From 48bd9bf8d956afc08111244eec3cb1af774c9d23 Mon Sep 17 00:00:00 2001 From: sebastian Date: Sat, 14 Feb 2026 16:51:38 +0100 Subject: [PATCH] ADD: CollectResourceSystem --- CMakeLists.txt | 2 + src/game/GameLayer.cpp | 2 + src/game/GameMode.cpp | 4 ++ src/game/GameMode.h | 5 ++ .../ecs/systems/CollectResourceSystem.cpp | 46 +++++++++++++++++++ .../ecs/systems/CollectResourceSystem.h | 17 +++++++ 6 files changed, 76 insertions(+) create mode 100644 src/game/hexWorld/ecs/systems/CollectResourceSystem.cpp create mode 100644 src/game/hexWorld/ecs/systems/CollectResourceSystem.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e282aae..979dbdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,6 +200,8 @@ add_executable(Dicewars_Siedler src/main.cpp src/engine/core/animations/AnimationSystem.h src/engine/core/EngineTime.cpp src/engine/core/EngineTime.h + src/game/hexWorld/ecs/systems/CollectResourceSystem.cpp + src/game/hexWorld/ecs/systems/CollectResourceSystem.h ) target_compile_options(Dicewars_Siedler PRIVATE diff --git a/src/game/GameLayer.cpp b/src/game/GameLayer.cpp index 5f66d55..b9555ef 100644 --- a/src/game/GameLayer.cpp +++ b/src/game/GameLayer.cpp @@ -22,6 +22,7 @@ #include "hexWorld/building/BuildingFactory.h" #include "hexWorld/building/TemporaryBuildingDefinitionFactory.h" #include "hexWorld/ecs/components/ProducingComponent.h" +#include "hexWorld/ecs/systems/CollectResourceSystem.h" #include "hexWorld/ecs/systems/ProducingSystem.h" #include "hexWorld/events/TurnChangedEvent.h" @@ -101,6 +102,7 @@ void GameLayer::onUpdate() camera->move(moveDir, 0.5f); tileHighlightSystem->update(*entityManager, *mousePicker, *camera); buildingPlacementSystem->update(*entityManager, *gameMode, 0, *turnState); + CollectResourceSystem::update(*entityManager, *gameMode); RenderSystem::render(*entityManager, *renderer); renderer->render(*light, *camera); diff --git a/src/game/GameMode.cpp b/src/game/GameMode.cpp index 04cfd87..231908f 100644 --- a/src/game/GameMode.cpp +++ b/src/game/GameMode.cpp @@ -75,4 +75,8 @@ bool GameMode::hasTurn(PlayerID playerID, int turn) const { return turn % static_cast(getPlayerCount()) == static_cast(playerID); } +void GameMode::addResource(PlayerID playerID, RessourceType ressource, int amount) { + players[playerID].getInventory()->add(ressource, amount); +} + diff --git a/src/game/GameMode.h b/src/game/GameMode.h index 9819dea..3f3bb43 100644 --- a/src/game/GameMode.h +++ b/src/game/GameMode.h @@ -4,10 +4,12 @@ #ifndef GAMEMODE_H #define GAMEMODE_H +#include #include #include "../engine/core/ECS/EntityManager.h" #include "hexWorld/ecs/components/BuildingComponent.h" +#include "hexWorld/ecs/components/ProducingComponent.h" #include "player/Player.h" @@ -34,6 +36,9 @@ public: bool hasTurn(PlayerID playerID, int turn) const; bool getCurrentTurnPlayer(int turn) const; + + void addResource(PlayerID uint32, RessourceType ressource, int get_storage); + private: std::unordered_map players; std::optional activeBuilding; diff --git a/src/game/hexWorld/ecs/systems/CollectResourceSystem.cpp b/src/game/hexWorld/ecs/systems/CollectResourceSystem.cpp new file mode 100644 index 0000000..af2e9c0 --- /dev/null +++ b/src/game/hexWorld/ecs/systems/CollectResourceSystem.cpp @@ -0,0 +1,46 @@ +// +// Created by sebastian on 14.02.26. +// + +#include "CollectResourceSystem.h" + +#include "../../../../engine/core/ECS/ModelStateComponent.h" +#include "../../../../engine/platform/glfw/InputManager.h" +#include "../components/ProducingComponent.h" +#include "../components/OwnerComponent.h" +#include "../components/BuildingComponent.h" +#include "../../../../engine/core/ECS/TileRenderComponent.h" + +void CollectResourceSystem::update(EntityManager &em, GameMode &gm) { + if (!InputManager::isMouseButtonPressed(GLFW_MOUSE_BUTTON_LEFT)) return; + printf("Collect Resources!\n"); + for (EntityID e : em.getAllEntities()) { + auto prod = em.getComponent(e); + auto owner = em.getComponent(e); + auto buildingComponent = em.getComponent(e); + auto modelStateComponent = em.getComponent(e); + + if (!prod || !owner || !buildingComponent || !modelStateComponent) continue; + printf("Bare Minimum Components existing\n"); + + EntityID tileID = buildingComponent->tileEntity; + auto tileRenderComponent = em.getComponent(tileID); + + if (!tileRenderComponent || !tileRenderComponent->isHighlighted) continue; + printf("Tile is highlighted\n"); + + if (prod->getStorage() == 0) continue; + printf("Storage is not empty\n"); + + if (owner->playerID == gm.getCurrentPlayer()) { + printf("You own this tile!\n"); + gm.addResource(owner->playerID, prod->getProduces(), prod->getStorage()); + prod->setStorage(0); + + modelStateComponent->params["fillRatio"] = 0.0f; + } else { + printf("Not your tile!\n"); + } + + } +} diff --git a/src/game/hexWorld/ecs/systems/CollectResourceSystem.h b/src/game/hexWorld/ecs/systems/CollectResourceSystem.h new file mode 100644 index 0000000..c78e7aa --- /dev/null +++ b/src/game/hexWorld/ecs/systems/CollectResourceSystem.h @@ -0,0 +1,17 @@ +// +// Created by sebastian on 14.02.26. +// + +#ifndef DICEWARS_SIEDLER_COLLECTRESOURCESYSTEM_H +#define DICEWARS_SIEDLER_COLLECTRESOURCESYSTEM_H +#include "../../../GameMode.h" +#include "../../../../engine/core/ECS/EntityManager.h" + + +class CollectResourceSystem { +public: + static void update(EntityManager& em, GameMode& gm); +}; + + +#endif //DICEWARS_SIEDLER_COLLECTRESOURCESYSTEM_H \ No newline at end of file