mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	* zaczytywanie biografii bohaterów
* zaczytywanie nazw obiektów (są z numerami) * klasa na zamek, klasy na różne obiekty * poprawka zaczytywania defów (teraz zaczytuje wszystkie) * rozpoczęcie prac nad zaczytywaniem obiektów (zaczytuje już ich ilość) * poprawki kodu związanego z wyświetlaniem mapy (już nie ucina paska od dołu i z prawej, za to jest irytujący czarny pasek na dole związny z niecałkowitym wynikiem dzielenia 600 przez 32) * może jakieś inne pomniejsze zmiany
This commit is contained in:
		| @@ -2,6 +2,7 @@ | ||||
| #include "CAmbarCendamo.h" | ||||
| #include "CSemiDefHandler.h" | ||||
| #include "CGameInfo.h" | ||||
| #include "CObjectHandler.h" | ||||
| #include <set> | ||||
|  | ||||
| unsigned int intPow(unsigned int a, unsigned int b) | ||||
| @@ -384,6 +385,7 @@ void CAmbarCendamo::deh3m() | ||||
| 	} | ||||
| 	THC std::cout<<"Wczytywanie terenu: "<<th.getDif()<<std::endl; | ||||
| 	int defAmount = bufor[i]; // liczba defow | ||||
| 	defAmount = readNormalNr(i); | ||||
| 	i+=4; | ||||
| 	for (int idd = 0 ; idd<defAmount; idd++) // reading defs | ||||
| 	{ | ||||
| @@ -401,6 +403,18 @@ void CAmbarCendamo::deh3m() | ||||
| 		//teceDef(); | ||||
| 	} | ||||
| 	THC std::cout<<"Wczytywanie defow: "<<th.getDif()<<std::endl; | ||||
| 	////loading objects | ||||
| 	int howManyObjs = readNormalNr(i, 4); i+=4; | ||||
| 	for(int ww=0; ww<howManyObjs; ++ww) | ||||
| 	{ | ||||
| 		CObjectInstance nobj; //we will read this object | ||||
| 		nobj.x = bufor[i++]; | ||||
| 		nobj.y = bufor[i++]; | ||||
| 		nobj.z = bufor[i++]; | ||||
| 		nobj.defNumber = bufor[i++]; //TODO - zobaczy� co si� dzieje, jak numer okre�laj�cego defa jest wi�kszy ni� 255 | ||||
| 		//TODO - doko�czy�, du�o do zrobienia - trzeba patrze�, co def niesie | ||||
| 	} | ||||
| 	////objects loaded | ||||
| 	//todo: read events | ||||
| } | ||||
| int CAmbarCendamo::readNormalNr (int pos, int bytCon) | ||||
| @@ -415,6 +429,7 @@ int CAmbarCendamo::readNormalNr (int pos, int bytCon) | ||||
|  | ||||
| 	return ret; | ||||
| } | ||||
|  | ||||
| void CAmbarCendamo::loadDefs() | ||||
| { | ||||
| 	std::set<int> loadedTypes; | ||||
|   | ||||
| @@ -249,6 +249,7 @@ void CBuildingHandler::loadBuildings() | ||||
| 	} | ||||
| 	loadNames(); | ||||
| 	loadNeutNames(); | ||||
| 	loadDwellingNames(); | ||||
| } | ||||
|  | ||||
| void CBuildingHandler::loadNames() | ||||
| @@ -635,4 +636,38 @@ void CBuildingHandler::loadNeutNames() | ||||
| 		black.type = EbuildingType(q+1); | ||||
| 		blacksmiths.push_back(black); | ||||
| 	} | ||||
| } | ||||
| } | ||||
|  | ||||
| void CBuildingHandler::loadDwellingNames() | ||||
| { | ||||
| 	std::ifstream inp("H3bitmap.lod\\DWELLING.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 | ||||
| 	std::string buf = std::string(bufor); | ||||
| 	delete [andame] bufor; | ||||
| 	int i = 0; //buf iterator | ||||
| 	int whdw = 98; //wchich dwelling we are currently reading | ||||
| 	for(whdw; whdw<224; ++whdw) | ||||
| 	{ | ||||
| 		int befi=i; | ||||
| 		for(i; i<andame; ++i) | ||||
| 		{ | ||||
| 			if(buf[i]=='\t') | ||||
| 				break; | ||||
| 		} | ||||
| 		buildings[whdw].name = buf.substr(befi, i-befi); | ||||
| 		++i; | ||||
|  | ||||
| 		befi=i; | ||||
| 		for(i; i<andame; ++i) | ||||
| 		{ | ||||
| 			if(buf[i]=='\r') | ||||
| 				break; | ||||
| 		} | ||||
| 		buildings[whdw].description = buf.substr(befi, i-befi); | ||||
| 		i+=2; | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -35,6 +35,7 @@ public: | ||||
| 	void loadBuildings(); //main loader, calls loading functions below | ||||
| 	void loadNames(); //loads castle - specufuc names and descriptoins | ||||
| 	void loadNeutNames(); //loads castle independent names and descriptions | ||||
| 	void loadDwellingNames(); //load names for dwellgins | ||||
| }; | ||||
|  | ||||
| #endif //CBUILDINGHANDLER_H | ||||
							
								
								
									
										1
									
								
								CCastleHandler.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								CCastleHandler.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| #include "CCastleHandler.h" | ||||
							
								
								
									
										19
									
								
								CCastleHandler.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								CCastleHandler.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| #ifndef CCASTLEHANDLER_H | ||||
| #define CCASTLEHANDLER_H | ||||
|  | ||||
| #include "CBuildingHandler.h" | ||||
| #include "CHeroHandler.h" | ||||
| #include "CObjectHandler.h" | ||||
|  | ||||
| class CCastle : public CSpecObjInfo //castle class | ||||
| { | ||||
| public: | ||||
| 	int x, y, z; //posiotion | ||||
| 	std::vector<CBuilding> buildings; //buildings we can build in this castle | ||||
| 	std::vector<bool> isBuild; //isBuild[i] is true, when building buildings[i] has been built | ||||
| 	CHero * visitingHero; | ||||
| 	CHero * garnisonHero; | ||||
| 	//TODO: doko�czy� | ||||
| }; | ||||
|  | ||||
| #endif //CCASTLEHANDLER_H | ||||
| @@ -16,6 +16,13 @@ public: | ||||
| 	//TODO - zdolno�ci - na typie wyliczeniowym czy czym� | ||||
| }; | ||||
|  | ||||
| class CCreatureSet //seven combined creatures | ||||
| { | ||||
| 	CCreature * slot1, slot2, slot3, slot4, slot5, slot6, slot7; //types of creatures on each slot | ||||
| 	unsigned int s1, s2, s3, s4, s5, s6, s7; //amounts of units in slots | ||||
| 	bool formation; //false - wide, true - tight | ||||
| }; | ||||
|  | ||||
| class CCreatureHandler | ||||
| { | ||||
| public: | ||||
|   | ||||
| @@ -8,6 +8,7 @@ | ||||
| #include "CHeroHandler.h" | ||||
| #include "CAmbarCendamo.h" | ||||
| #include "CBuildingHandler.h" | ||||
| #include "CObjectHandler.h" | ||||
|  | ||||
| /* | ||||
| 	CGameInfo class | ||||
| @@ -24,6 +25,7 @@ public: | ||||
| 	CSpellHandler * spellh; | ||||
| 	CAmbarCendamo * ac; | ||||
| 	CBuildingHandler * buildh; | ||||
| 	CObjectHandler * objh; | ||||
| }; | ||||
|  | ||||
| #endif //CGAMEINFO_H | ||||
| @@ -21,6 +21,7 @@ void CHeroHandler::loadHeroes() | ||||
| 		if(base.size()<2) //ended, but some rubbish could still stay end we have something useless | ||||
| 		{ | ||||
| 			loadSpecialAbilities(); | ||||
| 			loadBiographies(); | ||||
| 			return; | ||||
| 		} | ||||
| 		while(base[iit]!='\t') | ||||
| @@ -157,4 +158,28 @@ void CHeroHandler::loadSpecialAbilities() | ||||
| 		++whHero; | ||||
| 		delete [500] tab; | ||||
| 	} | ||||
| } | ||||
| } | ||||
|  | ||||
| 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 | ||||
| 	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; | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -3,6 +3,7 @@ | ||||
|  | ||||
| #include <string> | ||||
| #include <vector> | ||||
| #include "CCreatureHandler.h" | ||||
|  | ||||
| class CHero | ||||
| { | ||||
| @@ -11,6 +12,7 @@ public: | ||||
| 	int low1stack, high1stack, low2stack, high2stack, low3stack, high3stack; //amount of units; described below | ||||
| 	std::string refType1stack, refType2stack, refType3stack; //reference names of units appearing in hero's army if he is recruited in tavern | ||||
| 	std::string bonusName, shortBonus, longBonus; //for special abilities | ||||
| 	std::string biography; //biography, of course | ||||
| 	bool isAllowed; //true if we can play with this hero (depends on map) | ||||
| }; | ||||
|  | ||||
| @@ -18,8 +20,8 @@ class CHeroInstance | ||||
| { | ||||
| public: | ||||
| 	CHero type; | ||||
| 	int x, y; //position | ||||
| 	bool under; //is underground? | ||||
| 	int x, y, z; //position | ||||
| 	CCreatureSet army; //army | ||||
| 	//TODO: armia, artefakty, itd. | ||||
| }; | ||||
|  | ||||
| @@ -29,6 +31,7 @@ public: | ||||
| 	std::vector<CHero> heroes; | ||||
| 	void loadHeroes(); | ||||
| 	void loadSpecialAbilities(); | ||||
| 	void loadBiographies(); | ||||
| }; | ||||
|  | ||||
|  | ||||
|   | ||||
							
								
								
									
										12
									
								
								CMT.cpp
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								CMT.cpp
									
									
									
									
									
								
							| @@ -10,12 +10,13 @@ | ||||
| #include "zlib.h" | ||||
| #include <cmath> | ||||
| #include <ctime> | ||||
| #include "CArthandler.h" | ||||
| #include "CArtHandler.h" | ||||
| #include "CHeroHandler.h" | ||||
| #include "CCreatureHandler.h" | ||||
| #include "CAbilityHandler.h" | ||||
| #include "CSpellHandler.h" | ||||
| #include "CBuildingHandler.h" | ||||
| #include "CObjectHandler.h" | ||||
| #include "CGameInfo.h" | ||||
| #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) | ||||
| #  include <fcntl.h> | ||||
| @@ -249,6 +250,9 @@ int _tmain(int argc, _TCHAR* argv[]) | ||||
| 		CBuildingHandler * buildh = new CBuildingHandler; | ||||
| 		buildh->loadBuildings(); | ||||
| 		cgi->buildh = buildh; | ||||
| 		CObjectHandler * objh = new CObjectHandler; | ||||
| 		objh->loadObjects(); | ||||
| 		cgi->objh = objh; | ||||
| 		CAmbarCendamo * ac = new CAmbarCendamo("4gryf"); | ||||
| 		cgi->ac = ac; | ||||
| 		THC std::cout<<"Wczytywanie pliku: "<<tmh.getDif()<<std::endl; | ||||
| @@ -292,7 +296,7 @@ int _tmain(int argc, _TCHAR* argv[]) | ||||
| 							} | ||||
| 						case (SDLK_RIGHT): | ||||
| 							{ | ||||
| 								if(xx<ac->map.width-33) | ||||
| 								if(xx<ac->map.width-25) | ||||
| 									xx++; | ||||
| 								break; | ||||
| 							} | ||||
| @@ -304,7 +308,7 @@ int _tmain(int argc, _TCHAR* argv[]) | ||||
| 							} | ||||
| 						case (SDLK_DOWN): | ||||
| 							{ | ||||
| 								if(yy<ac->map.height-25) | ||||
| 								if(yy<ac->map.height-18) | ||||
| 									yy++; | ||||
| 								break; | ||||
| 							} | ||||
| @@ -322,7 +326,7 @@ int _tmain(int argc, _TCHAR* argv[]) | ||||
| 							} | ||||
| 						} | ||||
| 						SDL_FillRect(ekran, NULL, SDL_MapRGB(ekran->format, 0, 0, 0)); | ||||
| 						SDL_Surface * help = mh->terrainRect(xx,yy,32,24,zz); | ||||
| 						SDL_Surface * help = mh->terrainRect(xx,yy,25,18,zz); | ||||
| 						SDL_BlitSurface(help,NULL,ekran,NULL); | ||||
| 						SDL_FreeSurface(help); | ||||
| 						SDL_Flip(ekran); | ||||
|   | ||||
							
								
								
									
										30
									
								
								CObjectHandler.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								CObjectHandler.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| #include "CObjectHandler.h" | ||||
| #include "stdafx.h" | ||||
|  | ||||
| void CObjectHandler::loadObjects() | ||||
| { | ||||
| 	std::ifstream inp("H3bitmap.lod\\OBJNAMES.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 | ||||
| 	std::string buf = std::string(bufor); | ||||
| 	delete [andame] bufor; | ||||
| 	int i = 0; //buf iterator | ||||
| 	while(!inp.eof()) | ||||
| 	{ | ||||
| 		if(objects.size()>200 && buf.substr(i, buf.size()-i).find('\r')==std::string::npos) | ||||
| 			break; | ||||
| 		CObject nobj; | ||||
| 		int befi=i; | ||||
| 		for(i; i<andame; ++i) | ||||
| 		{ | ||||
| 			if(buf[i]=='\r') | ||||
| 				break; | ||||
| 		} | ||||
| 		nobj.name = buf.substr(befi, i-befi); | ||||
| 		i+=2; | ||||
| 		objects.push_back(nobj); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										35
									
								
								CObjectHandler.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								CObjectHandler.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | ||||
| #ifndef COBJECTHANDLER_H | ||||
| #define COBJECTHANDLER_H | ||||
|  | ||||
| #include <string> | ||||
| #include <vector> | ||||
|  | ||||
| class CSpecObjInfo //class with object - specific info (eg. different information for creatures and heroes); use inheritance to make object - specific classes | ||||
| { | ||||
| }; | ||||
|  | ||||
| class CObject //typical object that can be encountered on a map | ||||
| { | ||||
| public: | ||||
| 	std::string name; //object's name | ||||
| }; | ||||
|  | ||||
| class CObjectInstance //instance of object | ||||
| { | ||||
| public: | ||||
| 	int defNumber; //specifies number of def file with animation of this object | ||||
| 	int id; //number of object in CObjectHandler's vector | ||||
| 	int x, y, z; // position | ||||
| 	CSpecObjInfo * info; //pointer to something with additional information | ||||
| }; | ||||
|  | ||||
| class CObjectHandler | ||||
| { | ||||
| public: | ||||
| 	std::vector<CObject> objects; //vector of objects; i-th object in vector has subnumber i | ||||
| 	std::vector<CObjectInstance> objInstances; //vector with objects on map | ||||
| 	void loadObjects(); | ||||
| }; | ||||
|  | ||||
|  | ||||
| #endif //COBJECTHANDLER_H | ||||
| @@ -123,7 +123,7 @@ SDL_Surface * mapHandler::terrainRect(int x, int y, int dx, int dy, int level) | ||||
| #endif | ||||
| 	SDL_Surface * su = SDL_CreateRGBSurface(SDL_SWSURFACE, dx*32, dy*32, 32, | ||||
|                                    rmask, gmask, bmask, amask); | ||||
| 	if (((dx+x)>((reader->map.width)-1) || (dy+y)>((reader->map.height)-1)) || ((x<0)||(y<0) ) ) | ||||
| 	if (((dx+x)>((reader->map.width)) || (dy+y)>((reader->map.height))) || ((x<0)||(y<0) ) ) | ||||
| 		throw new std::string("Poza zakresem"); | ||||
| 	for (int bx=0; bx<dx; bx++) | ||||
| 	{ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user