Browse Source

Clean up level initialization

pull/4717/head
Anders Jenbo 4 years ago
parent
commit
6fa681e567
  1. 138
      Source/drlg_l1.cpp
  2. 92
      Source/drlg_l2.cpp
  3. 88
      Source/drlg_l3.cpp
  4. 75
      Source/drlg_l4.cpp
  5. 28
      Source/gendung.cpp
  6. 3
      Source/gendung.h
  7. 1
      Source/setmaps.cpp
  8. 88
      Source/town.cpp

138
Source/drlg_l1.cpp

@ -804,11 +804,6 @@ void LoadQuestSetPieces()
} }
} }
void FreeQuestSetPieces()
{
pSetPiece = nullptr;
}
void InitDungeonPieces() void InitDungeonPieces()
{ {
for (int j = 0; j < MAXDUNY; j++) { for (int j = 0; j < MAXDUNY; j++) {
@ -1497,16 +1492,6 @@ Point SelectChamber()
} }
} }
void SetSetPieceRoom()
{
if (pSetPiece == nullptr)
return;
Point position = SelectChamber();
PlaceDunTiles(pSetPiece.get(), position, Tile::Floor);
SetPiece = { position, { SDL_SwapLE16(pSetPiece[0]), SDL_SwapLE16(pSetPiece[1]) } };
}
void SetCryptRoom() void SetCryptRoom()
{ {
Point position = SelectChamber(); Point position = SelectChamber();
@ -1586,8 +1571,8 @@ void FillChambers()
} else if (currlevel == 21) { } else if (currlevel == 21) {
SetCornerRoom(); SetCornerRoom();
} }
} else { } else if (pSetPiece != nullptr) {
SetSetPieceRoom(); SetSetPieceRoom(SelectChamber(), Tile::Floor);
} }
} }
@ -1910,6 +1895,8 @@ void GenerateLevel(lvl_entry entry)
break; break;
} }
LoadQuestSetPieces();
while (true) { while (true) {
DRLG_InitTrans(); DRLG_InitTrans();
@ -1928,6 +1915,8 @@ void GenerateLevel(lvl_entry entry)
break; break;
} }
FreeQuestSetPieces();
for (int j = 0; j < DMAXY; j++) { for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) { for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == Tile::EntranceStairs) { if (dungeon[i][j] == Tile::EntranceStairs) {
@ -2005,117 +1994,80 @@ void GenerateLevel(lvl_entry entry)
FillFloor(); FillFloor();
} }
for (int j = 0; j < DMAXY; j++) { memcpy(pdungeon, dungeon, sizeof(pdungeon));
for (int i = 0; i < DMAXX; i++) {
pdungeon[i][j] = dungeon[i][j];
}
}
DRLG_Init_Globals();
DRLG_CheckQuests(SetPiece.position); DRLG_CheckQuests(SetPiece.position);
} }
void Pass3() void Pass3()
{ {
DRLG_LPass3(22 - 1); DRLG_LPass3(22 - 1);
if (leveltype == DTYPE_CRYPT)
InitCryptPieces();
else
InitDungeonPieces();
} }
} // namespace } // namespace
void LoadL1Dungeon(const char *path, int vx, int vy) void CreateL5Dungeon(uint32_t rseed, lvl_entry entry)
{ {
dminPosition = { 16, 16 }; SetRndSeed(rseed);
dmaxPosition = { 96, 96 };
DRLG_InitTrans();
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
dungeon[i][j] = 22;
Protected[i][j] = false;
}
}
auto dunData = LoadFileInMem<uint16_t>(path);
PlaceDunTiles(dunData.get(), { 0, 0 }, Tile::Floor);
FillFloor(); UberRow = 0;
UberCol = 0;
ViewPosition = { vx, vy }; GenerateLevel(entry);
Pass3(); Pass3();
DRLG_Init_Globals();
if (leveltype != DTYPE_CRYPT)
InitDungeonPieces();
SetMapMonsters(dunData.get(), Point(0, 0).megaToWorld()); if (leveltype == DTYPE_CRYPT) {
SetMapObjects(dunData.get(), 0, 0); for (int j = dminPosition.y; j < dmaxPosition.y; j++) {
for (int i = dminPosition.x; i < dmaxPosition.x; i++) {
if (dPiece[i][j] == 290) {
UberRow = i;
UberCol = j;
}
if (dPiece[i][j] == 317) {
CornerStone.position = { i, j };
}
}
}
}
} }
void LoadPreL1Dungeon(const char *path) void LoadPreL1Dungeon(const char *path)
{ {
for (int j = 0; j < DMAXY; j++) { memset(dungeon, 22, sizeof(dungeon));
for (int i = 0; i < DMAXX; i++) {
dungeon[i][j] = 22;
Protected[i][j] = false;
}
}
dminPosition = { 16, 16 };
dmaxPosition = { 96, 96 };
auto dunData = LoadFileInMem<uint16_t>(path); auto dunData = LoadFileInMem<uint16_t>(path);
PlaceDunTiles(dunData.get(), { 0, 0 }, Tile::Floor); PlaceDunTiles(dunData.get(), { 0, 0 }, Tile::Floor);
FillFloor(); if (leveltype == DTYPE_CATHEDRAL)
FillFloor();
for (int j = 0; j < DMAXY; j++) { memcpy(pdungeon, dungeon, sizeof(pdungeon));
for (int i = 0; i < DMAXX; i++) {
pdungeon[i][j] = dungeon[i][j];
}
}
} }
void CreateL5Dungeon(uint32_t rseed, lvl_entry entry) void LoadL1Dungeon(const char *path, int vx, int vy)
{ {
SetRndSeed(rseed); ViewPosition = { vx, vy };
dminPosition = { 16, 16 }; DRLG_Init_Globals();
dmaxPosition = { 96, 96 };
UberRow = 0; memset(dungeon, 22, sizeof(dungeon));
UberCol = 0;
IsUberRoomOpened = false;
IsUberLeverActivated = false;
UberDiabloMonsterIndex = 0;
DRLG_InitTrans(); auto dunData = LoadFileInMem<uint16_t>(path);
DRLG_InitSetPC(); PlaceDunTiles(dunData.get(), { 0, 0 }, Tile::Floor);
LoadQuestSetPieces();
GenerateLevel(entry);
Pass3();
FreeQuestSetPieces();
if (leveltype == DTYPE_CRYPT) { if (leveltype == DTYPE_CATHEDRAL)
InitCryptPieces(); FillFloor();
} else {
InitDungeonPieces();
}
DRLG_SetPC(); Pass3();
for (int j = dminPosition.y; j < dmaxPosition.y; j++) { SetMapMonsters(dunData.get(), Point(0, 0).megaToWorld());
for (int i = dminPosition.x; i < dmaxPosition.x; i++) { SetMapObjects(dunData.get(), 0, 0);
if (dPiece[i][j] == 290) {
UberRow = i;
UberCol = j;
}
if (dPiece[i][j] == 317) {
CornerStone.position = { i, j };
}
}
}
} }
} // namespace devilution } // namespace devilution

92
Source/drlg_l2.cpp

@ -1613,11 +1613,6 @@ void LoadQuestSetPieces()
} }
} }
void FreeQuestSetPieces()
{
pSetPiece = nullptr;
}
void InitDungeonPieces() void InitDungeonPieces()
{ {
for (int j = 0; j < MAXDUNY; j++) { for (int j = 0; j < MAXDUNY; j++) {
@ -2713,6 +2708,8 @@ bool PlaceStairs(lvl_entry entry)
void GenerateLevel(lvl_entry entry) void GenerateLevel(lvl_entry entry)
{ {
LoadQuestSetPieces();
while (true) { while (true) {
nRoomCnt = 0; nRoomCnt = 0;
InitDungeonFlags(); InitDungeonFlags();
@ -2721,16 +2718,15 @@ void GenerateLevel(lvl_entry entry)
continue; continue;
} }
FixTilesPatterns(); FixTilesPatterns();
if (pSetPiece != nullptr) { SetSetPieceRoom(SetPieceRoom.position, 3);
PlaceDunTiles(pSetPiece.get(), SetPieceRoom.position, 3);
SetPiece = { SetPieceRoom.position, { SDL_SwapLE16(pSetPiece[0]), SDL_SwapLE16(pSetPiece[1]) } };
}
FloodTransparencyValues(3); FloodTransparencyValues(3);
FixTransparency(); FixTransparency();
if (PlaceStairs(entry)) if (PlaceStairs(entry))
break; break;
} }
FreeQuestSetPieces();
FixLockout(); FixLockout();
FixDoors(); FixDoors();
FixDirtTiles(); FixDirtTiles();
@ -2847,88 +2843,54 @@ void GenerateLevel(lvl_entry entry)
Substitution(); Substitution();
ApplyShadowsPatterns(); ApplyShadowsPatterns();
for (int j = 0; j < DMAXY; j++) { memcpy(pdungeon, dungeon, sizeof(pdungeon));
for (int i = 0; i < DMAXX; i++) {
pdungeon[i][j] = dungeon[i][j];
}
}
DRLG_Init_Globals();
DRLG_CheckQuests(SetPieceRoom.position); DRLG_CheckQuests(SetPieceRoom.position);
} }
void LoadDungeonData(const uint16_t *dunData)
{
InitDungeonFlags();
DRLG_InitTrans();
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
dungeon[i][j] = 12;
}
}
PlaceDunTiles(dunData, { 0, 0 }, 3);
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) { // NOLINT(modernize-loop-convert)
if (dungeon[i][j] == 0) {
dungeon[i][j] = 12;
}
}
}
}
void Pass3() void Pass3()
{ {
DRLG_LPass3(12 - 1); DRLG_LPass3(12 - 1);
InitDungeonPieces();
} }
} // namespace } // namespace
void LoadL2Dungeon(const char *path, int vx, int vy) void CreateL2Dungeon(uint32_t rseed, lvl_entry entry)
{ {
auto dunData = LoadFileInMem<uint16_t>(path); SetRndSeed(rseed);
LoadDungeonData(dunData.get());
Pass3();
DRLG_Init_Globals();
InitDungeonPieces();
ViewPosition = { vx, vy }; GenerateLevel(entry);
SetMapMonsters(dunData.get(), Point(0, 0).megaToWorld()); Pass3();
SetMapObjects(dunData.get(), 0, 0);
} }
void LoadPreL2Dungeon(const char *path) void LoadPreL2Dungeon(const char *path)
{ {
memset(dungeon, 12, sizeof(dungeon));
auto dunData = LoadFileInMem<uint16_t>(path); auto dunData = LoadFileInMem<uint16_t>(path);
LoadDungeonData(dunData.get()); PlaceDunTiles(dunData.get(), { 0, 0 }, 3);
for (int j = 0; j < DMAXY; j++) { memcpy(pdungeon, dungeon, sizeof(pdungeon));
for (int i = 0; i < DMAXX; i++) {
pdungeon[i][j] = dungeon[i][j];
}
}
} }
void CreateL2Dungeon(uint32_t rseed, lvl_entry entry) void LoadL2Dungeon(const char *path, int vx, int vy)
{ {
SetRndSeed(rseed); ViewPosition = { vx, vy };
dminPosition = { 16, 16 }; DRLG_Init_Globals();
dmaxPosition = { 96, 96 };
memset(dungeon, 12, sizeof(dungeon));
auto dunData = LoadFileInMem<uint16_t>(path);
PlaceDunTiles(dunData.get(), { 0, 0 }, 3);
DRLG_InitTrans();
DRLG_InitSetPC();
LoadQuestSetPieces();
GenerateLevel(entry);
Pass3(); Pass3();
FreeQuestSetPieces();
InitDungeonPieces(); SetMapMonsters(dunData.get(), Point(0, 0).megaToWorld());
DRLG_SetPC(); SetMapObjects(dunData.get(), 0, 0);
} }
} // namespace devilution } // namespace devilution

88
Source/drlg_l3.cpp

@ -1831,11 +1831,16 @@ void Fence()
FenceDoorFix(); FenceDoorFix();
} }
void LoadQuestSetPieces()
{
if (Quests[Q_ANVIL].IsAvailable())
pSetPiece = LoadFileInMem<uint16_t>("Levels\\L3Data\\Anvil.DUN");
}
bool PlaceAnvil() bool PlaceAnvil()
{ {
auto dunData = LoadFileInMem<uint16_t>("Levels\\L3Data\\Anvil.DUN"); int width = SDL_SwapLE16(pSetPiece[0]);
int width = SDL_SwapLE16(dunData[0]); int height = SDL_SwapLE16(pSetPiece[1]);
int height = SDL_SwapLE16(dunData[1]);
int sx = GenerateRnd(DMAXX - width - 2); int sx = GenerateRnd(DMAXX - width - 2);
int sy = GenerateRnd(DMAXY - height - 2); int sy = GenerateRnd(DMAXY - height - 2);
@ -1866,6 +1871,7 @@ bool PlaceAnvil()
break; break;
} }
PlaceDunTiles(pSetPiece.get(), { sx + 1, sy + 1 }, 7);
SetPiece = { { sx, sy }, { width + 2, height + 2 } }; SetPiece = { { sx, sy }, { width + 2, height + 2 } };
for (int yy = 0; yy < SetPiece.size.width; yy++) { for (int yy = 0; yy < SetPiece.size.width; yy++) {
@ -1874,8 +1880,6 @@ bool PlaceAnvil()
} }
} }
PlaceDunTiles(dunData.get(), { sx + 1, sy + 1 }, 7);
// Hack to avoid rivers entering the island, reversed later // Hack to avoid rivers entering the island, reversed later
dungeon[SetPiece.position.x + 7][SetPiece.position.y + 5] = 2; dungeon[SetPiece.position.x + 7][SetPiece.position.y + 5] = 2;
dungeon[SetPiece.position.x + 8][SetPiece.position.y + 5] = 2; dungeon[SetPiece.position.x + 8][SetPiece.position.y + 5] = 2;
@ -2030,6 +2034,8 @@ bool PlaceStairs(lvl_entry entry)
void GenerateLevel(lvl_entry entry) void GenerateLevel(lvl_entry entry)
{ {
LoadQuestSetPieces();
while (true) { while (true) {
InitDungeonFlags(); InitDungeonFlags();
int x1 = GenerateRnd(20) + 10; int x1 = GenerateRnd(20) + 10;
@ -2064,6 +2070,8 @@ void GenerateLevel(lvl_entry entry)
break; break;
} }
FreeQuestSetPieces();
if (leveltype == DTYPE_NEST) { if (leveltype == DTYPE_NEST) {
PlaceMiniSetRandom(L6ISLE1, 70); PlaceMiniSetRandom(L6ISLE1, 70);
PlaceMiniSetRandom(L6ISLE2, 70); PlaceMiniSetRandom(L6ISLE2, 70);
@ -2175,13 +2183,7 @@ void GenerateLevel(lvl_entry entry)
PlaceMiniSetRandom1x1(10, 110, 25); PlaceMiniSetRandom1x1(10, 110, 25);
} }
for (int j = 0; j < DMAXY; j++) { memcpy(pdungeon, dungeon, sizeof(pdungeon));
for (int i = 0; i < DMAXX; i++) {
pdungeon[i][j] = dungeon[i][j];
}
}
DRLG_Init_Globals();
} }
void Pass3() void Pass3()
@ -2232,74 +2234,38 @@ void CreateL3Dungeon(uint32_t rseed, lvl_entry entry)
{ {
SetRndSeed(rseed); SetRndSeed(rseed);
dminPosition = { 16, 16 };
dmaxPosition = { 96, 96 };
DRLG_InitTrans();
DRLG_InitSetPC();
GenerateLevel(entry); GenerateLevel(entry);
Pass3(); Pass3();
PlaceLights(); PlaceLights();
DRLG_SetPC();
} }
void LoadL3Dungeon(const char *path, int vx, int vy) void LoadPreL3Dungeon(const char *path)
{ {
dminPosition = { 16, 16 }; memset(dungeon, 8, sizeof(dungeon));
dmaxPosition = { 96, 96 };
InitDungeonFlags();
DRLG_InitTrans();
auto dunData = LoadFileInMem<uint16_t>(path); auto dunData = LoadFileInMem<uint16_t>(path);
PlaceDunTiles(dunData.get(), { 0, 0 }, 7); PlaceDunTiles(dunData.get(), { 0, 0 }, 7);
for (int j = 0; j < DMAXY; j++) { memcpy(pdungeon, dungeon, sizeof(pdungeon));
for (int i = 0; i < DMAXX; i++) { // NOLINT(modernize-loop-convert) }
if (dungeon[i][j] == 0) {
dungeon[i][j] = 8;
}
}
}
Pass3();
DRLG_Init_Globals();
void LoadL3Dungeon(const char *path, int vx, int vy)
{
ViewPosition = { vx, vy }; ViewPosition = { vx, vy };
SetMapMonsters(dunData.get(), Point(0, 0).megaToWorld()); DRLG_Init_Globals();
SetMapObjects(dunData.get(), 0, 0);
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) {
if (dPiece[i][j] >= 56 && dPiece[i][j] <= 147) {
DoLighting({ i, j }, 7, -1);
} else if (dPiece[i][j] >= 154 && dPiece[i][j] <= 161) {
DoLighting({ i, j }, 7, -1);
} else if (IsAnyOf(dPiece[i][j], 150, 152)) {
DoLighting({ i, j }, 7, -1);
}
}
}
}
void LoadPreL3Dungeon(const char *path) memset(dungeon, 8, sizeof(dungeon));
{
InitDungeonFlags();
DRLG_InitTrans();
auto dunData = LoadFileInMem<uint16_t>(path); auto dunData = LoadFileInMem<uint16_t>(path);
PlaceDunTiles(dunData.get(), { 0, 0 }, 7); PlaceDunTiles(dunData.get(), { 0, 0 }, 7);
for (int j = 0; j < DMAXY; j++) { Pass3();
for (int i = 0; i < DMAXX; i++) { // NOLINT(modernize-loop-convert) PlaceLights();
if (dungeon[i][j] == 0) {
dungeon[i][j] = 8;
}
}
}
memcpy(pdungeon, dungeon, sizeof(pdungeon)); SetMapMonsters(dunData.get(), Point(0, 0).megaToWorld());
SetMapObjects(dunData.get(), 0, 0);
} }
} // namespace devilution } // namespace devilution

