2
0
Эх сурвалжийг харах

* close button properly closes (same does 'q' key)
* two players can't have selected same hero
* double click on "Show Avalible Scenarios" won't reset options
* fixed crashbug in town/hero lists
* fixed crashbug in initializing game caused by wrong prisons handling
* fixed crashbug on reading custom artifacts in RoE map
* fixed crashbug on reading custom pandora's box in RoE map
* fixed crashbug on reading blank quest guards
* improved console messages


Ufff....

Michał W. Urbańczyk 17 жил өмнө
parent
commit
847126f57a

+ 1 - 1
AdventureMapButton.h

@@ -165,9 +165,9 @@ void CTownList<T>::genList()
 template<typename T>
 void CTownList<T>::select(int which)
 {
-	selected = which;
 	if (which>=items.size()) 
 		return;
+	selected = which;
 	if(owner)
 		(owner->*fun)();
 }

+ 27 - 7
CMT.cpp

@@ -146,12 +146,24 @@ void initGameState(CGameInfo * cgi)
 		//initial army
 		if (!vhi->army.slots.size())
 		{
+			int pom;
 			vhi->army.slots[0].first = &(cgi->creh->creatures[(cgi->creh->nameToID[vhi->type->refType1stack])]);
-			vhi->army.slots[0].second = (rand()%(vhi->type->high1stack-vhi->type->low1stack))+vhi->type->low1stack;
+			if((pom = (vhi->type->high1stack-vhi->type->low1stack)) > 0)
+				vhi->army.slots[0].second = (rand()%pom)+vhi->type->low1stack;
+			else 
+				vhi->army.slots[0].second = +vhi->type->low1stack;
+
 			vhi->army.slots[1].first = &(cgi->creh->creatures[(cgi->creh->nameToID[vhi->type->refType2stack])]);
-			vhi->army.slots[1].second = (rand()%(vhi->type->high2stack-vhi->type->low2stack))+vhi->type->low2stack;
+			if((pom=(vhi->type->high2stack-vhi->type->low2stack))>0)
+				vhi->army.slots[1].second = (rand()%pom)+vhi->type->low2stack;
+			else
+				vhi->army.slots[1].second = vhi->type->low2stack;
+
 			vhi->army.slots[2].first = &(cgi->creh->creatures[(cgi->creh->nameToID[vhi->type->refType3stack])]);
-			vhi->army.slots[2].second = (rand()%(vhi->type->high3stack-vhi->type->low3stack))+vhi->type->low3stack;
+			if((pom=(vhi->type->high3stack-vhi->type->low3stack))>0)
+				vhi->army.slots[2].second = (rand()%pom)+vhi->type->low3stack;
+			else
+				vhi->army.slots[2].second = vhi->type->low3stack;
 		}
 
 		cgi->state->players[vhi->getOwner()].heroes.push_back(vhi);
@@ -691,8 +703,15 @@ int _tmain(int argc, _TCHAR* argv[])
 		THC std::cout<<"Handlers initailization: "<<tmh.getDif()<<std::endl;
 
 		std::string mapname;
-		if(CPG->ourScenSel->mapsel.selected==0) CPG->ourScenSel->mapsel.selected = 1; //only for tests
-		if (CPG) mapname = CPG->ourScenSel->mapsel.ourMaps[CPG->ourScenSel->mapsel.selected].filename;
+		//if(CPG->ourScenSel->mapsel.selected==0) 
+		//	CPG->ourScenSel->mapsel.selected = 1; //only for tests
+		if (CPG) 
+			mapname = CPG->ourScenSel->mapsel.ourMaps[CPG->ourScenSel->mapsel.selected].filename;
+		else
+		{
+			std::cout<<"Critical error: CPG==NULL"<<std::endl;
+		}
+		std::cout<<"Opening map file: "<<mapname<<"\t\t"<<std::flush;
 		gzFile map = gzopen(mapname.c_str(),"rb");
 		std::string mapstr;int pom;
 		while((pom=gzgetc(map))>=0)
@@ -705,13 +724,14 @@ int _tmain(int argc, _TCHAR* argv[])
 		{
 			initTable[ss] = mapstr[ss];
 		}
+		std::cout<<"done."<<std::endl;
 #define CHOOSE
 #ifdef CHOOSE
 		CAmbarCendamo * ac = new CAmbarCendamo(initTable); //4gryf
 #else
 		CAmbarCendamo * ac = new CAmbarCendamo("RoEtest"); //4gryf
 #endif
