mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 00:41:55 +00:00
- split out the sprite switch toggle handler into a common subfunction using the switch definitions.
This commit is contained in:
parent
4191a9493a
commit
d9122a0482
3 changed files with 64 additions and 155 deletions
|
@ -1494,4 +1494,63 @@ void tag10000specialswitch(int snum, DDukeActor* act, const DVector3& v)
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void togglespriteswitches(DDukeActor* act, const TexExtInfo& ext, int lotag, int& correctdips, int& numdips)
|
||||
{
|
||||
auto& swdef = switches[ext.switchindex];
|
||||
|
||||
DukeStatIterator it(STAT_DEFAULT);
|
||||
while (auto other = it.Next())
|
||||
{
|
||||
if (lotag != other->spr.lotag) continue;
|
||||
|
||||
auto& other_ext = GetExtInfo(other->spr.spritetexture());
|
||||
auto& other_swdef = switches[other_ext.switchindex];
|
||||
|
||||
switch (other_swdef.type)
|
||||
{
|
||||
case SwitchDef::Combo:
|
||||
if (other_ext.switchphase == 0)
|
||||
{
|
||||
if (act && act == other) other->spr.setspritetexture(other_swdef.states[1]);
|
||||
else if (other->spr.hitag == 0) correctdips++;
|
||||
numdips++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (act && act == other) other->spr.setspritetexture(other_swdef.states[0]);
|
||||
else if (other->spr.hitag == 1) correctdips++;
|
||||
numdips++;
|
||||
}
|
||||
break;
|
||||
|
||||
case SwitchDef::Multi:
|
||||
other->spr.setspritetexture(other_swdef.states[(other_ext.switchphase + 1) & 3]);
|
||||
break;
|
||||
|
||||
case SwitchDef::Access:
|
||||
case SwitchDef::Regular:
|
||||
if (other->spr.hitag != 999 || other_ext.switchphase != 1 || !(other_swdef.flags & SwitchDef::resettable))
|
||||
{
|
||||
other->spr.setspritetexture(other_swdef.states[1 - other_ext.switchphase]);
|
||||
}
|
||||
// one of RR's ugly hacks.
|
||||
if (other->spr.hitag == 999 && other_ext.switchphase == 0 && (other_swdef.flags & SwitchDef::resettable))
|
||||
{
|
||||
DukeStatIterator it1(STAT_LUMBERMILL);
|
||||
while (auto other2 = it1.Next())
|
||||
{
|
||||
CallOnUse(other2, nullptr);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
END_DUKE_NS
|
||||
|
|
|
@ -203,6 +203,7 @@ bool checkaccessswitch_d(int snum, int switchpal, DDukeActor* act, walltype* wwa
|
|||
// how NOT to implement switch animations...
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
void togglespriteswitches(DDukeActor* act, const TexExtInfo& ext, int lotag, int& correctdips, int& numdips);
|
||||
|
||||
bool checkhitswitch_d(int snum, walltype* wwal, DDukeActor *act)
|
||||
{
|
||||
|
@ -260,67 +261,7 @@ bool checkhitswitch_d(int snum, walltype* wwal, DDukeActor *act)
|
|||
break;
|
||||
}
|
||||
|
||||
DukeStatIterator it(STAT_DEFAULT);
|
||||
while (auto other = it.Next())
|
||||
{
|
||||
if (lotag == other->spr.lotag) switch (other->spr.picnum)
|
||||
{
|
||||
case DTILE_DIPSWITCH:
|
||||
case DTILE_TECHSWITCH:
|
||||
case DTILE_ALIENSWITCH:
|
||||
if (act && act == other) other->spr.picnum++;
|
||||
else if (other->spr.hitag == 0) correctdips++;
|
||||
numdips++;
|
||||
break;
|
||||
case DTILE_TECHSWITCHON:
|
||||
case DTILE_DIPSWITCHON:
|
||||
case DTILE_ALIENSWITCHON:
|
||||
if (act && act == other) other->spr.picnum--;
|
||||
else if (other->spr.hitag == 1) correctdips++;
|
||||
numdips++;
|
||||
break;
|
||||
case DTILE_MULTISWITCH:
|
||||
case DTILE_MULTISWITCH_2:
|
||||
case DTILE_MULTISWITCH_3:
|
||||
case DTILE_MULTISWITCH_4:
|
||||
other->spr.picnum++;
|
||||
if (other->spr.picnum > (DTILE_MULTISWITCH_4))
|
||||
other->spr.picnum = DTILE_MULTISWITCH;
|
||||
break;
|
||||
case DTILE_ACCESSSWITCH:
|
||||
case DTILE_ACCESSSWITCH2:
|
||||
case DTILE_SLOTDOOR:
|
||||
case DTILE_LIGHTSWITCH:
|
||||
case DTILE_SPACELIGHTSWITCH:
|
||||
case DTILE_SPACEDOORSWITCH:
|
||||
case DTILE_FRANKENSTINESWITCH:
|
||||
case DTILE_LIGHTSWITCH2:
|
||||
case DTILE_POWERSWITCH1:
|
||||
case DTILE_LOCKSWITCH1:
|
||||
case DTILE_POWERSWITCH2:
|
||||
case DTILE_HANDSWITCH:
|
||||
case DTILE_PULLSWITCH:
|
||||
case DTILE_DIPSWITCH2:
|
||||
case DTILE_DIPSWITCH3:
|
||||
other->spr.picnum++;
|
||||
break;
|
||||
case DTILE_PULLSWITCHON:
|
||||
case DTILE_HANDSWITCHON:
|
||||
case DTILE_LIGHTSWITCH2ON:
|
||||
case DTILE_POWERSWITCH1ON:
|
||||
case DTILE_LOCKSWITCH1ON:
|
||||
case DTILE_POWERSWITCH2ON:
|
||||
case DTILE_SLOTDOORON:
|
||||
case DTILE_LIGHTSWITCHON:
|
||||
case DTILE_SPACELIGHTSWITCHON:
|
||||
case DTILE_SPACEDOORSWITCHON:
|
||||
case DTILE_FRANKENSTINESWITCHON:
|
||||
case DTILE_DIPSWITCH2ON:
|
||||
case DTILE_DIPSWITCH3ON:
|
||||
other->spr.picnum--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
togglespriteswitches(act, ext, lotag, correctdips, numdips);
|
||||
|
||||
for (auto& wal : wall)
|
||||
{
|
||||
|
|
|
@ -174,6 +174,8 @@ bool checkaccessswitch_r(int snum, int switchpal, DDukeActor* act, walltype* wwa
|
|||
//
|
||||
//---------------------------------------------------------------------------
|
||||
void tag10000specialswitch(int snum, DDukeActor* act, const DVector3& v);
|
||||
void togglespriteswitches(DDukeActor* act, const TexExtInfo& ext, int lotag, int& correctdips, int& numdips);
|
||||
|
||||
bool checkhitswitch_r(int snum, walltype* wwal, DDukeActor* act)
|
||||
{
|
||||
uint8_t switchpal;
|
||||
|
@ -230,100 +232,7 @@ bool checkhitswitch_r(int snum, walltype* wwal, DDukeActor* act)
|
|||
break;
|
||||
}
|
||||
|
||||
|
||||
DukeStatIterator it(STAT_DEFAULT);
|
||||
while (auto other = it.Next())
|
||||
{
|
||||
if (lotag == other->spr.lotag) switch (other->spr.picnum)
|
||||
{
|
||||
case RTILE_DIPSWITCH:
|
||||
case RTILE_TECHSWITCH:
|
||||
case RTILE_ALIENSWITCH:
|
||||
if (act && act == other) other->spr.picnum++;
|
||||
else if (other->spr.hitag == 0) correctdips++;
|
||||
numdips++;
|
||||
break;
|
||||
case RTILE_TECHSWITCHON:
|
||||
case RTILE_DIPSWITCHON:
|
||||
case RTILE_ALIENSWITCHON:
|
||||
if (act && act == other) other->spr.picnum--;
|
||||
else if (other->spr.hitag == 1) correctdips++;
|
||||
numdips++;
|
||||
break;
|
||||
case RTILE_MULTISWITCH:
|
||||
case RTILE_MULTISWITCH_2:
|
||||
case RTILE_MULTISWITCH_3:
|
||||
case RTILE_MULTISWITCH_4:
|
||||
other->spr.picnum++;
|
||||
if (other->spr.picnum > (RTILE_MULTISWITCH_4))
|
||||
other->spr.picnum = RTILE_MULTISWITCH;
|
||||
break;
|
||||
case RTILE_MULTISWITCH2:
|
||||
case RTILE_MULTISWITCH2_2:
|
||||
case RTILE_MULTISWITCH2_3:
|
||||
case RTILE_MULTISWITCH2_4:
|
||||
if (!isRRRA()) break;
|
||||
other->spr.picnum++;
|
||||
if (other->spr.picnum > (RTILE_MULTISWITCH2_4))
|
||||
other->spr.picnum = RTILE_MULTISWITCH2;
|
||||
break;
|
||||
|
||||
case RTILE_CONTESTSWITCH:
|
||||
other->spr.picnum++;
|
||||
break;
|
||||
case RTILE_BELLSWITCH:
|
||||
if (!isRRRA()) break;
|
||||
[[fallthrough]];
|
||||
case RTILE_ACCESSSWITCH:
|
||||
case RTILE_ACCESSSWITCH2:
|
||||
case RTILE_SLOTDOOR:
|
||||
case RTILE_LIGHTSWITCH:
|
||||
case RTILE_SPACELIGHTSWITCH:
|
||||
case RTILE_SPACEDOORSWITCH:
|
||||
case RTILE_FRANKENSTINESWITCH:
|
||||
case RTILE_LIGHTSWITCH2:
|
||||
case RTILE_POWERSWITCH1:
|
||||
case RTILE_LOCKSWITCH1:
|
||||
case RTILE_POWERSWITCH2:
|
||||
case RTILE_HANDSWITCH:
|
||||
case RTILE_PULLSWITCH:
|
||||
case RTILE_DIPSWITCH2:
|
||||
case RTILE_DIPSWITCH3:
|
||||
case RTILE_ALERTSWITCH:
|
||||
case RTILE_HANDLESWITCH:
|
||||
if (other->spr.picnum == RTILE_DIPSWITCH3)
|
||||
if (other->spr.hitag == 999)
|
||||
{
|
||||
DukeStatIterator it1(STAT_LUMBERMILL);
|
||||
while (auto other2 = it1.Next())
|
||||
{
|
||||
CallOnUse(other2, nullptr);
|
||||
}
|
||||
other->spr.picnum++;
|
||||
break;
|
||||
}
|
||||
other->spr.picnum++;
|
||||
break;
|
||||
case RTILE_PULLSWITCHON:
|
||||
case RTILE_HANDSWITCHON:
|
||||
case RTILE_LIGHTSWITCH2ON:
|
||||
case RTILE_POWERSWITCH1ON:
|
||||
case RTILE_LOCKSWITCH1ON:
|
||||
case RTILE_POWERSWITCH2ON:
|
||||
case RTILE_SLOTDOORON:
|
||||
case RTILE_LIGHTSWITCHON:
|
||||
case RTILE_SPACELIGHTSWITCHON:
|
||||
case RTILE_SPACEDOORSWITCHON:
|
||||
case RTILE_FRANKENSTINESWITCHON:
|
||||
case RTILE_DIPSWITCH2ON:
|
||||
case RTILE_DIPSWITCH3ON:
|
||||
case RTILE_ALERTSWITCHON:
|
||||
case RTILE_HANDLESWITCHON:
|
||||
if (other->spr.hitag != 999)
|
||||
other->spr.picnum--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
togglespriteswitches(act, ext, lotag, correctdips, numdips);
|
||||
|
||||
for (auto& wal : wall)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue