The Unittypes List

From WiCWiki

Jump to: navigation, search


The file

To make the workflow faster and easier when we we worked with units in the single player campaign we added a file in the python folder called The file made it possible for us to get auto completion in the editor and we didn’t have to convert the units name to its hash value each and every time we created a unit. By time it became more and more important and today it is a very important part of our API.

Unit Names

What happens in the file is that all units hash value will be saved in variables each time we start a map. By having all units in the same place it will be much easier if one unit must be changed, instead of changing the unit in every map it is used.

To convert a units name to a hash value we use the function base.StringToInt like this.

base.StringToInt( "nameOfUnit" )

-The parameter is the name of the unit found in the wic\units\unittypes_wic_singleplayer.juice file.

For example like this.

NATO_LEOPARD2 = base.StringToInt("NATO_Tank_Leopard2")

And when we want to create a unit we use the variable from the unittypes file like this.

mapvars.grpTest.CreateUnitsAtPosition( [NATO_LEOPARD2], 'areaTankSpawn' ) 

If we didn’t have the unittypes file we would be forced to write like this every time we created units.

mapvars.grpTest.CreateUnitsAtPosition( [ base.StringToInt("NATO_Tank_Leopard2") ], 'areaTankSpawn') 

The UnitClassLists

The contains other important functions as well. There is the unit class lists which specify what ‘roll’ every unit have, a jeep can transport units; a marine is an infantry unit etc. The lists make it possible to check what specific roll a units belongs to. There are seven lists (classes) a unit can belong to; squad, infantry, tanks, artillery, container, air and repair. There are three variants of each list, one for each team. A unit can be in more than one list at the same time like the Humwee that can transport infantry and repair other vehicles which puts it in both the container list and the repair list.

The names in the lists must be the units hash value.

Here is an example with the three different lists of the tank class.




The UnitCosts dictionary

There is also a unit cost dictionary in the file. The unit cost dictionary contains a default cost for how many reinforcement points the unit type costs.

The functions GetUnitCost() and AddToSPReinforcement() use this value so the units always will have the same price during the whole single player campaign.

You can change the predefined cost from the dictionary in the AddToSPReinforcement function by overwriting it with a new cost. If you don’t send a cost in the AddToSPReinforcement function and the unit type don’t exist in the unit cost dictionary the game will crash. You can change the predefined values in the dictionary as well but that will affect every mission you create.

Here is an example where the cost for the NATO faction leopard tank is set to 1200 AP points.

unitCosts["NATO_Tank_Leopard2"] = 1200

The name of the unit in the list is from the wic\units\unittypes_wic_singleplayer.juice file.

Chapter 11a: Creating units < > Chapter 12: Secondary Objective
Personal tools
User Created Content