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