Add repair tasks to builder
This commit is contained in:
parent
7214f6d408
commit
950681a0ed
@ -22,19 +22,17 @@ export function runAsBuilder(creep: Creep) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (memory.building) {
|
if (memory.building) {
|
||||||
const targets = creep.room.find(FIND_CONSTRUCTION_SITES);
|
if (build(creep)) {
|
||||||
if (targets.length > 0) {
|
return;
|
||||||
if (creep.build(targets[0]) == ERR_NOT_IN_RANGE) {
|
}
|
||||||
creep.say('🚧 build');
|
if (repair(creep)) {
|
||||||
creep.moveTo(targets[0], { visualizePathStyle: { stroke: '#ffffff' } });
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
const spawns = creep.room.find(FIND_MY_SPAWNS);
|
const spawns = creep.room.find(FIND_MY_SPAWNS);
|
||||||
if (spawns.length > 0) {
|
if (spawns.length > 0) {
|
||||||
creep.say('To spawn');
|
creep.say('To spawn');
|
||||||
creep.moveTo(spawns[0]);
|
creep.moveTo(spawns[0]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const sources = creep.room.find(FIND_SOURCES);
|
const sources = creep.room.find(FIND_SOURCES);
|
||||||
const sourceNum = memory.sourceNum;
|
const sourceNum = memory.sourceNum;
|
||||||
@ -44,3 +42,27 @@ export function runAsBuilder(creep: Creep) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function build(creep: Creep): boolean {
|
||||||
|
const targets = creep.room.find(FIND_MY_CONSTRUCTION_SITES);
|
||||||
|
if (targets.length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (creep.build(targets[0]) == ERR_NOT_IN_RANGE) {
|
||||||
|
creep.say('🚧 build');
|
||||||
|
creep.moveTo(targets[0], { visualizePathStyle: { stroke: '#ffffff' } });
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function repair(creep: Creep) {
|
||||||
|
const targets = creep.room.find(FIND_STRUCTURES).filter((t) => t.hits < t.hitsMax);
|
||||||
|
if (targets.length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (creep.repair(targets[0]) == ERR_NOT_IN_RANGE) {
|
||||||
|
creep.say('🚧 repair');
|
||||||
|
creep.moveTo(targets[0], { visualizePathStyle: { stroke: '#ffffff' } });
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -16,20 +16,20 @@ enum CreepRole {
|
|||||||
|
|
||||||
function makeCreep(role: CreepRole, count: number) {
|
function makeCreep(role: CreepRole, count: number) {
|
||||||
const creeps = Object.values(Game.creeps).filter((c) => c.memory.role === role);
|
const creeps = Object.values(Game.creeps).filter((c) => c.memory.role === role);
|
||||||
console.log('Make creep ', role, 'need', count, 'has', creeps.length);
|
console.log(`Make creep "${role}"`, 'need', count, 'has', creeps.length);
|
||||||
if (creeps.length < count) {
|
if (creeps.length < count) {
|
||||||
const firstSpawn = _.first(Object.values(Game.spawns));
|
const firstSpawn = _.first(Object.values(Game.spawns));
|
||||||
const name = makeName(role);
|
const name = makeName(role);
|
||||||
const memory = { role: role } as CreepMemory;
|
const memory = { role: role } as CreepMemory;
|
||||||
const err = firstSpawn.spawnCreep([WORK, CARRY, MOVE], name, { memory });
|
const err = firstSpawn.spawnCreep([WORK, CARRY, MOVE], name, { memory });
|
||||||
console.log(`Make creep "${role}" err`, err);
|
console.log(`Make creep "${role}"`, 'err', err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When compiling TS to JS and bundling with rollup, the line numbers and file names in error messages change
|
// When compiling TS to JS and bundling with rollup, the line numbers and file names in error messages change
|
||||||
// This utility uses source maps to get the line numbers and file names of the original, TS source code
|
// This utility uses source maps to get the line numbers and file names of the original, TS source code
|
||||||
export const loop = ErrorMapper.wrapLoop(() => {
|
export const loop = ErrorMapper.wrapLoop(() => {
|
||||||
console.log(`Current game tick is ${Game.time}`);
|
console.log(`\nCurrent game tick is ${Game.time}`);
|
||||||
|
|
||||||
// Automatically delete memory of missing creeps
|
// Automatically delete memory of missing creeps
|
||||||
for (const name in Memory.creeps) {
|
for (const name in Memory.creeps) {
|
||||||
|
Loading…
Reference in New Issue
Block a user