diff --git a/Source/items.cpp b/Source/items.cpp index f7ba6ea88..f18564ce9 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -888,10 +888,10 @@ void CalcPlrItemVals(int playerId, bool Loadgfx) SetPlrAnims(player); LoadPlrGFX(player, static_cast(PFILE_STAND | PFILE_WALK)); if (player._pmode == PM_STAND) { - player._pAnimWidth = player._pNWidth; + player._pAnimWidth = player.GetAnimationWidth(PFILE_STAND); player.AnimInfo.ChangeAnimationData(player._pNAnim[player._pdir], player._pNFrames, 3); } else { - player._pAnimWidth = player._pWWidth; + player._pAnimWidth = player.GetAnimationWidth(PFILE_WALK); player.AnimInfo.ChangeAnimationData(player._pWAnim[player._pdir], player._pWFrames, 0); } } else { diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 6fb5d081e..a3fb32776 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -434,29 +434,36 @@ static void LoadPlayer(LoadHelper *file, int p) pPlayer->_pGFXLoad = file->nextLE(); file->skip(4 * 8); // Skip pointers _pNAnim pPlayer->_pNFrames = file->nextLE(); - pPlayer->_pNWidth = file->nextLE(); + // skip _pNWidth + file->skip(4); file->skip(4 * 8); // Skip pointers _pWAnim pPlayer->_pWFrames = file->nextLE(); - pPlayer->_pWWidth = file->nextLE(); + // skip _pWWidth + file->skip(4); file->skip(4 * 8); // Skip pointers _pAAnim pPlayer->_pAFrames = file->nextLE(); - pPlayer->_pAWidth = file->nextLE(); + // skip _pAWidth + file->skip(4); pPlayer->_pAFNum = file->nextLE(); file->skip(4 * 8); // Skip pointers _pLAnim file->skip(4 * 8); // Skip pointers _pFAnim file->skip(4 * 8); // Skip pointers _pTAnim pPlayer->_pSFrames = file->nextLE(); - pPlayer->_pSWidth = file->nextLE(); + // skip _pSWidth + file->skip(4); pPlayer->_pSFNum = file->nextLE(); file->skip(4 * 8); // Skip pointers _pHAnim pPlayer->_pHFrames = file->nextLE(); - pPlayer->_pHWidth = file->nextLE(); + // skip _pHWidth + file->skip(4); file->skip(4 * 8); // Skip pointers _pDAnim pPlayer->_pDFrames = file->nextLE(); - pPlayer->_pDWidth = file->nextLE(); + // skip _pDWidth + file->skip(4); file->skip(4 * 8); // Skip pointers _pBAnim pPlayer->_pBFrames = file->nextLE(); - pPlayer->_pBWidth = file->nextLE(); + // skip _pBWidth + file->skip(4); LoadItems(file, NUM_INVLOC, pPlayer->InvBody); LoadItems(file, NUM_INV_GRID_ELEM, pPlayer->InvList); @@ -1421,29 +1428,36 @@ static void SavePlayer(SaveHelper *file, int p) file->writeLE(pPlayer->_pGFXLoad); file->skip(4 * 8); // Skip pointers _pNAnim file->writeLE(pPlayer->_pNFrames); - file->writeLE(pPlayer->_pNWidth); + // Skip _pNWidth + file->skip(4); file->skip(4 * 8); // Skip pointers _pWAnim file->writeLE(pPlayer->_pWFrames); - file->writeLE(pPlayer->_pWWidth); + // Skip _pWWidth + file->skip(4); file->skip(4 * 8); // Skip pointers _pAAnim file->writeLE(pPlayer->_pAFrames); - file->writeLE(pPlayer->_pAWidth); + // Skip _pAWidth + file->skip(4); file->writeLE(pPlayer->_pAFNum); file->skip(4 * 8); // Skip pointers _pLAnim file->skip(4 * 8); // Skip pointers _pFAnim file->skip(4 * 8); // Skip pointers _pTAnim file->writeLE(pPlayer->_pSFrames); - file->writeLE(pPlayer->_pSWidth); + // Skip _pSWidth + file->skip(4); file->writeLE(pPlayer->_pSFNum); file->skip(4 * 8); // Skip pointers _pHAnim file->writeLE(pPlayer->_pHFrames); - file->writeLE(pPlayer->_pHWidth); + // Skip _pHWidth + file->skip(4); file->skip(4 * 8); // Skip pointers _pDAnim file->writeLE(pPlayer->_pDFrames); - file->writeLE(pPlayer->_pDWidth); + // Skip _pDWidth + file->skip(4); file->skip(4 * 8); // Skip pointers _pBAnim file->writeLE(pPlayer->_pBFrames); - file->writeLE(pPlayer->_pBWidth); + // Skip _pBWidth + file->skip(4); SaveItems(file, pPlayer->InvBody, NUM_INVLOC); SaveItems(file, pPlayer->InvList, NUM_INV_GRID_ELEM); diff --git a/Source/player.cpp b/Source/player.cpp index 2881035d3..10aa995f8 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -374,6 +374,52 @@ void PlayerStruct::Reset() *this = std::move(*emptyPlayer); } +int PlayerStruct::GetAnimationWidth(player_graphic graphic) +{ + switch (graphic) { + case PFILE_STAND: + if (_pClass == HeroClass::Monk) + return 112; + return 96; + case PFILE_WALK: + if (_pClass == HeroClass::Monk) + return 112; + return 96; + case PFILE_ATTACK: + if (_pClass == HeroClass::Monk) + return 130; + if (_pClass == HeroClass::Warrior || _pClass == HeroClass::Barbarian) { + auto gn = static_cast(_pgfxnum & 0xF); + if (gn == ANIM_ID_BOW) + return 96; + } + return 128; + case PFILE_HIT: + if (_pClass == HeroClass::Monk) + return 98; + return 96; + case PFILE_LIGHTNING: + case PFILE_FIRE: + case PFILE_MAGIC: + if (_pClass == HeroClass::Monk) + return 114; + if (_pClass == HeroClass::Sorcerer) + return 128; + return 96; + case PFILE_DEATH: + if (_pClass == HeroClass::Monk) + return 160; + return 128; + case PFILE_BLOCK: + if (_pClass == HeroClass::Monk) + return 98; + return 96; + default: + Log("GetAnimationWidth: Unkown graphic {}", graphic); + return 96; + } +} + void SetPlayerGPtrs(byte *pData, byte **pAnim) { int i; @@ -625,43 +671,34 @@ void NewPlrAnim(PlayerStruct &player, player_graphic graphic, Direction dir, int if ((player._pGFXLoad & graphic) != graphic) LoadPlrGFX(player, graphic); - int width = 96; + int width = player.GetAnimationWidth(graphic); byte *pData = nullptr; switch (graphic) { case PFILE_STAND: - width = player._pNWidth; pData = player._pNAnim[dir]; break; case PFILE_WALK: - width = player._pWWidth; pData = player._pWAnim[dir]; break; case PFILE_ATTACK: - width = player._pAWidth; pData = player._pAAnim[dir]; break; case PFILE_HIT: - width = player._pHWidth; pData = player._pHAnim[dir]; break; case PFILE_LIGHTNING: - width = player._pSWidth; pData = player._pLAnim[dir]; break; case PFILE_FIRE: - width = player._pSWidth; pData = player._pFAnim[dir]; break; case PFILE_MAGIC: - width = player._pSWidth; pData = player._pTAnim[dir]; break; case PFILE_DEATH: - width = player._pDWidth; pData = player._pDAnim[dir]; break; case PFILE_BLOCK: - width = player._pBWidth; pData = player._pBAnim[dir]; break; default: @@ -685,14 +722,6 @@ static void ClearPlrPVars(PlayerStruct &player) void SetPlrAnims(PlayerStruct &player) { - player._pNWidth = 96; - player._pWWidth = 96; - player._pAWidth = 128; - player._pHWidth = 96; - player._pSWidth = 96; - player._pDWidth = 128; - player._pBWidth = 96; - HeroClass pc = player._pClass; if (leveltype == DTYPE_TOWN) { @@ -718,7 +747,6 @@ void SetPlrAnims(PlayerStruct &player) if (leveltype != DTYPE_TOWN) { player._pNFrames = 8; } - player._pAWidth = 96; player._pAFNum = 11; } else if (gn == ANIM_ID_AXE) { player._pAFrames = 20; @@ -739,7 +767,6 @@ void SetPlrAnims(PlayerStruct &player) player._pAFNum = 11; } } else if (pc == HeroClass::Sorcerer) { - player._pSWidth = 128; if (gn == ANIM_ID_UNARMED) { player._pAFrames = 20; } else if (gn == ANIM_ID_UNARMED_SHIELD) { @@ -752,14 +779,6 @@ void SetPlrAnims(PlayerStruct &player) player._pAFNum = 16; } } else if (pc == HeroClass::Monk) { - player._pNWidth = 112; - player._pWWidth = 112; - player._pAWidth = 130; - player._pHWidth = 98; - player._pSWidth = 114; - player._pDWidth = 160; - player._pBWidth = 98; - switch (gn) { case ANIM_ID_UNARMED: case ANIM_ID_UNARMED_SHIELD: @@ -800,7 +819,6 @@ void SetPlrAnims(PlayerStruct &player) if (leveltype != DTYPE_TOWN) { player._pNFrames = 8; } - player._pAWidth = 96; player._pAFNum = 11; } else if (gn == ANIM_ID_STAFF) { player._pAFrames = 16; diff --git a/Source/player.h b/Source/player.h index e83d89860..6fb841357 100644 --- a/Source/player.h +++ b/Source/player.h @@ -241,29 +241,22 @@ struct PlayerStruct { int _pGFXLoad; byte *_pNAnim[8]; // Stand animations int _pNFrames; - int _pNWidth; byte *_pWAnim[8]; // Walk animations int _pWFrames; - int _pWWidth; byte *_pAAnim[8]; // Attack animations int _pAFrames; - int _pAWidth; int _pAFNum; byte *_pLAnim[8]; // Lightning spell cast animations byte *_pFAnim[8]; // Fire spell cast animations byte *_pTAnim[8]; // Generic spell cast animations int _pSFrames; - int _pSWidth; int _pSFNum; byte *_pHAnim[8]; // Getting hit animations int _pHFrames; - int _pHWidth; byte *_pDAnim[8]; // Death animations int _pDFrames; - int _pDWidth; byte *_pBAnim[8]; // Block animations int _pBFrames; - int _pBWidth; ItemStruct InvBody[NUM_INVLOC]; ItemStruct InvList[NUM_INV_GRID_ELEM]; int _pNumInv; @@ -403,6 +396,11 @@ struct PlayerStruct { * @brief Resets all Data of the current PlayerStruct */ void Reset(); + + /** + * @brief Gets the width for the specified player animation + */ + int GetAnimationWidth(player_graphic graphic); }; extern int myplr; diff --git a/test/writehero_test.cpp b/test/writehero_test.cpp index cd97d37b3..e6cfca49e 100644 --- a/test/writehero_test.cpp +++ b/test/writehero_test.cpp @@ -324,21 +324,14 @@ static void AssertPlayer(PlayerStruct *pPlayer) ASSERT_EQ(CountBool(pPlayer->_pLvlVisited, NUMLEVELS), 0); ASSERT_EQ(CountBool(pPlayer->_pSLvlVisited, NUMLEVELS), 0); ASSERT_EQ(pPlayer->_pNFrames, 20); - ASSERT_EQ(pPlayer->_pNWidth, 96); ASSERT_EQ(pPlayer->_pWFrames, 8); - ASSERT_EQ(pPlayer->_pWWidth, 96); ASSERT_EQ(pPlayer->_pAFrames, 0); - ASSERT_EQ(pPlayer->_pAWidth, 128); ASSERT_EQ(pPlayer->_pAFNum, 0); ASSERT_EQ(pPlayer->_pSFrames, 16); - ASSERT_EQ(pPlayer->_pSWidth, 96); ASSERT_EQ(pPlayer->_pSFNum, 12); ASSERT_EQ(pPlayer->_pHFrames, 0); - ASSERT_EQ(pPlayer->_pHWidth, 96); ASSERT_EQ(pPlayer->_pDFrames, 20); - ASSERT_EQ(pPlayer->_pDWidth, 128); ASSERT_EQ(pPlayer->_pBFrames, 0); - ASSERT_EQ(pPlayer->_pBWidth, 96); ASSERT_EQ(pPlayer->_pIMinDam, 1); ASSERT_EQ(pPlayer->_pIMaxDam, 14); ASSERT_EQ(pPlayer->_pIAC, 115);