Drop Zones and the Reinforcements Menu

From WiCWiki

Revision as of 09:13, 16 January 2008 by Tabu (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Contents

Chapter 9: Drop Zones and the Reinforcements Menu

To be able to order down units we need two important things. First of all, we need a drop zone; second we need the reinforcements menu with units and points.


Drop zones are also known as deployment zones or deployment areas.


Drop Zones.

To make a drop zone you’ll need a “deployment area mask”. The “deployment area mask” is a *.tga file with 256x256 pixels with a black and white alpha channel. The white area will be the drop zone in the game. It is important that you don’t save the tga with RLE compression because that won’t work.

Image:mapscripting_dropzones_001.jpg


Every map have an over view image, in *.dds format. If you open the overview map in a separate layer it is a bit easier to paint, or at least to get some idea of where to paint the drop zone. Sometimes it is important that the drop zone won’t cover buildings or houses because there are a chance the units you deploy will get stuck.


You will find the image, which is auto generated by “WICEd”, in maps\nameOfMap\OverviewMap.dds


Deployment areas in the juice file.

As with almost everything you have to add the deployment mask in the juice file. The juice file is located here. wic\maps\mapname\mapname_singleplayerdata.juice


You will find the deployment mask under mySinglePlayerData -> mySinglePlayerMissionStats -> mySinglePlayerDeploymentAreaMask.


It will be empty by default and look like this.

mySinglePlayerDeploymentAreaMask
{

}

First you must write “FILE” followed by the name you want to give it, in this case we use “DZ_Village”. Then simply write the file path to where ever you have it.

mySinglePlayerDeploymentAreaMask
{
    FILE DZ_Village maps/europeTest/deploymentareamasks/DZ_Start.tga
}

Deployment zones in python.

The first thing we have to do is to add the deployment zone. You add the deployment zone with this code. This could be added wherever you want, but we usually add it in the server.py file. Make sure you have the “serverimports.py” file imported, else it won’t work.

AddDeploymentZone(‘DZ_Village’)

If you want to add it in an action queue the code looks like this.

queMyQue.AddFunction( AddDeploymentZone, ‘DZ_Village’)
  • The parameter is the name that you gave the drop zone mask in the juice file.


Now that the mask is added we have to give it to the team we want to be able to use it. In this case, because it is the player drop zone we will add, it is team NATO.

AddDeploymentZoneToTeam( 'DZ_Village', TEAM_NATO )
  • The first parameter is the name of the drop zone mask in the juice file.
  • The second parameter is which team that shall use the drop zone.

This means if you have allied AIs they can use the same drop zone. More about this covered in the chapter about the AI.

If we don’t want the team to be able to drop units in the zone we can remove it.

RemoveDeploymentZoneFromTeam( 'DZ_Village', TEAM_NATO )
  • The first parameter is the name of the zone to remove.
  • The second is which team that we shall remove the zone from.


If you add more than one zone to a team they will be added to the previous ones.


Reinforcements menu.

The first thing we have to do is to make sure we can se the reinforcements menu which is hidden by default.

This is the code for making it visible and we write it in the server.py file. The parameter is which of the GUI elements you will show.

theGame.ShowGUIChunk( ' reinforcements' )

If you start the game you will have a reinforcements menu that looks like this.

Image:mapscripting_dropzones_002.jpg


This is the code if you want to hide it again.

theGame.HideGUIChunk( 'reinforcements' )


Add units to the menu.

By default there are no units in the menu. In Single player we are not bound to the rules of roles so you can mix units as you like. You can add units without a cost and units with a limitation.

The menu has a limit of 10 units at a time and you can’t add the same kind of unit twice, for example 2 tanks for free and one with a normal cost.


The code looks like this and we usually put it in the Player function in the allunits.py file.

AddToSPReinforcement( aUnitType, aNrOfUnitsIfLimited = -1, anOverrideCost = -1 )
  • The first parameter is the name of the unit you want to add. The names are from the unittypes_wic_singleplayer.juice file. Don’t try to add units from another file, it won’t work.
  • The second parameter contains the possible limit you may want to add on how many units of that type the player can order down. The variable is assigned to -1 by default and means that there is no limit.
  • The third parameter contains an optional override cost for the unit. Changing this parameter will override the unit type cost as defined in unittypes.py (we will cover unittypes.py later).


You can change the limitation and the cost during the game as well. Just use the same line of code again and change limitation and/or cost.


In this case we don’t need anything except the unit's name. We won’t use a limit yet and we will use the defined unit cost.


If you have this following code in your server.py or in your allunits.py and call it from server, file you can start the game and take a look at your nice looking reinforcements menu.


We usually place this code in the Player function in allunits.py file. Don’t forget to call the player function from the sever.py file; we suggest in the Intro function if you have one.

(You can place all the code in the server.py file as well, but we usually don’t do that.)

def Player( ):
    DebugMessage( 'allunits.Player::' )

         [More code goes here]

         # Set Tactical aid point cap.
         thePlayers[PLAYER_HUMAN].myMaxTacticalAid = 100

         # Add units to the reinforcements meny
         AddToSPReinforcement( 'NATO_LandRover' )

         AddToSPReinforcement( 'NATO_Warrior_APC' )

         AddToSPReinforcement( 'NATO_AMX30' )

         AddToSPReinforcement( 'NATO_Chieftain_MkV' )

         AddToSPReinforcement( 'NATO_Tank_Leopard2' )  


Image:mapscripting_dropzones_003.jpg

It should look something like this (except from the AP points which we will cover in the next paragraph).

It might be a good idea to add an event string to let the player know that it’s now possible to order down units. This event string contains the sentence “You can now use the reinforcement menu.”

AddScriptEventAll(‘myReinforcementMenu’)

You can read more about this in the chapter about event strings.

Remove units from the reinforcements menu.

There’s a new feature, or, a bug fix that suddenly makes it possible to remove units from the menu during the game as well. The code looks like this and the important thing is the second parameters ‘-1’.

SetUnitCostForSPRole( 'NATO_Tank_Leopard2', -1, 'REBATE_REBATED' )

We’ve never used this code in the game, but fell free to play around with it (and if you notice any problems, please report it to us.J).


Free units, with or without limitations.

You can add free units to the player as well. It can be handy if you want to ensue the player can have access to something specific.

To add free units to the player we do like this, where the second parameter decides the limit and the third the cost.

AddToSPReinforcement( 'NATO_Mangusta', 1, 0 )


That will give the player one free Mangusta helicopter to order down for free.

Image:mapscripting_dropzones_004.jpg It should look something like this.

If you add new units to the player during the game there’s an excellent event string you can use. It contains the phrase "New units have been added to your reinforcement menu".

queLastStandStart.AddEventString( 'myNewUnits' ) 


Some information about AP points.

AP points and reinforcement points are the same thing. In this tutorial we’ll refer to it as AP because it’s easier to write and we are lazy.

There are two values you can affect. The first one is the player’s maximum amount of AP points.

You can increase the player’s maxAP during the game, but never decrease it because you can never have less maxAP than the total amount of points you perhaps have spent on units.

thePlayers[ PLAYER_HUMAN ].myMaxAP = 6000
thePlayers[ PLAYER_HUMAN ].myCurrentAP = 3000

The myCurrentAP is the amount of points that are available for the player. If this is the same value as the myMaxAP all the points would be available for the player. We usually use this in the start of the map so the player won’t need do wait for the points to be available.

SpeedRPTrickle( ) 

SpeedAPTrickle does exactly what it says. It speeds up the AP trickle so the myCurrentAP will increase faster.

AddAPToPlayer( anApAmount )

AddAPToPlayer will add the amount, the parameter, to both myMaxAP and myCurrentAP. It should be an integer.

If you have, like in this test map, given the player starting units, you have to include the cost for them in the myCurrentAP. We will cover this in the chapter about starting units.


Finding the unit types names.

In the wic\units folder there are two juice files, unittypes_wic and unittypes_wic_singleplayer. We can’t use units from the unittypes_wic file in single player; we must use units from the unittypes_wic_singleplayer file. The one thing we are interested in from the juice file is the units’ names. The costs in the juice file are ignored in single player so don’t waste your time trying to get it to work.


The name of the unit is next to “UnitType”, in this case “NATO_Tank_Leopard2”.


UnitType NATO_Tank_Leopard2
{
    myTeam NATO
    myType GROUND
   “More unit data here.”

UNITTYPES.PY!

In the unittypes.py file there is a python dictionary called unitCosts that contains all the global cost of the units we used in the single player campaign. The unit type must be in the dictionary or you must send in a cost when you add the unit to the reiforcements menu, else the game will crash.

More about this in the chapter about ‘The Unittypes list’.

Appendix.

Changed files in this chapter:


Server.py


europeTest_singleplayerdata.juice


Changes in the server.py file.

def Intro( ):
 DebugMessage( "Intro::" )
 # Add deployment Zones to use later on.
 AddDeploymentZone( 'DZ_Village' ) 

 [More code here.]


def VillageStart( ):

[More code here.]

    queVillageComplete.AddFunction( SetCommandPointActive, 'CP_Village', False )
    queVillageComplete.AddFunction( AddDeploymentZoneToTeam, 'DZ_Village', TEAM_NATO )
    queVillageComplete.AddFunction( theGame.ShowGUIChunk, 'reinforcements' )
    queVillageComplete.AddEventString( 'myReinforcementMenu' )
    queVillageComplete.AddFunction( VillageEnd )

[More code here.]


Changes in the allunits.py file.

def Player( ):

[More code here.]

# Set the max and current reinforcement points that we want the player to have. Because we have
# given the player some starting units we decrease there cost form the max value.

    thePlayers[ PLAYER_HUMAN ].myMaxAP = 6000
    thePlayers[ PLAYER_HUMAN ].myCurrentAP = ( thePlayers[ PLAYER_HUMAN ].myMaxAP - GetUnitCost( [ 'NATO_Tank_Leopard2', 'NATO_Tank_Leopard2' ] ) )

  # Add units to the reinforcements meny

    AddToSPReinforcement( 'NATO_LandRover' )
    AddToSPReinforcement( 'NATO_Warrior_APC' )
    AddToSPReinforcement( 'NATO_AMX30' )
    AddToSPReinforcement( 'NATO_Chieftain_MkV' )
    AddToSPReinforcement( 'NATO_Tank_Leopard2' )   

Changes in the europeTest_singleplayerdata.juice file.

If you open europeTest_singleplayerdata.juice in the ‘JuiceMaker’ tool you will find mySinglePlayerDeploymentAreaMask under mySinglePlayerData -> mySinglePlayerMissionStats -> mySinglePlayerDeploymentAreaMask.

mySinglePlayerDeploymentAreaMask
{
    FILE DZ_Village maps/europeTest/deploymentareamasks/DZ_Start.tga
}


Chapter 8: Objectives and the Objectives browser < > Chapter 10: Event string
Personal tools
User Created Content