From be83c229e027ef08c451824c04803fa947333ad9 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sat, 2 Nov 2024 17:54:27 +0200 Subject: [PATCH] game: fix position of dropped objects --- Makefile | 4 ++-- src/game/g_items.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d26b013f..612a789e 100644 --- a/Makefile +++ b/Makefile @@ -150,7 +150,7 @@ endif # Highest supported optimizations are -O2, higher levels # will likely break this crappy code. ifdef DEBUG -CFLAGS ?= -O0 -g -Wall -pipe -DDEBUG +CFLAGS ?= -O0 -g -Wall -Wpointer-arith -pipe -DDEBUG ifdef ASAN override CFLAGS += -fsanitize=address -DUSE_SANITIZER endif @@ -158,7 +158,7 @@ ifdef UBSAN override CFLAGS += -fsanitize=undefined -DUSE_SANITIZER endif else -CFLAGS ?= -O2 -Wall -pipe -fomit-frame-pointer +CFLAGS ?= -O2 -Wall -Wpointer-arith -pipe -fomit-frame-pointer endif # Always needed are: diff --git a/src/game/g_items.c b/src/game/g_items.c index a20e5138..6ccf8f21 100644 --- a/src/game/g_items.c +++ b/src/game/g_items.c @@ -1931,6 +1931,57 @@ Use_Item(edict_t *ent, edict_t *other /* unused */, edict_t *activator /* unused /* ====================================================================== */ +static void +FixObjectPosition(edict_t *ent) +{ + int i; + + for (i = 0; i < 3; i++) + { + int j; + + for (j = 0; j < 3; j++) + { + vec3_t pos; + trace_t tr_pos; + int k; + + VectorCopy(ent->s.origin, pos); + + /* move by min */ + for (k = 0; k < i + 1; k++) + { + int v; + + v = (j + k) % 3; + pos[v] = ent->s.origin[v] - ent->mins[v]; + } + + tr_pos = gi.trace(pos, ent->mins, ent->maxs, ent->s.origin, ent, MASK_SOLID); + if (!tr_pos.startsolid) + { + VectorCopy(tr_pos.endpos, ent->s.origin); + return; + } + + /* move by max */ + for (k = 0; k < i + 1; k++) + { + int v; + + v = (j + k) % 3; + pos[v] = ent->s.origin[v] - ent->maxs[v]; + } + tr_pos = gi.trace(pos, ent->mins, ent->maxs, ent->s.origin, ent, MASK_SOLID); + if (!tr_pos.startsolid) + { + VectorCopy(tr_pos.endpos, ent->s.origin); + return; + } + } + } +} + void droptofloor(edict_t *ent) { @@ -1966,6 +2017,13 @@ droptofloor(edict_t *ent) tr = gi.trace(ent->s.origin, ent->mins, ent->maxs, dest, ent, MASK_SOLID); + if (tr.startsolid) + { + FixObjectPosition(ent); + + tr = gi.trace(ent->s.origin, ent->mins, ent->maxs, dest, ent, MASK_SOLID); + } + if (tr.startsolid) { if (strcmp(ent->classname, "foodcube") == 0)