Browse Source

* poprawione zaczytywanie potworów
* częściowe czytanie bohaterów (zakomentowane, coby się nie sypało)
* wczytywanie tekstów wyświetlających się po wciśnięciu ppm w menu new game
* drobne poprawki w opisie bohaterów w specyfikacji

mateuszb 18 years ago
parent
commit
df7ef8115b
10 changed files with 318 additions and 20 deletions
  1. 186 12
      CAmbarCendamo.cpp
  2. 3 1
      CAmbarCendamo.h
  3. 1 0
      CCastleHandler.h
  4. 5 2
      CCreatureHandler.cpp
  5. 2 1
      CCreatureHandler.h
  6. 1 1
      CMT.cpp
  7. 24 3
      CObjectHandler.h
  8. 95 0
      CPreGameTextHandler.cpp
  9. 1 0
      CPreGameTextHandler.h
  10. BIN
      h3m.txt

+ 186 - 12
CAmbarCendamo.cpp

@@ -3,6 +3,7 @@
 #include "CSemiDefHandler.h"
 #include "CGameInfo.h"
 #include "CObjectHandler.h"
+#include "CCastleHandler.h"
 #include <set>
 
 unsigned int intPow(unsigned int a, unsigned int b)
@@ -405,9 +406,10 @@ void CAmbarCendamo::deh3m()
 	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)
+	/*for(int ww=0; ww<howManyObjs; ++ww)
 	{
 		CObjectInstance nobj; //we will read this object
+		nobj.id = CGameInfo::mainObj->objh->objInstances.size();
 		nobj.x = bufor[i++];
 		nobj.y = bufor[i++];
 		nobj.z = bufor[i++];
@@ -415,9 +417,9 @@ void CAmbarCendamo::deh3m()
 		i+=5;
 		switch(getDefType(map.defy[nobj.defNumber]))
 		{
-		case EDefType::EVENTOBJ_DEF:
+		case EDefType::EVENTOBJ_DEF: //for event - objects
 			{
-				CEventObjInfo spec;
+				CEventObjInfo * spec = new CEventObjInfo;
 				bool guardMess;
 				guardMess = bufor[i]; ++i;
 				if(guardMess)
@@ -425,28 +427,121 @@ void CAmbarCendamo::deh3m()
 					int messLong = readNormalNr(i, 4); i+=4;
 					if(messLong>0)
 					{
-						spec.isMessage = true;
+						spec->isMessage = true;
 						for(int yy=0; yy<messLong; ++yy)
 						{
-							spec.message +=bufor[i+yy];
+							spec->message +=bufor[i+yy];
 						}
 						i+=messLong;
 					}
-					spec.areGuarders = bufor[i]; ++i;
-					if(spec.areGuarders)
+					spec->areGuarders = bufor[i]; ++i;
+					if(spec->areGuarders)
 					{
-						//TODO: czytanie potworów w zapisie standardowym, to jest czêsto wykorzystywane
+						spec->guarders = readCreatureSet(i); i+=32;
 					}
 				}
+				else
+				{
+					spec->isMessage = false;
+					spec->areGuarders = false;
+					spec->message = std::string("");
+				}
+				spec->gainedExp = readNormalNr(i, 4); i+=4;
+				spec->manaDiff = readNormalNr(i, 4); i+=4;
+				spec->moraleDiff = readNormalNr(i, 1, true); ++i;
+				spec->luckDiff = readNormalNr(i, 1, true); ++i;
+				spec->wood = readNormalNr(i); i+=4;
+				spec->mercury = readNormalNr(i); i+=4;
+				spec->ore = readNormalNr(i); i+=4;
+				spec->sulfur = readNormalNr(i); i+=4;
+				spec->crystal = readNormalNr(i); i+=4;
+				spec->gems = readNormalNr(i); i+=4;
+				spec->gold = readNormalNr(i); i+=4;
+				spec->attack = readNormalNr(i, 1); ++i;
+				spec->defence = readNormalNr(i, 1); ++i;
+				spec->power = readNormalNr(i, 1); ++i;
+				spec->knowledge = readNormalNr(i, 1); ++i;
+				int gabn; //number of gained abilities
+				gabn = readNormalNr(i, 1); ++i;
+				for(int oo = 0; oo<gabn; ++oo)
+				{
+					spec->abilities.push_back(&((CGameInfo::mainObj->abilh)->abilities[readNormalNr(i, 1)])); ++i;
+					spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
+				}
+				int gart = readNormalNr(i, 1); ++i; //number of gained artifacts
+				for(int oo = 0; oo<gart; ++oo)
+				{
+					spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[readNormalNr(i, 2)])); i+=2;
+				}
+				int gspel = readNormalNr(i, 1); ++i; //number of gained spells
+				for(int oo = 0; oo<gspel; ++oo)
+				{
+					spec->spells.push_back(&(CGameInfo::mainObj->spellh->spells[readNormalNr(i, 1)])); ++i;
+				}
+				int gcre = readNormalNr(i, 1); ++i; //number of gained creatures
+				spec->creatures = readCreatureSet(i, gcre); i+=4*gcre;
+				i+=8;
+				spec->availableFor = readNormalNr(i, 1); ++i;
+				spec->computerActivate = readNormalNr(i, 1); ++i;
+				spec->humanActivate = readNormalNr(i, 1); ++i;
+				i+=4;
+				nobj.info = spec;
+				break;
+			}
+		case EDefType::HERO_DEF:
+			{
+				CHeroObjInfo * spec = new CHeroObjInfo;
+				spec->bytes[0] = bufor[i]; ++i;
+				spec->bytes[1] = bufor[i]; ++i;
+				spec->bytes[2] = bufor[i]; ++i;
+				spec->bytes[3] = bufor[i]; ++i;
+				spec->player = bufor[i]; ++i;
+				spec->type = &(CGameInfo::mainObj->heroh->heroes[readNormalNr(i, 1)]); ++i;
+				bool isName = bufor[i]; ++i; //true if hero has nonstandard name
+				if(isName)
+				{
+					int length = readNormalNr(i, 4); i+=4;
+					for(int gg=0; gg<length; ++gg)
+					{
+						spec->name+=bufor[i]; ++i;
+					}
+				}
+				else
+					spec->name = std::string("");
+				bool isExp = bufor[i]; ++i; //true if hore's experience is greater than 0
+				if(isExp)
+				{
+					spec->experience = readNormalNr(i); i+=4;
+				}
+				else spec->experience = 0;
+				++i; //TODO - czy tu na pewno nie ma istotnej informacji?
+				bool nonstandardAbilities = bufor[i]; //true if hero has specified abilities
+				if(nonstandardAbilities)
+				{
+					int howMany = readNormalNr(i); i+=4;
+					for(int yy=0; yy<howMany; ++yy)
+					{
+						spec->abilities.push_back(&(CGameInfo::mainObj->abilh->abilities[readNormalNr(i, 1)])); ++i;
+						spec->abilityLevels.push_back(readNormalNr(i, 1)); ++i;
+					}
+				}
+				bool standGarrison = bufor[i]; ++i; //true if hero has nonstandard garrison
+				if(standGarrison)
+				{
+					spec->garrison = readCreatureSet(i); i+=7;
+				}
+				bool form = bufor[i]; ++i; //formation
+				spec->garrison.formation = form;
 				break;
 			}
 		}
+		CGameInfo::mainObj->objh->objInstances.push_back(nobj);
 		//TODO - dokoñczyæ, du¿o do zrobienia - trzeba patrzeæ, co def niesie
-	}
+	}//*/ //end of loading objects; commented to making application work until it will be finished
 	////objects loaded
 	//todo: read events
 }
-int CAmbarCendamo::readNormalNr (int pos, int bytCon)
+int CAmbarCendamo::readNormalNr (int pos, int bytCon, bool cyclic)
 {
 	int ret=0;
 	int amp=1;
@@ -455,7 +550,10 @@ int CAmbarCendamo::readNormalNr (int pos, int bytCon)
 		ret+=bufor[pos+i]*amp;
 		amp*=256;
 	}
-
+	if(cyclic && bytCon<4 && ret>=amp/2)
+	{
+		ret = ret-amp;
+	}
 	return ret;
 }
 
@@ -507,4 +605,80 @@ EDefType CAmbarCendamo::getDefType(DefInfo &a)
 	default:
 		return EDefType::TERRAINOBJ_DEF;
 	}
-}
+}
+
+CCreatureSet CAmbarCendamo::readCreatureSet(int pos, int number)
+{
+	CCreatureSet ret;
+	if(number>0 && readNormalNr(pos, 2)!=0xffff)
+	{
+		ret.slot1 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos, 2)]);
+		ret.s1 = readNormalNr(pos+2, 2);
+	}
+	else
+	{
+		ret.slot1 = NULL;
+		ret.s1 = 0;
+	}
+	if(number>1 && readNormalNr(pos+4, 2)!=0xffff)
+	{
+		ret.slot2 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+4, 2)]);
+		ret.s2 = readNormalNr(pos+6, 2);
+	}
+	else
+	{
+		ret.slot2 = NULL;
+		ret.s2 = 0;
+	}
+	if(number>2 && readNormalNr(pos+8, 2)!=0xffff)
+	{
+		ret.slot3 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+8, 2)]);
+		ret.s3 = readNormalNr(pos+10, 2);
+	}
+	else
+	{
+		ret.slot3 = NULL;
+		ret.s3 = 0;
+	}
+	if(number>3 && readNormalNr(pos+12, 2)!=0xffff)
+	{
+		ret.slot4 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+12, 2)]);
+		ret.s4 = readNormalNr(pos+14, 2);
+	}
+	else
+	{
+		ret.slot4 = NULL;
+		ret.s4 = 0;
+	}
+	if(number>4 && readNormalNr(pos+16, 2)!=0xffff)
+	{
+		ret.slot5 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+16, 2)]);
+		ret.s5 = readNormalNr(pos+18, 2);
+	}
+	else
+	{
+		ret.slot5 = NULL;
+		ret.s5 = 0;
+	}
+	if(number>5 && readNormalNr(pos+20, 2)!=0xffff)
+	{
+		ret.slot6 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+20, 2)]);
+		ret.s6 = readNormalNr(pos+22, 2);
+	}
+	else
+	{
+		ret.slot6 = NULL;
+		ret.s6 = 0;
+	}
+	if(number>6 && readNormalNr(pos+24, 2)!=0xffff)
+	{
+		ret.slot7 = &(CGameInfo::mainObj->creh->creatures[readNormalNr(pos+24, 2)]);
+		ret.s7 = readNormalNr(pos+26, 2);
+	}
+	else
+	{
+		ret.slot7 = NULL;
+		ret.s7 = 0;
+	}
+	return ret;
+}

