Prefix all getters with "get"
This commit is contained in:
@@ -87,7 +87,7 @@ static void fillMaterials(Simulation& sim, BuildingId yardId,
|
||||
}
|
||||
for (const PlacedModule& pm : layout.placedModules)
|
||||
{
|
||||
for (const ModuleDef& modDef : sim.config().modules.modules)
|
||||
for (const ModuleDef& modDef : sim.getConfig().modules.modules)
|
||||
{
|
||||
if (modDef.id == pm.moduleId)
|
||||
{
|
||||
@@ -109,22 +109,22 @@ static void fillMaterials(Simulation& sim, BuildingId yardId,
|
||||
TEST_CASE("Ship spawn: no modules leaves base stats unchanged", "[modules]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
const ShipDef* def = findSchematic(sim.config(), "interceptor");
|
||||
const ShipDef* def = findSchematic(sim.getConfig(), "interceptor");
|
||||
REQUIRE(def != nullptr);
|
||||
|
||||
const float expectedHp = static_cast<float>(def->health.hp);
|
||||
|
||||
const entt::entity e = sim.ships().spawn("interceptor",
|
||||
const entt::entity e = sim.getShips().spawn("interceptor",
|
||||
QVector2D(5.0f, 5.0f), false, std::nullopt);
|
||||
|
||||
REQUIRE(sim.admin().isValid(e));
|
||||
CHECK(sim.admin().get<HealthComponent>(e).maxHp == Approx(expectedHp));
|
||||
REQUIRE(sim.getAdmin().isValid(e));
|
||||
CHECK(sim.getAdmin().get<HealthComponent>(e).maxHp == Approx(expectedHp));
|
||||
}
|
||||
|
||||
TEST_CASE("Ship spawn: multiplicative HP module applies correctly", "[modules]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
const ShipDef* def = findSchematic(sim.config(), "interceptor");
|
||||
const ShipDef* def = findSchematic(sim.getConfig(), "interceptor");
|
||||
REQUIRE(def != nullptr);
|
||||
|
||||
const float baseHp = static_cast<float>(def->health.hp);
|
||||
@@ -136,23 +136,23 @@ TEST_CASE("Ship spawn: multiplicative HP module applies correctly", "[modules]")
|
||||
pm.rotation = Rotation::East;
|
||||
layout.placedModules.push_back(pm);
|
||||
|
||||
const entt::entity e = sim.ships().spawn("interceptor",
|
||||
const entt::entity e = sim.getShips().spawn("interceptor",
|
||||
QVector2D(5.0f, 5.0f), false, layout);
|
||||
|
||||
REQUIRE(sim.admin().isValid(e));
|
||||
REQUIRE(sim.getAdmin().isValid(e));
|
||||
// armor_plate has multiplied_hp_formula = "1.5"
|
||||
// final = base * (1 + (1.5 - 1)) + 0 = base * 1.5
|
||||
CHECK(sim.admin().get<HealthComponent>(e).maxHp == Approx(baseHp * 1.5f));
|
||||
CHECK(sim.admin().get<HealthComponent>(e).hp == sim.admin().get<HealthComponent>(e).maxHp);
|
||||
CHECK(sim.getAdmin().get<HealthComponent>(e).maxHp == Approx(baseHp * 1.5f));
|
||||
CHECK(sim.getAdmin().get<HealthComponent>(e).hp == sim.getAdmin().get<HealthComponent>(e).maxHp);
|
||||
}
|
||||
|
||||
TEST_CASE("Ship spawn: additive sensor module applies correctly", "[modules]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
const ShipDef* def = findSchematic(sim.config(), "interceptor");
|
||||
const ShipDef* def = findSchematic(sim.getConfig(), "interceptor");
|
||||
REQUIRE(def != nullptr);
|
||||
|
||||
const float tileSize = static_cast<float>(sim.config().world.tileSize_m);
|
||||
const float tileSize = static_cast<float>(sim.getConfig().world.tileSize_m);
|
||||
const float baseRange_tiles = static_cast<float>(def->sensor.sensorRange_m) / tileSize;
|
||||
|
||||
ShipLayoutConfig layout;
|
||||
@@ -162,19 +162,19 @@ TEST_CASE("Ship spawn: additive sensor module applies correctly", "[modules]")
|
||||
pm.rotation = Rotation::East;
|
||||
layout.placedModules.push_back(pm);
|
||||
|
||||
const entt::entity e = sim.ships().spawn("interceptor",
|
||||
const entt::entity e = sim.getShips().spawn("interceptor",
|
||||
QVector2D(5.0f, 5.0f), false, layout);
|
||||
|
||||
REQUIRE(sim.admin().isValid(e));
|
||||
REQUIRE(sim.getAdmin().isValid(e));
|
||||
// sensor_booster has added_sensor_range_m_formula = "100" m → 100/10 = 10 tiles
|
||||
// final = baseRange_tiles * 1.0 + 10 = baseRange_tiles + 10
|
||||
CHECK(sim.admin().get<SensorRangeComponent>(e).value_tiles == Approx(baseRange_tiles + 10.0f));
|
||||
CHECK(sim.getAdmin().get<SensorRangeComponent>(e).value_tiles == Approx(baseRange_tiles + 10.0f));
|
||||
}
|
||||
|
||||
TEST_CASE("Ship spawn: multiple modules stack correctly", "[modules]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
const ShipDef* def = findSchematic(sim.config(), "interceptor");
|
||||
const ShipDef* def = findSchematic(sim.getConfig(), "interceptor");
|
||||
REQUIRE(def != nullptr);
|
||||
|
||||
const float baseHp = static_cast<float>(def->health.hp);
|
||||
@@ -189,14 +189,14 @@ TEST_CASE("Ship spawn: multiple modules stack correctly", "[modules]")
|
||||
layout.placedModules.push_back(pm);
|
||||
}
|
||||
|
||||
const entt::entity e = sim.ships().spawn("interceptor",
|
||||
const entt::entity e = sim.getShips().spawn("interceptor",
|
||||
QVector2D(5.0f, 5.0f), false, layout);
|
||||
|
||||
REQUIRE(sim.admin().isValid(e));
|
||||
REQUIRE(sim.getAdmin().isValid(e));
|
||||
// Two armor_plates: each 1.5 multiplier
|
||||
// total_mult = 1 + (1.5 - 1) + (1.5 - 1) = 2.0
|
||||
// final = base * 2.0
|
||||
CHECK(sim.admin().get<HealthComponent>(e).maxHp == Approx(baseHp * 2.0f));
|
||||
CHECK(sim.getAdmin().get<HealthComponent>(e).maxHp == Approx(baseHp * 2.0f));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -207,7 +207,7 @@ TEST_CASE("Shipyard: setShipLayout reinitializes buffers with module materials",
|
||||
"[modules][shipyard]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
const BuildingDef* yardDef = findShipyardDef(sim.config());
|
||||
const BuildingDef* yardDef = findShipyardDef(sim.getConfig());
|
||||
REQUIRE(yardDef != nullptr);
|
||||
|
||||
const BuildingId yardId = placeShipyard(sim, *yardDef);
|
||||
@@ -222,7 +222,7 @@ TEST_CASE("Shipyard: setShipLayout reinitializes buffers with module materials",
|
||||
|
||||
SimulationTestAccess::buildings(sim).setShipLayout(yardId, layout);
|
||||
|
||||
const Building* b = sim.buildings().findBuilding(yardId);
|
||||
const Building* b = sim.getBuildings().findBuilding(yardId);
|
||||
REQUIRE(b != nullptr);
|
||||
// armor_plate needs 2 iron_ingot; interceptor needs 3 iron_ingot + 1 circuit_board
|
||||
// Total iron_ingot = 5, buffer cap = 2 * 5 = 10
|
||||
@@ -234,9 +234,9 @@ TEST_CASE("Shipyard: setShipLayout cancels in-progress production",
|
||||
"[modules][shipyard]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
const ShipDef* def = findSchematic(sim.config(), "interceptor");
|
||||
const ShipDef* def = findSchematic(sim.getConfig(), "interceptor");
|
||||
REQUIRE(def != nullptr);
|
||||
const BuildingDef* yardDef = findShipyardDef(sim.config());
|
||||
const BuildingDef* yardDef = findShipyardDef(sim.getConfig());
|
||||
REQUIRE(yardDef != nullptr);
|
||||
|
||||
const BuildingId yardId = placeShipyard(sim, *yardDef);
|
||||
@@ -247,7 +247,7 @@ TEST_CASE("Shipyard: setShipLayout cancels in-progress production",
|
||||
fillMaterials(sim, yardId, *def, emptyLayout);
|
||||
sim.tick();
|
||||
|
||||
const Building* b1 = sim.buildings().findBuilding(yardId);
|
||||
const Building* b1 = sim.getBuildings().findBuilding(yardId);
|
||||
REQUIRE(b1 != nullptr);
|
||||
REQUIRE(b1->production.has_value());
|
||||
|
||||
@@ -261,7 +261,7 @@ TEST_CASE("Shipyard: setShipLayout cancels in-progress production",
|
||||
|
||||
SimulationTestAccess::buildings(sim).setShipLayout(yardId, layout);
|
||||
|
||||
const Building* b2 = sim.buildings().findBuilding(yardId);
|
||||
const Building* b2 = sim.getBuildings().findBuilding(yardId);
|
||||
REQUIRE(b2 != nullptr);
|
||||
CHECK_FALSE(b2->production.has_value());
|
||||
}
|
||||
@@ -270,7 +270,7 @@ TEST_CASE("Shipyard: builds a bare hull when no layout is configured",
|
||||
"[modules][shipyard]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
const ShipDef* def = findSchematic(sim.config(), "interceptor");
|
||||
const ShipDef* def = findSchematic(sim.getConfig(), "interceptor");
|
||||
REQUIRE(def != nullptr);
|
||||
// The schematic carries a weapon in its (wave-only) default loadout. This
|
||||
// test pins that a player shipyard with no configured layout does NOT hand
|
||||
@@ -278,7 +278,7 @@ TEST_CASE("Shipyard: builds a bare hull when no layout is configured",
|
||||
// base-hull materials it was charged.
|
||||
REQUIRE_FALSE(def->defaultModules.empty());
|
||||
|
||||
const BuildingDef* yardDef = findShipyardDef(sim.config());
|
||||
const BuildingDef* yardDef = findShipyardDef(sim.getConfig());
|
||||
REQUIRE(yardDef != nullptr);
|
||||
|
||||
const BuildingId yardId = placeShipyard(sim, *yardDef);
|
||||
@@ -297,23 +297,23 @@ TEST_CASE("Shipyard: builds a bare hull when no layout is configured",
|
||||
|
||||
// Locate the freshly built player ship.
|
||||
entt::entity built = entt::null;
|
||||
sim.admin().forEach<ShipIdentityComponent, FactionComponent>(
|
||||
sim.getAdmin().forEach<ShipIdentityComponent, FactionComponent>(
|
||||
[&](entt::entity e, const ShipIdentityComponent& si, const FactionComponent& fac)
|
||||
{
|
||||
if (!fac.isEnemy && si.schematicId == "interceptor") { built = e; }
|
||||
});
|
||||
REQUIRE(sim.admin().isValid(built));
|
||||
REQUIRE(sim.getAdmin().isValid(built));
|
||||
|
||||
// Bare hull: the schematic's default weapon must NOT have been installed.
|
||||
const bool hasWeapon =
|
||||
findFirstWeaponChild(sim.admin(), built) != entt::null;
|
||||
findFirstWeaponChild(sim.getAdmin(), built) != entt::null;
|
||||
CHECK_FALSE(hasWeapon);
|
||||
}
|
||||
|
||||
TEST_CASE("Shipyard: setRecipe clears ship layout", "[modules][shipyard]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
const BuildingDef* yardDef = findShipyardDef(sim.config());
|
||||
const BuildingDef* yardDef = findShipyardDef(sim.getConfig());
|
||||
REQUIRE(yardDef != nullptr);
|
||||
|
||||
const BuildingId yardId = placeShipyard(sim, *yardDef);
|
||||
@@ -327,13 +327,13 @@ TEST_CASE("Shipyard: setRecipe clears ship layout", "[modules][shipyard]")
|
||||
layout.placedModules.push_back(pm);
|
||||
SimulationTestAccess::buildings(sim).setShipLayout(yardId, layout);
|
||||
|
||||
const Building* b1 = sim.buildings().findBuilding(yardId);
|
||||
const Building* b1 = sim.getBuildings().findBuilding(yardId);
|
||||
REQUIRE(b1 != nullptr);
|
||||
REQUIRE(b1->shipLayout.has_value());
|
||||
|
||||
SimulationTestAccess::buildings(sim).setRecipe(yardId,"destroyer");
|
||||
|
||||
const Building* b2 = sim.buildings().findBuilding(yardId);
|
||||
const Building* b2 = sim.getBuildings().findBuilding(yardId);
|
||||
REQUIRE(b2 != nullptr);
|
||||
CHECK_FALSE(b2->shipLayout.has_value());
|
||||
}
|
||||
@@ -342,7 +342,7 @@ TEST_CASE("Shipyard: setRecipe with unchanged recipe keeps ship layout",
|
||||
"[modules][shipyard]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
const BuildingDef* yardDef = findShipyardDef(sim.config());
|
||||
const BuildingDef* yardDef = findShipyardDef(sim.getConfig());
|
||||
REQUIRE(yardDef != nullptr);
|
||||
|
||||
const BuildingId yardId = placeShipyard(sim, *yardDef);
|
||||
@@ -356,14 +356,14 @@ TEST_CASE("Shipyard: setRecipe with unchanged recipe keeps ship layout",
|
||||
layout.placedModules.push_back(pm);
|
||||
SimulationTestAccess::buildings(sim).setShipLayout(yardId, layout);
|
||||
|
||||
const Building* b1 = sim.buildings().findBuilding(yardId);
|
||||
const Building* b1 = sim.getBuildings().findBuilding(yardId);
|
||||
REQUIRE(b1 != nullptr);
|
||||
REQUIRE(b1->shipLayout.has_value());
|
||||
|
||||
// Re-selecting the same recipe must be a no-op and preserve the layout.
|
||||
SimulationTestAccess::buildings(sim).setRecipe(yardId,"interceptor");
|
||||
|
||||
const Building* b2 = sim.buildings().findBuilding(yardId);
|
||||
const Building* b2 = sim.getBuildings().findBuilding(yardId);
|
||||
REQUIRE(b2 != nullptr);
|
||||
REQUIRE(b2->shipLayout.has_value());
|
||||
REQUIRE(b2->shipLayout->placedModules.size() == 1);
|
||||
@@ -377,7 +377,7 @@ TEST_CASE("Shipyard: setRecipe with unchanged recipe keeps ship layout",
|
||||
TEST_CASE("Ship spawn: weapon_primer multiplies attack rate in simulation", "[modules]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
const ShipDef* def = findSchematic(sim.config(), "interceptor");
|
||||
const ShipDef* def = findSchematic(sim.getConfig(), "interceptor");
|
||||
REQUIRE(def != nullptr);
|
||||
|
||||
ShipLayoutConfig layout;
|
||||
@@ -390,22 +390,22 @@ TEST_CASE("Ship spawn: weapon_primer multiplies attack rate in simulation", "[mo
|
||||
layout.placedModules.push_back(pm);
|
||||
}
|
||||
|
||||
const entt::entity ship = sim.ships().spawn("interceptor",
|
||||
const entt::entity ship = sim.getShips().spawn("interceptor",
|
||||
QVector2D(5.0f, 5.0f), false, layout);
|
||||
|
||||
const entt::entity weapon = findFirstWeaponChild(sim.admin(), ship);
|
||||
REQUIRE(sim.admin().isValid(weapon));
|
||||
const entt::entity weapon = findFirstWeaponChild(sim.getAdmin(), ship);
|
||||
REQUIRE(sim.getAdmin().isValid(weapon));
|
||||
// base rate = 2.0 hz; weapon_primer multiplier = 1.2 → 2.4 hz
|
||||
CHECK(sim.admin().get<WeaponComponent>(weapon).fireRateHz == Approx(2.4f));
|
||||
CHECK(sim.getAdmin().get<WeaponComponent>(weapon).fireRateHz == Approx(2.4f));
|
||||
}
|
||||
|
||||
TEST_CASE("Ship spawn: weapon_stabilizer multiplies attack range in simulation", "[modules]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
const ShipDef* def = findSchematic(sim.config(), "interceptor");
|
||||
const ShipDef* def = findSchematic(sim.getConfig(), "interceptor");
|
||||
REQUIRE(def != nullptr);
|
||||
|
||||
const float tileSize = static_cast<float>(sim.config().world.tileSize_m);
|
||||
const float tileSize = static_cast<float>(sim.getConfig().world.tileSize_m);
|
||||
|
||||
ShipLayoutConfig layout;
|
||||
for (const std::string& id : {"laser_cannon", "weapon_stabilizer"})
|
||||
@@ -417,22 +417,22 @@ TEST_CASE("Ship spawn: weapon_stabilizer multiplies attack range in simulation",
|
||||
layout.placedModules.push_back(pm);
|
||||
}
|
||||
|
||||
const entt::entity ship = sim.ships().spawn("interceptor",
|
||||
const entt::entity ship = sim.getShips().spawn("interceptor",
|
||||
QVector2D(5.0f, 5.0f), false, layout);
|
||||
|
||||
const entt::entity weapon = findFirstWeaponChild(sim.admin(), ship);
|
||||
REQUIRE(sim.admin().isValid(weapon));
|
||||
const entt::entity weapon = findFirstWeaponChild(sim.getAdmin(), ship);
|
||||
REQUIRE(sim.getAdmin().isValid(weapon));
|
||||
// base range = 50 m / tileSize = 5 tiles; weapon_stabilizer multiplier = 1.5 → 7.5 tiles
|
||||
CHECK(sim.admin().get<WeaponComponent>(weapon).range_tiles == Approx(50.0f / tileSize * 1.5f));
|
||||
CHECK(sim.getAdmin().get<WeaponComponent>(weapon).range_tiles == Approx(50.0f / tileSize * 1.5f));
|
||||
}
|
||||
|
||||
TEST_CASE("Ship spawn: afterburner additive main_acceleration is converted m/s² to tiles/tick", "[modules]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
const ShipDef* def = findSchematic(sim.config(), "interceptor");
|
||||
const ShipDef* def = findSchematic(sim.getConfig(), "interceptor");
|
||||
REQUIRE(def != nullptr);
|
||||
|
||||
const float tileSize = static_cast<float>(sim.config().world.tileSize_m);
|
||||
const float tileSize = static_cast<float>(sim.getConfig().world.tileSize_m);
|
||||
const float tickRate = static_cast<float>(kTickRateHz);
|
||||
const float base_mpss = static_cast<float>(def->movement.mainAcceleration_mpss);
|
||||
|
||||
@@ -443,21 +443,21 @@ TEST_CASE("Ship spawn: afterburner additive main_acceleration is converted m/s²
|
||||
pm.rotation = Rotation::East;
|
||||
layout.placedModules.push_back(pm);
|
||||
|
||||
const entt::entity e = sim.ships().spawn("interceptor",
|
||||
const entt::entity e = sim.getShips().spawn("interceptor",
|
||||
QVector2D(5.0f, 5.0f), false, layout);
|
||||
|
||||
// added_main_acceleration_mpss = 60; same conversion as base: / tileSize / tickRate
|
||||
const float expected = (base_mpss + 60.0f) / tileSize / tickRate;
|
||||
CHECK(sim.admin().get<DynamicBodyComponent>(e).mainAcceleration_tptt == Approx(expected));
|
||||
CHECK(sim.getAdmin().get<DynamicBodyComponent>(e).mainAcceleration_tptt == Approx(expected));
|
||||
}
|
||||
|
||||
TEST_CASE("Ship spawn: maneuvering_thrusters additive maneuvering_acceleration is converted m/s² to tiles/tick", "[modules]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
const ShipDef* def = findSchematic(sim.config(), "interceptor");
|
||||
const ShipDef* def = findSchematic(sim.getConfig(), "interceptor");
|
||||
REQUIRE(def != nullptr);
|
||||
|
||||
const float tileSize = static_cast<float>(sim.config().world.tileSize_m);
|
||||
const float tileSize = static_cast<float>(sim.getConfig().world.tileSize_m);
|
||||
const float tickRate = static_cast<float>(kTickRateHz);
|
||||
const float base_mpss = static_cast<float>(def->movement.maneuveringAcceleration_mpss);
|
||||
|
||||
@@ -468,12 +468,12 @@ TEST_CASE("Ship spawn: maneuvering_thrusters additive maneuvering_acceleration i
|
||||
pm.rotation = Rotation::East;
|
||||
layout.placedModules.push_back(pm);
|
||||
|
||||
const entt::entity e = sim.ships().spawn("interceptor",
|
||||
const entt::entity e = sim.getShips().spawn("interceptor",
|
||||
QVector2D(5.0f, 5.0f), false, layout);
|
||||
|
||||
// added_maneuvering_acceleration_mpss = 10; same conversion as base: / tileSize / tickRate
|
||||
const float expected = (base_mpss + 10.0f) / tileSize / tickRate;
|
||||
CHECK(sim.admin().get<DynamicBodyComponent>(e).maneuveringAcceleration_tptt == Approx(expected));
|
||||
CHECK(sim.getAdmin().get<DynamicBodyComponent>(e).maneuveringAcceleration_tptt == Approx(expected));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user