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