| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 | 
							- #include "stdafx.h"
 
- #include "CHeroHandler.h"
 
- #include "CGameInfo.h"
 
- #include <sstream>
 
- #define CGI (CGameInfo::mainObj)
 
- CHeroHandler::~CHeroHandler()
 
- {
 
- 	for (int j=0;j<heroes.size();j++)
 
- 	{
 
- 		if (heroes[j]->portraitSmall)
 
- 			SDL_FreeSurface(heroes[j]->portraitSmall);
 
- 		delete heroes[j];
 
- 	}
 
- }
 
- void CHeroHandler::loadPortraits()
 
- {
 
- 	std::ifstream of("portrety.txt");
 
- 	for (int j=0;j<heroes.size();j++)
 
- 	{
 
- 		int ID;
 
- 		of>>ID;
 
- 		std::string path;
 
- 		of>>path;
 
- 		heroes[ID]->portraitSmall=CGI->bitmaph->loadBitmap(path);
 
- 		if (!heroes[ID]->portraitSmall)
 
- 			std::cout<<"Can't read portrait for "<<ID<<" ("<<path<<")\n";
 
- 	}
 
- 	of.close();
 
- }
 
- void CHeroHandler::loadHeroes()
 
- {
 
- 	int ID=0;
 
- 	std::ifstream inp("H3bitmap.lod\\HOTRAITS.TXT", std::ios::in);
 
- 	std::string dump;
 
- 	for(int i=0; i<25; ++i)
 
- 	{
 
- 		inp>>dump;
 
- 	}
 
- 	inp.ignore();
 
- 	int numberOfCurrentClassHeroes = 0;
 
- 	int currentClass = 0;
 
- 	int additHero = 0;
 
- 	EHeroClasses addTab[12];
 
- 	addTab[0] = HERO_KNIGHT;
 
- 	addTab[1] = HERO_WITCH;
 
- 	addTab[2] = HERO_KNIGHT;
 
- 	addTab[3] = HERO_WIZARD;
 
- 	addTab[4] = HERO_RANGER;
 
- 	addTab[5] = HERO_BARBARIAN;
 
- 	addTab[6] = HERO_DEATHKNIGHT;
 
- 	addTab[7] = HERO_WARLOCK;
 
- 	addTab[8] = HERO_KNIGHT;
 
- 	addTab[9] = HERO_WARLOCK;
 
- 	addTab[10] = HERO_BARBARIAN;
 
- 	addTab[11] = HERO_DEMONIAC;
 
- 	while(!inp.eof())
 
- 	{
 
- 		CHero * nher = new CHero;
 
- 		if(currentClass<18)
 
- 		{
 
- 			nher->heroType = (EHeroClasses)currentClass;
 
- 			++numberOfCurrentClassHeroes;
 
- 			if(numberOfCurrentClassHeroes==8)
 
- 			{
 
- 				numberOfCurrentClassHeroes = 0;
 
- 				++currentClass;
 
- 			}
 
- 		}
 
- 		else
 
- 		{
 
- 			nher->heroType = addTab[additHero++];
 
- 		}
 
- 		std::string base;
 
- 		char * tab = new char[500];
 
- 		int iit = 0;
 
- 		inp.getline(tab, 500);
 
- 		base = std::string(tab);
 
- 		if(base.size()<2) //ended, but some rubbish could still stay end we have something useless
 
- 		{
 
- 			loadSpecialAbilities();
 
- 			loadBiographies();
 
- 			loadHeroClasses();
 
- 			initHeroClasses();
 
- 			inp.close();
 
- 			return;
 
- 		}
 
- 		while(base[iit]!='\t')
 
- 		{
 
- 			++iit;
 
- 		}
 
- 		nher->name = base.substr(0, iit);
 
- 		++iit;
 
- 		for(int i=iit; i<iit+100; ++i)
 
- 		{
 
- 			if(base[i]==(char)(10) || base[i]==(char)(9))
 
- 			{
 
- 				nher->low1stack = atoi(base.substr(iit, i).c_str());
 
- 				iit=i+1;
 
- 				break;
 
- 			}
 
- 		}
 
- 		for(int i=iit; i<iit+100; ++i)
 
- 		{
 
- 			if(base[i]==(char)(10) || base[i]==(char)(9))
 
- 			{
 
- 				nher->high1stack = atoi(base.substr(iit, i).c_str());
 
- 				iit=i+1;
 
- 				break;
 
- 			}
 
- 		}
 
- 		int ipom=iit;
 
- 		while(base[ipom]!='\t')
 
- 		{
 
- 			++ipom;
 
- 		}
 
- 		nher->refType1stack = base.substr(iit, ipom-iit);
 
- 		iit=ipom+1;
 
- 		for(int i=iit; i<iit+100; ++i)
 
- 		{
 
- 			if(base[i]==(char)(10) || base[i]==(char)(9))
 
- 			{
 
- 				nher->low2stack = atoi(base.substr(iit, i-iit).c_str());
 
- 				iit=i+1;
 
- 				break;
 
- 			}
 
- 		}
 
- 		for(int i=iit; i<iit+100; ++i)
 
- 		{
 
- 			if(base[i]==(char)(10) || base[i]==(char)(9))
 
- 			{
 
- 				nher->high2stack = atoi(base.substr(iit, i-iit).c_str());
 
- 				iit=i+1;
 
- 				break;
 
- 			}
 
- 		}
 
- 		ipom=iit;
 
- 		while(base[ipom]!='\t')
 
- 		{
 
- 			++ipom;
 
- 		}
 
- 		nher->refType2stack = base.substr(iit, ipom-iit);
 
- 		iit=ipom+1;
 
- 		for(int i=iit; i<iit+100; ++i)
 
- 		{
 
- 			if(base[i]==(char)(10) || base[i]==(char)(9))
 
- 			{
 
- 				nher->low3stack = atoi(base.substr(iit, i-iit).c_str());
 
- 				iit=i+1;
 
- 				break;
 
- 			}
 
- 		}
 
- 		for(int i=iit; i<iit+100; ++i)
 
- 		{
 
- 			if(base[i]==(char)(10) || base[i]==(char)(9))
 
- 			{
 
- 				nher->high3stack = atoi(base.substr(iit, i-iit).c_str());
 
- 				iit=i+1;
 
- 				break;
 
- 			}
 
- 		}
 
- 		nher->refType3stack = base.substr(iit, base.size()-iit);
 
- 		nher->ID=ID++;
 
- 		heroes.push_back(nher);
 
- 		delete[500] tab;
 
- 	}
 
- 	loadSpecialAbilities();
 
- }
 
- void CHeroHandler::loadSpecialAbilities()
 
- {
 
- 	std::ifstream inp("H3bitmap.lod\\HEROSPEC.txt", std::ios::in);
 
- 	std::string dump;
 
- 	for(int i=0; i<7; ++i)
 
- 	{
 
- 		inp>>dump;
 
- 	}
 
- 	inp.ignore();
 
- 	int whHero=0;
 
- 	while(!inp.eof() && whHero<heroes.size())
 
- 	{
 
- 		std::string base;
 
- 		char * tab = new char[500];
 
- 		int iitBef = 0;
 
- 		int iit = 0;
 
- 		inp.getline(tab, 500);
 
- 		base = std::string(tab);
 
- 		if(base.size()<2) //ended, but some rubbish could still stay end we have something useless
 
- 		{
 
- 			inp.close();
 
- 			return; //add counter
 
- 		}
 
- 		while(base[iit]!='\t')
 
- 		{
 
- 			++iit;
 
- 		}
 
- 		heroes[whHero]->bonusName = base.substr(0, iit);
 
- 		++iit;
 
- 		iitBef=iit;
 
- 		if(heroes[whHero]->bonusName == std::string("Ogry"))
 
- 		{
 
- 			char * tab2 = new char[500];
 
- 			inp.getline(tab2, 500);
 
- 			base += std::string(tab2);
 
- 			delete [500] tab2;
 
- 		}
 
- 		while(base[iit]!='\t')
 
- 		{
 
- 			++iit;
 
- 		}
 
- 		heroes[whHero]->shortBonus = base.substr(iitBef, iit-iitBef);
 
- 		++iit;
 
- 		iitBef=iit;
 
- 		while(base[iit]!='\t' && iit<base.size())
 
- 		{
 
- 			++iit;
 
- 		}
 
- 		heroes[whHero]->longBonus = base.substr(iitBef, iit-iitBef);
 
- 		++whHero;
 
- 		delete [500] tab;
 
- 	}
 
- 	inp.close();
 
- }
 
