view LayingItem.cpp @ 388:d95a91011d57

AudioPlayer::PlaySound
author Nomad
date Sat, 23 Feb 2013 04:01:09 +0200
parents 2799737f8a74
children 58b71c1af7d8
line wrap: on
line source

#include "LayingItem.h"
#include "Party.h"
#include "TurnEngine.h"
#include "MapInfo.h"

#include "mm7_data.h"




size_t uNumLayingItems;
LayingItem pLayingItems[1000];


//----- (00438E35) --------------------------------------------------------
void LayingItem::_438E35()
{
  LayingItem *v1; // edi@1
  MapInfo *pMapInfo; // esi@1
  int v3; // ebx@1
  int v4; // eax@1
  int v5; // ebx@1
  unsigned int v6; // ecx@1
  int v7; // edx@2
  unsigned int v8; // edx@4
  unsigned int v9; // edx@6
  unsigned int v10; // eax@7
  signed int v11; // ebx@8
  Player **v12; // esi@18
  signed int v13; // edi@20
  int v15; // [sp+Ch] [bp-Ch]@1
  int v16; // [sp+10h] [bp-8h]@1
  signed int v17; // [sp+14h] [bp-4h]@8
  int v18; // [sp+14h] [bp-4h]@14

  v1 = this;
  pMapInfo = &pMapStats->pInfos[pMapStats->GetMapInfo(pCurrentMapName)];
  v3 = abs(pParty->vPosition.x - v1->vPosition.x);
  v15 = abs(pParty->vPosition.y - v1->vPosition.y);
  v16 = abs(pParty->vPosition.z + pParty->sEyelevel - v1->vPosition.z);
  v4 = v3;
  v5 = v15;
  v6 = v16;
  if ( v4 < v15 )
  {
    v7 = v4;
    v4 = v15;
    v5 = v7;
  }
  if ( v4 < v16 )
  {
    v8 = v4;
    v4 = v16;
    v6 = v8;
  }
  if ( v5 < (signed int)v6 )
  {
    v9 = v6;
    v6 = v5;
    v5 = v9;
  }
  v10 = ((unsigned int)(11 * v5) >> 5) + (v6 >> 2) + v4;
  if ( (signed int)v10 <= 768 )
  {
    v17 = 0;
    v11 = 5;
    if ( pMapInfo->Trap_D20 )
    {
      do
      {
        ++v17;
        v11 += rand() % 20 + 1;
      }
      while ( v17 < pMapInfo->Trap_D20 );
    }
    switch ( v1->uItemType )
    {
      case 0x32Bu:
        v18 = 0;
        break;
      case 0x32Cu:
        v18 = 1;
        break;
      case 0x32Du:
        v18 = 2;
        break;
      default:
        //LOWORD(v10) = v1->uItemType - 814;
        if ( v1->uItemType != 814 )
          return;
        v18 = 8;
        break;
    }
    v12 = &pPlayers[1];
    do
    {
      if ( (*v12)->CanAct() && (v13 = (*v12)->GetPerception() + 20, rand() % v13 > 20) )
        (*v12)->PlaySound(SPEECH_6, 0);
      else
        (*v12)->ReceiveDamage(v11, v18);
      ++v12;
    }
    while ( (signed int)v12 <= (signed int)&pPlayers[4] );
  }
}



//----- (0042F933) --------------------------------------------------------
void LayingItem::_42F933(unsigned int uLayingItemID)
{
  unsigned int v1; // ecx@1
  unsigned __int16 *pAttributes; // ecx@2
  unsigned __int16 v3; // ax@2

  //__debugbreak(); // find out what's going on

  v1 = uLayingItemID;
  pLayingItems[v1].uObjectDescID = 0;
  if ( pParty->bTurnBasedModeOn == 1 )
  {
    pAttributes = &pLayingItems[v1].uAttributes;
    v3 = *pAttributes;
    if ( *pAttributes & 4 )
    {
      v3 = v3 & 0xFB;
      --pTurnEngine->field_1C;
      *pAttributes = v3;
    }
  }
}