Browse Source

* buttons can use more than one def
* underground/urface switch button changes look when cliked
* object handler stories pointers to object instances
* new structure for terrain tile - TerrainTile2
* started doing video handlers - unfortunetly they don't work...

Michał W. Urbańczyk 18 năm trước cách đây
mục cha
commit
a3c45bcaa2
14 tập tin đã thay đổi với 558 bổ sung559 xóa
  1. 34 10
      CAdvmapInterface.cpp
  2. 3 3
      CAdvmapInterface.h
  3. 101 101
      CAmbarCendamo.cpp
  4. 5 4
      CGameInterface.cpp
  5. 2 1
      CGameInterface.h
  6. 12 0
      CMT.cpp
  7. 1 1
      CObjectHandler.h
  8. 5 4
      CPathfinder.cpp
  9. 2 1
      CSndHandler.h
  10. 87 0
      CVideoHandler.cpp
  11. 120 0
      CVideoHandler.h
  12. 1 1
      global.h
  13. 149 426
      mapHandler.cpp
  14. 36 7
      mapHandler.h

+ 34 - 10
CAdvmapInterface.cpp

@@ -15,7 +15,7 @@ AdventureMapButton::AdventureMapButton ()
 	state=0;
 }
 AdventureMapButton::AdventureMapButton
-( std::string Name, std::string HelpBox, void(CAdvMapInt::*Function)(), int x, int y, std::string defName, bool activ )
+( std::string Name, std::string HelpBox, void(CAdvMapInt::*Function)(), int x, int y, std::string defName, bool activ, std::vector<std::string> * add )
 {
 	type=2;
 	abs=true;
@@ -28,14 +28,29 @@ AdventureMapButton::AdventureMapButton
 	CDefHandler * temp = CGI->spriteh->giveDef(defName); //todo: moze cieknac
 	for (int i=0;i<temp->ourImages.size();i++)
 	{
-		imgs.push_back(temp->ourImages[i].bitmap);
-		blueToPlayersAdv(imgs[i],LOCPLINT->playerID);
+		imgs.resize(1);
+		imgs[0].push_back(temp->ourImages[i].bitmap);
+		blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
+	}
+	if (add)
+	{
+		imgs.resize(imgs.size()+add->size());
+		for (int i=0; i<add->size();i++)
+		{
+			temp = CGI->spriteh->giveDef((*add)[i]);
+			for (int j=0;j<temp->ourImages.size();j++)
+			{
+				imgs[i+1].push_back(temp->ourImages[j].bitmap);
+				blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
+			}
+		}
+		delete add;
 	}
 	function = Function;
 	pos.x=x;
 	pos.y=y;
-	pos.w = imgs[0]->w;
-	pos.h = imgs[0]->h  -1;
+	pos.w = imgs[curimg][0]->w;
+	pos.h = imgs[curimg][0]->h  -1;
 	if (activ)
 		activate();
 }
@@ -169,8 +184,8 @@ statusbar(7,556),
 kingOverview(CGI->preth->advKingdomOverview.first,CGI->preth->advKingdomOverview.second,
 			 &CAdvMapInt::fshowOverview, 679, 196, "IAM002.DEF"),
 
-undeground(CGI->preth->advSurfaceSwitch.first,CGI->preth->advSurfaceSwitch.second,
-		   &CAdvMapInt::fswitchLevel, 711, 196, "IAM003.DEF"),
+underground(CGI->preth->advSurfaceSwitch.first,CGI->preth->advSurfaceSwitch.second,
+		   &CAdvMapInt::fswitchLevel, 711, 196, "IAM010.DEF", false, new std::vector<std::string>(1,std::string("IAM003.DEF"))),
 
 questlog(CGI->preth->advQuestlog.first,CGI->preth->advQuestlog.second,
 		 &CAdvMapInt::fshowQuestlog, 679, 228, "IAM004.DEF"),
@@ -220,8 +235,17 @@ void CAdvMapInt::fswitchLevel()
 	if(!CGI->ac->map.twoLevel)
 		return;
 	if (position.z)
+	{
 		position.z--;
-	else position.z++;
+		underground.curimg=0;
+		underground.show();
+	}
+	else 
+	{
+		underground.curimg=1;
+		position.z++;
+		underground.show();
+	}
 	updateScreen = true;
 }
 void CAdvMapInt::fshowQuestlog()
@@ -255,8 +279,8 @@ void CAdvMapInt::show()
 
 	kingOverview.show();
 	kingOverview.activate();
-	undeground.show();
-	undeground.activate();
+	underground.show();
+	underground.activate();
 	questlog.show();
 	questlog.activate();
 	sleepWake.show();

+ 3 - 3
CAdvmapInterface.h

@@ -8,8 +8,8 @@
 #include "CGameInfo.h"
 #include "SDL_Extensions.h"
 #include <boost/logic/tribool.hpp>
-#define CGI (CGameInfo::mainObj)
 using namespace boost::logic;
+#define CGI (CGameInfo::mainObj)
 using namespace CSDL_Ext;
 class AdventureMapButton 
 	: public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public CButtonBase
@@ -28,7 +28,7 @@ public:
 	void deactivate(); // makes button inactive (but don't deletes)
 
 	AdventureMapButton(); //c-tor
-	AdventureMapButton( std::string Name, std::string HelpBox, void(CAdvMapInt::*Function)(), int x, int y, std::string defName, bool activ=false );//c-tor
+	AdventureMapButton( std::string Name, std::string HelpBox, void(CAdvMapInt::*Function)(), int x, int y, std::string defName, bool activ=false,  std::vector<std::string> * add = NULL );//c-tor
 
 };
 /*****************************/
@@ -133,7 +133,7 @@ public:
 
 	SDL_Surface * bg;
 	AdventureMapButton kingOverview,//- kingdom overview
-		undeground,//- underground switch
+		underground,//- underground switch
 		questlog,//- questlog
 		sleepWake, //- sleep/wake hero
 		moveHero, //- move hero

+ 101 - 101
CAmbarCendamo.cpp

@@ -463,12 +463,12 @@ void CAmbarCendamo::deh3m()
 	for(int ww=0; ww<howManyObjs; ++ww) //comment this line to turn loading objects off
 	{
 		//std::cout << "object nr "<<ww<<"\ti= "<<i<<std::endl;
-		CObjectInstance nobj; //we will read this object
-		nobj.id = CGameInfo::mainObj->objh->objInstances.size();
-		nobj.pos.x = bufor[i++];
-		nobj.pos.y = bufor[i++];
-		nobj.pos.z = bufor[i++];
-		nobj.defNumber = readNormalNr(i, 4); i+=4;
+		CObjectInstance * nobj = new CObjectInstance; //we will read this object
+		nobj->id = CGameInfo::mainObj->objh->objInstances.size();
+		nobj->pos.x = bufor[i++];
+		nobj->pos.y = bufor[i++];
+		nobj->pos.z = bufor[i++];
+		nobj->defNumber = readNormalNr(i, 4); i+=4;
 
 		//if (((nobj.x==0)&&(nobj.y==0)) || nobj.x>map.width || nobj.y>map.height || nobj.z>1 || nobj.defNumber>map.defy.size())
 		//	std::cout << "Alarm!!! Obiekt "<<ww<<" jest kopniety (lub wystaje poza mape)\n";
@@ -479,10 +479,10 @@ void CAmbarCendamo::deh3m()
 		{
 			buff[ccc] = bufor[i+ccc];
 		}
-		EDefType uu = getDefType(map.defy[nobj.defNumber]);
-		int j = map.defy[nobj.defNumber].bytes[16];
+		EDefType uu = getDefType(map.defy[nobj->defNumber]);
+		int j = map.defy[nobj->defNumber].bytes[16];
 		int p = 99;
-		switch(getDefType(map.defy[nobj.defNumber]))
+		switch(getDefType(map.defy[nobj->defNumber]))
 		{
 		case EDefType::EVENTOBJ_DEF: //for event - objects
 			{
@@ -553,7 +553,7 @@ void CAmbarCendamo::deh3m()
 				spec->computerActivate = readNormalNr(i, 1); ++i;
 				spec->humanActivate = readNormalNr(i, 1); ++i;
 				i+=4;
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		case EDefType::HERO_DEF:
@@ -780,7 +780,7 @@ void CAmbarCendamo::deh3m()
 					spec->knowledge = bufor[i]; ++i;
 				}
 				i+=16;
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		case CREATURES_DEF:
@@ -819,7 +819,7 @@ void CAmbarCendamo::deh3m()
 				spec->neverFlees = bufor[i]; ++i;
 				spec->notGrowingTeam = bufor[i]; ++i;
 				i+=2;
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		case EDefType::SIGN_DEF:
@@ -831,7 +831,7 @@ void CAmbarCendamo::deh3m()
 					spec->message += bufor[i]; ++i;
 				}
 				i+=4;
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		case EDefType::SEERHUT_DEF:
@@ -1098,7 +1098,7 @@ void CAmbarCendamo::deh3m()
 					}
 				}// end of internal switch
 				i+=2;
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		case EDefType::WITCHHUT_DEF:
@@ -1118,7 +1118,7 @@ void CAmbarCendamo::deh3m()
 					}
 				}
 				
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		case EDefType::SCHOLAR_DEF:
@@ -1141,7 +1141,7 @@ void CAmbarCendamo::deh3m()
 					break;
 				}
 				i+=6;
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		case EDefType::GARRISON_DEF:
@@ -1152,7 +1152,7 @@ void CAmbarCendamo::deh3m()
 				spec->units = readCreatureSet(i); i+=28;
 				spec->movableUnits = bufor[i]; ++i;
 				i+=8;
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		case EDefType::ARTIFACT_DEF:
@@ -1176,7 +1176,7 @@ void CAmbarCendamo::deh3m()
 						spec->areGuards = false;
 					i+=4;
 				}
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		case EDefType::RESOURCE_DEF:
@@ -1203,7 +1203,7 @@ void CAmbarCendamo::deh3m()
 				}
 				spec->amount = readNormalNr(i); i+=4;
 				i+=4;
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		case EDefType::TOWN_DEF:
@@ -1323,7 +1323,7 @@ void CAmbarCendamo::deh3m()
 
 				spec->alignment = bufor[i]; ++i;
 				i+=3;
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		case EDefType::PLAYERONLY_DEF:
@@ -1331,14 +1331,14 @@ void CAmbarCendamo::deh3m()
 				CPlayerOnlyObjInfo * spec = new CPlayerOnlyObjInfo;
 				spec->player = bufor[i]; ++i;
 				i+=3;
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		case EDefType::SHRINE_DEF:
 			{
 				CShrineObjInfo * spec = new CShrineObjInfo;
 				spec->spell = bufor[i]; i+=4;
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		case EDefType::SPELLSCROLL_DEF:
@@ -1361,7 +1361,7 @@ void CAmbarCendamo::deh3m()
 				}
 				spec->spell = &(CGameInfo::mainObj->spellh->spells[bufor[i]]); ++i;
 				i+=3;
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		case EDefType::PANDORA_DEF:
@@ -1418,7 +1418,7 @@ void CAmbarCendamo::deh3m()
 				int gcre = readNormalNr(i, 1); ++i; //number of gained creatures
 				spec->creatures = readCreatureSet(i, gcre); i+=4*gcre;
 				i+=8;
-				nobj.info = spec;
+				nobj->info = spec;
 				///////end of copied fragment
 				break;
 			}
