changeset 1273:fbb7428fa58c

PlayerCreation_ComputeAttributeBonus cleanup Player::IncreaseAttribute cleanup
author Grumpy7
date Sat, 15 Jun 2013 03:00:36 +0200
parents 19a4809e1da0
children 351bc06722f2
files Player.cpp Player.h UIPartyCreation.cpp mm7_5.cpp mm7_data.h
diffstat 5 files changed, 103 insertions(+), 155 deletions(-) [+]
line wrap: on
line diff
--- a/Player.cpp	Sat Jun 15 02:31:27 2013 +0200
+++ b/Player.cpp	Sat Jun 15 03:00:36 2013 +0200
@@ -138,75 +138,61 @@
 
 
 //----- (00490913) --------------------------------------------------------
-signed int __cdecl PlayerCreation_ComputeAttributeBonus()
+signed int __cdecl PlayerCreation_GetUnspentAttributePointCount()
 {
   signed int v0; // edi@1
-  signed int v1; // esi@1
-  int v2; // ebx@2
-  int v3; // ecx@17
+  int raceId; // ebx@2
   signed int v4; // eax@17
   int v5; // edx@18
   signed int v6; // ecx@18
-  signed int v8; // [sp+Ch] [bp-8h]@1
-  signed int v9; // [sp+10h] [bp-4h]@2
-
-  v8 = 50;
+  signed int remainingStatPoints; // [sp+Ch] [bp-8h]@1
+
+  remainingStatPoints = 50;
   v0 = 50;
-  v1 = 0;
-  do
-  {
-    v9 = 0;
-    v2 = 7 * pParty->pPlayers[v1].GetRace();
-    do
-    {
-      if ( v9 )
+  for (int playerNum = 0; playerNum < 4; playerNum++)
+  {
+    raceId = pParty->pPlayers[playerNum].GetRace();
+    for (int statNum = 0; statNum <= 6; statNum++)
+    {
+      switch ( statNum )
       {
-        switch ( v9 )
-        {
-          case 1:
-            v0 = pParty->pPlayers[v1].uIntelligence;
-            break;
-          case 2:
-            v0 = pParty->pPlayers[v1].uWillpower;
-            break;
-          case 3:
-            v0 = pParty->pPlayers[v1].uEndurance;
-            break;
-          case 4:
-            v0 = pParty->pPlayers[v1].uAccuracy;
-            break;
-          case 5:
-            v0 = pParty->pPlayers[v1].uSpeed;
-            break;
-          case 6:
-            v0 = pParty->pPlayers[v1].uLuck;
-            break;
-        }
+      case 0:
+        v0 = pParty->pPlayers[playerNum].uMight;
+        break;
+      case 1:
+        v0 = pParty->pPlayers[playerNum].uIntelligence;
+        break;
+      case 2:
+        v0 = pParty->pPlayers[playerNum].uWillpower;
+        break;
+      case 3:
+        v0 = pParty->pPlayers[playerNum].uEndurance;
+        break;
+      case 4:
+        v0 = pParty->pPlayers[playerNum].uAccuracy;
+        break;
+      case 5:
+        v0 = pParty->pPlayers[playerNum].uSpeed;
+        break;
+      case 6:
+        v0 = pParty->pPlayers[playerNum].uLuck;
+        break;
+      }
+      v4 = StatTable[raceId][statNum].uBaseValue;
+      if ( v0 >= v4 )
+      {
+        v5 = StatTable[raceId][statNum].uDroppedStep;
+        v6 = StatTable[raceId][statNum].uBaseStep;
       }
       else
       {
-        v0 = pParty->pPlayers[v1].uMight;
-      }
-      v3 = v2 + v9;
-      v4 = StatTable[0][v3].uBaseValue;
-      if ( v0 >= v4 )
-      {
-        v5 = StatTable[0][v3].uDroppedStep;
-        v6 = StatTable[0][v3].uBaseStep;
+        v5 = StatTable[raceId][statNum].uBaseStep;
+        v6 = StatTable[raceId][statNum].uDroppedStep;
       }
-      else
-      {
-        v5 = StatTable[0][v3].uBaseStep;
-        v6 = StatTable[0][v3].uDroppedStep;
-      }
-      v8 += v5 * (v4 - v0) / v6;
-      ++v9;
-    }
-    while ( v9 <= 6 );
-    ++v1;
-  }
-  while ( v1 < 4 );
-  return v8;
+      remainingStatPoints += v5 * (v4 - v0) / v6;
+    }
+  }
+  return remainingStatPoints;
 }
 
 
@@ -6457,100 +6443,62 @@
 
 //----- (004905F5) --------------------------------------------------------
 //signed int __thiscall PartyCreation_BtnPlusClick(Player *this, int eAttribute)
-int Player::IncreaseAttribute(int eAttribute)
-{
-  Player *v2; // esi@1
-  int v3; // eax@1
-  int v4; // ebx@1
-  signed int v5; // edi@1
-  int v6; // eax@8
-  signed int v7; // eax@17
+void Player::IncreaseAttribute( int eAttribute )
+{
+  int raceId; // eax@1
+  int maxValue; // ebx@1
+  signed int baseStep; // edi@1
+  signed int tmp; // eax@17
   signed int result; // eax@18
-  int v9; // [sp+Ch] [bp-8h]@1
-  signed int v10; // [sp+10h] [bp-4h]@1
-
-  v2 = this;
-  v3 = eAttribute + 7 * GetRace();
-  v4 = StatTable[0][v3].uMaxValue;
-  v5 = StatTable[0][v3].uBaseStep;
-  v9 = StatTable[0][v3].uBaseValue;
-  v10 = StatTable[0][v3].uDroppedStep;
-  PlayerCreation_ComputeAttributeBonus();
-  if ( eAttribute )
-  {
-    switch ( eAttribute )
-    {
-      case 1:
-        v6 = v2->uIntelligence;
-        break;
-      case 2:
-        v6 = v2->uWillpower;
-        break;
-      case 3:
-        v6 = v2->uEndurance;
-        break;
-      case 4:
-        v6 = v2->uAccuracy;
-        break;
-      case 5:
-        v6 = v2->uSpeed;
-        break;
-      case 6:
-        v6 = v2->uLuck;
-        break;
-      default:
-        v6 = eAttribute;
-        break;
-    }
-  }
-  else
-  {
-    v6 = v2->uMight;
-  }
-  if ( v6 < v9 )
-  {
-    v7 = v5;
-    v5 = v10;
-    v10 = v7;
-  }
-  result = PlayerCreation_ComputeAttributeBonus();
-  if ( result >= v10 )
-  {
-    if ( eAttribute )
-    {
-      switch ( eAttribute )
-      {
-        case 1:
-          result = (signed int)&v2->uIntelligence;
-          break;
-        case 2:
-          result = (signed int)&v2->uWillpower;
-          break;
-        case 3:
-          result = (signed int)&v2->uEndurance;
-          break;
-        case 4:
-          result = (signed int)&v2->uAccuracy;
-          break;
-        case 5:
-          result = (signed int)&v2->uSpeed;
-          break;
-        default:
-          result = eAttribute - 6;
-          if ( eAttribute != 6 )
-            return result;
-          result = (signed int)&v2->uLuck;
-          break;
-      }
-    }
-    else
-    {
-      result = (signed int)&v2->uMight;
-    }
-    if ( v5 + *(short *)result <= v4 )
-      *(short *)result += v5;
-  }
-  return result;
+  int baseValue; // [sp+Ch] [bp-8h]@1
+  signed int droppedStep; // [sp+10h] [bp-4h]@1
+  unsigned short* statToChange;
+
+  raceId = GetRace();
+  maxValue = StatTable[raceId][eAttribute].uMaxValue;
+  baseStep = StatTable[raceId][eAttribute].uBaseStep;
+  baseValue = StatTable[raceId][eAttribute].uBaseValue;
+  droppedStep = StatTable[raceId][eAttribute].uDroppedStep;
+  PlayerCreation_GetUnspentAttributePointCount();
+  switch ( eAttribute )
+  {
+  case 0:
+    statToChange = &this->uMight;
+    break;
+  case 1:
+    statToChange = &this->uIntelligence;
+    break;
+  case 2:
+    statToChange = &this->uWillpower;
+    break;
+  case 3:
+    statToChange = &this->uEndurance;
+    break;
+  case 4:
+    statToChange = &this->uAccuracy;
+    break;
+  case 5:
+    statToChange = &this->uSpeed;
+    break;
+  case 6:
+    statToChange = &this->uLuck;
+  default:
+    assert(false);
+    return;
+    break;
+  }
+  if ( *statToChange < baseValue )
+  {
+    tmp = baseStep;
+    baseStep = droppedStep;
+    droppedStep = tmp;
+  }
+  result = PlayerCreation_GetUnspentAttributePointCount();
+  if ( result >= droppedStep )
+  {
+    if ( baseStep + *statToChange <= maxValue )
+      *statToChange += baseStep;
+  }
 }
 
 //----- (0049070F) --------------------------------------------------------
--- a/Player.h	Sat Jun 15 02:31:27 2013 +0200
+++ b/Player.h	Sat Jun 15 03:00:36 2013 +0200
@@ -543,7 +543,7 @@
   void Reset(PLAYER_CLASS_TYPE classType);
   PLAYER_SKILL_TYPE GetSkillIdxByOrder(signed int order);
   void DecreaseAttribute(int eAttribute);
-  int IncreaseAttribute(int eAttribute);
+  void IncreaseAttribute(int eAttribute);
   void Player::Zero();
   unsigned int GetStatColor(int uStat);
   bool DiscardConditionIfLastsLongerThan(unsigned int uCondition, unsigned __int64 uTime);
--- a/UIPartyCreation.cpp	Sat Jun 15 02:31:27 2013 +0200
+++ b/UIPartyCreation.cpp	Sat Jun 15 03:00:36 2013 +0200
@@ -454,7 +454,7 @@
 
   pTextCenter = pFontCreate->AlignText_Center(0x5C, pGlobalTXT_LocalizationStrings[30]);// "Bonus"
   pGUIWindow_CurrentMenu->DrawText(pFontCreate, pTextCenter + 533, 394, uColor1, pGlobalTXT_LocalizationStrings[30], 0, 0, 0);
-  pBonusNum = PlayerCreation_ComputeAttributeBonus();
+  pBonusNum = PlayerCreation_GetUnspentAttributePointCount();
   sprintf(pTmpBuf.data(), "%d", pBonusNum);
   pTextCenter = pFontCreate->AlignText_Center(84, pTmpBuf.data());
   pGUIWindow_CurrentMenu->DrawText(pFontCreate, pTextCenter + 530, 410, uColorWhite, pTmpBuf.data(), 0, 0, 0);
--- a/mm7_5.cpp	Sat Jun 15 02:31:27 2013 +0200
+++ b/mm7_5.cpp	Sat Jun 15 03:00:36 2013 +0200
@@ -3409,7 +3409,7 @@
           break;
         case UIMSG_PlayerCreationClickOK:
           GUIWindow::Create(580, 431, 0, 0, WINDOW_PressedButton2, (int)pPlayerCreationUI_BtnOK, 0);
-          if ( PlayerCreation_ComputeAttributeBonus() || !PlayerCreation_Chose4Skills() )
+          if ( PlayerCreation_GetUnspentAttributePointCount() || !PlayerCreation_Chose4Skills() )
             GameUI_Footer_TimeLeft = GetTickCount() + 4000;
           else
             uGameState = GAME_STATE_STARTING_NEW_GAME;
--- a/mm7_data.h	Sat Jun 15 02:31:27 2013 +0200
+++ b/mm7_data.h	Sat Jun 15 03:00:36 2013 +0200
@@ -1448,7 +1448,7 @@
 void __fastcall RGB2HSV(float *a1, float *a2, float a3, float a4, float a5, float *a6);
 unsigned int ReplaceHSV(unsigned int uColor, float a2, float gamma, float a4);
 signed int __cdecl PlayerCreation_Chose4Skills();
-signed int __cdecl PlayerCreation_ComputeAttributeBonus();
+signed int __cdecl PlayerCreation_GetUnspentAttributePointCount();
 void LoadPlayerPortraintsAndVoices();
 int __fastcall ReloadPlayerPortraits(int, int); // weak
 void sub_491E3A();