Browse Source

♻️Typed file loading

Tthis gives us the option to specify what type a file should be loaded
as, avoidng the need to case it and does some automatic checks on the
fitness of the data, while making the process simpler.

If no type is given then the type will be set to std::byte which limit
what operations can be performed on the data.
pull/952/head
Anders Jenbo 5 years ago
parent
commit
fa0b286693
  1. 10
      Source/DiabloUI/fonts.cpp
  2. 2
      Source/DiabloUI/fonts.h
  3. 7
      Source/DiabloUI/text.cpp
  4. 2
      Source/DiabloUI/text_draw.cpp
  5. 27
      Source/automap.cpp
  6. 48
      Source/diablo.cpp
  7. 159
      Source/drlg_l1.cpp
  8. 2
      Source/drlg_l1.h
  9. 72
      Source/drlg_l2.cpp
  10. 89
      Source/drlg_l3.cpp
  11. 136
      Source/drlg_l4.cpp
  12. 30
      Source/engine.cpp
  13. 42
      Source/engine.h
  14. 100
      Source/gendung.cpp
  15. 42
      Source/gendung.h
  16. 4
      Source/lighting.cpp
  17. 6
      Source/missiles.cpp
  18. 81
      Source/monster.cpp
  19. 2
      Source/monster.h
  20. 207
      Source/objects.cpp
  21. 2
      Source/objects.h
  22. 24
      Source/palette.cpp
  23. 165
      Source/quests.cpp
  24. 38
      Source/setmaps.cpp
  25. 103
      Source/town.cpp
  26. 66
      Source/towners.cpp
  27. 2
      Source/towners.h

10
Source/DiabloUI/fonts.cpp

@ -8,7 +8,7 @@
namespace devilution {
TTF_Font *font = nullptr;
std::unique_ptr<BYTE[]> FontTables[4];
std::unique_ptr<uint8_t[]> FontTables[4];
Art ArtFonts[4][2];
/** This is so we know ttf has been init when we get to the diablo_deinit() function */
bool was_fonts_init = false;
@ -24,10 +24,10 @@ void LoadArtFont(const char *pszFile, int size, int color)
void LoadArtFonts()
{
FontTables[AFT_SMALL] = LoadFileInMem("ui_art\\font16.bin");
FontTables[AFT_MED] = LoadFileInMem("ui_art\\font24.bin");
FontTables[AFT_BIG] = LoadFileInMem("ui_art\\font30.bin");
FontTables[AFT_HUGE] = LoadFileInMem("ui_art\\font42.bin");
FontTables[AFT_SMALL] = LoadFileInMem<uint8_t>("ui_art\\font16.bin");
FontTables[AFT_MED] = LoadFileInMem<uint8_t>("ui_art\\font24.bin");
FontTables[AFT_BIG] = LoadFileInMem<uint8_t>("ui_art\\font30.bin");
FontTables[AFT_HUGE] = LoadFileInMem<uint8_t>("ui_art\\font42.bin");
LoadArtFont("ui_art\\font16s.pcx", AFT_SMALL, AFC_SILVER);
LoadArtFont("ui_art\\font16g.pcx", AFT_SMALL, AFC_GOLD);
LoadArtFont("ui_art\\font24s.pcx", AFT_MED, AFC_SILVER);

2
Source/DiabloUI/fonts.h

@ -22,7 +22,7 @@ enum _artFontColors : uint8_t {
};
extern TTF_Font *font;
extern std::unique_ptr<BYTE[]> FontTables[4];
extern std::unique_ptr<uint8_t[]> FontTables[4];
extern Art ArtFonts[4][2];
void LoadArtFonts();

7
Source/DiabloUI/text.cpp

@ -7,11 +7,8 @@ std::size_t GetArtStrWidth(const char *str, std::size_t size)
int strWidth = 0;
for (size_t i = 0, n = strlen(str); i < n; i++) {
BYTE w = FontTables[size][*(BYTE *)&str[i] + 2];
if (w != 0)
strWidth += w;
else
strWidth += FontTables[size][0];
uint8_t w = FontTables[size][*(BYTE *)&str[i] + 2];
strWidth += (w != 0) ? w : FontTables[size][0];
}
return strWidth;

2
Source/DiabloUI/text_draw.cpp

@ -89,7 +89,7 @@ void DrawArtStr(const char *text, const SDL_Rect &rect, int flags, bool drawText
sy += ArtFonts[size][color].h();
continue;
}
BYTE w = FontTables[size][*(BYTE *)&text[i] + 2] != 0 ? FontTables[size][*(BYTE *)&text[i] + 2] : FontTables[size][0];
uint8_t w = FontTables[size][*(BYTE *)&text[i] + 2] != 0 ? FontTables[size][*(BYTE *)&text[i] + 2] : FontTables[size][0];
DrawArt(sx, sy, &ArtFonts[size][color], *(BYTE *)&text[i], w);
sx += w;
}

27
Source/automap.cpp

@ -124,7 +124,7 @@ void DrawAutomapTile(const CelOutputBuffer &out, Point center, uint16_t automapT
switch (automapType & MapFlagsType) {
case 1: // stand-alone column or other unpassable object
DrawSquare(out, { center.x, center.y - AmLine8 }, MapColorsDim);
break;
break;
case 2:
case 5:
drawVertical = true;
@ -415,21 +415,21 @@ void DrawAutomapText(const CelOutputBuffer &out)
}
}
std::unique_ptr<BYTE[]> LoadAutomapData(uint32_t &dwTiles)
std::unique_ptr<uint16_t[]> LoadAutomapData(size_t &tileCount)
{
switch (leveltype) {
case DTYPE_CATHEDRAL:
if (currlevel < 21)
return LoadFileInMem("Levels\\L1Data\\L1.AMP", &dwTiles);
return LoadFileInMem("NLevels\\L5Data\\L5.AMP", &dwTiles);
return LoadFileInMem<uint16_t>("Levels\\L1Data\\L1.AMP", &tileCount);
return LoadFileInMem<uint16_t>("NLevels\\L5Data\\L5.AMP", &tileCount);
case DTYPE_CATACOMBS:
return LoadFileInMem("Levels\\L2Data\\L2.AMP", &dwTiles);
return LoadFileInMem<uint16_t>("Levels\\L2Data\\L2.AMP", &tileCount);
case DTYPE_CAVES:
if (currlevel < 17)
return LoadFileInMem("Levels\\L3Data\\L3.AMP", &dwTiles);
return LoadFileInMem("NLevels\\L6Data\\L6.AMP", &dwTiles);
return LoadFileInMem<uint16_t>("Levels\\L3Data\\L3.AMP", &tileCount);
return LoadFileInMem<uint16_t>("NLevels\\L6Data\\L6.AMP", &tileCount);
case DTYPE_HELL:
return LoadFileInMem("Levels\\L4Data\\L4.AMP", &dwTiles);
return LoadFileInMem<uint16_t>("Levels\\L4Data\\L4.AMP", &tileCount);
default:
return nullptr;
}
@ -460,17 +460,12 @@ void InitAutomapOnce()
void InitAutomap()
{
uint32_t tileCount = 0;
std::unique_ptr<BYTE[]> pAFile = LoadAutomapData(tileCount);
tileCount /= 2;
auto tileTypes = reinterpret_cast<uint16_t *>(pAFile.get());
size_t tileCount = 0;
std::unique_ptr<uint16_t[]> tileTypes = LoadAutomapData(tileCount);
for (unsigned i = 0; i < tileCount; i++) {
AutomapTypes[i + 1] = tileTypes[i];
}
pAFile = nullptr;
tileTypes = nullptr;
memset(AutomapView, 0, sizeof(AutomapView));

48
Source/diablo.cpp

@ -1503,51 +1503,51 @@ void LoadLvlGFX()
switch (leveltype) {
case DTYPE_TOWN:
if (gbIsHellfire) {
pDungeonCels = LoadFileInMem("NLevels\\TownData\\Town.CEL");
pMegaTiles = LoadFileInMem("NLevels\\TownData\\Town.TIL");
pLevelPieces = LoadFileInMem("NLevels\\TownData\\Town.MIN");
pDungeonCels = LoadFileInMem<BYTE>("NLevels\\TownData\\Town.CEL");
pMegaTiles = LoadFileInMem<MegaTile>("NLevels\\TownData\\Town.TIL");
pLevelPieces = LoadFileInMem<BYTE>("NLevels\\TownData\\Town.MIN");
} else {
pDungeonCels = LoadFileInMem("Levels\\TownData\\Town.CEL");
pMegaTiles = LoadFileInMem("Levels\\TownData\\Town.TIL");
pLevelPieces = LoadFileInMem("Levels\\TownData\\Town.MIN");
pDungeonCels = LoadFileInMem<BYTE>("Levels\\TownData\\Town.CEL");
pMegaTiles = LoadFileInMem<MegaTile>("Levels\\TownData\\Town.TIL");
pLevelPieces = LoadFileInMem<BYTE>("Levels\\TownData\\Town.MIN");
}
pSpecialCels = LoadCel("Levels\\TownData\\TownS.CEL", SpecialCelWidth);
break;
case DTYPE_CATHEDRAL:
if (currlevel < 21) {
pDungeonCels = LoadFileInMem("Levels\\L1Data\\L1.CEL");
pMegaTiles = LoadFileInMem("Levels\\L1Data\\L1.TIL");
pLevelPieces = LoadFileInMem("Levels\\L1Data\\L1.MIN");
pDungeonCels = LoadFileInMem<BYTE>("Levels\\L1Data\\L1.CEL");
pMegaTiles = LoadFileInMem<MegaTile>("Levels\\L1Data\\L1.TIL");
pLevelPieces = LoadFileInMem<BYTE>("Levels\\L1Data\\L1.MIN");
pSpecialCels = LoadCel("Levels\\L1Data\\L1S.CEL", SpecialCelWidth);
} else {
pDungeonCels = LoadFileInMem("NLevels\\L5Data\\L5.CEL");
pMegaTiles = LoadFileInMem("NLevels\\L5Data\\L5.TIL");
pLevelPieces = LoadFileInMem("NLevels\\L5Data\\L5.MIN");
pDungeonCels = LoadFileInMem<BYTE>("NLevels\\L5Data\\L5.CEL");
pMegaTiles = LoadFileInMem<MegaTile>("NLevels\\L5Data\\L5.TIL");
pLevelPieces = LoadFileInMem<BYTE>("NLevels\\L5Data\\L5.MIN");
pSpecialCels = LoadCel("NLevels\\L5Data\\L5S.CEL", SpecialCelWidth);
}
break;
case DTYPE_CATACOMBS:
pDungeonCels = LoadFileInMem("Levels\\L2Data\\L2.CEL");
pMegaTiles = LoadFileInMem("Levels\\L2Data\\L2.TIL");
pLevelPieces = LoadFileInMem("Levels\\L2Data\\L2.MIN");
pDungeonCels = LoadFileInMem<BYTE>("Levels\\L2Data\\L2.CEL");
pMegaTiles = LoadFileInMem<MegaTile>("Levels\\L2Data\\L2.TIL");
pLevelPieces = LoadFileInMem<BYTE>("Levels\\L2Data\\L2.MIN");
pSpecialCels = LoadCel("Levels\\L2Data\\L2S.CEL", SpecialCelWidth);
break;
case DTYPE_CAVES:
if (currlevel < 17) {
pDungeonCels = LoadFileInMem("Levels\\L3Data\\L3.CEL");
pMegaTiles = LoadFileInMem("Levels\\L3Data\\L3.TIL");
pLevelPieces = LoadFileInMem("Levels\\L3Data\\L3.MIN");
pDungeonCels = LoadFileInMem<BYTE>("Levels\\L3Data\\L3.CEL");
pMegaTiles = LoadFileInMem<MegaTile>("Levels\\L3Data\\L3.TIL");
pLevelPieces = LoadFileInMem<BYTE>("Levels\\L3Data\\L3.MIN");
} else {
pDungeonCels = LoadFileInMem("NLevels\\L6Data\\L6.CEL");
pMegaTiles = LoadFileInMem("NLevels\\L6Data\\L6.TIL");
pLevelPieces = LoadFileInMem("NLevels\\L6Data\\L6.MIN");
pDungeonCels = LoadFileInMem<BYTE>("NLevels\\L6Data\\L6.CEL");
pMegaTiles = LoadFileInMem<MegaTile>("NLevels\\L6Data\\L6.TIL");
pLevelPieces = LoadFileInMem<BYTE>("NLevels\\L6Data\\L6.MIN");
}
pSpecialCels = LoadCel("Levels\\L1Data\\L1S.CEL", SpecialCelWidth);
break;
case DTYPE_HELL:
pDungeonCels = LoadFileInMem("Levels\\L4Data\\L4.CEL");
pMegaTiles = LoadFileInMem("Levels\\L4Data\\L4.TIL");
pLevelPieces = LoadFileInMem("Levels\\L4Data\\L4.MIN");
pDungeonCels = LoadFileInMem<BYTE>("Levels\\L4Data\\L4.CEL");
pMegaTiles = LoadFileInMem<MegaTile>("Levels\\L4Data\\L4.TIL");
pLevelPieces = LoadFileInMem<BYTE>("Levels\\L4Data\\L4.MIN");
pSpecialCels = LoadCel("Levels\\L2Data\\L2S.CEL", SpecialCelWidth);
break;
default:

159
Source/drlg_l1.cpp

@ -5,6 +5,7 @@
*/
#include "drlg_l1.h"
#include "gendung.h"
#include "lighting.h"
#include "player.h"
#include "quests.h"
@ -40,7 +41,7 @@ bool VR2;
/** Specifies whether to generate a vertical room at position 3 in the Cathedral. */
bool VR3;
/** Contains the contents of the single player quest DUN file. */
std::unique_ptr<BYTE[]> L5pSetPiece;
std::unique_ptr<uint16_t[]> L5pSetPiece;
/** Contains shadows for 2x2 blocks of base tile IDs in the Cathedral. */
const ShadowStruct SPATS[37] = {
@ -1069,17 +1070,17 @@ static void DRLG_L1Floor()
void DRLG_LPass3(int lv)
{
auto *MegaTiles = (uint16_t *)&pMegaTiles[lv * 8];
int v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1;
int v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1;
int v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1;
int v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1;
MegaTile mega = pMegaTiles[lv];
int v1 = SDL_SwapLE16(mega.micro1) + 1;
int v2 = SDL_SwapLE16(mega.micro2) + 1;
int v3 = SDL_SwapLE16(mega.micro3) + 1;
int v4 = SDL_SwapLE16(mega.micro4) + 1;
for (int j = 0; j < MAXDUNY; j += 2) {
for (int i = 0; i < MAXDUNX; i += 2) {
dPiece[i][j] = v1;
dPiece[i + 1][j] = v2;
dPiece[i][j + 1] = v3;
dPiece[i + 0][j + 0] = v1;
dPiece[i + 1][j + 0] = v2;
dPiece[i + 0][j + 1] = v3;
dPiece[i + 1][j + 1] = v4;
}
}
@ -1088,22 +1089,22 @@ void DRLG_LPass3(int lv)
for (int j = 0; j < DMAXY; j++) {
int xx = 16;
for (int i = 0; i < DMAXX; i++) {
lv = dungeon[i][j] - 1;
if (lv >= 0) {
MegaTiles = (uint16_t *)&pMegaTiles[lv * 8];
v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1;
v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1;
v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1;
v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1;
} else {
v1 = 0;
v2 = 0;
v3 = 0;
v4 = 0;
v1 = 0;
v2 = 0;
v3 = 0;
v4 = 0;
int tileId = dungeon[i][j] - 1;
if (tileId >= 0) {
MegaTile mega = pMegaTiles[tileId];
v1 = SDL_SwapLE16(mega.micro1) + 1;
v2 = SDL_SwapLE16(mega.micro2) + 1;
v3 = SDL_SwapLE16(mega.micro3) + 1;
v4 = SDL_SwapLE16(mega.micro4) + 1;
}
dPiece[xx][yy] = v1;
dPiece[xx + 1][yy] = v2;
dPiece[xx][yy + 1] = v3;
dPiece[xx + 0][yy + 0] = v1;
dPiece[xx + 1][yy + 0] = v2;
dPiece[xx + 0][yy + 1] = v3;
dPiece[xx + 1][yy + 1] = v4;
xx += 2;
}
@ -1120,15 +1121,15 @@ static void DRLG_LoadL1SP()
{
L5setloadflag = false;
if (QuestStatus(Q_BUTCHER)) {
L5pSetPiece = LoadFileInMem("Levels\\L1Data\\rnd6.DUN");
L5pSetPiece = LoadFileInMem<uint16_t>("Levels\\L1Data\\rnd6.DUN");
L5setloadflag = true;
}
if (QuestStatus(Q_SKELKING) && !gbIsMultiplayer) {
L5pSetPiece = LoadFileInMem("Levels\\L1Data\\SKngDO.DUN");
L5pSetPiece = LoadFileInMem<uint16_t>("Levels\\L1Data\\SKngDO.DUN");
L5setloadflag = true;
}
if (QuestStatus(Q_LTBANNER)) {
L5pSetPiece = LoadFileInMem("Levels\\L1Data\\Banner2.DUN");
L5pSetPiece = LoadFileInMem<uint16_t>("Levels\\L1Data\\Banner2.DUN");
L5setloadflag = true;
}
}
@ -1207,96 +1208,95 @@ static void DRLG_InitL1Vals()
}
}
void LoadL1Dungeon(const char *sFileName, int vx, int vy)
void LoadL1Dungeon(const char *path, int vx, int vy)
{
int i, j, rw, rh;
BYTE *lm;
dminx = 16;
dminy = 16;
dmaxx = 96;
dmaxy = 96;
DRLG_InitTrans();
auto pLevelMap = LoadFileInMem(sFileName);
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
dungeon[i][j] = 22;
L5dflags[i][j] = 0;
}
}
lm = pLevelMap.get();
rw = *lm;
lm += 2;
rh = *lm;
lm += 2;
auto dunData = LoadFileInMem<uint16_t>(path);
for (j = 0; j < rh; j++) {
for (i = 0; i < rw; i++) {
if (*lm != 0) {
dungeon[i][j] = *lm;
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
const uint16_t *tileLayer = &dunData[2];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
uint8_t tileId = SDL_SwapLE16(*tileLayer);
tileLayer++;
if (tileId != 0) {
dungeon[i][j] = tileId;
L5dflags[i][j] |= DLRG_PROTECTED;
} else {
dungeon[i][j] = 13;
}
lm += 2;
}
}
DRLG_L1Floor();
ViewX = vx;
ViewY = vy;
DRLG_L1Pass3();
DRLG_Init_Globals();
if (currlevel < 17)
DRLG_InitL1Vals();
SetMapMonsters(pLevelMap.get(), 0, 0);
SetMapObjects(pLevelMap.get(), 0, 0);
SetMapMonsters(dunData.get(), 0, 0);
SetMapObjects(dunData.get(), 0, 0);
}
void LoadPreL1Dungeon(const char *sFileName)
void LoadPreL1Dungeon(const char *path)
{
int i, j, rw, rh;
BYTE *lm;
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
dungeon[i][j] = 22;
L5dflags[i][j] = 0;
}
}
dminx = 16;
dminy = 16;
dmaxx = 96;
dmaxy = 96;
auto pLevelMap = LoadFileInMem(sFileName);
auto dunData = LoadFileInMem<uint16_t>(path);
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
dungeon[i][j] = 22;
L5dflags[i][j] = 0;
}
}
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
lm = pLevelMap.get();
rw = *lm;
lm += 2;
rh = *lm;
lm += 2;
const uint16_t *tileLayer = &dunData[2];
for (j = 0; j < rh; j++) {
for (i = 0; i < rw; i++) {
if (*lm != 0) {
dungeon[i][j] = *lm;
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
uint8_t tileId = SDL_SwapLE16(*tileLayer);
tileLayer++;
if (tileId != 0) {
dungeon[i][j] = tileId;
L5dflags[i][j] |= DLRG_PROTECTED;
} else {
dungeon[i][j] = 13;
}
lm += 2;
}
}
DRLG_L1Floor();
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
pdungeon[i][j] = dungeon[i][j];
}
}
@ -2038,28 +2038,25 @@ static void DRLG_L5Subs()
static void DRLG_L5SetRoom(int rx1, int ry1)
{
int rw, rh, i, j;
BYTE *sp;
rw = L5pSetPiece[0];
rh = L5pSetPiece[2];
int width = SDL_SwapLE16(L5pSetPiece[0]);
int height = SDL_SwapLE16(L5pSetPiece[1]);
setpc_x = rx1;
setpc_y = ry1;
setpc_w = rw;
setpc_h = rh;
setpc_w = width;
setpc_h = height;
sp = &L5pSetPiece[4];
uint16_t *tileLayer = &L5pSetPiece[2];
for (j = 0; j < rh; j++) {
for (i = 0; i < rw; i++) {
if (*sp) {
dungeon[rx1 + i][ry1 + j] = *sp;
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]);
if (tileId != 0) {
dungeon[rx1 + i][ry1 + j] = tileId;
L5dflags[rx1 + i][ry1 + j] |= DLRG_PROTECTED;
} else {
dungeon[rx1 + i][ry1 + j] = 13;
}
sp += 2;
}
}
}

