changeset 2310:43af6c819e88

ActorDamageFromMonster moved into Actor class
author Grumpy7
date Mon, 17 Mar 2014 22:52:52 +0100
parents a07bf9afa652
children 9dbfeda280d7
files Actor.cpp Actor.h mm7_5.cpp mm7_unsorted_subs.h
diffstat 4 files changed, 84 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/Actor.cpp	Mon Mar 17 22:49:54 2014 +0100
+++ b/Actor.cpp	Mon Mar 17 22:52:52 2014 +0100
@@ -2591,6 +2591,86 @@
   this->uAIState = Removed;
 }
 
+
+//----- (0043B1B0) --------------------------------------------------------
+void Actor::ActorDamageFromMonster(signed int attacker_id, unsigned int actor_id, Vec3_int_ *pVelocity, signed int a4)
+{
+  int v4; // ebx@1
+  int dmgToRecv; // qax@8
+  signed int v12; // ecx@20
+  int finalDmg; // edi@30
+  int pushDistance; // [sp+20h] [bp+Ch]@34
+
+  v4 = 0;
+  if ( PID_TYPE(attacker_id) == OBJECT_Item)
+  {
+    v4 = pSpriteObjects[PID_ID(attacker_id)].field_60_distance_related_prolly_lod;
+    attacker_id = pSpriteObjects[PID_ID(attacker_id)].spell_caster_pid;
+  }
+  if ( PID_TYPE(attacker_id) == OBJECT_Actor)
+  {
+    if ( !pActors[actor_id].IsNotAlive() )
+    {
+      pActors[actor_id].uLastCharacterIDToHit = attacker_id;
+      if ( pActors[actor_id].uAIState == Fleeing )
+        pActors[actor_id].uAttributes |= FACE_UNKNOW7;
+      if ( pActors[PID_ID(attacker_id)]._4273BB_DoesHitOtherActor(&pActors[actor_id], v4, 0) )
+      {
+        dmgToRecv = pActors[PID_ID(attacker_id)]._43B3E0_CalcDamage(a4);
+        if ( pActors[PID_ID(attacker_id)].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime > 0 )
+        {
+          if ( pActors[PID_ID(attacker_id)].pActorBuffs[ACTOR_BUFF_SHRINK].uPower )
+            dmgToRecv = dmgToRecv / pActors[PID_ID(attacker_id)].pActorBuffs[ACTOR_BUFF_SHRINK].uPower;
+        }
+        if ( pActors[actor_id].pActorBuffs[ACTOR_BUFF_STONED].uExpireTime > 0 )
+          dmgToRecv = 0;
+        if ( a4 == 0 )
+          v12 = pActors[PID_ID(attacker_id)].pMonsterInfo.uAttack1Type;
+        else if ( a4 == 1 )
+        {
+          v12 = pActors[PID_ID(attacker_id)].pMonsterInfo.uAttack2Type;
+          if ( SHIDWORD(pActors[actor_id].pActorBuffs[ACTOR_BUFF_SHIELD].uExpireTime) > 0 )
+            dmgToRecv = dmgToRecv / 2;
+        }
+        else if ( a4 == 2 )
+          v12 = pSpellStats->pInfos[pActors[actor_id].pMonsterInfo.uSpell1ID].uSchool;
+        else if ( a4 == 3 )
+          v12 = pSpellStats->pInfos[pActors[actor_id].pMonsterInfo.uSpell2ID].uSchool;
+        else if ( a4 == 4 )
+          v12 = pActors[PID_ID(attacker_id)].pMonsterInfo.field_3C_some_special_attack;
+        else
+          v12 = 4;
+        finalDmg = pActors[actor_id].CalcMagicalDamageToActor((DAMAGE_TYPE)v12, dmgToRecv);
+        pActors[actor_id].sCurrentHP -= finalDmg;
+        if ( finalDmg )
+        {
+          if ( pActors[actor_id].sCurrentHP > 0 )
+            Actor::AI_Stun(actor_id, attacker_id, 0);
+          else
+            Actor::Die(actor_id);
+          Actor::AggroSurroundingPeasants(actor_id, 0);
+          pushDistance = 20 * finalDmg / pActors[actor_id].pMonsterInfo.uHP;
+          if ( pushDistance > 10 )
+            pushDistance = 10;
+          if ( !MonsterStats::BelongsToSupertype(pActors[actor_id].pMonsterInfo.uID, MONSTER_SUPERTYPE_TREANT) )
+          {
+            pVelocity->x = (int32)fixpoint_mul(pushDistance, pVelocity->x);
+            pVelocity->y = (int32)fixpoint_mul(pushDistance, pVelocity->y);
+            pVelocity->z = (int32)fixpoint_mul(pushDistance, pVelocity->z);
+            pActors[actor_id].vVelocity.x = 50 * LOWORD(pVelocity->x);
+            pActors[actor_id].vVelocity.y = 50 * LOWORD(pVelocity->y);
+            pActors[actor_id].vVelocity.z = 50 * LOWORD(pVelocity->z);
+          }
+          Actor::AddBloodsplatOnDamageOverlay(actor_id, 1, finalDmg);
+        }
+        else
+          Actor::AI_Stun(actor_id, attacker_id, 0);
+        return;
+      }
+    }
+  }
+}
+
 //----- (0044FD29) --------------------------------------------------------
 void Actor::SummonMinion( int summonerId )
 {
--- a/Actor.h	Mon Mar 17 22:49:54 2014 +0100
+++ b/Actor.h	Mon Mar 17 22:52:52 2014 +0100
@@ -213,6 +213,7 @@
   static void Explode(unsigned int uActorID);
   static void AI_RangedAttack(unsigned int uActorID, struct AIDirection *a2, int type, char a4);
   static void AI_SpellAttack(unsigned int uActorID, struct AIDirection *pDir, int uSpellID, int a4, unsigned int uSkillLevel);
+  static void ActorDamageFromMonster(signed int attacker_id, unsigned int actor_id, struct Vec3_int_ *pVelocity, signed int a4);
 
   static unsigned short GetObjDescId( int spellId );
 
--- a/mm7_5.cpp	Mon Mar 17 22:49:54 2014 +0100
+++ b/mm7_5.cpp	Mon Mar 17 22:52:52 2014 +0100
@@ -126,7 +126,7 @@
               AttackerInfo.vec_4B4[attacker_id].x = a1;
               AttackerInfo.vec_4B4[attacker_id].y = v48;
               AttackerInfo.vec_4B4[attacker_id].z = v44;
-              ActorDamageFromMonster(AttackerInfo.pIDs[attacker_id], target_id, &AttackerInfo.vec_4B4[attacker_id], AttackerInfo.field_450[attacker_id]);
+              Actor::ActorDamageFromMonster(AttackerInfo.pIDs[attacker_id], target_id, &AttackerInfo.vec_4B4[attacker_id], AttackerInfo.field_450[attacker_id]);
             }
           }
         }
