view Spells.cpp @ 209:29545d87e11d

m
author Ritor1
date Sat, 16 Feb 2013 16:23:07 +0600
parents 4813b57396ba
children fcdb80fc1f74
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[95];






//----- (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");
	//v14 = 1;
	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 = 4;
					if (!_strcmpi("fire", test_string) )
						{
						pInfos[i].uSchool =0;
						break;
						}
					if ( !_strcmpi("air", test_string) )	
						{
						pInfos[i].uSchool = 1;
						break;
						}
					if ( !_strcmpi("water", test_string))	
						{
						pInfos[i].uSchool = 2;
						break;
						}	
					if ( !_strcmpi("earth", test_string))	
						{
						pInfos[i].uSchool = 3;
						break;
						}	
					if ( !_strcmpi("spirit", test_string))	
						{
						pInfos[i].uSchool = 6;
						break;
						}
					if ( !_strcmpi("mind", test_string))	
						{
						pInfos[i].uSchool = 7;
						break;
						}
					if ( !_strcmpi("body", test_string) )	
						{
						pInfos[i].uSchool = 8;
						break;
						}			
					if ( !_strcmpi("light", test_string) )	
						{
						pInfos[i].uSchool = 9;
						break;
						}					
					if ( !_strcmpi("dark", test_string))	
						{
						pInfos[i].uSchool = 10;
						break;
						}					

					if ( !_strcmpi("magic", test_string))	
						{
						pInfos[i].uSchool = 5;
						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;
					int in_str_len=strlen(test_string);
					/*v4 = 0; fix_me
					v8 = strlen(v5);
					if ( (signed int)v8 > 0 )
					{
					do
					{
					v9 = tolower((unsigned __int8)v5[v4]) - 99;
					if ( v9 )
					{
					v10 = v9 - 2;
					if ( v10 )
					{
					v11 = v10 - 8;
					if ( v11 )
					{
					if ( v11 == 11 )
					*v12 |= 8u;
					}
					else
					{
					*v12 |= 1u;
					}
					}
					else
					{
					*v12 |= 2u;
					}
					}
					else
					{
					*v12 |= 4u;
					}
					++v4;
					}
					while ( v4 < (signed int)v8 );*/
					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");
		}

	}