Add harvester source selection
This commit is contained in:
parent
60bd33c8d4
commit
74e8340cc0
@ -1,4 +1,4 @@
|
||||
import { randomIntInRange } from './utils/Random';
|
||||
import { randomIntInRange } from '../utils/Random';
|
||||
|
||||
interface BuilderMemory extends CreepMemory {
|
||||
building: boolean | undefined;
|
22
src/creep/common.ts
Normal file
22
src/creep/common.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { randomIntInRange } from '../utils/Random';
|
||||
|
||||
export interface SourceNumber {
|
||||
sourceNum: number | undefined;
|
||||
}
|
||||
|
||||
function selectSource(memory: SourceNumber) {
|
||||
if (memory.sourceNum === undefined) {
|
||||
const sources = creep.room.find(FIND_SOURCES);
|
||||
memory.sourceNum = randomIntInRange(0, sources.length);
|
||||
}
|
||||
}
|
||||
|
||||
function moveToSource(creep: Creep) {
|
||||
const memory = creep.memory as SourceNumber;
|
||||
const sources = creep.room.find(FIND_SOURCES);
|
||||
const sourceNum = memory.sourceNum;
|
||||
if (creep.harvest(sources[sourceNum]) == ERR_NOT_IN_RANGE) {
|
||||
creep.say('🔄 harvest ' + sourceNum);
|
||||
creep.moveTo(sources[sourceNum], { visualizePathStyle: { stroke: '#ffaa00' } });
|
||||
}
|
||||
}
|
@ -1,9 +1,23 @@
|
||||
import { randomIntInRange } from '../utils/Random';
|
||||
|
||||
interface HarvesterMemory extends CreepMemory {
|
||||
sourceNum: number | undefined;
|
||||
}
|
||||
|
||||
export function runAsHarvester(creep: Creep) {
|
||||
const memory = creep.memory as HarvesterMemory;
|
||||
|
||||
if (memory.sourceNum === undefined) {
|
||||
const sources = creep.room.find(FIND_SOURCES);
|
||||
memory.sourceNum = randomIntInRange(0, sources.length);
|
||||
}
|
||||
|
||||
if (creep.store.getFreeCapacity() > 0) {
|
||||
let sources = creep.room.find(FIND_SOURCES);
|
||||
if (creep.harvest(sources[0]) === ERR_NOT_IN_RANGE) {
|
||||
creep.say('to source');
|
||||
creep.moveTo(sources[0], { visualizePathStyle: { stroke: '#ffaa00' } });
|
||||
const sourceNum = memory.sourceNum;
|
||||
if (creep.harvest(sources[sourceNum]) === ERR_NOT_IN_RANGE) {
|
||||
creep.say('To source ' + sourceNum);
|
||||
creep.moveTo(sources[sourceNum], { visualizePathStyle: { stroke: '#ffaa00' } });
|
||||
}
|
||||
} else {
|
||||
let targets = creep.room.find(FIND_STRUCTURES, {
|
@ -1,4 +1,4 @@
|
||||
import { randomIntInRange } from './utils/Random';
|
||||
import { randomIntInRange } from '../utils/Random';
|
||||
|
||||
interface UpgraderMemory extends CreepMemory {
|
||||
upgrading: boolean | undefined;
|
@ -1,7 +1,7 @@
|
||||
import { ErrorMapper } from 'utils/ErrorMapper';
|
||||
import { runAsHarvester } from './harvester';
|
||||
import { runAsBuilder } from './builder';
|
||||
import { runAsUpgrader } from './upgrader';
|
||||
import { runAsHarvester } from './creep/harvester';
|
||||
import { runAsBuilder } from './creep/builder';
|
||||
import { runAsUpgrader } from './creep/upgrader';
|
||||
import { uniqId } from './utils/Identity';
|
||||
|
||||
function makeName(role: string): string {
|
||||
|
Loading…
Reference in New Issue
Block a user