Copy first mapthing tag to their mobjs

Allows the ThingCount and ThingSound ACS functions to fully work now, and adds significantly more possibilities for scripting later.
This commit is contained in:
Sally Coolatta 2023-01-01 16:55:39 -05:00 committed by NepDisk
parent b9b7bd676c
commit 25a9b5cfa9
7 changed files with 138 additions and 1 deletions

View file

@ -153,6 +153,11 @@ mapformat_udmf
include("RingRacers_misc.cfg", "linedefflags_udmf");
}
linedefactivations
{
include("RingRacers_misc.cfg", "linedefactivations_udmf");
}
linedefflagstranslation
{
include("RingRacers_misc.cfg", "linedefflagstranslation");

View file

@ -1,5 +1,7 @@
udmf
{
requiresactivation = false;
misc
{
title = "Miscellaneous";
@ -1556,6 +1558,7 @@ udmf
linedefexecsector
{
title = "Linedef Executor (sector)";
requiresactivation = true;
400
{
@ -1894,6 +1897,7 @@ udmf
linedefexecplane
{
title = "Linedef Executor (plane movement)";
requiresactivation = true;
403
{
@ -2031,6 +2035,7 @@ udmf
linedefexecplayer
{
title = "Linedef Executor (player/object)";
requiresactivation = true;
412
{
@ -2357,6 +2362,7 @@ udmf
linedefexecmisc
{
title = "Linedef Executor (misc.)";
requiresactivation = true;
413
{
@ -3014,6 +3020,7 @@ udmf
linedefexecpoly
{
title = "Linedef Executor (polyobject)";
requiresactivation = true;
480
{

View file

@ -551,4 +551,9 @@ fixed_t P_GetMobjFeet(const mobj_t *);
fixed_t P_GetMobjGround(const mobj_t *);
fixed_t P_GetMobjZMovement(mobj_t *mo);
void P_InitTIDHash(void);
void P_SetThingTID(mobj_t *mo, mtag_t tid);
void P_RemoveThingTID(mobj_t *mo);
mobj_t *P_FindMobjFromTID(mtag_t tid, mobj_t *i, mobj_t *activator);
#endif // __P_LOCAL__

View file

@ -10296,6 +10296,7 @@ void P_RemoveMobj(mobj_t *mobj)
memset((UINT8 *)mobj + sizeof(thinker_t), 0xff, sizeof(mobj_t) - sizeof(thinker_t));
#endif
P_RemoveThingTID(mobj);
R_RemoveMobjInterpolator(mobj);
// free block
@ -12488,6 +12489,8 @@ static mobj_t *P_SpawnMobjFromMapThing(mapthing_t *mthing, fixed_t x, fixed_t y,
P_InitPitch(mobj, FixedAngle(mthing->pitch << FRACBITS));
P_InitRoll(mobj, FixedAngle(mthing->roll << FRACBITS));
P_SetThingTID(mobj, Tag_FGet(&mthing->tags));
mthing->mobj = mobj;
// Generic reverse gravity for individual objects flag.
@ -13416,3 +13419,109 @@ fixed_t P_GetMobjZMovement(mobj_t *mo)
return P_ReturnThrustY(mo, slope->zangle, P_ReturnThrustX(mo, angDiff, speed));
}
//
// Thing IDs / tags
//
// TODO: Replace this system with taglist_t instead.
// The issue is that those require a static numbered ID
// to determine which struct it belongs to, which mobjs
// don't really have.
//
#define TID_HASH_CHAINS (131)
static mobj_t *TID_Hash[TID_HASH_CHAINS];
//
// P_InitTIDHash
// Initializes mobj tag hash array
//
void P_InitTIDHash(void)
{
memset(TID_Hash, 0, TID_HASH_CHAINS * sizeof(mobj_t *));
}
//
// P_SetThingTID
// Adds a mobj to the hash array
//
void P_SetThingTID(mobj_t *mo, mtag_t tid)
{
INT32 key = 0;
if (tid == 0)
{
if (mo->tid != 0)
{
P_RemoveThingTID(mo);
}
return;
}
mo->tid = tid;
// Insert at the head of this chain
key = tid % TID_HASH_CHAINS;
mo->tid_next = TID_Hash[key];
mo->tid_prev = &TID_Hash[key];
TID_Hash[key] = mo;
// Connect to any existing things in chain
if (mo->tid_next != NULL)
{
mo->tid_next->tid_prev = &(mo->tid_next);
}
}
//
// P_RemoveThingTID
// Removes a mobj from the hash array
//
void P_RemoveThingTID(mobj_t *mo)
{
if (mo->tid != 0 && mo->tid_prev != NULL)
{
// Fix the gap this would leave.
*(mo->tid_prev) = mo->tid_next;
if (mo->tid_next != NULL)
{
mo->tid_next->tid_prev = mo->tid_prev;
}
}
// Remove TID.
mo->tid = 0;
}
//
// P_FindMobjFromTID
// Mobj tag search function.
//
mobj_t *P_FindMobjFromTID(mtag_t tid, mobj_t *i, mobj_t *activator)
{
if (tid == 0)
{
// 0 grabs the activator, if applicable,
// for some ACS functions.
if (i != NULL)
{
// Don't do more than once.
return NULL;
}
return activator;
}
i = (i != NULL) ? i->tid_next : TID_Hash[tid % TID_HASH_CHAINS];
while (i != NULL && i->tid != tid)
{
i = i->tid_next;
}
return i;
}

View file

@ -330,6 +330,10 @@ typedef struct mobj_s
UINT32 flags2; // MF2_ flags
UINT16 eflags; // extra flags
mtag_t tid;
struct mobj_s *tid_next;
struct mobj_s **tid_prev; // killough 8/11/98: change to ptr-to-ptr
void *skin; // overrides 'sprite' when non-NULL (for player bodies to 'remember' the skin)
// Player and mobj sprites in multiplayer modes are modified
// using an internal color lookup table for re-indexing.

View file

@ -1640,7 +1640,7 @@ typedef enum
MD2_ROLLANGLE = 1<<14,
MD2_SHADOWSCALE = 1<<15,
MD2_RENDERFLAGS = 1<<16,
// 1<<17 was taken out, maybe reuse later
MD2_TID = 1<<17,
MD2_SPRITEXSCALE = 1<<18,
MD2_SPRITEYSCALE = 1<<19,
MD2_SPRITEXOFFSET = 1<<20,
@ -1871,6 +1871,8 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type)
diff2 |= MD2_SHADOWSCALE;
if (mobj->renderflags)
diff2 |= MD2_RENDERFLAGS;
if (mobj->tid != 0)
diff2 |= MD2_TID;
if (mobj->spritexscale != FRACUNIT)
diff2 |= MD2_SPRITEXSCALE;
if (mobj->spriteyscale != FRACUNIT)
@ -2068,6 +2070,8 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type)
WRITEUINT32(save_p, rf);
}
if (diff2 & MD2_TID)
WRITEINT16(save_p, mobj->tid);
if (diff2 & MD2_SPRITEXSCALE)
WRITEFIXED(save_p, mobj->spritexscale);
if (diff2 & MD2_SPRITEYSCALE)
@ -3176,6 +3180,8 @@ static thinker_t* LoadMobjThinker(actionf_p1 thinker)
}
if (diff2 & MD2_RENDERFLAGS)
mobj->renderflags = READUINT32(save_p);
if (diff2 & MD2_TID)
P_SetThingTID(mobj, READINT16(save_p));
if (diff2 & MD2_SPRITEXSCALE)
mobj->spritexscale = READFIXED(save_p);
else

View file

@ -7704,6 +7704,7 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate)
R_InitializeLevelInterpolators();
P_InitThinkers();
P_InitTIDHash();
R_InitMobjInterpolators();
P_InitCachedActions();