2
Source/drlg_l1.h

@ -21,7 +21,7 @@ extern int UberDiabloMonsterIndex;
void DRLG_LPass3(int lv);
void DRLG_Init_Globals();
void LoadL1Dungeon(const char *sFileName, int vx, int vy);
void LoadL1Dungeon(const char *path, int vx, int vy);
void LoadPreL1Dungeon(const char *sFileName);
void CreateL5Dungeon(uint32_t rseed, lvl_entry entry);
void drlg_l1_set_crypt_room(int rx1, int ry1);

72
Source/drlg_l2.cpp

@ -1843,15 +1843,15 @@ static void DRLG_LoadL2SP()
setloadflag = false;
if (QuestStatus(Q_BLIND)) {
pSetPiece = LoadFileInMem("Levels\\L2Data\\Blind1.DUN");
pSetPiece[26] = 154; // Close outer wall
pSetPiece[200] = 154; // Close outer wall
pSetPiece = LoadFileInMem<uint16_t>("Levels\\L2Data\\Blind1.DUN");
pSetPiece[13] = SDL_SwapLE16(154); // Close outer wall
pSetPiece[100] = SDL_SwapLE16(154); // Close outer wall
setloadflag = true;
} else if (QuestStatus(Q_BLOOD)) {
pSetPiece = LoadFileInMem("Levels\\L2Data\\Blood1.DUN");
pSetPiece = LoadFileInMem<uint16_t>("Levels\\L2Data\\Blood1.DUN");
setloadflag = true;
} else if (QuestStatus(Q_SCHAMB)) {
pSetPiece = LoadFileInMem("Levels\\L2Data\\Bonestr2.DUN");
pSetPiece = LoadFileInMem<uint16_t>("Levels\\L2Data\\Bonestr2.DUN");
setloadflag = true;
}
}
@ -1863,28 +1863,25 @@ static void DRLG_FreeL2SP()
static void DRLG_L2SetRoom(int rx1, int ry1)
{
int rw, rh, i, j;
BYTE *sp;
rw = pSetPiece[0];
rh = pSetPiece[2];
int width = SDL_SwapLE16(pSetPiece[0]);
int height = SDL_SwapLE16(pSetPiece[1]);
setpc_x = rx1;
setpc_y = ry1;
setpc_w = rw;
setpc_h = rh;
setpc_w = width;
setpc_h = height;
sp = &pSetPiece[4];
uint16_t *tileLayer = &pSetPiece[2];
for (j = 0; j < rh; j++) {
for (i = 0; i < rw; i++) {
if (*sp != 0) {
dungeon[i + rx1][j + ry1] = *sp;
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]);
if (tileId != 0) {
dungeon[i + rx1][j + ry1] = tileId;
dflags[i + rx1][j + ry1] |= DLRG_PROTECTED;
} else {
dungeon[i + rx1][j + ry1] = 3;
}
sp += 2;
}
}
}
@ -3227,7 +3224,7 @@ static void DRLG_InitL2Vals()
}
}
static void LoadL2DungeonData(BYTE *pLevelMap)
static void LoadL2DungeonData(const uint16_t *dunData)
{
InitDungeon();
DRLG_InitTrans();
@ -3239,21 +3236,21 @@ static void LoadL2DungeonData(BYTE *pLevelMap)
}
}
BYTE *lm = pLevelMap;
int rw = *lm;
lm += 2;
int rh = *lm;
lm += 2;
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
const uint16_t *tileLayer = &dunData[2];
for (int j = 0; j < rh; j++) {
for (int i = 0; i < rw; i++) {
if (*lm != 0) {
dungeon[i][j] = *lm;
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
uint8_t tileId = SDL_SwapLE16(*tileLayer);
tileLayer++;
if (tileId != 0) {
dungeon[i][j] = tileId;
dflags[i][j] |= DLRG_PROTECTED;
} else {
dungeon[i][j] = 3;
}
lm += 2;
}
}
@ -3266,11 +3263,11 @@ static void LoadL2DungeonData(BYTE *pLevelMap)
}
}
void LoadL2Dungeon(const char *sFileName, int vx, int vy)
void LoadL2Dungeon(const char *path, int vx, int vy)
{
auto pLevelMap = LoadFileInMem(sFileName);
auto dunData = LoadFileInMem<uint16_t>(path);
LoadL2DungeonData(pLevelMap.get());
LoadL2DungeonData(dunData.get());
DRLG_L2Pass3();
DRLG_Init_Globals();
@ -3310,15 +3307,16 @@ void LoadL2Dungeon(const char *sFileName, int vx, int vy)
ViewX = vx;
ViewY = vy;
SetMapMonsters(pLevelMap.get(), 0, 0);
SetMapObjects(pLevelMap.get(), 0, 0);
SetMapMonsters(dunData.get(), 0, 0);
SetMapObjects(dunData.get(), 0, 0);
}
void LoadPreL2Dungeon(const char *sFileName)
void LoadPreL2Dungeon(const char *path)
{
{
auto pLevelMap = LoadFileInMem(sFileName);
LoadL2DungeonData(pLevelMap.get());
auto dunData = LoadFileInMem<uint16_t>(path);
LoadL2DungeonData(dunData.get());
}
for (int j = 0; j < DMAXY; j++) {

89
Source/drlg_l3.cpp

@ -2619,37 +2619,32 @@ void CreateL3Dungeon(uint32_t rseed, lvl_entry entry)
DRLG_SetPC();
}
void LoadL3Dungeon(const char *sFileName, int vx, int vy)
void LoadL3Dungeon(const char *path, int vx, int vy)
{
int i, j, rw, rh;
BYTE *lm;
InitL3Dungeon();
dminx = 16;
dminy = 16;
dmaxx = 96;
dmaxy = 96;
InitL3Dungeon();
DRLG_InitTrans();
auto pLevelMap = LoadFileInMem(sFileName);
lm = pLevelMap.get();
rw = *lm;
lm += 2;
rh = *lm;
lm += 2;
for (j = 0; j < rh; j++) {
for (i = 0; i < rw; i++) {
if (*lm != 0) {
dungeon[i][j] = *lm;
} else {
dungeon[i][j] = 7;
}
lm += 2;
auto dunData = LoadFileInMem<uint16_t>(path);
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
const uint16_t *tileLayer = &dunData[2];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]);
dungeon[i][j] = (tileId != 0) ? tileId : 7;
}
}
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 0) {
dungeon[i][j] = 8;
}
@ -2658,13 +2653,15 @@ void LoadL3Dungeon(const char *sFileName, int vx, int vy)
DRLG_L3Pass3();
DRLG_Init_Globals();
ViewX = vx;
ViewY = vy;
SetMapMonsters(pLevelMap.get(), 0, 0);
SetMapObjects(pLevelMap.get(), 0, 0);
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
SetMapMonsters(dunData.get(), 0, 0);
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) {
@ -2678,33 +2675,27 @@ void LoadL3Dungeon(const char *sFileName, int vx, int vy)
}
}
void LoadPreL3Dungeon(const char *sFileName)
void LoadPreL3Dungeon(const char *path)
{
int i, j, rw, rh;
BYTE *lm;
InitL3Dungeon();
DRLG_InitTrans();
auto pLevelMap = LoadFileInMem(sFileName);
lm = pLevelMap.get();
rw = *lm;
lm += 2;
rh = *lm;
lm += 2;
for (j = 0; j < rh; j++) {
for (i = 0; i < rw; i++) {
if (*lm != 0) {
dungeon[i][j] = *lm;
} else {
dungeon[i][j] = 7;
}
lm += 2;
auto dunData = LoadFileInMem<uint16_t>(path);
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
const uint16_t *tileLayer = &dunData[2];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]);
dungeon[i][j] = (tileId != 0) ? tileId : 7;
}
}
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 0) {
dungeon[i][j] = 8;
}