-		CMapHeader * mmhh = new CMapHeader(ac->bufor); //czytanie nag³ówka
+		//CMapHeader * mmhh = new CMapHeader(ac->bufor); //czytanie nag³ówka
 		cgi->ac = ac;
 		THC std::cout<<"Reading file: "<<tmh.getDif()<<std::endl;
 		ac->deh3m();
@@ -723,7 +743,7 @@ int _tmain(int argc, _TCHAR* argv[])
 		mh->reader = ac;
 		THC std::cout<<"Creating mapHandler: "<<tmh.getDif()<<std::endl;
 		mh->init();
-		THC std::cout<<"Initializing mapHandler: "<<tmh.getDif()<<std::endl;
+		THC std::cout<<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl;
 
 		initGameState(cgi);
 		THC std::cout<<"Initializing GameState: "<<tmh.getDif()<<std::endl;

+ 1 - 1
CPlayerInterface.cpp

@@ -2030,9 +2030,9 @@ void CHeroList::genList()
 }
 void CHeroList::select(int which)
 {
-	selected = which;
 	if (which>=items.size()) 
 		return;
+	selected = which;
 	LOCPLINT->adventureInt->centerOn(items[which].first->pos);
 	LOCPLINT->adventureInt->selection.type = HEROI_TYPE;
 	LOCPLINT->adventureInt->selection.selected = items[which].first;

BIN
CPreGame.cpp


+ 24 - 7
hch/CAmbarCendamo.cpp

@@ -128,6 +128,7 @@ std::set<int> convertBuildings(const std::set<int> h3m, int castleID)
 void CAmbarCendamo::deh3m()
 {
 	THC timeHandler th;
+	th.getDif();
 	map.version = (Eformat)bufor[0]; //wersja mapy
 	map.areAnyPLayers = bufor[4]; //invalid on some maps
 	map.height = map.width = bufor[5]; // wymiary mapy
@@ -468,7 +469,7 @@ void CAmbarCendamo::deh3m()
 	}
 	//allowed hero's abilities have been read
 
-	THC std::cout<<"Reading header: "<<th.getDif()<<std::endl;
+	THC std::cout<<"\tReading header: "<<th.getDif()<<std::endl;
 	int rumNr = readNormalNr(i,4);i+=4;
 	for (int it=0;it<rumNr;it++)
 	{
@@ -481,7 +482,7 @@ void CAmbarCendamo::deh3m()
 			ourRumor.text+=bufor[i++];
 		map.rumors.push_back(ourRumor); //add to our list
 	}
-	THC std::cout<<"Reading rumors: "<<th.getDif()<<std::endl;
+	THC std::cout<<"\tReading rumors: "<<th.getDif()<<std::endl;
 	switch(map.version)
 	{
 	case WoG: case SoD: case AB:
@@ -544,7 +545,7 @@ void CAmbarCendamo::deh3m()
 			}
 		}
 	}
-	THC std::cout<<"Reading terrain: "<<th.getDif()<<std::endl;
+	THC std::cout<<"\tReading terrain: "<<th.getDif()<<std::endl;
 	int defAmount = bufor[i]; // liczba defow
 	defAmount = readNormalNr(i);
 	i+=4;
@@ -609,7 +610,7 @@ void CAmbarCendamo::deh3m()
 		map.defy.push_back(vinya); // add this def to the vector
 		defsToUnpack.push_back(vinya->name);
 	}
-	THC std::cout<<"Reading defs: "<<th.getDif()<<std::endl;
+	THC std::cout<<"\tReading defs: "<<th.getDif()<<std::endl;
 	////loading objects
 	int howManyObjs = readNormalNr(i, 4); i+=4;
 	for(int ww=0; ww<howManyObjs; ++ww) //comment this line to turn loading objects off
@@ -915,7 +916,7 @@ void CAmbarCendamo::deh3m()
 					{
 						for(int ss=0; ss<amount; ++ss)
 						{
-							id = readNormalNr(i, artidlen); i+=2;
+							id = readNormalNr(i, artidlen); i+=artidlen;
 							if(id!=artmask)
 								spec->artifacts.push_back(&(CGameInfo::mainObj->arth->artifacts[id]));
 							else
@@ -1069,7 +1070,11 @@ void CAmbarCendamo::deh3m()
 				{
 					nhi->secSkills.push_back(std::make_pair(spec->abilities[qq]->idNumber, spec->abilityLevels[qq]-1));
 				}
-				CGI->heroh->heroInstances.push_back(nhi);
+				if(nhi->ID==34)
+					CGI->heroh->heroInstances.push_back(nhi);
+				else
+					CGI->objh->objInstances.push_back(nhi);
+
 				break;
 			}
 		case CREATURES_DEF:
@@ -2046,7 +2051,9 @@ void CAmbarCendamo::deh3m()
 				}
 				int gcre = readNormalNr(i, 1); ++i; //number of gained creatures
 				spec->creatures = readCreatureSet(i, gcre); i+=4*gcre;
