Browse Source

Fixed Agent plans, Combat, and Interacts

- I made a mistake with parameter ordering which caused me to append the wrong list, meaning neither Interacts nor CombatComponent subscribers were tracked properly
- Goals now are set to StartGoal instead of None so Agents can actually do things
- Control flow for Agent goals is now slightly more clear; no more switch case fallthrough
combatComponentRefactor
Macoy Madson 6 years ago
parent
commit
09641e5dff
  1. 5
      TODO.txt
  2. 4
      src/game/InteractComponentManager.cpp
  3. 24
      src/game/agent/AgentComponentManager.cpp
  4. 13
      src/game/agent/PlanComponentManager.cpp
  5. 2
      src/game/agent/combat/CombatComponentManager.cpp

5
TODO.txt

@ -24,9 +24,6 @@ Some sort of resource system
Could be something like ResourceDictionary<key, ResourceType> resources
then things could stuff in things from load or even hard coded (via resources["new thing"] = {})
Put HTN Tasks etc. in resource dictionaries? Who owns them?
Position vs GlobalPosition
As soon as possible, I need to decide if I need Chunk XYZ with Position XYZ
This depends on whether I ever want to support really large worlds
@ -77,6 +74,7 @@ Spawning very, very broken
Actually important: Put Entity integration into AActor!
Finish lifetime management
Only call ActorOnDestroy if it wasn't previously marked for destruction (in Actor.h)
Current lifetime management doesn't prevent segfault. Wait until agents all group up for repro
Combat
@ -88,6 +86,7 @@ Remember to put Galavant-specific UE code into a patch or something
------------------
Done
------------------
Put HTN Tasks etc. in resource dictionaries? Who owns them?
Spawning very, very broken
Segfault every time you replay in editor on scene component thing

4
src/game/InteractComponentManager.cpp

@ -1,6 +1,6 @@
#include "InteractComponentManager.hpp"
#include "../entityComponentSystem/EntityComponentManager.hpp"
#include "entityComponentSystem/EntityComponentManager.hpp"
#include "agent/AgentComponentManager.hpp"
namespace gv
@ -49,7 +49,7 @@ void InteractComponentManager::CreatePickups(const EntityList& entities, PickupR
newPickups.push_back(newPickup);
}
EntityListAppendList(entitiesToSubscribe, Subscribers);
EntityListAppendList(Subscribers, entitiesToSubscribe);
}
Pickup* InteractComponentManager::GetPickup(Entity pickupEntity)

24
src/game/agent/AgentComponentManager.cpp

@ -134,6 +134,7 @@ void AgentComponentManager::Update(float deltaSeconds)
{
AgentGoal newGoal;
newGoal.Def = needLevelTrigger.GoalDef;
newGoal.Status = AgentGoal::GoalStatus::StartGoal;
AddGoalIfUniqueType(goals, newGoal);
}
else if (needLevelTrigger.NeedsResource && needLevelTrigger.WorldResource)
@ -142,6 +143,7 @@ void AgentComponentManager::Update(float deltaSeconds)
newNeedResourceGoal.Def =
gv::g_AgentGoalDefDictionary.GetResource(RESKEY("GetResource"));
newNeedResourceGoal.WorldResource = needLevelTrigger.WorldResource;
newNeedResourceGoal.Status = AgentGoal::GoalStatus::StartGoal;
AddGoalIfUniqueType(goals, newNeedResourceGoal);
}
}
@ -208,15 +210,12 @@ void AgentComponentManager::Update(float deltaSeconds)
case AgentGoal::GoalStatus::InProgress:
{
// While goal is in progress, watch planner events for a conclusive status
bool entityConcludedPlan = false;
for (PlanExecutionEvent planEvent : planConclusiveExecutionEvents)
{
if (planEvent.entity != currentEntity)
continue;
// If we got this far we received a relevant conclusive event
entityConcludedPlan = true;
if (planEvent.status == PlanExecuteStatus::Failed)
{
if (goal.Def->NumRetriesIfFailed &&
@ -229,7 +228,6 @@ void AgentComponentManager::Update(float deltaSeconds)
goal.NumFailureRetries++;
goal.Status = AgentGoal::GoalStatus::StartGoal;
entityConcludedPlan = false;
}
else
goal.Status = AgentGoal::GoalStatus::Failed;
@ -240,16 +238,22 @@ void AgentComponentManager::Update(float deltaSeconds)
break;
}
// Fall through if we finished the plan (failed or otherwise)
if (!entityConcludedPlan)
break;
break;
}
case AgentGoal::GoalStatus::Failed:
case AgentGoal::GoalStatus::Succeeded:
case AgentGoal::GoalStatus::None:
LOGE << "Goal added with no status; it should be GoalStatus::StartGoal if it's "
"new";
break;
default:
goals.erase(headGoalIt);
break;
}
if (goal.Status != AgentGoal::GoalStatus::InProgress &&
goal.Status != AgentGoal::GoalStatus::StartGoal)
{
LOGD_IF(DebugPrint) << "Agent Goal concluded with status " << (int)goal.Status;
goals.erase(headGoalIt);
}
}
}

13
src/game/agent/PlanComponentManager.cpp

@ -167,12 +167,15 @@ void PlanComponentManager::Update(float deltaSeconds)
if (status < Htn::Planner::Status::Running_EnumBegin)
{
LOGD_IF(DebugPrint) << "Failed plan for Entity " << currentComponent->entity
<< " with code " << int(status) << "! Initial Call List:";
Htn::PrintTaskCallList(componentPlanner.InitialCallList);
if (DebugPrint)
{
LOGD << "Failed plan for Entity " << currentComponent->entity
<< " with code " << int(status) << "! Initial Call List:";
Htn::PrintTaskCallList(componentPlanner.InitialCallList);
// Plan failed, remove entity
LOGD_IF(DebugPrint) << "Plan not running/failed";
// Plan failed, remove entity
LOGD << "Plan not running/failed";
}
planStatus = PlanExecuteStatus::Failed;
entitiesToUnsubscribe.push_back(currentEntity);
}

2
src/game/agent/combat/CombatComponentManager.cpp

@ -57,7 +57,7 @@ void CombatComponentManager::CreateCombatants(const EntityList& entities,
}
// We've already made sure all entities in the list are unique
EntityListAppendList(entitiesToSubscribe, Subscribers);
EntityListAppendList(Subscribers, entitiesToSubscribe);
}
Combatant* CombatComponentManager::GetCombatant(Entity combatantEntity)

Loading…
Cancel
Save