commit 4e5267347757f9c79a2393c64511a8ae50be10f0 Author: Philipp Horstenkamp Date: Sat Apr 9 17:46:39 2022 +0200 init diff --git a/main.mjs b/main.mjs new file mode 100644 index 0000000..f0f532b --- /dev/null +++ b/main.mjs @@ -0,0 +1,21 @@ +import { prototypes, utils } from '/game'; +import { RESOURCE_ENERGY, ERR_NOT_IN_RANGE } from '/game/constants'; + +export function loop() { + const creep = utils.getObjectsByPrototype(prototypes.Creep).find(i => i.my); + if(!creep.store[RESOURCE_ENERGY]) { + const container = utils.findClosestByPath(creep, utils.getObjectsByPrototype(prototypes.StructureContainer)); + if(creep.withdraw(container, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { + creep.moveTo(container); + } + } else { + const constructionSite = utils.getObjectsByPrototype(prototypes.ConstructionSite).find(i => i.my); + if(!constructionSite) { + utils.createConstructionSite(50,55, prototypes.StructureTower); + } else { + if(creep.build(constructionSite) == ERR_NOT_IN_RANGE) { + creep.moveTo(constructionSite); + } + } + } +} \ No newline at end of file