Skip to content

Commit

Permalink
- more stateGroup wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed May 28, 2023
1 parent 7eb713a commit beb8368
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 45 deletions.
1 change: 1 addition & 0 deletions source/core/namedef_custom.h
Expand Up @@ -78,3 +78,4 @@ xx(Climb)
xx(Special)
xx(CloseAttack)
xx(Attack)
xx(Dive)
12 changes: 6 additions & 6 deletions source/games/sw/src/actor.cpp
Expand Up @@ -39,6 +39,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
#include "weapon.h"
#include "sprite.h"
#include "gamefuncs.h"
#include "ai.h"

BEGIN_SW_NS

Expand Down Expand Up @@ -535,7 +536,7 @@ void KeepActorOnFloor(DSWActor* actor)
{
if (actor->user.Flags & (SPR_SWIMMING))
{
if (actor->user.__legacyState.Rot != actor->user.__legacyState.ActorActionSet->Run && actor->user.__legacyState.Rot != actor->user.__legacyState.ActorActionSet->Swim && actor->user.__legacyState.Rot != actor->user.__legacyState.ActorActionSet->Stand)
if (!actor->checkStateGroup(NAME_Run) && !actor->checkStateGroup(NAME_Swim) && !actor->checkStateGroup(NAME_Stand))
{
// was swimming but have now stopped
actor->user.Flags &= ~(SPR_SWIMMING);
Expand All @@ -544,7 +545,7 @@ void KeepActorOnFloor(DSWActor* actor)
return;
}

if (actor->user.__legacyState.Rot == actor->user.__legacyState.ActorActionSet->Run)
if (actor->checkStateGroup(NAME_Run))
{
actor->setStateGroup(NAME_Swim);
}
Expand All @@ -555,7 +556,7 @@ void KeepActorOnFloor(DSWActor* actor)
else
{
// only start swimming if you are running
if (actor->user.__legacyState.Rot == actor->user.__legacyState.ActorActionSet->Run || actor->user.__legacyState.Rot == actor->user.__legacyState.ActorActionSet->Swim)
if (actor->checkStateGroup(NAME_Run) || actor->checkStateGroup(NAME_Swim))
{
actor->setStateGroup(NAME_Swim);
actor->spr.pos.Z = actor->user.oz = actor->user.loz - depth;
Expand Down Expand Up @@ -1076,9 +1077,6 @@ static STATE** getLegacyState(ACTOR_ACTION_SET* a, FName label, int subl)
return nullptr;
}

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

void DSWActor::setStateGroup(FName label, int subl)
{
auto a = user.__legacyState.ActorActionSet;
Expand All @@ -1099,4 +1097,6 @@ bool DSWActor::hasState(FName label, int subl)
return getLegacyState(a, label, subl) != nullptr;
}

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

END_SW_NS
4 changes: 2 additions & 2 deletions source/games/sw/src/ai.cpp
Expand Up @@ -421,7 +421,7 @@ int DoActorOperate(DSWActor* actor)
if (actor->user.ID == HORNET_RUN_R0 || actor->user.ID == EEL_RUN_R0 || actor->user.ID == BUNNY_RUN_R0)
return false;

if (actor->user.__legacyState.Rot == actor->user.__legacyState.ActorActionSet->Sit || actor->user.__legacyState.Rot == actor->user.__legacyState.ActorActionSet->Stand)
if (actor->checkStateGroup(NAME_Sit) || actor->checkStateGroup(NAME_Stand))
return false;

if ((actor->user.WaitTics -= ACTORMOVETICS) > 0)
Expand Down Expand Up @@ -816,7 +816,7 @@ int InitActorMoveCloser(DSWActor* actor)
{
actor->user.__legacyState.ActorActionFunc = DoActorMoveCloser;

if (actor->user.__legacyState.Rot != actor->user.__legacyState.ActorActionSet->Run)
if (!actor->checkStateGroup(NAME_Run))
actor->setStateGroup(NAME_Run);

(*actor->user.__legacyState.ActorActionFunc)(actor);
Expand Down
4 changes: 2 additions & 2 deletions source/games/sw/src/bunny.cpp
Expand Up @@ -1178,7 +1178,7 @@ void BunnyHatch(DSWActor* actor)

actorNew->user.ShellNum = 0; // Not Pregnant right now

NewStateGroup(actorNew, actorNew->user.__legacyState.ActorActionSet->Jump);
actorNew->setStateGroup(NAME_Jump);
actorNew->user.__legacyState.ActorActionFunc = DoActorMoveJump;
DoActorSetSpeed(actorNew, FAST_SPEED);
PickJumpMaxSpeed(actorNew, -600);
Expand Down Expand Up @@ -1226,7 +1226,7 @@ DSWActor* BunnyHatch2(DSWActor* actor)

actorNew->user.ShellNum = 0; // Not Pregnant right now

NewStateGroup(actorNew, actorNew->user.__legacyState.ActorActionSet->Jump);
actorNew->setStateGroup(NAME_Jump);
actorNew->user.__legacyState.ActorActionFunc = DoActorMoveJump;
DoActorSetSpeed(actorNew, FAST_SPEED);
if (TEST_BOOL3(actor))
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/ninja.cpp
Expand Up @@ -2427,7 +2427,7 @@ void InitPlayerSprite(PLAYER* pp, const DVector3& spawnpos, const DAngle startan
actor->spr.pal = PALETTE_PLAYER0 + pp->pnum;
actor->user.spal = actor->spr.pal;

NewStateGroup(pp->actor, actor->user.__legacyState.ActorActionSet->Run);
pp->actor->setStateGroup(NAME_Run);

pp->PlayerUnderActor = nullptr;

Expand Down
50 changes: 22 additions & 28 deletions source/games/sw/src/player.cpp
Expand Up @@ -1061,10 +1061,7 @@ void DoPlayerSpriteThrow(PLAYER* pp)
if (pp->CurWpn == pp->Wpn[WPN_SWORD] && pp->actor->user.__legacyState.Rot != sg_PlayerNinjaSword)
NewStateGroup(pp->actor, sg_PlayerNinjaSword);
else
//if (pp->CurWpn == pp->Wpn[WPN_FIST] && pp->actor->user.__legacyState.Rot != sg_PlayerNinjaPunch)
NewStateGroup(pp->actor, sg_PlayerNinjaPunch);
//else
// NewStateGroup(pp->actor, sg_PlayerNinjaThrow);
}
}

Expand All @@ -1085,13 +1082,13 @@ int DoPlayerSpriteReset(DSWActor* actor)

// need to figure out what frames to put sprite into
if (pp->DoPlayerAction == DoPlayerCrawl)
NewStateGroup(pp->actor, actor->user.__legacyState.ActorActionSet->Crawl);
pp->actor->setStateGroup(NAME_Crawl);
else
{
if (pp->Flags & (PF_PLAYER_MOVED))
NewStateGroup(pp->actor, actor->user.__legacyState.ActorActionSet->Run);
pp->actor->setStateGroup(NAME_Run);
else
NewStateGroup(pp->actor, actor->user.__legacyState.ActorActionSet->Stand);
pp->actor->setStateGroup(NAME_Stand);
}

return 0;
Expand Down Expand Up @@ -1423,7 +1420,7 @@ void DoPlayerWarpTeleporter(PLAYER* pp)
DoPlayerBeginRun(pp);
pp->DoPlayerAction = DoPlayerTeleportPause;

NewStateGroup(ppActor, ppActor->user.__legacyState.ActorActionSet->Stand);
ppActor->setStateGroup(NAME_Stand);

UpdatePlayerSprite(pp);
DoSpawnTeleporterEffect(ppActor);
Expand Down Expand Up @@ -2789,7 +2786,7 @@ void DoPlayerBeginJump(PLAYER* pp)

///DamageData[plActor->user.WeaponNum].Init(pp);

NewStateGroup(pp->actor, plActor->user.__legacyState.ActorActionSet->Jump);
plActor->setStateGroup(NAME_Jump);
}

//---------------------------------------------------------------------------
Expand All @@ -2816,7 +2813,7 @@ void DoPlayerBeginForceJump(PLAYER* pp)

///DamageData[plActor->user.WeaponNum].Init(pp);

NewStateGroup(pp->actor, plActor->user.__legacyState.ActorActionSet->Jump);
plActor->setStateGroup(NAME_Jump);
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -2992,7 +2989,7 @@ void DoPlayerBeginFall(PLAYER* pp)
// Only change to falling frame if you were in the jump frame
// Otherwise an animation may be messed up such as Running Jump Kick
if (plActor->user.__legacyState.Rot == plActor->user.__legacyState.ActorActionSet->Jump)
NewStateGroup(pp->actor, plActor->user.__legacyState.ActorActionSet->Fall);
plActor->setStateGroup(NAME_Fall);
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -3196,9 +3193,6 @@ void DoPlayerBeginClimb(PLAYER* pp)
pp->Flags |= (PF_CLIMBING|PF_WEAPON_DOWN);
actor->spr.cstat |= (CSTAT_SPRITE_YCENTER);

//DamageData[plActor->user.WeaponNum].Init(pp);

//NewStateGroup(pp->actor, pp->actor->user.__legacyState.ActorActionSet->Climb);
NewStateGroup(pp->actor, sg_PlayerNinjaClimb);
}

Expand Down Expand Up @@ -3464,7 +3458,7 @@ void DoPlayerBeginCrawl(PLAYER* pp)

//pp->posz = pp->loz - PLAYER_CRAWL_HEIGHT;

NewStateGroup(pp->actor, plActor->user.__legacyState.ActorActionSet->Crawl);
plActor->setStateGroup(NAME_Crawl);
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -3571,7 +3565,7 @@ void DoPlayerCrawl(PLAYER* pp)

if (!(pp->Flags & PF_PLAYER_MOVED))
{
NewStateGroup(pp->actor, plActor->user.__legacyState.ActorActionSet->Crawl);
plActor->setStateGroup(NAME_Crawl);
}

// If the floor is far below you, fall hard instead of adjusting height
Expand Down Expand Up @@ -4304,7 +4298,7 @@ void DoPlayerBeginDive(PLAYER* pp)
DoPlayerMove(pp); // needs to be called to reset the pp->loz/hiz variable
///DamageData[plActor->user.WeaponNum].Init(pp);

NewStateGroup(pp->actor, plActor->user.__legacyState.ActorActionSet->Dive);
plActor->setStateGroup(NAME_Dive);

DoPlayerDive(pp);
}
Expand Down Expand Up @@ -4357,7 +4351,7 @@ void DoPlayerBeginDiveNoWarp(PLAYER* pp)
pp->DiveDamageTics = 0;
DoPlayerMove(pp); // needs to be called to reset the pp->loz/hiz variable
///DamageData[plActor->user.WeaponNum].Init(pp);
NewStateGroup(pp->actor, plActor->user.__legacyState.ActorActionSet->Dive);
plActor->setStateGroup(NAME_Dive);
DoPlayerDive(pp);
}

