changeset 1930:df4e27f2a541

Merge
author Grumpy7
date Wed, 23 Oct 2013 19:13:07 -0700
parents 4cce1e24b7e7 (diff) 3eb0c4f3d899 (current diff)
children 2e3d08ff3309 68f2d9d3a1d9
files MM7_manifest.rc Might and Magic Trilogy.rc mm7_1.cpp
diffstat 1 files changed, 163 insertions(+), 235 deletions(-) [+]
line wrap: on
line diff
--- a/Actor.cpp	Wed Oct 23 15:46:05 2013 +0200
+++ b/Actor.cpp	Wed Oct 23 19:13:07 2013 -0700
@@ -957,7 +957,6 @@
   float v31; // st7@45
   float v32; // st6@45
   float v33; // st7@45
-  AIDirection *result; // eax@48
   Vec3_int_ v37; // [sp-10h] [bp-5Ch]@15
   AIDirection v41; // [sp+14h] [bp-38h]@46
   float outy2; // [sp+38h] [bp-14h]@33
@@ -2876,7 +2875,6 @@
 	int v45; // eax@192
 	unsigned __int8 v46; // cl@197
 	signed int v47; // st7@206
-	AIDirection *v57; // eax@246
 	uint v58; // st7@246
 	unsigned int v65; // [sp-10h] [bp-C0h]@144
 	int v70; // [sp-10h] [bp-C0h]@213
