Compare commits

...

3 Commits

Author SHA1 Message Date
ac97652c60 make ships claim targets 2026-06-16 21:18:28 +02:00
4153b7e2f5 make ships orbit their targets 2026-06-15 21:37:47 +02:00
6b7c3df64a advance towards enemy buildings 2026-06-15 20:52:43 +02:00
25 changed files with 617 additions and 56 deletions

View File

@@ -7,6 +7,8 @@ tile_size_m = 10
belt_speed_mps = 20 belt_speed_mps = 20
tunnel_max_distance_tiles = 10 tunnel_max_distance_tiles = 10
departure_interval_seconds = 20 departure_interval_seconds = 20
orbit_factor = 0.8
rally_orbit_radius_tiles = 5.0
[regions] [regions]
asteroid_width_tiles = 40 asteroid_width_tiles = 40
@@ -22,6 +24,11 @@ cost_building_blocks = 200
push_expand_columns_tiles = 10 push_expand_columns_tiles = 10
boss_advance_seconds = 60 boss_advance_seconds = 60
[targeting]
target_score_formula = "1 / (1 + x)" # x = distance / max weapon range; higher = better, clamped to >=0
overclaim_penalty_formula = "max(0.5, 1 - 0.1*x)" # x = competing claim count; multiplies score, clamped to [0,1]
target_hysteresis = 0.10 # keep current target unless a challenger beats it by >10%
[waves] [waves]
threat_rate_formula = "x" threat_rate_formula = "x"
ship_level_formula = "1" ship_level_formula = "1"

View File

@@ -7,6 +7,8 @@ tile_size_m = 10
belt_speed_mps = 20 belt_speed_mps = 20
tunnel_max_distance_tiles = 10 tunnel_max_distance_tiles = 10
departure_interval_seconds = 20 departure_interval_seconds = 20
orbit_factor = 0.8
rally_orbit_radius_tiles = 5.0
[regions] [regions]
asteroid_width_tiles = 40 asteroid_width_tiles = 40
@@ -22,6 +24,11 @@ cost_building_blocks = 200
push_expand_columns_tiles = 20 push_expand_columns_tiles = 20
boss_advance_seconds = 60 boss_advance_seconds = 60
[targeting]
target_score_formula = "1 / (1 + x)" # x = distance / max weapon range; higher = better, clamped to >=0
overclaim_penalty_formula = "max(0.5, 1 - 0.1*x)" # x = competing claim count; multiplies score, clamped to [0,1]
target_hysteresis = 0.10 # keep current target unless a challenger beats it by >10%
[waves] [waves]
threat_rate_formula = "x" threat_rate_formula = "x"
ship_level_formula = "1 + x / 10" ship_level_formula = "1 + x / 10"

View File

