From 865cbd2fd934341223b6ab945a6902798297695a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 7 Oct 2023 17:38:46 +0200 Subject: [PATCH] parse AI states into a temp array. --- source/core/actorinfo.h | 1 + source/core/states.h | 14 ++++++++++++ source/core/thingdef_properties.cpp | 20 ----------------- source/games/blood/src/blood.cpp | 35 +++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 20 deletions(-) diff --git a/source/core/actorinfo.h b/source/core/actorinfo.h index 4c89033e6..df1b4df15 100644 --- a/source/core/actorinfo.h +++ b/source/core/actorinfo.h @@ -44,6 +44,7 @@ struct FActorInfo // these are temporary. Due to how Build games handle their tiles, we cannot look up the textures when scripts are being parsed. TArray SpriteSetNames; + TArray AIStates; // these can only get fully resolved after parsing everything. FState* OwnedStates = nullptr; int NumOwnedStates = 0; diff --git a/source/core/states.h b/source/core/states.h index 39b23d928..3247f02d6 100644 --- a/source/core/states.h +++ b/source/core/states.h @@ -149,6 +149,20 @@ public: }; +// used during definition of AIState properties. +struct FDefiningState +{ + int sprite; + int Type; + int Tics; + FName Label; + FName NextState; + VMFunction* ActionFunc; // called when an attached animation triggers an event. (i.e. Blood's SEQs. Should be made game independent.) + VMFunction* EnterFunc; // called when entering the state. + VMFunction* TickFunc; // called when ticking the state. + VMFunction* MoveFunc; // called when moving the actor +}; + struct FStateLabels; struct FStateLabel { diff --git a/source/core/thingdef_properties.cpp b/source/core/thingdef_properties.cpp index d7aefe7ea..946df6102 100644 --- a/source/core/thingdef_properties.cpp +++ b/source/core/thingdef_properties.cpp @@ -392,24 +392,4 @@ DEFINE_PROPERTY(precacheclass, Sssssssssssssssssssssssssssssss, CoreActor) } } -// hopefully this can later be integrated into the state block and made usable for all games. -// for now we need something that can be made to work quickly without messing around with the parser. -DEFINE_PROPERTY(aistate, SSIIGGGGs, CoreActor) -{ - PROP_STRING_PARM(label, 0); - PROP_STRING_PARM(seq, 1); // either a sequence name or an Id as '#123'. - PROP_INT_PARM(type, 2); - PROP_INT_PARM(duration, 3); - PROP_FUNC_PARM(action, 4); - PROP_FUNC_PARM(enter, 5); - PROP_FUNC_PARM(tick, 6); - PROP_FUNC_PARM(move, 7); - const char* next = nullptr; - if (PROP_PARM_COUNT > 8) - { - PROP_STRING_PARM(_next, 8); - next = _next; - } - -} diff --git a/source/games/blood/src/blood.cpp b/source/games/blood/src/blood.cpp index a9925c663..043a86e94 100644 --- a/source/games/blood/src/blood.cpp +++ b/source/games/blood/src/blood.cpp @@ -781,4 +781,39 @@ DEFINE_PROPERTY(dmgcontrol, IIIIIII, BloodActor) } } +// the state parser with its special semantics cannot be extended to handle this right. :( +DEFINE_PROPERTY(aistate, SSIIGGGGs, CoreActor) +{ + PROP_STRING_PARM(label, 0); + PROP_STRING_PARM(seq, 1); // either a name, an absolute ID with #000 or a relative ID with +000. Empty string means nothing + PROP_INT_PARM(type, 2); + PROP_INT_PARM(duration, 3); + PROP_FUNC_PARM(action, 4); + PROP_FUNC_PARM(enter, 5); + PROP_FUNC_PARM(tick, 6); + PROP_FUNC_PARM(move, 7); + const char* next = nullptr; + if (PROP_PARM_COUNT > 8) + { + PROP_STRING_PARM(_next, 8); + next = _next; + } + bag.Info->ActorInfo()->AIStates.Reserve(1); + auto& state = bag.Info->ActorInfo()->AIStates.Last(); + + char* endp = (char*)""; + if (*seq == 0) state.sprite = 0; + else if (*seq == '#') state.sprite = strtoull(seq + 1, &endp, 10) | 0x10000000; + else if (*seq == '+') state.sprite = strtoull(seq + 1, &endp, 10) | 0x20000000; + + state.Label = label; + state.Type = type; + state.Tics = duration; + state.ActionFunc = action; + state.EnterFunc = enter; + state.MoveFunc = move; + state.TickFunc = tick; + state.NextState = next ? FName(next) : FName(NAME_None); +} + END_BLD_NS