-
Notifications
You must be signed in to change notification settings - Fork 0
AI functions
This page covers all the non-movement AI-related functions that are shared by all KAI NPCs.
- Other: The actor to check the melee range to.
- Range: The range of the check. Default is -1, which means that the actors' MeleeRange is used instead.
- Flags: The flags to use for the check.
- CMR_NOHITFRIEND: Do not run HitFriend() during the check.
- CMR_3DDISTANCE: Use Distance3D() instead of Distance2D() for the range check. This flag is also used by KAI_CheckMissileRange().
- CMR_INVERTDIST: Used by KAI_CheckMissileRange(). This flag inverts the distance formula the function uses to decide if the NPC should attack, meaning that the actor is MORE likely to attack the further Other is, instead of less likely. THIS FLAG ALTERS HOW THE AGGRESSIONMULTIPLIER WORKS !
- CMR_IGNOREDIST: Used by KAI_CheckMissileRange(). Making that function ignore the arbitrary distance check entirely, so the chance of attacking doesn't scale with distance at all.
- Returns true if Other is in Range of the caller, false otherwise.
This function is a ZScript version of CheckMissileRange().
- Other: The actor to check the missile range to.
- Flags: The flags to use for the check. Uses, the same flags as KAI_CheckMeleeRange().
- Returns true if Other is in range of the target, the chance of returning true scales with the distance to the target, like CheckMissileRange(). Unless CMR_IGNOREDIST is true.
This function is a ZScript version of CheckMissileRange(), besides supporting 3D distance checks, it also supports the AggressionMultiplier property.
- Flags, MinSeeDist, MaxSeeDist, MaxHearDist, FOV, Label: These parameters are the exact same as their A_LookEx() counterparts.
- ExtraFlags: Extra flags used by KAI_Look() itself, as opposed to A_LookEx's own flags.
- KAIL_CHASETARGET: If the caller already has a target, then make the actor go to the specified sight state. Useful for when A_LookEx itself doesn't do this.
- KAIL_NOTEMPSTAND: The caller won't temporarily enable +STANDSTILL if it isn't already enabled, when called by friendly monsters. If this isn't on, then friendly monsters will not begin moving when they hear the player.
- None
This is a generic wrapper for A_LookEx(), that includes a fix for monsters not going to their See state when they already have a target, and also makes friendly monsters not begin moving when they hear a player by default.
For more information, click here.
For more information, click here.
- CheckDist: How far ahead of the actor to check for obstacles, in map units.
- CheckSlices: How many slices around the actor should be checked? i.e if this is set to 16, the function will check every 22.5 degrees from the left to right for an obstructions. This is the "resolution" of the check, so to speak.
- CheckSpacing: Used by IsPosReachable() (Which is what checks each slice), how far apart should the steps be spaced? Normally it makes sense to space them by the movement speed of the caller.
- The position the actor should move to, to try and avoid the obstacle(s) ahead, if any. If all slices around the actor are clear, it just returns a NaN/null vector.
- If the function found an obstruction around the actor.
Tries to make the actor avoid any obstacles around it by firing a series of IsPosReachable() checks in a 360 degree field around them. Divided by CheckSlices.
For more information, click here.
For more information, click here.
- TargetPos: The position to check if the caller has a valid path to.
- DistCutoff: The amount of map units to trim off the distance between the callers' pos and TargetPos. Useful for subtracting the radius of another actor, so that if you are checking if a position to another actor can be reached, the check doesn't return false because the actor itself is in the way.
- Spacing: Determines how far apart the position checks from the callers' position to TargetPos are. Default is 0, which makes the spacing be the diameter of the callers' hitbox.
- IgnoreActors: Makes the check ignore any blocking actors in the way by temporarily enabling +THRUACTORS.
- Dropoff: Passed to TryMove()'s dropoff parameter.
- Returns true if the caller can move up to TargetPos.
Checks if the caller can move from their current position towards TargetPos without hitting any obstacles along the way. The Spacing parameter can be used to patch up holes in the path check, such as corners being considered possible to cross.
The function will sometimes return true for positions that are behind drops too tall for the caller. It also doesn't seem to account properly for static portals. The former bug I have no idea how to fix, the latter bug I may be able to fix.
- TargetRadius: The maximum radius up to which the function checks for free space at the callers' position.
- TargetHeight: Ditto, but for the height.
- Iterations: How many steps between a radius and height of 0 and the target values will be performed, i.e if the radius is 256 and the there's 8 iterations, it'll go like 32, 36, 42, 51, 64, 85, 128, 256. Default is 8 steps.
- ActorBlock: Should the function also check for blocking actors? Default is false, meaning it's only concerned with level geometry.
Note: If the space is wide open at the specified target height and radius, all these returns will be -1.
- How many iterations/steps the function performed before something blocked the caller, steps are counted down, so the more steps left, the more crammed the area generally is, because the function returned that its' crammed sooner.
- The radius at which the function returned that the space is blocked.
- Ditto, but for the height.
Does a crude check for how crammed the area around the caller is. Works by making the callers' hitbox large and large, and checking for collision on every iteration, up to the target size. And returning non -1, -1, 1, value if the check is blocked by level geometry and/or actors that would block the caller along any step of the way.
This code stores all the return values of the function, and checks if the radius at which the space check prematurely ended is less than 192 map units away to arbitrarily determine that the space the caller is in is crammed.
Int Iterations; Double Rad; Double Eh;
[Iterations, Rad, Eh] = CheckSpaceSize (384,384,16);
TooCrammed = Rad < 192; //If there's any level geometry blocking us less than 192MU away, we're in a crammed area.
- Range: The range to look for enemies within, if it's 0 or less, no search is performed. Default is 256 map units.
- Returns a pointer to the enemy that is closest to the caller, if any.
Finds the nearest enemy NPC in Range of the caller that is alive, can be targeted, and is visible. And returns a pointer to them. Used by KAI_LandVehicleChase() to make vehicles stay away from enemies instead of charging headfirst like normal Doom monsters.
- Other: The actor to get the proper aim position to.
- Offsets: The Vector3 offsets relative to the caller to fire the line of sight checks from. Default is (0,0,0).
Returns which part of the Other actor the calling NPC can shoot at. Using the A_Face() flags. By default, it returns FAF_MIDDLE, but if the middle of the Other actor is covered, it will return FAF_TOP, and if that is blocked too, it will return FAF_BOTTOM. If the whole actor is blocked, it falls back to FAF_MIDDLE. Used by KAI_TurretRefire() and KAI_TurretCheckLOF.
This is how KAI_TurretRefire() uses the function after every attack to update what part of the target the turret should aim at: `TurretAimPos = GetFAFAimPos(Target);
- Sharee: The actor passing their target to the caller.
- NewTarget: The actor the Sharee wants to pass to the caller.
- IgnoreAllegiance: The function will set the callers' target to NewTarget even if the Sharee is hostile.
Used to pass a target from one KAI NPC to another, working in a similar manner to CopyFriendliness()'s target changing code. Does nothing if no NewTarget is passed, if the caller is dormant, if the caller is patrolling with bChaseGoal, or if the NewTarget cannot actually be targeted.
- Returns true if the callers' target was successfully set.
An NPC can call the function on another KAI NPC like this to change their target:
OtherNPC.KAI_ShareTarget(Self,Target);
This will make the OtherNPC change their target to the same one as the NPC doing the target share.
- Returns true if the NPC used a line.
Makes the NPC use any pushable and usable lines it touches, similar to the native line using code of monsters. Used by KAI_MoveTowards()
- Returns the callers' friendplayer.
Gets the calling NPCs' friendplayer, without running into VM aborts. In most cases, this should be used in place of plainly calling Players[FriendPlayer]
.
- Returns true if the NPC is in any particular attack state.
This function checks if the caller is in any of the states defined in the AttackStates[] array, but first checks if they are within their MissileState or MeleeState states currently.
- IgnorePlayerLeaders: Ignore the special precedence of player-led groups, and simply return the first group on the list.
- Returns the first NPC group found in the NPCs' Groups[] array where the leader is a player, otherwise it just tries to return the first group in the list, if any.
These functions are related to the NPCs' order system.
- Order: The exact order the NPC should switch to. If Increment is true, this is ignored.
- Increment: Instead of picking a specific order, move to the next order in the list. And loop back around at the end of the list (ORDER_NONE is ignored).
- Commander: A pointer to the actor who is demanding the order, if any.
- IgnoreAllegiance: If there IS a specified Commander, their order will be ignored if they're hostile to the ordered NPC, unless this is true. Default is false.
- FromACS: Specifies if the function is being called from ACS, default is false. This shouldn't be set to true unless you're actually calling the function from ACS.
One of the primary functions of the order system. Sets the current built-in order type the NPC is following, or increments through the list. Can also be used to pass a commander making the order in cause it is wanted for any special behavior. The execution of this function can be expanded with OnOrderChange() and AfterOrderChange()
- Activator: A pointer to the functions caller from ACS, which would be the script activator. The activator is used as the Commander so make sure there's no activator when this function is called from ACS if you don't want a commander.
- NPCTID: The TID of all the NPCs whose order will be changed.
- Order: The exact order the NPC should switch to. If Increment is true, this is ignored.
- Increment: Instead of picking a specific order, move to the next order in the list. And loop back around at the end of the list (ORDER_NONE is ignored).
- IgnoreAllegiance: If there IS a specified Commander, their order will be ignored if they're hostile to the ordered NPC, unless this is true. Default is false.
A version of SetNPCOrder() that can be called from ACS (Such as for scripted sequences) using ScriptCall().
This is an example of how the function can be used in an Enter ACS script (Where the player entering is the activator). To make all KAI NPCs with a TID of 42 follow the player.
Script "MapInit" Enter
{
ScriptCall ("KAI_Actor","ACS_SetNPCOrder",45,ORDER_FOLLOW,False,False);
}
These functions in particular allow NPCs to interact with the hazard system.
- Hazard: The hazard to check.
- Returns true if the NPC is in range of the specified hazard.
Checks if the calling actor is in the range of the specified hazard, or in the case of HAZ_SECTOR hazards, if the actor is within the same sector that can be found at the hazards' Position vector.
- Hazard: The hazard to check.
Returns the distance to Hazard, either the hazards' Origin, or if it's an attack type hazard, the distance to its' Position vector. Returns a distance of 0 if the NPC is inside the same sector as a sector hazard.
- Hazard: The hazard to check.
- AttackerIsOrigin: If it's a HAZARD_ATTACK type hazard, considering the origin to be the hazards' Origin pointer (The shooter), instead of its' Position vector (Where the attack will land)/
- Returns the origin of Hazard. Returns an empty/NaN vector if Hazard is null.
Gets the origin position of the specified hazard, regardless of type, since different hazard types have different actual origin positions.
- Home
- Features
- Classes
- Functions
- Guides