changeset 1517:c3da3c2985b8

Clean CastSpellInfo. (1)
author yoctozepto
date Wed, 04 Sep 2013 14:34:59 +0200
parents f3cd08b89476
children 091c5eb46a0e
files Actor.cpp CastSpellInfo.cpp CastSpellInfo.h _deleted.cpp mm7_2.cpp mm7_5.cpp mm7_6.cpp mm7_data.cpp
diffstat 8 files changed, 143 insertions(+), 162 deletions(-) [+]
line wrap: on
line diff
--- a/Actor.cpp	Tue Sep 03 21:23:39 2013 +0200
+++ b/Actor.cpp	Wed Sep 04 14:34:59 2013 +0200
@@ -2308,7 +2308,7 @@
   result = pPlayer->CanAct();
   if ( result )
   {
-    pCastSpellInfo.data()->_427D48(v1);
+    CastSpellInfoHelpers::_427D48();
     v4 = 0;
     v5 = pMapStats->GetMapInfo(pCurrentMapName);
     if ( v5 )
--- a/CastSpellInfo.cpp	Tue Sep 03 21:23:39 2013 +0200
+++ b/CastSpellInfo.cpp	Wed Sep 04 14:34:59 2013 +0200
@@ -25,8 +25,11 @@
 #include "texts.h"
 #include "LOD.h"
 
+const size_t CastSpellInfoCount = 10;
+std::array<CastSpellInfo, CastSpellInfoCount> pCastSpellInfo;
+
 //----- (00427E01) --------------------------------------------------------
-void CastSpellInfo::_427E01_cast_spell()
+void CastSpellInfoHelpers::_427E01_cast_spell()
 {
   int v2; // edi@1
   CastSpellInfo *pCastSpell; // ebx@2
@@ -306,9 +309,9 @@
   LODWORD(v733) = 0;
   v723 = 0;
   v727 = 0.0;
-  for(n = 0; n < 10; ++n)
+  for(n = 0; n < CastSpellInfoCount; ++n)
   {
-    pCastSpell = &this[n];
+    pCastSpell = &pCastSpellInfo[n];
     HIDWORD(v733) = (int)pCastSpell;
     if ( pCastSpell->spellnum == 0 )
       continue;
@@ -319,7 +322,7 @@
     if ( pCastSpell->field_8 & 0x3CA )
     {
       if ( !pParty->pPlayers[pCastSpell->uPlayerID].CanAct() )
-        this->_427D48(1);
+        _427D48();
       continue;
     }
     pPlayer = &pParty->pPlayers[pCastSpell->uPlayerID];
@@ -428,13 +431,13 @@
         //v646 = pPlayer;
         //v648 = sRecoveryTime;
         //v649 = pPlayer;
-        pParty->pTurnBasedPlayerRecoveryTimes[this[n].uPlayerID] = 100;
+        pParty->pTurnBasedPlayerRecoveryTimes[pCastSpellInfo[n].uPlayerID] = 100;
         pPlayer->SetRecoveryTime(sRecoveryTime);
         pTurnEngine->ApplyPlayerAction();
       }
       ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2u); // "Spell failed"
       pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
-      this[n].spellnum = 0;
+      pCastSpellInfo[n].spellnum = 0;
       pPlayer->sMana -= uRequiredMana;
       return;
     }
@@ -1214,7 +1217,7 @@
 					v114 = v118;
 				}
 				_this = (ItemGen *)(((unsigned int)(11 * v114) >> 5) + (v115 >> 2) + v113);
-				if ( (double)(signed int)this <= 307.2 )
+				if ( (double)(signed int)_this <= 307.2 )
 				{
 					v701.x = 0;
 					v701.y = 0;
@@ -3525,7 +3528,7 @@
 				++a2;
 				_this = (ItemGen *)((char *)_this + 4);
 			}
-			while ( (signed int)this < (signed int)&qword_A750D8 );
+			while ( (signed int)_this < (signed int)&qword_A750D8 );
 			v571 = pPlayer;
 			v572 = (char *)&pPlayer->sAgeModifier;
 			if ( pPlayer->sAgeModifier + 10 >= 120 )
@@ -4067,53 +4070,42 @@
   
 }
 //----- (00427DA0) --------------------------------------------------------
-unsigned int CastSpellInfo::PushCastSpellInfo(__int16 a2, __int16 uPlayerID, __int16 skill_level, __int16 a5, int spell_sound_id)
+unsigned int PushCastSpellInfo(__int16 a2, __int16 uPlayerID, __int16 skill_level, __int16 a5, int spell_sound_id)
 {
-  for ( uint i = 0; i < 10; i++ )
+  for (size_t i = 0; i < CastSpellInfoCount; i++)
   {
-    if ( !this[i].spellnum )
+    if (!pCastSpellInfo[i].spellnum)
     {
-      this[i].spellnum = a2;
-      this[i].uPlayerID = uPlayerID;
+      pCastSpellInfo[i].spellnum = a2;
+      pCastSpellInfo[i].uPlayerID = uPlayerID;
       if ( a5 & 0x10 )
-        this[i].uPlayerID_2 = uPlayerID;
-      this[i].field_6 = 0;
-      this[i].spell_target_pid = 0;
-      this[i].field_8 = a5;
-      this[i].forced_spell_skill_level = skill_level;
-      this[i].sound_id = spell_sound_id;
+        pCastSpellInfo[i].uPlayerID_2 = uPlayerID;
+      pCastSpellInfo[i].field_6 = 0;
+      pCastSpellInfo[i].spell_target_pid = 0;
+      pCastSpellInfo[i].field_8 = a5;
+      pCastSpellInfo[i].forced_spell_skill_level = skill_level;
+      pCastSpellInfo[i].sound_id = spell_sound_id;
       return i;
     }
   }
   return -1;
 }
 //----- (00427D48) --------------------------------------------------------
-void CastSpellInfo::_427D48(unsigned int uPlayerID)//Press S
+void CastSpellInfoHelpers::_427D48()
 {
-  CastSpellInfo *v2; // esi@1
-  signed int v3; // ebx@1
-
-  v2 = this;
-  v3 = 10;
-  do
+  for (size_t i = 0; i < CastSpellInfoCount; i++)
   {
-    if ( v2->spellnum )
+    if (pCastSpellInfo[i].spellnum && pCastSpellInfo[i].field_8 & 0x3CA)
     {
-      if ( v2->field_8 & 0x3CA )
-      {
-        v2->spellnum = 0;
-        pGUIWindow_Settings->Release();
-        pGUIWindow_Settings = 0;
-        pMouse->SetCursorBitmap("MICON1");
-        GameUI_Footer_TimeLeft = 0;
-        unk_50C9A0 = 0;
-        back_to_game();
-      }
+      pCastSpellInfo[i].spellnum = 0;
+      pGUIWindow_Settings->Release();
+      pGUIWindow_Settings = 0;
+      pMouse->SetCursorBitmap("MICON1");
+      GameUI_Footer_TimeLeft = 0;
+      unk_50C9A0 = 0;
+      back_to_game();
     }
-    ++v2;
-    --v3;
   }
-  while ( v3 );
 }
 //----- (0042777D) --------------------------------------------------------
 void _42777D_CastSpell_UseWand_ShootArrow(int a1, unsigned int uPlayerID, unsigned int a4, __int16 a5, int a6)
@@ -4316,8 +4308,7 @@
 
     if (a5 & 0x3CA)
     {
-      assert(sizeof(pCastSpellInfo) / sizeof(*pCastSpellInfo.data()) == 10);
-      for (uint i = 0; i < 10; ++i)
+      for (uint i = 0; i < CastSpellInfoCount; ++i)
         if (pCastSpellInfo[i].field_8 & 0x3CA)
         {
           pCastSpellInfo[i].spellnum = 0;
@@ -4325,8 +4316,7 @@
         }
     }
       
-    assert(sizeof(pCastSpellInfo) / sizeof(*pCastSpellInfo.data()) == 10);
-    for (uint i = 0; i < 10; ++i)
+    for (uint i = 0; i < CastSpellInfoCount; ++i)
     {
       auto spell = &pCastSpellInfo[i];
       if (!spell->spellnum)
@@ -4344,7 +4334,7 @@
       }
     }
 
-    int result = pCastSpellInfo.data()->PushCastSpellInfo(a1, uPlayerID, a4, a5, a6);
+    int result = PushCastSpellInfo(a1, uPlayerID, a4, a5, a6);
     if ( result != -1 )
     {
       if ( a5 & 2 )
@@ -4422,101 +4412,3 @@
       }
     }
 }
-
-const wchar_t *UIMessage2String(UIMessageType msg)
-{
-  #define CASE(xxx) case xxx: swprintf(b, wcslen(L"%03X/%s"), L"%03X/%s", msg, L#xxx); return b;
-  static wchar_t b[256]; // bad for threads
-  switch (msg)
-  {
-    CASE(UIMSG_SelectSpell)
-    CASE(UIMSG_ChangeGameState)
-    CASE(UIMSG_Attack)
-    CASE(UIMSG_PlayArcomage)
-    CASE(UIMSG_MainMenu_ShowPartyCreationWnd)
-    CASE(UIMSG_MainMenu_ShowLoadWindow)
-    CASE(UIMSG_ShowCredits)
-    CASE(UIMSG_ExitToWindows)
-    CASE(UIMSG_PlayerCreationChangeName)
-    CASE(UIMSG_PlayerCreationClickPlus)
-    CASE(UIMSG_PlayerCreationClickMinus)
-    CASE(UIMSG_PlayerCreationSelectActiveSkill)
-    CASE(UIMSG_PlayerCreationSelectClass)
-    CASE(UIMSG_PlayerCreationClickOK)
-    CASE(UIMSG_PlayerCreationClickReset)
-    CASE(UIMSG_ClickBooksBtn)
-    CASE(UIMSG_PlayerCreationRemoveUpSkill)
-    CASE(UIMSG_PlayerCreationRemoveDownSkill)
-    CASE(UIMSG_SPellbook_ShowHightlightedSpellInfo)
-    CASE(UIMSG_LoadGame)
-    CASE(UIMSG_SaveGame)
-    CASE(UIMSG_ShowStatus_DateTime)
-    CASE(UIMSG_ShowStatus_ManaHP)
-    CASE(UIMSG_ShowStatus_Player)
-    CASE(UIMSG_Wait5Minutes)
-    CASE(UIMSG_Wait1Hour)
-    CASE(UIMSG_ShowStatus_Food)
-    CASE(UIMSG_ShowStatus_Funds)
-    CASE(UIMSG_QuickReference)
-    CASE(UIMSG_GameMenuButton)
-    CASE(UIMSG_AlreadyResting)
-    CASE(UIMSG_SelectCharacter)
-    CASE(UIMSG_ChangeSoundVolume)
-    CASE(UIMSG_ChangeMusicVolume)
-    CASE(UIMSG_Escape)
-    CASE(UIMSG_PlayerCreation_SelectAttribute)
-    CASE(UIMSG_InventoryLeftClick)
-    CASE(UIMSG_SkillUp)
-    CASE(UIMSG_GameMenu_ReturnToGame)
-    CASE(UIMSG_StartNewGame)
-    CASE(UIMSG_Game_OpenLoadGameDialog)
-    CASE(UIMSG_Game_OpenSaveGameDialog)
-    CASE(UIMSG_Game_OpenOptionsDialog)
-    CASE(UIMSG_SetGraphicsMode)
-    CASE(UIMSG_Quit)
-    CASE(UIMSG_StartHireling1Dialogue)
-    CASE(UIMSG_StartHireling2Dialogue)
-    CASE(UIMSG_SelectNPCDialogueOption)
-    CASE(UIMSG_CastSpellFromBook)
-    CASE(UIMSG_PlayerCreation_VoicePrev)
-    CASE(UIMSG_PlayerCreation_VoiceNext)
-    CASE(UIMSG_StartNPCDialogue)
-    CASE(UIMSG_ArrowUp)
-    CASE(UIMSG_DownArrow)
-    CASE(UIMSG_SaveLoadBtn)
-    CASE(UIMSG_SelectLoadSlot)
-    CASE(UIMSG_Cancel)
-    CASE(UIMSG_ExitRest)
-    CASE(UIMSG_PlayerCreation_FacePrev)
-    CASE(UIMSG_PlayerCreation_FaceNext)
-    CASE(UIMSG_CycleCharacters)
-    CASE(UIMSG_SetTurnSpeed)
-    CASE(UIMSG_ToggleWalkSound)
-    CASE(UIMSG_ChangeVoiceVolume)
-    CASE(UIMSG_ToggleShowDamage)
-    CASE(UIMSG_ScrollNPCPanel)
-    CASE(UIMSG_ShowFinalWindow)
-    CASE(UIMSG_OpenQuestBook)
-    CASE(UIMSG_OpenAutonotes)
-    CASE(UIMSG_OpenMapBook)
-    CASE(UIMSG_OpenCalendar)
-    CASE(UIMSG_OpenHistoryBook)
-    CASE(UIMSG_ToggleAlwaysRun)
-    CASE(UIMSG_ToggleFlipOnExit)
-    CASE(UIMSG_Game_Action)
-    CASE(UIMSG_RentRoom)
-    CASE(UIMSG_TransitionUI_Confirm)
-    CASE(UIMSG_OpenKeyMappingOptions)
-    CASE(UIMSG_SelectKeyPage1)
-    CASE(UIMSG_SelectKeyPage2)
-    CASE(UIMSG_ResetKeyMapping)
-    CASE(UIMSG_ChangeKeyButton)
-    CASE(UIMSG_OpenVideoOptions)
-    CASE(UIMSG_ToggleBloodsplats)
-    CASE(UIMSG_ToggleColoredLights)
-    CASE(UIMSG_ToggleTint)
-    default:
-      swprintf(b, wcslen(L"UIMSG_%03X") , L"UIMSG_%03X", msg); return b;
-  };
-  #undef CASE
-}
\ No newline at end of file
--- a/CastSpellInfo.h	Tue Sep 03 21:23:39 2013 +0200
+++ b/CastSpellInfo.h	Wed Sep 04 14:34:59 2013 +0200
@@ -1,6 +1,11 @@
 #pragma once
 #include <array>
 
+namespace CastSpellInfoHelpers
+{
+  void _427D48();
+  void _427E01_cast_spell();
+};
 
 /*  271 */
 #pragma pack(push, 1)
@@ -17,10 +22,7 @@
     sound_id = 0;
   }
 
-  void _427D48(unsigned int uPlayerID);
-  unsigned int PushCastSpellInfo(__int16 a2, __int16 uPlayerID, __int16 skill_level, __int16 a5, int sound_id);
   struct GUIWindow *GetCastSpellInInventoryWindow();
-  void _427E01_cast_spell();
 
   __int16 spellnum;
   unsigned __int16 uPlayerID;
@@ -32,7 +34,3 @@
   int sound_id;
 };
 #pragma pack(pop)
-
-
-extern std::array<CastSpellInfo, 10> pCastSpellInfo;
-extern CastSpellInfo stru_50CDB4; // idb
--- a/_deleted.cpp	Tue Sep 03 21:23:39 2013 +0200
+++ b/_deleted.cpp	Wed Sep 04 14:34:59 2013 +0200
@@ -12276,4 +12276,101 @@
     while ( v16 != 1 );
   }
 }
+const wchar_t *UIMessage2String(UIMessageType msg)
+{
+  #define CASE(xxx) case xxx: swprintf(b, wcslen(L"%03X/%s"), L"%03X/%s", msg, L#xxx); return b;
+  static wchar_t b[256]; // bad for threads
+  switch (msg)
+  {
+    CASE(UIMSG_SelectSpell)
+    CASE(UIMSG_ChangeGameState)
+    CASE(UIMSG_Attack)
+    CASE(UIMSG_PlayArcomage)
+    CASE(UIMSG_MainMenu_ShowPartyCreationWnd)
+    CASE(UIMSG_MainMenu_ShowLoadWindow)
+    CASE(UIMSG_ShowCredits)
+    CASE(UIMSG_ExitToWindows)
+    CASE(UIMSG_PlayerCreationChangeName)
+    CASE(UIMSG_PlayerCreationClickPlus)
+    CASE(UIMSG_PlayerCreationClickMinus)
+    CASE(UIMSG_PlayerCreationSelectActiveSkill)
+    CASE(UIMSG_PlayerCreationSelectClass)
+    CASE(UIMSG_PlayerCreationClickOK)
+    CASE(UIMSG_PlayerCreationClickReset)
+    CASE(UIMSG_ClickBooksBtn)
+    CASE(UIMSG_PlayerCreationRemoveUpSkill)
+    CASE(UIMSG_PlayerCreationRemoveDownSkill)
+    CASE(UIMSG_SPellbook_ShowHightlightedSpellInfo)
+    CASE(UIMSG_LoadGame)
+    CASE(UIMSG_SaveGame)
+    CASE(UIMSG_ShowStatus_DateTime)
+    CASE(UIMSG_ShowStatus_ManaHP)
+    CASE(UIMSG_ShowStatus_Player)
+    CASE(UIMSG_Wait5Minutes)
+    CASE(UIMSG_Wait1Hour)
+    CASE(UIMSG_ShowStatus_Food)
+    CASE(UIMSG_ShowStatus_Funds)
+    CASE(UIMSG_QuickReference)
+    CASE(UIMSG_GameMenuButton)
+    CASE(UIMSG_AlreadyResting)
+    CASE(UIMSG_SelectCharacter)
+    CASE(UIMSG_ChangeSoundVolume)
+    CASE(UIMSG_ChangeMusicVolume)
+    CASE(UIMSG_Escape)
+    CASE(UIMSG_PlayerCreation_SelectAttribute)
+    CASE(UIMSG_InventoryLeftClick)
+    CASE(UIMSG_SkillUp)
+    CASE(UIMSG_GameMenu_ReturnToGame)
+    CASE(UIMSG_StartNewGame)
+    CASE(UIMSG_Game_OpenLoadGameDialog)
+    CASE(UIMSG_Game_OpenSaveGameDialog)
+    CASE(UIMSG_Game_OpenOptionsDialog)
+    CASE(UIMSG_SetGraphicsMode)
+    CASE(UIMSG_Quit)
+    CASE(UIMSG_StartHireling1Dialogue)
+    CASE(UIMSG_StartHireling2Dialogue)
+    CASE(UIMSG_SelectNPCDialogueOption)
+    CASE(UIMSG_CastSpellFromBook)
+    CASE(UIMSG_PlayerCreation_VoicePrev)
+    CASE(UIMSG_PlayerCreation_VoiceNext)
+    CASE(UIMSG_StartNPCDialogue)
+    CASE(UIMSG_ArrowUp)
+    CASE(UIMSG_DownArrow)
+    CASE(UIMSG_SaveLoadBtn)
+    CASE(UIMSG_SelectLoadSlot)
+    CASE(UIMSG_Cancel)
+    CASE(UIMSG_ExitRest)
+    CASE(UIMSG_PlayerCreation_FacePrev)
+    CASE(UIMSG_PlayerCreation_FaceNext)
+    CASE(UIMSG_CycleCharacters)
+    CASE(UIMSG_SetTurnSpeed)
+    CASE(UIMSG_ToggleWalkSound)
+    CASE(UIMSG_ChangeVoiceVolume)
+    CASE(UIMSG_ToggleShowDamage)
+    CASE(UIMSG_ScrollNPCPanel)
+    CASE(UIMSG_ShowFinalWindow)
+    CASE(UIMSG_OpenQuestBook)
+    CASE(UIMSG_OpenAutonotes)
+    CASE(UIMSG_OpenMapBook)
+    CASE(UIMSG_OpenCalendar)
+    CASE(UIMSG_OpenHistoryBook)
+    CASE(UIMSG_ToggleAlwaysRun)
+    CASE(UIMSG_ToggleFlipOnExit)
+    CASE(UIMSG_Game_Action)
+    CASE(UIMSG_RentRoom)
+    CASE(UIMSG_TransitionUI_Confirm)
+    CASE(UIMSG_OpenKeyMappingOptions)
+    CASE(UIMSG_SelectKeyPage1)
+    CASE(UIMSG_SelectKeyPage2)
+    CASE(UIMSG_ResetKeyMapping)
+    CASE(UIMSG_ChangeKeyButton)
+    CASE(UIMSG_OpenVideoOptions)
+    CASE(UIMSG_ToggleBloodsplats)
+    CASE(UIMSG_ToggleColoredLights)
+    CASE(UIMSG_ToggleTint)
+    default:
+      swprintf(b, wcslen(L"UIMSG_%03X") , L"UIMSG_%03X", msg); return b;
+  };
+  #undef CASE
+}
 */
