view mm7_6.cpp @ 1262:0aeac0b9ca30

included header cleanup
author Grumpy7
date Wed, 12 Jun 2013 21:07:34 +0200
parents 96a81634669e
children 1803172dffd9
line wrap: on
line source

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include "MM7.h"



#include "Sprites.h"
#include "BSPModel.h"
#include "OutdoorCamera.h"
#include "Mouse.h"
#include "Keyboard.h"
#include "stru6.h"

#include "Vis.h"
#include "Game.h"
#include "GUIWindow.h"
#include "GUIFont.h"
#include "Party.h"
#include "AudioPlayer.h"
#include "Outdoor.h"
#include "Overlays.h"
#include "LOD.h"
#include "Actor.h"
#include "Events.h"
#include "Viewport.h"
#include "Math.h"
#include "SpriteObject.h"
#include "ObjectList.h"
#include "stru123.h"
#include "Time.h"
#include "IconFrameTable.h"
#include "Awards.h"
#include "TurnEngine.h"
#include "CastSpellInfo.h"
#include "stru298.h"
#include "texts.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]._rhw;
  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]._rhw;
  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]._rhw;
  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;
}

//----- (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->uViewportTL_X;
  v100 = (double)(signed int)pViewport->uViewportBR_X;
  v117 = a1;
  v136 = 1;
  v104 = (double)(signed int)pViewport->uViewportTL_Y;
  v102 = (double)(pViewport->uViewportBR_Y + 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->uViewportTL_X;
  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]._rhw;
  v7 = (char *)&array_50AC10[0].flt_2C;
  do
  {
    v103 = *((float *)v7 + 7) + 6.7553994e15;
    v106 = SLODWORD(v103) >= (signed int)pViewport->uViewportTL_X;
    if ( !(v5 ^ v106) )
      goto LABEL_25;
    v8 = v101;
    if ( SLODWORD(v103) >= (signed int)pViewport->uViewportTL_X )
    {
      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->uViewportBR_X,
        v110 < 1) )
    goto LABEL_112;
  v25 = (char *)&array_509950[0]._rhw;
  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]._rhw;
  v26 = (char *)&array_50A2B0[0].flt_2C;
  while ( 2 )
  {
    v97 = *((float *)v26 + 7) + 6.7553994e15;
    v27 = SLODWORD(v97) <= (signed int)pViewport->uViewportBR_X;
    v107 = SLODWORD(v97) <= (signed int)pViewport->uViewportBR_X;
    if ( v24 != v27 )
    {
      v28 = v100;
      if ( SLODWORD(v97) <= (signed int)pViewport->uViewportBR_X )
      {
        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->uViewportTL_Y,
        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]._rhw;
  v45 = (char *)&array_509950[0].flt_2C;
  v112 = v115;
  while ( 2 )
  {
    v98 = *((float *)v45 + 8) + 6.7553994e15;
    v46 = SLODWORD(v98) >= (signed int)pViewport->uViewportTL_Y;
    v108 = SLODWORD(v98) >= (signed int)pViewport->uViewportTL_Y;
    if ( v43 != v46 )
    {
      v47 = v104;
      if ( SLODWORD(v98) >= (signed int)pViewport->uViewportTL_Y )
      {
        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->uViewportBR_Y,
        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]._rhw;
  v64 = (char *)&array_508FF0[0].flt_2C;
  v113 = v123;
  while ( 2 )
  {
    v99 = *((float *)v64 + 8) + 6.7553994e15;
    v65 = SLODWORD(v99) <= (signed int)pViewport->uViewportBR_Y;
    v109 = SLODWORD(v99) <= (signed int)pViewport->uViewportBR_Y;
    if ( v62 != v65 )
    {
      v66 = v102;
      if ( SLODWORD(v99) <= (signed int)pViewport->uViewportBR_Y )
      {
        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->uViewportBR_X )
      {
        v86 = *(float *)v81 + 6.7553994e15;
        if ( SLODWORD(v86) >= (signed int)pViewport->uViewportTL_X )
          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->uViewportBR_Y )
      {
        v88 = v102;
LABEL_92:
        *((int *)v81 + 1) = LODWORD(v88);
        goto LABEL_93;
      }
      v89 = *((float *)v81 + 1) + 6.7553994e15;
      if ( SLODWORD(v89) < (signed int)pViewport->uViewportTL_Y )
      {
        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 false;
      }
    }
    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 true;
}

//----- (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()
{
  stru_50C198.field_0 = 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) --------------------------------------------------------
void __fastcall GivePartyExp(unsigned int pEXPNum)
{
  signed int pActivePlayerCount; // ecx@1
  int pLearningPercent; // eax@13

  pActivePlayerCount = 0;
  for ( uint i = 0; i < 4; ++i )
  {
    if ( !pParty->pPlayers[i].pConditions[13] && !pParty->pPlayers[i].pConditions[14] && !pParty->pPlayers[i].pConditions[15] && !pParty->pPlayers[i].pConditions[16] )
      pActivePlayerCount ++;
  }
  if ( pActivePlayerCount )
  {
    pEXPNum = pEXPNum / pActivePlayerCount;
    for ( uint i = 0; i < 4; ++i )
    {
      if ( !pParty->pPlayers[i].pConditions[13] && !pParty->pPlayers[i].pConditions[14] && !pParty->pPlayers[i].pConditions[15] && !pParty->pPlayers[i].pConditions[16] )
      {
        if ( pEXPNum )
        {
          pLearningPercent = pParty->pPlayers[i].GetLearningPercent();
          pEXPNum = pEXPNum + pEXPNum * pLearningPercent / 100;
          pParty->pPlayers[i].uExperience += pEXPNum;
          if ( pParty->pPlayers[i].uExperience > 4000000000i64 )
          {
            pParty->pPlayers[i].uExperience = 0;
          }
        }
      }
    }
  }
}

//----- (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].uSpecEnchantmentType;
    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 )
      sprintfex(pTmpBuf2.data(), (char*)pGlobalTXT_LocalizationStrings[490], v14, v9);
    else
      sprintfex(pTmpBuf2.data(), (char*)pGlobalTXT_LocalizationStrings[471], v9);
    ShowStatusBarString(pTmpBuf2.data(), 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.uEnchantmentType = 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 )
        sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[490], v14, v11);
      else
        sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[471], v11);
      ShowStatusBarString(pTmpBuf2.data(), 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 )
    sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[490], v14, v10);
  else
    sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[471], v10);
  ShowStatusBarString(pTmpBuf2.data(), 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]->classType )
            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
  Player *v7; // esi@49
  signed int v8; // edx@50
  SpellBuff *v9; // ecx@50

  switch(a2)
  {
	case 77:
		{
		if ( pActor->sCurrentHP >= (signed int)pActor->pMonsterInfo.uHP )
			return 0;
		return 1;
		}
	case 80:
		{
		v6 = pParty->pPartyBuffs;
		while ( (signed __int64)v6->uExpireTime <= 0 )
		{
			++v6;
			if ( v6 > &pParty->pPartyBuffs[PARTY_BUFF_WIZARD_EYE] )
			{
				v7 = pParty->pPlayers;//[0].pPlayerBuffs;
				v8 = 0;
				v9 = v7->pPlayerBuffs;
				while ( v9->uExpireTime <= 0i64 )
				{
					++v8;
					++v9;
					if ( v8 >= 24 )
					{
						++v7;
						if ( v7 <= &pParty->pPlayers[3] )
						{
							v8 = 0;
							v9 = v7->pPlayerBuffs;
						}
						else
							return 0;
					}
				}
				return 1;
			}
		}
		return 1;
		}
	case 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;
		break;
		}
	case 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;
		break;
		}
	case 95:
		{
        if ( 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;
		break;
		}
	case 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;
		break;
		}
	case 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;
		break;
		}
	case 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;
		break;
		}
	case 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;
		}
	case 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;
		break;
		}
	case 47:
		{
		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;
		break;
		}
	case 51:
		{
		if ( SHIDWORD(pActor->pActorBuffs[18].uExpireTime) < 0 )
			return 1;
		if ( SHIDWORD(pActor->pActorBuffs[18].uExpireTime) <= 0 )
		{
			v3 = 0;
			v4 = LODWORD(pActor->pActorBuffs[18].uExpireTime) == 0;
		}
		else
			return 0;
		break;
		}
	default:
		{
		return 1;
		}
  }
  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

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

//----- (0042777D) --------------------------------------------------------
void _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 )
  if (pParty->bTurnBasedModeOn)
  {
    if (pTurnEngine->field_4 == 1 || pTurnEngine->field_4 == 3)
      return;
  }


    //v6 = a5;
    //v7 = &pParty->pPlayers[uPlayerID];
  assert(uPlayerID < 4);
  auto player = &pParty->pPlayers[uPlayerID];
    if ( !(a5 & 0x10) )
    {
      switch ( a1 )
      {
        case SPELL_SPIRIT_FATE:
        case SPELL_BODY_FIRST_AID:
        case SPELL_DARK_REANIMATE:
          //HIBYTE(v6) = HIBYTE(a5) | 1;
          a5 |= 0x0100;
          break;

        case SPELL_FIRE_FIRE_AURA:
        case SPELL_WATER_RECHARGE_ITEM:
        case SPELL_WATER_ENCHANT_ITEM:
        case SPELL_DARK_VAMPIRIC_WEAPON:
          //LOBYTE(v6) = a5 | 0x80;
          a5 |= 0x0080;
          break;

        case SPELL_FIRE_FIRE_BOLT:
        case SPELL_FIRE_FIREBALL:
        case SPELL_FIRE_INCINERATE:
        case SPELL_AIR_LIGHNING_BOLT:
        case SPELL_AIR_IMPLOSION:
        case SPELL_WATER_POISON_SPRAY:
        case SPELL_WATER_ICE_BOLT:
        case SPELL_WATER_ACID_BURST:
        case SPELL_WATER_ICE_BLAST:
        case SPELL_EARTH_STUN:
        case SPELL_EARTH_SLOW:
        case SPELL_EARTH_DEADLY_SWARM:
        case SPELL_EARTH_BLADES:
        case SPELL_EARTH_MASS_DISTORTION:
        case SPELL_SPIRIT_SPIRIT_LASH:
        case SPELL_MIND_MIND_BLAST:
        case SPELL_MIND_CHARM:
        case SPELL_MIND_PSYCHIC_SHOCK:
        case SPELL_BODY_HARM:
        case SPELL_BODY_FLYING_FIST:
        case SPELL_LIGHT_LIGHT_BOLT:
        case SPELL_LIGHT_DESTROY_UNDEAD:
        case SPELL_LIGHT_SUNRAY:
        case SPELL_DARK_TOXIC_CLOUD:
        case SPELL_DARK_SHRINKING_RAY:
        case SPELL_DARK_SHARPMETAL:
        case SPELL_DARK_DRAGON_BREATH:
          if ( !a6 )
            a5 |= 0x0008;
          break;
        case SPELL_MIND_TELEPATHY:
        case SPELL_MIND_BERSERK:
        case SPELL_MIND_ENSLAVE:
        case SPELL_LIGHT_PARALYZE:
        case SPELL_DARK_CONTROL_UNDEAD:
//LABEL_9:
          //v6 = a5 | 8;
          a5 |= 0x0008;
          break;

        case SPELL_EARTH_TELEKINESIS:
          a5 |= 0x0040;
          break;

        case SPELL_SPIRIT_BLESS:
          if (a4 && ~a4 & 0x01C0)
            //goto LABEL_25;
          {
            a5 |= 0x0002;
            break;
          }
          else if ((player->pActiveSkills[PLAYER_SKILL_SPIRIT] & 0x1C0) == 0)
            //goto LABEL_25;
          {
            a5 |= 0x0002;
            break;
          }
          break;

        case SPELL_SPIRIT_PRESERVATION:
          v9 = a4;
          if ( !a4 )
            v9 = player->pActiveSkills[PLAYER_SKILL_SPIRIT];
          //goto LABEL_18;
          v10 = SkillToMastery(v9);
          v12 = __OFSUB__(v10, 3);
          v11 = ((v10 - 3) & 0x80000000u) != 0;
          //goto LABEL_24;
          if ( v11 ^ v12 )
          {
            a5 |= 0x0002;
            break;
          }
          break;

        case SPELL_DARK_PAIN_REFLECTION:
          v9 = a4;
          if ( !a4 )
            v9 = player->pActiveSkills[PLAYER_SKILL_DARK];
//LABEL_18:
          v10 = SkillToMastery(v9);
          v12 = __OFSUB__(v10, 3);
          v11 = ((v10 - 3) & 0x80000000u) != 0;
          //goto LABEL_24;
          if ( v11 ^ v12 )
          {
            a5 |= 0x0002;
            break;
          }
          break;

        case SPELL_BODY_HAMMERHANDS:
          v13 = a4;
          if ( !a4 )
            v13 = player->pActiveSkills[PLAYER_SKILL_BODY];
          v14 = SkillToMastery(v13);
          v12 = __OFSUB__(v14, 4);
          v11 = ((v14 - 4) & 0x80000000u) != 0;
//LABEL_24:
          if ( v11 ^ v12 )
            //goto LABEL_25;
          {
            a5 |= 0x0002;
            break;
          }
          break;

        case SPELL_EARTH_STONE_TO_FLESH:
        case SPELL_SPIRIT_REMOVE_CURSE:
        case SPELL_SPIRIT_RAISE_DEAD:
        case SPELL_SPIRIT_RESSURECTION:
        case SPELL_MIND_REMOVE_FEAR:
        case SPELL_MIND_CURE_PARALYSIS:
        case SPELL_MIND_CURE_INSANITY:
        case SPELL_BODY_CURE_WEAKNESS:
        case SPELL_BODY_REGENERATION:
        case SPELL_BODY_CURE_POISON:
        case SPELL_BODY_CURE_DISEASE:
//LABEL_25:
          //v6 = a5 | 2;
          a5 |= 0x0002;
          break;

        case SPELL_DARK_SACRIFICE:
          //HIBYTE(v6) = HIBYTE(a5) | 2;
          a5 |= 0x0200;
          break;
        default:
          break;
      }
    }


    if (a5 & 0x3CA)
    {
      assert(sizeof(pCastSpellInfo) / sizeof(*pCastSpellInfo.data()) == 10);
      for (uint i = 0; i < 10; ++i)
        if (pCastSpellInfo[i].field_8 & 0x3CA)
        {
          pCastSpellInfo[i].spellnum = 0;
          break;
        }
    }
      
    assert(sizeof(pCastSpellInfo) / sizeof(*pCastSpellInfo.data()) == 10);
    for (uint i = 0; i < 10; ++i)
    {
      auto spell = &pCastSpellInfo[i];
      if (!spell->spellnum)
        continue;

      spell->spellnum = 0;
      if (spell->field_8 & 0x3CA)
      {
        pGUIWindow_Settings->Release();
        pGUIWindow_Settings = nullptr;
        pMouse->SetCursorBitmap("MICON1");
        GameUI_Footer_TimeLeft = 0;
        unk_50C9A0 = 0;
        back_to_game();
      }
    }

    int result = pCastSpellInfo.data()->PushCastSpellInfo(a1, uPlayerID, a4, a5, a6);
    if ( result != -1 )
    {
      if ( a5 & 2 )
      {
        if ( pGUIWindow_Settings )
          return;
        pGUIWindow_Settings = GUIWindow::Create(0, 0, 640, 480, WINDOW_CastSpell, (int)&pCastSpellInfo[result], 0);
        pGUIWindow_Settings->CreateButton(52, 422, 35, 0, 2, 0, UIMSG_CastSpell_Character_Big_Improvement, 0, 49, "", 0);
        pGUIWindow_Settings->CreateButton(165, 422, 35, 0, 2, 0, UIMSG_CastSpell_Character_Big_Improvement, 1, 50, "", 0);
        pGUIWindow_Settings->CreateButton(280, 422, 35, 0, 2, 0, UIMSG_CastSpell_Character_Big_Improvement, 2, 51, "", 0);
        pGUIWindow_Settings->CreateButton(390, 422, 35, 0, 2, 0, UIMSG_CastSpell_Character_Big_Improvement, 3, 52, "", 0);
        sub_421B2C_PlaceInInventory_or_DropPickedItem();
        return;
      }
      if ( a5 & 8 )
      {
        if ( pGUIWindow_Settings )
          return;

        pGUIWindow_Settings = GUIWindow::Create(0, 0, 640, 480, WINDOW_CastSpell, (int)&pCastSpellInfo[result], 0);
        pGUIWindow_Settings->CreateButton(game_viewport_x, game_viewport_y, game_viewport_width, game_viewport_height, 1, 0, UIMSG_CastSpell_Shoot_Monster, 0, 0, "", 0);
        sub_421B2C_PlaceInInventory_or_DropPickedItem();
        return;
      }
      if ( a5 & 0x40 )
      {
        if ( pGUIWindow_Settings )
          return;

        pGUIWindow_Settings = GUIWindow::Create(0, 0, 640, 480, WINDOW_CastSpell, (int)&pCastSpellInfo[result], 0);
        pGUIWindow_Settings->CreateButton(game_viewport_x, game_viewport_y, game_viewport_width, game_viewport_height, 1, 0, UIMSG_CastSpell_BE, 0, 0, "", 0);
        sub_421B2C_PlaceInInventory_or_DropPickedItem();
        return;
      }
      if ( (char)a5 < 0 )
      {
        if ( pGUIWindow_Settings )
          return;
        ++pIcons_LOD->uTexturePacksCount;
        if ( !pIcons_LOD->uNumPrevLoadedFiles )
          pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles;
        pGUIWindow_Settings = pCastSpellInfo[result].sub_4219BE();
        unk_50C9A0 = 1;
        some_active_character = uActiveCharacter;
        sub_421B2C_PlaceInInventory_or_DropPickedItem();
        return;
      }
      if ( HIBYTE(a5) & 1 )
      {
        if ( pGUIWindow_Settings )
          return;
        pGUIWindow_Settings = GUIWindow::Create(0, 0, 640, 480, WINDOW_CastSpell, (int)&pCastSpellInfo[result], 0);
        pGUIWindow_Settings->CreateButton(0x34u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_Character_Small_Improvement, 0, 0x31u, "", 0);
        pGUIWindow_Settings->CreateButton(0xA5u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_Character_Small_Improvement, 1, 0x32u, "", 0);
        pGUIWindow_Settings->CreateButton(0x118u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_Character_Small_Improvement, 2, 0x33u, "", 0);
        pGUIWindow_Settings->CreateButton(0x186u, 0x1A6u, 0x23u, 0, 2, 0, UIMSG_CastSpell_Character_Small_Improvement, 3, 0x34u, "", 0);
        pGUIWindow_Settings->CreateButton(8, 8, game_viewport_width, game_viewport_height, 1, 0, UIMSG_CastSpell_Monster_Improvement, 0, 0, "", NULL);
        sub_421B2C_PlaceInInventory_or_DropPickedItem();
      }
      if ( HIBYTE(a5) & 2 && !pGUIWindow_Settings )
      {
        pGUIWindow_Settings = GUIWindow::Create(0, 0, 640, 480, WINDOW_CastSpell, (int)&pCastSpellInfo[result], 0);
        pBtn_NPCLeft = pGUIWindow_Settings->CreateButton(469, 178,
                       pIcons_LOD->GetTexture(uTextureID_Btn_NPCLeft)->uTextureWidth,
                       pIcons_LOD->GetTexture(uTextureID_Btn_NPCLeft)->uTextureHeight,
                       1, 0, UIMSG_ScrollNPCPanel, 0, 0, "",
                       pIcons_LOD->GetTexture(uTextureID_Btn_NPCLeft), 0);
        pBtn_NPCRight = pGUIWindow_Settings->CreateButton(626, 178,
                       pIcons_LOD->GetTexture(uTextureID_Btn_NPCRight)->uTextureWidth,
                       pIcons_LOD->GetTexture(uTextureID_Btn_NPCRight)->uTextureHeight,
                       1, 0, UIMSG_ScrollNPCPanel, 1, 0, "",
                       pIcons_LOD->GetTexture(uTextureID_Btn_NPCRight), 0);
        pGUIWindow_Settings->CreateButton(491, 149, 64, 74, 1, 0, UIMSG_HiredNPC_CastSpell, 4, 0x35u, "", 0);
        pGUIWindow_Settings->CreateButton(561, 149, 64, 74, 1, 0, UIMSG_HiredNPC_CastSpell, 5, 0x36u, "", 0);
      }
    }
}

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

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

//----- (00427DA0) --------------------------------------------------------
unsigned int CastSpellInfo::PushCastSpellInfo(__int16 a2, __int16 uPlayerID, __int16 skill_level, __int16 a5, int spell_sound_id)
{
  unsigned int result; // eax@1
  CastSpellInfo *v7; // edx@1
  CastSpellInfo *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;
  v8->spell_target_pid = 0;
  v8->field_8 = a5;
  v8->forced_spell_skill_level = skill_level;
  v8->sound_id = spell_sound_id;
LABEL_8:
  if ( result == 10 )
    result = -1;
  return result;
}

//----- (00427E01) --------------------------------------------------------
void CastSpellInfo::_427E01_cast_spell()
{
  int v2; // edi@1
  CastSpellInfo *pCastSpell; // ebx@2
  signed int v6; // eax@14
  unsigned __int16 v11; // cx@45
  unsigned __int8 v14; // zf@53
  signed int i; // esi@76
  __int16 v23; // ax@88
  int v51; // eax@146
  __int16 v52; // ax@153
  signed __int64 v54; // qax@164
  Actor *v55; // edi@164
  signed __int64 v58; // qax@177
  Actor *pActor; // edi@177
  unsigned __int16 v60; // ax@184
  int v61; // ecx@184
  ItemGen *v69; // esi@211
  double v90; // st7@245
  Player *v92; // eax@255
  int v105; // edi@271
  __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
  signed int v122; // eax@286
  int v127; // eax@296
  int v153; // ecx@322
  int v154; // eax@322
  int v155; // eax@323
  int v156; // eax@323
  int v162; // edi@340
  signed int v164; // eax@340
  signed int v165; // edi@340
  signed int v168; // edi@343
  int v169; // eax@344
  signed int v174; // edi@355
  int v188; // esi@369
  int v189; // edi@369
  signed int v191; // edi@379
  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
  char v223; // al@438

  int v227; // esi@453
  unsigned int v228; // edi@454
  int v229; // edi@466

  ItemGen *v240; // ecx@472
  double v241; // st7@478
  ItemGen *v245; // edi@492
  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
  char v271; // al@531
  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
  ItemGen *v294; // esi@575
  int v295; // edx@575
  int kk; // edi@575
  char v313; // al@606pGame->GetStru6()
  const char *v317; // ecx@617
  Player *v318; // ecx@619
  unsigned int v319; // edi@627
  int v323; // edi@635
  char *v324; // eax@635
  Player *v325; // ecx@640
  int v328; // ecx@651
  int v329; // ecx@652
  int v330; // edi@654
  signed int v342; // edi@668
  signed int v343; // edi@670
  unsigned __int64 v344; // ST08_8@670
  Player *v351; // edi@680
  Player *v357; // edi@694
  Actor *v369; // edi@705
  int v373; // eax@715
  int v374; // eax@717
  int v376; // eax@717
  Player *v377; // ecx@719
  int v381; // edi@727
  int v382; // ecx@727
  Player *v383; // eax@728
  int v384; // eax@733
  int v388; // edi@740
  int v396; // eax@752
  int v397; // eax@757
  int v398; // eax@757
  int v399; // eax@757
  Actor *v417; // eax@787
  int v418; // ecx@789
  __int16 v419; // ax@791
  signed int v420; // eax@793
  ItemGen *v421; // edx@793
  const char *v422; // eax@801
  signed int v426; // eax@815
  Actor *v433; // edi@832
  int v435; // ecx@837
  int v440; // eax@843
  int v441; // eax@847
  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
  signed int v460; // eax@895
  Actor *v461; // eax@897
  unsigned __int16 v462; // cx@897
  signed int v463; // edx@897
  int v470; // edi@913
  int v471; // eax@917
  int v472; // eax@917
  int v498; // edi@931
  int v499; // eax@935
  int v500; // eax@935
  Player *v501; // edi@939
  int v505; // eax@943
  int v507; // edi@944
  signed int v509; // eax@944
  //signed int v510; // edi@944
  Actor *v518; // edx@957
  __int16 v519; // cx@958
  int v531; // eax@982
  int v533; // edi@983
  signed int v535; // eax@983
  signed int v536; // edi@983
  stru6 *v537; // eax@984
  double v549; // st7@991
  unsigned __int16 v550; // di@991
  Player *v553; // edi@1001
  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
  Player *v571; // eax@1013
  char *v572; // ecx@1013
  signed int v576; // eax@1025
  Player *v577; // eax@1026
  int v578; // eax@1028
  __int16 v579; // ax@1029
  int v581; // edi@1031
  char *v585; // esi@1034
  signed int v587; // eax@1035
  char v591; // al@1048
  ItemGen *v592; // esi@1052
  int v596; // esi@1066
  unsigned int v597; // edi@1067
  int v600; // edi@1086
  int v601; // edx@1086
  int v602; // eax@1086
  int v603; // ecx@1086
  NPCData *pNPCData; // eax@1089
  int v606; // edx@1091
  AwardType *v607; // ecx@1100
  __int16 v608; // ax@1102
  signed int v609; // eax@1104
  int v610; // edi@1106
  unsigned int v611; // eax@1106
  Player *v612; // edi@1106
  DDM_DLV_Header *v613; // eax@1108
  int v615; // edi@1119
  Player *v619; // edi@1123
  signed __int64 v623; // qax@1127
  int v625; // edi@1129
  signed int v627; // eax@1129
  signed int v628; // edi@1129
  int v629; // ecx@1130
  Player *v630; // eax@1131
  int v631; // eax@1137
  int v635; // edi@1142
  int v642; // edi@1156
  int v643; // eax@1156
  int v644; // eax@1156
  signed int v645; // eax@1158
  unsigned int v656; // [sp-4h] [bp-E88h]@639
  int v657; // [sp-4h] [bp-E88h]@807
  int v659; // [sp+0h] [bp-E84h]@123
  int v660; // [sp+0h] [bp-E84h]@146
  Actor *v661; // [sp+0h] [bp-E84h]@164
  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
  PLAYER_SKILL_TYPE v667; // [sp+4h] [bp-E80h]@25
  int v671; // [sp+4h] [bp-E80h]@146
  int v675; // [sp+4h] [bp-E80h]@800
  int v676; // [sp+4h] [bp-E80h]@807
  int v677; // [sp+4h] [bp-E80h]@861
  int v679[800]; // [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
  unsigned __int64 v687; // [sp+D24h] [bp-160h]@327
  Vec3_int_ v688; // [sp+D2Ch] [bp-158h]@943
  Vec3_int_ v691; // [sp+D38h] [bp-14Ch]@137
  Vec3_int_ v694; // [sp+D44h] [bp-140h]@982
  Vec3_int_ v697; // [sp+D50h] [bp-134h]@129
  Vec3_int_ v700; // [sp+D5Ch] [bp-128h]@339
  Vec3_int_ v701; // [sp+D68h] [bp-11Ch]@286
  Vec3_int_ v704; // [sp+D74h] [bp-110h]@132
  Vec3_int_ v707; // [sp+D80h] [bp-104h]@1127
  int v710; // [sp+D8Ch] [bp-F8h]@1156
  __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
  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
  Player *v730b;
  ItemGen *v730c;
  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

  SpriteObject pSpellSprite; // [sp+DDCh] [bp-A8h]@1

  v2 = 0;
  amount = 0;
  LODWORD(v733) = 0;
  v723 = 0;
  v727 = 0.0;
  for(n = 0; n < 10; ++n)
  {
    pCastSpell = &this[n];
    HIDWORD(v733) = (int)pCastSpell;
    if ( pCastSpell->spellnum == 0 )
      continue;

    if (pParty->Invisible())
      pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Reset();

    if ( pCastSpell->field_8 & 0x3CA )
    {
      if ( !pParty->pPlayers[pCastSpell->uPlayerID].CanAct() )
        this->_427D48(1);
      continue;
    }
    pPlayer = &pParty->pPlayers[pCastSpell->uPlayerID];

    a2 = pCastSpell->spell_target_pid;
    if (!pCastSpell->spell_target_pid)
    {
      if (pCastSpell->spellnum == SPELL_LIGHT_DESTROY_UNDEAD ||
          pCastSpell->spellnum == SPELL_SPIRIT_TURN_UNDEAD ||
          pCastSpell->spellnum == SPELL_DARK_CONTROL_UNDEAD )
        v666 = 1;
      else
        v666 = 0;

      a2 = stru_50C198.FindClosestActor(5120, 1, v666);
      v6 = pMouse->uPointingObjectID;
      if ( pMouse->uPointingObjectID && PID_TYPE(v6) == OBJECT_Actor && pActors[PID_ID(v6)].CanAct() )
        a2 = pMouse->uPointingObjectID;
    }


    pSpellSprite.uType = stru_4E3ACC[pCastSpell->spellnum].uType;
    if (pSpellSprite.uType)
    {
      if (PID_TYPE(a2) == OBJECT_Actor)
      {
        memcpy(&v715, Actor::GetDirectionInfo(PID(OBJECT_Player, pCastSpell->uPlayerID + 1), a2, &a3, 0), sizeof(v715));
        v2 = v723;
      }
      else
      {
        v715.uYawAngle = pParty->sRotationY;
        v715.uPitchAngle = pParty->sRotationX;
      }
    }

    LODWORD(v725) = 0;
    _this = 0;
    if (pCastSpell->forced_spell_skill_level)
    {
      v11 = pCastSpell->forced_spell_skill_level;
      v723 = v11 & 0x3F; // 6 bytes
      v2 = v723;
    }
    else
    {
      //v667 = PLAYER_SKILL_STAFF;
      if (pCastSpell->spellnum < SPELL_AIR_WIZARD_EYE)
        v667 = PLAYER_SKILL_FIRE;
      else if (pCastSpell->spellnum < SPELL_WATER_AWAKEN)
        v667 = PLAYER_SKILL_AIR;
      else if (pCastSpell->spellnum < SPELL_EARTH_STUN)
        v667 = PLAYER_SKILL_WATER;
      else if (pCastSpell->spellnum < SPELL_SPIRIT_DETECT_LIFE)
        v667 = PLAYER_SKILL_EARTH;
      else if (pCastSpell->spellnum < SPELL_MIND_REMOVE_FEAR)
        v667 = PLAYER_SKILL_SPIRIT;
      else if (pCastSpell->spellnum < SPELL_BODY_CURE_WEAKNESS)
        v667 = PLAYER_SKILL_MIND;
      else if (pCastSpell->spellnum < SPELL_LIGHT_LIGHT_BOLT)
        v667 = PLAYER_SKILL_BODY;
      else if (pCastSpell->spellnum < SPELL_DARK_REANIMATE)
        v667 = PLAYER_SKILL_LIGHT;
      else if (pCastSpell->spellnum < SPELL_BOW_ARROW)
        v667 = PLAYER_SKILL_DARK;
      else if (pCastSpell->spellnum == SPELL_BOW_ARROW)
        v667 = PLAYER_SKILL_BOW;
      else assert(false && "Unknown spell");

      LODWORD(v725) = v667;
      v723 = pPlayer->GetActualSkillLevel(v667) & 0x3F;
      v2 = v723;
      v11 = pPlayer->pActiveSkills[LODWORD(v725)];
    }

	v731 = SkillToMastery(v11);

    if (pCastSpell->forced_spell_skill_level)
      uRequiredMana = 0;
    else 
      uRequiredMana = pSpellDatas[pCastSpell->spellnum].mana_per_skill[v731 - 1];
    sRecoveryTime = pSpellDatas[pCastSpell->spellnum].recovery_per_skill[v731 - 1];

    if (LODWORD(v725) == PLAYER_SKILL_DARK && pParty->uCurrentHour == 0 && pParty->uCurrentMinute == 0 ||
        LODWORD(v725) == PLAYER_SKILL_LIGHT && pParty->uCurrentHour == 12 && pParty->uCurrentMinute == 0)
      uRequiredMana = 0;

    if (pCastSpell->spellnum < SPELL_BOW_ARROW && pPlayer->sMana < uRequiredMana)
    {
      ShowStatusBarString(pGlobalTXT_LocalizationStrings[586], 2u); // "Not enough spell points"
      pCastSpell->spellnum = 0;
      continue;
    }
    v730 = pCastSpell->spellnum;
    if (pPlayer->Cursed() && pCastSpell->spellnum < SPELL_BOW_ARROW && rand() % 100 < 50)
    {
      if (!pParty->bTurnBasedModeOn)
      {
        //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[this[n].uPlayerID] = 100;
        pPlayer->SetRecoveryTime(sRecoveryTime);
        pTurnEngine->_40471C();
      }
      ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2u); // "Spell failed"
      pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
      this[n].spellnum = 0;
      pPlayer->sMana -= uRequiredMana;
      return;
    }

    switch ( pCastSpell->spellnum )
    {
		case SPELL_101:
			assert(false && "Unknown spell effect #101 (prolly flaming bow arrow");
		case SPELL_BOW_ARROW:
		{
			amount = 1;
			if ( SkillToMastery(pPlayer->pActiveSkills[PLAYER_SKILL_BOW]) >= 3 )
				amount = 2;
			sRecoveryTime = pPlayer->GetAttackRecoveryTime(true);
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			if ( pPlayer->WearsItem(ITEM_ARTEFACT_ULLYSES, EQUIP_BOW) )
				pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(0xBD6u);
			pSpellSprite.vPosition.x = pParty->vPosition.x;
			pSpellSprite.vPosition.y = pParty->vPosition.y;
			pSpellSprite.uAttributes = 0;
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.spell_target_pid = a2;
			pSpellSprite.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
			pSpellSprite.uFacing = LOWORD(v715.uYawAngle);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			pPlayer = &pParty->pPlayers[pCastSpell->uPlayerID];
			memcpy(&pSpellSprite.stru_24, &pPlayer->pInventoryItems[pPlayer->pEquipment.uBow-1], sizeof(pSpellSprite.stru_24));
			pSpellSprite.uAttributes = 256;
			if ( pParty->bTurnBasedModeOn == 1 )
				pSpellSprite.uAttributes = 260;
			for ( i = 0; i < amount; ++i )
			{
				if ( i )
					pSpellSprite.vPosition.z += 32;
				pSpellSprite.uSectorID = pIndoor->GetSector(pSpellSprite.vPosition.x, pSpellSprite.vPosition.y, pSpellSprite.vPosition.z);
				if ( pSpellSprite.Create(v715.uYawAngle, v715.uPitchAngle, pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed,
					pCastSpell->uPlayerID + 1) != -1 && pParty->bTurnBasedModeOn == 1 )
				++pTurnEngine->field_1C;
			}
			break;
		}
		case SPELL_LASER_PROJECTILE:
		{
			sRecoveryTime = pPlayer->GetAttackRecoveryTime(0);
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v723;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.vPosition.x = pParty->vPosition.x;
			pSpellSprite.vPosition.y = pParty->vPosition.y;
			pSpellSprite.uAttributes = 0;
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 2;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.spell_target_pid = a2;
			pSpellSprite.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
			pSpellSprite.uFacing = LOWORD(v715.uYawAngle);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			pPlayer = &pParty->pPlayers[pCastSpell->uPlayerID];
			memcpy(&pSpellSprite.stru_24, &pPlayer->pInventoryItems[pPlayer->pEquipment.uMainHand-1],sizeof(pSpellSprite.stru_24));
			//	&pParty->pPlayers[pCastSpell->uPlayerID].spellbook.pDarkSpellbook.bIsSpellAvailable[36
			//		* pParty->pPlayers[pCastSpell->uPlayerID].pEquipment.uMainHand + 5], );
			v23 = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pSpellSprite.vPosition.z);
			HIBYTE(pSpellSprite.uAttributes) |= 1u;
			pSpellSprite.uSectorID = v23;
			if ( pParty->bTurnBasedModeOn == 1 )
				LOBYTE(pSpellSprite.uAttributes) |= 4u;
			if ( pSpellSprite.Create(v715.uYawAngle, v715.uPitchAngle, pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed,
					pCastSpell->uPlayerID + 1) != -1 && pParty->bTurnBasedModeOn == 1 )
				++pTurnEngine->field_1C;
			break;
		}
		case SPELL_FIRE_TORCH_LIGHT:
		{
			switch (v731)
			{
				case 1: amount = 2; break;
				case 2: amount = 3; break;
				case 3:
				case 4: amount = 4; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			pParty->pPartyBuffs[PARTY_BUFF_TORCHLIGHT].Apply(pParty->uTimePlayed + (signed __int64)((double)(signed int)3600 * v2 * 4.2666669), v731, amount, 0, 0);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_FIRE_FIRE_SPIKE:
		{
			switch (v731)
			{
				case 1: amount = 3; break;
				case 2: amount = 5; break;
				case 3: amount = 7; break;
				case 4: amount = 9; break;
				default:
				assert(false);
			}

			//v31 = v3->uPlayerID;
			//v32 = 8 * v31;
			//LOBYTE(v32) = v32 | OBJECT_Player;

			//if ( (signed int)uNumSpriteObjects > 0 )
			int _v733 = 0;
			for (uint i = 0; i < uNumSpriteObjects; ++i)
			{
				auto object = &pSpriteObjects[i];
				if (object->uType && object->spell_id == SPELL_FIRE_FIRE_SPIKE && object->spell_caster_pid == PID(OBJECT_Player, pCastSpell->uPlayerID))
				++_v733;
				/*v33 = (char *)&pSpriteObjects[0].field_48;
				v730 = uNumSpriteObjects;
				do
				{
				if ( *((short *)v33 - 36) && *(int *)v33 == 7 && *((int *)v33 + 4) == v32 )
					++HIDWORD(v733);
				v33 += 112;
				--v730;
				}
				while ( v730 );*/
			}
			if (_v733 > amount)
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2); // Spell failed
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.vPosition.y = pParty->vPosition.y;
			pSpellSprite.vPosition.x = pParty->vPosition.x;
			pSpellSprite.uAttributes = 0;
			pSpellSprite.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
			pSpellSprite.uSectorID = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3);
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.spell_target_pid = a2;
			pSpellSprite.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
			pSpellSprite.uFacing = LOWORD(v715.uYawAngle);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			if ( pParty->bTurnBasedModeOn == 1 )
				LOBYTE(pSpellSprite.uAttributes) |= 4u;
			v659 = pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed;
			if ( pSpellSprite.Create(pParty->sRotationY, pParty->sRotationX + 10, v659, pCastSpell->uPlayerID + 1) != -1 && pParty->bTurnBasedModeOn == 1 )
				++pTurnEngine->field_1C;
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_AIR_IMPLOSION:
		{
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			if (!a2)
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2); // Spell failed
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			if (PID_TYPE(a2) != OBJECT_Actor)
			{
				LODWORD(v727) = 1;
				break;
			}
			v697.x = 0;
			v697.y = 0;
			v697.z = 0;
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.uAttributes = 0;
			pSpellSprite.uSectorID = 0;
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.field_60_distance_related_prolly_lod = 0;
			pSpellSprite.uFacing = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			pSpellSprite.vPosition.x = pActors[PID_ID(a2)].vPosition.x;
			pSpellSprite.vPosition.z = pActors[PID_ID(a2)].vPosition.z;
			pSpellSprite.vPosition.y = pActors[PID_ID(a2)].vPosition.y;
			pSpellSprite.spell_target_pid = PID(OBJECT_Actor, PID_ID(a2));
			auto obj_id = pSpellSprite.Create(0, 0, 0, 0);
			DamageMonsterFromParty(PID(OBJECT_Item, obj_id), PID_ID(a2), &v697);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_EARTH_MASS_DISTORTION:
		{
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			if ( !stru_50C198.GetMagicalResistance(&pActors[PID_ID(a2)], 3u) )
			{
				LODWORD(v727) = 1;
				break;
			}
			pActors[PID_ID(a2)].pActorBuffs[10].Apply(pMiscTimer->uTotalGameTimeElapsed + 128, 0, 0, 0, 0);
			v704.x = 0;
			v704.y = 0;
			v704.z = 0;
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.uAttributes = 0;
			pSpellSprite.uSectorID = 0;
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.field_60_distance_related_prolly_lod = 0;
			pSpellSprite.uFacing = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			pSpellSprite.vPosition.x = pActors[PID_ID(a2)].vPosition.x;
			pSpellSprite.vPosition.y = pActors[PID_ID(a2)].vPosition.y;
			pSpellSprite.vPosition.z = pActors[PID_ID(a2)].vPosition.z;
			pSpellSprite.spell_target_pid = PID(OBJECT_Actor, PID_ID(a2));
			auto obj_id = pSpellSprite.Create(0, 0, 0, 0);
			DamageMonsterFromParty(PID(OBJECT_Item, obj_id), PID_ID(a2), &v704);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_LIGHT_DESTROY_UNDEAD:
		{
			if ( !pPlayer->CanCastSpell(uRequiredMana) || !a2 || PID_TYPE(a2) != OBJECT_Actor)
				break;
			//v730 = a2 >> 3;
			//HIDWORD(v733) = (int)&pActors[PID_ID(a2)];
			v691.x = 0;
			v691.y = 0;
			v691.z = 0;
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.vPosition.x = pActors[PID_ID(a2)].vPosition.x;
			pSpellSprite.vPosition.y = pActors[PID_ID(a2)].vPosition.y;
			pSpellSprite.vPosition.z = pActors[PID_ID(a2)].vPosition.z;
			pSpellSprite.uAttributes = 0;
			pSpellSprite.uSectorID = pIndoor->GetSector(pSpellSprite.vPosition.x, pSpellSprite.vPosition.y, pSpellSprite.vPosition.z);
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.spell_target_pid = a2;
			pSpellSprite.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
			pSpellSprite.uFacing = LOWORD(v715.uYawAngle);
			pSpellSprite.uAttributes |= 0x80u;
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			auto obj_id = pSpellSprite.Create(0, 0, 0, 0);
			if ( !MonsterStats::BelongsToSupertype(pActor->pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD) )
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2); // Spell failed
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			DamageMonsterFromParty(PID(OBJECT_Item, obj_id), PID_ID(a2), &v691);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_FIRE_FIRE_BOLT:
		case SPELL_FIRE_FIREBALL:
		case SPELL_FIRE_INCINERATE:
		case SPELL_AIR_LIGHNING_BOLT:
		case SPELL_WATER_ICE_BOLT:
		case SPELL_WATER_ICE_BLAST:
		case SPELL_EARTH_STUN:
		case SPELL_EARTH_DEADLY_SWARM:
		case SPELL_MIND_MIND_BLAST:
		case SPELL_MIND_PSYCHIC_SHOCK:
		case SPELL_BODY_HARM:
		case SPELL_LIGHT_LIGHT_BOLT:
		case SPELL_DARK_DRAGON_BREATH:
		{
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.vPosition.y = pParty->vPosition.y;
			pSpellSprite.vPosition.x = pParty->vPosition.x;
			pSpellSprite.uAttributes = 0;
			pSpellSprite.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
			if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
				pSpellSprite.uSectorID = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3);
			else
				pSpellSprite.uSectorID = 0;
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.spell_target_pid = a2;
			pSpellSprite.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
			pSpellSprite.uFacing = LOWORD(v715.uYawAngle);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			if ( pParty->bTurnBasedModeOn == 1 )
				LOBYTE(pSpellSprite.uAttributes) |= 4u;
			if ( pCastSpell->spellnum == SPELL_AIR_LIGHNING_BOLT )
				LOBYTE(pSpellSprite.uAttributes) |= 0x40u;
			v659 = pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed;
			if ( pSpellSprite.Create(v715.uYawAngle, v715.uPitchAngle, v659, pCastSpell->uPlayerID + 1) != -1 && pParty->bTurnBasedModeOn == 1 )
				++pTurnEngine->field_1C;
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_WATER_ACID_BURST:
		case SPELL_EARTH_BLADES:
		case SPELL_BODY_FLYING_FIST:
		case SPELL_DARK_TOXIC_CLOUD:
		{
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			v51 = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 2;
			pSpellSprite.vPosition.y = pParty->vPosition.y;
			v671 = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 2;
			v660 = pParty->vPosition.y;
			pSpellSprite.uAttributes = 0;
			pSpellSprite.vPosition.x = pParty->vPosition.x;
			pSpellSprite.vPosition.z = v51;
			v52 = pIndoor->GetSector(pParty->vPosition.x, v660, v671);
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.uSectorID = v52;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.spell_target_pid = a2;
			pSpellSprite.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
			pSpellSprite.uFacing = LOWORD(v715.uYawAngle);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			if ( pParty->bTurnBasedModeOn == 1 )
				LOBYTE(pSpellSprite.uAttributes) |= 4u;
			v659 = pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed;
			if ( pSpellSprite.Create(v715.uYawAngle, v715.uPitchAngle, v659, pCastSpell->uPlayerID + 1) != -1 && pParty->bTurnBasedModeOn == 1 )
				++pTurnEngine->field_1C;
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_LIGHT_SUNRAY:
		{
			if ( uCurrentlyLoadedLevelType == LEVEL_Indoor
				|| uCurrentlyLoadedLevelType == LEVEL_Outdoor && (pParty->uCurrentHour < 5 || pParty->uCurrentHour >= 21) )
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2); // Spell failed
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			if ( pPlayer->CanCastSpell(uRequiredMana) )
			{
				pSpellSprite.stru_24.Reset();
				pSpellSprite.spell_id = pCastSpell->spellnum;
				pSpellSprite.spell_skill = v731;
				pSpellSprite.spell_level = v2;
				pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
				pSpellSprite.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;
				pSpellSprite.uAttributes = 0;
				pSpellSprite.vPosition.x = pParty->vPosition.x;
				pSpellSprite.vPosition.z = v51;
				v52 = pIndoor->GetSector(pParty->vPosition.x, v660, v671);
				pSpellSprite.uSpriteFrameID = 0;
				pSpellSprite.uSectorID = v52;
				pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
				pSpellSprite.spell_target_pid = a2;
				pSpellSprite.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
				pSpellSprite.uFacing = LOWORD(v715.uYawAngle);
				pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
				if ( pParty->bTurnBasedModeOn == 1 )
					LOBYTE(pSpellSprite.uAttributes) |= 4u;
				v659 = pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed;
				if ( pSpellSprite.Create(v715.uYawAngle, v715.uPitchAngle, v659, pCastSpell->uPlayerID + 1) != -1 && pParty->bTurnBasedModeOn == 1 )
					++pTurnEngine->field_1C;
				LODWORD(v727) = 1;
			}
			break;
		}
		case SPELL_LIGHT_PARALYZE:
		{
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			if (PID_TYPE(a2) != OBJECT_Actor || (v730 = PID_ID(a2), v721 = (int)&pActors[PID_ID(a2)],
					!stru_50C198.GetMagicalResistance(&pActors[PID_ID(a2)], 9)) )
			{
				LODWORD(v727) = 1;
				break;
			}
			Actor::AI_Stand(PID_ID(a2), 4u, 0x80u, 0);
			v54 = (signed __int64)((double)(23040 * v2) * 0.033333335);
			v55 = &pActors[PID_ID(a2)];
			v55->pActorBuffs[6].Apply(pParty->uTimePlayed + (signed int)v54, v731, 0, 0, 0);
			BYTE2(v55->uAttributes) |= 8u;
			v55->vVelocity.x = 0;
			//v672 = 0;
			v55->vVelocity.y = 0;
			v661 = v55;
			pGame->GetStru6()->_4A7E89_sparkles_on_actor_after_it_casts_buff(v661, 0);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_EARTH_SLOW:
		{
			switch (v731)
			{
				case 1: LODWORD(v733) = 180 * v2; amount = 2; break;
				case 2: LODWORD(v733) = 300 * v2; amount = 2; break;
				case 3: LODWORD(v733) = 300 * v2; amount = 4; break;
				case 4: LODWORD(v733) = 300 * v2; amount = 8; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			if (PID_TYPE(a2) != OBJECT_Actor
				|| (v721 = 836 * PID_ID(a2),
					LODWORD(v718) = (int)&pActors[PID_ID(a2)],
					!stru_50C198.GetMagicalResistance(&pActors[PID_ID(a2)], 3u)) )
			{
				LODWORD(v727) = 1;
				break;
			}
			v58 = (signed __int64)((double)(23040 * v2) * 0.033333335);
			//v59 = v721;
			pActor = &pActors[PID_ID(a2)];
			//((SpellBuff *)((char *)&pActors[0].pActorBuffs[7] + v721))->Apply(
			pActor->pActorBuffs[7].Apply(pParty->uTimePlayed + (signed int)v58,	v731, amount, 0, 0);
			//*((char *)&pActors[0].uAttributes + v59 + 2) |= 8u;
			BYTE2(pActor->uAttributes) |= 8u;
			//v672 = 0;
			v661 = (Actor *)LODWORD(v718);
			pGame->GetStru6()->_4A7E89_sparkles_on_actor_after_it_casts_buff(v661, 0);
			LODWORD(v727) = 1;
			break;
      }
		case SPELL_MIND_CHARM:
		{
		if ( !pPlayer->CanCastSpell(uRequiredMana) )
			break;

		if ( !stru_50C198.GetMagicalResistance(&pActors[PID_ID(a2)], 7u) )
		{
			LODWORD(v727) = 1;
			break;
		}

		uint power = 300 * v2;
		if ( v731 == 2 )
		{
			power = 600 * v2;
		}
		else if ( v731 == 3 )
			power  = 29030400;

		//((SpellBuff *)((char *)&pActors[0].pActorBuffs[9] + v730))->Reset();
		pActors[PID_ID(a2)].pActorBuffs[9].Reset();
		//((SpellBuff *)((char *)&pActors[0].pActorBuffs[12] + v730))->Reset();
		pActors[PID_ID(a2)].pActorBuffs[12].Reset();
		//((SpellBuff *)((char *)&pActors[0].pActorBuffs[1] + v730))->Apply(
		pActors[PID_ID(a2)].pActorBuffs[1].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)(power << 7) * 0.033333335),
			v731, 0, 0, 0);
		pSpellSprite.stru_24.Reset();
		pSpellSprite.spell_id = pCastSpell->spellnum;
		pSpellSprite.spell_level = v2;
		pSpellSprite.spell_skill = v731;
		v60 = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
		v61 = PID_ID(a2);
			v600 = pActors[v61].vPosition.y;
			v601 = pActors[v61].vPosition.x;
			pSpellSprite.uObjectDescID = v60;
			pSpellSprite.vPosition.x = v601;
			v602 = pActors[v61].uActorHeight;
			v603 = pActors[v61].vPosition.z;
			pSpellSprite.vPosition.y = v600;
			v676 = v603 + v602;
			v665 = v600;
			pSpellSprite.vPosition.z = v603 + v602;
			v657 = v601;
			pSpellSprite.uAttributes = 0;
			pSpellSprite.uSectorID = pIndoor->GetSector(v657, v665, v676);
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.spell_target_pid = a2;
			pSpellSprite.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
			pSpellSprite.uFacing = LOWORD(v715.uYawAngle);
			LOBYTE(pSpellSprite.uAttributes) |= 0x80u;
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			pSpellSprite.Create(0, 0, 0, pCastSpell->uPlayerID + 1);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_DARK_SHRINKING_RAY:
		{
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			pSpellSprite.stru_24.Reset();
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.vPosition.x = pParty->vPosition.x;
			pSpellSprite.vPosition.y = pParty->vPosition.y;
			pSpellSprite.uAttributes = 0;
			pSpellSprite.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
			pSpellSprite.uSectorID = pIndoor->GetSector(
								pParty->vPosition.x,
								pParty->vPosition.y,
								pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3);
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.spell_target_pid = a2;
			pSpellSprite.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
			pSpellSprite.uFacing = LOWORD(v715.uYawAngle);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			pSpellSprite.spell_skill = v731;
			pSpellSprite.spell_id = SPELL_FIRE_PROTECTION_FROM_FIRE;
			pSpellSprite.spell_level = 300 * v2;
				if ( pParty->bTurnBasedModeOn == 1 )
				LOBYTE(pSpellSprite.uAttributes) |= 4u;

				v659 = pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed;

				if ( pSpellSprite.Create(v715.uYawAngle, v715.uPitchAngle, v659, pCastSpell->uPlayerID + 1) != -1 && pParty->bTurnBasedModeOn == 1 )
				++pTurnEngine->field_1C;
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_FIRE_FIRE_AURA:
		{
			switch (v731)
			{
				case 1: LODWORD(v733) = 3600 * v2; amount = 10; break;
				case 2: LODWORD(v733) = 3600 * v2; amount = 11; break;
				case 3: LODWORD(v733) = 3600 * v2; amount = 12; break;
				case 4: LODWORD(v733) = 0; amount = 12; break;
				default:
				assert(false);
			}
			
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v730c = &pParty->pPlayers[pCastSpell->uPlayerID_2].pInventoryItems[a2];
			auto _itm = &pItemsTable->pItems[v730c->uItemID];
			v730c->UpdateTempBonus(pParty->uTimePlayed);
			if ( v730c->uItemID < 64 || v730c->uItemID > 65 
				&& !v730c->Broken()
				&& !v730c->uSpecEnchantmentType
				&& !v730c->uEnchantmentType
				&& ( _itm->uEquipType == 0 || _itm->uEquipType == 1 || _itm->uEquipType == 2)
				&& !pItemsTable->IsMaterialNonCommon(v730c) )
			{
				v69 = v730c;
				v14 = v731 == 4;
				v730c->uSpecEnchantmentType = amount;
				if ( !v14 )
				{
					v69->uExpireTime = pParty->uTimePlayed
										+ (signed int)(signed __int64)((double)(signed int)((int)v733 << 7)
																		* 0.033333335);
					v69->uAttributes |= 8u;
				}
				v69->uAttributes |= 0x10u;
				_50C9A8_item_enchantment_timer = 256;
				LODWORD(v727) = 1;
				break;
			}

			dword_50C9D0 = 113;
			dword_50C9D4 = 0;
			dword_50C9D8 = 1;

			ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2); // Spell failed
			pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
			pCastSpell->spellnum = 0;
			continue;
		}
		case SPELL_BODY_REGENERATION:
		{
			switch (v731)
			{
				case 1: LODWORD(v733) = 3600 * v2; amount = 1; break;
				case 2: LODWORD(v733) = 3600 * v2; amount = 1; break;
				case 3: LODWORD(v733) = 3600 * v2; amount = 3; break;
				case 4: LODWORD(v733) = 3600 * v2; amount = 10; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;

			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, pCastSpell->uPlayerID_2);

			pParty->pPlayers[pCastSpell->uPlayerID_2].pPlayerBuffs[PLAYER_BUFF_REGENERATION].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)v733 * 4.2666669), v731, amount, 0, 0);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_FIRE_PROTECTION_FROM_FIRE:
		case SPELL_AIR_PROTECTION_FROM_AIR:
		case SPELL_WATER_PROTECTION_FROM_WATER:
		case SPELL_EARTH_PROTECTION_FROM_EARTH:
		case SPELL_MIND_PROTECTION_FROM_MIND:
		case SPELL_BODY_PROTECTION_FROM_BODY:
		{
			switch (v731)
			{
				case 1: 
				case 2: 
				case 3: 
				case 4: LODWORD(v733) = 3600 * v2; amount = v731 * v2; break;
				default:
				assert(false);
			}

			switch (pCastSpell->spellnum)
			{
			  case SPELL_FIRE_PROTECTION_FROM_FIRE:
				LODWORD(v725) = PARTY_BUFF_RESIST_FIRE;
				break;
			  case SPELL_AIR_PROTECTION_FROM_AIR:
				LODWORD(v725) = PARTY_BUFF_RESIST_AIR;
				break;
			  case SPELL_WATER_PROTECTION_FROM_WATER:
				LODWORD(v725) = PARTY_BUFF_RESIST_WATER;
				break;
			  case SPELL_EARTH_PROTECTION_FROM_EARTH:
				LODWORD(v725) = PARTY_BUFF_RESIST_EARTH;
				break;
			  case SPELL_MIND_PROTECTION_FROM_MIND:
				LODWORD(v725) = PARTY_BUFF_RESIST_MIND;
				break;
			  case SPELL_BODY_PROTECTION_FROM_BODY:
				LODWORD(v725) = PARTY_BUFF_RESIST_BODY;
				break;
			  default:
				assert(false);
				continue;
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
			  break;
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 0);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 1);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 2);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 3);
			v90 = (double)(signed int)v733 * 4.2666669;
			pParty->pPartyBuffs[LODWORD(v725)].Apply(pParty->uTimePlayed + (signed int)(signed __int64)v90, v731, amount, 0, 0);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_FIRE_HASTE:
		{
			switch (v731)
			{
				case 1: LODWORD(v733) = 60 * (v2 + 60); break;
				case 2: LODWORD(v733) = 60 * (v2 + 60); break;
				case 3: LODWORD(v733) = 180 * (v2 + 20); break;
				case 4: LODWORD(v733) = 240 * (v2 + 15); break;
				default:
				assert(false);
			}
			if ( pPlayer->CanCastSpell(uRequiredMana) )
			{
				v92 = pParty->pPlayers;//[0].pConditions[1];
				LODWORD(v727) = 1;
				do
				{
					if ( v92->pConditions[1] )
						LODWORD(v727) = 0;
					++v92;
				}
				while ( v92 <= &pParty->pPlayers[3] );
				if (LODWORD(v727))
				{
					pParty->pPartyBuffs[PARTY_BUFF_HASTE].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335), v731, 0, 0, 0);

					pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 0);
					pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 1);
					pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 2);
					pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 3);
				}
			}
			break;
		}
		case SPELL_SPIRIT_BLESS:
		{
			switch (v731)
			{
				case 1: LODWORD(v733) = 300 * (v2 + 12); break;
				case 2: LODWORD(v733) = 300 * (v2 + 12); break;
				case 3: LODWORD(v733) = 900 * (v2 + 4); break;
				case 4: LODWORD(v733) = 3600 * (v2 + 1); break;
				default:
				assert(false);
			}
			amount = v2 + 5;
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			if ( v731 == 1 )
			{
				v108 = pCastSpell->uPlayerID_2;
				v109 = pCastSpell->spellnum;
				v110 = pGame->GetStru6();
				pGame->GetStru6()->SetPlayerBuffAnim(v109, v108);
				v111 = pOtherOverlayList->_4418B1(10000, pCastSpell->uPlayerID_2 + 310, 0, 65536);
				//v668 = 0;
				v716 = v111;
				//v658 = v111;
				//v653 = amount;
				//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[PLAYER_BUFF_BLESS];
		//LABEL_103:
				//HIDWORD(v650) = HIDWORD(v28);
		//LABEL_104:
				//LODWORD(v650) = v28;
				pParty->pPlayers[pCastSpell->uPlayerID_2].pPlayerBuffs[PLAYER_BUFF_BLESS].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335), 1, amount, v111, 0);
				LODWORD(v727) = 1;
				break;
			}
			v105 = 0;
			v717 = (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
			v730b = pParty->pPlayers;//[0].pPlayerBuffs[1];
			do
			{
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, v105);
				v716 = pOtherOverlayList->_4418B1(10000, v105 + 310, 0, 65536);
				v730b->pPlayerBuffs[1].Apply(pParty->uTimePlayed + v717, v731, amount, v716, 0);
				++v730b;
				++v105;
			}
			while ( v730b <= &pParty->pPlayers[3] );
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_SPIRIT_SPIRIT_LASH:
		{
			if ( pPlayer->CanCastSpell(uRequiredMana) && a2 && PID_TYPE(a2) == OBJECT_Actor)
			{
				//v730 = a2 >> 3;
				v112 = &pActors[PID_ID(a2)];
				//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)abs(v112->vPosition.z - pParty->vPosition.z);
				if ( v113 < v721 )
				{
					v116 = v113;
					v113 = v721;
					v114 = v116;
				}
				if ( v113 < (signed int)v115 )
				{
					v117 = v113;
					v113 = (int)v115;
					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 )
				{
					v701.x = 0;
					v701.y = 0;
					v701.z = 0;
					pSpellSprite.stru_24.Reset();
					pSpellSprite.spell_id = pCastSpell->spellnum;
					pSpellSprite.spell_level = v723;
					pSpellSprite.spell_skill = v731;
					pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
					pSpellSprite.uAttributes = 0;
					pSpellSprite.uSectorID = 0;
					pSpellSprite.uSpriteFrameID = 0;
					pSpellSprite.field_60_distance_related_prolly_lod = 0;
					pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
					pSpellSprite.uFacing = 0;
					pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
					pSpellSprite.vPosition.x = v112->vPosition.x;
					pSpellSprite.vPosition.y = v112->vPosition.y;
					pSpellSprite.vPosition.z = v112->vPosition.z - (unsigned int)(signed __int64)((double)(signed int)v112->uActorHeight * unk_4D8548);
					pSpellSprite.spell_target_pid = PID(OBJECT_Actor, a2);
					v122 = pSpellSprite.Create(0, 0, 0, 0);
					DamageMonsterFromParty(PID(OBJECT_Item, v122), PID_ID(a2), &v701);
					LODWORD(v727) = 1;
				}
				else
				{
					ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2u);
					pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
					pCastSpell->spellnum = 0;
				}
				//pCastSpell = (CastSpellInfo *)HIDWORD(v733);
			}
			break;
		}
		case SPELL_AIR_SHIELD:
		case SPELL_EARTH_STONESKIN:
		case SPELL_SPIRIT_HEROISM:
		{
			switch (v731)
			{
				case 1: LODWORD(v733) = 300 * (v2 + 12); break;
				case 2: LODWORD(v733) = 300 * (v2 + 12); break;
				case 3: LODWORD(v733) = 900 * (v2 + 4); break;
				case 4: LODWORD(v733) = 3600 * (v2 + 1); break;
				default:
				assert(false);
			}
			v127 = pCastSpell->spellnum;
			if ( v127 == 17 )
			{
				amount = 0;
				LODWORD(v725) = 14;
			}
			else
			{
				if ( v127 == 38 )
				{
					LODWORD(v725) = 15;
					amount = v2 + 5;
				}
				else
				{
					if ( v127 != 51 )
						continue;
					LODWORD(v725) = 9;
					amount = v2 + 5;
				}
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 0);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 1);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 2);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 3);
			v90 = (double)(signed int)((int)v733 << 7) * 0.033333335;
	//LABEL_304:
			pParty->pPartyBuffs[LODWORD(v725)].Apply(pParty->uTimePlayed + (signed int)(signed __int64)v90, v731, amount, 0, 0);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_FIRE_IMMOLATION:
		{
			if ( v731 == 4 )
				LODWORD(v733) = 600 * v2;
			else
				LODWORD(v733) = 60 * v2;
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;

			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 0);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 1);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 2);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 3);

			pParty->pPartyBuffs[PARTY_BUFF_IMMOLATION].Apply(pParty->uTimePlayed + (signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335), v731, v2, 0, 0);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_FIRE_METEOR_SHOWER:
		{
			//v149 = v731 - 1;
			//if ( v149 && (v150 = v149 - 1) != 0 && (v151 = v150 - 1) != 0 )
			int i;
			if ( v731 == 4 )
			{
				i = 20;
			}
			else
			{
				i = 16;
			}
			if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[491], 2);  // Can't cast Meteor Shower indoors!
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			LODWORD(v725) = PID_TYPE(a2);
			if (PID_TYPE(a2) == OBJECT_Actor)
			{
				uRequiredMana = pActors[PID_ID(a2)].vPosition.x;
				v153 = pActors[PID_ID(a2)].vPosition.y;
				v154 = pActors[PID_ID(a2)].vPosition.z;
				LODWORD(v727) = v153;
			}
			else
			{
				v155 = stru_5C6E00->Cos(pParty->sRotationY);
				uRequiredMana = pParty->vPosition.x + sub_42EBBE(2048, v155);
				v156 = stru_5C6E00->Sin(pParty->sRotationY);
				LODWORD(v727) = pParty->vPosition.y + sub_42EBBE(2048, v156);
				v154 = pParty->vPosition.z;
			}
			unsigned __int64 k = 0;
			int j = 0;
			if ( (signed int)i > 0 )
			{
				v730 = LODWORD(v725) == 3 ? a2 : 0;
				do
				{
					a2 = rand() % 1000;
					if ( sqrt((double)(rand() % 1000) - 2500 * 
								(double)(rand() % 1000) - 2500 + 
								j * j + k * k) <= 1.0 )
					{
						LODWORD(v687) = 0;
						HIDWORD(v687) = 0;
					}
					else
					{
						v687 = __PAIR__(
								stru_5C6E00->Atan2((signed __int64)sqrt((float)(j * j + k * k)), 
													(double)(rand() % 1000) - 2500),
													stru_5C6E00->Atan2(j, k));
					}
					pSpellSprite.stru_24.Reset();
					pSpellSprite.spell_id = pCastSpell->spellnum;
					pSpellSprite.spell_level = v2;
					pSpellSprite.spell_skill = v731;
					pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
					pSpellSprite.uAttributes = 0;
					pSpellSprite.vPosition.x = uRequiredMana;
					pSpellSprite.vPosition.y = LODWORD(v727);
					pSpellSprite.uSectorID = 0;
					pSpellSprite.vPosition.z = a2 + v154;
					pSpellSprite.uSpriteFrameID = 0;
					pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
					pSpellSprite.spell_target_pid = v730;
					pSpellSprite.field_60_distance_related_prolly_lod = stru_50C198._427546(a2 + 2500);
					pSpellSprite.uFacing = v687;
					pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
					if ( pParty->bTurnBasedModeOn == 1 )
						pSpellSprite.uAttributes = 4;
					if ( pSpellSprite.Create(v687, SHIDWORD(v687), pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed, 0) != -1
						&& pParty->bTurnBasedModeOn == 1 )
						++pTurnEngine->field_1C;
					j = rand() % 1024 - 512;
					k = rand() % 1024 - 512;
				}
				while ( i-- != 1 );
			}
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_FIRE_INFERNO:
		{
			//v67 = 2;
			if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[492], 2); // Can't cast Inferno outdoors!
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			auto _v726 = sub_46A6AC((int)dword_50BF30.data(), 100, 4096);
			v700.z = 0;
			v700.y = 0;
			v700.x = 0;
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.uAttributes = 0;
			pSpellSprite.uSectorID = 0;
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.field_60_distance_related_prolly_lod = 0;
			pSpellSprite.uFacing = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			a2 = 0;
			if ( (signed int)_v726 > 0 )
			{
				do
				{
					v162 = dword_50BF30[a2];
					pSpellSprite.vPosition.x = pActors[v162].vPosition.x;
					pSpellSprite.vPosition.y = pActors[v162].vPosition.y;
					pSpellSprite.vPosition.z = pActors[v162].vPosition.z - (unsigned int)(signed __int64)((double)pActors[v162].uActorHeight * unk_4D8548);
					pSpellSprite.spell_target_pid = PID(OBJECT_Actor, dword_50BF30[a2]);
					v164 = pSpellSprite.Create(0, 0, 0, 0);
					v165 = a2;
					DamageMonsterFromParty(PID(OBJECT_Item, v164), dword_50BF30[a2], &v700);
					pGame->GetStru6()->_4A81CA(&pSpellSprite);
					pGame->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0xFF3C1Eu, 0x40u);
					a2 = v165 + 1;
				}
				while ( v165 + 1 < (signed int)_v726 );
			}
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_AIR_WIZARD_EYE:
		{
			LODWORD(v733) = 3600 * v2;
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v168 = 0;
			do
			{
				v169 = pOtherOverlayList->_4418B1(2000, v168++ + 100, 0, 65536);
				v716 = v169;
			}
			while ( v168 < 4 );

			pParty->pPartyBuffs[PARTY_BUFF_WIZARD_EYE].Apply(pParty->uTimePlayed + (signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335), v731, 0, 0, 0);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_AIR_FEATHER_FALL:
		{
			switch (v731)
			{
				case 1: LODWORD(v733) = 300 * v2; break;
				case 2: LODWORD(v733) = 600 * v2; break;
				case 3: LODWORD(v733) = 3600 * v2; break;
				case 4: LODWORD(v733) = 3600 * v2; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v174 = 0;
			do
				pOtherOverlayList->_4418B1(2010, v174++ + 100, 0, 65536);
			while ( v174 < 4 );
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 0);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 1);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 2);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 3);

			pParty->pPartyBuffs[PARTY_BUFF_FEATHER_FALL].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335), v731, 0, 0, 0);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_AIR_SPARKS:
		{
			switch (v731)
			{
				case 1: amount = 3; break;
				case 2: amount = 5; break;
				case 3: amount = 7; break;
				case 4: amount = 9; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			auto _v726 = (signed int)(60 * stru_5C6E00->uIntegerDoublePi) / 360;
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.vPosition.y = pParty->vPosition.y;
			pSpellSprite.vPosition.x = pParty->vPosition.x;
			pSpellSprite.uAttributes = 0;
			pSpellSprite.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
			pSpellSprite.uSectorID = pIndoor->GetSector(
								pParty->vPosition.x,
								pParty->vPosition.y,
								pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3);
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.spell_target_pid = a2;
			pSpellSprite.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			if ( pParty->bTurnBasedModeOn == 1 )
				LOBYTE(pSpellSprite.uAttributes) |= 4u;
			v188 = (signed int)_v726 / -2;
			v189 = (signed int)_v726 / 2;
			while ( v188 <= v189 )
			{
				pSpellSprite.uFacing = v188 + LOWORD(v715.uYawAngle);
				if ( pSpellSprite.Create(
						(signed __int16)(v188 + LOWORD(v715.uYawAngle)),
						v715.uPitchAngle,
						pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed,
						pCastSpell->uPlayerID + 1) != -1
						&& pParty->bTurnBasedModeOn == 1 )
				    ++pTurnEngine->field_1C;
				v188 += _v726 / (amount - 1);
			}
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_AIR_JUMP:
		{
			if ( pParty->uFlags & PARTY_FLAGS_1_FALLING)
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[493], 2);  // Can't cast Jump while airborne!
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				break;
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v191 = 0;
			do
				pOtherOverlayList->_4418B1(2040, v191++ + 100, 0, 65536);
			while ( v191 < 4 );
			BYTE1(pParty->uFlags) |= 1u;
			pParty->uFallSpeed = 1000;
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_AIR_INVISIBILITY:
		{
			switch (v731)
			{
				case 1: LODWORD(v733) = 600 * v2; amount = v2; break;
				case 2: LODWORD(v733) = 600 * v2; amount = 2 * v2; break;
				case 3: LODWORD(v733) = 600 * v2; amount = 3 * v2; break;
				case 4: LODWORD(v733) = 3600 * v2; amount = 4 * v2; break;
				default:
				assert(false);
			}
			if (pParty->uFlags & (PARTY_FLAGS_1_ALERT_RED | PARTY_FLAGS_1_ALERT_YELLOW))
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[638], 2);  // There are hostile creatures nearby!
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			if ( pPlayer->CanCastSpell(uRequiredMana) )
			{
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 0);
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 1);
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 2);
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 3);

				pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335), v731, amount, 0, 0);
				LODWORD(v727) = 1;
			}
			break;
		}
		case SPELL_AIR_FLY:
		{
			if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[494], 2);  // Can not cast Fly indoors!
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				break;
			}
			if ( !pPlayers[pCastSpell->uPlayerID + 1]->GetMaxMana() )
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2);  // Spell failed
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				break;
			}
			LODWORD(v733) = 3600 * v2;
			if ( v731 == 1 || v731 == 2 || v731 == 3 )
				amount = 1;
			else
				amount = 0;
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v205 = 0;
			do
				pOtherOverlayList->_4418B1(2090, v205++ + 100, 0, 65536);
			while ( v205 < 4 );
			v206 = pOtherOverlayList->_4418B1(10008, 203, 0, 65536);
			v207 = pCastSpell->uPlayerID + 1;
			v716 = v206;

			pParty->pPartyBuffs[PARTY_BUFF_FLY].Apply(pParty->uTimePlayed + (signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335), v731, amount, v206, v207);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_AIR_STARBURST:
		{
			//v67 = 2;
			if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[495], 2);  // Can't cast Starburst indoors!
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v208 = PID_TYPE(a2);
			LODWORD(v725) = PID_TYPE(a2);
			if ( v208 == 3 )
			{
				v209 = PID_ID(a2);
				LODWORD(v718) = pActors[v209].vPosition.x;
				v210 = pActors[v209].vPosition.y;
				v211 = pActors[v209].vPosition.z;
				v713 = v210;
			}
			else
			{
				v212 = stru_5C6E00->Cos(pParty->sRotationY);
				LODWORD(v718) = pParty->vPosition.x + sub_42EBBE(2048, v212);
				v213 = stru_5C6E00->Sin(pParty->sRotationY);
				v214 = sub_42EBBE(2048, v213);
				v211 = pParty->vPosition.z;
				v713 = pParty->vPosition.y + v214;
				v208 = LODWORD(v725);
			}
			signed int _v733 = 0;
			*(float *)&v732 = (double)v211;
			LODWORD(v725) = v211 + 2500;
			v721 = 0;
			*(float *)&y = (double)(v211 + 2500);
			v730 = v208 == 3 ? a2 : 0;
			a2 = 20;
			do
			{
				v215 = rand();
				v216 = (double)v721;
				v217 = (double)_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) + v216 * v216 + *(float *)&v721) <= 1.0 )
				{
					LODWORD(v685) = 0;
					HIDWORD(v685) = 0;
				}
				else
				{
					v684 = (signed __int64)sqrt(v216 * v216 + *(float *)&v721);
					v685 = __PAIR__(
								stru_5C6E00->Atan2(v684, (signed __int64)*((float *)&v733 + 1)),
								stru_5C6E00->Atan2((signed __int64)v216, (signed __int64)*(float *)&uRequiredMana));
				}
				pSpellSprite.stru_24.Reset();
				pSpellSprite.spell_id = pCastSpell->spellnum;
				pSpellSprite.spell_level = v2;
				pSpellSprite.spell_skill = v731;
				pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
				pSpellSprite.uAttributes = 0;
				pSpellSprite.vPosition.x = LODWORD(v718);
				pSpellSprite.vPosition.y = v713;
				pSpellSprite.uSectorID = 0;
				pSpellSprite.vPosition.z = (int)((char *)_this + LODWORD(v725));
				pSpellSprite.uSpriteFrameID = 0;
				pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
				pSpellSprite.spell_target_pid = v730;
				//__debugbreak();//çâåçäîïàä
				pSpellSprite.field_60_distance_related_prolly_lod = stru_50C198._427546((int)&_this[69].uNumCharges);
				pSpellSprite.uFacing = v685;
				pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
				if ( pParty->bTurnBasedModeOn == 1 )
				pSpellSprite.uAttributes = 4;
				if ( pSpellSprite.Create(v685, SHIDWORD(v685), pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed, 0) != -1
					   && pParty->bTurnBasedModeOn == 1 )
				  ++pTurnEngine->field_1C;
				v721 = rand() % 1024 - 512;
				v218 = rand();
				v14 = a2-- == 1;
				_v733 = (unsigned __int64)(v218 % 1024) - 512;
			}
			while ( !v14 );
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_WATER_AWAKEN:
		{
			switch (v731)
			{
				case 1: amount = 180 * v2; break;
				case 2: amount = 3600 * v2; break;
				case 3: amount = 86400 * v2; break;
				case 4: amount = 0; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			for( int i=0; i < 4; i++ )
			{
				pPlayer = &pParty->pPlayers[i];
				if ( v731 == 4 )
				{
					if ( pPlayer->pConditions[2] )
					{
						//*((int *)v222 + 4) = 0;
						//*((int *)v222 + 5) = 0;
						pPlayer->pConditions[2] = 0;
						pPlayer->PlaySound(SPEECH_103, 0);
					}
				}
				else
				{
					v223 = pPlayer->DiscardConditionIfLastsLongerThan(
								2u,
								pParty->uTimePlayed - (signed int)(signed __int64)((double)(amount << 7) * 0.033333335));
					if ( v223 )
						pPlayer->PlaySound(SPEECH_103, 0);
				}
			}
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_WATER_POISON_SPRAY:
		{
			switch (v731)
			{
				case 1: amount = 1; break;
				case 2: amount = 3; break;
				case 3: amount = 5; break;
				case 4: amount = 7; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			signed int _v733 = (signed int)(60 * stru_5C6E00->uIntegerDoublePi) / 360;
			if ( amount == 1 )
			{
				pSpellSprite.stru_24.Reset();
				pSpellSprite.spell_id = pCastSpell->spellnum;
				pSpellSprite.spell_skill = v731;
				pSpellSprite.spell_level = v2;
				pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
				pSpellSprite.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:
				pSpellSprite.uAttributes = 0;
				pSpellSprite.vPosition.x = pParty->vPosition.x;
				pSpellSprite.vPosition.z = v51;
				v52 = pIndoor->GetSector(pParty->vPosition.x, v660, v671);
				pSpellSprite.uSpriteFrameID = 0;
				pSpellSprite.uSectorID = v52;
				pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
				pSpellSprite.spell_target_pid = a2;
				pSpellSprite.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
				pSpellSprite.uFacing = LOWORD(v715.uYawAngle);
				pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
				if ( pParty->bTurnBasedModeOn == 1 )
					LOBYTE(pSpellSprite.uAttributes) |= 4u;
				v659 = pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed;
				if ( pSpellSprite.Create(v715.uYawAngle, v715.uPitchAngle, v659, pCastSpell->uPlayerID + 1) != -1 && pParty->bTurnBasedModeOn == 1 )
					++pTurnEngine->field_1C;
			}
			else
			{
				pSpellSprite.stru_24.Reset();
				pSpellSprite.spell_id = pCastSpell->spellnum;
				pSpellSprite.spell_level = v2;
				pSpellSprite.spell_skill = v731;
				pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
				pSpellSprite.vPosition.y = pParty->vPosition.y;
				pSpellSprite.vPosition.x = pParty->vPosition.x;
				pSpellSprite.uAttributes = 0;
				pSpellSprite.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
				pSpellSprite.uSectorID = pIndoor->GetSector(pParty->vPosition.x, pParty->vPosition.y, pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3);
				pSpellSprite.uSpriteFrameID = 0;
				pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
				pSpellSprite.spell_target_pid = a2;
				pSpellSprite.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
				pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
				if ( pParty->bTurnBasedModeOn == 1 )
					LOBYTE(pSpellSprite.uAttributes) |= 4u;
				v227 = _v733 / -2;
				signed int _y = _v733 / 2;
				if ( _v733 / -2 <= _v733 / 2 )
				{
					v228 = v715.uYawAngle;
					do
					{
						pSpellSprite.uFacing = v227 + v228;
						if ( pSpellSprite.Create(
								v227 + v228,
								v715.uPitchAngle,
								pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed,
								pCastSpell->uPlayerID + 1) != -1
								&& pParty->bTurnBasedModeOn == 1 )
							++pTurnEngine->field_1C;
						v227 += _v733 / (amount - 1);
					}
					while ( v227 <= _y );
				}
			}
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_WATER_WATER_WALK:
		{
			if ( !pPlayers[pCastSpell->uPlayerID + 1]->GetMaxMana() )
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2);  // Spell failed
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				break;
			}
			if ( v731 == 2 || v731 != 3 && v731 != 4 )
				v229 = 600 * v2;
			else
				v229 = 3600 * v2;
			LODWORD(v733) = v229;
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v716 = pOtherOverlayList->_4418B1(10005, 201, 0, 65536);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 0);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 1);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 2);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 3);

			pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].Apply(
				pParty->uTimePlayed + (signed int)(signed __int64)((double)(v229 << 7) * 0.033333335),
				v731,
				amount,
				v716,
				pCastSpell->uPlayerID + 1);
			if ( v731 == 4 )
				pParty->pPartyBuffs[PARTY_BUFF_WATER_WALK].uFlags = 1;
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_WATER_RECHARGE_ITEM:
		{
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v240 = &pParty->pPlayers[pCastSpell->uPlayerID_2].pInventoryItems[a2];
			
			if ( pItemsTable->pItems[v240->uItemID].uEquipType != 12 || v240->uAttributes & 2 )
			{
				dword_50C9D0 = 113;
				dword_50C9D4 = 0;
				dword_50C9D8 = 1;

				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2);  // Spell failed
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			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 = (double)v723 * 0.0099999998 + 0.80000001;
			}
			else
			{
				v241 = 0.0;
			}
			if ( v241 > 1.0 )
				v241 = 1.0;
			int uNewCharges = v240->uMaxCharges * v241;
			v240->uMaxCharges = uNewCharges;
			v240->uNumCharges = uNewCharges;
			if ( uNewCharges <= 0 )
			{
				v240 = 0;
				dword_50C9D0 = 113;
				dword_50C9D4 = 0;
				dword_50C9D8 = 1;
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2u);
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				v2 = v723;
				continue;
			}
			v240->uAttributes |= 0x40u;
			_50C9A8_item_enchantment_timer = 256;
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_WATER_ENCHANT_ITEM:
		{
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			uRequiredMana = 0;
			amount = 10 * v2;
			v730 = 1;
			pPlayer = &pParty->pPlayers[pCastSpell->uPlayerID_2];
			v245 = &pPlayer->pInventoryItems[a2];
			ItemDesc *_v725 = &pItemsTable->pItems[v245->uItemID];
			if ( 
				v731 == 1 || v731 == 2 && _v725->uEquipType > 2 ||
				v731 == 3 || v731 == 4 && 
				v245->uItemID <= 134 &&
				v245->uSpecEnchantmentType == 0 &&
				v245->uEnchantmentType == 0 &&
				v245->_bonus_strength== 0 &&
				!v245->Broken() )
			{
				if ( v245->GetValue() < 450 || 
					(v245->GetValue() < 250 && (v731 == 3 || v731 == 4) && _v725->uEquipType >= 0 && _v725->uEquipType <= 2)
					)
				{
					v730 = 0;
				}
				if ( rand() % 100 < 10 * v2 || 
					(rand() % 100 < 80 && (v731 == 3 || v731 == 4 )) ||
					v245->GetValue() < 450 || 
					(v245->GetValue() < 250 && (v731 == 3 || v731 == 4) && v271 >= 0 && v271 <= 2)
					)
				{
					v313 = _v725->uEquipType;
					if ( _v725->uEquipType >= 3 && _v725->uEquipType <= 11 )
					{
						v295 = rand() % 10;// pItemsTable->field_116D8[pItemsTable->pItems[_this->uItemID].uEquipType];
						v245->uEnchantmentType = 0;
						for ( kk = pItemsTable->pEnchantments[0].to_item[pItemsTable->pItems[v245->uItemID].uEquipType + 1];
							;
							kk += pItemsTable->pEnchantments[v294->uEnchantmentType].to_item[pItemsTable->pItems[v245->uItemID].uEquipType + 1] )
						{
							++v245->uEnchantmentType;
							if ( kk >= v295 )
								break;
						}
						v255 = 10;//pItemsTable->field_116D8[17];
						v256 = 10;//pItemsTable->field_116D8[16];
						v245->_bonus_strength = v256 + rand() % (v255 - v256 + 1);
						v245->uAttributes |= 0x20u;
						_50C9A8_item_enchantment_timer = 256;
						LODWORD(v727) = 1;
						break;
					}
					else if ( v731 == 3 || v731 == 4)
					{
					v257 = pItemsTable->pSpecialEnchantments_count;
					v258 = 0;
					v725 = 0.0;
					int _v733 = 0;
					if ( pItemsTable->pSpecialEnchantments_count > 0 )
					{
						v730 = (int)&v679;
						do
						{
							v259 = LOBYTE(pItemsTable->pSpecialEnchantments[v258 + 1].pBonusStatement);
							if ( !v259 || v259 == 1 )
							{
								v260 = *(&pItemsTable->pSpecialEnchantments[0].to_item_apply[pItemsTable->pItems[*(int *)v245].uEquipType
																					+ 4]
										+ v258 * 28);
								LODWORD(v725) += v260;
								if ( v260 )
								{
									v261 = v730;
									v730 += 4;
									*(int *)v261 = _v733;
								}
							}
							++_v733;
							++v258;
						}
						while ( _v733 < v257 );
					}
					v262 = rand() % SLODWORD(v725);
					v263 = v679;
					v245->uSpecEnchantmentType = v679[0];
					v264 = pItemsTable->pSpecialEnchantments[*v263].to_item_apply[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].to_item_apply[pItemsTable->pItems[*(int *)v245].uEquipType
																				+ 4];
							if ( v264 >= v265 )
								break;
						}
					}

						v277 = pItemsTable->pSpecialEnchantments_count;
						v278 = 0;
						v725 = 0.0;
						_v733 = 0;
						if ( pItemsTable->pSpecialEnchantments_count > 0 )
						{
							int *_v730 = v679;
							do
							{
								v279 = LOBYTE(pItemsTable->pSpecialEnchantments[v278].pBonusStatement);
								if ( !v279 || v279 == 1 )
								{
									v280 = *(&pItemsTable->pSpecialEnchantments[v278].to_item_apply[pItemsTable->pItems[v245->uItemID].uEquipType]);
									_v733 += v280;
									if ( v280 )
									{
										v281 = _v730;
										++_v730;
										*v281 = _v733;
									}
								}
								++_v733;
								++v278;
							}
							while ( _v733 < v277 );
						}
						v282 = rand() % _v733;
						v283 = v679;
						v245->uSpecEnchantmentType = v679[0];
						v284 = pItemsTable->pSpecialEnchantments[*v283].to_item_apply[pItemsTable->pItems[v245->uItemID].uEquipType ];
						v285 = v282 + 1;
						for ( l = v679; v284 < v285; ++l )
						{
							v245->uSpecEnchantmentType = *(l+1);
							v284 += pItemsTable->pSpecialEnchantments[*(l+1)].to_item_apply[pItemsTable->pItems[v245->uItemID].uEquipType];
						}
						++v245->uSpecEnchantmentType;
						v245->uAttributes |= 0x20u;
						_50C9A8_item_enchantment_timer = 256;
						LODWORD(v727) = 1;
						break;
					}
				}
				else
				{
					if ( !(BYTE1(v245->uAttributes) & 2) )
					{
						v245->uAttributes |= 2;
					}
				}
						
			}

			if ( LODWORD(v727) == 0 )
			{
				v317 = pGlobalTXT_LocalizationStrings[428];
				if ( v730 == 0 )
					v317 = pGlobalTXT_LocalizationStrings[585];
				ShowStatusBarString(v317, 2u);
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				v318 =  &pParty->pPlayers[pCastSpell->uPlayerID_2];
				pCastSpell->spellnum = 0;
				v318->PlaySound(SPEECH_43, 0);
			}

			break;
		}
		case SPELL_WATER_TOWN_PORTAL:
		{
			amount = 10 * v2;
			if ( pPlayer->sMana < (signed int)uRequiredMana )
				break;
			if ( pParty->uFlags & (PARTY_FLAGS_1_ALERT_RED | PARTY_FLAGS_1_ALERT_YELLOW) && v731 != 4 || rand() % 100 >= amount && v731 != 4 )
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2); // Spell failed
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			town_portal_caster_id = LOBYTE(pCastSpell->uPlayerID);
			pMessageQueue_50CBD0->AddMessage(UIMSG_OnCastTownPortal, 0, 0);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_WATER_LLOYDS_BEACON:
		{
			LODWORD(v733) = 604800 * v2;
			if ( !_stricmp(pCurrentMapName.data(), "d05.blv") )
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2); // Spell failed
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			v319 = uRequiredMana;
			if ( pPlayer->sMana >= (signed int)uRequiredMana )
			{
				pEventTimer->Pause();
				pMessageQueue_50CBD0->AddMessage(UIMSG_OnCastLloydsBeacon, 0, 0);
				qword_506350 = (signed int)v733;
				_506348_current_lloyd_playerid = pCastSpell->uPlayerID;
				::uRequiredMana = v319;
				::sRecoveryTime = sRecoveryTime;
				dword_50633C = pCastSpell->sound_id;
				dword_506338 = pCastSpell->spellnum;
				LOBYTE(pCastSpell->field_8) |= 0x20u;
			}
			break;
		}
		case SPELL_EARTH_STONE_TO_FLESH:
		{
			__debugbreak(); // missing GM ?
			switch (v731)
			{
				case 1: amount = 3600 * v2; break;
				case 2: amount = 3600 * v2; break;
				case 3: amount = 86400 * v2; break;
				case 4: break;
				default:
				assert(false);
			}
	//LABEL_634:
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v323 = pCastSpell->uPlayerID_2;
			v324 = (char *)&pParty->pPlayers[v323].pConditions[15];
			if ( !pParty->pPlayers[v323].pConditions[15] )
			{
				LODWORD(v727) = 1;
				break;
			}
			if ( v731 == 4 )
			{
				*(int *)v324 = 0;
				*((int *)v324 + 1) = 0;
				LODWORD(v727) = 1;
				break;
			}
			v732 = amount << 7;
			v663 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed - (double)(amount << 7) * 0.033333335);
			v656 = 15;
			v325 = &pParty->pPlayers[v323];
			v325->DiscardConditionIfLastsLongerThan(v656, v663);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_EARTH_ROCK_BLAST:
		{
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.vPosition.y = pParty->vPosition.y;
			pSpellSprite.vPosition.x = pParty->vPosition.x;
			pSpellSprite.uAttributes = 0;
			pSpellSprite.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
			pSpellSprite.uSectorID = pIndoor->GetSector(
								pParty->vPosition.x,
								pParty->vPosition.y,
								pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3);
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.spell_target_pid = a2;
			pSpellSprite.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
			pSpellSprite.uFacing = LOWORD(pParty->sRotationY);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			if ( pParty->bTurnBasedModeOn == 1 )
				LOBYTE(pSpellSprite.uAttributes) |= 4u;

			v659 = pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed;
			if ( pSpellSprite.Create(pParty->sRotationY, pParty->sRotationX, v659, pCastSpell->uPlayerID + 1) != -1 && pParty->bTurnBasedModeOn == 1 )
				++pTurnEngine->field_1C;
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_EARTH_DEATH_BLOSSOM:
		{
			if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2); // Spell failed
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			pSpellSprite.uType = 4090;
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.vPosition.x = pParty->vPosition.x;
			pSpellSprite.vPosition.y = pParty->vPosition.y;
			pSpellSprite.uAttributes = 0;
			pSpellSprite.uSectorID = 0;
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 3;
			pSpellSprite.field_60_distance_related_prolly_lod = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.spell_target_pid = a2;
			pSpellSprite.uFacing = LOWORD(pParty->sRotationY);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			if ( pParty->bTurnBasedModeOn == 1 )
				pSpellSprite.uAttributes = 4;

			v659 = pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed;
			if ( pSpellSprite.Create(pParty->sRotationY, stru_5C6E00->uIntegerHalfPi / 2, v659, 0) != -1 && pParty->bTurnBasedModeOn == 1 )
				++pTurnEngine->field_1C;
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_SPIRIT_DETECT_LIFE:
		{
			v328 = v731 - 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) )
				break;
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 0);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 1);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 2);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 3);

			pParty->pPartyBuffs[PARTY_BUFF_DETECT_LIFE].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335), v731, 0, 0, 0);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_SPIRIT_FATE:
		{
			switch (v731)
			{
				case 1: amount = 1 * v2; break;
				case 2: amount = 2 * v2; break;
				case 3: amount = 4 * v2; break;
				case 4: amount = 6 * v2; break;
				default:
				assert(false);
			}
			LODWORD(v733) = 300;
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v342 = pCastSpell->spell_target_pid;
			if ( v342 == 0 )
			{
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, pCastSpell->uPlayerID_2);

				pParty->pPlayers[pCastSpell->uPlayerID_2].pPlayerBuffs[PLAYER_BUFF_FATE].Apply(pParty->uTimePlayed + 1280, v731, amount, 0, 0);
				LODWORD(v727) = 1;
				break;
			}
			if (PID_TYPE(v342) == OBJECT_Actor)
			{
				v343 = PID_ID(v342);
				HIDWORD(v344) = 0 + ((pParty->uTimePlayed + 1280) >> 32);
				LODWORD(v344) = LODWORD(pParty->uTimePlayed) + 1280;
				pActors[v343].pActorBuffs[11].Apply(v344, v731, amount, 0, 0);
				BYTE2(pActors[v343].uAttributes) |= 8u;
				//v672 = 0;
				v661 = &pActors[v343];
				pGame->GetStru6()->_4A7E89_sparkles_on_actor_after_it_casts_buff(v661, 0);
			}
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_SPIRIT_REMOVE_CURSE:
		{
			switch (v731)
			{
				case 1: amount = 3600 * v2; break;
				case 2: amount = 3600 * v2; break;
				case 3: amount = 86400 * v2; break;
				case 4: amount = 0; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v351 = &pParty->pPlayers[pCastSpell->uPlayerID_2];
			if ( !v351->pConditions[0] )
			{
				LODWORD(v727) = 1;
				break;
			}
			if ( v731 == 4 )
			{
				LODWORD(v351->pConditions[0]) = 0;
				HIDWORD(v351->pConditions[0]) = 0;
			}
			else
			{
				v732 = amount << 7;
				v351->DiscardConditionIfLastsLongerThan(0, (signed __int64)((double)(signed __int64)pParty->uTimePlayed - (double)(amount << 7) * 0.033333335));
				if ( HIDWORD(pParty->pPlayers[pCastSpell->uPlayerID_2].pConditions[0]) | LODWORD(pParty->pPlayers[pCastSpell->uPlayerID_2].pConditions[0]) )
				{
					LODWORD(v727) = 1;
					break;
				}
			}
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, pCastSpell->uPlayerID_2);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_SPIRIT_PRESERVATION:
		{
			if ( v731 == 4 )
				LODWORD(v733) = 900 * (v2 + 4);
			else
				LODWORD(v733) = 300 * (v2 + 12);
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			if ( v731 == 1 || v731 == 2 )
			{
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, pCastSpell->uPlayerID_2);
				pParty->pPlayers[pCastSpell->uPlayerID_2].pPlayerBuffs[PLAYER_BUFF_PRESERVATION].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335), v731, 0, 0, 0);
				LODWORD(v727) = 1;
				break;
			}
			a2 = 0;
			v717 = (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
			v357 = pParty->pPlayers;//[0].pPlayerBuffs[11];
			do
			{
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, a2);
				v357->pPlayerBuffs[PLAYER_BUFF_PRESERVATION].Apply(pParty->uTimePlayed + v717, v731, 0, 0, 0);
				++a2;
				++v357;// = (SpellBuff *)((char *)v357 + 6972);
			}
			while ( v357 <= &pParty->pPlayers[3] );
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_SPIRIT_TURN_UNDEAD:
		{
			if ( v731 == 1 || v731 == 2)
				LODWORD(v733) = 60 * (v2 + 3);
			else
				LODWORD(v733) = 300 * v2 + 180;
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			auto _v726 = sub_46A6AC((int)dword_50BF30.data(), 100, 4096);
			pGame->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0xFFFFFFu, 0xC0u);
			++pSpellSprite.uType;
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.uAttributes = 0;
			pSpellSprite.uSectorID = 0;
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.field_60_distance_related_prolly_lod = 0;
			pSpellSprite.uFacing = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			for ( a2 = 0; a2 < (signed int)_v726; ++a2 )
			{
				v369 = &pActors[dword_50BF30[a2]];
				if ( MonsterStats::BelongsToSupertype(v369->pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD) )
				{
					pSpellSprite.vPosition.x = v369->vPosition.x;
					pSpellSprite.vPosition.y = v369->vPosition.y;
					pSpellSprite.vPosition.z = v369->vPosition.z - (unsigned int)(signed __int64)((double)v369->uActorHeight * unk_4D8548);

					pSpellSprite.spell_target_pid = PID(OBJECT_Actor, dword_50BF30[a2]);
					pSpellSprite.Create(0, 0, 0, 0);
					v369->pActorBuffs[4].Apply(
						pParty->uTimePlayed + (signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335),
						v731, 0, 0, 0);
				}
			}
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_SPIRIT_RAISE_DEAD:
		{
			if ( v731 == 4 )
				amount = 0;
			else
				amount = 86400 * v2;
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			pOtherOverlayList->_4418B1(5080, pCastSpell->uPlayerID_2 + 100, 0, 65536);
			v373 = pCastSpell->uPlayerID_2;
			if ( !(HIDWORD(pParty->pPlayers[v373].pConditions[14]) | LODWORD(pParty->pPlayers[v373].pConditions[14])) )
			{
				LODWORD(v727) = 1;
				break;
			}
			v14 = v731 == 4;
			pParty->pPlayers[v373].sHealth = 1;
			if ( v14 )
			{
				v374 = pCastSpell->uPlayerID_2;
				LODWORD(pParty->pPlayers[v374].pConditions[14]) = 0;
				HIDWORD(pParty->pPlayers[v374].pConditions[14]) = 0;
				v376 = pCastSpell->uPlayerID_2;
				LODWORD(pParty->pPlayers[v376].pConditions[13]) = 0;
				HIDWORD(pParty->pPlayers[v376].pConditions[13]) = 0;
			}
			else
			{
				*(float *)&a2 = (double)(amount << 7) * 0.033333335;
				pParty->pPlayers[pCastSpell->uPlayerID_2].DiscardConditionIfLastsLongerThan(
				0xEu,
				(signed __int64)((double)(signed __int64)pParty->uTimePlayed - *(float *)&a2));
				pParty->pPlayers[pCastSpell->uPlayerID_2].DiscardConditionIfLastsLongerThan(
				0xDu,
				(signed __int64)((double)(signed __int64)pParty->uTimePlayed - *(float *)&a2));
			}
			v377 = &pParty->pPlayers[pCastSpell->uPlayerID_2];
			v377->SetCondition(1, 0);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_SPIRIT_SHARED_LIFE:
		{
			if ( v731 == 4 )
				amount = 4 * v2;
			else
				amount = 3 * v2;
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v381 = 0;
			signed int _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 > 0 )
			{
				do
					_v733 += pPlayers[v682[v384++]]->sHealth;
				while ( v384 < v381 );
			}
			v732 = (signed __int64)((double)_v733 / (double)v730);
			_v733 = 0;
			if ( v381 > 0 )
			{
				do
				{
					//v385 = (ItemGen **)&pPlayers[v682[HIDWORD(v733)]];
					v726 = pPlayers[v682[_v733]];
					v726->sHealth = v732;
					//v386 = v726->GetMaxHealth();
					if ( v726->sHealth > v726->GetMaxHealth())
						v726->sHealth = v726->GetMaxHealth();
					if ( v726->sHealth > 0 )
					{
						v726->pConditions[Player::Condition_Unconcious] = 0;
					}
					v388 = _v733;

					pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, LOWORD(v682[_v733]) - 1);
					_v733 = v388 + 1;
				}
				while ( v388 + 1 < v730 );
			}
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_SPIRIT_RESSURECTION:
		{
			switch (v731)
			{
				case 1: amount = 180 * v2; break;
				case 2: amount = 10800 * v2; break;
				case 3: amount = 259200 * v2; break;
				case 4: amount = 0; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v396 = pCastSpell->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(SPEECH_25, 0);
				if ( v731 == 4 )
				{
					v397 = pCastSpell->uPlayerID_2;
					LODWORD(pParty->pPlayers[v397].pConditions[16]) = 0;
					HIDWORD(pParty->pPlayers[v397].pConditions[16]) = 0;
					v398 = pCastSpell->uPlayerID_2;
					LODWORD(pParty->pPlayers[v398].pConditions[14]) = 0;
					HIDWORD(pParty->pPlayers[v398].pConditions[14]) = 0;
					v399 = pCastSpell->uPlayerID_2;
					LODWORD(pParty->pPlayers[v399].pConditions[13]) = 0;
					HIDWORD(pParty->pPlayers[v399].pConditions[13]) = 0;
				}
				else
				{
					*(float *)&a2 = (double)(amount << 7) * 0.033333335;
					pParty->pPlayers[pCastSpell->uPlayerID_2].DiscardConditionIfLastsLongerThan( 0x10u,
						(signed __int64)((double)(signed __int64)pParty->uTimePlayed - *(float *)&a2));
					pParty->pPlayers[pCastSpell->uPlayerID_2].DiscardConditionIfLastsLongerThan( 0xEu,
						(signed __int64)((double)(signed __int64)pParty->uTimePlayed - *(float *)&a2));
					pParty->pPlayers[pCastSpell->uPlayerID_2].DiscardConditionIfLastsLongerThan( 0xDu,
						(signed __int64)((double)(signed __int64)pParty->uTimePlayed - *(float *)&a2));
				}
				pParty->pPlayers[pCastSpell->uPlayerID_2].SetCondition(1u, 1);
				pParty->pPlayers[pCastSpell->uPlayerID_2].sHealth = 1;
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, pCastSpell->uPlayerID_2);
			}
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_MIND_CURE_PARALYSIS:
		{
			switch (v731)
			{
				case 1: amount = 3600 * v2; break;
				case 2: amount = 3600 * v2; break;
				case 3: amount = 86400 * v2; break;
				case 4: amount = 0; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;

			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, pCastSpell->uPlayerID_2);
			v323 = pCastSpell->uPlayerID_2;
			v324 = (char *)&pParty->pPlayers[v323].pConditions[12];
			if ( !pParty->pPlayers[v323].pConditions[12] )
			{
				LODWORD(v727) = 1;
				break;
			}
			if ( v731 == 4 )
			{
				*(int *)v324 = 0;
				*((int *)v324 + 1) = 0;
				LODWORD(v727) = 1;
				break;
			}
			v663 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed - (double)(amount << 7) * 0.033333335);
			v656 = 12;
			v325 = &pParty->pPlayers[v323];
			v325->DiscardConditionIfLastsLongerThan(v656, v663);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_MIND_REMOVE_FEAR:
		{
			switch (v731)
			{
				case 1: amount = 180 * v2; break;
				case 2: amount = 3600 * v2; break;
				case 3: amount = 86400 * v2; break;
				case 4: amount = 0; break;
				default:
				assert(false);
			}

			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;

			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, pCastSpell->uPlayerID_2);
			v323 = pCastSpell->uPlayerID_2;
			v324 = (char *)&pParty->pPlayers[v323].pConditions[3];
			if ( !pParty->pPlayers[v323].pConditions[3] )
			{
				LODWORD(v727) = 1;
				break;
			}
			if ( v731 == 4 )
			{
				*(int *)v324 = 0;
				*((int *)v324 + 1) = 0;
				LODWORD(v727) = 1;
				break;
			}
			v663 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed - (double)(amount << 7) * 0.033333335);
			v656 = 3;
			v325 = &pParty->pPlayers[v323];
			v325->DiscardConditionIfLastsLongerThan(v656, v663);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_MIND_TELEPATHY:
		{
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			if (PID_TYPE(a2) != OBJECT_Actor)
			{
				LODWORD(v727) = 1;
				break;
			}
			v417 = &pActors[PID_ID(a2)];
			Actor * _v730 = v417;
			if ( !(BYTE2(v417->uAttributes) & 0x80) )
			{
				v417->SetRandomGoldIfTheresNoItem();
				v417 = _v730;
			}
			v418 = v417->array_000234[3].uItemID;
			signed int _v733 = 0;
			if ( pItemsTable->pItems[v418].uEquipType == 18 )
				_v733 = v417->array_000234[3].uSpecEnchantmentType;

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

			v419 = _v730->uCarriedItemID;
			if (v419)
			{
				v683.uItemID = v419;
				//goto LABEL_799;
			}
			else
			{
				v420 = 0;
				v421 = _v730->array_000234;
				while ( !v421->uItemID || pItemsTable->pItems[v421->uItemID].uEquipType == 18 )
				{
					++v420;
					++v421;
					if ( v420 >= 4 )
						break;
				}
				if ( v420 < 4 )
				{
					memcpy(&v683, &_v730->array_000234[v420], sizeof(v683));
					v2 = v723;
					//v1 = 0;
				}
			}
//	LABEL_799:
			if ( _v733 != 0 )
			{
				v675 = _v733;
				if (v683.uItemID)
				{
					v422 = v683.GetDisplayName();
					sprintf(pTmpBuf2.data(), "(%s), and %d gold", v422, v675);

				}
				else
				{
					v664 = "%d gold";
					sprintf(pTmpBuf2.data(), v664, v675);
				}
			}
			else
			{
				if (v683.uItemID)
				{
					const char *_v675 = v683.GetDisplayName();
					v664 = "(%s)";
					sprintf(pTmpBuf2.data(), v664, _v675);
				}
				else
				{
					strcpy(pTmpBuf2.data(), "nothing");
					ShowStatusBarString(pTmpBuf2.data(), 2u);
				}
			}
			ShowStatusBarString(pTmpBuf2.data(), 2u);
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.vPosition.x = _v730->vPosition.x;
			pSpellSprite.vPosition.y = _v730->vPosition.y;
			v676 = _v730->uActorHeight;
			v665 = pSpellSprite.vPosition.y;
			pSpellSprite.vPosition.z = _v730->uActorHeight;
			v657 = pSpellSprite.vPosition.x;
			pSpellSprite.uAttributes = 0;
			pSpellSprite.uSectorID = pIndoor->GetSector(v657, v665, v676);
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.spell_target_pid = a2;
			pSpellSprite.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
			pSpellSprite.uFacing = LOWORD(v715.uYawAngle);
			LOBYTE(pSpellSprite.uAttributes) |= 0x80u;
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			pSpellSprite.Create(0, 0, 0, pCastSpell->uPlayerID + 1);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_MIND_BERSERK:
		{
			switch (v731)
			{
				case 1: amount = 300 * v2; break;
				case 2: amount = 300 * v2; break;
				case 3: amount = 600 * v2; break;
				case 4: amount = 3600; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v426 = PID_ID(a2);
			if (PID_TYPE(a2) != OBJECT_Actor)
			{
				LODWORD(v727) = 1;
				break;
			}
			v730 = 836 * v426;
			if ( stru_50C198.GetMagicalResistance(&pActors[v426], 7u) )
			{
				pActors[v426].pActorBuffs[1].Reset();
				pActors[v426].pActorBuffs[12].Reset();
				pActors[v426].pActorBuffs[9].Apply(
				pParty->uTimePlayed + (signed __int64)((double)(amount << 7) * 0.033333335),
				v731, 0, 0, 0);
				pActors[v426].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
			}
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			v60 = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			v61 = v426;
			v600 = pActors[v61].vPosition.y;
			v601 = pActors[v61].vPosition.x;
			pSpellSprite.uObjectDescID = v60;
			pSpellSprite.vPosition.x = v601;
			v602 = pActors[v61].uActorHeight;
			v603 = pActors[v61].vPosition.z;
			pSpellSprite.vPosition.y = v600;
			v676 = v603 + v602;
			v665 = v600;
			pSpellSprite.vPosition.z = v603 + v602;
			v657 = v601;
			pSpellSprite.uAttributes = 0;
			pSpellSprite.uSectorID = pIndoor->GetSector(v657, v665, v676);
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.spell_target_pid = a2;
			pSpellSprite.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
			pSpellSprite.uFacing = LOWORD(v715.uYawAngle);
			LOBYTE(pSpellSprite.uAttributes) |= 0x80u;
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			pSpellSprite.Create(0, 0, 0, pCastSpell->uPlayerID + 1);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_MIND_ENSLAVE:
		{
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			amount = 600 * v2;
			if (PID_TYPE(a2) != OBJECT_Actor)
			{
				LODWORD(v727) = 1;
				break;
			}
			v730 = 836 * PID_ID(a2);
			if ( MonsterStats::BelongsToSupertype(pActors[PID_ID(a2)].pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD) )
				break;
			if ( stru_50C198.GetMagicalResistance(&pActors[PID_ID(a2)], 7u) )
			{
				pActors[PID_ID(a2)].pActorBuffs[9].Reset();
				pActors[PID_ID(a2)].pActorBuffs[1].Reset();
				pActors[PID_ID(a2)].pActorBuffs[12].Apply(pParty->uTimePlayed + (signed __int64)((double)(amount << 7) * 0.033333335),
				v731, 0, 0, 0);
			}
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			v60 = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			v61 = PID_ID(a2);
			v600 = pActors[v61].vPosition.y;
			v601 = pActors[v61].vPosition.x;
			pSpellSprite.uObjectDescID = v60;
			pSpellSprite.vPosition.x = v601;
			v602 = pActors[v61].uActorHeight;
			v603 = pActors[v61].vPosition.z;
			pSpellSprite.vPosition.y = v600;
			v676 = v603 + v602;
			v665 = v600;
			pSpellSprite.vPosition.z = v603 + v602;
			v657 = v601;
			pSpellSprite.uAttributes = 0;
			pSpellSprite.uSectorID = pIndoor->GetSector(v657, v665, v676);
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.spell_target_pid = a2;
			pSpellSprite.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
			pSpellSprite.uFacing = LOWORD(v715.uYawAngle);
			LOBYTE(pSpellSprite.uAttributes) |= 0x80u;
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			pSpellSprite.Create(0, 0, 0, pCastSpell->uPlayerID + 1);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_MIND_MASS_FEAR:
		{
			if ( v731 == 4 )
				amount = 300 * v2;
			else
				amount = 180 * v2;
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			auto _v726 = sub_46A6AC((int)dword_50BF30.data(), 100, 4096);
			pGame->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0xA0A0Au, 0xC0u);
			++pSpellSprite.uType;
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.uAttributes = 0;
			pSpellSprite.uSectorID = 0;
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.field_60_distance_related_prolly_lod = 0;
			pSpellSprite.uFacing = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			for ( a2 = 0; a2 < (signed int)_v726; ++a2 )
			{
				v433 = &pActors[dword_50BF30[a2]];
				if ( MonsterStats::BelongsToSupertype(v433->pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD) )
					break;
				pSpellSprite.vPosition.x = v433->vPosition.x;
				pSpellSprite.vPosition.y = v433->vPosition.y;
				pSpellSprite.vPosition.z = v433->vPosition.z - (unsigned int)(signed __int64)((double)v433->uActorHeight * unk_4D8548);

				pSpellSprite.spell_target_pid = PID(OBJECT_Actor, dword_50BF30[a2]);
				pSpellSprite.Create(0, 0, 0, 0);
				if ( stru_50C198.GetMagicalResistance(v433, 7u) )
				{
					v433->pActorBuffs[4].Apply(pParty->uTimePlayed + (signed __int64)((double)(amount << 7) * 0.033333335),
						v731, 0, 0, 0);
				}
			}
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_MIND_CURE_INSANITY:
		{
			v435 = v731 - 2;
			if ( v731 == 4 )
				amount = 0;
			else
				amount = 86400 * v2;
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;

			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, pCastSpell->uPlayerID_2);
			v440 = pCastSpell->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(SPEECH_25, 0);
				if ( v731 == 4 )
				{
					v441 = pCastSpell->uPlayerID_2;
					LODWORD(pParty->pPlayers[v441].pConditions[5]) = 0;
					HIDWORD(pParty->pPlayers[v441].pConditions[5]) = 0;
				}
				else
				{
					pParty->pPlayers[pCastSpell->uPlayerID_2].DiscardConditionIfLastsLongerThan(5u,
						(signed __int64)((double)(signed __int64)pParty->uTimePlayed - (double)(amount << 7) * 0.033333335));
				}
				v377 = &pParty->pPlayers[pCastSpell->uPlayerID_2];
				v377->SetCondition(1, 0);
			}
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_EARTH_TELEKINESIS:
		{
			switch (v731)
			{
				case 1: amount = 2 * v2; break;
				case 2: amount = 2 * v2; break;
				case 3: amount = 3 * v2; break;
				case 4: amount = 4 * v2; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v445 = PID_ID(a2);
			if (PID_TYPE(a2) == OBJECT_Item)
			{
				v449 = (char *)&pSpriteObjects[v445].stru_24;
				v450 = *(int *)v449;
				if ( pItemsTable->pItems[v450].uEquipType == 18 )
				{
					party_finds_gold(*((int *)v449 + 3), 0);
					viewparams->bRedrawGameUI = 1;
				}
				else
				{
					sprintfex(pTmpBuf2.data(), pGlobalTXT_LocalizationStrings[471], pItemsTable->pItems[v450].pUnidentifiedName);
					ShowStatusBarString(pTmpBuf2.data(), 2u);
					if ( !pParty->AddItem(&pSpriteObjects[v445].stru_24) )
						pParty->SetHoldingItem(&pSpriteObjects[v445].stru_24);
				}
				SpriteObject::OnInteraction(v445);
			}
			else
			{
				if (PID_TYPE(a2) == OBJECT_Actor)
				{
					stru_50C198.LootActor(&pActors[v445]);
				}
				else
				{
					if (PID_TYPE(a2) != OBJECT_Decoration)
					{
						if (PID_TYPE(a2) != OBJECT_BModel)
						{
							LODWORD(v727) = 1;
							break;
						}
						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;
						EventProcessor(v446, a2, v677);
						LODWORD(v727) = 1;
						break;
					}
					v447 = &pLevelDecorations[v445];
					dword_507CD8 = 1;
					v448 = v447->field_16_event_id;
					if (v448)
					{
						v677 = 1;
						v446 = v448;
						EventProcessor(v446, a2, v677);
						LODWORD(v727) = 1;
						break;
					}
					if ( v447->IsInteractive() )
					{
						activeLevelDecoration = v447;
						EventProcessor(stru_5E4C90._decor_events[v447->_idx_in_stru123 - 75] + 380, 0, 1);
						activeLevelDecoration = NULL;
					}
				}
			}
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_BODY_CURE_WEAKNESS:
		{
			switch (v731)
			{
				case 1: amount = 180 * v2; break;
				case 2: amount = 3600 * v2; break;
				case 3: amount = 86400 * v2; break;
				case 4: amount = 0; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;

			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, pCastSpell->uPlayerID_2);
			v323 = pCastSpell->uPlayerID_2;
			v324 = (char *)&pParty->pPlayers[v323].pConditions[1];
			if ( !pParty->pPlayers[v323].pConditions[1] )
			{
				LODWORD(v727) = 1;
				break;
			}
			if ( v731 == 4 )
			{
				*(int *)v324 = 0;
				*((int *)v324 + 1) = 0;
				LODWORD(v727) = 1;
				break;
			}
			v663 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed - (double)(amount << 7) * 0.033333335);
			v656 = 1;
			v325 = &pParty->pPlayers[v323];
			v325->DiscardConditionIfLastsLongerThan(v656, v663);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_BODY_FIRST_AID:
		{
			switch (v731)
			{
				case 1: amount = 2 * v2 + 5; break;
				case 2: amount = 3 * v2 + 5; break;
				case 3: amount = 4 * v2 + 5; break;
				case 4: amount = 5 * v2 + 5; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v460 = pCastSpell->spell_target_pid;
			if (!v460)
			{
				pParty->pPlayers[pCastSpell->uPlayerID_2].Heal(amount);
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, pCastSpell->uPlayerID_2);
			}
			else
			{
				if (PID_TYPE(v460) == OBJECT_Actor)
				{
					v461 = &pActors[PID_ID(v460)];
					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;
								}
							}
						}
					}
				}
			}
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_BODY_CURE_POISON:
		{
			switch (v731)
			{
				case 1: amount = 3600 * v2; break;
				case 2: amount = 3600 * v2; break;
				case 3: amount = 86400 * v2; break;
				case 4: amount = 0; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;

			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, pCastSpell->uPlayerID_2);
			v470 = pCastSpell->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])) )
			{
				LODWORD(v727) = 1;
				break;
			}
			if ( v731 == 4 )
			{
				LODWORD(pParty->pPlayers[v470].pConditions[6]) = 0;
				HIDWORD(pParty->pPlayers[v470].pConditions[6]) = 0;
				v471 = pCastSpell->uPlayerID_2;
				LODWORD(pParty->pPlayers[v471].pConditions[8]) = 0;
				HIDWORD(pParty->pPlayers[v471].pConditions[8]) = 0;
				v472 = pCastSpell->uPlayerID_2;
				LODWORD(pParty->pPlayers[v472].pConditions[10]) = 0;
				HIDWORD(pParty->pPlayers[v472].pConditions[10]) = 0;
				LODWORD(v727) = 1;
				break;
			}
			*(float *)&a2 = (double)(amount << 7) * 0.033333335;
			pParty->pPlayers[v470].DiscardConditionIfLastsLongerThan(
				6u,
				(signed __int64)((double)(signed __int64)pParty->uTimePlayed - *(float *)&a2));
			pParty->pPlayers[pCastSpell->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;
			v325 = &pParty->pPlayers[pCastSpell->uPlayerID_2];
			v325->DiscardConditionIfLastsLongerThan(v656, v663);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_BODY_PROTECTION_FROM_MAGIC:
		{
			amount = v2;
			LODWORD(v733) = 3600 * v2;
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;

			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 0);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 1);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 2);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 3);

			pParty->pPartyBuffs[PARTY_BUFF_PROTECTION_FROM_MAGIC].Apply(pParty->uTimePlayed + (signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335), v731, v2, 0, 0);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_BODY_HAMMERHANDS:
		{
			LODWORD(v733) = 3600 * v2;
			amount = v2;
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			if ( v731 == 4 )
			{
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 0);
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 1);
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 2);
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 3);
				v732 = (int)v733 << 7;
				v717 = (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
				pParty->pPlayers[0].pPlayerBuffs[PLAYER_BUFF_HAMMERHANDS].Apply(pParty->uTimePlayed + v717, 4u, v2, v2, 0);
				pParty->pPlayers[1].pPlayerBuffs[PLAYER_BUFF_HAMMERHANDS].Apply(pParty->uTimePlayed + v717, 4u, v2, v2, 0);
				pParty->pPlayers[2].pPlayerBuffs[PLAYER_BUFF_HAMMERHANDS].Apply(pParty->uTimePlayed + v717, 4u, v2, v2, 0);

				pParty->pPlayers[3].pPlayerBuffs[PLAYER_BUFF_HAMMERHANDS].Apply(pParty->uTimePlayed + v717, 4, v2, v2, 0);
				LODWORD(v727) = 1;
				break;
			}
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, pCastSpell->uPlayerID_2);

			pParty->pPlayers[pCastSpell->uPlayerID_2].pPlayerBuffs[PLAYER_BUFF_HAMMERHANDS].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335), v731, v2, v2, 0);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_BODY_CURE_DISEASE:
		{
			if ( v731 == 4 )
				amount = 0;
			else
				amount = 86400 * v2;
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;

			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, pCastSpell->uPlayerID_2);
			v498 = pCastSpell->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])) )
			{
				LODWORD(v727) = 1;
				break;
			}
			if ( v731 == 4 )
			{
				LODWORD(pParty->pPlayers[v498].pConditions[7]) = 0;
				HIDWORD(pParty->pPlayers[v498].pConditions[7]) = 0;
				v499 = pCastSpell->uPlayerID_2;
				LODWORD(pParty->pPlayers[v499].pConditions[9]) = 0;
				HIDWORD(pParty->pPlayers[v499].pConditions[9]) = 0;
				v500 = pCastSpell->uPlayerID_2;
				LODWORD(pParty->pPlayers[v500].pConditions[11]) = 0;
				HIDWORD(pParty->pPlayers[v500].pConditions[11]) = 0;
			}
			else
			{
				*(float *)&a2 = (double)(amount << 7) * 0.033333335;
				pParty->pPlayers[v498].DiscardConditionIfLastsLongerThan(
				7u,
				(signed __int64)((double)(signed __int64)pParty->uTimePlayed - *(float *)&a2));
				pParty->pPlayers[pCastSpell->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;
				v325 = &pParty->pPlayers[pCastSpell->uPlayerID_2];
				v325->DiscardConditionIfLastsLongerThan(v656, v663);
			}
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_BODY_POWER_CURE:
		{
			amount = 5 * v2 + 10;
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v501 = pParty->pPlayers;
			int v1 = 0;
			do
			{
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, v1);
				v501->Heal(amount);
				++v501;
				++v1;
			}
			while ( (signed int)v501 < (signed int)pParty->pHirelings );
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_LIGHT_DISPEL_MAGIC:
		{
			sRecoveryTime -= v2;
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;

			pGame->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0xAFF0Au, 0xC0u);
			v505 = sub_46A6AC((int)dword_50BF30.data(), 100, 4096);
			++pSpellSprite.uType;
			//signed int _v733 = v505;
			v688.x = 0;
			v688.y = 0;
			v688.z = 0;
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.uAttributes = 0;
			pSpellSprite.uSectorID = 0;
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.field_60_distance_related_prolly_lod = 0;
			pSpellSprite.uFacing = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			a2 = 0;
			for ( a2 = 0; a2 < v505; ++a2 )
			{
				v507 = dword_50BF30[a2];
				pSpellSprite.vPosition.x = pActors[v507].vPosition.x;
				pSpellSprite.vPosition.y = pActors[v507].vPosition.y;
				pSpellSprite.vPosition.z = pActors[v507].vPosition.z - (unsigned int)(signed __int64)((double)pActors[v507].uActorHeight * unk_4D8548);
				pSpellSprite.spell_target_pid = PID(OBJECT_Actor, dword_50BF30[a2]);
				v509 = pSpellSprite.Create(0, 0, 0, 0);
				DamageMonsterFromParty(PID(OBJECT_Item, v509), dword_50BF30[a2], &v688);
			}
			for ( a2 = 0; a2 < v505; ++a2 )
			{
				pActor = &pActors[dword_50BF30[a2]];
				pSpellSprite.vPosition.x = pActor->vPosition.x;
				pSpellSprite.vPosition.y = pActor->vPosition.y;
				pSpellSprite.vPosition.z = pActor->vPosition.z - (unsigned int)(signed __int64)((double)pActor->uActorHeight * unk_4D8548);
				pSpellSprite.spell_target_pid = PID(OBJECT_Actor, dword_50BF30[a2]);
				pSpellSprite.Create(0, 0, 0, 0);
				for (int i = 0; i < 22; ++i)
				{
					pActor->pActorBuffs[i].Reset();
				}
			}
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_LIGHT_SUMMON_ELEMENTAL:
		{
			switch (v731)
			{
				case 1: v733 = 300 * v2; amount = 1; break;
				case 2: v733 = 300 * v2; amount = 1; break;
				case 3: v733 = 900 * v2; amount = 3; break;
				case 4: v733 = 900 * v2; amount = 5; break;
				default:
				assert(false);
			}
			//v733 = __PAIR__(0, v516);
			signed int _v733 = 0;
			if ( (signed int)uNumActors > 0 )
			{
				v518 = pActors.data();//[0].uAIState;
				auto _v726 = uNumActors;
				do
				{
					v519 = v518->uAIState;
					if ( v518->uAIState != 5 && v519 != 11 && v519 != 19 && PID(OBJECT_Player, pCastSpell->uPlayerID) == v518->uSummonerID )
						++_v733;
					++v518;
					--_v726;
				}
				while ( _v726 != 0 );
			}
			if ( _v733 >= amount )
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[648], 2);  // This character can't summon any more monsters!
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			sub_44FA4C_spawn_light_elemental(pCastSpell->uPlayerID, v731, v733);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_LIGHT_DAY_OF_THE_GODS:
		{
			switch (v731)
			{
				case 1: LODWORD(v733) = 10800 * v2; amount = 3 * v2 + 10; break;
				case 2: LODWORD(v733) = 10800 * v2; amount = 3 * v2 + 10; break;
				case 3: LODWORD(v733) = 14400 * v2; amount = 4 * v2 + 10; break;
				case 4: LODWORD(v733) = 18000 * v2; amount = 5 * v2 + 10; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;

			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 0);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 1);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 2);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 3);

			pParty->pPartyBuffs[PARTY_BUFF_DAY_OF_GODS].Apply(pParty->uTimePlayed + (signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335), v731, amount, 0, 0);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_LIGHT_PRISMATIC_LIGHT:
		{
			//v67 = 2;
			if ( uCurrentlyLoadedLevelType == LEVEL_Outdoor)
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[497], 2);  // Can't cast Prismatic Light outdoors!
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v531 = sub_46A6AC((int)dword_50BF30.data(), 100, 4096);
			++pSpellSprite.uType;
			v694.x = 0;
			v694.y = 0;
			v694.z = 0;
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.uAttributes = 0;
			pSpellSprite.uSectorID = 0;
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.field_60_distance_related_prolly_lod = 0;
			pSpellSprite.uFacing = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			a2 = 0;
			if ( (signed int)v531 > 0 )
			{
				do
				{
					v533 = dword_50BF30[a2];
					pSpellSprite.vPosition.x = pActors[v533].vPosition.x;
					pSpellSprite.vPosition.y = pActors[v533].vPosition.y;
					pSpellSprite.vPosition.z = pActors[v533].vPosition.z - (unsigned int)(signed __int64)((double)pActors[v533].uActorHeight * unk_4D8548);
					pSpellSprite.spell_target_pid = PID(OBJECT_Actor, dword_50BF30[a2]);
					v535 = pSpellSprite.Create(0, 0, 0, 0);
					v536 = a2;
					DamageMonsterFromParty(PID(OBJECT_Item, v535), dword_50BF30[a2], &v694);
					a2 = v536 + 1;
				}
				while ( v536 + 1 < (signed int)v531 );
			}
			v537 = pGame->GetStru6();
			pGame->GetStru6()->_4A8BFC();
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_LIGHT_DAY_OF_PROTECTION:
		{
			switch (v731)
			{
				case 1: LODWORD(v733) = 14400 * v2; amount = 4 * v2; break;
				case 2: LODWORD(v733) = 14400 * v2; amount = 4 * v2; break;
				case 3: LODWORD(v733) = 14400 * v2; amount = 4 * v2; break;
				case 4: LODWORD(v733) = 18000 * v2; amount = 5 * v2; break;
				default:
				assert(false);
			}
			v730 = LODWORD(v733);
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;

			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 0);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 1);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 2);
			pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 3);

			v732 = v730 << 7;
			v549 = (double)(v730 << 7) * 0.033333335;
			*((float *)&v733 + 1) = v549;
			v712 = (signed __int64)v549;
			pParty->pPartyBuffs[PARTY_BUFF_RESIST_BODY].Apply(pParty->uTimePlayed + (signed __int64)v549, v731, amount, 0, 0);
			pParty->pPartyBuffs[PARTY_BUFF_RESIST_MIND].Apply(pParty->uTimePlayed + v712, v731, amount, 0, 0);
			pParty->pPartyBuffs[PARTY_BUFF_RESIST_FIRE].Apply(pParty->uTimePlayed + v712, v731, amount, 0, 0);
			pParty->pPartyBuffs[PARTY_BUFF_RESIST_WATER].Apply(pParty->uTimePlayed + v712, v731, amount, 0, 0);
			pParty->pPartyBuffs[PARTY_BUFF_RESIST_AIR].Apply(pParty->uTimePlayed + v712, v731, amount, 0, 0);
			pParty->pPartyBuffs[PARTY_BUFF_RESIST_EARTH].Apply(pParty->uTimePlayed + v712, v731, amount, 0, 0);
			v550 = v2 + 5;
			pParty->pPartyBuffs[PARTY_BUFF_FEATHER_FALL].Apply(
				(signed __int64)((double)(signed __int64)pParty->uTimePlayed + *((float *)&v733 + 1)),
				v731,
				v550, 0, 0);

			pParty->pPartyBuffs[PARTY_BUFF_WIZARD_EYE].Apply((signed __int64)((double)(signed __int64)pParty->uTimePlayed + *((float *)&v733 + 1)), v731, v550, 0, 0);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_LIGHT_HOUR_OF_POWER:
		{
			switch (v731)
			{
				case 1: LODWORD(v733) = 4; amount = 4; break;
				case 2: LODWORD(v733) = 4; amount = 4; break;
				case 3: LODWORD(v733) = 12; amount = 12; break;
				case 4: LODWORD(v733) = 20; amount = 15; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			y = (char *)(60 * (v2 * LODWORD(v733) + 60));
			v732 = (300 * amount * v2 + 60) << 7;
			v730 = v2 + 5;
			int _v726 = 0;
			v553 = pParty->pPlayers;//[0].pConditions[1];
			*((float *)&v733) = (double)v732 * 0.033333335;
			do
			{
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 0);
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 1);
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 2);
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, 3);

				//((SpellBuff *)(v553 + 6056))->Apply(
				v553->pPlayerBuffs[4].Apply((signed __int64)((double)(signed __int64)pParty->uTimePlayed + *((float *)&v733)), v731, v730, 0, 0);
				if ( *(_QWORD *)v553 )
					_v726 = 1;
				++v553;
			}
			while ( v553 <= &pParty->pPlayers[3] );
			v562 = v731;
			pParty->pPartyBuffs[PARTY_BUFF_HEROISM].Apply((signed __int64)((double)(signed __int64)pParty->uTimePlayed + *((float *)&v733)), v731, v730, 0, 0);
			pParty->pPartyBuffs[PARTY_BUFF_SHIELD].Apply((signed __int64)((double)(signed __int64)pParty->uTimePlayed + *((float *)&v733)), v562, 0, 0, 0);
			pParty->pPartyBuffs[PARTY_BUFF_STONE_SKIN].Apply((signed __int64)((double)(signed __int64)pParty->uTimePlayed + *((float *)&v733)), v562, v730, 0, 0);
			if (!_v726)
			{
				pParty->pPartyBuffs[PARTY_BUFF_HASTE].Apply((signed __int64)((double)(signed int)((int)y << 7) * 0.033333335 + (double)(signed __int64)pParty->uTimePlayed), v562, v730, 0, 0);
			}
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_LIGHT_DIVINE_INTERVENTION:
		{
			amount = 3;
			if ( pPlayer->uNumDivineInterventionCastsThisDay >= 3u )
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2); // Spell failed
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			a2 = 0;
			_this = (ItemGen *)&pPlayers[1];
			do
			{
				v563 = 0;
				do
				{
					v564 = _this->uItemID;
					*(int *)(v563 + _this->uItemID) = 0;
					v563 += 8;
					*(int *)(v563 + v564 - 4) = 0;
				}
				while ( v563 <= 128 );
				v565 = ((Player *)_this->uItemID)->GetMaxHealth();
				v566 = (Player **)_this;
				*(int *)(_this->uItemID + 6460) = v565;
				v567 = (*v566)->GetMaxMana();
				*(int *)(_this->uItemID + 6464) = v567;
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, a2);
				++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;
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_DARK_REANIMATE:
		{
			switch (v731)
			{
				case 1: amount = 2 * v2; break;
				case 2: amount = 3 * v2; break;
				case 3: amount = 4 * v2; break;
				case 4: amount = 5 * v2; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			v576 = pCastSpell->spell_target_pid;
			if (!v576)
			{
				v585 = (char *)&pParty->pPlayers[pCastSpell->uPlayerID_2];
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, pCastSpell->uPlayerID_2);
				if ( *((_QWORD *)v585 + 14) )
				{
				((Player *)v585)->SetCondition(0x11u, 1);
				v587 = ((Player *)v585)->GetSexByVoice();
				ReloadPlayerPortraits(pCastSpell->uPlayerID_2, (v587 != 0) + 23);
				*((_QWORD *)v585 + 17) = pParty->uTimePlayed;
				}
				break;
			}
			v577 = (Player *)(PID_ID(v576));
			//v726 = v577;
			if ( v577 == (Player *)-1 )
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[496], 2);  // No valid target exists!
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			v578 = (int)&pActors[(int)v577];
			v721 = v578;
			if ( *(short *)(v578 + 40) > 0 || (v579 = *(short *)(v578 + 176), v579 != 5) && v579 != 4 )
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2); // Spell failed
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			++pSpellSprite.uType;
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.uAttributes = 0;
			pSpellSprite.uSectorID = 0;
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.field_60_distance_related_prolly_lod = 0;
			v581 = v721;
			pSpellSprite.uFacing = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			pSpellSprite.vPosition.x = *(short *)(v721 + 142);
			pSpellSprite.vPosition.y = *(short *)(v721 + 144);
			v732 = *(short *)(v721 + 138);
			pSpellSprite.vPosition.z = *(short *)(v721 + 146) - (unsigned int)(signed __int64)((double)v732 * unk_4D8548);
			pSpellSprite.spell_target_pid = PID(OBJECT_Actor, (int)v577);
			pSpellSprite.Create(0, 0, 0, 0);
			if ( *(char *)(v581 + 52) > amount )
				break;
			Actor::Resurrect((unsigned int)v577);
			*(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) = 0;
			((SpellBuff *)(v581 + 356))->Reset();
			((SpellBuff *)(v581 + 228))->Reset();
			((SpellBuff *)(v581 + 404))->Reset();
			if ( *(short *)(v581 + 40) > 10 * amount )
				*(short *)(v581 + 40) = 10 * amount;
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_DARK_VAMPIRIC_WEAPON:
		{
			amount = 16;
			if ( v731 == 4 )
			{
				LODWORD(v733) = 0;
			}
			else
			{
				LODWORD(v733) = 3600 * v2;
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			__debugbreak();
			//HIDWORD(v733) = (int)(char *)&pParty + 6972 * pCastSpell->uPlayerID_2 + 36 * a2 + 3040;
			ItemGen *_v733 = &pParty->pPlayers[pCastSpell->uPlayerID_2].pInventoryItems[a2];
			ItemDesc *_v732 = &pItemsTable->pItems[_v733->uItemID];
			_v733->UpdateTempBonus(pParty->uTimePlayed);
			if ( _v733->uItemID >= 64 && _v733->uItemID <= 65
				|| LOBYTE(_v733->uAttributes) & 2
				|| _v733->uSpecEnchantmentType != 0
				|| _v733->uEnchantmentType != 0
				|| (v591 = _v732->uEquipType) != 0 && v591 != 1 && v591 != 2
				|| pItemsTable->IsMaterialNonCommon(_v733) )
			{
				dword_50C9D0 = 113;
				dword_50C9D4 = 0;
				dword_50C9D8 = 1;

				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2); // Spell failed
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			v592 = _v733;
			v14 = v731 == 4;
			_v733->uSpecEnchantmentType = 16;
			if ( !v14 )
			{
				v732 = (int)v733 << 7;
				v592->uExpireTime = pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
				v592->uAttributes |= 8u;
			}
			LOBYTE(v592->uAttributes) |= 0x80u;
			_50C9A8_item_enchantment_timer = 256;
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_DARK_SHARPMETAL:
		{
			switch (v731)
			{
				case 1: amount = 5; break;
				case 2: amount = 5; break;
				case 3: amount = 7; break;
				case 4: amount = 9; break;
				default:
				assert(false);
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			auto _v726 = ((signed int)(60 * stru_5C6E00->uIntegerDoublePi) / 360);
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.vPosition.x = pParty->vPosition.x;
			pSpellSprite.vPosition.y = pParty->vPosition.y;
			pSpellSprite.uAttributes = 0;
			pSpellSprite.vPosition.z = pParty->vPosition.z + (signed int)pParty->uPartyHeight / 2;
			pSpellSprite.uSectorID = pIndoor->GetSector(
								pParty->vPosition.x,
								pParty->vPosition.y,
								pParty->vPosition.z + (signed int)pParty->uPartyHeight / 2);
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.spell_target_pid = a2;
			pSpellSprite.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			if ( pParty->bTurnBasedModeOn == 1 )
				LOBYTE(pSpellSprite.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
				{
					pSpellSprite.uFacing = v596 + v597;
					if ( pSpellSprite.Create(
							v596 + v597,
							v715.uPitchAngle,
							pObjectList->pObjects[(signed __int16)pSpellSprite.uObjectDescID].uSpeed,
							pCastSpell->uPlayerID + 1) != -1
							&& pParty->bTurnBasedModeOn == 1 )
						++pTurnEngine->field_1C;
					v596 += _v726 / (amount - 1);
				}
				while ( v596 <= (signed int)y );
			}
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_DARK_CONTROL_UNDEAD:
		{
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			switch (v731)
			{
				case 1: LODWORD(v733) = 180 * v2; break;
				case 2: LODWORD(v733) = 180 * v2; break;
				case 3: LODWORD(v733) = 300 * v2; break;
				case 4: LODWORD(v733) = 29030400; break;
				default:
				assert(false);
			}
			if (PID_TYPE(a2) != OBJECT_Actor)
			{
				LODWORD(v727) = 1;
				break;
			}
			pActor = &pActors[PID_ID(a2)];
			if ( !MonsterStats::BelongsToSupertype(pActor->pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD) )
				break;
			if ( !stru_50C198.GetMagicalResistance(pActor, 0xAu) )
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2); // Spell failed
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			pActor->pActorBuffs[9].Reset();
			pActor->pActorBuffs[1].Reset();
			pActor->pActorBuffs[12].Apply(pParty->uTimePlayed + (signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335),
				v731, 0, 0, 0);
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			v60 = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			
			v600 = pActor->vPosition.y;
			v601 = pActor->vPosition.x;
			pSpellSprite.uObjectDescID = v60;
			pSpellSprite.vPosition.x = v601;
			v602 = pActor->uActorHeight;
			v603 = pActor->vPosition.z;
			pSpellSprite.vPosition.y = v600;
			v676 = v603 + v602;
			v665 = v600;
			pSpellSprite.vPosition.z = v603 + v602;
			v657 = v601;
			pSpellSprite.uAttributes = 0;
			pSpellSprite.uSectorID = pIndoor->GetSector(v657, v665, v676);
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.spell_target_pid = a2;
			pSpellSprite.field_60_distance_related_prolly_lod = LOBYTE(v715.uDistance);
			pSpellSprite.uFacing = LOWORD(v715.uYawAngle);
			LOBYTE(pSpellSprite.uAttributes) |= 0x80u;
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			pSpellSprite.Create(0, 0, 0, pCastSpell->uPlayerID + 1);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_DARK_SACRIFICE:
		{
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			int _v733 = 0;
			memset(&achieved_awards, 0, 4000);
			int i = 0;
			pNPCData = pParty->pHirelings;
			do
			{
				if ( pNPCData->pName != 0)
				{
					v606 = _v733++;
					achieved_awards[v606] = (AwardType)(i + 1);
				}
				++i;
				++pNPCData;
			}
			while ( pNPCData <= &pParty->pHirelings[1] );
			i = 0;
			if ( (signed int)pNPCStats->uNumNewNPCs > 0)
			{
				pNPCData = pNPCStats->pNewNPCData;
				//__debugbreak(); // data offset
				AwardType *_v734 = &achieved_awards[_v733];
				do
				{
					if ( pNPCData->uFlags & 0x80
						&& (!pParty->pHirelings[0].pName || strcmp(pNPCData->pName, pParty->pHirelings[0].pName))
						&& (!pParty->pHirelings[1].pName || strcmp(pNPCData->pName, pParty->pHirelings[1].pName)) )
					{
						v607 = _v734;
						++_v734;
						*v607 = (AwardType)(i + 3);
					}
					++i;
					++pNPCData;
				}
				while ( (signed int)i < (signed int)pNPCStats->uNumNewNPCs );
			}
			v608 = pCastSpell->uPlayerID_2;
			if ( v608 != 4 && v608 != 5
				|| (v609 = (signed int)*(&pFontCChar + v608 + (unsigned __int8)pParty->field_709), v609 <= 0)
				|| v609 >= 3 )
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2); // Spell failed
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			v610 = 76 * v609;
			//*((int *)&pParty->pPlayers[3].pInstalledBeacons[4].uBeaconTime + 19 * v609) = 0;
			pParty->pHirelings[v609-1].evt_B = 0;
			v611 = pIconsFrameTable->FindIcon("spell96");
			//*(int *)((char *)&pParty->pPlayers[3].pInstalledBeacons[4].uBeaconTime + v610 + 4) = pIconsFrameTable->GetIconAnimLength(v611);
			pParty->pHirelings[v609-1].evt_C = pIconsFrameTable->GetIconAnimLength(v611);
			//*(int *)((char *)&pParty->pPlayers[3].pInstalledBeacons[3].field_18 + v610) = 1;
			pParty->pHirelings[v609-1].evt_A = 1;

			v612 = pParty->pPlayers;
			do
			{
				v612->sHealth = v612->GetMaxHealth();
				v612->sMana = v612->GetMaxMana();
				++v612;
			}
			while ( v612 <= &pParty->pPlayers[3] );
			v613 = &pOutdoor->ddm;
			if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor)
				v613 = &pIndoor->dlv;
			v613->uReputation += 15;
			if ( v613->uReputation > 10000 )
				v613->uReputation = 10000;
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_DARK_PAIN_REFLECTION:
		{
			switch (v731)
			{
				case 1: LODWORD(v733) = 300 * (v2 + 12); break;
				case 2: LODWORD(v733) = 300 * (v2 + 12); break;
				case 3: LODWORD(v733) = 300 * (v2 + 12); break;
				case 4: LODWORD(v733) = 900 * (v2 + 4); break;
				default:
				assert(false);
			}
			amount = v2 + 5;
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			if ( v731 != 3 && v731 != 4 )
			{
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, pCastSpell->uPlayerID_2);
				pParty->pPlayers[pCastSpell->uPlayerID_2].pPlayerBuffs[PLAYER_BUFF_PAIN_REFLECTION].Apply(pParty->uTimePlayed + (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335), v731, amount, v716, 0);
				LODWORD(v727) = 1;
				break;
			}
			a2 = 0;
			v717 = (signed int)(signed __int64)((double)(signed int)((int)v733 << 7) * 0.033333335);
			v619 = pParty->pPlayers;//[0].pPlayerBuffs[10];
			do
			{
				pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, a2);
				v619->pPlayerBuffs[PLAYER_BUFF_PAIN_REFLECTION].Apply(pParty->uTimePlayed + v717, v731, amount, v716, 0);
				++a2;
				++v619;
			}
			while ( v619 <= &pParty->pPlayers[3] );
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_DARK_SOULDRINKER:
		{
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			pGame->GetIndoorCamera();
			v623 = (signed __int64)pGame->pIndoorCameraD3D->GetPickDepth();
			signed int _v733 = sub_46A6AC((int)dword_50BF30.data(), 100, v623);
			v707.x = 0;
			v707.y = 0;
			v707.z = 0;
			pSpellSprite.stru_24.Reset();
			pSpellSprite.spell_id = pCastSpell->spellnum;
			pSpellSprite.spell_level = v2;
			pSpellSprite.spell_skill = v731;
			pSpellSprite.uObjectDescID = pObjectList->ObjectIDByItemID(pSpellSprite.uType);
			pSpellSprite.uAttributes = 0;
			pSpellSprite.uSectorID = 0;
			pSpellSprite.uSpriteFrameID = 0;
			pSpellSprite.field_60_distance_related_prolly_lod = 0;
			pSpellSprite.uFacing = 0;
			pSpellSprite.spell_caster_pid = PID(OBJECT_Player, pCastSpell->uPlayerID);
			pSpellSprite.uSoundID = LOWORD(pCastSpell->sound_id);
			a2 = 0;
			int _v726 = 0;
			if ( _v733 > 0 )
			{
				_v726 = (_v733 * (7 * v2 + 25));
				do
				{
					v625 = dword_50BF30[a2];
					pSpellSprite.vPosition.x = pActors[v625].vPosition.x;
					pSpellSprite.vPosition.y = pActors[v625].vPosition.y;
					//v732 = pActors[v625].uActorHeight;
					pSpellSprite.vPosition.z = pActors[v625].vPosition.z - (unsigned int)(signed __int64)((double)pActors[v625].uActorHeight * unk_4D8548);
					pSpellSprite.spell_target_pid = PID(OBJECT_Actor, dword_50BF30[a2]);
					v627 = pSpellSprite.Create(0, 0, 0, 0);
					v628 = a2;
					DamageMonsterFromParty(PID(OBJECT_Item, v627), dword_50BF30[a2], &v707);
					a2 = v628 + 1;
				}
				while ( v628 + 1 < _v733 );
			}
			v730 = 0;
			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);
			_v733 = 0;
			if ( v730 > 0 )
			{
				do
				{
					//v632 = 4 * v681[HIDWORD(v733)] + 10965188;
					v726 = pPlayers[v681[_v733]];
					//v633 = pPlayers[v681[HIDWORD(v733)]];
					v726->sHealth += v732;
					//v726 = *(Player **)v632;
					//v634 = v726->GetMaxHealth();
					if ( v726->sHealth > v726->GetMaxHealth())
						v726->sHealth = v726->GetMaxHealth();
					v635 = _v733;

					pGame->GetStru6()->SetPlayerBuffAnim(pCastSpell->spellnum, WORD2(v733));
					_v733 = v635 + 1;
				}
				while ( v635 + 1 < v730 );
			}
			pGame->GetStru6()->FadeScreen__like_Turn_Undead_and_mb_Armageddon(0, 0x40u);
			LODWORD(v727) = 1;
			break;
		}
		case SPELL_DARK_ARMAGEDDON:
		{
			if ( uCurrentlyLoadedLevelType == LEVEL_Indoor)
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[499], 2);  // Can't cast Armageddon indoors!
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			if ( v731 == 4)
				amount = 4;
			else
				amount = 3;
			if ( pPlayer->uNumArmageddonCasts >= amount || pParty->armageddon_timer > 0 )
			{
				ShowStatusBarString(pGlobalTXT_LocalizationStrings[428], 2); // Spell failed
				pAudioPlayer->PlaySound(SOUND_PlayerCantCastSpell, 0, 0, -1, 0, 0, 0, 0);
				pCastSpell->spellnum = 0;
				continue;
			}
			if ( !pPlayer->CanCastSpell(uRequiredMana) )
				break;
			pParty->armageddon_timer = 256;
			pParty->field_16140 = v2;
			++pPlayer->uNumArmageddonCasts;
			if ( pParty->bTurnBasedModeOn == 1 )
				++pTurnEngine->field_1C;
			auto _v726 = 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, &v710, 0);
				v644 = rand();
				sub_42F7EB_DropItemAt(0xFE6u, v721, (int)y, v732 + 16, v644 % 500 + 500, 1, 0, 0, 0);
				--_v726;
			}
			while ( _v726 != 0 );
			LODWORD(v727) = 1;
			break;
		}

		default:
			break;
	}
	if ( pCastSpell->field_8 & 0x20 )
	{
		if ( v727 != 0.0 )
			pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[pCastSpell->spellnum], 0, 0, -1, 0, pCastSpell->sound_id, 0, 0);
	}
	else
	{
		if ( sRecoveryTime < 0 )
			sRecoveryTime = 0;
		if ( pParty->bTurnBasedModeOn )
		{
			v645 = sRecoveryTime;
			pParty->pTurnBasedPlayerRecoveryTimes[pCastSpell->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(SPEECH_49, 0);
			if ( v727 != 0.0 )
				pAudioPlayer->PlaySound((SoundID)word_4EE088_sound_ids[pCastSpell->spellnum], 0, 0, -1, 0, pCastSpell->sound_id, 0,	0);
		}
	}
	pCastSpell->spellnum = 0;
	v2 = v723;
	continue;
  }
  
}
//----- (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;
}

