comparison mm7_6.cpp @ 295:640a176c030f

sub_42ECB5
author Nomad
date Tue, 19 Feb 2013 13:29:02 +0200
parents 1f0af5cac2dd
children 3dcc9d945eeb
comparison
equal deleted inserted replaced
275:250e49fef6f6 295:640a176c030f
7835 void _42ECB5_PlayerAttacksActor() 7835 void _42ECB5_PlayerAttacksActor()
7836 { 7836 {
7837 //unsigned int v0; // ebx@1 7837 //unsigned int v0; // ebx@1
7838 //Player *v1; // esi@1 7838 //Player *v1; // esi@1
7839 //bool result; // eax@1 7839 //bool result; // eax@1
7840 int v3; // edi@2 7840 //int v3; // edi@2
7841 //unsigned int v4; // eax@7 7841 //unsigned int v4; // eax@7
7842 char *v5; // eax@8 7842 char *v5; // eax@8
7843 //int v6; // ecx@9 7843 //int v6; // ecx@9
7844 //signed int v7; // eax@16 7844 //signed int v7; // eax@16
7845 Actor *v8; // edi@20 7845 //Actor *v8; // edi@20
7846 unsigned int v9; // ecx@21 7846 unsigned int v9; // ecx@21
7847 char *v10; // eax@26 7847 //char *v10; // eax@26
7848 char *v11; // eax@26 7848 char *v11; // eax@26
7849 unsigned int v12; // eax@47 7849 unsigned int v12; // eax@47
7850 char *v13; // eax@47 7850 //char *v13; // eax@47
7851 char *v14; // eax@47 7851 //char *v14; // eax@47
7852 unsigned int v15; // ebx@54 7852 //unsigned int v15; // ebx@54
7853 int v16; // [sp-10h] [bp-4Ch]@24 7853 //int v16; // [sp-10h] [bp-4Ch]@24
7854 int v17; // [sp-10h] [bp-4Ch]@44 7854 //int v17; // [sp-10h] [bp-4Ch]@44
7855 unsigned int v18; // [sp-Ch] [bp-48h]@24 7855 //unsigned int v18; // [sp-Ch] [bp-48h]@24
7856 unsigned int v19; // [sp-Ch] [bp-48h]@44 7856 //unsigned int v19; // [sp-Ch] [bp-48h]@44
7857 __int16 v20; // [sp-8h] [bp-44h]@24 7857 //__int16 v20; // [sp-8h] [bp-44h]@24
7858 __int16 v21; // [sp-8h] [bp-44h]@44 7858 //__int16 v21; // [sp-8h] [bp-44h]@44
7859 int v22; // [sp-4h] [bp-40h]@24 7859 //int v22; // [sp-4h] [bp-40h]@24
7860 int v23; // [sp-4h] [bp-40h]@44 7860 //int v23; // [sp-4h] [bp-40h]@44
7861 SoundID v24; // [sp-4h] [bp-40h]@58 7861 SoundID v24; // [sp-4h] [bp-40h]@58
7862 Vec3_int_ a3; // [sp+Ch] [bp-30h]@19 7862 //Vec3_int_ a3; // [sp+Ch] [bp-30h]@19
7863 //unsigned int a2; // [sp+18h] [bp-24h]@20 7863 //unsigned int a2; // [sp+18h] [bp-24h]@20
7864 //unsigned int v27; // [sp+1Ch] [bp-20h]@1 7864 //unsigned int v27; // [sp+1Ch] [bp-20h]@1
7865 int v28; // [sp+20h] [bp-1Ch]@9 7865 //int v28; // [sp+20h] [bp-1Ch]@9
7866 //unsigned int *v28b; 7866 //unsigned int *v28b;
7867 int v29; // [sp+24h] [bp-18h]@16 7867 //int v29; // [sp+24h] [bp-18h]@16
7868 int v30; // [sp+28h] [bp-14h]@16 7868 //int v30; // [sp+28h] [bp-14h]@16
7869 //int v31; // [sp+2Ch] [bp-10h]@4 7869 //int v31; // [sp+2Ch] [bp-10h]@4
7870 int v32; // [sp+30h] [bp-Ch]@7 7870 //int v32; // [sp+30h] [bp-Ch]@7
7871 //int v33; // [sp+34h] [bp-8h]@7 7871 //int v33; // [sp+34h] [bp-8h]@7
7872 int v34; // [sp+38h] [bp-4h]@17 7872 //int v34; // [sp+38h] [bp-4h]@17
7873 7873
7874 //v0 = uActiveCharacter; 7874 //v0 = uActiveCharacter;
7875 //v27 = 6972 * uActiveCharacter; 7875 //v27 = 6972 * uActiveCharacter;
7876 //v1 = &pParty->pPlayers[uActiveCharacter-1]; 7876 //v1 = &pParty->pPlayers[uActiveCharacter-1];
7877 //result = pParty->pPlayers[uActiveCharacter-1].CanAct(); 7877 //result = pParty->pPlayers[uActiveCharacter-1].CanAct();
7878 auto player = &pParty->pPlayers[uActiveCharacter - 1]; 7878 auto player = &pParty->pPlayers[uActiveCharacter - 1];
7879 if (!player->CanAct()) 7879 if (!player->CanAct())
7880 return; 7880 return;
7881 7881
7882 pStru277->_427D48(uActiveCharacter); 7882 pStru277->_427D48(uActiveCharacter);
7883 v3 = 0; 7883 //v3 = 0;
7884 if (pParty->Invisible()) 7884 if (pParty->Invisible())
7885 pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Reset(); 7885 pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Reset();
7886 7886
7887 //v31 = player->pEquipment.uBow; 7887 //v31 = player->pEquipment.uBow;
7888 int bow_idx = player->pEquipment.uBow; 7888 int bow_idx = player->pEquipment.uBow;
7889 if (bow_idx && player->pInventoryItems[bow_idx - 1].Broken()) 7889 if (bow_idx && player->pInventoryItems[bow_idx - 1].Broken())
7890 bow_idx = 0; 7890 bow_idx = 0;
7891 7891
7892 v32 = 0; 7892 //v32 = 0;
7893 int wand_item_id = 0;
7893 //v33 = 0; 7894 //v33 = 0;
7894 //v4 = v1->pEquipment.uMainHand; 7895 //v4 = v1->pEquipment.uMainHand;
7895 int laser_weapon_item_id = 0; 7896 int laser_weapon_item_id = 0;
7896 7897
7897 int main_hand_idx = player->pEquipment.uMainHand; 7898 int main_hand_idx = player->pEquipment.uMainHand;
7901 //v5 = (char *)v1 + 36 * v4; 7902 //v5 = (char *)v1 + 36 * v4;
7902 if (!item->Broken()) 7903 if (!item->Broken())
7903 { 7904 {
7904 //v28b = &v1->pInventoryItems[v4].uItemID; 7905 //v28b = &v1->pInventoryItems[v4].uItemID;
7905 //v6 = v1->pInventoryItems[v4].uItemID;//*((int *)v5 + 124); 7906 //v6 = v1->pInventoryItems[v4].uItemID;//*((int *)v5 + 124);
7906 if (pItemsTable->pItems[item->uItemID].uEquipType == EQUIP_C) 7907 if (pItemsTable->pItems[item->uItemID].uEquipType == EQUIP_WAND)
7907 { 7908 {
7908 if (item->_bonus_type <= 0) 7909 if (item->uNumCharges <= 0)
7909 player->pEquipment.uMainHand = 0; 7910 player->pEquipment.uMainHand = 0; // wand discharged - unequip
7910 else 7911 else
7911 v32 = item->uItemID;//*((int *)v5 + 124); 7912 wand_item_id = item->uItemID;//*((int *)v5 + 124);
7912 } 7913 }
7913 else if (item->uItemID == ITEM_BLASTER || item->uItemID == ITEM_LASER_RIFLE) 7914 else if (item->uItemID == ITEM_BLASTER || item->uItemID == ITEM_LASER_RIFLE)
7914 laser_weapon_item_id = item->uItemID;//*((int *)v5 + 124); 7915 laser_weapon_item_id = item->uItemID;//*((int *)v5 + 124);
7915 } 7916 }
7916 } 7917 }
7917 7918
7918 v30 = 0; 7919 //v30 = 0;
7919 v29 = 0; 7920 //v29 = 0;
7920 v28 = 0; 7921 //v28 = 0;
7921 //v7 = pMouse->uPointingObjectID; 7922 //v7 = pMouse->uPointingObjectID;
7922 7923
7923 int target_pid = pMouse->uPointingObjectID; 7924 int target_pid = pMouse->uPointingObjectID;
7924 int target_type = target_pid & 7, 7925 int target_type = target_pid & 7,
7925 target_id = target_pid >> 3; 7926 target_id = target_pid >> 3;
7927 { 7928 {
7928 target_pid = stru_50C198.FindClosestActor(5120, 0, 0); 7929 target_pid = stru_50C198.FindClosestActor(5120, 0, 0);
7929 target_type = target_pid & 7; 7930 target_type = target_pid & 7;
7930 target_id = target_pid >> 3; 7931 target_id = target_pid >> 3;
7931 } 7932 }
7932 7933
7933 7934 auto actor = &pActors[target_id];
7934 a3.z = 0; 7935 int actor_distance = 0;
7935 a3.y = 0;
7936 a3.x = 0;
7937 if (target_type == OBJECT_Actor) 7936 if (target_type == OBJECT_Actor)
7938 { 7937 {
7939 //a2 = target_id; 7938 int distance_x = actor->vPosition.x - pParty->vPosition.x,
7940 v8 = &pActors[target_id]; 7939 distance_y = actor->vPosition.y - pParty->vPosition.y,
7941 int distance_x = v8->vPosition.x - pParty->vPosition.x, 7940 distance_z = actor->vPosition.z - pParty->vPosition.z;
7942 distance_y = v8->vPosition.y - pParty->vPosition.y, 7941 actor_distance = integer_sqrt(distance_x * distance_x + distance_y * distance_y + distance_z * distance_z) - actor->uActorRadius;
7943 distance_z = v8->vPosition.z - pParty->vPosition.z; 7942 if (actor_distance < 0)
7944 v34 = sub_452A9E(distance_x * distance_x + distance_y * distance_y + distance_z * distance_z) - v8->uActorRadius; 7943 actor_distance = 0;
7945 if ( v34 >= 0 ) 7944 }
7945
7946 bool shooting_bow = false,
7947 shotting_laser = false,
7948 shooting_wand = false;
7949 if (laser_weapon_item_id)
7950 {
7951 shotting_laser = true;
7952 _42777D_CastSpell_UseWand_ShootArrow(102, uActiveCharacter - 1, 0, 0, uActiveCharacter + 8);
7953 }
7954 else if (wand_item_id)
7955 {
7956 shooting_wand = true;
7957
7958 int main_hand_idx = player->pEquipment.uMainHand;
7959 _42777D_CastSpell_UseWand_ShootArrow(*((int *)&pSpellDatas[66].field_8 + player->pInventoryItems[main_hand_idx - 1].uItemID), uActiveCharacter - 1, 8, 0, uActiveCharacter + 8);
7960
7961 if (!--player->pInventoryItems[main_hand_idx - 1].uNumCharges)
7962 player->pEquipment.uMainHand = 0;
7963 }
7964 else if (target_type == OBJECT_Actor)
7965 {
7966 if (actor_distance <= 407.2)
7967 {
7968 Vec3_int_ a3;
7969 a3.x = actor->vPosition.x - pParty->vPosition.x;
7970 a3.y = actor->vPosition.y - pParty->vPosition.y;
7971 a3.z = actor->vPosition.z - pParty->vPosition.z;
7972 Vec3_int_::Normalize(&a3.x, &a3.y, &a3.z);
7973
7974 DamageMonsterFromParty((8 * uActiveCharacter - 8) | OBJECT_Player, target_id, &a3);
7975 if (player->WearsItem(506, 1) || player->WearsItem(506, 0))
7976 _42FA66_do_explosive_impact(
7977 actor->vPosition.x,
7978 actor->vPosition.y,
7979 actor->vPosition.z + actor->uActorHeight / 2,
7980 0, 512, uActiveCharacter);
7981 }
7982 else if (bow_idx)
7983 {
7984 shooting_bow = true;
7985
7986 _42777D_CastSpell_UseWand_ShootArrow(100, uActiveCharacter - 1, 0, 0, 0);
7987 if (!pParty->bTurnBasedModeOn)
7946 { 7988 {
7947 v9 = 0; 7989 int recovery = player->GetAttackRecoveryTime(0);
7990 if (recovery < 30)
7991 recovery = 30;
7992 player->SetRecoveryTime(flt_6BE3A4_debug_recmod1 * (double)recovery * 2.133333333333333);
7948 } 7993 }
7949 else
7950 {
7951 v9 = 0;
7952 v34 = 0;
7953 }
7954 if ( laser_weapon_item_id != v9 )
7955 {
7956 v28 = 1;
7957 v22 = uActiveCharacter + 8;
7958 v20 = v9;
7959 v18 = v9;
7960 v16 = 102;
7961 LABEL_34:
7962 _42777D_CastSpell_UseWand_ShootArrow(v16, uActiveCharacter - 1, v18, v20, v22);
7963 LABEL_28:
7964 v3 = 0;
7965 goto LABEL_29;
7966 }
7967 if ( v32 != v9 )
7968 {
7969 v29 = 1;
7970 _42777D_CastSpell_UseWand_ShootArrow(
7971 *((int *)&pSpellDatas[66].field_8
7972 + *(int *)(&stru_AA1058[3].pSounds[36 * *(int *)&pParty->pArtifactsFound[6972 * uActiveCharacter + 22] + 41048] + 6972 * uActiveCharacter)),
7973 uActiveCharacter - 1,
7974 8u,
7975 v9,
7976 uActiveCharacter + 8);
7977 v10 = &player->field_1F5[36 * player->pEquipment.uMainHand + 11];
7978 --*(int *)v10;
7979 v11 = (char *)player + 36 * player->pEquipment.uMainHand;
7980 if ( *((int *)v11 + 128) <= 0 )
7981 {
7982 *((int *)v11 + 124) = 0;
7983 player->pEquipment.uMainHand = 0;
7984 }
7985 goto LABEL_28;
7986 }
7987 if ( (double)v34 <= 407.2 )
7988 {
7989 a3.x = v8->vPosition.x - pParty->vPosition.x;
7990 a3.y = v8->vPosition.y - pParty->vPosition.y;
7991 a3.z = v8->vPosition.z - pParty->vPosition.z;
7992 Vec3_int_::Normalize(&a3.x, &a3.y, &a3.z);
7993 DamageMonsterFromParty((8 * uActiveCharacter - 8) | OBJECT_Player, target_id, &a3);
7994 if ( player->WearsItem(506, 1) || player->WearsItem(506, 0) )
7995 _42FA66_do_explosive_impact(
7996 v8->vPosition.x,
7997 v8->vPosition.y,
7998 v8->vPosition.z + v8->uActorHeight / 2,
7999 0,
8000 512,
8001 uActiveCharacter);
8002 }
8003 else
8004 {
8005 if ( bow_idx != v9 )
8006 {
8007 v30 = 1;
8008 v22 = 0;
8009 v20 = 0;
8010 v18 = 0;
8011 v16 = 100;
8012 goto LABEL_34;
8013 }
8014 }
8015 v3 = 0;
8016 goto LABEL_39;
8017 } 7994 }
8018 7995 }
8019 if ( laser_weapon_item_id ) 7996 else
7997 {
7998 if (bow_idx)
8020 { 7999 {
8021 v28 = 1; 8000 shooting_bow = true;
8022 v23 = uActiveCharacter + 8; 8001 _42777D_CastSpell_UseWand_ShootArrow(100, uActiveCharacter - 1, 0, 0, 0);
8023 v21 = 0;
8024 v19 = 0;
8025 v17 = 102;
8026 } 8002 }
8027 else 8003 else
8028 { 8004 {
8029 if ( v32 ) 8005 if (!pParty->bTurnBasedModeOn)
8030 { 8006 {
8031 v12 = player->pEquipment.uMainHand; 8007 int recovery = player->GetAttackRecoveryTime(0);
8032 v29 = 1; 8008 if (recovery < 30 )
8033 _42777D_CastSpell_UseWand_ShootArrow( 8009 recovery = 30;
8034 *((int *)&pSpellDatas[66].field_8 + *(int *)&player->pInventoryItems[v12-1]), 8010 player->SetRecoveryTime((signed __int64)(flt_6BE3A4_debug_recmod1 * (double)recovery * 2.133333333333333));
8035 uActiveCharacter - 1,
8036 8u,
8037 0,
8038 uActiveCharacter + 8);
8039 v13 = &player->field_1F5[36 * player->pEquipment.uMainHand + 11];
8040 --*(int *)v13;
8041 v14 = (char *)player + 36 * player->pEquipment.uMainHand;
8042 if ( *((int *)v14 + 128) <= 0 )
8043 {
8044 *((int *)v14 + 124) = 0;
8045 player->pEquipment.uMainHand = 0;
8046 }
8047 LABEL_29:
8048 v34 = v3;
8049 if ( v30 == v3 )
8050 {
8051 if ( v29 != v3 )
8052 return;
8053 if ( v28 == v3 )
8054 {
8055 v15 = player->pEquipment.uMainHand;
8056 if ( player->HasItemEquipped(EQUIP_TWO_HANDED) )
8057 v34 = pItemsTable->pItems[*(int *)&player->pInventoryItems[v15-1]].uSkillType;
8058 pTurnEngine->_40471C();
8059 }
8060 else
8061 {
8062 v34 = 7;
8063 }
8064 }
8065 else
8066 {
8067 v34 = 5;
8068 player->PlaySound(SPEECH_50, v3);
8069 }
8070 switch ( v34 )
8071 {
8072 case 0:
8073 v24 = (SoundID)81;
8074 goto LABEL_66;
8075 case 1:
8076 v24 = (SoundID)84;
8077 goto LABEL_66;
8078 case 2:
8079 v24 = (SoundID)85;
8080 goto LABEL_66;
8081 case 3:
8082 v24 = (SoundID)78;
8083 goto LABEL_66;
8084 case 4:
8085 v24 = (SoundID)80;
8086 goto LABEL_66;
8087 case 5:
8088 v24 = (SoundID)71;
8089 goto LABEL_66;
8090 case 6:
8091 v24 = (SoundID)83;
8092 goto LABEL_66;
8093 case 7:
8094 v24 = (SoundID)67;
8095 LABEL_66:
8096 pAudioPlayer->PlaySound(v24, v3, v3, -1, v3, v3, v3, v3);
8097 break;
8098 default:
8099 return;
8100 }
8101 return;
8102 } 8011 }
8103 if ( !bow_idx )
8104 {
8105 LABEL_39:
8106 int v31 = player->GetAttackRecoveryTime(v3);
8107 if ( v31 < 30 )
8108 v31 = 30;
8109 if ( pParty->bTurnBasedModeOn == v3 )
8110 player->SetRecoveryTime((signed __int64)(flt_6BE3A4_debug_recmod1 * (double)v31 * 2.133333333333333));
8111 goto LABEL_29;
8112 }
8113 v23 = 0;
8114 v21 = 0;
8115 v19 = 0;
8116 v30 = 1;
8117 v17 = 100;
8118 } 8012 }
8119 _42777D_CastSpell_UseWand_ShootArrow(v17, uActiveCharacter - 1, v19, v21, v23); 8013 }
8120 goto LABEL_29; 8014
8015
8016 int v34 = 0;
8017 if (shooting_wand)
8018 return;
8019 else if (shooting_bow)
8020 {
8021 v34 = 5;
8022 player->PlaySound(SPEECH_50, 0);
8023 }
8024 if (shotting_laser)
8025 v34 = 7;
8026 else
8027 {
8028 int main_hand_idx = player->pEquipment.uMainHand;
8029 if (player->HasItemEquipped(EQUIP_TWO_HANDED))
8030 v34 = pItemsTable->pItems[*(int *)&player->pInventoryItems[main_hand_idx - 1]].uSkillType;
8031 pTurnEngine->_40471C();
8032 }
8033
8034 switch (v34)
8035 {
8036 case 0: pAudioPlayer->PlaySound(SOUND_81, 0, 0, -1, 0, 0, 0, 0); break;
8037 case 1: pAudioPlayer->PlaySound(SOUND_84, 0, 0, -1, 0, 0, 0, 0); break;
8038 case 2: pAudioPlayer->PlaySound(SOUND_85, 0, 0, -1, 0, 0, 0, 0); break;
8039 case 3: pAudioPlayer->PlaySound(SOUND_78, 0, 0, -1, 0, 0, 0, 0); break;
8040 case 4: pAudioPlayer->PlaySound(SOUND_80, 0, 0, -1, 0, 0, 0, 0); break;
8041 case 5: pAudioPlayer->PlaySound(SOUND_71, 0, 0, -1, 0, 0, 0, 0); break;
8042 case 6: pAudioPlayer->PlaySound(SOUND_83, 0, 0, -1, 0, 0, 0, 0); break;
8043 case 7: pAudioPlayer->PlaySound(SOUND_67, 0, 0, -1, 0, 0, 0, 0); break;
8044 }
8121 } 8045 }
8122 8046
8123 //----- (0042F184) -------------------------------------------------------- 8047 //----- (0042F184) --------------------------------------------------------
8124 int stru319::FindClosestActor(int a2, int a3, int a4) 8048 int stru319::FindClosestActor(int pick_depth, int a3, int a4)
8125 { 8049 {
8126 int v4; // edi@1 8050 int v4; // edi@1
8127 stru319 *v5; // esi@1 8051 stru319 *v5; // esi@1
8128 int v6; // eax@2 8052 int v6; // eax@2
8129 int v7; // eax@4 8053 int v7; // eax@4
8159 if ( pRenderer->pRenderD3D ) 8083 if ( pRenderer->pRenderD3D )
8160 { 8084 {
8161 v6 = a3 != 0; 8085 v6 = a3 != 0;
8162 if ( a4 ) 8086 if ( a4 )
8163 LOBYTE(v6) = v6 | 8; 8087 LOBYTE(v6) = v6 | 8;
8164 v7 = pGame->pVisInstance->_4C1944(OBJECT_Actor, a2, v6, 657456, -1); 8088 v7 = pGame->pVisInstance->PickClosestActor(OBJECT_Actor, pick_depth, v6, 657456, -1);
8165 if ( v7 != -1 ) 8089 if ( v7 != -1 )
8166 return (unsigned __int16)v7; 8090 return (unsigned __int16)v7;
8091 else return 0;
8167 } 8092 }
8168 else 8093 else
8169 { 8094 {
8170 v30 = 0; 8095 v30 = 0;
8171 if ( pRenderer->pActiveZBuffer ) 8096 if ( pRenderer->pActiveZBuffer )
8199 && v13 != 19 8124 && v13 != 19
8200 && v13 != 17 8125 && v13 != 17
8201 && (!a3 || pActors[(unsigned int)v11 >> 3].GetActorsRelation(0)) ) 8126 && (!a3 || pActors[(unsigned int)v11 >> 3].GetActorsRelation(0)) )
8202 { 8127 {
8203 if ( (!a4 || MonsterStats::BelongsToSupertype(v12->pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD)) 8128 if ( (!a4 || MonsterStats::BelongsToSupertype(v12->pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD))
8204 && v22 <= a2 << 16 ) 8129 && v22 <= pick_depth << 16 )
8205 { 8130 {
8206 v14 = 0; 8131 v14 = 0;
8207 if ( v10 > 0 ) 8132 if ( v10 > 0 )
8208 { 8133 {
8209 do 8134 do