Changes between Version 2 and Version 3 of AIEngineAPI
- Timestamp:
- Jul 19, 2012, 12:20:25 AM (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
AIEngineAPI
v2 v3 3 3 > 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] 4 4 5 The 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 5 7 The AI's `HandleMessage` method is called with one argument: 6 8 7 {{{ 9 {{{#!js 8 10 state = { 9 11 entities: ..., … … 11 13 players: [...], 12 14 timeElapsed: ..., // seconds since the start of the match 13 map: ..., 15 territoryMap: ..., // map of player territories 16 passabilityMap: ..., // Map showing where obstructions are 14 17 passabilityClasses: ... 15 };16 18 }}} 17 19 == `entities` == 18 TODO 20 Each 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 22 An entity will have the form 23 24 {{{#!js 25 var 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 }}} 19 52 20 53 == `events` == 21 54 TODO 22 55 23 == ` map` and `passabilityClasses` ==24 {{{ 25 state. map = {56 == `passabilityMap` and `passabilityClasses` == 57 {{{#!js 58 state.passabilityMap = { 26 59 width: 256, 27 60 height: 256, … … 29 62 }; 30 63 }}} 31 {{{ 64 {{{#!js 32 65 state.passabilityClasses = { 33 66 "pathfinderObstruction": 1, … … 37 70 }; 38 71 }}} 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: 40 73 41 {{{ 74 {{{#!js 42 75 // Get the bitmask for tiles that will obstruct foundations (i.e. you can't place any buildings there) 43 76 var obstructionMask = gameState.getPassabilityClassMask("foundationObstruction"); … … 50 83 Since these are bitmasks, you can 'or' them together: 51 84 52 {{{ 85 {{{#!js 53 86 var obstructionMask = gameState.getPassabilityClassMask("foundationObstruction"); 54 87