const wchar_t *UIMessage2String(UIMessageType msg)
{
  #define CASE(xxx) case xxx: swprintf(b, wcslen(L"%03X/%s"), L"%03X/%s", msg, L#xxx); return b;
  static wchar_t b[256]; // bad for threads
  switch (msg)
  {
    CASE(UIMSG_SelectSpell)
    CASE(UIMSG_ChangeGameState)
    CASE(UIMSG_Attack)
    CASE(UIMSG_PlayArcomage)
    CASE(UIMSG_MainMenu_ShowPartyCreationWnd)
    CASE(UIMSG_MainMenu_ShowLoadWindow)
    CASE(UIMSG_ShowCredits)
    CASE(UIMSG_ExitToWindows)
    CASE(UIMSG_PlayerCreationChangeName)
    CASE(UIMSG_PlayerCreationClickPlus)
    CASE(UIMSG_PlayerCreationClickMinus)
    CASE(UIMSG_PlayerCreationSelectActiveSkill)
    CASE(UIMSG_PlayerCreationSelectClass)
    CASE(UIMSG_PlayerCreationClickOK)
    CASE(UIMSG_PlayerCreationClickReset)
    CASE(UIMSG_ClickBooksBtn)
    CASE(UIMSG_PlayerCreationRemoveUpSkill)
    CASE(UIMSG_PlayerCreationRemoveDownSkill)
    CASE(UIMSG_SPellbook_ShowHightlightedSpellInfo)
    CASE(UIMSG_LoadGame)
    CASE(UIMSG_SaveGame)
    CASE(UIMSG_ShowStatus_DateTime)
    CASE(UIMSG_ShowStatus_ManaHP)
    CASE(UIMSG_ShowStatus_Player)
    CASE(UIMSG_Wait5Minutes)
    CASE(UIMSG_Wait1Hour)
    CASE(UIMSG_ShowStatus_Food)
    CASE(UIMSG_ShowStatus_Funds)
    CASE(UIMSG_QuickReference)
    CASE(UIMSG_GameMenuButton)
    CASE(UIMSG_AlreadyResting)
    CASE(UIMSG_SelectCharacter)
    CASE(UIMSG_ChangeSoundVolume)
    CASE(UIMSG_ChangeMusicVolume)
    CASE(UIMSG_Escape)
    CASE(UIMSG_PlayerCreation_SelectAttribute)
    CASE(UIMSG_InventoryLeftClick)
    CASE(UIMSG_SkillUp)
    CASE(UIMSG_GameMenu_ReturnToGame)
    CASE(UIMSG_StartNewGame)
    CASE(UIMSG_Game_OpenLoadGameDialog)
    CASE(UIMSG_Game_OpenSaveGameDialog)
    CASE(UIMSG_Game_OpenOptionsDialog)
    CASE(UIMSG_SetGraphicsMode)
    CASE(UIMSG_Quit)
    CASE(UIMSG_StartHireling1Dialogue)
    CASE(UIMSG_StartHireling2Dialogue)
    CASE(UIMSG_SelectNPCDialogueOption)
    CASE(UIMSG_CastSpellFromBook)
    CASE(UIMSG_PlayerCreation_VoicePrev)
    CASE(UIMSG_PlayerCreation_VoiceNext)
    CASE(UIMSG_StartNPCDialogue)
    CASE(UIMSG_ArrowUp)
    CASE(UIMSG_DownArrow)
    CASE(UIMSG_SaveLoadBtn)
    CASE(UIMSG_SelectLoadSlot)
    CASE(UIMSG_Cancel)
    CASE(UIMSG_ExitRest)
    CASE(UIMSG_PlayerCreation_FacePrev)
    CASE(UIMSG_PlayerCreation_FaceNext)
    CASE(UIMSG_CycleCharacters)
    CASE(UIMSG_SetTurnSpeed)
    CASE(UIMSG_ToggleWalkSound)
    CASE(UIMSG_ChangeVoiceVolume)
    CASE(UIMSG_ToggleShowDamage)
    CASE(UIMSG_ScrollNPCPanel)
    CASE(UIMSG_ShowFinalWindow)
    CASE(UIMSG_OpenQuestBook)
    CASE(UIMSG_OpenAutonotes)
    CASE(UIMSG_OpenMapBook)
    CASE(UIMSG_OpenCalendar)
    CASE(UIMSG_OpenHistoryBook)
    CASE(UIMSG_ToggleAlwaysRun)
    CASE(UIMSG_ToggleFlipOnExit)
    CASE(UIMSG_Game_Action)
    CASE(UIMSG_RentRoom)
    CASE(UIMSG_TransitionUI_Confirm)
    CASE(UIMSG_OpenKeyMappingOptions)
    CASE(UIMSG_SelectKeyPage1)
    CASE(UIMSG_SelectKeyPage2)
    CASE(UIMSG_ResetKeyMapping)
    CASE(UIMSG_ChangeKeyButton)
    CASE(UIMSG_OpenVideoOptions)
    CASE(UIMSG_ToggleBloodsplats)
    CASE(UIMSG_ToggleColoredLights)
    CASE(UIMSG_ToggleTint)
    default:
      swprintf(b, wcslen(L"UIMSG_%03X") , L"UIMSG_%03X", msg); return b;
  };
  #undef CASE
}