\ No newline at end of file
--- a/mm7_2.cpp	Tue Sep 03 21:23:39 2013 +0200
+++ b/mm7_2.cpp	Wed Sep 04 14:34:59 2013 +0200
@@ -3916,7 +3916,7 @@
   pEventTimer->Pause();
   pMiscTimer->Pause();
   pParty->uFlags = 2;
-  pCastSpellInfo.data()->_427D48(1);
+  CastSpellInfoHelpers::_427D48();
   ResetCursor_Palettes_LODs_Level_Audio_SFT_Windows();
   DoPrepareWorld(0, (_0_box_loading_1_fullscreen == 0) + 1);
   pMiscTimer->Resume();
--- a/mm7_5.cpp	Tue Sep 03 21:23:39 2013 +0200
+++ b/mm7_5.cpp	Wed Sep 04 14:34:59 2013 +0200
@@ -1688,7 +1688,7 @@
           {
             pParty->field_6E4 = 0;
             pParty->field_6E0 = 0;
-            pCastSpellInfo.data()->_427D48(1);
+            CastSpellInfoHelpers::_427D48();
             DialogueEnding();
             pEventTimer->Pause();
             pGameLoadingUI_ProgressBar->Initialize(GUIProgressBar::TYPE_Box);
@@ -3235,7 +3235,7 @@
       }
     }
   }
-  pCastSpellInfo.data()->_427E01_cast_spell();
+  CastSpellInfoHelpers::_427E01_cast_spell();
 }
 
 //----- (004356FF) --------------------------------------------------------
--- a/mm7_6.cpp	Tue Sep 03 21:23:39 2013 +0200
+++ b/mm7_6.cpp	Wed Sep 04 14:34:59 2013 +0200
@@ -1110,7 +1110,7 @@
   if (!player->CanAct())
     return;
 
-  pCastSpellInfo.data()->_427D48(uActiveCharacter);
+  CastSpellInfoHelpers::_427D48();
     //v3 = 0;
   if (pParty->Invisible())
     pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Reset();
@@ -2062,7 +2062,7 @@
                 v24 = pPlayers[uActiveCharacter]->GetAttackRecoveryTime(false);
                 if ( !pParty->bTurnBasedModeOn )
                   pPlayers[uActiveCharacter]->SetRecoveryTime((signed __int64)(flt_6BE3A4_debug_recmod1 * (double)v24 * 2.133333333333333));
-                pCastSpellInfo.data()->_427D48(uActiveCharacter);
+                CastSpellInfoHelpers::_427D48();
                 pTurnEngine->ApplyPlayerAction();
               }
             }
--- a/mm7_data.cpp	Tue Sep 03 21:23:39 2013 +0200
+++ b/mm7_data.cpp	Wed Sep 04 14:34:59 2013 +0200
@@ -33,12 +33,6 @@
 #include "MapInfo.h"
 struct MapStats *pMapStats;
 
-
-
-#include "CastSpellInfo.h"
-std::array<CastSpellInfo, 10> pCastSpellInfo;
-CastSpellInfo stru_50CDB4; // idb
-
 #include "Viewport.h"
 struct Viewport *pViewport = new Viewport;
 struct ViewingParams *viewparams = new ViewingParams;