ADD: ProducingSystem
This commit is contained in:
parent
0ca673f702
commit
2c1c5b2d63
@ -181,6 +181,10 @@ add_executable(Dicewars_Siedler src/main.cpp
|
|||||||
src/engine/toolbox/IndexedMap.h
|
src/engine/toolbox/IndexedMap.h
|
||||||
src/engine/core/ECS/ModelStateComponent.cpp
|
src/engine/core/ECS/ModelStateComponent.cpp
|
||||||
src/engine/core/ECS/ModelStateComponent.h
|
src/engine/core/ECS/ModelStateComponent.h
|
||||||
|
src/game/hexWorld/ecs/components/ProducingComponent.cpp
|
||||||
|
src/game/hexWorld/ecs/components/ProducingComponent.h
|
||||||
|
src/game/hexWorld/ecs/systems/ProducingSystem.cpp
|
||||||
|
src/game/hexWorld/ecs/systems/ProducingSystem.h
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_options(Dicewars_Siedler PRIVATE
|
target_compile_options(Dicewars_Siedler PRIVATE
|
||||||
|
|||||||
@ -42,7 +42,7 @@ void RenderSystem::updateModelStage(ModelComponent *model, ModelStateComponent *
|
|||||||
if (it == state->params.end()) continue;
|
if (it == state->params.end()) continue;
|
||||||
|
|
||||||
float value = it->second;
|
float value = it->second;
|
||||||
if (value >= stage.getCondition().min && value < stage.getCondition().max) {
|
if (value >= stage.getCondition().min && value <= stage.getCondition().max) {
|
||||||
bestStage = stage.getStageName();
|
bestStage = stage.getStageName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,10 +8,12 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "../../game/GameMode.h"
|
#include "../../game/GameMode.h"
|
||||||
|
#include "../core/Application.h"
|
||||||
|
|
||||||
|
|
||||||
class Layer {
|
class Layer {
|
||||||
public:
|
public:
|
||||||
|
Layer() : events(Application::getInstance().getEventBus()) {}
|
||||||
virtual ~Layer() = default;
|
virtual ~Layer() = default;
|
||||||
virtual void onAttach() {}
|
virtual void onAttach() {}
|
||||||
virtual void onDetach() {}
|
virtual void onDetach() {}
|
||||||
@ -22,6 +24,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<GameMode> gameMode;
|
std::shared_ptr<GameMode> gameMode;
|
||||||
|
EventBus& events;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,9 @@
|
|||||||
#include "../engine/renderer/loader/AssetManager.h"
|
#include "../engine/renderer/loader/AssetManager.h"
|
||||||
#include "hexWorld/HexModelFactory.h"
|
#include "hexWorld/HexModelFactory.h"
|
||||||
#include "hexWorld/MapGenerator.h"
|
#include "hexWorld/MapGenerator.h"
|
||||||
|
#include "hexWorld/ecs/components/ProducingComponent.h"
|
||||||
|
#include "hexWorld/ecs/systems/ProducingSystem.h"
|
||||||
|
#include "hexWorld/events/TurnChangedEvent.h"
|
||||||
|
|
||||||
GameLayer::GameLayer() :texturedModel(0,0) //Platzhalter, echtes Model kommt in onAttach
|
GameLayer::GameLayer() :texturedModel(0,0) //Platzhalter, echtes Model kommt in onAttach
|
||||||
{
|
{
|
||||||
@ -67,13 +70,21 @@ void GameLayer::onAttach()
|
|||||||
auto transformComponent = std::make_shared<TransformComponent>(glm::vec3(0,0,0), glm::vec3(0), 1.f);
|
auto transformComponent = std::make_shared<TransformComponent>(glm::vec3(0,0,0), glm::vec3(0), 1.f);
|
||||||
auto modelComponent = std::make_shared<ModelComponent>(modelStages, "stoneMason");
|
auto modelComponent = std::make_shared<ModelComponent>(modelStages, "stoneMason");
|
||||||
auto modelStateComponent = std::make_shared<ModelStateComponent>();
|
auto modelStateComponent = std::make_shared<ModelStateComponent>();
|
||||||
|
auto producingComponent = std::make_shared<ProducingComponent>(RessourceType::STONE, 2, false);
|
||||||
|
auto ownerComponent = std::make_shared<OwnerComponent>(gameMode->getCurrentPlayer());
|
||||||
modelStateComponent->params["fillRatio"] = 0.f;
|
modelStateComponent->params["fillRatio"] = 0.f;
|
||||||
modelComponent->updateStage("stone_mason_empty");
|
modelComponent->updateStage("stone_mason_empty");
|
||||||
EntityID entityID = entityManager->createEntity();
|
EntityID entityID = entityManager->createEntity();
|
||||||
entityManager->addComponent(entityID, transformComponent);
|
entityManager->addComponent(entityID, transformComponent);
|
||||||
entityManager->addComponent(entityID, modelComponent);
|
entityManager->addComponent(entityID, modelComponent);
|
||||||
entityManager->addComponent(entityID, modelStateComponent);
|
entityManager->addComponent(entityID, modelStateComponent);
|
||||||
|
entityManager->addComponent(entityID, producingComponent);
|
||||||
|
entityManager->addComponent(entityID, ownerComponent);
|
||||||
testEntity = entityID;
|
testEntity = entityID;
|
||||||
|
|
||||||
|
events.subscribe<TurnChangedEvent>([this](const TurnChangedEvent& event) {
|
||||||
|
ProducingSystem::onTurnEnded(*entityManager);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameLayer::onDetach()
|
void GameLayer::onDetach()
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
#include "ui/components/UiRessourceWidget.h"
|
#include "ui/components/UiRessourceWidget.h"
|
||||||
#include "ui/components/factorys/RessourceWidgetFactory.h"
|
#include "ui/components/factorys/RessourceWidgetFactory.h"
|
||||||
|
|
||||||
UILayer::UILayer(): events(Application::getInstance().getEventBus()) {
|
UILayer::UILayer() {
|
||||||
Loader& loader = Loader::instance();
|
Loader& loader = Loader::instance();
|
||||||
guiRenderer = std::make_unique<GUIRenderer>(loader);
|
guiRenderer = std::make_unique<GUIRenderer>(loader);
|
||||||
textRenderer = std::make_unique<TextRenderer>();
|
textRenderer = std::make_unique<TextRenderer>();
|
||||||
|
|||||||
@ -28,7 +28,7 @@ private:
|
|||||||
size_t inventoryContainerID;
|
size_t inventoryContainerID;
|
||||||
size_t turnTextID;
|
size_t turnTextID;
|
||||||
|
|
||||||
EventBus& events;
|
|
||||||
public:
|
public:
|
||||||
UILayer();
|
UILayer();
|
||||||
void onAttach() override;
|
void onAttach() override;
|
||||||
|
|||||||
@ -9,11 +9,9 @@
|
|||||||
|
|
||||||
|
|
||||||
class OwnerComponent : public Component{
|
class OwnerComponent : public Component{
|
||||||
private:
|
public:
|
||||||
PlayerID playerID;
|
PlayerID playerID;
|
||||||
|
explicit OwnerComponent(PlayerID playerID) : playerID(playerID) {};
|
||||||
public:
|
|
||||||
OwnerComponent(PlayerID playerID) : playerID(playerID) {};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
5
src/game/hexWorld/ecs/components/ProducingComponent.cpp
Normal file
5
src/game/hexWorld/ecs/components/ProducingComponent.cpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
//
|
||||||
|
// Created by sebastian on 14.02.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "ProducingComponent.h"
|
||||||
42
src/game/hexWorld/ecs/components/ProducingComponent.h
Normal file
42
src/game/hexWorld/ecs/components/ProducingComponent.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
//
|
||||||
|
// Created by sebastian on 14.02.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DICEWARS_SIEDLER_PRODUCINGCOMPONENT_H
|
||||||
|
#define DICEWARS_SIEDLER_PRODUCINGCOMPONENT_H
|
||||||
|
#include "../../../../engine/core/ECS/Component.h"
|
||||||
|
|
||||||
|
|
||||||
|
enum class RessourceType;
|
||||||
|
|
||||||
|
class ProducingComponent: public Component {
|
||||||
|
public:
|
||||||
|
ProducingComponent(RessourceType produces, int baseAmountPerTurn, bool isBlocked = false) : produces(produces), baseAmountPerTurn(baseAmountPerTurn), blocked(isBlocked) {}
|
||||||
|
|
||||||
|
[[nodiscard]] int getStorage() const {return storage;}
|
||||||
|
[[nodiscard]] RessourceType getProduces() const {return produces;}
|
||||||
|
[[nodiscard]] bool isBlocked() const {return blocked;}
|
||||||
|
[[nodiscard]] float getEfficiency() const {return efficiency;}
|
||||||
|
[[nodiscard]] int getMaxStorage() const {return maxStorage;}
|
||||||
|
[[nodiscard]] int getAmountPerTurn() const {return baseAmountPerTurn;}
|
||||||
|
|
||||||
|
void setBlocked(bool blocked) {this->blocked = blocked;}
|
||||||
|
void setStorage(int storage) {this->storage = storage;}
|
||||||
|
void setEfficiency(float efficiency) {this->efficiency = efficiency;}
|
||||||
|
void increaseStorage(int amount) {storage += amount;}
|
||||||
|
void decreaseStorage(int amount) {storage -= amount;}
|
||||||
|
void setMaxStorage(int maxStorage) {this->maxStorage = maxStorage;}
|
||||||
|
private:
|
||||||
|
RessourceType produces;
|
||||||
|
int baseAmountPerTurn;
|
||||||
|
|
||||||
|
int storage = 0;
|
||||||
|
int maxStorage = 20;
|
||||||
|
|
||||||
|
float efficiency = 1.0f;
|
||||||
|
|
||||||
|
bool blocked;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //DICEWARS_SIEDLER_PRODUCINGCOMPONENT_H
|
||||||
36
src/game/hexWorld/ecs/systems/ProducingSystem.cpp
Normal file
36
src/game/hexWorld/ecs/systems/ProducingSystem.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
//
|
||||||
|
// Created by sebastian on 14.02.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "ProducingSystem.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
#include "../../../../engine/core/ECS/EntityManager.h"
|
||||||
|
#include "../../../../engine/core/ECS/ModelStateComponent.h"
|
||||||
|
#include "../components/ProducingComponent.h"
|
||||||
|
|
||||||
|
void ProducingSystem::onTurnEnded(EntityManager &em) {
|
||||||
|
printf("Updating producing entities...\n");
|
||||||
|
for (const EntityID e : em.getAllEntities()) {
|
||||||
|
const auto prod = em.getComponent<ProducingComponent>(e);
|
||||||
|
const auto modelState = em.getComponent<ModelStateComponent>(e);
|
||||||
|
|
||||||
|
if (!prod || !modelState) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prod->isBlocked()) {
|
||||||
|
std::cout << "Producing is blocked for entity " << e << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int produced = prod->getAmountPerTurn();
|
||||||
|
prod->setStorage(std::min(prod->getStorage() + produced, prod->getMaxStorage()));
|
||||||
|
|
||||||
|
float fillRatio = static_cast<float>(prod->getStorage()) / static_cast<float>(prod->getMaxStorage());
|
||||||
|
modelState->params["fillRatio"] = fillRatio;
|
||||||
|
printf("Updated fillRatio: %f\n", fillRatio);
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/game/hexWorld/ecs/systems/ProducingSystem.h
Normal file
18
src/game/hexWorld/ecs/systems/ProducingSystem.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
//
|
||||||
|
// Created by sebastian on 14.02.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DICEWARS_SIEDLER_PRODUCINGSYSTEM_H
|
||||||
|
#define DICEWARS_SIEDLER_PRODUCINGSYSTEM_H
|
||||||
|
#include "../../../player/Player.h"
|
||||||
|
|
||||||
|
|
||||||
|
class EntityManager;
|
||||||
|
|
||||||
|
class ProducingSystem {
|
||||||
|
public:
|
||||||
|
static void onTurnEnded(EntityManager &em);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //DICEWARS_SIEDLER_PRODUCINGSYSTEM_H
|
||||||
Loading…
Reference in New Issue
Block a user