Created
March 10, 2016 18:50
-
-
Save gdborton/562a75dd6e9936b3ada3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = | |
/******/ (function(modules) { // webpackBootstrap | |
/******/ // The module cache | |
/******/ var installedModules = {}; | |
/******/ // The require function | |
/******/ function __webpack_require__(moduleId) { | |
/******/ // Check if module is in cache | |
/******/ if(installedModules[moduleId]) | |
/******/ return installedModules[moduleId].exports; | |
/******/ // Create a new module (and put it into the cache) | |
/******/ var module = installedModules[moduleId] = { | |
/******/ exports: {}, | |
/******/ id: moduleId, | |
/******/ loaded: false | |
/******/ }; | |
/******/ // Execute the module function | |
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | |
/******/ // Flag the module as loaded | |
/******/ module.loaded = true; | |
/******/ // Return the exports of the module | |
/******/ return module.exports; | |
/******/ } | |
/******/ // expose the modules object (__webpack_modules__) | |
/******/ __webpack_require__.m = modules; | |
/******/ // expose the module cache | |
/******/ __webpack_require__.c = installedModules; | |
/******/ // __webpack_public_path__ | |
/******/ __webpack_require__.p = ""; | |
/******/ // Load entry module and return exports | |
/******/ return __webpack_require__(0); | |
/******/ }) | |
/************************************************************************/ | |
/******/ ([ | |
/* 0 */ | |
/***/ function(module, exports, __webpack_require__) { | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.loop = loop; | |
__webpack_require__(1); | |
var _game = __webpack_require__(2); | |
var _game2 = _interopRequireDefault(_game); | |
__webpack_require__(3); | |
__webpack_require__(8); | |
__webpack_require__(9); | |
__webpack_require__(10); | |
__webpack_require__(11); | |
__webpack_require__(12); | |
var _screepsProfiler = __webpack_require__(13); | |
var _screepsProfiler2 = _interopRequireDefault(_screepsProfiler); | |
var _screepGlobals = __webpack_require__(6); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
// Order here is important. These modify global prototypes. | |
_screepsProfiler2.default.enable(); | |
function loop() { | |
if (_screepGlobals.Room.prototype.work && Game.cpuLimit > 100) { | |
_screepsProfiler2.default.wrap(function () { | |
_game2.default.setup(); | |
Object.keys(Game.rooms).forEach(function (roomName, index) { | |
if (index === 1 || Game.cpuLimit > 50) { | |
Game.rooms[roomName].work(); | |
} | |
}); | |
}); | |
} | |
} | |
/***/ }, | |
/* 1 */ | |
/***/ function(module, exports) { | |
var originalFindPath = Room.prototype.findPath; | |
var setup = false; | |
function creepMemoryCleanUp() { | |
if (Game.time - Memory.screepsPerf.lastMemoryCleanUp > 100) { | |
Object.keys(Memory.creeps).forEach(creepName => { | |
if (!Game.creeps[creepName]) { | |
Memory.creeps[creepName] = undefined; | |
} | |
}); | |
Memory.screepsPerf.lastMemoryCleanUp = Game.time; | |
} | |
}; | |
module.exports = function(options) { | |
if (!setup) { | |
options = options || {}; | |
Memory.screepsPerf = Memory.screepsPerf || { | |
lastMemoryCleanUp: Game.time | |
}; | |
if (options.speedUpArrayFunctions || options.speedUpArrayFunctions === undefined) { | |
Array.prototype.filter = function(callback, thisArg) { | |
var results = []; | |
var arr = this; | |
for (var iterator = 0; iterator < arr.length; iterator++) { | |
if (callback.call(thisArg, arr[iterator], iterator, arr)) { | |
results.push(arr[iterator]); | |
} | |
} | |
return results; | |
}; | |
Array.prototype.forEach = function(callback, thisArg) { | |
var arr = this; | |
for (var iterator = 0; iterator < arr.length; iterator++) { | |
callback.call(thisArg, arr[iterator], iterator, arr); | |
} | |
}; | |
Array.prototype.map = function(callback, thisArg) { | |
var arr = this; | |
var returnVal = []; | |
for (var iterator = 0; iterator < arr.length; iterator++) { | |
returnVal.push(callback.call(thisArg, arr[iterator], iterator, arr)); | |
} | |
return returnVal; | |
}; | |
} | |
/** | |
* Creep memory clean up... this speeds up the initial memory parse each tick. | |
*/ | |
if (options.cleanUpCreepMemory || options.cleanUpCreepMemory === undefined) { | |
// Monkey patch creating creeps so that we can clean up their memory without forcing the user to make a call. | |
var originalCreateCreep = Spawn.prototype.createCreep; | |
Spawn.prototype.createCreep = function() { | |
creepMemoryCleanUp(); | |
return originalCreateCreep.apply(this, arguments); | |
}; | |
} | |
/** | |
* FIND PATH OPTIMIZATION | |
* This cache's the built in findPath results in memory and reuses them as long as that same path is used at least 1/300 ticks. | |
* The cached path is also refreshed every 2000 ticks. This helps to ensure that creeps respond to changing room terrain. | |
*/ | |
if (options.optimizePathFinding || options.optimizePathFinding === undefined) { | |
function roomPositionIdentifier(roomPosition) { | |
return roomPosition.roomName + 'x' + roomPosition.x + 'y' + roomPosition.y; | |
}; | |
Room.prototype.findPath = function(fromPos, toPos, options) { | |
creepMemoryCleanUp(); | |
if (!Memory.pathOptimizer) { | |
Memory.pathOptimizer = { lastCleaned: Game.time}; | |
} | |
if (Game.time - Memory.pathOptimizer.lastCleaned > 40 && !this._cleanedUp) { | |
var keys = Object.keys(Memory.pathOptimizer); | |
keys.forEach((key) => { | |
var val = Memory.pathOptimizer[key]; | |
if (val && ((val.used / (Game.time - val.tick) < 1 / 300) || Game.time - val.tick > 2000)) { | |
Memory.pathOptimizer[key] = undefined; | |
} | |
}); | |
this._cleanedUp = true; | |
Memory.pathOptimizer.lastCleaned = Game.time; | |
} | |
var pathIdentifier = roomPositionIdentifier(fromPos) + roomPositionIdentifier(toPos); | |
if (!Memory.pathOptimizer[pathIdentifier]) { | |
var path = originalFindPath.apply(this, arguments); | |
Memory.pathOptimizer[pathIdentifier] = { | |
tick: Game.time, | |
path: Room.serializePath(path), | |
used: 1 | |
} | |
} else { | |
Memory.pathOptimizer[pathIdentifier].used++; | |
} | |
return Room.deserializePath(Memory.pathOptimizer[pathIdentifier].path); | |
} | |
} | |
setup = true; | |
} | |
return { | |
originalFindPath: originalFindPath | |
} | |
}; | |
/***/ }, | |
/* 2 */ | |
/***/ function(module, exports) { | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
function getFlagsOfType(type) { | |
return Game.flagArray().filter(function (flag) { | |
return flag.name.toLowerCase().indexOf(type) !== -1; | |
}); | |
} | |
var scoutFlags = undefined; | |
var enhancedGame = { | |
flagArray: function flagArray() { | |
return Object.keys(Game.flags).map(function (flagName) { | |
return Game.flags[flagName]; | |
}); | |
}, | |
clearScoutFlags: function clearScoutFlags() { | |
Game.getScoutFlags().forEach(function (flag) { | |
flag.remove(); | |
}); | |
}, | |
getScoutFlags: function getScoutFlags() { | |
if (scoutFlags === undefined) { | |
scoutFlags = getFlagsOfType('scout'); | |
} | |
return scoutFlags; | |
}, | |
dismantleFlags: function dismantleFlags() { | |
return getFlagsOfType('dismantle'); | |
}, | |
claimFlags: function claimFlags() { | |
return getFlagsOfType('claim'); | |
} | |
}; | |
exports.default = { | |
setup: function setup() { | |
scoutFlags = undefined; | |
Object.assign(Game, enhancedGame); | |
} | |
}; | |
/***/ }, | |
/* 3 */ | |
/***/ function(module, exports, __webpack_require__) { | |
'use strict'; | |
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | |
__webpack_require__(4); | |
var _bodyCosts = __webpack_require__(7); | |
var _bodyCosts2 = _interopRequireDefault(_bodyCosts); | |
var _screepGlobals = __webpack_require__(6); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
var originalMoveTo = _screepGlobals.Creep.prototype.moveTo; | |
var roles = { | |
harvester: function harvester() { | |
if (this.carry.energy < this.carryCapacity || this.carry.energy === 0) { | |
var source = this.targetSource(); | |
this.moveToAndHarvest(source); | |
} else if (this.room.courierCount() === 0 && this.getSpawn().availableEnergy() < 300) { | |
this.deliverEnergyTo(this.getSpawn()); | |
} else { | |
var storage = this.room.getStorage(); | |
var links = this.room.getLinks(); | |
var closestLink = this.pos.findClosestByRange(links); | |
var rangeToStore = storage ? this.pos.getRangeTo(storage) : 100; | |
if (storage && storage.store.energy < storage.storeCapacity * 0.3 && rangeToStore === 1) { | |
this.deliverEnergyTo(storage); | |
} else if (links.length && this.pos.getRangeTo(closestLink) === 1 && !closestLink.isFull()) { | |
this.deliverEnergyTo(closestLink); | |
} else if (storage && storage.store.energy < storage.storeCapacity && rangeToStore === 1) { | |
this.deliverEnergyTo(storage); | |
} else { | |
this.dropEnergy(); | |
} | |
} | |
}, | |
scoutharvester: function scoutharvester() { | |
if (this.findUnvisitedScoutFlags().length > 0) { | |
this.scout(); | |
} else { | |
var sourcesNeedingHarvesters = this.room.getSourcesNeedingHarvesters(); | |
if (sourcesNeedingHarvesters.length > 0) { | |
this.memory.role = 'harvester'; | |
this.memory.oldRole = 'scoutharvester'; | |
this.memory.source = sourcesNeedingHarvesters[0].id; | |
} | |
} | |
}, | |
courier: function courier() { | |
var potentialTargets = this.room.getMyStructures().filter(function (structure) { | |
var notALink = structure.structureType !== STRUCTURE_LINK; | |
return structure.energyCapacity && structure.energy < structure.energyCapacity && notALink; | |
}); | |
var dumpTarget = this.pos.findClosestByRange(potentialTargets); | |
if (this.carry.energy === this.carryCapacity) { | |
this.memory.task = 'deliver'; | |
} else if (!dumpTarget || this.carry.energy === 0) { | |
this.memory.task = 'pickup'; | |
} | |
if (!dumpTarget) { | |
dumpTarget = this.room.getControllerEnergyDropFlag(); | |
} | |
if (this.memory.task === 'pickup') { | |
if (!this.memory.target) { | |
var target = this.room.getEnergySourcesThatNeedsStocked()[0]; | |
this.memory.target = target ? target.id : ''; | |
} | |
if (this.memory.target) { | |
var target = Game.getObjectById(this.memory.target); | |
var result = undefined; | |
if (target) { | |
result = this.takeEnergyFrom(target); | |
} | |
if (!target || result === 0) { | |
this.memory.target = ''; | |
} | |
} else { | |
this.deliverEnergyTo(dumpTarget); | |
} | |
} else { | |
this.deliverEnergyTo(dumpTarget); | |
} | |
}, | |
builder: function builder() { | |
if (this.carry.energy === this.carryCapacity) { | |
this.memory.task = 'work'; | |
} else if (this.carry.energy === 0 || this.memory.task === 'stockup') { | |
this.memory.target = null; | |
this.memory.task = 'stockup'; | |
if (this.room.droppedControllerEnergy()) { | |
this.takeEnergyFrom(this.room.droppedControllerEnergy()); | |
} else if (this.room.getControllerLink() && !this.room.getControllerLink().isEmpty()) { | |
this.takeEnergyFrom(this.room.getControllerLink()); | |
} else if (this.room.getStorage() && !this.room.getStorage().isEmpty()) { | |
this.takeEnergyFrom(this.room.getStorage()); | |
} | |
} | |
if (this.memory.task === 'work') { | |
var constructionSites = this.room.getConstructionSites(); | |
if (constructionSites.length) { | |
var closestConstructionSite = this.pos.findClosestByRange(constructionSites); | |
this.moveToAndBuild(closestConstructionSite); | |
} else if (this.memory.target) { | |
var target = Game.getObjectById(this.memory.target); | |
if (target.hits < target.hitsMax) { | |
this.moveToAndRepair(target); | |
} else { | |
this.memory.target = null; | |
} | |
} else { | |
var damagedStructures = this.room.getStructures().sort(function (structureA, structureB) { | |
return structureA.hits / structureA.hitsMax - structureB.hits / structureB.hitsMax; | |
}); | |
if (damagedStructures.length) { | |
this.memory.target = damagedStructures[0].id; | |
} | |
} | |
} | |
}, | |
upgrader: function upgrader() { | |
var empty = this.carry.energy === 0; | |
if (!empty) { | |
this.moveToAndUpgrade(this.room.controller); | |
} else if (empty && this.room.droppedControllerEnergy()) { | |
this.takeEnergyFrom(this.room.droppedControllerEnergy()); | |
} else if (empty && this.room.getLinks().length) { | |
var closestLink = this.pos.findClosestByRange(this.room.getLinks()); | |
if (this.pos.getRangeTo(closestLink) < 5) { | |
this.takeEnergyFrom(closestLink); | |
} else { | |
this.moveToAndUpgrade(this.room.controller); | |
} | |
} | |
}, | |
roadworker: function roadworker() { | |
if (this.carry.energy === 0) { | |
var closestEnergySource = this.pos.findClosestByRange(this.room.getEnergyStockSources()); | |
if (closestEnergySource) { | |
this.takeEnergyFrom(closestEnergySource); | |
} | |
} else { | |
var roads = this.room.getRoads().filter(function (road) { | |
return road.hits < road.hitsMax; | |
}); | |
if (roads.length) { | |
var road = this.pos.findClosestByRange(roads); | |
this.moveToAndRepair(road); | |
} else { | |
this.suicide(); | |
} | |
} | |
}, | |
mailman: function mailman() { | |
if (this.carry.energy === 0) { | |
this.memory.task = 'stock'; | |
} else if (this.carry.energy === this.carryCapacity) { | |
this.memory.task = 'deliver'; | |
} | |
if (this.memory.task === 'deliver') { | |
var target = this.pos.findClosestByRange(this.room.myCreeps().filter(function (creep) { | |
return creep.needsEnergyDelivered(); | |
})); | |
if (target) { | |
this.deliverEnergyTo(target); | |
} | |
} else { | |
var closestEnergySource = this.pos.findClosestByRange(this.room.getEnergyStockSources()); | |
if (closestEnergySource) { | |
this.takeEnergyFrom(closestEnergySource); | |
} | |
} | |
}, | |
claimer: function claimer() { | |
if (this.findUnvisitedScoutFlags().length > 0) { | |
this.scout(); | |
} else if (!this.room.getControllerOwned()) { | |
this.moveToAndClaimController(this.room.controller); | |
} | |
}, | |
scout: function scout() { | |
if (this.findUnvisitedScoutFlags().length > 0) { | |
if (this.room.getDismantleFlag()) { | |
this.dismantleFlag(this.room.getDismantleFlag()); | |
} else { | |
this.scout(); | |
} | |
} else if (this.room.getConstructionSites().length && this.carry.energy > 0) { | |
this.moveToAndBuild(this.pos.findClosestByRange(this.room.getConstructionSites())); | |
} else if (this.carry.energy === 0) { | |
var droppedEnergies = this.room.getDroppedEnergy(); | |
if (droppedEnergies.length > 0) { | |
this.takeEnergyFrom(droppedEnergies[0]); | |
} | |
} else { | |
this.moveToAndUpgrade(this.room.controller); | |
} | |
} | |
}; | |
Object.assign(_screepGlobals.Creep.prototype, { | |
work: function work() { | |
var creepFlag = Game.flags[this.name]; | |
// move to creep flag if it is defined. | |
if (creepFlag !== undefined) { | |
if (this.pos.getRangeTo(creepFlag) === 0) { | |
creepFlag.remove(); | |
} else { | |
this.moveTo(creepFlag); | |
} | |
} else if (this.memory.role && roles[this.memory.role]) { | |
roles[this.memory.role].call(this); | |
} | |
}, | |
targetSource: function targetSource() { | |
var _this = this; | |
return this.room.getSources().filter(function (source) { | |
return _this.memory.source === source.id; | |
})[0]; | |
}, | |
getSpawn: function getSpawn() { | |
var _this2 = this; | |
var validSpawns = Object.keys(Game.spawns).filter(function (spawnName) { | |
var spawn = Game.spawns[spawnName]; | |
return spawn.room === _this2.room; | |
}); | |
return validSpawns.length ? Game.spawns[validSpawns[0]] : Game.spawns[this.memory.spawn]; | |
}, | |
moveToAndClaimController: function moveToAndClaimController(controller) { | |
if (this.pos.getRangeTo(controller) > 1) { | |
this.moveTo(controller); | |
} else { | |
if (this.claimController(controller) === 0) { | |
var claimFlag = Game.claimFlags().filter(function (flag) { | |
return flag.pos.getRangeTo(controller) === 0; | |
})[0]; | |
if (claimFlag) { | |
claimFlag.remove(); | |
} | |
} | |
} | |
}, | |
moveToThenDrop: function moveToThenDrop(target) { | |
if (this.pos.getRangeTo(target) > 1) { | |
this.moveTo(target); | |
} else { | |
this.dropEnergy(); | |
} | |
}, | |
moveTo: function moveTo() { | |
for (var _len = arguments.length, myArgs = Array(_len), _key = 0; _key < _len; _key++) { | |
myArgs[_key] = arguments[_key]; | |
} | |
var args = [].map.call(myArgs, function (arg) { | |
return arg; | |
}); | |
var whitelist = ['upgrader', 'claimer', 'scout']; | |
var potentialOptions = undefined; | |
if (typeof myArgs[0] === 'number') { | |
potentialOptions = args[2]; | |
} else { | |
potentialOptions = args[1]; | |
} | |
if (!potentialOptions) { | |
potentialOptions = {}; | |
args.push(potentialOptions); | |
} | |
var whitelisted = whitelist.indexOf(this.memory.role) !== -1; | |
if (!whitelisted && this.room.controller && (typeof potentialOptions === 'undefined' ? 'undefined' : _typeof(potentialOptions)) === 'object') { | |
var coord = this.room.controller.pos; | |
var avoid = []; | |
for (var x = coord.x - 1; x <= coord.x + 1; x++) { | |
for (var y = coord.y - 1; y <= coord.y + 1; y++) { | |
avoid.push({ x: x, y: y }); | |
} | |
} | |
if (potentialOptions.avoid) { | |
potentialOptions.avoid = potentialOptions.avoid.concat(avoid); | |
} else { | |
potentialOptions.avoid = avoid; | |
} | |
} | |
if (!potentialOptions.reusePath) { | |
potentialOptions.reusePath = 20; | |
} | |
return originalMoveTo.apply(this, args); | |
}, | |
moveToAndHarvest: function moveToAndHarvest(target) { | |
if (this.pos.getRangeTo(target) > 1) { | |
this.moveTo(target); | |
} else { | |
this.harvest(target); | |
} | |
}, | |
moveToAndUpgrade: function moveToAndUpgrade(target) { | |
if (this.pos.getRangeTo(target) > 1) { | |
this.moveTo(this.room.controller); | |
} else { | |
this.upgradeController(this.room.controller); | |
} | |
}, | |
moveToAndBuild: function moveToAndBuild(target) { | |
var range = this.pos.getRangeTo(target); | |
if (range > 1) { | |
this.moveTo(target); | |
} | |
if (range <= 3) { | |
this.build(target); | |
} | |
}, | |
hasVisitedFlag: function hasVisitedFlag(flag) { | |
var visitedFlags = this.memory.visitedFlags || []; | |
return visitedFlags.indexOf(flag.name) !== -1; | |
}, | |
findUnvisitedScoutFlags: function findUnvisitedScoutFlags() { | |
var _this3 = this; | |
if (!this._unvisitedFlags) { | |
var flags = Game.getScoutFlags(); | |
this._unvisitedFlags = flags.filter(function (flag) { | |
return !_this3.hasVisitedFlag(flag); | |
}); | |
} | |
return this._unvisitedFlags; | |
}, | |
dismantleFlag: function dismantleFlag(flag) { | |
var structure = this.room.getStructureAt(flag.pos); | |
if (structure) { | |
this.moveToAndDismantle(structure); | |
} else { | |
flag.remove(); | |
} | |
}, | |
moveToAndDismantle: function moveToAndDismantle(target) { | |
if (this.pos.getRangeTo(target) === 1) { | |
this.dismantle(target); | |
} else { | |
this.moveTo(target); | |
} | |
}, | |
scout: function scout() { | |
var unvisitedFlags = this.findUnvisitedScoutFlags(); | |
unvisitedFlags.sort(function (flagA, flagB) { | |
return parseInt(flagA.name, 10) - parseInt(flagB.name, 10); | |
}); | |
var targetFlag = unvisitedFlags[0]; | |
if (this.pos.getRangeTo(targetFlag) === 0) { | |
if (!this.memory.visitedFlags) { | |
this.memory.visitedFlags = []; | |
} | |
this.memory.visitedFlags.push(targetFlag.name); | |
targetFlag = unvisitedFlags[1]; | |
} | |
this.moveTo(targetFlag, { reusePath: 50 }); | |
}, | |
moveToAndRepair: function moveToAndRepair(target) { | |
var range = this.pos.getRangeTo(target); | |
if (range > 1) { | |
this.moveTo(target); | |
} | |
if (range <= 3) { | |
this.repair(target); | |
} | |
}, | |
takeEnergyFrom: function takeEnergyFrom(target) { | |
var range = this.pos.getRangeTo(target); | |
if (target instanceof _screepGlobals.Energy) { | |
if (range > 1) { | |
this.moveTo(target); | |
} | |
return this.pickup(target); | |
} | |
if (range > 1) { | |
this.moveTo(target); | |
} | |
return target.transferEnergy(this); | |
}, | |
deliverEnergyTo: function deliverEnergyTo(target) { | |
var range = this.pos.getRangeTo(target); | |
if (target instanceof _screepGlobals.Flag) { | |
if (range === 0) { | |
this.dropEnergy(); | |
} else { | |
this.moveTo(target); | |
} | |
} else { | |
if (range <= 1) { | |
this.transferEnergy(target); | |
} else { | |
this.moveTo(target); | |
} | |
} | |
}, | |
needsOffloaded: function needsOffloaded() { | |
return this.carry.energy / this.carryCapacity > 0.6; | |
}, | |
needsEnergyDelivered: function needsEnergyDelivered() { | |
var blacklist = ['harvester', 'courier', 'mailman']; | |
if (blacklist.indexOf(this.memory.role) !== -1) { | |
return false; | |
} | |
return this.carry.energy / this.carryCapacity < 0.6; | |
}, | |
cost: function cost() { | |
return _bodyCosts2.default.calculateCosts(this.body); | |
} | |
}); | |
/***/ }, | |
/* 4 */ | |
/***/ function(module, exports, __webpack_require__) { | |
'use strict'; | |
var _settings = __webpack_require__(5); | |
var _settings2 = _interopRequireDefault(_settings); | |
var _screepGlobals = __webpack_require__(6); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
function getAllClaimers() { | |
return Object.keys(Game.creeps).filter(function (creepName) { | |
var creep = Game.creeps[creepName]; | |
return creep.memory.role === 'claimer'; | |
}); | |
} | |
function getAllScoutHarvesters() { | |
return Object.keys(Game.creeps).filter(function (creepName) { | |
var creep = Game.creeps[creepName]; | |
return creep.memory.role === 'scoutharvester' || creep.memory.oldRole === 'scoutharvester'; | |
}); | |
} | |
function getAllScouts() { | |
return Object.keys(Game.creeps).filter(function (creepName) { | |
var creep = Game.creeps[creepName]; | |
return creep.memory.role === 'scout'; | |
}); | |
} | |
Object.assign(_screepGlobals.Room.prototype, { | |
work: function work() { | |
this.getMyStructures().forEach(function (structure) { | |
structure.work(); | |
}); | |
this.myCreeps().forEach(function (creep) { | |
creep.work(); | |
}); | |
this.getFlags().forEach(function (flag) { | |
flag.work(); | |
}); | |
}, | |
hasHostileCreeps: function hasHostileCreeps() { | |
return this.getHostileCreeps().length > 0; | |
}, | |
getHostileCreeps: function getHostileCreeps() { | |
return this.find(FIND_HOSTILE_CREEPS); | |
}, | |
needsUpgraders: function needsUpgraders() { | |
var hasFreeEdges = this.upgraderCount() < this.controller.pos.freeEdges(); | |
return hasFreeEdges && !!this.droppedControllerEnergy() && this.upgraderWorkParts() < this.maxEnergyProducedPerTick(); | |
}, | |
needsBuilders: function needsBuilders() { | |
return this.builderCount() < 1 && (this.getConstructionSites().length > 0 || this.damagedBuildings().length > 0); | |
}, | |
damagedBuildings: function damagedBuildings() { | |
return this.getStructures().filter(function (structure) { | |
return structure.structureType !== STRUCTURE_ROAD && structure.needsRepaired(); | |
}); | |
}, | |
getStorage: function getStorage() { | |
if (!this._storageCalc) { | |
this._storageCalc = true; | |
this._storage = this.getMyStructures().filter(function (structure) { | |
return structure.structureType === STRUCTURE_STORAGE; | |
})[0]; | |
} | |
return this._storage; | |
}, | |
getLinks: function getLinks() { | |
if (!this._links) { | |
this._links = this.getMyStructures().filter(function (structure) { | |
return structure.structureType === STRUCTURE_LINK; | |
}); | |
} | |
return this._links; | |
}, | |
getControllerLink: function getControllerLink() { | |
return this.getLinks().filter(function (link) { | |
return link.isControllerLink(); | |
})[0]; | |
}, | |
upgraderWorkParts: function upgraderWorkParts() { | |
if (!this._upgraderWorkParts) { | |
var parts = this.getUpgraders(); | |
parts = parts.map(function (upgrader) { | |
return upgrader.body.filter(function (bodyPart) { | |
return bodyPart.type === WORK; | |
}).length; | |
}); | |
if (parts.length) { | |
this._upgraderWorkParts = parts.reduce(function (a, b) { | |
return a + b; | |
}); | |
} else { | |
this._upgraderWorkParts = 0; | |
} | |
} | |
return this._upgraderWorkParts; | |
}, | |
maxEnergyProducedPerTick: function maxEnergyProducedPerTick() { | |
return this.sourceCount() * 10; | |
}, | |
sourceCount: function sourceCount() { | |
return this.getSources().length; | |
}, | |
getStructures: function getStructures() { | |
if (!this._structures) { | |
this._structures = this.find(FIND_STRUCTURES); | |
} | |
return this._structures; | |
}, | |
getRoads: function getRoads() { | |
if (!this._roads) { | |
this._roads = this.getStructures().filter(function (structure) { | |
return structure.structureType === STRUCTURE_ROAD; | |
}); | |
} | |
return this._roads; | |
}, | |
getDamagedRoads: function getDamagedRoads() { | |
if (!this._damagedRoads) { | |
this._damagedRoads = this.getRoads().filter(function (road) { | |
return road.structureType === STRUCTURE_ROAD && road.hits / road.hitsMax < 0.5; | |
}); | |
} | |
return this._damagedRoads; | |
}, | |
hasDamagedRoads: function hasDamagedRoads() { | |
return this.getDamagedRoads().length > 0; | |
}, | |
needsRoadWorkers: function needsRoadWorkers() { | |
if (Game.time % 30 !== 0) { | |
return false; | |
} | |
return this.roadWorkerCount() < 1 && this.hasDamagedRoads(); | |
}, | |
needsCouriers: function needsCouriers() { | |
if (this.courierCount() === 1 && this.getCouriers()[0].ticksToLive < 70) { | |
return true; | |
} | |
var storage = this.getStorage(); | |
if (!storage) { | |
return this.courierCount() < 2; | |
} else if (storage.store.energy > 500000) { | |
return this.courierCount() < Math.floor(storage.store.energy / 200000); | |
} | |
return this.courierCount() < 1; | |
}, | |
getMyStructures: function getMyStructures() { | |
if (!this._myStructures) { | |
this._myStructures = this.find(FIND_MY_STRUCTURES); | |
} | |
return this._myStructures; | |
}, | |
getHarvesters: function getHarvesters() { | |
if (!this._harvesters) { | |
this._harvesters = this.myCreeps().filter(function (creep) { | |
return creep.memory.role === 'harvester'; | |
}); | |
} | |
return this._harvesters; | |
}, | |
getRoadWorkers: function getRoadWorkers() { | |
if (!this._roadWorkers) { | |
this._roadWorkers = this.myCreeps().filter(function (creep) { | |
return creep.memory.role === 'roadworker'; | |
}); | |
} | |
return this._roadWorkers; | |
}, | |
roadWorkerCount: function roadWorkerCount() { | |
return this.getRoadWorkers().length; | |
}, | |
harvesterCount: function harvesterCount() { | |
return this.getHarvesters().length; | |
}, | |
getMailmen: function getMailmen() { | |
if (!this._mailmen) { | |
this._mailmen = this.myCreeps().filter(function (creep) { | |
return creep.memory.role === 'mailman'; | |
}); | |
} | |
return this._mailmen; | |
}, | |
mailmanCount: function mailmanCount() { | |
return this.getMailmen().length; | |
}, | |
getExits: function getExits() { | |
if (!this._exits) { | |
this._exits = this.find(FIND_EXIT); | |
} | |
return this._exits; | |
}, | |
getUniqueExitPoints: function getUniqueExitPoints() { | |
var _this = this; | |
if (!this._uniqueExitPoints) { | |
(function () { | |
var exitCoords = _this.getExits(); | |
_this._uniqueExitPoints = exitCoords.filter(function (coord, index) { | |
if (index === 0) { | |
return true; | |
} | |
var prevCoord = exitCoords[index - 1]; | |
return !(Math.abs(coord.x - prevCoord.x) < 2) || !(Math.abs(coord.y - prevCoord.y) < 2); | |
}); | |
})(); | |
} | |
return this._uniqueExitPoints(); | |
}, | |
hasOutdatedCreeps: function hasOutdatedCreeps() { | |
return this.getOutdatedCreeps().length > 0; | |
}, | |
getOutdatedCreeps: function getOutdatedCreeps() { | |
var _this2 = this; | |
return this.myCreeps().filter(function (creep) { | |
return creep.cost() <= _this2.getSpawn().maxEnergy() - 100; | |
}); | |
}, | |
getFlags: function getFlags() { | |
var _this3 = this; | |
return this.find(FIND_FLAGS).filter(function (flag) { | |
return flag.room === _this3; | |
}); | |
}, | |
getControllerEnergyDropFlag: function getControllerEnergyDropFlag() { | |
return this.getFlags().filter(function (flag) { | |
return flag.name.indexOf('CONTROLLER_ENERGY_DROP') !== -1; | |
})[0]; | |
}, | |
workerCount: function workerCount() { | |
return this.harvesterCount() + this.builderCount() + this.mailmanCount(); | |
}, | |
courierCount: function courierCount() { | |
return this.getCouriers().length; | |
}, | |
getCouriers: function getCouriers() { | |
if (!this._couriers) { | |
this._couriers = this.myCreeps().filter(function (creep) { | |
return creep.memory.role === 'courier'; | |
}); | |
} | |
return this._couriers; | |
}, | |
myCreeps: function myCreeps() { | |
if (!this._myCreeps) { | |
this._myCreeps = this.find(FIND_MY_CREEPS); | |
} | |
return this._myCreeps; | |
}, | |
builderCount: function builderCount() { | |
return this.getBuilders().length; | |
}, | |
getBuilders: function getBuilders() { | |
if (!this._builders) { | |
this._builders = this.myCreeps().filter(function (creep) { | |
return creep.memory.role === 'builder'; | |
}); | |
} | |
return this._builders; | |
}, | |
upgraderCount: function upgraderCount() { | |
return this.getUpgraders().length; | |
}, | |
getUpgraders: function getUpgraders() { | |
if (!this._upgraders) { | |
this._upgraders = this.myCreeps().filter(function (creep) { | |
return creep.memory.role === 'upgrader'; | |
}); | |
} | |
return this._upgraders; | |
}, | |
getConstructionSites: function getConstructionSites() { | |
return this.find(FIND_CONSTRUCTION_SITES); | |
}, | |
getSources: function getSources() { | |
if (!this._sources) { | |
this._sources = this.find(FIND_SOURCES); | |
} | |
return this._sources; | |
}, | |
getSourcesNeedingHarvesters: function getSourcesNeedingHarvesters() { | |
return this.getSources().filter(function (source) { | |
return source.needsHarvesters(); | |
}); | |
}, | |
needsHarvesters: function needsHarvesters() { | |
return this.getSourcesNeedingHarvesters().length > 0; | |
}, | |
getEnergySourceStructures: function getEnergySourceStructures() { | |
return this.getMyStructures().filter(function (structure) { | |
return structure.energy; | |
}); | |
}, | |
droppedControllerEnergy: function droppedControllerEnergy() { | |
var _this4 = this; | |
if (!this._droppedControllerEnergy) { | |
(function () { | |
var dumpFlag = _this4.getControllerEnergyDropFlag(); | |
_this4._droppedControllerEnergy = _this4.find(FIND_DROPPED_ENERGY).filter(function (energy) { | |
return energy.pos.getRangeTo(dumpFlag) === 0; | |
})[0]; | |
})(); | |
} | |
return this._droppedControllerEnergy; | |
}, | |
getEnergyStockSources: function getEnergyStockSources() { | |
if (!this._energyStockSources) { | |
var droppedControllerEnergy = this.droppedControllerEnergy(); | |
this._energyStockSources = this.getEnergySourceStructures(); | |
if (droppedControllerEnergy) { | |
this._energyStockSources.unshift(droppedControllerEnergy); | |
} | |
} | |
return this._energyStockSources; | |
}, | |
getSpawn: function getSpawn() { | |
var spawns = this.find(FIND_MY_SPAWNS); | |
if (spawns.length) { | |
return spawns[0]; | |
} | |
return spawns; | |
}, | |
canBuildExtension: function canBuildExtension() { | |
if (this._canBuildExtensions === undefined) { | |
var maxExtensions = _settings2.default.buildingCount[this.controller.level].extensions || 0; | |
this._canBuildExtensions = this.getExtensions().length < maxExtensions; | |
} | |
return this._canBuildExtensions; | |
}, | |
getExtensions: function getExtensions() { | |
if (!this._extensions) { | |
this._extensions = this.getMyStructures().filter(function (structure) { | |
return structure.structureType === STRUCTURE_EXTENSION; | |
}); | |
} | |
return this._extensions; | |
}, | |
courierTargets: function courierTargets() { | |
return this.getCouriers().filter(function (creep) { | |
return creep.memory.role === 'courier' && !!creep.memory.target; | |
}).map(function (courier) { | |
return courier.memory.target; | |
}); | |
}, | |
getCreepsThatNeedOffloading: function getCreepsThatNeedOffloading() { | |
var targets = this.courierTargets(); | |
return this.getHarvesters().filter(function (harvester) { | |
var targeted = targets.indexOf(harvester.id) !== -1; | |
return harvester.needsOffloaded() && !targeted; | |
}); | |
}, | |
getDroppedEnergy: function getDroppedEnergy() { | |
return this.find(FIND_DROPPED_ENERGY).sort(function (energyA, energyB) { | |
return energyB.energy - energyA.energy; | |
}); | |
}, | |
getEnergyThatNeedsPickedUp: function getEnergyThatNeedsPickedUp() { | |
var targets = this.courierTargets(); | |
var dumpFlag = this.getControllerEnergyDropFlag(); | |
return this.getDroppedEnergy().filter(function (energy) { | |
var targeted = targets.indexOf(energy.id) !== -1; | |
return !targeted && energy.pos.getRangeTo(dumpFlag) !== 0; | |
}); | |
}, | |
getControllerOwned: function getControllerOwned() { | |
return this.controller.my; | |
}, | |
getDismantleFlag: function getDismantleFlag() { | |
var _this5 = this; | |
return Game.dismantleFlags().filter(function (flag) { | |
return flag.room === _this5; | |
})[0]; | |
}, | |
getStructureAt: function getStructureAt(roomPosition) { | |
return this.getStructures().filter(function (structure) { | |
return structure.pos.getRangeTo(roomPosition) === 0; | |
})[0]; | |
}, | |
hasScoutFlag: function hasScoutFlag() { | |
var _this6 = this; | |
return Game.getScoutFlags().filter(function (flag) { | |
return flag.room === _this6; | |
}).length > 0; | |
}, | |
needsScouts: function needsScouts() { | |
var desiredValue = 2; | |
if (Game.dismantleFlags().length > 0) { | |
desiredValue = 4; | |
} | |
return this.hasScoutFlag() && getAllScouts().length < desiredValue; | |
}, | |
needsClaimers: function needsClaimers() { | |
return this.hasScoutFlag() && Game.claimFlags().length > 0 && getAllClaimers().length < 1; | |
}, | |
needsScoutHarvesters: function needsScoutHarvesters() { | |
var desiredValue = 2; | |
if (Game.dismantleFlags().length > 0) { | |
desiredValue = 0; | |
} | |
return this.hasScoutFlag() && getAllScoutHarvesters().length < desiredValue; | |
}, | |
getEnergySourcesThatNeedsStocked: function getEnergySourcesThatNeedsStocked() { | |
if (this.getEnergyThatNeedsPickedUp().length) { | |
return this.getEnergyThatNeedsPickedUp(); | |
} else if (this.getCreepsThatNeedOffloading().length) { | |
return this.getCreepsThatNeedOffloading(); | |
} else if (this.getStorage() && !this.getStorage().isEmpty()) { | |
return [this.getStorage()]; | |
} | |
return []; | |
} | |
}); | |
/***/ }, | |
/* 5 */ | |
/***/ function(module, exports) { | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = { | |
courierToWorkerRatio: 0.5, | |
// count of structures that can be built at each controller level. | |
buildingCount: { | |
1: { | |
spawns: 1 | |
}, | |
2: { | |
spawns: 1, | |
extensions: 5, | |
ramparts: true, | |
walls: true | |
}, | |
3: { | |
spawns: 1, | |
extensions: 10, | |
ramparts: true, | |
walls: true, | |
roads: true | |
}, | |
4: { | |
spawns: 1, | |
extensions: 20, | |
ramparts: true, | |
walls: true, | |
roads: true, | |
storage: 1 | |
}, | |
5: { | |
spawns: 1, | |
extensions: 30, | |
ramparts: true, | |
walls: true, | |
roads: true, | |
storage: 1 | |
}, | |
6: { | |
spawns: 1, | |
extensions: 40, | |
ramparts: true, | |
walls: true, | |
roads: true, | |
storage: 1 | |
}, | |
7: { | |
spawns: 1, | |
extensions: 50, | |
ramparts: true, | |
walls: true, | |
roads: true, | |
storage: 1 | |
}, | |
8: { | |
spawns: 1, | |
extensions: 60, | |
ramparts: true, | |
walls: true, | |
roads: true, | |
storage: 1 | |
} | |
} | |
}; | |
/***/ }, | |
/* 6 */ | |
/***/ function(module, exports) { | |
"use strict"; | |
module.exports = | |
/******/function (modules) { | |
// webpackBootstrap | |
/******/ // The module cache | |
/******/var installedModules = {}; | |
/******/ // The require function | |
/******/function __webpack_require__(moduleId) { | |
/******/ // Check if module is in cache | |
/******/if (installedModules[moduleId]) | |
/******/return installedModules[moduleId].exports; | |
/******/ // Create a new module (and put it into the cache) | |
/******/var module = installedModules[moduleId] = { | |
/******/exports: {}, | |
/******/id: moduleId, | |
/******/loaded: false | |
/******/ }; | |
/******/ // Execute the module function | |
/******/modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | |
/******/ // Flag the module as loaded | |
/******/module.loaded = true; | |
/******/ // Return the exports of the module | |
/******/return module.exports; | |
/******/ | |
} | |
/******/ // expose the modules object (__webpack_modules__) | |
/******/__webpack_require__.m = modules; | |
/******/ // expose the module cache | |
/******/__webpack_require__.c = installedModules; | |
/******/ // __webpack_public_path__ | |
/******/__webpack_require__.p = ""; | |
/******/ // Load entry module and return exports | |
/******/return __webpack_require__(0); | |
/******/ | |
}( | |
/************************************************************************/ | |
/******/[ | |
/* 0 */ | |
/***/function (module, exports, __webpack_require__) { | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.Structure = exports.Spawn = exports.Source = exports.RoomPosition = exports.Room = exports.Resource = exports.RawMemory = exports.PathFinder = exports.Memory = exports.Map = exports.Game = exports.Flag = exports.Energy = exports.Creep = exports.ConstructionSite = undefined; | |
var _constructionSite = __webpack_require__(1); | |
var _constructionSite2 = _interopRequireDefault(_constructionSite); | |
var _creep = __webpack_require__(2); | |
var _creep2 = _interopRequireDefault(_creep); | |
var _energy = __webpack_require__(3); | |
var _energy2 = _interopRequireDefault(_energy); | |
var _flag = __webpack_require__(4); | |
var _flag2 = _interopRequireDefault(_flag); | |
var _game = __webpack_require__(5); | |
var _game2 = _interopRequireDefault(_game); | |
var _map = __webpack_require__(6); | |
var _map2 = _interopRequireDefault(_map); | |
var _memory = __webpack_require__(7); | |
var _memory2 = _interopRequireDefault(_memory); | |
var _pathFinder = __webpack_require__(8); | |
var _pathFinder2 = _interopRequireDefault(_pathFinder); | |
var _rawMemory = __webpack_require__(9); | |
var _rawMemory2 = _interopRequireDefault(_rawMemory); | |
var _resource = __webpack_require__(10); | |
var _resource2 = _interopRequireDefault(_resource); | |
var _roomPosition = __webpack_require__(11); | |
var _roomPosition2 = _interopRequireDefault(_roomPosition); | |
var _source = __webpack_require__(12); | |
var _source2 = _interopRequireDefault(_source); | |
var _spawn = __webpack_require__(13); | |
var _spawn2 = _interopRequireDefault(_spawn); | |
var _structure = __webpack_require__(14); | |
var _structure2 = _interopRequireDefault(_structure); | |
function _interopRequireDefault(obj) { | |
return obj && obj.__esModule ? obj : { default: obj }; | |
} | |
exports.ConstructionSite = _constructionSite2.default; | |
exports.Creep = _creep2.default; | |
exports.Energy = _energy2.default; | |
exports.Flag = _flag2.default; | |
exports.Game = _game2.default; | |
exports.Map = _map2.default; | |
exports.Memory = _memory2.default; | |
exports.PathFinder = _pathFinder2.default; | |
exports.RawMemory = _rawMemory2.default; | |
exports.Resource = _resource2.default; | |
exports.Room = Room; | |
exports.RoomPosition = _roomPosition2.default; | |
exports.Source = _source2.default; | |
exports.Spawn = _spawn2.default; | |
exports.Structure = _structure2.default; | |
/***/ | |
}, | |
/* 1 */ | |
/***/function (module, exports) { | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = ConstructionSite; | |
/***/ | |
}, | |
/* 2 */ | |
/***/function (module, exports) { | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = Creep; | |
/***/ | |
}, | |
/* 3 */ | |
/***/function (module, exports) { | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = Energy; | |
/***/ | |
}, | |
/* 4 */ | |
/***/function (module, exports) { | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = Flag; | |
/***/ | |
}, | |
/* 5 */ | |
/***/function (module, exports) { | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = Game; | |
/***/ | |
}, | |
/* 6 */ | |
/***/function (module, exports) { | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = Map; | |
/***/ | |
}, | |
/* 7 */ | |
/***/function (module, exports) { | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = Memory; | |
/***/ | |
}, | |
/* 8 */ | |
/***/function (module, exports) { | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = PathFinder; | |
/***/ | |
}, | |
/* 9 */ | |
/***/function (module, exports) { | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = RawMemory; | |
/***/ | |
}, | |
/* 10 */ | |
/***/function (module, exports) { | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = Resource; | |
/***/ | |
}, | |
/* 11 */ | |
/***/function (module, exports) { | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = RoomPosition; | |
/***/ | |
}, | |
/* 12 */ | |
/***/function (module, exports) { | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = Source; | |
/***/ | |
}, | |
/* 13 */ | |
/***/function (module, exports) { | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = Spawn; | |
/***/ | |
}, | |
/* 14 */ | |
/***/function (module, exports) { | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = Structure; | |
/***/ | |
} | |
/******/]); | |
/***/ }, | |
/* 7 */ | |
/***/ function(module, exports) { | |
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = { | |
calculateCosts: function calculateCosts(bodyParts) { | |
var cost = 0; | |
bodyParts.forEach(function (bodyPart) { | |
var part = typeof bodyPart === 'string' ? bodyPart : bodyPart.type; | |
cost += BODYPART_COST[part]; | |
}); | |
return cost; | |
} | |
}; | |
/***/ }, | |
/* 8 */ | |
/***/ function(module, exports, __webpack_require__) { | |
'use strict'; | |
var _screepGlobals = __webpack_require__(6); | |
Object.assign(_screepGlobals.Source.prototype, { | |
// Finds and returns the number of open spots next to the source. | |
freeEdges: function freeEdges() { | |
return this.pos.freeEdges(); | |
}, | |
needsHarvesters: function needsHarvesters() { | |
var _this = this; | |
var harvesters = this.room.getHarvesters(); | |
var myHarvesters = 0; | |
var workParts = 0; | |
harvesters.forEach(function (harvester) { | |
if (harvester.memory.source === _this.id) { | |
myHarvesters++; | |
workParts = workParts + harvester.body.filter(function (bodyPart) { | |
return bodyPart.type === 'work'; | |
}).length; | |
} | |
}); | |
return workParts < 5 && myHarvesters < this.freeEdges(); | |
} | |
}); | |
/***/ }, | |
/* 9 */ | |
/***/ function(module, exports, __webpack_require__) { | |
'use strict'; | |
__webpack_require__(8); | |
__webpack_require__(4); | |
var _bodyCosts = __webpack_require__(7); | |
var _bodyCosts2 = _interopRequireDefault(_bodyCosts); | |
var _screepGlobals = __webpack_require__(6); | |
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | |
Object.assign(_screepGlobals.Spawn.prototype, { | |
buildHarvester: function buildHarvester(availableEnergy) { | |
var sources = this.room.getSourcesNeedingHarvesters(); | |
var closestSource = this.pos.findClosestByRange(sources); | |
if (closestSource) { | |
var sourceId = closestSource.id; | |
var body = [MOVE, WORK, WORK, CARRY]; | |
var cost = _bodyCosts2.default.calculateCosts(body); | |
var forcedReturn = false; | |
while (cost <= availableEnergy && !forcedReturn) { | |
if (body.filter(function (part) { | |
return part === WORK; | |
}).length < 5) { | |
body.push(WORK); | |
} else if (body.filter(function (part) { | |
return part === CARRY; | |
}).length < 10) { | |
body.push(CARRY); | |
} else { | |
body.push(WORK); | |
forcedReturn = true; | |
} | |
cost = _bodyCosts2.default.calculateCosts(body); | |
} | |
while (cost > availableEnergy) { | |
body.pop(); | |
cost = _bodyCosts2.default.calculateCosts(body); | |
} | |
this.createCreep(body, undefined, { role: 'harvester', source: sourceId }); | |
} | |
}, | |
buildScout: function buildScout(availableEnergy) { | |
var body = [MOVE, MOVE, MOVE, MOVE, MOVE, WORK, WORK, WORK, WORK, WORK]; | |
var cost = _bodyCosts2.default.calculateCosts(body); | |
while (cost < availableEnergy && body.length < 50) { | |
body.push(MOVE); | |
body.push(Game.dismantleFlags().length ? WORK : CARRY); | |
cost = _bodyCosts2.default.calculateCosts(body); | |
} | |
while (cost > availableEnergy) { | |
body.pop(); | |
body.pop(); | |
cost = _bodyCosts2.default.calculateCosts(body); | |
} | |
this.createCreep(body, undefined, { role: 'scout', spawn: this.name }); | |
}, | |
buildScoutHarvester: function buildScoutHarvester() { | |
var body = [MOVE, MOVE, MOVE, MOVE, MOVE, WORK, WORK, WORK, WORK, WORK]; | |
this.createCreep(body, undefined, { role: 'scoutharvester' }); | |
}, | |
buildMailman: function buildMailman(availableEnergy) { | |
var body = [MOVE, MOVE, MOVE, CARRY, CARRY, CARRY]; | |
var cost = _bodyCosts2.default.calculateCosts(body); | |
while (cost < availableEnergy) { | |
body.push(MOVE); | |
body.push(CARRY); | |
cost = _bodyCosts2.default.calculateCosts(body); | |
} | |
while (cost > availableEnergy) { | |
body.pop(); | |
cost = _bodyCosts2.default.calculateCosts(body); | |
} | |
this.createCreep(body, undefined, { role: 'mailman' }); | |
}, | |
buildCourier: function buildCourier(availableEnergy) { | |
var body = [MOVE, MOVE, MOVE, CARRY, CARRY, CARRY]; | |
var cost = _bodyCosts2.default.calculateCosts(body); | |
var maxCarryParts = this.room.getStorage() && this.room.getLinks().length > 1 ? 10 : 100; | |
var carryParts = 3; | |
while (cost < availableEnergy && carryParts < maxCarryParts) { | |
body.push(MOVE); | |
body.push(CARRY); | |
carryParts++; | |
cost = _bodyCosts2.default.calculateCosts(body); | |
} | |
while (cost > availableEnergy) { | |
body.pop(); | |
cost = _bodyCosts2.default.calculateCosts(body); | |
} | |
this.createCreep(body, undefined, { role: 'courier' }); | |
}, | |
buildRoadWorker: function buildRoadWorker() { | |
var body = [MOVE, WORK, WORK, CARRY]; | |
this.createCreep(body, undefined, { role: 'roadworker' }); | |
}, | |
buildBuilder: function buildBuilder(availableEnergy) { | |
var body = [MOVE, MOVE, WORK, CARRY]; | |
var cost = _bodyCosts2.default.calculateCosts(body); | |
while (cost < availableEnergy) { | |
body.push(MOVE); | |
body.push(CARRY); | |
body.push(WORK); | |
cost = _bodyCosts2.default.calculateCosts(body); | |
} | |
while (cost > availableEnergy || body.length > 50) { | |
body.pop(); | |
cost = _bodyCosts2.default.calculateCosts(body); | |
} | |
this.createCreep(body, undefined, { role: 'builder' }); | |
}, | |
buildClaimer: function buildClaimer() { | |
var body = [MOVE, CLAIM]; | |
this.createCreep(body, undefined, { role: 'claimer' }); | |
}, | |
buildSourceTaker: function buildSourceTaker(availableEnergy) { | |
var body = []; | |
var cost = _bodyCosts2.default.calculateCosts(body); | |
var toughParts = 0; | |
while (toughParts < 10) { | |
toughParts++; | |
body.push(TOUGH, MOVE); | |
} | |
var rangedAttackParts = 0; | |
while (cost < availableEnergy) { | |
rangedAttackParts++; | |
body.push(RANGED_ATTACK, MOVE); | |
cost = _bodyCosts2.default.calculateCosts(body); | |
} | |
body.push(HEAL); | |
while (cost > availableEnergy || body.length > 50) { | |
body.pop(); | |
cost = _bodyCosts2.default.calculateCosts(body); | |
} | |
this.createCreep(body, undefined, { role: 'sourcetaker' }); | |
}, | |
buildUpgrader: function buildUpgrader(availableEnergy) { | |
var body = [MOVE, WORK, WORK, CARRY]; | |
var workParts = 2; | |
var cost = _bodyCosts2.default.calculateCosts(body); | |
var workPartsNeeded = this.room.maxEnergyProducedPerTick() - this.room.upgraderWorkParts(); | |
if (this.room.controller.level === 8) { | |
workPartsNeeded = Math.min(15, workPartsNeeded); | |
} | |
if (this.room.controller.pos.freeEdges() > 1) { | |
workPartsNeeded = Math.min(workPartsNeeded, this.room.maxEnergyProducedPerTick() / 2); | |
} | |
while (cost < availableEnergy && workParts < workPartsNeeded) { | |
body.push(WORK); | |
workParts++; | |
cost = _bodyCosts2.default.calculateCosts(body); | |
} | |
while (cost > availableEnergy) { | |
body.pop(); | |
cost = _bodyCosts2.default.calculateCosts(body); | |
} | |
this.createCreep(body, undefined, { role: 'upgrader' }); | |
}, | |
work: function work() { | |
if (this.spawning) { | |
return; | |
} | |
var harvesterCount = this.room.harvesterCount(); | |
var availableEnergy = this.availableEnergy(); | |
if (availableEnergy >= 300 && availableEnergy < this.maxEnergy()) { | |
if (harvesterCount < 1) { | |
this.buildHarvester(availableEnergy); | |
} else if (this.room.needsCouriers()) { | |
this.buildCourier(availableEnergy); | |
} else if (this.room.needsRoadWorkers()) { | |
this.buildRoadWorker(availableEnergy); | |
} | |
} else if (availableEnergy === this.maxEnergy()) { | |
if (this.room.needsHarvesters()) { | |
this.buildHarvester(availableEnergy); | |
} else if (this.room.needsCouriers()) { | |
this.buildCourier(availableEnergy); | |
} else if (this.room.needsUpgraders()) { | |
this.buildUpgrader(availableEnergy); | |
} else if (this.room.mailmanCount() < 2 && this.maxEnergy() < 600) { | |
this.buildMailman(availableEnergy); | |
} else if (this.room.needsBuilders()) { | |
this.buildBuilder(availableEnergy); | |
} else if (this.room.needsScouts()) { | |
this.buildScout(availableEnergy); | |
} else if (this.room.needsScoutHarvesters()) { | |
this.buildScoutHarvester(availableEnergy); | |
} else if (this.room.needsClaimers()) { | |
this.buildClaimer(availableEnergy); | |
} else { | |
this.extend(); | |
} | |
} else { | |
this.extend(); | |
} | |
}, | |
maxEnergy: function maxEnergy() { | |
return this.room.energyCapacityAvailable; | |
}, | |
needsRepaired: function needsRepaired() { | |
return this.hits < this.hitsMax; | |
}, | |
availableEnergy: function availableEnergy() { | |
return this.room.energyAvailable; | |
}, | |
extend: function extend() { | |
if (this.room.canBuildExtension()) { | |
this.room.createConstructionSite(this.pos.x - 1, this.pos.y - 1, STRUCTURE_EXTENSION); | |
} | |
} | |
}); | |
/***/ }, | |
/* 10 */ | |
/***/ function(module, exports, __webpack_require__) { | |
'use strict'; | |
var _structureTypes; | |
var _screepGlobals = __webpack_require__(6); | |
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | |
var TEN_MILLION = 10000000; | |
var structureTypes = (_structureTypes = {}, _defineProperty(_structureTypes, STRUCTURE_EXTENSION, function () { | |
if (Game.time % 10 === 0) { | |
if (this.room.canBuildExtension()) { | |
this.room.createConstructionSite(this.pos.x - 1, this.pos.y - 1, STRUCTURE_EXTENSION); | |
} | |
if (this.room.canBuildExtension()) { | |
this.room.createConstructionSite(this.pos.x - 1, this.pos.y + 1, STRUCTURE_EXTENSION); | |
} | |
} | |
}), _defineProperty(_structureTypes, STRUCTURE_LINK, function () { | |
var shouldTransfer = !this.isControllerLink() && !this.cooldown; | |
var controllerLink = this.room.getControllerLink(); | |
var controllerLinkNeedsEnergy = controllerLink && controllerLink.energy < 100; | |
if (shouldTransfer && controllerLinkNeedsEnergy) { | |
this.transferEnergy(this.room.getControllerLink()); | |
} | |
}), _defineProperty(_structureTypes, STRUCTURE_TOWER, function () { | |
if (this.room.hasHostileCreeps() && !this.isEmpty()) { | |
this.attack(this.pos.findClosestByRange(this.room.getHostileCreeps())); | |
} | |
}), _structureTypes); | |
Object.assign(_screepGlobals.Structure.prototype, { | |
work: function work() { | |
if (structureTypes[this.structureType]) { | |
structureTypes[this.structureType].call(this); | |
} | |
}, | |
isControllerLink: function isControllerLink() { | |
return this.structureType === STRUCTURE_LINK && this.pos.getRangeTo(this.room.controller) < 5; | |
}, | |
isFull: function isFull() { | |
if (this.energyCapacity) { | |
return this.energy === this.energyCapacity; | |
} else if (this.storeCapacity) { | |
return this.store === this.storeCapacity; | |
} | |
return true; | |
}, | |
needsRepaired: function needsRepaired() { | |
return this.hits / this.hitsMax < 0.9 && this.hits < TEN_MILLION; | |
}, | |
isEmpty: function isEmpty() { | |
if (this.energyCapacity) { | |
return this.energy === 0; | |
} else if (this.storeCapacity) { | |
return this.store === 0; | |
} | |
return true; | |
} | |
}); | |
/***/ }, | |
/* 11 */ | |
/***/ function(module, exports, __webpack_require__) { | |
'use strict'; | |
var _screepGlobals = __webpack_require__(6); | |
Object.assign(_screepGlobals.RoomPosition.prototype, { | |
identifier: function identifier() { | |
return this.roomName + 'x' + this.x + 'y' + this.y; | |
}, | |
freeEdges: function freeEdges() { | |
var _this = this; | |
if (!(Memory.freeEdges && Memory.freeEdges[this.identifier()])) { | |
(function () { | |
var openSpots = 0; | |
var room = Game.rooms[_this.roomName]; | |
var surroundings = room.lookAtArea(_this.y - 1, _this.x - 1, _this.y + 1, _this.x + 1); | |
Object.keys(surroundings).forEach(function (x) { | |
Object.keys(surroundings[x]).forEach(function (y) { | |
openSpots = openSpots + surroundings[x][y].filter(function (object) { | |
var isTerrain = object.type === 'terrain'; | |
return isTerrain && (object.terrain === 'swamp' || object.terrain === 'plain'); | |
}).length; | |
}); | |
}); | |
Memory.freeEdges = Memory.freeEdges || {}; | |
Memory.freeEdges[_this.identifier()] = openSpots; | |
})(); | |
} | |
return Memory.freeEdges[this.identifier()]; | |
} | |
}); | |
/***/ }, | |
/* 12 */ | |
/***/ function(module, exports, __webpack_require__) { | |
'use strict'; | |
var _screepGlobals = __webpack_require__(6); | |
Object.assign(_screepGlobals.Flag.prototype, { | |
work: function work() { | |
if (this.name.toLowerCase().indexOf('build') !== -1 && this.room.getControllerOwned()) { | |
var parts = this.name.split('_'); | |
var target = parts[parts.length - 1]; | |
var shouldBuild = false; | |
if (target === STRUCTURE_SPAWN) { | |
shouldBuild = true; | |
} else if (target === STRUCTURE_STORAGE && this.room.controller.level === 4) { | |
shouldBuild = true; | |
} else if (target === STRUCTURE_LINK && this.room.controller.level === 5) { | |
shouldBuild = true; | |
} else if (target === STRUCTURE_WALL && this.room.controller.level > 1) { | |
shouldBuild = true; | |
} | |
if (shouldBuild) { | |
var result = this.room.createConstructionSite(this.pos.x, this.pos.y, target); | |
if (result === 0) { | |
this.remove(); | |
} | |
} | |
} | |
} | |
}); | |
/***/ }, | |
/* 13 */ | |
/***/ function(module, exports) { | |
'use strict'; | |
var usedOnStart = 0; | |
var enabled = false; | |
var depth = 0; | |
function setupProfiler() { | |
depth = 0; // reset depth, this needs to be done each tick. | |
Game.profiler = { | |
stream: function stream(duration, filter) { | |
setupMemory('stream', duration || 10, filter); | |
}, | |
email: function email(duration, filter) { | |
setupMemory('email', duration || 100, filter); | |
}, | |
profile: function profile(duration, filter) { | |
setupMemory('profile', duration || 100, filter); | |
}, | |
reset: resetMemory | |
}; | |
overloadCPUCalc(); | |
} | |
function setupMemory(profileType, duration, filter) { | |
resetMemory(); | |
if (!Memory.profiler) { | |
Memory.profiler = { | |
map: {}, | |
totalTime: 0, | |
enabledTick: Game.time + 1, | |
disableTick: Game.time + duration, | |
type: profileType, | |
filter: filter | |
}; | |
} | |
} | |
function resetMemory() { | |
Memory.profiler = null; | |
} | |
function overloadCPUCalc() { | |
if (Game.rooms.sim) { | |
usedOnStart = 0; // This needs to be reset, but only in the sim. | |
Game.getUsedCpu = function getUsedCpu() { | |
return performance.now() - usedOnStart; | |
}; | |
} | |
} | |
function getFilter() { | |
return Memory.profiler.filter; | |
} | |
function wrapFunction(name, originalFunction) { | |
return function wrappedFunction() { | |
if (Profiler.isProfiling()) { | |
var nameMatchesFilter = name === getFilter(); | |
var start = Game.getUsedCpu(); | |
if (nameMatchesFilter) { | |
depth++; | |
} | |
var result = originalFunction.apply(this, arguments); | |
if (depth > 0 || !getFilter()) { | |
var end = Game.getUsedCpu(); | |
Profiler.record(name, end - start); | |
} | |
if (nameMatchesFilter) { | |
depth--; | |
} | |
return result; | |
} | |
return originalFunction.apply(this, arguments); | |
}; | |
} | |
function hookUpPrototypes() { | |
Profiler.prototypes.forEach(function (proto) { | |
profileObjectFunctions(proto.val, proto.name); | |
}); | |
} | |
function profileObjectFunctions(object, label) { | |
var objectToWrap = object.prototype ? object.prototype : object; | |
Object.keys(objectToWrap).forEach(function (functionName) { | |
var extendedLabel = label + '.' + functionName; | |
if (label === 'Room') { | |
console.log(extendedLabel); | |
} | |
try { | |
if (typeof objectToWrap[functionName] === 'function' && functionName !== 'getUsedCpu') { | |
var originalFunction = objectToWrap[functionName]; | |
objectToWrap[functionName] = profileFunction(originalFunction, extendedLabel); | |
} | |
} catch (e) {} /* eslint no-empty:0 */ | |
}); | |
return objectToWrap; | |
} | |
function profileFunction(fn, functionName) { | |
var fnName = functionName || fn.name; | |
if (!fnName) { | |
console.log('Couldn\'t find a function name for - ', fn); | |
console.log('Will not profile this function.'); | |
// return fn; | |
} | |
return wrapFunction(fnName, fn); | |
} | |
var Profiler = { | |
printProfile: function printProfile() { | |
console.log(Profiler.output()); | |
}, | |
emailProfile: function emailProfile() { | |
Game.notify(Profiler.output()); | |
}, | |
output: function output() { | |
var elapsedTicks = Game.time - Memory.profiler.enabledTick + 1; | |
var header = 'calls\t\ttime\t\tavg\t\tfunction'; | |
var footer = ['Avg: ' + (Memory.profiler.totalTime / elapsedTicks).toFixed(2), 'Total: ' + Memory.profiler.totalTime.toFixed(2), 'Ticks: ' + elapsedTicks].join('\t'); | |
return [].concat(header, Profiler.lines().slice(0, 20), footer).join('\n'); | |
}, | |
lines: function lines() { | |
var stats = Object.keys(Memory.profiler.map).map(function (functionName) { | |
var functionCalls = Memory.profiler.map[functionName]; | |
return { | |
name: functionName, | |
calls: functionCalls.calls, | |
totalTime: functionCalls.time, | |
averageTime: functionCalls.time / functionCalls.calls | |
}; | |
}).sort(function (val1, val2) { | |
return val2.totalTime - val1.totalTime; | |
}); | |
var lines = stats.map(function (data) { | |
return [data.calls, data.totalTime.toFixed(1), data.averageTime.toFixed(3), data.name].join('\t\t'); | |
}); | |
return lines; | |
}, | |
prototypes: [{ name: 'Game', val: Game }, { name: 'Room', val: Room }, { name: 'Structure', val: Structure }, { name: 'Spawn', val: Spawn }, { name: 'Creep', val: Creep }, { name: 'RoomPosition', val: RoomPosition }, { name: 'Source', val: Source }], | |
record: function record(functionName, time) { | |
if (!Memory.profiler.map[functionName]) { | |
Memory.profiler.map[functionName] = { | |
time: 0, | |
calls: 0 | |
}; | |
} | |
Memory.profiler.map[functionName].calls++; | |
Memory.profiler.map[functionName].time += time; | |
}, | |
endTick: function endTick() { | |
if (Game.time >= Memory.profiler.enabledTick) { | |
var cpuUsed = Game.getUsedCpu(); | |
Memory.profiler.totalTime += cpuUsed; | |
Profiler.report(); | |
} | |
}, | |
report: function report() { | |
if (Profiler.shouldPrint()) { | |
Profiler.printProfile(); | |
} else if (Profiler.shouldEmail()) { | |
Profiler.emailProfile(); | |
} | |
}, | |
isProfiling: function isProfiling() { | |
return enabled && !!Memory.profiler && Game.time <= Memory.profiler.disableTick; | |
}, | |
type: function type() { | |
return Memory.profiler.type; | |
}, | |
shouldPrint: function shouldPrint() { | |
var streaming = Profiler.type() === 'stream'; | |
var profiling = Profiler.type() === 'profile'; | |
var onEndingTick = Memory.profiler.disableTick === Game.time; | |
return streaming || profiling && onEndingTick; | |
}, | |
shouldEmail: function shouldEmail() { | |
return Profiler.type() === 'email' && Memory.profiler.disableTick === Game.time; | |
} | |
}; | |
module.exports = { | |
wrap: function wrap(callback) { | |
if (enabled) { | |
setupProfiler(); | |
} | |
if (Profiler.isProfiling()) { | |
usedOnStart = Game.getUsedCpu(); | |
// Commented lines are part of an on going experiment to keep the profiler | |
// performant, and measure certain types of overhead. | |
// var callbackStart = Game.getUsedCpu(); | |
var returnVal = callback(); | |
// var callbackEnd = Game.getUsedCpu(); | |
Profiler.endTick(); | |
// var end = Game.getUsedCpu(); | |
// var profilerTime = (end - start) - (callbackEnd - callbackStart); | |
// var callbackTime = callbackEnd - callbackStart; | |
// var unaccounted = end - profilerTime - callbackTime; | |
// console.log('total-', end, 'profiler-', profilerTime, 'callbacktime-', | |
// callbackTime, 'start-', start, 'unaccounted', unaccounted); | |
return returnVal; | |
} | |
return callback(); | |
}, | |
enable: function enable() { | |
enabled = true; | |
hookUpPrototypes(); | |
}, | |
registerObject: function registerObject(object, label) { | |
return profileObjectFunctions(object, label); | |
}, | |
registerFN: function registerFN(fn, functionName) { | |
return profileFunction(fn, functionName); | |
} | |
}; | |
/***/ } | |
/******/ ]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment