From 56f04e19192e4852670cc5acc29a70487618b02e Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 17 Sep 2019 04:40:41 +0200 Subject: [PATCH 01/25] Update dthread.cpp --- Source/dthread.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/dthread.cpp b/Source/dthread.cpp index 396ce655c..2c268c25b 100644 --- a/Source/dthread.cpp +++ b/Source/dthread.cpp @@ -21,7 +21,7 @@ void dthread_remove_player(int pnum) #endif for (pkt = sgpInfoHead; pkt; pkt = pkt->pNext) { if (pkt->dwSpaceLeft == pnum) - pkt->dwSpaceLeft = 4; + pkt->dwSpaceLeft = MAX_PLRS; } #ifdef __cplusplus sgMemCrit.Leave(); @@ -106,7 +106,7 @@ unsigned int __stdcall dthread_handler(void *) #endif if (pkt) { - if (pkt->dwSpaceLeft != 4) + if (pkt->dwSpaceLeft != MAX_PLRS) multi_send_zero_packet(pkt->dwSpaceLeft, pkt->data[0], &pkt->data[8], *(DWORD *)&pkt->data[4]); dwMilliseconds = 1000 * *(DWORD *)&pkt->data[4] / gdwDeltaBytesSec; From 6a1ab27a1acd3f56af1f0993a5e38ced4b3534dd Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 17 Sep 2019 13:28:58 +0200 Subject: [PATCH 02/25] gmenu_clear_buffer cleanup --- Source/gmenu.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 9b3e7f3ab..d37a2943c 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -200,7 +200,8 @@ void gmenu_clear_buffer(int x, int y, int width, int height) { BYTE *i; - for (i = gpBuffer + PitchTbl[y] + x; height; height--) { + i = gpBuffer + PitchTbl[y] + x; + while (height--) { memset(i, 205, width); i -= BUFFER_WIDTH; } From 12435a9317c264d2fa86848c6b984bf66f02908c Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 17 Sep 2019 16:43:57 +0200 Subject: [PATCH 03/25] SetSpell cleanup --- Source/control.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/control.cpp b/Source/control.cpp index 3758e8ef7..b12b1bb30 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -504,9 +504,9 @@ void SetSpell() spselflag = 0; if (pSpell != -1) { ClearPanel(); - drawpanflag = 255; plr[myplr]._pRSpell = pSpell; plr[myplr]._pRSplType = pSplType; + drawpanflag = 255; } } From 13c957a445d8c252812eb5ee5711561d06754e77 Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 17 Sep 2019 18:17:03 +0200 Subject: [PATCH 04/25] Freeupstairs cleanup --- Source/trigs.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/trigs.cpp b/Source/trigs.cpp index c2e258c47..4597282c3 100644 --- a/Source/trigs.cpp +++ b/Source/trigs.cpp @@ -590,15 +590,15 @@ BOOL ForceL4Trig() void Freeupstairs() { - int i, yy, xx, tx, ty; + int i, tx, ty, yy, xx; for (i = 0; i < numtrigs; i++) { tx = trigs[i]._tx; ty = trigs[i]._ty; - for (yy = 0; yy < MAXTRIGGERS; yy++) { - for (xx = 0; xx < MAXTRIGGERS; xx++) { - dFlags[tx - 2 + xx][ty - 2 + yy] |= BFLAG_POPULATED; + for (yy = -2; yy <= 2; yy++) { + for (xx = -2; xx <= 2; xx++) { + dFlags[tx + xx][ty + yy] |= BFLAG_POPULATED; } } } From c629eb1e60b8830171477c4e1a3d78645f05cb80 Mon Sep 17 00:00:00 2001 From: qndel Date: Wed, 18 Sep 2019 00:51:49 +0200 Subject: [PATCH 05/25] codec_decode cleanup (#1661) --- Source/codec.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Source/codec.cpp b/Source/codec.cpp index 748fa2925..157c23141 100644 --- a/Source/codec.cpp +++ b/Source/codec.cpp @@ -34,20 +34,21 @@ int codec_decode(BYTE *pbSrcDst, DWORD size, char *pszPassword) memset(buf, 0, sizeof(buf)); sig = (CodecSignature *)pbSrcDst; if (sig->error > 0) { - size = 0; - SHA1Clear(); - } else { - SHA1Result(0, dst); - if (sig->checksum != *(DWORD *)dst) { - memset(dst, 0, sizeof(dst)); - size = 0; - SHA1Clear(); - } else { - size += sig->last_chunk_size - 64; - SHA1Clear(); - } + goto error; + } + + SHA1Result(0, dst); + if (sig->checksum != *(DWORD *)dst) { + memset(dst, 0, sizeof(dst)); + goto error; } + + size += sig->last_chunk_size - 64; + SHA1Clear(); return size; +error: + SHA1Clear(); + return 0; } void codec_init_key(int unused, char *pszPassword) From a593f3a1d2a6cce3c5a77499b482c353776b404d Mon Sep 17 00:00:00 2001 From: qndel Date: Tue, 17 Sep 2019 20:57:02 +0200 Subject: [PATCH 06/25] 6 functions cleanup --- Source/engine.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/engine.cpp b/Source/engine.cpp index a7173b2f3..35ae01520 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -164,9 +164,9 @@ void CelDecDatOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth) */ void CelDrawHdrOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { - int nDataStart, nDataSize, nDataCap; BYTE *pRLEBytes; DWORD *pFrameTable; + int nDataStart, nDataSize, nDataCap; /// ASSERT: assert(gpBuffer); if (!gpBuffer) @@ -205,9 +205,9 @@ void CelDrawHdrOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int Ce */ void CelDecodeHdrOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { - int nDataStart, nDataSize, nDataCap; BYTE *pRLEBytes; DWORD *pFrameTable; + int nDataStart, nDataSize, nDataCap; /// ASSERT: assert(pCelBuff != NULL); if (!pCelBuff) @@ -924,9 +924,9 @@ void Cel2DecDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) */ void Cel2DrawHdrOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { - int nDataStart, nDataSize, nDataCap; BYTE *pRLEBytes; DWORD *pFrameTable; + int nDataStart, nDataSize, nDataCap; /// ASSERT: assert(gpBuffer); if (!gpBuffer) @@ -965,9 +965,9 @@ void Cel2DrawHdrOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int C */ void Cel2DecodeHdrOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { - int nDataStart, nDataSize, nDataCap; BYTE *pRLEBytes; DWORD *pFrameTable; + int nDataStart, nDataSize, nDataCap; /// ASSERT: assert(pCelBuff != NULL); if (!pCelBuff) @@ -2480,9 +2480,9 @@ void Cl2ApplyTrans(BYTE *p, BYTE *ttbl, int nCel) */ void Cl2DecodeFrm1(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { - int nDataStart, nDataSize; BYTE *pRLEBytes; DWORD *pFrameTable; + int nDataStart, nDataSize; /// ASSERT: assert(gpBuffer != NULL); if (!gpBuffer) @@ -3112,9 +3112,9 @@ void Cl2DecodeLightTbl(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int */ void Cl2DecodeFrm4(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth, int CelSkip, int CelCap) { - int nDataStart, nDataSize; BYTE *pRLEBytes; DWORD *pFrameTable; + int nDataStart, nDataSize; /// ASSERT: assert(gpBuffer != NULL); if (!gpBuffer) From 0b7fca12afb93941a461fc63f67d3f4dba97cec4 Mon Sep 17 00:00:00 2001 From: Robin Eklind Date: Thu, 19 Sep 2019 01:53:29 +0200 Subject: [PATCH 07/25] multi: use sizeof(sgGameInitInfo) for initdatabytes --- Source/multi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/multi.cpp b/Source/multi.cpp index 113539136..543650360 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -690,7 +690,7 @@ BOOL NetInit(BOOL bSinglePlayer, BOOL *pfExitProgram) ProgramData.versionid = 42; ProgramData.maxplayers = MAX_PLRS; ProgramData.initdata = &sgGameInitInfo; - ProgramData.initdatabytes = 8; + ProgramData.initdatabytes = sizeof(sgGameInitInfo); ProgramData.optcategorybits = 15; ProgramData.lcid = 1033; /* LANG_ENGLISH */ memset(&plrdata, 0, sizeof(plrdata)); From 4940163d0e0842c74c0d8b4d384d95613b450992 Mon Sep 17 00:00:00 2001 From: qndel Date: Fri, 20 Sep 2019 04:26:21 +0200 Subject: [PATCH 08/25] AddTeleport cleanup --- Source/missiles.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 73c75e7b6..839a206fb 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -1372,12 +1372,12 @@ void AddTeleport(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy tx = dx + CrawlTable[pn - 1]; ty = dy + CrawlTable[pn]; if (0 < tx && tx < MAXDUNX && 0 < ty && ty < MAXDUNY) { - if (!(dMonster[tx][ty] | dObject[tx][ty] | dPlayer[tx][ty] | nSolidTable[dPiece[tx][ty]])) { - missile[mi]._miDelFlag = FALSE; + if (!(nSolidTable[dPiece[tx][ty]] | dMonster[tx][ty] | dObject[tx][ty] | dPlayer[tx][ty])) { missile[mi]._mix = tx; missile[mi]._miy = ty; missile[mi]._misx = tx; missile[mi]._misy = ty; + missile[mi]._miDelFlag = FALSE; i = 6; break; } From bba1ab1da9223c31c0fa6a80b785b812b5cec91e Mon Sep 17 00:00:00 2001 From: qndel Date: Fri, 20 Sep 2019 04:06:48 +0200 Subject: [PATCH 09/25] AddResurrectBeam cleanup --- Source/missiles.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 839a206fb..787b93fa8 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -2342,8 +2342,8 @@ void AddResurrectBeam(int mi, int sx, int sy, int dx, int dy, int midir, char mi { missile[mi]._mix = dx; missile[mi]._miy = dy; - missile[mi]._misx = dx; - missile[mi]._misy = dy; + missile[mi]._misx = missile[mi]._mix; + missile[mi]._misy = missile[mi]._miy; missile[mi]._mixvel = 0; missile[mi]._miyvel = 0; missile[mi]._mirange = misfiledata[36].mAnimLen[0]; From 880a5d6b7207b997c5f756a2a07c32acffcefb49 Mon Sep 17 00:00:00 2001 From: qndel Date: Fri, 20 Sep 2019 14:38:06 +0200 Subject: [PATCH 10/25] AddStone cleanup --- Source/missiles.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 787b93fa8..c0aa76a67 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -1924,10 +1924,9 @@ void AddStone(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, i } else { missile[mi]._mix = tx; missile[mi]._miy = ty; - missile[mi]._misx = tx; - missile[mi]._misy = ty; - missile[mi]._mirange = 6; - missile[mi]._mirange += missile[mi]._mispllvl; + missile[mi]._misx = missile[mi]._mix; + missile[mi]._misy = missile[mi]._miy; + missile[mi]._mirange = missile[mi]._mispllvl + 6; missile[mi]._mirange += (missile[mi]._mirange * plr[id]._pISplDur) >> 7; if (missile[mi]._mirange > 15) From 4b0ffef7813b8d9ff56a283b0c5b20d89ff5cccc Mon Sep 17 00:00:00 2001 From: qndel Date: Fri, 20 Sep 2019 14:42:34 +0200 Subject: [PATCH 11/25] AddRhino cleanup --- Source/missiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index c0aa76a67..7cf64f376 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -1777,8 +1777,8 @@ void AddRhino(int mi, int sx, int sy, int dx, int dy, int midir, char mienemy, i anim = &monster[id].MType->Anims[MA_SPECIAL]; } GetMissileVel(mi, sx, sy, dx, dy, 18); - missile[mi]._miAnimFlags = 0; missile[mi]._mimfnum = midir; + missile[mi]._miAnimFlags = 0; missile[mi]._miAnimData = anim->Data[midir]; missile[mi]._miAnimDelay = anim->Rate; missile[mi]._miAnimLen = anim->Frames; From 76eb0a3d68dd3a42a6b1b00f1e230b353446a634 Mon Sep 17 00:00:00 2001 From: qndel Date: Fri, 20 Sep 2019 16:00:34 +0200 Subject: [PATCH 12/25] MI_Firewall cleanup --- Source/missiles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 7cf64f376..77c68f24b 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -2799,8 +2799,8 @@ void MI_Firewall(int i) } if (missile[i]._mirange == missile[i]._miAnimLen - 1) { SetMissDir(i, 0); - missile[i]._miAnimAdd = -1; missile[i]._miAnimFrame = 13; + missile[i]._miAnimAdd = -1; } CheckMissileCol(i, missile[i]._midam, missile[i]._midam, 1, missile[i]._mix, missile[i]._miy, 1); if (!missile[i]._mirange) { From 32e519415a714e1c011048175c91c6146cc8e2b7 Mon Sep 17 00:00:00 2001 From: qndel Date: Sat, 21 Sep 2019 11:37:55 +0200 Subject: [PATCH 13/25] GetDirection cleanup --- Source/engine.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/engine.cpp b/Source/engine.cpp index 35ae01520..b5fd3d4d4 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -2301,12 +2301,13 @@ int GetDirection(int x1, int y1, int x2, int y2) if (2 * my < mx) return DIR_SE; } else { - ny = -mx; if (my >= 0) { + ny = -mx; md = DIR_W; if (2 * ny < my) md = DIR_SW; } else { + ny = -mx; my = -my; md = DIR_N; if (2 * ny < my) From d71e447a043b2a7fc9606b9c4c66a92ba552ad4d Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 24 Sep 2019 06:02:07 +0200 Subject: [PATCH 14/25] Improve build time Most Mac images at Travis are severely outdated each build spends about 5 minutes just to update the brew package list before it is able to install any packages. Switching to a known more recent image solves this situation for now. --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 871a5065d..962081ac8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,8 @@ language: cpp os: - linux - osx + +osx_image: xcode10.3 notifications: email: @@ -15,7 +17,6 @@ addons: homebrew: packages: - mingw-w64 - update: true env: - MAKE_BUILD=make From da78f547122e66b59ae1eea3c59a6ce1bec08e12 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 24 Sep 2019 19:06:54 +0200 Subject: [PATCH 15/25] Apply plr_class --- Source/towners.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/towners.cpp b/Source/towners.cpp index 7a6e4fc2d..968541e18 100644 --- a/Source/towners.cpp +++ b/Source/towners.cpp @@ -689,11 +689,11 @@ void TalkToTowner(int p, int t) towner[t]._tVar1 = p; quests[QTYPE_BUTCH]._qvar1 = 1; #ifndef SPAWN - if (plr[p]._pClass == 0 && !effect_is_playing(PS_WARR8)) { + if (plr[p]._pClass == PC_WARRIOR && !effect_is_playing(PS_WARR8)) { PlaySFX(PS_WARR8); - } else if (plr[p]._pClass == 1 && !effect_is_playing(PS_ROGUE8)) { + } else if (plr[p]._pClass == PC_ROGUE && !effect_is_playing(PS_ROGUE8)) { PlaySFX(PS_ROGUE8); - } else if (plr[p]._pClass == 2 && !effect_is_playing(PS_MAGE8)) { + } else if (plr[p]._pClass == PC_SORCERER && !effect_is_playing(PS_MAGE8)) { PlaySFX(PS_MAGE8); } #endif From ddec3ce5bb745cedc062c9a85889a88c6b598f64 Mon Sep 17 00:00:00 2001 From: qndel Date: Wed, 25 Sep 2019 19:40:10 +0200 Subject: [PATCH 16/25] PrintStoreItem cleanup --- Source/stores.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Source/stores.cpp b/Source/stores.cpp index 6c6a56f76..d9043f93d 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -449,6 +449,8 @@ void S_ScrollSBuy(int idx) void PrintStoreItem(ItemStruct *x, int l, char iclr) { char sstr[128]; + char str, dex; + BYTE mag; sstr[0] = '\0'; if (x->_iIdentified) { @@ -488,7 +490,10 @@ void PrintStoreItem(ItemStruct *x, int l, char iclr) } if (!x->_itype) sstr[0] = '\0'; - if (!(x->_iMinStr + x->_iMinMag + x->_iMinDex)) { + str = x->_iMinStr; + dex = x->_iMinDex; + mag = x->_iMinMag; + if (!(str + mag + dex)) { strcat(sstr, "No required attributes"); } else { strcpy(tempstr, "Required:"); @@ -500,10 +505,10 @@ void PrintStoreItem(ItemStruct *x, int l, char iclr) sprintf(tempstr, "%s %i Dex", tempstr, x->_iMinDex); strcat(sstr, tempstr); } - AddSText(40, l, 0, sstr, iclr, 0); + AddSText(40, l++, 0, sstr, iclr, 0); if (x->_iMagical == ITEM_QUALITY_UNIQUE) { if (x->_iIdentified) - AddSText(40, l + 1, 0, "Unique Item", iclr, 0); + AddSText(40, l, 0, "Unique Item", iclr, 0); } } From d3389f3f7cc1b44cbc97db9e5071da16bd415d27 Mon Sep 17 00:00:00 2001 From: qndel Date: Wed, 25 Sep 2019 18:54:54 +0200 Subject: [PATCH 17/25] DrawSLine cleanup --- Source/stores.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/stores.cpp b/Source/stores.cpp index d9043f93d..2bf8d1a99 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -195,16 +195,17 @@ void PrintSString(int x, int y, BOOL cjustflag, char *str, char col, int val) void DrawSLine(int y) { - int xy, yy, width, line; + int xy, yy, width, line, sy; + sy = SStringY[y]; if (stextsize == 1) { xy = SCREENXY(26, 25); - yy = PitchTbl[SStringY[y] + 198] + 26 + 64; + yy = PitchTbl[sy + 198] + 26 + 64; width = 586 / 4; line = BUFFER_WIDTH - 586; } else { xy = SCREENXY(346, 25); - yy = PitchTbl[SStringY[y] + 198] + 346 + 64; + yy = PitchTbl[sy + 198] + 346 + 64; width = 266 / 4; line = BUFFER_WIDTH - 266; } From 5253e285846586b0158ba7ed1d906de481aea9ec Mon Sep 17 00:00:00 2001 From: qndel Date: Wed, 25 Sep 2019 14:05:28 +0200 Subject: [PATCH 18/25] InitAutomap cleanup --- Source/automap.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Source/automap.cpp b/Source/automap.cpp index 432b8cc5f..de22aaf52 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -71,24 +71,21 @@ void InitAutomap() switch (leveltype) { case DTYPE_CATHEDRAL: pAFile = LoadFileInMem("Levels\\L1Data\\L1.AMP", &dwTiles); - dwTiles >>= 1; break; case DTYPE_CATACOMBS: pAFile = LoadFileInMem("Levels\\L2Data\\L2.AMP", &dwTiles); - dwTiles >>= 1; break; case DTYPE_CAVES: pAFile = LoadFileInMem("Levels\\L3Data\\L3.AMP", &dwTiles); - dwTiles >>= 1; break; case DTYPE_HELL: pAFile = LoadFileInMem("Levels\\L4Data\\L4.AMP", &dwTiles); - dwTiles >>= 1; break; default: return; } + dwTiles >>= 1; pTmp = pAFile; for (i = 1; i <= dwTiles; i++) { From d0421621c4a7095d640ae4c8cc6f136af5f5ca37 Mon Sep 17 00:00:00 2001 From: qndel Date: Wed, 25 Sep 2019 17:56:34 +0200 Subject: [PATCH 19/25] InitMonsterGFX cleanup --- Source/monster.cpp | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/Source/monster.cpp b/Source/monster.cpp index 807f9aa52..5e9c56da4 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -328,34 +328,22 @@ void InitMonsterGFX(int monst) MissileFileFlag |= 2; LoadMissileGFX(MFILE_THINLGHT); } - if (mtype == MT_SUCCUBUS) { - if (MissileFileFlag & 4) - return; - + if (mtype == MT_SUCCUBUS && !(MissileFileFlag & 4)) { MissileFileFlag |= 4; LoadMissileGFX(MFILE_FLARE); LoadMissileGFX(MFILE_FLAREEXP); } - if (mtype == MT_SNOWWICH) { - if (MissileFileFlag & 0x20) - return; - + if (mtype == MT_SNOWWICH && !(MissileFileFlag & 0x20)) { MissileFileFlag |= 0x20; LoadMissileGFX(MFILE_SCUBMISB); LoadMissileGFX(MFILE_SCBSEXPB); } - if (mtype == MT_HLSPWN) { - if (MissileFileFlag & 0x40) - return; - + if (mtype == MT_HLSPWN && !(MissileFileFlag & 0x40)) { MissileFileFlag |= 0x40; LoadMissileGFX(MFILE_SCUBMISD); LoadMissileGFX(MFILE_SCBSEXPD); } - if (mtype == MT_SOLBRNR) { - if (MissileFileFlag & 0x80) - return; - + if (mtype == MT_SOLBRNR && !(MissileFileFlag & 0x80)) { MissileFileFlag |= 0x80; LoadMissileGFX(MFILE_SCUBMISC); LoadMissileGFX(MFILE_SCBSEXPC); From 0704393bc3396f3d190da8f2c7ff879100058b4b Mon Sep 17 00:00:00 2001 From: qndel Date: Wed, 25 Sep 2019 19:18:38 +0200 Subject: [PATCH 20/25] StoreAutoPlace cleanup --- Source/stores.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/stores.cpp b/Source/stores.cpp index 2bf8d1a99..dc41200c6 100644 --- a/Source/stores.cpp +++ b/Source/stores.cpp @@ -327,9 +327,9 @@ void StoreAutoPlace() int i, w, h, idx; SetICursor(plr[myplr].HoldItem._iCurs + CURSOR_FIRSTITEM); - done = FALSE; w = icursW28; h = icursH28; + done = FALSE; if (w == 1 && h == 1) { idx = plr[myplr].HoldItem.IDidx; if (plr[myplr].HoldItem._iStatFlag && AllItemsList[idx].iUsable) { From 449b9fd2dc08c24fad11732886e980e8e42450d8 Mon Sep 17 00:00:00 2001 From: qndel Date: Fri, 27 Sep 2019 02:42:10 +0200 Subject: [PATCH 21/25] CastSpell cleanup --- Source/spells.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/spells.cpp b/Source/spells.cpp index 8bd5d983e..c9bde2a22 100644 --- a/Source/spells.cpp +++ b/Source/spells.cpp @@ -138,7 +138,7 @@ void CastSpell(int id, int spl, int sx, int sy, int dx, int dy, int caster, int if (spelldata[spl].sMissiles[0] == MIS_CBOLT) { UseMana(id, SPL_CBOLT); - for (i = 0; i < (spllvl >> 1) + 3; i++) { + for (i = (spllvl >> 1) + 3; i > 0; i--) { AddMissile(sx, sy, dx, dy, dir, MIS_CBOLT, caster, id, 0, spllvl); } } From 1516ad57acaa06a738a21b3e7d1ce26c3035b403 Mon Sep 17 00:00:00 2001 From: qndel Date: Fri, 27 Sep 2019 03:16:26 +0200 Subject: [PATCH 22/25] GetManaAmount cleanup (#1737) --- Source/spells.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Source/spells.cpp b/Source/spells.cpp index c9bde2a22..bedadaaf8 100644 --- a/Source/spells.cpp +++ b/Source/spells.cpp @@ -2,7 +2,6 @@ int GetManaAmount(int id, int sn) { - int i; // "raw" mana cost int ma; // mana amount // mana adjust @@ -26,12 +25,12 @@ int GetManaAmount(int id, int sn) } if (spelldata[sn].sManaCost == 255) { - i = (BYTE)plr[id]._pMaxManaBase; + ma = ((BYTE)plr[id]._pMaxManaBase - adj); } else { - i = spelldata[sn].sManaCost; + ma = (spelldata[sn].sManaCost - adj); } - ma = (i - adj) << 6; + ma <<= 6; if (sn == SPL_HEAL) { ma = (spelldata[SPL_HEAL].sManaCost + 2 * plr[id]._pLevel - adj) << 6; From ea5c8bd23aab9fea785196803cc10c3c94145934 Mon Sep 17 00:00:00 2001 From: qndel Date: Fri, 27 Sep 2019 15:23:28 +0200 Subject: [PATCH 23/25] SpecialThemeFit cleanup --- Source/themes.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Source/themes.cpp b/Source/themes.cpp index b3f04db77..cbc333d6b 100644 --- a/Source/themes.cpp +++ b/Source/themes.cpp @@ -283,41 +283,41 @@ BOOL SpecialThemeFit(int i, int t) case THEME_BLOODFOUNTAIN: if (rv) { rv = TFit_Obj5(i); - if (rv) { - bFountainFlag = FALSE; - } + } + if (rv) { + bFountainFlag = FALSE; } break; case THEME_PURIFYINGFOUNTAIN: if (rv) { rv = TFit_Obj5(i); - if (rv) { - pFountainFlag = FALSE; - } + } + if (rv) { + pFountainFlag = FALSE; } break; case THEME_MURKYFOUNTAIN: if (rv) { rv = TFit_Obj5(i); - if (rv) { - mFountainFlag = FALSE; - } + } + if (rv) { + mFountainFlag = FALSE; } break; case THEME_TEARFOUNTAIN: if (rv) { rv = TFit_Obj5(i); - if (rv) { - tFountainFlag = FALSE; - } + } + if (rv) { + tFountainFlag = FALSE; } break; case THEME_CAULDRON: if (rv) { rv = TFit_Obj5(i); - if (rv) { - cauldronFlag = FALSE; - } + } + if (rv) { + cauldronFlag = FALSE; } break; case THEME_GOATSHRINE: @@ -336,7 +336,7 @@ BOOL SpecialThemeFit(int i, int t) break; case THEME_TREASURE: rv = treasureFlag; - if (treasureFlag) { + if (rv) { treasureFlag = FALSE; } break; From ce6fc51b5025733f3990d7f6f23cffd249dacb2a Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Fri, 27 Sep 2019 20:05:45 +0200 Subject: [PATCH 24/25] Implement CelGetFrame (CEL decoder helper) This implements the first of the inlined CEL decoder helper functions that are still visable in the Mac port code. Functions are still bin exact --- Source/control.cpp | 8 +++----- Source/engine.cpp | 50 ++++++++++++++++++++++------------------------ Source/engine.h | 2 ++ defs.h | 12 +++++++++++ 4 files changed, 41 insertions(+), 31 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index b12b1bb30..71abe9b09 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -726,14 +726,12 @@ void CPrintString(int nOffset, int nCel, char col) labret: } #else - int i; + int i, nDataSize; BYTE width, pix; BYTE *src, *dst, *end; - DWORD *pFrameTable; - pFrameTable = (DWORD *)&pPanelText[4 * nCel]; - src = &pPanelText[pFrameTable[0]]; - end = &src[pFrameTable[1] - pFrameTable[0]]; + src = CelGetFrame(pPanelText, nCel, &nDataSize); + end = &src[nDataSize]; dst = &gpBuffer[nOffset]; switch (col) { diff --git a/Source/engine.cpp b/Source/engine.cpp index b5fd3d4d4..f795b27fe 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -19,6 +19,18 @@ BOOL gbNotInView; // valid - if x/y are in bounds const int RndInc = 1; const int RndMult = 0x015A4E35; +__FINLINE BYTE *CelGetFrame(BYTE *pCelBuff, int nCel, int *nDataSize) +{ + DWORD *pFrameTable; + DWORD nCellStart; + + pFrameTable = (DWORD *)pCelBuff; + nCellStart = SwapLE32(pFrameTable[nCel]); + *nDataSize = SwapLE32(pFrameTable[nCel + 1]) - nCellStart; + + return pCelBuff + nCellStart; +} + void CelDrawDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) { int w; @@ -120,7 +132,8 @@ void CelDrawDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) void CelDecodeOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth) { - DWORD *pFrameTable; + int nDataSize; + BYTE *pRLEBytes; /// ASSERT: assert(gpBuffer); if (!gpBuffer) @@ -129,18 +142,14 @@ void CelDecodeOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth) if (!pCelBuff) return; - pFrameTable = (DWORD *)pCelBuff; - - CelDrawDatOnly( - &gpBuffer[sx + PitchTbl[sy]], - &pCelBuff[pFrameTable[nCel]], - pFrameTable[nCel + 1] - pFrameTable[nCel], - nWidth); + pRLEBytes = CelGetFrame(pCelBuff, nCel, &nDataSize); + CelDrawDatOnly(&gpBuffer[sx + PitchTbl[sy]], pRLEBytes, nDataSize, nWidth); } void CelDecDatOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth) { - DWORD *pFrameTable; + int nDataSize; + BYTE *pRLEBytes; /// ASSERT: assert(pCelBuff != NULL); if (!pCelBuff) @@ -149,13 +158,8 @@ void CelDecDatOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth) if (!pBuff) return; - pFrameTable = (DWORD *)pCelBuff; - - CelDrawDatOnly( - pBuff, - &pCelBuff[pFrameTable[nCel]], - pFrameTable[nCel + 1] - pFrameTable[nCel], - nWidth); + pRLEBytes = CelGetFrame(pCelBuff, nCel, &nDataSize); + CelDrawDatOnly(pBuff, pRLEBytes, nDataSize, nWidth); } /** @@ -580,7 +584,6 @@ void CelDecodeLightOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth) { int nDataSize; BYTE *pDecodeTo, *pRLEBytes; - DWORD *pFrameTable; /// ASSERT: assert(gpBuffer); if (!gpBuffer) @@ -589,10 +592,7 @@ void CelDecodeLightOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth) if (!pCelBuff) return; - pFrameTable = (DWORD *)pCelBuff; - - nDataSize = pFrameTable[nCel + 1] - pFrameTable[nCel]; - pRLEBytes = &pCelBuff[pFrameTable[nCel]]; + pRLEBytes = CelGetFrame(pCelBuff, nCel, &nDataSize); pDecodeTo = &gpBuffer[sx + PitchTbl[sy]]; if (light_table_index) @@ -1643,13 +1643,11 @@ void CelDecodeRect(BYTE *pBuff, int CelSkip, int hgt, int wdt, BYTE *pCelBuff, i jnz label1 } #else - int i; + int i, nDataSize; BYTE width; - DWORD *pFrameTable; - pFrameTable = (DWORD *)&pCelBuff[4 * nCel]; - pRLEBytes = &pCelBuff[pFrameTable[0]]; - end = &pRLEBytes[pFrameTable[1] - pFrameTable[0]]; + pRLEBytes = CelGetFrame(pCelBuff, nCel, &nDataSize); + end = &pRLEBytes[nDataSize]; dst = &pBuff[hgt * wdt + CelSkip]; for (; pRLEBytes != end; dst -= wdt + nWidth) { diff --git a/Source/engine.h b/Source/engine.h index 051e8f97d..234ccb317 100644 --- a/Source/engine.h +++ b/Source/engine.h @@ -11,6 +11,8 @@ extern int orgseed; extern int SeedCount; extern BOOL gbNotInView; // valid - if x/y are in bounds +__FINLINE BYTE *CelGetFrame(BYTE *pCelBuff, int nCel, int *nDataSize); + void CelDrawDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth); void CelDecodeOnly(int sx, int sy, BYTE *pCelBuff, int nCel, int nWidth); void CelDecDatOnly(BYTE *pBuff, BYTE *pCelBuff, int nCel, int nWidth); diff --git a/defs.h b/defs.h index b7623b95d..a5a407552 100644 --- a/defs.h +++ b/defs.h @@ -173,3 +173,15 @@ typedef void (*_PVFV)(void); #else #define ALIGN_BY_1 #endif + +#if (_MSC_VER == 1200) +#define __FINLINE __forceinline +#else +#define __FINLINE +#endif + +#ifndef _BIG_ENDIAN_ +#define SwapLE32 +#else +#define SwapLE32(value) (value << 24 | (value & 0xFF00) << 8 | (value & 0xFF0000) >> 8 | value >> 24); +#endif From 6dd0893bce7d75c6c126d4c3739a97b493e175cc Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 28 Sep 2019 00:10:41 +0200 Subject: [PATCH 25/25] Implement CelGetFrameSize --- Source/engine.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Source/engine.cpp b/Source/engine.cpp index f795b27fe..eb883845a 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -31,6 +31,15 @@ __FINLINE BYTE *CelGetFrame(BYTE *pCelBuff, int nCel, int *nDataSize) return pCelBuff + nCellStart; } +__FINLINE int CelGetFrameSize(BYTE *pCelBuff, int nCel) +{ + DWORD *pFrameTable; + + pFrameTable = (DWORD *)pCelBuff; + + return SwapLE32(pFrameTable[nCel + 1]) - SwapLE32(pFrameTable[nCel]); +} + void CelDrawDatOnly(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nWidth) { int w; @@ -2447,7 +2456,7 @@ void Cl2ApplyTrans(BYTE *p, BYTE *ttbl, int nCel) for (i = 1; i <= nCel; i++) { pFrameTable = (DWORD *)&p[4 * i]; dst = &p[pFrameTable[0] + 10]; - nDataSize = pFrameTable[1] - pFrameTable[0] - 10; + nDataSize = CelGetFrameSize(p, i) - 10; while (nDataSize) { width = *dst++; nDataSize--;