35 lines
1.0 KiB
C++
35 lines
1.0 KiB
C++
//
|
|
// 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) {
|
|
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;
|
|
}
|
|
}
|