mirror of
https://github.com/paradizelost/screeps.git
synced 2024-11-25 02:14:44 -06:00
get market working for all mineral types
This commit is contained in:
parent
d314f52c66
commit
3e73445a76
@ -2,7 +2,7 @@ let Phase1 = {
|
|||||||
run: function(room) {
|
run: function(room) {
|
||||||
let myroom=Game.rooms[room]
|
let myroom=Game.rooms[room]
|
||||||
require('assignsources').tick(room)
|
require('assignsources').tick(room)
|
||||||
if(Game.time % 1 === 0){
|
if(Game.time % 10 === 0){
|
||||||
//console.log('processing spawn')
|
//console.log('processing spawn')
|
||||||
|
|
||||||
let myspawns = myroom.find(FIND_MY_SPAWNS)
|
let myspawns = myroom.find(FIND_MY_SPAWNS)
|
||||||
@ -45,26 +45,64 @@ let Phase1 = {
|
|||||||
console.log("Spawning Mover in " + room)
|
console.log("Spawning Mover in " + room)
|
||||||
require('proc.spawning').spawnmover(room)
|
require('proc.spawning').spawnmover(room)
|
||||||
}
|
}
|
||||||
|
if((myroom.storage || myroom.terminal) && (creepcounts["mineralmover"] < 1 || creepcounts["mineralmover"]==undefined)){
|
||||||
|
console.log("Spawning MineralMover in " + room)
|
||||||
|
require('proc.spawning').spawnmineralmover(room)
|
||||||
|
}
|
||||||
if((myroom.find(FIND_MY_STRUCTURES, {filter: {structureType: STRUCTURE_EXTRACTOR}}).length > 0)&&(creepcounts["miner"] < myroom.memory.mineralminablepositions || creepcounts["miner"]==undefined)&&(myroom.energyAvailable >= myroom.energyCapacityAvailable)){
|
if((myroom.find(FIND_MY_STRUCTURES, {filter: {structureType: STRUCTURE_EXTRACTOR}}).length > 0)&&(creepcounts["miner"] < myroom.memory.mineralminablepositions || creepcounts["miner"]==undefined)&&(myroom.energyAvailable >= myroom.energyCapacityAvailable)){
|
||||||
if(myroom.find(FIND_MINERALS)[0].ticksToRegeneration == undefined || myroom.find(FIND_MINERALS)[0].ticksToRegeneration < 1000 ){
|
if(myroom.find(FIND_MINERALS)[0].ticksToRegeneration == undefined || myroom.find(FIND_MINERALS)[0].ticksToRegeneration < 1000 ){
|
||||||
console.log("Spawning Miner in " + room)
|
console.log("Spawning Miner in " + room)
|
||||||
require('proc.spawning').spawnminer(room)
|
require('proc.spawning').spawnminer(room)
|
||||||
} else { if(Game.flags.debug && Game.flags.debug.room == myroom){console.log("Not spawning miner in " + room + ", waiting for regen")}}
|
} else { if(Game.flags.debug && Game.flags.debug.room == myroom){console.log("Not spawning miner in " + room + ", waiting for regen")}}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(Game.time % 4 === 0){
|
||||||
if(myroom.find(FIND_MY_STRUCTURES, {filter: {structureType: STRUCTURE_TERMINAL}}).length > 0){
|
if(myroom.find(FIND_MY_STRUCTURES, {filter: {structureType: STRUCTURE_TERMINAL}}).length > 0){
|
||||||
console.log("starting market check for room " + room)
|
//console.log("starting market check for room " + room)
|
||||||
try{
|
try{
|
||||||
let availtosell = myroom.terminal.store.getUsedCapacity([RESOURCE_ENERGY]) - 200000
|
if(myroom.terminal){
|
||||||
if(availtosell > 1000){
|
///console.log("1")
|
||||||
require('proc.market').sellEnergy(room)
|
if(myroom.terminal.store.getUsedCapacity() == 0) {
|
||||||
|
//console.log("terminal is empty")
|
||||||
|
}else{
|
||||||
|
if(myroom.terminal.store.getUsedCapacity('energy') > 10000){
|
||||||
|
console.log("Starting market loop for "+ myroom)
|
||||||
|
for(mat in myroom.terminal.store){
|
||||||
|
let availtosell=0
|
||||||
|
//console.log(mat)
|
||||||
|
if(mat == 'energy'){
|
||||||
|
try{
|
||||||
|
availtosell = myroom.terminal.store.getUsedCapacity(mat) - 200000
|
||||||
|
} catch {
|
||||||
|
//console.log("error getting energy")
|
||||||
|
availtosell=0
|
||||||
}
|
}
|
||||||
}catch{
|
} else {
|
||||||
|
try{
|
||||||
|
//console.log("2")
|
||||||
|
availtosell = myroom.terminal.store.getUsedCapacity(mat)
|
||||||
|
} catch {
|
||||||
|
//console.log("Couldn't get available " + mat)
|
||||||
|
availtosell=0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(availtosell){
|
||||||
|
//console.log(availtosell)
|
||||||
|
if(availtosell > 20000){
|
||||||
|
//console.log("processing market")
|
||||||
|
require('proc.market').sellEnergy(room,mat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch(e){
|
||||||
console.log("Myroom" + myroom)
|
console.log("Myroom" + myroom)
|
||||||
console.log("Room" + room)
|
console.log(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//require('proc.market').sellEnergy(room)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(myroom.controller.level>2){ }
|
if(myroom.controller.level>2){ }
|
||||||
}
|
}
|
||||||
|
@ -7,18 +7,18 @@
|
|||||||
* mod.thing == 'a thing'; // true
|
* mod.thing == 'a thing'; // true
|
||||||
*/
|
*/
|
||||||
let gomarket={
|
let gomarket={
|
||||||
sellEnergy: function(myroom) {
|
sellEnergy: function(myroom,mat) {
|
||||||
try{
|
try{
|
||||||
let availtosell= Game.rooms[myroom].terminal.storage[RESOURCE_ENERGY]
|
let availtosell= Game.rooms[myroom].terminal.store.getUsedCapacity(mat)
|
||||||
|
if(availtosell>0){
|
||||||
if(availtosell>200000){
|
console.log(myroom + ":" + mat +":" + availtosell)
|
||||||
console.log(myroom + ":" + availtosell)
|
|
||||||
//console.log(JSON.stringify(Game.market.orders))
|
//console.log(JSON.stringify(Game.market.orders))
|
||||||
// if(Game.market.orders.length > 9){
|
// if(Game.market.orders.length > 9){
|
||||||
let myorders = Game.market.getAllOrders(order=>order.resourceType == RESOURCE_ENERGY && order.type == ORDER_BUY)
|
let myorders = Game.market.getAllOrders(order=>order.resourceType == mat && order.type == ORDER_BUY)
|
||||||
|
//console.log("Open orders: " + myorders.length)
|
||||||
//console.log(myorders.length)
|
//console.log(myorders.length)
|
||||||
for(let i=0; i<myorders.length; i++){
|
for(let i=0; i<myorders.length; i++){
|
||||||
let recheckavailtosell= Game.rooms[myroom].terminal.storage[RESOURCE_ENERGY]
|
let recheckavailtosell= Game.rooms[myroom].terminal.store.getUsedCapacity(mat)
|
||||||
if(recheckavailtosell<1000){
|
if(recheckavailtosell<1000){
|
||||||
console.log("too little to mess with")
|
console.log("too little to mess with")
|
||||||
} else {
|
} else {
|
||||||
@ -30,9 +30,21 @@ let gomarket={
|
|||||||
} else {
|
} else {
|
||||||
amttosell=myorders[i].amount
|
amttosell=myorders[i].amount
|
||||||
}
|
}
|
||||||
console.log( myroom + " trying to sell " + amttosell + " Energy on order size of " + myorders[i].amount + " with " + recheckavailtosell + " left")
|
console.log( myroom + " trying to sell " + amttosell + " " + mat + " on order size of " + myorders[i].amount + " with " + recheckavailtosell + " left and " + myorders.length + " orders open")
|
||||||
let mydeal = Game.market.deal(myorders[i].id, amttosell, myroom);
|
let mydeal = Game.market.deal(myorders[i].id, amttosell, myroom);
|
||||||
|
if(mydeal == 0){
|
||||||
|
console.log("Order Created")
|
||||||
|
} else if(mydeal==-6){
|
||||||
|
console.log("not enouhg resources")
|
||||||
|
} else if(mydeal == -8){
|
||||||
|
console.log("too many orders")
|
||||||
|
} else if (mydeal == -10){
|
||||||
|
console.log("Invalid arguments")
|
||||||
|
} else if (mydeal==-11){
|
||||||
|
console.log("terminal cooling down")
|
||||||
|
} else {
|
||||||
console.log(mydeal)
|
console.log(mydeal)
|
||||||
|
}
|
||||||
//} else {
|
//} else {
|
||||||
// console.log("Too expensive")
|
// console.log("Too expensive")
|
||||||
//}
|
//}
|
||||||
|
@ -124,6 +124,33 @@ let buildparts = {
|
|||||||
let newcreep = spawn.createCreep(tobuild,CreepName,{spawnedat: Game.time,role:"mover"})
|
let newcreep = spawn.createCreep(tobuild,CreepName,{spawnedat: Game.time,role:"mover"})
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
},
|
||||||
|
spawnmineralmover: function(roomname) {
|
||||||
|
let myspawns=Game.rooms[roomname].find(FIND_MY_SPAWNS)
|
||||||
|
Game.rooms[roomname].memory.CreepNum++
|
||||||
|
let CreepName = 'MineralMover_' + roomname + "_" + (Game.rooms[roomname].memory.CreepNum)
|
||||||
|
for(let spawn of myspawns){
|
||||||
|
if(!spawn.spawning){
|
||||||
|
for(let totry of [
|
||||||
|
[MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY],//MOVE*6,WORK*5,CARRY*7
|
||||||
|
[MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY],// all * 5
|
||||||
|
[MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY],//move*5, work*4, carry*5
|
||||||
|
[MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY],//move*4,work*4,carry*4
|
||||||
|
[MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY],//move*4, work*3, carry*4
|
||||||
|
[MOVE,CARRY,CARRY,MOVE,CARRY,CARRY,MOVE,CARRY], //move*3,work*2, carry*3
|
||||||
|
[MOVE,CARRY,CARRY,MOVE,CARRY,CARRY], //move*2, work*2, carry*2
|
||||||
|
[MOVE,CARRY,CARRY,MOVE,CARRY],//move*2, work*1, carry*2
|
||||||
|
[MOVE,CARRY,CARRY]
|
||||||
|
]){
|
||||||
|
let ispossible = spawn.canCreateCreep(totry)
|
||||||
|
if(ispossible==OK){
|
||||||
|
tobuild=totry
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let newcreep = spawn.createCreep(tobuild,CreepName,{spawnedat: Game.time,role:"mineralmover"})
|
||||||
|
}}
|
||||||
|
|
||||||
},
|
},
|
||||||
spawnnrworker: function(roomname) {
|
spawnnrworker: function(roomname) {
|
||||||
console.log('1')
|
console.log('1')
|
||||||
|
@ -32,7 +32,7 @@ let roleMiner = {
|
|||||||
creep.moveTo(spawn);
|
creep.moveTo(spawn);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_TERMINAL || s.structureType == STRUCTURE_FACTORY ) && _.sum(s.store) < s.storeCapacity) ;}});
|
let storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_TERMINAL || s.structureType == STRUCTURE_FACTORY ) && _.sum(s.store) < s.storeCapacity) ;}});
|
||||||
if(storagetargets){
|
if(storagetargets){
|
||||||
if(this.transferAll(creep,storagetargets) == ERR_NOT_IN_RANGE) {
|
if(this.transferAll(creep,storagetargets) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(storagetargets,{ignoreCreeps:ignorecreeps})
|
creep.moveTo(storagetargets,{ignoreCreeps:ignorecreeps})
|
||||||
|
132
role.mineralmover.js
Normal file
132
role.mineralmover.js
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
let mover={
|
||||||
|
run: function(creep) {
|
||||||
|
//creep.say("Moving Minerals")
|
||||||
|
let ignorecreeps=true
|
||||||
|
if(creep.memory.lastpos==undefined || creep.memory.timeatpos==undefined){
|
||||||
|
creep.memory.lastpos = creep.pos
|
||||||
|
creep.memory.timeatpos = 0
|
||||||
|
}
|
||||||
|
if(creep.memory.working==undefined){
|
||||||
|
creep.memory.working=false
|
||||||
|
}
|
||||||
|
let lastpos = _.create(RoomPosition.prototype, creep.memory.lastpos)
|
||||||
|
if(creep.pos.isEqualTo(lastpos)){
|
||||||
|
creep.memory.timeatpos = creep.memory.timeatpos+1
|
||||||
|
if(creep.memory.timeatpos>2){
|
||||||
|
//console.log(creep.name + " " + creep.memory.timeatpos)
|
||||||
|
ignorecreeps=false
|
||||||
|
} else { }
|
||||||
|
} else { creep.memory.timeatpos=0}
|
||||||
|
let filllevel = _.sum(creep.carry)
|
||||||
|
if(creep.memory.working && filllevel == 0) {
|
||||||
|
creep.memory.working = false;
|
||||||
|
creep.say('Gathering');
|
||||||
|
}
|
||||||
|
if(!creep.memory.working && filllevel == creep.carryCapacity) {
|
||||||
|
creep.memory.working = true;
|
||||||
|
creep.say('working');
|
||||||
|
}
|
||||||
|
if(creep.memory.working){
|
||||||
|
let terminaltarget = creep.room.terminal
|
||||||
|
if(creep.room.terminal){
|
||||||
|
if(terminaltarget.store.getUsedCapacity()<200000){
|
||||||
|
if(this.transferAll(creep,terminaltarget) == ERR_NOT_IN_RANGE) {
|
||||||
|
creep.moveTo(terminaltarget,{ignoreCreeps:ignorecreeps})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ((creep.ticksToLive < 300 || creep.ticksToLive <= creep.memory.renewto) && (Game.rooms[creep.room.name].find(FIND_MY_SPAWNS, {filter: (r) =>{return ( r.store[RESOURCE_ENERGY]>200)}})) ) {
|
||||||
|
if(creep.memory.renewto == undefined){
|
||||||
|
creep.memory.renewto = 1200
|
||||||
|
} else {
|
||||||
|
if(creep.ticksToLive >= creep.memory.renewto){
|
||||||
|
delete creep.memory.renewto
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//console.log(creep.name + ": " + creep.ticksToLive + " " + creep.memory.renewto)
|
||||||
|
creep.say('renewing')
|
||||||
|
let spawn = creep.pos.findClosestByRange(FIND_MY_SPAWNS)
|
||||||
|
if(spawn.renewCreep(creep) == ERR_NOT_IN_RANGE)
|
||||||
|
{
|
||||||
|
creep.moveTo(spawn);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(filllevel < creep.carryCapacity){
|
||||||
|
/*
|
||||||
|
let nearestcontainer = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_CONTAINER ) && s.store.getUsedCapacity('energy') >= 10) ;}});
|
||||||
|
if(creep.room.terminal){
|
||||||
|
let terminal = creep.room.terminal
|
||||||
|
let terminalenergy= terminal.store.getUsedCapacity('energy')
|
||||||
|
}
|
||||||
|
if(creep.room.storage){
|
||||||
|
let storage = creep.room.storage
|
||||||
|
let storageenergy=storage.store.getUsedCapacity('energy')
|
||||||
|
}
|
||||||
|
//console.log("Storage: " + storage.store.getUsedCapacity('energy'))
|
||||||
|
//console.log("Container: " + nearestcontainer.store.getUsedCapacity('energy')
|
||||||
|
try{
|
||||||
|
if(nearestcontainer == null){
|
||||||
|
|
||||||
|
}else {
|
||||||
|
storagetarget = nearestcontainer
|
||||||
|
}
|
||||||
|
}catch{
|
||||||
|
if(storageenergy > 0){
|
||||||
|
storagetarget = storage
|
||||||
|
} else if ( terminalenergy > 0) {
|
||||||
|
storagetarget = terminal
|
||||||
|
} else {
|
||||||
|
console.log("we're out of energy!")
|
||||||
|
storagetarget=storage
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
let storagetarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_CONTAINER ) && (s.store.getUsedCapacity() > s.store.getUsedCapacity('energy') || s.store.getUsedCapacity('energy') > 200000)) ;}});
|
||||||
|
let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: (r) =>{return ( r.resourceType==RESOURCE_ENERGY&& r.amount>10)}});
|
||||||
|
let tombstone = creep.pos.findClosestByRange(FIND_TOMBSTONES, {filter: (r) =>{return ( r.store[RESOURCE_ENERGY]>200)}});
|
||||||
|
if((droppedenergy == undefined) && (tombstone==undefined)){
|
||||||
|
try{
|
||||||
|
// console.log(storagetarget.store.getUsedCapacity('energy')/storagetarget.store.getCapacity())
|
||||||
|
if(storagetarget.store.getUsedCapacity('energy')< 1000 && (storagetarget.store.getUsedCapacity('energy')/storagetarget.store.getCapacity() < .5 )){
|
||||||
|
//console.log("too much crap")
|
||||||
|
//console.log(storagetarget.store.getUsedCapacity())
|
||||||
|
//creep.travelTo(storagetarget);
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
//console.log("oops" + e)
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
for(mat in storagetarget.store){
|
||||||
|
if(mat=='energy' && storagetarget.store.getUsedCapacity('energy') > 200000){
|
||||||
|
if(creep.withdraw(storagetarget,mat)== ERR_NOT_IN_RANGE) {
|
||||||
|
creep.say('Getting ' + mat )
|
||||||
|
creep.travelTo(storagetarget);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(creep.withdraw(storagetarget,mat)== ERR_NOT_IN_RANGE) {
|
||||||
|
creep.say('Getting ' + mat )
|
||||||
|
creep.travelTo(storagetarget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e){
|
||||||
|
//console.log(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!storagetarget && (creep.carry > 0)){
|
||||||
|
creep.memory.working=true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
creep.memory.lastpos=creep.pos
|
||||||
|
},
|
||||||
|
transferAll: function(creep,targetStorage){
|
||||||
|
let result = 0;
|
||||||
|
for(mat in creep.store)
|
||||||
|
{
|
||||||
|
let tempResult = creep.transfer(targetStorage,mat);
|
||||||
|
if(tempResult !== ERR_INVALID_ARGS) {result = tempResult;}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
module.exports = mover;
|
@ -26,16 +26,18 @@ let mover={
|
|||||||
creep.say('working');
|
creep.say('working');
|
||||||
}
|
}
|
||||||
if(creep.memory.working){
|
if(creep.memory.working){
|
||||||
let terminaltarget = creep.room.terminal
|
//let terminaltarget = creep.room.terminal
|
||||||
if(creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ((([STRUCTURE_SPAWN, STRUCTURE_EXTENSION, STRUCTURE_TOWER, STRUCTURE_LAB].includes(s.structureType)) && s.energy < s.energyCapacity))}})){
|
let spawntarget = creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ((([STRUCTURE_SPAWN, STRUCTURE_EXTENSION, STRUCTURE_TOWER, STRUCTURE_LAB].includes(s.structureType)) && s.energy < s.energyCapacity))}})
|
||||||
let spawntarget = creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return (((s.structureType == STRUCTURE_EXTENSION || s.structureType == STRUCTURE_SPAWN || s.structureType == STRUCTURE_TOWER|| s.structureType == STRUCTURE_LAB) && s.energy < s.energyCapacity))}});
|
if(spawntarget){
|
||||||
if(creep.transfer(spawntarget, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
if(creep.transfer(spawntarget, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(spawntarget,{ignoreCreeps:ignorecreeps})
|
creep.moveTo(spawntarget,{ignoreCreeps:ignorecreeps})
|
||||||
}
|
}
|
||||||
}else if(creep.transfer(terminaltarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE) {
|
}/*else if(terminaltarget != creep.memory.pulledenergyfrom){
|
||||||
|
if(creep.transfer(terminaltarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE ) {
|
||||||
creep.say('Putting Energy')
|
creep.say('Putting Energy')
|
||||||
creep.travelTo(terminaltarget);
|
creep.travelTo(terminaltarget);
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
} else if ((creep.ticksToLive < 300 || creep.ticksToLive <= creep.memory.renewto) && (Game.rooms[creep.room.name].find(FIND_MY_SPAWNS, {filter: (r) =>{return ( r.store[RESOURCE_ENERGY]>200)}})) ) {
|
} else if ((creep.ticksToLive < 300 || creep.ticksToLive <= creep.memory.renewto) && (Game.rooms[creep.room.name].find(FIND_MY_SPAWNS, {filter: (r) =>{return ( r.store[RESOURCE_ENERGY]>200)}})) ) {
|
||||||
if(creep.memory.renewto == undefined){
|
if(creep.memory.renewto == undefined){
|
||||||
creep.memory.renewto = 1200
|
creep.memory.renewto = 1200
|
||||||
@ -53,14 +55,56 @@ let mover={
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(filllevel < creep.carryCapacity){
|
if(filllevel < creep.carryCapacity){
|
||||||
let storagetarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_CONTAINER) && _.sum(s.store) >= 10) ;}});
|
/*
|
||||||
|
let nearestcontainer = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_CONTAINER ) && s.store.getUsedCapacity('energy') >= 10) ;}});
|
||||||
|
if(creep.room.terminal){
|
||||||
|
let terminal = creep.room.terminal
|
||||||
|
let terminalenergy= terminal.store.getUsedCapacity('energy')
|
||||||
|
}
|
||||||
|
if(creep.room.storage){
|
||||||
|
let storage = creep.room.storage
|
||||||
|
let storageenergy=storage.store.getUsedCapacity('energy')
|
||||||
|
}
|
||||||
|
//console.log("Storage: " + storage.store.getUsedCapacity('energy'))
|
||||||
|
//console.log("Container: " + nearestcontainer.store.getUsedCapacity('energy')
|
||||||
|
try{
|
||||||
|
if(nearestcontainer == null){
|
||||||
|
|
||||||
|
}else {
|
||||||
|
storagetarget = nearestcontainer
|
||||||
|
}
|
||||||
|
}catch{
|
||||||
|
if(storageenergy > 0){
|
||||||
|
storagetarget = storage
|
||||||
|
} else if ( terminalenergy > 0) {
|
||||||
|
storagetarget = terminal
|
||||||
|
} else {
|
||||||
|
console.log("we're out of energy!")
|
||||||
|
storagetarget=storage
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
let storagetarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_CONTAINER) && s.store.getUsedCapacity('energy') >= 10) ;}});
|
||||||
|
if(storagetarget===undefined){
|
||||||
|
storagetarget==creep.room.terminal
|
||||||
|
}
|
||||||
let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: (r) =>{return ( r.resourceType==RESOURCE_ENERGY&& r.amount>10)}});
|
let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: (r) =>{return ( r.resourceType==RESOURCE_ENERGY&& r.amount>10)}});
|
||||||
let tombstone = creep.pos.findClosestByRange(FIND_TOMBSTONES, {filter: (r) =>{return ( r.store[RESOURCE_ENERGY]>200)}});
|
let tombstone = creep.pos.findClosestByRange(FIND_TOMBSTONES, {filter: (r) =>{return ( r.store[RESOURCE_ENERGY]>200)}});
|
||||||
if((droppedenergy == undefined) && (tombstone==undefined)){
|
if((droppedenergy == undefined) && (tombstone==undefined)){
|
||||||
|
/*try{
|
||||||
|
// console.log(storagetarget.store.getUsedCapacity('energy')/storagetarget.store.getCapacity())
|
||||||
|
if(storagetarget.store.getUsedCapacity('energy')< 1000 && (storagetarget.store.getUsedCapacity('energy')/storagetarget.store.getCapacity() < .5 )){
|
||||||
|
//console.log("too much crap")
|
||||||
|
//console.log(storagetarget.store.getUsedCapacity())
|
||||||
|
//creep.travelTo(storagetarget);
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
console.log("oops" + e)
|
||||||
|
}*/
|
||||||
if(creep.withdraw(storagetarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE) {
|
if(creep.withdraw(storagetarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE) {
|
||||||
creep.say('Getting Energy')
|
creep.say('Getting Energy')
|
||||||
creep.travelTo(storagetarget);
|
creep.travelTo(storagetarget);
|
||||||
}
|
}
|
||||||
|
creep.memory.pulledenergyfrom=storagetarget
|
||||||
} else {
|
} else {
|
||||||
if(droppedenergy){
|
if(droppedenergy){
|
||||||
if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) {
|
if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) {
|
||||||
|
Loading…
Reference in New Issue
Block a user