@@ -184,7 +184,7 @@
                     break;
                   case OBJECT_Actor:
                     if ( v36 && pActors[v3].GetActorsRelation(&pActors[actorID]) )
-                      ActorDamageFromMonster(AttackerInfo.pIDs[attacker_id], actorID, &AttackerInfo.vec_4B4[attacker_id], v36->field_61);
+                      Actor::ActorDamageFromMonster(AttackerInfo.pIDs[attacker_id], actorID, &AttackerInfo.vec_4B4[attacker_id], v36->field_61);
                     break;
                   case OBJECT_Item:
                     ItemDamageFromActor(AttackerInfo.pIDs[attacker_id], actorID, &AttackerInfo.vec_4B4[attacker_id]);
@@ -223,7 +223,7 @@
     switch (PID_TYPE(pSpriteObjects[uLayingItemID].spell_caster_pid))
     {
       case OBJECT_Actor:
-        ActorDamageFromMonster(PID(OBJECT_Item, uLayingItemID), PID_ID(a2), &layingitem_vel_50FDFC, pSpriteObjects[uLayingItemID].field_61);
+        Actor::ActorDamageFromMonster(PID(OBJECT_Item, uLayingItemID), PID_ID(a2), &layingitem_vel_50FDFC, pSpriteObjects[uLayingItemID].field_61);
         break;
       case OBJECT_Player:
         DamageMonsterFromParty(PID(OBJECT_Item, uLayingItemID), PID_ID(a2), &layingitem_vel_50FDFC);
@@ -304,84 +304,6 @@
   }
 }
 
-//----- (0043B1B0) --------------------------------------------------------
-void ActorDamageFromMonster(signed int attacker_id, unsigned int actor_id, Vec3_int_ *pVelocity, signed int a4)
-{
-  int v4; // ebx@1
-  int dmgToRecv; // qax@8
-  signed int v12; // ecx@20
-  int finalDmg; // edi@30
-  int pushDistance; // [sp+20h] [bp+Ch]@34
-
-  v4 = 0;
-  if ( PID_TYPE(attacker_id) == OBJECT_Item)
-  {
-    v4 = pSpriteObjects[PID_ID(attacker_id)].field_60_distance_related_prolly_lod;
-    attacker_id = pSpriteObjects[PID_ID(attacker_id)].spell_caster_pid;
-  }
-  if ( PID_TYPE(attacker_id) == OBJECT_Actor)
-  {
-    if ( !pActors[actor_id].IsNotAlive() )
-    {
-      pActors[actor_id].uLastCharacterIDToHit = attacker_id;
-      if ( pActors[actor_id].uAIState == Fleeing )
-        pActors[actor_id].uAttributes |= FACE_UNKNOW7;
-      if ( pActors[PID_ID(attacker_id)]._4273BB_DoesHitOtherActor(&pActors[actor_id], v4, 0) )
-      {
-        dmgToRecv = pActors[PID_ID(attacker_id)]._43B3E0_CalcDamage(a4);
-        if ( pActors[PID_ID(attacker_id)].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime > 0 )
-        {
-          if ( pActors[PID_ID(attacker_id)].pActorBuffs[ACTOR_BUFF_SHRINK].uPower )
-            dmgToRecv = dmgToRecv / pActors[PID_ID(attacker_id)].pActorBuffs[ACTOR_BUFF_SHRINK].uPower;
-        }
-        if ( pActors[actor_id].pActorBuffs[ACTOR_BUFF_STONED].uExpireTime > 0 )
-          dmgToRecv = 0;
-        if ( a4 == 0 )
-          v12 = pActors[PID_ID(attacker_id)].pMonsterInfo.uAttack1Type;
-        else if ( a4 == 1 )
-        {
-          v12 = pActors[PID_ID(attacker_id)].pMonsterInfo.uAttack2Type;
-          if ( SHIDWORD(pActors[actor_id].pActorBuffs[ACTOR_BUFF_SHIELD].uExpireTime) > 0 )
-            dmgToRecv = dmgToRecv / 2;
-        }
-        else if ( a4 == 2 )
-          v12 = pSpellStats->pInfos[pActors[actor_id].pMonsterInfo.uSpell1ID].uSchool;
-        else if ( a4 == 3 )
-          v12 = pSpellStats->pInfos[pActors[actor_id].pMonsterInfo.uSpell2ID].uSchool;
-        else if ( a4 == 4 )
-          v12 = pActors[PID_ID(attacker_id)].pMonsterInfo.field_3C_some_special_attack;
-        else
-          v12 = 4;
-        finalDmg = pActors[actor_id].CalcMagicalDamageToActor((DAMAGE_TYPE)v12, dmgToRecv);
-        pActors[actor_id].sCurrentHP -= finalDmg;
-        if ( finalDmg )
-        {
-          if ( pActors[actor_id].sCurrentHP > 0 )
-            Actor::AI_Stun(actor_id, attacker_id, 0);
-          else
-            Actor::Die(actor_id);
-          Actor::AggroSurroundingPeasants(actor_id, 0);
-          pushDistance = 20 * finalDmg / pActors[actor_id].pMonsterInfo.uHP;
-          if ( pushDistance > 10 )
-            pushDistance = 10;
-          if ( !MonsterStats::BelongsToSupertype(pActors[actor_id].pMonsterInfo.uID, MONSTER_SUPERTYPE_TREANT) )
-          {
-            pVelocity->x = (int32)fixpoint_mul(pushDistance, pVelocity->x);
-            pVelocity->y = (int32)fixpoint_mul(pushDistance, pVelocity->y);
-            pVelocity->z = (int32)fixpoint_mul(pushDistance, pVelocity->z);
-            pActors[actor_id].vVelocity.x = 50 * LOWORD(pVelocity->x);
-            pActors[actor_id].vVelocity.y = 50 * LOWORD(pVelocity->y);
-            pActors[actor_id].vVelocity.z = 50 * LOWORD(pVelocity->z);
-          }
-          Actor::AddBloodsplatOnDamageOverlay(actor_id, 1, finalDmg);
-        }
-        else
-          Actor::AI_Stun(actor_id, attacker_id, 0);
-        return;
-      }
-    }
-  }
-}
 
 //----- (0043F515) --------------------------------------------------------
 void FindBillboardsLightLevels_BLV()
--- a/mm7_unsorted_subs.h	Mon Mar 17 22:49:54 2014 +0100
+++ b/mm7_unsorted_subs.h	Mon Mar 17 22:52:52 2014 +0100
@@ -85,7 +85,6 @@
 double __fastcall sub_43AE12(signed int a1);
 int __fastcall _43AFE3_calc_spell_damage(int a1, int a2, signed int a3, int a4);
 void ItemDamageFromActor(unsigned int uObjID, unsigned int uActorID, struct Vec3_int_ *pVelocity);
-void ActorDamageFromMonster(signed int attacker_id, unsigned int actor_id, struct Vec3_int_ *pVelocity, signed int a4);
 void CharacterUI_LoadPaperdollTextures();
 int GetItemTextureFilename(char *pOut, signed int item_id, int index, int shoulder);
 bool IsDwarfPresentInParty(bool b);