75
Source/drlg_l4.cpp

@ -168,11 +168,6 @@ void LoadQuestSetPieces()
} }
} }
void FreeQuestSetPieces()
{
pSetPiece = nullptr;
}
void InitDungeonFlags() void InitDungeonFlags()
{ {
memset(dung, 0, sizeof(dung)); memset(dung, 0, sizeof(dung));
@ -312,16 +307,6 @@ void FirstRoom()
GenerateRoom(x, y, w, h, GenerateRnd(2)); GenerateRoom(x, y, w, h, GenerateRnd(2));
} }
void SetSetPieceRoom(Point position)
{
if (pSetPiece == nullptr)
return;
SetPiece = { position, { SDL_SwapLE16(pSetPiece[0]), SDL_SwapLE16(pSetPiece[1]) } };
PlaceDunTiles(pSetPiece.get(), position, 6);
}
void MakeDungeon() void MakeDungeon()
{ {
for (int j = 0; j < 20; j++) { for (int j = 0; j < 20; j++) {
@ -1211,6 +1196,8 @@ bool PlaceStairs(lvl_entry entry)
void GenerateLevel(lvl_entry entry) void GenerateLevel(lvl_entry entry)
{ {
LoadQuestSetPieces();
while (true) { while (true) {
DRLG_InitTrans(); DRLG_InitTrans();
@ -1238,7 +1225,7 @@ void GenerateLevel(lvl_entry entry)
AddWall(); AddWall();
FloodTransparencyValues(6); FloodTransparencyValues(6);
FixTransparency(); FixTransparency();
SetSetPieceRoom(SetPieceRoom.position); SetSetPieceRoom(SetPieceRoom.position, 6);
if (currlevel == 16) { if (currlevel == 16) {
LoadDiabQuads(true); LoadDiabQuads(true);
} }
@ -1246,6 +1233,8 @@ void GenerateLevel(lvl_entry entry)
break; break;
} }
FreeQuestSetPieces();
GeneralFix(); GeneralFix();
if (currlevel != 16) { if (currlevel != 16) {
@ -1255,15 +1244,8 @@ void GenerateLevel(lvl_entry entry)
ApplyShadowsPatterns(); ApplyShadowsPatterns();
FixCornerTiles(); FixCornerTiles();
Substitution(); Substitution();
DRLG_Init_Globals();
if (Quests[Q_WARLORD].IsAvailable()) { memcpy(pdungeon, dungeon, sizeof(pdungeon));
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
pdungeon[i][j] = dungeon[i][j];
}
}
}
DRLG_CheckQuests(SetPieceRoom.position); DRLG_CheckQuests(SetPieceRoom.position);
@ -1281,11 +1263,6 @@ void GenerateLevel(lvl_entry entry)
} }
} }
if (currlevel == 16) { if (currlevel == 16) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
pdungeon[i][j] = dungeon[i][j];
}
}
LoadDiabQuads(false); LoadDiabQuads(false);
} }
} }
@ -1301,48 +1278,36 @@ void CreateL4Dungeon(uint32_t rseed, lvl_entry entry)
{ {
SetRndSeed(rseed); SetRndSeed(rseed);
dminPosition = Point(0, 0).megaToWorld();
dmaxPosition = Point(40, 40).megaToWorld();
ViewPosition = { 40, 40 };
DRLG_InitSetPC();
LoadQuestSetPieces();
GenerateLevel(entry); GenerateLevel(entry);
Pass3(); Pass3();
FreeQuestSetPieces();
DRLG_SetPC();
} }
void LoadL4Dungeon(const char *path, int vx, int vy) void LoadPreL4Dungeon(const char *path)
{ {
dminPosition = Point(0, 0).megaToWorld(); memset(dungeon, 30, sizeof(dungeon));
dmaxPosition = Point(40, 40).megaToWorld();
DRLG_InitTrans();
InitDungeonFlags();
auto dunData = LoadFileInMem<uint16_t>(path); auto dunData = LoadFileInMem<uint16_t>(path);
PlaceDunTiles(dunData.get(), { 0, 0 }, 6); PlaceDunTiles(dunData.get(), { 0, 0 }, 6);
ViewPosition = { vx, vy }; memcpy(pdungeon, dungeon, sizeof(pdungeon));
Pass3();
DRLG_Init_Globals();
SetMapMonsters(dunData.get(), Point(0, 0).megaToWorld());
SetMapObjects(dunData.get(), 0, 0);
} }
void LoadPreL4Dungeon(const char *path) void LoadL4Dungeon(const char *path, int vx, int vy)
{ {
dminPosition = Point(0, 0).megaToWorld(); ViewPosition = { vx, vy };
dmaxPosition = Point(40, 40).megaToWorld();
DRLG_Init_Globals();
InitDungeonFlags(); memset(dungeon, 30, sizeof(dungeon));
auto dunData = LoadFileInMem<uint16_t>(path); auto dunData = LoadFileInMem<uint16_t>(path);
PlaceDunTiles(dunData.get(), { 0, 0 }, 6); PlaceDunTiles(dunData.get(), { 0, 0 }, 6);
Pass3();
SetMapMonsters(dunData.get(), Point(0, 0).megaToWorld());
SetMapObjects(dunData.get(), 0, 0);
} }
} // namespace devilution } // namespace devilution

