mirror of
https://github.com/paradizelost/screeps.git
synced 2024-11-25 02:14:44 -06:00
Mining Changes
This commit is contained in:
parent
aa2d7fdfce
commit
36c253fa36
@ -71,52 +71,13 @@ let mover={
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(filllevel < creep.carryCapacity){
|
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_CONTAINER) && s.store.getUsedCapacity('energy') >= 1000) ;}});
|
let storagetarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_CONTAINER) && s.store.getUsedCapacity('energy') >= 1000) ;}});
|
||||||
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)}});
|
||||||
let ruins=creep.pos.findClosestByRange(FIND_RUINS, {filter: ruin => ruin.store.getUsedCapacity(RESOURCE_ENERGY) > 0});
|
let ruins=creep.pos.findClosestByRange(FIND_RUINS, {filter: ruin => ruin.store.getUsedCapacity(RESOURCE_ENERGY) > 0});
|
||||||
if((droppedenergy == undefined) && (tombstone==undefined) && (ruins==undefined)){
|
console.log(creep.room.name + " " + creep.name + " " + creep.room.energyAvailable+":"+ creep.room.energyCapacityAvailable )
|
||||||
/*try{
|
if(creep.room.energyAvailable < creep.room.energyCapacityAvailable || ((droppedenergy == undefined) && (tombstone==undefined) && (ruins==undefined))){
|
||||||
// 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)
|
|
||||||
}*/
|
|
||||||
// creep.say('2')
|
|
||||||
//creep.say(storagetarget)
|
|
||||||
if(storagetarget===undefined||storagetarget==null){
|
if(storagetarget===undefined||storagetarget==null){
|
||||||
creep.say('finding storage')
|
creep.say('finding storage')
|
||||||
storagetarget=creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE) && s.store.getUsedCapacity('energy') >= 10) ;}});
|
storagetarget=creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE) && s.store.getUsedCapacity('energy') >= 10) ;}});
|
||||||
@ -125,10 +86,9 @@ let mover={
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
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('GEST')
|
||||||
creep.travelTo(storagetarget);
|
creep.travelTo(storagetarget);
|
||||||
}
|
}
|
||||||
//creep.memory.pulledenergyfrom=storagetarget
|
|
||||||
} else {
|
} else {
|
||||||
if(ruins){
|
if(ruins){
|
||||||
if(creep.withdraw(ruins,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
if(creep.withdraw(ruins,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
|
@ -33,7 +33,7 @@ let Phase1Worker = {
|
|||||||
|
|
||||||
if(creep.memory.working){
|
if(creep.memory.working){
|
||||||
let look=creep.pos.lookFor(LOOK_STRUCTURES)
|
let look=creep.pos.lookFor(LOOK_STRUCTURES)
|
||||||
let storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_TERMINAL ) && _.sum(s.store) < s.store.getCapacity()) ;}});
|
let storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_TERMINAL ) && _.sum(s.store) < s.store.getCapacity()) ;}});
|
||||||
if(creep.room.memory.NeedsRecharge==1){
|
if(creep.room.memory.NeedsRecharge==1){
|
||||||
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
|
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
|
||||||
creep.say(creep.room.controller.ticksToDowngrade + " of " + CONTROLLER_DOWNGRADE[creep.room.controller.level] * .2)
|
creep.say(creep.room.controller.ticksToDowngrade + " of " + CONTROLLER_DOWNGRADE[creep.room.controller.level] * .2)
|
||||||
@ -97,8 +97,10 @@ let Phase1Worker = {
|
|||||||
} else {
|
} else {
|
||||||
let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: (r) =>{return ( r.resourceType==RESOURCE_ENERGY&& r.amount>200)}});
|
let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: (r) =>{return ( r.resourceType==RESOURCE_ENERGY&& r.amount>200)}});
|
||||||
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)}});
|
||||||
|
let ruins=creep.pos.findClosestByRange(FIND_RUINS, {filter: ruin => ruin.store.getUsedCapacity(RESOURCE_ENERGY) > 0});
|
||||||
|
let spawn= creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ( s.structureType == STRUCTURE_SPAWN)}});
|
||||||
//console.log(tombstone)
|
//console.log(tombstone)
|
||||||
if((droppedenergy == undefined || droppedenergy==null) && (tombstone==undefined || tombstone==null)){
|
if((droppedenergy == undefined || droppedenergy==null) && (tombstone==undefined || tombstone==null) && (spawn!=undefined || spawn!=null) && (ruins==undefined || ruins==null)){
|
||||||
creep.say("1")
|
creep.say("1")
|
||||||
if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined}
|
if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined}
|
||||||
let mysource=Game.getObjectById(creep.memory.destsource.id)
|
let mysource=Game.getObjectById(creep.memory.destsource.id)
|
||||||
@ -117,10 +119,12 @@ let Phase1Worker = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//console.log(Game.getObjectById(storagetarget.id))
|
//console.log(Game.getObjectById(storagetarget.id))
|
||||||
if((storagetarget != undefined || storagetarget != null) && creep.withdraw(storagetarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE) {
|
if((storagetarget != undefined || storagetarget != null)){
|
||||||
creep.say('3')
|
if( creep.withdraw(storagetarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE){
|
||||||
//creep.say('Getting Energy')
|
creep.say('3')
|
||||||
creep.travelTo(storagetarget);
|
//creep.say('Getting Energy')
|
||||||
|
creep.travelTo(storagetarget);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE){
|
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE){
|
||||||
creep.moveTo(mysource,{ignoreCreeps:ignorecreeps})
|
creep.moveTo(mysource,{ignoreCreeps:ignorecreeps})
|
||||||
@ -143,13 +147,32 @@ let Phase1Worker = {
|
|||||||
}
|
}
|
||||||
creep.moveTo(droppedenergy,{ignoreCreeps:ignorecreeps})
|
creep.moveTo(droppedenergy,{ignoreCreeps:ignorecreeps})
|
||||||
}
|
}
|
||||||
} else {
|
} else if (tombstone) {
|
||||||
if(creep.withdraw(tombstone,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
if(creep.withdraw(tombstone,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
if(global.verbosity>0){
|
if(global.verbosity>0){
|
||||||
creep.say("MTTS");
|
creep.say("MTTS");
|
||||||
}
|
}
|
||||||
creep.moveTo(tombstone.pos,{ignoreCreeps:ignorecreeps})
|
creep.moveTo(tombstone.pos,{ignoreCreeps:ignorecreeps})
|
||||||
}
|
}
|
||||||
|
} else if (ruins){
|
||||||
|
if(creep.withdraw(ruins,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
|
if(global.verbosity>0){
|
||||||
|
creep.say("MTTS");
|
||||||
|
}
|
||||||
|
creep.moveTo(ruins,{ignoreCreeps:ignorecreeps})
|
||||||
|
}
|
||||||
|
} else if(spawn==null || spawn==undefined){
|
||||||
|
storagetarget=creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE)) ;}});
|
||||||
|
if(storagetarget){
|
||||||
|
if(creep.withdraw(storagetarget,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
|
if(global.verbosity>0){
|
||||||
|
creep.say("MTTS");
|
||||||
|
}
|
||||||
|
creep.moveTo(storagetarget,{ignoreCreeps:ignorecreeps})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
creep.say("IDK")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
let rolesourceMiner = {
|
let rolesourceMiner = {
|
||||||
run: function(creep) {
|
run: function(creep) {
|
||||||
|
try{
|
||||||
//if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined}
|
//if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined}
|
||||||
let ignorecreeps=true
|
let ignorecreeps=true
|
||||||
//console.log('running sourceminer')
|
//console.log('running sourceminer')
|
||||||
@ -26,10 +27,58 @@ let rolesourceMiner = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else{
|
} else{
|
||||||
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE) {
|
try{
|
||||||
creep.travelTo(mysource);
|
creep.say('1')
|
||||||
|
destcontainer=Game.getObjectById(creep.memory.destsource.id).pos.findInRange(FIND_STRUCTURES,1,{filter: (s) => {return (s.structureType == STRUCTURE_CONTAINER && s.store.getFreeCapacity() > 0) ;}})
|
||||||
|
|
||||||
|
if(destcontainer == undefined || destcontainer == null){
|
||||||
|
creep.say('2')
|
||||||
|
console.log(creep.name + " " + destcontainer[0].id)
|
||||||
|
creep.travelTo(destcontainer[0])
|
||||||
|
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE) {
|
||||||
|
//let mycontainer = creep.find(FIND_STRUCTURES, {filter: (s) => {return (s.structureType == STRUCTURE_CONTAINER) ;}});
|
||||||
|
creep.travelTo(destcontainer[0],{ignoreCreeps:ignorecreeps});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
creep.say('3')
|
||||||
|
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE) {
|
||||||
|
//let mycontainer = creep.find(FIND_STRUCTURES, {filter: (s) => {return (s.structureType == STRUCTURE_CONTAINER) ;}});
|
||||||
|
creep.travelTo(mysource,{ignoreCreeps:ignorecreeps});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(e){
|
||||||
|
console.log(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch(e){
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computeSourceAccessPoints: function(room, source){
|
||||||
|
const roomTerrain = room.getTerrain();
|
||||||
|
var accessPoints = 0;
|
||||||
|
for(var x = -1;x<=1;x++)
|
||||||
|
{
|
||||||
|
for(var y = -1;y<=1;y++)
|
||||||
|
{
|
||||||
|
if(x==0 && y==0){continue;}
|
||||||
|
if(roomTerrain.get(source.pos.x+x,source.pos.y+y)!=1){accessPoints++;}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return accessPoints;
|
||||||
|
},
|
||||||
|
checkminablepositions: function(name){
|
||||||
|
let x = this.pos.x;
|
||||||
|
let y = this.pos.y;
|
||||||
|
let walkable = this.room.lookForAtArea(
|
||||||
|
LOOK_TERRAIN,
|
||||||
|
y - 1, // top
|
||||||
|
x - 1, // left
|
||||||
|
y + 1, // bottom
|
||||||
|
x + 1, // right
|
||||||
|
true // asArray
|
||||||
|
).filter(o => o[LOOK_TERRAIN] !== 'wall');
|
||||||
|
return walkable.length;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
module.exports = rolesourceMiner;
|
module.exports = rolesourceMiner;
|
Loading…
Reference in New Issue
Block a user