Skip to content

Vehicle functions

inkoalawetrust edited this page Sep 16, 2023 · 10 revisions

NOTE: For a list of functions shared by both vehicles and humanoids, look here !

These are the ZScript functions shared by all vehicles and turrets.

SpawnVehicleTurret()

Parameters:

  • TurretClass: The class of the turret to spawn, must be based on KAI_BaseTurret

Return type(s):

  • None, for a pointer to the spawned turret, just check the Turret pointer.

Function:

This function handles the basic tasks for spawning a vehicle turret, like setting its' allegiance, passing the vehicles spawn flags to the turret, etc. Useful if you have custom turret spawning logic in SpawnVehicleTurret(), such as a vehicle that can have different turrets through a user variable.

SpawnVehicleHeadlight()

Parameters:

  • AttachTo: The actor to attach the lights to, normally a vehicle.
  • Offsets: The Vector3 offsets relative to AttachTo's origin at which the light should spawn.
  • Flags:
    • VHSF_BACKLIGHT: The spawned headlight is a backlight.
    • VHSF_SPRITEROT: The headlight takes its targets' SpriteRotation into account.
    • VHSF_CARDINALS: The headlights snaps to the nearest of 8 sprite angles relative to the vehicle. To take the limited amount of rotations into account.
    • VHSF_16ANGLES: Used in conjunction with VHSF_CARDINALS to snap the light to the nearest of 16 angles instead of 8, for 16 angle sprites.
  • LightColor: The color of the headlight, because this uses dynamic light actors, this is a Vector3 that stores the R, G, and B colors of the the light, respectively, can be any value between 0 and 255. Is white by default (255, 255, 255).
  • Intensity: How strong the headlight is, default is 256.
  • SpotlightAngles: A Vectpr2 that stores the inner (X) and outer (Y) angles of the headlight.

Return type(s):

Function:

Spawn a vehicle headlight, vehicle headlights are spotlight actors. Normally called in the SpawnHeadlights() virtual to spawn and store the vehicle's headlights when it spawns.

Example

This is how the function is used by one of the vehicles from the Military Vehicles Pack.

	Override Void SpawnHeadlights ()
	{
		Headlights.Push(SpawnVehicleHeadlight(Self,(128,28,8),intensity:384));
		Headlights.Push(SpawnVehicleHeadlight(Self,(128,-28,8),intensity:384));
		Headlights.Push(SpawnVehicleHeadlight(Self,(128,28,8),VHSF_BACKLIGHT,(255,0,0),32,(40,80)));
		Headlights.Push(SpawnVehicleHeadlight(Self,(128,-28,8),VHSF_BACKLIGHT,(255,0,0),32,(40,80)));
	}

KAI_VehiclePushActors()

Note:

This function must be called before the actor moves, but after the position to move to has been decided, to push any obstacles out of the way. Refer to how it's used in KAI_MoveTowards() as an example.

Bug:

Depending on how many pushable obstacles are stacked next to each other, this function may cause game freezes in spite of the recursion failsafe !

Parameters:

  • Source: The actor who is pushing the obstacles away, this is normally the vehicle itself.
  • MovePos: The XY position to check for pushable obstacles to push away at.
  • MaxPushRadius: The maximum radius a blocking obstacle can have before the vehicle can no longer push it, normally this value is the vehicles' MaxPushRadius.
  • MaxPushHeight: Ditto
  • Blockers: A pointer to an actor array can be passed to this parameter, to have pointers to all the actors that blocked the vehicle at MovePos, even if the vehicle can't necessarily push them.
  • Depth: The recursion depth of the function, basically, how many times the function has called itself (Depth+1), if it goes above 32, it terminates. THIS IS NOT MEANT TO BE USED ! It's only used to make vehicles able to push multiple obstacles stacked next to each other.

Function:

Pushes all pushable obstacles that are intersecting the the callers' hitbox at NextPos away. This must be called before the vehicle actually moves. The function can also push multiple obstacles that are stacked and collide with each other, like a bunch of traffic cones set up like bowling pins. However, the behavior is incredibly finicky due to Doom's broken physics, so it's generally recommended to just not get pushable obstacles stacked next to each other like that.

If it's monsters, they will be allowed to clip through objects, since they can walk out of objects they are clipping into. This makes it feasible to push crowds of enemies around.

KAI_VehicleCrushObstacles()

Parameters:

  • Victims: An array list of all the actors to apply Crush damage to.
  • Damage: How much crush damage to do to the Victims. Normally the vehicles' VehicleCrushDamage variable is passed here.

