From aaa8c26d651c0c0aaec307afdd2b336b04d28ea2 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 10 Nov 2020 01:29:27 -0600 Subject: [PATCH] Changes to road making rules --- RoomInit.js | 1 + main.js | 38 ++++++++++++++++++++++++++++++++------ role.nrworker.js | 2 +- role.phase0worker.js | 1 + role.phase1worker.js | 8 ++++++-- 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/RoomInit.js b/RoomInit.js index b12495f..7e5a1e8 100644 --- a/RoomInit.js +++ b/RoomInit.js @@ -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 \ No newline at end of file diff --git a/main.js b/main.js index a1a78d8..a079ac2 100644 --- a/main.js +++ b/main.js @@ -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 diff --git a/role.nrworker.js b/role.nrworker.js index b851004..3e0e74c 100644 --- a/role.nrworker.js +++ b/role.nrworker.js @@ -7,4 +7,4 @@ let rolenrBuilder = { } } }; -module.exports = rolenrBuilder; +module.exports = rolenrBuilder; \ No newline at end of file diff --git a/role.phase0worker.js b/role.phase0worker.js index ce463b6..519ae3b 100644 --- a/role.phase0worker.js +++ b/role.phase0worker.js @@ -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'); diff --git a/role.phase1worker.js b/role.phase1worker.js index d9e3dea..fb0ded3 100644 --- a/role.phase1worker.js +++ b/role.phase1worker.js @@ -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 {