lodash magic, making it so that vickery doesn't think i'm a noob
This commit is contained in:
parent
acf5e8e70a
commit
0aeab1cf36
21
main.js
21
main.js
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@ -51,27 +51,24 @@ module.exports.loop = function(){
|
||||
helpers.generateName(roleName), // Make names show the roles. Change me to undefined if this gets annoying.
|
||||
{role: roleName});
|
||||
if(newName == ERR_NOT_ENOUGH_ENERGY){
|
||||
console.log("not enough resources to spawn");
|
||||
console.log('not enough resources to spawn');
|
||||
} else {
|
||||
console.log("Spawning", newName);
|
||||
console.log('Spawning', newName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Run stuff for each creep
|
||||
var roleCounts = { builder: 0, harvester: 0, upgrader: 0, guard: 0 }
|
||||
var expected = { builder: 0, harvester: 0, upgrader: 0, guard: 0 }
|
||||
var roleCounts = {harvester: 0, builder: 0, upgrader: 0, guard: 0};
|
||||
var expected = _(creepsConfig).mapValues('minimumCreeps');
|
||||
|
||||
for (var name in Game.creeps){
|
||||
var creep = Game.creeps[name];
|
||||
var role = creep.memory.role;
|
||||
roleCounts[role] += 1;
|
||||
creepsConfig[role].role.run(creep);
|
||||
|
||||
}
|
||||
for (var role in creepsConfig){
|
||||
expected[role] = creepsConfig[role].minimumCreeps;
|
||||
}
|
||||
console.log("current:", JSON.stringify(roleCounts));
|
||||
console.log("expect: ", JSON.stringify(expected));
|
||||
console.log("#############################################################");
|
||||
console.log('current\t', JSON.stringify(roleCounts));
|
||||
console.log('expect\t', JSON.stringify(expected));
|
||||
console.log('#############################################################');
|
||||
};
|
||||
|
@ -1,21 +1,22 @@
|
||||
var battle = require("battle")
|
||||
var battle = require('battle')
|
||||
|
||||
var roleGuard = {
|
||||
getLastFlag: function(){
|
||||
return 2; // TODO. calculate me.
|
||||
|
||||
return 4; // TODO. calculate me.
|
||||
},
|
||||
run: function(creep){
|
||||
console.log(creep, "running Guard")
|
||||
console.log(creep, 'running Guard')
|
||||
// Reset creep to 1
|
||||
creep.memory.patrolDestination = creep.memory.patrolDestination || 1;
|
||||
|
||||
var target = battle.findEnemy(creep);
|
||||
if(target != creep.room.controller && creep.hits > creep.hitsMax - 500 /* no more attack */) {
|
||||
console.log("\t", creep, "attacking:",target)
|
||||
console.log('\t', creep, 'attacking:',target)
|
||||
creep.moveTo(target);
|
||||
creep.attack(target);
|
||||
} else {
|
||||
var destinationFlag = Game.flags["patrol_" + creep.memory.patrolDestination];
|
||||
var destinationFlag = Game.flags['patrol_' + creep.memory.patrolDestination];
|
||||
|
||||
if (creep.pos.isEqualTo(destinationFlag)){
|
||||
creep.memory.patrolDestination += 1;
|
||||
@ -24,8 +25,8 @@ var roleGuard = {
|
||||
if (creep.memory.patrolDestination > this.getLastFlag()){
|
||||
creep.memory.patrolDestination = 1;
|
||||
}
|
||||
destinationFlag = Game.flags["patrol_" + creep.memory.patrolDestination];
|
||||
console.log("\tMoving to Patrol leg:", creep.memory.patrolDestination);
|
||||
destinationFlag = Game.flags['patrol_' + creep.memory.patrolDestination];
|
||||
console.log('\tMoving to Patrol leg:', creep.memory.patrolDestination);
|
||||
creep.moveTo(destinationFlag);
|
||||
}
|
||||
|
||||
|
@ -2,11 +2,11 @@ var roleHarvester = {
|
||||
|
||||
/** @param {Creep} creep **/
|
||||
run: function(creep) {
|
||||
console.log(creep, "running Harvest");
|
||||
console.log(creep, 'running Harvest');
|
||||
if(creep.carry.energy < creep.carryCapacity) {
|
||||
var source = creep.pos.findClosestByPath(FIND_SOURCES);
|
||||
if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
|
||||
console.log("\tmoving to", source);
|
||||
console.log('\tmoving to', source);
|
||||
creep.moveTo(source);
|
||||
}
|
||||
}
|
||||
@ -21,7 +21,7 @@ var roleHarvester = {
|
||||
});
|
||||
if(targets.length > 0) {
|
||||
if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||
console.log("\tmoving to", targets[0]);
|
||||
console.log('\tmoving to', targets[0]);
|
||||
creep.moveTo(targets[0]);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ var roleUpgrader = {
|
||||
|
||||
/** @param {Creep} creep **/
|
||||
run: function(creep) {
|
||||
console.log(creep, "running Upgrade");
|
||||
console.log(creep, 'running Upgrade');
|
||||
|
||||
if(creep.memory.upgrading && creep.carry.energy == 0) {
|
||||
creep.memory.upgrading = false;
|
||||
@ -13,14 +13,14 @@ var roleUpgrader = {
|
||||
|
||||
if(creep.memory.upgrading) {
|
||||
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
|
||||
console.log("\tmoving to", creep.room.controller);
|
||||
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);
|
||||
console.log('\tmoving to', source);
|
||||
creep.moveTo(source);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user