Expand Down Expand Up @@ -4796,7 +4790,7 @@ void DoPlayerBeginWade(PLAYER* pp)

ASSERT(plActor->user.__legacyState.ActorActionSet->Run);

NewStateGroup(pp->actor, plActor->user.__legacyState.ActorActionSet->Run);
plActor->setStateGroup(NAME_Run);
}


Expand Down Expand Up @@ -4890,12 +4884,12 @@ void DoPlayerWade(PLAYER* pp)
if (pp->Flags & (PF_PLAYER_MOVED))
{
if (plActor->user.__legacyState.Rot != plActor->user.__legacyState.ActorActionSet->Run)
NewStateGroup(pp->actor, plActor->user.__legacyState.ActorActionSet->Run);
plActor->setStateGroup(NAME_Run);
}
else
{
if (plActor->user.__legacyState.Rot != plActor->user.__legacyState.ActorActionSet->Stand)
NewStateGroup(pp->actor, plActor->user.__legacyState.ActorActionSet->Stand);
plActor->setStateGroup(NAME_Stand);
}

// If the floor is far below you, fall hard instead of adjusting height
Expand Down Expand Up @@ -4967,7 +4961,7 @@ void DoPlayerBeginOperateVehicle(PLAYER* pp)

ASSERT(plActor->user.__legacyState.ActorActionSet->Stand);

