|
13 | 13 | #include "player.h" |
14 | 14 | #include "quests.h" |
15 | 15 | #include "utils/endian_swap.hpp" |
| 16 | +#include "utils/log.hpp" |
16 | 17 |
|
17 | 18 | namespace devilution { |
18 | 19 |
|
@@ -200,33 +201,35 @@ void DrlgTPass3() |
200 | 201 | } |
201 | 202 | } |
202 | 203 |
|
203 | | - const TownConfig &config = GetTownRegistry().GetTown(GetTownRegistry().GetCurrentTown()); |
| 204 | + const std::string &townId = GetTownRegistry().GetCurrentTown(); |
| 205 | + if (!GetTownRegistry().HasTown(townId)) { |
| 206 | + LogError("DrlgTPass3: current town '{}' not registered", townId); |
| 207 | + return; |
| 208 | + } |
| 209 | + const TownConfig &config = GetTownRegistry().GetTown(townId); |
204 | 210 | for (const auto §or : config.sectors) { |
205 | 211 | FillSector(sector.filePath.c_str(), sector.x, sector.y); |
206 | 212 | } |
207 | 213 |
|
208 | | - if (GetTownRegistry().GetCurrentTown() == "tristram") { |
| 214 | + for (const TownWarpPatch &patch : config.warpClosedPatches) { |
| 215 | + if (IsWarpOpen(patch.requiredWarp)) |
| 216 | + continue; |
| 217 | + for (const auto &[pos, cellVal] : patch.dungeonCells) |
| 218 | + dungeon[pos.x][pos.y] = static_cast<uint8_t>(cellVal); |
| 219 | + for (const TownWarpFillTile &ft : patch.fillTiles) |
| 220 | + FillTile(ft.x, ft.y, ft.tile); |
| 221 | + if (patch.randomGroundStrip.has_value()) { |
| 222 | + const TownWarpClosedRandomGroundStrip &strip = *patch.randomGroundStrip; |
| 223 | + for (int x = strip.xStart; x < strip.xEndExclusive; x++) { |
| 224 | + FillTile(x, strip.y, PickRandomlyAmong({ 1, 2, 3, 4 })); |
| 225 | + } |
| 226 | + } |
| 227 | + } |
| 228 | + |
| 229 | + if (townId == TristramTownId) { |
209 | 230 | auto dunData = LoadFileInMem<uint16_t>("levels\\towndata\\automap.dun"); |
210 | 231 | PlaceDunTiles(dunData.get(), { 0, 0 }); |
211 | 232 |
|
212 | | - if (!IsWarpOpen(DTYPE_CATACOMBS)) { |
213 | | - dungeon[20][7] = 10; |
214 | | - dungeon[20][6] = 8; |
215 | | - FillTile(48, 20, 320); |
216 | | - } |
217 | | - if (!IsWarpOpen(DTYPE_CAVES)) { |
218 | | - dungeon[4][30] = 8; |
219 | | - FillTile(16, 68, 332); |
220 | | - FillTile(16, 70, 331); |
221 | | - } |
222 | | - if (!IsWarpOpen(DTYPE_HELL)) { |
223 | | - dungeon[15][35] = 7; |
224 | | - dungeon[16][35] = 7; |
225 | | - dungeon[17][35] = 7; |
226 | | - for (int x = 36; x < 46; x++) { |
227 | | - FillTile(x, 78, PickRandomlyAmong({ 1, 2, 3, 4 })); |
228 | | - } |
229 | | - } |
230 | 233 | if (gbIsHellfire) { |
231 | 234 | if (IsWarpOpen(DTYPE_NEST)) { |
232 | 235 | TownOpenHive(); |
@@ -361,7 +364,12 @@ void CleanTownFountain() |
361 | 364 |
|
362 | 365 | void CreateTown(lvl_entry entry) |
363 | 366 | { |
364 | | - const TownConfig &config = GetTownRegistry().GetTown(GetTownRegistry().GetCurrentTown()); |
| 367 | + const std::string &townId = GetTownRegistry().GetCurrentTown(); |
| 368 | + if (!GetTownRegistry().HasTown(townId)) { |
| 369 | + LogError("CreateTown: current town '{}' not registered", townId); |
| 370 | + return; |
| 371 | + } |
| 372 | + const TownConfig &config = GetTownRegistry().GetTown(townId); |
365 | 373 | dminPosition = config.dminPosition; |
366 | 374 | dmaxPosition = config.dmaxPosition; |
367 | 375 | ViewPosition = config.GetEntryPoint(entry, TWarpFrom); |
|
0 commit comments