Customizing The Warfare Aircraft Factory Part 3.

Appending Units to the Aircraft Factory.

ch-47 and merlin hc3 in ArmaII Warfare

CH-47 and Merlin HC3 in ArmaII Warfare Mission

Last time I removed all the units from the Warfare Aircraft Factory and replaced them with a custom set of helicopters.

Now if instead I wanted to keep the stock roster of units available in the factory, but just append my custom units, I’d have to make a few changes to my scripting.

So for this example I’m going to keep the standard USMC units in the Aircraft Factory and just append the British Armed Forces CH-47 and Merlin HC3 to the list.

To do this I’ll setup my mission in the Arma II mission editor exactly as I did in Part 1 (see Customizing The Warfare Aircraft Factory Part 1).

I’ll setup my folders and create a InitMission.sqf as I did in Part 2 (see Customizing The Warfare Aircraft Factory Part 2), but my two scripts Init_Common.sqf, and Config_AircraftFactory.sqf will be a bit different. So lets take another look at those scripts.

Init_Common.sqf

My new Init_common.sqf will consist of just one line:

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

The only difference being I’ve removed aircraftUnits = []; from my previous example. This line would have set aircraftUnits to a blank array. I don’t want to do this, since the Warfare module will have already populated it with the default aircraft. Next I’m going to create my Config_AircraftFactory.sqf to add the CH-47 and Merlin to the factory.

Note that I don’t have to create a separate script, I could stuff all the code into Init_common.sqf. I’m just creating a separate Config_AircraftFactory.sqf script for the sake of organization and the odd chance that I may want to expand this mission later.

Config_AircraftFactory.sqf

Since I’m just adding my custom information to the existing variables created by the Warfare Script, my Config_AircraftFactory.sqf will look a bit different than it did in my last post. I’ll start with declaring my Private variables:

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

Where …

  • _c is the base cost of the helicopter. Note that I’ll be assigning it to a low value, for testing purposes.
  • _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, maybe it’s the salvage points?)
  • _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 put my values for the CH-47 and Merlin into my arrays.

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

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

_pilotCost = 75;

This next bit of code loops through each of my new aircraft in array _u and adds the appropriate information to the existing Warfare variables westAircraftMannedCosts , westAircraftDescriptions, westAircraftFactions and westAircraftImages.
Note that again I’ve decided to make the CH-47 & Merlin part of the USMC faction, because my simple mission only has this faction.

_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")];
};

This next block of code stuffs my arrays _u, _c etc. into the existing Warfare variables.

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

The next block of code updates the existing Warfare variables aircraftUnits, aircraftUnitCosts, and aircraftUnitDescriptions with the new values I updated above. Then I update the build time and end my script.

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.sqf

So placed altogether my new script will look like this:

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

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

_u = _u + ["BAF_Merlin_HC3_D"];
_c = _c + [40];
_m = _m + [2];
_t = _t + [40];
_p = _p + [30];
_pilotCost = 75;

_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 = westAircraftUnits + _u;
westAircraftCosts = westAircraftCosts + _c;
westAircraftCrews = westAircraftCrews + _m;
westAircraftTimes = westAircraftTimes + _t;
westAircraftPoints = 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;
};
};

Assuming I made no typos, when I go to purchase a helicopter from the Aircraft Factory I should be greeted with my expanded equipment list.

Reference

Customizing The Warfare Aircraft Factory Part 1.

Customizing The Warfare Aircraft Factory Part 2.

adding_warfare_aircraftfactory.Chernarus example mission