parent
a741cd8352
commit
493a1e0bad
@ -1,47 +1,50 @@ |
|||||||
const roleHarvester = require('./role.harvester') |
const roleHarvester = require('./role.harvester') |
||||||
|
const roleRemoteHarvester = require('./role.remoteHarvester') |
||||||
const roleTransporter = require('./role.transporter') |
const roleTransporter = require('./role.transporter') |
||||||
const roleBuilder = require('./role.builder') |
const roleBuilder = require('./role.builder') |
||||||
const roleUpgrader = require('./role.upgrader') |
const roleUpgrader = require('./role.upgrader') |
||||||
|
const roleScout = require('./role.scout') |
||||||
|
const roleAttacker = require('./role.attacker') |
||||||
|
const roleRangedAttacker = require('./role.rangedAttacker') |
||||||
|
const roleHauler = require('./role.hauler') |
||||||
|
const roleHealer = require('./role.healer') |
||||||
|
const roleFiller = require('./role.filler') |
||||||
|
const roleReserver = require('./role.reserver') |
||||||
|
|
||||||
global.ROLES = { |
global.roleModules = [ |
||||||
harvester: { |
roleHarvester, |
||||||
prio: 3, |
roleRemoteHarvester, |
||||||
count: 3, |
roleBuilder, |
||||||
module: roleHarvester, |
roleTransporter, |
||||||
bodies: [ |
roleUpgrader, |
||||||
[WORK, WORK, CARRY, MOVE], |
roleScout, |
||||||
[WORK, WORK, WORK, WORK, WORK, WORK, CARRY, MOVE], |
roleRangedAttacker, |
||||||
[WORK, WORK, WORK, WORK, WORK, WORK, CARRY, MOVE, MOVE], |
roleHauler, |
||||||
[WORK, WORK, WORK, WORK, WORK, WORK, CARRY, MOVE, MOVE, MOVE], |
roleAttacker, |
||||||
[WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE, MOVE], |
roleHealer, |
||||||
[WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE], |
roleFiller, |
||||||
|
roleReserver, |
||||||
] |
] |
||||||
}, |
|
||||||
transporter: { |
global.ROLES = {} |
||||||
prio: 4, |
for (let mod of roleModules) { |
||||||
count: 2, |
ROLES[mod.name] = mod |
||||||
module: roleTransporter, |
} |
||||||
bodies: [ |
|
||||||
[CARRY, CARRY, MOVE], |
global.creepIsAttacker = creep => creep.getActiveBodyparts(ATTACK) + creep.getActiveBodyparts(RANGED_ATTACK) > 0 |
||||||
[CARRY, CARRY, MOVE, CARRY, CARRY, MOVE], |
global.activeRemotes = ['E8S4', 'E8S5', 'E9S5', 'E8S3'] |
||||||
[CARRY, CARRY, MOVE, CARRY, CARRY, MOVE, CARRY, CARRY, MOVE], |
|
||||||
[CARRY, CARRY, MOVE, CARRY, CARRY, MOVE, CARRY, CARRY, MOVE, CARRY, CARRY, MOVE], |
global.ALREADY_IN_ROOM = 'alreadyInRoom' |
||||||
] |
global.MOVING = 'moving' |
||||||
}, |
|
||||||
builder: { |
global.moveToRoom = function (creep, targetRoom) { |
||||||
prio: 5, |
if (creep.pos.roomName === targetRoom) { |
||||||
count: 2, |
return ALREADY_IN_ROOM |
||||||
maxExpands: 4, |
} |
||||||
module: roleBuilder, |
|
||||||
baseBody: [WORK, CARRY, MOVE, MOVE], |
const exitDir = Game.map.findExit(creep.room, targetRoom); |
||||||
expandBody: [WORK, CARRY, MOVE, MOVE], |
const exit = creep.pos.findClosestByRange(exitDir); |
||||||
}, |
creep.moveTo(exit); |
||||||
upgrader: { |
creep.say(targetRoom) |
||||||
prio: 6, |
return MOVING |
||||||
count: 2, |
|
||||||
maxExpands: 4, |
|
||||||
module: roleUpgrader, |
|
||||||
baseBody: [WORK, CARRY, MOVE], |
|
||||||
expandBody: [WORK, WORK, MOVE], |
|
||||||
}, |
|
||||||
} |
} |
||||||
|
@ -0,0 +1,85 @@ |
|||||||
|
module.exports = { |
||||||
|
name: 'attacker', |
||||||
|
prio: 10, |
||||||
|
tickInit () { |
||||||
|
for (let room of Object.values(Game.rooms)) { |
||||||
|
if (!room.memory.attacker) { |
||||||
|
room.memory.attacker = {} |
||||||
|
} |
||||||
|
if (room.find(FIND_STRUCTURES, {filter: s => s.structureType === STRUCTURE_TOWER}).length > 0) { |
||||||
|
room.memory.attacker.targetCount = 0 |
||||||
|
continue |
||||||
|
} |
||||||
|
room.memory.attacker.targetCount = Math.min(room.find(FIND_HOSTILE_CREEPS).length, 2) |
||||||
|
} |
||||||
|
}, |
||||||
|
nextSpawn (spawn, roleCreeps) { |
||||||
|
for (let room of Object.values(Game.rooms)) { |
||||||
|
if (_.filter(roleCreeps, {memory: {room: room.name}}).length < room.memory.attacker.targetCount) { |
||||||
|
return [ |
||||||
|
[ATTACK, MOVE, ATTACK, MOVE, ATTACK, MOVE, ATTACK, MOVE, ATTACK, MOVE, ATTACK, MOVE], |
||||||
|
{room: room.name} |
||||||
|
] |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
tick (creep) { |
||||||
|
let room = Game.rooms[creep.memory.room] |
||||||
|
let targetRoomName = creep.memory.room |
||||||
|
if (targetRoomName !== creep.pos.roomName |
||||||
|
&& (_.filter(Game.creeps, {memory: {role: 'healer', room: targetRoomName}, spawning: false}).length < Memory.rooms[targetRoomName].healer.targetCount |
||||||
|
|| _.filter(Game.creeps, {memory: {role: 'attacker', room: targetRoomName}, spawning: false}).length < Memory.rooms[targetRoomName].attacker.targetCount |
||||||
|
|| _.filter(Game.creeps, {memory: {role: 'rangedAttacker', room: targetRoomName}, spawning: false}).length < Memory.rooms[targetRoomName].rangedAttacker.targetCount) |
||||||
|
) { |
||||||
|
if (creep.ticksToLive < 1200) { |
||||||
|
creep.moveTo(creep.pos.findClosestByPath(FIND_MY_SPAWNS)) |
||||||
|
} |
||||||
|
else { |
||||||
|
creep.moveTo(creep.pos.findClosestByPath(FIND_FLAGS, { |
||||||
|
filter: el => el.name.startsWith('gather'), |
||||||
|
visualizePathStyle: {stroke: '#0017ff'} |
||||||
|
})) |
||||||
|
} |
||||||
|
return |
||||||
|
} |
||||||
|
if (!room || targetRoomName !== creep.pos.roomName) { |
||||||
|
creep.moveTo(new RoomPosition(25, 25, creep.memory.room)) |
||||||
|
return |
||||||
|
} |
||||||
|
if (creep.pos.x <= 1) { |
||||||
|
creep.move(RIGHT) |
||||||
|
} else if (creep.pos.y <= 1) { |
||||||
|
creep.move(BOTTOM) |
||||||
|
} else if (creep.pos.x >= 48) { |
||||||
|
creep.move(LEFT) |
||||||
|
} else if (creep.pos.y >= 48) { |
||||||
|
creep.move(TOP) |
||||||
|
} |
||||||
|
|
||||||
|
let targetCreep |
||||||
|
if (creep.memory.lastTarget) { |
||||||
|
targetCreep = Game.getObjectById(creep.memory.lastTarget) |
||||||
|
if (targetCreep && targetCreep.pos.roomName !== targetRoomName) { |
||||||
|
delete creep.memory.lastTarget |
||||||
|
targetCreep = undefined |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (targetCreep && !creepIsAttacker(targetCreep)) { |
||||||
|
let closeAttackers = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 3, {filter: c => c.getActiveBodyparts(ATTACK) > 0 && c.pos.roomName === targetRoomName}) |
||||||
|
if (closeAttackers.length > 0) { |
||||||
|
targetCreep = closeAttackers[0] |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (!targetCreep) { |
||||||
|
targetCreep = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS, {filter: c => (creepIsAttacker(c) || c.getActiveBodyparts(CARRY) >= 2) && c.pos.roomName === targetRoomName}) |
||||||
|
} |
||||||
|
if (targetCreep) { |
||||||
|
creep.memory.lastTarget = targetCreep.id |
||||||
|
if (creep.attack(targetCreep) === ERR_NOT_IN_RANGE) { |
||||||
|
creep.moveTo(targetCreep.pos) |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
} |
@ -0,0 +1,58 @@ |
|||||||
|
const common = require('common') |
||||||
|
|
||||||
|
module.exports = { |
||||||
|
name: 'filler', |
||||||
|
prio: 4, |
||||||
|
count: 2, |
||||||
|
bodies: [ |
||||||
|
[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], |
||||||
|
], |
||||||
|
tick (creep) { |
||||||
|
if (creep.store.getFreeCapacity(RESOURCE_ENERGY) === 0) { |
||||||
|
creep.memory.loading = false |
||||||
|
} |
||||||
|
else if (creep.store[RESOURCE_ENERGY] === 0) { |
||||||
|
creep.memory.loading = true |
||||||
|
} |
||||||
|
|
||||||
|
if (creep.memory.loading) { |
||||||
|
let target = creep.pos.findClosestByPath(FIND_STRUCTURES, { |
||||||
|
filter: s => { |
||||||
|
return (s.structureType === STRUCTURE_STORAGE || s.structureType === STRUCTURE_CONTAINER) |
||||||
|
&& s.store[RESOURCE_ENERGY] > Math.min(creep.store.getFreeCapacity(RESOURCE_ENERGY), 100) |
||||||
|
} |
||||||
|
}) |
||||||
|
if (target) { |
||||||
|
if (creep.withdraw(target, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) { |
||||||
|
creep.moveTo(target, {visualizePathStyle: {stroke: '#f7e180'}}) |
||||||
|
} |
||||||
|
} else { |
||||||
|
creep.moveTo(creep.pos.findClosestByRange(FIND_FLAGS, {filter: flag => flag.name.startsWith('idle')}), {visualizePathStyle: {stroke: '#ff0000'}}); |
||||||
|
return 'idle' |
||||||
|
} |
||||||
|
} |
||||||
|
else { |
||||||
|
let target = creep.pos.findClosestByPath(FIND_STRUCTURES, { |
||||||
|
filter: s => ( |
||||||
|
s.structureType === STRUCTURE_EXTENSION |
||||||
|
|| s.structureType === STRUCTURE_SPAWN |
||||||
|
) |
||||||
|
&& s.store.getFreeCapacity(RESOURCE_ENERGY) > 0 |
||||||
|
}) |
||||||
|
if (!target && creep.room.storage && creep.room.storage.store[RESOURCE_ENERGY] > 1e5) { |
||||||
|
target = creep.room.storage.pos.findClosestByRange(FIND_STRUCTURES, {filter: s => s.structureType === STRUCTURE_LINK}) |
||||||
|
} |
||||||
|
if (target) { |
||||||
|
if (creep.transfer(target, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) { |
||||||
|
creep.moveTo(target, {visualizePathStyle: {stroke: '#00ff0f'}}); |
||||||
|
} |
||||||
|
} else { |
||||||
|
creep.moveTo(creep.pos.findClosestByRange(FIND_FLAGS, {filter: flag => flag.name.startsWith('idle')}), {visualizePathStyle: {stroke: '#ff0000'}}); |
||||||
|
return 'idle' |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
@ -0,0 +1,101 @@ |
|||||||
|
module.exports = { |
||||||
|
name: 'hauler', |
||||||
|
prio: 11, |
||||||
|
tickInit () { |
||||||
|
for (let room of Object.values(Game.rooms)) { |
||||||
|
if (!room.memory.hauler) { |
||||||
|
room.memory.hauler = {} |
||||||
|
} |
||||||
|
let harvesters = room.find(FIND_MY_CREEPS, {filter: c => c.memory.role === 'remoteHarvester' && c.memory.room === room.name}) |
||||||
|
let filledContainers = room.find(FIND_STRUCTURES, {filter: s => s.structureType === STRUCTURE_CONTAINER && s.store[RESOURCE_ENERGY] > 0}) |
||||||
|
if (room.find(FIND_STRUCTURES, {filter: s => s.structureType === STRUCTURE_TOWER || s.structureType === STRUCTURE_SPAWN}).length > 0 |
||||||
|
|| (filledContainers.length === 0 && harvesters.length === 0) |
||||||
|
|| room.find(FIND_HOSTILE_CREEPS, {filter: c => creepIsAttacker(c)}).length > 0 |
||||||
|
) { |
||||||
|
room.memory.hauler.targetCount = 0 |
||||||
|
continue |
||||||
|
} |
||||||
|
room.memory.hauler.targetCount = Math.max(filledContainers.length, harvesters.length) * 6 |
||||||
|
} |
||||||
|
}, |
||||||
|
nextSpawn (spawn, roleCreeps) { |
||||||
|
for (let room of Object.values(Game.rooms)) { |
||||||
|
if (_.filter(roleCreeps, {memory: {room: room.name}}).length < room.memory.hauler.targetCount) { |
||||||
|
return [ |
||||||
|
[CARRY, MOVE, CARRY, MOVE, CARRY, MOVE, CARRY, MOVE], |
||||||
|
{room: room.name} |
||||||
|
] |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
tick (creep) { |
||||||
|
let targetRoom = Game.rooms[creep.memory.room] |
||||||
|
let hostileCreeps = [1] |
||||||
|
if (targetRoom) { |
||||||
|
hostileCreeps = targetRoom.find(FIND_HOSTILE_CREEPS, {filter: c => creepIsAttacker(c)}) |
||||||
|
} |
||||||
|
if (creep.store.getFreeCapacity(RESOURCE_ENERGY) > 0 && hostileCreeps.length === 0) { |
||||||
|
if (moveToRoom(creep, creep.memory.room) === MOVING) { |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
let dropped = creep.pos.findInRange(FIND_DROPPED_RESOURCES, 1); |
||||||
|
if (dropped.length > 0) { |
||||||
|
creep.pickup(dropped[0]) |
||||||
|
} |
||||||
|
|
||||||
|
dropped = creep.pos.findClosestByPath(FIND_DROPPED_RESOURCES, {filter: r => r.amount >= 100}); |
||||||
|
if (dropped) { |
||||||
|
if (creep.pickup(dropped) === ERR_NOT_IN_RANGE) { |
||||||
|
creep.moveTo(dropped) |
||||||
|
return |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
let target = creep.pos.findClosestByPath(FIND_TOMBSTONES, { |
||||||
|
filter: (structure) => structure.store[RESOURCE_ENERGY] > 0 |
||||||
|
}) |
||||||
|
if (!target) { |
||||||
|
target = creep.pos.findClosestByPath(FIND_RUINS, { |
||||||
|
filter: (structure) => structure.store[RESOURCE_ENERGY] > 0 |
||||||
|
}) |
||||||
|
} |
||||||
|
if (!target) { |
||||||
|
target = creep.pos.findClosestByPath(FIND_STRUCTURES, { |
||||||
|
filter: s => { |
||||||
|
return s.structureType === STRUCTURE_CONTAINER |
||||||
|
} |
||||||
|
}) |
||||||
|
} |
||||||
|
if (target) { |
||||||
|
if (creep.withdraw(target, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) { |
||||||
|
creep.moveTo(target, {visualizePathStyle: {stroke: '#f7e180'}}) |
||||||
|
} |
||||||
|
} else { |
||||||
|
if (!target) { |
||||||
|
target = creep.pos.findClosestByRange(FIND_MY_CREEPS, { |
||||||
|
filter: s => { |
||||||
|
return s.store[RESOURCE_ENERGY] >= s.store.getCapacity(RESOURCE_ENERGY) * 0.5 |
||||||
|
&& s.memory.role === 'remoteHarvester' |
||||||
|
} |
||||||
|
}) |
||||||
|
} |
||||||
|
if (target) { |
||||||
|
if (creep.pos.getRangeTo(target) > 1) { |
||||||
|
creep.moveTo(target, {visualizePathStyle: {stroke: '#f7e180'}}) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} else if (creep.store[RESOURCE_ENERGY] > 0) { |
||||||
|
let storage = Game.rooms[creep.memory.colony].storage |
||||||
|
if (creep.transfer(storage, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) { |
||||||
|
creep.moveTo(storage) |
||||||
|
} |
||||||
|
} else if (moveToRoom(creep,creep.memory.colony) === MOVING) { |
||||||
|
return |
||||||
|
} else { |
||||||
|
creep.moveTo(creep.pos.findClosestByRange(FIND_FLAGS, {filter: flag => flag.name.startsWith('idle')}), {visualizePathStyle: {stroke: '#ff0000'}}); |
||||||
|
return 'idle' |
||||||
|
} |
||||||
|
}, |
||||||
|
} |
@ -0,0 +1,88 @@ |
|||||||
|
module.exports = { |
||||||
|
name: 'healer', |
||||||
|
prio: 10, |
||||||
|
tickInit () { |
||||||
|
for (let room of Object.values(Game.rooms)) { |
||||||
|
if (!room.memory.healer) { |
||||||
|
room.memory.healer = {} |
||||||
|
} |
||||||
|
if (room.find(FIND_STRUCTURES, {filter: s => s.structureType === STRUCTURE_TOWER}).length > 0) { |
||||||
|
room.memory.healer.targetCount = 0 |
||||||
|
continue |
||||||
|
} |
||||||
|
room.memory.healer.targetCount = Math.min(room.find(FIND_HOSTILE_CREEPS).length, 1) |
||||||
|
} |
||||||
|
}, |
||||||
|
nextSpawn (spawn, roleCreeps) { |
||||||
|
for (let room of Object.values(Game.rooms)) { |
||||||
|
if (_.filter(roleCreeps, {memory: {room: room.name}}).length < room.memory.healer.targetCount) { |
||||||
|
return [ |
||||||
|
[MOVE, MOVE, MOVE, MOVE, HEAL, HEAL, HEAL, HEAL], |
||||||
|
{room: room.name} |
||||||
|
] |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
tick (creep) { |
||||||
|
let room = Game.rooms[creep.memory.room] |
||||||
|
let targetRoomName = creep.memory.room |
||||||
|
if (creep.memory.room !== creep.pos.roomName |
||||||
|
&& (_.filter(Game.creeps, {memory: {role: 'healer', room: targetRoomName}, spawning: false}).length < Memory.rooms[targetRoomName].healer.targetCount |
||||||
|
|| _.filter(Game.creeps, {memory: {role: 'attacker', room: targetRoomName}, spawning: false}).length < Memory.rooms[targetRoomName].attacker.targetCount |
||||||
|
|| _.filter(Game.creeps, {memory: {role: 'rangedAttacker', room: targetRoomName}, spawning: false}).length < Memory.rooms[targetRoomName].rangedAttacker.targetCount) |
||||||
|
) { |
||||||
|
creep.moveTo(creep.pos.findClosestByPath(FIND_FLAGS, {filter: el => el.name.startsWith('gather'), visualizePathStyle: {stroke: '#0017ff'}})) |
||||||
|
return |
||||||
|
} |
||||||
|
if (!room || creep.memory.room !== creep.pos.roomName) { |
||||||
|
creep.moveTo(new RoomPosition(25, 25, creep.memory.room)) |
||||||
|
return |
||||||
|
} |
||||||
|
if (creep.pos.x <= 2) { |
||||||
|
creep.move(RIGHT) |
||||||
|
} else if (creep.pos.y <= 2) { |
||||||
|
creep.move(BOTTOM) |
||||||
|
} else if (creep.pos.x >= 47) { |
||||||
|
creep.move(LEFT) |
||||||
|
} else if (creep.pos.y >= 47) { |
||||||
|
creep.move(TOP) |
||||||
|
} |
||||||
|
|
||||||
|
let targetCreep |
||||||
|
if (creep.memory.lastTarget) { |
||||||
|
targetCreep = Game.getObjectById(creep.memory.lastTarget) |
||||||
|
} |
||||||
|
|
||||||
|
let closeAttackers = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 4, {filter: c => c.getActiveBodyparts(ATTACK) > 0 && c.pos.roomName === targetRoomName}) |
||||||
|
if (closeAttackers.length > 0) { |
||||||
|
creep.moveByPath(PathFinder.search(creep.pos, closeAttackers.map(el => {return {pos: el.pos, range: 3}}), {flee: true, maxRooms: 1}).path) |
||||||
|
} |
||||||
|
|
||||||
|
if (creep.hits < creep.hitsMax) { |
||||||
|
creep.heal(creep) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
let healTargets = creep.pos.findInRange(FIND_MY_CREEPS, 1, {filter: c => c.hits < c.hitsMax && c.pos.roomName === targetRoomName}) |
||||||
|
if (healTargets.length > 0) { |
||||||
|
creep.heal(healTargets[0]) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
let rangedHealTarget = creep.pos.findClosestByRange(FIND_MY_CREEPS, {filter: c => c.hits < c.hitsMax && c.pos.roomName === targetRoomName}) |
||||||
|
if (rangedHealTarget) { |
||||||
|
creep.rangedHeal(rangedHealTarget) |
||||||
|
creep.moveTo(rangedHealTarget, {visualizePathStyle: {stroke: '#00ff0f'}}) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
let possibleTarget = creep.pos.findClosestByPath(FIND_MY_CREEPS, {filter: c => creepIsAttacker(c) && c.pos.roomName === targetRoomName}) |
||||||
|
let range = creep.pos.getRangeTo(possibleTarget) |
||||||
|
if (range === 1) { |
||||||
|
creep.moveByPath(PathFinder.search(creep.pos, {pos: possibleTarget.pos, range: 2}, {flee: true, maxRooms: 1}).path) |
||||||
|
} |
||||||
|
else if (range > 3) { |
||||||
|
creep.moveTo(possibleTarget, {visualizePathStyle: {stroke: '#00ff0f'}}) |
||||||
|
} |
||||||
|
}, |
||||||
|
} |
@ -0,0 +1,90 @@ |
|||||||
|
module.exports = { |
||||||
|
name: 'rangedAttacker', |
||||||
|
prio: 10, |
||||||
|
tickInit () { |
||||||
|
for (let room of Object.values(Game.rooms)) { |
||||||
|
if (!room.memory.rangedAttacker) { |
||||||
|
room.memory.rangedAttacker = {} |
||||||
|
} |
||||||
|
if (room.find(FIND_STRUCTURES, {filter: s => s.structureType === STRUCTURE_TOWER}).length > 0) { |
||||||
|
room.memory.rangedAttacker.targetCount = 0 |
||||||
|
continue |
||||||
|
} |
||||||
|
room.memory.rangedAttacker.targetCount = Math.min(room.find(FIND_HOSTILE_CREEPS).length, 2) |
||||||
|
} |
||||||
|
}, |
||||||
|
nextSpawn (spawn, roleCreeps) { |
||||||
|
for (let [roomName, roomMemory] of Object.entries(Memory.rooms)) { |
||||||
|
if (_.filter(roleCreeps, {memory: {room: roomName}}).length < roomMemory.rangedAttacker.targetCount) { |
||||||
|
return [ |
||||||
|
[RANGED_ATTACK, MOVE, RANGED_ATTACK, MOVE, RANGED_ATTACK, MOVE, RANGED_ATTACK, MOVE, RANGED_ATTACK, MOVE], |
||||||
|
{room: roomName} |
||||||
|
] |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
tick (creep) { |
||||||
|
let room = Game.rooms[creep.memory.room] |
||||||
|
let targetRoomName = creep.memory.room |
||||||
|
if (creep.memory.colony === creep.pos.roomName |
||||||
|
&& (_.filter(Game.creeps, {memory: {role: 'healer', room: targetRoomName}, spawning: false}).length < Memory.rooms[targetRoomName].healer.targetCount |
||||||
|
|| _.filter(Game.creeps, {memory: {role: 'attacker', room: targetRoomName}, spawning: false}).length < Memory.rooms[targetRoomName].attacker.targetCount |
||||||
|
|| _.filter(Game.creeps, {memory: {role: 'rangedAttacker', room: targetRoomName}, spawning: false}).length < Memory.rooms[targetRoomName].rangedAttacker.targetCount) |
||||||
|
) { |
||||||
|
if (creep.ticksToLive < 1200) { |
||||||
|
creep.moveTo(creep.pos.findClosestByPath(FIND_MY_SPAWNS)) |
||||||
|
} else { |
||||||
|
creep.moveTo(creep.pos.findClosestByPath(FIND_FLAGS, { |
||||||
|
filter: el => el.name.startsWith('gather'), |
||||||
|
visualizePathStyle: {stroke: '#0017ff'} |
||||||
|
})) |
||||||
|
} |
||||||
|
return |
||||||
|
} |
||||||
|
if (!room || targetRoomName !== creep.pos.roomName) { |
||||||
|
creep.moveTo(new RoomPosition(25, 25, creep.memory.room)) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
if (creep.pos.x <= 2) { |
||||||
|
creep.move(RIGHT) |
||||||
|
} else if (creep.pos.y <= 2) { |
||||||
|
creep.move(BOTTOM) |
||||||
|
} else if (creep.pos.x >= 47) { |
||||||
|
creep.move(LEFT) |
||||||
|
} else if (creep.pos.y >= 47) { |
||||||
|
creep.move(TOP) |
||||||
|
} |
||||||
|
|
||||||
|
let targetCreep |
||||||
|
if (creep.memory.lastTarget) { |
||||||
|
targetCreep = Game.getObjectById(creep.memory.lastTarget) |
||||||
|
} |
||||||
|
|
||||||
|
let closeAttackers = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 3, {filter: c => creepIsAttacker(c)}) |
||||||
|
if (closeAttackers.length > 0) { |
||||||
|
creep.moveByPath(PathFinder.search(creep.pos, closeAttackers.map(el => {return {pos: el.pos, range: 2}}), {flee: true, maxRooms: 1}).path) |
||||||
|
targetCreep = closeAttackers[0] |
||||||
|
} |
||||||
|
|
||||||
|
if (!targetCreep) { |
||||||
|
targetCreep = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS, {filter: c => creepIsAttacker(c) || c.getActiveBodyparts(CARRY) >= 2}) |
||||||
|
} |
||||||
|
if (targetCreep) { |
||||||
|
let targetIsAttacker = creepIsAttacker(targetCreep) |
||||||
|
creep.memory.lastTarget = targetCreep.id |
||||||
|
let range = creep.pos.getRangeTo(targetCreep.pos) |
||||||
|
if (range <= 3) { |
||||||
|
creep.rangedAttack(targetCreep) |
||||||
|
} |
||||||
|
else { |
||||||
|
let driveByTargets = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 3, {filter: c => creepIsAttacker(c) || c.getActiveBodyparts(CARRY) >= 2}) |
||||||
|
if (driveByTargets.length > 0) { |
||||||
|
creep.rangedAttack(driveByTargets[0]) |
||||||
|
} |
||||||
|
} |
||||||
|
let distanceToKeep = targetIsAttacker ? 3 : 2 |
||||||
|
creep.moveByPath(PathFinder.search(creep.pos, [{pos: targetCreep.pos, range: distanceToKeep}], {maxRooms: 1, flee: range < distanceToKeep}).path) |
||||||
|
} |
||||||
|
}, |
||||||
|
} |
@ -0,0 +1,54 @@ |
|||||||
|
let common = require('common') |
||||||
|
|
||||||
|
module.exports = { |
||||||
|
name: 'remoteHarvester', |
||||||
|
prio: 10, |
||||||
|
bodies: [ |
||||||
|
[WORK, WORK, WORK, CARRY, MOVE, MOVE, MOVE, MOVE], |
||||||
|
[WORK, WORK, WORK, WORK, WORK, WORK, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE], |
||||||
|
[WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE], |
||||||
|
], |
||||||
|
tick (creep) { |
||||||
|
let dropped = creep.pos.findInRange(FIND_DROPPED_RESOURCES, 1); |
||||||
|
if (dropped.length > 0) { |
||||||
|
creep.pickup(dropped[0]) |
||||||
|
} |
||||||
|
|
||||||
|
let repairTargets = creep.pos.findInRange( |
||||||
|
FIND_STRUCTURES, |
||||||
|
3, |
||||||
|
{filter: s => s.structureType === STRUCTURE_CONTAINER && s.hits + creep.getActiveBodyparts(WORK) * 100 <= s.hitsMax}); |
||||||
|
if (repairTargets.length > 0) { |
||||||
|
if (creep.store[RESOURCE_ENERGY] >= creep.getActiveBodyparts(WORK) * 10 && creep.repair(repairTargets[0]) === OK) { |
||||||
|
return |
||||||
|
} |
||||||
|
} else { |
||||||
|
let targetCreeps = creep.pos.findInRange(FIND_MY_CREEPS, 1, { |
||||||
|
filter: tc => tc.store.getFreeCapacity(RESOURCE_ENERGY) && tc.memory.role !== 'remoteHarvester' |
||||||
|
}); |
||||||
|
if (targetCreeps.length > 0) { |
||||||
|
creep.transfer(targetCreeps[0], RESOURCE_ENERGY) |
||||||
|
} else { |
||||||
|
let targets = creep.pos.findInRange(FIND_STRUCTURES, 1, { |
||||||
|
filter: (structure) => structure.store && structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0 |
||||||
|
}); |
||||||
|
if (targets.length > 0) { |
||||||
|
creep.transfer(_.min(targets, el => el.store[RESOURCE_ENERGY]), RESOURCE_ENERGY) |
||||||
|
} else { |
||||||
|
if (creep.store[RESOURCE_ENERGY] >= creep.getActiveBodyparts(WORK) * 5) { |
||||||
|
let buildTargets = creep.pos.findInRange(FIND_MY_CONSTRUCTION_SITES, 1); |
||||||
|
if (buildTargets.length > 0 && creep.build(buildTargets[0]) === OK) { |
||||||
|
return |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
let target = Game.getObjectById(creep.memory.source) |
||||||
|
let actionResult = creep.harvest(target) |
||||||
|
if (actionResult === ERR_NOT_IN_RANGE) { |
||||||
|
creep.moveTo(target, {visualizePathStyle: {stroke: '#ffaa00'}}); |
||||||
|
} |
||||||
|
} |
||||||
|
}; |
@ -0,0 +1,31 @@ |
|||||||
|
module.exports = { |
||||||
|
name: 'reserver', |
||||||
|
prio: 20, |
||||||
|
nextSpawn (spawn, roleCreeps) { |
||||||
|
for (let roomName of activeRemotes) { |
||||||
|
let room = Game.rooms[roomName] |
||||||
|
if (!room) { |
||||||
|
continue |
||||||
|
} |
||||||
|
if (!room.controller.owner |
||||||
|
&& _.filter(roleCreeps, {memory: {room: roomName}}).length === 0 && ( |
||||||
|
!room.controller.reservation |
||||||
|
|| (room.controller.reservation.username === 'NativeException' && room.controller.reservation.ticksToEnd < 3000) |
||||||
|
)) { |
||||||
|
return [ |
||||||
|
[CLAIM, CLAIM, MOVE, MOVE], |
||||||
|
{room: roomName} |
||||||
|
] |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
tick (creep) { |
||||||
|
if (moveToRoom(creep, creep.memory.room) === MOVING) { |
||||||
|
return |
||||||
|
} |
||||||
|
let room = Game.rooms[creep.memory.room] |
||||||
|
if (creep.reserveController(room.controller) === ERR_NOT_IN_RANGE) { |
||||||
|
creep.moveTo(room.controller) |
||||||
|
} |
||||||
|
}, |
||||||
|
} |
@ -1,5 +1,30 @@ |
|||||||
module.exports = { |
module.exports = { |
||||||
|
name: 'scout', |
||||||
|
count: 1, |
||||||
|
prio: 15, |
||||||
|
bodies: [[MOVE]], |
||||||
|
nextSpawn (spawn, roleCreeps) { |
||||||
|
for (let roomName of activeRemotes) { |
||||||
|
if (!Game.rooms[roomName] && _.filter(roleCreeps, {memory: {room: roomName}}).length === 0) { |
||||||
|
return [ |
||||||
|
[MOVE], |
||||||
|
{room: roomName} |
||||||
|
] |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
tick (creep) { |
tick (creep) { |
||||||
|
let room = Game.rooms[creep.memory.room] |
||||||
|
if (!room) { |
||||||
|
for (let remoteRoom of activeRemotes) { |
||||||
|
if (!Game.rooms[remoteRoom]) { |
||||||
|
creep.memory.room = remoteRoom |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
let pos = new RoomPosition(25, 25, creep.memory.room) |
||||||
|
if (moveToRoom(creep, creep.memory.room) === ALREADY_IN_ROOM && creep.pos.getRangeTo(pos) > 10) { |
||||||
|
creep.moveByPath(PathFinder.search(creep.pos, {pos, range: 10}).path) |
||||||
} |
} |
||||||
|
}, |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue