瀏覽代碼

* minor changes to code handling cartographer (next time please make more documentation of your code, especially interfaces and especially when it's not consistent with the rest of the engine (map level description in this case) )

mateuszb 16 年之前
父節點
當前提交
9c45f050ef
共有 3 個文件被更改,包括 24 次插入23 次删除
  1. 2 6
      hch/CObjectHandler.cpp
  2. 21 16
      lib/IGameCallback.cpp
  3. 1 1
      lib/IGameCallback.h

+ 2 - 6
hch/CObjectHandler.cpp

@@ -4179,18 +4179,14 @@ void CCartographer::buyMap (const CGHeroInstance *h, ui32 accept) const
 		cb->giveResource (h->tempOwner, 6, -1000);
 		FoWChange fw;
 		fw.player = h->tempOwner;
-		int floor, surface = 0;
+		int surface = 0;
 		if (cb->getTile(pos)->tertype == 8) //water
 			surface = 2;
 		else
 			surface = 1;
-		if (pos.z == 0) //ground
-			floor = 1;
-		else
-			floor = 2;
 
 		//reveal apropriate tiles
-		cb->getAllTiles (fw.tiles, h->tempOwner, floor, surface);
+		cb->getAllTiles (fw.tiles, h->tempOwner, pos.z, surface);
 		cb->sendAndApply (&fw);
 		cb->setObjProperty (id, 10, h->tempOwner);
 	}

+ 21 - 16
lib/IGameCallback.cpp

@@ -114,31 +114,36 @@ void IGameCallback::getTilesInRange( std::set<int3> &tiles, int3 pos, int radiou
 	}
 }
 
-void IGameCallback::getAllTiles (std::set<int3> &tiles, int player/*=-1*/, int floor, int surface )
+void IGameCallback::getAllTiles (std::set<int3> &tiles, int player/*=-1*/, int level, int surface )
 {
 	if(player >= PLAYER_LIMIT)
 	{
 		tlog1 << "Illegal call to getTilesInRange!\n";
 		return;
 	}
-	bool water = false, land = false;
-	if (surface == 0 || surface == 2)
-		water = true;
-	if (surface == 0 || surface == 1)
-		land  = true;
-	std::set<int> floors;
-	if (floor==1 || floor == 0) // ground
-		floors.insert(0);
-	if (floor==2 || floor == 0) // undergroundground
-		floors.insert(1);
-	for (std::set<int>::iterator i = floors.begin(); i!= floors.end(); i++)
+	bool water = surface == 0 || surface == 2,
+		land = surface == 0 || surface == 1;
+
+	std::vector<int> floors;
+	if(level == -1)
+	{
+		for(int b=0; b<gs->map->twoLevel + 1; ++b) //if gs->map->twoLevel is false then false (0) + 1 is 1, if it's true (1) then we have 2
+		{
+			floors.push_back(b);
+		}
+	}
+	else
+		floors.push_back(level);
+
+	for (std::vector<int>::const_iterator i = floors.begin(); i!= floors.end(); i++)
 	{
-		for (int xd = 0; xd <= gs->map->width - 1; xd++)
+		for (int xd = 0; xd < gs->map->width; xd++)
 		{
-			for (int yd = 0; yd <= gs->map->height - 1; yd++)
+			for (int yd = 0; yd < gs->map->height; yd++)
 			{
-				if ((getTile (int3 (xd,yd,*i))->tertype == 8 && water == true)
-					|| (getTile (int3 (xd,yd,*i))->tertype != 8 && land == true))
+				if ( (getTile (int3 (xd,yd,*i))->tertype == 8 && water == true)
+					|| (getTile (int3 (xd,yd,*i))->tertype != 8 && land == true)
+					)
 					tiles.insert(int3(xd,yd,*i));
 			}
 		}

+ 1 - 1
lib/IGameCallback.h

@@ -54,7 +54,7 @@ public:
 	virtual const PlayerSettings * getPlayerSettings(int color);
 	virtual int getHeroCount(int player, bool includeGarrisoned);
 	virtual void getTilesInRange(std::set<int3> &tiles, int3 pos, int radious, int player=-1, int mode=0);  //mode 1 - only unrevealed tiles; mode 0 - all, mode -1 -  only unrevealed
-	virtual void getAllTiles (std::set<int3> &tiles, int player=-1, int floor=0, int surface=0);
+	virtual void getAllTiles (std::set<int3> &tiles, int player=-1, int level=-1, int surface=0); //returns all tiles on given level (-1 - both levels, otherwise number of level); surface: 0 - land and water, 1 - only land, 2 - only water
 	virtual bool isAllowed(int type, int id); //type: 0 - spell; 1- artifact
 	virtual void getAllowedArts(std::vector<CArtifact*> &out, std::vector<CArtifact*> CArtHandler::*arts);
 	virtual void getAllowed(std::vector<CArtifact*> &out, int flags); //flags: bitfield uses EartClass