Add action for harvest energy from tombstone

This commit is contained in:
Anton Vakhrushev 2020-07-23 15:39:55 +03:00
parent db60d70ee8
commit b2a52fd4f5
4 changed files with 19 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import { selectSource } from './common';
import { harvestEnergyFromTombstone, selectSource } from './common';
interface BuilderMemory extends CreepMemory {
building: boolean | undefined;
@ -20,6 +20,8 @@ export function runAsBuilder(creep: Creep) {
memory.sourceId = selectSource(creep.room);
}
harvestEnergyFromTombstone(creep);
if (memory.building) {
if (build(creep)) {
return;

View File

@ -27,3 +27,13 @@ function getKeyWithMinWeight(weights: Weights): string {
let keys = Object.keys(weights);
return keys.reduce((key, v) => (weights[v] < weights[key] ? v : key));
}
export function harvestEnergyFromTombstone(creep: Creep) {
const tombstones = creep.pos.findInRange(FIND_TOMBSTONES, 1, {
filter: (t) => t.store[RESOURCE_ENERGY] > 0
});
for (let tomb of tombstones) {
const res = creep.withdraw(tomb, RESOURCE_ENERGY);
console.log('Withdraw', res);
}
}

View File

@ -1,4 +1,4 @@
import { selectSource } from './common';
import { harvestEnergyFromTombstone, selectSource } from './common';
const TARGET_TYPES = [STRUCTURE_EXTENSION, STRUCTURE_SPAWN, STRUCTURE_TOWER];
@ -31,6 +31,8 @@ export function runAsHarvester(creep: Creep) {
break;
}
harvestEnergyFromTombstone(creep);
switch (memory.action) {
case Action.Harvest:
const source = Game.getObjectById(memory.sourceId);

View File

@ -1,4 +1,4 @@
import { selectSource } from './common';
import { harvestEnergyFromTombstone, selectSource } from './common';
interface UpgraderMemory extends CreepMemory {
upgrading: boolean | undefined;
@ -19,6 +19,8 @@ export function runAsUpgrader(creep: Creep) {
memory.sourceId = selectSource(creep.room);
}
harvestEnergyFromTombstone(creep);
if (memory.upgrading) {
if (creep.room.controller && creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.say('⚡ upgrade');