- wrapped more direct access to the states.

This commit is contained in:
Christoph Oelckers 2023-05-24 16:58:48 +02:00
parent beb8368819
commit 89cce849e8
22 changed files with 71 additions and 76 deletions

View file

@ -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;
@ -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))
{
@ -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
@ -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);
@ -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);
@ -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

View file

@ -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;
}
@ -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
{
@ -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;
}
@ -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;
@ -1199,7 +1197,7 @@ int InitActorAttack(DSWActor* actor)
}
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();
return 0;
}
@ -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;
@ -1354,7 +1352,7 @@ int InitActorDuck(DSWActor* actor)
}
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();
return 0;
}
@ -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;
}
@ -1737,7 +1735,7 @@ int InitActorPause(DSWActor* actor)
{
actor->user.__legacyState.ActorActionFunc = DoActorPause;
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();
return 0;
}

View file

@ -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)))

View file

@ -735,7 +735,7 @@ int InitCoolgCircle(DSWActor* actor)
actor->user.WaitTics = (RandomRange(3)+1) * 120;
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();
return 0;
}
@ -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))

View file

@ -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;
@ -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);

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -450,7 +450,7 @@ int InitHornetCircle(DSWActor* actor)
actor->user.WaitTics = (RandomRange(3)+1) * 60;
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();
return 0;
}
@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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
@ -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),

View file

@ -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);
}
@ -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);
@ -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);
}
}

View file

@ -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;

View file

@ -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);

View file

@ -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)

View file

@ -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);

View file

@ -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);

View file

@ -53,6 +53,7 @@ public:
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();
};

View file

@ -154,7 +154,7 @@ short ActorFindTrack(DSWActor* actor, int8_t player_dir, int track_type, int* tr
{
case BIT(TT_DUCK_N_SHOOT):
{
if (!actor->user.__legacyState.ActorActionSet->Duck)
if (!actor->hasState(NAME_Duck))
return -1;
end_point[1] = 0;
@ -164,7 +164,7 @@ short ActorFindTrack(DSWActor* actor, int8_t player_dir, int track_type, int* tr
// for ladders only look at first track point
case BIT(TT_LADDER):
{
if (!actor->user.__legacyState.ActorActionSet->Climb)
if (!actor->hasState(NAME_Climb))
return -1;
end_point[1] = 0;
@ -174,7 +174,7 @@ short ActorFindTrack(DSWActor* actor, int8_t player_dir, int track_type, int* tr
case BIT(TT_JUMP_UP):
case BIT(TT_JUMP_DOWN):
{
if (!actor->user.__legacyState.ActorActionSet->Jump)
if (!actor->hasState(NAME_Jump))
return -1;
end_point[1] = 0;
@ -183,7 +183,7 @@ short ActorFindTrack(DSWActor* actor, int8_t player_dir, int track_type, int* tr
case BIT(TT_TRAVERSE):
{
if (!actor->user.__legacyState.ActorActionSet->Crawl || !actor->user.__legacyState.ActorActionSet->Jump)
if (!actor->hasState(NAME_Crawl) || !!actor->hasState(NAME_Jump))
return -1;
break;
@ -2901,7 +2901,7 @@ bool ActorTrackDecide(TRACK_POINT* tpoint, DSWActor* actor)
break;
case TRACK_ACTOR_JUMP:
if (actor->user.__legacyState.ActorActionSet->Jump)
if (actor->hasState(NAME_Jump))
{
actor->spr.Angles.Yaw = tpoint->angle;
@ -2918,7 +2918,7 @@ bool ActorTrackDecide(TRACK_POINT* tpoint, DSWActor* actor)
case TRACK_ACTOR_QUICK_JUMP:
case TRACK_ACTOR_QUICK_SUPER_JUMP:
if (actor->user.__legacyState.ActorActionSet->Jump)
if (actor->hasState(NAME_Jump))
{
int zdiff;
HitInfo hit{};
@ -2966,7 +2966,7 @@ bool ActorTrackDecide(TRACK_POINT* tpoint, DSWActor* actor)
case TRACK_ACTOR_QUICK_JUMP_DOWN:
if (actor->user.__legacyState.ActorActionSet->Jump)
if (actor->hasState(NAME_Jump))
{
actor->spr.Angles.Yaw = tpoint->angle;
@ -2990,7 +2990,7 @@ bool ActorTrackDecide(TRACK_POINT* tpoint, DSWActor* actor)
case TRACK_ACTOR_QUICK_SCAN:
if (actor->user.__legacyState.ActorActionSet->Jump)
if (actor->hasState(NAME_Jump))
{
ActorLeaveTrack(actor);
return false;
@ -3067,7 +3067,7 @@ bool ActorTrackDecide(TRACK_POINT* tpoint, DSWActor* actor)
}
case TRACK_ACTOR_JUMP_IF_FORWARD:
if (actor->user.__legacyState.ActorActionSet->Jump && actor->user.track_dir == 1)
if (actor->hasState(NAME_Jump) && actor->user.track_dir == 1)
{
if (!tpoint->tag_high)
actor->user.jump_speed = ACTOR_STD_JUMP;
@ -3080,7 +3080,7 @@ bool ActorTrackDecide(TRACK_POINT* tpoint, DSWActor* actor)
break;
case TRACK_ACTOR_JUMP_IF_REVERSE:
if (actor->user.__legacyState.ActorActionSet->Jump && actor->user.track_dir == -1)
if (actor->hasState(NAME_Jump) && actor->user.track_dir == -1)
{
if (!tpoint->tag_high)
actor->user.jump_speed = ACTOR_STD_JUMP;
@ -3112,7 +3112,7 @@ bool ActorTrackDecide(TRACK_POINT* tpoint, DSWActor* actor)
case TRACK_ACTOR_SIT:
if (actor->user.__legacyState.ActorActionSet->Sit)
if (actor->hasState(NAME_Sit))
{
if (!tpoint->tag_high)
actor->user.WaitTics = 3 * 120;
@ -3125,7 +3125,7 @@ bool ActorTrackDecide(TRACK_POINT* tpoint, DSWActor* actor)
break;
case TRACK_ACTOR_DEATH1:
if (actor->user.__legacyState.ActorActionSet->Death2)
if (actor->hasState(NAME_Death2))
{
actor->user.WaitTics = 4 * 120;
actor->setStateGroup(NAME_Death1);
@ -3134,7 +3134,7 @@ bool ActorTrackDecide(TRACK_POINT* tpoint, DSWActor* actor)
case TRACK_ACTOR_DEATH2:
if (actor->user.__legacyState.ActorActionSet->Death2)
if (actor->hasState(NAME_Death2))
{
actor->user.WaitTics = 4 * 120;
actor->setStateGroup(NAME_Death2);
@ -3144,7 +3144,7 @@ bool ActorTrackDecide(TRACK_POINT* tpoint, DSWActor* actor)
case TRACK_ACTOR_DEATH_JUMP:
if (actor->user.__legacyState.ActorActionSet->DeathJump)
if (actor->hasState(NAME_DeathJump))
{
actor->user.Flags |= (SPR_DEAD);
actor->vel.X *= 2;
@ -3157,7 +3157,7 @@ bool ActorTrackDecide(TRACK_POINT* tpoint, DSWActor* actor)
case TRACK_ACTOR_CLOSE_ATTACK1:
if (actor->user.__legacyState.ActorActionSet->CloseAttack[0])
if (actor->hasState(NAME_CloseAttack, 0))
{
if (!tpoint->tag_high)
actor->user.WaitTics = 2 * 120;
@ -3171,7 +3171,7 @@ bool ActorTrackDecide(TRACK_POINT* tpoint, DSWActor* actor)
case TRACK_ACTOR_CLOSE_ATTACK2:
if (actor->user.__legacyState.ActorActionSet->CloseAttack[1])
if (actor->hasState(NAME_CloseAttack, 1))
{
if (!tpoint->tag_high)
actor->user.WaitTics = 4 * 120;
@ -3221,7 +3221,7 @@ bool ActorTrackDecide(TRACK_POINT* tpoint, DSWActor* actor)
case TRACK_ACTOR_CLIMB_LADDER:
if (actor->user.__legacyState.ActorActionSet->Jump)
if (actor->hasState(NAME_Jump))
{
HitInfo near;

View file

@ -684,7 +684,7 @@ int DoZillaMove(DSWActor* actor)
if (actor->user.track >= 0)
ActorFollowTrack(actor, ACTORMOVETICS);
else
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();
KeepActorOnFloor(actor);

View file

@ -903,7 +903,7 @@ int DoZombieMove(DSWActor* actor)
ActorFollowTrack(actor, ACTORMOVETICS);
else
{
(*actor->user.__legacyState.ActorActionFunc)(actor);
actor->callStateAction();
}
// stay on floor unless doing certain things