Skip to content

Commit

Permalink
- wrapped more direct access to the states.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed May 28, 2023
1 parent beb8368 commit 89cce84
Show file tree
Hide file tree
Showing 22 changed files with 71 additions and 76 deletions.
40 changes: 19 additions & 21 deletions source/games/sw/src/actor.cpp
Expand Up @@ -184,7 +184,6 @@ int DoActorDie(DSWActor* actor, DSWActor* weapActor, int meansofdeath)
actor->user.__legacyState.RotNum = 0;

actor->clearActionFunc();
//actor->user.__legacyState.ActorActionFunc = NullAnimator;
if (!sw_ninjahack)
actor->spr.Angles.Yaw = weapActor->spr.Angles.Yaw;
break;
Expand Down Expand Up @@ -532,7 +531,7 @@ void KeepActorOnFloor(DSWActor* actor)

if ((sectp->extra & SECTFX_SINK) &&
depth > 35 &&
actor->user.__legacyState.ActorActionSet && actor->user.__legacyState.ActorActionSet->Swim)
actor->hasState(NAME_Swim))
{
if (actor->user.Flags & (SPR_SWIMMING))
{
Expand Down Expand Up @@ -657,13 +656,11 @@ int DoActorBeginJump(DSWActor* actor)
actor->user.jump_grav = ACTOR_GRAVITY;

// Change sprites state to jumping
if (actor->user.__legacyState.ActorActionSet)
{
if (actor->user.Flags & (SPR_DEAD))
actor->setStateGroup(NAME_DeathJump);
else
actor->setStateGroup(NAME_Jump);
}
if (actor->user.Flags & (SPR_DEAD))
actor->setStateGroup(NAME_DeathJump);
else
actor->setStateGroup(NAME_Jump);

actor->user.__legacyState.StateFallOverride = nullptr;

//DO NOT CALL DoActorJump! DoActorStopFall can cause an infinite loop and
Expand Down Expand Up @@ -729,19 +726,16 @@ int DoActorBeginFall(DSWActor* actor)
actor->user.jump_grav = ACTOR_GRAVITY;

// Change sprites state to falling
if (actor->user.__legacyState.ActorActionSet)
if (actor->user.Flags & (SPR_DEAD))
{
if (actor->user.Flags & (SPR_DEAD))
{
actor->setStateGroup(NAME_DeathFall);
}
else
actor->setStateGroup(NAME_Fall);
actor->setStateGroup(NAME_DeathFall);
}
else
actor->setStateGroup(NAME_Fall);

if (actor->user.__legacyState.StateFallOverride)
{
NewStateGroup(actor, actor->user.__legacyState.StateFallOverride);
}
if (actor->user.__legacyState.StateFallOverride)
{
NewStateGroup(actor, actor->user.__legacyState.StateFallOverride);
}

DoActorFall(actor);
Expand Down Expand Up @@ -810,7 +804,7 @@ int DoActorStopFall(DSWActor* actor)

actor->setStateGroup(NAME_Run);

if ((actor->user.track >= 0) && (actor->user.jump_speed) > 800 && (actor->user.__legacyState.ActorActionSet->Sit))
if ((actor->user.track >= 0) && (actor->user.jump_speed) > 800 && (actor->hasState(NAME_Sit)))
{
actor->user.WaitTics = 80;
actor->setStateGroup(NAME_Sit);
Expand Down Expand Up @@ -1099,4 +1093,8 @@ bool DSWActor::hasState(FName label, int subl)

void DSWActor::setActionDecide() { user.__legacyState.ActorActionFunc = DoActorDecide; }

void DSWActor::callStateAction()
{
(*user.__legacyState.ActorActionFunc)(this);
}
END_SW_NS
22 changes: 10 additions & 12 deletions source/games/sw/src/ai.cpp
Expand Up @@ -111,11 +111,9 @@ void DoActorSetSpeed(DSWActor* actor, uint8_t speed)

actor->user.speed = speed;

int vel;
int vel = actor->user.__legacyState.Attrib->Speed[speed];
if (ActorFlaming(actor))
vel = actor->user.__legacyState.Attrib->Speed[speed] + (actor->user.__legacyState.Attrib->Speed[speed] >> 1);
else
vel = actor->user.__legacyState.Attrib->Speed[speed];
vel = (vel * 3) >> 1;

actor->vel.X = vel * maptoworld;
}
Expand Down Expand Up @@ -556,7 +554,7 @@ ANIMATOR* DoActorActionDecide(DSWActor* actor)
actor->user.Flags &= ~(SPR_TARGETED); // as far as actor
// knows, its not a
// target any more
if (actor->user.__legacyState.ActorActionSet->Duck && RANDOM_P2(1024<<8)>>8 < 100)
if (actor->hasState(NAME_Duck) && RANDOM_P2(1024<<8)>>8 < 100)
action = InitActorDuck;
else
{
Expand Down Expand Up @@ -819,7 +817,7 @@ int InitActorMoveCloser(DSWActor* actor)
if (!actor->checkStateGroup(NAME_Run))
actor->setStateGroup(NAME_Run);

(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();

return 0;
}
Expand Down Expand Up @@ -1183,7 +1181,7 @@ int InitActorAttack(DSWActor* actor)
}

// Hari Kari for Ninja's
if (actor->user.__legacyState.ActorActionSet->Death2)
if (actor->hasState(NAME_Death2))
{
const int SUICIDE_HEALTH_VALUE = 38;

Expand All @@ -1199,7 +1197,7 @@ int InitActorAttack(DSWActor* actor)
}


(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();

return 0;
}
Expand Down Expand Up @@ -1332,7 +1330,7 @@ int InitActorFindPlayer(DSWActor* actor)

int InitActorDuck(DSWActor* actor)
{
if (!actor->user.__legacyState.ActorActionSet->Duck)
if (!actor->hasState(NAME_Duck))
{
actor->setActionDecide();
return 0;
Expand All @@ -1354,7 +1352,7 @@ int InitActorDuck(DSWActor* actor)
}


(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();

return 0;
}
Expand Down Expand Up @@ -1693,7 +1691,7 @@ int InitActorReposition(DSWActor* actor)
if (!(actor->user.Flags & SPR_SWIMMING))
actor->setStateGroup(NAME_Run);

(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();

return 0;
}
Expand Down Expand Up @@ -1737,7 +1735,7 @@ int InitActorPause(DSWActor* actor)
{
actor->user.__legacyState.ActorActionFunc = DoActorPause;

(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/bunny.cpp
Expand Up @@ -1297,7 +1297,7 @@ int DoBunnyMove(DSWActor* actor)
if (actor->user.track >= 0)
ActorFollowTrack(actor, ACTORMOVETICS);
else
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();

// stay on floor unless doing certain things
if (!(actor->user.Flags & (SPR_JUMPING | SPR_FALLING)))
Expand Down
4 changes: 2 additions & 2 deletions source/games/sw/src/coolg.cpp
Expand Up @@ -735,7 +735,7 @@ int InitCoolgCircle(DSWActor* actor)

actor->user.WaitTics = (RandomRange(3)+1) * 120;

(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();

return 0;
}
Expand Down Expand Up @@ -901,7 +901,7 @@ int DoCoolgMove(DSWActor* actor)
ActorFollowTrack(actor, ACTORMOVETICS);
else
{
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();
}

if (RANDOM_P2(1024) < 32 && !(actor->spr.cstat & CSTAT_SPRITE_INVISIBLE))
Expand Down
4 changes: 2 additions & 2 deletions source/games/sw/src/coolie.cpp
Expand Up @@ -475,7 +475,7 @@ void EnemyDefaults(DSWActor* actor, ACTOR_ACTION_SET* action, PERSONALITY* perso
// find the number of long range attacks
for (wpn = wpn_cnt = 0; wpn < SIZ(actor->user.__legacyState.ActorActionSet->Attack); wpn++)
{
if (actor->user.__legacyState.ActorActionSet->Attack[wpn])
if (actor->hasState(NAME_Attack, wpn))
wpn_cnt++;
else
break;
Expand Down Expand Up @@ -588,7 +588,7 @@ int DoCoolieMove(DSWActor* actor)
if (actor->user.track >= 0)
ActorFollowTrack(actor, ACTORMOVETICS);
else
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();

KeepActorOnFloor(actor);

Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/eel.cpp
Expand Up @@ -590,7 +590,7 @@ int DoEelMove(DSWActor* actor)
if (actor->user.track >= 0)
ActorFollowTrack(actor, ACTORMOVETICS);
else
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();

DoEelMatchPlayerZ(actor);

Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/girlninj.cpp
Expand Up @@ -769,7 +769,7 @@ int DoGirlNinjaMove(DSWActor* actor)
ActorFollowTrack(actor, ACTORMOVETICS);
else
{
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();
}

// stay on floor unless doing certain things
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/goro.cpp
Expand Up @@ -557,7 +557,7 @@ int DoGoroMove(DSWActor* actor)
if (actor->user.track >= 0)
ActorFollowTrack(actor, ACTORMOVETICS);
else
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();

KeepActorOnFloor(actor);

Expand Down
4 changes: 2 additions & 2 deletions source/games/sw/src/hornet.cpp
Expand Up @@ -450,7 +450,7 @@ int InitHornetCircle(DSWActor* actor)

actor->user.WaitTics = (RandomRange(3)+1) * 60;

(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();

return 0;
}
Expand Down Expand Up @@ -616,7 +616,7 @@ int DoHornetMove(DSWActor* actor)
if (actor->user.track >= 0)
ActorFollowTrack(actor, ACTORMOVETICS);
else
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();

DoHornetMatchPlayerZ(actor);

Expand Down
1 change: 0 additions & 1 deletion source/games/sw/src/jweapon.cpp
Expand Up @@ -1268,7 +1268,6 @@ int PlayerInitChemBomb(PLAYER* pp)
actorNew->vel.X *= 0.75;
}

// actorNew->user.__legacyState.RotNum = 5;
actorNew->user.Flags |= (SPR_XFLIP_TOGGLE);

SetOwner(pp->actor, actorNew);
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/lava.cpp
Expand Up @@ -514,7 +514,7 @@ int DoLavaMove(DSWActor* actor)
if (actor->user.track >= 0)
ActorFollowTrack(actor, ACTORMOVETICS);
else
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();

KeepActorOnFloor(actor);

Expand Down
4 changes: 2 additions & 2 deletions source/games/sw/src/ninja.cpp
Expand Up @@ -2031,7 +2031,7 @@ int DoNinjaMove(DSWActor* actor)
ActorFollowTrack(actor, ACTORMOVETICS);
else
{
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();
}

// stay on floor unless doing certain things
Expand Down Expand Up @@ -2532,7 +2532,7 @@ static saveable_data saveable_ninja_data[] =

SAVE_DATA(NinjaAttrib),
SAVE_DATA(InvisibleNinjaAttrib),

SAVE_DATA(s_NinjaRun),
SAVE_DATA(sg_NinjaRun),
SAVE_DATA(s_NinjaStand),
Expand Down
9 changes: 4 additions & 5 deletions source/games/sw/src/player.cpp
Expand Up @@ -4883,12 +4883,12 @@ void DoPlayerWade(PLAYER* pp)

if (pp->Flags & (PF_PLAYER_MOVED))
{
if (plActor->user.__legacyState.Rot != plActor->user.__legacyState.ActorActionSet->Run)
if (plActor->checkStateGroup(NAME_Run))
plActor->setStateGroup(NAME_Run);
}
else
{
if (plActor->user.__legacyState.Rot != plActor->user.__legacyState.ActorActionSet->Stand)
if (plActor->checkStateGroup(NAME_Stand))
plActor->setStateGroup(NAME_Stand);
}

Expand Down Expand Up @@ -5973,7 +5973,6 @@ void DoPlayerDeathCheckKeys(PLAYER* pp)

plActor->setStateGroup(NAME_Stand);
plActor->spr.picnum = plActor->user.__legacyState.State->Pic;
plActor->spr.picnum = plActor->user.__legacyState.State->Pic;
plActor->spr.cstat &= ~(CSTAT_SPRITE_YCENTER);

//DoSpawnTeleporterEffect(plActor);
Expand Down Expand Up @@ -6543,12 +6542,12 @@ void DoPlayerRun(PLAYER* pp)
{
if (pp->Flags & (PF_PLAYER_MOVED))
{
if (plActor->user.__legacyState.Rot != plActor->user.__legacyState.ActorActionSet->Run)
if (plActor->checkStateGroup(NAME_Run))
plActor->setStateGroup(NAME_Run);
}
else
{
if (plActor->user.__legacyState.Rot != plActor->user.__legacyState.ActorActionSet->Stand)
if (plActor->checkStateGroup(NAME_Stand))
plActor->setStateGroup(NAME_Stand);
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/ripper.cpp
Expand Up @@ -1294,7 +1294,7 @@ int DoRipperMove(DSWActor* actor)
if (actor->user.track >= 0)
ActorFollowTrack(actor, ACTORMOVETICS);
else
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();

DoActorSectorDamage(actor);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/ripper2.cpp
Expand Up @@ -1307,7 +1307,7 @@ int DoRipper2Move(DSWActor* actor)
if (actor->user.track >= 0)
ActorFollowTrack(actor, ACTORMOVETICS);
else
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();

DoActorSectorDamage(actor);

Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/serp.cpp
Expand Up @@ -760,7 +760,7 @@ int DoSerpMove(DSWActor* actor)
if (actor->user.track >= 0)
ActorFollowTrack(actor, ACTORMOVETICS);
else
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();

// serp ring
if (actor->spr.pal != 16)
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/skel.cpp
Expand Up @@ -636,7 +636,7 @@ int DoSkelMove(DSWActor* actor)
if (actor->user.track >= 0)
ActorFollowTrack(actor, ACTORMOVETICS);
else
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();

KeepActorOnFloor(actor);

Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/sumo.cpp
Expand Up @@ -669,7 +669,7 @@ int DoSumoMove(DSWActor* actor)
if (actor->user.track >= 0)
ActorFollowTrack(actor, ACTORMOVETICS);
else
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();

KeepActorOnFloor(actor);

Expand Down
1 change: 1 addition & 0 deletions source/games/sw/src/swactor.h
Expand Up @@ -53,6 +53,7 @@ class DSWActor : public DCoreActor
void setStateGroup(FName label, int substate = 0); // substate is only valid for Attack and CloseAttack
bool checkStateGroup(FName label, int substate = 0);
bool hasState(FName label, int substate = 0);
void callStateAction();


};
Expand Down

0 comments on commit 89cce84

Please sign in to comment.