136
Source/drlg_l4.cpp

@ -202,11 +202,11 @@ void DRLG_LoadL4SP()
{
setloadflag = false;
if (QuestStatus(Q_WARLORD)) {
pSetPiece = LoadFileInMem("Levels\\L4Data\\Warlord.DUN");
pSetPiece = LoadFileInMem<uint16_t>("Levels\\L4Data\\Warlord.DUN");
setloadflag = true;
}
if (currlevel == 15 && gbIsMultiplayer) {
pSetPiece = LoadFileInMem("Levels\\L4Data\\Vile1.DUN");
pSetPiece = LoadFileInMem<uint16_t>("Levels\\L4Data\\Vile1.DUN");
setloadflag = true;
}
}
@ -216,34 +216,36 @@ void DRLG_FreeL4SP()
pSetPiece = nullptr;
}
void DRLG_L4SetSPRoom(int rx1, int ry1)
void DRLG_L4SetRoom(const uint16_t *dunData, int rx1, int ry1)
{
int rw, rh, i, j;
BYTE *sp;
rw = pSetPiece[0];
rh = pSetPiece[2];
setpc_x = rx1;
setpc_y = ry1;
setpc_w = rw;
setpc_h = rh;
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
sp = &pSetPiece[4];
const uint16_t *tileLayer = &dunData[2];
for (j = 0; j < rh; j++) {
for (i = 0; i < rw; i++) {
if (*sp != 0) {
dungeon[i + rx1][j + ry1] = *sp;
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]);
if (tileId != 0) {
dungeon[i + rx1][j + ry1] = tileId;
dflags[i + rx1][j + ry1] |= DLRG_PROTECTED;
} else {
dungeon[i + rx1][j + ry1] = 6;
}
sp += 2;
}
}
}
void DRLG_L4SetSPRoom(int rx1, int ry1)
{
setpc_x = rx1;
setpc_y = ry1;
setpc_w = SDL_SwapLE16(pSetPiece[0]);
setpc_h = SDL_SwapLE16(pSetPiece[1]);
DRLG_L4SetRoom(pSetPiece.get(), rx1, ry1);
}
static void L4makeDmt()
{
int i, j, idx, val, dmtx, dmty;
@ -1252,53 +1254,31 @@ void L4SaveQuads()
}
}
void DRLG_L4SetRoom(BYTE *pSetPiece, int rx1, int ry1)
{
int rw, rh, i, j;
BYTE *sp;
rw = pSetPiece[0];
rh = pSetPiece[2];
sp = &pSetPiece[4];
for (j = 0; j < rh; j++) {
for (i = 0; i < rw; i++) {
if (*sp != 0) {
dungeon[i + rx1][j + ry1] = *sp;
dflags[i + rx1][j + ry1] |= DLRG_PROTECTED;
} else {
dungeon[i + rx1][j + ry1] = 6;
}
sp += 2;
}
}
}
void DRLG_LoadDiabQuads(bool preflag)
{
{
auto lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab1.DUN");
auto dunData = LoadFileInMem<uint16_t>("Levels\\L4Data\\diab1.DUN");
diabquad1x = 4 + l4holdx;
diabquad1y = 4 + l4holdy;
DRLG_L4SetRoom(lpSetPiece.get(), diabquad1x, diabquad1y);
DRLG_L4SetRoom(dunData.get(), diabquad1x, diabquad1y);
}
{
auto lpSetPiece = LoadFileInMem(preflag ? "Levels\\L4Data\\diab2b.DUN" : "Levels\\L4Data\\diab2a.DUN");
auto dunData = LoadFileInMem<uint16_t>(preflag ? "Levels\\L4Data\\diab2b.DUN" : "Levels\\L4Data\\diab2a.DUN");
diabquad2x = 27 - l4holdx;
diabquad2y = 1 + l4holdy;
DRLG_L4SetRoom(lpSetPiece.get(), diabquad2x, diabquad2y);
DRLG_L4SetRoom(dunData.get(), diabquad2x, diabquad2y);
}
{
auto lpSetPiece = LoadFileInMem(preflag ? "Levels\\L4Data\\diab3b.DUN" : "Levels\\L4Data\\diab3a.DUN");
auto dunData = LoadFileInMem<uint16_t>(preflag ? "Levels\\L4Data\\diab3b.DUN" : "Levels\\L4Data\\diab3a.DUN");
diabquad3x = 1 + l4holdx;
diabquad3y = 27 - l4holdy;
DRLG_L4SetRoom(lpSetPiece.get(), diabquad3x, diabquad3y);
DRLG_L4SetRoom(dunData.get(), diabquad3x, diabquad3y);
}
{
auto lpSetPiece = LoadFileInMem(preflag ? "Levels\\L4Data\\diab4b.DUN" : "Levels\\L4Data\\diab4a.DUN");
auto dunData = LoadFileInMem<uint16_t>(preflag ? "Levels\\L4Data\\diab4b.DUN" : "Levels\\L4Data\\diab4a.DUN");
diabquad4x = 28 - l4holdx;
diabquad4y = 28 - l4holdy;
DRLG_L4SetRoom(lpSetPiece.get(), diabquad4x, diabquad4y);
DRLG_L4SetRoom(dunData.get(), diabquad4x, diabquad4y);
}
}
@ -1758,11 +1738,8 @@ void CreateL4Dungeon(uint32_t rseed, lvl_entry entry)
DRLG_SetPC();
}
void LoadL4Dungeon(char *sFileName, int vx, int vy)
void LoadL4Dungeon(const char *path, int vx, int vy)
{
int i, j, rw, rh;
BYTE *lm;
dminx = 16;
dminy = 16;
dmaxx = 96;
@ -1770,40 +1747,23 @@ void LoadL4Dungeon(char *sFileName, int vx, int vy)
DRLG_InitTrans();
InitL4Dungeon();
auto pLevelMap = LoadFileInMem(sFileName);
lm = pLevelMap.get();
rw = *lm;
lm += 2;
rh = *lm;
lm += 2;
for (j = 0; j < rh; j++) {
for (i = 0; i < rw; i++) {
if (*lm != 0) {
dungeon[i][j] = *lm;
dflags[i][j] |= 0x80;
} else {
dungeon[i][j] = 6;
}
lm += 2;
}
}
auto dunData = LoadFileInMem<uint16_t>(path);
DRLG_L4SetRoom(dunData.get(), 0, 0);
ViewX = vx;
ViewY = vy;
DRLG_L4Pass3();
DRLG_Init_Globals();
SetMapMonsters(pLevelMap.get(), 0, 0);
SetMapObjects(pLevelMap.get(), 0, 0);
SetMapMonsters(dunData.get(), 0, 0);
SetMapObjects(dunData.get(), 0, 0);
}
void LoadPreL4Dungeon(char *sFileName)
void LoadPreL4Dungeon(const char *path)
{
int i, j, rw, rh;
BYTE *lm;
dminx = 16;
dminy = 16;
dmaxx = 96;
@ -1811,25 +1771,9 @@ void LoadPreL4Dungeon(char *sFileName)
InitL4Dungeon();
auto pLevelMap = LoadFileInMem(sFileName);
lm = pLevelMap.get();
rw = *lm;
lm += 2;
rh = *lm;
lm += 2;
auto dunData = LoadFileInMem<uint16_t>(path);
for (j = 0; j < rh; j++) {
for (i = 0; i < rw; i++) {
if (*lm != 0) {
dungeon[i][j] = *lm;
dflags[i][j] |= DLRG_PROTECTED;
} else {
dungeon[i][j] = 6;
}
lm += 2;
}
}
DRLG_L4SetRoom(dunData.get(), 0, 0);
}
} // namespace devilution

