Explorar o código

Partial support for random wandering stacks. Well, they are not 'that' random as don't use global ran() function.

DjWarmonger %!s(int64=15) %!d(string=hai) anos
pai
achega
f6b97704c7
Modificáronse 5 ficheiros con 53 adicións e 4 borrados
  1. 6 0
      lib/CGameState.cpp
  2. 24 0
      lib/IGameCallback.cpp
  3. 1 0
      lib/IGameCallback.h
  4. 21 4
      lib/NetPacksLib.cpp
  5. 1 0
      lib/VCMI_Lib.cpp

+ 6 - 0
lib/CGameState.cpp

@@ -1167,6 +1167,12 @@ int CGameState::getDate(int mode) const
 	case 3: //current month
 		return ((day-1)/28)+1; 
 		break;
+	case 4: //day of month
+		temp = (day)%28;
+		if (temp)
+			return temp;
+		else return 28;
+		break;
 	}
 	return 0;
 }

+ 24 - 0
lib/IGameCallback.cpp

@@ -164,6 +164,30 @@ void IGameCallback::getAllTiles (std::set<int3> &tiles, int player/*=-1*/, int l
 	}
 }
 
+void IGameCallback::getFreeTiles (std::vector<int3> &tiles)
+{
+	std::vector<int> floors;
+	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);
+	}
+	TerrainTile *tinfo;
+	for (std::vector<int>::const_iterator i = floors.begin(); i!= floors.end(); i++)
+	{
+		register int zd = *i;
+		for (int xd = 0; xd < gs->map->width; xd++)
+		{
+			for (int yd = 0; yd < gs->map->height; yd++)
+			{
+				tinfo = getTile (int3 (xd,yd,zd));
+				if (tinfo->tertype != 8 && !tinfo->blocked) //land and free
+					tiles.push_back (int3 (xd,yd,zd));
+			}
+		}
+	}
+
+}
+
 bool IGameCallback::isAllowed( int type, int id )
 {
 	switch(type)

+ 1 - 0
lib/IGameCallback.h

@@ -59,6 +59,7 @@ public:
 	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 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 void getFreeTiles (std::vector<int3> &tiles); //used for random spawns
 	virtual bool isAllowed(int type, int id); //type: 0 - spell; 1- artifact; 2 - secondary skill
 	virtual ui16 getRandomArt (int flags);
 	virtual ui16 getArtSync (ui32 rand, int flags); //synchronic

+ 21 - 4
lib/NetPacksLib.cpp

@@ -544,6 +544,17 @@ DLL_EXPORT void NewObject::applyGs( CGameState *gs )
 	case 8:
 		o = new CGBoat();
 		break;
+	case 54: //probably more options will be needed
+		o = new CGCreature();
+		{
+			CStackInstance hlp;
+			CGCreature *cre = static_cast<CGCreature*>(o);
+			cre->slots[0] = hlp;
+			cre->notGrowingTeam = cre->neverFlees = 0;
+			cre->character = 2;
+			cre->gainedArtifact = -1;
+		}
+		break;
 	default:
 		o = new CGObjectInstance();
 		break;
@@ -555,11 +566,17 @@ DLL_EXPORT void NewObject::applyGs( CGameState *gs )
 	id = o->id = gs->map->objects.size();
 	o->hoverName = VLC->generaltexth->names[ID];
 
-	if(ID == 124) // hole
+	switch(ID)
 	{
-		const TerrainTile &t = gs->map->getTile(pos);
-		o->defInfo = VLC->dobjinfo->gobjs[ID][t.tertype];
-		assert(o->defInfo);
+		case 54: //cfreature
+			o->defInfo = VLC->dobjinfo->gobjs[ID][subID];
+			assert(o->defInfo);
+			break;
+		case 124://hole
+			const TerrainTile &t = gs->map->getTile(pos);
+			o->defInfo = VLC->dobjinfo->gobjs[ID][t.tertype];
+			assert(o->defInfo);
+		break;
 	}
 
 	gs->map->objects.push_back(o);

+ 1 - 0
lib/VCMI_Lib.cpp

@@ -27,6 +27,7 @@ LibClasses * VLC = NULL;
 DLL_EXPORT CLodHandler *bitmaph = NULL, 
 	*spriteh = NULL;
 
+
 DLL_EXPORT CLogger tlog0(0);
 DLL_EXPORT CLogger tlog1(1);
 DLL_EXPORT CLogger tlog2(2);