Customizing The Warfare Aircraft Factory Part 2.

Scripting The Warfare Module.

Last post I placed the basic units in the mission editor and got everything setup for my Warfare mission. (See Customizing The Warfare Aircraft Factory Part 1.)

Now I’m going to create the custom scripting required to add a BAF lite CH-47 to the Warfare Aircraft Factory.

This is a basic example so I’m going to limit my customizations to just the Aircraft Factory and only the West side.

Overview Of The Script Logic Flow

If you have ever poked around in the Warfare module code or even the stripped down example missions you might have found it a bit overwhelming. The following illustration is my attempt to visualize the flow through each of the components we are concerned with for this simple mission.

  1. Warfare Editor Module: When I placed this in the mission editor (see step 3 of  Customizing The Warfare Aircraft Factory Part 1.) I added a line of code to the module’s initialization field telling it where to find my custom script. In my example I’m going to build a file called InitMission.sqf.
  2. InitMission.sqf: from this file the warfare module will get the names of all my custom initialization scripts.  I’ll be using the defaults except for my common init Init_Common.sqf
  3. Init_Common.sqf: here is where I will declare the variables I need as well as call the script Config_AircraftFactory.sqf.
  4. Config_AircraftFactory.sqf: This is where I’ll place all the details of the available units (names, costs etc.)

Step 1: Create Folders

When I saved my example mission Arma II created a mission folder called example.Chernarus in My Documents \ ArmA 2 \ missions. When I use Windows to navigate to this folder I see it contains only mission.sqm The first thing I’m going to do is create some folders to better organize my scripts. With such a simple mission this is not required, but if I ever decide to expand the mission later being organized from the start will make that easier. Also by using the Warfare module’s folder layout and naming conventions as a template for my mission it should make the inevitable debugging easier as well.

So inside your mission folder you will need to create a new folder called Common. This is where we will put all the initialization and configuration scripts.

Next open up the newly created Common folder. Inside it create two new folders called Init, and Config. Now that we have our folder layout ready we can create the first script.

Step 2: Create The InitMission.sqf

Open up Notepad or the basic text editor of your choice and copy paste the following code into it:

BIS_WF_Common SetVariable ["sidePlacement",[true,-1,-1]];
BIS_WF_Common SetVariable ["customInitClientScript",""];


BIS_WF_Common SetVariable ["customInitCommonScript","Common\Init\Init_Common.sqf"];


BIS_WF_Common SetVariable ["customInitServerScript",""];
BIS_WF_Common SetVariable ["customInitBasesScript",""];
BIS_WF_Common SetVariable ["customBaseLayoutsScript",""];
BIS_WF_Common SetVariable ["customTownsScript",""];
BIS_WF_Common SetVariable ["customTownPath",""];

 

Next save the document as InitMission.sqf in your mission folder (in my case example.Chernarus).

If you are using Notepad, make sure you select the file type as all files. If you save it as a text file, Notepad will append the file extension .txt to your file and Arma will just ignore it. For added confusion Windows by default will hide the file extension of files it recognizes. So Notepad will save it as  InitMission.sqf.txt but Windows will show you InitMission.sqf. Your Warfare mission wont work, but everything will look ok. You’ll get frustrated and write me a nasty email, and I’ll say “I told you so”.

Save yourself some head bashing and make sure you select the file type as all files.

Explanation of InitMission.sqf

All the above code in Black is for customizing features that I’m not interested in for this simple mission.

For example the customBaseLayoutsScript variable is used to call the script that configures custom base layouts. I don’t need that for my mission, the default settings are fine.

However even though I don’t need them, I’m setting the variables to “” (ie. blank). I have to do this, because if I don’t my Warfare mission will hang at “Recieving” when I start it. I don’t know why, I just know that I need to specifically set the variables to blank for the module to use the default settings.

I’ve highlighted the line of code that we are concerned with in Blue. The variable customInitCommonScript I’m going to assign with the path and file name of my custom initialization script (highlighted in Red) which we will create next.

Step 3: Create The Init_Common.sqf

In notepad again, I’m going to create the Init_Common.sqf file with the following code:

aircraftUnits = [];
[] Call Compile PreprocessFile ("Common\Config\Config_AircraftFactory.sqf");

 

Save the file as  Init_Common.sqf in the example.Chernarus\common\init\ folder. Again make sure you don’t save it as a .txt file type.

The first line of code in my Init_Common.sqf sets the aircraftUnits variable to a blank array. I’m doing this to clear out the default units the Warfare module may have placed in the array.

The second line of code calls my custom config file for the aircraft factory.

Note that I could have placed the custom aircraft factory code here in my Init_Common.sqf – I don’t have to create a separate file. If I ever plan on expanding this mission it makes things a lot less confusing and more manageable to separate the config code out into their own files.

Step 4: Create the Config_AircraftFactory.sqf

In this file I’m going to place all the config information for my aircraft factory units. (cost, number of crew, available units etc.) I open up Notepad and start with declaring the variables used I will use in the Config_AircraftFactory script.

Private["_c","_config","_m","_p","_pilotCost","_t","_total","_u"];

  • _c is the base cost of the helicopter
  • _config will hold information about the unit, pulled from the addon.
  • _m is the number of men a crewed unit will have when purchased
  • _p a value for each unit that will get stuffed into westAircraftPoints (I’m not clear on this one, more research required)
  • _pilotCost is the cost for each crew member.
  • _t is the time required to build the unit
  • _total a counter
  • _u an array of class names of our helicopter units

Next I’ll add the code for my first unit. I’ll start with a UH1.

