game: fix position of dropped objects

This commit is contained in:
Denis Pauk 2024-11-02 17:54:27 +02:00
parent dce9415411
commit be83c229e0
2 changed files with 60 additions and 2 deletions

View file

@ -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:

View file

@ -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)