32 | | {{{#!js |
33 | | var ret = { |
34 | | "id": 172, // This id is unique and permanent |
35 | | "template": "unit/hele_spearman", |
36 | | "position": [102.2, 34.7], // The unit position is undefined in some cases (e.g. garrisoned) |
37 | | "hitpoints": 80, |
38 | | "owner": 4, // Player who owns this unit |
39 | | "idle": true, |
40 | | "unitAIState": "UNIT/INDIVIDUAL/GATHERING", |
41 | | "unitAIOrderData": cmpUnitAI.GetOrderData(), |
42 | | "trainingQueue": [{ |
43 | | "id": 7, |
44 | | "unitTemplate": "spearman", // If this is a unit being trained |
45 | | "technologyTemplate": "phase_city", // If this is a technology being researched |
46 | | "count": 5, // number of units being trained |
47 | | "progress": 0.78, // Proportion of training completed (range 0.0 to 1.0) |
48 | | "metadata": {"role": "worker"}, // The AI can set metadata when adding a unit to the queue |
49 | | }, ... ], // Array of items currently in the training queue |
50 | | "foundationProgress": 78, // Percentage complete for construction |
51 | | "resourceSupplyAmount": 195, // Current resources in a resource deposit (tree, mine, ...) |
52 | | "resourceCarrying": [{ |
53 | | "type": "wood", // Resource type |
54 | | "amount": 8, // Amount currently being carried |
55 | | "max": 20 // Maximum amout of this resource which can be carried |
56 | | }, ... ], // array of resources being carried by a gathering unit |
57 | | "garrisoned": [167, 377, 345] // array of entity id's for the garrisoned entities |
58 | | } |
59 | | }}} |
| 35 | {{{#!js var ret = { |
| 36 | |
| 37 | "id": 172, // This id is unique and permanent "template": "unit/hele_spearman", "position": [102.2, 34.7], // The unit position is undefined in some cases (e.g. garrisoned) "hitpoints": 80, "owner": 4, // Player who owns this unit "idle": true, "unitAIState": "UNIT/INDIVIDUAL/GATHERING", "unitAIOrderData": cmpUnitAI.[wiki:GetOrderData] (), "trainingQueue": [{ |
| 38 | "id": 7, "unitTemplate": "spearman", // If this is a unit being trained "technologyTemplate": "phase_city", // If this is a technology being researched "count": 5, // number of units being trained "progress": 0.78, // Proportion of training completed (range 0.0 to 1.0) "metadata": {"role": "worker"}, // The AI can set metadata when adding a unit to the queue |
| 39 | }, ... ], // Array of items currently in the training queue |
| 40 | |
| 41 | "foundationProgress": 78, // Percentage complete for construction |
| 42 | |
| 43 | "resourceSupplyAmount": 195, // Current resources in a resource deposit (tree, mine, ...) "resourceCarrying": [{ |
| 44 | "type": "wood", // Resource type "amount": 8, // Amount currently being carried "max": 20 // Maximum amout of this resource which can be carried |
| 45 | }, ... ], // array of resources being carried by a gathering unit |
| 46 | |
| 47 | "garrisoned": [167, 377, 345] // array of entity id's for the garrisoned entities } }}} |
82 | | {{{#!js |
83 | | // Get the bitmask for tiles that will obstruct foundations (i.e. you can't place any buildings there) |
84 | | var obstructionMask = gameState.getPassabilityClassMask("foundationObstruction"); |
| 55 | "width": 256, "height": 256, "data": [ ... ] // Uint16Array with width*height entries |
| 56 | |
| 57 | }; }}} {{{#!js state.passabilityClasses = { |
| 58 | |
| 59 | "pathfinderObstruction": 1, "foundationObstruction": 2, "building-land": ..., // these are all the PassabilityClasses defined in simulation/data/pathfinder.xml ... |
| 60 | |
| 61 | }; }}} `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: |
| 62 | |
| 63 | {{{#!js // Get the bitmask for tiles that will obstruct foundations (i.e. you can't place any buildings there) var obstructionMask = gameState.getPassabilityClassMask("foundationObstruction"); |
87 | | if (map.data[i] & obstructionMask) |
88 | | ; // tile i is an unbuildable location |
| 66 | |
| 67 | if (map.data[i] & obstructionMask) |
| 68 | ; // tile i is an unbuildable location |
| 69 | |
| 70 | }}} Since these are bitmasks, you can 'or' them together: |
| 71 | |
| 72 | {{{#!js var obstructionMask = gameState.getPassabilityClassMask("foundationObstruction"); |
| 73 | |
| 74 | // Add in the bitmask for tiles that are obstructed for the "building-land" passability class // (i.e. tiles that are underwater or too steep, based on the definition in pathfinder.xml) obstructionMask |= gameState.getPassabilityClassMask("building-land"); |
| 75 | |
| 76 | for (var i = 0; i < map.data.length; ++i) |
| 77 | |
| 78 | if (map.data[i] & obstructionMask) |
| 79 | ; // tile i is an unbuildable location for land-based buildings |