diff SpriteObject.cpp @ 1406:d071e0e9ba75

Explosion Traps fix
author Ritor1
date Tue, 23 Jul 2013 15:41:45 +0600
parents 613c77e51e38
children c9e3b93ec570
line wrap: on
line diff
--- a/SpriteObject.cpp	Mon Jul 22 15:23:43 2013 +0600
+++ b/SpriteObject.cpp	Tue Jul 23 15:41:45 2013 +0600
@@ -53,46 +53,17 @@
 //----- (0042F5ED) --------------------------------------------------------
 int SpriteObject::Create(int yaw, int pitch, int a4, int a5)
 {
-  //SpriteObject *v5; // eax@1
   signed int v6; // ebx@2
-  //char *v7; // ecx@2
-  //signed int result; // eax@6
-  SpriteObject *v9; // ebx@7
-  int v10; // edx@11
-  int v11; // edi@18
-  __int16 v12; // ax@18
   int v13; // ST2C_4@20
-  int v14; // eax@20
-  int v15; // [sp-28h] [bp-38h]@14
-  int v16; // [sp-24h] [bp-34h]@11
   Vec3_int_ v17; // [sp-20h] [bp-30h]@11
-  int *v18; // [sp-14h] [bp-24h]@11
-  int *v19; // [sp-10h] [bp-20h]@11
-  int *v20; // [sp-Ch] [bp-1Ch]@11
-  //signed int v21; // [sp+8h] [bp-8h]@2
   int angle; // [sp+Ch] [bp-4h]@1
-  int a4a; // [sp+1Ch] [bp+Ch]@20
-  int a4b; // [sp+1Ch] [bp+Ch]@20
   int a5a; // [sp+20h] [bp+10h]@20
 
-  //auto a1 = this;
   angle = yaw;
-  //v5 = a1;
   if (!uObjectDescID)
     return -1;
 
   v6 = 1000;
-  //v7 = (char *)&pSpriteObjects[0].uObjectDescID;
-  /*v21 = 0;
-  do
-  {
-    if ( !*(short *)v7 )
-      break;
-    v7 += 112;
-    ++v6;
-    v21 = v6;
-  }
-  while ( (signed int)v7 < (signed int)((char *)&pObjectList->uNumObjects + 2) );*/
   for (uint i = 0; i < MAX_SPRITE_OBJECTS; ++i)
     if (!pSpriteObjects[i].uObjectDescID)
     {
@@ -104,89 +75,130 @@
     return -1;
   field_64.x = vPosition.x;
   field_64.y = vPosition.y;
-  v9 = &pSpriteObjects[v6];
   field_64.z = vPosition.z;
 
   assert(sizeof(SpriteObject) == 0x70);
-  memcpy(v9, this, sizeof(*this));
+  memcpy(&pSpriteObjects[v6], this, sizeof(*this));
+  if ( a5 == 0 )
+  {
+    pSpriteObjects[v6].vVelocity.z = 0;
+    if ( a4 )
+    {
+      v13 = (unsigned __int64)(stru_5C6E00->Cos(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
+      a5a = (unsigned __int64)(stru_5C6E00->Sin(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
+      pSpriteObjects[v6].vVelocity.x = (unsigned int)(v13 * a4) >> 16;
+      pSpriteObjects[v6].vVelocity.y = (unsigned int)(a5a * a4) >> 16;
+      pSpriteObjects[v6].vVelocity.z = (unsigned int)(stru_5C6E00->Sin(pitch) * a4) >> 16;
+    }
+    else
+    {
+      pSpriteObjects[v6].vVelocity.y = 0;
+      pSpriteObjects[v6].vVelocity.x = 0;
+    }
+    if ( v6 >= (signed int)uNumSpriteObjects )
+      uNumSpriteObjects = v6 + 1;
+    return v6;
+  }
   if ( a5 == 1 )
   {
-    v20 = &v9->vPosition.z;
-    v19 = &v9->vPosition.y;
-    v18 = (int *)&v9->vPosition;
     v17.x = vPosition.x;
     v17.y = vPosition.y;
     v17.z = vPosition.z;
-    v16 = 0;
-    v10 = stru_5C6E00->uIntegerHalfPi + v9->uFacing;
-    goto LABEL_16;
+    Vec3_int_::Rotate(24, stru_5C6E00->uIntegerHalfPi + pSpriteObjects[v6].uFacing, 0, v17, &pSpriteObjects[v6].vPosition.x,
+                      &pSpriteObjects[v6].vPosition.y, &pSpriteObjects[v6].vPosition.z);
+    pSpriteObjects[v6].vVelocity.z = 0;
+    if ( a4 )
+    {
+      v13 = (unsigned __int64)(stru_5C6E00->Cos(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
+      a5a = (unsigned __int64)(stru_5C6E00->Sin(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
+      pSpriteObjects[v6].vVelocity.x = (unsigned int)(v13 * a4) >> 16;
+      pSpriteObjects[v6].vVelocity.y = (unsigned int)(a5a * a4) >> 16;
+      pSpriteObjects[v6].vVelocity.z = (unsigned int)(stru_5C6E00->Sin(pitch) * a4) >> 16;
+    }
+    else
+    {
+      pSpriteObjects[v6].vVelocity.y = 0;
+      pSpriteObjects[v6].vVelocity.x = 0;
+    }
+    if ( v6 >= (signed int)uNumSpriteObjects )
+      uNumSpriteObjects = v6 + 1;
+    return v6;
   }
   if ( a5 == 2 )
   {
-    v20 = &v9->vPosition.z;
-    v19 = &v9->vPosition.y;
-    v18 = (int *)&v9->vPosition;
-    v17.x = vPosition.x;
-    v17.y = vPosition.y;
-    v17.z = vPosition.z;
-    v16 = 0;
-    v10 = stru_5C6E00->uIntegerHalfPi + v9->uFacing;
-    goto LABEL_14;
-  }
-  if ( a5 == 3 )
-  {
-    v20 = &v9->vPosition.z;
-    v19 = &v9->vPosition.y;
-    v18 = (int *)&v9->vPosition;
     v17.x = vPosition.x;
     v17.y = vPosition.y;
     v17.z = vPosition.z;
-    v16 = 0;
-    v10 = v9->uFacing - stru_5C6E00->uIntegerHalfPi;
-LABEL_14:
-    v15 = 8;
-LABEL_17:
-    Vec3_int_::Rotate(v15, v10, v16, v17, v18, v19, v20);
-    goto LABEL_18;
+    Vec3_int_::Rotate(8, stru_5C6E00->uIntegerHalfPi + pSpriteObjects[v6].uFacing, 0, v17, &pSpriteObjects[v6].vPosition.x,
+                      &pSpriteObjects[v6].vPosition.y, &pSpriteObjects[v6].vPosition.z);
+    pSpriteObjects[v6].vVelocity.z = 0;
+    if ( a4 )
+    {
+      v13 = (unsigned __int64)(stru_5C6E00->Cos(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
+      a5a = (unsigned __int64)(stru_5C6E00->Sin(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
+      pSpriteObjects[v6].vVelocity.x = (unsigned int)(v13 * a4) >> 16;
+      pSpriteObjects[v6].vVelocity.y = (unsigned int)(a5a * a4) >> 16;
+      pSpriteObjects[v6].vVelocity.z = (unsigned int)(stru_5C6E00->Sin(pitch) * a4) >> 16;
+    }
+    else
+    {
+      pSpriteObjects[v6].vVelocity.y = 0;
+      pSpriteObjects[v6].vVelocity.x = 0;
+    }
+    if ( v6 >= (signed int)uNumSpriteObjects )
+      uNumSpriteObjects = v6 + 1;
+    return v6;
   }
-  if ( a5 == 4 )
+  if ( a5 == 3 )
   {
-    v20 = &v9->vPosition.z;
-    v19 = &v9->vPosition.y;
-    v18 = (int *)&v9->vPosition;
     v17.x = vPosition.x;
     v17.y = vPosition.y;
     v17.z = vPosition.z;
-    v16 = 0;
-    v10 = v9->uFacing - stru_5C6E00->uIntegerHalfPi;
-LABEL_16:
-    v15 = 24;
-    goto LABEL_17;
+    Vec3_int_::Rotate(8, pSpriteObjects[v6].uFacing - stru_5C6E00->uIntegerHalfPi, 0, v17, &pSpriteObjects[v6].vPosition.x,
+                      &pSpriteObjects[v6].vPosition.y, &pSpriteObjects[v6].vPosition.z);
+    pSpriteObjects[v6].vVelocity.z = 0;
+    if ( a4 )
+    {
+      v13 = (unsigned __int64)(stru_5C6E00->Cos(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
+      a5a = (unsigned __int64)(stru_5C6E00->Sin(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
+      pSpriteObjects[v6].vVelocity.x = (unsigned int)(v13 * a4) >> 16;
+      pSpriteObjects[v6].vVelocity.y = (unsigned int)(a5a * a4) >> 16;
+      pSpriteObjects[v6].vVelocity.z = (unsigned int)(stru_5C6E00->Sin(pitch) * a4) >> 16;
+    }
+    else
+    {
+      pSpriteObjects[v6].vVelocity.y = 0;
+      pSpriteObjects[v6].vVelocity.x = 0;
+    }
+    if ( v6 >= (signed int)uNumSpriteObjects )
+      uNumSpriteObjects = v6 + 1;
+    return v6;
   }
-LABEL_18:
-  v11 = a4;
-  v12 = 0;
-  if ( a4 )
+  if ( a5 == 4 )
   {
-    a4a = stru_5C6E00->Cos(angle);
-    v13 = (unsigned __int64)(a4a * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
-    a4b = stru_5C6E00->Sin(angle);
-    a5a = (unsigned __int64)(a4b * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
-    v14 = stru_5C6E00->Sin(pitch);
-    v9->vVelocity.x = (unsigned int)(v13 * v11) >> 16;
-    v9->vVelocity.y = (unsigned int)(a5a * v11) >> 16;
-    v12 = (unsigned int)(v14 * v11) >> 16;
+    v17.x = vPosition.x;
+    v17.y = vPosition.y;
+    v17.z = vPosition.z;
+    Vec3_int_::Rotate(24, pSpriteObjects[v6].uFacing - stru_5C6E00->uIntegerHalfPi, 0, v17, &pSpriteObjects[v6].vPosition.x,
+                      &pSpriteObjects[v6].vPosition.y, &pSpriteObjects[v6].vPosition.z);
+    pSpriteObjects[v6].vVelocity.z = 0;
+    if ( a4 )
+    {
+      v13 = (unsigned __int64)(stru_5C6E00->Cos(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
+      a5a = (unsigned __int64)(stru_5C6E00->Sin(angle) * (signed __int64)stru_5C6E00->Cos(pitch)) >> 16;
+      pSpriteObjects[v6].vVelocity.x = (unsigned int)(v13 * a4) >> 16;
+      pSpriteObjects[v6].vVelocity.y = (unsigned int)(a5a * a4) >> 16;
+      pSpriteObjects[v6].vVelocity.z = (unsigned int)(stru_5C6E00->Sin(pitch) * a4) >> 16;
+    }
+    else
+    {
+      pSpriteObjects[v6].vVelocity.y = 0;
+      pSpriteObjects[v6].vVelocity.x = 0;
+    }
+    if ( v6 >= (signed int)uNumSpriteObjects )
+      uNumSpriteObjects = v6 + 1;
+    return v6;
   }
-  else
-  {
-    v9->vVelocity.y = 0;
-    v9->vVelocity.x = 0;
-  }
-  v9->vVelocity.z = v12;
-
-  if ( v6 >= (signed int)uNumSpriteObjects )
-    uNumSpriteObjects = v6 + 1;
-  return v6;
 }
 
 //----- (00471C03) --------------------------------------------------------
@@ -970,94 +982,73 @@
 // 46DF1A: using guessed type int __fastcall 46DF1A_collide_against_actor(int, int);
 
 //----- (00438E35) --------------------------------------------------------
-void SpriteObject::_438E35()
+void SpriteObject::ExplosionTraps()
 {
-  SpriteObject *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 dir_x; // ebx@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
+  int dir_y; // [sp+Ch] [bp-Ch]@1
+  int dir_z; // [sp+10h] [bp-8h]@1
+  DAMAGE_TYPE pDamageType; // [sp+14h] [bp-4h]@14
 
-  v1 = this;
   pMapInfo = &pMapStats->pInfos[pMapStats->GetMapInfo(pCurrentMapName.data())];
-  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 )
+  dir_x = abs(pParty->vPosition.x - this->vPosition.x);
+  dir_y = abs(pParty->vPosition.y - this->vPosition.y);
+  dir_z = abs(pParty->vPosition.z + pParty->sEyelevel - this->vPosition.z);
+  if ( dir_x < dir_y )
   {
-    v7 = v4;
-    v4 = v15;
-    v5 = v7;
+    v7 = dir_x;
+    dir_x = dir_y;
+    dir_y = v7;
   }
-  if ( v4 < v16 )
+  if ( dir_x < dir_z )
   {
-    v8 = v4;
-    v4 = v16;
-    v6 = v8;
+    v7 = dir_x;
+    dir_x = dir_z;
+    dir_z = v7;
   }
-  if ( v5 < (signed int)v6 )
+  if ( dir_y < dir_z )
   {
-    v9 = v6;
-    v6 = v5;
-    v5 = v9;
+    v7 = dir_z;
+    dir_z = dir_y;
+    dir_y = v7;
   }
-  v10 = ((unsigned int)(11 * v5) >> 5) + (v6 >> 2) + v4;
+  v10 = ((unsigned int)(11 * dir_y) >> 5) + (dir_z / 4) + dir_x;
   if ( (signed int)v10 <= 768 )
   {
-    v17 = 0;
     v11 = 5;
     if ( pMapInfo->Trap_D20 )
     {
-      do
-      {
-        ++v17;
+      for ( uint i = 0; i < pMapInfo->Trap_D20; ++i )
         v11 += rand() % 20 + 1;
-      }
-      while ( v17 < pMapInfo->Trap_D20 );
     }
-    switch ( v1->uType )
+    switch ( this->uType )
     {
-      case 0x32Bu:
-        v18 = 0;
+      case 811:
+        pDamageType = DMGT_FIRE;
+        break;
+      case 812:
+        pDamageType = DMGT_ELECTR;
         break;
-      case 0x32Cu:
-        v18 = 1;
+      case 813:
+        pDamageType = DMGT_COLD;
         break;
-      case 0x32Du:
-        v18 = 2;
+      case 814:
+        pDamageType = DMGT_BODY;
         break;
       default:
-        //LOWORD(v10) = v1->uItemType - 814;
-        if ( v1->uType != 814 )
-          return;
-        v18 = 8;
-        break;
+        return;
     }
-    v12 = &pPlayers[1];
-    do
+    for ( uint i = 1; i <= 4; ++i )
     {
-      if ( (*v12)->CanAct() && (v13 = (*v12)->GetPerception() + 20, rand() % v13 > 20) )
-        (*v12)->PlaySound(SPEECH_6, 0);
+      if ( pPlayers[i]->CanAct() && (v13 = pPlayers[i]->GetPerception() + 20, rand() % v13 > 20) )
+        pPlayers[i]->PlaySound(SPEECH_6, 0);
       else
-        (*v12)->ReceiveDamage(v11, (DAMAGE_TYPE)v18);
-      ++v12;
+        pPlayers[i]->ReceiveDamage(v11, pDamageType);
     }
-    while ( (signed int)v12 <= (signed int)&pPlayers[4] );
   }
 }