import { ErrorMapper } from 'utils/ErrorMapper'; import { move } from 'states/move'; import { harvest } from 'states/harvest'; // When compiling TS to JS and bundling with rollup, the line numbers and file names in error messages change // This utility uses source maps to get the line numbers and file names of the original, TS source code function dispose() { // Automatically delete memory of missing creeps for (const name in Memory.creeps) { if (!(name in Game.creeps)) { delete Memory.creeps[name]; } } } const defaultState = 'harvest'; function execCreep(creep: Creep) { switch(creep.memory.state) { case 'move': move(creep); break; case 'harvest': harvest(creep); break; default: creep.memory.state = defaultState; break; } } export const loop = ErrorMapper.wrapLoop(() => { for(let i in Game.creeps) { execCreep(Game.creeps[i]); } dispose(); });