Overview
UACFGroupAIComponent and UACFCompanionGroupAIComponent are two components of the ACF framework designed to handle group-based AI logic. These classes provide functionality to manage AI agents, including spawning, despawning, and issuing commands, as well as specialized behavior for companion groups.
UACFGroupAIComponent
Description
The UACFGroupAIComponent is a core component for managing groups of AI agents within the ACF framework. It provides functionalities to spawn, despawn, initialize, and control AI agents within a group. It also handles communication between agents and group-level decision-making.
Features
Spawn and despawn AI agents dynamically.
Initialize agents with specific behaviors and attributes.
Command all agents in the group using gameplay tags.
Assign AI agents to teams and handle inter-group dynamics.
Calculate the group's centroid and manage group-level actions.
Key Properties
groupLead: The actor leading the AI group.
bInBattle: Indicates if the group is currently engaged in combat.
AICharactersInfo: A list of information about the agents in the group.
AIToSpawn: Information about the AI agents queued for spawning.
bAlreadySpawned: Tracks if the group has already been spawned.
DefaultSpawnOffset: Determines the spawn offset for agents relative to the leader.
Key Methods
SpawnGroup(): Spawns all AI agents in the group.
DespawnGroup(): Despawns all AI agents and optionally updates the spawn list.
SendCommandToCompanions(FGameplayTag command): Sends a command to all agents in the group.
InitAgents(): Initializes all agents in the group.
AddAIToSpawn(FAISpawnInfo spawnInfo): Adds an AI character blueprint to the spawn queue.
RemoveAgentFromGroup(AACFCharacter character): Removes an AI agent from the group.
SetInBattle(bool inBattle, AActor newTarget): Updates the group's battle state.
GetAgentNearestTo(FVector location): Finds the nearest agent to a specific location.
Events
OnAgentsSpawned: Broadcasts when agents are spawned.
OnAgentsDespawned: Broadcasts when agents are despawned.
OnAgentDeath: Broadcasts when an agent dies.
OnAllAgentDeath: Broadcasts when all agents are dead.
Example Usage
// Example: Spawn a group and issue a command
UACFGroupAIComponent* GroupComponent = NewObject<UACFGroupAIComponent>(OwnerActor);
GroupComponent->SpawnGroup();
GroupComponent->SendCommandToCompanions(FGameplayTag::RequestGameplayTag(FName("Attack")));
UACFCompanionGroupAIComponent
Description
The UACFCompanionGroupAIComponent extends UACFGroupAIComponent to include functionality specific to companion AI behavior. This includes features like synchronizing experience points across the group and managing the group’s position relative to the leader.
Features
Adds experience points to all group members.
Dynamically updates the group centroid and despawns the group if too far from the leader.
Reacts to damage events of the leader to enter battle mode.
Monitors changes in the possessed character.
Key Properties
contr: The controller owning the component.
bDespawnIfTooDistanceFromLead: Determines whether the group despawns if too far from the leader.
Key Methods
AddExpToTheGroup(int32 Exp): Adds experience points to all group members.
SetDespawnIfTooDistanceFromLead(bool bDespawn): Enables or disables despawning based on distance from the leader.
UpdateCentroid(): Calculates the group's centroid and manages despawn logic if the group is too far from the leader.
HandleLeadGetHit(const FACFDamageEvent& damage): Reacts to the leader taking damage.
Example Usage
UACFCompanionGroupAIComponent* CompanionComponent = NewObject<UACFCompanionGroupAIComponent>(OwnerController);
CompanionComponent->AddExpToTheGroup(100);
CompanionComponent->SetDespawnIfTooDistanceFromLead(true);
Notes
Both components rely on specific data structures and systems within the ACF framework, such as FGameplayTag, TArray, and UWorld. They assume the presence of supporting classes like AACFCharacter and AACFAIController. Ensure these dependencies are correctly implemented in your project.