From 239a43cc1c6bb720aba80027daa400bc31ff2abd Mon Sep 17 00:00:00 2001 From: obligaron Date: Sun, 25 Apr 2021 13:32:33 +0200 Subject: [PATCH] Remove "AnimWidth2" expect for missiles (#1680) --- Source/dead.cpp | 4 ---- Source/dead.h | 1 - Source/engine.cpp | 5 +++++ Source/engine.h | 7 +++++++ Source/items.cpp | 2 -- Source/items.h | 1 - Source/loadsave.cpp | 18 ++++++++++++------ Source/missiles.cpp | 4 ++-- Source/monster.cpp | 1 - Source/monster.h | 1 - Source/objects.cpp | 2 -- Source/objects.h | 1 - Source/player.cpp | 1 - Source/player.h | 1 - Source/scrollrt.cpp | 18 +++++++++--------- Source/towners.cpp | 1 - Source/towners.h | 1 - test/writehero_test.cpp | 1 - 18 files changed, 35 insertions(+), 35 deletions(-) diff --git a/Source/dead.cpp b/Source/dead.cpp index 97ae5c5b8..865459826 100644 --- a/Source/dead.cpp +++ b/Source/dead.cpp @@ -30,7 +30,6 @@ void InitDead() dead[nd]._deadData[d] = Monsters[i].Anims[MA_DEATH].Data[d]; dead[nd]._deadFrame = Monsters[i].Anims[MA_DEATH].Frames; dead[nd]._deadWidth = Monsters[i].width; - dead[nd]._deadWidth2 = Monsters[i].width2; dead[nd]._deadtrans = 0; nd++; @@ -43,7 +42,6 @@ void InitDead() d = misfiledata[MFILE_BLODBUR].mAnimData[0]; dead[nd]._deadFrame = 8; dead[nd]._deadWidth = 128; - dead[nd]._deadWidth2 = 32; dead[nd]._deadtrans = 0; nd++; @@ -52,7 +50,6 @@ void InitDead() dead[nd]._deadFrame = 12; dead[nd]._deadWidth = 128; - dead[nd]._deadWidth2 = 32; dead[nd]._deadtrans = 0; nd++; @@ -65,7 +62,6 @@ void InitDead() dead[nd]._deadData[d] = monster[mi].MType->Anims[MA_DEATH].Data[d]; dead[nd]._deadFrame = monster[mi].MType->Anims[MA_DEATH].Frames; dead[nd]._deadWidth = monster[mi].MType->width; - dead[nd]._deadWidth2 = monster[mi].MType->width2; dead[nd]._deadtrans = monster[mi]._uniqtrans + 4; nd++; diff --git a/Source/dead.h b/Source/dead.h index d01f3b20d..3a2aef08b 100644 --- a/Source/dead.h +++ b/Source/dead.h @@ -17,7 +17,6 @@ struct DeadStruct { uint8_t *_deadData[8]; int _deadFrame; int _deadWidth; - int _deadWidth2; uint8_t _deadtrans; }; diff --git a/Source/engine.cpp b/Source/engine.cpp index 91d1cc9dd..999cece30 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -579,6 +579,11 @@ direction GetDirection(Point start, Point destination) return md; } +int CalculateWidth2(int width) +{ + return (width - 64) / 2; +} + /** * @brief Set the RNG seed * @param s RNG seed diff --git a/Source/engine.h b/Source/engine.h index 1a66062b9..13447c636 100644 --- a/Source/engine.h +++ b/Source/engine.h @@ -482,6 +482,13 @@ void DrawHalfTransparentRectTo(const CelOutputBuffer &out, int sx, int sy, int w */ direction GetDirection(Point start, Point destination); +/** + * @brief Calculate Width2 from the orginal Width + * Width2 is needed for savegame compatiblity and to render animations centered + * @return Returns Width2 + */ +int CalculateWidth2(int width); + void SetRndSeed(int32_t s); int32_t AdvanceRndSeed(); int32_t GetRndSeed(); diff --git a/Source/items.cpp b/Source/items.cpp index 523bd37ce..9ef90b46c 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -2256,7 +2256,6 @@ void SetupItem(int i) items[i]._iAnimData = itemanims[it]; items[i]._iAnimLen = ItemAnimLs[it]; items[i]._iAnimWidth = 96; - items[i]._iAnimWidth2 = 16; items[i]._iIdentified = false; items[i]._iPostDraw = false; @@ -2967,7 +2966,6 @@ void RespawnItem(ItemStruct *item, bool FlipFlag) item->_iAnimData = itemanims[it]; item->_iAnimLen = ItemAnimLs[it]; item->_iAnimWidth = 96; - item->_iAnimWidth2 = 16; item->_iPostDraw = false; item->_iRequest = false; if (FlipFlag) { diff --git a/Source/items.h b/Source/items.h index 2a14b5337..9871cb99a 100644 --- a/Source/items.h +++ b/Source/items.h @@ -172,7 +172,6 @@ struct ItemStruct { uint8_t _iAnimLen; // Number of frames in current animation uint8_t _iAnimFrame; // Current frame of animation. int _iAnimWidth; - int _iAnimWidth2; // width 2? bool _iDelFlag; // set when item is flagged for deletion, deprecated in 1.02 uint8_t _iSelFlag; bool _iPostDraw; diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index b28405156..a9f212bd9 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -226,7 +226,8 @@ static void LoadItemData(LoadHelper *file, ItemStruct *pItem) pItem->_iAnimLen = file->nextLE(); pItem->_iAnimFrame = file->nextLE(); pItem->_iAnimWidth = file->nextLE(); - pItem->_iAnimWidth2 = file->nextLE(); + // Skip _iAnimWidth2 + file->skip(4); file->skip(4); // Unused since 1.02 pItem->_iSelFlag = file->nextLE(); file->skip(3); // Alignment @@ -346,7 +347,8 @@ static void LoadPlayer(LoadHelper *file, int p) pPlayer->_pAnimLen = file->nextLE(); pPlayer->_pAnimFrame = file->nextLE(); pPlayer->_pAnimWidth = file->nextLE(); - pPlayer->_pAnimWidth2 = file->nextLE(); + // Skip _pAnimWidth2 + file->skip(4); file->skip(4); // Skip _peflag pPlayer->_plid = file->nextLE(); pPlayer->_pvid = file->nextLE(); @@ -703,7 +705,8 @@ static void LoadObject(LoadHelper *file, int i) pObject->_oAnimLen = file->nextLE(); pObject->_oAnimFrame = file->nextLE(); pObject->_oAnimWidth = file->nextLE(); - pObject->_oAnimWidth2 = file->nextLE(); + // Skip _oAnimWidth2 + file->skip(4); pObject->_oDelFlag = file->nextBool32(); pObject->_oBreak = file->nextLE(); file->skip(3); // Alignment @@ -1211,7 +1214,8 @@ static void SaveItem(SaveHelper *file, ItemStruct *pItem) file->writeLE(pItem->_iAnimLen); file->writeLE(pItem->_iAnimFrame); file->writeLE(pItem->_iAnimWidth); - file->writeLE(pItem->_iAnimWidth2); + // write _iAnimWidth2 for vanilla compatibility + file->writeLE(CalculateWidth2(pItem->_iAnimWidth)); file->skip(4); // Unused since 1.02 file->writeLE(pItem->_iSelFlag); file->skip(3); // Alignment @@ -1327,7 +1331,8 @@ static void SavePlayer(SaveHelper *file, int p) file->writeLE(pPlayer->_pAnimLen); file->writeLE(pPlayer->_pAnimFrame); file->writeLE(pPlayer->_pAnimWidth); - file->writeLE(pPlayer->_pAnimWidth2); + // write _pAnimWidth2 for vanilla compatibility + file->writeLE(CalculateWidth2(pPlayer->_pAnimWidth)); file->skip(4); // Skip _peflag file->writeLE(pPlayer->_plid); file->writeLE(pPlayer->_pvid); @@ -1662,7 +1667,8 @@ static void SaveObject(SaveHelper *file, int i) file->writeLE(pObject->_oAnimLen); file->writeLE(pObject->_oAnimFrame); file->writeLE(pObject->_oAnimWidth); - file->writeLE(pObject->_oAnimWidth2); + file->writeLE(pObject->_oAnimWidth); + // Write _oAnimWidth2 for vanilla compatibility file->writeLE(pObject->_oDelFlag); file->writeLE(pObject->_oBreak); file->skip(3); // Alignment diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 7748d0df9..058dfeae2 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -2513,7 +2513,7 @@ void AddRhino(int mi, int sx, int sy, int dx, int dy, int midir, int8_t mienemy, missile[mi]._miAnimDelay = anim->Rate; missile[mi]._miAnimLen = anim->Frames; missile[mi]._miAnimWidth = monster[id].MType->width; - missile[mi]._miAnimWidth2 = monster[id].MType->width2; + missile[mi]._miAnimWidth2 = CalculateWidth2(monster[id].MType->width); missile[mi]._miAnimAdd = 1; if (monster[id].MType->mtype >= MT_NSNAKE && monster[id].MType->mtype <= MT_GSNAKE) missile[mi]._miAnimFrame = 7; @@ -2541,7 +2541,7 @@ void AddFireman(int mi, int sx, int sy, int dx, int dy, int midir, int8_t mienem missile[mi]._miAnimDelay = anim->Rate; missile[mi]._miAnimLen = anim->Frames; missile[mi]._miAnimWidth = monster[id].MType->width; - missile[mi]._miAnimWidth2 = monster[id].MType->width2; + missile[mi]._miAnimWidth2 = CalculateWidth2(monster[id].MType->width); missile[mi]._miAnimAdd = 1; missile[mi]._miVar1 = 0; missile[mi]._miVar2 = 0; diff --git a/Source/monster.cpp b/Source/monster.cpp index feda20d01..4be72f1f0 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -369,7 +369,6 @@ void InitMonsterGFX(int monst) } Monsters[monst].width = monsterdata[mtype].width; - Monsters[monst].width2 = (monsterdata[mtype].width - 64) / 2; Monsters[monst].mMinHP = monsterdata[mtype].mMinHP; Monsters[monst].mMaxHP = monsterdata[mtype].mMaxHP; if (!gbIsHellfire && mtype == MT_DIABLO) { diff --git a/Source/monster.h b/Source/monster.h index 019b38787..2509bd90f 100644 --- a/Source/monster.h +++ b/Source/monster.h @@ -118,7 +118,6 @@ struct CMonster { AnimStruct Anims[6]; TSnd *Snds[4][2]; int width; - int width2; uint16_t mMinHP; uint16_t mMaxHP; bool has_special; diff --git a/Source/objects.cpp b/Source/objects.cpp index b812af733..f0213c264 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -1683,7 +1683,6 @@ void objects_44D8C5(_object_id ot, int v2, int ox, int oy) dObject[ox][oy] = oi + 1; SetupObject(oi, ox, oy, ot); objects_44DA68(oi, v2); - object[oi]._oAnimWidth2 = (object[oi]._oAnimWidth - 64) / 2; nobjects++; } @@ -1903,7 +1902,6 @@ void AddObject(_object_id ot, int ox, int oy) default: break; } - object[oi]._oAnimWidth2 = (object[oi]._oAnimWidth - 64) / 2; nobjects++; } diff --git a/Source/objects.h b/Source/objects.h index 2988e7818..91e7a3c04 100644 --- a/Source/objects.h +++ b/Source/objects.h @@ -26,7 +26,6 @@ struct ObjectStruct { int _oAnimLen; // Number of frames in current animation int _oAnimFrame; // Current frame of animation. int _oAnimWidth; - int _oAnimWidth2; bool _oDelFlag; int8_t _oBreak; bool _oSolidFlag; diff --git a/Source/player.cpp b/Source/player.cpp index 3a4acd862..1bdc89f30 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -558,7 +558,6 @@ void NewPlrAnim(int pnum, BYTE *Peq, int numFrames, int Delay, int width, Animat plr[pnum]._pAnimCnt = 0; plr[pnum]._pAnimDelay = Delay; plr[pnum]._pAnimWidth = width; - plr[pnum]._pAnimWidth2 = (width - 64) / 2; plr[pnum]._pAnimGameTicksSinceSequenceStarted = 0; plr[pnum]._pAnimRelevantAnimationFramesForDistributing = 0; plr[pnum]._pAnimGameTickModifier = 0.0f; diff --git a/Source/player.h b/Source/player.h index d962be96d..afabcdb5b 100644 --- a/Source/player.h +++ b/Source/player.h @@ -166,7 +166,6 @@ struct PlayerStruct { int _pAnimLen; // Number of frames in current animation int _pAnimFrame; // Current frame of animation. int _pAnimWidth; - int _pAnimWidth2; /* * @brief Specifies how many animations-fractions are displayed between two gameticks. this can be > 0, if animations are skipped or < 0 if the same animation is shown in multiple times (delay specified). */ diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 0a84fa330..3913a52e6 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -378,7 +378,7 @@ static void DrawManaShield(const CelOutputBuffer &out, int pnum, int x, int y, b if (!plr[pnum].pManaShield) return; - x += plr[pnum]._pAnimWidth2 - misfiledata[MFILE_MANASHLD].mAnimWidth2[0]; + x += CalculateWidth2(plr[pnum]._pAnimWidth) - misfiledata[MFILE_MANASHLD].mAnimWidth2[0]; int width = misfiledata[MFILE_MANASHLD].mAnimWidth[0]; BYTE *pCelBuff = misfiledata[MFILE_MANASHLD].mAnimData[0]; @@ -487,7 +487,7 @@ void DrawDeadPlayer(const CelOutputBuffer &out, int x, int y, int sx, int sy) p = &plr[i]; if (p->plractive && p->_pHitPoints == 0 && p->plrlevel == (BYTE)currlevel && p->position.tile.x == x && p->position.tile.y == y) { dFlags[x][y] |= BFLAG_DEAD_PLAYER; - px = sx + p->position.offset.x - p->_pAnimWidth2; + px = sx + p->position.offset.x - CalculateWidth2(p->_pAnimWidth); py = sy + p->position.offset.y; DrawPlayer(out, i, x, y, px, py); } @@ -514,7 +514,7 @@ static void DrawObject(const CelOutputBuffer &out, int x, int y, int ox, int oy, bv = dObject[x][y] - 1; if (object[bv]._oPreFlag != pre) return; - sx = ox - object[bv]._oAnimWidth2; + sx = ox - CalculateWidth2(object[bv]._oAnimWidth); sy = oy; } else { bv = -(dObject[x][y] + 1); @@ -522,7 +522,7 @@ static void DrawObject(const CelOutputBuffer &out, int x, int y, int ox, int oy, return; int xx = object[bv].position.x - x; int yy = object[bv].position.y - y; - sx = (xx * TILE_WIDTH / 2) + ox - object[bv]._oAnimWidth2 - (yy * TILE_WIDTH / 2); + sx = (xx * TILE_WIDTH / 2) + ox - CalculateWidth2(object[bv]._oAnimWidth) - (yy * TILE_WIDTH / 2); sy = oy + (yy * TILE_HEIGHT / 2) + (xx * TILE_HEIGHT / 2); } @@ -640,7 +640,7 @@ static void DrawItem(const CelOutputBuffer &out, int x, int y, int sx, int sy, b return; } - int px = sx - pItem->_iAnimWidth2; + int px = sx - CalculateWidth2(pItem->_iAnimWidth); if (bItem - 1 == pcursitem || AutoMapShowItems) { CelBlitOutlineTo(out, GetOutlineColor(*pItem, false), px, sy, pCelBuff, nCel, pItem->_iAnimWidth); } @@ -665,7 +665,7 @@ static void DrawMonsterHelper(const CelOutputBuffer &out, int x, int y, int oy, mi = mi > 0 ? mi - 1 : -(mi + 1); if (leveltype == DTYPE_TOWN) { - px = sx - towners[mi]._tAnimWidth2; + px = sx - CalculateWidth2(towners[mi]._tAnimWidth); if (mi == pcursmonst) { CelBlitOutlineTo(out, 166, px, sy, towners[mi]._tAnimData, towners[mi]._tAnimFrame, towners[mi]._tAnimWidth); } @@ -692,7 +692,7 @@ static void DrawMonsterHelper(const CelOutputBuffer &out, int x, int y, int oy, return; } - px = sx + pMonster->position.offset.x - pMonster->MType->width2; + px = sx + pMonster->position.offset.x - CalculateWidth2(pMonster->MType->width); py = sy + pMonster->position.offset.y; if (mi == pcursmonst) { Cl2DrawOutline(out, 233, px, py, pMonster->_mAnimData, pMonster->_mAnimFrame, pMonster->MType->width); @@ -719,7 +719,7 @@ static void DrawPlayerHelper(const CelOutputBuffer &out, int x, int y, int sx, i } PlayerStruct *pPlayer = &plr[p]; - int px = sx + pPlayer->position.offset.x - pPlayer->_pAnimWidth2; + int px = sx + pPlayer->position.offset.x - CalculateWidth2(pPlayer->_pAnimWidth); int py = sy + pPlayer->position.offset.y; DrawPlayer(out, p, x, y, px, py); @@ -768,7 +768,7 @@ static void scrollrt_draw_dungeon(const CelOutputBuffer &out, int sx, int sy, in do { DeadStruct *pDeadGuy = &dead[(bDead & 0x1F) - 1]; auto dd = static_cast((bDead >> 5) & 7); - int px = dx - pDeadGuy->_deadWidth2; + int px = dx - CalculateWidth2(pDeadGuy->_deadWidth); BYTE *pCelBuff = pDeadGuy->_deadData[dd]; assert(pCelBuff != nullptr); if (pCelBuff == nullptr) diff --git a/Source/towners.cpp b/Source/towners.cpp index 3125d78d4..283f0d96e 100644 --- a/Source/towners.cpp +++ b/Source/towners.cpp @@ -205,7 +205,6 @@ void InitTownerInfo(int i, int w, bool sel, _talker_id t, int x, int y, int ao) memset(&towners[i], 0, sizeof(TownerStruct)); towners[i]._tSelFlag = sel; towners[i]._tAnimWidth = w; - towners[i]._tAnimWidth2 = (w - 64) / 2; towners[i]._tMsgSaid = false; towners[i]._ttype = t; towners[i].position = { x, y }; diff --git a/Source/towners.h b/Source/towners.h index 26dca26d3..29cc280a8 100644 --- a/Source/towners.h +++ b/Source/towners.h @@ -46,7 +46,6 @@ struct TownerStruct { /** Tile position of NPC */ Point position; int16_t _tAnimWidth; - int16_t _tAnimWidth2; int16_t _tAnimDelay; // Tick length of each frame in the current animation int16_t _tAnimCnt; // Increases by one each game tick, counting how close we are to _pAnimDelay uint8_t _tAnimLen; // Number of frames in current animation diff --git a/test/writehero_test.cpp b/test/writehero_test.cpp index d99c72d2b..642bb6552 100644 --- a/test/writehero_test.cpp +++ b/test/writehero_test.cpp @@ -297,7 +297,6 @@ static void AssertPlayer(PlayerStruct *pPlayer) ASSERT_EQ(pPlayer->_pAnimLen, 20); ASSERT_EQ(pPlayer->_pAnimFrame, 1); ASSERT_EQ(pPlayer->_pAnimWidth, 96); - ASSERT_EQ(pPlayer->_pAnimWidth2, 16); ASSERT_EQ(pPlayer->_pSpell, -1); ASSERT_EQ(pPlayer->_pSplType, 4); ASSERT_EQ(pPlayer->_pSplFrom, 0);