Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Excerpt |
---|
This function guesses the droid type from its stats... |
Syntax
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
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
Parameter | Type | Notes |
---|---|---|
factoryType | Constant | If the droid is being built in a factory, this will be the .stattype of that factory:
|
body | String | The body component |
propulsion | String | The propulsion compoment |
reserved | Undefined | Ignore this parameter for now. |
t1, t2, t3 | String | Up to three turret components |
Return value
Your function should return a valid .droidType constant:
Child pages (Children Display) | ||||
---|---|---|---|---|
|
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.
The Warzone 3.1 bug with cyborg engineers and mechanics is dealt with externally to this function (your function should not return types 10 or 11).
Example
The API provides a default version of this function that is based on standard game stats...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
go.guessDroidTypeFromStats = function(factoryType, body, prop, reserved, turret1, t2, t3) {
if (isDefined(factoryType)) { // simplifies things a little
switch (factoryType) {
case CYBORG_FACTORY: {
// check for non-weapon droids first
// note: 3.1 buildDroid() bug is dealt with in Defines/GO32/DroidProduction.js
if (turret1.contains("Spade" )) return DROID_CONSTRUCT;
if (turret1.contains("Repair")) return DROID_REPAIR;
// failing that, check if it's a person or cyborg
return body.contains("Person") || propulsion.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 (turret1.contains("Spade")) return DROID_CONSTRUCT;
if (turret1.contains("epair")) return DROID_REPAIR;
if (turret1.contains("ECM")) return DROID_ECM;
if (turret1.contains("Sensor")
|| turret1.contains("Radar")
|| turret1.contains("CB")
|| turret1.contains("rike")) return DROID_SENSOR
;
if (turret1.contains("Brain")
|| turret1.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;
} |