ADD: ProducingSystem for placed Buildings

This commit is contained in:
sebastian 2026-02-14 09:44:32 +01:00
parent 2c1c5b2d63
commit 994ad89c13
17 changed files with 528199 additions and 150633 deletions

View File

Before

Width:  |  Height:  |  Size: 2.8 MiB

After

Width:  |  Height:  |  Size: 2.8 MiB

View File

@ -0,0 +1,28 @@
{
"name": "cabin",
"allowedTileResources" : ["stone"],
"cost" : {"wood": 15},
"modelStages": [
{
"name": "cabin-base",
"filename": "cabin.obj",
"conditionKey": "fillRatio",
"minValue": 0.0,
"maxValue": 0.1
},
{
"name": "cabin-one",
"filename": "cabin_1.obj",
"conditionKey": "fillRatio",
"minValue": 0.1,
"maxValue": 0.2
},
{
"name": "cabin-two",
"filename": "cabin_2.obj",
"conditionKey": "fillRatio",
"minValue": 0.2,
"maxValue": 1.0
}
]
}

View File

@ -0,0 +1,12 @@
# Blender 5.0.1 MTL File: 'Untitled.blend'
# www.blender.org
newmtl Material_0.003
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.500000
d 1.000000
illum 2
map_Kd textures/forest_hut.png

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 909 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 909 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 MiB

View File

@ -1,31 +0,0 @@
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
# File Created: 03.06.2013 16:07:05
newmtl 20958_Log_Cabin_v1
Ns 18.0000
Ni 1.5000
d 1.0000
Tr 0.0000
Tf 1.0000 1.0000 1.0000
illum 2
Ka 1.0000 1.0000 1.0000
Kd 1.0000 1.0000 1.0000
Ks 0.3240 0.3240 0.3240
Ke 0.0000 0.0000 0.0000
map_Ka cabin.jpg
map_Kd cabin.jpg
map_Ks 20958_Log_Cabin_v1_specular.jpg
newmtl 02___Default
Ns 10.0000
Ni 1.5000
d 1.0000
Tr 0.0000
Tf 1.0000 1.0000 1.0000
illum 2
Ka 1.0000 1.0000 1.0000
Kd 1.0000 1.0000 1.0000
Ks 0.0000 0.0000 0.0000
Ke 0.0000 0.0000 0.0000
map_Ka disc_diffuse.JPG
map_Kd disc_diffuse.JPG

File diff suppressed because it is too large Load Diff

View File

@ -49,38 +49,9 @@ void GameLayer::onAttach()
const std::string stoneMasonPath = "assets/buildings/stone_mason/";
auto cabinModel = AssetManager::loadModel("cabin", "assets/cabin/cabin.obj", "assets/cabin/cabin.jpg", loader);
auto stoneMasonModel = AssetManager::loadModel("stoneMason", stoneMasonPath + "stone_mason.obj", stoneMasonPath + "stone_mason.png", loader);
//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);*/
AssetManager::loadAsset("assets/buildings/stone_mason/stone_mason.json", loader);
auto modelStages = AssetManager::getModelStages("stoneMason");
AssetManager::loadAsset("assets/buildings/forest_hut/cabin.json", loader);
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 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;
modelComponent->updateStage("stone_mason_empty");
EntityID entityID = entityManager->createEntity();
entityManager->addComponent(entityID, transformComponent);
entityManager->addComponent(entityID, modelComponent);
entityManager->addComponent(entityID, modelStateComponent);
entityManager->addComponent(entityID, producingComponent);
entityManager->addComponent(entityID, ownerComponent);
testEntity = entityID;
events.subscribe<TurnChangedEvent>([this](const TurnChangedEvent& event) {
ProducingSystem::onTurnEnded(*entityManager);

View File

@ -13,6 +13,11 @@ struct BuildingDefinition {
std::unordered_map<RessourceType, int> resourceCosts;
std::string model;
int maxStorage;
int baseAmountPerTurn;
RessourceType produces;
};
#endif //DICEWARS_SIEDLER_BUILDINGDEFINITION_H

View File

@ -5,15 +5,17 @@
#include "BuildingFactory.h"
#include "../../../engine/core/ECS/ModelComponent.h"
#include "../../../engine/core/ECS/ModelStateComponent.h"
#include "../../../engine/core/ECS/TransformComponent.h"
#include "../../../engine/renderer/loader/AssetManager.h"
#include "../ecs/components/ProducingComponent.h"
EntityID BuildingFactory::create(EntityManager &em, const BuildingDefinition &def,
const TransformComponent &tileTransform, EntityID tileEntity, PlayerID owner) {
EntityID e = em.createEntity();
em.addComponent(e, std::make_shared<ModelComponent>(AssetManager::getModel(def.model), def.model));
em.addComponent(e, std::make_shared<ModelComponent>(AssetManager::getModelStages(def.model), def.model));
if (def.type == BuildingType::FOREST_HUT) {
em.addComponent(e, std::make_shared<TransformComponent>(
@ -31,5 +33,14 @@ EntityID BuildingFactory::create(EntityManager &em, const BuildingDefinition &de
em.addComponent(e, std::make_shared<OwnerComponent>(owner));
auto modelStateComponent = std::make_shared<ModelStateComponent>();
modelStateComponent->params["fillRatio"] = 0.f;
auto producingComponent = std::make_shared<ProducingComponent>( ProducingComponent(def.produces, def.baseAmountPerTurn, false));
producingComponent->setMaxStorage(def.maxStorage);
em.addComponent(e, modelStateComponent);
em.addComponent(e, producingComponent);
return e;
}

View File

@ -15,7 +15,8 @@ namespace TemporaryBuildingDefinitionFactory {
BuildingType::FOREST_HUT,
allowedTileResources,
resourceCosts,
"cabin"
"cabin",
20, 1, RessourceType::WOOD
};
}
@ -28,7 +29,8 @@ namespace TemporaryBuildingDefinitionFactory {
BuildingType::FOREST_HUT,
allowedTileResources,
resourceCosts,
"stoneMason"
"stoneMason",
20, 1, RessourceType::STONE
};
}
}

View File

@ -12,7 +12,6 @@
#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);
@ -31,6 +30,5 @@ void ProducingSystem::onTurnEnded(EntityManager &em) {
float fillRatio = static_cast<float>(prod->getStorage()) / static_cast<float>(prod->getMaxStorage());
modelState->params["fillRatio"] = fillRatio;
printf("Updated fillRatio: %f\n", fillRatio);
}
}