28
Source/gendung.cpp

@ -397,6 +397,8 @@ dungeon_type GetLevelType(int level)
void CreateDungeon(uint32_t rseed, lvl_entry entry) void CreateDungeon(uint32_t rseed, lvl_entry entry)
{ {
DRLG_Init_Globals();
switch (leveltype) { switch (leveltype) {
case DTYPE_TOWN: case DTYPE_TOWN:
CreateTown(entry); CreateTown(entry);
@ -418,6 +420,8 @@ void CreateDungeon(uint32_t rseed, lvl_entry entry)
default: default:
app_fatal("Invalid level type"); app_fatal("Invalid level type");
} }
Make_SetPC(SetPiece);
} }
void FillSolidBlockTbls() void FillSolidBlockTbls()
@ -511,11 +515,6 @@ void DRLG_InitSetPC()
SetPiece = { { 0, 0 }, { 0, 0 } }; SetPiece = { { 0, 0 }, { 0, 0 } };
} }
void DRLG_SetPC()
{
Make_SetPC(SetPiece);
}
void Make_SetPC(Rectangle area) void Make_SetPC(Rectangle area)
{ {
Point position = area.position.megaToWorld(); Point position = area.position.megaToWorld();
@ -641,6 +640,20 @@ void DRLG_HoldThemeRooms()
} }
} }
void SetSetPieceRoom(Point position, int floorId)
{
if (pSetPiece == nullptr)
return;
PlaceDunTiles(pSetPiece.get(), position, floorId);
SetPiece = { position, { SDL_SwapLE16(pSetPiece[0]), SDL_SwapLE16(pSetPiece[1]) } };
}
void FreeQuestSetPieces()
{
pSetPiece = nullptr;
}
void DRLG_LPass3(int lv) void DRLG_LPass3(int lv)
{ {
{ {
@ -689,6 +702,9 @@ void DRLG_LPass3(int lv)
void DRLG_Init_Globals() void DRLG_Init_Globals()
{ {
dminPosition = Point(0, 0).megaToWorld();
dmaxPosition = Point(40, 40).megaToWorld();
memset(dItem, 0, sizeof(dItem));
memset(dFlags, 0, sizeof(dFlags)); memset(dFlags, 0, sizeof(dFlags));
memset(dPlayer, 0, sizeof(dPlayer)); memset(dPlayer, 0, sizeof(dPlayer));
memset(dMonster, 0, sizeof(dMonster)); memset(dMonster, 0, sizeof(dMonster));
@ -697,6 +713,8 @@ void DRLG_Init_Globals()
memset(dSpecial, 0, sizeof(dSpecial)); memset(dSpecial, 0, sizeof(dSpecial));
int8_t c = DisableLighting ? 0 : 15; int8_t c = DisableLighting ? 0 : 15;
memset(dLight, c, sizeof(dLight)); memset(dLight, c, sizeof(dLight));
DRLG_InitTrans();
DRLG_InitSetPC();
} }
bool SkipThemeRoom(int x, int y) bool SkipThemeRoom(int x, int y)

3
Source/gendung.h

@ -324,7 +324,6 @@ void DRLG_MRectTrans(Rectangle area);
void DRLG_RectTrans(Rectangle area); void DRLG_RectTrans(Rectangle area);
void DRLG_CopyTrans(int sx, int sy, int dx, int dy); void DRLG_CopyTrans(int sx, int sy, int dx, int dy);
void DRLG_InitSetPC(); void DRLG_InitSetPC();
void DRLG_SetPC();
void Make_SetPC(Rectangle area); void Make_SetPC(Rectangle area);
/** /**
* @param tries Tiles to try, 1600 will scan the full map * @param tries Tiles to try, 1600 will scan the full map
@ -334,6 +333,8 @@ std::optional<Point> PlaceMiniSet(const Miniset &miniset, int tries = 199, bool
void PlaceDunTiles(const uint16_t *dunData, Point position, int floorId = 0); void PlaceDunTiles(const uint16_t *dunData, Point position, int floorId = 0);
void DRLG_PlaceThemeRooms(int minSize, int maxSize, int floor, int freq, bool rndSize); void DRLG_PlaceThemeRooms(int minSize, int maxSize, int floor, int freq, bool rndSize);
void DRLG_HoldThemeRooms(); void DRLG_HoldThemeRooms();
void SetSetPieceRoom(Point position, int floorId);
void FreeQuestSetPieces();
void DRLG_LPass3(int lv); void DRLG_LPass3(int lv);
void DRLG_Init_Globals(); void DRLG_Init_Globals();
bool SkipThemeRoom(int x, int y); bool SkipThemeRoom(int x, int y);

1
Source/setmaps.cpp

@ -117,7 +117,6 @@ void LoadSetMap()
case SL_POISONWATER: case SL_POISONWATER:
if (Quests[Q_PWATER]._qactive == QUEST_INIT) if (Quests[Q_PWATER]._qactive == QUEST_INIT)
Quests[Q_PWATER]._qactive = QUEST_ACTIVE; Quests[Q_PWATER]._qactive = QUEST_ACTIVE;
LoadPreL3Dungeon("Levels\\L3Data\\Foulwatr.DUN");
LoadL3Dungeon("Levels\\L3Data\\Foulwatr.DUN", 31, 83); LoadL3Dungeon("Levels\\L3Data\\Foulwatr.DUN", 31, 83);
LoadPalette("Levels\\L3Data\\L3pfoul.pal"); LoadPalette("Levels\\L3Data\\L3pfoul.pal");
InitPWaterTriggers(); InitPWaterTriggers();

88
Source/town.cpp

@ -148,6 +148,46 @@ void TownCloseGrave()
SetDungeonMicros(); SetDungeonMicros();
} }
void InitTownPieces()
{
for (int y = 0; y < MAXDUNY; y++) {
for (int x = 0; x < MAXDUNX; x++) {
if (dPiece[x][y] == 360) {
dSpecial[x][y] = 1;
} else if (dPiece[x][y] == 358) {
dSpecial[x][y] = 2;
} else if (dPiece[x][y] == 129) {
dSpecial[x][y] = 6;
} else if (dPiece[x][y] == 130) {
dSpecial[x][y] = 7;
} else if (dPiece[x][y] == 128) {
dSpecial[x][y] = 8;
} else if (dPiece[x][y] == 117) {
dSpecial[x][y] = 9;
} else if (dPiece[x][y] == 157) {
dSpecial[x][y] = 10;
} else if (dPiece[x][y] == 158) {
dSpecial[x][y] = 11;
} else if (dPiece[x][y] == 156) {
dSpecial[x][y] = 12;
} else if (dPiece[x][y] == 162) {
dSpecial[x][y] = 13;
} else if (dPiece[x][y] == 160) {
dSpecial[x][y] = 14;
} else if (dPiece[x][y] == 214) {
dSpecial[x][y] = 15;
} else if (dPiece[x][y] == 212) {
dSpecial[x][y] = 16;
} else if (dPiece[x][y] == 217) {
dSpecial[x][y] = 17;
} else if (dPiece[x][y] == 216) {
dSpecial[x][y] = 18;
}
}
}
}
/** /**
* @brief Initialize all of the levels data * @brief Initialize all of the levels data
*/ */
@ -196,6 +236,8 @@ void DrlgTPass3()
} else { } else {
FillTile(60, 70, 71); FillTile(60, 70, 71);
} }
InitTownPieces();
} }
} // namespace } // namespace
@ -284,8 +326,6 @@ void CreateTown(lvl_entry entry)
{ {
dminPosition = { 10, 10 }; dminPosition = { 10, 10 };
dmaxPosition = { 84, 84 }; dmaxPosition = { 84, 84 };
DRLG_InitTrans();
DRLG_Init_Globals();
if (entry == ENTRY_MAIN) { // New game if (entry == ENTRY_MAIN) { // New game
ViewPosition = { 75, 68 }; ViewPosition = { 75, 68 };
@ -310,50 +350,6 @@ void CreateTown(lvl_entry entry)
} }
DrlgTPass3(); DrlgTPass3();
memset(dFlags, 0, sizeof(dFlags));
memset(dLight, 0, sizeof(dLight));
memset(dFlags, 0, sizeof(dFlags));
memset(dPlayer, 0, sizeof(dPlayer));
memset(dMonster, 0, sizeof(dMonster));
memset(dObject, 0, sizeof(dObject));
memset(dItem, 0, sizeof(dItem));
memset(dSpecial, 0, sizeof(dSpecial));
for (int y = 0; y < MAXDUNY; y++) {
for (int x = 0; x < MAXDUNX; x++) {
if (dPiece[x][y] == 360) {
dSpecial[x][y] = 1;
} else if (dPiece[x][y] == 358) {
dSpecial[x][y] = 2;
} else if (dPiece[x][y] == 129) {
dSpecial[x][y] = 6;
} else if (dPiece[x][y] == 130) {
dSpecial[x][y] = 7;
} else if (dPiece[x][y] == 128) {
dSpecial[x][y] = 8;
} else if (dPiece[x][y] == 117) {
dSpecial[x][y] = 9;
} else if (dPiece[x][y] == 157) {
dSpecial[x][y] = 10;
} else if (dPiece[x][y] == 158) {
dSpecial[x][y] = 11;
} else if (dPiece[x][y] == 156) {
dSpecial[x][y] = 12;
} else if (dPiece[x][y] == 162) {
dSpecial[x][y] = 13;
} else if (dPiece[x][y] == 160) {
dSpecial[x][y] = 14;
} else if (dPiece[x][y] == 214) {
dSpecial[x][y] = 15;
} else if (dPiece[x][y] == 212) {
dSpecial[x][y] = 16;
} else if (dPiece[x][y] == 217) {
dSpecial[x][y] = 17;
} else if (dPiece[x][y] == 216) {
dSpecial[x][y] = 18;
}
}
}
} }
} // namespace devilution } // namespace devilution

Loading…
Cancel
Save