Add action for harvest energy from tombstone
This commit is contained in:
parent
db60d70ee8
commit
b2a52fd4f5
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user