Added custom move behaviour to creeps
This commit is contained in:
73
douwco_hivemind/include/Engine.hpp
Normal file
73
douwco_hivemind/include/Engine.hpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user