Global

Members

(constant) ModificationSchema

Common definition of the XML schema for in-template modifications.
Source:

Methods

basename()

Removes prefixing path from a path or filename, leaving just the file's name (with extension) ie. a/b/c/file.ext -> file.ext
Source:

bicubicInterpolation(position)

Two dimensional interpolation within a square grid using a polynomial of degree three.
Parameters:
Name Type Description
position Vector2D Location of the point to interpolate, relative to p11
Source:

deepCompare(first, second) → {boolean}

Compare two variables recursively. This compares better than a quick JSON.stringify check since we also check undefineds, Sets and the like.
Parameters:
Name Type Description
first Any javascript instance.
second Any javascript instance.
Source:
Returns:
Whether first and second are equal.
Type
boolean

DeriveModificationFromXMLTemplate(techTemplate) → {Object}

Derives a single modification (to be applied to entities) from a given XML template.
Parameters:
Name Type Description
techTemplate Object The XML template node to derive the modification from.
Source:
Returns:
containing the relevant modification.
Type
Object

DeriveModificationsFromTech(techTemplate) → {Object}

Derives modifications (to be applied to entities) from a given aura/technology.
Parameters:
Name Type Description
techTemplate Object The aura/technology template to derive the modifications from.
Source:
Returns:
- An object containing the relevant modifications.
Type
Object

DeriveModificationsFromTechnologies(techsDataArray) → {Object}

Derives modifications (to be applied to entities) from a provided array of aura/technology template data.
Parameters:
Name Type Description
techsDataArray Array.<Object>
Source:
Returns:
- The combined relevant modifications of all the technologies.
Type
Object

DeriveModificationsFromXMLTemplate(techTemplate) → {Object}

Derives all modifications (to be applied to entities) from a given XML template.
Parameters:
Name Type Description
techTemplate Object The XML template node to derive the modifications from.
Source:
Returns:
containing the combined modifications.
Type
Object

DeriveTechnologyRequirements(template)

Derives the technology requirements from a given technology template. Takes into account the `supersedes` attribute.
Parameters:
Name Type Description
template Object The template object. Loading of the template must have already occured.
Source:
Returns:
Derived technology requirements. See `InterpretTechRequirements` for object's syntax.

dirname()

Returns the directories of a given path. ie. a/b/c/file.ext -> a/b/c
Source:

DoesModificationApply()

Returns whether the given modification applies to the entity containing the given class list NB: returns true if modifications.affects is empty, to allow "affects anything" modifiers.
Source:

FSM()

