How To Spawn New AI - Subject9x/battleMETAL GitHub Wiki

After going through How To Add/Mod Vehicles, you may be wondering how to get your new vehicle into a map?

This article is here to tell you how.

Code Flow

Units spawn into the map using Quake style function calls - the QUAKED definition in battleMETAL.def. We'll use the venerable Foslager tank for this.

Unit Data: data_foslager.qc

QUAKED map function: unit_foslager_h

this second function tells the game code how to customize the entity that's being spawned. We see that the unit's self.data_idx is set to the Foslager's UID. Also the .faction and .flags are set here as well.

Your new vehicle will need a similar function to this and ideally you put that function in this file

self.flags = FL_TURRET - set this if you want your vehicle to rotate its turret (if it has one).

[INFO] a vehicle can have a turret that doesn't rotate, simply ignore the FL_TURRET code at this step.

if( !ai_can_spawn() )

this must be in every unit spawn function, exactly as you see it! You can see what this function does by following the link. It runs some game logic validation to check if the unit is allowed to actually spawn into the map or not.

next, we call

ai_promote();

this will adjust the AI's starting stats, checking to see if its ai_rank is adjusted by spawnflags.

now things get a big complicated. This section of code determines the starting accuracy and Weapons that the unit will spawn with based on the game's skill setting.

switch( self.ai_rank ){

[INFO] 'skill' is a console variable that you can set in the console with a value 0 - 3

self.spreadDefault = ACCURACY_SKIRMISH;

just like the mech data, here we can set the unit's starting accuracy before the stat is modified later in the code.

  • This defines the base-line convergence for the unit. The following are allowable values for this variable:
    • ACCURACY_SKIRMISH
    • ACCURACY_SNIPER
    • ACCURACY_MARKSMAN
    • ACCURACY_LOWTECH
    • ACCURACY_PRIMITVE
    • The exact value of each can be found here
    • type the value exactly as it appears above, this is a vector var, not a string.

ai_ini_weapons( )

Now we assign the weapons we'd like to give the unit when it spawns. This function takes 9 float values, each maps to a hardpoint on the unit. If the hardpoint is missing, then this value is ignored, but you should make sure that any empty value uses the UID_ITEM_EMPTY global just for safety.

For each game difficulty rating, we can adjust the loadout of the unit. I chose to add better and more powerful weapons to a unit as the game got harder.

Now, we come to the last piece - calling the initialization.

we use self.think and set it to the appropraite ai template.

you match tank and gev behaviors for your vehicles,

match mech behaviors for your mech units.

This completes the code portion for adding / modifying unit data. To get your new vehicle into maps from here, you'll need to consult the mapping tutorials.