瀏覽代碼

Mainly refactoring

Michał W. Urbańczyk 17 年之前
父節點
當前提交
08b6796545
共有 11 個文件被更改,包括 187 次插入342 次删除
  1. 3 3
      CAdvmapInterface.cpp
  2. 26 116
      CCallback.cpp
  3. 28 28
      CConsoleHandler.cpp
  4. 6 6
      CPathfinder.cpp
  5. 1 1
      CPlayerInterface.cpp
  6. 0 1
      hch/CObjectHandler.h
  7. 3 0
      map.cpp
  8. 1 0
      map.h
  9. 104 165
      mapHandler.cpp
  10. 6 16
      mapHandler.h
  11. 9 6
      server/CGameHandler.cpp

+ 3 - 3
CAdvmapInterface.cpp

@@ -146,9 +146,9 @@ void CMinimap::redraw(int level)// (level==-1) => redraw all levels
 			{
 				int mx=(CGI->mh->sizes.x*x)/pos.w;
 				int my=(CGI->mh->sizes.y*y)/pos.h;
-				if (CGI->mh->ttiles[mx][my][i].blocked && (!CGI->mh->ttiles[mx][my][i].visitable))
-					SDL_PutPixel(pom,x,y,colorsBlocked[CGI->mh->ttiles[mx][my][i].terType].r,colorsBlocked[CGI->mh->ttiles[mx][my][i].terType].g,colorsBlocked[CGI->mh->ttiles[mx][my][i].terType].b);
-				else SDL_PutPixel(pom,x,y,colors[CGI->mh->ttiles[mx][my][i].terType].r,colors[CGI->mh->ttiles[mx][my][i].terType].g,colors[CGI->mh->ttiles[mx][my][i].terType].b);
+				if (CGI->mh->ttiles[mx][my][i].tileInfo->blocked && (!CGI->mh->ttiles[mx][my][i].tileInfo->visitable))
+					SDL_PutPixel(pom,x,y,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].r,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].g,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].b);
+				else SDL_PutPixel(pom,x,y,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].r,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].g,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].b);
 			}
 		}
 		map.push_back(pom);

+ 26 - 116
CCallback.cpp

@@ -93,107 +93,6 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
 				return false;
 		}
 	}
-
-	//	if(hero->movement >= (ourPath->nodes.size()>=2 ?  (*(ourPath->nodes.end()-2)).dist : 0) - ourPath->nodes[i].dist  || player==-1)
-	//	{ //performing move
-	//		hero->movement -= (ourPath->nodes.size()>=2 ?  (*(ourPath->nodes.end()-2)).dist : 0) - ourPath->nodes[i].dist;
-	//		ourPath->nodes.pop_back();
-	//		
-	//		std::vector< CGObjectInstance * > vis = CGI->mh->getVisitableObjs(CGHeroInstance::convertPosition(curd.dst,false));
-	//		bool blockvis = false;
-	//		for (int pit = 0; pit<vis.size();pit++)
-	//			if (vis[pit]->blockVisit)
-	//				blockvis = true;
-
-	//		if (!blockvis)
-	//		{
-	//			curd.successful = true;
-	//			hero->pos = curd.dst;
-
-	//			//inform leaved objects
-	//			std::vector< CGObjectInstance * > leave = CGI->mh->getVisitableObjs(CGHeroInstance::convertPosition(curd.src,false));
-	//			for (int iii=0; iii<leave.size(); iii++) //if object is visitable we call onHeroVisit
-	//			{
-	//				//TODO: allow to handle this in LUA
-	//				if(leave[iii]->state) //hard-coded function
-	//					leave[iii]->state->onHeroLeave(leave[iii],curd.ho->subID);
-	//			}
-
-
-	//			//reveal fog of war
-	//			int heroSight = hero->getSightDistance();
-	//			int xbeg = stpos.x - heroSight - 2;
-	//			if(xbeg < 0)
-	//				xbeg = 0;
-	//			int xend = stpos.x + heroSight + 2;
-	//			if(xend >= CGI->mh->map->width)
-	//				xend = CGI->mh->map->width;
-	//			int ybeg = stpos.y - heroSight - 2;
-	//			if(ybeg < 0)
-	//				ybeg = 0;
-	//			int yend = stpos.y + heroSight + 2;
-	//			if(yend >= CGI->mh->map->height)
-	//				yend = CGI->mh->map->height;
-	//			for(int xd=xbeg; xd<xend; ++xd) //revealing part of map around heroes
-	//			{
-	//				for(int yd=ybeg; yd<yend; ++yd)
-	//				{
-	//					int deltaX = (hero->getPosition(false).x-xd)*(hero->getPosition(false).x-xd);
-	//					int deltaY = (hero->getPosition(false).y-yd)*(hero->getPosition(false).y-yd);
-	//					if(deltaX+deltaY<hero->getSightDistance()*hero->getSightDistance())
-	//					{
-	//						if(gs->players[player].fogOfWarMap[xd][yd][hero->getPosition(false).z] == 0)
-	//						{
-	//							cl->playerint[player]->tileRevealed(int3(xd, yd, hero->getPosition(false).z));
-	//						}
-	//						gs->players[player].fogOfWarMap[xd][yd][hero->getPosition(false).z] = 1;
-	//					}
-	//				}
-	//			}
-
-
-	//			//notify interfacesabout move
-	//			int nn=0; //number of interfece of currently browsed player
-	//			for(std::map<ui8, PlayerState>::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j)//CGI->state->players.size(); ++j) //for testing
-	//			{
-	//				if (j->first > PLAYER_LIMIT)
-	//					break;
-	//				if(j->second.fogOfWarMap[stpos.x-1][stpos.y][stpos.z] || j->second.fogOfWarMap[endpos.x-1][endpos.y][endpos.z])
-	//				{ //player should be notified
-	//					cl->playerint[j->second.color]->heroMoved(curd);
-	//				}
-	//				++nn;
-	//			}
-
-
-	//			//call objects if they arevisited
-	//			for (int iii=0; iii<vis.size(); iii++) //if object is visitable we call onHeroVisit
-	//			{
-	//				if(gs->checkFunc(vis[iii]->ID,"heroVisit")) //script function
-	//					gs->objscr[vis[iii]->ID]["heroVisit"]->onHeroVisit(vis[iii],curd.ho->subID);
-	//				if(vis[iii]->state) //hard-coded function
-	//					vis[iii]->state->onHeroVisit(vis[iii],curd.ho->subID);
-	//			}
-	//		}
-	//		else //interaction with blocking object (like resources)
-	//		{
-	//			curd.successful = false;
-	//			cl->playerint[gs->players[hero->getOwner()].color]->heroMoved(curd);
-	//			for (int iii=0; iii<vis.size(); iii++) //if object is visitable we call onHeroVisit
-	//			{
-	//				if (vis[iii]->blockVisit)
-	//				{
-	//					if(gs->checkFunc(vis[iii]->ID,"heroVisit")) //script function
-	//						gs->objscr[vis[iii]->ID]["heroVisit"]->onHeroVisit(vis[iii],curd.ho->subID);
-	//					if(vis[iii]->state) //hard-coded function
-	//						vis[iii]->state->onHeroVisit(vis[iii],curd.ho->subID);
-	//				}
-	//			}
-	//			return false;
-	//		}
-
-	//	}
-	//}
 	return true;
 }
 
@@ -393,12 +292,30 @@ int CCallback::getDate(int mode)
 {
 	return gs->getDate(mode);
 }
+std::vector < std::string > CCallback::getObjDescriptions(int3 pos)
+{
+	std::vector<std::string> ret;
+	//BOOST_FOREACH(const CGObjectInstance * obj, gs->map->terrain[i][j]
+	//{
+	//	if( (5-(objs[g].first->pos.y-pos.y)) >= 0 && (5-(objs[g].first->pos.y-pos.y)) < 6 && (objs[g].first->pos.x-pos.x) >= 0 && (objs[g].first->pos.x-pos.x)<7 && objs[g].first->defInfo &&
+	//		(((objs[g].first->defInfo->blockMap[5-(objs[g].first->pos.y-pos.y)])>>((objs[g].first->pos.x-pos.x)))&1)==0
+	//		) //checking position blocking
+	//	{
+	//		//unsigned char * blm = objs[g].first->defInfo->blockMap;
+	//		if (objs[g].first->state)
+	//			ret.push_back(objs[g].first->state->hoverText(objs[g].first));
+	//		else
+	//			ret.push_back(CGI->objh->objects[objs[g].first->ID].name);
+	//	}
+	//}
+	return ret;
+}
 bool CCallback::verifyPath(CPath * path, bool blockSea)
 {
 	for (int i=0;i<path->nodes.size();i++)
 	{
-		if ( CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].blocked 
-			&& (! (CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].visitable)))
+		if ( CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->blocked 
+			&& (! (CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->visitable)))
 			return false; //path is wrong - one of the tiles is blocked
 
 		if (blockSea)
@@ -407,15 +324,15 @@ bool CCallback::verifyPath(CPath * path, bool blockSea)
 				continue;
 
 			if (
-					((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].terType==EterrainType::water)
+					((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->tertype==EterrainType::water)
 					&&
-					(CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].terType!=EterrainType::water))
+					(CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype!=EterrainType::water))
 				  ||
-					((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].terType!=EterrainType::water)
+					((CGI->mh->ttiles[path->nodes[i].coord.x][path->nodes[i].coord.y][path->nodes[i].coord.z].tileInfo->tertype!=EterrainType::water)
 					&&
-					(CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].terType==EterrainType::water))
+					(CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype==EterrainType::water))
 				  ||
-				  (CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].terType==EterrainType::rock)
+				  (CGI->mh->ttiles[path->nodes[i-1].coord.x][path->nodes[i-1].coord.y][path->nodes[i-1].coord.z].tileInfo->tertype==EterrainType::rock)
 					
 				)
 				return false;
@@ -426,13 +343,6 @@ bool CCallback::verifyPath(CPath * path, bool blockSea)
 	return true;
 }
 
