diff --git a/source/core/states.h b/source/core/states.h index 88f510ca6..c623acc9b 100644 --- a/source/core/states.h +++ b/source/core/states.h @@ -166,10 +166,6 @@ struct FDefiningState VMFunction* TickFunc; // called when ticking the state. VMFunction* MoveFunc; // called when moving the actor FScriptPosition scriptpos; - - // these are only here so we can use this struct directly in the first stage of transitioning the states in Blood. - FDefiningState* NextState; - int seqId; }; struct FStateLabels; diff --git a/source/core/zcc_compile_raze.cpp b/source/core/zcc_compile_raze.cpp index e08e30ca9..d4e886701 100644 --- a/source/core/zcc_compile_raze.cpp +++ b/source/core/zcc_compile_raze.cpp @@ -1045,6 +1045,7 @@ void ZCCRazeCompiler::CompileStates() state.EnterFunc = defstate.EnterFunc; statedef.AddStates(&state, "A", defstate.scriptpos); if (defstate.NextStaten != NAME_None) statedef.SetGotoLabel(defstate.NextStaten.GetChars()); + else statedef.SetStop(); } static_cast(c->ClassType())->ActorInfo()->AIStates.Reset(); diff --git a/source/games/blood/src/ai.cpp b/source/games/blood/src/ai.cpp index 7e1f2c43e..046531b37 100644 --- a/source/games/blood/src/ai.cpp +++ b/source/games/blood/src/ai.cpp @@ -77,16 +77,31 @@ void aiPlay3DSound(DBloodActor* actor, int soundid, AI_SFX_PRIORITY a3, int play // //--------------------------------------------------------------------------- -void aiNewState(DBloodActor* actor, FDefiningState* pAIState) +void aiNewState(DBloodActor* actor, FState* pAIState) { DUDEINFO* pDudeInfo = getDudeInfo(actor); actor->xspr.stateTimer = pAIState->Tics; actor->xspr.aiState = pAIState; - int seqStartId = pDudeInfo->seqStartID; + int seqStartId = -1; - if (pAIState->seqId >= 0) + switch (pAIState->StateFlags & STF_SPRITESEQMASK) + { + case STF_SPRITESEQNAME: + if (pAIState->sprite > 0) + I_Error("Named SEQs not supported yet!"); + break; + + case STF_SPRITESEQINDEX: + seqStartId = pAIState->sprite; + break; + + case STF_SPRITESEQOFFSET: + seqStartId = pAIState->sprite + pDudeInfo->seqStartID; + break; + } + + if (seqStartId >= 0) { - seqStartId += pAIState->seqId; if (getSequence(seqStartId)) seqSpawn(seqStartId, actor, pAIState->ActionFunc); } @@ -97,18 +112,10 @@ void aiNewState(DBloodActor* actor, FDefiningState* pAIState) void aiNewState(DBloodActor* actor, FName nAIState) { - auto cls = actor->GetClass(); - while (cls) + auto state = actor->FindState(nAIState); + if (state != nullptr) { - for (auto& state : static_cast(cls)->ActorInfo()->AIStates) - { - if (state.Label == nAIState) - { - aiNewState(actor, &state); - return; - } - } - cls = cls->ParentClass; + aiNewState(actor, state); } } @@ -630,14 +637,14 @@ void aiActivateDude(DBloodActor* actor) { actor->dudeExtra.thinkTime = 1; - if (actor->xspr.aiState->Label == NAME_zombieEIdle) aiNewState(actor, NAME_zombieEUp); + if (actor->xspr.aiState == actor->FindState(NAME_zombieEIdle)) aiNewState(actor, NAME_zombieEUp); break; } case kDudeZombieAxeLaying: { actor->dudeExtra.thinkTime = 1; - if (actor->xspr.aiState->Label == NAME_zombieSIdle) aiNewState(actor, NAME_zombieEStand); + if (actor->xspr.aiState == actor->FindState(NAME_zombieSIdle)) aiNewState(actor, NAME_zombieEStand); break; } case kDudeZombieButcher: diff --git a/source/games/blood/src/ai.h b/source/games/blood/src/ai.h index 6bf9df6db..3b66b4a1e 100644 --- a/source/games/blood/src/ai.h +++ b/source/games/blood/src/ai.h @@ -49,7 +49,7 @@ extern const int gCultTeslaFireChance[5]; bool dudeIsPlayingSeq(DBloodActor* pSprite, int nSeq); void aiPlay3DSound(DBloodActor* pSprite, int a2, AI_SFX_PRIORITY a3, int a4); void aiNewState(DBloodActor* actor, FName pAIState); -void aiNewState(DBloodActor* actor, FDefiningState* pAIState); +void aiNewState(DBloodActor* actor, FState* pAIState); void aiChooseDirection(DBloodActor* actor, DAngle a3); void aiMoveForward(DBloodActor*pXSprite); void aiMoveTurn(DBloodActor*pXSprite); diff --git a/source/games/blood/src/blood.cpp b/source/games/blood/src/blood.cpp index ed3621fd5..481936ade 100644 --- a/source/games/blood/src/blood.cpp +++ b/source/games/blood/src/blood.cpp @@ -718,19 +718,6 @@ void GameInterface::FinalizeSetup() actorinfo->TypeNum = pair->Key; } } - -// Make the StatesToDefine array temporarily operable to allow transitioning the state calls without first altering the state table implementation. -#pragma message("remove after state transitioning") - auto cls = PClass::FindActor("BloodDudeBase"); - for (auto& state : cls->ActorInfo()->AIStates) - { - state.seqId = state.sprite == 0 ? -1 : state.sprite & 0xffff; - state.NextState = nullptr; - for (auto& state2 : cls->ActorInfo()->AIStates) - { - if (state.NextStaten == state2.Label) state.NextState = &state2; - } - } } //--------------------------------------------------------------------------- diff --git a/source/games/blood/src/loadsave.cpp b/source/games/blood/src/loadsave.cpp index ff0b59cb0..8207d98f4 100644 --- a/source/games/blood/src/loadsave.cpp +++ b/source/games/blood/src/loadsave.cpp @@ -213,7 +213,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, XSPRITE& w, XSPRIT if (arc.BeginObject(keyname)) { arc("flags", w.flags, def->flags) - //("aistate", w.aiState, def->aiState) disabled until we can transition to engine states. + ("aistate", w.aiState, def->aiState) ("busy", w.busy, def->busy) ("txid", w.txID, def->txID) ("rxid", w.rxID, def->rxID) diff --git a/source/games/blood/src/mapstructs.h b/source/games/blood/src/mapstructs.h index 29af14e3f..4a9030172 100644 --- a/source/games/blood/src/mapstructs.h +++ b/source/games/blood/src/mapstructs.h @@ -60,7 +60,7 @@ class DBloodActor; struct XSPRITE { - FDefiningState* aiState; // ai + FState* aiState; // ai union { uint32_t flags;