30
Source/engine.cpp

@ -89,12 +89,12 @@ BYTE *GetLightTable(char light)
CelSprite LoadCel(const char *pszName, int width)
{
return CelSprite(LoadFileInMem(pszName), width);
return CelSprite(LoadFileInMem<BYTE>(pszName), width);
}
CelSprite LoadCel(const char *pszName, const int *widths)
{
return CelSprite(LoadFileInMem(pszName), widths);
return CelSprite(LoadFileInMem<BYTE>(pszName), widths);
}
std::pair<int, int> MeasureSolidHorizontalBounds(const CelSprite &cel, int frame)
@ -710,30 +710,26 @@ int32_t GenerateRnd(int32_t v)
return AdvanceRndSeed() % v;
}
/**
* @brief Load a file in to a buffer
* @param pszName Path of file
* @param pdwFileLen Will be set to file size if non-NULL
* @return Buffer with content of file
*/
std::unique_ptr<BYTE[]> LoadFileInMem(const char *pszName, DWORD *pdwFileLen)
size_t GetFileSize(const char *pszName)
{
HANDLE file;
SFileOpenFile(pszName, &file);
const DWORD fileLen = SFileGetFileSize(file, nullptr);
const size_t fileLen = SFileGetFileSize(file, nullptr);
SFileCloseFile(file);
if (pdwFileLen != nullptr)
*pdwFileLen = fileLen;
return fileLen;
}
void LoadFileData(const char *pszName, byte *buffer, size_t fileLen)
{
HANDLE file;
SFileOpenFile(pszName, &file);
if (fileLen == 0)
app_fatal("Zero length SFILE:\n%s", pszName);
std::unique_ptr<BYTE[]> buf { new BYTE[fileLen] };
SFileReadFileThreadSafe(file, buf.get(), fileLen);
SFileReadFileThreadSafe(file, buffer, fileLen);
SFileCloseFile(file);
return buf;
}
/**

42
Source/engine.h

@ -13,6 +13,7 @@
#pragma once
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
@ -31,6 +32,12 @@
namespace devilution {
#if __cplusplus >= 201703L
using byte = std::byte;
#else
using byte = uint8_t;
#endif
#if defined(__cpp_lib_clamp)
using std::clamp;
#else
@ -598,7 +605,40 @@ void SetRndSeed(int32_t s);
int32_t AdvanceRndSeed();
int32_t GetRndSeed();
int32_t GenerateRnd(int32_t v);
std::unique_ptr<BYTE[]> LoadFileInMem(const char *pszName, DWORD *pdwFileLen = nullptr);
size_t GetFileSize(const char *pszName);
void LoadFileData(const char *pszName, byte *buffer, size_t bufferSize);
template <typename T, std::size_t N>
void LoadFileInMem(const char *path, std::array<T, N> &data)
{
LoadFileData(path, reinterpret_cast<byte *>(&data), N * sizeof(T));
}
/**
* @brief Load a file in to a buffer
* @param path Path of file
* @param elements Number of T elements read
* @return Buffer with content of file
*/
template <typename T = byte>
std::unique_ptr<T[]> LoadFileInMem(const char *path, size_t *elements = nullptr)
{
const size_t fileLen = GetFileSize(path);
if ((fileLen % sizeof(T)) != 0)
app_fatal("File size does not align with type\n%s", path);
if (elements != nullptr)
*elements = fileLen / sizeof(T);
std::unique_ptr<T[]> buf { new T[fileLen / sizeof(T)] };
LoadFileData(path, reinterpret_cast<byte *>(buf.get()), fileLen);
return buf;
}
DWORD LoadFileWithMem(const char *pszName, BYTE *p);
void Cl2ApplyTrans(BYTE *p, BYTE *ttbl, int nCel);
void PlayInGameMovie(const char *pszMovie);

100
Source/gendung.cpp

@ -10,9 +10,9 @@
namespace devilution {
/** Contains the tile IDs of the map. */
BYTE dungeon[DMAXX][DMAXY];
uint8_t dungeon[DMAXX][DMAXY];
/** Contains a backup of the tile IDs of the map. */
BYTE pdungeon[DMAXX][DMAXY];
uint8_t pdungeon[DMAXX][DMAXY];
char dflags[DMAXX][DMAXY];
/** Specifies the active set level X-coordinate of the map. */
int setpc_x;
@ -23,35 +23,20 @@ int setpc_w;
/** Specifies the height of the active set level of the map. */
int setpc_h;
/** Contains the contents of the single player quest DUN file. */
std::unique_ptr<BYTE[]> pSetPiece;
std::unique_ptr<uint16_t[]> pSetPiece;
/** Specifies whether a single player quest DUN has been loaded. */
bool setloadflag;
std::optional<CelSprite> pSpecialCels;
/** Specifies the tile definitions of the active dungeon type; (e.g. levels/l1data/l1.til). */
std::unique_ptr<BYTE[]> pMegaTiles;
std::unique_ptr<MegaTile[]> pMegaTiles;
std::unique_ptr<BYTE[]> pLevelPieces;
std::unique_ptr<BYTE[]> pDungeonCels;
/**
* List of transparancy masks to use for dPieces
*/
char block_lvid[MAXTILES + 1];
/**
* List of light blocking dPieces
*/
bool nBlockTable[MAXTILES + 1];
/**
* List of path blocking dPieces
*/
bool nSolidTable[MAXTILES + 1];
/**
* List of transparent dPieces
*/
bool nTransTable[MAXTILES + 1];
/**
* List of missile blocking dPieces
*/
bool nMissileTable[MAXTILES + 1];
bool nTrapTable[MAXTILES + 1];
std::array<uint8_t, MAXTILES + 1> block_lvid;
std::array<bool, MAXTILES + 1> nBlockTable;
std::array<bool, MAXTILES + 1> nSolidTable;
std::array<bool, MAXTILES + 1> nTransTable;
std::array<bool, MAXTILES + 1> nMissileTable;
std::array<bool, MAXTILES + 1> nTrapTable;
/** Specifies the minimum X-coordinate of the map. */
int dminx;
/** Specifies the minimum Y-coordinate of the map. */
@ -125,62 +110,43 @@ char dSpecial[MAXDUNX][MAXDUNY];
int themeCount;
THEME_LOC themeLoc[MAXTHEMES];
void FillSolidBlockTbls()
std::unique_ptr<uint8_t[]> LoadLevelSOLData(size_t &tileCount)
{
BYTE bv;
DWORD i, dwTiles;
memset(nBlockTable, 0, sizeof(nBlockTable));
memset(nSolidTable, 0, sizeof(nSolidTable));
memset(nTransTable, 0, sizeof(nTransTable));
memset(nMissileTable, 0, sizeof(nMissileTable));
memset(nTrapTable, 0, sizeof(nTrapTable));
std::unique_ptr<BYTE[]> pSBFile;
switch (leveltype) {
case DTYPE_TOWN:
if (gbIsHellfire)
pSBFile = LoadFileInMem("NLevels\\TownData\\Town.SOL", &dwTiles);
else
pSBFile = LoadFileInMem("Levels\\TownData\\Town.SOL", &dwTiles);
break;
return LoadFileInMem<uint8_t>("NLevels\\TownData\\Town.SOL", &tileCount);
return LoadFileInMem<uint8_t>("Levels\\TownData\\Town.SOL", &tileCount);
case DTYPE_CATHEDRAL:
if (currlevel < 17)
pSBFile = LoadFileInMem("Levels\\L1Data\\L1.SOL", &dwTiles);
else
pSBFile = LoadFileInMem("NLevels\\L5Data\\L5.SOL", &dwTiles);
break;
return LoadFileInMem<uint8_t>("Levels\\L1Data\\L1.SOL", &tileCount);
return LoadFileInMem<uint8_t>("NLevels\\L5Data\\L5.SOL", &tileCount);
case DTYPE_CATACOMBS:
pSBFile = LoadFileInMem("Levels\\L2Data\\L2.SOL", &dwTiles);
break;
return LoadFileInMem<uint8_t>("Levels\\L2Data\\L2.SOL", &tileCount);
case DTYPE_CAVES:
if (currlevel < 17)
pSBFile = LoadFileInMem("Levels\\L3Data\\L3.SOL", &dwTiles);
else
pSBFile = LoadFileInMem("NLevels\\L6Data\\L6.SOL", &dwTiles);
break;
return LoadFileInMem<uint8_t>("Levels\\L3Data\\L3.SOL", &tileCount);
return LoadFileInMem<uint8_t>("NLevels\\L6Data\\L6.SOL", &tileCount);
case DTYPE_HELL:
pSBFile = LoadFileInMem("Levels\\L4Data\\L4.SOL", &dwTiles);
break;
return LoadFileInMem<uint8_t>("Levels\\L4Data\\L4.SOL", &tileCount);
default:
app_fatal("FillSolidBlockTbls");
}
}
const BYTE *pTmp = pSBFile.get();
for (i = 1; i <= dwTiles; i++) {
bv = *pTmp++;
if ((bv & 0x01) != 0)
nSolidTable[i] = true;
if ((bv & 0x02) != 0)
nBlockTable[i] = true;
if ((bv & 0x04) != 0)
nMissileTable[i] = true;
if ((bv & 0x08) != 0)
nTransTable[i] = true;
if ((bv & 0x80) != 0)
nTrapTable[i] = true;
block_lvid[i] = (bv & 0x70) >> 4; /* beta: (bv >> 4) & 7 */
void FillSolidBlockTbls()
{
size_t tileCount;
auto pSBFile = LoadLevelSOLData(tileCount);
for (unsigned i = 0; i < tileCount; i++) {
uint8_t bv = pSBFile[i];
nSolidTable[i + 1] = (bv & 0x01) != 0;
nBlockTable[i + 1] = (bv & 0x02) != 0;
nMissileTable[i + 1] = (bv & 0x04) != 0;
nTransTable[i + 1] = (bv & 0x08) != 0;
nTrapTable[i + 1] = (bv & 0x80) != 0 ;
block_lvid[i + 1] = (bv & 0x70) >> 4;
}
}

42
Source/gendung.h

@ -99,6 +99,13 @@ struct THEME_LOC {
int16_t height;
};
struct MegaTile {
uint16_t micro1;
uint16_t micro2;
uint16_t micro3;
uint16_t micro4;
};
struct MICROS {
uint16_t mt[16];
};
@ -113,25 +120,40 @@ struct ShadowStruct {
uint8_t nv3;
};
extern BYTE dungeon[DMAXX][DMAXY];
extern BYTE pdungeon[DMAXX][DMAXY];
extern uint8_t dungeon[DMAXX][DMAXY];
extern uint8_t pdungeon[DMAXX][DMAXY];
extern char dflags[DMAXX][DMAXY];
extern int setpc_x;
extern int setpc_y;
extern int setpc_w;
extern int setpc_h;
extern std::unique_ptr<BYTE[]> pSetPiece;
extern std::unique_ptr<uint16_t[]> pSetPiece;
extern bool setloadflag;
extern std::optional<CelSprite> pSpecialCels;
extern std::unique_ptr<BYTE[]> pMegaTiles;
extern std::unique_ptr<MegaTile[]> pMegaTiles;
extern std::unique_ptr<BYTE[]> pLevelPieces;
extern std::unique_ptr<BYTE[]> pDungeonCels;
extern char block_lvid[MAXTILES + 1];
extern bool nBlockTable[MAXTILES + 1];
extern bool nSolidTable[MAXTILES + 1];
extern bool nTransTable[MAXTILES + 1];
extern bool nMissileTable[MAXTILES + 1];
extern bool nTrapTable[MAXTILES + 1];
/**
* List of transparancy masks to use for dPieces
*/
extern std::array<uint8_t, MAXTILES + 1> block_lvid;
/**
* List of light blocking dPieces
*/
extern std::array<bool, MAXTILES + 1> nBlockTable;
/**
* List of path blocking dPieces
*/
extern std::array<bool, MAXTILES + 1> nSolidTable;
/**
* List of transparent dPieces
*/
extern std::array<bool, MAXTILES + 1> nTransTable;
/**
* List of missile blocking dPieces
*/
extern std::array<bool, MAXTILES + 1> nMissileTable;
extern std::array<bool, MAXTILES + 1> nTrapTable;
extern int dminx;
extern int dminy;
extern int dmaxx;

4
Source/lighting.cpp

@ -894,14 +894,14 @@ void MakeLightTable()
}
{
auto trn = LoadFileInMem("PlrGFX\\Infra.TRN");
auto trn = LoadFileInMem<BYTE>("PlrGFX\\Infra.TRN");
for (i = 0; i < 256; i++) {
*tbl++ = trn[i];
}
}
{
auto trn = LoadFileInMem("PlrGFX\\Stone.TRN");
auto trn = LoadFileInMem<BYTE>("PlrGFX\\Stone.TRN");
for (i = 0; i < 256; i++) {
*tbl++ = trn[i];
}

6
Source/missiles.cpp

@ -1140,16 +1140,16 @@ void LoadMissileGFX(BYTE mi)
char pszName[256];
if ((mfd->mFlags & MFLAG_ALLOW_SPECIAL) != 0) {
sprintf(pszName, "Missiles\\%s.CL2", mfd->mName);
BYTE *file = LoadFileInMem(pszName, nullptr).release();
BYTE *file = LoadFileInMem<BYTE>(pszName).release();
for (unsigned i = 0; i < mfd->mAnimFAmt; i++)
mfd->mAnimData[i] = CelGetFrameStart(file, i);
} else if (mfd->mAnimFAmt == 1) {
sprintf(pszName, "Missiles\\%s.CL2", mfd->mName);
mfd->mAnimData[0] = LoadFileInMem(pszName, nullptr).release();
mfd->mAnimData[0] = LoadFileInMem<BYTE>(pszName).release();
} else {
for (unsigned i = 0; i < mfd->mAnimFAmt; i++) {
sprintf(pszName, "Missiles\\%s%u.CL2", mfd->mName, i + 1);
mfd->mAnimData[i] = LoadFileInMem(pszName, nullptr).release();
mfd->mAnimData[i] = LoadFileInMem<BYTE>(pszName).release();
}
}
}

81
Source/monster.cpp

@ -351,7 +351,7 @@ void InitMonsterGFX(int monst)
BYTE *celBuf;
{
auto celData = LoadFileInMem(strBuff);
auto celData = LoadFileInMem<BYTE>(strBuff);
celBuf = celData.get();
Monsters[monst].Anims[anim].CMem = std::move(celData);
}
@ -384,7 +384,7 @@ void InitMonsterGFX(int monst)
Monsters[monst].MData = &monsterdata[mtype];
if (monsterdata[mtype].has_trans) {
Monsters[monst].trans_file = LoadFileInMem(monsterdata[mtype].TransFile, nullptr).release();
Monsters[monst].trans_file = LoadFileInMem<BYTE>(monsterdata[mtype].TransFile).release();
InitMonsterTRN(monst, monsterdata[mtype].has_special);
delete[] Monsters[monst].trans_file;
}
@ -950,24 +950,24 @@ void PlaceQuestMonsters()
}
if (QuestStatus(Q_LTBANNER)) {
auto setp = LoadFileInMem("Levels\\L1Data\\Banner1.DUN");
SetMapMonsters(setp.get(), 2 * setpc_x, 2 * setpc_y);
auto dunData = LoadFileInMem<uint16_t>("Levels\\L1Data\\Banner1.DUN");
SetMapMonsters(dunData.get(), 2 * setpc_x, 2 * setpc_y);
}
if (QuestStatus(Q_BLOOD)) {
auto setp = LoadFileInMem("Levels\\L2Data\\Blood2.DUN");
SetMapMonsters(setp.get(), 2 * setpc_x, 2 * setpc_y);
auto dunData = LoadFileInMem<uint16_t>("Levels\\L2Data\\Blood2.DUN");
SetMapMonsters(dunData.get(), 2 * setpc_x, 2 * setpc_y);
}
if (QuestStatus(Q_BLIND)) {
auto setp = LoadFileInMem("Levels\\L2Data\\Blind2.DUN");
SetMapMonsters(setp.get(), 2 * setpc_x, 2 * setpc_y);
auto dunData = LoadFileInMem<uint16_t>("Levels\\L2Data\\Blind2.DUN");
SetMapMonsters(dunData.get(), 2 * setpc_x, 2 * setpc_y);
}
if (QuestStatus(Q_ANVIL)) {
auto setp = LoadFileInMem("Levels\\L3Data\\Anvil.DUN");
SetMapMonsters(setp.get(), 2 * setpc_x + 2, 2 * setpc_y + 2);
auto dunData = LoadFileInMem<uint16_t>("Levels\\L3Data\\Anvil.DUN");
SetMapMonsters(dunData.get(), 2 * setpc_x + 2, 2 * setpc_y + 2);
}
if (QuestStatus(Q_WARLORD)) {
auto setp = LoadFileInMem("Levels\\L4Data\\Warlord.DUN");
SetMapMonsters(setp.get(), 2 * setpc_x, 2 * setpc_y);
auto dunData = LoadFileInMem<uint16_t>("Levels\\L4Data\\Warlord.DUN");
SetMapMonsters(dunData.get(), 2 * setpc_x, 2 * setpc_y);
AddMonsterType(UniqMonst[UMT_WARLORD].mtype, PLACE_SCATTER);
}
if (QuestStatus(Q_VEIL)) {
@ -983,8 +983,8 @@ void PlaceQuestMonsters()
PlaceUniqueMonst(UMT_LAZURUS, 0, 0);
PlaceUniqueMonst(UMT_RED_VEX, 0, 0);
PlaceUniqueMonst(UMT_BLACKJADE, 0, 0);
auto setp = LoadFileInMem("Levels\\L4Data\\Vile1.DUN");
SetMapMonsters(setp.get(), 2 * setpc_x, 2 * setpc_y);
auto dunData = LoadFileInMem<uint16_t>("Levels\\L4Data\\Vile1.DUN");
SetMapMonsters(dunData.get(), 2 * setpc_x, 2 * setpc_y);
}
if (currlevel == 24) {
@ -1086,20 +1086,20 @@ void PlaceGroup(int mtype, int num, int leaderf, int leader)
void LoadDiabMonsts()
{
{
auto lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab1.DUN");
SetMapMonsters(lpSetPiece.get(), 2 * diabquad1x, 2 * diabquad1y);
auto dunData = LoadFileInMem<uint16_t>("Levels\\L4Data\\diab1.DUN");
SetMapMonsters(dunData.get(), 2 * diabquad1x, 2 * diabquad1y);
}
{
auto lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab2a.DUN");
SetMapMonsters(lpSetPiece.get(), 2 * diabquad2x, 2 * diabquad2y);
auto dunData = LoadFileInMem<uint16_t>("Levels\\L4Data\\diab2a.DUN");
SetMapMonsters(dunData.get(), 2 * diabquad2x, 2 * diabquad2y);
}
{
auto lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab3a.DUN");
SetMapMonsters(lpSetPiece.get(), 2 * diabquad3x, 2 * diabquad3y);
auto dunData = LoadFileInMem<uint16_t>("Levels\\L4Data\\diab3a.DUN");
SetMapMonsters(dunData.get(), 2 * diabquad3x, 2 * diabquad3y);
}
{
auto lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab4a.DUN");
SetMapMonsters(lpSetPiece.get(), 2 * diabquad4x, 2 * diabquad4y);
auto dunData = LoadFileInMem<uint16_t>("Levels\\L4Data\\diab4a.DUN");
SetMapMonsters(dunData.get(), 2 * diabquad4x, 2 * diabquad4y);
}
}
@ -1179,13 +1179,8 @@ void InitMonsters()
}
}
void SetMapMonsters(BYTE *pMap, int startx, int starty)
void SetMapMonsters(const uint16_t *dunData, int startx, int starty)
{
uint16_t rw, rh;
uint16_t *lm;
int i, j;
int mtype;
AddMonsterType(MT_GOLEM, PLACE_SPECIAL);
AddMonster(1, 0, DIR_S, 0, false);
AddMonster(1, 0, DIR_S, 0, false);
@ -1199,21 +1194,25 @@ void SetMapMonsters(BYTE *pMap, int startx, int starty)
PlaceUniqueMonst(UMT_RED_VEX, 0, 0);
PlaceUniqueMonst(UMT_BLACKJADE, 0, 0);
}
lm = (uint16_t *)pMap;
rw = SDL_SwapLE16(*lm++);
rh = SDL_SwapLE16(*lm++);
lm += rw * rh;
rw = rw * 2;
rh = rh * 2;
lm += rw * rh;
for (j = 0; j < rh; j++) {
for (i = 0; i < rw; i++) {
if (*lm != 0) {
mtype = AddMonsterType(MonstConvTbl[SDL_SwapLE16(*lm) - 1], PLACE_SPECIAL);
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
int layer2Offset = 2 + width * height;
// The rest of the layers are at dPiece scale
width *= 2;
height *= 2;
const uint16_t *monsterLayer = &dunData[layer2Offset + width * height];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
uint8_t monsterId = SDL_SwapLE16(monsterLayer[j * width + i]);
if (monsterId != 0) {
int mtype = AddMonsterType(MonstConvTbl[monsterId - 1], PLACE_SPECIAL);
PlaceMonster(nummonsters++, mtype, i + startx + 16, j + starty + 16);
}
lm++;
}
}
}

2
Source/monster.h

@ -215,7 +215,7 @@ void ClrAllMonsters();
void monster_some_crypt();
void PlaceGroup(int mtype, int num, int leaderf, int leader);
void InitMonsters();
void SetMapMonsters(BYTE *pMap, int startx, int starty);
void SetMapMonsters(const uint16_t *dunData, int startx, int starty);
void DeleteMonster(int i);
int AddMonster(int x, int y, direction dir, int mtype, bool InMap);
void monster_43C785(int i);

207
Source/objects.cpp