-std::vector < std::string > CCallback::getObjDescriptions(int3 pos)
-{
-	if(gs->players[player].fogOfWarMap[pos.x][pos.y][pos.z])
-		return CGI->mh->getObjDescriptions(pos);
-	else return std::vector< std::string > ();
-}
-
 std::vector< std::vector< std::vector<unsigned char> > > & CCallback::getVisibilityMap()
 {
 	return gs->players[player].fogOfWarMap;
@@ -654,7 +564,7 @@ bool CCallback::buildBuilding(const CGTownInstance *town, int buildingID)
 
 int CCallback::battleGetBattlefieldType()
 {
-	return CGI->mh->ttiles[CGI->state->curB->tile.x][CGI->state->curB->tile.y][CGI->state->curB->tile.z].terType;
+	return CGI->mh->ttiles[CGI->state->curB->tile.x][CGI->state->curB->tile.y][CGI->state->curB->tile.z].tileInfo->tertype;
 }
 
 int CCallback::battleGetObstaclesAtTile(int tile) //returns bitfield 

+ 28 - 28
CConsoleHandler.cpp

@@ -100,34 +100,34 @@ int internalFunc(void * callback)
 			//		//LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]);
 			//		break;
 			//	}
-			case 'D': //pos description
-				readed>>src;
-				CGI->mh->getObjDescriptions(src);
-				break;
-			case 'I': 
-				{
-					SDL_Surface * temp = LOCPLINT->infoWin(NULL);
-					blitAtWR(temp,605,389);
-					SDL_FreeSurface(temp);
-					break;
-				}
-			case 'T': //test rect
-				readed>>src;
-				for(int g=0; g<8; ++g)
-				{
-					for(int v=0; v<8; ++v)
-					{
-						int3 csrc = src;
-						csrc.y+=g;
-						csrc.x+=v;
-						if(CGI->mh->getObjDescriptions(csrc).size())
-							std::cout<<'x';
-						else
-							std::cout<<'o';
-					}
-					std::cout<<std::endl;
-				}
-				break;
+			//case 'D': //pos description
+			//	readed>>src;
+			//	CGI->mh->getObjDescriptions(src);
+			//	break;
+			//case 'I': 
+			//	{
+			//		SDL_Surface * temp = LOCPLINT->infoWin(NULL);
+			//		blitAtWR(temp,605,389);
+			//		SDL_FreeSurface(temp);
+			//		break;
+			//	}
+			//case 'T': //test rect
+			//	readed>>src;
+			//	for(int g=0; g<8; ++g)
+			//	{
+			//		for(int v=0; v<8; ++v)
+			//		{
+			//			int3 csrc = src;
+			//			csrc.y+=g;
+			//			csrc.x+=v;
+			//			if(CGI->mh->getObjDescriptions(csrc).size())
+			//				std::cout<<'x';
+			//			else
+			//				std::cout<<'o';
+			//		}
+			//		std::cout<<std::endl;
+			//	}
+			//	break;
 			//case 'A':  //hide everything from map
 			//	for(int c=0; c<CGI->objh->objInstances.size(); ++c)
 			//	{

+ 6 - 6
CPathfinder.cpp

@@ -42,7 +42,7 @@ vector<Coordinate>* CPathfinder::GetPath(const CGHeroInstance* hero)
 	int3 hpos = Hero->getPosition(false);
 	if (!Hero->canWalkOnSea())
 	{
-		if (CGI->mh->ttiles[hpos.x][hpos.y][hpos.z].terType==EterrainType::water)
+		if (CGI->mh->ttiles[hpos.x][hpos.y][hpos.z].tileInfo->tertype==EterrainType::water)
 			blockLandSea=false;
 		else
 			blockLandSea=true;
@@ -192,11 +192,11 @@ void CPathfinder::CalcH(Coordinate* node)
 	 * If there is fog of war on the node.
 	 *  => Impossible to move there.
 	 */
-	if( (CGI->mh->ttiles[node->x][node->y][node->z].blocked && !(node->x==End.x && node->y==End.y && CGI->mh->ttiles[node->x][node->y][node->z].visitable)) ||
-		(CGI->mh->ttiles[node->x][node->y][node->z].terType==EterrainType::rock) ||
-		((blockLandSea) && (CGI->mh->ttiles[node->x][node->y][node->z].terType==EterrainType::water)) ||
+	if( (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->blocked && !(node->x==End.x && node->y==End.y && CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->visitable)) ||
+		(CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->tertype==EterrainType::rock) ||
+		((blockLandSea) && (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->tertype==EterrainType::water)) ||
 		(!CGI->state->players[Hero->tempOwner].fogOfWarMap[node->x][node->y][node->z]) ||
-		((!blockLandSea) && (CGI->mh->ttiles[node->x][node->y][node->z].terType!=EterrainType::water)))
+		((!blockLandSea) && (CGI->mh->ttiles[node->x][node->y][node->z].tileInfo->tertype!=EterrainType::water)))
 	{
 		//Impossible.
 	
@@ -213,7 +213,7 @@ void CPathfinder::CalcH(Coordinate* node)
 		y = CGI->mh->map->height-1;
 
 	//Get the movement cost.
-	ret = Hero->getTileCost(CGI->mh->ttiles[x][y][node->z].terType, CGI->mh->map->terrain[x][y].malle,CGI->mh->map->terrain[x][y].nuine);
+	ret = Hero->getTileCost(CGI->mh->ttiles[x][y][node->z].tileInfo->tertype, CGI->mh->map->terrain[x][y].malle,CGI->mh->map->terrain[x][y].nuine);
 	
 	node->h = ret;
 }

+ 1 - 1
CPlayerInterface.cpp

@@ -44,7 +44,7 @@ extern boost::mutex eventsM;
 class OCM_HLP_CGIN
 {
 public:
-	bool operator ()(const std::pair<CGObjectInstance*,SDL_Rect>  & a, const std::pair<CGObjectInstance*,SDL_Rect> & b) const
+	bool operator ()(const std::pair<const CGObjectInstance*,SDL_Rect>  & a, const std::pair<const CGObjectInstance*,SDL_Rect> & b) const
 	{
 		return (*a.first)<(*b.first);
 	}

+ 0 - 1
hch/CObjectHandler.h

@@ -88,7 +88,6 @@ public:
 					//		8 4
 					//		765
 	bool isStanding;
-	bool flagPrinted;
 	CHero * type;
 	int exp; //experience point
 	int level; //current level of hero

+ 3 - 0
map.cpp

@@ -2316,7 +2316,10 @@ borderguardend:
 						curt.visitable = true;
 					}
 					if(!((objects[f]->defInfo->blockMap[fy] >> (7 - fx)) & 1))
+					{
+						curt.blockingObjects.push_back(objects[f]);
 						curt.blocked = true;
+					}
 				}
 			}
 		}

+ 1 - 0
map.h

@@ -268,6 +268,7 @@ struct DLL_EXPORT TerrainTile
 	bool blocked; //false = free; true = blocked;
 
 	std::vector <CGObjectInstance*> visitableObjects; //pointers to objects hero can visit while being on this tile
+	std::vector <CGObjectInstance*> blockingObjects; //pointers to objects that are blocking this tile
 };
 struct DLL_EXPORT SheroName //name of starting hero
 {

+ 104 - 165
mapHandler.cpp

@@ -77,7 +77,7 @@ std::string nameFromType (EterrainType typ)
 class OCM_HLP
 {
 public:
-	bool operator ()(const std::pair<CGObjectInstance*, SDL_Rect> & a, const std::pair<CGObjectInstance*, SDL_Rect> & b)
+	bool operator ()(const std::pair<const CGObjectInstance*, SDL_Rect> & a, const std::pair<const CGObjectInstance*, SDL_Rect> & b)
 	{
 		return (*a.first)<(*b.first);
 	}
@@ -227,37 +227,23 @@ void CMapHandler::roadsRiverTerrainInit()
 		{
 			for (int k=0; k<=map->twoLevel; ++k)
 			{
-				TerrainTile** pomm = map->terrain; ;
-				if (k==0)
-					pomm = map->terrain;
-				else
-					pomm = map->undergroungTerrain;
-				if(pomm[i][j].malle)
+				TerrainTile2 &pom(ttiles[i][j][k]);
+				pom.pos = int3(i, j, k);
+				pom.tileInfo = &( k  ?  map->undergroungTerrain[i][j]  :  map->terrain[i][j] );
+				if(pom.tileInfo->malle)
 				{
 					int cDir;
 					bool rotV, rotH;
-					if(k==0)
-					{
-						int roadpom = map->terrain[i][j].malle-1,
-							impom = map->terrain[i][j].roadDir;
-						SDL_Surface *pom1 = roadDefs[roadpom]->ourImages[impom].bitmap;
-						ttiles[i][j][k].roadbitmap.push_back(pom1);
-						cDir = map->terrain[i][j].roadDir;
 
-						rotH = (map->terrain[i][j].siodmyTajemniczyBajt >> 5) & 1;
-						rotV = (map->terrain[i][j].siodmyTajemniczyBajt >> 4) & 1;
-					}
-					else
-					{
-						int pom111 = map->undergroungTerrain[i][j].malle-1,
-							pom777 = map->undergroungTerrain[i][j].roadDir;
-						SDL_Surface *pom1 = roadDefs[pom111]->ourImages[pom777].bitmap;
-						ttiles[i][j][k].roadbitmap.push_back(pom1);
-						cDir = map->undergroungTerrain[i][j].roadDir;
+					int roadpom = pom.tileInfo->malle-1,
+						impom = pom.tileInfo->roadDir;
+					SDL_Surface *pom1 = roadDefs[roadpom]->ourImages[impom].bitmap;
+					ttiles[i][j][k].roadbitmap.push_back(pom1);
+					cDir = pom.tileInfo->roadDir;
+
+					rotH = (pom.tileInfo->siodmyTajemniczyBajt >> 5) & 1;
+					rotV = (pom.tileInfo->siodmyTajemniczyBajt >> 4) & 1;
 
-						rotH = (map->undergroungTerrain[i][j].siodmyTajemniczyBajt >> 5) & 1;
-						rotV = (map->undergroungTerrain[i][j].siodmyTajemniczyBajt >> 4) & 1;
-					}
 					if(rotH)
 					{
 						ttiles[i][j][k].roadbitmap[0] = CSDL_Ext::hFlip(ttiles[i][j][k].roadbitmap[0]);
@@ -275,32 +261,6 @@ void CMapHandler::roadsRiverTerrainInit()
 		}
 	}
 
-	//initializing simple values
-	for (int i=0; i<CGI->mh->map->width; i++) //jest po szerokoœci
-	{
-		for (int j=0; j<CGI->mh->map->height;j++) //po wysokoœci
-		{
-			for(int k=0; k<ttiles[0][0].size(); ++k)
-			{
-				ttiles[i][j][k].pos = int3(i, j, k);
-				ttiles[i][j][k].blocked = false;
-				ttiles[i][j][k].visitable = false;
-				if(i<0 || j<0 || i>=CGI->mh->map->width || j>=CGI->mh->map->height)
-				{
-					ttiles[i][j][k].blocked = true;
-					continue;
-				}
-				ttiles[i][j][k].terType = (k==0 ? CGI->mh->map->terrain[i][j].tertype : CGI->mh->map->undergroungTerrain[i][j].tertype);
-				ttiles[i][j][k].malle = (k==0 ? CGI->mh->map->terrain[i][j].malle : CGI->mh->map->undergroungTerrain[i][j].malle);
-				ttiles[i][j][k].nuine = (k==0 ? CGI->mh->map->terrain[i][j].nuine : CGI->mh->map->undergroungTerrain[i][j].nuine);
-				ttiles[i][j][k].rivdir = (k==0 ? CGI->mh->map->terrain[i][j].rivDir : CGI->mh->map->undergroungTerrain[i][j].rivDir);
-				ttiles[i][j][k].roaddir = (k==0 ? CGI->mh->map->terrain[i][j].roadDir : CGI->mh->map->undergroungTerrain[i][j].roadDir);
-
-			}
-		}
-	}
-	//simple values initialized
-
 	for (int i=0; i<map->width; i++) //jest po szerokoœci
 	{
 		for (int j=0; j<map->height;j++) //po wysokoœci
@@ -517,29 +477,29 @@ void CMapHandler::initObjectRects()
 }
 void CMapHandler::calculateBlockedPos()
 {
-	for(int f=0; f<map->objects.size(); ++f) //calculationg blocked / visitable positions
-	{
-		if(!map->objects[f]->defInfo)
-			continue;
-		CDefHandler * curd = map->objects[f]->defInfo->handler;
-		for(int fx=0; fx<8; ++fx)
-		{
-			for(int fy=0; fy<6; ++fy)
-			{
-				int xVal = map->objects[f]->pos.x + fx - 7;
-				int yVal = map->objects[f]->pos.y + fy - 5;
-				int zVal = map->objects[f]->pos.z;
-				if(xVal>=0 && xVal<ttiles.size()-Woff && yVal>=0 && yVal<ttiles[0].size()-Hoff)
-				{
-					TerrainTile2 & curt = ttiles[xVal][yVal][zVal];
-					if(((map->objects[f]->defInfo->visitMap[fy] >> (7 - fx)) & 1))
-						curt.visitable = true;
-					if(!((map->objects[f]->defInfo->blockMap[fy] >> (7 - fx)) & 1))
-						curt.blocked = true;
-				}
-			}
-		}
-	}
+	//for(int f=0; f<map->objects.size(); ++f) //calculationg blocked / visitable positions
+	//{
+	//	if(!map->objects[f]->defInfo)
+	//		continue;
+	//	CDefHandler * curd = map->objects[f]->defInfo->handler;
+	//	for(int fx=0; fx<8; ++fx)
+	//	{
+	//		for(int fy=0; fy<6; ++fy)
+	//		{
+	//			int xVal = map->objects[f]->pos.x + fx - 7;
+	//			int yVal = map->objects[f]->pos.y + fy - 5;
+	//			int zVal = map->objects[f]->pos.z;
+	//			if(xVal>=0 && xVal<ttiles.size()-Woff && yVal>=0 && yVal<ttiles[0].size()-Hoff)
+	//			{
+	//				TerrainTile2 & curt = ttiles[xVal][yVal][zVal];
+	//				if(((map->objects[f]->defInfo->visitMap[fy] >> (7 - fx)) & 1))
+	//					curt.tileInfo->visitable = true;
+	//				if(!((map->objects[f]->defInfo->blockMap[fy] >> (7 - fx)) & 1))
+	//					curt.tileInfo->blocked = true;
+	//			}
+	//		}
+	//	}
+	//}
 }
 void processDef (CGDefInfo* def)
 {
@@ -714,7 +674,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 				SDL_Rect pp = ttiles[x+bx][y+by][level].objects[h].second;
 				pp.h = sr.h;
 				pp.w = sr.w;
-				CGHeroInstance * themp = (dynamic_cast<CGHeroInstance*>(ttiles[x+bx][y+by][level].objects[h].first));
+				const CGHeroInstance * themp = (dynamic_cast<const CGHeroInstance*>(ttiles[x+bx][y+by][level].objects[h].first));
 
 				if(themp && themp->moveDir && !themp->isStanding && themp->ID!=62) //last condition - this is not prison
 				{
@@ -767,7 +727,6 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 						bufr.w = 96;
 						if(bufr.x-extRect->x>-64)
 							SDL_BlitSurface(graphics->flags4[themp->getOwner()]->ourImages[ getHeroFrameNum(themp->moveDir, !themp->isStanding) *8+(heroAnim/4)%imgVal].bitmap, NULL, su, &bufr);
-						themp->flagPrinted = true;
 					}
 				}
 				else
@@ -821,7 +780,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 			}
 			else 
 			{
-				if(MARK_BLOCKED_POSITIONS &&  ttiles[x+bx][y+by][level].blocked) //temporary hiding blocked positions
+				if(MARK_BLOCKED_POSITIONS &&  ttiles[x+bx][y+by][level].tileInfo->blocked) //temporary hiding blocked positions
 				{
 					SDL_Rect sr;
 					sr.y=by*32;
@@ -839,7 +798,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 
 					SDL_FreeSurface(ns);
 				}
-				if(MARK_VISITABLE_POSITIONS &&  ttiles[x+bx][y+by][level].visitable) //temporary hiding visitable positions
+				if(MARK_VISITABLE_POSITIONS &&  ttiles[x+bx][y+by][level].tileInfo->visitable) //temporary hiding visitable positions
 				{
 					SDL_Rect sr;
 					sr.y=by*32;
@@ -1128,13 +1087,13 @@ int CMapHandler::getCost(int3 &a, int3 &b, const CGHeroInstance *hero)
 {
 	int ret=-1;
 	if(a.x>=CGI->mh->map->width && a.y>=CGI->mh->map->height)
-		ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->map->width-1][CGI->mh->map->width-1][a.z].malle];
+		ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->map->width-1][CGI->mh->map->width-1][a.z].tileInfo->malle];
 	else if(a.x>=CGI->mh->map->width && a.y<CGI->mh->map->height)
-		ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->map->width-1][a.y][a.z].malle];
+		ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->map->width-1][a.y][a.z].tileInfo->malle];
 	else if(a.x<CGI->mh->map->width && a.y>=CGI->mh->map->height)
