Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var settings = {
- renew:[400,1200],
- status:{
- renewing:"♻ RENEW",
- harvesting:"⛏ HARVEST",
- delivering:"🛢 DELIVER",
- idle:"🛏 IDLE"
- },
- visualization:{
- "harvest": {visualizePathStyle: {stroke: '#ff0000'}},
- "idle": {visualizePathStyle: {stroke: '#ffff00'}},
- "deliver": {visualizePathStyle: {stroke: '#00ff00'}},
- "renew": {visualizePathStyle: {stroke: '#ff00ff'}}
- }
- }
- function setStatus(creep,status){
- if(creep.memory.status !== status){
- creep.memory.status = status;
- creep.say(settings.status[status]);
- }
- }
- module.exports = {
- run: function(creep){
- if(!creep.memory.status){
- creep.memory.status = "harvesting";
- }
- if(creep.memory.renew && creep.ticksToLive < settings.renew[0]){
- setStatus(creep,"renew");
- var target = creep.pos.findClosestByPath(FIND_MY_SPAWNS);
- if(target){
- creep.moveTo(target.pos, settings.visualization[creep.memory.status]);
- }
- if(creep.pos.isNearTo(target.pos)){
- if(creep.carry.energy > 0){
- creep.transfer(target.pos,RESOURCE_ENERGY)
- }
- }
- }
- if(creep.memory.status === "renew" && creep.ticksToLive < settings.renew[1]){
- return;
- } else if(creep.memory.status === "renew" && creep.ticksToLive >= settings.renew[1]){
- if(creep.memory.delivering){
- setStatus(creep, "delivering");
- } else {
- setStatus(creep, "harvesting");
- }
- }
- if(creep.carry.energy === 0){
- creep.memory.delivering = false;
- }
- if(!creep.memory.delivering){
- setStatus(creep,"harvesting");
- }
- if((creep.memory.status === "delivering" || creep.memory.status === "idle" || (!creep.memory.renew && creep.memory.status === "renew")) && creep.memory.delivering){
- var target = creep.pos.findClosestByPath(FIND_STRUCTURES,{
- filter: (structure)=>{
- return structure.my && ((structure.structureType === STRUCTURE_SPAWN && structure.energyCapacity > structure.energy) ||
- (structure.structureType === STRUCTURE_STORAGE && structure.storeCapacity > _.sum(container.store)) ||
- (structure.structureType === STRUCTURE_EXTENSION && structure.energyCapacity > structure.energy) ||
- (structure.structureType === STRUCTURE_CONTAINER && structure.storeCapacity > _.sum(container.store)))
- }
- });
- if(target){
- if(creep.transfer(target,RESOURCE_ENERGY) === ERR_NOT_IN_RANGE){
- creep.moveTo(target, settings.visualization[creep.memory.status]);
- }
- } else {
- setStatus(creep,"idle");
- creep.moveTo(25,25,settings.visualization[creep.memory.status]);
- }
- }
- if(creep.memory.status === "harvesting"){
- if(creep.carry.energy === creep.carryCapacity){
- setStatus(creep,"delivering");
- creep.memory.delivering = true;
- } else {
- var target = creep.pos.findClosestByPath(FIND_SOURCES,{
- filter:(source)=>{
- return source.energy > 0
- }
- });
- if(target){
- if(creep.harvest(target) === ERR_NOT_IN_RANGE){
- creep.moveTo(target,settings.visualization[creep.memory.status]);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment