Other great resources: Official JS API docs, Scripting Forum
Player Initialisation
- Aubergine
Summary
Player initialisation takes within rules.js during eventGameInit():
- Enabling certain structures
- Enabling certain cyborg components
- Enabling primary technologies (Sensor, Engineering, Machine gun)
- Setting default structure limits (which then get overwritten by limits from game set-up screen)
- Apply base type settings:
- Gifting a certain number of technologies
- Setting starting power
- Removing certain map-defined buildings
- Make the construction truck template available
- For the player this instance of rules.js is responsible for, set Design Mode and Mini Map based on presence of HQ
Note: The Scavenger faction is not part of this – Scavengers are initialised and controlled by "scavfact.js" and buildings that are pre-placed on the map during map design. The game will quickly de-synchronise if someone's hacked their "scavfact.js", etc.
All players must be initialised
Warzone uses deterministic algorithms to determine if players are cheating in multiplayer games (and this is used in any game where there's multiple players, even if they're AI bots).
Because of this, each machine connected to the game needs to initialise all players in it's memory, so it knows what to expect when the game starts. It can't rely on other machines to provide accurate results – what if someone's cheated by hacking the game or the initialisation rules on their machine?
A simple loop will initialise all players:
var player = maxPlayers; while (-1<--player) { // initialise 'player' here }
Wax Net off, Wax Net on.
Each human player will have a rules.js, and that rules.js will be initialising all players on their machine including AI players.
To avoid problems, network communications must be temporarily disabled using an ugly hack as follows:
hackNetOff(); // initialise 'player' here hackNetOn();
For more information on those functions, see: hackNetOff() and hackNetOn().
Enabling Structures
There are some basic structures, without which the player will be pretty much doomed from the outset. So, rules.js needs to enable these for all players.
The structures which must be enabled are:
Structure ID | Description | Reason | |
---|---|---|---|
"A0CommandCentre" | Command Centre (HQ or CC) | The player needs access to Design Mode and Mini Map | |
"A0LightFactory" | Factory | The player needs to build construction trucks | |
"A0ResourceExtractor" | Oil Derrick | The player needs to gain power | |
"A0PowerGenerator" | Power Generator | Power Generators are required to make Oil Derricks work | |
"A0ResearchFacility" | Research Facility | Research is practically impossible without labs |
Structures are enabled by using the enableStructure() function. Note that although these structures are enabled, structure limits might prevent them from being built.
Enabling Cyborg Components
Players cannot design cyborgs like they can other vehicles. Instead, pre-designed cyborgs become available as soon as the required research has been completed. For that to happen, certain components (that the player cannot research) must be enabled by rules.js:
Icon | Component ID | Description |
---|---|---|
"CyborgLegs" | Cyborg legged propulsion | |
"CyborgSpade" | Combat Engineer | |
"CyborgRepair" | Cyborg Mechanic | |
"Cyb-Wpn-Atmiss" | Scourge | |
"CyborgCannon" | Heavy Gunner | |
"CyborgChaingun" | Machinegunner | |
"CyborgFlamer01" | Cyborg Flamer | |
"Cyb-Wpn-Grenade" | Grenadier | |
"Cyb-Hvywpn-A-T" | Super Scourge Cyborg | |
"Cyb-Hvywpn-Acannon" | Super Auto-Cannon Cyborg | |
"Cyb-Hvywpn-HPV" | Super HPV Cyborg | |
"Cyb-Hvywpn-Mcannon" | Super Heavy-Gunner | |
"Cyb-Hvywpn-PulseLsr" | Super Pulse Laser Cyborg | |
"Cyb-Hvywpn-RailGunner" | Super Rail-Gunner | |
"Cyb-Hvywpn-TK" | Super Tank-Killer Cyborg | |
"Cyb-Wpn-Laser" | Flashlight Gunner | |
"Cyb-Wpn-Rail1" | Needle Gunner | |
"CyborgRocket" | Lancer | |
"CyborgRotMG" | Assault Gunner | |
"Cyb-Wpn-Thermite" | Thermite Flamer |
Components are enabled using the enableComponent() function.
Enabling Primary Technologies
Players need to be able to research at least the following technologies:
Icon | Research ID | Description |
---|---|---|
"R-Sys-Sensor-Turret01" | Sensor Turret | |
"R-Sys-Engineering01" | Engineering | |
"R-Wpn-MG1Mk1" | Machine gun |
These are the three primary technologies at the root of the research tree for all non-Campaign maps, so rules.js needs to ensure they are available.
The technologies are enabled using the enableResearch() function. Note that this doesn't mean they get researched, it just means that they can be researched.
Setting Initial Structure Limits
Structure limits don't enable structures to be built, they just limit how many structures of a given type can be built.
Before any game-specific structure limits are applied, rules.js must set the default limits as follows:
Icon | Structure ID | Description | Limit |
---|---|---|---|
"A0LightFactory" | Factory | 5 | |
"A0PowerGenerator" | Power Generator | 8 | |
"A0ResearchFacility" | Research Facility | 5 | |
"A0CommandCentre" | Command Centre (HQ or CC) | 1 | |
"A0ComDroidControl" | Command Relay Centre (CRC) | 1 | |
"A0CyborgFactory" | Cyborg Factory | 5 | |
"A0VTolFactory1" | VTOL Factory | 5 |
The default structure limits are set using the setStructureLimits() function.
After setting structure limits, the applyLimitSet() function has to be called:
- This applies the limits as specified by any prior setStructureLimits() calls
- It then takes the limits from the game set-up screen and applies those, overwriting any previously set limits
If you want to change the limits that are listed on the game set-up screen, and their maximum and minimum values, you'll have to edit multilim.slo (and multilim.vlo if adding any new structures to the limits screen) in the multiplay/script/ folder. For more information, see this forum topic.
Apply Base Type Settings
Players use base type settings to gain some control over how advanced they are at the start of the game.
More advanced base types mean:
- More technology at the start of the game - including weapons, propulsions, bodies, structures and upgrades
- Almost double the starting power
- More map-defined buildings remain, particularly for INSANE AI players
Gifting Technologies
Depending on the baseType setting, all players will be given a number of researched technologies.
The reasoning behind this is that they should obviously have whatever technologies would be needed to create the base and defence structures they've started the game with - otherwise, how can they rebuild them if they get destroyed?
Here is the list of technologies gifted for each of the base type settings:
Research ID | Description | baseType | ||
---|---|---|---|---|
CAMP_CLEAN | CAMP_BASE | CAMP_WALLS | ||
"R-Vehicle-Prop-Wheels" | Wheeled Propulsion | |||
"R-Sys-Spade1Mk1" | Construction Turret | |||
"R-Vehicle-Body01" | Viper Body | |||
"R-Comp-SynapticLink" | Synaptic Link | |||
"R-Wpn-MG1Mk1" | Machine gun | |||
"R-Defense-HardcreteWall" | Hardcrete Wall | |||
"R-Vehicle-Prop-Wheels" | duplicate? | |||
"R-Sys-Spade1Mk1" | duplicate? | |||
"R-Struc-Factory-Cyborg" | Cyborg Factory | |||
"R-Defense-Pillbox01" | ||||
"R-Defense-Tower01" | ||||
"R-Vehicle-Body01" | duplicate? | |||
"R-Sys-Engineering01" | Engineering | |||
"R-Struc-CommandRelay" | Command Relay Centre | |||
"R-Vehicle-Prop-Halftracks" | Halftracked Propulsion | |||
"R-Comp-CommandTurret01" | Command Turret Mk 1 | |||
"R-Sys-Sensor-Turret01" | Sensor Turret | |||
"R-Wpn-Flamer01Mk1" | ||||
"R-Vehicle-Body05" | ||||
"R-Struc-Research-Module" | Research Module | |||
"R-Struc-PowerModuleMk1" | Power Module | |||
"R-Struc-Factory-Module" | Factory Module | |||
"R-Struc-RepairFacility" | Repair Facility | |||
"R-Sys-MobileRepairTurret01" | Mobile Repair Turret | |||
"R-Vehicle-Engine01" | ||||
"R-Wpn-MG3Mk1" | ||||
"R-Wpn-Cannon1Mk1" | ||||
"R-Wpn-Mortar01Lt" | ||||
"R-Defense-Pillbox05" | ||||
"R-Defense-TankTrap01" | Tank Traps | |||
"R-Defense-WallTower02" | ||||
"R-Sys-Sensor-Tower01" | duplicate? | |||
"R-Defense-Pillbox04" | ||||
"R-Wpn-MG2Mk1" | ||||
"R-Wpn-Rocket05-MiniPod" | ||||
"R-Wpn-MG-Damage01" | ||||
"R-Wpn-Rocket-Damage01" | ||||
"R-Defense-WallTower01" |
The technologies are given to the players using the completeResearch() function, so the players don't need to research those things at all - they are fully researched from the outset.
Starting Power
Starting with higher technology means you'll be constructing and producing more expensive things, so the power level needs to increase to compensate.
The normal game rules use the following starting power depending on base type:
baseType | ||
---|---|---|
CAMP_CLEAN | CAMP_BASE | CAMP_WALLS |
1300 | 2500 | 2500 |
You'll notice that CAMP_WALLS gets the same starting power as CAMP_BASE – that's not a typo, it's done that way on purpose. CAMP_WALLS gets so much extra technology that giving it any more starting power would unbalance the game too much.
Starting power is set using the setPower() function.
Removal of Map-Placed Structures
There are several factors besides baseType which affect the removal of map-placed structures, as defined in the table below:
Icon | baseType | Effect on normal players: | Effect on "INSANE" AI players: | Effect on Scavengers: |
---|---|---|---|---|
CAMP_CLEAN | All structures removed | Walls kept Defences kept Gates kept Oil Derricks kept Everything else is removed | All structures remain | |
CAMP_BASE | Gates removed Cyborg factories removed Command control (HQ) removed Walls removed Defences removed All other structures are kept. | Gates removed Cyborg factories removed Command control (HQs) removed All other structures are kept | All structures remain | |
CAMP_WALLS | All structures remain | All structures remain | All structures remain |
The building removal is achieved by using the removeStruct() function in Warzone 3.1, and removeObject() in Warzone 3.2 and above.
Construction Truck Template
It is customary in Warzone to be able to build trucks as soon as you've built a factory – without needing to do any research or build a HQ to enable Design Mode.
For this reason, there is a special function to enable construction trucks: enableTemplate(). It's applied only for the player that the instance of rules.js is associated with:
enableTemplate("ConstructionDroid");
Deviating from the Rules
The initialisation rules shown above are what everyone has come to expect at the start of the game. Any changes to them will likely be met with lots of heated debate, particularly if players aren't expecting the changes.
However, there are some scenarios where changing the initialisation rules may be worthwhile:
- Custom campaign mods
- Challenge maps
Both of these game modes do not affect Skirmish or Multiplayer games, so they are good places to experiment with different initialisation rules.
Contents
Assimilate: