Browse Source

♻️Clean up variable initialization

pull/2256/head
Anders Jenbo 5 years ago
parent
commit
0f2ad469ea
  1. 5
      Source/DiabloUI/text_draw.cpp
  2. 25
      Source/DiabloUI/ttf_render_wrapped.cpp
  3. 7
      Source/controls/plrctrls.cpp
  4. 94
      Source/cursor.cpp
  5. 6
      Source/cursor.h
  6. 4
      Source/dvlnet/abstract_net.h
  7. 4
      Source/dvlnet/base.cpp
  8. 2
      Source/dvlnet/base.h
  9. 4
      Source/dvlnet/cdwrap.h
  10. 4
      Source/dvlnet/loopback.cpp
  11. 2
      Source/dvlnet/loopback.h
  12. 3
      Source/dx.cpp
  13. 2
      Source/engine/random.cpp
  14. 153
      Source/gendung.cpp
  15. 86
      Source/multi.cpp
  16. 8
      Source/nthread.cpp
  17. 23
      Source/path.cpp
  18. 544
      Source/player.cpp
  19. 11
      Source/qol/itemlabels.cpp
  20. 116
      Source/quests.cpp
  21. 68
      Source/scrollrt.cpp
  22. 38
      Source/sha.cpp
  23. 14
      Source/spells.cpp
  24. 2
      Source/storm/storm.h
  25. 2
      Source/storm/storm_net.cpp
  26. 22
      Source/sync.cpp
  27. 203
      Source/themes.cpp
  28. 14
      Source/town.cpp
  29. 172
      Source/trigs.cpp

5
Source/DiabloUI/text_draw.cpp

@ -10,8 +10,6 @@
namespace devilution {
namespace {
TextAlignment XAlignmentFromFlags(int flags)
@ -82,7 +80,8 @@ void DrawArtStr(const char *text, const SDL_Rect &rect, int flags, bool drawText
const int x = rect.x + AlignXOffset(flags, rect, GetArtStrWidth(text, size));
const int y = rect.y + ((flags & UIS_VCENTER) != 0 ? (rect.h - ArtFonts[size][color].h()) / 2 : 0);
int sx = x, sy = y;
int sx = x;
int sy = y;
for (size_t i = 0, n = strlen(text); i < n; i++) {
if (text[i] == '\n') {
sx = x;

25
Source/DiabloUI/ttf_render_wrapped.cpp

@ -32,10 +32,9 @@ SDL_bool CharacterIsDelimiter(char c, const char *delimiters)
// Based on SDL 2.0.12 TTF_RenderUTF8_Blended_Wrapped
SDL_Surface *RenderUTF8_Solid_Wrapped(TTF_Font *font, const char *text, SDL_Color fg, Uint32 wrapLength, const int xAlign)
{
int width, height;
SDL_Surface *textbuf;
int width = 0;
int height = 0;
const int lineSpace = 2;
char *str, **strLines;
/* Get the dimensions of the text surface */
if (TTF_SizeUTF8(font, text, &width, &height) < 0 || width == 0) {
@ -44,13 +43,10 @@ SDL_Surface *RenderUTF8_Solid_Wrapped(TTF_Font *font, const char *text, SDL_Colo
}
std::size_t numLines = 1;
str = nullptr;
strLines = nullptr;
char *str = nullptr;
char **strLines = nullptr;
if (wrapLength > 0 && *text != '\0') {
const char *wrapDelims = " \t\r\n";
int w, h;
char *spot, *tok, *nextTok, *end;
char delim;
const std::size_t strLen = std::strlen(text);
numLines = 0;
@ -62,8 +58,8 @@ SDL_Surface *RenderUTF8_Solid_Wrapped(TTF_Font *font, const char *text, SDL_Colo
}
std::memcpy(str, text, strLen + 1);
tok = str;
end = str + strLen;
char *tok = str;
char *end = str + strLen;
do {
strLines = (char **)SDL_realloc(strLines, (numLines + 1) * sizeof(*strLines));
if (strLines == nullptr) {
@ -73,6 +69,7 @@ SDL_Surface *RenderUTF8_Solid_Wrapped(TTF_Font *font, const char *text, SDL_Colo
strLines[numLines++] = tok;
/* Look for the end of the line */
char *spot;
if ((spot = SDL_strchr(tok, '\r')) != nullptr || (spot = SDL_strchr(tok, '\n')) != nullptr) {
if (*spot == '\r') {
++spot;
@ -83,7 +80,7 @@ SDL_Surface *RenderUTF8_Solid_Wrapped(TTF_Font *font, const char *text, SDL_Colo
} else {
spot = end;
}
nextTok = spot;
char *nextTok = spot;
/* Get the longest string that will fit in the desired space */
for (;;) {
@ -97,9 +94,11 @@ SDL_Surface *RenderUTF8_Solid_Wrapped(TTF_Font *font, const char *text, SDL_Colo
}
break;
}
delim = *spot;
char delim = *spot;
*spot = '\0';
int w = 0;
int h = 0;
TTF_SizeUTF8(font, tok, &w, &h);
if ((Uint32)w <= wrapLength) {
break;
@ -124,7 +123,7 @@ SDL_Surface *RenderUTF8_Solid_Wrapped(TTF_Font *font, const char *text, SDL_Colo
}
/* Create the target surface */
textbuf = SDL_CreateRGBSurface(SDL_SWSURFACE, (numLines > 1) ? wrapLength : width, height * numLines + (lineSpace * (numLines - 1)), 8, 0, 0, 0, 0);
SDL_Surface *textbuf = SDL_CreateRGBSurface(SDL_SWSURFACE, (numLines > 1) ? wrapLength : width, height * numLines + (lineSpace * (numLines - 1)), 8, 0, 0, 0, 0);
if (textbuf == nullptr) {
if (strLines != nullptr)
SDL_free(strLines);

7
Source/controls/plrctrls.cpp

@ -1023,7 +1023,9 @@ const Direction FaceDir[3][3] = {
*/
bool IsPathBlocked(Point position, Direction dir)
{
Direction d1, d2;
Direction d1;
Direction d2;
switch (dir) {
case DIR_N:
d1 = DIR_NW;
@ -1262,7 +1264,8 @@ void HandleRightStickMotion()
}
if (IsAutomapActive()) { // move map
int dx = 0, dy = 0;
int dx = 0;
int dy = 0;
acc.Pool(&dx, &dy, 32);
AutomapOffset.x += dy + dx;
AutomapOffset.y += dy - dx;

94
Source/cursor.cpp

@ -266,15 +266,11 @@ void CheckRportal()
void CheckCursMove()
{
int i, sx, sy, fx, fy, mx, my, tx, ty, px, py, xx, yy, mi, columns, rows, xo, yo;
int8_t bv;
bool flipflag, flipx, flipy;
if (IsItemLabelHighlighted())
return;
sx = MousePosition.x;
sy = MousePosition.y;
int sx = MousePosition.x;
int sy = MousePosition.y;
if (CanPanelsCoverView()) {
if (chrflag || questlog) {
@ -301,6 +297,8 @@ void CheckCursMove()
}
// Adjust by player offset and tile grid alignment
int xo = 0;
int yo = 0;
CalcTileOffset(&xo, &yo);
const auto &myPlayer = plr[myplr];
Point offset = ScrollInfo.offset;
@ -310,8 +308,8 @@ void CheckCursMove()
sy -= offset.y - yo;
// Predict the next frame when walking to avoid input jitter
fx = myPlayer.position.offset2.x / 256;
fy = myPlayer.position.offset2.y / 256;
int fx = myPlayer.position.offset2.x / 256;
int fy = myPlayer.position.offset2.y / 256;
fx -= (myPlayer.position.offset2.x + myPlayer.position.velocity.x) / 256;
fy -= (myPlayer.position.offset2.y + myPlayer.position.velocity.y) / 256;
if (ScrollInfo._sdir != SDIR_NONE) {
@ -320,9 +318,11 @@ void CheckCursMove()
}
// Convert to tile grid
mx = ViewX;
my = ViewY;
int mx = ViewX;
int my = ViewY;
int columns = 0;
int rows = 0;
TilesInView(&columns, &rows);
int lrow = rows - RowsCoveredByPanel();
@ -342,20 +342,20 @@ void CheckCursMove()
sy -= TILE_HEIGHT / 4;
}
tx = sx / TILE_WIDTH;
ty = sy / TILE_HEIGHT;
int tx = sx / TILE_WIDTH;
int ty = sy / TILE_HEIGHT;
ShiftGrid(&mx, &my, tx, ty);
// Shift position to match diamond grid aligment
px = sx % TILE_WIDTH;
py = sy % TILE_HEIGHT;
int px = sx % TILE_WIDTH;
int py = sy % TILE_HEIGHT;
// Shift position to match diamond grid aligment
flipy = py < (px / 2);
bool flipy = py < (px / 2);
if (flipy) {
my--;
}
flipx = py >= TILE_HEIGHT - (px / 2);
bool flipx = py >= TILE_HEIGHT - (px / 2);
if (flipx) {
mx++;
}
@ -373,7 +373,7 @@ void CheckCursMove()
my = MAXDUNY - 1;
}
flipflag = (flipy && flipx) || ((flipy || flipx) && px < TILE_WIDTH / 2);
bool flipflag = (flipy && flipx) || ((flipy || flipx) && px < TILE_WIDTH / 2);
pcurstemp = pcursmonst;
pcursmonst = -1;
@ -417,7 +417,7 @@ void CheckCursMove()
if (leveltype != DTYPE_TOWN) {
if (pcurstemp != -1) {
if (!flipflag && mx + 2 < MAXDUNX && my + 1 < MAXDUNY && dMonster[mx + 2][my + 1] != 0 && (dFlags[mx + 2][my + 1] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 2][my + 1] > 0 ? dMonster[mx + 2][my + 1] - 1 : -(dMonster[mx + 2][my + 1] + 1);
int mi = dMonster[mx + 2][my + 1] > 0 ? dMonster[mx + 2][my + 1] - 1 : -(dMonster[mx + 2][my + 1] + 1);
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 4) != 0) {
cursmx = mx + 2; /// BUGFIX: 'mx + 2' (fixed)
cursmy = my + 1; /// BUGFIX: 'my + 1' (fixed)
@ -425,7 +425,7 @@ void CheckCursMove()
}
}
if (flipflag && mx + 1 < MAXDUNX && my + 2 < MAXDUNY && dMonster[mx + 1][my + 2] != 0 && (dFlags[mx + 1][my + 2] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 1][my + 2] > 0 ? dMonster[mx + 1][my + 2] - 1 : -(dMonster[mx + 1][my + 2] + 1);
int mi = dMonster[mx + 1][my + 2] > 0 ? dMonster[mx + 1][my + 2] - 1 : -(dMonster[mx + 1][my + 2] + 1);
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 4) != 0) {
cursmx = mx + 1;
cursmy = my + 2;
@ -433,7 +433,7 @@ void CheckCursMove()
}
}
if (mx + 2 < MAXDUNX && my + 2 < MAXDUNY && dMonster[mx + 2][my + 2] != 0 && (dFlags[mx + 2][my + 2] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 2][my + 2] > 0 ? dMonster[mx + 2][my + 2] - 1 : -(dMonster[mx + 2][my + 2] + 1);
int mi = dMonster[mx + 2][my + 2] > 0 ? dMonster[mx + 2][my + 2] - 1 : -(dMonster[mx + 2][my + 2] + 1);
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 4) != 0) {
cursmx = mx + 2;
cursmy = my + 2;
@ -441,7 +441,7 @@ void CheckCursMove()
}
}
if (mx + 1 < MAXDUNX && !flipflag && dMonster[mx + 1][my] != 0 && (dFlags[mx + 1][my] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 1][my] > 0 ? dMonster[mx + 1][my] - 1 : -(dMonster[mx + 1][my] + 1);
int mi = dMonster[mx + 1][my] > 0 ? dMonster[mx + 1][my] - 1 : -(dMonster[mx + 1][my] + 1);
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 2) != 0) {
cursmx = mx + 1;
cursmy = my;
@ -449,7 +449,7 @@ void CheckCursMove()
}
}
if (my + 1 < MAXDUNY && flipflag && dMonster[mx][my + 1] != 0 && (dFlags[mx][my + 1] & BFLAG_LIT) != 0) {
mi = dMonster[mx][my + 1] > 0 ? dMonster[mx][my + 1] - 1 : -(dMonster[mx][my + 1] + 1);
int mi = dMonster[mx][my + 1] > 0 ? dMonster[mx][my + 1] - 1 : -(dMonster[mx][my + 1] + 1);
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 2) != 0) {
cursmx = mx;
cursmy = my + 1;
@ -457,7 +457,7 @@ void CheckCursMove()
}
}
if (dMonster[mx][my] != 0 && (dFlags[mx][my] & BFLAG_LIT) != 0) {
mi = dMonster[mx][my] > 0 ? dMonster[mx][my] - 1 : -(dMonster[mx][my] + 1);
int mi = dMonster[mx][my] > 0 ? dMonster[mx][my] - 1 : -(dMonster[mx][my] + 1);
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 1) != 0) {
cursmx = mx;
cursmy = my;
@ -465,7 +465,7 @@ void CheckCursMove()
}
}
if (mx + 1 < MAXDUNX && my + 1 < MAXDUNY && dMonster[mx + 1][my + 1] != 0 && (dFlags[mx + 1][my + 1] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 1][my + 1] > 0 ? dMonster[mx + 1][my + 1] - 1 : -(dMonster[mx + 1][my + 1] + 1);
int mi = dMonster[mx + 1][my + 1] > 0 ? dMonster[mx + 1][my + 1] - 1 : -(dMonster[mx + 1][my + 1] + 1);
if (mi == pcurstemp && monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 2) != 0) {
cursmx = mx + 1;
cursmy = my + 1;
@ -485,7 +485,7 @@ void CheckCursMove()
}
}
if (!flipflag && mx + 2 < MAXDUNX && my + 1 < MAXDUNY && dMonster[mx + 2][my + 1] != 0 && (dFlags[mx + 2][my + 1] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 2][my + 1] > 0 ? dMonster[mx + 2][my + 1] - 1 : -(dMonster[mx + 2][my + 1] + 1);
int mi = dMonster[mx + 2][my + 1] > 0 ? dMonster[mx + 2][my + 1] - 1 : -(dMonster[mx + 2][my + 1] + 1);
if (monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 4) != 0) {
cursmx = mx + 2;
cursmy = my + 1;
@ -493,7 +493,7 @@ void CheckCursMove()
}
}
if (flipflag && mx + 1 < MAXDUNX && my + 2 < MAXDUNY && dMonster[mx + 1][my + 2] != 0 && (dFlags[mx + 1][my + 2] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 1][my + 2] > 0 ? dMonster[mx + 1][my + 2] - 1 : -(dMonster[mx + 1][my + 2] + 1);
int mi = dMonster[mx + 1][my + 2] > 0 ? dMonster[mx + 1][my + 2] - 1 : -(dMonster[mx + 1][my + 2] + 1);
if (monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 4) != 0) {
cursmx = mx + 1;
cursmy = my + 2;
@ -501,7 +501,7 @@ void CheckCursMove()
}
}
if (mx + 2 < MAXDUNX && my + 2 < MAXDUNY && dMonster[mx + 2][my + 2] != 0 && (dFlags[mx + 2][my + 2] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 2][my + 2] > 0 ? dMonster[mx + 2][my + 2] - 1 : -(dMonster[mx + 2][my + 2] + 1);
int mi = dMonster[mx + 2][my + 2] > 0 ? dMonster[mx + 2][my + 2] - 1 : -(dMonster[mx + 2][my + 2] + 1);
if (monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 4) != 0) {
cursmx = mx + 2;
cursmy = my + 2;
@ -509,7 +509,7 @@ void CheckCursMove()
}
}
if (!flipflag && mx + 1 < MAXDUNX && dMonster[mx + 1][my] != 0 && (dFlags[mx + 1][my] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 1][my] > 0 ? dMonster[mx + 1][my] - 1 : -(dMonster[mx + 1][my] + 1);
int mi = dMonster[mx + 1][my] > 0 ? dMonster[mx + 1][my] - 1 : -(dMonster[mx + 1][my] + 1);
if (monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 2) != 0) {
cursmx = mx + 1;
cursmy = my;
@ -517,7 +517,7 @@ void CheckCursMove()
}
}
if (flipflag && my + 1 < MAXDUNY && dMonster[mx][my + 1] != 0 && (dFlags[mx][my + 1] & BFLAG_LIT) != 0) {
mi = dMonster[mx][my + 1] > 0 ? dMonster[mx][my + 1] - 1 : -(dMonster[mx][my + 1] + 1);
int mi = dMonster[mx][my + 1] > 0 ? dMonster[mx][my + 1] - 1 : -(dMonster[mx][my + 1] + 1);
if (monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 2) != 0) {
cursmx = mx;
cursmy = my + 1;
@ -525,7 +525,7 @@ void CheckCursMove()
}
}
if (dMonster[mx][my] != 0 && (dFlags[mx][my] & BFLAG_LIT) != 0) {
mi = dMonster[mx][my] > 0 ? dMonster[mx][my] - 1 : -(dMonster[mx][my] + 1);
int mi = dMonster[mx][my] > 0 ? dMonster[mx][my] - 1 : -(dMonster[mx][my] + 1);
if (monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 1) != 0) {
cursmx = mx;
cursmy = my;
@ -533,7 +533,7 @@ void CheckCursMove()
}
}
if (mx + 1 < MAXDUNX && my + 1 < MAXDUNY && dMonster[mx + 1][my + 1] != 0 && (dFlags[mx + 1][my + 1] & BFLAG_LIT) != 0) {
mi = dMonster[mx + 1][my + 1] > 0 ? dMonster[mx + 1][my + 1] - 1 : -(dMonster[mx + 1][my + 1] + 1);
int mi = dMonster[mx + 1][my + 1] > 0 ? dMonster[mx + 1][my + 1] - 1 : -(dMonster[mx + 1][my + 1] + 1);
if (monster[mi]._mhitpoints >> 6 > 0 && (monster[mi].MData->mSelFlag & 2) != 0) {
cursmx = mx + 1;
cursmy = my + 1;
@ -573,7 +573,7 @@ void CheckCursMove()
if (pcursmonst == -1) {
if (!flipflag && mx + 1 < MAXDUNX && dPlayer[mx + 1][my] != 0) {
bv = dPlayer[mx + 1][my] > 0 ? dPlayer[mx + 1][my] - 1 : -(dPlayer[mx + 1][my] + 1);
int8_t bv = dPlayer[mx + 1][my] > 0 ? dPlayer[mx + 1][my] - 1 : -(dPlayer[mx + 1][my] + 1);
if (bv != myplr && plr[bv]._pHitPoints != 0) {
cursmx = mx + 1;
cursmy = my;
@ -581,7 +581,7 @@ void CheckCursMove()
}
}
if (flipflag && my + 1 < MAXDUNY && dPlayer[mx][my + 1] != 0) {
bv = dPlayer[mx][my + 1] > 0 ? dPlayer[mx][my + 1] - 1 : -(dPlayer[mx][my + 1] + 1);
int8_t bv = dPlayer[mx][my + 1] > 0 ? dPlayer[mx][my + 1] - 1 : -(dPlayer[mx][my + 1] + 1);
if (bv != myplr && plr[bv]._pHitPoints != 0) {
cursmx = mx;
cursmy = my + 1;
@ -589,7 +589,7 @@ void CheckCursMove()
}
}
if (dPlayer[mx][my] != 0) {
bv = dPlayer[mx][my] > 0 ? dPlayer[mx][my] - 1 : -(dPlayer[mx][my] + 1);
int8_t bv = dPlayer[mx][my] > 0 ? dPlayer[mx][my] - 1 : -(dPlayer[mx][my] + 1);
if (bv != myplr) {
cursmx = mx;
cursmy = my;
@ -597,7 +597,7 @@ void CheckCursMove()
}
}
if ((dFlags[mx][my] & BFLAG_DEAD_PLAYER) != 0) {
for (i = 0; i < MAX_PLRS; i++) {
for (int i = 0; i < MAX_PLRS; i++) {
if (plr[i].position.tile.x == mx && plr[i].position.tile.y == my && i != myplr) {
cursmx = mx;
cursmy = my;
@ -606,10 +606,10 @@ void CheckCursMove()
}
}
if (pcurs == CURSOR_RESURRECT) {
for (xx = -1; xx < 2; xx++) {
for (yy = -1; yy < 2; yy++) {
for (int xx = -1; xx < 2; xx++) {
for (int yy = -1; yy < 2; yy++) {
if (mx + xx < MAXDUNX && my + yy < MAXDUNY && (dFlags[mx + xx][my + yy] & BFLAG_DEAD_PLAYER) != 0) {
for (i = 0; i < MAX_PLRS; i++) {
for (int i = 0; i < MAX_PLRS; i++) {
if (plr[i].position.tile.x == mx + xx && plr[i].position.tile.y == my + yy && i != myplr) {
cursmx = mx + xx;
cursmy = my + yy;
@ -621,7 +621,7 @@ void CheckCursMove()
}
}
if (mx + 1 < MAXDUNX && my + 1 < MAXDUNY && dPlayer[mx + 1][my + 1] != 0) {
bv = dPlayer[mx + 1][my + 1] > 0 ? dPlayer[mx + 1][my + 1] - 1 : -(dPlayer[mx + 1][my + 1] + 1);
int8_t bv = dPlayer[mx + 1][my + 1] > 0 ? dPlayer[mx + 1][my + 1] - 1 : -(dPlayer[mx + 1][my + 1] + 1);
if (bv != myplr && plr[bv]._pHitPoints != 0) {
cursmx = mx + 1;
cursmy = my + 1;
@ -631,7 +631,7 @@ void CheckCursMove()
}
if (pcursmonst == -1 && pcursplr == -1) {
if (!flipflag && mx + 1 < MAXDUNX && dObject[mx + 1][my] != 0) {
bv = dObject[mx + 1][my] > 0 ? dObject[mx + 1][my] - 1 : -(dObject[mx + 1][my] + 1);
int8_t bv = dObject[mx + 1][my] > 0 ? dObject[mx + 1][my] - 1 : -(dObject[mx + 1][my] + 1);
if (object[bv]._oSelFlag >= 2) {
cursmx = mx + 1;
cursmy = my;
@ -639,7 +639,7 @@ void CheckCursMove()
}
}
if (flipflag && my + 1 < MAXDUNY && dObject[mx][my + 1] != 0) {
bv = dObject[mx][my + 1] > 0 ? dObject[mx][my + 1] - 1 : -(dObject[mx][my + 1] + 1);
int8_t bv = dObject[mx][my + 1] > 0 ? dObject[mx][my + 1] - 1 : -(dObject[mx][my + 1] + 1);
if (object[bv]._oSelFlag >= 2) {
cursmx = mx;
cursmy = my + 1;
@ -647,7 +647,7 @@ void CheckCursMove()
}
}
if (dObject[mx][my] != 0) {
bv = dObject[mx][my] > 0 ? dObject[mx][my] - 1 : -(dObject[mx][my] + 1);
int8_t bv = dObject[mx][my] > 0 ? dObject[mx][my] - 1 : -(dObject[mx][my] + 1);
if (object[bv]._oSelFlag == 1 || object[bv]._oSelFlag == 3) {
cursmx = mx;
cursmy = my;
@ -655,7 +655,7 @@ void CheckCursMove()
}
}
if (mx + 1 < MAXDUNX && my + 1 < MAXDUNY && dObject[mx + 1][my + 1] != 0) {
bv = dObject[mx + 1][my + 1] > 0 ? dObject[mx + 1][my + 1] - 1 : -(dObject[mx + 1][my + 1] + 1);
int8_t bv = dObject[mx + 1][my + 1] > 0 ? dObject[mx + 1][my + 1] - 1 : -(dObject[mx + 1][my + 1] + 1);
if (object[bv]._oSelFlag >= 2) {
cursmx = mx + 1;
cursmy = my + 1;
@ -665,7 +665,7 @@ void CheckCursMove()
}
if (pcursplr == -1 && pcursobj == -1 && pcursmonst == -1) {
if (!flipflag && mx + 1 < MAXDUNX && dItem[mx + 1][my] > 0) {
bv = dItem[mx + 1][my] - 1;
int8_t bv = dItem[mx + 1][my] - 1;
if (items[bv]._iSelFlag >= 2) {
cursmx = mx + 1;
cursmy = my;
@ -673,7 +673,7 @@ void CheckCursMove()
}
}
if (flipflag && my + 1 < MAXDUNY && dItem[mx][my + 1] > 0) {
bv = dItem[mx][my + 1] - 1;
int8_t bv = dItem[mx][my + 1] - 1;
if (items[bv]._iSelFlag >= 2) {
cursmx = mx;
cursmy = my + 1;
@ -681,7 +681,7 @@ void CheckCursMove()
}
}
if (dItem[mx][my] > 0) {
bv = dItem[mx][my] - 1;
int8_t bv = dItem[mx][my] - 1;
if (items[bv]._iSelFlag == 1 || items[bv]._iSelFlag == 3) {
cursmx = mx;
cursmy = my;
@ -689,7 +689,7 @@ void CheckCursMove()
}
}
if (mx + 1 < MAXDUNX && my + 1 < MAXDUNY && dItem[mx + 1][my + 1] > 0) {
bv = dItem[mx + 1][my + 1] - 1;
int8_t bv = dItem[mx + 1][my + 1] - 1;
if (items[bv]._iSelFlag >= 2) {
cursmx = mx + 1;
cursmy = my + 1;

6
Source/cursor.h

@ -48,8 +48,8 @@ extern int pcurs;
void InitCursor();
void FreeCursor();
void SetICursor(int i);
void NewCursor(int i);
void SetICursor(int cursId);
void NewCursor(int cursId);
void InitLevelCursor();
void CheckRportal();
void CheckTown();
@ -69,6 +69,6 @@ const CelSprite &GetInvItemSprite(int i);
int GetInvItemFrame(int i);
/** Returns the width and height for an inventory index. */
Size GetInvItemSize(int i);
Size GetInvItemSize(int cursId);
} // namespace devilution

4
Source/dvlnet/abstract_net.h

@ -24,8 +24,8 @@ class abstract_net {
public:
virtual int create(std::string addrstr, std::string passwd) = 0;
virtual int join(std::string addrstr, std::string passwd) = 0;
virtual bool SNetReceiveMessage(int *sender, char **data,
int *size)
virtual bool SNetReceiveMessage(int *sender, void **data,
uint32_t *size)
= 0;
virtual bool SNetSendMessage(int dest, void *data,
unsigned int size)

4
Source/dvlnet/base.cpp

@ -106,7 +106,7 @@ void base::recv_local(packet &pkt)
}
}
bool base::SNetReceiveMessage(int *sender, char **data, int *size)
bool base::SNetReceiveMessage(int *sender, void **data, uint32_t *size)
{
poll();
if (message_queue.empty())
@ -115,7 +115,7 @@ bool base::SNetReceiveMessage(int *sender, char **data, int *size)
message_queue.pop_front();
*sender = message_last.sender;
*size = message_last.payload.size();
*data = reinterpret_cast<char *>(message_last.payload.data());
*data = message_last.payload.data();
return true;
}

2
Source/dvlnet/base.h

@ -17,7 +17,7 @@ public:
virtual int create(std::string addrstr, std::string passwd) = 0;
virtual int join(std::string addrstr, std::string passwd) = 0;
virtual bool SNetReceiveMessage(int *sender, char **data, int *size);
virtual bool SNetReceiveMessage(int *sender, void **data, uint32_t *size);
virtual bool SNetSendMessage(int playerId, void *data, unsigned int size);
virtual bool SNetReceiveTurns(char **data, unsigned int *size,
DWORD *status);

4
Source/dvlnet/cdwrap.h

@ -23,7 +23,7 @@ private:
public:
virtual int create(std::string addrstr, std::string passwd);
virtual int join(std::string addrstr, std::string passwd);
virtual bool SNetReceiveMessage(int *sender, char **data, int *size);
virtual bool SNetReceiveMessage(int *sender, void **data, uint32_t *size);
virtual bool SNetSendMessage(int dest, void *data,
unsigned int size);
virtual bool SNetReceiveTurns(char **data, unsigned int *size,
@ -84,7 +84,7 @@ void cdwrap<T>::setup_gameinfo(buffer_t info)
}
template <class T>
bool cdwrap<T>::SNetReceiveMessage(int *sender, char **data, int *size)
bool cdwrap<T>::SNetReceiveMessage(int *sender, void **data, uint32_t *size)
{
return dvlnet_wrap->SNetReceiveMessage(sender, data, size);
}

4
Source/dvlnet/loopback.cpp

@ -15,7 +15,7 @@ int loopback::join(std::string /*addrstr*/, std::string /*passwd*/)
ABORT();
}
bool loopback::SNetReceiveMessage(int *sender, char **data, int *size)
bool loopback::SNetReceiveMessage(int *sender, void **data, uint32_t *size)
{
if (message_queue.empty())
return false;
@ -23,7 +23,7 @@ bool loopback::SNetReceiveMessage(int *sender, char **data, int *size)
message_queue.pop();
*sender = plr_single;
*size = message_last.size();
*data = reinterpret_cast<char *>(message_last.data());
*data = message_last.data();
return true;
}

2
Source/dvlnet/loopback.h

@ -22,7 +22,7 @@ public:
virtual int create(std::string addrstr, std::string passwd);
virtual int join(std::string addrstr, std::string passwd);
virtual bool SNetReceiveMessage(int *sender, char **data, int *size);
virtual bool SNetReceiveMessage(int *sender, void **data, uint32_t *size);
virtual bool SNetSendMessage(int dest, void *data, unsigned int size);
virtual bool SNetReceiveTurns(char **data, unsigned int *size,
DWORD *status);

3
Source/dx.cpp

@ -97,7 +97,8 @@ static void dx_create_primary_surface()
{
#ifndef USE_SDL1
if (renderer != nullptr) {
int width, height;
int width = 0;
int height = 0;
SDL_RenderGetLogicalSize(renderer, &width, &height);
Uint32 format;
if (SDL_QueryTexture(texture, &format, nullptr, nullptr, nullptr) < 0)

2
Source/engine/random.cpp

@ -47,4 +47,4 @@ int32_t GenerateRnd(int32_t v)
return AdvanceRndSeed() % v;
}
}
} // namespace devilution

153
Source/gendung.cpp

@ -192,15 +192,13 @@ void DRLG_InitTrans()
void DRLG_MRectTrans(int x1, int y1, int x2, int y2)
{
int i, j;
x1 = 2 * x1 + 17;
y1 = 2 * y1 + 17;
x2 = 2 * x2 + 16;
y2 = 2 * y2 + 16;
for (j = y1; j <= y2; j++) {
for (i = x1; i <= x2; i++) {
for (int j = y1; j <= y2; j++) {
for (int i = x1; i <= x2; i++) {
dTransVal[i][j] = TransVal;
}
}
@ -210,10 +208,8 @@ void DRLG_MRectTrans(int x1, int y1, int x2, int y2)
void DRLG_RectTrans(int x1, int y1, int x2, int y2)
{
int i, j;
for (j = y1; j <= y2; j++) {
for (i = x1; i <= x2; i++) {
for (int j = y1; j <= y2; j++) {
for (int i = x1; i <= x2; i++) {
dTransVal[i][j] = TransVal;
}
}
@ -227,28 +223,22 @@ void DRLG_CopyTrans(int sx, int sy, int dx, int dy)
void DRLG_ListTrans(int num, BYTE *List)
{
int i;
BYTE x1, y1, x2, y2;
for (i = 0; i < num; i++) {
x1 = *List++;
y1 = *List++;
x2 = *List++;
y2 = *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)
{
int i;
BYTE x1, y1, x2, y2;
for (i = 0; i < num; i++) {
x1 = *List++;
y1 = *List++;
x2 = *List++;
y2 = *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--;
}
@ -265,15 +255,13 @@ void DRLG_InitSetPC()
void DRLG_SetPC()
{
int i, j, x, y, w, h;
int w = 2 * setpc_w;
int h = 2 * setpc_h;
int x = 2 * setpc_x + 16;
int y = 2 * setpc_y + 16;
w = 2 * setpc_w;
h = 2 * setpc_h;
x = 2 * setpc_x + 16;
y = 2 * setpc_y + 16;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
for (int i = 0; i < w; i++) {
dFlags[i + x][j + y] |= BFLAG_POPULATED;
}
}
@ -281,15 +269,13 @@ void DRLG_SetPC()
void Make_SetPC(int x, int y, int w, int h)
{
int i, j, dx, dy, dh, dw;
dw = 2 * w;
dh = 2 * h;
dx = 2 * x + 16;
dy = 2 * y + 16;
int dw = 2 * w;
int dh = 2 * h;
int dx = 2 * x + 16;
int dy = 2 * y + 16;
for (j = 0; j < dh; j++) {
for (i = 0; i < dw; i++) {
for (int j = 0; j < dh; j++) {
for (int i = 0; i < dw; i++) {
dFlags[i + dx][j + dy] |= BFLAG_POPULATED;
}
}
@ -297,16 +283,10 @@ void Make_SetPC(int x, int y, int w, int h)
bool DRLG_WillThemeRoomFit(int floor, int x, int y, int minSize, int maxSize, int *width, int *height)
{
int ii, xx, yy;
int xSmallest, ySmallest;
int xArray[20], yArray[20];
int xCount, yCount;
bool yFlag, xFlag;
yFlag = true;
xFlag = true;
xCount = 0;
yCount = 0;
bool yFlag = true;
bool xFlag = true;
int xCount = 0;
int yCount = 0;
// BUGFIX: change '&&' to '||' (fixed)
if (x > DMAXX - maxSize || y > DMAXY - maxSize) {
@ -316,12 +296,12 @@ bool DRLG_WillThemeRoomFit(int floor, int x, int y, int minSize, int maxSize, in
return false;
}
memset(xArray, 0, sizeof(xArray));
memset(yArray, 0, sizeof(yArray));
int xArray[20] = {};
int yArray[20] = {};
for (ii = 0; ii < maxSize; ii++) {
for (int ii = 0; ii < maxSize; ii++) {
if (xFlag) {
for (xx = x; xx < x + maxSize; xx++) {
for (int xx = x; xx < x + maxSize; xx++) {
if (dungeon[xx][y + ii] != floor) {
if (xx >= minSize) {
break;
@ -337,7 +317,7 @@ bool DRLG_WillThemeRoomFit(int floor, int x, int y, int minSize, int maxSize, in
}
}
if (yFlag) {
for (yy = y; yy < y + maxSize; yy++) {
for (int yy = y; yy < y + maxSize; yy++) {
if (dungeon[x + ii][yy] != floor) {
if (yy >= minSize) {
break;
@ -354,16 +334,16 @@ bool DRLG_WillThemeRoomFit(int floor, int x, int y, int minSize, int maxSize, in
}
}
for (ii = 0; ii < minSize; ii++) {
for (int ii = 0; ii < minSize; ii++) {
if (xArray[ii] < minSize || yArray[ii] < minSize) {
return false;
}
}
xSmallest = xArray[0];
ySmallest = yArray[0];
int xSmallest = xArray[0];
int ySmallest = yArray[0];
for (ii = 0; ii < maxSize; ii++) {
for (int ii = 0; ii < maxSize; ii++) {
if (xArray[ii] < minSize || yArray[ii] < minSize) {
break;
}
@ -382,14 +362,13 @@ bool DRLG_WillThemeRoomFit(int floor, int x, int y, int minSize, int maxSize, in
void DRLG_CreateThemeRoom(int themeIndex)
{
int xx, yy;
const int lx = themeLoc[themeIndex].x;
const int ly = themeLoc[themeIndex].y;
const int hx = lx + themeLoc[themeIndex].width;
const int hy = ly + themeLoc[themeIndex].height;
for (yy = ly; yy < hy; yy++) {
for (xx = lx; xx < hx; xx++) {
for (int yy = ly; yy < hy; yy++) {
for (int xx = lx; xx < hx; xx++) {
if (leveltype == DTYPE_CATACOMBS) {
if (yy == ly || yy == hy - 1) {
dungeon[xx][yy] = 2;
@ -461,48 +440,42 @@ void DRLG_CreateThemeRoom(int themeIndex)
}
if (leveltype == DTYPE_HELL) {
switch (GenerateRnd(2)) {
case 0:
yy = (ly + hy) / 2;
case 0: {
int yy = (ly + hy) / 2;
dungeon[hx - 1][yy - 1] = 53;
dungeon[hx - 1][yy] = 6;
dungeon[hx - 1][yy + 1] = 52;
dungeon[hx - 2][yy - 1] = 54;
break;
case 1:
xx = (lx + hx) / 2;
} break;
case 1: {
int xx = (lx + hx) / 2;
dungeon[xx - 1][hy - 1] = 57;
dungeon[xx][hy - 1] = 6;
dungeon[xx + 1][hy - 1] = 56;
dungeon[xx][hy - 2] = 59;
dungeon[xx - 1][hy - 2] = 58;
break;
} break;
}
}
}
void DRLG_PlaceThemeRooms(int minSize, int maxSize, int floor, int freq, bool rndSize)
{
int i, j;
int themeW, themeH;
int rv2, min, max;
themeCount = 0;
memset(themeLoc, 0, sizeof(*themeLoc));
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++) {
int themeW = 0;
int themeH = 0;
if (dungeon[i][j] == floor && GenerateRnd(freq) == 0 && DRLG_WillThemeRoomFit(floor, i, j, minSize, maxSize, &themeW, &themeH)) {
if (rndSize) {
min = minSize - 2;
max = maxSize - 2;
rv2 = min + GenerateRnd(GenerateRnd(themeW - min + 1));
if (rv2 >= min && rv2 <= max)
themeW = rv2;
else
int min = minSize - 2;
int max = maxSize - 2;
themeW = min + GenerateRnd(GenerateRnd(themeW - min + 1));
if (themeW < min || themeW > max)
themeW = min;
rv2 = min + GenerateRnd(GenerateRnd(themeH - min + 1));
if (rv2 >= min && rv2 <= max)
themeH = rv2;
else
themeH = min + GenerateRnd(GenerateRnd(themeH - min + 1));
if (themeH < min || themeH > max)
themeH = min;
}
themeLoc[themeCount].x = i + 1;
@ -523,13 +496,11 @@ void DRLG_PlaceThemeRooms(int minSize, int maxSize, int floor, int freq, bool rn
void DRLG_HoldThemeRooms()
{
int i, x, y, xx, yy;
for (i = 0; i < themeCount; i++) {
for (y = themeLoc[i].y; y < themeLoc[i].y + themeLoc[i].height - 1; y++) {
for (x = themeLoc[i].x; x < themeLoc[i].x + themeLoc[i].width - 1; x++) {
xx = 2 * x + 16;
yy = 2 * y + 16;
for (int i = 0; i < themeCount; i++) {
for (int y = themeLoc[i].y; y < themeLoc[i].y + themeLoc[i].height - 1; y++) {
for (int x = themeLoc[i].x; x < themeLoc[i].x + themeLoc[i].width - 1; x++) {
int xx = 2 * x + 16;
int yy = 2 * y + 16;
dFlags[xx][yy] |= BFLAG_POPULATED;
dFlags[xx + 1][yy] |= BFLAG_POPULATED;
dFlags[xx][yy + 1] |= BFLAG_POPULATED;

86
Source/multi.cpp

@ -86,7 +86,7 @@ static void multi_copy_packet(TBuffer *buf, byte *packet, uint8_t size)
p[size] = byte { 0 };
}
static byte *multi_recv_packet(TBuffer *pBuf, byte *body, DWORD *size)
static byte *multi_recv_packet(TBuffer *pBuf, byte *body, size_t *size)
{
if (pBuf->dwNextWriteOffset != 0) {
byte *src_ptr = pBuf->bData;
@ -153,21 +153,19 @@ void NetSendLoPri(int playerId, byte *pbMsg, BYTE bLen)
void NetSendHiPri(int playerId, byte *pbMsg, BYTE bLen)
{
DWORD size, len;
TPkt pkt;
if (pbMsg != nullptr && bLen != 0) {
multi_copy_packet(&sgHiPriBuf, pbMsg, bLen);
multi_send_packet(playerId, pbMsg, bLen);
}
if (!gbShouldValidatePackage) {
gbShouldValidatePackage = true;
TPkt pkt;
NetRecvPlrData(&pkt);
size = gdwNormalMsgSize - sizeof(TPktHdr);
size_t size = gdwNormalMsgSize - sizeof(TPktHdr);
byte *hipri_body = multi_recv_packet(&sgHiPriBuf, pkt.body, &size);
byte *lowpri_body = multi_recv_packet(&sgLoPriBuf, hipri_body, &size);
size = sync_all_monsters(lowpri_body, size);
len = gdwNormalMsgSize - size;
size_t len = gdwNormalMsgSize - size;
pkt.hdr.wLen = len;
if (!SNetSendMessage(-2, &pkt.hdr, len))
nthread_terminate_game("SNetSendMessage");
@ -176,14 +174,13 @@ void NetSendHiPri(int playerId, byte *pbMsg, BYTE bLen)
void multi_send_msg_packet(uint32_t pmask, byte *src, BYTE len)
{
DWORD v, p, t;
TPkt pkt;
NetRecvPlrData(&pkt);
t = len + sizeof(pkt.hdr);
size_t t = len + sizeof(pkt.hdr);
pkt.hdr.wLen = t;
memcpy(pkt.body, src, len);
for (v = 1, p = 0; p < MAX_PLRS; p++, v <<= 1) {
size_t p = 0;
for (size_t v = 1; p < MAX_PLRS; p++, v <<= 1) {
if ((v & pmask) != 0) {
if (!SNetSendMessage(p, &pkt.hdr, t) && SErrGetLastError() != STORM_ERROR_INVALID_PLAYER) {
nthread_terminate_game("SNetSendMessage");
@ -195,12 +192,9 @@ void multi_send_msg_packet(uint32_t pmask, byte *src, BYTE len)
static void multi_mon_seeds()
{
int i;
DWORD l;
sgdwGameLoops++;
l = (sgdwGameLoops >> 8) | (sgdwGameLoops << 24); // _rotr(sgdwGameLoops, 8)
for (i = 0; i < MAXMONSTERS; i++)
uint32_t l = (sgdwGameLoops >> 8) | (sgdwGameLoops << 24); // _rotr(sgdwGameLoops, 8)
for (int i = 0; i < MAXMONSTERS; i++)
monster[i]._mAISeed = l + i;
}
@ -320,9 +314,6 @@ static void multi_check_drop_player()
static void multi_begin_timeout()
{
int i, nTicks, nLowestActive, nLowestPlayer;
BYTE bGroupPlayers, bGroupCount;
if (!sgbTimeout) {
return;
}
@ -332,7 +323,7 @@ static void multi_begin_timeout()
}
#endif
nTicks = SDL_GetTicks() - sglTimeoutStart;
int nTicks = SDL_GetTicks() - sglTimeoutStart;
if (nTicks > 20000) {
gbRunGame = false;
return;
@ -341,11 +332,11 @@ static void multi_begin_timeout()
return;
}
nLowestActive = -1;
nLowestPlayer = -1;
bGroupPlayers = 0;
bGroupCount = 0;
for (i = 0; i < MAX_PLRS; i++) {
int nLowestActive = -1;
int nLowestPlayer = -1;
uint8_t bGroupPlayers = 0;
uint8_t bGroupCount = 0;
for (int i = 0; i < MAX_PLRS; i++) {
uint32_t nState = player_state[i];
if ((nState & PS_CONNECTED) != 0) {
if (nLowestPlayer == -1) {
@ -447,19 +438,15 @@ static void multi_process_tmsgs()
void multi_process_network_packets()
{
int dx, dy;
TPktHdr *pkt;
DWORD dwMsgSize;
int dwID;
bool cond;
char *data;
multi_clear_left_tbl();
multi_process_tmsgs();
while (SNetReceiveMessage(&dwID, &data, (int *)&dwMsgSize)) {
int dwID = -1;
TPktHdr *pkt;
uint32_t dwMsgSize = 0;
while (SNetReceiveMessage(&dwID, (void **)&pkt, &dwMsgSize)) {
dwRecCount++;
multi_clear_left_tbl();
pkt = (TPktHdr *)data;
if (dwMsgSize < sizeof(TPktHdr))
continue;
if (dwID < 0 || dwID >= MAX_PLRS)
@ -473,14 +460,14 @@ void multi_process_network_packets()
assert(gbBufferMsgs != 2);
plr[dwID]._pHitPoints = pkt->php;
plr[dwID]._pMaxHP = pkt->pmhp;
cond = gbBufferMsgs == 1;
bool cond = gbBufferMsgs == 1;
plr[dwID]._pBaseStr = pkt->bstr;
plr[dwID]._pBaseMag = pkt->bmag;
plr[dwID]._pBaseDex = pkt->bdex;
if (!cond && plr[dwID].plractive && plr[dwID]._pHitPoints != 0) {
if (currlevel == plr[dwID].plrlevel && !plr[dwID]._pLvlChanging) {
dx = abs(plr[dwID].position.tile.x - pkt->px);
dy = abs(plr[dwID].position.tile.y - pkt->py);
int dx = abs(plr[dwID].position.tile.x - pkt->px);
int dy = abs(plr[dwID].position.tile.y - pkt->py);
if ((dx > 3 || dy > 3) && dPlayer[pkt->px][pkt->py] == 0) {
FixPlrWalkTags(dwID);
plr[dwID].position.old = plr[dwID].position.tile;
@ -509,17 +496,14 @@ void multi_process_network_packets()
void multi_send_zero_packet(int pnum, _cmd_id bCmd, byte *pbSrc, DWORD dwLen)
{
DWORD dwOffset, dwBody, dwMsg;
TPkt pkt;
TCmdPlrInfoHdr *p;
assert(pnum != myplr);
assert(pbSrc);
assert(dwLen <= 0x0ffff);
dwOffset = 0;
uint32_t dwOffset = 0;
while (dwLen != 0) {
TPkt pkt;
pkt.hdr.wCheck = LoadBE32("\0\0ip");
pkt.hdr.px = 0;
pkt.hdr.py = 0;
@ -530,17 +514,17 @@ void multi_send_zero_packet(int pnum, _cmd_id bCmd, byte *pbSrc, DWORD dwLen)
pkt.hdr.bstr = 0;
pkt.hdr.bmag = 0;
pkt.hdr.bdex = 0;
p = (TCmdPlrInfoHdr *)pkt.body;
auto *p = (TCmdPlrInfoHdr *)pkt.body;
p->bCmd = bCmd;
p->wOffset = dwOffset;
dwBody = gdwLargestMsgSize - sizeof(pkt.hdr) - sizeof(*p);
size_t dwBody = gdwLargestMsgSize - sizeof(pkt.hdr) - sizeof(*p);
if (dwLen < dwBody) {
dwBody = dwLen;
}
assert(dwBody <= 0x0ffff);
p->wBytes = dwBody;
memcpy(&pkt.body[sizeof(*p)], pbSrc, p->wBytes);
dwMsg = sizeof(pkt.hdr);
size_t dwMsg = sizeof(pkt.hdr);
dwMsg += sizeof(*p);
dwMsg += p->wBytes;
pkt.hdr.wLen = dwMsg;
@ -602,21 +586,21 @@ static dungeon_type InitLevelType(int l)
static void SetupLocalCoords()
{
int x, y;
if (!leveldebug || gbIsMultiplayer) {
currlevel = 0;
leveltype = DTYPE_TOWN;
setlevel = false;
}
x = 75;
y = 68;
int x = 75;
int y = 68;
#ifdef _DEBUG
if (debug_mode_key_inverted_v) {
x = 49;
y = 23;
}
#endif
x += plrxoff[myplr];
y += plryoff[myplr];
plr[myplr].position.tile = { x, y };
@ -666,13 +650,13 @@ static void multi_handle_events(_SNETEVENT *pEvt)
static void multi_event_handler(bool add)
{
for (int i = 0; i < 3; i++) {
for (auto event_type : event_types) {
if (add) {
if (!SNetRegisterEventHandler(event_types[i], multi_handle_events)) {
if (!SNetRegisterEventHandler(event_type, multi_handle_events)) {
app_fatal("SNetRegisterEventHandler:\n%s", SDL_GetError());
}
} else {
SNetUnregisterEventHandler(event_types[i]);
SNetUnregisterEventHandler(event_type);
}
}
}

8
Source/nthread.cpp

@ -51,18 +51,16 @@ void nthread_terminate_game(const char *pszFcn)
uint32_t nthread_send_and_recv_turn(uint32_t cur_turn, int turn_delta)
{
int turn, turn_tmp;
DWORD curTurnsInTransit;
uint32_t curTurnsInTransit;
if (!SNetGetTurnsInTransit(&curTurnsInTransit)) {
nthread_terminate_game("SNetGetTurnsInTransit");
return 0;
}
while (curTurnsInTransit++ < gdwTurnsInTransit) {
turn_tmp = turn_upper_bit | (cur_turn & 0x7FFFFFFF);
int turn_tmp = turn_upper_bit | (cur_turn & 0x7FFFFFFF);
turn_upper_bit = 0;
turn = turn_tmp;
int turn = turn_tmp;
if (!SNetSendTurn((char *)&turn, sizeof(turn))) {
nthread_terminate_game("SNetSendTurn");

23
Source/path.cpp

@ -53,15 +53,12 @@ int8_t path_directions[9] = { 5, 1, 6, 2, 0, 3, 8, 4, 7 };
*/
int FindPath(bool (*PosOk)(int, Point), int PosOkArg, int sx, int sy, int dx, int dy, int8_t path[MAX_PATH_LENGTH])
{
PATHNODE *path_start, *next_node, *current;
int path_length, i;
// clear all nodes, create root nodes for the visited/frontier linked lists
gdwCurNodes = 0;
path_2_nodes = path_new_step();
pnode_ptr = path_new_step();
gdwCurPathStep = 0;
path_start = path_new_step();
PATHNODE *path_start = path_new_step();
path_start->g = 0;
path_start->h = path_get_h_cost(sx, sy, dx, dy);
path_start->position.x = sx;
@ -69,11 +66,12 @@ int FindPath(bool (*PosOk)(int, Point), int PosOkArg, int sx, int sy, int dx, in
path_start->position.y = sy;
path_2_nodes->NextNode = path_start;
// A* search until we find (dx,dy) or fail
PATHNODE *next_node;
while ((next_node = GetNextPath()) != nullptr) {
// reached the end, success!
if (next_node->position.x == dx && next_node->position.y == dy) {
current = next_node;
path_length = 0;
PATHNODE *current = next_node;
int path_length = 0;
while (current->Parent != nullptr) {
if (path_length >= MAX_PATH_LENGTH)
break;
@ -81,6 +79,7 @@ int FindPath(bool (*PosOk)(int, Point), int PosOkArg, int sx, int sy, int dx, in
current = current->Parent;
}
if (path_length != MAX_PATH_LENGTH) {
int i;
for (i = 0; i < path_length; i++)
path[i] = pnode_vals[path_length - i - 1];
return i;
@ -180,14 +179,10 @@ bool path_solid_pieces(PATHNODE *pPath, int dx, int dy)
*/
bool path_get_path(bool (*PosOk)(int, Point), int PosOkArg, PATHNODE *pPath, int x, int y)
{
int dx, dy;
int i;
bool ok;
for (i = 0; i < 8; i++) {
dx = pPath->position.x + pathxdir[i];
dy = pPath->position.y + pathydir[i];
ok = PosOk(PosOkArg, { dx, dy });
for (int i = 0; i < 8; i++) {
int dx = pPath->position.x + pathxdir[i];
int dy = pPath->position.y + pathydir[i];
bool ok = PosOk(PosOkArg, { dx, dy });
if ((ok && path_solid_pieces(pPath, dx, dy)) || (!ok && dx == x && dy == y)) {
if (!path_parent_path(pPath, dx, dy, x, y))
return false;

544
Source/player.cpp

@ -1029,8 +1029,6 @@ int CalcStatDiff(PlayerStruct &player)
void NextPlrLevel(int pnum)
{
int hp, mana;
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("NextPlrLevel: illegal player %i", pnum);
}
@ -1049,7 +1047,7 @@ void NextPlrLevel(int pnum)
player._pNextExper = ExpLvlsTbl[player._pLevel];
hp = player._pClass == HeroClass::Sorcerer ? 64 : 128;
int hp = player._pClass == HeroClass::Sorcerer ? 64 : 128;
if (!gbIsMultiplayer) {
hp++;
}
@ -1062,12 +1060,11 @@ void NextPlrLevel(int pnum)
drawhpflag = true;
}
int mana = 128;
if (player._pClass == HeroClass::Warrior)
mana = 64;
else if (player._pClass == HeroClass::Barbarian)
mana = 0;
else
mana = 128;
if (!gbIsMultiplayer) {
mana++;
@ -1094,8 +1091,6 @@ void NextPlrLevel(int pnum)
void AddPlrExperience(int pnum, int lvl, int exp)
{
int powerLvlCap, expCap, newLvl, i;
if (pnum != myplr) {
return;
}
@ -1117,7 +1112,7 @@ void AddPlrExperience(int pnum, int lvl, int exp)
// Prevent power leveling
if (gbIsMultiplayer) {
powerLvlCap = player._pLevel < 0 ? 0 : player._pLevel;
int powerLvlCap = player._pLevel < 0 ? 0 : player._pLevel;
if (powerLvlCap >= 50) {
powerLvlCap = 50;
}
@ -1126,7 +1121,7 @@ void AddPlrExperience(int pnum, int lvl, int exp)
exp = ExpLvlsTbl[powerLvlCap] / 20;
}
// cap to 200 * current level
expCap = 200 * powerLvlCap;
int expCap = 200 * powerLvlCap;
if (exp >= expCap) {
exp = expCap;
}
@ -1147,12 +1142,12 @@ void AddPlrExperience(int pnum, int lvl, int exp)
}
// Increase player level if applicable
newLvl = 0;
int newLvl = 0;
while (player._pExperience >= ExpLvlsTbl[newLvl]) {
newLvl++;
}
if (newLvl != player._pLevel) {
for (i = newLvl - player._pLevel; i > 0; i--) {
for (int i = newLvl - player._pLevel; i > 0; i--) {
NextPlrLevel(pnum);
}
}
@ -1162,17 +1157,15 @@ void AddPlrExperience(int pnum, int lvl, int exp)
void AddPlrMonstExper(int lvl, int exp, char pmask)
{
int totplrs, i, e;
totplrs = 0;
for (i = 0; i < MAX_PLRS; i++) {
int totplrs = 0;
for (int i = 0; i < MAX_PLRS; i++) {
if (((1 << i) & pmask) != 0) {
totplrs++;
}
}
if (totplrs != 0) {
e = exp / totplrs;
int e = exp / totplrs;
if ((pmask & (1 << myplr)) != 0)
AddPlrExperience(myplr, lvl, e);
}
@ -1309,10 +1302,8 @@ bool SolidLoc(Point position)
void PlrClrTrans(Point position)
{
int i, j;
for (i = position.y - 1; i <= position.y + 1; i++) {
for (j = position.x - 1; j <= position.x + 1; j++) {
for (int i = position.y - 1; i <= position.y + 1; i++) {
for (int j = position.x - 1; j <= position.x + 1; j++) {
TransList[dTransVal[j][i]] = false;
}
}
@ -1320,16 +1311,15 @@ void PlrClrTrans(Point position)
void PlrDoTrans(Point position)
{
int i, j;
if (leveltype != DTYPE_CATHEDRAL && leveltype != DTYPE_CATACOMBS) {
TransList[1] = true;
} else {
for (i = position.y - 1; i <= position.y + 1; i++) {
for (j = position.x - 1; j <= position.x + 1; j++) {
if (!nSolidTable[dPiece[j][i]] && dTransVal[j][i] != 0) {
TransList[dTransVal[j][i]] = true;
}
return;
}
for (int i = position.y - 1; i <= position.y + 1; i++) {
for (int j = position.x - 1; j <= position.x + 1; j++) {
if (!nSolidTable[dPiece[j][i]] && dTransVal[j][i] != 0) {
TransList[dTransVal[j][i]] = true;
}
}
}
@ -1367,16 +1357,17 @@ void StartStand(int pnum, Direction dir)
}
auto &player = plr[pnum];
if (!player._pInvincible || player._pHitPoints != 0 || pnum != myplr) {
NewPlrAnim(player, player_graphic::Stand, dir, player._pNFrames, 4);
player._pmode = PM_STAND;
FixPlayerLocation(pnum, dir);
FixPlrWalkTags(pnum);
dPlayer[player.position.tile.x][player.position.tile.y] = pnum + 1;
SetPlayerOld(player);
} else {
if (player._pInvincible && player._pHitPoints == 0 && pnum == myplr) {
SyncPlrKill(pnum, -1);
return;
}
NewPlrAnim(player, player_graphic::Stand, dir, player._pNFrames, 4);
player._pmode = PM_STAND;
FixPlayerLocation(pnum, dir);
FixPlrWalkTags(pnum);
dPlayer[player.position.tile.x][player.position.tile.y] = pnum + 1;
SetPlayerOld(player);
}
void StartWalkStand(int pnum)
@ -1560,20 +1551,17 @@ void StartSpell(int pnum, Direction d, int cx, int cy)
void FixPlrWalkTags(int pnum)
{
int pp, pn;
int dx, dy, y, x;
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("FixPlrWalkTags: illegal player %i", pnum);
}
auto &player = plr[pnum];
pp = pnum + 1;
pn = -(pnum + 1);
dx = player.position.old.x;
dy = player.position.old.y;
for (y = dy - 1; y <= dy + 1; y++) {
for (x = dx - 1; x <= dx + 1; x++) {
int pp = pnum + 1;
int pn = -(pnum + 1);
int dx = player.position.old.x;
int dy = player.position.old.y;
for (int y = dy - 1; y <= dy + 1; y++) {
for (int x = dx - 1; x <= dx + 1; x++) {
if (x >= 0 && x < MAXDUNX && y >= 0 && y < MAXDUNY && (dPlayer[x][y] == pp || dPlayer[x][y] == pn)) {
dPlayer[x][y] = 0;
}
@ -1588,14 +1576,11 @@ void FixPlrWalkTags(int pnum)
void RemovePlrFromMap(int pnum)
{
int x, y;
int pp, pn;
pp = pnum + 1;
pn = -(pnum + 1);
int pp = pnum + 1;
int pn = -(pnum + 1);
for (y = 1; y < MAXDUNY; y++) {
for (x = 1; x < MAXDUNX; x++) {
for (int y = 1; y < MAXDUNY; y++) {
for (int x = 1; x < MAXDUNX; x++) {
if (dPlayer[x][y - 1] == pn || dPlayer[x - 1][y] == pn) {
if ((dFlags[x][y] & BFLAG_PLAYERLR) != 0) {
dFlags[x][y] &= ~BFLAG_PLAYERLR;
@ -1604,8 +1589,8 @@ void RemovePlrFromMap(int pnum)
}
}
for (y = 0; y < MAXDUNY; y++) {
for (x = 0; x < MAXDUNX; x++)
for (int y = 0; y < MAXDUNY; y++) {
for (int x = 0; x < MAXDUNX; x++) // NOLINT(modernize-loop-convert)
if (dPlayer[x][y] == pp || dPlayer[x][y] == pn)
dPlayer[x][y] = 0;
}
@ -1856,20 +1841,17 @@ void DropHalfPlayersGold(int pnum)
void StripTopGold(int pnum)
{
ItemStruct tmpItem;
int i, val;
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("StripTopGold: illegal player %i", pnum);
}
auto &player = plr[pnum];
tmpItem = player.HoldItem;
ItemStruct tmpItem = player.HoldItem;
for (i = 0; i < player._pNumInv; i++) {
for (int i = 0; i < player._pNumInv; i++) {
if (player.InvList[i]._itype == ITYPE_GOLD) {
if (player.InvList[i]._ivalue > MaxGold) {
val = player.InvList[i]._ivalue - MaxGold;
int val = player.InvList[i]._ivalue - MaxGold;
player.InvList[i]._ivalue = MaxGold;
SetPlrHandItem(&player.HoldItem, 0);
GetGoldSeed(pnum, &player.HoldItem);
@ -1950,21 +1932,18 @@ void SyncPlrKill(int pnum, int earflag)
void RemovePlrMissiles(int pnum)
{
int i, am;
int mx, my;
if (currlevel != 0 && pnum == myplr && (monster[myplr].position.tile.x != 1 || monster[myplr].position.tile.y != 0)) {
M_StartKill(myplr, myplr);
AddDead(monster[myplr].position.tile, (monster[myplr].MType)->mdeadval, monster[myplr]._mdir);
mx = monster[myplr].position.tile.x;
my = monster[myplr].position.tile.y;
int mx = monster[myplr].position.tile.x;
int my = monster[myplr].position.tile.y;
dMonster[mx][my] = 0;
monster[myplr]._mDelFlag = true;
DeleteMonsterList();
}
for (i = 0; i < nummissiles; i++) {
am = missileactive[i];
for (int i = 0; i < nummissiles; i++) {
int am = missileactive[i];
if (missile[am]._mitype == MIS_STONE && missile[am]._misource == pnum) {
monster[missile[am]._miVar2]._mmode = (MON_MODE)missile[am]._miVar1;
}
@ -2269,10 +2248,7 @@ bool WeaponDur(int pnum, int durrnd)
bool PlrHitMonst(int pnum, int m)
{
bool rv, ret;
int hit, hper, mind, maxd, ddp, dam, skdam, phanditype, tmac;
hper = 0;
ret = false;
int hper = 0;
bool adjacentDamage = false;
if ((DWORD)m >= MAXMONSTERS) {
@ -2305,14 +2281,12 @@ bool PlrHitMonst(int pnum, int m)
app_fatal("PlrHitMonst: illegal player %i", pnum);
}
rv = false;
hit = GenerateRnd(100);
int hit = GenerateRnd(100);
if (monster[m]._mmode == MM_STONE) {
hit = 0;
}
tmac = monster[m].mArmorClass;
int tmac = monster[m].mArmorClass;
if (gbIsHellfire && player._pIEnAc > 0) {
int _pIEnAc = player._pIEnAc - 1;
if (_pIEnAc > 0)
@ -2342,188 +2316,185 @@ bool PlrHitMonst(int pnum, int m)
hper = 95;
}
bool ret = false;
if (CheckMonsterHit(m, &ret)) {
return ret;
}
#ifdef _DEBUG
if (hit < hper || debug_mode_key_inverted_v || debug_mode_dollar_sign) {
if (hit >= hper && !debug_mode_key_inverted_v && !debug_mode_dollar_sign)
return false;
#else
if (hit < hper) {
if (hit >= hper)
return false;
#endif
if ((player._pIFlags & ISPL_FIREDAM) != 0 && (player._pIFlags & ISPL_LIGHTDAM) != 0) {
int midam = player._pIFMinDam + GenerateRnd(player._pIFMaxDam - player._pIFMinDam);
AddMissile(player.position.tile, player.position.temp, player._pdir, MIS_SPECARROW, TARGET_MONSTERS, pnum, midam, 0);
}
mind = player._pIMinDam;
maxd = player._pIMaxDam;
dam = GenerateRnd(maxd - mind + 1) + mind;
dam += dam * player._pIBonusDam / 100;
dam += player._pIBonusDamMod;
int dam2 = dam << 6;
dam += player._pDamageMod;
if (player._pClass == HeroClass::Warrior || player._pClass == HeroClass::Barbarian) {
ddp = player._pLevel;
if (GenerateRnd(100) < ddp) {
dam *= 2;
}
if ((player._pIFlags & ISPL_FIREDAM) != 0 && (player._pIFlags & ISPL_LIGHTDAM) != 0) {
int midam = player._pIFMinDam + GenerateRnd(player._pIFMaxDam - player._pIFMinDam);
AddMissile(player.position.tile, player.position.temp, player._pdir, MIS_SPECARROW, TARGET_MONSTERS, pnum, midam, 0);
}
int mind = player._pIMinDam;
int maxd = player._pIMaxDam;
int dam = GenerateRnd(maxd - mind + 1) + mind;
dam += dam * player._pIBonusDam / 100;
dam += player._pIBonusDamMod;
int dam2 = dam << 6;
dam += player._pDamageMod;
if (player._pClass == HeroClass::Warrior || player._pClass == HeroClass::Barbarian) {
int ddp = player._pLevel;
if (GenerateRnd(100) < ddp) {
dam *= 2;
}
}
phanditype = ITYPE_NONE;
if (player.InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_SWORD || player.InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SWORD) {
phanditype = ITYPE_SWORD;
}
if (player.InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_MACE || player.InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_MACE) {
phanditype = ITYPE_MACE;
}
int phanditype = ITYPE_NONE;
if (player.InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_SWORD || player.InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SWORD) {
phanditype = ITYPE_SWORD;
}
if (player.InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_MACE || player.InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_MACE) {
phanditype = ITYPE_MACE;
}
switch (monster[m].MData->mMonstClass) {
case MC_UNDEAD:
if (phanditype == ITYPE_SWORD) {
dam -= dam / 2;
} else if (phanditype == ITYPE_MACE) {
dam += dam / 2;
}
break;
case MC_ANIMAL:
if (phanditype == ITYPE_MACE) {
dam -= dam / 2;
} else if (phanditype == ITYPE_SWORD) {
dam += dam / 2;
}
break;
case MC_DEMON:
if ((player._pIFlags & ISPL_3XDAMVDEM) != 0) {
dam *= 3;
}
break;
switch (monster[m].MData->mMonstClass) {
case MC_UNDEAD:
if (phanditype == ITYPE_SWORD) {
dam -= dam / 2;
} else if (phanditype == ITYPE_MACE) {
dam += dam / 2;
}
if ((player.pDamAcFlags & 0x01) != 0 && GenerateRnd(100) < 5) {
break;
case MC_ANIMAL:
if (phanditype == ITYPE_MACE) {
dam -= dam / 2;
} else if (phanditype == ITYPE_SWORD) {
dam += dam / 2;
}
break;
case MC_DEMON:
if ((player._pIFlags & ISPL_3XDAMVDEM) != 0) {
dam *= 3;
}
break;
}
if ((player.pDamAcFlags & 0x10) != 0 && monster[m].MType->mtype != MT_DIABLO && monster[m]._uniqtype == 0 && GenerateRnd(100) < 10) {
monster_43C785(m);
}
if ((player.pDamAcFlags & 0x01) != 0 && GenerateRnd(100) < 5) {
dam *= 3;
}
dam <<= 6;
if ((player.pDamAcFlags & 0x08) != 0) {
int r = GenerateRnd(201);
if (r >= 100)
r = 100 + (r - 100) * 5;
dam = dam * r / 100;
}
if ((player.pDamAcFlags & 0x10) != 0 && monster[m].MType->mtype != MT_DIABLO && monster[m]._uniqtype == 0 && GenerateRnd(100) < 10) {
monster_43C785(m);
}
if (adjacentDamage)
dam >>= 2;
dam <<= 6;
if ((player.pDamAcFlags & 0x08) != 0) {
int r = GenerateRnd(201);
if (r >= 100)
r = 100 + (r - 100) * 5;
dam = dam * r / 100;
}
if (pnum == myplr) {
if ((player.pDamAcFlags & 0x04) != 0) {
dam2 += player._pIGetHit << 6;
if (dam2 >= 0) {
ApplyPlrDamage(pnum, 0, 1, dam2);
}
dam *= 2;
if (adjacentDamage)
dam >>= 2;
if (pnum == myplr) {
if ((player.pDamAcFlags & 0x04) != 0) {
dam2 += player._pIGetHit << 6;
if (dam2 >= 0) {
ApplyPlrDamage(pnum, 0, 1, dam2);
}
monster[m]._mhitpoints -= dam;
dam *= 2;
}
monster[m]._mhitpoints -= dam;
}
if ((player._pIFlags & ISPL_RNDSTEALLIFE) != 0) {
skdam = GenerateRnd(dam / 8);
player._pHitPoints += skdam;
if (player._pHitPoints > player._pMaxHP) {
player._pHitPoints = player._pMaxHP;
}
player._pHPBase += skdam;
if (player._pHPBase > player._pMaxHPBase) {
player._pHPBase = player._pMaxHPBase;
}
drawhpflag = true;
int skdam = 0;
if ((player._pIFlags & ISPL_RNDSTEALLIFE) != 0) {
skdam = GenerateRnd(dam / 8);
player._pHitPoints += skdam;
if (player._pHitPoints > player._pMaxHP) {
player._pHitPoints = player._pMaxHP;
}
if ((player._pIFlags & (ISPL_STEALMANA_3 | ISPL_STEALMANA_5)) != 0 && (player._pIFlags & ISPL_NOMANA) == 0) {
if ((player._pIFlags & ISPL_STEALMANA_3) != 0) {
skdam = 3 * dam / 100;
}
if ((player._pIFlags & ISPL_STEALMANA_5) != 0) {
skdam = 5 * dam / 100;
}
player._pMana += skdam;
if (player._pMana > player._pMaxMana) {
player._pMana = player._pMaxMana;
}
player._pManaBase += skdam;
if (player._pManaBase > player._pMaxManaBase) {
player._pManaBase = player._pMaxManaBase;
}
drawmanaflag = true;
player._pHPBase += skdam;
if (player._pHPBase > player._pMaxHPBase) {
player._pHPBase = player._pMaxHPBase;
}
if ((player._pIFlags & (ISPL_STEALLIFE_3 | ISPL_STEALLIFE_5)) != 0) {
if ((player._pIFlags & ISPL_STEALLIFE_3) != 0) {
skdam = 3 * dam / 100;
}
if ((player._pIFlags & ISPL_STEALLIFE_5) != 0) {
skdam = 5 * dam / 100;
}
player._pHitPoints += skdam;
if (player._pHitPoints > player._pMaxHP) {
player._pHitPoints = player._pMaxHP;
}
player._pHPBase += skdam;
if (player._pHPBase > player._pMaxHPBase) {
player._pHPBase = player._pMaxHPBase;
}
drawhpflag = true;
drawhpflag = true;
}
if ((player._pIFlags & (ISPL_STEALMANA_3 | ISPL_STEALMANA_5)) != 0 && (player._pIFlags & ISPL_NOMANA) == 0) {
if ((player._pIFlags & ISPL_STEALMANA_3) != 0) {
skdam = 3 * dam / 100;
}
if ((player._pIFlags & ISPL_NOHEALPLR) != 0) {
monster[m]._mFlags |= MFLAG_NOHEAL;
if ((player._pIFlags & ISPL_STEALMANA_5) != 0) {
skdam = 5 * dam / 100;
}
#ifdef _DEBUG
if (debug_mode_dollar_sign || debug_mode_key_inverted_v) {
monster[m]._mhitpoints = 0; /* double check */
player._pMana += skdam;
if (player._pMana > player._pMaxMana) {
player._pMana = player._pMaxMana;
}
player._pManaBase += skdam;
if (player._pManaBase > player._pMaxManaBase) {
player._pManaBase = player._pMaxManaBase;
}
drawmanaflag = true;
}
if ((player._pIFlags & (ISPL_STEALLIFE_3 | ISPL_STEALLIFE_5)) != 0) {
if ((player._pIFlags & ISPL_STEALLIFE_3) != 0) {
skdam = 3 * dam / 100;
}
if ((player._pIFlags & ISPL_STEALLIFE_5) != 0) {
skdam = 5 * dam / 100;
}
player._pHitPoints += skdam;
if (player._pHitPoints > player._pMaxHP) {
player._pHitPoints = player._pMaxHP;
}
player._pHPBase += skdam;
if (player._pHPBase > player._pMaxHPBase) {
player._pHPBase = player._pMaxHPBase;
}
drawhpflag = true;
}
if ((player._pIFlags & ISPL_NOHEALPLR) != 0) {
monster[m]._mFlags |= MFLAG_NOHEAL;
}
#ifdef _DEBUG
if (debug_mode_dollar_sign || debug_mode_key_inverted_v) {
monster[m]._mhitpoints = 0; /* double check */
}
#endif
if ((monster[m]._mhitpoints >> 6) <= 0) {
if (monster[m]._mmode == MM_STONE) {
M_StartKill(m, pnum);
monster[m].Petrify();
} else {
M_StartKill(m, pnum);
}
if ((monster[m]._mhitpoints >> 6) <= 0) {
if (monster[m]._mmode == MM_STONE) {
M_StartKill(m, pnum);
monster[m].Petrify();
} else {
if (monster[m]._mmode == MM_STONE) {
M_StartHit(m, pnum, dam);
monster[m].Petrify();
} else {
if ((player._pIFlags & ISPL_KNOCKBACK) != 0) {
M_GetKnockback(m);
}
M_StartHit(m, pnum, dam);
M_StartKill(m, pnum);
}
} else {
if (monster[m]._mmode == MM_STONE) {
M_StartHit(m, pnum, dam);
monster[m].Petrify();
} else {
if ((player._pIFlags & ISPL_KNOCKBACK) != 0) {
M_GetKnockback(m);
}
M_StartHit(m, pnum, dam);
}
rv = true;
}
return rv;
return true;
}
bool PlrHitPlr(int pnum, int8_t p)
{
bool rv;
int hit, hper, blk, blkper, mind, maxd, dam, lvl, skdam, tac;
if ((DWORD)p >= MAX_PLRS) {
app_fatal("PlrHitPlr: illegal target player %i", p);
}
auto &target = plr[p];
rv = false;
if (target._pInvincible) {
return rv;
return false;
}
if ((target._pSpellFlags & 1) != 0) {
return rv;
return false;
}
if ((DWORD)pnum >= MAX_PLRS) {
@ -2531,9 +2502,9 @@ bool PlrHitPlr(int pnum, int8_t p)
}
auto &attacker = plr[pnum];
hit = GenerateRnd(100);
int hit = GenerateRnd(100);
hper = (attacker._pDexterity / 2) + attacker._pLevel + 50 - (target._pIBonusAC + target._pIAC + target._pDexterity / 5);
int hper = (attacker._pDexterity / 2) + attacker._pLevel + 50 - (target._pIBonusAC + target._pIAC + target._pDexterity / 5);
if (attacker._pClass == HeroClass::Warrior) {
hper += 20;
@ -2546,13 +2517,12 @@ bool PlrHitPlr(int pnum, int8_t p)
hper = 95;
}
int blk = 100;
if ((target._pmode == PM_STAND || target._pmode == PM_ATTACK) && target._pBlockFlag) {
blk = GenerateRnd(100);
} else {
blk = 100;
}
blkper = target._pDexterity + target._pBaseToBlk + (target._pLevel * 2) - (attacker._pLevel * 2);
int blkper = target._pDexterity + target._pBaseToBlk + (target._pLevel * 2) - (attacker._pLevel * 2);
if (blkper < 0) {
blkper = 0;
}
@ -2560,46 +2530,46 @@ bool PlrHitPlr(int pnum, int8_t p)
blkper = 100;
}
if (hit < hper) {
if (blk < blkper) {
Direction dir = GetDirection(target.position.tile, attacker.position.tile);
StartPlrBlock(p, dir);
} else {
mind = attacker._pIMinDam;
maxd = attacker._pIMaxDam;
dam = GenerateRnd(maxd - mind + 1) + mind;
dam += (dam * attacker._pIBonusDam) / 100;
dam += attacker._pIBonusDamMod + attacker._pDamageMod;
if (attacker._pClass == HeroClass::Warrior || attacker._pClass == HeroClass::Barbarian) {
lvl = attacker._pLevel;
if (GenerateRnd(100) < lvl) {
dam *= 2;
}
}
skdam = dam << 6;
if ((attacker._pIFlags & ISPL_RNDSTEALLIFE) != 0) {
tac = GenerateRnd(skdam / 8);
attacker._pHitPoints += tac;
if (attacker._pHitPoints > attacker._pMaxHP) {
attacker._pHitPoints = attacker._pMaxHP;
}
attacker._pHPBase += tac;
if (attacker._pHPBase > attacker._pMaxHPBase) {
attacker._pHPBase = attacker._pMaxHPBase;
}
drawhpflag = true;
}
if (pnum == myplr) {
NetSendCmdDamage(true, p, skdam);
}
StartPlrHit(p, skdam, false);
}
if (hit >= hper) {
return false;
}
rv = true;
if (blk < blkper) {
Direction dir = GetDirection(target.position.tile, attacker.position.tile);
StartPlrBlock(p, dir);
return true;
}
int mind = attacker._pIMinDam;
int maxd = attacker._pIMaxDam;
int dam = GenerateRnd(maxd - mind + 1) + mind;
dam += (dam * attacker._pIBonusDam) / 100;
dam += attacker._pIBonusDamMod + attacker._pDamageMod;
if (attacker._pClass == HeroClass::Warrior || attacker._pClass == HeroClass::Barbarian) {
if (GenerateRnd(100) < attacker._pLevel) {
dam *= 2;
}
}
int skdam = dam << 6;
if ((attacker._pIFlags & ISPL_RNDSTEALLIFE) != 0) {
int tac = GenerateRnd(skdam / 8);
attacker._pHitPoints += tac;
if (attacker._pHitPoints > attacker._pMaxHP) {
attacker._pHitPoints = attacker._pMaxHP;
}
attacker._pHPBase += tac;
if (attacker._pHPBase > attacker._pMaxHPBase) {
attacker._pHPBase = attacker._pMaxHPBase;
}
drawhpflag = true;
}
if (pnum == myplr) {
NetSendCmdDamage(true, p, skdam);
}
StartPlrHit(p, skdam, false);
return rv;
return true;
}
bool PlrHitObj(int pnum, int mx, int my)
@ -2622,9 +2592,6 @@ bool PlrHitObj(int pnum, int mx, int my)
bool PM_DoAttack(int pnum)
{
int dx, dy, m;
bool didhit = false;
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("PM_DoAttack: illegal player %i", pnum);
}
@ -2634,12 +2601,15 @@ bool PM_DoAttack(int pnum)
PlaySfxLoc(PS_SWING, player.position.tile);
}
bool didhit = false;
if (player.AnimInfo.CurrentFrame == player._pAFNum) {
Point position = player.position.tile + player._pdir;
dx = position.x;
dy = position.y;
int dx = position.x;
int dy = position.y;
if (dMonster[dx][dy] != 0) {
int m = -1;
if (dMonster[dx][dy] > 0) {
m = dMonster[dx][dy] - 1;
} else {
@ -2660,7 +2630,7 @@ bool PM_DoAttack(int pnum)
}
if (dMonster[dx][dy] != 0) {
m = dMonster[dx][dy];
int m = dMonster[dx][dy];
if (dMonster[dx][dy] > 0) {
m = dMonster[dx][dy] - 1;
} else {
@ -2689,15 +2659,14 @@ bool PM_DoAttack(int pnum)
|| (player.InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_SWORD && player.InvBody[INVLOC_HAND_LEFT]._iLoc == ILOC_TWOHAND)
|| (player.InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SWORD && player.InvBody[INVLOC_HAND_RIGHT]._iLoc == ILOC_TWOHAND))
&& !(player.InvBody[INVLOC_HAND_LEFT]._itype == ITYPE_SHIELD || player.InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SHIELD))))) {
Point position = player.position.tile + right[player._pdir];
position = player.position.tile + right[player._pdir];
dx = position.x;
dy = position.y;
m = ((dMonster[dx][dy] > 0) ? dMonster[dx][dy] : -dMonster[dx][dy]) - 1;
int m = ((dMonster[dx][dy] > 0) ? dMonster[dx][dy] : -dMonster[dx][dy]) - 1;
if (dMonster[dx][dy] != 0 && !CanTalkToMonst(m) && monster[m].position.old.x == dx && monster[m].position.old.y == dy) {
if (PlrHitMonst(-pnum, m))
didhit = true;
}
position = player.position.tile + left[player._pdir];
dx = position.x;
dy = position.y;
@ -2720,6 +2689,7 @@ bool PM_DoAttack(int pnum)
ClearPlrPVars(player);
return true;
}
return false;
}
@ -2982,14 +2952,15 @@ bool PM_DoDeath(int pnum)
void CheckNewPath(int pnum, bool pmWillBeCalled)
{
int i, x, y;
int xvel3, xvel, yvel;
if ((DWORD)pnum >= MAX_PLRS) {
app_fatal("CheckNewPath: illegal player %i", pnum);
}
auto &player = plr[pnum];
int x = 0;
int y = 0;
int i = -1;
if (player.destAction == ACTION_ATTACKMON) {
i = player.destParam1;
MakePlrPath(pnum, monster[i].position.future, false);
@ -3030,14 +3001,13 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
}
}
int xvel3 = 2048;
int xvel = 1024;
int yvel = 512;
if (currlevel != 0) {
xvel3 = PWVel[static_cast<std::size_t>(player._pClass)][0];
xvel = PWVel[static_cast<std::size_t>(player._pClass)][1];
yvel = PWVel[static_cast<std::size_t>(player._pClass)][2];
} else {
xvel3 = 2048;
xvel = 1024;
yvel = 512;
}
switch (player.walkpath[0]) {
@ -3067,8 +3037,8 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
break;
}
for (i = 1; i < MAX_PATH_LENGTH; i++) {
player.walkpath[i - 1] = player.walkpath[i];
for (int j = 1; j < MAX_PATH_LENGTH; j++) {
player.walkpath[j - 1] = player.walkpath[j];
}
player.walkpath[MAX_PATH_LENGTH - 1] = WALK_NONE;
@ -3333,8 +3303,6 @@ bool PlrDeathModeOK(int p)
void ValidatePlayer()
{
int gt, i, b;
if ((DWORD)myplr >= MAX_PLRS) {
app_fatal("ValidatePlayer: illegal player %i", myplr);
}
@ -3349,8 +3317,8 @@ void ValidatePlayer()
}
}
gt = 0;
for (i = 0; i < myPlayer._pNumInv; i++) {
int gt = 0;
for (int i = 0; i < myPlayer._pNumInv; i++) {
if (myPlayer.InvList[i]._itype == ITYPE_GOLD) {
int maxGold = GOLD_MAX_LIMIT;
if (gbIsHellfire) {
@ -3379,7 +3347,7 @@ void ValidatePlayer()
}
uint64_t msk = 0;
for (b = SPL_FIREBOLT; b < MAX_SPELLS; b++) {
for (int b = SPL_FIREBOLT; b < MAX_SPELLS; b++) {
if (GetSpellBookLevel((spell_id)b) != -1) {
msk |= GetSpellBitmask(b);
if (myPlayer._pSplLvl[b] > MAX_SPELL_LEVEL)
@ -3519,8 +3487,6 @@ void ClrPlrPath(PlayerStruct &player)
bool PosOkPlayer(int pnum, Point position)
{
int8_t p, bv;
if (position.x < 0 || position.x >= MAXDUNX || position.y < 0 || position.y >= MAXDUNY)
return false;
if (dPiece[position.x][position.y] == 0)
@ -3528,6 +3494,7 @@ bool PosOkPlayer(int pnum, Point position)
if (SolidLoc(position))
return false;
if (dPlayer[position.x][position.y] != 0) {
int8_t p = -1;
if (dPlayer[position.x][position.y] > 0) {
p = dPlayer[position.x][position.y] - 1;
} else {
@ -3554,6 +3521,7 @@ bool PosOkPlayer(int pnum, Point position)
}
if (dObject[position.x][position.y] != 0) {
int8_t bv = -1;
if (dObject[position.x][position.y] > 0) {
bv = dObject[position.x][position.y] - 1;
} else {
@ -3731,10 +3699,6 @@ void SyncPlrAnim(int pnum)
void SyncInitPlrPos(int pnum)
{
int xx, yy, range;
DWORD i;
bool posOk;
auto &player = plr[pnum];
if (!gbIsMultiplayer || player.plrlevel != currlevel) {
@ -3742,7 +3706,7 @@ void SyncInitPlrPos(int pnum)
}
Point position = {};
for (i = 0; i < 8; i++) {
for (int i = 0; i < 8; i++) {
position = player.position.tile + Point { plrxoff2[i], plryoff2[i] };
if (PosOkPlayer(pnum, position)) {
break;
@ -3750,11 +3714,11 @@ void SyncInitPlrPos(int pnum)
}
if (!PosOkPlayer(pnum, position)) {
posOk = false;
for (range = 1; range < 50 && !posOk; range++) {
for (yy = -range; yy <= range && !posOk; yy++) {
bool posOk = false;
for (int range = 1; range < 50 && !posOk; range++) {
for (int yy = -range; yy <= range && !posOk; yy++) {
position.y = yy + player.position.tile.y;
for (xx = -range; xx <= range && !posOk; xx++) {
for (int xx = -range; xx <= range && !posOk; xx++) {
position.x = xx + player.position.tile.x;
if (PosOkPlayer(pnum, position) && !PosOkPortal(currlevel, position.x, position.y)) {
posOk = true;

11
Source/qol/itemlabels.cpp

@ -31,10 +31,10 @@ bool isLabelHighlighted = false;
std::array<std::optional<int>, ITEMTYPES> labelCenterOffsets;
bool invertHighlightToggle = false;
const int borderX = 4; // minimal horizontal space between labels
const int borderY = 2; // minimal vertical space between labels
const int marginX = 2; // horizontal margins between text and edges of the label
const int marginY = 1; // vertical margins between text and edges of the label
const int borderX = 4; // minimal horizontal space between labels
const int borderY = 2; // minimal vertical space between labels
const int marginX = 2; // horizontal margins between text and edges of the label
const int marginY = 1; // vertical margins between text and edges of the label
const int height = 11 + marginY * 2; // going above 13 scatters labels of items that are next to each other
} // namespace
@ -121,7 +121,8 @@ void DrawItemNameLabels(const CelOutputBuffer &out)
do {
canShow = true;
for (unsigned int j = 0; j < i; ++j) {
itemLabel &a = labelQueue[i], &b = labelQueue[j];
itemLabel &a = labelQueue[i];
itemLabel &b = labelQueue[j];
if (abs(b.pos.y - a.pos.y) < height + borderY) {
int widthA = a.width + borderX + marginX * 2;
int widthB = b.width + borderX + marginX * 2;

116
Source/quests.cpp

@ -113,15 +113,12 @@ int QuestGroup4[2] = { Q_VEIL, Q_WARLORD };
void InitQuests()
{
int i, initiatedQuests;
DWORD z;
if (!gbIsMultiplayer) {
for (i = 0; i < MAXQUESTS; i++) {
quests[i]._qactive = QUEST_NOTAVAIL;
for (auto &quest : quests) {
quest._qactive = QUEST_NOTAVAIL;
}
} else {
for (i = 0; i < MAXQUESTS; i++) {
for (int i = 0; i < MAXQUESTS; i++) {
if (questlist[i].isSinglePlayerOnly) {
quests[i]._qactive = QUEST_NOTAVAIL;
}
@ -133,33 +130,33 @@ void InitQuests()
questlog = false;
WaterDone = 0;
initiatedQuests = 0;
int initiatedQuests = 0;
for (z = 0; z < MAXQUESTS; z++) {
if (gbIsMultiplayer && questlist[z].isSinglePlayerOnly)
for (int i = 0; i < MAXQUESTS; i++) {
if (gbIsMultiplayer && questlist[i].isSinglePlayerOnly)
continue;
quests[z]._qtype = questlist[z]._qdtype;
quests[i]._qtype = questlist[i]._qdtype;
if (gbIsMultiplayer) {
quests[z]._qlevel = questlist[z]._qdmultlvl;
quests[i]._qlevel = questlist[i]._qdmultlvl;
if (!delta_quest_inited(initiatedQuests)) {
quests[z]._qactive = QUEST_INIT;
quests[z]._qvar1 = 0;
quests[z]._qlog = false;
quests[i]._qactive = QUEST_INIT;
quests[i]._qvar1 = 0;
quests[i]._qlog = false;
}
initiatedQuests++;
} else {
quests[z]._qactive = QUEST_INIT;
quests[z]._qlevel = questlist[z]._qdlvl;
quests[z]._qvar1 = 0;
quests[z]._qlog = false;
quests[i]._qactive = QUEST_INIT;
quests[i]._qlevel = questlist[i]._qdlvl;
quests[i]._qvar1 = 0;
quests[i]._qlog = false;
}
quests[z]._qslvl = questlist[z]._qslvl;
quests[z].position = { 0, 0 };
quests[z]._qidx = z;
quests[z]._qlvltype = questlist[z]._qlvlt;
quests[z]._qvar2 = 0;
quests[z]._qmsg = questlist[z]._qdmsg;
quests[i]._qslvl = questlist[i]._qslvl;
quests[i].position = { 0, 0 };
quests[i]._qidx = i;
quests[i]._qlvltype = questlist[i]._qlvlt;
quests[i]._qvar2 = 0;
quests[i]._qmsg = questlist[i]._qdmsg;
}
if (!gbIsMultiplayer && sgOptions.Gameplay.bRandomizeQuests) {
@ -180,8 +177,8 @@ void InitQuests()
#endif
if (gbIsSpawn) {
for (z = 0; z < MAXQUESTS; z++) {
quests[z]._qactive = QUEST_NOTAVAIL;
for (auto &quest : quests) {
quest._qactive = QUEST_NOTAVAIL;
}
}
@ -199,8 +196,6 @@ void CheckQuests()
if (gbIsSpawn)
return;
int i, rportx, rporty;
if (QuestStatus(Q_BETRAYER) && gbIsMultiplayer && quests[Q_BETRAYER]._qvar1 == 2) {
AddObject(OBJ_ALTBOY, 2 * setpc_x + 20, 2 * setpc_y + 22);
quests[Q_BETRAYER]._qvar1 = 3;
@ -218,8 +213,8 @@ void CheckQuests()
&& (quests[Q_BETRAYER]._qvar2 == 0 || quests[Q_BETRAYER]._qvar2 == 2)) {
quests[Q_BETRAYER].position.x = 2 * quests[Q_BETRAYER].position.x + 16;
quests[Q_BETRAYER].position.y = 2 * quests[Q_BETRAYER].position.y + 16;
rportx = quests[Q_BETRAYER].position.x;
rporty = quests[Q_BETRAYER].position.y;
int rportx = quests[Q_BETRAYER].position.x;
int rporty = quests[Q_BETRAYER].position.y;
AddMissile({ rportx, rporty }, { rportx, rporty }, 0, MIS_RPORTAL, TARGET_MONSTERS, myplr, 0, 0);
quests[Q_BETRAYER]._qvar2 = 1;
if (quests[Q_BETRAYER]._qactive == QUEST_ACTIVE) {
@ -231,8 +226,8 @@ void CheckQuests()
&& setlevel
&& setlvlnum == SL_VILEBETRAYER
&& quests[Q_BETRAYER]._qvar2 == 4) {
rportx = 35;
rporty = 32;
int rportx = 35;
int rporty = 32;
AddMissile({ rportx, rporty }, { rportx, rporty }, 0, MIS_RPORTAL, TARGET_MONSTERS, myplr, 0, 0);
quests[Q_BETRAYER]._qvar2 = 3;
}
@ -250,15 +245,15 @@ void CheckQuests()
WaterDone = 32;
}
} else if (plr[myplr]._pmode == PM_STAND) {
for (i = 0; i < MAXQUESTS; i++) {
if (currlevel == quests[i]._qlevel
&& quests[i]._qslvl != 0
&& quests[i]._qactive != QUEST_NOTAVAIL
&& plr[myplr].position.tile == quests[i].position) {
if (quests[i]._qlvltype != DTYPE_NONE) {
setlvltype = quests[i]._qlvltype;
for (auto &quest : quests) {
if (currlevel == quest._qlevel
&& quest._qslvl != 0
&& quest._qactive != QUEST_NOTAVAIL
&& plr[myplr].position.tile == quest.position) {
if (quest._qlvltype != DTYPE_NONE) {
setlvltype = quest._qlvltype;
}
StartNewLvl(myplr, WM_DIABSETLVL, quests[i]._qslvl);
StartNewLvl(myplr, WM_DIABSETLVL, quest._qslvl);
}
}
}
@ -266,8 +261,6 @@ void CheckQuests()
bool ForceQuests()
{
int i, j, qx, qy, ql;
if (gbIsSpawn)
return false;
@ -275,14 +268,13 @@ bool ForceQuests()
return false;
}
for (i = 0; i < MAXQUESTS; i++) {
for (int i = 0; i < MAXQUESTS; i++) {
if (i != Q_BETRAYER && currlevel == quests[i]._qlevel && quests[i]._qslvl != 0) {
ql = quests[quests[i]._qidx]._qslvl - 1;
qx = quests[i].position.x;
qy = quests[i].position.y;
int ql = quests[quests[i]._qidx]._qslvl - 1;
int qx = quests[i].position.x;
int qy = quests[i].position.y;
for (j = 0; j < 7; j++) {
for (int j = 0; j < 7; j++) {
if (qx + questxoff[j] == cursmx && qy + questyoff[j] == cursmy) {
strcpy(infostr, fmt::format(_(/* TRANSLATORS: Used for Quest Portals. {:s} is a Map Name */ "To {:s}"), _(questtrigstr[ql])).c_str());
cursmx = qx;
@ -311,8 +303,6 @@ bool QuestStatus(int i)
void CheckQuestKill(int m, bool sendmsg)
{
int i, j;
if (gbIsSpawn)
return;
@ -338,8 +328,8 @@ void CheckQuestKill(int m, bool sendmsg)
quests[Q_BETRAYER]._qvar1 = 7;
quests[Q_DIABLO]._qactive = QUEST_ACTIVE;
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) {
if (dPiece[i][j] == 370) {
trigs[numtrigs].position = { i, j };
trigs[numtrigs]._tmsg = WM_DIABNEXTLVL;
@ -368,10 +358,8 @@ void CheckQuestKill(int m, bool sendmsg)
void DrawButcher()
{
int x, y;
x = 2 * setpc_x + 16;
y = 2 * setpc_y + 16;
int x = 2 * setpc_x + 16;
int y = 2 * setpc_y + 16;
DRLG_RectTrans(x + 3, y + 3, x + 10, y + 10);
}
@ -639,8 +627,6 @@ void ResyncMPQuests()
void ResyncQuests()
{
int i, tren, x, y;
if (gbIsSpawn)
return;
@ -659,20 +645,20 @@ void ResyncQuests()
setpc_w + setpc_x + 1,
setpc_h + setpc_y + 1);
ObjChangeMapResync(setpc_x, setpc_y, (setpc_w / 2) + setpc_x + 2, (setpc_h / 2) + setpc_y - 2);
for (i = 0; i < nobjects; i++)
for (int i = 0; i < nobjects; i++)
SyncObjectAnim(objectactive[i]);
tren = TransVal;
int tren = TransVal;
TransVal = 9;
DRLG_MRectTrans(setpc_x, setpc_y, (setpc_w / 2) + setpc_x + 4, setpc_y + (setpc_h / 2));
TransVal = tren;
}
if (quests[Q_LTBANNER]._qvar1 == 3) {
x = setpc_x;
y = setpc_y;
int x = setpc_x;
int y = setpc_y;
ObjChangeMapResync(x, y, x + setpc_w + 1, y + setpc_h + 1);
for (i = 0; i < nobjects; i++)
for (int i = 0; i < nobjects; i++)
SyncObjectAnim(objectactive[i]);
tren = TransVal;
int tren = TransVal;
TransVal = 9;
DRLG_MRectTrans(setpc_x, setpc_y, (setpc_w / 2) + setpc_x + 4, setpc_y + (setpc_h / 2));
TransVal = tren;
@ -704,7 +690,7 @@ void ResyncQuests()
ObjChangeMapResync(1, 18, 20, 24);
if (quests[Q_BETRAYER]._qvar1 >= 7)
InitVPTriggers();
for (i = 0; i < nobjects; i++)
for (int i = 0; i < nobjects; i++)
SyncObjectAnim(objectactive[i]);
}
if (currlevel == quests[Q_BETRAYER]._qlevel

68
Source/scrollrt.cpp

@ -506,22 +506,23 @@ static void DrawObject(const CelOutputBuffer &out, int x, int y, int ox, int oy,
if (dObject[x][y] == 0 || light_table_index >= lightmax)
return;
int sx, sy;
int8_t bv;
Point objectPosition {};
int8_t bv = -1;
if (dObject[x][y] > 0) {
bv = dObject[x][y] - 1;
if (object[bv]._oPreFlag != pre)
return;
sx = ox - CalculateWidth2(object[bv]._oAnimWidth);
sy = oy;
objectPosition.x = ox - CalculateWidth2(object[bv]._oAnimWidth);
objectPosition.y = oy;
} else {
bv = -(dObject[x][y] + 1);
if (object[bv]._oPreFlag != pre)
return;
int xx = object[bv].position.x - x;
int yy = object[bv].position.y - y;
sx = (xx * TILE_WIDTH / 2) + ox - CalculateWidth2(object[bv]._oAnimWidth) - (yy * TILE_WIDTH / 2);
sy = oy + (yy * TILE_HEIGHT / 2) + (xx * TILE_HEIGHT / 2);
objectPosition.x = (xx * TILE_WIDTH / 2) + ox - CalculateWidth2(object[bv]._oAnimWidth) - (yy * TILE_WIDTH / 2);
objectPosition.y = oy + (yy * TILE_HEIGHT / 2) + (xx * TILE_HEIGHT / 2);
}
assert(bv >= 0 && bv < MAXOBJECTS);
@ -539,7 +540,6 @@ static void DrawObject(const CelOutputBuffer &out, int x, int y, int ox, int oy,
return;
}
const Point objectPosition { sx, sy };
CelSprite cel { object[bv]._oAnimData, object[bv]._oAnimWidth };
if (bv == pcursobj)
CelBlitOutlineTo(out, 194, objectPosition, cel, object[bv]._oAnimFrame);
@ -661,14 +661,11 @@ static void DrawItem(const CelOutputBuffer &out, int x, int y, int sx, int sy, b
*/
static void DrawMonsterHelper(const CelOutputBuffer &out, int x, int y, int oy, int sx, int sy)
{
int mi, px, py;
MonsterStruct *pMonster;
mi = dMonster[x][y + oy];
int mi = dMonster[x][y + oy];
mi = mi > 0 ? mi - 1 : -(mi + 1);
if (leveltype == DTYPE_TOWN) {
px = sx - CalculateWidth2(towners[mi]._tAnimWidth);
int px = sx - CalculateWidth2(towners[mi]._tAnimWidth);
const Point position { px, sy };
if (mi == pcursmonst) {
CelBlitOutlineTo(out, 166, position, CelSprite(towners[mi]._tAnimData, towners[mi]._tAnimWidth), towners[mi]._tAnimFrame);
@ -686,7 +683,7 @@ static void DrawMonsterHelper(const CelOutputBuffer &out, int x, int y, int oy,
return;
}
pMonster = &monster[mi];
MonsterStruct *pMonster = &monster[mi];
if ((pMonster->_mFlags & MFLAG_HIDDEN) != 0) {
return;
}
@ -703,8 +700,8 @@ static void DrawMonsterHelper(const CelOutputBuffer &out, int x, int y, int oy,
offset = GetOffsetForWalking(pMonster->AnimInfo, pMonster->_mdir);
}
px = sx + offset.x - CalculateWidth2(cel.Width());
py = sy + offset.y;
int px = sx + offset.x - CalculateWidth2(cel.Width());
int py = sy + offset.y;
if (mi == pcursmonst) {
Cl2DrawOutline(out, 233, px, py, cel, pMonster->AnimInfo.GetFrameToUseForRendering());
}
@ -1046,7 +1043,8 @@ int RowsCoveredByPanel()
*/
void CalcTileOffset(int *offsetX, int *offsetY)
{
int x, y;
int x;
int y;
if (zoomflag) {
x = gnScreenWidth % TILE_WIDTH;
@ -1106,11 +1104,12 @@ int tileRows;
void CalcViewportGeometry()
{
int xo, yo;
tileShiftX = 0;
tileShiftY = 0;
// Adjust by player offset and tile grid alignment
int xo = 0;
int yo = 0;
CalcTileOffset(&xo, &yo);
tileOffsetX = 0 - xo;
tileOffsetY = 0 - yo - 1 + TILE_HEIGHT / 2;
@ -1156,8 +1155,6 @@ void CalcViewportGeometry()
*/
static void DrawGame(const CelOutputBuffer &full_out, int x, int y)
{
int sx, sy, columns, rows;
// Limit rendering to the view area
const CelOutputBuffer &out = zoomflag
? full_out.subregionY(0, gnViewportHeight)
@ -1168,11 +1165,11 @@ static void DrawGame(const CelOutputBuffer &full_out, int x, int y)
Point offset = ScrollInfo.offset;
if (myPlayer.IsWalking())
offset = GetOffsetForWalking(myPlayer.AnimInfo, myPlayer._pdir, true);
sx = offset.x + tileOffsetX;
sy = offset.y + tileOffsetY;
int sx = offset.x + tileOffsetX;
int sy = offset.y + tileOffsetY;
columns = tileColums;
rows = tileRows;
int columns = tileColums;
int rows = tileRows;
x += tileShiftX;
y += tileShiftY;
@ -1433,21 +1430,22 @@ void EnableFrameCount()
*/
static void DrawFPS(const CelOutputBuffer &out)
{
DWORD tc, frames;
char String[12];
if (frameflag && gbActive) {
frameend++;
tc = SDL_GetTicks();
frames = tc - framestart;
if (tc - framestart >= 1000) {
framestart = tc;
framerate = 1000 * frameend / frames;
frameend = 0;
}
snprintf(String, 12, "%i FPS", framerate);
DrawString(out, String, Point { 8, 65 }, UIS_RED);
if (!frameflag || !gbActive) {
return;
}
frameend++;
uint32_t tc = SDL_GetTicks();
uint32_t frames = tc - framestart;
if (tc - framestart >= 1000) {
framestart = tc;
framerate = 1000 * frameend / frames;
frameend = 0;
}
snprintf(String, 12, "%i FPS", framerate);
DrawString(out, String, Point { 8, 65 }, UIS_RED);
}
/**

38
Source/sha.cpp

@ -50,26 +50,24 @@ static void SHA1Init(SHA1Context *context)
static void SHA1ProcessMessageBlock(SHA1Context *context)
{
std::uint32_t i, temp;
std::uint32_t W[80];
std::uint32_t A, B, C, D, E;
auto *buf = (std::uint32_t *)context->buffer;
for (i = 0; i < 16; i++)
for (int i = 0; i < 16; i++)
W[i] = SDL_SwapLE32(buf[i]);
for (i = 16; i < 80; i++) {
for (int i = 16; i < 80; i++) {
W[i] = W[i - 16] ^ W[i - 14] ^ W[i - 8] ^ W[i - 3];
}
A = context->state[0];
B = context->state[1];
C = context->state[2];
D = context->state[3];
E = context->state[4];
std::uint32_t A = context->state[0];
std::uint32_t B = context->state[1];
std::uint32_t C = context->state[2];
std::uint32_t D = context->state[3];
std::uint32_t E = context->state[4];
for (i = 0; i < 20; i++) {
temp = SHA1CircularShift(5, A) + ((B & C) | ((~B) & D)) + E + W[i] + 0x5A827999;
for (int i = 0; i < 20; i++) {
std::uint32_t temp = SHA1CircularShift(5, A) + ((B & C) | ((~B) & D)) + E + W[i] + 0x5A827999;
E = D;
D = C;
C = SHA1CircularShift(30, B);
@ -77,8 +75,8 @@ static void SHA1ProcessMessageBlock(SHA1Context *context)
A = temp;
}
for (i = 20; i < 40; i++) {
temp = SHA1CircularShift(5, A) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1;
for (int i = 20; i < 40; i++) {
std::uint32_t temp = SHA1CircularShift(5, A) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1;
E = D;
D = C;
C = SHA1CircularShift(30, B);
@ -86,8 +84,8 @@ static void SHA1ProcessMessageBlock(SHA1Context *context)
A = temp;
}
for (i = 40; i < 60; i++) {
temp = SHA1CircularShift(5, A) + ((B & C) | (B & D) | (C & D)) + E + W[i] + 0x8F1BBCDC;
for (int i = 40; i < 60; i++) {
std::uint32_t temp = SHA1CircularShift(5, A) + ((B & C) | (B & D) | (C & D)) + E + W[i] + 0x8F1BBCDC;
E = D;
D = C;
C = SHA1CircularShift(30, B);
@ -95,8 +93,8 @@ static void SHA1ProcessMessageBlock(SHA1Context *context)
A = temp;
}
for (i = 60; i < 80; i++) {
temp = SHA1CircularShift(5, A) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6;
for (int i = 60; i < 80; i++) {
std::uint32_t temp = SHA1CircularShift(5, A) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6;
E = D;
D = C;
C = SHA1CircularShift(30, B);
@ -113,16 +111,14 @@ static void SHA1ProcessMessageBlock(SHA1Context *context)
static void SHA1Input(SHA1Context *context, const char *message_array, std::uint32_t len)
{
std::uint32_t i, count;
count = context->count[0] + 8 * len;
std::uint32_t count = context->count[0] + 8 * len;
if (count < context->count[0])
context->count[1]++;
context->count[0] = count;
context->count[1] += len >> 29;
for (i = len; i >= 64; i -= 64) {
for (int i = len; i >= 64; i -= 64) {
memcpy(context->buffer, message_array, sizeof(context->buffer));
SHA1ProcessMessageBlock(context);
message_array += 64;

14
Source/spells.cpp

@ -201,13 +201,10 @@ void CastSpell(int id, int spl, int sx, int sy, int dx, int dy, int spllvl)
static void PlacePlayer(int pnum)
{
int max, min, x, y;
DWORD i;
bool done;
Point newPosition = {};
if (plr[pnum].plrlevel == currlevel) {
for (i = 0; i < 8; i++) {
for (int i = 0; i < 8; i++) {
newPosition = plr[pnum].position.tile + Point { plrxoff2[i], plryoff2[i] };
if (PosOkPlayer(pnum, newPosition)) {
break;
@ -215,13 +212,14 @@ static void PlacePlayer(int pnum)
}
if (!PosOkPlayer(pnum, newPosition)) {
done = false;
bool done = false;
for (max = 1, min = -1; min > -50 && !done; max++, min--) {
for (y = min; y <= max && !done; y++) {
int min = -1;
for (int max = 1; min > -50 && !done; max++, min--) {
for (int y = min; y <= max && !done; y++) {
newPosition.y = plr[pnum].position.tile.y + y;
for (x = min; x <= max && !done; x++) {
for (int x = min; x <= max && !done; x++) {
newPosition.x = plr[pnum].position.tile.x + x;
if (PosOkPlayer(pnum, newPosition)) {

2
Source/storm/storm.h

@ -198,7 +198,7 @@ bool SNetJoinGame(char *gameName, char *gamePassword, int *playerid);
*/
bool SNetLeaveGame(int type);
bool SNetReceiveMessage(int *senderplayerid, char **data, int *databytes);
bool SNetReceiveMessage(int *senderplayerid, void **data, uint32_t *databytes);
bool SNetReceiveTurns(int a1, int arraysize, char **arraydata, unsigned int *arraydatabytes, DWORD *arrayplayerstatus);
typedef void (*SEVTHANDLER)(struct _SNETEVENT *);

2
Source/storm/storm_net.cpp

@ -22,7 +22,7 @@ static char gpszGamePassword[128] = {};
static SdlMutex storm_net_mutex;
#endif
bool SNetReceiveMessage(int *senderplayerid, char **data, int *databytes)
bool SNetReceiveMessage(int *senderplayerid, void **data, uint32_t *databytes)
{
#ifndef NONET
std::lock_guard<SdlMutex> lg(storm_net_mutex);

22
Source/sync.cpp

@ -46,14 +46,11 @@ void sync_monster_pos(TSyncMonster *p, int ndx)
bool sync_monster_active(TSyncMonster *p)
{
int i, m, ndx;
uint32_t lru;
int ndx = -1;
uint32_t lru = 0xFFFFFFFF;
ndx = -1;
lru = 0xFFFFFFFF;
for (i = 0; i < nummonsters; i++) {
m = monstactive[i];
for (int i = 0; i < nummonsters; i++) {
int m = monstactive[i];
if (sgnMonsterPriority[m] < lru && sgwLRU[m] < 0xFFFE) {
lru = sgnMonsterPriority[m];
ndx = monstactive[i];
@ -70,17 +67,14 @@ bool sync_monster_active(TSyncMonster *p)
bool sync_monster_active2(TSyncMonster *p)
{
int i, m, ndx;
uint32_t lru;
int ndx = -1;
uint32_t lru = 0xFFFE;
ndx = -1;
lru = 0xFFFE;
for (i = 0; i < nummonsters; i++) {
for (int i = 0; i < nummonsters; i++) {
if (sgnMonsters >= nummonsters) {
sgnMonsters = 0;
}
m = monstactive[sgnMonsters];
int m = monstactive[sgnMonsters];
if (sgwLRU[m] < lru) {
lru = sgwLRU[m];
ndx = monstactive[sgnMonsters];

203
Source/themes.cpp

@ -63,11 +63,10 @@ int trm3y[] = {
bool TFit_Shrine(int i)
{
int xp, yp, found;
int xp = 0;
int yp = 0;
int found = 0;
xp = 0;
yp = 0;
found = 0;
while (found == 0) {
if (dTransVal[xp][yp] == themes[i].ttval) {
if (nTrapTable[dPiece[xp][yp - 1]]
@ -108,19 +107,16 @@ bool TFit_Shrine(int i)
bool TFit_Obj5(int t)
{
int xp, yp;
int i, r, rs;
bool found;
xp = 0;
yp = 0;
r = GenerateRnd(5) + 1;
rs = r;
int xp = 0;
int yp = 0;
int r = GenerateRnd(5) + 1;
int rs = r;
while (r > 0) {
found = false;
bool found = false;
if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) {
found = true;
for (i = 0; found && i < 25; i++) {
for (int i = 0; found && i < 25; i++) {
if (nSolidTable[dPiece[xp + trm5x[i]][yp + trm5y[i]]]) {
found = false;
}
@ -208,11 +204,10 @@ bool CheckThemeObj3(int xp, int yp, int t, int f)
bool TFit_Obj3(int t)
{
int xp, yp;
char objrnd[4] = { 4, 4, 3, 5 };
for (yp = 1; yp < MAXDUNY - 1; yp++) {
for (xp = 1; xp < MAXDUNX - 1; xp++) {
for (int yp = 1; yp < MAXDUNY - 1; yp++) {
for (int xp = 1; xp < MAXDUNX - 1; xp++) {
if (CheckThemeObj3(xp, yp, t, objrnd[leveltype - 1])) {
themex = xp;
themey = yp;
@ -226,57 +221,54 @@ bool TFit_Obj3(int t)
bool CheckThemeReqs(theme_id t)
{
bool rv;
rv = true;
switch (t) {
case THEME_SHRINE:
case THEME_SKELROOM:
case THEME_LIBRARY:
if (leveltype == DTYPE_CAVES || leveltype == DTYPE_HELL) {
rv = false;
return false;
}
break;
case THEME_BLOODFOUNTAIN:
if (!bFountainFlag) {
rv = false;
return false;
}
break;
case THEME_PURIFYINGFOUNTAIN:
if (!pFountainFlag) {
rv = false;
return false;
}
break;
case THEME_ARMORSTAND:
if (leveltype == DTYPE_CATHEDRAL) {
rv = false;
return false;
}
break;
case THEME_CAULDRON:
if (leveltype != DTYPE_HELL || !cauldronFlag) {
rv = false;
return false;
}
break;
case THEME_MURKYFOUNTAIN:
if (!mFountainFlag) {
rv = false;
return false;
}
break;
case THEME_TEARFOUNTAIN:
if (!tFountainFlag) {
rv = false;
return false;
}
break;
case THEME_WEAPONRACK:
if (leveltype == DTYPE_CATHEDRAL) {
rv = false;
return false;
}
break;
default:
break;
}
return rv;
return true;
}
static bool SpecialThemeFit(int i, theme_id t)
@ -365,16 +357,14 @@ static bool SpecialThemeFit(int i, theme_id t)
bool CheckThemeRoom(int tv)
{
int i, j, tarea;
for (i = 0; i < numtrigs; i++) {
for (int i = 0; i < numtrigs; i++) {
if (dTransVal[trigs[i].position.x][trigs[i].position.y] == tv)
return false;
}
tarea = 0;
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
int tarea = 0;
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) {
if (dTransVal[i][j] != tv)
continue;
if ((dFlags[i][j] & BFLAG_POPULATED) != 0)
@ -387,8 +377,8 @@ bool CheckThemeRoom(int tv)
if (leveltype == DTYPE_CATHEDRAL && (tarea < 9 || tarea > 100))
return false;
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) {
if (dTransVal[i][j] != tv || nSolidTable[dPiece[i][j]])
continue;
if (dTransVal[i - 1][j] != tv && !nSolidTable[dPiece[i - 1][j]])
@ -467,23 +457,22 @@ void InitThemes()
*/
void HoldThemeRooms()
{
int i, x, y;
char v;
if (currlevel == 16)
return;
if (currlevel != 16) {
if (leveltype == DTYPE_CATHEDRAL) {
for (i = 0; i < numthemes; i++) {
v = themes[i].ttval;
for (y = 0; y < MAXDUNY; y++) {
for (x = 0; x < MAXDUNX; x++) {
if (dTransVal[x][y] == v) {
dFlags[x][y] |= BFLAG_POPULATED;
}
}
if (leveltype != DTYPE_CATHEDRAL) {
DRLG_HoldThemeRooms();
return;
}
for (int i = 0; i < numthemes; i++) {
uint8_t v = themes[i].ttval;
for (int y = 0; y < MAXDUNY; y++) {
for (int x = 0; x < MAXDUNX; x++) {
if (dTransVal[x][y] == v) {
dFlags[x][y] |= BFLAG_POPULATED;
}
}
} else {
DRLG_HoldThemeRooms();
}
}
}
@ -496,20 +485,18 @@ void HoldThemeRooms()
*/
void PlaceThemeMonsts(int t, int f)
{
int xp, yp;
int scattertypes[138];
int numscattypes, mtype, i;
numscattypes = 0;
for (i = 0; i < nummtypes; i++) {
int numscattypes = 0;
for (int i = 0; i < nummtypes; i++) {
if ((Monsters[i].mPlaceFlags & PLACE_SCATTER) != 0) {
scattertypes[numscattypes] = i;
numscattypes++;
}
}
mtype = scattertypes[GenerateRnd(numscattypes)];
for (yp = 0; yp < MAXDUNY; yp++) {
for (xp = 0; xp < MAXDUNX; xp++) {
int mtype = scattertypes[GenerateRnd(numscattypes)];
for (int yp = 0; yp < MAXDUNY; yp++) {
for (int xp = 0; xp < MAXDUNX; xp++) {
if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]] && dItem[xp][yp] == 0 && dObject[xp][yp] == 0) {
if (GenerateRnd(f) == 0) {
AddMonster({ xp, yp }, static_cast<Direction>(GenerateRnd(8)), mtype, true);
@ -526,12 +513,11 @@ void PlaceThemeMonsts(int t, int f)
*/
void Theme_Barrel(int t)
{
int xp, yp;
char barrnd[4] = { 2, 6, 4, 8 };
char monstrnd[4] = { 5, 7, 3, 9 };
for (yp = 0; yp < MAXDUNY; yp++) {
for (xp = 0; xp < MAXDUNX; xp++) {
for (int yp = 0; yp < MAXDUNY; yp++) {
for (int xp = 0; xp < MAXDUNX; xp++) {
if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) {
if (GenerateRnd(barrnd[leveltype - 1]) == 0) {
_object_id r = OBJ_BARREL;
@ -575,13 +561,11 @@ void Theme_Shrine(int t)
*/
void Theme_MonstPit(int t)
{
int r;
int ixp, iyp;
char monstrnd[4] = { 6, 7, 3, 9 };
uint8_t monstrnd[4] = { 6, 7, 3, 9 };
r = GenerateRnd(100) + 1;
ixp = 0;
iyp = 0;
int r = GenerateRnd(100) + 1;
int ixp = 0;
int iyp = 0;
while (r > 0) {
if (dTransVal[ixp][iyp] == themes[t].ttval && !nSolidTable[dPiece[ixp][iyp]]) {
--r;
@ -609,56 +593,59 @@ void Theme_MonstPit(int t)
*/
void Theme_SkelRoom(int t)
{
int xp, yp, i;
char monstrnd[4] = { 6, 7, 3, 9 };
TFit_SkelRoom(t);
xp = themex;
yp = themey;
int xp = themex;
int yp = themey;
AddObject(OBJ_SKFIRE, xp, yp);
if (GenerateRnd(monstrnd[leveltype - 1]) != 0) {
i = PreSpawnSkeleton();
int i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp - 1, yp - 1 });
} else {
AddObject(OBJ_BANNERL, xp - 1, yp - 1);
}
i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp, yp - 1 });
{
int i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp, yp - 1 });
}
if (GenerateRnd(monstrnd[leveltype - 1]) != 0) {
i = PreSpawnSkeleton();
int i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp + 1, yp - 1 });
} else {
AddObject(OBJ_BANNERR, xp + 1, yp - 1);
}
if (GenerateRnd(monstrnd[leveltype - 1]) != 0) {
i = PreSpawnSkeleton();
int i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp - 1, yp });
} else {
AddObject(OBJ_BANNERM, xp - 1, yp);
}
if (GenerateRnd(monstrnd[leveltype - 1]) != 0) {
i = PreSpawnSkeleton();
int i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp + 1, yp });
} else {
AddObject(OBJ_BANNERM, xp + 1, yp);
}
if (GenerateRnd(monstrnd[leveltype - 1]) != 0) {
i = PreSpawnSkeleton();
int i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp - 1, yp + 1 });
} else {
AddObject(OBJ_BANNERR, xp - 1, yp + 1);
}
i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp, yp + 1 });
{
int i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp, yp + 1 });
}
if (GenerateRnd(monstrnd[leveltype - 1]) != 0) {
i = PreSpawnSkeleton();
int i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp + 1, yp + 1 });
} else {
AddObject(OBJ_BANNERL, xp + 1, yp + 1);
@ -679,14 +666,12 @@ void Theme_SkelRoom(int t)
*/
void Theme_Treasure(int t)
{
int xp, yp;
int i;
char treasrnd[4] = { 4, 9, 7, 10 };
char monstrnd[4] = { 6, 8, 3, 7 };
AdvanceRndSeed();
for (yp = 0; yp < MAXDUNY; yp++) {
for (xp = 0; xp < MAXDUNX; xp++) {
for (int yp = 0; yp < MAXDUNY; yp++) {
for (int xp = 0; xp < MAXDUNX; xp++) {
if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) {
int rv = GenerateRnd(treasrnd[leveltype - 1]);
// BUGFIX: the `2*` in `2*GenerateRnd(treasrnd...) == 0` has no effect, should probably be `GenerateRnd(2*treasrnd...) == 0`
@ -699,7 +684,7 @@ void Theme_Treasure(int t)
ItemNoFlippy();
}
if (rv == 0 || rv >= treasrnd[leveltype - 1] - 2) {
i = ItemNoFlippy();
int i = ItemNoFlippy();
if (rv >= treasrnd[leveltype - 1] - 2 && leveltype != DTYPE_CATHEDRAL) {
items[i]._ivalue /= 2;
}
@ -717,7 +702,6 @@ void Theme_Treasure(int t)
*/
void Theme_Library(int t)
{
int xp, yp, oi;
char librnd[4] = { 1, 2, 2, 5 };
char monstrnd[4] = { 5, 7, 3, 9 };
@ -733,12 +717,12 @@ void Theme_Library(int t)
AddObject(OBJ_BOOKCANDLE, themex, themey + 1);
}
for (yp = 1; yp < MAXDUNY - 1; yp++) {
for (xp = 1; xp < MAXDUNX - 1; xp++) {
for (int yp = 1; yp < MAXDUNY - 1; yp++) {
for (int xp = 1; xp < MAXDUNX - 1; xp++) {
if (CheckThemeObj3(xp, yp, t, -1) && dMonster[xp][yp] == 0 && GenerateRnd(librnd[leveltype - 1]) == 0) {
AddObject(OBJ_BOOKSTAND, xp, yp);
if (GenerateRnd(2 * librnd[leveltype - 1]) != 0 && dObject[xp][yp] != 0) { /// BUGFIX: check dObject[xp][yp] was populated by AddObject (fixed)
oi = dObject[xp][yp] - 1;
int oi = dObject[xp][yp] - 1;
object[oi]._oSelFlag = 0;
object[oi]._oAnimFrame += 2;
}
@ -763,12 +747,11 @@ void Theme_Library(int t)
*/
void Theme_Torture(int t)
{
int xp, yp;
char tortrnd[4] = { 6, 8, 3, 8 };
char monstrnd[4] = { 6, 8, 3, 9 };
for (yp = 1; yp < MAXDUNY - 1; yp++) {
for (xp = 1; xp < MAXDUNX - 1; xp++) {
for (int yp = 1; yp < MAXDUNY - 1; yp++) {
for (int xp = 1; xp < MAXDUNX - 1; xp++) {
if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) {
if (CheckThemeObj3(xp, yp, t, -1)) {
if (GenerateRnd(tortrnd[leveltype - 1]) == 0) {
@ -801,12 +784,11 @@ void Theme_BloodFountain(int t)
*/
void Theme_Decap(int t)
{
int xp, yp;
char decaprnd[4] = { 6, 8, 3, 8 };
char monstrnd[4] = { 6, 8, 3, 9 };
for (yp = 1; yp < MAXDUNY - 1; yp++) {
for (xp = 1; xp < MAXDUNX - 1; xp++) {
for (int yp = 1; yp < MAXDUNY - 1; yp++) {
for (int xp = 1; xp < MAXDUNX - 1; xp++) {
if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) {
if (CheckThemeObj3(xp, yp, t, -1)) {
if (GenerateRnd(decaprnd[leveltype - 1]) == 0) {
@ -840,7 +822,6 @@ void Theme_PurifyingFountain(int t)
*/
void Theme_ArmorStand(int t)
{
int xp, yp;
char armorrnd[4] = { 6, 8, 3, 8 };
char monstrnd[4] = { 6, 7, 3, 9 };
@ -848,8 +829,8 @@ void Theme_ArmorStand(int t)
TFit_Obj3(t);
AddObject(OBJ_ARMORSTAND, themex, themey);
}
for (yp = 0; yp < MAXDUNY; yp++) {
for (xp = 0; xp < MAXDUNX; xp++) {
for (int yp = 0; yp < MAXDUNY; yp++) {
for (int xp = 0; xp < MAXDUNX; xp++) {
if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) {
if (CheckThemeObj3(xp, yp, t, -1)) {
if (GenerateRnd(armorrnd[leveltype - 1]) == 0) {
@ -870,12 +851,10 @@ void Theme_ArmorStand(int t)
*/
void Theme_GoatShrine(int t)
{
int xx, yy;
TFit_GoatShrine(t);
AddObject(OBJ_GOATSHRINE, themex, themey);
for (yy = themey - 1; yy <= themey + 1; yy++) {
for (xx = themex - 1; xx <= themex + 1; xx++) {
for (int yy = themey - 1; yy <= themey + 1; yy++) {
for (int xx = themex - 1; xx <= themex + 1; xx++) {
if (dTransVal[xx][yy] == themes[t].ttval && !nSolidTable[dPiece[xx][yy]] && (xx != themex || yy != themey)) {
AddMonster({ xx, yy }, DIR_SW, themeVar1, true);
}
@ -932,12 +911,11 @@ void Theme_TearFountain(int t)
*/
void Theme_BrnCross(int t)
{
int xp, yp;
char monstrnd[4] = { 6, 8, 3, 9 };
char bcrossrnd[4] = { 5, 7, 3, 8 };
for (yp = 0; yp < MAXDUNY; yp++) {
for (xp = 0; xp < MAXDUNX; xp++) {
for (int yp = 0; yp < MAXDUNY; yp++) {
for (int xp = 0; xp < MAXDUNX; xp++) {
if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) {
if (CheckThemeObj3(xp, yp, t, -1)) {
if (GenerateRnd(bcrossrnd[leveltype - 1]) == 0) {
@ -958,7 +936,6 @@ void Theme_BrnCross(int t)
*/
void Theme_WeaponRack(int t)
{
int xp, yp;
char weaponrnd[4] = { 6, 8, 5, 8 };
char monstrnd[4] = { 6, 7, 3, 9 };
@ -966,8 +943,8 @@ void Theme_WeaponRack(int t)
TFit_Obj3(t);
AddObject(OBJ_WEAPONRACK, themex, themey);
}
for (yp = 0; yp < MAXDUNY; yp++) {
for (xp = 0; xp < MAXDUNX; xp++) {
for (int yp = 0; yp < MAXDUNY; yp++) {
for (int xp = 0; xp < MAXDUNX; xp++) {
if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) {
if (CheckThemeObj3(xp, yp, t, -1)) {
if (GenerateRnd(weaponrnd[leveltype - 1]) == 0) {
@ -986,10 +963,8 @@ void Theme_WeaponRack(int t)
*/
void UpdateL4Trans()
{
int i, j;
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) { // NOLINT(modernize-loop-convert)
if (dTransVal[i][j] != 0) {
dTransVal[i][j] = 1;
}
@ -1002,13 +977,11 @@ void UpdateL4Trans()
*/
void CreateThemeRooms()
{
int i;
if (currlevel == 16) {
return;
}
InitObjFlag = true;
for (i = 0; i < numthemes; i++) {
for (int i = 0; i < numthemes; i++) {
themex = 0;
themey = 0;
switch (themes[i].ttype) {

14
Source/town.cpp

@ -153,10 +153,8 @@ void TownCloseGrave()
*/
void T_Pass3()
{
int xx, yy, x;
for (yy = 0; yy < MAXDUNY; yy += 2) {
for (xx = 0; xx < MAXDUNX; xx += 2) {
for (int yy = 0; yy < MAXDUNY; yy += 2) {
for (int xx = 0; xx < MAXDUNX; xx += 2) {
dPiece[xx][yy] = 0;
dPiece[xx + 1][yy] = 0;
dPiece[xx][yy + 1] = 0;
@ -178,7 +176,7 @@ void T_Pass3()
T_FillTile(16, 70, 331);
}
if (gbIsSpawn || ((plr[myplr].pTownWarps & 4) == 0 && (!gbIsHellfire || plr[myplr]._pLevel < 20))) {
for (x = 36; x < 46; x++) {
for (int x = 36; x < 46; x++) {
T_FillTile(x, 78, GenerateRnd(4) + 1);
}
}
@ -283,8 +281,6 @@ void TownOpenGrave()
*/
void CreateTown(lvl_entry entry)
{
int x, y;
dminx = 10;
dminy = 10;
dmaxx = 84;
@ -331,8 +327,8 @@ void CreateTown(lvl_entry entry)
memset(dItem, 0, sizeof(dItem));
memset(dSpecial, 0, sizeof(dSpecial));
for (y = 0; y < MAXDUNY; y++) {
for (x = 0; x < MAXDUNX; x++) {
for (int y = 0; y < MAXDUNY; y++) {
for (int x = 0; x < MAXDUNX; x++) {
if (dPiece[x][y] == 360) {
dSpecial[x][y] = 1;
} else if (dPiece[x][y] == 358) {

172
Source/trigs.cpp

@ -122,12 +122,10 @@ void InitTownTriggers()
void InitL1Triggers()
{
int i, j;
numtrigs = 0;
if (currlevel < 17) {
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) {
if (dPiece[i][j] == 129) {
trigs[numtrigs].position = { i, j };
trigs[numtrigs]._tmsg = WM_DIABPREVLVL;
@ -141,8 +139,8 @@ void InitL1Triggers()
}
}
} else {
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) {
if (dPiece[i][j] == 184) {
trigs[numtrigs].position = { i, j };
trigs[numtrigs]._tmsg = WM_DIABTWARPUP;
@ -167,11 +165,9 @@ void InitL1Triggers()
void InitL2Triggers()
{
int i, j;
numtrigs = 0;
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) {
if (dPiece[i][j] == 267 && (i != quests[Q_SCHAMB].position.x || j != quests[Q_SCHAMB].position.y)) {
trigs[numtrigs].position = { i, j };
trigs[numtrigs]._tmsg = WM_DIABPREVLVL;
@ -197,12 +193,10 @@ void InitL2Triggers()
void InitL3Triggers()
{
int i, j;
if (currlevel < 17) {
numtrigs = 0;
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) {
if (dPiece[i][j] == 171) {
trigs[numtrigs].position = { i, j };
trigs[numtrigs]._tmsg = WM_DIABPREVLVL;
@ -224,8 +218,8 @@ void InitL3Triggers()
}
} else {
numtrigs = 0;
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) {
if (dPiece[i][j] == 66) {
trigs[numtrigs].position = { i, j };
trigs[numtrigs]._tmsg = WM_DIABPREVLVL;
@ -251,11 +245,9 @@ void InitL3Triggers()
void InitL4Triggers()
{
int i, j;
numtrigs = 0;
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) {
if (dPiece[i][j] == 83) {
trigs[numtrigs].position = { i, j };
trigs[numtrigs]._tmsg = WM_DIABPREVLVL;
@ -277,8 +269,8 @@ void InitL4Triggers()
}
}
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) {
if (dPiece[i][j] == 370 && quests[Q_BETRAYER]._qactive == QUEST_DONE) {
trigs[numtrigs].position = { i, j };
trigs[numtrigs]._tmsg = WM_DIABNEXTLVL;
@ -323,9 +315,7 @@ void InitVPTriggers()
bool ForceTownTrig()
{
int i, j, k, l;
for (i = 0; TownDownList[i] != -1; i++) {
for (int i = 0; TownDownList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == TownDownList[i]) {
strcpy(infostr, _("Down to dungeon"));
cursmx = 25;
@ -335,8 +325,8 @@ bool ForceTownTrig()
}
if (townwarps[0]) {
for (j = 0; TownWarp1List[j] != -1; j++) {
if (dPiece[cursmx][cursmy] == TownWarp1List[j]) {
for (int i = 0; TownWarp1List[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == TownWarp1List[i]) {
strcpy(infostr, _("Down to catacombs"));
cursmx = 49;
cursmy = 21;
@ -346,8 +336,8 @@ bool ForceTownTrig()
}
if (townwarps[1]) {
for (k = 1199; k <= 1220; k++) {
if (dPiece[cursmx][cursmy] == k) {
for (int i = 1199; i <= 1220; i++) {
if (dPiece[cursmx][cursmy] == i) {
strcpy(infostr, _("Down to caves"));
cursmx = 17;
cursmy = 69;
@ -357,8 +347,8 @@ bool ForceTownTrig()
}
if (townwarps[2]) {
for (l = 1240; l <= 1255; l++) {
if (dPiece[cursmx][cursmy] == l) {
for (int i = 1240; i <= 1255; i++) {
if (dPiece[cursmx][cursmy] == i) {
strcpy(infostr, _("Down to hell"));
cursmx = 41;
cursmy = 80;
@ -368,7 +358,7 @@ bool ForceTownTrig()
}
if (gbIsHellfire) {
for (i = 0; TownCryptList[i] != -1; i++) {
for (int i = 0; TownCryptList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == TownCryptList[i]) {
strcpy(infostr, _("Down to Crypt"));
cursmx = 36;
@ -376,7 +366,7 @@ bool ForceTownTrig()
return true;
}
}
for (i = 0; TownHiveList[i] != -1; i++) {
for (int i = 0; TownHiveList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == TownHiveList[i]) {
strcpy(infostr, _("Down to Hive"));
cursmx = 80;
@ -391,17 +381,14 @@ bool ForceTownTrig()
bool ForceL1Trig()
{
int i, j;
int dx, dy;
if (currlevel < 17) {
for (i = 0; L1UpList[i] != -1; i++) {
for (int i = 0; L1UpList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == L1UpList[i]) {
if (currlevel > 1)
strcpy(infostr, fmt::format(_("Up to level {:d}"), currlevel - 1).c_str());
else
strcpy(infostr, _("Up to town"));
for (j = 0; j < numtrigs; j++) {
for (int j = 0; j < numtrigs; j++) {
if (trigs[j]._tmsg == WM_DIABPREVLVL) {
cursmx = trigs[j].position.x;
cursmy = trigs[j].position.y;
@ -410,10 +397,10 @@ bool ForceL1Trig()
}
}
}
for (i = 0; L1DownList[i] != -1; i++) {
for (int i = 0; L1DownList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == L1DownList[i]) {
strcpy(infostr, fmt::format(_("Down to level {:d}"), currlevel + 1).c_str());
for (j = 0; j < numtrigs; j++) {
for (int j = 0; j < numtrigs; j++) {
if (trigs[j]._tmsg == WM_DIABNEXTLVL) {
cursmx = trigs[j].position.x;
cursmy = trigs[j].position.y;
@ -423,10 +410,10 @@ bool ForceL1Trig()
}
}
} else {
for (i = 0; L5UpList[i] != -1; i++) {
for (int i = 0; L5UpList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == L5UpList[i]) {
strcpy(infostr, fmt::format(_("Up to Crypt level {:d}"), currlevel - 21).c_str());
for (j = 0; j < numtrigs; j++) {
for (int j = 0; j < numtrigs; j++) {
if (trigs[j]._tmsg == WM_DIABPREVLVL) {
cursmx = trigs[j].position.x;
cursmy = trigs[j].position.y;
@ -439,10 +426,10 @@ bool ForceL1Trig()
strcpy(infostr, _("Cornerstone of the World"));
return true;
}
for (i = 0; L5DownList[i] != -1; i++) {
for (int i = 0; L5DownList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == L5DownList[i]) {
strcpy(infostr, fmt::format(_("Down to Crypt level {:d}"), currlevel - 19).c_str());
for (j = 0; j < numtrigs; j++) {
for (int j = 0; j < numtrigs; j++) {
if (trigs[j]._tmsg == WM_DIABNEXTLVL) {
cursmx = trigs[j].position.x;
cursmy = trigs[j].position.y;
@ -452,12 +439,12 @@ bool ForceL1Trig()
}
}
if (currlevel == 21) {
for (i = 0; L5TWarpUpList[i] != -1; i++) {
for (int i = 0; L5TWarpUpList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == L5TWarpUpList[i]) {
for (j = 0; j < numtrigs; j++) {
for (int j = 0; j < numtrigs; j++) {
if (trigs[j]._tmsg == WM_DIABTWARPUP) {
dx = abs(trigs[j].position.x - cursmx);
dy = abs(trigs[j].position.y - cursmy);
int dx = abs(trigs[j].position.x - cursmx);
int dy = abs(trigs[j].position.y - cursmy);
if (dx < 4 && dy < 4) {
strcpy(infostr, _("Up to town"));
cursmx = trigs[j].position.x;
@ -476,14 +463,12 @@ bool ForceL1Trig()
bool ForceL2Trig()
{
int i, j, dx, dy;
for (i = 0; L2UpList[i] != -1; i++) {
for (int i = 0; L2UpList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == L2UpList[i]) {
for (j = 0; j < numtrigs; j++) {
for (int j = 0; j < numtrigs; j++) {
if (trigs[j]._tmsg == WM_DIABPREVLVL) {
dx = abs(trigs[j].position.x - cursmx);
dy = abs(trigs[j].position.y - cursmy);
int dx = abs(trigs[j].position.x - cursmx);
int dy = abs(trigs[j].position.y - cursmy);
if (dx < 4 && dy < 4) {
strcpy(infostr, fmt::format(_("Up to level {:d}"), currlevel - 1).c_str());
cursmx = trigs[j].position.x;
@ -495,10 +480,10 @@ bool ForceL2Trig()
}
}
for (i = 0; L2DownList[i] != -1; i++) {
for (int i = 0; L2DownList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == L2DownList[i]) {
strcpy(infostr, fmt::format(_("Down to level {:d}"), currlevel + 1).c_str());
for (j = 0; j < numtrigs; j++) {
for (int j = 0; j < numtrigs; j++) {
if (trigs[j]._tmsg == WM_DIABNEXTLVL) {
cursmx = trigs[j].position.x;
cursmy = trigs[j].position.y;
@ -509,12 +494,12 @@ bool ForceL2Trig()
}
if (currlevel == 5) {
for (i = 0; L2TWarpUpList[i] != -1; i++) {
for (int i = 0; L2TWarpUpList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == L2TWarpUpList[i]) {
for (j = 0; j < numtrigs; j++) {
for (int j = 0; j < numtrigs; j++) {
if (trigs[j]._tmsg == WM_DIABTWARPUP) {
dx = abs(trigs[j].position.x - cursmx);
dy = abs(trigs[j].position.y - cursmy);
int dx = abs(trigs[j].position.x - cursmx);
int dy = abs(trigs[j].position.y - cursmy);
if (dx < 4 && dy < 4) {
strcpy(infostr, _("Up to town"));
cursmx = trigs[j].position.x;
@ -532,13 +517,11 @@ bool ForceL2Trig()
bool ForceL3Trig()
{
int i, j, dx, dy;
if (currlevel < 17) {
for (i = 0; L3UpList[i] != -1; ++i) {
for (int i = 0; L3UpList[i] != -1; ++i) {
if (dPiece[cursmx][cursmy] == L3UpList[i]) {
strcpy(infostr, fmt::format(_("Up to level {:d}"), currlevel - 1).c_str());
for (j = 0; j < numtrigs; j++) {
for (int j = 0; j < numtrigs; j++) {
if (trigs[j]._tmsg == WM_DIABPREVLVL) {
cursmx = trigs[j].position.x;
cursmy = trigs[j].position.y;
@ -547,12 +530,12 @@ bool ForceL3Trig()
}
}
}
for (i = 0; L3DownList[i] != -1; i++) {
for (int i = 0; L3DownList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == L3DownList[i]
|| dPiece[cursmx + 1][cursmy] == L3DownList[i]
|| dPiece[cursmx + 2][cursmy] == L3DownList[i]) {
strcpy(infostr, fmt::format(_("Down to level {:d}"), currlevel + 1).c_str());
for (j = 0; j < numtrigs; j++) {
for (int j = 0; j < numtrigs; j++) {
if (trigs[j]._tmsg == WM_DIABNEXTLVL) {
cursmx = trigs[j].position.x;
cursmy = trigs[j].position.y;
@ -562,10 +545,10 @@ bool ForceL3Trig()
}
}
} else {
for (i = 0; L6UpList[i] != -1; ++i) {
for (int i = 0; L6UpList[i] != -1; ++i) {
if (dPiece[cursmx][cursmy] == L6UpList[i]) {
strcpy(infostr, fmt::format(_("Up to Nest level {:d}"), currlevel - 17).c_str());
for (j = 0; j < numtrigs; j++) {
for (int j = 0; j < numtrigs; j++) {
if (trigs[j]._tmsg == WM_DIABPREVLVL) {
cursmx = trigs[j].position.x;
cursmy = trigs[j].position.y;
@ -574,12 +557,12 @@ bool ForceL3Trig()
}
}
}
for (i = 0; L6DownList[i] != -1; i++) {
for (int i = 0; L6DownList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == L6DownList[i]
|| dPiece[cursmx + 1][cursmy] == L6DownList[i]
|| dPiece[cursmx + 2][cursmy] == L6DownList[i]) {
strcpy(infostr, fmt::format(_("Down to level {:d}"), currlevel - 15).c_str());
for (j = 0; j < numtrigs; j++) {
for (int j = 0; j < numtrigs; j++) {
if (trigs[j]._tmsg == WM_DIABNEXTLVL) {
cursmx = trigs[j].position.x;
cursmy = trigs[j].position.y;
@ -591,12 +574,12 @@ bool ForceL3Trig()
}
if (currlevel == 9) {
for (i = 0; L3TWarpUpList[i] != -1; i++) {
for (int i = 0; L3TWarpUpList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == L3TWarpUpList[i]) {
for (j = 0; j < numtrigs; j++) {
for (int j = 0; j < numtrigs; j++) {
if (trigs[j]._tmsg == WM_DIABTWARPUP) {
dx = abs(trigs[j].position.x - cursmx);
dy = abs(trigs[j].position.y - cursmy);
int dx = abs(trigs[j].position.x - cursmx);
int dy = abs(trigs[j].position.y - cursmy);
if (dx < 4 && dy < 4) {
strcpy(infostr, _("Up to town"));
cursmx = trigs[j].position.x;
@ -609,12 +592,12 @@ bool ForceL3Trig()
}
}
if (currlevel == 17) {
for (i = 0; L6TWarpUpList[i] != -1; i++) {
for (int i = 0; L6TWarpUpList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == L6TWarpUpList[i]) {
for (j = 0; j < numtrigs; j++) {
for (int j = 0; j < numtrigs; j++) {
if (trigs[j]._tmsg == WM_DIABTWARPUP) {
dx = abs(trigs[j].position.x - cursmx);
dy = abs(trigs[j].position.y - cursmy);
int dx = abs(trigs[j].position.x - cursmx);
int dy = abs(trigs[j].position.y - cursmy);
if (dx < 4 && dy < 4) {
strcpy(infostr, _("Up to town"));
cursmx = trigs[j].position.x;
@ -632,12 +615,10 @@ bool ForceL3Trig()
bool ForceL4Trig()
{
int i, j, dx, dy;
for (i = 0; L4UpList[i] != -1; ++i) {
for (int i = 0; L4UpList[i] != -1; ++i) {
if (dPiece[cursmx][cursmy] == L4UpList[i]) {
strcpy(infostr, fmt::format(_("Up to level {:d}"), currlevel - 1).c_str());
for (j = 0; j < numtrigs; j++) {
for (int j = 0; j < numtrigs; j++) {
if (trigs[j]._tmsg == WM_DIABPREVLVL) {
cursmx = trigs[j].position.x;
cursmy = trigs[j].position.y;
@ -647,10 +628,10 @@ bool ForceL4Trig()
}
}
for (i = 0; L4DownList[i] != -1; i++) {
for (int i = 0; L4DownList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == L4DownList[i]) {
strcpy(infostr, fmt::format(_("Down to level {:d}"), currlevel + 1).c_str());
for (j = 0; j < numtrigs; j++) {
for (int j = 0; j < numtrigs; j++) {
if (trigs[j]._tmsg == WM_DIABNEXTLVL) {
cursmx = trigs[j].position.x;
cursmy = trigs[j].position.y;
@ -661,12 +642,12 @@ bool ForceL4Trig()
}
if (currlevel == 13) {
for (i = 0; L4TWarpUpList[i] != -1; i++) {
for (int i = 0; L4TWarpUpList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == L4TWarpUpList[i]) {
for (j = 0; j < numtrigs; j++) {
for (int j = 0; j < numtrigs; j++) {
if (trigs[j]._tmsg == WM_DIABTWARPUP) {
dx = abs(trigs[j].position.x - cursmx);
dy = abs(trigs[j].position.y - cursmy);
int dx = abs(trigs[j].position.x - cursmx);
int dy = abs(trigs[j].position.y - cursmy);
if (dx < 4 && dy < 4) {
strcpy(infostr, _("Up to town"));
cursmx = trigs[j].position.x;
@ -680,10 +661,10 @@ bool ForceL4Trig()
}
if (currlevel == 15) {
for (i = 0; L4PentaList[i] != -1; i++) {
for (int i = 0; L4PentaList[i] != -1; i++) {
if (dPiece[cursmx][cursmy] == L4PentaList[i]) {
strcpy(infostr, _("Down to Diablo"));
for (j = 0; j < numtrigs; j++) {
for (int j = 0; j < numtrigs; j++) {
if (trigs[j]._tmsg == WM_DIABNEXTLVL) {
cursmx = trigs[j].position.x;
cursmy = trigs[j].position.y;
@ -699,14 +680,13 @@ bool ForceL4Trig()
void Freeupstairs()
{
int i, tx, ty, xx, yy;
for (i = 0; i < numtrigs; i++) {
tx = trigs[i].position.x;
ty = trigs[i].position.y;
for (int i = 0; i < numtrigs; i++) {
int tx = trigs[i].position.x;
int ty = trigs[i].position.y;
for (yy = -2; yy <= 2; yy++) {
for (xx = -2; xx <= 2; xx++) {
for (int yy = -2; yy <= 2; yy++) {
for (int xx = -2; xx <= 2; xx++) {
dFlags[tx + xx][ty + yy] |= BFLAG_POPULATED;
}
}

Loading…
Cancel
Save