ADD: CollectResourceSystem
This commit is contained in:
parent
f1f1dde9b5
commit
48bd9bf8d9
@ -200,6 +200,8 @@ add_executable(Dicewars_Siedler src/main.cpp
|
|||||||
src/engine/core/animations/AnimationSystem.h
|
src/engine/core/animations/AnimationSystem.h
|
||||||
src/engine/core/EngineTime.cpp
|
src/engine/core/EngineTime.cpp
|
||||||
src/engine/core/EngineTime.h
|
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
|
target_compile_options(Dicewars_Siedler PRIVATE
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
#include "hexWorld/building/BuildingFactory.h"
|
#include "hexWorld/building/BuildingFactory.h"
|
||||||
#include "hexWorld/building/TemporaryBuildingDefinitionFactory.h"
|
#include "hexWorld/building/TemporaryBuildingDefinitionFactory.h"
|
||||||
#include "hexWorld/ecs/components/ProducingComponent.h"
|
#include "hexWorld/ecs/components/ProducingComponent.h"
|
||||||
|
#include "hexWorld/ecs/systems/CollectResourceSystem.h"
|
||||||
#include "hexWorld/ecs/systems/ProducingSystem.h"
|
#include "hexWorld/ecs/systems/ProducingSystem.h"
|
||||||
#include "hexWorld/events/TurnChangedEvent.h"
|
#include "hexWorld/events/TurnChangedEvent.h"
|
||||||
|
|
||||||
@ -101,6 +102,7 @@ void GameLayer::onUpdate()
|
|||||||
camera->move(moveDir, 0.5f);
|
camera->move(moveDir, 0.5f);
|
||||||
tileHighlightSystem->update(*entityManager, *mousePicker, *camera);
|
tileHighlightSystem->update(*entityManager, *mousePicker, *camera);
|
||||||
buildingPlacementSystem->update(*entityManager, *gameMode, 0, *turnState);
|
buildingPlacementSystem->update(*entityManager, *gameMode, 0, *turnState);
|
||||||
|
CollectResourceSystem::update(*entityManager, *gameMode);
|
||||||
RenderSystem::render(*entityManager, *renderer);
|
RenderSystem::render(*entityManager, *renderer);
|
||||||
|
|
||||||
renderer->render(*light, *camera);
|
renderer->render(*light, *camera);
|
||||||
|
|||||||
@ -75,4 +75,8 @@ bool GameMode::hasTurn(PlayerID playerID, int turn) const {
|
|||||||
return turn % static_cast<int>(getPlayerCount()) == static_cast<int>(playerID);
|
return turn % static_cast<int>(getPlayerCount()) == static_cast<int>(playerID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameMode::addResource(PlayerID playerID, RessourceType ressource, int amount) {
|
||||||
|
players[playerID].getInventory()->add(ressource, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -4,10 +4,12 @@
|
|||||||
|
|
||||||
#ifndef GAMEMODE_H
|
#ifndef GAMEMODE_H
|
||||||
#define GAMEMODE_H
|
#define GAMEMODE_H
|
||||||
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include "../engine/core/ECS/EntityManager.h"
|
#include "../engine/core/ECS/EntityManager.h"
|
||||||
#include "hexWorld/ecs/components/BuildingComponent.h"
|
#include "hexWorld/ecs/components/BuildingComponent.h"
|
||||||
|
#include "hexWorld/ecs/components/ProducingComponent.h"
|
||||||
#include "player/Player.h"
|
#include "player/Player.h"
|
||||||
|
|
||||||
|
|
||||||
@ -34,6 +36,9 @@ public:
|
|||||||
bool hasTurn(PlayerID playerID, int turn) const;
|
bool hasTurn(PlayerID playerID, int turn) const;
|
||||||
|
|
||||||
bool getCurrentTurnPlayer(int turn) const;
|
bool getCurrentTurnPlayer(int turn) const;
|
||||||
|
|
||||||
|
void addResource(PlayerID uint32, RessourceType ressource, int get_storage);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<PlayerID, Player> players;
|
std::unordered_map<PlayerID, Player> players;
|
||||||
std::optional<BuildingType> activeBuilding;
|
std::optional<BuildingType> activeBuilding;
|
||||||
|
|||||||
46
src/game/hexWorld/ecs/systems/CollectResourceSystem.cpp
Normal file
46
src/game/hexWorld/ecs/systems/CollectResourceSystem.cpp
Normal file
@ -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<ProducingComponent>(e);
|
||||||
|
auto owner = em.getComponent<OwnerComponent>(e);
|
||||||
|
auto buildingComponent = em.getComponent<BuildingComponent>(e);
|
||||||
|
auto modelStateComponent = em.getComponent<ModelStateComponent>(e);
|
||||||
|
|
||||||
|
if (!prod || !owner || !buildingComponent || !modelStateComponent) continue;
|
||||||
|
printf("Bare Minimum Components existing\n");
|
||||||
|
|
||||||
|
EntityID tileID = buildingComponent->tileEntity;
|
||||||
|
auto tileRenderComponent = em.getComponent<TileRenderComponent>(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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/game/hexWorld/ecs/systems/CollectResourceSystem.h
Normal file
17
src/game/hexWorld/ecs/systems/CollectResourceSystem.h
Normal file
@ -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
|
||||||
Loading…
Reference in New Issue
Block a user