mirror of
https://github.com/paradizelost/screeps.git
synced 2024-11-25 02:14:44 -06:00
Added repairbot and limits on energy usage
This commit is contained in:
parent
9f9811e831
commit
52d492863d
5
main.js
5
main.js
@ -7,6 +7,7 @@ var roleMiner2 = require('role.miner2');
|
|||||||
var roleHauler = require('role.hauler');
|
var roleHauler = require('role.hauler');
|
||||||
var roleHauler2 = require('role.hauler2');
|
var roleHauler2 = require('role.hauler2');
|
||||||
var roleWarrior = require('role.warrior');
|
var roleWarrior = require('role.warrior');
|
||||||
|
var roleRepairbot = require('role.repairbot')
|
||||||
var runTower = require('tower');
|
var runTower = require('tower');
|
||||||
var roleTowerrecharger = require('role.towerrecharger');
|
var roleTowerrecharger = require('role.towerrecharger');
|
||||||
var purgetype="NONE"
|
var purgetype="NONE"
|
||||||
@ -52,6 +53,7 @@ module.exports.loop = function () {
|
|||||||
roleHauler2.spawn()
|
roleHauler2.spawn()
|
||||||
roleTowerrecharger.spawn()
|
roleTowerrecharger.spawn()
|
||||||
roleWarrior.spawn()
|
roleWarrior.spawn()
|
||||||
|
roleRepairbot.spawn()
|
||||||
for(var name in Game.creeps) {
|
for(var name in Game.creeps) {
|
||||||
var creep = Game.creeps[name];
|
var creep = Game.creeps[name];
|
||||||
if(creep.memory.role == 'harvester') {
|
if(creep.memory.role == 'harvester') {
|
||||||
@ -84,5 +86,8 @@ module.exports.loop = function () {
|
|||||||
if(creep.memory.role == 'towerrecharger'){
|
if(creep.memory.role == 'towerrecharger'){
|
||||||
roleTowerrecharger.run(creep)
|
roleTowerrecharger.run(creep)
|
||||||
}
|
}
|
||||||
|
if(creep.memory.role == 'repairbot'){
|
||||||
|
roleRepairbot.run(creep)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,6 +2,20 @@ var roleBuilder = {
|
|||||||
|
|
||||||
/** @param {Creep} creep **/
|
/** @param {Creep} creep **/
|
||||||
run: function(creep,mysource) {
|
run: function(creep,mysource) {
|
||||||
|
var allcontainers = creep.room.find(FIND_STRUCTURES, {
|
||||||
|
filter: (s) => {
|
||||||
|
return ( s.structureType == STRUCTURE_CONTAINER)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var usedstorage=0
|
||||||
|
var mycapacity=0
|
||||||
|
for(var i=0; i < allcontainers.length;i++){
|
||||||
|
usedstorage+=_.sum(allcontainers[i].store)
|
||||||
|
mycapacity+=allcontainers[i].storeCapacity
|
||||||
|
}
|
||||||
|
console.log(usedstorage + " " + mycapacity)
|
||||||
|
|
||||||
|
var storagepercent = usedstorage/mycapacity
|
||||||
|
|
||||||
var ttl = creep.ticksToLive
|
var ttl = creep.ticksToLive
|
||||||
if(ttl < 300) {
|
if(ttl < 300) {
|
||||||
@ -22,6 +36,7 @@ var roleBuilder = {
|
|||||||
if(creep.memory.building) {
|
if(creep.memory.building) {
|
||||||
var target = creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES);
|
var target = creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES);
|
||||||
if(target != undefined) {
|
if(target != undefined) {
|
||||||
|
if(storagepercent > .4){
|
||||||
if(creep.build(target) == ERR_NOT_IN_RANGE) {
|
if(creep.build(target) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(target);
|
creep.moveTo(target);
|
||||||
if(creep.fatigue<1){
|
if(creep.fatigue<1){
|
||||||
@ -34,6 +49,7 @@ var roleBuilder = {
|
|||||||
creep.moveTo(Game.flags.Flag2);
|
creep.moveTo(Game.flags.Flag2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
var containers = creep.room.find(FIND_STRUCTURES, {
|
var containers = creep.room.find(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
|
64
role.repairbot.js
Normal file
64
role.repairbot.js
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
var roleRepairbot = {
|
||||||
|
|
||||||
|
/** @param {Creep} creep **/
|
||||||
|
run: function(creep) {
|
||||||
|
if(creep.memory.repairing == undefined){creep.memory.repairing=true}
|
||||||
|
if(creep.memory.repairing && creep.carry.energy == 0) {
|
||||||
|
creep.memory.repairing = false;
|
||||||
|
creep.say('gathering');
|
||||||
|
}
|
||||||
|
if(!creep.memory.repairing && creep.carry.energy == creep.carryCapacity) {
|
||||||
|
creep.memory.repairing = true;
|
||||||
|
creep.say('repairing');
|
||||||
|
}
|
||||||
|
console.log(creep.name)
|
||||||
|
if(creep.memory.repairing==false){
|
||||||
|
var container = creep.pos.findClosestByRange(FIND_STRUCTURES, {
|
||||||
|
filter: (structure) => {
|
||||||
|
return (structure.structureType == STRUCTURE_CONTAINER && structure.store[RESOURCE_ENERGY] > 0) ;
|
||||||
|
}});
|
||||||
|
if(creep.withdraw(container,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||||
|
creep.say("MTSC");
|
||||||
|
creep.moveTo(container);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var myclosestDamagedStructure = creep.room.find(FIND_STRUCTURES, {
|
||||||
|
filter: (structure) => structure.hits < structure.hitsMax
|
||||||
|
});
|
||||||
|
var closestDamagedStructure = _.first(_.sortBy(myclosestDamagedStructure, (s)=>s.hits / s.hitsMax));
|
||||||
|
var allcontainers = creep.room.find(FIND_STRUCTURES, {
|
||||||
|
filter: (s) => {
|
||||||
|
return ( s.structureType == STRUCTURE_CONTAINER)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var usedstorage=0
|
||||||
|
var mycapacity=0
|
||||||
|
for(var i=0; i < allcontainers.length;i++){
|
||||||
|
usedstorage+=_.sum(allcontainers[i].store)
|
||||||
|
mycapacity+=allcontainers[i].storeCapacity
|
||||||
|
}
|
||||||
|
var storagepercent = usedstorage/mycapacity
|
||||||
|
if(closestDamagedStructure) {
|
||||||
|
if(storagepercent > .1){
|
||||||
|
console.log(creep.name + " repairing. Currently at: " + storagepercent)
|
||||||
|
|
||||||
|
if(creep.repair(closestDamagedStructure) == ERR_NOT_IN_RANGE){ creep.moveTo(closestDamagedStructure)}
|
||||||
|
} else { console.log(creep.name + " waiting for more storage. Currently at: " + storagepercent)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
spawn: function(){
|
||||||
|
var myrole='repairbot';
|
||||||
|
var nummyrole=1;
|
||||||
|
var myroles = _.filter(Game.creeps, (creep) => creep.memory.role == myrole);
|
||||||
|
if(myroles.length < nummyrole) {
|
||||||
|
|
||||||
|
console.log('Miners: ' + myroles.length + ' Needed: ' + nummyrole);
|
||||||
|
var newName = Game.spawns['Spawn1'].createCreep([WORK,CARRY,CARRY,MOVE], undefined, {role: myrole});
|
||||||
|
console.log('Spawning new ' + myrole + ': ' + newName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = roleRepairbot;
|
@ -11,12 +11,26 @@ var roleUpgrader = {
|
|||||||
creep.memory.upgrading = true;
|
creep.memory.upgrading = true;
|
||||||
creep.say('upgrading');
|
creep.say('upgrading');
|
||||||
}
|
}
|
||||||
|
var allcontainers = creep.room.find(FIND_STRUCTURES, {
|
||||||
|
filter: (s) => {
|
||||||
|
return ( s.structureType == STRUCTURE_CONTAINER)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var usedstorage=0
|
||||||
|
var mycapacity=0
|
||||||
|
for(var i=0; i < allcontainers.length;i++){
|
||||||
|
usedstorage+=_.sum(allcontainers[i].store)
|
||||||
|
mycapacity+=allcontainers[i].storeCapacity
|
||||||
|
}
|
||||||
|
var storagepercent = usedstorage/mycapacity
|
||||||
|
|
||||||
if(creep.memory.upgrading) {
|
if(creep.memory.upgrading) {
|
||||||
|
if(storagepercent > .3){
|
||||||
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
|
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
|
||||||
creep.moveTo(creep.room.controller);
|
creep.moveTo(creep.room.controller);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
var containers = creep.room.find(FIND_STRUCTURES, {
|
var containers = creep.room.find(FIND_STRUCTURES, {
|
||||||
filter: (structure) => {
|
filter: (structure) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user