view Spells.cpp @ 362:38bfbee60146

Menu options
author Ritor1
date Fri, 22 Feb 2013 01:28:48 +0600
parents b07cf89108d5
children 2bc1c8d68f41
line wrap: on
line source

#include <stdlib.h>

#include "Spells.h"
#include "Overlays.h"
#include "Allocator.h"
#include "LOD.h"
#include "stru123.h"
#include "texts.h"

#include "mm7_data.h"





struct SpellStats *pSpellStats;


stru324_spell stru_4E3ACC[102];

SpellData pSpellDatas[100]={
					 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},	
					 {1, 1, 1, 1, 60, 60, 60, 40, 0, 0},
	                 {2, 2, 2, 2, 110, 110, 100, 90, 768, 0},
	                 {3, 3, 3, 3, 120, 120, 120, 120, 0, 0},
	                 {4, 4, 4, 4, 120, 120, 120, 120, 0, 0},
	                 {5, 5, 5, 5, 120, 120, 120, 120, 0, 0},
	                 {8, 8, 8, 8, 100, 100, 90, 80, 1536, 0},
	                 {10, 10, 10, 10, 150, 150, 150, 150, 1536, 0},
	                 {15, 15, 15, 15, 120, 120, 120, 120, 1536, 0},
	                 {20, 20, 20, 20, 100, 100, 100, 90, 264, 0},
	                 {25, 25, 25, 25, 100, 100, 100, 90, 268, 0},
	                 {30, 30, 30, 30, 90, 90, 90, 90, 3855, 0},
	                 {1, 1, 1, 0, 60, 60, 60, 60, 0, 0},
	                 {2, 2, 2, 2, 120, 120, 120, 100, 0, 0},
	                 {3, 3, 3, 3, 120, 120, 120, 120, 0, 0},
	                 {4, 4, 4, 4, 110, 100, 90, 80, 258, 0},
	                 {5, 5, 5, 5,  90, 90,  70, 50, 0, 0},
	                 {8, 8, 8, 8, 120, 120, 120, 120, 0, 0},
	                 {10, 10, 10, 10, 100, 100, 90, 70, 2048, 0},
	                 {15, 15, 15, 15, 200, 200, 200, 200, 0, 0},
	                 {20, 20, 20, 20, 100, 100, 100, 90, 2570, 0},
	                 {25, 25, 25, 25, 250, 250, 250, 250, 0, 0},
	                 {30, 30, 30, 30, 90, 90, 90, 90, 276, 0},
	                 {1, 1, 1, 1, 60, 60, 60, 20, 0, 0},
	                 {2, 2, 2, 2, 110, 100, 90, 70, 514, 0},
	                 {3, 3, 3, 3, 120, 120, 120, 120, 0, 0},
	                 {4, 4, 4, 4, 110, 100, 90, 80, 1024, 0},
	                 {5, 5, 5, 5, 150, 150, 150, 150, 0, 0},
	                 {8, 8, 8, 8, 200, 200, 200, 200, 0, 0},
	                 {10, 10, 10, 10, 100, 100, 90, 80, 2313, 0},
	                 {15, 15, 15, 15, 140, 140, 140, 140, 0, 0},
	                 {20, 20, 20, 20, 200, 200, 200, 200, 0, 0},
	                 {25, 25, 25, 25, 80, 80, 80, 80, 780, 0},
	                 {30, 30, 30, 30, 250, 250, 250, 250, 0, 0},
	                 {1, 1, 1, 1, 80, 80, 80, 80, 0, 0},
	                 {2, 2, 2, 2, 100, 100, 100, 100, 0, 0},
	                 {3, 3, 3, 3, 120, 120, 120, 120, 0, 0},
	                 {4, 4, 4, 4, 110, 100, 90, 80, 773, 0},
	                 {5, 5, 5, 5, 120, 120, 120, 120, 0, 0},
	                 {8, 8, 8, 8, 100, 100, 90, 80, 2304, 0},
	                 {10, 10, 10, 10, 140, 140, 140, 140, 0, 0},
	                 {15, 15, 15, 15, 90, 90, 90, 80, 2048, 0},
	                 {20, 20, 20, 20, 150, 150, 150, 150, 0, 0},
	                 {25, 25, 25, 25, 100, 100, 100, 90, 276, 0},
	                 {30, 30, 30, 30, 90, 90, 90, 90, 25, 0},
	                 {1, 1, 1, 1, 100, 100, 100, 100, 0, 0},
	                 {2, 2, 2, 2, 100, 100, 100, 100, 0, 0},
	                 {3, 3, 3, 3, 90, 90, 90, 90, 0, 0},
	                 {4, 4, 4, 4, 120, 120, 120, 120, 0, 0},
	                 {5, 5, 5, 5, 120, 120, 120, 120, 0, 0},
	                 {8, 8, 8, 8, 120, 120, 120, 120, 0, 0},
	                 {10, 10, 10, 10, 120, 120, 120, 120, 0, 0},
	                 {15, 15, 15, 15, 100, 100, 100, 100, 2058, 0},
	                 {20, 20, 20, 20, 240, 240, 240, 240, 0, 0},
	                 {25, 25, 25, 25, 150, 150, 150, 150, 0, 0},
	                 {30, 30, 30, 30, 1000, 1000, 1000, 1000, 0, 0},
	                 {1, 1, 1, 1, 120, 120, 120, 120, 0, 0},
	                 {2, 2, 2, 2, 110, 110, 110, 110, 771, 0},
	                 {3, 3, 3, 3, 120, 120, 120, 120, 0, 0},
	                 {4, 4, 4, 4, 110, 100, 90, 80, 0, 0},
	                 {5, 5, 5, 5, 100, 100, 100, 100, 0, 0},
	                 {8, 8, 8, 8, 120, 120, 120, 120, 0, 0},
	                 {10, 10, 10, 10, 120, 120, 120, 120, 0, 0},
	                 {15, 15, 15, 15, 80, 80, 80, 80, 0, 0},
	                 {20, 20, 20, 20, 120, 120, 120, 120, 0, 0},
	                 {25, 25, 25, 25, 110, 110, 110, 100, 268, 0},
	                 {30, 30, 30, 30, 120, 120, 120, 120, 0, 0},
	                 {1, 1, 1, 1, 120, 120, 120, 120, 0, 0},
	                 {2, 2, 2, 2, 100, 100, 100, 100, 0, 0},
	                 {3, 3, 3, 3, 120, 120, 120, 120, 0, 0},
	                 {4, 4, 4, 4, 110, 100, 90, 80, 520, 0},
	                 {5, 5, 5, 5, 110, 110, 110, 110, 0, 0},
	                 {8, 8, 8, 8, 120, 120, 120, 120, 0, 0},
	                 {10, 10, 10, 10, 120, 120, 120, 120, 0, 0},
	                 {15, 15, 15, 15, 120, 120, 120, 120, 0, 0},
	                 {20, 20, 20, 20, 120, 120, 120, 120, 0, 0},
	                 {25, 25, 25, 25, 110, 110, 110, 100, 1310, 0},
	                 {30, 30, 30, 30, 100, 100, 100, 100, 0, 0},
	                 {5, 5, 5, 5, 110, 100, 90, 80, 1024, 0},
	                 {10, 10, 10, 10, 120, 110, 100, 90, 4112, 0},
	                 {15, 15, 15, 15, 120, 110, 100, 90, 0, 0},
	                 {20, 20, 20, 20, 160, 140, 120, 100, 0, 0},
	                 {25, 25, 25, 25, 140, 140, 140, 140, 0, 0},
	                 {30, 30, 30, 30, 500, 500, 500, 500, 0, 0},
	                 {35, 35, 35, 35, 135, 135, 120, 100, 281, 0},
	                 {40, 40, 40, 40, 500, 500, 500, 500, 0, 0},
	                 {45, 45, 45, 45, 250, 250, 250, 250, 0, 0},
	                 {50, 50, 50, 50, 150, 150, 150, 135, 5140, 0},
	                 {55, 55, 55, 55, 300, 300, 300, 300, 0, 0},
	                 {10, 10, 10, 10, 140, 140, 140, 140, 0, 0},
	                 {15, 15, 15, 15, 120, 110, 100, 90, 2585, 0},
	                 {20, 20, 20, 20, 120, 100, 90, 120, 0, 0},
	                 {25, 25, 25, 25, 120, 120, 120, 120, 0, 0},
	                 {30, 30, 30, 30, 90, 90, 80, 70, 1542, 0},
	                 {35, 35, 35, 35, 120, 120, 100, 80, 0, 0},
	                 {40, 40, 40, 40, 110, 110, 110, 110, 0, 0},
	                 {45, 45, 45, 45, 200, 200, 200, 150, 0, 0},
	                 {50, 50, 50, 50, 120, 120, 120, 100, 6400, 0},
	                 {55, 55, 55, 55, 250, 250, 250, 250, 306, 0},
	                 {60, 60, 60, 60, 300, 300, 300, 300, 2073, 0}
	};

	unsigned char pSpellbookSpellIndices[9][12] = // 4E2430
	{
		{0,  3,  1,  8, 11,  7,  4, 10,  6,  2,  5,  9},
		{0, 11,  2,  9,  6,  8,  5, 10,  3,  7,  1,  4},
		{0,  4,  8,  9,  1, 10,  3, 11,  7,  6,  2,  5}, 
		{0,  7, 10,  8,  2, 11,  1,  5,  3,  6,  4,  9},
		{0,  5, 10, 11,  7,  2,  8,  1,  4,  9,  3,  6},
		{0,  5,  9,  8,  3,  7,  6,  4,  1, 11,  2, 10}, 
		{0,  1,  6,  9,  3,  5,  8, 11,  7, 10,  4,  2},
		{0,  1, 10, 11,  9,  4,  3,  6,  5,  7,  8,  2},
		{0,  9,  3,  7,  1,  5,  2, 10, 11,  8,  6,  4}
	};

	struct SpellBookIconPos pIconPos[108]={
		{0, 0},          
		{17, 13},
		{115, 2},
		{217, 15},
		{299, 6},
		{28, 125},
		{130, 133},
		{294, 114},
		{11, 232},
		{134, 233},
		{237, 171},
		{296, 231},

		{0, 0},
		{19, 9},
		{117, 3},
		{206, 13},
		{285, 7},
		{16, 123},
		{113, 101},
		{201, 118},
		{317, 110},
		{11, 230},
		{149, 236},
		{296, 234},

		{0, 0},
		{17, 9},
		{140, 0},
		{210, 34},
		{293, 5},
		{15, 98},
		{78, 121},
		{175, 136},
		{301, 115},
		{15, 226},
		{154, 225},
		{272, 220},

		{0, 0},
		{7, 9},
		{156, 2},
		{277, 9},
		{11, 117},
		{111, 82},
		{180, 102},
		{303, 108},
		{10, 229},
		{120, 221},
		{201, 217},
		{296, 225},

		{0, 0},
		{18, 8},
		{89, 15},
		{192, 14},
		{292, 7},
		{22, 129},
		{125, 146},
		{217, 136},
		{305, 115},
		{22, 226},
		{174, 237},
		{290, 231},

		{0, 0},
		{18, 12},
		{148, 9},
		{292, 7},
		{17, 122},
		{121, 99},
		{220, 87},
		{293, 112},
		{13, 236},
		{128, 213},
		{220, 223},
		{315, 223},

		{0, 0},
		{23, 14},
		{127, 8},
		{204, 0},
		{306, 8},
		{14, 115},
		{122, 132},
		{200, 116},
		{293, 122},
		{20, 228},
		{154, 228},
		{294, 239},

		{0, 0},
		{19, 14},
		{124, 10},
		{283, 12},
		{8, 105},
		{113, 89},
		{190, 82},
		{298, 108},
		{18, 181},
		{101, 204},
		{204, 203},
		{285, 218},

		{0, 0},
		{18, 17},
		{110, 16},
		{201, 15},
		{307, 15},
		{18, 148},
		{125, 166},
		{201, 123},
		{275, 120},
		{28, 235},
		{217, 222},
		{324, 216} };


