cleanup lastFlagCode
This commit is contained in:
parent
68faf498b7
commit
ed4c5eb67f
11
helpers.js
11
helpers.js
@ -6,13 +6,10 @@ var helpers = {
|
||||
});
|
||||
},
|
||||
getLastFlag: function(flagName){
|
||||
return Object.keys(Game.flags).reduce(function(m,f) {
|
||||
if (f.startsWith(flagName)){
|
||||
m = Math.max(m, f.slice(flagName.length));
|
||||
}
|
||||
return m;
|
||||
},
|
||||
-1);
|
||||
return _(Object.keys(Game.flags))
|
||||
.filter((f) => f.startsWith(flagName))
|
||||
.map((f) => f.slice(flagName.length))
|
||||
.max();
|
||||
},
|
||||
};
|
||||
|
||||
|
6
main.js
6
main.js
@ -17,8 +17,8 @@ var creepsConfig = {
|
||||
role: roleBuilder
|
||||
},
|
||||
upgrader: {
|
||||
bodyParts: [WORK, CARRY, MOVE, MOVE, MOVE],
|
||||
minimumCreeps: 4,
|
||||
bodyParts: [WORK, CARRY, CARRY, MOVE, MOVE],
|
||||
minimumCreeps: 6,
|
||||
role: roleUpgrader
|
||||
},
|
||||
guard: {
|
||||
@ -35,7 +35,7 @@ module.exports.loop = function(){
|
||||
for (var name in Memory.creeps){
|
||||
if (!Game.creeps[name]){
|
||||
delete Memory.creeps[name];
|
||||
console.log('Cleaning non-existing creep memory: ', name);
|
||||
console.log('Cleaning non-existing creep memory:', name);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ var BreakException= {};
|
||||
|
||||
var roleBuilder = {
|
||||
run: function(creep){
|
||||
console.log(creep, "running Builder");
|
||||
if(creep.memory.building && creep.carry.energy == 0){
|
||||
creep.memory.building = false;
|
||||
}
|
||||
|
@ -9,13 +9,14 @@ var roleGuard = {
|
||||
if (this.creep.pos.isEqualTo(this.getDestinationFlag())){
|
||||
this.creep.memory.patrolDestination += 1;
|
||||
}
|
||||
if (this.creep.memory.patrolDestination > helpers.getLastFlag("patrol_")){
|
||||
if (this.creep.memory.patrolDestination > this.lastFlag){
|
||||
this.creep.memory.patrolDestination = 1;
|
||||
}
|
||||
this.creep.moveTo(this.getDestinationFlag());
|
||||
},
|
||||
run: function(creep){
|
||||
this.creep = creep;
|
||||
this.lastFlag = helpers.getLastFlag("patrol_");
|
||||
console.log(creep, 'running Guard')
|
||||
creep.memory.patrolDestination = creep.memory.patrolDestination || 1;
|
||||
var target = battle.findEnemy(creep);
|
||||
@ -24,7 +25,11 @@ var roleGuard = {
|
||||
creep.moveTo(target);
|
||||
creep.attack(target);
|
||||
} else {
|
||||
if (this.lastFlag > 0){
|
||||
this.patrol();
|
||||
} else {
|
||||
this.creep.moveTo(creep.room.controller)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ var roleUpgrader = {
|
||||
|
||||
/** @param {Creep} creep **/
|
||||
run: function(creep) {
|
||||
console.log(creep, 'running Upgrade');
|
||||
|
||||
if(creep.memory.upgrading && creep.carry.energy == 0) {
|
||||
creep.memory.upgrading = false;
|
||||
}
|
||||
@ -13,14 +11,12 @@ var roleUpgrader = {
|
||||
|
||||
if(creep.memory.upgrading) {
|
||||
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
|
||||
console.log('\tmoving to', creep.room.controller);
|
||||
creep.moveTo(creep.room.controller);
|
||||
}
|
||||
}
|
||||
else {
|
||||
var source = creep.pos.findClosestByPath(FIND_SOURCES);
|
||||
if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
|
||||
console.log('\tmoving to', source);
|
||||
creep.moveTo(source);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user