Created a base engine class and let it handle all creeps.
This commit is contained in:
@@ -3,8 +3,7 @@
|
||||
|
||||
namespace DouwcoHivemind{
|
||||
|
||||
// Roles
|
||||
const int ROLE_HARVESTER = 0;
|
||||
enum Roles{ UNEMPLOYED, HARVESTER };
|
||||
|
||||
}
|
||||
|
||||
|
||||
21
include/Creeps/Creep.hpp
Normal file
21
include/Creeps/Creep.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef DOUWCO_HIVEMIND_CREEP_HPP
|
||||
#define DOUWCO_HIVEMIND_CREEP_HPP
|
||||
|
||||
#include <Screeps/Creep.hpp>
|
||||
|
||||
namespace DouwcoHivemind
|
||||
{
|
||||
class Creep
|
||||
{
|
||||
protected:
|
||||
Screeps::Creep creep;
|
||||
JSON memory;
|
||||
public:
|
||||
Creep(Screeps::Creep crp) : creep(crp), memory(crp.memory()){}
|
||||
~Creep(){ creep.setMemory(memory); }
|
||||
|
||||
virtual void loop(){}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // DOUWCO_HIVEMIND_CREEP_HPP
|
||||
@@ -3,18 +3,17 @@
|
||||
|
||||
#include <Screeps/Creep.hpp>
|
||||
|
||||
#include "Creeps/Creep.hpp"
|
||||
|
||||
namespace DouwcoHivemind
|
||||
{
|
||||
class HarvesterRole
|
||||
class HarvesterRole : public Creep
|
||||
{
|
||||
private:
|
||||
Screeps::Creep *creep;
|
||||
JSON memory;
|
||||
public:
|
||||
HarvesterRole(Screeps::Creep* creep_pntr);
|
||||
~HarvesterRole();
|
||||
HarvesterRole(Screeps::Creep crp) : Creep(crp){}
|
||||
~HarvesterRole(){}
|
||||
|
||||
void process();
|
||||
void loop() override;
|
||||
|
||||
private:
|
||||
void setupMemory();
|
||||
58
include/Engine.hpp
Normal file
58
include/Engine.hpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#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 "Constants.hpp"
|
||||
#include "Creeps/Harvester.hpp"
|
||||
|
||||
namespace DouwcoHivemind
|
||||
{
|
||||
class Creep;
|
||||
class Structure;
|
||||
|
||||
class Engine
|
||||
{
|
||||
private:
|
||||
std::vector<std::unique_ptr<Creep>> creeps;
|
||||
// std::vector<std::unique_ptr<Structure>> structure;
|
||||
|
||||
public:
|
||||
Engine()
|
||||
{
|
||||
ReadOutCreeps();
|
||||
}
|
||||
~Engine() {}
|
||||
|
||||
void loop() {
|
||||
for(auto &creep : creeps){
|
||||
creep->loop();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void ReadOutCreeps()
|
||||
{
|
||||
auto src_creeps = Screeps::Game.creeps();
|
||||
for (auto &creep : src_creeps)
|
||||
{
|
||||
Roles role = creep.second.memory()["role"];
|
||||
switch (role)
|
||||
{
|
||||
case Roles::HARVESTER:
|
||||
creeps.push_back(std::make_unique<HarvesterRole>(creep.second));
|
||||
break;
|
||||
case Roles::UNEMPLOYED:
|
||||
default:
|
||||
EM_ASM({console.log('Undefined role for creep' + $0)}, creep.first.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // DOUWCO_HIVEMIND_ENGINE_HPP
|
||||
0
include/Structures/Structure.hpp
Normal file
0
include/Structures/Structure.hpp
Normal file
Reference in New Issue
Block a user