73 lines
1.8 KiB
C++
73 lines
1.8 KiB
C++
#ifndef DOUWCO_HIVEMIND_ENGINE_HPP
|
|
#define DOUWCO_HIVEMIND_ENGINE_HPP
|
|
|
|
#include <vector>
|
|
#include <Screeps/JS.hpp>
|
|
#include <Screeps/Game.hpp>
|
|
#include <Screeps/Creep.hpp>
|
|
|
|
#include "Creeps/Creep.hpp"
|
|
#include "Creeps/Harvester.hpp"
|
|
#include "Structures/Structure.hpp"
|
|
#include "Structures/Spawn.hpp"
|
|
|
|
namespace DouwcoHivemind
|
|
{
|
|
class Creep;
|
|
class Structure;
|
|
|
|
class Engine
|
|
{
|
|
private:
|
|
std::vector<std::unique_ptr<Creep>> creeps;
|
|
std::vector<std::unique_ptr<Structure>> structures;
|
|
|
|
public:
|
|
Engine()
|
|
{
|
|
ReadOutCreeps();
|
|
ReadOutStructures();
|
|
}
|
|
~Engine() {}
|
|
|
|
void loop()
|
|
{
|
|
for (auto &creep : creeps)
|
|
creep->loop();
|
|
|
|
for (auto &structure : structures)
|
|
structure->loop();
|
|
}
|
|
|
|
private:
|
|
void ReadOutCreeps()
|
|
{
|
|
auto src_creeps = Screeps::Game.creeps();
|
|
for (auto &creep : src_creeps)
|
|
{
|
|
CreepRole role = creep.second.memory()["role"];
|
|
switch (role)
|
|
{
|
|
case CreepRole::HARVESTER:
|
|
creeps.push_back(std::make_unique<HarvesterRole>(creep.second));
|
|
break;
|
|
case CreepRole::UNEMPLOYED:
|
|
default:
|
|
EM_ASM({console.log('Undefined role for creep' + $0)}, creep.first.c_str());
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void ReadOutStructures()
|
|
{
|
|
auto spawns = Screeps::Game.spawns();
|
|
for (auto &spawn : spawns)
|
|
{
|
|
structures.push_back(std::make_unique<Spawn>(spawn.second));
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif // DOUWCO_HIVEMIND_ENGINE_HPP
|