Changes between Version 2 and Version 3 of AIEngineAPI


Ignore:
Timestamp:
Jul 19, 2012, 12:20:25 AM (12 years ago)
Author:
Jonathan Waller
Comment:

Added some information about entities

Legend:

Unmodified
Added
Removed
Modified
  • AIEngineAPI

    v2 v3  
    33> Note by lexa: here is [http://code.google.com/p/split-bot/source/browse/#svn%2Ftrunk%2Fsrc%2Forg%2Fzeroad%2Fcommon_api a fully typed description of the javascript classes]
    44
     5The Engine uses the AIInterface and AIProxy components to provide this data.  The AIInterface is a player level component which handles communication with the AI.  AIProxy is an entity level component which creates a proxy representation of each entity to be given to the AI.
     6
    57The AI's `HandleMessage` method is called with one argument:
    68
    7 {{{
     9{{{#!js
    810state = {
    911  entities: ...,
     
    1113  players: [...],
    1214  timeElapsed: ..., // seconds since the start of the match
    13   map: ...,
     15  territoryMap: ..., // map of player territories
     16  passabilityMap: ..., // Map showing where obstructions are
    1417  passabilityClasses: ...
    15 };
    1618}}}
    1719== `entities` ==
    18 TODO
     20Each entity has a set of dynamic properties which are kept up to date.  The AI can also access the template data for all entities.
     21
     22An entity will have the form
     23
     24{{{#!js
     25var ret = {
     26  "id": 172, // This id is unique and permanent
     27  "template": "unit/hele_spearman",
     28  "position": [102.2, 34.7], // The unit position is undefined in some cases (e.g. garrisoned)
     29  "hitpoints": 80,
     30  "owner": 4, // Player who owns this unit
     31  "idle": true,
     32  "unitAIState": "UNIT/INDIVIDUAL/GATHERING",
     33  "unitAIOrderData": cmpUnitAI.GetOrderData(),
     34  "trainingQueue": [{
     35                      "id": 7,
     36                      "unitTemplate": "spearman", // If this is a unit being trained
     37                      "technologyTemplate": "phase_city", // If this is a technology being researched
     38                      "count": 5, // number of units being trained
     39                      "progress": 0.78, // Proportion of training completed (range 0.0 to 1.0)
     40                      "metadata": {"role": "worker"}, // The AI can set metadata when adding a unit to the queue
     41                    }, ... ], // Array of items currently in the training queue
     42  "foundationProgress": 78, // Percentage complete for construction
     43  "resourceSupplyAmount": 195, // Current resources in a resource deposit (tree, mine, ...)
     44  "resourceCarrying": [{
     45                         "type": "wood", // Resource type
     46                         "amount": 8, // Amount currently being carried
     47                         "max": 20 // Maximum amout of this resource which can be carried
     48                       }, ... ], // array of resources being carried by a gathering unit
     49  "garrisoned": [167, 377, 345] // array of entity id's for the garrisoned entities
     50}
     51}}}
    1952
    2053== `events` ==
    2154TODO
    2255
    23 == `map` and `passabilityClasses` ==
    24 {{{
    25 state.map = {
     56== `passabilityMap` and `passabilityClasses` ==
     57{{{#!js
     58state.passabilityMap = {
    2659  width: 256,
    2760  height: 256,
     
    2962};
    3063}}}
    31 {{{
     64{{{#!js
    3265state.passabilityClasses = {
    3366  "pathfinderObstruction": 1,
     
    3770};
    3871}}}
    39 `state.map.data` encodes all the passability data of each terrain tile. `state.passabilityClasses` gives bitmasks that define how to interpret `state.map.data`. For example:
     72`state.passabilityMap.data` encodes all the passability data of each terrain tile. `state.passabilityClasses` gives bitmasks that define how to interpret `state.map.data`. For example:
    4073
    41 {{{
     74{{{#!js
    4275// Get the bitmask for tiles that will obstruct foundations (i.e. you can't place any buildings there)
    4376var obstructionMask = gameState.getPassabilityClassMask("foundationObstruction");
     
    5083Since these are bitmasks, you can 'or' them together:
    5184
    52 {{{
     85{{{#!js
    5386var obstructionMask = gameState.getPassabilityClassMask("foundationObstruction");
    5487