ADD: Add Stone Mason Building Type

This commit is contained in:
sebastian 2026-02-13 18:21:16 +01:00
parent 36900334d0
commit 687a4197e9
13 changed files with 86 additions and 11 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 MiB

View File

@ -0,0 +1,12 @@
# Blender 5.0.1 MTL File: 'None'
# www.blender.org
newmtl _Faerberhaus_FaerberhausFaerberhaus
Ns 0.000000
Ka 1.000000 1.000000 1.000000
Ks 0.000000 0.000000 0.000000
Ke 0.000000 0.000000 0.000000
Ni 1.500000
d 1.000000
illum 1
map_Kd /home/sebastian/Downloads/prehistoric-house-asparn/source/Asparn_Weberhaus3/Faerberhaus.jpg

View File

@ -54,8 +54,15 @@ void GameLayer::onAttach()
auto cabinModel = AssetManager::loadModel("cabin", "assets/cabin/cabin.obj", "assets/cabin/cabin.jpg", loader); auto cabinModel = AssetManager::loadModel("cabin", "assets/cabin/cabin.obj", "assets/cabin/cabin.jpg", loader);
auto stoneMasonModel = AssetManager::loadModel("stoneMason", "assets/prehistoric_house/stone_mason.obj", "assets/prehistoric_house/Faerberhaus.jpg", loader);
//entities.push_back(std::make_shared<Entity>(Entity(cabinModel, glm::vec3(0,0,0), 0,0,0, 1.f))); //entities.push_back(std::make_shared<Entity>(Entity(cabinModel, glm::vec3(0,0,0), 0,0,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>(stoneMasonModel);
EntityID entityID = entityManager->createEntity();
entityManager->addComponent(entityID, transformComponent);
entityManager->addComponent(entityID, modelComponent);*/
} }
void GameLayer::onDetach() void GameLayer::onDetach()
@ -74,6 +81,12 @@ void GameLayer::onUpdate()
if (InputManager::isKeyPressed(GLFW_KEY_A)) moveDir.x -= 1.0f; if (InputManager::isKeyPressed(GLFW_KEY_A)) moveDir.x -= 1.0f;
if (InputManager::isKeyPressed(GLFW_KEY_D)) moveDir.x += 1.0f; if (InputManager::isKeyPressed(GLFW_KEY_D)) moveDir.x += 1.0f;
if (InputManager::isKeyPressed(GLFW_KEY_1)) {
gameMode->setActiveBuilding(BuildingType::FOREST_HUT);
} else if (InputManager::isKeyPressed(GLFW_KEY_2)) {
gameMode->setActiveBuilding(BuildingType::STONE_MASON);
}
camera->move(moveDir, 0.5f); camera->move(moveDir, 0.5f);
tileHighlightSystem->update(*entityManager, *mousePicker, *camera); tileHighlightSystem->update(*entityManager, *mousePicker, *camera);

View File

@ -54,4 +54,16 @@ void GameMode::pay(PlayerID playerID, const std::unordered_map<RessourceType, in
} }
} }
std::optional<BuildingType> GameMode::getActiveBuilding() const {
return activeBuilding;
}
void GameMode::clearActiveBuilding() {
activeBuilding = std::nullopt;
}
void GameMode::setActiveBuilding(BuildingType buildingType) {
activeBuilding = buildingType;
}

View File

@ -4,6 +4,8 @@
#ifndef GAMEMODE_H #ifndef GAMEMODE_H
#define GAMEMODE_H #define GAMEMODE_H
#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 "player/Player.h" #include "player/Player.h"
@ -24,10 +26,12 @@ public:
PlayerInventory& getPlayerInventory(PlayerID playerID); PlayerInventory& getPlayerInventory(PlayerID playerID);
void pay(PlayerID uint32, const std::unordered_map<RessourceType, int> & pairs); void pay(PlayerID uint32, const std::unordered_map<RessourceType, int> & pairs);
std::optional<BuildingType> getActiveBuilding() const;
void clearActiveBuilding();
void setActiveBuilding(BuildingType buildingType);
private: private:
std::unordered_map<PlayerID, Player> players; std::unordered_map<PlayerID, Player> players;
std::optional<BuildingType> activeBuilding;
}; };

