changeset 2116:18dee3152c52

Merge
author Grumpy7
date Mon, 23 Dec 2013 15:18:16 +0100
parents 90cc547a7927 (current diff) 68fbaf45ef66 (diff)
children 16e2ed54f269
files mm7_4.cpp
diffstat 15 files changed, 411 insertions(+), 517 deletions(-) [+]
line wrap: on
line diff
--- a/Actor.cpp	Mon Dec 23 15:17:50 2013 +0100
+++ b/Actor.cpp	Mon Dec 23 15:18:16 2013 +0100
@@ -1669,7 +1669,7 @@
     v3->vVelocity.z = 0;
     v3->vVelocity.y = 0;
     v3->vVelocity.x = 0;
-    if ( _42FB5C_check_spell(v16) )
+    if ( _42FB5C_check_spell(v3->pMonsterInfo.uSpell1ID) )
     {
       v3->uCurrentActionLength = 64;
       v3->uCurrentActionTime = 0;
--- a/AudioPlayer.cpp	Mon Dec 23 15:17:50 2013 +0100
+++ b/AudioPlayer.cpp	Mon Dec 23 15:18:16 2013 +0100
@@ -45,15 +45,17 @@
 
 
 
-unsigned __int8 uSoundVolumeMultiplier = 4;
-unsigned __int8 uVoicesVolumeMultiplier = 4;
-unsigned __int8 uMusicVolimeMultiplier = 4;
+unsigned __int8 uSoundVolumeMultiplier;// = 4;
+unsigned __int8 uVoicesVolumeMultiplier;// = 4;
+unsigned __int8 uMusicVolimeMultiplier;// = 4;
 int bWalkSound; // idb
 
 std::array<float, 10> pSoundVolumeLevels = 
 {
   0.0000000f, 0.1099999f, 0.2199999f, 0.3300000f, 0.4399999f,
- 0.5500000f, 0.6600000f, 0.7699999f, 0.8799999f, 0.9700000f     //changed 0.9900000f to 0.9700000f. for some reason it only works for values below this
+ 0.5500000f, 0.6600000f, 0.7699999f, 0.8799999f, 0.9700000f  
+//  0.0000000f, 0.4900000f, 0.5500000f, 0.6100000f, 0.6700000f,  //for 128.0f
+// 0.7000000f, 0.7600000f, 0.8200000f, 0.8800000f, 0.9700000f     //changed 0.9900000f to 0.9700000f. for some reason it only works for values below this
 };
 
 
@@ -81,13 +83,16 @@
   {
     for ( uint i = 1; i < pSoundList->sNumSounds; ++i )
     {
-      sprintf(pSoundName, "%s", pSounds[i].pSoundName);
-      pSoundDesc = &pSoundList->pSounds[i];
-      if ( pSoundList->pSounds[i].eType != SOUND_DESC_SYSTEM || (sprintf(pSoundName, "%s", pSounds[i].pSoundName),
-            pSoundList->pSounds[i].pSoundData[0] = ::LoadSound(pSoundName, (SoundData *)-1, pSounds[i].uSoundID),
-            !pAudioPlayer->b3DSoundInitialized)
-        || (pSoundDesc = &pSoundList->pSounds[i], !(pSoundDesc->uFlags & SOUND_DESC_SWAP))
-        || !pSoundDesc->pSoundData[0] )
+      sprintf(pSoundName, "%s", pSL_Sounds[i].pSoundName);
+      pSoundDesc = &pSoundList->pSL_Sounds[i];
+      if ( pSoundList->pSL_Sounds[i].eType != SOUND_DESC_SYSTEM )
+        continue;
+      sprintf(pSoundName, "%s", pSL_Sounds[i].pSoundName);
+      pSoundList->pSL_Sounds[i].pSoundData[0] = ::LoadSound(pSoundName, (SoundData *)-1, pSL_Sounds[i].uSoundID);
+      if ( !pAudioPlayer->b3DSoundInitialized )
+        continue;
+      pSoundDesc = &pSoundList->pSL_Sounds[i];
+      if ( !(pSoundDesc->uFlags & SOUND_DESC_SWAP) || !pSoundDesc->pSoundData[0] )
         continue;
       pSoundData = pSoundDesc->pSoundData[0];
       uSoundSize = *(int *)pSoundData;
@@ -95,7 +100,7 @@
       pType = AIL_file_type(pSoundBytes, uSoundSize);
       if ( !pType )
       {
-        pSoundList->pSounds[i].bDecompressed = false;
+        pSoundList->pSL_Sounds[i].bDecompressed = false;
         pSoundList->UnloadSound(i, 1);
         continue;
       }
@@ -106,20 +111,20 @@
         {
           if ( AIL_WAV_info(pSoundBytes, &pInfo) && pInfo.uChannels != 2 )
           {
-            if ( !AIL_decompress_ADPCM(&pInfo, &pSoundList->pSounds[i].p3DSound, &v12) )
+            if ( !AIL_decompress_ADPCM(&pInfo, &pSoundList->pSL_Sounds[i].p3DSound, &v12) )
             {
-              pSoundList->pSounds[i].p3DSound = 0;
-              pSoundList->pSounds[i].bDecompressed = true;
+              pSoundList->pSL_Sounds[i].p3DSound = 0;
+              pSoundList->pSL_Sounds[i].bDecompressed = true;
             }
           }
           pSoundList->UnloadSound(i, 1);
           continue;
         }
-        pSoundList->pSounds[i].bDecompressed = false;
+        pSoundList->pSL_Sounds[i].bDecompressed = false;
         pSoundList->UnloadSound(i, 1);
         continue;
       }
-      pSoundList->pSounds[i].p3DSound = pSoundList->pSounds[i].pSoundData[0];
+      pSoundList->pSL_Sounds[i].p3DSound = pSoundList->pSL_Sounds[i].pSoundData[0];
       pSoundList->UnloadSound(i, 1);
     }
   }
@@ -136,10 +141,10 @@
   uint       uSoundIdx = 0;
   SoundDesc *pSound = nullptr;
   for (uint i = 1; i < sNumSounds; ++i)
-    if (pSounds[i].uSoundID == a1)
+    if (pSL_Sounds[i].uSoundID == a1)
     {
       uSoundIdx = i;
-      pSound = &pSounds[i];
+      pSound = &pSL_Sounds[i];
       break;
     }
   if (!pSound)
@@ -230,7 +235,7 @@
     v25 = 44;
     while ( 1 )
     {
-      v10 = pSounds;
+      v10 = pSL_Sounds;
       v11 = &v10[v24 / 0x78];
       Args = &v10[v24 / 0x78];
       if ( a2 == v10[v24 / 0x78].uSoundID )
@@ -288,7 +293,7 @@
       v16 = a2;
     }
     result = v26;
-    pSounds->pSoundData[a6 + 30 * v26] = (SoundData *)lpBuffer;
+    pSL_Sounds->pSoundData[a6 + 30 * v26] = (SoundData *)lpBuffer;
     *pOutSoundSize = v16;
 
   return result;
@@ -304,13 +309,13 @@
   {
     for ( uint i = 0; i < (signed int)this->sNumSounds; ++i )
     {
-      result = this->pSounds;
+      result = this->pSL_Sounds;
       v5 = result[i].pSoundData[0];
       if ( v5 )
       {
         ReleaseSoundData(v5);
-        this->pSounds[i].pSoundData[0] = 0;
-        result = (SoundDesc *)((char *)&this->pSounds[i] + 40);
+        this->pSL_Sounds[i].pSoundData[0] = 0;
+        result = (SoundDesc *)((char *)&this->pSL_Sounds[i] + 40);
         *(int *)&result->pSoundName[0] &= 0xFFFFFFFEu;
       }
     }
@@ -323,14 +328,14 @@
 {
   for ( int i = 0; i < (signed int)this->sNumSounds; ++i )
   {
-    if ( this->pSounds[i].eType != SOUND_DESC_SYSTEM && (a2 || this->pSounds[i].eType != SOUND_DESC_LOCK) )
+    if ( this->pSL_Sounds[i].eType != SOUND_DESC_SYSTEM && (a2 || this->pSL_Sounds[i].eType != SOUND_DESC_LOCK) )
     {
-      if ( this->pSounds[i].pSoundData[0] )
+      if ( this->pSL_Sounds[i].pSoundData[0] )
       {
-        ReleaseSoundData(this->pSounds[i].pSoundData[0]);
-        this->pSounds[i].pSoundData[0] = 0;
+        ReleaseSoundData(this->pSL_Sounds[i].pSoundData[0]);
+        this->pSL_Sounds[i].pSoundData[0] = 0;
       }
-      this->pSounds[i].uFlags &= ~SOUND_DESC_SYSTEM;
+      this->pSL_Sounds[i].uFlags &= ~SOUND_DESC_SYSTEM;
     }
   }
 }
@@ -338,20 +343,20 @@
 //----- (004A9DCD) --------------------------------------------------------
 void SoundList::UnloadSound(unsigned int uSoundID, char a3)
 {
-  if ( pSounds[uSoundID].eType != SOUND_DESC_SYSTEM )
+  if ( pSL_Sounds[uSoundID].eType != SOUND_DESC_SYSTEM )
   {
-    if ( (pSounds[uSoundID].uFlags & SOUND_DESC_SWAP) && pSounds[uSoundID].p3DSound && a3 )
+    if ( (pSL_Sounds[uSoundID].uFlags & SOUND_DESC_SWAP) && pSL_Sounds[uSoundID].p3DSound && a3 )
     {
-      if ( pSounds[uSoundID].bDecompressed)
-        AIL_mem_free_lock(pSounds[uSoundID].p3DSound);
-      pSounds[uSoundID].p3DSound = 0;
-      pSounds[uSoundID].uFlags &= ~SOUND_DESC_SYSTEM;
+      if ( pSL_Sounds[uSoundID].bDecompressed)
+        AIL_mem_free_lock(pSL_Sounds[uSoundID].p3DSound);
+      pSL_Sounds[uSoundID].p3DSound = 0;
+      pSL_Sounds[uSoundID].uFlags &= ~SOUND_DESC_SYSTEM;
     }
-    if ( pSounds[uSoundID].pSoundData[0] )
+    if ( pSL_Sounds[uSoundID].pSoundData[0] )
     {
-      ReleaseSoundData(pSounds[uSoundID].pSoundData[0]);
-      pSounds[uSoundID].pSoundData[0] = NULL;
-      pSounds[uSoundID].uFlags &= ~SOUND_DESC_SYSTEM;
+      ReleaseSoundData(pSL_Sounds[uSoundID].pSoundData[0]);
+      pSL_Sounds[uSoundID].pSoundData[0] = NULL;
+      pSL_Sounds[uSoundID].uFlags &= ~SOUND_DESC_SYSTEM;
     }
   }
 }
@@ -367,7 +372,7 @@
     Error("Unable to save dsounds.bin!");
 
   fwrite(this, 4, 1, v2);
-  fwrite(this->pSounds, 0x78u, this->sNumSounds, v2);
+  fwrite(this->pSL_Sounds, 0x78u, this->sNumSounds, v2);
   fclose(v2);
 }
 
@@ -382,12 +387,12 @@
   assert(sNumSounds);
   assert(!num_mm8_sounds);
 
-  pSounds = (SoundDesc *)malloc(sNumSounds * sizeof(SoundDesc));
-  memcpy(pSounds, (char *)data_mm7 + 4, num_mm7_sounds * sizeof(SoundDesc));
+  pSL_Sounds = (SoundDesc *)malloc(sNumSounds * sizeof(SoundDesc));
+  memcpy(pSL_Sounds, (char *)data_mm7 + 4, num_mm7_sounds * sizeof(SoundDesc));
   for (uint i = 0; i < num_mm6_sounds; ++i)
   {
     auto src = (SoundDesc_mm6 *)((char *)data_mm6 + 4) + i;
-    SoundDesc* dst = &pSounds[num_mm7_sounds + i];
+    SoundDesc* dst = &pSL_Sounds[num_mm7_sounds + i];
 
     memcpy(dst, src, sizeof(SoundDesc_mm6));
     dst->p3DSound = nullptr;
@@ -417,9 +422,9 @@
   FILE *File; // [sp+2F8h] [bp-4h]@1
   unsigned int Argsa; // [sp+304h] [bp+8h]@3
 
-  free(this->pSounds);
+  free(this->pSL_Sounds);
   v3 = 0;
-  this->pSounds = 0;
+  this->pSL_Sounds = 0;
   this->sNumSounds = 0;
   v4 = fopen(Args, "r");
   File = v4;
@@ -443,7 +448,7 @@
   }
   this->sNumSounds = v5;
   v6 = malloc(120 * v5);
-  this->pSounds = (SoundDesc *)v6;
+  this->pSL_Sounds = (SoundDesc *)v6;
   if ( v6 == (void *)v3 )
     Error("SoundListClass::load - Out of Memory!");
 
@@ -457,16 +462,16 @@
     memcpy(&v19, txt_file_frametable_parser(&Buf, &v18), sizeof(v19));
     if ( v19.uPropCount && *v19.pProperties[0] != 47 )
     {
-      sprintf(this->pSounds[this->sNumSounds].pSoundName, "%s", v19.pProperties[0]);
+      sprintf(this->pSL_Sounds[this->sNumSounds].pSoundName, "%s", v19.pProperties[0]);
       v9 = atoi(v19.pProperties[1]);
       v10 = v19.pProperties[2];
-      this->pSounds[this->sNumSounds].uSoundID = v9;
+      this->pSL_Sounds[this->sNumSounds].uSoundID = v9;
       if ( _stricmp(v10, "system") )
       {
         if ( _stricmp(v19.pProperties[2], "swap") )
         {
           v11 = _stricmp(v19.pProperties[2], "lock");
-          v12 = this->pSounds;
+          v12 = this->pSL_Sounds;
           v13 = v11 == 0;
           v14 = this->sNumSounds;
           if ( v13 )
@@ -475,13 +480,13 @@
             v12[v14].eType = SOUND_DESC_LEVEL;
         }
         else
-          this->pSounds[this->sNumSounds].eType = SOUND_DESC_SWAP;
+          this->pSL_Sounds[this->sNumSounds].eType = SOUND_DESC_SWAP;
       }
       else
-        this->pSounds[this->sNumSounds].eType = SOUND_DESC_SYSTEM;
+        this->pSL_Sounds[this->sNumSounds].eType = SOUND_DESC_SYSTEM;
       if ( v19.uPropCount >= 4 && !_stricmp(v19.pProperties[3], "3D") )
       {
-        v15 = (int)&this->pSounds[this->sNumSounds].uFlags;
+        v15 = (int)&this->pSL_Sounds[this->sNumSounds].uFlags;
         *(int *)v15 |= SOUND_DESC_SWAP;
       }
       ++this->sNumSounds;
@@ -557,7 +562,7 @@
 }
 
 //----- (004AA306) --------------------------------------------------------
-void AudioPlayer::PlaySound(SoundID eSoundID, signed int a3, unsigned int uNumRepeats, signed int PartyX, signed int PartyY, int a7, unsigned int uVolume, int sPlaybackRate)
+void AudioPlayer::PlaySound(SoundID eSoundID, signed int a3, unsigned int uNumRepeats, signed int source_x, signed int source_y, int a7, float uVolume, int sPlaybackRate)
 {
   int v12; // edi@13
   signed int v13; // ecx@17
@@ -626,7 +631,7 @@
 
   int sound_id = 0;
   for (uint i = 0; i < pSoundList->sNumSounds; ++i)
-    if (pSoundList->pSounds[i].uSoundID == eSoundID)
+    if (pSoundList->pSL_Sounds[i].uSoundID == eSoundID)
     {
       sound_id = i;
       break;
@@ -640,20 +645,20 @@
   assert(sound_id < pSoundList->sNumSounds);
   if ( !a7 )
   {
-    if ( !pSoundList->pSounds[sound_id].pSoundData[0] )
+    if ( !pSoundList->pSL_Sounds[sound_id].pSoundData[0] )
     {
-      if ( pSoundList->pSounds[sound_id].eType == SOUND_DESC_SWAP )
+      if ( pSoundList->pSL_Sounds[sound_id].eType == SOUND_DESC_SWAP )
         pSoundList->LoadSound(eSoundID, 0);
     }
   }
-  if ( !pSoundList->pSounds[sound_id].pSoundData[a7] )
+  if ( !pSoundList->pSL_Sounds[sound_id].pSoundData[a7] )
     return;
 
   int start_channel = 0,
       end_channel = 0;
   v62 = start_channel;
 
-  if (!b3DSoundInitialized || pSoundList->pSounds[sound_id].Is3D())
+  if (!b3DSoundInitialized || pSoundList->pSL_Sounds[sound_id].Is3D())
   {
     if (a3 == 0)  // generic sound like from UI
     {
@@ -674,22 +679,30 @@
         if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
         {
           AIL_init_sample(pMixerChannels[j].hSample);
-          AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+          char *p = (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7];
+          if (a7 == 0)  p = p + 4;//for RIFF
+		  if ( eSoundID == 75 )// Ritor1: include +7 for pSounds[20]
+			  p = p + 7;
+          AIL_set_sample_file(pMixerChannels[j].hSample, p, -1);
           if ( sample_volume == 10000 )
             sample_volume = uMasterVolume;
           if (uVolume)
             sample_volume = uVolume;
           int object_type = PID_TYPE(a3),
               object_id = PID_ID(a3);
-          /*if (PartyX != -1)
+          if (source_x != -1)//срабатывает например у форта в Хермондейле звук выстрелов пушек
           {
-            if (!PartyX)
-              PartyX = pParty->vPosition.x;
-            if (!PartyY)
-              PartyY = pParty->vPosition.y;
-            AIL_set_sample_pan(pMixerChannels[v62].hSample, sub_4AB66C(PartyX, PartyY));
-            AIL_set_sample_volume(pMixerChannels[v62].hSample, GetSoundStrengthByDistanceFromParty(PartyX, PartyY, pParty->vPosition.z));
-          }	*/
+            //if (!source_x)
+              //source_x = pParty->vPosition.x;
+            //if (!source_y)
+              //source_y = pParty->vPosition.y;
+           if ( source_x )//Ritor1: for pedestals
+           {
+              AIL_set_sample_pan(pMixerChannels[j].hSample, sub_4AB66C(source_x, source_y));
+              int vol = GetSoundStrengthByDistanceFromParty(source_x, source_y, pParty->vPosition.z);
+              AIL_set_sample_volume(pMixerChannels[j].hSample, vol);
+           }
+          }
           if (uNumRepeats)
             AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1);
           pMixerChannels[j].uSourceTrackIdx = sound_id;
@@ -707,12 +720,37 @@
     }
     else if (a3 == -1)  // exclusive sounds - can override
     {
-      if ( AIL_sample_status(pMixerChannels[13].hSample) == AIL::Sample::Done )
+      /*if ( AIL_sample_status(pMixerChannels[13].hSample) == AIL::Sample::Done )
       {
-        AIL_end_sample(pMixerChannels[13].hSample);
-        if ( pMixerChannels[13].uSourceTrackIdx )
-          FreeChannel(&pMixerChannels[13]);
-      }
+          AIL_end_sample(pMixerChannels[13].hSample);
+          if ( pMixerChannels[13].uSourceTrackIdx )
+            FreeChannel(&pMixerChannels[13]);
+      }*/
+      AIL_init_sample(pMixerChannels[13].hSample);
+      char *p = (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7];
+      if (a7 == 0)
+        p = p + 4;//for RIFF
+	  if ( eSoundID == 75 )//  Ritor1: include +7 for pSounds[20]
+		  p = p + 7;
+       AIL_set_sample_file(pMixerChannels[13].hSample, p, -1);
+       if ( sample_volume == 10000 )
+         sample_volume = uMasterVolume;
+       if (uVolume)
+         sample_volume = uVolume;
+       AIL_set_sample_volume(pMixerChannels[13].hSample, sample_volume);
+       int object_type = PID_TYPE(a3),
+           object_id = PID_ID(a3);
+       if (uNumRepeats)
+         AIL_set_sample_loop_count(pMixerChannels[13].hSample, uNumRepeats - 1);
+       pMixerChannels[13].uSourceTrackIdx = sound_id;
+       pMixerChannels[13].source_pid = a3;
+       pMixerChannels[13].uSourceTrackID = eSoundID;
+       int rval = AIL_start_sample(pMixerChannels[13].hSample);//no sound chest close 
+       if ( sPlaybackRate )
+         AIL_set_sample_playback_rate(pMixerChannels[13].hSample, sPlaybackRate);
+       if (object_type == OBJECT_Player)
+         AIL_sample_ms_position(pMixerChannels[13].hSample, &sLastTrackLengthMS, 0);
+       return;
     }
     else if (a3 < 0)    // exclusive sounds - no override (close chest)
     {
@@ -733,7 +771,11 @@
         if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
         {
           AIL_init_sample(pMixerChannels[j].hSample);
-          AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+          char *p = (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7];
+          if (a7 == 0)  p = p + 4;//for RIFF
+		  if ( eSoundID == 75 )//  Ritor1: include +7 for pSounds[20]
+			  p = p + 7;
+          AIL_set_sample_file(pMixerChannels[j].hSample, p, -1);
           if ( sample_volume == 10000 )
             sample_volume = uMasterVolume;
           if (uVolume)
@@ -785,7 +827,7 @@
               if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
               {
                 AIL_init_sample(pMixerChannels[j].hSample);
-                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
                 if (uVolume)
                   sample_volume = uVolume;
                 AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume);
@@ -831,7 +873,7 @@
               if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
               {
                 AIL_init_sample(pMixerChannels[j].hSample);
-                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
                 if (uVolume)
                   sample_volume = uVolume;
                 AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume);
@@ -874,7 +916,7 @@
               if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
               {
                 AIL_init_sample(pMixerChannels[j].hSample);
-                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
                 if (uVolume)
                   sample_volume = uVolume;
                 AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume);
@@ -920,7 +962,7 @@
               if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
               {
                 AIL_init_sample(pMixerChannels[j].hSample);
-                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
                 if (uVolume)
                   sample_volume = uVolume;
                 AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume);
@@ -966,7 +1008,7 @@
               if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
               {
                 AIL_init_sample(pMixerChannels[j].hSample);
-                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
                 if (uVolume)
                   sample_volume = uVolume;
                 AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume);
@@ -1008,7 +1050,7 @@
               if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
               {
                 AIL_init_sample(pMixerChannels[j].hSample);
-                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
                 if (uVolume)
                   sample_volume = uVolume;
                 AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume);
@@ -1064,21 +1106,21 @@
         sample_volume = uMasterVolume;
 
       AIL_init_sample(pMixerChannels[v62].hSample);
-      AIL_set_sample_file(pMixerChannels[v62].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+      AIL_set_sample_file(pMixerChannels[v62].hSample, (char *)pSoundList->pSL_Sounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
       if (uVolume)
         sample_volume = uVolume;
       AIL_set_sample_volume(pMixerChannels[v62].hSample, sample_volume);
 
       int object_type = PID_TYPE(a3),
           object_id = PID_ID(a3);
-      if (PartyX != -1)
+      if (source_x != -1)
       {
-        if (!PartyX)
-          PartyX = pParty->vPosition.x;
-        if (!PartyY)
-          PartyY = pParty->vPosition.y;
-        AIL_set_sample_pan(pMixerChannels[v62].hSample, sub_4AB66C(PartyX, PartyY));
-        AIL_set_sample_volume(pMixerChannels[v62].hSample, GetSoundStrengthByDistanceFromParty(PartyX, PartyY, pParty->vPosition.z));
+        if (!source_x)
+          source_x = pParty->vPosition.x;
+        if (!source_y)
+          source_y = pParty->vPosition.y;
+        AIL_set_sample_pan(pMixerChannels[v62].hSample, sub_4AB66C(source_x, source_y));
+        AIL_set_sample_volume(pMixerChannels[v62].hSample, GetSoundStrengthByDistanceFromParty(source_x, source_y, pParty->vPosition.z));
       }
 
       if (uNumRepeats)
@@ -1316,18 +1358,18 @@
     v102 = v36;
   }
   //v39 = v89;
-  if ( pSoundList->pSounds[sound_id].p3DSound || (LOWORD(v40) = pSoundList->LoadSound(eSoundID, 0), v40) )
+  if ( pSoundList->pSL_Sounds[sound_id].p3DSound || (LOWORD(v40) = pSoundList->LoadSound(eSoundID, 0), v40) )
   {
     v41 = (char *)pAudioPlayer + 16 * v102;
     v42 = (int)(v41 + 20);
-    if ( AIL_set_3D_sample_file(*((int *)v41 + 5), *(void **)((char *)&pSoundList->pSounds->p3DSound + sound_id * sizeof(SoundDesc))) )
+    if ( AIL_set_3D_sample_file(*((int *)v41 + 5), *(void **)((char *)&pSoundList->pSL_Sounds->p3DSound + sound_id * sizeof(SoundDesc))) )
     {
       if ( uNumRepeats )
         v86 = uNumRepeats - 1;
       else
         v86 = 1;
       AIL_set_3D_sample_loop_count(*(int *)v42, v86);
-      if ( PartyX == -1 )
+      if ( source_x == -1 )
       {
         if ( PID_TYPE(a3) == 1 )
         {
@@ -1410,8 +1452,8 @@
         v47 = (double)pLayingItem2->vPosition.z;
         goto LABEL_101;
       }
-      pRenderVertexSoft.vWorldPosition.x = (double)PartyX;
-      v43 = (double)PartyY;
+      pRenderVertexSoft.vWorldPosition.x = (double)source_x;
+      v43 = (double)source_y;
       pRenderVertexSoft.vWorldPosition.y = v43;
       v47 = (double)pParty->sEyelevel + (double)pParty->vPosition.z;
       goto LABEL_101;
@@ -1509,28 +1551,20 @@
   field_2D0_time_left -= pEventTimer->uTimeElapsed;
   if ( field_2D0_time_left <= 0 )
   {
-  //v3 = this->b3DSoundInitialized == 0;
   field_2D0_time_left = 32;
   if ( b3DSoundInitialized )//for 3D sound
   {
     __debugbreak(); // refactor refactor
-    //v3 = this->uNum3DSamples == 0;
-    //v5 = this->uNum3DSamples < 0;
-    
-    //if (uNum3DSamples > 0)
-    //{
-    //v6 = this->p3DSamples;
     v2 = 0;
-    //while ( 1 )
     for ( v59 = 0; v59 < pAudioPlayer->uNum3DSamples; ++v59 )
     {
       v7 = PID_TYPE(this->p3DSamples[v59].field_4);
-      if ( AIL_3D_sample_status(this->p3DSamples[v59].hSample) == 2 )
+      if ( AIL_3D_sample_status(this->p3DSamples[v59].hSample) == AIL::Sample::Done )
       {
         AIL_end_3D_sample(this->p3DSamples[v59].hSample);
         pAudioPlayer->_4ABF23(&this->p3DSamples[v59]);
       }
-      if ( AIL_3D_sample_status(this->p3DSamples[v59].hSample) != 4 )
+      if ( AIL_3D_sample_status(this->p3DSamples[v59].hSample) != AIL::Sample::Playing )
         continue;
       v8 = v7 - 1;//
       if ( v8 )//> 1
@@ -1542,13 +1576,13 @@
           if ( !v10 )//3
           {
             v13 = &pActors[PID_ID(this->p3DSamples[v59].field_4)];
-            uNumRepeats = v13->vPosition.x;
-            v14 = v13->vPosition.y;
-            a1.vWorldPosition.x = (double)uNumRepeats;
-            uNumRepeats = v13->vPosition.z;
-            a1.vWorldPosition.y = (double)v14;
-            v11 = (double)uNumRepeats;
-            a1.vWorldPosition.z = v11;
+            //uNumRepeats = v13->vPosition.x;
+            //v14 = v13->vPosition.y;
+            a1.vWorldPosition.x = (double)v13->vPosition.x;
+            //uNumRepeats = v13->vPosition.z;
+            a1.vWorldPosition.y = (double)v13->vPosition.y;
+            //v11 = (double)uNumRepeats;
+            a1.vWorldPosition.z = v13->vPosition.z;
             if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
             {
               v16 = pGame->pIndoorCameraD3D->fRotationXCosine;
@@ -1896,48 +1930,104 @@
         if (!pIndoor->pDoors[source_id].uDoorID)
           continue;
 
-        source_x = pIndoor->pDoors[source_id].pXOffsets[0];
-        source_y = pIndoor->pDoors[source_id].pYOffsets[0];
-        source_z = pIndoor->pDoors[source_id].pZOffsets[0];
+        //source_x = pIndoor->pDoors[source_id].pXOffsets[0];
+        //source_y = pIndoor->pDoors[source_id].pYOffsets[0];
+        //source_z = pIndoor->pDoors[source_id].pZOffsets[0];
+        int sound_strength = GetSoundStrengthByDistanceFromParty(pIndoor->pDoors[source_id].pXOffsets[0],
+                                                                 pIndoor->pDoors[source_id].pYOffsets[0],
+                                                                 pIndoor->pDoors[source_id].pZOffsets[0]);
+        if ( sound_strength )
+        {
+          AIL_set_sample_volume(pMixerChannels[i].hSample, sound_strength);
+          AIL_set_sample_pan(pMixerChannels[i].hSample, sub_4AB66C(pIndoor->pDoors[source_id].pXOffsets[0],
+                                                                 pIndoor->pDoors[source_id].pYOffsets[0]));
+        }
+        else
+        {
+          AIL_end_sample(pMixerChannels[i].hSample);
+          FreeChannel(&pMixerChannels[i]);
+        }
       }
-      break;
+      continue;
 
       case OBJECT_Item:
       {
         assert(source_id < uNumSpriteObjects);
 
-        source_x = pSpriteObjects[source_id].vPosition.x;
-        source_y = pSpriteObjects[source_id].vPosition.y;
-        source_z = pSpriteObjects[source_id].vPosition.z;
+        //source_x = pSpriteObjects[source_id].vPosition.x;
+        //source_y = pSpriteObjects[source_id].vPosition.y;
+        //source_z = pSpriteObjects[source_id].vPosition.z;
+        int sound_strength = GetSoundStrengthByDistanceFromParty(pSpriteObjects[source_id].vPosition.x,
+                                                                 pSpriteObjects[source_id].vPosition.y,
+                                                                 pSpriteObjects[source_id].vPosition.z);
+        if ( sound_strength )
+        {
+          AIL_set_sample_volume(pMixerChannels[i].hSample, sound_strength);
+          AIL_set_sample_pan(pMixerChannels[i].hSample, sub_4AB66C(pSpriteObjects[source_id].vPosition.x,
+                                                                   pSpriteObjects[source_id].vPosition.y));
+        }
+        else
+        {
+          AIL_end_sample(pMixerChannels[i].hSample);
+          FreeChannel(&pMixerChannels[i]);
+        }
       }
-      break;
+      continue;
 
       case OBJECT_Decoration:
       {
         assert(source_id < uNumLevelDecorations);
 
-        source_x = pLevelDecorations[source_id].vPosition.x;
-        source_y = pLevelDecorations[source_id].vPosition.y;
-        source_z = pLevelDecorations[source_id].vPosition.z;
+        //source_x = pLevelDecorations[source_id].vPosition.x;
+        //source_y = pLevelDecorations[source_id].vPosition.y;
+        //source_z = pLevelDecorations[source_id].vPosition.z;
+        int sound_strength = GetSoundStrengthByDistanceFromParty(pLevelDecorations[source_id].vPosition.x,
+                                                                 pLevelDecorations[source_id].vPosition.y,
+                                                                 pLevelDecorations[source_id].vPosition.z);
+        if ( sound_strength )
+        {
+          AIL_set_sample_volume(pMixerChannels[i].hSample, sound_strength);
+          AIL_set_sample_pan(pMixerChannels[i].hSample, sub_4AB66C(pLevelDecorations[source_id].vPosition.x,
+                                                                   pLevelDecorations[source_id].vPosition.y));
+        }
+        else
+        {
+          AIL_end_sample(pMixerChannels[i].hSample);
+          FreeChannel(&pMixerChannels[i]);
+        }
       }
-      break;
+      continue;
 
       case OBJECT_Actor:
       {
         assert(source_id < uNumActors);
 
-        source_x = pActors[source_id].vPosition.x;
-        source_y = pActors[source_id].vPosition.y;
-        source_z = pActors[source_id].vPosition.z;
+        //source_x = pActors[source_id].vPosition.x;
+        //source_y = pActors[source_id].vPosition.y;
+        //source_z = pActors[source_id].vPosition.z;
+        int sound_strength = GetSoundStrengthByDistanceFromParty(pActors[source_id].vPosition.x,
+                                                                 pActors[source_id].vPosition.y,
+                                                                 pActors[source_id].vPosition.z);
+        if ( sound_strength )
+        {
+          AIL_set_sample_volume(pMixerChannels[i].hSample, sound_strength);
+          AIL_set_sample_pan(pMixerChannels[i].hSample, sub_4AB66C(pActors[source_id].vPosition.x,
+                                                                   pActors[source_id].vPosition.y));
+        }
+        else
+        {
+          AIL_end_sample(pMixerChannels[i].hSample);
+          FreeChannel(&pMixerChannels[i]);
+        }
       }
-      break;
+      continue;
 
       default:
         assert(false);
         continue;
     }
 
-    if (int sound_strength = GetSoundStrengthByDistanceFromParty(source_x, source_y, source_z))
+    /*if (int sound_strength = GetSoundStrengthByDistanceFromParty(source_x, source_y, source_z))
     {
       AIL_set_sample_volume(pMixerChannels[i].hSample, sound_strength);
       AIL_set_sample_pan(pMixerChannels[i].hSample, sub_4AB66C(source_x, source_y));
@@ -1946,14 +2036,13 @@
     {
       AIL_end_sample(pMixerChannels[i].hSample);
       FreeChannel(&pMixerChannels[i]);
-    }
+    } */
   }
 
-  if (pCurrentScreen != SCREEN_GAME)
+  if (pCurrentScreen != SCREEN_GAME) //отключение звука декораций при переключенииокна игры
   {
-    MixerChannel* channel = &pMixerChannels[4];
-    if (AIL_sample_status(channel->hSample) == AIL::Sample::Playing)
-      AIL_end_sample(channel->hSample);
+    if (AIL_sample_status(pMixerChannels[4].hSample) == AIL::Sample::Playing)
+      AIL_end_sample(pMixerChannels[4].hSample);
     return;
   }
   if (!_6807E0_num_decorations_with_sounds_6807B8)
@@ -1963,8 +2052,6 @@
       //v59 = 0;
   for (uint i = 0; i < _6807E0_num_decorations_with_sounds_6807B8; ++i)
   {
-      //while ( 1 )
-      //{
         LODWORD(v56) = 1;
         //v43 = _6807B8_level_decorations_ids[v59];
         //v44 = &pLevelDecorations[_6807B8_level_decorations_ids[v59]];
@@ -2107,7 +2194,7 @@
       for ( uint i = 0; i < uNum3DSamples; ++i )
       {
         if ( (uStartChannel == -1 || i < uStartChannel || i > uEndChannel)
-            && p3DSamples[i].field_8 && pSoundList->pSounds[p3DSamples[i].field_8].eType != SOUND_DESC_SYSTEM)
+            && p3DSamples[i].field_8 && pSoundList->pSL_Sounds[p3DSamples[i].field_8].eType != SOUND_DESC_SYSTEM)
         {
           AIL_end_3D_sample(p3DSamples[i].hSample);
           _4ABF23(&p3DSamples[i]);
@@ -2120,7 +2207,7 @@
       for ( int i = 0; i < uMixerChannels; ++i )
       {
         if ( (uStartChannel == -1 || i < uStartChannel || i > uEndChannel)
-          && pSoundList->pSounds[pMixerChannels[i].uSourceTrackIdx].eType != SOUND_DESC_SYSTEM)//все, кроме системных звуков, отключаются
+          && pSoundList->pSL_Sounds[pMixerChannels[i].uSourceTrackIdx].eType != SOUND_DESC_SYSTEM)//все, кроме системных звуков, отключаются
         {
           AIL_end_sample(pMixerChannels[i].hSample);
           FreeChannel(&pMixerChannels[i]);
@@ -2147,7 +2234,7 @@
     return;
   }
 
-  ReadFile(hAudioSnd, &uNumSoundHeaders, 4u, &NumberOfBytesRead, 0);
+  ReadFile(hAudioSnd, &uNumSoundHeaders, 4, &NumberOfBytesRead, 0);
   pSoundHeaders = nullptr;
   pSoundHeaders = (SoundHeader *)malloc(52 * uNumSoundHeaders + 2);
   ReadFile(hAudioSnd, pSoundHeaders, 52 * uNumSoundHeaders, &NumberOfBytesRead, 0);
@@ -2439,14 +2526,14 @@
   int num_playing_channels; // [sp+4Ch] [bp-8h]@5
   //int v16; // [sp+50h] [bp-4h]@5
 
-  if (!pSoundList->pSounds)
+  if (!pSoundList->pSL_Sounds)
     return;
  
     //v4 = &pSoundList->pSounds[pChannel->uSourceTrackIdx];
-    if ( pSoundList->pSounds[pChannel->uSourceTrackIdx].eType == SOUND_DESC_SWAP)
+    if ( pSoundList->pSL_Sounds[pChannel->uSourceTrackIdx].eType == SOUND_DESC_SWAP)
     {
-      if ( pSoundList->pSounds[pChannel->uSourceTrackIdx].pSoundData[0] && 
-          !(pSoundList->pSounds[pChannel->uSourceTrackIdx].uFlags & SOUND_DESC_SYSTEM) )
+      if ( pSoundList->pSL_Sounds[pChannel->uSourceTrackIdx].pSoundData[0] && 
+          !(pSoundList->pSL_Sounds[pChannel->uSourceTrackIdx].uFlags & SOUND_DESC_SYSTEM) )
       {
         num_playing_channels = 0;
         num_same_sound_on_channels = 0;
@@ -2494,12 +2581,12 @@
   int v14; // [sp+4Ch] [bp-8h]@5
   int v15; // [sp+50h] [bp-4h]@5
 
-  if ( pSoundList->pSounds )
+  if ( pSoundList->pSL_Sounds )
   {
     //v4 = &pSoundList->pSounds[a2->field_8];
-    if ( pSoundList->pSounds[a2->field_8].eType == SOUND_DESC_SWAP)
+    if ( pSoundList->pSL_Sounds[a2->field_8].eType == SOUND_DESC_SWAP)
     {
-      if ( pSoundList->pSounds[a2->field_8].p3DSound && !(pSoundList->pSounds[a2->field_8].uFlags & SOUND_DESC_SYSTEM) )
+      if ( pSoundList->pSL_Sounds[a2->field_8].p3DSound && !(pSoundList->pSL_Sounds[a2->field_8].uFlags & SOUND_DESC_SYSTEM) )
       {
         v5 = this->uNum3DSamples == 0;
         v6 = this->uNum3DSamples < 0;
@@ -2755,7 +2842,7 @@
     pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize = pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize;
     if ( pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize )
     {
-      ReadFile(pAudioPlayer->hAudioSnd, (char *)pOutBuff + 4, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize, &NumberOfBytesRead, 0);
+      ReadFile(pAudioPlayer->hAudioSnd, pOutBuff->pData, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize + 7, &NumberOfBytesRead, 0);// Ritor1: include +7 for pSounds[20]
     }
     else
     {
@@ -2766,12 +2853,12 @@
   {
     uID = (unsigned int)malloc(pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize);
     ReadFile(pAudioPlayer->hAudioSnd, (LPVOID)uID, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize, &NumberOfBytesRead, 0);
-    zlib::MemUnzip((char *)pOutBuff + 4, &pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize, (const void *)uID, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize);
+    zlib::MemUnzip(pOutBuff->pData, &pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize, (const void *)uID, pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uCompressedSize);
     free((void *)uID);
   }
   if ( pOutBuff )
   {
-    *(int *)pOutBuff = pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize;
+    pOutBuff->uDataSize = pAudioPlayer->pSoundHeaders[uFindSound_BinSearch_ResultID].uDecompressedSize;
     uLastLoadedSoundID = 0;
     if ( pSounds[0].pSoundData )
     {
--- a/AudioPlayer.h	Mon Dec 23 15:17:50 2013 +0100
+++ b/AudioPlayer.h	Mon Dec 23 15:18:16 2013 +0100
@@ -165,7 +165,7 @@
   void SetMusicVolume(int vol);
   void SetMasterVolume(float fVolume);
   void _4AA258(int a2);
-  void PlaySound(SoundID eSoundID, signed int a3, unsigned int uNumRepeats, signed int a5, signed int a6, int a7, unsigned int uVolume, int sPlaybackRate);
+  void PlaySound(SoundID eSoundID, signed int a3, unsigned int uNumRepeats, signed int a5, signed int a6, int a7, float uVolume, int sPlaybackRate);
   void UpdateSounds();
   void StopChannels(int uStartChannel, int uEndChannel);
   void LoadAudioSnd();
@@ -281,7 +281,7 @@
 struct SoundList
 {
   inline SoundList():
-    sNumSounds(0), pSounds(nullptr), uTotalLoadedSoundSize(0)
+    sNumSounds(0), pSL_Sounds(nullptr), uTotalLoadedSoundSize(0)
   {}
 
   void Initialize();
@@ -295,7 +295,7 @@
   int FromFileTxt(const char *Args);
 
   signed int sNumSounds;
-  SoundDesc *pSounds;
+  SoundDesc *pSL_Sounds;
   unsigned int uTotalLoadedSoundSize;
 };
 #pragma pack(pop)
--- a/Game.cpp	Mon Dec 23 15:17:50 2013 +0100
+++ b/Game.cpp	Mon Dec 23 15:18:16 2013 +0100
@@ -1888,30 +1888,30 @@
         case UIMSG_ToggleTint:
           pRenderer->bTinting = pRenderer->bTinting == 0;
           continue;
-        case UIMSG_ChangeMusicVolume:
-          if ( uMessageParam == 4 )
+        case UIMSG_ChangeMusicVolume:  //громкость музыки
+          if ( uMessageParam == 4 )//кнопка понижения
           {
             --uMusicVolimeMultiplier;
             if ( (char)uMusicVolimeMultiplier < 1 )
               uMusicVolimeMultiplier = 0;
-            GUIWindow::Create(243, 0xD8u, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderLeft, (char *)1);
+            GUIWindow::Create(243, 216, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderLeft, (char *)1);
             if ( uMusicVolimeMultiplier )
-              pAudioPlayer->PlaySound(SOUND_Bell, -1, 0, -1, 0, 0, pSoundVolumeLevels[(char)uMusicVolimeMultiplier] * 64.0f, 0);
-            pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[(char)uMusicVolimeMultiplier] * 64.0f);
+              pAudioPlayer->PlaySound(SOUND_Bell, -1, 0, -1, 0, 0, pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f, 0);
+            pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
             continue;
           }
-          if ( uMessageParam == 5 )
+          if ( uMessageParam == 5 )//кнопка повышения
           {
             ++uMusicVolimeMultiplier;
             if ( (char)uMusicVolimeMultiplier > 9 )
               uMusicVolimeMultiplier = 9;
-            GUIWindow::Create(435, 0xD8u, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderRight, (char *)1);
+            GUIWindow::Create(435, 216, 0, 0, WINDOW_PressedButton2, (int)pBtn_SliderRight, (char *)1);
             if ( uMusicVolimeMultiplier )
-              pAudioPlayer->PlaySound(SOUND_Bell, -1, 0, -1, 0, 0, pSoundVolumeLevels[(char)uMusicVolimeMultiplier] * 64.0f, 0);
-            pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[(char)uMusicVolimeMultiplier] * 64.0f);
+              pAudioPlayer->PlaySound(SOUND_Bell, -1, 0, -1, 0, 0, pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f, 0);
+            pAudioPlayer->SetMusicVolume(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0f);
             continue;
           }
-          uMusicVolimeMultiplier = (pMouse->GetCursorPos(&v202)->x - 263) / 17;
+          uMusicVolimeMultiplier = (pMouse->GetCursorPos(&v202)->x - 263) / 17;//для задания громкости мышкой
           if ( (char)uMusicVolimeMultiplier > 9 )
             uMusicVolimeMultiplier = 9;
           if ( uMusicVolimeMultiplier )
@@ -4515,12 +4515,14 @@
         case UIMSG_PlayerCreationRemoveUpSkill:
           v4 = pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem;
           pGUIWindow_CurrentMenu->pCurrentPosActiveItem = v4 % 7 + pGUIWindow_CurrentMenu->pStartingPosActiveItem + 7 * pParam;
-          pParty->pPlayers[pParam].pActiveSkills[pPlayer[pParam].GetSkillIdxByOrder(2)] = 0;
+          if ( pPlayer[pParam].GetSkillIdxByOrder(2) != 37 )//37 - None(Нет)
+            pParty->pPlayers[pParam].pActiveSkills[pPlayer[pParam].GetSkillIdxByOrder(2)] = 0;
           break;
         case UIMSG_PlayerCreationRemoveDownSkill:
           v4 = pGUIWindow_CurrentMenu->pCurrentPosActiveItem - pGUIWindow_CurrentMenu->pStartingPosActiveItem;
           pGUIWindow_CurrentMenu->pCurrentPosActiveItem = v4 % 7 + pGUIWindow_CurrentMenu->pStartingPosActiveItem + 7 * pParam;
-          pParty->pPlayers[pParam].pActiveSkills[pPlayer[pParam].GetSkillIdxByOrder(3)] = 0;
+          if ( pPlayer[pParam].GetSkillIdxByOrder(3) != 37 )//37 - None(Нет)
+            pParty->pPlayers[pParam].pActiveSkills[pPlayer[pParam].GetSkillIdxByOrder(3)] = 0;
           break;
         case UIMSG_PlayerCreationChangeName:
           pAudioPlayer->PlaySound((SoundID)24, 0, 0, -1, 0, 0, 0, 0);
--- a/Outdoor.cpp	Mon Dec 23 15:17:50 2013 +0100
+++ b/Outdoor.cpp	Mon Dec 23 15:18:16 2013 +0100
@@ -4551,8 +4551,8 @@
           {
             for ( uint i = 1; i <= 4; ++i )
             {
-              v110 = pPlayers[i]->GetMaxHealth();
-              pPlayers[i]->ReceiveDamage((signed int)((pParty->uFallStartY - pZ) * (unsigned __int64)(signed __int64)((double)v110 * 0.1)) / 256,
+              //v110 = pPlayers[i]->GetMaxHealth();
+              pPlayers[i]->ReceiveDamage((signed int)((pParty->uFallStartY - pZ) * (unsigned __int64)(signed __int64)((double)pPlayers[i]->GetMaxHealth() * 0.1)) / 256,
                 DMGT_PHISYCAL);
               v110 = 20 - pPlayers[i]->GetParameterBonus(pPlayers[i]->GetActualEndurance());
               pPlayers[i]->SetRecoveryTime((signed __int64)((double)v110 * flt_6BE3A4_debug_recmod1 * 2.133333333333333));
--- a/Player.cpp	Mon Dec 23 15:17:50 2013 +0100
+++ b/Player.cpp	Mon Dec 23 15:18:16 2013 +0100
@@ -579,11 +579,11 @@
       {
         for (int i = 0; i < pSoundList->sNumSounds; i++)
         {
-          if (pSoundList->pSounds[i].uSoundID == pickedSoundID)
+          if (pSoundList->pSL_Sounds[i].uSoundID == pickedSoundID)
             pSoundID = i;
         }
       }
-      if ( pSoundList->pSounds[pSoundID].pSoundData[0] )
+      if ( pSoundList->pSL_Sounds[pSoundID].pSoundData[0] )
         expressionDuration = (sLastTrackLengthMS << 7) / 1000;
     }
     PlayEmotion(expression, expressionDuration);
--- a/Render.cpp	Mon Dec 23 15:17:50 2013 +0100
+++ b/Render.cpp	Mon Dec 23 15:18:16 2013 +0100
@@ -8681,18 +8681,18 @@
 
   }*/
 
-  for (uint i = pRenderer->uNumBillboardsToDraw - 1; i != (uint)-1; --i)
-  {
-    RenderBillboardD3D* p = &pRenderer->pBillboardRenderListD3D[i];
-
-    if (p->uOpacity != RenderBillboardD3D::NoBlend)
-      SetBillboardBlendOptions(p->uOpacity);
+  for (int i = pRenderer->uNumBillboardsToDraw - 1; i >= 0; --i)
+  {
+    if((int)pRenderer->pBillboardRenderListD3D[i].pTexture == 0xcdcdcdcd)
+      __debugbreak();//Ritor1: error
+    if (pRenderer->pBillboardRenderListD3D[i].uOpacity != RenderBillboardD3D::NoBlend)
+      SetBillboardBlendOptions(pRenderer->pBillboardRenderListD3D[i].uOpacity);
     
-	//if((int)p->pTexture!=0xcdcdcdcd)
-    pRenderer->pRenderD3D->pDevice->SetTexture(0, p->pTexture);
+
+    pRenderer->pRenderD3D->pDevice->SetTexture(0, pRenderer->pBillboardRenderListD3D[i].pTexture);
     ErrD3D(pRenderer->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
                                                          D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-                                                         p->pQuads, p->uNumVertices,
+                                                         pRenderer->pBillboardRenderListD3D[i].pQuads, pRenderer->pBillboardRenderListD3D[i].uNumVertices,
                                                          D3DDP_DONOTLIGHT | D3DDP_DONOTUPDATEEXTENTS));
   }
 
--- a/SaveLoad.cpp	Mon Dec 23 15:17:50 2013 +0100
+++ b/SaveLoad.cpp	Mon Dec 23 15:18:16 2013 +0100
@@ -76,14 +76,14 @@
     for (uint i = 0; i < 4; ++i)
     {
       for (uint j = 0; j < pSoundList->sNumSounds; ++j)
-        if (pSoundList->pSounds[j].uSoundID == 2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[i].uVoiceID) + 4998)
+        if (pSoundList->pSL_Sounds[j].uSoundID == 2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[i].uVoiceID) + 4998)
         {
           pSoundList->UnloadSound(j, 1);
           break;
         }
 
         for (uint j = 0; j < pSoundList->sNumSounds; ++j)
-        if (pSoundList->pSounds[j].uSoundID == 2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[i].uVoiceID) + 4999)
+        if (pSoundList->pSL_Sounds[j].uSoundID == 2 * (SoundSetAction[24][0] + 50 * pParty->pPlayers[i].uVoiceID) + 4999)
         {
           pSoundList->UnloadSound(j, 1);
           break;
--- a/TurnEngine.h	Mon Dec 23 15:17:50 2013 +0100
+++ b/TurnEngine.h	Mon Dec 23 15:18:16 2013 +0100
@@ -75,7 +75,7 @@
 
 
   int turns_count;
-  int turn_stage;
+  int turn_stage; //if = 2 - action
   int ai_turn_timer;
   int uActorQueueSize; //c
   int turn_initiative;
--- a/UI/UICharacter.cpp	Mon Dec 23 15:17:50 2013 +0100
+++ b/UI/UICharacter.cpp	Mon Dec 23 15:18:16 2013 +0100
@@ -1545,7 +1545,7 @@
 {
   Texture *pTexture; // esi@6
   int v13; // eax@13
-  int v15; // eax@13
+  //int v15; // eax@13
   unsigned int v17; // edi@15
   unsigned int uCellX; // [sp+30h] [bp-8h]@5
   unsigned int uCellY; // [sp+34h] [bp-4h]@5
@@ -1567,12 +1567,13 @@
       pTexture->uTextureWidth = 14;
     if ( (pTexture->uTextureWidth - 14) / 32 == 0 && pTexture->uTextureWidth < 32)
       uCellX += (32 - pTexture->uTextureWidth) / 2;
-    v13 = pTexture->uTextureWidth - 14;
-    LOBYTE(v13) = v13 & 0xE0;
-    v15 = v13 + 32;
+    //v13 = pTexture->uTextureWidth - 14;
+    //LOBYTE(v13) = v13 & 0xE0;
+    //v15 = v13 + 32;
     if (pTexture->uTextureHeight < 14 )
       pTexture->uTextureHeight = 14;
-    v17 = uCellX + ((v15 - pTexture->uTextureWidth) >> 1) + pSRZBufferLineOffsets[uCellY + (( (int)((pTexture->uTextureHeight - 14) & 0xFFFFFFE0) - pTexture->uTextureHeight + 32) >> 1)];   //added typecast. without it the value in the brackets got cat to unsigned which messed stuff up
+    v17 = uCellX + (( (int)((pTexture->uTextureWidth - 14) & 0xE0) + 32 - pTexture->uTextureWidth) / 2)
+       + pSRZBufferLineOffsets[uCellY + (( (int)((pTexture->uTextureHeight - 14) & 0xFFFFFFE0) - pTexture->uTextureHeight + 32) / 2)];   //added typecast. without it the value in the brackets got cat to unsigned which messed stuff up
     if (player->pInventoryItemList[player->pInventoryMatrix[i] - 1].uAttributes & ITEM_ENCHANT_ANIMATION)
     {
       Texture *loadedTextureptr = nullptr;
--- a/mm7_4.cpp	Mon Dec 23 15:17:50 2013 +0100
+++ b/mm7_4.cpp	Mon Dec 23 15:18:16 2013 +0100
@@ -252,7 +252,7 @@
       }
       else
       {
-        v2 = (char *)&pSoundList->pSounds->uSoundID;
+        v2 = (char *)&pSoundList->pSL_Sounds->uSoundID;
         while ( *(int *)v2 != 2 * (SoundSetAction[24][0] + 50 * v0->uVoiceID) + 4998 )
         {
           ++v1;
@@ -271,7 +271,7 @@
       }
       else
       {
-        v5 = (char *)&pSoundList->pSounds->uSoundID;
+        v5 = (char *)&pSoundList->pSL_Sounds->uSoundID;
         while ( *(int *)v5 != 2 * (SoundSetAction[24][0] + 50 * v0->uVoiceID) + 4999 )
         {
           ++v4;
--- a/mm7_5.cpp	Mon Dec 23 15:17:50 2013 +0100
+++ b/mm7_5.cpp	Mon Dec 23 15:18:16 2013 +0100
@@ -342,9 +342,9 @@
   int v6; // eax@3
   //Actor *v7; // esi@4
   //Actor *v8; // edi@4
-  char v9; // zf@5
+  //char v9; // zf@5
   __int64 v10; // qax@8
-  signed __int16 v11; // cx@9
+  //signed __int16 v11; // cx@9
   signed int v12; // ecx@20
   int v13; // ecx@22
   int v14; // edi@30
@@ -364,19 +364,19 @@
     v6 = pActors[actor_id].IsNotAlive();
     if ( !v6 )
     {
-      v9 = pActors[actor_id].uAIState == 7;
+      //v9 = pActors[actor_id].uAIState == 7;
       pActors[actor_id].uLastCharacterIDToHit = v17;
-      if ( v9 )
-        BYTE2(pActors[actor_id].uAttributes) |= 2u;
-      v6 = pActors[PID_ID(v17)]._4273BB_DoesHitOtherActor(&pActors[actor_id], v4, 0);
-      if ( v6 )
+      if ( pActors[actor_id].uAIState == Fleeing )
+        BYTE2(pActors[actor_id].uAttributes) |= 2;
+      //v6 = pActors[PID_ID(v17)]._4273BB_DoesHitOtherActor(&pActors[actor_id], v4, 0);
+      if ( pActors[PID_ID(v17)]._4273BB_DoesHitOtherActor(&pActors[actor_id], v4, 0) )
       {
         v10 = (unsigned int)pActors[PID_ID(v17)]._43B3E0_CalcDamage(a4);
         if ( (signed __int64)pActors[PID_ID(v17)].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime > 0 )
         {
-          v11 = pActors[PID_ID(v17)].pActorBuffs[ACTOR_BUFF_SHRINK].uPower;
-          if ( v11 )
-            v10 = (signed int)v10 / (unsigned __int16)v11;
+          //v11 = pActors[PID_ID(v17)].pActorBuffs[ACTOR_BUFF_SHRINK].uPower;
+          if ( pActors[PID_ID(v17)].pActorBuffs[ACTOR_BUFF_SHRINK].uPower )
+            v10 = (signed int)v10 / (unsigned __int16)pActors[PID_ID(v17)].pActorBuffs[ACTOR_BUFF_SHRINK].uPower;
         }
         if ( SHIDWORD(pActors[actor_id].pActorBuffs[ACTOR_BUFF_STONED].uExpireTime) >= SHIDWORD(v10)
           && (SHIDWORD(pActors[actor_id].pActorBuffs[ACTOR_BUFF_STONED].uExpireTime) > SHIDWORD(v10)
@@ -447,18 +447,15 @@
   }
 }
 
-
 //----- (0043F515) --------------------------------------------------------
 void FindBillboardsLightLevels_BLV()
 {
   for (uint i = 0; i < uNumBillboardsToDraw; ++i)
   {
-    RenderBillboard* p = &pBillboardRenderList[i];
-
-    if (p->field_1E & 2 || uCurrentlyLoadedLevelType == LEVEL_Indoor && !p->uIndoorSectorID)
-      p->dimming_level = 0;
+    if (pBillboardRenderList[i].field_1E & 2 || uCurrentlyLoadedLevelType == LEVEL_Indoor && !pBillboardRenderList[i].uIndoorSectorID)
+      pBillboardRenderList[i].dimming_level = 0;
     else
-      p->dimming_level = _43F55F_get_billboard_light_level(p, -1);
+      pBillboardRenderList[i].dimming_level = _43F55F_get_billboard_light_level(&pBillboardRenderList[i], -1);
   }
 }
 
@@ -468,9 +465,7 @@
   signed int v3; // ecx@2
 
   if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
-  {
     v3 = pIndoor->pSectors[a1->uIndoorSectorID].uMinAmbientLightLevel;
-  }
   else
   {
     if ( uBaseLightLevel == -1 )
@@ -759,7 +754,7 @@
       obj2_x = pParty->vPosition.x;
       obj2_z = pParty->sEyelevel + pParty->vPosition.z;
       obj2_y = pParty->vPosition.y;
-	  obj2_sector = pIndoor->GetSector(obj2_x, obj2_y, obj2_z);
+	  obj2_sector = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->sEyelevel + pParty->vPosition.z);
       break;
 	case OBJECT_Actor:
       obj2_y = pActors[v12].vPosition.y;
@@ -885,15 +880,10 @@
 		v58 = fixpoint_div(v38,v59);
 
 		if( v58 < 0 )
-		{
-			continue;
-		}
+          continue;
 
-		if(!sub_4075DB(
-				obj1_x + ((fixpoint_mul(v49,v58) + 32768) >> 16),
-				obj1_y + ((fixpoint_mul(v48,v58) + 32768) >> 16),
-				obj1_z + ((fixpoint_mul(v47,v58) + 32768) >> 16),
-				v29) )
+		if(!sub_4075DB(obj1_x + ((fixpoint_mul(v49,v58) + 32768) >> 16), obj1_y + ((fixpoint_mul(v48,v58) + 32768) >> 16),
+				obj1_z + ((fixpoint_mul(v47,v58) + 32768) >> 16), v29) )
 		{
 			continue;
 		}
@@ -906,9 +896,7 @@
 
 		//no more portals, quit
 		if ( next_sector == current_sector )
-		{
-			break;
-		}
+          break;
 
 		++sectors_visited;
 		current_sector = next_sector;
@@ -937,28 +925,11 @@
 }
 
 //----- (004075DB) --------------------------------------------------------
-bool __fastcall sub_4075DB(int x, int y, int z, BLVFace *a4)
+bool __fastcall sub_4075DB(int x, int y, int z, BLVFace *face)
 {
-  unsigned int v5; // esi@1
-  char v7; // zf@2
   int v8; // edi@2
-  Vec3_short_ *v9; // ecx@3
-  int v10; // edx@4
-  Vec3_short_ *v12; // ecx@8
-  int v13; // edx@9
-  Vec3_short_ *v15; // ecx@12
-  int v16; // edx@13
-  bool v18; // esi@14
-  int v19; // ecx@14
-  int v20; // ecx@16
-  int v21; // edx@16
-  int v22; // eax@17
-  signed int v23; // ebx@18
-  int v24; // esi@20
   signed int v25; // eax@22
-  signed __int64 v26; // qtt@22
   bool result; // eax@25
-  int v29; // [sp+10h] [bp-Ch]@14
   signed int a3a; // [sp+24h] [bp+8h]@14
   int a4a; // [sp+28h] [bp+Ch]@2
 
@@ -967,44 +938,42 @@
 
   //__debugbreak();
 
-  v5 = a4->uAttributes;
-  v9 = pIndoor->pVertices;
-  if ( v5 & FACE_XY_PLANE )
+  if ( face->uAttributes & FACE_XY_PLANE )
   {
     a4a = x;
     v8 = y;
-    for(int i = 0; i < a4->uNumVertices; i++)
+    for(int i = 0; i < face->uNumVertices; i++)
 	{
-        dword_4F5D98_xs[i] = v9[a4->pVertexIDs[i]].x;
-        dword_4F5CC8_ys[i] = v9[a4->pVertexIDs[i]].y;
+        dword_4F5D98_xs[i] = pIndoor->pVertices[face->pVertexIDs[i]].x;
+        dword_4F5CC8_ys[i] = pIndoor->pVertices[face->pVertexIDs[i]].y;
 	}
   }
   else
   {
     v8 = z;
-    if ( v5 & FACE_XZ_PLANE )
+    if ( face->uAttributes & FACE_XZ_PLANE )
     {
       a4a = x;
-      for(int i = 0; i < a4->uNumVertices; i++)
+      for(int i = 0; i < face->uNumVertices; i++)
 	  {
-		dword_4F5D98_xs[i] = v9[a4->pVertexIDs[i]].x;
-		dword_4F5CC8_ys[i] = v9[a4->pVertexIDs[i]].z;
+		dword_4F5D98_xs[i] = pIndoor->pVertices[face->pVertexIDs[i]].x;
+		dword_4F5CC8_ys[i] = pIndoor->pVertices[face->pVertexIDs[i]].z;
 	  }
     }
     else
     {
       a4a = y;
-      for(int i = 0; i < a4->uNumVertices; i++)
+      for(int i = 0; i < face->uNumVertices; i++)
 	  {
-		dword_4F5D98_xs[i] = v9[a4->pVertexIDs[i]].y;
-		dword_4F5CC8_ys[i] = v9[a4->pVertexIDs[i]].z;
+		dword_4F5D98_xs[i] = pIndoor->pVertices[face->pVertexIDs[i]].y;
+		dword_4F5CC8_ys[i] = pIndoor->pVertices[face->pVertexIDs[i]].z;
 	  }
     }
   }
   a3a = 0;
-  dword_4F5D98_xs[a4->uNumVertices] = dword_4F5D98_xs[0];
-  dword_4F5CC8_ys[a4->uNumVertices] = dword_4F5CC8_ys[0];
-  for(int i = 0; i < a4->uNumVertices && a3a < 2; i++)
+  dword_4F5D98_xs[face->uNumVertices] = dword_4F5D98_xs[0];
+  dword_4F5CC8_ys[face->uNumVertices] = dword_4F5CC8_ys[0];
+  for(int i = 0; i < face->uNumVertices && a3a < 2; i++)
   {
     if ( dword_4F5CC8_ys[i] >= v8 ^ (dword_4F5CC8_ys[i + 1] >= v8) )
     {
@@ -1019,7 +988,7 @@
 		  else
 		  {
 			v25 = fixpoint_div(dword_4F5D98_xs[i + 1] - dword_4F5D98_xs[i], dword_4F5CC8_ys[i + 1] - dword_4F5CC8_ys[i]);
-			if( dword_4F5D98_xs[i] + (fixpoint_mul(v25, (v8 - dword_4F5CC8_ys[i]) << 16) + 32768 >> 16) >= a4a)
+			if( dword_4F5D98_xs[i] + (fixpoint_mul(v25, (v8 - dword_4F5CC8_ys[i]) << 16) + 0x8000 >> 16) >= a4a)
 				++a3a;
 		  }
       }
@@ -1032,75 +1001,51 @@
 }
 
 //----- (004077F1) --------------------------------------------------------
-bool __fastcall sub_4077F1(int a1, int a2, int a3, ODMFace *a4, BSPVertexBuffer *a5)
+bool __fastcall sub_4077F1(int a1, int a2, int a3, ODMFace *face, BSPVertexBuffer *a5)
 {
-  //ODMFace *v5; // eax@1
-  Vec3_int_ *v9;
-  unsigned int v5; // esi@1
-  signed int v7; // edi@1
-  //char v8; // zf@2
-  //unsigned __int16 *v9; // edx@3
-  int v10; // ecx@4
-  unsigned __int16 *v11; // edx@8
-  int v12; // ecx@9
-  int v13; // edx@12
-  int v14; // ecx@13
-  int v15; // esi@14
-  bool v16; // edi@14
-  int v17; // ecx@16
-  int v18; // edx@16
-  int v19; // eax@17
-  signed int v20; // ebx@18
-  int v21; // edi@20
-  signed int v22; // eax@22
-  signed __int64 v23; // qtt@22
-  //bool result; // eax@25
-  //int v25; // [sp+14h] [bp-8h]@14
   int a4a; // [sp+28h] [bp+Ch]@2
   signed int a5a; // [sp+2Ch] [bp+10h]@14
 
   std::array<int, 52> dword_4F5B24_ys; // idb
   std::array<int, 52> dword_4F5BF4_xs; // idb
-  
+
   //__debugbreak();	//срабатывает при нападении стрекозавров с огнём
 
-  v5 = a4->uAttributes;
-  v9 = a5->pVertices;
-  if ( v5 & FACE_XY_PLANE )
+  if ( face->uAttributes & FACE_XY_PLANE )
   {
     a4a = a1;
     a3 = a2;
-    for(int i = 0; i < a4->uNumVertices; i++)
+    for(int i = 0; i < face->uNumVertices; i++)
 	{
-        dword_4F5BF4_xs[i+1] = v9[a4->pVertexIDs[i]].x;
-        dword_4F5B24_ys[i+1] = v9[a4->pVertexIDs[i]].y;
+        dword_4F5BF4_xs[i+1] = a5->pVertices[face->pVertexIDs[i]].x;
+        dword_4F5B24_ys[i+1] = a5->pVertices[face->pVertexIDs[i]].y;
 	}
   }
   else
   {
-    if ( v5 & FACE_XY_PLANE )
+    if ( face->uAttributes & FACE_XY_PLANE )
     {
       a4a = a1;
-      for(int i = 0; i < a4->uNumVertices; i++)
+      for(int i = 0; i < face->uNumVertices; i++)
 	  {
-		dword_4F5BF4_xs[i+1] = v9[a4->pVertexIDs[i]].x;
-		dword_4F5B24_ys[i+1] = v9[a4->pVertexIDs[i]].z;
+		dword_4F5BF4_xs[i+1] = a5->pVertices[face->pVertexIDs[i]].x;
+		dword_4F5B24_ys[i+1] = a5->pVertices[face->pVertexIDs[i]].z;
 	  }
     }
     else
     {
       a4a = a2;
-      for(int i = 0; i < a4->uNumVertices; i++)
+      for(int i = 0; i < face->uNumVertices; i++)
 	  {
-		dword_4F5BF4_xs[i+1] = v9[a4->pVertexIDs[i]].y;
-		dword_4F5B24_ys[i+1] = v9[a4->pVertexIDs[i]].z;
+		dword_4F5BF4_xs[i+1] = a5->pVertices[face->pVertexIDs[i]].y;
+		dword_4F5B24_ys[i+1] = a5->pVertices[face->pVertexIDs[i]].z;
 	  }
     }
   }
   a5a = 0;
-  dword_4F5BF4_xs[a4->uNumVertices + 1] = dword_4F5BF4_xs[1];
-  dword_4F5B24_ys[a4->uNumVertices + 1] = dword_4F5B24_ys[1];
-  for(int i = 0; i < a4->uNumVertices; i++)
+  dword_4F5BF4_xs[face->uNumVertices + 1] = dword_4F5BF4_xs[1];
+  dword_4F5B24_ys[face->uNumVertices + 1] = dword_4F5B24_ys[1];
+  for(int i = 0; i < face->uNumVertices; i++)
   {
     if ( a5a >= 2 )
       break;
@@ -1112,11 +1057,11 @@
             ++a5a;
           else
           {
-              v23 = (__int64)(dword_4F5BF4_xs[i + 2] - dword_4F5BF4_xs[i + 1]) << 16;
+              //v23 = (__int64)(dword_4F5BF4_xs[i + 2] - dword_4F5BF4_xs[i + 1]) << 16;
               __int64 _a = dword_4F5B24_ys[i + 2] - dword_4F5B24_ys[i + 1];
               __int64 _b = (__int64)(a3 - dword_4F5B24_ys[i + 1]) << 16;
 
-              if (dword_4F5BF4_xs[i + 1] + ((((v23 / _a * _b) >> 16) + 32768) >> 16) >= a4a)
+              if (dword_4F5BF4_xs[i + 1] + ((((((__int64)(dword_4F5BF4_xs[i + 2] - dword_4F5BF4_xs[i + 1]) << 16) / _a * _b) >> 16) + 0x8000) >> 16) >= a4a)
                 ++a5a;
           }
 	  }
@@ -1132,20 +1077,14 @@
 //----- (004088E9) --------------------------------------------------------
 int __fastcall sub_4088E9(int x1, int y1, int x2, int y2, int x3, int y3)
 {
-  int v8; // eax@1
   signed int result; // eax@1
-  int v11; // [sp+18h] [bp+8h]@1
 
-  v11 = abs(x2 - x1);
-  v8 = abs(y2 - y1);
-  result = integer_sqrt(v11 * v11 + v8 * v8);
+  result = integer_sqrt(abs(x2 - x1) * abs(x2 - x1) + abs(y2 - y1) * abs(y2 - y1));
   if ( result )
     result = abs(((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / result);
   return result;
 }
 
-
-
 //----- (0040F82D) --------------------------------------------------------
 void __fastcall ZBuffer_Fill(int *pZBuffer, int uTextureId, int iZValue)
 {
@@ -1153,95 +1092,69 @@
   ZBuffer_DoFill(pZBuffer, pIcons_LOD->GetTexture(uTextureId), iZValue);
 }
 
-
-
 //----- (0040F89C) --------------------------------------------------------
 void __fastcall ZBuffer_DoFill(int *pZBuffer, Texture *pTex, int uZValue)
-{
+{//срабатывает при продаже в магазине
   void *v3; // eax@3
-  void *v4; // esi@5
-  int *v5; // edi@5
-  int v6; // eax@5
+  //void *v4; // esi@5
+  //int *v5; // edi@5
+  //int v6; // eax@5
   int v7; // ecx@6
-  Texture *v8; // [sp+Ch] [bp-14h]@1
-  int *v9; // [sp+10h] [bp-10h]@1
-  int v10; // [sp+14h] [bp-Ch]@1
   int v11; // [sp+18h] [bp-8h]@1
-  void *v12; // [sp+1Ch] [bp-4h]@5
+  //void *v12; // [sp+1Ch] [bp-4h]@5
 
-  v10 = pTex->uTextureWidth;
-  v8 = pTex;
-  v9 = pZBuffer;
-  v11 = pTex->uTextureHeight;
   if ( pIcons_LOD->dword_011BA4 && pTex->uDecompressedSize )
     v3 = pTex->UnzipPalette();
   else
     v3 = pTex->pLevelOfDetail0_prolly_alpha_mask;
-  v12 = v3;
-  v4 = v3;
-  v5 = v9;
-  v6 = 0;
-  do
+  //v12 = v3;
+  //v4 = v3;
+  //v5 = pZBuffer;
+  //v6 = 0;
+  for ( uint i = 0; i < pTex->uTextureHeight; i++ )
   {
-    v7 = v10;
-    do
+    for ( uint j = 0; j < pTex->uTextureWidth; j++ )
     {
-      LOBYTE(v6) = *(char *)v4;
-      v4 = (char *)v4 + 1;
-      if ( v6 )
-        *v5 = uZValue;
-      ++v5;
-      --v7;
+      //LOBYTE(v6) = *(char *)v4;
+      //v4 = (char *)v4 + 1;
+      //if ( v6 )
+        *pZBuffer = uZValue;
+      ++pZBuffer;
     }
-    while ( v7 );
-    v5 += 640 - v10;
-    --v11;
+    pZBuffer += 640 - pTex->uTextureWidth;
   }
-  while ( v11 );
   if ( pIcons_LOD->dword_011BA4 )
   {
-    if ( v8->uDecompressedSize )
-      free(v12);
+    if ( pTex->uDecompressedSize )
+      free(v3);
   }
 }
 
 //----- (0040F92A) --------------------------------------------------------
 void __fastcall ZBuffer_DoFill2(int *pZBuffer, Texture *a2, int a3)
-{
-  Texture *v3; // esi@1
+{//срабатывает в покупке в магазине
   void *v4; // eax@3
-  int *v5; // edi@5
+  //int *v5; // edi@5
   int v6; // ecx@6
-  int *v7; // [sp+Ch] [bp-10h]@1
-  int v8; // [sp+10h] [bp-Ch]@1
   int v9; // [sp+18h] [bp-4h]@1
 
-  v3 = a2;
-  v7 = pZBuffer;
-  v8 = a2->uTextureWidth;
-  v9 = a2->uTextureHeight;
   if ( pIcons_LOD->dword_011BA4 && a2->uDecompressedSize )
     v4 = a2->UnzipPalette();
   else
     v4 = a2->pLevelOfDetail0_prolly_alpha_mask;
-  v5 = v7;
-  do
+  //v5 = pZBuffer;
+  for ( uint i = 0; i < a2->uTextureHeight; i++ )
   {
-    v6 = v8;
-    do
+    for ( uint j = 0; j < a2->uTextureWidth; j++ )
     {
-      *v5 = a3;
-      ++v5;
-      --v6;
+      *pZBuffer = a3;
+      ++pZBuffer;
     }
-    while ( v6 );
-    v5 += 640 - v8;
-    --v9;
+    pZBuffer += 640 - a2->uTextureWidth;
   }
-  while ( v9 );
   if ( pIcons_LOD->dword_011BA4 )
   {
-    if ( v3->uDecompressedSize )
+    if ( a2->uDecompressedSize )
       free(v4);
   }
 }
@@ -1254,6 +1167,7 @@
   const char **v3; // esi@2
   char *v4; // ebx@2
 
+  __debugbreak();//Ritor1
   v1 = a1;
   v2 = 1;
   if ( _stricmp(pMapStats->pInfos[1].pFilename, (const char *)&pGames_LOD->pSubIndices[a1]) )
--- a/mm7_6.cpp	Mon Dec 23 15:17:50 2013 +0100
+++ b/mm7_6.cpp	Mon Dec 23 15:18:16 2013 +0100
@@ -60,6 +60,7 @@
   int v15; // eax@14
   signed int result; // eax@17
 
+  __debugbreak();//Ritor1
   v5 = pActor->pMonsterInfo.uAC;
   v6 = 0;
   if ( (signed __int64)pActor->pActorBuffs[ACTOR_BUFF_SOMETHING_THAT_HALVES_AC].uExpireTime > 0 )
@@ -439,11 +440,7 @@
 
     DamageMonsterFromParty(PID(OBJECT_Player, uActiveCharacter - 1), target_id, &a3);
     if (player->WearsItem(ITEM_ARTIFACT_SPLITTER, EQUIP_TWO_HANDED) || player->WearsItem(ITEM_ARTIFACT_SPLITTER, EQUIP_SINGLE_HANDED))
-          _42FA66_do_explosive_impact(
-            actor->vPosition.x,
-            actor->vPosition.y,
-            actor->vPosition.z + actor->uActorHeight / 2,
-            0, 512, uActiveCharacter);
+          _42FA66_do_explosive_impact(actor->vPosition.x, actor->vPosition.y, actor->vPosition.z + actor->uActorHeight / 2, 0, 512, uActiveCharacter);
   }
   else if (bow_idx)
   {
@@ -464,7 +461,6 @@
     player->SetRecoveryTime(flt_6BE3A4_debug_recmod1 * (double)recovery * 2.133333333333333);
   }
 
-  
   int v34 = 0;
   if (shooting_wand)
     return;
@@ -529,6 +525,7 @@
   int i; // [sp+38h] [bp+Ch]@33
   signed int v32; // [sp+3Ch] [bp+10h]@32
 
+  __debugbreak();//Ritor1
   v4 = 0;
   v5 = this;
   v24 = this;
@@ -708,16 +705,11 @@
   pSpellObject.spell_id = 0;
   pSpellObject.field_54 = 0;
   pSpellObject.uType = uSpriteID;
-  if ( (signed int)pObjectList->uNumObjects <= 0 )
-    pObjectDescID = 0;
-  else
+  pObjectDescID = 0;
+  for ( uint i = 0; i < (signed int)pObjectList->uNumObjects; ++i )
   {
-    pObjectDescID = 0;
-    for ( uint i = 0; i < (signed int)pObjectList->uNumObjects; ++i )
-    {
-      if ( (short)uSpriteID == pObjectList->pObjects[i].uObjectID )
-        pObjectDescID = i;
-    }
+    if ( (short)uSpriteID == pObjectList->pObjects[i].uObjectID )
+      pObjectDescID = i;
   }
   pSpellObject.uObjectDescID = pObjectDescID;
   pSpellObject.vPosition.x = x;
@@ -770,52 +762,32 @@
 //----- (0042F960) --------------------------------------------------------
 void __fastcall sub_42F960_create_object(int x, int y, int z)
 {
-  int v3; // ebx@1
-  int v4; // edi@1
-  signed int v5; // edx@1
-  char *v6; // ecx@2
   unsigned __int16 v7; // ax@5
   signed int v8; // eax@6
   signed int v9; // eax@7
-  //SpriteObject a1; // [sp+Ch] [bp-70h]@1
 
-  v3 = x;
-  v4 = y;
-  
   SpriteObject a1; // [sp+Ch] [bp-70h]@1
   //SpriteObject::SpriteObject(&a1);
   a1.stru_24.Reset();
 
-  v5 = 0;
   a1.spell_skill = 0;
   a1.spell_level = 0;
   a1.spell_id = 0;
   a1.field_54 = 0;
   a1.uType = 800;
-  if ( (signed int)pObjectList->uNumObjects <= 0 )
-  {
-LABEL_5:
-    v7 = 0;
-  }
-  else
+  v7 = 0;
+  for ( uint i = 0; i < (signed int)pObjectList->uNumObjects; ++i )
   {
-    v6 = (char *)&pObjectList->pObjects->uObjectID;
-    while ( *(short *)v6 != 800 )
-    {
-      ++v5;
-      v6 += 56;
-      if ( v5 >= (signed int)pObjectList->uNumObjects )
-        goto LABEL_5;
-    }
-    v7 = v5;
+    if ( a1.uType == pObjectList->pObjects[i].uObjectID  )
+      v7 = i;
   }
   a1.uObjectDescID = v7;
-  a1.vPosition.x = v3;
-  a1.vPosition.y = v4;
+  a1.vPosition.x = x;
+  a1.vPosition.y = y;
   a1.vPosition.z = z;
   a1.uSoundID = 0;
   a1.uAttributes = 0;
-  a1.uSectorID = pIndoor->GetSector(v3, v4, z);
+  a1.uSectorID = pIndoor->GetSector(x, y, z);
   a1.uSpriteFrameID = 0;
   a1.spell_caster_pid = 0;
   a1.spell_target_pid = 0;
@@ -828,23 +800,11 @@
   }
 }
 
-
-
 //----- (0042FA66) --------------------------------------------------------
 void _42FA66_do_explosive_impact(int a1, int a2, int a3, int a4, __int16 a5, signed int a6)
 {
-  int v6; // edi@1
-  int v7; // esi@1
-  char *v8; // ecx@2
   unsigned __int16 v9; // ax@5
-  //int v10; // eax@10
-  //signed int result; // eax@11
-  //__int16 v12; // ax@12
-  //SpriteObject a1a; // [sp+Ch] [bp-74h]@1
-  int v14; // [sp+7Ch] [bp-4h]@1
 
-  v6 = a1;
-  v7 = a2;
   SpriteObject a1a; // [sp+Ch] [bp-74h]@1
   //SpriteObject::SpriteObject(&a1a);
   a1a.uType = 600;
@@ -853,43 +813,27 @@
   a1a.spell_id = SPELL_FIRE_FIREBALL;
   a1a.spell_level = 8;
   a1a.spell_skill = 3;
-  v14 = 0;
-  if ( (signed int)pObjectList->uNumObjects <= 0 )
-  {
-LABEL_5:
-    v9 = 0;
-  }
-  else
+  v9 = 0;
+  for ( uint i = 0; i < pObjectList->uNumObjects; ++i )
   {
-    v8 = (char *)&pObjectList->pObjects->uObjectID;
-    while ( (short)a1a.uType != *(short *)v8 )
-    {
-      ++v14;
-      v8 += 56;
-      if ( v14 >= (signed int)pObjectList->uNumObjects )
-        goto LABEL_5;
-    }
-    v9 = v14;
+    if ( a1a.uType == pObjectList->pObjects[i].uObjectID )
+      v9 = i;
   }
   a1a.uObjectDescID = v9;
-  a1a.vPosition.x = v6;
-  a1a.vPosition.y = v7;
+  a1a.vPosition.x = a1;
+  a1a.vPosition.y = a2;
   a1a.vPosition.z = a3;
   a1a.uAttributes = 0;
-  a1a.uSectorID = pIndoor->GetSector(v6, v7, a3);
+  a1a.uSectorID = pIndoor->GetSector(a1, a2, a3);
   a1a.uSpriteFrameID = 0;
   a1a.spell_target_pid = 0;
   a1a.field_60_distance_related_prolly_lod = 0;
   a1a.uFacing = 0;
   a1a.uSoundID = 0;
   if ( a6 >= 1 || a6 <= 4 )
-  {
     a1a.spell_caster_pid = PID(OBJECT_Player, a6 - 1);
-  }
   else
-  {
     a1a.spell_caster_pid = 0;
-  }
 
   int id = a1a.Create(0, 0, 0, 0);
   if (id != -1)
@@ -898,63 +842,22 @@
 }
 
 //----- (0042FB5C) --------------------------------------------------------
-bool _42FB5C_check_spell(signed int a1)
+bool _42FB5C_check_spell(signed int spell_id)
 {
-  int v1; // ecx@3
-  int v2; // ecx@4
-  int v3; // ecx@5
-  int v4; // ecx@6
-  int v5; // ecx@7
-  int v6; // ecx@8
-  char v7; // zf@9
-
-  if ( a1 > 39 )
+  if ( spell_id > 39 )
   {
-    if ( a1 > 77 )
-    {
-      if ( a1 == 80 )
-        return 0;
-      if ( a1 > 84 )
-      {
-        if ( a1 <= 86 )
-          return 0;
-        v7 = a1 == 95;
-        goto LABEL_20;
-      }
-    }
-    else
-    {
-      if ( a1 == 77 )
-        return 0;
-      if ( a1 >= 46 )
-      {
-        if ( a1 <= 47 || a1 == 51 )
-          return 0;
-        v7 = a1 == 73;
-        goto LABEL_20;
-      }
-    }
-    return 1;
+    if ( spell_id == SPELL_SPIRIT_BLESS || spell_id == SPELL_SPIRIT_FATE || spell_id == SPELL_SPIRIT_HEROISM || spell_id == SPELL_BODY_HAMMERHANDS
+      || spell_id == SPELL_BODY_POWER_CURE ||spell_id == SPELL_LIGHT_DISPEL_MAGIC || spell_id == SPELL_LIGHT_DAY_OF_PROTECTION
+      || spell_id == SPELL_LIGHT_HOUR_OF_POWER || spell_id == SPELL_DARK_PAIN_REFLECTION)
+      return false;
+    return true;
   }
-  if ( a1 == 39 || (v1 = a1 - 2) == 0 )
-    return 1;
-  v2 = v1 - 3;
-  if ( !v2 )
-    return 0;
-  v3 = v2 - 1;
-  if ( !v3 || (v4 = v3 - 3) == 0 )
-    return 1;
-  v5 = v4 - 8;
-  if ( !v5 )
-    return 0;
-  v6 = v5 - 1;
-  if ( !v6 )
-    return 1;
-  v7 = v6 == 20;
-LABEL_20:
-  if ( !v7 )
-    return 1;
-  return 0;
+  if ( spell_id == SPELL_FIRE_FIRE_BOLT || spell_id == SPELL_FIRE_FIREBALL || spell_id == SPELL_FIRE_METEOR_SHOWER
+    || spell_id == SPELL_AIR_LIGHNING_BOLT || spell_id == SPELL_EARTH_BLADES )
+    return true;
+  if ( spell_id == SPELL_FIRE_HASTE || spell_id == SPELL_AIR_SHIELD || spell_id == SPELL_EARTH_STONESKIN )
+    return false;
+  return true;
 }
 
 //----- (0042FBDD) --------------------------------------------------------
@@ -977,14 +880,14 @@
 void ProcessInputActions()
 {
   char v4; // al@9
-  char v8; // bl@100
+  //char v8; // bl@100
   unsigned __int16 v9; // ax@102
-  int v10; // eax@103
+  int spell_price; // eax@103
   char v14; // al@159
   unsigned int v15; // eax@168
   PartyAction partyAction; // [sp-14h] [bp-1Ch]@20
   InputAction inputAction; // [sp+0h] [bp-8h]@7
-  int v24; // [sp+4h] [bp-4h]@87
+  //int v24; // [sp+4h] [bp-4h]@87
 
   pGame->pKeyboardInstance->EnterCriticalSection();
   Keyboard* pKeyboard = pGame->pKeyboardInstance;
@@ -1208,9 +1111,8 @@
             {
               if ( !pPlayers[uActiveCharacter]->uTimeToRecovery )
               {
-                v24 = pPlayers[uActiveCharacter]->GetAttackRecoveryTime(false);
                 if ( !pParty->bTurnBasedModeOn )
-                  pPlayers[uActiveCharacter]->SetRecoveryTime((signed __int64)(flt_6BE3A4_debug_recmod1 * (double)v24 * 2.133333333333333));
+                  pPlayers[uActiveCharacter]->SetRecoveryTime((signed __int64)(flt_6BE3A4_debug_recmod1 * (double)pPlayers[uActiveCharacter]->GetAttackRecoveryTime(false) * 2.133333333333333));
                 CastSpellInfoHelpers::_427D48();
                 pTurnEngine->ApplyPlayerAction();
               }
@@ -1244,24 +1146,21 @@
             }
             if ( !uActiveCharacter )
               break;
-            v8 = pPlayers[uActiveCharacter]->uQuickSpell;
-            if ( !v8
-              || bUnderwater
-              || ((v9 = pPlayers[uActiveCharacter]->pActiveSkills[(unsigned __int8)v8 / 11 + 12], !(HIBYTE(v9) & 1)) ? 
-                 ((v9 & 0x80u) == 0 ? (!(v9 & 0x40) ? (v10 = *(&pSpellDatas[0].uNormalLevelMana + 10 * (unsigned __int8)v8)) : 
-                 (v10 = *(&pSpellDatas[0].uExpertLevelMana + 10 * (unsigned __int8)v8))) : 
-                 (v10 = *(&pSpellDatas[0].uMasterLevelMana + 10 * (unsigned __int8)v8))) : 
-                 (v10 = *(&pSpellDatas[0].uMagisterLevelMana + 10 * (unsigned __int8)v8)),
-                  v10 > pPlayers[uActiveCharacter]->sMana) )
+            v9 = pPlayers[uActiveCharacter]->pActiveSkills[(unsigned __int8)pPlayers[uActiveCharacter]->uQuickSpell / 11 + 12];
+            if ( !pPlayers[uActiveCharacter]->uQuickSpell || bUnderwater
+              || (( !(HIBYTE(v9) & 1)) ? 
+                 ((v9 & 0x80) == 0 ? 
+                 ((v9 & 0x40) == 0 ? spell_price = pSpellDatas[pPlayers[uActiveCharacter]->uQuickSpell].uNormalLevelMana : spell_price = pSpellDatas[pPlayers[uActiveCharacter]->uQuickSpell].uExpertLevelMana) : 
+                 spell_price = pSpellDatas[pPlayers[uActiveCharacter]->uQuickSpell].uMasterLevelMana) : 
+                 spell_price = pSpellDatas[pPlayers[uActiveCharacter]->uQuickSpell].uMagisterLevelMana,
+                 spell_price > pPlayers[uActiveCharacter]->sMana) )
             {
               pPartyActionQueue = pPartyActionQueue;
               pMessageQueue_50CBD0->AddMessage(UIMSG_Attack, 0, 0);
               break;
             }
             else
-            {
-            pMessageQueue_50C9E8->AddMessage(UIMSG_CastQuickSpell, 0, 0);
-            }
+              pMessageQueue_50C9E8->AddMessage(UIMSG_CastQuickSpell, 0, 0);
             break;
           case INPUT_Attack:
             if (pCurrentScreen != SCREEN_GAME)
--- a/mm7_7.cpp	Mon Dec 23 15:17:50 2013 +0100
+++ b/mm7_7.cpp	Mon Dec 23 15:18:16 2013 +0100
@@ -29,7 +29,7 @@
   dword_4F8580[0] = 1;
   return result;
   */
-
+	__debugbreak();//Ritor1
   for( int i = 0; i < 62; i++ )
   {
 	  dword_4F8580[i] = 0;
@@ -41,18 +41,9 @@
 //----- (00423B4A) --------------------------------------------------------
 void  sub_423B4A()
 {
-  float *v0; // eax@1
-  signed int v1; // ecx@1
-
-  v0 = &array_507D30[0].flt_2C;
-  v1 = 50;
-  do
-  {
-    *v0 = 0.0;
-    v0 += 12;
-    --v1;
-  }
-  while ( v1 );
+	__debugbreak();//Ritor1
+  for ( uint i = 0; i < 50; i++ )
+    array_507D30[i].flt_2C = 0.0;
 }
 
 /*
--- a/mm7_data.h	Mon Dec 23 15:17:50 2013 +0100
+++ b/mm7_data.h	Mon Dec 23 15:18:16 2013 +0100
@@ -1062,8 +1062,8 @@
 int MakeActorAIList_BLV();
 void UpdateActorAI();
 bool __fastcall sub_4070EF_prolly_detect_player(unsigned int uObjID, unsigned int uObj2ID);
-bool __fastcall sub_4075DB(int a1, int a2, int a3, struct BLVFace *a4);
-bool __fastcall sub_4077F1(int a1, int a2, int a3, struct ODMFace *a4, struct BSPVertexBuffer *a5);
+bool __fastcall sub_4075DB(int a1, int a2, int a3, struct BLVFace *face);
+bool __fastcall sub_4077F1(int a1, int a2, int a3, struct ODMFace *face, struct BSPVertexBuffer *a5);
 bool __fastcall sub_407A1C(int x, int z, int y, struct Vec3_int_ v); // idb
 void InitializeActors();
 void InitializeSpriteObjects();
@@ -1116,7 +1116,7 @@
 void __fastcall sub_42F960_create_object(int x, int y, int z); // idb
 void CompactLayingItemsList();
 void _42FA66_do_explosive_impact(int a1, int a2, int a3, int a4, __int16 a5, signed int a6);
-bool _42FB5C_check_spell(signed int a1);
+bool _42FB5C_check_spell(signed int spell_id);
 void sub_42FBDD();
 void CloseWindowBackground();
 void ProcessInputActions();