add basic types and fix cmake
This commit is contained in:
14
src/lib/core/BlueprintDropEvent.h
Normal file
14
src/lib/core/BlueprintDropEvent.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
// Emitted in tick step 9 (Deaths & loot) when a destroyed enemy-defence-station
|
||||
// set awards a blueprint (REQ-DEF-BLUEPRINT-DROP). The UI renders a toast
|
||||
// (REQ-UI-BLUEPRINT-TOAST); wasNewUnlock chooses between the "unlocked" and
|
||||
// "level -> N" wording.
|
||||
struct BlueprintDropEvent
|
||||
{
|
||||
std::string blueprintId; // matches ShipDef::id in the config.
|
||||
int newLevel;
|
||||
bool wasNewUnlock;
|
||||
};
|
||||
36
src/lib/core/BuildingType.cpp
Normal file
36
src/lib/core/BuildingType.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "BuildingType.h"
|
||||
|
||||
std::optional<BuildingType> parseBuildingType(const std::string& id)
|
||||
{
|
||||
if (id == "miner") { return BuildingType::Miner; }
|
||||
if (id == "smelter") { return BuildingType::Smelter; }
|
||||
if (id == "assembler") { return BuildingType::Assembler; }
|
||||
if (id == "reprocessing_plant") { return BuildingType::ReprocessingPlant; }
|
||||
if (id == "shipyard") { return BuildingType::Shipyard; }
|
||||
if (id == "salvage_bay") { return BuildingType::SalvageBay; }
|
||||
if (id == "belt") { return BuildingType::Belt; }
|
||||
if (id == "splitter") { return BuildingType::Splitter; }
|
||||
if (id == "hq") { return BuildingType::Hq; }
|
||||
if (id == "player_defence_station") { return BuildingType::PlayerDefenceStation; }
|
||||
if (id == "enemy_defence_station") { return BuildingType::EnemyDefenceStation; }
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::string buildingTypeId(BuildingType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case BuildingType::Miner: return "miner";
|
||||
case BuildingType::Smelter: return "smelter";
|
||||
case BuildingType::Assembler: return "assembler";
|
||||
case BuildingType::ReprocessingPlant: return "reprocessing_plant";
|
||||
case BuildingType::Shipyard: return "shipyard";
|
||||
case BuildingType::SalvageBay: return "salvage_bay";
|
||||
case BuildingType::Belt: return "belt";
|
||||
case BuildingType::Splitter: return "splitter";
|
||||
case BuildingType::Hq: return "hq";
|
||||
case BuildingType::PlayerDefenceStation: return "player_defence_station";
|
||||
case BuildingType::EnemyDefenceStation: return "enemy_defence_station";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
29
src/lib/core/BuildingType.h
Normal file
29
src/lib/core/BuildingType.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
// All building types defined in requirements.md. Belts and splitters share the
|
||||
// enum for cost/construction/placement/visuals lookup, but their runtime data
|
||||
// lives in the belt subsystem rather than in Building instances.
|
||||
enum class BuildingType
|
||||
{
|
||||
Miner,
|
||||
Smelter,
|
||||
Assembler,
|
||||
ReprocessingPlant,
|
||||
Shipyard,
|
||||
SalvageBay,
|
||||
Belt,
|
||||
Splitter,
|
||||
Hq,
|
||||
PlayerDefenceStation,
|
||||
EnemyDefenceStation,
|
||||
};
|
||||
|
||||
// Maps a config id string (e.g. "miner", "reprocessing_plant") to a
|
||||
// BuildingType. Returns std::nullopt for unknown ids.
|
||||
std::optional<BuildingType> parseBuildingType(const std::string& id);
|
||||
|
||||
// Canonical id string for a BuildingType. The inverse of parseBuildingType.
|
||||
std::string buildingTypeId(BuildingType type);
|
||||
26
src/lib/core/CMakeLists.txt
Normal file
26
src/lib/core/CMakeLists.txt
Normal file
@@ -0,0 +1,26 @@
|
||||
SET(HDRS
|
||||
${HDRS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Tick.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/EntityId.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Rotation.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BuildingType.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ItemType.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Item.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Port.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/MovementIntent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/FireEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BlueprintDropEvent.h
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
SET(SRCS
|
||||
${SRCS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BuildingType.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
set(LIB_INCLUDE_PATH
|
||||
${LIB_INCLUDE_PATH}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
PARENT_SCOPE
|
||||
)
|
||||
9
src/lib/core/EntityId.h
Normal file
9
src/lib/core/EntityId.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
// Canonical reference to every targetable entity in the simulation: ships,
|
||||
// scrap drops, and buildings (including HQ and defence stations).
|
||||
// Ids are allocated centrally by the Simulation, strictly increasing, never
|
||||
// reused. 0 is reserved as the invalid id.
|
||||
using EntityId = long long;
|
||||
|
||||
constexpr EntityId kInvalidEntityId = 0;
|
||||
14
src/lib/core/FireEvent.h
Normal file
14
src/lib/core/FireEvent.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "EntityId.h"
|
||||
#include "Tick.h"
|
||||
|
||||
// Transient record emitted each time a weapon fires (REQ-SHP-FIRING,
|
||||
// REQ-SHP-FIRING-BEAM). Buffered in a sim-owned queue and drained by the
|
||||
// renderer each frame to draw the 0.3-second laser beam.
|
||||
struct FireEvent
|
||||
{
|
||||
EntityId shooter;
|
||||
EntityId target;
|
||||
Tick emittedAt;
|
||||
};
|
||||
10
src/lib/core/Item.h
Normal file
10
src/lib/core/Item.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "ItemType.h"
|
||||
|
||||
// Items on belts have no persistent identity across ticks; see
|
||||
// architecture.md "Belt Subsystem".
|
||||
struct Item
|
||||
{
|
||||
ItemType type;
|
||||
};
|
||||
29
src/lib/core/ItemType.h
Normal file
29
src/lib/core/ItemType.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
// Opaque tagged id of every transportable material (ores, ingots,
|
||||
// intermediates, building_blocks, scrap). Defined in config; the simulation
|
||||
// does not enumerate item types.
|
||||
//
|
||||
// Wrapped in a struct (rather than a bare std::string typedef) so that function
|
||||
// signatures make the semantic intent explicit.
|
||||
struct ItemType
|
||||
{
|
||||
std::string id;
|
||||
};
|
||||
|
||||
inline bool operator==(const ItemType& a, const ItemType& b)
|
||||
{
|
||||
return a.id == b.id;
|
||||
}
|
||||
|
||||
inline bool operator!=(const ItemType& a, const ItemType& b)
|
||||
{
|
||||
return a.id != b.id;
|
||||
}
|
||||
|
||||
inline bool operator<(const ItemType& a, const ItemType& b)
|
||||
{
|
||||
return a.id < b.id;
|
||||
}
|
||||
12
src/lib/core/MovementIntent.h
Normal file
12
src/lib/core/MovementIntent.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <QVector2D>
|
||||
|
||||
// A ship-behavior system writes this each tick before movement runs; the
|
||||
// highest-priority write wins. Priority order is fixed globally — see
|
||||
// architecture.md "Movement Arbitration".
|
||||
struct MovementIntent
|
||||
{
|
||||
int priority;
|
||||
QVector2D target;
|
||||
};
|
||||
13
src/lib/core/Port.h
Normal file
13
src/lib/core/Port.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <QPoint>
|
||||
|
||||
#include "Rotation.h"
|
||||
|
||||
// Identifies a belt-adjacent cell and the direction of flow across it. Used by
|
||||
// the belt subsystem's push/pull interface.
|
||||
struct Port
|
||||
{
|
||||
QPoint tile;
|
||||
Rotation direction;
|
||||
};
|
||||
12
src/lib/core/Rotation.h
Normal file
12
src/lib/core/Rotation.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
// Rotation applied to a building's surface_mask when placed. Also the direction
|
||||
// of an output port or belt flow.
|
||||
// North = -Y (up), East = +X (right), South = +Y (down), West = -X (left).
|
||||
enum class Rotation
|
||||
{
|
||||
North,
|
||||
East,
|
||||
South,
|
||||
West,
|
||||
};
|
||||
23
src/lib/core/Tick.h
Normal file
23
src/lib/core/Tick.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
// Discrete simulation time, measured in ticks since t=0.
|
||||
using Tick = long long;
|
||||
|
||||
// Fixed simulation tick rate. See architecture.md "Fixed-Timestep Tick-Based Simulation".
|
||||
constexpr int kTickRateHz = 30;
|
||||
constexpr double kTickDurationMs = 1000.0 / kTickRateHz;
|
||||
constexpr double kTickDurationSeconds = 1.0 / kTickRateHz;
|
||||
|
||||
// Converts a wall-clock duration (in seconds, as it appears in config TOML) to
|
||||
// an integer tick count. Rounds to nearest to avoid systematic drift from
|
||||
// repeated conversions.
|
||||
constexpr Tick secondsToTicks(double seconds)
|
||||
{
|
||||
return static_cast<Tick>(seconds * kTickRateHz + 0.5);
|
||||
}
|
||||
|
||||
// Inverse of secondsToTicks; useful for logging and UI display.
|
||||
constexpr double ticksToSeconds(Tick ticks)
|
||||
{
|
||||
return static_cast<double>(ticks) / kTickRateHz;
|
||||
}
|
||||
Reference in New Issue
Block a user