Other great resources: Official JS API docs, Scripting Forum
Mini Map and Design Mode
- Aubergine
Â
Summary
Under normal game rules a HQ is required to enable the Design Mode (droid design tool) and mini map.
If the HQ gets destroyed, both those features must be disabled. If a HQ gets build, they are re-enabled.
The code to do this is usually stored in a function so that it can be called from three key events:
- eventGameInit() – when the game starts, as there might be a HQ present after Player Initialisation (for example a HQ pre-placed on the map at design time, and the baseType setting retained it).
- eventStructureBuilt() – in case an HQ has been built
- eventDestroyed() – in case the HQ has been destroyed
Human Player Only
The rules.js script is responsible for performing this check. Unlike the other things it does, this check needs to be limited to the localhost human player (defined by the 'selectedPlayer' or 'me' global, depending on how you want to do it).
Example Code
Assuming the player won't be using the Debug Menu to switch to other players, you can use me for your player checks...
function checkHQ(state) { // if you know the ID of HQ structure, using countStruct() would be faster (3.2+) (!arguments.length) ? state = !!enumStruct(me, HQ).length :; setDesign(state); // set design mode state setMiniMap(state); // set mini map state } Â function eventGameInit() { // do player init stuff checkHQ(); } function isMyHQ(obj) { return (obj.player == me && obj.type == STRUCTURE && obj.stattype == HQ); } Â function eventDestroyed(obj) { // note: mods can allow more than one HQ; if so, remove 'false' isMyHQ(obj) ? checkHQ(false) :; } Â function eventStructureBuilt(obj, droid) { isMyHQ(obj) ? checkHQ(true) :; }
If you want to be more comprehensive, and set minimap and design accurately even if the localhost human switches to a different player, then you'll need to use selectedPlayer instead, which is a bit more complex...
function checkHQ(state) { // if you know the ID of HQ structure, using countStruct() would be faster (3.2+) (!arguments.length) ? state = !!enumStruct(selectedPlayer, HQ).length :; setDesign(state); // set design mode state setMiniMap(state); // set mini map state } Â function eventGameInit() { // do player init stuff checkHQ(); // make sure we refresh if selectedPlayer changes setTimer("hasPlayerChanged", 5000); // allow some lag to avoid performance issues } Â function hasPlayerChanged() { (selectedPlayer != me) ? checkHQ() :; } function isMyHQ(obj) { return (obj.player == selectedPlayer && obj.type == STRUCTURE && obj.stattype == HQ); } function eventDestroyed(obj) { // note: mods can allow more than one HQ; if so, remove 'false' isMyHQ(obj) ? checkHQ(false) :; } function eventStructureBuilt(obj, droid) { isMyHQ(obj) ? checkHQ(true) :; }
Contents
Assimilate:
Developer Links
Related documentation:
- setDesign() – enable or disable design mode
- setMiniMap() – enable or disable mini map
- enumStruct()– get a list of structures
- Structure object – defines properties of a structure
- STRUCTURE – indicates a game object represents a structure
Â