Constructions.prototype.updateQueue = function(queue, testedPos, existingConstructions, maxCount) { // we remove misplaced constructions // TODO remove finished construction too ? var validCount = 0; for(var i = 0; i < existingConstructions.length; ++i) { var cs = existingConstructions[i]; // if it's not a tested pos, it's invalid if(!(HelperFunctions.posToInt(cs.pos) in testedPos)) cs.remove(); else if(validCount >= maxCount) cs.remove(); else validCount++; } var res = []; for(var i = validCount; i < maxCount; ++i) { if(!queue.length) break; res.push(queue.pop()); } return res; }
Constructions.prototype.generateWalls = function(walls, testedPos, invalidPos, exit) { var room = this.roomHandler.room; var exits = room.find(exit); var rampartFound = false; for(var i = 0; i < exits.length; ++i) { var x = exits[i]; var possiblePos = getPossibleWallsPositions(x); for(var j = 0; j < possiblePos.length; ++j) { var pos = possiblePos[j]; var p = HelperFunctions.posToInt(pos); // aleady done or invalid if(testedPos[p] || invalidPos[p]) continue; // w/e happens, it's an invalid pos now testedPos[p] = true; if(isRampart(room, pos.x, pos.y)) { rampartFound = true; } else if(isValidWallConstruction(room, pos.x, pos.y)) { // TODO at worse we create more rempart than needed if(!rampartFound) { rampartFound = true; walls.push({x: pos.x, y: pos.y, rampart: true}); } else { walls.push({x: pos.x, y: pos.y}); } } } } };
Constructions.prototype.generateInvalidWallPos = function(invalidPos, exit) { var room = this.roomHandler.room; var exits = room.find(exit); for(var i = 0; i < exits.length; ++i) { var x = exits[i]; var badPos = tooCloseWallPositions(x); for(var j = 0; j < badPos.length; ++j) invalidPos[HelperFunctions.posToInt(badPos[j])] = true; } }
Constructions.prototype.updatePathUse = function() { var pathUse = this.memory.pathUse; // we only take into account energy creeps because they move a lot var creeps = this.roomHandler.cache.myCreepsEnergy(); for(var i = 0; i < creeps.length; ++i) { var creep = creeps[i]; var p = HelperFunctions.posToInt(creep.pos); // we dont want to count creeps that doesnt move var last = creep.memory.lastPos; creep.memory.lastPos = p; if(!last || last == p) continue; var old = pathUse[p]; pathUse[p] = old ? (old + 1) : 1; } }