(info) 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 IDDescriptionReason
"A0CommandCentre"Command Centre (HQ or CC)The player needs access to Design Mode and Mini Map
"A0LightFactory"FactoryThe player needs to build construction trucks
"A0ResourceExtractor"Oil DerrickThe player needs to gain power
"A0PowerGenerator"Power GeneratorPower Generators are required to make Oil Derricks work
"A0ResearchFacility"Research FacilityResearch 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:

IconComponent IDDescription
 "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:

IconResearch IDDescription
"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:

IconStructure IDDescriptionLimit
"A0LightFactory"Factory5
"A0PowerGenerator"Power Generator8
"A0ResearchFacility"Research Facility5
"A0CommandCentre"Command Centre (HQ or CC)1
"A0ComDroidControl"Command Relay Centre (CRC)1
"A0CyborgFactory"Cyborg Factory5
"A0VTolFactory1"VTOL Factory5

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 IDDescriptionbaseType
 CAMP_CLEANCAMP_BASE CAMP_WALLS 
"R-Vehicle-Prop-Wheels"Wheeled Propulsion(tick)(tick)(tick)
"R-Sys-Spade1Mk1"Construction Turret(tick)(tick)(tick)
"R-Vehicle-Body01"Viper Body(tick)(tick)(tick)
"R-Comp-SynapticLink"Synaptic Link(tick)(tick)(tick)
"R-Wpn-MG1Mk1"Machine gun (tick)(tick)
"R-Defense-HardcreteWall"Hardcrete Wall (tick)(tick)
"R-Vehicle-Prop-Wheels"(warning) duplicate? (tick)(tick)
"R-Sys-Spade1Mk1"(warning) duplicate? (tick)(tick)
"R-Struc-Factory-Cyborg"Cyborg Factory (tick)(tick)
"R-Defense-Pillbox01"  (tick)(tick)
"R-Defense-Tower01"  (tick)(tick)
"R-Vehicle-Body01"(warning) duplicate? (tick)(tick)
"R-Sys-Engineering01"Engineering (tick)(tick)
"R-Struc-CommandRelay"Command Relay Centre (tick)(tick)
"R-Vehicle-Prop-Halftracks"Halftracked Propulsion (tick)(tick)
"R-Comp-CommandTurret01"Command Turret Mk 1 (tick)(tick)
"R-Sys-Sensor-Turret01"Sensor Turret (tick)(tick)
"R-Wpn-Flamer01Mk1"  (tick)(tick)
"R-Vehicle-Body05"   (tick)
"R-Struc-Research-Module"Research Module  (tick)
"R-Struc-PowerModuleMk1"Power Module  (tick)
"R-Struc-Factory-Module"Factory Module  (tick)
"R-Struc-RepairFacility"Repair Facility  (tick)
"R-Sys-MobileRepairTurret01"Mobile Repair Turret  (tick)
"R-Vehicle-Engine01"   (tick)
"R-Wpn-MG3Mk1"   (tick)
"R-Wpn-Cannon1Mk1"   (tick)
"R-Wpn-Mortar01Lt"   (tick)
"R-Defense-Pillbox05"   (tick)
"R-Defense-TankTrap01"Tank Traps  (tick)
"R-Defense-WallTower02"   (tick)
"R-Sys-Sensor-Tower01"(warning) duplicate?  (tick)
"R-Defense-Pillbox04"   (tick)
"R-Wpn-MG2Mk1"   (tick)
"R-Wpn-Rocket05-MiniPod"   (tick)
"R-Wpn-MG-Damage01"   (tick)
"R-Wpn-Rocket-Damage01"   (tick)
"R-Defense-WallTower01"   (tick)

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:

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:

IconbaseTypeEffect on normal players:Effect on "INSANE" AI players:Effect on Scavengers:
CAMP_CLEAN

(error) All structures removed

(tick) Walls kept

(tick) Defences kept

(tick) Gates kept

(tick) Oil Derricks kept

(error) Everything else is removed

(tick) All structures remain

CAMP_BASE

(error) Gates removed

(error) Cyborg factories removed

(error) Command control (HQ) removed

(error) Walls removed

(error) Defences removed

(tick) All other structures are kept.

(error) Gates removed

(error) Cyborg factories removed

(error) Command control (HQs) removed

(tick) All other structures are kept

(tick) All structures remain

CAMP_WALLS

(tick) All structures remain

(tick) All structures remain

(tick) 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.

The technologies given to players on T2 and T3 games is currently defined elsewhere - see T2 and T3 tech idea for a proposal to move that in to rules.js.
See Enhanced SitRep Mod for an example of player initialisation code.

Contents

Assimilate: