Skip to content

KAI_Actor

inkoalawetrust edited this page Oct 21, 2024 · 19 revisions

KAI_Actor

Class layout (Interactive):

Note: Right click on the linked nodes to use them.

flowchart TD
A[KAI_Actor]
click A "https://github.com/inkoalawetrust/KAI/wiki/KAI_Actor" "The base NPC class"
A --> B[KAI_Creature]
click B "https://github.com/inkoalawetrust/KAI/wiki/KAI_Creature" "The base class for most NPCs"
B --> C[KAI_Humanoid]
click C "https://github.com/inkoalawetrust/KAI/wiki/KAI_Humanoid" "The base class for smarter NPCs"
A --> D[KAI_BaseVehicle]
click D "https://github.com/inkoalawetrust/KAI/wiki/KAI_BaseVehicle" "The base class for NPC vehicles"
A --> G[KAI_EmplacementNPC]
click G "https://github.com/inkoalawetrust/KAI/wiki/KAI_EmplacementNPC" "The base class for NPC emplacements"
D --> F[KAI_BaseProp]
D --> E[KAI_BaseTurret]
click E "https://github.com/inkoalawetrust/KAI/wiki/KAI_BaseTurret" "The base class for turrets attached to NPC vehicles"
E --> H[KAI_BaseTurretProp]
Loading

Description

KAI_Actor is the base NPC class of the KAI library. It's the class from which all other NPC types inherit from. And only holds behavior that would be applicable for all kinds of NPCs.

Flags

These are the flags shared by all KAI NPCs.

NoTargetPrediction

The NPC will never use target prediction to lead its' shots ahead of its' target. Even if it uses the code required for that

MovesWithVelocity

The actor only moves by propelling itself with real momentum, like players do. Used to mark such KAI NPCs for the target prediction code to treat them differently, does nothing else by default.

IgnoreOrders

The actor ignores calls to SetNPCOrder() entirely.

Properties

These are the properties shared by all KAI NPCs.

ThreatLevel

The NPCs' threat level, used by the threat assessment system to determine how dangerous an NPC is. Non-KAI actors can also get a threat level using the KAI_DataToken item.

ThreatLevelThreshold

Specifies a threshold for a threat level, you can use this property to make your NPC perform a special action if another actors' threat level is at or above this level. Like using different attacks. Used by KAI_LandVehicleChase() to make vehicles drive away from NPCs at or above this threshold.

Inaccuracy

A Vector3 variable that specifies the radius of a box in each axis. In which the actors' aim will randomly vary within while target prediction is enabled. The actor slowly moves to the inaccurate position over time, and once within a tenth of the distance or less of it, a new random position within this box will be set for it to move to. In short, this function allows you to add inaccuracy to actors with predictive aiming.

InaccuracyFrequency

Determines how fast the actors' aim shifts between inaccurate positions. Default is 0.1.

ActorFollowDist

Doesn't necessarily do anything on its' own. But can be used to set a distance threshold which if lower (Or higher) changes the behavior of the NPC when following an actor in some way, like making them start going away from who they're following to avoid overcrowding.

Variables

These are the variables that are shared by all KAI NPCs, excluding properties.

CurrentOrder

Type: Integer The current order followed by the NPC, should only be changed with SetNPCOrder() Below is a list of all the built in-order enumerations (AKA the available orders.)

  • ORDER_NONE = 0: The NPC isn't following any order at all, the default order type for NPCs.
  • ORDER_FOLLOW = 1: The NPC is supposed to be following someone, most likely the player.
  • ORDER_STAY = 2: The NPC is just sitting in place when idling (Or even when fighting or something). Does nothing on its' own, so you can assign custom behavior to your NPCs when this order is set.
  • ORDER_WANDER = 3: The NPC is just wandering around, most likely when idle. Does nothing on its' own, so it's up to you to assign behavior when this order is on. Perhaps by calling KAI_Wander() in the NPC's Idle: or See: state if CurrentOrder == ORDER_FOLLOW.
  • ALLORDERS: A special enumeration whose value is whatever the maximum amount of orders in the NPCOrders enum is. Used to loop the orders around if SetNPCOrder() is called with Increment.

AttackStates

Type: Dynamic array

This is an array that stores all of the attack states of a KAI NPC. This is useful for NPCs that have multiple attack states that can't all be stored in the native MissileState and MeleeState variables. However, it is not a replacement for them, since they are still used by native and KAI code like NewChaseDir()'s monster back for example. Currently, it is mostly used by KAI_BaseTurret's turret traverse code.

Here is an example of how to assign attack states, from the PostBeginPlay() of the Military Vehicle Packs' APC:

	Override Void PostBeginPlay ()
	{
		TurretOffsets = (0.1,0,4.25);
		Super.PostBeginPlay();
		
		MissileState = FindState ("DeployMarines");
		AttackStates.Push (FindState("DeployMarines",True));
		AttackStates.Push (FindState("SpawnLoop",True));
		AttackStates.Push (FindState("EndDeploy",True));
	}

LastEnemyPosition, CurrentEnemyPosition

Type(s): Vector3

These 2 variables store the positions of the NPCs' current target pointer, LastEnemyPosition stores last ticks' position, and CurrentEnemyPosition stores the targets' position in the current tick. These variables are used by the target prediction code.

NextMovePos

Type: Vector3

The coordinates to the next position the NPC should move too, used by KAI_Wander() and KAI_MoveAway(). If not null, then those two functions will make the NPC move to this position before finding a new one.

NewPosStepCount

Type: Integer

How many steps the actor has taken before NextMovePos is reset, so the NPC will get a new point to move to. Used by KAI_Wander(), KAI_MoveAway() and KAI_VehicleRetreat() in case actor gets stuck trying to reach one position.

KAIHandler

Type: Pointer to KAI_EventHandler

A pointer to the libraries' event handler. Used to access the handlers' data (e.g the projectile array) and methods, without having to perform the expensive Find() operation every time. Instead, KAI NPCs cache this pointer to the handler once in PostBeginPlay().

OldAngle

Type: Double

The angle the actor was facing at in the last tick.

InaccuracyOffset

Type: Vector3

The current (Interpolated) inaccurate position that is added to the actors' aiming. These coordinates are relative to the targets' current position, and added on top of it as noise, to make the actor have imperfect aim.

NextInaccuracyOffset

Type: Vector3

The relative position that InaccuracyOffset is interpolating towards over time. Once the two vectors are within a tenth of the original distance or less of each other, this vector is update to a new random value based on the Inaccuracy property.

Hazards

Type: Dynamic array

Stores HazardInfo entries to each hazard that the NPC is currently keeping track of. Given by the threats to the NPC. Can be iterated through to determine what to do with this information, e.g what threats to flee from

Groups

Type: Dynamic array

Stores pointers to all the groups that the NPC is a part of, useful to actually allow KAI NPCs to read group data and make decisions like if they should follow the group leader, if they should react to certain members being near them, etc.

Functions

Clone this wiki locally