Browse Source

🚚 Move local code to anonymous namespace

pull/2351/head
Anders Jenbo 5 years ago
parent
commit
74b57558c9
  1. 79
      Source/drlg_l1.cpp
  2. 4
      Source/drlg_l1.h
  3. 3
      Source/drlg_l2.cpp
  4. 2
      Source/drlg_l3.cpp
  5. 8
      Source/drlg_l4.cpp
  6. 2
      Source/effects.cpp
  7. 54
      Source/encrypt.cpp
  8. 71
      Source/engine.cpp
  9. 2
      Source/engine.h
  10. 7
      Source/error.cpp
  11. 396
      Source/gendung.cpp
  12. 45
      Source/gendung.h
  13. 173
      Source/gmenu.cpp
  14. 7
      Source/help.cpp
  15. 5
      Source/interfac.cpp
  16. 1394
      Source/inv.cpp
  17. 5020
      Source/items.cpp
  18. 6
      Source/items.h
  19. 15
      Source/movie.cpp
  20. 1
      Source/movie.h

79
Source/drlg_l1.cpp

@ -9,7 +9,6 @@
#include "engine/point.hpp"
#include "engine/random.hpp"
#include "gendung.h"
#include "lighting.h"
#include "player.h"
#include "quests.h"
@ -1375,37 +1374,43 @@ void AddWall()
for (int j = 0; j < DMAXY; j++) {
for (int i = 0; i < DMAXX; i++) {
if (L5dflags[i][j] == 0) {
if (dungeon[i][j] == 3 && GenerateRnd(100) < WALL_CHANCE) {
if (dungeon[i][j] == 3) {
GenerateRnd(100);
int x = HorizontalWallOk(i, j);
if (x != -1) {
HorizontalWall(i, j, 2, x);
}
}
if (dungeon[i][j] == 3 && GenerateRnd(100) < WALL_CHANCE) {
if (dungeon[i][j] == 3) {
GenerateRnd(100);
int y = VerticalWallOk(i, j);
if (y != -1) {
VerticalWall(i, j, 1, y);
}
}
if (dungeon[i][j] == 6 && GenerateRnd(100) < WALL_CHANCE) {
if (dungeon[i][j] == 6) {
GenerateRnd(100);
int x = HorizontalWallOk(i, j);
if (x != -1) {
HorizontalWall(i, j, 4, x);
}
}
if (dungeon[i][j] == 7 && GenerateRnd(100) < WALL_CHANCE) {
if (dungeon[i][j] == 7) {
GenerateRnd(100);
int y = VerticalWallOk(i, j);
if (y != -1) {
VerticalWall(i, j, 4, y);
}
}
if (dungeon[i][j] == 2 && GenerateRnd(100) < WALL_CHANCE) {
if (dungeon[i][j] == 2) {
GenerateRnd(100);
int x = HorizontalWallOk(i, j);
if (x != -1) {
HorizontalWall(i, j, 2, x);
}
}
if (dungeon[i][j] == 1 && GenerateRnd(100) < WALL_CHANCE) {
if (dungeon[i][j] == 1) {
GenerateRnd(100);
int y = VerticalWallOk(i, j);
if (y != -1) {
VerticalWall(i, j, 1, y);
@ -2460,66 +2465,6 @@ void Pass3()
} // namespace
void DRLG_LPass3(int lv)
{
{
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 + 0][j + 0] = v1;
dPiece[i + 1][j + 0] = v2;
dPiece[i + 0][j + 1] = v3;
dPiece[i + 1][j + 1] = v4;
}
}
}
int yy = 16;
for (int j = 0; j < DMAXY; j++) {
int xx = 16;
for (int i = 0; i < DMAXX; i++) { // NOLINT(modernize-loop-convert)
int v1 = 0;
int v2 = 0;
int v3 = 0;
int 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 + 0][yy + 0] = v1;
dPiece[xx + 1][yy + 0] = v2;
dPiece[xx + 0][yy + 1] = v3;
dPiece[xx + 1][yy + 1] = v4;
xx += 2;
}
yy += 2;
}
}
void DRLG_Init_Globals()
{
memset(dFlags, 0, sizeof(dFlags));
memset(dPlayer, 0, sizeof(dPlayer));
memset(dMonster, 0, sizeof(dMonster));
memset(dDead, 0, sizeof(dDead));
memset(dObject, 0, sizeof(dObject));
memset(dItem, 0, sizeof(dItem));
memset(dMissile, 0, sizeof(dMissile));
memset(dSpecial, 0, sizeof(dSpecial));
int8_t c = DisableLighting ? 0 : 15;
memset(dLight, c, sizeof(dLight));
}
void LoadL1Dungeon(const char *path, int vx, int vy)
{
dminx = 16;

4
Source/drlg_l1.h

@ -9,16 +9,12 @@
namespace devilution {
#define WALL_CHANCE 100
extern int UberRow;
extern int UberCol;
extern bool IsUberRoomOpened;
extern bool IsUberLeverActivated;
extern int UberDiabloMonsterIndex;
void DRLG_LPass3(int lv);
void DRLG_Init_Globals();
void LoadL1Dungeon(const char *path, int vx, int vy);
void LoadPreL1Dungeon(const char *path);
void CreateL5Dungeon(uint32_t rseed, lvl_entry entry);

3
Source/drlg_l2.cpp

@ -9,10 +9,9 @@
#include <list>
#include "diablo.h"
#include "drlg_l1.h"
#include "engine/load_file.hpp"
#include "engine/random.hpp"
#include "objects.h"
#include "gendung.h"
#include "player.h"
#include "quests.h"
#include "setmaps.h"

2
Source/drlg_l3.cpp

@ -6,9 +6,9 @@
#include <algorithm>
#include "drlg_l1.h"
#include "engine/load_file.hpp"
#include "engine/random.hpp"
#include "gendung.h"
#include "lighting.h"
#include "monster.h"
#include "objdat.h"

8
Source/drlg_l4.cpp

@ -5,9 +5,9 @@
*/
#include "drlg_l4.h"
#include "drlg_l1.h"
#include "engine/load_file.hpp"
#include "engine/random.hpp"
#include "gendung.h"
#include "monster.h"
#include "multi.h"
#include "objdat.h"
@ -640,13 +640,15 @@ void AddWall()
if (dflags[i][j] != 0) {
continue;
}
if (IsAnyOf(dungeon[i][j], 10, 12, 13, 15, 16, 21, 22) && GenerateRnd(100) < WALL_CHANCE) {
if (IsAnyOf(dungeon[i][j], 10, 12, 13, 15, 16, 21, 22)) {
GenerateRnd(100);
int x = HorizontalWallOk(i, j);
if (x != -1) {
HorizontalWall(i, j, x);
}
}
if (IsAnyOf(dungeon[i][j], 8, 9, 11, 14, 15, 16, 21, 23) && GenerateRnd(100) < WALL_CHANCE) {
if (IsAnyOf(dungeon[i][j], 8, 9, 11, 14, 15, 16, 21, 23)) {
GenerateRnd(100);
int y = VerticalWallOk(i, j);
if (y != -1) {
VerticalWall(i, j, y);

2
Source/effects.cpp

@ -1394,7 +1394,7 @@ int GetSFXLength(int nSFX)
#ifdef RUN_TESTS
bool TestCalculatePosition(Point soundPosition, int *plVolume, int *plPan)
{
CalculatePosition(soundPosition, plVolume, plPan);
return CalculatePosition(soundPosition, plVolume, plPan);
}
#endif

54
Source/encrypt.cpp

@ -11,6 +11,35 @@
namespace devilution {
namespace {
static unsigned int PkwareBufferRead(char *buf, unsigned int *size, void *param) // NOLINT(readability-non-const-parameter)
{
auto *pInfo = (TDataInfo *)param;
uint32_t sSize;
if (*size >= pInfo->size - pInfo->srcOffset) {
sSize = pInfo->size - pInfo->srcOffset;
} else {
sSize = *size;
}
memcpy(buf, pInfo->srcData + pInfo->srcOffset, sSize);
pInfo->srcOffset += sSize;
return sSize;
}
static void PkwareBufferWrite(char *buf, unsigned int *size, void *param) // NOLINT(readability-non-const-parameter)
{
auto *pInfo = (TDataInfo *)param;
memcpy(pInfo->destData + pInfo->destOffset, buf, *size);
pInfo->destOffset += *size;
}
} // namespace
static uint32_t hashtable[5][256];
void Decrypt(uint32_t *castBlock, uint32_t size, uint32_t key)
@ -69,31 +98,6 @@ void InitHash()
}
}
static unsigned int PkwareBufferRead(char *buf, unsigned int *size, void *param) // NOLINT(readability-non-const-parameter)
{
auto *pInfo = (TDataInfo *)param;
uint32_t sSize;
if (*size >= pInfo->size - pInfo->srcOffset) {
sSize = pInfo->size - pInfo->srcOffset;
} else {
sSize = *size;
}
memcpy(buf, pInfo->srcData + pInfo->srcOffset, sSize);
pInfo->srcOffset += sSize;
return sSize;
}
static void PkwareBufferWrite(char *buf, unsigned int *size, void *param) // NOLINT(readability-non-const-parameter)
{
auto *pInfo = (TDataInfo *)param;
memcpy(pInfo->destData + pInfo->destOffset, buf, *size);
pInfo->destOffset += *size;
}
uint32_t PkwareCompress(byte *srcData, uint32_t size)
{
std::unique_ptr<char[]> ptr { new char[CMP_BUFFER_SIZE] };

71
Source/engine.cpp

@ -19,6 +19,35 @@
#include "options.h"
namespace devilution {
namespace {
static void DrawHalfTransparentBlendedRectTo(const Surface &out, int sx, int sy, int width, int height)
{
BYTE *pix = out.at(sx, sy);
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
*pix = paletteTransparencyLookup[0][*pix];
pix++;
}
pix += out.pitch() - width;
}
}
static void DrawHalfTransparentStippledRectTo(const Surface &out, int sx, int sy, int width, int height)
{
BYTE *pix = out.at(sx, sy);
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
if (((row & 1) != 0 && (col & 1) != 0) || ((row & 1) == 0 && (col & 1) == 0))
*pix = 0;
pix++;
}
pix += out.pitch() - width;
}
}
} // namespace
void DrawHorizontalLine(const Surface &out, Point from, int width, std::uint8_t colorIndex)
{
@ -61,33 +90,6 @@ void UnsafeDrawVerticalLine(const Surface &out, Point from, int height, std::uin
}
}
static void DrawHalfTransparentBlendedRectTo(const Surface &out, int sx, int sy, int width, int height)
{
BYTE *pix = out.at(sx, sy);
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
*pix = paletteTransparencyLookup[0][*pix];
pix++;
}
pix += out.pitch() - width;
}
}
static void DrawHalfTransparentStippledRectTo(const Surface &out, int sx, int sy, int width, int height)
{
BYTE *pix = out.at(sx, sy);
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
if (((row & 1) != 0 && (col & 1) != 0) || ((row & 1) == 0 && (col & 1) == 0))
*pix = 0;
pix++;
}
pix += out.pitch() - width;
}
}
void DrawHalfTransparentRectTo(const Surface &out, int sx, int sy, int width, int height)
{
if (sx + width < 0)
@ -179,19 +181,4 @@ int CalculateWidth2(int width)
return (width - 64) / 2;
}
/**
* @brief Fade to black and play a video
* @param pszMovie file path of movie
*/
void PlayInGameMovie(const char *pszMovie)
{
PaletteFadeOut(8);
play_movie(pszMovie, false);
ClearScreenBuffer();
force_redraw = 255;
scrollrt_draw_game_screen();
PaletteFadeIn(8);
force_redraw = 255;
}
} // namespace devilution

2
Source/engine.h

@ -120,6 +120,4 @@ Direction GetDirection(Point start, Point destination);
*/
int CalculateWidth2(int width);
void PlayInGameMovie(const char *pszMovie);
} // namespace devilution

7
Source/error.cpp

@ -13,11 +13,16 @@
namespace devilution {
diablo_message msgtable[MAX_SEND_STR_LEN];
DWORD msgdelay;
diablo_message msgflag;
namespace {
diablo_message msgtable[MAX_SEND_STR_LEN];
uint8_t msgcnt;
} // namespace
/** Maps from error_id to error message. */
const char *const MsgStrings[] = {
"",

396
Source/gendung.cpp

@ -8,29 +8,21 @@
#include "engine/load_file.hpp"
#include "engine/random.hpp"
#include "init.h"
#include "lighting.h"
#include "options.h"
namespace devilution {
/** Contains the tile IDs of the map. */
uint8_t dungeon[DMAXX][DMAXY];
/** Contains a backup of the tile IDs of the map. */
uint8_t pdungeon[DMAXX][DMAXY];
char dflags[DMAXX][DMAXY];
/** Specifies the active set level X-coordinate of the map. */
int setpc_x;
/** Specifies the active set level Y-coordinate of the map. */
int setpc_y;
/** Specifies the width of the active set level of the map. */
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<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<MegaTile[]> pMegaTiles;
std::unique_ptr<uint16_t[]> pLevelPieces;
std::unique_ptr<byte[]> pDungeonCels;
@ -40,71 +32,39 @@ 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. */
int dminy;
/** Specifies the maximum X-coordinate of the map. */
int dmaxx;
/** Specifies the maximum Y-coordinate of the map. */
int dmaxy;
/** Specifies the active dungeon type of the current game. */
dungeon_type leveltype;
/** Specifies the active dungeon level of the current game. */
BYTE currlevel;
bool setlevel;
/** Specifies the active quest level of the current game. */
_setlevels setlvlnum;
/** Level type of the active quest level */
dungeon_type setlvltype;
/** Specifies the player viewpoint X-coordinate of the map. */
int ViewX;
/** Specifies the player viewpoint Y-coordinate of the map. */
int ViewY;
ScrollStruct ScrollInfo;
int MicroTileLen;
char TransVal;
/** Specifies the active transparency indices. */
bool TransList[256];
/** Contains the piece IDs of each tile on the map. */
int dPiece[MAXDUNX][MAXDUNY];
/** Specifies the dungeon piece information for a given coordinate and block number. */
MICROS dpiece_defs_map_2[MAXDUNX][MAXDUNY];
/** Specifies the transparency at each coordinate of the map. */
int8_t dTransVal[MAXDUNX][MAXDUNY];
char dLight[MAXDUNX][MAXDUNY];
char dPreLight[MAXDUNX][MAXDUNY];
int8_t dFlags[MAXDUNX][MAXDUNY];
/** Contains the player numbers (players array indices) of the map. */
int8_t dPlayer[MAXDUNX][MAXDUNY];
/**
* Contains the NPC numbers of the map. The NPC number represents a
* towner number (towners array index) in Tristram and a monster number
* (monsters array index) in the dungeon.
*/
int16_t dMonster[MAXDUNX][MAXDUNY];
/**
* Contains the dead numbers (deads array indices) and dead direction of
* the map, encoded as specified by the pseudo-code below.
* dDead[x][y] & 0x1F - index of dead
* dDead[x][y] >> 0x5 - direction
*/
int8_t dDead[MAXDUNX][MAXDUNY];
/** Contains the object numbers (objects array indices) of the map. */
char dObject[MAXDUNX][MAXDUNY];
/** Contains the item numbers (items array indices) of the map. */
int8_t dItem[MAXDUNX][MAXDUNY];
/** Contains the missile numbers (missiles array indices) of the map. */
int8_t dMissile[MAXDUNX][MAXDUNY];
/**
* Contains the arch frame numbers of the map from the special tileset
* (e.g. "levels/l1data/l1s.cel"). Note, the special tileset of Tristram (i.e.
* "levels/towndata/towns.cel") contains trees rather than arches.
*/
char dSpecial[MAXDUNX][MAXDUNY];
int themeCount;
THEME_LOC themeLoc[MAXTHEMES];
namespace {
std::unique_ptr<uint8_t[]> LoadLevelSOLData(size_t &tileCount)
{
switch (leveltype) {
@ -129,150 +89,6 @@ std::unique_ptr<uint8_t[]> LoadLevelSOLData(size_t &tileCount)
}
}
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;
}
}
void SetDungeonMicros()
{
MicroTileLen = 10;
int blocks = 10;
if (leveltype == DTYPE_TOWN) {
MicroTileLen = 16;
blocks = 16;
} else if (leveltype == DTYPE_HELL) {
MicroTileLen = 12;
blocks = 16;
}
for (int y = 0; y < MAXDUNY; y++) {
for (int x = 0; x < MAXDUNX; x++) {
int lv = dPiece[x][y];
MICROS &micros = dpiece_defs_map_2[x][y];
if (lv != 0) {
lv--;
uint16_t *pieces = &pLevelPieces[blocks * lv];
for (int i = 0; i < blocks; i++)
micros.mt[i] = SDL_SwapLE16(pieces[blocks - 2 + (i & 1) - (i & 0xE)]);
} else {
for (int i = 0; i < blocks; i++)
micros.mt[i] = 0;
}
}
}
}
void DRLG_InitTrans()
{
memset(dTransVal, 0, sizeof(dTransVal));
memset(TransList, 0, sizeof(TransList));
TransVal = 1;
}
void DRLG_MRectTrans(int x1, int y1, int x2, int y2)
{
x1 = 2 * x1 + 17;
y1 = 2 * y1 + 17;
x2 = 2 * x2 + 16;
y2 = 2 * y2 + 16;
for (int j = y1; j <= y2; j++) {
for (int i = x1; i <= x2; i++) {
dTransVal[i][j] = TransVal;
}
}
TransVal++;
}
void DRLG_RectTrans(int x1, int y1, int x2, int y2)
{
for (int j = y1; j <= y2; j++) {
for (int i = x1; i <= x2; i++) {
dTransVal[i][j] = TransVal;
}
}
TransVal++;
}
void DRLG_CopyTrans(int sx, int sy, int dx, int dy)
{
dTransVal[dx][dy] = dTransVal[sx][sy];
}
void DRLG_ListTrans(int num, BYTE *list)
{
for (int i = 0; i < num; i++) {
uint8_t x1 = *list++;
uint8_t y1 = *list++;
uint8_t x2 = *list++;
uint8_t y2 = *list++;
DRLG_RectTrans(x1, y1, x2, y2);
}
}
void DRLG_AreaTrans(int num, BYTE *list)
{
for (int i = 0; i < num; i++) {
uint8_t x1 = *list++;
uint8_t y1 = *list++;
uint8_t x2 = *list++;
uint8_t y2 = *list++;
DRLG_RectTrans(x1, y1, x2, y2);
TransVal--;
}
TransVal++;
}
void DRLG_InitSetPC()
{
setpc_x = 0;
setpc_y = 0;
setpc_w = 0;
setpc_h = 0;
}
void DRLG_SetPC()
{
int w = 2 * setpc_w;
int h = 2 * setpc_h;
int x = 2 * setpc_x + 16;
int y = 2 * setpc_y + 16;
for (int j = 0; j < h; j++) {
for (int i = 0; i < w; i++) {
dFlags[i + x][j + y] |= BFLAG_POPULATED;
}
}
}
void Make_SetPC(int x, int y, int w, int h)
{
int dw = 2 * w;
int dh = 2 * h;
int dx = 2 * x + 16;
int dy = 2 * y + 16;
for (int j = 0; j < dh; j++) {
for (int i = 0; i < dw; i++) {
dFlags[i + dx][j + dy] |= BFLAG_POPULATED;
}
}
}
bool DRLG_WillThemeRoomFit(int floor, int x, int y, int minSize, int maxSize, int *width, int *height)
{
bool yFlag = true;
@ -451,6 +267,152 @@ void DRLG_CreateThemeRoom(int themeIndex)
}
}
} // namespace
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;
}
}
void SetDungeonMicros()
{
MicroTileLen = 10;
int blocks = 10;
if (leveltype == DTYPE_TOWN) {
MicroTileLen = 16;
blocks = 16;
} else if (leveltype == DTYPE_HELL) {
MicroTileLen = 12;
blocks = 16;
}
for (int y = 0; y < MAXDUNY; y++) {
for (int x = 0; x < MAXDUNX; x++) {
int lv = dPiece[x][y];
MICROS &micros = dpiece_defs_map_2[x][y];
if (lv != 0) {
lv--;
uint16_t *pieces = &pLevelPieces[blocks * lv];
for (int i = 0; i < blocks; i++)
micros.mt[i] = SDL_SwapLE16(pieces[blocks - 2 + (i & 1) - (i & 0xE)]);
} else {
for (int i = 0; i < blocks; i++)
micros.mt[i] = 0;
}
}
}
}
void DRLG_InitTrans()
{
memset(dTransVal, 0, sizeof(dTransVal));
memset(TransList, 0, sizeof(TransList));
TransVal = 1;
}
void DRLG_MRectTrans(int x1, int y1, int x2, int y2)
{
x1 = 2 * x1 + 17;
y1 = 2 * y1 + 17;
x2 = 2 * x2 + 16;
y2 = 2 * y2 + 16;
for (int j = y1; j <= y2; j++) {
for (int i = x1; i <= x2; i++) {
dTransVal[i][j] = TransVal;
}
}
TransVal++;
}
void DRLG_RectTrans(int x1, int y1, int x2, int y2)
{
for (int j = y1; j <= y2; j++) {
for (int i = x1; i <= x2; i++) {
dTransVal[i][j] = TransVal;
}
}
TransVal++;
}
void DRLG_CopyTrans(int sx, int sy, int dx, int dy)
{
dTransVal[dx][dy] = dTransVal[sx][sy];
}
void DRLG_ListTrans(int num, BYTE *list)
{
for (int i = 0; i < num; i++) {
uint8_t x1 = *list++;
uint8_t y1 = *list++;
uint8_t x2 = *list++;
uint8_t y2 = *list++;
DRLG_RectTrans(x1, y1, x2, y2);
}
}
void DRLG_AreaTrans(int num, BYTE *list)
{
for (int i = 0; i < num; i++) {
uint8_t x1 = *list++;
uint8_t y1 = *list++;
uint8_t x2 = *list++;
uint8_t y2 = *list++;
DRLG_RectTrans(x1, y1, x2, y2);
TransVal--;
}
TransVal++;
}
void DRLG_InitSetPC()
{
setpc_x = 0;
setpc_y = 0;
setpc_w = 0;
setpc_h = 0;
}
void DRLG_SetPC()
{
int w = 2 * setpc_w;
int h = 2 * setpc_h;
int x = 2 * setpc_x + 16;
int y = 2 * setpc_y + 16;
for (int j = 0; j < h; j++) {
for (int i = 0; i < w; i++) {
dFlags[i + x][j + y] |= BFLAG_POPULATED;
}
}
}
void Make_SetPC(int x, int y, int w, int h)
{
int dw = 2 * w;
int dh = 2 * h;
int dx = 2 * x + 16;
int dy = 2 * y + 16;
for (int j = 0; j < dh; j++) {
for (int i = 0; i < dw; i++) {
dFlags[i + dx][j + dy] |= BFLAG_POPULATED;
}
}
}
void DRLG_PlaceThemeRooms(int minSize, int maxSize, int floor, int freq, bool rndSize)
{
themeCount = 0;
@ -502,6 +464,66 @@ void DRLG_HoldThemeRooms()
}
}
void DRLG_LPass3(int lv)
{
{
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 + 0][j + 0] = v1;
dPiece[i + 1][j + 0] = v2;
dPiece[i + 0][j + 1] = v3;
dPiece[i + 1][j + 1] = v4;
}
}
}
int yy = 16;
for (int j = 0; j < DMAXY; j++) {
int xx = 16;
for (int i = 0; i < DMAXX; i++) { // NOLINT(modernize-loop-convert)
int v1 = 0;
int v2 = 0;
int v3 = 0;
int 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 + 0][yy + 0] = v1;
dPiece[xx + 1][yy + 0] = v2;
dPiece[xx + 0][yy + 1] = v3;
dPiece[xx + 1][yy + 1] = v4;
xx += 2;
}
yy += 2;
}
}
void DRLG_Init_Globals()
{
memset(dFlags, 0, sizeof(dFlags));
memset(dPlayer, 0, sizeof(dPlayer));
memset(dMonster, 0, sizeof(dMonster));
memset(dDead, 0, sizeof(dDead));
memset(dObject, 0, sizeof(dObject));
memset(dItem, 0, sizeof(dItem));
memset(dMissile, 0, sizeof(dMissile));
memset(dSpecial, 0, sizeof(dSpecial));
int8_t c = DisableLighting ? 0 : 15;
memset(dLight, c, sizeof(dLight));
}
bool SkipThemeRoom(int x, int y)
{
for (int i = 0; i < themeCount; i++) {

45
Source/gendung.h

@ -122,16 +122,25 @@ struct ShadowStruct {
uint8_t nv3;
};
/** Contains the tile IDs of the map. */
extern uint8_t dungeon[DMAXX][DMAXY];
/** Contains a backup of the tile IDs of the map. */
extern uint8_t pdungeon[DMAXX][DMAXY];
extern char dflags[DMAXX][DMAXY];
/** Specifies the active set level X-coordinate of the map. */
extern int setpc_x;
/** Specifies the active set level Y-coordinate of the map. */
extern int setpc_y;
/** Specifies the width of the active set level of the map. */
extern int setpc_w;
/** Specifies the height of the active set level of the map. */
extern int setpc_h;
/** Contains the contents of the single player quest DUN file. */
extern std::unique_ptr<uint16_t[]> pSetPiece;
/** Specifies whether a single player quest DUN has been loaded. */
extern bool setloadflag;
extern std::optional<CelSprite> pSpecialCels;
/** Specifies the tile definitions of the active dungeon type; (e.g. levels/l1data/l1.til). */
extern std::unique_ptr<MegaTile[]> pMegaTiles;
extern std::unique_ptr<uint16_t[]> pLevelPieces;
extern std::unique_ptr<byte[]> pDungeonCels;
@ -156,33 +165,67 @@ extern std::array<bool, MAXTILES + 1> nTransTable;
*/
extern std::array<bool, MAXTILES + 1> nMissileTable;
extern std::array<bool, MAXTILES + 1> nTrapTable;
/** Specifies the minimum X-coordinate of the map. */
extern int dminx;
/** Specifies the minimum Y-coordinate of the map. */
extern int dminy;
/** Specifies the maximum X-coordinate of the map. */
extern int dmaxx;
/** Specifies the maximum Y-coordinate of the map. */
extern int dmaxy;
/** Specifies the active dungeon type of the current game. */
extern dungeon_type leveltype;
/** Specifies the active dungeon level of the current game. */
extern BYTE currlevel;
extern bool setlevel;
/** Specifies the active quest level of the current game. */
extern _setlevels setlvlnum;
/** Specifies the player viewpoint X-coordinate of the map. */
extern dungeon_type setlvltype;
/** Specifies the player viewpoint X-coordinate of the map. */
extern int ViewX;
/** Specifies the player viewpoint Y-coordinate of the map. */
extern int ViewY;
extern ScrollStruct ScrollInfo;
extern int MicroTileLen;
extern char TransVal;
/** Specifies the active transparency indices. */
extern bool TransList[256];
/** Contains the piece IDs of each tile on the map. */
extern int dPiece[MAXDUNX][MAXDUNY];
/** Specifies the dungeon piece information for a given coordinate and block number. */
extern MICROS dpiece_defs_map_2[MAXDUNX][MAXDUNY];
/** Specifies the transparency at each coordinate of the map. */
extern int8_t dTransVal[MAXDUNX][MAXDUNY];
extern char dLight[MAXDUNX][MAXDUNY];
extern char dPreLight[MAXDUNX][MAXDUNY];
extern int8_t dFlags[MAXDUNX][MAXDUNY];
/** Contains the player numbers (players array indices) of the map. */
extern int8_t dPlayer[MAXDUNX][MAXDUNY];
/**
* Contains the NPC numbers of the map. The NPC number represents a
* towner number (towners array index) in Tristram and a monster number
* (monsters array index) in the dungeon.
*/
extern int16_t dMonster[MAXDUNX][MAXDUNY];
/**
* Contains the dead numbers (deads array indices) and dead direction of
* the map, encoded as specified by the pseudo-code below.
* dDead[x][y] & 0x1F - index of dead
* dDead[x][y] >> 0x5 - direction
*/
extern int8_t dDead[MAXDUNX][MAXDUNY];
/** Contains the object numbers (objects array indices) of the map. */
extern char dObject[MAXDUNX][MAXDUNY];
/** Contains the item numbers (items array indices) of the map. */
extern int8_t dItem[MAXDUNX][MAXDUNY];
/** Contains the missile numbers (missiles array indices) of the map. */
extern int8_t dMissile[MAXDUNX][MAXDUNY];
/**
* Contains the arch frame numbers of the map from the special tileset
* (e.g. "levels/l1data/l1s.cel"). Note, the special tileset of Tristram (i.e.
* "levels/towndata/towns.cel") contains trees rather than arches.
*/
extern char dSpecial[MAXDUNX][MAXDUNY];
extern int themeCount;
extern THEME_LOC themeLoc[MAXTHEMES];
@ -200,6 +243,8 @@ void DRLG_SetPC();
void Make_SetPC(int x, int y, int w, int h);
void DRLG_PlaceThemeRooms(int minSize, int maxSize, int floor, int freq, bool rndSize);
void DRLG_HoldThemeRooms();
void DRLG_LPass3(int lv);
void DRLG_Init_Globals();
bool SkipThemeRoom(int x, int y);
void InitLevels();

173
Source/gmenu.cpp

@ -19,61 +19,20 @@
#include "utils/ui_fwd.h"
namespace devilution {
namespace {
std::optional<CelSprite> optbar_cel;
std::optional<CelSprite> PentSpin_cel;
std::optional<CelSprite> option_cel;
std::optional<CelSprite> sgpLogo;
} // namespace
bool mouseNavigation;
TMenuItem *sgpCurrItem;
int LogoAnim_tick;
BYTE LogoAnim_frame;
void (*gmenu_current_option)();
TMenuItem *sgpCurrentMenu;
int sgCurrentMenuIdx;
void gmenu_draw_pause(const Surface &out)
{
if (currlevel != 0)
RedBack(out);
if (sgpCurrentMenu == nullptr) {
LightTableIndex = 0;
DrawString(out, _("Pause"), Point { 0, PANEL_TOP / 2 }, UIS_HUGE | UIS_CENTER, 2);
}
}
void FreeGMenu()
{
sgpLogo = std::nullopt;
PentSpin_cel = std::nullopt;
option_cel = std::nullopt;
optbar_cel = std::nullopt;
}
void gmenu_init_menu()
{
LogoAnim_frame = 1;
sgpCurrentMenu = nullptr;
sgpCurrItem = nullptr;
gmenu_current_option = nullptr;
sgCurrentMenuIdx = 0;
mouseNavigation = false;
if (gbIsHellfire)
sgpLogo = LoadCel("Data\\hf_logo3.CEL", 430);
else
sgpLogo = LoadCel("Data\\Diabsmal.CEL", 296);
PentSpin_cel = LoadCel("Data\\PentSpin.CEL", 48);
option_cel = LoadCel("Data\\option.CEL", 27);
optbar_cel = LoadCel("Data\\optbar.CEL", 287);
}
bool gmenu_is_active()
{
return sgpCurrentMenu != nullptr;
}
static void GmenuUpDown(bool isDown)
{
if (sgpCurrItem == nullptr) {
@ -123,26 +82,6 @@ static void GmenuLeftRight(bool isRight)
sgpCurrItem->fnMenu(false);
}
void gmenu_set_items(TMenuItem *pItem, void (*gmFunc)())
{
PauseMode = 0;
mouseNavigation = false;
sgpCurrentMenu = pItem;
gmenu_current_option = gmFunc;
if (gmenu_current_option != nullptr) {
gmenu_current_option();
}
sgCurrentMenuIdx = 0;
if (sgpCurrentMenu != nullptr) {
for (int i = 0; sgpCurrentMenu[i].fnMenu != nullptr; i++) {
sgCurrentMenuIdx++;
}
}
// BUGFIX: OOB access when sgCurrentMenuIdx is 0; should be set to NULL instead. (fixed)
sgpCurrItem = sgCurrentMenuIdx > 0 ? &sgpCurrentMenu[sgCurrentMenuIdx - 1] : nullptr;
GmenuUpDown(true);
}
static void GmenuClearBuffer(const Surface &out, int x, int y, int width, int height)
{
BYTE *i = out.at(x, y);
@ -192,6 +131,92 @@ static void GameMenuMove()
GmenuUpDown(moveDir.y == AxisDirectionY_DOWN);
}
static bool GmenuMouseNavigation()
{
if (MousePosition.x < 282 + PANEL_LEFT) {
return false;
}
if (MousePosition.x > 538 + PANEL_LEFT) {
return false;
}
return true;
}
static int GmenuGetMouseSlider()
{
if (MousePosition.x < 282 + PANEL_LEFT) {
return 0;
}
if (MousePosition.x > 538 + PANEL_LEFT) {
return 256;
}
return MousePosition.x - 282 - PANEL_LEFT;
}
} // namespace
TMenuItem *sgpCurrentMenu;
void gmenu_draw_pause(const Surface &out)
{
if (currlevel != 0)
RedBack(out);
if (sgpCurrentMenu == nullptr) {
LightTableIndex = 0;
DrawString(out, _("Pause"), Point { 0, PANEL_TOP / 2 }, UIS_HUGE | UIS_CENTER, 2);
}
}
void FreeGMenu()
{
sgpLogo = std::nullopt;
PentSpin_cel = std::nullopt;
option_cel = std::nullopt;
optbar_cel = std::nullopt;
}
void gmenu_init_menu()
{
LogoAnim_frame = 1;
sgpCurrentMenu = nullptr;
sgpCurrItem = nullptr;
gmenu_current_option = nullptr;
sgCurrentMenuIdx = 0;
mouseNavigation = false;
if (gbIsHellfire)
sgpLogo = LoadCel("Data\\hf_logo3.CEL", 430);
else
sgpLogo = LoadCel("Data\\Diabsmal.CEL", 296);
PentSpin_cel = LoadCel("Data\\PentSpin.CEL", 48);
option_cel = LoadCel("Data\\option.CEL", 27);
optbar_cel = LoadCel("Data\\optbar.CEL", 287);
}
bool gmenu_is_active()
{
return sgpCurrentMenu != nullptr;
}
void gmenu_set_items(TMenuItem *pItem, void (*gmFunc)())
{
PauseMode = 0;
mouseNavigation = false;
sgpCurrentMenu = pItem;
gmenu_current_option = gmFunc;
if (gmenu_current_option != nullptr) {
gmenu_current_option();
}
sgCurrentMenuIdx = 0;
if (sgpCurrentMenu != nullptr) {
for (int i = 0; sgpCurrentMenu[i].fnMenu != nullptr; i++) {
sgCurrentMenuIdx++;
}
}
// BUGFIX: OOB access when sgCurrentMenuIdx is 0; should be set to NULL instead. (fixed)
sgpCurrItem = sgCurrentMenuIdx > 0 ? &sgpCurrentMenu[sgCurrentMenuIdx - 1] : nullptr;
GmenuUpDown(true);
}
void gmenu_draw(const Surface &out)
{
if (sgpCurrentMenu != nullptr) {
@ -253,28 +278,6 @@ bool gmenu_presskeys(int vkey)
return true;
}
static bool GmenuMouseNavigation()
{
if (MousePosition.x < 282 + PANEL_LEFT) {
return false;
}
if (MousePosition.x > 538 + PANEL_LEFT) {
return false;
}
return true;
}
static int GmenuGetMouseSlider()
{
if (MousePosition.x < 282 + PANEL_LEFT) {
return 0;
}
if (MousePosition.x > 538 + PANEL_LEFT) {
return 256;
}
return MousePosition.x - 282 - PANEL_LEFT;
}
bool gmenu_on_mouse_move()
{
if (!mouseNavigation)

7
Source/help.cpp

@ -16,9 +16,12 @@
namespace devilution {
unsigned int SkipLines;
bool HelpFlag;
namespace {
unsigned int SkipLines;
const char *const HelpText[] = {
N_("$Keyboard Shortcuts:"),
N_("F1: Open Help Screen"),
@ -93,6 +96,8 @@ const char *const HelpText[] = {
std::vector<std::string> HelpTextLines;
} // namespace
void InitHelp()
{
HelpFlag = false;

5
Source/interfac.cpp

@ -23,9 +23,10 @@
#include "utils/stdcompat/optional.hpp"
namespace devilution {
namespace {
std::optional<CelSprite> sgpBackCel;
} // namespace
uint32_t sgdwProgress;
int progress_id;
@ -187,6 +188,8 @@ static void DrawCutscene()
RenderPresent();
}
} // namespace
void interface_msg_pump()
{
tagMSG msg;

1394
Source/inv.cpp

File diff suppressed because it is too large Load Diff

5020
Source/items.cpp

File diff suppressed because it is too large Load Diff

6
Source/items.h

@ -420,7 +420,6 @@ bool ItemSpaceOk(Point position);
int AllocateItem();
Point GetSuperItemLoc(Point position);
void GetItemAttrs(int i, int idata, int lvl);
void GetItemPower(int i, int minlvl, int maxlvl, affix_item_type flgs, bool onlygood);
void SetupItem(int i);
int RndItem(int m);
void SpawnUnique(_unique_items uid, Point position);
@ -433,7 +432,6 @@ void RecreateEar(int ii, uint16_t ic, int iseed, int Id, int dur, int mdur, int
void CornerstoneSave();
void CornerstoneLoad(Point position);
void SpawnQuestItem(int itemid, Point position, int randarea, int selflag);
void SpawnRock();
void SpawnRewardItem(int itemid, Point position);
void SpawnMapOfDoom(Point position);
void SpawnRuneBomb(Point position);
@ -453,16 +451,12 @@ void DrawUniqueInfo(const Surface &out);
void PrintItemDetails(ItemStruct *x);
void PrintItemDur(ItemStruct *x);
void UseItem(int p, item_misc_id Mid, spell_id spl);
bool StoreStatOk(ItemStruct *h);
void SpawnSmith(int lvl);
void SpawnPremium(int pnum);
void WitchBookLevel(int ii);
void SpawnWitch(int lvl);
void SpawnBoy(int lvl);
void SpawnHealer(int lvl);
void SpawnStoreGold();
void RecreateTownItem(int ii, int idx, uint16_t icreateinfo, int iseed);
void RecalcStoreStats();
int ItemNoFlippy();
void CreateSpellBook(Point position, spell_id ispell, bool sendmsg, bool delta);
void CreateMagicArmor(Point position, int imisc, int icurs, bool sendmsg, bool delta);

15
Source/movie.cpp

@ -68,4 +68,19 @@ void play_movie(const char *pszMovie, bool userCanClose)
OutputToLogical(&MousePosition.x, &MousePosition.y);
}
/**
* @brief Fade to black and play a video
* @param pszMovie file path of movie
*/
void PlayInGameMovie(const char *pszMovie)
{
PaletteFadeOut(8);
play_movie(pszMovie, false);
ClearScreenBuffer();
force_redraw = 255;
scrollrt_draw_game_screen();
PaletteFadeIn(8);
force_redraw = 255;
}
} // namespace devilution

1
Source/movie.h

@ -11,5 +11,6 @@ extern bool movie_playing;
extern bool loop_movie;
void play_movie(const char *pszMovie, bool user_can_close);
void PlayInGameMovie(const char *pszMovie);
} // namespace devilution

Loading…
Cancel
Save