-		ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][CGI->mh->map->width-1][a.z].malle];
+		ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][CGI->mh->map->width-1][a.z].tileInfo->malle];
 	else
-		ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][a.y][a.z].malle];
+		ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][a.y][a.z].tileInfo->malle];
 	if(!(a.x==b.x || a.y==b.y))
 		ret*=1.41421;
 
@@ -1142,37 +1101,17 @@ int CMapHandler::getCost(int3 &a, int3 &b, const CGHeroInstance *hero)
 	return ret;
 }
 
-std::vector < std::string > CMapHandler::getObjDescriptions(int3 pos)
-{
-	std::vector < std::pair<CGObjectInstance*,SDL_Rect > > objs = ttiles[pos.x][pos.y][pos.z].objects;
-	std::vector<std::string> ret;
-	for(int g=0; g<objs.size(); ++g)
-	{
-		if( (5-(objs[g].first->pos.y-pos.y)) >= 0 && (5-(objs[g].first->pos.y-pos.y)) < 6 && (objs[g].first->pos.x-pos.x) >= 0 && (objs[g].first->pos.x-pos.x)<7 && objs[g].first->defInfo &&
-			(((objs[g].first->defInfo->blockMap[5-(objs[g].first->pos.y-pos.y)])>>((objs[g].first->pos.x-pos.x)))&1)==0
-			) //checking position blocking
-		{
-			//unsigned char * blm = objs[g].first->defInfo->blockMap;
-			if (objs[g].first->state)
-				ret.push_back(objs[g].first->state->hoverText(objs[g].first));
-			else
-				ret.push_back(CGI->objh->objects[objs[g].first->ID].name);
-		}
-	}
-	return ret;
-}
-
-std::vector < CGObjectInstance * > CMapHandler::getVisitableObjs(int3 pos)
-{
-	std::vector < CGObjectInstance * > ret;
-	for(int h=0; h<ttiles[pos.x][pos.y][pos.z].objects.size(); ++h)
-	{
-		CGObjectInstance * curi = ttiles[pos.x][pos.y][pos.z].objects[h].first;
-		if(curi->visitableAt(- curi->pos.x + pos.x + curi->getWidth() - 1, -curi->pos.y + pos.y + curi->getHeight() - 1))
-			ret.push_back(curi);
-	}
-	return ret;
-}
+//std::vector < CGObjectInstance * > CMapHandler::getVisitableObjs(int3 pos)
+//{
+//	std::vector < CGObjectInstance * > ret;
+//	for(int h=0; h<ttiles[pos.x][pos.y][pos.z].objects.size(); ++h)
+//	{
+//		CGObjectInstance * curi = ttiles[pos.x][pos.y][pos.z].objects[h].first;
+//		if(curi->visitableAt(- curi->pos.x + pos.x + curi->getWidth() - 1, -curi->pos.y + pos.y + curi->getHeight() - 1))
+//			ret.push_back(curi);
+//	}
+//	return ret;
+//}
 
 std::string CMapHandler::getDefName(int id, int subid)
 {
@@ -1221,7 +1160,7 @@ bool CMapHandler::hideObject(CGObjectInstance *obj)
 		{
 			if((obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
 			{
-				std::vector < std::pair<CGObjectInstance*,SDL_Rect> > & ctile = ttiles[obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][obj->pos.z].objects;
+				std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > & ctile = ttiles[obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][obj->pos.z].objects;
 				for(int dd=0; dd<ctile.size(); ++dd)
 				{
 					if(ctile[dd].first->id==obj->id)
@@ -1245,60 +1184,60 @@ bool CMapHandler::removeObject(CGObjectInstance *obj)
 
 bool CMapHandler::recalculateHideVisPos(int3 &pos)
 {
-	ttiles[pos.x][pos.y][pos.z].visitable = false;
-	ttiles[pos.x][pos.y][pos.z].blocked = false;
-	for(int i=0; i<ttiles[pos.x][pos.y][pos.z].objects.size(); ++i)
-	{
-		CDefHandler * curd = ttiles[pos.x][pos.y][pos.z].objects[i].first->defInfo->handler;
-		for(int fx=0; fx<8; ++fx)
-		{
-			for(int fy=0; fy<6; ++fy)
-			{
-				int xVal = ttiles[pos.x][pos.y][pos.z].objects[i].first->pos.x + fx - 7;
-				int yVal = ttiles[pos.x][pos.y][pos.z].objects[i].first->pos.y + fy - 5;
-				int zVal = ttiles[pos.x][pos.y][pos.z].objects[i].first->pos.z;
-				if(xVal>=0 && xVal<ttiles.size()-Woff && yVal>=0 && yVal<ttiles[0].size()-Hoff)
-				{
-					TerrainTile2 & curt = ttiles[xVal][yVal][zVal];
-					if(((ttiles[pos.x][pos.y][pos.z].objects[i].first->defInfo->visitMap[fy] >> (7 - fx)) & 1))
-						curt.visitable = true;
-					if(!((ttiles[pos.x][pos.y][pos.z].objects[i].first->defInfo->blockMap[fy] >> (7 - fx)) & 1))
-						curt.blocked = true;
-				}
-			}
-		}
-	}
+	//ttiles[pos.x][pos.y][pos.z].tileInfo->visitable = false;
+	//ttiles[pos.x][pos.y][pos.z].tileInfo->blocked = false;
+	//for(int i=0; i<ttiles[pos.x][pos.y][pos.z].objects.size(); ++i)
+	//{
+	//	CDefHandler * curd = ttiles[pos.x][pos.y][pos.z].objects[i].first->defInfo->handler;
+	//	for(int fx=0; fx<8; ++fx)
+	//	{
+	//		for(int fy=0; fy<6; ++fy)
+	//		{
+	//			int xVal = ttiles[pos.x][pos.y][pos.z].objects[i].first->pos.x + fx - 7;
+	//			int yVal = ttiles[pos.x][pos.y][pos.z].objects[i].first->pos.y + fy - 5;
+	//			int zVal = ttiles[pos.x][pos.y][pos.z].objects[i].first->pos.z;
+	//			if(xVal>=0 && xVal<ttiles.size()-Woff && yVal>=0 && yVal<ttiles[0].size()-Hoff)
+	//			{
+	//				TerrainTile2 & curt = ttiles[xVal][yVal][zVal];
+	//				if(((ttiles[pos.x][pos.y][pos.z].objects[i].first->defInfo->visitMap[fy] >> (7 - fx)) & 1))
+	//					curt.tileInfo->visitable = true;
+	//				if(!((ttiles[pos.x][pos.y][pos.z].objects[i].first->defInfo->blockMap[fy] >> (7 - fx)) & 1))
+	//					curt.tileInfo->blocked = true;
+	//			}
+	//		}
+	//	}
+	//}
 	return true;
 }
 
 bool CMapHandler::recalculateHideVisPosUnderObj(CGObjectInstance *obj, bool withBorder)
 {
-	if(withBorder)
-	{
-		for(int fx=-1; fx<=obj->defInfo->handler->ourImages[0].bitmap->w/32; ++fx)
-		{
-			for(int fy=-1; fy<=obj->defInfo->handler->ourImages[0].bitmap->h/32; ++fy)
-			{
-				if((obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
-				{
-					recalculateHideVisPos(int3(obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32 +1, obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32 + 1, obj->pos.z));
-				}
-			}
-		}
-	}
-	else
-	{
-		for(int fx=0; fx<obj->defInfo->handler->ourImages[0].bitmap->w/32; ++fx)
-		{
-			for(int fy=0; fy<obj->defInfo->handler->ourImages[0].bitmap->h/32; ++fy)
-			{
-				if((obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
-				{
-					recalculateHideVisPos(int3(obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32 +1, obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32 + 1, obj->pos.z));
-				}
-			}
-		}
-	}
+	//if(withBorder)
+	//{
+	//	for(int fx=-1; fx<=obj->defInfo->handler->ourImages[0].bitmap->w/32; ++fx)
+	//	{
+	//		for(int fy=-1; fy<=obj->defInfo->handler->ourImages[0].bitmap->h/32; ++fy)
+	//		{
+	//			if((obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
+	//			{
+	//				recalculateHideVisPos(int3(obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32 +1, obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32 + 1, obj->pos.z));
+	//			}
+	//		}
+	//	}
+	//}
+	//else
+	//{
+	//	for(int fx=0; fx<obj->defInfo->handler->ourImages[0].bitmap->w/32; ++fx)
+	//	{
+	//		for(int fy=0; fy<obj->defInfo->handler->ourImages[0].bitmap->h/32; ++fy)
+	//		{
+	//			if((obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
+	//			{
+	//				recalculateHideVisPos(int3(obj->pos.x + fx - obj->defInfo->handler->ourImages[0].bitmap->w/32 +1, obj->pos.y + fy - obj->defInfo->handler->ourImages[0].bitmap->h/32 + 1, obj->pos.z));
+	//			}
+	//		}
+	//	}
+	//}
 	return true;
 }
 

+ 6 - 16
mapHandler.h

@@ -13,27 +13,17 @@ struct Mapa;
 class CGDefInfo;
 class CGObjectInstance;
 class CDefHandler;
+struct TerrainTile;
+
 struct TerrainTile2
 {
-	int3 pos; //this tile's position
-	EterrainType terType; //type of terrain tile
-
-	Eroad malle; //type of road
-	unsigned char roaddir; //type of road tile
-
-	Eriver nuine; //type of river
-	unsigned char  rivdir; //type of river tile
-
+	int3 pos;
+	const TerrainTile *tileInfo;
 	std::vector<SDL_Surface *> terbitmap; //frames of terrain animation
 	std::vector<SDL_Surface *> rivbitmap; //frames of river animation
 	std::vector<SDL_Surface *> roadbitmap; //frames of road animation
 
-	bool visitable; //false = not visitable; true = visitable
-	bool blocked; //false = free; true = blocked;
-
-	std::vector < std::pair<CGObjectInstance*,SDL_Rect> > objects; //poiters to objects being on this tile with rects to be easier to blit this tile on screen
-	std::vector <CGObjectInstance*> visitableObjects; //pointers to objects hero is visiting being on this tile
-
+	std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > objects; //poiters to objects being on this tile with rects to be easier to blit this tile on screen
 };
 
 //pathfinder
@@ -93,7 +83,7 @@ public:
 
 	int getCost(int3 & a, int3 & b, const CGHeroInstance * hero);
 	std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position
-	std::vector< CGObjectInstance * > getVisitableObjs(int3 pos); //returns vector of visitable objects at certain position
+	//std::vector< CGObjectInstance * > getVisitableObjs(int3 pos); //returns vector of visitable objects at certain position
 	CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid
 	std::string getDefName(int id, int subid); //returns name of def for object with given id and subid
 	bool printObject(CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map

+ 9 - 6
server/CGameHandler.cpp

@@ -20,7 +20,7 @@ boost::condition_variable cTurn;
 boost::mutex mTurn;
 boost::shared_mutex gsm;
 
-double neighbours(int3 a, int3 b)
+double distance(int3 a, int3 b)
 {
 	return std::sqrt( (double)(a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );
 }
@@ -51,24 +51,25 @@ void CGameHandler::handleConnection(std::set<int> players, CConnection &c)
 					int3 hmpos = end + int3(-1,0,0);
 					TerrainTile t = (hmpos.z) ? (gs->map->undergroungTerrain[hmpos.x][hmpos.y]) : (gs->map->terrain[hmpos.x][hmpos.y]);
 					CGHeroInstance *h = static_cast<CGHeroInstance *>(gs->map->objects[id]);
-					int cost = (double)h->getTileCost(t.tertype,t.malle,t.nuine) * neighbours(start,end);
+					int cost = (double)h->getTileCost(t.tertype,t.malle,t.nuine) * distance(start,end);
 
 					TryMoveHero tmh;
 					tmh.id = id;
-					tmh.start = tmh.end = start;
+					tmh.start = start;
 					tmh.end = end;
 					tmh.result = 0;
 					tmh.movePoints = h->movement;
 
 					if((h->getOwner() != gs->currentPlayer) || //not turn of that hero
-						(neighbours(start,end)>=1.5) || //tiles are not neighouring
+						(distance(start,end)>=1.5) || //tiles are not neighouring
 						(h->movement < cost) || //lack of movement points
 						(t.tertype == rock) || //rock
 						(!h->canWalkOnSea() && t.tertype == water) ||
 						(t.blocked && !t.visitable) ) //tile is blocked andnot visitable
 						goto fail;
 
-					//we start moving
+					
+					//check if there is blocking visitable object
 					bool blockvis = false;
 					tmh.movePoints = h->movement = (h->movement-cost); //take move points
 					BOOST_FOREACH(CGObjectInstance *obj, t.visitableObjects)
@@ -80,10 +81,12 @@ void CGameHandler::handleConnection(std::set<int> players, CConnection &c)
 						}
 					}
 
+
+					//we start moving
 					if(blockvis)//interaction with blocking object (like resources)
 					{
 						gs->apply(&tmh);
-						sendToAllClients(&tmh);
+						sendToAllClients(&tmh); //failed to move to that tile but we visit object
 						BOOST_FOREACH(CGObjectInstance *obj, t.visitableObjects)
 						{
 							if (obj->blockVisit)