Created
August 6, 2016 16:21
-
-
Save rDarge/efc5bb5d184c932f2b16867617f0ce2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Behavior for the harvesters: | |
/* | |
* Module code goes here. Use 'module.exports' to export things: | |
* module.exports.thing = 'a thing'; | |
* | |
* You can import it from another modules like this: | |
* var mod = require('role.pickup.source'); | |
* mod.thing == 'a thing'; // true | |
*/ | |
var pickupSource = { | |
pickup: function(creep) { | |
if(!creep.memory.pickupSource) { | |
console.log("Creep " + creep.name + creep.memory.role +" not properly configured to use pickupSource behavior!"); | |
return ERR_INVALID_TARGET; | |
} | |
var sourceId = creep.memory.pickupSource; | |
var source = Game.getObjectById(sourceId); | |
if(source == null) { | |
//Short circuit here to move to the appropriate room that we haven't been to yet | |
creep.moveTo(new RoomPosition(25, 25, creep.memory.pickupRoom), {ignoreCreeps: false}); | |
return; | |
} | |
var container = false; | |
if(source.pos.roomName == creep.pos.roomName) { | |
container = creep.room.lookForAtArea(LOOK_STRUCTURES, source.pos.y-1, source.pos.x-1, source.pos.y+1, source.pos.x+1, true) | |
.filter((container)=>container.structure.structureType == 'container'); | |
} | |
if(container.length > 0) { | |
container = container[0].structure; | |
} else { | |
container = false; | |
} | |
if(container && (creep.pos.x != container.pos.x || creep.pos.y != container.pos.y)) { | |
creep.moveTo(container, {ignoreCreeps: false}); | |
} else { | |
creep.moveTo(source, {ignoreCreeps: false}); | |
} | |
result = creep.harvest(source); | |
if(result == OK && Game.time % 2 == 0) { | |
creep.say("Yum!"); | |
} | |
} | |
} | |
//Behavior for the pickup part of the haulers | |
/* | |
* Module code goes here. Use 'module.exports' to export things: | |
* module.exports.thing = 'a thing'; | |
* | |
* You can import it from another modules like this: | |
* var mod = require('role.pickup.structure'); | |
* mod.thing == 'a thing'; // true | |
*/ | |
var pickupStructure = { | |
pickup: function(creep) { | |
if(!creep.memory.pickupStructure) { | |
console.log("Creep " + creep.name + " not properly configured to use pickupStructure behavior!"); | |
return ERR_INVALID_TARGET; | |
} | |
var structureId = creep.memory.pickupStructure; | |
var structure = Game.getObjectById(structureId); | |
if(structure == null) { | |
//Short circuit here to move to the appropriate room that we haven't been to yet | |
creep.moveTo(new RoomPosition(25, 25, creep.memory.pickupRoom), {ignoreCreeps: false}); | |
return; | |
} | |
creep.pickup(creep.room.lookForAt(RESOURCE_ENERGY,structure.pos)[0]); | |
if(creep.withdraw(structure, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE){ | |
creep.moveTo(structure, {ignoreCreeps: false}); | |
} | |
} | |
} | |
module.exports = pickupStructure; | |
//behavior for the deposit part of the haulers | |
/* | |
* Module code goes here. Use 'module.exports' to export things: | |
* module.exports.thing = 'a thing'; | |
* | |
* You can import it from another modules like this: | |
* var mod = require('role.deposit.structure'); | |
* mod.thing == 'a thing'; // true | |
*/ | |
var depositStructure = { | |
deposit: function(creep) { | |
creep.say("dst"); | |
if(!creep.memory.depositStructure) { | |
console.log("Creep " + creep.name + creep.memory.role +" not properly configured to use depositStructure behavior!"); | |
return ERR_INVALID_TARGET; | |
} | |
var targets = false; | |
var targetIds = creep.memory.depositStructure.split(","); | |
if(targetIds) { | |
targets = targetIds.map((id) => Game.getObjectById(id)); | |
// target = Game.getObjectById(targetId); | |
} | |
//Transfer type logic: | |
resourceType = RESOURCE_ENERGY; | |
if(creep.memory.resourceType) { | |
resourceType = creep.memory.resourceType; | |
} | |
var index = 0; | |
var target = targets[index]; | |
if(target.pos.roomName != creep.pos.roomName) { | |
creep.moveTo(target); | |
} else if(target) { | |
// creep.moveTo(target); | |
// console.log(creep.name + Object.keys(target)); | |
result = -1; | |
while(result != OK && result != ERR_NOT_IN_RANGE && index < targets.length){ | |
target = targets[index++]; | |
result = result = creep.transfer(target, resourceType); | |
} | |
// console.log(creep.name + result + " and " + resourceType + RESOURCE_ZYNTHIUM); | |
if(result == ERR_NOT_IN_RANGE) { | |
creep.moveTo(target); | |
} else if (result == OK) { | |
return true; | |
} | |
} | |
return false; | |
}, | |
name: "depositStructure" | |
} | |
module.exports = depositStructure; | |
module.exports = pickupSource; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment