diff --git a/.cache/jb/UpdateWork.dat b/.cache/jb/UpdateWork.dat new file mode 100644 index 0000000..96efdac Binary files /dev/null and b/.cache/jb/UpdateWork.dat differ diff --git a/.cache/jb/version.txt b/.cache/jb/version.txt new file mode 100644 index 0000000..ede3f69 --- /dev/null +++ b/.cache/jb/version.txt @@ -0,0 +1 @@ +(ssh://git@git.jetbrains.team/llvm/llvm-project.git f4157ca9dd49181f6d35eaf6d324ffa84a40f01b based on LLVM 31f1590e4fb324c43dc36199587c453e27b6f6fa revision) \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index af391e9..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/douwco_hivemind/include/Creeps/Miner.hpp b/douwco_hivemind/include/Creeps/Miner.hpp new file mode 100644 index 0000000..daad7e8 --- /dev/null +++ b/douwco_hivemind/include/Creeps/Miner.hpp @@ -0,0 +1,23 @@ +#ifndef DOUWCO_HIVEMIND_MINER_HPP +#define DOUWCO_HIVEMIND_MINER_HPP + +#include + +namespace DouwcoHivemind +{ + class Miner : public CreepBase + { + private: + bool requestedContainer = false; + public: + Miner(Screeps::Creep crp); + ~Miner() override; + void loop() override; + + private: + bool mineSource(); + std::unique_ptr getSourceTarget(); + }; +} + +#endif // DOUWCO_HIVEMIND_MINER_HPP \ No newline at end of file diff --git a/douwco_hivemind/include/Creeps/Worker.hpp b/douwco_hivemind/include/Creeps/Worker.hpp index 7804459..70ba98e 100644 --- a/douwco_hivemind/include/Creeps/Worker.hpp +++ b/douwco_hivemind/include/Creeps/Worker.hpp @@ -1,5 +1,5 @@ -#ifndef DOUWCO_HIVEMIND_HARVESTER_HPP -#define DOUWCO_HIVEMIND_HARVESTER_HPP +#ifndef DOUWCO_HIVEMIND_WORKER_HPP +#define DOUWCO_HIVEMIND_WORKER_HPP #include "Creeps/CreepBase.hpp" @@ -26,4 +26,4 @@ namespace DouwcoHivemind }; } -#endif // DOUWCO_HIVEMIND_HARVESTER_HPP \ No newline at end of file +#endif // DOUWCO_HIVEMIND_WORKER_HPP \ No newline at end of file diff --git a/douwco_hivemind/src/Miner.cpp b/douwco_hivemind/src/Miner.cpp new file mode 100644 index 0000000..b70370c --- /dev/null +++ b/douwco_hivemind/src/Miner.cpp @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include + +#include "Creeps/Miner.hpp" + +DouwcoHivemind::Miner::Miner(Screeps::Creep crp) : CreepBase(crp) +{ + requestedContainer = memory.contains("requestedContainer") ? static_cast(memory["requestedContainer"]) : false; +} + +DouwcoHivemind::Miner::~Miner() +{ + memory["requestedContainer"] = requestedContainer; +} + +void DouwcoHivemind::Miner::loop() +{ + if (mineSource() && !requestedContainer) + { + creep.room().createConstructionSite(creep.pos(), Screeps::STRUCTURE_CONTAINER); + requestedContainer = true; + } +} + +bool DouwcoHivemind::Miner::mineSource() +{ + auto source = getSourceTarget(); + if (!source){ + EM_ASM({console.log($0 + ': Miner doesn\'t have valid source target')}, creep.name().c_str()); + return false; + } + + if (isNearTo(source->pos(), 1)) + { + int resp = creep.harvest(*source); + return true; + } + else + { + moveToTarget(); + return false; + } +} + +std::unique_ptr DouwcoHivemind::Miner::getSourceTarget() +{ + auto roomObj = getRoomObjectTarget(); + if (!roomObj) + { + // todo: request source from room + return nullptr; + } + + // Check if found roomobject is an actual source + auto source = std::unique_ptr(dynamic_cast(roomObj.release())); + if (!source) + { + // EM_ASM({console.log($0 + ': Can\'t cast target to Source')}, creep.name().c_str()); + // todo: request source from room + return nullptr; + } + + return std::move(source); +}