@@ -4,7 +4,7 @@
Config files use the TOML format. The following config files drive game parameters: 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, enemy ship level formula, belt speed, starting building blocks, departure interval. - **world.toml** — world dimensions, region widths, expansion amounts, building refund percentage, wave timing, boss wave timing, enemy ship level formula, belt speed, starting building blocks, departure interval, ship orbit factor, rally orbit radius, and combat target-selection parameters (target score formula, overclaim penalty formula, target hysteresis).
- **buildings.toml** — building block cost and construction time per building type. - **buildings.toml** — building block cost and construction time per building type.
- **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). - **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).
- **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 formulas of ship level, required build materials, player production level, 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), a layout grid defining the ship's module slots, a `scrap_drop` loot value, and a `default_modules` list used for enemy wave ships (see REQ-WAV-DEFAULT-MODULES). - **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 formulas of ship level, required build materials, player production level, 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), a layout grid defining the ship's module slots, a `scrap_drop` loot value, and a `default_modules` list used for enemy wave ships (see REQ-WAV-DEFAULT-MODULES).
@@ -153,25 +153,35 @@ Modules in `modules.toml` define a `surface_mask` — a list of strings that des
- REQ-SHP-SPAWN-PLAYER: A ship produced by a shipyard spawns centered on the shipyard's output port tile. - 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-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_formula`) is applied along the ship's current facing direction only. The maneuvering acceleration (`maneuvering_acceleration_formula`) can be applied in any direction independently of the facing direction, enabling lateral or braking movement without rotating. The angular acceleration (`angular_acceleration_formula`) controls how quickly the ship rotates. Linear speed is capped at the ship's `speed_formula` value; rotation rate is capped at the ship's `max_rotation_speed_formula` value. Ship position refers to the ship's center for all range, sensor, and attack checks. - 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_formula`) is applied along the ship's current facing direction only. The maneuvering acceleration (`maneuvering_acceleration_formula`) can be applied in any direction independently of the facing direction, enabling lateral or braking movement without rotating. The angular acceleration (`angular_acceleration_formula`) controls how quickly the ship rotates. Linear speed is capped at the ship's `speed_formula` value; rotation rate is capped at the ship's `max_rotation_speed_formula` value. Ship position refers to the ship's center for all range, sensor, and attack checks.
- REQ-SHP-ORBIT: Several behaviors keep a ship circling its target at a fixed standoff distance (an **orbit**) rather than approaching a fixed point. The orbit radius depends on the behavior:
- **Combat engagement** (REQ-SHP-COMBAT, REQ-SHP-ENEMY-AI): `world.toml [world].orbit_factor` multiplied by the maximum weapon `attack_range` across the ship's weapon module instances.
- **Repair** (REQ-SHP-REPAIR): `orbit_factor` multiplied by the maximum `repair_range` across the ship's repair module instances.
- **Salvage** (REQ-SHP-SALVAGE): `orbit_factor` multiplied by the maximum `collection_range` across the ship's salvage module instances.
- **Rally** (REQ-SHP-RALLY): `world.toml [world].rally_orbit_radius_tiles` — a fixed radius in tiles, independent of any tool range (the rally point is a position, not a tool-bearing target).
All tool ranges incorporate passive module modifiers (REQ-MOD-STAT-CALC). While orbiting, the ship navigates to maintain the orbit radius from the target's current center (REQ-SHP-MOVEMENT) while moving tangentially around it: if it is farther than the orbit radius it closes in, if it is nearer it backs off, and at the radius it circles. The orbit direction (clockwise or counter-clockwise) is fixed for the duration of orbiting a given target. Orbiting uses the standard physics movement model (REQ-SHP-MOVEMENT) and introduces no new movement constraints. Orbiting does not by itself trigger tool use — weapons, repair tools, and salvage bays still fire/heal/collect strictly per their own range and rate checks (REQ-SHP-FIRING, REQ-SHP-REPAIR, REQ-SHP-SALVAGE). With `orbit_factor` ≤ 1 the orbit lies within the maximum tool range, so the longest-range tool of that type remains in range while the ship orbits.
- REQ-SHP-NO-COLLISION: Ships do not collide with each other or with defence stations; they may visually overlap. - REQ-SHP-NO-COLLISION: Ships do not collide with each other or with defence stations; they may visually overlap.
- REQ-SHP-SENSOR: A ship perceives only entities within its sensor range. Behavior is driven by what is in sensor range; entities outside sensor range are ignored. - REQ-SHP-SENSOR: A ship perceives only entities within its sensor range. Behavior is driven by what is in sensor range; entities outside sensor range are ignored.
- REQ-SHP-FIRING: All weapons — on ships and on defence stations — fire when off cooldown and the target is within attack range. Firing emits a fire event and starts a 0.15-second damage delay (half the beam duration). When that delay expires, damage is applied to the target — unless the target has already been destroyed, in which case the damage is silently dropped. If the shooter is destroyed before the delay expires, damage is still applied when the delay expires. There is no projectile entity and no intervening collision. The weapon's cooldown begins at the moment of firing, not at damage application. - REQ-SHP-FIRING: All weapons — on ships and on defence stations — fire when off cooldown and the target is within attack range. Firing emits a fire event and starts a 0.15-second damage delay (half the beam duration). When that delay expires, damage is applied to the target — unless the target has already been destroyed, in which case the damage is silently dropped. If the shooter is destroyed before the delay expires, damage is still applied when the delay expires. There is no projectile entity and no intervening collision. The weapon's cooldown begins at the moment of firing, not at damage application.
- REQ-SHP-FIRING-BEAM: Each fire event produces a visual laser beam drawn from the shooter's position to the target for 0.3 seconds. The beam endpoint is not the target's center but a point randomly offset from it: the offset direction is uniformly random and the offset magnitude is uniformly random up to half the target's visual size (for ships: half their rendered radius; for buildings/stations: half the shorter side of their tile footprint, in world units). The offset is chosen once per fire event and held fixed for the beam's lifetime. The beam is a pure rendering effect and has no simulation state (does not block movement, does not re-apply damage over its lifetime). Beams follow the shooter and target positions if either moves during the 0.3-second window. The beam is rendered for its full 0.3-second duration even if the shooter or target is destroyed before it expires. - REQ-SHP-FIRING-BEAM: Each fire event produces a visual laser beam drawn from the shooter's position to the target for 0.3 seconds. The beam endpoint is not the target's center but a point randomly offset from it: the offset direction is uniformly random and the offset magnitude is uniformly random up to half the target's visual size (for ships: half their rendered radius; for buildings/stations: half the shorter side of their tile footprint, in world units). The offset is chosen once per fire event and held fixed for the beam's lifetime. The beam is a pure rendering effect and has no simulation state (does not block movement, does not re-apply damage over its lifetime). Beams follow the shooter and target positions if either moves during the 0.3-second window. The beam is rendered for its full 0.3-second duration even if the shooter or target is destroyed before it expires.
- REQ-SHP-COMBAT: Ships with at least one **weapon module** (player) — engage enemy ships within sensor range. The player can configure the following per shipyard (applied to all ships produced by that shipyard): - REQ-SHP-COMBAT: Ships with at least one **weapon module** (player) — engage enemy ships within sensor range. When engaging an enemy, the ship orbits it at the combat orbit radius (REQ-SHP-ORBIT) rather than approaching its center. The player can configure the following per shipyard (applied to all ships produced by that shipyard):
- Stance: aggressive (advance toward enemies) / defensive (hold position near asteroid). - Stance: aggressive (advance toward enemies) / defensive (hold position near asteroid).
- Target priority: closest / highest HP / structures first. - Target priority: closest / highest HP / structures first.
- REQ-SHP-RALLY: After spawning, aggressive-stance ships with weapon modules move to and loiter at the **rally point** — the midpoint between the two player defence stations (center of their Y-span, at the player defence stations' X position). While at the rally point, ships still engage any enemy that enters sensor range. Every `world.toml [world].departure_interval_seconds` seconds (default 20), all ships with weapon modules currently at the rally point depart simultaneously and begin their normal aggressive advance toward the enemy. The departure timer is global and shared across all shipyards; it is not reset by individual ship arrivals at the rally point. - REQ-SHP-RALLY: After spawning, aggressive-stance ships with weapon modules move to and orbit the **rally point** — the midpoint between the two player defence stations (center of their Y-span, at the player defence stations' X position) — at the rally orbit radius (REQ-SHP-ORBIT). While orbiting the rally point, ships still engage any enemy that enters sensor range (switching to the combat orbit per REQ-SHP-COMBAT). Every `world.toml [world].departure_interval_seconds` seconds (default 20), all ships with weapon modules currently at the rally point depart simultaneously and begin their normal aggressive advance toward the enemy. The departure timer is global and shared across all shipyards; it is not reset by individual ship arrivals at the rally point.
- REQ-SHP-SALVAGE: Ships with at least one **salvage module** (player) — patrol by moving forward (rightward, away from the asteroid) while searching sensor range. If scrap enters sensor range, move to it; when it is within a module's `collection_range`, that module collects it (consuming the scrap entity). Once all cargo is full, fly to a Salvage Bay and deliver; after delivery, resume patrol. If an enemy ship enters sensor range, the ship retreats (REQ-SHP-RETREAT) until no enemy is in sensor range, then resumes patrol — this applies regardless of whether the ship is targeting or carrying scrap. Ships with salvage modules are vulnerable to enemy ships while operating. - REQ-SHP-SALVAGE: Ships with at least one **salvage module** (player) — patrol by moving forward (rightward, away from the asteroid) while searching sensor range. If scrap enters sensor range, navigate toward it by orbiting it at the salvage orbit radius (REQ-SHP-ORBIT); when it is within a module's `collection_range`, that module collects it (consuming the scrap entity). Once all cargo is full, fly to a Salvage Bay and deliver (a direct approach, not an orbit — the ship must reach the bay); after delivery, resume patrol. If an enemy ship enters sensor range, the ship retreats (REQ-SHP-RETREAT) until no enemy is in sensor range, then resumes patrol — this applies regardless of whether the ship is targeting or carrying scrap. Ships with salvage modules are vulnerable to enemy ships while operating.
Each salvage module instance operates independently: it has its own cargo hold (`cargo_capacity`), collection range (`collection_range`), and collection rate (`collection_rate`, in collections per second). After collecting a piece of scrap, the module cannot collect again until `1 / collection_rate` seconds have elapsed. A ship with multiple salvage modules can therefore collect multiple pieces of scrap per tick (one per ready module), and installs of different module types may have different ranges and rates. The ship navigates based on the maximum collection range across all installed salvage modules. Each salvage module instance operates independently: it has its own cargo hold (`cargo_capacity`), collection range (`collection_range`), and collection rate (`collection_rate`, in collections per second). After collecting a piece of scrap, the module cannot collect again until `1 / collection_rate` seconds have elapsed. A ship with multiple salvage modules can therefore collect multiple pieces of scrap per tick (one per ready module), and installs of different module types may have different ranges and rates. The ship navigates based on the maximum collection range across all installed salvage modules.
Salvage collection and delivery are world-state changes performed every tick regardless of which behavior the ship is currently executing; the salvage behavior only governs where the ship navigates (toward scrap, toward a Salvage Bay, or — when retreating — toward the rally point). Salvage collection and delivery are world-state changes performed every tick regardless of which behavior the ship is currently executing; the salvage behavior only governs where the ship navigates (toward scrap, toward a Salvage Bay, or — when retreating — toward the rally point).
- REQ-SHP-REPAIR: Ships with at least one **repair module** (player) — patrol by moving forward (rightward, away from the asteroid) while searching sensor range. If a damaged player defence station or player ship enters sensor range, move to it and repair. If an enemy ship enters sensor range, the ship retreats (REQ-SHP-RETREAT) until no enemy is in sensor range, then resumes patrol. The player can configure the target priority per shipyard: - REQ-SHP-REPAIR: Ships with at least one **repair module** (player) — patrol by moving forward (rightward, away from the asteroid) while searching sensor range. If a damaged player defence station or player ship enters sensor range, navigate toward it by orbiting it at the repair orbit radius (REQ-SHP-ORBIT) and repair. If an enemy ship enters sensor range, the ship retreats (REQ-SHP-RETREAT) until no enemy is in sensor range, then resumes patrol. The player can configure the target priority per shipyard:
- Defence stations first / ships first / nearest target. - Defence stations first / ships first / nearest target.
Each repair module instance operates independently: it has its own repair rate (`repair_rate`) and repair range (`repair_range`). On each tick, a module first attempts to heal the ship's current behavior-level navigation target if that target is within the module's `repair_range` and is damaged (HP above zero and below maximum HP). If those conditions are not met — because the target is out of the module's `repair_range`, already at full health, or destroyed — the module independently searches for the nearest damaged friendly (player ship or player defence station) within its own `repair_range` and heals that instead. If no valid target is found within range, the module idles. A ship with multiple repair modules can therefore heal different targets simultaneously. Navigation is driven solely by the behavior-level target; individual module fallback targets do not affect which direction the ship moves. Repair healing is a world-state change applied every tick regardless of which behavior the ship is currently executing. Each repair module instance operates independently: it has its own repair rate (`repair_rate`) and repair range (`repair_range`). On each tick, a module first attempts to heal the ship's current behavior-level navigation target if that target is within the module's `repair_range` and is damaged (HP above zero and below maximum HP). If those conditions are not met — because the target is out of the module's `repair_range`, already at full health, or destroyed — the module independently searches for the nearest damaged friendly (player ship or player defence station) within its own `repair_range` and heals that instead. If no valid target is found within range, the module idles. A ship with multiple repair modules can therefore heal different targets simultaneously. Navigation is driven solely by the behavior-level target; individual module fallback targets do not affect which direction the ship moves. Repair healing is a world-state change applied every tick regardless of which behavior the ship is currently executing.
- REQ-SHP-RETREAT: **Player ships retreat to the rally point (REQ-SHP-RALLY) when threatened.** A ship retreats while either condition holds: (a) its HP is below a low-HP threshold (currently 30% of its maximum HP); or (b) it has no weapon modules and an enemy ship is within its sensor range. Retreating takes priority over the ship's other behaviors and moves it toward the rally point; the ship resumes its normal behavior once neither condition holds. Enemy ships never retreat (REQ-SHP-ENEMY-AI). - REQ-SHP-RETREAT: **Player ships retreat to the rally point (REQ-SHP-RALLY) when threatened.** A ship retreats while either condition holds: (a) its HP is below a low-HP threshold (currently 30% of its maximum HP); or (b) it has no weapon modules and an enemy ship is within its sensor range. Retreating takes priority over the ship's other behaviors and moves it toward the rally point; the ship resumes its normal behavior once neither condition holds. Enemy ships never retreat (REQ-SHP-ENEMY-AI).
- REQ-SHP-ENEMY-AI: **Enemy ships** — engage the closest valid target (player defence station, HQ, or player ship) within their sensor range. If no target is in sensor range, they move toward the asteroid (leftward in world coordinates). - REQ-SHP-ENEMY-AI: **Enemy ships** — engage the closest valid target (player defence station, HQ, or player ship) within their sensor range, orbiting the engaged target at the combat orbit radius (REQ-SHP-ORBIT). If no target is in sensor range, they move toward the asteroid (leftward in world coordinates).
- REQ-SHP-TARGET-SELECT: **Combat target selection.** Both player combat ships (REQ-SHP-COMBAT) and enemy ships (REQ-SHP-ENEMY-AI) pick which hostile to engage by scoring every valid target (an opposing-faction ship, defence station, or HQ) within sensor range and engaging the highest-scoring one. A target's score is the product of a **base desirability** and an **overclaim penalty** (REQ-SHP-TARGET-CLAIM). The base desirability is `world.toml [targeting].target_score_formula` evaluated with `x` set to the target's distance from the ship divided by the ship's maximum weapon `attack_range` (falling back to sensor range for a ship with no weapon), clamped to a minimum of 0. The default formula `1 / (1 + x)` decreases with distance, so — absent any claims — the nearest target is chosen, realizing the closest-target priority referenced by REQ-SHP-COMBAT and REQ-SHP-ENEMY-AI. A ship engages at most one target at a time; all of its weapons fire on that target subject to their own range and rate checks (REQ-SHP-FIRING).
- REQ-SHP-TARGET-CLAIM: **Overclaim penalty.** To stop every ship from dogpiling the same hostile, each target a ship is currently engaging counts as a **claim** on that target. When scoring a candidate, its base desirability (REQ-SHP-TARGET-SELECT) is multiplied by `world.toml [targeting].overclaim_penalty_formula` evaluated with `x` set to the number of ships currently claiming that candidate — a ship never counts its own claim against the target it already holds — clamped to the range [0, 1]. The penalty is 1 (no reduction) at zero claims and decreases as claims accumulate, so heavily-claimed targets become less attractive and ships spread across the available hostiles. The default formula `max(0.5, 1 - 0.1*x)` reduces desirability by 0.1 per claim down to a floor of 0.5. Because claims reflect the previous tick's engagements, target distribution converges over successive ticks rather than instantaneously.
- REQ-SHP-TARGET-HYSTERESIS: **Target stickiness.** A ship keeps engaging its current target as long as that target remains valid and within sensor range, switching to a different target only when the best alternative's score exceeds the current target's score by more than the fractional margin `world.toml [targeting].target_hysteresis` (default 0.10). This prevents ships from rapidly oscillating between targets of near-equal score and preserves focus fire.
- REQ-SHP-SCHEMATICS: The player selects a schematic per shipyard by clicking it. New schematics are unlocked by destroying enemy defence station sets (REQ-DEF-SCHEMATIC-DROP) — there is no physical loot to collect. - REQ-SHP-SCHEMATICS: The player selects a schematic per shipyard by clicking it. New schematics are unlocked by destroying enemy defence station sets (REQ-DEF-SCHEMATIC-DROP) — there is no physical loot to collect.
## Ship Modules ## Ship Modules

