Repository navigation
Expand file tree
/
Copy pathgen_refineries.py
More file actions
109 lines (105 loc) · 5.64 KB
/
Copy pathgen_refineries.py
File metadata and controls
109 lines (105 loc) · 5.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import json, io, sys, datetime
# Generates include/RefineryData.h from scmdb's mining_data JSON (game data extract).
#
# The station bonuses are NOT in libs/foundry/records: the extracted DataCore
# has no refinery-profile record type. What says they are the game's own
# numbers is their shape: twenty stations share ten profiles, and every Pyro
# station shares one. Nobody measuring by hand lands on that. A material a
# profile does not mention is left as NONE, not as zero: "no modifier
# listed" is what the data says, and 0 % would be a claim the data does not
# make.
src = sys.argv[1]
out = sys.argv[2]
d = json.load(io.open(src, encoding="utf-8"))
profiles = d["refineryProfiles"]
stations = d["refineries"]
# Four ores are mined and refined but appear in no station profile at all;
# at the terminal, Ouratite refines like any other ore. A profile is a list
# of DEVIATIONS - a material no station deviates on has no entry anywhere -
# so these refine at the standard rate, which is what an absent entry means
# (Regolith carries an explicit +0 in all 60 places the extract leaves
# blank). They are listed so the shopping list can say something about them.
NO_PROFILE = ["Aslarite (Raw)", "Ouratite (Raw)", "Riccite (Ore)", "Stileron (Ore)"]
# What the terminal shows and the extract leaves out. MIC-L5's profile lists
# seven materials in scmdb's 4.10.0 and 4.10.2 extracts; the terminal there
# lists ten - these three on top - in every report UEX has of it (4.10.2,
# Lindinium "Last Yield 7 %, Avg Yield (30d) 7 %"). The other 377 numbers of
# UEX's table agree with the extract. A correction that finds the extract
# already carrying the material stops the script: then the extract caught up.
CORRECTIONS = {
"MIC-L5 Modern Icarus Station": {"Lindinium (Ore)": 7, "Savrilium (Ore)": 6, "Torite (Ore)": 8},
}
for station, fixes in CORRECTIONS.items():
pid = next(s["profileId"] for s in stations if s["name"] == station)
sharing = [s["name"] for s in stations if s["profileId"] == pid]
if sharing != [station]:
sys.exit("%s shares its profile with %s - a correction would move them too" % (station, sharing))
for material, value in fixes.items():
if material in profiles[pid]:
sys.exit("%s already has %s at %d - drop the correction" % (station, material, profiles[pid][material]))
profiles[pid][material] = value
mats = sorted({m for p in profiles.values() for m in p} | set(NO_PROFILE))
order = list(profiles.keys())
NONE = 127
lines = [
"#pragma once",
"// Refinery yields - GENERATED by gen_refineries.py, do not edit by hand.",
"// Source: scmdb mining_data extract, game build %s" % d.get("version", "?"),
"// Pulled %s: %d stations, %d profiles, %d materials." %
(datetime.date.today().isoformat(), len(stations), len(profiles), len(mats)),
"//",
"// Four of the materials are in no profile at all and stand at 0 %% "
"everywhere: they are mined and refined like the rest, and no station",
"// prefers them. A profile is a list of DEVIATIONS, so a material",
"// nobody deviates on has no entry to find.",
"//",
"// A station refines a material at a bonus or a penalty in percent. The",
"// number belongs to the station's PROFILE, and stations share profiles:",
"// every Pyro refinery runs the same one. REFINERY_NONE means the profile",
"// lists no modifier for that material - which is not the same as zero,",
"// and the window says so rather than printing a nought.",
"//",
"// Corrected where the terminal shows more than the extract (CORRECTIONS",
"// in the script): %s." % "; ".join(
"%s %s" % (station.split(" ")[0], ", ".join("%s %+d" % (m.split(" (")[0], v) for m, v in fixes.items()))
for station, fixes in CORRECTIONS.items()),
"#include <cstdint>",
"",
"namespace SCMiner {",
"",
"inline constexpr int REFINERY_MATERIAL_COUNT = %d;" % len(mats),
"inline constexpr int REFINERY_PROFILE_COUNT = %d;" % len(order),
"inline constexpr int REFINERY_COUNT = %d;" % len(stations),
"// no modifier listed for this material at this station",
"inline constexpr int8_t REFINERY_NONE = %d;" % NONE,
"",
"inline const char* const REFINERY_MATERIALS[] = {",
]
for m in mats:
lines.append(' "%s",' % m)
lines += ["};", "",
"// one row per profile, one column per material, in the order above",
"inline const int8_t REFINERY_YIELDS[REFINERY_PROFILE_COUNT][REFINERY_MATERIAL_COUNT] = {"]
for pid in order:
p = profiles[pid]
row = ", ".join(("%d" % p[m]) if m in p else "REFINERY_NONE" for m in mats)
lines.append(" {%s}, // %s" % (row, pid))
lines += ["};", "",
"struct Refinery {",
" const char* name;",
" const char* system;",
" int profile; // row in REFINERY_YIELDS",
"};", "",
"inline const Refinery REFINERIES[] = {"]
for s in sorted(stations, key=lambda s: (s["system"], s["name"])):
lines.append(' {"%s", "%s", %d},' % (s["name"], s["system"], order.index(s["profileId"])))
lines += ["};", "",
"// the modifier for a material at a station, or REFINERY_NONE",
"inline int refineryYield(int station, int material) {",
" if (station < 0 || station >= REFINERY_COUNT) return REFINERY_NONE;",
" if (material < 0 || material >= REFINERY_MATERIAL_COUNT) return REFINERY_NONE;",
" return REFINERY_YIELDS[REFINERIES[station].profile][material];",
"}", "",
"} // namespace SCMiner"]
io.open(out, "w", encoding="utf-8", newline="\n").write("\n".join(lines) + "\n")
print("%s: %d stations, %d profiles, %d materials" % (out, len(stations), len(order), len(mats)))