changeset 774:c319601893af

Слияние
author Ritor1
date Sun, 24 Mar 2013 00:32:13 +0600
parents b1b991f67d40 (current diff) 67b77b052ef3 (diff)
children 7994986603d5 a821bbace194
files Events.cpp mm7_3.cpp mm7_data.cpp
diffstat 36 files changed, 437 insertions(+), 462 deletions(-) [+]
line wrap: on
line diff
--- a/Arcomage.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/Arcomage.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -1395,7 +1395,7 @@
   v4 = am_sounds;
   do
   {
-    pSoundList->_4A9DCD((unsigned __int16)*v4, 1);
+    pSoundList->UnloadSound((unsigned __int16)*v4, 1);
     ++v4;
   }
   while ( (signed int)v4 <= (signed int)&unk_4FAA20 );
--- a/AudioPlayer.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/AudioPlayer.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -78,7 +78,7 @@
 
   pSoundList = this;
   a2 = 1;
-  if ( (signed int)this->uNumSounds > 1 )
+  if ( sNumSounds > 1 )
   {
     v2 = 1;
     //while ( 1 )
@@ -100,7 +100,7 @@
       if ( !pType )
         //goto LABEL_15;
 	  {
-		LOBYTE(pSoundList->pSounds[v2].bDecompressed) = 0;
+		pSoundList->pSounds[v2].bDecompressed = false;
 		goto LABEL_16;
 	  }
       v8 = pType - 1;
@@ -123,23 +123,23 @@
           if ( !AIL_decompress_ADPCM(&pInfo, &pSoundList->pSounds[v2].p3DSound, &v12) )
           {
             pSoundList->pSounds[v2].p3DSound = 0;
-            LOBYTE(pSoundList->pSounds[v2].bDecompressed) = 1;
+            pSoundList->pSounds[v2].bDecompressed = true;
           }
         }
         goto LABEL_16;
       }
 //LABEL_15:
-      LOBYTE(pSoundList->pSounds[v2].bDecompressed) = 0;
+      pSoundList->pSounds[v2].bDecompressed = false;
       goto LABEL_16;
     }
 	pSoundList->pSounds[v2].p3DSound = pSoundList->pSounds[v2].pSoundData[0];
 LABEL_16:
-    pSoundList->_4A9DCD(a2, 1);
+    pSoundList->UnloadSound(a2, 1);
 LABEL_17:
       ++a2;
       ++v2;
 	}
-    while ( a2 < (signed int)pSoundList->uNumSounds );
+    while ( a2 < pSoundList->sNumSounds );
   }
 }
 
@@ -148,12 +148,12 @@
 {
   AILSOUNDINFO v24; // [sp+84h] [bp-28h]@23
 
-  if (bNoSound || !uNumSounds)
+  if (bNoSound || !sNumSounds)
     return 0;
 
   uint       uSoundIdx = 0;
   SoundDesc *pSound = nullptr;
-  for (uint i = 1; i < uNumSounds; ++i)
+  for (uint i = 1; i < sNumSounds; ++i)
     if (pSounds[i].uSoundID == a1)
     {
       uSoundIdx = i;
@@ -202,7 +202,7 @@
         {
           pSound->p3DSound = nullptr;
           pSound->bDecompressed = true;
-          _4A9DCD(uSoundIdx, 0);
+          UnloadSound(uSoundIdx, 0);
         }
       }
       return uSoundIdx;
@@ -240,7 +240,7 @@
   //v8 = this->uNumSounds == 0;
   //v9 = (this->uNumSounds & 0x80000000u) != 0;
   v26 = 0;
-  if (!uNumSounds)
+  if (!sNumSounds)
     return 0;
 
 
@@ -262,7 +262,7 @@
       ++v26;
       v25 += 120;
       v24 += 120;
-      if ( v26 >= (signed int)uNumSounds )
+      if ( v26 >= (signed int)sNumSounds )
         return 0;
     }
     v12 = 0;
@@ -322,7 +322,7 @@
 
   v1 = this;
   v2 = 0;
-  if ( (signed int)this->uNumSounds > 0 )
+  if ( (signed int)this->sNumSounds > 0 )
   {
     v3 = 0;
     do
@@ -339,7 +339,7 @@
       ++v2;
       ++v3;
     }
-    while ( v2 < (signed int)v1->uNumSounds );
+    while ( v2 < (signed int)v1->sNumSounds );
   }
   return result;
 }
@@ -356,7 +356,7 @@
 
   v2 = this;
   v3 = 0;
-  for ( i = 0; i < (signed int)v2->uNumSounds; ++v3 )
+  for ( i = 0; i < (signed int)v2->sNumSounds; ++v3 )
   {
     v5 = &v2->pSounds[v3];
     v6 = v5->eType;
@@ -375,31 +375,22 @@
 }
 
 //----- (004A9DCD) --------------------------------------------------------
-void SoundList::_4A9DCD(unsigned int uSoundID, char a3)
+void SoundList::UnloadSound(unsigned int uSoundID, char a3)
 {
-  unsigned int v3; // esi@1
-  //SoundList *v4; // edi@1
-  SoundDesc *v5; // eax@1
-  void *v6; // ecx@8
-
-  v3 = uSoundID;
-  //v4 = this;
-  v5 = &this->pSounds[uSoundID];
-  if ( v5->eType != SOUND_DESC_SYSTEM )
+  if ( pSounds[uSoundID].eType != SOUND_DESC_SYSTEM )
   {
-    if ( v5->uFlags & SOUND_DESC_SWAP && v5->p3DSound && a3 )
+    if ( (pSounds[uSoundID].uFlags & SOUND_DESC_SWAP) && pSounds[uSoundID].p3DSound && a3 )
     {
-      if ( LOBYTE(v5->bDecompressed) )
-        AIL_mem_free_lock(v5->p3DSound);
-      pSounds[v3].p3DSound = 0;
-      pSounds[v3].uFlags &= ~SOUND_DESC_SYSTEM;
+      if ( pSounds[uSoundID].bDecompressed)
+        AIL_mem_free_lock(pSounds[uSoundID].p3DSound);
+      pSounds[uSoundID].p3DSound = 0;
+      pSounds[uSoundID].uFlags &= ~SOUND_DESC_SYSTEM;
     }
-    v6 = pSounds[v3].pSoundData[0];
-    if ( v6 )
+    if ( pSounds[uSoundID].pSoundData[0] )
     {
-      ReleaseSoundData(v6);
-      pSounds[v3].pSoundData[0] = 0;
-      pSounds[v3].uFlags &= ~SOUND_DESC_SYSTEM;
+      ReleaseSoundData(pSounds[uSoundID].pSoundData[0]);
+      pSounds[uSoundID].pSoundData[0] = NULL;
+      pSounds[uSoundID].uFlags &= ~SOUND_DESC_SYSTEM;
     }
   }
 }
@@ -418,16 +409,16 @@
   if ( !v2 )
     Abortf("Unable to save dsounds.bin!");
   fwrite(v1, 4u, 1u, v2);
-  fwrite(v1->pSounds, 0x78u, v1->uNumSounds, v3);
+  fwrite(v1->pSounds, 0x78u, v1->sNumSounds, v3);
   fclose(v3);
 }
 
 //----- (004A9E89) --------------------------------------------------------
 void *SoundList::FromFile(void *pSerialized)
 {
-  uNumSounds = *(int *)pSerialized;
-  pSounds = (SoundDesc *)pAllocator->AllocNamedChunk(pSounds, 120 * uNumSounds, "Snd Des.");
-  return memcpy(pSounds, (char *)pSerialized + 4, 120 * uNumSounds);
+  sNumSounds = *(int *)pSerialized;
+  pSounds = (SoundDesc *)pAllocator->AllocNamedChunk(pSounds, 120 * sNumSounds, "Snd Des.");
+  return memcpy(pSounds, (char *)pSerialized + 4, 120 * sNumSounds);
 }
 
 //----- (004A9ED0) --------------------------------------------------------
@@ -457,7 +448,7 @@
   pAllocator->FreeChunk(this->pSounds);
   v3 = 0;
   v2->pSounds = 0;
-  v2->uNumSounds = 0;
+  v2->sNumSounds = 0;
   v4 = fopen(Args, "r");
   File = v4;
   if ( !v4 )
@@ -477,14 +468,14 @@
     v5 = Argsa;
     v3 = 0;
   }
-  v2->uNumSounds = v5;
+  v2->sNumSounds = v5;
   v6 = pAllocator->AllocNamedChunk(v2->pSounds, 120 * v5, "Snd Des.");
   v2->pSounds = (SoundDesc *)v6;
   if ( v6 == (void *)v3 )
     Abortf("SoundListClass::load - Out of Memory!");
-  memset(v6, v3, 120 * v2->uNumSounds);
+  memset(v6, v3, 120 * v2->sNumSounds);
   v7 = File;
-  v2->uNumSounds = v3;
+  v2->sNumSounds = v3;
   fseek(v7, v3, v3);
   for ( i = fgets(&Buf, 490, File); i; i = fgets(&Buf, 490, File) )
   {
@@ -492,10 +483,10 @@
     memcpy(&v19, txt_file_frametable_parser(&Buf, &v18), sizeof(v19));
     if ( v19.uPropCount && *v19.pProperties[0] != 47 )
     {
-      sprintf(v2->pSounds[v2->uNumSounds].pSoundName, "%s", v19.pProperties[0]);
+      sprintf(v2->pSounds[v2->sNumSounds].pSoundName, "%s", v19.pProperties[0]);
       v9 = atoi(v19.pProperties[1]);
       v10 = v19.pProperties[2];
-      v2->pSounds[v2->uNumSounds].uSoundID = v9;
+      v2->pSounds[v2->sNumSounds].uSoundID = v9;
       if ( _strcmpi(v10, "system") )
       {
         if ( _strcmpi(v19.pProperties[2], "swap") )
@@ -503,7 +494,7 @@
           v11 = _strcmpi(v19.pProperties[2], "lock");
           v12 = v2->pSounds;
           v13 = v11 == 0;
-          v14 = v2->uNumSounds;
+          v14 = v2->sNumSounds;
           if ( v13 )
             v12[v14].eType = SOUND_DESC_LOCK;
           else
@@ -511,19 +502,19 @@
         }
         else
         {
-          v2->pSounds[v2->uNumSounds].eType = SOUND_DESC_SWAP;
+          v2->pSounds[v2->sNumSounds].eType = SOUND_DESC_SWAP;
         }
       }
       else
       {
-        v2->pSounds[v2->uNumSounds].eType = SOUND_DESC_SYSTEM;
+        v2->pSounds[v2->sNumSounds].eType = SOUND_DESC_SYSTEM;
       }
       if ( v19.uPropCount >= 4 && !_strcmpi(v19.pProperties[3], "3D") )
       {
-        v15 = (int)&v2->pSounds[v2->uNumSounds].uFlags;
+        v15 = (int)&v2->pSounds[v2->sNumSounds].uFlags;
         *(int *)v15 |= SOUND_DESC_SWAP;
       }
-      ++v2->uNumSounds;
+      ++v2->sNumSounds;
     }
   }
   fclose(File);
@@ -610,7 +601,7 @@
                 if ( AIL_sample_status(v6->hSample) == AIL::Sample::Playing)
                 {
                   AIL_end_sample(v6->hSample);
-                  _4ABE55(v6);
+                  FreeChannel(v6);
                 }
               }
               ++v5;
@@ -740,7 +731,7 @@
 
 
   int sound_id = 0;
-  for (uint i = 0; i < pSoundList->uNumSounds; ++i)
+  for (uint i = 0; i < pSoundList->sNumSounds; ++i)
     if (pSoundList->pSounds[i].uSoundID == eSoundID)
     {
       sound_id = i;
@@ -756,7 +747,7 @@
   int start_channel = 0,
       end_channel = 0;
 
-  assert(sound_id < pSoundList->uNumSounds);
+  assert(sound_id < pSoundList->sNumSounds);
   auto sound_desc = pSoundList->pSounds + sound_id;
   if (!b3DSoundInitialized || sound_desc->Is3D())
   {
@@ -869,7 +860,7 @@
           return;                          // already playing the same sound from the same source - return
 
         AIL_end_sample(channel->hSample);  // requested new sound from the same source - end & switch
-        _4ABE55(channel);
+        FreeChannel(channel);
       }
     }
 
@@ -883,7 +874,7 @@
         {
           AIL_end_sample(channel->hSample);
           if (channel->uSourceTrackIdx)
-            _4ABE55(channel);
+            FreeChannel(channel);
           break;
         }
       }
@@ -947,7 +938,7 @@
 
         auto channel = &pMixerChannels[v62];
         AIL_end_sample(channel->hSample);
-        _4ABE55(channel);
+        FreeChannel(channel);
       }
 
       if (v62 > end_channel)//10!=13
@@ -1001,7 +992,7 @@
         if (!GetSoundStrengthByDistanceFromParty(door->pXOffsets[0], door->pYOffsets[0], door->pZOffsets[0]))
         {
           AIL_end_sample(channel->hSample);
-          _4ABE55(channel);
+          FreeChannel(channel);
           return;
         }
         AIL_set_sample_pan(channel->hSample, sub_4AB66C(door->pXOffsets[0], door->pYOffsets[0]));
@@ -1622,7 +1613,7 @@
     if (AIL_sample_status(channel->hSample) == AIL::Sample::Done)
     {
       AIL_end_sample(channel->hSample);
-      _4ABE55(channel);
+      FreeChannel(channel);
     }
   }
 
@@ -1706,7 +1697,7 @@
     else
     {
       AIL_end_sample(channel->hSample);
-      _4ABE55(channel);
+      FreeChannel(channel);
     }
   }
 
@@ -1882,7 +1873,7 @@
           && pSoundList->pSounds[pChannel->uSourceTrackIdx].eType != SOUND_DESC_SYSTEM)
         {
           AIL_end_sample(pChannel->hSample);
-          _4ABE55(pChannel);
+          FreeChannel(pChannel);
           pChannel->source_pid = 0;
         }
         ++v6;
@@ -2205,7 +2196,7 @@
 }
 
 //----- (004ABE55) --------------------------------------------------------
-void AudioPlayer::_4ABE55(MixerChannel *pChannel)
+void AudioPlayer::FreeChannel(MixerChannel *pChannel)
 {
   int v2; // ebx@1
   //AudioPlayer *v3; // esi@1
@@ -2213,14 +2204,14 @@
   unsigned __int8 v5; // zf@5
   unsigned __int8 v6; // sf@5
   char *v7; // edi@6
-  int v8; // eax@8
+  int num_same_sound_on_channels; // eax@8
   int v9; // ST04_4@8
   int v10; // ecx@12
   int v11; // edi@13
   int v12; // eax@13
   unsigned __int8 v13; // of@13
   int v14[16]; // [sp+Ch] [bp-48h]@8
-  int v15; // [sp+4Ch] [bp-8h]@5
+  int num_playing_channels; // [sp+4Ch] [bp-8h]@5
   int v16; // [sp+50h] [bp-4h]@5
 
   v2 = 0;
@@ -2229,49 +2220,41 @@
     return;
  
     v4 = &pSoundList->pSounds[pChannel->uSourceTrackIdx];
-    if ( v4->eType == SOUND_DESC_SWAP)
+    if ( pSoundList->pSounds[pChannel->uSourceTrackIdx].eType == SOUND_DESC_SWAP)
     {
-      if ( v4->pSoundData[0] && !(v4->uFlags & SOUND_DESC_SYSTEM) )
+      if ( pSoundList->pSounds[pChannel->uSourceTrackIdx].pSoundData[0] && 
+          !(pSoundList->pSounds[pChannel->uSourceTrackIdx].uFlags & SOUND_DESC_SYSTEM) )
       {
-        v5 = this->uMixerChannels == 0;
-        v6 = this->uMixerChannels < 0;
-        v15 = 0;
-        v16 = 0;
-        if ( v6 | v5 )
+        num_playing_channels = 0;
+        num_same_sound_on_channels = 0;
+        if ( this->uMixerChannels <=0 )
           goto LABEL_16;
-        v7 = (char *)this->pMixerChannels;
         do
         {
-          if ( pChannel->uSourceTrackID == *((int *)v7 + 3) )
+          if ( pChannel->uSourceTrackID ==pMixerChannels[v2].uSourceTrackID )
           {
-            v8 = v16;
-            v9 = *(int *)v7;
-            ++v16;
-            v14[v8] = v2;
-            if ( AIL_sample_status((HSAMPLE)v9) == AIL::Sample::Playing)
-              ++v15;
+            v14[num_same_sound_on_channels++] = v2;
+            if ( AIL_sample_status((HSAMPLE)pMixerChannels[v2].hSample) == AIL::Sample::Playing)
+              ++num_playing_channels;
           }
           ++v2;
-          v7 += 16;
         }
         while ( v2 < uMixerChannels );
-        if ( !v15 )
+        if ( !num_playing_channels )
         {
 LABEL_16:
-          pSoundList->_4A9DCD(pChannel->uSourceTrackIdx, 1);
+          pSoundList->UnloadSound(pChannel->uSourceTrackIdx, 1);
           v10 = 0;
-          if ( v16 > 0 )
+          if ( num_same_sound_on_channels  > 0 )
           {
             do
             {
               v11 = v14[v10];
-              v12 = 16 * (v14[v10++] + 47);
+              v10++;
               pMixerChannels[v11].uSourceTrackID = 0;
-              v13 = __OFSUB__(v10, v16);
-              v6 = v10 - v16 < 0;
-              *(unsigned int *)((char *)&bEAXSupported + v12) = 0;
+               pMixerChannels[v11].hSample = NULL;
             }
-            while ( v6 ^ v13 );
+            while (v10<num_same_sound_on_channels);
           }
         }
       }
@@ -2398,7 +2381,7 @@
         if ( !v14 )
         {
 LABEL_16:
-          pSoundList->_4A9DCD(a2->field_8, 1);
+          pSoundList->UnloadSound(a2->field_8, 1);
           v10 = 0;
           if ( v15 > 0 )
           {
@@ -2675,9 +2658,10 @@
   v3 = pOutBuff;
   v4 = 0;
   for (uint i = 0; i < 3000; ++i)
-    if (pSounds[i].uID == uID)
-      return pSounds[i].pSoundData;
-
+      {
+      if (pSounds[i].uID == uID)
+          return pSounds[i].pSoundData;
+      }
   FindSound_BinSearch(0, pAudioPlayer->uNumSoundHeaders, pSoundName_);
   if ( uFindSound_BinSearch_ResultID == -1 )
   {
--- a/AudioPlayer.h	Sun Mar 24 00:31:56 2013 +0600
+++ b/AudioPlayer.h	Sun Mar 24 00:32:13 2013 +0600
@@ -152,7 +152,7 @@
   void Initialize(HWND hWnd);
   LSTATUS CheckA3DSupport(char a2);
   void Release();
-  void _4ABE55(MixerChannel *pChannel);
+  void FreeChannel(MixerChannel *pChannel);
   void _4ABF23(AudioPlayer_3DSample *a2);
   void SetEAXPreferences();
   void SetMapEAX();
@@ -256,7 +256,7 @@
 struct SoundList
 {
   inline SoundList():
-    uNumSounds(0), pSounds(nullptr), uTotalLoadedSoundSize(0)
+    sNumSounds(0), pSounds(nullptr), uTotalLoadedSoundSize(0)
   {}
 
   void Initialize();
@@ -264,12 +264,12 @@
   int LoadSound(unsigned int a2, LPVOID lpBuffer, int uBufferSizeLeft, int *pOutSoundSize, int a6);
   SoundDesc *Release();
   void _4A9D79(int a2);
-  void _4A9DCD(unsigned int uSoundID, char a3);
+  void UnloadSound(unsigned int uSoundID, char a3);
   void ToFile();
   void *FromFile(void *pSerialized);
   int FromFileTxt(const char *Args);
 
-  unsigned int uNumSounds;
+  signed int sNumSounds;
   SoundDesc *pSounds;
   unsigned int uTotalLoadedSoundSize;
 };
--- a/Events.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/Events.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -1,3 +1,4 @@
+#include <assert.h>
 #include <stdlib.h>
 
 #include "MapInfo.h"
@@ -87,7 +88,7 @@
 
 //----- (00443DA1) --------------------------------------------------------
 void __cdecl Initialize_GlobalEVT()
-	{
+{
 	struct raw_event_header
 		{ 
 		unsigned char evt_size;
@@ -116,7 +117,8 @@
 		}
 	uGlobalEVT_NumEvents = events_count;
 
-	}
+  assert(uGlobalEVT_NumEvents < 4400);
+}
 
 
 //----- (00443EF8) --------------------------------------------------------
@@ -438,11 +440,11 @@
 					break;
 					}
 				if ( !_strcmpi(v16, "pcout01") )    // moving to harmondale from emerald isle
-					{
+                {
 					Rest(0x2760u);
 					pParty->RestAndHeal();
-					pParty->field_764 = 0;
-					}
+					pParty->days_played_without_rest = 0;
+                }
 				if ( !v15 || v128 == 3 )
 					{
 					pCurrentScreen = v128;
--- a/GUIWindow.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/GUIWindow.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -1282,12 +1282,11 @@
 
 
 //----- (0044D406) --------------------------------------------------------
-char * GUIWindow::DrawTitleText( GUIFont *a2, signed int uHorizontalMargin, unsigned int uVerticalMargin, unsigned __int16 uDefaultColor, const char *pInString, unsigned int uLineSpacing )
-    {
+void GUIWindow::DrawTitleText( GUIFont *a2, signed int uHorizontalMargin, unsigned int uVerticalMargin, unsigned __int16 uDefaultColor, const char *pInString, unsigned int uLineSpacing )
+{
   GUIWindow *pWindow; // esi@1
   unsigned int v8; // ebx@1
   char *v9; // eax@1
-  char *result; // eax@1
   unsigned int v11; // edi@1
   signed int v12; // esi@1
   int v13; // eax@2
@@ -1299,22 +1298,20 @@
   v8 = this->uFrameWidth - uHorizontalMargin;
   ui_current_text_color = uDefaultColor;
   v9 = FitTextInAWindow(pInString, a2, this, uHorizontalMargin, 0);
-  result = strtok(v9, "\n");
+  Stra = strtok(v9, "\n");
   v11 = uHorizontalMargin + pWindow->uFrameX;
   v12 = uVerticalMargin + pWindow->uFrameY;
   while ( 1 )
   {
-    Stra = result;
-    if ( !result )
+    if ( !Stra )
       break;
-    v13 = (signed int)(v8 - pFont->GetLineWidth(result)) >> 1;
+    v13 = (signed int)(v8 - pFont->GetLineWidth(Stra)) >> 1;
     if ( v13 < 0 )
       v13 = 0;
     pFont->DrawTextLine(uDefaultColor, v11 + v13, v12, Stra, 640);
     v12 += pFont->uFontHeight - uLineSpacing;
-    result = strtok(0, "\n");
+    Stra = strtok(0, "\n");
   }
-  return result;
 }
 // 5C6DB4: using guessed type int ui_current_text_color;
 
--- a/GUIWindow.h	Sun Mar 24 00:31:56 2013 +0600
+++ b/GUIWindow.h	Sun Mar 24 00:32:13 2013 +0600
@@ -114,7 +114,7 @@
   void DrawFlashingInputCursor(signed int a3, int a4, struct GUIFont *a2);
   int DrawTextInRect(GUIFont *a2, unsigned int uX, unsigned int uY, unsigned int uColor, const char *Str1, int Source, int a8);
   char DrawText(GUIFont *a2, signed int uX, int uY, unsigned int uFontColor, const char *Str, int a7, int a8, unsigned int uFontShadowColor);
-  char *DrawTitleText(GUIFont *a2, signed int uHorizontalMargin, unsigned int uVerticalMargin, unsigned __int16 uDefaultColor, const char *pInString, unsigned int uLineSpacing);
+  void DrawTitleText(GUIFont *a2, signed int uHorizontalMargin, unsigned int uVerticalMargin, unsigned __int16 uDefaultColor, const char *pInString, unsigned int uLineSpacing);
   void DrawCurrentTime(__int64 a2);
   void HouseDialogManager();
   void OpenSpellBook();
--- a/Game.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/Game.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -395,7 +395,7 @@
         ++pPlayer;
       }
       while ( (signed int)pPlayer < (signed int)pParty->pHirelings );
-      pParty->field_764 = 0;
+      pParty->days_played_without_rest = 0;
       pParty->uTimePlayed += 0x276000ui64;
       LOWORD(pParty->uFlags) &= ~0x204;
       pParty->SetGold(0);
--- a/GameUIs.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/GameUIs.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -34,9 +34,8 @@
 
   uDialogueType_ = uDialogueType;
   dword_6BE138 = -1;
-  ++pIcons_LOD->uTexturePacksCount;
-  if ( !pIcons_LOD->uNumPrevLoadedFiles )
-    pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
+  pIcons_LOD->_inlined_sub2();
+
   memset(pSavegameUsedSlots, 0, sizeof(pSavegameUsedSlots));
   memset(pSavegameThumbnails, 0, 45 * sizeof(RGBTexture));
   uTextureID_loadsave = pIcons_LOD->LoadTexture("loadsave", TEXTURE_16BIT_PALETTE);
--- a/Items.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/Items.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -305,7 +305,6 @@
   pStdItemsTXT_Raw = NULL;
   pRndItemsTXT_Raw = NULL;
   pItemsTXT_Raw = NULL;
-
 }
 
 
--- a/LOD.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/LOD.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -28,6 +28,47 @@
 int _6A0CA8_lod_unused; // weak
 
 
+// inlined
+//----- (mm6c::00408860) --------------------------------------------------
+void LODFile_IconsBitmaps::_inlined_sub2()
+{
+  ++uTexturePacksCount;
+  if (!uNumPrevLoadedFiles)
+    uNumPrevLoadedFiles = uNumLoadedFiles;
+}
+
+// inlined
+//----- (mm6c::0045BE60) --------------------------------------------------
+void LODFile_IconsBitmaps::_inlined_sub1()
+{
+  dword_11B84 = uNumLoadedFiles;
+}
+
+// inlined
+//----- (mm6c::0045C310) --------------------------------------------------
+void LODFile_Sprites::_inlined_sub1()
+{
+  field_ECA0 = uNumLoadedSprites;
+}
+
+// inlined
+//----- (mm6c::0045C5B0) --------------------------------------------------
+void LODFile_IconsBitmaps::_inlined_sub0()
+{
+  dword_11B80 = uNumLoadedFiles;
+  if (dword_11B84 < uNumLoadedFiles)
+    dword_11B84 = uNumLoadedFiles;
+}
+
+
+// inlined
+//----- (mm6c::0045C660) --------------------------------------------------
+void LODFile_Sprites::_inlined_sub0()
+{
+  field_ECA4 = uNumLoadedSprites;
+  if (field_ECA0 < uNumLoadedSprites)
+    field_ECA0 = uNumLoadedSprites;
+}
 
 
 
--- a/LOD.h	Sun Mar 24 00:31:56 2013 +0600
+++ b/LOD.h	Sun Mar 24 00:32:13 2013 +0600
@@ -158,6 +158,9 @@
   void ReleaseAll2();
   void _4114F2();
   void _4355F7();
+  void _inlined_sub0();
+  void _inlined_sub1();
+  void _inlined_sub2();
 
   inline Texture *GetTexture(int idx)
   {
@@ -255,6 +258,8 @@
   void ReleaseLostHardwareSprites();
   void ReleaseAll();
   void MoveSpritesToVideoMemory();
+  void _inlined_sub0();
+  void _inlined_sub1();
 
 
   /*FILE *pFile;
--- a/MapInfo.h	Sun Mar 24 00:31:56 2013 +0600
+++ b/MapInfo.h	Sun Mar 24 00:32:13 2013 +0600
@@ -1,5 +1,25 @@
 #pragma once
 
+enum MAP_TYPE: unsigned __int32
+{
+  MAP_INVALID = 0,
+  MAP_EMERALD_ISLE = 1,
+  MAP_HARMONDALE = 2,
+  MAP_STEADWICK = 3,
+  MAP_PIERPONT = 4,
+  MAP_DEYJA = 5,
+  MAP_BRAKADA_DESERT = 6,
+  MAP_CELESTIA = 7,
+  MAP_THE_PIT = 8,
+  MAP_EVENMORN_ISLE = 9,
+  MAP_MOUNT_NIGHON = 10,
+  MAP_BARROW_DOWNS = 11,
+  MAP_LAND_OF_GIANTS = 12,
+  MAP_TATALIA = 13,
+  MAP_AVLEE = 14,
+  MAP_SHOALS = 15,
+  //...
+};
 
 
 /*  192 */
@@ -53,7 +73,7 @@
 struct MapStats
 {
   void Initialize();
-  unsigned int GetMapInfo(const char *Str2);
+  MAP_TYPE GetMapInfo(const char *Str2);
 
   MapInfo pInfos[77];
   unsigned int uNumMaps;
--- a/Mouse.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/Mouse.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -284,11 +284,18 @@
   SetCursorBitmap("MICON1");
 }
 
+// inlined
+//----- (0045FE00) mm6 chinese --------------------------------------------
+void Mouse::SetActive(bool active)
+{
+  bActive = active;
+}
+
 //----- (00469CC2) --------------------------------------------------------
 void Mouse::Deactivate()
 {
   if (bInitialized)
-    bActive = false;
+    SetActive(false);
 }
 
 //----- (00469CCD) --------------------------------------------------------
--- a/Mouse.h	Sun Mar 24 00:31:56 2013 +0600
+++ b/Mouse.h	Sun Mar 24 00:32:13 2013 +0600
@@ -68,6 +68,7 @@
   void *DoAllocCursorMem();
   POINT *GetCursorPos(POINT *p);
   void Initialize(HWND hWnd);
+  void SetActive(bool active);
   void Deactivate();
   void DrawCursor();
   void _469E1C();
--- a/Outdoor.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/Outdoor.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -42,6 +42,32 @@
 Edge stru_80C9A4;
 Edge stru_80C9D8;
 
+
+struct FogProbabilityTableEntry
+{
+  unsigned char small_fog_chance;
+  unsigned char average_fog_chance;
+  unsigned char dense_fog_chance;
+  unsigned char __unused;
+} fog_probability_table[15] =
+{
+  { 20,  10,   5,   0}, // MAP_EMERALD_ISLE
+  { 20,  10,   5,   0}, // MAP_HARMONDALE
+  { 20,  10,   5,   0}, // MAP_STEADWICK
+  { 20,  10,   5,   0}, // MAP_PIERPONT
+  { 20,  10,   5,   0}, // MAP_DEYJA
+  { 10,   5,   0,   0}, // MAP_BRAKADA_DESERT
+  {  0,   0,   0,   0}, // MAP_CELESTIA
+  {  0,   0,   0,   0}, // MAP_THE_PIT
+  { 20,  30,  50,   0}, // MAP_EVENMORN_ISLE
+  { 30,  20,  10,   0}, // MAP_MOUNT_NIGHON
+  { 10,   5,   0,   0}, // MAP_BARROW_DOWNS
+  { 20,  10,   5,   0}, // MAP_LAND_OF_GIANTS
+  { 20,  10,   5,   0}, // MAP_TATALIA
+  { 20,  10,   5,   0}, // MAP_AVLEE
+  {  0, 100,   0,   0}  // MAP_SHOALS
+};
+
 //for future sky textures?
 int dword_4EC268[9]={3,3,3,3,3,3,3,3,3}; // weak
 int dword_4EC28C[7]={3,3,3,3,3,3,3}; // weak
@@ -64,8 +90,8 @@
 
   pIndoorCamera->sRotationX = pParty->sRotationX;
   pIndoorCamera->sRotationY = pParty->sRotationY;
-  pIndoorCamera->pos.x = pParty->vPosition.x - ((stru_5C6E00->Cos(pParty->sRotationY) * (signed __int64)pParty->y_rotation_granularity) >> 16);
-  pIndoorCamera->pos.y = pParty->vPosition.y - pParty->y_rotation_granularity * (stru_5C6E00->Sin(pParty->sRotationY) >> 16);
+  pIndoorCamera->pos.x = pParty->vPosition.x - fixpoint_mul(stru_5C6E00->Cos(pParty->sRotationY), pParty->y_rotation_granularity);
+  pIndoorCamera->pos.y = pParty->vPosition.y - fixpoint_mul(stru_5C6E00->Sin(pParty->sRotationY), pParty->y_rotation_granularity);
   pIndoorCamera->pos.z = pParty->vPosition.z + pParty->sEyelevel;
   if (bRedraw || pRenderer->pRenderD3D)
   {
@@ -73,8 +99,11 @@
     pOutdoorCamera->RotationToInts();
     sub_481ED9_MessWithOutdoorCamera();
   }
+
   pIndoorCamera->uMapGridCellX = WorldPosToGridCellX(pParty->vPosition.x);
   pIndoorCamera->uMapGridCellZ = WorldPosToGridCellZ(pParty->vPosition.y);
+  assert(pIndoorCamera->uMapGridCellX <= 127 && pIndoorCamera->uMapGridCellZ <= 127);
+
   if (bRedraw)
   {
     Software_ResetNewEdges();
@@ -285,9 +314,9 @@
       MessageBoxA(0, "Error!", "Couldn't Load Map!", 0);
       CreateDebugLocation();
     }
-    day_attrib = v5->day_attrib;
-    day_fogrange_1 = v5->day_fogrange_1;
-    day_fogrange_2 = v5->day_fogrange_2;
+    ::day_attrib = v5->day_attrib;
+    ::day_fogrange_1 = v5->day_fogrange_1;
+    ::day_fogrange_2 = v5->day_fogrange_2;
     if ( Is_out15odm_underwater() )
       SetUnderwaterFog();
     _6BE134_odm_main_tile_group = v5->pTileTypes[0].tileset;
@@ -458,9 +487,9 @@
 }
 
 //----- (004892E6) --------------------------------------------------------
-unsigned int OutdoorLocation::UpdateSunlightVectors()
+void OutdoorLocation::UpdateSunlightVectors()
 {
-  unsigned int result; // eax@1
+  //unsigned int result; // eax@1
   OutdoorLocation *v2; // esi@1
   unsigned int v3; // edi@3
   //int v4; // ebx@3
@@ -469,7 +498,6 @@
   //int v7; // ecx@3
   double v8; // st7@4
 
-  result = pParty->uCurrentHour;
   v2 = this;
   if ( pParty->uCurrentHour >= 5 && pParty->uCurrentHour < 21 )
   {
@@ -489,10 +517,8 @@
     else
       v8 = (double)(signed int)v3;
     v2->max_terrain_dimming_level = (signed __int64)(20.0 - v8 / 480.0 * 20.0);
-    result = pParty->uCurrentMinute;
     v2->uLastSunlightUpdateMinute = pParty->uCurrentMinute;
   }
-  return result;
 }
 
 //----- (004893C1) --------------------------------------------------------
@@ -527,7 +553,7 @@
   v5 = WorldPosToGridCellX(pParty->vPosition.x);
   v6 = WorldPosToGridCellZ(pParty->vPosition.y);
   v7 = _47ED83(v5, v6 - 1);
-  v8 = pTileTable->pTiles[_47ECC1(v7)].tileset;
+  v8 = pTileTable->pTiles[GetTileIdByTileMapId(v7)].tileset;
   if ( v8 )
   {
     v9 = v8 - 1;
@@ -545,63 +571,50 @@
   }
   return 1;
 }
-// 47F44B: using guessed type int __stdcall WorldPosToGridCellX(int);
-// 47F458: using guessed type int __stdcall WorldPosToGridCellZ(int);
+
 
 //----- (00489487) --------------------------------------------------------
-int OutdoorLocation::SetFog()
+void OutdoorLocation::SetFog()
 {
-  int result; // eax@1
-  int v2; // esi@1
-  int v3; // edx@5
-  unsigned __int8 *v4; // eax@5
-  int v5; // ecx@5
-  int v6; // esi@7
-  unsigned __int8 v7; // al@9
+  strcpy(pOutdoor->pLevelFilename, pCurrentMapName);
 
-  strcpy(pOutdoor->pLevelFilename, pCurrentMapName);
-  result = pMapStats->GetMapInfo(pCurrentMapName);
-  v2 = result;
-  if ( result < 1 || result == 7 || result == 8 || result > 15 )
-    return result;
-  day_attrib &= 0xFFFFFFFEu;
-  v3 = rand() % 100;
-  v4 = (unsigned __int8 *)&byte_4ECB0C[4 * v2];
-  v5 = *v4;
-  if ( v3 < v5 )
+  auto map_id = pMapStats->GetMapInfo(pCurrentMapName);
+  if (map_id == MAP_INVALID || map_id == MAP_CELESTIA || map_id == MAP_THE_PIT || map_id > MAP_SHOALS)
+    return;
+
+  uint chance = rand() % 100;
+
+  if (chance < fog_probability_table[map_id - 1].small_fog_chance)
   {
-    day_fogrange_1 = 4096;
-    day_fogrange_2 = 8192;
-LABEL_13:
-    day_attrib |= 1u;
-    goto LABEL_14;
+    ::day_fogrange_1 = 4096;
+    ::day_fogrange_2 = 8192;
+    ::day_attrib |= DAY_ATTRIB_FOG;
   }
-  v6 = v4[1];
-  if ( v3 < v6 + v5 )
+  else if (chance < fog_probability_table[map_id - 1].small_fog_chance +
+                    fog_probability_table[map_id - 1].average_fog_chance)
   {
-    day_fogrange_2 = 4096;
-LABEL_12:
-    day_fogrange_1 = 0;
-    goto LABEL_13;
+    ::day_fogrange_2 = 4096;
+    ::day_fogrange_1 = 0;
+    ::day_attrib |= DAY_ATTRIB_FOG;
   }
-  v7 = v4[2];
-  if ( v7 && v3 < v5 + v6 + v7 )
+  else if (fog_probability_table[map_id - 1].dense_fog_chance &&
+           chance < fog_probability_table[map_id - 1].small_fog_chance + 
+                    fog_probability_table[map_id - 1].average_fog_chance +
+                    fog_probability_table[map_id - 1].dense_fog_chance)
   {
-    day_fogrange_2 = 2048;
-    goto LABEL_12;
+    ::day_fogrange_2 = 2048;
+    ::day_fogrange_1 = 0;
+    ::day_attrib |= DAY_ATTRIB_FOG;
   }
-LABEL_14:
+  else
+    ::day_attrib &= ~DAY_ATTRIB_FOG;
+
   if ( Is_out15odm_underwater() )
     SetUnderwaterFog();
-  pOutdoor->day_fogrange_1 = day_fogrange_1;
-  pOutdoor->day_fogrange_2 = day_fogrange_2;
-  result = day_attrib;
-  pOutdoor->day_attrib = day_attrib;
-  return result;
+  pOutdoor->day_fogrange_1 = ::day_fogrange_1;
+  pOutdoor->day_fogrange_2 = ::day_fogrange_2;
+  pOutdoor->day_attrib = ::day_attrib;
 }
-// 6BE030: using guessed type int day_attrib;
-// 6BE040: using guessed type int day_fogrange_1;
-// 6BE044: using guessed type int day_fogrange_2;
 
 //----- (00482170) --------------------------------------------------------
 bool ODMFace::IsBackfaceCulled(ODMFace *a1, RenderVertexSoft *a2, stru148 *a3)
@@ -1341,9 +1354,7 @@
     pPaletteManager->pPalette_tintColor[0] = 0x10;
     pPaletteManager->pPalette_tintColor[1] = 0xC2;
     pPaletteManager->pPalette_tintColor[2] = 0x99;
-    pPaletteManager->pPalette_mistColor[0] = 0x25;
-    pPaletteManager->pPalette_mistColor[1] = 0x8F;
-    pPaletteManager->pPalette_mistColor[2] = 0x5C;
+    pPaletteManager->SetMistColor(37, 143, 92);
   }
   else
   {
@@ -1354,9 +1365,7 @@
         pPaletteManager->pPalette_mistColor[1] != 0x80 ||
         pPaletteManager->pPalette_mistColor[2] != 0x80)
     {
-      pPaletteManager->pPalette_mistColor[0] = 0x80;
-      pPaletteManager->pPalette_mistColor[1] = 0x80;
-      pPaletteManager->pPalette_mistColor[2] = 0x80;
+      pPaletteManager->SetMistColor(128, 128, 128);
       pPaletteManager->RecalculateAll();
     }
   }
@@ -2342,7 +2351,7 @@
 }
 
 //----- (0047ECC1) --------------------------------------------------------
-int OutdoorLocation::_47ECC1(signed int a2)
+int OutdoorLocation::GetTileIdByTileMapId(signed int a2)
 {
   signed int result; // eax@2
   int v3; // eax@3
@@ -2465,101 +2474,43 @@
 }
 
 //----- (0047EE49) --------------------------------------------------------
-int OutdoorLocation::_47EE49(signed int a2, signed int a3, int a4)
-{
+int OutdoorLocation::GetSoundIdByPosition( signed int X_pos, signed int Y_pos, int running )
+    {
   signed int v4; // eax@5
   signed int v5; // eax@7
   int v6; // eax@8
   signed int v8; // eax@9
-  int v9; // eax@12
-  int v10; // eax@13
-  int v11; // eax@14
-  int v12; // eax@16
-  int v13; // eax@17
-  int v14; // eax@18
-  int v15; // eax@19
-  int v16; // eax@20
-  int v17; // eax@21
-  int v18; // eax@28
-  int v19; // eax@29
-  int v20; // eax@30
+  int modif=0;
 
-  if ( a2 < 0 || a2 > 127 || a3 < 0 || a3 > 127 )
+  if ( X_pos < 0 || X_pos > 127 || Y_pos < 0 || Y_pos > 127 )
     v4 = 0;
   else
-    v4 = *(&this->pTerrain.pTilemap[128 * a3] + a2);
-  v5 = _47ECC1(v4);
+    v4 = this->pTerrain.pTilemap[128 * Y_pos + X_pos];
+  v5 = GetTileIdByTileMapId(v4);
+  if (running)
+      modif=-39;
   if ( !v5 )
-  {
-    v6 = -(a4 != 0);
-    LOBYTE(v6) = v6 & 0xD9;
-    return v6 + 92;
-  }
-  v8 = pTileTable->pTiles[v5].tileset;
-  if ( v8 <= 6 )
+    return 92+modif;
+   
+  switch (pTileTable->pTiles[v5].tileset)
   {
-    if ( v8 == Tileset_6 )
-    {
-      v17 = -(a4 != 0);
-      LOBYTE(v17) = v17 & 0xD9;
-      return v17 + 88;
-    }
-    if ( v8 )
-    {
-      v9 = v8 - 1;
-      if ( !v9 )
-      {
-        v15 = -(a4 != 0);
-        LOBYTE(v15) = v15 & 0xD9;
-        return v15 + 97;
-      }
-      v10 = v9 - 1;
-      if ( !v10 )
-      {
-        v14 = -(a4 != 0);
-        LOBYTE(v14) = v14 & 0xD9;
-        return v14 + 91;
-      }
-      v11 = v10 - 1;
-      if ( !v11 )
-      {
-        v13 = -(a4 != 0);
-        LOBYTE(v13) = v13 & 0xD9;
-        return v13 + 90;
-      }
-      if ( v11 == 2 )
-      {
-        v12 = -(a4 != 0);
-        LOBYTE(v12) = v12 & 0xD9;
-        return v12 + 101;
-      }
-LABEL_29:
-      v19 = -(a4 != 0);
-      LOBYTE(v19) = v19 & 0xD9;
-      return v19 + 95;
-    }
-    goto LABEL_20;
+  case 0:  return 93+ modif; 
+  case 1:  return 97+ modif; 
+  case 2:  return 91+ modif;
+  case 3:  return 90+ modif;
+  case 4:  return 101+ modif;
+  case 5:  return 95+ modif;
+  case 6:  return 88+ modif;
+  case 7: return 100+ modif;
+  case 8: return 93+ modif;
+ default:
+     v8=pTileTable->pTiles[v5].tileset;
+     if ( (v8 > 9 && v8 <= 17) || (v8 > 21 && v8 <= 27) )
+        return 96+ modif;
+     else
+        return 95+ modif;
   }
-  if ( v8 != 7 )
-  {
-    if ( v8 != 8 )
-    {
-      if ( v8 > 9 && (v8 <= 17 || v8 > 21 && v8 <= 27) )
-      {
-        v18 = -(a4 != 0);
-        LOBYTE(v18) = v18 & 0xD9;
-        return v18 + 96;
-      }
-      goto LABEL_29;
-    }
-LABEL_20:
-    v16 = -(a4 != 0);
-    LOBYTE(v16) = v16 & 0xD9;
-    return v16 + 93;
-  }
-  v20 = -(a4 != 0);
-  LOBYTE(v20) = v20 & 0xD9;
-  return v20 + 100;
+
 }
 
 //----- (0047EF60) --------------------------------------------------------
@@ -2705,7 +2656,7 @@
         _6807B8_level_decorations_ids[v5] = i;
       }
       if ( v8 && decor->uCog == 20 )
-        LOBYTE(decor->field_2) |= 0x40u;
+        decor->field_2 |= 0x0040u;
       if ( !decor->field_16_event_id )
       {
         if ( decor->IsInteractive() )
@@ -2715,7 +2666,7 @@
             v6 = v1 + 75;
             decor->_idx_in_stru123 = v6;
             if ( !stru_5E4C90._decor_events[v1++] )
-              LOBYTE(decor->field_2) |= 0x20u;
+              decor->field_2 |= 0x0020u;
           }
         }
       }
--- a/Outdoor.h	Sun Mar 24 00:31:56 2013 +0600
+++ b/Outdoor.h	Sun Mar 24 00:32:13 2013 +0600
@@ -5,6 +5,9 @@
 #include "TileFrameTable.h"
 
 
+
+#define DAY_ATTRIB_FOG  1
+
 /*  256 */
 #pragma pack(push, 1)
 struct ODMHeader
@@ -153,12 +156,12 @@
   void CreateDebugLocation();
   void Release();
   bool Load(const char *pFilename, ODMFace *File, size_t a4, int thisa);
-  int _47ECC1(signed int a2);
+  int GetTileIdByTileMapId(signed int a2);
   unsigned int DoGetTileTexture(unsigned int uX, unsigned int uZ);
   int _47ED83(signed int a2, signed int a3);
   int ActuallyGetSomeOtherTileInfo(unsigned int uX, unsigned int uY);
   int DoGetHeightOnTerrain(unsigned int uX, unsigned int uZ);
-  int _47EE49(signed int a2, signed int a3, int a4);
+  int GetSoundIdByPosition(signed int X_pos, signed int Y_pos, int a4);
   int UpdateDiscoveredArea(int a2, int a3, int a4);
   bool _47F04C(signed int a2, signed int a3);
   bool _47F097(signed int a2, signed int a3);
@@ -176,10 +179,10 @@
   bool Release2();
   bool GetTravelDestination(signed int sPartyX, signed int sPartyZ, char *pOut, signed int a5);
   void MessWithLUN();
-  unsigned int UpdateSunlightVectors();
+  void UpdateSunlightVectors();
   void UpdateFog();
   int GetNumFoodRequiredToRestInCurrentPos(int x, signed int y, int z);
-  int SetFog();
+  void SetFog();
   void Draw();
 
 
--- a/PaletteManager.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/PaletteManager.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -865,6 +865,15 @@
 
 }
 
+// inlined
+//----- (mm6c::0045C610) ---------------------------------------------------
+void PaletteManager::SetMistColor(unsigned char r, unsigned char g, unsigned char b)
+{
+  pPalette_mistColor[0] = r;
+  pPalette_mistColor[1] = g;
+  pPalette_mistColor[2] = b;
+}
+
 //----- (0048A614) --------------------------------------------------------
 void PaletteManager::RecalculateAll()
 {
--- a/PaletteManager.h	Sun Mar 24 00:31:56 2013 +0600
+++ b/PaletteManager.h	Sun Mar 24 00:32:13 2013 +0600
@@ -6,7 +6,8 @@
 struct PaletteManager
 {
   PaletteManager();
-
+  
+  void SetMistColor(unsigned char r, unsigned char g, unsigned char b);
   int ResetNonTestLocked();
   void CalcPalettes_LUT(int a2);
   int ResetNonLocked();
--- a/Party.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/Party.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -1023,16 +1023,11 @@
     v2->Zero();
     if ( v2->pConditions[14] || v2->pConditions[15] || v2->pConditions[16] )
       goto LABEL_33;
-    LODWORD(v2->pConditions[13]) = 0;
-    HIDWORD(v2->pConditions[13]) = 0;
-    LODWORD(v2->pConditions[4]) = 0;
-    HIDWORD(v2->pConditions[4]) = 0;
-    LODWORD(v2->pConditions[2]) = 0;
-    HIDWORD(v2->pConditions[2]) = 0;
-    LODWORD(v2->pConditions[3]) = 0;
-    HIDWORD(v2->pConditions[3]) = 0;
-    LODWORD(v2->pConditions[1]) = 0;
-    HIDWORD(v2->pConditions[1]) = 0;
+    v2->pConditions[13] = 0;
+    v2->pConditions[4] = 0;
+    v2->pConditions[2] = 0;
+    v2->pConditions[3] = 0;
+    v2->pConditions[1] = 0;
     v2->uTimeToRecovery = 0;
     v2->sHealth = v2->GetMaxHealth();
     v5 = v2->GetMaxMana();
@@ -1094,5 +1089,5 @@
     ++v15;
   }
   while ( v15 < 4 );
-  pParty->field_764 = 0;
+  pParty->days_played_without_rest = 0;
 }
\ No newline at end of file
--- a/Party.h	Sun Mar 24 00:31:56 2013 +0600
+++ b/Party.h	Sun Mar 24 00:32:13 2013 +0600
@@ -152,7 +152,7 @@
     uCurrentTimeSecond = 0;
 
     field_6FC = 0;
-    field_764 = 0;
+    days_played_without_rest = 0;
 
     vPosition.y = 0;
     vPosition.z = 0;
@@ -262,7 +262,7 @@
   int field_74C;
   __int16 field_750[5];
   __int16 field_75A[5];
-  char field_764; // num hours resting or some sort of.
+  unsigned char   days_played_without_rest;
   unsigned __int8 _quest_bits[64];
   unsigned __int8 pArcomageWins[16];
   char field_7B5_in_arena_quest;
--- a/Player.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/Player.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -632,7 +632,7 @@
     if (expression == CHARACTER_EXPRESSION_21 && pSoundId )
     {
       v17 = 0;
-      if ( (signed int)pSoundList->uNumSounds <= 0 )
+      if ( (signed int)pSoundList->sNumSounds <= 0 )
       {
 LABEL_23:
         v17 = 0;
@@ -644,7 +644,7 @@
         {
           ++v17;
           pSoundID += 120;
-          if ( v17 >= (signed int)pSoundList->uNumSounds )
+          if ( v17 >= (signed int)pSoundList->sNumSounds )
             goto LABEL_23;
         }
       }
@@ -6792,7 +6792,6 @@
 void Player::Zero()
 {
   Player *v1; // esi@1
-  void *result; // eax@1
 
   v1 = this;
   this->sLevelModifier = 0;
@@ -6813,7 +6812,7 @@
   this->field_E8 = 0;
   this->field_E4 = 0;
   this->field_E0 = 0;
-  result = memset(&this->sResFireBonus, 0, 0x16u);
+  memset(&this->sResFireBonus, 0, 0x16u);
   v1->field_1A97 = 0;
   v1->_ranged_dmg_bonus = 0;
   v1->field_1A95 = 0;
--- a/Player.h	Sun Mar 24 00:31:56 2013 +0600
+++ b/Player.h	Sun Mar 24 00:32:13 2013 +0600
@@ -574,6 +574,7 @@
   inline bool Eradicated() {return pConditions[Condition::Condition_Eradicated] != 0;}
   inline bool Zombie()     {return pConditions[Condition::Condition_Zombie] != 0;}
   inline bool Cursed()     {return pConditions[Condition::Condition_Cursed] != 0;}
+  inline bool Pertified()  {return pConditions[Condition::Condition_Pertified] != 0;}
 
 
 
--- a/Render.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/Render.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -634,7 +634,7 @@
   array_77EC08[1999].field_24 = 0x2000000u;
   array_77EC08[1999].sTextureDeltaU = 224 * pMiscTimer->uTotalGameTimeElapsed;
   array_77EC08[1999].sTextureDeltaV = 224 * pMiscTimer->uTotalGameTimeElapsed;
-  if ( day_attrib & 1
+  if ( day_attrib & DAY_ATTRIB_FOG
     && (LOWORD(v2) = LOWORD(pParty->uCurrentHour), pParty->uCurrentHour >= 5)
     && pParty->uCurrentHour < 0x15
     || bUnderwater )
--- a/SaveLoad.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/SaveLoad.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -70,17 +70,17 @@
   if (SoundSetAction[24][0])
     for (uint i = 0; i < 4; ++i)
     {
-      for (uint j = 0; j < pSoundList->uNumSounds; ++j)
+      for (uint j = 0; j < pSoundList->sNumSounds; ++j)
         if (pSoundList->pSounds[j].uSoundID == 2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[i].uVoiceID) + 4998)
         {
-          pSoundList->_4A9DCD(j, 1);
+          pSoundList->UnloadSound(j, 1);
           break;
         }
 
-        for (uint j = 0; j < pSoundList->uNumSounds; ++j)
+        for (uint j = 0; j < pSoundList->sNumSounds; ++j)
         if (pSoundList->pSounds[j].uSoundID == 2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[i].uVoiceID) + 4999)
         {
-          pSoundList->_4A9DCD(j, 1);
+          pSoundList->UnloadSound(j, 1);
           break;
         }
     }
--- a/UIHouses.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/UIHouses.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -528,8 +528,8 @@
         806, 0, -1, 0, 0, 0, 0);
 }
 
-    //----- (004B4F4F) --------------------------------------------------------
-char *__cdecl JailDialog()
+//----- (004B4F4F) --------------------------------------------------------
+void JailDialog()
 {
   const char *v0; // esi@1
   const char *v1; // ST10_4@1
@@ -545,7 +545,7 @@
   v5.uFrameZ = 334;
   v2 = GenerateColorAsCloseAsPossibleToR8G8B8InTargetFormat(0xFFu, 0xFFu, 0x9Bu);
   v3 = pFontArrus->CalcTextHeight(v0, &v5, 0, 0);
-  return v5.DrawTitleText(pFontArrus, 0, (310 - v3) / 2 + 18, v2, v1, 3u);
+  v5.DrawTitleText(pFontArrus, 0, (310 - v3) / 2 + 18, v2, v1, 3u);
 }
 
 
@@ -3650,7 +3650,7 @@
                                 strcat(pTmpBuf, pGlobalTXT_LocalizationStrings[528]);
                                 v22 = WORD2(v59);
                                 v23 = pFontArrus->CalcTextHeight(pTmpBuf, &v57, 0, 0);
-                                result = (int)v57.DrawTitleText(pFontArrus, 0, (174 - v23) / 2 + 138, v22, pTmpBuf, 3u);
+                                v57.DrawTitleText(pFontArrus, 0, (174 - v23) / 2 + 138, v22, pTmpBuf, 3u);
                                 }
                         }
                     }
@@ -4047,7 +4047,7 @@
               strcat(pTmpBuf, pGlobalTXT_LocalizationStrings[528]);// "I can offer you nothing further."
               v29 = color2;
               v30 = pFontArrus->CalcTextHeight(pTmpBuf, &v65, 0, 0);
-              (int)v65.DrawTitleText(pFontArrus, 0, (174 - v30) / 2 + 138, v29, pTmpBuf, 3u);
+              v65.DrawTitleText(pFontArrus, 0, (174 - v30) / 2 + 138, v29, pTmpBuf, 3u);
             }
           }
         }
--- a/UIHouses.h	Sun Mar 24 00:31:56 2013 +0600
+++ b/UIHouses.h	Sun Mar 24 00:32:13 2013 +0600
@@ -96,7 +96,7 @@
 };
 
 void TrainingDialog();
-char *__cdecl JailDialog();
+void JailDialog();
 void  MagicShopDialog();
 void  GuildDialog();
 void  sub_4B6478();
--- a/VideoPlayer.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/VideoPlayer.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -316,8 +316,9 @@
   pRenderer->DrawTextureRGB(0, 0, &tex);
   free(tex.pPixels);
   tex.pPixels = 0;
-  MainMenuUI_LoadFontsAndSomeStuff();
-  DrawCopyrightWindow();
+
+  LoadFonts_and_DrawCopyrightWindow();
+
   pRenderer->EndScene();
   pRenderer->Present();
   if (!bNoSound && pAudioPlayer->hAILRedbook )
--- a/Viewport.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/Viewport.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -37,7 +37,7 @@
     this->uScreenHeight = br_y - tl_y + 1;
     this->uScreenCenterX = (signed int)(br_x + tl_x) /2;
     if ( pRenderer->pRenderD3D == 0 )
-        this->uScreenCenterY = this->uScreen_BR_Y - ((unsigned __int64)(this->field_30 * (signed __int64)(uScreenHeight)) >> 16);
+        this->uScreenCenterY = this->uScreen_BR_Y - fixpoint_mul(field_30, uScreenHeight);
     else
         this->uScreenCenterY = uScreenHeight/2;
     SetViewport(this->uScreen_TL_X, this->uScreen_TL_Y, this->uScreen_BR_X, this->uScreen_BR_Y);
--- a/Weather.h	Sun Mar 24 00:31:56 2013 +0600
+++ b/Weather.h	Sun Mar 24 00:32:13 2013 +0600
@@ -9,6 +9,10 @@
 #pragma pack(push, 1)
 struct Weather
 {
+  inline Weather():
+    bNight(false), bRenderSnow(false)
+  {}
+
   int DrawSnow();
   int Initialize();
   int Draw();
--- a/mm7_1.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/mm7_1.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -70,6 +70,13 @@
 
 
 
+//----- (004453C0) mm6-----------------------------------------------------
+//----- (004A1760) mm6_chinese---------------------------------------------
+int fixpoint_mul(int a1, int a2)
+{
+  return ((__int64)a1 * a2) >> 16;
+}
+
 //----- (004196A0) --------------------------------------------------------
 void __cdecl sub_4196A0()
 {
--- a/mm7_2.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/mm7_2.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -6741,25 +6741,15 @@
 
 
 //----- (004547A3) --------------------------------------------------------
-unsigned int MapStats::GetMapInfo(const char *Str2)
-{
-  MapStats *v2; // esi@1
-  unsigned int v3; // edi@1
-  const char **v4; // ebx@2
-  unsigned int result; // eax@6
-
-  v3 = 1;
-  if ( (signed int)uNumMaps <= 1 )
-     return 0;
-  
-    while ( !*this->pInfos[v3].pFilename || _strcmpi(this->pInfos[v3].pFilename, Str2) )
-    {
-      ++v3;
-      if ( (signed int)v3 >= (signed int)uNumMaps )
-        return 0;
-    }
-    return v3;
-
+MAP_TYPE MapStats::GetMapInfo(const char *Str2)
+{
+  assert(uNumMaps >= 2);
+
+  for (uint i = 1; i < uNumMaps; ++i)
+    if (!strcmpi(pInfos[i].pFilename, Str2))
+      return (MAP_TYPE)i;
+
+  assert(false && "Map not found!");
 }
 
 //----- (004547E4) --------------------------------------------------------
@@ -8049,7 +8039,7 @@
 }
 
 //----- (004627B7) --------------------------------------------------------
-void __cdecl MainMenu_Loop()
+void MainMenu_Loop()
 {
   GUIButton *pButton; // eax@27
   unsigned int pControlParam; // ecx@35
@@ -8068,9 +8058,9 @@
   pGUIWindow2 = 0;
   pAudioPlayer->StopChannels(-1, -1);
   pMouse->RemoveHoldingItem();
-  ++pIcons_LOD->uTexturePacksCount;
-  if ( !pIcons_LOD->uNumPrevLoadedFiles )
-    pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
+
+  pIcons_LOD->_inlined_sub2();
+
   pWindow_MainMenu = GUIWindow::Create(0, 0, 640, 480, WINDOW_MainMenu, 0, 0);
   auto pNew = pIcons_LOD->LoadTexturePtr("title_new", TEXTURE_16BIT_PALETTE);
   pMainMenu_BtnNew = pWindow_MainMenu->CreateButton(495, 172, pNew->uTextureWidth, pNew->uTextureHeight, 1, 0, 
@@ -8921,21 +8911,19 @@
 }
 
 //----- (004647AB) --------------------------------------------------------
-void __cdecl FinalInitialization()
+void FinalInitialization()
 {
   pViewport->SetScreen(viewparams->uSomeX, viewparams->uSomeY, viewparams->uSomeZ, viewparams->uSomeW);
   pViewport->_4C02F8((signed __int64)(flt_6BE3A0 * 65536.0));
 
   pIndoorCamera = new IndoorCamera;
-  pIndoorCamera->Initialize(
-    65,
-    viewparams->uScreen_BttmR_X - viewparams->uScreen_topL_X + 1,
-    viewparams->uScreen_BttmR_Y - viewparams->uScreen_topL_Y + 1);
+  pIndoorCamera->Initialize(65, viewparams->uScreen_BttmR_X - viewparams->uScreen_topL_X + 1,
+                                viewparams->uScreen_BttmR_Y - viewparams->uScreen_topL_Y + 1);
 
   InitializeTurnBasedAnimations(&stru_50C198);
-  pBitmaps_LOD->dword_11B84 = pBitmaps_LOD->uNumLoadedFiles;
-  pSprites_LOD->field_ECA0 = pSprites_LOD->uNumLoadedSprites;
-  pIcons_LOD->dword_11B84 = pIcons_LOD->uNumLoadedFiles;
+  pBitmaps_LOD->_inlined_sub1();
+  pSprites_LOD->_inlined_sub1();
+  pIcons_LOD->_inlined_sub1();
 }
 // 6BE3A0: using guessed type float flt_6BE3A0;
 
@@ -9947,9 +9935,8 @@
   pBitmaps_LOD->SetupPalettes(pRenderer->uTargetRBits, pRenderer->uTargetGBits, pRenderer->uTargetBBits);
   pIcons_LOD->SetupPalettes(pRenderer->uTargetRBits, pRenderer->uTargetGBits, pRenderer->uTargetBBits);
   pPaletteManager->SetColorChannelInfo(pRenderer->uTargetRBits, pRenderer->uTargetGBits, pRenderer->uTargetBBits);
-  pPaletteManager->pPalette_mistColor[0] = 128;
-  pPaletteManager->pPalette_mistColor[1] = 128;
-  pPaletteManager->pPalette_mistColor[2] = 128;
+
+  pPaletteManager->SetMistColor(128, 128, 128);
   pPaletteManager->RecalculateAll();
   pSprites_LOD->field_ECAC = 1;
   pObjectList->InitializeSprites();
@@ -10013,12 +10000,8 @@
   pNPCStats->Initialize();
 
   Initialize_GlobalEVT();
-  pBitmaps_LOD->dword_11B80 = pBitmaps_LOD->uNumLoadedFiles;
-  if ( pBitmaps_LOD->dword_11B84 < (signed int)pBitmaps_LOD->uNumLoadedFiles )
-    pBitmaps_LOD->dword_11B84 = pBitmaps_LOD->uNumLoadedFiles;
-  pSprites_LOD->field_ECA4 = pSprites_LOD->uNumLoadedSprites;
-  if ( pSprites_LOD->field_ECA0 < (signed int)pSprites_LOD->uNumLoadedSprites )
-    pSprites_LOD->field_ECA0 = pSprites_LOD->uNumLoadedSprites;
+  pBitmaps_LOD->_inlined_sub0();
+  pSprites_LOD->_inlined_sub0();
   pPaletteManager->LockAll();
 
   _mkdir("Saves");
--- a/mm7_3.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/mm7_3.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -3046,20 +3046,14 @@
       if ( !v107
         && !(BYTE1(pOutdoor->pBModels[pParty->field_6F4_packedid >> 9].pFaces[(pParty->field_6F4_packedid >> 3) & 0x3F].uAttributes) & 0x20) )
       {
-        v96 = 0;
-        v94 = 0;
-        v92 = 0;
-        v91 = 0;
+        
         v90 = -1;
         v89 = 1;
         v88 = 804;
         v87 = 64;
         goto LABEL_257;
       }
-      v96 = 0;
-      v94 = 0;
-      v92 = 0;
-      v91 = 0;
+     
       v90 = -1;
       v89 = 1;
       v88 = 804;
@@ -3067,7 +3061,7 @@
 LABEL_255:
       v63 = WorldPosToGridCellZ(pParty->vPosition.y) - 1;
       v64 = WorldPosToGridCellX(pParty->vPosition.x);
-      v87 = pOutdoor->_47EE49(v64, v63, v86);
+      v87 = pOutdoor->GetSoundIdByPosition(v64, v63, v86);
       goto LABEL_257;
     }
     if ( v124 && (!bJumping || v101) )
@@ -3075,26 +3069,19 @@
       if ( v107
         || BYTE1(pOutdoor->pBModels[pParty->field_6F4_packedid >> 9].pFaces[(pParty->field_6F4_packedid >> 3) & 0x3F].uAttributes) & 0x20 )
       {
-        v96 = 0;
-        v94 = 0;
-        v92 = 0;
-        v91 = 0;
+        
         v90 = -1;
         v89 = 1;
         v88 = 804;
         v86 = 0;
         goto LABEL_255;
       }
-      v96 = 0;
-      v94 = 0;
-      v92 = 0;
-      v91 = 0;
       v90 = -1;
       v89 = 1;
       v88 = 804;
       v87 = 103;
 LABEL_257:
-      pAudioPlayer->PlaySound((SoundID)v87, v88, v89, v90, v91, v92, v94, v96);
+      pAudioPlayer->PlaySound((SoundID)v87, v88, v89, v90, 0, 0, 0, 0);
     }
     else
     {
@@ -6686,7 +6673,7 @@
   {
     v4 = (MapInfo *)thisa;
   }
-  day_attrib &= 0xFFFFFFFEu;
+  day_attrib &= ~DAY_ATTRIB_FOG;
   dword_6BE13C_uCurrentlyLoadedLocationID = v2;
   pOutdoor->Initialize(
     pFilename,
@@ -6825,7 +6812,7 @@
     return PaletteManager::Get(a2);
   if ( !pWeather->bNight )
   {
-    if ( day_attrib & 1 )
+    if (day_attrib & DAY_ATTRIB_FOG)
     {
       v14 = day_fogrange_1 << 16;
       if ( a3 >= day_fogrange_1 << 16 )
@@ -6958,7 +6945,7 @@
     v10 = 0;
   if ( !v10 )
   {
-    if ( !(day_attrib & 1) && !bUnderwater )
+    if ( !(day_attrib & DAY_ATTRIB_FOG) && !bUnderwater )
     {
       v14 = a5;
       v15 = a6;
@@ -7233,13 +7220,13 @@
 
   if ( bUnderwater )
   {
-    result = 0xFF258F5Cu;
-  }
-  else
-  {
-    if ( day_attrib & 1 )
-    {
-      if ( pWeather->bNight )
+    result = 0xFF258F5C;
+  }
+  else
+  {
+    if (day_attrib & DAY_ATTRIB_FOG)
+    {
+      if ( pWeather->bNight ) // night-time fog
       {
         __debugbreak(); // decompilation can be inaccurate, please  send savegame to Nomad
         v2 = -(pWeather->bNight != 1);
@@ -7252,9 +7239,7 @@
       }
     }
     else
-    {
-      result = 0;
-    }
+      return 0;
   }
   return result;
 }
@@ -7277,7 +7262,7 @@
   v3 = pWeather->bNight;
   if ( bUnderwater == 1 )
     v3 = 0;
-  if ( pParty->armageddon_timer || !(day_attrib & 1) && !bUnderwater )
+  if ( pParty->armageddon_timer || !(day_attrib & DAY_ATTRIB_FOG) && !bUnderwater )
     return 0xFF000000;
   if ( v3 )
   {
--- a/mm7_4.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/mm7_4.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -1864,7 +1864,7 @@
     if (SoundSetAction[24][0])
     {
       v1 = 0;
-      if ( (signed int)pSoundList->uNumSounds <= 0 )
+      if ( (signed int)pSoundList->sNumSounds <= 0 )
       {
 LABEL_7:
         v3 = 0;
@@ -1876,14 +1876,14 @@
         {
           ++v1;
           v2 += 120;
-          if ( v1 >= (signed int)pSoundList->uNumSounds )
+          if ( v1 >= (signed int)pSoundList->sNumSounds )
             goto LABEL_7;
         }
         v3 = v1;
       }
-      pSoundList->_4A9DCD(v3, 1);
+      pSoundList->UnloadSound(v3, 1);
       v4 = 0;
-      if ( (signed int)pSoundList->uNumSounds <= 0 )
+      if ( (signed int)pSoundList->sNumSounds <= 0 )
       {
 LABEL_12:
         v4 = 0;
@@ -1895,11 +1895,11 @@
         {
           ++v4;
           v5 += 120;
-          if ( (signed int)v4 >= (signed int)pSoundList->uNumSounds )
+          if ( (signed int)v4 >= (signed int)pSoundList->sNumSounds )
             goto LABEL_12;
         }
       }
-      pSoundList->_4A9DCD(v4, 1);
+      pSoundList->UnloadSound(v4, 1);
     }
     ++v0;
   }
@@ -2421,7 +2421,7 @@
   //char *v6; // ecx@5
   //Player *v7; // esi@8
   //char *v8; // ecx@12
-  Player *pPlayer; // esi@15
+  //Player *pPlayer; // esi@15
   //void *v10; // esi@25
   unsigned int v11; // ecx@27
   signed int v12; // edi@29
@@ -2467,23 +2467,23 @@
   signed int v52; // ecx@130
   int v53; // eax@131
   Player *v54; // eax@141
-  unsigned int v55; // [sp-8h] [bp-38h]@18
+  //unsigned int v55; // [sp-8h] [bp-38h]@18
   unsigned int v56; // [sp-8h] [bp-38h]@55
-  int v57; // [sp-4h] [bp-34h]@18
+  //int v57; // [sp-4h] [bp-34h]@18
   int v58; // [sp-4h] [bp-34h]@33
   int v59; // [sp-4h] [bp-34h]@55
   unsigned int v60; // [sp+10h] [bp-20h]@1
   unsigned int v61; // [sp+14h] [bp-1Ch]@1
   Player **v62; // [sp+14h] [bp-1Ch]@50
-  unsigned int a2; // [sp+18h] [bp-18h]@1
+  //unsigned int a2; // [sp+18h] [bp-18h]@1
   signed int a2a; // [sp+18h] [bp-18h]@47
   signed int v65; // [sp+1Ch] [bp-14h]@47
 
-  a2 = pParty->uCurrentHour;
+  //a2 = pParty->uCurrentHour;
   v61 = pParty->uDaysPlayed;
   v60 = pEventTimer->uTimeElapsed;
-  pParty->uTimePlayed += (signed int)pEventTimer->uTimeElapsed;
-  v0 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) / 60;
+  pParty->uTimePlayed += pEventTimer->uTimeElapsed;
+  v0 = (signed __int64)(pParty->uTimePlayed * 0.234375) / 60;
   v1 = v0;
   v0 /= 60i64;
   v2 = v0;
@@ -2496,7 +2496,7 @@
   pParty->uDaysPlayed = (unsigned int)v3 % 28;
   pParty->uCurrentMonth = v4 % 12;
   pParty->uCurrentYear = v4 / 0xC + game_starting_year;
-  if ( pParty->uCurrentHour >= 3 && ((signed int)a2 < 3 || (unsigned int)v3 % 28 > v61) )
+  if ( pParty->uCurrentHour >= 3 && (pParty->uCurrentHour < 3 || pParty->uDaysPlayed > v61) ) // new day dawns
   {
     pParty->pHirelings[0].bHasUsedTheAbility = false;
     pParty->pHirelings[1].bHasUsedTheAbility = false;
@@ -2504,56 +2504,41 @@
     for (uint i = 0; i < pNPCStats->uNumNewNPCs; ++i)
       pNPCStats->pNewNPCData[i].bHasUsedTheAbility = false;
 
-    ++pParty->field_764;
-    if ( pParty->field_764 > 1u )
+    ++pParty->days_played_without_rest;
+    if (pParty->days_played_without_rest > 1)
     {
       for (uint i = 0; i < 4; ++i)
-        pParty->pPlayers[i].SetCondition(1, 0);
-
-      if ( pParty->uNumFoodRations )
-      {
-        Party::TakeFood(1u);
-      }
+        pParty->pPlayers[i].SetCondition(Player::Condition_Weak, 0);
+
+      if (pParty->uNumFoodRations)
+        Party::TakeFood(1);
       else
-      {
         for (uint i = 0; i < 4; ++i)
-          pParty->pPlayers[i].sHealth = pParty->pPlayers[i].sHealth / ((unsigned __int8)pParty->field_764 + 1) + 1;
-      }
-      if ( pParty->field_764 > 3u )
-      {
-        pPlayer = pParty->pPlayers;
-        do
+          pParty->pPlayers[i].sHealth = pParty->pPlayers[i].sHealth / (pParty->days_played_without_rest + 1) + 1;
+
+      if (pParty->days_played_without_rest > 3)
+        for (uint i = 0; i < 4; ++i)
         {
-          pPlayer->Zero();
-          if ( !(pPlayer->pConditions[15] | pPlayer->pConditions[16] | pPlayer->pConditions[14]) )
+          auto player = pParty->pPlayers + i;
+
+          player->Zero();
+
+          if (!player->Pertified() && !player->Eradicated() && !player->Dead())
           {
-            if ( rand() % 100 < 5 * (unsigned __int8)pParty->field_764 )
-            {
-              v57 = 0;
-              v55 = 14;
-LABEL_21:
-              pPlayer->SetCondition(v55, v57);
-              goto LABEL_22;
-            }
-            if ( rand() % 100 < 10 * (unsigned __int8)pParty->field_764 )
-            {
-              v57 = 0;
-              v55 = 5;
-              goto LABEL_21;
-            }
+            if (rand() % 100 < 5 * pParty->days_played_without_rest)
+              player->SetCondition(Player::Condition_Dead, 0);
+            if (rand() % 100 < 10 * pParty->days_played_without_rest)
+              player->SetCondition(Player::Condition_Insane, 0);
           }
-LABEL_22:
-          ++pPlayer;
         }
-        while ( (signed int)pPlayer < (signed int)pParty->pHirelings );
-      }
-    }
-    if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor )
+    }
+    if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
       pOutdoor->SetFog();
 
     for (uint i = 0; i < 4; ++i)
       pParty->pPlayers[i].uNumDivineInterventionCastsThisDay = 0;
   }
+
   v11 = LODWORD(pParty->uTimePlayed);
   if ( pParty->uFlags & 4 && pParty->field_6FC < (signed __int64)pParty->uTimePlayed )
   {
@@ -6255,7 +6240,7 @@
 }
 
 //----- (004B1523) --------------------------------------------------------
-char *__thiscall sub_4B1523(int *_this)
+void __thiscall sub_4B1523(int *_this)
 {
   int v1; // esi@1
   int v2; // edx@1
@@ -6321,7 +6306,7 @@
   a1.uFrameWidth = 108;
   a1.DrawTitleText(pFontComic, 0xCu, 0x4Bu, 0, pSkillNames[v11 / 4 + 12], 3u);
   sprintf(pTmpBuf, "%s\n%d", pGlobalTXT_LocalizationStrings[522], *(&pSpellDatas[0].uNormalLevelMana + 10 * v1));
-  return a1.DrawTitleText(pFontComic, 0xCu, a1.uFrameHeight - LOBYTE(pFontComic->uFontHeight) - 16, 0, pTmpBuf, 3);
+  a1.DrawTitleText(pFontComic, 0xCu, a1.uFrameHeight - LOBYTE(pFontComic->uFontHeight) - 16, 0, pTmpBuf, 3);
 }
 
 
@@ -7310,7 +7295,7 @@
 
 
 //----- (004B2A74) --------------------------------------------------------
-char __cdecl SimpleHouseAndBoatsDialog()
+void SimpleHouseAndBoatsDialog()
 {
   char *v0; // esi@3
   char *v1; // ST1C_4@3
@@ -7391,8 +7376,8 @@
     }
     v3 = v2;
     v4 = pFontCreate->CalcTextHeight(v2, &a1, 0, 0);
-    LOBYTE(i) = (unsigned int)a1.DrawTitleText(pFontCreate, 0, (212 - v4) / 2 + 101, 0, v3, 3u);
-    return i;
+    a1.DrawTitleText(pFontCreate, 0, (212 - v4) / 2 + 101, 0, v3, 3u);
+    return;
   }
   a1.uFrameWidth -= 10;
   a1.uFrameZ -= 10;
@@ -7631,9 +7616,8 @@
       (uTextureID_Leather != -1 ? pIcons_LOD->pTextures[uTextureID_Leather].uTextureHeight : 26) - v48);
     pRenderer->DrawTextureIndexed(8u, 347 - v48, pTexture_591428);
     v49 = FitTextInAWindow(ptr_F8B1E8, v47, &w, 0xDu, 0);
-    LOBYTE(i) = a1.DrawText(v47, 13, 354 - v48, 0, v49, 0, 0, 0);
-  }
-  return i;
+    a1.DrawText(v47, 13, 354 - v48, 0, v49, 0, 0, 0);
+  }
 }
 
 
--- a/mm7_5.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/mm7_5.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -1694,7 +1694,7 @@
                   ++pPlayer7;
                 }
                 while ( (signed int)pPlayer7 < (signed int)pParty->pHirelings );
-                ++pParty->field_764;
+                ++pParty->days_played_without_rest;
               }
               Party::TakeFood((unsigned int)pNPCData4);
             }
@@ -1707,7 +1707,7 @@
                 ++pPlayer8;
               }
               while ( (signed int)pPlayer8 < (signed int)pParty->pHirelings );
-              ++pParty->field_764;
+              ++pParty->days_played_without_rest;
             }
             pPaletteManager->ResetNonLocked();
             pSpriteFrameTable->ResetSomeSpriteFlags();
@@ -2568,11 +2568,11 @@
           //goto LABEL_615;
           dword_506F14 = 2;
           pParty->RestAndHeal();
-          pParty->field_764 = 0;
-          pParty->pPlayers[3].pConditions[2] = pParty->uTimePlayed;
-          pParty->pPlayers[2].pConditions[2] = pParty->uTimePlayed;
-          pParty->pPlayers[1].pConditions[2] = pParty->uTimePlayed;
-          pParty->pPlayers[0].pConditions[2] = pParty->uTimePlayed;
+          pParty->days_played_without_rest = 0;
+          pParty->pPlayers[3].pConditions[Player::Condition_Sleep] = pParty->uTimePlayed;
+          pParty->pPlayers[2].pConditions[Player::Condition_Sleep] = pParty->uTimePlayed;
+          pParty->pPlayers[1].pConditions[Player::Condition_Sleep] = pParty->uTimePlayed;
+          pParty->pPlayers[0].pConditions[Player::Condition_Sleep] = pParty->uTimePlayed;
           continue;
         case UIMSG_68:
           if ( pMessageQueue_50CBD0->uNumMessages )
@@ -2715,11 +2715,11 @@
 //LABEL_615:
             dword_506F14 = 2;
             pParty->RestAndHeal();
-            pParty->field_764 = 0;
-            pParty->pPlayers[3].pConditions[2] = pParty->uTimePlayed;
-            pParty->pPlayers[2].pConditions[2] = pParty->uTimePlayed;
-            pParty->pPlayers[1].pConditions[2] = pParty->uTimePlayed;
-            pParty->pPlayers[0].pConditions[2] = pParty->uTimePlayed;
+            pParty->days_played_without_rest = 0;
+            pParty->pPlayers[3].pConditions[Player::Condition_Sleep] = pParty->uTimePlayed;
+            pParty->pPlayers[2].pConditions[Player::Condition_Sleep] = pParty->uTimePlayed;
+            pParty->pPlayers[1].pConditions[Player::Condition_Sleep] = pParty->uTimePlayed;
+            pParty->pPlayers[0].pConditions[Player::Condition_Sleep] = pParty->uTimePlayed;
           }
           continue;
         case UIMSG_AlreadyResting:
@@ -10618,20 +10618,12 @@
 
 
 //----- (004141CA) --------------------------------------------------------
-GUIWindow *__fastcall ModalWindow(const char *pStr, int a4)
-{
-  const char *v2; // edi@1
-  int v3; // esi@1
-  GUIWindow *result; // eax@1
-
-  v2 = pStr;
-  v3 = a4;
+void ModalWindow(const char *pStr, int a4)
+{
   pEventTimer->Pause();
   dword_506F0C[0] = pCurrentScreen;
-  result = GUIWindow::Create(0, 0, 640, 480, WINDOW_FinalWindow, v3, (int)v2);
-  ptr_507BDC = result;
+  ptr_507BDC = GUIWindow::Create(0, 0, 640, 480, WINDOW_FinalWindow, a4, (int)pStr);
   pCurrentScreen = SCREEN_PRESS_ESCAPE_MESSAGE;
-  return result;
 }
 // 4E28F8: using guessed type int pCurrentScreen;
 
@@ -10674,7 +10666,11 @@
 
 
 
-
+void LoadFonts_and_DrawCopyrightWindow()
+{
+  MainMenuUI_LoadFontsAndSomeStuff();
+  DrawCopyrightWindow();
+}
 
 //----- (00415485) --------------------------------------------------------
 void DrawCopyrightWindow()
--- a/mm7_data.cpp	Sun Mar 24 00:31:56 2013 +0600
+++ b/mm7_data.cpp	Sun Mar 24 00:32:13 2013 +0600
@@ -1107,7 +1107,6 @@
 char aTiletableLoadU[777]; // idb
 char byte_4ECA93[777]; // weak
 char byte_4ECACF[777]; // weak
-char byte_4ECB0C[64]; // idb
 char aError_0[777]; // idb
 char aCouldnTLoadMap[777]; // idb
 char aOut02d_odm[777]; // idb
--- a/mm7_data.h	Sun Mar 24 00:31:56 2013 +0600
+++ b/mm7_data.h	Sun Mar 24 00:32:13 2013 +0600
@@ -953,7 +953,6 @@
 extern char aTiletableLoadU[]; // idb
 extern char byte_4ECA93[]; // weak
 extern char byte_4ECACF[]; // weak
-extern char byte_4ECB0C[64]; // idb
 extern char aError_0[]; // idb
 extern char aCouldnTLoadMap[]; // idb
 extern char aOut02d_odm[]; // idb
@@ -1793,7 +1792,7 @@
 int __fastcall am_40D2B4(struct Vec2_int_ *, int); // weak
 int __fastcall am_40D402(int, int); // weak
 int __cdecl am_40D444();
-struct GUIWindow *__fastcall ModalWindow(const char *pStr, int a4);
+void ModalWindow(const char *pStr, int a4);
 char __fastcall pPrimaryWindow_draws_text(int a1, const char *pText, int *pXY);
 void __thiscall am_BeginScene(unsigned __int16 *pPcxPixels, int a2, int a3); // idb
 void __fastcall Blt_Chroma(struct ArcomageRect *pSrcXYZW, int *pTargetXY, int a3, int a4);
@@ -1847,6 +1846,7 @@
 void __cdecl DrawGameOptions();
 void __fastcall DrawPopupWindow(unsigned int uX, unsigned int uY, unsigned int uWidth, unsigned int uHeight); // idb
 void DrawCopyrightWindow();
+void LoadFonts_and_DrawCopyrightWindow();
 void __cdecl GUI_UpdateWindows();
 void __cdecl identify_item();
 void __thiscall sub_416B01(void *_this);
@@ -2280,7 +2280,7 @@
 void __cdecl nullsub_20(); // idb
 void __cdecl nullsub_21(); // idb
 struct Player *__fastcall sub_4B1447_party_fine(int a1, int a2, int a3);
-char *__thiscall sub_4B1523(int *_this);
+void __thiscall sub_4B1523(int *_this);
 bool __cdecl sub_4B1784_check_if_player_concious__draw_warning_else_mess_with_dlg_win();
 void __cdecl sub_4B1A2D();
 void __stdcall RestAndHeal(__int64 uNumMinutes); // idb
@@ -2290,7 +2290,7 @@
 void __fastcall ClickNPCTopic(signed int uMessageParam);
 char *__thiscall _4B254D_SkillMasteryTeacher(int _this);
 const char * ContractSelectText(int pEventCode);
-char __cdecl SimpleHouseAndBoatsDialog();
+void SimpleHouseAndBoatsDialog();
 void  CreateButtonInColumn(int a1, unsigned int a2);
 void FillAviableSkillsToTeach(int _this);
 void  sub_4B3A72(int a1); // idb
@@ -2341,6 +2341,8 @@
 signed int __fastcall SpawnRandomTreasure(struct MapInfo *a1, struct SpawnPointMM7 *a2);
 void DamageMonsterFromParty(signed int a1, unsigned int uActorID_Monster, struct Vec3_int_ *pVelocity);
 
+int fixpoint_mul(int, int);
+
 
 #define ErrD3D(hr) do {extern void ErrHR(HRESULT, const char *, const char *, const char *, int); ErrHR(hr, "Direct3D", __FUNCTION__, __FILE__, __LINE__);} while(0)