NewStateGroup(pp->actor, plActor->user.__legacyState.ActorActionSet->Stand);
plActor->setStateGroup(NAME_Stand);
}

//---------------------------------------------------------------------------
Expand All @@ -4992,7 +4986,7 @@ void DoPlayerBeginOperateTurret(PLAYER* pp)

ASSERT(plActor->user.__legacyState.ActorActionSet->Stand);

NewStateGroup(pp->actor, plActor->user.__legacyState.ActorActionSet->Stand);
plActor->setStateGroup(NAME_Stand);
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -5755,7 +5749,7 @@ void DoPlayerBeginDie(PLAYER* pp)
pp->sop = nullptr;
pp->Flags &= ~(PF_TWO_UZI);

NewStateGroup(pp->actor, plActor->user.__legacyState.ActorActionSet->Run);
plActor->setStateGroup(NAME_Run);
pWeaponForceRest(pp);

switch (pp->DeathType)
Expand Down Expand Up @@ -5977,7 +5971,7 @@ void DoPlayerDeathCheckKeys(PLAYER* pp)
InitBloodSpray(plActor,true,-1);
}

NewStateGroup(plActor, plActor->user.__legacyState.ActorActionSet->Stand);
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);
Expand Down Expand Up @@ -6420,9 +6414,9 @@ void DoPlayerBeginRun(PLAYER* pp)
ASSERT(plActor->user.__legacyState.ActorActionSet->Run);