View File

@@ -56,7 +56,7 @@ ArenaSimulation::ArenaSimulation(const GameConfig& gameConfig,
// Arena fights are symmetric and aggressive: player-faction ships must not // Arena fights are symmetric and aggressive: player-faction ships must not
// retreat (REQ-BAL-SIM-AI). Only one faction would otherwise get retreat. // retreat (REQ-BAL-SIM-AI). Only one faction would otherwise get retreat.
m_shipSystem->setRetreatEnabled(false); m_shipSystem->setRetreatEnabled(false);
m_aiSystem = std::make_unique<AiSystem>(); m_aiSystem = std::make_unique<AiSystem>(m_gameConfig);
m_movementIntentSystem = std::make_unique<MovementIntentSystem>(); m_movementIntentSystem = std::make_unique<MovementIntentSystem>();
m_dynamicBodySystem = std::make_unique<DynamicBodySystem>(); m_dynamicBodySystem = std::make_unique<DynamicBodySystem>();
m_combatSystem = std::make_unique<CombatSystem>(m_gameConfig); m_combatSystem = std::make_unique<CombatSystem>(m_gameConfig);

View File

@@ -268,6 +268,8 @@ WorldConfig ConfigLoader::loadWorld(const std::string& path)
cfg.beltSpeed_tps = requireDouble(tbl["world"]["belt_speed_mps"], file, "world.belt_speed_mps") / cfg.tileSize_m; cfg.beltSpeed_tps = requireDouble(tbl["world"]["belt_speed_mps"], file, "world.belt_speed_mps") / cfg.tileSize_m;
cfg.tunnelMaxDistance_tiles = static_cast<int>(requireInt(tbl["world"]["tunnel_max_distance_tiles"], file, "world.tunnel_max_distance_tiles")); cfg.tunnelMaxDistance_tiles = static_cast<int>(requireInt(tbl["world"]["tunnel_max_distance_tiles"], file, "world.tunnel_max_distance_tiles"));
cfg.departureIntervalSeconds = requireDouble(tbl["world"]["departure_interval_seconds"], file, "world.departure_interval_seconds"); cfg.departureIntervalSeconds = requireDouble(tbl["world"]["departure_interval_seconds"], file, "world.departure_interval_seconds");
cfg.orbitFactor = requireDouble(tbl["world"]["orbit_factor"], file, "world.orbit_factor");
cfg.rallyOrbitRadius_tiles = requireDouble(tbl["world"]["rally_orbit_radius_tiles"], file, "world.rally_orbit_radius_tiles");
cfg.regions.asteroidWidth_tiles = static_cast<int>(requireInt(tbl["regions"]["asteroid_width_tiles"], file, "regions.asteroid_width_tiles")); 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.playerBufferWidth_tiles = static_cast<int>(requireInt(tbl["regions"]["player_buffer_width_tiles"], file, "regions.player_buffer_width_tiles"));
@@ -295,6 +297,10 @@ WorldConfig ConfigLoader::loadWorld(const std::string& path)
throw makeError(file, "waves", "gap_min_seconds > gap_max_seconds"); throw makeError(file, "waves", "gap_min_seconds > gap_max_seconds");
} }
cfg.targeting.targetScoreFormula = requireFormula(tbl["targeting"]["target_score_formula"], file, "targeting.target_score_formula");
cfg.targeting.overclaimPenaltyFormula = requireFormula(tbl["targeting"]["overclaim_penalty_formula"], file, "targeting.overclaim_penalty_formula");
cfg.targeting.hysteresis = requireDouble(tbl["targeting"]["target_hysteresis"], file, "targeting.target_hysteresis");
return cfg; return cfg;
} }

View File

@@ -4,6 +4,14 @@
#include "tinyexpr.h" #include "tinyexpr.h"
namespace
{
// tinyexpr has no built-in min/max; expose them so config formulas can
// clamp (e.g. a floored overclaim penalty "max(0.5, 1 - 0.1*x)").
double formulaMin(double a, double b) { return a < b ? a : b; }
double formulaMax(double a, double b) { return a > b ? a : b; }
}
Formula::Formula(Formula&& other) noexcept Formula::Formula(Formula&& other) noexcept
: m_source(std::move(other.m_source)) : m_source(std::move(other.m_source))
, m_x(std::move(other.m_x)) , m_x(std::move(other.m_x))
@@ -37,11 +45,14 @@ Formula Formula::compile(const std::string& source)
result.m_x = std::make_unique<double>(0.0); result.m_x = std::make_unique<double>(0.0);
const te_variable variables[] = { const te_variable variables[] = {
{ "x", result.m_x.get(), 0, nullptr }, { "x", result.m_x.get(), TE_VARIABLE, nullptr },
{ "min", reinterpret_cast<const void*>(&formulaMin), TE_FUNCTION2 | TE_FLAG_PURE, nullptr },
{ "max", reinterpret_cast<const void*>(&formulaMax), TE_FUNCTION2 | TE_FLAG_PURE, nullptr },
}; };
int errorPos = 0; int errorPos = 0;
result.m_expr = te_compile(result.m_source.c_str(), variables, 1, &errorPos); const int variableCount = static_cast<int>(sizeof(variables) / sizeof(variables[0]));
result.m_expr = te_compile(result.m_source.c_str(), variables, variableCount, &errorPos);
if (result.m_expr == nullptr) if (result.m_expr == nullptr)
{ {
@@ -66,3 +77,4 @@ double Formula::evaluate(double x) const
*m_x = x; *m_x = x;
return te_eval(m_expr); return te_eval(m_expr);
} }

View File

@@ -39,6 +39,14 @@ struct WorldWaves
double bossQuietAfterSeconds; // suppress normal waves this long after boss (REQ-WAV-QUIET) double bossQuietAfterSeconds; // suppress normal waves this long after boss (REQ-WAV-QUIET)
}; };
// Ship target selection (claim-aware scoring).
struct WorldTargeting
{
Formula targetScoreFormula; // x = distance / max weapon range; higher = better
Formula overclaimPenaltyFormula; // x = competing claim count; factor in [0,1]
double hysteresis; // fractional margin a challenger must beat the current target by
};
struct WorldConfig struct WorldConfig
{ {
int heightTiles; // REQ-GW-HEIGHT int heightTiles; // REQ-GW-HEIGHT
@@ -49,9 +57,12 @@ struct WorldConfig
double beltSpeed_tps; // REQ-GW-BELT-SPEED (tiles/s, converted from m/s in config) double beltSpeed_tps; // REQ-GW-BELT-SPEED (tiles/s, converted from m/s in config)
int tunnelMaxDistance_tiles; // REQ-BLD-TUNNEL-PAIR int tunnelMaxDistance_tiles; // REQ-BLD-TUNNEL-PAIR
double departureIntervalSeconds; // REQ-SHP-RALLY double departureIntervalSeconds; // REQ-SHP-RALLY
double orbitFactor; // REQ-SHP-ORBIT (multiplies tool range for orbit radius)
double rallyOrbitRadius_tiles; // REQ-SHP-ORBIT (fixed orbit radius around the rally point)
WorldRegions regions; WorldRegions regions;
WorldExpansion expansion; WorldExpansion expansion;
WorldPush push; WorldPush push;
WorldWaves waves; WorldWaves waves;
WorldTargeting targeting;
}; };

View File

@@ -9,5 +9,6 @@
struct AttackBehavior struct AttackBehavior
{ {
std::optional<entt::entity> currentTarget; std::optional<entt::entity> currentTarget;
float orbitRadius_tiles = 0.0f; // REQ-SHP-ORBIT
float score = 0.0f; float score = 0.0f;
}; };

View File

@@ -7,5 +7,6 @@
struct RallyBehavior struct RallyBehavior
{ {
QVector2D rallyPoint; QVector2D rallyPoint;
float orbitRadius_tiles = 0.0f; // REQ-SHP-ORBIT
float score = 0.0f; float score = 0.0f;
}; };

View File

@@ -11,5 +11,6 @@ struct RepairBehavior
{ {
std::optional<entt::entity> currentTarget; std::optional<entt::entity> currentTarget;
float maxRepairRange_tiles = 0.0f; float maxRepairRange_tiles = 0.0f;
float orbitRadius_tiles = 0.0f; // REQ-SHP-ORBIT
float score = 0.0f; float score = 0.0f;
}; };

View File

@@ -10,5 +10,6 @@ struct SalvageScrapBehavior
{ {
std::optional<QVector2D> scrapTarget; std::optional<QVector2D> scrapTarget;
float maxCollectionRange_tiles = 0.0f; float maxCollectionRange_tiles = 0.0f;
float orbitRadius_tiles = 0.0f; // REQ-SHP-ORBIT
float score = 0.0f; float score = 0.0f;
}; };

View File

