Mercurial > might-and-magic-trilogy
changeset 24:74940016abc8
* on Players
* render now properly handles primary surface pitch
author | Nomad |
---|---|
date | Mon, 15 Oct 2012 18:28:43 +0200 |
parents | 509744251c8e |
children | 2bbf33898c6b c033691c2eca |
files | Player.cpp Player.h Render.cpp Spells.h mm7_4.cpp mm7_data.cpp mm7_data.h |
diffstat | 7 files changed, 117 insertions(+), 100 deletions(-) [+] |
line wrap: on
line diff
--- a/Player.cpp Sun Oct 14 00:27:38 2012 +0200 +++ b/Player.cpp Mon Oct 15 18:28:43 2012 +0200 @@ -46,13 +46,20 @@ struct PlayerCreation_AttributeProps { - PlayerCreation_AttributePropsByRace race[4]; + union + { + unsigned __int8 _[4][7][4]; + PlayerCreation_AttributePropsByRace race[4]; + }; }; #pragma pack(pop) -PlayerCreation_AttributeProps stru_4ED7B0; - - - +PlayerCreation_AttributeProps stru_4ED7B0 = +{ + 11, 25, 1, 1, 11, 25, 1, 1, 11, 25, 1, 1, 9, 25, 1, 1, 11, 25, 1, 1, 11, 25, 1, 1, 9, 25, 1, 1, + 7, 15, 2, 1, 14, 30, 1, 2, 11, 25, 1, 1, 7, 15, 2, 1, 14, 30, 1, 2, 11, 25, 1, 1, 9, 20, 1, 1, + 14, 30, 1, 2, 7, 15, 2, 1, 7, 15, 2, 1, 11, 25, 1, 1, 11, 25, 1, 1, 14, 30, 1, 2, 9, 20, 1, 1, + 14, 30, 1, 2, 11, 25, 1, 1, 11, 25, 1, 1, 14, 30, 1, 2, 7, 15, 2, 1, 7, 15, 2, 1, 9, 20, 1, 1 +}; @@ -104,6 +111,10 @@ unsigned int pConditionImportancyTable[18] = {16, 15, 14, 17, 13, 2, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 1, 0}; +short word_4EDFFC[30] = {500, 500, 400, 350, 300, 275, 250, 225, 200, 175, + 150, 125, 100, 75, 50, 40, 35, 30, 25, 21, + 19, 17, 15, 13, 11, 9, 7, 5, 3, 0}; +unsigned char player_stat_bonuses[30] = {30, 25, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 255, 254, 253, 252, 251, 250, 0}; @@ -1919,13 +1930,12 @@ { char v1; // al@1 int v2; // ecx@1 - char v3; // ah@1 int v4; // eax@3 signed int v6; // [sp-4h] [bp-4h]@2 v1 = GetActualSkillLevel(PLAYER_SKILL_BODYBUILDING); v2 = v1 & 0x3F; - if ( v3 & 1 ) + if ( v1 & 0x100 ) { v6 = 5; } @@ -1947,13 +1957,12 @@ { char v1; // al@1 int v2; // ecx@1 - char v3; // ah@1 int v4; // eax@3 signed int v6; // [sp-4h] [bp-4h]@2 v1 = GetActualSkillLevel(PLAYER_SKILL_MEDITATION); v2 = v1 & 0x3F; - if ( v3 & 1 ) + if ( v1 & 0x100 ) { v6 = 5; } @@ -2257,11 +2266,27 @@ uTimeToRecovery = 0; uSkillPoints = 0; + sHealth = 0; + uFullHealthBonus = 0; + _health_related = 0; + sMana = 0; + uFullManaBonus = 0; + _mana_related = 0; + uQuickSpell = 0; memset(pInstalledBeacons, 0, 5 * sizeof(LloydBeacon)); + _some_attack_bonus = 0; + field_1A91 = 0; + _melee_dmg_bonus = 0; + field_1A93 = 0; + _ranged_atk_bonus = 0; + field_1A95 = 0; + _ranged_dmg_bonus = 0; + field_1A97 = 0; + uExpressionID = 0; uExpressionTimePassed = 0; uExpressionTimeLength = 0; @@ -2417,12 +2442,9 @@ //----- (0048C90D) -------------------------------------------------------- int Player::GetActualLevel() { - Player *v1; // esi@1 - int v2; // edi@1 - - v1 = this; - v2 = GetItemsBonus(CHARACTER_ATTRIBUTE_LEVEL, 0); - return v1->sLevelModifier + GetMagicalBonus(CHARACTER_ATTRIBUTE_LEVEL) + v2 + v1->uLevel; + return uLevel + sLevelModifier + + GetMagicalBonus(CHARACTER_ATTRIBUTE_LEVEL) + + GetItemsBonus(CHARACTER_ATTRIBUTE_LEVEL, 0); } //----- (0048C93C) -------------------------------------------------------- @@ -2489,33 +2511,20 @@ //----- (0048CA3F) -------------------------------------------------------- int Player::GetActualWillpower() { - Player *v1; // esi@1 - unsigned int v2; // eax@1 - signed int v3; // ecx@1 - signed int v4; // ebx@4 int v5; // edi@5 - int v6; // ebp@5 - - v1 = this; - v2 = this->sAgeModifier + GetBaseAge(); - v3 = 0; - while ( (signed int)v2 >= (signed int)pAgeingTable[v3] ) - { - ++v3; - if ( v3 >= 4 ) - { - v4 = 100; - goto LABEL_5; - } - } - v4 = pAgeingWillpowerMultiplier[v3]; -LABEL_5: + + uint uActualAge = GetBaseAge() + sAgeModifier; + uint uAgeingMultiplier = 100; + for (uint i = 0; i < 4; ++i) + if (uActualAge >= pAgeingTable[i]) + uAgeingMultiplier = pAgeingWillpowerMultiplier[i]; + else break; + v5 = pConditionWillpowerMultiplier[GetMajorConditionIdx()]; - v6 = GetItemsBonus(CHARACTER_ATTRIBUTE_WILLPOWER, 0); - return v5 * v4 * v1->uWillpower / 100 / 100 + return v5 * uAgeingMultiplier * uWillpower / 100 / 100 + GetMagicalBonus(CHARACTER_ATTRIBUTE_WILLPOWER) - + v6 - + v1->uWillpowerBonus; + + GetItemsBonus(CHARACTER_ATTRIBUTE_WILLPOWER, 0) + + uWillpowerBonus; } //----- (0048CABC) -------------------------------------------------------- @@ -3353,19 +3362,16 @@ } //----- (0048D6D0) -------------------------------------------------------- -int Player::HasEnchantedItemEquipped(int uEnchantment) -{ - int v2; // esi@1 - int v3; // edx@2 - - v2 = 0; - while ( !HasItemEquipped((ITEM_EQUIP_TYPE)v2) || *(int *)&this->field_1F5[36 * *(int *)v3 + 7] != uEnchantment ) - { - ++v2; - if ( (signed int)v2 >= 16 ) - return 0; - } - return 1; +bool Player::HasEnchantedItemEquipped(int uEnchantment) +{ + for (uint i = 0; i < 16; ++i) + { + if (HasItemEquipped((ITEM_EQUIP_TYPE)i) && + pInventoryItems[i].uAdditionalValue == uEnchantment) + // *(int *)&this->field_1F6[36 * pEquipment[i] + 6] != uEnchantment) + return true; + } + return false; } //----- (0048D709) -------------------------------------------------------- @@ -4264,27 +4270,22 @@ { int v3; // esi@1 int v4; // esi@1 - int v5; // esi@1 int v6; // esi@1 - signed int result; // eax@1 v3 = _48EA1B_get_static_effect(GetActualEndurance()); v4 = pBaseHealthPerLevelByClass[uClass] * (GetActualLevel() + v3); - v5 = GetItemsBonus(CHARACTER_ATTRIBUTE_HEALTH, 0) + v4; v6 = uFullHealthBonus + pBaseHealthByClass[uClass / 4] + GetSkillBonus(CHARACTER_ATTRIBUTE_HEALTH) - + v5; - result = 1; - if ( v6 >= 1 ) - result = v6; - return result; + + GetItemsBonus(CHARACTER_ATTRIBUTE_HEALTH, 0) + v4; + if (v6 <= 0) + return 1; + return v6; } //----- (0048E565) -------------------------------------------------------- int Player::GetMaxMana() { - Player *v1; // edi@1 int v2; // eax@2 int v3; // esi@4 int v4; // eax@5 @@ -4295,8 +4296,7 @@ int v9; // esi@6 int result; // eax@7 - v1 = this; - switch ( this->uClass ) + switch (uClass) { case 5u: case 6u: @@ -4310,7 +4310,8 @@ case 0x22u: case 0x23u: v2 = GetActualIntelligence(); - goto LABEL_4; + v3 = _48EA1B_get_static_effect(v2); + goto LABEL_6; case 9u: case 0xAu: case 0xBu: @@ -4323,7 +4324,6 @@ case 0x1Au: case 0x1Bu: v2 = GetActualWillpower(); -LABEL_4: v3 = _48EA1B_get_static_effect(v2); goto LABEL_6; case 0x15u: @@ -4338,10 +4338,10 @@ v6 = GetActualIntelligence(); v3 = _48EA1B_get_static_effect(v6) + v5; LABEL_6: - v7 = pBaseManaPerLevelByClass[v1->uClass] * (GetActualLevel() + v3); + v7 = pBaseManaPerLevelByClass[uClass] * (GetActualLevel() + v3); v8 = GetItemsBonus(CHARACTER_ATTRIBUTE_MANA, 0) + v7; - v9 = v1->uFullManaBonus - + pBaseManaByClass[v1->uClass / 4] + v9 = uFullManaBonus + + pBaseManaByClass[uClass / 4] + GetSkillBonus(CHARACTER_ATTRIBUTE_MANA) + v8; if ( v9 < 1 ) @@ -4743,6 +4743,15 @@ v6 = this; v62 = 0; v61 = 0; + + switch (attr) + { + case CHARACTER_ATTRIBUTE_LEVEL: + if (HasEnchantedItemEquipped(25)) + return 5; + return 0; + }; + if ( (signed int)attr > 36 ) { switch ( attr ) @@ -5482,13 +5491,6 @@ return v5 + v62 + v61; if ( (signed int)attr <= 23 ) goto LABEL_95; - if ( attr == 24 ) - { - if ( !HasEnchantedItemEquipped(25) ) - return v5 + v62 + v61; - v59 = 5; - goto LABEL_74; - } if ( (signed int)attr <= 24 ) return v5 + v62 + v61; if ( (signed int)attr <= 26 ) @@ -5552,6 +5554,11 @@ int v3; // eax@4 int v4; // ecx@5 + switch (a2) + { + case CHARACTER_ATTRIBUTE_LEVEL: return 0; + } + result = 0; if ( (signed int)a2 > 10 ) { @@ -5592,7 +5599,7 @@ v4 = pParty->pPartyBuffs[9].uPower; return v4 + v3; } - if ( a2 != 29 ) + if ( a2 != CHARACTER_ATTRIBUTE_RANGED_ATTACK ) return result; } return this->pPlayerBuffs[1].uPower; @@ -5606,25 +5613,25 @@ switch ( a2 ) { case CHARACTER_ATTRIBUTE_STRENGTH: - v3 = this->pPlayerBuffs[19].uPower; + v3 = pPlayerBuffs[19].uPower; goto LABEL_5; case CHARACTER_ATTRIBUTE_INTELLIGENCE: - v3 = this->pPlayerBuffs[17].uPower; + v3 = pPlayerBuffs[17].uPower; goto LABEL_5; case CHARACTER_ATTRIBUTE_WILLPOWER: - v3 = this->pPlayerBuffs[20].uPower; + v3 = pPlayerBuffs[20].uPower; goto LABEL_5; case CHARACTER_ATTRIBUTE_ENDURANCE: - v3 = this->pPlayerBuffs[16].uPower; + v3 = pPlayerBuffs[16].uPower; goto LABEL_5; case CHARACTER_ATTRIBUTE_ACCURACY: - v3 = this->pPlayerBuffs[15].uPower; + v3 = pPlayerBuffs[15].uPower; goto LABEL_5; case CHARACTER_ATTRIBUTE_SPEED: - v3 = this->pPlayerBuffs[21].uPower; + v3 = pPlayerBuffs[21].uPower; goto LABEL_5; case CHARACTER_ATTRIBUTE_LUCK: - v3 = this->pPlayerBuffs[18].uPower; + v3 = pPlayerBuffs[18].uPower; LABEL_5: v4 = pParty->pPartyBuffs[2].uPower; return v4 + v3;
--- a/Player.h Sun Oct 14 00:27:38 2012 +0200 +++ b/Player.h Mon Oct 15 18:28:43 2012 +0200 @@ -226,7 +226,7 @@ int GetEquippedItemSkillType(enum ITEM_EQUIP_TYPE uEquipSlot); bool IsUnarmed(); bool HasItemEquipped(enum ITEM_EQUIP_TYPE uEquipIndex); - int HasEnchantedItemEquipped(int uEnchantment); + bool HasEnchantedItemEquipped(int uEnchantment); bool WearsItem(int a1, signed int a2); bool StealFromShop(struct ItemGen *a2, int a3, int a4, int a5, int *a6); int StealFromActor(unsigned int uActorID, int _steal_perm, int reputation); @@ -347,7 +347,7 @@ unsigned __int16 pActiveSkills[37]; char field_152[64]; PlayerSpells spellbook; - char field_1F5[30]; + char field_1F5[30]; // used to be [31] ItemGen pInventoryItems[126]; ItemGen pEquippedItems[12]; int pInventoryIndices[126];
--- a/Render.cpp Sun Oct 14 00:27:38 2012 +0200 +++ b/Render.cpp Mon Oct 15 18:28:43 2012 +0200 @@ -4927,6 +4927,7 @@ { pRenderer->EndScene(); } + pAllocator->FreeChunk(ptr); fclose(v6); }
--- a/Spells.h Sun Oct 14 00:27:38 2012 +0200 +++ b/Spells.h Mon Oct 15 18:28:43 2012 +0200 @@ -39,6 +39,16 @@ #pragma pack(push, 1) struct SpellBuff { + inline SpellBuff() + { + uExpireTime = 0; + uPower = 0; + uSkill = 0; + uOverlayID = 0; + uCaster = 0; + uFlags = 0; + } + signed int Apply(unsigned __int64 uExpireTime, unsigned __int16 uSkillLevel, unsigned __int16 uPower, int a5, unsigned __int8 a6); void Reset(); signed int _4585CA(__int64 a2);
--- a/mm7_4.cpp Sun Oct 14 00:27:38 2012 +0200 +++ b/mm7_4.cpp Mon Oct 15 18:28:43 2012 +0200 @@ -7550,25 +7550,30 @@ v1 = pRenderer->pTargetSurface; v2 = Dst.lpSurface; - //memset(pRenderer->pTargetSurface, 128, 640 * 2 * 320); - + for (uint y = 0; y < 480; ++y) + { + auto pDst = (unsigned short *)((char *)Dst.lpSurface + y * Dst.lPitch); + for (uint x = 0; x < 640; ++x) + pDst[x] = pRenderer->uTargetGMask | pRenderer->uTargetBMask; + } + auto pSrc = pRenderer->pTargetSurface; auto pDst = (__int16 *)Dst.lpSurface; for (uint y = 0; y < 8; ++y) - memcpy(pDst + y * 640, + memcpy(pDst + y * Dst.lPitch / 2, pSrc + y * 640, 640 * sizeof(__int16)); for (uint y = 8; y < 352; ++y) { - memcpy(pDst + y * 640, + memcpy(pDst + y * Dst.lPitch / 2, pSrc + y * 640, 8 * sizeof(__int16)); - memcpy(pDst + y * 640 + 8 + 460/*462*/, - pSrc + y * 640 + 8 + 460/*462*/, 174/*172*/ * sizeof(__int16)); + memcpy(pDst + 8 + 460/*462*/ + y * Dst.lPitch / 2, + pSrc + 8 + 460/*462*/ + y * Dst.lPitch / 2, 174/*172*/ * sizeof(__int16)); } for (uint y = 351/*352*/; y < 480; ++y) - memcpy(pDst + y * 640, + memcpy(pDst + y * Dst.lPitch / 2, pSrc + y * 640, 640 * sizeof(__int16)); @@ -7589,8 +7594,8 @@ v13 = v24; for (uint y = pViewport->uViewportY; y < pViewport->uViewportW; ++y) - memcpy(pDst + 640 * y + pViewport->uViewportX, - pSrc + 640 * y + pViewport->uViewportX, (pViewport->uViewportZ - pViewport->uViewportX) * sizeof(__int16)); + memcpy(pDst + pViewport->uViewportX + y * Dst.lPitch / 2, + pSrc + pViewport->uViewportX + y * 640, (pViewport->uViewportZ - pViewport->uViewportX) * sizeof(__int16)); ErrD3D(pRenderer->pBackBuffer4->Unlock(0));
--- a/mm7_data.cpp Sun Oct 14 00:27:38 2012 +0200 +++ b/mm7_data.cpp Mon Oct 15 18:28:43 2012 +0200 @@ -1943,10 +1943,6 @@ __int16 word_4EDED8[777]; // weak __int16 word_4EDEDC; // weak _UNKNOWN unk_4EDF40; // weak -short word_4EDFFC[30] = {500, 500, 400, 350, 300, 275, 250, 225, 200, 175, - 150, 125, 100, 75, 50, 40, 35, 30, 25, 21, - 19, 17, 15, 13, 11, 9, 7, 5, 3, 0}; -char player_stat_bonuses[777]; // weak unsigned int pHiredNPCsIconsOffsetsX[2]; unsigned int pHiredNPCsIconsOffsetsY[2]; int dword_4EE07C[2]; // weak
--- a/mm7_data.h Sun Oct 14 00:27:38 2012 +0200 +++ b/mm7_data.h Mon Oct 15 18:28:43 2012 +0200 @@ -1931,8 +1931,6 @@ extern __int16 word_4EDED8[]; // weak extern __int16 word_4EDEDC; // weak extern _UNKNOWN unk_4EDF40; // weak -extern __int16 word_4EDFFC[30]; -extern char player_stat_bonuses[]; // weak extern unsigned int pHiredNPCsIconsOffsetsX[2]; extern unsigned int pHiredNPCsIconsOffsetsY[2]; extern int dword_4EE07C[2]; // weak