changeset 1972:3ef25d06b9b0

Actor::special_ability_use_check moved to Actor and cleaned up
author Grumpy7
date Sat, 26 Oct 2013 00:18:52 -0700
parents e45c277da9f1
children f708aaeb635b
files Actor.cpp Actor.h TurnEngine.cpp mm7_6.cpp
diffstat 4 files changed, 34 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/Actor.cpp	Sat Oct 26 00:09:30 2013 -0700
+++ b/Actor.cpp	Sat Oct 26 00:18:52 2013 -0700
@@ -3096,7 +3096,7 @@
 			}
 			else if ( pActor->uAIState == AttackingMelee )
 			{
-				v35 = stru_50C198.special_ability_use_check(pActor, actor_id);
+				v35 = pActor->special_ability_use_check(actor_id);
 				stru_50FE08.Add(
 					a1,
 					5120,
@@ -3217,7 +3217,7 @@
 			pActor->uAttributes &= 0xFFFBFFFF;
 			if ( v81 < 5120 )
 			{
-				v45 = stru_50C198.special_ability_use_check(pActor, actor_id);
+				v45 = pActor->special_ability_use_check(actor_id);
 				if ( v45 == 0 )
 				{
 					if ( pActor->pMonsterInfo.uMissleAttack1Type )
@@ -4350,4 +4350,26 @@
       return true;
     }
   }
+}
+
+
+//----- (0042704B) --------------------------------------------------------
+ABILITY_INDEX Actor::special_ability_use_check( int a2 )
+{
+  signed int okToCastSpell1; // ebx@5
+  signed int okToCastSpell2; // edi@5
+
+  if ( this->pMonsterInfo.uSpecialAbilityType == 2
+    && this->pMonsterInfo.uSpecialAbilityDamageDiceBonus < 3u
+    && rand() % 100 < 5 )
+    this->SummonMinion(a2);
+  okToCastSpell1 = this->_427102_IsOkToCastSpell(this->pMonsterInfo.uSpell1ID);
+  okToCastSpell2 = this->_427102_IsOkToCastSpell(this->pMonsterInfo.uSpell2ID);
+  if ( okToCastSpell1 && this->pMonsterInfo.uSpell1UseChance && rand() % 100 < this->pMonsterInfo.uSpell1UseChance )
+    return ABILITY_SPELL1;
+  if ( okToCastSpell2 && this->pMonsterInfo.uSpell2UseChance && rand() % 100 < this->pMonsterInfo.uSpell2UseChance )
+    return ABILITY_SPELL2;
+  if (this->pMonsterInfo.uAttack2Chance && rand() % 100 < this->pMonsterInfo.uAttack2Chance)
+    return ABILITY_ATTACK2;
+  return ABILITY_ATTACK1;
 }
\ No newline at end of file
--- a/Actor.h	Sat Oct 26 00:09:30 2013 -0700
+++ b/Actor.h	Sat Oct 26 00:18:52 2013 -0700
@@ -13,7 +13,6 @@
 struct stru319
 {
   int which_player_to_attack(struct Actor *pActor);
-  int  special_ability_use_check(struct Actor *pActor, int a2);
   int PlayerHitOrMiss(struct Player *pPlayer, struct Actor *pActor, int a3, int a4);
   bool _4273BB(struct Actor *pActor, struct Actor *a2, int a3, int a4);
   bool ActorHitOrMiss(struct Actor *pActor, struct Player *pPlayer);
@@ -30,7 +29,13 @@
 extern stru319 stru_50C198; // idb
 
 
-
+enum ABILITY_INDEX
+{
+  ABILITY_ATTACK1 = 0,
+  ABILITY_ATTACK2 = 1,
+  ABILITY_SPELL1 = 2,
+  ABILITY_SPELL2 = 3,
+};
 
 
 
@@ -249,6 +254,7 @@
 
   void LootActor();
   bool _427102_IsOkToCastSpell(signed int a2);
+  ABILITY_INDEX special_ability_use_check(int a2);
 
   char pActorName[32];
   signed __int16 sNPC_ID;
--- a/TurnEngine.cpp	Sat Oct 26 00:09:30 2013 -0700
+++ b/TurnEngine.cpp	Sat Oct 26 00:18:52 2013 -0700
@@ -727,7 +727,7 @@
                          switch (v3)
                          {
                            case  AIState::AttackingMelee:
-                             v19 = stru_50C198.special_ability_use_check(&pActors[v4], v4);
+                             v19 = pActors[v4].special_ability_use_check(v4);
                              stru_50FE08.Add( v28->uPackedID,  5120,  v5->vPosition.x, v5->vPosition.y, v5->vPosition.z + ((signed int)v5->uActorHeight >> 1), v19,  1);
                              Actor::AI_Stand(v4, a2a, 0, &a4);
                              break;
@@ -848,7 +848,7 @@
                 
                 if ( v5->pMonsterInfo.uHostilityType == 4 && v22 && (signed int)v9 < 5120 )
                     {
-                    v14 = stru_50C198.special_ability_use_check(v5, actor_id);
+                    v14 = v5->special_ability_use_check(actor_id);
                     v21->AI_action_type = TE_AI_STAND;
                     switch (v14)
                         {
--- a/mm7_6.cpp	Sat Oct 26 00:09:30 2013 -0700
+++ b/mm7_6.cpp	Sat Oct 26 00:18:52 2013 -0700
@@ -42,26 +42,6 @@
 
 
 
-//----- (0042704B) --------------------------------------------------------
-int stru319::special_ability_use_check( struct Actor *pActor, int a2 )
-    {
-  stru319 *v3; // edi@1
-  signed int v4; // ebx@5
-  signed int v5; // edi@5
-
-  v3 = this;
-  if ( pActor->pMonsterInfo.uSpecialAbilityType == 2
-    && pActor->pMonsterInfo.uSpecialAbilityDamageDiceBonus < 3u
-    && rand() % 100 < 5 )
-    pActor->SummonMinion(a2);
-  v4 = pActor->_427102_IsOkToCastSpell(pActor->pMonsterInfo.uSpell1ID);
-  v5 = pActor->_427102_IsOkToCastSpell(pActor->pMonsterInfo.uSpell2ID);
-  if ( v4 && pActor->pMonsterInfo.uSpell1UseChance && rand() % 100 < pActor->pMonsterInfo.uSpell1UseChance )
-    return 2;
-  if ( v5 && pActor->pMonsterInfo.uSpell2UseChance && rand() % 100 < pActor->pMonsterInfo.uSpell2UseChance )
-    return 3;
-  return pActor->pMonsterInfo.uAttack2Chance && rand() % 100 < pActor->pMonsterInfo.uAttack2Chance?1:0;
-}
 
 
 //----- (004272F5) --------------------------------------------------------