- vator.cpp

This commit is contained in:
Christoph Oelckers 2021-11-03 00:45:43 +01:00
parent 2c94259603
commit 10ea8b0fb5
5 changed files with 73 additions and 99 deletions

View file

@ -2119,7 +2119,7 @@ void SetRotatorActive(DSWActor* actor); // rotator.c
bool VatorSwitch(short match, short setting); // vator.c bool VatorSwitch(short match, short setting); // vator.c
void MoveSpritesWithSector(short sectnum,int z_amt,bool type); // vator.c void MoveSpritesWithSector(short sectnum,int z_amt,bool type); // vator.c
void SetVatorActive(short SpriteNum); // vator.c void SetVatorActive(DSWActor*); // vator.c
void DoSpikeMatch(short match); // spike.c void DoSpikeMatch(short match); // spike.c
void SpikeAlign(DSWActor*); // spike.c void SpikeAlign(DSWActor*); // spike.c

View file

@ -69,8 +69,8 @@ bool TestSpikeMatchActive(short match);
bool TestRotatorMatchActive(short match); bool TestRotatorMatchActive(short match);
bool TestSlidorMatchActive(short match); bool TestSlidorMatchActive(short match);
int PlayerCheckDeath(PLAYERp, short); int PlayerCheckDeath(PLAYERp, short);
short DoVatorOperate(PLAYERp, short); void DoVatorOperate(PLAYERp, short);
short DoVatorMatch(PLAYERp pp, short match); void DoVatorMatch(PLAYERp pp, short match);
void DoRotatorOperate(PLAYERp, short); void DoRotatorOperate(PLAYERp, short);
void DoRotatorMatch(PLAYERp pp, short match, bool); void DoRotatorMatch(PLAYERp pp, short match, bool);
void DoSlidorOperate(PLAYERp, short); void DoSlidorOperate(PLAYERp, short);

View file

@ -37,7 +37,6 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
BEGIN_SW_NS BEGIN_SW_NS
bool TestSpikeMatchActive(short match); bool TestSpikeMatchActive(short match);
int DoVatorMove(short SpriteNum, int *lptr);
void InterpSectorSprites(short sectnum, bool state); void InterpSectorSprites(short sectnum, bool state);
void ReverseSpike(DSWActor* actor) void ReverseSpike(DSWActor* actor)

View file

@ -6773,7 +6773,7 @@ SpriteControl(void)
if (u->Tics) if (u->Tics)
{ {
if ((u->Tics -= synctics) <= 0) if ((u->Tics -= synctics) <= 0)
SetVatorActive(i); SetVatorActive(actor);
else else
continue; continue;
} }

View file

@ -40,20 +40,20 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
BEGIN_SW_NS BEGIN_SW_NS
short DoVatorMatch(PLAYERp pp, short match); void DoVatorMatch(PLAYERp pp, short match);
bool TestVatorMatchActive(short match); bool TestVatorMatchActive(short match);
void InterpSectorSprites(short sectnum, bool state); void InterpSectorSprites(short sectnum, bool state);
void ReverseVator(short SpriteNum) void ReverseVator(DSWActor* actor)
{ {
USERp u = User[SpriteNum].Data(); USERp u = actor->u();
SPRITEp sp = u->SpriteP; SPRITEp sp = &actor->s();
// if paused go ahead and start it up again // if paused go ahead and start it up again
if (u->Tics) if (u->Tics)
{ {
u->Tics = 0; u->Tics = 0;
SetVatorActive(SpriteNum); SetVatorActive(actor);
return; return;
} }
@ -76,17 +76,15 @@ void ReverseVator(short SpriteNum)
u->vel_rate = -u->vel_rate; u->vel_rate = -u->vel_rate;
} }
bool bool VatorSwitch(short match, short setting)
VatorSwitch(short match, short setting)
{ {
SPRITEp sp; SPRITEp sp;
int i;
bool found = false; bool found = false;
StatIterator it(STAT_DEFAULT); SWStatIterator it(STAT_DEFAULT);
while ((i = it.NextIndex()) >= 0) while (auto actor = it.Next())
{ {
sp = &sprite[i]; sp = &actor->s();
if (sp->lotag == TAG_SPRITE_SWITCH_VATOR && sp->hitag == match) if (sp->lotag == TAG_SPRITE_SWITCH_VATOR && sp->hitag == match)
{ {
@ -98,10 +96,10 @@ VatorSwitch(short match, short setting)
return found; return found;
} }
void SetVatorActive(short SpriteNum) void SetVatorActive(DSWActor* actor)
{ {
USERp u = User[SpriteNum].Data(); USERp u = actor->u();
SPRITEp sp = u->SpriteP; SPRITEp sp = &actor->s();
SECTORp sectp = &sector[sp->sectnum]; SECTORp sectp = &sector[sp->sectnum];
if (TEST(sp->cstat, CSTAT_SPRITE_YFLIP)) if (TEST(sp->cstat, CSTAT_SPRITE_YFLIP))
@ -126,10 +124,10 @@ void SetVatorActive(short SpriteNum)
VatorSwitch(SP_TAG2(sp), OFF); VatorSwitch(SP_TAG2(sp), OFF);
} }
void SetVatorInactive(short SpriteNum) void SetVatorInactive(DSWActor* actor)
{ {
USERp u = User[SpriteNum].Data(); USERp u = actor->u();
SPRITEp sp = u->SpriteP; SPRITEp sp = &actor->s();
SECTORp sectp = &sector[sp->sectnum]; SECTORp sectp = &sector[sp->sectnum];
if (TEST(sp->cstat, CSTAT_SPRITE_YFLIP)) if (TEST(sp->cstat, CSTAT_SPRITE_YFLIP))
@ -146,16 +144,15 @@ void SetVatorInactive(short SpriteNum)
} }
// called for operation from the space bar // called for operation from the space bar
short DoVatorOperate(PLAYERp pp, short sectnum) void DoVatorOperate(PLAYERp pp, short sectnum)
{ {
SPRITEp fsp; SPRITEp fsp;
short match; short match;
int i;
SectIterator it(sectnum); SWSectIterator it(sectnum);
while ((i = it.NextIndex()) >= 0) while (auto actor = it.Next())
{ {
fsp = &sprite[i]; fsp = &actor->s();
if (fsp->statnum == STAT_VATOR && SP_TAG1(fsp) == SECT_VATOR && SP_TAG3(fsp) == 0) if (fsp->statnum == STAT_VATOR && SP_TAG1(fsp) == SECT_VATOR && SP_TAG3(fsp) == 0)
{ {
@ -172,10 +169,9 @@ short DoVatorOperate(PLAYERp pp, short sectnum)
match = SP_TAG2(fsp); match = SP_TAG2(fsp);
if (match > 0) if (match > 0)
{ {
if (TestVatorMatchActive(match)) if (!TestVatorMatchActive(match))
return -1; DoVatorMatch(pp, match);
else return;
return DoVatorMatch(pp, match);
} }
if (pp && SectUser[sectnum].Data() && SectUser[sectnum]->stag == SECT_LOCK_DOOR && SectUser[sectnum]->number) if (pp && SectUser[sectnum].Data() && SectUser[sectnum]->stag == SECT_LOCK_DOOR && SectUser[sectnum]->number)
@ -186,43 +182,32 @@ short DoVatorOperate(PLAYERp pp, short sectnum)
{ {
PutStringInfo(pp, quoteMgr.GetQuote(QUOTE_DOORMSG + key_num - 1)); PutStringInfo(pp, quoteMgr.GetQuote(QUOTE_DOORMSG + key_num - 1));
return false; return;
} }
} }
SetVatorActive(i); SetVatorActive(actor);
break; break;
} }
} }
return i;
} }
// called from switches and triggers // called from switches and triggers
// returns first vator found // returns first vator found
short void DoVatorMatch(PLAYERp pp, short match)
DoVatorMatch(PLAYERp pp, short match)
{ {
USERp fu; USERp fu;
SPRITEp fsp; SPRITEp fsp;
short sectnum; short sectnum;
short first_vator = -1;
int i; SWStatIterator it(STAT_VATOR);
while (auto actor = it.Next())
//VatorSwitch(match, ON);
StatIterator it(STAT_VATOR);
while ((i = it.NextIndex()) >= 0)
{ {
fsp = &sprite[i]; fsp = &actor->s();
if (SP_TAG1(fsp) == SECT_VATOR && SP_TAG2(fsp) == match) if (SP_TAG1(fsp) == SECT_VATOR && SP_TAG2(fsp) == match)
{ {
fu = User[i].Data(); fu = actor->u();
if (first_vator == -1)
first_vator = i;
// single play only vator // single play only vator
// bool 8 must be set for message to display // bool 8 must be set for message to display
@ -242,7 +227,7 @@ DoVatorMatch(PLAYERp pp, short match)
{ {
PutStringInfo(pp, quoteMgr.GetQuote(QUOTE_DOORMSG + key_num - 1)); PutStringInfo(pp, quoteMgr.GetQuote(QUOTE_DOORMSG + key_num - 1));
return -1; return;
} }
} }
@ -251,34 +236,29 @@ DoVatorMatch(PLAYERp pp, short match)
if (TEST(fu->Flags, SPR_ACTIVE)) if (TEST(fu->Flags, SPR_ACTIVE))
{ {
ReverseVator(i); ReverseVator(actor);
continue; continue;
} }
SetVatorActive(i); SetVatorActive(actor);
} }
} }
return first_vator;
} }
bool bool TestVatorMatchActive(short match)
TestVatorMatchActive(short match)
{ {
USERp fu; USERp fu;
SPRITEp fsp; SPRITEp fsp;
int i; SWStatIterator it(STAT_VATOR);
while (auto actor = it.Next())
StatIterator it(STAT_VATOR);
while ((i = it.NextIndex()) >= 0)
{ {
fsp = &sprite[i]; fsp = &actor->s();
if (SP_TAG1(fsp) == SECT_VATOR && SP_TAG2(fsp) == match) if (SP_TAG1(fsp) == SECT_VATOR && SP_TAG2(fsp) == match)
{ {
fu = User[i].Data(); fu = actor->u();
// Does not have to be inactive to be operated // Does not have to be inactive to be operated
if (TEST_BOOL6(fsp)) if (TEST_BOOL6(fsp))
@ -295,44 +275,43 @@ TestVatorMatchActive(short match)
void InterpSectorSprites(short sectnum, bool state) void InterpSectorSprites(short sectnum, bool state)
{ {
SPRITEp sp; SPRITEp sp;
int i;
SectIterator it(sectnum); SWSectIterator it(sectnum);
while ((i = it.NextIndex()) >= 0) while (auto actor = it.Next())
{ {
sp = &sprite[i]; sp = &actor->s();
if (User[i].Data()) if (actor->hasU())
{ {
if (TEST(User[i]->Flags, SPR_SKIP4) && sp->statnum <= STAT_SKIP4_INTERP_END) auto u = actor->u();
if (TEST(u->Flags, SPR_SKIP4) && sp->statnum <= STAT_SKIP4_INTERP_END)
continue; continue;
if (TEST(User[i]->Flags, SPR_SKIP2) && sp->statnum <= STAT_SKIP2_INTERP_END) if (TEST(u->Flags, SPR_SKIP2) && sp->statnum <= STAT_SKIP2_INTERP_END)
continue; continue;
} }
if (state) if (state)
StartInterpolation(i, Interp_Sprite_Z); StartInterpolation(actor->GetSpriteIndex(), Interp_Sprite_Z);
else else
StopInterpolation(i, Interp_Sprite_Z); StopInterpolation(actor->GetSpriteIndex(), Interp_Sprite_Z);
} }
} }
void MoveSpritesWithSector(short sectnum, int z_amt, bool type) void MoveSpritesWithSector(short sectnum, int z_amt, bool type)
{ {
SPRITEp sp; SPRITEp sp;
int i;
bool both = false; bool both = false;
if (SectUser[sectnum].Data()) if (SectUser[sectnum].Data())
both = !!TEST(SectUser[sectnum]->flags, SECTFU_VATOR_BOTH); both = !!TEST(SectUser[sectnum]->flags, SECTFU_VATOR_BOTH);
SectIterator it(sectnum); SWSectIterator it(sectnum);
while ((i = it.NextIndex()) >= 0) while (auto actor = it.Next())
{ {
sp = &sprite[i]; sp = &actor->s();
if (User[i].Data()) if (actor->hasU())
{ {
switch (sp->statnum) switch (sp->statnum)
{ {
@ -386,9 +365,9 @@ cont:
} }
} }
int DoVatorMove(short SpriteNum, int *lptr) int DoVatorMove(DSWActor* actor, int *lptr)
{ {
USERp u = User[SpriteNum].Data(); USERp u = actor->u();
int zval; int zval;
int move_amt; int move_amt;
@ -429,8 +408,7 @@ int DoVatorMove(short SpriteNum, int *lptr)
int DoVator(DSWActor* actor) int DoVator(DSWActor* actor)
{ {
USER* u = actor->u(); USER* u = actor->u();
int SpriteNum = u->SpriteNum; SPRITEp sp = &actor->s();
SPRITEp sp = u->SpriteP;
SECTORp sectp = &sector[sp->sectnum]; SECTORp sectp = &sector[sp->sectnum];
int *lptr; int *lptr;
int amt; int amt;
@ -444,13 +422,13 @@ int DoVator(DSWActor* actor)
if (TEST(sp->cstat, CSTAT_SPRITE_YFLIP)) if (TEST(sp->cstat, CSTAT_SPRITE_YFLIP))
{ {
lptr = &sectp->ceilingz; lptr = &sectp->ceilingz;
amt = DoVatorMove(SpriteNum, lptr); amt = DoVatorMove(actor, lptr);
MoveSpritesWithSector(sp->sectnum, amt, true); // ceiling MoveSpritesWithSector(sp->sectnum, amt, true); // ceiling
} }
else else
{ {
lptr = &sectp->floorz; lptr = &sectp->floorz;
amt = DoVatorMove(SpriteNum, lptr); amt = DoVatorMove(actor, lptr);
MoveSpritesWithSector(sp->sectnum, amt, false); // floor MoveSpritesWithSector(sp->sectnum, amt, false); // floor
} }
@ -464,7 +442,7 @@ int DoVator(DSWActor* actor)
u->z_tgt = u->sz; u->z_tgt = u->sz;
u->vel_rate = -u->vel_rate; u->vel_rate = -u->vel_rate;
SetVatorInactive(SpriteNum); SetVatorInactive(actor);
// if tag6 and nothing blocking door // if tag6 and nothing blocking door
if (SP_TAG6(sp) && !TEST_BOOL8(sp)) if (SP_TAG6(sp) && !TEST_BOOL8(sp))
@ -482,7 +460,7 @@ int DoVator(DSWActor* actor)
u->z_tgt = sp->z; u->z_tgt = sp->z;
RESET_BOOL8(sp); RESET_BOOL8(sp);
SetVatorInactive(SpriteNum); SetVatorInactive(actor);
// set Owner swith back to OFF // set Owner swith back to OFF
// only if ALL vators are inactive // only if ALL vators are inactive
@ -498,7 +476,7 @@ int DoVator(DSWActor* actor)
// operate only once // operate only once
if (TEST_BOOL2(sp)) if (TEST_BOOL2(sp))
{ {
SetVatorInactive(SpriteNum); SetVatorInactive(actor);
KillActor(actor); KillActor(actor);
return 0; return 0;
} }
@ -520,12 +498,11 @@ int DoVator(DSWActor* actor)
USERp bu; USERp bu;
bool found = false; bool found = false;
SectIterator it(sp->sectnum); SWSectIterator it(sp->sectnum);
while ((i = it.NextIndex()) >= 0) while (auto itActor = it.Next())
{ {
auto itActor = &swActors[i]; bsp = &itActor->s();
bsp = &sprite[i]; bu = itActor->u();
bu = User[i].Data();
if (bsp->statnum == STAT_ENEMY) if (bsp->statnum == STAT_ENEMY)
{ {
@ -541,7 +518,7 @@ int DoVator(DSWActor* actor)
if (bu && TEST(bsp->cstat, CSTAT_SPRITE_BLOCK) && TEST(bsp->extra, SPRX_PLAYER_OR_ENEMY)) if (bu && TEST(bsp->cstat, CSTAT_SPRITE_BLOCK) && TEST(bsp->extra, SPRX_PLAYER_OR_ENEMY))
{ {
// found something blocking so reverse to ON position // found something blocking so reverse to ON position
ReverseVator(SpriteNum); ReverseVator(actor);
SET_BOOL8(sp); // tell vator that something blocking door SET_BOOL8(sp); // tell vator that something blocking door
found = true; found = true;
break; break;
@ -560,7 +537,7 @@ int DoVator(DSWActor* actor)
if (pp->lo_sectp == &sector[sp->sectnum] || if (pp->lo_sectp == &sector[sp->sectnum] ||
pp->hi_sectp == &sector[sp->sectnum]) pp->hi_sectp == &sector[sp->sectnum])
{ {
ReverseVator(SpriteNum); ReverseVator(actor);
u->vel_rate = -u->vel_rate; u->vel_rate = -u->vel_rate;
found = true; found = true;
@ -570,14 +547,12 @@ int DoVator(DSWActor* actor)
} }
else else
{ {
int i;
SPRITEp bsp; SPRITEp bsp;
SectIterator it(sp->sectnum); SWSectIterator it(sp->sectnum);
while ((i = it.NextIndex()) >= 0) while (auto itActor = it.Next())
{ {
auto itActor = &swActors[i]; bsp = &itActor->s();
bsp = &sprite[i];
if (bsp->statnum == STAT_ENEMY) if (bsp->statnum == STAT_ENEMY)
{ {
@ -610,13 +585,13 @@ int DoVatorAuto(DSWActor* actor)
if (TEST(sp->cstat, CSTAT_SPRITE_YFLIP)) if (TEST(sp->cstat, CSTAT_SPRITE_YFLIP))
{ {
lptr = &sectp->ceilingz; lptr = &sectp->ceilingz;
amt = DoVatorMove(SpriteNum, lptr); amt = DoVatorMove(actor, lptr);
MoveSpritesWithSector(sp->sectnum, amt, true); // ceiling MoveSpritesWithSector(sp->sectnum, amt, true); // ceiling
} }
else else
{ {
lptr = &sectp->floorz; lptr = &sectp->floorz;
amt = DoVatorMove(SpriteNum, lptr); amt = DoVatorMove(actor, lptr);
MoveSpritesWithSector(sp->sectnum, amt, false); // floor MoveSpritesWithSector(sp->sectnum, amt, false); // floor
} }