feat: behavior states (#1918)

This commit is contained in:
David Markowitz
2025-10-19 23:16:36 -07:00
committed by GitHub
parent a70c365c23
commit 0dd504c803
8 changed files with 77 additions and 23 deletions

View File

@@ -160,13 +160,14 @@ void Strip::SpawnDrop(LOT dropLOT, Entity& entity) {
}
}
void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) {
void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent, UpdateResult& updateResult) {
auto& entity = *modelComponent.GetParent();
auto& nextAction = GetNextAction();
auto number = nextAction.GetValueParameterDouble();
auto valueStr = nextAction.GetValueParameterString();
auto numberAsInt = static_cast<int32_t>(number);
auto nextActionType = GetNextAction().GetType();
LOG_DEBUG("Processing Strip Action: %s with number %.2f and string %s", nextActionType.data(), number, valueStr.data());
// TODO replace with switch case and nextActionType with enum
/* BEGIN Move */
@@ -223,7 +224,8 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) {
unsmash.Send(UNASSIGNED_SYSTEM_ADDRESS);
modelComponent.AddUnSmash();
m_PausedTime = number;
// since it may take time for the message to relay to clients
m_PausedTime = number + 0.5f;
} else if (nextActionType == "Wait") {
m_PausedTime = number;
} else if (nextActionType == "Chat") {
@@ -258,6 +260,21 @@ void Strip::ProcNormalAction(float deltaTime, ModelComponent& modelComponent) {
for (; numberAsInt > 0; numberAsInt--) SpawnDrop(6431, entity); // 1 Armor powerup
}
/* END Gameplay */
/* BEGIN StateMachine */
else if (nextActionType == "ChangeStateHome") {
updateResult.newState = BehaviorState::HOME_STATE;
} else if (nextActionType == "ChangeStateCircle") {
updateResult.newState = BehaviorState::CIRCLE_STATE;
} else if (nextActionType == "ChangeStateSquare") {
updateResult.newState = BehaviorState::SQUARE_STATE;
} else if (nextActionType == "ChangeStateDiamond") {
updateResult.newState = BehaviorState::DIAMOND_STATE;
} else if (nextActionType == "ChangeStateTriangle") {
updateResult.newState = BehaviorState::TRIANGLE_STATE;
} else if (nextActionType == "ChangeStateStar") {
updateResult.newState = BehaviorState::STAR_STATE;
}
/* END StateMachine*/
else {
static std::set<std::string> g_WarnedActions;
if (!g_WarnedActions.contains(nextActionType.data())) {
@@ -330,7 +347,7 @@ bool Strip::CheckMovement(float deltaTime, ModelComponent& modelComponent) {
return moveFinished;
}
void Strip::Update(float deltaTime, ModelComponent& modelComponent) {
void Strip::Update(float deltaTime, ModelComponent& modelComponent, UpdateResult& updateResult) {
// No point in running a strip with only one action.
// Strips are also designed to have 2 actions or more to run.
if (!HasMinimumActions()) return;
@@ -354,9 +371,9 @@ void Strip::Update(float deltaTime, ModelComponent& modelComponent) {
// Check for trigger blocks and if not a trigger block proc this blocks action
if (m_NextActionIndex == 0) {
LOG("Behavior strip started %s", nextAction.GetType().data());
if (nextAction.GetType() == "OnInteract") {
modelComponent.AddInteract();
} else if (nextAction.GetType() == "OnChat") {
// logic here if needed
} else if (nextAction.GetType() == "OnAttack") {
@@ -365,7 +382,7 @@ void Strip::Update(float deltaTime, ModelComponent& modelComponent) {
Game::entityManager->SerializeEntity(entity);
m_WaitingForAction = true;
} else { // should be a normal block
ProcNormalAction(deltaTime, modelComponent);
ProcNormalAction(deltaTime, modelComponent, updateResult);
}
}