@ -314,7 +314,7 @@ void InitObjectGFX()
sprintf(filestr, "Objects\\%s.CEL", ObjHiveLoadList[i]);
else if (currlevel >= 21)
sprintf(filestr, "Objects\\%s.CEL", ObjCryptLoadList[i]);
pObjCels[numobjfiles] = LoadFileInMem(filestr);
pObjCels[numobjfiles] = LoadFileInMem<BYTE>(filestr);
numobjfiles++;
}
}
@ -762,85 +762,75 @@ void AddChestTraps()
}
}
void LoadMapObjects(BYTE *pMap, int startx, int starty, int x1, int y1, int w, int h, int leveridx)
void LoadMapObjects(const char *path, int startx, int starty, int x1, int y1, int w, int h, int leveridx)
{
int rw, rh, i, j, oi, type;
BYTE *lm;
long mapoff;
LoadMapObjsFlag = true;
InitObjFlag = true;
lm = pMap;
rw = *lm;
lm += 2;
rh = *lm;
mapoff = (rw * rh + 1) * 2;
rw *= 2;
rh *= 2;
mapoff += rw * 2 * rh * 2;
lm += mapoff;
for (j = 0; j < rh; j++) {
for (i = 0; i < rw; i++) {
if (*lm) {
type = *lm;
AddObject(ObjTypeConv[type], startx + 16 + i, starty + 16 + j);
oi = ObjIndex(startx + 16 + i, starty + 16 + j);
auto dunData = LoadFileInMem<uint16_t>(path);
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
int layer2Offset = 2 + width * height;
// The rest of the layers are at dPiece scale
width *= 2;
height *= 2;
const uint16_t *objectLayer = &dunData[layer2Offset + width * height * 2];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
uint8_t objectId = SDL_SwapLE16(objectLayer[j * width + i]);
if (objectId != 0) {
AddObject(ObjTypeConv[objectId], startx + 16 + i, starty + 16 + j);
int oi = ObjIndex(startx + 16 + i, starty + 16 + j);
SetObjMapRange(oi, x1, y1, x1 + w, y1 + h, leveridx);
}
lm += 2;
}
}
InitObjFlag = false;
LoadMapObjsFlag = false;
}
void LoadMapObjs(BYTE *pMap, int startx, int starty)
void LoadMapObjs(const char *path, int startx, int starty)
{
int rw, rh;
int i, j;
BYTE *lm;
long mapoff;
LoadMapObjsFlag = true;
InitObjFlag = true;
lm = pMap;
rw = *lm;
lm += 2;
rh = *lm;
mapoff = (rw * rh + 1) * 2;
rw *= 2;
rh *= 2;
mapoff += 2 * rw * rh * 2;
lm += mapoff;
for (j = 0; j < rh; j++) {
for (i = 0; i < rw; i++) {
if (*lm) {
AddObject(ObjTypeConv[*lm], startx + 16 + i, starty + 16 + j);
auto dunData = LoadFileInMem<uint16_t>(path);
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
int layer2Offset = 2 + width * height;
// The rest of the layers are at dPiece scale
width *= 2;
height *= 2;
const uint16_t *objectLayer = &dunData[layer2Offset + width * height * 2];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
uint8_t objectId = SDL_SwapLE16(objectLayer[j * width + i]);
if (objectId != 0) {
AddObject(ObjTypeConv[objectId], startx + 16 + i, starty + 16 + j);
}
lm += 2;
}
}
InitObjFlag = false;
LoadMapObjsFlag = false;
}
void AddDiabObjs()
{
{
auto lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab1.DUN");
LoadMapObjects(lpSetPiece.get(), 2 * diabquad1x, 2 * diabquad1y, diabquad2x, diabquad2y, 11, 12, 1);
}
{
auto lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab2a.DUN");
LoadMapObjects(lpSetPiece.get(), 2 * diabquad2x, 2 * diabquad2y, diabquad3x, diabquad3y, 11, 11, 2);
}
{
auto lpSetPiece = LoadFileInMem("Levels\\L4Data\\diab3a.DUN");
LoadMapObjects(lpSetPiece.get(), 2 * diabquad3x, 2 * diabquad3y, diabquad4x, diabquad4y, 9, 9, 3);
}
LoadMapObjects("Levels\\L4Data\\diab1.DUN", 2 * diabquad1x, 2 * diabquad1y, diabquad2x, diabquad2y, 11, 12, 1);
LoadMapObjects("Levels\\L4Data\\diab2a.DUN", 2 * diabquad2x, 2 * diabquad2y, diabquad3x, diabquad3y, 11, 11, 2);
LoadMapObjects("Levels\\L4Data\\diab3a.DUN", 2 * diabquad3x, 2 * diabquad3y, diabquad4x, diabquad4y, 9, 9, 3);
}
void objects_add_lv22(int s)
@ -1117,10 +1107,7 @@ void InitObjects()
}
quests[Q_BLIND]._qmsg = sp_id;
AddBookLever(setpc_x, setpc_y, setpc_w + setpc_x + 1, setpc_h + setpc_y + 1, sp_id);
{
auto mem = LoadFileInMem("Levels\\L2Data\\Blind2.DUN");
LoadMapObjs(mem.get(), 2 * setpc_x, 2 * setpc_y);
}
LoadMapObjs("Levels\\L2Data\\Blind2.DUN", 2 * setpc_x, 2 * setpc_y);
}
if (QuestStatus(Q_BLOOD)) {
_speech_id sp_id;
@ -1179,10 +1166,7 @@ void InitObjects()
}
quests[Q_WARLORD]._qmsg = sp_id;
AddBookLever(setpc_x, setpc_y, setpc_x + setpc_w, setpc_y + setpc_h, sp_id);
{
auto mem = LoadFileInMem("Levels\\L4Data\\Warlord.DUN");
LoadMapObjs(mem.get(), 2 * setpc_x, 2 * setpc_y);
}
LoadMapObjs("Levels\\L4Data\\Warlord.DUN", 2 * setpc_x, 2 * setpc_y);
}
if (QuestStatus(Q_BETRAYER) && !gbIsMultiplayer)
AddLazStand();
@ -1200,63 +1184,60 @@ void InitObjects()
}
}
void SetMapObjects(BYTE *pMap, int startx, int starty)
void SetMapObjects(const uint16_t *dunData, int startx, int starty)
{
int rw, rh;
int i, j;
BYTE *lm, *h;
long mapoff;
int fileload[56];
bool filesLoaded[56];
char filestr[32];
ClrAllObjects();
for (i = 0; i < 56; i++)
fileload[i] = false;
for (auto &fileLoaded : filesLoaded)
fileLoaded = false;
InitObjFlag = true;
for (i = 0; AllObjects[i].oload != -1; i++) {
for (int i = 0; AllObjects[i].oload != -1; i++) {
if (AllObjects[i].oload == 1 && leveltype == AllObjects[i].olvltype)
fileload[AllObjects[i].ofindex] = true;
filesLoaded[AllObjects[i].ofindex] = true;
}
lm = pMap;
rw = *lm;
lm += 2;
rh = *lm;
mapoff = (rw * rh + 1) * 2;
rw *= 2;
rh *= 2;
mapoff += 2 * rw * rh * 2;
lm += mapoff;
h = lm;
for (j = 0; j < rh; j++) {
for (i = 0; i < rw; i++) {
if (*lm) {
fileload[AllObjects[ObjTypeConv[*lm]].ofindex] = true;
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
int layer2Offset = 2 + width * height;
// The rest of the layers are at dPiece scale
width *= 2;
height *= 2;
const uint16_t *objectLayer = &dunData[layer2Offset + width * height * 2];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
uint8_t objectId = SDL_SwapLE16(objectLayer[j * width + i]);
if (objectId != 0) {
filesLoaded[AllObjects[ObjTypeConv[objectId]].ofindex] = true;
}
lm += 2;
}
}
for (i = OFILE_L1BRAZ; i <= OFILE_LZSTAND; i++) {
if (!fileload[i])
for (int i = OFILE_L1BRAZ; i <= OFILE_LZSTAND; i++) {
if (!filesLoaded[i])
continue;
ObjFileList[numobjfiles] = (object_graphic_id)i;
sprintf(filestr, "Objects\\%s.CEL", ObjMasterLoadList[i]);
pObjCels[numobjfiles] = LoadFileInMem(filestr);
pObjCels[numobjfiles] = LoadFileInMem<BYTE>(filestr);
numobjfiles++;
}
lm = h;
for (j = 0; j < rh; j++) {
for (i = 0; i < rw; i++) {
if (*lm)
AddObject(ObjTypeConv[*lm], startx + 16 + i, starty + 16 + j);
lm += 2;
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
uint8_t objectId = SDL_SwapLE16(objectLayer[j * width + i]);
if (objectId != 0) {
AddObject(ObjTypeConv[objectId], startx + 16 + i, starty + 16 + j);
}
}
}
InitObjFlag = false;
}
@ -2291,21 +2272,15 @@ void objects_set_door_piece(int x, int y)
void ObjSetMini(int x, int y, int v)
{
int xx, yy;
long v1, v2, v3, v4;
MegaTile mega = pMegaTiles[v - 1];
uint16_t *MegaTiles = (uint16_t *)&pMegaTiles[((uint16_t)v - 1) * 8];
v1 = SDL_SwapLE16(*(MegaTiles + 0)) + 1;
v2 = SDL_SwapLE16(*(MegaTiles + 1)) + 1;
v3 = SDL_SwapLE16(*(MegaTiles + 2)) + 1;
v4 = SDL_SwapLE16(*(MegaTiles + 3)) + 1;
int xx = 2 * x + 16;
int yy = 2 * y + 16;
xx = 2 * x + 16;
yy = 2 * y + 16;
ObjSetMicro(xx, yy, v1);
ObjSetMicro(xx + 1, yy, v2);
ObjSetMicro(xx, yy + 1, v3);
ObjSetMicro(xx + 1, yy + 1, v4);
ObjSetMicro(xx + 0, yy + 0, SDL_SwapLE16(mega.micro1) + 1);
ObjSetMicro(xx + 1, yy + 0, SDL_SwapLE16(mega.micro2) + 1);
ObjSetMicro(xx + 0, yy + 1, SDL_SwapLE16(mega.micro3) + 1);
ObjSetMicro(xx + 1, yy + 1, SDL_SwapLE16(mega.micro4) + 1);
}
void ObjL1Special(int x1, int y1, int x2, int y2)
@ -3349,10 +3324,7 @@ void OperatePedistal(int pnum, int i)
if (!deltaload)
PlaySfxLoc(LS_BLODSTAR, object[i].position.x, object[i].position.y);
ObjChangeMap(object[i]._oVar1, object[i]._oVar2, object[i]._oVar3, object[i]._oVar4);
{
auto mem = LoadFileInMem("Levels\\L2Data\\Blood2.DUN");
LoadMapObjs(mem.get(), 2 * setpc_x, 2 * setpc_y);
}
LoadMapObjs("Levels\\L2Data\\Blood2.DUN", 2 * setpc_x, 2 * setpc_y);
SpawnUnique(UITEM_ARMOFVAL, 2 * setpc_x + 25, 2 * setpc_y + 19);
object[i]._oSelFlag = 0;
}
@ -5368,8 +5340,7 @@ void SyncPedistal(int i)
}
if (object[i]._oVar6 == 3) {
ObjChangeMapResync(object[i]._oVar1, object[i]._oVar2, object[i]._oVar3, object[i]._oVar4);
auto setp = LoadFileInMem("Levels\\L2Data\\Blood2.DUN");
LoadMapObjs(setp.get(), 2 * setpc_x, 2 * setpc_y);
LoadMapObjs("Levels\\L2Data\\Blood2.DUN", 2 * setpc_x, 2 * setpc_y);
}
}

2
Source/objects.h

@ -58,7 +58,7 @@ void FreeObjectGFX();
void AddL1Objs(int x1, int y1, int x2, int y2);
void AddL2Objs(int x1, int y1, int x2, int y2);
void InitObjects();
void SetMapObjects(BYTE *pMap, int startx, int starty);
void SetMapObjects(const uint16_t *dunData, int startx, int starty);
void SetObjMapRange(int i, int x1, int y1, int x2, int y2, int v);
void SetBookMsg(int i, _speech_id msg);
void GetRndObjLoc(int randarea, int *xx, int *yy);

