| 1859 | } |
| 1860 | |
| 1861 | void LoadLevel(LevelConversionData *levelConversionData) |
| 1862 | { |
| 1863 | char szName[MaxMpqPathSize]; |
| 1864 | std::optional<SaveReader> archive = OpenSaveArchive(gSaveNumber); |
| 1865 | GetTempLevelNames(szName); |
| 1866 | if (!archive || !archive->HasFile(szName)) |
| 1867 | GetPermLevelNames(szName); |
| 1868 | LoadHelper file(std::move(archive), szName); |
| 1869 | if (!file.IsValid()) |
| 1870 | app_fatal(_("Unable to open save file archive")); |
| 1871 | |
| 1872 | if (leveltype != DTYPE_TOWN) { |
| 1873 | for (int j = 0; j < MAXDUNY; j++) { |
| 1874 | for (int i = 0; i < MAXDUNX; i++) // NOLINT(modernize-loop-convert) |
| 1875 | dCorpse[i][j] = file.NextLE<int8_t>(); |
| 1876 | } |
| 1877 | MoveLightsToCorpses(); |
| 1878 | } |
| 1879 | |
| 1880 | ActiveMonsterCount = file.NextBE<int32_t>(); |
| 1881 | auto savedItemCount = file.NextBE<uint32_t>(); |
| 1882 | ActiveObjectCount = file.NextBE<int32_t>(); |
| 1883 | |
| 1884 | if (leveltype != DTYPE_TOWN) { |
| 1885 | for (int &monsterId : ActiveMonsters) |
| 1886 | monsterId = file.NextBE<int32_t>(); |
| 1887 | for (size_t i = 0; i < ActiveMonsterCount; i++) { |
| 1888 | Monster &monster = Monsters[ActiveMonsters[i]]; |
| 1889 | MonsterConversionData *monsterConversionData = nullptr; |
| 1890 | if (levelConversionData != nullptr) |
| 1891 | monsterConversionData = &levelConversionData->monsterConversionData[ActiveMonsters[i]]; |
| 1892 | LoadMonster(&file, monster, monsterConversionData); |
| 1893 | if (monster.isUnique() && monster.lightId != NO_LIGHT) |
| 1894 | Lights[monster.lightId].isInvalid = false; |
| 1895 | } |
| 1896 | if (!gbSkipSync) { |
| 1897 | for (size_t i = 0; i < ActiveMonsterCount; i++) |
| 1898 | SyncMonsterAnim(Monsters[ActiveMonsters[i]]); |
| 1899 | } |
| 1900 | for (int &objectId : ActiveObjects) |
| 1901 | objectId = file.NextLE<int8_t>(); |
| 1902 | for (int &objectId : AvailableObjects) |
| 1903 | objectId = file.NextLE<int8_t>(); |
| 1904 | for (int i = 0; i < ActiveObjectCount; i++) |
| 1905 | LoadObject(file, Objects[ActiveObjects[i]]); |
| 1906 | if (!gbSkipSync) { |
| 1907 | for (int i = 0; i < ActiveObjectCount; i++) |
| 1908 | SyncObjectAnim(Objects[ActiveObjects[i]]); |
| 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | LoadDroppedItems(file, savedItemCount); |
| 1913 | |
| 1914 | for (int j = 0; j < MAXDUNY; j++) { |
| 1915 | for (int i = 0; i < MAXDUNX; i++) // NOLINT(modernize-loop-convert) |
| 1916 | dFlags[i][j] = static_cast<DungeonFlag>(file.NextLE<uint8_t>()) & DungeonFlag::LoadedFlags; |
| 1917 | } |
| 1918 |
no test coverage detected