- void CHeroHandler::loadBiographies()
 
- {
 
- 	std::ifstream inp("H3bitmap.lod\\HEROBIOS.TXT", std::ios::in | std::ios::binary);
 
- 	inp.seekg(0,std::ios::end); // na koniec
 
- 	int andame = inp.tellg();  // read length
 
- 	inp.seekg(0,std::ios::beg); // wracamy na poczatek
 
- 	char * bufor = new char[andame]; // allocate memory 
 
- 	inp.read((char*)bufor, andame); // read map file to buffer
 
- 	inp.close();
 
- 	std::string buf = std::string(bufor);
 
- 	delete [andame] bufor;
 
- 	int i = 0; //buf iterator
 
- 	for(int q=0; q<heroes.size(); ++q)
 
- 	{
 
- 		int befi=i;
 
- 		for(i; i<andame; ++i)
 
- 		{
 
- 			if(buf[i]=='\r')
 
- 				break;
 
- 		}
 
- 		heroes[q]->biography = buf.substr(befi, i-befi);
 
- 		i+=2;
 
- 	}
 
- }
 
- void CHeroHandler::loadHeroClasses()
 
- {
 
- 	//std::ifstream inp("H3bitmap.lod\\HCTRAITS.TXT", std::ios::in | std::ios::binary);
 
- 	//inp.seekg(0,std::ios::end); // na koniec
 
- 	//int andame = inp.tellg();  // read length
 
- 	//inp.seekg(0,std::ios::beg); // wracamy na poczatek
 
- 	//char * bufor = new char[andame]; // allocate memory 
 
- 	//inp.read((char*)bufor, andame); // read map file to buffer
 
- 	//inp.close();
 
- 	//std::string buf = std::string(bufor);
 
- 	//delete [andame] bufor;
 
- 	std::string buf = CGameInfo::mainObj->bitmaph->getTextFile("HCTRAITS.TXT");
 
- 	int andame = buf.size();
 
- 	for(int y=0; y<andame; ++y)
 
- 		if(buf[y]==',')
 
- 			buf[y]='.';
 
- 	int i = 0; //buf iterator
 
- 	int hmcr = 0;
 
- 	for(i; i<andame; ++i) //omitting rubbish
 
- 	{
 
- 		if(buf[i]=='\r')
 
- 			++hmcr;
 
- 		if(hmcr==2)
 
- 			break;
 
- 	}
 
- 	i+=2;
 
- 	for(int ss=0; ss<18; ++ss) //18 classes of hero (including conflux)
 
- 	{
 
- 		CHeroClass * hc = new CHeroClass;
 
- 		int befi=i;
 
- 		for(i; i<andame; ++i)
 
- 		{
 
- 			if(buf[i]=='\t')
 
- 				break;
 
- 		}
 
- 		hc->name = buf.substr(befi, i-befi);
 
- 		++i;
 
- 		befi=i;
 
- 		for(i; i<andame; ++i)
 
- 		{
 
- 			if(buf[i]=='\t')
 
- 				break;
 
- 		}
 
- 		hc->aggression = atof(buf.substr(befi, i-befi).c_str());
 
- 		++i;
 
- 		befi=i;
 
- 		for(i; i<andame; ++i)
 
- 		{
 
- 			if(buf[i]=='\t')
 
- 				break;
 
- 		}
 
- 		hc->initialAttack = atoi(buf.substr(befi, i-befi).c_str());
 
- 		++i;
 
- 		befi=i;
 
- 		for(i; i<andame; ++i)
 
- 		{
 
- 			if(buf[i]=='\t')
 
- 				break;
 
- 		}
 
- 		hc->initialDefence = atoi(buf.substr(befi, i-befi).c_str());
 
- 		++i;
 
- 		befi=i;
 
- 		for(i; i<andame; ++i)
 
- 		{
 
- 			if(buf[i]=='\t')
 
- 				break;
 
- 		}
 
- 		hc->initialPower = atoi(buf.substr(befi, i-befi).c_str());
 
- 		++i;
 
- 		befi=i;
 
- 		for(i; i<andame; ++i)
 
- 		{
 
- 			if(buf[i]=='\t')
 
- 				break;
 
- 		}
 
- 		hc->initialKnowledge = atoi(buf.substr(befi, i-befi).c_str());
 
- 		++i;
 
- 		befi=i;
 
- 		for(i; i<andame; ++i)
 
- 		{
 
- 			if(buf[i]=='\t')
 
- 				break;
 
- 		}
 
- 		hc->proAttack[0] = atoi(buf.substr(befi, i-befi).c_str());
 
- 		++i;
 
- 		befi=i;
 
- 		for(i; i<andame; ++i)
 
- 		{
 
- 			if(buf[i]=='\t')
 
- 				break;
 
- 		}
 
- 		hc->proDefence[0] = atoi(buf.substr(befi, i-befi).c_str());
 
- 		++i;
 
- 		befi=i;
 
- 		for(i; i<andame; ++i)
 
- 		{
 
- 			if(buf[i]=='\t')
 
- 				break;
 
- 		}
 
- 		hc->proPower[0] = atoi(buf.substr(befi, i-befi).c_str());
 
- 		++i;
 
- 		befi=i;
 
- 		for(i; i<andame; ++i)
 
- 		{
 
- 			if(buf[i]=='\t')
 
- 				break;
 
- 		}
 
- 		hc->proKnowledge[0] = atoi(buf.substr(befi, i-befi).c_str());
 
- 		++i;
 
- 		befi=i;
 
- 		for(i; i<andame; ++i)
 
- 		{
 
- 			if(buf[i]=='\t')
 
- 				break;
 
- 		}
 
- 		hc->proAttack[1] = atoi(buf.substr(befi, i-befi).c_str());
 
- 		++i;
 
- 		befi=i;
 
- 		for(i; i<andame; ++i)
 
- 		{
 
- 			if(buf[i]=='\t')
 
- 				break;
 
- 		}
 
- 		hc->proDefence[1] = atoi(buf.substr(befi, i-befi).c_str());
 
- 		++i;
 
- 		befi=i;
 
- 		for(i; i<andame; ++i)
 
- 		{
 
- 			if(buf[i]=='\t')
 
- 				break;
 
- 		}
 
- 		hc->proPower[1] = atoi(buf.substr(befi, i-befi).c_str());
 
- 		++i;
 
- 		befi=i;
 
- 		for(i; i<andame; ++i)
 
- 		{
 
- 			if(buf[i]=='\t')
 
- 				break;
 
- 		}
 
- 		hc->proKnowledge[1] = atoi(buf.substr(befi, i-befi).c_str());
 
- 		++i;
 
- 		//CHero kkk = heroes[0];
 
- 		for(int dd=0; dd<CGameInfo::mainObj->abilh->abilities.size(); ++dd)
 
- 		{
 
- 			befi=i;
 
- 			for(i; i<andame; ++i)
 
- 			{
 
- 				if(buf[i]=='\t')
 
- 					break;
 
- 			}
 
- 			int buff = atoi(buf.substr(befi, i-befi).c_str());
 
- 			++i;
 
- 			hc->proSec.push_back(buff);
 
- 		}
 
- 		for(int dd=0; dd<9; ++dd)
 
- 		{
 
- 			befi=i;
 
- 			for(i; i<andame; ++i)
 
- 			{
 
- 				if(buf[i]=='\t' || buf[i]=='\r')
 
- 					break;
 
- 			}
 
- 			hc->selectionProbability[dd] = atoi(buf.substr(befi, i-befi).c_str());
 
- 			++i;
 
- 		}
 
- 		++i;
 
- 		heroClasses.push_back(hc);
 
- 	}
 
- }
 
- void CHeroHandler::initHeroClasses()
 
- {
 
- 	for(int gg=0; gg<heroes.size(); ++gg)
 
- 	{
 
- 		heroes[gg]->heroClass = heroClasses[heroes[gg]->heroType];
 
- 	}
 
- }
 
 
  |