//----- (0042EB31) --------------------------------------------------------
bool SpellBuff::NotExpired()
{
  return (signed __int64)this->uExpireTime > 0 ? true:false;
}


//----- (00458585) --------------------------------------------------------
void SpellBuff::Reset()
{
  SpellBuff *v1; // esi@1
  unsigned __int16 v2; // ax@1

  this->uSkill = 0;
  this->uPower = 0;
  this->uExpireTime = 0i64;
  this->uCaster = 0;
  this->uFlags = 0;
  if ( this->uOverlayID )
  {
    ((OtherOverlay *)&stru_5E4C90._decor_events[20 * this->uOverlayID + 105])->Reset();
    pOtherOverlayList->bRedraw = true;
    this->uOverlayID = 0;
  }
}

//----- (004585CA) --------------------------------------------------------
signed int SpellBuff::_4585CA(__int64 a2)
{
  signed int result; // eax@3

  if ( this->uExpireTime && (signed __int64)this->uExpireTime < a2 )
  {
    this->uExpireTime = 0i64;
    this->uPower = 0;
    this->uSkill = 0;
    this->uOverlayID = 0;
    result = 1;
  }
  else
  {
    result = 0;
  }
  return result;
}

//----- (004584E0) --------------------------------------------------------
signed int SpellBuff::Apply(unsigned __int64 uExpireTime, unsigned __int16 uSkillLevel, unsigned __int16 uPower, int a5, unsigned __int8 a6)
{
  SpellBuff *v6; // esi@1
  signed int result; // eax@3
  int v8; // eax@4

  v6 = this;
  if ( this->uExpireTime && (signed __int64)uExpireTime < (signed __int64)this->uExpireTime )
  {
    result = 0;
  }
  else
  {
    this->uSkill = uSkillLevel;
    this->uPower = uPower;
    LOWORD(v8) = this->uOverlayID;
    this->uExpireTime = uExpireTime;
    if ( (short)v8 )
    {
      v8 = (unsigned __int16)v8;
      if ( (unsigned __int16)v8 != a5 )
      {
        ((OtherOverlay *)&stru_5E4C90._decor_events[20 * v8 + 105])->Reset();
        pOtherOverlayList->bRedraw = true;
        v6->uOverlayID = 0;
      }
    }
    v6->uOverlayID = a5;
    v6->uCaster = a6;
    result = 1;
  }
  return result;
}

