MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / extractResearch

Method extractResearch

tools/extractors/extract_research.cpp:10–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8{
9
10void InitialGameStateExtractor::extractResearch(GameState &state) const
11{
12 auto &data = this->ufo2p;
13 for (unsigned i = 0; i < data.research_data->count(); i++)
14 {
15 auto rdata = data.research_data->get(i);
16
17 auto r = mksp<ResearchTopic>();
18
19 r->name = data.research_names->get(i);
20 auto id = ResearchTopic::getPrefix() + canon_string(r->name);
21 r->description = data.research_descriptions->get(i);
22 r->ufopaedia_entry = "";
23 r->man_hours = rdata.skillHours;
24 r->man_hours_progress = 0;
25 switch (rdata.researchGroup)
26 {
27 case 0:
28 r->type = ResearchTopic::Type::BioChem;
29 break;
30 case 1:
31 r->type = ResearchTopic::Type::Physics;
32 break;
33 default:
34 LogError("Unexpected researchGroup 0x%02x for research item %s",
35 (unsigned)rdata.researchGroup, id);
36 }
37 switch (rdata.labSize)
38 {
39 case 0:
40 r->required_lab_size = ResearchTopic::LabSize::Small;
41 break;
42 case 1:
43 r->required_lab_size = ResearchTopic::LabSize::Large;
44 break;
45 default:
46 LogError("Unexpected labSize 0x%02x for research item %s", (unsigned)rdata.labSize,
47 id);
48 }
49 // FIXME: this assumed all listed techs are required, which is not true for some topics
50 // (It's possible that an unknown member in ResearchData marks this, or it's done
51 // in-code)
52 // This should be fixed up in the patch.
53
54 ResearchDependency dependency;
55 dependency.type = ResearchDependency::Type::All;
56
57 for (int pre = 0; pre < 3; pre++)
58 {
59
60 if (rdata.prereqTech[pre] != 0xffff)
61 {
62 auto prereqId = ResearchTopic::getPrefix() +
63 canon_string(data.research_names->get(rdata.prereqTech[pre]));
64 dependency.topics.emplace(StateRef<ResearchTopic>{&state, prereqId});
65 }
66 }
67

Callers 1

extractCommonMethod · 0.95

Calls 4

canon_stringFunction · 0.85
endMethod · 0.80
countMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected