This AI is still in early stages of development.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

This function guesses the droid type from its stats...

 

Syntax

go.guessDroidTypeFromStats(factoryType, body, propulsion, reserved, t1, t2, t3) {
	// ... guess droidType here ...
 
	return guessedType; // return DROID_ANY if you couldn't guess the type
}

Parameters

ParameterTypeMandatoryNotes
factoryTypeConstant(tick)

If the droid is being built in a factory, this will be the .stattype of that factory:

bodyString(tick)The body component
propulsionString(tick)The propulsion compoment
reservedUndefined(tick)Ignore this parameter for now.
t1, t2, t3String(tick)Up to three turret components

Return value

Your function should return a valid .droidType constant:

  • DROID_ANYUsed to bypass droid type filtering in functions that list or count droids.
  • DROID_COMMANDA commander unit, to which other units can be assigned.
  • DROID_CONSTRUCTA construction truck or a cyborg engineer.
  • DROID_CYBORGA cyborg warrior capable of attacking the enemy.
  • DROID_ECMA droid that has an Electronic Counter Measures (radar jammer) turret.
  • DROID_PERSONA droid that uses "legs" propulsion, for example a civilian or a scavenger machinegunner.
  • DROID_REPAIRA droid that has a repair turret, capable of repairing other droids.
  • DROID_SENSOR
  • DROID_SUPERTRANSPORTERA heavy transport unit, capable of airlifting any type of droid (including VTOLs) to some other location on the map...
  • DROID_TRANSPORTERA cyborg transporter (or possibly a super transporter in Warzone 3.1 Beta 4 and earlier), capable of airlifting droids to some other location on the map.
  • DROID_WEAPONA droid capable of attacking other droids.

If you are unable to determine the droid type, return DROID_ANY.

Notes

The results of the function are cached externally – so there's generally no need to build any additional caching in to your function.

This function is used to guess the droid type for the buildDroid() and addDroid() JS API functions, which in Warzone 3.2 do not use the droidType parameter.

If the external call to buildDroid() or addDroid() specifies a valid droid type, that value will be assumed correct except in the following cases:

  • Cyborg engineers/mecanics (see note below)
  • DROID_ANY – the guess function will be invoked
  • null, undefined or "" – the guess function will be invoked

The Warzone 3.1 bug with cyborg engineers and mechanics is dealt with separately (your function should never return types 10 or 11).

Example

The API provides a default version of this function that is based on standard game stats...

go.guessDroidTypeFromStats = function(factoryType, body, prop, reserved, t1, t2, t3) {
	if (isDefined(factoryType)) { // simplifies things a little
		switch (factoryType) {
			case CYBORG_FACTORY: {
				// check for non-weapon droids first
				if (t1.contains("Spade" )) return DROID_CONSTRUCT;
				if (t1.contains("Repair")) return DROID_REPAIR;
				// failing that, check if it's a person or cyborg
				return body.contains("Person") || prop.contains("BaBa")
					? DROID_PERSON
					: DROID_CYBORG
				;
			}
			case VTOL_FACTORY: {
				switch (body) {
					case "TransporterBody"   : return DROID_TRANSPORTER;
					case "SuperTransportBody": return DROID_SUPERTRANSPORTER;
					default: return DROID_WEAPON;
				}
			}
			case FACTORY: {
				if (t1.contains("Spade")) return DROID_CONSTRUCT;
				if (t1.contains("epair")) return DROID_REPAIR;
				if (t1.contains("ECM")) return DROID_ECM;
				if (t1.contains("Sensor")
					|| t1.contains("Radar")
					|| t1.contains("CB")
					|| t1.contains("rike")) return DROID_SENSOR
				;
				if (t1.contains("Brain")
					|| t1.contains("Command")) return DROID_COMMAND
				;
				return DROID_WEAPON;
			}
		}
	} else switch (prop) { // work out what factory would be required and try again
		case "V-Tol"     : {
			arguments[0] = VTOL_FACTORY;
			return arguments.callee.apply(go, arguments);
		}
		case "BaBaLegs"  :
		case "CyborgLegs": {
			arguments[0] = CYBORG_FACTORY;
			return arguments.callee.apply(go, arguments);
		}
		case "BaBaProp"  :
		case "wheeled01" :
		case "HalfTrack" :
		case "tracked01" :
		case "hover01"   : {
			arguments[0] = FACTORY;
			return arguments.callee.apply(go, arguments);
		}
	}
	return DROID_ANY;
}
Availability 3.1 BRANCH

Requires:

  • Warzone 3.1 Branch
  • The default function is not published on Warzone 3.2 or above (but you can still add your own)
Contents

Jump to:

 

  • No labels