Changes to road making rules

This commit is contained in:
dan 2020-11-10 01:29:27 -06:00
parent e72a3f37dd
commit aaa8c26d65
5 changed files with 41 additions and 9 deletions

View File

@ -8,6 +8,7 @@ let initroom = {
Game.rooms[name].memory.minrepairpct=.5
Game.rooms[name].memory.hasbeeninited=1
Game.rooms[name].memory.tickssofar=0
Game.rooms[name].memory.maphits={}
}
}
module.exports = initroom

38
main.js
View File

@ -3,6 +3,7 @@ global.Empire = require("Empire")
let Traveler = require("Traveler")
global.verbosity=0
module.exports.loop = function () {
let decrementcounter = Game.time % 30
for(let name in Game.rooms){
let myroom=Game.rooms[name]
@ -20,26 +21,51 @@ module.exports.loop = function () {
myroom.memory.tickssofar++
require('Room.Phase' + myroom.memory.phase).run(name)
}
}
for(let pos in myroom.memory.maphits){
if((myroom.memory.maphits[pos].lastwalked < (Game.time - 1000)) && (myroom.memory.maphits[pos].hits>0)){
if(decrementcounter== 0){
myroom.memory.maphits[pos].hits--
}
} else if(myroom.memory.maphits[pos].hits==0){
delete myroom.memory.maphits[pos]
}
}
}
for(let name in Memory.creeps) {
if(!Game.creeps[name]) {
delete Memory.creeps[name];
if(global.verbosity>0){
console.log('Clearing non-existing creep memory:', name);
}
} else {
try{
let creep = Game.creeps[name]
if(creep.spawning) return;
if(creep.fatigue>0){
creep.say('fatigued')
creep.room.createConstructionSite(creep.pos.x,creep.pos.y,STRUCTURE_ROAD)
if(creep.room.memory.maphits==undefined){
creep.room.memory.maphits={}
}
//creep.room.createConstructionSite(creep.pos.x,creep.pos.y,STRUCTURE_ROAD)
if(creep.room.memory.maphits[creep.pos.x + '-' + creep.pos.y] ==undefined){
creep.room.memory.maphits[creep.pos.x + '-' + creep.pos.y]={}
creep.room.memory.maphits[creep.pos.x + '-' + creep.pos.y].lastwalked = Game.time
creep.room.memory.maphits[creep.pos.x + '-' + creep.pos.y].hits=1
} else {
creep.room.memory.maphits[creep.pos.x + '-' + creep.pos.y].hits++
if(creep.room.memory.maphits[creep.pos.x + '-' + creep.pos.y].hits > 5){
if(creep.room.memory.phase>0){
creep.room.createConstructionSite(creep.pos.x,creep.pos.y,STRUCTURE_ROAD)
}
}
}
}
require('role.' + creep.memory.role).run(creep)
//creep.say("TRYING")
} catch (e) {}
} catch (e) {
console.log("creep error")
console.log(e)
}
}
}
let flags = Game.flags

View File

@ -7,4 +7,4 @@ let rolenrBuilder = {
}
}
};
module.exports = rolenrBuilder;
module.exports = rolenrBuilder;

View File

@ -2,6 +2,7 @@
let Phase0Worker = {
run: function(creep) {
let filllevel = _.sum(creep.carry)
//creep.say(creep.room.memory.maphits[creep.pos.x + '-' + creep.pos.y].hits)
if(creep.memory.working && filllevel == 0) {
creep.memory.working = false;
creep.say('Gathering');

View File

@ -6,6 +6,9 @@ let Phase1Worker = {
creep.memory.lastpos = creep.pos
creep.memory.timeatpos = 0
}
if(creep.memory.assignedroom==undefined){
creep.memory.assignedroom=creep.room.name
}
let lastpos = _.create(RoomPosition.prototype, creep.memory.lastpos)
if(creep.pos.isEqualTo(lastpos)){
@ -59,8 +62,9 @@ let Phase1Worker = {
}else {
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.say('MTRC')
if (road.length > 0) {creep.repair(road);}
creep.moveTo(creep.room.controller,{ignoreCreeps:ignorecreeps})
if (road.length > 0) {creep.repair(road);}
creep.memory.assignedroom=creep.room.name
creep.moveTo(Game.rooms[creep.memory.assignedroom].controller,{ignoreCreeps:ignorecreeps})
}
}
} else {