This AI is still in early stages of development.
You are viewing an old version of this page. View the current version.
Compare with Current View Page History
Version 1 Next »
go.cuessComponentType = function(comp) { // ... guess component type ... return guessedType; }
The function should return a constant defining the component type.
A list of constants can be found in the componentAvailable() "Notes" section.
GO32 defines the constants.
This function is used by componentAvailable() on Warzone 3.1 if the component type is not specified.
If the component type is specified, it is assumed to be correct and this function will not be invoked.
The function should provide it's own internal caching to improve performance (see example below).
A default function is provided by componentAvailable.js, a simplified version of which is shown below...
var componentCache = {}; // body and propulsion components are pre-cached (not shown in this example) go.guessComponentType = function(comp) { if (componentCache.hasOwnProperty(comp)) return componentCache[comp]; if (comp.contains("Brain") || comp.contains("Command")) { return componentCache[comp] = COMP_BRAIN; } if (comp.contains("epair")) { return componentCache[comp] = COMP_ECM; } if (comp.contains("ECM")) { return componentCache[comp] = COMP_ECM; } if (comp.contains("Spade")) { return componentCache[comp] = COMP_CONSTRUCT; } if (comp.contains("Sensor") || comp.contains("Radar") || comp.contains("CB") || comp.contains("trike")) { return componentCache[comp] = COMP_SENSOR; } return COMP_WEAPON; }