Browse Source

* 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

mateuszb 18 years ago
parent
commit
8860f1dca2
13 changed files with 186 additions and 9 deletions
  1. 15 0
      CAmbarCendamo.cpp
  2. 36 1
      CBuildingHandler.cpp
  3. 1 0
      CBuildingHandler.h
  4. 1 0
      CCastleHandler.cpp
  5. 19 0
      CCastleHandler.h
  6. 7 0
      CCreatureHandler.h
  7. 2 0
      CGameInfo.h
  8. 26 1
      CHeroHandler.cpp
  9. 5 2
      CHeroHandler.h
  10. 8 4
      CMT.cpp
  11. 30 0
      CObjectHandler.cpp
  12. 35 0
      CObjectHandler.h
  13. 1 1
      mapHandler.cpp

+ 15 - 0
CAmbarCendamo.cpp

@@ -2,6 +2,7 @@
 #include "CAmbarCendamo.h"
 #include "CAmbarCendamo.h"
 #include "CSemiDefHandler.h"
 #include "CSemiDefHandler.h"
 #include "CGameInfo.h"
 #include "CGameInfo.h"
+#include "CObjectHandler.h"
 #include <set>
 #include <set>
 
 
 unsigned int intPow(unsigned int a, unsigned int b)
 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;
 	THC std::cout<<"Wczytywanie terenu: "<<th.getDif()<<std::endl;
 	int defAmount = bufor[i]; // liczba defow
 	int defAmount = bufor[i]; // liczba defow
+	defAmount = readNormalNr(i);
 	i+=4;
 	i+=4;
 	for (int idd = 0 ; idd<defAmount; idd++) // reading defs
 	for (int idd = 0 ; idd<defAmount; idd++) // reading defs
 	{
 	{
@@ -401,6 +403,18 @@ void CAmbarCendamo::deh3m()
 		//teceDef();
 		//teceDef();
 	}
 	}
 	THC std::cout<<"Wczytywanie defow: "<<th.getDif()<<std::endl;
 	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
 	//todo: read events
 }
 }
 int CAmbarCendamo::readNormalNr (int pos, int bytCon)
 int CAmbarCendamo::readNormalNr (int pos, int bytCon)
@@ -415,6 +429,7 @@ int CAmbarCendamo::readNormalNr (int pos, int bytCon)
 
 
 	return ret;
 	return ret;
 }
 }
+
 void CAmbarCendamo::loadDefs()
 void CAmbarCendamo::loadDefs()
 {
 {
 	std::set<int> loadedTypes;
 	std::set<int> loadedTypes;

+ 36 - 1
CBuildingHandler.cpp

@@ -249,6 +249,7 @@ void CBuildingHandler::loadBuildings()
 	}
 	}
 	loadNames();
 	loadNames();
 	loadNeutNames();
 	loadNeutNames();
+	loadDwellingNames();
 }
 }
 
 
 void CBuildingHandler::loadNames()
 void CBuildingHandler::loadNames()
@@ -635,4 +636,38 @@ void CBuildingHandler::loadNeutNames()
 		black.type = EbuildingType(q+1);
 		black.type = EbuildingType(q+1);
 		blacksmiths.push_back(black);
 		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;
+	}
+}

+ 1 - 0
CBuildingHandler.h

@@ -35,6 +35,7 @@ public:
 	void loadBuildings(); //main loader, calls loading functions below
 	void loadBuildings(); //main loader, calls loading functions below
 	void loadNames(); //loads castle - specufuc names and descriptoins
 	void loadNames(); //loads castle - specufuc names and descriptoins
 	void loadNeutNames(); //loads castle independent names and descriptions
 	void loadNeutNames(); //loads castle independent names and descriptions
+	void loadDwellingNames(); //load names for dwellgins
 };
 };
 
 
 #endif //CBUILDINGHANDLER_H
 #endif //CBUILDINGHANDLER_H

+ 1 - 0
CCastleHandler.cpp

@@ -0,0 +1 @@
+#include "CCastleHandler.h"

+ 19 - 0
CCastleHandler.h

@@ -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

+ 7 - 0
CCreatureHandler.h