@@ -1426,7 +1426,7 @@ void CAmbarCendamo::deh3m()
 			{
 				CGrailObjInfo * spec = new CGrailObjInfo;
 				spec->radius = readNormalNr(i); i+=4;
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		case EDefType::CREGEN_DEF:
@@ -1448,7 +1448,7 @@ void CAmbarCendamo::deh3m()
 				{
 					spec->asCastle = true;
 				}
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		case EDefType::CREGEN2_DEF:
@@ -1476,7 +1476,7 @@ void CAmbarCendamo::deh3m()
 					spec->maxLevel = 7;
 				if(spec->minLevel<1)
 					spec->minLevel = 1;
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		case EDefType::CREGEN3_DEF:
@@ -1490,7 +1490,7 @@ void CAmbarCendamo::deh3m()
 					spec->maxLevel = 7;
 				if(spec->minLevel<1)
 					spec->minLevel = 1;
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		case EDefType::BORDERGUARD_DEF:
@@ -1690,7 +1690,7 @@ void CAmbarCendamo::deh3m()
 				{
 					spec->completedText += bufor[i]; ++i;
 				}
-				nobj.info = spec;
+				nobj->info = spec;
 				break;
 			}
 		} //end of main switch
@@ -2060,7 +2060,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 	//variables initialized
 	for(int j=0; j<CGI->objh->objInstances.size(); ++j)
 	{
-		DefInfo curDef = map.defy[CGI->objh->objInstances[j].defNumber];
+		DefInfo curDef = map.defy[CGI->objh->objInstances[j]->defNumber];
 		switch(getDefType(curDef))
 		{
 		case EDefType::RESOURCE_DEF:
@@ -2072,7 +2072,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					nxt.bytes[20] = rand()%7;
 					if(resDefNumbers[nxt.bytes[20]+1]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = resDefNumbers[nxt.bytes[20]+1];
+						CGI->objh->objInstances[j]->defNumber = resDefNumbers[nxt.bytes[20]+1];
 						continue;
 					}
 					nxt.name = resDefNames[nxt.bytes[20]+1];
@@ -2089,7 +2089,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(resDefNumbers[nxt.bytes[20]+1]==-1)
 					{
 						resDefNumbers[nxt.bytes[20]+1] = map.defy.size()-1;
@@ -2106,7 +2106,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					nxt.bytes[20] = 14*(rand()%9)+rand()%2;
 					if(creDefNumbers[nxt.bytes[20]]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
+						CGI->objh->objInstances[j]->defNumber = creDefNumbers[nxt.bytes[20]];
 						continue;
 					}
 					nxt.name = creDefNames[nxt.bytes[20]];
@@ -2123,7 +2123,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(creDefNumbers[nxt.bytes[20]]==-1)
 					{
 						creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
@@ -2136,7 +2136,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					nxt.bytes[20] = 14*(rand()%9)+rand()%2+2;
 					if(creDefNumbers[nxt.bytes[20]]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
+						CGI->objh->objInstances[j]->defNumber = creDefNumbers[nxt.bytes[20]];
 						continue;
 					}
 					nxt.name = creDefNames[nxt.bytes[20]];
@@ -2153,7 +2153,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(creDefNumbers[nxt.bytes[20]]==-1)
 					{
 						creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
@@ -2166,7 +2166,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					nxt.bytes[20] = 14*(rand()%9)+rand()%2+4;
 					if(creDefNumbers[nxt.bytes[20]]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
+						CGI->objh->objInstances[j]->defNumber = creDefNumbers[nxt.bytes[20]];
 						continue;
 					}
 					nxt.name = creDefNames[nxt.bytes[20]];
@@ -2183,7 +2183,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(creDefNumbers[nxt.bytes[20]]==-1)
 					{
 						creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
@@ -2196,7 +2196,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					nxt.bytes[20] = 14*(rand()%9)+rand()%2+6;
 					if(creDefNumbers[nxt.bytes[20]]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
+						CGI->objh->objInstances[j]->defNumber = creDefNumbers[nxt.bytes[20]];
 						continue;
 					}
 					nxt.name = creDefNames[nxt.bytes[20]];
@@ -2213,7 +2213,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(creDefNumbers[nxt.bytes[20]]==-1)
 					{
 						creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
@@ -2226,7 +2226,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					nxt.bytes[20] = 14*(rand()%9)+rand()%2+8;
 					if(creDefNumbers[nxt.bytes[20]]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
+						CGI->objh->objInstances[j]->defNumber = creDefNumbers[nxt.bytes[20]];
 						continue;
 					}
 					nxt.name = creDefNames[nxt.bytes[20]];
@@ -2243,7 +2243,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(creDefNumbers[nxt.bytes[20]]==-1)
 					{
 						creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
@@ -2256,7 +2256,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					nxt.bytes[20] = 14*(rand()%9)+rand()%2+10;
 					if(creDefNumbers[nxt.bytes[20]]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
+						CGI->objh->objInstances[j]->defNumber = creDefNumbers[nxt.bytes[20]];
 						continue;
 					}
 					nxt.name = creDefNames[nxt.bytes[20]];
@@ -2273,7 +2273,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(creDefNumbers[nxt.bytes[20]]==-1)
 					{
 						creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
@@ -2286,7 +2286,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					nxt.bytes[20] = 14*(rand()%9)+rand()%2+12;
 					if(creDefNumbers[nxt.bytes[20]]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
+						CGI->objh->objInstances[j]->defNumber = creDefNumbers[nxt.bytes[20]];
 						continue;
 					}
 					nxt.name = creDefNames[nxt.bytes[20]];
@@ -2303,7 +2303,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(creDefNumbers[nxt.bytes[20]]==-1)
 					{
 						creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
@@ -2316,7 +2316,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					nxt.bytes[20] = rand()%126;
 					if(creDefNumbers[nxt.bytes[20]]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = creDefNumbers[nxt.bytes[20]];
+						CGI->objh->objInstances[j]->defNumber = creDefNumbers[nxt.bytes[20]];
 						continue;
 					}
 					nxt.name = creDefNames[nxt.bytes[20]];
@@ -2333,7 +2333,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(creDefNumbers[nxt.bytes[20]]==-1)
 					{
 						creDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
@@ -2350,7 +2350,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					nxt.bytes[20] = rand()%artDefNames.size();
 					if(artDefNumbers[nxt.bytes[20]]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = artDefNumbers[nxt.bytes[20]];
+						CGI->objh->objInstances[j]->defNumber = artDefNumbers[nxt.bytes[20]];
 						continue;
 					}
 					nxt.name = artDefNames[nxt.bytes[20]];
@@ -2367,7 +2367,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(artDefNumbers[nxt.bytes[20]]==-1)
 					{
 						artDefNumbers[nxt.bytes[20]] = map.defy.size()-1;
@@ -2380,7 +2380,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					nxt.bytes[20] = rand()%art1DefNames.size();
 					if(art1DefNumbers[nxt.bytes[20]]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = art1DefNumbers[nxt.bytes[20]];
+						CGI->objh->objInstances[j]->defNumber = art1DefNumbers[nxt.bytes[20]];
 						continue;
 					}
 					nxt.name = art1DefNames[nxt.bytes[20]];
@@ -2397,7 +2397,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(art1DefNumbers[nxt.bytes[20]]==-1)
 					{
 						art1DefNumbers[nxt.bytes[20]] = map.defy.size()-1;
@@ -2410,7 +2410,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					nxt.bytes[20] = rand()%art2DefNames.size();
 					if(art2DefNumbers[nxt.bytes[20]]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = art2DefNumbers[nxt.bytes[20]];
+						CGI->objh->objInstances[j]->defNumber = art2DefNumbers[nxt.bytes[20]];
 						continue;
 					}
 					nxt.name = art2DefNames[nxt.bytes[20]];
@@ -2427,7 +2427,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(art2DefNumbers[nxt.bytes[20]]==-1)
 					{
 						art2DefNumbers[nxt.bytes[20]] = map.defy.size()-1;
@@ -2440,7 +2440,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					nxt.bytes[20] = rand()%art3DefNames.size();
 					if(art3DefNumbers[nxt.bytes[20]]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = art3DefNumbers[nxt.bytes[20]];
+						CGI->objh->objInstances[j]->defNumber = art3DefNumbers[nxt.bytes[20]];
 						continue;
 					}
 					nxt.name = art3DefNames[nxt.bytes[20]];
@@ -2457,7 +2457,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(art3DefNumbers[nxt.bytes[20]]==-1)
 					{
 						art3DefNumbers[nxt.bytes[20]] = map.defy.size()-1;
@@ -2470,7 +2470,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					nxt.bytes[20] = rand()%art4DefNames.size();
 					if(art4DefNumbers[nxt.bytes[20]]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = art4DefNumbers[nxt.bytes[20]];
+						CGI->objh->objInstances[j]->defNumber = art4DefNumbers[nxt.bytes[20]];
 						continue;
 					}
 					nxt.name = art4DefNames[nxt.bytes[20]];
@@ -2487,7 +2487,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(art4DefNumbers[nxt.bytes[20]]==-1)
 					{
 						art4DefNumbers[nxt.bytes[20]] = map.defy.size()-1;
@@ -2501,15 +2501,15 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 				{
 					DefInfo nxt = curDef;
 					nxt.bytes[16] = 98;
-					if(((CCastleObjInfo*)CGI->objh->objInstances[j].info)->player==0xff)
+					if(((CCastleObjInfo*)CGI->objh->objInstances[j]->info)->player==0xff)
 					{
 						nxt.bytes[20] = rand()%town1DefNames.size();		
 					}
 					else
 					{
-						if(CGI->scenarioOps.getIthPlayersSettings(((CCastleObjInfo*)CGI->objh->objInstances[j].info)->player).castle>-1)
+						if(CGI->scenarioOps.getIthPlayersSettings(((CCastleObjInfo*)CGI->objh->objInstances[j]->info)->player).castle>-1)
 						{
-							nxt.bytes[20] = CGI->scenarioOps.getIthPlayersSettings(((CCastleObjInfo*)CGI->objh->objInstances[j].info)->player).castle;
+							nxt.bytes[20] = CGI->scenarioOps.getIthPlayersSettings(((CCastleObjInfo*)CGI->objh->objInstances[j]->info)->player).castle;
 						}
 						else
 						{
@@ -2518,7 +2518,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					if(town1DefNumbers[nxt.bytes[20]]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = town1DefNumbers[nxt.bytes[20]];
+						CGI->objh->objInstances[j]->defNumber = town1DefNumbers[nxt.bytes[20]];
 						continue;
 					}
 					nxt.name = town1DefNames[nxt.bytes[20]];
@@ -2535,7 +2535,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(town1DefNumbers[nxt.bytes[20]]==-1)
 					{
 						town1DefNumbers[nxt.bytes[20]] = map.defy.size()-1;
@@ -2548,29 +2548,29 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 	} //end of main loop
 	for(int j=0; j<CGI->objh->objInstances.size(); ++j) //for creature dwellings on map (they are town type dependent)
 	{
-		DefInfo curDef = map.defy[CGI->objh->objInstances[j].defNumber];
+		DefInfo curDef = map.defy[CGI->objh->objInstances[j]->defNumber];
 		switch(getDefType(curDef))
 		{
 		case EDefType::CREGEN_DEF:
 			{
-				if(((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->asCastle)
+				if(((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->asCastle)
 				{
 					DefInfo nxt = curDef;
 					nxt.bytes[16] = 17;
 					for(int vv=0; vv<CGI->objh->objInstances.size(); ++vv)
 					{
-						if(getDefType(map.defy[CGI->objh->objInstances[vv].defNumber])==EDefType::TOWN_DEF)
+						if(getDefType(map.defy[CGI->objh->objInstances[vv]->defNumber])==EDefType::TOWN_DEF)
 						{
 							if(
-								((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[0]==((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->bytes[0]
-							&&  ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[1]==((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->bytes[1]
-							&&  ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[2]==((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->bytes[2]
-							&&  ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[3]==((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->bytes[3])
+								((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[0]==((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->bytes[0]
+							&&  ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[1]==((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->bytes[1]
+							&&  ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[2]==((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->bytes[2]
+							&&  ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[3]==((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->bytes[3])
 							{
 								for(int mm=0; mm<town1DefNames.size(); ++mm)
 								{
 									std::transform(town1DefNames[mm].begin(), town1DefNames[mm].end(), town1DefNames[mm].begin(), (int(*)(int))toupper);
-									std::string hlp = map.defy[CGI->objh->objInstances[vv].defNumber].name;
+									std::string hlp = map.defy[CGI->objh->objInstances[vv]->defNumber].name;
 									std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper);
 									if(town1DefNames[mm]==hlp)
 									{
@@ -2580,11 +2580,11 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 							}
 						}
 					}
-					int lvl = atoi(map.defy[CGI->objh->objInstances[j].defNumber].name.substr(7, 8).c_str())-1;
+					int lvl = atoi(map.defy[CGI->objh->objInstances[j]->defNumber].name.substr(7, 8).c_str())-1;
 					nxt.name = creGenNames[nxt.bytes[20]][lvl];
 					if(creGenNumbers[nxt.bytes[20]][lvl]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = creGenNumbers[nxt.bytes[20]][lvl];
+						CGI->objh->objInstances[j]->defNumber = creGenNumbers[nxt.bytes[20]][lvl];
 						continue;
 					}
 					std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(), 
@@ -2600,7 +2600,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(creGenNumbers[nxt.bytes[20]][lvl]==-1)
 					{
 						creGenNumbers[nxt.bytes[20]][lvl] = map.defy.size()-1;
@@ -2613,19 +2613,19 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					std::vector<int> possibleTowns;
 					for(int bb=0; bb<8; ++bb)
 					{
-						if(((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->castles[0] & (1<<bb))
+						if(((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->castles[0] & (1<<bb))
 						{
 							possibleTowns.push_back(bb);
 						}
 					}
-					if(((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->castles[1])
+					if(((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->castles[1])
 						possibleTowns.push_back(8);
 					nxt.bytes[20] = possibleTowns[rand()%possibleTowns.size()];
-					int lvl = atoi(map.defy[CGI->objh->objInstances[j].defNumber].name.substr(7, 8).c_str())-1;
+					int lvl = atoi(map.defy[CGI->objh->objInstances[j]->defNumber].name.substr(7, 8).c_str())-1;
 					nxt.name = creGenNames[nxt.bytes[20]][lvl];
 					if(creGenNumbers[nxt.bytes[20]][lvl]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = creGenNumbers[nxt.bytes[20]][lvl];
+						CGI->objh->objInstances[j]->defNumber = creGenNumbers[nxt.bytes[20]][lvl];
 						continue;
 					}
 					std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(), 
@@ -2641,7 +2641,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(creGenNumbers[nxt.bytes[20]][lvl]==-1)
 					{
 						creGenNumbers[nxt.bytes[20]][lvl] = map.defy.size()-1;
@@ -2651,24 +2651,24 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 			}
 		case EDefType::CREGEN2_DEF:
 			{
-				if(((CCreGenObjInfo*)CGI->objh->objInstances[j].info)->asCastle)
+				if(((CCreGenObjInfo*)CGI->objh->objInstances[j]->info)->asCastle)
 				{
 					DefInfo nxt = curDef;
 					nxt.bytes[16] = 17;
 					for(int vv=0; vv<CGI->objh->objInstances.size(); ++vv)
 					{
-						if(getDefType(map.defy[CGI->objh->objInstances[vv].defNumber])==EDefType::TOWN_DEF)
+						if(getDefType(map.defy[CGI->objh->objInstances[vv]->defNumber])==EDefType::TOWN_DEF)
 						{
 							if(
-								((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[0]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->bytes[0]
-							&&  ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[1]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->bytes[1]
-							&&  ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[2]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->bytes[2]
-							&&  ((CCastleObjInfo*)CGI->objh->objInstances[vv].info)->bytes[3]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->bytes[3])
+								((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[0]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->bytes[0]
+							&&  ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[1]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->bytes[1]
+							&&  ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[2]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->bytes[2]
+							&&  ((CCastleObjInfo*)CGI->objh->objInstances[vv]->info)->bytes[3]==((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->bytes[3])
 							{
 								for(int mm=0; mm<town1DefNames.size(); ++mm)
 								{
 									std::transform(town1DefNames[mm].begin(), town1DefNames[mm].end(), town1DefNames[mm].begin(), (int(*)(int))toupper);
-									std::string hlp = map.defy[CGI->objh->objInstances[vv].defNumber].name;
+									std::string hlp = map.defy[CGI->objh->objInstances[vv]->defNumber].name;
 									std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper);
 									if(town1DefNames[mm]==hlp)
 									{
@@ -2678,11 +2678,11 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 							}
 						}
 					}
-					int lvl = rand()%(((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->maxLevel - ((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->minLevel) + ((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->minLevel;
+					int lvl = rand()%(((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel) + ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel;
 					nxt.name = creGenNames[nxt.bytes[20]][lvl];
 					if(creGenNumbers[nxt.bytes[20]][lvl]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = creGenNumbers[nxt.bytes[20]][lvl];
+						CGI->objh->objInstances[j]->defNumber = creGenNumbers[nxt.bytes[20]][lvl];
 						continue;
 					}
 					std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(), 
@@ -2698,7 +2698,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(creGenNumbers[nxt.bytes[20]][lvl]==-1)
 					{
 						creGenNumbers[nxt.bytes[20]][lvl] = map.defy.size()-1;
@@ -2711,19 +2711,19 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					std::vector<int> possibleTowns;
 					for(int bb=0; bb<8; ++bb)
 					{
-						if(((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->castles[0] & (1<<bb))
+						if(((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->castles[0] & (1<<bb))
 						{
 							possibleTowns.push_back(bb);
 						}
 					}
-					if(((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->castles[1])
+					if(((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->castles[1])
 						possibleTowns.push_back(8);
 					nxt.bytes[20] = possibleTowns[rand()%possibleTowns.size()];
-					int lvl = rand()%(((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->maxLevel - ((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->minLevel) + ((CCreGen2ObjInfo*)CGI->objh->objInstances[j].info)->minLevel;
+					int lvl = rand()%(((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel) + ((CCreGen2ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel;
 					nxt.name = creGenNames[nxt.bytes[20]][lvl];
 					if(creGenNumbers[nxt.bytes[20]][lvl]!=-1)
 					{
-						CGI->objh->objInstances[j].defNumber = creGenNumbers[nxt.bytes[20]][lvl];
+						CGI->objh->objInstances[j]->defNumber = creGenNumbers[nxt.bytes[20]][lvl];
 						continue;
 					}
 					std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(), 
@@ -2739,7 +2739,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 					}
 					map.defy.push_back(nxt); // add this def to the vector
 					defsToUnpack.push_back(nxt.name);
-					CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+					CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 					if(creGenNumbers[nxt.bytes[20]][lvl]==-1)
 					{
 						creGenNumbers[nxt.bytes[20]][lvl] = map.defy.size()-1;
@@ -2750,21 +2750,21 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 			{
 				DefInfo nxt = curDef;
 				nxt.bytes[16] = 17;
-				nxt.bytes[20] = atoi(map.defy[CGI->objh->objInstances[j].defNumber].name.substr(7, 8).c_str());
+				nxt.bytes[20] = atoi(map.defy[CGI->objh->objInstances[j]->defNumber].name.substr(7, 8).c_str());
 				int lvl = -1;
-				CCreGen3ObjInfo * ct = (CCreGen3ObjInfo*)CGI->objh->objInstances[j].info;
+				CCreGen3ObjInfo * ct = (CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info;
 				if(ct->maxLevel>7)
 					ct->maxLevel = 7;
 				if(ct->minLevel<1)
 					ct->minLevel = 1;
-				if((((CCreGen3ObjInfo*)CGI->objh->objInstances[j].info)->maxLevel - ((CCreGen3ObjInfo*)CGI->objh->objInstances[j].info)->minLevel)!=0)
-					lvl = rand()%(((CCreGen3ObjInfo*)CGI->objh->objInstances[j].info)->maxLevel - ((CCreGen3ObjInfo*)CGI->objh->objInstances[j].info)->minLevel) + ((CCreGen3ObjInfo*)CGI->objh->objInstances[j].info)->minLevel;
+				if((((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel)!=0)
+					lvl = rand()%(((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel - ((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel) + ((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->minLevel;
 				else
-					lvl = ((CCreGen3ObjInfo*)CGI->objh->objInstances[j].info)->maxLevel;
+					lvl = ((CCreGen3ObjInfo*)CGI->objh->objInstances[j]->info)->maxLevel;
 				nxt.name = creGenNames[nxt.bytes[20]][lvl];
 				if(creGenNumbers[nxt.bytes[20]][lvl]!=-1)
 				{
-					CGI->objh->objInstances[j].defNumber = creGenNumbers[nxt.bytes[20]][lvl];
+					CGI->objh->objInstances[j]->defNumber = creGenNumbers[nxt.bytes[20]][lvl];
 					continue;
 				}
 				std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(), 
@@ -2780,7 +2780,7 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
 				}
 				map.defy.push_back(nxt); // add this def to the vector
 				defsToUnpack.push_back(nxt.name);
-				CGI->objh->objInstances[j].defNumber = map.defy.size()-1;
+				CGI->objh->objInstances[j]->defNumber = map.defy.size()-1;
 				if(creGenNumbers[nxt.bytes[20]][lvl]==-1)
 				{
 					creGenNumbers[nxt.bytes[20]][lvl] = map.defy.size()-1;

+ 5 - 4
CGameInterface.cpp

@@ -7,6 +7,7 @@
 using namespace CSDL_Ext;
 CButtonBase::CButtonBase()
 {
+	curimg=0;
 	type=-1;
 	abs=false;
 	active=false;
@@ -17,12 +18,12 @@ void CButtonBase::show()
 {
 	if (abs)
 	{
-		blitAt(imgs[state],pos.x,pos.y);
+		blitAt(imgs[curimg][state],pos.x,pos.y);
 		updateRect(&pos);
 	}
 	else
 	{
-		blitAt(imgs[state],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y);
+		blitAt(imgs[curimg][state],pos.x+ourObj->pos.x,pos.y+ourObj->pos.y);
 		updateRect(&genRect(pos.h,pos.w,pos.x+ourObj->pos.x,pos.y+ourObj->pos.y));
 		
 	}
@@ -187,7 +188,7 @@ void CPlayerInterface::handleEvent(SDL_Event *sEvent)
 			}
 		case (SDLK_u):
 			{
-				adventureInt->undeground.clickLeft(true);
+				adventureInt->underground.clickLeft(true);
 			}
 		}
 	} //keydown end
@@ -217,7 +218,7 @@ void CPlayerInterface::handleEvent(SDL_Event *sEvent)
 			}
 		case (SDLK_u):
 			{
-				adventureInt->undeground.clickLeft(false);
+				adventureInt->underground.clickLeft(false);
 			}
 		}
 	}//keyup end

+ 2 - 1
CGameInterface.h

@@ -23,7 +23,8 @@ public:
 	bool active;
 	CIntObject * ourObj;
 	int state;
-	std::vector<SDL_Surface*> imgs;
+	std::vector< std::vector<SDL_Surface*> > imgs;
+	int curimg;
 	virtual void show() ;
 	virtual void activate()=0;
 	virtual void deactivate()=0;

+ 12 - 0
CMT.cpp

@@ -3,6 +3,7 @@
 #include "stdafx.h"
 #include "SDL.h"
 #include "SDL_TTF.h"
+#include "CVideoHandler.h"
 #include "SDL_mixer.h"
 #include "CBuildingHandler.h"
 #include "SDL_Extensions.h"
@@ -79,6 +80,17 @@ int _tmain(int argc, _TCHAR* argv[])
 		GEOR13 = TTF_OpenFont("Fonts\\georgia.ttf",13);
 		GEORXX = TTF_OpenFont("Fonts\\tnrb.ttf",22);
 
+
+
+
+		//CBIKHandler cb;
+		//cb.open("CSECRET.BIK");
+
+
+
+
+
+
 		//initializing audio
 		CMusicHandler * mush = new CMusicHandler;
 		mush->initMusics();

+ 1 - 1
CObjectHandler.h

@@ -300,7 +300,7 @@ 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
+	std::vector<CObjectInstance*> objInstances; //vector with objects on map
 	void loadObjects();
 };
 

+ 5 - 4
CPathfinder.cpp

@@ -1,3 +1,4 @@
+#include "stdafx.h"
 #include "global.h"
 #include "CPathfinder.h"
 
@@ -25,10 +26,10 @@ CPath * CPathfinder::getPath(int3 &src, int3 &dest)
 
 	for(int h=0; h<CGI->objh->objInstances.size(); ++h)
 	{
-		if(CGI->objh->objInstances[h].pos.z == src.z)
+		if(CGI->objh->objInstances[h]->pos.z == src.z)
 		{
 			unsigned char blockMap[6];
-			std::string ourName = CGI->ac->map.defy[CGI->objh->objInstances[h].defNumber].name;
+			std::string ourName = CGI->ac->map.defy[CGI->objh->objInstances[h]->defNumber].name;
 			std::transform(ourName.begin(), ourName.end(), ourName.begin(), (int(*)(int))toupper);
 			for(int y=0; y<CGI->dobjinfo->objs.size(); ++y)
 			{
@@ -47,8 +48,8 @@ CPath * CPathfinder::getPath(int3 &src, int3 &dest)
 			{
 				for(int j=0; j<8; ++j)
 				{
-					int cPosX = CGI->objh->objInstances[h].pos.x - j;
-					int cPosY = CGI->objh->objInstances[h].pos.y - i;
+					int cPosX = CGI->objh->objInstances[h]->pos.x - j;
+					int cPosY = CGI->objh->objInstances[h]->pos.y - i;
 					if(cPosX>0 && cPosY>0)
 					{
 						graph[cPosX][cPosY].accesible = blockMap[i] & (128 >> j);

+ 2 - 1
CSndHandler.h

@@ -46,8 +46,9 @@ public:
 	std::vector<Entry> entries;
 	~CVidHandler();
 	CVidHandler(std::string fname);
+	std::ifstream & extract(std::string srcfile);
 	void extract(std::string srcfile, std::string dstfile, bool caseSens=true); //saves selected file
-	unsigned char * extract (std::string srcfile, int & size); //return selecte file
+	unsigned char * extract (std::string srcfile, int & size); //return selecte file,
 	void extract(int index, std::string dstfile); //saves selected file
 	MemberFile getFile(std::string name); //nie testowane - sprawdzic
 };

+ 87 - 0
CVideoHandler.cpp

@@ -0,0 +1,87 @@
+#include "stdafx.h"
+#include "CVideoHandler.h"
+
+void DLLHandler::Instantiate(const char *filename)
+{
+	dll = LoadLibraryA(filename);
+}
+const char *DLLHandler::GetLibExtension()
+{
+#ifdef WIN32
+	return "dll";
+#elif defined(__APPLE__)
+	return "dylib";
+#else
+	return "so";
+#endif
+}
+void *DLLHandler::FindAddress(const char *symbol)
+{
+	return (void*) GetProcAddress(dll,symbol);
+}
+DLLHandler::~DLLHandler()
+{
+	FreeLibrary(dll);
+}
+
+
+CBIKHandler::CBIKHandler()
+{
+	ourLib.Instantiate("BINKW32.DLL");
+	newmode=-1;
+	///waveOutOpen = ourLib.FindAddress("_BinkOpenWaveOut@4");
+}
+int readNormalNr2 (unsigned char* bufor, int &iter, int bytCon)
+{
+	int ret=0;
+	int amp=1;
+	for (int i=iter; i<iter+bytCon; i++)
+	{
+		ret+=bufor[i]*amp;
+		amp*=256;
+	}
+	iter+=bytCon;
+	return ret;
+}
+
+void CBIKHandler::open(std::string name)
+{
+	unsigned char * fdata = new unsigned char[400];
+	unsigned char * fdata2 = new unsigned char[400];
+	for (int i=0;i<400;i++) fdata[i]=0;
+
+	//str.open(name.c_str(),std::ios::binary);
+	BinkGetError = ourLib.FindAddress("_BinkGetError@0");
+	BinkOpen = ourLib.FindAddress("_BinkOpen@8");
+	BinkSetSoundSystem = ourLib.FindAddress("_BinkSetSoundSystem@8");
+
+	//((void(*)(void*,void*)) BinkSetSoundSystem)(waveOutOpen,NULL);
+
+	while (!fdata)
+		fdata = ((unsigned char *(*)(const char *)) BinkOpen)("CSECRET.BIK");
+
+	
+		fdata2 = ((unsigned char *(*)()) BinkGetError)();
+
+
+	int it = 0;
+	data.width = readNormalNr2(fdata,it,4);
+	data.height =  readNormalNr2(fdata,it,4);
+	data.frameCount =  readNormalNr2(fdata,it,4);
+	data.currentFrame =   readNormalNr2(fdata,it,4);
+	data.lastFrame =  readNormalNr2(fdata,it,4);
+
+  //FData:= BinkOpen(FileHandle);
+  //if FData = nil then
+  //  raise ERSRADException.Create(BinkGetError);
+  //Width:= @FData^.Width;
+  //Height:= @FData^.Height;
+}
+void CBIKHandler::close()
+{
+	str.close();
+	void *binkClose;
+	binkClose = ourLib.FindAddress("_BinkClose@4");
+	(( void(*)() ) binkClose )();
+
+}

+ 120 - 0
CVideoHandler.h

@@ -0,0 +1,120 @@
+#ifndef CVIDEOHANDLEER_H
+#define CVIDEOHANDLEER_H
+
+#include "windows.h"
+//
+//
+//  protected
+//    FLib: HINST;
+//    FLibName: string;
+//    FFileHandle: HFile;
+//    function GetCurrentFrame: int; virtual; abstract;
+//    function GetFramesCount: int; virtual; abstract;
+//    procedure SetCurrentFrame(v: int); virtual; abstract;
+//    procedure DoOpen(FileHandle: hFile); virtual; abstract;
+//    function NormalizeFrame(i:int):int;
+//    procedure SetPause(v:Boolean); virtual; abstract;
+//
+//    procedure LoadProc(var Proc:Pointer; const ProcName:string);
+//  public
+//    Width:pint;
+//    Height:pint;
+//    constructor Create(const LibName:string);
+//    destructor Destroy; override;
+//    procedure Open(FileHandle:hFile); overload;
+//    procedure Open(FileName:string); overload;
+////    procedure Open(FileData:TRSByteArray); overload;
+//    procedure SetVolume(i: int); virtual;
+//    procedure Close; virtual;
+//    procedure NextFrame; virtual; abstract;
+//    procedure PreparePic(b:TBitmap); virtual;
+//    procedure GotoFrame(Index:int; b:TBitmap); virtual;
+//    function ExtractFrame(b:TBitmap = nil):TBitmap; virtual; abstract;
+//    function Wait:Boolean; virtual; abstract;
+//      // Workaround for Bink and Smack thread synchronization bug
+//    property Frame: int read GetCurrentFrame write SetCurrentFrame;
+//    property FramesCount: int read GetFramesCount;
+//    property LibInstance: HINST read FLib;
+//    property Pause: Boolean write SetPause;
+
+  //TRSSmkStruct = packed record
+  //  Version: int;
+  //  Width: int;
+  //  Height: int;
+  //  FrameCount: int;
+  //  mspf: int;
+  //  Unk1: array[0..87] of byte;
+  //  Palette: array[0..775] of byte;
+  //  CurrentFrame: int; // Starting with 0
+  //   // 72 - Øèï
+  //   // 1060 - interesting
+  //   // 1100 - Mute:Bool
+  //end;
+
+  //TRSBinkStruct = packed record
+  //  Width: int;
+  //  Height: int;
+  //  FrameCount: int;
+  //  CurrentFrame: int; // Starting with 1
+  //  LastFrame: int;
+  //  FPSMul: int; // frames/second multiplier
+  //  FPSDiv: int; // frames/second divisor
+  //  Unk1: int;
+  //  Flags: int;
+  //  Unk2: array[0..259] of byte;
+  //  CurrentPlane: int;
+  //  Plane1: ptr;
+  //  Plane2: ptr;
+  //  Unk3: array[0..1] of int;
+  //  YPlaneWidth: int;
+  //  YPlaneHeight: int;
+  //  UVPlaneWidth: int;
+  //  UVPlaneHeight: int;
+  //end;
+struct BINKStruct
+{
+	int width, height, frameCount, lastFrame, currentFrame,
+		FPSMul, // frames/second multiplier
+		FPSDiv, // frames/second divisor
+		unk1, flags, YPlaneWidth, YPlaneHeight, UVPlaneWidth, UVPlaneHeight;
+	unsigned char unk2[260];
+	int unk3[2];
+	void *plane1, *plane2;
+};
+
+struct SMKStruct
+{
+	int version, width, height, frameCount, mspf, currentFrame;
+	unsigned char unk1[88], palette[776];
+};
+
+
+
+
+class DLLHandler
+{
+public:
+	HINSTANCE dll;
+
+	void Instantiate(const char *filename);
+	const char *GetLibExtension();
+	void *FindAddress(const char *symbol);
+
+	virtual ~DLLHandler();
+};
+
+class CBIKHandler
+{
+public:
+	DLLHandler ourLib;
+	std::ifstream str;
+	int newmode;
+	BINKStruct data;
+	unsigned char * buffer;
+	void * waveOutOpen, * BinkGetError, *BinkOpen, *BinkSetSoundSystem ;
+
+	CBIKHandler();
+	void open(std::string name);
+	void close();
+};
+#endif //CVIDEOHANDLEER_H

+ 1 - 1
global.h

@@ -9,7 +9,7 @@
 #define THC //
 #endif
 enum Ecolor {RED, BLUE, TAN, GREEN, ORANGE, PURPLE, TEAL, PINK}; //player's colors
-enum EterrainType {dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock};
+enum EterrainType {border=-1, dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock};
 enum Eriver {noRiver=0, clearRiver, icyRiver, muddyRiver, lavaRiver};
 enum Eroad {dirtRoad=1, grazvelRoad, cobblestoneRoad};
 enum Eformat { WoG=0x33, AB=0x15, RoE=0x0e,  SoD=0x1c};

+ 149 - 426
mapHandler.cpp

@@ -101,291 +101,123 @@ void CMapHandler::init()
 	staticRiverDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("mudrvr.def"));
 	staticRiverDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("lavrvr.def"));
 
-	roadBitmaps = new SDL_Surface **[reader->map.width+2*Woff];
-	for (int ii=0;ii<reader->map.width+2*Woff;ii++)
-		roadBitmaps[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory 
+	//roadBitmaps = new SDL_Surface** [reader->map.width+2*Woff];
+	//for (int ii=0;ii<reader->map.width+2*Woff;ii++)
+	//	roadBitmaps[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory 
+
+	ttiles.resize(CGI->ac->map.width+2*Woff);
+	for (int i=0;i<ttiles.size();i++)
+	{
+		ttiles[i].resize(CGI->ac->map.height+2*Hoff);
+	}
+	for (int i=0;i<ttiles.size();i++)
+	{
+		for (int j=0;j<CGI->ac->map.height+2*Hoff;j++)
+			ttiles[i][j].resize(CGI->ac->map.twoLevel+1);
+	}
+
+
 
 	for (int i=0; i<reader->map.width+2*Woff; i++) //jest po szerokoœci
 	{
 		for (int j=0; j<reader->map.height+2*Hoff;j++) //po wysokoœci
 		{
-			if(i<Woff || i>reader->map.width+Woff-1 || j<Woff || j>reader->map.height+Hoff-1)
-				roadBitmaps[i][j] = NULL;
-			else
+			if(!(i<Woff || i>reader->map.width+Woff-1 || j<Woff || j>reader->map.height+Hoff-1))
 			{
-				if(reader->map.terrain[i-Woff][j-Hoff].malle)
+				for (int k=0; k<=reader->map.twoLevel; ++k)
 				{
-					roadBitmaps[i][j] = roadDefs[reader->map.terrain[i-Woff][j-Hoff].malle-1]->ourImages[reader->map.terrain[i-Woff][j-Hoff].roadDir].bitmap;
-					int cDir = reader->map.terrain[i-Woff][j-Hoff].roadDir;
-					if(cDir==0 || cDir==1 || cDir==2 || cDir==3 || cDir==4 || cDir==5)
-					{
-						if(i-Woff+1<reader->map.width && j-Hoff-1>0 && reader->map.terrain[i-Woff+1][j-Hoff].malle && reader->map.terrain[i-Woff][j-Hoff-1].malle)
-						{
-							roadBitmaps[i][j] = CSDL_Ext::hFlip(roadBitmaps[i][j]);
-							roadBitmaps[i][j] = CSDL_Ext::alphaTransform(roadBitmaps[i][j]);
-							roadBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(roadBitmaps[i][j], su);
-						}
-						if(i-Woff-1>0 && j-Hoff-1>0 && reader->map.terrain[i-Woff-1][j-Hoff].malle && reader->map.terrain[i-Woff][j-Hoff-1].malle)
-						{
-							roadBitmaps[i][j] = CSDL_Ext::rotate03(roadBitmaps[i][j]);
-							roadBitmaps[i][j] = CSDL_Ext::alphaTransform(roadBitmaps[i][j]);
-							roadBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(roadBitmaps[i][j], su);
-						}
-						if(i-Woff-1>0 && j-Hoff+1<reader->map.height && reader->map.terrain[i-Woff-1][j-Hoff].malle && reader->map.terrain[i-Woff][j-Hoff+1].malle)
-						{
-							roadBitmaps[i][j] = CSDL_Ext::rotate01(roadBitmaps[i][j]);
-							roadBitmaps[i][j] = CSDL_Ext::alphaTransform(roadBitmaps[i][j]);
-							roadBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(roadBitmaps[i][j], su);
-						}
-					}
-					if(cDir==8 || cDir==9)
+					TerrainTile** pomm = reader->map.terrain; ;
+					if (k==0)
+						pomm = reader->map.terrain;
+					else
+						pomm = reader->map.undergroungTerrain;
+					if(pomm[i-Woff][j-Hoff].malle)
 					{
-						if((j-Hoff+1<reader->map.height && !(reader->map.terrain[i-Woff][j-Hoff+1].malle)) || j-Hoff+1==reader->map.height)
+						int cDir;
+						bool rotV, rotH;
+						if(k==0)
 						{
-							roadBitmaps[i][j] = CSDL_Ext::hFlip(roadBitmaps[i][j]);
-							roadBitmaps[i][j] = CSDL_Ext::alphaTransform(roadBitmaps[i][j]);
-							roadBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(roadBitmaps[i][j], su);
+							int roadpom = reader->map.terrain[i-Woff][j-Hoff].malle-1,
+								impom = reader->map.terrain[i-Woff][j-Hoff].roadDir;
+							SDL_Surface *pom1 = roadDefs[roadpom]->ourImages[impom].bitmap;
+							ttiles[i][j][k].roadbitmap.push_back(pom1);
+							cDir = reader->map.terrain[i-Woff][j-Hoff].roadDir;
+							
+							rotH = (reader->map.terrain[i-Woff][j-Hoff].siodmyTajemniczyBajt >> 5) & 1;
+							rotV = (reader->map.terrain[i-Woff][j-Hoff].siodmyTajemniczyBajt >> 4) & 1;
 						}
-					}
-					if(cDir==6 || cDir==7)
-					{
-						if(i-Woff+1<reader->map.width && !(reader->map.terrain[i-Woff+1][j-Hoff].malle))
+						else
 						{
-							roadBitmaps[i][j] = CSDL_Ext::rotate01(roadBitmaps[i][j]);
-							roadBitmaps[i][j] = CSDL_Ext::alphaTransform(roadBitmaps[i][j]);
-							roadBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(roadBitmaps[i][j], su);
+							int pom111 = reader->map.undergroungTerrain[i-Woff][j-Hoff].malle-1,
+								pom777 = reader->map.undergroungTerrain[i-Woff][j-Hoff].roadDir;
+							SDL_Surface *pom1 = roadDefs[pom111]->ourImages[pom777].bitmap;
+							ttiles[i][j][k].roadbitmap.push_back(pom1);
+							cDir = reader->map.undergroungTerrain[i-Woff][j-Hoff].roadDir;
+
+							rotH = (reader->map.undergroungTerrain[i-Woff][j-Hoff].siodmyTajemniczyBajt >> 5) & 1;
+							rotV = (reader->map.undergroungTerrain[i-Woff][j-Hoff].siodmyTajemniczyBajt >> 4) & 1;
 						}
-					}
-					if(cDir==0x0e)
-					{
-						if(j-Hoff+1<reader->map.height && !(reader->map.terrain[i-Woff][j-Hoff+1].malle))
+						if(rotH)
 						{
-							roadBitmaps[i][j] = CSDL_Ext::hFlip(roadBitmaps[i][j]);
-							roadBitmaps[i][j] = CSDL_Ext::alphaTransform(roadBitmaps[i][j]);
-							roadBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(roadBitmaps[i][j], su);
+							ttiles[i][j][k].roadbitmap[0] = CSDL_Ext::hFlip(ttiles[i][j][k].roadbitmap[0]);
 						}
-					}
-					if(cDir==0x0f)
-					{
-						if(i-Woff+1<reader->map.width && !(reader->map.terrain[i-Woff+1][j-Hoff].malle))
+						if(rotV)
 						{
-							roadBitmaps[i][j] = CSDL_Ext::rotate01(roadBitmaps[i][j]);
-							roadBitmaps[i][j] = CSDL_Ext::alphaTransform(roadBitmaps[i][j]);
-							roadBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(roadBitmaps[i][j], su);
+							ttiles[i][j][k].roadbitmap[0] = CSDL_Ext::rotate01(ttiles[i][j][k].roadbitmap[0]);
 						}
+						ttiles[i][j][k].roadbitmap[0] = CSDL_Ext::alphaTransform(ttiles[i][j][k].roadbitmap[0]);
+						ttiles[i][j][k].roadbitmap[0] = CSDL_Ext::secondAlphaTransform(ttiles[i][j][k].roadbitmap[0], su);
 					}
 				}
-				else
-					roadBitmaps[i][j] = NULL;
 			}
 		}
 	}
 
-	undRoadBitmaps = new SDL_Surface **[reader->map.width+2*Woff];
-	for (int ii=0;ii<reader->map.width+2*Woff;ii++)
-		undRoadBitmaps[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory 
-
-	if(reader->map.twoLevel)
+	for (int i=0; i<reader->map.width+Woff; i++) //jest po szerokoœci
 	{
-		for (int i=0; i<reader->map.width+2*Woff; i++) //jest po szerokoœci
+		for (int j=0; j<reader->map.height+Hoff;j++) //po wysokoœci
 		{
-			for (int j=0; j<reader->map.height+2*Hoff;j++) //po wysokoœci
+			for(int k=0; k<=reader->map.twoLevel; ++k)
 			{
-				if(i<Woff || i>reader->map.width+Woff-1 || j<Woff || j>reader->map.height+Hoff-1)
-					undRoadBitmaps[i][j] = NULL;
+				if(i<4 || j<4)
+					continue;
+				TerrainTile** pomm = reader->map.terrain;
+				if(k==0)
+				{
+					pomm = reader->map.terrain;
+				}
 				else
 				{
-					if(reader->map.undergroungTerrain[i-Woff][j-Hoff].malle)
-					{
-						undRoadBitmaps[i][j] = roadDefs[reader->map.undergroungTerrain[i-Woff][j-Hoff].malle-1]->ourImages[reader->map.undergroungTerrain[i-Woff][j-Hoff].roadDir].bitmap;
-						int cDir = reader->map.undergroungTerrain[i-Woff][j-Hoff].roadDir;
-						if(cDir==0 || cDir==1 || cDir==2 || cDir==3 || cDir==4 || cDir==5)
-						{
-							if(i-Woff+1<reader->map.width && j-Hoff-1>0 && reader->map.undergroungTerrain[i-Woff+1][j-Hoff].malle && reader->map.undergroungTerrain[i-Woff][j-Hoff-1].malle)
-							{
-								undRoadBitmaps[i][j] = CSDL_Ext::hFlip(undRoadBitmaps[i][j]);
-								undRoadBitmaps[i][j] = CSDL_Ext::alphaTransform(undRoadBitmaps[i][j]);
-								undRoadBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(undRoadBitmaps[i][j], su);
-							}
-							if(i-Woff-1>0 && j-Hoff-1>0 && reader->map.undergroungTerrain[i-Woff-1][j-Hoff].malle && reader->map.undergroungTerrain[i-Woff][j-Hoff-1].malle)
-							{
-								undRoadBitmaps[i][j] = CSDL_Ext::rotate03(undRoadBitmaps[i][j]);
-								undRoadBitmaps[i][j] = CSDL_Ext::alphaTransform(undRoadBitmaps[i][j]);
-								undRoadBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(undRoadBitmaps[i][j], su);
-							}
-							if(i-Woff-1>0 && j-Hoff+1<reader->map.height && reader->map.undergroungTerrain[i-Woff-1][j-Hoff].malle && reader->map.undergroungTerrain[i-Woff][j-Hoff+1].malle)
-							{
-								undRoadBitmaps[i][j] = CSDL_Ext::rotate01(undRoadBitmaps[i][j]);
-								undRoadBitmaps[i][j] = CSDL_Ext::alphaTransform(undRoadBitmaps[i][j]);
-								undRoadBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(undRoadBitmaps[i][j], su);
-							}
-						}
-						if(cDir==8 || cDir==9)
-						{
-							if((j-Hoff+1<reader->map.height && !(reader->map.undergroungTerrain[i-Woff][j-Hoff+1].malle)) || j-Hoff+1==reader->map.height)
-							{
-								undRoadBitmaps[i][j] = CSDL_Ext::hFlip(undRoadBitmaps[i][j]);
-								undRoadBitmaps[i][j] = CSDL_Ext::alphaTransform(undRoadBitmaps[i][j]);
-								undRoadBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(undRoadBitmaps[i][j], su);
-							}
-						}
-						if(cDir==6 || cDir==7)
-						{
-							if(i-Woff+1<reader->map.width && !(reader->map.undergroungTerrain[i-Woff+1][j-Hoff].malle))
-							{
-								undRoadBitmaps[i][j] = CSDL_Ext::rotate01(undRoadBitmaps[i][j]);
-								undRoadBitmaps[i][j] = CSDL_Ext::alphaTransform(undRoadBitmaps[i][j]);
-								undRoadBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(undRoadBitmaps[i][j], su);
-							}
-						}
-						if(cDir==0x0e)
-						{
-							if(j-Hoff+1<reader->map.height && !(reader->map.undergroungTerrain[i-Woff][j-Hoff+1].malle))
-							{
-								undRoadBitmaps[i][j] = CSDL_Ext::hFlip(undRoadBitmaps[i][j]);
-								undRoadBitmaps[i][j] = CSDL_Ext::alphaTransform(undRoadBitmaps[i][j]);
-								undRoadBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(undRoadBitmaps[i][j], su);
-							}
-						}
-						if(cDir==0x0f)
-						{
-							if(i-Woff+1<reader->map.width && !(reader->map.undergroungTerrain[i-Woff+1][j-Hoff].malle))
-							{
-								undRoadBitmaps[i][j] = CSDL_Ext::rotate01(undRoadBitmaps[i][j]);
-								undRoadBitmaps[i][j] = CSDL_Ext::alphaTransform(undRoadBitmaps[i][j]);
-								undRoadBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(undRoadBitmaps[i][j], su);
-							}
-						}
-					}
-					else
-						undRoadBitmaps[i][j] = NULL;
+					pomm = reader->map.undergroungTerrain;
 				}
-			}
-		}
-	}
-
-	staticRiverBitmaps = new SDL_Surface **[reader->map.width+2*Woff];
-	for (int ii=0;ii<reader->map.width+2*Woff;ii++)
-		staticRiverBitmaps[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory 
-
-	for (int i=0; i<reader->map.width+2*Woff; i++) //jest po szerokoœci
-	{
-		for (int j=0; j<reader->map.height+2*Hoff;j++) //po wysokoœci
-		{
-			if(i<Woff || i>reader->map.width+Woff-1 || j<Woff || j>reader->map.height+Hoff-1)
-				staticRiverBitmaps[i][j] = NULL;
-			else
-			{
-				if(reader->map.terrain[i-Woff][j-Hoff].nuine)
+				if(pomm[i-Woff][j-Hoff].nuine)
 				{
-					staticRiverBitmaps[i][j] = staticRiverDefs[reader->map.terrain[i-Woff][j-Hoff].nuine-1]->ourImages[reader->map.terrain[i-Woff][j-Hoff].rivDir].bitmap;
-					int cDir = reader->map.terrain[i-Woff][j-Hoff].rivDir;
-					if(cDir==0 || cDir==1 || cDir==2 || cDir==3)
+					int cDir;
+					bool rotH, rotV;
+					if(k==0)
 					{
-						if(i-Woff+1<reader->map.width && j-Hoff-1>0 && reader->map.terrain[i-Woff+1][j-Hoff].nuine && reader->map.terrain[i-Woff][j-Hoff-1].nuine)
-						{
-							staticRiverBitmaps[i][j] = CSDL_Ext::hFlip(staticRiverBitmaps[i][j]);
-							staticRiverBitmaps[i][j] = CSDL_Ext::alphaTransform(staticRiverBitmaps[i][j]);
-							staticRiverBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(staticRiverBitmaps[i][j], su);
-						}
-						if(i-Woff-1>0 && j-Hoff-1>0 && reader->map.terrain[i-Woff-1][j-Hoff].nuine && reader->map.terrain[i-Woff][j-Hoff-1].nuine)
-						{
-							staticRiverBitmaps[i][j] = CSDL_Ext::rotate03(staticRiverBitmaps[i][j]);
-							staticRiverBitmaps[i][j] = CSDL_Ext::alphaTransform(staticRiverBitmaps[i][j]);
-							staticRiverBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(staticRiverBitmaps[i][j], su);
-						}
-						if(i-Woff-1>0 && j-Hoff+1<reader->map.height && reader->map.terrain[i-Woff-1][j-Hoff].nuine && reader->map.terrain[i-Woff][j-Hoff+1].nuine)
-						{
-							staticRiverBitmaps[i][j] = CSDL_Ext::rotate01(staticRiverBitmaps[i][j]);
-							staticRiverBitmaps[i][j] = CSDL_Ext::alphaTransform(staticRiverBitmaps[i][j]);
-							staticRiverBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(staticRiverBitmaps[i][j], su);
-						}
+						ttiles[i][j][k].rivbitmap.push_back(staticRiverDefs[reader->map.terrain[i-Woff][j-Hoff].nuine-1]->ourImages[reader->map.terrain[i-Woff][j-Hoff].rivDir].bitmap);
+						cDir = reader->map.terrain[i-Woff][j-Hoff].rivDir;
+						rotH = (reader->map.terrain[i-Woff][j-Hoff].siodmyTajemniczyBajt >> 3) & 1;
+						rotV = (reader->map.terrain[i-Woff][j-Hoff].siodmyTajemniczyBajt >> 2) & 1;
 					}
-					if(cDir==5 || cDir==6)
+					else
 					{
-						if(j-Hoff+1<reader->map.height && !(reader->map.terrain[i-Woff][j-Hoff+1].nuine))
-						{
-							staticRiverBitmaps[i][j] = CSDL_Ext::hFlip(staticRiverBitmaps[i][j]);
-							staticRiverBitmaps[i][j] = CSDL_Ext::alphaTransform(staticRiverBitmaps[i][j]);
-							staticRiverBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(staticRiverBitmaps[i][j], su);
-						}
+						ttiles[i][j][k].rivbitmap.push_back(staticRiverDefs[reader->map.undergroungTerrain[i-Woff][j-Hoff].nuine-1]->ourImages[reader->map.undergroungTerrain[i-Woff][j-Hoff].rivDir].bitmap);
+						cDir = reader->map.undergroungTerrain[i-Woff][j-Hoff].rivDir;
+						rotH = (reader->map.undergroungTerrain[i-Woff][j-Hoff].siodmyTajemniczyBajt >> 3) & 1;
+						rotV = (reader->map.undergroungTerrain[i-Woff][j-Hoff].siodmyTajemniczyBajt >> 2) & 1;
 					}
-					if(cDir==7 || cDir==8)
+					if(rotH)
 					{
-						if(i-Woff+1<reader->map.width && !(reader->map.terrain[i-Woff+1][j-Hoff].nuine))
-						{
-							staticRiverBitmaps[i][j] = CSDL_Ext::rotate01(staticRiverBitmaps[i][j]);
-							staticRiverBitmaps[i][j] = CSDL_Ext::alphaTransform(staticRiverBitmaps[i][j]);
-							staticRiverBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(staticRiverBitmaps[i][j], su);
-						}
+						ttiles[i][j][k].rivbitmap[0] = CSDL_Ext::hFlip(ttiles[i][j][k].rivbitmap[0]);
 					}
-				}
-				else
-					staticRiverBitmaps[i][j] = NULL;
-			}
-		}
-	}
-
-	undStaticRiverBitmaps = new SDL_Surface **[reader->map.width+2*Woff];
-	for (int ii=0;ii<reader->map.width+2*Woff;ii++)
-		undStaticRiverBitmaps[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory 
-
-	if(reader->map.twoLevel)
-	{
-		for (int i=0; i<reader->map.width+2*Woff; i++) //jest po szerokoœci
-		{
-			for (int j=0; j<reader->map.height+2*Hoff;j++) //po wysokoœci
-			{
-				if(i<Woff || i>reader->map.width+Woff-1 || j<Woff || j>reader->map.height+Hoff-1)
-					undStaticRiverBitmaps[i][j] = NULL;
-				else
-				{
-					if(reader->map.undergroungTerrain[i-Woff][j-Hoff].nuine)
+					if(rotV)
 					{
-						undStaticRiverBitmaps[i][j] = staticRiverDefs[reader->map.undergroungTerrain[i-Woff][j-Hoff].nuine-1]->ourImages[reader->map.undergroungTerrain[i-Woff][j-Hoff].rivDir].bitmap;
-						int cDir = reader->map.undergroungTerrain[i-Woff][j-Hoff].rivDir;
-						if(cDir==0 || cDir==1 || cDir==2 || cDir==3)
-						{
-							if(i-Woff+1<reader->map.width && j-Hoff-1>0 && reader->map.undergroungTerrain[i-Woff+1][j-Hoff].nuine && reader->map.undergroungTerrain[i-Woff][j-Hoff-1].nuine)
-							{
-								undStaticRiverBitmaps[i][j] = CSDL_Ext::hFlip(undStaticRiverBitmaps[i][j]);
-								undStaticRiverBitmaps[i][j] = CSDL_Ext::alphaTransform(undStaticRiverBitmaps[i][j]);
-								undStaticRiverBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(undStaticRiverBitmaps[i][j], su);
-							}
-							if(i-Woff-1>0 && j-Hoff-1>0 && reader->map.undergroungTerrain[i-Woff-1][j-Hoff].nuine && reader->map.undergroungTerrain[i-Woff][j-Hoff-1].nuine)
-							{
-								undStaticRiverBitmaps[i][j] = CSDL_Ext::rotate03(undStaticRiverBitmaps[i][j]);
-								undStaticRiverBitmaps[i][j] = CSDL_Ext::alphaTransform(undStaticRiverBitmaps[i][j]);
-								undStaticRiverBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(undStaticRiverBitmaps[i][j], su);
-							}
-							if(i-Woff-1>0 && j-Hoff+1<reader->map.height && reader->map.undergroungTerrain[i-Woff-1][j-Hoff].nuine && reader->map.undergroungTerrain[i-Woff][j-Hoff+1].nuine)
-							{
-								undStaticRiverBitmaps[i][j] = CSDL_Ext::rotate01(undStaticRiverBitmaps[i][j]);
-								undStaticRiverBitmaps[i][j] = CSDL_Ext::alphaTransform(undStaticRiverBitmaps[i][j]);
-								undStaticRiverBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(undStaticRiverBitmaps[i][j], su);
-							}
-						}
-						if(cDir==5 || cDir==6)
-						{
-							if(j-Hoff+1<reader->map.height && !(reader->map.undergroungTerrain[i-Woff][j-Hoff+1].nuine))
-							{
-								undStaticRiverBitmaps[i][j] = CSDL_Ext::hFlip(undStaticRiverBitmaps[i][j]);
-								undStaticRiverBitmaps[i][j] = CSDL_Ext::alphaTransform(undStaticRiverBitmaps[i][j]);
-								undStaticRiverBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(undStaticRiverBitmaps[i][j], su);
-							}
-						}
-						if(cDir==7 || cDir==8)
-						{
-							if(i-Woff+1<reader->map.width && !(reader->map.undergroungTerrain[i-Woff+1][j-Hoff].nuine))
-							{
-								undStaticRiverBitmaps[i][j] = CSDL_Ext::rotate01(undStaticRiverBitmaps[i][j]);
-								undStaticRiverBitmaps[i][j] = CSDL_Ext::alphaTransform(undStaticRiverBitmaps[i][j]);
-								undStaticRiverBitmaps[i][j] = CSDL_Ext::secondAlphaTransform(undStaticRiverBitmaps[i][j], su);
-							}
-						}
+						ttiles[i][j][k].rivbitmap[0] = CSDL_Ext::rotate01(ttiles[i][j][k].rivbitmap[0]);
 					}
-					else
-						undStaticRiverBitmaps[i][j] = NULL;
+					ttiles[i][j][k].rivbitmap[0] = CSDL_Ext::alphaTransform(ttiles[i][j][k].rivbitmap[0]);
+					ttiles[i][j][k].rivbitmap[0] = CSDL_Ext::secondAlphaTransform(ttiles[i][j][k].rivbitmap[0], su);
 				}
 			}
 		}
@@ -395,202 +227,121 @@ void CMapHandler::init()
 
 	//road's and river's DefHandlers initialized
 
-	terrainBitmap = new SDL_Surface **[reader->map.width+2*Woff];
-	for (int ii=0;ii<reader->map.width+2*Woff;ii++)
-		terrainBitmap[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory 
+	//terrainBitmap = new SDL_Surface **[reader->map.width+2*Woff];
+	//for (int ii=0;ii<reader->map.width+2*Woff;ii++)
+	//	terrainBitmap[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory 
+
 	CDefHandler * bord = CGameInfo::mainObj->spriteh->giveDef("EDG.DEF");
 	for (int i=0; i<reader->map.width+2*Woff; i++) //jest po szerokoœci
 	{
 		for (int j=0; j<reader->map.height+2*Hoff;j++) //po wysokoœci
 		{
-			if(i < Woff || i > (reader->map.width+Woff-1) || j < Hoff  || j > (reader->map.height+Hoff-1))
-			{
-				if(i==Woff-1 && j==Hoff-1)
-				{
-					terrainBitmap[i][j] = bord->ourImages[16].bitmap;
-					continue;
-				}
-				else if(i==Woff-1 && j==(reader->map.height+Hoff))
-				{
-					terrainBitmap[i][j] = bord->ourImages[19].bitmap;
-					continue;
-				}
-				else if(i==(reader->map.width+Woff) && j==Hoff-1)
-				{
-					terrainBitmap[i][j] = bord->ourImages[17].bitmap;
-					continue;
-				}
-				else if(i==(reader->map.width+Woff) && j==(reader->map.height+Hoff))
-				{
-					terrainBitmap[i][j] = bord->ourImages[18].bitmap;
-					continue;
-				}
-				else if(j == Hoff-1 && i > Woff-1 && i < reader->map.height+Woff)
-				{
-					terrainBitmap[i][j] = bord->ourImages[22+rand()%2].bitmap;
-					continue;
-				}
-				else if(i == Woff-1 && j > Hoff-1 && j < reader->map.height+Hoff)
-				{
-					terrainBitmap[i][j] = bord->ourImages[33+rand()%2].bitmap;
-					continue;
-				}
-				else if(j == reader->map.height+Hoff && i > Woff-1 && i < reader->map.width+Woff)
-				{
-					terrainBitmap[i][j] = bord->ourImages[29+rand()%2].bitmap;
-					continue;
-				}
-				else if(i == reader->map.width+Woff && j > Hoff-1 && j < reader->map.height+Hoff)
-				{
-					terrainBitmap[i][j] = bord->ourImages[25+rand()%2].bitmap;
-					continue;
-				}
-				else
-				{
-					terrainBitmap[i][j] = bord->ourImages[rand()%16].bitmap;
-					continue;
-				}
-			}
-			TerrainTile zz = reader->map.terrain[i-Woff][j-Hoff];
-			std::string name = CSemiDefHandler::nameFromType(reader->map.terrain[i-Woff][j-Hoff].tertype);
-			for (unsigned int k=0; k<reader->defs.size(); k++)
-			{
-				try
-				{
-					if (reader->defs[k]->defName != name)
-						continue;
-					else
-					{
-						int ktora = reader->map.terrain[i-Woff][j-Hoff].terview;
-						terrainBitmap[i][j] = reader->defs[k]->ourImages[ktora].bitmap;
-						//TODO: odwracanie	
-						switch ((reader->map.terrain[i-Woff][j-Hoff].siodmyTajemniczyBajt)%4)
-						{
-						case 1:
-							{
-								terrainBitmap[i][j] = CSDL_Ext::rotate01(terrainBitmap[i][j]);
-								break;
-							}
-						case 2:
-							{
-								terrainBitmap[i][j] = CSDL_Ext::hFlip(terrainBitmap[i][j]);
-								break;
-							}
-						case 3:
-							{
-								terrainBitmap[i][j] = CSDL_Ext::rotate03(terrainBitmap[i][j]);
-								break;
-							}
-						}
-						//SDL_BlitSurface(terrainBitmap[i][j],NULL,ekran,NULL); SDL_Flip(ekran);SDL_Delay(50);
-
-						break;
-					}
-				}
-				catch (...)
-				{	continue;	}
-			}
-		}
-	}
-	if (reader->map.twoLevel)
-	{
-		undTerrainBitmap = new SDL_Surface **[reader->map.width+8];
-		for (int ii=0;ii<reader->map.width+8;ii++)
-			undTerrainBitmap[ii] = new SDL_Surface*[reader->map.height+8]; // allocate memory 
-		for (int i=0; i<reader->map.width+2*Woff; i++)
-		{
-			for (int j=0; j<reader->map.height+2*Hoff;j++)
+			for(int k=0; k<=reader->map.twoLevel; ++k)
 			{
 				if(i < Woff || i > (reader->map.width+Woff-1) || j < Hoff  || j > (reader->map.height+Hoff-1))
 				{
 					if(i==Woff-1 && j==Hoff-1)
 					{
-						undTerrainBitmap[i][j] = bord->ourImages[16].bitmap;
+						ttiles[i][j][k].terbitmap.push_back(bord->ourImages[16].bitmap);
 						continue;
 					}
 					else if(i==Woff-1 && j==(reader->map.height+Hoff))
 					{
-						undTerrainBitmap[i][j] = bord->ourImages[19].bitmap;
+						ttiles[i][j][k].terbitmap.push_back(bord->ourImages[19].bitmap);
 						continue;
 					}
 					else if(i==(reader->map.width+Woff) && j==Hoff-1)
 					{
-						undTerrainBitmap[i][j] = bord->ourImages[17].bitmap;
+						ttiles[i][j][k].terbitmap.push_back(bord->ourImages[17].bitmap);
 						continue;
 					}
 					else if(i==(reader->map.width+Woff) && j==(reader->map.height+Hoff))
 					{
-						undTerrainBitmap[i][j] = bord->ourImages[18].bitmap;
+						ttiles[i][j][k].terbitmap.push_back(bord->ourImages[18].bitmap);
 						continue;
 					}
-					else if(j == Hoff-1 && i > Woff-1 && i < reader->map.width+Woff)
+					else if(j == Hoff-1 && i > Woff-1 && i < reader->map.height+Woff)
 					{
-						undTerrainBitmap[i][j] = bord->ourImages[22+rand()%2].bitmap;
+						ttiles[i][j][k].terbitmap.push_back(bord->ourImages[22+rand()%2].bitmap);
 						continue;
 					}
 					else if(i == Woff-1 && j > Hoff-1 && j < reader->map.height+Hoff)
 					{
-						undTerrainBitmap[i][j] = bord->ourImages[33+rand()%2].bitmap;
+						ttiles[i][j][k].terbitmap.push_back(bord->ourImages[33+rand()%2].bitmap);
 						continue;
 					}
 					else if(j == reader->map.height+Hoff && i > Woff-1 && i < reader->map.width+Woff)
 					{
-						undTerrainBitmap[i][j] = bord->ourImages[29+rand()%2].bitmap;
+						ttiles[i][j][k].terbitmap.push_back(bord->ourImages[29+rand()%2].bitmap);
 						continue;
 					}
 					else if(i == reader->map.width+Woff && j > Hoff-1 && j < reader->map.height+Hoff)
 					{
-						undTerrainBitmap[i][j] = bord->ourImages[25+rand()%2].bitmap;
+						ttiles[i][j][k].terbitmap.push_back(bord->ourImages[25+rand()%2].bitmap);
 						continue;
 					}
 					else
 					{
-						undTerrainBitmap[i][j] = bord->ourImages[rand()%16].bitmap;
+						ttiles[i][j][k].terbitmap.push_back(bord->ourImages[rand()%16].bitmap);
 						continue;
 					}
 				}
-				TerrainTile zz = reader->map.undergroungTerrain[i-Woff][j-Hoff];
-				std::string name = CSemiDefHandler::nameFromType(reader->map.undergroungTerrain[i-Woff][j-Hoff].tertype);
-				for (unsigned int k=0; k<reader->defs.size(); k++)
+				//TerrainTile zz = reader->map.terrain[i-Woff][j-Hoff];
+				std::string name;
+				if (k>0)
+					name = CSemiDefHandler::nameFromType(reader->map.undergroungTerrain[i-Woff][j-Hoff].tertype);
+				else
+					name = CSemiDefHandler::nameFromType(reader->map.terrain[i-Woff][j-Hoff].tertype);
+				for (unsigned int m=0; m<reader->defs.size(); m++)
 				{
 					try
 					{
-						if (reader->defs[k]->defName != name)
+						if (reader->defs[m]->defName != name)
 							continue;
 						else
 						{
-							int ktora = reader->map.undergroungTerrain[i-Woff][j-Hoff].terview;
-							undTerrainBitmap[i][j] = reader->defs[k]->ourImages[ktora].bitmap;
-							//TODO: odwracanie	
-							switch ((reader->map.undergroungTerrain[i-Woff][j-Hoff].siodmyTajemniczyBajt)%4)
+							int ktora;
+							if (k==0)
+								ktora = reader->map.terrain[i-Woff][j-Hoff].terview;
+							else
+								ktora = reader->map.undergroungTerrain[i-Woff][j-Hoff].terview;
+							ttiles[i][j][k].terbitmap.push_back(reader->defs[m]->ourImages[ktora].bitmap);
+							int zz;
+							if (k==0)
+								zz = (reader->map.terrain[i-Woff][j-Hoff].siodmyTajemniczyBajt)%4;
+							else 
+								zz = (reader->map.undergroungTerrain[i-Woff][j-Hoff].siodmyTajemniczyBajt)%4;
+							switch (zz)
 							{
 							case 1:
 								{
-									undTerrainBitmap[i][j] = CSDL_Ext::rotate01(undTerrainBitmap[i][j]);
+									ttiles[i][j][k].terbitmap[0] = CSDL_Ext::rotate01(ttiles[i][j][k].terbitmap[0]);
 									break;
 								}
 							case 2:
 								{
-									undTerrainBitmap[i][j] = CSDL_Ext::hFlip(undTerrainBitmap[i][j]);
+									ttiles[i][j][k].terbitmap[0] = CSDL_Ext::hFlip(ttiles[i][j][k].terbitmap[0]);
 									break;
 								}
 							case 3:
 								{
-									undTerrainBitmap[i][j] = CSDL_Ext::rotate03(undTerrainBitmap[i][j]);
+									ttiles[i][j][k].terbitmap[0] = CSDL_Ext::rotate03(ttiles[i][j][k].terbitmap[0]);
 									break;
 								}
 							}
-							//SDL_BlitSurface(undTerrainBitmap[i][j],NULL,ekran,NULL); SDL_Flip(ekran);SDL_Delay(50);
+							//SDL_BlitSurface(terrainBitmap[i][j],NULL,ekran,NULL); SDL_Flip(ekran);SDL_Delay(50);
 
 							break;
 						}
 					}
 					catch (...)
-					{	continue;	}
+					{	
+						continue;	
+					}
 				}
-			} //end of internal for
-		} //end of external for
-	} //end of if
+			}
+		}
+	}
 }
 
 SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim)
@@ -620,14 +371,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 			sr->y=by*32;
 			sr->x=bx*32;
 			sr->h=sr->w=32;
-			if (!level)
-			{
-				SDL_BlitSurface(terrainBitmap[bx+x][by+y],NULL,su,sr);
-			}
-			else 
-			{
-				SDL_BlitSurface(undTerrainBitmap[bx+x][by+y],NULL,su,sr);
-			}
+			SDL_BlitSurface(ttiles[x+bx][y+by][level].terbitmap[anim%ttiles[x+bx][y+by][level].terbitmap.size()],NULL,su,sr);
 			delete sr;
 		}
 	}
@@ -641,16 +385,8 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 			sr->y=by*32;
 			sr->x=bx*32;
 			sr->h=sr->w=32;
-			if (!level)
-			{
-				if(staticRiverBitmaps[bx+x][by+y])
-					SDL_BlitSurface(staticRiverBitmaps[bx+x][by+y],NULL,su,sr);
-			}
-			else 
-			{
-				if(undStaticRiverBitmaps[bx+x][by+y])
-					SDL_BlitSurface(undStaticRiverBitmaps[bx+x][by+y],NULL,su,sr);
-			}
+			if(ttiles[x+bx][y+by][level].rivbitmap.size())
+				SDL_BlitSurface(ttiles[x+bx][y+by][level].rivbitmap[anim%ttiles[x+bx][y+by][level].rivbitmap.size()],NULL,su,sr);
 			delete sr;
 		}
 	}
@@ -661,19 +397,11 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 		for (int by=0; by<dy; by++)
 		{
 			SDL_Rect * sr = new SDL_Rect;
-			sr->y=by*32;
+			sr->y=by*32+16;
 			sr->x=bx*32;
 			sr->h=sr->w=32;
-			if (!level)
-			{
-				if(roadBitmaps[bx+x][by+y])
-					SDL_BlitSurface(roadBitmaps[bx+x][by+y],NULL,su,sr);
-			}
-			else 
-			{
-				if(undRoadBitmaps[bx+x][by+y])
-					SDL_BlitSurface(undRoadBitmaps[bx+x][by+y],NULL,su,sr);
-			}
+			if(ttiles[x+bx][y+by][level].roadbitmap.size())
+				SDL_BlitSurface(ttiles[x+bx][y+by][level].roadbitmap[anim%ttiles[x+bx][y+by][level].roadbitmap.size()],NULL,su,sr);
 			delete sr;
 		}
 	}
@@ -684,28 +412,28 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 	std::vector<ObjSorter> highPrObjsVis;
 	for(int gg=0; gg<CGameInfo::mainObj->objh->objInstances.size(); ++gg)
 	{
-		if(CGameInfo::mainObj->objh->objInstances[gg].pos.x >= x-Woff-4 && CGameInfo::mainObj->objh->objInstances[gg].pos.x < dx+x-Hoff+4 && CGameInfo::mainObj->objh->objInstances[gg].pos.y >= y-Hoff-4 && CGameInfo::mainObj->objh->objInstances[gg].pos.y < dy+y-Hoff+4 && CGameInfo::mainObj->objh->objInstances[gg].pos.z == level)
+		if(CGameInfo::mainObj->objh->objInstances[gg]->pos.x >= x-Woff-4 && CGameInfo::mainObj->objh->objInstances[gg]->pos.x < dx+x-Hoff+4 && CGameInfo::mainObj->objh->objInstances[gg]->pos.y >= y-Hoff-4 && CGameInfo::mainObj->objh->objInstances[gg]->pos.y < dy+y-Hoff+4 && CGameInfo::mainObj->objh->objInstances[gg]->pos.z == level)
 		{
-			if(!CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].isOnDefList)
+			if(!CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg]->defNumber].isOnDefList)
 			{
 				ObjSorter os;
-				os.bitmap = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[anim%CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages.size()].bitmap;
-				os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].pos.x-x+Woff)*32;
-				os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].pos.y-y+Hoff)*32;
+				os.bitmap = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg]->defNumber].handler->ourImages[anim%CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg]->defNumber].handler->ourImages.size()].bitmap;
+				os.xpos = (CGameInfo::mainObj->objh->objInstances[gg]->pos.x-x+Woff)*32;
+				os.ypos = (CGameInfo::mainObj->objh->objInstances[gg]->pos.y-y+Hoff)*32;
 				highPrObjsVis.push_back(os);
 			}
-			else if(CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].printPriority==0)
+			else if(CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg]->defNumber].printPriority==0)
 			{
 				ObjSorter os;
 
-				int defyod = CGameInfo::mainObj->objh->objInstances[gg].defNumber;
+				int defyod = CGameInfo::mainObj->objh->objInstances[gg]->defNumber;
 				int ourimagesod = anim%CGameInfo::mainObj->ac->map.defy[defyod].handler->ourImages.size();
 
 				os.bitmap = CGameInfo::mainObj->ac->map.defy[defyod].handler->ourImages[ourimagesod].bitmap;
 
-				os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].pos.x-x+Woff)*32;
-				os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].pos.y-y+Hoff)*32;
-				if (CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].isVisitable())
+				os.xpos = (CGameInfo::mainObj->objh->objInstances[gg]->pos.x-x+Woff)*32;
+				os.ypos = (CGameInfo::mainObj->objh->objInstances[gg]->pos.y-y+Hoff)*32;
+				if (CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg]->defNumber].isVisitable())
 					highPrObjsVis.push_back(os);
 				else
 					highPrObjs.push_back(os);
@@ -713,9 +441,9 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 			else
 			{
 				ObjSorter os;
-				os.bitmap = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[anim%CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages.size()].bitmap;
-				os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].pos.x-x+Woff)*32;
-				os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].pos.y-y+Hoff)*32;
+				os.bitmap = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg]->defNumber].handler->ourImages[anim%CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg]->defNumber].handler->ourImages.size()].bitmap;
+				os.xpos = (CGameInfo::mainObj->objh->objInstances[gg]->pos.x-x+Woff)*32;
+				os.ypos = (CGameInfo::mainObj->objh->objInstances[gg]->pos.y-y+Hoff)*32;
 				lowPrObjs.push_back(os);
 			}
 		}
@@ -823,14 +551,9 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 			sr->y=by*32;
 			sr->x=bx*32;
 			sr->h=sr->w=32;
-			if (!level)
-			{
-				SDL_BlitSurface(terrainBitmap[bx+x][by+y],NULL,su,sr);
-			}
-			else 
-			{
-				SDL_BlitSurface(undTerrainBitmap[bx+x][by+y],NULL,su,sr);
-			}
+
+			SDL_BlitSurface(ttiles[x+bx][y+by][level].terbitmap[anim%ttiles[x+bx][y+by][level].terbitmap.size()],NULL,su,sr);
+
 			delete sr;
 			}
 		}
@@ -841,12 +564,12 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 
 SDL_Surface * CMapHandler::terrBitmap(int x, int y)
 {
-	return terrainBitmap[x+4][y+4];
+	return ttiles[x+Woff][y+Hoff][0].terbitmap[0];
 }
 
 SDL_Surface * CMapHandler::undTerrBitmap(int x, int y)
 {
-	return undTerrainBitmap[x+4][y+4];
+	return ttiles[x+Woff][y+Hoff][0].terbitmap[1];
 }
 
 SDL_Surface * CMapHandler::getVisBitmap(int x, int y, std::vector< std::vector<char> > & visibility)

+ 36 - 7
mapHandler.h

@@ -5,7 +5,7 @@
 #include "CSemiDefHandler.h"
 #include "CGameInfo.h"
 #include "CDefHandler.h"
-
+#include <boost/logic/tribool.hpp>
 const int Woff = 4; //width of map's frame
 const int Hoff = 4; 
 
@@ -16,12 +16,41 @@ struct ObjSorter
 	bool operator<(const ObjSorter & por) const;
 };
 
+
+struct TerrainTile2
+{
+	int3 pos;
+	EterrainType typ;
+
+	Eroad malle;
+	unsigned char roaddir;
+
+	Eriver nuine;
+	unsigned char  rivdir;
+
+	std::vector<SDL_Surface *> terbitmap; //frames of animation
+	std::vector<SDL_Surface *> rivbitmap; //frames of animation
+	std::vector<SDL_Surface *> roadbitmap; //frames of animation
+
+	boost::logic::tribool state; //false = free; true = blocked; middle = visitable
+
+	std::vector < std::pair<CObjectInstance*,SDL_Rect> > objects;
+	std::vector <CObjectInstance*> visitableObjects;
+
+};
+	
+
+//pathfinder
+//	map<int,int> iDTerenu=>koszt_pola
+//	map<int,int> IDdrogi=>koszt_drogi
+
 class CMapHandler
 {
 public:
+	std::vector< std::vector< std::vector<TerrainTile2> > > ttiles;
 	CAmbarCendamo * reader;
-	SDL_Surface *** terrainBitmap;
-	SDL_Surface *** undTerrainBitmap; // used only if there is underground level
+	//SDL_Surface *** terrainBitmap;
+	//SDL_Surface *** undTerrainBitmap; // used only if there is underground level
 	SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0);
 	SDL_Surface * terrBitmap(int x, int y);
 	SDL_Surface * undTerrBitmap(int x, int y);
@@ -32,10 +61,10 @@ public:
 	std::vector< std::vector<char> > undVisibility; //true means that pointed place is visible
 	std::vector<CDefHandler *> roadDefs;
 	std::vector<CDefHandler *> staticRiverDefs;
-	SDL_Surface *** roadBitmaps;
-	SDL_Surface *** undRoadBitmaps;
-	SDL_Surface *** staticRiverBitmaps;
-	SDL_Surface *** undStaticRiverBitmaps;
+	//SDL_Surface *** roadBitmaps;
+	//SDL_Surface *** undRoadBitmaps;
+	//SDL_Surface *** staticRiverBitmaps;
+	//SDL_Surface *** undStaticRiverBitmaps;
 	char & visAccess(int x, int y);
 	char & undVisAccess(int x, int y);
 	SDL_Surface mirrorImage(SDL_Surface *src); //what is this??