(info) This AI is still in early stages of development.

go.guessComponentType()

Guess the type of a specified component...

 

Syntax

go.cuessComponentType = function(comp) {
	// ... guess component type ...
 
	return guessedType;
}

Parameters

ParameterTypeNotes
compStringThe component ID that the type should be determined for.

Return values

The function should return a constant defining the component type.

A list of constants can be found in the componentAvailable() "Notes" section.

(info) The constants are pre-defined by componentAvailable.js so you don't need to define them yourself.

If you're unable to guess the component type, return COMP_UNKNOWN.

Notes

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

Example

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;
}
Availability 3.1

Requires:

The default function is not published on WZ 3.2+

Contents

Jump to: