diff Player.cpp @ 190:9b77686e2239

Merge
author Gloval
date Sat, 16 Feb 2013 00:44:38 +0400
parents 038a4d09406f 207b2492e14b
children e6e348d66a75 8113753ed2ae
line wrap: on
line diff
--- a/Player.cpp	Sat Feb 16 00:33:21 2013 +0400
+++ b/Player.cpp	Sat Feb 16 00:44:38 2013 +0400
@@ -1,5 +1,6 @@
+#include <assert.h>
+
 #include "OSAPI.h"
-
 #include "Player.h"
 #include "PlayerFrameTable.h"
 #include "Texture.h"
@@ -570,43 +571,44 @@
 }
 
 //----- (004948B1) --------------------------------------------------------
-__int16 Player::PlaySound(int a2, int a3)
-{
-  Player *pPlayer; // edi@1
-  int v4; // eax@4
+void Player::PlaySound(PlayerSpeech speech, int a3)
+{
+  //Player *pPlayer; // edi@1
+  //int v4; // eax@4
   signed int v5; // esi@4
-  short *v6; // ebx@4
+  char *v6; // ebx@4
   signed int v7; // ecx@5
   unsigned __int8 v8; // al@6
   int v9; // eax@10
-  unsigned int pVoiceID; // ecx@10
+  //unsigned int pVoiceID; // ecx@10
   int v11; // esi@10
   signed int v12; // eax@11
   signed int v13; // esi@12
   int v14; // eax@12
-  int v15; // eax@17
+  //int v15; // eax@17
   int pExpression; // 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
+  //Player *pPlayer2; // [sp+20h] [bp-8h]@1
   int pPlayerNum; // [sp+24h] [bp-4h]@1
   int pSoundId; // [sp+30h] [bp+8h]@4
 
-  pPlayer = this;
-  pPlayer2 = this;
+  //pPlayer = this;
+  //pPlayer2 = this;
+
   pPlayerNum = 1;
-  do
-  {
-    if ( this == pPlayers[pPlayerNum] )
+  for (int i = 0; i < 4; ++i)
+    if (&pParty->pPlayers[i] == this)
+    {
+      pPlayerNum = i + 1;
       break;
-    ++pPlayerNum;
-  }
-  while ( pPlayerNum <= 4 );
-  v4 = a2;//102
+    }
+
+  //v4 = a2;//102
   v5 = 0;
   pSoundId = 0;
-  v6 = &SoundSetAction[8 * v4];//byte_4ED280 &byte_4ED3D8[4 * v4] ???
+  v6 = (char *)&SoundSetAction[4 * speech];//byte_4ED280 &byte_4ED3D8[4 * v4] ???
   if ( uVoicesVolumeMultiplier )
   {
     v7 = 0;
@@ -621,15 +623,15 @@
     if ( v5 )
     {
       v9 = rand();
-      pVoiceID = pPlayer->uVoiceID;
+      //pVoiceID = uVoiceID;
       v11 = v20[v9 % v5];
-      if ( LOBYTE((&(&dlhu_texnames_by_face[19])[25 * v11 + 3])[pVoiceID]) )
-      {
-        pSoundId = rand() % SLOBYTE((&(&dlhu_texnames_by_face[19])[25 * v11 + 3])[pVoiceID])
-            + 2 * (v11 + 50 * pPlayer2->uVoiceID)
+      if ( LOBYTE((&(&dlhu_texnames_by_face[19])[25 * v11 + 3])[uVoiceID]) )
+      {
+        pSoundId = rand() % SLOBYTE((&(&dlhu_texnames_by_face[19])[25 * v11 + 3])[uVoiceID])
+            + 2 * (v11 + 50 * uVoiceID)
             + 4998;
         v12 = 8 * pPlayerNum + 312;
-        LOBYTE(v12) = v12 | 4;
+        LOBYTE(v12) = v12 | OBJECT_Player;
         pAudioPlayer->PlaySound((SoundID)pSoundId, v12, 0, -1, 0, 0, (pSoundVolumeLevels[uVoicesVolumeMultiplier] * 128.0), 0);
       }
     }
@@ -645,9 +647,8 @@
   while ( -3 - (signed int)v6 + v14 < 5 );
   if ( v13 )
   {
-    v15 = rand();
     pPlayerNum = 0;
-    pExpression = v20[v15 % v13];
+    pExpression = v20[rand() % v13];
     if ( pExpression == 21 && pSoundId )
     {
       v17 = 0;
@@ -670,26 +671,27 @@
       if ( pSoundList->pSounds[v17].pSoundData[0] )
         pPlayerNum = (sLastTrackLengthMS << 7) / 1000;
     }
-    LOWORD(v14) = pPlayer2->PlayEmotion((CHARACTER_EXPRESSION_ID)pExpression, pPlayerNum);
-  }
-  return v14;
+    /*LOWORD(v14) = */PlayEmotion((CHARACTER_EXPRESSION_ID)pExpression, pPlayerNum);
+  }
+  //return v14;
 }
 // 4948B1: using guessed type int var_1C[5];
 
 //----- (00494A25) --------------------------------------------------------
-__int16 Player::PlayEmotion(CHARACTER_EXPRESSION_ID expr, int a3)
-{
-  signed int v3; // eax@1
-  CHARACTER_EXPRESSION_ID v4; // dx@1
+void Player::PlayEmotion(CHARACTER_EXPRESSION_ID new_expression, int a3)
+{
+  //signed int v3; // eax@1
+  //CHARACTER_EXPRESSION_ID v4; // dx@1
   signed int v5; // edi@15
   PlayerFrame *v6; // esi@17
   signed int v7; // eax@20
 
-  LOWORD(v3) = this->expression;
-  v4 = expr;
-  if ( (short)v3 != 4 && (short)v3 != 12 || expr != 58 )
-  {
-    v3 = (unsigned __int16)v3;
+  //LOWORD(v3) = this->expression;
+  //v4 = expr;
+  if (expression != CHARACTER_EXPRESSION_SLEEP &&
+      expression != CHARACTER_EXPRESSION_PERTIFIED || new_expression != CHARACTER_EXPRESSION_58)
+  {
+    int v3 = (unsigned)expression;
     if ( (signed int)(unsigned __int16)v3 >= 2 )
     {
       if ( v3 <= 7 )
@@ -698,19 +700,19 @@
       {
         if ( v3 > 11 )
         {
-          if ( v3 == 12 || v3 > 97 && v3 <= 99 )
-            return v3;
+          if ( v3 == CHARACTER_EXPRESSION_PERTIFIED || v3 > 97 && v3 <= 99 )
+            return;
           goto LABEL_15;
         }
 LABEL_12:
-        if ( expr != 34 && expr != 35 && expr != 36 )
-          return v3;
+        if (new_expression != CHARACTER_EXPRESSION_34 && new_expression != CHARACTER_EXPRESSION_35 && new_expression != CHARACTER_EXPRESSION_36)
+          return;
         goto LABEL_15;
       }
     }
   }
 LABEL_15:
-  LOWORD(v3) = a3;
+  //LOWORD(v3) = a3;
   v5 = 0;
   this->uExpressionTimeLength = a3;
   this->uExpressionTimePassed = 0;
@@ -724,7 +726,7 @@
     else
     {
       v6 = pPlayerFrameTable->pFrames;
-      while ( v6->expression != expr )
+      while ( v6->expression != new_expression )
       {
         ++v5;
         ++v6;
@@ -733,13 +735,11 @@
       }
       v7 = v5;
     }
-    v4 = expr;
-    LOWORD(v3) = 8 * pPlayerFrameTable->pFrames[v3].uAnimLength;
-    this->uExpressionTimeLength = v3;
-  }
-  this->expression = v4;
+    //v4 = expr;
+    this->uExpressionTimeLength = 8 * pPlayerFrameTable->pFrames[a3].uAnimLength;
+  }
+  expression = new_expression;
   viewparams->bRedrawGameUI = 1;
-  return v3;
 }
 
 //----- (0049327B) --------------------------------------------------------
@@ -1238,7 +1238,7 @@
           goto LABEL_76;
         goto LABEL_82;
       case 0xDu:
-        v3->PlaySound(32, 0);
+        v3->PlaySound(SPEECH_32, 0);
         v13 = (char *)&v3->sHealth;
         goto LABEL_70;
       case 0xEu:
@@ -1269,9 +1269,9 @@
           goto LABEL_76;
         }
         v28 = 0;
-        v25 = 35;
+        v25 = SPEECH_35;
 LABEL_67:
-        v3->PlaySound(v25, v28);
+        v3->PlaySound((PlayerSpeech)v25, v28);
         if ( v3->sHealth > 0 )
           v3->sHealth = 0;
         v13 = (char *)&v3->sMana;
@@ -1296,7 +1296,7 @@
         if ( v30 == 2 )
         {
           if ( v31 == 1 )
-            pPlayers[v21]->PlaySound(107, 0);
+            pPlayers[v21]->PlaySound(SPEECH_107, 0);
         }
         result = 1;
         break;
@@ -1346,11 +1346,11 @@
         }
         v26 = 0;
         v20 = (v18 != 0) + 23;
-        v23 = 99;
+        v23 = SPEECH_99;
         v3->uFace = v20;
         v3->uVoiceID = v20;
 LABEL_81:
-        v3->PlaySound(v23, v26);
+        v3->PlaySound((PlayerSpeech)v23, v26);
         goto LABEL_82;
       default:
         goto LABEL_82;
@@ -1463,7 +1463,7 @@
   if ( v12 == -1 )
   {
     if ( uActiveCharacter )
-      pPlayers[uActiveCharacter]->PlaySound(15, 0);
+      pPlayers[uActiveCharacter]->PlaySound(SPEECH_15, 0);
     result = 0;
   }
   else
@@ -2333,10 +2333,10 @@
   std::string v12; // [sp-18h] [bp-40h]@9
   const char *v13; // [sp-8h] [bp-30h]@9
   int v14; // [sp-4h] [bp-2Ch]@9
-  int v15; // [sp+Ch] [bp-1Ch]@3
-  int v16; // [sp+10h] [bp-18h]@3
-  int v17; // [sp+14h] [bp-14h]@3
-  int v18; // [sp+18h] [bp-10h]@3
+  int v15[4] = {0, 1, 2, 3}; // [sp+Ch] [bp-1Ch]@3
+  //int v16; // [sp+10h] [bp-18h]@3
+  //int v17; // [sp+14h] [bp-14h]@3
+  //int v18; // [sp+18h] [bp-10h]@3
   Player *v19; // [sp+1Ch] [bp-Ch]@9
   Party *v20; // [sp+20h] [bp-8h]@1
   int v21; // [sp+24h] [bp-4h]@10
@@ -2347,17 +2347,17 @@
   v2 = pItem->uItemID;
   if ( !BYTE2(pItemsTable->pItems[v2 + 1].uItemID) )
     pItem->uAttributes |= 1u;
-  v15 = 0;
-  v16 = 1;
-  v18 = 3;
-  v17 = 2;
+  ///v15 = 0;
+  //v16 = 1;
+  //v18 = 3;
+  //v17 = 2;
   if ( uActiveCharacter )
   {
     v3 = uActiveCharacter - 1;
     v4 = 0;
     do
     {
-      *(&v15 + v4++) = v3++;
+      v15[v4++] = v3++;
       if ( (signed int)v3 >= 4 )
         v3 = 0;
     }
@@ -2367,13 +2367,13 @@
   if ( v5 )
   {
     v6 = pIcons_LOD->LoadTexture(v5, TEXTURE_16BIT_PALETTE);
-    v7 = (Texture *)(v6 != -1 ? (int)&pIcons_LOD->pTextures[v6] : 0);
+    v7 = (Texture *)(v6 != -1 ? &pIcons_LOD->pTextures[v6] : 0);
     v21 = areWeLoadingTexture;
     v8 = 0;
     while ( 1 )
     {
-      v9 = &v20->pPlayers[*(&v15 + v8)];
-      v19 = &v20->pPlayers[*(&v15 + v8)];
+      v9 = &v20->pPlayers[v15[v8]];
+      v19 = &v20->pPlayers[v15[v8]];
       v10 = v19->AddItem(0xFFFFFFFFu, pItem->uItemID);
       if ( v10 )
         break;
@@ -2391,7 +2391,7 @@
     memcpy(&v9->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v10 + 5], pItem, 0x24u);
     pItem->Reset();
     pAudioPlayer->PlaySound(SOUND_GoldReceived, 0, 0, -1, 0, 0, 0, 0);
-    v19->PlaySound(60, 0);
+    v19->PlaySound(SPEECH_60, 0);
     if ( !v21 )
     {
       v7->Release();
@@ -3667,13 +3667,13 @@
   unsigned int v7; // eax@8
   char *v8; // ecx@9
   int v9; // eax@9
-  signed int typea; // [sp+14h] [bp+8h]@1
+  //signed int typea; // [sp+14h] [bp+8h]@1
 
   v3 = this;
   this->pConditions[2] = 0i64;
   v4 = CalculateIncommingDamage(resistance, type);
   v3->sHealth -= v4;
-  typea = v4;
+  //typea = v4;
   v5 = v3->sHealth;
   v6 = v5 < -10;
   LOBYTE(v6) = v5 <= -10;
@@ -3706,9 +3706,9 @@
       }
     }
   }
-  if ( typea && CanAct() )
-    PlaySound(24, 0);
-  return typea;
+  if ( v4 && CanAct() )
+    PlaySound(SPEECH_24, 0);
+  return v4;
 }
 
 //----- (0048DCF6) --------------------------------------------------------
@@ -4019,11 +4019,11 @@
         v26 = v48;
         if ( *(char *)(v48 + 21) & 2 )
           goto LABEL_84;
-        PlaySound(40, 0);
+        PlaySound(SPEECH_40, 0);
         *(int *)(v26 + 20) |= 2u;
         goto LABEL_79;
       case 20:
-        PlaySound(40, 0);
+        PlaySound(SPEECH_40, 0);
         v27 = pActor->array_000234;
         if ( pActor->array_000234[0].uItemID )
         {
@@ -4045,11 +4045,11 @@
         v30 = (SoundID)47;
         goto LABEL_83;
       case 21:
-        PlaySound(42, 0);
+        PlaySound(SPEECH_42, 0);
         ++v5->sAgeModifier;
         goto LABEL_82;
       case 22:
-        PlaySound(41, 0);
+        PlaySound(SPEECH_41, 0);
         v5->sMana = 0;
 LABEL_82:
         v42 = 0;
@@ -6408,7 +6408,7 @@
 }
 
 //----- (00490141) --------------------------------------------------------
-int Player::GetSexByVoice()
+PLAYER_SEX Player::GetSexByVoice()
 {
   signed int result; // eax@1
 
@@ -6427,8 +6427,8 @@
     case 0x11u:
     case 0x14u:
     case 0x17u:
-      result = 0;
-      break;
+      return SEX_MALE;
+
     case 4u:
     case 5u:
     case 6u:
@@ -6441,12 +6441,11 @@
     case 0x13u:
     case 0x15u:
     case 0x18u:
-      result = 1;
-      break;
+      return SEX_FEMALE;
+
     default:
-      return result;
-  }
-  return result;
+      assert(false);
+  }
 }
 
 //----- (00490188) --------------------------------------------------------
@@ -7007,7 +7006,7 @@
         pParty->pPlayers[a2-1].Heal(v69);//((Player *)&stru_AA1058[3].pSounds[6972 * a2 + 40552])->Heal(v69);
       }
 LABEL_112:
-      v3->PlaySound(36, 0);
+      v3->PlaySound(SPEECH_36, 0);
       goto LABEL_173;
     }
 LABEL_172:
@@ -7449,7 +7448,7 @@
               ShowStatusBarString(pTmpBuf, 2u);
               pMouse->RemoveHoldingItem();
               pGame->pStru6Instance->SetPlayerBuffAnim(0x97u, a2 - 1);
-              v3->PlaySound(93, 0);
+              v3->PlaySound(SPEECH_93, 0);
               pAudioPlayer->PlaySound((SoundID)(SOUND_Bell|0x2), 0, 0, -1, 0, 0, 0, 0);
               if ( pParty->uDaysPlayed == 6 || pParty->uDaysPlayed == 20 )
               {
@@ -7552,9 +7551,9 @@
       {
         sub_467F48(pParty->pPickedItem.uItemID);
         v65 = 0;
-        v56 = 37;
+        v56 = SPEECH_37;
 LABEL_67:
-        v3->PlaySound(v56, v65);
+        v3->PlaySound((PlayerSpeech)v56, v65);
         return;
       }
 LABEL_89:
@@ -7624,7 +7623,7 @@
               goto LABEL_67;
             }
             *v72 = 1;
-            v3->PlaySound(21, 0);
+            v3->PlaySound(SPEECH_21, 0);
             v73 = 0;
 LABEL_173:
             v36 = pItemsTable->pItems[pParty->pPickedItem.uItemID].uEquipType;
@@ -8435,7 +8434,7 @@
     {
       v20 = pPlayers[v3 + 1];
       v30 = 1;
-      v20->PlaySound(96, 0);
+      v20->PlaySound(SPEECH_96, 0);
 	  v21 = pAutonoteTxt[a3-1].eType;// dword_72371C[2 * a3];
       bFlashAutonotesBook = 1;
       dword_506568 = v21;
@@ -8506,7 +8505,7 @@
             v12 = pPlayers[v3 + 1];
             v30 = 1;
             v31 = 1;
-            v12->PlaySound(96, 0);
+            v12->PlaySound(SPEECH_96, 0);
           }
           v13 = v4->field_152;
           goto LABEL_51;
@@ -8522,7 +8521,7 @@
             bFlashQuestBook = 1;
             v30 = 1;
             v31 = 1;
-            v14->PlaySound(93, 0);
+            v14->PlaySound(SPEECH_93, 0);
           }
           v13 = (char *)pParty->_award_bits;
 LABEL_51:
@@ -8622,11 +8621,11 @@
     this->uMightBonus = (unsigned __int8)a3;
 LABEL_111:
     v28 = 0;
-    v26 = 91;
+    v26 = SPEECH_91;
 LABEL_112:
     v19 = pPlayers[v3 + 1];
     v31 = 1;
-    v19->PlaySound(v26, v28);
+    v19->PlaySound((PlayerSpeech)v26, v28);
     goto LABEL_169;
   }
   if ( var <= VAR_FireResistanceBonus )
@@ -8935,7 +8934,7 @@
                 v14 = pPlayers[uPlayerIdx + 1];
                 v34 = 1;
                 v3 = 1;
-                v14->PlaySound(96, 0);
+                v14->PlaySound(SPEECH_96, 0);
               }
               v15 = v4->field_152;
               goto LABEL_44;
@@ -8955,7 +8954,7 @@
                 bFlashQuestBook = 1;
                 v34 = 1;
                 v3 = 1;
-                v17->PlaySound(93, 0);
+                v17->PlaySound(SPEECH_93, 0);
               }
               v15 = (char *)pParty->_award_bits;
 LABEL_44:
@@ -9106,10 +9105,10 @@
         if ( *v19 > 255 )
           *v19 = 255;
         v31 = 0;
-        v29 = 91;
+        v29 = SPEECH_91;
 LABEL_116:
         v3 = 1;
-        pPlayers[uPlayerIdx + 1]->PlaySound(v29, v31);
+        pPlayers[uPlayerIdx + 1]->PlaySound((PlayerSpeech)v29, v31);
         goto _play_anim_and_maybe_sound;
       }
       if ( var <= VAR_DisarmTrapSkill )
@@ -9218,7 +9217,7 @@
     {
       v23 = pPlayers[uPlayerIdx + 1];
       v34 = 1;
-      v23->PlaySound(96, 0);
+      v23->PlaySound(SPEECH_96, 0);
 	  v24 = pAutonoteTxt[val-1].eType;//dword_72371C[2 * val];
       bFlashAutonotesBook = 1;
       dword_506568 = v24;
@@ -9566,7 +9565,7 @@
           goto LABEL_17;
         case VAR_QBits_QuestsDone:
           _449B7E_toggle_bit(pParty->_award_bits, (__int16)a3, 0);
-          pPlayers[v4 + 1]->PlaySound(96, 0);
+          pPlayers[v4 + 1]->PlaySound(SPEECH_96, 0);
           return;
         case VAR_PlayerItemInHands:
           v15 = (char *)this->pInventoryIndices;
@@ -9689,9 +9688,9 @@
           this->sResMagicBonus -= (signed __int16)a3;
 LABEL_72:
           v25 = 0;
-          v23 = 91;
+          v23 = SPEECH_91;
 LABEL_73:
-          pPlayers[v4 + 1]->PlaySound(v23, v25);
+          pPlayers[v4 + 1]->PlaySound((PlayerSpeech)v23, v25);
           goto LABEL_17;
         case VAR_FixedFood:
           Party::TakeFood((unsigned int)a3);