//----- (0045384A) --------------------------------------------------------
void SpellStats::Initialize()
	{

	int decode_step;
	char* test_string;
	bool break_loop;
	unsigned char c;
	unsigned int temp_str_len;
	char* tmp_pos;

	if ( pSpellsTXT_Raw )
		pAllocator->FreeChunk(pSpellsTXT_Raw);
	pSpellsTXT_Raw = NULL;

	pSpellsTXT_Raw = (char *)pEvents_LOD->LoadRaw("spells.txt", 0);
	strtok(pSpellsTXT_Raw, "\r");
	strtok(NULL, "\r");
	for(int i=1; i<100; ++i) 
		{
		test_string=strtok(NULL, "\r")+1;
		decode_step =0;
		break_loop=false;
		do 
			{
			c = *(unsigned char*)test_string;
			temp_str_len = 0;
			while((c!='\t')&&(c>0))
				{
				++temp_str_len;
				c=test_string[temp_str_len];
				}		
			tmp_pos=test_string+temp_str_len;
			if (*tmp_pos == 0)
				break_loop = true;
			*tmp_pos = 0;
			if (temp_str_len)
				{		
				switch (decode_step)
					{	
				case 2:
					pInfos[i].pName=RemoveQuotes(test_string);
					break;
				case 3:
					pInfos[i].uSchool = SPELL_SCHOOL_NONE;
					if (!_strcmpi("fire", test_string) )
						{
						pInfos[i].uSchool =SPELL_SCHOOL_FIRE;
						break;
						}
					if ( !_strcmpi("air", test_string) )	
						{
						pInfos[i].uSchool = SPELL_SCHOOL_AIR;
						break;
						}
					if ( !_strcmpi("water", test_string))	
						{
						pInfos[i].uSchool = SPELL_SCHOOL_WATER;
						break;
						}	
					if ( !_strcmpi("earth", test_string))	
						{
						pInfos[i].uSchool = SPELL_SCHOOL_EARTH;
						break;
						}	
					if ( !_strcmpi("spirit", test_string))	
						{
						pInfos[i].uSchool = SPELL_SCHOOL_SPIRIT;
						break;
						}
					if ( !_strcmpi("mind", test_string))	
						{
						pInfos[i].uSchool = SPELL_SCHOOL_MIND;
						break;
						}
					if ( !_strcmpi("body", test_string) )	
						{
						pInfos[i].uSchool = SPELL_SCHOOL_BODY;
						break;
						}			
					if ( !_strcmpi("light", test_string) )	
						{
						pInfos[i].uSchool =  SPELL_SCHOOL_LIGHT;
						break;
						}					
					if ( !_strcmpi("dark", test_string))	
						{
						pInfos[i].uSchool = SPELL_SCHOOL_DARK;
						break;
						}					

					if ( !_strcmpi("magic", test_string))	
						{
						pInfos[i].uSchool = SPELL_SCHOOL_MAGIC;
						break;
						}								
					break;
				case 4:
					pInfos[i].pShortName=RemoveQuotes(test_string);
					break;
				case 5:
					pInfos[i].pDescription=RemoveQuotes(test_string);
					break;
				case 6:
					pInfos[i].pBasicSkillDesc=RemoveQuotes(test_string);
					break;
				case 7:
					pInfos[i].pExpertSkillDesc=RemoveQuotes(test_string);
					break;
				case 8:
					pInfos[i].pMasterSkillDesc=RemoveQuotes(test_string);
					break;
				case 9:
					pInfos[i].pGrandmasterSkillDesc=RemoveQuotes(test_string);
					break;
				case 10:
					int in_string_pos=0;
					unsigned char test;
					int in_str_len=strlen(test_string);
					for (int j=0; j<in_str_len; ++j)
						{
							test= tolower(test_string[j]);
							switch (test)
							{
							case 109:
								pSpellDatas[i].field_12|=1;
								break;
							case 101:
								pSpellDatas[i].field_12|=2;
								break;
							case 99:
								pSpellDatas[i].field_12|=4;
								break;
							case 120:
								pSpellDatas[i].field_12|=8;
								break;
							}					
						}
					break;
					}
				}
			else
				break_loop=true;
			++decode_step;
			test_string=tmp_pos+1;	
			} while ((decode_step<11)&&!break_loop);
			if ((i%11)==0)
				strtok(NULL, "\r");
		}

	}