implement building system

This commit is contained in:
2026-04-19 20:50:42 +02:00
parent c70b5c8f08
commit bf29cc40e3
19 changed files with 1818 additions and 7 deletions

76
src/lib/sim/Building.h Normal file
View File

@@ -0,0 +1,76 @@
#pragma once
#include <map>
#include <optional>
#include <string>
#include <vector>
#include <QPoint>
#include <QSize>
#include "BuildingType.h"
#include "EntityId.h"
#include "Item.h"
#include "ItemType.h"
#include "Port.h"
#include "Rotation.h"
#include "Tick.h"
// Per-material input buffer for a production building.
struct InputBuffer
{
std::map<ItemType, int> counts; // current item counts per material
std::map<ItemType, int> caps; // max items per material (2× per-cycle requirement)
};
// Output buffer shared by all output materials for a production building.
struct OutputBuffer
{
std::vector<Item> items;
int capacity = 0; // 2× per-cycle output; 1× for ReprocessingPlant
};
// Active production cycle for a building.
struct Production
{
std::string recipeId;
Tick completesAt = 0;
std::vector<Item> chosenOutputs; // resolved at cycle start (reprocessing rolls here)
};
// A building placed on the map that is still under construction.
// Occupies tiles but does not produce.
struct ConstructionSite
{
EntityId id = kInvalidEntityId;
QPoint anchor; // top-left of body bounding box
QSize footprint;
std::vector<QPoint> bodyCells; // absolute world tile coordinates
Rotation rotation = Rotation::East;
BuildingType type = BuildingType::Miner;
std::string recipeId; // may be configured before completion
Tick completesAt = 0; // 0 = queued but not yet started
};
// A fully constructed, operational building.
struct Building
{
EntityId id = kInvalidEntityId;
QPoint anchor; // top-left of body bounding box
QSize footprint;
Rotation rotation = Rotation::East;
BuildingType type = BuildingType::Miner;
float hp = 0.0f;
float maxHp = 0.0f;
std::string recipeId; // empty = none selected
InputBuffer inputBuffer;
OutputBuffer outputBuffer;
std::optional<Production> production;
// Pre-computed from surface mask at placement; in absolute world coordinates.
std::vector<QPoint> bodyCells;
std::vector<Port> outputPorts;
std::vector<Port> inputPorts; // perimeter tiles (minus output-port tiles),
// direction pointing INTO building
};