changeset 1351:f1209ed77782

Player::PlaySound cleanup
author Grumpy7
date Sat, 13 Jul 2013 04:16:30 +0200
parents 8baf20c8f805
children 88f80476c99c
files Player.cpp
diffstat 1 files changed, 55 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/Player.cpp	Sat Jul 13 01:44:53 2013 +0200
+++ b/Player.cpp	Sat Jul 13 04:16:30 2013 +0200
@@ -448,6 +448,7 @@
   int item_idx; // eax@1
   int inv_index; // eax@3
 
+
   item_idx = *pitem_index;
   if ( item_idx >125 || item_idx < 0 )
   {
@@ -505,29 +506,19 @@
 //----- (004948B1) --------------------------------------------------------
 void Player::PlaySound(PlayerSpeech speech, int a3)
 {
-  //Player *pPlayer; // edi@1
-  //int v4; // eax@4
-  signed int v5; // esi@4
-  unsigned char *v6; // ebx@4
-  signed int v7; // ecx@5
+  signed int speechCount = 0; // esi@4
+  signed int expressionCount = 0; // esi@4
   unsigned __int8 v8; // al@6
-  int v9; // eax@10
-  //unsigned int pVoiceID; // ecx@10
-  int v11; // esi@10
-  //signed int v12; // eax@11
-  signed int v13; // esi@12
+  int pickedVariant; // esi@10
   int v14; // eax@12
-  //int v15; // eax@17
   CHARACTER_EXPRESSION_ID expression; // ebx@17
   signed int v17; // ecx@19
-  char *pSoundID; // edi@20
-  int v20[5]; // [sp+Ch] [bp-1Ch]@7
-  //Player *pPlayer2; // [sp+20h] [bp-8h]@1
+  unsigned int pSoundID; // edi@20
+  int speechVariantArray[5]; // [sp+Ch] [bp-1Ch]@7
+  int expressionVariantArray[5]; 
   int pPlayerNum; // [sp+24h] [bp-4h]@1
-  int pSoundId; // [sp+30h] [bp+8h]@4
-
-  //pPlayer = this;
-  //pPlayer2 = this;
+  unsigned int pickedSoundID; // [sp+30h] [bp+8h]@4
+  unsigned int expressionDuration = 0;
 
   pPlayerNum = 1;
   for (int i = 0; i < 4; ++i)
@@ -537,71 +528,66 @@
       break;
     }
 
-  //v4 = a2;//102
-  v5 = 0;
-  pSoundId = 0;
-  v6 = SoundSetAction[speech].data();//byte_4ED280 &byte_4ED3D8[4 * v4] ???
+  pickedSoundID = 0;
   if (uVoicesVolumeMultiplier)
   {
-    v7 = 0;
-    do
-    {
-      v8 = v6[v7];
+    for (int i = 0; i < 2; i++)
+    {
+      v8 = SoundSetAction[speech][i];
       if ( v8 )
-        v20[v5++] = v8;
-      ++v7;
-    }
-    while ( v7 < 2 );
-    if ( v5 )
-    {
-      v9 = rand();
-      //pVoiceID = uVoiceID;
-      v11 = v20[v9 % v5];
-
-      if (int _v1 = byte_4ECF08[v11 - 1][uVoiceID])
-      {
-        pSoundId = rand() % _v1 + 2 * (v11 + 50 * uVoiceID) + 4998;
-        pAudioPlayer->PlaySound((SoundID)pSoundId, PID(OBJECT_Player, pPlayerNum + 39), 0, -1, 0, 0, pSoundVolumeLevels[uVoicesVolumeMultiplier] * 128.0f, 0);
-      }
-    }
-  }
-
-  v13 = 0;
-  v14 = (int)(v6 + 3);
-  do
-  {
-    if ( *(char *)v14 )
-      v20[v13++] = *(char *)v14;
-    ++v14;
-  }
-  while ( -3 - (signed int)v6 + v14 < 5 );
-  if ( v13 )
-  {
-    pPlayerNum = 0;
-    expression = (CHARACTER_EXPRESSION_ID)v20[rand() % v13];
-    if (expression == CHARACTER_EXPRESSION_21 && pSoundId )
-    {
-      v17 = 0;
+      {
+        speechVariantArray[speechCount] = v8;
+        speechCount++;
+      }
+    }
+    if ( speechCount )
+    {
+      pickedVariant = speechVariantArray[rand() % speechCount];
+      int numberOfSubvariants = byte_4ECF08[pickedVariant - 1][uVoiceID];
+      if (numberOfSubvariants > 0)
+      {
+        pickedSoundID = rand() % numberOfSubvariants + 2 * (pickedVariant + 50 * uVoiceID) + 4998;
+        pAudioPlayer->PlaySound((SoundID)pickedSoundID, PID(OBJECT_Player, pPlayerNum + 39), 0, -1, 0, 0, (int)(pSoundVolumeLevels[uVoicesVolumeMultiplier] * 128.0f), 0);
+      }
+    }
+  }
+
+  for (int i = 0; i < 5; i++)
+  {
+    v14 = SoundSetAction[speech][i + 3];
+    if ( v14 )
+    {
+      expressionVariantArray[expressionCount] = v14;
+      expressionCount++;
+    }
+  }
+  if ( expressionCount )
+  {
+    expression = (CHARACTER_EXPRESSION_ID)expressionVariantArray[rand() % expressionCount];
+    if (expression == CHARACTER_EXPRESSION_21 && pickedSoundID )
+    {
       if ( (signed int)pSoundList->sNumSounds <= 0 )
       {
-LABEL_23:
         v17 = 0;
       }
       else
       {
-        pSoundID = (char *)&pSoundList->pSounds->uSoundID;
-        while ( *(int *)pSoundID != pSoundId )
+        pSoundID = pSoundList->pSounds->uSoundID;
+        v17 = 0;
+        for (int i = 0; i < pSoundList->sNumSounds; i++)
         {
-          ++v17;
+          v17 = i;
+          if (pSoundID == pickedSoundID)
+          {
+            break;
+          }
           pSoundID += 120;
-          if ( v17 >= (signed int)pSoundList->sNumSounds )
-            goto LABEL_23;
         }
       }
       if ( pSoundList->pSounds[v17].pSoundData[0] )
-        pPlayerNum = (sLastTrackLengthMS << 7) / 1000;
-    }
-    /*LOWORD(v14) = */PlayEmotion(expression, pPlayerNum);
+        expressionDuration = (sLastTrackLengthMS << 7) / 1000;
+    }
+    /*LOWORD(v14) = */PlayEmotion(expression, expressionDuration);
   }
   //return v14;
 }