-
Notifications
You must be signed in to change notification settings - Fork 0
KAI_BaseVehicle
Parent class: KAI_Actor
Child classes:
All the vehicles currently in my Military Vehicles Pack as of version 0.4.0.
This is the base NPC class for all vehicle NPCs. This class covers any vehicles you may want to add to your mod, and has vehicle-specific behavior and code to make vehicles behave differently from normal monsters.
As of 5/5/2023, it is the most fully fledged NPC base, since the KAI library was made out of the base vehicle code of my MVP mod.
Vehicle.turret.mp4
NPC vehicles have the ability to have turrets attached to them, that move and act independent of the vehicle. The behavior of the turrets, how they are spawned and attached, etc, are completely customizable. Vehicle turrets can also be made to visually change their elevation based on their pitch, if you have the sprites for it. And it's not a visual effect either, turrets can have actually elevation limits to how far up or down they can look, so a turret could be made unable to just shoot straight up or down. And much more !
For more information on turrets, click here.
Headlights.mp4
NPC vehicles have a configurable system that allows you to give the vehicle headlights, which it will turn on and off when it is inside dark sectors. The size, color, cone etc of the headlight can be customized as well, along with how dark a sector needs to be for the vehicle to turn its' headlights on.
NPC vehicles have the ability to crush corpses they touch, with the maximum dimensions of a corpse they can crush being configurable through properties. Keep in mind that crushing corpses has to manually be handled with a function call (TODO: Add link to KAI_CrushCorpses()) however.
- Stay away from enemies by default instead of charging headfirst like Doom monsters normally do. And can retreat from targets above a certain threshold.
- Friendly vehicles keep some amount of distance between themselves and the player when following them. So players aren't dogpiled by multiple vehicles.
- Can stay in place to let their turrets fire.
- Can stop chasing their target after not seeing it for a certain amount of time, in case they get stuck trying to head to an unreachable enemy.
These are the variables shared by all vehicles and turrets.
- DEFAULT_HEARDISTANCE = 4096: The default hear distance the vehicles' and turrets' KAI_Look() calls use.
- DEFAULT_SEEDISTANCE = 8192: The default sight distance the vehicles' and turrets' KAI_Look() calls use.
Type: Actor pointer
A pointer to the enemy that is closest to the vehicle, if any. Used in KAI_LandVehicleChase() to make vehicles keep a set distance from all enemies.
Type: Integer
How long the vehicle has been chasing its' target for since it last saw it. Used in conjunction with the SearchTime property.
Type: Integer
Used by the StayStillAndShoot (TODO: Add link) virtual function to put a cap on how long until the vehicle can decided to stand around and shoot again.
Type: Dynamic array
A dynamic array that stores pointers to each of the vehicle's headlights. Only accepts pointers to KAI_Headlight actors. Used to keep track of the headlights to turn them on or off or remove them when needed.
Type: Boolean
Returns if the headlights should currently be on, this updates every tick based on if the current sectors' light level is below the HeadlightLevel, so it should not be touched, only read.
Type: KAI_BaseTurret pointer
A pointer to the vehicles' turret, if any.
Type: Vector3
The relative offsets to pass on top of the turrets' own attachment offsets. Turrets stick to the top of the vehicle's hitbox, so this is a useful property to perform micro-adjustments to the attachment height to fix small sprite clipping issues. Should be set before SpawnVehicleTurret() (TODO: Add link) is called. This will be made into a property once GZDoom 4.11 releases.
Type: Boolean
Used in the headlight control functions (TODO: Add link) to prevent the headlights from being turned on and off every tick. Like HeadlightsOn this should not be modified, only read.
These are the flags shared by all vehicles and turrets.
Does nothing by default. Just marks the vehicle as being able to transport/spawn NPCs.
Disables the headlight system for the vehicle entirely.
If the vehicle has a threat level, and its' turret doesn't. Then the vehicles' threat level will be passed to the turret.
These are properties shared by all vehicles and turrets.
The class name of the vehicle turret to attach to the vehicle. This can only be an actor based on KAI_BaseTurret.
If the light level of the sector the vehicle is currently in is below this threshold, the vehicle will turn on its' headlights. Default is 104.
If an enemy is within this range of the vehicle, KAI_LandVehicleChase() should make it drive away from them. This range is 4 times longer for targets over the vehicle's ThreatLevelThreshold. If this is 0 or less, the vehicle will not drive away from enemies at all. Default is 768.
How long does the vehicle keep chasing its' target after losing sight of it, before giving up ? If this is 0 or less, vehicles never stop chasing their target after it goes out of sight, like normal Doom monsters. Keep in mind that this timer updates every time KAI_LandVehicleChase() is called, not every tick !
The maximum radius and height, respectively, of a corpse that the vehicle will be able to crush, anything over this will be uncrushable. Remember that corpse crushing has to be handled manually with the KAI_CrushCorpses() (TODO: Add link) function.
These are the virtual functions that can be accessed by KAI_BaseVehicle and any of its' descendants.
- None
Handles spawning a turret for the vehicle based on the value of VehicleTurret. And stores it in the vehicles' turret pointer.
- None
Override this to spawn headlights for your vehicle with SpawnVehicleHeadlight() (TODO: Add heading link to that function).
- CheckSightFrom: The actor to check their sight to their target.
- Returns true if the vehicle should stay still. False otherwise.
Checks if the vehicle should stay still to let its' turret shoot. By default this just checks if the vehicle has a turret that can shoot, and then checks if the vehicle is further from the enemy closest to it than its' RetreatRange. If these conditions are met, it returns true.
If you plan to make a vehicle that actually stays still to shoot, it is suggested that you use the base version of this virtual to just run the basic sight and distance checks, and write your own custom checks around it. The actual status changes, like putting the vehicle in its' StickAround state, should also be handled inside the virtual, similar to ShouldAttack()
Here is an abridged example of a StayStillAndShoot() override from one of my (inkoalawetrust) mods. Showing how it's meant to be used by also applying status changes:
Override Bool StayStillAndShoot (Actor CheckSightFrom)
{
//Other custom code
//And at last, run the standard KAI vehicle checks.
If (KAI_BaseVehicle.StayStillAndShoot(CheckSightFrom))
{
A_StopSound (CHAN_MOVING);
A_StartSound("Vehicle/ArmyCar/Idle",CHAN_IDLING,CHANF_LOOPING,attenuation:0.8);
//For the example, these are the important bits.
//ChaseTimer is how long the vehicle will stay in StickAround.
//And StayStillDelay is how much time the vehicle much wait before deciding to stop again.
ChaseTimer = Random (16,32);
StayStillDelay = ChaseTimer+(Random (2,4)*GameTicRate);
SetStateLabel ("StickAround");
Return True;
}
Return False;
}
- DeadTurret: The turret that died, normally this should just be the vehicles' turret.
- Removed: Was the turret killed by being removed entirely ? Default is false.
- None
Called when the vehicles' turret dies, useful for executing actions when that happens.
This is the stock state vehicles go to stay and shoot, it makes the vehicle face sideways away from its' target, and keeps it there until the ChaseTimer runs out, or until an enemy gets too close to the vehicle. It uses #### # sprites to keep the sprite from before the vehicle stopped, making it work with any vehicle actor.
- Home
- Features
- Classes
- Functions
- Guides