mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	* part of new object randomizing; make it work (I mean moving the last hero on your Arrogance2 - it doesn't wotk and I don't know why)
This commit is contained in:
		
							
								
								
									
										5
									
								
								CMT.cpp
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								CMT.cpp
									
									
									
									
									
								
							| @@ -713,7 +713,10 @@ int _tmain(int argc, _TCHAR* argv[]) | ||||
| 		initGameState(cgi); | ||||
| 		THC std::cout<<"Initializing GameState: "<<tmh.getDif()<<std::endl; | ||||
|  | ||||
|  | ||||
| 		/*for(int d=0; d<PLAYER_LIMIT; ++d) | ||||
| 		{ | ||||
| 			cgi->playerint.push_back(NULL); | ||||
| 		}*/ | ||||
| 		for (int i=0; i<cgi->scenarioOps.playerInfos.size();i++) //initializing interfaces | ||||
| 		{  | ||||
|  | ||||
|   | ||||
| @@ -143,37 +143,31 @@ void CSDL_Ext::printAt(std::string text, int x, int y, TTF_Font * font, SDL_Colo | ||||
| } | ||||
| void CSDL_Ext::SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC, Uint8 A) | ||||
| { | ||||
|      Uint8 *p = (Uint8 *)ekran->pixels + y * ekran->pitch + x * ekran->format->BytesPerPixel-myC; | ||||
|      if(SDL_BYTEORDER == SDL_BIG_ENDIAN) | ||||
|      { | ||||
|           p[0] = R; | ||||
|           p[1] = G; | ||||
|           p[2] = B; | ||||
|      } | ||||
|      else | ||||
|      { | ||||
|           p[0] = B; | ||||
|           p[1] = G; | ||||
|           p[2] = R; | ||||
|      } | ||||
|      SDL_UpdateRect(ekran, x, y, 1, 1); | ||||
| 	Uint8 *p = (Uint8 *)ekran->pixels + y * ekran->pitch + x * ekran->format->BytesPerPixel-myC; | ||||
| #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) | ||||
| 	p[0] = R; | ||||
| 	p[1] = G; | ||||
| 	p[2] = B; | ||||
| #else | ||||
| 	p[0] = B; | ||||
| 	p[1] = G; | ||||
| 	p[2] = R; | ||||
| #endif | ||||
| 	SDL_UpdateRect(ekran, x, y, 1, 1); | ||||
| } | ||||
|  | ||||
| void CSDL_Ext::SDL_PutPixelWithoutRefresh(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC, Uint8 A) | ||||
| { | ||||
|      Uint8 *p = (Uint8 *)ekran->pixels + y * ekran->pitch + x * ekran->format->BytesPerPixel-myC; | ||||
|      if(SDL_BYTEORDER == SDL_BIG_ENDIAN) | ||||
|      { | ||||
|           p[0] = B; | ||||
|           p[1] = G; | ||||
|           p[2] = R; | ||||
|      } | ||||
|      else | ||||
|      { | ||||
|           p[0] = R; | ||||
|           p[1] = G; | ||||
|           p[2] = B; | ||||
|      } | ||||
| #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) | ||||
| 	p[0] = B; | ||||
| 	p[1] = G; | ||||
| 	p[2] = R; | ||||
| #else | ||||
| 	p[0] = R; | ||||
| 	p[1] = G; | ||||
| 	p[2] = B; | ||||
| #endif | ||||
| } | ||||
|  | ||||
| ///**************/ | ||||
| @@ -192,14 +186,11 @@ SDL_Surface * CSDL_Ext::rotate01(SDL_Surface * toRot, int myC) | ||||
| 			{ | ||||
| 				{ | ||||
| 					Uint8 *p = (Uint8 *)toRot->pixels + j * toRot->pitch + (ret->w - i - 1) * toRot->format->BytesPerPixel; | ||||
| 					if(SDL_BYTEORDER == SDL_BIG_ENDIAN) | ||||
| 					{ | ||||
| #if(SDL_BYTEORDER == SDL_BIG_ENDIAN) | ||||
| 						CSDL_Ext::SDL_PutPixel(ret, i, j, p[0], p[1], p[2], myC); | ||||
| 					} | ||||
| 					else | ||||
| 					{ | ||||
| #else | ||||
| 						CSDL_Ext::SDL_PutPixel(ret, i, j, p[2], p[1], p[0], myC); | ||||
| 					} | ||||
| #endif | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| @@ -234,14 +225,11 @@ SDL_Surface * CSDL_Ext::hFlip(SDL_Surface * toRot) | ||||
| 				{ | ||||
| 					Uint8 *p = (Uint8 *)toRot->pixels + (ret->h - j -1) * toRot->pitch + i * toRot->format->BytesPerPixel-2; | ||||
| 					int k=2; | ||||
| 					if(SDL_BYTEORDER == SDL_BIG_ENDIAN) | ||||
| 					{ | ||||
| #if(SDL_BYTEORDER == SDL_BIG_ENDIAN) | ||||
| 						CSDL_Ext::SDL_PutPixel(ret, i, j, p[0], p[1], p[2], k); | ||||
| 					} | ||||
| 					else | ||||
| 					{ | ||||
| #else | ||||
| 						CSDL_Ext::SDL_PutPixel(ret, i, j, p[2], p[1], p[0], k); | ||||
| 					} | ||||
| #endif | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| @@ -277,14 +265,11 @@ SDL_Surface * CSDL_Ext::rotate02(SDL_Surface * toRot) | ||||
| 		{ | ||||
| 			{ | ||||
| 				Uint8 *p = (Uint8 *)toRot->pixels + i * toRot->pitch + j * toRot->format->BytesPerPixel; | ||||
| 				if(SDL_BYTEORDER == SDL_BIG_ENDIAN) | ||||
| 				{ | ||||
| #if(SDL_BYTEORDER == SDL_BIG_ENDIAN) | ||||
| 					SDL_PutPixel(ret, i, j, p[0], p[1], p[2]); | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
| #else | ||||
| 					SDL_PutPixel(ret, i, j, p[2], p[1], p[0]); | ||||
| 				} | ||||
| #endif | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| @@ -308,14 +293,11 @@ SDL_Surface * CSDL_Ext::rotate03(SDL_Surface * toRot) | ||||
| 			{ | ||||
| 				{ | ||||
| 					Uint8 *p = (Uint8 *)toRot->pixels + (ret->h - j - 1) * toRot->pitch + (ret->w - i - 1) * toRot->format->BytesPerPixel+2; | ||||
| 					if(SDL_BYTEORDER == SDL_BIG_ENDIAN) | ||||
| 					{ | ||||
| #if(SDL_BYTEORDER == SDL_BIG_ENDIAN) | ||||
| 						SDL_PutPixel(ret, i, j, p[0], p[1], p[2], 2); | ||||
| 					} | ||||
| 					else | ||||
| 					{ | ||||
| #else | ||||
| 						SDL_PutPixel(ret, i, j, p[2], p[1], p[0], 2); | ||||
| 					} | ||||
| #endif | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| @@ -392,10 +374,11 @@ Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, int x, int y, bool colorByte | ||||
|         return *(Uint16 *)p; | ||||
|  | ||||
|     case 3: | ||||
|         if(SDL_BYTEORDER == SDL_BIG_ENDIAN) | ||||
| #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) | ||||
|             return p[0] << 16 | p[1] << 8 | p[2]; | ||||
|         else | ||||
| #else | ||||
|             return p[0] | p[1] << 8 | p[2] << 16; | ||||
| #endif | ||||
|  | ||||
|     case 4: | ||||
|         return *(Uint32 *)p; | ||||
|   | ||||
| @@ -930,6 +930,7 @@ void CAmbarCendamo::deh3m() | ||||
| 				spec->myInstance = nhi; | ||||
| 				//nobj->isHero = true; | ||||
| 				(static_cast<CGHeroInstance*>(nobj))->moveDir = 4; | ||||
| 				nhi->isStanding = true; | ||||
| 				nhi->exp = spec->experience; | ||||
| 				nhi->level = CGI->heroh->level(nhi->exp); | ||||
| 				nhi->primSkills.resize(PRIMARY_SKILLS); | ||||
| @@ -1944,7 +1945,7 @@ void CAmbarCendamo::deh3m() | ||||
| 	}//*/ //end of loading objects; commented to make application work until it will be finished | ||||
| 	////objects loaded | ||||
|  | ||||
| 	processMap(defsToUnpack); | ||||
| 	//processMap(defsToUnpack); | ||||
| 	std::vector<CDefHandler *> dhandlers = CGameInfo::mainObj->spriteh->extractManyFiles(defsToUnpack); | ||||
| 	for (int i=0;i<dhandlers.size();i++) | ||||
| 		map.defy[i]->handler=dhandlers[i]; | ||||
|   | ||||
| @@ -19,6 +19,8 @@ void CDefObjInfoHandler::load() | ||||
| 		DefObjInfo nobj; | ||||
| 		std::string dump; | ||||
| 		inp>>nobj.defName; | ||||
| 		 | ||||
| 		std::transform(nobj.defName.begin(), nobj.defName.end(), nobj.defName.begin(), (int(*)(int))toupper); | ||||
|  | ||||
| 		for(int o=0; o<6; ++o) | ||||
| 		{ | ||||
|   | ||||
							
								
								
									
										226
									
								
								mapHandler.cpp
									
									
									
									
									
								
							
							
						
						
									
										226
									
								
								mapHandler.cpp
									
									
									
									
									
								
							| @@ -10,6 +10,7 @@ | ||||
| #include <algorithm> | ||||
| #include "CGameState.h" | ||||
| #include "CLua.h" | ||||
| #include "hch\CCastleHandler.h" | ||||
| #include "hch/CHeroHandler.h" | ||||
| extern SDL_Surface * ekran; | ||||
|  | ||||
| @@ -24,6 +25,54 @@ public: | ||||
|  | ||||
| void CMapHandler::init() | ||||
| { | ||||
| 	///////////////randomizing objects on map/////////////////////////// | ||||
|  | ||||
| 	for(int no=0; no<CGI->objh->objInstances.size(); ++no) | ||||
| 	{ | ||||
| 		std::string nname = getRandomizedDefName(CGI->objh->objInstances[no]->defInfo, CGI->objh->objInstances[no]); | ||||
| 		if(nname.size()>0) //change def | ||||
| 		{ | ||||
| 			int f=-1; | ||||
| 			for(f=0; f<CGI->dobjinfo->objs.size(); ++f) | ||||
| 			{ | ||||
| 				if(CGI->dobjinfo->objs[f].defName==nname) | ||||
| 				{ | ||||
| 					break; | ||||
| 				} | ||||
| 			} | ||||
| 			CGI->objh->objInstances[no]->defInfo->name = nname; | ||||
| 			if(loadedDefs.find(nname)!=loadedDefs.end()) | ||||
| 			{ | ||||
| 				CGI->objh->objInstances[no]->defInfo->handler = loadedDefs.find(nname)->second; | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				CGI->objh->objInstances[no]->defInfo->handler = CGI->spriteh->giveDef(nname); | ||||
| 				for(int dd=0; dd<CGI->objh->objInstances[no]->defInfo->handler->ourImages.size(); ++dd) | ||||
| 				{ | ||||
| 					CSDL_Ext::fullAlphaTransform(CGI->objh->objInstances[no]->defInfo->handler->ourImages[dd].bitmap); | ||||
| 				} | ||||
| 				loadedDefs.insert(std::pair<std::string, CDefHandler*>(nname, CGI->objh->objInstances[no]->defInfo->handler)); | ||||
| 			} | ||||
| 			CGI->objh->objInstances[no]->defObjInfoNumber = f; | ||||
| 			if(f!=-1) | ||||
| 			{ | ||||
| 				CGI->objh->objInstances[no]->defInfo->isOnDefList = true; | ||||
| 				CGI->objh->objInstances[no]->ID = CGI->dobjinfo->objs[f].type; | ||||
| 				CGI->objh->objInstances[no]->subID = CGI->dobjinfo->objs[f].subtype; | ||||
| 				CGI->objh->objInstances[no]->defInfo->id = CGI->dobjinfo->objs[f].type; | ||||
| 				CGI->objh->objInstances[no]->defInfo->subid = CGI->dobjinfo->objs[f].subtype; | ||||
| 				CGI->objh->objInstances[no]->defInfo->printPriority = CGI->dobjinfo->objs[f].priority; | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				CGI->objh->objInstances[no]->defInfo->isOnDefList = false; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	///////////////objects randomized/////////////////////////////////// | ||||
|  | ||||
| 	for(int h=0; h<reader->map.defy.size(); ++h) //initializing loaded def handler's info | ||||
| 	{ | ||||
| 		std::string hlp = reader->map.defy[h]->name; | ||||
| @@ -425,7 +474,7 @@ void CMapHandler::init() | ||||
| 				cr.y = fy*32; | ||||
| 				std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> toAdd = std::make_pair(CGI->objh->objInstances[f], std::make_pair(cr, std::vector<std::list<int3>>())); | ||||
| 				///initializing places that will be coloured by blitting (flag colour / player colour positions) | ||||
| 				if(toAdd.first->defObjInfoNumber>=0 && CGI->dobjinfo->objs[toAdd.first->defObjInfoNumber].isVisitable()) | ||||
| 				if(toAdd.first->defInfo->isVisitable()) | ||||
| 				{ | ||||
| 					toAdd.second.second.resize(toAdd.first->defInfo->handler->ourImages.size()); | ||||
| 					for(int no = 0; no<toAdd.first->defInfo->handler->ourImages.size(); ++no) | ||||
| @@ -467,8 +516,6 @@ void CMapHandler::init() | ||||
| 	} // for(int f=0; f<CGI->objh->objInstances.size(); ++f) | ||||
| 	for(int f=0; f<CGI->objh->objInstances.size(); ++f) //calculationg blocked / visitable positions | ||||
| 	{	 | ||||
| 		if(CGI->objh->objInstances[f]->defObjInfoNumber == -1) | ||||
| 			continue; | ||||
| 		CDefHandler * curd = CGI->objh->objInstances[f]->defInfo->handler; | ||||
| 		for(int fx=0; fx<8; ++fx) | ||||
| 		{ | ||||
| @@ -480,9 +527,9 @@ void CMapHandler::init() | ||||
| 				if(xVal>=0 && xVal<ttiles.size()-Woff && yVal>=0 && yVal<ttiles[0].size()-Hoff) | ||||
| 				{ | ||||
| 					TerrainTile2 & curt = ttiles[xVal][yVal][zVal]; | ||||
| 					if(((CGI->dobjinfo->objs[CGI->objh->objInstances[f]->defObjInfoNumber].visitMap[fy] >> (7 - fx)) & 1)) | ||||
| 					if(((CGI->objh->objInstances[f]->defInfo->visitMap[fy] >> (7 - fx)) & 1)) | ||||
| 						curt.visitable = true; | ||||
| 					if(!((CGI->dobjinfo->objs[CGI->objh->objInstances[f]->defObjInfoNumber].blockMap[fy] >> (7 - fx)) & 1)) | ||||
| 					if(!((CGI->objh->objInstances[f]->defInfo->blockMap[fy] >> (7 - fx)) & 1)) | ||||
| 						curt.blocked = true; | ||||
| 				} | ||||
| 			} | ||||
| @@ -1493,7 +1540,7 @@ bool CMapHandler::printObject(CGObjectInstance *obj) | ||||
| 			cr.y = fy*32; | ||||
| 			std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> toAdd = std::make_pair(obj, std::make_pair(cr, std::vector<std::list<int3>>())); | ||||
| 			///initializing places that will be coloured by blitting (flag colour / player colour positions) | ||||
| 			if(toAdd.first->defObjInfoNumber>=0 && CGI->dobjinfo->objs[toAdd.first->defObjInfoNumber].isVisitable()) | ||||
| 			if(CGI->dobjinfo->objs[toAdd.first->defObjInfoNumber].isVisitable()) | ||||
| 			{ | ||||
| 				toAdd.second.second.resize(toAdd.first->defInfo->handler->ourImages.size()); | ||||
| 				for(int no = 0; no<toAdd.first->defInfo->handler->ourImages.size(); ++no) | ||||
| @@ -1555,4 +1602,169 @@ bool CMapHandler::hideObject(CGObjectInstance *obj) | ||||
| 		} // for(int fy=0; fy<curd->ourImages[0].bitmap->h/32; ++fy) | ||||
| 	} //for(int fx=0; fx<curd->ourImages[0].bitmap->w/32; ++fx) | ||||
| 	return true; | ||||
| } | ||||
| } | ||||
|  | ||||
| std::string CMapHandler::getRandomizedDefName(CGDefInfo *di, CGObjectInstance * obj) | ||||
| { | ||||
| 	if(di->id==76) //random resource | ||||
| 	{ | ||||
| 		std::vector<std::string> resDefNames; | ||||
| 		resDefNames.push_back("AVTRNDM0.DEF"); | ||||
| 		resDefNames.push_back("AVTWOOD0.DEF"); | ||||
| 		resDefNames.push_back("AVTMERC0.DEF"); | ||||
| 		resDefNames.push_back("AVTORE0.DEF"); | ||||
| 		resDefNames.push_back("AVTSULF0.DEF"); | ||||
| 		resDefNames.push_back("AVTCRYS0.DEF"); | ||||
| 		resDefNames.push_back("AVTGEMS0.DEF"); | ||||
| 		resDefNames.push_back("AVTGOLD0.DEF"); | ||||
| 		resDefNames.push_back("ZMITHR.DEF"); | ||||
| 		return resDefNames[rand()%resDefNames.size()]; | ||||
| 	} | ||||
| 	else if(di->id==72 || di->id==73 || di->id==74 || di->id==75 || di->id==162 || di->id==163 || di->id==164 || di->id==71) //random monster | ||||
| 	{ | ||||
| 		std::vector<std::string> creDefNames; | ||||
| 		for(int dd=0; dd<140; ++dd) //we do not use here WoG units | ||||
| 		{ | ||||
| 			creDefNames.push_back(CGI->dobjinfo->objs[dd+1184].defName); | ||||
| 		} | ||||
|  | ||||
| 		switch(di->id) | ||||
| 		{ | ||||
| 		case 72: //level 1 | ||||
| 			return creDefNames[14*(rand()%9)+rand()%2]; | ||||
| 		case 73: //level 2 | ||||
| 			return creDefNames[14*(rand()%9)+rand()%2+2]; | ||||
| 		case 74: //level 3 | ||||
| 			return creDefNames[14*(rand()%9)+rand()%2+4]; | ||||
| 		case 75: //level 4 | ||||
| 			return creDefNames[14*(rand()%9)+rand()%2+6]; | ||||
| 		case 162: //level 5 | ||||
| 			return creDefNames[14*(rand()%9)+rand()%2+8]; | ||||
| 		case 163: //level 6 | ||||
| 			return creDefNames[14*(rand()%9)+rand()%2+10]; | ||||
| 		case 164: //level 7 | ||||
| 			return creDefNames[14*(rand()%9)+rand()%2+12]; | ||||
| 		case 71: // any level | ||||
| 			return creDefNames[rand()%126]; | ||||
| 		} | ||||
| 	} | ||||
| 	else if(di->id==65) //random artifact (any class) | ||||
| 	{ | ||||
| 		std::vector<std::string> artDefNames; | ||||
| 		for(int bb=0; bb<162; ++bb) | ||||
| 		{ | ||||
| 			if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass!=EartClass::SartClass) | ||||
| 				artDefNames.push_back(CGI->dobjinfo->objs[bb+213].defName); | ||||
| 		} | ||||
| 		return artDefNames[rand()%artDefNames.size()]; | ||||
| 	} | ||||
| 	else if(di->id==66) //random artifact (treasure) | ||||
| 	{ | ||||
| 		std::vector<std::string> art1DefNames; | ||||
| 		for(int bb=0; bb<162; ++bb) | ||||
| 		{ | ||||
| 			if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::TartClass) | ||||
| 				art1DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName); | ||||
| 		} | ||||
| 		return art1DefNames[rand()%art1DefNames.size()]; | ||||
| 	} | ||||
| 	else if(di->id==67) //random artifact (minor) | ||||
| 	{ | ||||
| 		std::vector<std::string> art2DefNames; | ||||
| 		for(int bb=0; bb<162; ++bb) | ||||
| 		{ | ||||
| 			if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::NartClass) | ||||
| 				art2DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName); | ||||
| 		} | ||||
| 		return art2DefNames[rand()%art2DefNames.size()]; | ||||
| 	} | ||||
| 	else if(di->id==68) //random artifact (major) | ||||
| 	{ | ||||
| 		std::vector<std::string> art3DefNames; | ||||
| 		for(int bb=0; bb<162; ++bb) | ||||
| 		{ | ||||
| 			if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::JartClass) | ||||
| 				art3DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName); | ||||
| 		} | ||||
| 		return art3DefNames[rand()%art3DefNames.size()]; | ||||
| 	} | ||||
| 	else if(di->id==69) //random artifact (relic) | ||||
| 	{ | ||||
| 		std::vector<std::string> art4DefNames; | ||||
| 		for(int bb=0; bb<162; ++bb) | ||||
| 		{ | ||||
| 			if(CGI->arth->artifacts[CGI->dobjinfo->objs[bb+213].subtype].aClass==EartClass::RartClass) | ||||
| 				art4DefNames.push_back(CGI->dobjinfo->objs[bb+213].defName); | ||||
| 		} | ||||
| 		return art4DefNames[rand()%art4DefNames.size()]; | ||||
| 	} | ||||
| 	else if(di->id==77) //random town | ||||
| 	{ | ||||
| 		if(!obj) | ||||
| 			return std::string(); //obj is necessary! | ||||
| 		std::vector<std::string> town0DefNames; //without fort | ||||
| 		town0DefNames.push_back("AVCCAST0.DEF"); | ||||
| 		town0DefNames.push_back("AVCRAMP0.DEF"); | ||||
| 		town0DefNames.push_back("AVCTOWR0.DEF"); | ||||
| 		town0DefNames.push_back("AVCINFT0.DEF"); | ||||
| 		town0DefNames.push_back("AVCNECR0.DEF"); | ||||
| 		town0DefNames.push_back("AVCDUNG0.DEF"); | ||||
| 		town0DefNames.push_back("AVCSTRO0.DEF"); | ||||
| 		town0DefNames.push_back("AVCFTRT0.DEF"); | ||||
| 		town0DefNames.push_back("AVCHFOR0.DEF"); | ||||
|  | ||||
| 		std::vector<std::string> town1DefNames; //with fort | ||||
| 		for(int dd=0; dd<F_NUMBER; ++dd) | ||||
| 		{ | ||||
| 			town1DefNames.push_back(CGI->dobjinfo->objs[dd+385].defName); | ||||
| 		} | ||||
|  | ||||
| 		std::vector<std::string> town2DefNames; //with capitol | ||||
| 		for(int dd=0; dd<F_NUMBER; ++dd) | ||||
| 		{ | ||||
| 			town2DefNames.push_back(CGI->dobjinfo->objs[dd+385].defName); | ||||
| 		} | ||||
| 		for(int b=0; b<town2DefNames.size(); ++b) | ||||
| 		{ | ||||
| 			for(int q=0; q<town2DefNames[b].size(); ++q) | ||||
| 			{ | ||||
| 				if(town2DefNames[b][q]=='x' || town2DefNames[b][q]=='X') | ||||
| 					town2DefNames[b][q] = 'Z'; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		//TODO: use capitol defs | ||||
|  | ||||
| 		//variables initialized | ||||
|  | ||||
| 		if(obj->tempOwner==0xff) //no preselected preferentions | ||||
| 		{ | ||||
| 			if(((CCastleObjInfo*)obj->info)->hasFort) | ||||
| 				return town1DefNames[rand()%town1DefNames.size()]; | ||||
| 			else | ||||
| 				return town0DefNames[rand()%town0DefNames.size()]; | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			 | ||||
| 			if(CGI->scenarioOps.getIthPlayersSettings(((CCastleObjInfo*)obj->info)->player).castle>-1) //castle specified in start options | ||||
| 			{ | ||||
| 				int defnr = CGI->scenarioOps.getIthPlayersSettings(((CCastleObjInfo*)obj->info)->player).castle; | ||||
| 				if(((CCastleObjInfo*)obj->info)->hasFort) | ||||
| 					return town1DefNames[defnr]; | ||||
| 				else | ||||
| 					return town0DefNames[defnr]; | ||||
| 			} | ||||
| 			else //no castle specified | ||||
| 			{ | ||||
| 				int defnr = rand()%F_NUMBER; | ||||
| 				if(((CCastleObjInfo*)obj->info)->hasFort) | ||||
| 					return town1DefNames[defnr]; | ||||
| 				else | ||||
| 					return town0DefNames[defnr]; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return std::string(); | ||||
| } | ||||
|   | ||||
| @@ -90,6 +90,7 @@ public: | ||||
| 	SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap = CGI->mh->visibility); | ||||
| 	SDL_Surface * terrBitmap(int x, int y); | ||||
| 	SDL_Surface * undTerrBitmap(int x, int y); | ||||
| 	std::string getRandomizedDefName(CGDefInfo* di, CGObjectInstance * obj = NULL); //objinstance needed only for heroes and towns | ||||
|  | ||||
| }; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user