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

Method extractMapSectors

tools/extractors/extract_battlescape_map.cpp:258–770  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

256}
257
258std::map<UString, up<BattleMapSectorTiles>>
259InitialGameStateExtractor::extractMapSectors(GameState &state, const UString &mapRootName) const
260{
261 std::map<UString, up<BattleMapSectorTiles>> sectors;
262 UString map_prefix = "xcom3/maps/";
263 UString dirName = mapRootName;
264 UString tilePrefix = format("%s_", dirName);
265 bool baseMap = mapRootName == "37base";
266 BuildingDatStructure bdata;
267 {
268 auto fileName = dirName + UString("/building.dat");
269
270 auto datFileName = map_prefix + fileName;
271 auto inFile = fw().data->fs.open(datFileName);
272 if (!inFile)
273 {
274 LogError("Failed to open \"%s\"", fileName);
275 return {};
276 }
277
278 inFile.read((char *)&bdata, sizeof(bdata));
279 if (!inFile)
280 {
281 LogError("Failed to read entry in \"%s\"", fileName);
282 return {};
283 }
284 }
285 auto sdtFiles = fw().data->fs.enumerateDirectory(map_prefix + "/" + dirName, ".sdt");
286
287 int fileCounter = -1;
288 for (const auto &sdtFile : sdtFiles)
289 {
290 fileCounter++;
291 LogInfo("Reading map %s", sdtFile);
292 /* Trim off '.sdt' to get the base map name */
293 LogAssert(sdtFile.length() >= 4);
294 auto secName = sdtFile.substr(0, sdtFile.length() - 4);
295
296 auto sector = secName.substr(secName.length() - 2);
297
298 // We will make 16 total grounds
299 int groundCounter = 0;
300 do
301 {
302 UString tilesName;
303 if (baseMap)
304 {
305 if (fileCounter == 0)
306 {
307 tilesName = format("%s_%02d", dirName, groundCounter);
308 }
309 else
310 {
311 tilesName = format("%s_%02d", dirName, fileCounter + 15);
312 }
313 }
314 else
315 {

Callers 1

main.cppFile · 0.80

Calls 6

formatFunction · 0.85
openMethod · 0.80
readMethod · 0.80
enumerateDirectoryMethod · 0.80
endMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected