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).
101 lines
4 KiB
C++
101 lines
4 KiB
C++
#include "stock_designs.h"
|
|
|
|
#include <fstream>
|
|
#include <sstream>
|
|
|
|
#include "game/data/common.h"
|
|
#include "json_min.h"
|
|
|
|
using namespace game::design;
|
|
using json_min::Value;
|
|
|
|
namespace {
|
|
|
|
std::vector<std::string> strings(const Value& v) {
|
|
std::vector<std::string> out;
|
|
for (const Value& x : v.items)
|
|
if (x.is_string()) out.push_back(x.str());
|
|
return out;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
bool load_stock_designs(const std::string& path, std::vector<StockDesign>& out, std::string& err) {
|
|
std::ifstream in(path, std::ios::binary);
|
|
if (!in) {
|
|
err = "cannot read " + path;
|
|
return false;
|
|
}
|
|
std::ostringstream ss;
|
|
ss << in.rdbuf();
|
|
Value root;
|
|
if (!json_min::parse(ss.str(), root, err)) return false;
|
|
if (!root.is_array()) {
|
|
err = "expected a list of players";
|
|
return false;
|
|
}
|
|
int pi = 0;
|
|
for (const Value& player : root.items) {
|
|
int di = 0;
|
|
for (const Value& d : player["designs"].items) {
|
|
StockDesign sd;
|
|
sd.player_index = pi;
|
|
sd.design_index = di++;
|
|
sd.save = player["save"].str();
|
|
sd.player = player["player"].str();
|
|
sd.npc = player["npc"].as_bool();
|
|
sd.race_text = d["race"].str();
|
|
sd.list = d["list"].str();
|
|
Design& des = sd.design;
|
|
des.name = d["name"].str();
|
|
des.hidden = d["hidden"].as_bool();
|
|
des.designer_made = d["faiDes"].as_bool();
|
|
des.default_weapons = d["dWep"].as_int();
|
|
des.race = game::data::parse_species(sd.race_text);
|
|
if (!d["known_techs"].is_null()) des.known_techs = strings(d["known_techs"]);
|
|
// Three entries: command, mission, engine. Fixtures generated
|
|
// before the reference reader stopped sweeping the design's Dtc and
|
|
// Dwgv tail into the section list carry five, the last two empty;
|
|
// both are accepted so an old fixture still loads.
|
|
const Value& raw = d["raw_slots"];
|
|
if (!raw.is_array() || raw.items.size() < 3 ||
|
|
raw.items.size() > static_cast<std::size_t>(kSlotCount)) {
|
|
err = des.name + ": raw_slots must have 3 to " + std::to_string(kSlotCount) + " entries";
|
|
return false;
|
|
}
|
|
const int slots = static_cast<int>(raw.items.size());
|
|
for (int i = 0; i < slots; ++i) {
|
|
const Value& r = raw.items[static_cast<std::size_t>(i)];
|
|
SectionUse& u = des.slots[static_cast<std::size_t>(i)];
|
|
int species = r["species"].as_int();
|
|
u.section_id = r["section_id"].as_int();
|
|
if (species == 0 && u.section_id == 0) continue; // empty slot
|
|
u.species = static_cast<game::data::Species>(species);
|
|
const Value& weapons = r["weapons"];
|
|
const Value& riders = r["rider_design_ids"];
|
|
for (std::size_t w = 0; w < weapons.items.size(); ++w) {
|
|
const Value& x = weapons.items[w];
|
|
WeaponRef ref;
|
|
if (x.is_number()) ref = WeaponRef::by_id(x.as_int());
|
|
else if (x.is_string()) ref = WeaponRef::by_file(x.str());
|
|
if (w < riders.items.size()) ref.rider_design_id = riders.items[w].as_int();
|
|
u.weapons.push_back(ref);
|
|
}
|
|
u.options = strings(r["options"]);
|
|
if (i < 3) {
|
|
sd.dopts[static_cast<std::size_t>(i)] = u.options;
|
|
sd.bank_count[static_cast<std::size_t>(i)] = r["bank_count"].as_int();
|
|
}
|
|
}
|
|
for (std::size_t i = 0; i < 3; ++i) {
|
|
const Value& view = d[slot_name(kUsedSlots[i])];
|
|
if (view.is_null()) continue;
|
|
sd.expect_stem[i] = view["section"].str();
|
|
sd.expect_options[i] = strings(view["options"]);
|
|
}
|
|
out.push_back(std::move(sd));
|
|
}
|
|
++pi;
|
|
}
|
|
return true;
|
|
}
|