View File

@ -8,8 +8,11 @@
const BuildingDefinition & BuildingConfig::get(BuildingType type) { const BuildingDefinition & BuildingConfig::get(BuildingType type) {
if (type == BuildingType::FOREST_HUT) { if (type == BuildingType::FOREST_HUT) {
static const BuildingDefinition def = TemporaryBuildingDefinitionFactory::createForestHutDefinition(); static const BuildingDefinition forest_hut_def = TemporaryBuildingDefinitionFactory::createForestHutDefinition();
return def; return forest_hut_def;
} else if (type == BuildingType::STONE_MASON) {
static const BuildingDefinition stone_mason_def = TemporaryBuildingDefinitionFactory::createStoneMasonDefinition();
return stone_mason_def;
} }
std::__throw_runtime_error("Unknown BuildingType"); std::__throw_runtime_error("Unknown BuildingType");
} }

View File

@ -15,9 +15,17 @@ EntityID BuildingFactory::create(EntityManager &em, const BuildingDefinition &de
em.addComponent(e, std::make_shared<ModelComponent>(AssetManager::getModel(def.model))); em.addComponent(e, std::make_shared<ModelComponent>(AssetManager::getModel(def.model)));
if (def.type == BuildingType::FOREST_HUT) {
em.addComponent(e, std::make_shared<TransformComponent>( em.addComponent(e, std::make_shared<TransformComponent>(
tileTransform.position, glm::vec3(0), 1.f tileTransform.position, glm::vec3(0), 1.f
)); ));
} else {
em.addComponent(e, std::make_shared<TransformComponent>(
tileTransform.position, glm::vec3(0), 2.f
));
}
em.addComponent(e, std::make_shared<BuildingComponent>(def.type, tileEntity)); em.addComponent(e, std::make_shared<BuildingComponent>(def.type, tileEntity));

View File

@ -18,6 +18,19 @@ namespace TemporaryBuildingDefinitionFactory {
"cabin" "cabin"
}; };
} }
static inline BuildingDefinition createStoneMasonDefinition() {
auto allowedTileResources = std::vector<RessourceType>{RessourceType::STONE};
auto resourceCosts = std::unordered_map<RessourceType, int>{};
resourceCosts[RessourceType::WOOD] = 15;
resourceCosts[RessourceType::STONE] = 10;
return {
BuildingType::FOREST_HUT,
allowedTileResources,
resourceCosts,
"stoneMason"
};
}
} }
#endif //DICEWARS_SIEDLER_TEMPORARYBUILDINGDEFINITIONFACTORY_H #endif //DICEWARS_SIEDLER_TEMPORARYBUILDINGDEFINITIONFACTORY_H

View File

@ -7,7 +7,8 @@
#include "../../../../engine/core/ECS/EntityManager.h" #include "../../../../engine/core/ECS/EntityManager.h"
enum class BuildingType { enum class BuildingType {
FOREST_HUT FOREST_HUT,
STONE_MASON
}; };

View File

@ -31,7 +31,14 @@ void BuildingPlacementSystem::update(EntityManager& entityManager, GameMode& gam
if (!transform || !gameplay || !render) continue; if (!transform || !gameplay || !render) continue;
if (!render->isHighlighted) continue; if (!render->isHighlighted) continue;
const auto &def = BuildingConfig::get(BuildingType::FOREST_HUT); 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; if (!BuildingRules::canPlace(def, *gameplay, gameMode, player)) continue;

View File

@ -7,6 +7,7 @@
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility>
#include "PlayerInventory.h" #include "PlayerInventory.h"
@ -21,8 +22,9 @@ private:
public: public:
Player() = default; Player() = default;
Player(const PlayerID playerID, const std::string& name) : playerID(playerID), name(std::move(name)) { Player(const PlayerID playerID, std::string name) : playerID(playerID), name(std::move(name)) {
inventory->add(RessourceType::WOOD, 100); inventory->add(RessourceType::WOOD, 100);
inventory->add(RessourceType::STONE, 178);
}; };
const std::unique_ptr<PlayerInventory> &getInventory() const; const std::unique_ptr<PlayerInventory> &getInventory() const;