Other great resources: Official JS API docs, Scripting Forum
Player Initialisation
Initialise player structures, components, technologies and bases before the game starts...
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" | The player needs to build construction trucks | ||
"A0ResourceExtractor" | The player needs to gain power | ||
"A0PowerGenerator" | Power Generators are required to make Oil Derricks work | ||
"A0ResearchFacility" | 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" | ||
"CyborgRepair" | ||
"Cyb-Wpn-Atmiss" | ||
"CyborgCannon" | ||
"CyborgChaingun" | ||
"CyborgFlamer01" | ||
"Cyb-Wpn-Grenade" | ||
"Cyb-Hvywpn-A-T" | ||
"Cyb-Hvywpn-Acannon" | ||
"Cyb-Hvywpn-HPV" | ||
"Cyb-Hvywpn-Mcannon" | ||
"Cyb-Hvywpn-PulseLsr" | ||
"Cyb-Hvywpn-RailGunner" | ||
"Cyb-Hvywpn-TK" | ||
"Cyb-Wpn-Laser" | ||
"Cyb-Wpn-Rail1" | ||
"CyborgRocket" | ||
"CyborgRotMG" | ||
"Cyb-Wpn-Thermite" |
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" | 5 | ||
"A0PowerGenerator" | 8 | ||
"A0ResearchFacility" | 5 | ||
"A0CommandCentre" | Command Centre (HQ or CC) | 1 | |
"A0ComDroidControl" | Command Relay Centre (CRC) | 1 | |
"A0CyborgFactory" | 5 | ||
"A0VTolFactory1" | 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 | |||
|---|---|---|---|---|
"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 |
|
| |