The two derived words the per-player turn record's ship census counts by, and the design serializers that three lanes had been told did not exist. HOW DESIGNS PERSIST. Game::ShipDesign derives from Game::ShipDesignDef and reaches IStreamable through adjustor thunks, so a design is written by TWO serializers: the base emits FAIDes/DHide/DWep/DName and exactly three section frames (command, mission, engine on the wire), the derived one appends Dtc, the Dwgv flag and, only when that flag is set, a weapon-group frame. The earlier "the writer makes no stream call at all" note named an address that is in no vftable at all. Corrected in shapes.h. THREE sections, not five. The "two reserved slots" were Dtc and Dwgv swept into the section list by the reference reader's catch-all tail; the constructor builds a three-element array. design.h's comment is corrected and the fixture loader now accepts 3-5 raw_slots so old fixtures still load; the array keeps five inert entries deliberately, since touching the slot enum reaches rules.cpp and another lane's tests for no behavioural gain. DWep and Dwgv are bools, not ints -- both writers call the bool primitive. With four-character tags a bool item and an int item are the same size on the wire and 0/1 the same bytes, so no save can tell them apart. Byte-neutral: the typed round trip is still byte-identical on all 11 saves at 100% named coverage. HULL SIZE is the section_class of the last resolved section in memory slot order, mapped Destroyer/Cruiser/Dreadnought -> 0/1/2 case-insensitively, with absent or unrecognised meaning 0 rather than an error. The DEFENCE-PLATFORM flag is one bit of a 64-bit role-flag word OR-ed across the design's sections. Neither is on the wire; both are rebuilt from the section catalog. MEASURED, not assumed: the new game_design_census test rebuilds the six census counters per player and compares them against the record the game archived for each save's own frame. 11 saves, 503 designs, 480 leaves, 0 mismatched, 0 ships with an unresolvable design, 0 designs where first- and last-resolved section disagree on hull size. COVERAGE IS THIN AND THE TEST SAYS SO: only 32 of the 480 leaves are nonzero, and three of the six census leaves (both cruiser rows and dreadnought platforms) are never exercised by any save in the corpus -- the test prints the per-leaf nonzero counts and names them unexercised rather than verified. Nothing is wired into the turn record: src/app is another lane's this cycle, so this is evaluated and reported, not written. host ctest 43/43 (was 42/42; +1, skips cleanly without the env). With a data root set, game_data_realdata and mars_text_realdata fail identically on main -- both are the absent Locale/EN/Strings.csv, not this change. clean-room OK. Reference readers fixed openly in the RE repo: save_reader 49/49, design rules 32/32, stock_designs.json regenerated (raw_slots 5->3 and dWep int->bool are the only field changes across all 127 designs).
146 lines
4.9 KiB
C++
146 lines
4.9 KiB
C++
// Hull size, the defence-platform class flag, and the six-counter census.
|
|
#include "game/design/hull.h"
|
|
|
|
#include "game/design/stats.h"
|
|
#include "mini_catalog.h"
|
|
#include "test_main.h"
|
|
|
|
using namespace game::data;
|
|
using namespace game::design;
|
|
|
|
namespace {
|
|
|
|
Design platform() {
|
|
Design d;
|
|
d.name = "Light Defense Platform";
|
|
d.race = Species::Human;
|
|
d.mission() = use("DEDefencePlatform", {"bal_gauss", "bal_gauss", "bal_gauss", "bal_gauss", "mis"});
|
|
return d;
|
|
}
|
|
|
|
Design cruiser() {
|
|
Design d;
|
|
d.name = "Cruiser";
|
|
d.race = Species::Human;
|
|
d.command() = use("CRCommand", {});
|
|
d.mission() = use("CRArmor", {});
|
|
d.engine() = use("CRFission", {});
|
|
return d;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST(hull_size_from_section_class) {
|
|
CHECK_EQ(hull_size(SectionClass::Destroyer), 0);
|
|
CHECK_EQ(hull_size(SectionClass::Cruiser), 1);
|
|
CHECK_EQ(hull_size(SectionClass::Dreadnought), 2);
|
|
// An absent or unrecognised class is a destroyer, not an error: the
|
|
// original's name lookup fails and leaves the field at zero.
|
|
CHECK_EQ(hull_size(SectionClass::None), 0);
|
|
CHECK_EQ(hull_size(SectionClass::Other), 0);
|
|
}
|
|
|
|
TEST(hull_class_of_a_stock_destroyer) {
|
|
HullClass h = classify_design(mini_catalog(), armor());
|
|
CHECK(h.ok());
|
|
CHECK_EQ(h.hull_size, 0);
|
|
CHECK(!h.defence_platform);
|
|
CHECK_EQ(h.resolved_sections, 3);
|
|
CHECK_EQ(h.unresolved_sections, 0);
|
|
}
|
|
|
|
TEST(hull_class_of_a_cruiser) {
|
|
HullClass h = classify_design(mini_catalog(), cruiser());
|
|
CHECK(h.ok());
|
|
CHECK_EQ(h.hull_size, 1);
|
|
CHECK(!h.defence_platform);
|
|
}
|
|
|
|
TEST(defence_platform_flag_is_read_from_the_section) {
|
|
const ShipSectionDef* s = mini_catalog().section("Human", "DEDefencePlatform");
|
|
CHECK(s != nullptr);
|
|
if (s) CHECK(s->defence_platform.value_or(false));
|
|
const ShipSectionDef* armorsec = mini_catalog().section("Human", "DEArmor");
|
|
CHECK(armorsec != nullptr);
|
|
if (armorsec) CHECK(!armorsec->defence_platform.value_or(false));
|
|
|
|
HullClass h = classify_design(mini_catalog(), platform());
|
|
CHECK(h.ok());
|
|
CHECK(h.defence_platform);
|
|
CHECK_EQ(h.hull_size, 0);
|
|
CHECK_EQ(h.resolved_sections, 1);
|
|
}
|
|
|
|
TEST(one_flagged_section_makes_the_whole_design_a_platform) {
|
|
// The flag word is OR-ed across sections, so a design that mixes a
|
|
// flagged section with unflagged ones is still a platform. No shipped
|
|
// design does this -- the platforms are all standalone mission sections --
|
|
// so this is the rule, tested where the data cannot show it.
|
|
Design d = armor();
|
|
d.mission() = use("DEDefencePlatform", {"bal_gauss", "bal_gauss", "bal_gauss", "bal_gauss", "mis"});
|
|
HullClass h = classify_design(mini_catalog(), d);
|
|
CHECK(h.defence_platform);
|
|
CHECK_EQ(h.resolved_sections, 3);
|
|
}
|
|
|
|
TEST(hull_size_takes_the_last_resolved_section) {
|
|
// Assignment in slot order, not first-wins and not max. Class-mixing is a
|
|
// rule A6 error, so this can only be shown on a design the validator
|
|
// rejects -- which is exactly why it is worth pinning.
|
|
Design d;
|
|
d.race = Species::Human;
|
|
d.command() = use("DECommand", {"bal_gauss"});
|
|
d.mission() = use("CRArmor", {});
|
|
HullClass h = classify_design(mini_catalog(), d);
|
|
CHECK_EQ(h.resolved_sections, 2);
|
|
CHECK_EQ(h.hull_size, 1); // the cruiser mission section, visited last
|
|
|
|
Design r;
|
|
r.race = Species::Human;
|
|
r.command() = use("CRCommand", {});
|
|
r.mission() = use("DEArmor", {"bal_gauss", "bal_gauss", "mis"});
|
|
CHECK_EQ(classify_design(mini_catalog(), r).hull_size, 0);
|
|
}
|
|
|
|
TEST(an_unresolvable_design_is_reported_not_counted_as_a_destroyer) {
|
|
Design d;
|
|
d.race = Species::Human;
|
|
d.mission() = use("NoSuchSection", {});
|
|
HullClass h = classify_design(mini_catalog(), d);
|
|
CHECK(!h.ok());
|
|
CHECK_EQ(h.resolved_sections, 0);
|
|
CHECK_EQ(h.unresolved_sections, 1);
|
|
}
|
|
|
|
TEST(derive_stats_carries_the_two_census_words) {
|
|
DesignStats st = derive_stats(mini_rules(), armor());
|
|
CHECK_EQ(st.hull_size, 0);
|
|
CHECK(!st.defence_platform);
|
|
|
|
DesignStats p = derive_stats(mini_rules(), platform());
|
|
CHECK_EQ(p.hull_size, 0);
|
|
CHECK(p.defence_platform);
|
|
|
|
DesignStats c = derive_stats(mini_rules(), cruiser());
|
|
CHECK_EQ(c.hull_size, 1);
|
|
CHECK_EQ(c.hull_class, "cruiser");
|
|
}
|
|
|
|
TEST(census_counts_ships_and_platforms_separately) {
|
|
ShipCensus c;
|
|
HullClass de; // destroyer ship
|
|
HullClass cr; cr.hull_size = 1; cr.resolved_sections = 1;
|
|
HullClass dn; dn.hull_size = 2; dn.resolved_sections = 1;
|
|
HullClass pl; pl.defence_platform = true; pl.resolved_sections = 1;
|
|
de.resolved_sections = 1;
|
|
|
|
c.add(de); c.add(de); c.add(cr); c.add(dn); c.add(pl); c.add(pl); c.add(pl);
|
|
CHECK_EQ(c.ships[0], 2);
|
|
CHECK_EQ(c.ships[1], 1);
|
|
CHECK_EQ(c.ships[2], 1);
|
|
CHECK_EQ(c.platforms[0], 3);
|
|
CHECK_EQ(c.platforms[1], 0);
|
|
CHECK_EQ(c.platforms[2], 0);
|
|
CHECK_EQ(c.ship_total(), 4);
|
|
CHECK_EQ(c.platform_total(), 3);
|
|
}
|