From e62aaa562f12e50db62ee288c6c15c5d3aa9febf Mon Sep 17 00:00:00 2001 From: obligaron Date: Sat, 11 Sep 2021 22:54:57 +0200 Subject: [PATCH] Fix missiles don't hit horizontal walking players/monsters --- Source/monster.cpp | 3 ++- Source/player.cpp | 3 ++- Source/scrollrt.cpp | 22 +++++----------------- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/Source/monster.cpp b/Source/monster.cpp index 5c6e5f2ac..5b4c10650 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -973,7 +973,7 @@ void StartWalk3(int i, int xvel, int yvel, int xoff, int yoff, int xadd, int yad ChangeLightXY(monster.mlid, { x, y }); dMonster[monster.position.tile.x][monster.position.tile.y] = -(i + 1); - dMonster[fx][fy] = -(i + 1); + dMonster[fx][fy] = i + 1; monster.position.temp = { x, y }; dFlags[x][y] |= BFLAG_MONSTLR; monster.position.old = monster.position.tile; @@ -1357,6 +1357,7 @@ bool MonsterWalk(int i, MonsterMode variant) dMonster[monster.position.tile.x][monster.position.tile.y] = 0; monster.position.tile = { monster._mVar1, monster._mVar2 }; dFlags[monster.position.temp.x][monster.position.temp.y] &= ~BFLAG_MONSTLR; + // dMonster is set here for backwards comparability, without it the monster would be invisible if loaded from a vanilla save. dMonster[monster.position.tile.x][monster.position.tile.y] = i + 1; break; default: diff --git a/Source/player.cpp b/Source/player.cpp index fb5510a18..64742bba4 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -269,7 +269,7 @@ void WalkSides(int pnum, const DirectionSettings &walkParams) Point const nextPosition = player.position.tile + walkParams.map; dPlayer[player.position.tile.x][player.position.tile.y] = -(pnum + 1); - dPlayer[player.position.future.x][player.position.future.y] = -(pnum + 1); + dPlayer[player.position.future.x][player.position.future.y] = pnum + 1; player._pVar4 = nextPosition.x; player._pVar5 = nextPosition.y; dFlags[nextPosition.x][nextPosition.y] |= BFLAG_PLAYERLR; @@ -732,6 +732,7 @@ bool DoWalk(int pnum, int variant) dPlayer[player.position.tile.x][player.position.tile.y] = 0; dFlags[player._pVar4][player._pVar5] &= ~BFLAG_PLAYERLR; player.position.tile = player.position.temp; + // dPlayer is set here for backwards comparability, without it the player would be invisible if loaded from a vanilla save. dPlayer[player.position.tile.x][player.position.tile.y] = pnum + 1; break; } diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 61d09f4be..a662c2998 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -731,12 +731,11 @@ void DrawItem(const Surface &out, Point tilePosition, Point targetBufferPosition * @brief Check if and how a monster should be rendered * @param out Output buffer * @param tilePosition dPiece coordinates - * @param oy dPiece Y offset * @param targetBufferPosition Output buffer coordinates */ -void DrawMonsterHelper(const Surface &out, Point tilePosition, int oy, Point targetBufferPosition) +void DrawMonsterHelper(const Surface &out, Point tilePosition, Point targetBufferPosition) { - int mi = dMonster[tilePosition.x][tilePosition.y + oy]; + int mi = dMonster[tilePosition.x][tilePosition.y]; mi = mi > 0 ? mi - 1 : -(mi + 1); if (leveltype == DTYPE_TOWN) { @@ -834,10 +833,6 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit int8_t bDead = dCorpse[tilePosition.x][tilePosition.y]; int8_t bMap = dTransVal[tilePosition.x][tilePosition.y]; - int negMon = 0; - if (tilePosition.y > 0) // check for OOB - negMon = dMonster[tilePosition.x][tilePosition.y - 1]; - #ifdef _DEBUG if (DebugVision && (bFlag & BFLAG_LIT) != 0) { CelClippedDrawTo(out, targetBufferPosition, *pSquareCel, 1); @@ -871,14 +866,7 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit } DrawObject(out, tilePosition, targetBufferPosition, true); DrawItem(out, tilePosition, targetBufferPosition, true); - if ((bFlag & BFLAG_PLAYERLR) != 0) { - int syy = tilePosition.y - 1; - assert(syy >= 0 && syy < MAXDUNY); - DrawPlayerHelper(out, { tilePosition.x, syy }, targetBufferPosition); - } - if ((bFlag & BFLAG_MONSTLR) != 0 && negMon < 0) { - DrawMonsterHelper(out, tilePosition, -1, targetBufferPosition); - } + if ((bFlag & BFLAG_DEAD_PLAYER) != 0) { DrawDeadPlayer(out, tilePosition, targetBufferPosition); } @@ -886,7 +874,7 @@ void DrawDungeon(const Surface &out, Point tilePosition, Point targetBufferPosit DrawPlayerHelper(out, tilePosition, targetBufferPosition); } if (dMonster[tilePosition.x][tilePosition.y] > 0) { - DrawMonsterHelper(out, tilePosition, 0, targetBufferPosition); + DrawMonsterHelper(out, tilePosition, targetBufferPosition); } DrawMissile(out, tilePosition, targetBufferPosition, false); DrawObject(out, tilePosition, targetBufferPosition, false); @@ -1407,7 +1395,7 @@ Displacement GetOffsetForWalking(const AnimationInfo &animationInfo, const Direc { // clang-format off // South, SouthWest, West, NorthWest, North, NorthEast, East, SouthEast, - constexpr Displacement StartOffset[8] = { { 0, -32 }, { 32, -16 }, { 32, -16 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { -32, -16 }, { -32, -16 } }; + constexpr Displacement StartOffset[8] = { { 0, -32 }, { 32, -16 }, { 64, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { -64, 0 }, { -32, -16 } }; constexpr Displacement MovingOffset[8] = { { 0, 32 }, { -32, 16 }, { -64, 0 }, { -32, -16 }, { 0, -32 }, { 32, -16 }, { 64, 0 }, { 32, 16 } }; // clang-format on