24
Source/palette.cpp

@ -120,20 +120,22 @@ static void GenerateBlendedLookupTable(SDL_Color *palette, int skipFrom, int ski
void LoadPalette(const char *pszFileName)
{
int i;
void *pBuf;
BYTE PalData[256][3];
assert(pszFileName);
SFileOpenFile(pszFileName, &pBuf);
SFileReadFileThreadSafe(pBuf, (char *)PalData, sizeof(PalData));
SFileCloseFile(pBuf);
struct Color {
uint8_t r;
uint8_t g;
uint8_t b;
};
std::array<Color, 256> PalData;
LoadFileInMem(pszFileName, PalData);
for (i = 0; i < 256; i++) {
orig_palette[i].r = PalData[i][0];
orig_palette[i].g = PalData[i][1];
orig_palette[i].b = PalData[i][2];
for (int i = 0; i < PalData.size(); i++) {
orig_palette[i].r = PalData[i].r;
orig_palette[i].g = PalData[i].g;
orig_palette[i].b = PalData[i].b;
#ifndef USE_SDL1
orig_palette[i].a = SDL_ALPHA_OPAQUE;
#endif

165
Source/quests.cpp

@ -378,137 +378,118 @@ void DrawSkelKing(int q, int x, int y)
void DrawWarLord(int x, int y)
{
int rw, rh;
int i, j;
BYTE *sp;
int v;
auto setp = LoadFileInMem("Levels\\L4Data\\Warlord2.DUN");
rw = setp[0];
sp = &setp[2];
rh = *sp;
sp += 2;
setpc_w = rw;
setpc_h = rh;
auto dunData = LoadFileInMem<uint16_t>("Levels\\L4Data\\Warlord2.DUN");
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
setpc_x = x;
setpc_y = y;
for (j = y; j < y + rh; j++) {
for (i = x; i < x + rw; i++) {
if (*sp != 0) {
v = *sp;
} else {
v = 6;
}
dungeon[i][j] = v;
sp += 2;
setpc_w = width;
setpc_h = height;
const uint16_t *tileLayer = &dunData[2];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]);
dungeon[x + i][y + j] = (tileId != 0) ? tileId : 6;
}
}
}
void DrawSChamber(int q, int x, int y)
{
int i, j;
int rw, rh;
int xx, yy;
BYTE *sp;
int v;
auto setp = LoadFileInMem("Levels\\L2Data\\Bonestr1.DUN");
rw = setp[0];
sp = &setp[2];
rh = *sp;
sp += 2;
setpc_w = rw;
setpc_h = rh;
auto dunData = LoadFileInMem<uint16_t>("Levels\\L2Data\\Bonestr1.DUN");
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
setpc_x = x;
setpc_y = y;
for (j = y; j < y + rh; j++) {
for (i = x; i < x + rw; i++) {
if (*sp != 0) {
v = *sp;
} else {
v = 3;
}
dungeon[i][j] = v;
sp += 2;
setpc_w = width;
setpc_h = height;
const uint16_t *tileLayer = &dunData[2];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]);
dungeon[x + i][y + j] = (tileId != 0) ? tileId : 3;
}
}
xx = 2 * x + 22;
yy = 2 * y + 23;
quests[q].position = { xx, yy };
quests[q].position = { 2 * x + 22, 2 * y + 23 };
}
void DrawLTBanner(int x, int y)
{
int rw, rh;
int i, j;
BYTE *sp;
auto setp = LoadFileInMem("Levels\\L1Data\\Banner1.DUN");
rw = setp[0];
sp = &setp[2];
rh = *sp;
sp += 2;
setpc_w = rw;
setpc_h = rh;
auto dunData = LoadFileInMem<uint16_t>("Levels\\L1Data\\Banner1.DUN");
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
setpc_x = x;
setpc_y = y;
for (j = 0; j < rh; j++) {
for (i = 0; i < rw; i++) {
if (*sp != 0) {
pdungeon[x + i][y + j] = *sp;
setpc_w = width;
setpc_h = height;
const uint16_t *tileLayer = &dunData[2];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]);
if (tileId != 0) {
pdungeon[x + i][y + j] = tileId;
}
sp += 2;
}
}
}
void DrawBlind(int x, int y)
{
int rw, rh;
int i, j;
BYTE *sp;
auto dunData = LoadFileInMem<uint16_t>("Levels\\L2Data\\Blind1.DUN");
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
auto setp = LoadFileInMem("Levels\\L2Data\\Blind1.DUN");
rw = setp[0];
sp = &setp[2];
rh = *sp;
sp += 2;
setpc_x = x;
setpc_y = y;
setpc_w = rw;
setpc_h = rh;
for (j = 0; j < rh; j++) {
for (i = 0; i < rw; i++) {
if (*sp != 0) {
pdungeon[x + i][y + j] = *sp;
setpc_w = width;
setpc_h = height;
const uint16_t *tileLayer = &dunData[2];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]);
if (tileId != 0) {
pdungeon[x + i][y + j] = tileId;
}
sp += 2;
}
}
}
void DrawBlood(int x, int y)
{
int rw, rh;
int i, j;
BYTE *sp;
auto dunData = LoadFileInMem<uint16_t>("Levels\\L2Data\\Blood2.DUN");
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
auto setp = LoadFileInMem("Levels\\L2Data\\Blood2.DUN");
rw = setp[0];
sp = &setp[2];
rh = *sp;
sp += 2;
setpc_x = x;
setpc_y = y;
setpc_w = rw;
setpc_h = rh;
for (j = 0; j < rh; j++) {
for (i = 0; i < rw; i++) {
if (*sp != 0) {
dungeon[x + i][y + j] = *sp;
setpc_w = width;
setpc_h = height;
const uint16_t *tileLayer = &dunData[2];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
uint8_t tileId = SDL_SwapLE16(tileLayer[j * width + i]);
if (tileId != 0) {
dungeon[x + i][y + j] = tileId;
}
sp += 2;
}
}
}

38
Source/setmaps.cpp

@ -117,27 +117,25 @@ void AddVileObjs()
SetObjMapRange(ObjIndex(35, 36), 7, 11, 13, 18, 3);
}
void DRLG_SetMapTrans(const char *sFileName)
void DRLG_SetMapTrans(const char *path)
{
int x, y;
int i, j;
BYTE *d;
DWORD dwOffset;
auto pLevelMap = LoadFileInMem(sFileName);
d = &pLevelMap[2];
x = pLevelMap[0];
y = *d;
dwOffset = (x * y + 1) * 2;
x *= 2;
y *= 2;
dwOffset += 3 * x * y * 2;
d += dwOffset;
for (j = 0; j < y; j++) {
for (i = 0; i < x; i++) {
dTransVal[16 + i][16 + j] = *d;
d += 2;
auto dunData = LoadFileInMem<uint16_t>(path);
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
int layer2Offset = 2 + width * height;
// The rest of the layers are at dPiece scale
width *= 2;
height *= 2;
const uint16_t *transparantLayer = &dunData[layer2Offset + width * height * 3];
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
dTransVal[16 + i][16 + j] = SDL_SwapLE16(*transparantLayer);
transparantLayer++;
}
}
}

103
Source/town.cpp

