77 lines
2.7 KiB
JavaScript
77 lines
2.7 KiB
JavaScript
var roleHarvester = require('role.harvester');
|
|
var roleUpgrader = require('role.upgrader');
|
|
var roleBuilder = require('role.builder');
|
|
var strategyCreepSize = require('strategy.creepSize');
|
|
|
|
module.exports.loop = function () {
|
|
|
|
var tower = Game.getObjectById('61dc669250ab766c4128b6a4');
|
|
if(tower) {
|
|
var closestDamagedStructure = tower.pos.findClosestByRange(FIND_STRUCTURES, {
|
|
filter: (structure) => structure.hits < structure.hitsMax
|
|
});
|
|
if(closestDamagedStructure) {
|
|
tower.repair(closestDamagedStructure);
|
|
}
|
|
|
|
var closestHostile = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
|
|
if(closestHostile) {
|
|
tower.attack(closestHostile);
|
|
}
|
|
}
|
|
for(var name in Memory.creeps) {
|
|
if(!Game.creeps[name]) {
|
|
delete Memory.creeps[name];
|
|
console.log('Clearing non-existing creep memory:', name);
|
|
}
|
|
}
|
|
|
|
var spawn = Game.spawns['Spawn1']
|
|
var harvesters = _.filter(Game.creeps, (creep) => creep.memory.role == 'harvester');
|
|
var builders = _.filter(Game.creeps, (creep) => creep.memory.role == 'builder');
|
|
var upgraders = _.filter(Game.creeps, (creep) => creep.memory.role == 'upgrader');
|
|
if (Game.time % 20 === 0) {
|
|
console.log(Game.time + 'tick: H:: ' + harvesters.length + " B: " + builders.length + " U: " + upgraders.length + " with energy: " + spawn.room.energyCapacityAvailable);
|
|
}
|
|
|
|
var newSize = strategyCreepSize.choose(spawn.room.energyCapacityAvailable);
|
|
var newRole = undefined;
|
|
if(harvesters.length < 4) {
|
|
var newCreep = 'Harvester' + Game.time;
|
|
newRole = 'harvester'
|
|
} else if(upgraders.length < 3) {
|
|
var newCreep = 'Upgrader ' + Game.time;
|
|
newRole = 'upgrader'
|
|
} else if(builders.length < 3) {
|
|
var newCreep = 'Builder ' + Game.time;
|
|
newRole = 'builder'
|
|
//newSize = [WORK, WORK, MOVE, CARRY];
|
|
}
|
|
if (newRole !== undefined) {
|
|
console.log('Spawning new : ' + newCreep + ' with size: ' + newSize.length);
|
|
spawn.spawnCreep(newSize, newCreep, {memory: {role: newRole}})
|
|
}
|
|
|
|
if(spawn.spawning) {
|
|
var spawningCreep = Game.creeps[spawn.spawning.name];
|
|
spawn.room.visual.text(
|
|
'🛠️' + spawningCreep.memory.role,
|
|
spawn.pos.x - 1,
|
|
spawn.pos.y + 1,
|
|
{align: 'left', opacity: 0.8});
|
|
}
|
|
|
|
for(var name in Game.creeps) {
|
|
var creep = Game.creeps[name];
|
|
if(creep.memory.role == 'harvester') {
|
|
roleHarvester.run(creep);
|
|
}
|
|
if(creep.memory.role == 'upgrader') {
|
|
roleUpgrader.run(creep);
|
|
}
|
|
if(creep.memory.role == 'builder') {
|
|
roleBuilder.run(creep);
|
|
}
|
|
}
|
|
}
|