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).
88 lines
4 KiB
C++
88 lines
4 KiB
C++
// game::design -- hull size and the defence-platform class flag, and the
|
|
// per-hull-class ship census built from them.
|
|
//
|
|
// WHY THIS EXISTS
|
|
// ---------------
|
|
// The per-player turn record the game archives every turn carries six ship
|
|
// counts: ships by hull size 0/1/2, and *defence platforms* by hull size
|
|
// 0/1/2, written to the wire as three `cls` groups of `shpt` (ships total)
|
|
// and `satt` (satellites total). Neither the hull size nor the platform flag
|
|
// is on the wire anywhere -- both are recomputed from the section catalog
|
|
// whenever a design changes -- so the census cannot be reproduced from a save
|
|
// alone until a reader can classify a design the way the game does.
|
|
//
|
|
// HOW THE ORIGINAL DOES IT
|
|
// ------------------------
|
|
// A design caches two derived words that are recomputed by its stats pass:
|
|
//
|
|
// * a 64-bit role-flag word, the OR of every resolved section's own flag
|
|
// word. `defence_platform` is one bit of it (the low word's 0x400).
|
|
// * a hull-size ordinal, assigned -- not OR-ed, not max-ed -- from each
|
|
// resolved section's `section_class` in slot order, so the last resolved
|
|
// section wins. Every shipped design is class-homogeneous (rule A6), so
|
|
// first-wins and last-wins agree on all 503 design records in the save
|
|
// corpus; the assignment order is reproduced anyway because it is what
|
|
// the original does, and a hand-built mixed-class design would show it.
|
|
//
|
|
// The census then walks the fleets a player owns, and for every ship takes
|
|
// its design's two words: platform bit set -> the platform row, else the ship
|
|
// row; hull size picks the column.
|
|
//
|
|
// NOT THE SAME 0x400
|
|
// ------------------
|
|
// A *fleet* also carries a flag word whose 0x400 bit is set when the retreat
|
|
// pipeline creates a fleet, and it appears on the wire as `FtFlg`. It is a
|
|
// different word on a different object and has nothing to do with this one.
|
|
// Reusing the numeral is a coincidence of two bit layouts.
|
|
#pragma once
|
|
|
|
#include <array>
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
#include "game/data/catalog.h"
|
|
#include "game/data/shipsection.h"
|
|
#include "game/design/design.h"
|
|
|
|
namespace game::design {
|
|
|
|
// What the census needs to know about one design.
|
|
struct HullClass {
|
|
int hull_size = 0; // 0 destroyer, 1 cruiser, 2 dreadnought
|
|
bool defence_platform = false; // any resolved section carries the flag
|
|
int resolved_sections = 0; // sections that named a section the catalog holds
|
|
int unresolved_sections = 0; // named a section the catalog does not hold
|
|
|
|
// True when at least one section resolved. A design none of whose sections
|
|
// resolve is not classifiable and must not be silently counted as a
|
|
// destroyer: callers should treat it as a gap, not as class 0.
|
|
bool ok() const { return resolved_sections > 0; }
|
|
};
|
|
|
|
// Classify from already-resolved section definitions, in the design's slot
|
|
// order. Null entries are empty slots and are skipped.
|
|
HullClass classify_sections(const std::vector<const data::ShipSectionDef*>& sections);
|
|
|
|
// Classify a design record against a catalog. Slots are visited in
|
|
// command / mission / engine order; an empty slot is skipped, and a slot that
|
|
// names a section the catalog does not hold is counted in
|
|
// `unresolved_sections` and otherwise ignored.
|
|
HullClass classify_design(const data::Catalog& cat, const Design& d);
|
|
|
|
// Six counters: ships and defence platforms, each by hull size.
|
|
struct ShipCensus {
|
|
std::array<int, 3> ships{}; // designs WITHOUT the platform flag
|
|
std::array<int, 3> platforms{}; // designs WITH it
|
|
|
|
// The original also accumulates the two grand totals and then throws them
|
|
// away without storing them; they are kept here because they are free and
|
|
// because a test that checks only the six stored counters cannot tell a
|
|
// miscounted ship from an unclassified one.
|
|
int total_ships = 0, total_platforms = 0;
|
|
|
|
void add(const HullClass& h);
|
|
int ship_total() const { return total_ships; }
|
|
int platform_total() const { return total_platforms; }
|
|
};
|
|
|
|
} // namespace game::design
|