Mercurial > mm7
diff Player.cpp @ 1682:3c451fd02fcf
OnInventoryLeftClick cleanup
author | Grumpy7 |
---|---|
date | Fri, 20 Sep 2013 10:23:54 +0200 |
parents | 406872881eb6 |
children | 96d567a7d15f |
line wrap: on
line diff
--- a/Player.cpp Thu Sep 19 08:26:28 2013 +0200 +++ b/Player.cpp Fri Sep 20 10:23:54 2013 +0200 @@ -7472,7 +7472,6 @@ Player *playerPtr; // ebx@3 Actor *actorPtr; // esi@3 unsigned int v8; // eax@4 - signed int v22; // edi@36 int spellId; // eax@38 signed int recvdMagicDmg; // eax@139 int v72[4]; // [sp+30h] [bp-24h]@164 @@ -7525,39 +7524,40 @@ if ( spellPower ) dmgToReceive /= (signed int)spellPower; } + int damageType; switch (element) { - case 0: v22 = actorPtr->pMonsterInfo.uAttack1Type; + case 0: damageType = actorPtr->pMonsterInfo.uAttack1Type; break; - case 1: v22 = actorPtr->pMonsterInfo.uAttack2Type; + case 1: damageType = actorPtr->pMonsterInfo.uAttack2Type; break; case 2: spellId = actorPtr->pMonsterInfo.uSpell1ID; - v22 = LOBYTE(pSpellStats->pInfos[spellId].uSchool); + damageType = LOBYTE(pSpellStats->pInfos[spellId].uSchool); break; case 3: spellId = actorPtr->pMonsterInfo.uSpell2ID; - v22 = LOBYTE(pSpellStats->pInfos[spellId].uSchool); + damageType = LOBYTE(pSpellStats->pInfos[spellId].uSchool); break; - case 4: v22 = actorPtr->pMonsterInfo.field_3C_some_special_attack; + case 4: damageType = actorPtr->pMonsterInfo.field_3C_some_special_attack; break; default: - case 5: v22 = 4; //yes, the original just assigned the value 4 + case 5: damageType = 4; //yes, the original just assigned the value 4 break; } if ( !(dword_6BE368_debug_settings_2 & 0x10) ) { - dmgToReceive = playerPtr->ReceiveDamage(dmgToReceive, (DAMAGE_TYPE)v22); + dmgToReceive = playerPtr->ReceiveDamage(dmgToReceive, (DAMAGE_TYPE)damageType); if ( playerPtr->pPlayerBuffs[10].uExpireTime > 0 ) { int actorState = actorPtr->uAIState; if ( actorState != Dying && actorState != Dead) { - int reflectedDamage = stru_50C198.CalcMagicalDamageToActor(actorPtr, v22, dmgToReceive); + int reflectedDamage = stru_50C198.CalcMagicalDamageToActor(actorPtr, damageType, dmgToReceive); actorPtr->sCurrentHP -= reflectedDamage; if ( reflectedDamage >= 0 ) { if ( actorPtr->sCurrentHP >= 1 ) { - Actor::AI_Stun(uActorID, PID(OBJECT_Player,a4), 0); + Actor::AI_Stun(uActorID, PID(OBJECT_Player,a4), 0); //todo extract this branch to a function once Actor::functions are changed to nonstatic actor functions Actor::AggroSurroundingPeasants(uActorID, 1); } else @@ -7797,102 +7797,108 @@ void OnInventoryLeftClick() { Player *v0; // ebx@1 - signed int v1; // eax@2 signed int v2; // ecx@2 int v3; // eax@2 - char v4; // sf@2 - int v5; // eax@2 + int invMatrixIndex; // eax@2 unsigned int v6; // eax@7 - unsigned int v7; // esi@12 - unsigned int v8; // eax@12 + unsigned int pickedItemId; // esi@12 + unsigned int invItemIndex; // eax@12 unsigned int v9; // eax@16 unsigned int v10; // eax@18 - ItemGen this_; // [sp+Ch] [bp-3Ch]@1 + ItemGen tmpItem; // [sp+Ch] [bp-3Ch]@1 POINT a2; // [sp+30h] [bp-18h]@4 - unsigned int v13; // [sp+38h] [bp-10h]@13 unsigned int pY; // [sp+3Ch] [bp-Ch]@2 unsigned int pX; // [sp+40h] [bp-8h]@2 - int a4; // [sp+44h] [bp-4h]@2 v0 = pPlayers[uActiveCharacter]; if ( pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] == 103 ) { pMouse->GetClickPos(&pX, &pY); - pY = pY - 17; - v2 =pX - 14; - pX = v2; - v3 = 14 * (pY >> 5); - v2 >>= 5; - v4 = v2 + v3 < 0; - v5 = v2 + v3; - a4 = v5; - if ( !v4 ) - { - if ( v5 <= 126 && pMouse->GetCursorPos(&a2)->x < 462 + v3 = Player::INVETORYSLOTSWIDTH * ((pY - 17) / 32); + v2 = (pX - 14) / 32; + invMatrixIndex = v2 + v3; + if ( v2 + v3 >= 0 ) + { + if ( invMatrixIndex <= 126 && pMouse->GetCursorPos(&a2)->x < 462 && pMouse->GetCursorPos(&a2)->x >= 14 ) { - if ( unk_50C9A0 ) + if ( _50C9A0_IsEnchantingInProgress ) { - v6 = v0->GetItemIDAtInventoryIndex(&a4); + v6 = v0->GetItemIDAtInventoryIndex(&invMatrixIndex); if ( v6 ) { *((char *)pGUIWindow_Settings->ptr_1C + 8) &= 0x7Fu; *((short *)pGUIWindow_Settings->ptr_1C + 2) = uActiveCharacter - 1; *((int *)pGUIWindow_Settings->ptr_1C + 3) = v6 - 1; - *((short *)pGUIWindow_Settings->ptr_1C + 3) = a4; - ptr_50C9A4 = (ItemGen *)&v0->pInventoryItemList[v6-1]; - unk_50C9A0 = 0; + *((short *)pGUIWindow_Settings->ptr_1C + 3) = invMatrixIndex; + ptr_50C9A4_ItemToEnchant = &v0->pInventoryItemList[v6-1]; + _50C9A0_IsEnchantingInProgress = 0; if ( pMessageQueue_50CBD0->uNumMessages ) pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0; pMouse->SetCursorBitmap("MICON1"); - dword_50C9D0 = 113; - dword_50C9D4 = 0; - dword_50C9D8 = 256; + _50C9D0_AfterEnchClickEventId = 113; + _50C9D4_AfterEnchClickEventSecondParam = 0; + _50C9D8_AfterEnchClickEventTimeout = 256; } return; } - if ( ptr_50C9A4 ) + if ( ptr_50C9A4_ItemToEnchant ) return; - v7 = pParty->pPickedItem.uItemID; - v8 = v0->GetItemIDAtInventoryIndex(&a4); - if ( !v7 ) + pickedItemId = pParty->pPickedItem.uItemID; + invItemIndex = v0->GetItemIDAtInventoryIndex(&invMatrixIndex); + if (!pickedItemId) { - if ( !v8 ) + if ( !invItemIndex ) return; - memcpy(&pParty->pPickedItem, &v0->pInventoryItemList[v8-1], sizeof(pParty->pPickedItem)); - v0->RemoveItemAtInventoryIndex(a4); - v9 = pParty->pPickedItem.uItemID; - pMouse->SetCursorBitmap(pItemsTable->pItems[v9].pIconName); - return; + else + { + memcpy(&pParty->pPickedItem, &v0->pInventoryItemList[invItemIndex-1], sizeof(pParty->pPickedItem)); + v0->RemoveItemAtInventoryIndex(invMatrixIndex); + v9 = pParty->pPickedItem.uItemID; + pMouse->SetCursorBitmap(pItemsTable->pItems[v9].pIconName); + return; + } } - v13 = v8; - if ( v8 ) + else { - a2.y = (LONG)&v0->pInventoryItemList[v8-1]; - memcpy(&this_, (const void *)a2.y, sizeof(this_)); - v0->RemoveItemAtInventoryIndex(a4); - pX = v0->AddItem2(a4, &pParty->pPickedItem); - if ( !pX ) + if ( invItemIndex ) { - pX = v0->AddItem2(0xFFFFFFFFu, &pParty->pPickedItem); - if ( !pX ) + ItemGen* invItemPtr = &v0->pInventoryItemList[invItemIndex-1]; + memcpy(&tmpItem, invItemPtr, sizeof(tmpItem)); + v0->RemoveItemAtInventoryIndex(invMatrixIndex); + int emptyIndex = v0->AddItem2(invMatrixIndex, &pParty->pPickedItem); + if ( !emptyIndex ) { - v0->PutItemArInventoryIndex(this_.uItemID, v13 - 1, a4); - memcpy((void *)a2.y, &this_, sizeof(ItemGen)); + emptyIndex = v0->AddItem2(-1, &pParty->pPickedItem); + if ( !emptyIndex ) + { + v0->PutItemArInventoryIndex(tmpItem.uItemID, invItemIndex - 1, invMatrixIndex); + memcpy(invItemPtr, &tmpItem, sizeof(ItemGen)); + return; + } + } + v9 = tmpItem.uItemID; + memcpy(&pParty->pPickedItem, &tmpItem, sizeof(ItemGen)); + pMouse->SetCursorBitmap(pItemsTable->pItems[pParty->pPickedItem.uItemID].pIconName); + return; + } + else + { + v10 = v0->AddItem(invMatrixIndex, pickedItemId); + if ( v10 ) + { + memcpy(&v0->pInventoryItemList[v10-1], &pParty->pPickedItem, sizeof(ItemGen)); + pMouse->RemoveHoldingItem(); + return; + } + v10 = v0->AddItem(-1, pickedItemId); + if ( v10 ) + { + memcpy(&v0->pInventoryItemList[v10-1], &pParty->pPickedItem, sizeof(ItemGen)); + pMouse->RemoveHoldingItem(); return; } } - v9 = this_.uItemID; - memcpy(&pParty->pPickedItem, &this_, sizeof(pParty->pPickedItem)); - pMouse->SetCursorBitmap(pItemsTable->pItems[v9].pIconName); - return; - } - v10 = v0->AddItem(a4, v7); - pX = v10; - if ( v10 || (v10 = v0->AddItem(-1, pParty->pPickedItem.uItemID), (pX = v10) != 0) ) - { - memcpy(&v0->pInventoryItemList[v10-1], &pParty->pPickedItem, 0x24u); - pMouse->RemoveHoldingItem(); } } }