@@ -2,6 +2,8 @@
#include <limits> #include <limits>
#include "GameConfig.h"
#include "AdvanceBehavior.h" #include "AdvanceBehavior.h"
#include "AttackBehavior.h" #include "AttackBehavior.h"
#include "BehaviorKind.h" #include "BehaviorKind.h"
@@ -34,6 +36,11 @@ namespace
} }
} }
AiSystem::AiSystem(const GameConfig& config)
: m_attackEvaluator(config.world.targeting)
{
}
void AiSystem::tick(EntityAdmin& admin, const BuildingSystem& buildings, void AiSystem::tick(EntityAdmin& admin, const BuildingSystem& buildings,
const ScrapSystem& scraps) const ScrapSystem& scraps)
{ {

View File

@@ -18,6 +18,7 @@
class BuildingSystem; class BuildingSystem;
class EntityAdmin; class EntityAdmin;
class ScrapSystem; class ScrapSystem;
struct GameConfig;
// Orchestrates ship-behavior decision-making in three batched phases: // Orchestrates ship-behavior decision-making in three batched phases:
// 1. evaluators score each behavior and set its target data, // 1. evaluators score each behavior and set its target data,
@@ -29,6 +30,8 @@ class ScrapSystem;
class AiSystem class AiSystem
{ {
public: public:
explicit AiSystem(const GameConfig& config);
void tick(EntityAdmin& admin, const BuildingSystem& buildings, const ScrapSystem& scraps); void tick(EntityAdmin& admin, const BuildingSystem& buildings, const ScrapSystem& scraps);
private: private:

View File

@@ -343,12 +343,24 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level,
if (!weaponChildren.empty()) if (!weaponChildren.empty())
{ {
m_admin.addComponent<AttackBehavior>(entity, AttackBehavior{}); float maxWeaponRange = 0.0f;
for (entt::entity child : weaponChildren)
{
const float r = m_admin.get<WeaponComponent>(child).range_tiles;
if (r > maxWeaponRange) { maxWeaponRange = r; }
}
AttackBehavior attack;
attack.orbitRadius_tiles =
maxWeaponRange * static_cast<float>(m_config.world.orbitFactor);
m_admin.addComponent<AttackBehavior>(entity, attack);
if (!isEnemy) if (!isEnemy)
{ {
RallyBehavior rally; RallyBehavior rally;
rally.rallyPoint = m_rallyPoint; rally.rallyPoint = m_rallyPoint;
rally.orbitRadius_tiles =
static_cast<float>(m_config.world.rallyOrbitRadius_tiles);
m_admin.addComponent<RallyBehavior>(entity, rally); m_admin.addComponent<RallyBehavior>(entity, rally);
} }
} }
@@ -365,6 +377,8 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level,
SalvageScrapBehavior salvage; SalvageScrapBehavior salvage;
salvage.scrapTarget = std::nullopt; salvage.scrapTarget = std::nullopt;
salvage.maxCollectionRange_tiles = maxCollRange; salvage.maxCollectionRange_tiles = maxCollRange;
salvage.orbitRadius_tiles =
maxCollRange * static_cast<float>(m_config.world.orbitFactor);
m_admin.addComponent<SalvageScrapBehavior>(entity, salvage); m_admin.addComponent<SalvageScrapBehavior>(entity, salvage);
DeliverScrapBehavior deliver; DeliverScrapBehavior deliver;
@@ -384,6 +398,8 @@ entt::entity ShipSystem::spawn(const std::string& schematicId, int level,
RepairBehavior repair; RepairBehavior repair;
repair.currentTarget = std::nullopt; repair.currentTarget = std::nullopt;
repair.maxRepairRange_tiles = maxRepairRange; repair.maxRepairRange_tiles = maxRepairRange;
repair.orbitRadius_tiles =
maxRepairRange * static_cast<float>(m_config.world.orbitFactor);
m_admin.addComponent<RepairBehavior>(entity, repair); m_admin.addComponent<RepairBehavior>(entity, repair);
} }

View File

@@ -1,30 +1,112 @@
#include "AdvanceExecutor.h" #include "AdvanceExecutor.h"
#include <optional>
#include <QVector2D> #include <QVector2D>
#include "AdvanceBehavior.h" #include "AdvanceBehavior.h"
#include "BehaviorKind.h" #include "BehaviorKind.h"
#include "EntityAdmin.h" #include "EntityAdmin.h"
#include "FactionComponent.h" #include "FactionComponent.h"
#include "HealthComponent.h"
#include "HqProxyComponent.h"
#include "MovementIntentComponent.h" #include "MovementIntentComponent.h"
#include "PositionComponent.h" #include "PositionComponent.h"
#include "SelectedBehaviorComponent.h" #include "SelectedBehaviorComponent.h"
#include "StationBodyComponent.h"
#include "tracing.h" #include "tracing.h"
namespace
{
// Accumulates positions to produce their centroid (the center between them).
struct Centroid
{
QVector2D sum;
int count = 0;
void add(const QVector2D& point)
{
sum += point;
count += 1;
}
std::optional<QVector2D> value() const
{
if (count == 0) { return std::nullopt; }
return sum / static_cast<float>(count);
}
};
}
void AdvanceExecutor::execute(EntityAdmin& admin) void AdvanceExecutor::execute(EntityAdmin& admin)
{ {
TRACE(); TRACE();
// Centroid of each faction's alive defence stations. In the arena the HQ is
// spawned as a station, so it is part of this centroid; in the main game the
// enemy side has only its defence stations.
Centroid enemyStations;
Centroid playerStations;
admin.forEach<StationBodyComponent, PositionComponent, FactionComponent, HealthComponent>(
[&enemyStations, &playerStations](entt::entity /*e*/,
const StationBodyComponent& /*sb*/, const PositionComponent& pos,
const FactionComponent& faction, const HealthComponent& health)
{
if (health.hp <= 0.0f) { return; }
Centroid& centroid = faction.isEnemy ? enemyStations : playerStations;
centroid.add(pos.value);
});
// Fallback target per faction: the HQ proxy (main game only), used when a side
// has lost all of its defence stations.
Centroid enemyHq;
Centroid playerHq;
admin.forEach<HqProxyComponent, PositionComponent, FactionComponent, HealthComponent>(
[&enemyHq, &playerHq](entt::entity /*e*/, const HqProxyComponent& /*hq*/,
const PositionComponent& pos, const FactionComponent& faction,
const HealthComponent& health)
{
if (health.hp <= 0.0f) { return; }
Centroid& centroid = faction.isEnemy ? enemyHq : playerHq;
centroid.add(pos.value);
});
const std::optional<QVector2D> enemyStationCenter = enemyStations.value();
const std::optional<QVector2D> playerStationCenter = playerStations.value();
const std::optional<QVector2D> enemyHqCenter = enemyHq.value();
const std::optional<QVector2D> playerHqCenter = playerHq.value();
admin.forEach<AdvanceBehavior, SelectedBehaviorComponent, PositionComponent, admin.forEach<AdvanceBehavior, SelectedBehaviorComponent, PositionComponent,
FactionComponent, MovementIntentComponent>( FactionComponent, MovementIntentComponent>(
[](entt::entity /*e*/, const AdvanceBehavior& /*advance*/, [&](entt::entity /*e*/, const AdvanceBehavior& /*advance*/,
const SelectedBehaviorComponent& selected, const PositionComponent& pos, const SelectedBehaviorComponent& selected, const PositionComponent& pos,
const FactionComponent& faction, MovementIntentComponent& intent) const FactionComponent& faction, MovementIntentComponent& intent)
{ {
if (selected.winner != BehaviorKind::Advance) { return; } if (selected.winner != BehaviorKind::Advance) { return; }
const QVector2D target = faction.isEnemy // Aim at the center between the opposing side's defence stations; fall
? QVector2D(-10000.0f, pos.value.y()) // back to the opposing HQ, then to an off-world point in the advance
: QVector2D(pos.value.x() + 1000.0f, pos.value.y()); // direction so the ship keeps moving when no target structure exists.
const std::optional<QVector2D>& stationCenter =
faction.isEnemy ? playerStationCenter : enemyStationCenter;
const std::optional<QVector2D>& hqCenter =
faction.isEnemy ? playerHqCenter : enemyHqCenter;
QVector2D target;
if (stationCenter)
{
target = *stationCenter;
}
else if (hqCenter)
{
target = *hqCenter;
}
else
{
target = faction.isEnemy
? QVector2D(-10000.0f, pos.value.y())
: QVector2D(pos.value.x() + 1000.0f, pos.value.y());
}
intent = MovementIntentComponent{true, target}; intent = MovementIntentComponent{true, target};
}); });
} }

View File

@@ -1,5 +1,7 @@
#include "AttackEvaluator.h" #include "AttackEvaluator.h"
#include <algorithm>
#include <unordered_map>
#include <vector> #include <vector>
#include <QVector2D> #include <QVector2D>
@@ -10,57 +12,131 @@
#include "EntityAdmin.h" #include "EntityAdmin.h"
#include "FactionComponent.h" #include "FactionComponent.h"
#include "HealthComponent.h" #include "HealthComponent.h"
#include "ModuleOwnerComponent.h"
#include "PositionComponent.h" #include "PositionComponent.h"
#include "SensorRangeComponent.h" #include "SensorRangeComponent.h"
#include "tracing.h" #include "tracing.h"
#include "WeaponComponent.h"
#include "WorldConfig.h"
AttackEvaluator::AttackEvaluator(const WorldTargeting& targeting)
: m_targeting(&targeting)
{
}
void AttackEvaluator::evaluate(EntityAdmin& admin) void AttackEvaluator::evaluate(EntityAdmin& admin)
{ {
TRACE(); TRACE();
const std::vector<CombatantInfo> combatants = buildCombatants(admin); const std::vector<CombatantInfo> combatants = buildCombatants(admin);
// Pass A: the maximum weapon range per ship, used to normalise target
// distance. Ships without a weapon fall back to their sensor range below.
std::unordered_map<entt::entity, float> maxWeaponRange_tiles;
admin.forEach<WeaponComponent, ModuleOwnerComponent>(
[&maxWeaponRange_tiles](entt::entity /*we*/, const WeaponComponent& weapon,
const ModuleOwnerComponent& owner)
{
float& best = maxWeaponRange_tiles[owner.owner];
best = std::max(best, weapon.range_tiles);
});
// Pass B: claim counts, taken from every ship's current target before any
// target is reassigned this tick. Each ship reads the previous tick's claim
// state and excludes its own contribution when scoring its current target.
std::unordered_map<entt::entity, int> claimsByTarget;
admin.forEach<AttackBehavior>(
[&claimsByTarget, &admin](entt::entity /*e*/, const AttackBehavior& attack)
{
if (attack.currentTarget && admin.isValid(*attack.currentTarget))
{
++claimsByTarget[*attack.currentTarget];
}
});
// Pass C: per-ship target selection.
admin.forEach<AttackBehavior, PositionComponent, FactionComponent, admin.forEach<AttackBehavior, PositionComponent, FactionComponent,
SensorRangeComponent, HealthComponent>( SensorRangeComponent, HealthComponent>(
[&](entt::entity e, AttackBehavior& attack, const PositionComponent& pos, [&](entt::entity e, AttackBehavior& attack, const PositionComponent& pos,
const FactionComponent& faction, const SensorRangeComponent& sensor, const FactionComponent& faction, const SensorRangeComponent& sensor,
const HealthComponent& health) const HealthComponent& health)
{ {
const float range = sensor.value_tiles; const float sensorRange_tiles = sensor.value_tiles;
// Validate current target: still valid, still in range. // Distance normaliser: max weapon range, or sensor range if unarmed.
bool targetValid = false; float weaponRange_tiles = sensorRange_tiles;
const auto weaponRangeIt = maxWeaponRange_tiles.find(e);
if (weaponRangeIt != maxWeaponRange_tiles.end() && weaponRangeIt->second > 0.0f)
{
weaponRange_tiles = weaponRangeIt->second;
}
// Scores a single candidate: base desirability from distance, reduced
// by the overclaim penalty. selfClaimed subtracts this ship's own claim
// so it does not penalise the target it already holds.
const auto scoreOf =
[&](const QVector2D& candidatePos, entt::entity candidate) -> float
{
const float dist = (candidatePos - pos.value).length();
const float x = dist / weaponRange_tiles;
float base = static_cast<float>(m_targeting->targetScoreFormula.evaluate(x));
base = std::max(base, 0.0f);
int claims = 0;
const auto claimIt = claimsByTarget.find(candidate);
if (claimIt != claimsByTarget.end()) { claims = claimIt->second; }
if (attack.currentTarget && candidate == *attack.currentTarget) { --claims; }
float penalty = static_cast<float>(
m_targeting->overclaimPenaltyFormula.evaluate(claims));
penalty = std::clamp(penalty, 0.0f, 1.0f);
return base * penalty;
};
// Find the best candidate among in-range enemies.
std::optional<entt::entity> bestTarget;
float bestScore = 0.0f;
for (const CombatantInfo& c : combatants)
{
if (c.entity == e) { continue; }
const bool isValidTarget = faction.isEnemy ? !c.isEnemy : c.isEnemy;
if (!isValidTarget) { continue; }
const float dist = (c.position - pos.value).length();
if (dist > sensorRange_tiles) { continue; }
const float score = scoreOf(c.position, c.entity);
if (!bestTarget || score > bestScore)
{
bestScore = score;
bestTarget = c.entity;
}
}
// Hysteresis: keep the current target if it is still valid and in
// range, unless a challenger beats its score by more than the margin.
bool keptCurrent = false;
if (attack.currentTarget) if (attack.currentTarget)
{ {
const entt::entity t = *attack.currentTarget; const entt::entity t = *attack.currentTarget;
if (admin.isValid(t) && admin.hasAll<PositionComponent>(t)) if (admin.isValid(t) && admin.hasAll<PositionComponent>(t))
{ {
const float dist = const QVector2D targetPos = admin.get<PositionComponent>(t).value;
(admin.get<PositionComponent>(t).value - pos.value).length(); const float dist = (targetPos - pos.value).length();
if (dist <= range) { targetValid = true; } if (dist <= sensorRange_tiles)
}
}
// Acquire nearest valid target if needed.
if (!targetValid)
{
attack.currentTarget = std::nullopt;
float bestDist = range;
for (const CombatantInfo& c : combatants)
{
if (c.entity == e) { continue; }
const bool isValidTarget =
faction.isEnemy ? !c.isEnemy : c.isEnemy;
if (!isValidTarget) { continue; }
const float dist = (c.position - pos.value).length();
if (dist < bestDist)
{ {
bestDist = dist; const float currentScore = scoreOf(targetPos, t);
attack.currentTarget = c.entity; const float margin = 1.0f + static_cast<float>(m_targeting->hysteresis);
if (!bestTarget || bestScore <= currentScore * margin)
{
keptCurrent = true;
}
} }
} }
} }
if (!keptCurrent) { attack.currentTarget = bestTarget; }
const bool healthy = const bool healthy =
(health.maxHp > 0.0f) (health.maxHp > 0.0f)
&& (health.hp / health.maxHp >= BehaviorScores::kLowHpFraction); && (health.hp / health.maxHp >= BehaviorScores::kLowHpFraction);

View File

@@ -1,11 +1,22 @@
#pragma once #pragma once
class EntityAdmin; class EntityAdmin;
struct WorldTargeting;
// Acquires/validates a combat target for ships with weapons. Scores high only // Acquires/validates a combat target for ships with weapons. Scores high only
// when the ship's health is not low and a valid target is within sensor range. // when the ship's health is not low and a valid target is within sensor range.
//
// Target choice is claim-aware: each tick the desirability of every candidate is
// scored from a configurable distance formula and reduced by a soft overclaim
// penalty that scales with how many other ships already target it, spreading
// ships across enemies instead of dogpiling the nearest one.
class AttackEvaluator class AttackEvaluator
{ {
public: public:
explicit AttackEvaluator(const WorldTargeting& targeting);
void evaluate(EntityAdmin& admin); void evaluate(EntityAdmin& admin);
private:
const WorldTargeting* m_targeting;
}; };

View File

@@ -5,6 +5,7 @@
#include "EntityAdmin.h" #include "EntityAdmin.h"
#include "ModuleOwnerComponent.h" #include "ModuleOwnerComponent.h"
#include "MovementIntentComponent.h" #include "MovementIntentComponent.h"
#include "OrbitMath.h"
#include "PositionComponent.h" #include "PositionComponent.h"
#include "SelectedBehaviorComponent.h" #include "SelectedBehaviorComponent.h"
#include "tracing.h" #include "tracing.h"
@@ -28,7 +29,9 @@ void AttackExecutor::execute(EntityAdmin& admin)
QVector2D dest = pos.value; QVector2D dest = pos.value;
if (admin.isValid(t) && admin.hasAll<PositionComponent>(t)) if (admin.isValid(t) && admin.hasAll<PositionComponent>(t))
{ {
dest = admin.get<PositionComponent>(t).value; const QVector2D targetPos = admin.get<PositionComponent>(t).value;
dest = OrbitMath::computeOrbitDestination(pos.value, targetPos,
attack.orbitRadius_tiles);
} }
intent = MovementIntentComponent{true, dest}; intent = MovementIntentComponent{true, dest};
}); });

View File

@@ -0,0 +1,45 @@
#pragma once
#include <cmath>
#include <QVector2D>
// Orbit movement helper (REQ-SHP-ORBIT). Behaviors that keep a ship circling a
// target (attack, repair, salvage, rally) feed the result of this function as the
// movement intent destination instead of the target's center.
namespace OrbitMath
{
// Lead angle (radians) by which the radial direction is rotated to produce
// tangential motion. The fixed positive (counter-clockwise) sense makes the
// orbit direction stable for the duration of orbiting a given target.
constexpr float kOrbitLeadAngle_rad = 0.6f;
// Returns a destination on the orbit circle of `radius` around `target`. The
// result always lies exactly `radius` from `target`, so steering toward it
// both corrects the standoff distance and advances the ship tangentially.
// A radius of zero or less falls back to the target center (legacy "approach
// the target" behavior), e.g. when the ship has no tool range to orbit at.
inline QVector2D computeOrbitDestination(const QVector2D& shipPos,
const QVector2D& target, float radius)
{
if (radius <= 0.0f) { return target; }
QVector2D radial = shipPos - target;
float length = radial.length();
if (length < 1.0e-4f)
{
// Ship sits on the target; pick an arbitrary radial direction.
radial = QVector2D(1.0f, 0.0f);
length = 1.0f;
}
const QVector2D radialDirection = radial / length;
const float cosLead = std::cos(kOrbitLeadAngle_rad);
const float sinLead = std::sin(kOrbitLeadAngle_rad);
const QVector2D leadDirection(
radialDirection.x() * cosLead - radialDirection.y() * sinLead,
radialDirection.x() * sinLead + radialDirection.y() * cosLead);
return target + radius * leadDirection;
}
}

View File

@@ -3,6 +3,8 @@
#include "BehaviorKind.h" #include "BehaviorKind.h"
#include "EntityAdmin.h" #include "EntityAdmin.h"
#include "MovementIntentComponent.h" #include "MovementIntentComponent.h"
#include "OrbitMath.h"
#include "PositionComponent.h"
#include "RallyBehavior.h" #include "RallyBehavior.h"
#include "SelectedBehaviorComponent.h" #include "SelectedBehaviorComponent.h"
#include "tracing.h" #include "tracing.h"
@@ -10,11 +12,15 @@
void RallyExecutor::execute(EntityAdmin& admin) void RallyExecutor::execute(EntityAdmin& admin)
{ {
TRACE(); TRACE();
admin.forEach<RallyBehavior, SelectedBehaviorComponent, MovementIntentComponent>( admin.forEach<RallyBehavior, SelectedBehaviorComponent, PositionComponent,
MovementIntentComponent>(
[](entt::entity /*e*/, const RallyBehavior& rally, [](entt::entity /*e*/, const RallyBehavior& rally,
const SelectedBehaviorComponent& selected, MovementIntentComponent& intent) const SelectedBehaviorComponent& selected, const PositionComponent& pos,
MovementIntentComponent& intent)
{ {
if (selected.winner != BehaviorKind::Rally) { return; } if (selected.winner != BehaviorKind::Rally) { return; }
intent = MovementIntentComponent{true, rally.rallyPoint}; const QVector2D dest = OrbitMath::computeOrbitDestination(
pos.value, rally.rallyPoint, rally.orbitRadius_tiles);
intent = MovementIntentComponent{true, dest};
}); });
} }

View File

@@ -4,6 +4,7 @@
#include "EntityAdmin.h" #include "EntityAdmin.h"
#include "ModuleOwnerComponent.h" #include "ModuleOwnerComponent.h"
#include "MovementIntentComponent.h" #include "MovementIntentComponent.h"
#include "OrbitMath.h"
#include "PositionComponent.h" #include "PositionComponent.h"
#include "RepairBehavior.h" #include "RepairBehavior.h"
#include "RepairToolComponent.h" #include "RepairToolComponent.h"
@@ -28,7 +29,9 @@ void RepairExecutor::execute(EntityAdmin& admin)
QVector2D dest = pos.value; QVector2D dest = pos.value;
if (admin.isValid(t) && admin.hasAll<PositionComponent>(t)) if (admin.isValid(t) && admin.hasAll<PositionComponent>(t))
{ {
dest = admin.get<PositionComponent>(t).value; const QVector2D targetPos = admin.get<PositionComponent>(t).value;
dest = OrbitMath::computeOrbitDestination(pos.value, targetPos,
repair.orbitRadius_tiles);
} }
intent = MovementIntentComponent{true, dest}; intent = MovementIntentComponent{true, dest};
}); });

View File

@@ -3,6 +3,8 @@
#include "BehaviorKind.h" #include "BehaviorKind.h"
#include "EntityAdmin.h" #include "EntityAdmin.h"
#include "MovementIntentComponent.h" #include "MovementIntentComponent.h"
#include "OrbitMath.h"
#include "PositionComponent.h"
#include "SalvageScrapBehavior.h" #include "SalvageScrapBehavior.h"
#include "SelectedBehaviorComponent.h" #include "SelectedBehaviorComponent.h"
#include "tracing.h" #include "tracing.h"
@@ -10,12 +12,16 @@
void SalvageScrapExecutor::execute(EntityAdmin& admin) void SalvageScrapExecutor::execute(EntityAdmin& admin)
{ {
TRACE(); TRACE();
admin.forEach<SalvageScrapBehavior, SelectedBehaviorComponent, MovementIntentComponent>( admin.forEach<SalvageScrapBehavior, SelectedBehaviorComponent, PositionComponent,
MovementIntentComponent>(
[](entt::entity /*e*/, const SalvageScrapBehavior& salvage, [](entt::entity /*e*/, const SalvageScrapBehavior& salvage,
const SelectedBehaviorComponent& selected, MovementIntentComponent& intent) const SelectedBehaviorComponent& selected, const PositionComponent& pos,
MovementIntentComponent& intent)
{ {
if (selected.winner != BehaviorKind::SalvageScrap) { return; } if (selected.winner != BehaviorKind::SalvageScrap) { return; }
if (!salvage.scrapTarget) { return; } if (!salvage.scrapTarget) { return; }
intent = MovementIntentComponent{true, *salvage.scrapTarget}; const QVector2D dest = OrbitMath::computeOrbitDestination(
pos.value, *salvage.scrapTarget, salvage.orbitRadius_tiles);
intent = MovementIntentComponent{true, dest};
}); });
} }

View File

@@ -66,7 +66,7 @@ Simulation::Simulation(GameConfig config, unsigned int seed)
[this](const std::string& itemId) -> bool { return isItemUnlocked(itemId); }, [this](const std::string& itemId) -> bool { return isItemUnlocked(itemId); },
m_rng); m_rng);
m_shipSystem = std::make_unique<ShipSystem>(m_config, m_admin); m_shipSystem = std::make_unique<ShipSystem>(m_config, m_admin);
m_aiSystem = std::make_unique<AiSystem>(); m_aiSystem = std::make_unique<AiSystem>(m_config);
m_movementIntentSystem = std::make_unique<MovementIntentSystem>(); m_movementIntentSystem = std::make_unique<MovementIntentSystem>();
m_dynamicBodySystem = std::make_unique<DynamicBodySystem>(); m_dynamicBodySystem = std::make_unique<DynamicBodySystem>();
m_scrapSystem = std::make_unique<ScrapSystem>(m_admin); m_scrapSystem = std::make_unique<ScrapSystem>(m_admin);
@@ -169,7 +169,7 @@ void Simulation::reset(unsigned int seed)
[this](const std::string& itemId) -> bool { return isItemUnlocked(itemId); }, [this](const std::string& itemId) -> bool { return isItemUnlocked(itemId); },
m_rng); m_rng);
m_shipSystem = std::make_unique<ShipSystem>(m_config, m_admin); m_shipSystem = std::make_unique<ShipSystem>(m_config, m_admin);
m_aiSystem = std::make_unique<AiSystem>(); m_aiSystem = std::make_unique<AiSystem>(m_config);
m_movementIntentSystem = std::make_unique<MovementIntentSystem>(); m_movementIntentSystem = std::make_unique<MovementIntentSystem>();
m_dynamicBodySystem = std::make_unique<DynamicBodySystem>(); m_dynamicBodySystem = std::make_unique<DynamicBodySystem>();
m_scrapSystem = std::make_unique<ScrapSystem>(m_admin); m_scrapSystem = std::make_unique<ScrapSystem>(m_admin);