+ 3 - 1
CAmbarCendamo.h

@@ -8,6 +8,7 @@
 #include "SDL.h"
 #include "map.h"
 #include "CSemiDefHandler.h"
+#include "CCreatureHandler.h"
 
 enum EDefType {TOWN_DEF, HERO_DEF, CREATURES_DEF, SEERHUT_DEF, RESOURCE_DEF, TERRAINOBJ_DEF, EVENTOBJ_DEF, SIGN_DEF, GARRISON_DEF};
 
@@ -23,10 +24,11 @@ public:
 /////////////////funkcje skladowe
 	CAmbarCendamo (const char * tie); // c-tor; tie is the path of the map file
 	~CAmbarCendamo (); // d-tor
-	int readNormalNr (int pos, int bytCon=4); //read number from bytCon bytes starting from pos position in buffer 
+	int readNormalNr (int pos, int bytCon=4, bool cyclic = false); //read number from bytCon bytes starting from pos position in buffer ; if cyclic is true, number is treated as it were signed number with bytCon bytes
 	void teceDef (); // create files with info about defs
 	void deh3m(); // decode file, results are stored in map
 	void loadDefs();
 	EDefType getDefType(DefInfo& a); //returns type of object in def
+	CCreatureSet readCreatureSet(int pos, int number = 7); //reads creature set in most recently encountered format; reades number units (default is 7)
 };
 #endif //AMBARCENDD

+ 1 - 0
CCastleHandler.h

@@ -11,6 +11,7 @@ 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
+	std::vector<bool> isLocked; //isLocked[i] is true, when building buildings[i] canot be built
 	CHero * visitingHero;
 	CHero * garnisonHero;
 	//TODO: dokoñczyæ

+ 5 - 2
CCreatureHandler.cpp

@@ -253,8 +253,11 @@ void CCreatureHandler::loadCreatures()
 		}
 		ncre.abilityRefs = buf.substr(befi, i-befi);
 		i+=2;
-		ncre.idNumber = creatures.size();
-		creatures.push_back(ncre);
+		if(ncre.nameSing!=std::string("") && ncre.namePl!=std::string(""))
+		{
+			ncre.idNumber = creatures.size();
+			creatures.push_back(ncre);
+		}
 	}
 }
 

+ 2 - 1
CCreatureHandler.h

@@ -18,7 +18,8 @@ public:
 
 class CCreatureSet //seven combined creatures
 {
-	CCreature * slot1, slot2, slot3, slot4, slot5, slot6, slot7; //types of creatures on each slot
+public:
+	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
 };

+ 1 - 1
CMT.cpp

@@ -258,7 +258,7 @@ int _tmain(int argc, _TCHAR* argv[])
 		CObjectHandler * objh = new CObjectHandler;
 		objh->loadObjects();
 		cgi->objh = objh;
-		CAmbarCendamo * ac = new CAmbarCendamo("4gryf");
+		CAmbarCendamo * ac = new CAmbarCendamo("4gryf"); //4gryf
 		cgi->ac = ac;
 		THC std::cout<<"Wczytywanie pliku: "<<tmh.getDif()<<std::endl;
 		ac->deh3m();

+ 24 - 3
CObjectHandler.h

@@ -7,6 +7,7 @@
 #include "CArtHandler.h"
 #include "CAbilityHandler.h"
 #include "CSpellHandler.h"