//----- (0042EB8D) --------------------------------------------------------
void GUIMessageQueue::AddMessageImpl(UIMessageType msg, int param, unsigned int a4, const char *file, int line)
{
  //Log::Warning(L"%s @ (%S %u)", UIMessage2String(msg), file, line);
  if (uNumMessages < 40)
  {
    files[uNumMessages] = file;
    lines[uNumMessages] = line;

    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::Sin(int angle)
{
  return Cos(angle - this->uIntegerHalfPi);
}

//----- (0042ECB5) --------------------------------------------------------
void _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
  //int v28; // [sp+20h] [bp-1Ch]@9
  //unsigned int *v28b;
  //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 = &pParty->pPlayers[uActiveCharacter-1];
  //result = pParty->pPlayers[uActiveCharacter-1].CanAct();
  auto player = &pParty->pPlayers[uActiveCharacter - 1];
  if (!player->CanAct())
    return;

  pCastSpellInfo.data()->_427D48(uActiveCharacter);
    //v3 = 0;
  if (pParty->Invisible())
    pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Reset();

    //v31 = player->pEquipment.uBow;
  int bow_idx = player->pEquipment.uBow;
  if (bow_idx && player->pInventoryItems[bow_idx - 1].Broken())
    bow_idx = 0;

    //v32 = 0;
  int wand_item_id = 0;
    //v33 = 0;
    //v4 = v1->pEquipment.uMainHand;
  int laser_weapon_item_id = 0;

  int main_hand_idx = player->pEquipment.uMainHand;
  if (main_hand_idx)
  {
    auto item = &player->pInventoryItems[main_hand_idx - 1];
      //v5 = (char *)v1 + 36 * v4;
    if (!item->Broken())
    {
		//v28b = &v1->pInventoryItems[v4].uItemID;
        //v6 = v1->pInventoryItems[v4].uItemID;//*((int *)v5 + 124);
      if (pItemsTable->pItems[item->uItemID].uEquipType == EQUIP_WAND)
      {
        if (item->uNumCharges <= 0)
          player->pEquipment.uMainHand = 0; // wand discharged - unequip
        else
          wand_item_id = item->uItemID;//*((int *)v5 + 124);
      }
      else if (item->uItemID == ITEM_BLASTER || item->uItemID == ITEM_LASER_RIFLE)
        laser_weapon_item_id = item->uItemID;//*((int *)v5 + 124);
    }
  }

    //v30 = 0;
    //v29 = 0;
    //v28 = 0;
    //v7 = pMouse->uPointingObjectID;

  int target_pid = pMouse->uPointingObjectID;
  int target_type = PID_TYPE(target_pid),
      target_id = PID_ID(target_pid);
  if (target_type != OBJECT_Actor || !pActors[target_id].CanAct())
  {
    target_pid = stru_50C198.FindClosestActor(5120, 0, 0);
    target_type = PID_TYPE(target_pid);
    target_id = PID_ID(target_pid);
  }

  auto actor = &pActors[target_id];
  int actor_distance = 0;
  if (target_type == OBJECT_Actor)
  {
    int distance_x = actor->vPosition.x - pParty->vPosition.x,
        distance_y = actor->vPosition.y - pParty->vPosition.y,
        distance_z = actor->vPosition.z - pParty->vPosition.z;
    actor_distance = integer_sqrt(distance_x * distance_x + distance_y * distance_y + distance_z * distance_z) - actor->uActorRadius;
    if (actor_distance < 0)
      actor_distance = 0;
  }

  bool shooting_bow = false,
       shotting_laser = false,
       shooting_wand = false,
       melee_attack = false;
  if (laser_weapon_item_id)
  {
    shotting_laser = true;
    _42777D_CastSpell_UseWand_ShootArrow(SPELL_LASER_PROJECTILE, uActiveCharacter - 1, 0, 0, uActiveCharacter + 8);
  }
  else if (wand_item_id)
  {
    shooting_wand = true;

    int main_hand_idx = player->pEquipment.uMainHand;
    _42777D_CastSpell_UseWand_ShootArrow(wand_spell_ids[player->pInventoryItems[main_hand_idx - 1].uItemID - ITEM_WAND_FIRE], uActiveCharacter - 1, 8, 0, uActiveCharacter + 8);

    if (!--player->pInventoryItems[main_hand_idx - 1].uNumCharges)
      player->pEquipment.uMainHand = 0;
  }
  else if (target_type == OBJECT_Actor && actor_distance <= 407.2)
  {
    melee_attack = true;

    Vec3_int_ a3;
    a3.x = actor->vPosition.x - pParty->vPosition.x;
    a3.y = actor->vPosition.y - pParty->vPosition.y;
    a3.z = actor->vPosition.z - pParty->vPosition.z;
    Vec3_int_::Normalize(&a3.x, &a3.y, &a3.z);

    DamageMonsterFromParty(PID(OBJECT_Player, uActiveCharacter - 1), target_id, &a3);
    if (player->WearsItem(ITEM_ARTIFACT_SPLITTER, EQUIP_MAIN_HAND) || player->WearsItem(ITEM_ARTIFACT_SPLITTER, EQUIP_OFF_HAND))
          _42FA66_do_explosive_impact(
            actor->vPosition.x,
            actor->vPosition.y,
            actor->vPosition.z + actor->uActorHeight / 2,
            0, 512, uActiveCharacter);
  }
  else if (bow_idx)
  {
    shooting_bow = true;
    _42777D_CastSpell_UseWand_ShootArrow(SPELL_BOW_ARROW, uActiveCharacter - 1, 0, 0, 0);
  }
  else
  {
    melee_attack = true;
    ; // actor out of range or no actor; no ranged weapon so melee attacking air
  }

  if (!pParty->bTurnBasedModeOn && melee_attack) // wands, bows & lasers will add recovery while shooting spell effect
  {
    int recovery = player->GetAttackRecoveryTime(false);
    if (recovery < 30 )
      recovery = 30;
    player->SetRecoveryTime(flt_6BE3A4_debug_recmod1 * (double)recovery * 2.133333333333333);
  }

  
  int v34 = 0;
  if (shooting_wand)
    return;
  else if (shooting_bow)
  {
    v34 = 5;
    player->PlaySound(SPEECH_50, 0);
  }
  if (shotting_laser)
    v34 = 7;
  else
  {
    int main_hand_idx = player->pEquipment.uMainHand;
    if (player->HasItemEquipped(EQUIP_MAIN_HAND))
      v34 = pItemsTable->pItems[*(int *)&player->pInventoryItems[main_hand_idx - 1]].uSkillType;
    pTurnEngine->_40471C();
  }

  switch (v34)
  {
    case 0: pAudioPlayer->PlaySound(SOUND_81, 0, 0, -1, 0, 0, 0, 0); break;
    case 1: pAudioPlayer->PlaySound(SOUND_84, 0, 0, -1, 0, 0, 0, 0); break;
    case 2: pAudioPlayer->PlaySound(SOUND_85, 0, 0, -1, 0, 0, 0, 0); break;
    case 3: pAudioPlayer->PlaySound(SOUND_78, 0, 0, -1, 0, 0, 0, 0); break;
    case 4: pAudioPlayer->PlaySound(SOUND_80, 0, 0, -1, 0, 0, 0, 0); break;
    case 5: pAudioPlayer->PlaySound(SOUND_71, 0, 0, -1, 0, 0, 0, 0); break;
    case 6: pAudioPlayer->PlaySound(SOUND_83, 0, 0, -1, 0, 0, 0, 0); break;
    case 7: pAudioPlayer->PlaySound(SOUND_67, 0, 0, -1, 0, 0, 0, 0); break;
  }
}

//----- (0042F184) --------------------------------------------------------
int stru319::FindClosestActor(int pick_depth, 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->PickClosestActor(OBJECT_Actor, pick_depth, v6, 657456, -1);
    if ( v7 != -1 )
      return (unsigned __int16)v7;
    else return 0;
  }
  else
  {
    v30 = 0;
    if ( pRenderer->pActiveZBuffer )
    {
      v29 = viewparams->uScreen_topL_X;
      v23 = viewparams->uScreen_BttmR_X;
      if ( (signed int)viewparams->uScreen_topL_Y < (signed int)viewparams->uScreen_BttmR_Y )
      {
        v25 = viewparams->uScreen_BttmR_Y - viewparams->uScreen_topL_Y;
        v9 = &pRenderer->pActiveZBuffer[viewparams->uScreen_topL_X + 640 * viewparams->uScreen_topL_Y];
        v26 = &pRenderer->pActiveZBuffer[viewparams->uScreen_topL_X + 640 * viewparams->uScreen_topL_Y];
        do
        {
          if ( (signed int)v29 < (signed int)v23 )
          {
            v28 = v9;
            v10 = v4;
            v27 = v23 - v29;
            do
            {
              v22 = *v28;
              v11 = *v28 & 0xFFFF;
              if (PID_TYPE(v11) == OBJECT_Actor)
              {
                v12 = &pActors[PID_ID(v11)];
                v13 = v12->uAIState;
                if ( v13 != 5 )
                {
                  if ( v13 != 4
                    && v13 != 11
                    && v13 != 19
                    && v13 != 17
                    && (!a3 || pActors[PID_ID(v11)].GetActorsRelation(0)) )
                  {
                    if ( (!a4 || MonsterStats::BelongsToSupertype(v12->pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD))
                      && v22 <= pick_depth << 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.data();
        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.data() - (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.data();
  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
  Actor *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 = pActors.data();
    while ( 1 )
    {
		v2 = abs(v1->vInitialPosition.x - pParty->vPosition.x);
		v11 = abs(v1->vInitialPosition.y - pParty->vPosition.y);
		v12 = abs(v1->vInitialPosition.z - 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 = v1->uAIState;
        if ( v1->uAIState != 5 )
        {
          if ( v9 != 4
            && v9 != 11
            && v9 != 19
            && v9 != 17
			&& (BYTE2(v1->uAttributes) & 8 || ((Actor *)nullptr)->GetActorsRelation( v1)) )
            break;
        }
      }
      ++v13;
      ++v1;
      if ( v13 >= (signed int)uNumActors )
        goto LABEL_20;
    }
    result = 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
  //SpriteObject 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;

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

  if ( a9 )
  {
    memcpy(&a1a.stru_24, a9, sizeof(a1a.stru_24));
    v9 = v22;
  }
  v10 = 0;
  a1a.spell_skill = 0;
  a1a.spell_level = 0;
  a1a.spell_id = 0;
  a1a.field_54 = 0;
  a1a.uType = 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.spell_caster_pid = 0;
  a1a.spell_target_pid = 0;
  if ( !(a1a.uAttributes & 0x10) )
  {
    v13 = 0;
    if ( (signed int)pItemsTable->uAllItemsCount > 0 )
    {
      v14 = (char *)&pItemsTable->pItems[0].uSpriteID;
      while ( *(short *)v14 != v9 )
      {
        ++v13;
        v14 += 48;
        if ( (signed int)v13 >= (signed int)pItemsTable->uAllItemsCount )
          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
  //SpriteObject a1; // [sp+Ch] [bp-70h]@1

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

  v5 = 0;
  a1.spell_skill = 0;
  a1.spell_level = 0;
  a1.spell_id = 0;
  a1.field_54 = 0;
  a1.uType = 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.spell_caster_pid = 0;
  a1.spell_target_pid = 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);
  }
}



//----- (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
  //SpriteObject a1a; // [sp+Ch] [bp-74h]@1
  int v14; // [sp+7Ch] [bp-4h]@1

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

  a1a.spell_id = SPELL_FIRE_FIREBALL;
  a1a.spell_level = 8;
  a1a.spell_skill = 3;
  v14 = 0;
  if ( (signed int)pObjectList->uNumObjects <= 0 )
  {
LABEL_5:
    v9 = 0;
  }
  else
  {
    v8 = (char *)&pObjectList->pObjects->uObjectID;
    while ( (short)a1a.uType != *(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.spell_target_pid = 0;
  a1a.field_60_distance_related_prolly_lod = 0;
  a1a.uFacing = 0;
  a1a.uSoundID = 0;
  if ( a6 >= 1 || a6 <= 4 )
  {
    a1a.spell_caster_pid = PID(OBJECT_Player, a6 - 1);
  }
  else
  {
    a1a.spell_caster_pid = 0;
  }
  result = a1a.Create(0, 0, 0, 0);
  if ( result != -1 )
  {
    result = stru_50FE08.Add(PID(OBJECT_Item, result),
               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(SOUND_Button2, 0, 0, -1, 0, 0, 0, 0);
  pRenderer->DrawTextureTransparent(pBtn_YES->uX, pBtn_YES->uY, pBtn_YES->pTextures[0]);
  pRenderer->Present();
}

//----- (0042FC15) --------------------------------------------------------
void __cdecl CloseWindowBackground()
{
  pAudioPlayer->PlaySound(SOUND_Button2, -2, 0, -1, 0, 0, 0, 0);
  pRenderer->DrawTextureTransparent(pBtn_ExitCancel->uX, pBtn_ExitCancel->uY, pBtn_ExitCancel->pTextures[0]);
  pRenderer->Present();
}

//----- (0042FC4E) --------------------------------------------------------
void __cdecl ProcessInputActions()
{
  char v4; // al@9
  char v8; // bl@100
  unsigned __int16 v9; // ax@102
  int v10; // eax@103
  char v14; // al@159
  unsigned int v15; // eax@168
  PartyAction partyAction; // [sp-14h] [bp-1Ch]@20
  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;


    //  WUT? double event trigger
  /*for ( uint i = 0; i < 30; ++i )
  {
    if ( pKeyActionMap->pToggleTypes[i] )
      v14 = pGame->pKeyboardInstance->WasKeyPressed(pKeyActionMap->pVirtualKeyCodesMapping[i]);
    else
      v14 = pGame->pKeyboardInstance->IsKeyBeingHeld(pKeyActionMap->pVirtualKeyCodesMapping[i]);
    if ( v14 )
    {
      if (pCurrentScreen == SCREEN_GAME)
      {
        pMessageQueue_50CBD0->AddMessage(UIMSG_Game_Action, 0, 0);
        continue;
      }
      if ( pCurrentScreen == SCREEN_NPC_DIALOGUE || pCurrentScreen == SCREEN_BRANCHLESS_NPC_DIALOG )
      {
        v15 = pMessageQueue_50CBD0->uNumMessages;
        if ( pMessageQueue_50CBD0->uNumMessages )
        {
          v15 = 0;
          if ( pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].field_8 )
          {
            v15 = 1;
            pMessageQueue_50CBD0->uNumMessages = 0;
            pMessageQueue_50CBD0->pMessages[v15].eType = UIMSG_Escape;
            pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
            *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
            ++pMessageQueue_50CBD0->uNumMessages;
            continue;
          }
          pMessageQueue_50CBD0->uNumMessages = 0;
        }
        //pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
      }
    }
  }*/
  if ( !pEventTimer->bPaused )
  {
    for ( uint i = 0; i < 30; ++i )
    {
      inputAction = (InputAction)i;
      if ( pKeyActionMap->pToggleTypes[(InputAction)i] )
        v4 = pKeyboard->WasKeyPressed(pKeyActionMap->pVirtualKeyCodesMapping[(InputAction)i]);
      else
        v4 = pKeyboard->IsKeyBeingHeld(pKeyActionMap->pVirtualKeyCodesMapping[(InputAction)i]);
      if ( v4 )
      {
        switch ( inputAction )
        {
          case INPUT_MoveForward:
            if (pCurrentScreen  != SCREEN_GAME)
              break;
            if (!pParty->bTurnBasedModeOn)
            {
              if ( pParty->uFlags2 & PARTY_FLAGS_2_RUNNING)
                partyAction = PARTY_RunForward;
              else
                partyAction = PARTY_WalkForward;
              pPartyActionQueue->Add(partyAction);
              break;
            }
            if (pTurnEngine->field_4 != 1 && pTurnEngine->field_4 != 2 && pTurnEngine->uActionPointsLeft > 0 )
            {
              pTurnEngine->uActionPointsLeft -= 26;
              if ( pParty->uFlags2 & PARTY_FLAGS_2_RUNNING)
                partyAction = PARTY_RunForward;
              else
                partyAction = PARTY_WalkForward;
              pPartyActionQueue->Add(partyAction);
              break;
            }
            break;
          case INPUT_MoveBackwards:
            if (pCurrentScreen  != SCREEN_GAME)
              break;
            if (!pParty->bTurnBasedModeOn)
            {
              if ( pParty->uFlags2 & 2 )
                partyAction = PARTY_RunBackward;
              else
                partyAction = PARTY_WalkBackward;
              pPartyActionQueue->Add(partyAction);
              break;
            }
            if ( pTurnEngine->field_4 != 1 && pTurnEngine->field_4 != 2 && pTurnEngine->uActionPointsLeft > 0 )
            {
              pTurnEngine->uActionPointsLeft -= 26;
              if ( pParty->uFlags2 & 2 )
                partyAction = PARTY_RunBackward;
              else
                partyAction = PARTY_WalkBackward;
              pPartyActionQueue->Add(partyAction);
              break;
            }
            break;
          case INPUT_StrafeLeft:
            if (pCurrentScreen  != SCREEN_GAME)
              break;
            if (!pParty->bTurnBasedModeOn)
            {
              partyAction = PARTY_StrafeLeft;
              pPartyActionQueue->Add(partyAction);
              break;
            }
            if ( pTurnEngine->field_4 == 1 || pTurnEngine->field_4 == 2 || pTurnEngine->uActionPointsLeft <= 0 )
              break;
            pTurnEngine->uActionPointsLeft -= 26;
            partyAction = PARTY_StrafeLeft;
            pPartyActionQueue->Add(partyAction);
            break;
          case INPUT_StrafeRight:
            if (pCurrentScreen != SCREEN_GAME)
              break;
            if (!pParty->bTurnBasedModeOn)
            {
              partyAction = PARTY_StrafeRight;
              pPartyActionQueue->Add(partyAction);
              break;
            }
            if ( pTurnEngine->field_4 == 1 || pTurnEngine->field_4 == 2 || pTurnEngine->uActionPointsLeft <= 0 )
              break;
            pTurnEngine->uActionPointsLeft -= 26;
            partyAction = PARTY_StrafeRight;
            pPartyActionQueue->Add(partyAction);
            break;
          case INPUT_TurnLeft:
            if (pCurrentScreen != SCREEN_GAME)
              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;
            }
            pPartyActionQueue->Add(partyAction);
            if (uCurrentlyLoadedLevelType == LEVEL_Outdoor && pWeather->bRenderSnow)
            {
              pWeather->OnPlayerTurn(10);
            }
            break;
          case INPUT_TurnRight:
            if (pCurrentScreen != SCREEN_GAME)
              break;
            if ( GetAsyncKeyState(17) )         // strafing
            {
              if (pParty->bTurnBasedModeOn)
              {
                if ( pTurnEngine->field_4 == 1 || pTurnEngine->field_4 == 2 || pTurnEngine->uActionPointsLeft <= 0 )
                  break;
                pTurnEngine->uActionPointsLeft -= 26;
              }
              partyAction = PARTY_StrafeRight;
            }
            else
            {
              if ( pParty->uFlags2 & 2 )
                partyAction = PARTY_FastTurnRight;
              else
                partyAction = PARTY_TurnRight;
            }
            pPartyActionQueue->Add(partyAction);
            if (uCurrentlyLoadedLevelType == LEVEL_Outdoor && pWeather->bRenderSnow)
            {
              pWeather->OnPlayerTurn(-10);
            }
            break;
          case INPUT_Jump:
            if (pCurrentScreen != SCREEN_GAME || pParty->bTurnBasedModeOn)
              break;
            partyAction = (PartyAction)12;
            pPartyActionQueue->Add(partyAction);
            break;
          case INPUT_Yell:
            if (!pCurrentScreen && uActiveCharacter)
            {
              pParty->Yell();
              pPlayers[uActiveCharacter]->PlaySound(SPEECH_Yell, 0);
            }
          break;
          case INPUT_Pass:
            if ( pCurrentScreen )
              break;
            if (pParty->bTurnBasedModeOn && pTurnEngine->field_4 == 3)
            {
              pTurnEngine->field_18 |= 8u;
              break;
            }
            if ( uActiveCharacter )
            {
              if ( !pPlayers[uActiveCharacter]->uTimeToRecovery )
              {
                v24 = pPlayers[uActiveCharacter]->GetAttackRecoveryTime(false);
                if ( !pParty->bTurnBasedModeOn )
                  pPlayers[uActiveCharacter]->SetRecoveryTime((signed __int64)(flt_6BE3A4_debug_recmod1 * (double)v24 * 2.133333333333333));
                pCastSpellInfo.data()->_427D48(uActiveCharacter);
                pTurnEngine->_40471C();
              }
            }
            break;
          case INPUT_Combat://if press ENTER
            if (pCurrentScreen == SCREEN_GAME)
            {
              if (pParty->bTurnBasedModeOn)
              {
                if (pTurnEngine->field_4 == OBJECT_Actor || PID_TYPE(pTurnEngine->pQueue[0].uPackedID) == OBJECT_Player)
                {
                  pParty->bTurnBasedModeOn = 0;
                  pTurnEngine->End(true);
                }
              }
              else
              {
                pTurnEngine->Start();
                pParty->bTurnBasedModeOn = true;
              }
            }
            break;
          case INPUT_CastReady:
            if (pCurrentScreen != SCREEN_GAME)
              break;
            if (pParty->bTurnBasedModeOn && pTurnEngine->field_4 == 3)
            {
              pTurnEngine->field_18 |= 8u;
              break;
            }
            if ( !uActiveCharacter )
              break;
            v8 = pPlayers[uActiveCharacter]->uQuickSpell;
            if ( !v8
              || bUnderwater
              || ((v9 = pPlayers[uActiveCharacter]->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 > pPlayers[uActiveCharacter]->sMana) )
            {
              pPartyActionQueue = pPartyActionQueue;
              pMessageQueue_50CBD0->AddMessage(UIMSG_Attack, 0, 0);
              break;
            }
            else
            {
            pMessageQueue_50C9E8->AddMessage(UIMSG_CastQuickSpell, 0, 0);
            }
            break;
          case INPUT_Attack:
            if (pCurrentScreen != SCREEN_GAME)
              break;
            if (pParty->bTurnBasedModeOn == 1 && pTurnEngine->field_4 == 3)
            {
              pTurnEngine->field_18 |= 8u;
              break;
            }
            pMessageQueue_50CBD0->AddMessage(UIMSG_Attack, 0, 0);
            break;
          case INPUT_EventTrigger:
            if (pCurrentScreen == SCREEN_GAME)
            {
              pMessageQueue_50CBD0->AddMessage(UIMSG_Game_Action, 0, 0);
              break;
            }
            if ( pCurrentScreen == SCREEN_NPC_DIALOGUE )
            {
              if ( pMessageQueue_50CBD0->uNumMessages )
              {
                pMessageQueue_50CBD0->uNumMessages = 0;
                if ( pMessageQueue_50CBD0->pMessages[0].field_8 )
                {
                  pMessageQueue_50CBD0->uNumMessages = 1;
                  pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
                  pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
                  *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
                  ++pMessageQueue_50CBD0->uNumMessages;
                  break;
                }
                break;
              }
              pMessageQueue_50CBD0->AddMessage(UIMSG_Escape, 0, 0);
            }
            break;
          case INPUT_CharCycle:
            if ( pCurrentScreen == SCREEN_SPELL_BOOK  )
              break;
           /* dword_50C9EC[3 * dword_50C9E8] = 176;|| dword_50C9E8 >= 40
            dword_50C9EC[3 * dword_50C9E8 + 1] = 0;
            dword_50C9EC[3 * dword_50C9E8 + 2] = 0;
            ++dword_50C9E8;*/
            pMessageQueue_50C9E8->AddMessage(UIMSG_CycleCharacters, 0, 0);
            break;
          case INPUT_LookUp:
            if ( pEventTimer->bPaused )
              break;
            partyAction = (PartyAction)7;
            pPartyActionQueue->Add(partyAction);
            break;
          case INPUT_CenterView:
            if ( pEventTimer->bPaused )
              break;
            partyAction = (PartyAction)9;
            pPartyActionQueue->Add(partyAction);
            break;
          case INPUT_LookDown:
            if ( pEventTimer->bPaused )
              break;
            partyAction = (PartyAction)8;
            pPartyActionQueue->Add(partyAction);
            break;
          case INPUT_FlyUp:
            if ( pCurrentScreen || pEventTimer->bPaused )
              break;
            partyAction = (PartyAction)13;
            pPartyActionQueue->Add(partyAction);
            break;
          case INPUT_Land:
            if ( pCurrentScreen || pEventTimer->bPaused )
              break;
            partyAction = (PartyAction)15;
            pPartyActionQueue->Add(partyAction);
            break;
          case INPUT_FlyDown:
            if ( !pCurrentScreen
              && !pEventTimer->bPaused )
            {
              partyAction = (PartyAction)14;
              pPartyActionQueue->Add(partyAction);
            }
            break;
          case INPUT_ZoomIn:
            /*if ( dword_50C9E8 >= 40 )
              break;
            dword_50C9EC[3 * dword_50C9E8] = 367;
            dword_50C9EC[3 * dword_50C9E8 + 1] = 0;
            dword_50C9EC[3 * dword_50C9E8 + 2] = 0;
            ++dword_50C9E8;*/
              pMessageQueue_50C9E8->AddMessage(UIMSG_ClickZoomOutBtn, 0, 0);
            break;
          case INPUT_ZoomOut:
            /*if ( dword_50C9E8 < 40 )
            {
              dword_50C9EC[3 * dword_50C9E8] = 368;
              dword_50C9EC[3 * dword_50C9E8 + 1] = 0;
              dword_50C9EC[3 * dword_50C9E8 + 2] = 0;
              ++dword_50C9E8;
            }*/
              pMessageQueue_50C9E8->AddMessage(UIMSG_ClickZoomInBtn, 0, 0);
            break;
          case INPUT_AlwaysRun:
            bAlwaysRun = bAlwaysRun == 0;
            break;
          default:
            break;
        }
      }
    }
  }
}