if (pp->Flags & (PF_PLAYER_MOVED))
NewStateGroup(pp->actor, plActor->user.__legacyState.ActorActionSet->Run);
plActor->setStateGroup(NAME_Run);
else
NewStateGroup(pp->actor, plActor->user.__legacyState.ActorActionSet->Stand);
plActor->setStateGroup(NAME_Stand);
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -6550,12 +6544,12 @@ void DoPlayerRun(PLAYER* pp)
if (pp->Flags & (PF_PLAYER_MOVED))
{
if (plActor->user.__legacyState.Rot != plActor->user.__legacyState.ActorActionSet->Run)
NewStateGroup(pp->actor, plActor->user.__legacyState.ActorActionSet->Run);
plActor->setStateGroup(NAME_Run);
}
else
{
if (plActor->user.__legacyState.Rot != plActor->user.__legacyState.ActorActionSet->Stand)
NewStateGroup(pp->actor, plActor->user.__legacyState.ActorActionSet->Stand);
plActor->setStateGroup(NAME_Stand);
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/ripper.cpp
Expand Up @@ -1241,7 +1241,7 @@ void RipperHatch(DSWActor* actor)
// make immediately active
actorNew->user.Flags |= (SPR_ACTIVE);

NewStateGroup(actorNew, actorNew->user.__legacyState.ActorActionSet->Jump);
actorNew->setStateGroup(NAME_Jump);
actorNew->user.__legacyState.ActorActionFunc = DoActorMoveJump;
DoActorSetSpeed(actorNew, FAST_SPEED);
PickJumpMaxSpeed(actorNew, -600);
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/ripper2.cpp
Expand Up @@ -1251,7 +1251,7 @@ void Ripper2Hatch(DSWActor* actor)
// make immediately active
actorNew->user.Flags |= (SPR_ACTIVE);

NewStateGroup(actorNew, actorNew->user.__legacyState.ActorActionSet->Jump);
actorNew->setStateGroup(NAME_Jump);
actorNew->user.__legacyState.ActorActionFunc = DoActorMoveJump;
DoActorSetSpeed(actorNew, FAST_SPEED);
PickJumpMaxSpeed(actorNew, -600);
Expand Down
1 change: 1 addition & 0 deletions source/games/sw/src/swactor.h
Expand Up @@ -40,6 +40,7 @@ class DSWActor : public DCoreActor
}

void Serialize(FSerializer& arc) override;

// wrappers to static class data. Must be stored in the meta data, but will require better means of access than what's currently available.
Personality* getPersonality();
int16_t* getCloseAttackPercent() { return CloseAttackPercent; }
Expand Down
8 changes: 4 additions & 4 deletions source/games/sw/src/track.cpp
Expand Up @@ -3000,7 +3000,7 @@ bool ActorTrackDecide(TRACK_POINT* tpoint, DSWActor* actor)

case TRACK_ACTOR_QUICK_DUCK:

if (actor->user.__legacyState.Rot != actor->user.__legacyState.ActorActionSet->Duck)
if (!actor->checkStateGroup(NAME_Duck))
{
actor->spr.Angles.Yaw = tpoint->angle;

Expand All @@ -3024,7 +3024,7 @@ bool ActorTrackDecide(TRACK_POINT* tpoint, DSWActor* actor)
HitInfo near{};
double z[2];

if (actor->user.__legacyState.Rot == actor->user.__legacyState.ActorActionSet->Sit || actor->user.__legacyState.Rot == actor->user.__legacyState.ActorActionSet->Stand)
if (actor->checkStateGroup(NAME_Sit) || actor->checkStateGroup(NAME_Stand))
return false;

actor->spr.Angles.Yaw = tpoint->angle;
Expand Down Expand Up @@ -3093,14 +3093,14 @@ bool ActorTrackDecide(TRACK_POINT* tpoint, DSWActor* actor)
break;

case TRACK_ACTOR_CRAWL:
if (actor->user.__legacyState.Rot != actor->user.__legacyState.ActorActionSet->Crawl)
if (!actor->checkStateGroup(NAME_Crawl))
actor->setStateGroup(NAME_Crawl);
else
actor->setStateGroup(NAME_Rise);
break;

case TRACK_ACTOR_SWIM:
if (actor->user.__legacyState.Rot != actor->user.__legacyState.ActorActionSet->Swim)
if (!actor->checkStateGroup(NAME_Swim))
actor->setStateGroup(NAME_Swim);
else
actor->setStateGroup(NAME_Rise);
Expand Down

0 comments on commit beb8368

Please sign in to comment.