@@ -3429,22 +3427,15 @@
 //----- (00408B54) --------------------------------------------------------
 unsigned int SearchActorByID(unsigned int *pTotalActors, unsigned int a2)
 {
-  unsigned int v2; // edi@1
-  unsigned int *v3; // esi@1
   int v4; // eax@1
   unsigned int v5; // ebx@1
-  unsigned int v6; // edx@1
 
-  v2 = a2;
-  v3 = pTotalActors;
   v4 = GetAlertStatus();
-  v5 = 0;
-  *v3 = 0;
-  v6 = pActors[v2].uAttributes;
-  if ( (v6 & 0x100000) == v4 )
+  *pTotalActors = 0;
+  if ( (pActors[a2].uAttributes & 0x100000) == GetAlertStatus() )
   {
-    *v3 = 1;
-    if ( pActors[v2].IsNotAlive() == 1 )
+    *pTotalActors = 1;
+    if ( pActors[a2].IsNotAlive() == 1 )
       v5 = 1;
   }
   return v5;
@@ -3452,114 +3443,66 @@
 //----- (00408AE7) --------------------------------------------------------
 unsigned int SearchActorByGroup(unsigned int *pTotalActors, unsigned int uGroup)
 {
-  unsigned int *v2; // esi@1
-  signed int v3; // ebx@1
-  Actor *v4; // edi@2
-  int v5; // eax@3
-  unsigned int v7; // [sp+8h] [bp-Ch]@1
   int v8; // [sp+Ch] [bp-8h]@1
   unsigned int v9; // [sp+10h] [bp-4h]@1
+  Actor* v4;
 
-  v7 = uGroup;
-  v2 = pTotalActors;
-  v3 = 0;
   v8 = GetAlertStatus();
-  *v2 = 0;
+  *pTotalActors = 0;
   v9 = 0;
-  if ( (signed int)uNumActors > 0 )
+  for ( uint i = 0; i < uNumActors; i++)
   {
-    v4 = pActors.data();//[0].uGroup;
-    do
+    v4 = &pActors[i];
+    if ( (v4->uAttributes & 0x100000) == v8 && v4->uGroup == uGroup)
     {
-	  v5 = v4->uAttributes;
-      if ( (v5 & 0x100000) == v8 )
-      {
-		if ( v4->uGroup == v7 )
-        {
-          ++*v2;
-          if ( v4->IsNotAlive() == 1 )
-            ++v9;
-        }
-      }
-      ++v3;
-      ++v4;
+      ++*pTotalActors;
+      if ( v4->IsNotAlive() == 1 )
+        ++v9;
     }
-    while ( v3 < (signed int)uNumActors );
   }
   return v9;
 }
 //----- (00408A7E) --------------------------------------------------------
 unsigned int SearchActorByMonsterID(unsigned int *pTotalActors, int uMonsterID)
 {
-  unsigned int *v2; // esi@1
-  signed int v3; // ebx@1
   Actor *v4; // edi@2
-  int v5; // eax@3
-  int v7; // [sp+8h] [bp-Ch]@1
   int v8; // [sp+Ch] [bp-8h]@1
   unsigned int v9; // [sp+10h] [bp-4h]@1
 
-  v7 = uMonsterID;
-  v2 = pTotalActors;
-  v3 = 0;
   v8 = GetAlertStatus();
-  *v2 = 0;
+  *pTotalActors = 0;
   v9 = 0;
-  if ( (signed int)uNumActors > 0 )
+  for ( uint i = 0; i < uNumActors; i++)
   {
-    v4 = pActors.data();//[0].pMonsterInfo.uID;
-    do
+    v4 = &pActors[i];
+    if ( (v4->uAttributes & 0x100000) == v8 && v4->pMonsterInfo.field_33 == uMonsterID)
     {
-	  v5 = v4->uAttributes;                // actor::attributes
-      if ( (v5 & 0x100000) == v8 )
-      {
-		if ( v4->pMonsterInfo.field_33 == v7 )
-        {
-          ++*v2;
-          if ( v4->IsNotAlive() == 1 )
-            ++v9;
-        }
-      }
-      ++v3;
-      ++v4;
+      ++*pTotalActors;
+      if ( v4->IsNotAlive() == 1 )
+        ++v9;
     }
-    while ( v3 < (signed int)uNumActors );
   }
   return v9;
 }
 //----- (00408A27) --------------------------------------------------------
 unsigned int SearchAliveActors(unsigned int *pTotalActors)
 {
-  unsigned int *v1; // esi@1
   int v2; // eax@1
   unsigned int v3; // ebp@1
-  signed int v4; // ebx@1
   Actor *v5; // edi@2
-  unsigned int v6; // eax@3
-  int v8; // [sp+Ch] [bp-4h]@1
 
-  v1 = pTotalActors;
   v2 = GetAlertStatus();
   v3 = 0;
-  v4 = 0;
-  *v1 = 0;
-  v8 = v2;
-  if ( (signed int)uNumActors > 0 )
+  *pTotalActors = 0;
+  for ( uint i = 0; i < uNumActors; i++)
   {
-    v5 = pActors.data();
-    do
+    v5 = &pActors[i];
+    if ( (v5->uAttributes & 0x100000) == v2 )
     {
-      v6 = v5->uAttributes;
-      if ( (v6 & 0x100000) == v8 )
-      {
-        ++*v1;
-        if ( v5->IsNotAlive() == 1 )
-          ++v3;
-      }
-      ++v4;
-      ++v5;
+      ++*pTotalActors;
+      if ( v5->IsNotAlive() == 1 )
+        ++v3;
     }
-    while ( v4 < (signed int)uNumActors );
   }
   return v3;
 }
@@ -3692,43 +3635,31 @@
   if ( PID_TYPE(a1) == OBJECT_Item)
   {
     v4 = &pSpriteObjects[PID_ID(a1)];
-    //uDamageAmount = (int)v4;
     v61 = v4->field_60_distance_related_prolly_lod;
     a1 = v4->spell_caster_pid;
-    //v54 = v4->field_58_pid;
   }
-  //v5 = a1 & 7;
-  //uPlayerID = a1 >> 3;
   if (PID_TYPE(a1) != OBJECT_Player)
     return;
 
   assert(PID_ID(abs(a1)) < 4);
   auto player = &pParty->pPlayers[PID_ID(a1)];
   pMonster = &pActors[uActorID_Monster_];
-  //uPlayerID = pMonster->IsAlive();
   if (pMonster->IsNotAlive())
     return;
 
   pMonster->uAttributes |= 0xC000;
   if ( pMonster->uAIState == Fleeing )
     pMonster->uAttributes |= 0x20000u;
-  //v57 = 0;
-  //v53 = 0;
-  //v58 = 0;
   bool hit_will_stun = false,
        hit_will_paralyze = false;
   if ( !v4 )
   {
-    //v51 = (unsigned __int64 *)player->pEquipment.uMainHand;
     int main_hand_idx = player->pEquipment.uMainHand;
     v59 = 1;
     if ( player->HasItemEquipped(EQUIP_MAIN_HAND) )
     {
       auto main_hand_skill = player->GetMainHandItem()->GetPlayerSkillType();
-      //v55 = pItemsTable->pItems[player->pInventoryItems[main_hand_idx - 1].uItemID].uSkillType;
-      //v28 = SkillToMastery(player->pActiveSkills[v55]);
       auto main_hand_mastery = SkillToMastery(player->pActiveSkills[main_hand_skill]);
-      //uDamageAmount = v28;
       switch (main_hand_skill)
       {
         case PLAYER_SKILL_STAFF:
@@ -3755,157 +3686,154 @@
     }
     v50 = pMonster->pMonsterInfo.uID;
     a2 = 4;
-    //v27 = player->CalculateMeleeDamageTo(0, 0, v50);
     uDamageAmount = player->CalculateMeleeDamageTo(false, false, v50);
-    //if ( !v57 )
-      goto LABEL_67;
-    //goto LABEL_69;
+    if ( !stru_50C198.PlayerHitOrMiss(player, pMonster, v61, a4) )
+    {
+      player->PlaySound(SPEECH_52, 0);
+      return;
+    }
   }
-
-
-  v19 = v4->spell_id == SPELL_DARK_SOULDRINKER;
-  v61 = v4->field_60_distance_related_prolly_lod;
-  if ( !v19 )
+  else
   {
-    //v9 = (SpriteObject *)uDamageAmount;
-	v50 = pParty->vPosition.x - v4->vPosition.x;
-    //v55 = abs(v50);
-    pMonsterName = (char *)(pParty->vPosition.y - v4->vPosition.y);
-    //v51 = (unsigned __int64 *)abs((int)pMonsterName);
-    pPlayerName = (char *)(pParty->vPosition.z - v4->vPosition.z);
-    v52 = abs((int)pPlayerName);
-    v61 = abs(v50);
-    v10 = abs(v50);
-    v11 = (int)abs((int)pMonsterName);
-    v12 = v52;
-    if ( v10 < v11)
+    v19 = v4->spell_id == SPELL_DARK_SOULDRINKER;
+    v61 = v4->field_60_distance_related_prolly_lod;
+    if ( !v19 )
+    {
+	    v50 = pParty->vPosition.x - v4->vPosition.x;
+      pMonsterName = (char *)(pParty->vPosition.y - v4->vPosition.y);
+      pPlayerName = (char *)(pParty->vPosition.z - v4->vPosition.z);
+      v52 = abs((int)pPlayerName);
+      v61 = abs(v50);
+      v10 = abs(v50);
+      v11 = (int)abs((int)pMonsterName);
+      v12 = v52;
+      if ( v10 < v11)
+      {
+        v10 = (int)v11;
+        v11 = v10;
+      }
+      if ( v10 < v52 )
+      {
+        v13 = v10;
+        v10 = v52;
+        v12 = v13;
+      }
+      if ( v11 < (signed int)v12 )
+      {
+        v14 = v12;
+        v12 = v11;
+        v11 = v14;
+      }
+      v61 = ((unsigned int)(11 * v11) >> 5) + (v12 >> 2) + v10;
+      if ( v61 >= 2560 )
+      {
+        if ( v61 >= 5120 && !(BYTE1(pMonster->uAttributes) & 4) )
+          return;
+        v61 = 2;
+      }
+      else
+      {
+        v61 = 1;
+      }
+    }
+
+    switch (v4->spell_id)
     {
-      v10 = (int)v11;
-      v11 = v10;
-    }
-    if ( v10 < v52 )
-    {
-      v13 = v10;
-      v10 = v52;
-      v12 = v13;
+      case SPELL_LASER_PROJECTILE:
+        v16 = player->pActiveSkills[7];
+        v61 = 1;
+        if ( (signed int)SkillToMastery(v16) >= 3 )
+          a4 = player->pActiveSkills[7] & 0x3F;
+        a2 = 4;
+        uDamageAmount = player->CalculateMeleeDamageTo(true, true, 0);
+        if ( !stru_50C198.PlayerHitOrMiss(player, pMonster, v61, a4) )
+        {
+          player->PlaySound(SPEECH_52, 0);
+          return;
+        }
+        break;
+      case SPELL_101:
+        a2 = 0;
+        v18 = player->CalculateRangedDamageTo(0);
+        v19 = HIDWORD(pMonster->pActorBuffs[15].uExpireTime) == 0;
+        v20 = SHIDWORD(pMonster->pActorBuffs[15].uExpireTime) < 0;
+        uDamageAmount = v18;
+        if ( !v20 && (!(v20 | v19) || LODWORD(pMonster->pActorBuffs[15].uExpireTime)) )
+          uDamageAmount >>= 1;
+        v59 = 1;
+        if ( !stru_50C198.PlayerHitOrMiss(player, pMonster, v61, a4) )
+        {
+          player->PlaySound(SPEECH_52, 0);
+          return;
+        }
+        break;
+      case SPELL_EARTH_BLADES:
+        a4 = 5 * v4->spell_level;
+        a2 = player->GetSpellSchool(0x27u);
+        v21 = v4->spell_level;
+        v50 = pMonster->sCurrentHP;
+        pMonsterName = (char *)v4->spell_skill;
+        v22 = _43AFE3_calc_spell_damage(39, v21, v4->spell_skill, v50);
+        v23 = HIDWORD(pMonster->pActorBuffs[15].uExpireTime) == 0;
+        v24 = SHIDWORD(pMonster->pActorBuffs[15].uExpireTime) < 0;
+        uDamageAmount = v22;
+        if ( !v24 && (!(v24 | v23) || LODWORD(pMonster->pActorBuffs[15].uExpireTime)) )
+          uDamageAmount >>= 1;
+        v59 = 0;
+        if ( !stru_50C198.PlayerHitOrMiss(player, pMonster, v61, a4) )
+        {
+          player->PlaySound(SPEECH_52, 0);
+          return;
+        }
+        break;
+      case SPELL_EARTH_STUN:
+        uDamageAmount = 0;
+        a2 = 4;
+        hit_will_stun = 1;
+        if ( !stru_50C198.PlayerHitOrMiss(player, pMonster, v61, a4) )
+        {
+          player->PlaySound(SPEECH_52, 0);
+          return;
+        }
+        break;
+      case SPELL_BOW_ARROW:
+        v50 = pMonster->word_000086_some_monster_id;
+        a2 = 4;
+        uDamageAmount = player->CalculateRangedDamageTo(v50);
+        if ( pMonster->pActorBuffs[ACTOR_BUFF_SHIELD].uExpireTime > 0 )
+          uDamageAmount /= 2;
+        v59 = 1;
+        if ( v4->stru_24.uItemID != 0 && v4->stru_24.uSpecEnchantmentType == 3 )  //of carnage
+        {
+          a2 = 0;
+        }
+        else if ( !stru_50C198.PlayerHitOrMiss(player, pMonster, v61, a4) )
+        {
+          player->PlaySound(SPEECH_52, 0);
+          return;
+        }
+        break;
+
+      default:
+        a2 = player->GetSpellSchool(v4->spell_id);
+        v25 = v4->spell_level;
+        v26 = v4->spell_id;
+        v50 = pMonster->sCurrentHP;
+        pMonsterName = (char *)v4->spell_skill;
+        v59 = 0;
+        uDamageAmount = _43AFE3_calc_spell_damage(v26, v25, v4->spell_skill, v50);
+        break;
     }
-    if ( v11 < (signed int)v12 )
-    {
-      v14 = v12;
-      v12 = v11;
-      v11 = v14;
-    }
-    //uPlayerID = ((unsigned int)(11 * v11) >> 5) + (v12 >> 2) + v10;
-    v61 = ((unsigned int)(11 * v11) >> 5) + (v12 >> 2) + v10;
-    if ( v61 >= 2560 )
-    {
-      if ( v61 >= 5120 && !(BYTE1(pMonster->uAttributes) & 4) )
-        return;
-      v61 = 2;
-    }
-    else
-    {
-      v61 = 1;
-    }
-    //v4 = (SpriteObject *)uDamageAmount;
   }
 
-  v15 = v4->spell_id;
-  if ( v15 == SPELL_LASER_PROJECTILE )
-  {
-    v16 = player->pActiveSkills[7];
-    v61 = 1;
-    if ( (signed int)SkillToMastery(v16) >= 3 )
-      a4 = player->pActiveSkills[7] & 0x3F;
-    a2 = 4;
-    uDamageAmount = player->CalculateMeleeDamageTo(true, true, 0);
-    goto LABEL_67;
-  }
-  if ( v15 != SPELL_BOW_ARROW )
-  {
-    if ( v15 == SPELL_101 )
-    {
-      a2 = 0;
-      v18 = player->CalculateRangedDamageTo(0);
-      v19 = HIDWORD(pMonster->pActorBuffs[15].uExpireTime) == 0;
-      v20 = SHIDWORD(pMonster->pActorBuffs[15].uExpireTime) < 0;
-      uDamageAmount = v18;
-      if ( !v20 && (!(v20 | v19) || LODWORD(pMonster->pActorBuffs[15].uExpireTime)) )
-        uDamageAmount >>= 1;
-      v59 = 1;
-      goto LABEL_67;
-    }
-    if ( v15 == SPELL_EARTH_BLADES )
-    {
-      a4 = 5 * v4->spell_level;
-      a2 = player->GetSpellSchool(0x27u);
-      v21 = v4->spell_level;
-      v50 = pMonster->sCurrentHP;
-      pMonsterName = (char *)v4->spell_skill;
-      v22 = _43AFE3_calc_spell_damage(39, v21, v4->spell_skill, v50);
-      v23 = HIDWORD(pMonster->pActorBuffs[15].uExpireTime) == 0;
-      v24 = SHIDWORD(pMonster->pActorBuffs[15].uExpireTime) < 0;
-      uDamageAmount = v22;
-      if ( !v24 && (!(v24 | v23) || LODWORD(pMonster->pActorBuffs[15].uExpireTime)) )
-        uDamageAmount >>= 1;
-      v59 = 0;
-LABEL_67:
-      if ( !stru_50C198.PlayerHitOrMiss(player, pMonster, v61, a4) )
-      {
-//LABEL_68:
-        player->PlaySound(SPEECH_52, 0);
-        return;
-      }
-      goto LABEL_69;
-    }
-    if ( v15 == SPELL_EARTH_STUN )
-    {
-      uDamageAmount = 0;
-      a2 = 4;
-      hit_will_stun = 1;
-      goto LABEL_67;
-    }
-    a2 = player->GetSpellSchool(v4->spell_id);
-    v25 = v4->spell_level;
-    v26 = v4->spell_id;
-    v50 = pMonster->sCurrentHP;
-    pMonsterName = (char *)v4->spell_skill;
-    //v27 = _43AFE3_calc_spell_damage(v26, v25, (signed int)pMonsterName, v50);
-    v59 = 0;
-    //v57 = (PlayerEquipment *)1;
-//LABEL_65:
-    uDamageAmount = _43AFE3_calc_spell_damage(v26, v25, v4->spell_skill, v50);
-    //if ( !v57 )
-    //  goto LABEL_67;
-    goto LABEL_69;
-  }
-  v50 = pMonster->word_000086_some_monster_id;
-  a2 = 4;
-  v17 = player->CalculateRangedDamageTo(v50);
-  v19 = v4->stru_24.uItemID == 0;
-  uDamageAmount = v17;
-  v57 = 0;
-  if ( !v19 && v4->stru_24.uSpecEnchantmentType == 3 )
-  {
-    a2 = 0;
-    v57 = (PlayerEquipment *)1;
-  }
-  if ( SHIDWORD(pMonster->pActorBuffs[15].uExpireTime) >= 0
-    && (SHIDWORD(pMonster->pActorBuffs[15].uExpireTime) > 0 || LODWORD(pMonster->pActorBuffs[15].uExpireTime)) )
-    uDamageAmount >>= 1;
-  v59 = 1;
-//LABEL_66:
-  if ( !v57 )
-    goto LABEL_67;
-LABEL_69:
   if (player->IsWeak())
-    uDamageAmount /= 1;
-  if ( (signed __int64)pMonster->pActorBuffs[5].uExpireTime > 0 )
+    uDamageAmount /= 2;
+  if ( pMonster->pActorBuffs[ACTOR_BUFF_STONED].uExpireTime > 0 )
     uDamageAmount = 0;
   v61 = stru_50C198.CalcMagicalDamageToActor(pMonster, a2, uDamageAmount);
-  if ( !v4 && player->IsUnarmed() && (signed __int64)player->pPlayerBuffs[6].uExpireTime > 0 )
+  if ( !v4 && player->IsUnarmed() && player->pPlayerBuffs[PLAYER_BUFF_HAMMERHANDS].uExpireTime > 0 )
   {
-    v50 = player->pPlayerBuffs[6].uPower;
+    v50 = player->pPlayerBuffs[PLAYER_BUFF_HAMMERHANDS].uPower;
     v29 = stru_50C198.CalcMagicalDamageToActor(pMonster, 8, v50);
     v61 += v29;
   }