|
| 1 | +#include "EU5Location.h" |
| 2 | + |
| 3 | +EU5::Location::Location(int theLocationID, std::string theLocationName): locID(theLocationID), name(std::move(theLocationName)) |
| 4 | +{ |
| 5 | +} |
| 6 | + |
| 7 | +void EU5::Location::parseData(std::istream& theStream) |
| 8 | +{ |
| 9 | + registerKeys(); |
| 10 | + parseStream(theStream); |
| 11 | + clearRegisteredKeywords(); |
| 12 | +} |
| 13 | + |
| 14 | +void EU5::Location::registerKeys() |
| 15 | +{ |
| 16 | + registerKeyword("owner", [this](std::istream& theStream) { |
| 17 | + ownerID = commonItems::getInt(theStream); |
| 18 | + }); |
| 19 | + registerKeyword("controller", [this](std::istream& theStream) { |
| 20 | + controllerID = commonItems::getInt(theStream); |
| 21 | + }); |
| 22 | + registerKeyword("previous_owner", [this](std::istream& theStream) { |
| 23 | + previousOwnerID = commonItems::getInt(theStream); |
| 24 | + }); |
| 25 | + registerKeyword("previous_controller", [this](std::istream& theStream) { |
| 26 | + previousControllerID = commonItems::getInt(theStream); |
| 27 | + }); |
| 28 | + registerKeyword("development", [this](std::istream& theStream) { |
| 29 | + development = commonItems::getDouble(theStream); |
| 30 | + }); |
| 31 | + registerKeyword("prosperity", [this](std::istream& theStream) { |
| 32 | + prosperity = commonItems::getDouble(theStream); |
| 33 | + }); |
| 34 | + registerKeyword("language", [this](std::istream& theStream) { |
| 35 | + language = commonItems::getString(theStream); |
| 36 | + }); |
| 37 | + registerKeyword("dialect", [this](std::istream& theStream) { |
| 38 | + dialect = commonItems::getString(theStream); |
| 39 | + }); |
| 40 | + registerKeyword("rank", [this](std::istream& theStream) { |
| 41 | + rank = commonItems::getString(theStream); |
| 42 | + }); |
| 43 | + registerKeyword("original_rank", [this](std::istream& theStream) { |
| 44 | + originalRank = commonItems::getString(theStream); |
| 45 | + }); |
| 46 | + registerKeyword("raw_material", [this](std::istream& theStream) { |
| 47 | + rawMaterial = commonItems::getString(theStream); |
| 48 | + }); |
| 49 | + registerKeyword("cores", [this](std::istream& theStream) { |
| 50 | + const auto& cores = commonItems::getInts(theStream); |
| 51 | + countriesWithCore.insert(cores.begin(), cores.end()); |
| 52 | + }); |
| 53 | + |
| 54 | + registerKeyword("religion", [this](std::istream& theStream) { |
| 55 | + religionID = commonItems::getInt(theStream); |
| 56 | + }); |
| 57 | + registerKeyword("culture", [this](std::istream& theStream) { |
| 58 | + cultureID = commonItems::getInt(theStream); |
| 59 | + }); |
| 60 | + registerKeyword("secondary_culture", [this](std::istream& theStream) { |
| 61 | + secondaryCultureID = commonItems::getInt(theStream); |
| 62 | + }); |
| 63 | + registerKeyword("cultural_unity", [this](std::istream& theStream) { |
| 64 | + culturalUnity = commonItems::getDouble(theStream); |
| 65 | + }); |
| 66 | + |
| 67 | + registerKeyword("last_owner_change", [this](std::istream& theStream) { |
| 68 | + lastOwnerChange = date(commonItems::getString(theStream)); |
| 69 | + }); |
| 70 | + registerKeyword("last_controller_change", [this](std::istream& theStream) { |
| 71 | + lastControllerChange = date(commonItems::getString(theStream)); |
| 72 | + }); |
| 73 | + |
| 74 | + registerKeyword("max_raw_material_workers", [this](std::istream& theStream) { |
| 75 | + maxRawMaterialWorkers = commonItems::getInt(theStream); |
| 76 | + }); |
| 77 | + registerKeyword("control", [this](std::istream& theStream) { |
| 78 | + control = commonItems::getDouble(theStream); |
| 79 | + }); |
| 80 | + registerKeyword("cap_control", [this](std::istream& theStream) { |
| 81 | + capControl = commonItems::getString(theStream) == "yes"; |
| 82 | + }); |
| 83 | + registerKeyword("road_to_capital", [this](std::istream& theStream) { |
| 84 | + roadToCapital = commonItems::getString(theStream) == "yes"; |
| 85 | + }); |
| 86 | + registerKeyword("proximity", [this](std::istream& theStream) { |
| 87 | + proximity = commonItems::getDouble(theStream); |
| 88 | + }); |
| 89 | + registerKeyword("local_proximity_propagation", [this](std::istream& theStream) { |
| 90 | + localProximityPropagation = commonItems::getDouble(theStream); |
| 91 | + }); |
| 92 | + registerKeyword("value_flow", [this](std::istream& theStream) { |
| 93 | + valueFlow = commonItems::getDouble(theStream); |
| 94 | + }); |
| 95 | + |
| 96 | + registerKeyword("province", [this](std::istream& theStream) { |
| 97 | + provinceID = commonItems::getInt(theStream); |
| 98 | + }); |
| 99 | + registerKeyword("tax", [this](std::istream& theStream) { |
| 100 | + tax = commonItems::getDouble(theStream); |
| 101 | + }); |
| 102 | + registerKeyword("possible_tax", [this](std::istream& theStream) { |
| 103 | + possibleTax = commonItems::getDouble(theStream); |
| 104 | + }); |
| 105 | + registerKeyword("estate_tax", [this](std::istream& theStream) { |
| 106 | + for (const auto& [estate, value]: commonItems::assignments(theStream).getAssignments()) |
| 107 | + estateTax[estate].tax = commonItems::stringToDouble(value); |
| 108 | + }); |
| 109 | + registerKeyword("estate_possible_tax", [this](std::istream& theStream) { |
| 110 | + for (const auto& [estate, value]: commonItems::assignments(theStream).getAssignments()) |
| 111 | + estateTax[estate].possibleTax = commonItems::stringToDouble(value); |
| 112 | + }); |
| 113 | + registerKeyword("institutions", [this](std::istream& theStream) { |
| 114 | + for (const auto& [institution, spread]: commonItems::assignments(theStream).getAssignments()) |
| 115 | + institutions.emplace(institution, commonItems::stringToDouble(spread)); |
| 116 | + }); |
| 117 | + |
| 118 | + registerKeyword("units", [this](std::istream& theStream) { |
| 119 | + unitIDs = commonItems::getInts(theStream); |
| 120 | + }); |
| 121 | + registerKeyword("port", [this](std::istream& theStream) { |
| 122 | + portIDs = commonItems::getInts(theStream); |
| 123 | + }); |
| 124 | + // |
| 125 | + registerKeyword("population", [this](std::istream& theStream) { |
| 126 | + commonItems::parser parser; |
| 127 | + parser.registerKeyword("pops", [this](std::istream& popsStream) { |
| 128 | + popIDs = commonItems::getInts(popsStream); |
| 129 | + }); |
| 130 | + parser.registerRegex(commonItems::catchallRegex, commonItems::ignoreItem); |
| 131 | + parser.parseStream(theStream); |
| 132 | + }); |
| 133 | + |
| 134 | + registerKeyword("garrison", [this](std::istream& theStream) { |
| 135 | + garrison = commonItems::getDouble(theStream); |
| 136 | + }); |
| 137 | + registerKeyword("counters", [this](std::istream& theStream) { |
| 138 | + for (const auto& [counter, value]: commonItems::assignments(theStream).getAssignments()) |
| 139 | + counters.emplace(counter, commonItems::stringToInteger<int>(value)); |
| 140 | + }); |
| 141 | + |
| 142 | + registerKeyword("market", [this](std::istream& theStream) { |
| 143 | + marketID = commonItems::getInt(theStream); |
| 144 | + }); |
| 145 | + registerKeyword("second_best_market", [this](std::istream& theStream) { |
| 146 | + secondBestMarketID = commonItems::getInt(theStream); |
| 147 | + }); |
| 148 | + registerKeyword("market_parent", [this](std::istream& theStream) { |
| 149 | + marketParentID = commonItems::getInt(theStream); |
| 150 | + }); |
| 151 | + registerKeyword("market_access", [this](std::istream& theStream) { |
| 152 | + marketAccess = commonItems::getDouble(theStream); |
| 153 | + }); |
| 154 | + registerKeyword("market_attraction", [this](std::istream& theStream) { |
| 155 | + marketAttraction = commonItems::getDouble(theStream); |
| 156 | + }); |
| 157 | + registerKeyword("second_best_market_access", [this](std::istream& theStream) { |
| 158 | + secondBestMarketAccess = commonItems::getDouble(theStream); |
| 159 | + }); |
| 160 | + |
| 161 | + // wanted to organize with country as key in map rather than a list |
| 162 | + // not even sure how many we can see here, max i've seen is 2 so far |
| 163 | + registerKeyword("integration_data", [this](std::istream& theStream) { |
| 164 | + for (const auto& blob: commonItems::blobList(theStream).getBlobs()) |
| 165 | + { |
| 166 | + std::istringstream blobStream(blob); |
| 167 | + int owner = 0; |
| 168 | + Integration integration; |
| 169 | + commonItems::parser parser; |
| 170 | + parser.registerKeyword("integration", [&integration](std::istream& itemStream) { |
| 171 | + integration.type = commonItems::getString(itemStream); |
| 172 | + }); |
| 173 | + parser.registerKeyword("integration_progress", [&integration](std::istream& itemStream) { |
| 174 | + integration.progress = commonItems::getDouble(itemStream); |
| 175 | + }); |
| 176 | + parser.registerKeyword("integration_owner", [&owner](std::istream& itemStream) { |
| 177 | + owner = commonItems::getInt(itemStream); |
| 178 | + }); |
| 179 | + parser.registerRegex(commonItems::catchallRegex, commonItems::ignoreItem); |
| 180 | + parser.parseStream(blobStream); |
| 181 | + integrationData.emplace(owner, integration); |
| 182 | + } |
| 183 | + }); |
| 184 | + |
| 185 | + registerRegex(commonItems::catchallRegex, commonItems::ignoreItem); |
| 186 | +} |
0 commit comments