(info) Other great resources: Official JS API docs, Scripting Forum

Mini Map and Design Mode

Enable or disable the mini map and design mode depending on the presence of a HQ.

 

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:

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...

'me' approach... (recommended)
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...

'selectedPlayer' approach...
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:

Related documentation: