view mm7_6.cpp @ 110:430786d916d6

6.11.12 SaveLoad
author Ritor1
date Tue, 06 Nov 2012 17:30:24 +0600
parents 8be5293b6b33
children 87c503d426e0
line wrap: on
line source

#include "MM7.h"

#include "MapInfo.h"
#include "Game.h"
#include "GUIWindow.h"
#include "GUIFont.h"
#include "GUIButton.h"
#include "GUIProgressBar.h"
#include "Party.h"
#include "AudioPlayer.h"
#include "Outdoor.h"
#include "IndoorCamera.h"
#include "Overlays.h"
#include "Monsters.h"
#include "Arcomage.h"
#include "LOD.h"
#include "Actor.h"
#include "Allocator.h"
#include "Events.h"
#include "Viewport.h"
#include "FrameTableInc.h"
#include "Math.h"
#include "LayingItem.h"
#include "ObjectList.h"
#include "Chest.h"
#include "PaletteManager.h"
#include "DecorationList.h"
#include "SaveLoad.h"
#include "stru123.h"
#include "Time.h"
#include "IconFrameTable.h"
#include "stru179.h"
#include "Awards.h"
#include "Autonotes.h"
#include "stru160.h"
#include "stru279.h"
#include "TurnEngine.h"
#include "stru277.h"
#include "Weather.h"
#include "stru272.h"
#include "stru298.h"
#include "StorylineTextTable.h"
#include "Events2D.h"

#include "mm7_data.h"



//----- (00424EE0) --------------------------------------------------------
signed int __fastcall sr_424EE0_MakeFanFromTriangle(unsigned int uVertexID)
{
  unsigned int v1; // edx@1
  double v2; // st7@1
  signed int v3; // edi@1
  char *v4; // esi@4
  char *v5; // ecx@4
  unsigned int v6; // eax@4
  char *v7; // edx@4
  double v8; // st6@10
  double v9; // st5@10
  double v10; // st6@11
  unsigned __int8 v11; // c2@15
  unsigned __int8 v12; // c3@15
  void *v13; // edi@22
  char *v14; // eax@22
  double v15; // st6@22
  char *v16; // ecx@22
  signed int result; // eax@24
  unsigned int v18; // [sp+8h] [bp-2Ch]@4
  bool v19; // [sp+Ch] [bp-28h]@6
  char *v20; // [sp+10h] [bp-24h]@4
  char *v21; // [sp+14h] [bp-20h]@4
  signed int v22; // [sp+18h] [bp-1Ch]@1
  char *v23; // [sp+1Ch] [bp-18h]@4
  RenderVertexSoft *v24; // [sp+20h] [bp-14h]@4
  char *v25; // [sp+24h] [bp-10h]@4
  char *v26; // [sp+28h] [bp-Ch]@4
  char *v27; // [sp+2Ch] [bp-8h]@4
  char *v28; // [sp+30h] [bp-4h]@4

  v1 = uVertexID;
  v2 = (double)pOutdoorCamera->shading_dist_mist;
  memcpy(&array_50AC10[uVertexID], array_50AC10, sizeof(array_50AC10[uVertexID]));
  v3 = 0;
  v22 = 0;
  if ( array_50AC10[0].vWorldViewPosition.x <= v2 )
    v3 = 1;
  if ( (signed int)(uVertexID + 1) <= 1 )
    return 0;
  v4 = (char *)&array_507D30[0].vWorldViewPosition.z;
  v5 = (char *)&array_507D30[0].vWorldViewPosition.y;
  v6 = v1;
  v23 = (char *)&array_507D30[0].flt_2C;
  v26 = (char *)&array_507D30[0].flt_20;
  v24 = array_507D30;
  v20 = (char *)&array_507D30[0].vWorldViewPosition.z;
  v21 = (char *)&array_507D30[0].vWorldViewPosition.y;
  v25 = (char *)&array_507D30[0].vWorldViewPosition;
  v27 = (char *)&array_507D30[0].v;
  v28 = (char *)&array_507D30[0].u;
  v7 = (char *)&array_50AC10[0].v;
  v18 = v6;
  do
  {
    v19 = v2 >= *((float *)v7 + 5);
    if ( v3 != v19 )
    {
      if ( v19 )
      {
        v8 = (v2 - *((float *)v7 - 7)) / (*((float *)v7 + 5) - *((float *)v7 - 7));
        *(float *)v5 = (*((float *)v7 + 6) - *((float *)v7 - 6)) * v8 + *((float *)v7 - 6);
        *(float *)v4 = (*((float *)v7 + 7) - *((float *)v7 - 5)) * v8 + *((float *)v7 - 5);
        *(float *)v28 = (*((float *)v7 + 11) - *((float *)v7 - 1)) * v8 + *((float *)v7 - 1);
        v9 = (*((float *)v7 + 12) - *(float *)v7) * v8 + *(float *)v7;
      }
      else
      {
        v10 = (v2 - *((float *)v7 + 5)) / (*((float *)v7 - 7) - *((float *)v7 + 5));
        *(float *)v5 = (*((float *)v7 - 6) - *((float *)v7 + 6)) * v10 + *((float *)v7 + 6);
        *(float *)v4 = (*((float *)v7 - 5) - *((float *)v7 + 7)) * v10 + *((float *)v7 + 7);
        *(float *)v28 = (*((float *)v7 - 1) - *((float *)v7 + 11)) * v10 + *((float *)v7 + 11);
        v9 = (*(float *)v7 - *((float *)v7 + 12)) * v10 + *((float *)v7 + 12);
      }
      *(float *)v27 = v9;
      *(float *)v25 = v2;
      *(float *)v26 = 1.0 / v2;
      if ( v3 )
      {
        if ( v2 == *((float *)v7 - 7) && *(float *)v5 == *((float *)v7 - 6) )
        {
          v11 = 0;
          v12 = *(float *)v4 == *((float *)v7 - 5);
          goto LABEL_19;
        }
      }
      else
      {
        if ( v2 == *((float *)v7 + 5) && *(float *)v5 == *((float *)v7 + 6) )
        {
          v11 = 0;
          v12 = *(float *)v4 == *((float *)v7 + 7);
LABEL_19:
          if ( v12 | v11 )
            goto LABEL_21;
          goto LABEL_20;
        }
      }
LABEL_20:
      v26 += 48;
      ++v24;
      v25 += 48;
      v27 += 48;
      v28 += 48;
      v5 += 48;
      v4 += 48;
      ++v22;
      v23 += 48;
      v21 = v5;
      v20 = v4;
    }
LABEL_21:
    if ( v19 )
    {
      v13 = v24;
      v14 = v26;
      v21 += 48;
      v15 = 1.0 / (*((float *)v7 + 5) + 0.0000001);
      v20 += 48;
      ++v22;
      v28 += 48;
      v27 += 48;
      v25 += 48;
      ++v24;
      v26 += 48;
      memcpy(v13, v7 + 8, 0x30u);
      v16 = v23;
      v23 += 48;
      v4 = v20;
      *(float *)v14 = v15;
      *(int *)v16 = *((int *)v7 + 13);
      v5 = v21;
    }
    v3 = v19;
    v7 += 48;
    --v18;
  }
  while ( v18 );
  result = v22;
  if ( v22 < 3 )
    return 0;
  return result;
}

//----- (004250FE) --------------------------------------------------------
signed int __fastcall sr_4250FE(unsigned int uVertexID)
{
  unsigned int v1; // edx@1
  char *v2; // edi@5
  char *v3; // esi@5
  char *v4; // ecx@5
  int v5; // ebx@6
  double v6; // st6@11
  double v7; // st5@11
  double v8; // st6@12
  unsigned __int8 v9; // c2@16
  unsigned __int8 v10; // c3@16
  void *v11; // edi@23
  double v12; // st6@23
  char *v13; // ecx@23
  char v14; // zf@24
  signed int result; // eax@25
  unsigned int v16; // [sp+8h] [bp-28h]@5
  bool v17; // [sp+Ch] [bp-24h]@2
  bool v18; // [sp+10h] [bp-20h]@7
  char *v19; // [sp+14h] [bp-1Ch]@5
  char *v20; // [sp+18h] [bp-18h]@5
  signed int v21; // [sp+1Ch] [bp-14h]@1
  RenderVertexSoft *v22; // [sp+20h] [bp-10h]@5
  char *v23; // [sp+24h] [bp-Ch]@5
  char *v24; // [sp+28h] [bp-8h]@5
  char *v25; // [sp+2Ch] [bp-4h]@5

  v1 = uVertexID;
  memcpy(&array_50AC10[uVertexID], array_50AC10, sizeof(array_50AC10[uVertexID]));
  v21 = 0;
  v17 = array_50AC10[0].vWorldViewPosition.x >= 8.0;
  if ( (signed int)(uVertexID + 1) <= 1 )
    return 0;
  v2 = (char *)&array_507D30[0].vWorldViewPosition.z;
  v3 = (char *)&array_507D30[0].vWorldViewPosition.y;
  v24 = (char *)&array_507D30[0].flt_20;
  v22 = array_507D30;
  v19 = (char *)&array_507D30[0].vWorldViewPosition.z;
  v20 = (char *)&array_507D30[0].vWorldViewPosition.y;
  v23 = (char *)&array_507D30[0].vWorldViewPosition;
  v25 = (char *)&array_507D30[0].flt_2C;
  v4 = (char *)&array_50AC10[0].vWorldViewPosition;
  v16 = v1;
  do
  {
    v5 = (int)(v4 + 48);
    v18 = *((float *)v4 + 12) >= 8.0;
    if ( v17 != v18 )
    {
      if ( v18 )
      {
        v6 = (8.0 - *(float *)v4) / (*(float *)v5 - *(float *)v4);
        *(float *)v3 = (*((float *)v4 + 13) - *((float *)v4 + 1)) * v6 + *((float *)v4 + 1);
        *(float *)v2 = (*((float *)v4 + 14) - *((float *)v4 + 2)) * v6 + *((float *)v4 + 2);
        v7 = (*((float *)v4 + 20) - *((float *)v4 + 8)) * v6 + *((float *)v4 + 8);
      }
      else
      {
        v8 = (8.0 - *(float *)v5) / (*(float *)v4 - *(float *)v5);
        *(float *)v3 = (*((float *)v4 + 1) - *((float *)v4 + 13)) * v8 + *((float *)v4 + 13);
        *(float *)v2 = (*((float *)v4 + 2) - *((float *)v4 + 14)) * v8 + *((float *)v4 + 14);
        v7 = (*((float *)v4 + 8) - *((float *)v4 + 20)) * v8 + *((float *)v4 + 20);
      }
      *(float *)v25 = v7;
      *(float *)v23 = 8.0;
      *(int *)v24 = 0x3E000000u;
      if ( v17 )
      {
        if ( 8.0 == *(float *)v4 && *(float *)v3 == *((float *)v4 + 1) )
        {
          v9 = 0;
          v10 = *(float *)v2 == *((float *)v4 + 2);
          goto LABEL_20;
        }
      }
      else
      {
        if ( 8.0 == *(float *)v5 && *(float *)v3 == *((float *)v4 + 13) )
        {
          v9 = 0;
          v10 = *(float *)v2 == *((float *)v4 + 14);
LABEL_20:
          if ( v10 | v9 )
            goto LABEL_22;
          goto LABEL_21;
        }
      }
LABEL_21:
      ++v22;
      v23 += 48;
      v25 += 48;
      v3 += 48;
      v2 += 48;
      ++v21;
      v24 += 48;
      v20 = v3;
      v19 = v2;
    }
LABEL_22:
    if ( v18 )
    {
      v11 = v22;
      v20 += 48;
      v19 += 48;
      v12 = 1.0 / (*(float *)v5 + 0.0000001);
      ++v21;
      v25 += 48;
      v23 += 48;
      ++v22;
      memcpy(v11, v4 + 36, 0x30u);
      v13 = v24;
      v24 += 48;
      v3 = v20;
      v2 = v19;
      *(float *)v13 = v12;
    }
    v14 = v16-- == 1;
    v17 = v18;
    v4 = (char *)v5;
  }
  while ( !v14 );
  result = v21;
  if ( v21 < 3 )
    return 0;
  return result;
}

//----- (004252E8) --------------------------------------------------------
signed int __fastcall sr_4252E8(unsigned int uVertexID)
{
  unsigned int v1; // edx@1
  double v2; // st7@1
  char *v3; // edi@5
  char *v4; // esi@5
  char *v5; // ecx@5
  int v6; // ebx@6
  double v7; // st6@11
  double v8; // st5@11
  double v9; // st6@12
  unsigned __int8 v10; // c2@16
  unsigned __int8 v11; // c3@16
  void *v12; // edi@23
  double v13; // st6@23
  char *v14; // ecx@23
  char v15; // zf@24
  signed int result; // eax@25
  unsigned int v17; // [sp+8h] [bp-28h]@5
  bool v18; // [sp+Ch] [bp-24h]@2
  bool v19; // [sp+10h] [bp-20h]@7
  char *v20; // [sp+14h] [bp-1Ch]@5
  char *v21; // [sp+18h] [bp-18h]@5
  signed int v22; // [sp+1Ch] [bp-14h]@1
  RenderVertexSoft *v23; // [sp+20h] [bp-10h]@5
  char *v24; // [sp+24h] [bp-Ch]@5
  char *v25; // [sp+28h] [bp-8h]@5
  char *v26; // [sp+2Ch] [bp-4h]@5

  v1 = uVertexID;
  v2 = (double)pOutdoorCamera->shading_dist_mist;
  memcpy(&array_50AC10[uVertexID], array_50AC10, sizeof(array_50AC10[uVertexID]));
  v22 = 0;
  v18 = array_50AC10[0].vWorldViewPosition.x <= v2;
  if ( (signed int)(uVertexID + 1) <= 1 )
    return 0;
  v3 = (char *)&array_507D30[0].vWorldViewPosition.z;
  v4 = (char *)&array_507D30[0].vWorldViewPosition.y;
  v25 = (char *)&array_507D30[0].flt_20;
  v23 = array_507D30;
  v20 = (char *)&array_507D30[0].vWorldViewPosition.z;
  v21 = (char *)&array_507D30[0].vWorldViewPosition.y;
  v24 = (char *)&array_507D30[0].vWorldViewPosition;
  v26 = (char *)&array_507D30[0].flt_2C;
  v5 = (char *)&array_50AC10[0].vWorldViewPosition;
  v17 = v1;
  do
  {
    v6 = (int)(v5 + 48);
    v19 = v2 >= *((float *)v5 + 12);
    if ( v18 != v19 )
    {
      if ( v19 )
      {
        v7 = (v2 - *(float *)v5) / (*(float *)v6 - *(float *)v5);
        *(float *)v4 = (*((float *)v5 + 13) - *((float *)v5 + 1)) * v7 + *((float *)v5 + 1);
        *(float *)v3 = (*((float *)v5 + 14) - *((float *)v5 + 2)) * v7 + *((float *)v5 + 2);
        v8 = (*((float *)v5 + 20) - *((float *)v5 + 8)) * v7 + *((float *)v5 + 8);
      }
      else
      {
        v9 = (v2 - *(float *)v6) / (*(float *)v5 - *(float *)v6);
        *(float *)v4 = (*((float *)v5 + 1) - *((float *)v5 + 13)) * v9 + *((float *)v5 + 13);
        *(float *)v3 = (*((float *)v5 + 2) - *((float *)v5 + 14)) * v9 + *((float *)v5 + 14);
        v8 = (*((float *)v5 + 8) - *((float *)v5 + 20)) * v9 + *((float *)v5 + 20);
      }
      *(float *)v26 = v8;
      *(float *)v24 = v2;
      *(float *)v25 = 1.0 / v2;
      if ( v18 )
      {
        if ( v2 == *(float *)v5 && *(float *)v4 == *((float *)v5 + 1) )
        {
          v10 = 0;
          v11 = *(float *)v3 == *((float *)v5 + 2);
          goto LABEL_20;
        }
      }
      else
      {
        if ( v2 == *(float *)v6 && *(float *)v4 == *((float *)v5 + 13) )
        {
          v10 = 0;
          v11 = *(float *)v3 == *((float *)v5 + 14);
LABEL_20:
          if ( v11 | v10 )
            goto LABEL_22;
          goto LABEL_21;
        }
      }
LABEL_21:
      ++v23;
      v24 += 48;
      v26 += 48;
      v4 += 48;
      v3 += 48;
      ++v22;
      v25 += 48;
      v21 = v4;
      v20 = v3;
    }
LABEL_22:
    if ( v19 )
    {
      v12 = v23;
      v21 += 48;
      v20 += 48;
      v13 = 1.0 / (*(float *)v6 + 0.0000001);
      ++v22;
      v26 += 48;
      v24 += 48;
      ++v23;
      memcpy(v12, v5 + 36, 0x30u);
      v14 = v25;
      v25 += 48;
      v4 = v21;
      v3 = v20;
      *(float *)v14 = v13;
    }
    v15 = v17-- == 1;
    v18 = v19;
    v5 = (char *)v6;
  }
  while ( !v15 );
  result = v22;
  if ( v22 < 3 )
    return 0;
  return result;
}



//----- (004361EF) --------------------------------------------------------
IndoorCameraD3D::IndoorCameraD3D()
{
  IndoorCameraD3D *v1; // esi@1
  double v2; // st7@1
  double v3; // st6@1
  double v4; // st5@1
  double v5; // st7@1
  double v6; // st6@1
  double v7; // st5@1

  v1 = this;
  //IndoorCameraD3D_Vec3::IndoorCameraD3D_Vec3(&this->field_4);
  //IndoorCameraD3D_Vec3::IndoorCameraD3D_Vec3(&v1->field_14);
  //IndoorCameraD3D_Vec3::IndoorCameraD3D_Vec3(&v1->field_24);
  /*_eh_vector_constructor_iterator_(v1->std__vector_000034_prolly_frustrum,
    24,
    6,
    (void (__thiscall *)(void *))IndoorCameraD3D_Vec4::IndoorCameraD3D_Vec4,
    (void (__thiscall *)(void *))IndoorCameraD3D_Vec4::dtor);*/
  v2 = 0;//(double)pBLVRenderParams->vPartyPos.z;
  v3 = 0;//(double)pBLVRenderParams->vPartyPos.y;
  v4 = 0;//(double)pBLVRenderParams->vPartyPos.x;
  v1->field_108 = 0.0;
  v1->field_DC = v4;
  v1->field_E0 = v3;
  v1->field_E4 = v2;
  v5 = 0;//(double)pBLVRenderParams->vPartyPos.z;
  v6 = 0;//(double)pBLVRenderParams->vPartyPos.y;
  v7 = 300;//(double)(pBLVRenderParams->vPartyPos.x + 300);
  v1->field_138 = 0.0;
  v1->field_10C = v7;
  v1->field_110 = v6;
  v1->field_114 = v5;
  v1->field_168 = 0.0;
  v1->field_198 = 0.0;
  v1->field_1C8 = 0.0;
  v1->field_1F8 = 0.0;
  v1->field_228 = 0.0;
  v1->field_258 = 0.0;
  v1->field_288 = 0.0;
  v1->field_2B8 = 0.0;
  v1->field_2E8 = 0.0;
  v1->field_2BC = 0.0;
  v1->field_2C0 = 0.0;
  v1->field_2C4 = 0.0;
  v1->field_318 = 0.0;
  v1->field_2EC = 0.0;
  v1->field_2F0 = 0.0;
  v1->field_2F4 = 0.0;
  v1->field_348 = 0.0;
  v1->field_31C = 0.0;
  v1->field_320 = 0.0;
  v1->field_324 = 0.0;
  v1->field_378 = 0.0;
  v1->field_34C = 0.0;
  v1->field_350 = 0.0;
  v1->field_354 = 0.0;
  for (uint i = 0; i < 16384; ++i)
  {
    list_0037C[i].field_0 = 0;
    list_0037C[i].flt_30 = 0.0f;
  }

  list_0037C_size = 0;
  for (uint i = 0; i < 256; ++i)
    list_E0380[i].mm7__vector_000004_size = 0;
  /*v10 = v1->list_E0380;
  v12 = 256;
  do
  {
    v10->mm7__vector_000004_size = 0;
    //mm7__vector_constructor(
    //  v10->mm7__vector_000004,
    //  48,
    //  64,
    //  (int (__thiscall *)(int))IndoorCameraD3D_stru1::IndoorCameraD3D_stru1);
    //++v10;
    --v12;
  }
  while ( v12 );*/
  list_E0380_size = 0;
  //v1->vdestructor_ptr = &stru8_pvdtor;
}


//----- (004254D2) --------------------------------------------------------
int __fastcall sr_4254D2(signed int a1)
{
  signed int v1; // ebx@2
  int v2; // ecx@2
  int result; // eax@11
  double v4; // ST74_8@12
  bool v5; // edi@12
  char *v6; // esi@13
  char *v7; // ebx@13
  double v8; // st7@15
  double v9; // st7@16
  double v10; // st6@16
  double v11; // st7@17
  float v12; // eax@18
  double v13; // ST4C_8@19
  double v14; // ST10_8@19
  double v15; // ST28_8@20
  double v16; // ST34_8@20
  char v17; // zf@20
  double v18; // ST18_8@21
  double v19; // ST3C_8@21
  double v20; // ST44_8@22
  double v21; // ST54_8@22
  void *v22; // edi@26
  double v23; // ST54_8@29
  bool v24; // esi@29
  char *v25; // edi@30
  char *v26; // ebx@30
  bool v27; // ecx@32
  double v28; // st7@33
  double v29; // st7@34
  double v30; // st6@34
  double v31; // st7@35
  double v32; // ST44_8@37
  double v33; // ST3C_8@37
  double v34; // ST18_8@38
  double v35; // ST34_8@38
  char v36; // zf@38
  double v37; // ST28_8@39
  double v38; // ST10_8@39
  double v39; // ST20_8@40
  double v40; // ST5C_8@40
  void *v41; // edi@44
  double v42; // ST5C_8@47
  bool v43; // edi@47
  char *v44; // esi@48
  char *v45; // ebx@48
  bool v46; // ecx@49
  double v47; // st6@50
  double v48; // st6@51
  double v49; // st5@51
  double v50; // st6@52
  double v51; // ST20_8@54
  double v52; // ST54_8@54
  double v53; // ST44_8@55
  double v54; // ST3C_8@55
  char v55; // zf@55
  double v56; // ST18_8@56
  double v57; // ST34_8@56
  double v58; // ST28_8@57
  double v59; // ST10_8@57
  void *v60; // edi@61
  double v61; // ST5C_8@64
  bool v62; // edi@64
  char *v63; // esi@65
  char *v64; // ebx@65
  bool v65; // ecx@66
  double v66; // st6@67
  double v67; // st6@68
  double v68; // st5@68
  double v69; // st6@69
  double v70; // ST20_8@71
  double v71; // ST54_8@71
  double v72; // ST44_8@72
  double v73; // ST3C_8@72
  char v74; // zf@72
  double v75; // ST18_8@73
  double v76; // ST34_8@73
  double v77; // ST28_8@74
  double v78; // ST10_8@74
  void *v79; // edi@78
  int v80; // ebx@81
  char *v81; // ecx@82
  signed int v82; // esi@82
  float v83; // ST78_4@83
  double v84; // ST5C_8@83
  float v85; // eax@84
  double v86; // ST20_8@85
  double v87; // ST54_8@88
  float v88; // eax@89
  double v89; // ST44_8@90
  unsigned __int8 v90; // sf@94
  unsigned __int8 v91; // of@94
  int v92; // edx@97
  int v93; // esi@97
  int v94; // edi@97
  int v95; // eax@97
  int v96; // eax@104
  double v97; // [sp+4Ch] [bp-8Ch]@32
  double v98; // [sp+54h] [bp-84h]@49
  double v99; // [sp+54h] [bp-84h]@66
  float v100; // [sp+5Ch] [bp-7Ch]@1
  float v101; // [sp+60h] [bp-78h]@1
  float v102; // [sp+64h] [bp-74h]@1
  double v103; // [sp+6Ch] [bp-6Ch]@14
  float v104; // [sp+A8h] [bp-30h]@1
  signed int v105; // [sp+A8h] [bp-30h]@96
  bool v106; // [sp+ACh] [bp-2Ch]@14
  bool v107; // [sp+ACh] [bp-2Ch]@32
  bool v108; // [sp+ACh] [bp-2Ch]@49
  bool v109; // [sp+ACh] [bp-2Ch]@66
  signed int v110; // [sp+B0h] [bp-28h]@12
  char *v111; // [sp+B8h] [bp-20h]@30
  signed int v112; // [sp+B8h] [bp-20h]@48
  signed int v113; // [sp+B8h] [bp-20h]@65
  char *v114; // [sp+BCh] [bp-1Ch]@13
  signed int v115; // [sp+BCh] [bp-1Ch]@29
  signed int v116; // [sp+BCh] [bp-1Ch]@64
  signed int v117; // [sp+C0h] [bp-18h]@1
  char *v118; // [sp+C0h] [bp-18h]@30
  char *v119; // [sp+C0h] [bp-18h]@48
  char *v120; // [sp+C0h] [bp-18h]@65
  char *v121; // [sp+C4h] [bp-14h]@13
  char *v122; // [sp+C4h] [bp-14h]@30
  signed int v123; // [sp+C4h] [bp-14h]@47
  char *v124; // [sp+C8h] [bp-10h]@30
  char *v125; // [sp+C8h] [bp-10h]@48
  char *v126; // [sp+C8h] [bp-10h]@65
  signed int v127; // [sp+CCh] [bp-Ch]@2
  char *v128; // [sp+CCh] [bp-Ch]@13
  char *v129; // [sp+CCh] [bp-Ch]@30
  RenderVertexSoft *v130; // [sp+CCh] [bp-Ch]@48
  RenderVertexSoft *v131; // [sp+CCh] [bp-Ch]@65
  RenderVertexSoft *v132; // [sp+D0h] [bp-8h]@13
  char *v133; // [sp+D0h] [bp-8h]@30
  char *v134; // [sp+D0h] [bp-8h]@48
  char *v135; // [sp+D0h] [bp-8h]@65
  signed int v136; // [sp+D4h] [bp-4h]@1
  char *v137; // [sp+D4h] [bp-4h]@13
  RenderVertexSoft *v138; // [sp+D4h] [bp-4h]@30
  char *v139; // [sp+D4h] [bp-4h]@48
  char *v140; // [sp+D4h] [bp-4h]@65

  v101 = (double)(signed int)pViewport->uViewportX;
  v100 = (double)(signed int)pViewport->uViewportZ;
  v117 = a1;
  v136 = 1;
  v104 = (double)(signed int)pViewport->uViewportY;
  v102 = (double)(pViewport->uViewportW + 1);
  if ( a1 <= 0 )
    return v117;
  v127 = a1;
  v1 = a1;
  memcpy(array_508690, array_50AC10, 4 * ((unsigned int)(48 * a1) >> 2));
  v2 = 0;
  do
  {
    if ( array_50AC10[v2].vWorldViewProjX < (double)v101 || array_50AC10[v2].vWorldViewProjX > (double)v100 )
      v136 = 0;
    if ( *(float *)(v2 * 48 + 5286956) < (double)v104 || *(float *)(v2 * 48 + 5286956) > (double)v102 )
      v136 = 0;
    ++v2;
    --v127;
  }
  while ( v127 );
  if ( v136 )
    return v117;
  v110 = 0;
  memcpy(&array_50AC10[v1], array_50AC10, sizeof(array_50AC10[v1]));
  v4 = array_50AC10[0].vWorldViewProjX + 6.7553994e15;
  v5 = SLODWORD(v4) >= (signed int)pViewport->uViewportX;
  if ( v117 < 1 )
    goto LABEL_112;
  v6 = (char *)&array_50A2B0[0].vWorldViewProjY;
  v132 = array_50A2B0;
  v137 = (char *)&array_50A2B0[0].vWorldViewProjX;
  v128 = (char *)&array_50A2B0[0].vWorldViewProjY;
  v121 = (char *)&array_50A2B0[0].flt_2C;
  v114 = (char *)&array_50A2B0[0].flt_20;
  v7 = (char *)&array_50AC10[0].flt_2C;
  do
  {
    v103 = *((float *)v7 + 7) + 6.7553994e15;
    v106 = SLODWORD(v103) >= (signed int)pViewport->uViewportX;
    if ( !(v5 ^ v106) )
      goto LABEL_25;
    v8 = v101;
    if ( SLODWORD(v103) >= (signed int)pViewport->uViewportX )
    {
      v9 = (v8 - *((float *)v7 - 5)) / (*((float *)v7 + 7) - *((float *)v7 - 5));
      *(float *)v6 = (*((float *)v7 + 8) - *((float *)v7 - 4)) * v9 + *((float *)v7 - 4);
      *(float *)v114 = (*((float *)v7 + 9) - *((float *)v7 - 3)) * v9 + *((float *)v7 - 3);
      v10 = (*((float *)v7 + 12) - *(float *)v7) * v9 + *(float *)v7;
    }
    else
    {
      v11 = (v8 - *((float *)v7 + 7)) / (*((float *)v7 - 5) - *((float *)v7 + 7));
      *(float *)v6 = (*((float *)v7 - 4) - *((float *)v7 + 8)) * v11 + *((float *)v7 + 8);
      *(float *)v114 = (*((float *)v7 - 3) - *((float *)v7 + 9)) * v11 + *((float *)v7 + 9);
      v10 = (*(float *)v7 - *((float *)v7 + 12)) * v11 + *((float *)v7 + 12);
    }
    *(float *)v121 = v10;
    *(int *)v137 = LODWORD(v101);
    LODWORD(v12) = *(int *)v6;
    if ( v5 )
    {
      v13 = v12 + 6.7553994e15;
      v14 = *((float *)v7 - 4) + 6.7553994e15;
      if ( LODWORD(v13) == LODWORD(v14) )
      {
        v15 = *(float *)v137 + 6.7553994e15;
        v16 = *((float *)v7 - 5) + 6.7553994e15;
        v17 = LODWORD(v15) == LODWORD(v16);
        goto LABEL_23;
      }
    }
    else
    {
      v18 = v12 + 6.7553994e15;
      v19 = *((float *)v7 + 8) + 6.7553994e15;
      if ( LODWORD(v18) == LODWORD(v19) )
      {
        v20 = *(float *)v137 + 6.7553994e15;
        v21 = *((float *)v7 + 7) + 6.7553994e15;
        v17 = LODWORD(v20) == LODWORD(v21);
LABEL_23:
        if ( v17 )
          goto LABEL_25;
        goto LABEL_24;
      }
    }
LABEL_24:
    v121 += 48;
    v114 += 48;
    v6 += 48;
    ++v110;
    ++v132;
    v128 = v6;
    v137 += 48;
LABEL_25:
    if ( v106 )
    {
      v22 = v132;
      v128 += 48;
      ++v110;
      v114 += 48;
      v121 += 48;
      v137 += 48;
      ++v132;
      memcpy(v22, v7 + 4, 0x30u);
      v6 = v128;
    }
    v5 = v106;
    v7 += 48;
    --v117;
  }
  while ( v117 );
  if ( v110 < 3
    || (v115 = 0,
        memcpy(&array_50A2B0[v110], array_50A2B0, sizeof(array_50A2B0[v110])),
        v23 = array_50A2B0[0].vWorldViewProjX + 6.7553994e15,
        v24 = SLODWORD(v23) <= (signed int)pViewport->uViewportZ,
        v110 < 1) )
    goto LABEL_112;
  v25 = (char *)&array_509950[0].flt_20;
  v138 = array_509950;
  v129 = (char *)&array_50A2B0[0].vWorldViewProjX;
  v118 = (char *)&array_50A2B0[0].vWorldViewProjY;
  v133 = (char *)&array_509950[0].vWorldViewProjX;
  v122 = (char *)&array_509950[0].vWorldViewProjY;
  v124 = (char *)&array_509950[0].flt_2C;
  v111 = (char *)&array_509950[0].flt_20;
  v26 = (char *)&array_50A2B0[0].flt_2C;
  while ( 2 )
  {
    v97 = *((float *)v26 + 7) + 6.7553994e15;
    v27 = SLODWORD(v97) <= (signed int)pViewport->uViewportZ;
    v107 = SLODWORD(v97) <= (signed int)pViewport->uViewportZ;
    if ( v24 != v27 )
    {
      v28 = v100;
      if ( SLODWORD(v97) <= (signed int)pViewport->uViewportZ )
      {
        v29 = (v28 - *((float *)v26 - 5)) / (*((float *)v26 + 7) - *((float *)v26 - 5));
        *(float *)v122 = (*((float *)v26 + 8) - *((float *)v26 - 4)) * v29 + *((float *)v26 - 4);
        *(float *)v25 = (*((float *)v26 + 9) - *((float *)v26 - 3)) * v29 + *((float *)v26 - 3);
        v30 = (*((float *)v26 + 12) - *(float *)v26) * v29 + *(float *)v26;
      }
      else
      {
        v31 = (v28 - *((float *)v26 + 7)) / (*((float *)v26 - 5) - *((float *)v26 + 7));
        *(float *)v122 = (*((float *)v26 - 4) - *((float *)v26 + 8)) * v31 + *((float *)v26 + 8);
        *(float *)v25 = (*((float *)v26 - 3) - *((float *)v26 + 9)) * v31 + *((float *)v26 + 9);
        v30 = (*(float *)v26 - *((float *)v26 + 12)) * v31 + *((float *)v26 + 12);
      }
      *(float *)v124 = v30;
      *(int *)v133 = LODWORD(v100);
      if ( v24 )
      {
        v32 = *(float *)v122 + 6.7553994e15;
        v33 = *((float *)v26 - 4) + 6.7553994e15;
        if ( LODWORD(v32) == LODWORD(v33) )
        {
          v34 = *(float *)v133 + 6.7553994e15;
          v35 = *((float *)v26 - 5) + 6.7553994e15;
          v36 = LODWORD(v34) == LODWORD(v35);
          goto LABEL_41;
        }
        goto LABEL_42;
      }
      v37 = *(float *)v118 + 6.7553994e15;
      v38 = *((float *)v26 + 8) + 6.7553994e15;
      if ( LODWORD(v37) != LODWORD(v38) )
        goto LABEL_42;
      v39 = *(float *)v129 + 6.7553994e15;
      v40 = *((float *)v26 + 7) + 6.7553994e15;
      v36 = LODWORD(v39) == LODWORD(v40);
LABEL_41:
      if ( !v36 )
      {
LABEL_42:
        v129 += 48;
        v118 += 48;
        v133 += 48;
        v122 += 48;
        v124 += 48;
        v111 += 48;
        ++v115;
        ++v138;
      }
    }
    if ( v27 )
    {
      v41 = v138;
      ++v115;
      v111 += 48;
      v124 += 48;
      v122 += 48;
      v133 += 48;
      v118 += 48;
      v129 += 48;
      ++v138;
      memcpy(v41, v26 + 4, 0x30u);
    }
    v24 = v107;
    v26 += 48;
    --v110;
    if ( v110 )
    {
      v25 = v111;
      continue;
    }
    break;
  }
  if ( v115 < 3
    || (v123 = 0,
        memcpy(&array_509950[v115], array_509950, sizeof(array_509950[v115])),
        v42 = array_509950[0].vWorldViewProjY + 6.7553994e15,
        v43 = SLODWORD(v42) >= (signed int)pViewport->uViewportY,
        v115 < 1) )
    goto LABEL_112;
  v44 = (char *)&array_508FF0[0].vWorldViewProjX;
  v130 = array_508FF0;
  v119 = (char *)&array_508FF0[0].vWorldViewProjX;
  v139 = (char *)&array_508FF0[0].vWorldViewProjY;
  v125 = (char *)&array_508FF0[0].flt_2C;
  v134 = (char *)&array_508FF0[0].flt_20;
  v45 = (char *)&array_509950[0].flt_2C;
  v112 = v115;
  while ( 2 )
  {
    v98 = *((float *)v45 + 8) + 6.7553994e15;
    v46 = SLODWORD(v98) >= (signed int)pViewport->uViewportY;
    v108 = SLODWORD(v98) >= (signed int)pViewport->uViewportY;
    if ( v43 != v46 )
    {
      v47 = v104;
      if ( SLODWORD(v98) >= (signed int)pViewport->uViewportY )
      {
        v48 = (v47 - *((float *)v45 - 4)) / (*((float *)v45 + 8) - *((float *)v45 - 4));
        *(float *)v44 = (*((float *)v45 + 7) - *((float *)v45 - 5)) * v48 + *((float *)v45 - 5);
        *(float *)v134 = (*((float *)v45 + 9) - *((float *)v45 - 3)) * v48 + *((float *)v45 - 3);
        v49 = (*((float *)v45 + 12) - *(float *)v45) * v48 + *(float *)v45;
      }
      else
      {
        v50 = (v47 - *((float *)v45 + 8)) / (*((float *)v45 - 4) - *((float *)v45 + 8));
        *(float *)v44 = (*((float *)v45 - 5) - *((float *)v45 + 7)) * v50 + *((float *)v45 + 7);
        *(float *)v134 = (*((float *)v45 - 3) - *((float *)v45 + 9)) * v50 + *((float *)v45 + 9);
        v49 = (*(float *)v45 - *((float *)v45 + 12)) * v50 + *((float *)v45 + 12);
      }
      *(float *)v125 = v49;
      *(float *)v139 = v104;
      if ( v43 )
      {
        v51 = v104 + 6.7553994e15;
        v52 = *((float *)v45 - 4) + 6.7553994e15;
        if ( LODWORD(v51) == LODWORD(v52) )
        {
          v53 = *(float *)v44 + 6.7553994e15;
          v54 = *((float *)v45 - 5) + 6.7553994e15;
          v55 = LODWORD(v53) == LODWORD(v54);
          goto LABEL_58;
        }
        goto LABEL_59;
      }
      v56 = v104 + 6.7553994e15;
      v57 = *((float *)v45 + 8) + 6.7553994e15;
      if ( LODWORD(v56) != LODWORD(v57) )
        goto LABEL_59;
      v58 = *(float *)v44 + 6.7553994e15;
      v59 = *((float *)v45 + 7) + 6.7553994e15;
      v55 = LODWORD(v58) == LODWORD(v59);
LABEL_58:
      if ( !v55 )
      {
LABEL_59:
        v139 += 48;
        v125 += 48;
        v134 += 48;
        v44 += 48;
        ++v123;
        ++v130;
        v119 = v44;
      }
    }
    if ( v46 )
    {
      v60 = v130;
      v119 += 48;
      ++v123;
      v134 += 48;
      v125 += 48;
      v139 += 48;
      ++v130;
      memcpy(v60, v45 + 4, 0x30u);
      v44 = v119;
    }
    v43 = v108;
    v45 += 48;
    --v112;
    if ( v112 )
      continue;
    break;
  }
  if ( v123 < 3
    || (v116 = 0,
        memcpy(&array_508FF0[v123], array_508FF0, sizeof(array_508FF0[v123])),
        v61 = array_508FF0[0].vWorldViewProjY + 6.7553994e15,
        v62 = SLODWORD(v61) <= (signed int)pViewport->uViewportW,
        v123 < 1) )
    goto LABEL_112;
  v63 = (char *)&array_508690[0].vWorldViewProjX;
  v131 = array_508690;
  v120 = (char *)&array_508690[0].vWorldViewProjX;
  v140 = (char *)&array_508690[0].vWorldViewProjY;
  v126 = (char *)&array_508690[0].flt_2C;
  v135 = (char *)&array_508690[0].flt_20;
  v64 = (char *)&array_508FF0[0].flt_2C;
  v113 = v123;
  while ( 2 )
  {
    v99 = *((float *)v64 + 8) + 6.7553994e15;
    v65 = SLODWORD(v99) <= (signed int)pViewport->uViewportW;
    v109 = SLODWORD(v99) <= (signed int)pViewport->uViewportW;
    if ( v62 != v65 )
    {
      v66 = v102;
      if ( SLODWORD(v99) <= (signed int)pViewport->uViewportW )
      {
        v67 = (v66 - *((float *)v64 - 4)) / (*((float *)v64 + 8) - *((float *)v64 - 4));
        *(float *)v63 = (*((float *)v64 + 7) - *((float *)v64 - 5)) * v67 + *((float *)v64 - 5);
        *(float *)v135 = (*((float *)v64 + 9) - *((float *)v64 - 3)) * v67 + *((float *)v64 - 3);
        v68 = (*((float *)v64 + 12) - *(float *)v64) * v67 + *(float *)v64;
      }
      else
      {
        v69 = (v66 - *((float *)v64 + 8)) / (*((float *)v64 - 4) - *((float *)v64 + 8));
        *(float *)v63 = (*((float *)v64 - 5) - *((float *)v64 + 7)) * v69 + *((float *)v64 + 7);
        *(float *)v135 = (*((float *)v64 - 3) - *((float *)v64 + 9)) * v69 + *((float *)v64 + 9);
        v68 = (*(float *)v64 - *((float *)v64 + 12)) * v69 + *((float *)v64 + 12);
      }
      *(float *)v126 = v68;
      *(float *)v140 = v102;
      if ( v62 )
      {
        v70 = v102 + 6.7553994e15;
        v71 = *((float *)v64 - 4) + 6.7553994e15;
        if ( LODWORD(v70) == LODWORD(v71) )
        {
          v72 = *(float *)v63 + 6.7553994e15;
          v73 = *((float *)v64 - 5) + 6.7553994e15;
          v74 = LODWORD(v72) == LODWORD(v73);
          goto LABEL_75;
        }
        goto LABEL_76;
      }
      v75 = v102 + 6.7553994e15;
      v76 = *((float *)v64 + 8) + 6.7553994e15;
      if ( LODWORD(v75) != LODWORD(v76) )
        goto LABEL_76;
      v77 = *(float *)v63 + 6.7553994e15;
      v78 = *((float *)v64 + 7) + 6.7553994e15;
      v74 = LODWORD(v77) == LODWORD(v78);
LABEL_75:
      if ( !v74 )
      {
LABEL_76:
        v140 += 48;
        v126 += 48;
        v135 += 48;
        v63 += 48;
        ++v116;
        ++v131;
        v120 = v63;
      }
    }
    if ( v65 )
    {
      v79 = v131;
      v120 += 48;
      ++v116;
      v135 += 48;
      v126 += 48;
      v140 += 48;
      ++v131;
      memcpy(v79, v64 + 4, 0x30u);
      v63 = v120;
    }
    v62 = v109;
    v64 += 48;
    --v113;
    if ( v113 )
      continue;
    break;
  }
  if ( v116 < 3 )
    goto LABEL_112;
  v80 = v116;
  memcpy(&array_508690[v116], array_508690, sizeof(array_508690[v116]));
  if ( v116 > 0 )
  {
    v81 = (char *)&array_508690[0].vWorldViewProjX;
    v82 = v116;
    do
    {
      LODWORD(v83) = *(int *)v81;
      *((float *)v81 - 3) = 1.0 / *((float *)v81 + 2);
      v84 = v83 + 6.7553994e15;
      if ( SLODWORD(v84) <= (signed int)pViewport->uViewportZ )
      {
        v86 = *(float *)v81 + 6.7553994e15;
        if ( SLODWORD(v86) >= (signed int)pViewport->uViewportX )
          goto LABEL_88;
        v85 = v101;
      }
      else
      {
        v85 = v100;
      }
      *(int *)v81 = LODWORD(v85);
LABEL_88:
      v87 = *((float *)v81 + 1) + 6.7553994e15;
      if ( SLODWORD(v87) > (signed int)pViewport->uViewportW )
      {
        v88 = v102;
LABEL_92:
        *((int *)v81 + 1) = LODWORD(v88);
        goto LABEL_93;
      }
      v89 = *((float *)v81 + 1) + 6.7553994e15;
      if ( SLODWORD(v89) < (signed int)pViewport->uViewportY )
      {
        v88 = v104;
        goto LABEL_92;
      }
LABEL_93:
      v81 += 48;
      --v82;
    }
    while ( v82 );
  }
  v91 = __OFSUB__(v116, 3);
  v90 = v116 - 3 < 0;
  if ( v116 > 3 )
  {
    memcpy(&array_508690[v116 + 1], &array_508690[1], sizeof(array_508690[v116 + 1]));
    if ( v116 > 0 )
    {
      v105 = 1;
      do
      {
        v92 = v105;
        v93 = v105 - 1;
        v94 = v105 + 1;
        v95 = v105 + 1;
        if ( v105 - 1 >= v80 )
          v93 -= v80;
        if ( v105 >= v80 )
          v92 = v105 - v80;
        if ( v94 >= v80 )
          v95 = v94 - v80;
        if ( (array_508690[v92].vWorldViewProjX - array_508690[v93].vWorldViewProjX)
           * (array_508690[v95].vWorldViewProjY - array_508690[v93].vWorldViewProjY)
           - (array_508690[v95].vWorldViewProjX - array_508690[v93].vWorldViewProjX)
           * (array_508690[v92].vWorldViewProjY - array_508690[v93].vWorldViewProjY) < 0.0 )
        {
          ++v105;
        }
        else
        {
          v96 = v105;
          if ( v105 < v80 || (v96 = v105 - v80, v105 - v80 < v80) )
            memcpy(&array_508690[v96], &array_508690[v96 + 1], 4 * ((unsigned int)(48 * v80 - 48 * v96) >> 2));
          --v80;
        }
      }
      while ( v105 - 1 < v80 );
    }
    v91 = __OFSUB__(v80, 3);
    v90 = v80 - 3 < 0;
  }
  if ( v90 ^ v91 )
LABEL_112:
    result = 0;
  else
    result = v80;
  return result;
}

//----- (0042620A) --------------------------------------------------------
bool __thiscall sr_42620A(RenderVertexSoft *p)
{
  __int16 v1; // fps@1
  unsigned __int8 v2; // c0@2
  char v3; // c2@2
  unsigned __int8 v4; // c3@2
  bool result; // eax@2
  unsigned __int8 v6; // c0@4
  char v7; // c2@4
  unsigned __int8 v8; // c3@4
  unsigned __int8 v9; // c0@6
  char v10; // c2@6
  unsigned __int8 v11; // c3@6
  double v12; // st6@7
  float v13; // ST04_4@7
  float v14; // ST00_4@7
  double v15; // st7@7
  double v16; // st6@8
  float v17; // ST04_4@8
  float v18; // ST00_4@8
  double v19; // st7@8

  //UNDEF(v1);
  if ( p->vWorldViewPosition.x < 300.0
    || (v2 = 300.0 < p[1].vWorldViewPosition.x,
        v3 = 0,
        v4 = 300.0 == p[1].vWorldViewPosition.x,
        BYTE1(result) = HIBYTE(v1),
        !(v2 | v4)) )
  {
    if ( p->vWorldViewPosition.x < 300.0 )
    {
      v6 = 300.0 < p[1].vWorldViewPosition.x;
      v7 = 0;
      v8 = 300.0 == p[1].vWorldViewPosition.x;
      BYTE1(result) = HIBYTE(v1);
      if ( !(v6 | v8) )
      {
        LOBYTE(result) = 0;
        return result;
      }
    }
    v9 = 300.0 < p->vWorldViewPosition.x;
    v10 = 0;
    v11 = 300.0 == p->vWorldViewPosition.x;
    BYTE1(result) = HIBYTE(v1);
    if ( v9 | v11 )
    {
      v16 = 1.0 / (p->vWorldViewPosition.x - p[1].vWorldViewPosition.x);
      v17 = (p->vWorldViewPosition.y - p[1].vWorldViewPosition.y) * v16;
      v18 = (p->vWorldViewPosition.z - p[1].vWorldViewPosition.z) * v16;
      v19 = 300.0 - p[1].vWorldViewPosition.x;
      p[1].vWorldViewPosition.x = v19 + p[1].vWorldViewPosition.x;
      p[1].vWorldViewPosition.y = v17 * v19 + p[1].vWorldViewPosition.y;
      p[1].vWorldViewPosition.z = v19 * v18 + p[1].vWorldViewPosition.z;
    }
    else
    {
      v12 = 1.0 / (p[1].vWorldViewPosition.x - p->vWorldViewPosition.x);
      v13 = (p[1].vWorldViewPosition.y - p->vWorldViewPosition.y) * v12;
      v14 = (p[1].vWorldViewPosition.z - p->vWorldViewPosition.z) * v12;
      v15 = 300.0 - p->vWorldViewPosition.x;
      p->vWorldViewPosition.x = v15 + p->vWorldViewPosition.x;
      p->vWorldViewPosition.y = v13 * v15 + p->vWorldViewPosition.y;
      p->vWorldViewPosition.z = v15 * v14 + p->vWorldViewPosition.z;
    }
  }
  LOBYTE(result) = 1;
  return result;
}




//----- (004268E3) --------------------------------------------------------
int __fastcall _4268E3_smthn_to_a1r5g5b5(unsigned int uColor)
{
  unsigned int v1; // eax@1
  unsigned int v2; // edx@1
  int v3; // eax@1
  int v4; // edx@1
  unsigned int v5; // ecx@1

  v1 = uColor >> 9;
  v2 = uColor >> 6;
  LOWORD(v1) = (uColor >> 9) & 0x7C00;
  LOWORD(v2) = (uColor >> 6) & 0x3E0;
  v3 = v2 | v1;
  v4 = (unsigned __int8)uColor >> 3;
  v5 = uColor >> 16;
  LOWORD(v5) = v5 & 0x8000;
  return v5 | v4 | v3;
}

//----- (0042690D) --------------------------------------------------------
int __fastcall _42690D_colors_cvt(unsigned int a1)
{
  unsigned int v1; // eax@1
  unsigned int v2; // edx@1

  v1 = a1 >> 8;
  v2 = a1 >> 5;
  LOWORD(v1) = (a1 >> 8) & 0xF800;
  LOWORD(v2) = (a1 >> 5) & 0x7E0;
  return ((unsigned __int8)a1 >> 3) | v2 | v1;
}

//----- (00426947) --------------------------------------------------------
void __cdecl sub_426947()
{
  dword_50C968 = 0;
  dword_50C994 = 0;
  dword_50C998_turnbased_icon_1A = 0;
}
// 50C968: using guessed type int dword_50C968;
// 50C994: using guessed type int dword_50C994;
// 50C998: using guessed type int dword_50C998_turnbased_icon_1A;



//----- (004269A2) --------------------------------------------------------
int __fastcall sub_4269A2_GivePartyExp(unsigned int a1)
{
  unsigned __int64 v1; // qax@1
  signed int v2; // ecx@1
  char *v3; // esi@1
  bool v4; // edi@6
  char *v5; // edi@10
  char *v6; // esi@10
  int v7; // eax@13
  unsigned __int8 v8; // cf@13
  char v10; // [sp+Ch] [bp-14h]@1
  int v11; // [sp+1Ch] [bp-4h]@10

  v1 = __PAIR__((int)((char *)&pParty + 2620), a1);
  v2 = 0;
  v3 = &v10;
  do
  {
    v4 = !(*(int *)(HIDWORD(v1) - 4) | *(int *)(HIDWORD(v1) - 8))
      && !*(int *)HIDWORD(v1)
      && !*(_QWORD *)(HIDWORD(v1) + 8)
      && !*(_QWORD *)(HIDWORD(v1) + 16);
    *(int *)v3 = v4;
    HIDWORD(v1) += 6972;
    v2 += v4;
    v3 += 4;
  }
  while ( SHIDWORD(v1) < (signed int)&pParty->pHirelings[1].field_24 );
  if ( v2 )
  {
    LODWORD(v1) = (signed int)v1 / v2;
    v5 = &v10;
    v6 = (char *)&pParty->pPlayers[0].uExperience;
    v11 = v1;
    do
    {
      if ( *(int *)v5 )
      {
        if ( v11 )
        {
          LOBYTE(v7) = ((Player *)(v6 - 160))->GetLearningPercent();
          v1 = v11 + v11 * v7 / 100;
          v8 = __CFADD__((int)v1, *(int *)v6);
          *(int *)v6 += v1;
          *((int *)v6 + 1) += HIDWORD(v1) + v8;
          if ( *(_QWORD *)v6 > 4000000000i64 )
          {
            *((int *)v6 + 1) = 0;
            *(int *)v6 = -294967296;
          }
        }
      }
      v6 += 6972;
      v5 += 4;
    }
    while ( (signed int)v6 < (signed int)&pParty->pPickedItem._bonus_strength );
  }
  return v1;
}

//----- (00426A5A) --------------------------------------------------------
void stru319::LootActor(Actor *pActor)
{
  signed int v2; // edi@1
  char v3; // zf@1
  unsigned int v4; // eax@13
  unsigned int v5; // esi@13
  int v6; // eax@14
  unsigned __int8 v7; // al@30
  Party *v8; // esi@34
  char *v9; // [sp-4h] [bp-3Ch]@10
  char *v10; // [sp-4h] [bp-3Ch]@31
  char *v11; // [sp-4h] [bp-3Ch]@38
  ItemGen Dst; // [sp+Ch] [bp-2Ch]@1
  int v13; // [sp+30h] [bp-8h]@1
  int v14; // [sp+34h] [bp-4h]@1

  sub_421B2C_PlaceInInventory_or_DropPickedItem();
  Dst.Reset();
  v2 = 0;
  v3 = ((unsigned int)&array_77EC08[1975].pEdgeList1[1] & pActor->uAttributes) == 0;
  v13 = 0;
  v14 = 0;
  if ( v3 )
  {
    if ( !pActor->pMonsterInfo.uTreasureDiceRolls )
      goto LABEL_9;
    do
    {
      ++v2;
      v14 += rand() % pActor->pMonsterInfo.uTreasureDiceSides + 1;
    }
    while ( v2 < pActor->pMonsterInfo.uTreasureDiceRolls );
  }
  else
  {
    if ( pItemsTable->pItems[pActor->array_000234[3].uItemID].uEquipType != 18 )
      goto LABEL_9;
    v14 = pActor->array_000234[3].uAdditionalValue;
    pActor->array_000234[3].Reset();
  }
  if ( v14 )
  {
    party_finds_gold(v14, 0);
    viewparams->bRedrawGameUI = 1;
  }
LABEL_9:
  if ( pActor->uCarriedItemID )
  {
    Dst.Reset();
    Dst.uItemID = pActor->uCarriedItemID;
    v9 = pItemsTable->pItems[Dst.uItemID].pUnidentifiedName;
    if ( v14 )
      sprintf(pTmpBuf2, pGlobalTXT_LocalizationStrings[490], v14, v9);
    else
      sprintf(pTmpBuf2, pGlobalTXT_LocalizationStrings[471], v9);
    ShowStatusBarString(pTmpBuf2, 2u);
    v4 = Dst.uItemID;
    v5 = Dst.uItemID;
    if ( pItemsTable->pItems[Dst.uItemID].uEquipType == 12 )
    {
      v5 = Dst.uItemID;
      v6 = rand() % 6 + pItemsTable->pItems[Dst.uItemID].uDamageMod + 1;
      Dst.uNumCharges = v6;
      Dst.uMaxCharges = v6;
      v4 = Dst.uItemID;
    }
    if ( pItemsTable->pItems[v5].uEquipType == 14 && v4 != 220 )
      Dst._bonus_type = 2 * rand() % 4 + 2;
    pItemsTable->SetSpecialBonus(&Dst);
    if ( !pParty->AddItem(&Dst) )
      pParty->SetHoldingItem(&Dst);
    pActor->uCarriedItemID = 0;
    if ( pActor->array_000234[0].uItemID )
    {
      if ( !pParty->AddItem(pActor->array_000234) )
      {
        sub_421B2C_PlaceInInventory_or_DropPickedItem();
        pParty->SetHoldingItem(pActor->array_000234);
      }
      pActor->array_000234[0].Reset();
    }
    if ( pActor->array_000234[1].uItemID )
    {
      if ( !pParty->AddItem(&pActor->array_000234[1]) )
      {
        sub_421B2C_PlaceInInventory_or_DropPickedItem();
        pParty->SetHoldingItem(&pActor->array_000234[1]);
      }
      pActor->array_000234[1].Reset();
    }
LABEL_55:
    pActor->Remove();
    return;
  }
  if ( (unsigned int)&array_77EC08[1975].pEdgeList1[1] & pActor->uAttributes )
  {
    if ( pActor->array_000234[3].uItemID )
    {
      memcpy(&Dst, &pActor->array_000234[3], sizeof(Dst));
      pActor->array_000234[3].Reset();
      v11 = pItemsTable->pItems[Dst.uItemID].pUnidentifiedName;
      if ( v14 )
        sprintf(pTmpBuf2, pGlobalTXT_LocalizationStrings[490], v14, v11);
      else
        sprintf(pTmpBuf2, pGlobalTXT_LocalizationStrings[471], v11);
      ShowStatusBarString(pTmpBuf2, 2u);
      if ( !pParty->AddItem(&Dst) )
        pParty->SetHoldingItem(&Dst);
      v13 = 1;
    }
    goto LABEL_44;
  }
  if ( rand() % 100 >= pActor->pMonsterInfo.uTreasureDropChance || (v7 = pActor->pMonsterInfo.uTreasureLevel) == 0 )
  {
LABEL_44:
    v8 = pParty;
    goto LABEL_45;
  }
  pItemsTable->GenerateItem(v7, pActor->pMonsterInfo.uTreasureType, &Dst);
  v10 = pItemsTable->pItems[Dst.uItemID].pUnidentifiedName;
  if ( v14 )
    sprintf(pTmpBuf2, pGlobalTXT_LocalizationStrings[490], v14, v10);
  else
    sprintf(pTmpBuf2, pGlobalTXT_LocalizationStrings[471], v10);
  ShowStatusBarString(pTmpBuf2, 2u);
  v8 = pParty;
  if ( !pParty->AddItem(&Dst) )
    pParty->SetHoldingItem(&Dst);
  v13 = 1;
LABEL_45:
  if ( pActor->array_000234[0].uItemID )
  {
    if ( !v8->AddItem(pActor->array_000234) )
    {
      sub_421B2C_PlaceInInventory_or_DropPickedItem();
      v8->SetHoldingItem(pActor->array_000234);
      v13 = 1;
    }
    pActor->array_000234[0].Reset();
  }
  if ( pActor->array_000234[1].uItemID )
  {
    if ( !v8->AddItem(&pActor->array_000234[1]) )
    {
      sub_421B2C_PlaceInInventory_or_DropPickedItem();
      v8->SetHoldingItem(&pActor->array_000234[1]);
      v13 = 1;
    }
    pActor->array_000234[1].Reset();
  }
  if ( !v13 || rand() % 100 < 90 )
    goto LABEL_55;
}

//----- (00426E10) --------------------------------------------------------
int stru319::which_player_would_attack(Actor *pActor)
{
  signed int v2; // ebx@1
  int v3; // ecx@2
  signed int v4; // edx@3
  char v5; // zf@3
  unsigned int v6; // eax@3
  int v7; // eax@6
  int v8; // eax@7
  int v9; // eax@8
  int v10; // eax@9
  int v11; // eax@10
  int v12; // eax@11
  int v13; // esi@35
  signed int v14; // edi@37
  enum CHARACTER_RACE v15; // eax@44
  Player *v16; // ecx@47
  unsigned __int8 v17; // sf@50
  unsigned __int8 v18; // of@50
  int v19; // esi@52
  Player *v20; // ecx@53
  int result; // eax@57
  int v22[16]; // [sp+8h] [bp-140h]@3
  int v23[60]; // [sp+48h] [bp-100h]@48
  int v24; // [sp+138h] [bp-10h]@2
  int v25; // [sp+13Ch] [bp-Ch]@1
  int v26; // [sp+140h] [bp-8h]@1
  int v27; // [sp+144h] [bp-4h]@1

  v27 = -1;
  v26 = -1;
  v25 = -1;
  v2 = 0;
  if ( pActor->pMonsterInfo.uAttackPreference )
  {
    v3 = 0;
    v24 = 0;
    do
    {
      v4 = 1;
      v6 = pActor->pMonsterInfo.uAttackPreference & (1 << v3);
      v5 = (pActor->pMonsterInfo.uAttackPreference & (1 << v3)) == 0;
      v22[v3] = v6;
      if ( !v5 )
      {
        if ( (signed int)v6 > 128 )
        {
          switch ( v6 )
          {
            case 0x100u:
              v27 = 8;
              break;
            case 0x200u:
              v25 = 0;
              break;
            case 0x400u:
              v25 = 1;
              break;
            case 0x800u:
              v26 = 0;
              break;
            case 0x1000u:
              v26 = 1;
              break;
            case 0x2000u:
              v26 = 3;
              break;
            case 0x4000u:
              v26 = 2;
              break;
          }
        }
        else
        {
          if ( v6 == 128 )
          {
            v27 = 4;
          }
          else
          {
            v7 = v6 - 1;
            if ( v7 )
            {
              v8 = v7 - 1;
              if ( v8 )
              {
                v9 = v8 - 2;
                if ( v9 )
                {
                  v10 = v9 - 4;
                  if ( v10 )
                  {
                    v11 = v10 - 8;
                    if ( v11 )
                    {
                      v12 = v11 - 16;
                      if ( v12 )
                      {
                        if ( v12 == 32 )
                          v27 = 20;
                      }
                      else
                      {
                        v27 = 32;
                      }
                    }
                    else
                    {
                      v27 = 24;
                    }
                  }
                  else
                  {
                    v27 = 28;
                  }
                }
                else
                {
                  v27 = 16;
                }
              }
              else
              {
                v27 = 12;
              }
            }
            else
            {
              v27 = 0;
            }
          }
        }
        v2 = 0;
        v13 = 0;
        while ( 1 )
        {
          v14 = 0;
          if ( v27 != -1 && v27 == pPlayers[v13 + 1]->uClass )
            v14 = v4;
          if ( v25 != -1 && v25 == pPlayers[v13 + 1]->uSex )
            v14 = v4;
          if ( v26 != -1 )
          {
            v15 = pPlayers[v13 + 1]->GetRace();
            if ( v26 == v15 )
              v14 = 1;
          }
          if ( v14 == 1 )
          {
            v16 = pPlayers[v13 + 1];
            if ( !(v16->pConditions[12] | v16->pConditions[13] | v16->pConditions[14] | v16->pConditions[15] | v16->pConditions[16]) )
              v23[v2++] = v13;
          }
          ++v13;
          if ( v13 >= 4 )
            break;
          v4 = 1;
        }
      }
      v3 = v24 + 1;
      v18 = __OFSUB__(v24 + 1, 15);
      v17 = v24++ - 14 < 0;
    }
    while ( v17 ^ v18 );
    if ( v2 )
      goto LABEL_61;
  }
  v19 = 0;
  do
  {
    v20 = pPlayers[v19 + 1];
    if ( !(v20->pConditions[12] | v20->pConditions[13] | v20->pConditions[14] | v20->pConditions[15] | v20->pConditions[16]) )
      v23[v2++] = v19;
    ++v19;
  }
  while ( v19 < 4 );
  if ( v2 )
LABEL_61:
    result = v23[rand() % v2];
  else
    result = 0;
  return result;
}


//----- (0042704B) --------------------------------------------------------
bool stru319::special_ability_use_check(Actor *pActor, int a2)
{
  stru319 *v3; // edi@1
  signed int v4; // ebx@5
  signed int v5; // edi@5

  v3 = this;
  if ( pActor->pMonsterInfo.uSpecialAbilityType == 2
    && pActor->pMonsterInfo.uSpecialAbilityDamageDiceBonus < 3u
    && rand() % 100 < 5 )
    pActor->_44FD29(a2);
  v4 = v3->_427102(pActor, pActor->pMonsterInfo.uSpell1ID);
  v5 = v3->_427102(pActor, pActor->pMonsterInfo.uSpell2ID);
  if ( v4 && pActor->pMonsterInfo.uSpell1UseChance && rand() % 100 < pActor->pMonsterInfo.uSpell1UseChance )
    return 2;
  if ( v5 && pActor->pMonsterInfo.uSpell2UseChance && rand() % 100 < pActor->pMonsterInfo.uSpell2UseChance )
    return 3;
  return pActor->pMonsterInfo.uAttack2Chance && rand() % 100 < pActor->pMonsterInfo.uAttack2Chance;
}

//----- (00427102) --------------------------------------------------------
int stru319::_427102(Actor *pActor, signed int a2)
{
  unsigned __int8 v3; // cf@11
  unsigned __int8 v4; // zf@11
  SpellBuff *v6; // ecx@46
  char *v7; // esi@49
  signed int v8; // edx@50
  char *v9; // ecx@50

  if ( a2 > 73 )
  {
    if ( a2 == 77 )
    {
      if ( pActor->sCurrentHP >= (signed int)pActor->pMonsterInfo.uHP )
        return 0;
      return 1;
    }
    if ( a2 == 80 )
    {
      v6 = pParty->pPartyBuffs;
      while ( (signed __int64)v6->uExpireTime <= 0 )
      {
        ++v6;
        if ( (signed int)v6 >= (signed int)pParty->pPlayers )
        {
          v7 = (char *)pParty->pPlayers[0].pPlayerBuffs;
LABEL_50:
          v8 = 0;
          v9 = v7;
          while ( *(_QWORD *)v9 <= 0i64 )
          {
            ++v8;
            v9 += 16;
            if ( v8 >= 24 )
            {
              v7 += 6972;
              if ( (signed int)v7 < (signed int)&pParty->field_871C[464] )
                goto LABEL_50;
              return 0;
            }
          }
          return 1;
        }
      }
      return 1;
    }
    if ( a2 == 85 )
    {
      if ( SHIDWORD(pActor->pActorBuffs[13].uExpireTime) < 0 )
        return 1;
      if ( SHIDWORD(pActor->pActorBuffs[13].uExpireTime) > 0 )
        return 0;
      v3 = 0;
      v4 = LODWORD(pActor->pActorBuffs[13].uExpireTime) == 0;
    }
    else
    {
      if ( a2 == 86 )
      {
        if ( SHIDWORD(pActor->pActorBuffs[14].uExpireTime) < 0 )
          return 1;
        if ( SHIDWORD(pActor->pActorBuffs[14].uExpireTime) > 0 )
          return 0;
        v3 = 0;
        v4 = LODWORD(pActor->pActorBuffs[14].uExpireTime) == 0;
      }
      else
      {
        if ( a2 != 95 || SHIDWORD(pActor->pActorBuffs[20].uExpireTime) < 0 )
          return 1;
        if ( SHIDWORD(pActor->pActorBuffs[20].uExpireTime) > 0 )
          return 0;
        v3 = 0;
        v4 = LODWORD(pActor->pActorBuffs[20].uExpireTime) == 0;
      }
    }
  }
  else
  {
    if ( a2 == 73 )
    {
      if ( SHIDWORD(pActor->pActorBuffs[21].uExpireTime) < 0 )
        return 1;
      if ( SHIDWORD(pActor->pActorBuffs[21].uExpireTime) > 0 )
        return 0;
      v3 = 0;
      v4 = LODWORD(pActor->pActorBuffs[21].uExpireTime) == 0;
      goto LABEL_15;
    }
    if ( a2 == 5 )
    {
      if ( SHIDWORD(pActor->pActorBuffs[19].uExpireTime) < 0 )
        return 1;
      if ( SHIDWORD(pActor->pActorBuffs[19].uExpireTime) > 0 )
        return 0;
      v3 = 0;
      v4 = LODWORD(pActor->pActorBuffs[19].uExpireTime) == 0;
      goto LABEL_15;
    }
    if ( a2 == 17 )
    {
      if ( SHIDWORD(pActor->pActorBuffs[15].uExpireTime) < 0 )
        return 1;
      if ( SHIDWORD(pActor->pActorBuffs[15].uExpireTime) > 0 )
        return 0;
      v3 = 0;
      v4 = LODWORD(pActor->pActorBuffs[15].uExpireTime) == 0;
      goto LABEL_15;
    }
    if ( a2 == 38 )
    {
      if ( SHIDWORD(pActor->pActorBuffs[16].uExpireTime) < 0 )
        return 1;
      if ( SHIDWORD(pActor->pActorBuffs[16].uExpireTime) > 0 )
        return 0;
      v3 = 0;
      v4 = LODWORD(pActor->pActorBuffs[16].uExpireTime) == 0;
      goto LABEL_15;
    }
    if ( a2 == 46 )
    {
      if ( SHIDWORD(pActor->pActorBuffs[17].uExpireTime) < 0 )
        return 1;
      if ( SHIDWORD(pActor->pActorBuffs[17].uExpireTime) > 0 )
        return 0;
      v3 = 0;
      v4 = LODWORD(pActor->pActorBuffs[17].uExpireTime) == 0;
      goto LABEL_15;
    }
    if ( a2 != 47 )
    {
      if ( a2 != 51 || SHIDWORD(pActor->pActorBuffs[18].uExpireTime) < 0 )
        return 1;
      if ( SHIDWORD(pActor->pActorBuffs[18].uExpireTime) <= 0 )
      {
        v3 = 0;
        v4 = LODWORD(pActor->pActorBuffs[18].uExpireTime) == 0;
        goto LABEL_15;
      }
      return 0;
    }
    if ( SHIDWORD(pActor->pActorBuffs[11].uExpireTime) < 0 )
      return 1;
    if ( SHIDWORD(pActor->pActorBuffs[11].uExpireTime) > 0 )
      return 0;
    v3 = 0;
    v4 = LODWORD(pActor->pActorBuffs[11].uExpireTime) == 0;
  }
LABEL_15:
  if ( !(v3 | v4) )
    return 0;
  return 1;
}

//----- (004272F5) --------------------------------------------------------
int stru319::PlayerHitOrMiss(Player *pPlayer, Actor *pActor, int a3, int a4)
{
  signed int v5; // esi@1
  signed int v6; // edi@1
  int v7; // esi@8
  int v8; // eax@9
  int v9; // edx@11
  int v10; // edx@13
  int v11; // esi@13
  unsigned __int8 v12; // sf@13
  unsigned __int8 v13; // of@13
  int v14; // edx@14
  int v15; // eax@14
  signed int result; // eax@17

  v5 = pActor->pMonsterInfo.uAC;
  v6 = 0;
  if ( (signed __int64)pActor->pActorBuffs[8].uExpireTime > 0 )
    v5 /= 2;
  if ( (signed __int64)pActor->pActorBuffs[14].uExpireTime > 0 )
    v6 = pActor->pActorBuffs[15].uPower;
  if ( (signed __int64)pActor->pActorBuffs[16].uExpireTime > 0 && pActor->pActorBuffs[16].uPower > v6 )
    v6 = pActor->pActorBuffs[16].uPower;
  v7 = v6 + v5;
  if ( a3 )
    v8 = pPlayer->GetRangedAttack();
  else
    v8 = pPlayer->GetActualAttack(0);
  v9 = rand() % (v7 + 2 * v8 + 30);
  if ( a3 == 2 )
  {
    v14 = a4 + v9;
    v15 = ((v7 + 15) >> 1) + v7 + 15;
  }
  else
  {
    if ( a3 != 3 )
    {
      v10 = a4 + v9;
      v11 = v7 + 15;
      v13 = __OFSUB__(v10, v11);
      v12 = v10 - v11 < 0;
      goto LABEL_16;
    }
    v14 = a4 + v9;
    v15 = 2 * v7 + 30;
  }
  v13 = __OFSUB__(v14, v15);
  v12 = v14 - v15 < 0;
LABEL_16:
  if ( v12 ^ v13 )
    result = 0;
  else
    result = 1;
  return result;
}

//----- (004273BB) --------------------------------------------------------
bool stru319::_4273BB(Actor *pActor, Actor *a2, int a3, int a4)
{
  Actor *v5; // ecx@1
  signed int v6; // ebx@1
  signed int v7; // esi@1
  unsigned __int8 v8; // zf@1
  unsigned __int8 v9; // sf@1
  int v10; // ebx@10
  signed int a2a; // [sp+18h] [bp+Ch]@1

  v5 = a2;
  v6 = a2->pMonsterInfo.uAC;
  v7 = 0;
  v8 = HIDWORD(a2->pActorBuffs[8].uExpireTime) == 0;
  v9 = SHIDWORD(a2->pActorBuffs[8].uExpireTime) < 0;
  a2a = 0;
  if ( !v9 && (!(v9 | v8) || LODWORD(v5->pActorBuffs[8].uExpireTime) > 0) )
    v6 /= 2;
  if ( (signed __int64)v5->pActorBuffs[14].uExpireTime > 0 )
    v7 = v5->pActorBuffs[14].uPower;
  if ( (signed __int64)v5->pActorBuffs[16].uExpireTime > 0 && v5->pActorBuffs[16].uPower > v7 )
    v7 = v5->pActorBuffs[16].uPower;
  v10 = v7 + v6;
  if ( (signed __int64)pActor->pActorBuffs[14].uExpireTime > 0 )
    a2a = pActor->pActorBuffs[14].uPower;
  if ( (signed __int64)pActor->pActorBuffs[17].uExpireTime > 0 && pActor->pActorBuffs[17].uPower > a2a )
    a2a = pActor->pActorBuffs[17].uPower;
  if ( (signed __int64)pActor->pActorBuffs[11].uExpireTime > 0 )
  {
    a2a += pActor->pActorBuffs[11].uPower;
    pActor->pActorBuffs[11].Reset();
  }
  return rand() % (v10 + 2 * pActor->pMonsterInfo.uLevel + 10) + a2a + 1 > v10 + 5;
}

//----- (004274AD) --------------------------------------------------------
bool stru319::ActorHitOrMiss(Actor *pActor, Player *pPlayer)
{
  signed int v3; // edi@1
  signed int v4; // esi@8
  int v5; // esi@8

  v3 = 0;
  if ( (signed __int64)pActor->pActorBuffs[14].uExpireTime > 0 )
    v3 = pActor->pActorBuffs[14].uPower;
  if ( (signed __int64)pActor->pActorBuffs[17].uExpireTime > 0 && pActor->pActorBuffs[17].uPower > v3 )
    v3 = pActor->pActorBuffs[17].uPower;
  if ( (signed __int64)pActor->pActorBuffs[11].uExpireTime > 0 )
  {
    v3 += pActor->pActorBuffs[11].uPower;
    pActor->pActorBuffs[11].Reset();
  }
  v4 = pPlayer->GetActualAC() + 2 * pActor->pMonsterInfo.uLevel + 10;
  v5 = rand() % v4 + 1;
  return v3 + v5 > pPlayer->GetActualAC() + 5;
}

//----- (00427546) --------------------------------------------------------
int stru319::_427546(int a2)
{
  int result; // eax@2

  if ( a2 >= 0 )
  {
    if ( a2 >= 1 )
      result = (a2 >= 2) + 2;
    else
      result = 1;
  }
  else
  {
    result = 0;
  }
  return result;
}

//----- (0042756B) --------------------------------------------------------
int stru319::CalcMagicalDamageToActor(Actor *pActor, int a2, signed int a3)
{
  int v4; // edx@1
  int v5; // ecx@1
  signed int v6; // eax@4
  signed int result; // eax@17
  signed int v8; // esi@18

  v4 = 0;
  v5 = 0;
  if ( (signed __int64)pActor->pActorBuffs[14].uExpireTime > 0 )
    v5 = pActor->pActorBuffs[14].uPower;
  switch ( a2 )
  {
    case 4:
      v6 = pActor->pMonsterInfo.uResPhysical;
      break;
    case 0:
      v6 = pActor->pMonsterInfo.uResFire;
      goto LABEL_12;
    case 1:
      v6 = pActor->pMonsterInfo.uResAir;
      goto LABEL_12;
    case 2:
      v6 = pActor->pMonsterInfo.uResWater;
      goto LABEL_12;
    case 3:
      v6 = pActor->pMonsterInfo.uResEarth;
      goto LABEL_12;
    case 6:
      v6 = pActor->pMonsterInfo.uResSpirit;
      break;
    case 7:
      v6 = pActor->pMonsterInfo.uResMind;
      goto LABEL_12;
    case 8:
      v6 = pActor->pMonsterInfo.uResBody;
LABEL_12:
      v4 = v5;
      break;
    case 9:
      v6 = pActor->pMonsterInfo.uResLight;
      break;
    case 10:
      v6 = pActor->pMonsterInfo.uResDark;
      break;
    default:
      v6 = 0;
      break;
  }
  if ( v6 < 200 )
  {
    v8 = v4 + v6 + 30;
    if ( rand() % v8 >= 30 )
    {
      a3 >>= 1;
      if ( rand() % v8 >= 30 )
      {
        a3 >>= 1;
        if ( rand() % v8 >= 30 )
        {
          a3 >>= 1;
          if ( rand() % v8 >= 30 )
            a3 >>= 1;
        }
      }
    }
    result = a3;
  }
  else
  {
    result = 0;
  }
  return result;
}

//----- (00427662) --------------------------------------------------------
bool stru319::GetMagicalResistance(Actor *pActor, unsigned int uType)
{
  Actor *v3; // edi@2
  signed int v4; // esi@2
  bool result; // eax@13

  switch ( uType )
  {
    case 0u:
      v3 = pActor;
      v4 = pActor->pMonsterInfo.uResFire;
      goto LABEL_12;
    case 1u:
      v3 = pActor;
      v4 = pActor->pMonsterInfo.uResAir;
      goto LABEL_12;
    case 2u:
      v3 = pActor;
      v4 = pActor->pMonsterInfo.uResWater;
      goto LABEL_12;
    case 3u:
      v3 = pActor;
      v4 = pActor->pMonsterInfo.uResEarth;
      goto LABEL_12;
    case 7u:
      v3 = pActor;
      v4 = pActor->pMonsterInfo.uResMind;
      goto LABEL_12;
    case 6u:
      v3 = pActor;
      v4 = pActor->pMonsterInfo.uResSpirit;
      goto LABEL_12;
    case 8u:
      v3 = pActor;
      v4 = pActor->pMonsterInfo.uResBody;
      goto LABEL_12;
    case 9u:
      v3 = pActor;
      v4 = pActor->pMonsterInfo.uResLight;
      goto LABEL_12;
    case 0xAu:
      v3 = pActor;
      v4 = pActor->pMonsterInfo.uResDark;
      goto LABEL_12;
    case 4u:
      v3 = pActor;
      v4 = pActor->pMonsterInfo.uResPhysical;
LABEL_12:
      if ( v4 < 200 )
        result = rand() % (signed int)(((unsigned int)v3->pMonsterInfo.uLevel >> 2) + v4 + 30) < 30;
      else
        result = 0;
      break;
    default:
      result = 1;
      break;
  }
  return result;
}


//----- (00427769) --------------------------------------------------------
bool __fastcall sub_427769_spell(unsigned int uSpellID)
{
  bool result; // eax@2

  if ( *(&pSpellDatas[0].field_12 + 20 * uSpellID) & 0xC )
    result = 1;
  else
    result = 0;
  return result;
}

//----- (0042777D) --------------------------------------------------------
bool __fastcall _42777D_CastSpell_UseWand_ShootArrow(int a1, unsigned int uPlayerID, unsigned int a4, __int16 a5, int a6)
{
  bool result; // eax@2
  __int16 v6; // bx@4
  Player *v7; // eax@4
  char v8; // zf@12
  unsigned __int16 v9; // cx@16
  unsigned int v10; // eax@18
  unsigned __int8 v11; // sf@18
  unsigned __int8 v12; // of@18
  unsigned __int16 v13; // cx@21
  unsigned int v14; // eax@23
  stru277 *v15; // esi@27
  stru277 *v16; // eax@28
  GUIWindow *v17; // eax@43
  GUIWindow *v18; // [sp-30h] [bp-48h]@44
  unsigned int v19; // [sp-2Ch] [bp-44h]@44
  unsigned int v20; // [sp-28h] [bp-40h]@44
  unsigned int v21; // [sp-24h] [bp-3Ch]@44
  unsigned int v22; // [sp-20h] [bp-38h]@44
  int v23; // [sp-1Ch] [bp-34h]@44
  int v24; // [sp-18h] [bp-30h]@44
  unsigned int v25; // [sp-14h] [bp-2Ch]@43
  unsigned int v26; // [sp-10h] [bp-28h]@43
  unsigned __int8 v27; // [sp-Ch] [bp-24h]@43
  char *v28; // [sp-8h] [bp-20h]@43
  Texture *v29; // [sp-4h] [bp-1Ch]@43
  __int16 a3a; // [sp+10h] [bp-8h]@1
  __int16 a2a; // [sp+14h] [bp-4h]@1

  a3a = uPlayerID;
  a2a = a1;
  if ( pParty->bTurnBasedModeOn != 1
    || (result = pTurnEngine->field_4, pTurnEngine->field_4 != 1) && pTurnEngine->field_4 != 3 )
  {
    v6 = a5;
    v7 = &pParty->pPlayers[uPlayerID];
    if ( !(a5 & 0x10) )
    {
      switch ( a1 )
      {
        case 47:
        case 68:
        case 89:
          HIBYTE(v6) = HIBYTE(a5) | 1;
          break;
        case 4:
        case 28:
        case 30:
        case 91:
          LOBYTE(v6) = a5 | 0x80;
          break;
        case 2:
        case 6:
        case 11:
        case 18:
        case 20:
        case 24:
        case 26:
        case 29:
        case 32:
        case 34:
        case 35:
        case 37:
        case 39:
        case 44:
        case 52:
        case 57:
        case 60:
        case 65:
        case 70:
        case 76:
        case 78:
        case 79:
        case 87:
        case 90:
        case 92:
        case 93:
        case 97:
          if ( !a6 )
            goto LABEL_9;
          break;
        case 59:
        case 62:
        case 66:
        case 81:
        case 94:
LABEL_9:
          v6 = a5 | 8;
          break;
        case 42:
          v6 = a5 | 0x40;
          break;
        case 46:
          if ( a4 )
            v8 = (a4 & 0x1C0) == 0;
          else
            v8 = (v7->pActiveSkills[16] & 0x1C0) == 0;
          if ( v8 )
            goto LABEL_25;
          break;
        case 50:
          v9 = a4;
          if ( !a4 )
            v9 = v7->pActiveSkills[16];
          goto LABEL_18;
        case 95:
          v9 = a4;
          if ( !a4 )
            v9 = v7->pActiveSkills[20];
LABEL_18:
          v10 = SkillToMastery(v9);
          v12 = __OFSUB__(v10, 3);
          v11 = ((v10 - 3) & 0x80000000u) != 0;
          goto LABEL_24;
        case 73:
          v13 = a4;
          if ( !a4 )
            v13 = v7->pActiveSkills[18];
          v14 = SkillToMastery(v13);
          v12 = __OFSUB__(v14, 4);
          v11 = ((v14 - 4) & 0x80000000u) != 0;
LABEL_24:
          if ( v11 ^ v12 )
            goto LABEL_25;
          break;
        case 40:
        case 49:
        case 53:
        case 55:
        case 56:
        case 61:
        case 64:
        case 67:
        case 71:
        case 72:
        case 74:
LABEL_25:
          v6 = a5 | 2;
          break;
        case 96:
          HIBYTE(v6) = HIBYTE(a5) | 2;
          break;
        default:
          break;
      }
    }
    v15 = pStru277;
    if ( v6 & 0x3CA )
    {
      v16 = pStru277;
      while ( !(v16->field_8 & 0x3CA) )
      {
        ++v16;
        if ( (signed int)v16 >= (signed int)&unk_50C190 )
          goto LABEL_33;
      }
      v16->spellnum = 0;
    }
    do
    {
LABEL_33:
      if ( v15->spellnum )
      {
        v8 = (v15->field_8 & 0x3CA) == 0;
        v15->spellnum = 0;
        if ( !v8 )
        {
          ptr_507BD4->Release();
          ptr_507BD4 = 0;
          pMouse->SetCursorBitmap("MICON1");
          GameUI_StatusBar_TimedStringTimeLeft = 0;
          unk_50C9A0 = 0;
          back_to_game();
        }
      }
      ++v15;
    }
    while ( (signed int)v15 < (signed int)&unk_50C190 );
    result = pStru277->PushStru277(a2a, a3a, a4, v6, a6);
    if ( result != -1 )
    {
      if ( v6 & 2 )
      {
        if ( ptr_507BD4 )
          return result;
        ptr_507BD4 = GUIWindow::Create(0, 0, 640, 480, (WindowType)(WINDOW_HouseInterior|0x2), (int)&pStru277[result], 0);
        ptr_507BD4->CreateButton(0x34u, 0x1A6u, 0x23u, 0, 2, 0, 0x45u, 0, 0x31u, "", 0);
        ptr_507BD4->CreateButton(0xA5u, 0x1A6u, 0x23u, 0, 2, 0, 0x45u, 1u, 0x32u, "", 0);
        ptr_507BD4->CreateButton(0x118u, 0x1A6u, 0x23u, 0, 2, 0, 0x45u, 2u, 0x33u, "", 0);
        ptr_507BD4->CreateButton(0x186u, 0x1A6u, 0x23u, 0, 2, 0, 0x45u, 3u, 0x34u, "", 0);
        return sub_421B2C_PlaceInInventory_or_DropPickedItem();
      }
      if ( v6 & 8 )
      {
        if ( ptr_507BD4 )
          return result;
        v17 = GUIWindow::Create(0, 0, 640, 480, (WindowType)(WINDOW_HouseInterior|0x2), (int)&pStru277[result], 0);
        v29 = 0;
        v28 = "";
        v27 = 0;
        v26 = 0;
        v25 = 70;
LABEL_44:
        v24 = 0;
        v23 = 1;
        v22 = 344;
        v21 = 460;
        v20 = 8;
        v19 = 8;
        ptr_507BD4 = v17;
        v18 = v17;
LABEL_56:
        v18->CreateButton(v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29);
        return sub_421B2C_PlaceInInventory_or_DropPickedItem();
      }
      if ( v6 & 0x40 )
      {
        if ( ptr_507BD4 )
          return result;
        v17 = GUIWindow::Create(0, 0, 640, 480, (WindowType)(WINDOW_HouseInterior|0x2), (int)&pStru277[result], 0);
        v29 = 0;
        v28 = "";
        v27 = 0;
        v26 = 0;
        v25 = 190;
        goto LABEL_44;
      }
      if ( (char)v6 < 0 )
      {
        if ( ptr_507BD4 )
          return result;
        ++pIcons_LOD->uTexturePacksCount;
        if ( !pIcons_LOD->uNumPrevLoadedFiles )
          pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
        ptr_507BD4 = pStru277[result].sub_4219BE();
        unk_50C9A0 = 1;
        some_active_character = uActiveCharacter;
        return sub_421B2C_PlaceInInventory_or_DropPickedItem();
      }
      if ( HIBYTE(v6) & 1 )
      {
        if ( ptr_507BD4 )
          return result;
        ptr_507BD4 = GUIWindow::Create(0, 0, 640, 480, (WindowType)(WINDOW_HouseInterior|0x2), 20 * result + 5292232, 0);
        ptr_507BD4->CreateButton(0x34u, 0x1A6u, 0x23u, 0, 2, 0, 0x8Du, 0, 0x31u, "", 0);
        ptr_507BD4->CreateButton(0xA5u, 0x1A6u, 0x23u, 0, 2, 0, 0x8Du, 1u, 0x32u, "", 0);
        ptr_507BD4->CreateButton(0x118u, 0x1A6u, 0x23u, 0, 2, 0, 0x8Du, 2u, 0x33u, "", 0);
        ptr_507BD4->CreateButton(0x186u, 0x1A6u, 0x23u, 0, 2, 0, 0x8Du, 3u, 0x34u, "", 0);
        v29 = 0;
        v28 = "";
        v27 = 0;
        v26 = 0;
        v25 = 140;
        v24 = 0;
        v23 = 1;
        v22 = 344;
        v21 = 460;
        v20 = 8;
        v19 = 8;
        v18 = ptr_507BD4;
        goto LABEL_56;
      }
      if ( HIBYTE(v6) & 2 && !ptr_507BD4 )
      {
        ptr_507BD4 = GUIWindow::Create(0, 0, 640, 480, (WindowType)(WINDOW_HouseInterior|0x2), 20 * result + 5292232, 0);
        ptr_5079EC = ptr_507BD4->CreateButton(
                       0x1D5u,
                       0xB2u,
                       (uTextureID_507990 != -1 ? pIcons_LOD->pTextures[uTextureID_507990].uTextureWidth : 24),
                       (uTextureID_507990 != -1 ? pIcons_LOD->pTextures[uTextureID_507990].uTextureHeight : 26),
                       1,
                       0,
                       0xBCu,
                       0,
                       0,
                       "",
                       (Texture *)(uTextureID_507990 != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_507990] : 0),
                       0);
        ptr_5079E8 = ptr_507BD4->CreateButton(
                       0x272u,
                       0xB2u,
                       (uTextureID_50798C != -1 ? pIcons_LOD->pTextures[uTextureID_50798C].uTextureWidth : 24),
                       (uTextureID_50798C != -1 ? pIcons_LOD->pTextures[uTextureID_50798C].uTextureHeight : 26),
                       1,
                       0,
                       0xBCu,
                       1u,
                       0,
                       "",
                       (Texture *)(uTextureID_50798C != -1 ? (int)&pIcons_LOD->pTextures[uTextureID_50798C] : 0),
                       0);
        ptr_507BD4->CreateButton(0x1EBu, 0x95u, 0x40u, 0x4Au, 1, 0, 0x8Fu, 4u, 0x35u, "", 0);
        result = (bool)ptr_507BD4->CreateButton(
                         0x231u,
                         0x95u,
                         0x40u,
                         0x4Au,
                         1,
                         0,
                         0x8Fu,
                         5u,
                         0x36u,
                         "",
                         0);
      }
    }
  }
  return result;
}



//----- (00427D48) --------------------------------------------------------
void stru277::_427D48(unsigned int uPlayerID)
{
  stru277 *v2; // esi@1
  signed int v3; // ebx@1

  v2 = this;
  v3 = 10;
  do
  {
    if ( v2->spellnum )
    {
      if ( v2->field_8 & 0x3CA )
      {
        v2->spellnum = 0;
        ptr_507BD4->Release();
        ptr_507BD4 = 0;
        pMouse->SetCursorBitmap("MICON1");
        GameUI_StatusBar_TimedStringTimeLeft = 0;
        unk_50C9A0 = 0;
        back_to_game();
      }
    }
    ++v2;
    --v3;
  }
  while ( v3 );
}

//----- (00427DA0) --------------------------------------------------------
unsigned int stru277::PushStru277(__int16 a2, __int16 uPlayerID, __int16 a4, __int16 a5, int a6)
{
  unsigned int result; // eax@1
  stru277 *v7; // edx@1
  stru277 *v8; // ecx@5

  result = 0;
  v7 = this;
  while ( v7->spellnum )
  {
    ++result;
    ++v7;
    if ( (signed int)result >= 10 )
      goto LABEL_8;
  }
  v8 = &this[result];
  v8->spellnum = a2;
  v8->uPlayerID = uPlayerID;
  if ( a5 & 0x10 )
    v8->uPlayerID_2 = uPlayerID;
  v8->field_6 = 0;
  *(int *)&v8->field_C = 0;
  v8->field_8 = a5;
  v8->field_A = a4;
  v8->field_10 = a6;
LABEL_8:
  if ( result == 10 )
    result = -1;
  return result;
}

//----- (00427E01) --------------------------------------------------------
void stru277::_427E01_cast_spell()
{
  int v1; // esi@1
  int v2; // edi@1
  stru277 *v3; // ebx@2
  signed int v4; // eax@8
  __int16 v5; // ax@9
  signed int v6; // eax@14
  __int16 v7; // ax@23
  __int16 v8; // ax@24
  char v9; // al@44
  int v10; // eax@45
  unsigned __int16 v11; // cx@45
  signed int v12; // ecx@48
  int v13; // eax@53
  unsigned __int8 v14; // zf@53
  unsigned int v15; // edx@53
  signed int v16; // eax@53
  Player *v17; // esi@70
  int v18; // eax@72
  int v19; // eax@74
  char *v20; // eax@74
  signed int i; // esi@76
  int v22; // eax@88
  __int16 v23; // ax@88
  int v24; // ecx@93
  int v25; // ecx@94
  signed __int64 v26; // qax@100
  char *v27; // ecx@100
  unsigned __int64 v28; // qax@102
  int v29; // ecx@105
  int v30; // ecx@106
  int v31; // eax@112
  int v32; // eax@112
  char *v33; // edx@113
  int v34; // eax@121
  int v35; // eax@123
  int v36; // edx@125
  int v37; // eax@129
  signed int v38; // edi@129
  signed int v39; // eax@129
  int v40; // ecx@129
  int v41; // eax@129
  signed int v42; // eax@129
  int *v43; // ecx@129
  int v44; // eax@132
  int v45; // ecx@132
  int v46; // eax@132
  unsigned int v47; // edx@133
  int v48; // eax@137
  int v49; // eax@137
  int v50; // eax@141
  int v51; // eax@146
  __int16 v52; // ax@153
  int v53; // eax@153
  signed __int64 v54; // qax@164
  int v55; // edi@164
  stru6 *v56; // eax@165
  int v57; // eax@169
  signed __int64 v58; // qax@177
  int v59; // edi@177
  unsigned __int16 v60; // ax@184
  int v61; // ecx@184
  int v62; // eax@186
  int v63; // ecx@187
  int v64; // ecx@188
  int v65; // ecx@189
  const char *v66; // ecx@200
  unsigned int v67; // edx@201
  char v68; // al@207
  int v69; // esi@211
  int v70; // ecx@214
  int v71; // ecx@215
  int v72; // ecx@216
  __int16 v73; // ST1C_2@222
  __int16 v74; // ST18_2@222
  stru6 *v75; // eax@222
  int v76; // ecx@223
  int v77; // ecx@224
  int v78; // ecx@225
  int v79; // eax@227
  int v80; // eax@232
  __int16 v81; // ST18_2@245
  stru6 *v82; // eax@245
  signed int v83; // edi@245
  __int16 v84; // ST18_2@245
  stru6 *v85; // eax@245
  __int16 v86; // ST18_2@245
  stru6 *v87; // eax@245
  __int16 v88; // ST18_2@245
  stru6 *v89; // eax@245
  double v90; // st7@245
  int v91; // eax@250
  char *v92; // eax@255
  __int16 v93; // ST18_2@260
  stru6 *v94; // eax@260
  __int16 v95; // ST18_2@260
  stru6 *v96; // eax@260
  __int16 v97; // ST18_2@260
  stru6 *v98; // eax@260
  __int16 v99; // ST18_2@260
  stru6 *v100; // eax@260
  int v101; // ecx@261
  int v102; // ecx@262
  int v103; // ecx@263
  int v104; // eax@265
  int v105; // edi@271
  __int16 v106; // ST18_2@272
  stru6 *v107; // eax@272
  __int16 v108; // ST1C_2@274
  __int16 v109; // ST18_2@274
  stru6 *v110; // eax@274
  int v111; // eax@274
  Actor *v112; // esi@278
  int v113; // eax@278
  int v114; // ebx@278
  unsigned int v115; // ecx@278
  int v116; // edx@279
  int v117; // edx@281
  int v118; // edx@283
  int v119; // edi@286
  int v120; // eax@286
  int v121; // eax@286
  signed int v122; // eax@286
  int v123; // ecx@288
  int v124; // ecx@289
  int v125; // ecx@290
  int v126; // eax@292
  int v127; // eax@296
  __int16 v128; // ST18_2@303
  stru6 *v129; // eax@303
  __int16 v130; // ST18_2@303
  stru6 *v131; // eax@303
  __int16 v132; // ST18_2@303
  stru6 *v133; // eax@303
  __int16 v134; // ST18_2@303
  stru6 *v135; // eax@303
  unsigned __int64 v136; // qax@304
  char *v137; // ecx@304
  int v138; // ecx@305
  int v139; // ecx@306
  int v140; // eax@308
  __int16 v141; // ST18_2@311
  stru6 *v142; // eax@311
  __int16 v143; // ST18_2@311
  stru6 *v144; // eax@311
  __int16 v145; // ST18_2@311
  stru6 *v146; // eax@311
  __int16 v147; // ST18_2@311
  stru6 *v148; // eax@311
  int v149; // ecx@312
  int v150; // ecx@313
  int v151; // ecx@314
  signed int v152; // eax@322
  int v153; // ecx@322
  int v154; // eax@322
  int v155; // eax@323
  int v156; // eax@323
  int v157; // eax@326
  double v158; // st7@326
  double v159; // st6@326
  signed __int64 v160; // qtt@334
  int v161; // eax@339
  int v162; // edi@340
  int v163; // eax@340
  signed int v164; // eax@340
  signed int v165; // edi@340
  stru6 *v166; // eax@340
  stru6 *v167; // eax@340
  signed int v168; // edi@343
  int v169; // eax@344
  int v170; // ecx@346
  int v171; // ecx@347
  int v172; // ecx@348
  int v173; // edi@350
  signed int v174; // edi@355
  __int16 v175; // ST18_2@357
  stru6 *v176; // eax@357
  __int16 v177; // ST18_2@357
  stru6 *v178; // eax@357
  __int16 v179; // ST18_2@357
  stru6 *v180; // eax@357
  __int16 v181; // ST18_2@357
  stru6 *v182; // eax@357
  signed __int64 v183; // qax@357
  int v184; // ecx@358
  int v185; // ecx@359
  int v186; // ecx@360
  int v187; // eax@367
  int v188; // esi@369
  int v189; // edi@369
  const char *v190; // ecx@377
  signed int v191; // edi@379
  int v192; // ecx@382
  int v193; // ecx@383
  int v194; // ecx@384
  int v195; // eax@386
  int v196; // eax@387
  __int16 v197; // ST18_2@395
  stru6 *v198; // eax@395
  __int16 v199; // ST18_2@395
  stru6 *v200; // eax@395
  __int16 v201; // ST18_2@395
  stru6 *v202; // eax@395
  __int16 v203; // ST18_2@395
  stru6 *v204; // eax@395
  signed int v205; // edi@405
  int v206; // eax@407
  __int16 v207; // cx@407
  int v208; // eax@411
  signed int v209; // ecx@412
  int v210; // edx@412
  signed int v211; // ecx@412
  int v212; // eax@413
  int v213; // eax@413
  int v214; // eax@413
  int v215; // eax@415
  double v216; // st7@415
  double v217; // st6@415
  signed __int64 v218; // qtt@423
  int v219; // ecx@425
  int v220; // ecx@426
  int v221; // edi@428
  char *v222; // edi@434
  char v223; // al@438
  int v224; // ecx@442
  int v225; // ecx@443
  int v226; // eax@451
  int v227; // esi@453
  unsigned int v228; // edi@454
  int v229; // edi@466
  __int16 v230; // ST18_2@469
  stru6 *v231; // eax@469
  signed int v232; // esi@469
  __int16 v233; // ST18_2@469
  stru6 *v234; // eax@469
  __int16 v235; // ST18_2@469
  stru6 *v236; // eax@469
  __int16 v237; // ST18_2@469
  stru6 *v238; // eax@469
  __int16 v239; // ST1C_2@469
  char *v240; // ecx@472
  double v241; // st7@478
  signed __int64 v242; // qax@484
  char *v243; // ecx@484
  char *v244; // eax@488
  int v245; // edi@492
  int v246; // eax@492
  char *v247; // eax@497
  char v248; // al@497
  char v249; // cf@500
  float v250; // esi@507
  char v251; // al@507
  int v252; // edx@510
  int m; // esi@510
  int v254; // eax@513
  int v255; // esi@513
  int v256; // ecx@513
  int v257; // edx@514
  int v258; // ecx@514
  char v259; // al@516
  int v260; // eax@518
  int v261; // esi@519
  int v262; // edx@521
  int v263; // ecx@521
  int v264; // esi@521
  int v265; // edx@521
  int *ii; // eax@522
  int v267; // eax@524
  int v268; // eax@524
  int v269; // eax@526
  char *v270; // eax@531
  char v271; // al@531
  char v272; // cf@534
  float v273; // esi@541
  char v274; // al@541
  int v275; // edx@544
  int k; // esi@544
  int v277; // edx@548
  int v278; // ecx@548
  char v279; // al@550
  int v280; // eax@552
  int v281; // esi@553
  int v282; // edx@555
  int v283; // ecx@555
  int v284; // esi@555
  int v285; // edx@555
  int *l; // eax@556
  int v287; // eax@558
  int v288; // eax@558
  ItemGen *v289; // eax@560
  signed int v290; // eax@560
  unsigned __int8 v291; // al@564
  char v292; // al@573
  int v293; // eax@575
  ItemGen *v294; // esi@575
  int v295; // edx@575
  int kk; // edi@575
  int v297; // edx@579
  int v298; // ecx@579
  char v299; // al@581
  int v300; // eax@583
  int v301; // edi@584
  int v302; // edx@586
  int v303; // ecx@586
  int v304; // edi@586
  int v305; // edx@586
  int *jj; // eax@587
  int v307; // eax@589
  int v308; // eax@589
  char *v309; // ecx@593
  char v310; // sf@593
  unsigned __int8 v311; // of@593
  char v312; // cl@597
  char v313; // al@606
  int v314; // edx@607
  int j; // esi@607
  unsigned int v316; // eax@613
  const char *v317; // ecx@617
  Player *v318; // ecx@619
  unsigned int v319; // edi@627
  int v320; // ecx@629
  int v321; // ecx@630
  int v322; // edi@632
  int v323; // edi@635
  char *v324; // eax@635
  Player *v325; // ecx@640
  int v326; // eax@643
  int v327; // eax@648
  int v328; // ecx@651
  int v329; // ecx@652
  int v330; // edi@654
  __int16 v331; // ST18_2@658
  stru6 *v332; // eax@658
  __int16 v333; // ST18_2@658
  stru6 *v334; // eax@658
  __int16 v335; // ST18_2@658
  stru6 *v336; // eax@658
  __int16 v337; // ST18_2@658
  stru6 *v338; // eax@658
  int v339; // ecx@659
  int v340; // ecx@660
  int v341; // eax@663
  signed int v342; // edi@668
  signed int v343; // edi@670
  unsigned __int64 v344; // ST08_8@670
  __int16 v345; // ST1C_2@671
  __int16 v346; // ST18_2@671
  stru6 *v347; // eax@671
  int v348; // ecx@672
  int v349; // ecx@673
  int v350; // edi@676
  Player *v351; // edi@680
  __int16 v352; // ST18_2@685
  stru6 *v353; // eax@685
  int v354; // ecx@686
  int v355; // ecx@687
  int v356; // eax@689
  SpellBuff *v357; // edi@694
  unsigned __int16 v358; // ST1C_2@695
  __int16 v359; // ST18_2@695
  stru6 *v360; // eax@695
  __int16 v361; // ST1C_2@697
  __int16 v362; // ST18_2@697
  stru6 *v363; // eax@697
  int v364; // ecx@698
  int v365; // ecx@699
  int v366; // eax@701
  stru6 *v367; // eax@704
  int v368; // eax@704
  Actor *v369; // edi@705
  int v370; // eax@706
  int v371; // ecx@709
  int v372; // ecx@710
  int v373; // eax@715
  int v374; // eax@717
  char *v375; // edi@717
  int v376; // eax@717
  Player *v377; // ecx@719
  int v378; // ecx@721
  int v379; // ecx@722
  int v380; // eax@724
  int v381; // edi@727
  int v382; // ecx@727
  Player *v383; // eax@728
  int v384; // eax@733
  int v385; // edi@736
  signed int v386; // eax@736
  Player *v387; // edi@738
  int v388; // edi@740
  unsigned __int16 v389; // ST1C_2@740
  __int16 v390; // ST18_2@740
  stru6 *v391; // eax@740
  int v392; // ecx@742
  int v393; // ecx@743
  int v394; // ecx@744
  int v395; // edi@747
  int v396; // eax@752
  int v397; // eax@757
  int v398; // eax@757
  int v399; // eax@757
  char *v400; // esi@757
  Game *v401; // ecx@759
  __int16 v402; // ST1C_2@759
  __int16 v403; // ST18_2@759
  stru6 *v404; // eax@759
  int v405; // ecx@761
  int v406; // ecx@762
  int v407; // edi@765
  __int16 v408; // ST1C_2@769
  __int16 v409; // ST18_2@769
  stru6 *v410; // eax@769
  int v411; // ecx@772
  int v412; // ecx@773
  int v413; // edi@775
  __int16 v414; // ST1C_2@781
  __int16 v415; // ST18_2@781
  stru6 *v416; // eax@781
  int v417; // eax@787
  int v418; // ecx@789
  __int16 v419; // ax@791
  signed int v420; // eax@793
  int v421; // edx@793
  const char *v422; // eax@801
  int v423; // ecx@808
  int v424; // ecx@809
  int v425; // eax@811
  signed int v426; // eax@815
  signed int v427; // eax@820
  int v428; // ecx@825
  int v429; // ecx@826
  int v430; // eax@828
  stru6 *v431; // eax@831
  int v432; // eax@831
  Actor *v433; // edi@832
  int v434; // eax@833
  int v435; // ecx@837
  int v436; // ecx@838
  __int16 v437; // ST1C_2@843
  __int16 v438; // ST18_2@843
  stru6 *v439; // eax@843
  int v440; // eax@843
  int v441; // eax@847
  int v442; // ecx@850
  int v443; // ecx@851
  int v444; // eax@853
  signed int v445; // edi@857
  int v446; // ecx@862
  LevelDecoration *v447; // edi@864
  __int16 v448; // ax@864
  char *v449; // esi@870
  int v450; // eax@870
  int v451; // ecx@875
  int v452; // ecx@876
  int v453; // edi@878
  __int16 v454; // ST1C_2@884
  __int16 v455; // ST18_2@884
  stru6 *v456; // eax@884
  int v457; // ecx@887
  int v458; // ecx@888
  int v459; // eax@890
  signed int v460; // eax@895
  Actor *v461; // eax@897
  unsigned __int16 v462; // cx@897
  signed int v463; // edx@897
  int v464; // ecx@905
  int v465; // ecx@906
  int v466; // edi@909
  __int16 v467; // ST1C_2@913
  __int16 v468; // ST18_2@913
  stru6 *v469; // eax@913
  int v470; // edi@913
  int v471; // eax@917
  int v472; // eax@917
  char *v473; // esi@918
  __int16 v474; // ST18_2@920
  stru6 *v475; // eax@920
  __int16 v476; // ST18_2@920
  stru6 *v477; // eax@920
  __int16 v478; // ST18_2@920
  stru6 *v479; // eax@920
  __int16 v480; // ST18_2@920
  stru6 *v481; // eax@920
  __int16 v482; // ST18_2@923
  stru6 *v483; // eax@923
  __int16 v484; // ST18_2@923
  stru6 *v485; // eax@923
  __int16 v486; // ST18_2@923
  stru6 *v487; // eax@923
  __int16 v488; // ST18_2@923
  stru6 *v489; // eax@923
  __int16 v490; // ST1C_2@924
  __int16 v491; // ST18_2@924
  stru6 *v492; // eax@924
  int v493; // ecx@925
  int v494; // ecx@926
  __int16 v495; // ST1C_2@931
  __int16 v496; // ST18_2@931
  stru6 *v497; // eax@931
  int v498; // edi@931
  int v499; // eax@935
  int v500; // eax@935
  Player *v501; // edi@939
  __int16 v502; // ST18_2@940
  stru6 *v503; // eax@940
  stru6 *v504; // eax@943
  int v505; // eax@943
  int v506; // eax@943
  int v507; // edi@944
  int v508; // eax@944
  signed int v509; // eax@944
  signed int v510; // edi@944
  Actor *v511; // edi@946
  int v512; // eax@946
  SpellBuff *v513; // edi@946
  int v514; // ecx@950
  int v515; // ecx@951
  int v516; // eax@953
  int v517; // eax@956
  char *v518; // edx@957
  __int16 v519; // cx@958
  int v520; // ecx@968
  int v521; // ecx@969
  int v522; // eax@971
  __int16 v523; // ST18_2@975
  stru6 *v524; // eax@975
  __int16 v525; // ST18_2@975
  stru6 *v526; // eax@975
  __int16 v527; // ST18_2@975
  stru6 *v528; // eax@975
  __int16 v529; // ST18_2@975
  stru6 *v530; // eax@975
  int v531; // eax@982
  int v532; // eax@982
  int v533; // edi@983
  int v534; // eax@983
  signed int v535; // eax@983
  signed int v536; // edi@983
  stru6 *v537; // eax@984
  int v538; // ecx@985
  int v539; // ecx@986
  int v540; // eax@988
  __int16 v541; // ST18_2@991
  stru6 *v542; // eax@991
  __int16 v543; // ST18_2@991
  stru6 *v544; // eax@991
  __int16 v545; // ST18_2@991
  stru6 *v546; // eax@991
  __int16 v547; // ST18_2@991
  stru6 *v548; // eax@991
  double v549; // st7@991
  unsigned __int16 v550; // di@991
  int v551; // ecx@993
  int v552; // ecx@994
  char *v553; // edi@1001
  __int16 v554; // ST18_2@1002
  stru6 *v555; // eax@1002
  __int16 v556; // ST18_2@1002
  stru6 *v557; // eax@1002
  __int16 v558; // ST18_2@1002
  stru6 *v559; // eax@1002
  __int16 v560; // ST18_2@1002
  stru6 *v561; // eax@1002
  unsigned __int16 v562; // di@1005
  signed int v563; // eax@1010
  unsigned int v564; // ecx@1011
  signed int v565; // eax@1012
  Player **v566; // ecx@1012
  int v567; // eax@1012
  unsigned __int16 v568; // ST1C_2@1012
  __int16 v569; // ST18_2@1012
  stru6 *v570; // eax@1012
  Player *v571; // eax@1013
  char *v572; // ecx@1013
  int v573; // ecx@1017
  int v574; // ecx@1018
  int v575; // eax@1020
  signed int v576; // eax@1025
  Player *v577; // eax@1026
  int v578; // eax@1028
  __int16 v579; // ax@1029
  int v580; // eax@1031
  int v581; // edi@1031
  int v582; // eax@1031
  __int16 v583; // ST1C_2@1034
  __int16 v584; // ST18_2@1034
  char *v585; // esi@1034
  stru6 *v586; // eax@1034
  signed int v587; // eax@1035
  int v588; // ecx@1036
  int v589; // ecx@1037
  int v590; // ecx@1038
  char v591; // al@1048
  int v592; // esi@1052
  int v593; // ecx@1057
  int v594; // ecx@1058
  int v595; // eax@1064
  int v596; // esi@1066
  unsigned int v597; // edi@1067
  int v598; // eax@1079
  signed int v599; // eax@1082
  int v600; // edi@1086
  int v601; // edx@1086
  int v602; // eax@1086
  int v603; // ecx@1086
  int v604; // eax@1087
  char *v605; // eax@1089
  int v606; // edx@1091
  int v607; // ecx@1100
  __int16 v608; // ax@1102
  signed int v609; // eax@1104
  int v610; // edi@1106
  unsigned int v611; // eax@1106
  char *v612; // edi@1106
  char *v613; // eax@1108
  int v614; // eax@1116
  int v615; // edi@1119
  __int16 v616; // ST1C_2@1122
  __int16 v617; // ST18_2@1122
  stru6 *v618; // eax@1122
  SpellBuff *v619; // edi@1123
  unsigned __int16 v620; // ST1C_2@1124
  __int16 v621; // ST18_2@1124
  stru6 *v622; // eax@1124
  signed __int64 v623; // qax@1127
  int v624; // eax@1127
  int v625; // edi@1129
  int v626; // eax@1129
  signed int v627; // eax@1129
  signed int v628; // edi@1129
  int v629; // ecx@1130
  Player *v630; // eax@1131
  int v631; // eax@1137
  int v632; // edi@1140
  Player *v633; // eax@1140
  signed int v634; // eax@1140
  int v635; // edi@1142
  unsigned __int16 v636; // ST1C_2@1142
  __int16 v637; // ST18_2@1142
  stru6 *v638; // eax@1142
  stru6 *v639; // eax@1143
  int v640; // ecx@1146
  int v641; // ecx@1147
  int v642; // edi@1156
  int v643; // eax@1156
  int v644; // eax@1156
  signed int v645; // eax@1158
  Player *v646; // ebx@1169
  int v647; // edi@1169
  signed int v648; // ST1C_4@1170
  Player *v649; // ecx@1170
  unsigned __int64 v650; // [sp-10h] [bp-E94h]@103
  unsigned __int16 v651; // [sp-8h] [bp-E8Ch]@100
  unsigned __int16 v652; // [sp-8h] [bp-E8Ch]@304
  unsigned __int16 v653; // [sp-4h] [bp-E88h]@100
  int v654; // [sp-4h] [bp-E88h]@124
  unsigned __int16 v655; // [sp-4h] [bp-E88h]@304
  unsigned int v656; // [sp-4h] [bp-E88h]@639
  int v657; // [sp-4h] [bp-E88h]@807
  int v658; // [sp+0h] [bp-E84h]@100
  int v659; // [sp+0h] [bp-E84h]@123
  int v660; // [sp+0h] [bp-E84h]@146
  Actor *v661; // [sp+0h] [bp-E84h]@164
  int v662; // [sp+0h] [bp-E84h]@304
  unsigned __int64 v663; // [sp+0h] [bp-E84h]@639
  const char *v664; // [sp+0h] [bp-E84h]@802
  int v665; // [sp+0h] [bp-E84h]@807
  int v666; // [sp+4h] [bp-E80h]@12
  enum PLAYER_SKILL_TYPE v667; // [sp+4h] [bp-E80h]@25
  unsigned __int8 v668; // [sp+4h] [bp-E80h]@100
  int v669; // [sp+4h] [bp-E80h]@123
  Vec3_int_ *v670; // [sp+4h] [bp-E80h]@133
  int v671; // [sp+4h] [bp-E80h]@146
  unsigned int v672; // [sp+4h] [bp-E80h]@164
  unsigned __int8 v673; // [sp+4h] [bp-E80h]@304
  __int16 v674; // [sp+4h] [bp-E80h]@684
  const char *v675; // [sp+4h] [bp-E80h]@800
  int v676; // [sp+4h] [bp-E80h]@807
  int v677; // [sp+4h] [bp-E80h]@861
  int v678; // [sp+4h] [bp-E80h]@997
  int v679; // [sp+14h] [bp-E70h]@515
  AIDirection a3; // [sp+C94h] [bp-1F0h]@21
  int v681[4]; // [sp+CB0h] [bp-1D4h]@1137
  int v682[4]; // [sp+CC0h] [bp-1C4h]@731
  ItemGen v683; // [sp+CD0h] [bp-1B4h]@791
  int v684; // [sp+D04h] [bp-180h]@416
  unsigned __int64 v685; // [sp+D08h] [bp-17Ch]@416
  int x; // [sp+D20h] [bp-164h]@327
  unsigned __int64 v687; // [sp+D24h] [bp-160h]@327
  int v688; // [sp+D2Ch] [bp-158h]@943
  int v689; // [sp+D30h] [bp-154h]@943
  int v690; // [sp+D34h] [bp-150h]@943
  int v691; // [sp+D38h] [bp-14Ch]@137
  int v692; // [sp+D3Ch] [bp-148h]@137
  int v693; // [sp+D40h] [bp-144h]@137
  int v694; // [sp+D44h] [bp-140h]@982
  int v695; // [sp+D48h] [bp-13Ch]@982
  int v696; // [sp+D4Ch] [bp-138h]@982
  int v697; // [sp+D50h] [bp-134h]@129
  int v698; // [sp+D54h] [bp-130h]@129
  int v699; // [sp+D58h] [bp-12Ch]@129
  Vec3_int_ v700; // [sp+D5Ch] [bp-128h]@339
  int v701; // [sp+D68h] [bp-11Ch]@286
  int v702; // [sp+D6Ch] [bp-118h]@286
  int v703; // [sp+D70h] [bp-114h]@286
  int v704; // [sp+D74h] [bp-110h]@132
  int v705; // [sp+D78h] [bp-10Ch]@132
  int v706; // [sp+D7Ch] [bp-108h]@132
  int v707; // [sp+D80h] [bp-104h]@1127
  int v708; // [sp+D84h] [bp-100h]@1127
  int v709; // [sp+D88h] [bp-FCh]@1127
  char v710; // [sp+D8Ch] [bp-F8h]@1156
  stru277 *v711; // [sp+D90h] [bp-F4h]@1
  __int64 v712; // [sp+D94h] [bp-F0h]@991
  int v713; // [sp+D9Ch] [bp-E8h]@324
  int n; // [sp+DA0h] [bp-E4h]@1
  AIDirection v715; // [sp+DA4h] [bp-E0h]@21
  int v716; // [sp+DC0h] [bp-C4h]@272
  __int64 v717; // [sp+DC4h] [bp-C0h]@271
  float v718; // [sp+DCCh] [bp-B8h]@176
  signed int sRecoveryTime; // [sp+DD0h] [bp-B4h]@53
  char *y; // [sp+DD4h] [bp-B0h]@325
  int v721; // [sp+DD8h] [bp-ACh]@163
  //LayingItem a1; // [sp+DDCh] [bp-A8h]@1
  int v723; // [sp+E4Ch] [bp-38h]@1
  ItemGen *_this; // [sp+E50h] [bp-34h]@23
  float v725; // [sp+E54h] [bp-30h]@23
  Player *v726; // [sp+E58h] [bp-2Ch]@131
  float v727; // [sp+E5Ch] [bp-28h]@1
  unsigned int uRequiredMana; // [sp+E60h] [bp-24h]@53
  Player *pPlayer; // [sp+E64h] [bp-20h]@8
  int v730; // [sp+E68h] [bp-1Ch]@53
  int v731; // [sp+E6Ch] [bp-18h]@48
  signed int v732; // [sp+E70h] [bp-14h]@325
  unsigned __int64 v733; // [sp+E74h] [bp-10h]@1
  signed int a2; // [sp+E7Ch] [bp-8h]@14
  int amount; // [sp+E80h] [bp-4h]@1

  auto ecx0 = this;

  v711 = ecx0;

  LayingItem a1; // [sp+DDCh] [bp-A8h]@1
  //LayingItem::LayingItem(&a1);

  v1 = 0;
  v2 = 0;
  amount = 0;
  LODWORD(v733) = 0;
  v723 = 0;
  v727 = 0.0;
  n = 0;
  while ( 1 )
  {
    v3 = &v711[n];
    HIDWORD(v733) = (int)v3;
    if ( v3->spellnum == (short)v1 )
      goto LABEL_1166;
    if ( pParty->pPartyBuffs[11].NotExpired() )
      pParty->pPartyBuffs[11].Reset();
    if ( v3->field_8 & 0x3CA )
    {
      if ( !pParty->pPlayers[v3->uPlayerID].CanAct() )
        v711->_427D48(1u);
      goto LABEL_1166;
    }
    pPlayer = &pParty->pPlayers[v3->uPlayerID];
    v4 = *(int *)&v3->field_C;
    if ( v4 != v1 )
      goto LABEL_18;
    v5 = v3->spellnum;
    if ( v3->spellnum == 79 || v5 == 48 || v5 == 94 )
      v666 = 1;
    else
      v666 = v1;
    a2 = stru_50C198.FindClosesActor(5120, 1, v666);
    v6 = pMouse->uPointingObjectID;
    if ( pMouse->uPointingObjectID != v1 && (v6 & 7) == 3 && pActors[v6 >> 3].CanAct() )
    {
      v4 = pMouse->uPointingObjectID;
LABEL_18:
      a2 = v4;
    }
    a1.uItemType = stru_4E3ACC[v3->spellnum].uItemType;
    if ( (short)a1.uItemType != (short)v1 )
    {
      if ( (a2 & 7) == 3 )
      {
        memcpy(&v715, Actor::GetDirectionInfo((8 * v3->uPlayerID + 8) | 4, a2, &a3, 0), sizeof(v715));
        v2 = v723;
        v1 = 0;
      }
      else
      {
        v715.uYawAngle = pParty->sRotationY;
        v715.uPitchAngle = pParty->sRotationX;
      }
    }
    v7 = v3->field_A;
    LODWORD(v725) = v1;
    _this = (ItemGen *)v1;
    if ( v7 == (short)v1 )
    {
      v8 = v3->spellnum;
      if ( v3->spellnum >= 12 )
      {
        if ( v8 >= 23 )
        {
          if ( v8 >= 34 )
          {
            if ( v8 >= 45 )
            {
              if ( v8 >= 56 )
              {
                if ( v8 >= 67 )
                {
                  if ( v8 >= 78 )
                  {
                    if ( v8 >= 89 )
                    {
                      if ( v8 >= 100 )
                      {
                        if ( v8 != 100 )
                        {
LABEL_45:
                          HIWORD(v10) = HIWORD(pPlayer);
                          v11 = pPlayer->pActiveSkills[LODWORD(v725)];
                          goto LABEL_47;
                        }
                        v667 = (PLAYER_SKILL_TYPE)5;
                      }
                      else
                      {
                        v667 = (PLAYER_SKILL_TYPE)20;
                      }
                    }
                    else
                    {
                      v667 = (PLAYER_SKILL_TYPE)19;
                    }
                  }
                  else
                  {
                    v667 = (PLAYER_SKILL_TYPE)18;
                  }
                }
                else
                {
                  v667 = (PLAYER_SKILL_TYPE)17;
                }
              }
              else
              {
                v667 = (PLAYER_SKILL_TYPE)16;
              }
            }
            else
            {
              v667 = (PLAYER_SKILL_TYPE)15;
            }
          }
          else
          {
            v667 = (PLAYER_SKILL_TYPE)14;
          }
        }
        else
        {
          v667 = (PLAYER_SKILL_TYPE)13;
        }
      }
      else
      {
        v667 = (PLAYER_SKILL_TYPE)12;
      }
      LODWORD(v725) = v667;
      v9 = pPlayer->GetActualSkillLevel(v667);
      v723 = v9 & 0x3F;
      v2 = v9 & 0x3F;
      goto LABEL_45;
    }
    v11 = v7;
    v10 = v7 & 0x3F;
    v723 = v10;
    v2 = v10;
LABEL_47:
    if ( HIBYTE(v11) & 1 )
    {
      v12 = 4;
      v731 = 4;
    }
    else
    {
      if ( (v11 & 0x80u) == 0 )
      {
        v10 = ((v11 & 0x40) != 0) + 1;
        v731 = ((v11 & 0x40) != 0) + 1;
      }
      else
      {
        v731 = 3;
      }
      v12 = v731;
    }
    LOWORD(v10) = v3->spellnum;
    v730 = v10;
    v13 = v12 + 10 * (signed __int16)v10;
    v14 = v3->field_A == (short)v1;
    v15 = (unsigned __int16)word_4E3C66[v13];   // pSpellDatas [negoffset] indexing
    v16 = *(unsigned __int16 *)((char *)&pSpellDatas[0].uMagisterLevelMana + v13 * 2);
    uRequiredMana = v15;
    sRecoveryTime = v16;
    if ( !v14 )
      uRequiredMana = v1;
    if ( pParty->uCurrentHour == v1 )
    {
      if ( pParty->uCurrentMinute != v1 )
        goto LABEL_62;
      if ( LODWORD(v725) == 20 )
        goto LABEL_61;
    }
    if ( pParty->uCurrentHour == 12 && pParty->uCurrentMinute == v1 && LODWORD(v725) == 19 )
LABEL_61:
      uRequiredMana = v1;
LABEL_62:
    if ( (signed __int16)v730 >= 100 || ((pPlayer->sMana - uRequiredMana) & 0x80000000u) == 0 )
      break;
    ShowStatusBarString(pGlobalTXT_LocalizationStrings[586], 2u);
LABEL_203:
    v3->spellnum = v1;
LABEL_1166:
    ++n;
    if ( n >= 10 )
      return;
  }
  if ( !pPlayer->pConditions[0] || (signed __int16)v730 >= 100 )
    goto LABEL_69;
  if ( rand() % 100 >= 50 )
  {
    v12 = v731;
LABEL_69:
    switch ( v3->spellnum )
    {
      case 100:
      case 101:
        v17 = pPlayer;
        _this = (ItemGen *)1;
        if ( (signed int)SkillToMastery(pPlayer->pActiveSkills[5]) >= 3 )
          _this = (ItemGen *)2;
        sRecoveryTime = v17->GetAttackRecoveryTime(1);
        a1.stru_24.Reset();
        v18 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_48 = v18;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        if ( v17->WearsItem(510, 2) )
          a1.uObjectDescID = pObjectList->ObjectIDByItemID(0xBD6u);
        a1.vPosition.x = pParty->vPosition.x;
        a1.vPosition.y = pParty->vPosition.y;
        a1.uAttributes = 0;
        a1.uSpriteFrameID = 0;
        a1.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
        v19 = 8 * v3->uPlayerID;
        LOBYTE(v19) = v19 | 4;
        a1.field_58 = v19;
        a1.field_5C = a2;
        a1.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
        a1.uFacing = LOWORD(v715.uYawAngle);
        a1.uSoundID = LOWORD(v3->field_10);
        v20 = (char *)&pParty->pPlayers[v3->uPlayerID];
        memcpy(&a1.stru_24, &v20[36 * *((int *)v20 + 1620) + 496], sizeof(a1.stru_24));
        a1.uAttributes = 256;
        if ( pParty->bTurnBasedModeOn == 1 )
          a1.uAttributes = 260;
        for ( i = 0; i < (signed int)this; ++i )
        {
          if ( i )
            a1.vPosition.z += 32;
          a1.uSectorID = pIndoor->GetSector(a1.vPosition.x, a1.vPosition.y, a1.vPosition.z);
          if ( a1.Create(
                 v715.uYawAngle,
                 v715.uPitchAngle,
                 pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed,
                 v3->uPlayerID + 1) != -1
            && pParty->bTurnBasedModeOn == 1 )
            ++pTurnEngine->field_1C;
        }
        goto LABEL_83;
      case 102:
        sRecoveryTime = pPlayer->GetAttackRecoveryTime(0);
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v723;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.vPosition.x = pParty->vPosition.x;
        a1.vPosition.y = pParty->vPosition.y;
        a1.uAttributes = 0;
        a1.uSpriteFrameID = 0;
        a1.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 2;
        v22 = 8 * v3->uPlayerID;
        LOBYTE(v22) = v22 | 4;
        a1.field_58 = v22;
        a1.field_5C = a2;
        a1.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
        a1.uFacing = LOWORD(v715.uYawAngle);
        a1.uSoundID = LOWORD(v3->field_10);
        memcpy(
          &a1.stru_24,
          &pParty->pPlayers[v3->uPlayerID].spellbook.pDarkSpellbook.bIsSpellAvailable[36
                                                                         * pParty->pPlayers[v3->uPlayerID].pEquipment.uMainHand
                                                                         + 5],
          sizeof(a1.stru_24));
        v23 = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, a1.vPosition.z);
        HIBYTE(a1.uAttributes) |= 1u;
        a1.uSectorID = v23;
        if ( pParty->bTurnBasedModeOn == 1 )
          LOBYTE(a1.uAttributes) |= 4u;
        if ( a1.Create(
               v715.uYawAngle,
               v715.uPitchAngle,
               pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed,
               v3->uPlayerID + 1) != -1
          && pParty->bTurnBasedModeOn == 1 )
          ++pTurnEngine->field_1C;
        goto LABEL_83;
      case 1:
        LODWORD(v733) = 3600 * v2;
        v24 = v12 - 2;
        if ( v24 )
        {
          v25 = v24 - 1;
          if ( v25 && v25 != 1 )
            amount = 2;
          else
            amount = 4;
        }
        else
        {
          amount = 3;
        }
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v668 = v1;
        v658 = v1;
        v653 = amount;
        v651 = v731;
        v26 = (signed __int64)((double)(signed int)v733 * 4.2666669);
        v27 = (char *)&pParty->pPartyBuffs[16];
        goto LABEL_101;
      case 7:
        v29 = v12 - 2;
        if ( v29 )
        {
          v30 = v29 - 1;
          if ( v30 )
          {
            if ( v30 == 1 )
              amount = 9;
            else
              amount = 3;
          }
          else
          {
            amount = 7;
          }
        }
        else
        {
          amount = 5;
        }
        v31 = v3->uPlayerID;
        HIDWORD(v733) = v1;
        v32 = 8 * v31;
        LOBYTE(v32) = v32 | 4;
        if ( (signed int)uNumLayingItems > v1 )
        {
          v33 = (char *)&pLayingItems[0].field_48;
          v730 = uNumLayingItems;
          do
          {
            if ( *((short *)v33 - 36) != (short)v1 && *(int *)v33 == 7 && *((int *)v33 + 4) == v32 )
              ++HIDWORD(v733);
            v33 += 112;
            --v730;
          }
          while ( v730 );
        }
        if ( SHIDWORD(v733) > amount )
          goto LABEL_200;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.vPosition.y = pParty->vPosition.y;
        a1.vPosition.x = pParty->vPosition.x;
        a1.uAttributes = v1;
        a1.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
        a1.uSectorID = pIndoor->GetSector(
                         pParty->vPosition.x,
                         pParty->vPosition.y,
                         pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3);
        a1.uSpriteFrameID = v1;
        v34 = 8 * v3->uPlayerID;
        LOBYTE(v34) = v34 | 4;
        a1.field_58 = v34;
        a1.field_5C = a2;
        a1.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
        a1.uFacing = LOWORD(v715.uYawAngle);
        a1.uSoundID = LOWORD(v3->field_10);
        if ( pParty->bTurnBasedModeOn == 1 )
          LOBYTE(a1.uAttributes) |= 4u;
        v669 = v3->uPlayerID + 1;
        v659 = pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed;
        v35 = pParty->sRotationX + 10;
        goto LABEL_124;
      case 20:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        if ( a2 == v1 )
          goto LABEL_200;
        if ( (a2 & 7) != 3 )
          goto LABEL_1056;
        v699 = v1;
        v698 = v1;
        v697 = v1;
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.uAttributes = v1;
        a1.uSectorID = v1;
        a1.uSpriteFrameID = v1;
        v37 = v3->uPlayerID;
        a1.field_60_distance_related_prolly_lod = 0;
        v37 *= 8;
        LOBYTE(v37) = v37 | 4;
        a1.uFacing = v1;
        a1.field_58 = v37;
        v38 = a2 >> 3;
        a1.uSoundID = LOWORD(v3->field_10);
        v39 = a2 >> 3;
        a1.vPosition.x = pActors[v39].vPosition.x;
        v40 = pActors[v39].vPosition.y;
        a1.vPosition.z = pActors[v39].vPosition.z;
        v41 = 8 * (a2 >> 3);
        a1.vPosition.y = v40;
        LOBYTE(v41) = v41 | 3;
        a1.field_5C = v41;
        v42 = a1.Create(0, v1, v1, v1);
        v43 = &v697;
        goto LABEL_133;
      case 44:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v726 = (Player *)(a2 >> 3);
        HIDWORD(v733) = 836 * (a2 >> 3);
        if ( !stru_50C198.GetMagicalResistance((Actor *)((char *)pActors + HIDWORD(v733)), 3u) )
          goto LABEL_1056;
        ((SpellBuff *)((char *)&pActors[0].pActorBuffs[10] + HIDWORD(v733)))->Apply(
          pMiscTimer->uTotalGameTimeElapsed + 128,
          v1,
          v1,
          v1,
          v1);
        v706 = v1;
        v705 = v1;
        v704 = v1;
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.uAttributes = v1;
        a1.uSectorID = v1;
        a1.uSpriteFrameID = v1;
        v44 = v3->uPlayerID;
        a1.field_60_distance_related_prolly_lod = 0;
        a1.uFacing = v1;
        v44 *= 8;
        LOBYTE(v44) = v44 | 4;
        v38 = (signed int)v726;
        a1.field_58 = v44;
        a1.uSoundID = LOWORD(v3->field_10);
        a1.vPosition.x = *(__int16 *)((char *)&pActors[0].vPosition.x + HIDWORD(v733));
        v45 = *(__int16 *)((char *)&pActors[0].vPosition.y + HIDWORD(v733));
        a1.vPosition.z = *(__int16 *)((char *)&pActors[0].vPosition.z + HIDWORD(v733));
        v46 = 8 * (int)v726;
        a1.vPosition.y = v45;
        LOBYTE(v46) = 8 * (char)v726 | 3;
        a1.field_5C = v46;
        v42 = a1.Create(0, v1, v1, v1);
        v43 = &v704;
LABEL_133:
        v670 = (Vec3_int_ *)v43;
        v47 = v38;
        goto LABEL_139;
      case 79:
        if ( !pPlayer->CanCastSpell(uRequiredMana) || a2 == v1 || (a2 & 7) != 3 )
          goto LABEL_83;
        v730 = a2 >> 3;
        v693 = v1;
        HIDWORD(v733) = (int)&pActors[a2 >> 3];
        v692 = v1;
        v691 = v1;
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.vPosition.x = *(short *)(HIDWORD(v733) + 142);
        a1.vPosition.y = *(short *)(HIDWORD(v733) + 144);
        v48 = *(short *)(HIDWORD(v733) + 138);
        a1.vPosition.z = *(short *)(HIDWORD(v733) + 138);
        a1.uAttributes = v1;
        a1.uSectorID = pIndoor->GetSector(a1.vPosition.x, a1.vPosition.y, v48);
        a1.uSpriteFrameID = v1;
        v49 = 8 * v3->uPlayerID;
        LOBYTE(v49) = v49 | 4;
        a1.field_58 = v49;
        a1.field_5C = a2;
        a1.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
        a1.uFacing = LOWORD(v715.uYawAngle);
        LOWORD(v49) = LOWORD(v3->field_10);
        LOBYTE(a1.uAttributes) |= 0x80u;
        a1.uSoundID = v49;
        v726 = (Player *)a1.Create(0, v1, v1, v1);
        if ( !MonsterStats::BelongsToSupertype(*(short *)(HIDWORD(v733) + 96), MONSTER_SUPERTYPE_UNDEAD) )
          goto LABEL_200;
        v47 = v730;
        v670 = (Vec3_int_ *)&v691;
        v42 = (signed int)v726;
LABEL_139:
        DamageMonsterFromParty(8 * v42 | 2, v47, v670);
        goto LABEL_1056;
      case 2:
      case 6:
      case 11:
      case 18:
      case 26:
      case 32:
      case 34:
      case 37:
      case 57:
      case 65:
      case 70:
      case 78:
      case 97:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.vPosition.y = pParty->vPosition.y;
        a1.vPosition.x = pParty->vPosition.x;
        a1.uAttributes = v1;
        a1.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
        a1.uSectorID = pIndoor->GetSector(
                         pParty->vPosition.x,
                         pParty->vPosition.y,
                         pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3);
        a1.uSpriteFrameID = v1;
        v50 = 8 * v3->uPlayerID;
        LOBYTE(v50) = v50 | 4;
        a1.field_58 = v50;
        a1.field_5C = a2;
        a1.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
        a1.uFacing = LOWORD(v715.uYawAngle);
        a1.uSoundID = LOWORD(v3->field_10);
        if ( pParty->bTurnBasedModeOn == 1 )
          LOBYTE(a1.uAttributes) |= 4u;
        if ( v3->spellnum == 18 )
          LOBYTE(a1.uAttributes) |= 0x40u;
        goto LABEL_156;
      case 29:
      case 39:
      case 76:
      case 90:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        v51 = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 2;
        a1.vPosition.y = pParty->vPosition.y;
        v671 = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 2;
        v660 = pParty->vPosition.y;
        goto LABEL_153;
      case 87:
        if ( uCurrentlyLoadedLevelType == LEVEL_Indoor
          || uCurrentlyLoadedLevelType == LEVEL_Outdoor && (pParty->uCurrentHour < 5 || pParty->uCurrentHour >= 0x15) )
          goto LABEL_200;
        if ( pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_152;
        goto LABEL_83;
      case 81:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        if ( a2 == v1
          || (a2 & 7) != 3
          || (v730 = a2 >> 3,
              v721 = (int)&pActors[a2 >> 3],
              !stru_50C198.GetMagicalResistance(&pActors[a2 >> 3], 9u)) )
          goto LABEL_1056;
        Actor::_403EB6(v730, 4u, 0x80u, (AIDirection *)v1);
        v726 = (Player *)(23040 * v2);
        v54 = (signed __int64)((double)(23040 * v2) * 0.033333335);
        v55 = v721;
        ((SpellBuff *)(v721 + 308))->Apply(pParty->uTimePlayed + (signed int)v54, v731, v1, v1, v1);
        *(char *)(v55 + 38) |= 8u;
        *(short *)(v55 + 148) = v1;
        v672 = v1;
        *(short *)(v55 + 150) = v1;
        v661 = (Actor *)v55;
        goto LABEL_165;
      case 35:
        if ( v12 == 2 )
        {
          v57 = 300 * v2;
        }
        else
        {
          if ( v12 == 3 )
          {
            amount = 4;
            v57 = 300 * v2;
            goto LABEL_174;
          }
          if ( v12 == 4 )
          {
            v57 = 300 * v2;
            amount = 8;
            goto LABEL_174;
          }
          v57 = 180 * v2;
        }
        amount = 2;
LABEL_174:
        LODWORD(v733) = v57;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        if ( (a2 & 7) != 3
          || (v721 = 836 * (a2 >> 3),
              LODWORD(v718) = (int)(char *)pActors + v721,
              !stru_50C198.GetMagicalResistance((Actor *)((char *)pActors + v721), 3u)) )
          goto LABEL_1056;
        v726 = (Player *)(23040 * v2);
        v58 = (signed __int64)((double)(23040 * v2) * 0.033333335);
        v59 = v721;
        ((SpellBuff *)((char *)&pActors[0].pActorBuffs[7] + v721))->Apply(
          pParty->uTimePlayed + (signed int)v58,
          v731,
          amount,
          v1,
          v1);
        *((char *)&pActors[0].uAttributes + v59 + 2) |= 8u;
        v672 = v1;
        v661 = (Actor *)LODWORD(v718);
        goto LABEL_165;
      case 60:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v730 = 836 * (a2 >> 3);
        if ( !stru_50C198.GetMagicalResistance((Actor *)((char *)pActors + v730), 7u) )
          goto LABEL_1056;
        LODWORD(v733) = 300 * v2;
        if ( v731 == 2 )
        {
          LODWORD(v733) = 600 * v2;
        }
        else
        {
          if ( v731 == 3 )
            LODWORD(v733) = 29030400;
        }
        ((SpellBuff *)((char *)&pActors[0].pActorBuffs[9] + v730))->Reset();
        ((SpellBuff *)((char *)&pActors[0].pActorBuffs[12] + v730))->Reset();
        v726 = (Player *)((int)v733 << 7);
        ((SpellBuff *)((char *)&pActors[0].pActorBuffs[1] + v730))->Apply(
          pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335),
          v731,
          v1,
          v1,
          v1);
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        v60 = pObjectList->ObjectIDByItemID(a1.uItemType);
        v61 = v730;
        goto LABEL_1086;
      case 92:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        a1.stru_24.Reset();
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.vPosition.x = pParty->vPosition.x;
        a1.vPosition.y = pParty->vPosition.y;
        a1.uAttributes = v1;
        a1.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
        a1.uSectorID = pIndoor->GetSector(
                         pParty->vPosition.x,
                         pParty->vPosition.y,
                         pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3);
        a1.uSpriteFrameID = v1;
        v62 = 8 * v3->uPlayerID;
        LOBYTE(v62) = v62 | 4;
        a1.field_58 = v62;
        a1.field_5C = a2;
        a1.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
        a1.uFacing = LOWORD(v715.uYawAngle);
        a1.uSoundID = LOWORD(v3->field_10);
        a1.field_50 = v731;
        a1.field_48 = 3;
        a1.field_4C = 300 * v2;
        goto LABEL_154;
      case 4:
        v63 = v12 - 1;
        if ( !v63 )
        {
          amount = 10;
          goto LABEL_195;
        }
        v64 = v63 - 1;
        if ( !v64 )
        {
          amount = 11;
          goto LABEL_195;
        }
        v65 = v64 - 1;
        if ( !v65 )
        {
          amount = 12;
LABEL_195:
          LODWORD(v733) = 3600 * v2;
          goto LABEL_196;
        }
        if ( v65 == 1 )
        {
          LODWORD(v733) = v1;
          amount = 12;
        }
LABEL_196:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v730 = (int)&pParty->pPlayers[v3->uPlayerID_2].pInventoryItems[a2];
        v726 = (Player *)&pItemsTable->pItems[*(int *)v730].pIconName;
        ((ItemGen *)v730)->UpdateTempBonus(pParty->uTimePlayed);
        if ( *(int *)v730 < 64 || *(int *)v730 > 65 )
        {
          if ( !(*(char *)(v730 + 20) & 2) )
          {
            if ( *(int *)(v730 + 12) == v1 )
            {
              if ( *(int *)(v730 + 4) == v1 )
              {
                v68 = BYTE4(v726->pConditions[3]);
                if ( !v68 || v68 == 1 || v68 == 2 )
                {
                  if ( !pItemsTable->_456D5E_is_some_material((ItemGen *)v730) )
                  {
                    v69 = v730;
                    v14 = v731 == 4;
                    *(int *)(v730 + 12) = amount;
                    if ( !v14 )
                    {
                      v726 = (Player *)((int)v733 << 7);
                      *(_QWORD *)(v69 + 28) = pParty->uTimePlayed
                                            + (signed int)(signed __int64)((double)(signed int)((int)v733 << 7)
                                                                         * 0.033333335);
                      *(int *)(v69 + 20) |= 8u;
                    }
                    *(int *)(v69 + 20) |= 0x10u;
LABEL_1055:
                    dword_50C9A8 = 256;
LABEL_1056:
                    LODWORD(v727) = 1;
LABEL_83:
                    if ( v3->field_8 & 0x20 )
                    {
LABEL_1162:
                      if ( v727 != 0.0 )
                        pAudioPlayer->PlaySound(
                          (SoundID)word_4EE088_sound_ids[v3->spellnum],
                          0,
                          0,
                          -1,
                          0,
                          v3->field_10,
                          0,
                          0);
                    }
                    else
                    {
                      if ( sRecoveryTime < 0 )
                        sRecoveryTime = 0;
                      if ( pParty->bTurnBasedModeOn )
                      {
                        v645 = sRecoveryTime;
                        pParty->pTurnBasedPlayerRecoveryTimes[v3->uPlayerID] = sRecoveryTime;
                        pPlayer->SetRecoveryTime(v645);
                        if ( !some_active_character )
                          pTurnEngine->_40471C();
                      }
                      else
                      {
                        pPlayer->SetRecoveryTime(
                          (signed __int64)(flt_6BE3A4_debug_recmod1 * (double)sRecoveryTime * 2.133333333333333));
                      }
                      if ( v727 != 0.0 )
                      {
                        pPlayer->PlaySound(49, 0);
                        goto LABEL_1162;
                      }
                    }
                    v3->spellnum = 0;
                    v1 = 0;
LABEL_1165:
                    v2 = v723;
                    goto LABEL_1166;
                  }
                }
              }
            }
          }
        }
LABEL_199:
        dword_50C9D0 = 113;
        dword_50C9D4 = v1;
        dword_50C9D8 = 1;
LABEL_200:
        v66 = pGlobalTXT_LocalizationStrings[428];
LABEL_201:
        v67 = 2;
LABEL_202:
        ShowStatusBarString(v66, v67);
        pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, v1, v1, -1, v1, v1, v1, v1);
        goto LABEL_203;
      case 71:
        v70 = v12 - 1;
        LODWORD(v733) = 3600 * v2;
        if ( v70 && (v71 = v70 - 1) != 0 )
        {
          v72 = v71 - 1;
          if ( v72 )
          {
            if ( v72 == 1 )
              amount = 10;
          }
          else
          {
            amount = 3;
          }
        }
        else
        {
          amount = 1;
        }
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v73 = v3->uPlayerID_2;
        v74 = v3->spellnum;
        v75 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v74, v73);
        v668 = v1;
        v658 = v1;
        v653 = amount;
        v651 = v731;
        v28 = pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)v733 * 4.2666669);
        v27 = (char *)&pParty->pPlayers[v3->uPlayerID_2].pPlayerBuffs[12];
        goto LABEL_103;
      case 3:
      case 14:
      case 25:
      case 36:
      case 58:
      case 69:
        v76 = v12 - 1;
        LODWORD(v733) = 3600 * v2;
        if ( v76 )
        {
          v77 = v76 - 1;
          if ( v77 )
          {
            v78 = v77 - 1;
            if ( v78 )
            {
              if ( v78 != 1 )
                goto LABEL_232;
              v79 = 4 * v2;
            }
            else
            {
              v79 = 3 * v2;
            }
          }
          else
          {
            v79 = 2 * v2;
          }
          amount = v79;
        }
        else
        {
          amount = v2;
        }
LABEL_232:
        v80 = v3->spellnum;
        switch ( v80 )
        {
          case 3:
            LODWORD(v725) = 6;
            break;
          case 14:
            LODWORD(v725) = v1;
            break;
          case 25:
            LODWORD(v725) = 17;
            break;
          case 36:
            LODWORD(v725) = 4;
            break;
          case 58:
            LODWORD(v725) = 12;
            break;
          default:
            if ( v80 != 69 )
              goto LABEL_1166;
            LODWORD(v725) = 1;
            break;
        }
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v81 = v3->spellnum;
        v82 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v81, v1);
        v83 = 1;
        v84 = v3->spellnum;
        v85 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v84, 1u);
        v86 = v3->spellnum;
        v87 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v86, 2u);
        v88 = v3->spellnum;
        v89 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v88, 3u);
        v90 = (double)(signed int)v733 * 4.2666669;
        goto LABEL_304;
      case 5:
        if ( v12 <= v1 )
          goto LABEL_254;
        if ( v12 <= 2 )
        {
          v91 = 60 * (v2 + 60);
        }
        else
        {
          if ( v12 == 3 )
          {
            v91 = 180 * (v2 + 20);
          }
          else
          {
            if ( v12 != 4 )
              goto LABEL_254;
            v91 = 240 * (v2 + 15);
          }
        }
        LODWORD(v733) = v91;
LABEL_254:
        if ( pPlayer->CanCastSpell(uRequiredMana) )
        {
          v92 = (char *)&pParty->pPlayers[0].pConditions[1];
          LODWORD(v727) = 1;
          do
          {
            if ( *(_QWORD *)v92 )
              LODWORD(v727) = v1;
            v92 += 6972;
          }
          while ( (signed int)v92 < (signed int)&pParty->pHirelings[0].uFlags );
          if ( LODWORD(v727) != v1 )
          {
            v726 = (Player *)((int)v733 << 7);
            pParty->pPartyBuffs[8].Apply(
              pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335),
              v731,
              v1,
              v1,
              v1);
            v93 = v3->spellnum;
            v94 = pGame->GetStru6();
            pGame->GetStru6()->SetPlayerBuffAnim(v93, v1);
            v95 = v3->spellnum;
            v96 = pGame->GetStru6();
            pGame->GetStru6()->SetPlayerBuffAnim(v95, 1u);
            v97 = v3->spellnum;
            v98 = pGame->GetStru6();
            pGame->GetStru6()->SetPlayerBuffAnim(v97, 2u);
            v99 = v3->spellnum;
            v100 = pGame->GetStru6();
            pGame->GetStru6()->SetPlayerBuffAnim(v99, 3u);
          }
        }
        goto LABEL_83;
      case 46:
        v101 = v12 - 1;
        if ( v101 && (v102 = v101 - 1) != 0 )
        {
          v103 = v102 - 1;
          if ( v103 )
          {
            if ( v103 != 1 )
              goto LABEL_269;
            v104 = 3600 * (v2 + 1);
          }
          else
          {
            v104 = 900 * (v2 + 4);
          }
        }
        else
        {
          v104 = 300 * (v2 + 12);
        }
        LODWORD(v733) = v104;
LABEL_269:
        amount = v2 + 5;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        if ( v731 == 1 )
        {
          v108 = v3->uPlayerID_2;
          v109 = v3->spellnum;
          v110 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v109, v108);
          v111 = pOtherOverlayList->_4418B1(10000, v3->uPlayerID_2 + 310, v1, 65536);
          v668 = v1;
          v716 = v111;
          v658 = v111;
          v653 = amount;
          v726 = (Player *)((int)v733 << 7);
          v651 = 1;
          v28 = pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
          v27 = (char *)&pParty->pPlayers[v3->uPlayerID_2].pPlayerBuffs[1];
          goto LABEL_103;
        }
        v105 = 0;
        v726 = (Player *)((int)v733 << 7);
        v717 = (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
        v730 = (int)&pParty->pPlayers[0].pPlayerBuffs[1];
        do
        {
          v106 = v3->spellnum;
          v107 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v106, v105);
          v716 = pOtherOverlayList->_4418B1(10000, v105 + 310, v1, 65536);
          ((SpellBuff *)v730)->Apply(pParty->uTimePlayed + v717, v731, amount, v716, v1);
          v730 += 6972;
          ++v105;
        }
        while ( v730 < (signed int)&pParty->field_871C[468] );
        goto LABEL_1056;
      case 52:
        if ( pPlayer->CanCastSpell(uRequiredMana) && a2 != v1 && (a2 & 7) == 3 )
        {
          v730 = a2 >> 3;
          v112 = &pActors[a2 >> 3];
          v726 = (Player *)abs(v112->vPosition.z - pParty->vPosition.z);
          v721 = abs(v112->vPosition.y - pParty->vPosition.y);
          v113 = abs(v112->vPosition.x - pParty->vPosition.x);
          _this = (ItemGen *)v113;
          v114 = v721;
          v115 = (unsigned int)v726;
          if ( v113 < v721 )
          {
            v116 = v113;
            v113 = v721;
            v114 = v116;
          }
          if ( v113 < (signed int)v726 )
          {
            v117 = v113;
            v113 = (int)v726;
            v115 = v117;
          }
          if ( v114 < (signed int)v115 )
          {
            v118 = v115;
            v115 = v114;
            v114 = v118;
          }
          _this = (ItemGen *)(((unsigned int)(11 * v114) >> 5) + (v115 >> 2) + v113);
          if ( (double)(signed int)this <= 307.2 )
          {
            v703 = 0;
            v702 = 0;
            v701 = 0;
            a1.stru_24.Reset();
            v119 = HIDWORD(v733);
            a1.field_48 = *(int *)HIDWORD(v733);
            a1.field_4C = v723;
            a1.field_50 = v731;
            a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
            a1.uAttributes = 0;
            a1.uSectorID = 0;
            a1.uSpriteFrameID = 0;
            v120 = 8 * *(short *)(v119 + 2);
            LOBYTE(v120) = v120 | 4;
            a1.field_60_distance_related_prolly_lod = 0;
            a1.field_58 = v120;
            a1.uFacing = 0;
            a1.uSoundID = *(short *)(v119 + 16);
            a1.vPosition.x = v112->vPosition.x;
            a1.vPosition.y = v112->vPosition.y;
            v726 = (Player *)v112->uActorHeight;
            v121 = 8 * a2;
            a1.vPosition.z = v112->vPosition.z - (unsigned int)(signed __int64)((double)(signed int)v726 * unk_4D8548);
            LOBYTE(v121) = 8 * a2 | 3;
            a1.field_5C = v121;
            v122 = a1.Create(0, 0, 0, 0);
            DamageMonsterFromParty(8 * v122 | 2, v730, (Vec3_int_ *)&v701);
            LODWORD(v727) = 1;
          }
          else
          {
            ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2u);
            pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
            *(int *)HIDWORD(v733) = 0;
          }
          v3 = (stru277 *)HIDWORD(v733);
        }
        goto LABEL_83;
      case 17:
      case 38:
      case 51:
        v123 = v12 - 1;
        if ( v123 && (v124 = v123 - 1) != 0 )
        {
          v125 = v124 - 1;
          if ( v125 )
          {
            if ( v125 != 1 )
              goto LABEL_296;
            v126 = 3600 * (v2 + 1);
          }
          else
          {
            v126 = 900 * (v2 + 4);
          }
        }
        else
        {
          v126 = 300 * (v2 + 12);
        }
        LODWORD(v733) = v126;
LABEL_296:
        v127 = v3->spellnum;
        if ( v127 == 17 )
        {
          amount = v1;
          LODWORD(v725) = 14;
        }
        else
        {
          if ( v127 == 38 )
          {
            LODWORD(v725) = 15;
            amount = v2 + 5;
          }
          else
          {
            if ( v127 != 51 )
              goto LABEL_1166;
            LODWORD(v725) = 9;
            amount = v2 + 5;
          }
        }
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v128 = v3->spellnum;
        v129 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v128, v1);
        v83 = 1;
        v130 = v3->spellnum;
        v131 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v130, 1u);
        v132 = v3->spellnum;
        v133 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v132, 2u);
        v134 = v3->spellnum;
        v135 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v134, 3u);
        v726 = (Player *)((int)v733 << 7);
        v90 = (double)(signed int)((int)v733 << 7) * 0.033333335;
LABEL_304:
        v673 = v1;
        v662 = v1;
        v655 = amount;
        v652 = v731;
        v136 = pParty->uTimePlayed + (signed int)(signed __int64)v90;
        v137 = (char *)&pParty->pPartyBuffs[LODWORD(v725)];
        goto LABEL_977;
      case 8:
        v138 = v12 - 2;
        if ( v138 && (v139 = v138 - 1) != 0 && v139 == 1 )
          v140 = 600 * v2;
        else
          v140 = 60 * v2;
        LODWORD(v733) = v140;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v141 = v3->spellnum;
        v142 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v141, v1);
        v143 = v3->spellnum;
        v144 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v143, 1u);
        v145 = v3->spellnum;
        v146 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v145, 2u);
        v147 = v3->spellnum;
        v148 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v147, 3u);
        v668 = v1;
        v726 = (Player *)((int)v733 << 7);
        v658 = v1;
        v653 = v2;
        v651 = v731;
        v26 = (signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
        v27 = (char *)&pParty->pPartyBuffs[10];
        goto LABEL_102;
      case 9:
        v149 = v12 - 1;
        if ( v149 && (v150 = v149 - 1) != 0 && (v151 = v150 - 1) != 0 )
        {
          if ( v151 == 1 )
            _this = (ItemGen *)20;
        }
        else
        {
          _this = (ItemGen *)16;
        }
        if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
        {
          v66 = pGlobalTXT_LocalizationStrings[491];
          goto LABEL_201;
        }
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        LODWORD(v725) = a2 & 7;
        if ( (a2 & 7) == 3 )
        {
          v152 = a2 >> 3;
          uRequiredMana = pActors[v152].vPosition.x;
          v153 = pActors[v152].vPosition.y;
          v154 = pActors[v152].vPosition.z;
          LODWORD(v727) = v153;
        }
        else
        {
          v155 = stru_5C6E00->SinCos(pParty->sRotationY);
          uRequiredMana = pParty->vPosition.x + sub_42EBBE(2048, v155);
          v156 = stru_5C6E00->_42EBDB(pParty->sRotationY);
          LODWORD(v727) = pParty->vPosition.y + sub_42EBBE(2048, v156);
          v154 = pParty->vPosition.z;
        }
        HIDWORD(v733) = v154;
        v713 = v154 + 2500;
        v721 = v1;
        LODWORD(v718) = v1;
        if ( (signed int)this > v1 )
        {
          *(float *)&y = (double)SHIDWORD(v733);
          *(float *)&v732 = (double)v713;
          v730 = LODWORD(v725) == 3 ? a2 : 0;
          v726 = (Player *)this;
          do
          {
            v157 = rand();
            v158 = (double)SLODWORD(v718);
            v718 = v158;
            v159 = (double)v721;
            *(float *)&v721 = v159;
            a2 = v157 % 1000;
            *((float *)&v733 + 1) = (double)(v157 % 1000) + *(float *)&y - *(float *)&v732;
            v725 = v159 * v159;
            *(float *)&_this = v158 * v158;
            if ( sqrt(*((float *)&v733 + 1) * *((float *)&v733 + 1) + *(float *)&_this + v725) <= 1.0 )
            {
              LODWORD(v687) = v1;
              HIDWORD(v687) = v1;
            }
            else
            {
              x = (signed __int64)sqrt(*(float *)&_this + v725);
              v687 = __PAIR__(
                       stru_5C6E00->Atan2(x, (signed __int64)*((float *)&v733 + 1)),
                       stru_5C6E00->Atan2((signed __int64)v718, (signed __int64)*(float *)&v721));
            }
            a1.stru_24.Reset();
            a1.field_48 = v3->spellnum;
            a1.field_4C = v2;
            a1.field_50 = v731;
            a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
            a1.uAttributes = v1;
            a1.vPosition.x = uRequiredMana;
            a1.vPosition.y = LODWORD(v727);
            a1.uSectorID = v1;
            a1.vPosition.z = a2 + v713;
            a1.uSpriteFrameID = v1;
            a1.field_58 = 8 * v3->uPlayerID | 4;
            a1.field_5C = v730;
            a1.field_60_distance_related_prolly_lod = stru_50C198._427546(a2 + 2500);
            a1.uFacing = v687;
            a1.uSoundID = LOWORD(v3->field_10);
            if ( pParty->bTurnBasedModeOn == 1 )
              a1.uAttributes = 4;
            if ( a1.Create(
                   v687,
                   SHIDWORD(v687),
                   pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed,
                   v1) != -1
              && pParty->bTurnBasedModeOn == 1 )
              ++pTurnEngine->field_1C;
            LODWORD(v718) = rand() % 1024 - 512;
            v160 = rand();
            v14 = v726 == (Player *)1;
            v726 = (Player *)((char *)v726 - 1);
            v721 = (unsigned __int64)(v160 % 1024) - 512;
          }
          while ( !v14 );
        }
        goto LABEL_1056;
      case 10:
        v67 = 2;
        if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
        {
          v66 = pGlobalTXT_LocalizationStrings[492];
          goto LABEL_202;
        }
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v726 = (Player *)sub_46A6AC((int)dword_50BF30, 100, 4096);
        v700.z = v1;
        v700.y = v1;
        v700.x = v1;
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.uAttributes = v1;
        a1.uSectorID = v1;
        a1.uSpriteFrameID = v1;
        v161 = v3->uPlayerID;
        a1.field_60_distance_related_prolly_lod = 0;
        a1.uFacing = v1;
        v161 *= 8;
        LOBYTE(v161) = v161 | 4;
        a1.field_58 = v161;
        a1.uSoundID = LOWORD(v3->field_10);
        a2 = v1;
        if ( (signed int)v726 > v1 )
        {
          do
          {
            v162 = dword_50BF30[a2];
            a1.vPosition.x = pActors[v162].vPosition.x;
            a1.vPosition.y = pActors[v162].vPosition.y;
            v732 = pActors[v162].uActorHeight;
            a1.vPosition.z = pActors[v162].vPosition.z - (unsigned int)(signed __int64)((double)v732 * unk_4D8548);
            v163 = 8 * dword_50BF30[a2];
            LOBYTE(v163) = v163 | 3;
            a1.field_5C = v163;
            v164 = a1.Create(0, v1, v1, v1);
            v165 = a2;
            DamageMonsterFromParty(8 * v164 | AI_OBJECT_LAYING_ITEM, dword_50BF30[a2], &v700);
            v166 = pGame->GetStru6();
            v166->_4A81CA(&a1);
            v167 = pGame->GetStru6();
            v167->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0xFF3C1Eu, 0x40u);
            a2 = v165 + 1;
          }
          while ( v165 + 1 < (signed int)v726 );
        }
        goto LABEL_1056;
      case 12:
        LODWORD(v733) = 3600 * v2;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v168 = 0;
        do
        {
          v169 = pOtherOverlayList->_4418B1(2000, v168++ + 100, v1, 65536);
          v716 = v169;
        }
        while ( v168 < 4 );
        v668 = v1;
        v732 = (int)v733 << 7;
        v658 = v1;
        v653 = v1;
        v651 = v731;
        v28 = pParty->uTimePlayed + (signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
        goto LABEL_992;
      case 13:
        v170 = v12 - 1;
        if ( !v170 )
        {
          v173 = 300 * v2;
          goto LABEL_353;
        }
        v171 = v170 - 1;
        if ( !v171 )
        {
          v173 = 600 * v2;
          goto LABEL_353;
        }
        v172 = v171 - 1;
        if ( !v172 || v172 == 1 )
        {
          v173 = 3600 * v2;
LABEL_353:
          LODWORD(v733) = v173;
        }
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v174 = 0;
        do
          pOtherOverlayList->_4418B1(2010, v174++ + 100, v1, 65536);
        while ( v174 < 4 );
        v175 = v3->spellnum;
        v176 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v175, v1);
        v83 = 1;
        v177 = v3->spellnum;
        v178 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v177, 1u);
        v179 = v3->spellnum;
        v180 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v179, 2u);
        v181 = v3->spellnum;
        v182 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v181, 3u);
        v673 = v1;
        v732 = (int)v733 << 7;
        v662 = v1;
        v655 = v1;
        v652 = v731;
        v183 = (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
        v137 = (char *)&pParty->pPartyBuffs[5];
        goto LABEL_976;
      case 15:
        v184 = v12 - 1;
        if ( v184 )
        {
          v185 = v184 - 1;
          if ( v185 )
          {
            v186 = v185 - 1;
            if ( v186 )
            {
              if ( v186 == 1 )
                amount = 9;
            }
            else
            {
              amount = 7;
            }
          }
          else
          {
            amount = 5;
          }
        }
        else
        {
          amount = 3;
        }
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v726 = (Player *)((signed int)(60 * stru_5C6E00->uIntegerDoublePi) / 360);
        v732 = (signed int)(60 * stru_5C6E00->uIntegerDoublePi) / 360 / (amount - 1);
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.vPosition.y = pParty->vPosition.y;
        a1.vPosition.x = pParty->vPosition.x;
        a1.uAttributes = v1;
        a1.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
        a1.uSectorID = pIndoor->GetSector(
                         pParty->vPosition.x,
                         pParty->vPosition.y,
                         pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3);
        a1.uSpriteFrameID = v1;
        v187 = 8 * v3->uPlayerID;
        LOBYTE(v187) = v187 | 4;
        a1.field_58 = v187;
        a1.field_5C = a2;
        a1.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
        a1.uSoundID = LOWORD(v3->field_10);
        if ( pParty->bTurnBasedModeOn == 1 )
          LOBYTE(a1.uAttributes) |= 4u;
        v188 = (signed int)v726 / -2;
        v189 = (signed int)v726 / 2;
        while ( v188 <= v189 )
        {
          a1.uFacing = v188 + LOWORD(v715.uYawAngle);
          if ( a1.Create(
                 (signed __int16)(v188 + LOWORD(v715.uYawAngle)),
                 v715.uPitchAngle,
                 pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed,
                 v3->uPlayerID + 1) != -1
            && pParty->bTurnBasedModeOn == 1 )
            ++pTurnEngine->field_1C;
          v188 += v732;
        }
        goto LABEL_1056;
      case 16:
        if ( pParty->uFlags & 8 )
        {
          v190 = pGlobalTXT_LocalizationStrings[493];
          goto LABEL_462;
        }
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v191 = 0;
        do
          pOtherOverlayList->_4418B1(2040, v191++ + 100, v1, 65536);
        while ( v191 < 4 );
        BYTE1(pParty->uFlags) |= 1u;
        pParty->uFallSpeed = 1000;
        goto LABEL_1056;
      case 19:
        v192 = v12 - 1;
        if ( !v192 )
        {
          amount = v2;
          goto LABEL_391;
        }
        v193 = v192 - 1;
        if ( !v193 )
        {
          v196 = 2 * v2;
LABEL_389:
          amount = v196;
LABEL_391:
          v195 = 600 * v2;
          goto LABEL_392;
        }
        v194 = v193 - 1;
        if ( !v194 )
        {
          v196 = 3 * v2;
          goto LABEL_389;
        }
        if ( v194 != 1 )
          goto LABEL_393;
        amount = 4 * v2;
        v195 = 3600 * v2;
LABEL_392:
        LODWORD(v733) = v195;
LABEL_393:
        if ( pParty->uFlags & 0x30 )
        {
          v66 = pGlobalTXT_LocalizationStrings[638];
          goto LABEL_201;
        }
        if ( pPlayer->CanCastSpell(uRequiredMana) )
        {
          v197 = v3->spellnum;
          v198 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v197, v1);
          v83 = 1;
          v199 = v3->spellnum;
          v200 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v199, 1u);
          v201 = v3->spellnum;
          v202 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v201, 2u);
          v203 = v3->spellnum;
          v204 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v203, 3u);
          v673 = v1;
          v732 = (int)v733 << 7;
          v662 = v1;
          v655 = amount;
          v652 = v731;
          v183 = (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
          v137 = (char *)&pParty->pPartyBuffs[11];
LABEL_976:
          v136 = pParty->uTimePlayed + v183;
LABEL_977:
          ((SpellBuff *)v137)->Apply(v136, v652, v655, v662, v673);
LABEL_978:
          LODWORD(v727) = v83;
        }
        goto LABEL_83;
      case 21:
        if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
        {
          v190 = pGlobalTXT_LocalizationStrings[494];
LABEL_462:
          ShowStatusBarString(v190, 2u);
          pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, v1, v1, -1, v1, v1, v1, v1);
          goto LABEL_83;
        }
        if ( !pPlayers[v3->uPlayerID + 1]->GetMaxMana() )
        {
LABEL_461:
          v190 = pGlobalTXT_LocalizationStrings[428];
          goto LABEL_462;
        }
        LODWORD(v733) = 3600 * v2;
        if ( v731 == 2 || v731 == 3 || (amount = v1, v731 != 4) )
          amount = 1;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v205 = 0;
        do
          pOtherOverlayList->_4418B1(2090, v205++ + 100, v1, 65536);
        while ( v205 < 4 );
        v206 = pOtherOverlayList->_4418B1(10008, 203, v1, 65536);
        v207 = v3->uPlayerID + 1;
        v716 = v206;
        v668 = v207;
        v658 = v206;
        v653 = amount;
        v732 = (int)v733 << 7;
        v651 = v731;
        v26 = (signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
        v27 = (char *)&pParty->pPartyBuffs[7];
LABEL_101:
        v26 = (signed int)v26;
LABEL_102:
        v28 = pParty->uTimePlayed + v26;
LABEL_103:
        HIDWORD(v650) = HIDWORD(v28);
LABEL_104:
        LODWORD(v650) = v28;
        ((SpellBuff *)v27)->Apply(v650, v651, v653, v658, v668);
        goto LABEL_1056;
      case 22:
        v67 = 2;
        if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
        {
          v66 = pGlobalTXT_LocalizationStrings[495];
          goto LABEL_202;
        }
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v208 = a2 & 7;
        LODWORD(v725) = a2 & 7;
        if ( v208 == 3 )
        {
          v209 = a2 >> 3;
          LODWORD(v718) = pActors[v209].vPosition.x;
          v210 = pActors[v209].vPosition.y;
          v211 = pActors[v209].vPosition.z;
          v713 = v210;
        }
        else
        {
          v212 = stru_5C6E00->SinCos(pParty->sRotationY);
          LODWORD(v718) = pParty->vPosition.x + sub_42EBBE(2048, v212);
          v213 = stru_5C6E00->_42EBDB(pParty->sRotationY);
          v214 = sub_42EBBE(2048, v213);
          v211 = pParty->vPosition.z;
          v713 = pParty->vPosition.y + v214;
          v208 = LODWORD(v725);
        }
        v726 = (Player *)v211;
        HIDWORD(v733) = v1;
        *(float *)&v732 = (double)v211;
        LODWORD(v725) = v211 + 2500;
        v721 = v1;
        *(float *)&y = (double)(v211 + 2500);
        v730 = v208 == 3 ? a2 : 0;
        a2 = 20;
        do
        {
          v215 = rand();
          v216 = (double)v721;
          v727 = v216;
          v217 = (double)SHIDWORD(v733);
          *(float *)&uRequiredMana = v217;
          _this = (ItemGen *)(v215 % 1000);
          *((float *)&v733 + 1) = (double)(v215 % 1000) + *(float *)&v732 - *(float *)&y;
          *(float *)&v721 = v217 * v217;
          *(float *)&v726 = v216 * v216;
          if ( sqrt(*((float *)&v733 + 1) * *((float *)&v733 + 1) + *(float *)&v726 + *(float *)&v721) <= 1.0 )
          {
            LODWORD(v685) = v1;
            HIDWORD(v685) = v1;
          }
          else
          {
            v684 = (signed __int64)sqrt(*(float *)&v726 + *(float *)&v721);
            v685 = __PAIR__(
                     stru_5C6E00->Atan2(v684, (signed __int64)*((float *)&v733 + 1)),
                     stru_5C6E00->Atan2((signed __int64)v727, (signed __int64)*(float *)&uRequiredMana));
          }
          a1.stru_24.Reset();
          a1.field_48 = v3->spellnum;
          a1.field_4C = v2;
          a1.field_50 = v731;
          a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
          a1.uAttributes = v1;
          a1.vPosition.x = LODWORD(v718);
          a1.vPosition.y = v713;
          a1.uSectorID = v1;
          a1.vPosition.z = (int)((char *)_this + LODWORD(v725));
          a1.uSpriteFrameID = v1;
          a1.field_58 = 8 * v3->uPlayerID | 4;
          a1.field_5C = v730;
          a1.field_60_distance_related_prolly_lod = stru_50C198._427546((int)&_this[69].uNumCharges);
          a1.uFacing = v685;
          a1.uSoundID = LOWORD(v3->field_10);
          if ( pParty->bTurnBasedModeOn == 1 )
            a1.uAttributes = 4;
          if ( a1.Create(
                 v685,
                 SHIDWORD(v685),
                 pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed,
                 v1) != -1
            && pParty->bTurnBasedModeOn == 1 )
            ++pTurnEngine->field_1C;
          v721 = rand() % 1024 - 512;
          v218 = rand();
          v14 = a2-- == 1;
          HIDWORD(v733) = (unsigned __int64)(v218 % 1024) - 512;
        }
        while ( !v14 );
        goto LABEL_1056;
      case 23:
        v219 = v12 - 2;
        if ( v219 )
        {
          v220 = v219 - 1;
          if ( v220 )
          {
            if ( v220 == 1 )
            {
              amount = v1;
              goto LABEL_433;
            }
            v221 = 180 * v2;
          }
          else
          {
            v221 = 86400 * v2;
          }
        }
        else
        {
          v221 = 3600 * v2;
        }
        amount = v221;
LABEL_433:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v222 = (char *)pParty->pPlayers;
        HIDWORD(v733) = (int)(char *)&pParty + 2508;
        break;
      case 24:
        v224 = v12 - 2;
        if ( v224 )
        {
          v225 = v224 - 1;
          if ( v225 )
          {
            if ( v225 == 1 )
              amount = 7;
            else
              amount = 1;
          }
          else
          {
            amount = 5;
          }
        }
        else
        {
          amount = 3;
        }
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        HIDWORD(v733) = (signed int)(60 * stru_5C6E00->uIntegerDoublePi) / 360;
        if ( amount == 1 )
        {
LABEL_152:
          a1.stru_24.Reset();
          a1.field_48 = v3->spellnum;
          a1.field_50 = v731;
          a1.field_4C = v2;
          a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
          a1.vPosition.y = pParty->vPosition.y;
          v51 = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
          v671 = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
          v660 = pParty->vPosition.y;
LABEL_153:
          a1.uAttributes = v1;
          a1.vPosition.x = pParty->vPosition.x;
          a1.vPosition.z = v51;
          v52 = pIndoor->GetSector(pParty->vPosition.x, v660, v671);
          a1.uSpriteFrameID = v1;
          a1.uSectorID = v52;
          v53 = 8 * v3->uPlayerID;
          LOBYTE(v53) = v53 | 4;
          a1.field_58 = v53;
          a1.field_5C = a2;
          a1.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
          a1.uFacing = LOWORD(v715.uYawAngle);
          a1.uSoundID = LOWORD(v3->field_10);
LABEL_154:
          if ( pParty->bTurnBasedModeOn == 1 )
            LOBYTE(a1.uAttributes) |= 4u;
LABEL_156:
          v669 = v3->uPlayerID + 1;
          v36 = v715.uYawAngle;
          v659 = pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed;
          v654 = v715.uPitchAngle;
LABEL_157:
          if ( a1.Create(v36, v654, v659, v669) != -1 && pParty->bTurnBasedModeOn == 1 )
            ++pTurnEngine->field_1C;
        }
        else
        {
          v732 = SHIDWORD(v733) / (amount - 1);
          a1.stru_24.Reset();
          a1.field_48 = v3->spellnum;
          a1.field_4C = v2;
          a1.field_50 = v731;
          a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
          a1.vPosition.y = pParty->vPosition.y;
          a1.vPosition.x = pParty->vPosition.x;
          a1.uAttributes = v1;
          a1.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
          a1.uSectorID = pIndoor->GetSector(
                           pParty->vPosition.x,
                           pParty->vPosition.y,
                           pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3);
          a1.uSpriteFrameID = v1;
          v226 = 8 * v3->uPlayerID;
          LOBYTE(v226) = v226 | 4;
          a1.field_58 = v226;
          a1.field_5C = a2;
          a1.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
          a1.uSoundID = LOWORD(v3->field_10);
          if ( pParty->bTurnBasedModeOn == 1 )
            LOBYTE(a1.uAttributes) |= 4u;
          v227 = SHIDWORD(v733) / -2;
          y = (char *)(SHIDWORD(v733) / 2);
          if ( SHIDWORD(v733) / -2 <= SHIDWORD(v733) / 2 )
          {
            v228 = v715.uYawAngle;
            do
            {
              a1.uFacing = v227 + v228;
              if ( a1.Create(
                     v227 + v228,
                     v715.uPitchAngle,
                     pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed,
                     v3->uPlayerID + 1) != -1
                && pParty->bTurnBasedModeOn == 1 )
                ++pTurnEngine->field_1C;
              v227 += v732;
            }
            while ( v227 <= (signed int)y );
          }
        }
        goto LABEL_1056;
      case 27:
        if ( !pPlayers[v3->uPlayerID + 1]->GetMaxMana() )
          goto LABEL_461;
        if ( v731 == 2 || v731 != 3 && v731 != 4 )
          v229 = 600 * v2;
        else
          v229 = 3600 * v2;
        LODWORD(v733) = v229;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v716 = pOtherOverlayList->_4418B1(10005, 201, v1, 65536);
        v230 = v3->spellnum;
        v231 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v230, v1);
        v232 = 1;
        v233 = v3->spellnum;
        v234 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v233, 1u);
        v235 = v3->spellnum;
        v236 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v235, 2u);
        v237 = v3->spellnum;
        v238 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v237, 3u);
        v239 = v3->uPlayerID + 1;
        v732 = v229 << 7;
        pParty->pPartyBuffs[18].Apply(
          pParty->uTimePlayed + (signed int)(signed __int64)((double)(v229 << 7) * 0.033333335),
          v731,
          amount,
          v716,
          v239);
        if ( v731 == 4 )
          pParty->pPartyBuffs[18].uFlags = 1;
        goto LABEL_1112;
      case 28:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v240 = (char *)&pParty->pPlayers[v3->uPlayerID_2].pInventoryItems[a2];
        y = v240;
        if ( pItemsTable->pItems[*(int *)v240].uEquipType != 12 || v240[20] & 2 )
          goto LABEL_199;
        if ( v731 == 1 || v731 == 2 )
        {
          v241 = (double)v723 * 0.0099999998 + 0.5;
        }
        else
        {
          if ( v731 == 3 )
          {
            v241 = (double)v723 * 0.0099999998 + 0.69999999;
          }
          else
          {
            if ( v731 != 4 )
            {
              v241 = 0.0;
              goto LABEL_484;
            }
            v241 = (double)v723 * 0.0099999998 + 0.80000001;
          }
        }
        if ( v241 > 1.0 )
          v241 = 1.0;
LABEL_484:
        v732 = (unsigned __int8)v240[25];
        v242 = (signed __int64)((double)v732 * v241);
        v243 = y;
        y[25] = v242;
        *((int *)v243 + 4) = (unsigned __int8)v242;
        if ( (unsigned __int8)v242 <= v1 )
        {
          *(int *)v243 = v1;
          dword_50C9D0 = 113;
          dword_50C9D4 = v1;
          dword_50C9D8 = 1;
          ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2u);
          pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, v1, v1, -1, v1, v1, v1, v1);
          v3->spellnum = v1;
          goto LABEL_1165;
        }
        *((int *)v243 + 5) |= 0x40u;
        goto LABEL_1055;
      case 30:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        uRequiredMana = v1;
        HIDWORD(v733) = 10 * v2;
        v730 = 1;
        v244 = (char *)&pParty->pPlayers[v3->uPlayerID_2];
        v726 = &pParty->pPlayers[v3->uPlayerID_2];
        if ( v731 == 1 )
        {
          v245 = (int)&v244[36 * a2 + 532];
          v309 = (char *)&pItemsTable->pItems[*(int *)v245].pIconName;
          v311 = __OFSUB__(*(int *)v245, 134);
          v14 = *(int *)v245 == 134;
          v310 = *(int *)v245 - 134 < 0;
          LODWORD(v725) = (int)(char *)&pItemsTable + 48 * *(int *)v245 + 4;
          if ( (unsigned __int8)(v310 ^ v311) | v14 )
          {
            if ( *(int *)&v244[36 * a2 + 544] == v1 )
            {
              if ( *(int *)&v244[36 * a2 + 536] == v1 )
              {
                if ( *(int *)&v244[36 * a2 + 540] == v1 )
                {
                  v312 = v309[28];
                  if ( v312 )
                  {
                    if ( v312 != 1 )
                    {
                      if ( v312 != 2 )
                      {
                        _this = (ItemGen *)&v244[36 * a2 + 552];
                        if ( !(v244[36 * a2 + 552] & 2) )
                        {
                          if ( ((ItemGen *)v245)->GetValue() < 0x1C2 )
                          {
                            uRequiredMana = 1;
                            v730 = v1;
                          }
                          if ( rand() % 100 >= SHIDWORD(v733) )
                            uRequiredMana = 1;
                          if ( uRequiredMana == v1 )
                          {
                            v313 = *(char *)(LODWORD(v725) + 28);
                            if ( v313 == 3 | v313 == 4 | v313 == 5 | v313 == 6 | v313 == 7 | v313 == 8 | v313 == 9 | v313 == 10 | v313 == 11 )
                            {
                              v314 = rand() % pItemsTable->field_116D8[pItemsTable->pItems[*(int *)v245].uEquipType];
                              *(int *)(v245 + 4) = 0;
                              for ( j = pItemsTable->pEnchantments[0].field_8[pItemsTable->pItems[*(int *)v245].uEquipType
                                                                           + 1];
                                    ;
                                    j += pItemsTable->pEnchantments[*(int *)(v245 + 4)].field_8[pItemsTable->pItems[*(int *)v245].uEquipType
                                                                                                + 1] )
                              {
                                ++*(int *)(v245 + 4);
                                if ( j >= v314 )
                                  break;
                              }
                              v254 = rand();
                              v255 = pItemsTable->field_116D8[17];
                              v256 = pItemsTable->field_116D8[16];
LABEL_611:
                              *(int *)(v245 + 8) = v256 + v254 % (v255 - v256 + 1);
LABEL_612:
                              _this->uItemID |= 0x20u;
                              goto LABEL_1055;
                            }
                            goto LABEL_615;
                          }
LABEL_613:
                          v316 = _this->uItemID;
                          if ( !(BYTE1(v316) & 2) )
                          {
                            LOBYTE(v316) = v316 | 2;
                            _this->uItemID = v316;
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
LABEL_616:
          if ( LODWORD(v727) == v1 )
          {
            v317 = pGlobalTXT_LocalizationStrings[428];
            if ( v730 == v1 )
              v317 = pGlobalTXT_LocalizationStrings[585];
            ShowStatusBarString(v317, 2u);
            pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, v1, v1, -1, v1, v1, v1, v1);
            v318 = v726;
            v3->spellnum = v1;
            v318->PlaySound(43, v1);
          }
          goto LABEL_83;
        }
        if ( v731 != 2 )
        {
          if ( v731 == 3 )
          {
            v245 = (int)&v244[36 * a2 + 532];
            v269 = *(int *)v245;
            if ( *(int *)v245 > 134
              || *(int *)(v245 + 12) != v1
              || *(int *)(v245 + 4) != v1
              || *(int *)(v245 + 8) != v1
              || (_this = (ItemGen *)(v245 + 20), *(char *)(v245 + 20) & 2) )
              goto LABEL_616;
            v270 = (char *)&pItemsTable->pItems[v269].pIconName;
            LODWORD(v725) = (int)v270;
            v271 = v270[28];
            if ( v271 && v271 != 1 && v271 != 2 )
              v272 = ((ItemGen *)v245)->GetValue() < 0x1C2;
            else
              v272 = ((ItemGen *)v245)->GetValue() < 0xFA;
            if ( v272 )
            {
              uRequiredMana = 1;
              v730 = v1;
            }
            if ( rand() % 100 >= SHIDWORD(v733) )
              uRequiredMana = 1;
            if ( uRequiredMana != v1 )
              goto LABEL_613;
            v273 = v725;
            v274 = *(char *)(LODWORD(v725) + 28);
            if ( v274 == 0 | v274 == 1 | v274 == 2 | v274 == 3 | v274 == 4 | v274 == 5 | v274 == 6 | v274 == 7 | v274 == 8 | v274 == 9 | v274 == 10 | v274 == 11 )
            {
              if ( rand() % 100 < 80
                && !(*(char *)(LODWORD(v273) + 28) == 0 | *(char *)(LODWORD(v273) + 28) == 1 | *(char *)(LODWORD(v273) + 28) == 2) )
              {
                v275 = rand() % pItemsTable->field_116D8[pItemsTable->pItems[*(int *)v245].uEquipType];
                *(int *)(v245 + 4) = 0;
                for ( k = pItemsTable->pEnchantments[0].field_8[pItemsTable->pItems[*(int *)v245].uEquipType + 1];
                      ;
                      k += pItemsTable->pEnchantments[*(int *)(v245 + 4)].field_8[pItemsTable->pItems[*(int *)v245].uEquipType
                                                                                  + 1] )
                {
                  ++*(int *)(v245 + 4);
                  if ( k >= v275 )
                    break;
                }
                v254 = rand();
                v255 = pItemsTable->field_116D8[19];
                v256 = pItemsTable->field_116D8[18];
                goto LABEL_611;
              }
              v277 = pItemsTable->field_11798;
              v278 = 0;
              v725 = 0.0;
              HIDWORD(v733) = 0;
              if ( pItemsTable->field_11798 > 0 )
              {
                v730 = (int)&v679;
                do
                {
                  v279 = LOBYTE(pItemsTable->pSpecialEnchantments[v278 + 1].pName);
                  if ( !v279 || v279 == 1 )
                  {
                    v280 = *(&pItemsTable->pSpecialEnchantments[0].field_8[pItemsTable->pItems[*(int *)v245].uEquipType
                                                                        + 4]
                           + v278 * 28);
                    LODWORD(v725) += v280;
                    if ( v280 )
                    {
                      v281 = v730;
                      v730 += 4;
                      *(int *)v281 = HIDWORD(v733);
                    }
                  }
                  ++HIDWORD(v733);
                  ++v278;
                }
                while ( SHIDWORD(v733) < v277 );
              }
              v282 = rand() % SLODWORD(v725);
              v283 = v679;
              *(int *)(v245 + 12) = v679;
              v284 = pItemsTable->pSpecialEnchantments[v283].field_8[pItemsTable->pItems[*(int *)v245].uEquipType + 4];
              v285 = v282 + 1;
              if ( v284 < v285 )
              {
                for ( l = &v679; ; l = (int *)v732 )
                {
                  v287 = (int)(l + 1);
                  v732 = v287;
                  v288 = *(int *)v287;
                  *(int *)(v245 + 12) = v288;
                  v284 += pItemsTable->pSpecialEnchantments[v288].field_8[pItemsTable->pItems[*(int *)v245].uEquipType
                                                                       + 4];
                  if ( v284 >= v285 )
                    break;
                }
              }
              goto LABEL_525;
            }
          }
          else
          {
            if ( v731 != 4
              || (v245 = (int)&v726->pInventoryItems[a2], v246 = *(int *)v245, *(int *)v245 > 134)
              || v726->pInventoryItems[a2].uAdditionalValue != v1
              || v726->pInventoryItems[a2]._bonus_type != v1
              || v726->pInventoryItems[a2]._bonus_strength != v1
              || (_this = (ItemGen *)((char *)&v726->pInventoryItems[a2] + 20), v726->pInventoryItems[a2].uAttributes & 2) )
              goto LABEL_616;
            v247 = (char *)&pItemsTable->pItems[v246].pIconName;
            LODWORD(v725) = (int)v247;
            v248 = v247[28];
            if ( v248 && v248 != 1 && v248 != 2 )
              v249 = v726->pInventoryItems[a2].GetValue() < 0x1C2;
            else
              v249 = v726->pInventoryItems[a2].GetValue() < 0xFA;
            if ( v249 )
            {
              uRequiredMana = 1;
              v730 = v1;
            }
            if ( rand() % 100 >= SHIDWORD(v733) )
              uRequiredMana = 1;
            if ( uRequiredMana != v1 )
              goto LABEL_613;
            v250 = v725;
            v251 = *(char *)(LODWORD(v725) + 28);
            if ( v251 == 0 | v251 == 1 | v251 == 2 | v251 == 3 | v251 == 4 | v251 == 5 | v251 == 6 | v251 == 7 | v251 == 8 | v251 == 9 | v251 == 10 | v251 == 11 )
            {
              if ( rand() % 100 < 80
                && !(*(char *)(LODWORD(v250) + 28) == 0 | *(char *)(LODWORD(v250) + 28) == 1 | *(char *)(LODWORD(v250) + 28) == 2) )
              {
                v252 = rand() % pItemsTable->field_116D8[pItemsTable->pItems[*(int *)v245].uEquipType];
                *(int *)(v245 + 4) = 0;
                for ( m = pItemsTable->pEnchantments[0].field_8[pItemsTable->pItems[*(int *)v245].uEquipType + 1];
                      ;
                      m += pItemsTable->pEnchantments[*(int *)(v245 + 4)].field_8[pItemsTable->pItems[*(int *)v245].uEquipType
                                                                                  + 1] )
                {
                  ++*(int *)(v245 + 4);
                  if ( m >= v252 )
                    break;
                }
                v254 = rand();
                v255 = pItemsTable->field_116D8[21];
                v256 = pItemsTable->field_116D8[20];
                goto LABEL_611;
              }
              v257 = pItemsTable->field_11798;
              v258 = 0;
              v725 = 0.0;
              HIDWORD(v733) = 0;
              if ( pItemsTable->field_11798 > 0 )
              {
                v730 = (int)&v679;
                do
                {
                  v259 = LOBYTE(pItemsTable->pSpecialEnchantments[v258 + 1].pName);
                  if ( !v259 || v259 == 1 )
                  {
                    v260 = *(&pItemsTable->pSpecialEnchantments[0].field_8[pItemsTable->pItems[*(int *)v245].uEquipType
                                                                        + 4]
                           + v258 * 28);
                    LODWORD(v725) += v260;
                    if ( v260 )
                    {
                      v261 = v730;
                      v730 += 4;
                      *(int *)v261 = HIDWORD(v733);
                    }
                  }
                  ++HIDWORD(v733);
                  ++v258;
                }
                while ( SHIDWORD(v733) < v257 );
              }
              v262 = rand() % SLODWORD(v725);
              v263 = v679;
              *(int *)(v245 + 12) = v679;
              v264 = pItemsTable->pSpecialEnchantments[v263].field_8[pItemsTable->pItems[*(int *)v245].uEquipType + 4];
              v265 = v262 + 1;
              if ( v264 < v265 )
              {
                for ( ii = &v679; ; ii = (int *)v732 )
                {
                  v267 = (int)(ii + 1);
                  v732 = v267;
                  v268 = *(int *)v267;
                  *(int *)(v245 + 12) = v268;
                  v264 += pItemsTable->pSpecialEnchantments[v268].field_8[pItemsTable->pItems[*(int *)v245].uEquipType
                                                                       + 4];
                  if ( v264 >= v265 )
                    break;
                }
              }
LABEL_525:
              ++*(int *)(v245 + 12);
              goto LABEL_612;
            }
          }
LABEL_615:
          v1 = 0;
          goto LABEL_616;
        }
        v289 = (ItemGen *)&v244[36 * a2 + 532];
        _this = v289;
        v290 = v289->uItemID;
        LODWORD(v725) = (int)(char *)&pItemsTable + 48 * v290 + 4;
        if ( v290 > 134
          || _this->uAdditionalValue != v1
          || _this->_bonus_type != v1
          || _this->_bonus_strength != v1
          || (v291 = pItemsTable->pItems[v290].uEquipType) == 0
          || v291 == 1
          || v291 == 2
          || _this->uAttributes & 2 )
          goto LABEL_616;
        if ( _this->GetValue() < 0x1C2 )
          uRequiredMana = 1;
        if ( rand() % 100 >= SHIDWORD(v733) )
          uRequiredMana = 1;
        if ( uRequiredMana != v1 )
          goto LABEL_199;
        v292 = *(char *)(LODWORD(v725) + 28);
        if ( !(v292 == 3 | v292 == 4 | v292 == 5 | v292 == 6 | v292 == 7 | v292 == 8 | v292 == 9 | v292 == 10 | v292 == 11) )
        {
          v2 = v723;
          v1 = 0;
          goto LABEL_199;
        }
        if ( rand() % 100 >= 80 )
        {
          v297 = pItemsTable->field_11798;
          v294 = _this;
          v298 = 0;
          v725 = 0.0;
          HIDWORD(v733) = 0;
          if ( pItemsTable->field_11798 > 0 )
          {
            v730 = (int)&v679;
            do
            {
              v299 = LOBYTE(pItemsTable->pSpecialEnchantments[v298 + 1].pName);
              if ( !v299 || v299 == 1 )
              {
                v300 = *(&pItemsTable->pSpecialEnchantments[0].field_8[pItemsTable->pItems[v294->uItemID].uEquipType + 4]
                       + v298 * 28);
                LODWORD(v725) += v300;
                if ( v300 )
                {
                  v301 = v730;
                  v730 += 4;
                  *(int *)v301 = HIDWORD(v733);
                }
              }
              ++HIDWORD(v733);
              ++v298;
            }
            while ( SHIDWORD(v733) < v297 );
          }
          v302 = rand() % SLODWORD(v725);
          v303 = v679;
          v294->uAdditionalValue = v679;
          v304 = pItemsTable->pSpecialEnchantments[v303].field_8[pItemsTable->pItems[v294->uItemID].uEquipType + 4];
          v305 = v302 + 1;
          if ( v304 < v305 )
          {
            for ( jj = &v679; ; jj = (int *)v732 )
            {
              v307 = (int)(jj + 1);
              v732 = v307;
              v308 = *(int *)v307;
              v294->uAdditionalValue = v308;
              v304 += pItemsTable->pSpecialEnchantments[v308].field_8[pItemsTable->pItems[v294->uItemID].uEquipType + 4];
              if ( v304 >= v305 )
                break;
            }
          }
          ++v294->uAdditionalValue;
        }
        else
        {
          v293 = rand();
          v294 = _this;
          v295 = v293 % pItemsTable->field_116D8[pItemsTable->pItems[_this->uItemID].uEquipType];
          _this->_bonus_type = 0;
          for ( kk = pItemsTable->pEnchantments[0].field_8[pItemsTable->pItems[v294->uItemID].uEquipType + 1];
                ;
                kk += pItemsTable->pEnchantments[v294->_bonus_type].field_8[pItemsTable->pItems[v294->uItemID].uEquipType
                                                                         + 1] )
          {
            ++v294->_bonus_type;
            if ( kk >= v295 )
              break;
          }
          v294->_bonus_strength = pItemsTable->field_116D8[18]
                                + rand() % (pItemsTable->field_116D8[19] - pItemsTable->field_116D8[18] + 1);
        }
        v294->uAttributes |= 0x20u;
        goto LABEL_1055;
      case 31:
        amount = 10 * v2;
        if ( pPlayer->sMana < (signed int)uRequiredMana )
          goto LABEL_83;
        if ( pParty->uFlags & 0x30 && v12 != 4 || rand() % 100 >= amount && v731 != 4 )
          goto LABEL_200;
        byte_50C0C0 = LOBYTE(v3->uPlayerID);
        pMessageQueue_50CBD0->SendMessage((UIMessageType)195, v1, v1);
        goto LABEL_1056;
      case 33:
        LODWORD(v733) = 604800 * v2;
        if ( !_strcmpi(pCurrentMapName, "d05.blv") )
          goto LABEL_200;
        v319 = uRequiredMana;
        if ( pPlayer->sMana >= (signed int)uRequiredMana )
        {
          pEventTimer->Pause();
          pMessageQueue_50CBD0->SendMessage((UIMessageType)177, v1, v1);
          qword_506350 = (signed int)v733;
          _506348_current_lloyd_playerid = v3->uPlayerID;
          ::uRequiredMana = v319;
          ::sRecoveryTime = sRecoveryTime;
          dword_50633C = v3->field_10;
          dword_506338 = v3->spellnum;
          LOBYTE(v3->field_8) |= 0x20u;
        }
        goto LABEL_83;
      case 40:
        v320 = v12 - 2;
        if ( !v320 )
          goto LABEL_632;
        v321 = v320 - 1;
        if ( v321 )
        {
          if ( v321 == 1 )
            goto LABEL_634;
LABEL_632:
          v322 = 3600 * v2;
        }
        else
        {
          v322 = 86400 * v2;
        }
        amount = v322;
LABEL_634:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v323 = v3->uPlayerID_2;
        v324 = (char *)&pParty->pPlayers[v323].pConditions[15];
        if ( !pParty->pPlayers[v323].pConditions[15] )
          goto LABEL_1056;
        if ( v731 == 4 )
          goto LABEL_637;
        v732 = amount << 7;
        v663 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed - (double)(amount << 7) * 0.033333335);
        v656 = 15;
        goto LABEL_640;
      case 41:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.vPosition.y = pParty->vPosition.y;
        a1.vPosition.x = pParty->vPosition.x;
        a1.uAttributes = v1;
        a1.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
        a1.uSectorID = pIndoor->GetSector(
                         pParty->vPosition.x,
                         pParty->vPosition.y,
                         pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3);
        a1.uSpriteFrameID = v1;
        v326 = 8 * v3->uPlayerID;
        LOBYTE(v326) = v326 | 4;
        a1.field_58 = v326;
        a1.field_5C = a2;
        a1.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
        a1.uFacing = LOWORD(pParty->sRotationY);
        a1.uSoundID = LOWORD(v3->field_10);
        if ( pParty->bTurnBasedModeOn == 1 )
          LOBYTE(a1.uAttributes) |= 4u;
        v669 = v3->uPlayerID + 1;
        v659 = pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed;
        v654 = pParty->sRotationX;
        goto LABEL_125;
      case 43:
        if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
          goto LABEL_200;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        a1.uItemType = 4090;
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.vPosition.x = pParty->vPosition.x;
        a1.vPosition.y = pParty->vPosition.y;
        a1.uAttributes = v1;
        a1.uSectorID = v1;
        a1.uSpriteFrameID = v1;
        a1.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
        v327 = 8 * v3->uPlayerID;
        LOBYTE(v327) = v327 | 4;
        a1.field_60_distance_related_prolly_lod = 0;
        a1.field_58 = v327;
        a1.field_5C = a2;
        a1.uFacing = LOWORD(pParty->sRotationY);
        a1.uSoundID = LOWORD(v3->field_10);
        if ( pParty->bTurnBasedModeOn == 1 )
          a1.uAttributes = 4;
        v669 = v1;
        v659 = pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed;
        v35 = (signed int)stru_5C6E00->uIntegerHalfPi / 2;
LABEL_124:
        v654 = v35;
LABEL_125:
        v36 = pParty->sRotationY;
        goto LABEL_157;
      case 45:
        v328 = v12 - 2;
        if ( v328 )
        {
          v329 = v328 - 1;
          if ( v329 && v329 != 1 )
            v330 = 600 * v2;
          else
            v330 = 3600 * v2;
        }
        else
        {
          v330 = 1800 * v2;
        }
        LODWORD(v733) = v330;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v331 = v3->spellnum;
        v332 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v331, v1);
        v83 = 1;
        v333 = v3->spellnum;
        v334 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v333, 1u);
        v335 = v3->spellnum;
        v336 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v335, 2u);
        v337 = v3->spellnum;
        v338 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v337, 3u);
        v673 = v1;
        v732 = (int)v733 << 7;
        v662 = v1;
        v655 = v1;
        v652 = v731;
        v183 = (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
        v137 = (char *)&pParty->pPartyBuffs[3];
        goto LABEL_976;
      case 47:
        LODWORD(v733) = 300;
        v339 = v12 - 2;
        if ( v339 )
        {
          v340 = v339 - 1;
          if ( v340 )
          {
            if ( v340 != 1 )
            {
              amount = v2;
              goto LABEL_667;
            }
            v341 = 6 * v2;
          }
          else
          {
            v341 = 4 * v2;
          }
        }
        else
        {
          v341 = 2 * v2;
        }
        amount = v341;
LABEL_667:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v342 = *(int *)&v3->field_C;
        if ( v342 == v1 )
        {
          v345 = v3->uPlayerID_2;
          v346 = v3->spellnum;
          v347 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v346, v345);
          v668 = v1;
          v658 = v1;
          v653 = amount;
          LODWORD(v28) = LODWORD(pParty->uTimePlayed) + 1280;
          v651 = v731;
          HIDWORD(v650) = v1 + ((pParty->uTimePlayed + 1280) >> 32);
          v27 = (char *)&pParty->pPlayers[v3->uPlayerID_2].pPlayerBuffs[4];
          goto LABEL_104;
        }
        if ( (v342 & 7) == 3 )
        {
          v343 = v342 >> 3;
          HIDWORD(v344) = v1 + ((pParty->uTimePlayed + 1280) >> 32);
          LODWORD(v344) = LODWORD(pParty->uTimePlayed) + 1280;
          pActors[v343].pActorBuffs[11].Apply(v344, v731, amount, v1, v1);
          BYTE2(pActors[v343].uAttributes) |= 8u;
          v672 = v1;
          v661 = &pActors[v343];
LABEL_165:
          v56 = pGame->GetStru6();
          pGame->GetStru6()->_4A7E89_sparkles_on_actor_after_it_casts_buff(v661, v672);
        }
        goto LABEL_1056;
      case 49:
        v348 = v12 - 2;
        if ( !v348 )
          goto LABEL_677;
        v349 = v348 - 1;
        if ( v349 )
        {
          if ( v349 == 1 )
          {
            amount = v1;
            goto LABEL_679;
          }
LABEL_677:
          v350 = 3600 * v2;
        }
        else
        {
          v350 = 86400 * v2;
        }
        amount = v350;
LABEL_679:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v351 = &pParty->pPlayers[v3->uPlayerID_2];
        if ( !v351->pConditions[0] )
          goto LABEL_1056;
        if ( v731 == 4 )
        {
          LODWORD(v351->pConditions[0]) = v1;
          HIDWORD(v351->pConditions[0]) = v1;
          goto LABEL_904;
        }
        v732 = amount << 7;
        v351->DiscardConditionIfLastsLongerThan(
          v1,
          (signed __int64)((double)(signed __int64)pParty->uTimePlayed - (double)(amount << 7) * 0.033333335));
        if ( HIDWORD(pParty->pPlayers[v3->uPlayerID_2].pConditions[0]) | LODWORD(pParty->pPlayers[v3->uPlayerID_2].pConditions[0]) )
          goto LABEL_1056;
        v674 = v3->uPlayerID_2;
        goto LABEL_685;
      case 50:
        v354 = v12 - 2;
        if ( v354 && (v355 = v354 - 1) != 0 && v355 == 1 )
          v356 = 900 * (v2 + 4);
        else
          v356 = 300 * (v2 + 12);
        LODWORD(v733) = v356;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        if ( v731 == 1 || v731 == 2 )
        {
          v361 = v3->uPlayerID_2;
          v362 = v3->spellnum;
          v363 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v362, v361);
          v668 = v1;
          v732 = (int)v733 << 7;
          v658 = v1;
          v653 = v1;
          v651 = v731;
          v28 = pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
          v27 = (char *)&pParty->pPlayers[v3->uPlayerID_2].pPlayerBuffs[11];
          goto LABEL_103;
        }
        a2 = v1;
        v732 = (int)v733 << 7;
        v717 = (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
        v357 = &pParty->pPlayers[0].pPlayerBuffs[11];
        do
        {
          v358 = a2;
          v359 = v3->spellnum;
          v360 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v359, v358);
          v357->Apply(pParty->uTimePlayed + v717, v731, v1, v1, v1);
          ++a2;
          v357 = (SpellBuff *)((char *)v357 + 6972);
        }
        while ( (signed int)v357 < (signed int)&pParty->field_871C[508] );
        goto LABEL_1056;
      case 48:
        v364 = v12 - 2;
        if ( !v364 || (v365 = v364 - 1) != 0 && v365 != 1 )
          v366 = 60 * (v2 + 3);
        else
          v366 = 300 * v2 + 180;
        LODWORD(v733) = v366;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v726 = (Player *)sub_46A6AC((int)dword_50BF30, 100, 4096);
        v367 = pGame->GetStru6();
        pGame->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0xFFFFFFu, 0xC0u);
        ++a1.uItemType;
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.uAttributes = v1;
        a1.uSectorID = v1;
        a1.uSpriteFrameID = v1;
        v368 = v3->uPlayerID;
        a1.field_60_distance_related_prolly_lod = 0;
        a1.uFacing = v1;
        v368 *= 8;
        LOBYTE(v368) = v368 | 4;
        a1.field_58 = v368;
        a1.uSoundID = LOWORD(v3->field_10);
        for ( a2 = v1; a2 < (signed int)v726; ++a2 )
        {
          v369 = &pActors[dword_50BF30[a2]];
          if ( MonsterStats::BelongsToSupertype(v369->pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD) )
          {
            a1.vPosition.x = v369->vPosition.x;
            a1.vPosition.y = v369->vPosition.y;
            v732 = v369->uActorHeight;
            a1.vPosition.z = v369->vPosition.z - (unsigned int)(signed __int64)((double)v732 * unk_4D8548);
            v370 = 8 * dword_50BF30[a2];
            LOBYTE(v370) = v370 | 3;
            a1.field_5C = v370;
            a1.Create(0, v1, v1, v1);
            v732 = (int)v733 << 7;
            v369->pActorBuffs[4].Apply(
              pParty->uTimePlayed + (signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335),
              v731,
              v1,
              v1,
              v1);
          }
        }
        goto LABEL_1056;
      case 53:
        v371 = v12 - 2;
        if ( v371 && (v372 = v371 - 1) != 0 && v372 == 1 )
          amount = v1;
        else
          amount = 86400 * v2;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        pOtherOverlayList->_4418B1(5080, v3->uPlayerID_2 + 100, v1, 65536);
        v373 = v3->uPlayerID_2;
        if ( !(HIDWORD(pParty->pPlayers[v373].pConditions[14]) | LODWORD(pParty->pPlayers[v373].pConditions[14])) )
          goto LABEL_1056;
        v14 = v731 == 4;
        pParty->pPlayers[v373].sHealth = 1;
        if ( v14 )
        {
          v374 = v3->uPlayerID_2;
          v375 = (char *)pParty->pPlayers;
          LODWORD(pParty->pPlayers[v374].pConditions[14]) = v1;
          HIDWORD(pParty->pPlayers[v374].pConditions[14]) = v1;
          v376 = v3->uPlayerID_2;
          LODWORD(pParty->pPlayers[v376].pConditions[13]) = v1;
          HIDWORD(pParty->pPlayers[v376].pConditions[13]) = v1;
        }
        else
        {
          v732 = amount << 7;
          *(float *)&a2 = (double)(amount << 7) * 0.033333335;
          v375 = (char *)pParty->pPlayers;
          pParty->pPlayers[v3->uPlayerID_2].DiscardConditionIfLastsLongerThan(
            0xEu,
            (signed __int64)((double)(signed __int64)pParty->uTimePlayed - *(float *)&a2));
          pParty->pPlayers[v3->uPlayerID_2].DiscardConditionIfLastsLongerThan(
            0xDu,
            (signed __int64)((double)(signed __int64)pParty->uTimePlayed - *(float *)&a2));
        }
        v377 = (Player *)&v375[6972 * v3->uPlayerID_2];
        goto LABEL_720;
      case 54:
        v378 = v12 - 2;
        if ( v378 && (v379 = v378 - 1) != 0 && v379 == 1 )
          v380 = 4 * v2;
        else
          v380 = 3 * v2;
        amount = v380;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v381 = 0;
        HIDWORD(v733) = amount;
        v730 = 0;
        v382 = 1;
        do
        {
          v383 = pPlayers[v382];
          if ( !v383->pConditions[14] && !v383->pConditions[15] && !v383->pConditions[16] )
            v682[v381++] = v382;
          ++v382;
        }
        while ( v382 <= 4 );
        v384 = 0;
        v730 = v381;
        if ( v381 > v1 )
        {
          do
            HIDWORD(v733) += pPlayers[v682[v384++]]->sHealth;
          while ( v384 < v381 );
        }
        v732 = (signed __int64)((double)SHIDWORD(v733) / (double)v730);
        HIDWORD(v733) = v1;
        if ( v381 > v1 )
        {
          do
          {
            v385 = 4 * v682[HIDWORD(v733)] + 10965188;
            pPlayers[v682[HIDWORD(v733)]]->sHealth = v732;
            v726 = *(Player **)v385;
            v386 = v726->GetMaxHealth();
            if ( v726->sHealth > v386 )
              *(int *)(*(int *)v385 + 6460) = v726->GetMaxHealth();
            v387 = *(Player **)v385;
            if ( v387->sHealth > v1 )
            {
              LODWORD(v387->pConditions[13]) = v1;
              HIDWORD(v387->pConditions[13]) = v1;
            }
            v388 = HIDWORD(v733);
            v389 = LOWORD(v682[HIDWORD(v733)]) - 1;
            v390 = v3->spellnum;
            v391 = pGame->GetStru6();
            pGame->GetStru6()->SetPlayerBuffAnim(v390, v389);
            HIDWORD(v733) = v388 + 1;
          }
          while ( v388 + 1 < v730 );
        }
        goto LABEL_1056;
      case 55:
        v392 = v12 - 1;
        if ( !v392 )
        {
          v395 = 180 * v2;
          goto LABEL_750;
        }
        v393 = v392 - 1;
        if ( !v393 )
        {
          v395 = 10800 * v2;
          goto LABEL_750;
        }
        v394 = v393 - 1;
        if ( !v394 )
        {
          v395 = 259200 * v2;
LABEL_750:
          amount = v395;
          goto LABEL_751;
        }
        if ( v394 == 1 )
          amount = v1;
LABEL_751:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v396 = v3->uPlayerID_2;
        if ( HIDWORD(pParty->pPlayers[v396].pConditions[16]) | LODWORD(pParty->pPlayers[v396].pConditions[16])
          || HIDWORD(pParty->pPlayers[v396].pConditions[14]) | LODWORD(pParty->pPlayers[v396].pConditions[14]) )
        {
          if ( !(HIDWORD(pParty->pPlayers[v396].pConditions[1]) | LODWORD(pParty->pPlayers[v396].pConditions[1])) )
            pParty->pPlayers[v396].PlaySound(25, v1);
          if ( v731 == 4 )
          {
            v397 = v3->uPlayerID_2;
            LODWORD(pParty->pPlayers[v397].pConditions[16]) = v1;
            HIDWORD(pParty->pPlayers[v397].pConditions[16]) = v1;
            v398 = v3->uPlayerID_2;
            LODWORD(pParty->pPlayers[v398].pConditions[14]) = v1;
            HIDWORD(pParty->pPlayers[v398].pConditions[14]) = v1;
            v399 = v3->uPlayerID_2;
            LODWORD(pParty->pPlayers[v399].pConditions[13]) = v1;
            HIDWORD(pParty->pPlayers[v399].pConditions[13]) = v1;
            v400 = (char *)pParty->pPlayers;
          }
          else
          {
            v732 = amount << 7;
            *(float *)&a2 = (double)(amount << 7) * 0.033333335;
            v400 = (char *)pParty->pPlayers;
            pParty->pPlayers[v3->uPlayerID_2].DiscardConditionIfLastsLongerThan(
              0x10u,
              (signed __int64)((double)(signed __int64)pParty->uTimePlayed - *(float *)&a2));
            pParty->pPlayers[v3->uPlayerID_2].DiscardConditionIfLastsLongerThan(
              0xEu,
              (signed __int64)((double)(signed __int64)pParty->uTimePlayed - *(float *)&a2));
            pParty->pPlayers[v3->uPlayerID_2].DiscardConditionIfLastsLongerThan(
              0xDu,
              (signed __int64)((double)(signed __int64)pParty->uTimePlayed - *(float *)&a2));
          }
          v83 = 1;
          ((Player *)&v400[6972 * v3->uPlayerID_2])->SetCondition(1u, 1);
          v401 = pGame;
          pParty->pPlayers[v3->uPlayerID_2].sHealth = 1;
          v402 = v3->uPlayerID_2;
          v403 = v3->spellnum;
          v404 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v403, v402);
        }
        else
        {
          v83 = 1;
        }
        goto LABEL_978;
      case 61:
        v405 = v12 - 2;
        if ( !v405 )
          goto LABEL_766;
        v406 = v405 - 1;
        if ( v406 )
        {
          if ( v406 == 1 )
          {
            amount = v1;
            goto LABEL_768;
          }
LABEL_766:
          v407 = 3600 * v2;
        }
        else
        {
          v407 = 86400 * v2;
        }
        amount = v407;
LABEL_768:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v408 = v3->uPlayerID_2;
        v409 = v3->spellnum;
        v410 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v409, v408);
        v323 = v3->uPlayerID_2;
        v324 = (char *)&pParty->pPlayers[v323].pConditions[12];
        if ( !pParty->pPlayers[v323].pConditions[12] )
          goto LABEL_1056;
        if ( v731 == 4 )
          goto LABEL_637;
        v732 = amount << 7;
        v663 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed - (double)(amount << 7) * 0.033333335);
        v656 = 12;
        goto LABEL_640;
      case 56:
        v411 = v12 - 2;
        if ( v411 )
        {
          v412 = v411 - 1;
          if ( v412 )
          {
            if ( v412 == 1 )
            {
              amount = v1;
              goto LABEL_780;
            }
            v413 = 180 * v2;
          }
          else
          {
            v413 = 86400 * v2;
          }
        }
        else
        {
          v413 = 3600 * v2;
        }
        amount = v413;
LABEL_780:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v414 = v3->uPlayerID_2;
        v415 = v3->spellnum;
        v416 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v415, v414);
        v323 = v3->uPlayerID_2;
        v324 = (char *)&pParty->pPlayers[v323].pConditions[3];
        if ( !pParty->pPlayers[v323].pConditions[3] )
          goto LABEL_1056;
        if ( v731 == 4 )
          goto LABEL_637;
        v732 = amount << 7;
        v663 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed - (double)(amount << 7) * 0.033333335);
        v656 = 3;
        goto LABEL_640;
      case 59:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        if ( a2 == v1 || (a2 & 7) != 3 )
          goto LABEL_1056;
        v417 = (int)&pActors[a2 >> 3];
        v730 = v417;
        if ( !(*(char *)(v417 + 38) & 0x80) )
        {
          ((Actor *)v417)->SetRandomGoldIfTheresNoItem();
          v417 = v730;
        }
        v418 = *(int *)(v417 + 672);
        HIDWORD(v733) = v1;
        if ( pItemsTable->pItems[v418].uEquipType == 18 )
          HIDWORD(v733) = *(int *)(v417 + 684);

        //ItemGen::ItemGen(&v683);
        v683.Reset();

        v419 = *(short *)(v730 + 180);
        if ( v419 != (short)v1 )
        {
          v683.uItemID = v419;
          goto LABEL_799;
        }
        v420 = 0;
        v421 = v730 + 564;
        while ( *(int *)v421 == v1 || pItemsTable->pItems[*(int *)v421].uEquipType == 18 )
        {
          ++v420;
          v421 += 36;
          if ( v420 >= 4 )
            goto LABEL_799;
        }
        memcpy(&v683, (const void *)(v730 + 36 * v420 + 564), sizeof(v683));
        v2 = v723;
        v1 = 0;
LABEL_799:
        if ( HIDWORD(v733) != v1 )
        {
          v675 = (const char *)HIDWORD(v733);
          if ( v683.uItemID != v1 )
          {
            v422 = v683.GetDisplayName();
            sprintf(pTmpBuf2, "(%s), and %d gold", v422, v675);
            goto LABEL_807;
          }
          v664 = "%d gold";
          goto LABEL_803;
        }
        if ( v683.uItemID != v1 )
        {
          v675 = v683.GetDisplayName();
          v664 = "(%s)";
LABEL_803:
          sprintf(pTmpBuf2, v664, v675);
          goto LABEL_807;
        }
        strcpy(pTmpBuf2, "nothing");
LABEL_807:
        ShowStatusBarString(pTmpBuf2, 2u);
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.vPosition.x = *(short *)(v730 + 142);
        a1.vPosition.y = *(short *)(v730 + 144);
        v676 = *(short *)(v730 + 138);
        v665 = a1.vPosition.y;
        a1.vPosition.z = *(short *)(v730 + 138);
        v657 = a1.vPosition.x;
        goto LABEL_1087;
      case 62:
        v423 = v12 - 2;
        if ( !v423 )
          goto LABEL_813;
        v424 = v423 - 1;
        if ( v424 )
        {
          if ( v424 == 1 )
            v425 = 3600 * v2;
          else
LABEL_813:
            v425 = 300 * v2;
        }
        else
        {
          v425 = 600 * v2;
        }
        amount = v425;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v426 = a2 >> 3;
        if ( (a2 & 7) != 3 )
          goto LABEL_1056;
        v730 = 836 * v426;
        if ( stru_50C198.GetMagicalResistance(&pActors[v426], 7u) )
        {
          ((SpellBuff *)((char *)&pActors[0].pActorBuffs[1] + v730))->Reset();
          ((SpellBuff *)((char *)&pActors[0].pActorBuffs[12] + v730))->Reset();
          v732 = amount << 7;
          ((SpellBuff *)((char *)&pActors[0].pActorBuffs[9] + v730))->Apply(
            pParty->uTimePlayed + (signed __int64)((double)(amount << 7) * 0.033333335),
            v731,
            v1,
            v1,
            v1);
          *(&pActors[0].pMonsterInfo.uHostilityType + v730) = MonsterInfo::Hostility_Long;
        }
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        v60 = pObjectList->ObjectIDByItemID(a1.uItemType);
        v61 = v730;
        goto LABEL_1086;
      case 66:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        amount = 600 * v2;
        v427 = a2 >> 3;
        if ( (a2 & 7) != 3 )
          goto LABEL_1056;
        v730 = 836 * v427;
        if ( MonsterStats::BelongsToSupertype(pActors[v427].pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD) )
          goto LABEL_83;
        if ( stru_50C198.GetMagicalResistance((Actor *)((char *)pActors + v730), 7u) )
        {
          ((SpellBuff *)((char *)&pActors[0].pActorBuffs[9] + v730))->Reset();
          ((SpellBuff *)((char *)&pActors[0].pActorBuffs[1] + v730))->Reset();
          v732 = amount << 7;
          ((SpellBuff *)((char *)&pActors[0].pActorBuffs[12] + v730))->Apply(
            pParty->uTimePlayed + (signed __int64)((double)(amount << 7) * 0.033333335),
            v731,
            v1,
            v1,
            v1);
        }
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        v60 = pObjectList->ObjectIDByItemID(a1.uItemType);
        v61 = v730;
        goto LABEL_1086;
      case 63:
        v428 = v12 - 2;
        if ( v428 && (v429 = v428 - 1) != 0 && v429 == 1 )
          v430 = 300 * v2;
        else
          v430 = 180 * v2;
        amount = v430;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v726 = (Player *)sub_46A6AC((int)dword_50BF30, 100, 4096);
        v431 = pGame->GetStru6();
        pGame->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0xA0A0Au, 0xC0u);
        ++a1.uItemType;
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.uAttributes = v1;
        a1.uSectorID = v1;
        a1.uSpriteFrameID = v1;
        v432 = v3->uPlayerID;
        a1.field_60_distance_related_prolly_lod = 0;
        a1.uFacing = v1;
        v432 *= 8;
        LOBYTE(v432) = v432 | 4;
        a1.field_58 = v432;
        a1.uSoundID = LOWORD(v3->field_10);
        for ( a2 = v1; a2 < (signed int)v726; ++a2 )
        {
          v433 = &pActors[dword_50BF30[a2]];
          if ( MonsterStats::BelongsToSupertype(v433->pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD) )
            break;
          a1.vPosition.x = v433->vPosition.x;
          a1.vPosition.y = v433->vPosition.y;
          v732 = v433->uActorHeight;
          a1.vPosition.z = v433->vPosition.z - (unsigned int)(signed __int64)((double)v732 * unk_4D8548);
          v434 = 8 * dword_50BF30[a2];
          LOBYTE(v434) = v434 | 3;
          a1.field_5C = v434;
          a1.Create(0, v1, v1, v1);
          if ( stru_50C198.GetMagicalResistance(v433, 7u) )
          {
            v732 = amount << 7;
            v433->pActorBuffs[4].Apply(
              pParty->uTimePlayed + (signed __int64)((double)(amount << 7) * 0.033333335),
              v731,
              v1,
              v1,
              v1);
          }
        }
        goto LABEL_1056;
      case 64:
        v435 = v12 - 2;
        if ( v435 && (v436 = v435 - 1) != 0 && v436 == 1 )
          amount = v1;
        else
          amount = 86400 * v2;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v437 = v3->uPlayerID_2;
        v438 = v3->spellnum;
        v439 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v438, v437);
        v440 = v3->uPlayerID_2;
        if ( HIDWORD(pParty->pPlayers[v440].pConditions[5]) | LODWORD(pParty->pPlayers[v440].pConditions[5]) )
        {
          if ( !(HIDWORD(pParty->pPlayers[v440].pConditions[1]) | LODWORD(pParty->pPlayers[v440].pConditions[1])) )
            pParty->pPlayers[v440].PlaySound(25, v1);
          if ( v731 == 4 )
          {
            v441 = v3->uPlayerID_2;
            LODWORD(pParty->pPlayers[v441].pConditions[5]) = v1;
            HIDWORD(pParty->pPlayers[v441].pConditions[5]) = v1;
          }
          else
          {
            v732 = amount << 7;
            pParty->pPlayers[v3->uPlayerID_2].DiscardConditionIfLastsLongerThan(
              5u,
              (signed __int64)((double)(signed __int64)pParty->uTimePlayed - (double)(amount << 7) * 0.033333335));
          }
          v377 = &pParty->pPlayers[v3->uPlayerID_2];
LABEL_720:
          v377->SetCondition(1u, v1);
        }
        goto LABEL_1056;
      case 42:
        v442 = v12 - 2;
        if ( !v442 )
          goto LABEL_855;
        v443 = v442 - 1;
        if ( v443 )
        {
          if ( v443 == 1 )
            v444 = 4 * v2;
          else
LABEL_855:
            v444 = 2 * v2;
        }
        else
        {
          v444 = 3 * v2;
        }
        amount = v444;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v445 = a2 >> 3;
        if ( (a2 & 7) == 2 )
        {
          v449 = (char *)&pLayingItems[v445].stru_24;
          v450 = *(int *)v449;
          if ( pItemsTable->pItems[v450].uEquipType == 18 )
          {
            party_finds_gold(*((int *)v449 + 3), 0);
            viewparams->bRedrawGameUI = 1;
          }
          else
          {
            sprintf(pTmpBuf2, pGlobalTXT_LocalizationStrings[471], pItemsTable->pItems[v450].pUnidentifiedName);
            ShowStatusBarString(pTmpBuf2, 2u);
            if ( !pParty->AddItem(&pLayingItems[v445].stru_24) )
              pParty->SetHoldingItem(&pLayingItems[v445].stru_24);
          }
          LayingItem::_42F933(v445);
        }
        else
        {
          if ( (a2 & 7) == 3 )
          {
            stru_50C198.LootActor(&pActors[v445]);
          }
          else
          {
            if ( (a2 & 7) != 5 )
            {
              if ( (a2 & 7) != 6 )
                goto LABEL_1056;
              dword_507CD8 = 1;
              v677 = 1;
              if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
                v446 = pIndoor->pFaceExtras[pIndoor->pFaces[v445].uFaceExtraID].uEventID;
              else
                v446 = pOutdoor->pBModels[a2 >> 9].pFaces[v445 & 0x3F].sCogTriggeredID;
              goto LABEL_866;
            }
            v447 = &pLevelDecorations[v445];
            dword_507CD8 = 1;
            v448 = v447->field_16_event_id;
            if ( v448 != (short)v1 )
            {
              v677 = 1;
              v446 = v448;
LABEL_866:
              EventProcessor(v446, a2, v677);
              goto LABEL_1056;
            }
            if ( v447->IsInteractive() )
            {
              _5C3420_pDecoration = v447;
              EventProcessor(stru_5E4C90._decor_events[v447->_idx_in_stru123 - 75] + 380, 0, 1);
              _5C3420_pDecoration = (LevelDecoration *)v1;
            }
          }
        }
        goto LABEL_1056;
      case 67:
        v451 = v12 - 2;
        if ( v451 )
        {
          v452 = v451 - 1;
          if ( v452 )
          {
            if ( v452 == 1 )
            {
              amount = v1;
              goto LABEL_883;
            }
            v453 = 180 * v2;
          }
          else
          {
            v453 = 86400 * v2;
          }
        }
        else
        {
          v453 = 3600 * v2;
        }
        amount = v453;
LABEL_883:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v454 = v3->uPlayerID_2;
        v455 = v3->spellnum;
        v456 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v455, v454);
        v323 = v3->uPlayerID_2;
        v324 = (char *)&pParty->pPlayers[v323].pConditions[1];
        if ( !pParty->pPlayers[v323].pConditions[1] )
          goto LABEL_1056;
        if ( v731 == 4 )
        {
LABEL_637:
          *(int *)v324 = v1;
          *((int *)v324 + 1) = v1;
          goto LABEL_1056;
        }
        v732 = amount << 7;
        v663 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed - (double)(amount << 7) * 0.033333335);
        v656 = 1;
LABEL_640:
        v325 = &pParty->pPlayers[v323];
        goto LABEL_641;
      case 68:
        v457 = v12 - 2;
        if ( v457 )
        {
          v458 = v457 - 1;
          if ( v458 )
          {
            if ( v458 == 1 )
              v459 = 5 * v2 + 5;
            else
              v459 = 2 * v2 + 5;
          }
          else
          {
            v459 = 4 * v2 + 5;
          }
        }
        else
        {
          v459 = 3 * v2 + 5;
        }
        amount = v459;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v460 = *(int *)&v3->field_C;
        if ( v460 == v1 )
        {
          pParty->pPlayers[v3->uPlayerID_2].Heal(amount);
LABEL_904:
          v674 = v3->uPlayerID_2;
LABEL_685:
          v352 = v3->spellnum;
          v353 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v352, v674);
        }
        else
        {
          if ( (v460 & 7) == 3 )
          {
            v461 = &pActors[v460 >> 3];
            v462 = v461->uAIState;
            v463 = v461->pMonsterInfo.uHP;
            if ( v462 != 5 )
            {
              if ( v462 != 4 )
              {
                if ( v462 != 19 )
                {
                  if ( v462 != 11 )
                  {
                    v461->sCurrentHP += amount;
                    if ( v461->sCurrentHP > v463 )
                      v461->sCurrentHP = v463;
                  }
                }
              }
            }
          }
        }
        goto LABEL_1056;
      case 72:
        v464 = v12 - 2;
        if ( !v464 )
          goto LABEL_910;
        v465 = v464 - 1;
        if ( v465 )
        {
          if ( v465 == 1 )
          {
            amount = v1;
            goto LABEL_912;
          }
LABEL_910:
          v466 = 3600 * v2;
        }
        else
        {
          v466 = 86400 * v2;
        }
        amount = v466;
LABEL_912:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v467 = v3->uPlayerID_2;
        v468 = v3->spellnum;
        v469 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v468, v467);
        v470 = v3->uPlayerID_2;
        if ( !(HIDWORD(pParty->pPlayers[v470].pConditions[6]) | LODWORD(pParty->pPlayers[v470].pConditions[6]))
          && !(HIDWORD(pParty->pPlayers[v470].pConditions[8]) | LODWORD(pParty->pPlayers[v470].pConditions[8]))
          && !(HIDWORD(pParty->pPlayers[v470].pConditions[10]) | LODWORD(pParty->pPlayers[v470].pConditions[10])) )
          goto LABEL_1056;
        if ( v731 == 4 )
        {
          LODWORD(pParty->pPlayers[v470].pConditions[6]) = v1;
          HIDWORD(pParty->pPlayers[v470].pConditions[6]) = v1;
          v471 = v3->uPlayerID_2;
          LODWORD(pParty->pPlayers[v471].pConditions[8]) = v1;
          HIDWORD(pParty->pPlayers[v471].pConditions[8]) = v1;
          v472 = v3->uPlayerID_2;
          LODWORD(pParty->pPlayers[v472].pConditions[10]) = v1;
          HIDWORD(pParty->pPlayers[v472].pConditions[10]) = v1;
          goto LABEL_1056;
        }
        v732 = amount << 7;
        *(float *)&a2 = (double)(amount << 7) * 0.033333335;
        pParty->pPlayers[v470].DiscardConditionIfLastsLongerThan(
          6u,
          (signed __int64)((double)(signed __int64)pParty->uTimePlayed - *(float *)&a2));
        v473 = (char *)pParty->pPlayers;
        pParty->pPlayers[v3->uPlayerID_2].DiscardConditionIfLastsLongerThan(
          8u,
          (signed __int64)((double)(signed __int64)pParty->uTimePlayed - *(float *)&a2));
        v663 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed - *(float *)&a2);
        v656 = 10;
        goto LABEL_937;
      case 75:
        amount = v2;
        LODWORD(v733) = 3600 * v2;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v474 = v3->spellnum;
        v475 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v474, v1);
        v476 = v3->spellnum;
        v477 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v476, 1u);
        v478 = v3->spellnum;
        v479 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v478, 2u);
        v480 = v3->spellnum;
        v481 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v480, 3u);
        v668 = v1;
        v732 = (int)v733 << 7;
        v658 = v1;
        v653 = v2;
        v651 = v731;
        v26 = (signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
        v27 = (char *)&pParty->pPartyBuffs[13];
        goto LABEL_101;
      case 73:
        LODWORD(v733) = 3600 * v2;
        amount = v2;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        if ( v731 == 4 )
        {
          v482 = v3->spellnum;
          v483 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v482, v1);
          v484 = v3->spellnum;
          v485 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v484, 1u);
          v486 = v3->spellnum;
          v487 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v486, 2u);
          v488 = v3->spellnum;
          v489 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v488, 3u);
          v732 = (int)v733 << 7;
          v717 = (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
          pParty->pPlayers[0].pPlayerBuffs[6].Apply(pParty->uTimePlayed + v717, 4u, v2, v2, v1);
          pParty->pPlayers[1].pPlayerBuffs[6].Apply(pParty->uTimePlayed + v717, 4u, v2, v2, v1);
          pParty->pPlayers[2].pPlayerBuffs[6].Apply(pParty->uTimePlayed + v717, 4u, v2, v2, v1);
          v668 = v1;
          v658 = v2;
          v653 = v2;
          LODWORD(v28) = LODWORD(pParty->uTimePlayed) + v717;
          v651 = 4;
          HIDWORD(v650) = (pParty->uTimePlayed + v717) >> 32;
          v27 = (char *)&pParty->pPlayers[3].pPlayerBuffs[6];
          goto LABEL_104;
        }
        v490 = v3->uPlayerID_2;
        v491 = v3->spellnum;
        v492 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v491, v490);
        v668 = v1;
        v732 = (int)v733 << 7;
        v658 = v2;
        v653 = v2;
        v651 = v731;
        v28 = pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
        v27 = (char *)&pParty->pPlayers[v3->uPlayerID_2].pPlayerBuffs[6];
        goto LABEL_103;
      case 74:
        v493 = v12 - 2;
        if ( v493 && (v494 = v493 - 1) != 0 && v494 == 1 )
          amount = v1;
        else
          amount = 86400 * v2;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v495 = v3->uPlayerID_2;
        v496 = v3->spellnum;
        v497 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v496, v495);
        v498 = v3->uPlayerID_2;
        if ( !(HIDWORD(pParty->pPlayers[v498].pConditions[7]) | LODWORD(pParty->pPlayers[v498].pConditions[7]))
          && !(HIDWORD(pParty->pPlayers[v498].pConditions[9]) | LODWORD(pParty->pPlayers[v498].pConditions[9]))
          && !(HIDWORD(pParty->pPlayers[v498].pConditions[11]) | LODWORD(pParty->pPlayers[v498].pConditions[11])) )
          goto LABEL_1056;
        if ( v731 == 4 )
        {
          LODWORD(pParty->pPlayers[v498].pConditions[7]) = v1;
          HIDWORD(pParty->pPlayers[v498].pConditions[7]) = v1;
          v499 = v3->uPlayerID_2;
          LODWORD(pParty->pPlayers[v499].pConditions[9]) = v1;
          HIDWORD(pParty->pPlayers[v499].pConditions[9]) = v1;
          v500 = v3->uPlayerID_2;
          LODWORD(pParty->pPlayers[v500].pConditions[11]) = v1;
          HIDWORD(pParty->pPlayers[v500].pConditions[11]) = v1;
        }
        else
        {
          v732 = amount << 7;
          *(float *)&a2 = (double)(amount << 7) * 0.033333335;
          pParty->pPlayers[v498].DiscardConditionIfLastsLongerThan(
            7u,
            (signed __int64)((double)(signed __int64)pParty->uTimePlayed - *(float *)&a2));
          v473 = (char *)pParty->pPlayers;
          pParty->pPlayers[v3->uPlayerID_2].DiscardConditionIfLastsLongerThan(
            9u,
            (signed __int64)((double)(signed __int64)pParty->uTimePlayed - *(float *)&a2));
          v663 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed - *(float *)&a2);
          v656 = 11;
LABEL_937:
          v325 = (Player *)&v473[6972 * v3->uPlayerID_2];
LABEL_641:
          v325->DiscardConditionIfLastsLongerThan(v656, v663);
        }
        goto LABEL_1056;
      case 77:
        amount = 5 * v2 + 10;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v501 = pParty->pPlayers;
        do
        {
          v502 = v3->spellnum;
          v503 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v502, v1);
          v501->Heal(amount);
          ++v501;
          ++v1;
        }
        while ( (signed int)v501 < (signed int)pParty->pHirelings );
        goto LABEL_1056;
      case 80:
        sRecoveryTime -= v2;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v504 = pGame->GetStru6();
        pGame->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0xAFF0Au, 0xC0u);
        v505 = sub_46A6AC((int)dword_50BF30, 100, 4096);
        ++a1.uItemType;
        HIDWORD(v733) = v505;
        v690 = v1;
        v689 = v1;
        v688 = v1;
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.uAttributes = v1;
        a1.uSectorID = v1;
        a1.uSpriteFrameID = v1;
        v506 = v3->uPlayerID;
        a1.field_60_distance_related_prolly_lod = 0;
        a1.uFacing = v1;
        v506 *= 8;
        LOBYTE(v506) = v506 | 4;
        a1.field_58 = v506;
        a1.uSoundID = LOWORD(v3->field_10);
        a2 = v1;
        if ( SHIDWORD(v733) > v1 )
        {
          do
          {
            v507 = dword_50BF30[a2];
            a1.vPosition.x = pActors[v507].vPosition.x;
            a1.vPosition.y = pActors[v507].vPosition.y;
            v732 = pActors[v507].uActorHeight;
            a1.vPosition.z = pActors[v507].vPosition.z - (unsigned int)(signed __int64)((double)v732 * unk_4D8548);
            v508 = 8 * dword_50BF30[a2];
            LOBYTE(v508) = v508 | 3;
            a1.field_5C = v508;
            v509 = a1.Create(0, v1, v1, v1);
            v510 = a2;
            DamageMonsterFromParty(8 * v509 | 2, dword_50BF30[a2], (Vec3_int_ *)&v688);
            a2 = v510 + 1;
          }
          while ( v510 + 1 < SHIDWORD(v733) );
        }
        for ( a2 = v1; a2 < SHIDWORD(v733); ++a2 )
        {
          v511 = &pActors[dword_50BF30[a2]];
          a1.vPosition.x = v511->vPosition.x;
          a1.vPosition.y = v511->vPosition.y;
          v732 = v511->uActorHeight;
          a1.vPosition.z = v511->vPosition.z - (unsigned int)(signed __int64)((double)v732 * unk_4D8548);
          v512 = 8 * dword_50BF30[a2];
          LOBYTE(v512) = v512 | 3;
          a1.field_5C = v512;
          a1.Create(0, v1, v1, v1);
          v513 = v511->pActorBuffs;
          v726 = (Player *)22;
          do
          {
            v513->Reset();
            ++v513;
            v726 = (Player *)((char *)v726 - 1);
          }
          while ( *(float *)&v726 != 0.0 );
        }
        goto LABEL_1056;
      case 82:
        v514 = v12 - 2;
        if ( !v514 )
          goto LABEL_955;
        v515 = v514 - 1;
        if ( v515 )
        {
          if ( v515 == 1 )
          {
            v516 = 900 * v2;
            amount = 5;
          }
          else
          {
LABEL_955:
            v516 = 300 * v2;
            amount = 1;
          }
        }
        else
        {
          v516 = 900 * v2;
          amount = 3;
        }
        v733 = __PAIR__(v1, v516);
        v517 = 8 * v3->uPlayerID;
        LOBYTE(v517) = v517 | 4;
        if ( (signed int)uNumActors > v1 )
        {
          v518 = (char *)&pActors[0].uAIState;
          v726 = (Player *)uNumActors;
          do
          {
            v519 = *(short *)v518;
            if ( *(short *)v518 != 5 && v519 != 11 && v519 != 19 && v517 == *((int *)v518 + 159) )
              ++HIDWORD(v733);
            v518 += 836;
            v726 = (Player *)((char *)v726 - 1);
          }
          while ( *(float *)&v726 != 0.0 );
        }
        if ( SHIDWORD(v733) >= amount )
        {
          v66 = pGlobalTXT_LocalizationStrings[648];
          goto LABEL_201;
        }
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        sub_44FA4C_spawn_light_elemental(v3->uPlayerID, v731, v733);
        goto LABEL_1056;
      case 83:
        v520 = v12 - 2;
        if ( !v520 )
          goto LABEL_973;
        v521 = v520 - 1;
        if ( v521 )
        {
          if ( v521 == 1 )
          {
            LODWORD(v733) = 18000 * v2;
            v522 = 5 * v2 + 10;
          }
          else
          {
LABEL_973:
            LODWORD(v733) = 10800 * v2;
            v522 = 3 * v2 + 10;
          }
        }
        else
        {
          LODWORD(v733) = 14400 * v2;
          v522 = 4 * v2 + 10;
        }
        amount = v522;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v523 = v3->spellnum;
        v524 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v523, v1);
        v83 = 1;
        v525 = v3->spellnum;
        v526 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v525, 1u);
        v527 = v3->spellnum;
        v528 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v527, 2u);
        v529 = v3->spellnum;
        v530 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v529, 3u);
        v673 = v1;
        v732 = (int)v733 << 7;
        v662 = v1;
        v655 = amount;
        v652 = v731;
        v183 = (signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
        v137 = (char *)&pParty->pPartyBuffs[2];
        goto LABEL_976;
      case 84:
        v67 = 2;
        if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
        {
          v66 = pGlobalTXT_LocalizationStrings[497];
          goto LABEL_202;
        }
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v531 = sub_46A6AC((int)dword_50BF30, 100, 4096);
        ++a1.uItemType;
        v726 = (Player *)v531;
        v696 = v1;
        v695 = v1;
        v694 = v1;
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.uAttributes = v1;
        a1.uSectorID = v1;
        a1.uSpriteFrameID = v1;
        v532 = v3->uPlayerID;
        a1.field_60_distance_related_prolly_lod = 0;
        a1.uFacing = v1;
        v532 *= 8;
        LOBYTE(v532) = v532 | 4;
        a1.field_58 = v532;
        a1.uSoundID = LOWORD(v3->field_10);
        a2 = v1;
        if ( (signed int)v726 > v1 )
        {
          do
          {
            v533 = dword_50BF30[a2];
            a1.vPosition.x = pActors[v533].vPosition.x;
            a1.vPosition.y = pActors[v533].vPosition.y;
            v732 = pActors[v533].uActorHeight;
            a1.vPosition.z = pActors[v533].vPosition.z - (unsigned int)(signed __int64)((double)v732 * unk_4D8548);
            v534 = 8 * dword_50BF30[a2];
            LOBYTE(v534) = v534 | 3;
            a1.field_5C = v534;
            v535 = a1.Create(0, v1, v1, v1);
            v536 = a2;
            DamageMonsterFromParty(8 * v535 | 2, dword_50BF30[a2], (Vec3_int_ *)&v694);
            a2 = v536 + 1;
          }
          while ( v536 + 1 < (signed int)v726 );
        }
        v537 = pGame->GetStru6();
        pGame->GetStru6()->_4A8BFC();
        goto LABEL_1056;
      case 85:
        v538 = v12 - 2;
        if ( v538 && (v539 = v538 - 1) != 0 && v539 == 1 )
        {
          amount = 5 * v2;
          v540 = 18000 * v2;
        }
        else
        {
          amount = 4 * v2;
          v540 = 14400 * v2;
        }
        v730 = v540;
        LODWORD(v733) = v540;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v541 = v3->spellnum;
        v542 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v541, v1);
        v543 = v3->spellnum;
        v544 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v543, 1u);
        v545 = v3->spellnum;
        v546 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v545, 2u);
        v547 = v3->spellnum;
        v548 = pGame->GetStru6();
        pGame->GetStru6()->SetPlayerBuffAnim(v547, 3u);
        v732 = v730 << 7;
        v549 = (double)(v730 << 7) * 0.033333335;
        *((float *)&v733 + 1) = v549;
        v712 = (signed __int64)v549;
        pParty->pPartyBuffs[ 1].Apply(pParty->uTimePlayed + (signed __int64)v549, v731, amount, v1, v1);
        pParty->pPartyBuffs[12].Apply(pParty->uTimePlayed + v712, v731, amount, v1, v1);
        pParty->pPartyBuffs[ 6].Apply(pParty->uTimePlayed + v712, v731, amount, v1, v1);
        pParty->pPartyBuffs[17].Apply(pParty->uTimePlayed + v712, v731, amount, v1, v1);
        pParty->pPartyBuffs[ 0].Apply(pParty->uTimePlayed + v712, v731, amount, v1, v1);
        pParty->pPartyBuffs[ 4].Apply(pParty->uTimePlayed + v712, v731, amount, v1, v1);
        v550 = v2 + 5;
        pParty->pPartyBuffs[ 5].Apply(
          (signed __int64)((double)(signed __int64)pParty->uTimePlayed + *((float *)&v733 + 1)),
          v731,
          v550,
          v1,
          v1);
        v668 = v1;
        v658 = v1;
        v653 = v550;
        v651 = v731;
        v28 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed + *((float *)&v733 + 1));
LABEL_992:
        v27 = (char *)&pParty->pPartyBuffs[19];
        goto LABEL_103;
      case 86:
        v551 = v12 - 2;
        if ( !v551 )
          goto LABEL_998;
        v552 = v551 - 1;
        if ( v552 )
        {
          if ( v552 == 1 )
          {
            amount = 15;
            HIDWORD(v733) = 20;
            goto LABEL_1000;
          }
LABEL_998:
          v678 = 4;
        }
        else
        {
          v678 = 12;
        }
        amount = v678;
        HIDWORD(v733) = v678;
LABEL_1000:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        y = (char *)(60 * (v2 * HIDWORD(v733) + 60));
        v732 = (300 * amount * v2 + 60) << 7;
        v730 = v2 + 5;
        v726 = (Player *)v1;
        v553 = (char *)&pParty->pPlayers[0].pConditions[1];
        *((float *)&v733 + 1) = (double)v732 * 0.033333335;
        do
        {
          v554 = v3->spellnum;
          v555 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v554, v1);
          v556 = v3->spellnum;
          v557 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v556, 1u);
          v558 = v3->spellnum;
          v559 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v558, 2u);
          v560 = v3->spellnum;
          v561 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v560, 3u);
          ((SpellBuff *)(v553 + 6056))->Apply(
            (signed __int64)((double)(signed __int64)pParty->uTimePlayed + *((float *)&v733 + 1)),
            v731,
            v730,
            v1,
            v1);
          if ( *(_QWORD *)v553 )
            v726 = (Player *)1;
          v553 += 6972;
        }
        while ( (signed int)v553 < (signed int)&pParty->pHirelings[0].uFlags );
        v562 = v731;
        pParty->pPartyBuffs[9].Apply(
          (signed __int64)((double)(signed __int64)pParty->uTimePlayed + *((float *)&v733 + 1)),
          v731,
          v730,
          v1,
          v1);
        pParty->pPartyBuffs[14].Apply(
          (signed __int64)((double)(signed __int64)pParty->uTimePlayed + *((float *)&v733 + 1)),
          v562,
          v1,
          v1,
          v1);
        pParty->pPartyBuffs[15].Apply(
          (signed __int64)((double)(signed __int64)pParty->uTimePlayed + *((float *)&v733 + 1)),
          v562,
          v730,
          v1,
          v1);
        if ( v726 != (Player *)v1 )
          goto LABEL_1056;
        v668 = v1;
        v732 = (int)y << 7;
        v658 = v1;
        v653 = v730;
        v651 = v562;
        v28 = (signed __int64)((double)(signed int)((int)y << 7) * 0.033333335
                             + (double)(signed __int64)pParty->uTimePlayed);
        v27 = (char *)&pParty->pPartyBuffs[8];
        goto LABEL_103;
      case 88:
        amount = 3;
        if ( pPlayer->uNumDivineInterventionCastsThisDay >= 3u )
          goto LABEL_200;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        a2 = v1;
        _this = (ItemGen *)&pPlayers[1];
        do
        {
          v563 = 0;
          do
          {
            v564 = _this->uItemID;
            *(int *)(v563 + _this->uItemID) = v1;
            v563 += 8;
            *(int *)(v563 + v564 - 4) = v1;
          }
          while ( v563 <= 128 );
          v565 = ((Player *)_this->uItemID)->GetMaxHealth();
          v566 = (Player **)_this;
          *(int *)(_this->uItemID + 6460) = v565;
          v567 = (*v566)->GetMaxMana();
          v568 = a2;
          *(int *)(_this->uItemID + 6464) = v567;
          v569 = v3->spellnum;
          v570 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v569, v568);
          ++a2;
          _this = (ItemGen *)((char *)_this + 4);
        }
        while ( (signed int)this < (signed int)&qword_A750D8 );
        v571 = pPlayer;
        v572 = (char *)&pPlayer->sAgeModifier;
        if ( pPlayer->sAgeModifier + 10 >= 120 )
          *(short *)v572 = 120;
        else
          *(short *)v572 = pPlayer->sAgeModifier + 10;
        sRecoveryTime += -5 * v2;
        ++v571->uNumDivineInterventionCastsThisDay;
        goto LABEL_1056;
      case 89:
        v573 = v12 - 2;
        if ( v573 )
        {
          v574 = v573 - 1;
          if ( v574 )
          {
            if ( v574 == 1 )
              v575 = 5 * v2;
            else
              v575 = 2 * v2;
          }
          else
          {
            v575 = 4 * v2;
          }
        }
        else
        {
          v575 = 3 * v2;
        }
        amount = v575;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v576 = *(int *)&v3->field_C;
        if ( v576 == v1 )
        {
          v583 = v3->uPlayerID_2;
          v584 = v3->spellnum;
          v585 = (char *)&pParty->pPlayers[v3->uPlayerID_2];
          v586 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v584, v583);
          if ( *((_QWORD *)v585 + 14) )
          {
            ((Player *)v585)->SetCondition(0x11u, 1);
            v587 = ((Player *)v585)->GetSexByVoice();
            ReloadPlayerPortraits(v3->uPlayerID_2, (v587 != 0) + 23);
            *((_QWORD *)v585 + 17) = pParty->uTimePlayed;
          }
          goto LABEL_83;
        }
        v577 = (Player *)(v576 >> 3);
        v726 = v577;
        if ( v577 == (Player *)-1 )
        {
          v66 = pGlobalTXT_LocalizationStrings[496];
          goto LABEL_201;
        }
        v578 = (int)&pActors[(int)v577];
        v721 = v578;
        if ( *(short *)(v578 + 40) > (signed __int16)v1 || (v579 = *(short *)(v578 + 176), v579 != 5) && v579 != 4 )
          goto LABEL_200;
        ++a1.uItemType;
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.uAttributes = v1;
        a1.uSectorID = v1;
        a1.uSpriteFrameID = v1;
        v580 = v3->uPlayerID;
        a1.field_60_distance_related_prolly_lod = 0;
        v581 = v721;
        v580 *= 8;
        LOBYTE(v580) = v580 | 4;
        a1.uFacing = v1;
        a1.field_58 = v580;
        a1.uSoundID = LOWORD(v3->field_10);
        a1.vPosition.x = *(short *)(v721 + 142);
        a1.vPosition.y = *(short *)(v721 + 144);
        v732 = *(short *)(v721 + 138);
        v582 = 8 * (int)v726;
        a1.vPosition.z = *(short *)(v721 + 146) - (unsigned int)(signed __int64)((double)v732 * unk_4D8548);
        LOBYTE(v582) = 8 * (char)v726 | 3;
        a1.field_5C = v582;
        a1.Create(0, v1, v1, v1);
        if ( *(char *)(v581 + 52) > amount )
          goto LABEL_83;
        Actor::Resurrect((unsigned int)v726);
        *(char *)(v581 + 61) = 0;
        *(char *)(v581 + 53) = 0;
        *(char *)(v581 + 54) = 0;
        *(char *)(v581 + 55) = 0;
        *(char *)(v581 + 56) = 0;
        *(char *)(v581 + 57) = 0;
        *(int *)(v581 + 712) = 9999;
        *(char *)(v581 + 38) &= 0xF7u;
        *(int *)(v581 + 708) = v1;
        ((SpellBuff *)(v581 + 356))->Reset();
        ((SpellBuff *)(v581 + 228))->Reset();
        ((SpellBuff *)(v581 + 404))->Reset();
        if ( *(short *)(v581 + 40) > 10 * amount )
          *(short *)(v581 + 40) = 10 * amount;
        goto LABEL_1056;
      case 91:
        v588 = v12 - 1;
        amount = 16;
        if ( v588 && (v589 = v588 - 1) != 0 && (v590 = v589 - 1) != 0 )
        {
          if ( v590 == 1 )
            LODWORD(v733) = v1;
        }
        else
        {
          LODWORD(v733) = 3600 * v2;
        }
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        HIDWORD(v733) = (int)(char *)&pParty + 6972 * v3->uPlayerID_2 + 36 * a2 + 3040;
        v732 = (signed int)&pItemsTable->pItems[*(int *)HIDWORD(v733)].pIconName;
        ((ItemGen *)HIDWORD(v733))->UpdateTempBonus(pParty->uTimePlayed);
        if ( *(int *)HIDWORD(v733) >= 64 && *(int *)HIDWORD(v733) <= 65
          || *(char *)(HIDWORD(v733) + 20) & 2
          || *(int *)(HIDWORD(v733) + 12) != v1
          || *(int *)(HIDWORD(v733) + 4) != v1
          || (v591 = *(char *)(v732 + 28)) != 0 && v591 != 1 && v591 != 2
          || pItemsTable->_456D5E_is_some_material((ItemGen *)HIDWORD(v733)) )
          goto LABEL_199;
        v592 = HIDWORD(v733);
        v14 = v731 == 4;
        *(int *)(HIDWORD(v733) + 12) = 16;
        if ( !v14 )
        {
          v732 = (int)v733 << 7;
          *(_QWORD *)(v592 + 28) = pParty->uTimePlayed
                                 + (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
          *(int *)(v592 + 20) |= 8u;
        }
        *(char *)(v592 + 20) |= 0x80u;
        goto LABEL_1055;
      case 93:
        v593 = v12 - 2;
        if ( !v593 )
          goto LABEL_1062;
        v594 = v593 - 1;
        if ( v594 )
        {
          if ( v594 == 1 )
            amount = 9;
          else
LABEL_1062:
            amount = 5;
        }
        else
        {
          amount = 7;
        }
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v726 = (Player *)((signed int)(60 * stru_5C6E00->uIntegerDoublePi) / 360);
        v732 = (signed int)(60 * stru_5C6E00->uIntegerDoublePi) / 360 / (amount - 1);
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.vPosition.x = pParty->vPosition.x;
        a1.vPosition.y = pParty->vPosition.y;
        a1.uAttributes = v1;
        a1.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 2;
        a1.uSectorID = pIndoor->GetSector(
                         pParty->vPosition.x,
                         pParty->vPosition.y,
                         pParty->vPosition.z + (signed int)pParty->uPartyHeight / 2);
        a1.uSpriteFrameID = v1;
        v595 = 8 * v3->uPlayerID;
        LOBYTE(v595) = v595 | 4;
        a1.field_58 = v595;
        a1.field_5C = a2;
        a1.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
        a1.uSoundID = LOWORD(v3->field_10);
        if ( pParty->bTurnBasedModeOn == 1 )
          LOBYTE(a1.uAttributes) |= 4u;
        v596 = (signed int)v726 / -2;
        y = (char *)((signed int)v726 / 2);
        if ( (signed int)v726 / -2 <= (signed int)v726 / 2 )
        {
          v597 = v715.uYawAngle;
          do
          {
            a1.uFacing = v596 + v597;
            if ( a1.Create(
                   v596 + v597,
                   v715.uPitchAngle,
                   pObjectList->pObjects[(signed __int16)a1.uObjectDescID].uSpeed,
                   v3->uPlayerID + 1) != -1
              && pParty->bTurnBasedModeOn == 1 )
              ++pTurnEngine->field_1C;
            v596 += v732;
          }
          while ( v596 <= (signed int)y );
        }
        goto LABEL_1056;
      case 94:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        if ( v731 == 1 || v731 == 2 )
        {
          v598 = 180 * v2;
          goto LABEL_1081;
        }
        if ( v731 == 3 )
        {
          v598 = 300 * v2;
LABEL_1081:
          LODWORD(v733) = v598;
          goto LABEL_1082;
        }
        if ( v731 == 4 )
          LODWORD(v733) = 29030400;
LABEL_1082:
        v599 = a2 >> 3;
        if ( (a2 & 7) != 3 )
          goto LABEL_1056;
        v730 = 836 * v599;
        if ( !MonsterStats::BelongsToSupertype(pActors[v599].pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD) )
          goto LABEL_83;
        if ( !stru_50C198.GetMagicalResistance((Actor *)((char *)pActors + v730), 0xAu) )
          goto LABEL_200;
        ((SpellBuff *)((char *)&pActors[0].pActorBuffs[9] + v730))->Reset();
        ((SpellBuff *)((char *)&pActors[0].pActorBuffs[1] + v730))->Reset();
        v732 = (int)v733 << 7;
        ((SpellBuff *)((char *)&pActors[0].pActorBuffs[12] + v730))->Apply(
          pParty->uTimePlayed + (signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335),
          v731,
          v1,
          v1,
          v1);
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        v60 = pObjectList->ObjectIDByItemID(a1.uItemType);
        v61 = v730;
LABEL_1086:
        v600 = *(__int16 *)((char *)&pActors[0].vPosition.y + v61);
        v601 = *(__int16 *)((char *)&pActors[0].vPosition.x + v61);
        a1.uObjectDescID = v60;
        a1.vPosition.x = v601;
        v602 = *(unsigned __int16 *)((char *)&pActors[0].uActorHeight + v61);
        v603 = *(__int16 *)((char *)&pActors[0].vPosition.z + v61);
        a1.vPosition.y = v600;
        v676 = v603 + v602;
        v665 = v600;
        a1.vPosition.z = v603 + v602;
        v657 = v601;
LABEL_1087:
        a1.uAttributes = v1;
        a1.uSectorID = pIndoor->GetSector(v657, v665, v676);
        a1.uSpriteFrameID = v1;
        v604 = 8 * v3->uPlayerID;
        LOBYTE(v604) = v604 | 4;
        a1.field_58 = v604;
        a1.field_5C = a2;
        a1.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
        a1.uFacing = LOWORD(v715.uYawAngle);
        LOWORD(v604) = LOWORD(v3->field_10);
        LOBYTE(a1.uAttributes) |= 0x80u;
        a1.uSoundID = v604;
        a1.Create(0, v1, v1, v3->uPlayerID + 1);
        goto LABEL_1056;
      case 96:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        HIDWORD(v733) = v1;
        memset(&pStru179, v1, 0xFA0u);
        _this = (ItemGen *)v1;
        v605 = (char *)pParty->pHirelings;
        do
        {
          if ( *(int *)v605 != v1 )
          {
            v606 = HIDWORD(v733)++;
            pStru179->field_0[v606] = (int)((char *)&_this->uItemID + 1);
          }
          _this = (ItemGen *)((char *)_this + 1);
          v605 += 76;
        }
        while ( (signed int)v605 < (signed int)&pParty->pPickedItem );
        _this = (ItemGen *)v1;
        if ( (signed int)pNPCStats->uNumNewNPCs > v1 )
        {
          v730 = (int)pNPCStats->pNewNPCData;
          HIDWORD(v733) = 4 * HIDWORD(v733) + 6043152;
          do
          {
            if ( *(char *)(v730 + 8) & 0x80
              && (pParty->pHirelings[0].pName == (char *)v1 || strcmp(*(const char **)v730, pParty->pHirelings[0].pName))
              && (pParty->pHirelings[1].pName == (char *)v1 || strcmp(*(const char **)v730, pParty->pHirelings[1].pName)) )
            {
              v607 = HIDWORD(v733);
              HIDWORD(v733) += 4;
              *(int *)v607 = (int)_this + 3;
            }
            _this = (ItemGen *)((char *)_this + 1);
            v730 += 76;
          }
          while ( (signed int)this < (signed int)pNPCStats->uNumNewNPCs );
        }
        v608 = v3->uPlayerID_2;
        if ( v608 != 4 && v608 != 5
          || (v609 = (signed int)*(&pFontCChar + v608 + (unsigned __int8)pParty->field_709), v609 <= v1)
          || v609 >= 3 )
          goto LABEL_200;
        v610 = 76 * v609;
        *((int *)&pParty->pPlayers[3].pInstalledBeacons[4].uBeaconTime + 19 * v609) = v1;
        v611 = pIconsFrameTable->FindIcon("spell96");
        *(int *)((char *)&pParty->pPlayers[3].pInstalledBeacons[4].uBeaconTime + v610 + 4) = pIconsFrameTable->GetIconAnimLength(
                                                                                                 v611);
        v232 = 1;
        *(int *)((char *)&pParty->pPlayers[3].pInstalledBeacons[3].field_18 + v610) = 1;
        v612 = (char *)pParty->pPlayers;
        do
        {
          *((int *)v612 + 1615) = ((Player *)v612)->GetMaxHealth();
          *((int *)v612 + 1616) = ((Player *)v612)->GetMaxMana();
          v612 += 6972;
        }
        while ( (signed int)v612 < (signed int)pParty->pHirelings );
        v613 = (char *)&pOutdoor->ddm;
        if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor)
          v613 = (char *)&pIndoor->dlv;
        *((int *)v613 + 2) += 15;
        if ( *((int *)v613 + 2) > 10000 )
          *((int *)v613 + 2) = 10000;
LABEL_1112:
        LODWORD(v727) = v232;
        goto LABEL_83;
      case 95:
        if ( v12 <= v1 )
          goto LABEL_1119;
        if ( v12 <= 3 )
        {
          v614 = 300 * (v2 + 12);
        }
        else
        {
          if ( v12 != 4 )
            goto LABEL_1119;
          v614 = 900 * (v2 + 4);
        }
        LODWORD(v733) = v614;
LABEL_1119:
        v615 = v2 + 5;
        amount = v615;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        if ( v731 != 3 && v731 != 4 )
        {
          v616 = v3->uPlayerID_2;
          v617 = v3->spellnum;
          v618 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v617, v616);
          v668 = v1;
          v658 = v716;
          v732 = (int)v733 << 7;
          v653 = v615;
          v651 = v731;
          v28 = pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
          v27 = (char *)&pParty->pPlayers[v3->uPlayerID_2].pPlayerBuffs[10];
          goto LABEL_103;
        }
        a2 = v1;
        v732 = (int)v733 << 7;
        v717 = (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
        v619 = &pParty->pPlayers[0].pPlayerBuffs[10];
        do
        {
          v620 = a2;
          v621 = v3->spellnum;
          v622 = pGame->GetStru6();
          pGame->GetStru6()->SetPlayerBuffAnim(v621, v620);
          v619->Apply(pParty->uTimePlayed + v717, v731, amount, v716, v1);
          ++a2;
          v619 = (SpellBuff *)((char *)v619 + 6972);
        }
        while ( (signed int)v619 < (signed int)&pParty->field_871C[504] );
        goto LABEL_1056;
      case 99:
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        v726 = (Player *)v1;
        pGame->GetIndoorCamera();
        v623 = (signed __int64)GetPickDepth();
        HIDWORD(v733) = sub_46A6AC((int)dword_50BF30, 100, v623);
        v709 = v1;
        v708 = v1;
        v707 = v1;
        a1.stru_24.Reset();
        a1.field_48 = v3->spellnum;
        a1.field_4C = v2;
        a1.field_50 = v731;
        a1.uObjectDescID = pObjectList->ObjectIDByItemID(a1.uItemType);
        a1.uAttributes = v1;
        a1.uSectorID = v1;
        a1.uSpriteFrameID = v1;
        v624 = v3->uPlayerID;
        a1.field_60_distance_related_prolly_lod = 0;
        a1.uFacing = v1;
        v624 *= 8;
        LOBYTE(v624) = v624 | 4;
        a1.field_58 = v624;
        a1.uSoundID = LOWORD(v3->field_10);
        a2 = v1;
        if ( SHIDWORD(v733) > v1 )
        {
          v726 = (Player *)(HIDWORD(v733) * (7 * v2 + 25));
          do
          {
            v625 = dword_50BF30[a2];
            a1.vPosition.x = pActors[v625].vPosition.x;
            a1.vPosition.y = pActors[v625].vPosition.y;
            v732 = pActors[v625].uActorHeight;
            a1.vPosition.z = pActors[v625].vPosition.z - (unsigned int)(signed __int64)((double)v732 * unk_4D8548);
            v626 = 8 * dword_50BF30[a2];
            LOBYTE(v626) = v626 | 3;
            a1.field_5C = v626;
            v627 = a1.Create(0, v1, v1, v1);
            v628 = a2;
            DamageMonsterFromParty(8 * v627 | 2, dword_50BF30[a2], (Vec3_int_ *)&v707);
            a2 = v628 + 1;
          }
          while ( v628 + 1 < SHIDWORD(v733) );
        }
        v730 = v1;
        v629 = 1;
        do
        {
          v630 = pPlayers[v629];
          if ( !v630->pConditions[2]
            && !v630->pConditions[12]
            && !v630->pConditions[13]
            && !v630->pConditions[14]
            && !v630->pConditions[15]
            && !v630->pConditions[16] )
          {
            v631 = v730++;
            v681[v631] = v629;
          }
          ++v629;
        }
        while ( v629 <= 4 );
        v732 = (signed __int64)((double)(signed int)v726 / (double)v730);
        HIDWORD(v733) = v1;
        if ( v730 > v1 )
        {
          do
          {
            v632 = 4 * v681[HIDWORD(v733)] + 10965188;
            v633 = pPlayers[v681[HIDWORD(v733)]];
            v633->sHealth += v732;
            v726 = *(Player **)v632;
            v634 = v726->GetMaxHealth();
            if ( v726->sHealth > v634 )
              *(int *)(*(int *)v632 + 6460) = v726->GetMaxHealth();
            v635 = HIDWORD(v733);
            v636 = WORD2(v733);
            v637 = v3->spellnum;
            v638 = pGame->GetStru6();
            pGame->GetStru6()->SetPlayerBuffAnim(v637, v636);
            HIDWORD(v733) = v635 + 1;
          }
          while ( v635 + 1 < v730 );
        }
        v639 = pGame->GetStru6();
        pGame->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(v1, 0x40u);
        goto LABEL_1056;
      case 98:
        if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
        {
          v66 = pGlobalTXT_LocalizationStrings[499];
          goto LABEL_201;
        }
        v640 = v12 - 2;
        if ( !v640 || (v641 = v640 - 1) == 0 || (amount = 4, v641 != 1) )
          amount = 3;
        if ( pPlayer->uNumArmageddonCasts >= amount || pParty->field_1613C > v1 )
          goto LABEL_200;
        if ( !pPlayer->CanCastSpell(uRequiredMana) )
          goto LABEL_83;
        pParty->field_1613C = 256;
        pParty->field_16140 = v2;
        ++pPlayer->uNumArmageddonCasts;
        if ( pParty->bTurnBasedModeOn == 1 )
          ++pTurnEngine->field_1C;
        v726 = (Player *)50;
        do
        {
          v642 = rand() % 4096 - 2048;
          v643 = rand();
          v721 = v642 + pParty->vPosition.x;
          y = (char *)(pParty->vPosition.y + v643 % 4096 - 2048);
          v732 = GetTerrainHeightsAroundParty2(v642 + pParty->vPosition.x, (int)y, (int *)&v710, v1);
          v644 = rand();
          sub_42F7EB_DropItemAt(0xFE6u, v721, (int)y, v732 + 16, v644 % 500 + 500, 1, v1, v1, (ItemGen *)v1);
          v726 = (Player *)((char *)v726 - 1);
        }
        while ( *(float *)&v726 != 0.0 );
        goto LABEL_1056;
      default:
        goto LABEL_83;
    }
    while ( 2 )
    {
      if ( v731 == 4 )
      {
        if ( *((_QWORD *)v222 + 2) )
        {
          *((int *)v222 + 4) = v1;
          *((int *)v222 + 5) = v1;
          goto LABEL_439;
        }
      }
      else
      {
        v732 = amount << 7;
        v223 = ((Player *)v222)->DiscardConditionIfLastsLongerThan(
                 2u,
                 pParty->uTimePlayed - (signed int)(signed __int64)((double)(amount << 7) * 0.033333335));
        v222 = (char *)HIDWORD(v733);
        if ( v223 )
LABEL_439:
          ((Player *)v222)->PlaySound(103, v1);
      }
      v222 += 6972;
      HIDWORD(v733) = (int)v222;
      if ( (signed int)v222 >= (signed int)pParty->pHirelings )
        goto LABEL_1056;
      continue;
    }
  }
  if ( pParty->bTurnBasedModeOn == v1 )
  {
    v646 = pPlayer;
    pPlayer->SetRecoveryTime((signed __int64)(flt_6BE3A4_debug_recmod1 * 213.3333333333333));
    v647 = n;
  }
  else
  {
    v647 = n;
    v646 = pPlayer;
    v648 = sRecoveryTime;
    v649 = pPlayer;
    pParty->pTurnBasedPlayerRecoveryTimes[v711[n].uPlayerID] = 100;
    v649->SetRecoveryTime(v648);
    pTurnEngine->_40471C();
  }
  ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2u);
  pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, v1, v1, -1, v1, v1, v1, v1);
  v711[v647].spellnum = v1;
  v646->sMana -= uRequiredMana;
}
//----- (0042EB42) --------------------------------------------------------
__int16 ObjectList::ObjectIDByItemID(unsigned __int16 uItemID)
{
  unsigned int v2; // edx@1
  signed int v3; // eax@1
  char *v4; // ecx@2

  v2 = this->uNumObjects;
  v3 = 0;
  if ( (signed int)this->uNumObjects <= 0 )
  {
LABEL_5:
    LOWORD(v3) = 0;
  }
  else
  {
    v4 = (char *)&this->pObjects->uObjectID;
    while ( uItemID != *(short *)v4 )
    {
      ++v3;
      v4 += 56;
      if ( v3 >= (signed int)v2 )
        goto LABEL_5;
    }
  }
  return v3;
}



//----- (0042EB78) --------------------------------------------------------
int IconFrameTable::GetIconAnimLength(unsigned int uIconID)
{
  return 8 * this->pIcons[uIconID].uAnimLength;
}

//----- (0042EB8D) --------------------------------------------------------
void GUIMessageQueue::SendMessage(UIMessageType msg, int param, unsigned int a4)
{
  if (uNumMessages < 40)
  {
    pMessages[uNumMessages].eType = msg;
    pMessages[uNumMessages].param = param;
    pMessages[uNumMessages++].field_8 = a4;
  }
}

//----- (0042EBBE) --------------------------------------------------------
int __fastcall sub_42EBBE(int a1, int a2)
{
  return (unsigned __int64)(a2 * (signed __int64)a1) >> 16;
}
// 42EBBE: using guessed type int __fastcall sub_42EBBE(int, int);

//----- (0042EBDB) --------------------------------------------------------
int stru193_math::_42EBDB(int angle)
{
  return SinCos(angle - this->uIntegerHalfPi);
}

//----- (0042ECB5) --------------------------------------------------------
bool __cdecl _42ECB5_PlayerAttacksActor()
{
  unsigned int v0; // ebx@1
  Player *v1; // esi@1
  bool result; // eax@1
  int v3; // edi@2
  unsigned int v4; // eax@7
  char *v5; // eax@8
  int v6; // ecx@9
  signed int v7; // eax@16
  Actor *v8; // edi@20
  unsigned int v9; // ecx@21
  char *v10; // eax@26
  char *v11; // eax@26
  unsigned int v12; // eax@47
  char *v13; // eax@47
  char *v14; // eax@47
  unsigned int v15; // ebx@54
  int v16; // [sp-10h] [bp-4Ch]@24
  int v17; // [sp-10h] [bp-4Ch]@44
  unsigned int v18; // [sp-Ch] [bp-48h]@24
  unsigned int v19; // [sp-Ch] [bp-48h]@44
  __int16 v20; // [sp-8h] [bp-44h]@24
  __int16 v21; // [sp-8h] [bp-44h]@44
  int v22; // [sp-4h] [bp-40h]@24
  int v23; // [sp-4h] [bp-40h]@44
  SoundID v24; // [sp-4h] [bp-40h]@58
  Vec3_int_ a3; // [sp+Ch] [bp-30h]@19
  unsigned int a2; // [sp+18h] [bp-24h]@20
  unsigned int v27; // [sp+1Ch] [bp-20h]@1
  char *v28; // [sp+20h] [bp-1Ch]@9
  int v29; // [sp+24h] [bp-18h]@16
  int v30; // [sp+28h] [bp-14h]@16
  int v31; // [sp+2Ch] [bp-10h]@4
  int v32; // [sp+30h] [bp-Ch]@7
  int v33; // [sp+34h] [bp-8h]@7
  int v34; // [sp+38h] [bp-4h]@17

  v0 = uActiveCharacter;
  v27 = 6972 * uActiveCharacter;
  v1 = (Player *)&stru_AA1058[3].pSounds[6972 * uActiveCharacter + 40552];
  result = ((Player *)&stru_AA1058[3].pSounds[6972 * uActiveCharacter + 40552])->CanAct();
  if ( result )
  {
    pStru277->_427D48(v0);
    v3 = 0;
    if ( (signed __int64)pParty->pPartyBuffs[11].uExpireTime > 0 )
      pParty->pPartyBuffs[11].Reset();
    v31 = v1->pEquipment.uBow;
    if ( v31 && v1->field_1F5[36 * v31 + 15] & 2 )
      v31 = 0;
    v4 = v1->pEquipment.uMainHand;
    v32 = 0;
    v33 = 0;
    if ( v4 )
    {
      v5 = (char *)v1 + 36 * v4;
      if ( !(v5[516] & 2) )
      {
        v28 = v5 + 496;
        v6 = *((int *)v5 + 124);
        if ( pItemsTable->pItems[v6].uEquipType == 12 )
        {
          if ( *((int *)v5 + 128) <= 0 )
          {
            *(int *)v28 = 0;
            v1->pEquipment.uMainHand = 0;
          }
          else
          {
            v32 = *((int *)v5 + 124);
          }
        }
        else
        {
          if ( v6 == 64 || v6 == 65 )
            v33 = *((int *)v5 + 124);
        }
      }
    }
    v30 = 0;
    v29 = 0;
    v28 = 0;
    v7 = pMouse->uPointingObjectID;
    if ( (pMouse->uPointingObjectID & 7) != 3 || (v34 = pMouse->uPointingObjectID, !pActors[v7 >> 3].CanAct()) )
      v34 = stru_50C198.FindClosesActor(5120, 0, 0);
    a3.z = 0;
    a3.y = 0;
    a3.x = 0;
    if ( (v34 & 7) == 3 )
    {
      a2 = v34 >> 3;
      v8 = &pActors[v34 >> 3];
      v34 = sub_452A9E((v8->vPosition.x - pParty->vPosition.x) * (v8->vPosition.x - pParty->vPosition.x) + (v8->vPosition.y - pParty->vPosition.y) * (v8->vPosition.y - pParty->vPosition.y) + (v8->vPosition.z - pParty->vPosition.z) * (v8->vPosition.z - pParty->vPosition.z))
          - v8->uActorRadius;
      if ( v34 >= 0 )
      {
        v9 = 0;
      }
      else
      {
        v9 = 0;
        v34 = 0;
      }
      if ( v33 != v9 )
      {
        v28 = (char *)1;
        v22 = v0 + 8;
        v20 = v9;
        v18 = v9;
        v16 = 102;
LABEL_34:
        _42777D_CastSpell_UseWand_ShootArrow(v16, v0 - 1, v18, v20, v22);
LABEL_28:
        v3 = 0;
        goto LABEL_29;
      }
      if ( v32 != v9 )
      {
        v29 = 1;
        _42777D_CastSpell_UseWand_ShootArrow(
          *((int *)&pSpellDatas[66].field_8
          + *(int *)(&stru_AA1058[3].pSounds[36 * *(int *)&pParty->pArtifactsFound[v27 + 22] + 41048] + v27)),
          v0 - 1,
          8u,
          v9,
          v0 + 8);
        v10 = &v1->field_1F5[36 * v1->pEquipment.uMainHand + 11];
        --*(int *)v10;
        v11 = (char *)v1 + 36 * v1->pEquipment.uMainHand;
        if ( *((int *)v11 + 128) <= 0 )
        {
          *((int *)v11 + 124) = 0;
          v1->pEquipment.uMainHand = 0;
        }
        goto LABEL_28;
      }
      if ( (double)v34 <= 407.2 )
      {
        a3.x = v8->vPosition.x - pParty->vPosition.x;
        a3.y = v8->vPosition.y - pParty->vPosition.y;
        a3.z = v8->vPosition.z - pParty->vPosition.z;
        Vec3_int_::Normalize(&a3.x, &a3.y, &a3.z);
        DamageMonsterFromParty((8 * v0 - 8) | 4, a2, &a3);
        if ( v1->WearsItem(506, 1) || v1->WearsItem(506, 0) )
          _42FA66_do_explosive_impact(
            v8->vPosition.x,
            v8->vPosition.y,
            v8->vPosition.z + v8->uActorHeight / 2,
            0,
            512,
            v0);
      }
      else
      {
        if ( v31 != v9 )
        {
          v30 = 1;
          v22 = 0;
          v20 = 0;
          v18 = 0;
          v16 = 100;
          goto LABEL_34;
        }
      }
      v3 = 0;
      goto LABEL_39;
    }
    if ( v33 )
    {
      v28 = (char *)1;
      v23 = v0 + 8;
      v21 = 0;
      v19 = 0;
      v17 = 102;
    }
    else
    {
      if ( v32 )
      {
        v12 = v1->pEquipment.uMainHand;
        v29 = 1;
        _42777D_CastSpell_UseWand_ShootArrow(
          *((int *)&pSpellDatas[66].field_8 + *(int *)&v1->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v12 + 5]),
          v0 - 1,
          8u,
          0,
          v0 + 8);
        v13 = &v1->field_1F5[36 * v1->pEquipment.uMainHand + 11];
        --*(int *)v13;
        v14 = (char *)v1 + 36 * v1->pEquipment.uMainHand;
        if ( *((int *)v14 + 128) <= 0 )
        {
          *((int *)v14 + 124) = 0;
          v1->pEquipment.uMainHand = 0;
        }
LABEL_29:
        v34 = v3;
        if ( v30 == v3 )
        {
          if ( v29 != v3 )
            return 1;
          if ( v28 == (char *)v3 )
          {
            v15 = v1->pEquipment.uMainHand;
            if ( v1->HasItemEquipped(EQUIP_TWO_HANDED) )
              v34 = pItemsTable->pItems[*(int *)&v1->spellbook.pDarkSpellbook.bIsSpellAvailable[36 * v15 + 5]].uSkillType;
            pTurnEngine->_40471C();
          }
          else
          {
            v34 = 7;
          }
        }
        else
        {
          v34 = 5;
          v1->PlaySound(50, v3);
        }
        switch ( v34 )
        {
          case 0:
            v24 = (SoundID)81;
            goto LABEL_66;
          case 1:
            v24 = (SoundID)84;
            goto LABEL_66;
          case 2:
            v24 = (SoundID)85;
            goto LABEL_66;
          case 3:
            v24 = (SoundID)78;
            goto LABEL_66;
          case 4:
            v24 = (SoundID)80;
            goto LABEL_66;
          case 5:
            v24 = (SoundID)71;
            goto LABEL_66;
          case 6:
            v24 = (SoundID)83;
            goto LABEL_66;
          case 7:
            v24 = (SoundID)67;
LABEL_66:
            pAudioPlayer->PlaySound(v24, v3, v3, -1, v3, v3, v3, v3);
            break;
          default:
            return 1;
        }
        return 1;
      }
      if ( !v31 )
      {
LABEL_39:
        v31 = v1->GetAttackRecoveryTime(v3);
        if ( v31 < 30 )
          v31 = 30;
        if ( pParty->bTurnBasedModeOn == v3 )
          v1->SetRecoveryTime((signed __int64)(flt_6BE3A4_debug_recmod1 * (double)v31 * 2.133333333333333));
        goto LABEL_29;
      }
      v23 = 0;
      v21 = 0;
      v19 = 0;
      v30 = 1;
      v17 = 100;
    }
    _42777D_CastSpell_UseWand_ShootArrow(v17, v0 - 1, v19, v21, v23);
    goto LABEL_29;
  }
  return result;
}

//----- (0042F184) --------------------------------------------------------
int stru319::FindClosesActor(int a2, int a3, int a4)
{
  int v4; // edi@1
  stru319 *v5; // esi@1
  int v6; // eax@2
  int v7; // eax@4
  int result; // eax@5
  int *v9; // edx@8
  signed int v10; // ebx@10
  int v11; // edi@11
  Actor *v12; // esi@12
  unsigned __int16 v13; // ax@12
  int v14; // eax@22
  char v15; // zf@30
  int v16; // esi@32
  int v17; // ecx@34
  stru319 *v18; // eax@39
  int v19; // edx@39
  int v20; // ecx@41
  unsigned __int16 v21; // ax@42
  unsigned int v22; // [sp+8h] [bp-24h]@11
  unsigned int v23; // [sp+Ch] [bp-20h]@7
  stru319 *v24; // [sp+10h] [bp-1Ch]@1
  unsigned int v25; // [sp+14h] [bp-18h]@8
  int *v26; // [sp+18h] [bp-14h]@8
  int v27; // [sp+1Ch] [bp-10h]@10
  int *v28; // [sp+20h] [bp-Ch]@10
  unsigned int v29; // [sp+24h] [bp-8h]@7
  int v30; // [sp+28h] [bp-4h]@6
  int i; // [sp+38h] [bp+Ch]@33
  signed int v32; // [sp+3Ch] [bp+10h]@32

  v4 = 0;
  v5 = this;
  v24 = this;
  if ( pRenderer->pRenderD3D )
  {
    v6 = a3 != 0;
    if ( a4 )
      LOBYTE(v6) = v6 | 8;
    v7 = pGame->pVisInstance->_4C1944(3, a2, v6, 657456, -1);
    if ( v7 != -1 )
      return (unsigned __int16)v7;
  }
  else
  {
    v30 = 0;
    if ( pRenderer->pActiveZBuffer )
    {
      v29 = viewparams->uScreenX;
      v23 = viewparams->uScreenZ;
      if ( (signed int)viewparams->uScreenY < (signed int)viewparams->uScreenW )
      {
        v25 = viewparams->uScreenW - viewparams->uScreenY;
        v9 = &pRenderer->pActiveZBuffer[viewparams->uScreenX + 640 * viewparams->uScreenY];
        v26 = &pRenderer->pActiveZBuffer[viewparams->uScreenX + 640 * viewparams->uScreenY];
        do
        {
          if ( (signed int)v29 < (signed int)v23 )
          {
            v28 = v9;
            v10 = v4;
            v27 = v23 - v29;
            do
            {
              v22 = *v28;
              v11 = *v28 & 0xFFFF;
              if ( (*(char *)v28 & 7) == 3 )
              {
                v12 = &pActors[(unsigned int)v11 >> 3];
                v13 = v12->uAIState;
                if ( v13 != 5 )
                {
                  if ( v13 != 4
                    && v13 != 11
                    && v13 != 19
                    && v13 != 17
                    && (!a3 || pActors[(unsigned int)v11 >> 3].GetActorsRelation(0)) )
                  {
                    if ( (!a4 || MonsterStats::BelongsToSupertype(v12->pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD))
                      && v22 <= a2 << 16 )
                    {
                      v14 = 0;
                      if ( v10 > 0 )
                      {
                        do
                        {
                          if ( dword_50BDA0[v14] == v11 )
                            break;
                          ++v14;
                        }
                        while ( v14 < v30 );
                      }
                      if ( v14 == v30 && v10 < 100 )
                      {
                        ++v30;
                        dword_50BC10[v10] = v22;
                        dword_50BDA0[v10] = v11;
                        ++v10;
                      }
                    }
                  }
                }
              }
              ++v28;
              --v27;
            }
            while ( v27 );
            v4 = v30;
            v5 = v24;
          }
          v9 = v26 + 640;
          v15 = v25-- == 1;
          v26 += 640;
        }
        while ( !v15 );
      }
      if ( v4 > 0 )
      {
        v32 = 1;
        v16 = (int)dword_50BC10;
        do
        {
          for ( i = v32; i < v4; ++i )
          {
            v17 = dword_50BC10[i];
            if ( v17 < *(int *)v16 )
            {
              dword_50BC10[i] = *(int *)v16;
              *(int *)v16 = v17;
            }
          }
          ++v32;
          v16 += 4;
        }
        while ( v32 - 1 < v4 );
        v5 = v24;
        if ( v4 > 0 )
        {
          v18 = v24;
          v19 = v4;
          do
          {
            *(int *)&v18->field_0 = (*(int *)&v18[(char *)dword_50BC10 - (char *)v24].field_0 >> 3) & 0x1FFF;
            v18 += 4;
            --v19;
          }
          while ( v19 );
        }
      }
      v20 = 0;
      for ( *(int *)&v5[2000].field_0 = v4; v20 < v4; ++v20 )
      {
        v21 = pActors[*(int *)&v5[4 * v20].field_0].uAIState;
        if ( v21 != 4 && v21 != 5 )
          break;
      }
      if ( v20 != v4 )
      {
        result = 8 * *(int *)&v5[4 * v20].field_0;
        LOBYTE(result) = result | 3;
        return result;
      }
    }
  }
  return 0;
}


//----- (0042F3D6) --------------------------------------------------------
void InitializeTurnBasedAnimations(void *_this)
{
  unsigned int *v1; // edi@1

  pIconIDs_Turn[0] = pIconsFrameTable->FindIcon("turn0");
  pIconIDs_Turn[1] = pIconsFrameTable->FindIcon("turn1");
  pIconIDs_Turn[2] = pIconsFrameTable->FindIcon("turn2");
  pIconIDs_Turn[3] = pIconsFrameTable->FindIcon("turn3");
  pIconIDs_Turn[4] = pIconsFrameTable->FindIcon("turn4");
  uIconID_TurnStop = pIconsFrameTable->FindIcon("turnstop");
  uIconID_TurnHour = pIconsFrameTable->FindIcon("turnhour");
  uIconID_TurnStart = pIconsFrameTable->FindIcon("turnstart");
  uIconID_CharacterFrame = pIconsFrameTable->FindIcon("aframe1");
  uSpriteID_Spell11 = pSpriteFrameTable->FastFindSprite("spell11");
  v1 = pIconIDs_Turn;
  do
  {
    pIconsFrameTable->InitializeAnimation(*v1);
    ++v1;
  }
  while ( (signed int)v1 < (signed int)&uIconID_TurnStop );
  pIconsFrameTable->InitializeAnimation(uIconID_TurnHour);
  pIconsFrameTable->InitializeAnimation(uIconID_TurnStop);
  pIconsFrameTable->InitializeAnimation(uIconID_TurnStart);
  pIconsFrameTable->InitializeAnimation(uIconID_CharacterFrame);
}

//----- (0042F4DA) --------------------------------------------------------
signed int __cdecl sub_42F4DA()
{
  signed int v0; // edi@1
  char *v1; // esi@4
  int v2; // ebx@5
  int v3; // eax@5
  int v4; // ebx@5
  unsigned int v5; // ecx@5
  int v6; // edx@6
  unsigned int v7; // edx@8
  unsigned int v8; // edx@10
  __int16 v9; // ax@12
  signed int result; // eax@20
  int v11; // [sp+Ch] [bp-10h]@5
  int v12; // [sp+10h] [bp-Ch]@5
  signed int v13; // [sp+14h] [bp-8h]@3

  v0 = 5120;
  if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
    v0 = 2560;
  v13 = 0;
  if ( (signed int)uNumActors <= 0 )
  {
LABEL_20:
    result = 0;
  }
  else
  {
    v1 = (char *)&pActors[0].uAIState;
    while ( 1 )
    {
      v2 = abs(*((short *)v1 - 17) - pParty->vPosition.x);
      v11 = abs(*((short *)v1 - 16) - pParty->vPosition.y);
      v12 = abs(*((short *)v1 - 15) - pParty->vPosition.z);
      v3 = v2;
      v4 = v11;
      v5 = v12;
      if ( v3 < v11 )
      {
        v6 = v3;
        v3 = v11;
        v4 = v6;
      }
      if ( v3 < v12 )
      {
        v7 = v3;
        v3 = v12;
        v5 = v7;
      }
      if ( v4 < (signed int)v5 )
      {
        v8 = v5;
        v5 = v4;
        v4 = v8;
      }
      if ( (signed int)(((unsigned int)(11 * v4) >> 5) + (v5 >> 2) + v3) < v0 )
      {
        v9 = *(short *)v1;
        if ( *(short *)v1 != 5 )
        {
          if ( v9 != 4
            && v9 != 11
            && v9 != 19
            && v9 != 17
            && (*(v1 - 138) & 8 || ((Actor *)nullptr)->GetActorsRelation( (Actor *)(v1 - 176))) )
            break;
        }
      }
      ++v13;
      v1 += 836;
      if ( v13 >= (signed int)uNumActors )
        goto LABEL_20;
    }
    result = 1;
  }
  return result;
}

//----- (0042F5ED) --------------------------------------------------------
int LayingItem::Create(int yaw, int pitch, int a4, int a5)
{
  LayingItem *v5; // eax@1
  signed int v6; // ebx@2
  char *v7; // ecx@2
  signed int result; // eax@6
  LayingItem *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 ( !a1->uObjectDescID )
    return -1;
  v6 = 0;
  v7 = (char *)&pLayingItems[0].uObjectDescID;
  v21 = 0;
  do
  {
    if ( !*(short *)v7 )
      break;
    v7 += 112;
    ++v6;
    v21 = v6;
  }
  while ( (signed int)v7 < (signed int)((char *)&pObjectList->uNumObjects + 2) );
  if ( v6 >= 1000 )
    return -1;
  *(int *)&v5->field_62[2] = v5->vPosition.x;
  *(int *)&v5->field_62[6] = v5->vPosition.y;
  v9 = &pLayingItems[v6];
  *(int *)&v5->field_62[10] = v5->vPosition.z;
  memcpy(v9, v5, 0x70u);
  if ( a5 == 1 )
  {
    v20 = &v9->vPosition.z;
    v19 = &v9->vPosition.y;
    v18 = (int *)&v9->vPosition;
    v17.z = v5->vPosition.z;
    *(_QWORD *)&v17.x = *(_QWORD *)&v5->vPosition.x;
    v16 = 0;
    v10 = stru_5C6E00->uIntegerHalfPi + v9->uFacing;
    goto LABEL_16;
  }
  if ( a5 == 2 )
  {
    v20 = &v9->vPosition.z;
    v19 = &v9->vPosition.y;
    v18 = (int *)&v9->vPosition;
    v17.z = v5->vPosition.z;
    *(_QWORD *)&v17.x = *(_QWORD *)&v5->vPosition.x;
    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.z = v5->vPosition.z;
    *(_QWORD *)&v17.x = *(_QWORD *)&v5->vPosition.x;
    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;
  }
  if ( a5 == 4 )
  {
    v20 = &v9->vPosition.z;
    v19 = &v9->vPosition.y;
    v18 = (int *)&v9->vPosition;
    v17.z = v5->vPosition.z;
    *(_QWORD *)&v17.x = *(_QWORD *)&v5->vPosition.x;
    v16 = 0;
    v10 = v9->uFacing - stru_5C6E00->uIntegerHalfPi;
LABEL_16:
    v15 = 24;
    goto LABEL_17;
  }
LABEL_18:
  v11 = a4;
  v12 = 0;
  if ( a4 )
  {
    a4a = stru_5C6E00->SinCos(angle);
    v13 = (unsigned __int64)(a4a * (signed __int64)stru_5C6E00->SinCos(pitch)) >> 16;
    a4b = stru_5C6E00->SinCos(angle - stru_5C6E00->uIntegerHalfPi);
    a5a = (unsigned __int64)(a4b * (signed __int64)stru_5C6E00->SinCos(pitch)) >> 16;
    v14 = stru_5C6E00->SinCos(pitch - stru_5C6E00->uIntegerHalfPi);
    v9->vVelocity.x = (unsigned int)(v13 * v11) >> 16;
    v9->vVelocity.y = (unsigned int)(a5a * v11) >> 16;
    v12 = (unsigned int)(v14 * v11) >> 16;
  }
  else
  {
    v9->vVelocity.y = 0;
    v9->vVelocity.x = 0;
  }
  v9->vVelocity.z = v12;
  result = v21;
  if ( v21 >= (signed int)uNumLayingItems )
    uNumLayingItems = v21 + 1;
  return result;
}

//----- (0042F7EB) --------------------------------------------------------
bool __fastcall sub_42F7EB_DropItemAt(unsigned int uSpriteID, int x, int y, int z, int a4, int count, int a7, unsigned __int16 attributes, ItemGen *a9)
{
  unsigned int v9; // edi@1
  signed int v10; // edx@3
  char *v11; // ecx@4
  unsigned __int16 v12; // ax@7
  unsigned int v13; // edx@9
  char *v14; // ecx@10
  int v15; // esi@17
  int v16; // eax@18
  int v17; // edi@20
  int v18; // esi@20
  //LayingItem a1a; // [sp+Ch] [bp-78h]@1
  int v21; // [sp+7Ch] [bp-8h]@1
  unsigned int v22; // [sp+80h] [bp-4h]@1

  v9 = uSpriteID;
  v21 = x;
  v22 = uSpriteID;

  LayingItem a1a; // [sp+Ch] [bp-78h]@1
  //LayingItem::LayingItem(&a1a);
  a1a.stru_24.Reset();

  if ( a9 )
  {
    memcpy(&a1a.stru_24, a9, sizeof(a1a.stru_24));
    v9 = v22;
  }
  v10 = 0;
  a1a.field_50 = 0;
  a1a.field_4C = 0;
  a1a.field_48 = 0;
  a1a.field_54 = 0;
  a1a.uItemType = v9;
  if ( (signed int)pObjectList->uNumObjects <= 0 )
  {
LABEL_7:
    v12 = 0;
  }
  else
  {
    v11 = (char *)&pObjectList->pObjects->uObjectID;
    while ( (short)v9 != *(short *)v11 )
    {
      ++v10;
      v11 += 56;
      if ( v10 >= (signed int)pObjectList->uNumObjects )
        goto LABEL_7;
    }
    v12 = v10;
  }
  a1a.uObjectDescID = v12;
  a1a.vPosition.z = z;
  a1a.vPosition.x = v21;
  a1a.vPosition.y = y;
  a1a.uSoundID = 0;
  a1a.uAttributes = attributes;
  a1a.uSectorID = pIndoor->GetSector(v21, y, z);
  a1a.uSpriteFrameID = 0;
  a1a.field_58 = 0;
  a1a.field_5C = 0;
  if ( !(a1a.uAttributes & 0x10) )
  {
    v13 = 0;
    if ( (signed int)pItemsTable->pItems[0].uItemID > 0 )
    {
      v14 = (char *)&pItemsTable->pItems[0].uSpriteID;
      while ( *(short *)v14 != v9 )
      {
        ++v13;
        v14 += 48;
        if ( (signed int)v13 >= (signed int)pItemsTable->pItems[0].uItemID )
          goto LABEL_16;
      }
      a1a.stru_24.uItemID = v13;
    }
  }
LABEL_16:
  if ( a7 )
  {
    v15 = count;
    if ( count > 0 )
    {
      do
      {
        a1a.uFacing = rand() % (signed int)stru_5C6E00->uIntegerDoublePi;
        v16 = rand();
        a1a.Create(
          (signed __int16)a1a.uFacing,
          ((signed int)stru_5C6E00->uIntegerHalfPi >> 1) + (v16 % (signed int)stru_5C6E00->uIntegerHalfPi >> 1),
          a4,
          0);
        --v15;
      }
      while ( v15 );
    }
  }
  else
  {
    v17 = count;
    v18 = stru_5C6E00->uIntegerHalfPi;
    a1a.uFacing = 0;
    if ( count > 0 )
    {
      do
      {
        a1a.Create((signed __int16)a1a.uFacing, v18, a4, 0);
        --v17;
      }
      while ( v17 );
    }
  }
  return 1;
}

//----- (0042F960) --------------------------------------------------------
void __fastcall sub_42F960_create_object(int x, int y, int z)
{
  int v3; // ebx@1
  int v4; // edi@1
  signed int v5; // edx@1
  char *v6; // ecx@2
  unsigned __int16 v7; // ax@5
  signed int v8; // eax@6
  signed int v9; // eax@7
  //LayingItem a1; // [sp+Ch] [bp-70h]@1

  v3 = x;
  v4 = y;
  
  LayingItem a1; // [sp+Ch] [bp-70h]@1
  //LayingItem::LayingItem(&a1);
  a1.stru_24.Reset();

  v5 = 0;
  a1.field_50 = 0;
  a1.field_4C = 0;
  a1.field_48 = 0;
  a1.field_54 = 0;
  a1.uItemType = 800;
  if ( (signed int)pObjectList->uNumObjects <= 0 )
  {
LABEL_5:
    v7 = 0;
  }
  else
  {
    v6 = (char *)&pObjectList->pObjects->uObjectID;
    while ( *(short *)v6 != 800 )
    {
      ++v5;
      v6 += 56;
      if ( v5 >= (signed int)pObjectList->uNumObjects )
        goto LABEL_5;
    }
    v7 = v5;
  }
  a1.uObjectDescID = v7;
  a1.vPosition.x = v3;
  a1.vPosition.y = v4;
  a1.vPosition.z = z;
  a1.uSoundID = 0;
  a1.uAttributes = 0;
  a1.uSectorID = pIndoor->GetSector(v3, v4, z);
  a1.uSpriteFrameID = 0;
  a1.field_58 = 0;
  a1.field_5C = 0;
  v8 = a1.Create(0, 0, 0, 0);
  if ( v8 != -1 )
  {
    v9 = 8 * v8;
    LOBYTE(v9) = v9 | 2;
    pAudioPlayer->PlaySound((SoundID)(SOUND_GoldReceived|0x14), v9, 0, -1, 0, 0, 0, 0);
  }
}

//----- (0042FA22) --------------------------------------------------------
char *__cdecl sub_42FA22_mess_with_laying_item_list()
{
  size_t v0; // edx@1
  int v1; // ebp@1
  char *result; // eax@1
  void *v3; // ebx@1

  v0 = 0;
  v1 = 0;
  result = (char *)&pLayingItems[0].uObjectDescID;
  v3 = pLayingItems;
  do
  {
    if ( *(short *)result )
    {
      if ( v1 != v0 )
      {
        memcpy(v3, result - 2, 0x70u);
        *(short *)result = 0;
      }
      ++v0;
      v3 = (char *)v3 + 112;
    }
    result += 112;
    ++v1;
  }
  while ( (signed int)result < (signed int)((char *)&pObjectList->uNumObjects + 2) );
  uNumLayingItems = v0;
  return result;
}

//----- (0042FA66) --------------------------------------------------------
int __fastcall _42FA66_do_explosive_impact(int a1, int a2, int a3, int a4, __int16 a5, signed int a6)
{
  int v6; // edi@1
  int v7; // esi@1
  char *v8; // ecx@2
  unsigned __int16 v9; // ax@5
  int v10; // eax@10
  signed int result; // eax@11
  __int16 v12; // ax@12
  //LayingItem a1a; // [sp+Ch] [bp-74h]@1
  int v14; // [sp+7Ch] [bp-4h]@1

  v6 = a1;
  v7 = a2;
  LayingItem a1a; // [sp+Ch] [bp-74h]@1
  //LayingItem::LayingItem(&a1a);
  a1a.uItemType = 600;
  a1a.stru_24.Reset();

  a1a.field_48 = 6;
  a1a.field_4C = 8;
  a1a.field_50 = 3;
  v14 = 0;
  if ( (signed int)pObjectList->uNumObjects <= 0 )
  {
LABEL_5:
    v9 = 0;
  }
  else
  {
    v8 = (char *)&pObjectList->pObjects->uObjectID;
    while ( (short)a1a.uItemType != *(short *)v8 )
    {
      ++v14;
      v8 += 56;
      if ( v14 >= (signed int)pObjectList->uNumObjects )
        goto LABEL_5;
    }
    v9 = v14;
  }
  a1a.uObjectDescID = v9;
  a1a.vPosition.x = v6;
  a1a.vPosition.y = v7;
  a1a.vPosition.z = a3;
  a1a.uAttributes = 0;
  a1a.uSectorID = pIndoor->GetSector(v6, v7, a3);
  a1a.uSpriteFrameID = 0;
  a1a.field_5C = 0;
  a1a.field_60_distance_related_prolly_lod = 0;
  a1a.uFacing = 0;
  a1a.uSoundID = 0;
  if ( a6 >= 1 || a6 <= 4 )
  {
    v10 = 8 * a6 - 8;
    LOBYTE(v10) = v10 | 4;
    a1a.field_58 = v10;
  }
  else
  {
    a1a.field_58 = 0;
  }
  result = a1a.Create(0, 0, 0, 0);
  if ( result != -1 )
  {
    v12 = 8 * result;
    LOBYTE(v12) = v12 | 2;
    result = stru_50FE08.Add(
               v12,
               a5,
               SLOWORD(a1a.vPosition.x),
               SLOWORD(a1a.vPosition.y),
               SLOWORD(a1a.vPosition.z),
               0,
               0);
  }
  return result;
}



//----- (0042FB5C) --------------------------------------------------------
bool __fastcall sub_42FB5C(signed int a1)
{
  int v1; // ecx@3
  int v2; // ecx@4
  int v3; // ecx@5
  int v4; // ecx@6
  int v5; // ecx@7
  int v6; // ecx@8
  char v7; // zf@9

  if ( a1 > 39 )
  {
    if ( a1 > 77 )
    {
      if ( a1 == 80 )
        return 0;
      if ( a1 > 84 )
      {
        if ( a1 <= 86 )
          return 0;
        v7 = a1 == 95;
        goto LABEL_20;
      }
    }
    else
    {
      if ( a1 == 77 )
        return 0;
      if ( a1 >= 46 )
      {
        if ( a1 <= 47 || a1 == 51 )
          return 0;
        v7 = a1 == 73;
        goto LABEL_20;
      }
    }
    return 1;
  }
  if ( a1 == 39 || (v1 = a1 - 2) == 0 )
    return 1;
  v2 = v1 - 3;
  if ( !v2 )
    return 0;
  v3 = v2 - 1;
  if ( !v3 || (v4 = v3 - 3) == 0 )
    return 1;
  v5 = v4 - 8;
  if ( !v5 )
    return 0;
  v6 = v5 - 1;
  if ( !v6 )
    return 1;
  v7 = v6 == 20;
LABEL_20:
  if ( !v7 )
    return 1;
  return 0;
}

//----- (0042FBDD) --------------------------------------------------------
void __cdecl sub_42FBDD()
{
  pAudioPlayer->PlaySound((SoundID)75, 0, 0, -1, 0, 0, 0, 0);
  pRenderer->DrawTextureTransparent(ptr_5076FC->uX, ptr_5076FC->uY, ptr_5076FC->pTextures[0]);
  pRenderer->Present();
}

//----- (0042FC15) --------------------------------------------------------
void __cdecl sub_42FC15()
{
  pAudioPlayer->PlaySound((SoundID)75, -2, 0, -1, 0, 0, 0, 0);
  pRenderer->DrawTextureTransparent(ptr_5076F4->uX, ptr_5076F4->uY, ptr_5076F4->pTextures[0]);
  pRenderer->Present();
}

//----- (0042FC4E) --------------------------------------------------------
void __cdecl ProcessInputActions()
{
  ActionQueue *pActionQueue; // esi@7
  Keyboard *v3; // ecx@8
  char v4; // al@9
  ActionQueue *v5; // ecx@19
  Player *v6; // ecx@86
  Player *v7; // esi@100
  char v8; // bl@100
  unsigned __int16 v9; // ax@102
  int v10; // eax@103
  unsigned int v11; // eax@127
  signed int v12; // esi@157
  Keyboard *v13; // ecx@158
  char v14; // al@159
  unsigned int v15; // eax@168
  void *v16; // esi@177
  int v17; // [sp-14h] [bp-1Ch]@8
  PartyAction partyAction; // [sp-14h] [bp-1Ch]@20
  PartyAction partyAction_; // [sp-14h] [bp-1Ch]@54
  __int16 v20; // [sp-14h] [bp-1Ch]@60
  int v21; // [sp-14h] [bp-1Ch]@68
  int v22; // [sp-Ch] [bp-14h]@158
  InputAction inputAction; // [sp+0h] [bp-8h]@7
  int v24; // [sp+4h] [bp-4h]@87

  pGame->pKeyboardInstance->EnterCriticalSection();
  auto pKeyboard = pGame->pKeyboardInstance;
  if (!bAlwaysRun)
  {
    if (pKeyboard->IsShiftHeld())
      pParty->uFlags2 |= PARTY_FLAGS_2_RUNNING;
    else
      pParty->uFlags2 &= ~PARTY_FLAGS_2_RUNNING;
   }
  else
  {
    if (pKeyboard->IsShiftHeld())
      pParty->uFlags2 &= ~PARTY_FLAGS_2_RUNNING;
    else
      pParty->uFlags2 |= PARTY_FLAGS_2_RUNNING;
  }

  pParty->uFlags2 |= PARTY_FLAGS_2_RUNNING;
LABEL_6:
  if ( !pEventTimer->bPaused )
  {
    inputAction = (InputAction)0;
    pActionQueue = pPartyActionQueue;
    while ( 1 )
    {
      v3 = pGame->pKeyboardInstance;
      v17 = pKeyActionMap->pVirtualKeyCodesMapping[inputAction];
      if ( pKeyActionMap->pToggleTypes[inputAction] )
        v4 = v3->WasKeyPressed(v17);
      else
        v4 = v3->IsKeyBeingHeld(v17);
      if ( v4 )
      {
        switch ( inputAction )
        {
          case INPUT_MoveForward:
            if ( pCurrentScreen )
              break;
            if (!pParty->bTurnBasedModeOn)
              goto _do_move_forward;
            if (pTurnEngine->field_4 != 1 && pTurnEngine->field_4 != 2 && pTurnEngine->uActionPointsLeft > 0 )
            {
              pTurnEngine->uActionPointsLeft -= 26;
_do_move_forward:
              v5 = pActionQueue;
              if ( pParty->uFlags2 & 2 )
                partyAction = PARTY_RunForward;
              else
                partyAction = PARTY_WalkForward;
              goto _add_action_and_continue;
            }
            break;
          case INPUT_MoveBackwards:
            __debugbreak();
            if ( pCurrentScreen )
              break;
            if (!pParty->bTurnBasedModeOn)
              goto _do_move_backwards;
            if ( pTurnEngine->field_4 != 1 && pTurnEngine->field_4 != 2 && pTurnEngine->uActionPointsLeft > 0 )
            {
              pTurnEngine->uActionPointsLeft -= 26;
_do_move_backwards:
              v5 = pActionQueue;
              if ( pParty->uFlags2 & 2 )
                partyAction = PARTY_RunBackward;
              else
                partyAction = PARTY_WalkBackward;
              goto _add_action_and_continue;
            }
            break;
          case INPUT_StrafeLeft:
            __debugbreak();
            if ( pCurrentScreen )
              break;
            if (!pParty->bTurnBasedModeOn)
              goto _do_strafe_left;
            if ( pTurnEngine->field_4 == 1 || pTurnEngine->field_4 == 2 || pTurnEngine->uActionPointsLeft <= 0 )
              break;
            pTurnEngine->uActionPointsLeft -= 26;
_do_strafe_left:
            partyAction = PARTY_StrafeLeft;
            goto _add_action_and_continue_;
          case INPUT_StrafeRight:
            __debugbreak();
            if ( pCurrentScreen )
              break;
            if (!pParty->bTurnBasedModeOn)
              goto _do_strafe_right;
            if ( pTurnEngine->field_4 == 1 || pTurnEngine->field_4 == 2 || pTurnEngine->uActionPointsLeft <= 0 )
              break;
            pTurnEngine->uActionPointsLeft -= 26;
_do_strafe_right:
            partyAction = PARTY_StrafeRight;
            goto _add_action_and_continue_;
          case INPUT_TurnLeft:
            if ( pCurrentScreen )
              break;
            if ( GetAsyncKeyState(VK_CONTROL) ) // strafing
            {
              if (pParty->bTurnBasedModeOn)
              {
                if ( pTurnEngine->field_4 == 1 || pTurnEngine->field_4 == 2 || pTurnEngine->uActionPointsLeft <= 0 )
                  break;
                pTurnEngine->uActionPointsLeft -= 26;
              }
              partyAction_ = PARTY_StrafeLeft;
            }
            else
            {
              if ( pParty->uFlags2 & 2 )
                partyAction_ = PARTY_FastTurnLeft;
              else
                partyAction_ = PARTY_TurnLeft;
            }
            pActionQueue->Add(partyAction_);
            if (uCurrentlyLoadedLevelType == LEVEL_Outdoor && pWeather->bRenderSnow)
            {
              v20 = 10;
              goto LABEL_75;
            }
            break;
          case INPUT_TurnRight:
            if ( pCurrentScreen )
              break;
            if ( GetAsyncKeyState(17) )         // strafing
            {
              if (pParty->bTurnBasedModeOn)
              {
                if ( pTurnEngine->field_4 == 1 || pTurnEngine->field_4 == 2 || pTurnEngine->uActionPointsLeft <= 0 )
                  break;
                pTurnEngine->uActionPointsLeft -= 26;
              }
              v21 = 4;
            }
            else
            {
              if ( pParty->uFlags2 & 2 )
                v21 = 19;
              else
                v21 = 2;
            }
            pActionQueue->Add((PartyAction)v21);
            if (uCurrentlyLoadedLevelType == LEVEL_Outdoor && pWeather->bRenderSnow)
            {
              v20 = -10;
LABEL_75:
              pWeather->_4C2F0B(v20);
            }
            break;
          case INPUT_Jump:
            __debugbreak();
            if ( pCurrentScreen
              || pParty->bTurnBasedModeOn)
              break;
            partyAction = (PartyAction)12;
            goto _add_action_and_continue_;
          case INPUT_Yell:
            __debugbreak();
            if ( !pCurrentScreen
              && uActiveCharacter )
            {
              pParty->Yell();
              pPlayers[uActiveCharacter]->PlaySound(65, 0);
            }
            break;
          case INPUT_Pass:
            __debugbreak();
            if ( pCurrentScreen )
              break;
            if (pParty->bTurnBasedModeOn && pTurnEngine->field_4 == 3)
              goto LABEL_118;
            if ( uActiveCharacter )
            {
              v6 = pPlayers[uActiveCharacter];
              if ( !v6->uTimeToRecovery )
              {
                v24 = v6->GetAttackRecoveryTime(0);
                if ( !pParty->bTurnBasedModeOn )
                  pPlayers[uActiveCharacter]->SetRecoveryTime(
                    (signed __int64)(flt_6BE3A4_debug_recmod1 * (double)v24 * 2.133333333333333));
                pStru277->_427D48(uActiveCharacter);
                pTurnEngine->_40471C();
              }
            }
            break;
          case INPUT_Combat:
            __debugbreak();
            if ( !pCurrentScreen )
            {
              if (pParty->bTurnBasedModeOn)
              {
                if ( pTurnEngine->field_4 == 3 || (pTurnEngine->pQueue[0].uPackedID & 7) == 4 )
                {
                  pParty->bTurnBasedModeOn = 0;
                  pTurnEngine->End(true);
                }
              }
              else
              {
                pTurnEngine->Start();
                pParty->bTurnBasedModeOn = true;
              }
            }
            break;
          case INPUT_CastReady:
            __debugbreak();
            if ( pCurrentScreen )
              break;
            if (pParty->bTurnBasedModeOn && pTurnEngine->field_4 == 3)
              goto LABEL_118;
            if ( !uActiveCharacter )
              break;
            v7 = pPlayers[uActiveCharacter];
            v8 = v7->uQuickSpell;
            if ( !v8
              || bUnderwater
              || ((v9 = v7->pActiveSkills[(unsigned __int8)v8 / 11 + 12], !(HIBYTE(v9) & 1)) ? ((v9 & 0x80u) == 0 ? (!(v9 & 0x40) ? (v10 = *(&pSpellDatas[0].uNormalLevelMana + 10 * (unsigned __int8)v8)) : (v10 = *(&pSpellDatas[0].uExpertLevelMana + 10 * (unsigned __int8)v8))) : (v10 = *(&pSpellDatas[0].uMasterLevelMana + 10 * (unsigned __int8)v8))) : (v10 = *(&pSpellDatas[0].uMagisterLevelMana + 10 * (unsigned __int8)v8)),
                  v10 > v7->sMana) )
            {
              pActionQueue = pPartyActionQueue;
LABEL_120:
              if ( (signed int)pMessageQueue_50CBD0->uNumMessages < 40 )
              {
                pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)23;
                goto _send_message;
              }
            }
            else
            {
              pActionQueue = pPartyActionQueue;
              if ( dword_50C9E8 < 40 )
              {
                dword_50C9EC[3 * dword_50C9E8] = 25;
                dword_50C9F0[3 * dword_50C9E8] = 0;
                *(&dword_50C9E8 + 3 * dword_50C9E8 + 3) = 0;
                ++dword_50C9E8;
              }
            }
            break;
          default:
            __debugbreak();
            break;
          case INPUT_Attack:
            __debugbreak();
            if ( pCurrentScreen )
              break;
            if (!pParty->bTurnBasedModeOn || pTurnEngine->field_4 != 3)
              goto LABEL_120;
LABEL_118:
            pTurnEngine->field_18 |= 8u;
            break;
          case INPUT_EventTrigger:
            if ( !pCurrentScreen )
            {
              if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
                break;
              pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)404;
              goto _send_message;
            }
            if ( pCurrentScreen == 4 )
            {
              v11 = pMessageQueue_50CBD0->uNumMessages;
              if ( pMessageQueue_50CBD0->uNumMessages )
              {
                if ( pMessageQueue_50CBD0->pMessages[0].field_8 )
                {
                  v11 = 1;
                  pMessageQueue_50CBD0->uNumMessages = 1;
LABEL_132:
                  pMessageQueue_50CBD0->pMessages[v11].eType = (UIMessageType)113;
_send_message:
                  pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
                  *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
                  ++pMessageQueue_50CBD0->uNumMessages;
                  break;
                }
                v11 = 0;
                pMessageQueue_50CBD0->uNumMessages = 0;
              }
              if ( (signed int)v11 < 40 )
                goto LABEL_132;
            }
            break;
          case INPUT_CharCycle:
            __debugbreak();
            if ( pCurrentScreen == 8
              || dword_50C9E8 >= 40 )
              break;
            dword_50C9EC[3 * dword_50C9E8] = 176;
            goto LABEL_155;
          case INPUT_LookUp:
            __debugbreak();
            if ( pEventTimer->bPaused )
              break;
            partyAction = (PartyAction)7;
            goto _add_action_and_continue_;
          case INPUT_CenterView:
            __debugbreak();
            if ( pEventTimer->bPaused )
              break;
            partyAction = (PartyAction)9;
            goto _add_action_and_continue_;
          case INPUT_LookDown:
            __debugbreak();
            if ( pEventTimer->bPaused )
              break;
            partyAction = (PartyAction)8;
            goto _add_action_and_continue_;
          case INPUT_FlyUp:
            __debugbreak();
            if ( pCurrentScreen
              || pEventTimer->bPaused )
              break;
            partyAction = (PartyAction)13;
            goto _add_action_and_continue_;
          case INPUT_Land:
            __debugbreak();
            if ( pCurrentScreen
              || pEventTimer->bPaused )
              break;
            partyAction = (PartyAction)15;
            goto _add_action_and_continue_;
          case INPUT_FlyDown:
            __debugbreak();
            if ( !pCurrentScreen
              && !pEventTimer->bPaused )
            {
              partyAction = (PartyAction)14;
_add_action_and_continue_:
              v5 = pActionQueue;
_add_action_and_continue:
              v5->Add(partyAction);
            }
            break;
          case INPUT_ZoomIn:
            __debugbreak();
            if ( dword_50C9E8 >= 40 )
              break;
            dword_50C9EC[3 * dword_50C9E8] = 367;
            goto LABEL_155;
          case INPUT_ZoomOut:
            __debugbreak();
            if ( dword_50C9E8 < 40 )
            {
              dword_50C9EC[3 * dword_50C9E8] = 368;
LABEL_155:
              dword_50C9F0[3 * dword_50C9E8] = 0;
              *(&dword_50C9E8 + 3 * dword_50C9E8 + 3) = 0;
              ++dword_50C9E8;
            }
            break;
          case INPUT_AlwaysRun:
            bAlwaysRun = bAlwaysRun == 0;
            break;
        }
      }
      inputAction = (InputAction)((int)inputAction + 1);
      if ( (signed int)inputAction >= 30 )
        goto LABEL_176;
    }
  }
  v12 = 0;
  do
  {
    v22 = pKeyActionMap->pVirtualKeyCodesMapping[v12];
    v13 = pGame->pKeyboardInstance;
    if ( pKeyActionMap->pToggleTypes[v12] )
      v14 = v13->WasKeyPressed(v22);
    else
      v14 = v13->IsKeyBeingHeld(v22);
    if ( v14 && v12 == 9 )
    {
      if ( !pCurrentScreen )
      {
        if ( (signed int)pMessageQueue_50CBD0->uNumMessages >= 40 )
          goto LABEL_175;
        pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = (UIMessageType)404;
        goto LABEL_174;
      }
      if ( pCurrentScreen == 4
        || pCurrentScreen == 19 )
      {
        v15 = pMessageQueue_50CBD0->uNumMessages;
        if ( pMessageQueue_50CBD0->uNumMessages )
        {
          v15 = 0;
          if ( pMessageQueue_50CBD0->pMessages[0].field_8 )
          {
            v15 = 1;
            pMessageQueue_50CBD0->uNumMessages = 1;
            goto LABEL_173;
          }
          pMessageQueue_50CBD0->uNumMessages = 0;
        }
        if ( (signed int)v15 >= 40 )
          goto LABEL_175;
LABEL_173:
        pMessageQueue_50CBD0->pMessages[v15].eType = (UIMessageType)113;
LABEL_174:
        pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
        *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
        ++pMessageQueue_50CBD0->uNumMessages;
        goto LABEL_175;
      }
    }
LABEL_175:
    ++v12;
  }
  while ( v12 < 30 );
LABEL_176:
  if (pGame->pKeyboardInstance->bUsingAsynKeyboard)
  {
    AsyncKeyboard::LeaveCriticalSection();
    v16 = pAsyncKeyboard;
    AsyncKeyboard::EnterCriticalSection();
    memset((char *)v16 + 521, 0, 0x100u);
    AsyncKeyboard::LeaveCriticalSection();
  }
}