_u            = ["UH1Y"];
_c            = [3500];
_m            = [2];
_t            = [35];
_p            = [20];

  • _u is the units class name as it appears in the addon’s configfile. You can find Arma II classnames on the Official Forums. If you are using a mod, hopefuly the mod’s author was kind enough to provide a readme with the unit names.
  • _c is the cost of an empty UH1
  • _m is the number of crew
  • _t is the construction time of the unit
  • _p is the number of points for the unit (?)

For the second available unit I’m going to add my CH-47. Note that _u, _c etc are arrays, so I’m just going to add the information about my CH-47 to my existing arrays.

_u = _u        + ["CH_47F_BAF"];
_c = _c        + [40];
_m = _m        + [2];
_t = _t        + [40];
_p = _p        + [30];

Next I’m going to initialize some the of the variables:

_pilotCost = 75;

 

westAircraftDescriptions = [];
westAircraftFactions = [];
westAircraftImages = [];
westAircraftMannedCosts = []

This next block of code will step though each of the units I’ve placed in the array _u and pull the unit’s information from the configfile

_total = Count _u;
for [{_count = 0},{_count < _total},{_count = _count + 1}] do
{
_config = configFile >> "CfgVehicles" >> (_u Select _count);
westAircraftMannedCosts = westAircraftMannedCosts + [(_c Select _count) + (_m Select _count) * _pilotCost];
westAircraftDescriptions = westAircraftDescriptions + [GetText (_config >> "displayName")];
westAircraftFactions = westAircraftFactions + [Localize "STR_FN_USMC"];
westAircraftImages = westAircraftImages + [GetText (_config >> "picture")];
};

The section I’ve highlighted in Blue is a bit different as I’m not pulling the information from the addon, but forcing all my aircraft to be of the USMC faction. I’m doing this as the CH-47 by default is BAF and I don’t plan on using that faction for this mission.

The next block of code stuffs my variables into the Warfare module’s global variables.

westAircraftUnits = _u;
westAircraftCosts = _c;
westAircraftCrews = _m;
westAircraftTimes = _t;
westAircraftPoints = _p;

 

aircraftUnits = westAircraftUnits;
aircraftUnitCosts = westAircraftCosts;
aircraftUnitDescriptions = westAircraftDescriptions;

 

 

//Determine longest build time.
longestAircraftBuildTime = 0;
_t = westAircraftTimes;
for [{_count = Count _t - 1},{_count >= 0},{_count = _count - 1}] do
{
if (_t Select _count > longestAircraftBuildTime) then
{
longestAircraftBuildTime = _t Select _count;
};
};

Complete Config_AircraftFactory

So when I’m done typing my code looks like the following:

Private["_c","_config","_data","_m","_p","_pilotCost","_t","_total","_u"];

 

//WEST
_u            = ["UH1Y"];
_c            = [3500];
_m            = [2];
_t            = [35];
_p            = [20];

 

_u = _u        + ["CH_47F_BAF"];
_c = _c        + [40];
_m = _m        + [2];
_t = _t        + [40];
_p = _p        + [30];

_u = _u        + ["MV22"];
_c = _c        + [4000];
_m = _m        + [2];
_t = _t        + [40];
_p = _p        + [30];

 

_u = _u        + ["AH1Z"];
_c = _c        + [7500];
_m = _m        + [2];
_t = _t        + [55];
_p = _p        + [50];

 

_pilotCost = 75;

westAircraftDescriptions = [];
westAircraftFactions = [];
westAircraftImages = [];
westAircraftMannedCosts = [];

 

_total = Count _u;
for [{_count = 0},{_count < _total},{_count = _count + 1}] do
{
_config = configFile >> "CfgVehicles" >> (_u Select _count);
westAircraftMannedCosts = westAircraftMannedCosts + [(_c Select _count) + (_m Select _count) * _pilotCost];
westAircraftDescriptions = westAircraftDescriptions + [GetText (_config >> "displayName")];
westAircraftFactions = westAircraftFactions + [Localize "STR_FN_USMC"];
westAircraftImages = westAircraftImages + [GetText (_config >> "picture")];
};

 

westAircraftUnits = _u;
westAircraftCosts = _c;
westAircraftCrews = _m;
westAircraftTimes = _t;
westAircraftPoints = _p;

aircraftUnits = westAircraftUnits;
aircraftUnitCosts = westAircraftCosts;
aircraftUnitDescriptions = westAircraftDescriptions;

 

 

//Determine longest build time.
longestAircraftBuildTime = 0;
_t = westAircraftTimes;
for [{_count = Count _t - 1},{_count >= 0},{_count = _count - 1}] do
{
if (_t Select _count > longestAircraftBuildTime) then
{
longestAircraftBuildTime = _t Select _count;
};
};

I save this file as Config_AircraftFactory.sqf and I place it in my example.Chernarus\common\config. Again, making sure I don’t save it as a .txt file.

Note that I’ve added code for the MV22 and AH1Z as well. Also to keep things simple I’ve only concerned myself with West units. To add East and Resistance units I would need to add a block of code for their units and stuff the information into the Warfare variables as follows

aircraftUnits = westAircraftUnits + eastAircraftUnits + resistanceAircraftUnits;
aircraftUnitCosts = westAircraftCosts + eastAircraftCosts + resistanceAircraftCosts;
aircraftUnitDescriptions = westAircraftDescriptions + eastAircraftDescriptions + resistanceAircraftDescriptions;

 

That is all the scripting required to do a basic customization of the Aircraft Factory in a Warfare mission. Everything should work well if I’ve made no typos.

Reference

PreprocessFile

Call

Compile

Arma II class names

Customizing The Warfare Aircraft Factory Part 1.

Customizing The Warfare Aircraft Factory Part 3.

custom_warfare_aircraftfactory.Chernarus example mission.