Chanded some filenames

Removed automatic path placement.
Started command section.
This commit is contained in:
Gebruiker
2022-10-23 01:19:58 +02:00
parent 1806935c50
commit ef9159260b
9 changed files with 67 additions and 176 deletions

View File

@@ -12,70 +12,4 @@ class _Room extends Room {
// Start game when spawn is in neutral room make it the capital.
if (this.controller.my && this.memory.state == ROOMSTATE_NEUTRAL) this.memory.state = ROOMSTATE_CAPITAL;
}
//#region Checks
// Is the max amount of construction sites achieved?
canConstruct() { return this.find(FIND_CONSTRUCTION_SITES).length < 90; }
//#endregion
//#region Construcion
// Place construction sites for the road system.
planRoads() {
if (this.memory.roadsPlanned == undefined) this.memory.roadsPlanned = false;
if (this.memory.roadsPlanned) return;
var target_array = [];
var index = 0;
// For any structure of given type add to targets.
this.find(FIND_MY_STRUCTURES, {
filter: function (structure) {
var value = structure.structureType == STRUCTURE_SPAWN;
value = value || structure.structureType == STRUCTURE_CONTAINER;
value = value || structure.structureType == STRUCTURE_CONTROLLER;
value = value || structure.structureType == STRUCTURE_EXTENSION;
value = value || structure.structureType == STRUCTURE_STORAGE;
value = value || structure.structureType == STRUCTURE_TOWER;
return value;
}
}).forEach(structure => {
target_array[index++] = structure.pos;
});
// Add all sources to targets.
this.find(FIND_SOURCES).forEach(source => {
target_array[index++] = source.pos;
});
// Add minerals to targers
this.find(FIND_MINERALS).forEach(mineral => {
target_array[index++] = mineral.pos;
});
// Build a road for every permutation of the targets.
for (let i = 0; i < target_array.length; i++) {
const begin = target_array[i];
for (let j = 0; j < target_array.length; j++) {
const end = target_array[j];
if (j == i) continue;
var path = this.findPath(begin, end, { ignoreCreeps: true, swampCost: 2 });
// Remove the begin and end tile.
path = path.slice(1, path.length - 1);
// Build road on every step.
path.forEach(step => {
const response = this.createConstructionSite(step.x, step.y, STRUCTURE_ROAD);
if (response == ERR_FULL) return;
});
}
}
this.memory.roadsPlanned = true;
}
planStructures() {
this.memory.roadsPlanned = false;
}
//#endregion
}