@@ -16,6 +16,13 @@ public:
 	//TODO - zdolnoœci - na typie wyliczeniowym czy czymœ
 	//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
 class CCreatureHandler
 {
 {
 public:
 public:

+ 2 - 0
CGameInfo.h

@@ -8,6 +8,7 @@
 #include "CHeroHandler.h"
 #include "CHeroHandler.h"
 #include "CAmbarCendamo.h"
 #include "CAmbarCendamo.h"
 #include "CBuildingHandler.h"
 #include "CBuildingHandler.h"
+#include "CObjectHandler.h"
 
 
 /*
 /*
 	CGameInfo class
 	CGameInfo class
@@ -24,6 +25,7 @@ public:
 	CSpellHandler * spellh;
 	CSpellHandler * spellh;
 	CAmbarCendamo * ac;
 	CAmbarCendamo * ac;
 	CBuildingHandler * buildh;
 	CBuildingHandler * buildh;
+	CObjectHandler * objh;
 };
 };
 
 
 #endif //CGAMEINFO_H
 #endif //CGAMEINFO_H

+ 26 - 1
CHeroHandler.cpp

@@ -21,6 +21,7 @@ void CHeroHandler::loadHeroes()
 		if(base.size()<2) //ended, but some rubbish could still stay end we have something useless
 		if(base.size()<2) //ended, but some rubbish could still stay end we have something useless
 		{
 		{
 			loadSpecialAbilities();
 			loadSpecialAbilities();
+			loadBiographies();
 			return;
 			return;
 		}
 		}
 		while(base[iit]!='\t')
 		while(base[iit]!='\t')
@@ -157,4 +158,28 @@ void CHeroHandler::loadSpecialAbilities()
 		++whHero;
 		++whHero;
 		delete [500] tab;
 		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;
+	}
+}

+ 5 - 2
CHeroHandler.h

@@ -3,6 +3,7 @@
 
 
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
+#include "CCreatureHandler.h"
 
 
 class CHero
 class CHero
 {
 {
@@ -11,6 +12,7 @@ public:
 	int low1stack, high1stack, low2stack, high2stack, low3stack, high3stack; //amount of units; described below
 	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 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 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)
 	bool isAllowed; //true if we can play with this hero (depends on map)
 };
 };
 
 
@@ -18,8 +20,8 @@ class CHeroInstance
 {
 {
 public:
 public:
 	CHero type;
 	CHero type;
-	int x, y; //position
-	bool under; //is underground?
+	int x, y, z; //position
+	CCreatureSet army; //army
 	//TODO: armia, artefakty, itd.
 	//TODO: armia, artefakty, itd.
 };
 };
 
 
@@ -29,6 +31,7 @@ public:
 	std::vector<CHero> heroes;
 	std::vector<CHero> heroes;
 	void loadHeroes();
 	void loadHeroes();
 	void loadSpecialAbilities();
 	void loadSpecialAbilities();
+	void loadBiographies();
 };
 };
 
 
 
 

+ 8 - 4
CMT.cpp

@@ -10,12 +10,13 @@
 #include "zlib.h"
 #include "zlib.h"
 #include <cmath>
 #include <cmath>
 #include <ctime>
 #include <ctime>
-#include "CArthandler.h"
+#include "CArtHandler.h"
 #include "CHeroHandler.h"
 #include "CHeroHandler.h"
 #include "CCreatureHandler.h"
 #include "CCreatureHandler.h"
 #include "CAbilityHandler.h"
 #include "CAbilityHandler.h"
 #include "CSpellHandler.h"
 #include "CSpellHandler.h"
 #include "CBuildingHandler.h"
 #include "CBuildingHandler.h"
+#include "CObjectHandler.h"
 #include "CGameInfo.h"
 #include "CGameInfo.h"
 #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
 #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
 #  include <fcntl.h>
 #  include <fcntl.h>
@@ -249,6 +250,9 @@ int _tmain(int argc, _TCHAR* argv[])
 		CBuildingHandler * buildh = new CBuildingHandler;
 		CBuildingHandler * buildh = new CBuildingHandler;
 		buildh->loadBuildings();
 		buildh->loadBuildings();
 		cgi->buildh = buildh;
 		cgi->buildh = buildh;
+		CObjectHandler * objh = new CObjectHandler;
+		objh->loadObjects();
+		cgi->objh = objh;
 		CAmbarCendamo * ac = new CAmbarCendamo("4gryf");
 		CAmbarCendamo * ac = new CAmbarCendamo("4gryf");
 		cgi->ac = ac;
 		cgi->ac = ac;
 		THC std::cout<<"Wczytywanie pliku: "<<tmh.getDif()<<std::endl;
 		THC std::cout<<"Wczytywanie pliku: "<<tmh.getDif()<<std::endl;
@@ -292,7 +296,7 @@ int _tmain(int argc, _TCHAR* argv[])
 							}
 							}
 						case (SDLK_RIGHT):
 						case (SDLK_RIGHT):
 							{
 							{
-								if(xx<ac->map.width-33)
+								if(xx<ac->map.width-25)
 									xx++;
 									xx++;
 								break;
 								break;
 							}
 							}
@@ -304,7 +308,7 @@ int _tmain(int argc, _TCHAR* argv[])
 							}
 							}
 						case (SDLK_DOWN):
 						case (SDLK_DOWN):
 							{
 							{
-								if(yy<ac->map.height-25)
+								if(yy<ac->map.height-18)
 									yy++;
 									yy++;
 								break;
 								break;
 							}
 							}
@@ -322,7 +326,7 @@ int _tmain(int argc, _TCHAR* argv[])
 							}
 							}
 						}
 						}
 						SDL_FillRect(ekran, NULL, SDL_MapRGB(ekran->format, 0, 0, 0));
 						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_BlitSurface(help,NULL,ekran,NULL);
 						SDL_FreeSurface(help);
 						SDL_FreeSurface(help);
 						SDL_Flip(ekran);
 						SDL_Flip(ekran);

+ 30 - 0
CObjectHandler.cpp

@@ -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 - 0
CObjectHandler.h

@@ -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

+ 1 - 1
mapHandler.cpp

@@ -123,7 +123,7 @@ SDL_Surface * mapHandler::terrainRect(int x, int y, int dx, int dy, int level)
 #endif
 #endif
 	SDL_Surface * su = SDL_CreateRGBSurface(SDL_SWSURFACE, dx*32, dy*32, 32,
 	SDL_Surface * su = SDL_CreateRGBSurface(SDL_SWSURFACE, dx*32, dy*32, 32,
                                    rmask, gmask, bmask, amask);
                                    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");
 		throw new std::string("Poza zakresem");
 	for (int bx=0; bx<dx; bx++)
 	for (int bx=0; bx<dx; bx++)
 	{
 	{