Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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('base.unit.carrier');
- * mod.thing == 'a thing'; // true
- */
- exports.run = function (group ,roomname,config)
- {
- // get the group of creeps we need to controle
- var my_group = _.filter(Game.creeps, (creep) => creep.memory.GROUP == group && creep.memory.ROOM == roomname)
- var my_room = Game.rooms[roomname]
- var condision_ok = _.filter(my_group, (creep) => creep.ticksToLive > 30 )
- if (condision_ok.length < config[group])
- {
- if (condision_ok.length < 1 || my_room.energyCapacityAvailable <301)
- {
- console.log("harvester pannic")
- common.functions.roomspawns(roomname)[0].createCreep([WORK,WORK,MOVE,CARRY],{GROUP:group,ROOM : roomname})
- var newcreep = common.functions.roomspawns(roomname)[0].createCreep([WORK,WORK,WORK,WORK,MOVE,CARRY],{GROUP:group,ROOM : roomname})
- console.log(roomname+" 300-pannic "+newcreep+" "+common.functions.roomspawns(roomname)[0])
- } else {
- console.log(my_room.energyCapacityAvailable +" "+my_room.energyAvailable )
- if (my_room.energyCapacityAvailable >700)
- {
- console.log("700 "+common.functions.roomspawns(roomname)[0].createCreep([WORK,WORK,WORK,WORK,WORK,MOVE,MOVE,MOVE,CARRY],{GROUP:group,ROOM : roomname}))
- } else if (my_room.energyCapacityAvailable > 600){
- console.log("600 "+common.functions.roomspawns(roomname)[0].createCreep([WORK,WORK,WORK,WORK,WORK,MOVE,CARRY],{GROUP:group,ROOM : roomname}))
- } else if (my_room.energyCapacityAvailable > 500){
- var newcreep = common.functions.roomspawns(roomname)[0].createCreep([WORK,WORK,WORK,WORK,MOVE,CARRY],{GROUP:group,ROOM : roomname})
- console.log(roomname+" 500 "+newcreep+" "+common.functions.roomspawns(roomname)[0])
- } else if (my_room.energyCapacityAvailable > 400){
- var newcreep = common.functions.roomspawns(roomname)[0].createCreep([WORK,WORK,WORK,MOVE,CARRY],{GROUP:group,ROOM : roomname})
- console.log(roomname+" 400 "+newcreep)
- } else if (my_room.energyCapacityAvailable > 300){
- common.functions.roomspawns(roomname)[0].createCreep([WORK,WORK,MOVE,CARRY],{GROUP:group,ROOM : roomname})
- } else {
- }
- }
- }
- for (var ind in my_group)
- {
- var this_creep = my_group[ind]
- if (this_creep.memory.ACTION == undefined)
- {
- // we are doing nothing yet lets find crip
- var valid_sources =[]
- var sources = my_room.find(FIND_SOURCES)
- for (var s in sources )
- {
- var on_source= _.filter(Game.creeps, (creep) => creep.memory.GROUP == group && creep.memory.ROOM == roomname && creep.memory.DEST == sources[s].id)
- // if this source is alrdy taken
- if (on_source.length < 1)
- {
- // nope this just what we where looking for
- valid_sources.push(sources[s])
- }
- }
- console.log(">> "+on_source.length)
- if (valid_sources.length > 0)
- {
- target = this_creep.pos.findClosestByRange(valid_sources)
- //common.path.startpath(this_creep,target,{ACTION : "HARVEST", RESOURCE : RESOURCE_ENERGY})
- this_creep.memory.DEST = target.id
- this_creep.memory.ACTION = "MOVING"
- } else {
- this_creep.say("error")
- delete this_creep.memory.DEST
- delete this_creep.memory.ACTION
- }
- } else {
- var work_destination = Game.getObjectById(this_creep.memory.DEST)
- //console.log("move")
- if (this_creep.pos.getRangeTo(work_destination.pos) > 1)
- {
- this_creep.moveTo(work_destination)
- } else {
- //this_creep.say("X")
- if (this_creep.memory.ACTION == "MOVING")
- {
- this_creep.say("3")
- var build_containers =work_destination.pos.findInRange(FIND_CONSTRUCTION_SITES, 1);
- var containers = work_destination.room.find(FIND_STRUCTURES, {filter: (structure) => {return (structure.structureType == STRUCTURE_CONTAINER)}},1);
- containers =work_destination.pos.findInRange(containers, 1);
- if (containers.length > 0)
- {
- this_creep.say("1")
- containers = work_destination.pos.findInRange(containers, 1);
- if (this_creep.pos.getRangeTo(containers[0].pos) < 1)
- {
- this_creep.memory.ACTION = "MINING"
- this_creep.memory.container = container.id
- this_creep.say("1b")
- } else {
- this_creep.moveTo(containers[0])
- this_creep.say("1a")
- }
- } else if (build_containers.length >0 ) {
- this_creep.say("2")
- if (this_creep.carry.energy < 30)
- {
- this_creep.harvest(work_destination)
- } else {
- this_creep.build( this_creep.pos.findClosestByPath(build_containers ))
- }
- } else if (build_containers.length == 0) {
- this_creep.say("3")
- this_creep.pos.createConstructionSite(STRUCTURE_CONTAINER)
- } else {
- this_creep.say("4")
- }
- } else if (this_creep.memory.ACTION == "MINING") {
- var containers = work_destination.room.find(FIND_STRUCTURES, {filter: (structure) => {return (structure.structureType == STRUCTURE_CONTAINER)}}, 20);
- var container = this_creep.pos.findClosestByPath(containers )
- var total = _.sum(container.store)
- this_creep.say("t"+total)
- if (total < 2000)this_creep.harvest(work_destination)
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement