changeset 2108:16f5a7ca289a

Merge
author Grumpy7
date Fri, 20 Dec 2013 01:28:39 +0100
parents 85e9766d6124 (current diff) b52c09e01e7e (diff)
children 4fae5a167a05
files Spells.cpp mm7_data.h
diffstat 18 files changed, 2595 insertions(+), 3033 deletions(-) [+]
line wrap: on
line diff
--- a/Actor.cpp	Fri Dec 20 01:25:52 2013 +0100
+++ b/Actor.cpp	Fri Dec 20 01:28:39 2013 +0100
@@ -4404,4 +4404,45 @@
     this->pActorBuffs[ACTOR_BUFF_FATE].Reset();
   }
   return rand() % (armorSum + 2 * this->pMonsterInfo.uLevel + 10) + a2a + 1 > armorSum + 5;
+}
+
+//----- (00448A98) --------------------------------------------------------
+void __fastcall ToggleActorGroupFlag(unsigned int uGroupID, unsigned int uFlag, unsigned int bToggle)
+{
+  if ( uGroupID )
+  {
+    if ( bToggle )
+    {
+      for ( uint i = 0; i < (unsigned int)uNumActors; ++i )
+      {
+        if ( pActors[i].uGroup == uGroupID )
+        {
+          pActors[i].uAttributes |= uFlag;
+          if ( uFlag == 0x10000 )
+          {
+            pActors[i].uAIState = Disabled;
+            pActors[i].UpdateAnimation();
+          }
+        }
+      }
+    }
+    else
+    {
+      for ( uint i = 0; i < (unsigned int)uNumActors; ++i )
+      {
+        if ( pActors[i].uGroup == uGroupID )
+        {
+          if ( uFlag == 0x10000 )
+          {
+            if ( pActors[i].uAIState != Dead )
+            {
+              if ( pActors[i].uAIState != 4 && pActors[i].uAIState != 11 )
+                pActors[i].uAIState = Standing;
+            }
+          }
+          LODWORD(pActors[i].uAttributes) &= ~uFlag;
+        }
+      }
+    }
+  }
 }
\ No newline at end of file
--- a/AudioPlayer.cpp	Fri Dec 20 01:25:52 2013 +0100
+++ b/AudioPlayer.cpp	Fri Dec 20 01:28:39 2013 +0100
@@ -535,44 +535,30 @@
   if (!bPlayerReady)
     return;
 
-    if ( this->b3DSoundInitialized && a2 && this->uNum3DSamples > 0 )
+  if ( this->b3DSoundInitialized && a2 )
+  {
+    for ( uint i = 0; i < this->uNum3DSamples; ++i )
     {
-      for ( uint i = 0; i < this->uNum3DSamples; ++i )
-      {
-        if ( this->p3DSamples[i].field_4 == a2 && AIL_3D_sample_status(this->p3DSamples[i].hSample) == 4 )
-          AIL_end_3D_sample(this->p3DSamples[i].hSample);
-      }
-      goto LABEL_9;
+      if ( this->p3DSamples[i].field_4 == a2 && AIL_3D_sample_status(this->p3DSamples[i].hSample) == AIL::Sample::Playing )
+        AIL_end_3D_sample(this->p3DSamples[i].hSample);
     }
-    else
+  }
+  if ( this->hDigDriver && a2 )
+  {
+    for ( uint i = 0; i < this->uMixerChannels; ++i )
     {
-LABEL_9:
-      if ( this->hDigDriver )
+      if ( this->pMixerChannels[i].source_pid == a2 && AIL_sample_status(this->pMixerChannels[i].hSample) == AIL::Sample::Playing)
       {
-        if ( a2 && this->uMixerChannels > 0 )
-        {
-          for ( uint i = 0; i < this->uMixerChannels; ++i )
-          {
-            if ( this->pMixerChannels[i].source_pid == a2 )
-            {
-              if ( AIL_sample_status(this->pMixerChannels[i].hSample) == AIL::Sample::Playing)
-              {
-                AIL_end_sample(this->pMixerChannels[i].hSample);
-                FreeChannel(&this->pMixerChannels[i]);
-              }
-            }
-          }
-        }
+        AIL_end_sample(this->pMixerChannels[i].hSample);
+        FreeChannel(&this->pMixerChannels[i]);
       }
     }
+  }
 }
 
 //----- (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)
 {
-  //AudioPlayer *pAudioPlayer1; // esi@1
-  //signed int pNum; // edx@5
-  //int *pSoundID; // ecx@6
   int v12; // edi@13
   signed int v13; // ecx@17
   signed int v14; // eax@20
@@ -598,9 +584,7 @@
   int v34; // eax@70
   char v35; // zf@70
   signed int v36; // ebx@74
-  //AudioPlayer *pAudioPlayer2; // edi@79
   AudioPlayer_3DSample *pAudioPlayer_3DSample3; // esi@79
-  //unsigned int v39; // ebx@80
   int v40; // eax@81
   char *v41; // edi@82
   int v42; // esi@82
@@ -616,47 +600,16 @@
   int v52; // eax@104
   float v53; // ST0C_4@106
   float v54; // ST04_4@106
-  //AudioPlayer *pAudioPlayer3; // edx@106
   SoundDesc *pSoundDesc; // edx@107
   SpriteObject *pLayingItem3; // eax@114
-  //int v58; // edx@115
-  //int v59; // ecx@115
-  //Actor *pActor2; // eax@118
-  //MixerChannel *pMixerChannel; // esi@126
   signed int v62; // esi@133
-  //AudioPlayer *pAudioPlayer4; // ebx@133
-  //MixerChannel *pMixerChannel2; // edi@134
-  //int v65; // ebx@141
-  //AudioPlayer *pAudioPlayer5; // ecx@142
-  //MixerChannel *pMixerChannel3; // edi@142
   int v68; // eax@143
-  //MixerChannel *pMixerChannel4; // edi@149
-  //int v70; // ecx@152
-  //SoundDesc *pSoundDesc2; // eax@153
-  //int v72; // edi@156
-  //MixerChannel *pMixerChannel5; // esi@157
-  //unsigned int pVolume; // eax@157
-  //int pPartyX; // ebx@159
-  //int v76; // ebx@160
-  //SpriteObject *pLayingItem4; // edi@164
-  //unsigned int pPosY; // edx@166
-  //unsigned int pPosX; // ecx@166
-  //int v80; // eax@167
-  //Actor *pActor3; // edi@168
-  //BLVDoor *pBLVDoor2; // edi@173
-  //int v83; // eax@183
-  //int v84; // eax@183
-  //_SAMPLE *v85; // ST18_4@186
   unsigned int v86; // [sp+14h] [bp-60h]@84
-  //int v87; // [sp+14h] [bp-60h]@115
   RenderVertexSoft pRenderVertexSoft; // [sp+24h] [bp-50h]@1
-  //unsigned int v89; // [sp+54h] [bp-20h]@12
   int v90; // [sp+58h] [bp-1Ch]@68
   float v91; // [sp+5Ch] [bp-18h]@68
-  //unsigned int v92; // [sp+60h] [bp-14h]@10
   float v93; // [sp+64h] [bp-10h]@1
   signed int varC; // [sp+68h] [bp-Ch]@68
-  //AudioPlayer *pAudioPlayer; // [sp+6Ch] [bp-8h]@1
   int v96; // [sp+70h] [bp-4h]@19
   signed int uNumRepeatsb; // [sp+84h] [bp+10h]@93
   float uNumRepeatsa; // [sp+84h] [bp+10h]@104
@@ -666,22 +619,11 @@
   int v102; // [sp+90h] [bp+1Ch]@60
   int v103; // [sp+90h] [bp+1Ch]@68
 
-  if (!bPlayerReady)
-    return;
-  if (!uSoundVolumeMultiplier)
-    return;
-  if (!hDigDriver)
-    return;
-  if (eSoundID == SOUND_Invalid)
+  if ( !bPlayerReady || !uSoundVolumeMultiplier || !hDigDriver || eSoundID == SOUND_Invalid )
     return;
 
-  //pAudioPlayer = this;
-  //v35 = this->bPlayerReady == 0;
-  //pAudioPlayer = this;
-  //LODWORD(v93) = 10000;
   int sample_volume = 10000;
 
-
   int sound_id = 0;
   for (uint i = 0; i < pSoundList->sNumSounds; ++i)
     if (pSoundList->pSounds[i].uSoundID == eSoundID)
@@ -695,345 +637,464 @@
     Log::Warning(L"SoundID = %u not found", eSoundID);
     return;
   }
+  assert(sound_id < pSoundList->sNumSounds);
+  if ( !a7 )
+  {
+    if ( !pSoundList->pSounds[sound_id].pSoundData[0] )
+    {
+      if ( pSoundList->pSounds[sound_id].eType == SOUND_DESC_SWAP )
+        pSoundList->LoadSound(eSoundID, 0);
+    }
+  }
+  if ( !pSoundList->pSounds[sound_id].pSoundData[a7] )
+    return;
 
   int start_channel = 0,
       end_channel = 0;
-v62 = start_channel;
-  assert(sound_id < pSoundList->sNumSounds);
-  SoundDesc* sound_desc = &pSoundList->pSounds[sound_id];
-  if (!b3DSoundInitialized || sound_desc->Is3D())
+  v62 = start_channel;
+
+  if (!b3DSoundInitialized || pSoundList->pSounds[sound_id].Is3D())
   {
-    if (!a3)  // generic sound like from UI
+    if (a3 == 0)  // generic sound like from UI
     {
       start_channel = 10;
       end_channel = 12;
-      for (v62 = start_channel; v62 <= end_channel; ++v62)
+      for (uint i = start_channel; i <= end_channel; ++i)
       {
-        MixerChannel* channel = pMixerChannels + v62;
-        if (AIL_sample_status(channel->hSample) == AIL::Sample::Done)
+        if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing )
         {
-          AIL_end_sample(channel->hSample);
-          if (channel->uSourceTrackIdx)
-            FreeChannel(channel);
-          break;
+          if ( pMixerChannels[i].uSourceTrackIdx == sound_id )
+            return;                          // already playing the same sound from the same source - return
+          AIL_end_sample(pMixerChannels[i].hSample);  // requested new sound from the same source - end & switch
+          FreeChannel(&pMixerChannels[i]);
         }
       }
+      for ( uint j = start_channel; j <= end_channel; j++ )
+      {
+        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);
+          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 (!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 (uNumRepeats)
+            AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1);
+          pMixerChannels[j].uSourceTrackIdx = sound_id;
+          pMixerChannels[j].source_pid = a3;
+          pMixerChannels[j].uSourceTrackID = eSoundID;
+          int rval = AIL_start_sample(pMixerChannels[j].hSample);
+          if ( sPlaybackRate )
+            AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate);
+          if (object_type == OBJECT_Player)
+            AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0);
+          return;
+        }
+      }
+      return;
     }
     else if (a3 == -1)  // exclusive sounds - can override
     {
-      start_channel = 13;
-      end_channel = 13;
-      for (v62 = start_channel; v62 <= end_channel; ++v62)
+      if ( AIL_sample_status(pMixerChannels[13].hSample) == AIL::Sample::Done )
       {
-        MixerChannel* channel = pMixerChannels + v62;
-        if (AIL_sample_status(channel->hSample) == AIL::Sample::Done)
+        AIL_end_sample(pMixerChannels[13].hSample);
+        if ( pMixerChannels[13].uSourceTrackIdx )
+          FreeChannel(&pMixerChannels[13]);
+      }
+    }
+    else if (a3 < 0)    // exclusive sounds - no override (close chest)
+    {
+      start_channel = 14;
+      end_channel = 14;
+      for (uint i = start_channel; i <= end_channel; ++i)
+      {
+        if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing )
         {
-          AIL_end_sample(channel->hSample);
-          if (channel->uSourceTrackIdx)
-            FreeChannel(channel);
-          break;
+          if ( pMixerChannels[i].uSourceTrackIdx == sound_id )
+            return;                          // already playing the same sound from the same source - return
+          AIL_end_sample(pMixerChannels[i].hSample);  // requested new sound from the same source - end & switch
+          FreeChannel(&pMixerChannels[i]);
         }
       }
+      for ( uint j = start_channel; j <= end_channel; j++ )
+      {
+        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);
+          if ( sample_volume == 10000 )
+            sample_volume = uMasterVolume;
+          if (uVolume)
+            sample_volume = uVolume;
+          int object_type = PID_TYPE(a3),
+              object_id = PID_ID(a3);
+          if (uNumRepeats)
+            AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1);
+          pMixerChannels[j].uSourceTrackIdx = sound_id;
+          pMixerChannels[j].source_pid = a3;
+          pMixerChannels[j].uSourceTrackID = eSoundID;
+          int rval = AIL_start_sample(pMixerChannels[j].hSample);//no sound chest close 
+          if ( sPlaybackRate )
+            AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate);
+          if (object_type == OBJECT_Player)
+            AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0);
+          return;
+        }
+      }
+      return;
     }
     else
     {
-      if (a3 < 0)    // exclusive sounds - no override
-      {
-        start_channel = 14;
-        end_channel = 14;
-        for (uint i = 0; i < uMixerChannels; ++i)
-        {
-          MixerChannel* channel = &pMixerChannels[i];
-          if (channel->source_pid == a3 && AIL_sample_status(channel->hSample) == AIL::Sample::Playing)
-          {
-            if (channel->uSourceTrackIdx == sound_id)
-              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
-            FreeChannel(channel);
-          }
-        }
-      }
-      else
-      {
         int object_type = PID_TYPE(a3),
             object_id = PID_ID(a3);
         switch (object_type)
         {
           case OBJECT_BLVDoor:
+          {
+            assert(uCurrentlyLoadedLevelType == LEVEL_Indoor);
+            assert(object_id < pIndoor->uNumDoors);
+            if ( !pIndoor->pDoors[object_id].uDoorID )
+              return;
+
+            start_channel = 10;
+            end_channel = 12;
+            for (uint i = start_channel; i <= end_channel; ++i)
+            {
+              if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing )
+              {
+                if ( pMixerChannels[i].uSourceTrackIdx == sound_id )
+                  return;                          // already playing the same sound from the same source - return
+                AIL_end_sample( pMixerChannels[i].hSample);  // requested new sound from the same source - end & switch
+                FreeChannel(&pMixerChannels[i]);
+              }
+            }
+            for ( uint j = start_channel; j <= end_channel; j++ )
+            {
+              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);
+                if (uVolume)
+                  sample_volume = uVolume;
+                AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume);
+                /*if (!GetSoundStrengthByDistanceFromParty(pIndoor->pDoors[object_id].pXOffsets[0], pIndoor->pDoors[object_id].pYOffsets[0], pIndoor->pDoors[object_id].pZOffsets[0]))
+                {
+                  AIL_end_sample(pMixerChannels[j].hSample);
+                  FreeChannel(&pMixerChannels[j]);
+                  return;
+                } */
+                AIL_set_sample_pan(pMixerChannels[j].hSample, sub_4AB66C(pIndoor->pDoors[object_id].pXOffsets[0], pIndoor->pDoors[object_id].pYOffsets[0]));
+                if (uNumRepeats)
+                  AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1);
+                pMixerChannels[j].uSourceTrackIdx = sound_id;
+                pMixerChannels[j].source_pid = a3;
+                pMixerChannels[j].uSourceTrackID = eSoundID;
+                int rval = AIL_start_sample(pMixerChannels[j].hSample);
+                if ( sPlaybackRate )
+                  AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate);
+                if (object_type == OBJECT_Player)
+                  AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0);
+                return;
+              }
+            }
+          }
+          return;
+
           case OBJECT_Player:
           {
             start_channel = 10;
             end_channel = 12;
-            for (v62 = start_channel; v62 <= end_channel; ++v62)
+            for (uint i = start_channel; i <= end_channel; ++i)
             {
-              MixerChannel* channel = pMixerChannels + v62;
-              if (AIL_sample_status(channel->hSample) == AIL::Sample::Done)
+              if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing )
+              {
+                if ( pMixerChannels[i].uSourceTrackIdx == sound_id )
+                  return;                          // already playing the same sound from the same source - return
+                AIL_end_sample( pMixerChannels[i].hSample);  // requested new sound from the same source - end & switch
+                FreeChannel(&pMixerChannels[i]);
+              }
+            }
+            for ( uint j = start_channel; j <= end_channel; j++ )
+            {
+              if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
               {
-                AIL_end_sample(channel->hSample);
-                if (channel->uSourceTrackIdx)
-                  FreeChannel(channel);
-                break;
+                AIL_init_sample(pMixerChannels[j].hSample);
+                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+                if (uVolume)
+                  sample_volume = uVolume;
+                AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume);
+                if (uNumRepeats)
+                  AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1);
+                pMixerChannels[j].uSourceTrackIdx = sound_id;
+                pMixerChannels[j].source_pid = a3;
+                pMixerChannels[j].uSourceTrackID = eSoundID;
+                int rval = AIL_start_sample(pMixerChannels[j].hSample);
+                if ( sPlaybackRate )
+                  AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate);
+                if (object_type == OBJECT_Player)
+                  AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0);
+                return;
               }
             }
           }
-          break;
+          return;
 
           case OBJECT_Actor:
           {
             start_channel = 0;
             end_channel = 3;
-
             assert(object_id < uNumActors);
-            Actor* actor = &pActors[object_id];
-
-            sample_volume = GetSoundStrengthByDistanceFromParty(actor->vPosition.x, actor->vPosition.y, actor->vPosition.z);
+            sample_volume = GetSoundStrengthByDistanceFromParty(pActors[object_id].vPosition.x, pActors[object_id].vPosition.y, pActors[object_id].vPosition.z);
             if (!sample_volume)
               return;
-            for (uint i = 0; i < uMixerChannels; ++i)
+            for (uint i = start_channel; i <= end_channel; ++i)
             {
-              MixerChannel* channel = &pMixerChannels[i];
-              if (channel->source_pid == a3 && AIL_sample_status(channel->hSample) == AIL::Sample::Playing)
+              if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing )
+              {
+                if ( pMixerChannels[i].uSourceTrackIdx == sound_id )
+                  return;                          // already playing the same sound from the same source - return
+                AIL_end_sample( pMixerChannels[i].hSample);  // requested new sound from the same source - end & switch
+                FreeChannel(&pMixerChannels[i]);
+              }
+            }
+            for ( uint j = start_channel; j <= end_channel; j++ )
+            {
+              if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
               {
-                if (channel->uSourceTrackIdx == sound_id)
-                  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
-                FreeChannel(channel);
+                AIL_init_sample(pMixerChannels[j].hSample);
+                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+                if (uVolume)
+                  sample_volume = uVolume;
+                AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume);
+                if (!GetSoundStrengthByDistanceFromParty(pActors[object_id].vPosition.x, pActors[object_id].vPosition.y, pActors[object_id].vPosition.z))
+                  return;
+                AIL_set_sample_pan(pMixerChannels[j].hSample, sub_4AB66C(pActors[object_id].vPosition.x, pActors[object_id].vPosition.y));
+                if (uNumRepeats)
+                  AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1);
+                pMixerChannels[j].uSourceTrackIdx = sound_id;
+                pMixerChannels[j].source_pid = a3;
+                pMixerChannels[j].uSourceTrackID = eSoundID;
+                int rval = AIL_start_sample(pMixerChannels[j].hSample);
+                if ( sPlaybackRate )
+                  AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate);
+                if (object_type == OBJECT_Player)
+                  AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0);
+                return;
               }
             }
           }
-          break;
+          return;
 
           case OBJECT_Decoration:
           {
             start_channel = 4;
             end_channel = 4;
-
             assert(object_id < uNumLevelDecorations);
-            LevelDecoration* decor = &pLevelDecorations[object_id];
-
-            sample_volume = GetSoundStrengthByDistanceFromParty(decor->vPosition.x, decor->vPosition.y, decor->vPosition.z);
+            sample_volume = GetSoundStrengthByDistanceFromParty(pLevelDecorations[object_id].vPosition.x, pLevelDecorations[object_id].vPosition.y, pLevelDecorations[object_id].vPosition.z);
             if (!sample_volume)
               return;
-            for (uint i = 0; i < uMixerChannels; ++i)
+            for (uint i = start_channel; i <= end_channel; ++i)
             {
-              MixerChannel* channel = &pMixerChannels[i];
-              if (channel->source_pid == a3 && AIL_sample_status(channel->hSample) == AIL::Sample::Playing)
+              if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing )//звук фонтана и шагов не проходят проверку на повтор
+              {
+                if ( pMixerChannels[i].uSourceTrackIdx == sound_id )
+                  return;                          // already playing the same sound from the same source - return
+                AIL_end_sample(pMixerChannels[i].hSample);  // requested new sound from the same source - end & switch
+                FreeChannel(&pMixerChannels[i]);
+              }
+            }
+            for ( uint j = start_channel; j <= end_channel; j++ )
+            {
+              if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
               {
-                if (channel->uSourceTrackIdx == sound_id)
-                  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
-                FreeChannel(channel);
+                AIL_init_sample(pMixerChannels[j].hSample);
+                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+                if (uVolume)
+                  sample_volume = uVolume;
+                AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume);
+                if (!GetSoundStrengthByDistanceFromParty(pLevelDecorations[object_id].vPosition.x, pLevelDecorations[object_id].vPosition.y, pLevelDecorations[object_id].vPosition.z))
+                  return;
+                AIL_set_sample_pan(pMixerChannels[j].hSample, sub_4AB66C(pLevelDecorations[object_id].vPosition.x, pLevelDecorations[object_id].vPosition.y));
+                if (uNumRepeats)
+                  AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1);
+                pMixerChannels[j].uSourceTrackIdx = sound_id;
+                pMixerChannels[j].source_pid = a3;
+                pMixerChannels[j].uSourceTrackID = eSoundID;
+                int rval = AIL_start_sample(pMixerChannels[j].hSample);
+                if ( sPlaybackRate )
+                  AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate);
+                if (object_type == OBJECT_Player)
+                  AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0);
+                return;
               }
             }
           }
-          break;
+          return;
 
           case OBJECT_Item:
           {
             start_channel = 5;
             end_channel = 7;
-
             assert(object_id < uNumSpriteObjects);
-            SpriteObject* object = &pSpriteObjects[object_id];
-
-            sample_volume = GetSoundStrengthByDistanceFromParty(object->vPosition.x, object->vPosition.y, object->vPosition.z);
+            sample_volume = GetSoundStrengthByDistanceFromParty(pSpriteObjects[object_id].vPosition.x, pSpriteObjects[object_id].vPosition.y, pSpriteObjects[object_id].vPosition.z);
             if (!sample_volume)
               return;
-            for (uint i = 0; i < uMixerChannels; ++i)
+            for (uint i = start_channel; i <= end_channel; ++i)
             {
-              MixerChannel* channel = &pMixerChannels[i];
-              if (channel->source_pid == a3 && AIL_sample_status(channel->hSample) == AIL::Sample::Playing)
+              if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing )
+              {
+                if (pMixerChannels[i].uSourceTrackIdx == sound_id)
+                  return;                          // already playing the same sound from the same source - return
+                AIL_end_sample(pMixerChannels[i].hSample);  // requested new sound from the same source - end & switch
+                FreeChannel(&pMixerChannels[i]);
+              }
+            }
+            for ( uint j = start_channel; j <= end_channel; j++ )
+            {
+              if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
               {
-                if (channel->uSourceTrackIdx == sound_id)
-                  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
-                FreeChannel(channel);
+                AIL_init_sample(pMixerChannels[j].hSample);
+                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+                if (uVolume)
+                  sample_volume = uVolume;
+                AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume);
+                if (!GetSoundStrengthByDistanceFromParty(pSpriteObjects[object_id].vPosition.x, pSpriteObjects[object_id].vPosition.y, pSpriteObjects[object_id].vPosition.z) )
+                  return;
+                AIL_set_sample_pan(pMixerChannels[v62].hSample, sub_4AB66C(pSpriteObjects[object_id].vPosition.x, pSpriteObjects[object_id].vPosition.y));
+                if (uNumRepeats)
+                  AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1);
+                pMixerChannels[j].uSourceTrackIdx = sound_id;
+                pMixerChannels[j].source_pid = a3;
+                pMixerChannels[j].uSourceTrackID = eSoundID;
+                int rval = AIL_start_sample(pMixerChannels[j].hSample);
+                if ( sPlaybackRate )
+                  AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate);
+                if (object_type == OBJECT_Player)
+                  AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0);
+                return;
               }
             }
           }
-          break;
+          return;
 
           case OBJECT_BModel:
           {
             start_channel = 8;
             end_channel = 9;
-            for (uint i = 0; i < uMixerChannels; ++i)
+            for (uint i = start_channel; i <= end_channel; ++i)
             {
-              MixerChannel* channel = &pMixerChannels[i];
-              if (channel->source_pid == a3 && AIL_sample_status(channel->hSample) == AIL::Sample::Playing)
+              if ( pMixerChannels[i].source_pid == a3 && AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Playing )
+              {
+                if ( pMixerChannels[i].uSourceTrackIdx == sound_id )
+                  return;                          // already playing the same sound from the same source - return
+                AIL_end_sample(pMixerChannels[i].hSample);  // requested new sound from the same source - end & switch
+                FreeChannel(&pMixerChannels[i]);
+              }
+            }
+            for ( uint j = start_channel; j <= end_channel; j++ )
+            {
+              if ( AIL_sample_status(pMixerChannels[j].hSample) == AIL::Sample::Done )
               {
-                if (channel->uSourceTrackIdx == sound_id)
-                  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
-                FreeChannel(channel);
+                AIL_init_sample(pMixerChannels[j].hSample);
+                AIL_set_sample_file(pMixerChannels[j].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+                if (uVolume)
+                  sample_volume = uVolume;
+                AIL_set_sample_volume(pMixerChannels[j].hSample, sample_volume);
+                if (uNumRepeats)
+                  AIL_set_sample_loop_count(pMixerChannels[j].hSample, uNumRepeats - 1);
+                pMixerChannels[j].uSourceTrackIdx = sound_id;
+                pMixerChannels[j].source_pid = a3;
+                pMixerChannels[j].uSourceTrackID = eSoundID;
+                int rval = AIL_start_sample(pMixerChannels[j].hSample);
+                if ( sPlaybackRate )
+                  AIL_set_sample_playback_rate(pMixerChannels[j].hSample, sPlaybackRate);
+                if (object_type == OBJECT_Player)
+                  AIL_sample_ms_position(pMixerChannels[j].hSample, &sLastTrackLengthMS, 0);
+                return;
               }
             }
           }
-          break;
+          return;
 
           default:
             assert(false);
         }
       }
-    }
-      /*if ( start_channel <= end_channel)
-      {
-        pMixerChannel2 = &pAudioPlayer->pMixerChannels[start_channel];
-        while ( AIL_sample_status(pMixerChannel2->hSample) != AIL::Sample::Done)
-        {
-          ++v62;
-          ++pMixerChannel2;
-          if ( v62 > end_channel )
-            goto LABEL_140;
-        }
-        AIL_end_sample(pMixerChannel2->hSample);
-        if ( pMixerChannel2->uSourceTrackIdx )
-          _4ABE55(pMixerChannel2);
-      }
-LABEL_140:*/
 
+	  __debugbreak();//Ritor1
       if (start_channel > end_channel)  // no free channel - occupy the quitest one
       {
         start_channel = -1;
-
         int min_volume = sample_volume;
         for (uint i = start_channel; i <= end_channel; ++i)
         {
-          MixerChannel* channel = &pMixerChannels[i];
-
-          int volume = AIL_sample_volume(channel->hSample);
+          int volume = AIL_sample_volume(pMixerChannels[i].hSample);
           if (volume < min_volume)
           {
             min_volume = volume;
             start_channel = i;
           }
         }
-        /*v65 = start_channel;
-        v91 = v93;
-      if (start_channel <= end_channel)
-      {
-        //pAudioPlayer5 = pAudioPlayer;
-        pMixerChannel3 = &pAudioPlayer->pMixerChannels[start_channel];
-        do
-        {
-          v68 = AIL_sample_volume(pMixerChannel3->hSample);
-          if ( v68 < SLODWORD(v91) )
-          {
-            LODWORD(v91) = v68;
-            v62 = v65;
-          }
-          ++v65;
-          ++pMixerChannel3;
-        }
-        while ( v65 <= end_channel );*/
-
         if (v62 == -1)   // no free channels at all - only channel 13 allows override (a3 == -1)
         {
           if (start_channel != 13)
             return;
           v62 = 13;
         }
-
-        MixerChannel* channel = &pMixerChannels[v62];
-        AIL_end_sample(channel->hSample);
-        FreeChannel(channel);
+        AIL_end_sample(pMixerChannels[v62].hSample);
+        FreeChannel(&pMixerChannels[v62]);
       }
 
       if (v62 > end_channel)//10!=13
         return;
 
-//LABEL_150:
-      if (sample_volume == 10000)
+      if ( sample_volume == 10000 )
         sample_volume = uMasterVolume;
 
-        //v70 = 0;
-      if ( !a7 )
-      {
-          //pSoundDesc = pSoundList->pSounds;
-          //pSoundDesc2 = &pSoundList->pSounds[sound_id];
-        if (!sound_desc->pSoundData[0])
-        {
-          if (sound_desc->eType == SOUND_DESC_SWAP)
-            pSoundList->LoadSound(eSoundID, 0);
-        }
-      }
-        //v72 = 4 * (a7 + 30 * sound_id) + 44;
-      if (!pSoundList->pSounds[sound_id].pSoundData[a7])
-        return;
-
-        //pMixerChannel5 = &pAudioPlayer->pMixerChannels[v62];
-      MixerChannel* channel = &pMixerChannels[v62];
-      AIL_init_sample(channel->hSample);
-      AIL_set_sample_file(channel->hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
+      AIL_init_sample(pMixerChannels[v62].hSample);
+      AIL_set_sample_file(pMixerChannels[v62].hSample, (char *)pSoundList->pSounds[sound_id].pSoundData[a7] + 4 * (a7 == 0), -1);
       if (uVolume)
         sample_volume = uVolume;
-      AIL_set_sample_volume(channel->hSample, sample_volume);
+      AIL_set_sample_volume(pMixerChannels[v62].hSample, sample_volume);
 
       int object_type = PID_TYPE(a3),
           object_id = PID_ID(a3);
       if (PartyX != -1)
       {
-        if (!PartyX) PartyX = pParty->vPosition.x;
-        if (!PartyY) PartyY = pParty->vPosition.y;
-        AIL_set_sample_pan(channel->hSample, sub_4AB66C(PartyX, PartyY));
-        AIL_set_sample_volume(channel->hSample, GetSoundStrengthByDistanceFromParty(PartyX, PartyY, pParty->vPosition.z));
-      }
-      else if (object_type == OBJECT_BLVDoor)
-      {
-        assert(uCurrentlyLoadedLevelType == LEVEL_Indoor);
-
-        assert(object_id < pIndoor->uNumDoors);
-        BLVDoor* door = &pIndoor->pDoors[object_id];
-        if (!door->uDoorID)
-          return;
-
-        if (!GetSoundStrengthByDistanceFromParty(door->pXOffsets[0], door->pYOffsets[0], door->pZOffsets[0]))
-        {
-          AIL_end_sample(channel->hSample);
-          FreeChannel(channel);
-          return;
-        }
-        AIL_set_sample_pan(channel->hSample, sub_4AB66C(door->pXOffsets[0], door->pYOffsets[0]));
-      }
-      else if (object_type == OBJECT_Item)
-      {
-        assert(object_id < uNumSpriteObjects);
-        SpriteObject* object = &pSpriteObjects[object_id];
-        if (!GetSoundStrengthByDistanceFromParty(object->vPosition.x, object->vPosition.y, object->vPosition.z) )
-            return;
-        AIL_set_sample_pan(channel->hSample, sub_4AB66C(object->vPosition.x, object->vPosition.y));
-      }
-      else if (object_type == OBJECT_Actor)
-      {
-        assert(object_id < uNumActors);
-        Actor* actor = &pActors[object_id];
-        if (!GetSoundStrengthByDistanceFromParty(actor->vPosition.x, actor->vPosition.y, actor->vPosition.z))
-          return;
-        AIL_set_sample_pan(channel->hSample, sub_4AB66C(actor->vPosition.x, actor->vPosition.y));
-      }
-      else if (object_type == OBJECT_Decoration)
-      {
-        assert(object_id < uNumLevelDecorations);
-        LevelDecoration* decor = &pLevelDecorations[object_id];
-        if (!GetSoundStrengthByDistanceFromParty(decor->vPosition.x, decor->vPosition.y, decor->vPosition.z))
-          return;
-        AIL_set_sample_pan(channel->hSample, sub_4AB66C(decor->vPosition.x, decor->vPosition.y));
+        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));
       }
 
-//LABEL_184:
       if (uNumRepeats)
-        AIL_set_sample_loop_count(channel->hSample, uNumRepeats - 1);
-      channel->uSourceTrackIdx = sound_id;
-      channel->source_pid = a3;
-      channel->uSourceTrackID = eSoundID;
-      int rval = AIL_start_sample(channel->hSample);
+        AIL_set_sample_loop_count(pMixerChannels[v62].hSample, uNumRepeats - 1);
+      pMixerChannels[v62].uSourceTrackIdx = sound_id;
+      pMixerChannels[v62].source_pid = a3;
+      pMixerChannels[v62].uSourceTrackID = eSoundID;
+      int rval = AIL_start_sample(pMixerChannels[v62].hSample);
       if ( sPlaybackRate )
-        AIL_set_sample_playback_rate(channel->hSample, sPlaybackRate);
+        AIL_set_sample_playback_rate(pMixerChannels[v62].hSample, sPlaybackRate);
       if (object_type == OBJECT_Player)
-        AIL_sample_ms_position(channel->hSample, &sLastTrackLengthMS, 0);
-      return;
+        AIL_sample_ms_position(pMixerChannels[v62].hSample, &sLastTrackLengthMS, 0);
+      return; 
   }
-
+  else
+  {
   __debugbreak(); // 3d sound stuff, refactor
   v12 = 13;
   if ( a3 < 0 )
@@ -1356,6 +1417,7 @@
       goto LABEL_101;
     }
   }
+  }
 }
 
 //----- (0040DEA5) --------------------------------------------------------
@@ -1373,7 +1435,7 @@
   //unsigned __int8 v3; // zf@1
   //int *v4; // eax@2
   //unsigned __int8 v5; // sf@4
-  AudioPlayer_3DSample *v6; // esi@5
+  //AudioPlayer_3DSample *v6; // esi@5
   int v7; // ebx@6
   int v8; // ebx@9
   int v9; // ebx@10
@@ -1437,164 +1499,368 @@
   if (!bPlayerReady)
     return;
   
-  if (field_2D0_time_left <= pEventTimer->uTimeElapsed)
-    field_2D0_time_left = 32;
-  else
+  //if (field_2D0_time_left <= pEventTimer->uTimeElapsed)
+    //field_2D0_time_left = 32;
+  //else
+  //{
+    //field_2D0_time_left -= pEventTimer->uTimeElapsed;
+    //return;
+  //}
+  field_2D0_time_left -= pEventTimer->uTimeElapsed;
+  if ( field_2D0_time_left <= 0 )
   {
-    field_2D0_time_left -= pEventTimer->uTimeElapsed;
-    return;
-  }
-
   //v3 = this->b3DSoundInitialized == 0;
-  if ( b3DSoundInitialized )
+  field_2D0_time_left = 32;
+  if ( b3DSoundInitialized )//for 3D sound
   {
     __debugbreak(); // refactor refactor
     //v3 = this->uNum3DSamples == 0;
     //v5 = this->uNum3DSamples < 0;
-    v59 = 0;
-    if (uNum3DSamples > 0)
+    
+    //if (uNum3DSamples > 0)
+    //{
+    //v6 = this->p3DSamples;
+    v2 = 0;
+    //while ( 1 )
+    for ( v59 = 0; v59 < pAudioPlayer->uNum3DSamples; ++v59 )
     {
-      v6 = this->p3DSamples;
-      while ( 1 )
+      v7 = PID_TYPE(this->p3DSamples[v59].field_4);
+      if ( AIL_3D_sample_status(this->p3DSamples[v59].hSample) == 2 )
       {
-        v7 = PID_TYPE(v6->field_4);
-        if ( AIL_3D_sample_status(v6->hSample) == 2 )
-        {
-          AIL_end_3D_sample(v6->hSample);
-          pAudioPlayer->_4ABF23(v6);
-        }
-        if ( AIL_3D_sample_status(v6->hSample) != 4 )
-          goto LABEL_35;
-        v8 = v7 - 1;//
-        if ( v8 )//> 1
-          break;
-        if ( uCurrentlyLoadedLevelType != LEVEL_Indoor )//==1
-          goto LABEL_31;
-        pDoor = &pIndoor->pDoors[PID_ID(v6->field_4)];
-        if ( pDoor->uDoorID )
-        {
-          uNumRepeats = *pDoor->pXOffsets;
-          a1.vWorldPosition.x = (double)uNumRepeats;
-          uNumRepeats = *pDoor->pYOffsets;
-          a1.vWorldPosition.y = (double)uNumRepeats;
-          uNumRepeats = *pDoor->pZOffsets;
-          v11 = (double)uNumRepeats;
-          goto LABEL_21;
-        }
-LABEL_35:
-        ++v59;
-        ++v6;
-        if ( v59 >= pAudioPlayer->uNum3DSamples )
-        {
-          v2 = 0;
-          goto LABEL_37;
-        }
+        AIL_end_3D_sample(this->p3DSamples[v59].hSample);
+        pAudioPlayer->_4ABF23(&this->p3DSamples[v59]);
       }
-
-      v9 = v8 - 1;//
-      if ( v9 )//> 2
+      if ( AIL_3D_sample_status(this->p3DSamples[v59].hSample) != 4 )
+        continue;
+      v8 = v7 - 1;//
+      if ( v8 )//> 1
       {
-        v10 = v9 - 1;//
-        if ( !v10 )//3
-        {
-          v13 = &pActors[PID_ID(v6->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;
-          goto LABEL_21;
-        }
-        if ( v10 != 2 )//4
+        v9 = v8 - 1;//
+        if ( v9 )//> 2
         {
-          a1.vWorldPosition.x = (double)pParty->vPosition.x;
-          a1.vWorldPosition.y = (double)pParty->vPosition.y;
-          v11 = (double)pParty->sEyelevel + (double)pParty->vPosition.z;
-          goto LABEL_21;
-        }//5
-        v12 = (SpriteObject *)&pLevelDecorations[PID_ID(v6->field_4)];
-      }
-      else//2
-      {
-        v12 = &pSpriteObjects[PID_ID(v6->field_4)];
-      }
-      a1.vWorldPosition.x = (double)v12->vPosition.x;
-      a1.vWorldPosition.y = (double)v12->vPosition.y;
-      v11 = (double)v12->vPosition.z;
-LABEL_21:
-      a1.vWorldPosition.z = v11;
-      if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
-      {
-        v16 = pGame->pIndoorCameraD3D->fRotationXCosine;
-        v17 = pGame->pIndoorCameraD3D->fRotationXSine;
-        v55 = pGame->pIndoorCameraD3D->fRotationYCosine;
-        v56 = pGame->pIndoorCameraD3D->fRotationYSine;
-        if (pGame->pIndoorCameraD3D->sRotationX)
+          v10 = v9 - 1;//
+          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;
+            if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+            {
+              v16 = pGame->pIndoorCameraD3D->fRotationXCosine;
+              v17 = pGame->pIndoorCameraD3D->fRotationXSine;
+              v55 = pGame->pIndoorCameraD3D->fRotationYCosine;
+              v56 = pGame->pIndoorCameraD3D->fRotationYSine;
+              if (pGame->pIndoorCameraD3D->sRotationX)
+              {
+                v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
+                *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
+                v18 = a1.vWorldPosition.z - (double)pParty->vPosition.z;
+                if ( pRenderer->pRenderD3D )
+                {
+                  v19 = *(float *)&uNumRepeats * v56 + v58 * v55;
+                  v20 = v58 * v56 - *(float *)&uNumRepeats * v55;
+                }
+                else
+                {
+                  v19 = v58 * v55 - *(float *)&uNumRepeats * v56;
+                  v20 = v58 * v56 + *(float *)&uNumRepeats * v55;
+                }
+                a1.vWorldViewPosition.x = v19 * v16 - v18 * v17;
+                a1.vWorldViewPosition.y = v20;
+                a1.vWorldViewPosition.z = v19 * v17 + v18 * v16;
+              }
+              else
+              {
+                v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
+                *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
+                if ( pRenderer->pRenderD3D )
+                {
+                  a1.vWorldViewPosition.x = *(float *)&uNumRepeats * v56 + v58 * v55;
+                  v21 = v58 * v56 - *(float *)&uNumRepeats * v55;
+                }
+                else
+                {
+                  a1.vWorldViewPosition.x = v58 * v55 - *(float *)&uNumRepeats * v56;
+                  v21 = v58 * v56 + *(float *)&uNumRepeats * v55;
+                }
+                a1.vWorldViewPosition.y = v21;
+                a1.vWorldViewPosition.z = a1.vWorldPosition.z - (double)pParty->vPosition.z;
+              }
+            }
+            else
+              pGame->pIndoorCameraD3D->ViewTransform(&a1, 1);
+            v58 = a1.vWorldViewPosition.y * -0.012207031;
+            v22 = a1.vWorldViewPosition.x * 0.012207031;
+            *(float *)&uNumRepeats = v22;
+            v23 = abs((signed __int64)v22);
+            v24 = abs(0);
+            v25 = abs((signed __int64)v58);
+            if ( int_get_vector_length(v25, v24, v23) <= 100 )
+            {
+              AIL_set_3D_position(this->p3DSamples[v59].hSample, LODWORD(v58), 0.0, uNumRepeats);
+              v26 = -*(float *)&uNumRepeats;
+              v27 = -v58;
+              AIL_set_3D_orientation(this->p3DSamples[v59].hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0);
+            }
+            else
+            {
+              AIL_end_3D_sample(this->p3DSamples[v59].hSample);
+              pAudioPlayer->_4ABF23(&this->p3DSamples[v59]);
+            }
+            continue;
+          }
+          if ( v10 != 2 )//4
+          {
+            a1.vWorldPosition.x = (double)pParty->vPosition.x;
+            a1.vWorldPosition.y = (double)pParty->vPosition.y;
+            v11 = (double)pParty->sEyelevel + (double)pParty->vPosition.z;
+            a1.vWorldPosition.z = v11;
+            if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+            {
+              v16 = pGame->pIndoorCameraD3D->fRotationXCosine;
+              v17 = pGame->pIndoorCameraD3D->fRotationXSine;
+              v55 = pGame->pIndoorCameraD3D->fRotationYCosine;
+              v56 = pGame->pIndoorCameraD3D->fRotationYSine;
+              if (pGame->pIndoorCameraD3D->sRotationX)
+              {
+                v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
+                *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
+                v18 = a1.vWorldPosition.z - (double)pParty->vPosition.z;
+                if ( pRenderer->pRenderD3D )
+                {
+                  v19 = *(float *)&uNumRepeats * v56 + v58 * v55;
+                  v20 = v58 * v56 - *(float *)&uNumRepeats * v55;
+                }
+                else
+                {
+                  v19 = v58 * v55 - *(float *)&uNumRepeats * v56;
+                  v20 = v58 * v56 + *(float *)&uNumRepeats * v55;
+                }
+                a1.vWorldViewPosition.x = v19 * v16 - v18 * v17;
+                a1.vWorldViewPosition.y = v20;
+                a1.vWorldViewPosition.z = v19 * v17 + v18 * v16;
+              }
+              else
+              {
+                v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
+                *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
+                if ( pRenderer->pRenderD3D )
+                {
+                  a1.vWorldViewPosition.x = *(float *)&uNumRepeats * v56 + v58 * v55;
+                  v21 = v58 * v56 - *(float *)&uNumRepeats * v55;
+                }
+                else
+                {
+                  a1.vWorldViewPosition.x = v58 * v55 - *(float *)&uNumRepeats * v56;
+                  v21 = v58 * v56 + *(float *)&uNumRepeats * v55;
+                }
+                a1.vWorldViewPosition.y = v21;
+                a1.vWorldViewPosition.z = a1.vWorldPosition.z - (double)pParty->vPosition.z;
+              }
+            }
+            else
+              pGame->pIndoorCameraD3D->ViewTransform(&a1, 1);
+            v58 = a1.vWorldViewPosition.y * -0.012207031;
+            v22 = a1.vWorldViewPosition.x * 0.012207031;
+            *(float *)&uNumRepeats = v22;
+            v23 = abs((signed __int64)v22);
+            v24 = abs(0);
+            v25 = abs((signed __int64)v58);
+            if ( int_get_vector_length(v25, v24, v23) <= 100 )
+            {
+              AIL_set_3D_position(this->p3DSamples[v59].hSample, LODWORD(v58), 0.0, uNumRepeats);
+              v26 = -*(float *)&uNumRepeats;
+              v27 = -v58;
+              AIL_set_3D_orientation(this->p3DSamples[v59].hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0);
+            }
+            else
+            {
+              AIL_end_3D_sample(this->p3DSamples[v59].hSample);
+              pAudioPlayer->_4ABF23(&this->p3DSamples[v59]);
+            }
+            continue;
+          }//5
+          v12 = (SpriteObject *)&pLevelDecorations[PID_ID(this->p3DSamples[v59].field_4)];
+        }
+        else//2
+          v12 = &pSpriteObjects[PID_ID(this->p3DSamples[v59].field_4)];
+        a1.vWorldPosition.x = (double)v12->vPosition.x;
+        a1.vWorldPosition.y = (double)v12->vPosition.y;
+        v11 = (double)v12->vPosition.z;
+//LABEL_21:
+        a1.vWorldPosition.z = v11;
+        if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
         {
-          v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
-          *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
-          v18 = a1.vWorldPosition.z - (double)pParty->vPosition.z;
-          if ( pRenderer->pRenderD3D )
+          v16 = pGame->pIndoorCameraD3D->fRotationXCosine;
+          v17 = pGame->pIndoorCameraD3D->fRotationXSine;
+          v55 = pGame->pIndoorCameraD3D->fRotationYCosine;
+          v56 = pGame->pIndoorCameraD3D->fRotationYSine;
+          if (pGame->pIndoorCameraD3D->sRotationX)
           {
-            v19 = *(float *)&uNumRepeats * v56 + v58 * v55;
-            v20 = v58 * v56 - *(float *)&uNumRepeats * v55;
+            v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
+            *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
+            v18 = a1.vWorldPosition.z - (double)pParty->vPosition.z;
+            if ( pRenderer->pRenderD3D )
+            {
+              v19 = *(float *)&uNumRepeats * v56 + v58 * v55;
+              v20 = v58 * v56 - *(float *)&uNumRepeats * v55;
+            }
+            else
+            {
+              v19 = v58 * v55 - *(float *)&uNumRepeats * v56;
+              v20 = v58 * v56 + *(float *)&uNumRepeats * v55;
+            }
+            a1.vWorldViewPosition.x = v19 * v16 - v18 * v17;
+            a1.vWorldViewPosition.y = v20;
+            a1.vWorldViewPosition.z = v19 * v17 + v18 * v16;
           }
           else
           {
-            v19 = v58 * v55 - *(float *)&uNumRepeats * v56;
-            v20 = v58 * v56 + *(float *)&uNumRepeats * v55;
+            v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
+            *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
+            if ( pRenderer->pRenderD3D )
+            {
+              a1.vWorldViewPosition.x = *(float *)&uNumRepeats * v56 + v58 * v55;
+              v21 = v58 * v56 - *(float *)&uNumRepeats * v55;
+            }
+            else
+            {
+              a1.vWorldViewPosition.x = v58 * v55 - *(float *)&uNumRepeats * v56;
+              v21 = v58 * v56 + *(float *)&uNumRepeats * v55;
+            }
+            a1.vWorldViewPosition.y = v21;
+            a1.vWorldViewPosition.z = a1.vWorldPosition.z - (double)pParty->vPosition.z;
           }
-          a1.vWorldViewPosition.x = v19 * v16 - v18 * v17;
-          a1.vWorldViewPosition.y = v20;
-          a1.vWorldViewPosition.z = v19 * v17 + v18 * v16;
+        }
+        else
+          pGame->pIndoorCameraD3D->ViewTransform(&a1, 1);
+        v58 = a1.vWorldViewPosition.y * -0.012207031;
+        v22 = a1.vWorldViewPosition.x * 0.012207031;
+        *(float *)&uNumRepeats = v22;
+        v23 = abs((signed __int64)v22);
+        v24 = abs(0);
+        v25 = abs((signed __int64)v58);
+        if ( int_get_vector_length(v25, v24, v23) <= 100 )
+        {
+          AIL_set_3D_position(this->p3DSamples[v59].hSample, LODWORD(v58), 0.0, uNumRepeats);
+          v26 = -*(float *)&uNumRepeats;
+          v27 = -v58;
+          AIL_set_3D_orientation(this->p3DSamples[v59].hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0);
         }
         else
         {
-          v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
-          *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
-          if ( pRenderer->pRenderD3D )
+          AIL_end_3D_sample(this->p3DSamples[v59].hSample);
+          pAudioPlayer->_4ABF23(&this->p3DSamples[v59]);
+        }
+        continue;
+      }
+      if ( uCurrentlyLoadedLevelType != LEVEL_Indoor )//==1
+      {
+        pGame->pIndoorCameraD3D->ViewTransform(&a1, 1);
+        v58 = a1.vWorldViewPosition.y * -0.012207031;
+        v22 = a1.vWorldViewPosition.x * 0.012207031;
+        *(float *)&uNumRepeats = v22;
+        v23 = abs((signed __int64)v22);
+        v24 = abs(0);
+        v25 = abs((signed __int64)v58);
+        if ( int_get_vector_length(v25, v24, v23) <= 100 )
+        {
+          AIL_set_3D_position(this->p3DSamples[v59].hSample, LODWORD(v58), 0.0, uNumRepeats);
+          v26 = -*(float *)&uNumRepeats;
+          v27 = -v58;
+          AIL_set_3D_orientation(this->p3DSamples[v59].hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0);
+        }
+        else
+        {
+          AIL_end_3D_sample(this->p3DSamples[v59].hSample);
+          pAudioPlayer->_4ABF23(&this->p3DSamples[v59]);
+        }
+        continue;
+      }
+      pDoor = &pIndoor->pDoors[PID_ID(this->p3DSamples[v59].field_4)];
+      if ( pDoor->uDoorID )
+      {
+        uNumRepeats = *pDoor->pXOffsets;
+        a1.vWorldPosition.x = (double)uNumRepeats;
+        uNumRepeats = *pDoor->pYOffsets;
+        a1.vWorldPosition.y = (double)uNumRepeats;
+        uNumRepeats = *pDoor->pZOffsets;
+        v11 = (double)uNumRepeats;
+        a1.vWorldPosition.z = v11;
+        if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+        {
+          v16 = pGame->pIndoorCameraD3D->fRotationXCosine;
+          v17 = pGame->pIndoorCameraD3D->fRotationXSine;
+          v55 = pGame->pIndoorCameraD3D->fRotationYCosine;
+          v56 = pGame->pIndoorCameraD3D->fRotationYSine;
+          if (pGame->pIndoorCameraD3D->sRotationX)
           {
-            a1.vWorldViewPosition.x = *(float *)&uNumRepeats * v56 + v58 * v55;
-            v21 = v58 * v56 - *(float *)&uNumRepeats * v55;
+            v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
+            *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
+            v18 = a1.vWorldPosition.z - (double)pParty->vPosition.z;
+            if ( pRenderer->pRenderD3D )
+            {
+              v19 = *(float *)&uNumRepeats * v56 + v58 * v55;
+              v20 = v58 * v56 - *(float *)&uNumRepeats * v55;
+            }
+            else
+            {
+              v19 = v58 * v55 - *(float *)&uNumRepeats * v56;
+              v20 = v58 * v56 + *(float *)&uNumRepeats * v55;
+            }
+            a1.vWorldViewPosition.x = v19 * v16 - v18 * v17;
+            a1.vWorldViewPosition.y = v20;
+            a1.vWorldViewPosition.z = v19 * v17 + v18 * v16;
           }
           else
           {
-            a1.vWorldViewPosition.x = v58 * v55 - *(float *)&uNumRepeats * v56;
-            v21 = v58 * v56 + *(float *)&uNumRepeats * v55;
+            v58 = a1.vWorldPosition.x - (double)pParty->vPosition.x;
+            *(float *)&uNumRepeats = a1.vWorldPosition.y - (double)pParty->vPosition.y;
+            if ( pRenderer->pRenderD3D )
+            {
+              a1.vWorldViewPosition.x = *(float *)&uNumRepeats * v56 + v58 * v55;
+              v21 = v58 * v56 - *(float *)&uNumRepeats * v55;
+            }
+            else
+            {
+              a1.vWorldViewPosition.x = v58 * v55 - *(float *)&uNumRepeats * v56;
+              v21 = v58 * v56 + *(float *)&uNumRepeats * v55;
+            }
+            a1.vWorldViewPosition.y = v21;
+            a1.vWorldViewPosition.z = a1.vWorldPosition.z - (double)pParty->vPosition.z;
           }
-          a1.vWorldViewPosition.y = v21;
-          a1.vWorldViewPosition.z = a1.vWorldPosition.z - (double)pParty->vPosition.z;
+        }
+        else
+          pGame->pIndoorCameraD3D->ViewTransform(&a1, 1);
+        v58 = a1.vWorldViewPosition.y * -0.012207031;
+        v22 = a1.vWorldViewPosition.x * 0.012207031;
+        *(float *)&uNumRepeats = v22;
+        v23 = abs((signed __int64)v22);
+        v24 = abs(0);
+        v25 = abs((signed __int64)v58);
+        if ( int_get_vector_length(v25, v24, v23) <= 100 )
+        {
+          AIL_set_3D_position(this->p3DSamples[v59].hSample, LODWORD(v58), 0.0, uNumRepeats);
+          v26 = -*(float *)&uNumRepeats;
+          v27 = -v58;
+          AIL_set_3D_orientation(this->p3DSamples[v59].hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0);
+        }
+        else
+        {
+          AIL_end_3D_sample(this->p3DSamples[v59].hSample);
+          pAudioPlayer->_4ABF23(&this->p3DSamples[v59]);
         }
       }
-      else
-      {
-LABEL_31:
-        pGame->pIndoorCameraD3D->ViewTransform(&a1, 1u);
-      }
-      v58 = a1.vWorldViewPosition.y * -0.012207031;
-      v22 = a1.vWorldViewPosition.x * 0.012207031;
-      *(float *)&uNumRepeats = v22;
-      v23 = abs((signed __int64)v22);
-      v24 = abs(0);
-      v25 = abs((signed __int64)v58);
-      if ( int_get_vector_length(v25, v24, v23) <= 100 )
-      {
-        AIL_set_3D_position(v6->hSample, LODWORD(v58), 0.0, uNumRepeats);
-        v26 = -*(float *)&uNumRepeats;
-        v27 = -v58;
-        AIL_set_3D_orientation(v6->hSample, LODWORD(v27), 0.0, LODWORD(v26), 0.0, 1.0, 0.0);
-      }
-      else
-      {
-        AIL_end_3D_sample(v6->hSample);
-        pAudioPlayer->_4ABF23(v6);
-      }
-      goto LABEL_35;
     }
+    //}
   }
 
-LABEL_37:
+//LABEL_37:
   for (uint i = 0; i < uMixerChannels; ++i)
   {
     if (AIL_sample_status(pMixerChannels[i].hSample) == AIL::Sample::Done)
@@ -1683,8 +1949,6 @@
     }
   }
 
-
-
   if (pCurrentScreen != SCREEN_GAME)
   {
     MixerChannel* channel = &pMixerChannels[4];
@@ -1725,9 +1989,9 @@
         uNumRepeats = 2;
         if (decor->field_1A)
         {
-          v51 = decor->field_1A - 32;
-          decor->field_1A = v51;
-          if ( v51 < 0 )
+          //v51 = decor->field_1A - 32;
+          decor->field_1A = decor->field_1A - 32;
+          if ( decor->field_1A < 0 )
             decor->field_1A = 0;
         }
     }
@@ -1743,7 +2007,7 @@
           {
             v53 = 8 * _6807B8_level_decorations_ids[i];
             LOBYTE(v53) = v53 | OBJECT_Decoration;
-            PlaySound((SoundID)decor_desc->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0);
+            PlaySound((SoundID)decor_desc->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0);//звуки корабля, плескания воды
           }
           continue;
         }
@@ -1799,6 +2063,7 @@
     }
     continue;
   }
+  }
 }
 
 //----- (004AB66C) --------------------------------------------------------
@@ -1835,37 +2100,27 @@
 //----- (004AB71F) --------------------------------------------------------
 void AudioPlayer::StopChannels(int uStartChannel, int uEndChannel)
 {
-  int v4; // ecx@1
-  int v9; // [sp+4h] [bp-4h]@3
-
   if ( bPlayerReady )
   {
     if ( b3DSoundInitialized )
     {
-      v9 = 0;
-      if ( uNum3DSamples > 0 )
+      for ( uint i = 0; i < uNum3DSamples; ++i )
       {
-        for ( v4 = 0; v4 < uNum3DSamples; ++v4 )
+        if ( (uStartChannel == -1 || i < uStartChannel || i > uEndChannel)
+            && p3DSamples[i].field_8 && pSoundList->pSounds[p3DSamples[i].field_8].eType != SOUND_DESC_SYSTEM)
         {
-          if ( (uStartChannel == -1 || v4 < uStartChannel || v4 > uEndChannel)
-              && p3DSamples[v4].field_8
-              && pSoundList->pSounds[p3DSamples[v4].field_8].eType != SOUND_DESC_SYSTEM)
-          {
-            AIL_end_3D_sample(p3DSamples[v4].hSample);
-            _4ABF23(&p3DSamples[v4]);
-            p3DSamples[v4].field_4 = 0;
-            v4 = v9;
-          }
-          v9 = v4;
+          AIL_end_3D_sample(p3DSamples[i].hSample);
+          _4ABF23(&p3DSamples[i]);
+          p3DSamples[i].field_4 = 0;
         }
       }
     }
-    if ( hDigDriver && uMixerChannels > 0 )
+    if ( hDigDriver )
     {
       for ( int i = 0; i < uMixerChannels; ++i )
       {
         if ( (uStartChannel == -1 || i < uStartChannel || i > uEndChannel)
-          && pSoundList->pSounds[pMixerChannels[i].uSourceTrackIdx].eType != SOUND_DESC_SYSTEM)
+          && pSoundList->pSounds[pMixerChannels[i].uSourceTrackIdx].eType != SOUND_DESC_SYSTEM)//все, кроме системных звуков, отключаются
         {
           AIL_end_sample(pMixerChannels[i].hSample);
           FreeChannel(&pMixerChannels[i]);
@@ -2226,7 +2481,7 @@
 {
   int v2; // ebx@1
   //AudioPlayer *v3; // esi@1
-  SoundDesc *v4; // eax@2
+  //SoundDesc *v4; // eax@2
   unsigned __int8 v5; // zf@5
   unsigned __int8 v6; // sf@5
   char *v7; // edi@6
@@ -2239,14 +2494,12 @@
   int v14; // [sp+4Ch] [bp-8h]@5
   int v15; // [sp+50h] [bp-4h]@5
 
-  v2 = 0;
-  //v3 = this;
   if ( pSoundList->pSounds )
   {
-    v4 = &pSoundList->pSounds[a2->field_8];
-    if ( v4->eType == SOUND_DESC_SWAP)
+    //v4 = &pSoundList->pSounds[a2->field_8];
+    if ( pSoundList->pSounds[a2->field_8].eType == SOUND_DESC_SWAP)
     {
-      if ( v4->p3DSound && !(v4->uFlags & SOUND_DESC_SYSTEM) )
+      if ( pSoundList->pSounds[a2->field_8].p3DSound && !(pSoundList->pSounds[a2->field_8].uFlags & SOUND_DESC_SYSTEM) )
       {
         v5 = this->uNum3DSamples == 0;
         v6 = this->uNum3DSamples < 0;
@@ -2255,37 +2508,29 @@
         if ( v6 | v5 )
           goto LABEL_16;
         v7 = (char *)this->p3DSamples;
-        do
+        __debugbreak();//Ritor1
+        for ( v2 = 0; v2 < uNum3DSamples; ++v2 )
         {
           if ( a2->field_C == *((int *)v7 + 3) )
           {
             v8 = v15;
-            v9 = *(int *)v7;
+            //v9 = this->p3DSamples[v2];
             ++v15;
             v13[v8] = v2;
-            if ( AIL_3D_sample_status((void *)v9) == 4 )
+            if ( AIL_3D_sample_status(&this->p3DSamples[v2]) == 4 )
               ++v14;
           }
-          ++v2;
           v7 += 16;
         }
-        while ( v2 < uNum3DSamples );
         if ( !v14 )
         {
 LABEL_16:
           pSoundList->UnloadSound(a2->field_8, 1);
-          v10 = 0;
-          if ( v15 > 0 )
+          for ( v10 = 0; v10 < v15; v10++ )
           {
-            do
-            {
-              v11 = v13[v10++];
-              *(&bEAXSupported + 4 * (v11 + 2)) = 0;
-              v12 = __OFSUB__(v10, v15);
-              v6 = v10 - v15 < 0;
-              p3DSamples[v11].field_8 = 0;
-            }
-            while ( v6 ^ v12 );
+            v11 = v13[v10];
+            *(&bEAXSupported + 4 * (v11 + 2)) = 0;
+            p3DSamples[v11].field_8 = 0;
           }
         }
       }
@@ -2345,71 +2590,61 @@
 //----- (004AC0A2) --------------------------------------------------------
 int AudioPlayer::_4AC0A2()
 {
-  AudioPlayer *v1; // esi@1
-  unsigned int v2; // eax@1
-  char v3; // zf@1
-  int v4; // ebx@1
-  int *v5; // edi@2
-  int v6; // eax@4
-  AudioPlayer_3DSample *v8; // ebx@7
+  unsigned int map_id; // eax@1
+  //int v4; // ebx@1
+  //int *v5; // edi@2
+  //int v6; // eax@4
+  //AudioPlayer_3DSample *v8; // ebx@7
   void *v9; // eax@8
-  int v10; // ebx@14
-  unsigned int v11; // eax@14
+  //int v10; // ebx@14
+  //unsigned int v11; // eax@14
   int v12; // [sp+1Ch] [bp-8h]@1
-  int v13; // [sp+20h] [bp-4h]@6
+  //int v13; // [sp+20h] [bp-4h]@6
 
-  v1 = this;
-  v2 = pMapStats->GetMapInfo(pCurrentMapName);
-  v3 = v1->b3DSoundInitialized == 0;
-  v4 = v2;
-  v12 = v2;
-  if ( !v3 )
+  __debugbreak();//Ritor1
+  map_id = pMapStats->GetMapInfo(pCurrentMapName);
+  if ( this->b3DSoundInitialized )
   {
-    v5 = &v1->uNum3DSamples;
-    AIL_3D_provider_attribute(v1->h3DSoundProvider, "Maximum supported samples", &v1->uNum3DSamples);
-    if ( v1->uNum3DSamples > 32 )
-      *v5 = 32;
-    v6 = *v5;
-    if ( !*v5 )
+    //v5 = &this->uNum3DSamples;
+    AIL_3D_provider_attribute(this->h3DSoundProvider, "Maximum supported samples", &this->uNum3DSamples);
+    if ( this->uNum3DSamples > 32 )
+      this->uNum3DSamples = 32;
+    //v6 = this->uNum3DSamples;
+    if ( !this->uNum3DSamples )
     {
-      v1->b3DSoundInitialized = 0;
+      this->b3DSoundInitialized = 0;
       return -1;
     }
-    v13 = 0;
-    if ( v6 > 0 )
-    {
-      v8 = v1->p3DSamples;
-      while ( 1 )
+    //v13 = 0;
+    //if ( this->uNum3DSamples > 0 )
+    //{
+      //v8 = this->p3DSamples;
+      //while ( 1 )
+      for ( uint i = 0; i < this->uNum3DSamples; ++i )
       {
-        v9 = (void *)AIL_allocate_3D_sample_handle(v1->h3DSoundProvider);
-        v8->hSample = v9;
+        v9 = (void *)AIL_allocate_3D_sample_handle(this->h3DSoundProvider);
+        this->p3DSamples[i].hSample = v9;
         if ( !v9 )
-          break;
+          this->uNum3DSamples = i;
         AIL_set_3D_sample_float_distances(v9, 4096.0, 256.0, 4096.0, 256.0);
-        AIL_set_3D_sample_volume(v8->hSample, v1->s3DSoundVolume);
-        ++v13;
-        ++v8;
-        if ( v13 >= *v5 )
-          goto LABEL_12;
+        AIL_set_3D_sample_volume(this->p3DSamples[i].hSample, this->s3DSoundVolume);
+        //++v8;
       }
-      *v5 = v13;
-LABEL_12:
-      v4 = v12;
-    }
-    if ( v1->bEAXSupported )
+    //}
+    if ( this->bEAXSupported )
     {
-      v10 = v4;
-      v11 = pMapStats->pInfos[v10].uEAXEnv;
-      v12 = pMapStats->pInfos[v10].uEAXEnv;
-      if ( v11 >= 0x1A )
+      //v10 = v4;
+      //v11 = pMapStats->pInfos[map_id].uEAXEnv;
+      v12 = pMapStats->pInfos[map_id].uEAXEnv;
+      if ( pMapStats->pInfos[map_id].uEAXEnv >= 0x1A )
       {
         pAudioPlayer->SetEAXPreferences();
-        v1->field_214 = -1;
+        this->field_214 = -1;
       }
       else
       {
-        AIL_set_3D_provider_preference(v1->h3DSoundProvider, "EAX environment selection", &v12);
-        v1->field_214 = v12;
+        AIL_set_3D_provider_preference(this->h3DSoundProvider, "EAX environment selection", &v12);
+        this->field_214 = v12;
       }
     }
   }
@@ -2419,7 +2654,8 @@
 //----- (004A96BE) --------------------------------------------------------
 void ReleaseSoundData(void *_this)
 {
-  for ( uint i = 0; (void *)&pSounds[i].pSoundData < (void *)&pSounds[2999].pSoundData; i++ )
+  //for ( uint i = 0; (void *)&pSounds[i].pSoundData < (void *)&pSounds[2999].pSoundData; i++ )
+  for ( uint i = 0; i < 2999; i++ )
   {
     if ( pSounds[i].pSoundData == _this )
     {
--- a/Events.cpp	Fri Dec 20 01:25:52 2013 +0100
+++ b/Events.cpp	Fri Dec 20 01:28:39 2013 +0100
@@ -1420,7 +1420,7 @@
         else
           {
           pGameLoadingUI_ProgressBar->uType = (GUIProgressBar::Type)((activeLevelDecoration == NULL) + 1);
-          sub_44987B(v99, MapStartPoint_Party);
+          Transition_StopSound_Autosave(v99, MapStartPoint_Party);
           v133 = 1;
           if ( pCurrentScreen == SCREEN_HOUSE )
             {
--- a/GUIWindow.h	Fri Dec 20 01:25:52 2013 +0100
+++ b/GUIWindow.h	Fri Dec 20 01:28:39 2013 +0100
@@ -231,16 +231,21 @@
   DIALOGUE_USE_NPC_ABILITY = 9,
   DIALOGUE_13 = 0xD,
   DIALOGUE_18 = 0x12,
-  DIALOGUE_19 = 19,
-  DIALOGUE_20 = 20,
-  DIALOGUE_21 = 21,
-  DIALOGUE_22 = 22,
-  DIALOGUE_23 = 23,
-  DIALOGUE_24 = 0x18,
+  DIALOGUE_EVT_A = 19,
+  DIALOGUE_EVT_B = 20,
+  DIALOGUE_EVT_C = 21,
+  DIALOGUE_EVT_D = 22,
+  DIALOGUE_EVT_E = 23,
+  DIALOGUE_EVT_F = 0x18,
   DIALOGUE_76 = 76,
   DIALOGUE_PROFESSION_DETAILS = 77,
-  DIALOGUE_ARENA_WELCOME = 0x59,
-  DIALOGUE_ARENA_FIGHT_NOT_OVER_YET = 0x5A,
+  DIALOGUE_84 = 84,
+  DIALOGUE_ARENA_SELECT_PAGE = 85,
+  DIALOGUE_ARENA_SELECT_SQUIRE = 86,
+  DIALOGUE_ARENA_SELECT_KNIGHT = 87,
+  DIALOGUE_ARENA_SELECT_CHAMPION = 88,
+  DIALOGUE_ARENA_WELCOME = 89,
+  DIALOGUE_ARENA_FIGHT_NOT_OVER_YET = 90,
   DIALOGUE_ARENA_REWARD = 0x5B,
   DIALOGUE_ARENA_ALREADY_WON = 0x5C,
 };
--- a/Game.cpp	Fri Dec 20 01:25:52 2013 +0100
+++ b/Game.cpp	Fri Dec 20 01:28:39 2013 +0100
@@ -2772,7 +2772,7 @@
               pGameLoadingUI_ProgressBar->uType = (GUIProgressBar::Type)2;
               dword_5B65C0 = _5B65A8_npcdata_uflags_or_other | _5B65AC_npcdata_fame_or_other | _5B65B0_npcdata_rep_or_other | _5B65B4_npcdata_loword_house_or_other | _5B65B8_npcdata_hiword_house_or_other | v38;
               OnMapLeave();
-              sub_44987B(dword_591164_teleport_map_name, MapStartPoint_Party);
+              Transition_StopSound_Autosave(dword_591164_teleport_map_name, MapStartPoint_Party);
             }
           }
           else
--- a/Indoor.cpp	Fri Dec 20 01:25:52 2013 +0100
+++ b/Indoor.cpp	Fri Dec 20 01:28:39 2013 +0100
@@ -7150,4 +7150,98 @@
     pParty->uFlags |= 0x200;
   if (uFaceEvent)
     EventProcessor(uFaceEvent, 0, 1);
+}
+
+//----- (00449A49) --------------------------------------------------------
+void Door_switch_animation(unsigned int uDoorID, int a2)
+{
+  int old_state; // eax@1
+  signed int door_id; // esi@2
+
+  if ( !pIndoor->pDoors )
+    return;
+  for ( door_id = 0; door_id < 200; ++door_id )
+  {
+    if ( pIndoor->pDoors[door_id].uDoorID == uDoorID )
+      break;
+  }
+  if ( door_id >= 200 )
+  {
+    Error("Unable to find Door ID: %i!", uDoorID);
+  }
+  old_state = pIndoor->pDoors[door_id].uState;
+  //old_state: 0 - в нижнем положении/закрыто
+  //           2 - в верхнем положении/открыто,
+  //a2: 1 - открыть
+  //    2 - опустить/поднять
+  if ( a2 == 2 )
+  {
+    if ( pIndoor->pDoors[door_id].uState == BLVDoor::Closing || pIndoor->pDoors[door_id].uState == BLVDoor::Opening )
+      return;
+    if ( pIndoor->pDoors[door_id].uState )
+    {
+      if ( pIndoor->pDoors[door_id].uState != BLVDoor::Closed && pIndoor->pDoors[door_id].uState != BLVDoor::Closing )
+      {
+        pIndoor->pDoors[door_id].uState = BLVDoor::Closing;
+        if ( old_state == BLVDoor::Open )
+        {
+          pIndoor->pDoors[door_id].uTimeSinceTriggered = 0;
+          return;
+        }
+        if ( pIndoor->pDoors[door_id].uTimeSinceTriggered != 15360 )
+        {
+          pIndoor->pDoors[door_id].uTimeSinceTriggered = (pIndoor->pDoors[door_id].uMoveLength << 7) / pIndoor->pDoors[door_id].uOpenSpeed
+             - ((signed int)(pIndoor->pDoors[door_id].uTimeSinceTriggered * pIndoor->pDoors[door_id].uCloseSpeed)
+             / 128 << 7) / pIndoor->pDoors[door_id].uOpenSpeed;
+          return;
+        }
+        pIndoor->pDoors[door_id].uTimeSinceTriggered = 15360;
+      }
+      return;
+    }
+  }
+  else
+  {
+    if ( a2 == 0 )
+    {
+      if ( pIndoor->pDoors[door_id].uState != BLVDoor::Closed && pIndoor->pDoors[door_id].uState != BLVDoor::Closing )
+      {
+        pIndoor->pDoors[door_id].uState = BLVDoor::Closing;
+        if ( old_state == BLVDoor::Open )
+        {
+          pIndoor->pDoors[door_id].uTimeSinceTriggered = 0;
+          return;
+        }
+        if ( pIndoor->pDoors[door_id].uTimeSinceTriggered != 15360 )
+        {
+          pIndoor->pDoors[door_id].uTimeSinceTriggered = (pIndoor->pDoors[door_id].uMoveLength << 7) / pIndoor->pDoors[door_id].uOpenSpeed
+             - ((signed int)(pIndoor->pDoors[door_id].uTimeSinceTriggered * pIndoor->pDoors[door_id].uCloseSpeed)
+             / 128 << 7) / pIndoor->pDoors[door_id].uOpenSpeed;
+          return;
+        }
+        pIndoor->pDoors[door_id].uTimeSinceTriggered = 15360;
+      }
+      return;
+    }
+    if ( a2 != 1 )
+      return;
+  }
+  if ( old_state != BLVDoor::Open && old_state != BLVDoor::Opening )
+  {
+    pIndoor->pDoors[door_id].uState = BLVDoor::Opening;
+    if ( old_state == BLVDoor::Closed )
+    {
+      pIndoor->pDoors[door_id].uTimeSinceTriggered = 0;
+      return;
+    }
+    if ( pIndoor->pDoors[door_id].uTimeSinceTriggered != 15360 )
+    {
+      pIndoor->pDoors[door_id].uTimeSinceTriggered = (pIndoor->pDoors[door_id].uMoveLength << 7) / pIndoor->pDoors[door_id].uCloseSpeed
+         - ((signed int)(pIndoor->pDoors[door_id].uTimeSinceTriggered * pIndoor->pDoors[door_id].uOpenSpeed)
+         / 128 << 7) / pIndoor->pDoors[door_id].uCloseSpeed;
+      return;
+    }
+    pIndoor->pDoors[door_id].uTimeSinceTriggered = 15360;
+  }
+  return;
 }
\ No newline at end of file
--- a/MapInfo.h	Fri Dec 20 01:25:52 2013 +0100
+++ b/MapInfo.h	Fri Dec 20 01:28:39 2013 +0100
@@ -102,4 +102,4 @@
 
 
 void TeleportToStartingPoint(MapStartPoint point); // idb
-void sub_44987B(const char *pMapName, MapStartPoint point); // idb
\ No newline at end of file
+void Transition_StopSound_Autosave(const char *pMapName, MapStartPoint point); // sub_44987B idb
\ No newline at end of file
--- a/OSWindow.cpp	Fri Dec 20 01:25:52 2013 +0100
+++ b/OSWindow.cpp	Fri Dec 20 01:28:39 2013 +0100
@@ -331,7 +331,7 @@
           else
             pMiscTimer->Pause();
 
-          pAudioPlayer->StopChannels(-1, -1);
+          pAudioPlayer->StopChannels(-1, -1);//приостановка воспроизведения звуков при неактивном окне игры
           if ( pAudioPlayer->hAILRedbook )
             AIL_redbook_pause(pAudioPlayer->hAILRedbook);
         }
--- a/Outdoor.cpp	Fri Dec 20 01:25:52 2013 +0100
+++ b/Outdoor.cpp	Fri Dec 20 01:28:39 2013 +0100
@@ -4209,10 +4209,7 @@
   {
 	  if ( !bUnderwater && v34 <= 0)
 	  {
-		if ( v34 < -500
-		  && !pParty->bFlying
-		  && pParty->vPosition.z - v111 > 1000
-		  && !pParty->FeatherFallActive())
+		if ( v34 < -500 && !pParty->bFlying && pParty->vPosition.z - v111 > 1000 && !pParty->FeatherFallActive())
 		{ // falling scream
 		  for (int i = 0; i < 4; ++i)
 		  {
@@ -4258,9 +4255,9 @@
     if ( stru_721530._47050A(v36) )
       break;
     _46E889_collide_against_bmodels(1);
-    v37 = WorldPosToGridCellZ(pParty->vPosition.y);
-    v38 = WorldPosToGridCellX(pParty->vPosition.x);
-    _46E26D_collide_against_sprites(v38, v37);
+    //v37 = WorldPosToGridCellZ(pParty->vPosition.y);
+    //v38 = WorldPosToGridCellX(pParty->vPosition.x);
+    _46E26D_collide_against_sprites(WorldPosToGridCellX(pParty->vPosition.x), WorldPosToGridCellZ(pParty->vPosition.y));
     _46ED8A_collide_against_sprite_objects(4);
     for ( i = 0; i < (signed int)uNumActors; ++i )
       Actor::_46DF1A_collide_against_actor(i, 0);
--- a/Render.cpp	Fri Dec 20 01:25:52 2013 +0100
+++ b/Render.cpp	Fri Dec 20 01:28:39 2013 +0100
@@ -3561,16 +3561,11 @@
 }
 
 //----- (004A0BEE) --------------------------------------------------------
-char Render::RasterLine2D(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW, unsigned __int16 uColor)
-{
-  unsigned int v8; // ebx@5
-  unsigned int v10; // ecx@9
-  unsigned int v11; // esi@13
-  int v12; // eax@17
-  int v13; // eax@21
-  int v16; // eax@27
-  signed __int64 v19; // qax@41
-  int v20; // edi@41
+void Render::RasterLine2D(signed int uX, signed int uY, signed int uZ, signed int uW, unsigned __int16 uColor)
+{
+  signed int v12; // eax@17
+  //signed int v19; // qax@41
+  //int v20; // edi@41
   unsigned int v21; // edi@46
   int v22; // esi@47
   int v23; // ebx@47
@@ -3586,45 +3581,44 @@
   __int64 v36; // [sp+14h] [bp-8h]@1
   signed int v37; // [sp+18h] [bp-4h]@28
   unsigned int uXa; // [sp+24h] [bp+8h]@49
-  unsigned int uYa; // [sp+28h] [bp+Ch]@28
+  //unsigned int uYa; // [sp+28h] [bp+Ch]@28
   int uYb; // [sp+28h] [bp+Ch]@47
-  int uZa; // [sp+2Ch] [bp+10h]@38
+  //int uZa; // [sp+2Ch] [bp+10h]@38
+  bool left_border;
 
   v36 = 0i64;
-  if ( (signed int)uX < this->raster_clip_x )
-    HIDWORD(v36) = 8;
-  if ( (signed int)uX > this->raster_clip_z )
-    HIDWORD(v36) |= 4;
-
-  v8 = uY;
-  if ( (signed int)uY < this->raster_clip_y )
-    HIDWORD(v36) |= 2;
-  if ( (signed int)uY > this->raster_clip_w )
-    HIDWORD(v36) |= 1;
-
-  v10 = uZ;
-  if ( (signed int)uZ < this->raster_clip_x )
-    LODWORD(v36) = 8;
-  if ( (signed int)uZ > this->raster_clip_z )
-    LODWORD(v36) = v36 | 4;
-
-  v11 = uW;
-  if ( (signed int)uW < this->raster_clip_y )
-    LODWORD(v36) = v36 | 2;
-  if ( (signed int)uW > this->raster_clip_w )
-    LODWORD(v36) = v36 | 1;
-
-  LOBYTE(v12) = v36;
+  if ( uX < this->raster_clip_x )// x выходит за рамки левой границы
+    HIDWORD(v36) = 8; //left_border = true;
+  if ( uX > this->raster_clip_z )// x выходит за рамки правой границы
+    HIDWORD(v36) |= 4;//right_border = true;
+
+  if ( uZ < this->raster_clip_x )// z выходит за рамки левой границы
+    LODWORD(v36) = 8;//
+  if ( uZ > this->raster_clip_z )// z выходит за рамки правой границы
+    LODWORD(v36) |= 4;
+
+  if ( uY < this->raster_clip_y )// y выходит за рамки верхней границы
+    HIDWORD(v36) |= 2;//upper_border = true;
+  if ( uY > this->raster_clip_w )// y выходит за рамки нижней границы
+    HIDWORD(v36) |= 1;//bottom_border = true;
+
+  if ( uW < this->raster_clip_y )// w выходит за рамки верхней границы
+    LODWORD(v36) |= 2;
+  if ( uW > this->raster_clip_w )// w выходит за рамки нижней границы
+    LODWORD(v36) |= 1;
+
+  //LOBYTE(v12) = v36;
   if ( (unsigned int)v36 & HIDWORD(v36) )
-    return v12;
-  if ( !v36 )
+    return;
+
+  if ( !v36 ) //полностью в рамках
   {
 LABEL_46:
     v21 = pRenderer->uTargetSurfacePitch;
     if ( pRenderer->uTargetSurfacePitch )
     {
       v12 = uX + uY * pRenderer->uTargetSurfacePitch;
-      v22 = v11 - v8;
+      v22 = uW - uY;
       v23 = v22;
       uYb = v22;
       if ( v22 < 0 )
@@ -3633,7 +3627,7 @@
         uYb = -v22;
         v21 = -pRenderer->uTargetSurfacePitch;
       }
-      uXa = v10 - uX;
+      uXa = uZ - uX;
       if ( (uXa & 0x80000000u) == 0 )
       {
         v24 = 1;
@@ -3646,8 +3640,6 @@
       v25 = 0;
 
       v26 = (unsigned __int16 *)this->pTargetSurface;
-      int y = 0;
-      int x = 0;
       if ( v26 )
       {
         if ( (signed int)uXa <= v23 )//рисуем вертикальную линию
@@ -3658,6 +3650,8 @@
             v31 = 2 * v24;
             v32 = 2 * v21;
             v12 = (int)&v26[v12];
+            int y = 0;
+            int x = 0;
             for ( v30; v30; --v30 )
             {
               v25 += uXa;
@@ -3683,11 +3677,12 @@
         else//рисуем горизонтальную линию
         {
           v27 = uXa + 1;
-          int x = 0;
           if ( (signed int)(uXa + 1) > 0 )
           {
             v28 = 2 * v21;
             v29 = 2 * v24;
+            int y = 0;
+            int x = 0;
             v12 = (int)&v26[v12];
             for ( v27; v27; --v27 )
             {
@@ -3713,87 +3708,80 @@
         }
       }
     }
-    return v12;
-  }
-  if ( (BYTE4(v36) ^ (unsigned __int8)v36) & 8 )
-  {
-    if ( BYTE4(v36) & 8 )
-    {
-      v13 = (signed int)((uW - uY) * (this->raster_clip_x - uX)) / (signed int)(uZ - uX);
-      v8 = v13 + uY;
+    return;
+  }
+
+  if ( (BYTE4(v36) ^ (unsigned __int8)v36) & 8 )//левая и 
+  {
+    if ( BYTE4(v36) & 8 )//left_border = true;
+    {
+      uY += ((uW - uY) * (this->raster_clip_x - uX)) / (uZ - uX);
       uX = this->raster_clip_x;
-      goto LABEL_24;
-    }
-    v10 = this->raster_clip_x;
-    v11 = (signed int)((uY - uW) * (this->raster_clip_x - uZ)) / (signed int)(uX - uZ) + uW;
-  }
-LABEL_24:
+    }
+    else
+    {
+      uZ = this->raster_clip_x;
+      uW += ((uY - uW) * (this->raster_clip_x - uZ)) / (uX - uZ);
+    }
+  }
   if ( (BYTE4(v36) ^ (unsigned __int8)v36) & 4 )
   {
-    //v15 = this->raster_clip_z;
-    if ( BYTE4(v36) & 4 )
-    {
-      v8 += (signed int)((v11 - v8) * (this->raster_clip_z - uX)) / (signed int)(v10 - uX);
+    if ( BYTE4(v36) & 4 ) //right_border = true
+    {
+      uY += ((uW - uY) * (this->raster_clip_z - uX)) / (uZ - uX);
       uX = this->raster_clip_z;
     }
     else
     {
-      v16 = (signed int)((v8 - v11) * (this->raster_clip_z - v10)) / (signed int)(uX - v10);
-      v10 = this->raster_clip_z;
-      v11 += v16;
+      uW += ((uY - uW) * (this->raster_clip_z - uZ)) / (uX - uZ);
+      uY = this->raster_clip_z;
     }
   }
   v37 = 0;
-  uYa = this->raster_clip_y;
-  if ( (signed int)v8 < this->raster_clip_y )
+  if ( uY < this->raster_clip_y )
     v37 = 2;
-  if ( (signed int)v8 > this->raster_clip_w )
+  if ( uY > this->raster_clip_w )
     v37 |= 1;
-  if ( (signed int)v11 >= this->raster_clip_y )
+
+  if ( uW >= this->raster_clip_y )
     v12 = 0;
   else
     v12 = 2;
-  if ( (signed int)v11 > this->raster_clip_w )
-    LOBYTE(v12) = v12 | 1;
+  if ( uW > this->raster_clip_w )
+    v12 |= 1;
+
   if ( !(v12 & v37) )
   {
     v12 ^= v37;
-    uZa = v12;
     if ( v12 & 2 )
     {
       if ( v37 & 2 )
       {
-        uX += (signed int)((v10 - uX) * (uYa - v8)) / (signed int)(v11 - v8);
-        LOBYTE(v12) = (char)this;
-        v8 = this->raster_clip_y;
+        uX += ((uZ - uX) * (this->raster_clip_y - uY)) / (uW - uY);
+        uY = this->raster_clip_y;
       }
       else
       {
-        v19 = (signed int)((uX - v10) * (uYa - v11));
-        v20 = v8 - v11;
-        v11 = uYa;
-        v12 = v19 / v20;
-        v10 += v12;
-      }
-    }
-    if ( uZa & 1 )
+        uZ += (uX - uZ) * (this->raster_clip_y - uW) / (uY - uW);
+        uW = this->raster_clip_y;
+      }
+    }
+    if ( v12 & 1 )
     {
       if ( v37 & 1 )
       {
-        uX += (signed int)((v10 - uX) * (this->raster_clip_w - v8)) / (signed int)(v11 - v8);
-        LOBYTE(v12) = (char)this;
-        v8 = this->raster_clip_w;
+        uX += ((uZ - uX) * (this->raster_clip_w - uY)) / (uW - uY);
+        uY = this->raster_clip_w;
       }
       else
       {
-        v12 = (signed int)((uX - v10) * (this->raster_clip_w - v11)) / (signed int)(v8 - v11);
-        v11 = this->raster_clip_w;
-        v10 += v12;
+        uZ += ((uX - uZ) * (this->raster_clip_w - uW)) / (uY - uW);
+        uW = this->raster_clip_w;
       }
     }
     goto LABEL_46;
   }
-  return v12;
+  return;
 }
 
 //----- (004A0E80) --------------------------------------------------------
@@ -7838,7 +7826,7 @@
               {
                   if ( *v28 )
                   {
-                    v20 = *(&a5->pLevelOfDetail0_prolly_alpha_mask[i & a5->uWidthMinus1] + a5->uTextureWidth * (v27 & a5->uHeightMinus1));
+                    v20 = *(&a5->pLevelOfDetail0_prolly_alpha_mask[x & a5->uWidthMinus1] + a5->uTextureWidth * (v27 & a5->uHeightMinus1));
                     if ( v20 >= a7 )
                     {
                       if ( v20 <= a8 )
--- a/Render.h	Fri Dec 20 01:25:52 2013 +0100
+++ b/Render.h	Fri Dec 20 01:28:39 2013 +0100
@@ -292,7 +292,7 @@
   void CreateSomeTexture();
   bool InitializeFullscreen();
   bool SwitchToWindow();
-  char RasterLine2D(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW, unsigned __int16 uColor);
+  void RasterLine2D(signed int uX, signed int uY, signed int uZ, signed int uW, unsigned __int16 uColor);
   void ClearZBuffer(int a2, int a3);
   void SetRasterClipRect(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW);
   void ParseTargetPixelFormat();
--- a/SaveLoad.cpp	Fri Dec 20 01:25:52 2013 +0100
+++ b/SaveLoad.cpp	Fri Dec 20 01:28:39 2013 +0100
@@ -177,7 +177,7 @@
   {
     uchar uQuickspell = pParty->pPlayers[i].uQuickSpell;
     if (uQuickspell)
-      stru_AA1058[i]._494836(uQuickspell, i + 9 - 8);
+      stru_AA1058[i]._494836(uQuickspell, i + 1);
 
     for (uint j = 0; j < 2; ++j)
     {
--- a/Spells.cpp	Fri Dec 20 01:25:52 2013 +0100
+++ b/Spells.cpp	Fri Dec 20 01:28:39 2013 +0100
@@ -554,9 +554,9 @@
   a1.uType = stru_4E3ACC[uSpellID].uType;
   if ( uSpellID > 58 )
   {
-    if ( uSpellID == 69 )
+    if ( uSpellID == SPELL_BODY_PROTECTION_FROM_BODY )
       goto LABEL_117;
-    if ( uSpellID != 83 )
+    if ( uSpellID != SPELL_LIGHT_DAY_OF_THE_GODS )
       return;
     v40 = v15 - 2;
     if ( v40 )
@@ -574,7 +574,8 @@
         v37 = &pParty->pPartyBuffs[PARTY_BUFF_DAY_OF_GODS];
         v36 = pParty->uTimePlayed + v39;
         v37->Apply(v36, a7b, v43, 0, 0);
-        goto LABEL_139;
+        pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+        return;
       }
       if ( v41 == 1 )
       {
@@ -588,7 +589,8 @@
        v37 = &pParty->pPartyBuffs[PARTY_BUFF_DAY_OF_GODS];
        v36 = pParty->uTimePlayed + v39;
        v37->Apply(v36, a7b, v43, 0, 0);
-       goto LABEL_139;
+        pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+        return;
       }
     }
     v42 = 10800 * uSkill;
@@ -601,20 +603,21 @@
     v37 = &pParty->pPartyBuffs[PARTY_BUFF_DAY_OF_GODS];
     v36 = pParty->uTimePlayed + v39;
     v37->Apply(v36, a7b, v43, 0, 0);
-    goto LABEL_139;
+    pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+    return;
   }
   if ( uSpellID != 58 )
   {
     switch ( uSpellID )
     {
-      case 2:
-      case 6:
-      case 18:
-      case 26:
-      case 29:
-      case 32:
-      case 39:
-      case 41:
+      case SPELL_FIRE_FIRE_BOLT:
+      case SPELL_FIRE_FIREBALL:
+      case SPELL_AIR_LIGHNING_BOLT:
+      case SPELL_WATER_ICE_BOLT:
+      case SPELL_WATER_ACID_BURST:
+      case SPELL_WATER_ICE_BLAST:
+      case SPELL_EARTH_BLADES:
+      case SPELL_EARTH_ROCK_BLAST:
         a1.stru_24.Reset();
         v16 = 0;
         a1.spell_id = uSpellID;
@@ -622,22 +625,23 @@
         a1.spell_skill = v15;
         if ( (signed int)pObjectList->uNumObjects <= 0 )
         {
-          v18 = 0;
-          a1.uObjectDescID = v18;
+          //v18 = 0;
+          a1.uObjectDescID = 0;
           *(_QWORD *)&a1.vPosition.y = __PAIR__(fromz, fromy);
           a1.vPosition.x = fromx;
           a1.uAttributes = 16;
           a1.uSectorID = pIndoor->GetSector(fromx, fromy, fromz);
           a1.field_60_distance_related_prolly_lod = v55;
-          v20 = yaw;
+          //v20 = yaw;
           a1.uSpriteFrameID = 0;
           a1.spell_caster_pid = 8000 | OBJECT_Item;
           a1.spell_target_pid = 0;
           a1.uFacing = yaw;
           a1.uSoundID = 0;
           v49 = pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed;
-          a1.Create(v20, pitch, v49, 0);
-          goto LABEL_139;
+          a1.Create(yaw, pitch, v49, 0);
+          pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+          return;
         }
         v17 = (char *)&pObjectList->pObjects->uObjectID;
         while ( (short)a1.uType != *(short *)v17 )
@@ -646,22 +650,23 @@
           v17 += 56;
           if ( v16 >= (signed int)pObjectList->uNumObjects )
           {
-            v18 = 0;
-            a1.uObjectDescID = v18;
+            //v18 = 0;
+            a1.uObjectDescID = 0;
             *(_QWORD *)&a1.vPosition.y = __PAIR__(fromz, fromy);
             a1.vPosition.x = fromx;
             a1.uAttributes = 16;
             a1.uSectorID = pIndoor->GetSector(fromx, fromy, fromz);
             a1.field_60_distance_related_prolly_lod = v55;
-            v20 = yaw;
+            //v20 = yaw;
             a1.uSpriteFrameID = 0;
             a1.spell_caster_pid = 8000 | OBJECT_Item;
             a1.spell_target_pid = 0;
             a1.uFacing = yaw;
             a1.uSoundID = 0;
             v49 = pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed;
-            a1.Create(v20, pitch, v49, 0);
-            goto LABEL_139;
+            a1.Create(yaw, pitch, v49, 0);
+            pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+            return;
           }
         }
         v18 = v16;
@@ -671,16 +676,17 @@
         a1.uAttributes = 16;
         a1.uSectorID = pIndoor->GetSector(fromx, fromy, fromz);
         a1.field_60_distance_related_prolly_lod = v55;
-        v20 = yaw;
+        //v20 = yaw;
         a1.uSpriteFrameID = 0;
         a1.spell_caster_pid = 8000 | OBJECT_Item;
         a1.spell_target_pid = 0;
         a1.uFacing = yaw;
         a1.uSoundID = 0;
         v49 = pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed;
-        a1.Create(v20, pitch, v49, 0);
-        goto LABEL_139;
-      case 24:
+        a1.Create(yaw, pitch, v49, 0);
+        pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+        return;
+      case SPELL_WATER_POISON_SPRAY:
         switch ( v15 )
         {
           case 1:
@@ -706,9 +712,7 @@
           a1.spell_level = uSkill;
           a1.spell_skill = v15;
           if ( (signed int)pObjectList->uNumObjects <= 0 )
-          {
             v23 = 0;
-          }
           else
           {
             v22 = (char *)&pObjectList->pObjects->uObjectID;
@@ -734,7 +738,8 @@
                   a1.uFacing = i + yaw;
                   a1.Create((signed __int16)(i + (short)yaw), pitch, pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed, 0);
                 }
-                goto LABEL_139;
+                pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+                return;
               }
             }
             v23 = v21;
@@ -754,81 +759,82 @@
             a1.uFacing = i + yaw;
             a1.Create((signed __int16)(i + (short)yaw), pitch, pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed, 0);
           }
-          goto LABEL_139;
+          pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+          return;
         }
         a1.stru_24.Reset();
-        v16 = 0;
         a1.spell_id = uSpellID;
         a1.spell_level = uSkill;
         a1.spell_skill = v15;
         if ( (signed int)pObjectList->uNumObjects <= 0 )
-       {
-         v18 = 0;
-         a1.uObjectDescID = v18;
-         *(_QWORD *)&a1.vPosition.y = __PAIR__(fromz, fromy);
-         a1.vPosition.x = fromx;
-         a1.uAttributes = 16;
-         a1.uSectorID = pIndoor->GetSector(fromx, fromy, fromz);
-         a1.field_60_distance_related_prolly_lod = v55;
-         v20 = yaw;
-         a1.uSpriteFrameID = 0;
-         a1.spell_caster_pid = 8000 | OBJECT_Item;
-         a1.spell_target_pid = 0;
-         a1.uFacing = yaw;
-         a1.uSoundID = 0;
-         v51 = 0;
-         v49 = pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed;
-         v47 = pitch;
-         a1.Create(v20, v47, v49, v51);
-         goto LABEL_139;
-       }
-        v19 = (char *)&pObjectList->pObjects->uObjectID;
-        do
         {
-          if ( (short)a1.uType == *(short *)v19 )
+          //v18 = 0;
+          a1.uObjectDescID = 0;
+          *(_QWORD *)&a1.vPosition.y = __PAIR__(fromz, fromy);
+          a1.vPosition.x = fromx;
+          a1.uAttributes = 16;
+          a1.uSectorID = pIndoor->GetSector(fromx, fromy, fromz);
+          a1.field_60_distance_related_prolly_lod = v55;
+          //v20 = yaw;
+          a1.uSpriteFrameID = 0;
+          a1.spell_caster_pid = 8000 | OBJECT_Item;
+          a1.spell_target_pid = 0;
+          a1.uFacing = yaw;
+          a1.uSoundID = 0;
+          //v51 = 0;
+          v49 = pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed;
+          //v47 = pitch;
+          a1.Create(yaw, pitch, v49, 0);
+          pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+          return;
+        }
+        //v19 = (char *)&pObjectList->pObjects->uObjectID;
+        for ( v16 = 0; v16 < (signed int)pObjectList->uNumObjects; ++v16 )
+        {
+          if ( (short)a1.uType == pObjectList->pObjects[v16].uObjectID )
           {
-            v18 = v16;
-            a1.uObjectDescID = v18;
+            //v18 = v16;
+            a1.uObjectDescID = v16;
             *(_QWORD *)&a1.vPosition.y = __PAIR__(fromz, fromy);
             a1.vPosition.x = fromx;
             a1.uAttributes = 16;
             a1.uSectorID = pIndoor->GetSector(fromx, fromy, fromz);
             a1.field_60_distance_related_prolly_lod = v55;
-            v20 = yaw;
+            //v20 = yaw;
             a1.uSpriteFrameID = 0;
             a1.spell_caster_pid = 8000 | OBJECT_Item;
             a1.spell_target_pid = 0;
             a1.uFacing = yaw;
             a1.uSoundID = 0;
-            v51 = 0;
+            //v51 = 0;
             v49 = pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed;
-            v47 = pitch;
-            a1.Create(v20, v47, v49, v51);
-            goto LABEL_139;
+            //v47 = pitch;
+            a1.Create(yaw, pitch, v49, 0);
+            pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+            return;
           }
-          ++v16;
-          v19 += 56;
+          //v19 += 56;
         }
-        while ( v16 < (signed int)pObjectList->uNumObjects );
-        v18 = 0;
-        a1.uObjectDescID = v18;
+        //v18 = 0;
+        a1.uObjectDescID = 0;
         *(_QWORD *)&a1.vPosition.y = __PAIR__(fromz, fromy);
         a1.vPosition.x = fromx;
         a1.uAttributes = 16;
         a1.uSectorID = pIndoor->GetSector(fromx, fromy, fromz);
         a1.field_60_distance_related_prolly_lod = v55;
-        v20 = yaw;
+        //v20 = yaw;
         a1.uSpriteFrameID = 0;
         a1.spell_caster_pid = 8000 | OBJECT_Item;
         a1.spell_target_pid = 0;
         a1.uFacing = yaw;
         a1.uSoundID = 0;
-        v51 = 0;
+        //v51 = 0;
         v49 = pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed;
-        v47 = pitch;
-        a1.Create(v20, v47, v49, v51);
-        goto LABEL_139;
-      case 15:
+        //v47 = pitch;
+        a1.Create(yaw, pitch, v49, 0);
+        pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+        return;
+      case SPELL_AIR_SPARKS:
         switch ( v15 )
         {
           case 1:
@@ -853,8 +859,8 @@
         a1.spell_skill = v15;
         if ( (signed int)pObjectList->uNumObjects <= 0 )
         {
-          v27 = 0;
-          a1.uObjectDescID = v27;
+          //v27 = 0;
+          a1.uObjectDescID = 0;
           *(_QWORD *)&a1.vPosition.y = __PAIR__(fromz, fromy);
           a1.vPosition.x = fromx;
           a1.uAttributes = 16;
@@ -869,7 +875,8 @@
             a1.uFacing = j + yaw;
             a1.Create((signed __int16)(j + (short)yaw), pitch, pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed, 0);
           }
-          goto LABEL_139;
+          pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+          return;
         }
         v26 = (char *)&pObjectList->pObjects->uObjectID;
         while ( (short)a1.uType != *(short *)v26 )
@@ -894,7 +901,8 @@
               a1.uFacing = j + yaw;
               a1.Create((signed __int16)(j + (short)yaw), pitch, pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed, 0);
             }
-            goto LABEL_139;
+            pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+            return;
           }
         }
         v27 = v25;
@@ -911,14 +919,12 @@
         for ( j = a7d / -2; j <= a7d / 2; j += a8c )
         {
           a1.uFacing = j + yaw;
-          a1.Create(
-            (signed __int16)(j + (short)yaw),
-            pitch,
-            pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed,
-            0);
+          a1.Create((signed __int16)(j + (short)yaw), pitch,
+            pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed, 0);
         }
-        goto LABEL_139;
-      case 43:
+        pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+        return;
+      case SPELL_EARTH_DEATH_BLOSSOM:
         if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
           return;
         a1.stru_24.Reset();
@@ -928,8 +934,8 @@
         a1.spell_skill = v15;
         if ( (signed int)pObjectList->uNumObjects <= 0 )
         {
-          v31 = 0;
-          a1.uObjectDescID = v31;
+          //v31 = 0;
+          a1.uObjectDescID = 0;
           *(_QWORD *)&a1.vPosition.y = __PAIR__(fromz, fromy);
           a1.vPosition.x = fromx;
           a1.uAttributes = 16;
@@ -939,12 +945,13 @@
           a1.spell_caster_pid = 8000 | OBJECT_Item;
           a1.spell_target_pid = 4;
           a1.uSoundID = 0;
-          v51 = 0;
+          //v51 = 0;
           v49 = pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed;
-          v20 = yaw;
+          //v20 = yaw;
           v47 = (signed int)stru_5C6E00->uIntegerHalfPi / 2;
-          a1.Create(v20, v47, v49, v51);
-          goto LABEL_139;
+          a1.Create(yaw, v47, v49, 0);
+          pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+          return;
         }
         v30 = (char *)&pObjectList->pObjects->uObjectID;
         break;
@@ -953,21 +960,11 @@
         if ( v15 > 0 )
         {
           if ( v15 <= 2 )
-          {
             v9 = 60 * (uSkill + 60);
-          }
-          else
-          {
-            if ( v15 == 3 )
-            {
-              v9 = 180 * (uSkill + 20);
-            }
-            else
-            {
-              if ( v15 == 4 )
-                v9 = 240 * (uSkill + 15);
-            }
-          }
+          else if ( v15 == 3 )
+            v9 = 180 * (uSkill + 20);
+          else if ( v15 == 4 )
+            v9 = 240 * (uSkill + 15);
         }
         //levela = 1;
         //v32 = pParty->pPlayers;//[0].pConditions[1];
@@ -979,19 +976,17 @@
         //if ( !levela )
         //  return;
         pParty->pPartyBuffs[PARTY_BUFF_HASTE].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)(v9 * 128) * 0.033333335),
-          v15,
-          0,
-          0,
-          0);
+          v15, 0, 0, 0);
         //v33 = spellnum_;
         pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 0);
         pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 1);
         pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 2);
         pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 3);
-        goto LABEL_138;
-      case 17:
-      case 38:
-      case 51:
+        pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);//звук алтаря
+        return;
+      case SPELL_AIR_SHIELD:
+      case SPELL_EARTH_STONESKIN:
+      case SPELL_SPIRIT_HEROISM:
         switch ( v15 )
         {
           case 1:
@@ -1026,15 +1021,16 @@
         pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 1);
         pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 2);
         pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 3);
-        v52 = 0;
-        v50 = 0;
-        v48 = v60;
-        v46 = v15;
+        //v52 = 0;
+        //v50 = 0;
+        //v48 = v60;
+        //v46 = v15;
         v36 = pParty->uTimePlayed + (signed int)(signed __int64)((double)(v9 << 7) * 0.033333335);
-        v37 = &pParty->pPartyBuffs[uSkill];
-        v37->Apply(v36, v46, v48, v50, v52);
-        goto LABEL_139;;
-      case 8:
+        //v37 = &pParty->pPartyBuffs[uSkill];
+        pParty->pPartyBuffs[uSkill].Apply(v36, v15, v60, 0, 0);
+        pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+        return;
+      case SPELL_FIRE_IMMOLATION:
         if ( v15 == 2 || v15 == 3 || v15 != 4 )
           v38 = 60 * uSkill;
         else
@@ -1051,11 +1047,12 @@
         v37 = &pParty->pPartyBuffs[PARTY_BUFF_IMMOLATION];
         v36 = pParty->uTimePlayed + v39;
         v37->Apply(v36, v46, v48, v50, v52);
-        goto LABEL_139;
-      case 3:
-      case 14:
-      case 25:
-      case 36:
+        pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+        return;
+      case SPELL_FIRE_PROTECTION_FROM_FIRE:
+      case SPELL_AIR_PROTECTION_FROM_AIR:
+      case SPELL_WATER_PROTECTION_FROM_WATER:
+      case SPELL_EARTH_PROTECTION_FROM_EARTH:
         goto LABEL_117;
       default:
         return;
@@ -1066,8 +1063,8 @@
       v30 += 56;
       if ( v29 >= (signed int)pObjectList->uNumObjects )
       {
-        v31 = 0;
-        a1.uObjectDescID = v31;
+        //v31 = 0;
+        a1.uObjectDescID = 0;
         *(_QWORD *)&a1.vPosition.y = __PAIR__(fromz, fromy);
         a1.vPosition.x = fromx;
         a1.uAttributes = 16;
@@ -1077,12 +1074,13 @@
         a1.spell_caster_pid = 8000 | OBJECT_Item;
         a1.spell_target_pid = 4;
         a1.uSoundID = 0;
-        v51 = 0;
+        //v51 = 0;
         v49 = pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed;
-        v20 = yaw;
+        //v20 = yaw;
         v47 = (signed int)stru_5C6E00->uIntegerHalfPi / 2;
-        a1.Create(v20, v47, v49, v51);
-        goto LABEL_139;
+        a1.Create(yaw, v47, v49, 0);
+        pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+        return;
       }
     }
     v31 = v29;
@@ -1096,12 +1094,13 @@
     a1.spell_caster_pid = 8000 | OBJECT_Item;
     a1.spell_target_pid = 4;
     a1.uSoundID = 0;
-    v51 = 0;
+    //v51 = 0;
     v49 = pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed;
-    v20 = yaw;
+    //v20 = yaw;
     v47 = (signed int)stru_5C6E00->uIntegerHalfPi / 2;
-    a1.Create(v20, v47, v49, v51);
-    goto LABEL_139;
+    a1.Create(yaw, v47, v49, 0);
+    pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
+    return;
   }
 LABEL_117:
   v44 = uSkill;
@@ -1158,9 +1157,9 @@
   pGame->pStru6Instance->SetPlayerBuffAnim(uSpellID, 3);
   pParty->pPartyBuffs[uSkill].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)a6_4 * 4.2666669), v15, v60, 0, 0);
   //levela = 1;
-LABEL_138:
+//LABEL_138:
   //if ( levela )
-LABEL_139:
+//LABEL_139:
     pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[uSpellID], 0, 0, fromx, fromy, 0, 0, 0);
 }
 //----- (00427769) --------------------------------------------------------
--- a/UI/UiGame.cpp	Fri Dec 20 01:25:52 2013 +0100
+++ b/UI/UiGame.cpp	Fri Dec 20 01:28:39 2013 +0100
@@ -421,7 +421,7 @@
     break;
 
     default:
-      if (uDialogueType > DIALOGUE_18 && uDialogueType < DIALOGUE_23 && !byte_5B0938[0])
+      if (uDialogueType > DIALOGUE_18 && uDialogueType < DIALOGUE_EVT_E && !byte_5B0938[0])
       {
         pInString = (char *)current_npc_text;
       }
@@ -1819,7 +1819,7 @@
 void GameUI_DrawMinimap(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW, unsigned int uZoom, unsigned int bRedrawOdmMinimap)
 {
   int uHeight; // ebx@6
-  unsigned int pW; // ebx@23
+  signed int pW; // ebx@23
   int v15; // eax@23
   double v20; // st7@30
   signed int v27; // eax@37
@@ -1828,15 +1828,15 @@
   int pPoint_X; // edi@72
   int pPoint_Y; // ebx@72
   unsigned int lPitch; // [sp+20h] [bp-34h]@1
-  unsigned int pY; // [sp+20h] [bp-34h]@23
-  unsigned int pX; // [sp+24h] [bp-30h]@23
+  signed int pY; // [sp+20h] [bp-34h]@23
+  signed int pX; // [sp+24h] [bp-30h]@23
   signed int v70; // [sp+24h] [bp-30h]@37
   signed int uBluea; // [sp+28h] [bp-2Ch]@37
   int v73; // [sp+2Ch] [bp-28h]@30
   signed int uCenterY; // [sp+48h] [bp-Ch]@1
   signed int uCenterX; // [sp+4Ch] [bp-8h]@1
   signed int uWidth; // [sp+5Ch] [bp+8h]@30
-  unsigned int pZ; // [sp+60h] [bp+Ch]@23
+  signed int pZ; // [sp+60h] [bp+Ch]@23
   float uWb; // [sp+60h] [bp+Ch]@30
   unsigned int pColor;
 
@@ -1985,13 +1985,15 @@
         long long _a = (uZoom * (signed __int64)pIndoor->pVertices[pOutline->uVertex1ID].x);
         uint _b = ((unsigned int)((unsigned __int64)_a >> 16) << 16);
         int _c = ((signed int)(_b - uZoom * pParty->vPosition.x) >> 16);
-        pX = uCenterX + ((signed int)(((unsigned int)((unsigned __int64)(uZoom * (signed __int64)pIndoor->pVertices[pOutline->uVertex1ID].x) >> 16) << 16) - uZoom * pParty->vPosition.x) >> 16);
-        pY = uCenterY - ((signed int)(((unsigned int)((unsigned __int64)(uZoom * (signed __int64)pIndoor->pVertices[pOutline->uVertex1ID].y) >> 16) << 16) - uZoom * pParty->vPosition.y) >> 16);
-        pZ = uCenterX + ((signed int)(((unsigned int)((unsigned __int64)(uZoom * (signed __int64)pIndoor->pVertices[pOutline->uVertex2ID].x) >> 16) << 16) - uZoom * pParty->vPosition.x) >> 16);
-        pW = uCenterY - ((signed int)(((unsigned int)((unsigned __int64)(uZoom * (signed __int64)pIndoor->pVertices[pOutline->uVertex2ID].y) >> 16) << 16) - uZoom * pParty->vPosition.y) >> 16);
+        pX = uCenterX + ((signed int)(((unsigned int)((unsigned __int64)(uZoom * (signed __int64)pIndoor->pVertices[pIndoor->pMapOutlines->pOutlines[i].uVertex1ID].x) >> 16) << 16) - uZoom * pParty->vPosition.x) >> 16);
+        pY = uCenterY - ((signed int)(((unsigned int)((unsigned __int64)(uZoom * (signed __int64)pIndoor->pVertices[pIndoor->pMapOutlines->pOutlines[i].uVertex1ID].y) >> 16) << 16) - uZoom * pParty->vPosition.y) >> 16);
+        pZ = uCenterX + ((signed int)(((unsigned int)((unsigned __int64)(uZoom * (signed __int64)pIndoor->pVertices[pIndoor->pMapOutlines->pOutlines[i].uVertex2ID].x) >> 16) << 16) - uZoom * pParty->vPosition.x) >> 16);
+        pW = uCenterY - ((signed int)(((unsigned int)((unsigned __int64)(uZoom * (signed __int64)pIndoor->pVertices[pIndoor->pMapOutlines->pOutlines[i].uVertex2ID].y) >> 16) << 16) - uZoom * pParty->vPosition.y) >> 16);
         v15 = abs(pOutline->sZ - pParty->vPosition.z) / 8;
         if ( v15 > 100 )
           v15 = 100;
+		//if ( i == 1000 )//pY < 0 && pW > 16 )
+			//__debugbreak();
         pRenderer->RasterLine2D(pX, pY, pZ, pW, viewparams->pPalette[-v15 + 200]);
       }
     }
--- a/mm7_2.cpp	Fri Dec 20 01:25:52 2013 +0100
+++ b/mm7_2.cpp	Fri Dec 20 01:28:39 2013 +0100
@@ -2278,7 +2278,6 @@
   if (val < 1)
     return val;
 
-
     v2 = 0;
     v3 = val;
     result = 0;
@@ -2349,32 +2348,16 @@
 //----- (00452B2E) --------------------------------------------------------
 int __fastcall GetDiceResult(unsigned int uNumDice, unsigned int uDiceSides)
 {
-  signed int v2; // edi@1
   int v3; // esi@1
-  int result; // eax@2
-  unsigned int v5; // ebx@4
-
-  v2 = uDiceSides;
+
   v3 = 0;
   if ( uDiceSides )
   {
-    if ( (signed int)uNumDice > 0 )
-    {
-      v5 = uNumDice;
-      do
-      {
-        --v5;
-        v3 += rand() % v2 + 1;
-      }
-      while ( v5 );
-    }
-    result = v3;
+    for ( uint i = 0; i < uNumDice; ++i)
+      v3 += rand() % uDiceSides + 1;
+    return v3;
   }
-  else
-  {
-    result = 0;
-  }
-  return result;
+  return 0;
 }
 
 //----- (00453F62) --------------------------------------------------------
@@ -2734,37 +2717,36 @@
   pHostileTXT_Raw = NULL;
   pHostileTXT_Raw = (char *)pEvents_LOD->LoadRaw("hostile.txt", 0);
   strtok(pHostileTXT_Raw, "\r");
-  for (i=0; i<89; ++i)
-	  {
-	  test_string = strtok(NULL, "\r") + 1;
-	  break_loop = false;
-	  decode_step=0;
-	  do 
-		  {
-		  c = *(unsigned char*)test_string;
-		  temp_str_len = 0;
-		  while((c!='\t')&&(c>0))
-			  {
-			  ++temp_str_len;
-			  c=test_string[temp_str_len];
-			  }		
-		  tmp_pos=test_string+temp_str_len;
-		  if (*tmp_pos == 0)
-			  break_loop = true;
-		  *tmp_pos = 0;
-		  if (temp_str_len)
-			  {
-			  if ( decode_step >= 1 && decode_step < 90 )
-				  relations[decode_step-1][i] = atoi(test_string);
-			  }
-		  else
-			  { 
-			  break_loop = true;
-			  }
-		  ++decode_step;
-		  test_string=tmp_pos+1;
-		  } while ((decode_step<92)&&!break_loop);
-	  }
+  for ( i=0; i < 89; ++i )
+  {
+     test_string = strtok(NULL, "\r") + 1;
+     break_loop = false;
+     decode_step=0;
+     do 
+     {
+       c = *(unsigned char*)test_string;
+       temp_str_len = 0;
+       while((c!='\t') && (c > 0))
+       {
+         ++temp_str_len;
+         c = test_string[temp_str_len];
+       }
+       tmp_pos=test_string+temp_str_len;
+       if (*tmp_pos == 0)
+         break_loop = true;
+       *tmp_pos = 0;
+       if (temp_str_len)
+       {
+         if ( decode_step >= 1 && decode_step < 90 )
+           relations[decode_step-1][i] = atoi(test_string);
+       }
+       else
+         break_loop = true;
+       ++decode_step;
+       test_string=tmp_pos+1;
+     }
+     while ((decode_step < 92) && !break_loop );
+   }
   if ( pHostileTXT_Raw)
   {
     free(pHostileTXT_Raw);
@@ -2831,7 +2813,7 @@
   //GUIProgressBar *v0; // ebx@1
   //signed int v1; // ebp@1
   //char *v2; // esi@2
-  __int16 v3; // cx@3
+  //__int16 v3; // cx@3
   int v4; // edx@8
   //size_t v5; // edi@14
   signed int v6; // esi@14
@@ -2853,7 +2835,7 @@
 
   GenerateItemsInChest();
   pGameLoadingUI_ProgressBar->Progress();
-  pParty->uFlags |= 2u;
+  pParty->uFlags |= 2;
   pParty->field_7B5_in_arena_quest = 0;
   dword_5C6DF8 = 1;
   pNPCStats->uNewlNPCBufPos = 0;
@@ -2867,13 +2849,13 @@
     //v2 = (char *)&pActors[0].uNPC_ID;
     //do
     //{
-      v3 = pActors[i].pMonsterInfo.uID;
+      //v3 = pActors[i].pMonsterInfo.uID;
       v17 = 0;
       if ( pActors[i].pMonsterInfo.uID >= 115 && pActors[i].pMonsterInfo.uID <= 186
         || pActors[i].pMonsterInfo.uID >= 232 && pActors[i].pMonsterInfo.uID <= 249 )
         v17 = 1;
       //v1 = 0;
-      v4 = (v3 - 1) % 3;
+      v4 = (pActors[i].pMonsterInfo.uID - 1) % 3;
       if ( 2 == v4 )
       {
         if ( pActors[i].sNPC_ID && pActors[i].sNPC_ID < 5000 )
@@ -2884,15 +2866,15 @@
         if ( v4 != 1 )
         {
           if ( v4 == 0 && pActors[i].sNPC_ID == 0 )
-			pActors[i].sNPC_ID = 0;
-		  continue;
+            pActors[i].sNPC_ID = 0;
+          continue;
         }
       }
       if ( pActors[i].sNPC_ID > 0 && pActors[i].sNPC_ID < 5000 )
         continue;
       if ( v17 )
       {
-        pNPCStats->InitializeAdditionalNPCs(&pNPCStats->pAdditionalNPC[pNPCStats->uNewlNPCBufPos], v3, 0, v19);
+        pNPCStats->InitializeAdditionalNPCs(&pNPCStats->pAdditionalNPC[pNPCStats->uNewlNPCBufPos], pActors[i].pMonsterInfo.uID, 0, v19);
         v14 = LOWORD(pNPCStats->uNewlNPCBufPos) + 5000;
         ++pNPCStats->uNewlNPCBufPos;
         pActors[i].sNPC_ID = v14;
@@ -2917,60 +2899,38 @@
     //v7 = (char *)&pActors[0].pMonsterInfo;
     //do
     //{
-      v8 = 0;
-      if ( v6 > 0 )
-      {
-        do
-        {
-          if ( v21[v8] == pActors[i].pMonsterInfo.uID - 1 )
-            break;
-          ++v8;
-        }
-        while ( v8 < v6 );
-      }
-
-      if ( v8 == v6 )
-      {
-        v21[v6++] = pActors[i].pMonsterInfo.uID - 1;
-        v20 = v6;
-        if ( v6 == 16 )
-          break;
-      }
-      //++v16;
-      //v7 += 836;
+    for ( v8 = 0; v8 < v6; ++v8 )
+    {
+      if ( v21[v8] == pActors[i].pMonsterInfo.uID - 1 )
+        break;
+    }
+
+    if ( v8 == v6 )
+    {
+      v21[v6++] = pActors[i].pMonsterInfo.uID - 1;
+      v20 = v6;
+      if ( v6 == 16 )
+        break;
+    }
+    //++v16;
+    //v7 += 836;
     //}
     //while ( v16 < (signed int)v5 );
   }
 
   pGameLoadingUI_ProgressBar->Progress();
 
-  if ( v6 > 0 )
-  {
-    int _v0 = 0;
-    do
+    for ( int _v0 = 0; _v0 < v6; ++_v0 )
     {
-      v9 = v21[_v0];
-      v18 = 4;
-      v10 = &pMonsterStats->pInfos[v9 + 1];
-      //v11 = (int *)pMonsterList->pMonsters[v9].pSoundSampleIDs;
-      MonsterDesc* v11 = &pMonsterList->pMonsters[v9];
-      do
-      {
-        pSoundList->LoadSound(v11->pSoundSampleIDs[4 - v18], 0);
-        //v11 = (int *)((char *)v11 + 2);
-        --v18;
-      }
-      while ( v18 );
+      for ( v18 = 4; v18; --v18 )
+        pSoundList->LoadSound(pMonsterList->pMonsters[v21[_v0]].pSoundSampleIDs[4 - v18], 0);
       v12 = 0;
       do
-        v13 = pSoundList->LoadSound(v12++ + word_4EE088_sound_ids[v10->uSpell1ID], 1);
+        v13 = pSoundList->LoadSound(v12++ + word_4EE088_sound_ids[pMonsterStats->pInfos[v21[_v0] + 1].uSpell1ID], 1);
       while ( v13 );
-      ++_v0;
     }
-    while ( _v0 < v6 );
     //v0 = pGameLoadingUI_ProgressBar;
     //v1 = 0;
-  }
 
   pGameLoadingUI_ProgressBar->Progress();
 
@@ -3467,7 +3427,7 @@
       {
         if ( !RegCreateKeyExA(v7, "1.0", 0, "", 0, 0xF003Fu, 0, &v8, &dwDisposition) )
         {
-          RegSetValueExA(v8, lpValueName, 0, 4u, Data, 4u);
+          RegSetValueExA(v8, lpValueName, 0, 4, Data, 4);
           RegCloseKey(v8);
         }
         RegCloseKey(v7);
@@ -4107,21 +4067,12 @@
     pUIAnims[i]->y = _4E98D0[i][2];
   }
 
-  v5 = 0;
-  if ( (signed int)pObjectList->uNumObjects > 0 )
+  for ( v5 = 0; v5 < (signed int)pObjectList->uNumObjects; ++v5 )
   {
-    v6 = 0;
-    do
-    {
-      BYTE3(v7) = 0;
-      v8 = &pObjectList->pObjects[v6];
-      ++v6;
-      *(short *)((char *)&v7 + 1) = v8->uParticleTrailColorR;
-      LOBYTE(v7) = v8->uParticleTrailColorG;
-      ++v5;
-      v8->uParticleTrailColor = v8->uParticleTrailColorB | (v7 << 8);
-    }
-    while ( v5 < (signed int)pObjectList->uNumObjects );
+    BYTE3(v7) = 0;
+    *(short *)((char *)&v7 + 1) = pObjectList->pObjects[v5].uParticleTrailColorR;
+    LOBYTE(v7) = pObjectList->pObjects[v5].uParticleTrailColorG;
+    pObjectList->pObjects[v5].uParticleTrailColor = pObjectList->pObjects[v5].uParticleTrailColorB | (v7 << 8);
   }
   flt_6BE3A0 = 0.55000001f;
   MainMenuUI_Create();
@@ -4686,7 +4637,7 @@
   {
     LOBYTE(viewparams->field_20) = 0;
   }
-  pParty->uFlags |= 2u;
+  pParty->uFlags |= 2;
   viewparams->uSomeY = viewparams->uScreen_topL_Y;
   viewparams->uSomeX = viewparams->uScreen_topL_X;
   viewparams->uSomeZ = viewparams->uScreen_BttmR_X;
@@ -4736,22 +4687,15 @@
 int __fastcall _46A6AC_spell_render(int a1, int a2, int a3)
 {
   int result; // eax@2
-  unsigned int v4; // edx@3
   int *v5; // esi@6
   unsigned int v6; // ebx@6
   signed int v7; // edi@9
-  unsigned __int16 v8; // ax@9
   int i; // eax@14
   int v10; // ecx@19
-  int v11; // [sp+0h] [bp-18h]@1
-  unsigned int v12; // [sp+4h] [bp-14h]@3
   unsigned int v13; // [sp+8h] [bp-10h]@4
-  int v14; // [sp+Ch] [bp-Ch]@1
   int *v15; // [sp+10h] [bp-8h]@4
   int v16; // [sp+14h] [bp-4h]@3
 
-  v11 = a2;
-  v14 = a1;
   if ( pRenderer->pRenderD3D )
   {
     result = _46A6AC_spell_render_d3d(a1, a2, a3);
@@ -4760,56 +4704,47 @@
   {
     __debugbreak(); // SW render never called
     v16 = 0;
-    v4 = viewparams->uScreen_topL_X;
-    v12 = viewparams->uScreen_BttmR_X;
     if ( (signed int)viewparams->uScreen_topL_Y < (signed int)viewparams->uScreen_BttmR_Y )
     {
       v15 = &pRenderer->pActiveZBuffer[viewparams->uScreen_topL_X + 640 * viewparams->uScreen_topL_Y];
       v13 = ((viewparams->uScreen_BttmR_Y - viewparams->uScreen_topL_Y - 1) >> 1) + 1;
-      do
+      for ( v13; v13; --v13 )
       {
-        if ( (signed int)v4 < (signed int)v12 )
+        if ( (signed int)viewparams->uScreen_topL_X < (signed int)viewparams->uScreen_BttmR_X )
         {
           v5 = v15;
-          v6 = ((v12 - v4 - 1) >> 1) + 1;
-          do
+          v6 = ((viewparams->uScreen_BttmR_X - viewparams->uScreen_topL_X - 1) >> 1) + 1;
+          for ( v6; v6; --v6 )
           {
             if ( PID_TYPE(*(char *)v5) == OBJECT_Actor)
             {
               if ( *v5 <= a3 << 16 )
               {
                 v7 = PID_ID((signed int)(unsigned __int16)*v5);
-                v8 = pActors[v7].uAIState;
-                if ( v8 != 5 )
+                if ( pActors[v7].uAIState != Dead && pActors[v7].uAIState != Dying && pActors[v7].uAIState != Removed
+                  && pActors[v7].uAIState != Summoned && pActors[v7].uAIState != Disabled )
                 {
-                  if ( v8 != 4 && v8 != 11 && v8 != 17 && v8 != 19 )
+                  for ( i = 0; i < v16; ++i )
                   {
-                    for ( i = 0; i < v16; ++i )
+                    if ( *(int *)(a1 + 4 * i) == v7 )
+                      break;
+                  }
+                  if ( i == v16 )
+                  {
+                    if ( i < a2 - 1 )
                     {
-                      if ( *(int *)(v14 + 4 * i) == v7 )
-                        break;
-                    }
-                    if ( i == v16 )
-                    {
-                      if ( i < v11 - 1 )
-                      {
-                        v10 = v16++;
-                        *(int *)(v14 + 4 * v10) = v7;
-                      }
+                      v10 = v16++;
+                      *(int *)(a1 + 4 * v10) = v7;
                     }
                   }
                 }
               }
             }
             v5 += 2;
-            --v6;
           }
-          while ( v6 );
         }
         v15 += 1280;
-        --v13;
       }
-      while ( v13 );
     }
     result = v16;
   }
@@ -4820,67 +4755,42 @@
 int __fastcall _46A6AC_spell_render_d3d(int a1, int a2, int a3)
 {
   unsigned int v3; // eax@2
-  int v4; // ecx@2
   unsigned int v5; // eax@2
   unsigned int v6; // eax@4
-  unsigned int v7; // edi@4
-  unsigned __int16 v8; // ax@4
-  float v9; // ST00_4@9
   int v10; // ecx@11
   unsigned int v12; // [sp+10h] [bp-14h]@1
-  int v13; // [sp+14h] [bp-10h]@1
-  int v14; // [sp+18h] [bp-Ch]@1
   int v15; // [sp+1Ch] [bp-8h]@1
   unsigned int a1a; // [sp+20h] [bp-4h]@1
 
-  v13 = a1;
-  v14 = a2;
   v15 = 0;
-  a1a = 0;
   v12 = pRenderer->GetBillboardDrawListSize();
-  if ( (signed int)v12 > 0 )
+  if ( (signed int)pRenderer->GetBillboardDrawListSize() > 0 )
   {
-    do
+    for ( a1a = 0; (signed int)a1a < (signed int)v12; ++a1a )
     {
       v3 = pRenderer->GetParentBillboardID(a1a);
-      v4 = pBillboardRenderList[v3].sZValue;
       v5 = (unsigned __int16)pBillboardRenderList[v3].object_pid;
       if ( PID_TYPE(v5) == OBJECT_Actor)
       {
-        if ( v4 <= (unsigned int)(a3 << 16) )
+        if ( pBillboardRenderList[v3].sZValue <= (unsigned int)(a3 << 16) )
         {
           v6 = PID_ID(v5);
-          v7 = v6;
-          v8 = pActors[v6].uAIState;
-          if ( v8 != Dead )
+          if ( pActors[v6].uAIState != Dead && pActors[v6].uAIState != Dying && pActors[v6].uAIState != Removed
+            && pActors[v6].uAIState != Disabled && pActors[v6].uAIState != Summoned )
           {
-            if ( v8 != Dying )
+            if ( pGame->pVisInstance->DoesRayIntersectBillboard((double)a3, a1a) )
             {
-              if ( v8 != Removed )
+              if ( v15 < a2 - 1 )
               {
-                if ( v8 != Disabled )
-                {
-                  if ( v8 != Summoned )
-                  {
-                    v9 = (double)a3;
-                    if ( pGame->pVisInstance->DoesRayIntersectBillboard(v9, a1a) )
-                    {
-                      if ( v15 < v14 - 1 )
-                      {
-                        v10 = v15++;
-                        *(int *)(v13 + 4 * v10) = v7;
-                      }
-                    }
-                  }
-                }
+                __debugbreak();// *(int *)(a1 + 4 * v10) = v6; что это такое?
+                v10 = v15++;
+                *(int *)(a1 + 4 * v10) = v6;
               }
             }
           }
         }
       }
-      ++a1a;
     }
-    while ( (signed int)a1a < (signed int)v12 );
   }
   return v15;
 }
@@ -4888,8 +4798,6 @@
 //----- (0046A89E) --------------------------------------------------------
 int __fastcall _46A89E_immolation_effect(int a1, int a2, int a3)
 {
-  signed int v3; // edi@1
-  Actor *v4; // esi@2
   int v5; // ebx@3
   int v6; // eax@3
   int v7; // ebx@3
@@ -4897,74 +4805,50 @@
   int v9; // edx@4
   unsigned int v10; // edx@6
   unsigned int v11; // edx@8
-  __int16 v12; // ax@10
   int v13; // ecx@15
-  int v15; // [sp+4h] [bp-18h]@1
-  int v16; // [sp+8h] [bp-14h]@1
   int v17; // [sp+Ch] [bp-10h]@3
   int v18; // [sp+10h] [bp-Ch]@3
   int v19; // [sp+18h] [bp-4h]@1
 
-  v3 = 0;
-  v15 = a2;
-  v16 = a1;
   v19 = 0;
-  if ( (signed int)uNumActors > 0 )
+  for ( uint i = 0; i < (signed int)uNumActors; ++i )
   {
-    v4 = pActors.data();//[0].uAIState;
-    do
+    v5 = abs(pActors[i].vPosition.x - pParty->vPosition.x);
+    v17 = abs(pActors[i].vPosition.y - pParty->vPosition.y);
+    v18 = abs(pActors[i].vPosition.z - pParty->vPosition.z);
+    v6 = v5;
+    v7 = v17;
+    v8 = v18;
+    if ( v6 < v17 )
     {
-	  v5 = abs(v4->vPosition.x - pParty->vPosition.x);
-	  v17 = abs(v4->vPosition.y - pParty->vPosition.y);
-	  v18 = abs(v4->vPosition.z - pParty->vPosition.z);
-      v6 = v5;
-      v7 = v17;
-      v8 = v18;
-      if ( v6 < v17 )
-      {
-        v9 = v6;
-        v6 = v17;
-        v7 = v9;
-      }
-      if ( v6 < v18 )
-      {
-        v10 = v6;
-        v6 = v18;
-        v8 = v10;
-      }
-      if ( v7 < (signed int)v8 )
+      v9 = v6;
+      v6 = v17;
+      v7 = v9;
+    }
+    if ( v6 < v18 )
+    {
+      v10 = v6;
+      v6 = v18;
+      v8 = v10;
+    }
+    if ( v7 < (signed int)v8 )
+    {
+      v11 = v8;
+      v8 = v7;
+      v7 = v11;
+    }
+    if ( (signed int)(((unsigned int)(11 * v7) >> 5) + (v8 >> 2) + v6) <= a3 )
+    {
+      if ( pActors[i].uAIState != Dead && pActors[i].uAIState != Dying && pActors[i].uAIState != Removed
+        && pActors[i].uAIState != Disabled && pActors[i].uAIState != Summoned )
       {
-        v11 = v8;
-        v8 = v7;
-        v7 = v11;
+        __debugbreak();// *(int *)(a1 + 4 * v13) = i; что это такое?
+        v13 = v19++;
+        *(int *)(a1 + 4 * v13) = i;
+        if ( v19 >= a2 - 1 )
+          break;
       }
-      if ( (signed int)(((unsigned int)(11 * v7) >> 5) + (v8 >> 2) + v6) <= a3 )
-      {
-		v12 = v4->uAIState;
-        if ( v4->uAIState != 5 )
-        {
-          if ( v12 != 4 )
-          {
-            if ( v12 != 11 )
-            {
-              if ( v12 != 19 )
-              {
-                if ( v12 != 17 )
-                {
-                  v13 = v19++;
-                  *(int *)(v16 + 4 * v13) = v3;
-                  if ( v19 >= v15 - 1 )
-                    break;
-                }
-              }
-            }
-          }
-        }
-      }
-      ++v3;
-      ++v4;
     }
-    while ( v3 < (signed int)uNumActors );
   }
   return v19;
 }
@@ -4999,19 +4883,13 @@
 //----- (0046BFFA) --------------------------------------------------------
 bool __fastcall _46BFFA_check_object_intercept(unsigned int uLayingItemID, signed int a2)
 {
-  //SpriteObject *v2; // esi@1
-  ObjectDesc *v3; // ebx@1
-  unsigned __int16 v5; // cx@9
-  //unsigned __int16 v6; // cx@14
-  //signed int v7; // edx@14
+  ObjectDesc *object; // ebx@1
   unsigned int v8; // eax@19
-  unsigned int v9; // edi@19
   signed int v10; // ebx@19
   char *v11; // edx@20
   unsigned __int16 v12; // ax@23
   int v13; // eax@27
   unsigned int v14; // ebx@33
-  //unsigned __int16 v15; // ax@35
   int v16; // eax@36
   unsigned int v17; // eax@37
   __int16 v18; // di@37
@@ -5047,7 +4925,6 @@
   int v48; // edx@87
   int v49; // edx@88
   int v50; // edx@89
-  unsigned int v51; // eax@93
   signed int v52; // ebx@93
   char *v53; // edx@94
   unsigned __int16 v54; // ax@98
@@ -5069,11 +4946,6 @@
   char *v70; // edx@125
   unsigned __int16 v71; // ax@128
   unsigned int v72; // ebx@131
-  //int v73; // ST14_4@132
-  //int v74; // ST10_4@132
-  //int v75; // ebx@132
-  //int v76; // ST0C_4@132
-  //unsigned __int16 v77; // ax@132
   int v78; // eax@133
   char v79; // zf@139
   unsigned int v80; // eax@140
@@ -5095,13 +4967,8 @@
   unsigned __int16 v96; // ax@184
   int v97; // eax@185
   unsigned __int16 v98; // ax@191
-  unsigned int v99; // ecx@191
   char v100; // ST18_1@198
-  //int v101; // ST14_4@198
   int v102; // eax@198
-  //int v103; // ST10_4@198
-  //int v104; // ST0C_4@198
-  //unsigned __int16 v105; // ax@200
   signed int v106; // eax@208
   unsigned int v107; // edx@220
   signed int v108; // ebx@225
@@ -5112,7 +4979,6 @@
   unsigned __int16 v113; // si@241
   int v114; // eax@242
   int v115; // eax@245
-  //signed int v116; // eax@245
   unsigned __int16 v117; // ax@251
   unsigned int v118; // ecx@251
   signed int v119; // ebx@251
@@ -5122,14 +4988,7 @@
   char *v123; // edx@261
   int v124; // eax@267
   int v125; // [sp-20h] [bp-4Ch]@28
-  //signed int v126; // [sp-1Ch] [bp-48h]@27
-  //unsigned int v127; // [sp-18h] [bp-44h]@27
-  //signed int v128; // [sp-14h] [bp-40h]@27
-  //signed int v129; // [sp-10h] [bp-3Ch]@27
-  //int v130; // [sp-Ch] [bp-38h]@27
-  //unsigned int v131; // [sp-8h] [bp-34h]@27
   char v132; // [sp-8h] [bp-34h]@131
-  //int v133; // [sp-4h] [bp-30h]@27
   char v134; // [sp-4h] [bp-30h]@131
   signed int v135; // [sp-4h] [bp-30h]@217
   int v136; // [sp+Ch] [bp-20h]@208
@@ -5141,21 +5000,15 @@
   unsigned int v142; // [sp+1Ch] [bp-10h]@158
   signed int v143; // [sp+1Ch] [bp-10h]@172
   char *v144; // [sp+1Ch] [bp-10h]@192
-  signed int v145; // [sp+20h] [bp-Ch]@1
   signed int v146; // [sp+20h] [bp-Ch]@60
   int v147; // [sp+20h] [bp-Ch]@72
   signed int v148; // [sp+20h] [bp-Ch]@158
-  //int v149; // [sp+20h] [bp-Ch]@198
   unsigned __int16 v150; // [sp+20h] [bp-Ch]@208
-  int v151; // [sp+24h] [bp-8h]@1
   signed int v152; // [sp+24h] [bp-8h]@208
-  unsigned int v153; // [sp+28h] [bp-4h]@1
-
-  v153 = uLayingItemID;
-  //v2 = &pSpriteObjects[uLayingItemID];
-  v3 = &pObjectList->pObjects[pSpriteObjects[uLayingItemID].uObjectDescID];
-  v145 = a2;
-  v151 = PID_TYPE(a2);
+
+  //применение: фаерболт в храме луны
+  object = &pObjectList->pObjects[pSpriteObjects[uLayingItemID].uObjectDescID];
+  //v151 = PID_TYPE(a2);
   if ( PID_TYPE(a2) == OBJECT_Actor)
   {
     if ( PID_TYPE(pSpriteObjects[uLayingItemID].spell_caster_pid) == OBJECT_Actor 
@@ -5169,14 +5022,13 @@
   }
   if ( pParty->bTurnBasedModeOn == 1 )
   {
-    v5 = pSpriteObjects[uLayingItemID].uAttributes;
-    if ( v5 & 4 )
+    if ( pSpriteObjects[uLayingItemID].uAttributes & 4 )
     {
       --pTurnEngine->pending_actions;
-      pSpriteObjects[uLayingItemID].uAttributes = v5 & 0xFFFB;
+      pSpriteObjects[uLayingItemID].uAttributes &= 0xFFFB;
     }
   }
-  if ( v151 == OBJECT_BModel && PID_TYPE(pSpriteObjects[uLayingItemID].spell_caster_pid) != OBJECT_Player)
+  if ( PID_TYPE(a2) == OBJECT_BModel && PID_TYPE(pSpriteObjects[uLayingItemID].spell_caster_pid) != OBJECT_Player)
       {
       if (PID_ID(pSpriteObjects[uLayingItemID].spell_caster_pid) < 500)  //bugfix  PID_ID(v2->spell_caster_pid)==1000
          BYTE2(pActors[PID_ID(pSpriteObjects[uLayingItemID].spell_caster_pid)].uAttributes) |= 4;
@@ -5198,86 +5050,59 @@
           {
             if ( pSpriteObjects[uLayingItemID].uType != 9080 )
               return 0;
-LABEL_191:
-            v98 = pSpriteObjects[uLayingItemID].uType + 1;
-            v99 = pObjectList->uNumObjects;
-            v32 = 0;
-            pSpriteObjects[uLayingItemID].uType = v98;
-            v146 = 0;
-            if ( (signed int)v99 > 0 )
+            v95 = 0;
+            pSpriteObjects[uLayingItemID].uType = pSpriteObjects[uLayingItemID].uType + 1;
+            for ( v146 = 0; v146 < (signed int)pObjectList->uNumObjects; ++v146 )
             {
-              v144 = (char *)&pObjectList->pObjects->uObjectID;
-              while ( v98 != *(short *)v144 )
-              {
-                ++v146;
-                v144 += 56;
-                if ( v146 >= (signed int)v99 )
-                {
-                  pSpriteObjects[uLayingItemID].uObjectDescID = 0;
-                  if ( !v32 )
-                    SpriteObject::OnInteraction(v153);
-                  v100 = pSpriteObjects[uLayingItemID].field_61;
-                  pSpriteObjects[uLayingItemID].uSpriteFrameID = v32;
-                  v102 = 8 * v153;
-                  LOBYTE(v102) = PID(OBJECT_Item,v153);
-                  pSpriteObjects[uLayingItemID].vVelocity.x = v32;
-                  pSpriteObjects[uLayingItemID].vVelocity.y = v32;
-                  pSpriteObjects[uLayingItemID].vVelocity.z = v32;
-                  AttackerInfo.Add(v102, 512, pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v100, v32);
-                  if (v3->uFlags & OBJECT_DESC_TRIAL_PARTICLE)
-                    trail_particle_generator.GenerateTrailParticles(pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v3->uParticleTrailColor);
-                  if ( pSpriteObjects[uLayingItemID].uSoundID == (short)v32 )
-                    v47 = 0;
-                  else
-                    v47 = (signed __int16)pSpriteObjects[uLayingItemID].uSoundID + 4;
-                  v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
-                  pAudioPlayer->PlaySound((SoundID)v125, v102, v32, -1, v32, v47, v32, v32);
-                  return 0;
-                }
-              }
-              pSpriteObjects[uLayingItemID].uObjectDescID = v146;
-              if ( v146 == (short)v32 )
-                SpriteObject::OnInteraction(v153);
-              v100 = pSpriteObjects[uLayingItemID].field_61;
-              pSpriteObjects[uLayingItemID].uSpriteFrameID = v32;
-              v102 = 8 * v153;
-              LOBYTE(v102) = PID(OBJECT_Item,v153);
-              pSpriteObjects[uLayingItemID].vVelocity.x = v32;
-              pSpriteObjects[uLayingItemID].vVelocity.y = v32;
-              pSpriteObjects[uLayingItemID].vVelocity.z = v32;
-              AttackerInfo.Add(v102, 512, pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v100, v32);
-              if (v3->uFlags & OBJECT_DESC_TRIAL_PARTICLE)
-                trail_particle_generator.GenerateTrailParticles(pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v3->uParticleTrailColor);
-              if ( pSpriteObjects[uLayingItemID].uSoundID == (short)v32 )
-                v47 = 0;
-              else
-                v47 = (signed __int16)pSpriteObjects[uLayingItemID].uSoundID + 4;
-              v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
-              pAudioPlayer->PlaySound((SoundID)v125, v102, v32, -1, v32, v47, v32, v32);
-              return 0;
+              if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v146].uObjectID )
+                v95 = v146;
             }
-            pSpriteObjects[uLayingItemID].uObjectDescID = 0;
-            if ( !v32 )
-              SpriteObject::OnInteraction(v153);
+            pSpriteObjects[uLayingItemID].uObjectDescID = v95;
+            if ( !v95 )
+              SpriteObject::OnInteraction(uLayingItemID);
             v100 = pSpriteObjects[uLayingItemID].field_61;
-            pSpriteObjects[uLayingItemID].uSpriteFrameID = v32;
-            v102 = 8 * v153;
-            LOBYTE(v102) = PID(OBJECT_Item,v153);
-            pSpriteObjects[uLayingItemID].vVelocity.x = v32;
-            pSpriteObjects[uLayingItemID].vVelocity.y = v32;
-            pSpriteObjects[uLayingItemID].vVelocity.z = v32;
-            AttackerInfo.Add(v102, 512, pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v100, v32);
-            if (v3->uFlags & OBJECT_DESC_TRIAL_PARTICLE)
-              trail_particle_generator.GenerateTrailParticles(pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v3->uParticleTrailColor);
-            if ( pSpriteObjects[uLayingItemID].uSoundID == (short)v32 )
+            pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
+            v102 = 8 * uLayingItemID;
+            LOBYTE(v102) = PID(OBJECT_Item, uLayingItemID);
+            pSpriteObjects[uLayingItemID].vVelocity.x = 0;
+            pSpriteObjects[uLayingItemID].vVelocity.y = 0;
+            pSpriteObjects[uLayingItemID].vVelocity.z = 0;
+            AttackerInfo.Add(v102, 512, pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v100, 0);
+            if (object->uFlags & OBJECT_DESC_TRIAL_PARTICLE)
+              trail_particle_generator.GenerateTrailParticles(pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, object->uParticleTrailColor);
+            if ( !pSpriteObjects[uLayingItemID].uSoundID )
               v47 = 0;
             else
               v47 = (signed __int16)pSpriteObjects[uLayingItemID].uSoundID + 4;
             v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
-            pAudioPlayer->PlaySound((SoundID)v125, v102, v32, -1, v32, v47, v32, v32);
+            pAudioPlayer->PlaySound((SoundID)v125, v102, 0, -1, 0, v47, 0, 0);
             return 0;
           }
-          goto LABEL_93;
+          sub_43A97E(uLayingItemID, a2);
+          ++pSpriteObjects[uLayingItemID].uType;
+          v95 = 0;
+          for ( v52 = 0; v52 < (signed int)pObjectList->uNumObjects; ++v52 )
+          {
+            if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v52].uObjectID )
+              v95 = v52;
+          }
+          pSpriteObjects[uLayingItemID].uObjectDescID = v95;
+          if ( !v95 )
+            SpriteObject::OnInteraction(uLayingItemID);
+          v96 = pSpriteObjects[uLayingItemID].uSoundID;
+          pSpriteObjects[uLayingItemID].vVelocity.z = 0;
+          pSpriteObjects[uLayingItemID].vVelocity.y = 0;
+          pSpriteObjects[uLayingItemID].vVelocity.x = 0;
+          pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
+          if ( !v96 )
+            v97 = 0;
+          else
+            v97 = (signed __int16)v96 + 4;
+          v124 = 8 * uLayingItemID;
+          LOBYTE(v124) = v124 | 2;
+          v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
+          pAudioPlayer->PlaySound((SoundID)v125, v124, 0, -1, 0, v97, 0, 0);
+          return 0;
         }
 LABEL_172:
         v143 = 17030;
@@ -5294,40 +5119,27 @@
             break;
         }
         v138 = 1;
-        if ( v151 != OBJECT_Actor)
+        if ( PID_TYPE(a2) != OBJECT_Actor)
         {
           if ( pSpriteObjects[uLayingItemID].uType != 9030 || pSpriteObjects[uLayingItemID].spell_skill != 4 )
-		  {
-			  SpriteObject::OnInteraction(v153);
-			  return 0;
-		  }
-		  pSpriteObjects[uLayingItemID]._46BEF1_apply_spells_aoe();
+          {
+            SpriteObject::OnInteraction(uLayingItemID);
+            return 0;
+          }
+          pSpriteObjects[uLayingItemID]._46BEF1_apply_spells_aoe();
 LABEL_233:
           if ( !v138 )
           {
-            v109 = pObjectList->uNumObjects;
             ++pSpriteObjects[uLayingItemID].uType;
-            v110 = 0;
-            if ( (signed int)v109 <= 0 )
-            {
-LABEL_238:
-              v112 = 0;
-            }
-            else
+            v112 = 0;
+            for ( v110 = 0; v110 < (signed int)pObjectList->uNumObjects; ++v110 )
             {
-              v111 = (char *)&pObjectList->pObjects->uObjectID;
-              while ( pSpriteObjects[uLayingItemID].uType != *(short *)v111 )
-              {
-                ++v110;
-                v111 += 56;
-                if ( v110 >= (signed int)v109 )
-                  goto LABEL_238;
-              }
-              v112 = v110;
+              if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v110].uObjectID )
+                v112 = v110;
             }
             pSpriteObjects[uLayingItemID].uObjectDescID = v112;
             if ( !v112 )
-              SpriteObject::OnInteraction(v153);
+              SpriteObject::OnInteraction(uLayingItemID);
             pSpriteObjects[uLayingItemID].vVelocity.z = 0;
             pSpriteObjects[uLayingItemID].vVelocity.y = 0;
             pSpriteObjects[uLayingItemID].vVelocity.x = 0;
@@ -5337,16 +5149,16 @@
               v114 = (signed __int16)v113 + 4;
             else
               v114 = 0;
-            v115 = 8 * v153;
-            LOBYTE(v115) = PID(OBJECT_Item,v153);
+            v115 = 8 * uLayingItemID;
+            LOBYTE(v115) = PID(OBJECT_Item, uLayingItemID);
             v125 = v143 + 1;
             pAudioPlayer->PlaySound((SoundID)v125, v115, 0, -1, 0, v114, 0, 0);
             return 0;
           }
-          SpriteObject::OnInteraction(v153);
+          SpriteObject::OnInteraction(uLayingItemID);
           return 0;
         }
-        v106 = v145;
+        v106 = a2;
         v150 = 0;
         v139 = PID_ID(v106);
         v137 = pSpriteObjects[uLayingItemID].spell_level;
@@ -5412,55 +5224,100 @@
         v107 = v135;
         goto LABEL_222;
       }
-      if ( pSpriteObjects[uLayingItemID].uType == 8090 || pSpriteObjects[uLayingItemID].uType == 7030 || pSpriteObjects[uLayingItemID].uType == 7090 || pSpriteObjects[uLayingItemID].uType == 8000 )
-        goto LABEL_93;
+      if ( pSpriteObjects[uLayingItemID].uType == 8090
+        || pSpriteObjects[uLayingItemID].uType == 7030
+        || pSpriteObjects[uLayingItemID].uType == 7090 || pSpriteObjects[uLayingItemID].uType == 8000 )
+      {
+        sub_43A97E(uLayingItemID, a2);
+        ++pSpriteObjects[uLayingItemID].uType;
+        v95 = 0;
+        for ( v52 = 0; v52 < (signed int)pObjectList->uNumObjects; ++v52 )
+        {
+          if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v52].uObjectID )
+            v95 = v52;
+        }
+        pSpriteObjects[uLayingItemID].uObjectDescID = v95;
+        if ( !v95 )
+          SpriteObject::OnInteraction(uLayingItemID);
+        v96 = pSpriteObjects[uLayingItemID].uSoundID;
+        pSpriteObjects[uLayingItemID].vVelocity.z = 0;
+        pSpriteObjects[uLayingItemID].vVelocity.y = 0;
+        pSpriteObjects[uLayingItemID].vVelocity.x = 0;
+        pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
+        if ( !v96 )
+          v97 = 0;
+        else
+          v97 = (signed __int16)v96 + 4;
+        v124 = 8 * uLayingItemID;
+        LOBYTE(v124) = v124 | 2;
+        v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
+        pAudioPlayer->PlaySound((SoundID)v125, v124, 0, -1, 0, v97, 0, 0);
+        return 0;
+      }
       if ( pSpriteObjects[uLayingItemID].uType == 8010 )
       {
-        if ( v151 == 3
-          && MonsterStats::BelongsToSupertype(pActors[PID_ID(v145)].pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD) )
-          sub_43A97E(v153, v145);
-        v93 = pObjectList->uNumObjects;
+        if ( PID_TYPE(a2) == 3
+          && MonsterStats::BelongsToSupertype(pActors[PID_ID(a2)].pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD) )
+          sub_43A97E(uLayingItemID, a2);
         ++pSpriteObjects[uLayingItemID].uType;
-        v9 = 0;
-        v52 = 0;
-        if ( (signed int)v93 > 0 )
+        //v9 = 0;
+        v95 = 0;
+        for ( v52 = 0; v52 < (signed int)pObjectList->uNumObjects; ++v52 )
         {
-          v94 = (char *)&pObjectList->pObjects->uObjectID;
-          while ( pSpriteObjects[uLayingItemID].uType != *(short *)v94 )
-          {
-            ++v52;
-            v94 += 56;
-            if ( v52 >= (signed int)v93 )
-              goto LABEL_181;
-          }
-          v95 = v52;
-          pSpriteObjects[uLayingItemID].uObjectDescID = v95;
-			if ( v95 == (short)v9 )
-				SpriteObject::OnInteraction(v153);
-			v96 = pSpriteObjects[uLayingItemID].uSoundID;
-			pSpriteObjects[uLayingItemID].vVelocity.z = v9;
-			pSpriteObjects[uLayingItemID].vVelocity.y = v9;
-			pSpriteObjects[uLayingItemID].vVelocity.x = v9;
-			pSpriteObjects[uLayingItemID].uSpriteFrameID = v9;
-			if ( v96 == (short)v9 )
-				v97 = 0;
-			else
-				v97 = (signed __int16)v96 + 4;
-			v92 = v153;
-            v124 = 8 * v92;
-            LOBYTE(v124) = v124 | 2;
-            v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
-            pAudioPlayer->PlaySound((SoundID)v125, v124, v9, -1, v9, v97, v9, v9);
-            return 0;
+          if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v52].uObjectID )
+            v95 = v52;
         }
-        goto LABEL_181;
+        pSpriteObjects[uLayingItemID].uObjectDescID = v95;
+        if ( !v95 )
+          SpriteObject::OnInteraction(uLayingItemID);
+        v96 = pSpriteObjects[uLayingItemID].uSoundID;
+         pSpriteObjects[uLayingItemID].vVelocity.z = 0;
+        pSpriteObjects[uLayingItemID].vVelocity.y = 0;
+        pSpriteObjects[uLayingItemID].vVelocity.x = 0;
+        pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
+        if ( !v96 )
+          v97 = 0;
+        else
+          v97 = (signed __int16)v96 + 4;
+        v92 = uLayingItemID;
+        v124 = 8 * v92;
+        LOBYTE(v124) = v124 | 2;
+        v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
+        pAudioPlayer->PlaySound((SoundID)v125, v124, 0, -1, 0, v97, 0, 0);
+        return 0;
       }
       v79 = pSpriteObjects[uLayingItemID].uType == 8030;
     }
     else
     {
       if ( pSpriteObjects[uLayingItemID].uType == 6090 )
-        goto LABEL_93;
+      {
+        sub_43A97E(uLayingItemID, a2);
+        ++pSpriteObjects[uLayingItemID].uType;
+        v95 = 0;
+        for ( v52 = 0; v52 < (signed int)pObjectList->uNumObjects; ++v52 )
+        {
+          if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v52].uObjectID )
+            v95 = v52;
+        }
+        pSpriteObjects[uLayingItemID].uObjectDescID = v95;
+        if ( !v95 )
+          SpriteObject::OnInteraction(uLayingItemID);
+        v96 = pSpriteObjects[uLayingItemID].uSoundID;
+        pSpriteObjects[uLayingItemID].vVelocity.z = 0;
+        pSpriteObjects[uLayingItemID].vVelocity.y = 0;
+        pSpriteObjects[uLayingItemID].vVelocity.x = 0;
+        pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
+        if ( !v96 )
+          v97 = 0;
+        else
+          v97 = (signed __int16)v96 + 4;
+        v124 = 8 * uLayingItemID;
+        LOBYTE(v124) = v124 | 2;
+        v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
+        pAudioPlayer->PlaySound((SoundID)v125, v124, 0, -1, 0, v97, 0, 0);
+        return 0;
+      }
       if ( pSpriteObjects[uLayingItemID].uType <= 4070 )
       {
         if ( pSpriteObjects[uLayingItemID].uType != 4070 )
@@ -5472,81 +5329,75 @@
             if ( v49 )
             {
               v50 = v49 - 908;
-              if ( !v50 )
-                goto LABEL_93;
+              if ( v49 == 908 )
+              {
+                sub_43A97E(uLayingItemID, a2);
+                ++pSpriteObjects[uLayingItemID].uType;
+                v95 = 0;
+                for ( v52 = 0; v52 < (signed int)pObjectList->uNumObjects; ++v52 )
+                {
+                  if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v52].uObjectID )
+                    v95 = v52;
+                }
+                pSpriteObjects[uLayingItemID].uObjectDescID = v95;
+                if ( !v95 )
+                  SpriteObject::OnInteraction(uLayingItemID);
+                v96 = pSpriteObjects[uLayingItemID].uSoundID;
+                pSpriteObjects[uLayingItemID].vVelocity.z = 0;
+                pSpriteObjects[uLayingItemID].vVelocity.y = 0;
+                pSpriteObjects[uLayingItemID].vVelocity.x = 0;
+                pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
+                if ( !v96 )
+                  v97 = 0;
+                else
+                  v97 = (signed __int16)v96 + 4;
+                v124 = 8 * uLayingItemID;
+                LOBYTE(v124) = v124 | 2;
+                v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
+                pAudioPlayer->PlaySound((SoundID)v125, v124, 0, -1, 0, v97, 0, 0);
+                return 0;
+              }
               v45 = v50 - 30;
               v44 = v45 == 0;
               goto LABEL_91;
             }
-            v54 = pSpriteObjects[uLayingItemID].uType - 1;
-            v55 = pObjectList->uNumObjects;
-            v9 = 0;
-            v56 = 0;
-            v44 = pObjectList->uNumObjects == 0;
-            v20 = (pObjectList->uNumObjects & 0x80000000u) != 0;
-            pSpriteObjects[uLayingItemID].uType = v54;
-            if ( v20 | v44 )
+            //v9 = 0;
+            pSpriteObjects[uLayingItemID].uType = pSpriteObjects[uLayingItemID].uType - 1;
+            v58 = 0;
+            for ( v56 = 0; v56 < (signed int)pObjectList->uNumObjects; ++v56 )
             {
-LABEL_102:
-              v58 = 0;
-            }
-            else
-            {
-              v57 = (char *)&pObjectList->pObjects->uObjectID;
-              while ( v54 != *(short *)v57 )
-              {
-                ++v56;
-                v57 += 56;
-                if ( v56 >= (signed int)v55 )
-                  goto LABEL_102;
-              }
-              v58 = v56;
+              if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v56].uObjectID )
+                v58 = v56;
             }
             pSpriteObjects[uLayingItemID].uObjectDescID = v58;
             if ( !v58 )
-              SpriteObject::OnInteraction(v153);
+              SpriteObject::OnInteraction(uLayingItemID);
             pSpriteObjects[uLayingItemID].vVelocity.z = 0;
             pSpriteObjects[uLayingItemID].vVelocity.y = 0;
             pSpriteObjects[uLayingItemID].vVelocity.x = 0;
             pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
-            sub_43A97E(v153, v145);
-            if ( pSpriteObjects[uLayingItemID].uSoundID == (short)v9 )
+            sub_43A97E(uLayingItemID, a2);
+            if ( !pSpriteObjects[uLayingItemID].uSoundID )
               v16 = 0;
             else
               v16 = (signed __int16)pSpriteObjects[uLayingItemID].uSoundID + 4;
-            v124 = 8 * v153;
+            v124 = 8 * uLayingItemID;
             LOBYTE(v124) = v124 | 2;
             v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
-            pAudioPlayer->PlaySound((SoundID)v125, v124, v9, -1, v9, v16, v9, v9);
+            pAudioPlayer->PlaySound((SoundID)v125, v124, 0, -1, 0, v16, 0, 0);
             return 0;
           }
-          v59 = pSpriteObjects[uLayingItemID].uType + 2;
-          v60 = pObjectList->uNumObjects;
-          v9 = 0;
-          v61 = 0;
-          v44 = pObjectList->uNumObjects == 0;
-          v20 = (pObjectList->uNumObjects & 0x80000000u) != 0;
-          pSpriteObjects[uLayingItemID].uType = v59;
-          if ( v20 | v44 )
+          //v9 = 0;
+          pSpriteObjects[uLayingItemID].uType = pSpriteObjects[uLayingItemID].uType + 2;
+          v63 = 0;
+          for ( v61 = 0; v61 < (signed int)pObjectList->uNumObjects; ++v61 )
           {
-LABEL_111:
-            v63 = 0;
-          }
-          else
-          {
-            v62 = (char *)&pObjectList->pObjects->uObjectID;
-            while ( v59 != *(short *)v62 )
-            {
-              ++v61;
-              v62 += 56;
-              if ( v61 >= (signed int)v60 )
-                goto LABEL_111;
-            }
-            v63 = v61;
+            if ( v59 == pObjectList->pObjects[v61].uObjectID )
+              v63 = v61;
           }
           pSpriteObjects[uLayingItemID].uObjectDescID = v63;
           if ( !v63 )
-            SpriteObject::OnInteraction(v153);
+            SpriteObject::OnInteraction(uLayingItemID);
           v64 = pSpriteObjects[uLayingItemID].uFacing - stru_5C6E00->uIntegerDoublePi;
           v44 = pSpriteObjects[uLayingItemID].spell_skill == 4;
           pSpriteObjects[uLayingItemID].vVelocity.z = 0;
@@ -5560,60 +5411,45 @@
             v141 = v65;
             do
             {
-              v64 += (signed int)stru_5C6E00->uIntegerHalfPi >> 1;
+              v64 += (signed int)stru_5C6E00->uIntegerHalfPi / 2;
               pSpriteObjects[uLayingItemID].Create(v64, 0, 1000, 0);
               --v141;
             }
             while ( v141 );
           }
-          SpriteObject::OnInteraction(v153);
-          if ( pSpriteObjects[uLayingItemID].uSoundID == (short)v9 )
+          SpriteObject::OnInteraction(uLayingItemID);
+          if ( !pSpriteObjects[uLayingItemID].uSoundID )
             v16 = 0;
           else
             v16 = (signed __int16)pSpriteObjects[uLayingItemID].uSoundID + 4;
-          v124 = 8 * v153;
+          v124 = 8 * uLayingItemID;
           LOBYTE(v124) = v124 | 2;
           v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
-          pAudioPlayer->PlaySound((SoundID)v125, v124, v9, -1, v9, v16, v9, v9);
+          pAudioPlayer->PlaySound((SoundID)v125, v124, 0, -1, 0, v16, 0, 0);
           return 0;
         }
-        if ( v151 == 6 || v151 == 5 || (v66 = 0, !v151) )
+        //v66 = 0;
+        if ( PID_TYPE(a2) == 6 || PID_TYPE(a2) == 5 ||  !PID_TYPE(a2) )
           return 1;
-        v67 = pSpriteObjects[uLayingItemID].uType + 1;
-        v68 = pObjectList->uNumObjects;
-        v69 = 0;
-        v44 = pObjectList->uNumObjects == 0;
-        v20 = (pObjectList->uNumObjects & 0x80000000u) != 0;
-        pSpriteObjects[uLayingItemID].uType = v67;
-        if ( v20 | v44 )
+        pSpriteObjects[uLayingItemID].uType = pSpriteObjects[uLayingItemID].uType + 1;
+        v71 = 0;
+        for ( v69 = 0; v69 < (signed int)pObjectList->uNumObjects; ++v69 )
         {
-LABEL_128:
-          v71 = 0;
-        }
-        else
-        {
-          v70 = (char *)&pObjectList->pObjects->uObjectID;
-          while ( v67 != *(short *)v70 )
-          {
-            ++v69;
-            v70 += 56;
-            if ( v69 >= (signed int)v68 )
-              goto LABEL_128;
-          }
-          v71 = v69;
+          if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v69].uObjectID )
+            v71 = v69;
         }
         pSpriteObjects[uLayingItemID].uObjectDescID = v71;
         if ( !v71 )
-          SpriteObject::OnInteraction(v153);
+          SpriteObject::OnInteraction(uLayingItemID);
         v134 = 0;
-        v72 = v153;
+        v72 = uLayingItemID;
         v132 = 0;
-        pSpriteObjects[uLayingItemID].vVelocity.z = v66;
-        pSpriteObjects[uLayingItemID].vVelocity.y = v66;
-        pSpriteObjects[uLayingItemID].vVelocity.x = v66;
-        pSpriteObjects[uLayingItemID].uSpriteFrameID = v66;
+        pSpriteObjects[uLayingItemID].vVelocity.z = 0;
+        pSpriteObjects[uLayingItemID].vVelocity.y = 0;
+        pSpriteObjects[uLayingItemID].vVelocity.x = 0;
+        pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
         AttackerInfo.Add(PID(OBJECT_Item,v72), 512, pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v132, v134);
-        if ( pSpriteObjects[uLayingItemID].uSoundID == (short)v66 )
+        if ( !pSpriteObjects[uLayingItemID].uSoundID )
           v78 = 0;
         else
           v78 = (signed __int16)pSpriteObjects[uLayingItemID].uSoundID + 4;
@@ -5623,33 +5459,17 @@
       }
       if ( pSpriteObjects[uLayingItemID].uType == 4090 )
       {
-        v84 = pSpriteObjects[uLayingItemID].uType + 2;
-        v85 = pObjectList->uNumObjects;
-        v9 = 0;
-        v86 = 0;
-        v44 = pObjectList->uNumObjects == 0;
-        v20 = (pObjectList->uNumObjects & 0x80000000u) != 0;
-        pSpriteObjects[uLayingItemID].uType = v84;
-        if ( v20 | v44 )
+        //v9 = 0;
+        pSpriteObjects[uLayingItemID].uType = pSpriteObjects[uLayingItemID].uType + 2;
+        v88 = 0;
+        for ( v86 = 0; v86 < (signed int)pObjectList->uNumObjects; ++v86 )
         {
-LABEL_155:
-          v88 = 0;
-        }
-        else
-        {
-          v87 = (char *)&pObjectList->pObjects->uObjectID;
-          while ( v84 != *(short *)v87 )
-          {
-            ++v86;
-            v87 += 56;
-            if ( v86 >= (signed int)v85 )
-              goto LABEL_155;
-          }
-          v88 = v86;
+          if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v86].uObjectID )
+            v88 = v86;
         }
         pSpriteObjects[uLayingItemID].uObjectDescID = v88;
         if ( !v88 )
-          SpriteObject::OnInteraction(v153);
+          SpriteObject::OnInteraction(uLayingItemID);
         v89 = pSpriteObjects[uLayingItemID].uFacing - stru_5C6E00->uIntegerDoublePi;
         pSpriteObjects[uLayingItemID].vVelocity.z = 0;
         pSpriteObjects[uLayingItemID].vVelocity.y = 0;
@@ -5667,63 +5487,74 @@
           --v148;
         }
         while ( v148 );
-        SpriteObject::OnInteraction(v153);
-        if ( pSpriteObjects[uLayingItemID].uSoundID == (short)v9 )
+        SpriteObject::OnInteraction(uLayingItemID);
+        if ( !pSpriteObjects[uLayingItemID].uSoundID )
           v16 = 0;
         else
           v16 = (signed __int16)pSpriteObjects[uLayingItemID].uSoundID + 4;
-        v124 = 8 * v153;
+        v124 = 8 * uLayingItemID;
         LOBYTE(v124) = v124 | 2;
         v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id-1] + 1;
-        pAudioPlayer->PlaySound((SoundID)v125, v124, v9, -1, v9, v16, v9, v9);
+        pAudioPlayer->PlaySound((SoundID)v125, v124, 0, -1, 0, v16, 0, 0);
         return 0;
       }
       if ( pSpriteObjects[uLayingItemID].uType == 4092 )
       {
-        v80 = pObjectList->uNumObjects;
-        v66 = 0;
-        v81 = 0;
-        v44 = pObjectList->uNumObjects == 0;
-        v20 = (pObjectList->uNumObjects & 0x80000000u) != 0;
+        //v66 = 0;
         pSpriteObjects[uLayingItemID].uType = 4091;
-        if ( v20 | v44 )
+        v83 = 0;
+        for ( v81 = 0; v81 < (signed int)pObjectList->uNumObjects; ++v81 )
         {
-LABEL_144:
-          v83 = 0;
-        }
-        else
-        {
-          v82 = (char *)&pObjectList->pObjects->uObjectID;
-          while ( *(short *)v82 != 4091 )
-          {
-            ++v81;
-            v82 += 56;
-            if ( v81 >= (signed int)v80 )
-              goto LABEL_144;
-          }
-          v83 = v81;
+          if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v81].uObjectID )
+            v83 = v81;
         }
         pSpriteObjects[uLayingItemID].uObjectDescID = v83;
         if ( !v83 )
-          SpriteObject::OnInteraction(v153);
+          SpriteObject::OnInteraction(uLayingItemID);
         v134 = 0;
-        v72 = v153;
+        //v72 = uLayingItemID;
         v132 = pSpriteObjects[uLayingItemID].field_61;
-        pSpriteObjects[uLayingItemID].vVelocity.z = v66;
-        pSpriteObjects[uLayingItemID].vVelocity.y = v66;
-        pSpriteObjects[uLayingItemID].vVelocity.x = v66;
-        pSpriteObjects[uLayingItemID].uSpriteFrameID = v66;
-        AttackerInfo.Add(PID(OBJECT_Item,v72), 512, pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v132, v134);
-        if ( pSpriteObjects[uLayingItemID].uSoundID == (short)v66 )
+        pSpriteObjects[uLayingItemID].vVelocity.z = 0;
+        pSpriteObjects[uLayingItemID].vVelocity.y = 0;
+        pSpriteObjects[uLayingItemID].vVelocity.x = 0;
+        pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
+        AttackerInfo.Add(PID(OBJECT_Item, uLayingItemID), 512, pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v132, v134);
+        if ( !pSpriteObjects[uLayingItemID].uSoundID )
           v78 = 0;
         else
           v78 = (signed __int16)pSpriteObjects[uLayingItemID].uSoundID + 4;
         v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
-        pAudioPlayer->PlaySound((SoundID)v125, pSpriteObjects[uLayingItemID].vPosition.x, v66, -1, v66, v78, v66, v66);
+        pAudioPlayer->PlaySound((SoundID)v125, pSpriteObjects[uLayingItemID].vPosition.x, 0, -1, 0, v78, 0, 0);
         return 0;
       }
       if ( pSpriteObjects[uLayingItemID].uType == 4100 || pSpriteObjects[uLayingItemID].uType == 6010 )
-        goto LABEL_93;
+      {
+        sub_43A97E(uLayingItemID, a2);
+        ++pSpriteObjects[uLayingItemID].uType;
+        v95 = 0;
+        for ( v52 = 0; v52 < (signed int)pObjectList->uNumObjects; ++v52 )
+        {
+          if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v52].uObjectID )
+            v95 = v52;
+        }
+        pSpriteObjects[uLayingItemID].uObjectDescID = v95;
+        if ( !v95 )
+          SpriteObject::OnInteraction(uLayingItemID);
+        v96 = pSpriteObjects[uLayingItemID].uSoundID;
+        pSpriteObjects[uLayingItemID].vVelocity.z = 0;
+        pSpriteObjects[uLayingItemID].vVelocity.y = 0;
+        pSpriteObjects[uLayingItemID].vVelocity.x = 0;
+        pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
+        if ( !v96 )
+          v97 = 0;
+        else
+          v97 = (signed __int16)v96 + 4;
+        v124 = 8 * uLayingItemID;
+        LOBYTE(v124) = v124 | 2;
+        v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
+        pAudioPlayer->PlaySound((SoundID)v125, v124, 0, -1, 0, v97, 0, 0);
+        return 0;
+      }
       v79 = pSpriteObjects[uLayingItemID].uType == 6040;
     }
     if ( !v79 )
@@ -5731,37 +5562,50 @@
     goto LABEL_172;
   }
   if ( pSpriteObjects[uLayingItemID].uType == 3060 )
-    goto LABEL_93;
+  {
+    sub_43A97E(uLayingItemID, a2);
+    ++pSpriteObjects[uLayingItemID].uType;
+    v95 = 0;
+    for ( v52 = 0; v52 < (signed int)pObjectList->uNumObjects; ++v52 )
+    {
+      if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v52].uObjectID )
+        v95 = v52;
+    }
+    pSpriteObjects[uLayingItemID].uObjectDescID = v95;
+    if ( !v95 )
+      SpriteObject::OnInteraction(uLayingItemID);
+    v96 = pSpriteObjects[uLayingItemID].uSoundID;
+    pSpriteObjects[uLayingItemID].vVelocity.z = 0;
+    pSpriteObjects[uLayingItemID].vVelocity.y = 0;
+    pSpriteObjects[uLayingItemID].vVelocity.x = 0;
+    pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
+    if ( !v96 )
+      v97 = 0;
+    else
+      v97 = (signed __int16)v96 + 4;
+    v124 = 8 * uLayingItemID;
+    LOBYTE(v124) = v124 | 2;
+    v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
+    pAudioPlayer->PlaySound((SoundID)v125, v124, 0, -1, 0, v97, 0, 0);
+    return 0;
+  }
   if ( pSpriteObjects[uLayingItemID].uType <= 555 )
   {
     if ( pSpriteObjects[uLayingItemID].uType == 555 )
     {
-      sub_43A97E(v153, v145);
-      v23 = pObjectList->uNumObjects;
+      sub_43A97E(uLayingItemID, a2);
       ++pSpriteObjects[uLayingItemID].uType;
       v18 = 0;
-      v24 = 0;
-      if ( (signed int)v23 <= 0 )
-      {
-LABEL_41:
-        v22 = 0;
-      }
-      else
+      v22 = 0;
+      v25 = (char *)&pObjectList->pObjects->uObjectID;
+      for ( v24 = 0; v24 < (signed int)pObjectList->uNumObjects; ++v24 )
       {
-        v25 = (char *)&pObjectList->pObjects->uObjectID;
-        while ( pSpriteObjects[uLayingItemID].uType != *(short *)v25 )
-        {
-          ++v24;
-          v25 += 56;
-          if ( v24 >= (signed int)v23 )
-            goto LABEL_41;
-        }
-        v22 = v24;
+        if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v24].uObjectID )
+          v22 = v24;
       }
-LABEL_42:
       pSpriteObjects[uLayingItemID].uObjectDescID = v22;
       if ( v22 == v18 )
-        SpriteObject::OnInteraction(v153);
+        SpriteObject::OnInteraction(uLayingItemID);
       pSpriteObjects[uLayingItemID].vVelocity.z = v18;
       pSpriteObjects[uLayingItemID].vVelocity.y = v18;
       pSpriteObjects[uLayingItemID].vVelocity.x = v18;
@@ -5780,18 +5624,29 @@
         case 530:
         case 535:
         case 540:
-          sub_43A97E(v153, v145);
-          v8 = pObjectList->uNumObjects;
+          sub_43A97E(uLayingItemID, a2);
           ++pSpriteObjects[uLayingItemID].uType;
-          v9 = 0;
-          v10 = 0;
-          if ( (signed int)v8 <= 0 )
+          v12 = 0;
+          for ( v10 = 0; v10 < (signed int)pObjectList->uNumObjects; ++v10 )
           {
-            v12 = 0;
-            goto LABEL_24;
+            if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v10].uObjectID )
+              v12 = v10;
           }
-          v11 = (char *)&pObjectList->pObjects->uObjectID;
-          break;
+          pSpriteObjects[uLayingItemID].uObjectDescID = v12;
+          if ( !v12 )
+            SpriteObject::OnInteraction(uLayingItemID);
+          v44 = pSpriteObjects[uLayingItemID].uType == 555;
+          pSpriteObjects[uLayingItemID].vVelocity.z = 0;
+          pSpriteObjects[uLayingItemID].vVelocity.y = 0;
+          pSpriteObjects[uLayingItemID].vVelocity.x = 0;
+          pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
+          if ( !v44 )
+          {
+            v13 = 8 * uLayingItemID;
+            LOBYTE(v13) = PID(OBJECT_Item, uLayingItemID);
+            pAudioPlayer->PlaySound(SOUND_8, v13, 0, -1, 0, 0, 0, 0);
+          }
+          return 0;
         case 545:
         case 550:
           if ( pSpriteObjects[uLayingItemID].stru_24.uItemID != 405 && pSpriteObjects[uLayingItemID].stru_24.uSpecEnchantmentType != 3 )
@@ -5800,54 +5655,46 @@
             pSpriteObjects[uLayingItemID].vVelocity.y = 0;
             pSpriteObjects[uLayingItemID].vVelocity.x = 0;
             pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
-            sub_43A97E(v153, v145);
-            SpriteObject::OnInteraction(v153);
+            sub_43A97E(uLayingItemID, a2);
+            SpriteObject::OnInteraction(uLayingItemID);
             if ( pSpriteObjects[uLayingItemID].uSoundID == 0 )
               v16 = 0;
             else
               v16 = (signed __int16)pSpriteObjects[uLayingItemID].uSoundID + 4;
-            v124 = 8 * v153;
+            v124 = 8 * uLayingItemID;
             LOBYTE(v124) = v124 | 2;
             v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id] + 1;
             pAudioPlayer->PlaySound((SoundID)v125, v124, 0, -1, 0, v16, 0, 0);
             return 0;
           }
-          v17 = pObjectList->uNumObjects;
           v18 = 0;
-          v19 = 0;
-          v44 = pObjectList->uNumObjects == 0;
-          v20 = (pObjectList->uNumObjects & 0x80000000u) != 0;
           pSpriteObjects[uLayingItemID].uType = 600;
-          if ( v20 | v44 )
-            goto LABEL_41;
-          v21 = (char *)&pObjectList->pObjects->uObjectID;
-          while ( *(short *)v21 != 600 )
+          v22 = 0;
+          for ( v19 = 0; v19 < (signed int)pObjectList->uNumObjects; ++v19 )
           {
-            ++v19;
-            v21 += 56;
-            if ( v19 >= (signed int)v17 )
-              goto LABEL_41;
+            if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v19].uObjectID )
+              v22 = v19;
           }
-          v22 = v19;
-          goto LABEL_42;
+          pSpriteObjects[uLayingItemID].uObjectDescID = v22;
+          if ( !v22 )
+            SpriteObject::OnInteraction(uLayingItemID);
+          pSpriteObjects[uLayingItemID].vVelocity.z = v18;
+          pSpriteObjects[uLayingItemID].vVelocity.y = v18;
+          pSpriteObjects[uLayingItemID].vVelocity.x = v18;
+          pSpriteObjects[uLayingItemID].uSpriteFrameID = v18;
         default:
           return 0;
       }
-      while ( pSpriteObjects[uLayingItemID].uType != *(short *)v11 )
+      v12 = 0;
+      for ( v10; v10 < (signed int)v8; ++v10 )
       {
-        ++v10;
         v11 += 56;
-        if ( v10 >= (signed int)v8 )
-        {
-          v12 = 0;
-          goto LABEL_24;
-        }
+        if ( pSpriteObjects[uLayingItemID].uType != *(short *)v11 )
+          v12 = v10;
       }
-      v12 = v10;
-LABEL_24:
       pSpriteObjects[uLayingItemID].uObjectDescID = v12;
       if ( !v12 )
-        SpriteObject::OnInteraction(v153);
+        SpriteObject::OnInteraction(uLayingItemID);
       v44 = pSpriteObjects[uLayingItemID].uType == 555;
       pSpriteObjects[uLayingItemID].vVelocity.z = 0;
       pSpriteObjects[uLayingItemID].vVelocity.y = 0;
@@ -5855,9 +5702,9 @@
       pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
       if ( !v44 )
       {
-        v13 = 8 * v153;
-        LOBYTE(v13) = PID(OBJECT_Item,v153);
-        pAudioPlayer->PlaySound(SOUND_8, v13, v9, -1, v9, v9, v9, v9);
+        v13 = 8 * uLayingItemID;
+        LOBYTE(v13) = PID(OBJECT_Item, uLayingItemID);
+        pAudioPlayer->PlaySound(SOUND_8, v13, 0, -1, 0, 0, 0, 0);
         return 0;
       }
     }
@@ -5872,284 +5719,276 @@
     if ( v42 )
     {
       v43 = v42 - 40;
-      if ( !v43 )
-        goto LABEL_59;
+      if ( v42 == 40 )
+      {
+        if ( PID_TYPE(a2) != 3 )
+        {
+          //v32 = 0;
+          pSpriteObjects[uLayingItemID].uType = pSpriteObjects[uLayingItemID].uType + 1;
+          v46 = 0;
+          for ( v146 = 0; v146 < (signed int)pObjectList->uNumObjects; ++v146 )
+          {
+            if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v146].uObjectID )
+              v46 = v146;
+          }
+          pSpriteObjects[uLayingItemID].uObjectDescID = v46;
+          if ( !v46 )
+            SpriteObject::OnInteraction(uLayingItemID);
+          v100 = pSpriteObjects[uLayingItemID].field_61;
+          pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
+          v102 = 8 * uLayingItemID;
+          LOBYTE(v102) = PID(OBJECT_Item, uLayingItemID);
+          pSpriteObjects[uLayingItemID].vVelocity.x = 0;
+          pSpriteObjects[uLayingItemID].vVelocity.y = 0;
+          pSpriteObjects[uLayingItemID].vVelocity.z = 0;
+          AttackerInfo.Add(v102, 512, pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v100, 0);
+          if (object->uFlags & OBJECT_DESC_TRIAL_PARTICLE)
+            trail_particle_generator.GenerateTrailParticles(pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, object->uParticleTrailColor);
+          if ( !pSpriteObjects[uLayingItemID].uSoundID )
+            v47 = 0;
+          else
+            v47 = (signed __int16)pSpriteObjects[uLayingItemID].uSoundID + 4;
+          v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
+          pAudioPlayer->PlaySound((SoundID)v125, v102, 0, -1, 0, v47, 0, 0);
+          return 0;
+        }
+        return 1;
+      }
       v45 = v43 - 910;
       v44 = v45 == 0;
 LABEL_91:
       if ( !v44 && v45 != 20 )
         return 0;
     }
-LABEL_93:
-    sub_43A97E(v153, v145);
-    v51 = pObjectList->uNumObjects;
+    sub_43A97E(uLayingItemID, a2);
     ++pSpriteObjects[uLayingItemID].uType;
-    v9 = 0;
-    v52 = 0;
-    if ( (signed int)v51 > 0 )
+    v95 = 0;
+    for ( v52 = 0; v52 < (signed int)pObjectList->uNumObjects; ++v52 )
     {
-      v53 = (char *)&pObjectList->pObjects->uObjectID;
-      while ( pSpriteObjects[uLayingItemID].uType != *(short *)v53 )
-      {
-        ++v52;
-        v53 += 56;
-        if ( v52 >= (signed int)v51 )
-          goto LABEL_181;
-      }
-      v95 = v52;
+      if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v52].uObjectID )
+        v95 = v52;
     }
-	else
-	{
-LABEL_181:
-    v95 = 0;
-	}
     pSpriteObjects[uLayingItemID].uObjectDescID = v95;
-    if ( v95 == (short)v9 )
-      SpriteObject::OnInteraction(v153);
+    if ( !v95 )
+      SpriteObject::OnInteraction(uLayingItemID);
     v96 = pSpriteObjects[uLayingItemID].uSoundID;
-    pSpriteObjects[uLayingItemID].vVelocity.z = v9;
-    pSpriteObjects[uLayingItemID].vVelocity.y = v9;
-    pSpriteObjects[uLayingItemID].vVelocity.x = v9;
-    pSpriteObjects[uLayingItemID].uSpriteFrameID = v9;
-    if ( v96 == (short)v9 )
+    pSpriteObjects[uLayingItemID].vVelocity.z = 0;
+    pSpriteObjects[uLayingItemID].vVelocity.y = 0;
+    pSpriteObjects[uLayingItemID].vVelocity.x = 0;
+    pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
+    if ( !v96 )
       v97 = 0;
     else
       v97 = (signed __int16)v96 + 4;
-    v92 = v153;
+    v124 = 8 * uLayingItemID;
+    LOBYTE(v124) = v124 | 2;
+    v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
+    pAudioPlayer->PlaySound((SoundID)v125, v124, 0, -1, 0, v97, 0, 0);
+    return 0;
+  }
+  if ( pSpriteObjects[uLayingItemID].uType == 1100 )
+  {
+    sub_43A97E(uLayingItemID, a2);
+    ++pSpriteObjects[uLayingItemID].uType;
+    v95 = 0;
+    for ( v52 = 0; v52 < (signed int)pObjectList->uNumObjects; ++v52 )
+    {
+      if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v52].uObjectID )
+        v95 = v52;
+    }
+    pSpriteObjects[uLayingItemID].uObjectDescID = v95;
+    if ( !v95 )
+      SpriteObject::OnInteraction(uLayingItemID);
+    v96 = pSpriteObjects[uLayingItemID].uSoundID;
+    pSpriteObjects[uLayingItemID].vVelocity.z = 0;
+    pSpriteObjects[uLayingItemID].vVelocity.y = 0;
+    pSpriteObjects[uLayingItemID].vVelocity.x = 0;
+    pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
+    if ( !v96 )
+      v97 = 0;
+    else
+      v97 = (signed __int16)v96 + 4;
+    v92 = uLayingItemID;
     v124 = 8 * v92;
     LOBYTE(v124) = v124 | 2;
     v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
-    pAudioPlayer->PlaySound((SoundID)v125, v124, v9, -1, v9, v97, v9, v9);
+    pAudioPlayer->PlaySound((SoundID)v125, v124, 0, -1, 0, v97, 0, 0);
     return 0;
   }
-  if ( pSpriteObjects[uLayingItemID].uType == 1100 )
-    goto LABEL_93;
   v26 = pSpriteObjects[uLayingItemID].uType - 600;
-  if ( !v26 )
+  if ( pSpriteObjects[uLayingItemID].uType == 600 )
   {
-    v33 = pObjectList->uNumObjects;
-    v34 = 0;
-    v44 = pObjectList->uNumObjects == 0;
-    v20 = (pObjectList->uNumObjects & 0x80000000u) != 0;
     pSpriteObjects[uLayingItemID].uType = 601;
-    if ( v20 | v44 )
+    v36 = 0;
+    for ( v34 = 0; v34 < (signed int)pObjectList->uNumObjects; ++v34 )
     {
-LABEL_69:
-      v36 = 0;
-    }
-    else
-    {
-      v35 = (char *)&pObjectList->pObjects->uObjectID;
-      while ( *(short *)v35 != 601 )
-      {
-        ++v34;
-        v35 += 56;
-        if ( v34 >= (signed int)v33 )
-          goto LABEL_69;
-      }
-      v36 = v34;
+      if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v34].uObjectID )
+        v36 = v34;
     }
     pSpriteObjects[uLayingItemID].uObjectDescID = v36;
     if ( !v36 )
-      SpriteObject::OnInteraction(v153);
+      SpriteObject::OnInteraction(uLayingItemID);
     v37 = pSpriteObjects[uLayingItemID].vPosition.z;
     pSpriteObjects[uLayingItemID].vVelocity.z = 0;
-    v38 = 8 * v153;
+    v38 = 8 * uLayingItemID;
     v39 = pSpriteObjects[uLayingItemID].vPosition.y;
-    LOBYTE(v38) = PID(OBJECT_Item,v153);
+    LOBYTE(v38) = PID(OBJECT_Item, uLayingItemID);
     pSpriteObjects[uLayingItemID].vVelocity.y = 0;
     pSpriteObjects[uLayingItemID].vVelocity.x = 0;
     v40 = pSpriteObjects[uLayingItemID].vPosition.x;
     pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
     v147 = v38;
     AttackerInfo.Add(v38, 512, v40, v39, v37, 0, 0);
-    if (v3->uFlags & OBJECT_DESC_TRIAL_PARTICLE)
-      trail_particle_generator.GenerateTrailParticles(pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v3->uParticleTrailColor);
+    if (object->uFlags & OBJECT_DESC_TRIAL_PARTICLE)
+      trail_particle_generator.GenerateTrailParticles(pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, object->uParticleTrailColor);
     pAudioPlayer->PlaySound(SOUND_8, v147, 0, -1, 0, 0, 0, 0);
     return 0;
   }
   v27 = v26 - 410;
-  if ( !v27 )
-    goto LABEL_93;
+  if ( v26 == 410 )
+  {
+    sub_43A97E(uLayingItemID, a2);
+    ++pSpriteObjects[uLayingItemID].uType;
+    v95 = 0;
+    for ( v52 = 0; v52 < (signed int)pObjectList->uNumObjects; ++v52 )
+    {
+      if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v52].uObjectID )
+        v95 = v52;
+    }
+    pSpriteObjects[uLayingItemID].uObjectDescID = v95;
+    if ( !v95 )
+    SpriteObject::OnInteraction(uLayingItemID);
+    v96 = pSpriteObjects[uLayingItemID].uSoundID;
+    pSpriteObjects[uLayingItemID].vVelocity.z = 0;
+    pSpriteObjects[uLayingItemID].vVelocity.y = 0;
+    pSpriteObjects[uLayingItemID].vVelocity.x = 0;
+    pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
+    if ( !v96 )
+      v97 = 0;
+    else
+      v97 = (signed __int16)v96 + 4;
+    v124 = 8 * uLayingItemID;
+    LOBYTE(v124) = v124 | 2;
+    v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
+    pAudioPlayer->PlaySound((SoundID)v125, v124, 0, -1, 0, v97, 0, 0);
+    return 0;
+  }
   v28 = v27 - 40;
   if ( !v28 )
-    goto LABEL_191;
+  {
+    v95 = 0;
+    pSpriteObjects[uLayingItemID].uType = pSpriteObjects[uLayingItemID].uType + 1;
+    for ( v146 = 0; v146 < (signed int)pObjectList->uNumObjects; ++v146 )
+    {
+      if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v146].uObjectID )
+        v95 = v146;
+    }
+    pSpriteObjects[uLayingItemID].uObjectDescID = v95;
+    if ( !v95 )
+      SpriteObject::OnInteraction(uLayingItemID);
+    v100 = pSpriteObjects[uLayingItemID].field_61;
+    pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
+    v102 = 8 * uLayingItemID;
+    LOBYTE(v102) = PID(OBJECT_Item, uLayingItemID);
+    pSpriteObjects[uLayingItemID].vVelocity.x = 0;
+    pSpriteObjects[uLayingItemID].vVelocity.y = 0;
+    pSpriteObjects[uLayingItemID].vVelocity.z = 0;
+    AttackerInfo.Add(v102, 512, pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v100, 0);
+    if (object->uFlags & OBJECT_DESC_TRIAL_PARTICLE)
+      trail_particle_generator.GenerateTrailParticles(pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, object->uParticleTrailColor);
+    if ( !pSpriteObjects[uLayingItemID].uSoundID )
+      v47 = 0;
+    else
+      v47 = (signed __int16)pSpriteObjects[uLayingItemID].uSoundID + 4;
+    v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
+    pAudioPlayer->PlaySound((SoundID)v125, v102, 0, -1, 0, v47, 0, 0);
+    return 0;
+  }
   v29 = v28 - 10;
   if ( v29 )
   {
     if ( v29 != 20 )
       return 0;
-LABEL_59:
-    if ( v151 != 3 )
+    if ( PID_TYPE(a2) != 3 )
     {
-      v30 = pSpriteObjects[uLayingItemID].uType + 1;
-      v31 = pObjectList->uNumObjects;
-      v32 = 0;
-      pSpriteObjects[uLayingItemID].uType = v30;
-      v146 = 0;
-      if ( (signed int)v31 > 0 )
+      //v32 = 0;
+      pSpriteObjects[uLayingItemID].uType = pSpriteObjects[uLayingItemID].uType + 1;
+      v46 = 0;
+      for ( v146 = 0; v146 < (signed int)pObjectList->uNumObjects; ++v146 )
       {
-        v140 = (char *)&pObjectList->pObjects->uObjectID;
-        while ( v30 != *(short *)v140 )
-        {
-          ++v146;
-          v140 += 56;
-          if ( v146 >= (signed int)v31 )
-          {
-            v46 = 0;
-            pSpriteObjects[uLayingItemID].uObjectDescID = v46;
-            if ( v46 == (short)v32 )
-              SpriteObject::OnInteraction(v153);
-            v100 = pSpriteObjects[uLayingItemID].field_61;
-            pSpriteObjects[uLayingItemID].uSpriteFrameID = v32;
-            v102 = 8 * v153;
-            LOBYTE(v102) = PID(OBJECT_Item,v153);
-            pSpriteObjects[uLayingItemID].vVelocity.x = v32;
-            pSpriteObjects[uLayingItemID].vVelocity.y = v32;
-            pSpriteObjects[uLayingItemID].vVelocity.z = v32;
-            AttackerInfo.Add(v102, 512, pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v100, v32);
-            if (v3->uFlags & OBJECT_DESC_TRIAL_PARTICLE)
-              trail_particle_generator.GenerateTrailParticles(pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v3->uParticleTrailColor);
-            if ( pSpriteObjects[uLayingItemID].uSoundID == (short)v32 )
-              v47 = 0;
-            else
-              v47 = (signed __int16)pSpriteObjects[uLayingItemID].uSoundID + 4;
-            v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
-            pAudioPlayer->PlaySound((SoundID)v125, v102, v32, -1, v32, v47, v32, v32);
-            return 0;
-          }
-        }
-        v46 = v146;
-        pSpriteObjects[uLayingItemID].uObjectDescID = v46;
-        if ( v46 == (short)v32 )
-          SpriteObject::OnInteraction(v153);
-        v100 = pSpriteObjects[uLayingItemID].field_61;
-        pSpriteObjects[uLayingItemID].uSpriteFrameID = v32;
-        v102 = 8 * v153;
-        LOBYTE(v102) = PID(OBJECT_Item,v153);
-        pSpriteObjects[uLayingItemID].vVelocity.x = v32;
-        pSpriteObjects[uLayingItemID].vVelocity.y = v32;
-        pSpriteObjects[uLayingItemID].vVelocity.z = v32;
-        AttackerInfo.Add(v102, 512, pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v100, v32);
-        if (v3->uFlags & OBJECT_DESC_TRIAL_PARTICLE)
-          trail_particle_generator.GenerateTrailParticles(pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v3->uParticleTrailColor);
-        if ( pSpriteObjects[uLayingItemID].uSoundID == (short)v32 )
-          v47 = 0;
-        else
-          v47 = (signed __int16)pSpriteObjects[uLayingItemID].uSoundID + 4;
-        v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
-        pAudioPlayer->PlaySound((SoundID)v125, v102, v32, -1, v32, v47, v32, v32);
-        return 0;
+        if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v146].uObjectID )
+          v46 = v146;
       }
-      v46 = 0;
       pSpriteObjects[uLayingItemID].uObjectDescID = v46;
-      if ( v46 == (short)v32 )
-        SpriteObject::OnInteraction(v153);
+      if ( !v46 )
+        SpriteObject::OnInteraction(uLayingItemID);
       v100 = pSpriteObjects[uLayingItemID].field_61;
-      pSpriteObjects[uLayingItemID].uSpriteFrameID = v32;
-      v102 = 8 * v153;
-      LOBYTE(v102) = PID(OBJECT_Item,v153);
-      pSpriteObjects[uLayingItemID].vVelocity.x = v32;
-      pSpriteObjects[uLayingItemID].vVelocity.y = v32;
-      pSpriteObjects[uLayingItemID].vVelocity.z = v32;
-      AttackerInfo.Add(v102, 512, pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v100, v32);
-      if (v3->uFlags & OBJECT_DESC_TRIAL_PARTICLE)
-        trail_particle_generator.GenerateTrailParticles(pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v3->uParticleTrailColor);
-      if ( pSpriteObjects[uLayingItemID].uSoundID == (short)v32 )
+      pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
+      v102 = 8 * uLayingItemID;
+      LOBYTE(v102) = PID(OBJECT_Item, uLayingItemID);
+      pSpriteObjects[uLayingItemID].vVelocity.x = 0;
+      pSpriteObjects[uLayingItemID].vVelocity.y = 0;
+      pSpriteObjects[uLayingItemID].vVelocity.z = 0;
+      AttackerInfo.Add(v102, 512, pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, v100, 0);
+      if (object->uFlags & OBJECT_DESC_TRIAL_PARTICLE)
+        trail_particle_generator.GenerateTrailParticles(pSpriteObjects[uLayingItemID].vPosition.x, pSpriteObjects[uLayingItemID].vPosition.y, pSpriteObjects[uLayingItemID].vPosition.z, object->uParticleTrailColor);
+      if ( !pSpriteObjects[uLayingItemID].uSoundID )
         v47 = 0;
       else
         v47 = (signed __int16)pSpriteObjects[uLayingItemID].uSoundID + 4;
       v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
-      pAudioPlayer->PlaySound((SoundID)v125, v102, v32, -1, v32, v47, v32, v32);
+      pAudioPlayer->PlaySound((SoundID)v125, v102, 0, -1, 0, v47, 0, 0);
       return 0;
     }
     return 1;
   }
 LABEL_247:
-  if ( v151 == 6 || v151 == 5 || (v9 = 0, !v151) )
+  //v9 = 0;
+  if ( PID_TYPE(a2) == 6 || PID_TYPE(a2) == 5 || !PID_TYPE(a2) )
     return 1;
-  if ( v151 != 2 )
+  if ( PID_TYPE(a2) != 2 )
   {
-    sub_43A97E(v153, v145);
-    v122 = pObjectList->uNumObjects;
+    sub_43A97E(uLayingItemID, a2);
     ++pSpriteObjects[uLayingItemID].uType;
-    v52 = 0;
-    if ( (signed int)v122 > 0 )
+    v95 = 0;
+    for ( v52 = 0; v52 < (signed int)pObjectList->uNumObjects; ++v52 )
     {
-      v123 = (char *)&pObjectList->pObjects->uObjectID;
-      while ( pSpriteObjects[uLayingItemID].uType != *(short *)v123 )
-      {
-        ++v52;
-        v123 += 56;
-        if ( v52 >= (signed int)v122 )
-          goto LABEL_181;
-      }
-      v95 = v52;
-      pSpriteObjects[uLayingItemID].uObjectDescID = v95;
-      if ( v95 == (short)v9 )
-        SpriteObject::OnInteraction(v153);
-      v96 = pSpriteObjects[uLayingItemID].uSoundID;
-      pSpriteObjects[uLayingItemID].vVelocity.z = v9;
-      pSpriteObjects[uLayingItemID].vVelocity.y = v9;
-      pSpriteObjects[uLayingItemID].vVelocity.x = v9;
-      pSpriteObjects[uLayingItemID].uSpriteFrameID = v9;
-      if ( v96 == (short)v9 )
-        v97 = 0;
-      else
-        v97 = (signed __int16)v96 + 4;
-      v92 = v153;
-      v124 = 8 * v92;
-      LOBYTE(v124) = v124 | 2;
-      v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
-      pAudioPlayer->PlaySound((SoundID)v125, v124, v9, -1, v9, v97, v9, v9);
-      return 0;
+      if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v52].uObjectID )
+        v95 = v52;
     }
-    goto LABEL_181;
+    pSpriteObjects[uLayingItemID].uObjectDescID = v95;
+    if ( !v95 )
+      SpriteObject::OnInteraction(uLayingItemID);
+    pSpriteObjects[uLayingItemID].vVelocity.z = 0;
+    pSpriteObjects[uLayingItemID].vVelocity.y = 0;
+    pSpriteObjects[uLayingItemID].vVelocity.x = 0;
+    pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
+    if ( !pSpriteObjects[uLayingItemID].uSoundID )
+      v97 = 0;
+    else
+      v97 = (signed __int16)pSpriteObjects[uLayingItemID].uSoundID + 4;
+    v124 = 8 * uLayingItemID;
+    LOBYTE(v124) = v124 | 2;
+    v125 = word_4EE088_sound_ids[pSpriteObjects[uLayingItemID].spell_id - 1] + 1;
+    pAudioPlayer->PlaySound((SoundID)v125, v124, 0, -1, 0, v97, 0, 0);
+    return 0;
   }
-  v117 = pSpriteObjects[uLayingItemID].uType + 1;
-  v118 = pObjectList->uNumObjects;
-  v119 = 0;
-  v44 = pObjectList->uNumObjects == 0;
-  v20 = (pObjectList->uNumObjects & 0x80000000u) != 0;
-  pSpriteObjects[uLayingItemID].uType = v117;
-  if ( v20 | v44 )
-  {
-    v121 = 0;
-  }
-  else
+  pSpriteObjects[uLayingItemID].uType = pSpriteObjects[uLayingItemID].uType + 1;
+  v121 = 0;
+  for ( v119 = 0; v119 < (signed int)pObjectList->uNumObjects; ++v119 )
   {
-    v120 = (char *)&pObjectList->pObjects->uObjectID;
-    while ( v117 != *(short *)v120 )
-    {
-      ++v119;
-      v120 += 56;
-      if ( v119 >= (signed int)v118 )
-      {
-        v121 = 0;
-        pSpriteObjects[uLayingItemID].uObjectDescID = v121;
-        if ( !v121 )
-          SpriteObject::OnInteraction(v153);
-        pSpriteObjects[uLayingItemID].vVelocity.z = 0;
-        pSpriteObjects[uLayingItemID].vVelocity.y = 0;
-        pSpriteObjects[uLayingItemID].vVelocity.x = 0;
-        pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
-        v13 = 8 * v153;
-        LOBYTE(v13) = PID(OBJECT_Item,v153);
-        pAudioPlayer->PlaySound(SOUND_8, v13, v9, -1, v9, v9, v9, v9);
-        return 0;
-      }
-    }
-    v121 = v119;
+    if ( pSpriteObjects[uLayingItemID].uType == pObjectList->pObjects[v119].uObjectID )
+      v121 = v119;
   }
   pSpriteObjects[uLayingItemID].uObjectDescID = v121;
   if ( !v121 )
-    SpriteObject::OnInteraction(v153);
+    SpriteObject::OnInteraction(uLayingItemID);
   pSpriteObjects[uLayingItemID].vVelocity.z = 0;
   pSpriteObjects[uLayingItemID].vVelocity.y = 0;
   pSpriteObjects[uLayingItemID].vVelocity.x = 0;
   pSpriteObjects[uLayingItemID].uSpriteFrameID = 0;
-  v13 = 8 * v153;
-  LOBYTE(v13) = PID(OBJECT_Item,v153);
-  pAudioPlayer->PlaySound(SOUND_8, v13, v9, -1, v9, v9, v9, v9);
+  v13 = 8 * uLayingItemID;
+  LOBYTE(v13) = PID(OBJECT_Item,uLayingItemID);
+  pAudioPlayer->PlaySound(SOUND_8, v13, 0, -1, 0, 0, 0, 0);
   return 0;
 }
--- a/mm7_3.cpp	Fri Dec 20 01:25:52 2013 +0100
+++ b/mm7_3.cpp	Fri Dec 20 01:28:39 2013 +0100
@@ -210,7 +210,7 @@
 
   a11 = ecx0;
 
-  BLVFace f; // [sp+Ch] [bp-7Ch]@1
+  BLVFace face; // [sp+Ch] [bp-7Ch]@1
 
   result = 0;
   for ( a10 = 0; a10 < (signed int)pOutdoor->uNumBModels; ++a10 )
@@ -225,51 +225,51 @@
           && stru_721530.sMaxY <= pOutdoor->pBModels[a10].pFaces[v3].pBoundingBox.y2 && stru_721530.sMinY >= pOutdoor->pBModels[a10].pFaces[v3].pBoundingBox.y1
           && stru_721530.sMaxZ <= pOutdoor->pBModels[a10].pFaces[v3].pBoundingBox.z2 && stru_721530.sMinZ >= pOutdoor->pBModels[a10].pFaces[v3].pBoundingBox.z1 )
         {
-          f.pFacePlane_old.vNormal.x = pOutdoor->pBModels[a10].pFaces[v3].pFacePlane.vNormal.x;
-          f.pFacePlane_old.vNormal.y = pOutdoor->pBModels[a10].pFaces[v3].pFacePlane.vNormal.y;
-          f.pFacePlane_old.vNormal.z = pOutdoor->pBModels[a10].pFaces[v3].pFacePlane.vNormal.z;
-          f.pFacePlane_old.dist = pOutdoor->pBModels[a10].pFaces[v3].pFacePlane.dist;
-          f.uAttributes = pOutdoor->pBModels[a10].pFaces[v3].uAttributes;
-          f.pBounding.x1 = pOutdoor->pBModels[a10].pFaces[v3].pBoundingBox.x1;
-          f.pBounding.y1 = pOutdoor->pBModels[a10].pFaces[v3].pBoundingBox.y1;
-          f.pBounding.z1 = pOutdoor->pBModels[a10].pFaces[v3].pBoundingBox.z1;
-          f.pBounding.x2 = pOutdoor->pBModels[a10].pFaces[v3].pBoundingBox.x2;
-          f.pBounding.y2 = pOutdoor->pBModels[a10].pFaces[v3].pBoundingBox.y2;
-          f.pBounding.z2 = pOutdoor->pBModels[a10].pFaces[v3].pBoundingBox.z2;
-          f.zCalc1 = pOutdoor->pBModels[a10].pFaces[v3].zCalc1;
-          f.zCalc2 = pOutdoor->pBModels[a10].pFaces[v3].zCalc2;
-          f.zCalc3 = pOutdoor->pBModels[a10].pFaces[v3].zCalc3;
-          f.pXInterceptDisplacements = pOutdoor->pBModels[a10].pFaces[v3].pXInterceptDisplacements;
-          f.pYInterceptDisplacements = pOutdoor->pBModels[a10].pFaces[v3].pYInterceptDisplacements;
-          f.pZInterceptDisplacements = pOutdoor->pBModels[a10].pFaces[v3].pZInterceptDisplacements;
-          f.uPolygonType = (PolygonType)pOutdoor->pBModels[a10].pFaces[v3].uPolygonType;
-          f.uNumVertices = pOutdoor->pBModels[a10].pFaces[v3].uNumVertices;
-          f.uBitmapID = pOutdoor->pBModels[a10].pFaces[v3].uTextureID;
-          f.pVertexIDs = pOutdoor->pBModels[a10].pFaces[v3].pVertexIDs;
-          if ( !f.Ethereal() && !f.Portal() )
+          face.pFacePlane_old.vNormal.x = pOutdoor->pBModels[a10].pFaces[v3].pFacePlane.vNormal.x;
+          face.pFacePlane_old.vNormal.y = pOutdoor->pBModels[a10].pFaces[v3].pFacePlane.vNormal.y;
+          face.pFacePlane_old.vNormal.z = pOutdoor->pBModels[a10].pFaces[v3].pFacePlane.vNormal.z;
+          face.pFacePlane_old.dist = pOutdoor->pBModels[a10].pFaces[v3].pFacePlane.dist;
+          face.uAttributes = pOutdoor->pBModels[a10].pFaces[v3].uAttributes;
+          face.pBounding.x1 = pOutdoor->pBModels[a10].pFaces[v3].pBoundingBox.x1;
+          face.pBounding.y1 = pOutdoor->pBModels[a10].pFaces[v3].pBoundingBox.y1;
+          face.pBounding.z1 = pOutdoor->pBModels[a10].pFaces[v3].pBoundingBox.z1;
+          face.pBounding.x2 = pOutdoor->pBModels[a10].pFaces[v3].pBoundingBox.x2;
+          face.pBounding.y2 = pOutdoor->pBModels[a10].pFaces[v3].pBoundingBox.y2;
+          face.pBounding.z2 = pOutdoor->pBModels[a10].pFaces[v3].pBoundingBox.z2;
+          face.zCalc1 = pOutdoor->pBModels[a10].pFaces[v3].zCalc1;
+          face.zCalc2 = pOutdoor->pBModels[a10].pFaces[v3].zCalc2;
+          face.zCalc3 = pOutdoor->pBModels[a10].pFaces[v3].zCalc3;
+          face.pXInterceptDisplacements = pOutdoor->pBModels[a10].pFaces[v3].pXInterceptDisplacements;
+          face.pYInterceptDisplacements = pOutdoor->pBModels[a10].pFaces[v3].pYInterceptDisplacements;
+          face.pZInterceptDisplacements = pOutdoor->pBModels[a10].pFaces[v3].pZInterceptDisplacements;
+          face.uPolygonType = (PolygonType)pOutdoor->pBModels[a10].pFaces[v3].uPolygonType;
+          face.uNumVertices = pOutdoor->pBModels[a10].pFaces[v3].uNumVertices;
+          face.uBitmapID = pOutdoor->pBModels[a10].pFaces[v3].uTextureID;
+          face.pVertexIDs = pOutdoor->pBModels[a10].pFaces[v3].pVertexIDs;
+          if ( !face.Ethereal() && !face.Portal() )
           {
-            v8 = (f.pFacePlane_old.dist + f.pFacePlane_old.vNormal.x * stru_721530.normal.x
-                                        + f.pFacePlane_old.vNormal.y * stru_721530.normal.y
-                                        + f.pFacePlane_old.vNormal.z * stru_721530.normal.z ) >> 16;
+            v8 = (face.pFacePlane_old.dist + face.pFacePlane_old.vNormal.x * stru_721530.normal.x
+                                        + face.pFacePlane_old.vNormal.y * stru_721530.normal.y
+                                        + face.pFacePlane_old.vNormal.z * stru_721530.normal.z ) >> 16;
             if ( v8 > 0 )
             {
-              v9 = (f.pFacePlane_old.dist + f.pFacePlane_old.vNormal.x * stru_721530.normal2.x
-                                          + f.pFacePlane_old.vNormal.y * stru_721530.normal2.y
-                                          + f.pFacePlane_old.vNormal.z * stru_721530.normal2.z) >> 16;
+              v9 = (face.pFacePlane_old.dist + face.pFacePlane_old.vNormal.x * stru_721530.normal2.x
+                                          + face.pFacePlane_old.vNormal.y * stru_721530.normal2.y
+                                          + face.pFacePlane_old.vNormal.z * stru_721530.normal2.z) >> 16;
               if ( v8 <= stru_721530.prolly_normal_d || v9 <= stru_721530.prolly_normal_d )
               {
                 if ( v9 <= v8 )
                 {
                   a2 = stru_721530.field_6C;
                   if ( sub_4754BF(stru_721530.prolly_normal_d, &a2, stru_721530.normal.x, stru_721530.normal.y, stru_721530.normal.z,
-                            stru_721530.direction.x, stru_721530.direction.y, stru_721530.direction.z, &f, a10, a11) )
+                            stru_721530.direction.x, stru_721530.direction.y, stru_721530.direction.z, &face, a10, a11) )
                   {
                     v10 = a2;
                   }
                   else
                   {
                     a2 = stru_721530.prolly_normal_d + stru_721530.field_6C;
-                    if ( !sub_475F30( &a2, &f, stru_721530.normal.x, stru_721530.normal.y, stru_721530.normal.z,
+                    if ( !sub_475F30( &a2, &face, stru_721530.normal.x, stru_721530.normal.y, stru_721530.normal.z,
                              stru_721530.direction.x, stru_721530.direction.y, stru_721530.direction.z, a10) )
                       goto LABEL_29;
                     v10 = a2 - stru_721530.prolly_normal_d;
@@ -288,21 +288,21 @@
 LABEL_29:
             if ( stru_721530.field_0 & 1 )
             {
-              v15 = (f.pFacePlane_old.dist + f.pFacePlane_old.vNormal.x * stru_721530.position.x
-                                           + f.pFacePlane_old.vNormal.y * stru_721530.position.y
-                                           + f.pFacePlane_old.vNormal.z * stru_721530.position.z) >> 16;
+              v15 = (face.pFacePlane_old.dist + face.pFacePlane_old.vNormal.x * stru_721530.position.x
+                                           + face.pFacePlane_old.vNormal.y * stru_721530.position.y
+                                           + face.pFacePlane_old.vNormal.z * stru_721530.position.z) >> 16;
               if ( v15 > 0 )
               {
-                v16 = (f.pFacePlane_old.dist + f.pFacePlane_old.vNormal.x * stru_721530.field_4C
-                                             + f.pFacePlane_old.vNormal.y * stru_721530.field_50
-                                             + f.pFacePlane_old.vNormal.z * stru_721530.field_54) >> 16;
+                v16 = (face.pFacePlane_old.dist + face.pFacePlane_old.vNormal.x * stru_721530.field_4C
+                                             + face.pFacePlane_old.vNormal.y * stru_721530.field_50
+                                             + face.pFacePlane_old.vNormal.z * stru_721530.field_54) >> 16;
                 if ( v15 <= stru_721530.prolly_normal_d || v16 <= stru_721530.prolly_normal_d )
                 {
                   if ( v16 <= v15 )
                   {
                     a2 = stru_721530.field_6C;
                     if ( sub_4754BF(stru_721530.field_8_radius, &a2, stru_721530.position.x, stru_721530.position.y, stru_721530.position.z,
-                             stru_721530.direction.x, stru_721530.direction.y, stru_721530.direction.z, &f, a10, a11) )
+                             stru_721530.direction.x, stru_721530.direction.y, stru_721530.direction.z, &face, a10, a11) )
                     {
                       if ( a2 < stru_721530.field_7C )
                       {
@@ -315,7 +315,7 @@
                     else
                     {
                       a2 = stru_721530.field_6C + stru_721530.field_8_radius;
-                      if ( sub_475F30(&a2, &f, stru_721530.position.x, stru_721530.position.y, stru_721530.position.z,
+                      if ( sub_475F30(&a2, &face, stru_721530.position.x, stru_721530.position.y, stru_721530.position.z,
                                      stru_721530.direction.x, stru_721530.direction.y, stru_721530.direction.z, a10) )
                       {
                         v21 = a2 - stru_721530.prolly_normal_d;
@@ -371,38 +371,32 @@
   int v10; // ecx@12
   int v11; // esi@13
 
-  if ( (signed int)uNumSpriteObjects > 0 )
+  for ( uint i = 0; i < uNumSpriteObjects; ++i )
   {
-    for ( uint i = 0; i < uNumSpriteObjects; ++i )
+    if ( pSpriteObjects[i].uObjectDescID )
     {
-      if ( pSpriteObjects[i].uObjectDescID )
+      object = &pObjectList->pObjects[pSpriteObjects[i].uObjectDescID];
+      if ( !(object->uFlags & OBJECT_DESC_NO_COLLISION) )
       {
-        object = &pObjectList->pObjects[pSpriteObjects[i].uObjectDescID];
-        if ( !(object->uFlags & OBJECT_DESC_NO_COLLISION) )
+        if ( stru_721530.sMaxX <= pSpriteObjects[i].vPosition.x + object->uRadius && stru_721530.sMinX >= pSpriteObjects[i].vPosition.x - object->uRadius
+          && stru_721530.sMaxY <= pSpriteObjects[i].vPosition.y + object->uRadius && stru_721530.sMinY >= pSpriteObjects[i].vPosition.y - object->uRadius
+          && stru_721530.sMaxZ <= pSpriteObjects[i].vPosition.z + object->uHeight && stru_721530.sMinZ >= pSpriteObjects[i].vPosition.z )
         {
-          if ( stru_721530.sMaxX <= pSpriteObjects[i].vPosition.x + object->uRadius
-            && stru_721530.sMinX >= pSpriteObjects[i].vPosition.x - object->uRadius
-            && stru_721530.sMaxY <= pSpriteObjects[i].vPosition.y + object->uRadius
-            && stru_721530.sMinY >= pSpriteObjects[i].vPosition.y - object->uRadius
-            && stru_721530.sMaxZ <= pSpriteObjects[i].vPosition.z + object->uHeight
-            && stru_721530.sMinZ >= pSpriteObjects[i].vPosition.z )
+          if ( abs(((pSpriteObjects[i].vPosition.x - stru_721530.normal.x) * stru_721530.direction.y
+                  - (pSpriteObjects[i].vPosition.y - stru_721530.normal.y) * stru_721530.direction.x) >> 16)
+                  <= object->uHeight + stru_721530.prolly_normal_d )
           {
-            if ( abs(((pSpriteObjects[i].vPosition.x - stru_721530.normal.x) * stru_721530.direction.y
-                    - (pSpriteObjects[i].vPosition.y - stru_721530.normal.y) * stru_721530.direction.x) >> 16) <= object->uHeight
-                                                                                    + stru_721530.prolly_normal_d )
+            v10 = ((pSpriteObjects[i].vPosition.x - stru_721530.normal.x) * stru_721530.direction.x
+                 + (pSpriteObjects[i].vPosition.y - stru_721530.normal.y) * stru_721530.direction.y) >> 16;
+            if ( v10 > 0 )
             {
-              v10 = ((pSpriteObjects[i].vPosition.x - stru_721530.normal.x) * stru_721530.direction.x
-                   + (pSpriteObjects[i].vPosition.y - stru_721530.normal.y) * stru_721530.direction.y) >> 16;
-              if ( v10 > 0 )
+              v11 = stru_721530.normal.z + ((unsigned __int64)(stru_721530.direction.z * (signed __int64)v10) >> 16);
+              if ( v11 >= pSpriteObjects[i].vPosition.z - stru_721530.prolly_normal_d )
               {
-                v11 = stru_721530.normal.z + ((unsigned __int64)(stru_721530.direction.z * (signed __int64)v10) >> 16);
-                if ( v11 >= pSpriteObjects[i].vPosition.z - stru_721530.prolly_normal_d )
+                if ( v11 <= object->uHeight + stru_721530.prolly_normal_d + pSpriteObjects[i].vPosition.z )
                 {
-                  if ( v11 <= object->uHeight + stru_721530.prolly_normal_d + pSpriteObjects[i].vPosition.z )
-                  {
-                    if ( v10 < stru_721530.field_7C )
-                      sub_46DEF2(_this, i);
-                  }
+                  if ( v10 < stru_721530.field_7C )
+                    sub_46DEF2(_this, i);
                 }
               }
             }
@@ -416,35 +410,29 @@
 //----- (0046EF01) --------------------------------------------------------
 int _46EF01_collision_chech_player(int a1)
 {
-  int v1; // edx@1
   int result; // eax@1
   int v3; // ebx@7
   int v4; // esi@7
   int v5; // edi@8
   int v6; // ecx@9
   int v7; // edi@12
-  int v8; // [sp+Ch] [bp-10h]@1
-  unsigned int v9; // [sp+10h] [bp-Ch]@1
   int v10; // [sp+14h] [bp-8h]@7
   int v11; // [sp+18h] [bp-4h]@7
 
-  v8 = a1;
-  v1 = 2 * pParty->field_14_radius;
   result = pParty->vPosition.x;
-  v9 = pParty->uPartyHeight;
-  if ( stru_721530.sMaxX <= pParty->vPosition.x + v1 && stru_721530.sMinX >= pParty->vPosition.x - v1
-    && stru_721530.sMaxY <= pParty->vPosition.y + v1 && stru_721530.sMinY >= pParty->vPosition.y - v1
-    && stru_721530.sMaxZ <= (signed int)(pParty->vPosition.z + pParty->uPartyHeight)
-    && stru_721530.sMinZ >= pParty->vPosition.z )
+  //v9 = pParty->uPartyHeight;
+  if ( stru_721530.sMaxX <= pParty->vPosition.x + (2 * pParty->field_14_radius) && stru_721530.sMinX >= pParty->vPosition.x - (2 * pParty->field_14_radius)
+    && stru_721530.sMaxY <= pParty->vPosition.y + (2 * pParty->field_14_radius) && stru_721530.sMinY >= pParty->vPosition.y - (2 * pParty->field_14_radius)
+    && stru_721530.sMaxZ <= pParty->vPosition.z + pParty->uPartyHeight && stru_721530.sMinZ >= pParty->vPosition.z )
   {
-    v3 = stru_721530.prolly_normal_d + v1;
+    v3 = stru_721530.prolly_normal_d + (2 * pParty->field_14_radius);
     v11 = pParty->vPosition.x - stru_721530.normal.x;
     v4 = ((pParty->vPosition.x - stru_721530.normal.x) * stru_721530.direction.y
         - (pParty->vPosition.y - stru_721530.normal.y) * stru_721530.direction.x) >> 16;
     v10 = pParty->vPosition.y - stru_721530.normal.y;
     result = abs(((pParty->vPosition.x - stru_721530.normal.x) * stru_721530.direction.y
                 - (pParty->vPosition.y - stru_721530.normal.y) * stru_721530.direction.x) >> 16);
-    if ( result <= stru_721530.prolly_normal_d + v1 )
+    if ( result <= stru_721530.prolly_normal_d + (2 * pParty->field_14_radius) )
     {
       result = v10 * stru_721530.direction.y;
       v5 = (v10 * stru_721530.direction.y + v11 * stru_721530.direction.x) >> 16;
@@ -454,8 +442,8 @@
         result = pParty->vPosition.z;
         if ( v6 >= pParty->vPosition.z )
         {
-          result = v9 + pParty->vPosition.z;
-          if ( v6 <= (signed int)(v9 + pParty->vPosition.z) || v8 )
+          result = pParty->uPartyHeight + pParty->vPosition.z;
+          if ( v6 <= (signed int)(pParty->uPartyHeight + pParty->vPosition.z) || a1 )
           {
             result = integer_sqrt(v3 * v3 - v4 * v4);
             v7 = v5 - integer_sqrt(v3 * v3 - v4 * v4);
@@ -535,35 +523,13 @@
 //----- (0047050A) --------------------------------------------------------
 int stru141_actor_collision_object::_47050A(int dt)
 {
-  //stru141_actor_collision_object *v2; // esi@1
-  //signed int v3; // eax@1
-  //int v4; // ecx@1
-  //int v5; // edx@1
-  //int v6; // edx@1
   int v7; // eax@1
-  //int v8; // eax@3
   signed int result; // eax@4
-  //int v10; // eax@5
-  //int v11; // eax@5
-  //int v12; // ebx@5
-  //int v13; // edx@5
-  //int v14; // edi@5
-  //int v15; // ecx@5
-  //int v16; // eax@5
   int v17; // eax@5
   int v18; // eax@7
-  //int v19; // edx@9
-  //int v20; // edi@9
   int v21; // eax@9
   int v22; // eax@11
-  //int v23; // edx@13
-  //int v24; // eax@13
-  //int v25; // eax@14
-  //int v26; // eax@16
-  //int v27; // eax@17
-  //int v28; // [sp+14h] [bp+8h]@5
-
-  //v2 = this;
+
   int speed = 1 | integer_sqrt(this->velocity.z * this->velocity.z + this->velocity.y * this->velocity.y + this->velocity.x * this->velocity.x);
 
   this->direction.x = 65536 / speed * this->velocity.x;
@@ -681,7 +647,6 @@
   int v71; // [sp+38h] [bp-18h]@62
   int uIsAboveFloor; // [sp+3Ch] [bp-14h]@10
   int v72b;
-  //int v73; // [sp+40h] [bp-10h]@17
   int uIsFlying; // [sp+44h] [bp-Ch]@8
   unsigned int v75; // [sp+48h] [bp-8h]@1
   int uIsOnWater; // [sp+4Ch] [bp-4h]@10
@@ -997,14 +962,10 @@
 void UpdateObjects()
 {
   unsigned int v0; // ebx@0
-  //unsigned int v1; // edi@1
-  //char *v2; // esi@2
-  //__int16 v3; // dx@5
   ObjectDesc *object; // eax@5
   int v5; // ecx@6
   __int16 v6; // cx@7
   signed int v7; // eax@9
-  //unsigned int v10; // ecx@16
   signed int v11; // eax@17
   int v12; // edi@27
   int v13; // eax@27
@@ -1014,103 +975,94 @@
   unsigned int v17; // edx@32
   int v18; // [sp+4h] [bp-10h]@27
   int v19; // [sp+8h] [bp-Ch]@27
-  //signed int v20; // [sp+10h] [bp-4h]@1
-
-  //v1 = 0;
-  //v20 = 0;
+
   for (uint i = 0; i < uNumSpriteObjects; ++i)
   {
-    SpriteObject* item = &pSpriteObjects[i];
-    //v2 = (char *)&item->uSpriteFrameID;
-    //do
-    //{
-      //LOWORD(v0) = item->uAttributes;
-    if (item->uAttributes & OBJECT_40)
-      item->uAttributes &= ~OBJECT_40;
+    if (pSpriteObjects[i].uAttributes & OBJECT_40)
+      pSpriteObjects[i].uAttributes &= ~OBJECT_40;
     else
     {
-      object = &pObjectList->pObjects[item->uObjectDescID];
-      if (item->AttachedToActor())
+      object = &pObjectList->pObjects[pSpriteObjects[i].uObjectDescID];
+      if (pSpriteObjects[i].AttachedToActor())
       {
-          v5 = PID_ID(item->spell_target_pid);
-          item->vPosition.x = pActors[v5].vPosition.x;
-          item->vPosition.y = pActors[v5].vPosition.y;
-          item->vPosition.z = pActors[v5].vPosition.z + pActors[v5].uActorHeight;
-          if ( !item->uObjectDescID )
-            continue;
-          item->uSpriteFrameID += pEventTimer->uTimeElapsed;
-          if ( !(object->uFlags & OBJECT_DESC_TEMPORARY))
-            continue;
-          if ( item->uSpriteFrameID >= 0 )
-          {
-            v7 = object->uLifetime;
-            if (item->uAttributes & ITEM_BROKEN)
-              v7 = item->field_20;
-            if ( item->uSpriteFrameID < v7 )
-              continue;
-          }
-          SpriteObject::OnInteraction(i);
+        v5 = PID_ID(pSpriteObjects[i].spell_target_pid);
+        pSpriteObjects[i].vPosition.x = pActors[v5].vPosition.x;
+        pSpriteObjects[i].vPosition.y = pActors[v5].vPosition.y;
+        pSpriteObjects[i].vPosition.z = pActors[v5].vPosition.z + pActors[v5].uActorHeight;
+        if ( !pSpriteObjects[i].uObjectDescID )
           continue;
-      }
-
-        if ( item->uObjectDescID )
+        pSpriteObjects[i].uSpriteFrameID += pEventTimer->uTimeElapsed;
+        if ( !(object->uFlags & OBJECT_DESC_TEMPORARY))
+          continue;
+        if ( pSpriteObjects[i].uSpriteFrameID >= 0 )
         {
-          item->uSpriteFrameID += pEventTimer->uTimeElapsed;
-          if ( object->uFlags & OBJECT_DESC_TEMPORARY )
-          {
-            if ( item->uSpriteFrameID < 0 )
-            {
-              SpriteObject::OnInteraction(i);
-              continue;
-            }
-            v11 = object->uLifetime;
-            if (item->uAttributes & ITEM_BROKEN)
-              v11 = item->field_20;
-          }
-          if ( !(object->uFlags & OBJECT_DESC_TEMPORARY) || item->uSpriteFrameID < v11 )
-          {
-            if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
-              SpriteObject::UpdateObject_fn0_BLV(i);
-            else
-              SpriteObject::UpdateObject_fn0_ODM(i);
-			if ( pParty->bTurnBasedModeOn != 1 || !(item->uSectorID & 4) )
-              continue;
-			v12 = abs(pParty->vPosition.x - item->vPosition.x);
-			v18 = abs(pParty->vPosition.y - item->vPosition.y);
-			v19 = abs(pParty->vPosition.z - item->vPosition.z);
-            v13 = v12;
-            v14 = v18;
-            v15 = v19;
-            if ( v12 < v18 )
-            {
-              v13 = v18;
-              v14 = v12;
-            }
-            if ( v13 < v19 )
-            {
-              v16 = v13;
-              v13 = v19;
-              v15 = v16;
-            }
-            if ( v14 < (signed int)v15 )
-            {
-              v17 = v15;
-              v15 = v14;
-              v14 = v17;
-            }
-            v0 = (unsigned int)(11 * v14) >> 5;
-            if ( (signed int)(v0 + (v15 >> 2) + v13) <= 5120 )
-              continue;
-            SpriteObject::OnInteraction(i);
-            continue;
-          }
-          if ( !(object->uFlags & OBJECT_DESC_INTERACTABLE) )
+          v7 = object->uLifetime;
+          if (pSpriteObjects[i].uAttributes & ITEM_BROKEN)
+             v7 = pSpriteObjects[i].field_20;
+          if ( pSpriteObjects[i].uSpriteFrameID < v7 )
+             continue;
+        }
+        SpriteObject::OnInteraction(i);
+        continue;
+      }
+      if ( pSpriteObjects[i].uObjectDescID )
+      {
+        pSpriteObjects[i].uSpriteFrameID += pEventTimer->uTimeElapsed;
+        if ( object->uFlags & OBJECT_DESC_TEMPORARY )
+        {
+          if ( pSpriteObjects[i].uSpriteFrameID < 0 )
           {
             SpriteObject::OnInteraction(i);
             continue;
           }
-          _46BFFA_check_object_intercept(i, PID(OBJECT_Item,i));
+          v11 = object->uLifetime;
+          if (pSpriteObjects[i].uAttributes & ITEM_BROKEN)
+            v11 = pSpriteObjects[i].field_20;
         }
+        if ( !(object->uFlags & OBJECT_DESC_TEMPORARY) || pSpriteObjects[i].uSpriteFrameID < v11 )
+        {
+          if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
+            SpriteObject::UpdateObject_fn0_BLV(i);
+          else
+            SpriteObject::UpdateObject_fn0_ODM(i);
+          if ( pParty->bTurnBasedModeOn != 1 || !(pSpriteObjects[i].uSectorID & 4) )
+            continue;
+          v12 = abs(pParty->vPosition.x - pSpriteObjects[i].vPosition.x);
+          v18 = abs(pParty->vPosition.y - pSpriteObjects[i].vPosition.y);
+          v19 = abs(pParty->vPosition.z - pSpriteObjects[i].vPosition.z);
+          v13 = v12;
+          v14 = v18;
+          v15 = v19;
+          if ( v12 < v18 )
+          {
+            v13 = v18;
+            v14 = v12;
+          }
+          if ( v13 < v19 )
+          {
+            v16 = v13;
+            v13 = v19;
+            v15 = v16;
+          }
+          if ( v14 < (signed int)v15 )
+          {
+            v17 = v15;
+            v15 = v14;
+            v14 = v17;
+          }
+          v0 = (unsigned int)(11 * v14) >> 5;
+          if ( (signed int)(v0 + (v15 >> 2) + v13) <= 5120 )
+            continue;
+          SpriteObject::OnInteraction(i);
+          continue;
+        }
+        if ( !(object->uFlags & OBJECT_DESC_INTERACTABLE) )
+        {
+          SpriteObject::OnInteraction(i);
+          continue;
+        }
+        _46BFFA_check_object_intercept(i, PID(OBJECT_Item,i));
+      }
     }
   }
 }
@@ -1118,32 +1070,26 @@
 //----- (0047272C) --------------------------------------------------------
 int collide_against_floor_approximate(int x, int y, int z, unsigned int *pSectorID, unsigned int *pFaceID)
 {
-  signed int v5; // ebx@1
   int result; // eax@1
-  int v7; // [sp+10h] [bp-8h]@1
-  signed int v8; // [sp+14h] [bp-4h]@1
-
-  v5 = x - 2;
-  v7 = x;
-  v8 = y;
+
   *pSectorID = pIndoor->GetSector(x - 2, y, z + 40);
-  result = collide_against_floor(v5, v8, z + 40, pSectorID, pFaceID);
+  result = collide_against_floor(x - 2, y, z + 40, pSectorID, pFaceID);
   if ( result == -30000 || !*pSectorID )
   {
-    *pSectorID = pIndoor->GetSector(v7 + 2, v8, z + 40);
-    result = collide_against_floor(v7 + 2, v8, z + 40, pSectorID, pFaceID);
+    *pSectorID = pIndoor->GetSector(x + 2, y, z + 40);
+    result = collide_against_floor(x + 2, y, z + 40, pSectorID, pFaceID);
     if ( result == -30000 || !*pSectorID )
     {
-      *pSectorID = pIndoor->GetSector(v7, v8 - 2, z + 40);
-      result = collide_against_floor(v7, v8 - 2, z + 40, pSectorID, pFaceID);
+      *pSectorID = pIndoor->GetSector(x, y - 2, z + 40);
+      result = collide_against_floor(x, y - 2, z + 40, pSectorID, pFaceID);
       if ( result == -30000 || !*pSectorID )
       {
-        *pSectorID = pIndoor->GetSector(v7, v8 + 2, z + 40);
-        result = collide_against_floor(v7, v8 + 2, z + 40, pSectorID, pFaceID);
+        *pSectorID = pIndoor->GetSector(x, y + 2, z + 40);
+        result = collide_against_floor(x, y + 2, z + 40, pSectorID, pFaceID);
         if ( result == -30000 || !*pSectorID )
         {
-          *pSectorID = pIndoor->GetSector(v7, v8, z + 140);
-          result = collide_against_floor(v7, v8, z + 140, pSectorID, pFaceID);
+          *pSectorID = pIndoor->GetSector(x, y, z + 140);
+          result = collide_against_floor(x, y, z + 140, pSectorID, pFaceID);
         }
       }
     }
@@ -1272,25 +1218,9 @@
 }
 
 //----- (00475665) --------------------------------------------------------
-int sub_475665(BLVFace *_this, int a2, __int16 a3)
+int sub_475665(BLVFace *face, int a2, __int16 a3)
 {
-  unsigned int v3; // eax@1
-  Vec3_short_ *v4; // edx@3
-  signed int v5; // eax@4
-  int v6; // esi@4
-  signed int v7; // eax@7
-  Vec3_short_ *v8; // edx@8
-  signed int v9; // eax@9
-  int v10; // esi@9
-  signed int v11; // eax@11
-  Vec3_short_ *v12; // edx@12
-  signed int v13; // eax@13
-  int v14; // esi@13
-  int v15; // esi@14
   bool v16; // edi@14
-  int v17; // ecx@16
-  signed int v18; // edx@16
-  int v19; // eax@17
   signed int v20; // ebx@18
   int v21; // edi@20
   signed int v22; // ST14_4@22
@@ -1304,113 +1234,86 @@
   signed int v30; // [sp+30h] [bp+Ch]@11
   signed int v31; // [sp+30h] [bp+Ch]@14
 
-  v3 = _this->uAttributes;
-  if ( BYTE1(v3) & 1 )
+  if ( face->uAttributes & FACE_XY_PLANE )
   {
-    v28 = 0;
     v26 = (signed __int16)a2;
     v27 = SHIWORD(a2);
-    if ( _this->uNumVertices )
+    if ( face->uNumVertices )
     {
-      v4 = pIndoor->pVertices;
-      do
+      for ( v28 = 0; v28 < face->uNumVertices; v28++ )
       {
-        v5 = v28;
-        v6 = 2 * v28;
-        word_720C10_intercepts_xs[2 * v28] = _this->pXInterceptDisplacements[v28] + v4[_this->pVertexIDs[v28]].x;
-        word_720B40_intercepts_zs[2 * v28] = _this->pYInterceptDisplacements[v5] + v4[_this->pVertexIDs[v5]].y;
-        word_720C10_intercepts_xs[2 * v28++ + 1] = _this->pXInterceptDisplacements[v5 + 1]
-                                                 + v4[_this->pVertexIDs[v5 + 1]].x;
-        word_720B40_intercepts_zs[v6 + 1] = _this->pYInterceptDisplacements[v5 + 1] + v4[_this->pVertexIDs[v5 + 1]].y;
+        word_720C10_intercepts_xs[2 * v28] = face->pXInterceptDisplacements[v28] + pIndoor->pVertices[face->pVertexIDs[v28]].x;
+        word_720B40_intercepts_zs[2 * v28] = face->pYInterceptDisplacements[v28] + pIndoor->pVertices[face->pVertexIDs[v28]].y;
+        word_720C10_intercepts_xs[2 * v28 + 1] = face->pXInterceptDisplacements[v28 + 1] + pIndoor->pVertices[face->pVertexIDs[v28 + 1]].x;
+        word_720B40_intercepts_zs[2 * v28 + 1] = face->pYInterceptDisplacements[v28 + 1] + pIndoor->pVertices[face->pVertexIDs[v28 + 1]].y;
       }
-      while ( v28 < _this->uNumVertices );
     }
   }
   else
   {
-    if ( BYTE1(v3) & 2 )
+    if ( face->uAttributes & FACE_XZ_PLANE )
     {
       v26 = (signed __int16)a2;
-      v7 = a3;
-      v29 = 0;
-      v27 = v7;
-      if ( _this->uNumVertices )
+      v27 = a3;
+      if ( face->uNumVertices )
       {
-        v8 = pIndoor->pVertices;
-        do
+        for ( v29 = 0; v29 < face->uNumVertices; v29++ )
         {
-          v9 = v29;
-          v10 = 2 * v29;
-          word_720C10_intercepts_xs[2 * v29] = _this->pXInterceptDisplacements[v29] + v8[_this->pVertexIDs[v29]].x;
-          word_720B40_intercepts_zs[2 * v29] = _this->pZInterceptDisplacements[v9] + v8[_this->pVertexIDs[v9]].z;
-          word_720C10_intercepts_xs[2 * v29++ + 1] = _this->pXInterceptDisplacements[v9 + 1] + v8[_this->pVertexIDs[v9 + 1]].x;
-          word_720B40_intercepts_zs[v10 + 1] = _this->pZInterceptDisplacements[v9 + 1] + v8[_this->pVertexIDs[v9 + 1]].z;
+          word_720C10_intercepts_xs[2 * v29] = face->pXInterceptDisplacements[v29] + pIndoor->pVertices[face->pVertexIDs[v29]].x;
+          word_720B40_intercepts_zs[2 * v29] = face->pZInterceptDisplacements[v29] + pIndoor->pVertices[face->pVertexIDs[v29]].z;
+          word_720C10_intercepts_xs[2 * v29 + 1] = face->pXInterceptDisplacements[v29 + 1] + pIndoor->pVertices[face->pVertexIDs[v29 + 1]].x;
+          word_720B40_intercepts_zs[2 * v29 + 1] = face->pZInterceptDisplacements[v29 + 1] + pIndoor->pVertices[face->pVertexIDs[v29 + 1]].z;
         }
-        while ( v29 < _this->uNumVertices );
       }
     }
     else
     {
       v26 = SHIWORD(a2);
-      v11 = a3;
-      v30 = 0;
-      v27 = v11;
-      if ( _this->uNumVertices )
+      v27 = a3;
+      if ( face->uNumVertices )
       {
-        v12 = pIndoor->pVertices;
-        do
+        for ( v30 = 0; v30 < face->uNumVertices; v30++ )
         {
-          v13 = v30;
-          v14 = 2 * v30;
-          word_720C10_intercepts_xs[2 * v30] = _this->pYInterceptDisplacements[v30] + v12[_this->pVertexIDs[v30]].y;
-          word_720B40_intercepts_zs[2 * v30] = _this->pZInterceptDisplacements[v13] + v12[_this->pVertexIDs[v13]].z;
-          word_720C10_intercepts_xs[2 * v30++ + 1] = _this->pYInterceptDisplacements[v13 + 1] + v12[_this->pVertexIDs[v13 + 1]].y;
-          word_720B40_intercepts_zs[v14 + 1] = _this->pZInterceptDisplacements[v13 + 1] + v12[_this->pVertexIDs[v13 + 1]].z;
+          word_720C10_intercepts_xs[2 * v30] = face->pYInterceptDisplacements[v30] + pIndoor->pVertices[face->pVertexIDs[v30]].y;
+          word_720B40_intercepts_zs[2 * v30] = face->pZInterceptDisplacements[v30] + pIndoor->pVertices[face->pVertexIDs[v30]].z;
+          word_720C10_intercepts_xs[2 * v30 + 1] = face->pYInterceptDisplacements[v30 + 1] + pIndoor->pVertices[face->pVertexIDs[v30 + 1]].y;
+          word_720B40_intercepts_zs[2 * v30 + 1] = face->pZInterceptDisplacements[v30 + 1] + pIndoor->pVertices[face->pVertexIDs[v30 + 1]].z;
         }
-        while ( v30 < _this->uNumVertices );
       }
     }
   }
-  v15 = 2 * _this->uNumVertices;
   v31 = 0;
-  word_720C10_intercepts_xs[2 * _this->uNumVertices] = word_720C10_intercepts_xs[0];
-  word_720B40_intercepts_zs[v15] = word_720B40_intercepts_zs[0];
-  v25 = 0;
+  word_720C10_intercepts_xs[2 * face->uNumVertices] = word_720C10_intercepts_xs[0];
+  word_720B40_intercepts_zs[2 * face->uNumVertices] = word_720B40_intercepts_zs[0];
   v16 = word_720B40_intercepts_zs[0] >= v27;
-  if ( v15 <= 0 )
+  if ( 2 * face->uNumVertices <= 0 )
     return 0;
-  do
+  for ( v25 = 0; v25 < 2 * face->uNumVertices; ++v25 )
   {
     if ( v31 >= 2 )
       break;
-    v17 = v25;
-    v18 = word_720B40_intercepts_zs[v25 + 1];
-    if ( v16 ^ (v18 >= v27) )
+    if ( v16 ^ (word_720B40_intercepts_zs[v25 + 1] >= v27) )
     {
-      v19 = word_720C10_intercepts_xs[v17 + 1];
-      if ( v19 >= v26 )
+      if ( word_720C10_intercepts_xs[v25 + 1] >= v26 )
         v20 = 0;
       else
         v20 = 2;
-      v21 = v20 | (word_720C10_intercepts_xs[v17] < v26);
+      v21 = v20 | (word_720C10_intercepts_xs[v25] < v26);
       if ( v21 != 3 )
       {
+        v22 = word_720C10_intercepts_xs[v25 + 1] - word_720C10_intercepts_xs[v25];
+        LODWORD(v23) = v22 << 16;
+        HIDWORD(v23) = v22 >> 16;
         if ( !v21
-          || (v22 = v19 - word_720C10_intercepts_xs[v17],
-              LODWORD(v23) = v22 << 16,
-              HIDWORD(v23) = v22 >> 16,
-              word_720C10_intercepts_xs[v17]
-            + ((signed int)(((unsigned __int64)(v23
-                                              / (v18 - word_720B40_intercepts_zs[v17])
-                                              * ((v27 - (signed int)word_720B40_intercepts_zs[v17]) << 16)) >> 16)
-                          + 32768) >> 16) >= v26) )
+          || (word_720C10_intercepts_xs[v25] + ((signed int)(((unsigned __int64)(v23
+           / (word_720B40_intercepts_zs[v25 + 1] - word_720B40_intercepts_zs[v25])
+           * ((v27 - (signed int)word_720B40_intercepts_zs[v25]) << 16)) >> 16)
+               + 32768) >> 16) >= v26) )
           ++v31;
       }
     }
-    ++v25;
-    v16 = v18 >= v27;
+    v16 = word_720B40_intercepts_zs[v25 + 1] >= v27;
   }
-  while ( v25 < v15 );
   result = 1;
   if ( v31 != 1 )
     result = 0;
@@ -1418,20 +1321,9 @@
 }
 
 //----- (004759C9) --------------------------------------------------------
-bool __fastcall sub_4759C9(BLVFace *a1, int a2, int a3, __int16 a4)
+bool __fastcall sub_4759C9(BLVFace *face, int a2, int a3, __int16 a4)
 {
-  //unsigned int v4; // eax@1
-  //int v5; // edx@4
-  __int16 v6; // si@4
-  //int v7; // edx@9
-  __int16 v8; // si@9
-  //int v9; // edx@13
-  __int16 v10; // si@13
-  int v11; // esi@14
   bool v12; // edi@14
-  int v13; // ecx@16
-  signed int v14; // edx@16
-  int v15; // eax@17
   signed int v16; // ebx@18
   int v17; // edi@20
   signed int v18; // ST14_4@22
@@ -1441,113 +1333,88 @@
   signed int v22; // [sp+18h] [bp-Ch]@1
   int v23; // [sp+1Ch] [bp-8h]@2
   signed int v24; // [sp+20h] [bp-4h]@2
-  Vec3_int_ **a4a; // [sp+30h] [bp+Ch]@3
-  Vec3_int_ **a4b; // [sp+30h] [bp+Ch]@8
-  Vec3_int_ **a4c; // [sp+30h] [bp+Ch]@12
   signed int a4d; // [sp+30h] [bp+Ch]@14
 
-  //v4 = a1->uAttributes;
-  v22 = 0;
-  if ( BYTE1(a1->uAttributes) & 1 )
+  if ( face->uAttributes & FACE_XY_PLANE )
   {
     v23 = (signed __int16)a3;
     v24 = SHIWORD(a3);
-    if ( a1->uNumVertices )
+    if ( face->uNumVertices )
     {
-      a4a = &pOutdoor->pBModels[a2].pVertices.pVertices;
-      do
+      for ( v22 = 0; v22 < face->uNumVertices; ++v22 )
       {
-        //v5 = 2 * v22;
-        word_720A70_intercepts_xs_plus_xs[2 * v22] = a1->pXInterceptDisplacements[v22] + LOWORD((*a4a)[a1->pVertexIDs[v22]].x);
-        word_7209A0_intercepts_ys_plus_ys[2 * v22] = a1->pYInterceptDisplacements[v22] + LOWORD((*a4a)[a1->pVertexIDs[v22]].y);
-        word_720A70_intercepts_xs_plus_xs[2 * v22 + 1] = a1->pXInterceptDisplacements[v22 + 1] + LOWORD((*a4a)[a1->pVertexIDs[v22 + 1]].x);
-        word_7209A0_intercepts_ys_plus_ys[2 * v22 + 1] = v6 = a1->pYInterceptDisplacements[v22 + 1] + LOWORD((*a4a)[a1->pVertexIDs[v22 + 1]].y);
-        ++v22;
+        word_720A70_intercepts_xs_plus_xs[2 * v22] = face->pXInterceptDisplacements[v22] + LOWORD(pOutdoor->pBModels[a2].pVertices.pVertices[face->pVertexIDs[v22]].x);
+        word_7209A0_intercepts_ys_plus_ys[2 * v22] = face->pYInterceptDisplacements[v22] + LOWORD(pOutdoor->pBModels[a2].pVertices.pVertices[face->pVertexIDs[v22]].y);
+        word_720A70_intercepts_xs_plus_xs[2 * v22 + 1] = face->pXInterceptDisplacements[v22 + 1] + LOWORD(pOutdoor->pBModels[a2].pVertices.pVertices[face->pVertexIDs[v22 + 1]].x);
+        word_7209A0_intercepts_ys_plus_ys[2 * v22 + 1] = face->pYInterceptDisplacements[v22 + 1] + LOWORD(pOutdoor->pBModels[a2].pVertices.pVertices[face->pVertexIDs[v22 + 1]].y);
       }
-      while ( v22 < a1->uNumVertices );
     }
   }
   else
   {
-    if ( BYTE1(a1->uAttributes) & 2 )
+    if ( face->uAttributes & FACE_XZ_PLANE )
     {
       v23 = (signed __int16)a3;
       v24 = a4;
-      if ( a1->uNumVertices )
+      if ( face->uNumVertices )
       {
-        a4b = &pOutdoor->pBModels[a2].pVertices.pVertices;
-        do
+        for ( v22 = 0; v22 < face->uNumVertices; ++v22 )
         {
-          //v7 = 2 * v22;
-          word_720A70_intercepts_xs_plus_xs[2 * v22] = a1->pXInterceptDisplacements[v22] + LOWORD((*a4b)[a1->pVertexIDs[v22]].x);
-          word_7209A0_intercepts_ys_plus_ys[2 * v22] = a1->pZInterceptDisplacements[v22] + LOWORD((*a4b)[a1->pVertexIDs[v22]].z);
-          word_720A70_intercepts_xs_plus_xs[2 * v22 + 1] = a1->pXInterceptDisplacements[v22 + 1] + LOWORD((*a4b)[a1->pVertexIDs[v22 + 1]].x);
-          word_7209A0_intercepts_ys_plus_ys[2 * v22 + 1] = v8 = a1->pZInterceptDisplacements[v22 + 1] + LOWORD((*a4b)[a1->pVertexIDs[v22 + 1]].z);
-          ++v22;
+          word_720A70_intercepts_xs_plus_xs[2 * v22] = face->pXInterceptDisplacements[v22] + LOWORD(pOutdoor->pBModels[a2].pVertices.pVertices[face->pVertexIDs[v22]].x);
+          word_7209A0_intercepts_ys_plus_ys[2 * v22] = face->pZInterceptDisplacements[v22] + LOWORD(pOutdoor->pBModels[a2].pVertices.pVertices[face->pVertexIDs[v22]].z);
+          word_720A70_intercepts_xs_plus_xs[2 * v22 + 1] = face->pXInterceptDisplacements[v22 + 1] + LOWORD(pOutdoor->pBModels[a2].pVertices.pVertices[face->pVertexIDs[v22 + 1]].x);
+          word_7209A0_intercepts_ys_plus_ys[2 * v22 + 1] = face->pZInterceptDisplacements[v22 + 1] + LOWORD(pOutdoor->pBModels[a2].pVertices.pVertices[face->pVertexIDs[v22 + 1]].z);
         }
-        while ( v22 < a1->uNumVertices );
       }
     }
     else
     {
       v23 = SHIWORD(a3);
       v24 = a4;
-      if ( a1->uNumVertices )
+      if ( face->uNumVertices )
       {
-        a4c = &pOutdoor->pBModels[a2].pVertices.pVertices;
-        do
+        for ( v22 = 0; v22 < face->uNumVertices; ++v22 )
         {
-          //v9 = 2 * v22;
-          word_720A70_intercepts_xs_plus_xs[2 * v22] = a1->pYInterceptDisplacements[v22] + LOWORD((*a4c)[a1->pVertexIDs[v22]].y);
-          word_7209A0_intercepts_ys_plus_ys[2 * v22] = a1->pZInterceptDisplacements[v22] + LOWORD((*a4c)[a1->pVertexIDs[v22]].z);
-          word_720A70_intercepts_xs_plus_xs[2 * v22 + 1] = a1->pYInterceptDisplacements[v22 + 1] + LOWORD((*a4c)[a1->pVertexIDs[v22 + 1]].y);
-          word_7209A0_intercepts_ys_plus_ys[2 * v22 + 1] = v10 = a1->pZInterceptDisplacements[v22 + 1] + LOWORD((*a4c)[a1->pVertexIDs[v22 + 1]].z);
-          ++v22;
+          word_720A70_intercepts_xs_plus_xs[2 * v22] = face->pYInterceptDisplacements[v22] + LOWORD(pOutdoor->pBModels[a2].pVertices.pVertices[face->pVertexIDs[v22]].y);
+          word_7209A0_intercepts_ys_plus_ys[2 * v22] = face->pZInterceptDisplacements[v22] + LOWORD(pOutdoor->pBModels[a2].pVertices.pVertices[face->pVertexIDs[v22]].z);
+          word_720A70_intercepts_xs_plus_xs[2 * v22 + 1] = face->pYInterceptDisplacements[v22 + 1] + LOWORD(pOutdoor->pBModels[a2].pVertices.pVertices[face->pVertexIDs[v22 + 1]].y);
+          word_7209A0_intercepts_ys_plus_ys[2 * v22 + 1] = face->pZInterceptDisplacements[v22 + 1] + LOWORD(pOutdoor->pBModels[a2].pVertices.pVertices[face->pVertexIDs[v22 + 1]].z);
         }
-        while ( v22 < a1->uNumVertices );
       }
     }
   }
-  v11 = 2 * a1->uNumVertices;
   a4d = 0;
-  word_720A70_intercepts_xs_plus_xs[2 * a1->uNumVertices] = word_720A70_intercepts_xs_plus_xs[0];
-  word_7209A0_intercepts_ys_plus_ys[v11] = word_7209A0_intercepts_ys_plus_ys[0];
-  v21 = 0;
+  word_720A70_intercepts_xs_plus_xs[2 * face->uNumVertices] = word_720A70_intercepts_xs_plus_xs[0];
+  word_7209A0_intercepts_ys_plus_ys[2 * face->uNumVertices] = word_7209A0_intercepts_ys_plus_ys[0];
   v12 = word_7209A0_intercepts_ys_plus_ys[0] >= v24;
-  if ( v11 <= 0 )
+  if ( 2 * face->uNumVertices <= 0 )
     return 0;
-  do
+  for ( v21 = 0; v21 < 2 * face->uNumVertices; ++v21 )
   {
     if ( a4d >= 2 )
       break;
-    v13 = v21;
-    v14 = word_7209A0_intercepts_ys_plus_ys[v21 + 1];
-    if ( v12 ^ (v14 >= v24) )
+    if ( v12 ^ (word_7209A0_intercepts_ys_plus_ys[v21 + 1] >= v24) )
     {
-      v15 = word_720A70_intercepts_xs_plus_xs[v13 + 1];
-      if ( v15 >= v23 )
+      if ( word_720A70_intercepts_xs_plus_xs[v21 + 1] >= v23 )
         v16 = 0;
       else
         v16 = 2;
-      v17 = v16 | (word_720A70_intercepts_xs_plus_xs[v13] < v23);
+      v17 = v16 | (word_720A70_intercepts_xs_plus_xs[v21] < v23);
       if ( v17 != 3 )
       {
+        v18 = word_720A70_intercepts_xs_plus_xs[v21 + 1] - word_720A70_intercepts_xs_plus_xs[v21];
+        LODWORD(v19) = v18 << 16;
+        HIDWORD(v19) = v18 >> 16;
         if ( !v17
-          || (v18 = v15 - word_720A70_intercepts_xs_plus_xs[v13],
-              LODWORD(v19) = v18 << 16,
-              HIDWORD(v19) = v18 >> 16,
-              word_720A70_intercepts_xs_plus_xs[v13]
-            + ((signed int)(((unsigned __int64)(v19
-                                              / (v14 - word_7209A0_intercepts_ys_plus_ys[v13])
-                                              * ((v24 - (signed int)word_7209A0_intercepts_ys_plus_ys[v13]) << 16)) >> 16)
-                          + 32768) >> 16) >= v23) )
+          || (word_720A70_intercepts_xs_plus_xs[v21] + ((signed int)(((unsigned __int64)(v19
+              / (word_7209A0_intercepts_ys_plus_ys[v21 + 1] - word_7209A0_intercepts_ys_plus_ys[v21])
+              * ((v24 - (signed int)word_7209A0_intercepts_ys_plus_ys[v21]) << 16)) >> 16)
+              + 32768) >> 16) >= v23) )
           ++a4d;
       }
     }
-    ++v21;
-    v12 = v14 >= v24;
+    v12 = word_7209A0_intercepts_ys_plus_ys[v21 + 1] >= v24;
   }
-  while ( v21 < v11 );
   result = 1;
   if ( a4d != 1 )
     result = 0;
@@ -1617,24 +1484,19 @@
 //----- (00475F30) --------------------------------------------------------
 bool __fastcall sub_475F30(int *a1, BLVFace *a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9)
 {
-  //BLVFace *v9; // ebx@1
   int v10; // ST20_4@2
   int v11; // ST28_4@2
   int v12; // ST24_4@2
   char v13; // zf@2
   int v14; // edi@2
-  int v15; // eax@5
   signed int v16; // esi@5
   int v17; // ST20_4@9
   signed __int64 v18; // qtt@10
   int v19; // ST14_4@11
-  //int *v21; // [sp+14h] [bp-10h]@1
   int v22; // [sp+1Ch] [bp-8h]@2
   int v23; // [sp+1Ch] [bp-8h]@10
   signed int v24; // [sp+20h] [bp-4h]@10
 
-  //v9 = a2;
-  //v21 = a1;
   if ( a2->Ethereal()
     || (v10 = (unsigned __int64)(a6 * (signed __int64)a2->pFacePlane_old.vNormal.x) >> 16,
         v11 = (unsigned __int64)(a7 * (signed __int64)a2->pFacePlane_old.vNormal.y) >> 16,
@@ -1645,11 +1507,10 @@
         v13)
     || v14 > 0 && !a2->Portal())
     return 0;
-  v15 = a4 * a2->pFacePlane_old.vNormal.y;
-  v16 = -(a2->pFacePlane_old.dist + v15 + a3 * a2->pFacePlane_old.vNormal.x + a5 * a2->pFacePlane_old.vNormal.z);
+  v16 = -(a2->pFacePlane_old.dist + a4 * a2->pFacePlane_old.vNormal.y + a3 * a2->pFacePlane_old.vNormal.x + a5 * a2->pFacePlane_old.vNormal.z);
   if ( v14 <= 0 )
   {
-    if ( a2->pFacePlane_old.dist + v15 + a3 * a2->pFacePlane_old.vNormal.x + a5 * a2->pFacePlane_old.vNormal.z < 0 )
+    if ( a2->pFacePlane_old.dist + a4 * a2->pFacePlane_old.vNormal.y + a3 * a2->pFacePlane_old.vNormal.x + a5 * a2->pFacePlane_old.vNormal.z < 0 )
       return 0;
   }
   else
@@ -1657,7 +1518,7 @@
     if ( v16 < 0 )
       return 0;
   }
-  v17 = abs(-(a2->pFacePlane_old.dist + v15 + a3 * a2->pFacePlane_old.vNormal.x + a5 * a2->pFacePlane_old.vNormal.z)) >> 14;
+  v17 = abs(-(a2->pFacePlane_old.dist + a4 * a2->pFacePlane_old.vNormal.y + a3 * a2->pFacePlane_old.vNormal.x + a5 * a2->pFacePlane_old.vNormal.z)) >> 14;
   if ( v17 > abs(v14)
     || (LODWORD(v18) = v16 << 16, HIDWORD(v18) = v16 >> 16, v24 = v18 / v22, v23 = v18 / v22, v23 > *a1 << 16)
     || (LOWORD(v19) = a3 + (((unsigned int)((unsigned __int64)(v23 * (signed __int64)a6) >> 16) + 32768) >> 16),
@@ -1726,6 +1587,7 @@
   float v39; // [sp+D0h] [bp-8h]@6
   int *v40; // [sp+D4h] [bp-4h]@2
 
+  __debugbreak();//нужно почистить
   v2 = (char *)&this->field_64[4 * this->uNumVertices];
   v38 = 0;
   *(int *)v2 = this->field_64[0];
@@ -1873,6 +1735,7 @@
   float v39; // [sp+D0h] [bp-8h]@6
   int *v40; // [sp+D4h] [bp-4h]@2
 
+  __debugbreak();//нужно почистить
   v2 = (char *)&this->field_64[4 * this->uNumVertices];
   v38 = 0;
   *(int *)v2 = this->field_64[0];
@@ -2022,7 +1885,7 @@
   float v41; // [sp+2Ch] [bp-4h]@6
   float v42; // [sp+2Ch] [bp-4h]@9
 
-  //v1 = this;
+  __debugbreak();//нужно почистить
   if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
   {
     v2 = 0;
@@ -2133,7 +1996,6 @@
 bool stru6_stru1_indoor_sw_billboard::sub_477F63()
 {
   signed int v1; // ebx@1
-  stru6_stru1_indoor_sw_billboard *v2; // esi@1
   double v3; // st7@2
   int v4; // edx@4
   char *v5; // ecx@5
@@ -2142,10 +2004,8 @@
   signed int v9; // [sp+Ch] [bp-8h]@1
   float v10; // [sp+10h] [bp-4h]@2
 
-  stru6_stru1_indoor_sw_billboard* a1 = this;
-
+  __debugbreak();//где используется ф-ция sw или hw?
   v1 = 0;
-  v2 = a1;
   v9 = 0;
   if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
   {
@@ -2157,15 +2017,14 @@
     v10 = (double)pODMRenderParams->shading_dist_mist;
     v3 = 8.0;
   }
-  v4 = a1->uNumVertices;
+  v4 = this->uNumVertices;
   if ( v4 <= 0 )
   {
-    memcpy(&v2->field_14[40], &v2->field_14[20], 16 * v4);
-    return v2->uNumVertices != 0;
+    memcpy(&this->field_14[40], &this->field_14[20], 16 * v4);
+    return this->uNumVertices != 0;
   }
-  v5 = (char *)&a1->field_14[20];
-  v6 = v4;
-  do
+  v5 = (char *)&this->field_14[20];
+  for ( v6 = v4; v6; --v6 )
   {
     if ( v3 >= *(float *)v5 || *(float *)v5 >= (double)v10 )
     {
@@ -2175,81 +2034,68 @@
         v1 = 1;
     }
     v5 += 16;
-    --v6;
   }
-  while ( v6 );
   if ( !v1 )
   {
     if ( v9 )
     {
-      v2->_477927(v10);
-      return v2->uNumVertices != 0;
+      this->_477927(v10);
+      return this->uNumVertices != 0;
     }
-    memcpy(&v2->field_14[40], &v2->field_14[20], 16 * v4);
-    return v2->uNumVertices != 0;
+    memcpy(&this->field_14[40], &this->field_14[20], 16 * v4);
+    return this->uNumVertices != 0;
   }
   v7 = v3;
   _4775ED(v7);
-  return v2->uNumVertices != 0;
+  return this->uNumVertices != 0;
 }
 
 //----- (0047802A) --------------------------------------------------------
 int stru6_stru1_indoor_sw_billboard::sub_47802A()
 {
   double v6; // st7@4
-  double v12; // st7@16
   signed int v16; // [sp+38h] [bp-Ch]@1
   int a6; // [sp+3Ch] [bp-8h]@5
   int a5; // [sp+40h] [bp-4h]@5
 
-  stru6_stru1_indoor_sw_billboard* a1 = this;
-
+  __debugbreak(); //необходимо проверить this->field_B4[i*4+16]
   v16 = 0;
   if ( uCurrentlyLoadedLevelType == LEVEL_Indoor )
   {
-	for(int i = 0; i < a1->uNumVertices; i++)
+    for(int i = 0; i < this->uNumVertices; i++)
     {
-		v6 = (double)pBLVRenderParams->fov_rad_fixpoint * 0.000015258789 / a1->field_B4[i*4];
-		if ( pRenderer->pRenderD3D )
-		{
-			pGame->pIndoorCameraD3D->Project(
-				round(a1->field_B4[i*4]),
-				round(a1->field_B4[i*4+1]),
-				round(a1->field_B4[i*4+2]),
-				&a5,
-				&a6);
-			a1->field_B4[i*4+16] = (double)a5;
-			a1->field_B4[i*4+17] = (double)a6;
-			a1->field_B4[i*4+18] = round(a1->field_B4[i*4]);
-		}
-		else
-		{
-			a1->field_B4[i*4+16] = (double)pBLVRenderParams->uViewportCenterX - v6 * a1->field_B4[i*4+1];
-			a1->field_B4[i*4+17] = (double)pBLVRenderParams->uViewportCenterY - v6 * a1->field_B4[i*4+2];
-			a1->field_B4[i*4+18] = a1->field_B4[i*4];
-		}
-		a1->field_B4[i*4+19] = a1->field_B4[i*4+3];
-		if ( (double)(signed int)pViewport->uViewportTL_X <= a1->field_B4[i*4+16]
-			&& (double)(signed int)pViewport->uViewportBR_X > a1->field_B4[i*4+16]
-			&& (double)(signed int)pViewport->uViewportTL_Y <= a1->field_B4[i*4+17]
-			&& (double)(signed int)pViewport->uViewportBR_Y > a1->field_B4[i*4+17] )
-			v16 = 1;
+      v6 = (double)pBLVRenderParams->fov_rad_fixpoint * 0.000015258789 / this->field_B4[i*4];
+      if ( pRenderer->pRenderD3D )
+      {
+        pGame->pIndoorCameraD3D->Project(round(this->field_B4[i*4]), round(this->field_B4[i*4+1]), round(this->field_B4[i*4+2]),
+           &a5, &a6);
+        this->field_B4[i*4+16] = (double)a5;
+        this->field_B4[i*4+17] = (double)a6;
+        this->field_B4[i*4+18] = round(this->field_B4[i*4]);
+      }
+      else
+      {
+        this->field_B4[i*4+16] = (double)pBLVRenderParams->uViewportCenterX - v6 * this->field_B4[i*4+1];
+        this->field_B4[i*4+17] = (double)pBLVRenderParams->uViewportCenterY - v6 * this->field_B4[i*4+2];
+        this->field_B4[i*4+18] = this->field_B4[i*4];
+      }
+      this->field_B4[i*4+19] = this->field_B4[i*4+3];
+      if ( (double)(signed int)pViewport->uViewportTL_X <= this->field_B4[i*4+16] && (double)(signed int)pViewport->uViewportBR_X > this->field_B4[i*4+16]
+        && (double)(signed int)pViewport->uViewportTL_Y <= this->field_B4[i*4+17] && (double)(signed int)pViewport->uViewportBR_Y > this->field_B4[i*4+17] )
+        v16 = 1;
     }
   }
   else
   {
-	for(int i = 0; i < a1->uNumVertices; i++)
+    for(int i = 0; i < this->uNumVertices; i++)
     {
-		v12 = (double)pODMRenderParams->int_fov_rad / a1->field_B4[i*4];
-		a1->field_B4[i*4+20] = (double)pViewport->uScreenCenterX - v12 * a1->field_B4[i*4+1];
-		a1->field_B4[i*4+21] = (double)pViewport->uScreenCenterY - v12 * a1->field_B4[i*4+2];
-		*((int *)&a1->field_B4[i*4+22]) = (int)a1->field_B4[i*4];
-		*((int *)&a1->field_B4[i*4+23]) = a1->field_B4[i*4+3];
-		if ( (double)(signed int)pViewport->uViewportTL_X <= a1->field_B4[i*4+20]
-			&& (double)(signed int)pViewport->uViewportBR_X > a1->field_B4[i*4+20]
-			&& (double)(signed int)pViewport->uViewportTL_Y <= a1->field_B4[i*4+21]
-			&& (double)(signed int)pViewport->uViewportBR_Y > a1->field_B4[i*4+21] )
-			v16 = 1;
+       this->field_B4[i*4+20] = (double)pViewport->uScreenCenterX - (double)pODMRenderParams->int_fov_rad / this->field_B4[i*4] * this->field_B4[i*4+1];
+       this->field_B4[i*4+21] = (double)pViewport->uScreenCenterY - (double)pODMRenderParams->int_fov_rad / this->field_B4[i*4] * this->field_B4[i*4+2];
+       *((int *)&this->field_B4[i*4+22]) = (int)this->field_B4[i*4];
+       *((int *)&this->field_B4[i*4+23]) = this->field_B4[i*4+3];
+       if ( (double)(signed int)pViewport->uViewportTL_X <= this->field_B4[i*4+20] && (double)(signed int)pViewport->uViewportBR_X > this->field_B4[i*4+20]
+         && (double)(signed int)pViewport->uViewportTL_Y <= this->field_B4[i*4+21] && (double)(signed int)pViewport->uViewportBR_Y > this->field_B4[i*4+21] )
+         v16 = 1;
     }
   }
   return v16;
@@ -2260,56 +2106,34 @@
 //----- (00479089) --------------------------------------------------------
 bool __fastcall IsBModelVisible(unsigned int uModelID, int *reachable)
 {
-  BSPModel *v2; // eax@1
   int v3; // edi@1
   int v4; // ebx@1
-  int v5; // ST28_4@1
-  int v6; // ecx@1
-  int v7; // ebx@3
-  int v8; // eax@3
   int v9; // eax@3
-  //int v10; // ebx@3
   signed int v11; // esi@6
   int v12; // esi@8
   bool result; // eax@9
-  //unsigned int v14; // [sp+Ch] [bp-20h]@1
-  int v15; // [sp+Ch] [bp-20h]@5
-  //int *v16; // [sp+10h] [bp-1Ch]@1
   int v17; // [sp+1Ch] [bp-10h]@1
-  int v18; // [sp+20h] [bp-Ch]@1
   int v19; // [sp+20h] [bp-Ch]@3
   int angle; // [sp+24h] [bp-8h]@1
-  int v21; // [sp+28h] [bp-4h]@1
-  //int v22; // [sp+28h] [bp-4h]@3
-
-  //v16 = unused;
-  angle = (signed int)(pODMRenderParams->uCameraFovInDegrees << 11) / 360 >> 1;
-  //v14 = uModelID;
-  v2 = &pOutdoor->pBModels[uModelID];
-  v3 = v2->vBoundingCenter.x - pGame->pIndoorCameraD3D->vPartyPos.x;
-  v4 = v2->vBoundingCenter.y - pGame->pIndoorCameraD3D->vPartyPos.y;
-  v5 = stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationY);
-  v21 = stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationY);
-  v18 = stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationX);
+
+  angle = (signed int)(pODMRenderParams->uCameraFovInDegrees << 11) / 360 / 2;
+  v3 = pOutdoor->pBModels[uModelID].vBoundingCenter.x - pGame->pIndoorCameraD3D->vPartyPos.x;
+  v4 = pOutdoor->pBModels[uModelID].vBoundingCenter.y - pGame->pIndoorCameraD3D->vPartyPos.y;
   stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationX);
-  v6 = v5;
-  v17 = v3 * v5 + v4 * v21;
+  v17 = v3 * stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationY) + v4 * stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationY);
   if (pGame->pIndoorCameraD3D->sRotationX)
-    v17 = (unsigned __int64)(v17 * (signed __int64)v18) >> 16;
-  v19 = v4 * v6 - v3 * v21;
-  v7 = abs(v4);
-  v8 = abs(v3);
-  v9 = int_get_vector_length(v8, v7, 0);
+    v17 = (unsigned __int64)(v17 * (signed __int64)stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationX)) >> 16;
+  v19 = v4 * stru_5C6E00->Cos(pGame->pIndoorCameraD3D->sRotationY) - v3 * stru_5C6E00->Sin(pGame->pIndoorCameraD3D->sRotationY);
+  v9 = int_get_vector_length(abs(v3), abs(v4), 0);
   //v10 = v14 * 188;
   //v22 = v9;
   *reachable = false;
   if ( v9 < pOutdoor->pBModels[uModelID].sBoundingRadius + 256 )
     *reachable = true;
-  v15 = stru_5C6E00->Sin(angle);
   if ( v19 >= 0 )
-    v11 = ((unsigned __int64)(v15 * (signed __int64)v17) >> 16) - ((unsigned __int64)(stru_5C6E00->Cos(angle) * (signed __int64)v19) >> 16);
+    v11 = ((unsigned __int64)(stru_5C6E00->Sin(angle) * (signed __int64)v17) >> 16) - ((unsigned __int64)(stru_5C6E00->Cos(angle) * (signed __int64)v19) >> 16);
   else
-    v11 = ((unsigned __int64)(stru_5C6E00->Cos(angle) * (signed __int64)v19) >> 16) + ((unsigned __int64)(v15 * (signed __int64)v17) >> 16);
+    v11 = ((unsigned __int64)(stru_5C6E00->Cos(angle) * (signed __int64)v19) >> 16) + ((unsigned __int64)(stru_5C6E00->Sin(angle) * (signed __int64)v17) >> 16);
   v12 = v11 >> 16;
   if ( v9 <= pODMRenderParams->shading_dist_mist + 2048 )
   {
@@ -2329,28 +2153,25 @@
 //----- (00479295) --------------------------------------------------------
 int Polygon::_479295()
 {
-  ODMFace *v2; // esi@1
   int v3; // ecx@4
   int v4; // eax@4
   int v5; // edx@4
   int v6; // ST14_4@5
-  int v7; // ST04_4@5
-  stru149 *v8; // ecx@5
   Vec3_int_ thisa; // [sp+Ch] [bp-10h]@8
   int v11; // [sp+18h] [bp-4h]@4
 
-  v2 = this->pODMFace;
-  if ( !v2->pFacePlane.vNormal.z )
+  if ( !this->pODMFace->pFacePlane.vNormal.z )
   {
-    v3 = v2->pFacePlane.vNormal.x;
-    v4 = -v2->pFacePlane.vNormal.y;
+    v3 = this->pODMFace->pFacePlane.vNormal.x;
+    v4 = -this->pODMFace->pFacePlane.vNormal.y;
     v5 = 0;
     v11 = 65536;
   }
-  else if ( (v2->pFacePlane.vNormal.x || v2->pFacePlane.vNormal.y) && abs(v2->pFacePlane.vNormal.z) < 59082 )
+  else if ( (this->pODMFace->pFacePlane.vNormal.x || this->pODMFace->pFacePlane.vNormal.y)
+      && abs(this->pODMFace->pFacePlane.vNormal.z) < 59082 )
   {
-    thisa.x = -v2->pFacePlane.vNormal.y;
-    thisa.y = v2->pFacePlane.vNormal.x;
+    thisa.x = -this->pODMFace->pFacePlane.vNormal.y;
+    thisa.y = this->pODMFace->pFacePlane.vNormal.x;
     thisa.z = 0;
     thisa.Normalize_float();
     v4 = thisa.x;
@@ -2365,12 +2186,9 @@
 	  v11 = 0;
 	  v5 = -65536;
   }
-  v6 = v11;
-  sTextureDeltaU = v2->sTextureDeltaU;
-  v7 = v3;
-  v8 = ptr_38;
-  sTextureDeltaV = v2->sTextureDeltaV;
-  v8->_48616B_frustum_odm(v4, v7, 0, 0, v5, v6);
+  sTextureDeltaU = this->pODMFace->sTextureDeltaU;
+  sTextureDeltaV = this->pODMFace->sTextureDeltaV;
+  ptr_38->_48616B_frustum_odm(v4, v3, 0, 0, v5, v11);
   return 1;
 }
 
@@ -3377,21 +3195,14 @@
 //----- (0048257A) --------------------------------------------------------
 int __fastcall GetTerrainHeightsAroundParty2(int a1, int a2, int *pIsOnWater, int bFloatAboveWater)
 {
-  //unsigned int v4; // ebx@1
-  //unsigned int v5; // edi@1
   int result; // eax@9
-  //int v7; // ebx@10
   int v8; // ebx@11
   int v9; // eax@11
   int v10; // ecx@11
-  //int v11; // [sp+Ch] [bp-Ch]@1
-  //int v12; // [sp+10h] [bp-8h]@1
   int v13; // [sp+10h] [bp-8h]@11
   signed int v14; // [sp+14h] [bp-4h]@3
   int v15; // [sp+24h] [bp+Ch]@11
 
-  //v11 = a1;
-  //v12 = a2;
   unsigned int grid_x = WorldPosToGridCellX(a1);
   unsigned int grid_z = WorldPosToGridCellZ(a2) - 1;
 
@@ -3450,10 +3261,6 @@
     return y_x1z1;
 }
 
-
-
-
-
 //----- (00485F53) --------------------------------------------------------
 void  sr_485F53(Vec2_int_ *v)
 {
@@ -3472,15 +3279,14 @@
 //----- (00486089) --------------------------------------------------------
 void Polygon::_normalize_v_18()
 {
-  double v2; // st7@1
-  double v3; // st6@1
-  double v5; // st5@1
-
-  //v1 = this;
-  v2 = (double)this->v_18.x;
-  v3 = (double)this->v_18.y;
-  v5 = (double)this->v_18.z;
-  float len = sqrt(v5 * v5 + v3 * v3 + v2 * v2);
+  //double v2; // st7@1
+  //double v3; // st6@1
+  //double v5; // st5@1
+
+ // v2 = (double)this->v_18.x;
+  //v3 = (double)this->v_18.y;
+ // v5 = (double)this->v_18.z;
+  float len = sqrt((double)this->v_18.z * (double)this->v_18.z + (double)this->v_18.y * (double)this->v_18.y + (double)this->v_18.x * (double)this->v_18.x);
   if (fabsf(len) < 1e-6f)
   {
     v_18.x = 0;
@@ -3489,9 +3295,9 @@
   }
   else
   {
-    v_18.x = round(v2 / len * 65536.0);
-    v_18.y = round(v3 / len * 65536.0);
-    v_18.y = round(v5 / len * 65536.0);
+    v_18.x = round((double)this->v_18.x / len * 65536.0);
+    v_18.y = round((double)this->v_18.y / len * 65536.0);
+    v_18.y = round((double)this->v_18.z / len * 65536.0);
   }
 }
 
@@ -3499,28 +3305,13 @@
 void stru149::_48616B_frustum_odm(int a2, int a3, int a4, int a5, int a6, int a7)
 {
   int v7; // ebx@1
-  //int v8; // esi@1
   int v9; // edi@1
-  //int v10; // eax@1
   int v11; // edx@1
-  //int v12; // esi@2
-  //int v13; // eax@2
-  //int v14; // ST10_4@3
-  //int v15; // esi@3
-  //int v16; // eax@5
   int v17; // ST0C_4@6
-  //int v18; // eax@8
   int v19; // ST0C_4@9
-  //int v20; // eax@10
-  //int v21; // edx@10
-  //int v22; // eax@10
-  //int result; // eax@10
   int v24; // [sp+14h] [bp-14h]@1
   int v25; // [sp+18h] [bp-10h]@1
-  //int v26; // [sp+1Ch] [bp-Ch]@1
   int v27; // [sp+24h] [bp-4h]@1
-  //int v28; // [sp+30h] [bp+8h]@10
-  //int v29; // [sp+3Ch] [bp+14h]@10
 
   v25 = pGame->pIndoorCameraD3D->int_cosine_x;
   v7 = pGame->pIndoorCameraD3D->int_sine_y;
@@ -3939,7 +3730,7 @@
       if ( !pLevelStr[i] )
       {
         pLevelStrOffsets[string_num] = i + 1;
-		++string_num;
+        ++string_num;
         if ( i - prev_string_offset > max_string_length )
           max_string_length = i - prev_string_offset;
         prev_string_offset = i;
@@ -3968,7 +3759,7 @@
   {
     for (uint i = 0; i < uLevelEVT_NumEvents; ++i)
     {
-		test_event=(_evt_raw*)&pLevelEVT[pLevelEVT_Index[i].uEventOffsetInEVT];
+      test_event=(_evt_raw*)&pLevelEVT[pLevelEVT_Index[i].uEventOffsetInEVT];
       if ( test_event->_e_type == EVENT_OnMapLeave )
       {
         EventProcessor(pLevelEVT_Index[i].uEventID, 0, 1, pLevelEVT_Index[i].event_sequence_num);
@@ -3980,161 +3771,150 @@
 //----- (00443FDC) --------------------------------------------------------
 void OnMapLoad()
 {
-	stru176 *v3; // esi@7
-	__int16 v4; // cx@9
-	__int16 v5; // di@9
-	int v6; // eax@9
-	signed __int64 v8; // qax@26
-	unsigned int v9; // ecx@26
-	signed __int64 v10; // qax@26
-	signed __int64 v11; // qax@26
-	int v12; // ST50_4@26
-	signed __int64 v13; // qax@26
-	signed __int64 v14; // qax@26
-	int v15; // ST58_4@26
-	signed __int64 v16; // qax@26
-	int hours; // ebx@26
-	unsigned __int64 v18; // [sp+Ch] [bp-44h]@12
-	signed __int64 seconds; // [sp+14h] [bp-3Ch]@26
-	unsigned __int64 v20; // [sp+1Ch] [bp-34h]@7
-	int minutes; // [sp+2Ch] [bp-24h]@26
-	int years; // [sp+34h] [bp-1Ch]@26
-	int weeks; // [sp+38h] [bp-18h]@26
-	int v26; // [sp+3Ch] [bp-14h]@15
-	int days; // [sp+3Ch] [bp-14h]@26
-	int months; // [sp+40h] [bp-10h]@26
-	__int16 v29; // [sp+46h] [bp-Ah]@9
-	__int16 v30; // [sp+48h] [bp-8h]@9
-	__int16 v31; // [sp+4Ah] [bp-6h]@9
-	__int16 v32; // [sp+4Ch] [bp-4h]@9
-	__int16 v33; // [sp+4Eh] [bp-2h]@9
-
-	for (uint i = 0; i < uLevelEVT_NumEvents; ++i)
-	{
-		EventIndex pEvent = pLevelEVT_Index[i];
-
-		_evt_raw* _evt = (_evt_raw *)(&pLevelEVT[pEvent.uEventOffsetInEVT]);
-
-		if (_evt->_e_type == EVENT_PlaySound)
-		{
-			pSoundList->LoadSound(EVT_DWORD(_evt->v5), 0);
-		}
-		else if (_evt->_e_type == EVENT_OnMapReload)
-		{
-			EventProcessor(pEvent.uEventID, 0, 0, pEvent.event_sequence_num);
-		}
-		else if (_evt->_e_type == EVENT_OnTimer || _evt->_e_type == EVENT_Initialize)
-		{
-			v3 = &array_5B5928_timers[dword_5B65C8_timers_count];
-			v20 = pOutdoor->loc_time.uLastVisitDay;
-			if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
-				v20 = pIndoor->stru1.uLastVisitDay;
-
-			v3->timer_evt_type = _evt->_e_type;
-			v3->timer_evt_ID = pEvent.uEventID;
-			v3->timer_evt_seq_num = pEvent.event_sequence_num;
-
-			v3->field_10 = _evt->v5;
-			v3->field_12 = _evt->v6;
-			v3->field_14 = _evt->v7;
-			v3->field_16 = _evt->v8;
-			v3->field_18 = _evt->v9;
-			v3->field_1A = _evt->v10;
-
-
-			v6 = ((unsigned short)_evt->v12 << 8) + _evt->v11;
-
-			v3->time_left_to_fire = ((unsigned short)_evt->v12 << 8) + _evt->v11;
-            v3->fire_interval = ((unsigned short)_evt->v12 << 8) + _evt->v11;
-			if (v3->timer_evt_type  == EVENT_Initialize && !(short)v6 )
-			{
-				if ( v20 )
-					v18 = pParty->uTimePlayed - v20;
-				else
-					v18 = 0i64;
-				v26 = (signed int)(signed __int64)((double)(signed __int64)v18 * 0.234375) / 60 / 60 / 24;
-
-				if ( v26 / 7 / 4 / 12 )
-				{
-					if ( v3->field_10 )
-					{
-						++dword_5B65C8_timers_count;
-                        v3->next_fire_time = 0;
-						continue;
-					}
-				}
-				if (v26 / 7 / 4 != 0 && v3->field_12 != 0 ||
-					v26 / 7 != 0 && v3->field_14 != 0 ||
-					v26 != 0 || !v20)
-				{
-					++dword_5B65C8_timers_count;
-					v3->next_fire_time = 0;
-					continue;
-				}
-			}
-			else
-			{
-				v8 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375);
-				v9 = v8;
-				v10 = (signed int)v8 / 60;
-				minutes = v10 % 60;
-				v11 = (signed int)(v10 / 60);
-				v12 = v11 % 24;
-				v13 = (signed int)(v11 / 24);
-				days = v13 % 7;
-				v14 = (signed int)(v13 / 7);
-				v15 = v14 % 4;
-				v16 = (signed int)(v14 / 4);
-				years = v16 / 12;
-
-				unsigned __int64 _1 = (unsigned __int64)((double)pParty->uTimePlayed * 0.234375) >> 32;
-				__int64 _2 = ((__int64)v9 << 32) | _1;
-
-				seconds = _2 % 60;
-				//v19 = (signed __int64)__PAIR__((unsigned __int64)(signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) >> 32,
-				//                        v9)
-				//    % 60;
-
-				hours = v12;
-				weeks = v15;
-				months = v16 % 12;
-				if ( v3->field_10 )
-				{
-					++years;
-				}
-				else
-				{
-					if ( v3->field_12 )
-					{
-						++months;
-					}
-					else
-					{
-						if ( v3->field_14 )
-						{
-							++weeks;
-						}
-						else
-						{
-							++days;
-							minutes = v3->field_18;
-							hours = v3->field_16;
-							seconds = v3->field_1A;
-						}
-					}
-				}
-                v3->next_fire_time = (signed __int64)((double)((seconds
-					+ 60 * minutes
-					+ 3600 * hours
-					+ 0x93A80 * weeks
-					+ 0x15180 * days
-					+ 0x24EA00 * (months + 12i64 * years)) << 7)
-					* 0.033333335);
-
-				++dword_5B65C8_timers_count;
-			}
-		}
-	}
+  __int16 v4; // cx@9
+  __int16 v5; // di@9
+  int v6; // eax@9
+  signed __int64 v8; // qax@26
+  unsigned int v9; // ecx@26
+  signed __int64 v10; // qax@26
+  signed __int64 v11; // qax@26
+  int v12; // ST50_4@26
+  signed __int64 v13; // qax@26
+  signed __int64 v14; // qax@26
+  int v15; // ST58_4@26
+  signed __int64 v16; // qax@26
+  int hours; // ebx@26
+  unsigned __int64 v18; // [sp+Ch] [bp-44h]@12
+  signed __int64 seconds; // [sp+14h] [bp-3Ch]@26
+  unsigned __int64 v20; // [sp+1Ch] [bp-34h]@7
+  int minutes; // [sp+2Ch] [bp-24h]@26
+  int years; // [sp+34h] [bp-1Ch]@26
+  int weeks; // [sp+38h] [bp-18h]@26
+  int v26; // [sp+3Ch] [bp-14h]@15
+  int days; // [sp+3Ch] [bp-14h]@26
+  int months; // [sp+40h] [bp-10h]@26
+  __int16 v29; // [sp+46h] [bp-Ah]@9
+  __int16 v30; // [sp+48h] [bp-8h]@9
+  __int16 v31; // [sp+4Ah] [bp-6h]@9
+  __int16 v32; // [sp+4Ch] [bp-4h]@9
+  __int16 v33; // [sp+4Eh] [bp-2h]@9
+
+  for (uint i = 0; i < uLevelEVT_NumEvents; ++i)
+  {
+    EventIndex pEvent = pLevelEVT_Index[i];
+
+    _evt_raw* _evt = (_evt_raw *)(&pLevelEVT[pEvent.uEventOffsetInEVT]);
+
+    if (_evt->_e_type == EVENT_PlaySound)
+      pSoundList->LoadSound(EVT_DWORD(_evt->v5), 0);
+    else if (_evt->_e_type == EVENT_OnMapReload)
+      EventProcessor(pEvent.uEventID, 0, 0, pEvent.event_sequence_num);
+    else if (_evt->_e_type == EVENT_OnTimer || _evt->_e_type == EVENT_Initialize)
+    {
+      //v3 = &array_5B5928_timers[dword_5B65C8_timers_count];
+      v20 = pOutdoor->loc_time.uLastVisitDay;
+      if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
+        v20 = pIndoor->stru1.uLastVisitDay;
+
+      array_5B5928_timers[dword_5B65C8_timers_count].timer_evt_type = _evt->_e_type;
+      array_5B5928_timers[dword_5B65C8_timers_count].timer_evt_ID = pEvent.uEventID;
+      array_5B5928_timers[dword_5B65C8_timers_count].timer_evt_seq_num = pEvent.event_sequence_num;
+
+      array_5B5928_timers[dword_5B65C8_timers_count].field_10 = _evt->v5;
+      array_5B5928_timers[dword_5B65C8_timers_count].field_12 = _evt->v6;
+      array_5B5928_timers[dword_5B65C8_timers_count].field_14 = _evt->v7;
+      array_5B5928_timers[dword_5B65C8_timers_count].field_16 = _evt->v8;
+      array_5B5928_timers[dword_5B65C8_timers_count].field_18 = _evt->v9;
+      array_5B5928_timers[dword_5B65C8_timers_count].field_1A = _evt->v10;
+
+
+      v6 = ((unsigned short)_evt->v12 << 8) + _evt->v11;
+
+      array_5B5928_timers[dword_5B65C8_timers_count].time_left_to_fire = ((unsigned short)_evt->v12 << 8) + _evt->v11;
+      array_5B5928_timers[dword_5B65C8_timers_count].fire_interval = ((unsigned short)_evt->v12 << 8) + _evt->v11;
+      if (array_5B5928_timers[dword_5B65C8_timers_count].timer_evt_type  == EVENT_Initialize && !(short)v6 )
+      {
+        if ( v20 )
+          v18 = pParty->uTimePlayed - v20;
+        else
+          v18 = 0i64;
+        v26 = (signed int)(signed __int64)((double)(signed __int64)v18 * 0.234375) / 60 / 60 / 24;
+
+        if ( v26 / 7 / 4 / 12 )
+        {
+          if ( array_5B5928_timers[dword_5B65C8_timers_count].field_10 )
+          {
+            ++dword_5B65C8_timers_count;
+            array_5B5928_timers[dword_5B65C8_timers_count].next_fire_time = 0;
+            continue;
+          }
+        }
+        if (v26 / 7 / 4 != 0 && array_5B5928_timers[dword_5B65C8_timers_count].field_12 != 0 ||
+          v26 / 7 != 0 && array_5B5928_timers[dword_5B65C8_timers_count].field_14 != 0 ||
+          v26 != 0 || !v20)
+        {
+          ++dword_5B65C8_timers_count;
+          array_5B5928_timers[dword_5B65C8_timers_count].next_fire_time = 0;
+          continue;
+        }
+      }
+      else
+      {
+        v8 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375);
+        v9 = v8;
+        v10 = (signed int)v8 / 60;
+        minutes = v10 % 60;
+        v11 = (signed int)(v10 / 60);
+        v12 = v11 % 24;
+        v13 = (signed int)(v11 / 24);
+        days = v13 % 7;
+        v14 = (signed int)(v13 / 7);
+        v15 = v14 % 4;
+        v16 = (signed int)(v14 / 4);
+        years = v16 / 12;
+
+        unsigned __int64 _1 = (unsigned __int64)((double)pParty->uTimePlayed * 0.234375) >> 32;
+        __int64 _2 = ((__int64)v9 << 32) | _1;
+
+        seconds = _2 % 60;
+        //v19 = (signed __int64)__PAIR__((unsigned __int64)(signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) >> 32,
+        //                        v9)
+        //    % 60;
+
+        hours = v12;
+        weeks = v15;
+        months = v16 % 12;
+        if ( array_5B5928_timers[dword_5B65C8_timers_count].field_10 )
+          ++years;
+        else
+        {
+          if ( array_5B5928_timers[dword_5B65C8_timers_count].field_12 )
+            ++months;
+          else
+          {
+            if ( array_5B5928_timers[dword_5B65C8_timers_count].field_14 )
+              ++weeks;
+            else
+            {
+              ++days;
+              minutes = array_5B5928_timers[dword_5B65C8_timers_count].field_18;
+              hours = array_5B5928_timers[dword_5B65C8_timers_count].field_16;
+              seconds = array_5B5928_timers[dword_5B65C8_timers_count].field_1A;
+            }
+          }
+        }
+        array_5B5928_timers[dword_5B65C8_timers_count].next_fire_time = (signed __int64)((double)((seconds
+                    + 60 * minutes
+                    + 3600 * hours
+                    + 0x93A80 * weeks
+                    + 0x15180 * days
+                    + 0x24EA00 * (months + 12i64 * years)) << 7)
+                    * 0.033333335);
+
+        ++dword_5B65C8_timers_count;
+      }
+    }
+  }
 }
 
 //----- (00444360) --------------------------------------------------------
@@ -4154,31 +3934,26 @@
 //----- (00444D80) --------------------------------------------------------
 int GetTravelTime()
 {
-  signed int v0; // esi@1
-
-  v0 = uDefaultTravelTime_ByFoot;
+  signed int new_travel_time; // esi@1
+
+  new_travel_time = uDefaultTravelTime_ByFoot;
   if ( CheckHiredNPCSpeciality(Guide) )
-    --v0;
+    --new_travel_time;
   if ( CheckHiredNPCSpeciality(Tracker) )
-    v0 -= 2;
+    new_travel_time -= 2;
   if ( CheckHiredNPCSpeciality(Pathfinder) )
-    v0 -= 3;
+    new_travel_time -= 3;
   if ( CheckHiredNPCSpeciality(Explorer) )
-    --v0;
-  if ( v0 < 1 )
-    v0 = 1;
-  return v0;
+    --new_travel_time;
+  if ( new_travel_time < 1 )
+    new_travel_time = 1;
+  return new_travel_time;
 }
 // 6BD07C: using guessed type int uDefaultTravelTime_ByFoot;
 
 //----- (004451A8) --------------------------------------------------------
 void __fastcall sub_4451A8_press_any_key(int a1, int a2, int a4)
 {
-  int v3; // esi@1
-  int v4; // edi@1
-
-  v3 = a2;
-  v4 = a1;
   if ( !pGUIWindow2 )
   {
     if ( pParty->uFlags & 2 )
@@ -4186,8 +3961,8 @@
     pAudioPlayer->StopChannels(-1, -1);
     pMiscTimer->Pause();
     pEventTimer->Pause();
-    dword_5C3418 = v4;
-    dword_5C341C = v3;
+    dword_5C3418 = a1;
+    dword_5C341C = a2;
     _591094_decoration = activeLevelDecoration;
     pGUIWindow2 = GUIWindow::Create(0, 0, 640, 480, WINDOW_GreetingNPC, a4, 0);
     pGUIWindow2->CreateButton( 61, 424, 31, 40, 2, 94, UIMSG_SelectCharacter, 1, '1', "", 0);
@@ -4209,7 +3984,7 @@
 }
 
 //----- (004465DF) --------------------------------------------------------
-int sub_4465DF_check_season(int a1)
+bool sub_4465DF_check_season(int a1)
 {
   unsigned int v1; // eax@1
   unsigned int v2; // edx@1
@@ -4222,22 +3997,21 @@
   if ( a1 )
   {
     v3 = a1 - 1;
-    if ( v3 )
+    if ( a1 - 1 )
     {
       v4 = v3 - 1;
-      if ( v4 )
+      if ( v3 - 1 )
       {
         if ( v4 != 1 )
-          return 0;
+          return false;
         if ( v1 != 12 )
         {
           if ( (signed int)v1 >= 1 && (signed int)v1 <= 2 )
-            return 1;
+            return true;
           v6 = v1 == 3;
-LABEL_24:
           if ( !v6 || (signed int)v2 >= 21 )
-            return 0;
-          return 1;
+            return false;
+          return true;
         }
       }
       else
@@ -4245,9 +4019,11 @@
         if ( v1 != 9 )
         {
           if ( (signed int)v1 >= 10 && (signed int)v1 <= 11 )
-            return 1;
+            return true;
           v6 = v1 == 12;
-          goto LABEL_24;
+          if ( !v6 || (signed int)v2 >= 21 )
+            return false;
+          return true;
         }
       }
     }
@@ -4256,9 +4032,11 @@
       if ( v1 != 6 )
       {
         if ( (signed int)v1 >= 7 && (signed int)v1 <= 8 )
-          return 1;
+          return true;
         v6 = v1 == 9;
-        goto LABEL_24;
+        if ( !v6 || (signed int)v2 >= 21 )
+          return false;
+        return true;
       }
     }
   }
@@ -4267,137 +4045,86 @@
     if ( v1 != 3 )
     {
       if ( (signed int)v1 >= 4 && (signed int)v1 <= 5 )
-        return 1;
+        return true;
       v6 = v1 == 6;
-      goto LABEL_24;
+      if ( !v6 || (signed int)v2 >= 21 )
+        return false;
+      return true;
     }
   }
   if ( (signed int)v2 >= 21 )
-    return 1;
-  return 0;
+    return true;
+  return false;
 }
 
 //----- (0044861E) --------------------------------------------------------
 void __fastcall sub_44861E_set_texture(unsigned int uFaceCog, const char *pFilename)
 {
-  unsigned int v2; // eax@2
-  unsigned __int16 v3; // di@2
-  signed int v4; // esi@5
-  BLVFace *v5; // eax@7
-  unsigned int *v6; // eax@8
-  char *v7; // eax@9
-  int v8; // edi@16
-  char *v9; // esi@16
-  ODMFace *v10; // eax@17
-  unsigned int *v11; // eax@19
-  unsigned __int16 v12; // [sp+Ch] [bp-18h]@2
-  const char *Str2; // [sp+10h] [bp-14h]@1
-  unsigned int v14; // [sp+14h] [bp-10h]@1
-  signed int v15; // [sp+18h] [bp-Ch]@14
-  int v16; // [sp+1Ch] [bp-8h]@15
-  signed int v17; // [sp+20h] [bp-4h]@4
-  signed int v18; // [sp+20h] [bp-4h]@16
-
-  Str2 = pFilename;
-  v14 = uFaceCog;
+  unsigned int texture; // eax@2
+
   if ( uFaceCog )
   {
-    v2 = pBitmaps_LOD->LoadTexture(pFilename);
-    v3 = v2;
-    v12 = v2;
-    if ( v2 != -1 ? (int)&pBitmaps_LOD->pTextures[v2] : 0 )
+    texture = pBitmaps_LOD->LoadTexture(pFilename);
+    if ( texture != -1 ? (int)&pBitmaps_LOD->pTextures[texture] : 0 )
     {
-      pBitmaps_LOD->pTextures[v2].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[v2].palette_id1);
+      pBitmaps_LOD->pTextures[texture].palette_id2 = pPaletteManager->LoadPalette(pBitmaps_LOD->pTextures[texture].palette_id1);
 
       if ( uCurrentlyLoadedLevelType == 1 )
       {
-        v17 = 1;
         if ( (signed int)pIndoor->uNumFaceExtras > 1 )
         {
-          v4 = 1;
-          do
+          for ( uint i = 1; i < (signed int)pIndoor->uNumFaceExtras; ++i )
           {
-            if ( pIndoor->pFaceExtras[v4].sCogNumber == v14 )
+            if ( pIndoor->pFaceExtras[i].sCogNumber == uFaceCog )
             {
-              v5 = &pIndoor->pFaces[pIndoor->pFaceExtras[v4].field_C];
-              if ( BYTE1(v5->uAttributes) & 0x40 )
+              if ( BYTE1(pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uAttributes) & 0x40 )
               {
-                pIndoor->pFaces[pIndoor->pFaceExtras[v4].field_C].uBitmapID = pTextureFrameTable->FindTextureByName(
-                                                                              Str2);
-                v6 = (unsigned int *)&pIndoor->pFaces[pIndoor->pFaceExtras[v4].field_C].uBitmapID;
-                if ( *(_WORD *)v6 )
+                pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uBitmapID = pTextureFrameTable->FindTextureByName(pFilename);
+                if ( pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uBitmapID)
                 {
-                  pTextureFrameTable->LoadAnimationSequenceAndPalettes(*(_WORD *)v6);
+                  pTextureFrameTable->LoadAnimationSequenceAndPalettes(pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uBitmapID);
                 }
                 else
                 {
-                  *(_WORD *)v6 = v3;
-                  v7 = (char *)&pIndoor->pFaces[pIndoor->pFaceExtras[v4].field_C].uAttributes;
-                  v7[1] &= 0xBFu;
+                  pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uBitmapID = texture;
+                  BYTE1(pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uAttributes) &= 0xBFu;
                 }
               }
               else
               {
-                v5->uBitmapID = v3;
+                pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uBitmapID = texture;
               }
             }
-            ++v17;
-            ++v4;
           }
-          while ( v17 < (signed int)pIndoor->uNumFaceExtras );
         }
-        pParty->uFlags |= 2u;
+        pParty->uFlags |= 2;
       }
       else
       {
-        v15 = 0;
-        if ( (signed int)pOutdoor->uNumBModels > 0 )
+        for ( uint j = 0; j < (unsigned int)pOutdoor->uNumBModels; ++j )
         {
-          v16 = 0;
-          do
+          for ( uint i = 0; i < pOutdoor->pBModels[j].uNumFaces; ++i )
           {
-            v8 = 0;
-            v9 = (char *)&pOutdoor->pBModels[v16].pVertices;
-            v18 = 0;
-            if ( (signed int)pOutdoor->pBModels[v16].uNumFaces > 0 )
+            if ( pOutdoor->pBModels[j].pFaces[i].sCogNumber == uFaceCog )
             {
-              do
+              if ( BYTE1(pOutdoor->pBModels[j].pFaces[i].uAttributes) & 0x40 )
               {
-                v10 = (ODMFace *)(v8 + *((_DWORD *)v9 + 4));
-                if ( v10->sCogNumber == v14 )
+                pOutdoor->pBModels[j].pFaces[i].uTextureID = pTextureFrameTable->FindTextureByName(pFilename);
+                if ( pOutdoor->pBModels[j].pFaces[i].uTextureID )
+                  pTextureFrameTable->LoadAnimationSequenceAndPalettes(pOutdoor->pBModels[j].pFaces[i].uTextureID);
+                else
                 {
-                  if ( BYTE1(v10->uAttributes) & 0x40 )
-                  {
-                    *(_WORD *)(*((_DWORD *)v9 + 4) + v8 + 272) = pTextureFrameTable->FindTextureByName(
-                                                                   Str2);
-                    v11 = (unsigned int *)(*((_DWORD *)v9 + 4) + v8 + 272);
-                    if ( *(_WORD *)v11 )
-                    {
-                      pTextureFrameTable->LoadAnimationSequenceAndPalettes(*(_WORD *)v11);
-                    }
-                    else
-                    {
-                      *(_WORD *)v11 = v12;
-                      *(_BYTE *)(*((_DWORD *)v9 + 4) + v8 + 29) &= 0xBFu;
-                    }
-                  }
-                  else
-                  {
-                    v10->uTextureID = v12;
-                  }
+                  pOutdoor->pBModels[j].pFaces[i].uTextureID = texture;
+                  BYTE1(pOutdoor->pBModels[j].pFaces[i].uAttributes) &= 0xBFu;
                 }
-                ++v18;
-                v8 += 308;
               }
-              while ( v18 < *((_DWORD *)v9 + 2) );
+              else
+                pOutdoor->pBModels[j].pFaces[i].uTextureID = texture;
             }
-            ++v15;
-            ++v16;
           }
-          while ( v15 < (signed int)pOutdoor->uNumBModels );
         }
       }
-      pParty->uFlags |= 2u;
+      pParty->uFlags |= 2;
     }
   }
 }
@@ -4420,7 +4147,7 @@
       else
         pLevelDecorations[i].uFlags |= LEVEL_DECORATION_INVISIBLE;
 
-      pParty->uFlags |= 2u;
+      pParty->uFlags |= 2;
     }
   }
 }
@@ -4428,148 +4155,42 @@
 //----- (0044892E) --------------------------------------------------------
 void __fastcall sub_44892E_set_faces_bit(int sCogNumber, int bit, int on)
 {
-  signed int v3; // esi@2
-  signed int v4; // ecx@4
-  char *v5; // eax@6
-  int v6; // edi@13
-  char *v7; // esi@13
-  signed int v8; // ecx@13
-  ODMFace *v9; // eax@14
-  int v10; // [sp+0h] [bp-Ch]@1
-  signed int v11; // [sp+4h] [bp-8h]@11
-  int v12; // [sp+8h] [bp-4h]@12
-
-  v10 = sCogNumber;
   if ( sCogNumber )
   {
-    v3 = 1;
     if ( uCurrentlyLoadedLevelType == 1 )
     {
-      if ( (signed int)pIndoor->uNumFaceExtras > 1 )
+      for ( uint i = 1; i < (unsigned int)pIndoor->uNumFaceExtras; ++i )
       {
-        v4 = 1;
-        do
+        if ( pIndoor->pFaceExtras[i].sCogNumber == sCogNumber )
         {
-          if ( pIndoor->pFaceExtras[v4].sCogNumber == v10 )
-          {
-            v5 = (char *)&pIndoor->pFaces[pIndoor->pFaceExtras[v4].field_C].uAttributes;
-            if ( on )
-              *(_DWORD *)v5 |= bit;
-            else
-              *(_DWORD *)v5 &= ~bit;
-          }
-          ++v3;
-          ++v4;
+          if ( on )
+            pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uAttributes |= bit;
+          else
+            pIndoor->pFaces[pIndoor->pFaceExtras[i].field_C].uAttributes &= ~bit;
         }
-        while ( v3 < (signed int)pIndoor->uNumFaceExtras );
       }
-      pParty->uFlags |= 2u;
+      pParty->uFlags |= 2;
     }
     else
     {
-      v11 = 0;
-      if ( (signed int)pOutdoor->uNumBModels > 0 )
+      for ( uint j = 0; j < (unsigned int)pOutdoor->uNumBModels; ++j )
       {
-        v12 = 0;
-        do
+        for ( uint i = 0; i < (unsigned int)pOutdoor->pBModels[j].uNumFaces; ++i )
         {
-          v6 = 0;
-          v7 = (char *)&pOutdoor->pBModels[v12].pVertices;
-          v8 = 0;
-          if ( (signed int)pOutdoor->pBModels[v12].uNumFaces > 0 )
+          if ( pOutdoor->pBModels[j].pFaces[i].sCogNumber == sCogNumber )
           {
-            do
-            {
-              v9 = (ODMFace *)(v6 + *((_DWORD *)v7 + 4));
-              if ( v9->sCogNumber == v10 )
-              {
-                if ( on )
-                  v9->uAttributes |= bit;
-                else
-                  v9->uAttributes &= ~bit;
-              }
-              ++v8;
-              v6 += 308;
-            }
-            while ( v8 < *((_DWORD *)v7 + 2) );
+            if ( on )
+              pOutdoor->pBModels[j].pFaces[i].uAttributes |= bit;
+            else
+              pOutdoor->pBModels[j].pFaces[i].uAttributes &= ~bit;
           }
-          ++v11;
-          ++v12;
         }
-        while ( v11 < (signed int)pOutdoor->uNumBModels );
       }
     }
-    pParty->uFlags |= 2u;
+    pParty->uFlags |= 2;
   }
 }
 
-//----- (00448A98) --------------------------------------------------------
-void __fastcall ToggleActorGroupFlag(unsigned int uGroupID, unsigned int uFlag, unsigned int bToggle)
-{
-  unsigned int v3; // ebx@1
-  unsigned int v4; // ebp@1
-  signed int v5; // edi@1
-  Actor *v6; // esi@4
-  size_t v7; // ecx@10
-  Actor *v8; // eax@11
-  unsigned __int16 v9; // dx@14
-
-  v4 = uGroupID;
-  v5 = Standing;
-  v3 = uFlag;
-  if ( uGroupID )
-  {
-    if ( bToggle )
-    {
-      if ( (signed int)uNumActors > Standing )
-      {
-        v6 = pActors.data();//[0].uAttributes;
-        do
-        {
-          if ( v6->uGroup == v4 )
-          {
-            v6->uAttributes |= v3;
-            if ( v3 == 0x10000 )
-            {
-              v6->uAIState = Disabled;
-              v6->UpdateAnimation();
-            }
-          }
-          ++v5;
-          ++v6;
-        }
-        while ( v5 < (signed int)uNumActors );
-      }
-    }
-    else
-    {
-      v7 = uNumActors;
-      if ( (signed int)uNumActors > Standing )
-      {
-        v8 = pActors.data();//[0].uAIState;
-        do
-        {
-          if ( v8->uGroup == v4 )
-          {
-            if ( v3 == 0x10000 )
-            {
-              v9 = v8->uAIState;
-              if ( v8->uAIState != Dead )
-              {
-                if ( v9 != 4 && v9 != 11 )
-                  v8->uAIState = Standing;
-              }
-            }
-			LODWORD(v8->uAttributes) &= ~v3;
-          }
-          ++v8;
-          --v7;
-        }
-        while ( v7 );
-      }
-    }
-  }
-}
 
 //----- (00448B45) --------------------------------------------------------
 void  GameUI_StatusBar_UpdateTimedString(unsigned int bForceHide)
@@ -4652,63 +4273,44 @@
 //----- (00448CF4) --------------------------------------------------------
 void __fastcall sub_448CF4_spawn_monsters(__int16 typeindex, __int16 level, int count, int x, int y, int z, int group, unsigned int uUniqueName)
 {
-  __int16 v8; // di@1
-  __int16 v9; // si@1
-  unsigned int v10; // eax@1
-  size_t v11; // ebx@2
-  signed int v12; // esi@2
-  Actor *pActor;//Actor_uYawAngle_cr *v13; // ebx@3
-  AIDirection a3; // [sp+Ch] [bp-50h]@2
+  unsigned int map_id; // eax@1
+  size_t old_num_actors; // ebx@2
   AIDirection v15; // [sp+28h] [bp-34h]@2
-  //SpawnPointMM7 v16; // [sp+44h] [bp-18h]@1
-
-  v8 = typeindex;
-  v9 = level;
-
-  SpawnPointMM7 v16; // [sp+44h] [bp-18h]@1
-  //SpawnPointMM7::SpawnPointMM7(&v16);
-
-  v16.vPosition.x = x;
-  v16.vPosition.y = y;
-  v16.vPosition.z = z;
-  v16.uGroup = group;
-  v16.uRadius = 32;
-  v16.uKind = 3;
-  v16.uIndex = v8 + 2 * v9 + v9;
-  v10 = pMapStats->GetMapInfo(pCurrentMapName);
-  if ( v10 )
+  SpawnPointMM7 pSpawnPoint; // [sp+44h] [bp-18h]@1
+
+  pSpawnPoint.vPosition.x = x;
+  pSpawnPoint.vPosition.y = y;
+  pSpawnPoint.vPosition.z = z;
+  pSpawnPoint.uGroup = group;
+  pSpawnPoint.uRadius = 32;
+  pSpawnPoint.uKind = 3;
+  pSpawnPoint.uIndex = typeindex + 2 * level + level;
+  map_id = pMapStats->GetMapInfo(pCurrentMapName);
+  if ( map_id )
   {
-    v11 = uNumActors;
-    SpawnEncounter(&pMapStats->pInfos[v10], &v16, 0, count, 0);
-    Actor::GetDirectionInfo(PID(OBJECT_Actor, v11), 4u, &v15, 1);
-    v12 = v11;
-    if ( (signed int)v11 < (signed int)uNumActors )
+    old_num_actors = uNumActors;
+    SpawnEncounter(&pMapStats->pInfos[map_id], &pSpawnPoint, 0, count, 0);
+    Actor::GetDirectionInfo(PID(OBJECT_Actor, old_num_actors), 4, &v15, 1);
+    for ( uint i = (unsigned int)old_num_actors; i < (unsigned int)uNumActors; ++i )
     {
-      for ( pActor = &pActors[v11]; v12 < (signed int)uNumActors; ++pActor )
-      {
-        pActor->PrepareSprites(0);
-        ++v12;
-        pActor->uYawAngle = v15.uYawAngle;
-        pActor->dword_000334_unique_name = uUniqueName;
-      }
+      pActors[i].PrepareSprites(0);
+      pActors[i].uYawAngle = v15.uYawAngle;
+      pActors[i].dword_000334_unique_name = uUniqueName;
     }
   }
 }
 
 
 //----- (0044987B) --------------------------------------------------------
-void sub_44987B(const char *pMapName, MapStartPoint start_point)
+void Transition_StopSound_Autosave(const char *pMapName, MapStartPoint start_point)
 {
-  const char *v2; // edi@1
-
-  v2 = pMapName;
   pAudioPlayer->StopChannels(-1, -1);
   pGameLoadingUI_ProgressBar->Initialize(GUIProgressBar::TYPE_None);
-  if ( _stricmp(pCurrentMapName, v2) )
+  if ( _stricmp(pCurrentMapName, pMapName) )
     SaveGame(1, 0);
 
   uGameState = GAME_STATE_2;
-  strcpy(pCurrentMapName, v2);
+  strcpy(pCurrentMapName, pMapName);
   uLevel_StartingPointType = start_point;
 }
 // 6BE35C: using guessed type int uLevel_StartingPointType;
@@ -4716,58 +4318,42 @@
 //----- (004498D5) --------------------------------------------------------
 void TeleportToStartingPoint(MapStartPoint point)
 {
-  //unsigned int v1; // ecx@2
-  //int v2; // ecx@3
-  //int v3; // ecx@4
-  unsigned __int16 v4; // ax@11
-  signed int v5; // ecx@12
-  LevelDecoration *v6; // edx@13
-  signed int v7; // ecx@17
-  int v8; // eax@17
-  int v9; // ecx@17
-  const char *v10; // [sp-4h] [bp-84h]@6
+  const char *model_name; // [sp-4h] [bp-84h]@6
   char pName[128]; // [sp+8h] [bp-78h]@11
 
   switch (point)
   {
-    case MapStartPoint_Party: v10 = "Party Start"; break;
-    case MapStartPoint_North: v10 = "North Start"; break;
-    case MapStartPoint_South: v10 = "South Start"; break;
-    case MapStartPoint_East: v10 = "East Start";  break;
-    case MapStartPoint_West: v10 = "West Start";  break;
+    case MapStartPoint_Party: model_name = "Party Start"; break;
+    case MapStartPoint_North: model_name = "North Start"; break;
+    case MapStartPoint_South: model_name = "South Start"; break;
+    case MapStartPoint_East: model_name = "East Start";  break;
+    case MapStartPoint_West: model_name = "West Start";  break;
     default:
       Error("Invalid enum value: %u", point);
   }
 
-  strcpy(pName, v10);
-  v4 = pDecorationList->GetDecorIdByName(pName);
-  if ( v4 )
+  strcpy(pName, model_name);
+  if ( pDecorationList->GetDecorIdByName(pName) )
   {
-    v5 = 0;
+    
     if ( (signed int)uNumLevelDecorations > 0 )
     {
-      v6 = pLevelDecorations.data();
-      while ( v6->uDecorationDescID != (signed __int16)v4 )
+      for ( uint i = 0; i < (signed int)uNumLevelDecorations; ++i )
       {
-        ++v5;
-        ++v6;
-        if ( v5 >= (signed int)uNumLevelDecorations )
-          goto LABEL_20;
+        if ( pLevelDecorations[i].uDecorationDescID == (signed __int16)pDecorationList->GetDecorIdByName(pName) )
+        {
+          pParty->vPosition.x = pLevelDecorations[i].vPosition.x;
+          pParty->vPosition.y = pLevelDecorations[i].vPosition.y;
+          pParty->vPosition.z = pLevelDecorations[i].vPosition.z;
+          pParty->uFallStartY = pParty->vPosition.z;
+          pParty->sRotationY = (signed int)(stru_5C6E00->uIntegerHalfPi * pLevelDecorations[i].field_1A) / 90;
+          if ( pLevelDecorations[i].field_10_y_rot )
+            pParty->sRotationY = pLevelDecorations[i].field_10_y_rot;
+          pParty->sRotationX = 0;
+          pParty->uFallSpeed = 0;
+        }
       }
-      v7 = v5;
-      pParty->vPosition.x = pLevelDecorations[v7].vPosition.x;
-      pParty->vPosition.y = pLevelDecorations[v7].vPosition.y;
-      pParty->vPosition.z = pLevelDecorations[v7].vPosition.z;
-      pParty->uFallStartY = pParty->vPosition.z;
-      v8 = (signed int)(stru_5C6E00->uIntegerHalfPi * pLevelDecorations[v7].field_1A) / 90;
-      v9 = pLevelDecorations[v7].field_10_y_rot;
-      pParty->sRotationY = v8;
-      if ( v9 )
-        pParty->sRotationY = v9;
-      pParty->sRotationX = 0;
-      pParty->uFallSpeed = 0;
     }
-LABEL_20:
     if ( dword_5B65C0 )
     {
       if ( _5B65A8_npcdata_uflags_or_other )
@@ -4796,100 +4382,6 @@
   }
 }
 
-//----- (00449A49) --------------------------------------------------------
-void Door_switch_animation(unsigned int uDoorID, int a2)
-{
-  int old_state; // eax@1
-  signed int door_id; // esi@2
-
-  if ( !pIndoor->pDoors )
-    return;
-  for ( door_id = 0; door_id < 200; ++door_id )
-  {
-    if ( pIndoor->pDoors[door_id].uDoorID == uDoorID )
-      break;
-  }
-  if ( door_id >= 200 )
-  {
-    Error("Unable to find Door ID: %i!", uDoorID);
-  }
-  old_state = pIndoor->pDoors[door_id].uState;
-  //old_state: 0 - в нижнем положении/закрыто
-  //           2 - в верхнем положении/открыто,
-  //a2: 1 - открыть
-  //    2 - опустить/поднять
-  if ( a2 == 2 )
-  {
-    if ( pIndoor->pDoors[door_id].uState == BLVDoor::Closing || pIndoor->pDoors[door_id].uState == BLVDoor::Opening )
-      return;
-    if ( pIndoor->pDoors[door_id].uState )
-    {
-      if ( pIndoor->pDoors[door_id].uState != BLVDoor::Closed && pIndoor->pDoors[door_id].uState != BLVDoor::Closing )
-      {
-        pIndoor->pDoors[door_id].uState = BLVDoor::Closing;
-        if ( old_state == BLVDoor::Open )
-        {
-          pIndoor->pDoors[door_id].uTimeSinceTriggered = 0;
-          return;
-        }
-        if ( pIndoor->pDoors[door_id].uTimeSinceTriggered != 15360 )
-        {
-          pIndoor->pDoors[door_id].uTimeSinceTriggered = (pIndoor->pDoors[door_id].uMoveLength << 7) / pIndoor->pDoors[door_id].uOpenSpeed
-             - ((signed int)(pIndoor->pDoors[door_id].uTimeSinceTriggered * pIndoor->pDoors[door_id].uCloseSpeed)
-             / 128 << 7) / pIndoor->pDoors[door_id].uOpenSpeed;
-          return;
-        }
-        pIndoor->pDoors[door_id].uTimeSinceTriggered = 15360;
-      }
-      return;
-    }
-  }
-  else
-  {
-    if ( a2 == 0 )
-    {
-      if ( pIndoor->pDoors[door_id].uState != BLVDoor::Closed && pIndoor->pDoors[door_id].uState != BLVDoor::Closing )
-      {
-        pIndoor->pDoors[door_id].uState = BLVDoor::Closing;
-        if ( old_state == BLVDoor::Open )
-        {
-          pIndoor->pDoors[door_id].uTimeSinceTriggered = 0;
-          return;
-        }
-        if ( pIndoor->pDoors[door_id].uTimeSinceTriggered != 15360 )
-        {
-          pIndoor->pDoors[door_id].uTimeSinceTriggered = (pIndoor->pDoors[door_id].uMoveLength << 7) / pIndoor->pDoors[door_id].uOpenSpeed
-             - ((signed int)(pIndoor->pDoors[door_id].uTimeSinceTriggered * pIndoor->pDoors[door_id].uCloseSpeed)
-             / 128 << 7) / pIndoor->pDoors[door_id].uOpenSpeed;
-          return;
-        }
-        pIndoor->pDoors[door_id].uTimeSinceTriggered = 15360;
-      }
-      return;
-    }
-    if ( a2 != 1 )
-      return;
-  }
-  if ( old_state != BLVDoor::Open && old_state != BLVDoor::Opening )
-  {
-    pIndoor->pDoors[door_id].uState = BLVDoor::Opening;
-    if ( old_state == BLVDoor::Closed )
-    {
-      pIndoor->pDoors[door_id].uTimeSinceTriggered = 0;
-      return;
-    }
-    if ( pIndoor->pDoors[door_id].uTimeSinceTriggered != 15360 )
-    {
-      pIndoor->pDoors[door_id].uTimeSinceTriggered = (pIndoor->pDoors[door_id].uMoveLength << 7) / pIndoor->pDoors[door_id].uCloseSpeed
-         - ((signed int)(pIndoor->pDoors[door_id].uTimeSinceTriggered * pIndoor->pDoors[door_id].uOpenSpeed)
-         / 128 << 7) / pIndoor->pDoors[door_id].uCloseSpeed;
-      return;
-    }
-    pIndoor->pDoors[door_id].uTimeSinceTriggered = 15360;
-  }
-  return;
-}
-
 //----- (00449B57) --------------------------------------------------------
 bool _449B57_test_bit( unsigned __int8 *a1, __int16 a2 )
 {
@@ -4949,7 +4441,7 @@
   dword_5B65C0 = 0;
 
   pGameLoadingUI_ProgressBar->uType = GUIProgressBar::TYPE_Fullscreen;
-  sub_44987B("nwc.blv", MapStartPoint_Party);
+  Transition_StopSound_Autosave("nwc.blv", MapStartPoint_Party);
   pCurrentScreen = SCREEN_GAME;
   return true;
 }
--- a/mm7_4.cpp	Fri Dec 20 01:25:52 2013 +0100
+++ b/mm7_4.cpp	Fri Dec 20 01:28:39 2013 +0100
@@ -989,36 +989,33 @@
 {
   int v3; // esi@1
   int result; // eax@1
-  stru339_spell_sound *v5; // ebx@1
+  //stru339_spell_sound *v5; // ebx@1
   int *v6; // edi@2
   unsigned int v7; // eax@3
   int v8; // [sp+Ch] [bp-8h]@3
   int v9; // [sp+10h] [bp-4h]@2
   int a2a; // [sp+1Ch] [bp+8h]@1
-  return 0;
+  //return 0;
   v3 = 0;
   result = word_4EE088_sound_ids[uSoundID];
-  v5 = this;
+  //v5 = this;
   a2a = word_4EE088_sound_ids[uSoundID];
-  if ( result )
+  if ( word_4EE088_sound_ids[uSoundID] )
   {
-    v9 = 0;
     v6 = this->pSoundsOffsets;
-    do
+    for ( v9 = 0; v9 < 2; ++v9 )
     {
       v7 = a2a++;
-      result = pSoundList->LoadSound(v7, (char *)v5 + v3, 44744 - v3, &v8, a6);
+      result = pSoundList->LoadSound(v7, (char *)this + v3, 44744 - v3, &v8, a6);
       if ( !result )
         break;
       a6 += 4;
       result = v8 + 256;
-      *v6 = v3;
+      this->pSoundsOffsets[v9] = v3;
       v3 += result;
-      ++v9;
-      *(v6 - 2) = result;
+      this->pSoundsSizes[v9] = v8 + 256;
       ++v6;
     }
-    while ( v9 < 2 );
   }
   return result;
 }
@@ -1027,28 +1024,12 @@
 //----- (00494AED) --------------------------------------------------------
 unsigned int PlayerFrameTable::GetFrameIdByExpression(CHARACTER_EXPRESSION_ID expression)
 {
-  unsigned int _uNumFrames; // edx@1
-  unsigned int result; // eax@1
-  PlayerFrame *v4; // ecx@2
-
-  _uNumFrames = this->uNumFrames;
-  result = 0;
-  if ( (signed int)this->uNumFrames <= 0 )
+  for ( uint i = 0; i < this->uNumFrames; i++ )
   {
-    result = 0;
+    if ( this->pFrames[i].expression == expression )
+      return i;
   }
-  else
-  {
-    v4 = this->pFrames;
-    while ( v4->expression != expression )
-    {
-      ++result;
-      ++v4;
-      if ( (signed int)result >= (signed int)_uNumFrames )
-        return 0;
-    }
-  }
-  return result;
+  return 0;
 }
 
 //----- (00494B10) --------------------------------------------------------
@@ -1771,64 +1752,30 @@
 //----- (0049B13D) --------------------------------------------------------
 void stru154::GetFacePlane(ODMFace *pFace, BSPVertexBuffer *pVertices, Vec3_float_ *pOutNormal, float *pOutDist)
 {
-  ODMFace *v5; // ebx@1
-  //int v6; // eax@1
-  //unsigned __int16 *v7; // ebx@2
-  //Vec3_int_ *v8; // eax@3
-  Vec3_int_ *v9; // ecx@3
-  //double v10; // st7@3
-  //int v11; // ecx@3
-  Vec3_int_ *v12; // ecx@3
-  //double v13; // st7@3
-  //double v14; // st6@3
-  //double v15; // st5@3
-  //int v16; // ecx@3
-  Vec3_int_ *v17; // eax@3
-  //double v18; // st5@3
   Vec3_float_ *v19; // eax@3
-  //int result; // eax@8
-  //float v21; // ecx@10
-  //double v22; // st7@10
-  //double v23; // st6@10
   Vec3_float_ v2; // [sp+4h] [bp-64h]@3
-  //float v25; // [sp+18h] [bp-50h]@3
   float v26; // [sp+1Ch] [bp-4Ch]@3
   float v27; // [sp+20h] [bp-48h]@3
   float v28; // [sp+24h] [bp-44h]@3
-  //float v29; // [sp+2Ch] [bp-3Ch]@3
-  //float v30; // [sp+30h] [bp-38h]@3
-  //float v31; // [sp+34h] [bp-34h]@3
-  //float v32; // [sp+38h] [bp-30h]@3
-  //float v33; // [sp+3Ch] [bp-2Ch]@3
   Vec3_float_ v1; // [sp+40h] [bp-28h]@1
-  //float v35; // [sp+4Ch] [bp-1Ch]@3
-  //float v36; // [sp+50h] [bp-18h]@3
-  //float v37; // [sp+54h] [bp-14h]@3
   Vec3_float_ v38; // [sp+58h] [bp-10h]@3
-  //int v39; // [sp+64h] [bp-4h]@1
 
-  //v39 = 0;
   v1.x = 0.0;
-  v5 = pFace;
-  //v6 = pFace->uNumVertices;
   v1.y = 0.0;
   v1.z = 0.0;
 
   if (pFace->uNumVertices >= 2)
   {
-    int i = 0;
-    while ( i < pFace->uNumVertices - 2 )
+    for ( int i = 0; i < pFace->uNumVertices - 2; i++ )
     {
-      v9 = &pVertices->pVertices[pFace->pVertexIDs[i]];
-      v12 = &pVertices->pVertices[pFace->pVertexIDs[i + 1]];
-      v17 = &pVertices->pVertices[pFace->pVertexIDs[i + 2]];
-	  i++;
-      v1.x = v12->x - v9->x;
-      v26 = v17->x - v12->x;
-      v1.y = v12->y - v9->y;
-      v27 = v17->y - v12->y;
-      v1.z = v12->z - v9->z;
-      v28 = v17->z - v12->z;
+      v1.x = pVertices->pVertices[pFace->pVertexIDs[i + 1]].x - pVertices->pVertices[pFace->pVertexIDs[i]].x;
+      v1.y = pVertices->pVertices[pFace->pVertexIDs[i + 1]].y - pVertices->pVertices[pFace->pVertexIDs[i]].y;
+      v1.z = pVertices->pVertices[pFace->pVertexIDs[i + 1]].z - pVertices->pVertices[pFace->pVertexIDs[i]].z;
+
+      v26 = pVertices->pVertices[pFace->pVertexIDs[i + 2]].x - pVertices->pVertices[pFace->pVertexIDs[i + 1]].x;
+      v27 = pVertices->pVertices[pFace->pVertexIDs[i + 2]].y - pVertices->pVertices[pFace->pVertexIDs[i + 1]].y;
+      v28 = pVertices->pVertices[pFace->pVertexIDs[i + 2]].z - pVertices->pVertices[pFace->pVertexIDs[i + 1]].z;
+
       v19 = Vec3_float_::Cross(&v1, &v2, v26, v27, v28);
       v38.x = v19->x;
       v38.y = v19->y;
@@ -1841,28 +1788,28 @@
         pOutNormal->y = v38.y;
         pOutNormal->z = v38.z;
 
-        *pOutDist = -(v9->x * v38.x + v9->y * v38.y + v9->z * v38.z);
+        *pOutDist = -(pVertices->pVertices[pFace->pVertexIDs[i]].x * v38.x
+                    + pVertices->pVertices[pFace->pVertexIDs[i]].y * v38.y
+                    + pVertices->pVertices[pFace->pVertexIDs[i]].z * v38.z);
         return;
       }
     }
   }
 
-  pOutNormal->x = (double)(v5->pFacePlane.vNormal.x & 0xFFFF) / 65535.0f + (double)(v5->pFacePlane.vNormal.x >> 16);
-  pOutNormal->y = (double)(v5->pFacePlane.vNormal.y & 0xFFFF) / 65535.0f + (double)(v5->pFacePlane.vNormal.y >> 16);
-  pOutNormal->z = (double)(v5->pFacePlane.vNormal.z & 0xFFFF) / 65535.0f + (double)(v5->pFacePlane.vNormal.z >> 16);
-  *pOutDist = (double)(v5->pFacePlane.dist & 0xFFFF) / 65535.0f + (double)(v5->pFacePlane.dist >> 16);
+  pOutNormal->x = (double)(pFace->pFacePlane.vNormal.x & 0xFFFF) / 65535.0f + (double)(pFace->pFacePlane.vNormal.x >> 16);
+  pOutNormal->y = (double)(pFace->pFacePlane.vNormal.y & 0xFFFF) / 65535.0f + (double)(pFace->pFacePlane.vNormal.y >> 16);
+  pOutNormal->z = (double)(pFace->pFacePlane.vNormal.z & 0xFFFF) / 65535.0f + (double)(pFace->pFacePlane.vNormal.z >> 16);
+  *pOutDist = (double)(pFace->pFacePlane.dist & 0xFFFF) / 65535.0f + (double)(pFace->pFacePlane.dist >> 16);
 }
 
 //----- (0049D700) --------------------------------------------------------
 unsigned int __fastcall GetMaxMipLevels(unsigned int uDim)
 {
-  unsigned int v1; // eax@1
   int v2; // ecx@1
   unsigned int v3; // eax@1
 
-  v1 = uDim;
   v2 = 0;
-  v3 = v1 - 1;
+  v3 = uDim - 1;
   while ( v3 & 1 )
   {
     v3 >>= 1;
@@ -2287,28 +2234,29 @@
   uDialogueType = 84;
   current_npc_text = (char *)pNPCTopics[667].pText;
   v0 = _4F0882_evt_VAR_PlayerItemInHands_vals.data();
-  while ( 1 )
+  //while ( 1 )
+  for ( uint i = 0; i <= 53; i++ )
   {
     if ( (unsigned __int16)_449B57_test_bit(pParty->_quest_bits, *v0) )
     {
-      v1 = 0;
-      v2 = pParty->pPlayers.data();
-      do
+      //v1 = 0;
+      //v2 = pParty->pPlayers.data();
+      for ( uint pl = 0; pl < 4; pl++ )
       {
-        LOBYTE(v3) = v2->CompareVariable(VAR_PlayerItemInHands, *(v0+1));
-        if ( v3 )
+        //LOBYTE(v3) = pParty->pPlayers[pl].CompareVariable(VAR_PlayerItemInHands, *(v0+1));
+        if ( pParty->pPlayers[pl].CompareVariable(VAR_PlayerItemInHands, *(v0+1)) )
           break;
-        ++v2;
-        ++v1;
+        //++v2;
+        //++v1;
       }
-      while ( (signed int)v2 < (signed int)pParty->pHirelings.data() );
-      if ( v1 == 4 )
-        break;
+      //while ( (signed int)v2 < (signed int)pParty->pHirelings.data() );
+      //if ( v1 == 4 )
+        //break;
     }
     ++v11;
-    v0 += 2;
-    if ( v0 > &_4F0882_evt_VAR_PlayerItemInHands_vals[53] )
-	  break;
+    //v0 += 2;
+    //if ( v0 > &_4F0882_evt_VAR_PlayerItemInHands_vals[53] )
+	  //break;
   }
   if ( v0 <= &_4F0882_evt_VAR_PlayerItemInHands_vals[53] )
   {
@@ -2320,41 +2268,35 @@
   if ( contract_approved == 601 )
   {
     v5 = 0;
-    v12 = pParty->pPlayers.data();//[0].uClass;
+    //v12 = pParty->pPlayers.data();//[0].uClass;
     v9 = 0;
-    while ( 1 )
+    //while ( 1 )
+    for ( uint i = 0; i < 4; i++ )
     {
-      if ( v12->classType == PLAYER_CLASS_LICH )
+      if ( pParty->pPlayers[i].classType == PLAYER_CLASS_LICH )
       {
         v10 = 0;
-        v6 = pParty->pPlayers.data();//[0].pInventoryItems[0].field_1A;
-        do
+        //v6 = pParty->pPlayers.data();//[0].pInventoryItems[0].field_1A;
+        for ( uint pl = 0; pl < 4; pl++ )
         {
-		  v7 = v6->pInventoryItemList.data();
-          v8 = 138;
-          do
+          for ( v8 = 0; v8 < 126; v8++ )//138
           {
-			if ( v7->uItemID == ITEM_LICH_JAR_FULL )
+            if ( pParty->pPlayers[pl].pInventoryItemList[v8].uItemID == ITEM_LICH_JAR_FULL )
             {
-			  if ( !v7->uHolderPlayer )
-				  v9 = v7;
-			  if ( v7->uHolderPlayer == v5 )
+              if ( !pParty->pPlayers[pl].pInventoryItemList[v8].uHolderPlayer )
+                v9 = &pParty->pPlayers[pl].pInventoryItemList[v8];
+              if ( pParty->pPlayers[pl].pInventoryItemList[v8].uHolderPlayer == v5 )
                 v10 = 1;
             }
-            ++v7;
-            --v8;
           }
-          while ( v8 );
-          ++v6;
         }
-		while ( v6 <= &pParty->pPlayers[3] );
         if ( !v10 )
           break;
       }
-      ++v12;
+//      ++v12;
       ++v5;
-	  if ( v12 > &pParty->pPlayers[3] )
-        return;
+	//  if ( v12 > &pParty->pPlayers[3] )
+      //  return;
     }
     if ( v9 )
 	  v9->uHolderPlayer = v5;
@@ -2375,8 +2317,8 @@
   signed int v9; // esi@8
   int v10; // eax@8
   char *v11; // ecx@8
-  int v12; // edi@9
-  char *v13; // edx@9
+  //int v12; // edi@9
+  //char *v13; // edx@9
   signed int v14; // edi@10
   unsigned int v16; // eax@29
   //int v17; // eax@36
@@ -2435,27 +2377,23 @@
   if ( v6 < v2 + 2 )
   {
     //v8 = v33;
-    v9 = 0;
+    
     v10 = pClassType - pClassType % 4;
     v11 = &byte_4ED970_skill_learn_ability_by_class_table[pClassType - pClassType % 4][v3];
-    do
+    for ( v9 = 0; v9 < 4; ++v9 )
     {
-      v12 = (unsigned __int8)*v11;
-      v13 = &v28[4 * v9];
-      *(int *)v13 = 0;
-      if ( v12 < v34 )
+      v28[4 * v9] = 0;
+      if ( (unsigned __int8)*v11 < v34 )
       {
         v14 = 1;
       }
       else
       {
         v14 = 1;
-        *(int *)v13 = 1;
+        v28[4 * v9] = 1;
       }
-      ++v9;
       v11 += 37;
     }
-    while ( v9 < 4 );
     __debugbreak(); // warning C4700: uninitialized local variable 'v29' used
     if ( v29 == v14 )
     {
@@ -2763,20 +2701,18 @@
 //----- (004B3FE5) --------------------------------------------------------
 void __fastcall _4B3FE5_training_dialogue(int a4)
 {
-  int v1; // edi@1
   const char *v2; // edi@1
-  
+
   __debugbreak();
-  v1 = a4;
   uDialogueType = 78;
   current_npc_text = (char *)pNPCTopics[a4 + 168].pText;
   _4B254D_SkillMasteryTeacher(a4);
   pDialogueWindow->Release();
-  pDialogueWindow = GUIWindow::Create(0, 0, 640, 0x15Eu, WINDOW_MainMenu, v1, 0);
-  v2 = "";
-  pBtn_ExitCancel = pDialogueWindow->CreateButton( 0x1D7u, 0x1BDu, 0xA9u,  0x23u,   1,  0, UIMSG_Escape, 0,   0,
+  pDialogueWindow = GUIWindow::Create(0, 0, 640, 350, WINDOW_MainMenu, a4, 0);
+  pBtn_ExitCancel = pDialogueWindow->CreateButton( 471, 445, 169,  35,   1,  0, UIMSG_Escape, 0,   0,
                  pGlobalTXT_LocalizationStrings[34], pIcons_LOD->GetTexture(uExitCancelTextureId), 0);
   pDialogueWindow->CreateButton(0, 0, 0, 0, 1, 0, UIMSG_BuyInShop_Identify_Repair, 0, 0, "", 0);
+  v2 = "";
   if ( contract_approved )
     v2 = pGlobalTXT_LocalizationStrings[535];
   pDialogueWindow->CreateButton(0x1E0u, 0xA0u, 0x8Cu, 0x1Eu, 1, 0, UIMSG_ClickNPCTopic, 0x4Fu, 0, v2, 0);
@@ -2789,10 +2725,8 @@
 //----- (004B46A5) --------------------------------------------------------
 void __fastcall DrawTextAtStatusBar( const char *Str, int a5 )
 {
-  int v4; // eax@1
   pRenderer->DrawTextureRGB(0, 352, pTexture_StatusBar);
-  v4 = pFontLucida->AlignText_Center(450, Str);
-  pPrimaryWindow->DrawText(pFontLucida, v4 + 11, 357, a5, Str, 0, 0, 0);
+  pPrimaryWindow->DrawText(pFontLucida, pFontLucida->AlignText_Center(450, Str) + 11, 357, a5, Str, 0, 0, 0);
 }
 
 //----- (004B46F8) --------------------------------------------------------
@@ -2810,235 +2744,170 @@
 //----- (004BC49B) --------------------------------------------------------
 void OnSelectNPCDialogueOption(DIALOGUE_TYPE newDialogueType)
 {
-	//unsigned int v1; // esi@1
-    NPCData *speakingNPC; // ebp@1
-    //unsigned int v3; // eax@1
-    int npc_event_id; // ecx@10
-    signed int v5; // edi@14
-    char *v6; // esi@15
-    const char *v7; // ecx@22
-    signed int v8; // edi@37
-    //unsigned int v9; // eax@56
-    unsigned int v10; // ecx@57
-    void *v11; // [sp-Ch] [bp-1Ch]@46
-    int v12; // [sp-8h] [bp-18h]@46
-    char *v13; // [sp-8h] [bp-18h]@60
-    size_t v14; // [sp-4h] [bp-14h]@46
-    const char *v15; // [sp-4h] [bp-14h]@60
-
-    //v1 = _this;
-	speakingNPC = GetNPCData(sDialogue_SpeakingActorNPC_ID);
-    //v3 = v1;
-	uDialogueType = newDialogueType;
-	if (!speakingNPC->uFlags)
-	{
-		speakingNPC->uFlags = 1;
-		//v3 = uDialogueType;
-	}
-
-	if(newDialogueType == DIALOGUE_PROFESSION_DETAILS)
-	{
-		dialogue_show_profession_details = ~dialogue_show_profession_details;
-	}
-	else if(newDialogueType == DIALOGUE_76)
-	{
-		if (speakingNPC->Hired())
-		{
-			v8 = 0;
-			if ( (signed int)pNPCStats->uNumNewNPCs > 0 )
-			{
-				v6 = (char *)pNPCStats->pNewNPCData;
-				while ( !(v6[8] & 0x80) || strcmp(speakingNPC->pName, *(const char **)v6) )
-				{
-					++v8;
-					v6 += 76;
-					if ( v8 >= (signed int)pNPCStats->uNumNewNPCs )
-						break;
-				}
-				if( v8 < (signed int)pNPCStats->uNumNewNPCs )
-					v6[8] &= 0x7Fu;
-			}
-			if ( pParty->pHirelings[0].pName && !_stricmp(pParty->pHirelings[0].pName, speakingNPC->pName) )
-			{
-				v11 = pParty->pHirelings.data();
-				memset(v11, 0, sizeof(NPCData));
-			}
-			else if ( pParty->pHirelings[1].pName && !_stricmp(pParty->pHirelings[1].pName, speakingNPC->pName) )
-			{
-				v11 = &pParty->pHirelings[1];
-				memset(v11, 0, sizeof(NPCData));
-			}
-			pParty->hirelingScrollPosition = 0;
-			pParty->CountHirelings();
-			dword_591084 = 0;
-			pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
-			dword_7241C8 = 0;
-			return;
-		}
-		if ( pParty->pHirelings[0].pName && pParty->pHirelings[1].pName )
-		{
-			v7 = pGlobalTXT_LocalizationStrings[533]; // ""I cannot join you, you're party is full""
-			ShowStatusBarString(v7, 2u);
-		}
-		else
-		{
-			//v9 = v2->uProfession;
-			if ( speakingNPC->uProfession != 51 )
-			{
-				v10 = pNPCStats->pProfessions[speakingNPC->uProfession - 1].uHirePrice;
-																	if ( pParty->uNumGold < v10 )
-			{
-				ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);// "You don't have enough gold"
-				dialogue_show_profession_details = false;
-				uDialogueType = 13;
-				if ( uActiveCharacter )
-					pPlayers[uActiveCharacter]->PlaySound(SPEECH_NotEnoughGold, 0);
-				v7 = pGlobalTXT_LocalizationStrings[155];
-				ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2u);
-				if ( !dword_7241C8 )
-					pGame->Draw();
-				dword_7241C8 = 0;
-				return;
-			}
-				Party::TakeGold(v10);
-			}
-			LOBYTE(speakingNPC->uFlags) |= 0x80u;
-			if ( pParty->pHirelings[0].pName )
-			{
-				memcpy(&pParty->pHirelings[1], speakingNPC, sizeof(pParty->pHirelings[1]));
-				v15 = speakingNPC->pName;
-				v13 = pParty->pHireling2Name;
-			}
-			else
-			{
-				memcpy(pParty->pHirelings.data(), speakingNPC, 0x4Cu);
-				v15 = speakingNPC->pName;
-				v13 = pParty->pHireling1Name;
-			}
-			strcpy(v13, v15);
-			pParty->hirelingScrollPosition = 0;
-			pParty->CountHirelings();
+  NPCData *speakingNPC; // ebp@1
+  int npc_event_id; // ecx@10
+  char *v13; // [sp-8h] [bp-18h]@60
 
-			pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
-
-			if ( sDialogue_SpeakingActorNPC_ID >= 0 )
-				pDialogue_SpeakingActor->uAIState = Removed;
-			if ( uActiveCharacter )
-				pPlayers[uActiveCharacter]->PlaySound(SPEECH_61, 0);
-		}
-	}
-	else if ( (signed int)newDialogueType > 84 && (signed int)newDialogueType <= 88 )
-	{
-		ArenaFight();
-		return;
-	}
-	else if(newDialogueType == DIALOGUE_USE_NPC_ABILITY)
-	{
-		if (UseNPCSkill((NPCProf)speakingNPC->uProfession) == 0)
-		{
-			if ( speakingNPC->uProfession != GateMaster )
-				speakingNPC->bHasUsedTheAbility = 1;
-
-			pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
-		}
-		else
-			ShowStatusBarString(pGlobalTXT_LocalizationStrings[140], 2); //"Your packs are already full!"
-	}
-	else if(newDialogueType == DIALOGUE_13)
-	{
-		if (!speakingNPC->Hired())
-		{
-			sub_4B3E1E();
-			dialogue_show_profession_details = false;
-		}
-		else
-		{
-			v5 = 0;
-			if ( (signed int)pNPCStats->uNumNewNPCs > 0 )
-			{
-				v6 = (char *)pNPCStats->pNewNPCData;
-				while ( !(v6[8] & 0x80) || strcmp(speakingNPC->pName, *(const char **)v6) )
-				{
-					++v5;
-					v6 += 76;
-					if ( v5 >= (signed int)pNPCStats->uNumNewNPCs )
-						break;
-				}
-				if ( v5 < (signed int)pNPCStats->uNumNewNPCs )
-					v6[8] &= 0x7Fu;
-			}
-			if ( pParty->pHirelings[0].pName && !_stricmp(pParty->pHirelings[0].pName, speakingNPC->pName) )
-			{
-				v11 = pParty->pHirelings.data();
-				memset(v11, 0, sizeof(NPCData));
-			}
-			else if ( pParty->pHirelings[1].pName && !_stricmp(pParty->pHirelings[1].pName, speakingNPC->pName) )
-			{
-				v11 = &pParty->pHirelings[1];
-				memset(v11, 0, sizeof(NPCData));
-			}
-			pParty->hirelingScrollPosition = 0;
-			pParty->CountHirelings();
-			dword_591084 = 0;
-			pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
-			dword_7241C8 = 0;
-			return;
-		}
-	}
-	else if(newDialogueType >= 19 && newDialogueType <= 24)
-	{
-		switch(newDialogueType)
-		{
-			case DIALOGUE_19:  npc_event_id = speakingNPC->evt_A; break;
-			case DIALOGUE_20:  npc_event_id = speakingNPC->evt_B; break;
-			case DIALOGUE_21:  npc_event_id = speakingNPC->evt_C; break;
-			case DIALOGUE_22:	 npc_event_id = speakingNPC->evt_D; break;
-			case DIALOGUE_23:  npc_event_id = speakingNPC->evt_E; break;
-			case DIALOGUE_24:	 npc_event_id = speakingNPC->evt_F; break;
-		}
-		if ( (npc_event_id >= 200) && (npc_event_id <= 310) )
-			_4B3FE5_training_dialogue(npc_event_id); //200-310
-		else if (( npc_event_id >= 400) && (npc_event_id <= 410) )
-		{ //400-410
-			dword_F8B1D8 = newDialogueType;
-			DrawJoinGuildWindow(npc_event_id - 400);
-		}
-		else
-		{
-			switch ( npc_event_id )
-			{
-				case 139:
-					OracleDialogue();
-					break;
-				case 311:
-					CheckBountyRespawnAndAward();
-					break;
-				case 399:
-					Arena_SelectionFightLevel();
-					break;
-				default:
-					activeLevelDecoration = (LevelDecoration*)1;
-					current_npc_text = 0;
-					EventProcessor(npc_event_id, 0, 1);
-					activeLevelDecoration = NULL;
-					break;
-			}
-		}
-	}
-	if ( !dword_7241C8 )
-		pGame->Draw();
-	dword_7241C8 = 0;
+  speakingNPC = GetNPCData(sDialogue_SpeakingActorNPC_ID);
+  uDialogueType = newDialogueType;
+  if (!speakingNPC->uFlags)
+    speakingNPC->uFlags = 1;
+  if(newDialogueType == DIALOGUE_PROFESSION_DETAILS)
+    dialogue_show_profession_details = ~dialogue_show_profession_details;
+  else if(newDialogueType == DIALOGUE_76)
+  {
+    if (speakingNPC->Hired())
+    {
+      if ( (signed int)pNPCStats->uNumNewNPCs > 0 )
+      {
+        for ( uint i = 0; i < (unsigned int)pNPCStats->uNumNewNPCs; ++i )
+        {
+          if ( pNPCStats->pNewNPCData[i].uFlags & 0x80 && !strcmp(speakingNPC->pName, pNPCStats->pNewNPCData[i].pName) )
+            pNPCStats->pNewNPCData[i].uFlags &= 0x7Fu;
+        }
+      }
+      if ( pParty->pHirelings[0].pName && !_stricmp(pParty->pHirelings[0].pName, speakingNPC->pName) )
+        memset(&pParty->pHirelings[0], 0, sizeof(NPCData));
+      else if ( pParty->pHirelings[1].pName && !_stricmp(pParty->pHirelings[1].pName, speakingNPC->pName) )
+        memset(&pParty->pHirelings[1], 0, sizeof(NPCData));
+      pParty->hirelingScrollPosition = 0;
+      pParty->CountHirelings();
+      dword_591084 = 0;
+      pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
+      dword_7241C8 = 0;
+      return;
+    }
+    if ( pParty->pHirelings[0].pName && pParty->pHirelings[1].pName )
+      ShowStatusBarString(pGlobalTXT_LocalizationStrings[533], 2);// ""I cannot join you, you're party is full""
+    else
+    {
+      if ( speakingNPC->uProfession != 51 )
+      {
+        if ( pParty->uNumGold < pNPCStats->pProfessions[speakingNPC->uProfession - 1].uHirePrice )
+        {
+          ShowStatusBarString(pGlobalTXT_LocalizationStrings[155], 2);// "You don't have enough gold"
+          dialogue_show_profession_details = false;
+          uDialogueType = 13;
+          if ( uActiveCharacter )
+            pPlayers[uActiveCharacter]->PlaySound(SPEECH_NotEnoughGold, 0);
+          if ( !dword_7241C8 )
+            pGame->Draw();
+          dword_7241C8 = 0;
+          return;
+        }
+        Party::TakeGold(pNPCStats->pProfessions[speakingNPC->uProfession - 1].uHirePrice);
+      }
+      LOBYTE(speakingNPC->uFlags) |= 0x80u;
+      if ( pParty->pHirelings[0].pName )
+      {
+        memcpy(&pParty->pHirelings[1], speakingNPC, sizeof(pParty->pHirelings[1]));
+        v13 = pParty->pHireling2Name;
+      }
+      else
+      {
+        memcpy(&pParty->pHirelings[0], speakingNPC, sizeof(pParty->pHirelings[0]));
+        v13 = pParty->pHireling1Name;
+      }
+      strcpy(v13, speakingNPC->pName);
+      pParty->hirelingScrollPosition = 0;
+      pParty->CountHirelings();
+      pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
+      if ( sDialogue_SpeakingActorNPC_ID >= 0 )
+        pDialogue_SpeakingActor->uAIState = Removed;
+      if ( uActiveCharacter )
+        pPlayers[uActiveCharacter]->PlaySound(SPEECH_61, 0);
+    }
+  }
+  else if ( (signed int)newDialogueType > DIALOGUE_84 && (signed int)newDialogueType <= DIALOGUE_ARENA_SELECT_CHAMPION ) //выбор уровня сложности боя
+  {
+    ArenaFight();
+    return;
+  }
+  else if(newDialogueType == DIALOGUE_USE_NPC_ABILITY)
+  {
+    if (UseNPCSkill((NPCProf)speakingNPC->uProfession) == 0)
+    {
+      if ( speakingNPC->uProfession != GateMaster )
+        speakingNPC->bHasUsedTheAbility = 1;
+      pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
+    }
+    else
+      ShowStatusBarString(pGlobalTXT_LocalizationStrings[140], 2); //"Your packs are already full!"
+  }
+  else if(newDialogueType == DIALOGUE_13)
+  {
+    if (!speakingNPC->Hired())
+    {
+      sub_4B3E1E();
+      dialogue_show_profession_details = false;
+    }
+    else
+    {
+      for ( uint i = 0; i < (signed int)pNPCStats->uNumNewNPCs; ++i )
+      {
+        if ( pNPCStats->pNewNPCData[i].uFlags & 0x80 && !strcmp(speakingNPC->pName, pNPCStats->pNewNPCData[i].pName) )
+          pNPCStats->pNewNPCData[i].uFlags &= 0x7Fu;
+      }
+      if ( pParty->pHirelings[0].pName && !_stricmp(pParty->pHirelings[0].pName, speakingNPC->pName) )
+        memset(&pParty->pHirelings[0], 0, sizeof(NPCData));
+      else if ( pParty->pHirelings[1].pName && !_stricmp(pParty->pHirelings[1].pName, speakingNPC->pName) )
+        memset(&pParty->pHirelings[1], 0, sizeof(NPCData));
+      pParty->hirelingScrollPosition = 0;
+      pParty->CountHirelings();
+      dword_591084 = 0;
+      pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 1, 0);
+      dword_7241C8 = 0;
+      return;
+    }
+  }
+  else if(newDialogueType >= DIALOGUE_EVT_A && newDialogueType <= DIALOGUE_EVT_F)
+  {
+    switch(newDialogueType)
+    {
+      case DIALOGUE_EVT_A:  npc_event_id = speakingNPC->evt_A; break;
+      case DIALOGUE_EVT_B:  npc_event_id = speakingNPC->evt_B; break;
+      case DIALOGUE_EVT_C:  npc_event_id = speakingNPC->evt_C; break;
+      case DIALOGUE_EVT_D:  npc_event_id = speakingNPC->evt_D; break;
+      case DIALOGUE_EVT_E:  npc_event_id = speakingNPC->evt_E; break;
+      case DIALOGUE_EVT_F:  npc_event_id = speakingNPC->evt_F; break;
+    }
+    if ( (npc_event_id >= 200) && (npc_event_id <= 310) )
+      _4B3FE5_training_dialogue(npc_event_id); //200-310
+    else if (( npc_event_id >= 400) && (npc_event_id <= 410) )
+    { //400-410
+      dword_F8B1D8 = newDialogueType;
+      DrawJoinGuildWindow(npc_event_id - 400);
+    }
+    else
+    {
+      switch ( npc_event_id )
+      {
+        case 139:
+          OracleDialogue();
+          break;
+        case 311:
+          CheckBountyRespawnAndAward();
+          break;
+        case 399:
+          Arena_SelectionFightLevel();
+          break;
+        default:
+          activeLevelDecoration = (LevelDecoration*)1;
+          current_npc_text = 0;
+          EventProcessor(npc_event_id, 0, 1);
+          activeLevelDecoration = NULL;
+          break;
+      }
+    }
+  }
+  if ( !dword_7241C8 )
+    pGame->Draw();
+  dword_7241C8 = 0;
 }
 
 //----- (004BDAAF) --------------------------------------------------------
 bool MerchandiseTest(ItemGen *item, int _2da_idx)
 {
-  int v6; // edx@8
-  int v7; // edx@9
-  int v8; // edx@10
-  unsigned __int8 v9; // zf@16
-  char v10; // sf@16
-  unsigned __int8 v11; // of@16
   bool test;
 
   if ( (p2DEvents[_2da_idx - 1].uType != 4 || (signed int)item->uItemID < 740 || (signed int)item->uItemID > 771)
--- a/mm7_data.h	Fri Dec 20 01:25:52 2013 +0100
+++ b/mm7_data.h	Fri Dec 20 01:28:39 2013 +0100
@@ -1310,8 +1310,8 @@
 void ODM_ProcessPartyActions();
 bool sub_47531C(int a1, int *a2, int pos_x, int pos_y, int pos_z, int dir_x, int dir_y, int dir_z, struct BLVFace *face, int a10);
 bool sub_4754BF(int a1, int *a2, int X, int Y, int Z, int dir_x, int dir_y, int dir_z, struct BLVFace *face, int a10, int a11);
-int sub_475665(struct BLVFace *_this, int a2, __int16 a3);
-bool __fastcall sub_4759C9(struct BLVFace *a1, int a2, int a3, __int16 a4);
+int sub_475665(struct BLVFace *face, int a2, __int16 a3);
+bool __fastcall sub_4759C9(struct BLVFace *face, int a2, int a3, __int16 a4);
 bool __fastcall sub_475D85(Vec3_int_ *a1, Vec3_int_ *a2, int *a3, struct BLVFace *a4);
 bool __fastcall sub_475F30(int *a1, struct BLVFace *a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9);
 void sub_4452BB();
@@ -1322,7 +1322,7 @@
 void  DialogueEnding();
 void PrepareHouse(enum HOUSE_ID house); // idb
 bool EnterHouse(enum HOUSE_ID uHouseID);
-int sub_4465DF_check_season(int a1);
+bool sub_4465DF_check_season(int a1);
 int __fastcall IsActorAlive(unsigned int uType, unsigned int uParam, unsigned int uNumAlive); // idb
 int NPC_EventProcessor(int npc_event_id, int entry_line = 0);
 void __fastcall sub_448518_npc_set_item(int npc, unsigned int item, int a3);