changeset 2060:72177f3603da

_493938_regenerate()
author Ritor1
date Mon, 02 Dec 2013 17:00:58 +0600
parents f9698295c0bd
children b2a434d65344 c2a004e7458b
files mm7_4.cpp mm7_data.h
diffstat 2 files changed, 165 insertions(+), 259 deletions(-) [+]
line wrap: on
line diff
--- a/mm7_4.cpp	Sun Dec 01 23:43:03 2013 +0600
+++ b/mm7_4.cpp	Mon Dec 02 17:00:58 2013 +0600
@@ -324,12 +324,10 @@
 // 4ED498: using guessed type char byte_4ED498;
 
 //----- (00493938) --------------------------------------------------------
-int  _493938_regenerate()
+void  _493938_regenerate()
 {
-  int v0; // edi@1
-  signed __int64 v1; // qax@1
-  int v2; // ecx@1
-  int result; // eax@1
+  int current_time; // edi@1
+  int last_reg_time; // qax@1
   int v4; // eax@2
   int v5; // edi@5
   bool cursed_flag; // ecx@5
@@ -343,50 +341,33 @@
   unsigned int *v14; // esi@21
   unsigned int v15; // ecx@21
   unsigned int v16; // eax@21
-  int v17; // edx@21
   int v18; // eax@21
   signed int v19; // eax@21
-  signed int v20; // ebx@25
-  Player *v21; // esi@25
+  bool recovery_HP; // ebx@25
   ITEM_EQUIP_TYPE v22; // edi@30
-  //int v23; // edx@31
-  signed int v24; // ecx@32
   signed int v25; // eax@33
   int v26; // eax@35
   int v27; // eax@36
   int v28; // eax@37
-  int v29; // eax@40
-  int v30; // eax@41
   signed int v31; // ecx@53
-  char *v32; // eax@53
-  char *v33; // edi@82
-  int v34; // ecx@88
-  int v35; // eax@88
-  char *v36; // edi@99
-  int v37; // edi@104
-  int v38; // edi@106
-  int v39; // edi@111
-  int v40; // ecx@113
   char v41[400]; // [sp+4h] [bp-22Ch]@20
   SpriteObject a1; // [sp+194h] [bp-9Ch]@15
   Vec3_int_ a3; // [sp+204h] [bp-2Ch]@15
-  int v44; // [sp+210h] [bp-20h]@22
-  int v45; // [sp+214h] [bp-1Ch]@25
-  int v46; // [sp+218h] [bp-18h]@25
-  int v47; // [sp+21Ch] [bp-14h]@25
-  int v48; // [sp+220h] [bp-10h]@25
+  bool has_dragon_flag; // [sp+210h] [bp-20h]@22
+  bool lich_jar_flag; // [sp+214h] [bp-1Ch]@25
+  bool zombie_flag; // [sp+218h] [bp-18h]@25
+  bool decrease_HP; // [sp+21Ch] [bp-14h]@25
+  bool lich_flag; // [sp+220h] [bp-10h]@25
   int v49; // [sp+224h] [bp-Ch]@24
-  int v50; // [sp+228h] [bp-8h]@25
-  int v51; // [sp+22Ch] [bp-4h]@2
+  bool recovery_SP; // [sp+228h] [bp-8h]@25
+  bool redraw_flag; // [sp+22Ch] [bp-4h]@2
 
-  v0 = (signed int)(signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) / 60;
-  v1 = (signed __int64)((double)pParty->uLastRegenerationTime * 0.234375);
-  v2 = (signed int)v1 / 60;
-  result = (signed int)v1 / 60 + 5;
-  if ( v0 >= result )
+  current_time = (signed int)(signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) / 60;
+  last_reg_time = (signed int)(signed __int64)((double)pParty->uLastRegenerationTime * 0.234375) / 60;
+  if ( current_time >= (signed int)last_reg_time + 5 )
   {
-    v51 = 0;
-    v4 = (v0 - v2) / 5;
+    redraw_flag = false;
+    v4 = (current_time - last_reg_time) / 5;
     if (pParty->FlyActive())
     {
       if ( pParty->bFlying )
@@ -394,14 +375,14 @@
         if ( !(pParty->pPartyBuffs[PARTY_BUFF_FLY].uFlags & 1) )
         {
           v5 = v4 * pParty->pPartyBuffs[PARTY_BUFF_FLY].uPower;
-          cursed_flag = pParty->pPlayers[pParty->pPartyBuffs[PARTY_BUFF_FLY].uCaster - 1].pConditions[0];//cursed
+          cursed_flag = pParty->pPlayers[pParty->pPartyBuffs[PARTY_BUFF_FLY].uCaster - 1].pConditions[Condition_Cursed];//cursed
           v7 = cursed_flag < v5;
           //cursed_flag -= v5;
           if ( !v7 )
           {
             pParty->uFlags &= 0xFFFFFFBFu;
             pParty->bFlying = false;
-            v51 = 1;
+            redraw_flag = true;
           }
         }
       }
@@ -413,24 +394,21 @@
       {
         if ( !(pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uFlags & 1) )
         { // taking on water
-          //__debugbreak();
-          v8 = (int *)&pParty->pPlayers[pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uCaster - 1].pConditions[0];//&stru_AA1058[4].pSounds[6972 * pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uCaster + 2000];
+          v8 = (int *)&pParty->pPlayers[pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uCaster - 1].pConditions[Condition_Cursed];//&stru_AA1058[4].pSounds[6972 * pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uCaster + 2000];
           v7 = *v8 < v4;
           *v8 -= v4;
           if ( v7 )
           {
             *v8 = 0;
             pParty->uFlags &= ~PARTY_FLAGS_1_STANDING_ON_WATER;
-            v51 = 1;
+            redraw_flag = true;
           }
         }
       }
     }
 
-    if (pParty->ImmolationActive())
+    if (pParty->ImmolationActive())//Жертва
     {
-      //SpriteObject::SpriteObject(&a1);
-      v9 = 0;
       a3.z = 0;
       a3.y = 0;
       a3.x = 0;
@@ -467,249 +445,177 @@
       a1.uFacing = 0;
       a1.uSoundID = 0;
       v13 = _46A89E_immolation_effect((int)v41, 100, 307);
-      if ( v13 > 0 )
+      for ( v9 = 0; v9 < v13; ++v9 )
       {
-        do
-        {
-          v14 = (unsigned int *)&v41[4 * v9];
-          v15 = *v14;
-          v16 = *v14;
-          a1.vPosition.x = pActors[v16].vPosition.x;
-          v17 = pActors[v16].vPosition.y;
-          a1.vPosition.z = pActors[v16].vPosition.z;
-          v18 = 8 * v15;
-          LOBYTE(v18) = PID(OBJECT_Actor,v15);
-          a1.vPosition.y = v17;
-          a1.spell_target_pid = v18;
-          v19 = a1.Create(0, 0, 0, 0);
-          DamageMonsterFromParty(PID(OBJECT_Item,v19), *v14, &a3);
-          ++v9;
-        }
-        while ( v9 < v13 );
+        v14 = (unsigned int *)&v41[4 * v9];
+        v15 = *v14;
+        v16 = *v14;
+        a1.vPosition.x = pActors[v16].vPosition.x;
+        a1.vPosition.y = pActors[v16].vPosition.y;
+        a1.vPosition.z = pActors[v16].vPosition.z;
+        v18 = 8 * v15;
+        LOBYTE(v18) = PID(OBJECT_Actor,v15);
+        a1.spell_target_pid = v18;
+        v19 = a1.Create(0, 0, 0, 0);
+        DamageMonsterFromParty(PID(OBJECT_Item,v19), *v14, &a3);
       }
     }
-    v44 = 0;
+
+    has_dragon_flag = false;
     if (PartyHasDragon())
-      v44 = 1;
-    v49 = 0;
-LABEL_25:
-    v20 = 0;
-    v21 = &pParty->pPlayers[v49];
-    v50 = 0;
-    v47 = 0;
-    v45 = 0;
-    v48 = 0;
-    v46 = 0;
-    if ( v44 && v21->classType == PLAYER_CLASS_WARLOCK )
-      v50 = 1;
-    if ( v21->classType == PLAYER_CLASS_LICH )
-      v48 = 1;
-    v22 = (ITEM_EQUIP_TYPE)0;
-    while ( 1 )
+      has_dragon_flag = true;
+
+    for ( v49 = 0; v49 < 4; v49++ )
     {
-      if ( v21->HasItemEquipped(v22) )
+      recovery_HP = false;
+      recovery_SP = false;
+      decrease_HP = false;
+      lich_flag = false;
+      lich_jar_flag = false;
+      zombie_flag = false;
+
+      for ( int v22 = 0; (signed int)v22 < 16; v22++ )
       {
-        //v23 = v21->pEquipment.pIndices;
-        uint _idx = v21->pEquipment.pIndices[v22];
-        v24 = v21->pInventoryItemList[_idx].uItemID;
-        if ( v24 > 134 )
+        if ( pParty->pPlayers[v49].HasItemEquipped((ITEM_EQUIP_TYPE)v22) )
         {
-          if ( v24 == 529 )
+          uint _idx = pParty->pPlayers[v49].pEquipment.pIndices[v22];
+          if ( pParty->pPlayers[v49].pInventoryItemList[_idx - 1].uItemID > 134 )
           {
-            v20 = 1;
-            v50 = 1;
-            goto LABEL_51;
-          }
-          if ( v24 == 535 )
-          {
-            v20 = 1;
-            goto LABEL_51;
-          }
-          if ( v24 == 515 )
-          {
-            v47 = 1;
+            if ( pParty->pPlayers[v49].pInventoryItemList[_idx - 1].uItemID == ITEM_RELIC_ETHRICS_STAFF )
+              decrease_HP = true;
+            if ( pParty->pPlayers[v49].pInventoryItemList[_idx - 1].uItemID == ITEM_ARTIFACT_HERMES_SANDALS )
+            {
+              recovery_HP = true;
+              recovery_SP = true;
+            }
+            if ( pParty->pPlayers[v49].pInventoryItemList[_idx - 1].uItemID == ITEM_ARTIFACT_MINDS_EYE )
+              recovery_SP = true;
+            if ( pParty->pPlayers[v49].pInventoryItemList[_idx - 1].uItemID == ITEM_ARTIFACT_HEROS_BELT )
+              recovery_HP = true;
           }
           else
           {
-            if ( v24 == 532 )
+            v25 = pParty->pPlayers[v49].pInventoryItemList[_idx - 1].uSpecEnchantmentType;
+            if ( v25 == 37 //of Regeneration("Regenerate 1hp/x while walking, etc")
+              && v25 == 44 //of Life("HP (+10), Regen hpts")
+              && v25 == 50 //of The Phoenix("Fire Res (+30), Regen hpts") && 
+              && v25 == 54 )// of The Troll("End (+15), Regen hpts")
+               recovery_HP = true;
+            if ( v25 == 38 //of Mana("Regenerate 1sp/x while walking, etc")
+              && v25 == 47 //of The Eclipse("SP (+10), Regen spts")
+              && v25 == 55 )//of The Unicorn("Luck (+15), Regen spts")
+               recovery_SP = true;
+            if ( v25 == 66 )// of Plenty("Regenerate 1 hp/x and 1 sp/x while walking, etc.")
             {
-              v50 = 1;
-              goto LABEL_51;
+              recovery_HP = true;
+              recovery_SP = true;
             }
           }
-        }
-        else
-        {
-          v25 = v21->pInventoryItemList[_idx].uSpecEnchantmentType;
-          if ( v25 <= 50 )
+
+          if ( recovery_HP && !pParty->pPlayers[v49].pConditions[Condition_Dead]
+                           && !pParty->pPlayers[v49].pConditions[Condition_Eradicated] )
+          {
+            ++pParty->pPlayers[v49].sHealth;
+            if ( pParty->pPlayers[v49].sHealth > pParty->pPlayers[v49].GetMaxHealth() )
+              pParty->pPlayers[v49].sHealth = pParty->pPlayers[v49].GetMaxHealth();
+            if ( pParty->pPlayers[v49].pConditions[Condition_Unconcious] && pParty->pPlayers[v49].sHealth > 0 )
+              pParty->pPlayers[v49].pConditions[Condition_Unconcious] = 0;
+            redraw_flag = true;
+          }
+
+          if ( recovery_SP )
           {
-            if ( v25 != 50 )
+            ++pParty->pPlayers[v49].sMana;
+            if ( pParty->pPlayers[v49].sMana > pParty->pPlayers[v49].GetMaxMana() )
+              pParty->pPlayers[v49].sMana = pParty->pPlayers[v49].GetMaxMana();
+            redraw_flag = true;
+          }
+
+          if ( decrease_HP && !pParty->pPlayers[v49].pConditions[Condition_Dead]
+                   && !pParty->pPlayers[v49].pConditions[Condition_Eradicated] )
+          {
+            --pParty->pPlayers[v49].sHealth;
+            if ( !(pParty->pPlayers[v49].pConditions[Condition_Unconcious]) && pParty->pPlayers[v49].sHealth < 0 )
+              pParty->pPlayers[v49].pConditions[Condition_Unconcious] = pParty->uTimePlayed;
+            if ( pParty->pPlayers[v49].sHealth < 1 )
             {
-              v26 = v25 - 37;
-              if ( v26 )
+              if ( pParty->pPlayers[v49].sHealth + pParty->pPlayers[v49].uEndurance + pParty->pPlayers[v49].GetItemsBonus(CHARACTER_ATTRIBUTE_ENDURANCE) >= 1
+                || (signed __int64)pParty->pPlayers[v49].pPlayerBuffs[PLAYER_BUFF_PRESERVATION].uExpireTime > 0 )
+                 pParty->pPlayers[v49].pConditions[Condition_Unconcious] = pParty->uTimePlayed;
+              else
               {
-                v27 = v26 - 1;
-                if ( !v27 )
-                {
-                  v50 = 1;
-                  goto LABEL_51;
-                }
-                v28 = v27 - 6;
-                if ( v28 )
-                {
-                  if ( v28 != 3 )
-                    goto LABEL_51;
-//LABEL_50:
-                  v50 = 1;
-                  goto LABEL_51;
-                }
+                if ( !pParty->pPlayers[v49].pConditions[Condition_Dead] )
+                  pParty->pPlayers[v49].pConditions[Condition_Dead] = pParty->uTimePlayed;
               }
             }
-//LABEL_44:
-            v20 = 1;
-            goto LABEL_51;
-          }
-          v29 = v25 - 54;
-          if ( !v29 )
-          {
-            v20 = 1;
-            goto LABEL_51;
-          }
-          v30 = v29 - 1;
-          if ( !v30 )
-          {
-            v50 = 1;
-            goto LABEL_51;
-          }
-          if ( v30 == 11 )
-          {
-//LABEL_43:
-            v20 = 1;
-            v50 = 1;
-            goto LABEL_51;
+            redraw_flag = true;
           }
         }
       }
-LABEL_51:
-      v22 = (ITEM_EQUIP_TYPE)((int)v22 + 1);
-      if ( (signed int)v22 >= 16 )
+
+      //regeneration
+      if ( pParty->pPlayers[v49].pPlayerBuffs[PLAYER_BUFF_REGENERATION].uExpireTime > 0
+        && !pParty->pPlayers[v49].pConditions[Condition_Dead]
+        && !pParty->pPlayers[v49].pConditions[Condition_Eradicated] )
       {
-        if ( v48 )
-        {
-          v31 = 0;
-          v32 = (char *)v21->pInventoryItemList.data();
-          while ( *(int *)v32 != 601 || (unsigned __int8)v32[26] != v49 + 1 )
-          {
-            ++v31;
-            v32 += 36;
-            if ( v31 >= 138 )
-              goto LABEL_59;
-          }
-          v48 = 0;
-          v45 = 1;
-        }
-LABEL_59:
-        if ( v21->pConditions[17] )
-          v46 = 1;
-        if ( v20 && !v21->pConditions[14] && !v21->pConditions[16] )
-        {
-          ++v21->sHealth;
-          if ( v21->sHealth > v21->GetMaxHealth() )
-            v21->sHealth = v21->GetMaxHealth();
-          if ( v21->pConditions[13] && v21->sHealth > 0 )
-          {
-            LODWORD(v21->pConditions[13]) = 0;
-            HIDWORD(v21->pConditions[13]) = 0;
-          }
-          v51 = 1;
-        }
-        if ( SHIDWORD(v21->pPlayerBuffs[12].uExpireTime) >= 0
-          && (SHIDWORD(v21->pPlayerBuffs[12].uExpireTime) > 0 || LODWORD(v21->pPlayerBuffs[12].uExpireTime))
-          && !v21->pConditions[14]
-          && !v21->pConditions[16] )
-        {
-          v21->sHealth += 5 * v21->pPlayerBuffs[12].uPower;
-          if ( v21->sHealth > v21->GetMaxHealth() )
-            v21->sHealth = v21->GetMaxHealth();
-          if ( v21->pConditions[13] && v21->sHealth > 0 )
-          {
-            LODWORD(v21->pConditions[13]) = 0;
-            HIDWORD(v21->pConditions[13]) = 0;
-          }
-          v51 = 1;
-        }
-        if ( v50 )
-        {
-          v33 = (char *)&v21->sMana;
-          ++*(int *)v33;
-          if ( v21->sMana > v21->GetMaxMana() )
-            *(int *)v33 = v21->GetMaxMana();
-          v51 = 1;
-        }
-        if ( v47 && !v21->pConditions[14] && !v21->pConditions[16] )
+        pParty->pPlayers[v49].sHealth += 5 * pParty->pPlayers[v49].pPlayerBuffs[PLAYER_BUFF_REGENERATION].uPower;
+        if ( pParty->pPlayers[v49].sHealth > pParty->pPlayers[v49].GetMaxHealth() )
+          pParty->pPlayers[v49].sHealth = pParty->pPlayers[v49].GetMaxHealth();
+        if ( pParty->pPlayers[v49].pConditions[Condition_Unconcious] && pParty->pPlayers[v49].sHealth > 0 )
+          pParty->pPlayers[v49].pConditions[Condition_Unconcious] = 0;
+        redraw_flag = true;
+      }
+
+      //for warlock
+      if ( has_dragon_flag && pParty->pPlayers[v49].classType == PLAYER_CLASS_WARLOCK )
+      {
+        ++pParty->pPlayers[v49].sMana;
+        if ( pParty->pPlayers[v49].sMana > pParty->pPlayers[v49].GetMaxMana() )
+          pParty->pPlayers[v49].sMana = pParty->pPlayers[v49].GetMaxMana();
+        redraw_flag = true;
+      }
+
+      //for lich
+      if ( pParty->pPlayers[v49].classType == PLAYER_CLASS_LICH )
+      {
+        for ( v31 = 0; v31 < 138; ++v31 )
         {
-          v34 = LODWORD(v21->pConditions[13]);
-          --v21->sHealth;
-          v35 = v21->sHealth;
-          if ( !(HIDWORD(v21->pConditions[13]) | v34) && v35 < 0 )
-            v21->pConditions[13] = pParty->uTimePlayed;
-          if ( v35 < 1 )
-          {
-            if ( v21->sHealth + v21->uEndurance + v21->GetItemsBonus(CHARACTER_ATTRIBUTE_ENDURANCE) >= 1
-              || (signed __int64)v21->pPlayerBuffs[11].uExpireTime > 0 )
-            {
-              v21->pConditions[13] = pParty->uTimePlayed;
-            }
-            else
-            {
-              if ( !v21->pConditions[14] )
-                v21->pConditions[14] = pParty->uTimePlayed;
-            }
-          }
-          v51 = 1;
-        }
-        if ( v45 )
-        {
-          v36 = (char *)&v21->sMana;
-          ++*(int *)v36;
-          if ( v21->sMana > v21->GetMaxMana() )
-            *(int *)v36 = v21->GetMaxMana();
+          if ( pParty->pPlayers[v49].pInventoryItemList[v31].uItemID == ITEM_LICH_JAR_FULL )
+            lich_jar_flag = true;
         }
-        if ( v48 && !v21->pConditions[14] && !v21->pConditions[16] )
-        {
-          v37 = v21->sHealth;
-          if ( v37 > v21->GetMaxHealth() / 2 )
-            v21->sHealth = v37 - 2;
-          v38 = v21->sMana;
-          if ( v38 > v21->GetMaxMana() / 2 )
-            v21->sMana = v38 - 2;
-        }
-        if ( v46 && !v21->pConditions[14] && !v21->pConditions[16] )
-        {
-          v39 = v21->sHealth;
-          if ( v39 > v21->GetMaxHealth() / 2 )
-            v21->sHealth = v39 - 1;
-          v40 = v21->sMana;
-          if ( v40 > 0 )
-            v21->sMana = v40 - 1;
-        }
-        ++v49;
-        if ( v49 >= 4 )
-        {
-          result = HIDWORD(pParty->uTimePlayed);
-          pParty->uLastRegenerationTime = pParty->uTimePlayed;
-          if ( !viewparams->bRedrawGameUI )
-          {
-            result = v51;
-            viewparams->bRedrawGameUI = v51;
-          }
-          return result;
-        }
-        goto LABEL_25;
+        lich_flag = true;
+      }
+      if ( lich_flag && !pParty->pPlayers[v49].pConditions[Condition_Dead]
+                     && !pParty->pPlayers[v49].pConditions[Condition_Eradicated] )
+      {
+        if ( pParty->pPlayers[v49].sHealth > pParty->pPlayers[v49].GetMaxHealth() / 2 )
+          pParty->pPlayers[v49].sHealth = pParty->pPlayers[v49].sHealth - 2;
+        if ( pParty->pPlayers[v49].sMana > pParty->pPlayers[v49].GetMaxMana() / 2 )
+          pParty->pPlayers[v49].sMana = pParty->pPlayers[v49].sMana - 2;
+      }
+      if ( lich_jar_flag )
+      {
+        ++pParty->pPlayers[v49].sMana;
+       if ( pParty->pPlayers[v49].sMana > pParty->pPlayers[v49].GetMaxMana() )
+          pParty->pPlayers[v49].sMana = pParty->pPlayers[v49].GetMaxMana();
+      }
+
+      //for zombie
+      if ( pParty->pPlayers[v49].pConditions[Condition_Zombie] )
+        zombie_flag = true;
+      if ( zombie_flag && !pParty->pPlayers[v49].pConditions[Condition_Dead]
+                       && !pParty->pPlayers[v49].pConditions[Condition_Eradicated] )
+      {
+        if ( pParty->pPlayers[v49].sHealth > pParty->pPlayers[v49].GetMaxHealth() / 2 )
+          pParty->pPlayers[v49].sHealth = pParty->pPlayers[v49].sHealth - 1;
+        if ( pParty->pPlayers[v49].sMana > 0 )
+          pParty->pPlayers[v49].sMana = pParty->pPlayers[v49].sMana - 1;
       }
     }
+    pParty->uLastRegenerationTime = pParty->uTimePlayed;
+    if ( !viewparams->bRedrawGameUI )
+      viewparams->bRedrawGameUI = redraw_flag;
   }
-  return result;
 }
 
 //----- (00493F79) --------------------------------------------------------
--- a/mm7_data.h	Sun Dec 01 23:43:03 2013 +0600
+++ b/mm7_data.h	Mon Dec 02 17:00:58 2013 +0600
@@ -1228,7 +1228,7 @@
 void sub_491E3A();
 int CycleCharacter(bool backwards);
 void __fastcall Rest(unsigned int uHoursToSleep);
-int _493938_regenerate();
+void _493938_regenerate();
 void init_summoned_item(struct stru351_summoned_item *_this, __int64 duration);
 void _494035_timed_effects__water_walking_damage__etc();
 unsigned int __fastcall _494820_training_time(unsigned int a1);