Function:

Performs crushing (The exact "Crush" damage type used by actual sector crushers) damage to the actors contained in the Victims array. This function is used in conjunction with the Blockers parameter of KAI_VehiclePushActors() to optionally crush the actors that blocked it's next move, even if it couldn't push them. If an actor in the Victims array is too large to crush, it will be ignored. Does nothing if bNoCrushing is true.

KAI_VehicleRetreat()

Parameters:

  • Other: The actor to retreat from.
  • Distance: How far back to pick a position away from the Other actor.
  • CheckDistance: How far ahead of the vehicle to check for obstacles, so the vehicle can try to avoid them. A value of 0 disables obstacle avoidance.
  • Slices: How many angles around the caller to check for obstacles (360 degrees / slices). A value of 0 here also disables obstacles avoidance.
  • Flags:
    • VRF_ZIGZAG: Instead of driving in a straight line away from Other. The reverse angle will randomly vary every few steps, to move in a more zig-zag pattern.
  • DetourFactor, AngleLimit, ChaseFlags, Flags: These parameters work the same as in KAI_MoveTowards().

Return type(s):

  • Not a return, but this does set the NPCs' NextMovePos.

Function:

Makes the vehicle retreat from Other, unlike KAI_MoveAway(), this function picks the furthest Distance away from the other actor, instead of a random spot that is the furthest. Even more unlike KAI_MoveAway(), this function will attempt to make the vehicle avoid hitting any obstacles that are CheckDistance ahead of the vehicle.

KAI_LandVehicleChase()

See here.

HandleChaseTimer()

Return type(s):

  • None

Function:

Handles the vehicles' SearchTime property. Used by KAI_LandVehicleChase() and can also be called independently on turrets if you want them to be able to stop chasing their target and switch to a new one.

FollowPlayerControl()

Parameters:

  • MaxDist: The distance to check if the vehicles' friendplayer is within. Default is 384 map units.

Return type(s):

  • None

Function:

Checks if the player the vehicle is following is within MaxDist, if they are then the function turns +DONTFOLLOWPLAYERS on, otherwise it turns it off. This is used by KAI_LandVehicleChase() to try and prevent friendly vehicles from dogpiling the player and blocking their way.

RetargetVehicleHull()

Parameters:

  • Flags: The flags to use for the retarget. These are mostly flags for not running specific retarget conditions.
    • RVHF_NOTARGETCHANGE: Don't actually change the callers' target to the hull of the turret they are targeting, only return if the retarget SHOULD occur.
    • RVHF_NOTRANSFERDAMAGECHECK: Don't retarget if the turret has +TRANSFERDAMAGE, and the hull its' attached to is bigger than the turret itself.
    • RVHF_NOWEAKHULLCHECK: Don't retarget if the vehicle the turret is attached to is weaker than the turret itself.

Return type(s):

  • Returns true if the callers' target is a vehicle turret, and targeting the vehicle the turret is attached to would be more advantageous instead.

Function:

Checks if the callers' target is a vehicle turret, and changes it if it would be more advantageous to target the vehicle itself, this function checks for several conditions to determine if it would be better/easier to target the vehicle rather than its' turret:

  • If the turret has +TRANSFERDAMAGE, and is overall smaller than the vehicle it's on. Then it would make more sense to target the bigger hull, since both actors share the same health pool.
  • If the turret does not have +TRANSFERDAMAGE, but the vehicle it's attached to is weaker than 80% of the turrets' current health. Meaning that it should be easier and quicker to destroy the vehicle itself than its' turret, which it can probably function without anyway.

KAI_CrushCorpses()

Parameters:

  • RadiusMultiplier: The amount to multiply the crushing radius of the vehicle by. Default is 1.0, which only crushes corpses the vehicle is touching.

Function:

Handles crushing any non-flying corpses the vehicle is touching. Useful for making vehicles that can crush corpses they drive or walk over. Like tanks. Must be called every time the vehicle moves ideally, to crush the corpses after every move. Does nothing if bNoCrushing is true.

Headlight functions

These functions handle the vehicles' headlight system.

TurnHeadlightsOn()

Turn the vehicle's headlights on if they aren't already, and increases its light level by 64, along with the light level of any turret attached on it.

TurnHeadlightsOff()

Turns the headlights off and sets the vehicles and turrets' light levels back to 0.

RemoveHeadlights()

Removes all the vehicles' headlights. Called when vehicles die or are erased from existence.

See also

Clone this wiki locally