+#include "CHeroHandler.h"
 
 class CSpecObjInfo //class with object - specific info (eg. different information for creatures and heroes); use inheritance to make object - specific classes
 {
@@ -28,16 +29,36 @@ public:
 	unsigned int defence; //added defence points
 	unsigned int power; //added power points
 	unsigned int knowledge; //added knowledge points
-	std::vector<CAbility> abilities; //gained abilities
+	std::vector<CAbility *> abilities; //gained abilities
 	std::vector<int> abilityLevels; //levels of gained abilities
-	std::vector<CArtifact> artifacts; //gained artifacts
-	std::vector<CSpell> spells; //gained spells
+	std::vector<CArtifact *> artifacts; //gained artifacts
+	std::vector<CSpell *> spells; //gained spells
 	CCreatureSet creatures; //gained creatures
 	unsigned char availableFor; //players whom this event is available for
 	bool computerActivate; //true if computre player can activate this event
 	bool humanActivate; //true if human player can activate this event
 };
 
+class CHeroObjInfo : public CSpecObjInfo
+{
+public:
+	char bytes[4]; //mysterius bytes identifying hero in a strange way
+	int player;
+	CHero * type;
+	std::string name; //if nonstandard
+	CCreatureSet garrison; //hero's army
+	std::vector<CArtifact *> artifacts; //hero's artifacts
+	bool isGuarding;
+	int guardRange; //range of hero's guard
+	std::string biography; //if nonstandard
+	bool sex; //if true, reverse hero's sex
+	std::vector<CSpell *> spells; //hero's spells
+	int attack, defence, power, knowledge; //main hero's attributes
+	unsigned int experience; //hero's experience points
+	std::vector<CAbility *> abilities; //hero's abilities
+	std::vector<int> abilityLevels; //hero ability levels
+};
+
 class CObject //typical object that can be encountered on a map
 {
 public:

+ 95 - 0
CPreGameTextHandler.cpp

@@ -124,4 +124,99 @@ void CPreGameTextHandler::loadTexts()
 	}
 	mainQuit = buf.substr(befi, i-befi);
 	++i;
+
+	hmcr = 0;
+	for(i; i<andame; ++i)
+	{
+		if(buf[i]=='\r')
+			++hmcr;
+		if(hmcr==3)
+			break;
+	}
+	i+=3;
+
+	befi=i;
+	for(i; i<andame; ++i)
+	{
+		if(buf[i]=='\t')
+			break;
+	}
+	ngSingleScenario = buf.substr(befi, i-befi);
+	++i;
+
+	hmcr = 0;
+	for(i; i<andame; ++i)
+	{
+		if(buf[i]=='\r')
+			++hmcr;
+		if(hmcr==1)
+			break;
+	}
+	i+=3;
+
+	befi=i;
+	for(i; i<andame; ++i)
+	{
+		if(buf[i]=='\t')
+			break;
+	}
+	ngCampain = buf.substr(befi, i-befi);
+	++i;
+
+	hmcr = 0;
+	for(i; i<andame; ++i)
+	{
+		if(buf[i]=='\r')
+			++hmcr;
+		if(hmcr==1)
+			break;
+	}
+	i+=3;
+
+	befi=i;
+	for(i; i<andame; ++i)
+	{
+		if(buf[i]=='\t')
+			break;
+	}
+	ngMultiplayer = buf.substr(befi, i-befi);
+	++i;
+
+	hmcr = 0;
+	for(i; i<andame; ++i)
+	{
+		if(buf[i]=='\r')
+			++hmcr;
+		if(hmcr==1)
+			break;
+	}
+	i+=3;
+
+	befi=i;
+	for(i; i<andame; ++i)
+	{
+		if(buf[i]=='\t')
+			break;
+	}
+	ngTutorial = buf.substr(befi, i-befi);
+	++i;
+
+	hmcr = 0;
+	for(i; i<andame; ++i)
+	{
+		if(buf[i]=='\r')
+			++hmcr;
+		if(hmcr==1)
+			break;
+	}
+	i+=3;
+
+	befi=i;
+	for(i; i<andame; ++i)
+	{
+		if(buf[i]=='\t')
+			break;
+	}
+	ngBack = buf.substr(befi, i-befi);
+	++i;
 }

+ 1 - 0
CPreGameTextHandler.h

@@ -7,6 +7,7 @@ class CPreGameTextHandler //handles pre - game texts
 {
 public:
 	std::string mainNewGame, mainLoadGame, mainHighScores, mainCredits, mainQuit; //right - click texts in main menu
+	std::string ngSingleScenario, ngCampain, ngMultiplayer, ngTutorial, ngBack; //right - click texts in new game menu
 	std::string getTitle(std::string text);
 	std::string getDescr(std::string text);
 	void loadTexts();

BIN
h3m.txt