Basic setup for Cpp based screeping.

This commit is contained in:
douwe
2025-08-12 23:56:10 +02:00
parent 7c1a84a5ca
commit 5ed1329d2e
60 changed files with 2709 additions and 604 deletions

29
src/loop.cpp Normal file
View File

@@ -0,0 +1,29 @@
#include <Screeps/Context.hpp>
#include <Screeps/Creep.hpp>
#include <Screeps/StructureSpawn.hpp>
#include <emscripten.h>
#include <emscripten/bind.h>
#include <emscripten/val.h>
#include "structures/spawn.hpp"
EMSCRIPTEN_KEEPALIVE
extern "C" void loop()
{
Screeps::Context::update();
EM_ASM({ console.log('Starting loop...'); });
auto spawnManager = SpawnManager();
spawnManager.process();
auto creeps = Screeps::Game.creeps();
for (auto& creep : creeps)
creep.second.say("screepsxx");
}
EMSCRIPTEN_BINDINGS(loop)
{
emscripten::function("loop", &loop);
}

18
src/spawn.cpp Normal file
View File

@@ -0,0 +1,18 @@
#include <Screeps/Game.hpp>
#include <Screeps/Room.hpp>
#include <Screeps/StructureSpawn.hpp>
#include <emscripten.h>
#include "structures/spawn.hpp"
void SpawnManager::process()
{
for (auto& spawn : Screeps::Game.spawns())
{
int creepcount = spawn.second.room().find(Screeps::FIND_MY_CREEPS, nullptr).size();
// EM_ASM({ console.log('creepcount: ' + $0); }, creepcount);
if (creepcount >= 3) continue;
int resp = spawn.second.spawnCreep({"work", "carry", "move"}, "harvester" + std::to_string(creepcount + 1));
}
}