-				i+=8;
+				i+=7;
+				if(map.version > RoE)
+					i++;
 				nobj->info = spec;
 				///////end of copied fragment
 				break;
@@ -2131,6 +2138,11 @@ void CAmbarCendamo::deh3m()
 				spec->missionType = bufor[i]; ++i;
 				switch(spec->missionType)
 				{
+				case 0:
+					{
+						goto borderguardend;
+						break;
+					}
 				case 1:
 					{
 						spec->m1level = readNormalNr(i); i+=4;
@@ -2323,6 +2335,7 @@ void CAmbarCendamo::deh3m()
 					spec->completedText += bufor[i]; ++i;
 				}
 				nobj->info = spec;
+borderguardend:
 				break;
 			}
 		case EDefType::HEROPLACEHOLDER_DEF:
@@ -2336,8 +2349,11 @@ void CAmbarCendamo::deh3m()
 	}//*/ //end of loading objects; commented to make application work until it will be finished
 	////objects loaded
 
+	THC std::cout<<"\tReading objects: "<<th.getDif()<<std::endl;
 	//processMap(defsToUnpack);
 	std::vector<CDefHandler *> dhandlers = CGameInfo::mainObj->spriteh->extractManyFiles(defsToUnpack);
+	
+	THC std::cout<<"\tUnpacking defs: "<<th.getDif()<<std::endl;
 	for (int i=0;i<dhandlers.size();i++)
 		map.defy[i]->handler=dhandlers[i];
 	for(int vv=0; vv<map.defy.size(); ++vv)
@@ -2370,6 +2386,7 @@ void CAmbarCendamo::deh3m()
 		}
 	}
 
+	THC std::cout<<"\tHandling defs: "<<th.getDif()<<std::endl;
 	//for(int ww=0; ww<CGI->objh->objInstances.size(); ++ww)
 	//{
 	//	if (CGI->objh->objInstances[ww]->defObjInfoNumber==-1)

+ 1 - 0
hch/CLodHandler.cpp

@@ -427,6 +427,7 @@ std::vector<CDefHandler *> CLodHandler::extractManyFiles(std::vector<std::string
 	std::vector<char> found(defNamesIn.size(), 0);
 	for (int i=0;i<totalFiles;i++)
 	{
+		//std::cout << "Reading def "<<i<<": "<<entries[i].name<<std::endl;
 		//std::cout<<'\r'<<"Reading defs: "<<(100.0*i)/((float)(totalFiles))<<"%      ";
 		std::string buf1 = std::string((char*)entries[i].name);
 		//std::transform(buf1.begin(), buf1.end(), buf1.begin(), (int(*)(int))toupper);

+ 9 - 0
mapHandler.cpp

@@ -595,7 +595,10 @@ void CMapHandler::calculateBlockedPos()
 }
 void CMapHandler::init()
 {
+	timeHandler th;
+	th.getDif();
 	randomizeObjects();//randomizing objects on map
+	std::cout<<"\tRandomizing objects: "<<th.getDif()<<std::endl;
 
 	for(int h=0; h<reader->map.defy.size(); ++h) //initializing loaded def handler's info
 	{
@@ -603,12 +606,18 @@ void CMapHandler::init()
 		std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper);
 		CGI->mh->loadedDefs.insert(std::make_pair(hlp, reader->map.defy[h]->handler));
 	}
+	std::cout<<"\tCollecting loaded def's handlers: "<<th.getDif()<<std::endl;
 
 	prepareFOWDefs();
 	roadsRiverTerrainInit();	//road's and river's DefHandlers; and simple values initialization
 	borderAndTerrainBitmapInit();
+	std::cout<<"\tPreparing FoW, roads, rivers,borders: "<<th.getDif()<<std::endl;
+
 	initObjectRects();
+	std::cout<<"\tMaking object rects: "<<th.getDif()<<std::endl;
+
 	calculateBlockedPos();
+	std::cout<<"\tCalculating blockmap: "<<th.getDif()<<std::endl;
 }
 
 SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap, bool otherHeroAnim, unsigned char heroAnim)