Mercurial > mm7
diff mm7_6.cpp @ 271:1f0af5cac2dd
_42ECB5_PlayerAttacksActor
author | Nomad |
---|---|
date | Mon, 18 Feb 2013 13:07:25 +0200 |
parents | a6a8fa73b4ec |
children | 640a176c030f |
line wrap: on
line diff
--- a/mm7_6.cpp Mon Feb 18 11:29:55 2013 +0200 +++ b/mm7_6.cpp Mon Feb 18 13:07:25 2013 +0200 @@ -3323,7 +3323,7 @@ v666 = 1; else v666 = v1; - a2 = stru_50C198.FindClosesActor(5120, 1, v666); + a2 = stru_50C198.FindClosestActor(5120, 1, v666); v6 = pMouse->uPointingObjectID; if ( pMouse->uPointingObjectID != v1 && (v6 & 7) == OBJECT_Actor && pActors[v6 >> 3].CanAct() ) { @@ -7832,16 +7832,16 @@ } //----- (0042ECB5) -------------------------------------------------------- -bool __cdecl _42ECB5_PlayerAttacksActor() +void _42ECB5_PlayerAttacksActor() { - unsigned int v0; // ebx@1 - Player *v1; // esi@1 - bool result; // eax@1 + //unsigned int v0; // ebx@1 + //Player *v1; // esi@1 + //bool result; // eax@1 int v3; // edi@2 - unsigned int v4; // eax@7 + //unsigned int v4; // eax@7 char *v5; // eax@8 - int v6; // ecx@9 - signed int v7; // eax@16 + //int v6; // ecx@9 + //signed int v7; // eax@16 Actor *v8; // edi@20 unsigned int v9; // ecx@21 char *v10; // eax@26 @@ -7860,74 +7860,88 @@ int v23; // [sp-4h] [bp-40h]@44 SoundID v24; // [sp-4h] [bp-40h]@58 Vec3_int_ a3; // [sp+Ch] [bp-30h]@19 - unsigned int a2; // [sp+18h] [bp-24h]@20 - unsigned int v27; // [sp+1Ch] [bp-20h]@1 + //unsigned int a2; // [sp+18h] [bp-24h]@20 + //unsigned int v27; // [sp+1Ch] [bp-20h]@1 int v28; // [sp+20h] [bp-1Ch]@9 - unsigned int *v28b; + //unsigned int *v28b; int v29; // [sp+24h] [bp-18h]@16 int v30; // [sp+28h] [bp-14h]@16 - int v31; // [sp+2Ch] [bp-10h]@4 + //int v31; // [sp+2Ch] [bp-10h]@4 int v32; // [sp+30h] [bp-Ch]@7 - int v33; // [sp+34h] [bp-8h]@7 + //int v33; // [sp+34h] [bp-8h]@7 int v34; // [sp+38h] [bp-4h]@17 - v0 = uActiveCharacter; - v27 = 6972 * uActiveCharacter; - v1 = &pParty->pPlayers[uActiveCharacter-1]; - result = pParty->pPlayers[uActiveCharacter-1].CanAct(); - if ( result ) + //v0 = uActiveCharacter; + //v27 = 6972 * uActiveCharacter; + //v1 = &pParty->pPlayers[uActiveCharacter-1]; + //result = pParty->pPlayers[uActiveCharacter-1].CanAct(); + auto player = &pParty->pPlayers[uActiveCharacter - 1]; + if (!player->CanAct()) + return; + + pStru277->_427D48(uActiveCharacter); + v3 = 0; + if (pParty->Invisible()) + pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Reset(); + + //v31 = player->pEquipment.uBow; + int bow_idx = player->pEquipment.uBow; + if (bow_idx && player->pInventoryItems[bow_idx - 1].Broken()) + bow_idx = 0; + + v32 = 0; + //v33 = 0; + //v4 = v1->pEquipment.uMainHand; + int laser_weapon_item_id = 0; + + int main_hand_idx = player->pEquipment.uMainHand; + if (main_hand_idx) { - pStru277->_427D48(v0); - v3 = 0; - if ( (signed __int64)pParty->pPartyBuffs[11].uExpireTime > 0 ) - pParty->pPartyBuffs[11].Reset(); - v31 = v1->pEquipment.uBow; - if ( v31 && v1->field_1F5[36 * v31 + 15] & 2 ) - v31 = 0; - v4 = v1->pEquipment.uMainHand; - v32 = 0; - v33 = 0; - if ( v4 ) - { + auto item = &player->pInventoryItems[main_hand_idx - 1]; //v5 = (char *)v1 + 36 * v4; - if ( !(v1->pInventoryItems[v4].field_1A & 2) )//v5[516] & 2) ) + if (!item->Broken()) + { + //v28b = &v1->pInventoryItems[v4].uItemID; + //v6 = v1->pInventoryItems[v4].uItemID;//*((int *)v5 + 124); + if (pItemsTable->pItems[item->uItemID].uEquipType == EQUIP_C) { - v28b = &v1->pInventoryItems[v4].uItemID; - v6 = v1->pInventoryItems[v4].uItemID;//*((int *)v5 + 124); - if ( pItemsTable->pItems[v6].uEquipType == 12 ) - { - if ( v1->pInventoryItems[v4]._bonus_type <= 0 ) - { - *v28b = 0; - v1->pEquipment.uMainHand = 0; - } - else - { - v32 = v1->pInventoryItems[v4].uItemID;//*((int *)v5 + 124); - } - } + if (item->_bonus_type <= 0) + player->pEquipment.uMainHand = 0; else - { - if ( v6 == 64 || v6 == 65 ) - v33 = v1->pInventoryItems[v4].uItemID;//*((int *)v5 + 124); - } + v32 = item->uItemID;//*((int *)v5 + 124); } + else if (item->uItemID == ITEM_BLASTER || item->uItemID == ITEM_LASER_RIFLE) + laser_weapon_item_id = item->uItemID;//*((int *)v5 + 124); } + } + v30 = 0; v29 = 0; v28 = 0; - v7 = pMouse->uPointingObjectID; - if ( (pMouse->uPointingObjectID & 7) != OBJECT_Actor || (v34 = pMouse->uPointingObjectID, !pActors[v7 >> 3].CanAct()) ) - v34 = stru_50C198.FindClosesActor(5120, 0, 0); + //v7 = pMouse->uPointingObjectID; + + int target_pid = pMouse->uPointingObjectID; + int target_type = target_pid & 7, + target_id = target_pid >> 3; + if (target_type != OBJECT_Actor || !pActors[target_id].CanAct()) + { + target_pid = stru_50C198.FindClosestActor(5120, 0, 0); + target_type = target_pid & 7; + target_id = target_pid >> 3; + } + + a3.z = 0; a3.y = 0; a3.x = 0; - if ( (v34 & 7) == OBJECT_Actor) - { - a2 = v34 >> 3; - v8 = &pActors[v34 >> 3]; - v34 = sub_452A9E((v8->vPosition.x - pParty->vPosition.x) * (v8->vPosition.x - pParty->vPosition.x) + (v8->vPosition.y - pParty->vPosition.y) * (v8->vPosition.y - pParty->vPosition.y) + (v8->vPosition.z - pParty->vPosition.z) * (v8->vPosition.z - pParty->vPosition.z)) - - v8->uActorRadius; + if (target_type == OBJECT_Actor) + { + //a2 = target_id; + v8 = &pActors[target_id]; + int distance_x = v8->vPosition.x - pParty->vPosition.x, + distance_y = v8->vPosition.y - pParty->vPosition.y, + distance_z = v8->vPosition.z - pParty->vPosition.z; + v34 = sub_452A9E(distance_x * distance_x + distance_y * distance_y + distance_z * distance_z) - v8->uActorRadius; if ( v34 >= 0 ) { v9 = 0; @@ -7937,15 +7951,15 @@ v9 = 0; v34 = 0; } - if ( v33 != v9 ) + if ( laser_weapon_item_id != v9 ) { v28 = 1; - v22 = v0 + 8; + v22 = uActiveCharacter + 8; v20 = v9; v18 = v9; v16 = 102; LABEL_34: - _42777D_CastSpell_UseWand_ShootArrow(v16, v0 - 1, v18, v20, v22); + _42777D_CastSpell_UseWand_ShootArrow(v16, uActiveCharacter - 1, v18, v20, v22); LABEL_28: v3 = 0; goto LABEL_29; @@ -7955,18 +7969,18 @@ v29 = 1; _42777D_CastSpell_UseWand_ShootArrow( *((int *)&pSpellDatas[66].field_8 - + *(int *)(&stru_AA1058[3].pSounds[36 * *(int *)&pParty->pArtifactsFound[v27 + 22] + 41048] + v27)), - v0 - 1, + + *(int *)(&stru_AA1058[3].pSounds[36 * *(int *)&pParty->pArtifactsFound[6972 * uActiveCharacter + 22] + 41048] + 6972 * uActiveCharacter)), + uActiveCharacter - 1, 8u, v9, - v0 + 8); - v10 = &v1->field_1F5[36 * v1->pEquipment.uMainHand + 11]; + uActiveCharacter + 8); + v10 = &player->field_1F5[36 * player->pEquipment.uMainHand + 11]; --*(int *)v10; - v11 = (char *)v1 + 36 * v1->pEquipment.uMainHand; + v11 = (char *)player + 36 * player->pEquipment.uMainHand; if ( *((int *)v11 + 128) <= 0 ) { *((int *)v11 + 124) = 0; - v1->pEquipment.uMainHand = 0; + player->pEquipment.uMainHand = 0; } goto LABEL_28; } @@ -7976,19 +7990,19 @@ a3.y = v8->vPosition.y - pParty->vPosition.y; a3.z = v8->vPosition.z - pParty->vPosition.z; Vec3_int_::Normalize(&a3.x, &a3.y, &a3.z); - DamageMonsterFromParty((8 * v0 - 8) | 4, a2, &a3); - if ( v1->WearsItem(506, 1) || v1->WearsItem(506, 0) ) + DamageMonsterFromParty((8 * uActiveCharacter - 8) | OBJECT_Player, target_id, &a3); + if ( player->WearsItem(506, 1) || player->WearsItem(506, 0) ) _42FA66_do_explosive_impact( v8->vPosition.x, v8->vPosition.y, v8->vPosition.z + v8->uActorHeight / 2, 0, 512, - v0); + uActiveCharacter); } else { - if ( v31 != v9 ) + if ( bow_idx != v9 ) { v30 = 1; v22 = 0; @@ -8001,10 +8015,11 @@ v3 = 0; goto LABEL_39; } - if ( v33 ) + + if ( laser_weapon_item_id ) { v28 = 1; - v23 = v0 + 8; + v23 = uActiveCharacter + 8; v21 = 0; v19 = 0; v17 = 102; @@ -8013,33 +8028,33 @@ { if ( v32 ) { - v12 = v1->pEquipment.uMainHand; + v12 = player->pEquipment.uMainHand; v29 = 1; _42777D_CastSpell_UseWand_ShootArrow( - *((int *)&pSpellDatas[66].field_8 + *(int *)&v1->pInventoryItems[v12-1]), - v0 - 1, + *((int *)&pSpellDatas[66].field_8 + *(int *)&player->pInventoryItems[v12-1]), + uActiveCharacter - 1, 8u, 0, - v0 + 8); - v13 = &v1->field_1F5[36 * v1->pEquipment.uMainHand + 11]; + uActiveCharacter + 8); + v13 = &player->field_1F5[36 * player->pEquipment.uMainHand + 11]; --*(int *)v13; - v14 = (char *)v1 + 36 * v1->pEquipment.uMainHand; + v14 = (char *)player + 36 * player->pEquipment.uMainHand; if ( *((int *)v14 + 128) <= 0 ) { *((int *)v14 + 124) = 0; - v1->pEquipment.uMainHand = 0; + player->pEquipment.uMainHand = 0; } LABEL_29: v34 = v3; if ( v30 == v3 ) { if ( v29 != v3 ) - return 1; + return; if ( v28 == v3 ) { - v15 = v1->pEquipment.uMainHand; - if ( v1->HasItemEquipped(EQUIP_TWO_HANDED) ) - v34 = pItemsTable->pItems[*(int *)&v1->pInventoryItems[v15-1]].uSkillType; + v15 = player->pEquipment.uMainHand; + if ( player->HasItemEquipped(EQUIP_TWO_HANDED) ) + v34 = pItemsTable->pItems[*(int *)&player->pInventoryItems[v15-1]].uSkillType; pTurnEngine->_40471C(); } else @@ -8050,7 +8065,7 @@ else { v34 = 5; - v1->PlaySound(SPEECH_50, v3); + player->PlaySound(SPEECH_50, v3); } switch ( v34 ) { @@ -8081,18 +8096,18 @@ pAudioPlayer->PlaySound(v24, v3, v3, -1, v3, v3, v3, v3); break; default: - return 1; - } - return 1; + return; + } + return; } - if ( !v31 ) + if ( !bow_idx ) { LABEL_39: - v31 = v1->GetAttackRecoveryTime(v3); + int v31 = player->GetAttackRecoveryTime(v3); if ( v31 < 30 ) v31 = 30; if ( pParty->bTurnBasedModeOn == v3 ) - v1->SetRecoveryTime((signed __int64)(flt_6BE3A4_debug_recmod1 * (double)v31 * 2.133333333333333)); + player->SetRecoveryTime((signed __int64)(flt_6BE3A4_debug_recmod1 * (double)v31 * 2.133333333333333)); goto LABEL_29; } v23 = 0; @@ -8101,14 +8116,12 @@ v30 = 1; v17 = 100; } - _42777D_CastSpell_UseWand_ShootArrow(v17, v0 - 1, v19, v21, v23); + _42777D_CastSpell_UseWand_ShootArrow(v17, uActiveCharacter - 1, v19, v21, v23); goto LABEL_29; - } - return result; } //----- (0042F184) -------------------------------------------------------- -int stru319::FindClosesActor(int a2, int a3, int a4) +int stru319::FindClosestActor(int a2, int a3, int a4) { int v4; // edi@1 stru319 *v5; // esi@1 @@ -8899,7 +8912,7 @@ int v17; // [sp-14h] [bp-1Ch]@8 PartyAction partyAction; // [sp-14h] [bp-1Ch]@20 PartyAction partyAction_; // [sp-14h] [bp-1Ch]@54 - __int16 v20; // [sp-14h] [bp-1Ch]@60 + //__int16 v20; // [sp-14h] [bp-1Ch]@60 int v21; // [sp-14h] [bp-1Ch]@68 int v22; // [sp-Ch] [bp-14h]@158 InputAction inputAction; // [sp+0h] [bp-8h]@7 @@ -8941,7 +8954,7 @@ switch ( inputAction ) { case INPUT_MoveForward: - if ( pCurrentScreen ) + if (pCurrentScreen != SCREEN_GAME) break; if (!pParty->bTurnBasedModeOn) //goto _do_move_forward; @@ -8971,7 +8984,7 @@ break; case INPUT_MoveBackwards: //__debugbreak(); - if ( pCurrentScreen ) + if (pCurrentScreen != SCREEN_GAME) break; if (!pParty->bTurnBasedModeOn) //goto _do_move_backwards; @@ -9001,7 +9014,7 @@ break; case INPUT_StrafeLeft: //__debugbreak(); - if ( pCurrentScreen ) + if (pCurrentScreen != SCREEN_GAME) break; if (!pParty->bTurnBasedModeOn) //goto _do_strafe_left; @@ -9023,7 +9036,7 @@ break; case INPUT_StrafeRight: //__debugbreak(); - if ( pCurrentScreen ) + if (pCurrentScreen != SCREEN_GAME) break; if (!pParty->bTurnBasedModeOn) //goto _do_strafe_right; @@ -9044,7 +9057,7 @@ v5->Add(partyAction); break; case INPUT_TurnLeft: - if ( pCurrentScreen ) + if (pCurrentScreen != SCREEN_GAME) break; if ( GetAsyncKeyState(VK_CONTROL) ) // strafing { @@ -9066,14 +9079,11 @@ pActionQueue->Add(partyAction_); if (uCurrentlyLoadedLevelType == LEVEL_Outdoor && pWeather->bRenderSnow) { - v20 = 10; - //goto LABEL_75; - pWeather->_4C2F0B(v20); - break; + pWeather->OnPlayerTurn(10); } break; case INPUT_TurnRight: - if ( pCurrentScreen ) + if (pCurrentScreen != SCREEN_GAME) break; if ( GetAsyncKeyState(17) ) // strafing { @@ -9083,27 +9093,24 @@ break; pTurnEngine->uActionPointsLeft -= 26; } - v21 = 4; + v21 = PARTY_StrafeRight; } else { if ( pParty->uFlags2 & 2 ) - v21 = 19; + v21 = PARTY_FastTurnRight; else - v21 = 2; + v21 = PARTY_TurnRight; } pActionQueue->Add((PartyAction)v21); if (uCurrentlyLoadedLevelType == LEVEL_Outdoor && pWeather->bRenderSnow) { - v20 = -10; -//LABEL_75: - pWeather->_4C2F0B(v20); + pWeather->OnPlayerTurn(-10); } break; case INPUT_Jump: //__debugbreak(); - if ( pCurrentScreen - || pParty->bTurnBasedModeOn) + if (pCurrentScreen != SCREEN_GAME || pParty->bTurnBasedModeOn) break; partyAction = (PartyAction)12; //goto _add_action_and_continue_; @@ -9143,7 +9150,7 @@ break; case INPUT_Combat: //__debugbreak(); - if ( !pCurrentScreen ) + if (pCurrentScreen == SCREEN_GAME) { if (pParty->bTurnBasedModeOn) { @@ -9162,7 +9169,7 @@ break; case INPUT_CastReady: //__debugbreak(); - if ( pCurrentScreen ) + if (pCurrentScreen != SCREEN_GAME) break; if (pParty->bTurnBasedModeOn && pTurnEngine->field_4 == 3) //goto LABEL_118; @@ -9181,9 +9188,10 @@ { pActionQueue = pPartyActionQueue; LABEL_120: + if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 ) { - pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)23; + pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Attack; //goto _send_message; pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0; *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0; @@ -9205,7 +9213,7 @@ break; case INPUT_Attack: //__debugbreak(); - if ( pCurrentScreen ) + if (pCurrentScreen != SCREEN_GAME) break; if (!pParty->bTurnBasedModeOn || pTurnEngine->field_4 != 3) goto LABEL_120; @@ -9213,11 +9221,11 @@ pTurnEngine->field_18 |= 8u; break; case INPUT_EventTrigger: - if ( !pCurrentScreen ) + if (pCurrentScreen == SCREEN_GAME) { if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 ) break; - pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)404; + pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Game_Action; //goto _send_message; pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0; *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0; @@ -9234,7 +9242,7 @@ v11 = 1; pMessageQueue_50CBD0->uNumMessages = 1; //LABEL_132: - pMessageQueue_50CBD0->pMessages[v11].eType = (UIMessageType)113; + pMessageQueue_50CBD0->pMessages[v11].eType = UIMSG_Escape; //_send_message: pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0; *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0; @@ -9247,7 +9255,7 @@ if ( (signed int)v11 < 40 ) //goto LABEL_132; { - pMessageQueue_50CBD0->pMessages[v11].eType = (UIMessageType)113; + pMessageQueue_50CBD0->pMessages[v11].eType = UIMSG_Escape; pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0; *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0; ++pMessageQueue_50CBD0->uNumMessages;