diff CastSpellInfo.cpp @ 1517:c3da3c2985b8

Clean CastSpellInfo. (1)
author yoctozepto
date Wed, 04 Sep 2013 14:34:59 +0200
parents 965af46e8793
children 4c787c28ddce
line wrap: on
line diff
--- 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