Added structure handling in engine as well.
This commit is contained in:
7
.vscode/settings.json
vendored
7
.vscode/settings.json
vendored
@@ -103,6 +103,11 @@
|
|||||||
"__sso_allocator": "cpp",
|
"__sso_allocator": "cpp",
|
||||||
"__std_stream": "cpp",
|
"__std_stream": "cpp",
|
||||||
"__threading_support": "cpp",
|
"__threading_support": "cpp",
|
||||||
"__tuple": "cpp"
|
"__tuple": "cpp",
|
||||||
|
"csignal": "cpp",
|
||||||
|
"coroutine": "cpp",
|
||||||
|
"source_location": "cpp",
|
||||||
|
"stdfloat": "cpp",
|
||||||
|
"typeindex": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
2
dist/douwco_hivemind_loader.js
vendored
2
dist/douwco_hivemind_loader.js
vendored
File diff suppressed because one or more lines are too long
BIN
dist/douwco_hivemind_module.wasm
vendored
BIN
dist/douwco_hivemind_module.wasm
vendored
Binary file not shown.
@@ -7,7 +7,10 @@
|
|||||||
#include <Screeps/Creep.hpp>
|
#include <Screeps/Creep.hpp>
|
||||||
|
|
||||||
#include "Constants.hpp"
|
#include "Constants.hpp"
|
||||||
|
#include "Creeps/Creep.hpp"
|
||||||
#include "Creeps/Harvester.hpp"
|
#include "Creeps/Harvester.hpp"
|
||||||
|
#include "Structures/Structure.hpp"
|
||||||
|
#include "Structures/Spawn.hpp"
|
||||||
|
|
||||||
namespace DouwcoHivemind
|
namespace DouwcoHivemind
|
||||||
{
|
{
|
||||||
@@ -18,19 +21,23 @@ namespace DouwcoHivemind
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::vector<std::unique_ptr<Creep>> creeps;
|
std::vector<std::unique_ptr<Creep>> creeps;
|
||||||
// std::vector<std::unique_ptr<Structure>> structure;
|
std::vector<std::unique_ptr<Structure>> structures;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Engine()
|
Engine()
|
||||||
{
|
{
|
||||||
ReadOutCreeps();
|
ReadOutCreeps();
|
||||||
|
ReadOutStructures();
|
||||||
}
|
}
|
||||||
~Engine() {}
|
~Engine() {}
|
||||||
|
|
||||||
void loop() {
|
void loop()
|
||||||
for(auto &creep : creeps){
|
{
|
||||||
|
for (auto &creep : creeps)
|
||||||
creep->loop();
|
creep->loop();
|
||||||
}
|
|
||||||
|
for (auto &structure : structures)
|
||||||
|
structure->loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -52,6 +59,15 @@ namespace DouwcoHivemind
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReadOutStructures()
|
||||||
|
{
|
||||||
|
auto spawns = Screeps::Game.spawns();
|
||||||
|
for (auto &spawn : spawns)
|
||||||
|
{
|
||||||
|
structures.push_back(std::make_unique<Spawn>(spawn.second));
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,17 +3,21 @@
|
|||||||
|
|
||||||
#include <Screeps/StructureSpawn.hpp>
|
#include <Screeps/StructureSpawn.hpp>
|
||||||
|
|
||||||
|
#include "Structures/Structure.hpp"
|
||||||
|
|
||||||
namespace DouwcoHivemind
|
namespace DouwcoHivemind
|
||||||
{
|
{
|
||||||
class Spawn
|
class Spawn : public Structure
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Screeps::StructureSpawn *structure;
|
Screeps::StructureSpawn spawn;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Spawn(Screeps::StructureSpawn *structure_pntr) { structure = structure_pntr; }
|
Spawn(Screeps::StructureSpawn spwn) : spawn(spwn),
|
||||||
|
Structure() {}
|
||||||
~Spawn() {}
|
~Spawn() {}
|
||||||
void process();
|
|
||||||
|
void loop() override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef DOUWCO_HIVEMIND_STRUCTURE_HPP
|
||||||
|
#define DOUWCO_HIVEMIND_STRUCTURE_HPP
|
||||||
|
|
||||||
|
#include <Screeps/Structure.hpp>
|
||||||
|
|
||||||
|
namespace DouwcoHivemind
|
||||||
|
{
|
||||||
|
class Structure
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void loop(){}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // DOUWCO_HIVEMIND_STRUCTURE_HPP
|
||||||
@@ -15,13 +15,6 @@ extern "C" void loop()
|
|||||||
{
|
{
|
||||||
Screeps::Context::update();
|
Screeps::Context::update();
|
||||||
|
|
||||||
// Structures
|
|
||||||
for (auto &spawn_entry : Screeps::Game.spawns())
|
|
||||||
{
|
|
||||||
auto spawn = DouwcoHivemind::Spawn(&spawn_entry.second);
|
|
||||||
spawn.process();
|
|
||||||
}
|
|
||||||
|
|
||||||
JS::console.log(std::string("\n\n\n\n\n\n\n\n\n"));
|
JS::console.log(std::string("\n\n\n\n\n\n\n\n\n"));
|
||||||
JS::console.log(std::string("Processing tick:\t") + std::to_string(Screeps::Game.time()));
|
JS::console.log(std::string("Processing tick:\t") + std::to_string(Screeps::Game.time()));
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,9 @@
|
|||||||
#include "Constants.hpp"
|
#include "Constants.hpp"
|
||||||
#include "Structures/Spawn.hpp"
|
#include "Structures/Spawn.hpp"
|
||||||
|
|
||||||
void DouwcoHivemind::Spawn::process()
|
void DouwcoHivemind::Spawn::loop()
|
||||||
{
|
{
|
||||||
int creepcount = structure->room().find(Screeps::FIND_MY_CREEPS).size();
|
int creepcount = spawn.room().find(Screeps::FIND_MY_CREEPS).size();
|
||||||
if (creepcount > 10)
|
if (creepcount > 10)
|
||||||
{
|
{
|
||||||
EM_ASM({ console.log('To much creeps in this room'); });
|
EM_ASM({ console.log('To much creeps in this room'); });
|
||||||
@@ -21,7 +21,7 @@ void DouwcoHivemind::Spawn::process()
|
|||||||
JSON opts;
|
JSON opts;
|
||||||
opts["memory"]["role"] = Roles::HARVESTER;
|
opts["memory"]["role"] = Roles::HARVESTER;
|
||||||
|
|
||||||
int resp = structure->spawnCreep(
|
int resp = spawn.spawnCreep(
|
||||||
{"work", "carry", "move"},
|
{"work", "carry", "move"},
|
||||||
"harvester" + std::to_string(Screeps::Game.time()),
|
"harvester" + std::to_string(Screeps::Game.time()),
|
||||||
opts);
|
opts);
|
||||||
|
|||||||
Reference in New Issue
Block a user