@ -17,47 +17,42 @@ namespace {
/**
* @brief Load level data into dPiece
* @param P3Tiles Tile set
* @param pSector Sector data
* @param megas Map from mega tiles to macro tiles
* @param path Path of dun file
* @param xi upper left destination
* @param yi upper left destination
* @param w width of sector
* @param h height of sector
* @param yy upper left destination
*/
void T_FillSector(BYTE *P3Tiles, BYTE *pSector, int xi, int yi, int w, int h)
void T_FillSector(MegaTile *megas, const char *path, int xi, int yy)
{
int i, j, xx, yy, nMap;
int16_t v1, v2, v3, v4, ii;
uint16_t *Sector;
auto dunData = LoadFileInMem<uint16_t>(path);
int width = SDL_SwapLE16(dunData[0]);
int height = SDL_SwapLE16(dunData[1]);
ii = 4;
yy = yi;
for (j = 0; j < h; j++) {
xx = xi;
for (i = 0; i < w; i++) {
uint16_t *Map;
const uint16_t *tileLayer = &dunData[2];
Map = (uint16_t *)&pSector[ii];
nMap = SDL_SwapLE16(*Map);
if (nMap) {
Sector = (((uint16_t *)&P3Tiles[(nMap - 1) * 8]));
v1 = SDL_SwapLE16(*(Sector + 0)) + 1;
v2 = SDL_SwapLE16(*(Sector + 1)) + 1;
v3 = SDL_SwapLE16(*(Sector + 2)) + 1;
v4 = SDL_SwapLE16(*(Sector + 3)) + 1;
for (int j = 0; j < height; j++) {
int xx = xi;
for (int i = 0; i < width; i++) {
int v1 = 0;
int v2 = 0;
int v3 = 0;
int v4 = 0;
} else {
v1 = 0;
v2 = 0;
v3 = 0;
v4 = 0;
int tileId = SDL_SwapLE16(tileLayer[j * width + i]) - 1;
if (tileId >= 0) {
MegaTile mega = pMegaTiles[tileId];
v1 = SDL_SwapLE16(mega.micro1) + 1;
v2 = SDL_SwapLE16(mega.micro2) + 1;
v3 = SDL_SwapLE16(mega.micro3) + 1;
v4 = SDL_SwapLE16(mega.micro4) + 1;
}
dPiece[xx][yy] = v1;
dPiece[xx + 1][yy] = v2;
dPiece[xx][yy + 1] = v3;
dPiece[xx + 0][yy + 0] = v1;
dPiece[xx + 1][yy + 0] = v2;
dPiece[xx + 0][yy + 1] = v3;
dPiece[xx + 1][yy + 1] = v4;
xx += 2;
ii += 2;
}
yy += 2;
}
@ -65,26 +60,17 @@ void T_FillSector(BYTE *P3Tiles, BYTE *pSector, int xi, int yi, int w, int h)
/**
* @brief Load a tile in to dPiece
* @param P3Tiles Tile set
* @param megas Map from mega tiles to macro tiles
* @param xx upper left destination
* @param yy upper left destination
* @param t tile id
*/
void T_FillTile(BYTE *P3Tiles, int xx, int yy, int t)
void T_FillTile(MegaTile *megas, int xx, int yy, int t)
{
long v1, v2, v3, v4;
uint16_t *Tiles;
Tiles = ((uint16_t *)&P3Tiles[(t - 1) * 8]);
v1 = SDL_SwapLE16(*(Tiles + 0)) + 1;
v2 = SDL_SwapLE16(*(Tiles + 1)) + 1;
v3 = SDL_SwapLE16(*(Tiles + 2)) + 1;
v4 = SDL_SwapLE16(*(Tiles + 3)) + 1;
dPiece[xx][yy] = v1;
dPiece[xx + 1][yy] = v2;
dPiece[xx][yy + 1] = v3;
dPiece[xx + 1][yy + 1] = v4;
dPiece[xx + 0][yy + 0] = SDL_SwapLE16(megas[t - 1].micro1) + 1;
dPiece[xx + 1][yy + 0] = SDL_SwapLE16(megas[t - 1].micro2) + 1;
dPiece[xx + 0][yy + 1] = SDL_SwapLE16(megas[t - 1].micro3) + 1;
dPiece[xx + 1][yy + 1] = SDL_SwapLE16(megas[t - 1].micro4) + 1;
}
/**
@ -175,23 +161,12 @@ void T_Pass3()
}
}
auto P3Tiles = LoadFileInMem("Levels\\TownData\\Town.TIL");
{
auto pSector = LoadFileInMem("Levels\\TownData\\Sector1s.DUN");
T_FillSector(P3Tiles.get(), pSector.get(), 46, 46, 25, 25);
}
{
auto pSector = LoadFileInMem("Levels\\TownData\\Sector2s.DUN");
T_FillSector(P3Tiles.get(), pSector.get(), 46, 0, 25, 23);
}
{
auto pSector = LoadFileInMem("Levels\\TownData\\Sector3s.DUN");
T_FillSector(P3Tiles.get(), pSector.get(), 0, 46, 23, 25);
}
{
auto pSector = LoadFileInMem("Levels\\TownData\\Sector4s.DUN");
T_FillSector(P3Tiles.get(), pSector.get(), 0, 0, 23, 23);
}
auto P3Tiles = LoadFileInMem<MegaTile>("Levels\\TownData\\Town.TIL");
T_FillSector(P3Tiles.get(), "Levels\\TownData\\Sector1s.DUN", 46, 46);
T_FillSector(P3Tiles.get(), "Levels\\TownData\\Sector2s.DUN", 46, 0);
T_FillSector(P3Tiles.get(), "Levels\\TownData\\Sector3s.DUN", 0, 46);
T_FillSector(P3Tiles.get(), "Levels\\TownData\\Sector4s.DUN", 0, 0);
if (gbIsSpawn || !gbIsMultiplayer) {
if (gbIsSpawn || (!(plr[myplr].pTownWarps & 1) && (!gbIsHellfire || plr[myplr]._pLevel < 10))) {

66
Source/towners.cpp

@ -186,16 +186,16 @@ int GetActiveTowner(int t)
return -1;
}
void SetTownerGPtrs(BYTE *pData, BYTE **pAnim)
void SetTownerGPtrs(BYTE *pData, byte **pAnim)
{
for (int i = 0; i < 8; i++) {
pAnim[i] = CelGetFrameStart(pData, i);
pAnim[i] = (byte *)CelGetFrameStart(pData, i);
}
}
void NewTownerAnim(int tnum, BYTE *pAnim, uint8_t numFrames, int Delay)
void NewTownerAnim(int tnum, byte *pAnim, uint8_t numFrames, int Delay)
{
towners[tnum]._tAnimData = pAnim;
towners[tnum]._tAnimData = (BYTE *)pAnim;
towners[tnum]._tAnimLen = numFrames;
towners[tnum]._tAnimFrame = 1;
towners[tnum]._tAnimCnt = 0;
@ -232,9 +232,9 @@ void InitSmith()
InitTownerInfo(numtowners, 96, true, TOWN_SMITH, 62, 63, 0);
InitQstSnds(numtowners, TOWN_SMITH);
towners[numtowners]._tNData = LoadFileInMem("Towners\\Smith\\SmithN.CEL");
towners[numtowners]._tNData = LoadFileInMem<BYTE>("Towners\\Smith\\SmithN.CEL");
for (i = 0; i < 8; i++) {
towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get();
towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get();
}
towners[numtowners]._tNFrames = 16;
NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_SW], towners[numtowners]._tNFrames, 3);
@ -246,9 +246,9 @@ void InitBarOwner()
{
InitTownerInfo(numtowners, 96, true, TOWN_TAVERN, 55, 62, 3);
InitQstSnds(numtowners, TOWN_TAVERN);
towners[numtowners]._tNData = LoadFileInMem("Towners\\TwnF\\TwnFN.CEL");
towners[numtowners]._tNData = LoadFileInMem<BYTE>("Towners\\TwnF\\TwnFN.CEL");
for (auto &towner : towners[numtowners]._tNAnim) {
towner = towners[numtowners]._tNData.get();
towner = (byte *)towners[numtowners]._tNData.get();
}
towners[numtowners]._tNFrames = 16;
NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_SW], towners[numtowners]._tNFrames, 3);
@ -262,9 +262,9 @@ void InitTownDead()
InitTownerInfo(numtowners, 96, true, TOWN_DEADGUY, 24, 32, -1);
InitQstSnds(numtowners, TOWN_DEADGUY);
towners[numtowners]._tNData = LoadFileInMem("Towners\\Butch\\Deadguy.CEL");
towners[numtowners]._tNData = LoadFileInMem<BYTE>("Towners\\Butch\\Deadguy.CEL");
for (i = 0; i < 8; i++) {
towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get();
towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get();
}
towners[numtowners]._tNFrames = 8;
NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_N], towners[numtowners]._tNFrames, 6);
@ -278,13 +278,13 @@ void InitWitch()
InitTownerInfo(numtowners, 96, true, TOWN_WITCH, 80, 20, 5);
InitQstSnds(numtowners, TOWN_WITCH);
towners[numtowners]._tNData = LoadFileInMem("Towners\\TownWmn1\\Witch.CEL");
towners[numtowners]._tNData = LoadFileInMem<BYTE>("Towners\\TownWmn1\\Witch.CEL");
for (i = 0; i < 8; i++) {
towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get();
towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get();
}
towners[numtowners]._tNFrames = 19;
NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_S], towners[numtowners]._tNFrames, 6);
towners[numtowners]._tName = _("Adria the Witch");
towners[numtowners]._tName = _("Adria the Witch");
numtowners++;
}
@ -294,9 +294,9 @@ void InitBarmaid()
InitTownerInfo(numtowners, 96, true, TOWN_BMAID, 43, 66, -1);
InitQstSnds(numtowners, TOWN_BMAID);
towners[numtowners]._tNData = LoadFileInMem("Towners\\TownWmn1\\WmnN.CEL");
towners[numtowners]._tNData = LoadFileInMem<BYTE>("Towners\\TownWmn1\\WmnN.CEL");
for (i = 0; i < 8; i++) {
towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get();
towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get();
}
towners[numtowners]._tNFrames = 18;
NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_S], towners[numtowners]._tNFrames, 6);
@ -310,9 +310,9 @@ void InitBoy()
InitTownerInfo(numtowners, 96, true, TOWN_PEGBOY, 11, 53, -1);
InitQstSnds(numtowners, TOWN_PEGBOY);
towners[numtowners]._tNData = LoadFileInMem("Towners\\TownBoy\\PegKid1.CEL");
towners[numtowners]._tNData = LoadFileInMem<BYTE>("Towners\\TownBoy\\PegKid1.CEL");
for (i = 0; i < 8; i++) {
towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get();
towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get();
}
towners[numtowners]._tNFrames = 20;
NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_S], towners[numtowners]._tNFrames, 6);
@ -326,9 +326,9 @@ void InitHealer()
InitTownerInfo(numtowners, 96, true, TOWN_HEALER, 55, 79, 1);
InitQstSnds(numtowners, TOWN_HEALER);
towners[numtowners]._tNData = LoadFileInMem("Towners\\Healer\\Healer.CEL");
towners[numtowners]._tNData = LoadFileInMem<BYTE>("Towners\\Healer\\Healer.CEL");
for (i = 0; i < 8; i++) {
towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get();
towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get();
}
towners[numtowners]._tNFrames = 20;
NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_SE], towners[numtowners]._tNFrames, 6);
@ -342,9 +342,9 @@ void InitTeller()
InitTownerInfo(numtowners, 96, true, TOWN_STORY, 62, 71, 2);
InitQstSnds(numtowners, TOWN_STORY);
towners[numtowners]._tNData = LoadFileInMem("Towners\\Strytell\\Strytell.CEL");
towners[numtowners]._tNData = LoadFileInMem<BYTE>("Towners\\Strytell\\Strytell.CEL");
for (i = 0; i < 8; i++) {
towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get();
towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get();
}
towners[numtowners]._tNFrames = 25;
NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_S], towners[numtowners]._tNFrames, 3);
@ -358,9 +358,9 @@ void InitDrunk()
InitTownerInfo(numtowners, 96, true, TOWN_DRUNK, 71, 84, 4);
InitQstSnds(numtowners, TOWN_DRUNK);
towners[numtowners]._tNData = LoadFileInMem("Towners\\Drunk\\TwnDrunk.CEL");
towners[numtowners]._tNData = LoadFileInMem<BYTE>("Towners\\Drunk\\TwnDrunk.CEL");
for (i = 0; i < 8; i++) {
towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get();
towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get();
}
towners[numtowners]._tNFrames = 18;
NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_S], towners[numtowners]._tNFrames, 3);
@ -375,7 +375,7 @@ void InitCows()
//if ( pCowCels )
// assertion_failed(__LINE__, __FILE__, "! pCowCels");
pCowCels = LoadFileInMem("Towners\\Animals\\Cow.CEL");
pCowCels = LoadFileInMem<BYTE>("Towners\\Animals\\Cow.CEL");
for (i = 0; i < 3; i++) {
x = TownCowX[i];
y = TownCowY[i];
@ -408,9 +408,9 @@ void InitFarmer()
InitTownerInfo(numtowners, 96, true, TOWN_FARMER, 62, 16, -1);
InitQstSnds(numtowners, TOWN_FARMER);
towners[numtowners]._tNData = LoadFileInMem("Towners\\Farmer\\Farmrn2.CEL");
towners[numtowners]._tNData = LoadFileInMem<BYTE>("Towners\\Farmer\\Farmrn2.CEL");
for (i = 0; i < 8; i++) {
towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get();
towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get();
}
towners[numtowners]._tNFrames = 15;
NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_S], towners[numtowners]._tNFrames, 3);
@ -425,12 +425,12 @@ void InitCowFarmer()
InitTownerInfo(numtowners, 96, true, TOWN_COWFARM, 61, 22, -1);
InitQstSnds(numtowners, TOWN_COWFARM);
if (quests[Q_JERSEY]._qactive != QUEST_DONE) {
towners[numtowners]._tNData = LoadFileInMem("Towners\\Farmer\\cfrmrn2.CEL");
towners[numtowners]._tNData = LoadFileInMem<BYTE>("Towners\\Farmer\\cfrmrn2.CEL");
} else {
towners[numtowners]._tNData = LoadFileInMem("Towners\\Farmer\\mfrmrn2.CEL");
towners[numtowners]._tNData = LoadFileInMem<BYTE>("Towners\\Farmer\\mfrmrn2.CEL");
}
for (i = 0; i < 8; i++) {
towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get();
towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get();
}
towners[numtowners]._tNFrames = 15;
NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_SW], towners[numtowners]._tNFrames, 3);
@ -445,16 +445,16 @@ void InitGirl()
InitTownerInfo(numtowners, 96, true, TOWN_GIRL, 77, 43, -1);
InitQstSnds(numtowners, TOWN_GIRL);
if (quests[Q_GIRL]._qactive != QUEST_DONE) {
towners[numtowners]._tNData = LoadFileInMem("Towners\\Girl\\Girlw1.CEL");
towners[numtowners]._tNData = LoadFileInMem<BYTE>("Towners\\Girl\\Girlw1.CEL");
} else {
towners[numtowners]._tNData = LoadFileInMem("Towners\\Girl\\Girls1.CEL");
towners[numtowners]._tNData = LoadFileInMem<BYTE>("Towners\\Girl\\Girls1.CEL");
}
for (i = 0; i < 8; i++) {
towners[numtowners]._tNAnim[i] = towners[numtowners]._tNData.get();
towners[numtowners]._tNAnim[i] = (byte *)towners[numtowners]._tNData.get();
}
towners[numtowners]._tNFrames = 20;
NewTownerAnim(numtowners, towners[numtowners]._tNAnim[DIR_S], towners[numtowners]._tNFrames, 6);
towners[numtowners]._tName = {"Celia"};
towners[numtowners]._tName = "Celia";
numtowners++;
}

2
Source/towners.h

@ -41,7 +41,7 @@ struct TNQ {
};
struct TownerStruct {
uint8_t *_tNAnim[8];
byte *_tNAnim[8];
std::unique_ptr<BYTE[]> _tNData;
uint8_t *_tAnimData;
int16_t _tSeed;

Loading…
Cancel
Save