Compare commits
24 Commits
0.1.1
...
ae41f677e6
| Author | SHA1 | Date | |
|---|---|---|---|
| ae41f677e6 | |||
| 1914705ab9 | |||
| aec65446d5 | |||
| 1f339bd8d7 | |||
| 8dc76284e6 | |||
| a8a6a04f1e | |||
| a75222f111 | |||
| 9b63af6ccb | |||
| 4ca5b332cd | |||
| 0c4eb480be | |||
| b2c1ea34fd | |||
| 1cbc695bc5 | |||
| c7ecce6ac4 | |||
| be475e2836 | |||
| 9622fa4345 | |||
| 1cdafb7bcd | |||
| f205136e21 | |||
| b708e1b29d | |||
| c76ba07bc7 | |||
| b2e7e4897a | |||
| c21af63e84 | |||
| a4267a4760 | |||
| d412c69f82 | |||
| 08752aeced |
@@ -24,7 +24,7 @@ set(CMAKE_BUILD_TYPE_INIT "Release")
|
||||
|
||||
# Qt ---------------------------------------------------------------------------
|
||||
|
||||
find_package(Qt5 COMPONENTS Widgets Network Multimedia Charts REQUIRED)
|
||||
find_package(Qt5 COMPONENTS Widgets Network Multimedia Charts Svg REQUIRED)
|
||||
|
||||
if(Qt5Widgets_FOUND)
|
||||
message(STATUS "Found Qt ${Qt5Widgets_VERSION_STRING}")
|
||||
@@ -64,6 +64,7 @@ function(COPY_QT_BINARIES TARGET_DIR IS_DEBUG)
|
||||
configure_file("${QT_BINARY_DIR}/Qt5Network${SUFFIX}.dll" "${TARGET_DIR}/Qt5Network${SUFFIX}.dll" COPYONLY)
|
||||
configure_file("${QT_BINARY_DIR}/Qt5Widgets${SUFFIX}.dll" "${TARGET_DIR}/Qt5Widgets${SUFFIX}.dll" COPYONLY)
|
||||
configure_file("${QT_BINARY_DIR}/Qt5Multimedia${SUFFIX}.dll" "${TARGET_DIR}/Qt5Multimedia${SUFFIX}.dll" COPYONLY)
|
||||
configure_file("${QT_BINARY_DIR}/Qt5Svg${SUFFIX}.dll" "${TARGET_DIR}/Qt5Svg${SUFFIX}.dll" COPYONLY)
|
||||
endfunction(COPY_QT_BINARIES)
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ surface_mask = ["<A>"]
|
||||
|
||||
[[building]]
|
||||
id = "tunnel_entry"
|
||||
tooltip = "Sends items underground to a matching tunnel exit, letting belts cross."
|
||||
tooltip = "Sends items underground so belts can cross. Places an entry, or an exit when it would connect to a matching entry under the cursor."
|
||||
cost = 5
|
||||
player_placeable = true
|
||||
construction_time_seconds = 0.5
|
||||
|
||||
@@ -7,10 +7,9 @@
|
||||
# Combat stats are placeholders until the arena balancing pass;
|
||||
# production_time_seconds values come from the numbers pass.
|
||||
#
|
||||
# Unlock progression is mostly disabled (unlock_at_station_level = -1) pending
|
||||
# the pacing pass. The railguns are the exception: railgun_m is gated to
|
||||
# station level 1, and railgun_l requires railgun_m to be unlocked first
|
||||
# (unlock_requires) — a demonstration of the prerequisite chain.
|
||||
# Unlock gating is defined in unlocks.toml, not here (REQ-LOCK-EXPLICIT): a
|
||||
# module id granted by an unlock group starts locked and is awarded via a
|
||||
# defence station drop; ids absent from unlocks.toml (railgun_s) start unlocked.
|
||||
#
|
||||
# Surface mask footprint ladder — footprints gate which hulls can mount a
|
||||
# module, purely through geometry (see ships.toml for the matching hull
|
||||
@@ -33,7 +32,6 @@
|
||||
[[module]]
|
||||
id = "railgun_s"
|
||||
tooltip = "Small railgun. Fast-firing, short range, low damage; fits any hull."
|
||||
unlock_at_station_level = -1
|
||||
surface_mask = ["O"]
|
||||
materials = [{item = "railgun_s_module", amount = 1}]
|
||||
production_time_seconds = 1
|
||||
@@ -49,7 +47,6 @@ attack_rate_hz = 2.0
|
||||
[[module]]
|
||||
id = "railgun_m"
|
||||
tooltip = "Medium railgun. Higher damage at longer range; needs a 2x2 slot."
|
||||
unlock_at_station_level = 2
|
||||
surface_mask = [
|
||||
"OO",
|
||||
"OO"]
|
||||
@@ -67,8 +64,6 @@ attack_rate_hz = 1.5
|
||||
[[module]]
|
||||
id = "railgun_l"
|
||||
tooltip = "Large railgun. Heavy damage at long range; needs a 3x3 slot."
|
||||
unlock_at_station_level = 6
|
||||
unlock_requires = ["railgun_m"]
|
||||
surface_mask = [
|
||||
"OOO",
|
||||
"OOO",
|
||||
@@ -90,7 +85,6 @@ attack_rate_hz = 0.8
|
||||
[[module]]
|
||||
id = "salvager"
|
||||
tooltip = "Collects scrap from wrecks and stores it in the ship's cargo hold."
|
||||
unlock_at_station_level = -1
|
||||
surface_mask = ["O"]
|
||||
materials = [{item = "salvager_module", amount = 1}]
|
||||
production_time_seconds = 1
|
||||
@@ -106,7 +100,6 @@ collection_rate_hz = 0.5
|
||||
[[module]]
|
||||
id = "repair_tool"
|
||||
tooltip = "Repairs damaged friendly ships and defence stations within range."
|
||||
unlock_at_station_level = 0
|
||||
surface_mask = ["O"]
|
||||
materials = [{item = "repair_tool_module", amount = 1}]
|
||||
production_time_seconds = 1
|
||||
@@ -125,7 +118,6 @@ repair_range_m = 80
|
||||
[[module]]
|
||||
id = "afterburner"
|
||||
tooltip = "Greatly boosts top speed and forward acceleration."
|
||||
unlock_at_station_level = 2
|
||||
surface_mask = ["OOO"]
|
||||
materials = [{item = "afterburner_module", amount = 1}]
|
||||
production_time_seconds = 1
|
||||
@@ -140,7 +132,6 @@ added_main_acceleration_mpss = 60
|
||||
[[module]]
|
||||
id = "maneuvering_thrusters"
|
||||
tooltip = "Improves top speed and lateral/braking acceleration."
|
||||
unlock_at_station_level = 1
|
||||
surface_mask = ["OO"]
|
||||
materials = [{item = "maneuvering_thrusters_module", amount = 1}]
|
||||
production_time_seconds = 1
|
||||
@@ -158,7 +149,6 @@ added_maneuvering_acceleration_mpss = 10
|
||||
[[module]]
|
||||
id = "armor_plates"
|
||||
tooltip = "Adds a large flat bonus to the ship's hit points."
|
||||
unlock_at_station_level = 0
|
||||
surface_mask = ["OO"]
|
||||
materials = [{item = "armor_plates_module", amount = 1}]
|
||||
production_time_seconds = 1
|
||||
@@ -172,7 +162,6 @@ added_hp = 1200
|
||||
[[module]]
|
||||
id = "sensor_booster"
|
||||
tooltip = "Extends the ship's sensor range."
|
||||
unlock_at_station_level = 1
|
||||
surface_mask = ["OO"]
|
||||
materials = [{item = "sensor_booster_module", amount = 1}]
|
||||
production_time_seconds = 1
|
||||
@@ -189,7 +178,6 @@ added_sensor_range_m = 50
|
||||
[[module]]
|
||||
id = "weapon_upgrade"
|
||||
tooltip = "Increases the damage of all weapons on the ship."
|
||||
unlock_at_station_level = 4
|
||||
surface_mask = [
|
||||
"OO",
|
||||
"OX",
|
||||
@@ -206,7 +194,6 @@ multiplied_damage = 1.2
|
||||
[[module]]
|
||||
id = "weapon_primer"
|
||||
tooltip = "Increases the fire rate of all weapons on the ship."
|
||||
unlock_at_station_level = 4
|
||||
surface_mask = [
|
||||
"OO",
|
||||
"OX",
|
||||
@@ -223,7 +210,6 @@ multiplied_attack_rate_hz = 1.2
|
||||
[[module]]
|
||||
id = "weapon_stabilizer"
|
||||
tooltip = "Extends weapon range at the cost of some fire rate."
|
||||
unlock_at_station_level = 3
|
||||
surface_mask = [
|
||||
"OO",
|
||||
"OX",
|
||||
@@ -247,7 +233,6 @@ multiplied_attack_rate_hz = 0.8
|
||||
[[module]]
|
||||
id = "drone_bay"
|
||||
tooltip = "Drone launch bay (capability not yet implemented)."
|
||||
unlock_at_station_level = 5
|
||||
surface_mask = [
|
||||
"OO",
|
||||
"OO"]
|
||||
@@ -260,7 +245,6 @@ glyph = "Db"
|
||||
[[module]]
|
||||
id = "drone_hangar"
|
||||
tooltip = "Large drone hangar (capability not yet implemented)."
|
||||
unlock_at_station_level = 9
|
||||
surface_mask = [
|
||||
"OOOOOO",
|
||||
"OOOOOO"]
|
||||
|
||||
@@ -142,12 +142,12 @@ duration_seconds = 1.5
|
||||
|
||||
# Depth-3 chain (ore -> ingot -> plate -> block) is the factory's
|
||||
# doubling-time knob; see the block economy rules in docs/balancing/rules.md.
|
||||
# Explicitly unlocked at start (-1): building blocks appear in no
|
||||
# schematic's materials, so implicit unlocking can never reach this recipe.
|
||||
# unlocked_at_start: building blocks appear in no schematic's materials, so the
|
||||
# implicit item graph can never reach this recipe (REQ-LOCK-IMPLICIT).
|
||||
[[recipe]]
|
||||
id = "building_block"
|
||||
unlock_at_station_level = -1
|
||||
building = "assembler"
|
||||
unlocked_at_start = true
|
||||
inputs = [{item = "steel_plate", amount = 2}]
|
||||
outputs = [{item = "building_block", amount = 4}]
|
||||
duration_seconds = 2.0
|
||||
@@ -220,15 +220,14 @@ outputs = [{item = "capital_core", amount = 1}]
|
||||
duration_seconds = 10.0
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Shortcut recipes — drop-only assembler recipe schematics
|
||||
# (unlock_at_station_level >= 0). Pure rewards: item threat stays defined by
|
||||
# Shortcut recipes — drop-only assembler recipes, gated by unlock groups in
|
||||
# unlocks.toml (REQ-LOCK-EXPLICIT). Pure rewards: item threat stays defined by
|
||||
# the base (expensive) path via the max rule, so shortcuts give real factory
|
||||
# efficiency without shifting any balance.
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
[[recipe]]
|
||||
id = "shortcut_steel_plate"
|
||||
unlock_at_station_level = 1
|
||||
building = "assembler"
|
||||
inputs = [{item = "iron_ore", amount = 3}]
|
||||
outputs = [{item = "steel_plate", amount = 1}]
|
||||
@@ -236,7 +235,6 @@ duration_seconds = 2.0
|
||||
|
||||
[[recipe]]
|
||||
id = "shortcut_control_chip"
|
||||
unlock_at_station_level = 2
|
||||
building = "assembler"
|
||||
inputs = [{item = "quartz", amount = 2}]
|
||||
outputs = [{item = "control_chip", amount = 1}]
|
||||
@@ -244,7 +242,6 @@ duration_seconds = 4.0
|
||||
|
||||
[[recipe]]
|
||||
id = "shortcut_hardened_steel"
|
||||
unlock_at_station_level = 2
|
||||
building = "assembler"
|
||||
inputs = [{item = "iron_ingot", amount = 4}]
|
||||
outputs = [{item = "hardened_steel", amount = 1}]
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
# content; stats, materials, and production times are placeholders until the
|
||||
# recipe and balancing passes.
|
||||
#
|
||||
# Unlock progression is mostly disabled (unlock_at_station_level = -1) pending
|
||||
# the balancing pass. The capital hulls are the exception: battleship is gated
|
||||
# to station level 1, and dreadnought (level 2) requires battleship to be
|
||||
# unlocked first (unlock_requires) — a demonstration of the prerequisite chain.
|
||||
# Unlock gating is defined in unlocks.toml, not here (REQ-LOCK-EXPLICIT): a ship
|
||||
# id granted by an unlock group starts locked and is awarded via a defence
|
||||
# station drop; ids absent from unlocks.toml (drone, frigate) start unlocked.
|
||||
#
|
||||
# Size classes:
|
||||
# xs drone 1 cell — exactly one 1x1 module
|
||||
@@ -22,7 +21,6 @@
|
||||
|
||||
[[ship]]
|
||||
id = "drone"
|
||||
unlock_at_station_level = -1
|
||||
layout = ["O"]
|
||||
default_modules = [{type = "railgun_s", x = 0, y = 0, rotation = "east"}]
|
||||
|
||||
@@ -49,7 +47,6 @@ sensor_range_m = 150
|
||||
# L-shaped weapon modifier, or an afterburner spanning the full center line.
|
||||
[[ship]]
|
||||
id = "frigate"
|
||||
unlock_at_station_level = -1
|
||||
layout = [
|
||||
"XOX",
|
||||
"OOO",
|
||||
@@ -84,7 +81,6 @@ sensor_range_m = 200
|
||||
# mount medium hardware.
|
||||
[[ship]]
|
||||
id = "destroyer"
|
||||
unlock_at_station_level = 0
|
||||
layout = [
|
||||
"OXOXO",
|
||||
"OOOOO",
|
||||
@@ -120,7 +116,6 @@ sensor_range_m = 220
|
||||
# supports; no 3x3 area exists for an l gun.
|
||||
[[ship]]
|
||||
id = "cruiser"
|
||||
unlock_at_station_level = 2
|
||||
layout = [
|
||||
"XOOX",
|
||||
"OOOO",
|
||||
@@ -158,8 +153,6 @@ sensor_range_m = 250
|
||||
# stern leave no 3x3 area for an l gun and no 2x6 area for a drone hangar.
|
||||
[[ship]]
|
||||
id = "battlecruiser"
|
||||
unlock_at_station_level = 4
|
||||
unlock_requires = ["cruiser"]
|
||||
layout = [
|
||||
"OOXXOO",
|
||||
"OOOOOO",
|
||||
@@ -201,8 +194,6 @@ sensor_range_m = 260
|
||||
# so no 2x6 drone hangar fits.
|
||||
[[ship]]
|
||||
id = "battleship"
|
||||
unlock_at_station_level = 6
|
||||
unlock_requires = ["battlecruiser"]
|
||||
layout = [
|
||||
"XOOOOX",
|
||||
"OOOOOO",
|
||||
@@ -244,8 +235,6 @@ sensor_range_m = 280
|
||||
# stay the only hangar hull. Bow and stern strips hold supports.
|
||||
[[ship]]
|
||||
id = "dreadnought"
|
||||
unlock_at_station_level = 8
|
||||
unlock_requires = ["battleship"]
|
||||
layout = [
|
||||
"XXXOOOOOXXX",
|
||||
"OOOXOOOXOOO",
|
||||
@@ -288,8 +277,6 @@ sensor_range_m = 300
|
||||
# the lower decks hold supports and 2x2 point-defense m guns.
|
||||
[[ship]]
|
||||
id = "carrier"
|
||||
unlock_at_station_level = 9
|
||||
unlock_requires = ["battleship"]
|
||||
layout = [
|
||||
"XOOOOOOOOX",
|
||||
"OOOOOOOOOO",
|
||||
|
||||
140
bin/app/data/config/unlocks.toml
Normal file
@@ -0,0 +1,140 @@
|
||||
# Unlock groups (REQ-LOCK-EXPLICIT, REQ-DEF-SCHEMATIC-DROP).
|
||||
#
|
||||
# Each [[unlock]] is a group of ships/modules/buildings/recipes awarded together
|
||||
# from a single defence station drop. Anything NOT granted by any group is
|
||||
# available from game start. `station_level` gates when a group becomes eligible;
|
||||
# `requires` lists prerequisite unlock-group ids (REQ-LOCK-PREREQ).
|
||||
#
|
||||
# Most entries below are single-item groups that reproduce the previous per-item
|
||||
# progression. The salvage_operations and reprocessing groups are the grouped
|
||||
# unlocks: they lock the salvager module + salvage bay, and the reprocessing
|
||||
# plant, from game start.
|
||||
|
||||
# --- Grouped unlocks -------------------------------------------------------
|
||||
|
||||
[[unlock]]
|
||||
id = "salvage_operations"
|
||||
station_level = 1
|
||||
modules = ["salvager"]
|
||||
buildings = ["salvage_bay"]
|
||||
|
||||
[[unlock]]
|
||||
id = "reprocessing"
|
||||
station_level = 2
|
||||
buildings = ["reprocessing_plant"]
|
||||
|
||||
# --- Ships -----------------------------------------------------------------
|
||||
|
||||
[[unlock]]
|
||||
id = "destroyer"
|
||||
station_level = 0
|
||||
ships = ["destroyer"]
|
||||
|
||||
[[unlock]]
|
||||
id = "cruiser"
|
||||
station_level = 2
|
||||
ships = ["cruiser"]
|
||||
|
||||
[[unlock]]
|
||||
id = "battlecruiser"
|
||||
station_level = 4
|
||||
requires = ["cruiser"]
|
||||
ships = ["battlecruiser"]
|
||||
|
||||
[[unlock]]
|
||||
id = "battleship"
|
||||
station_level = 6
|
||||
requires = ["battlecruiser"]
|
||||
ships = ["battleship"]
|
||||
|
||||
[[unlock]]
|
||||
id = "dreadnought"
|
||||
station_level = 8
|
||||
requires = ["battleship"]
|
||||
ships = ["dreadnought"]
|
||||
|
||||
[[unlock]]
|
||||
id = "carrier"
|
||||
station_level = 9
|
||||
requires = ["battleship"]
|
||||
ships = ["carrier"]
|
||||
|
||||
# --- Modules ---------------------------------------------------------------
|
||||
|
||||
[[unlock]]
|
||||
id = "repair_tool"
|
||||
station_level = 0
|
||||
modules = ["repair_tool"]
|
||||
|
||||
[[unlock]]
|
||||
id = "armor_plates"
|
||||
station_level = 0
|
||||
modules = ["armor_plates"]
|
||||
|
||||
[[unlock]]
|
||||
id = "maneuvering_thrusters"
|
||||
station_level = 1
|
||||
modules = ["maneuvering_thrusters"]
|
||||
|
||||
[[unlock]]
|
||||
id = "sensor_booster"
|
||||
station_level = 1
|
||||
modules = ["sensor_booster"]
|
||||
|
||||
[[unlock]]
|
||||
id = "railgun_m"
|
||||
station_level = 2
|
||||
modules = ["railgun_m"]
|
||||
|
||||
[[unlock]]
|
||||
id = "afterburner"
|
||||
station_level = 2
|
||||
modules = ["afterburner"]
|
||||
|
||||
[[unlock]]
|
||||
id = "weapon_stabilizer"
|
||||
station_level = 3
|
||||
modules = ["weapon_stabilizer"]
|
||||
|
||||
[[unlock]]
|
||||
id = "weapon_upgrade"
|
||||
station_level = 4
|
||||
modules = ["weapon_upgrade"]
|
||||
|
||||
[[unlock]]
|
||||
id = "weapon_primer"
|
||||
station_level = 4
|
||||
modules = ["weapon_primer"]
|
||||
|
||||
[[unlock]]
|
||||
id = "drone_bay"
|
||||
station_level = 5
|
||||
modules = ["drone_bay"]
|
||||
|
||||
[[unlock]]
|
||||
id = "railgun_l"
|
||||
station_level = 6
|
||||
requires = ["railgun_m"]
|
||||
modules = ["railgun_l"]
|
||||
|
||||
[[unlock]]
|
||||
id = "drone_hangar"
|
||||
station_level = 9
|
||||
modules = ["drone_hangar"]
|
||||
|
||||
# --- Assembler recipes -----------------------------------------------------
|
||||
|
||||
[[unlock]]
|
||||
id = "shortcut_steel_plate"
|
||||
station_level = 1
|
||||
recipes = ["shortcut_steel_plate"]
|
||||
|
||||
[[unlock]]
|
||||
id = "shortcut_control_chip"
|
||||
station_level = 2
|
||||
recipes = ["shortcut_control_chip"]
|
||||
|
||||
[[unlock]]
|
||||
id = "shortcut_hardened_steel"
|
||||
station_level = 2
|
||||
recipes = ["shortcut_hardened_steel"]
|
||||
@@ -335,7 +335,7 @@ salvage_color = "#33ccff"
|
||||
width_px = 2
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Build / demolish / selection overlays
|
||||
# Build / deconstruct / selection overlays
|
||||
#
|
||||
# All overlay colors carry an alpha channel so they composite over the
|
||||
# underlying scene.
|
||||
@@ -344,13 +344,14 @@ width_px = 2
|
||||
[overlays]
|
||||
ghost_valid = "#ffffff44" # builder-mode ghost, placement allowed (REQ-BLD-GHOST)
|
||||
ghost_invalid = "#ff000044" # builder-mode ghost, placement invalid (REQ-BLD-PLACE-VALID)
|
||||
demolish_tint = "#ff000033" # demolish-mode hover tint
|
||||
deconstruct_tint = "#ff000033" # deconstruct-mode hover tint
|
||||
selection_rect = "#00ff00" # box-drag selection rectangle (REQ-UI-MULTI-SELECT)
|
||||
tile_highlight = "#ffffff22" # tile under cursor
|
||||
selected_outline = "#ffff00" # outline drawn around currently-selected building(s)
|
||||
copy_config = "#33ccff66" # copy-settings eligible-target tint + copy/paste flash (REQ-BLD-COPY-CONFIG-FEEDBACK)
|
||||
locked_asteroid = "#0000007f" # tint over the asteroid left of the buildable edge (not yet unlocked by expansion)
|
||||
modal_dim = "#00000099" # semi-transparent black dim behind modal dialogs/menus (REQ-UI-MODAL-DIM)
|
||||
tunnel_preview = "#00ff0055" # tunnel connection preview: matched end + tiles between (REQ-BLD-TUNNEL-MODE)
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Schematic-drop toasts (REQ-UI-SCHEMATIC-TOAST)
|
||||
@@ -360,3 +361,17 @@ modal_dim = "#00000099" # semi-transparent black dim behind modal dialogs
|
||||
bg = "#000000cc"
|
||||
fg = "#ffffff"
|
||||
font_size = 14
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Building status light (REQ-UI-STATUS-LIGHT)
|
||||
#
|
||||
# Fill color per production state, drawn as a small circle in the building's
|
||||
# upper-right corner, plus the constant outline color.
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
[status_light]
|
||||
grey = "#808080" # no recipe/schematic selected
|
||||
green = "#33cc33" # producing (Salvage Bay: holding scrap)
|
||||
red = "#cc3333" # idle, input missing (Salvage Bay: empty)
|
||||
yellow = "#e6c619" # idle, output buffer full
|
||||
outline = "#000000"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
[world]
|
||||
height_tiles = 40
|
||||
refund_percentage = 100
|
||||
deconstruction_time_seconds = 0.1
|
||||
starting_building_blocks = 200
|
||||
scrap_despawn_seconds = 120
|
||||
scrap_per_threat = 0.25
|
||||
@@ -10,7 +11,8 @@ tunnel_max_distance_tiles = 10
|
||||
departure_interval_seconds = 20
|
||||
orbit_factor = 0.8
|
||||
rally_orbit_radius_tiles = 5.0
|
||||
building_blocks_tooltip = "Building blocks are the currency for construction. Spend them to place buildings and to expand the asteroid. Produce building blocks in your factory and deliver them to the HQ on a belt to grow your stock."
|
||||
building_blocks_tooltip = "Building blocks are the currency for construction. Spend them to place buildings and to expand the asteroid. Produce building blocks in your assemblers and deliver them to the HQ on a belt to grow your stock."
|
||||
artifact_tooltip = "Artifacts are the key to victory. Earn one by choosing the artifact reward when you destroy a set of enemy defence stations. Collect enough of them to win the game."
|
||||
|
||||
[regions]
|
||||
asteroid_width_tiles = 60
|
||||
|
||||
6
bin/app/data/icons/buildings/assembler.svg
Normal file
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
|
||||
<rect width="100" height="100" rx="22" fill="#3a6fa8"/>
|
||||
<g transform="translate(13,13) scale(2.3125)" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="16" cy="16" r="6.2"/><circle cx="16" cy="16" r="2.2"/><path d="M16 5.5v3M16 23.5v3M5.5 16h3M23.5 16h3M8.6 8.6 10.7 10.7M23.4 8.6 21.3 10.7M8.6 23.4 10.7 21.3M23.4 23.4 21.3 21.3"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 499 B |
6
bin/app/data/icons/buildings/belt.svg
Normal file
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
|
||||
<rect width="100" height="100" rx="22" fill="#6a6a6a"/>
|
||||
<g transform="translate(13,13) scale(2.3125)" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<rect x="4" y="10" width="24" height="12" rx="3"/><path d="M9 13 12.5 16 9 19"/><path d="M14.5 13 18 16 14.5 19"/><path d="M20 13 23.5 16 20 19"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 453 B |
6
bin/app/data/icons/buildings/deconstruct.svg
Normal file
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
|
||||
<rect width="100" height="100" rx="22" fill="#cc3333"/>
|
||||
<g transform="translate(13,13) scale(2.3125)" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M7 10h18"/><path d="M9.5 10 11 26h10l1.5-16"/><path d="M13 10V6.5h6V10"/><path d="M13.5 14v8M18.5 14v8"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 421 B |
6
bin/app/data/icons/buildings/miner.svg
Normal file
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
|
||||
<rect width="100" height="100" rx="22" fill="#6b4a2c"/>
|
||||
<g transform="translate(13,13) scale(2.3125)" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<rect x="9" y="5" width="14" height="8" rx="1.5"/><path d="M11 13 16 26 21 13"/><path d="M13 17.5h6"/><path d="M14.5 21.5h3"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 433 B |
6
bin/app/data/icons/buildings/reprocessing_plant.svg
Normal file
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
|
||||
<rect width="100" height="100" rx="22" fill="#6a3a8a"/>
|
||||
<g transform="translate(13,13) scale(2.3125)" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="12" cy="18" r="4"/><circle cx="20" cy="18" r="4"/><path d="M10.6 16.6 13.4 19.4M13.4 16.6 10.6 19.4M18.6 16.6 21.4 19.4M21.4 16.6 18.6 19.4"/><path d="M16 4v8"/><path d="M13 9 16 12 19 9"/><path d="M16 24v4"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 528 B |
6
bin/app/data/icons/buildings/salvage_bay.svg
Normal file
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
|
||||
<rect width="100" height="100" rx="22" fill="#b8a23a"/>
|
||||
<g transform="translate(13,13) scale(2.3125)" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M7 13h18l-2 13H9z"/><path d="M16 3v7"/><path d="M12 7 16 11 20 7"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 383 B |
6
bin/app/data/icons/buildings/shipyard.svg
Normal file
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
|
||||
<rect width="100" height="100" rx="22" fill="#3f6580"/>
|
||||
<g transform="translate(13,13) scale(2.3125)" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M16 4c2 3 2.6 6 2.6 9.5V16h-5.2v-2.5C13.4 10 14 7 16 4z"/><circle cx="16" cy="10" r="1.3"/><path d="M13.4 15 11 18h2.4z"/><path d="M18.6 15 21 18h-2.4z"/><path d="M14.7 17 16 21 17.3 17"/><path d="M9 25h14"/><path d="M12 25v-2M20 25v-2"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 554 B |
6
bin/app/data/icons/buildings/smelter.svg
Normal file
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
|
||||
<rect width="100" height="100" rx="22" fill="#b85a1e"/>
|
||||
<g transform="translate(13,13) scale(2.3125)" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M9 9h14l-2.5 8h-9z"/><path d="M8 9h16"/><path d="M11 26c-1-1.8.4-3 .4-4 .9 1 1.6 2.2 1.6 4"/><path d="M16 26c-1-2 .4-3.4.4-4.4 .9 1 1.6 2.6 1.6 4.4"/><path d="M21 26c-1-1.8.4-3 .4-4 .9 1 1.6 2.2 1.6 4"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 519 B |
6
bin/app/data/icons/buildings/splitter.svg
Normal file
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
|
||||
<rect width="100" height="100" rx="22" fill="#7a7a5a"/>
|
||||
<g transform="translate(13,13) scale(2.3125)" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M5 16h11"/><path d="M16 8v16"/><path d="M13.5 10.5 16 8 18.5 10.5"/><path d="M13.5 21.5 16 24 18.5 21.5"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 422 B |
6
bin/app/data/icons/buildings/tunnel_entry.svg
Normal file
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">
|
||||
<rect width="100" height="100" rx="22" fill="#4f7562"/>
|
||||
<g transform="translate(13,13) scale(2.3125)" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M4 9h24"/><path d="M8 9C8 24 24 24 24 9"/><path d="M14.5 18.5 17.5 20 14.5 21.5"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 398 B |
@@ -1,7 +1,6 @@
|
||||
[[module]]
|
||||
id = "armor_plate"
|
||||
tooltip = "Adds a large flat bonus to hit points."
|
||||
unlock_at_station_level = -1
|
||||
surface_mask = ["OO"]
|
||||
materials = [{item = "iron_ingot", amount = 2}]
|
||||
production_time_seconds = 3
|
||||
@@ -13,7 +12,6 @@ multiplied_hp = 1.5
|
||||
|
||||
[[module]]
|
||||
id = "sensor_booster"
|
||||
unlock_at_station_level = -1
|
||||
surface_mask = ["O"]
|
||||
materials = [{item = "circuit_board", amount = 1}]
|
||||
production_time_seconds = 2
|
||||
@@ -25,7 +23,6 @@ added_sensor_range_m = 100
|
||||
|
||||
[[module]]
|
||||
id = "weapon_upgrade"
|
||||
unlock_at_station_level = -1
|
||||
surface_mask = ["O"]
|
||||
materials = [{item = "iron_ingot", amount = 1}, {item = "circuit_board", amount = 1}]
|
||||
production_time_seconds = 4
|
||||
@@ -37,7 +34,6 @@ multiplied_damage = 1.2
|
||||
|
||||
[[module]]
|
||||
id = "laser_cannon"
|
||||
unlock_at_station_level = -1
|
||||
surface_mask = ["O"]
|
||||
materials = [{item = "iron_ingot", amount = 1}]
|
||||
production_time_seconds = 5
|
||||
@@ -51,7 +47,6 @@ attack_rate_hz = 2.0
|
||||
|
||||
[[module]]
|
||||
id = "salvager"
|
||||
unlock_at_station_level = -1
|
||||
surface_mask = ["OO"]
|
||||
materials = [{item = "iron_ingot", amount = 2}]
|
||||
production_time_seconds = 5
|
||||
@@ -65,7 +60,6 @@ collection_rate_hz = 0.5
|
||||
|
||||
[[module]]
|
||||
id = "repair_tool"
|
||||
unlock_at_station_level = -1
|
||||
surface_mask = ["O"]
|
||||
materials = [{item = "circuit_board", amount = 2}]
|
||||
production_time_seconds = 5
|
||||
@@ -79,7 +73,6 @@ repair_range_m = 800
|
||||
|
||||
[[module]]
|
||||
id = "weapon_primer"
|
||||
unlock_at_station_level = -1
|
||||
surface_mask = ["O"]
|
||||
materials = [{item = "iron_ingot", amount = 1}]
|
||||
production_time_seconds = 4
|
||||
@@ -91,7 +84,6 @@ multiplied_attack_rate_hz = 1.2
|
||||
|
||||
[[module]]
|
||||
id = "weapon_stabilizer"
|
||||
unlock_at_station_level = -1
|
||||
surface_mask = ["O"]
|
||||
materials = [{item = "iron_ingot", amount = 1}]
|
||||
production_time_seconds = 4
|
||||
@@ -104,7 +96,6 @@ multiplied_attack_rate_hz = 0.8
|
||||
|
||||
[[module]]
|
||||
id = "afterburner"
|
||||
unlock_at_station_level = -1
|
||||
surface_mask = ["O"]
|
||||
materials = [{item = "iron_ingot", amount = 1}]
|
||||
production_time_seconds = 2
|
||||
@@ -117,7 +108,6 @@ added_main_acceleration_mpss = 60
|
||||
|
||||
[[module]]
|
||||
id = "maneuvering_thrusters"
|
||||
unlock_at_station_level = -1
|
||||
surface_mask = ["O"]
|
||||
materials = [{item = "iron_ingot", amount = 1}]
|
||||
production_time_seconds = 2
|
||||
|
||||
@@ -43,7 +43,7 @@ duration_seconds = 4.0
|
||||
[[recipe]]
|
||||
id = "premium_circuit"
|
||||
building = "assembler"
|
||||
unlock_at_station_level = -1
|
||||
unlocked_at_start = true
|
||||
inputs = [{item = "circuit_board", amount = 1}]
|
||||
outputs = [{item = "premium_circuit", amount = 1}]
|
||||
duration_seconds = 8.0
|
||||
@@ -51,7 +51,6 @@ duration_seconds = 8.0
|
||||
[[recipe]]
|
||||
id = "quick_circuit"
|
||||
building = "assembler"
|
||||
unlock_at_station_level = 0
|
||||
inputs = [{item = "copper_ingot", amount = 3}]
|
||||
outputs = [{item = "circuit_board", amount = 1}]
|
||||
duration_seconds = 3.0
|
||||
@@ -59,7 +58,6 @@ duration_seconds = 3.0
|
||||
[[recipe]]
|
||||
id = "advanced_circuit"
|
||||
building = "assembler"
|
||||
unlock_at_station_level = 1
|
||||
inputs = [{item = "iron_ingot", amount = 5}]
|
||||
outputs = [{item = "circuit_board", amount = 1}]
|
||||
duration_seconds = 6.0
|
||||
@@ -67,7 +65,6 @@ duration_seconds = 6.0
|
||||
[[recipe]]
|
||||
id = "exotic_alloy"
|
||||
building = "assembler"
|
||||
unlock_at_station_level = 0
|
||||
inputs = [{item = "exotic_ore", amount = 2}]
|
||||
outputs = [{item = "exotic_alloy", amount = 1}]
|
||||
duration_seconds = 10.0
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
[[ship]]
|
||||
id = "interceptor"
|
||||
unlock_at_station_level = -1
|
||||
layout = ["XOX", "OOO", "XOX"]
|
||||
default_modules = [{type = "laser_cannon", x = 1, y = 1, rotation = "east"}]
|
||||
|
||||
@@ -24,7 +23,6 @@ sensor_range_m = 2000
|
||||
|
||||
[[ship]]
|
||||
id = "destroyer"
|
||||
unlock_at_station_level = -1
|
||||
layout = ["XOOX", "OOOO", "XOOX"]
|
||||
default_modules = [{type = "laser_cannon", x = 1, y = 1, rotation = "east"}]
|
||||
|
||||
@@ -48,7 +46,6 @@ sensor_range_m = 3000
|
||||
|
||||
[[ship]]
|
||||
id = "salvage_ship"
|
||||
unlock_at_station_level = -1
|
||||
layout = ["OOO", "OOO"]
|
||||
|
||||
[ship.schematic]
|
||||
@@ -71,7 +68,6 @@ sensor_range_m = 2500
|
||||
|
||||
[[ship]]
|
||||
id = "repair_ship"
|
||||
unlock_at_station_level = 0
|
||||
layout = ["XOX", "OOO", "XOX"]
|
||||
|
||||
[ship.schematic]
|
||||
|
||||
21
bin/test/data/config/unlocks.toml
Normal file
@@ -0,0 +1,21 @@
|
||||
# Unlock groups for the test config (REQ-LOCK-EXPLICIT). Mirrors the previous
|
||||
# per-item gating: repair_ship, quick_circuit, advanced_circuit start locked and
|
||||
# are awarded via defence station drops. exotic_alloy is intentionally NOT here:
|
||||
# it stays implicitly gated (its output/inputs are unreachable), so it is never
|
||||
# unlocked. premium_circuit uses unlocked_at_start in recipes.toml. Everything
|
||||
# else (interceptor, destroyer, salvage_ship, all modules) starts unlocked.
|
||||
|
||||
[[unlock]]
|
||||
id = "repair_ship"
|
||||
station_level = 0
|
||||
ships = ["repair_ship"]
|
||||
|
||||
[[unlock]]
|
||||
id = "quick_circuit"
|
||||
station_level = 0
|
||||
recipes = ["quick_circuit"]
|
||||
|
||||
[[unlock]]
|
||||
id = "advanced_circuit"
|
||||
station_level = 1
|
||||
recipes = ["advanced_circuit"]
|
||||
@@ -1,6 +1,7 @@
|
||||
[world]
|
||||
height_tiles = 60
|
||||
refund_percentage = 75
|
||||
deconstruction_time_seconds = 0.1
|
||||
starting_building_blocks = 100
|
||||
scrap_despawn_seconds = 30
|
||||
scrap_per_threat = 1.0
|
||||
@@ -11,6 +12,7 @@ departure_interval_seconds = 20
|
||||
orbit_factor = 0.8
|
||||
rally_orbit_radius_tiles = 5.0
|
||||
building_blocks_tooltip = "Spend building blocks to build; deliver them to the HQ to gain more."
|
||||
artifact_tooltip = "Choose the artifact reward when destroying enemy stations; collect enough to win."
|
||||
|
||||
[regions]
|
||||
asteroid_width_tiles = 40
|
||||
|
||||
@@ -15,7 +15,7 @@ This document captures the architectural decisions for the project. It is a comp
|
||||
A strict separation between the game simulation and the Qt Widgets UI.
|
||||
|
||||
- The **simulation** is a pure C++ library that depends only on Qt Core and Qt Gui (QPoint, QVector2D, QRect, etc., as required by the coding guidelines), toml++, and tinyexpr. It contains no QtWidgets, no painting, and no QApplication. Note: in Qt 5, vector math types such as QVector2D live in Qt::Gui rather than Qt::Core, so the lib links both.
|
||||
- The **UI** reads simulation state and renders it. It owns all widgets, painting, and input handling, and drives the simulation via a small command interface (place building, demolish, clear belt tiles, change recipe, set game speed, etc.).
|
||||
- The **UI** reads simulation state and renders it. It owns all widgets, painting, and input handling, and drives the simulation via a small command interface (place building, deconstruct, clear belt tiles, change recipe, set game speed, etc.).
|
||||
|
||||
This split is enforced at the CMake target level (see below). Tests link only against the simulation library and run without a display server.
|
||||
|
||||
@@ -93,10 +93,16 @@ Schematic drops: when an enemy station set is destroyed, the simulation generate
|
||||
|
||||
### UI Events
|
||||
|
||||
All UI interactions — building selection, builder/blueprint mode transitions, speed changes, demolish mode, escape menu, layout dialog requests — are communicated via EventManager events rather than Qt signals/slots. Each event is a small struct inheriting `Event` (e.g., `SelectionChangedEvent`, `BuildingTypeSelectedEvent`, `SpeedChangeRequestedEvent`). Widgets register as `CombinedEventHandler` for the events they care about and emit events via `EventManager::sendEventImmediately()`.
|
||||
All UI interactions — building selection, builder/blueprint mode transitions, speed changes, deconstruct mode, escape menu, layout dialog requests — are communicated via EventManager events rather than Qt signals/slots. Each event is a small struct inheriting `Event` (e.g., `SelectionChangedEvent`, `BuildingTypeSelectedEvent`, `SpeedChangeRequestedEvent`). Widgets register as `CombinedEventHandler` for the events they care about and emit events via `EventManager::sendEventImmediately()`.
|
||||
|
||||
Bidirectional interactions use separate request/notification event types to avoid infinite recursion (e.g., `ExitBuilderModeRequestedEvent` from `BuildButtonGrid` → `GameWorldView`, vs. `BuilderModeExitedEvent` from `GameWorldView` → `BuildButtonGrid`).
|
||||
|
||||
### Reading Simulation State
|
||||
|
||||
The simulation is the single source of truth for every game value (building block stock, expansion cost, threat level, tick, etc.). A UI widget that needs such a value holds the `Simulation*` it was constructed with and **pulls the value on demand** via the corresponding getter (e.g., `m_sim->getBuildingBlocksStock()`), rather than caching its own copy.
|
||||
|
||||
State-change events (e.g., `BuildingBlocksChangedEvent`) are treated as *refresh signals*, not as carriers of truth: a widget subscribes to the event to learn *when* the value changed and then re-reads it from the simulation to learn *what* it now is. The value carried in the event payload is not authoritative and should not be stored. This keeps a single copy of each value and avoids stale-cache bugs (a widget acting on a value that has since moved on because nothing refreshed its local copy).
|
||||
|
||||
## Tick Order
|
||||
|
||||
Within a single simulation tick, subsystems run in this fixed order. The order is load-bearing for determinism and for avoiding one-tick-delay artifacts (e.g., items landing on a belt but not advancing in the same tick).
|
||||
@@ -319,7 +325,7 @@ Sim and UI run on the same thread for v1. `paintEvent` reads sim state directly
|
||||
4. **Scrap** — glyphs at world positions.
|
||||
5. **Ships** — colored arrows oriented by velocity; color keyed to role (player combat / salvage / repair / enemy).
|
||||
6. **Laser beams** — lines derived from live `BeamFiredEvent`s kept by the renderer for 0.3 s, colored per `BeamKind` (weapon/repair/salvage) (REQ-SHP-FIRING-BEAM).
|
||||
7. **Build overlays** — ghost in builder mode (REQ-BLD-GHOST), demolish-mode tint, tile highlight under cursor, box-drag selection rectangle.
|
||||
7. **Build overlays** — ghost in builder mode (REQ-BLD-GHOST), deconstruct-mode tint, tile highlight under cursor, box-drag selection rectangle.
|
||||
8. **Screen-space UI** — screen-anchored elements, drawn after resetting the world-space transform.
|
||||
|
||||
### Coordinates and Scrolling
|
||||
@@ -366,7 +372,7 @@ width_px = 2
|
||||
[overlays]
|
||||
ghost_valid = "#ffffff44"
|
||||
ghost_invalid = "#ff000044"
|
||||
demolish_tint = "#ff000033"
|
||||
deconstruct_tint = "#ff000033"
|
||||
selection_rect = "#00ff00"
|
||||
|
||||
[toast]
|
||||
|
||||
@@ -55,7 +55,7 @@ data, not the UI gesture. Example: placing a miner records
|
||||
One command per sim-mutating operation (the complete mutation surface):
|
||||
|
||||
- `PlaceBuilding`
|
||||
- `Demolish`
|
||||
- `Deconstruct`
|
||||
- `RotateInPlace`
|
||||
- `SetRecipe`
|
||||
- `SetShipLayout`
|
||||
@@ -125,7 +125,7 @@ the only way production code can reach them is `apply(command)`.
|
||||
> `BeltSystem` directly, and every production `buildings()`/`belts()` call is a const query.
|
||||
> So:
|
||||
>
|
||||
> - `Simulation::tryPlaceBuilding`, `demolish`, and `applySchematicChoice` are **private**.
|
||||
> - `Simulation::tryPlaceBuilding`, `deconstruct`, and `applySchematicChoice` are **private**.
|
||||
> - The mutable subsystem accessors are private and renamed `buildingsMutable()` /
|
||||
> `beltsMutable()`; only `const BuildingSystem& buildings() const` / `belts() const` are
|
||||
> public (queries). UI query sites bind to the const overload unchanged.
|
||||
@@ -377,7 +377,7 @@ The whole feature rests on a deterministic sim, so prove that before building on
|
||||
|
||||
Reshape mutations to flow through one path; behaviour unchanged.
|
||||
|
||||
- Defined `Command` base + derived types (`PlaceBuilding`, `Demolish`, `RotateInPlace`,
|
||||
- Defined `Command` base + derived types (`PlaceBuilding`, `Deconstruct`, `RotateInPlace`,
|
||||
`SetRecipe`, `SetShipLayout`, `SetSiteSplitterFilters`, `SetSplitterFilters`,
|
||||
`ClearBeltTiles`, `ApplySchematicChoice`, `Reset`) in `lib`, each with a `playerId` (always 0
|
||||
now). `PlaceBuilding` is atomic (carries optional config — see the refinement note above).
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
|
||||
Config files use the TOML format. The following config files drive game parameters:
|
||||
|
||||
- **world.toml** — world dimensions, region widths, expansion amounts, building refund percentage, wave timing, boss wave timing, belt speed, starting building blocks, departure interval, ship orbit factor, rally orbit radius, scrap-per-threat conversion, combat target-selection parameters (target score formula, overclaim penalty formula, target hysteresis), artifact chance formula, artifact win count, view pan speeds (slow and fast horizontal pan speed and pan ramp band width), and an optional building blocks tooltip string (shown as the header bar's building blocks stock hover tooltip, REQ-UI-BLOCKS-TOOLTIP; omitted when unset).
|
||||
- **buildings.toml** — building block cost and construction time per building type, plus an optional tooltip description string per building type (shown as the build button's hover tooltip, REQ-UI-BUILD-TOOLTIP; omitted when unset).
|
||||
- **recipes.toml** — crafting recipes: inputs, outputs, quantities, durations, and reprocessing plant probabilities. Assembler recipe entries may optionally define `unlock_at_station_level` (integer): -1 means the recipe is explicitly unlocked at game start; a value ≥ 0 means the recipe starts locked and a schematic for it can be awarded via defence station destruction (see REQ-LOCK-EXPLICIT, REQ-DEF-SCHEMATIC-DROP). An assembler recipe schematic entry may also define an optional `unlock_requires` list of prerequisite schematic ids (REQ-LOCK-PREREQ).
|
||||
- **ships.toml** — per schematic: a human-readable display name (used in the UI), hull stats (HP, max linear speed, sensor range, main acceleration, maneuvering acceleration, angular acceleration, max rotation speed) as plain values, required build materials, the station level at which the schematic becomes available for unlock (`unlock_at_station_level`; -1 means the player starts with the schematic already unlocked), an optional `unlock_requires` prerequisite list (REQ-LOCK-PREREQ), a layout grid defining the ship's module slots, and a `default_modules` list used for enemy wave ships (see REQ-WAV-DEFAULT-MODULES).
|
||||
- **modules.toml** — per module type: id, surface mask, materials list, production time, fill color, glyph, an optional tooltip description string (shown as the module selection button's hover tooltip, REQ-MOD-UI-MODULE-TOOLTIP; omitted when unset), the station level at which the schematic becomes available for unlock (`unlock_at_station_level`; -1 means the player starts with the module schematic already unlocked), an optional `unlock_requires` prerequisite list (REQ-LOCK-PREREQ), and an optional capability section and/or stat modifier formulas. A module with a capability section (`[module.weapon]`, `[module.salvage]`, or `[module.repair]`) containing base stat formulas is a **capability module** that grants the ship a weapon, salvage bay, or repair tool per instance (see REQ-MOD-CONFIG for the full list of formulas per capability type). A module with only `added_*`/`multiplied_*` formulas is a **passive module** that modifies stats on the ship or on capability module instances (see REQ-MOD-STAT-CALC).
|
||||
- **world.toml** — world dimensions, region widths, expansion amounts, building refund percentage, building deconstruction time, wave timing, boss wave timing, belt speed, starting building blocks, departure interval, ship orbit factor, rally orbit radius, scrap-per-threat conversion, combat target-selection parameters (target score formula, overclaim penalty formula, target hysteresis), artifact chance formula, artifact win count, view pan speeds (slow and fast horizontal pan speed and pan ramp band width), an optional building blocks tooltip string (shown as the header bar's building blocks stock hover tooltip, REQ-UI-BLOCKS-TOOLTIP; omitted when unset), and an optional artifact tooltip string (shown as the header bar's artifact count hover tooltip, REQ-UI-ARTIFACTS-TOOLTIP; omitted when unset).
|
||||
- **buildings.toml** — building block cost and construction time per building type, plus an optional tooltip description string per building type (shown as the build button's hover tooltip, REQ-UI-BUILD-TOOLTIP; omitted when unset). Whether a building type is available from game start or must be unlocked during play is not defined here but in **unlocks.toml** (REQ-LOCK-EXPLICIT): a building type granted by an unlock group starts locked and is hidden from the build menu until its group is awarded (REQ-LOCK-BUILDING).
|
||||
- **recipes.toml** — crafting recipes: inputs, outputs, quantities, durations, and reprocessing plant probabilities. Assembler recipe entries may optionally define `unlocked_at_start` (boolean, default false): when true the recipe is available from game start regardless of the implicit item graph — used for base recipes that no schematic's materials reach (such as building blocks; see REQ-LOCK-IMPLICIT). Which assembler recipes must instead be awarded during play (explicitly gated) is defined in **unlocks.toml**, not here (REQ-LOCK-EXPLICIT); every remaining assembler recipe is implicitly unlocked through the item graph (REQ-LOCK-IMPLICIT).
|
||||
- **ships.toml** — per schematic: a human-readable display name (used in the UI), hull stats (HP, max linear speed, sensor range, main acceleration, maneuvering acceleration, angular acceleration, max rotation speed) as plain values, required build materials, a layout grid defining the ship's module slots, and a `default_modules` list used for enemy wave ships (see REQ-WAV-DEFAULT-MODULES). Whether a ship schematic is available from game start or must be unlocked during play is defined in **unlocks.toml** (REQ-LOCK-EXPLICIT), not here.
|
||||
- **modules.toml** — per module type: id, surface mask, materials list, production time, fill color, glyph, an optional tooltip description string (shown as the module selection button's hover tooltip, REQ-MOD-UI-MODULE-TOOLTIP; omitted when unset), and an optional capability section and/or stat modifier formulas. Whether a module schematic is available from game start or must be unlocked during play is defined in **unlocks.toml** (REQ-LOCK-EXPLICIT), not here. A module with a capability section (`[module.weapon]`, `[module.salvage]`, or `[module.repair]`) containing base stat formulas is a **capability module** that grants the ship a weapon, salvage bay, or repair tool per instance (see REQ-MOD-CONFIG for the full list of formulas per capability type). A module with only `added_*`/`multiplied_*` formulas is a **passive module** that modifies stats on the ship or on capability module instances (see REQ-MOD-STAT-CALC).
|
||||
- **unlocks.toml** — unlock groups: each `[[unlock]]` entry names a group of ship schematics, module schematics, building types, and/or assembler recipes that are awarded together from a single defence station drop (see Unlock Group Format, REQ-LOCK-EXPLICIT, REQ-DEF-SCHEMATIC-DROP). Anything not granted by any unlock group is available from game start.
|
||||
- **stations.toml** — HP, damage, range, fire rate, and scrap drop for player and enemy defence stations, defined as formulas of station level.
|
||||
- **visuals.toml** — rendering-only config (not game parameters): fill and outline colors and glyphs for every building type, item type, ship schematic, and station type; a distinct beam color per tool type (weapon, repair, salvage) and beam width; overlay and toast colors. Loaded by the UI at startup; the simulation does not read it.
|
||||
- **visuals.toml** — rendering-only config (not game parameters): fill and outline colors and glyphs for every building type, item type, ship schematic, and station type; a distinct beam color per tool type (weapon, repair, salvage) and beam width; overlay and toast colors; and building status light colors (grey, green, red, and yellow fills plus the outline color, REQ-UI-STATUS-LIGHT). Loaded by the UI at startup; the simulation does not read it.
|
||||
- **ship_layouts.toml** — named layout blueprints per ship type; written and read by the application to persist the layout blueprint panel (REQ-MOD-UI-BLUEPRINT-PANEL through REQ-MOD-UI-BLUEPRINT-FILE-LOAD). Not a game parameter file; the simulation does not read it.
|
||||
|
||||
- REQ-CFG-RELOAD: When the player triggers a Restart (REQ-UI-GAME-MENU), all config files are reloaded from disk before the simulation is reset to its initial state. Formula strings are recompiled at that point. This allows config edits made while the application is running to take effect without a full application restart.
|
||||
@@ -65,6 +66,28 @@ Modules in `modules.toml` define a `surface_mask` — a list of strings that des
|
||||
- `O` — module cell: must be placed on an unoccupied buildable cell (`O`) of the ship's layout.
|
||||
- `X` — ignored cell: may overlap any cell (non-buildable, unoccupied buildable, or occupied buildable) or extend outside the layout grid entirely.
|
||||
|
||||
### Unlock Group Format
|
||||
|
||||
Unlock groups in `unlocks.toml` define what the player can be awarded from defence station drops (REQ-DEF-SCHEMATIC-DROP); by their absence they also define what is available from game start (REQ-LOCK-EXPLICIT). Each entry:
|
||||
|
||||
```toml
|
||||
[[unlock]]
|
||||
id = "salvage_operations" # unique unlock-group id
|
||||
station_level = 2 # eligible once a destroyed station set's level >= this
|
||||
requires = [] # prerequisite unlock-group ids (REQ-LOCK-PREREQ); default empty
|
||||
ships = [] # ship schematic ids granted (from ships.toml)
|
||||
modules = ["salvager"] # module schematic ids granted (from modules.toml)
|
||||
buildings = ["salvage_bay"] # building type ids granted (from buildings.toml)
|
||||
recipes = [] # assembler recipe ids granted (from recipes.toml)
|
||||
```
|
||||
|
||||
- `id` — unique identifier of the unlock group; referenced by other groups' `requires`. Its display name in the schematic choice dialog is derived from the id (same convention as building, module, and recipe ids); there is no separate name field for now.
|
||||
- `station_level` — the minimum destroyed enemy defence station level at which this group becomes eligible to drop (REQ-DEF-SCHEMATIC-DROP).
|
||||
- `requires` — optional list of prerequisite unlock-group ids that must already have been awarded before this group can drop (REQ-LOCK-PREREQ). Defaults to empty.
|
||||
- `ships`, `modules`, `buildings`, `recipes` — the ids granted when this group is awarded. Each list defaults to empty, but a group must grant at least one item overall. Every id must resolve to a definition in the corresponding config file, and `recipes` ids must name **assembler** recipes. Each grantable id (ship, module, building, or assembler recipe) may be granted by **at most one** unlock group; violations fail config load (REQ-LOCK-EXPLICIT).
|
||||
|
||||
Any ship, module, building, or assembler recipe id that appears in no unlock group's grant lists is available from game start (REQ-LOCK-EXPLICIT).
|
||||
|
||||
## Game World
|
||||
|
||||
- REQ-GW-COORDS: Tile coordinates are integer `(x, y)`. The origin `(0, 0)` is the first column of space — the tile immediately to the right of the asteroid's right edge at game start, at the top of the world. X grows right; Y grows down. All asteroid tiles have `x < 0`; asteroid left-expansions add tiles at increasingly negative X. The origin never shifts.
|
||||
@@ -100,19 +123,31 @@ Modules in `modules.toml` define a `surface_mask` — a list of strings that des
|
||||
- REQ-BLD-COST: The player places buildings from a build menu. Placement costs building blocks from the global stock. The cost per building type is read from `buildings.toml [[building]].cost`.
|
||||
- REQ-BLD-QUEUE: Placed buildings enter a construction queue and are built one at a time. Each building takes a duration defined in `buildings.toml [[building]].construction_time_seconds` to construct.
|
||||
- REQ-BLD-ASTEROID-ONLY: Buildings can only be placed on asteroid tiles (per surface_mask; tiles marked `S` may extend into space).
|
||||
- REQ-BLD-BUILDER-MODE: Clicking a build button activates builder mode for that building type. Builder mode is exited by right-clicking in the game world or clicking the same build button again.
|
||||
- REQ-BLD-BUILDER-MODE: Clicking a build button activates builder mode for that building type. Builder mode is exited by right-clicking in the game world or clicking the same build button again. (Exception: while a belt drag placement is in progress, right-clicking cancels that drag instead of exiting, and builder mode stays active — REQ-BLD-BELT-DRAG.)
|
||||
- REQ-BLD-GHOST: While in builder mode, a ghost of the building is rendered at the tile under the cursor, showing where it would be placed. The ghost is drawn semi-transparently in the building type's own visuals — its `fill` and `outline` colors and `glyph` from `visuals.toml` — so that different building types are visually distinguishable in builder mode rather than all looking alike. When the current cursor position is invalid, the ghost instead uses the distinct "invalid" color (REQ-BLD-PLACE-VALID), which overrides the per-building coloring.
|
||||
- REQ-BLD-ROTATE: While in builder mode, pressing Shift+R rotates the ghost 90° clockwise and R rotates it 90° counter-clockwise. Rotation affects the direction of the output port.
|
||||
- REQ-BLD-PLACE: Clicking a valid tile in builder mode places a construction site and adds it to the build queue, consuming building blocks from the global stock.
|
||||
- REQ-BLD-PLACE: Clicking a valid tile in builder mode places a construction site and adds it to the build queue, consuming building blocks from the global stock. (For belts, placement is instead deferred to a drag gesture and happens on mouse release — REQ-BLD-BELT-DRAG.)
|
||||
- REQ-BLD-PLACE-VALID: A placement position is valid only if (a) every footprint cell in the rotated `surface_mask` is satisfied by the underlying terrain — `A` cells coincide with asteroid tiles, `S` cells coincide with space tiles — (b) no footprint cell overlaps an existing placed building or construction site, except as allowed by REQ-BLD-ROTATE-IN-PLACE, and (c) the player has enough building blocks to afford the building. The ghost (REQ-BLD-GHOST) is rendered in a distinct "invalid" color — overriding its per-building coloring (REQ-BLD-GHOST) — when the current cursor position fails any of these conditions.
|
||||
- REQ-BLD-ROTATE-IN-PLACE: If the ghost's footprint exactly coincides with the footprint of an existing placed building or construction site of the same building type, clicking places no new construction site and consumes no building blocks. Instead, the existing building or site is rotated to match the ghost's rotation. If the target is a construction site, its construction progress is preserved. This applies in both normal builder mode and blueprint placement mode; in blueprint placement mode it is evaluated per building in the blueprint independently — buildings in the blueprint whose footprint coincides with an existing same-type building or site are rotated in place, while the remaining buildings in the blueprint are placed as normal construction sites (subject to the usual validity checks and total cost).
|
||||
- REQ-BLD-BELT-DRAG: For belts, the player can click and drag across multiple tiles to place a construction site on each tile in one gesture.
|
||||
- REQ-BLD-TUNNEL-AUTO-SWITCH: After the player successfully places a Tunnel Entry construction site, builder mode automatically switches to Tunnel Exit (and vice versa), preserving the current ghost rotation. This makes it easy to immediately place the paired end without manually selecting the complementary type.
|
||||
- REQ-BLD-DEMOLISH: The player can demolish a placed factory building. Demolition returns `world.toml [world].refund_percentage` percent of the original building block cost (default 75%) to the global stock. Exception: if the building is still in the construction queue (not yet fully built, including the one currently being constructed), it is removed from the queue and the **full** building block cost is refunded. The HQ and player defence stations cannot be demolished.
|
||||
- REQ-BLD-DEMOLISH-CLICK: While in demolish mode (REQ-UI-HOTKEYS, REQ-UI-DEMOLISH-BUTTON), left-clicking a placed factory building or construction site in the game world demolishes it, following the refund rules of REQ-BLD-DEMOLISH — the partial refund for built buildings and the full refund for still-queued construction sites. Clicking a building that cannot be demolished (the HQ or a player defence station, per REQ-BLD-DEMOLISH), or clicking empty world space, has no effect. Demolish mode stays active after a demolition so the player can demolish further buildings without re-entering the mode; it is exited via the Q toggle (REQ-UI-HOTKEYS) or the Demolish button (REQ-UI-DEMOLISH-BUTTON).
|
||||
- REQ-BLD-DEMOLISH-BOX: While in demolish mode (REQ-UI-HOTKEYS, REQ-UI-DEMOLISH-BUTTON), the player can click and drag a selection box in the game world. A selection rectangle is drawn while dragging, using the same box-drag gesture and coverage semantics as the multi-select box (REQ-UI-MULTI-SELECT). On mouse up, every placed factory building and construction site covered by the box is demolished, each following the refund rules of REQ-BLD-DEMOLISH — the partial refund for built buildings and the full refund for still-queued construction sites. Buildings that cannot be demolished (the HQ and player defence stations, per REQ-BLD-DEMOLISH) are excluded from the box demolition; ships and defence stations are never affected.
|
||||
- REQ-BLD-ROTATE-IN-PLACE: If the ghost's footprint exactly coincides with the footprint of an existing placed building or construction site of the same building type, clicking places no new construction site and consumes no building blocks. Instead, the existing building or site is rotated to match the ghost's rotation. If the target is a construction site, its construction progress is preserved. **Exception:** Tunnel Entries and Tunnel Exits are never rotated in place — re-orienting a tunnel requires deconstructing and re-placing it (REQ-BLD-TUNNEL-MODE). A tunnel ghost whose footprint coincides with an existing tunnel is therefore treated as an ordinary occupied-tile placement (invalid in normal builder mode; skipped in blueprint placement mode). This applies in both normal builder mode and blueprint placement mode; in blueprint placement mode it is evaluated per building in the blueprint independently — buildings in the blueprint whose footprint coincides with an existing same-type building or site are rotated in place, while the remaining buildings in the blueprint are placed as normal construction sites (subject to the usual validity checks and total cost).
|
||||
- REQ-BLD-BELT-DRAG: **Belt drag placement.** For belts, placement is a deferred drag gesture rather than immediate per-tile placement: construction sites are not placed while the cursor hovers new tiles, but only once the player releases the left mouse button. Pressing the left mouse button in the game world while in belt builder mode starts a drag anchored at the tile under the cursor. As the cursor moves, a **rectilinear (L-shaped) path** of belt tiles is computed from the anchor tile to the tile under the cursor: the path first runs along the axis **parallel to the belt's current orientation** (REQ-BLD-ROTATE) — stepping toward the cursor's coordinate on that axis to a corner tile — and then runs along the orthogonal axis to the cursor tile. When the cursor shares the anchor's row or column the path degenerates to a straight line, and when it is on the anchor tile the path is a single tile.
|
||||
- **Snapping to a building.** When the tile under the cursor is occupied by a non-belt building or construction site (the **target**), the path does not end on that occupied tile. Instead the end tile is the tile **closest to the cursor** (by distance from the cursor position to the tile) among the tiles orthogonally adjacent to the target across one of its **input-capable edges** — any footprint edge that is not one of the target's output ports, i.e. an edge on which the target can accept an incoming item (REQ-MAT-INPUT-PORTS for buildings, REQ-MAT-ACCEPT-DIR for splitters and tunnels). The geometrically closest such tile is **always** used, even if it turns out not to be a valid belt endpoint — in that case it is previewed and applied by the ordinary rules below (invalid color and skipped if occupied by a non-belt building or invalid terrain; re-oriented if it already holds a belt). The rest of the L-shaped path is computed from the anchor to this end tile exactly as above. The end tile's belt direction points **toward the target** (across the shared input edge), overriding the "final tile keeps its incoming step" rule; this applies whether the end tile is a newly placed belt or an existing belt re-oriented in place, and is reflected both in the ghost preview and in the placement on release.
|
||||
- **Rotating during the drag.** Rotating the belt with R / Shift+R (REQ-BLD-ROTATE) while a drag is in progress re-picks the path's primary axis immediately from the new orientation and re-derives the whole path from the anchor to the current cursor tile, without waiting for the next cursor movement.
|
||||
- **Ghosts.** While dragging, a belt ghost (REQ-BLD-GHOST) is rendered on every path tile that would be acted on, instead of a single ghost under the cursor. Each ghost is oriented to point toward the next tile along the path toward the cursor, so the path forms one connected belt run that turns at the corner (curved belts along the path auto-derive per REQ-BLD-BELT); the final tile keeps the direction of its incoming step (unless the end tile is snapped to a building, in which case it points into the target — see **Snapping to a building**), and a single-tile path keeps the belt's current orientation. A tile occupied by only an existing belt or belt construction site is a valid target — its belt is re-oriented to follow the path — and shows a normal belt ghost. A tile occupied by a non-belt building or construction site, or otherwise an invalid belt position (REQ-BLD-PLACE-VALID), is drawn in the distinct invalid color, overriding the belt coloring. A tile whose new belt is unaffordable — the cumulative cost of the belts newly placed up to and including it exceeds the global stock — shows **no ghost at all**.
|
||||
- **Placement on release.** No construction site is placed while dragging. On releasing the left mouse button, the path is applied in order (anchor to cursor): each cell occupied by only an existing belt or belt construction site has that belt re-oriented in place to its path direction, consuming no building blocks and preserving any construction progress (REQ-BLD-ROTATE-IN-PLACE); each empty, valid cell gets a new belt construction site, consuming building blocks from the global stock (REQ-BLD-COST). Cells occupied by a non-belt building or construction site, cells that are otherwise invalid (REQ-BLD-PLACE-VALID), and cells whose new belt can no longer be afforded once the running total has been spent are skipped. This supersedes the click-to-place of REQ-BLD-PLACE for belts, including both the single-tile case and multi-tile drags that pass over existing belts.
|
||||
- **Right-click cancels the drag.** Right-clicking while a belt drag is in progress cancels it: the path is discarded, no construction site is placed, and belt builder mode stays active (the exception to REQ-BLD-BUILDER-MODE). Right-clicking when no drag is in progress exits builder mode as usual (REQ-BLD-BUILDER-MODE).
|
||||
- REQ-BLD-TUNNEL-MODE: **Unified tunnel build mode.** The build button grid contains a single **Tunnel** button rather than separate Tunnel Entry and Tunnel Exit buttons (REQ-UI-BUILD-GRID), activated by that button or by hotkey 3 (REQ-UI-HOTKEYS). This one builder mode places either a Tunnel Entry or a Tunnel Exit construction site depending on the hovered position, so the player never manually chooses between the two ends. Both remain distinct building types (REQ-BLD-TUNNEL-ENTRY, REQ-BLD-TUNNEL-EXIT) with their own costs and construction; only their build-menu entry point is unified.
|
||||
- **Default type.** The ghost (REQ-BLD-GHOST) is a **Tunnel Entry** by default; clicking places a Tunnel Entry construction site (REQ-BLD-PLACE). Rotation (REQ-BLD-ROTATE) sets the ghost's facing direction as for any building.
|
||||
- **Exit-completion match.** While the ghost is at a valid position, the game tests whether placing a **Tunnel Exit** at the hovered tile with the current ghost rotation would pair — per the pairing rules of REQ-BLD-TUNNEL-PAIR (same facing direction, within `tunnel_max_distance`, first same-direction building along the search, nearest-claim semantics) — with an existing Tunnel Entry. If so, that Entry is the **exit-completion match** and the ghost turns into a **Tunnel Exit**; clicking then places a Tunnel Exit construction site.
|
||||
- **Entry-completion match.** The game also tests whether placing a **Tunnel Entry** at the hovered tile with the current ghost rotation would pair — again per REQ-BLD-TUNNEL-PAIR — with an existing Tunnel Exit. If so, that Exit is the **entry-completion match** and the ghost stays a Tunnel Entry.
|
||||
- **Resolving the type.** If neither match exists, the ghost is a Tunnel Entry (the default). If only one kind of match exists, the ghost is the kind that produces it (Tunnel Exit for an exit-completion match, Tunnel Entry for an entry-completion match). If **both** an exit-completion match (an existing Entry) and an entry-completion match (an existing Exit) exist, the mode resolves to the completion whose **existing partner building is closer to the mouse cursor position** — the actual sub-tile cursor position, not the hovered tile's center — and the ghost becomes the corresponding type (a Tunnel Exit to complete the nearer Entry, or a Tunnel Entry to complete the nearer Exit). Because the comparison uses the sub-tile cursor position, when the two partners are at the same tile distance the player can move the cursor within the hovered tile to switch which end is placed. When more than one candidate qualifies on a side, the nearest qualifying partner on that side is used.
|
||||
- **Connection preview (green).** Whenever a completion match is resolved, the matched existing partner building is highlighted green, and every tile strictly between that partner and the hovered ghost tile (along the tunnel's straight run) is marked green, previewing the connection that placing the ghost would create.
|
||||
- **Invalid positions.** The completion tests, type switch, and green preview apply only while the hovered position is a valid placement (REQ-BLD-PLACE-VALID). At an invalid position the ordinary invalid-colored ghost is shown (REQ-BLD-GHOST) with no green preview and no switch away from the default Tunnel Entry.
|
||||
- REQ-BLD-DECONSTRUCT: The player can deconstruct a placed factory building. Deconstructing a **fully-built** factory building does not remove it instantly: it is added to the deconstruction queue (REQ-BLD-DECON-QUEUE) and, once its deconstruction completes, `world.toml [world].refund_percentage` percent of the original building block cost (default 75%) is returned to the global stock. Exception: if the building is still in the construction queue (not yet fully built, including the one currently being constructed), it is **not** queued for deconstruction but removed instantly from the construction queue, and the **full** building block cost is refunded immediately. The HQ and player defence stations cannot be deconstructed.
|
||||
- REQ-BLD-DECON-QUEUE: Fully-built factory buildings marked for demolition (REQ-BLD-DECONSTRUCT) enter a **deconstruction queue** that is processed one building at a time and runs in parallel with the construction queue (REQ-BLD-QUEUE) — the two queues advance independently and simultaneously. Each building takes `world.toml [world].deconstruction_time_seconds` (default 0.1) to deconstruct, the same duration for every building type. When a building's deconstruction completes it is removed from the world and its refund is credited (REQ-BLD-DECONSTRUCT). A building **stops operating the moment it enters the queue**: it runs no production and transports no items, and no longer participates as a live building (its tunnel pairing is re-evaluated as if it were gone, REQ-BLD-TUNNEL-PAIR), but it still physically occupies its tiles until removed, so those tiles stay blocked for placement. A queued building can be taken back out of the deconstruction queue before it is removed (REQ-BLD-DECONSTRUCT-CLICK, REQ-BLD-DECONSTRUCT-BOX) — including the one currently being deconstructed; doing so discards any deconstruction progress, credits no refund, and the building resumes operating (and re-pairs, REQ-BLD-TUNNEL-PAIR). Construction sites never enter the deconstruction queue (REQ-BLD-DECONSTRUCT). Every building in the deconstruction queue is rendered with the deconstruct tint — the `visuals.toml [overlays].deconstruct_tint` color, the same tint applied to a building hovered in deconstruct mode (REQ-UI-DECONSTRUCT-BORDER) — so queued buildings are visually distinct.
|
||||
- REQ-BLD-DECONSTRUCT-CLICK: While in deconstruct mode (REQ-UI-HOTKEYS, REQ-UI-DECONSTRUCT-BUTTON), left-clicking a placed factory building or construction site in the game world marks it for demolition, following the rules of REQ-BLD-DECONSTRUCT: a fully-built building is added to the deconstruction queue (REQ-BLD-DECON-QUEUE), and a construction site is removed instantly with the full refund. Left-clicking a fully-built building that is **already in the deconstruction queue** instead removes it from the queue (un-queues it, REQ-BLD-DECON-QUEUE), with no refund; repeated clicks on the same building therefore alternate between queueing and un-queueing it. Clicking a building that cannot be deconstructed (the HQ or a player defence station, per REQ-BLD-DECONSTRUCT), or clicking empty world space, has no effect. Deconstruct mode stays active after each action so the player can continue without re-entering the mode; it is exited via the Q toggle (REQ-UI-HOTKEYS) or the Deconstruct button (REQ-UI-DECONSTRUCT-BUTTON).
|
||||
- REQ-BLD-DECONSTRUCT-BOX: While in deconstruct mode (REQ-UI-HOTKEYS, REQ-UI-DECONSTRUCT-BUTTON), the player can click and drag a selection box in the game world. A selection rectangle is drawn while dragging, using the same box-drag gesture and coverage semantics as the multi-select box (REQ-UI-MULTI-SELECT). On mouse up, following the rules of REQ-BLD-DECONSTRUCT: every construction site covered by the box is removed instantly with the full refund; and among the fully-built deconstructible buildings covered by the box, if **all** of them are already in the deconstruction queue they are all removed from it (un-queued, REQ-BLD-DECON-QUEUE), otherwise every covered building not yet in the queue is added to the deconstruction queue (already-queued ones stay). Buildings that cannot be deconstructed (the HQ and player defence stations, per REQ-BLD-DECONSTRUCT) are excluded from the box demolition; ships and defence stations are never affected.
|
||||
- REQ-BLD-SITE-CONFIG: A construction site — a building that has been placed but is still queued or under construction (REQ-BLD-QUEUE) — can be selected and configured exactly like the equivalent operational building, before it finishes building. Whatever configuration the building type supports is available on the site: the recipe for a Miner or Assembler (REQ-UI-SELECT-BUTTON), the produced-ship schematic and its module layout for a Shipyard (REQ-UI-SELECT-BUTTON, REQ-MOD-UI-PREVIEW, REQ-MOD-UI-DIALOG), and the output filters for a Splitter (REQ-BLD-SPLITTER) — all set through the same Selected Building Panel controls (REQ-UI-CONFIG-INLINE). Only currently unlocked recipes and schematics are offered, exactly as for operational buildings (REQ-LOCK-UI-RECIPE, REQ-LOCK-UI-SCHEMATIC, REQ-LOCK-UI-SPLITTER). The configuration is stored on the construction site and carries over unchanged when construction completes, so the building becomes operational already configured. A construction site has no input/output buffers and runs no production cycle, so the buffer and production-progress portions of the panel (REQ-UI-SINGLE-SELECTION, REQ-UI-PRODUCTION-PROGRESS) are not shown for it; only its construction progress (REQ-UI-CONSTRUCTION-PROGRESS) and its configuration controls appear. (Blueprint placement already applies a stored recipe or schematic to a construction site on placement per REQ-UI-BLUEPRINT-PLACE; this requirement additionally lets the player set or change that configuration directly on an existing site.)
|
||||
- REQ-BLD-COPY-CONFIG: **Copy building settings (hold Shift).** While the Shift key is held, the player can copy one building's settings onto other buildings of the same type, so several identical machines can be set up without opening each one's panel. This gesture is available only in the default selection mode; while a builder, blueprint placement, or demolish mode is active it is disabled, so it never clashes with placement or demolition clicks.
|
||||
- REQ-BLD-COPY-CONFIG: **Copy building settings (hold Shift).** While the Shift key is held, the player can copy one building's settings onto other buildings of the same type, so several identical machines can be set up without opening each one's panel. This gesture is available only in the default selection mode; while a builder, blueprint placement, or deconstruct mode is active it is disabled, so it never clashes with placement or demolition clicks.
|
||||
- **Shift + right-click** a building copies its current settings into a temporary cache, along with the building's type. The settings copied are whatever that building type supports: the selected recipe (Miner, Assembler), the selected schematic together with its module layout (Shipyard), or the two output filters (Splitter, REQ-BLD-SPLITTER). Copying succeeds only when there is something to copy — a Miner or Assembler with a recipe selected, a Shipyard with a schematic selected, or any Splitter (whose output filters, even when empty/accept-all, always constitute valid settings). Shift + right-clicking a configurable building with nothing yet selected, a building type that has no settings at all (Smelter, Reprocessing Plant, Salvage Bay, belt/tunnel tiles, the HQ), or empty world space, has no effect and leaves any existing cache unchanged.
|
||||
- **Shift + left-click** a building of the **same type** as the cached one applies the cached settings to it, exactly as if the player had made that selection through the selected building panel — with the same effects as a normal selection change (buffer clearing per REQ-MAT-INPUT-BUFFER and REQ-MAT-OUTPUT-BUFFER, and, for a Shipyard, in-progress cycle cancellation per REQ-BLD-SHIPYARD). This can be repeated on any number of same-type buildings while Shift stays held. Shift + left-clicking a building of a different type than the cached one, any building while the cache is empty, or empty world space, has no effect.
|
||||
- Both operational buildings and construction sites take part as source and target (REQ-BLD-SITE-CONFIG); settings applied to a construction site carry over unchanged when it finishes building.
|
||||
@@ -136,13 +171,14 @@ Modules in `modules.toml` define a `surface_mask` — a list of strings that des
|
||||
- In all alternation cases, if one output is blocked the item goes to the other output until it unblocks.
|
||||
- REQ-BLD-TUNNEL-ENTRY: **Tunnel Entry** (1×1): The sending end of a tunnel pair. The player sets a direction (N, S, E, W) at placement, rotatable with R/Shift+R. Items arriving from an adjacent belt tile on a non-output edge (i.e. not the mouth edge in the entry's facing direction — see REQ-MAT-ACCEPT-DIR) whose direction points into the entry are forwarded through the tunnel to the paired Tunnel Exit (see REQ-BLD-TUNNEL-PAIR, REQ-BLD-TUNNEL-TRANSIT). If the entry is unpaired, or if the paired exit's output is blocked, the entry blocks like a full belt tile.
|
||||
- REQ-BLD-TUNNEL-EXIT: **Tunnel Exit** (1×1): The receiving end of a tunnel pair. The player sets a direction at placement, rotatable with R/Shift+R. Items received from the paired Tunnel Entry emerge from the output side of the exit tile — the tile adjacent in the exit's facing direction — continuing in that direction. If the exit is unpaired or its output is blocked, it holds received items until they can advance.
|
||||
- REQ-BLD-TUNNEL-PAIR: **Tunnel pairing rules.** Pairing is re-evaluated for all Tunnel Entries whenever any Tunnel Entry or Tunnel Exit is placed or demolished.
|
||||
- REQ-BLD-TUNNEL-PAIR: **Tunnel pairing rules.** Pairing is re-evaluated for all Tunnel Entries whenever any Tunnel Entry or Tunnel Exit is placed, deconstructed, or enters or leaves the deconstruction queue (REQ-BLD-DECON-QUEUE; a tunnel end that is queued for deconstruction counts as removed for pairing).
|
||||
- A Tunnel Entry searches tile-by-tile in its facing direction for a partner. Any tunnel building (entry or exit) that faces a *different* direction is ignored and skipped. The search stops at the first tunnel building that faces the *same* direction as the searching entry.
|
||||
- If that first same-direction tunnel building is a Tunnel Exit, is within `tunnel_max_distance` tiles of the entry, and is not already paired with a closer entry, the two form a pair.
|
||||
- Otherwise the entry is unpaired.
|
||||
- Pairing is one-to-one: each Tunnel Entry pairs with at most one Tunnel Exit, and vice versa. A Tunnel Exit is claimed by the nearest Tunnel Entry that can validly reach it; all other entries for which it would otherwise qualify are unpaired.
|
||||
- When one end of a pair is demolished, the pair is dissolved and any items currently in transit are discarded.
|
||||
- When one end of a pair is deconstructed, the pair is dissolved and any items currently in transit are discarded.
|
||||
- REQ-BLD-TUNNEL-TRANSIT: **Tunnel transit.** Items inside a tunnel are not rendered (they travel invisibly). Transit time equals the tile-coordinate distance between entry and exit divided by `world.toml [world].belt_speed_tiles_per_second`, matching the time a chain of belt tiles of equivalent length would take. Multiple items may be in transit simultaneously, spaced as they would be on a belt chain of the same length. Clearing a tunnel entry or exit tile (REQ-UI-BELT-CLEAR) also discards all items currently in transit through that tunnel.
|
||||
- REQ-BLD-TUNNEL-SELECT-HIGHLIGHT: **Selected-tunnel connection highlight.** While a Tunnel Entry or Tunnel Exit — operational building or construction site — is part of the current selection (single selection or multi-selection, REQ-UI-MULTI-SELECT), its tunnel connection is marked green in the game world, using the same `visuals.toml [overlays].tunnel_preview` green as the placement connection preview (REQ-BLD-TUNNEL-MODE). The matching end is found by applying the pairing scan of REQ-BLD-TUNNEL-PAIR over both built tunnels **and** construction-site tunnels (site-inclusive, matching the placement preview): for a selected entry, the first same-direction tunnel within `tunnel_max_distance` along its facing direction, if it is a Tunnel Exit; for a selected exit, the first same-direction tunnel within `tunnel_max_distance` opposite its facing direction, if it is a Tunnel Entry. When a matching end is found, the entry tile, the exit tile, and every tile strictly between them (along the tunnel's straight run) are marked green. A selected tunnel with no matching end shows no green highlight (it still receives the normal selection outline). In multi-selection each selected tunnel end that has a matching end contributes its connection, and a given connection is shown whenever either of its ends is selected. The highlight is presentation-only and has no effect on the simulation.
|
||||
|
||||
## Material Transport & Buffers
|
||||
|
||||
@@ -181,7 +217,7 @@ Modules in `modules.toml` define a `surface_mask` — a list of strings that des
|
||||
## Ships
|
||||
|
||||
- REQ-SHP-AUTONOMOUS: Ships are produced by shipyards and are fully autonomous once produced.
|
||||
- REQ-SHP-STATS: Base hull stats are defined as plain values in `ships.toml`: HP (`[ship.health].hp`), max linear speed (`[ship.movement].speed`), sensor range (`[ship.sensors].range`), main acceleration (`[ship.movement].main_acceleration`, tiles/s²), maneuvering acceleration (`[ship.movement].maneuvering_acceleration`, tiles/s²), angular acceleration (`[ship.movement].angular_acceleration`, rad/s²), max rotation speed (`[ship.movement].max_rotation_speed`, rad/s). Required build materials (`[ship.schematic].materials`) and the station level at which the schematic becomes available for unlock (`[[ship]].unlock_at_station_level`; -1 = player starts with the schematic already unlocked) are also defined there. Combat, salvage, and repair capabilities are provided by modules (see REQ-MOD-CONFIG). Final hull stats incorporate passive module modifiers per REQ-MOD-STAT-CALC.
|
||||
- REQ-SHP-STATS: Base hull stats are defined as plain values in `ships.toml`: HP (`[ship.health].hp`), max linear speed (`[ship.movement].speed`), sensor range (`[ship.sensors].range`), main acceleration (`[ship.movement].main_acceleration`, tiles/s²), maneuvering acceleration (`[ship.movement].maneuvering_acceleration`, tiles/s²), angular acceleration (`[ship.movement].angular_acceleration`, rad/s²), max rotation speed (`[ship.movement].max_rotation_speed`, rad/s). Required build materials (`[ship.schematic].materials`) are also defined there; whether the schematic starts unlocked or must be awarded during play is defined in `unlocks.toml` (REQ-LOCK-EXPLICIT). Combat, salvage, and repair capabilities are provided by modules (see REQ-MOD-CONFIG). Final hull stats incorporate passive module modifiers per REQ-MOD-STAT-CALC.
|
||||
- REQ-SHP-SPAWN-PLAYER: A ship produced by a shipyard spawns centered on the shipyard's output port tile.
|
||||
- REQ-SHP-SPAWN-ENEMY: Enemy ships spawn at a uniformly random position within the current enemy buffer zone — random X across the buffer's width and random Y across the world height.
|
||||
- REQ-SHP-MOVEMENT: Ships move using a physics-based model. Each ship has a velocity and a facing direction, both updated each tick. The main acceleration (`main_acceleration`) is applied along the ship's current facing direction only. The maneuvering acceleration (`maneuvering_acceleration`) can be applied in any direction independently of the facing direction, enabling lateral or braking movement without rotating. The angular acceleration (`angular_acceleration`) controls how quickly the ship rotates. Linear speed is capped at the ship's `speed` value; rotation rate is capped at the ship's `max_rotation_speed` value. Ship position refers to the ship's center for all range, sensor, and attack checks.
|
||||
@@ -222,8 +258,6 @@ Modules in `modules.toml` define a `surface_mask` — a list of strings that des
|
||||
- `id` — unique identifier, also used as the display name in the UI.
|
||||
- `surface_mask` — footprint within the ship layout grid (see Module Surface Mask Format).
|
||||
- `materials` — list of materials required per instance (added to the ship's build cost).
|
||||
- `unlock_at_station_level` — the enemy defence station level at which this module's schematic becomes available for unlock; -1 means the player starts with the module schematic already unlocked.
|
||||
- `unlock_requires` — optional list of prerequisite schematic ids that must already be unlocked before this module's schematic can drop (REQ-LOCK-PREREQ). Defaults to empty.
|
||||
- `production_time_seconds` — time added to the ship's production cycle per instance.
|
||||
- `fill_color` — fill color used to render this module's cells in the layout grid.
|
||||
- `glyph` — single character rendered on this module's cells in the layout grid and preview widget.
|
||||
@@ -287,6 +321,8 @@ Modules in `modules.toml` define a `surface_mask` — a list of strings that des
|
||||
- **Right** (below the grid): The layout blueprint panel (see REQ-MOD-UI-BLUEPRINT-PANEL through REQ-MOD-UI-BLUEPRINT-FILE-LOAD).
|
||||
- **Bottom**: A "Confirm" button and a "Cancel" button. Cancel discards all changes made in this dialog session and closes the dialog. Confirm applies the changes: the shipyard's configured layout is updated, the required materials and cycle time displayed in the selected building panel are recalculated, and the ship layout preview is refreshed.
|
||||
|
||||
- REQ-MOD-UI-EMPTY-PULSE: While a module is selected for placement in the layout configuration dialog (REQ-MOD-UI-DIALOG), the empty buildable cells of the layout grid pulse smoothly around their normal fill shade, oscillating between a slightly darker and a slightly brighter shade at approximately 1 Hz (one full cycle per second), to draw the player's attention to where the module can be placed. All empty buildable cells pulse in phase. When no module is selected for placement (including remove mode), empty buildable cells render at their normal static shade. Non-buildable cells and cells occupied by a placed module do not pulse.
|
||||
|
||||
- REQ-MOD-UI-AUTO-DIALOG: When the player selects a schematic for a shipyard (operational building or construction site) through the schematic selection dialog (REQ-UI-SELECT-BUTTON), and the chosen schematic **differs** from the shipyard's current schematic, the layout configuration dialog (REQ-MOD-UI-DIALOG) opens automatically and immediately once the selection dialog closes — exactly as if the player had then clicked "Configure". Re-selecting the schematic already set does not reopen the dialog. This auto-open applies only to the manual schematic selection dialog; schematic changes applied via the copy-settings gesture (REQ-BLD-COPY-CONFIG) or blueprint placement (REQ-UI-BLUEPRINT-PLACE) do **not** auto-open the dialog. The player may still cancel the auto-opened dialog (REQ-MOD-UI-DIALOG), which leaves the newly selected schematic in place with its default empty layout; the "Configure" button (REQ-MOD-UI-PREVIEW) remains available to open the dialog again later.
|
||||
|
||||
- REQ-MOD-UI-MODULE-TOOLTIP: Each module selection button in the layout configuration dialog (REQ-MOD-UI-DIALOG) shows a hover tooltip with the descriptive text defined for that module type in `modules.toml` (the optional per-module tooltip field). If a module type defines no tooltip text, its button shows no tooltip. The "Remove" button is not a module type and has no config-defined tooltip.
|
||||
@@ -335,35 +371,27 @@ Modules in `modules.toml` define a `surface_mask` — a list of strings that des
|
||||
- REQ-DEF-ENEMY-FIRE: Enemy defence stations automatically fire at player ships within range.
|
||||
- REQ-DEF-NO-CROSSFIRE: Enemy and player defence stations are never in each other's firing range.
|
||||
- REQ-DEF-PUSH: When both enemy defence stations in a set are destroyed, the boss countdown is advanced (REQ-WAV-BOSS-ADVANCE), the scrollable area is extended (REQ-GW-PUSH-EXPAND), a new set of enemy defence stations is placed at the new boundary, and exactly one schematic drop is awarded for the destroyed set (REQ-DEF-SCHEMATIC-DROP).
|
||||
- REQ-DEF-SCHEMATIC-DROP: Each destroyed set of enemy defence stations awards exactly one schematic drop (not one per station). The drop opens a **schematic choice dialog** — a modal dialog that pauses the game (speed set to 0×; on close, speed is restored to what it was before the dialog opened). Before drawing schematic picks, an artifact roll is made: evaluate `world.toml [world].artifact_chance_formula` with `x` set to the level of the destroyed station set, clamp the result to [0, 1], then compare against a uniform random value in [0, 1). If the roll succeeds, the dialog presents one **artifact option** plus two schematic picks drawn from the eligible pool; otherwise it presents three schematic picks. Up to three (or two, if an artifact option is present) schematic options are drawn uniformly at random **without replacement** from the eligible drop pool. If the pool contains fewer than the required number of entries, only that many schematic options are shown (the artifact option is always shown if the roll succeeded). The eligible drop pool contains:
|
||||
- All **ship schematics** and **module schematics** whose `unlock_at_station_level` is ≥ 0 and ≤ the level of the destroyed station set, and which have not yet been unlocked.
|
||||
- All **assembler recipe schematics** whose `unlock_at_station_level` is ≥ 0 and ≤ the level of the destroyed station set, whose output item is currently implicitly unlocked (REQ-LOCK-IMPLICIT), and which have not yet been awarded.
|
||||
- REQ-DEF-SCHEMATIC-DROP: Each destroyed set of enemy defence stations awards exactly one drop (not one per station). The drop opens a **schematic choice dialog** — a modal dialog that pauses the game (speed set to 0×; on close, speed is restored to what it was before the dialog opened). Before drawing picks, an artifact roll is made: evaluate `world.toml [world].artifact_chance_formula` with `x` set to the level of the destroyed station set, clamp the result to [0, 1], then compare against a uniform random value in [0, 1). If the roll succeeds, the dialog presents one **artifact option** plus two unlock picks drawn from the eligible pool; otherwise it presents three unlock picks. Up to three (or two, if an artifact option is present) unlock options are drawn uniformly at random **without replacement** from the eligible pool. If the pool contains fewer than the required number of entries, only that many unlock options are shown (the artifact option is always shown if the roll succeeded).
|
||||
|
||||
In addition to the conditions above, a schematic is included in the eligible drop pool only when every prerequisite in its optional `unlock_requires` list is currently satisfied (REQ-LOCK-PREREQ). Because the pool is rebuilt for each drop, a schematic gated behind prerequisites first appears only after all of its prerequisites have themselves been unlocked.
|
||||
The eligible pool contains every **unlock group** (REQ-LOCK-EXPLICIT) that (a) has not yet been awarded, (b) whose `station_level` is ≤ the level of the destroyed station set, and (c) every prerequisite in its `requires` list is currently satisfied (REQ-LOCK-PREREQ). Because the pool is rebuilt for each drop, an unlock group gated behind prerequisites first appears only after all of its prerequisites have themselves been awarded.
|
||||
|
||||
Each option in the dialog displays: the schematic name (ship `id` from `ships.toml`, module `id` from `modules.toml`, or assembler recipe `id` from `recipes.toml`) and the schematic type (ship, module, or assembler recipe). The artifact option (if present) is displayed as a distinct entry with the name "Artifact".
|
||||
Each option in the dialog displays the unlock group's display name — derived from its `id` (same display convention as building, module, and recipe ids) — and the list of items it would grant: its ship, module, building, and assembler-recipe ids (each shown with the same display convention as its respective selection dialog). The artifact option (if present) is displayed as a distinct entry with the name "Artifact".
|
||||
|
||||
Each option additionally displays a vertical list of recipe names labeled "Unlocks recipes:", showing which miner and assembler recipes would newly become implicitly unlocked (REQ-LOCK-IMPLICIT) if this option were selected — specifically, the miner recipes and assembler recipes (without `unlock_at_station_level`) that are not currently implicitly unlocked but would become so after applying this option's effect:
|
||||
- For a ship or module schematic, its `materials` are added to the base set per REQ-LOCK-IMPLICIT step 1a before recomputation.
|
||||
- For an assembler recipe schematic, its output item is added to the base set per REQ-LOCK-IMPLICIT step 1b before recomputation.
|
||||
Each option additionally displays a vertical list of recipe names labeled "Unlocks recipes:", showing which miner and assembler recipes would newly become implicitly unlocked (REQ-LOCK-IMPLICIT) if this option were selected — specifically, the miner recipes and implicitly-gated assembler recipes that are not currently implicitly unlocked but would become so after applying this option's effect. To compute this, all `materials` of the group's granted ship and module schematics are added to the base set per REQ-LOCK-IMPLICIT step 1a, and the output items of the group's granted assembler recipes are added per step 1b, before recomputation.
|
||||
|
||||
Each recipe is listed by its `id` (using the same display convention as the assembler recipe-selection dialog), sorted alphabetically. Hovering a recipe in this list displays the recipe info tooltip described for a recipe in REQ-UI-SELECT-TOOLTIP (the recipe name; the name and quantity of each input item; the completion time; and the name and quantity of the produced output item). If no recipes would be newly unlocked, the list shows "None".
|
||||
|
||||
The player selects one option by clicking it. If the player selects the artifact option, the player's artifact count is incremented by 1 (REQ-WIN-ARTIFACT-COUNT) and the dialog closes; no schematic is applied. Otherwise, the selected schematic is applied and the dialog closes:
|
||||
|
||||
For a **ship or module schematic**: it is unlocked (ship schematics unlock the corresponding shipyard selection; module schematics unlock the module type for placement in the layout configuration dialog (REQ-MOD-UI-DIALOG)).
|
||||
|
||||
For an **assembler recipe schematic**: the recipe is explicitly unlocked and becomes available in the assembler recipe-selection dialog (subject to REQ-LOCK-UI-RECIPE). The schematic is removed from the drop pool permanently (REQ-LOCK-EXPLICIT). The implicit unlock set is recomputed (REQ-LOCK-IMPLICIT).
|
||||
The player selects one option by clicking it. If the player selects the artifact option, the player's artifact count is incremented by 1 (REQ-WIN-ARTIFACT-COUNT) and the dialog closes; no unlock is applied. Otherwise the selected unlock group is awarded and the dialog closes: every ship, module, building, and assembler recipe the group grants becomes unlocked at once — ship schematics unlock the corresponding shipyard selection; module schematics unlock the module type for placement in the layout configuration dialog (REQ-MOD-UI-DIALOG); building types become available in the build menu (REQ-LOCK-BUILDING); assembler recipes become available in the assembler recipe-selection dialog (subject to REQ-LOCK-UI-RECIPE). The unlock group is removed from the pool permanently (REQ-LOCK-EXPLICIT), and the implicit unlock set is recomputed (REQ-LOCK-IMPLICIT).
|
||||
|
||||
## Progression & Locking
|
||||
|
||||
- REQ-LOCK-EXPLICIT: Ship schematics, module schematics, and **assembler recipe schematics** (assembler recipes in `recipes.toml` that define `unlock_at_station_level`) are **explicitly** locked or unlocked. A schematic starts unlocked if its `unlock_at_station_level` is -1; all others start locked. Locked schematics are unlocked only by REQ-DEF-SCHEMATIC-DROP. Once unlocked, a schematic is never re-locked within a run; lock states reset to their initial values on Restart (REQ-CFG-RELOAD). Unlike ship and module schematics, an assembler recipe schematic is removed from the drop pool permanently once awarded and cannot be dropped again.
|
||||
- REQ-LOCK-EXPLICIT: The unit of unlocking is an **unlock group**, defined by an `[[unlock]]` entry in `unlocks.toml` (see Unlock Group Format). Each unlock group grants a set of ship schematics, module schematics, building types, and/or assembler recipes. A ship, module, building, or assembler recipe is **locked at game start if and only if some unlock group grants it**; anything not granted by any unlock group starts unlocked. (For assembler recipes this "starts unlocked" is further governed by implicit gating — see REQ-LOCK-IMPLICIT; an assembler recipe granted by an unlock group is explicitly gated and never subject to implicit unlocking, while one flagged `unlocked_at_start` is always available.) A locked item is unlocked only by awarding its unlock group via REQ-DEF-SCHEMATIC-DROP, which grants all of the group's members at once. Once awarded, an unlock group and its members are never re-locked within a run, and the group is removed from the drop pool permanently; lock states reset to their initial values on Restart (REQ-CFG-RELOAD). Each grantable id may be granted by **at most one** unlock group; a grant id that names no defined ship/module/building/assembler-recipe, that names a non-assembler recipe, or that is granted by more than one unlock group, is a configuration error that fails config load with a descriptive message (REQ-CFG-RELOAD).
|
||||
|
||||
- REQ-LOCK-PREREQ: A ship schematic, module schematic, or assembler recipe schematic may optionally define `unlock_requires` — a list of prerequisite schematic ids (a ship `id`, module `id`, or assembler recipe `id`) that must already be unlocked before this schematic may enter the drop pool. A prerequisite is **satisfied** only when the schematic it names is currently **explicitly unlocked** (REQ-LOCK-EXPLICIT) — that is, the referenced schematic either started unlocked with `unlock_at_station_level = -1` or has been awarded via a drop. This prerequisite check is applied in addition to the per-schematic conditions in REQ-DEF-SCHEMATIC-DROP: a schematic enters the eligible drop pool only when its `unlock_at_station_level` condition is met, it has not yet been unlocked/awarded, and every id in its `unlock_requires` is satisfied. `unlock_requires` defaults to empty (no prerequisites), which reproduces the prior behaviour. The check is re-evaluated against the current explicit-unlock set every time a drop pool is built (after each REQ-DEF-SCHEMATIC-DROP and on Restart per REQ-CFG-RELOAD), so a gated schematic becomes eligible in the first drop after its last prerequisite is unlocked. Every id listed in any `unlock_requires` must resolve to a schematic that is itself explicitly unlockable (a ship, module, or assembler recipe schematic defined in config); an id that names no such schematic is a configuration error that fails config load with a descriptive message (config is loaded at startup and reloaded on Restart, REQ-CFG-RELOAD). A schematic that lists itself, or a cycle of mutually dependent prerequisites, is not a load error but can never become eligible, since no schematic in the cycle can be the first to unlock.
|
||||
- REQ-LOCK-PREREQ: An unlock group may optionally define `requires` — a list of prerequisite **unlock-group ids** that must already have been awarded before this group may enter the drop pool. A prerequisite is **satisfied** only when the unlock group it names has been awarded (REQ-LOCK-EXPLICIT). This check is applied in addition to the conditions in REQ-DEF-SCHEMATIC-DROP: a group enters the eligible pool only when its `station_level` condition is met, it has not yet been awarded, and every id in its `requires` is satisfied. `requires` defaults to empty (no prerequisites). The check is re-evaluated against the current set of awarded unlock groups every time a drop pool is built (after each REQ-DEF-SCHEMATIC-DROP and on Restart per REQ-CFG-RELOAD), so a gated group becomes eligible in the first drop after its last prerequisite is awarded. Every id listed in any `requires` must resolve to an unlock group defined in `unlocks.toml`; an id that names no such group is a configuration error that fails config load with a descriptive message (config is loaded at startup and reloaded on Restart, REQ-CFG-RELOAD). An unlock group that lists itself, or a cycle of mutually dependent prerequisites, is not a load error but can never become eligible, since no group in the cycle can be the first to be awarded.
|
||||
|
||||
- REQ-LOCK-IMPLICIT: Item types and miner/assembler recipes are **implicitly** unlocked or locked based on the current set of unlocked ship, module, and assembler recipe schematics. The implicit unlock set is recomputed whenever any schematic changes lock state (on Restart or after REQ-DEF-SCHEMATIC-DROP). Computation:
|
||||
1. Start with the union of: (a) all item types listed in `materials` across all currently unlocked ship schematics and all currently unlocked module schematics, and (b) the output item type of every currently explicitly unlocked assembler recipe schematic (REQ-LOCK-EXPLICIT).
|
||||
2. For each item type in the current set: for every recipe (miner, smelter, or assembler) that produces it — skipping any assembler recipe schematic that defines `unlock_at_station_level` and is not yet explicitly unlocked — add each of that recipe's input item types to the set. If the recipe is a miner recipe or an assembler recipe that does not define `unlock_at_station_level`, mark it as implicitly unlocked. Explicitly unlocked assembler recipe schematics are available in the assembler recipe-selection dialog by virtue of REQ-LOCK-EXPLICIT; their inputs are also added to the implicit set in this step.
|
||||
1. Start with the union of: (a) all item types listed in `materials` across all currently unlocked ship schematics and all currently unlocked module schematics, and (b) the output item type of every assembler recipe that is currently **explicitly available** — that is, either flagged `unlocked_at_start` in `recipes.toml`, or granted by an unlock group that has been awarded (REQ-LOCK-EXPLICIT).
|
||||
2. For each item type in the current set: for every recipe (miner, smelter, or assembler) that produces it — skipping any assembler recipe that is granted by an unlock group whose group has not yet been awarded — add each of that recipe's input item types to the set. If the recipe is a miner recipe, or an assembler recipe that is not granted by any unlock group, mark it as implicitly unlocked. Assembler recipes that are explicitly available (flagged `unlocked_at_start`, or granted by an awarded unlock group) are available in the assembler recipe-selection dialog by virtue of REQ-LOCK-EXPLICIT; their inputs are also added to the implicit set in this step.
|
||||
3. Repeat step 2 until no new item types are added.
|
||||
Item types and miner/assembler recipes not reached by this process (and not explicitly unlocked) are locked. Smelter recipes participate in the traversal to propagate unlocking to their inputs but are never themselves shown in any UI dropdown.
|
||||
|
||||
@@ -373,9 +401,11 @@ Modules in `modules.toml` define a `surface_mask` — a list of strings that des
|
||||
|
||||
- REQ-LOCK-UI-SCHEMATIC: Locked ship schematics are not shown in the shipyard's schematic-selection dialog (REQ-UI-SELECT-BUTTON).
|
||||
|
||||
- REQ-LOCK-BUILDING: A building type granted by an unlock group (REQ-LOCK-EXPLICIT) is **locked** until that group is awarded. A locked building type has no button in the build button grid (REQ-UI-BUILD-GRID) and cannot be placed, selected as a build tool, or triggered by its build hotkey (REQ-UI-HOTKEYS); its button appears in the grid only once the building type is unlocked. Building types not granted by any unlock group are available from game start. Lock state resets on Restart (REQ-CFG-RELOAD).
|
||||
|
||||
- REQ-LOCK-UI-SPLITTER: Item types that are not implicitly unlocked are excluded from splitter filter dropdowns (REQ-BLD-SPLITTER).
|
||||
|
||||
- REQ-LOCK-UI-BLUEPRINT: When a blueprint is placed (REQ-UI-BLUEPRINT-PLACE): if a stored recipe ID for a miner or assembler is currently locked, that building's recipe is left unset rather than applied; if a stored splitter filter entry refers to a locked item type, that entry is silently removed. (The analogous rule for locked ship schematics is defined in REQ-UI-BLUEPRINT-PLACE.)
|
||||
- REQ-LOCK-UI-BLUEPRINT: When a blueprint is placed (REQ-UI-BLUEPRINT-PLACE): if a building in the blueprint is of a currently locked building type (REQ-LOCK-BUILDING), that building is silently skipped — no ghost, no validity check, no construction site, and its cost is excluded from the total — exactly as if it were not part of the blueprint; if a stored recipe ID for a miner or assembler is currently locked, that building's recipe is left unset rather than applied; if a stored splitter filter entry refers to a locked item type, that entry is silently removed. (The analogous rule for locked ship schematics is defined in REQ-UI-BLUEPRINT-PLACE.)
|
||||
|
||||
## Threat Level & Enemy Waves
|
||||
|
||||
@@ -424,8 +454,11 @@ The screen is divided into two columns: a main column (75% width) containing the
|
||||
|
||||
- REQ-UI-HEADER: The header bar spans the width of the game world column (75% of the screen width) and always shows the elapsed survival time, the current global building blocks stock, and the artifact count (REQ-WIN-ARTIFACT-COUNT) displayed as `Artifacts: x/y` (where `x` is the current artifact count and `y` is `world.toml [world].artifact_win_count`) on the left, the boss wave counter and boss countdown (REQ-UI-BOSS-STATUS) and an asteroid expansion button (REQ-UI-EXPAND-BUTTON) to the left of the speed buttons, and game speed controls on the right.
|
||||
- REQ-UI-BLOCKS-TOOLTIP: The header bar's building blocks stock display (REQ-UI-HEADER) shows a hover tooltip with the descriptive text defined in `world.toml [world].building_blocks_tooltip` — intended to tell the player what building blocks are used for and how to obtain them. If the field is unset, the stock display shows no tooltip. This tooltip is distinct from the build/module button tooltips (REQ-UI-BUILD-TOOLTIP, REQ-MOD-UI-MODULE-TOOLTIP).
|
||||
- REQ-UI-ARTIFACTS-TOOLTIP: The header bar's artifact count display (REQ-UI-HEADER) shows a hover tooltip with the descriptive text defined in `world.toml [world].artifact_tooltip` — intended to tell the player what artifacts are, how they are obtained (REQ-DEF-SCHEMATIC-DROP), and that collecting `world.toml [world].artifact_win_count` of them wins the game (REQ-WIN-ARTIFACT-COUNT). If the field is unset, the artifact count display shows no tooltip. This tooltip is distinct from the building blocks tooltip (REQ-UI-BLOCKS-TOOLTIP) and the build/module button tooltips (REQ-UI-BUILD-TOOLTIP, REQ-MOD-UI-MODULE-TOOLTIP).
|
||||
- REQ-UI-BOSS-STATUS: The header bar displays, to the left of the speed buttons, the current boss wave counter (REQ-WAV-BOSS-COUNTER) and the time remaining on the boss countdown (REQ-WAV-BOSS-COUNTDOWN). The boss wave counter is shown as `Boss Wave #<x>` and the countdown as `Next boss: <M:SS>`, where `<M:SS>` is the remaining seconds formatted as whole minutes and two-digit seconds. Both values update continuously as the simulation runs.
|
||||
- REQ-UI-SPEED: The game speed controls in the header bar are buttons for 0×, 0.5×, 1×, 2×, and 4× speed. The currently active speed is shown as selected. All game simulation (production, movement, threat accumulation, wave timing) scales with the selected speed. 0× pauses the game.
|
||||
- REQ-UI-SPEED: The game speed controls in the header bar are buttons for 0×, 0.5×, 1×, 2×, and 10× speed. The currently active speed is shown as selected. All game simulation (production, movement, threat accumulation, wave timing) scales with the selected speed. 0× pauses the game.
|
||||
- REQ-UI-PAUSE-BORDER: While the game is paused (speed 0×, whether set via the speed controls (REQ-UI-SPEED), the Space toggle (REQ-UI-HOTKEYS), or an auto-pausing modal), a vignette border is drawn around the edges of the game world view to make the paused state hard to miss. The border is black and fades in the alpha channel from fully transparent at its inner (center-facing) edge to 50% opacity at the viewport edge, over a thickness of 100 pixels (capped at half the smaller viewport dimension on very small views).
|
||||
- REQ-UI-DECONSTRUCT-BORDER: While deconstruct mode is active (REQ-UI-DECONSTRUCT-BUTTON, REQ-UI-HOTKEYS), a vignette border is drawn around the edges of the game world view to signal the mode, matching the geometry of the paused-state vignette (REQ-UI-PAUSE-BORDER): a 100-pixel thickness (capped at half the smaller viewport dimension on very small views) with the four sides meeting along mitred corner diagonals. It fades in the alpha channel from fully transparent at its inner (center-facing) edge to the deconstruct tint color at the viewport edge. The color — including its alpha, which sets the peak opacity at the viewport edge — is read from `visuals.toml [overlays].deconstruct_tint`, the same deconstruct-mode color used for the hover tint. The border is presentation-only and has no effect on the simulation. If the game is both paused and in deconstruct mode, both vignettes are drawn and compose over each other.
|
||||
- REQ-UI-EXPAND-BUTTON: The header bar shows an asteroid expansion button captioned `Expand: <x> Blocks`, where `<x>` is the current expansion cost computed from `world.toml [expansion].cost_building_blocks_formula` at the current number of purchased expansions (REQ-EXP-COST). Clicking the button unlocks the next asteroid expansion (REQ-EXP-UNLOCK, REQ-GW-ASTEROID-EXPAND), spending that many building blocks from the global stock. The button is disabled when the player cannot currently afford the cost (consistent with REQ-UI-BUILD-DISABLED). The caption updates as the cost changes with each purchased expansion.
|
||||
- REQ-UI-WORLD-SIZE: The game world view occupies the full height below the header bar in the main column (75% of the screen width).
|
||||
- REQ-UI-PANEL-COLUMN: The side panel column occupies 25% of the screen width and the full screen height. It is divided into three equal-height panels stacked top to bottom: selected building panel (top), build button grid (middle), and blueprint panel (bottom).
|
||||
@@ -442,19 +475,29 @@ The screen is divided into two columns: a main column (75% width) containing the
|
||||
Because the contest-zone boundaries shift as the scrollable area grows with each push (REQ-GW-PUSH-EXPAND, REQ-GW-SCROLL-LIMIT), the ramp bands are recomputed from the current contest-zone boundaries. This is a presentation-only concern and does not affect the simulation, consistent with REQ-UI-NO-ZOOM.
|
||||
- REQ-UI-CONSTRUCTION-PROGRESS: Construction sites display the building's glyph centered on the footprint (same as an operational building). Below the glyph — or centered on the footprint if the building has no glyph — a construction progress percentage is shown (integer, e.g. `42%`), increasing from 0% to 100% as construction completes.
|
||||
- REQ-UI-PORT-GLYPH: Every output port of every building is indicated by a directional glyph drawn on the port's tile. The glyph is a `>` rotated to face the port's exit direction (`>` for East, `^` for North, `<` for West, `v` for South). It is drawn at the midpoint between the tile center and the tile edge that the port exits through (i.e. halfway from center toward the exit edge). The indicator is rendered for all building states: operational buildings, construction sites, and the builder-mode ghost. Buildings with multiple output ports (e.g. splitters) show one indicator per port.
|
||||
- REQ-UI-PORT-TARGET-GLYPH: While in builder mode (REQ-BLD-BUILDER-MODE), the builder-mode ghost additionally shows, for each of the building's output ports, a directional glyph drawn centered in the port's **target cell** — the cell immediately outside the footprint that the port pushes into, i.e. the cell the surface-mask output-port indicator occupies (see Surface Mask Format). As in REQ-UI-PORT-GLYPH the glyph is a `>` rotated to face the port's exit direction (`>` East, `^` North, `<` West, `v` South), previewing where the port's output will go before placement. This is in addition to the on-tile port glyph of REQ-UI-PORT-GLYPH, and — unlike that indicator — is shown only for the builder-mode ghost, not for operational buildings, construction sites, or the blueprint-placement ghost (REQ-UI-BLUEPRINT-PLACE). A building with multiple output ports (e.g. a splitter) shows one target-cell glyph per port. The target-cell glyph is drawn larger than the on-tile port glyph so it stands out as the flow-direction preview. Exceptions: the Tunnel Entry shows no target-cell glyph, because it receives items (which may arrive from any of its non-mouth edges, REQ-BLD-TUNNEL-ENTRY) rather than emitting into a single adjacent cell; the Shipyard shows none either, because its output port is a ship-spawn point (REQ-SHP-SPAWN-PLAYER) rather than a belt-item output (REQ-MAT-OUTPUT-EMERGE).
|
||||
- REQ-UI-STATUS-LIGHT: Every operational production building — Miner, Smelter, Assembler, Reprocessing Plant, Shipyard, and Salvage Bay — renders a small **status light**: a filled circle with a black outline drawn in the building's upper-right corner, letting the player read a building's production state without selecting it. The light is anchored to the footprint corner that is the upper-right corner in the building's default orientation and rotates with the building — like the output-port glyph (REQ-UI-PORT-GLYPH) — so it stays on the same physical corner of the building as it is rotated. The status light is rendered only for operational buildings; construction sites (which instead show construction progress, REQ-UI-CONSTRUCTION-PROGRESS) and the builder-mode ghost do not render it. Buildings that are not production buildings — belts, splitters, tunnel entries/exits, and the HQ — have no status light. The black outline is constant; the fill color reflects the building's current production state.
|
||||
- For the five production buildings (Miner, Smelter, Assembler, Reprocessing Plant, Shipyard), the fill color is determined by evaluating, in order:
|
||||
- **Grey** — no recipe or schematic is selected. This applies only to buildings with a player-facing selection (Miner, Assembler, Shipyard); the Smelter and Reprocessing Plant always run an implicit recipe (REQ-BLD-SMELTER, REQ-BLD-REPROCESSING) and are never grey.
|
||||
- **Green** — the building is currently producing: a production cycle is active (REQ-MAT-CYCLE; for the Shipyard, an in-progress production cycle per REQ-BLD-SHIPYARD).
|
||||
- **Red** — the building is idle because a required input is missing from its input buffers, so it cannot start a cycle. Missing input takes precedence over a full output buffer: if any required input is missing the light is red even when the output buffer is also full.
|
||||
- **Yellow** — the building is idle with all required inputs present but its output buffer full, so no new cycle can start (REQ-MAT-OUTPUT-BUFFER, REQ-MAT-CYCLE).
|
||||
- A configured building that is momentarily idle yet blocked by neither condition (all inputs present and the output buffer has room — a transient state that resolves into a started cycle on the same or the next tick per REQ-MAT-CYCLE) shows green.
|
||||
- The Salvage Bay has no recipe and no production cycle (REQ-BLD-SALVAGE-BAY); its status light uses only two states: **green** while its output buffer holds at least one unit of scrap, and **red** while its output buffer is empty. The Salvage Bay's status light is never grey or yellow.
|
||||
- The four fill colors (grey, green, red, yellow) and the outline color are read from `visuals.toml [status_light]`, consistent with the other rendering-only colors. The status light is presentation-only and has no effect on the simulation.
|
||||
- REQ-UI-HP-BARS: All entities with HP — the HQ, player and enemy defence stations, and player and enemy ships — render an HP bar below them. The bar is always visible regardless of current HP. The bar's filled portion represents the fraction of current HP to maximum HP.
|
||||
- REQ-UI-NO-ZOOM: The view has a fixed zoom level; the player cannot zoom in or out.
|
||||
- REQ-UI-HOTKEYS: Global keyboard shortcuts:
|
||||
- **Space** — toggles pause. Pressing Space pauses (sets speed to 0×) and stores the previously selected non-zero speed; pressing Space again restores that speed.
|
||||
- **W** — increases game speed by one step in the sequence 0×, 0.5×, 1×, 2×, 4× (no wrap-around past 4×).
|
||||
- **W** — increases game speed by one step in the sequence 0×, 0.5×, 1×, 2×, 10× (no wrap-around past 10×).
|
||||
- **S** — decreases game speed by one step in the same sequence (no wrap-around past 0×).
|
||||
- **A / D** — scroll the view left / right (REQ-UI-SCROLL).
|
||||
- **Q** — context-sensitive. If a build mode is active (builder mode or blueprint placement mode), pressing Q exits it. Otherwise, pressing Q toggles demolish mode: it enters demolish mode if inactive, or exits demolish mode if already active. (See also REQ-UI-DEMOLISH-BUTTON for the equivalent button.)
|
||||
- **Q** — context-sensitive. If a build mode is active (builder mode or blueprint placement mode), pressing Q exits it. Otherwise, pressing Q toggles deconstruct mode: it enters deconstruct mode if inactive, or exits deconstruct mode if already active. (See also REQ-UI-DECONSTRUCT-BUTTON for the equivalent button.)
|
||||
- **R / Shift+R** — in builder mode, rotate the ghost counter-clockwise / clockwise (REQ-BLD-ROTATE).
|
||||
- **T** — create a temporary blueprint from the current selection and enter its placement mode (REQ-UI-BLUEPRINT-TEMP).
|
||||
- **Escape** — opens the escape menu (REQ-UI-GAME-MENU).
|
||||
- **Build mode selection** — pressing a build hotkey activates builder mode for the corresponding building type, equivalent to clicking its build button (REQ-BLD-BUILDER-MODE):
|
||||
- **1** — Belt, **2** — Splitter, **3** — Tunnel Entry, **4** — Tunnel Exit.
|
||||
- **1** — Belt, **2** — Splitter, **3** — Tunnel (the unified tunnel build mode, REQ-BLD-TUNNEL-MODE). Hotkey 4 is unused.
|
||||
- **Shift+1** — Miner, **Shift+2** — Smelter, **Shift+3** — Assembler, **Shift+4** — Shipyard, **Shift+5** — Salvage Bay, **Shift+6** — Reprocessing Plant.
|
||||
|
||||
### Debug Draw
|
||||
@@ -479,9 +522,10 @@ The screen is divided into two columns: a main column (75% width) containing the
|
||||
### Selected Building Panel
|
||||
|
||||
- REQ-UI-EMPTY-SELECTION: When nothing is selected (no building, construction site, ship, defence station, or scrap pile), the panel is empty.
|
||||
- REQ-UI-SELECTION-CATEGORIES: **Selection categories and precedence.** Every selectable object belongs to one of two mutually exclusive selection categories: **buildings** (buildings and construction sites) and **field objects** (ships and defence stations — player or enemy — together with scrap piles). A single selection holds objects from only one category at a time. Field objects of different kinds may be selected together (e.g. several ships plus scrap piles, freely mixing player and enemy actors). Buildings are exclusive and take precedence — **buildings win**: selecting a building (by click, Ctrl+click, or a box-drag covering at least one building) clears any field selection and yields a buildings-only selection, and conversely selecting any field object clears any building selection. Point hit-testing prefers a building over a coincident field object, and among field objects prefers an actor (ship or defence station) over a coincident scrap pile (REQ-UI-ENTITY-CLICK-SELECT, REQ-UI-SCRAP-CLICK-SELECT).
|
||||
- REQ-UI-SINGLE-SELECTION: When one building is selected, the panel shows: building name, current recipe or schematic selection, input buffer contents, and output buffer contents. Buffer counts are displayed as `a/b` where `a` is the current item count and `b` is the per-cycle amount (items consumed per run for inputs; items produced per run for outputs). For a selected construction site, the recipe/schematic selection (and, for a shipyard, the layout preview and "Configure" button) are shown but the buffer rows are omitted (REQ-BLD-SITE-CONFIG).
|
||||
- REQ-UI-PRODUCTION-PROGRESS: For buildings that produce items or ships (miner, smelter, assembler, reprocessing plant, shipyard), the selected building panel also shows: (a) the cycle time of the currently selected recipe or schematic in seconds, and (b) the completion percentage of the active production cycle as an integer (e.g. `42%`), or the text `idle` when no production cycle is active. When no recipe or schematic is selected, neither the cycle time nor the progress indicator is shown.
|
||||
- REQ-UI-MULTI-SELECT: The player selects multiple buildings by box-drag or by Ctrl+clicking individual buildings to add or remove them from the selection. A box-drag that covers at least one building selects buildings (any scrap piles within the box are ignored); a box-drag that covers no buildings but does cover scrap piles selects those scrap piles instead (REQ-UI-SCRAP-MULTI-SELECT).
|
||||
- REQ-UI-MULTI-SELECT: The player selects multiple objects by box-drag or by Ctrl+clicking individual objects to add or remove them from the selection. Multi-select operates within a single category (REQ-UI-SELECTION-CATEGORIES). A box-drag that covers at least one building selects buildings (any field objects within the box are ignored — buildings win); a box-drag that covers no building but does cover ships, defence stations, or scrap piles selects all of those field objects together (REQ-UI-ENTITY-CLICK-SELECT, REQ-UI-SCRAP-MULTI-SELECT).
|
||||
- REQ-UI-MULTI-SELECTION: When multiple buildings are selected, the panel shows how many of each building type are selected. No per-building detail is shown. The panel additionally shows the **total building block cost** of the selection — the sum of each selected building's placement cost (`buildings.toml [[building]].cost`, per REQ-BLD-COST), counting only player-placeable buildings (buildings with a button in the build button grid); non-player-placeable buildings (the HQ and defence stations) are excluded from the total, consistent with the blueprint total (REQ-UI-BLUEPRINT-BUTTON). Construction sites count at their building type's full placement cost regardless of construction progress.
|
||||
- REQ-UI-CONFIG-INLINE: Recipe and schematic configuration for a selected building is shown within this panel. Recipe selection (miner, assembler) and schematic selection (shipyard) use the selection button and dialog (REQ-UI-SELECT-BUTTON) rather than an inline control. For shipyards, the panel additionally shows the ship layout preview and "Configure" button below the schematic selection button (REQ-MOD-UI-PREVIEW).
|
||||
- REQ-UI-SELECT-BUTTON: **Recipe and schematic selection control.** Recipe selection (Miner ore type, Assembler recipe) and schematic selection (Shipyard) are each presented in the selected building panel as a single **selection button** whose caption is the name of the currently selected recipe or schematic, or a placeholder ("Select recipe" / "Select schematic") when none is selected. Clicking the button opens a modal **selection dialog** that pauses the game (speed set to 0×; on close, the speed is restored to what it was before the dialog was opened). The dialog contains a grid of option buttons, one per selectable option — only options that are currently unlocked are shown (REQ-LOCK-UI-RECIPE for recipes, REQ-LOCK-UI-SCHEMATIC for schematics). Hovering an option button shows the selection info tooltip (REQ-UI-SELECT-TOOLTIP). Clicking an option button selects that recipe/schematic, closes the dialog, and updates the selection button's caption in the selected building panel. The dialog can be dismissed without changing the current selection (e.g. closing it without clicking an option). Selecting a new recipe or schematic has the same effects as before (REQ-MAT-INPUT-BUFFER, REQ-MAT-OUTPUT-BUFFER, REQ-BLD-SHIPYARD).
|
||||
@@ -489,8 +533,8 @@ The screen is divided into two columns: a main column (75% width) containing the
|
||||
- For a **recipe** (Miner or Assembler): the recipe name; the name and quantity of each input item (no inputs are listed for miner recipes, which consume nothing); the completion time (`duration_seconds`); and the name and quantity of the produced output item.
|
||||
- For a **ship schematic** (Shipyard): the ship's `display_name`; the name and quantity of each base required material (`[ship.schematic].materials`, excluding any module contributions); the base production time (`[ship.schematic].production_time_seconds`); and "Produces: 1 <ship display name>".
|
||||
- REQ-UI-BELT-CLEAR: When one or more belt, splitter, tunnel entry, or tunnel exit tiles are selected, the panel shows a "Clear" button that removes all items from the selected tiles. Clearing a tunnel entry or exit also discards all items currently in transit through that tunnel (REQ-BLD-TUNNEL-TRANSIT). This can be used to resolve stalled belts, splitters, and tunnels.
|
||||
- REQ-UI-ENTITY-CLICK-SELECT: The player can click any ship (player or enemy) or any defence station (player or enemy) in the game world to select it. Clicking a ship or defence station clears any existing selection and establishes a single-entity selection containing only that entity. Ships and defence stations cannot participate in multi-select together with buildings. Clicking a scrap pile instead establishes a scrap selection (REQ-UI-SCRAP-CLICK-SELECT). Clicking empty world space (no building, ship, defence station, or scrap pile) clears the selection.
|
||||
- REQ-UI-SHIP-STATS-PANEL: When a single ship is selected (REQ-UI-ENTITY-CLICK-SELECT), the selected building panel shows a **ship stats panel**. The panel structure mirrors REQ-MOD-UI-STATS-PANEL but reflects the ship's actual live state: stats are computed from its installed modules per REQ-MOD-STAT-CALC. The panel always shows all hull stats: HP (current / maximum), max linear speed, sensor range, main acceleration, maneuvering acceleration, angular acceleration, and max rotation speed. In addition, capability module summaries are shown conditioned on which module types are installed, using the same aggregation rules as REQ-MOD-UI-STATS-PANEL: weapons (combined DPS, maximum range), salvage (combined collection rate, maximum range), and repair (combined repair rate, maximum range), each section appearing only if at least one instance of that module type is installed. While debug draw mode is active (REQ-UI-DEBUG-DRAW), the panel additionally shows the ship's derived threat cost (REQ-MOD-THREAT).
|
||||
- REQ-UI-ENTITY-CLICK-SELECT: The player can click any ship (player or enemy) or any defence station (player or enemy) in the game world to select it. A plain click on a ship or defence station makes it the sole selection, clearing any previous selection. Ships and defence stations can be multi-selected — by Ctrl+clicking individual actors to add or remove them, or by box-drag (REQ-UI-MULTI-SELECT) — and can be selected together with scrap piles and with one another in a single field selection (REQ-UI-SELECTION-CATEGORIES), freely mixing player and enemy actors. Actors cannot be selected together with buildings: selecting a ship or defence station clears any building selection, and selecting a building clears the actors (buildings win). Clicking a scrap pile adds to or establishes a field selection (REQ-UI-SCRAP-CLICK-SELECT). Clicking empty world space (no building, ship, defence station, or scrap pile) clears the selection.
|
||||
- REQ-UI-SHIP-STATS-PANEL: When exactly one ship is selected (REQ-UI-ENTITY-CLICK-SELECT) and no scrap is selected, the selected building panel shows a **ship stats panel**. (If scrap is also selected, the panel shows the compact count summary instead, per REQ-UI-FIELD-MULTI-SELECTION.) The panel structure mirrors REQ-MOD-UI-STATS-PANEL but reflects the ship's actual live state: stats are computed from its installed modules per REQ-MOD-STAT-CALC. The panel always shows all hull stats: HP (current / maximum), max linear speed, sensor range, main acceleration, maneuvering acceleration, angular acceleration, and max rotation speed. In addition, capability module summaries are shown conditioned on which module types are installed, using the same aggregation rules as REQ-MOD-UI-STATS-PANEL: weapons (combined DPS, maximum range), salvage (combined collection rate, maximum range), and repair (combined repair rate, maximum range), each section appearing only if at least one instance of that module type is installed. While debug draw mode is active (REQ-UI-DEBUG-DRAW), the panel additionally shows the ship's derived threat cost (REQ-MOD-THREAT).
|
||||
- REQ-UI-SHIP-BEHAVIOR: The ship stats panel (REQ-UI-SHIP-STATS-PANEL) additionally displays the selected ship's **current behavior** — a single label naming the top-priority behavior currently governing the ship's navigation, as resolved by the fixed-priority behavior arbitration. Only the winning behavior is named; lower-priority behaviors that are suppressed are not shown, and neither are the salvage/repair cycles that run regardless of the active behavior (REQ-SHP-SALVAGE, REQ-SHP-REPAIR). The label updates live as the ship's behavior changes, and it is always shown (independent of debug draw mode, unlike the threat-cost line of REQ-UI-SHIP-STATS-PANEL). This applies to both player and enemy ships (REQ-UI-ENTITY-CLICK-SELECT); enemy ships only ever show **Engaging** or **Advancing**. The behavior labels (all wrapped in `tr()`) are:
|
||||
- **Retreating** — the ship is retreating (REQ-SHP-RETREAT).
|
||||
- **Engaging** — the ship is engaging a combat target (player: REQ-SHP-COMBAT; enemy: REQ-SHP-ENEMY-AI).
|
||||
@@ -499,18 +543,19 @@ The screen is divided into two columns: a main column (75% width) containing the
|
||||
- **Rallying** — the ship is moving to or orbiting the rally point (REQ-SHP-RALLY).
|
||||
- **Standby** — the ship is holding with its fleet (REQ-SHP-STANDBY).
|
||||
- **Advancing** — the ship is executing the baseline forward advance with no higher-priority behavior active (player: REQ-SHP-COMBAT advance toward the enemy; enemy: REQ-SHP-ENEMY-AI advance toward the asteroid).
|
||||
- REQ-UI-STATION-STATS-PANEL: When a single defence station is selected (REQ-UI-ENTITY-CLICK-SELECT), the selected building panel shows a **station stats panel** displaying the station's stats computed at its current level: HP (current / maximum), damage, range, and fire rate.
|
||||
- REQ-UI-SCRAP-CLICK-SELECT: The player can click any scrap pile (REQ-RES-SCRAP-DROP) in the game world to select it. Scrap forms its own selection category: clicking a scrap pile clears any existing selection and establishes a scrap selection containing only that pile. Scrap piles cannot participate in a selection together with buildings, ships, or defence stations. Hit-testing prioritizes actors over scrap: when a building, ship, or defence station lies under the cursor at the same point as a scrap pile, that object is selected in preference to the scrap; a scrap pile is selected only when no building, ship, or defence station is under the cursor. A selected scrap pile that despawns or is fully collected (REQ-RES-SCRAP-DROP) is removed from the selection; once the last selected pile is gone, the selection becomes empty (REQ-UI-EMPTY-SELECTION).
|
||||
- REQ-UI-SCRAP-MULTI-SELECT: Multiple scrap piles can be selected by box-drag or by Ctrl+clicking individual piles to add or remove them from the selection, mirroring building multi-select (REQ-UI-MULTI-SELECT). A scrap selection contains only scrap piles. Because scrap cannot mix with other object types (REQ-UI-SCRAP-CLICK-SELECT), Ctrl+clicking a scrap pile while a building, ship, or defence station selection is active first clears that selection and begins a scrap selection; conversely, selecting a building, ship, or defence station while a scrap selection is active clears the scrap selection. Box-drag disambiguation between buildings and scrap follows REQ-UI-MULTI-SELECT (a box covering any building selects buildings; a box covering scrap but no buildings selects the scrap).
|
||||
- REQ-UI-SCRAP-PANEL: When one or more scrap piles are selected, the selected building panel shows the **total remaining scrap amount** across all selected piles — the sum of the piles' current remaining amounts (REQ-RES-SCRAP-DROP), e.g. "Scrap: 47". The same summed-amount display is used whether one pile or many are selected; no per-pile detail and no pile count are shown. The displayed total updates as selected piles are partially collected or despawn (REQ-UI-SCRAP-CLICK-SELECT).
|
||||
- REQ-UI-STATION-STATS-PANEL: When exactly one defence station is selected (REQ-UI-ENTITY-CLICK-SELECT) and no scrap is selected, the selected building panel shows a **station stats panel** displaying the station's stats computed at its current level: HP (current / maximum), damage, range, and fire rate. (If scrap is also selected, the panel shows the compact count summary instead, per REQ-UI-FIELD-MULTI-SELECTION.)
|
||||
- REQ-UI-FIELD-MULTI-SELECTION: The full single-actor stats panel (REQ-UI-SHIP-STATS-PANEL, REQ-UI-STATION-STATS-PANEL) is shown only when the field selection holds exactly one actor and no scrap. Whenever the selection holds more than one object — multiple actors, or a single actor together with scrap — the panel shows a **compact summary** instead: a count per actor type, one line per type rendered as "<type> x <count>" (the same `x`-count notation as the recipe tooltip and the building multi-selection, REQ-UI-MULTI-SELECTION). Ships are grouped by schematic display name and defence stations as a group, distinguishing player from enemy. No per-actor detail and no total-actor-count header are shown (consistent with the building panel). If scrap piles are also part of the field selection (REQ-UI-SELECTION-CATEGORIES) their total is appended as a final line of the same summary (REQ-UI-SCRAP-PANEL), so all lines share uniform spacing. Building selections use REQ-UI-SINGLE-SELECTION / REQ-UI-MULTI-SELECTION instead.
|
||||
- REQ-UI-SCRAP-CLICK-SELECT: The player can click any scrap pile (REQ-RES-SCRAP-DROP) in the game world to select it. Scrap piles are field objects (REQ-UI-SELECTION-CATEGORIES) and can be selected together with ships and defence stations, but not with buildings. A plain click on a scrap pile makes it the sole selection, clearing any previous selection; selecting a building clears any scrap (buildings win), and selecting a scrap pile clears any building selection. Hit-testing prefers a building over a coincident actor or scrap pile, and an actor (ship or defence station) over a coincident scrap pile: a scrap pile is selected only when no building or actor is under the cursor. A selected scrap pile that despawns or is fully collected (REQ-RES-SCRAP-DROP) is removed from the selection; if no selected object remains, the panel becomes empty (REQ-UI-EMPTY-SELECTION).
|
||||
- REQ-UI-SCRAP-MULTI-SELECT: Multiple scrap piles can be selected by box-drag or by Ctrl+clicking individual piles to add or remove them, mirroring building multi-select (REQ-UI-MULTI-SELECT). Scrap shares the field-object category with ships and defence stations (REQ-UI-SELECTION-CATEGORIES), so a field selection may hold scrap piles and actors together. Ctrl+clicking a scrap pile while a field selection is active adds or removes that pile within the same selection; Ctrl+clicking a scrap pile while a building selection is active first clears the buildings and begins a field selection (buildings win). Conversely, selecting a building while a field selection is active clears it. Box-drag disambiguation follows REQ-UI-MULTI-SELECT (a box covering any building selects buildings; a box covering no building selects the ships, defence stations, and scrap piles within it).
|
||||
- REQ-UI-SCRAP-PANEL: When one or more scrap piles are selected, the selected building panel shows the **total remaining scrap amount** across all selected piles — the sum of the piles' current remaining amounts (REQ-RES-SCRAP-DROP), e.g. "Scrap x 47". The same summed-amount display is used whether one pile or many are selected; no per-pile detail and no pile count are shown. The displayed total updates as selected piles are partially collected or despawn (REQ-UI-SCRAP-CLICK-SELECT). When actors are also selected, this scrap total is shown as an additional line of the actor count summary rather than alongside a single-actor stats panel (REQ-UI-FIELD-MULTI-SELECTION).
|
||||
|
||||
### Build Button Grid
|
||||
|
||||
- REQ-UI-BUILD-GRID: All placeable building types are shown as a flat grid of buttons with no grouping.
|
||||
- REQ-UI-BUILD-GRID: All placeable building types are shown as a flat grid of buttons with no grouping. Tunnel Entry and Tunnel Exit share a single **Tunnel** button (REQ-BLD-TUNNEL-MODE) rather than one button each.
|
||||
- REQ-UI-BUILD-COST: Each button caption shows the building name and its building block cost, e.g. "Belt: 2 Blocks".
|
||||
- REQ-UI-BUILD-TOOLTIP: Each building-type button shows a hover tooltip with the descriptive text defined for that building type in `buildings.toml` (the optional per-building tooltip field). This tooltip is distinct from the recipe/schematic selection tooltip (REQ-UI-SELECT-TOOLTIP). If a building type defines no tooltip text, its button shows no tooltip. The Demolish button (REQ-UI-DEMOLISH-BUTTON) is not a building type and has no config-defined tooltip.
|
||||
- REQ-UI-BUILD-TOOLTIP: Each building-type button shows a hover tooltip with the descriptive text defined for that building type in `buildings.toml` (the optional per-building tooltip field). This tooltip is distinct from the recipe/schematic selection tooltip (REQ-UI-SELECT-TOOLTIP). If a building type defines no tooltip text, its button shows no tooltip. The Deconstruct button (REQ-UI-DECONSTRUCT-BUTTON) is not a building type and has no config-defined tooltip.
|
||||
- REQ-UI-BUILD-DISABLED: Buttons for buildings the player cannot currently afford are shown as disabled.
|
||||
- REQ-UI-DEMOLISH-BUTTON: A dedicated **Demolish** button is shown in the build button grid. Clicking it toggles demolish mode on and off, equivalent to the Q demolish toggle (REQ-UI-HOTKEYS). The button is shown in a visually active/pressed state while demolish mode is active.
|
||||
- REQ-UI-DECONSTRUCT-BUTTON: A dedicated **Deconstruct** button is shown in the build button grid. Clicking it toggles deconstruct mode on and off, equivalent to the Q deconstruct toggle (REQ-UI-HOTKEYS). The button is shown in a visually active/pressed state while deconstruct mode is active.
|
||||
|
||||
### Blueprint Panel
|
||||
|
||||
@@ -518,15 +563,15 @@ The screen is divided into two columns: a main column (75% width) containing the
|
||||
|
||||
- REQ-UI-BLUEPRINT-CREATE: The "Create Blueprint" button is enabled only when at least one player-placeable building (i.e. a building with a button in the build button grid) is currently selected; non-player-placeable buildings (HQ, defence stations) in the selection do not count toward this condition. A selected player-placeable building may be either an operational building or a construction site (a building placed but not yet fully built, REQ-BLD-SITE-CONFIG); both count toward this condition and are captured identically (REQ-UI-BLUEPRINT-STORAGE). When clicked, a modal dialog appears prompting the player to enter a name. The dialog has Confirm and Cancel buttons. Clicking Cancel closes the dialog with no effect. Clicking Confirm with a non-empty name creates a blueprint from the current selection, silently excluding any non-player-placeable buildings, and appends its button to the blueprint list.
|
||||
|
||||
- REQ-UI-BLUEPRINT-TEMP: Pressing the **T** key (REQ-UI-HOTKEYS) creates a **temporary blueprint** from the current selection and immediately enters blueprint placement mode for it, without opening the naming dialog. It has effect only when at least one player-placeable building is currently selected — the same condition as REQ-UI-BLUEPRINT-CREATE; pressing T with an empty selection, or a selection containing only non-player-placeable buildings (HQ, defence stations), does nothing. Entering this mode replaces any currently active build, blueprint placement, or demolish mode. The temporary blueprint is captured exactly as a saved blueprint (REQ-UI-BLUEPRINT-STORAGE), silently excluding any non-player-placeable buildings from the selection, but it is never named, never shown in the blueprint panel (REQ-UI-BLUEPRINT-PANEL), and never persisted to `blueprints.toml` (REQ-UI-BLUEPRINT-SAVE). Placement behaves identically to a saved blueprint's placement mode (REQ-UI-BLUEPRINT-MODE, REQ-UI-BLUEPRINT-PLACE): a ghost is rendered per building, R / Shift+R rotate the entire constellation, placement follows the same per-building validity and total-cost rules, and after a successful placement the mode stays active so the blueprint can be placed again. Right-clicking in the game world exits placement mode, at which point the temporary blueprint is discarded.
|
||||
- REQ-UI-BLUEPRINT-TEMP: Pressing the **T** key (REQ-UI-HOTKEYS) creates a **temporary blueprint** from the current selection and immediately enters blueprint placement mode for it, without opening the naming dialog. It has effect only when at least one player-placeable building is currently selected — the same condition as REQ-UI-BLUEPRINT-CREATE; pressing T with an empty selection, or a selection containing only non-player-placeable buildings (HQ, defence stations), does nothing. Entering this mode replaces any currently active build, blueprint placement, or deconstruct mode. The temporary blueprint is captured exactly as a saved blueprint (REQ-UI-BLUEPRINT-STORAGE), silently excluding any non-player-placeable buildings from the selection, but it is never named, never shown in the blueprint panel (REQ-UI-BLUEPRINT-PANEL), and never persisted to `blueprints.toml` (REQ-UI-BLUEPRINT-SAVE). Placement behaves identically to a saved blueprint's placement mode (REQ-UI-BLUEPRINT-MODE, REQ-UI-BLUEPRINT-PLACE): a ghost is rendered per building, R / Shift+R rotate the entire constellation, placement follows the same per-building validity and total-cost rules, and after a successful placement the mode stays active so the blueprint can be placed again. Right-clicking in the game world exits placement mode, at which point the temporary blueprint is discarded.
|
||||
|
||||
- REQ-UI-BLUEPRINT-STORAGE: A blueprint stores its name and, for each building in the selection, the building type, its rotation, its tile offset (integer dx, dy) from the center of the bounding box of all selected buildings' footprints, and — where applicable — the selected recipe ID (miners and assemblers) or schematic ID (shipyards), and for splitters the two output filters (each a list of item types; an empty list means accept-all), at the time of capture. A source building may be either an operational building or a construction site (REQ-BLD-SITE-CONFIG); a construction site is captured identically, storing whatever configuration it currently holds and never any buffer or construction-progress state. If no recipe or schematic was selected at capture time, none is stored; for a splitter with no filters set, no filter lists are stored. This structure maps directly to a TOML representation (e.g. one `[[building]]` array entry per constituent building, with the splitter filters as `filter_a`/`filter_b` arrays of item-type ids).
|
||||
|
||||
- REQ-UI-BLUEPRINT-BUTTON: Each blueprint entry consists of a blueprint button and a dedicated delete icon ("×") placed to the right of the button. The blueprint button displays the blueprint name and, below it, the total building block cost of the blueprint (sum of the individual costs of all constituent buildings). A blueprint button is disabled when the player cannot afford the total cost. Clicking an enabled blueprint button enters blueprint placement mode for that blueprint. The delete icon is always enabled regardless of whether the player can afford the blueprint.
|
||||
|
||||
- REQ-UI-BLUEPRINT-MODE: In blueprint placement mode a ghost is rendered for every building in the blueprint at the position determined by its stored tile offset from the bounding-box center, which is anchored to the tile under the cursor. Each ghost is rendered individually as valid or invalid, applying REQ-BLD-PLACE-VALID conditions (a) and (b) per building (the other ghosts in the same blueprint do not count as existing buildings for the overlap check). A valid ghost uses its building type's semi-transparent per-building coloring (REQ-BLD-GHOST); an invalid ghost uses the distinct "invalid" color, as in single-building builder mode. Pressing R / Shift+R rotates the entire constellation 90° counter-clockwise / clockwise: each building's tile offset is rotated around the bounding-box center and each building's own rotation is updated, consistent with REQ-BLD-ROTATE. Blueprint placement mode is exited by right-clicking in the game world. Clicking a different blueprint button exits the current mode and enters blueprint placement mode for the newly clicked blueprint.
|
||||
- REQ-UI-BLUEPRINT-MODE: In blueprint placement mode a ghost is rendered for every building in the blueprint (excluding any of a currently locked building type, REQ-LOCK-BUILDING, which is omitted entirely per REQ-LOCK-UI-BLUEPRINT) at the position determined by its stored tile offset from the bounding-box center, which is anchored to the tile under the cursor. Each ghost is rendered individually as valid or invalid, applying REQ-BLD-PLACE-VALID conditions (a) and (b) per building (the other ghosts in the same blueprint do not count as existing buildings for the overlap check). A valid ghost uses its building type's semi-transparent per-building coloring (REQ-BLD-GHOST); an invalid ghost uses the distinct "invalid" color, as in single-building builder mode. Pressing R / Shift+R rotates the entire constellation 90° counter-clockwise / clockwise: each building's tile offset is rotated around the bounding-box center and each building's own rotation is updated, consistent with REQ-BLD-ROTATE. Blueprint placement mode is exited by right-clicking in the game world. Clicking a different blueprint button exits the current mode and enters blueprint placement mode for the newly clicked blueprint.
|
||||
|
||||
- REQ-UI-BLUEPRINT-PLACE: Left-clicking in blueprint placement mode places the blueprint if (a) every building in the constellation satisfies REQ-BLD-PLACE-VALID conditions (a) and (b) at its resolved tile, and (b) the player has enough building blocks to afford the total cost. If both conditions are met, a construction site is added to the build queue for each building in the blueprint and the full total cost is deducted from the global building blocks stock in one transaction. If a recipe ID is stored for a building, it is applied to the construction site immediately. If a schematic ID is stored, it is applied only if that schematic is currently unlocked; if it is not unlocked, the shipyard's schematic is left unset. If splitter output filters are stored, they are applied to the construction site immediately and carry over when it finishes building (REQ-BLD-SITE-CONFIG). Locked recipe IDs and splitter filter entries for locked item types are handled on placement per REQ-LOCK-UI-BLUEPRINT. After a successful placement the game remains in blueprint placement mode, allowing the player to place the same blueprint again immediately.
|
||||
- REQ-UI-BLUEPRINT-PLACE: Buildings of a currently locked building type (REQ-LOCK-BUILDING) are first excluded from the blueprint for this placement, per REQ-LOCK-UI-BLUEPRINT — they are not ghosted, not validity-checked, not placed, and their cost is excluded from the total. Left-clicking in blueprint placement mode then places the (remaining) blueprint if (a) every building in the constellation satisfies REQ-BLD-PLACE-VALID conditions (a) and (b) at its resolved tile, and (b) the player has enough building blocks to afford the total cost. If both conditions are met, a construction site is added to the build queue for each building in the blueprint and the full total cost is deducted from the global building blocks stock in one transaction. If a recipe ID is stored for a building, it is applied to the construction site immediately. If a schematic ID is stored, it is applied only if that schematic is currently unlocked; if it is not unlocked, the shipyard's schematic is left unset. If splitter output filters are stored, they are applied to the construction site immediately and carry over when it finishes building (REQ-BLD-SITE-CONFIG). Locked recipe IDs and splitter filter entries for locked item types are handled on placement per REQ-LOCK-UI-BLUEPRINT. After a successful placement the game remains in blueprint placement mode, allowing the player to place the same blueprint again immediately.
|
||||
|
||||
- REQ-UI-BLUEPRINT-DELETE: Clicking the delete icon ("×") on a blueprint entry immediately removes that blueprint from the list. If the deleted blueprint was active in blueprint placement mode, that mode is exited.
|
||||
|
||||
@@ -560,7 +605,7 @@ A separate executable target (`balancing`) that links against `lib` but contains
|
||||
|
||||
- REQ-BAL-SIM-ENV: Each arena simulates a pure-space environment using the same tick-based simulation as the main game. There is no asteroid, no buildings, no belts, no wave system, and no threat accumulation. Only ships, HQs, defence stations, and combat are active.
|
||||
- REQ-BAL-SIM-AI: Ships use the same AI and stats as in the main game. Ships with no target in sensor range advance toward the enemy team's HQ. Ships that detect an enemy in sensor range engage it as in the normal game (REQ-SHP-COMBAT, REQ-SHP-ENEMY-AI).
|
||||
- REQ-BAL-SIM-SPEED: Each arena that is not being inspected runs its simulation at maximum tick rate (as many ticks per second as the hardware allows), with no rendering. An inspected arena runs at a player-controllable game speed (same speed steps as the main game: 0×, 0.5×, 1×, 2×, 4×) with full rendering in the inspect window, defaulting to 1× on open.
|
||||
- REQ-BAL-SIM-SPEED: Each arena that is not being inspected runs its simulation at maximum tick rate (as many ticks per second as the hardware allows), with no rendering. An inspected arena runs at a player-controllable game speed (same speed steps as the main game: 0×, 0.5×, 1×, 2×, 10×) with full rendering in the inspect window, defaulting to 1× on open.
|
||||
- REQ-BAL-SIM-PARALLEL: All arenas are simulated in parallel, each on its own thread.
|
||||
- REQ-BAL-SIM-END: An arena fight ends when either team's HQ is destroyed or all ships and defence stations of one team have been destroyed. If a team has no defence stations, destroying all its ships is sufficient. When the fight ends, the simulation for that arena stops.
|
||||
|
||||
@@ -577,6 +622,6 @@ A separate executable target (`balancing`) that links against `lib` but contains
|
||||
- REQ-BAL-UI-WIDGET-START: Each arena widget contains a "Start" button that starts the simulation for that arena. The button is disabled while the arena's simulation is running. When a finished arena's Start button is clicked, a fresh simulation is created and started (the widget resets to initial unit counts, the border returns to blue, and the previous results are replaced).
|
||||
- REQ-BAL-UI-WIDGET-BORDER: Each arena widget has a colored border indicating its state: grey when not yet started, blue while its simulation is running, and green when the fight has ended.
|
||||
- REQ-BAL-UI-INSPECT: Clicking an arena widget's "Inspect" button opens a new inspect window for that arena. Any previously open inspect window is closed first (its arena's simulation is aborted and its widget border returns to grey). The inspected arena is restarted with a fresh simulation that runs at controllable game speed with full rendering (REQ-BAL-SIM-SPEED). The arena widget updates live during inspection (surviving counts, border color, `[WON]` prefix) as it does for non-inspected arenas. Only one inspect window may be open at a time.
|
||||
- REQ-BAL-UI-INSPECT-WINDOW: The inspect window consists of three sections, top to bottom: a title bar area containing the arena name and game speed controls (same buttons as the main game: 0×, 0.5×, 1×, 2×, 4×, with Space to toggle pause — see REQ-UI-SPEED and REQ-UI-HOTKEYS), the arena view in the center, and an info panel at the bottom displaying the same team columns and entry format as the arena widget in the main window (REQ-BAL-UI-WIDGET), updated live, including the arena's battle duration once the fight has ended (REQ-BAL-UI-WIDGET).
|
||||
- REQ-BAL-UI-INSPECT-WINDOW: The inspect window consists of three sections, top to bottom: a title bar area containing the arena name and game speed controls (same buttons as the main game: 0×, 0.5×, 1×, 2×, 10×, with Space to toggle pause — see REQ-UI-SPEED and REQ-UI-HOTKEYS), the arena view in the center, and an info panel at the bottom displaying the same team columns and entry format as the arena widget in the main window (REQ-BAL-UI-WIDGET), updated live, including the arena's battle duration once the fight has ended (REQ-BAL-UI-WIDGET).
|
||||
- REQ-BAL-UI-INSPECT-VIEW: The arena view renders all tiles of the arena and displays ships, HQs, defence stations, and laser beams using the same visual elements and `visuals.toml` colors as the main game. Team 1 uses player visual styles; team 2 uses enemy visual styles. The view has a fixed zoom level — no zoom or scroll is possible. The tile size is derived so that the full arena (all tiles) fits within the view.
|
||||
- REQ-BAL-UI-INSPECT-CLOSE: Closing the inspect window (via the window's close button) aborts the inspected arena's simulation. The arena widget's border returns to grey and its surviving counts are left as they were at the moment of closing. All main window buttons and controls are re-enabled.
|
||||
|
||||
@@ -117,6 +117,7 @@ target_link_libraries(${TARGET_UI_NAME}
|
||||
Qt5::Network
|
||||
Qt5::Multimedia
|
||||
Qt5::Charts
|
||||
Qt5::Svg
|
||||
)
|
||||
target_compile_definitions(${TARGET_UI_NAME} PRIVATE TOML_FLOAT_CHARCONV=0)
|
||||
|
||||
|
||||
@@ -44,7 +44,6 @@ ArenaSimulation::ArenaSimulation(const GameConfig& gameConfig,
|
||||
, m_team1HqEntity(entt::null)
|
||||
, m_team2HqEntity(entt::null)
|
||||
, m_finished(false)
|
||||
, m_winnerTeam(-1)
|
||||
, m_stopRequested(false)
|
||||
{
|
||||
m_buildingSystem = std::make_unique<BuildingSystem>(
|
||||
@@ -95,7 +94,7 @@ ArenaSimulation::ArenaSimulation(const GameConfig& gameConfig,
|
||||
updateStatus();
|
||||
}
|
||||
|
||||
std::string ArenaStatus::TeamStatus::ehpPercentText() const
|
||||
std::string ArenaStatus::TeamStatus::getEhpPercentText() const
|
||||
{
|
||||
if (maxEhp <= 0.0)
|
||||
{
|
||||
@@ -312,7 +311,7 @@ void ArenaSimulation::requestStop()
|
||||
m_stopRequested.store(true, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
ArenaStatus ArenaSimulation::status() const
|
||||
ArenaStatus ArenaSimulation::getStatus() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_statusMutex);
|
||||
return m_status;
|
||||
@@ -473,42 +472,42 @@ bool ArenaSimulation::isFinished() const
|
||||
return m_finished;
|
||||
}
|
||||
|
||||
int ArenaSimulation::winnerTeam() const
|
||||
std::optional<int> ArenaSimulation::getWinnerTeam() const
|
||||
{
|
||||
return m_winnerTeam;
|
||||
}
|
||||
|
||||
Tick ArenaSimulation::currentTick() const
|
||||
Tick ArenaSimulation::getCurrentTick() const
|
||||
{
|
||||
return m_currentTick;
|
||||
}
|
||||
|
||||
const ArenaConfig& ArenaSimulation::arenaConfig() const
|
||||
const ArenaConfig& ArenaSimulation::getArenaConfig() const
|
||||
{
|
||||
return m_arenaConfig;
|
||||
}
|
||||
|
||||
const BuildingSystem& ArenaSimulation::buildings() const
|
||||
const BuildingSystem& ArenaSimulation::getBuildings() const
|
||||
{
|
||||
return *m_buildingSystem;
|
||||
}
|
||||
|
||||
const ShipSystem& ArenaSimulation::ships() const
|
||||
const ShipSystem& ArenaSimulation::getShips() const
|
||||
{
|
||||
return *m_shipSystem;
|
||||
}
|
||||
|
||||
const ScrapSystem& ArenaSimulation::scraps() const
|
||||
const ScrapSystem& ArenaSimulation::getScraps() const
|
||||
{
|
||||
return *m_scrapSystem;
|
||||
}
|
||||
|
||||
EntityAdmin& ArenaSimulation::admin()
|
||||
EntityAdmin& ArenaSimulation::getAdmin()
|
||||
{
|
||||
return m_admin;
|
||||
}
|
||||
|
||||
const EntityAdmin& ArenaSimulation::admin() const
|
||||
const EntityAdmin& ArenaSimulation::getAdmin() const
|
||||
{
|
||||
return m_admin;
|
||||
}
|
||||
|
||||
@@ -46,19 +46,19 @@ struct ArenaStatus
|
||||
double threatLevel = 0.0; // accumulated threat of the team's configured ships
|
||||
// Remaining durability of the team's ships and defence stations (HQ
|
||||
// excluded). currentEhp is summed live; maxEhp is the fixed full-HP
|
||||
// baseline. See ehpPercentText() for the displayed value.
|
||||
// baseline. See getEhpPercentText() for the displayed value.
|
||||
double currentEhp = 0.0;
|
||||
double maxEhp = 0.0;
|
||||
std::vector<Entry> entries; // HQ first, then ships, then stations
|
||||
|
||||
// Remaining EHP as a whole-number percentage ("NN%"), or "n/a" when the
|
||||
// team has no ships or stations (maxEhp == 0).
|
||||
std::string ehpPercentText() const;
|
||||
std::string getEhpPercentText() const;
|
||||
};
|
||||
|
||||
TeamStatus teams[2];
|
||||
bool finished = false;
|
||||
int winnerTeam = -1; // 0 or 1 when finished; -1 while running
|
||||
std::optional<int> winnerTeam; // 0 or 1 when finished; nullopt while running
|
||||
// Game time the fight has lasted (simulated ticks * fixed tick duration).
|
||||
// Meaningful once finished; the battle duration shown for completed runs.
|
||||
double durationSeconds = 0.0;
|
||||
@@ -78,17 +78,17 @@ public:
|
||||
void tickOnce();
|
||||
std::vector<BeamFiredEvent> drainBeamFiredEvents();
|
||||
|
||||
ArenaStatus status() const;
|
||||
ArenaStatus getStatus() const;
|
||||
bool isFinished() const;
|
||||
int winnerTeam() const;
|
||||
Tick currentTick() const;
|
||||
std::optional<int> getWinnerTeam() const;
|
||||
Tick getCurrentTick() const;
|
||||
|
||||
const ArenaConfig& arenaConfig() const;
|
||||
const BuildingSystem& buildings() const;
|
||||
const ShipSystem& ships() const;
|
||||
const ScrapSystem& scraps() const;
|
||||
EntityAdmin& admin();
|
||||
const EntityAdmin& admin() const;
|
||||
const ArenaConfig& getArenaConfig() const;
|
||||
const BuildingSystem& getBuildings() const;
|
||||
const ShipSystem& getShips() const;
|
||||
const ScrapSystem& getScraps() const;
|
||||
EntityAdmin& getAdmin();
|
||||
const EntityAdmin& getAdmin() const;
|
||||
|
||||
private:
|
||||
BuildingId allocateBuildingId();
|
||||
@@ -122,7 +122,7 @@ private:
|
||||
entt::entity m_team2HqEntity;
|
||||
|
||||
bool m_finished;
|
||||
int m_winnerTeam;
|
||||
std::optional<int> m_winnerTeam;
|
||||
std::atomic<bool> m_stopRequested;
|
||||
|
||||
// Static accumulated threat per team, computed once from the configured roster.
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "Building.h"
|
||||
#include "BuildingSystem.h"
|
||||
#include "EntityHitTest.h"
|
||||
#include "EntitySelectedEvent.h"
|
||||
#include "EntitySelectionChangedEvent.h"
|
||||
#include "EventManager.h"
|
||||
#include "FacingComponent.h"
|
||||
#include "FactionComponent.h"
|
||||
@@ -73,7 +73,7 @@ void ArenaView::setGameSpeed(double multiplier)
|
||||
std::make_shared<GameSpeedChangedEvent>(multiplier));
|
||||
}
|
||||
|
||||
double ArenaView::gameSpeed() const
|
||||
double ArenaView::getGameSpeed() const
|
||||
{
|
||||
return m_gameSpeedMultiplier;
|
||||
}
|
||||
@@ -121,7 +121,7 @@ void ArenaView::onFrame()
|
||||
// Expire old beams. Lifetime is measured in game ticks so beams stay
|
||||
// visible while the simulation is paused or slowed (REQ-SHP-FIRING-BEAM).
|
||||
{
|
||||
const Tick now = m_sim->currentTick();
|
||||
const Tick now = m_sim->getCurrentTick();
|
||||
std::vector<ActiveBeam> live;
|
||||
for (const ActiveBeam& b : m_activeBeams)
|
||||
{
|
||||
@@ -144,16 +144,16 @@ void ArenaView::onFrame()
|
||||
void ArenaView::handleEvent(std::shared_ptr<const BeamFiredEvent> event)
|
||||
{
|
||||
float maxRadius = 0.125f;
|
||||
if (m_sim->admin().isValid(event->target)
|
||||
&& m_sim->admin().hasAll<StationBodyComponent>(event->target))
|
||||
if (m_sim->getAdmin().isValid(event->target)
|
||||
&& m_sim->getAdmin().hasAll<StationBodyComponent>(event->target))
|
||||
{
|
||||
const StationBodyComponent& sb = m_sim->admin().get<StationBodyComponent>(event->target);
|
||||
const StationBodyComponent& sb = m_sim->getAdmin().get<StationBodyComponent>(event->target);
|
||||
const int shorter = std::min(sb.footprint.width(),
|
||||
sb.footprint.height());
|
||||
maxRadius = shorter / 2.0f;
|
||||
}
|
||||
else if (m_sim->admin().isValid(event->target)
|
||||
&& m_sim->admin().hasAll<ScrapDataComponent>(event->target))
|
||||
else if (m_sim->getAdmin().isValid(event->target)
|
||||
&& m_sim->getAdmin().hasAll<ScrapDataComponent>(event->target))
|
||||
{
|
||||
maxRadius = 0.1f;
|
||||
}
|
||||
@@ -192,9 +192,9 @@ void ArenaView::paintGL()
|
||||
// Coordinate helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
float ArenaView::tilePx() const
|
||||
float ArenaView::getTilePx() const
|
||||
{
|
||||
const ArenaConfig& ac = m_sim->arenaConfig();
|
||||
const ArenaConfig& ac = m_sim->getArenaConfig();
|
||||
const int totalWidth = ac.playerBufferWidth_tiles
|
||||
+ ac.contestZoneWidth_tiles
|
||||
+ ac.enemyBufferWidth_tiles;
|
||||
@@ -209,8 +209,8 @@ float ArenaView::tilePx() const
|
||||
QPointF ArenaView::worldToWidget(QVector2D worldPos) const
|
||||
{
|
||||
return QPointF(
|
||||
static_cast<qreal>(worldPos.x() * tilePx()),
|
||||
static_cast<qreal>(worldPos.y() * tilePx()));
|
||||
static_cast<qreal>(worldPos.x() * getTilePx()),
|
||||
static_cast<qreal>(worldPos.y() * getTilePx()));
|
||||
}
|
||||
|
||||
QPointF ArenaView::tileToWidget(QPoint tile) const
|
||||
@@ -223,21 +223,21 @@ QRectF ArenaView::tileRect(QPoint tile) const
|
||||
{
|
||||
const QPointF tl = tileToWidget(tile);
|
||||
return QRectF(tl.x(), tl.y(),
|
||||
static_cast<qreal>(tilePx()), static_cast<qreal>(tilePx()));
|
||||
static_cast<qreal>(getTilePx()), static_cast<qreal>(getTilePx()));
|
||||
}
|
||||
|
||||
std::optional<QVector2D> ArenaView::entityPosition(entt::entity entity) const
|
||||
{
|
||||
if (!m_sim->admin().isValid(entity) || !m_sim->admin().hasAll<PositionComponent>(entity))
|
||||
if (!m_sim->getAdmin().isValid(entity) || !m_sim->getAdmin().hasAll<PositionComponent>(entity))
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
return m_sim->admin().get<PositionComponent>(entity).value;
|
||||
return m_sim->getAdmin().get<PositionComponent>(entity).value;
|
||||
}
|
||||
|
||||
QVector2D ArenaView::widgetToWorld(QPoint widgetPt) const
|
||||
{
|
||||
const float px = tilePx();
|
||||
const float px = getTilePx();
|
||||
if (px < 0.001f) { return QVector2D(0.0f, 0.0f); }
|
||||
return QVector2D(static_cast<float>(widgetPt.x()) / px,
|
||||
static_cast<float>(widgetPt.y()) / px);
|
||||
@@ -248,7 +248,7 @@ void ArenaView::mousePressEvent(QMouseEvent* event)
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
const QVector2D worldPos = widgetToWorld(event->pos());
|
||||
entt::entity hit = entityAtWorldPos(m_sim->admin(), worldPos);
|
||||
entt::entity hit = entityAtWorldPos(m_sim->getAdmin(), worldPos);
|
||||
|
||||
if (hit != entt::null)
|
||||
{
|
||||
@@ -259,8 +259,14 @@ void ArenaView::mousePressEvent(QMouseEvent* event)
|
||||
m_selectedEntity = std::nullopt;
|
||||
}
|
||||
|
||||
// The arena is strictly single-select; emit a vector of size 0 or 1.
|
||||
std::vector<entt::entity> selection;
|
||||
if (m_selectedEntity.has_value())
|
||||
{
|
||||
selection.push_back(*m_selectedEntity);
|
||||
}
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<EntitySelectedEvent>(m_selectedEntity));
|
||||
std::make_shared<EntitySelectionChangedEvent>(selection));
|
||||
}
|
||||
|
||||
QOpenGLWidget::mousePressEvent(event);
|
||||
@@ -282,7 +288,7 @@ void ArenaView::keyPressEvent(QKeyEvent* event)
|
||||
|
||||
void ArenaView::drawTiles(QPainter& painter)
|
||||
{
|
||||
const ArenaConfig& ac = m_sim->arenaConfig();
|
||||
const ArenaConfig& ac = m_sim->getArenaConfig();
|
||||
const int totalWidth = ac.playerBufferWidth_tiles
|
||||
+ ac.contestZoneWidth_tiles
|
||||
+ ac.enemyBufferWidth_tiles;
|
||||
@@ -300,7 +306,7 @@ void ArenaView::drawTiles(QPainter& painter)
|
||||
|
||||
void ArenaView::drawBuildings(QPainter& painter)
|
||||
{
|
||||
for (const Building& b : m_sim->buildings().allBuildings())
|
||||
for (const Building& b : m_sim->getBuildings().getAllBuildings())
|
||||
{
|
||||
const std::map<BuildingType, BuildingVisuals>::const_iterator it =
|
||||
m_visuals->buildings.find(b.type);
|
||||
@@ -315,8 +321,8 @@ void ArenaView::drawBuildings(QPainter& painter)
|
||||
|
||||
const QPointF tl = tileToWidget(b.anchor);
|
||||
const QRectF bboxRect(tl.x(), tl.y(),
|
||||
b.footprint.width() * static_cast<qreal>(tilePx()),
|
||||
b.footprint.height() * static_cast<qreal>(tilePx()));
|
||||
b.footprint.width() * static_cast<qreal>(getTilePx()),
|
||||
b.footprint.height() * static_cast<qreal>(getTilePx()));
|
||||
|
||||
painter.setPen(QPen(bv.outline, 1));
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
@@ -332,8 +338,8 @@ void ArenaView::drawBuildings(QPainter& painter)
|
||||
|
||||
void ArenaView::drawScrap(QPainter& painter)
|
||||
{
|
||||
const float r = tilePx() * 0.2f;
|
||||
for (const ScrapInfo& scrap : m_sim->scraps().allScrapInfo())
|
||||
const float r = getTilePx() * 0.2f;
|
||||
for (const ScrapInfo& scrap : m_sim->getScraps().getAllScrapInfo())
|
||||
{
|
||||
const QPointF center = worldToWidget(scrap.position);
|
||||
painter.setBrush(QColor(128, 110, 90));
|
||||
@@ -345,7 +351,7 @@ void ArenaView::drawScrap(QPainter& painter)
|
||||
|
||||
void ArenaView::drawStations(QPainter& painter)
|
||||
{
|
||||
m_sim->admin().forEach<StationBodyComponent, FactionComponent, HealthComponent>(
|
||||
m_sim->getAdmin().forEach<StationBodyComponent, FactionComponent, HealthComponent>(
|
||||
[&](entt::entity e, const StationBodyComponent& sb, const FactionComponent& f, const HealthComponent& h)
|
||||
{
|
||||
const BuildingType visType = f.isEnemy
|
||||
@@ -364,8 +370,8 @@ void ArenaView::drawStations(QPainter& painter)
|
||||
|
||||
const QPointF tl = tileToWidget(sb.anchor);
|
||||
const QRectF bboxRect(tl.x(), tl.y(),
|
||||
sb.footprint.width() * static_cast<qreal>(tilePx()),
|
||||
sb.footprint.height() * static_cast<qreal>(tilePx()));
|
||||
sb.footprint.width() * static_cast<qreal>(getTilePx()),
|
||||
sb.footprint.height() * static_cast<qreal>(getTilePx()));
|
||||
|
||||
painter.setPen(QPen(bv.outline, 1));
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
@@ -374,7 +380,7 @@ void ArenaView::drawStations(QPainter& painter)
|
||||
if (h.maxHp > 0.0f)
|
||||
{
|
||||
const float fraction = std::max(0.0f, h.hp / h.maxHp);
|
||||
const qreal barH = static_cast<qreal>(tilePx()) * 0.12;
|
||||
const qreal barH = static_cast<qreal>(getTilePx()) * 0.12;
|
||||
const qreal barY = bboxRect.bottom() + 1.0;
|
||||
const qreal barW = bboxRect.width();
|
||||
painter.fillRect(QRectF(bboxRect.left(), barY, barW, barH),
|
||||
@@ -394,7 +400,7 @@ void ArenaView::drawStations(QPainter& painter)
|
||||
|
||||
void ArenaView::drawShips(QPainter& painter)
|
||||
{
|
||||
m_sim->admin().forEach<ShipIdentityComponent, PositionComponent, FacingComponent,
|
||||
m_sim->getAdmin().forEach<ShipIdentityComponent, PositionComponent, FacingComponent,
|
||||
FactionComponent, HealthComponent>(
|
||||
[&](entt::entity e, const ShipIdentityComponent& si,
|
||||
const PositionComponent& pos, const FacingComponent& facing,
|
||||
@@ -408,8 +414,8 @@ void ArenaView::drawShips(QPainter& painter)
|
||||
const QVector2D dir(std::cos(facing.radians), std::sin(facing.radians));
|
||||
const QVector2D perp(-dir.y(), dir.x());
|
||||
|
||||
const float fwd = tilePx() * 0.45f;
|
||||
const float side = tilePx() * 0.25f;
|
||||
const float fwd = getTilePx() * 0.45f;
|
||||
const float side = getTilePx() * 0.25f;
|
||||
|
||||
QPolygonF tri;
|
||||
tri << QPointF(center.x() + static_cast<qreal>(dir.x() * fwd),
|
||||
@@ -427,7 +433,7 @@ void ArenaView::drawShips(QPainter& painter)
|
||||
{
|
||||
const float fraction = std::max(0.0f, h.hp / h.maxHp);
|
||||
const qreal barW = static_cast<qreal>(fwd) * 2.0;
|
||||
const qreal barH = static_cast<qreal>(tilePx()) * 0.12;
|
||||
const qreal barH = static_cast<qreal>(getTilePx()) * 0.12;
|
||||
const qreal barX = center.x() - static_cast<qreal>(fwd);
|
||||
const qreal barY = center.y() + static_cast<qreal>(fwd) + 1.0;
|
||||
painter.fillRect(QRectF(barX, barY, barW, barH), QColor(60, 60, 60));
|
||||
@@ -437,7 +443,7 @@ void ArenaView::drawShips(QPainter& painter)
|
||||
|
||||
if (m_selectedEntity.has_value() && *m_selectedEntity == e)
|
||||
{
|
||||
const qreal radius = static_cast<qreal>(tilePx()) * 0.55;
|
||||
const qreal radius = static_cast<qreal>(getTilePx()) * 0.55;
|
||||
painter.setPen(QPen(QColor(255, 255, 0), 2));
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
painter.drawEllipse(center, radius, radius);
|
||||
@@ -448,7 +454,7 @@ void ArenaView::drawShips(QPainter& painter)
|
||||
void ArenaView::drawDebugSensorRanges(QPainter& painter)
|
||||
{
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
m_sim->admin().forEach<ShipIdentityComponent, PositionComponent, SensorRangeComponent>(
|
||||
m_sim->getAdmin().forEach<ShipIdentityComponent, PositionComponent, SensorRangeComponent>(
|
||||
[&](entt::entity /*e*/, const ShipIdentityComponent& si,
|
||||
const PositionComponent& pos, const SensorRangeComponent& sensor)
|
||||
{
|
||||
@@ -458,7 +464,7 @@ void ArenaView::drawDebugSensorRanges(QPainter& painter)
|
||||
|
||||
const QPointF center = worldToWidget(pos.value);
|
||||
const qreal radiusPx = static_cast<qreal>(sensor.value_tiles)
|
||||
* static_cast<qreal>(tilePx());
|
||||
* static_cast<qreal>(getTilePx());
|
||||
QColor circleColor = it->second.outline;
|
||||
circleColor.setAlpha(77);
|
||||
painter.setPen(QPen(circleColor, 1));
|
||||
@@ -487,7 +493,7 @@ void ArenaView::drawDebugTargetLines(QPainter& painter)
|
||||
painter.drawLine(worldToWidget(from), worldToWidget(to));
|
||||
};
|
||||
|
||||
m_sim->admin().forEach<ShipIdentityComponent, PositionComponent,
|
||||
m_sim->getAdmin().forEach<ShipIdentityComponent, PositionComponent,
|
||||
FactionComponent, AttackBehavior>(
|
||||
[&](entt::entity /*e*/, const ShipIdentityComponent& /*si*/,
|
||||
const PositionComponent& pos, const FactionComponent& fac,
|
||||
@@ -502,7 +508,7 @@ void ArenaView::drawDebugTargetLines(QPainter& painter)
|
||||
drawTargetLine(fac.isEnemy, pos.value, *targetPos);
|
||||
});
|
||||
|
||||
m_sim->admin().forEach<ShipIdentityComponent, PositionComponent,
|
||||
m_sim->getAdmin().forEach<ShipIdentityComponent, PositionComponent,
|
||||
FactionComponent, RepairBehavior>(
|
||||
[&](entt::entity /*e*/, const ShipIdentityComponent& /*si*/,
|
||||
const PositionComponent& pos, const FactionComponent& fac,
|
||||
@@ -517,7 +523,7 @@ void ArenaView::drawDebugTargetLines(QPainter& painter)
|
||||
drawTargetLine(fac.isEnemy, pos.value, *targetPos);
|
||||
});
|
||||
|
||||
m_sim->admin().forEach<ShipIdentityComponent, PositionComponent,
|
||||
m_sim->getAdmin().forEach<ShipIdentityComponent, PositionComponent,
|
||||
FactionComponent, SalvageScrapBehavior>(
|
||||
[&](entt::entity /*e*/, const ShipIdentityComponent& /*si*/,
|
||||
const PositionComponent& pos, const FactionComponent& fac,
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "BeamFiredEvent.h"
|
||||
|
||||
#include "entt/entity/entity.hpp"
|
||||
#include "EntitySelectedEvent.h"
|
||||
#include "EntitySelectionChangedEvent.h"
|
||||
#include "Tick.h"
|
||||
#include "TickDriver.h"
|
||||
#include "VisualsConfig.h"
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
~ArenaView() override;
|
||||
|
||||
void setGameSpeed(double multiplier);
|
||||
double gameSpeed() const;
|
||||
double getGameSpeed() const;
|
||||
void togglePause();
|
||||
void stopRendering();
|
||||
|
||||
@@ -56,7 +56,7 @@ private:
|
||||
void drawDebugTargetLines(QPainter& painter);
|
||||
void drawBeams(QPainter& painter);
|
||||
|
||||
float tilePx() const;
|
||||
float getTilePx() const;
|
||||
QPointF worldToWidget(QVector2D worldPos) const;
|
||||
QPointF tileToWidget(QPoint tile) const;
|
||||
QRectF tileRect(QPoint tile) const;
|
||||
|
||||
@@ -141,7 +141,7 @@ void ArenaWidget::updateStatus(const ArenaStatus& status)
|
||||
}
|
||||
|
||||
threat->setText(tr("Threat: %1").arg(QString::number(team.threatLevel, 'f', 0)));
|
||||
ehp->setText(tr("EHP: %1").arg(QString::fromStdString(team.ehpPercentText())));
|
||||
ehp->setText(tr("EHP: %1").arg(QString::fromStdString(team.getEhpPercentText())));
|
||||
|
||||
QString lines;
|
||||
for (const ArenaStatus::Entry& entry : team.entries)
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace
|
||||
header = QStringLiteral("[WON] ") + header;
|
||||
}
|
||||
header += QStringLiteral(" - threat %1").arg(QString::number(team.threatLevel, 'f', 0));
|
||||
header += QStringLiteral(" - EHP %1").arg(QString::fromStdString(team.ehpPercentText()));
|
||||
header += QStringLiteral(" - EHP %1").arg(QString::fromStdString(team.getEhpPercentText()));
|
||||
return escapeCell(header);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,6 @@ BalancingWindow::BalancingWindow(const BalancingConfig& balancingConfig,
|
||||
, m_balancingConfigPath(balancingConfigPath)
|
||||
, m_nextSeed(0)
|
||||
, m_inspectWindow(nullptr)
|
||||
, m_inspectedArenaIndex(-1)
|
||||
{
|
||||
m_visuals = VisualsLoader::load(m_configDir + "/visuals.toml");
|
||||
setWindowTitle(tr("DotaFactory — Balancing Tool"));
|
||||
@@ -147,7 +146,7 @@ void BalancingWindow::populateArenas(const BalancingConfig& balancingConfig)
|
||||
entry.widget = new ArenaWidget(index, arenaConfig.name, scrollContent);
|
||||
contentLayout->addWidget(entry.widget);
|
||||
|
||||
entry.widget->updateStatus(entry.simulation->status());
|
||||
entry.widget->updateStatus(entry.simulation->getStatus());
|
||||
|
||||
m_arenas.push_back(std::move(entry));
|
||||
}
|
||||
@@ -179,15 +178,15 @@ void BalancingWindow::pollStatuses()
|
||||
{
|
||||
if (entry.worker.joinable())
|
||||
{
|
||||
const ArenaStatus status = entry.simulation->status();
|
||||
const ArenaStatus status = entry.simulation->getStatus();
|
||||
entry.widget->updateStatus(status);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_inspectedSim && m_inspectedArenaIndex >= 0)
|
||||
if (m_inspectedSim && m_inspectedArenaIndex.has_value())
|
||||
{
|
||||
const ArenaStatus status = m_inspectedSim->status();
|
||||
m_arenas[static_cast<std::size_t>(m_inspectedArenaIndex)].widget->updateStatus(status);
|
||||
const ArenaStatus status = m_inspectedSim->getStatus();
|
||||
m_arenas[static_cast<std::size_t>(*m_inspectedArenaIndex)].widget->updateStatus(status);
|
||||
}
|
||||
|
||||
updateButtons();
|
||||
@@ -242,7 +241,7 @@ void BalancingWindow::startArena(int index)
|
||||
entry.simulation = std::make_unique<ArenaSimulation>(
|
||||
m_gameConfig, entry.config, m_nextSeed++);
|
||||
entry.widget->startSimulation();
|
||||
entry.widget->updateStatus(entry.simulation->status());
|
||||
entry.widget->updateStatus(entry.simulation->getStatus());
|
||||
ArenaSimulation* sim = entry.simulation.get();
|
||||
entry.worker = std::thread([sim]() { sim->run(); });
|
||||
updateButtons();
|
||||
@@ -255,13 +254,13 @@ void BalancingWindow::inspectArena(int index)
|
||||
delete m_inspectWindow;
|
||||
m_inspectWindow = nullptr;
|
||||
|
||||
if (m_inspectedSim && m_inspectedArenaIndex >= 0
|
||||
if (m_inspectedSim && m_inspectedArenaIndex.has_value()
|
||||
&& !m_inspectedSim->isFinished())
|
||||
{
|
||||
m_arenas[static_cast<std::size_t>(m_inspectedArenaIndex)].widget->resetToGrey();
|
||||
m_arenas[static_cast<std::size_t>(*m_inspectedArenaIndex)].widget->resetToGrey();
|
||||
}
|
||||
m_inspectedSim.reset();
|
||||
m_inspectedArenaIndex = -1;
|
||||
m_inspectedArenaIndex = std::nullopt;
|
||||
}
|
||||
|
||||
ArenaEntry& entry = m_arenas[static_cast<std::size_t>(index)];
|
||||
@@ -278,7 +277,7 @@ void BalancingWindow::inspectArena(int index)
|
||||
|
||||
entry.widget->resetToGrey();
|
||||
entry.widget->startSimulation();
|
||||
entry.widget->updateStatus(m_inspectedSim->status());
|
||||
entry.widget->updateStatus(m_inspectedSim->getStatus());
|
||||
|
||||
m_inspectWindow = new InspectWindow(
|
||||
m_inspectedSim.get(), &m_gameConfig, &m_visuals, entry.config.name, nullptr);
|
||||
@@ -297,16 +296,16 @@ void BalancingWindow::closeInspectWindow()
|
||||
m_inspectWindow->deleteLater();
|
||||
m_inspectWindow = nullptr;
|
||||
|
||||
if (m_inspectedArenaIndex >= 0 && m_inspectedSim)
|
||||
if (m_inspectedArenaIndex.has_value() && m_inspectedSim)
|
||||
{
|
||||
if (!m_inspectedSim->isFinished())
|
||||
{
|
||||
m_arenas[static_cast<std::size_t>(m_inspectedArenaIndex)].widget->resetToGrey();
|
||||
m_arenas[static_cast<std::size_t>(*m_inspectedArenaIndex)].widget->resetToGrey();
|
||||
}
|
||||
}
|
||||
|
||||
m_inspectedSim.reset();
|
||||
m_inspectedArenaIndex = -1;
|
||||
m_inspectedArenaIndex = std::nullopt;
|
||||
setMainControlsEnabled(true);
|
||||
updateButtons();
|
||||
}
|
||||
@@ -336,7 +335,7 @@ void BalancingWindow::updateButtons()
|
||||
bool allRunning = true;
|
||||
for (ArenaEntry& entry : m_arenas)
|
||||
{
|
||||
if (entry.worker.joinable() && !entry.simulation->status().finished)
|
||||
if (entry.worker.joinable() && !entry.simulation->getStatus().finished)
|
||||
{
|
||||
anyRunning = true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
@@ -78,6 +79,6 @@ private:
|
||||
QTimer* m_pollTimer;
|
||||
|
||||
InspectWindow* m_inspectWindow;
|
||||
int m_inspectedArenaIndex;
|
||||
std::optional<int> m_inspectedArenaIndex; // nullopt = no arena inspected
|
||||
std::unique_ptr<ArenaSimulation> m_inspectedSim;
|
||||
};
|
||||
|
||||
@@ -199,7 +199,7 @@ void InspectWindow::handleEvent(std::shared_ptr<const GameSpeedChangedEvent> eve
|
||||
|
||||
void InspectWindow::pollStatus()
|
||||
{
|
||||
const ArenaStatus status = m_sim->status();
|
||||
const ArenaStatus status = m_sim->getStatus();
|
||||
updateInfoPanel(status);
|
||||
refreshEntityStats();
|
||||
}
|
||||
@@ -228,7 +228,7 @@ void InspectWindow::updateInfoPanel(const ArenaStatus& status)
|
||||
}
|
||||
|
||||
threat->setText(tr("Threat: %1").arg(QString::number(team.threatLevel, 'f', 0)));
|
||||
ehp->setText(tr("EHP: %1").arg(QString::fromStdString(team.ehpPercentText())));
|
||||
ehp->setText(tr("EHP: %1").arg(QString::fromStdString(team.getEhpPercentText())));
|
||||
|
||||
QString lines;
|
||||
for (const ArenaStatus::Entry& entry : team.entries)
|
||||
@@ -250,13 +250,14 @@ void InspectWindow::updateInfoPanel(const ArenaStatus& status)
|
||||
}
|
||||
}
|
||||
|
||||
void InspectWindow::handleEvent(std::shared_ptr<const EntitySelectedEvent> event)
|
||||
void InspectWindow::handleEvent(std::shared_ptr<const EntitySelectionChangedEvent> event)
|
||||
{
|
||||
if (event->entity.has_value())
|
||||
if (!event->entities.empty())
|
||||
{
|
||||
m_selectedEntity = event->entity;
|
||||
// The arena is single-select, so only the first entity is inspected.
|
||||
m_selectedEntity = event->entities.front();
|
||||
|
||||
EntityAdmin& admin = m_sim->admin();
|
||||
EntityAdmin& admin = m_sim->getAdmin();
|
||||
entt::entity entity = *m_selectedEntity;
|
||||
|
||||
if (!admin.isValid(entity))
|
||||
@@ -332,7 +333,7 @@ void InspectWindow::refreshEntityStats()
|
||||
{
|
||||
if (!m_selectedEntity.has_value()) { return; }
|
||||
|
||||
EntityAdmin& admin = m_sim->admin();
|
||||
EntityAdmin& admin = m_sim->getAdmin();
|
||||
entt::entity entity = *m_selectedEntity;
|
||||
|
||||
if (!admin.isValid(entity))
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "entt/entity/entity.hpp"
|
||||
|
||||
#include "ArenaSimulation.h"
|
||||
#include "EntitySelectedEvent.h"
|
||||
#include "EntitySelectionChangedEvent.h"
|
||||
#include "EventHandler.h"
|
||||
#include "GameConfig.h"
|
||||
#include "GameSpeedChangedEvent.h"
|
||||
@@ -22,7 +22,7 @@ class ArenaView;
|
||||
class ShipStatsPanel;
|
||||
|
||||
class InspectWindow : public QWidget,
|
||||
public CombinedEventHandler<EntitySelectedEvent,
|
||||
public CombinedEventHandler<EntitySelectionChangedEvent,
|
||||
GameSpeedChangedEvent>
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -38,7 +38,7 @@ protected:
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
|
||||
private:
|
||||
void handleEvent(std::shared_ptr<const EntitySelectedEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const EntitySelectionChangedEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const GameSpeedChangedEvent> event) override;
|
||||
|
||||
private slots:
|
||||
|
||||
@@ -8,6 +8,7 @@ SET(HDRS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/StationsConfig.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/GameConfig.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ModulesConfig.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/UnlocksConfig.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ConfigLoader.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/SurfaceMask.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BlueprintSerializer.h
|
||||
|
||||
@@ -263,6 +263,7 @@ WorldConfig ConfigLoader::loadWorld(const std::string& path)
|
||||
|
||||
cfg.heightTiles = static_cast<int>(requireInt(tbl["world"]["height_tiles"], file, "world.height_tiles"));
|
||||
cfg.refundPercentage = static_cast<int>(requireInt(tbl["world"]["refund_percentage"], file, "world.refund_percentage"));
|
||||
cfg.deconstructionTimeSeconds = requireDouble(tbl["world"]["deconstruction_time_seconds"], file, "world.deconstruction_time_seconds");
|
||||
cfg.startingBuildingBlocks = static_cast<int>(requireInt(tbl["world"]["starting_building_blocks"], file, "world.starting_building_blocks"));
|
||||
cfg.scrapDespawnSeconds = requireDouble(tbl["world"]["scrap_despawn_seconds"], file, "world.scrap_despawn_seconds");
|
||||
cfg.scrapPerThreat = requireDouble(tbl["world"]["scrap_per_threat"], file, "world.scrap_per_threat");
|
||||
@@ -279,6 +280,12 @@ WorldConfig ConfigLoader::loadWorld(const std::string& path)
|
||||
cfg.buildingBlocksTooltip = *tip;
|
||||
}
|
||||
|
||||
if (const std::optional<std::string> tip =
|
||||
tbl["world"]["artifact_tooltip"].value<std::string>())
|
||||
{
|
||||
cfg.artifactTooltip = *tip;
|
||||
}
|
||||
|
||||
cfg.regions.asteroidWidth_tiles = static_cast<int>(requireInt(tbl["regions"]["asteroid_width_tiles"], file, "regions.asteroid_width_tiles"));
|
||||
cfg.regions.playerBufferWidth_tiles = static_cast<int>(requireInt(tbl["regions"]["player_buffer_width_tiles"], file, "regions.player_buffer_width_tiles"));
|
||||
cfg.regions.contestZoneWidth_tiles = static_cast<int>(requireInt(tbl["regions"]["contest_zone_width_tiles"], file, "regions.contest_zone_width_tiles"));
|
||||
@@ -398,18 +405,10 @@ RecipesConfig ConfigLoader::loadRecipes(const std::string& path)
|
||||
}
|
||||
def.building = *parsedType;
|
||||
|
||||
if (def.building == BuildingType::Assembler)
|
||||
if (def.building == BuildingType::Assembler && mt.contains("unlocked_at_start"))
|
||||
{
|
||||
const auto level = mt["unlock_at_station_level"].value<int64_t>();
|
||||
if (level)
|
||||
{
|
||||
def.unlockAtStationLevel = static_cast<int>(*level);
|
||||
}
|
||||
if (mt.contains("unlock_requires"))
|
||||
{
|
||||
def.unlockRequires = requireStringArray(mt["unlock_requires"], file,
|
||||
elemPath + ".unlock_requires");
|
||||
}
|
||||
def.unlockedAtStart = requireBool(mt["unlocked_at_start"], file,
|
||||
elemPath + ".unlocked_at_start");
|
||||
}
|
||||
|
||||
// inputs may be omitted (e.g. miner recipes). An empty array is fine.
|
||||
@@ -448,11 +447,6 @@ ShipsConfig ConfigLoader::loadShips(const std::string& path)
|
||||
|
||||
ShipDef def;
|
||||
def.id = requireString(mt["id"], file, elemPath + ".id");
|
||||
def.unlockAtStationLevel = static_cast<int>(requireInt(mt["unlock_at_station_level"], file, elemPath + ".unlock_at_station_level"));
|
||||
if (mt.contains("unlock_requires"))
|
||||
{
|
||||
def.unlockRequires = requireStringArray(mt["unlock_requires"], file, elemPath + ".unlock_requires");
|
||||
}
|
||||
def.layout = requireStringArray(mt["layout"], file, elemPath + ".layout");
|
||||
|
||||
// Schematic
|
||||
@@ -602,12 +596,6 @@ ModulesConfig ConfigLoader::loadModules(const std::string& path)
|
||||
|
||||
ModuleDef def;
|
||||
def.id = requireString(mt["id"], file, elemPath + ".id");
|
||||
def.unlockAtStationLevel = static_cast<int>(
|
||||
mt["unlock_at_station_level"].value_or<int64_t>(-1));
|
||||
if (mt.contains("unlock_requires"))
|
||||
{
|
||||
def.unlockRequires = requireStringArray(mt["unlock_requires"], file, elemPath + ".unlock_requires");
|
||||
}
|
||||
def.surfaceMask = requireStringArray(mt["surface_mask"], file, elemPath + ".surface_mask");
|
||||
def.productionTimeSeconds = requireDouble(
|
||||
mt["production_time_seconds"], file, elemPath + ".production_time_seconds");
|
||||
@@ -725,62 +713,141 @@ ModulesConfig ConfigLoader::loadModules(const std::string& path)
|
||||
return cfg;
|
||||
}
|
||||
|
||||
UnlocksConfig ConfigLoader::loadUnlocks(const std::string& path)
|
||||
{
|
||||
const std::string file = "unlocks.toml";
|
||||
toml::table tbl = parseFile(path, file);
|
||||
|
||||
UnlocksConfig cfg;
|
||||
if (!tbl.contains("unlock"))
|
||||
{
|
||||
return cfg;
|
||||
}
|
||||
|
||||
const toml::array& arr = requireArray(tbl["unlock"], file, "unlock");
|
||||
|
||||
for (std::size_t i = 0; i < arr.size(); ++i)
|
||||
{
|
||||
const std::string elemPath = "unlock[" + std::to_string(i) + "]";
|
||||
const toml::table* ut = arr[i].as_table();
|
||||
if (ut == nullptr)
|
||||
{
|
||||
throw makeError(file, elemPath, "not a table");
|
||||
}
|
||||
toml::table& mt = const_cast<toml::table&>(*ut);
|
||||
|
||||
UnlockGroupDef def;
|
||||
def.id = requireString(mt["id"], file, elemPath + ".id");
|
||||
def.stationLevel = static_cast<int>(
|
||||
requireInt(mt["station_level"], file, elemPath + ".station_level"));
|
||||
if (mt.contains("requires"))
|
||||
{
|
||||
def.requiredGroupIds = requireStringArray(mt["requires"], file, elemPath + ".requires");
|
||||
}
|
||||
if (mt.contains("ships"))
|
||||
{
|
||||
def.ships = requireStringArray(mt["ships"], file, elemPath + ".ships");
|
||||
}
|
||||
if (mt.contains("modules"))
|
||||
{
|
||||
def.modules = requireStringArray(mt["modules"], file, elemPath + ".modules");
|
||||
}
|
||||
if (mt.contains("buildings"))
|
||||
{
|
||||
def.buildings = requireStringArray(mt["buildings"], file, elemPath + ".buildings");
|
||||
}
|
||||
if (mt.contains("recipes"))
|
||||
{
|
||||
def.recipes = requireStringArray(mt["recipes"], file, elemPath + ".recipes");
|
||||
}
|
||||
|
||||
cfg.groups.push_back(std::move(def));
|
||||
}
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
// Throws if any id in requiredIds is not a valid explicitly-unlockable schematic.
|
||||
void checkUnlockRequires(const std::vector<std::string>& requiredIds,
|
||||
const std::unordered_set<std::string>& schematicIds,
|
||||
const std::string& file,
|
||||
const std::string& path)
|
||||
// Validates unlocks.toml against the rest of the config (REQ-LOCK-EXPLICIT,
|
||||
// REQ-LOCK-PREREQ): each granted id resolves to the right kind of definition
|
||||
// (recipe grants must name assembler recipes), each grantable id is granted by
|
||||
// at most one group, group ids are unique, every group grants at least one
|
||||
// item, and every `requires` id names a defined group.
|
||||
void validateUnlocks(const GameConfig& cfg)
|
||||
{
|
||||
for (const std::string& requiredId : requiredIds)
|
||||
{
|
||||
if (schematicIds.count(requiredId) == 0)
|
||||
{
|
||||
throw makeError(file, path,
|
||||
"references unknown schematic '" + requiredId + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
const std::string file = "unlocks.toml";
|
||||
|
||||
// Validates that every id listed in an `unlock_requires` (REQ-LOCK-PREREQ)
|
||||
// resolves to an explicitly-unlockable schematic: a ship, a module, or an
|
||||
// assembler recipe that carries `unlock_at_station_level` (a recipe schematic,
|
||||
// per REQ-LOCK-EXPLICIT). An unresolved id is a config error surfaced at load.
|
||||
void validateUnlockRequires(const GameConfig& cfg)
|
||||
{
|
||||
std::unordered_set<std::string> schematicIds;
|
||||
for (const ShipDef& def : cfg.ships.ships)
|
||||
{
|
||||
schematicIds.insert(def.id);
|
||||
}
|
||||
for (const ModuleDef& def : cfg.modules.modules)
|
||||
{
|
||||
schematicIds.insert(def.id);
|
||||
}
|
||||
std::unordered_set<std::string> shipIds;
|
||||
for (const ShipDef& def : cfg.ships.ships) { shipIds.insert(def.id); }
|
||||
std::unordered_set<std::string> moduleIds;
|
||||
for (const ModuleDef& def : cfg.modules.modules) { moduleIds.insert(def.id); }
|
||||
std::unordered_set<std::string> buildingIds;
|
||||
for (const BuildingDef& def : cfg.buildings.buildings) { buildingIds.insert(def.id); }
|
||||
std::unordered_set<std::string> assemblerRecipeIds;
|
||||
for (const RecipeDef& def : cfg.recipes.recipes)
|
||||
{
|
||||
if (def.building == BuildingType::Assembler && def.unlockAtStationLevel.has_value())
|
||||
{
|
||||
schematicIds.insert(def.id);
|
||||
}
|
||||
if (def.building == BuildingType::Assembler) { assemblerRecipeIds.insert(def.id); }
|
||||
}
|
||||
|
||||
for (const ShipDef& def : cfg.ships.ships)
|
||||
std::unordered_set<std::string> groupIds;
|
||||
std::unordered_set<std::string> grantedShipIds;
|
||||
std::unordered_set<std::string> grantedModuleIds;
|
||||
std::unordered_set<std::string> grantedBuildingIds;
|
||||
std::unordered_set<std::string> grantedRecipeIds;
|
||||
|
||||
const auto checkGrants = [&](const std::vector<std::string>& ids,
|
||||
const std::unordered_set<std::string>& valid,
|
||||
std::unordered_set<std::string>& granted,
|
||||
const std::string& kind,
|
||||
const std::string& gPath)
|
||||
{
|
||||
checkUnlockRequires(def.unlockRequires, schematicIds, "ships.toml",
|
||||
"ship '" + def.id + "'.unlock_requires");
|
||||
for (const std::string& id : ids)
|
||||
{
|
||||
if (valid.count(id) == 0)
|
||||
{
|
||||
throw makeError(file, gPath, "grants unknown " + kind + " '" + id + "'");
|
||||
}
|
||||
if (!granted.insert(id).second)
|
||||
{
|
||||
throw makeError(file, gPath,
|
||||
"grants " + kind + " '" + id + "' which is already granted by another unlock group");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (const UnlockGroupDef& group : cfg.unlocks.groups)
|
||||
{
|
||||
const std::string gPath = "unlock '" + group.id + "'";
|
||||
if (!groupIds.insert(group.id).second)
|
||||
{
|
||||
throw makeError(file, gPath, "duplicate unlock group id");
|
||||
}
|
||||
|
||||
if (group.ships.empty() && group.modules.empty()
|
||||
&& group.buildings.empty() && group.recipes.empty())
|
||||
{
|
||||
throw makeError(file, gPath, "grants no items (must grant at least one)");
|
||||
}
|
||||
|
||||
checkGrants(group.ships, shipIds, grantedShipIds, "ship", gPath);
|
||||
checkGrants(group.modules, moduleIds, grantedModuleIds, "module", gPath);
|
||||
checkGrants(group.buildings, buildingIds, grantedBuildingIds, "building", gPath);
|
||||
checkGrants(group.recipes, assemblerRecipeIds, grantedRecipeIds, "assembler recipe", gPath);
|
||||
}
|
||||
for (const ModuleDef& def : cfg.modules.modules)
|
||||
|
||||
// requires must reference defined group ids (checked once all group ids known).
|
||||
for (const UnlockGroupDef& group : cfg.unlocks.groups)
|
||||
{
|
||||
checkUnlockRequires(def.unlockRequires, schematicIds, "modules.toml",
|
||||
"module '" + def.id + "'.unlock_requires");
|
||||
}
|
||||
for (const RecipeDef& def : cfg.recipes.recipes)
|
||||
{
|
||||
checkUnlockRequires(def.unlockRequires, schematicIds, "recipes.toml",
|
||||
"recipe '" + def.id + "'.unlock_requires");
|
||||
for (const std::string& req : group.requiredGroupIds)
|
||||
{
|
||||
if (groupIds.count(req) == 0)
|
||||
{
|
||||
throw makeError(file, "unlock '" + group.id + "'.requires",
|
||||
"references unknown unlock group '" + req + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -795,7 +862,8 @@ GameConfig ConfigLoader::loadFromDirectory(const std::string& configDir)
|
||||
cfg.ships = loadShips(configDir + "/ships.toml");
|
||||
cfg.stations = loadStations(configDir + "/stations.toml");
|
||||
cfg.modules = loadModules(configDir + "/modules.toml");
|
||||
validateUnlockRequires(cfg);
|
||||
cfg.unlocks = loadUnlocks(configDir + "/unlocks.toml");
|
||||
validateUnlocks(cfg);
|
||||
cfg.threatCosts = computeThreatCostTable(cfg);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@@ -22,4 +22,5 @@ public:
|
||||
static ShipsConfig loadShips(const std::string& path);
|
||||
static StationsConfig loadStations(const std::string& path);
|
||||
static ModulesConfig loadModules(const std::string& path);
|
||||
static UnlocksConfig loadUnlocks(const std::string& path);
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
// Evaluates the expression at the given x. Requires a compiled formula.
|
||||
double evaluate(double x) const;
|
||||
|
||||
const std::string& source() const { return m_source; }
|
||||
const std::string& getSource() const { return m_source; }
|
||||
bool isValid() const { return m_expr != nullptr; }
|
||||
|
||||
private:
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "ShipsConfig.h"
|
||||
#include "StationsConfig.h"
|
||||
#include "ModulesConfig.h"
|
||||
#include "UnlocksConfig.h"
|
||||
#include "ThreatCostCalculator.h"
|
||||
|
||||
// Aggregate of all simulation config files. Loaded at startup and reloaded
|
||||
@@ -18,5 +19,6 @@ struct GameConfig
|
||||
ShipsConfig ships;
|
||||
StationsConfig stations;
|
||||
ModulesConfig modules;
|
||||
UnlocksConfig unlocks;
|
||||
ThreatCostTable threatCosts;
|
||||
};
|
||||
|
||||
@@ -40,10 +40,6 @@ struct ModuleRepairCapability
|
||||
struct ModuleDef
|
||||
{
|
||||
std::string id;
|
||||
int unlockAtStationLevel;
|
||||
// Prerequisite schematic ids that must be explicitly unlocked before this
|
||||
// schematic can enter the drop pool (REQ-LOCK-PREREQ). Empty = none.
|
||||
std::vector<std::string> unlockRequires;
|
||||
std::vector<std::string> surfaceMask;
|
||||
std::vector<RecipeIngredient> materials;
|
||||
double productionTimeSeconds;
|
||||
|
||||
@@ -32,14 +32,12 @@ struct RecipeDef
|
||||
std::vector<RecipeIngredient> inputs;
|
||||
std::vector<RecipeOutput> outputs;
|
||||
double durationSeconds;
|
||||
// Assembler only. nullopt = implicit-only locking. -1 = explicitly unlocked
|
||||
// at game start. >= 0 = locked; schematic enters drop pool at that station
|
||||
// level once the output item is implicitly unlocked (REQ-LOCK-EXPLICIT).
|
||||
std::optional<int> unlockAtStationLevel;
|
||||
// Assembler recipe schematics only. Prerequisite schematic ids that must be
|
||||
// explicitly unlocked before this schematic can enter the drop pool
|
||||
// (REQ-LOCK-PREREQ). Empty = none.
|
||||
std::vector<std::string> unlockRequires;
|
||||
// Assembler only. When true, this recipe is available from game start
|
||||
// regardless of the implicit item graph — used for base recipes that no
|
||||
// schematic's materials reach (e.g. building blocks). See REQ-LOCK-IMPLICIT.
|
||||
// Otherwise an assembler recipe is either explicitly gated (granted by an
|
||||
// unlock group, REQ-LOCK-EXPLICIT) or implicitly gated via the item graph.
|
||||
bool unlockedAtStart = false;
|
||||
};
|
||||
|
||||
struct RecipesConfig
|
||||
|
||||
@@ -35,10 +35,6 @@ struct ShipSensor
|
||||
struct ShipDef
|
||||
{
|
||||
std::string id;
|
||||
int unlockAtStationLevel;
|
||||
// Prerequisite schematic ids that must be explicitly unlocked before this
|
||||
// schematic can enter the drop pool (REQ-LOCK-PREREQ). Empty = none.
|
||||
std::vector<std::string> unlockRequires;
|
||||
std::vector<std::string> layout;
|
||||
|
||||
ShipSchematic schematic;
|
||||
|
||||
26
src/lib/config/UnlocksConfig.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// A single [[unlock]] entry from unlocks.toml — an unlock group, the unit of
|
||||
// loot awarded by defence station drops (REQ-DEF-SCHEMATIC-DROP,
|
||||
// REQ-LOCK-EXPLICIT). Awarding a group unlocks all of its granted members at
|
||||
// once. Anything not granted by any group is available from game start.
|
||||
struct UnlockGroupDef
|
||||
{
|
||||
std::string id; // Unique unlock-group id.
|
||||
int stationLevel; // Min destroyed station level to become eligible.
|
||||
std::vector<std::string> requiredGroupIds; // Prerequisite unlock-group ids (REQ-LOCK-PREREQ).
|
||||
|
||||
// Granted ids by kind (each defaults to empty; a group grants >= 1 item).
|
||||
std::vector<std::string> ships;
|
||||
std::vector<std::string> modules;
|
||||
std::vector<std::string> buildings;
|
||||
std::vector<std::string> recipes; // Assembler recipe ids only.
|
||||
};
|
||||
|
||||
struct UnlocksConfig
|
||||
{
|
||||
std::vector<UnlockGroupDef> groups;
|
||||
};
|
||||
@@ -67,7 +67,8 @@ struct WorldScroll
|
||||
struct WorldConfig
|
||||
{
|
||||
int heightTiles; // REQ-GW-HEIGHT
|
||||
int refundPercentage; // REQ-BLD-DEMOLISH
|
||||
int refundPercentage; // REQ-BLD-DECONSTRUCT
|
||||
double deconstructionTimeSeconds; // REQ-BLD-DECON-QUEUE
|
||||
int startingBuildingBlocks; // REQ-HQ-STARTING-BLOCKS
|
||||
double scrapDespawnSeconds; // REQ-RES-SCRAP-DROP
|
||||
double scrapPerThreat; // REQ-RES-SCRAP-DROP, REQ-THREAT-SCRAP (scrap dropped per unit threat)
|
||||
@@ -82,6 +83,10 @@ struct WorldConfig
|
||||
// (REQ-UI-BLOCKS-TOOLTIP). Presentation-only; the simulation ignores it.
|
||||
std::optional<std::string> buildingBlocksTooltip;
|
||||
|
||||
// Optional hover-tooltip for the header artifact count display
|
||||
// (REQ-UI-ARTIFACTS-TOOLTIP). Presentation-only; the simulation ignores it.
|
||||
std::optional<std::string> artifactTooltip;
|
||||
|
||||
WorldRegions regions;
|
||||
WorldExpansion expansion;
|
||||
WorldPush push;
|
||||
|
||||
94
src/lib/core/BeltDragPath.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
#include "BeltDragPath.h"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace
|
||||
{
|
||||
int signOf(int value)
|
||||
{
|
||||
if (value > 0) { return 1; }
|
||||
if (value < 0) { return -1; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Direction stepping from one tile to an orthogonally adjacent tile.
|
||||
Rotation directionBetween(QPoint from, QPoint to)
|
||||
{
|
||||
const QPoint delta = to - from;
|
||||
if (delta.x() > 0) { return Rotation::East; }
|
||||
if (delta.x() < 0) { return Rotation::West; }
|
||||
if (delta.y() > 0) { return Rotation::South; }
|
||||
return Rotation::North;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<BeltPathTile> computeBeltDragPath(QPoint anchor, QPoint cursor,
|
||||
Rotation orientation)
|
||||
{
|
||||
const bool horizontalFirst =
|
||||
(orientation == Rotation::East || orientation == Rotation::West);
|
||||
|
||||
// Build the ordered tile coordinates: first leg along the primary axis to the
|
||||
// corner, then the orthogonal leg to the cursor (no duplicated corner tile).
|
||||
std::vector<QPoint> coords;
|
||||
if (horizontalFirst)
|
||||
{
|
||||
const int stepX = signOf(cursor.x() - anchor.x());
|
||||
for (int x = anchor.x(); ; x += stepX)
|
||||
{
|
||||
coords.push_back(QPoint(x, anchor.y()));
|
||||
if (x == cursor.x() || stepX == 0) { break; }
|
||||
}
|
||||
const int stepY = signOf(cursor.y() - anchor.y());
|
||||
if (stepY != 0)
|
||||
{
|
||||
for (int y = anchor.y() + stepY; ; y += stepY)
|
||||
{
|
||||
coords.push_back(QPoint(cursor.x(), y));
|
||||
if (y == cursor.y()) { break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const int stepY = signOf(cursor.y() - anchor.y());
|
||||
for (int y = anchor.y(); ; y += stepY)
|
||||
{
|
||||
coords.push_back(QPoint(anchor.x(), y));
|
||||
if (y == cursor.y() || stepY == 0) { break; }
|
||||
}
|
||||
const int stepX = signOf(cursor.x() - anchor.x());
|
||||
if (stepX != 0)
|
||||
{
|
||||
for (int x = anchor.x() + stepX; ; x += stepX)
|
||||
{
|
||||
coords.push_back(QPoint(x, cursor.y()));
|
||||
if (x == cursor.x()) { break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Assign each tile the direction toward the next tile; the last tile keeps its
|
||||
// incoming step direction, and a single-tile path keeps the belt orientation.
|
||||
std::vector<BeltPathTile> path;
|
||||
path.reserve(coords.size());
|
||||
const std::size_t count = coords.size();
|
||||
for (std::size_t index = 0; index < count; ++index)
|
||||
{
|
||||
Rotation rotation;
|
||||
if (count == 1)
|
||||
{
|
||||
rotation = orientation;
|
||||
}
|
||||
else if (index + 1 < count)
|
||||
{
|
||||
rotation = directionBetween(coords[index], coords[index + 1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
rotation = directionBetween(coords[index - 1], coords[index]);
|
||||
}
|
||||
path.push_back(BeltPathTile{ coords[index], rotation });
|
||||
}
|
||||
return path;
|
||||
}
|
||||
27
src/lib/core/BeltDragPath.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <QPoint>
|
||||
|
||||
#include "Rotation.h"
|
||||
|
||||
// One tile of a belt drag-placement path: the tile coordinate and the belt
|
||||
// orientation it should be given (REQ-BLD-BELT-DRAG).
|
||||
struct BeltPathTile
|
||||
{
|
||||
QPoint tile;
|
||||
Rotation rotation;
|
||||
};
|
||||
|
||||
// Computes the rectilinear (L-shaped) belt path from `anchor` to `cursor` for a
|
||||
// belt whose current orientation is `orientation` (REQ-BLD-BELT-DRAG). The path
|
||||
// first runs along the axis parallel to `orientation` (horizontal for East/West,
|
||||
// vertical for North/South), stepping toward the cursor's coordinate on that axis
|
||||
// to the corner tile, then runs along the orthogonal axis to the cursor tile. Each
|
||||
// tile is oriented to point toward the next tile along the path; the final tile
|
||||
// keeps the direction of its incoming step, and a single-tile path keeps
|
||||
// `orientation`. Returned tiles are ordered from anchor to cursor with no duplicate
|
||||
// corner tile.
|
||||
std::vector<BeltPathTile> computeBeltDragPath(QPoint anchor, QPoint cursor,
|
||||
Rotation orientation);
|
||||
@@ -11,6 +11,8 @@ SET(HDRS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Port.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/SchematicChoiceOption.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/DisplayName.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BeltDragPath.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TunnelCompletion.h
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
@@ -19,6 +21,8 @@ SET(SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BuildingType.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/EntityAdmin.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/DisplayName.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BeltDragPath.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TunnelCompletion.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
|
||||
@@ -3,23 +3,43 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// The kind of a single granted schematic within an unlock option.
|
||||
enum class SchematicType
|
||||
{
|
||||
Ship,
|
||||
Module,
|
||||
Recipe,
|
||||
Artifact
|
||||
Building,
|
||||
Recipe
|
||||
};
|
||||
|
||||
// One item granted by an unlock group (REQ-LOCK-EXPLICIT), shown in the
|
||||
// schematic choice dialog's granted-items list.
|
||||
struct GrantedSchematic
|
||||
{
|
||||
SchematicType type;
|
||||
std::string id;
|
||||
std::string displayName;
|
||||
};
|
||||
|
||||
// One option presented to the player in the schematic choice dialog
|
||||
// (REQ-DEF-SCHEMATIC-DROP). Built by the simulation when enemy stations are
|
||||
// destroyed; the UI reads these to populate the dialog.
|
||||
// destroyed; the UI reads these to populate the dialog. A non-artifact option
|
||||
// represents one unlock group; selecting it awards the whole group.
|
||||
struct SchematicChoiceOption
|
||||
{
|
||||
std::string schematicId;
|
||||
SchematicType type;
|
||||
bool isArtifact = false;
|
||||
|
||||
// Unlock group id (empty for the artifact option).
|
||||
std::string unlockGroupId;
|
||||
|
||||
// Display name shown as the option's title: the unlock group's derived name,
|
||||
// or "Artifact" for the artifact option.
|
||||
std::string displayName;
|
||||
|
||||
// The ships, modules, buildings, and assembler recipes this group grants
|
||||
// (empty for the artifact option).
|
||||
std::vector<GrantedSchematic> grantedItems;
|
||||
|
||||
// Ids of miner/assembler recipes that would newly become implicitly
|
||||
// unlocked (REQ-LOCK-IMPLICIT) if this option is selected. Sorted
|
||||
// alphabetically by display name; empty if none.
|
||||
|
||||
155
src/lib/core/TunnelCompletion.cpp
Normal file
@@ -0,0 +1,155 @@
|
||||
#include "TunnelCompletion.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
QPoint stepTile(QPoint tile, Rotation dir)
|
||||
{
|
||||
switch (dir)
|
||||
{
|
||||
case Rotation::North: return {tile.x(), tile.y() - 1};
|
||||
case Rotation::East: return {tile.x() + 1, tile.y() };
|
||||
case Rotation::South: return {tile.x(), tile.y() + 1};
|
||||
case Rotation::West: return {tile.x() - 1, tile.y() };
|
||||
}
|
||||
return tile;
|
||||
}
|
||||
|
||||
Rotation oppositeRotation(Rotation dir)
|
||||
{
|
||||
switch (dir)
|
||||
{
|
||||
case Rotation::North: return Rotation::South;
|
||||
case Rotation::East: return Rotation::West;
|
||||
case Rotation::South: return Rotation::North;
|
||||
case Rotation::West: return Rotation::East;
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
float tileCenterDistanceSq(QPoint tile, QVector2D cursorWorldPos)
|
||||
{
|
||||
const QVector2D center(static_cast<float>(tile.x()) + 0.5f,
|
||||
static_cast<float>(tile.y()) + 0.5f);
|
||||
return (center - cursorWorldPos).lengthSquared();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::optional<QPoint> firstTunnelFacing(const TunnelLookup& lookup, QPoint start,
|
||||
Rotation stepDir, Rotation targetFacing,
|
||||
int maxDistance)
|
||||
{
|
||||
QPoint probe = start;
|
||||
for (int distance = 1; distance <= maxDistance; ++distance)
|
||||
{
|
||||
probe = stepTile(probe, stepDir);
|
||||
const std::optional<TunnelTileInfo> info = lookup(probe);
|
||||
if (info.has_value() && info->rotation == targetFacing)
|
||||
{
|
||||
return probe;
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
TunnelCompletion resolveTunnelCompletion(const TunnelLookup& lookup, QPoint hoverTile,
|
||||
Rotation rotation, int maxDistance,
|
||||
QVector2D cursorWorldPos)
|
||||
{
|
||||
// Entry-completion: a hypothetical entry at the hovered tile searches ahead (its
|
||||
// facing direction) for a same-direction exit to pair with. The first
|
||||
// same-direction tunnel ahead completes the entry only if it is an exit.
|
||||
std::optional<QPoint> exitPartner;
|
||||
if (const std::optional<QPoint> ahead =
|
||||
firstTunnelFacing(lookup, hoverTile, rotation, rotation, maxDistance);
|
||||
ahead.has_value())
|
||||
{
|
||||
const std::optional<TunnelTileInfo> info = lookup(*ahead);
|
||||
if (info.has_value() && info->type == BuildingType::TunnelExit)
|
||||
{
|
||||
exitPartner = ahead;
|
||||
}
|
||||
}
|
||||
|
||||
// Exit-completion: a hypothetical exit at the hovered tile pairs with an existing
|
||||
// entry behind it — one whose forward search (its facing direction) reaches the
|
||||
// hovered tile as its first same-direction tunnel. Scanning backwards, the first
|
||||
// same-direction tunnel completes the exit only if it is an entry.
|
||||
std::optional<QPoint> entryPartner;
|
||||
if (const std::optional<QPoint> behind =
|
||||
firstTunnelFacing(lookup, hoverTile, oppositeRotation(rotation), rotation,
|
||||
maxDistance);
|
||||
behind.has_value())
|
||||
{
|
||||
const std::optional<TunnelTileInfo> info = lookup(*behind);
|
||||
if (info.has_value() && info->type == BuildingType::TunnelEntry)
|
||||
{
|
||||
entryPartner = behind;
|
||||
}
|
||||
}
|
||||
|
||||
// Default: a TunnelEntry with no partner.
|
||||
if (!entryPartner.has_value() && !exitPartner.has_value())
|
||||
{
|
||||
return TunnelCompletion{BuildingType::TunnelEntry, std::nullopt};
|
||||
}
|
||||
if (entryPartner.has_value() && !exitPartner.has_value())
|
||||
{
|
||||
return TunnelCompletion{BuildingType::TunnelExit, entryPartner};
|
||||
}
|
||||
if (exitPartner.has_value() && !entryPartner.has_value())
|
||||
{
|
||||
return TunnelCompletion{BuildingType::TunnelEntry, exitPartner};
|
||||
}
|
||||
|
||||
// Both apply: complete whichever existing partner is closer to the sub-tile
|
||||
// cursor position (REQ-BLD-TUNNEL-MODE).
|
||||
const float entryDistanceSq = tileCenterDistanceSq(*entryPartner, cursorWorldPos);
|
||||
const float exitDistanceSq = tileCenterDistanceSq(*exitPartner, cursorWorldPos);
|
||||
if (entryDistanceSq <= exitDistanceSq)
|
||||
{
|
||||
return TunnelCompletion{BuildingType::TunnelExit, entryPartner};
|
||||
}
|
||||
return TunnelCompletion{BuildingType::TunnelEntry, exitPartner};
|
||||
}
|
||||
|
||||
std::optional<QPoint> findTunnelPartner(const TunnelLookup& lookup, QPoint tile,
|
||||
BuildingType type, Rotation rotation,
|
||||
int maxDistance)
|
||||
{
|
||||
if (type == BuildingType::TunnelEntry)
|
||||
{
|
||||
// An entry pairs with the first same-direction tunnel ahead, if it is an exit.
|
||||
const std::optional<QPoint> ahead =
|
||||
firstTunnelFacing(lookup, tile, rotation, rotation, maxDistance);
|
||||
if (ahead.has_value())
|
||||
{
|
||||
const std::optional<TunnelTileInfo> info = lookup(*ahead);
|
||||
if (info.has_value() && info->type == BuildingType::TunnelExit)
|
||||
{
|
||||
return ahead;
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (type == BuildingType::TunnelExit)
|
||||
{
|
||||
// An exit is claimed by the first same-direction tunnel behind it, if it is an
|
||||
// entry (its forward search reaches this exit as its first same-direction tunnel).
|
||||
const std::optional<QPoint> behind =
|
||||
firstTunnelFacing(lookup, tile, oppositeRotation(rotation), rotation, maxDistance);
|
||||
if (behind.has_value())
|
||||
{
|
||||
const std::optional<TunnelTileInfo> info = lookup(*behind);
|
||||
if (info.has_value() && info->type == BuildingType::TunnelEntry)
|
||||
{
|
||||
return behind;
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
66
src/lib/core/TunnelCompletion.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
|
||||
#include <QPoint>
|
||||
#include <QVector2D>
|
||||
|
||||
#include "BuildingType.h"
|
||||
#include "Rotation.h"
|
||||
|
||||
// A tunnel building occupying a single tile: whether it is an entry or an exit and
|
||||
// the direction it faces. Used by the tunnel pairing scan (REQ-BLD-TUNNEL-PAIR) and
|
||||
// the unified tunnel build mode (REQ-BLD-TUNNEL-MODE).
|
||||
struct TunnelTileInfo
|
||||
{
|
||||
BuildingType type; // TunnelEntry or TunnelExit
|
||||
Rotation rotation; // facing direction
|
||||
};
|
||||
|
||||
// Given a tile, returns the tunnel building on it (entry or exit) with its facing
|
||||
// direction, or std::nullopt when the tile holds no tunnel building.
|
||||
using TunnelLookup = std::function<std::optional<TunnelTileInfo>(QPoint)>;
|
||||
|
||||
// Steps from `start` in `stepDir` over the tiles at distance 1..maxDistance and
|
||||
// returns the first tile whose tunnel faces `targetFacing`. Tunnel buildings facing
|
||||
// any other direction are skipped, mirroring the "stop at the first same-direction
|
||||
// tunnel" rule of REQ-BLD-TUNNEL-PAIR. Returns std::nullopt if none is found in range.
|
||||
std::optional<QPoint> firstTunnelFacing(const TunnelLookup& lookup, QPoint start,
|
||||
Rotation stepDir, Rotation targetFacing,
|
||||
int maxDistance);
|
||||
|
||||
// Result of resolving which tunnel end the ghost should become at a hovered tile
|
||||
// (REQ-BLD-TUNNEL-MODE): the type to place and the existing tunnel it would complete.
|
||||
struct TunnelCompletion
|
||||
{
|
||||
BuildingType resolvedType; // TunnelEntry (default) or TunnelExit
|
||||
std::optional<QPoint> partnerTile; // matched existing tunnel, if any
|
||||
};
|
||||
|
||||
// Resolves the tunnel ghost type for a hover at `hoverTile` with the ghost facing
|
||||
// `rotation` (REQ-BLD-TUNNEL-MODE):
|
||||
// - exit-completion: placing an exit here would pair with an existing entry behind
|
||||
// it (the entry's forward search reaches this tile as its first same-direction
|
||||
// tunnel) — the ghost becomes a TunnelExit;
|
||||
// - entry-completion: placing an entry here would pair with an existing exit ahead
|
||||
// of it — the ghost stays a TunnelEntry.
|
||||
// When both apply, the end whose existing partner is closer to `cursorWorldPos` (the
|
||||
// sub-tile cursor position in world tile units) wins, so nudging the cursor within a
|
||||
// single tile can flip the target. With no match the ghost stays a TunnelEntry with
|
||||
// no partner.
|
||||
TunnelCompletion resolveTunnelCompletion(const TunnelLookup& lookup, QPoint hoverTile,
|
||||
Rotation rotation, int maxDistance,
|
||||
QVector2D cursorWorldPos);
|
||||
|
||||
// Finds the matching end of an existing tunnel building at `tile` of the given `type`
|
||||
// (TunnelEntry or TunnelExit) facing `rotation`, applying the pairing scan of
|
||||
// REQ-BLD-TUNNEL-PAIR over `lookup`:
|
||||
// - for an entry, the first same-direction tunnel along its facing direction, if it
|
||||
// is an exit;
|
||||
// - for an exit, the first same-direction tunnel opposite its facing direction, if it
|
||||
// is an entry.
|
||||
// Returns the partner tile, or std::nullopt when the tunnel is unpaired.
|
||||
std::optional<QPoint> findTunnelPartner(const TunnelLookup& lookup, QPoint tile,
|
||||
BuildingType type, Rotation rotation,
|
||||
int maxDistance);
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "BuildingId.h"
|
||||
|
||||
// Deliver-scrap behavior (one half of the old SalvageBehaviorComponent). Scored
|
||||
@@ -7,6 +9,6 @@
|
||||
// SalvagerSystem performs the actual delivery.
|
||||
struct DeliverScrapBehavior
|
||||
{
|
||||
BuildingId deliveryBay = kInvalidBuildingId;
|
||||
float score = 0.0f;
|
||||
std::optional<BuildingId> deliveryBay; // nullopt until a bay is assigned
|
||||
float score = 0.0f;
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ void SalvagerSystem::tick(Tick currentTick, ScrapSystem& scraps, BuildingSystem&
|
||||
// Apply collections whose mid-beam delay has elapsed (cycles started earlier).
|
||||
applyPendingCollections(currentTick, scraps);
|
||||
|
||||
const std::vector<ScrapInfo> allScrap = scraps.allScrapInfo();
|
||||
const std::vector<ScrapInfo> allScrap = scraps.getAllScrapInfo();
|
||||
|
||||
// Tick down per-module collection cooldowns.
|
||||
m_admin.forEach<SalvagerComponent>(
|
||||
@@ -88,8 +88,8 @@ void SalvagerSystem::tick(Tick currentTick, ScrapSystem& scraps, BuildingSystem&
|
||||
m_admin.forEach<DeliverScrapBehavior, PositionComponent>(
|
||||
[&](entt::entity ship, const DeliverScrapBehavior& deliver, const PositionComponent& pos)
|
||||
{
|
||||
if (deliver.deliveryBay == kInvalidBuildingId) { return; }
|
||||
const Building* bay = buildings.findBuilding(deliver.deliveryBay);
|
||||
if (!deliver.deliveryBay.has_value()) { return; }
|
||||
const Building* bay = buildings.findBuilding(*deliver.deliveryBay);
|
||||
if (!bay) { return; }
|
||||
|
||||
const QVector2D bayCenter(bay->anchor.x() + bay->footprint.width() / 2.0f,
|
||||
@@ -100,7 +100,7 @@ void SalvagerSystem::tick(Tick currentTick, ScrapSystem& scraps, BuildingSystem&
|
||||
if (!m_admin.hasAll<CargoComponent>(ship)) { return; }
|
||||
CargoComponent& cargo = m_admin.get<CargoComponent>(ship);
|
||||
if (cargo.current <= 0) { return; }
|
||||
if (buildings.deliverScrapToSalvageBay(deliver.deliveryBay))
|
||||
if (buildings.deliverScrapToSalvageBay(*deliver.deliveryBay))
|
||||
{
|
||||
--cargo.current;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ bool ScrapSystem::collectOne(entt::entity entity)
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<ScrapInfo> ScrapSystem::allScrapInfo() const
|
||||
std::vector<ScrapInfo> ScrapSystem::getAllScrapInfo() const
|
||||
{
|
||||
std::vector<ScrapInfo> result;
|
||||
m_admin.forEach<ScrapDataComponent>(
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
bool collectOne(entt::entity entity);
|
||||
|
||||
// Lightweight snapshot for callers that need to iterate all scrap.
|
||||
std::vector<ScrapInfo> allScrapInfo() const;
|
||||
std::vector<ScrapInfo> getAllScrapInfo() const;
|
||||
|
||||
private:
|
||||
EntityAdmin& m_admin;
|
||||
|
||||
@@ -398,8 +398,7 @@ entt::entity ShipSystem::spawn(const std::string& schematicId,
|
||||
maxCollRange * static_cast<float>(m_config.world.orbitFactor);
|
||||
m_admin.addComponent<SalvageScrapBehavior>(entity, salvage);
|
||||
|
||||
DeliverScrapBehavior deliver;
|
||||
deliver.deliveryBay = kInvalidBuildingId;
|
||||
DeliverScrapBehavior deliver; // deliveryBay starts unassigned (nullopt)
|
||||
m_admin.addComponent<DeliverScrapBehavior>(entity, deliver);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ void DeliverScrapEvaluator::evaluate(EntityAdmin& admin, const BuildingSystem& b
|
||||
}
|
||||
|
||||
// Assign nearest SalvageBay if not yet assigned.
|
||||
if (deliver.deliveryBay == kInvalidBuildingId)
|
||||
if (!deliver.deliveryBay.has_value())
|
||||
{
|
||||
const Building* bay =
|
||||
buildings.findNearestBuilding(pos.value, BuildingType::SalvageBay);
|
||||
|
||||
@@ -24,9 +24,9 @@ void DeliverScrapExecutor::execute(EntityAdmin& admin, const BuildingSystem& bui
|
||||
if (selected.winner != BehaviorKind::DeliverScrap) { return; }
|
||||
|
||||
QVector2D dest = pos.value;
|
||||
if (deliver.deliveryBay != kInvalidBuildingId)
|
||||
if (deliver.deliveryBay.has_value())
|
||||
{
|
||||
const Building* bay = buildings.findBuilding(deliver.deliveryBay);
|
||||
const Building* bay = buildings.findBuilding(*deliver.deliveryBay);
|
||||
if (bay)
|
||||
{
|
||||
dest = QVector2D(bay->anchor.x() + bay->footprint.width() / 2.0f,
|
||||
|
||||
@@ -19,7 +19,7 @@ void SalvageScrapEvaluator::evaluate(EntityAdmin& admin, const ScrapSystem& scra
|
||||
{
|
||||
TRACE();
|
||||
const std::unordered_map<entt::entity, CargoState> cargoByShip = buildCargoByShip(admin);
|
||||
const std::vector<ScrapInfo> allScrap = scraps.allScrapInfo();
|
||||
const std::vector<ScrapInfo> allScrap = scraps.getAllScrapInfo();
|
||||
|
||||
admin.forEach<SalvageScrapBehavior, PositionComponent, SensorRangeComponent>(
|
||||
[&](entt::entity e, SalvageScrapBehavior& salvage, const PositionComponent& pos,
|
||||
|
||||
@@ -4,7 +4,7 @@ SET(HDRS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TickAdvancedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BuildingBlocksChangedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ExpansionCostChangedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/EntitySelectedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/EntitySelectionChangedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/GameSpeedChangedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BossWaveUpdatedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/SchematicChoicesAvailableEvent.h
|
||||
@@ -12,14 +12,15 @@ SET(HDRS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/GameOverEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/WinEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ArtifactCountChangedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/UnlockedBuildingsChangedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BuilderModeExitedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BlueprintModeExitedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/EscapeMenuRequestedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/DemolishModeChangedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/DeconstructModeChangedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BuildingTypeSelectedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BuildHotkeyPressedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ExitBuilderModeRequestedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/DemolishModeToggleRequestedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/DeconstructModeToggleRequestedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BlueprintPlacementRequestedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ExitBlueprintModeRequestedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/TemporaryBlueprintRequestedEvent.h
|
||||
|
||||
10
src/lib/eventsystem/event/DeconstructModeChangedEvent.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "Event.h"
|
||||
|
||||
class DeconstructModeChangedEvent : public Event
|
||||
{
|
||||
public:
|
||||
explicit DeconstructModeChangedEvent(bool active) : active(active) {}
|
||||
const bool active;
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Event.h"
|
||||
|
||||
class DeconstructModeToggleRequestedEvent : public Event
|
||||
{
|
||||
};
|
||||
@@ -1,10 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Event.h"
|
||||
|
||||
class DemolishModeChangedEvent : public Event
|
||||
{
|
||||
public:
|
||||
explicit DemolishModeChangedEvent(bool active) : active(active) {}
|
||||
const bool active;
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Event.h"
|
||||
|
||||
class DemolishModeToggleRequestedEvent : public Event
|
||||
{
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
#ifndef ENTITY_SELECTED_EVENT_H
|
||||
#define ENTITY_SELECTED_EVENT_H
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "entt/entity/entity.hpp"
|
||||
|
||||
#include "Event.h"
|
||||
|
||||
class EntitySelectedEvent : public Event
|
||||
{
|
||||
public:
|
||||
explicit EntitySelectedEvent(std::optional<entt::entity> entity)
|
||||
: entity(entity)
|
||||
{
|
||||
}
|
||||
|
||||
const std::optional<entt::entity> entity;
|
||||
};
|
||||
|
||||
#endif // ENTITY_SELECTED_EVENT_H
|
||||
25
src/lib/eventsystem/event/EntitySelectionChangedEvent.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef ENTITY_SELECTION_CHANGED_EVENT_H
|
||||
#define ENTITY_SELECTION_CHANGED_EVENT_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "entt/entity/entity.hpp"
|
||||
|
||||
#include "Event.h"
|
||||
|
||||
// The set of currently selected ships and/or defence stations. An empty list means
|
||||
// no actor is selected. Actors share the "field" selection category with scrap piles
|
||||
// (REQ-UI-SELECTION-CATEGORIES): they can be selected together, but never together with
|
||||
// buildings.
|
||||
class EntitySelectionChangedEvent : public Event
|
||||
{
|
||||
public:
|
||||
explicit EntitySelectionChangedEvent(std::vector<entt::entity> entities)
|
||||
: entities(std::move(entities))
|
||||
{
|
||||
}
|
||||
|
||||
const std::vector<entt::entity> entities;
|
||||
};
|
||||
|
||||
#endif // ENTITY_SELECTION_CHANGED_EVENT_H
|
||||
13
src/lib/eventsystem/event/UnlockedBuildingsChangedEvent.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef UNLOCKED_BUILDINGS_CHANGED_EVENT_H
|
||||
#define UNLOCKED_BUILDINGS_CHANGED_EVENT_H
|
||||
|
||||
#include "Event.h"
|
||||
|
||||
// Emitted when the set of unlocked building types changes (REQ-LOCK-BUILDING),
|
||||
// i.e. after an unlock group granting a building is awarded (REQ-DEF-SCHEMATIC-DROP)
|
||||
// or on Restart. The build button grid re-evaluates which buttons are shown.
|
||||
class UnlockedBuildingsChangedEvent : public Event
|
||||
{
|
||||
};
|
||||
|
||||
#endif // UNLOCKED_BUILDINGS_CHANGED_EVENT_H
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "StateChecksum.h"
|
||||
#include "Tick.h"
|
||||
#include "TunnelCompletion.h"
|
||||
#include "tracing.h"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -177,55 +178,57 @@ void BeltSystem::reevaluateTunnelPairing()
|
||||
std::vector<TunnelLink> oldLinks;
|
||||
std::swap(oldLinks, m_tunnelLinks);
|
||||
|
||||
// Tunnel index over this system's own (completed) tunnel tiles, shared with the
|
||||
// scan primitive so the pairing rule lives in one place (REQ-BLD-TUNNEL-PAIR).
|
||||
const TunnelLookup lookup = [this](QPoint tile) -> std::optional<TunnelTileInfo>
|
||||
{
|
||||
const std::map<std::pair<int, int>, TunnelEntryTile>::const_iterator teIt =
|
||||
m_tunnelEntries.find(key(tile));
|
||||
if (teIt != m_tunnelEntries.end())
|
||||
{
|
||||
return TunnelTileInfo{BuildingType::TunnelEntry, teIt->second.direction};
|
||||
}
|
||||
const std::map<std::pair<int, int>, TunnelExitTile>::const_iterator txIt =
|
||||
m_tunnelExits.find(key(tile));
|
||||
if (txIt != m_tunnelExits.end())
|
||||
{
|
||||
return TunnelTileInfo{BuildingType::TunnelExit, txIt->second.direction};
|
||||
}
|
||||
return std::nullopt;
|
||||
};
|
||||
|
||||
for (const std::pair<const std::pair<int, int>, TunnelEntryTile>& entry : m_tunnelEntries)
|
||||
{
|
||||
const QPoint entryPos(entry.first.first, entry.first.second);
|
||||
const Rotation dir = entry.second.direction;
|
||||
const int maxDist = entry.second.maxDistance;
|
||||
|
||||
for (int d = 1; d <= maxDist; ++d)
|
||||
// The first same-direction tunnel ahead forms a pair only when it is an exit;
|
||||
// a same-direction entry blocks (firstTunnelFacing stops at it either way).
|
||||
const std::optional<QPoint> target =
|
||||
firstTunnelFacing(lookup, entryPos, dir, dir, maxDist);
|
||||
if (!target.has_value() || m_tunnelExits.find(key(*target)) == m_tunnelExits.end())
|
||||
{
|
||||
QPoint probe = entryPos;
|
||||
for (int step = 0; step < d; ++step)
|
||||
{
|
||||
probe = adjacentTile(probe, dir);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if a same-direction tunnel entry is here (blocks pairing)
|
||||
const std::map<std::pair<int, int>, TunnelEntryTile>::const_iterator teIt =
|
||||
m_tunnelEntries.find(key(probe));
|
||||
if (teIt != m_tunnelEntries.end() && teIt->second.direction == dir)
|
||||
TunnelLink link;
|
||||
link.entryTile = entryPos;
|
||||
link.exitTile = *target;
|
||||
// The exit is colinear with the entry along `dir`, so the tile-coordinate
|
||||
// distance is the Manhattan distance.
|
||||
link.length = static_cast<double>((*target - entryPos).manhattanLength());
|
||||
|
||||
for (const TunnelLink& old : oldLinks)
|
||||
{
|
||||
if (old.entryTile == entryPos && old.exitTile == *target)
|
||||
{
|
||||
link.items = old.items;
|
||||
break;
|
||||
}
|
||||
|
||||
// Check if a same-direction tunnel exit is here (forms pair)
|
||||
const std::map<std::pair<int, int>, TunnelExitTile>::const_iterator txIt =
|
||||
m_tunnelExits.find(key(probe));
|
||||
if (txIt != m_tunnelExits.end())
|
||||
{
|
||||
if (txIt->second.direction == dir)
|
||||
{
|
||||
TunnelLink link;
|
||||
link.entryTile = entryPos;
|
||||
link.exitTile = probe;
|
||||
link.length = static_cast<double>(d);
|
||||
|
||||
for (const TunnelLink& old : oldLinks)
|
||||
{
|
||||
if (old.entryTile == entryPos && old.exitTile == probe)
|
||||
{
|
||||
link.items = old.items;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_tunnelLinks.push_back(std::move(link));
|
||||
break;
|
||||
}
|
||||
// Different direction exit — skip, keep searching
|
||||
}
|
||||
}
|
||||
|
||||
m_tunnelLinks.push_back(std::move(link));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
// tile are held and routed to one of the two outputs.
|
||||
void placeSplitter(QPoint tile, Rotation outputA, Rotation outputB);
|
||||
|
||||
// Remove a belt or splitter tile (on demolish). Items are discarded.
|
||||
// Remove a belt or splitter tile (on deconstruct). Items are discarded.
|
||||
void removeTile(QPoint tile);
|
||||
|
||||
// -- Splitter filter configuration (REQ-BLD-SPLITTER) -------------------
|
||||
|
||||
@@ -86,7 +86,7 @@ struct Building
|
||||
// Total items held on the output side: buffered plus still-emerging. The
|
||||
// output-buffer capacity rule (REQ-MAT-OUTPUT-BUFFER) counts emerging items,
|
||||
// since they have not yet left the building.
|
||||
int outputItemCount() const
|
||||
int getOutputItemCount() const
|
||||
{
|
||||
int count = static_cast<int>(outputBuffer.items.size());
|
||||
for (const std::vector<BeltItemSlot>& lane : emergingItems)
|
||||
@@ -129,5 +129,10 @@ struct Building
|
||||
|
||||
// Module layout for shipyards (REQ-MOD-LAYOUT).
|
||||
std::optional<ShipLayoutConfig> shipLayout;
|
||||
|
||||
// True while this building sits in the deconstruction queue (REQ-BLD-DECON-QUEUE).
|
||||
// A queued building stops operating immediately (all tick loops skip it) but keeps
|
||||
// occupying its tiles until its deconstruction completes.
|
||||
bool queuedForDeconstruction = false;
|
||||
};
|
||||
|
||||
|
||||
@@ -26,15 +26,15 @@ struct SelectedBuilding
|
||||
// (the HQ and defence stations, per REQ-UI-BLUEPRINT-CREATE).
|
||||
std::optional<SelectedBuilding> resolvePlaceable(const Simulation& sim, BuildingId id)
|
||||
{
|
||||
const Building* building = sim.buildings().findBuilding(id);
|
||||
const ConstructionSite* site = building ? nullptr : sim.buildings().findSite(id);
|
||||
const Building* building = sim.getBuildings().findBuilding(id);
|
||||
const ConstructionSite* site = building ? nullptr : sim.getBuildings().findSite(id);
|
||||
if (!building && !site)
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const BuildingType type = building ? building->type : site->type;
|
||||
const BuildingDef* def = sim.config().buildings.findBuildingDef(type);
|
||||
const BuildingDef* def = sim.getConfig().buildings.findBuildingDef(type);
|
||||
if (!def || !def->playerPlaceable)
|
||||
{
|
||||
return std::nullopt;
|
||||
@@ -52,8 +52,8 @@ std::optional<SelectedBuilding> resolvePlaceable(const Simulation& sim, Building
|
||||
|
||||
std::optional<BuildingConfig> readBuildingConfig(const Simulation& sim, BuildingId id)
|
||||
{
|
||||
const Building* building = sim.buildings().findBuilding(id);
|
||||
const ConstructionSite* site = building ? nullptr : sim.buildings().findSite(id);
|
||||
const Building* building = sim.getBuildings().findBuilding(id);
|
||||
const ConstructionSite* site = building ? nullptr : sim.getBuildings().findSite(id);
|
||||
if (!building && !site)
|
||||
{
|
||||
return std::nullopt;
|
||||
@@ -77,7 +77,7 @@ std::optional<BuildingConfig> readBuildingConfig(const Simulation& sim, Building
|
||||
{
|
||||
// Operational splitter filters live in the BeltSystem, keyed by tile.
|
||||
const std::optional<BeltSystem::SplitterInfo> info =
|
||||
sim.belts().getSplitterInfo(building->anchor);
|
||||
sim.getBelts().getSplitterInfo(building->anchor);
|
||||
if (info.has_value())
|
||||
{
|
||||
config.splitterFilterA = info->filterA;
|
||||
|
||||
@@ -21,6 +21,17 @@ bool isAutoRecipeBuildingType(BuildingType type)
|
||||
|| type == BuildingType::ReprocessingPlant;
|
||||
}
|
||||
|
||||
// Belts, splitters, and tunnel ends keep their runtime data in the belt subsystem
|
||||
// rather than in the Building instance, so placing/removing them must register or
|
||||
// unregister a tile with BeltSystem.
|
||||
bool isBeltSubsystemType(BuildingType type)
|
||||
{
|
||||
return type == BuildingType::Belt
|
||||
|| type == BuildingType::Splitter
|
||||
|| type == BuildingType::TunnelEntry
|
||||
|| type == BuildingType::TunnelExit;
|
||||
}
|
||||
|
||||
// The building body tile that owns an output port, given the port's outside tile
|
||||
// (port.tile) and its facing direction. The virtual output belt occupies this tile
|
||||
// and flows toward port.tile (REQ-MAT-OUTPUT-EMERGE).
|
||||
@@ -267,16 +278,23 @@ void BuildingSystem::initSalvageBayBuffer(Building& b) const
|
||||
}
|
||||
|
||||
std::vector<Port> BuildingSystem::computeInputPorts(const Building& b) const
|
||||
{
|
||||
return computeInputPorts(b.bodyCells, b.outputPorts);
|
||||
}
|
||||
|
||||
std::vector<Port> BuildingSystem::computeInputPorts(
|
||||
const std::vector<QPoint>& bodyCells,
|
||||
const std::vector<Port>& outputPorts) const
|
||||
{
|
||||
// Build lookup sets for quick membership checks.
|
||||
std::set<std::pair<int, int>> bodySet;
|
||||
for (const QPoint& cell : b.bodyCells)
|
||||
for (const QPoint& cell : bodyCells)
|
||||
{
|
||||
bodySet.insert({cell.x(), cell.y()});
|
||||
}
|
||||
|
||||
std::set<std::pair<int, int>> outputPortTiles;
|
||||
for (const Port& port : b.outputPorts)
|
||||
for (const Port& port : outputPorts)
|
||||
{
|
||||
outputPortTiles.insert({port.tile.x(), port.tile.y()});
|
||||
}
|
||||
@@ -294,7 +312,7 @@ std::vector<Port> BuildingSystem::computeInputPorts(const Building& b) const
|
||||
std::set<std::pair<int, int>> seen;
|
||||
std::vector<Port> inputPorts;
|
||||
|
||||
for (const QPoint& cell : b.bodyCells)
|
||||
for (const QPoint& cell : bodyCells)
|
||||
{
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
@@ -317,6 +335,30 @@ std::vector<Port> BuildingSystem::computeInputPorts(const Building& b) const
|
||||
return inputPorts;
|
||||
}
|
||||
|
||||
std::vector<Port> BuildingSystem::getInputPorts(BuildingId id) const
|
||||
{
|
||||
if (const Building* building = findBuilding(id))
|
||||
{
|
||||
return building->inputPorts;
|
||||
}
|
||||
if (const ConstructionSite* site = findSite(id))
|
||||
{
|
||||
// A site stores no ports; derive its output ports from the mask (absolute)
|
||||
// and run the same input-edge scan (REQ-BLD-BELT-DRAG, REQ-MAT-INPUT-PORTS).
|
||||
const BuildingDef* def = findBuildingDef(site->type);
|
||||
if (def == nullptr) { return {}; }
|
||||
const ParsedSurfaceMask mask = parseSurfaceMask(def->surfaceMask, site->rotation);
|
||||
std::vector<Port> outputPortsAbsolute;
|
||||
outputPortsAbsolute.reserve(mask.outputPorts.size());
|
||||
for (const Port& port : mask.outputPorts)
|
||||
{
|
||||
outputPortsAbsolute.push_back(Port{ site->anchor + port.tile, port.direction });
|
||||
}
|
||||
return computeInputPorts(site->bodyCells, outputPortsAbsolute);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<Item> BuildingSystem::rollReprocessingOutput(const RecipeDef& recipe)
|
||||
{
|
||||
std::vector<const RecipeOutput*> eligible;
|
||||
@@ -346,7 +388,7 @@ std::vector<Item> BuildingSystem::rollReprocessingOutput(const RecipeDef& recipe
|
||||
// Placement
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
BuildingId BuildingSystem::place(BuildingType type, QPoint anchor,
|
||||
std::optional<BuildingId> BuildingSystem::place(BuildingType type, QPoint anchor,
|
||||
Rotation rotation, Tick currentTick)
|
||||
{
|
||||
const BuildingDef* def = findBuildingDef(type);
|
||||
@@ -356,7 +398,7 @@ BuildingId BuildingSystem::place(BuildingType type, QPoint anchor,
|
||||
// Reject placements that fall outside the world (REQ-BLD-PLACE-VALID).
|
||||
if (!bodyCellsWithinWorldBounds(mask.bodyCells, anchor))
|
||||
{
|
||||
return kInvalidBuildingId;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const BuildingId id = m_allocateBuildingId();
|
||||
@@ -455,12 +497,13 @@ bool BuildingSystem::isPlacementValid(BuildingType type, QPoint anchor,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Demolish
|
||||
// Deconstruct
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
int BuildingSystem::demolish(BuildingId id)
|
||||
int BuildingSystem::deconstruct(BuildingId id, Tick currentTick)
|
||||
{
|
||||
// Construction queue?
|
||||
// Construction site? Removed instantly with the full refund; never queued
|
||||
// for deconstruction (REQ-BLD-DECONSTRUCT).
|
||||
for (std::deque<ConstructionSite>::iterator it = m_constructionQueue.begin();
|
||||
it != m_constructionQueue.end();
|
||||
++it)
|
||||
@@ -481,35 +524,60 @@ int BuildingSystem::demolish(BuildingId id)
|
||||
}
|
||||
}
|
||||
|
||||
// Operational building?
|
||||
for (std::vector<Building>::iterator it = m_buildings.begin();
|
||||
it != m_buildings.end();
|
||||
++it)
|
||||
// Operational building? Append it to the deconstruction queue rather than
|
||||
// removing it now; the partial refund is credited on completion in
|
||||
// tickDeconstruction (REQ-BLD-DECON-QUEUE).
|
||||
for (Building& building : m_buildings)
|
||||
{
|
||||
if (it->id == id)
|
||||
if (building.id != id) { continue; }
|
||||
if (building.queuedForDeconstruction) { return 0; } // already queued
|
||||
|
||||
building.queuedForDeconstruction = true;
|
||||
|
||||
DeconstructionEntry entry;
|
||||
entry.id = id;
|
||||
|
||||
// A queued belt/tunnel/splitter stops transporting at once: capture a
|
||||
// splitter's filters (so an un-queue can restore them), then unregister
|
||||
// its tile, discarding items on it and re-pairing tunnels as if it were
|
||||
// gone (REQ-BLD-TUNNEL-PAIR).
|
||||
if (building.type == BuildingType::Splitter)
|
||||
{
|
||||
if (it->type == BuildingType::Belt || it->type == BuildingType::Splitter
|
||||
|| it->type == BuildingType::TunnelEntry || it->type == BuildingType::TunnelExit)
|
||||
if (const std::optional<BeltSystem::SplitterInfo> info =
|
||||
m_belts.getSplitterInfo(building.anchor))
|
||||
{
|
||||
m_belts.removeTile(it->anchor);
|
||||
entry.splitterFilterA = info->filterA;
|
||||
entry.splitterFilterB = info->filterB;
|
||||
}
|
||||
const BuildingDef* def = findBuildingDef(it->type);
|
||||
for (const QPoint& cell : it->bodyCells)
|
||||
{
|
||||
m_tileOccupancy.erase({cell.x(), cell.y()});
|
||||
}
|
||||
m_buildings.erase(it);
|
||||
if (def)
|
||||
{
|
||||
return def->cost * m_config.world.refundPercentage / 100;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (isBeltSubsystemType(building.type))
|
||||
{
|
||||
m_belts.removeTile(building.anchor);
|
||||
}
|
||||
|
||||
const bool wasEmpty = m_deconstructionQueue.empty();
|
||||
m_deconstructionQueue.push_back(std::move(entry));
|
||||
if (wasEmpty)
|
||||
{
|
||||
startFrontDeconstruction(currentTick);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BuildingSystem::startFrontDeconstruction(Tick currentTick)
|
||||
{
|
||||
if (m_deconstructionQueue.empty()) { return; }
|
||||
DeconstructionEntry& front = m_deconstructionQueue.front();
|
||||
if (front.completesAt == 0)
|
||||
{
|
||||
front.completesAt =
|
||||
currentTick + secondsToTicks(m_config.world.deconstructionTimeSeconds);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Set recipe
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -749,31 +817,9 @@ void BuildingSystem::tickConstruction(Tick currentTick)
|
||||
}
|
||||
}
|
||||
|
||||
// Register with BeltSystem before the move (mask stays valid).
|
||||
if (front.type == BuildingType::Belt)
|
||||
{
|
||||
m_belts.placeBelt(front.anchor, front.rotation);
|
||||
}
|
||||
else if (front.type == BuildingType::Splitter)
|
||||
{
|
||||
assert(mask.outputPorts.size() >= 2);
|
||||
m_belts.placeSplitter(front.anchor,
|
||||
mask.outputPorts[0].direction,
|
||||
mask.outputPorts[1].direction);
|
||||
// Carry over any filters configured while under construction
|
||||
// (REQ-BLD-SITE-CONFIG).
|
||||
m_belts.setSplitterFilters(front.anchor,
|
||||
front.splitterFilterA,
|
||||
front.splitterFilterB);
|
||||
}
|
||||
else if (front.type == BuildingType::TunnelEntry)
|
||||
{
|
||||
m_belts.placeTunnelEntry(front.anchor, front.rotation, m_config.world.tunnelMaxDistance_tiles);
|
||||
}
|
||||
else if (front.type == BuildingType::TunnelExit)
|
||||
{
|
||||
m_belts.placeTunnelExit(front.anchor, front.rotation);
|
||||
}
|
||||
// Register with BeltSystem before the move (mask/building stays valid). Any
|
||||
// filters configured while under construction carry over (REQ-BLD-SITE-CONFIG).
|
||||
reregisterBeltTile(building, front.splitterFilterA, front.splitterFilterB);
|
||||
|
||||
m_buildings.push_back(std::move(building));
|
||||
|
||||
@@ -791,6 +837,114 @@ void BuildingSystem::tickConstruction(Tick currentTick)
|
||||
}
|
||||
}
|
||||
|
||||
void BuildingSystem::reregisterBeltTile(const Building& building,
|
||||
const std::vector<ItemType>& splitterFilterA,
|
||||
const std::vector<ItemType>& splitterFilterB)
|
||||
{
|
||||
switch (building.type)
|
||||
{
|
||||
case BuildingType::Belt:
|
||||
m_belts.placeBelt(building.anchor, building.rotation);
|
||||
break;
|
||||
case BuildingType::Splitter:
|
||||
assert(building.outputPorts.size() >= 2);
|
||||
m_belts.placeSplitter(building.anchor,
|
||||
building.outputPorts[0].direction,
|
||||
building.outputPorts[1].direction);
|
||||
m_belts.setSplitterFilters(building.anchor, splitterFilterA, splitterFilterB);
|
||||
break;
|
||||
case BuildingType::TunnelEntry:
|
||||
m_belts.placeTunnelEntry(building.anchor, building.rotation,
|
||||
m_config.world.tunnelMaxDistance_tiles);
|
||||
break;
|
||||
case BuildingType::TunnelExit:
|
||||
m_belts.placeTunnelExit(building.anchor, building.rotation);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void BuildingSystem::tickDeconstruction(Tick currentTick)
|
||||
{
|
||||
TRACE();
|
||||
if (m_deconstructionQueue.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DeconstructionEntry& front = m_deconstructionQueue.front();
|
||||
|
||||
// Guard: if the front entry's timer was never started, start it now.
|
||||
if (front.completesAt == 0)
|
||||
{
|
||||
startFrontDeconstruction(currentTick);
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentTick < front.completesAt)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the building from the world and credit its refund (REQ-BLD-DECONSTRUCT).
|
||||
// Belt/tunnel/splitter tiles were already unregistered when the building was
|
||||
// queued (see deconstruct), so only tile occupancy and the record remain.
|
||||
for (std::vector<Building>::iterator it = m_buildings.begin();
|
||||
it != m_buildings.end();
|
||||
++it)
|
||||
{
|
||||
if (it->id != front.id) { continue; }
|
||||
|
||||
const BuildingDef* def = findBuildingDef(it->type);
|
||||
for (const QPoint& cell : it->bodyCells)
|
||||
{
|
||||
m_tileOccupancy.erase({cell.x(), cell.y()});
|
||||
}
|
||||
m_buildings.erase(it);
|
||||
if (def)
|
||||
{
|
||||
m_addBuildingBlocks(def->cost * m_config.world.refundPercentage / 100);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
m_deconstructionQueue.pop_front();
|
||||
|
||||
// Start the next queued deconstruction, if any.
|
||||
startFrontDeconstruction(currentTick);
|
||||
}
|
||||
|
||||
void BuildingSystem::cancelDeconstruction(BuildingId id)
|
||||
{
|
||||
for (std::deque<DeconstructionEntry>::iterator it = m_deconstructionQueue.begin();
|
||||
it != m_deconstructionQueue.end();
|
||||
++it)
|
||||
{
|
||||
if (it->id != id) { continue; }
|
||||
|
||||
// Resume operation: clear the flag and re-register belt/tunnel/splitter
|
||||
// tiles that were unregistered at enqueue (which re-pairs tunnels,
|
||||
// REQ-BLD-TUNNEL-PAIR). Deconstruction progress is discarded; no refund.
|
||||
if (Building* building = findBuildingMutable(id))
|
||||
{
|
||||
building->queuedForDeconstruction = false;
|
||||
reregisterBeltTile(*building, it->splitterFilterA, it->splitterFilterB);
|
||||
}
|
||||
|
||||
m_deconstructionQueue.erase(it);
|
||||
// If the running front was removed, the new front (completesAt == 0) has
|
||||
// its timer started by the next tickDeconstruction guard.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool BuildingSystem::isQueuedForDeconstruction(BuildingId id) const
|
||||
{
|
||||
const Building* building = findBuilding(id);
|
||||
return building && building->queuedForDeconstruction;
|
||||
}
|
||||
|
||||
void BuildingSystem::tickBeltPull()
|
||||
{
|
||||
TRACE();
|
||||
@@ -800,6 +954,9 @@ void BuildingSystem::tickBeltPull()
|
||||
|
||||
for (Building& building : m_buildings)
|
||||
{
|
||||
// A building queued for deconstruction stops operating (REQ-BLD-DECON-QUEUE).
|
||||
if (building.queuedForDeconstruction) { continue; }
|
||||
|
||||
const bool isHq = (building.type == BuildingType::Hq);
|
||||
|
||||
// 1. Advance every input belt and deliver arrivals (progress >= 0.5) into
|
||||
@@ -891,6 +1048,10 @@ bool BuildingSystem::tryDirectCoupleDeposit(BuildingId producerId,
|
||||
{
|
||||
return false; // an unbuilt construction site, or not an operational building
|
||||
}
|
||||
if (consumer->queuedForDeconstruction)
|
||||
{
|
||||
return false; // queued for deconstruction: stopped operating (REQ-BLD-DECON-QUEUE)
|
||||
}
|
||||
|
||||
// The coupling is the consumer input port meeting this output port: same flow
|
||||
// direction, feeding the producer's output-port tile (REQ-MAT-DIRECT-COUPLE).
|
||||
@@ -912,6 +1073,9 @@ void BuildingSystem::tickProduction(Tick currentTick)
|
||||
TRACE();
|
||||
for (Building& building : m_buildings)
|
||||
{
|
||||
// A building queued for deconstruction stops operating (REQ-BLD-DECON-QUEUE).
|
||||
if (building.queuedForDeconstruction) { continue; }
|
||||
|
||||
// Skip types without a recipe-based production loop.
|
||||
if (building.type == BuildingType::Belt ||
|
||||
building.type == BuildingType::Splitter ||
|
||||
@@ -951,43 +1115,13 @@ void BuildingSystem::tickProduction(Tick currentTick)
|
||||
// recipe of their type in config order, running the first whose inputs
|
||||
// are satisfied (REQ-BLD-SMELTER, REQ-BLD-REPROCESSING). Other buildings
|
||||
// try only their selected recipe.
|
||||
std::vector<const RecipeDef*> candidates;
|
||||
if (autoRecipe)
|
||||
{
|
||||
for (const RecipeDef& r : m_config.recipes.recipes)
|
||||
{
|
||||
if (r.building == building.type && !r.inputs.empty())
|
||||
{
|
||||
candidates.push_back(&r);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const RecipeDef* recipe = findRecipe(building.recipeId, building.type);
|
||||
if (recipe)
|
||||
{
|
||||
candidates.push_back(recipe);
|
||||
}
|
||||
}
|
||||
const std::vector<const RecipeDef*> candidates =
|
||||
gatherCandidateRecipes(building);
|
||||
|
||||
for (const RecipeDef* recipe : candidates)
|
||||
{
|
||||
// 1. All required inputs present?
|
||||
bool inputsOk = true;
|
||||
for (const RecipeIngredient& ing : recipe->inputs)
|
||||
{
|
||||
const ItemType type{ing.item};
|
||||
const std::map<ItemType, int>::const_iterator it =
|
||||
building.inputBuffer.counts.find(type);
|
||||
const int have = (it != building.inputBuffer.counts.end()) ? it->second : 0;
|
||||
if (have < ing.amount)
|
||||
{
|
||||
inputsOk = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!inputsOk)
|
||||
if (!recipeInputsAvailable(building, *recipe))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -1014,7 +1148,7 @@ void BuildingSystem::tickProduction(Tick currentTick)
|
||||
|
||||
// 3. Output buffer has space for chosen outputs? Emerging items still
|
||||
// count against the buffer (REQ-MAT-OUTPUT-EMERGE).
|
||||
const int newSize = building.outputItemCount()
|
||||
const int newSize = building.getOutputItemCount()
|
||||
+ static_cast<int>(chosen.size());
|
||||
if (newSize > building.outputBuffer.capacity)
|
||||
{
|
||||
@@ -1042,6 +1176,9 @@ void BuildingSystem::tickShipyardProduction(Tick currentTick)
|
||||
TRACE();
|
||||
for (Building& building : m_buildings)
|
||||
{
|
||||
// A building queued for deconstruction stops operating (REQ-BLD-DECON-QUEUE).
|
||||
if (building.queuedForDeconstruction) { continue; }
|
||||
|
||||
if (building.type != BuildingType::Shipyard)
|
||||
{
|
||||
continue;
|
||||
@@ -1082,26 +1219,8 @@ void BuildingSystem::tickShipyardProduction(Tick currentTick)
|
||||
}
|
||||
|
||||
// Build combined materials list (base + modules).
|
||||
std::map<std::string, int> requiredMaterials;
|
||||
for (const RecipeIngredient& ing : shipDef->schematic.materials)
|
||||
{
|
||||
requiredMaterials[ing.item] += ing.amount;
|
||||
}
|
||||
if (building.shipLayout.has_value())
|
||||
{
|
||||
for (const PlacedModule& pm : building.shipLayout->placedModules)
|
||||
{
|
||||
const ModuleDef* modDef = findModuleDef(pm.moduleId);
|
||||
if (!modDef)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (const RecipeIngredient& ing : modDef->materials)
|
||||
{
|
||||
requiredMaterials[ing.item] += ing.amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
const std::map<std::string, int> requiredMaterials =
|
||||
computeShipyardRequiredMaterials(building);
|
||||
|
||||
// Idle: check if all combined materials are available.
|
||||
bool inputsOk = true;
|
||||
@@ -1157,6 +1276,9 @@ void BuildingSystem::tickOutputBelts()
|
||||
|
||||
for (Building& building : m_buildings)
|
||||
{
|
||||
// A building queued for deconstruction stops operating (REQ-BLD-DECON-QUEUE).
|
||||
if (building.queuedForDeconstruction) { continue; }
|
||||
|
||||
for (std::size_t p = 0; p < building.outputPorts.size(); ++p)
|
||||
{
|
||||
const Port& port = building.outputPorts[p];
|
||||
@@ -1279,12 +1401,12 @@ const ConstructionSite* BuildingSystem::findSite(BuildingId id) const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<Building> BuildingSystem::allBuildings() const
|
||||
std::vector<Building> BuildingSystem::getAllBuildings() const
|
||||
{
|
||||
return m_buildings;
|
||||
}
|
||||
|
||||
std::vector<ConstructionSite> BuildingSystem::allSites() const
|
||||
std::vector<ConstructionSite> BuildingSystem::getAllSites() const
|
||||
{
|
||||
return std::vector<ConstructionSite>(m_constructionQueue.begin(),
|
||||
m_constructionQueue.end());
|
||||
@@ -1308,7 +1430,7 @@ bool isProductionBuildingType(BuildingType type)
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int BuildingSystem::productionBuildingCount() const
|
||||
int BuildingSystem::getProductionBuildingCount() const
|
||||
{
|
||||
int count = 0;
|
||||
for (const Building& b : m_buildings)
|
||||
@@ -1318,7 +1440,7 @@ int BuildingSystem::productionBuildingCount() const
|
||||
return count;
|
||||
}
|
||||
|
||||
int BuildingSystem::activeProductionBuildingCount() const
|
||||
int BuildingSystem::getActiveProductionBuildingCount() const
|
||||
{
|
||||
int count = 0;
|
||||
for (const Building& b : m_buildings)
|
||||
@@ -1328,7 +1450,148 @@ int BuildingSystem::activeProductionBuildingCount() const
|
||||
return count;
|
||||
}
|
||||
|
||||
std::vector<BuildingSystem::BeltTileInfo> BuildingSystem::allBeltTiles() const
|
||||
std::vector<const RecipeDef*>
|
||||
BuildingSystem::gatherCandidateRecipes(const Building& b) const
|
||||
{
|
||||
std::vector<const RecipeDef*> candidates;
|
||||
if (isAutoRecipeBuildingType(b.type))
|
||||
{
|
||||
for (const RecipeDef& r : m_config.recipes.recipes)
|
||||
{
|
||||
if (r.building == b.type && !r.inputs.empty())
|
||||
{
|
||||
candidates.push_back(&r);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const RecipeDef* recipe = findRecipe(b.recipeId, b.type);
|
||||
if (recipe)
|
||||
{
|
||||
candidates.push_back(recipe);
|
||||
}
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
bool BuildingSystem::recipeInputsAvailable(const Building& b,
|
||||
const RecipeDef& recipe) const
|
||||
{
|
||||
for (const RecipeIngredient& ing : recipe.inputs)
|
||||
{
|
||||
const std::map<ItemType, int>::const_iterator it =
|
||||
b.inputBuffer.counts.find(ItemType{ing.item});
|
||||
const int have = (it != b.inputBuffer.counts.end()) ? it->second : 0;
|
||||
if (have < ing.amount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::map<std::string, int>
|
||||
BuildingSystem::computeShipyardRequiredMaterials(const Building& b) const
|
||||
{
|
||||
std::map<std::string, int> requiredMaterials;
|
||||
const ShipDef* shipDef = findShipDef(b.recipeId);
|
||||
if (!shipDef)
|
||||
{
|
||||
return requiredMaterials;
|
||||
}
|
||||
for (const RecipeIngredient& ing : shipDef->schematic.materials)
|
||||
{
|
||||
requiredMaterials[ing.item] += ing.amount;
|
||||
}
|
||||
if (b.shipLayout.has_value())
|
||||
{
|
||||
for (const PlacedModule& pm : b.shipLayout->placedModules)
|
||||
{
|
||||
const ModuleDef* modDef = findModuleDef(pm.moduleId);
|
||||
if (!modDef)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (const RecipeIngredient& ing : modDef->materials)
|
||||
{
|
||||
requiredMaterials[ing.item] += ing.amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
return requiredMaterials;
|
||||
}
|
||||
|
||||
bool BuildingSystem::hasInputsToStart(const Building& b) const
|
||||
{
|
||||
if (b.type == BuildingType::Shipyard)
|
||||
{
|
||||
const std::map<std::string, int> required =
|
||||
computeShipyardRequiredMaterials(b);
|
||||
for (const std::pair<const std::string, int>& req : required)
|
||||
{
|
||||
const std::map<ItemType, int>::const_iterator it =
|
||||
b.inputBuffer.counts.find(ItemType{req.first});
|
||||
const int have = (it != b.inputBuffer.counts.end()) ? it->second : 0;
|
||||
if (have < req.second)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Recipe buildings: startable if any candidate recipe's inputs are satisfied.
|
||||
// A Miner recipe has no inputs, so an idle Miner is always startable and its
|
||||
// only idle reason is a full output buffer.
|
||||
for (const RecipeDef* recipe : gatherCandidateRecipes(b))
|
||||
{
|
||||
if (recipeInputsAvailable(b, *recipe))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::optional<ProductionStatus>
|
||||
BuildingSystem::getProductionStatus(const Building& building) const
|
||||
{
|
||||
// Salvage Bay has no recipe or production cycle (REQ-BLD-SALVAGE-BAY): it is
|
||||
// "producing" while it holds scrap to push out, and starved when empty.
|
||||
if (building.type == BuildingType::SalvageBay)
|
||||
{
|
||||
return building.getOutputItemCount() >= 1 ? ProductionStatus::Producing
|
||||
: ProductionStatus::Starved;
|
||||
}
|
||||
|
||||
// Only the five recipe/cycle production types show a status light besides the
|
||||
// Salvage Bay; belts, splitters, tunnels, HQ, and stations show none.
|
||||
if (!isProductionBuildingType(building.type))
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Grey only applies to player-configured types; auto-recipe buildings
|
||||
// (Smelter, Reprocessing Plant) always run an implicit recipe.
|
||||
if (!isAutoRecipeBuildingType(building.type) && building.recipeId.empty())
|
||||
{
|
||||
return ProductionStatus::Unconfigured;
|
||||
}
|
||||
|
||||
if (building.production.has_value())
|
||||
{
|
||||
return ProductionStatus::Producing;
|
||||
}
|
||||
|
||||
// Idle: missing inputs (red) take precedence over a full output buffer
|
||||
// (yellow). If inputs are present yet the building is idle, the only remaining
|
||||
// reason it could not start a cycle is a full output buffer (REQ-MAT-CYCLE).
|
||||
return hasInputsToStart(building) ? ProductionStatus::Blocked
|
||||
: ProductionStatus::Starved;
|
||||
}
|
||||
|
||||
std::vector<BuildingSystem::BeltTileInfo> BuildingSystem::getAllBeltTiles() const
|
||||
{
|
||||
std::vector<BeltTileInfo> result;
|
||||
for (const Building& b : m_buildings)
|
||||
@@ -1368,6 +1631,13 @@ bool BuildingSystem::isTileOccupied(QPoint tile) const
|
||||
std::optional<BuildingId> BuildingSystem::findRotateInPlaceTarget(
|
||||
BuildingType type, QPoint anchor, Rotation rot) const
|
||||
{
|
||||
// Tunnel Entries and Tunnel Exits cannot be rotated in place; re-orienting a
|
||||
// tunnel requires deconstructing and re-placing it (REQ-BLD-ROTATE-IN-PLACE).
|
||||
if (type == BuildingType::TunnelEntry || type == BuildingType::TunnelExit)
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const BuildingDef* def = findBuildingDef(type);
|
||||
if (!def) { return std::nullopt; }
|
||||
|
||||
@@ -1516,9 +1786,13 @@ bool BuildingSystem::deliverScrapToSalvageBay(BuildingId bayId)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (bay->queuedForDeconstruction)
|
||||
{
|
||||
return false; // queued for deconstruction: stopped operating (REQ-BLD-DECON-QUEUE)
|
||||
}
|
||||
// Emerging scrap still counts against the bay's holding capacity
|
||||
// (REQ-MAT-OUTPUT-EMERGE).
|
||||
if (bay->outputItemCount() >= bay->outputBuffer.capacity)
|
||||
if (bay->getOutputItemCount() >= bay->outputBuffer.capacity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -1689,6 +1963,7 @@ void BuildingSystem::appendChecksum(Hasher& hasher) const
|
||||
appendItems(hasher, b.production->chosenOutputs);
|
||||
}
|
||||
hasher.append(b.shipLayout.has_value());
|
||||
hasher.append(b.queuedForDeconstruction);
|
||||
}
|
||||
|
||||
hasher.append(m_constructionQueue.size());
|
||||
@@ -1709,6 +1984,17 @@ void BuildingSystem::appendChecksum(Hasher& hasher) const
|
||||
for (const ItemType& type : s.splitterFilterB) { hasher.append(type.id); }
|
||||
}
|
||||
|
||||
hasher.append(m_deconstructionQueue.size());
|
||||
for (const DeconstructionEntry& e : m_deconstructionQueue)
|
||||
{
|
||||
hasher.append(e.id);
|
||||
hasher.append(e.completesAt);
|
||||
hasher.append(e.splitterFilterA.size());
|
||||
for (const ItemType& type : e.splitterFilterA) { hasher.append(type.id); }
|
||||
hasher.append(e.splitterFilterB.size());
|
||||
for (const ItemType& type : e.splitterFilterB) { hasher.append(type.id); }
|
||||
}
|
||||
|
||||
// std::map iterates in sorted key order.
|
||||
hasher.append(m_tileOccupancy.size());
|
||||
for (const std::pair<const std::pair<int, int>, BuildingId>& entry : m_tileOccupancy)
|
||||
|
||||
@@ -26,6 +26,18 @@
|
||||
|
||||
class Hasher;
|
||||
|
||||
// Production state of a building for the UI status light (REQ-UI-STATUS-LIGHT).
|
||||
// The simulation owns the classification so it stays in sync with the
|
||||
// production-cycle predicates (REQ-MAT-CYCLE); the UI maps each value to a fill
|
||||
// color.
|
||||
enum class ProductionStatus
|
||||
{
|
||||
Unconfigured, // no recipe/schematic selected (grey)
|
||||
Producing, // a production cycle is active (green)
|
||||
Starved, // idle: a required input is missing / Salvage Bay empty (red)
|
||||
Blocked, // idle: output buffer full, inputs otherwise present (yellow)
|
||||
};
|
||||
|
||||
// Manages building placement, construction queuing, and the per-tick
|
||||
// production loop (belt→building pull, production, building→belt push).
|
||||
// All types including Belt and Splitter are stored as Building instances;
|
||||
@@ -42,14 +54,14 @@ public:
|
||||
std::function<bool(const std::string&)> isItemUnlocked,
|
||||
std::mt19937& rng);
|
||||
|
||||
// -- Placement / demolish ------------------------------------------------
|
||||
// Returns the new entity id, or kInvalidBuildingId if the placement falls
|
||||
// outside the world bounds (vertical extent and asteroid left edge). Belt
|
||||
// and Splitter register with BeltSystem directly; other types enter the
|
||||
// construction queue. Terrain type (A vs S) is NOT checked here so that
|
||||
// tests can stage arbitrary layouts; the player-facing entry point
|
||||
// -- Placement / deconstruct ------------------------------------------------
|
||||
// Returns the new entity id, or nullopt if the placement falls outside the
|
||||
// world bounds (vertical extent and asteroid left edge). Belt and Splitter
|
||||
// register with BeltSystem directly; other types enter the construction
|
||||
// queue. Terrain type (A vs S) is NOT checked here so that tests can stage
|
||||
// arbitrary layouts; the player-facing entry point
|
||||
// (Simulation::tryPlaceBuilding) enforces the full rule via isPlacementValid.
|
||||
BuildingId place(BuildingType type, QPoint anchor, Rotation rotation,
|
||||
std::optional<BuildingId> place(BuildingType type, QPoint anchor, Rotation rotation,
|
||||
Tick currentTick);
|
||||
|
||||
// Returns true if the placement satisfies REQ-BLD-PLACE-VALID terrain and
|
||||
@@ -65,10 +77,22 @@ public:
|
||||
// Defaults to world.regions.asteroid_width_tiles at construction.
|
||||
void setAsteroidWidth_tiles(int widthTiles) { m_asteroidWidth_tiles = widthTiles; }
|
||||
|
||||
// Remove a building or construction site by id. Returns the refund in
|
||||
// building blocks (floor(cost * refundPercentage / 100)). Returns 0 for
|
||||
// unknown ids.
|
||||
int demolish(BuildingId id);
|
||||
// Mark a building or construction site for demolition (REQ-BLD-DECONSTRUCT).
|
||||
// A construction site is removed instantly and the full cost is returned.
|
||||
// A fully-built building is instead appended to the deconstruction queue
|
||||
// (REQ-BLD-DECON-QUEUE) and stops operating at once; its (partial) refund is
|
||||
// credited later, on completion in tickDeconstruction, so this returns 0 for
|
||||
// it. Returns 0 for unknown ids and for a building already queued.
|
||||
int deconstruct(BuildingId id, Tick currentTick);
|
||||
|
||||
// Take a building back out of the deconstruction queue before it is removed
|
||||
// (REQ-BLD-DECON-QUEUE). Clears its queued flag and resumes operation
|
||||
// (re-registering belt/tunnel/splitter tiles); discards deconstruction
|
||||
// progress and credits no refund. No-op if the id is not queued.
|
||||
void cancelDeconstruction(BuildingId id);
|
||||
|
||||
// True if the building is currently in the deconstruction queue.
|
||||
bool isQueuedForDeconstruction(BuildingId id) const;
|
||||
|
||||
// Set the recipe (or schematic id for shipyard) on a building or queued
|
||||
// construction site. Clears both buffers on an operational building.
|
||||
@@ -92,6 +116,10 @@ public:
|
||||
|
||||
// -- Tick hooks (called from Simulation::tick in the documented order) ---
|
||||
void tickConstruction(Tick currentTick);
|
||||
// Advances the deconstruction queue (REQ-BLD-DECON-QUEUE): one building at a
|
||||
// time, in parallel with tickConstruction. Removes the front building and
|
||||
// credits its refund when its timer elapses.
|
||||
void tickDeconstruction(Tick currentTick);
|
||||
void tickBeltPull();
|
||||
void tickProduction(Tick currentTick);
|
||||
void tickShipyardProduction(Tick currentTick);
|
||||
@@ -112,17 +140,23 @@ public:
|
||||
|
||||
const Building* findBuilding(BuildingId id) const;
|
||||
const ConstructionSite* findSite(BuildingId id) const;
|
||||
std::vector<Building> allBuildings() const;
|
||||
std::vector<ConstructionSite> allSites() const;
|
||||
std::vector<Building> getAllBuildings() const;
|
||||
std::vector<ConstructionSite> getAllSites() const;
|
||||
|
||||
// REQ-UI-DEBUG-OVERLAY "Max Factory Production": count of completed
|
||||
// (operational) Miner/Smelter/Assembler/ReprocessingPlant/Shipyard buildings.
|
||||
int productionBuildingCount() const;
|
||||
int getProductionBuildingCount() const;
|
||||
|
||||
// REQ-UI-DEBUG-OVERLAY "Current Factory Production": subset of the above
|
||||
// that currently has an active production cycle.
|
||||
int activeProductionBuildingCount() const;
|
||||
std::vector<BeltTileInfo> allBeltTiles() const;
|
||||
int getActiveProductionBuildingCount() const;
|
||||
|
||||
// Production state for the UI status light (REQ-UI-STATUS-LIGHT). Returns
|
||||
// nullopt for building types that show no light (belts, splitters, tunnels,
|
||||
// HQ, defence stations). The Salvage Bay is a two-state special case:
|
||||
// Producing while its output buffer holds scrap, Starved when empty.
|
||||
std::optional<ProductionStatus> getProductionStatus(const Building& building) const;
|
||||
std::vector<BeltTileInfo> getAllBeltTiles() const;
|
||||
bool isTileOccupied(QPoint tile) const;
|
||||
|
||||
// Visits every item currently emerging from a building output port on its
|
||||
@@ -153,6 +187,12 @@ public:
|
||||
// Find nearest operational building of the given type; nullptr if none.
|
||||
const Building* findNearestBuilding(QVector2D worldPos, BuildingType type) const;
|
||||
|
||||
// Input-capable adjacent tiles for a building or construction site
|
||||
// (REQ-BLD-BELT-DRAG, REQ-MAT-INPUT-PORTS): each returned Port.tile is the
|
||||
// outside adjacent tile and Port.direction is the belt facing that points into
|
||||
// the target. Output-port edges are excluded. Empty for an unknown id.
|
||||
std::vector<Port> getInputPorts(BuildingId id) const;
|
||||
|
||||
// Register / unregister tile occupancy for ECS station entities.
|
||||
void registerTileOccupancy(const std::vector<QPoint>& cells, BuildingId ownerPlaceholder);
|
||||
void unregisterTileOccupancy(const std::vector<QPoint>& cells);
|
||||
@@ -181,6 +221,17 @@ public:
|
||||
void appendChecksum(Hasher& hasher) const;
|
||||
|
||||
private:
|
||||
// Starts the front deconstruction-queue entry's timer if not yet started
|
||||
// (mirrors how tickConstruction starts a queued construction site).
|
||||
void startFrontDeconstruction(Tick currentTick);
|
||||
|
||||
// Registers a belt/splitter/tunnel building's tile with the belt subsystem
|
||||
// (on construction completion, or when un-queuing a deconstruction). No-op for
|
||||
// non-belt-subsystem types. Splitter filters are (re)applied after placement.
|
||||
void reregisterBeltTile(const Building& building,
|
||||
const std::vector<ItemType>& splitterFilterA,
|
||||
const std::vector<ItemType>& splitterFilterB);
|
||||
|
||||
Building* findBuildingMutable(BuildingId id);
|
||||
// True if the consumer would accept `type` at the given input port right now:
|
||||
// it is a required input (or a building block for the HQ), the reservation-aware
|
||||
@@ -200,6 +251,22 @@ private:
|
||||
const Port& outputPort,
|
||||
const Item& item);
|
||||
|
||||
// Candidate recipes an idle building would try this tick: an auto-recipe
|
||||
// building (Smelter, Reprocessing Plant) offers every recipe of its type with
|
||||
// inputs; other buildings offer only their selected recipe. Shared by
|
||||
// tickProduction and the status classifier (REQ-MAT-CYCLE, REQ-UI-STATUS-LIGHT).
|
||||
std::vector<const RecipeDef*> gatherCandidateRecipes(const Building& b) const;
|
||||
// True if every input of `recipe` is present in `b`'s input buffers in the
|
||||
// required per-cycle amount (REQ-MAT-CYCLE input check).
|
||||
bool recipeInputsAvailable(const Building& b,
|
||||
const RecipeDef& recipe) const;
|
||||
// Combined base + module materials a shipyard needs per ship (REQ-BLD-SHIPYARD).
|
||||
std::map<std::string, int> computeShipyardRequiredMaterials(const Building& b) const;
|
||||
// True if the building currently has all inputs/materials to start a cycle
|
||||
// (ignoring output-buffer space); drives the Starved/Blocked distinction of
|
||||
// the status light (REQ-UI-STATUS-LIGHT).
|
||||
bool hasInputsToStart(const Building& b) const;
|
||||
|
||||
const BuildingDef* findBuildingDef(BuildingType type) const;
|
||||
const RecipeDef* findRecipe(const std::string& id, BuildingType type) const;
|
||||
const ShipDef* findShipDef(const std::string& id) const;
|
||||
@@ -212,6 +279,9 @@ private:
|
||||
void initShipyardBuffers(Building& b) const;
|
||||
void initSalvageBayBuffer(Building& b) const;
|
||||
std::vector<Port> computeInputPorts(const Building& b) const;
|
||||
// Core input-edge scan shared by operational buildings and construction sites.
|
||||
std::vector<Port> computeInputPorts(const std::vector<QPoint>& bodyCells,
|
||||
const std::vector<Port>& outputPorts) const;
|
||||
std::vector<Item> rollReprocessingOutput(const RecipeDef& recipe);
|
||||
bool bodyCellsWithinWorldBounds(
|
||||
const std::vector<QPoint>& bodyCells,
|
||||
@@ -230,6 +300,19 @@ private:
|
||||
std::vector<Building> m_buildings;
|
||||
std::deque<ConstructionSite> m_constructionQueue;
|
||||
|
||||
// One pending demolition of a fully-built building (REQ-BLD-DECON-QUEUE).
|
||||
// completesAt == 0 means "queued but its timer has not started yet"
|
||||
// (mirrors ConstructionSite). For a Splitter, the filters it had are captured
|
||||
// here so cancelDeconstruction can restore them on re-registration.
|
||||
struct DeconstructionEntry
|
||||
{
|
||||
BuildingId id = kInvalidBuildingId;
|
||||
Tick completesAt = 0;
|
||||
std::vector<ItemType> splitterFilterA;
|
||||
std::vector<ItemType> splitterFilterB;
|
||||
};
|
||||
std::deque<DeconstructionEntry> m_deconstructionQueue;
|
||||
|
||||
// Maps every occupied body-cell coordinate to the entity that owns it.
|
||||
std::map<std::pair<int, int>, BuildingId> m_tileOccupancy;
|
||||
};
|
||||
|
||||
@@ -27,7 +27,8 @@ class GameConfig;
|
||||
enum class CommandKind
|
||||
{
|
||||
PlaceBuilding,
|
||||
Demolish,
|
||||
Deconstruct,
|
||||
CancelDeconstruction,
|
||||
RotateInPlace,
|
||||
SetRecipe,
|
||||
SetShipLayout,
|
||||
@@ -72,31 +73,41 @@ struct PlaceBuildingCommand : Command
|
||||
std::vector<ItemType> splitterFilterB;
|
||||
};
|
||||
|
||||
struct DemolishCommand : Command
|
||||
// Marks a building for demolition: a construction site is removed instantly, a
|
||||
// built building is queued for deconstruction (REQ-BLD-DECONSTRUCT, REQ-BLD-DECON-QUEUE).
|
||||
struct DeconstructCommand : Command
|
||||
{
|
||||
DemolishCommand() : Command(CommandKind::Demolish) {}
|
||||
BuildingId id = kInvalidBuildingId;
|
||||
DeconstructCommand() : Command(CommandKind::Deconstruct) {}
|
||||
std::optional<BuildingId> id;
|
||||
};
|
||||
|
||||
// Takes a building back out of the deconstruction queue (REQ-BLD-DECONSTRUCT-CLICK,
|
||||
// REQ-BLD-DECONSTRUCT-BOX). No-op if the id is not currently queued.
|
||||
struct CancelDeconstructionCommand : Command
|
||||
{
|
||||
CancelDeconstructionCommand() : Command(CommandKind::CancelDeconstruction) {}
|
||||
std::optional<BuildingId> id;
|
||||
};
|
||||
|
||||
struct RotateInPlaceCommand : Command
|
||||
{
|
||||
RotateInPlaceCommand() : Command(CommandKind::RotateInPlace) {}
|
||||
BuildingId id = kInvalidBuildingId;
|
||||
Rotation newRotation = Rotation::East;
|
||||
std::optional<BuildingId> id;
|
||||
Rotation newRotation = Rotation::East;
|
||||
};
|
||||
|
||||
struct SetRecipeCommand : Command
|
||||
{
|
||||
SetRecipeCommand() : Command(CommandKind::SetRecipe) {}
|
||||
BuildingId id = kInvalidBuildingId;
|
||||
std::string recipeId;
|
||||
std::optional<BuildingId> id;
|
||||
std::string recipeId;
|
||||
};
|
||||
|
||||
struct SetShipLayoutCommand : Command
|
||||
{
|
||||
SetShipLayoutCommand() : Command(CommandKind::SetShipLayout) {}
|
||||
BuildingId id = kInvalidBuildingId;
|
||||
ShipLayoutConfig layout;
|
||||
std::optional<BuildingId> id;
|
||||
ShipLayoutConfig layout;
|
||||
};
|
||||
|
||||
// Splitter filters for a queued / under-construction Splitter site (configured by
|
||||
@@ -104,8 +115,8 @@ struct SetShipLayoutCommand : Command
|
||||
struct SetSiteSplitterFiltersCommand : Command
|
||||
{
|
||||
SetSiteSplitterFiltersCommand() : Command(CommandKind::SetSiteSplitterFilters) {}
|
||||
BuildingId id = kInvalidBuildingId;
|
||||
std::vector<ItemType> filterA;
|
||||
std::optional<BuildingId> id;
|
||||
std::vector<ItemType> filterA;
|
||||
std::vector<ItemType> filterB;
|
||||
};
|
||||
|
||||
|
||||
@@ -46,18 +46,18 @@ void CommandManager::drain()
|
||||
{
|
||||
// Restart is a file boundary: a fresh file with the new seed.
|
||||
m_recorder->startNewRun(m_simulation.getSeed(),
|
||||
m_simulation.rngFingerprint());
|
||||
m_simulation.getRngFingerprint());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Commands drain before the tick batch, so currentTick is the count of
|
||||
// completed ticks the command is pinned to.
|
||||
const Tick tick = m_simulation.currentTick();
|
||||
const Tick tick = m_simulation.getCurrentTick();
|
||||
m_simulation.apply(*command);
|
||||
if (m_recorder)
|
||||
{
|
||||
m_recorder->recordCommand(tick, *command, m_simulation.rngFingerprint());
|
||||
m_recorder->recordCommand(tick, *command, m_simulation.getRngFingerprint());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ void CommandManager::setRecorder(std::unique_ptr<ReplayRecorder> recorder)
|
||||
m_recorder = std::move(recorder);
|
||||
if (m_recorder)
|
||||
{
|
||||
m_recorder->startNewRun(m_simulation.getSeed(), m_simulation.rngFingerprint());
|
||||
m_recorder->startNewRun(m_simulation.getSeed(), m_simulation.getRngFingerprint());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,8 +85,8 @@ void CommandManager::setReplayMode(bool replayMode)
|
||||
|
||||
void CommandManager::recordTickCheckpoint()
|
||||
{
|
||||
if (m_recorder && (m_simulation.currentTick() % kChecksumIntervalTicks == 0))
|
||||
if (m_recorder && (m_simulation.getCurrentTick() % kChecksumIntervalTicks == 0))
|
||||
{
|
||||
m_recorder->recordChecksum(m_simulation.currentTick(), m_simulation.rngFingerprint());
|
||||
m_recorder->recordChecksum(m_simulation.getCurrentTick(), m_simulation.getRngFingerprint());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,25 +128,29 @@ std::string serializeCommand(const Command& command)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CommandKind::Demolish:
|
||||
out << "demolish " << static_cast<const DemolishCommand&>(command).id;
|
||||
case CommandKind::Deconstruct:
|
||||
out << "deconstruct " << static_cast<const DeconstructCommand&>(command).id.value();
|
||||
break;
|
||||
case CommandKind::CancelDeconstruction:
|
||||
out << "cancel_deconstruct "
|
||||
<< static_cast<const CancelDeconstructionCommand&>(command).id.value();
|
||||
break;
|
||||
case CommandKind::RotateInPlace:
|
||||
{
|
||||
const RotateInPlaceCommand& c = static_cast<const RotateInPlaceCommand&>(command);
|
||||
out << "rotate " << c.id << ' ' << rotationToChar(c.newRotation);
|
||||
out << "rotate " << c.id.value() << ' ' << rotationToChar(c.newRotation);
|
||||
break;
|
||||
}
|
||||
case CommandKind::SetRecipe:
|
||||
{
|
||||
const SetRecipeCommand& c = static_cast<const SetRecipeCommand&>(command);
|
||||
out << "setrecipe " << c.id << ' ' << c.recipeId;
|
||||
out << "setrecipe " << c.id.value() << ' ' << c.recipeId;
|
||||
break;
|
||||
}
|
||||
case CommandKind::SetShipLayout:
|
||||
{
|
||||
const SetShipLayoutCommand& c = static_cast<const SetShipLayoutCommand&>(command);
|
||||
out << "setlayout " << c.id << ' ';
|
||||
out << "setlayout " << c.id.value() << ' ';
|
||||
appendLayout(out, c.layout);
|
||||
break;
|
||||
}
|
||||
@@ -154,7 +158,7 @@ std::string serializeCommand(const Command& command)
|
||||
{
|
||||
const SetSiteSplitterFiltersCommand& c =
|
||||
static_cast<const SetSiteSplitterFiltersCommand&>(command);
|
||||
out << "sitefilters " << c.id << ' ';
|
||||
out << "sitefilters " << c.id.value() << ' ';
|
||||
appendFilters(out, c.filterA, c.filterB);
|
||||
break;
|
||||
}
|
||||
@@ -239,30 +243,47 @@ std::shared_ptr<Command> parseCommand(const std::string& tokens)
|
||||
}
|
||||
return c;
|
||||
}
|
||||
if (verb == "demolish")
|
||||
if (verb == "deconstruct")
|
||||
{
|
||||
std::shared_ptr<DemolishCommand> c = std::make_shared<DemolishCommand>();
|
||||
if (!(in >> c->id)) { return nullptr; }
|
||||
std::shared_ptr<DeconstructCommand> c = std::make_shared<DeconstructCommand>();
|
||||
BuildingId id = 0;
|
||||
if (!(in >> id)) { return nullptr; }
|
||||
c->id = id;
|
||||
return c;
|
||||
}
|
||||
if (verb == "cancel_deconstruct")
|
||||
{
|
||||
std::shared_ptr<CancelDeconstructionCommand> c =
|
||||
std::make_shared<CancelDeconstructionCommand>();
|
||||
BuildingId id = 0;
|
||||
if (!(in >> id)) { return nullptr; }
|
||||
c->id = id;
|
||||
return c;
|
||||
}
|
||||
if (verb == "rotate")
|
||||
{
|
||||
std::shared_ptr<RotateInPlaceCommand> c = std::make_shared<RotateInPlaceCommand>();
|
||||
std::string rotToken;
|
||||
if (!(in >> c->id >> rotToken)) { return nullptr; }
|
||||
BuildingId id = 0;
|
||||
if (!(in >> id >> rotToken)) { return nullptr; }
|
||||
c->id = id;
|
||||
c->newRotation = rotationFromString(rotToken);
|
||||
return c;
|
||||
}
|
||||
if (verb == "setrecipe")
|
||||
{
|
||||
std::shared_ptr<SetRecipeCommand> c = std::make_shared<SetRecipeCommand>();
|
||||
if (!(in >> c->id >> c->recipeId)) { return nullptr; }
|
||||
BuildingId id = 0;
|
||||
if (!(in >> id >> c->recipeId)) { return nullptr; }
|
||||
c->id = id;
|
||||
return c;
|
||||
}
|
||||
if (verb == "setlayout")
|
||||
{
|
||||
std::shared_ptr<SetShipLayoutCommand> c = std::make_shared<SetShipLayoutCommand>();
|
||||
if (!(in >> c->id)) { return nullptr; }
|
||||
BuildingId id = 0;
|
||||
if (!(in >> id)) { return nullptr; }
|
||||
c->id = id;
|
||||
c->layout = parseLayout(in, ok);
|
||||
if (!ok) { return nullptr; }
|
||||
return c;
|
||||
@@ -271,7 +292,9 @@ std::shared_ptr<Command> parseCommand(const std::string& tokens)
|
||||
{
|
||||
std::shared_ptr<SetSiteSplitterFiltersCommand> c =
|
||||
std::make_shared<SetSiteSplitterFiltersCommand>();
|
||||
if (!(in >> c->id)) { return nullptr; }
|
||||
BuildingId id = 0;
|
||||
if (!(in >> id)) { return nullptr; }
|
||||
c->id = id;
|
||||
parseFilters(in, c->filterA, c->filterB, ok);
|
||||
if (!ok) { return nullptr; }
|
||||
return c;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "EntityAdmin.h"
|
||||
#include "PositionComponent.h"
|
||||
#include "ScrapDataComponent.h"
|
||||
#include "ShipIdentityComponent.h"
|
||||
#include "StationBodyComponent.h"
|
||||
#include "HealthComponent.h"
|
||||
|
||||
@@ -101,3 +102,46 @@ std::vector<entt::entity> scrapInBox(EntityAdmin& admin, QPoint tileA, QPoint ti
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<entt::entity> actorsInBox(EntityAdmin& admin, QPoint tileA, QPoint tileB)
|
||||
{
|
||||
const int minX = std::min(tileA.x(), tileB.x());
|
||||
const int maxX = std::max(tileA.x(), tileB.x());
|
||||
const int minY = std::min(tileA.y(), tileB.y());
|
||||
const int maxY = std::max(tileA.y(), tileB.y());
|
||||
|
||||
std::vector<entt::entity> result;
|
||||
|
||||
// Stations: included when any occupied body cell lies in the box.
|
||||
admin.forEach<StationBodyComponent, HealthComponent>(
|
||||
[&](entt::entity entity, const StationBodyComponent& sb, const HealthComponent& h)
|
||||
{
|
||||
if (h.hp <= 0.0f) { return; }
|
||||
for (const QPoint& cell : sb.bodyCells)
|
||||
{
|
||||
if (cell.x() >= minX && cell.x() <= maxX
|
||||
&& cell.y() >= minY && cell.y() <= maxY)
|
||||
{
|
||||
result.push_back(entity);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Ships: included when the floored position tile lies in the box. Requiring
|
||||
// ShipIdentityComponent excludes the HQ proxy and any station bodies.
|
||||
admin.forEach<ShipIdentityComponent, PositionComponent, HealthComponent>(
|
||||
[&](entt::entity entity, const ShipIdentityComponent& /*id*/,
|
||||
const PositionComponent& pos, const HealthComponent& h)
|
||||
{
|
||||
if (h.hp <= 0.0f) { return; }
|
||||
const int tileX = static_cast<int>(std::floor(pos.value.x()));
|
||||
const int tileY = static_cast<int>(std::floor(pos.value.y()));
|
||||
if (tileX >= minX && tileX <= maxX && tileY >= minY && tileY <= maxY)
|
||||
{
|
||||
result.push_back(entity);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -19,3 +19,10 @@ entt::entity scrapAtWorldPos(EntityAdmin& admin, QVector2D worldPos);
|
||||
// Returns every scrap pile whose position falls within the inclusive tile rectangle
|
||||
// spanned by tileA and tileB, in any corner order (REQ-UI-SCRAP-MULTI-SELECT).
|
||||
std::vector<entt::entity> scrapInBox(EntityAdmin& admin, QPoint tileA, QPoint tileB);
|
||||
|
||||
// Returns every living actor (ship or defence station, player or enemy) that falls
|
||||
// within the inclusive tile rectangle spanned by tileA and tileB, in any corner order
|
||||
// (REQ-UI-MULTI-SELECT, REQ-UI-ENTITY-CLICK-SELECT). A ship is included when its floored
|
||||
// position tile lies in the box; a station is included when any of its body cells does.
|
||||
// Dead actors (hp <= 0) and the HQ proxy are excluded.
|
||||
std::vector<entt::entity> actorsInBox(EntityAdmin& admin, QPoint tileA, QPoint tileB);
|
||||
|
||||
@@ -48,7 +48,7 @@ void ReplayPlayer::processEntriesAt(Tick tick)
|
||||
{
|
||||
m_simulation.apply(*entry.command);
|
||||
}
|
||||
else if (m_simulation.rngFingerprint() != entry.fingerprint)
|
||||
else if (m_simulation.getRngFingerprint() != entry.fingerprint)
|
||||
{
|
||||
m_desyncTick = tick;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class Simulation;
|
||||
// each frame, for each tick to run:
|
||||
// if (player.isFinished()) break;
|
||||
// sim.tick();
|
||||
// player.advanceTo(sim.currentTick());
|
||||
// player.advanceTo(sim.getCurrentTick());
|
||||
class ReplayPlayer
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -58,7 +58,7 @@ std::string computeReplayConfigHash(const std::string& configDir)
|
||||
hasher.appendBytes(bytes.constData(), static_cast<std::size_t>(bytes.size()));
|
||||
}
|
||||
}
|
||||
return toHex(hasher.value());
|
||||
return toHex(hasher.getValue());
|
||||
}
|
||||
|
||||
void ReplayRecorder::startNewRun(unsigned int seed, std::uint64_t initialRngFingerprint)
|
||||
@@ -124,7 +124,7 @@ bool ReplayRecorder::isOpen() const
|
||||
return m_stream.is_open();
|
||||
}
|
||||
|
||||
const std::string& ReplayRecorder::currentFilePath() const
|
||||
const std::string& ReplayRecorder::getCurrentFilePath() const
|
||||
{
|
||||
return m_filePath;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
|
||||
void close();
|
||||
bool isOpen() const;
|
||||
const std::string& currentFilePath() const;
|
||||
const std::string& getCurrentFilePath() const;
|
||||
|
||||
private:
|
||||
std::string m_configDir;
|
||||
|
||||
@@ -40,7 +40,6 @@ Simulation::Simulation(GameConfig config, unsigned int seed)
|
||||
, m_nextBuildingId(1)
|
||||
, m_buildingBlocksStock(m_config.world.startingBuildingBlocks)
|
||||
, m_gameOver(false)
|
||||
, m_hqBuildingId(kInvalidBuildingId)
|
||||
, m_hqProxyEntity(entt::null)
|
||||
, m_playerStation1Entity(entt::null)
|
||||
, m_playerStation2Entity(entt::null)
|
||||
@@ -76,34 +75,7 @@ Simulation::Simulation(GameConfig config, unsigned int seed)
|
||||
m_waveSystem = std::make_unique<WaveSystem>(m_config, m_rng);
|
||||
m_combatSystem = std::make_unique<CombatSystem>(m_config);
|
||||
|
||||
// Initialize ship schematic unlock state.
|
||||
for (const ShipDef& def : m_config.ships.ships)
|
||||
{
|
||||
SchematicState state;
|
||||
state.unlocked = (def.unlockAtStationLevel == -1);
|
||||
m_schematicLevels[def.id] = state;
|
||||
}
|
||||
|
||||
// Initialize module schematic unlock state.
|
||||
for (const ModuleDef& def : m_config.modules.modules)
|
||||
{
|
||||
SchematicState state;
|
||||
state.unlocked = (def.unlockAtStationLevel == -1);
|
||||
m_moduleSchematicLevels[def.id] = state;
|
||||
}
|
||||
|
||||
// Initialize assembler recipe schematic unlock state.
|
||||
for (const RecipeDef& def : m_config.recipes.recipes)
|
||||
{
|
||||
if (def.building == BuildingType::Assembler
|
||||
&& def.unlockAtStationLevel.has_value()
|
||||
&& def.unlockAtStationLevel.value() == -1)
|
||||
{
|
||||
m_unlockedRecipeSchematicIds.insert(def.id);
|
||||
}
|
||||
}
|
||||
|
||||
recomputeUnlocked();
|
||||
initializeUnlockState();
|
||||
placeInitialStructures();
|
||||
registerForEvents();
|
||||
}
|
||||
@@ -113,7 +85,7 @@ Simulation::~Simulation()
|
||||
unregisterForEvents();
|
||||
}
|
||||
|
||||
const GameConfig& Simulation::config() const
|
||||
const GameConfig& Simulation::getConfig() const
|
||||
{
|
||||
return m_config;
|
||||
}
|
||||
@@ -137,7 +109,7 @@ void Simulation::reset(unsigned int seed)
|
||||
m_gameOver = false;
|
||||
m_isWon = false;
|
||||
m_artifactCount = 0;
|
||||
m_hqBuildingId = kInvalidBuildingId;
|
||||
m_hqBuildingId = std::nullopt;
|
||||
m_hqProxyEntity = entt::null;
|
||||
m_playerStation1Entity = entt::null;
|
||||
m_playerStation2Entity = entt::null;
|
||||
@@ -175,11 +147,33 @@ void Simulation::reset(unsigned int seed)
|
||||
m_waveSystem = std::make_unique<WaveSystem>(m_config, m_rng);
|
||||
m_combatSystem = std::make_unique<CombatSystem>(m_config);
|
||||
|
||||
initializeUnlockState();
|
||||
placeInitialStructures();
|
||||
}
|
||||
|
||||
void Simulation::initializeUnlockState()
|
||||
{
|
||||
// Cache the ids granted by some unlock group (REQ-LOCK-EXPLICIT); an item
|
||||
// starts locked iff it is granted by a group.
|
||||
m_grantedShipIds.clear();
|
||||
m_grantedModuleIds.clear();
|
||||
m_grantedBuildingIds.clear();
|
||||
m_grantedRecipeIds.clear();
|
||||
for (const UnlockGroupDef& group : m_config.unlocks.groups)
|
||||
{
|
||||
m_grantedShipIds.insert(group.ships.begin(), group.ships.end());
|
||||
m_grantedModuleIds.insert(group.modules.begin(), group.modules.end());
|
||||
m_grantedBuildingIds.insert(group.buildings.begin(), group.buildings.end());
|
||||
m_grantedRecipeIds.insert(group.recipes.begin(), group.recipes.end());
|
||||
}
|
||||
|
||||
m_awardedUnlockGroupIds.clear();
|
||||
|
||||
m_schematicLevels.clear();
|
||||
for (const ShipDef& def : m_config.ships.ships)
|
||||
{
|
||||
SchematicState state;
|
||||
state.unlocked = (def.unlockAtStationLevel == -1);
|
||||
state.unlocked = (m_grantedShipIds.count(def.id) == 0);
|
||||
m_schematicLevels[def.id] = state;
|
||||
}
|
||||
|
||||
@@ -187,23 +181,23 @@ void Simulation::reset(unsigned int seed)
|
||||
for (const ModuleDef& def : m_config.modules.modules)
|
||||
{
|
||||
SchematicState state;
|
||||
state.unlocked = (def.unlockAtStationLevel == -1);
|
||||
state.unlocked = (m_grantedModuleIds.count(def.id) == 0);
|
||||
m_moduleSchematicLevels[def.id] = state;
|
||||
}
|
||||
|
||||
m_unlockedRecipeSchematicIds.clear();
|
||||
for (const RecipeDef& def : m_config.recipes.recipes)
|
||||
m_buildingLevels.clear();
|
||||
for (const BuildingDef& def : m_config.buildings.buildings)
|
||||
{
|
||||
if (def.building == BuildingType::Assembler
|
||||
&& def.unlockAtStationLevel.has_value()
|
||||
&& def.unlockAtStationLevel.value() == -1)
|
||||
{
|
||||
m_unlockedRecipeSchematicIds.insert(def.id);
|
||||
}
|
||||
SchematicState state;
|
||||
state.unlocked = (m_grantedBuildingIds.count(def.id) == 0);
|
||||
m_buildingLevels[def.id] = state;
|
||||
}
|
||||
|
||||
// Gated assembler recipes start locked; unlocked_at_start recipes are handled
|
||||
// in the REQ-LOCK-IMPLICIT traversal, not tracked here.
|
||||
m_unlockedRecipeSchematicIds.clear();
|
||||
|
||||
recomputeUnlocked();
|
||||
placeInitialStructures();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -217,11 +211,12 @@ void Simulation::apply(const Command& command)
|
||||
case CommandKind::PlaceBuilding:
|
||||
{
|
||||
const PlaceBuildingCommand& c = static_cast<const PlaceBuildingCommand&>(command);
|
||||
const BuildingId id = tryPlaceBuilding(c.type, c.anchor, c.rotation);
|
||||
if (id == kInvalidBuildingId)
|
||||
const std::optional<BuildingId> placed = tryPlaceBuilding(c.type, c.anchor, c.rotation);
|
||||
if (!placed.has_value())
|
||||
{
|
||||
break;
|
||||
}
|
||||
const BuildingId id = *placed;
|
||||
if (c.recipeId.has_value())
|
||||
{
|
||||
m_buildingSystem->setRecipe(id, *c.recipeId);
|
||||
@@ -236,32 +231,35 @@ void Simulation::apply(const Command& command)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CommandKind::Demolish:
|
||||
demolish(static_cast<const DemolishCommand&>(command).id);
|
||||
case CommandKind::Deconstruct:
|
||||
deconstruct(*static_cast<const DeconstructCommand&>(command).id);
|
||||
break;
|
||||
case CommandKind::CancelDeconstruction:
|
||||
cancelDeconstruction(*static_cast<const CancelDeconstructionCommand&>(command).id);
|
||||
break;
|
||||
case CommandKind::RotateInPlace:
|
||||
{
|
||||
const RotateInPlaceCommand& c = static_cast<const RotateInPlaceCommand&>(command);
|
||||
m_buildingSystem->rotateInPlace(c.id, c.newRotation);
|
||||
m_buildingSystem->rotateInPlace(*c.id, c.newRotation);
|
||||
break;
|
||||
}
|
||||
case CommandKind::SetRecipe:
|
||||
{
|
||||
const SetRecipeCommand& c = static_cast<const SetRecipeCommand&>(command);
|
||||
m_buildingSystem->setRecipe(c.id, c.recipeId);
|
||||
m_buildingSystem->setRecipe(*c.id, c.recipeId);
|
||||
break;
|
||||
}
|
||||
case CommandKind::SetShipLayout:
|
||||
{
|
||||
const SetShipLayoutCommand& c = static_cast<const SetShipLayoutCommand&>(command);
|
||||
m_buildingSystem->setShipLayout(c.id, c.layout);
|
||||
m_buildingSystem->setShipLayout(*c.id, c.layout);
|
||||
break;
|
||||
}
|
||||
case CommandKind::SetSiteSplitterFilters:
|
||||
{
|
||||
const SetSiteSplitterFiltersCommand& c =
|
||||
static_cast<const SetSiteSplitterFiltersCommand&>(command);
|
||||
m_buildingSystem->setSiteSplitterFilters(c.id, c.filterA, c.filterB);
|
||||
m_buildingSystem->setSiteSplitterFilters(*c.id, c.filterA, c.filterB);
|
||||
break;
|
||||
}
|
||||
case CommandKind::SetSplitterFilters:
|
||||
@@ -312,6 +310,7 @@ void Simulation::tick()
|
||||
|
||||
// Construction + production pipeline
|
||||
m_buildingSystem->tickConstruction(m_currentTick);
|
||||
m_buildingSystem->tickDeconstruction(m_currentTick); // parallel to construction
|
||||
m_buildingSystem->tickBeltPull(); // step 3
|
||||
m_buildingSystem->tickProduction(m_currentTick); // step 4
|
||||
m_buildingSystem->tickShipyardProduction(m_currentTick); // step 4b
|
||||
@@ -579,7 +578,7 @@ void Simulation::tickDeathsAndLoot()
|
||||
}
|
||||
else
|
||||
{
|
||||
const double genD = static_cast<double>(m_waveSystem->generation());
|
||||
const double genD = static_cast<double>(m_waveSystem->getGeneration());
|
||||
scrap = static_cast<int>(
|
||||
m_config.stations.enemyStation.scrapDropFormula.evaluate(genD));
|
||||
}
|
||||
@@ -619,52 +618,25 @@ void Simulation::tickDeathsAndLoot()
|
||||
if (es0Gone && es1Gone &&
|
||||
m_currentEnemyStationEntities[0] != entt::null)
|
||||
{
|
||||
const int destroyedLevel = m_waveSystem->generation();
|
||||
const int destroyedLevel = m_waveSystem->getGeneration();
|
||||
m_waveSystem->onEnemyStationsDestroyed();
|
||||
placeEnemyStationSet(m_waveSystem->generation());
|
||||
placeEnemyStationSet(m_waveSystem->getGeneration());
|
||||
generateSchematicChoices(destroyedLevel);
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::generateSchematicChoices(int destroyedStationLevel)
|
||||
{
|
||||
enum class DropType { Ship, Module, Recipe };
|
||||
struct PoolEntry { std::string id; DropType type; };
|
||||
std::vector<PoolEntry> pool;
|
||||
|
||||
// Owned schematics leave the pool (REQ-DEF-SCHEMATIC-DROP): only offer
|
||||
// ship/module schematics that are gated to a station level in range and not
|
||||
// yet unlocked. Schematics with unlock_at_station_level -1 start unlocked, so
|
||||
// they are always owned and never eligible.
|
||||
for (const ShipDef& def : m_config.ships.ships)
|
||||
// Build the eligible pool of unlock groups (REQ-DEF-SCHEMATIC-DROP,
|
||||
// REQ-LOCK-EXPLICIT, REQ-LOCK-PREREQ): not yet awarded, station level in
|
||||
// range, and every prerequisite group already awarded.
|
||||
std::vector<const UnlockGroupDef*> pool;
|
||||
for (const UnlockGroupDef& group : m_config.unlocks.groups)
|
||||
{
|
||||
if (def.unlockAtStationLevel < 0 || def.unlockAtStationLevel > destroyedStationLevel) { continue; }
|
||||
if (m_schematicLevels.at(def.id).unlocked) { continue; }
|
||||
if (!prerequisitesSatisfied(def.unlockRequires)) { continue; }
|
||||
pool.push_back({def.id, DropType::Ship});
|
||||
}
|
||||
for (const ModuleDef& def : m_config.modules.modules)
|
||||
{
|
||||
if (def.unlockAtStationLevel < 0 || def.unlockAtStationLevel > destroyedStationLevel) { continue; }
|
||||
if (m_moduleSchematicLevels.at(def.id).unlocked) { continue; }
|
||||
if (!prerequisitesSatisfied(def.unlockRequires)) { continue; }
|
||||
pool.push_back({def.id, DropType::Module});
|
||||
}
|
||||
for (const RecipeDef& def : m_config.recipes.recipes)
|
||||
{
|
||||
if (def.building != BuildingType::Assembler) { continue; }
|
||||
if (!def.unlockAtStationLevel.has_value()) { continue; }
|
||||
const int level = def.unlockAtStationLevel.value();
|
||||
if (level < 0 || level > destroyedStationLevel) { continue; }
|
||||
if (m_unlockedRecipeSchematicIds.count(def.id) > 0) { continue; }
|
||||
bool outputUnlocked = false;
|
||||
for (const RecipeOutput& out : def.outputs)
|
||||
{
|
||||
if (m_unlockedItemIds.count(out.item) > 0) { outputUnlocked = true; break; }
|
||||
}
|
||||
if (!outputUnlocked) { continue; }
|
||||
if (!prerequisitesSatisfied(def.unlockRequires)) { continue; }
|
||||
pool.push_back({def.id, DropType::Recipe});
|
||||
if (m_awardedUnlockGroupIds.count(group.id) > 0) { continue; }
|
||||
if (group.stationLevel < 0 || group.stationLevel > destroyedStationLevel) { continue; }
|
||||
if (!prerequisitesSatisfied(group.requiredGroupIds)) { continue; }
|
||||
pool.push_back(&group);
|
||||
}
|
||||
|
||||
if (pool.empty()) { return; }
|
||||
@@ -679,9 +651,6 @@ void Simulation::generateSchematicChoices(int destroyedStationLevel)
|
||||
const int numChoices = std::min(static_cast<int>(pool.size()), artifactRolled ? 2 : 3);
|
||||
m_pendingSchematicChoices.clear();
|
||||
|
||||
const std::set<std::string> currentShipIds = getUnlockedShipSchematicIds();
|
||||
const std::set<std::string> currentModuleIds = getUnlockedModuleSchematicIds();
|
||||
|
||||
for (int i = 0; i < numChoices; ++i)
|
||||
{
|
||||
std::uniform_int_distribution<int> dist(0, static_cast<int>(pool.size()) - 1 - i);
|
||||
@@ -689,68 +658,67 @@ void Simulation::generateSchematicChoices(int destroyedStationLevel)
|
||||
const std::size_t rollIdx = static_cast<std::size_t>(roll);
|
||||
const std::size_t endIdx = pool.size() - 1 - static_cast<std::size_t>(i);
|
||||
std::swap(pool[rollIdx], pool[endIdx]);
|
||||
const PoolEntry& entry = pool[endIdx];
|
||||
|
||||
SchematicChoiceOption option;
|
||||
option.schematicId = entry.id;
|
||||
|
||||
if (entry.type == DropType::Ship)
|
||||
{
|
||||
option.type = SchematicType::Ship;
|
||||
option.displayName = toDisplayName(entry.id);
|
||||
}
|
||||
else if (entry.type == DropType::Module)
|
||||
{
|
||||
option.type = SchematicType::Module;
|
||||
option.displayName = toDisplayName(entry.id);
|
||||
}
|
||||
else
|
||||
{
|
||||
option.type = SchematicType::Recipe;
|
||||
option.displayName = toDisplayName(entry.id);
|
||||
}
|
||||
|
||||
// REQ-DEF-SCHEMATIC-DROP: preview recipes newly implicitly unlocked by this option.
|
||||
std::set<std::string> hypotheticalShipIds = currentShipIds;
|
||||
std::set<std::string> hypotheticalModuleIds = currentModuleIds;
|
||||
std::set<std::string> hypotheticalRecipeSchematicIds = m_unlockedRecipeSchematicIds;
|
||||
|
||||
if (entry.type == DropType::Ship)
|
||||
{
|
||||
hypotheticalShipIds.insert(entry.id);
|
||||
}
|
||||
else if (entry.type == DropType::Module)
|
||||
{
|
||||
hypotheticalModuleIds.insert(entry.id);
|
||||
}
|
||||
else if (entry.type == DropType::Recipe)
|
||||
{
|
||||
hypotheticalRecipeSchematicIds.insert(entry.id);
|
||||
}
|
||||
|
||||
const UnlockedSets hypothetical = computeUnlockedSets(
|
||||
hypotheticalShipIds, hypotheticalModuleIds, hypotheticalRecipeSchematicIds);
|
||||
option.newlyUnlockedRecipeIds = computeNewlyUnlockedRecipeIds(hypothetical);
|
||||
|
||||
m_pendingSchematicChoices.push_back(option);
|
||||
m_pendingSchematicChoices.push_back(makeUnlockOption(*pool[endIdx]));
|
||||
}
|
||||
|
||||
if (artifactRolled)
|
||||
{
|
||||
SchematicChoiceOption artifactOption;
|
||||
artifactOption.schematicId = "";
|
||||
artifactOption.type = SchematicType::Artifact;
|
||||
artifactOption.displayName = "Artifact";
|
||||
artifactOption.isArtifact = true;
|
||||
artifactOption.displayName = "Artifact";
|
||||
m_pendingSchematicChoices.push_back(std::move(artifactOption));
|
||||
}
|
||||
}
|
||||
|
||||
SchematicChoiceOption Simulation::makeUnlockOption(const UnlockGroupDef& group) const
|
||||
{
|
||||
SchematicChoiceOption option;
|
||||
option.isArtifact = false;
|
||||
option.unlockGroupId = group.id;
|
||||
option.displayName = toDisplayName(group.id);
|
||||
|
||||
for (const std::string& id : group.ships)
|
||||
{
|
||||
option.grantedItems.push_back({SchematicType::Ship, id, toDisplayName(id)});
|
||||
}
|
||||
for (const std::string& id : group.modules)
|
||||
{
|
||||
option.grantedItems.push_back({SchematicType::Module, id, toDisplayName(id)});
|
||||
}
|
||||
for (const std::string& id : group.buildings)
|
||||
{
|
||||
option.grantedItems.push_back({SchematicType::Building, id, toDisplayName(id)});
|
||||
}
|
||||
for (const std::string& id : group.recipes)
|
||||
{
|
||||
option.grantedItems.push_back({SchematicType::Recipe, id, toDisplayName(id)});
|
||||
}
|
||||
|
||||
// REQ-DEF-SCHEMATIC-DROP: preview recipes newly implicitly unlocked by
|
||||
// awarding this whole group. Seed the hypothetical explicit-unlock sets with
|
||||
// every grant (ship + module materials via step 1a, recipe outputs via step
|
||||
// 1b), then diff against the current implicit set.
|
||||
std::set<std::string> hypotheticalShipIds = getUnlockedShipSchematicIds();
|
||||
std::set<std::string> hypotheticalModuleIds = getUnlockedModuleSchematicIds();
|
||||
std::set<std::string> hypotheticalRecipeSchematicIds = m_unlockedRecipeSchematicIds;
|
||||
for (const std::string& id : group.ships) { hypotheticalShipIds.insert(id); }
|
||||
for (const std::string& id : group.modules) { hypotheticalModuleIds.insert(id); }
|
||||
for (const std::string& id : group.recipes) { hypotheticalRecipeSchematicIds.insert(id); }
|
||||
|
||||
const UnlockedSets hypothetical = computeUnlockedSets(
|
||||
hypotheticalShipIds, hypotheticalModuleIds, hypotheticalRecipeSchematicIds);
|
||||
option.newlyUnlockedRecipeIds = computeNewlyUnlockedRecipeIds(hypothetical);
|
||||
|
||||
return option;
|
||||
}
|
||||
|
||||
void Simulation::applySchematicChoice(int choiceIndex)
|
||||
{
|
||||
assert(choiceIndex >= 0 && choiceIndex < static_cast<int>(m_pendingSchematicChoices.size()));
|
||||
const SchematicChoiceOption& chosen = m_pendingSchematicChoices[static_cast<std::size_t>(choiceIndex)];
|
||||
|
||||
if (chosen.type == SchematicType::Artifact)
|
||||
if (chosen.isArtifact)
|
||||
{
|
||||
m_artifactCount += 1;
|
||||
if (m_artifactCount >= m_config.world.artifacts.artifactWinCount)
|
||||
@@ -761,16 +729,18 @@ void Simulation::applySchematicChoice(int choiceIndex)
|
||||
return;
|
||||
}
|
||||
|
||||
if (chosen.type == SchematicType::Recipe)
|
||||
// Award the whole unlock group (REQ-DEF-SCHEMATIC-DROP): unlock every granted
|
||||
// ship, module, building, and assembler recipe at once.
|
||||
m_awardedUnlockGroupIds.insert(chosen.unlockGroupId);
|
||||
for (const GrantedSchematic& grant : chosen.grantedItems)
|
||||
{
|
||||
m_unlockedRecipeSchematicIds.insert(chosen.schematicId);
|
||||
}
|
||||
else
|
||||
{
|
||||
SchematicState& state = (chosen.type == SchematicType::Module)
|
||||
? m_moduleSchematicLevels.at(chosen.schematicId)
|
||||
: m_schematicLevels.at(chosen.schematicId);
|
||||
state.unlocked = true;
|
||||
switch (grant.type)
|
||||
{
|
||||
case SchematicType::Ship: m_schematicLevels.at(grant.id).unlocked = true; break;
|
||||
case SchematicType::Module: m_moduleSchematicLevels.at(grant.id).unlocked = true; break;
|
||||
case SchematicType::Building: m_buildingLevels.at(grant.id).unlocked = true; break;
|
||||
case SchematicType::Recipe: m_unlockedRecipeSchematicIds.insert(grant.id); break;
|
||||
}
|
||||
}
|
||||
|
||||
recomputeUnlocked();
|
||||
@@ -809,28 +779,13 @@ std::set<std::string> Simulation::getUnlockedModuleSchematicIds() const
|
||||
return ids;
|
||||
}
|
||||
|
||||
bool Simulation::isSchematicIdExplicitlyUnlocked(const std::string& schematicId) const
|
||||
bool Simulation::prerequisitesSatisfied(const std::vector<std::string>& requiredGroupIds) const
|
||||
{
|
||||
// A prerequisite is satisfied only by an explicitly-unlocked schematic
|
||||
// (REQ-LOCK-PREREQ): a ship or module schematic marked unlocked, or a recipe
|
||||
// schematic in the explicit-unlock set. Cross-type ids are looked up with
|
||||
// find/count so an id from one namespace never throws against another.
|
||||
const std::map<std::string, SchematicState>::const_iterator shipIt =
|
||||
m_schematicLevels.find(schematicId);
|
||||
if (shipIt != m_schematicLevels.end() && shipIt->second.unlocked) { return true; }
|
||||
|
||||
const std::map<std::string, SchematicState>::const_iterator moduleIt =
|
||||
m_moduleSchematicLevels.find(schematicId);
|
||||
if (moduleIt != m_moduleSchematicLevels.end() && moduleIt->second.unlocked) { return true; }
|
||||
|
||||
return m_unlockedRecipeSchematicIds.count(schematicId) > 0;
|
||||
}
|
||||
|
||||
bool Simulation::prerequisitesSatisfied(const std::vector<std::string>& unlockRequires) const
|
||||
{
|
||||
for (const std::string& requiredId : unlockRequires)
|
||||
// A prerequisite is satisfied only once the named unlock group has been
|
||||
// awarded (REQ-LOCK-PREREQ).
|
||||
for (const std::string& groupId : requiredGroupIds)
|
||||
{
|
||||
if (!isSchematicIdExplicitlyUnlocked(requiredId)) { return false; }
|
||||
if (m_awardedUnlockGroupIds.count(groupId) == 0) { return false; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -860,9 +815,11 @@ Simulation::UnlockedSets Simulation::computeUnlockedSets(
|
||||
}
|
||||
for (const RecipeDef& def : m_config.recipes.recipes)
|
||||
{
|
||||
// An assembler recipe seeds the base set when it is explicitly available:
|
||||
// flagged unlocked_at_start (base recipes the graph can't reach), or a
|
||||
// gated recipe whose unlock group has been awarded (REQ-LOCK-EXPLICIT).
|
||||
if (def.building == BuildingType::Assembler
|
||||
&& def.unlockAtStationLevel.has_value()
|
||||
&& unlockedRecipeSchematicIds.count(def.id) > 0)
|
||||
&& (def.unlockedAtStart || unlockedRecipeSchematicIds.count(def.id) > 0))
|
||||
{
|
||||
for (const RecipeOutput& out : def.outputs)
|
||||
{
|
||||
@@ -883,8 +840,10 @@ Simulation::UnlockedSets Simulation::computeUnlockedSets(
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// Skip a gated assembler recipe (granted by an unlock group) whose
|
||||
// group has not yet been awarded (REQ-LOCK-IMPLICIT step 2).
|
||||
if (recipe.building == BuildingType::Assembler
|
||||
&& recipe.unlockAtStationLevel.has_value()
|
||||
&& m_grantedRecipeIds.count(recipe.id) > 0
|
||||
&& unlockedRecipeSchematicIds.count(recipe.id) == 0)
|
||||
{
|
||||
continue;
|
||||
@@ -968,7 +927,7 @@ void Simulation::appendStringSet(Hasher& hasher, const std::set<std::string>& id
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long long Simulation::rngFingerprint() const
|
||||
unsigned long long Simulation::getRngFingerprint() const
|
||||
{
|
||||
return fingerprintRng(m_rng);
|
||||
}
|
||||
@@ -991,15 +950,17 @@ unsigned long long Simulation::computeStateChecksum() const
|
||||
hasher.append(m_expansionsPurchased);
|
||||
|
||||
// WaveSystem scalar state, reached through existing accessors.
|
||||
hasher.append(threatLevel());
|
||||
hasher.append(threatAccumulationRate());
|
||||
hasher.append(bossWaveCounter());
|
||||
hasher.append(bossCountdownTicks());
|
||||
hasher.append(normalGapRemainingTicks());
|
||||
hasher.append(getThreatLevel());
|
||||
hasher.append(getThreatAccumulationRate());
|
||||
hasher.append(getBossWaveCounter());
|
||||
hasher.append(getBossCountdownTicks());
|
||||
hasher.append(getNormalGapRemainingTicks());
|
||||
|
||||
// Schematic / unlock state (std::map and std::set iterate in sorted order).
|
||||
appendSchematicMap(hasher, m_schematicLevels);
|
||||
appendSchematicMap(hasher, m_moduleSchematicLevels);
|
||||
appendSchematicMap(hasher, m_buildingLevels);
|
||||
appendStringSet(hasher, m_awardedUnlockGroupIds);
|
||||
appendStringSet(hasher, m_unlockedRecipeSchematicIds);
|
||||
appendStringSet(hasher, m_unlockedRecipeIds);
|
||||
appendStringSet(hasher, m_unlockedItemIds);
|
||||
@@ -1052,7 +1013,7 @@ unsigned long long Simulation::computeStateChecksum() const
|
||||
hasher.append(c.schematicId);
|
||||
});
|
||||
|
||||
return hasher.value();
|
||||
return hasher.getValue();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -1081,7 +1042,7 @@ bool Simulation::hasSchematicChoicesPending() const
|
||||
// Accessors
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Tick Simulation::currentTick() const
|
||||
Tick Simulation::getCurrentTick() const
|
||||
{
|
||||
return m_currentTick;
|
||||
}
|
||||
@@ -1091,18 +1052,18 @@ unsigned int Simulation::getSeed() const
|
||||
return m_seed;
|
||||
}
|
||||
|
||||
int Simulation::buildingBlocksStock() const
|
||||
int Simulation::getBuildingBlocksStock() const
|
||||
{
|
||||
return m_buildingBlocksStock;
|
||||
}
|
||||
|
||||
int Simulation::currentAsteroidWidth_tiles() const
|
||||
int Simulation::getCurrentAsteroidWidth_tiles() const
|
||||
{
|
||||
return m_config.world.regions.asteroidWidth_tiles
|
||||
+ m_expansionsPurchased * m_config.world.expansion.columnsPerExpansion_tiles;
|
||||
}
|
||||
|
||||
int Simulation::currentExpansionCost() const
|
||||
int Simulation::getCurrentExpansionCost() const
|
||||
{
|
||||
const double cost = m_config.world.expansion.costBuildingBlocksFormula.evaluate(
|
||||
static_cast<double>(m_expansionsPurchased));
|
||||
@@ -1111,14 +1072,14 @@ int Simulation::currentExpansionCost() const
|
||||
|
||||
void Simulation::tryExpandAsteroid()
|
||||
{
|
||||
const int cost = currentExpansionCost();
|
||||
const int cost = getCurrentExpansionCost();
|
||||
if (m_buildingBlocksStock < cost)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_buildingBlocksStock -= cost;
|
||||
++m_expansionsPurchased;
|
||||
m_buildingSystem->setAsteroidWidth_tiles(currentAsteroidWidth_tiles());
|
||||
m_buildingSystem->setAsteroidWidth_tiles(getCurrentAsteroidWidth_tiles());
|
||||
}
|
||||
|
||||
bool Simulation::isGameOver() const
|
||||
@@ -1131,44 +1092,44 @@ bool Simulation::isWon() const
|
||||
return m_isWon;
|
||||
}
|
||||
|
||||
int Simulation::artifactCount() const
|
||||
int Simulation::getArtifactCount() const
|
||||
{
|
||||
return m_artifactCount;
|
||||
}
|
||||
|
||||
double Simulation::threatLevel() const
|
||||
double Simulation::getThreatLevel() const
|
||||
{
|
||||
return m_waveSystem->threatLevel();
|
||||
return m_waveSystem->getThreatLevel();
|
||||
}
|
||||
|
||||
double Simulation::threatAccumulationRate() const
|
||||
double Simulation::getThreatAccumulationRate() const
|
||||
{
|
||||
return m_waveSystem->threatAccumulationRate();
|
||||
return m_waveSystem->getThreatAccumulationRate();
|
||||
}
|
||||
|
||||
double Simulation::maxFactoryProductionThreatRate() const
|
||||
double Simulation::getMaxFactoryProductionThreatRate() const
|
||||
{
|
||||
return static_cast<double>(m_buildingSystem->productionBuildingCount());
|
||||
return static_cast<double>(m_buildingSystem->getProductionBuildingCount());
|
||||
}
|
||||
|
||||
double Simulation::currentFactoryProductionThreatRate() const
|
||||
double Simulation::getCurrentFactoryProductionThreatRate() const
|
||||
{
|
||||
return static_cast<double>(m_buildingSystem->activeProductionBuildingCount());
|
||||
return static_cast<double>(m_buildingSystem->getActiveProductionBuildingCount());
|
||||
}
|
||||
|
||||
int Simulation::bossWaveCounter() const
|
||||
int Simulation::getBossWaveCounter() const
|
||||
{
|
||||
return m_waveSystem->bossWaveCounter();
|
||||
return m_waveSystem->getBossWaveCounter();
|
||||
}
|
||||
|
||||
Tick Simulation::bossCountdownTicks() const
|
||||
Tick Simulation::getBossCountdownTicks() const
|
||||
{
|
||||
return m_waveSystem->bossCountdownTicks();
|
||||
return m_waveSystem->getBossCountdownTicks();
|
||||
}
|
||||
|
||||
Tick Simulation::normalGapRemainingTicks() const
|
||||
Tick Simulation::getNormalGapRemainingTicks() const
|
||||
{
|
||||
return m_waveSystem->normalGapRemainingTicks();
|
||||
return m_waveSystem->getNormalGapRemainingTicks();
|
||||
}
|
||||
|
||||
bool Simulation::isSchematicUnlocked(const std::string& shipId) const
|
||||
@@ -1193,11 +1154,31 @@ bool Simulation::isModuleSchematicUnlocked(const std::string& moduleId) const
|
||||
return it->second.unlocked;
|
||||
}
|
||||
|
||||
BuildingId Simulation::tryPlaceBuilding(BuildingType type, QPoint anchor, Rotation rotation)
|
||||
bool Simulation::isBuildingUnlocked(BuildingType type) const
|
||||
{
|
||||
const BuildingDef* def = m_config.buildings.findBuildingDef(type);
|
||||
if (def == nullptr)
|
||||
{
|
||||
// Types without a config entry (e.g. HQ, defence stations) are unrestricted.
|
||||
return true;
|
||||
}
|
||||
const std::map<std::string, SchematicState>::const_iterator it =
|
||||
m_buildingLevels.find(def->id);
|
||||
return it == m_buildingLevels.end() ? true : it->second.unlocked;
|
||||
}
|
||||
|
||||
std::optional<BuildingId> Simulation::tryPlaceBuilding(BuildingType type, QPoint anchor, Rotation rotation)
|
||||
{
|
||||
// Locked building types cannot be placed (REQ-LOCK-BUILDING); the build menu
|
||||
// hides them, this is the simulation-side backstop (e.g. blueprint placement).
|
||||
if (!isBuildingUnlocked(type))
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (!m_buildingSystem->isPlacementValid(type, anchor, rotation))
|
||||
{
|
||||
return kInvalidBuildingId;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
int cost = 0;
|
||||
@@ -1211,63 +1192,68 @@ BuildingId Simulation::tryPlaceBuilding(BuildingType type, QPoint anchor, Rotati
|
||||
}
|
||||
if (m_buildingBlocksStock < cost)
|
||||
{
|
||||
return kInvalidBuildingId;
|
||||
return std::nullopt;
|
||||
}
|
||||
m_buildingBlocksStock -= cost;
|
||||
return m_buildingSystem->place(type, anchor, rotation, m_currentTick);
|
||||
}
|
||||
|
||||
void Simulation::demolish(BuildingId id)
|
||||
void Simulation::deconstruct(BuildingId id)
|
||||
{
|
||||
m_buildingBlocksStock += m_buildingSystem->demolish(id);
|
||||
m_buildingBlocksStock += m_buildingSystem->deconstruct(id, m_currentTick);
|
||||
}
|
||||
|
||||
BuildingSystem& Simulation::buildingsMutable()
|
||||
void Simulation::cancelDeconstruction(BuildingId id)
|
||||
{
|
||||
m_buildingSystem->cancelDeconstruction(id);
|
||||
}
|
||||
|
||||
BuildingSystem& Simulation::getBuildingsMutable()
|
||||
{
|
||||
return *m_buildingSystem;
|
||||
}
|
||||
|
||||
const BuildingSystem& Simulation::buildings() const
|
||||
const BuildingSystem& Simulation::getBuildings() const
|
||||
{
|
||||
return *m_buildingSystem;
|
||||
}
|
||||
|
||||
BeltSystem& Simulation::beltsMutable()
|
||||
BeltSystem& Simulation::getBeltsMutable()
|
||||
{
|
||||
return m_beltSystem;
|
||||
}
|
||||
|
||||
const BeltSystem& Simulation::belts() const
|
||||
const BeltSystem& Simulation::getBelts() const
|
||||
{
|
||||
return m_beltSystem;
|
||||
}
|
||||
|
||||
ShipSystem& Simulation::ships()
|
||||
ShipSystem& Simulation::getShips()
|
||||
{
|
||||
return *m_shipSystem;
|
||||
}
|
||||
|
||||
const ShipSystem& Simulation::ships() const
|
||||
const ShipSystem& Simulation::getShips() const
|
||||
{
|
||||
return *m_shipSystem;
|
||||
}
|
||||
|
||||
ScrapSystem& Simulation::scraps()
|
||||
ScrapSystem& Simulation::getScraps()
|
||||
{
|
||||
return *m_scrapSystem;
|
||||
}
|
||||
|
||||
const ScrapSystem& Simulation::scraps() const
|
||||
const ScrapSystem& Simulation::getScraps() const
|
||||
{
|
||||
return *m_scrapSystem;
|
||||
}
|
||||
|
||||
EntityAdmin& Simulation::admin()
|
||||
EntityAdmin& Simulation::getAdmin()
|
||||
{
|
||||
return m_admin;
|
||||
}
|
||||
|
||||
const EntityAdmin& Simulation::admin() const
|
||||
const EntityAdmin& Simulation::getAdmin() const
|
||||
{
|
||||
return m_admin;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <random>
|
||||
#include <set>
|
||||
#include <string>
|
||||
@@ -41,7 +42,7 @@ public:
|
||||
explicit Simulation(GameConfig config, unsigned int seed = 0);
|
||||
~Simulation();
|
||||
|
||||
const GameConfig& config() const;
|
||||
const GameConfig& getConfig() const;
|
||||
|
||||
// Reinitializes all simulation state as if constructed fresh.
|
||||
void reset(unsigned int seed = 0);
|
||||
@@ -68,26 +69,26 @@ public:
|
||||
// Returns true if there are pending schematic choices waiting for player input.
|
||||
bool hasSchematicChoicesPending() const;
|
||||
|
||||
Tick currentTick() const;
|
||||
Tick getCurrentTick() const;
|
||||
// The seed this run was (re)initialized with; written to the replay header.
|
||||
unsigned int getSeed() const;
|
||||
int buildingBlocksStock() const;
|
||||
int getBuildingBlocksStock() const;
|
||||
// Current asteroid width in tiles = base width + purchased expansions
|
||||
// (REQ-EXP-UNLOCK, REQ-GW-ASTEROID-EXPAND).
|
||||
int currentAsteroidWidth_tiles() const;
|
||||
int getCurrentAsteroidWidth_tiles() const;
|
||||
// Building block cost of the next expansion, floored to an integer
|
||||
// (REQ-EXP-COST); x = number of expansions already purchased.
|
||||
int currentExpansionCost() const;
|
||||
int getCurrentExpansionCost() const;
|
||||
bool isGameOver() const;
|
||||
bool isWon() const;
|
||||
int artifactCount() const;
|
||||
double threatLevel() const;
|
||||
double threatAccumulationRate() const;
|
||||
double maxFactoryProductionThreatRate() const;
|
||||
double currentFactoryProductionThreatRate() const;
|
||||
int bossWaveCounter() const;
|
||||
Tick bossCountdownTicks() const;
|
||||
Tick normalGapRemainingTicks() const;
|
||||
int getArtifactCount() const;
|
||||
double getThreatLevel() const;
|
||||
double getThreatAccumulationRate() const;
|
||||
double getMaxFactoryProductionThreatRate() const;
|
||||
double getCurrentFactoryProductionThreatRate() const;
|
||||
int getBossWaveCounter() const;
|
||||
Tick getBossCountdownTicks() const;
|
||||
Tick getNormalGapRemainingTicks() const;
|
||||
|
||||
// Ship schematic state query.
|
||||
bool isSchematicUnlocked(const std::string& shipId) const;
|
||||
@@ -99,28 +100,32 @@ public:
|
||||
bool isRecipeUnlocked(const std::string& recipeId) const;
|
||||
bool isItemUnlocked(const std::string& itemId) const;
|
||||
|
||||
// Building unlock query (REQ-LOCK-BUILDING). True if the building type is not
|
||||
// gated by any unlock group, or its granting group has been awarded.
|
||||
bool isBuildingUnlocked(BuildingType type) const;
|
||||
|
||||
// -- Determinism (see docs/replay_design.md) -----------------------------
|
||||
// 64-bit fingerprint of the RNG stream state. Cheap; written to the replay
|
||||
// file periodically + after each command for desync detection.
|
||||
unsigned long long rngFingerprint() const;
|
||||
unsigned long long getRngFingerprint() const;
|
||||
|
||||
// 64-bit fingerprint of the full simulation state (RNG, scalars, buildings,
|
||||
// belts, and ECS component state). Used by the double-run determinism test;
|
||||
// a superset of rngFingerprint().
|
||||
// a superset of getRngFingerprint().
|
||||
unsigned long long computeStateChecksum() const;
|
||||
|
||||
// Const subsystem accessors (queries only). The mutable counterparts are
|
||||
// private and reachable only through Simulation::apply (the command
|
||||
// chokepoint) or, in tests, SimulationTestAccess — so production code cannot
|
||||
// mutate the factory outside the recorded command path (docs/replay_design.md).
|
||||
const BuildingSystem& buildings() const;
|
||||
const BeltSystem& belts() const;
|
||||
ShipSystem& ships();
|
||||
const ShipSystem& ships() const;
|
||||
ScrapSystem& scraps();
|
||||
const ScrapSystem& scraps() const;
|
||||
EntityAdmin& admin();
|
||||
const EntityAdmin& admin() const;
|
||||
const BuildingSystem& getBuildings() const;
|
||||
const BeltSystem& getBelts() const;
|
||||
ShipSystem& getShips();
|
||||
const ShipSystem& getShips() const;
|
||||
ScrapSystem& getScraps();
|
||||
const ScrapSystem& getScraps() const;
|
||||
EntityAdmin& getAdmin();
|
||||
const EntityAdmin& getAdmin() const;
|
||||
|
||||
private:
|
||||
// Grants tests access to the private player-action mutators below without
|
||||
@@ -131,11 +136,16 @@ private:
|
||||
// Reached during play exclusively via apply(); never called by UI/app code.
|
||||
|
||||
// Checks affordability, deducts building blocks, and places the building.
|
||||
// Returns the new entity id, or kInvalidBuildingId if blocks are insufficient.
|
||||
BuildingId tryPlaceBuilding(BuildingType type, QPoint anchor, Rotation rotation);
|
||||
// Returns the new entity id, or nullopt if blocks are insufficient.
|
||||
std::optional<BuildingId> tryPlaceBuilding(BuildingType type, QPoint anchor, Rotation rotation);
|
||||
|
||||
// Demolishes the building with the given id and refunds building blocks.
|
||||
void demolish(BuildingId id);
|
||||
// Marks the building with the given id for demolition: a construction site is
|
||||
// removed instantly (full refund), a built building is queued for timed
|
||||
// deconstruction (REQ-BLD-DECON-QUEUE), refunded on completion.
|
||||
void deconstruct(BuildingId id);
|
||||
|
||||
// Takes a queued building back out of the deconstruction queue (REQ-BLD-DECON-QUEUE).
|
||||
void cancelDeconstruction(BuildingId id);
|
||||
|
||||
// Applies the player's chosen schematic from the pending choices.
|
||||
// choiceIndex must be in [0, pendingChoices.size()).
|
||||
@@ -148,8 +158,8 @@ private:
|
||||
void tryExpandAsteroid();
|
||||
|
||||
// Mutable subsystem accessors; same chokepoint rule as the mutators above.
|
||||
BuildingSystem& buildingsMutable();
|
||||
BeltSystem& beltsMutable();
|
||||
BuildingSystem& getBuildingsMutable();
|
||||
BeltSystem& getBeltsMutable();
|
||||
|
||||
void handleEvent(std::shared_ptr<const TracePrintRequestedEvent> event) override;
|
||||
|
||||
@@ -182,7 +192,7 @@ private:
|
||||
int m_artifactCount = 0;
|
||||
|
||||
// Pre-placed structure IDs.
|
||||
BuildingId m_hqBuildingId; // Building id (for belt integration)
|
||||
std::optional<BuildingId> m_hqBuildingId; // Building id (for belt integration)
|
||||
entt::entity m_hqProxyEntity; // ECS entity (HP, targeting)
|
||||
entt::entity m_playerStation1Entity;
|
||||
entt::entity m_playerStation2Entity;
|
||||
@@ -195,6 +205,24 @@ private:
|
||||
};
|
||||
std::map<std::string, SchematicState> m_schematicLevels;
|
||||
std::map<std::string, SchematicState> m_moduleSchematicLevels;
|
||||
std::map<std::string, SchematicState> m_buildingLevels;
|
||||
|
||||
// Unlock groups awarded so far (REQ-LOCK-EXPLICIT). Group ids.
|
||||
std::set<std::string> m_awardedUnlockGroupIds;
|
||||
|
||||
// Ids granted by some unlock group, per kind — cached from config at init.
|
||||
// An item starts locked iff it appears in the corresponding set.
|
||||
std::set<std::string> m_grantedShipIds;
|
||||
std::set<std::string> m_grantedModuleIds;
|
||||
std::set<std::string> m_grantedBuildingIds;
|
||||
std::set<std::string> m_grantedRecipeIds;
|
||||
|
||||
// Builds the granted-id sets and initializes all per-item unlock maps from
|
||||
// them (shared by the constructor and reset). Ends with recomputeUnlocked().
|
||||
void initializeUnlockState();
|
||||
|
||||
// Builds a schematic choice option for one unlock group (REQ-DEF-SCHEMATIC-DROP).
|
||||
SchematicChoiceOption makeUnlockOption(const UnlockGroupDef& group) const;
|
||||
|
||||
// Determinism helpers — fold sub-state into the hasher in deterministic order.
|
||||
static void appendSchematicMap(Hasher& hasher,
|
||||
@@ -227,11 +255,8 @@ private:
|
||||
std::set<std::string> getUnlockedShipSchematicIds() const;
|
||||
std::set<std::string> getUnlockedModuleSchematicIds() const;
|
||||
|
||||
// True if schematicId names a currently explicitly-unlocked ship, module, or
|
||||
// assembler recipe schematic (REQ-LOCK-PREREQ satisfaction basis).
|
||||
bool isSchematicIdExplicitlyUnlocked(const std::string& schematicId) const;
|
||||
// True if every prerequisite in unlockRequires is explicitly unlocked (REQ-LOCK-PREREQ).
|
||||
bool prerequisitesSatisfied(const std::vector<std::string>& unlockRequires) const;
|
||||
// True if every prerequisite unlock group has been awarded (REQ-LOCK-PREREQ).
|
||||
bool prerequisitesSatisfied(const std::vector<std::string>& requiredGroupIds) const;
|
||||
|
||||
// Ids (sorted alphabetically by display name) of the recipes in
|
||||
// hypothetical.recipeIds that are not yet in m_unlockedRecipeIds.
|
||||
|
||||
@@ -57,5 +57,5 @@ std::uint64_t fingerprintRng(const std::mt19937& rng)
|
||||
stream << rng; // full internal state as space-separated integers
|
||||
Hasher hasher;
|
||||
hasher.append(stream.str());
|
||||
return hasher.value();
|
||||
return hasher.getValue();
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
void append(const QVector2D& vector);
|
||||
void append(const std::string& text);
|
||||
|
||||
std::uint64_t value() const { return m_state; }
|
||||
std::uint64_t getValue() const { return m_state; }
|
||||
|
||||
private:
|
||||
std::uint64_t m_state = 14695981039346656037ull; // FNV-1a 64-bit offset basis
|
||||
|
||||
@@ -98,12 +98,12 @@ void WaveSystem::onEnemyStationsDestroyed()
|
||||
++m_generation;
|
||||
}
|
||||
|
||||
double WaveSystem::threatLevel() const
|
||||
double WaveSystem::getThreatLevel() const
|
||||
{
|
||||
return m_threatLevel;
|
||||
}
|
||||
|
||||
double WaveSystem::threatAccumulationRate() const
|
||||
double WaveSystem::getThreatAccumulationRate() const
|
||||
{
|
||||
if (isInQuietWindow())
|
||||
{
|
||||
@@ -113,22 +113,22 @@ double WaveSystem::threatAccumulationRate() const
|
||||
return std::max(0.0, m_config.world.waves.threatRateFormula.evaluate(x));
|
||||
}
|
||||
|
||||
int WaveSystem::generation() const
|
||||
int WaveSystem::getGeneration() const
|
||||
{
|
||||
return m_generation;
|
||||
}
|
||||
|
||||
int WaveSystem::bossWaveCounter() const
|
||||
int WaveSystem::getBossWaveCounter() const
|
||||
{
|
||||
return m_bossWaveCounter;
|
||||
}
|
||||
|
||||
Tick WaveSystem::bossCountdownTicks() const
|
||||
Tick WaveSystem::getBossCountdownTicks() const
|
||||
{
|
||||
return m_bossCountdownTicks;
|
||||
}
|
||||
|
||||
Tick WaveSystem::normalGapRemainingTicks() const
|
||||
Tick WaveSystem::getNormalGapRemainingTicks() const
|
||||
{
|
||||
return m_normalGapRemainingTicks;
|
||||
}
|
||||
|
||||
@@ -34,26 +34,26 @@ public:
|
||||
// (REQ-WAV-BOSS-ADVANCE, REQ-PSH-STATION-STATS).
|
||||
void onEnemyStationsDestroyed();
|
||||
|
||||
double threatLevel() const;
|
||||
double getThreatLevel() const;
|
||||
|
||||
// Current rate at which threatLevel() is increasing, in threat/second
|
||||
// Current rate at which getThreatLevel() is increasing, in threat/second
|
||||
// (REQ-WAV-THREAT-RATE). 0 during a quiet window (REQ-WAV-QUIET) or when
|
||||
// the rate formula evaluates to a negative value.
|
||||
double threatAccumulationRate() const;
|
||||
double getThreatAccumulationRate() const;
|
||||
|
||||
// Current enemy-station generation level (0 for initial set,
|
||||
// incremented by 1 after each push — REQ-PSH-STATION-STATS).
|
||||
int generation() const;
|
||||
int getGeneration() const;
|
||||
|
||||
// Boss wave counter (REQ-WAV-BOSS-COUNTER): current cycle number, starts at 1.
|
||||
int bossWaveCounter() const;
|
||||
int getBossWaveCounter() const;
|
||||
|
||||
// Ticks remaining until the next boss wave fires (REQ-WAV-BOSS-COUNTDOWN).
|
||||
Tick bossCountdownTicks() const;
|
||||
Tick getBossCountdownTicks() const;
|
||||
|
||||
// Ticks remaining on the current normal-wave gap timer (REQ-WAV-GAP).
|
||||
// Frozen during quiet windows.
|
||||
Tick normalGapRemainingTicks() const;
|
||||
Tick getNormalGapRemainingTicks() const;
|
||||
|
||||
private:
|
||||
struct SpawnEntry
|
||||
|
||||
@@ -19,7 +19,7 @@ static GameConfig loadConfig()
|
||||
|
||||
static void killEnemyStations(Simulation& sim)
|
||||
{
|
||||
sim.admin().forEach<StationBodyComponent, FactionComponent, HealthComponent>(
|
||||
sim.getAdmin().forEach<StationBodyComponent, FactionComponent, HealthComponent>(
|
||||
[](entt::entity, StationBodyComponent&, FactionComponent& faction, HealthComponent& health)
|
||||
{
|
||||
if (faction.isEnemy)
|
||||
@@ -36,7 +36,7 @@ static int findArtifactChoiceIndex(const Simulation& sim)
|
||||
const auto& choices = sim.getPendingSchematicChoices();
|
||||
for (int i = 0; i < static_cast<int>(choices.size()); ++i)
|
||||
{
|
||||
if (choices[static_cast<std::size_t>(i)].type == SchematicType::Artifact)
|
||||
if (choices[static_cast<std::size_t>(i)].isArtifact)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ TEST_CASE("ArtifactWinCondition: artifact count is 0 and isWon is false at game
|
||||
"[artifact_win]")
|
||||
{
|
||||
const Simulation sim(loadConfig());
|
||||
CHECK(sim.artifactCount() == 0);
|
||||
CHECK(sim.getArtifactCount() == 0);
|
||||
CHECK_FALSE(sim.isWon());
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ TEST_CASE("ArtifactWinCondition: artifact option appears when chance formula ret
|
||||
const auto& choices = sim.getPendingSchematicChoices();
|
||||
|
||||
const long artifactCount = std::count_if(choices.begin(), choices.end(),
|
||||
[](const SchematicChoiceOption& opt) { return opt.type == SchematicType::Artifact; });
|
||||
[](const SchematicChoiceOption& opt) { return opt.isArtifact; });
|
||||
CHECK(artifactCount == 1);
|
||||
// Exactly 2 schematic picks + 1 artifact (or fewer if pool was small)
|
||||
CHECK(choices.size() <= 3);
|
||||
@@ -105,7 +105,7 @@ TEST_CASE("ArtifactWinCondition: at most 2 schematic options accompany the artif
|
||||
const auto& choices = sim.getPendingSchematicChoices();
|
||||
|
||||
const long schematicCount = std::count_if(choices.begin(), choices.end(),
|
||||
[](const SchematicChoiceOption& opt) { return opt.type != SchematicType::Artifact; });
|
||||
[](const SchematicChoiceOption& opt) { return !opt.isArtifact; });
|
||||
CHECK(schematicCount <= 2);
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ TEST_CASE("ArtifactWinCondition: selecting artifact increments artifact count",
|
||||
|
||||
SimulationTestAccess::applySchematicChoice(sim,index);
|
||||
|
||||
CHECK(sim.artifactCount() == 1);
|
||||
CHECK(sim.getArtifactCount() == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("ArtifactWinCondition: selecting a non-artifact option does not increment artifact count",
|
||||
@@ -161,12 +161,12 @@ TEST_CASE("ArtifactWinCondition: selecting a non-artifact option does not increm
|
||||
// Pick the first non-artifact choice.
|
||||
const auto& choices = sim.getPendingSchematicChoices();
|
||||
const auto it = std::find_if(choices.begin(), choices.end(),
|
||||
[](const SchematicChoiceOption& opt) { return opt.type != SchematicType::Artifact; });
|
||||
[](const SchematicChoiceOption& opt) { return !opt.isArtifact; });
|
||||
REQUIRE(it != choices.end());
|
||||
|
||||
SimulationTestAccess::applySchematicChoice(sim,static_cast<int>(it - choices.begin()));
|
||||
|
||||
CHECK(sim.artifactCount() == 0);
|
||||
CHECK(sim.getArtifactCount() == 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -205,7 +205,7 @@ TEST_CASE("ArtifactWinCondition: isWon stays false when artifact count is below
|
||||
REQUIRE(sim.hasSchematicChoicesPending());
|
||||
SimulationTestAccess::applySchematicChoice(sim,findArtifactChoiceIndex(sim));
|
||||
|
||||
CHECK(sim.artifactCount() == 1);
|
||||
CHECK(sim.getArtifactCount() == 1);
|
||||
CHECK_FALSE(sim.isWon());
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ TEST_CASE("ArtifactWinCondition: isWon becomes true after collecting required nu
|
||||
SimulationTestAccess::applySchematicChoice(sim,index);
|
||||
}
|
||||
|
||||
CHECK(sim.artifactCount() == 2);
|
||||
CHECK(sim.getArtifactCount() == 2);
|
||||
CHECK(sim.isWon());
|
||||
}
|
||||
|
||||
@@ -249,6 +249,6 @@ TEST_CASE("ArtifactWinCondition: reset clears artifact count and win state",
|
||||
|
||||
sim.reset();
|
||||
|
||||
CHECK(sim.artifactCount() == 0);
|
||||
CHECK(sim.getArtifactCount() == 0);
|
||||
CHECK_FALSE(sim.isWon());
|
||||
}
|
||||
|
||||
@@ -954,7 +954,7 @@ TEST_CASE("BehaviorSystem: full-cargo salvage ship moves toward SalvageBay", "[b
|
||||
Fixture f;
|
||||
|
||||
const BuildingId bayId = f.buildings.place(BuildingType::SalvageBay,
|
||||
QPoint(-4, 0), Rotation::East, 0);
|
||||
QPoint(-4, 0), Rotation::East, 0).value();
|
||||
Tick t = 0;
|
||||
for (int i = 0; i < 500; ++i)
|
||||
{
|
||||
@@ -989,7 +989,7 @@ TEST_CASE("SalvagerSystem: full-cargo ship at its SalvageBay hands over cargo",
|
||||
Fixture f;
|
||||
|
||||
const BuildingId bayId = f.buildings.place(BuildingType::SalvageBay,
|
||||
QPoint(-4, 0), Rotation::East, 0);
|
||||
QPoint(-4, 0), Rotation::East, 0).value();
|
||||
Tick t = 0;
|
||||
for (int i = 0; i < 500; ++i)
|
||||
{
|
||||
|
||||
157
src/test/BeltDragPathTest.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <QPoint>
|
||||
|
||||
#include "BeltDragPath.h"
|
||||
#include "Rotation.h"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static std::vector<QPoint> tilesOf(const std::vector<BeltPathTile>& path)
|
||||
{
|
||||
std::vector<QPoint> tiles;
|
||||
for (const BeltPathTile& entry : path) { tiles.push_back(entry.tile); }
|
||||
return tiles;
|
||||
}
|
||||
|
||||
static std::vector<Rotation> rotationsOf(const std::vector<BeltPathTile>& path)
|
||||
{
|
||||
std::vector<Rotation> rotations;
|
||||
for (const BeltPathTile& entry : path) { rotations.push_back(entry.rotation); }
|
||||
return rotations;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Single tile
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
TEST_CASE("Single-tile path keeps the belt orientation")
|
||||
{
|
||||
for (Rotation orientation : { Rotation::North, Rotation::East,
|
||||
Rotation::South, Rotation::West })
|
||||
{
|
||||
const std::vector<BeltPathTile> path =
|
||||
computeBeltDragPath(QPoint(3, 4), QPoint(3, 4), orientation);
|
||||
REQUIRE(path.size() == 1);
|
||||
REQUIRE(path[0].tile == QPoint(3, 4));
|
||||
REQUIRE(path[0].rotation == orientation);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Straight runs
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
TEST_CASE("Straight horizontal run faces along the row toward the cursor")
|
||||
{
|
||||
const std::vector<BeltPathTile> path =
|
||||
computeBeltDragPath(QPoint(0, 0), QPoint(3, 0), Rotation::East);
|
||||
REQUIRE(tilesOf(path) == std::vector<QPoint>{
|
||||
QPoint(0, 0), QPoint(1, 0), QPoint(2, 0), QPoint(3, 0) });
|
||||
REQUIRE(rotationsOf(path) == std::vector<Rotation>{
|
||||
Rotation::East, Rotation::East, Rotation::East, Rotation::East });
|
||||
}
|
||||
|
||||
TEST_CASE("Straight horizontal run toward the left faces West")
|
||||
{
|
||||
const std::vector<BeltPathTile> path =
|
||||
computeBeltDragPath(QPoint(0, 0), QPoint(-2, 0), Rotation::East);
|
||||
REQUIRE(tilesOf(path) == std::vector<QPoint>{
|
||||
QPoint(0, 0), QPoint(-1, 0), QPoint(-2, 0) });
|
||||
REQUIRE(rotationsOf(path) == std::vector<Rotation>{
|
||||
Rotation::West, Rotation::West, Rotation::West });
|
||||
}
|
||||
|
||||
TEST_CASE("Straight vertical run faces along the column toward the cursor")
|
||||
{
|
||||
const std::vector<BeltPathTile> path =
|
||||
computeBeltDragPath(QPoint(0, 0), QPoint(0, 3), Rotation::South);
|
||||
REQUIRE(tilesOf(path) == std::vector<QPoint>{
|
||||
QPoint(0, 0), QPoint(0, 1), QPoint(0, 2), QPoint(0, 3) });
|
||||
REQUIRE(rotationsOf(path) == std::vector<Rotation>{
|
||||
Rotation::South, Rotation::South, Rotation::South, Rotation::South });
|
||||
}
|
||||
|
||||
// A vertical target with a horizontal orientation still yields a straight vertical
|
||||
// line (the parallel-axis leg is zero-length).
|
||||
TEST_CASE("Vertical target with horizontal orientation is a straight vertical line")
|
||||
{
|
||||
const std::vector<BeltPathTile> path =
|
||||
computeBeltDragPath(QPoint(2, 0), QPoint(2, 2), Rotation::East);
|
||||
REQUIRE(tilesOf(path) == std::vector<QPoint>{
|
||||
QPoint(2, 0), QPoint(2, 1), QPoint(2, 2) });
|
||||
REQUIRE(rotationsOf(path) == std::vector<Rotation>{
|
||||
Rotation::South, Rotation::South, Rotation::South });
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// L-shaped paths — horizontal-first (East/West orientation)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
TEST_CASE("East orientation goes horizontal then vertical (down-right)")
|
||||
{
|
||||
const std::vector<BeltPathTile> path =
|
||||
computeBeltDragPath(QPoint(0, 0), QPoint(2, 2), Rotation::East);
|
||||
// Leg 1 East to the corner (2,0), then Leg 2 South to the cursor (2,2).
|
||||
REQUIRE(tilesOf(path) == std::vector<QPoint>{
|
||||
QPoint(0, 0), QPoint(1, 0), QPoint(2, 0), QPoint(2, 1), QPoint(2, 2) });
|
||||
REQUIRE(rotationsOf(path) == std::vector<Rotation>{
|
||||
Rotation::East, Rotation::East, Rotation::South, Rotation::South,
|
||||
Rotation::South });
|
||||
}
|
||||
|
||||
TEST_CASE("East orientation with cursor up-left goes horizontal (West) then vertical (North)")
|
||||
{
|
||||
const std::vector<BeltPathTile> path =
|
||||
computeBeltDragPath(QPoint(0, 0), QPoint(-2, -2), Rotation::East);
|
||||
REQUIRE(tilesOf(path) == std::vector<QPoint>{
|
||||
QPoint(0, 0), QPoint(-1, 0), QPoint(-2, 0), QPoint(-2, -1),
|
||||
QPoint(-2, -2) });
|
||||
REQUIRE(rotationsOf(path) == std::vector<Rotation>{
|
||||
Rotation::West, Rotation::West, Rotation::North, Rotation::North,
|
||||
Rotation::North });
|
||||
}
|
||||
|
||||
TEST_CASE("West orientation is horizontal-first as well (up-right cursor)")
|
||||
{
|
||||
const std::vector<BeltPathTile> path =
|
||||
computeBeltDragPath(QPoint(0, 0), QPoint(2, -2), Rotation::West);
|
||||
// Horizontal axis first: East toward the cursor to the corner (2,0), then North.
|
||||
REQUIRE(tilesOf(path) == std::vector<QPoint>{
|
||||
QPoint(0, 0), QPoint(1, 0), QPoint(2, 0), QPoint(2, -1), QPoint(2, -2) });
|
||||
REQUIRE(rotationsOf(path) == std::vector<Rotation>{
|
||||
Rotation::East, Rotation::East, Rotation::North, Rotation::North,
|
||||
Rotation::North });
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// L-shaped paths — vertical-first (North/South orientation)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
TEST_CASE("South orientation goes vertical then horizontal (down-right)")
|
||||
{
|
||||
const std::vector<BeltPathTile> path =
|
||||
computeBeltDragPath(QPoint(0, 0), QPoint(2, 2), Rotation::South);
|
||||
// Leg 1 South to the corner (0,2), then Leg 2 East to the cursor (2,2).
|
||||
REQUIRE(tilesOf(path) == std::vector<QPoint>{
|
||||
QPoint(0, 0), QPoint(0, 1), QPoint(0, 2), QPoint(1, 2), QPoint(2, 2) });
|
||||
REQUIRE(rotationsOf(path) == std::vector<Rotation>{
|
||||
Rotation::South, Rotation::South, Rotation::East, Rotation::East,
|
||||
Rotation::East });
|
||||
}
|
||||
|
||||
TEST_CASE("North orientation is vertical-first (down-left cursor)")
|
||||
{
|
||||
const std::vector<BeltPathTile> path =
|
||||
computeBeltDragPath(QPoint(0, 0), QPoint(-2, 2), Rotation::North);
|
||||
// Vertical axis first: South toward the cursor to the corner (0,2), then West.
|
||||
REQUIRE(tilesOf(path) == std::vector<QPoint>{
|
||||
QPoint(0, 0), QPoint(0, 1), QPoint(0, 2), QPoint(-1, 2), QPoint(-2, 2) });
|
||||
REQUIRE(rotationsOf(path) == std::vector<Rotation>{
|
||||
Rotation::South, Rotation::South, Rotation::West, Rotation::West,
|
||||
Rotation::West });
|
||||
}
|
||||
@@ -974,7 +974,7 @@ TEST_CASE("BeltSystem: unpaired entry blocks items at front", "[belt]")
|
||||
REQUIRE(bs.peekItem(Port{QPoint(3, 0), Rotation::East}).has_value());
|
||||
}
|
||||
|
||||
TEST_CASE("BeltSystem: demolish entry discards transit items", "[belt]")
|
||||
TEST_CASE("BeltSystem: deconstruct entry discards transit items", "[belt]")
|
||||
{
|
||||
BeltSystem bs(kFastBeltSpeed);
|
||||
|
||||
|
||||
@@ -527,15 +527,15 @@ TEST_CASE("Blueprint placement: buildings land at anchor + offset from cursor",
|
||||
const QPoint offsetB( 1, 0);
|
||||
|
||||
const BuildingId idA = SimulationTestAccess::place(sim,
|
||||
BuildingType::Belt, cursor + offsetA, Rotation::East);
|
||||
BuildingType::Belt, cursor + offsetA, Rotation::East).value();
|
||||
const BuildingId idB = SimulationTestAccess::place(sim,
|
||||
BuildingType::Belt, cursor + offsetB, Rotation::East);
|
||||
BuildingType::Belt, cursor + offsetB, Rotation::East).value();
|
||||
|
||||
REQUIRE(idA != kInvalidBuildingId);
|
||||
REQUIRE(idB != kInvalidBuildingId);
|
||||
REQUIRE(sim.buildings().isTileOccupied(cursor + offsetA)); // (-6, 0)
|
||||
REQUIRE(sim.buildings().isTileOccupied(cursor + offsetB)); // (-4, 0)
|
||||
REQUIRE_FALSE(sim.buildings().isTileOccupied(cursor)); // center not occupied
|
||||
REQUIRE(sim.getBuildings().isTileOccupied(cursor + offsetA)); // (-6, 0)
|
||||
REQUIRE(sim.getBuildings().isTileOccupied(cursor + offsetB)); // (-4, 0)
|
||||
REQUIRE_FALSE(sim.getBuildings().isTileOccupied(cursor)); // center not occupied
|
||||
}
|
||||
|
||||
TEST_CASE("Blueprint placement: cost is deducted for each building in sequence", "[blueprint]")
|
||||
@@ -544,20 +544,20 @@ TEST_CASE("Blueprint placement: cost is deducted for each building in sequence",
|
||||
|
||||
// Find belt cost from config (belt cost = 2 in test config).
|
||||
int beltCost = 0;
|
||||
for (const BuildingDef& def : sim.config().buildings.buildings)
|
||||
for (const BuildingDef& def : sim.getConfig().buildings.buildings)
|
||||
{
|
||||
if (def.type == BuildingType::Belt) { beltCost = def.cost; break; }
|
||||
}
|
||||
REQUIRE(beltCost > 0);
|
||||
|
||||
const int startBlocks = sim.buildingBlocksStock();
|
||||
const int startBlocks = sim.getBuildingBlocksStock();
|
||||
REQUIRE(startBlocks >= 2 * beltCost); // test config has enough starting blocks
|
||||
|
||||
SimulationTestAccess::place(sim,BuildingType::Belt, QPoint(-6, 0), Rotation::East);
|
||||
REQUIRE(sim.buildingBlocksStock() == startBlocks - beltCost);
|
||||
REQUIRE(sim.getBuildingBlocksStock() == startBlocks - beltCost);
|
||||
|
||||
SimulationTestAccess::place(sim,BuildingType::Belt, QPoint(-4, 0), Rotation::East);
|
||||
REQUIRE(sim.buildingBlocksStock() == startBlocks - 2 * beltCost);
|
||||
REQUIRE(sim.getBuildingBlocksStock() == startBlocks - 2 * beltCost);
|
||||
}
|
||||
|
||||
TEST_CASE("Blueprint placement: insufficient blocks returns kInvalidBuildingId and deducts nothing",
|
||||
@@ -567,7 +567,7 @@ TEST_CASE("Blueprint placement: insufficient blocks returns kInvalidBuildingId a
|
||||
|
||||
// Find miner cost (15 in test config) — expensive enough to exhaust a small stock.
|
||||
int minerCost = 0;
|
||||
for (const BuildingDef& def : sim.config().buildings.buildings)
|
||||
for (const BuildingDef& def : sim.getConfig().buildings.buildings)
|
||||
{
|
||||
if (def.type == BuildingType::Miner) { minerCost = def.cost; break; }
|
||||
}
|
||||
@@ -576,35 +576,35 @@ TEST_CASE("Blueprint placement: insufficient blocks returns kInvalidBuildingId a
|
||||
// Drain the stock by placing miners until we no longer have enough.
|
||||
// Non-overlapping columns: miner body is 2 wide, so step by 2.
|
||||
int col = -2;
|
||||
while (sim.buildingBlocksStock() >= minerCost)
|
||||
while (sim.getBuildingBlocksStock() >= minerCost)
|
||||
{
|
||||
SimulationTestAccess::place(sim,BuildingType::Miner, QPoint(col, 0), Rotation::East);
|
||||
col -= 2;
|
||||
}
|
||||
|
||||
const int blocksBeforeAttempt = sim.buildingBlocksStock();
|
||||
const BuildingId id = SimulationTestAccess::place(sim,
|
||||
const int blocksBeforeAttempt = sim.getBuildingBlocksStock();
|
||||
const std::optional<BuildingId> id = SimulationTestAccess::place(sim,
|
||||
BuildingType::Miner, QPoint(col - 2, 0), Rotation::East);
|
||||
|
||||
// Placement must fail and leave the stock unchanged.
|
||||
REQUIRE(id == kInvalidBuildingId);
|
||||
REQUIRE(sim.buildingBlocksStock() == blocksBeforeAttempt);
|
||||
REQUIRE_FALSE(id.has_value());
|
||||
REQUIRE(sim.getBuildingBlocksStock() == blocksBeforeAttempt);
|
||||
}
|
||||
|
||||
TEST_CASE("Simulation: tryPlaceBuilding rejects terrain-invalid placement and charges nothing",
|
||||
"[blueprint]")
|
||||
{
|
||||
Simulation sim(loadConfig());
|
||||
const int startBlocks = sim.buildingBlocksStock();
|
||||
const int startBlocks = sim.getBuildingBlocksStock();
|
||||
|
||||
// A miner is all-asteroid; placing it in space (x >= 0) violates the terrain
|
||||
// rule, so it must be rejected without consuming building blocks.
|
||||
const BuildingId id =
|
||||
const std::optional<BuildingId> id =
|
||||
SimulationTestAccess::place(sim,BuildingType::Miner, QPoint(0, 0), Rotation::East);
|
||||
|
||||
REQUIRE(id == kInvalidBuildingId);
|
||||
REQUIRE(sim.buildingBlocksStock() == startBlocks);
|
||||
REQUIRE(sim.buildings().allSites().empty());
|
||||
REQUIRE_FALSE(id.has_value());
|
||||
REQUIRE(sim.getBuildingBlocksStock() == startBlocks);
|
||||
REQUIRE(sim.getBuildings().getAllSites().empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Simulation: tryPlaceBuilding accepts a valid asteroid spot, occupies tiles, charges cost",
|
||||
@@ -613,25 +613,25 @@ TEST_CASE("Simulation: tryPlaceBuilding accepts a valid asteroid spot, occupies
|
||||
Simulation sim(loadConfig());
|
||||
|
||||
int minerCost = 0;
|
||||
for (const BuildingDef& def : sim.config().buildings.buildings)
|
||||
for (const BuildingDef& def : sim.getConfig().buildings.buildings)
|
||||
{
|
||||
if (def.type == BuildingType::Miner) { minerCost = def.cost; break; }
|
||||
}
|
||||
REQUIRE(minerCost > 0);
|
||||
const int startBlocks = sim.buildingBlocksStock();
|
||||
const int startBlocks = sim.getBuildingBlocksStock();
|
||||
|
||||
// Miner mask ["AA","A>"] East at (-3,0) → all-asteroid body at
|
||||
// (-3,0),(-2,0),(-3,1); a valid spot.
|
||||
const BuildingId id =
|
||||
SimulationTestAccess::place(sim,BuildingType::Miner, QPoint(-3, 0), Rotation::East);
|
||||
SimulationTestAccess::place(sim,BuildingType::Miner, QPoint(-3, 0), Rotation::East).value();
|
||||
|
||||
REQUIRE(id != kInvalidBuildingId);
|
||||
REQUIRE(sim.buildingBlocksStock() == startBlocks - minerCost);
|
||||
REQUIRE(sim.buildings().isTileOccupied(QPoint(-3, 0)));
|
||||
REQUIRE(sim.buildings().isTileOccupied(QPoint(-2, 0)));
|
||||
REQUIRE(sim.buildings().isTileOccupied(QPoint(-3, 1)));
|
||||
REQUIRE(sim.getBuildingBlocksStock() == startBlocks - minerCost);
|
||||
REQUIRE(sim.getBuildings().isTileOccupied(QPoint(-3, 0)));
|
||||
REQUIRE(sim.getBuildings().isTileOccupied(QPoint(-2, 0)));
|
||||
REQUIRE(sim.getBuildings().isTileOccupied(QPoint(-3, 1)));
|
||||
// The output-port tile (1,1)+anchor = (-2,1) is not a body cell.
|
||||
REQUIRE_FALSE(sim.buildings().isTileOccupied(QPoint(-2, 1)));
|
||||
REQUIRE_FALSE(sim.getBuildings().isTileOccupied(QPoint(-2, 1)));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -666,12 +666,12 @@ TEST_CASE("Blueprint placement: setRecipe on construction site stores recipe", "
|
||||
Simulation sim(loadConfig());
|
||||
|
||||
// Miner body cells: (0,0),(1,0),(0,1) — all at x < 0, valid for asteroid.
|
||||
const BuildingId id = SimulationTestAccess::place(sim,BuildingType::Miner, QPoint(-2, 0), Rotation::East);
|
||||
const BuildingId id = SimulationTestAccess::place(sim,BuildingType::Miner, QPoint(-2, 0), Rotation::East).value();
|
||||
REQUIRE(id != kInvalidBuildingId);
|
||||
|
||||
SimulationTestAccess::buildings(sim).setRecipe(id, "mine_iron_ore");
|
||||
|
||||
const ConstructionSite* site = sim.buildings().findSite(id);
|
||||
const ConstructionSite* site = sim.getBuildings().findSite(id);
|
||||
REQUIRE(site != nullptr);
|
||||
REQUIRE(site->recipeId == "mine_iron_ore");
|
||||
}
|
||||
@@ -681,7 +681,7 @@ TEST_CASE("Blueprint placement: recipe transfers to building after construction
|
||||
{
|
||||
Simulation sim(loadConfig());
|
||||
|
||||
const BuildingId id = SimulationTestAccess::place(sim,BuildingType::Miner, QPoint(-2, 0), Rotation::East);
|
||||
const BuildingId id = SimulationTestAccess::place(sim,BuildingType::Miner, QPoint(-2, 0), Rotation::East).value();
|
||||
REQUIRE(id != kInvalidBuildingId);
|
||||
SimulationTestAccess::buildings(sim).setRecipe(id, "mine_copper_ore");
|
||||
|
||||
@@ -692,7 +692,7 @@ TEST_CASE("Blueprint placement: recipe transfers to building after construction
|
||||
sim.tick();
|
||||
}
|
||||
|
||||
const Building* b = sim.buildings().findBuilding(id);
|
||||
const Building* b = sim.getBuildings().findBuilding(id);
|
||||
REQUIRE(b != nullptr);
|
||||
REQUIRE(b->recipeId == "mine_copper_ore");
|
||||
}
|
||||
@@ -710,10 +710,10 @@ TEST_CASE("Blueprint creation: a construction site is captured", "[blueprint]")
|
||||
// Freshly placed → a ConstructionSite (not ticked to completion). A 1x1 belt keeps
|
||||
// the body-cell bounding-box centered on the anchor, so a single site → zero offset.
|
||||
const BuildingId id =
|
||||
SimulationTestAccess::place(sim, BuildingType::Belt, QPoint(-2, 0), Rotation::East);
|
||||
SimulationTestAccess::place(sim, BuildingType::Belt, QPoint(-2, 0), Rotation::East).value();
|
||||
REQUIRE(id != kInvalidBuildingId);
|
||||
REQUIRE(sim.buildings().findSite(id) != nullptr);
|
||||
REQUIRE(sim.buildings().findBuilding(id) == nullptr);
|
||||
REQUIRE(sim.getBuildings().findSite(id) != nullptr);
|
||||
REQUIRE(sim.getBuildings().findBuilding(id) == nullptr);
|
||||
|
||||
const Blueprint bp = captureBlueprintFromSelection(sim, { id });
|
||||
|
||||
@@ -727,7 +727,7 @@ TEST_CASE("Blueprint creation: a construction site's recipe is captured", "[blue
|
||||
Simulation sim(loadConfig());
|
||||
|
||||
const BuildingId id =
|
||||
SimulationTestAccess::place(sim, BuildingType::Miner, QPoint(-2, 0), Rotation::East);
|
||||
SimulationTestAccess::place(sim, BuildingType::Miner, QPoint(-2, 0), Rotation::East).value();
|
||||
REQUIRE(id != kInvalidBuildingId);
|
||||
SimulationTestAccess::buildings(sim).setRecipe(id, "mine_iron_ore");
|
||||
|
||||
@@ -744,18 +744,18 @@ TEST_CASE("Blueprint creation: mixed operational building and construction site
|
||||
|
||||
// Building A: place, configure, and tick to completion so it is operational.
|
||||
const BuildingId idA =
|
||||
SimulationTestAccess::place(sim, BuildingType::Miner, QPoint(-2, 0), Rotation::East);
|
||||
SimulationTestAccess::place(sim, BuildingType::Miner, QPoint(-2, 0), Rotation::East).value();
|
||||
REQUIRE(idA != kInvalidBuildingId);
|
||||
SimulationTestAccess::buildings(sim).setRecipe(idA, "mine_iron_ore");
|
||||
for (int i = 0; i <= static_cast<int>(secondsToTicks(10.0)); ++i) { sim.tick(); }
|
||||
REQUIRE(sim.buildings().findBuilding(idA) != nullptr);
|
||||
REQUIRE(sim.getBuildings().findBuilding(idA) != nullptr);
|
||||
|
||||
// Building B: place and configure, but leave as a construction site.
|
||||
const BuildingId idB =
|
||||
SimulationTestAccess::place(sim, BuildingType::Miner, QPoint(-6, 0), Rotation::East);
|
||||
SimulationTestAccess::place(sim, BuildingType::Miner, QPoint(-6, 0), Rotation::East).value();
|
||||
REQUIRE(idB != kInvalidBuildingId);
|
||||
SimulationTestAccess::buildings(sim).setRecipe(idB, "mine_copper_ore");
|
||||
REQUIRE(sim.buildings().findSite(idB) != nullptr);
|
||||
REQUIRE(sim.getBuildings().findSite(idB) != nullptr);
|
||||
|
||||
const Blueprint bp = captureBlueprintFromSelection(sim, { idA, idB });
|
||||
|
||||
@@ -777,9 +777,9 @@ TEST_CASE("Blueprint creation: selectionHasPlaceableBuilding sees a construction
|
||||
REQUIRE_FALSE(selectionHasPlaceableBuilding(sim, {}));
|
||||
|
||||
const BuildingId id =
|
||||
SimulationTestAccess::place(sim, BuildingType::Miner, QPoint(-2, 0), Rotation::East);
|
||||
SimulationTestAccess::place(sim, BuildingType::Miner, QPoint(-2, 0), Rotation::East).value();
|
||||
REQUIRE(id != kInvalidBuildingId);
|
||||
REQUIRE(sim.buildings().findSite(id) != nullptr);
|
||||
REQUIRE(sim.getBuildings().findSite(id) != nullptr);
|
||||
REQUIRE(selectionHasPlaceableBuilding(sim, { id }));
|
||||
}
|
||||
|
||||
@@ -847,7 +847,7 @@ TEST_CASE("Blueprint placement: setShipLayout on construction site stores layout
|
||||
// Shipyard surface_mask ["AAAS>","AAAS "] with Rotation::East:
|
||||
// A-tiles at (-3,0),(-2,0),(-1,0),(-3,1),(-2,1),(-1,1) — all x < 0, valid asteroid tiles.
|
||||
// S-tile at (0,0) and (0,1) — x >= 0, valid space tiles.
|
||||
const BuildingId id = SimulationTestAccess::place(sim,BuildingType::Shipyard, QPoint(-3, 0), Rotation::East);
|
||||
const BuildingId id = SimulationTestAccess::place(sim,BuildingType::Shipyard, QPoint(-3, 0), Rotation::East).value();
|
||||
REQUIRE(id != kInvalidBuildingId);
|
||||
|
||||
ShipLayoutConfig layout;
|
||||
@@ -859,7 +859,7 @@ TEST_CASE("Blueprint placement: setShipLayout on construction site stores layout
|
||||
|
||||
SimulationTestAccess::buildings(sim).setShipLayout(id, layout);
|
||||
|
||||
const ConstructionSite* site = sim.buildings().findSite(id);
|
||||
const ConstructionSite* site = sim.getBuildings().findSite(id);
|
||||
REQUIRE(site != nullptr);
|
||||
REQUIRE(site->shipLayout.has_value());
|
||||
REQUIRE(site->shipLayout->placedModules.size() == 1);
|
||||
@@ -871,7 +871,7 @@ TEST_CASE("Blueprint placement: ship layout transfers to building after construc
|
||||
{
|
||||
Simulation sim(loadConfig());
|
||||
|
||||
const BuildingId id = SimulationTestAccess::place(sim,BuildingType::Shipyard, QPoint(-3, 0), Rotation::East);
|
||||
const BuildingId id = SimulationTestAccess::place(sim,BuildingType::Shipyard, QPoint(-3, 0), Rotation::East).value();
|
||||
REQUIRE(id != kInvalidBuildingId);
|
||||
|
||||
ShipLayoutConfig layout;
|
||||
@@ -885,7 +885,7 @@ TEST_CASE("Blueprint placement: ship layout transfers to building after construc
|
||||
|
||||
// Shipyard construction_time_seconds = 30 in the test config.
|
||||
double constructionTime = 0.0;
|
||||
for (const BuildingDef& def : sim.config().buildings.buildings)
|
||||
for (const BuildingDef& def : sim.getConfig().buildings.buildings)
|
||||
{
|
||||
if (def.type == BuildingType::Shipyard) { constructionTime = def.constructionTimeSeconds; break; }
|
||||
}
|
||||
@@ -896,7 +896,7 @@ TEST_CASE("Blueprint placement: ship layout transfers to building after construc
|
||||
sim.tick();
|
||||
}
|
||||
|
||||
const Building* b = sim.buildings().findBuilding(id);
|
||||
const Building* b = sim.getBuildings().findBuilding(id);
|
||||
REQUIRE(b != nullptr);
|
||||
REQUIRE(b->shipLayout.has_value());
|
||||
REQUIRE(b->shipLayout->placedModules.size() == 1);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "Building.h"
|
||||
#include "BuildingConfig.h"
|
||||
#include "BuildingSystem.h"
|
||||
@@ -46,7 +48,17 @@ const ShipDef* findAvailableSchematic(const GameConfig& cfg)
|
||||
{
|
||||
for (const ShipDef& def : cfg.ships.ships)
|
||||
{
|
||||
if (def.unlockAtStationLevel == -1) { return &def; }
|
||||
// A ship starts unlocked iff no unlock group grants it (REQ-LOCK-EXPLICIT).
|
||||
bool granted = false;
|
||||
for (const UnlockGroupDef& group : cfg.unlocks.groups)
|
||||
{
|
||||
if (std::find(group.ships.begin(), group.ships.end(), def.id) != group.ships.end())
|
||||
{
|
||||
granted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!granted) { return &def; }
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -112,10 +124,10 @@ TEST_CASE("readBuildingConfig reads a queued construction site", "[copyconfig]")
|
||||
|
||||
// A placed miner enters the construction queue as a site (not yet operational).
|
||||
const BuildingId id =
|
||||
SimulationTestAccess::place(sim, BuildingType::Miner, QPoint(-2, 0), Rotation::East);
|
||||
SimulationTestAccess::place(sim, BuildingType::Miner, QPoint(-2, 0), Rotation::East).value();
|
||||
REQUIRE(id != kInvalidBuildingId);
|
||||
REQUIRE(sim.buildings().findBuilding(id) == nullptr);
|
||||
REQUIRE(sim.buildings().findSite(id) != nullptr);
|
||||
REQUIRE(sim.getBuildings().findBuilding(id) == nullptr);
|
||||
REQUIRE(sim.getBuildings().findSite(id) != nullptr);
|
||||
|
||||
SimulationTestAccess::buildings(sim).setRecipe(id, "mine_iron_ore");
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
#include <map>
|
||||
#include <random>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <QPoint>
|
||||
@@ -56,6 +58,7 @@ static void runTicks(BuildingSystem& bs, BeltSystem& belts, int n, Tick& tick)
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
bs.tickConstruction(tick);
|
||||
bs.tickDeconstruction(tick);
|
||||
bs.tickBeltPull();
|
||||
bs.tickProduction(tick);
|
||||
bs.tickOutputBelts();
|
||||
@@ -119,7 +122,7 @@ TEST_CASE("BuildingSystem: place miner occupies expected body tiles", "[building
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
const BuildingId id = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId id = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0).value();
|
||||
REQUIRE(id != kInvalidBuildingId);
|
||||
|
||||
// Miner mask ["AA","A>"] with East rotation → body at (0,0),(1,0),(0,1).
|
||||
@@ -138,9 +141,9 @@ TEST_CASE("BuildingSystem: place rejects a building above the world (y < 0)", "[
|
||||
|
||||
// Miner mask ["AA","A>"] East → body at (0,0),(1,0),(0,1); at y=-1 the top
|
||||
// row sits above the world.
|
||||
const BuildingId id = f.bs.place(BuildingType::Miner, QPoint(0, -1), Rotation::East, 0);
|
||||
REQUIRE(id == kInvalidBuildingId);
|
||||
REQUIRE(f.bs.allSites().empty());
|
||||
const std::optional<BuildingId> id = f.bs.place(BuildingType::Miner, QPoint(0, -1), Rotation::East, 0);
|
||||
REQUIRE_FALSE(id.has_value());
|
||||
REQUIRE(f.bs.getAllSites().empty());
|
||||
REQUIRE_FALSE(f.bs.isTileOccupied(QPoint(0, 0)));
|
||||
}
|
||||
|
||||
@@ -151,10 +154,10 @@ TEST_CASE("BuildingSystem: place rejects a building below the world (y >= height
|
||||
|
||||
// Anchored on the last in-bounds row, the miner's lower body row reaches
|
||||
// y == heightTiles, which is outside the world.
|
||||
const BuildingId id = f.bs.place(BuildingType::Miner,
|
||||
const std::optional<BuildingId> id = f.bs.place(BuildingType::Miner,
|
||||
QPoint(0, heightTiles - 1), Rotation::East, 0);
|
||||
REQUIRE(id == kInvalidBuildingId);
|
||||
REQUIRE(f.bs.allSites().empty());
|
||||
REQUIRE_FALSE(id.has_value());
|
||||
REQUIRE(f.bs.getAllSites().empty());
|
||||
}
|
||||
|
||||
TEST_CASE("BuildingSystem: place rejects a building left of the asteroid edge", "[building]")
|
||||
@@ -162,10 +165,10 @@ TEST_CASE("BuildingSystem: place rejects a building left of the asteroid edge",
|
||||
PlacementFixture f;
|
||||
const int leftEdgeX = -f.cfg.world.regions.asteroidWidth_tiles;
|
||||
|
||||
const BuildingId id = f.bs.place(BuildingType::Miner,
|
||||
const std::optional<BuildingId> id = f.bs.place(BuildingType::Miner,
|
||||
QPoint(leftEdgeX - 1, 0), Rotation::East, 0);
|
||||
REQUIRE(id == kInvalidBuildingId);
|
||||
REQUIRE(f.bs.allSites().empty());
|
||||
REQUIRE_FALSE(id.has_value());
|
||||
REQUIRE(f.bs.getAllSites().empty());
|
||||
}
|
||||
|
||||
TEST_CASE("BuildingSystem: place accepts a building flush against the world's left edge",
|
||||
@@ -176,7 +179,7 @@ TEST_CASE("BuildingSystem: place accepts a building flush against the world's le
|
||||
|
||||
// Miner body min relative x is 0, so its leftmost cell sits exactly on the edge.
|
||||
const BuildingId id = f.bs.place(BuildingType::Miner,
|
||||
QPoint(leftEdgeX, 0), Rotation::East, 0);
|
||||
QPoint(leftEdgeX, 0), Rotation::East, 0).value();
|
||||
REQUIRE(id != kInvalidBuildingId);
|
||||
REQUIRE(f.bs.isTileOccupied(QPoint(leftEdgeX, 0)));
|
||||
}
|
||||
@@ -187,7 +190,7 @@ TEST_CASE("BuildingSystem: place imposes no right-side bound (space extends righ
|
||||
PlacementFixture f;
|
||||
|
||||
const BuildingId id = f.bs.place(BuildingType::Miner,
|
||||
QPoint(1000, 0), Rotation::East, 0);
|
||||
QPoint(1000, 0), Rotation::East, 0).value();
|
||||
REQUIRE(id != kInvalidBuildingId);
|
||||
}
|
||||
|
||||
@@ -237,9 +240,9 @@ TEST_CASE("BuildingSystem: placing a belt registers it with BeltSystem after con
|
||||
runTicks(bs, belts, static_cast<int>(secondsToTicks(1.0)) + 1, tick);
|
||||
|
||||
REQUIRE(belts.tryPutItem(QPoint(5, 5), makeItem("iron_ore"), Rotation::East));
|
||||
REQUIRE(bs.allBuildings().size() == 1);
|
||||
REQUIRE(bs.allBuildings()[0].type == BuildingType::Belt);
|
||||
REQUIRE(bs.allBuildings()[0].anchor == QPoint(5, 5));
|
||||
REQUIRE(bs.getAllBuildings().size() == 1);
|
||||
REQUIRE(bs.getAllBuildings()[0].type == BuildingType::Belt);
|
||||
REQUIRE(bs.getAllBuildings()[0].anchor == QPoint(5, 5));
|
||||
}
|
||||
|
||||
TEST_CASE("BuildingSystem: placed building enters construction queue", "[building]")
|
||||
@@ -256,40 +259,27 @@ TEST_CASE("BuildingSystem: placed building enters construction queue", "[buildin
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
const BuildingId id = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId id = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0).value();
|
||||
|
||||
REQUIRE(bs.allSites().size() == 1);
|
||||
REQUIRE(bs.allBuildings().empty());
|
||||
REQUIRE(bs.getAllSites().size() == 1);
|
||||
REQUIRE(bs.getAllBuildings().empty());
|
||||
REQUIRE(bs.findSite(id) != nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE("BuildingSystem: demolish frees tiles and returns refund", "[building]")
|
||||
TEST_CASE("BuildingSystem: deconstructing a construction site removes it instantly with full refund",
|
||||
"[building]")
|
||||
{
|
||||
const GameConfig cfg = loadConfig();
|
||||
BeltSystem belts(cfg.world.beltSpeed_tps);
|
||||
int stock = 0;
|
||||
std::mt19937 rng(0);
|
||||
BuildingId nextBuildingId = 1;
|
||||
BuildingSystem bs(cfg, belts,
|
||||
[&nextBuildingId]() { return nextBuildingId++; },
|
||||
[&stock](int n) { stock += n; },
|
||||
[](const std::string&, QVector2D, const std::optional<ShipLayoutConfig>&) {},
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
PlacementFixture f;
|
||||
const BuildingId id =
|
||||
f.bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0).value();
|
||||
|
||||
const BuildingId id = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0);
|
||||
// Still queued for construction (not yet built): instant removal, full cost
|
||||
// refunded immediately, never entering the deconstruction queue (REQ-BLD-DECONSTRUCT).
|
||||
const int refund = f.bs.deconstruct(id, 0);
|
||||
|
||||
// Miner construction_time_seconds = 10. completesAt = secondsToTicks(10) = 300.
|
||||
// We need to process tick 300 itself, so run 301 ticks (ticks 0..300).
|
||||
Tick tick = 0;
|
||||
runTicks(bs, belts, static_cast<int>(secondsToTicks(10.0)) + 1, tick);
|
||||
|
||||
const int refund = bs.demolish(id);
|
||||
|
||||
// Miner cost = 15, refund = floor(15 * 75 / 100) = 11.
|
||||
REQUIRE(refund == 15 * cfg.world.refundPercentage / 100);
|
||||
REQUIRE_FALSE(bs.isTileOccupied(QPoint(0, 0)));
|
||||
REQUIRE(bs.allSites().empty());
|
||||
REQUIRE(refund == 15); // Miner cost = 15
|
||||
REQUIRE_FALSE(f.bs.isTileOccupied(QPoint(0, 0)));
|
||||
REQUIRE(f.bs.getAllSites().empty());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -312,7 +302,7 @@ TEST_CASE("BuildingSystem: first queued building starts construction immediately
|
||||
rng);
|
||||
|
||||
bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0);
|
||||
REQUIRE(bs.allSites().front().completesAt > 0);
|
||||
REQUIRE(bs.getAllSites().front().completesAt > 0);
|
||||
}
|
||||
|
||||
TEST_CASE("BuildingSystem: second queued building waits (completesAt == 0)", "[building]")
|
||||
@@ -332,9 +322,9 @@ TEST_CASE("BuildingSystem: second queued building waits (completesAt == 0)", "[b
|
||||
bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0);
|
||||
bs.place(BuildingType::Miner, QPoint(5, 5), Rotation::East, 0);
|
||||
|
||||
REQUIRE(bs.allSites().size() == 2);
|
||||
REQUIRE(bs.allSites()[0].completesAt > 0);
|
||||
REQUIRE(bs.allSites()[1].completesAt == 0);
|
||||
REQUIRE(bs.getAllSites().size() == 2);
|
||||
REQUIRE(bs.getAllSites()[0].completesAt > 0);
|
||||
REQUIRE(bs.getAllSites()[1].completesAt == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("BuildingSystem: construction completes after configured duration", "[building]")
|
||||
@@ -351,17 +341,158 @@ TEST_CASE("BuildingSystem: construction completes after configured duration", "[
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
const BuildingId id = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId id = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0).value();
|
||||
|
||||
// Miner construction_time_seconds = 10. completesAt = secondsToTicks(10) = 300.
|
||||
// We need to process tick 300 itself, so run 301 ticks (ticks 0..300).
|
||||
Tick tick = 0;
|
||||
runTicks(bs, belts, static_cast<int>(secondsToTicks(10.0)) + 1, tick);
|
||||
|
||||
REQUIRE(bs.allSites().empty());
|
||||
REQUIRE(bs.getAllSites().empty());
|
||||
REQUIRE(bs.findBuilding(id) != nullptr);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Deconstruction queue (REQ-BLD-DECON-QUEUE)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// Runs ticks until the building with the given id is operational, or fails.
|
||||
static void runUntilBuilt(PlacementFixture& f, BuildingId id, Tick& tick)
|
||||
{
|
||||
for (int i = 0; i < 100000 && f.bs.findBuilding(id) == nullptr; ++i)
|
||||
{
|
||||
runTicks(f.bs, f.belts, 1, tick);
|
||||
}
|
||||
REQUIRE(f.bs.findBuilding(id) != nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE("BuildingSystem: deconstructing a built building queues it; refund credited on completion",
|
||||
"[building][decon]")
|
||||
{
|
||||
PlacementFixture f;
|
||||
const BuildingId id =
|
||||
f.bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0).value();
|
||||
|
||||
Tick tick = 0;
|
||||
runUntilBuilt(f, id, tick);
|
||||
|
||||
// Deconstructing a built building returns nothing immediately and queues it,
|
||||
// stopping it operating while its tiles stay occupied (REQ-BLD-DECON-QUEUE).
|
||||
const int refund = f.bs.deconstruct(id, tick);
|
||||
REQUIRE(refund == 0);
|
||||
REQUIRE(f.bs.isQueuedForDeconstruction(id));
|
||||
REQUIRE(f.bs.isTileOccupied(QPoint(0, 0)));
|
||||
REQUIRE(f.stock == 0);
|
||||
|
||||
// After the deconstruction time (0.1s = 3 ticks) it is removed and the partial
|
||||
// refund (15 * 75 / 100 = 11) is credited exactly once.
|
||||
runTicks(f.bs, f.belts, static_cast<int>(secondsToTicks(0.1)) + 1, tick);
|
||||
REQUIRE(f.bs.findBuilding(id) == nullptr);
|
||||
REQUIRE_FALSE(f.bs.isTileOccupied(QPoint(0, 0)));
|
||||
REQUIRE(f.stock == 15 * f.cfg.world.refundPercentage / 100);
|
||||
}
|
||||
|
||||
TEST_CASE("BuildingSystem: deconstruction queue removes one building at a time", "[building][decon]")
|
||||
{
|
||||
PlacementFixture f;
|
||||
const BuildingId a = f.bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0).value();
|
||||
const BuildingId b = f.bs.place(BuildingType::Miner, QPoint(5, 5), Rotation::East, 0).value();
|
||||
|
||||
Tick tick = 0;
|
||||
runUntilBuilt(f, a, tick);
|
||||
runUntilBuilt(f, b, tick);
|
||||
|
||||
// Queue both in one tick; 'a' is at the front of the deconstruction queue.
|
||||
f.bs.deconstruct(a, tick);
|
||||
f.bs.deconstruct(b, tick);
|
||||
REQUIRE(f.bs.isQueuedForDeconstruction(a));
|
||||
REQUIRE(f.bs.isQueuedForDeconstruction(b));
|
||||
|
||||
// After one deconstruction interval only the front building is gone; the
|
||||
// second is still queued and its refund not yet credited.
|
||||
runTicks(f.bs, f.belts, static_cast<int>(secondsToTicks(0.1)) + 1, tick);
|
||||
REQUIRE(f.bs.findBuilding(a) == nullptr);
|
||||
REQUIRE(f.bs.findBuilding(b) != nullptr);
|
||||
REQUIRE(f.bs.isQueuedForDeconstruction(b));
|
||||
REQUIRE(f.stock == 15 * f.cfg.world.refundPercentage / 100);
|
||||
|
||||
// The second drains next.
|
||||
runTicks(f.bs, f.belts, static_cast<int>(secondsToTicks(0.1)) + 2, tick);
|
||||
REQUIRE(f.bs.findBuilding(b) == nullptr);
|
||||
REQUIRE(f.stock == 2 * (15 * f.cfg.world.refundPercentage / 100));
|
||||
}
|
||||
|
||||
TEST_CASE("BuildingSystem: cancelling deconstruction resumes the building with no refund",
|
||||
"[building][decon]")
|
||||
{
|
||||
PlacementFixture f;
|
||||
const BuildingId id =
|
||||
f.bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0).value();
|
||||
|
||||
Tick tick = 0;
|
||||
runUntilBuilt(f, id, tick);
|
||||
|
||||
f.bs.deconstruct(id, tick);
|
||||
REQUIRE(f.bs.isQueuedForDeconstruction(id));
|
||||
|
||||
// Un-queue before it drains: it operates again, no refund, tiles still occupied.
|
||||
f.bs.cancelDeconstruction(id);
|
||||
REQUIRE_FALSE(f.bs.isQueuedForDeconstruction(id));
|
||||
REQUIRE(f.bs.findBuilding(id) != nullptr);
|
||||
REQUIRE(f.bs.isTileOccupied(QPoint(0, 0)));
|
||||
REQUIRE(f.stock == 0);
|
||||
|
||||
// It is never removed even after more than a deconstruction interval passes.
|
||||
runTicks(f.bs, f.belts, static_cast<int>(secondsToTicks(0.1)) + 5, tick);
|
||||
REQUIRE(f.bs.findBuilding(id) != nullptr);
|
||||
REQUIRE(f.stock == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("BuildingSystem: queued belt stops transporting; cancel restores it", "[building][decon]")
|
||||
{
|
||||
PlacementFixture f;
|
||||
const BuildingId id =
|
||||
f.bs.place(BuildingType::Belt, QPoint(0, 0), Rotation::East, 0).value();
|
||||
|
||||
Tick tick = 0;
|
||||
runUntilBuilt(f, id, tick);
|
||||
REQUIRE(f.belts.tryPutItem(QPoint(0, 0), makeItem("iron_ore"), Rotation::East));
|
||||
|
||||
// Queuing a belt unregisters its tile from the belt subsystem, so it no longer
|
||||
// accepts or transports items, though the tile stays occupied (REQ-BLD-DECON-QUEUE).
|
||||
f.bs.deconstruct(id, tick);
|
||||
REQUIRE_FALSE(f.belts.tryPutItem(QPoint(0, 0), makeItem("iron_ore"), Rotation::East));
|
||||
REQUIRE(f.bs.isTileOccupied(QPoint(0, 0)));
|
||||
|
||||
// Un-queuing re-registers the belt tile so it transports again.
|
||||
f.bs.cancelDeconstruction(id);
|
||||
REQUIRE(f.belts.tryPutItem(QPoint(0, 0), makeItem("iron_ore"), Rotation::East));
|
||||
}
|
||||
|
||||
TEST_CASE("BuildingSystem: splitter filters survive a queue/un-queue round-trip", "[building][decon]")
|
||||
{
|
||||
PlacementFixture f;
|
||||
const BuildingId id =
|
||||
f.bs.place(BuildingType::Splitter, QPoint(0, 0), Rotation::East, 0).value();
|
||||
|
||||
Tick tick = 0;
|
||||
runUntilBuilt(f, id, tick);
|
||||
|
||||
f.belts.setSplitterFilters(QPoint(0, 0), {ItemType{"iron_ore"}}, {});
|
||||
|
||||
// Queue: the belt subsystem tile (and its filters) are unregistered, but the
|
||||
// filters are captured so an un-queue can restore them.
|
||||
f.bs.deconstruct(id, tick);
|
||||
REQUIRE_FALSE(f.belts.getSplitterInfo(QPoint(0, 0)).has_value());
|
||||
|
||||
f.bs.cancelDeconstruction(id);
|
||||
const std::optional<BeltSystem::SplitterInfo> info = f.belts.getSplitterInfo(QPoint(0, 0));
|
||||
REQUIRE(info.has_value());
|
||||
REQUIRE(info->filterA.size() == 1);
|
||||
REQUIRE(info->filterA[0].id == "iron_ore");
|
||||
REQUIRE(info->filterB.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("BuildingSystem: second building starts after first completes", "[building]")
|
||||
{
|
||||
const GameConfig cfg = loadConfig();
|
||||
@@ -377,15 +508,15 @@ TEST_CASE("BuildingSystem: second building starts after first completes", "[buil
|
||||
rng);
|
||||
|
||||
bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId id2 = bs.place(BuildingType::Miner, QPoint(5, 5), Rotation::East, 0);
|
||||
const BuildingId id2 = bs.place(BuildingType::Miner, QPoint(5, 5), Rotation::East, 0).value();
|
||||
|
||||
// Process through tick 300 to complete first miner's construction.
|
||||
Tick tick = 0;
|
||||
runTicks(bs, belts, static_cast<int>(secondsToTicks(10.0)) + 1, tick);
|
||||
|
||||
REQUIRE(bs.allSites().size() == 1);
|
||||
REQUIRE(bs.allSites().front().id == id2);
|
||||
REQUIRE(bs.allSites().front().completesAt > 0);
|
||||
REQUIRE(bs.getAllSites().size() == 1);
|
||||
REQUIRE(bs.getAllSites().front().id == id2);
|
||||
REQUIRE(bs.getAllSites().front().completesAt > 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -406,7 +537,7 @@ TEST_CASE("BuildingSystem: miner produces iron_ore after recipe duration", "[bui
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
const BuildingId id = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId id = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0).value();
|
||||
bs.setRecipe(id, "mine_iron_ore");
|
||||
|
||||
Tick tick = 0;
|
||||
@@ -439,7 +570,7 @@ TEST_CASE("BuildingSystem: miner output buffer stalls when full", "[building]")
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
const BuildingId id = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId id = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0).value();
|
||||
bs.setRecipe(id, "mine_iron_ore");
|
||||
|
||||
Tick tick = 0;
|
||||
@@ -457,7 +588,7 @@ TEST_CASE("BuildingSystem: miner output buffer stalls when full", "[building]")
|
||||
REQUIRE(b != nullptr);
|
||||
// Both produced items are held on the output side (buffer + emerging lane),
|
||||
// which is what the capacity rule counts (REQ-MAT-OUTPUT-EMERGE).
|
||||
REQUIRE(b->outputItemCount() == 2);
|
||||
REQUIRE(b->getOutputItemCount() == 2);
|
||||
REQUIRE_FALSE(b->production.has_value());
|
||||
}
|
||||
|
||||
@@ -479,29 +610,29 @@ TEST_CASE("BuildingSystem: productionBuildingCount excludes construction sites",
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
const BuildingId minerId = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId smelterId = bs.place(BuildingType::Smelter, QPoint(10, 0), Rotation::East, 0);
|
||||
const BuildingId minerId = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0).value();
|
||||
const BuildingId smelterId = bs.place(BuildingType::Smelter, QPoint(10, 0), Rotation::East, 0).value();
|
||||
(void)smelterId;
|
||||
|
||||
Tick tick = 0;
|
||||
// Both still under construction.
|
||||
REQUIRE(bs.productionBuildingCount() == 0);
|
||||
REQUIRE(bs.getProductionBuildingCount() == 0);
|
||||
|
||||
// The queue builds one at a time: miner (10s) completes at tick 300, then
|
||||
// the smelter (15s) starts and completes at tick 300 + 450 = 750.
|
||||
runTicks(bs, belts, static_cast<int>(secondsToTicks(10.0)) + 1, tick);
|
||||
REQUIRE(bs.productionBuildingCount() == 1);
|
||||
REQUIRE(bs.getProductionBuildingCount() == 1);
|
||||
|
||||
runTicks(bs, belts, static_cast<int>(secondsToTicks(15.0)), tick);
|
||||
REQUIRE(bs.productionBuildingCount() == 2);
|
||||
REQUIRE(bs.getProductionBuildingCount() == 2);
|
||||
|
||||
// Neither is producing yet: the miner has no recipe selected, and the
|
||||
// smelter (auto-recipe, REQ-BLD-SMELTER) has no input feeding it.
|
||||
REQUIRE(bs.activeProductionBuildingCount() == 0);
|
||||
REQUIRE(bs.getActiveProductionBuildingCount() == 0);
|
||||
|
||||
bs.setRecipe(minerId, "mine_iron_ore");
|
||||
runTicks(bs, belts, 1, tick);
|
||||
REQUIRE(bs.activeProductionBuildingCount() == 1);
|
||||
REQUIRE(bs.getActiveProductionBuildingCount() == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("BuildingSystem: activeProductionBuildingCount tracks production cycle state",
|
||||
@@ -519,16 +650,16 @@ TEST_CASE("BuildingSystem: activeProductionBuildingCount tracks production cycle
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
const BuildingId id = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId id = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0).value();
|
||||
bs.setRecipe(id, "mine_iron_ore");
|
||||
|
||||
Tick tick = 0;
|
||||
// Not yet operational while under construction.
|
||||
REQUIRE(bs.activeProductionBuildingCount() == 0);
|
||||
REQUIRE(bs.getActiveProductionBuildingCount() == 0);
|
||||
|
||||
// Construction completes at tick 300; cycle 1 starts the same tick (completesAt=330).
|
||||
runTicks(bs, belts, static_cast<int>(secondsToTicks(10.0)) + 1, tick);
|
||||
REQUIRE(bs.activeProductionBuildingCount() == 1);
|
||||
REQUIRE(bs.getActiveProductionBuildingCount() == 1);
|
||||
|
||||
// Run cycles 1 and 2 to completion (1s each); cycle 3 stalls once the
|
||||
// output buffer (capacity 2) is full (REQ-MAT-OUTPUT-BUFFER).
|
||||
@@ -536,9 +667,9 @@ TEST_CASE("BuildingSystem: activeProductionBuildingCount tracks production cycle
|
||||
|
||||
const Building* b = bs.findBuilding(id);
|
||||
REQUIRE(b != nullptr);
|
||||
REQUIRE(b->outputItemCount() == 2);
|
||||
REQUIRE(b->getOutputItemCount() == 2);
|
||||
REQUIRE_FALSE(b->production.has_value());
|
||||
REQUIRE(bs.activeProductionBuildingCount() == 0);
|
||||
REQUIRE(bs.getActiveProductionBuildingCount() == 0);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -563,7 +694,7 @@ TEST_CASE("BuildingSystem: smelter input buffer fills from adjacent west-flowing
|
||||
|
||||
// Smelter mask ["AA ","AA>"] → body (0,0),(1,0),(0,1),(1,1).
|
||||
// Output port (2,1) East. Input port example: (2,0) West.
|
||||
const BuildingId sid = bs.place(BuildingType::Smelter, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId sid = bs.place(BuildingType::Smelter, QPoint(0, 0), Rotation::East, 0).value();
|
||||
// Smelters have no recipe selection (REQ-BLD-SMELTER); they auto-accept any
|
||||
// ore/scrap that is an input to a smelter recipe.
|
||||
|
||||
@@ -603,7 +734,7 @@ TEST_CASE("BuildingSystem: accepted input travels inward before entering the buf
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
const BuildingId sid = bs.place(BuildingType::Smelter, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId sid = bs.place(BuildingType::Smelter, QPoint(0, 0), Rotation::East, 0).value();
|
||||
Tick tick = 0;
|
||||
runTicks(bs, belts, static_cast<int>(secondsToTicks(15.0)) + 1, tick);
|
||||
|
||||
@@ -645,7 +776,7 @@ TEST_CASE("BuildingSystem: input reservation caps buffered plus in-transit at th
|
||||
rng);
|
||||
|
||||
const BuildingId id = bs.place(BuildingType::ReprocessingPlant,
|
||||
QPoint(0, 0), Rotation::East, 0);
|
||||
QPoint(0, 0), Rotation::East, 0).value();
|
||||
Tick tick = 0;
|
||||
runTicks(bs, belts, static_cast<int>(secondsToTicks(25.0)) + 1, tick);
|
||||
|
||||
@@ -686,7 +817,7 @@ TEST_CASE("BuildingSystem: smelter auto-smelts ore without a recipe selection",
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
const BuildingId sid = bs.place(BuildingType::Smelter, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId sid = bs.place(BuildingType::Smelter, QPoint(0, 0), Rotation::East, 0).value();
|
||||
|
||||
Tick tick = 0;
|
||||
runTicks(bs, belts, static_cast<int>(secondsToTicks(15.0)) + 1, tick);
|
||||
@@ -732,7 +863,7 @@ TEST_CASE("BuildingSystem: smelter runs a satisfiable recipe while an incomplete
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
const BuildingId sid = bs.place(BuildingType::Smelter, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId sid = bs.place(BuildingType::Smelter, QPoint(0, 0), Rotation::East, 0).value();
|
||||
|
||||
Tick tick = 0;
|
||||
runTicks(bs, belts, static_cast<int>(secondsToTicks(15.0)) + 1, tick);
|
||||
@@ -786,7 +917,7 @@ TEST_CASE("BuildingSystem: miner output buffer drains onto adjacent belt", "[bui
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
const BuildingId id = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId id = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0).value();
|
||||
bs.setRecipe(id, "mine_iron_ore");
|
||||
|
||||
// Belt at the miner's output port tile (1,1) flowing East.
|
||||
@@ -826,12 +957,12 @@ TEST_CASE("BuildingSystem: output port couples directly into an adjacent input p
|
||||
rng);
|
||||
|
||||
// Miner at (0,0): body (0,0),(1,0),(0,1); output port tile (1,1) flowing East.
|
||||
const BuildingId minerId = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId minerId = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0).value();
|
||||
bs.setRecipe(minerId, "mine_iron_ore");
|
||||
// Smelter anchored at (1,1): body (1,1),(2,1),(1,2),(2,2). Its body cell (1,1) is
|
||||
// the miner's output-port tile, and its west input edge there faces East, so the
|
||||
// two ports meet — no belt placed anywhere.
|
||||
const BuildingId smelterId = bs.place(BuildingType::Smelter, QPoint(1, 1), Rotation::East, 0);
|
||||
const BuildingId smelterId = bs.place(BuildingType::Smelter, QPoint(1, 1), Rotation::East, 0).value();
|
||||
|
||||
Tick tick = 0;
|
||||
// Smelter build (15s) + margin for coupling and a smelt cycle.
|
||||
@@ -866,11 +997,11 @@ TEST_CASE("BuildingSystem: direct coupling to a non-consumer leaves the item stu
|
||||
rng);
|
||||
|
||||
// Producing miner at (0,0), output port (1,1) East.
|
||||
const BuildingId minerId = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId minerId = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0).value();
|
||||
bs.setRecipe(minerId, "mine_iron_ore");
|
||||
// A second, idle miner anchored at (1,1) occupies the output-port tile but takes
|
||||
// no inputs, so it cannot accept the iron_ore.
|
||||
const BuildingId sinkId = bs.place(BuildingType::Miner, QPoint(1, 1), Rotation::East, 0);
|
||||
const BuildingId sinkId = bs.place(BuildingType::Miner, QPoint(1, 1), Rotation::East, 0).value();
|
||||
|
||||
Tick tick = 0;
|
||||
// Both miners build sequentially (10s each), then the producer runs and jams.
|
||||
@@ -882,7 +1013,7 @@ TEST_CASE("BuildingSystem: direct coupling to a non-consumer leaves the item stu
|
||||
REQUIRE(sink != nullptr);
|
||||
// Nothing was delivered, and the producer's output side has backed up to its cap.
|
||||
REQUIRE(sink->pendingInputCount(ItemType{"iron_ore"}) == 0);
|
||||
REQUIRE(miner->outputItemCount() == miner->outputBuffer.capacity);
|
||||
REQUIRE(miner->getOutputItemCount() == miner->outputBuffer.capacity);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -904,7 +1035,7 @@ TEST_CASE("BuildingSystem: setRecipe clears output buffer and active production"
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
const BuildingId id = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId id = bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0).value();
|
||||
bs.setRecipe(id, "mine_iron_ore");
|
||||
|
||||
Tick tick = 0;
|
||||
@@ -916,7 +1047,7 @@ TEST_CASE("BuildingSystem: setRecipe clears output buffer and active production"
|
||||
{
|
||||
const Building* b = bs.findBuilding(id);
|
||||
REQUIRE(b != nullptr);
|
||||
REQUIRE(b->outputItemCount() > 0);
|
||||
REQUIRE(b->getOutputItemCount() > 0);
|
||||
}
|
||||
|
||||
bs.setRecipe(id, "mine_copper_ore");
|
||||
@@ -924,7 +1055,7 @@ TEST_CASE("BuildingSystem: setRecipe clears output buffer and active production"
|
||||
const Building* b = bs.findBuilding(id);
|
||||
// Clearing the output buffer on a recipe change also discards emerging items
|
||||
// (REQ-MAT-OUTPUT-EMERGE).
|
||||
REQUIRE(b->outputItemCount() == 0);
|
||||
REQUIRE(b->getOutputItemCount() == 0);
|
||||
REQUIRE_FALSE(b->production.has_value());
|
||||
}
|
||||
|
||||
@@ -948,7 +1079,7 @@ TEST_CASE("BuildingSystem: reprocessing plant output buffer capacity equals max
|
||||
rng);
|
||||
|
||||
const BuildingId id = bs.place(BuildingType::ReprocessingPlant,
|
||||
QPoint(0, 0), Rotation::East, 0);
|
||||
QPoint(0, 0), Rotation::East, 0).value();
|
||||
// Reprocessing plants have no recipe selection (REQ-BLD-REPROCESSING); the
|
||||
// single reprocessing recipe is applied automatically on completion.
|
||||
|
||||
@@ -980,7 +1111,7 @@ TEST_CASE("BuildingSystem: reprocessing plant produces one cycle output then sta
|
||||
rng);
|
||||
|
||||
const BuildingId id = bs.place(BuildingType::ReprocessingPlant,
|
||||
QPoint(0, 0), Rotation::East, 0);
|
||||
QPoint(0, 0), Rotation::East, 0).value();
|
||||
// Reprocessing plants have no recipe selection (REQ-BLD-REPROCESSING); the
|
||||
// single reprocessing recipe is applied automatically on completion.
|
||||
|
||||
@@ -1056,7 +1187,7 @@ TEST_CASE("BuildingSystem: findRotateInPlaceTarget returns the site id for a que
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
const BuildingId id = bs.place(BuildingType::Belt, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId id = bs.place(BuildingType::Belt, QPoint(0, 0), Rotation::East, 0).value();
|
||||
|
||||
const std::optional<BuildingId> result =
|
||||
bs.findRotateInPlaceTarget(BuildingType::Belt, QPoint(0, 0), Rotation::North);
|
||||
@@ -1079,11 +1210,11 @@ TEST_CASE("BuildingSystem: findRotateInPlaceTarget returns the building id for a
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
const BuildingId id = bs.place(BuildingType::Belt, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId id = bs.place(BuildingType::Belt, QPoint(0, 0), Rotation::East, 0).value();
|
||||
|
||||
Tick tick = 0;
|
||||
runTicks(bs, belts, static_cast<int>(secondsToTicks(1.0)) + 1, tick);
|
||||
REQUIRE(bs.allSites().empty());
|
||||
REQUIRE(bs.getAllSites().empty());
|
||||
|
||||
const std::optional<BuildingId> result =
|
||||
bs.findRotateInPlaceTarget(BuildingType::Belt, QPoint(0, 0), Rotation::South);
|
||||
@@ -1113,6 +1244,32 @@ TEST_CASE("BuildingSystem: findRotateInPlaceTarget returns nullopt when building
|
||||
bs.findRotateInPlaceTarget(BuildingType::Splitter, QPoint(0, 0), Rotation::East).has_value());
|
||||
}
|
||||
|
||||
TEST_CASE("BuildingSystem: findRotateInPlaceTarget never rotates a tunnel in place",
|
||||
"[building][rotate-in-place]")
|
||||
{
|
||||
const GameConfig cfg = loadConfig();
|
||||
BeltSystem belts(cfg.world.beltSpeed_tps);
|
||||
int stock = 0;
|
||||
std::mt19937 rng(0);
|
||||
BuildingId nextBuildingId = 1;
|
||||
BuildingSystem bs(cfg, belts,
|
||||
[&nextBuildingId]() { return nextBuildingId++; },
|
||||
[&stock](int n) { stock += n; },
|
||||
[](const std::string&, QVector2D, const std::optional<ShipLayoutConfig>&) {},
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
// Even with a coincident same-type tunnel under the ghost, rotate-in-place is
|
||||
// never offered for tunnels (REQ-BLD-ROTATE-IN-PLACE exception).
|
||||
bs.place(BuildingType::TunnelEntry, QPoint(-1, 0), Rotation::East, 0);
|
||||
bs.place(BuildingType::TunnelExit, QPoint(-2, 0), Rotation::East, 0);
|
||||
|
||||
REQUIRE_FALSE(
|
||||
bs.findRotateInPlaceTarget(BuildingType::TunnelEntry, QPoint(-1, 0), Rotation::North).has_value());
|
||||
REQUIRE_FALSE(
|
||||
bs.findRotateInPlaceTarget(BuildingType::TunnelExit, QPoint(-2, 0), Rotation::North).has_value());
|
||||
}
|
||||
|
||||
TEST_CASE("BuildingSystem: findRotateInPlaceTarget returns nullopt when footprints only partially overlap",
|
||||
"[building][rotate-in-place]")
|
||||
{
|
||||
@@ -1154,7 +1311,7 @@ TEST_CASE("BuildingSystem: findRotateInPlaceTarget works for a symmetric multi-t
|
||||
|
||||
// Smelter is a fully filled 2×2 footprint — rotating the ghost produces the
|
||||
// same four body tiles, so findRotateInPlaceTarget must still return the id.
|
||||
const BuildingId id = bs.place(BuildingType::Smelter, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId id = bs.place(BuildingType::Smelter, QPoint(0, 0), Rotation::East, 0).value();
|
||||
|
||||
const std::optional<BuildingId> result =
|
||||
bs.findRotateInPlaceTarget(BuildingType::Smelter, QPoint(0, 0), Rotation::North);
|
||||
@@ -1181,7 +1338,7 @@ TEST_CASE("BuildingSystem: rotateInPlace updates the rotation field of a constru
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
const BuildingId id = bs.place(BuildingType::Belt, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId id = bs.place(BuildingType::Belt, QPoint(0, 0), Rotation::East, 0).value();
|
||||
REQUIRE(bs.findSite(id)->rotation == Rotation::East);
|
||||
|
||||
bs.rotateInPlace(id, Rotation::North);
|
||||
@@ -1204,7 +1361,7 @@ TEST_CASE("BuildingSystem: rotateInPlace preserves the construction progress of
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
const BuildingId id = bs.place(BuildingType::Belt, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId id = bs.place(BuildingType::Belt, QPoint(0, 0), Rotation::East, 0).value();
|
||||
const Tick completesAt = bs.findSite(id)->completesAt;
|
||||
REQUIRE(completesAt > 0);
|
||||
|
||||
@@ -1228,7 +1385,7 @@ TEST_CASE("BuildingSystem: rotateInPlace updates rotation and output port direct
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
const BuildingId id = bs.place(BuildingType::Belt, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId id = bs.place(BuildingType::Belt, QPoint(0, 0), Rotation::East, 0).value();
|
||||
|
||||
Tick tick = 0;
|
||||
runTicks(bs, belts, static_cast<int>(secondsToTicks(1.0)) + 1, tick);
|
||||
@@ -1259,7 +1416,7 @@ TEST_CASE("BuildingSystem: rotateInPlace re-registers a belt tile with BeltSyste
|
||||
[](const std::string&) -> bool { return true; },
|
||||
rng);
|
||||
|
||||
const BuildingId id = bs.place(BuildingType::Belt, QPoint(0, 0), Rotation::East, 0);
|
||||
const BuildingId id = bs.place(BuildingType::Belt, QPoint(0, 0), Rotation::East, 0).value();
|
||||
|
||||
Tick tick = 0;
|
||||
runTicks(bs, belts, static_cast<int>(secondsToTicks(1.0)) + 1, tick);
|
||||
@@ -1276,7 +1433,7 @@ TEST_CASE("BuildingSystem: splitter filters configured on a construction site ca
|
||||
PlacementFixture f;
|
||||
|
||||
const QPoint tile(5, 5);
|
||||
const BuildingId id = f.bs.place(BuildingType::Splitter, tile, Rotation::East, 0);
|
||||
const BuildingId id = f.bs.place(BuildingType::Splitter, tile, Rotation::East, 0).value();
|
||||
REQUIRE(id != kInvalidBuildingId);
|
||||
REQUIRE(f.bs.findSite(id) != nullptr);
|
||||
|
||||
@@ -1295,12 +1452,12 @@ TEST_CASE("BuildingSystem: splitter filters configured on a construction site ca
|
||||
|
||||
// Run until construction completes.
|
||||
Tick tick = 0;
|
||||
while (f.bs.allBuildings().empty() && tick < 100000)
|
||||
while (f.bs.getAllBuildings().empty() && tick < 100000)
|
||||
{
|
||||
runTicks(f.bs, f.belts, 1, tick);
|
||||
}
|
||||
REQUIRE(f.bs.allBuildings().size() == 1);
|
||||
REQUIRE(f.bs.allBuildings()[0].type == BuildingType::Splitter);
|
||||
REQUIRE(f.bs.getAllBuildings().size() == 1);
|
||||
REQUIRE(f.bs.getAllBuildings()[0].type == BuildingType::Splitter);
|
||||
|
||||
// The built splitter is registered with BeltSystem carrying the filters.
|
||||
const std::optional<BeltSystem::SplitterInfo> builtInfo = f.belts.getSplitterInfo(tile);
|
||||
@@ -1308,3 +1465,219 @@ TEST_CASE("BuildingSystem: splitter filters configured on a construction site ca
|
||||
REQUIRE(builtInfo->filterA == filterA);
|
||||
REQUIRE(builtInfo->filterB.empty());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Production status classifier (REQ-UI-STATUS-LIGHT)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
TEST_CASE("BuildingSystem: getProductionStatus classifies production state", "[building]")
|
||||
{
|
||||
PlacementFixture f;
|
||||
|
||||
// Pick representative config ids so the test survives content edits.
|
||||
std::string minerRecipeId;
|
||||
for (const RecipeDef& r : f.cfg.recipes.recipes)
|
||||
{
|
||||
if (r.building == BuildingType::Miner) { minerRecipeId = r.id; break; }
|
||||
}
|
||||
REQUIRE_FALSE(minerRecipeId.empty());
|
||||
|
||||
const RecipeDef* assemblerRecipe = nullptr;
|
||||
for (const RecipeDef& r : f.cfg.recipes.recipes)
|
||||
{
|
||||
if (r.building == BuildingType::Assembler && !r.inputs.empty())
|
||||
{
|
||||
assemblerRecipe = &r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
REQUIRE(assemblerRecipe != nullptr);
|
||||
|
||||
std::string shipId;
|
||||
for (const ShipDef& s : f.cfg.ships.ships)
|
||||
{
|
||||
if (!s.schematic.materials.empty()) { shipId = s.id; break; }
|
||||
}
|
||||
REQUIRE_FALSE(shipId.empty());
|
||||
|
||||
const auto statusOf = [&f](const Building& b) { return f.bs.getProductionStatus(b); };
|
||||
|
||||
SECTION("non-production buildings show no status light")
|
||||
{
|
||||
Building belt; belt.type = BuildingType::Belt;
|
||||
Building hq; hq.type = BuildingType::Hq;
|
||||
REQUIRE_FALSE(statusOf(belt).has_value());
|
||||
REQUIRE_FALSE(statusOf(hq).has_value());
|
||||
}
|
||||
|
||||
SECTION("Miner: unconfigured, producing, output-blocked")
|
||||
{
|
||||
Building miner; miner.type = BuildingType::Miner;
|
||||
REQUIRE(statusOf(miner) == ProductionStatus::Unconfigured); // no recipe -> grey
|
||||
|
||||
miner.recipeId = minerRecipeId;
|
||||
miner.production = Production{};
|
||||
REQUIRE(statusOf(miner) == ProductionStatus::Producing); // active cycle -> green
|
||||
|
||||
// A miner has no inputs, so its only idle reason is a full output buffer.
|
||||
miner.production = std::nullopt;
|
||||
miner.outputBuffer.capacity = 2;
|
||||
miner.outputBuffer.items = { makeItem("iron_ore"), makeItem("iron_ore") };
|
||||
REQUIRE(statusOf(miner) == ProductionStatus::Blocked); // -> yellow
|
||||
}
|
||||
|
||||
SECTION("Assembler: starved vs blocked, input-missing takes precedence")
|
||||
{
|
||||
Building assembler; assembler.type = BuildingType::Assembler;
|
||||
assembler.recipeId = assemblerRecipe->id;
|
||||
|
||||
// Idle with inputs missing -> red.
|
||||
REQUIRE(statusOf(assembler) == ProductionStatus::Starved);
|
||||
|
||||
// Inputs present but idle -> the only remaining reason is a full output
|
||||
// buffer -> yellow.
|
||||
for (const RecipeIngredient& ing : assemblerRecipe->inputs)
|
||||
{
|
||||
assembler.inputBuffer.counts[ItemType{ing.item}] = ing.amount;
|
||||
}
|
||||
REQUIRE(statusOf(assembler) == ProductionStatus::Blocked);
|
||||
|
||||
// Inputs missing AND output full -> red wins over yellow.
|
||||
assembler.inputBuffer.counts.clear();
|
||||
assembler.outputBuffer.capacity = 2;
|
||||
assembler.outputBuffer.items = { makeItem("x"), makeItem("x") };
|
||||
REQUIRE(statusOf(assembler) == ProductionStatus::Starved);
|
||||
}
|
||||
|
||||
SECTION("Smelter (auto-recipe) is never grey")
|
||||
{
|
||||
Building smelter; smelter.type = BuildingType::Smelter;
|
||||
// No player-selectable recipe and empty inputs -> red, not grey.
|
||||
REQUIRE(statusOf(smelter) == ProductionStatus::Starved);
|
||||
}
|
||||
|
||||
SECTION("Shipyard: unconfigured, then starved without materials, then producing")
|
||||
{
|
||||
Building yard; yard.type = BuildingType::Shipyard;
|
||||
REQUIRE(statusOf(yard) == ProductionStatus::Unconfigured); // no schematic -> grey
|
||||
|
||||
yard.recipeId = shipId;
|
||||
REQUIRE(statusOf(yard) == ProductionStatus::Starved); // no materials -> red
|
||||
|
||||
yard.production = Production{};
|
||||
REQUIRE(statusOf(yard) == ProductionStatus::Producing); // active cycle -> green
|
||||
}
|
||||
|
||||
SECTION("Salvage Bay: red when empty, green when holding scrap")
|
||||
{
|
||||
Building bay; bay.type = BuildingType::SalvageBay;
|
||||
bay.outputBuffer.capacity = 20;
|
||||
REQUIRE(statusOf(bay) == ProductionStatus::Starved); // empty -> red
|
||||
|
||||
bay.outputBuffer.items = { makeItem("scrap") };
|
||||
REQUIRE(statusOf(bay) == ProductionStatus::Producing); // holding scrap -> green
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// getInputPorts (REQ-BLD-BELT-DRAG snapping, REQ-MAT-INPUT-PORTS)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
namespace
|
||||
{
|
||||
QPoint directionDelta(Rotation direction)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case Rotation::North: return QPoint(0, -1);
|
||||
case Rotation::East: return QPoint(1, 0);
|
||||
case Rotation::South: return QPoint(0, 1);
|
||||
case Rotation::West: return QPoint(-1, 0);
|
||||
}
|
||||
return QPoint(0, 0);
|
||||
}
|
||||
|
||||
bool hasInputPort(const std::vector<Port>& ports, QPoint tile, Rotation direction)
|
||||
{
|
||||
for (const Port& port : ports)
|
||||
{
|
||||
if (port.tile == tile && port.direction == direction) { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Advances the sim until the given site becomes an operational building, or a
|
||||
// safety cap is reached.
|
||||
void buildToCompletion(BuildingSystem& bs, BeltSystem& belts, BuildingId id,
|
||||
Tick& tick)
|
||||
{
|
||||
for (int i = 0; i < 20000 && bs.findBuilding(id) == nullptr; ++i)
|
||||
{
|
||||
runTicks(bs, belts, 1, tick);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("BuildingSystem: getInputPorts on a miner site lists every input edge", "[building]")
|
||||
{
|
||||
PlacementFixture f;
|
||||
// Miner mask ["AA","A>"] East → body (0,0),(1,0),(0,1); output tile (1,1) East.
|
||||
const BuildingId id = f.bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0).value();
|
||||
|
||||
const std::vector<Port> ports = f.bs.getInputPorts(id);
|
||||
|
||||
// Every perimeter edge except the output-port edge at (1,1), each pointing in.
|
||||
REQUIRE(ports.size() == 6);
|
||||
REQUIRE(hasInputPort(ports, QPoint(-1, 0), Rotation::East));
|
||||
REQUIRE(hasInputPort(ports, QPoint(0, -1), Rotation::South));
|
||||
REQUIRE(hasInputPort(ports, QPoint(2, 0), Rotation::West));
|
||||
REQUIRE(hasInputPort(ports, QPoint(1, -1), Rotation::South));
|
||||
REQUIRE(hasInputPort(ports, QPoint(-1, 1), Rotation::East));
|
||||
REQUIRE(hasInputPort(ports, QPoint(0, 2), Rotation::North));
|
||||
|
||||
// The output-port tile is never an input port.
|
||||
REQUIRE_FALSE(hasInputPort(ports, QPoint(1, 1), Rotation::North));
|
||||
REQUIRE_FALSE(hasInputPort(ports, QPoint(1, 1), Rotation::West));
|
||||
}
|
||||
|
||||
TEST_CASE("BuildingSystem: getInputPorts matches between a site and the built building",
|
||||
"[building]")
|
||||
{
|
||||
PlacementFixture f;
|
||||
Tick tick = 0;
|
||||
const BuildingId id = f.bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::East, 0).value();
|
||||
|
||||
const std::vector<Port> sitePorts = f.bs.getInputPorts(id);
|
||||
buildToCompletion(f.bs, f.belts, id, tick);
|
||||
REQUIRE(f.bs.findBuilding(id) != nullptr);
|
||||
const std::vector<Port> builtPorts = f.bs.getInputPorts(id);
|
||||
|
||||
// The operational path (stored inputPorts) agrees with the site path (mask-derived).
|
||||
REQUIRE(builtPorts.size() == sitePorts.size());
|
||||
for (const Port& port : sitePorts)
|
||||
{
|
||||
REQUIRE(hasInputPort(builtPorts, port.tile, port.direction));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("BuildingSystem: getInputPorts invariants hold for a rotated site", "[building]")
|
||||
{
|
||||
PlacementFixture f;
|
||||
const BuildingId id = f.bs.place(BuildingType::Miner, QPoint(0, 0), Rotation::South, 0).value();
|
||||
const ConstructionSite* site = f.bs.findSite(id);
|
||||
REQUIRE(site != nullptr);
|
||||
|
||||
std::set<std::pair<int, int>> bodySet;
|
||||
for (const QPoint& cell : site->bodyCells) { bodySet.insert({cell.x(), cell.y()}); }
|
||||
|
||||
const std::vector<Port> ports = f.bs.getInputPorts(id);
|
||||
REQUIRE_FALSE(ports.empty());
|
||||
for (const Port& port : ports)
|
||||
{
|
||||
// Each port tile is outside the footprint...
|
||||
REQUIRE(bodySet.count({port.tile.x(), port.tile.y()}) == 0);
|
||||
// ...and its direction points into an adjacent body cell.
|
||||
const QPoint into = port.tile + directionDelta(port.direction);
|
||||
REQUIRE(bodySet.count({into.x(), into.y()}) == 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ add_files(
|
||||
SimulationTest.cpp
|
||||
BeltSystemTest.cpp
|
||||
SurfaceMaskTest.cpp
|
||||
BeltDragPathTest.cpp
|
||||
TunnelCompletionTest.cpp
|
||||
BuildingTest.cpp
|
||||
BuildingConfigTest.cpp
|
||||
ShipTest.cpp
|
||||
@@ -23,6 +25,7 @@ add_files(
|
||||
ThreatCostCalculatorTest.cpp
|
||||
RecipeSchematicTest.cpp
|
||||
UnlockPrereqTest.cpp
|
||||
UnlockGroupTest.cpp
|
||||
ArtifactWinConditionTest.cpp
|
||||
DeterminismTest.cpp
|
||||
CommandTest.cpp
|
||||
|
||||
@@ -183,7 +183,7 @@ TEST_CASE("CombatSystem: player station fires at enemy ship in range", "[combat]
|
||||
// Find the player station entity via ECS.
|
||||
entt::entity stationEntity = entt::null;
|
||||
QVector2D stationCenter;
|
||||
sim.admin().forEach<StationBodyComponent, FactionComponent>(
|
||||
sim.getAdmin().forEach<StationBodyComponent, FactionComponent>(
|
||||
[&](entt::entity e, const StationBodyComponent& sb, const FactionComponent& f)
|
||||
{
|
||||
if (!f.isEnemy && stationEntity == entt::null)
|
||||
@@ -194,12 +194,12 @@ TEST_CASE("CombatSystem: player station fires at enemy ship in range", "[combat]
|
||||
sb.anchor.y() + sb.footprint.height() / 2.0f);
|
||||
}
|
||||
});
|
||||
REQUIRE(sim.admin().isValid(stationEntity));
|
||||
REQUIRE(sim.getAdmin().isValid(stationEntity));
|
||||
|
||||
const ShipDef* combatDef = findCombatShip(sim.config());
|
||||
const ShipDef* combatDef = findCombatShip(sim.getConfig());
|
||||
REQUIRE(combatDef != nullptr);
|
||||
|
||||
const entt::entity enemyShip = sim.ships().spawn(
|
||||
const entt::entity enemyShip = sim.getShips().spawn(
|
||||
combatDef->id,
|
||||
QVector2D(stationCenter.x() + 1.0f, stationCenter.y()),
|
||||
/*isEnemy=*/true);
|
||||
@@ -221,7 +221,7 @@ TEST_CASE("CombatSystem: enemy station fires at player ship in range", "[combat]
|
||||
|
||||
entt::entity stationEntity = entt::null;
|
||||
QVector2D stationCenter;
|
||||
sim.admin().forEach<StationBodyComponent, FactionComponent>(
|
||||
sim.getAdmin().forEach<StationBodyComponent, FactionComponent>(
|
||||
[&](entt::entity e, const StationBodyComponent& sb, const FactionComponent& f)
|
||||
{
|
||||
if (f.isEnemy && stationEntity == entt::null)
|
||||
@@ -232,12 +232,12 @@ TEST_CASE("CombatSystem: enemy station fires at player ship in range", "[combat]
|
||||
sb.anchor.y() + sb.footprint.height() / 2.0f);
|
||||
}
|
||||
});
|
||||
REQUIRE(sim.admin().isValid(stationEntity));
|
||||
REQUIRE(sim.getAdmin().isValid(stationEntity));
|
||||
|
||||
const ShipDef* combatDef = findCombatShip(sim.config());
|
||||
const ShipDef* combatDef = findCombatShip(sim.getConfig());
|
||||
REQUIRE(combatDef != nullptr);
|
||||
|
||||
sim.ships().spawn(
|
||||
sim.getShips().spawn(
|
||||
combatDef->id,
|
||||
QVector2D(stationCenter.x() - 1.0f, stationCenter.y()),
|
||||
/*isEnemy=*/false);
|
||||
@@ -259,7 +259,7 @@ TEST_CASE("CombatSystem: player ship fires at enemy station in range", "[combat]
|
||||
|
||||
entt::entity stationEntity = entt::null;
|
||||
QVector2D stationCenter;
|
||||
sim.admin().forEach<StationBodyComponent, FactionComponent>(
|
||||
sim.getAdmin().forEach<StationBodyComponent, FactionComponent>(
|
||||
[&](entt::entity e, const StationBodyComponent& sb, const FactionComponent& f)
|
||||
{
|
||||
if (f.isEnemy && stationEntity == entt::null)
|
||||
@@ -270,12 +270,12 @@ TEST_CASE("CombatSystem: player ship fires at enemy station in range", "[combat]
|
||||
sb.anchor.y() + sb.footprint.height() / 2.0f);
|
||||
}
|
||||
});
|
||||
REQUIRE(sim.admin().isValid(stationEntity));
|
||||
REQUIRE(sim.getAdmin().isValid(stationEntity));
|
||||
|
||||
const ShipDef* combatDef = findCombatShip(sim.config());
|
||||
const ShipDef* combatDef = findCombatShip(sim.getConfig());
|
||||
REQUIRE(combatDef != nullptr);
|
||||
|
||||
const entt::entity playerShip = sim.ships().spawn(
|
||||
const entt::entity playerShip = sim.getShips().spawn(
|
||||
combatDef->id,
|
||||
QVector2D(stationCenter.x() - 1.0f, stationCenter.y()),
|
||||
/*isEnemy=*/false);
|
||||
@@ -390,17 +390,17 @@ TEST_CASE("CombatSystem: dead ship is removed after tick step 9", "[combat]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
|
||||
const ShipDef* combatDef = findCombatShip(sim.config());
|
||||
const ShipDef* combatDef = findCombatShip(sim.getConfig());
|
||||
REQUIRE(combatDef != nullptr);
|
||||
|
||||
const entt::entity ship = sim.ships().spawn(combatDef->id,
|
||||
const entt::entity ship = sim.getShips().spawn(combatDef->id,
|
||||
QVector2D(10.0f, 10.0f));
|
||||
|
||||
sim.admin().get<HealthComponent>(ship).hp = -1.0f;
|
||||
sim.getAdmin().get<HealthComponent>(ship).hp = -1.0f;
|
||||
|
||||
sim.tick();
|
||||
|
||||
REQUIRE_FALSE(sim.admin().isValid(ship));
|
||||
REQUIRE_FALSE(sim.getAdmin().isValid(ship));
|
||||
}
|
||||
|
||||
TEST_CASE("CombatSystem: scrap is spawned on ship death", "[combat]")
|
||||
@@ -411,15 +411,15 @@ TEST_CASE("CombatSystem: scrap is spawned on ship death", "[combat]")
|
||||
// (REQ-RES-SCRAP-DROP): round(threat * scrap_per_threat). The interceptor's
|
||||
// threat is 59.0 and the test config sets scrap_per_threat = 1.0, so it drops
|
||||
// round(59.0 * 1.0) = 59 scrap.
|
||||
const entt::entity ship = sim.ships().spawn("interceptor",
|
||||
const entt::entity ship = sim.getShips().spawn("interceptor",
|
||||
QVector2D(10.0f, 10.0f));
|
||||
sim.admin().get<HealthComponent>(ship).hp = -1.0f;
|
||||
sim.getAdmin().get<HealthComponent>(ship).hp = -1.0f;
|
||||
|
||||
sim.tick();
|
||||
|
||||
const std::vector<ScrapInfo> scraps = sim.scraps().allScrapInfo();
|
||||
const std::vector<ScrapInfo> scraps = sim.getScraps().getAllScrapInfo();
|
||||
REQUIRE(scraps.size() == 1);
|
||||
CHECK(sim.admin().get<ScrapDataComponent>(scraps[0].entity).amount == 59);
|
||||
CHECK(sim.getAdmin().get<ScrapDataComponent>(scraps[0].entity).amount == 59);
|
||||
}
|
||||
|
||||
TEST_CASE("CombatSystem: HQ death sets game over", "[combat]")
|
||||
@@ -427,7 +427,7 @@ TEST_CASE("CombatSystem: HQ death sets game over", "[combat]")
|
||||
Simulation sim(loadConfig(), 42);
|
||||
|
||||
// Damage the HQ proxy entity (has HqProxy + Health).
|
||||
sim.admin().forEach<HqProxyComponent, HealthComponent>(
|
||||
sim.getAdmin().forEach<HqProxyComponent, HealthComponent>(
|
||||
[](entt::entity /*e*/, const HqProxyComponent& /*hq*/, HealthComponent& h)
|
||||
{
|
||||
h.hp = -1.0f;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "Rotation.h"
|
||||
#include "Simulation.h"
|
||||
#include "SimulationTestAccess.h"
|
||||
#include "Tick.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -52,28 +53,57 @@ TEST_CASE("apply(PlaceBuildingCommand) with recipe matches place-then-setRecipe"
|
||||
viaCommand.apply(command);
|
||||
|
||||
const BuildingId id =
|
||||
SimulationTestAccess::place(viaDirect, BuildingType::Miner, QPoint(-2, 0), Rotation::East);
|
||||
SimulationTestAccess::place(viaDirect, BuildingType::Miner, QPoint(-2, 0), Rotation::East).value();
|
||||
SimulationTestAccess::buildings(viaDirect).setRecipe(id, "mine_iron_ore");
|
||||
|
||||
REQUIRE(viaCommand.computeStateChecksum() == viaDirect.computeStateChecksum());
|
||||
}
|
||||
|
||||
TEST_CASE("apply(DemolishCommand) matches direct demolish", "[command]")
|
||||
TEST_CASE("apply(DeconstructCommand) matches direct deconstruct", "[command]")
|
||||
{
|
||||
Simulation viaCommand(loadConfig(), 99);
|
||||
Simulation viaDirect(loadConfig(), 99);
|
||||
|
||||
const BuildingId idA =
|
||||
SimulationTestAccess::place(viaCommand, BuildingType::Miner, QPoint(-3, 0), Rotation::East);
|
||||
SimulationTestAccess::place(viaCommand, BuildingType::Miner, QPoint(-3, 0), Rotation::East).value();
|
||||
const BuildingId idB =
|
||||
SimulationTestAccess::place(viaDirect, BuildingType::Miner, QPoint(-3, 0), Rotation::East);
|
||||
SimulationTestAccess::place(viaDirect, BuildingType::Miner, QPoint(-3, 0), Rotation::East).value();
|
||||
REQUIRE(idA == idB);
|
||||
|
||||
DemolishCommand command;
|
||||
DeconstructCommand command;
|
||||
command.id = idA;
|
||||
viaCommand.apply(command);
|
||||
|
||||
SimulationTestAccess::demolish(viaDirect, idB);
|
||||
SimulationTestAccess::deconstruct(viaDirect, idB);
|
||||
|
||||
REQUIRE(viaCommand.computeStateChecksum() == viaDirect.computeStateChecksum());
|
||||
}
|
||||
|
||||
TEST_CASE("apply(CancelDeconstructionCommand) matches direct cancelDeconstruction", "[command]")
|
||||
{
|
||||
Simulation viaCommand(loadConfig(), 99);
|
||||
Simulation viaDirect(loadConfig(), 99);
|
||||
|
||||
const BuildingId idA =
|
||||
SimulationTestAccess::place(viaCommand, BuildingType::Miner, QPoint(-3, 0), Rotation::East).value();
|
||||
const BuildingId idB =
|
||||
SimulationTestAccess::place(viaDirect, BuildingType::Miner, QPoint(-3, 0), Rotation::East).value();
|
||||
REQUIRE(idA == idB);
|
||||
|
||||
// Build the miners, then queue both for deconstruction identically.
|
||||
for (int i = 0; i < static_cast<int>(secondsToTicks(10.0)) + 1; ++i)
|
||||
{
|
||||
viaCommand.tick();
|
||||
viaDirect.tick();
|
||||
}
|
||||
SimulationTestAccess::deconstruct(viaCommand, idA);
|
||||
SimulationTestAccess::deconstruct(viaDirect, idB);
|
||||
|
||||
CancelDeconstructionCommand command;
|
||||
command.id = idA;
|
||||
viaCommand.apply(command);
|
||||
|
||||
SimulationTestAccess::cancelDeconstruction(viaDirect, idB);
|
||||
|
||||
REQUIRE(viaCommand.computeStateChecksum() == viaDirect.computeStateChecksum());
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "BuildingType.h"
|
||||
#include "ConfigLoader.h"
|
||||
#include "UnlocksConfig.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -88,6 +89,11 @@ TEST_CASE("ConfigLoader loads the committed bin/config/ configs end-to-end", "[c
|
||||
REQUIRE(*cfg.world.buildingBlocksTooltip ==
|
||||
"Spend building blocks to build; deliver them to the HQ to gain more.");
|
||||
|
||||
// Optional header artifact tooltip (REQ-UI-ARTIFACTS-TOOLTIP).
|
||||
REQUIRE(cfg.world.artifactTooltip.has_value());
|
||||
REQUIRE(*cfg.world.artifactTooltip ==
|
||||
"Choose the artifact reward when destroying enemy stations; collect enough to win.");
|
||||
|
||||
// Spot-check that a config-derived formula computes as expected.
|
||||
// threat_rate_formula = "x": evaluates to the input value.
|
||||
REQUIRE(cfg.world.waves.threatRateFormula.evaluate(1.0) == Approx(1.0));
|
||||
@@ -205,6 +211,7 @@ TEST_CASE("Missing field in world.toml is rejected with the field path", "[confi
|
||||
[world]
|
||||
height_tiles = 60
|
||||
refund_percentage = 75
|
||||
deconstruction_time_seconds = 0.1
|
||||
scrap_despawn_seconds = 30
|
||||
scrap_per_threat = 0.01
|
||||
tile_size_m = 10
|
||||
@@ -256,6 +263,7 @@ TEST_CASE("Malformed formula in world.toml is rejected with field identification
|
||||
[world]
|
||||
height_tiles = 60
|
||||
refund_percentage = 75
|
||||
deconstruction_time_seconds = 0.1
|
||||
scrap_despawn_seconds = 30
|
||||
scrap_per_threat = 0.01
|
||||
tile_size_m = 10
|
||||
@@ -308,6 +316,7 @@ TEST_CASE("Inverted wave gap range is rejected", "[config]")
|
||||
[world]
|
||||
height_tiles = 60
|
||||
refund_percentage = 75
|
||||
deconstruction_time_seconds = 0.1
|
||||
scrap_despawn_seconds = 30
|
||||
scrap_per_threat = 0.01
|
||||
tile_size_m = 10
|
||||
@@ -402,99 +411,42 @@ void copyConfigInto(const std::filesystem::path& dir)
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("unlock_requires parses into a ship def", "[config]")
|
||||
TEST_CASE("loadUnlocks parses id, station_level, requires, and grants", "[config]")
|
||||
{
|
||||
TempConfigDir dir;
|
||||
writeFile(dir.path() / "ships.toml", R"(
|
||||
[[ship]]
|
||||
id = "alpha"
|
||||
unlock_at_station_level = 1
|
||||
unlock_requires = ["beta", "gamma"]
|
||||
layout = ["O"]
|
||||
[ship.schematic]
|
||||
materials = []
|
||||
production_time_seconds = 5
|
||||
[ship.health]
|
||||
hp = 10
|
||||
[ship.movement]
|
||||
speed_mps = 1
|
||||
main_acceleration_mpss = 1
|
||||
maneuvering_acceleration_mpss = 1
|
||||
angular_acceleration_radpss = 1
|
||||
max_rotation_speed_radps = 1
|
||||
[ship.sensor]
|
||||
sensor_range_m = 10
|
||||
writeFile(dir.path() / "unlocks.toml", R"(
|
||||
[[unlock]]
|
||||
id = "base"
|
||||
station_level = 0
|
||||
buildings = ["salvage_bay"]
|
||||
|
||||
[[unlock]]
|
||||
id = "gated"
|
||||
station_level = 3
|
||||
requires = ["base"]
|
||||
ships = ["cruiser"]
|
||||
modules = ["railgun_m"]
|
||||
recipes = ["shortcut_steel_plate"]
|
||||
)");
|
||||
|
||||
const ShipsConfig cfg = ConfigLoader::loadShips((dir.path() / "ships.toml").string());
|
||||
REQUIRE(cfg.ships.size() == 1);
|
||||
CHECK(cfg.ships[0].unlockRequires == std::vector<std::string>{"beta", "gamma"});
|
||||
const UnlocksConfig cfg = ConfigLoader::loadUnlocks((dir.path() / "unlocks.toml").string());
|
||||
REQUIRE(cfg.groups.size() == 2);
|
||||
CHECK(cfg.groups[0].id == "base");
|
||||
CHECK(cfg.groups[0].stationLevel == 0);
|
||||
CHECK(cfg.groups[0].buildings == std::vector<std::string>{"salvage_bay"});
|
||||
CHECK(cfg.groups[1].requiredGroupIds == std::vector<std::string>{"base"});
|
||||
CHECK(cfg.groups[1].ships == std::vector<std::string>{"cruiser"});
|
||||
CHECK(cfg.groups[1].modules == std::vector<std::string>{"railgun_m"});
|
||||
CHECK(cfg.groups[1].recipes == std::vector<std::string>{"shortcut_steel_plate"});
|
||||
}
|
||||
|
||||
TEST_CASE("unlock_requires parses into a module def", "[config]")
|
||||
{
|
||||
TempConfigDir dir;
|
||||
writeFile(dir.path() / "modules.toml", R"(
|
||||
[[module]]
|
||||
id = "m1"
|
||||
unlock_at_station_level = 0
|
||||
unlock_requires = ["dep"]
|
||||
surface_mask = ["O"]
|
||||
materials = [{item = "iron_ingot", amount = 1}]
|
||||
production_time_seconds = 1
|
||||
fill_color = "#ffffff"
|
||||
glyph = "M"
|
||||
)");
|
||||
|
||||
const ModulesConfig cfg = ConfigLoader::loadModules((dir.path() / "modules.toml").string());
|
||||
REQUIRE(cfg.modules.size() == 1);
|
||||
CHECK(cfg.modules[0].unlockRequires == std::vector<std::string>{"dep"});
|
||||
}
|
||||
|
||||
TEST_CASE("unlock_requires parses only for assembler recipes", "[config]")
|
||||
{
|
||||
TempConfigDir dir;
|
||||
writeFile(dir.path() / "recipes.toml", R"(
|
||||
[[recipe]]
|
||||
id = "gated_asm"
|
||||
building = "assembler"
|
||||
unlock_at_station_level = 1
|
||||
unlock_requires = ["prereq_recipe"]
|
||||
inputs = []
|
||||
outputs = [{item = "foo", amount = 1}]
|
||||
duration_seconds = 1.0
|
||||
|
||||
[[recipe]]
|
||||
id = "a_miner"
|
||||
building = "miner"
|
||||
unlock_requires = ["ignored"]
|
||||
inputs = []
|
||||
outputs = [{item = "ore", amount = 1}]
|
||||
duration_seconds = 1.0
|
||||
)");
|
||||
|
||||
const RecipesConfig cfg = ConfigLoader::loadRecipes((dir.path() / "recipes.toml").string());
|
||||
REQUIRE(cfg.recipes.size() == 2);
|
||||
CHECK(cfg.recipes[0].unlockRequires == std::vector<std::string>{"prereq_recipe"});
|
||||
// The field is only consumed for assembler recipe schematics; a miner recipe
|
||||
// leaves it unparsed (empty).
|
||||
CHECK(cfg.recipes[1].unlockRequires.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("unlock_requires referencing an unknown schematic is rejected at load", "[config]")
|
||||
TEST_CASE("validateUnlocks rejects a grant that names no definition", "[config]")
|
||||
{
|
||||
TempConfigDir dir;
|
||||
copyConfigInto(dir.path());
|
||||
|
||||
std::ofstream out((dir.path() / "recipes.toml").string(), std::ios::app);
|
||||
out << "\n[[recipe]]\n"
|
||||
"id = \"gated_bogus\"\n"
|
||||
"building = \"assembler\"\n"
|
||||
"unlock_at_station_level = 1\n"
|
||||
"unlock_requires = [\"___does_not_exist___\"]\n"
|
||||
"inputs = []\n"
|
||||
"outputs = [{item = \"circuit_board\", amount = 1}]\n"
|
||||
"duration_seconds = 1.0\n";
|
||||
std::ofstream out((dir.path() / "unlocks.toml").string(), std::ios::app);
|
||||
out << "\n[[unlock]]\nid = \"bogus\"\nstation_level = 0\nships = [\"___nope___\"]\n";
|
||||
out.close();
|
||||
|
||||
try
|
||||
@@ -504,26 +456,103 @@ TEST_CASE("unlock_requires referencing an unknown schematic is rejected at load"
|
||||
}
|
||||
catch (const std::runtime_error& e)
|
||||
{
|
||||
const std::string msg = e.what();
|
||||
REQUIRE(msg.find("___does_not_exist___") != std::string::npos);
|
||||
REQUIRE(std::string(e.what()).find("___nope___") != std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("unlock_requires referencing a real schematic loads without error", "[config]")
|
||||
TEST_CASE("validateUnlocks rejects an id granted by two groups", "[config]")
|
||||
{
|
||||
TempConfigDir dir;
|
||||
copyConfigInto(dir.path());
|
||||
|
||||
// "interceptor" is a ship schematic in the test config — a valid prerequisite.
|
||||
std::ofstream out((dir.path() / "recipes.toml").string(), std::ios::app);
|
||||
out << "\n[[recipe]]\n"
|
||||
"id = \"gated_ok\"\n"
|
||||
"building = \"assembler\"\n"
|
||||
"unlock_at_station_level = 1\n"
|
||||
"unlock_requires = [\"interceptor\"]\n"
|
||||
"inputs = []\n"
|
||||
"outputs = [{item = \"circuit_board\", amount = 1}]\n"
|
||||
"duration_seconds = 1.0\n";
|
||||
// repair_ship is already granted by the test config's unlocks.toml.
|
||||
std::ofstream out((dir.path() / "unlocks.toml").string(), std::ios::app);
|
||||
out << "\n[[unlock]]\nid = \"dup\"\nstation_level = 0\nships = [\"repair_ship\"]\n";
|
||||
out.close();
|
||||
|
||||
try
|
||||
{
|
||||
ConfigLoader::loadFromDirectory(dir.path().string());
|
||||
FAIL("Expected exception");
|
||||
}
|
||||
catch (const std::runtime_error& e)
|
||||
{
|
||||
REQUIRE(std::string(e.what()).find("already granted") != std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("validateUnlocks rejects a non-assembler recipe grant", "[config]")
|
||||
{
|
||||
TempConfigDir dir;
|
||||
copyConfigInto(dir.path());
|
||||
|
||||
// mine_iron_ore is a miner recipe, not an assembler recipe.
|
||||
std::ofstream out((dir.path() / "unlocks.toml").string(), std::ios::app);
|
||||
out << "\n[[unlock]]\nid = \"badrecipe\"\nstation_level = 0\nrecipes = [\"mine_iron_ore\"]\n";
|
||||
out.close();
|
||||
|
||||
try
|
||||
{
|
||||
ConfigLoader::loadFromDirectory(dir.path().string());
|
||||
FAIL("Expected exception");
|
||||
}
|
||||
catch (const std::runtime_error& e)
|
||||
{
|
||||
REQUIRE(std::string(e.what()).find("mine_iron_ore") != std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("validateUnlocks rejects requires naming an unknown group", "[config]")
|
||||
{
|
||||
TempConfigDir dir;
|
||||
copyConfigInto(dir.path());
|
||||
|
||||
std::ofstream out((dir.path() / "unlocks.toml").string(), std::ios::app);
|
||||
out << "\n[[unlock]]\nid = \"needsmissing\"\nstation_level = 0\n"
|
||||
"requires = [\"___missing___\"]\nships = [\"interceptor\"]\n";
|
||||
out.close();
|
||||
|
||||
try
|
||||
{
|
||||
ConfigLoader::loadFromDirectory(dir.path().string());
|
||||
FAIL("Expected exception");
|
||||
}
|
||||
catch (const std::runtime_error& e)
|
||||
{
|
||||
REQUIRE(std::string(e.what()).find("___missing___") != std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("validateUnlocks rejects a group that grants nothing", "[config]")
|
||||
{
|
||||
TempConfigDir dir;
|
||||
copyConfigInto(dir.path());
|
||||
|
||||
std::ofstream out((dir.path() / "unlocks.toml").string(), std::ios::app);
|
||||
out << "\n[[unlock]]\nid = \"empty\"\nstation_level = 0\n";
|
||||
out.close();
|
||||
|
||||
try
|
||||
{
|
||||
ConfigLoader::loadFromDirectory(dir.path().string());
|
||||
FAIL("Expected exception");
|
||||
}
|
||||
catch (const std::runtime_error& e)
|
||||
{
|
||||
REQUIRE(std::string(e.what()).find("grants no items") != std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("validateUnlocks accepts a well-formed unlock group", "[config]")
|
||||
{
|
||||
TempConfigDir dir;
|
||||
copyConfigInto(dir.path());
|
||||
|
||||
// salvage_ship starts unlocked (not granted elsewhere); repair_ship is an
|
||||
// existing group id, so this new group is valid.
|
||||
std::ofstream out((dir.path() / "unlocks.toml").string(), std::ios::app);
|
||||
out << "\n[[unlock]]\nid = \"extra\"\nstation_level = 2\n"
|
||||
"requires = [\"repair_ship\"]\nships = [\"salvage_ship\"]\n";
|
||||
out.close();
|
||||
|
||||
REQUIRE_NOTHROW(ConfigLoader::loadFromDirectory(dir.path().string()));
|
||||
|
||||