A typical sequence for building a new structure is:
Check if the structure can be built (eg. has it been researched, have structure limits been reached, etc?)
Find a free construction droid to do the construction (use enumDroid() to get a list of available droids)
Find a suitable location for the structure (use pickStructLocation() – RTFM for important notes on how the function works)
Order an idle construction droid (truck or engineer) to start the construction at the selected location
Only construction droids (trucks and field engineers) of type DROID_CONSTRUCT can build structures.
Example
// define some constants if missing
if (typeof NORTH == "undefined") {
const NORTH = 0;
const EAST = 90;
const SOUTH = 180;
const WEST = 270;
}
function isIdle(droid) {
var notIdle = [
DORDER_BIULD,
DORDER_HELPBUILD,
DORDER_LINEBUILD,
DORDER_DEMOLISH
];
return (notIdle.indexOf(droid.order) == -1);
}
function buildA(structure, near) {
// can we build the structure?
if (!isStructureAvailable(structure)) return false;
// get list of construction droids
var constructors = enumDroid(me, DROID_CONSTRUCT);
// find free droid
var freeDroid;
constructors.some(function isFree(droid) {
if (isIdle(droid)) {
freeDroid = droid;
return true;
}
});
// if no free droids abort
if (!freeDroid) return false;
// find suitable location to build
var pos = pickStructLocation(freeDroid, structure, near.x, near.y);
// abort if no location found
if (!pos) return false;
// let's build!
return orderDroidBuild(
freeDroid,
DORDER_BUILD,
structure,
pos.x,
pos.y,
NORTH
);
}
// find where our HQ is
var nearMyHQ = enumStuct(me, HQ)[0]; // assuming we already have one
buildA("A0LightFactory", nearMyHQ); // build a factory near my HQ
Availability STABLE
Requires:
Warzone 3.1 Beta 1 or above
The 'direction' parameter was added in Warzone 3.1.0
Contents
Jump to:
See also
Related articles:
orderDroidObj() – use if you want additional droids to help with construction