screeps/main.js

94 lines
3.8 KiB
JavaScript
Raw Normal View History

2016-09-28 08:37:28 -05:00
'use strict';
2017-06-06 13:17:26 -05:00
global.Empire = require("Empire")
2020-11-09 19:31:39 -06:00
let Traveler = require("Traveler")
2017-07-13 23:24:42 -05:00
global.verbosity=0
2016-09-15 00:30:24 -05:00
module.exports.loop = function () {
2020-11-17 10:30:13 -06:00
console.log("----Start loop for "+ Game.time + '----')
2020-11-10 01:29:27 -06:00
let decrementcounter = Game.time % 30
2022-05-04 08:30:12 -05:00
///for (let key of require('Empire')) global[key] = require('Empire')[key]
2020-11-18 08:30:53 -06:00
try{
2020-11-09 19:31:39 -06:00
for(let name in Game.rooms){
let myroom=Game.rooms[name]
let towers = Game.rooms[name].find(FIND_MY_STRUCTURES, {filter: { structureType: STRUCTURE_TOWER }})
//console.log(towers.length)
if(towers.length>0){
// console.log('running towers in ' + name)
require('Run.Tower').tick(name)
}
if(!myroom.memory.hasbeeninited && (myroom.controller!==undefined)){
require('RoomInit').run(name)
}
if(myroom.controller!==undefined){
myroom.memory.tickssofar++
2022-05-23 15:59:00 -05:00
try{
2020-11-09 19:31:39 -06:00
require('Room.Phase' + myroom.memory.phase).run(name)
2022-05-23 15:59:00 -05:00
} catch(e){
console.log(e)
}
2020-11-09 19:31:39 -06:00
}
2020-11-10 01:29:27 -06:00
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]
}
}
2020-11-18 08:30:53 -06:00
}} catch(e) {console.log("Error processing rooms: "+ e + " " + e.stack)}
try{
2016-09-28 08:37:28 -05:00
for(let name in Memory.creeps) {
2016-09-15 00:30:24 -05:00
if(!Game.creeps[name]) {
delete Memory.creeps[name];
2017-07-13 23:24:42 -05:00
if(global.verbosity>0){
}
2020-11-09 19:31:39 -06:00
} else {
2020-11-18 08:30:53 -06:00
let creep = Game.creeps[name]
2020-11-09 19:31:39 -06:00
try{
if(creep.spawning) return;
if(creep.fatigue>0){
2020-11-10 01:29:27 -06:00
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)
}
}
}
2020-11-09 19:31:39 -06:00
}
require('role.' + creep.memory.role).run(creep)
//creep.say("TRYING")
2020-11-10 01:29:27 -06:00
} catch (e) {
2020-11-18 08:30:53 -06:00
creep.say('🦄')
console.log("creep error " + creep.name)
2020-11-10 01:29:27 -06:00
console.log(e)
2020-11-18 08:30:53 -06:00
console.log(e.stack)
2020-11-10 01:29:27 -06:00
}
2016-09-15 00:30:24 -05:00
}
2020-11-17 11:47:15 -06:00
//console.log('done running creeps')
2020-11-18 08:30:53 -06:00
}} catch(e) {console.log("Error processing creeps: "+ e.stack)}
try{
2020-11-09 19:31:39 -06:00
let flags = Game.flags
for(let flag in flags){
2020-11-17 11:47:15 -06:00
//console.log('running flags')
2020-11-09 19:31:39 -06:00
require('flag.' + flag ).run()
2020-11-18 08:30:53 -06:00
}} catch(e) {console.log("Error processing flags: "+ e.stack)}
2020-11-09 19:31:39 -06:00
for(let name in Memory.rooms) {
2020-11-17 11:47:15 -06:00
// console.log('cleaning up old rooms')
2020-11-09 19:31:39 -06:00
let myroom = Game.rooms[name]
if(!Game.rooms[name]){delete Memory.rooms[name]}
}
2020-11-17 10:30:13 -06:00
console.log("----End loop for "+ Game.time +'----')
2020-11-17 11:47:15 -06:00
}