Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.run = function (group ,roomname,config)
- {
- var spawing_busy = false
- function flee (creep)
- {
- creep.moveTo (common.functions.roomspawns(creep.memory.ROOM )[0])
- }
- var opt = {reusePath : 10}
- var containers_dir = []
- var arival_dir ={}
- if (config[group].routes != undefined)
- {
- var routes = config[group].routes
- //console.log("routes "+routes)
- for (var t in routes)
- {
- var route_container
- var pos = routes[t].position
- var enable = routes[t].enable
- // do we have creeps running this?
- var my_group = _.filter(Game.creeps, (creep) => creep.memory.GROUP == group && creep.memory.ROOM == roomname && creep.memory.TASK == "harvester" && creep.memory.DEST == pos)
- // console.log(my_group.length+" "+pos+" "+enable)
- var my_group_expire = _.filter(my_group, (creep) => creep.memory.arival+30 < creep.ticksToLive || creep.memory.arival == undefined)
- //for (var ex in my_group_expire)
- //{
- // console.log("<h1>"+my_group_expire[ex]+" "+my_group_expire[ex].memory.arival +" "+my_group_expire[ex].ticksToLive+"</h1>")
- //}
- var my_room = Game.rooms[roomname]
- if (my_group_expire .length < 1 && enable > 0 && common.functions.cuttoff(config,roomname) > 0)
- {
- spawing_busy = true
- // spawn a unit
- // common.functions.roomspawns(roomname)[0].createCreep([WORK,MOVE,CARRY,CARRY],{GROUP:group, ROOM : roomname, TASK : "harvester", DEST : pos})
- 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, TASK : "harvester", DEST : pos}))
- } 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, TASK : "harvester", DEST : pos}))
- } else if (my_room.energyCapacityAvailable > 500){
- var newcreep = common.functions.roomspawns(roomname)[0].createCreep([WORK,WORK,WORK,WORK,MOVE,CARRY],{GROUP:group, ROOM : roomname, TASK : "harvester", DEST : pos})
- 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, TASK : "harvester", DEST : pos})
- 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, TASK : "harvester", DEST : pos})
- } else {
- }
- console.log("spawning harvester for route "+routes[t])
- }
- if (my_group.length > 0)
- {
- for (var o in my_group)
- {
- var this_creep = my_group[o]
- if (external_hostiles[this_creep.pos.roomName] != undefined || this_creep.hits < this_creep.hitsMax)
- {
- console.log("HOSTILE!!!!!! FLEEiNG")
- flee (this_creep)
- } else {
- var s = this_creep.memory.DEST.split(" ")
- var p = new RoomPosition(s[0],s[1],s[2]);
- //console.log(this_creep.memory.POS+" "+p)
- if (this_creep.pos.getRangeTo(p) > 1)
- {
- this_creep.say("1")
- this_creep.moveTo(p)
- } else {
- delete this_creep.memory.path
- if (this_creep.memory.arival == undefined)
- {
- this_creep.memory.arival = 1500 - this_creep.ticksToLive
- }
- var source = this_creep.room.find(FIND_SOURCES)
- source = this_creep.pos.findClosestByRange(source)
- var container = this_creep.room.find(FIND_STRUCTURES, {filter: (structure) => {return (structure.structureType == STRUCTURE_CONTAINER)}})
- container = source.pos.findInRange(container, 2);
- if (container.length < 1)
- {
- container = this_creep.pos.findClosestByRange(container)
- this_creep.say("3")
- var build_containers =source.pos.findInRange(FIND_CONSTRUCTION_SITES, 1);
- if (build_containers.length < 1)
- {
- this_creep.say("3a")
- this_creep.pos.createConstructionSite(STRUCTURE_CONTAINER)
- } else {
- this_creep.say("3b")
- this_creep.build(build_containers[0])
- this_creep.harvest(source)
- }
- } else {
- this_creep.say("2")
- container = this_creep.pos.findClosestByRange(container)
- var energy = container.store[RESOURCE_ENERGY]
- if (this_creep.pos.getRangeTo(container.pos) > 0)
- {
- this_creep.moveTo(container)
- }
- if (energy < 2000 && this_creep.pos.getRangeTo(container.pos) < 1)
- {
- this_creep.harvest(source)
- }
- // there is a container now
- if (container.hits < 200000)
- {
- if (this_creep.carry.energy < 25)
- { this_creep.harvest(source)
- } else {
- this_creep.repair(container)
- }
- }
- this_creep.say(energy)
- //add object to the container directory
- if (container != undefined)
- {
- containers_dir.push(container)
- // arival_dir[container.id] = this_creep.memory.arival
- }
- if (this_creep.memory.CONTAINER == undefined)
- {
- this_creep.memory.CONTAINER = container.id
- }
- route_container = container
- }
- }}
- }
- }
- // this is the end of the route deal
- // console.log ("run the carriers for "+pos )
- var my_carrier_group = _.filter(Game.creeps, (creep) => creep.memory.GROUP == group && creep.memory.ROOM == roomname && creep.memory.TASK == "carrier" && creep.memory.ROUTE == pos)
- // find the config of this set.
- if ( route_container != undefined && my_carrier_group < routes[t].carriers && routes[t].enable > 0 && spawing_busy == false && route_container.store.energy > 1000)
- {
- var arg = {ROUTE :pos, GROUP:group, ROOM : roomname, TASK : "carrier"}
- if (my_room.energyCapacityAvailable >1750)
- {
- common.functions.roomspawns(roomname)[0].createCreep([CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,WORK],arg)
- } else if (my_room.energyCapacityAvailable > 1450){
- common.functions.roomspawns(roomname)[0].createCreep([CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,WORK],arg)
- } else if (my_room.energyCapacityAvailable > 1050){
- common.functions.roomspawns(roomname)[0].createCreep([CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,WORK],arg)
- } else if (my_room.energyCapacityAvailable > 900){
- common.functions.roomspawns(roomname)[0].createCreep([CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,WORK],arg)
- } else if (my_room.energyCapacityAvailable > 800){
- common.functions.roomspawns(roomname)[0].createCreep([CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,WORK],arg)
- } else if (my_room.energyCapacityAvailable > 700){
- common.functions.roomspawns(roomname)[0].createCreep([CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,WORK],arg)
- } else if (my_room.energyCapacityAvailable > 600){
- common.functions.roomspawns(roomname)[0].createCreep([CARRY,CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE,MOVE,WORK],arg)
- } else if (my_room.energyCapacityAvailable > 500){
- common.functions.roomspawns(roomname)[0].createCreep([CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE,WORK],arg)
- } else if (my_room.energyCapacityAvailable > 400){
- common.functions.roomspawns(roomname)[0].createCreep([CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,WORK],arg)
- } else if (my_room.energyCapacityAvailable > 300){
- common.functions.roomspawns(roomname)[0].createCreep([CARRY,CARRY,MOVE,MOVE,WORK],arg)
- } else {
- }
- }
- if (my_carrier_group.length>0)
- {
- for (var tt in my_carrier_group)
- {
- var this_creep = my_carrier_group[tt]
- this_creep.say("1")
- if (external_hostiles[this_creep.pos.roomName] != undefined || this_creep.hits < this_creep.hitsMax)
- {
- console.log("HOSTILE!!!!!! FLEEiNG")
- flee (this_creep)
- } else {
- //delete this_creep.memory.roundtrip
- if (this_creep.memory.ACTION == undefined)
- {
- this_creep.memory.ACTION = "LOAD"
- }
- if (this_creep.memory.ACTION == "LOAD")
- {
- if (route_container == undefined)
- {
- var s = this_creep.memory.ROUTE.split(" ")
- var p = new RoomPosition(s[0],s[1],s[2]);
- route_container = p
- if (this_creep.pos.getRangeTo(route_container) < 3)
- {
- route_container = p.findInRange(FIND_STRUCTURES,3);
- route_container = _.filter(route_container, (structure) => structure.structureType == STRUCTURE_CONTAINER)
- route_container = route_container[0]
- }
- }
- if (this_creep.pos.getRangeTo(route_container) > 1)
- {
- this_creep.say("1")
- this_creep.say(this_creep.moveTo(route_container))
- } else {
- this_creep.repair(route_container)
- if (this_creep.pos.getRangeTo(route_container) > 1)
- {
- this_creep.say(this_creep.moveTo(route_container))
- } else {
- this_creep.withdraw(route_container,RESOURCE_ENERGY)
- }
- if (this_creep.carry.energy >this_creep.carryCapacity-2)
- {
- this_creep.memory.ACTION = "UNLOAD"
- }
- }
- }
- if (this_creep.memory.ACTION == "UNLOAD")
- {
- //console.log(config[group].dropoff)
- this_creep.say("u")
- var work_destination = Game.getObjectById(config[group].dropoff)
- if (this_creep.pos.getRangeTo(work_destination.pos) > 1)
- {
- this_creep.moveTo(work_destination,opt)
- //var build_road = this_creep.room.find(FIND_CONSTRUCTION_SITES);
- var build_road = this_creep.pos.findInRange(FIND_CONSTRUCTION_SITES, 3);
- if (build_road.length < 1)
- {
- // repair
- var roads = this_creep.pos.findInRange(FIND_STRUCTURES,3);
- var roads = _.filter(roads, (structure) => (structure.hits / structure.hitsMax) < 0.8)
- //roads = this_creep.pos.findInRange(roads, 3);
- //roads = this_creep.pos.findClosestByPath(roads)
- this_creep.say("R: "+this_creep.repair(roads[0]))
- this_creep.say("R: "+roads)
- //this_creep.say(roads)
- if (this_creep.carry.energy == 0)
- {
- this_creep.memory.ACTION = "LOAD"
- }
- } else {
- // var constroad = this_creep.pos.findClosestByPath(build_road )
- this_creep.build(build_road[0])
- }
- } else {
- if (this_creep.memory.roundtrip == undefined)
- {
- this_creep.memory.roundtrip = 1500 - this_creep.ticksToLive
- }
- this_creep.transfer(work_destination,RESOURCE_ENERGY)
- if (this_creep.carry.energy == 0)
- {
- if (this_creep.memory.roundtrip+10 > this_creep.ticksToLive)
- {
- this_creep.memory.ACTION = "recycle"
- } else {
- this_creep.memory.ACTION = "LOAD"
- }
- //console.log("<h2>age of creep "+this_creep.ticksToLive+" "+arival_dir[this_creep.memory.DEST]+" "+(arival_dir[this_creep.memory.DEST]*2)+" "+this_creep.memory.DEST+" "+"</h2>")
- }
- }
- }
- if (this_creep.memory.ACTION == "recycle")
- {
- var spawn = common.functions.roomspawns(roomname)[0]
- if (this_creep.pos.getRangeTo(spawn.pos) > 1)
- {
- this_creep.moveTo(spawn)
- this_creep.say("recycle")
- } else {
- spawn.recycleCreep(this_creep)
- }
- }}
- }
- }
- //console.log(cc+" "+containers_dir[cc].id+" "+containers_dir[cc].store.energy)
- //if (containers_dir[cc].store.energy > 500)
- //{
- //}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement