diff --git a/source/games/sw/src/misc.h b/source/games/sw/src/misc.h index 6738e196d..59908d59d 100644 --- a/source/games/sw/src/misc.h +++ b/source/games/sw/src/misc.h @@ -71,13 +71,13 @@ inline constexpr int TEXT_INFO_LINE(int line) { return (TEXT_INFO_Y + ((line)*TE void PutStringInfo(PLAYERp pp, const char* string); -short DoSlidorMatch(PLAYERp pp, short match, bool); +void DoSlidorMatch(PLAYERp pp, short match, bool); bool TestSlidorMatchActive(short match); void InterpSectorSprites(short sectnum, bool state); using INTERP_FUNC = void(*)(int, int); -void SetSlidorActive(short SpriteNum); +void SetSlidorActive(DSWActor*); void DoSlidorInterp(short, INTERP_FUNC); int DoBeginJump(DSWActor* actor); diff --git a/source/games/sw/src/sector.cpp b/source/games/sw/src/sector.cpp index 32314dc36..ce7314ba9 100644 --- a/source/games/sw/src/sector.cpp +++ b/source/games/sw/src/sector.cpp @@ -73,8 +73,8 @@ short DoVatorOperate(PLAYERp, short); short DoVatorMatch(PLAYERp pp, short match); void DoRotatorOperate(PLAYERp, short); void DoRotatorMatch(PLAYERp pp, short match, bool); -short DoSlidorOperate(PLAYERp, short); -short DoSlidorMatch(PLAYERp pp, short match, bool); +void DoSlidorOperate(PLAYERp, short); +void DoSlidorMatch(PLAYERp pp, short match, bool); void KillMatchingCrackSprites(short match); int DoTrapReset(short match); diff --git a/source/games/sw/src/slidor.cpp b/source/games/sw/src/slidor.cpp index e54a2bba6..7d1fdbb97 100644 --- a/source/games/sw/src/slidor.cpp +++ b/source/games/sw/src/slidor.cpp @@ -39,9 +39,9 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms BEGIN_SW_NS -void ReverseSlidor(short SpriteNum) +void ReverseSlidor(DSWActor* actor) { - USERp u = User[SpriteNum].Data(); + USERp u = actor->u(); ROTATORp r; r = u->rotator.Data(); @@ -50,7 +50,7 @@ void ReverseSlidor(short SpriteNum) if (u->Tics) { u->Tics = 0; - SetSlidorActive(SpriteNum); + SetSlidorActive(actor); return; } @@ -68,17 +68,15 @@ void ReverseSlidor(short SpriteNum) } -bool -SlidorSwitch(short match, short setting) +bool SlidorSwitch(short match, short setting) { SPRITEp sp; - int i; bool found = false; - StatIterator it(STAT_DEFAULT); - while ((i = it.NextIndex()) >= 0) + SWStatIterator it(STAT_DEFAULT); + while (auto actor = it.Next()) { - sp = &sprite[i]; + sp = &actor->s(); if (sp->lotag == TAG_SPRITE_SWITCH_VATOR && sp->hitag == match) { @@ -90,15 +88,15 @@ SlidorSwitch(short match, short setting) return found; } -void SetSlidorActive(short SpriteNum) +void SetSlidorActive(DSWActor* actor) { - USERp u = User[SpriteNum].Data(); - SPRITEp sp = u->SpriteP; + USERp u = actor->u(); + SPRITEp sp = &actor->s(); ROTATORp r; r = u->rotator.Data(); - DoSlidorInterp(SpriteNum, StartInterpolation); + DoSlidorInterp(actor->GetSpriteIndex(), StartInterpolation); // play activate sound DoSoundSpotMatch(SP_TAG2(sp), 1, SOUND_OBJECT_TYPE); @@ -127,7 +125,7 @@ void SetSlidorInactive(short SpriteNum) } // called for operation from the space bar -short DoSlidorOperate(PLAYERp pp, short sectnum) +void DoSlidorOperate(PLAYERp pp, short sectnum) { short match; @@ -136,37 +134,27 @@ short DoSlidorOperate(PLAYERp pp, short sectnum) if (match > 0) { - if (TestSlidorMatchActive(match)) - return -1; - else - return DoSlidorMatch(pp, match, true); + if (!TestSlidorMatchActive(match)) + DoSlidorMatch(pp, match, true); } - - return -1; } // called from switches and triggers // returns first vator found -short -DoSlidorMatch(PLAYERp pp, short match, bool manual) +void DoSlidorMatch(PLAYERp pp, short match, bool manual) { USERp fu; SPRITEp fsp; short sectnum; - short first_vator = -1; - int i; - - //SlidorSwitch(match, ON); - - StatIterator it(STAT_SLIDOR); - while ((i = it.NextIndex()) >= 0) + SWStatIterator it(STAT_SLIDOR); + while (auto actor = it.Next()) { - fsp = &sprite[i]; + fsp = &actor->s(); if (SP_TAG1(fsp) == SECT_SLIDOR && SP_TAG2(fsp) == match) { - fu = User[i].Data(); + fu = actor->u(); // single play only vator // bool 8 must be set for message to display @@ -184,9 +172,6 @@ DoSlidorMatch(PLAYERp pp, short match, bool manual) continue; } - if (first_vator == -1) - first_vator = i; - sectnum = fsp->sectnum; if (pp && SectUser[sectnum].Data() && SectUser[sectnum]->stag == SECT_LOCK_DOOR && SectUser[sectnum]->number) @@ -197,40 +182,35 @@ DoSlidorMatch(PLAYERp pp, short match, bool manual) { PutStringInfo(pp, quoteMgr.GetQuote(QUOTE_DOORMSG + key_num - 1)); - return -1; + return; } } if (TEST(fu->Flags, SPR_ACTIVE)) { - ReverseSlidor(i); + ReverseSlidor(actor); continue; } - SetSlidorActive(i); + SetSlidorActive(actor); } } - - return first_vator; } -bool -TestSlidorMatchActive(short match) +bool TestSlidorMatchActive(short match) { USERp fu; SPRITEp fsp; - int i; - - StatIterator it(STAT_SLIDOR); - while ((i = it.NextIndex()) >= 0) + SWStatIterator it(STAT_SLIDOR); + while (auto actor = it.Next()) { - fsp = &sprite[i]; + fsp = &actor->s(); if (SP_TAG1(fsp) == SECT_SLIDOR && SP_TAG2(fsp) == match) { - fu = User[i].Data(); + fu = actor->u(); // Does not have to be inactive to be operated if (TEST_BOOL6(fsp)) @@ -625,7 +605,7 @@ int DoSlidorMove(short SpriteNum) if (bu && TEST(bsp->cstat, CSTAT_SPRITE_BLOCK) && TEST(bsp->extra, SPRX_PLAYER_OR_ENEMY)) { // found something blocking so reverse to ON position - ReverseSlidor(SpriteNum); + ReverseSlidor(actor); SET_BOOL8(sp); // tell vator that something blocking door found = true; break; @@ -644,7 +624,7 @@ int DoSlidorMove(short SpriteNum) if (pp->lo_sectp == §or[sp->sectnum] || pp->hi_sectp == §or[sp->sectnum]) { - ReverseSlidor(SpriteNum); + ReverseSlidor(actor); u->vel_rate = -u->vel_rate; found = true; diff --git a/source/games/sw/src/sprite.cpp b/source/games/sw/src/sprite.cpp index f14e3f763..ca8fa4368 100644 --- a/source/games/sw/src/sprite.cpp +++ b/source/games/sw/src/sprite.cpp @@ -6836,7 +6836,7 @@ SpriteControl(void) if (u->Tics) { if ((u->Tics -= synctics) <= 0) - SetSlidorActive(i); + SetSlidorActive(actor); else continue; }