|
|
|
@ -3,13 +3,49 @@ const common = require('common') |
|
|
|
|
module.exports = { |
|
|
|
|
name: 'transporter', |
|
|
|
|
prio: 4, |
|
|
|
|
count: 1, |
|
|
|
|
getCount: colonyRoom => Object.keys(colonyRoom.memory.sourcesData).length |
|
|
|
|
+ Math.floor((colonyRoom.find(FIND_DROPPED_RESOURCES).reduce((total, current) => total + current.amount, 0)) / 500) |
|
|
|
|
+ Math.floor((colonyRoom.find(FIND_STRUCTURES, {filter: s => s.structureType === STRUCTURE_CONTAINER && colonyRoom.memory.sourceContainers.indexOf(s.id) !== -1}).reduce((total, current) => total + current.store[RESOURCE_ENERGY], 0)) / 500) |
|
|
|
|
, |
|
|
|
|
bodies: [ |
|
|
|
|
[CARRY, MOVE], |
|
|
|
|
[CARRY, CARRY, MOVE], |
|
|
|
|
[CARRY, CARRY, MOVE, CARRY, CARRY, MOVE], |
|
|
|
|
[CARRY, CARRY, MOVE, CARRY, CARRY, MOVE, CARRY, CARRY, MOVE], |
|
|
|
|
[CARRY, CARRY, MOVE, CARRY, CARRY, MOVE, CARRY, CARRY, MOVE, CARRY, CARRY, MOVE], |
|
|
|
|
], |
|
|
|
|
tickInit () { |
|
|
|
|
for (let room of Object.values(Game.rooms)) { |
|
|
|
|
if (!room.memory.spawnContainers) { |
|
|
|
|
room.memory.spawnContainers = [] |
|
|
|
|
} |
|
|
|
|
if (!room.memory.sourceContainers) { |
|
|
|
|
room.memory.sourceContainers = [] |
|
|
|
|
} |
|
|
|
|
if (Game.time % 100 === 0 && room.controller.my) { |
|
|
|
|
let containers = room.controller.pos.findInRange(FIND_STRUCTURES, 4, {filter: s => s.structureType === STRUCTURE_CONTAINER}) |
|
|
|
|
if (containers.length > 0) { |
|
|
|
|
room.memory.controllerContainer = containers[0].id |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
room.memory.spawnContainers = [] |
|
|
|
|
for (let spawn of room.find(FIND_STRUCTURES, {filter: s => s.structureType === STRUCTURE_SPAWN})) { |
|
|
|
|
containers = spawn.pos.findInRange(FIND_STRUCTURES, 4, {filter: s => s.structureType === STRUCTURE_CONTAINER}) |
|
|
|
|
if (containers.length > 0) { |
|
|
|
|
containers.forEach(el => room.memory.spawnContainers.push(el.id)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
room.memory.sourceContainers = [] |
|
|
|
|
for (let spawn of room.find(FIND_SOURCES)) { |
|
|
|
|
containers = spawn.pos.findInRange(FIND_STRUCTURES, 2, {filter: s => s.structureType === STRUCTURE_CONTAINER}) |
|
|
|
|
if (containers.length > 0) { |
|
|
|
|
containers.forEach(el => room.memory.sourceContainers.push(el.id)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
tick (creep) { |
|
|
|
|
if (creep.store.getFreeCapacity(RESOURCE_ENERGY) === 0) { |
|
|
|
|
creep.memory.loading = false |
|
|
|
@ -45,6 +81,8 @@ module.exports = { |
|
|
|
|
let quickloadTargets = creep.pos.findInRange(FIND_STRUCTURES, 2, { |
|
|
|
|
filter: s => { |
|
|
|
|
return s.structureType === STRUCTURE_CONTAINER |
|
|
|
|
&& s.id !== creep.room.memory.controllerContainer |
|
|
|
|
&& creep.room.memory.spawnContainers.indexOf(s.id) === -1 |
|
|
|
|
&& s.store[RESOURCE_ENERGY] > creep.store.getFreeCapacity(RESOURCE_ENERGY) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
@ -71,6 +109,8 @@ module.exports = { |
|
|
|
|
target = creep.pos.findClosestByPath(FIND_STRUCTURES, { |
|
|
|
|
filter: s => { |
|
|
|
|
return s.structureType === STRUCTURE_CONTAINER |
|
|
|
|
&& s.id !== creep.room.memory.controllerContainer |
|
|
|
|
&& creep.room.memory.spawnContainers.indexOf(s.id) === -1 |
|
|
|
|
&& s.store[RESOURCE_ENERGY] > 100 |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
@ -131,7 +171,9 @@ module.exports = { |
|
|
|
|
if (!target) { |
|
|
|
|
target = creep.pos.findClosestByPath(FIND_STRUCTURES, { |
|
|
|
|
filter: s => { |
|
|
|
|
return s.structureType === STRUCTURE_STORAGE |
|
|
|
|
return (s.structureType === STRUCTURE_STORAGE |
|
|
|
|
|| s.id === creep.room.memory.controllerContainer |
|
|
|
|
|| creep.room.memory.spawnContainers.indexOf(s.id) !== -1) |
|
|
|
|
&& s.store.getFreeCapacity(RESOURCE_ENERGY) > 0 |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|