Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 49f253a546 | |||
| e809d23f57 | |||
|
|
656cca578e | ||
| 1596283841 | |||
| 74d6e9e76d |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,3 +1,7 @@
|
|||||||
|
# IDE
|
||||||
|
.cache/
|
||||||
|
.idea/
|
||||||
|
|
||||||
# Build files
|
# Build files
|
||||||
build/*
|
build/*
|
||||||
dist/*
|
dist/*
|
||||||
|
|||||||
23
douwco_hivemind/include/Creeps/Miner.hpp
Normal file
23
douwco_hivemind/include/Creeps/Miner.hpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef DOUWCO_HIVEMIND_MINER_HPP
|
||||||
|
#define DOUWCO_HIVEMIND_MINER_HPP
|
||||||
|
|
||||||
|
#include <Creeps/CreepBase.hpp>
|
||||||
|
|
||||||
|
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<Screeps::Source> getSourceTarget();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // DOUWCO_HIVEMIND_MINER_HPP
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef DOUWCO_HIVEMIND_HARVESTER_HPP
|
#ifndef DOUWCO_HIVEMIND_WORKER_HPP
|
||||||
#define DOUWCO_HIVEMIND_HARVESTER_HPP
|
#define DOUWCO_HIVEMIND_WORKER_HPP
|
||||||
|
|
||||||
#include "Creeps/CreepBase.hpp"
|
#include "Creeps/CreepBase.hpp"
|
||||||
|
|
||||||
@@ -26,4 +26,4 @@ namespace DouwcoHivemind
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // DOUWCO_HIVEMIND_HARVESTER_HPP
|
#endif // DOUWCO_HIVEMIND_WORKER_HPP
|
||||||
67
douwco_hivemind/src/Miner.cpp
Normal file
67
douwco_hivemind/src/Miner.cpp
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
#include <emscripten.h>
|
||||||
|
#include <Screeps/Constants.hpp>
|
||||||
|
#include <Screeps/Source.hpp>
|
||||||
|
#include <Screeps/Room.hpp>
|
||||||
|
#include <Screeps/RoomPosition.hpp>
|
||||||
|
|
||||||
|
#include "Creeps/Miner.hpp"
|
||||||
|
|
||||||
|
DouwcoHivemind::Miner::Miner(Screeps::Creep crp) : CreepBase(crp)
|
||||||
|
{
|
||||||
|
requestedContainer = memory.contains("requestedContainer") ? static_cast<bool>(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<Screeps::Source> 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<Screeps::Source>(dynamic_cast<Screeps::Source *>(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);
|
||||||
|
}
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <Screeps/Game.hpp>
|
#include <Screeps/Game.hpp>
|
||||||
#include <Screeps/Room.hpp>
|
#include <Screeps/Room.hpp>
|
||||||
|
#include <Screeps/RoomObject.hpp>
|
||||||
|
#include <Screeps/Constants.hpp>
|
||||||
|
#include <Screeps/Structure.hpp>
|
||||||
|
|
||||||
#include "Creeps/CreepBase.hpp"
|
#include "Creeps/CreepBase.hpp"
|
||||||
#include "Structures/Spawn.hpp"
|
#include "Structures/Spawn.hpp"
|
||||||
@@ -10,13 +15,25 @@ void DouwcoHivemind::Spawn::loop()
|
|||||||
if (Screeps::Game.time() % 50 != 0)
|
if (Screeps::Game.time() % 50 != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int energyAvailable = spawn.room().energyAvailable();
|
auto room = spawn.room();
|
||||||
int energyCapacityAvailable = spawn.room().energyCapacityAvailable();
|
int energyAvailable = room.energyAvailable();
|
||||||
|
int energyCapacityAvailable = room.energyCapacityAvailable();
|
||||||
|
int constructionSiteCount = room.find(Screeps::FIND_MY_CONSTRUCTION_SITES).size();
|
||||||
|
auto structures = room.find(Screeps::FIND_STRUCTURES);
|
||||||
|
int repairableStructureCount, extensionCount;
|
||||||
|
for (auto& roomObj : structures)
|
||||||
|
{
|
||||||
|
auto structure = dynamic_cast<Screeps::Structure*>(roomObj.get());
|
||||||
|
std::string type = structure->structureType();
|
||||||
|
if (type == Screeps::STRUCTURE_CONTROLLER || type == Screeps::STRUCTURE_SPAWN) continue;
|
||||||
|
repairableStructureCount++;
|
||||||
|
if (type == Screeps::STRUCTURE_EXTENSION) extensionCount++;
|
||||||
|
}
|
||||||
|
|
||||||
int required_upgraders = 1;
|
int required_suppliers = std::clamp(extensionCount/5, 1, 2);
|
||||||
int required_suppliers = 1;
|
int required_maintainers = std::clamp(repairableStructureCount, 0, 1);
|
||||||
int required_maintainers = spawn.room().find(Screeps::FIND_MY_STRUCTURES).size() <= 2 ? 0 : 1;;
|
int required_builders = std::clamp(constructionSiteCount, 0, 5);
|
||||||
int required_builders = spawn.room().find(Screeps::FIND_MY_CONSTRUCTION_SITES).size() == 0 ? 0 : 1;
|
int required_upgraders = std::clamp(5-required_builders-required_maintainers-required_suppliers, 1, 3);
|
||||||
|
|
||||||
for (auto &creep : Screeps::Game.creeps())
|
for (auto &creep : Screeps::Game.creeps())
|
||||||
{
|
{
|
||||||
@@ -32,7 +49,7 @@ void DouwcoHivemind::Spawn::loop()
|
|||||||
required_builders--;
|
required_builders--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (energyAvailable < energyCapacityAvailable && required_suppliers < 2)
|
if (energyAvailable < energyCapacityAvailable && required_suppliers == 0)
|
||||||
return;
|
return;
|
||||||
std::string name;
|
std::string name;
|
||||||
JSON opts;
|
JSON opts;
|
||||||
|
|||||||
Reference in New Issue
Block a user