Behavior parameter

From AI Product Manuals
Revision as of 16:10, 1 October 2021 by Davemark (talk | contribs) (Initial Entries)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
This page is part of the IAUS Manual.BrainBehaviorBehavior TypeDecisionAI Entity

This item is a component of a Behavior.

Concept

A Behavior Parameter is attached to a Behavior to help define specific things that behavior needs to execute. Some of them are booleans about whether or not something should occur. For example, specifying an arrival distance to a location or target that the character will be moving to, or whether the behavior should reset where the character is looking or facing when it it executes. Others can be used to pass data into the execution of the behavior. If an action is supposed to place a tag onto a target agent, for instance, the specific tag to be applied can be held in the appropriate behavior parameter.

While there are some built-in behavior parameters from the start (with their relevant code), they can be added to—both in data and with the relevant code for how it is executed—in order to support game-specific things.

Implementation

Code

The list of available Behavior Params is held in the enums file as BehaviorParameterType.

enum class BehaviorParamType
{
	ThinkDelay = 1,		// How long to wait before thinking after performing this action. (Good for completing animations.)
	StopMovement = 2,		// Should this behavior stop any existing movement? (1 or 0 for boolean equivalent.)
	ArrivalDistance = 3,		// What is the distance to use for "arrival"?
	SetLooking = 4,		// Set head looking. (0=No change, 1=target, 2=self orient)
	...
}

Behavior Parameters are stored in the Behavior themselves in a sparse data construct (Dictionary in C# or unordered_map in C++). For readability, these are defined in a typedef, "BehaviorParamMap".

typedef std::unordered_map<BehaviorParamType, float> BehaviorParamMap;

They are contained in the Behavior class as "behaviorParams". (Note this must exist in both the IBehavior interface as well as the Behavior class itself.)

BehaviorParamMap behaviorParams;

They are accessed by a function that checks to see if it exists in that behavior's parameters and, if not, returns a default.

virtual float GetParameterOrDefault(BehaviorParamType thisParamType, float thisDefault);

These checks are often performed in individual functions for readability and called from the SetupBehavior function at the start of execution of each behavior.

void Behavior::SetupBehavior(ContextInfo* thisContext)
{
	StopMovementIfDesignated(thisContext);		
	StopAttackIfDesignated(thisContext);
	ApplyTagToTargetIfDesignated(thisContext);
	ManageBPIfDesignated(thisContext);
	...
}

Using simply the first one in that example list, this is a simple boolean check for the parameter to see if the behavior should force the stoppage of moment.

void Behavior::StopMovementIfDesignated(ContextInfo* thisContext)
{
	bool shouldStop = GetParameterOrDefault(&behaviorParams, BehaviorParamType::StopMovement, 0.0);
	if (shouldStop)
	{
		thisContext->MyBrain()->AbortMovement();
	}
}

Data