View File

@@ -1,8 +1,10 @@
#include "catch.hpp" #include "catch.hpp"
#include <cmath>
#include <random> #include <random>
#include <QPoint> #include <QPoint>
#include <QSize>
#include <QVector2D> #include <QVector2D>
#include "AdvanceBehavior.h" #include "AdvanceBehavior.h"
@@ -24,6 +26,7 @@
#include "MovementIntentComponent.h" #include "MovementIntentComponent.h"
#include "MovementIntentSystem.h" #include "MovementIntentSystem.h"
#include "PositionComponent.h" #include "PositionComponent.h"
#include "RallyBehavior.h"
#include "RepairBehavior.h" #include "RepairBehavior.h"
#include "RepairSystem.h" #include "RepairSystem.h"
#include "RepairToolComponent.h" #include "RepairToolComponent.h"
@@ -80,6 +83,7 @@ struct Fixture
[](const std::string&) -> bool { return true; }, [](const std::string&) -> bool { return true; },
rng) rng)
, ships(cfg, admin) , ships(cfg, admin)
, ai(cfg)
, salvager(admin) , salvager(admin)
, repair(admin) , repair(admin)
, scraps(admin) , scraps(admin)
@@ -348,6 +352,100 @@ TEST_CASE("BehaviorSystem: player combat ship ignores enemy beyond engagement ra
REQUIRE_FALSE(f.admin.get<AttackBehavior>(player).currentTarget.has_value()); REQUIRE_FALSE(f.admin.get<AttackBehavior>(player).currentTarget.has_value());
} }
// ---------------------------------------------------------------------------
// AttackBehavior — overclaim penalty & hysteresis
// ---------------------------------------------------------------------------
// Absent claims, the nearer enemy wins; once another ship claims that enemy, the
// overclaim penalty steers the deciding ship to the unclaimed, equidistant one.
TEST_CASE("BehaviorSystem: overclaim penalty steers a ship off a claimed target",
"[behavior]")
{
SECTION("no claim: the nearer enemy is chosen")
{
Fixture f;
const entt::entity player = f.ships.spawn("interceptor", 1, QVector2D(0.0f, 0.0f));
const entt::entity nearEnemy = f.ships.spawn("interceptor", 1, QVector2D(8.0f, 0.0f),
/*isEnemy=*/true);
f.ships.spawn("interceptor", 1, QVector2D(0.0f, 12.0f), /*isEnemy=*/true);
f.decide();
REQUIRE(f.admin.get<AttackBehavior>(player).currentTarget == nearEnemy);
}
SECTION("enemyA already claimed: penalty redirects to the unclaimed enemyB")
{
const float d = 10.0f;
Fixture f;
const entt::entity player = f.ships.spawn("interceptor", 1, QVector2D(0.0f, 0.0f));
const entt::entity enemyA = f.ships.spawn("interceptor", 1, QVector2D(d, 0.0f),
/*isEnemy=*/true);
const entt::entity enemyB = f.ships.spawn("interceptor", 1, QVector2D(0.0f, d),
/*isEnemy=*/true);
// A second player ship already commits to enemyA, registering a claim, so
// the penalised score of enemyA falls below the unclaimed equidistant enemyB.
const entt::entity claimant = f.ships.spawn("interceptor", 1, QVector2D(d, 1.0f));
f.admin.get<AttackBehavior>(claimant).currentTarget = enemyA;
f.decide();
REQUIRE(f.admin.get<AttackBehavior>(player).currentTarget == enemyB);
}
}
// Hysteresis keeps a ship on its committed target when a fresh candidate is only
// marginally better — and self-exclusion means the ship's own claim never counts
// against the target it already holds.
TEST_CASE("BehaviorSystem: hysteresis keeps a ship on its own claimed target",
"[behavior]")
{
const float d = 10.0f;
Fixture f;
const entt::entity player = f.ships.spawn("interceptor", 1, QVector2D(0.0f, 0.0f));
const entt::entity enemyA = f.ships.spawn("interceptor", 1, QVector2D(d, 0.0f),
/*isEnemy=*/true);
f.ships.spawn("interceptor", 1, QVector2D(0.0f, d), /*isEnemy=*/true);
// The ship already holds enemyA; enemyB is equidistant. Without self-exclusion
// the ship's own claim would penalise enemyA and flip the choice.
f.admin.get<AttackBehavior>(player).currentTarget = enemyA;
f.decide();
REQUIRE(f.admin.get<AttackBehavior>(player).currentTarget == enemyA);
}
// When the held target becomes heavily overclaimed by others, its penalised score
// drops far enough that an equidistant unclaimed enemy beats the hysteresis margin
// and the ship switches.
TEST_CASE("BehaviorSystem: a ship switches off a heavily overclaimed target",
"[behavior]")
{
const float d = 10.0f;
Fixture f;
const entt::entity player = f.ships.spawn("interceptor", 1, QVector2D(0.0f, 0.0f));
const entt::entity enemyA = f.ships.spawn("interceptor", 1, QVector2D(d, 0.0f),
/*isEnemy=*/true);
const entt::entity enemyB = f.ships.spawn("interceptor", 1, QVector2D(0.0f, d),
/*isEnemy=*/true);
f.admin.get<AttackBehavior>(player).currentTarget = enemyA;
// Five other ships also commit to enemyA, saturating the claim penalty (0.5).
for (int i = 0; i < 5; ++i)
{
const entt::entity other =
f.ships.spawn("interceptor", 1, QVector2D(d, static_cast<float>(2 + i)));
f.admin.get<AttackBehavior>(other).currentTarget = enemyA;
}
f.decide();
REQUIRE(f.admin.get<AttackBehavior>(player).currentTarget == enemyB);
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// AttackBehavior — enemy ships // AttackBehavior — enemy ships
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -383,11 +481,63 @@ TEST_CASE("BehaviorSystem: enemy ship with no target advances leftward",
REQUIRE(intent(f.admin, enemy).target.x() < 0.0f); REQUIRE(intent(f.admin, enemy).target.x() < 0.0f);
} }
TEST_CASE("BehaviorSystem: advancing ship targets center between enemy defence stations",
"[behavior]")
{
Fixture f;
// Two enemy defence stations far from the ship (out of sensor/attack range),
// 1x1 footprint so each center is anchor + (0.5, 0.5).
const std::vector<QPoint> body{QPoint(0, 0)};
f.admin.spawnStation(QPoint(1000, 10), QSize(1, 1), body, 100.0f, 100.0f, /*isEnemy=*/true);
f.admin.spawnStation(QPoint(1000, 30), QSize(1, 1), body, 100.0f, 100.0f, /*isEnemy=*/true);
const entt::entity player = f.ships.spawn("interceptor", 1, QVector2D(0.0f, 0.0f),
/*isEnemy=*/false);
// Player ships rally until departure; drop Rally so Advance is the fallback.
f.ships.triggerRallyDeparture();
f.decide();
// Centers (1000.5, 10.5) and (1000.5, 30.5) -> midpoint (1000.5, 20.5).
REQUIRE(winnerOf(f.admin, player) == BehaviorKind::Advance);
REQUIRE(intent(f.admin, player).active);
REQUIRE(intent(f.admin, player).target.x() == Approx(1000.5f));
REQUIRE(intent(f.admin, player).target.y() == Approx(20.5f));
}
TEST_CASE("BehaviorSystem: advancing ship falls back to enemy HQ, then off-world",
"[behavior]")
{
Fixture f;
// Player HQ proxy (isEnemy=false) but no player defence stations.
const QVector2D hqPos(5.0f, 7.0f);
const entt::entity hq = f.admin.spawnHqProxy(hqPos, 100.0f, 100.0f);
const entt::entity enemy = f.ships.spawn("interceptor", 1, QVector2D(1000.0f, 0.0f),
/*isEnemy=*/true);
f.decide();
REQUIRE(winnerOf(f.admin, enemy) == BehaviorKind::Advance);
REQUIRE(intent(f.admin, enemy).active);
REQUIRE(intent(f.admin, enemy).target.x() == Approx(hqPos.x()));
REQUIRE(intent(f.admin, enemy).target.y() == Approx(hqPos.y()));
// With the HQ gone too, the ship falls back to advancing off-world (leftward).
f.admin.get<HealthComponent>(hq).hp = 0.0f;
f.decide();
REQUIRE(winnerOf(f.admin, enemy) == BehaviorKind::Advance);
REQUIRE(intent(f.admin, enemy).target.x() < 0.0f);
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// RepairBehavior // RepairBehavior
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
TEST_CASE("BehaviorSystem: repair ship moves toward damaged friendly ship", TEST_CASE("BehaviorSystem: repair ship orbits damaged friendly ship",
"[behavior]") "[behavior]")
{ {
Fixture f; Fixture f;
@@ -402,7 +552,13 @@ TEST_CASE("BehaviorSystem: repair ship moves toward damaged friendly ship",
REQUIRE(winnerOf(f.admin, repairShip) == BehaviorKind::Repair); REQUIRE(winnerOf(f.admin, repairShip) == BehaviorKind::Repair);
REQUIRE(intent(f.admin, repairShip).active); REQUIRE(intent(f.admin, repairShip).active);
REQUIRE(intent(f.admin, repairShip).target.x() == Approx(5.0f));
// Orbit at orbit_factor * max repair range (REQ-SHP-ORBIT): the movement
// destination lies exactly the orbit radius from the target's center.
const float orbitRadius = f.admin.get<RepairBehavior>(repairShip).orbitRadius_tiles;
REQUIRE(orbitRadius > 0.0f);
REQUIRE((intent(f.admin, repairShip).target - pos(f.admin, friendly).value).length()
== Approx(orbitRadius));
} }
TEST_CASE("BehaviorSystem: repair ship heals damaged ally within repair range", TEST_CASE("BehaviorSystem: repair ship heals damaged ally within repair range",
@@ -650,7 +806,7 @@ TEST_CASE("RepairSystem: does not crash when a tool's owner is not a repair ship
// SalvageScrapBehavior / DeliverScrapBehavior // SalvageScrapBehavior / DeliverScrapBehavior
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
TEST_CASE("BehaviorSystem: salvage ship moves toward nearest scrap", "[behavior]") TEST_CASE("BehaviorSystem: salvage ship orbits nearest scrap", "[behavior]")
{ {
Fixture f; Fixture f;
const ShipLayoutConfig salvageLayout = makeSingleModuleLayout("salvager"); const ShipLayoutConfig salvageLayout = makeSingleModuleLayout("salvager");
@@ -664,7 +820,11 @@ TEST_CASE("BehaviorSystem: salvage ship moves toward nearest scrap", "[behavior]
REQUIRE(winnerOf(f.admin, ship) == BehaviorKind::SalvageScrap); REQUIRE(winnerOf(f.admin, ship) == BehaviorKind::SalvageScrap);
REQUIRE(intent(f.admin, ship).active); REQUIRE(intent(f.admin, ship).active);
REQUIRE(intent(f.admin, ship).target.x() == Approx(scrapPos.x()));
// Orbit at orbit_factor * max collection range (REQ-SHP-ORBIT).
const float orbitRadius = f.admin.get<SalvageScrapBehavior>(ship).orbitRadius_tiles;
REQUIRE(orbitRadius > 0.0f);
REQUIRE((intent(f.admin, ship).target - scrapPos).length() == Approx(orbitRadius));
} }
TEST_CASE("BehaviorSystem: salvage ship collects scrap on arrival", "[behavior]") TEST_CASE("BehaviorSystem: salvage ship collects scrap on arrival", "[behavior]")
@@ -985,3 +1145,76 @@ TEST_CASE("SensorRange: salvage ship ignores scrap beyond sensor range", "[senso
REQUIRE_FALSE(f.admin.get<SalvageScrapBehavior>(ship).scrapTarget.has_value()); REQUIRE_FALSE(f.admin.get<SalvageScrapBehavior>(ship).scrapTarget.has_value());
REQUIRE(intent(f.admin, ship).target.x() > pos(f.admin, ship).value.x()); REQUIRE(intent(f.admin, ship).target.x() > pos(f.admin, ship).value.x());
} }
// ---------------------------------------------------------------------------
// Orbit movement (REQ-SHP-ORBIT)
// ---------------------------------------------------------------------------
TEST_CASE("Orbit: combat ship aims at a point on the orbit circle around its target",
"[orbit]")
{
Fixture f;
const entt::entity player = f.ships.spawn("interceptor", 1, QVector2D(0.0f, 0.0f));
const entt::entity enemy = f.ships.spawn("interceptor", 1, QVector2D(10.0f, 0.0f),
/*isEnemy=*/true);
f.decide();
REQUIRE(winnerOf(f.admin, player) == BehaviorKind::Attack);
const float orbitRadius = f.admin.get<AttackBehavior>(player).orbitRadius_tiles;
REQUIRE(orbitRadius > 0.0f);
// The movement destination lies exactly the orbit radius from the enemy center.
REQUIRE((intent(f.admin, player).target - pos(f.admin, enemy).value).length()
== Approx(orbitRadius));
}
TEST_CASE("Orbit: rally ship orbits the rally point at the configured rally radius",
"[orbit]")
{
Fixture f;
const QVector2D rallyPoint(-50.0f, 0.0f);
f.ships.setRallyPoint(rallyPoint);
const entt::entity player = f.ships.spawn("interceptor", 1, QVector2D(0.0f, 0.0f));
f.decide();
REQUIRE(winnerOf(f.admin, player) == BehaviorKind::Rally);
const float orbitRadius = f.admin.get<RallyBehavior>(player).orbitRadius_tiles;
REQUIRE(orbitRadius == Approx(static_cast<float>(f.cfg.world.rallyOrbitRadius_tiles)));
REQUIRE((intent(f.admin, player).target - rallyPoint).length() == Approx(orbitRadius));
}
TEST_CASE("Orbit: combat ship settles near the orbit radius and circles a stationary target",
"[orbit]")
{
Fixture f;
const QVector2D enemyPos(80.0f, 0.0f);
const entt::entity player = f.ships.spawn("interceptor", 1, QVector2D(0.0f, 0.0f));
const entt::entity enemy = f.ships.spawn("interceptor", 1, enemyPos, /*isEnemy=*/true);
const float orbitRadius = f.admin.get<AttackBehavior>(player).orbitRadius_tiles;
REQUIRE(orbitRadius > 0.0f);
REQUIRE(orbitRadius < enemyPos.x()); // ship must close in to reach the orbit
// Run many full ticks, pinning the enemy in place so it is a stationary target.
float angleBefore = 0.0f;
for (int i = 0; i < 1200; ++i)
{
f.admin.get<PositionComponent>(enemy).value = enemyPos; // keep target fixed
f.admin.get<DynamicBodyComponent>(enemy).velocity_tpt = QVector2D(0.0f, 0.0f);
if (i == 800)
{
angleBefore = std::atan2(pos(f.admin, player).value.y() - enemyPos.y(),
pos(f.admin, player).value.x() - enemyPos.x());
}
f.runBehaviorTick();
}
const float angleAfter = std::atan2(pos(f.admin, player).value.y() - enemyPos.y(),
pos(f.admin, player).value.x() - enemyPos.x());
// Settled close to the orbit radius (chasing a moving lead point oscillates a bit).
const float dist = (pos(f.admin, player).value - enemyPos).length();
REQUIRE(dist == Approx(orbitRadius).margin(0.35f * orbitRadius));
// The ship is circling: its angular position around the target has moved.
REQUIRE(std::abs(angleAfter - angleBefore) > 0.05f);
}

View File

@@ -76,12 +76,21 @@ TEST_CASE("ConfigLoader loads the committed bin/config/ configs end-to-end", "[c
REQUIRE(cfg.world.regions.enemyBufferWidth_tiles == 15); REQUIRE(cfg.world.regions.enemyBufferWidth_tiles == 15);
REQUIRE(cfg.world.expansion.columnsPerExpansion_tiles == 10); REQUIRE(cfg.world.expansion.columnsPerExpansion_tiles == 10);
REQUIRE(cfg.world.push.bossAdvanceSeconds == Approx(60.0)); REQUIRE(cfg.world.push.bossAdvanceSeconds == Approx(60.0));
REQUIRE(cfg.world.orbitFactor == Approx(0.8));
REQUIRE(cfg.world.rallyOrbitRadius_tiles == Approx(5.0));
// Spot-check that a config-derived formula computes as expected. // Spot-check that a config-derived formula computes as expected.
// threat_rate_formula = "x": evaluates to the input value. // threat_rate_formula = "x": evaluates to the input value.
REQUIRE(cfg.world.waves.threatRateFormula.evaluate(1.0) == Approx(1.0)); REQUIRE(cfg.world.waves.threatRateFormula.evaluate(1.0) == Approx(1.0));
REQUIRE(cfg.world.waves.threatRateFormula.evaluate(5.0) == Approx(5.0)); REQUIRE(cfg.world.waves.threatRateFormula.evaluate(5.0) == Approx(5.0));
// targeting: distance score 1/(1+x) and overclaim penalty max(0.5, 1-0.1*x).
REQUIRE(cfg.world.targeting.hysteresis == Approx(0.10));
REQUIRE(cfg.world.targeting.targetScoreFormula.evaluate(0.0) == Approx(1.0));
REQUIRE(cfg.world.targeting.targetScoreFormula.evaluate(1.0) == Approx(0.5));
REQUIRE(cfg.world.targeting.overclaimPenaltyFormula.evaluate(0.0) == Approx(1.0));
REQUIRE(cfg.world.targeting.overclaimPenaltyFormula.evaluate(5.0) == Approx(0.5));
// buildings.toml // buildings.toml
REQUIRE(cfg.buildings.buildings.size() >= 8); REQUIRE(cfg.buildings.buildings.size() >= 8);
const auto minerIt = std::find_if( const auto minerIt = std::find_if(
@@ -163,6 +172,8 @@ belt_speed_mps = 20
starting_building_blocks = 100 starting_building_blocks = 100
tunnel_max_distance_tiles = 10 tunnel_max_distance_tiles = 10
departure_interval_seconds = 20 departure_interval_seconds = 20
orbit_factor = 0.8
rally_orbit_radius_tiles = 5.0
[regions] [regions]
asteroid_width_tiles = 40 asteroid_width_tiles = 40
@@ -211,6 +222,8 @@ belt_speed_mps = 20
starting_building_blocks = 100 starting_building_blocks = 100
tunnel_max_distance_tiles = 10 tunnel_max_distance_tiles = 10
departure_interval_seconds = 20 departure_interval_seconds = 20
orbit_factor = 0.8
rally_orbit_radius_tiles = 5.0
[regions] [regions]
asteroid_width_tiles = 40 asteroid_width_tiles = 40