FSM API: Users define the FSM behaviour like: var FsmSpec = { // Define some default message handlers: "MessageName1": function(msg) { // This function will be called in response to calls to // Fsm.ProcessMessage(this, { "type": "MessageName1", "data": msg }); // // In this function, 'this' is the component object passed into // ProcessMessage, so you can access 'this.propertyName' // and 'this.methodName()' etc. }, "MessageName2": function(msg) { // Another message handler. }, // Define the behaviour for the 'STATENAME' state: // Names of states may only contain the characters A-Z "STATENAME": { "MessageName1": function(msg) { // This overrides the previous MessageName1 that was // defined earlier, and will be called instead of it // in response to ProcessMessage. }, // We don't override MessageName2, so the default one // will be called instead. // Define the 'STATENAME.SUBSTATENAME' state: // (we support arbitrarily-nested hierarchies of states) "SUBSTATENAME": { "MessageName2": function(msg) { // Override the default MessageName2. // But we don't override MessageName1, so the one from // STATENAME will be used instead. }, "enter": function() { // This is a special function called when transitioning // into this state, or into a substate of this state. // // If it returns true, the transition will be aborted: // do this if you've called SetNextState inside this enter // handler, because otherwise the new state transition // will get mixed up with the previous ongoing one. // In normal cases, you can return false or nothing. }, "leave": function() { // Called when transitioning out of this state. }, }, // Define a new state which is an exact copy of another // state that is defined elsewhere in this FSM: "OTHERSUBSTATENAME": "STATENAME.SUBSTATENAME", } } Objects can then make themselves act as an instance of the FSM by running FsmSpec.Init(this, "STATENAME"); which will define a few properties on 'this' (with names prefixed "fsm"), and then they can call the FSM functions on the object like FsmSpec.SetNextState(this, "STATENAME.SUBSTATENAME"); These objects must also define a function property that can be called as this.FsmStateNameChanged(name); (This design aims to avoid storing any per-instance state that cannot be easily serialized - it only stores state-name strings.)
Source:

GetAuraDataHelper(template)

Get information about an aura template.
Parameters:
Name Type Description
template object A valid template as obtained by loading the aura JSON file.
Source:

GetBaseTemplateDataValue(template, value_path) → {number}

Gets the value originating at the value_path as-is, with no modifiers applied.
Parameters:
Name Type Description
template Object A valid template as returned from a template loader.
value_path string Route to value within the xml template structure.
Source:
Returns:
Type
number

GetIdentityClasses() → {Array.<string>}

Source:
Returns:
- All the classes for this identity template.
Type
Array.<string>

GetModifiedTemplateDataValue(template, value_path, mod_key, player, modifiers) → {number}

Gets the value originating at the value_path with the modifiers dictated by the mod_key applied.
Parameters:
Name Type Description
template Object A valid template as returned from a template loader.
value_path string Route to value within the xml template structure.
mod_key string Tech modification key, if different from value_path.
player number Optional player id.
modifiers Object Value modifiers from auto-researched techs, unit upgrades, etc. Optional as only used if no player id provided.
Source:
Returns:
Modifier altered value.
Type
number

GetTechModifiedProperty(modifications, classes, originalValue)

Returns modified property value modified by the applicable tech modifications.
Parameters:
Name Type Description
modifications array of modificiations
classes Array containing the class list of the template.
originalValue Number storing the original value. Can also be non-numeric, but then only "replace" and "tokens" techs can be supported.
Source:

GetTechnologyBasicDataHelper(template, civ)

Get basic information about a technology template.
Parameters:
Name Type Description
template Object A valid template as obtained by loading the tech JSON file.
civ string Civilization for which the tech requirements should be calculated.
Source:

GetTechnologyDataHelper(template, civ)

Get information about a technology template.
Parameters:
Name Type Description
template Object A valid template as obtained by loading the tech JSON file.
civ string Civilization for which the specific name and tech requirements should be returned.
Source:

GetTemplateDataHelper(template, player, auraTemplates, modifiers)

Get information about a template with or without technology modifications. NOTICE: The data returned here should have the same structure as the object returned by GetEntityState and GetExtendedEntityState!
Parameters:
Name Type Description
template Object A valid template as returned by the template loader.
player number An optional player id to get the technology modifications of properties.
auraTemplates Object In the form of { key: { "auraName": "", "auraDescription": "" } }.
modifiers Object Modifications from auto-researched techs, unit upgrades etc. Optional as only used if there's no player id provided.
Source:

GetVisibleIdentityClasses()

Gets an array with all classes for this identity template that should be shown in the GUI
Source:

HandleTokens()

Returns a modified list of tokens. Supports "A>B" to replace A by B, "-A" to remove A, and the rest will add tokens.
Source:

heapsPermute()

Generates each permutation of the given array and runs the callback function on it. Uses the given clone function on each item of the array. Creating arrays with all permutations of the given array has a bad memory footprint. Algorithm by B. R. Heap. Changes the input array.
Source:

InterpretTechRequirements(civ, operator, value)

Interprets the prerequisite requirements of a technology. Takes the initial { key: value } from the short-form requirements object in entity templates, and parses it into an object that can be more easily checked by simulation and gui. Works recursively if needed. The returned object is in the form: ``` { "techs": ["tech1", "tech2"] }, { "techs": ["tech3"] } ``` or ``` { "entities": [[{ "class": "human", "number": 2, "check": "count" } or ``` false; ``` (Or, to translate: 1. need either both `tech1` and `tech2`, or `tech3` 2. need 2 entities with the `human` class 3. cannot research this tech at all)
Parameters:
Name Type Description
civ string The civ code
operator string The base operation. Can be "civ", "notciv", "tech", "entity", "all" or "any".
value mixed The value associated with the above operation.
Source:
Returns:
Object containing the requirements for the given civ, or false if the civ cannot research the tech.

listFiles()

Returns names of files found in the given directory, stripping the directory path and file extension.
Source:

MatchesClassList(classes, match)

Check if a given list of classes matches another list of classes. Useful f.e. for checking identity classes.
Parameters:
Name Type Description
classes List of the classes to check against.
match Either a string in the form "Class1 Class2+Class3" where spaces are handled as OR and '+'-signs as AND, and ! is handled as NOT, thus Class1+!Class2 = Class1 AND NOT Class2. Or a list in the form [["Class1"], ["Class2", "Class3"]] where the outer list is combined as OR, and the inner lists are AND-ed. Or a hybrid format containing a list of strings, where the list is combined as OR, and the strings are split by space and '+' and AND-ed.
Source:
Returns:
undefined if there are no classes or no match object true if the the logical combination in the match object matches the classes false otherwise.

pickRandom()

Return a random element of the source array.
Source:

randBool()

Returns a Bernoulli distributed boolean with p chance on true.
Source:

randFloat()

Return a random floating point number in the interval [min, max).
Source:

randIntExclusive()

Return a random integer of the interval [floor(min) .. ceil(max-1)]. If an argument is not integer, the uniform distribution is cut off at that endpoint. For example randIntExclusive(1.5, 3.5) yields 50% chance to get 2 and 25% chance for 1 and 3.
Source:

randIntInclusive()

Return a random integer of the interval [floor(min) .. ceil(max)] using Math.random library. If an argument is not integer, the uniform distribution is cut off at that endpoint. For example randIntInclusive(1.5, 2.5) yields 50% chance to get 2 and 25% chance for 1 and 3.
Source:

randomAngle()

Returns a random radians between 0 and 360 degrees.
Source:

removeFiltersFromTemplateName()

Remove filter prefix (mirage, corpse, etc) from template name. ie. filter|dir/to/template -> dir/to/template
Source:

TradeGain()

Part of the trade gain which depends on the distance, the full gain being TradeGainNormalization * TradeGain.
Source:

UnravelPhases(phases) → {array}

Determine order of phases.
Parameters:
Name Type Description
phases Object The current available store of phases.
Source:
Returns:
List of phases
Type
array