62 lines
2.3 KiB
C++
62 lines
2.3 KiB
C++
//
|
|
// Created by sebastian on 08.02.26.
|
|
//
|
|
|
|
#include "BuildingPlacementSystem.h"
|
|
|
|
#include "../../RessourceType.h"
|
|
#include "../../../../engine/core/Application.h"
|
|
#include "../../../../engine/core/ECS/ModelComponent.h"
|
|
#include "../../../../engine/core/ECS/TileRenderComponent.h"
|
|
#include "../../../../engine/core/ECS/TransformComponent.h"
|
|
#include "../../../../engine/platform/glfw/InputManager.h"
|
|
#include "../../../../engine/renderer/loader/AssetManager.h"
|
|
#include "../../building/BuildingConfig.h"
|
|
#include "../../building/BuildingFactory.h"
|
|
#include "../../building/BuildingRules.h"
|
|
#include "../../gameplay/TurnState.h"
|
|
#include "../components/BuildingComponent.h"
|
|
#include "../components/TileGameplayComponent.h"
|
|
#include "GLFW/glfw3.h"
|
|
|
|
void BuildingPlacementSystem::update(EntityManager& entityManager, GameMode& gameMode, PlayerID player, const TurnState& turnState) {
|
|
if (!gameMode.hasTurn(player, turnState.currentTurn)) {
|
|
return;
|
|
}
|
|
|
|
if (!InputManager::isMouseButtonPressed(GLFW_MOUSE_BUTTON_LEFT)) {
|
|
return;
|
|
}
|
|
|
|
for (EntityID entityID : entityManager.getAllEntities()) {
|
|
auto transform = entityManager.getComponent<TransformComponent>(entityID);
|
|
auto gameplay = entityManager.getComponent<TileGameplayComponent>(entityID);
|
|
auto render = entityManager.getComponent<TileRenderComponent>(entityID);
|
|
|
|
if (!transform || !gameplay || !render) continue;
|
|
if (!render->isHighlighted) continue;
|
|
|
|
BuildingDefinition def;
|
|
if (gameMode.getActiveBuilding() == BuildingType::FOREST_HUT) {
|
|
def = BuildingConfig::get(BuildingType::FOREST_HUT);
|
|
} else if (gameMode.getActiveBuilding() == BuildingType::STONE_MASON) {
|
|
def = BuildingConfig::get(BuildingType::STONE_MASON);
|
|
} else {
|
|
continue;
|
|
}
|
|
|
|
if (!BuildingRules::canPlace(def, *gameplay, gameMode, player)) continue;
|
|
|
|
gameMode.pay(player, def.resourceCosts);
|
|
|
|
for (auto e : gameplay->entitiesOnTile) {
|
|
entityManager.destroyEntity(e);
|
|
}
|
|
gameplay->entitiesOnTile.clear();
|
|
|
|
const EntityID buildingEntity = BuildingFactory::create(entityManager, def, *transform, entityID, player);
|
|
gameplay->buildingEntityID = buildingEntity;
|
|
break;
|
|
}
|
|
};
|