Browse Source

Move CPrivilagedInfoCallback, IGameEventCallback and CNonConstInfoCallback to IGameCallback.h

O01eg 11 years ago
parent
commit
463073ebfa
8 changed files with 346 additions and 334 deletions
  1. 4 0
      CCallback.h
  2. 1 1
      lib/CGameState.h
  3. 4 1
      lib/CScriptingModule.h
  4. 209 9
      lib/IGameCallback.cpp
  5. 98 11
      lib/IGameCallback.h
  6. 10 211
      lib/IGameCallback2.cpp
  7. 19 101
      lib/IGameCallback2.h
  8. 1 0
      scripting/erm/ERMInterpreter.cpp

+ 4 - 0
CCallback.h

@@ -2,6 +2,7 @@
 
 
 #include "lib/IGameCallback2.h"
+#include "int3.h" // for int3
 
 /*
  * CCallback.h, part of VCMI engine
@@ -30,6 +31,9 @@ struct CPack;
 class IBattleEventsReceiver;
 class IGameEventsReceiver;
 
+//my
+struct ArtifactLocation;
+
 class IBattleCallback
 {
 public:

+ 1 - 1
lib/CGameState.h

@@ -11,7 +11,7 @@
 #include "HeroBonus.h"
 #include "CCreatureSet.h"
 #include "ConstTransitivePtr.h"
-#include "IGameCallback2.h"
+#include "IGameCallback.h"
 #include "ResourceSet.h"
 #include "int3.h"
 #include "CObjectHandler.h"

+ 4 - 1
lib/CScriptingModule.h

@@ -2,7 +2,7 @@
 
 
 #include "IGameEventsReceiver.h"
-#include "IGameCallback2.h"
+//#include "IGameCallback2.h"
 
 /*
  * CScriptingModule.h, part of VCMI engine
@@ -14,6 +14,9 @@
  *
  */
 
+class IGameEventRealizer;
+class CPrivilagedInfoCallback;
+
 class CScriptingModule : public IGameEventsReceiver, public IBattleEventsReceiver
 {
 public:

+ 209 - 9
lib/IGameCallback.cpp

@@ -13,22 +13,22 @@
 
 /*#include "CGameState.h"
 #include "mapping/CMap.h"
-#include "CObjectHandler.h"
-#include "CHeroHandler.h"
-#include "StartInfo.h"
-#include "CArtHandler.h"
-#include "CSpellHandler.h"
-#include "VCMI_Lib.h"
+#include "CObjectHandler.h"*/
+#include "CHeroHandler.h" // for CHeroHandler
+/*#include "StartInfo.h"
+#include "CArtHandler.h"*/
+#include "CSpellHandler.h" // for CSpell
+/*#include "VCMI_Lib.h"
 #include "CTownHandler.h"
 #include "BattleState.h"*/
 #include "NetPacks.h"
 /*#include "CBuildingHandler.h"
 #include "GameConstants.h"
 #include "CModHandler.h"
-#include "CDefObjInfoHandler.h"
-#include "CBonusTypeHandler.h"
+#include "CDefObjInfoHandler.h"*/
+#include "CBonusTypeHandler.h" // for CBonusTypeHandler
 
-#include "Connection.h"*/
+#include "Connection.h" // for SAVEGAME_MAGIC
 
 //TODO make clean
 /*#define ERROR_SILENT_RET_VAL_IF(cond, txt, retVal) do {if(cond){return retVal;}} while(0)
@@ -36,6 +36,206 @@
 #define ERROR_RET_IF(cond, txt) do {if(cond){logGlobal->errorStream() << BOOST_CURRENT_FUNCTION << ": " << txt; return;}} while(0)
 #define ERROR_RET_VAL_IF(cond, txt, retVal) do {if(cond){logGlobal->errorStream() << BOOST_CURRENT_FUNCTION << ": " << txt; return retVal;}} while(0)*/
 
+void CPrivilagedInfoCallback::getFreeTiles (std::vector<int3> &tiles) const
+{
+	std::vector<int> floors;
+	for (int b = 0; b < (gs->map->twoLevel ? 2 : 1); ++b)
+	{
+		floors.push_back(b);
+	}
+	const TerrainTile *tinfo;
+	for (auto zd : floors)
+	{
+
+		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 != ETerrainType::WATER && !tinfo->blocked) //land and free
+					tiles.push_back (int3 (xd,yd,zd));
+			}
+		}
+	}
+}
+
+void CPrivilagedInfoCallback::getTilesInRange( std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, boost::optional<PlayerColor> player/*=uninit*/, int mode/*=0*/ ) const
+{
+	if(!!player && *player >= PlayerColor::PLAYER_LIMIT)
+	{
+        logGlobal->errorStream() << "Illegal call to getTilesInRange!";
+		return;
+	}
+	if (radious == -1) //reveal entire map
+		getAllTiles (tiles, player, -1, 0);
+	else
+	{
+		const TeamState * team = !player ? nullptr : gs->getPlayerTeam(*player);
+		for (int xd = std::max<int>(pos.x - radious , 0); xd <= std::min<int>(pos.x + radious, gs->map->width - 1); xd++)
+		{
+			for (int yd = std::max<int>(pos.y - radious, 0); yd <= std::min<int>(pos.y + radious, gs->map->height - 1); yd++)
+			{
+				double distance = pos.dist2d(int3(xd,yd,pos.z)) - 0.5;
+				if(distance <= radious)
+				{
+					if(!player
+						|| (mode == 1  && team->fogOfWarMap[xd][yd][pos.z]==0)
+						|| (mode == -1 && team->fogOfWarMap[xd][yd][pos.z]==1)
+					)
+						tiles.insert(int3(xd,yd,pos.z));
+				}
+			}
+		}
+	}
+}
+
+void CPrivilagedInfoCallback::getAllTiles (std::unordered_set<int3, ShashInt3> &tiles, boost::optional<PlayerColor> Player/*=uninit*/, int level, int surface ) const
+{
+	if(!!Player && *Player >= PlayerColor::PLAYER_LIMIT)
+	{
+        logGlobal->errorStream() << "Illegal call to getAllTiles !";
+		return;
+	}
+	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 ? 2 : 1); ++b)
+		{
+			floors.push_back(b);
+		}
+	}
+	else
+		floors.push_back(level);
+
+	for (auto zd : floors)
+	{
+
+		for (int xd = 0; xd < gs->map->width; xd++)
+		{
+			for (int yd = 0; yd < gs->map->height; yd++)
+			{
+				if ((getTile (int3 (xd,yd,zd))->terType == ETerrainType::WATER && water)
+					|| (getTile (int3 (xd,yd,zd))->terType != ETerrainType::WATER && land))
+					tiles.insert(int3(xd,yd,zd));
+			}
+		}
+	}
+}
+
+void CPrivilagedInfoCallback::pickAllowedArtsSet(std::vector<const CArtifact*> &out)
+{
+	for (int j = 0; j < 3 ; j++)
+		out.push_back(VLC->arth->artifacts[VLC->arth->pickRandomArtifact(gameState()->getRandomGenerator(), CArtifact::ART_TREASURE)]);
+	for (int j = 0; j < 3 ; j++)
+		out.push_back(VLC->arth->artifacts[VLC->arth->pickRandomArtifact(gameState()->getRandomGenerator(), CArtifact::ART_MINOR)]);
+
+	out.push_back(VLC->arth->artifacts[VLC->arth->pickRandomArtifact(gameState()->getRandomGenerator(), CArtifact::ART_MAJOR)]);
+}
+
+void CPrivilagedInfoCallback::getAllowedSpells(std::vector<SpellID> &out, ui16 level)
+{
+	for (ui32 i = 0; i < gs->map->allowedSpell.size(); i++) //spellh size appears to be greater (?)
+	{
+
+		const CSpell *spell = SpellID(i).toSpell();
+		if (isAllowed (0, spell->id) && spell->level == level)
+		{
+			out.push_back(spell->id);
+		}
+	}
+}
+
+CGameState * CPrivilagedInfoCallback::gameState ()
+{
+	return gs;
+}
+
+template<typename Loader>
+void CPrivilagedInfoCallback::loadCommonState(Loader &in)
+{
+    logGlobal->infoStream() << "Loading lib part of game...";
+	in.checkMagicBytes(SAVEGAME_MAGIC);
+
+	CMapHeader dum;
+	StartInfo *si;
+
+    logGlobal->infoStream() <<"\tReading header";
+	in >> dum;
+
+    logGlobal->infoStream() << "\tReading options";
+	in >> si;
+
+    logGlobal->infoStream() <<"\tReading handlers";
+	in >> *VLC;
+
+    logGlobal->infoStream() <<"\tReading gamestate";
+	in >> gs;
+}
+
+template<typename Saver>
+void CPrivilagedInfoCallback::saveCommonState(Saver &out) const
+{
+    logGlobal->infoStream() << "Saving lib part of game...";
+	out.putMagicBytes(SAVEGAME_MAGIC);
+    logGlobal->infoStream() <<"\tSaving header";
+	out << static_cast<CMapHeader&>(*gs->map);
+    logGlobal->infoStream() << "\tSaving options";
+	out << gs->scenarioOps;
+    logGlobal->infoStream() << "\tSaving handlers";
+	out << *VLC;
+    logGlobal->infoStream() << "\tSaving gamestate";
+	out << gs;
+}
+
+template DLL_LINKAGE void CPrivilagedInfoCallback::loadCommonState<CLoadIntegrityValidator>(CLoadIntegrityValidator&);
+template DLL_LINKAGE void CPrivilagedInfoCallback::loadCommonState<CLoadFile>(CLoadFile&);
+template DLL_LINKAGE void CPrivilagedInfoCallback::saveCommonState<CSaveFile>(CSaveFile&) const;
+
+TerrainTile * CNonConstInfoCallback::getTile( int3 pos )
+{
+	if(!gs->map->isInTheMap(pos))
+		return nullptr;
+	return &gs->map->getTile(pos);
+}
+
+CGHeroInstance *CNonConstInfoCallback::getHero(ObjectInstanceID objid)
+{
+	return const_cast<CGHeroInstance*>(CGameInfoCallback::getHero(objid));
+}
+
+CGTownInstance *CNonConstInfoCallback::getTown(ObjectInstanceID objid)
+{
+	return const_cast<CGTownInstance*>(CGameInfoCallback::getTown(objid));
+}
+
+TeamState *CNonConstInfoCallback::getTeam(TeamID teamID)
+{
+	return const_cast<TeamState*>(CGameInfoCallback::getTeam(teamID));
+}
+
+TeamState *CNonConstInfoCallback::getPlayerTeam(PlayerColor color)
+{
+	return const_cast<TeamState*>(CGameInfoCallback::getPlayerTeam(color));
+}
+
+PlayerState * CNonConstInfoCallback::getPlayer( PlayerColor color, bool verbose )
+{
+	return const_cast<PlayerState*>(CGameInfoCallback::getPlayer(color, verbose));
+}
+
+CArtifactInstance * CNonConstInfoCallback::getArtInstance( ArtifactInstanceID aid )
+{
+	return gs->map->artInstances[aid.num];
+}
+
+CGObjectInstance * CNonConstInfoCallback::getObjInstance( ObjectInstanceID oid )
+{
+	return gs->map->objects[oid.num];
+}
+
 const CGObjectInstance * IGameCallback::putNewObject(Obj ID, int subID, int3 pos)
 {
 	NewObject no;

+ 98 - 11
lib/IGameCallback.h

@@ -1,6 +1,6 @@
 #pragma once
 
-#include "IGameCallback2.h" // for CPrivilagedInfoCallback, IGameEventCallback
+#include "IGameCallback2.h" // for CGameInfoCallback
 
 /*#include "BattleHex.h"
 #include "ResourceSet.h"
@@ -18,16 +18,16 @@
  *
  */
 
-/*struct SetMovePoints;
+struct SetMovePoints;
 struct GiveBonus;
-class CGObjectInstance;
+/*class CGObjectInstance;
 class CGTownInstance;
-class CGHeroInstance;
+class CGHeroInstance;*/
 struct BlockingDialog;
-struct InfoWindow;
+/*struct InfoWindow;*/
 struct MetaString;
 struct ShowInInfobox;
-struct BattleResult;
+/*struct BattleResult;
 struct Component;
 class CGameState;
 struct PlayerSettings;
@@ -37,10 +37,10 @@ class CArtifact;
 class CArmedInstance;
 struct TerrainTile;
 struct PlayerState;
-class CTown;
+class CTown;*/
 struct StackLocation;
 struct ArtifactLocation;
-class CArtifactInstance;
+/*class CArtifactInstance;
 struct StartInfo;
 struct InfoAboutTown;
 struct UpgradeInfo;
@@ -51,16 +51,103 @@ struct InfoAboutHero;
 class CMapHeader;
 struct BattleAction;
 class CStack;
-class CSpell;
+class CSpell;*/
 class CCreatureSet;
-class CCreature;
+/*class CCreature;*/
 class CStackBasicDescriptor;
-struct TeamState;
+/*struct TeamState;
 struct QuestInfo;*/
 class CGCreature;
 /*class CSaveFile;
 class CLoadFile;*/
 
+//my
+struct ShashInt3;
+
+class DLL_LINKAGE CPrivilagedInfoCallback : public CGameInfoCallback
+{
+public:
+	CGameState * gameState();
+	void getFreeTiles (std::vector<int3> &tiles) const; //used for random spawns
+	void getTilesInRange(std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, boost::optional<PlayerColor> player = boost::optional<PlayerColor>(), int mode=0) const;  //mode 1 - only unrevealed tiles; mode 0 - all, mode -1 -  only unrevealed
+	void getAllTiles (std::unordered_set<int3, ShashInt3> &tiles, boost::optional<PlayerColor> player = boost::optional<PlayerColor>(), int level=-1, int surface=0) const; //returns all tiles on given level (-1 - both levels, otherwise number of level); surface: 0 - land and water, 1 - only land, 2 - only water
+	void pickAllowedArtsSet(std::vector<const CArtifact*> &out); //gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant
+	void getAllowedSpells(std::vector<SpellID> &out, ui16 level);
+
+	template<typename Saver>
+	void saveCommonState(Saver &out) const; //stores GS and VLC
+
+	template<typename Loader>
+	void loadCommonState(Loader &in); //loads GS and VLC
+};
+
+class DLL_LINKAGE IGameEventCallback : public IGameEventRealizer
+{
+public:
+	virtual void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> &spells)=0;
+	virtual bool removeObject(const CGObjectInstance * obj)=0;
+	virtual void setBlockVis(ObjectInstanceID objid, bool bv)=0;
+	virtual void setOwner(const CGObjectInstance * objid, PlayerColor owner)=0;
+	virtual void setHoverName(const CGObjectInstance * obj, MetaString * name)=0;
+	virtual void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false)=0;
+	virtual void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false)=0; 
+	virtual void showBlockingDialog(BlockingDialog *iw) =0;
+	virtual void showGarrisonDialog(ObjectInstanceID upobj, ObjectInstanceID hid, bool removableUnits) =0; //cb will be called when player closes garrison window
+	virtual void showThievesGuildWindow(PlayerColor player, ObjectInstanceID requestingObjId) =0;
+	virtual void giveResource(PlayerColor player, Res::ERes which, int val)=0;
+	virtual void giveResources(PlayerColor player, TResources resources)=0;
+
+	virtual void giveCreatures(const CArmedInstance *objid, const CGHeroInstance * h, const CCreatureSet &creatures, bool remove) =0;
+	virtual void takeCreatures(ObjectInstanceID objid, const std::vector<CStackBasicDescriptor> &creatures) =0;
+	virtual bool changeStackCount(const StackLocation &sl, TQuantity count, bool absoluteValue = false) =0;
+	virtual bool changeStackType(const StackLocation &sl, CCreature *c) =0;
+	virtual bool insertNewStack(const StackLocation &sl, const CCreature *c, TQuantity count = -1) =0; //count -1 => moves whole stack
+	virtual bool eraseStack(const StackLocation &sl, bool forceRemoval = false) =0;
+	virtual bool swapStacks(const StackLocation &sl1, const StackLocation &sl2) =0;
+	virtual bool addToSlot(const StackLocation &sl, const CCreature *c, TQuantity count) =0; //makes new stack or increases count of already existing
+	virtual void tryJoiningArmy(const CArmedInstance *src, const CArmedInstance *dst, bool removeObjWhenFinished, bool allowMerging) =0; //merges army from src do dst or opens a garrison window
+	virtual bool moveStack(const StackLocation &src, const StackLocation &dst, TQuantity count) = 0;
+
+	virtual void removeAfterVisit(const CGObjectInstance *object) = 0; //object will be destroyed when interaction is over. Do not call when interaction is not ongoing!
+
+	virtual void giveHeroNewArtifact(const CGHeroInstance *h, const CArtifact *artType, ArtifactPosition pos) = 0;
+	virtual void giveHeroArtifact(const CGHeroInstance *h, const CArtifactInstance *a, ArtifactPosition pos) = 0; //pos==-1 - first free slot in backpack=0; pos==-2 - default if available or backpack
+	virtual void putArtifact(const ArtifactLocation &al, const CArtifactInstance *a) = 0;
+	virtual void removeArtifact(const ArtifactLocation &al) = 0;
+	virtual bool moveArtifact(const ArtifactLocation &al1, const ArtifactLocation &al2) = 0;
+	virtual void synchronizeArtifactHandlerLists() = 0;
+
+	virtual void showCompInfo(ShowInInfobox * comp)=0;
+	virtual void heroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero)=0;
+	virtual void stopHeroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero)=0;
+	virtual void startBattlePrimary(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank = false, const CGTownInstance *town = nullptr)=0; //use hero=nullptr for no hero
+	virtual void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, bool creatureBank = false)=0; //if any of armies is hero, hero will be used
+	virtual void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, bool creatureBank = false)=0; //if any of armies is hero, hero will be used, visitable tile of second obj is place of battle
+	virtual void setAmount(ObjectInstanceID objid, ui32 val)=0;
+	virtual bool moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, PlayerColor asker = PlayerColor::NEUTRAL)=0;
+	virtual void giveHeroBonus(GiveBonus * bonus)=0;
+	virtual void setMovePoints(SetMovePoints * smp)=0;
+	virtual void setManaPoints(ObjectInstanceID hid, int val)=0;
+	virtual void giveHero(ObjectInstanceID id, PlayerColor player)=0;
+	virtual void changeObjPos(ObjectInstanceID objid, int3 newPos, ui8 flags)=0;
+	virtual void sendAndApply(CPackForClient * info)=0;
+	virtual void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2)=0; //when two heroes meet on adventure map
+	virtual void addQuest(int player, QuestInfo & quest){};
+};
+
+class DLL_LINKAGE CNonConstInfoCallback : public CPrivilagedInfoCallback
+{
+public:
+	PlayerState *getPlayer(PlayerColor color, bool verbose = true);
+	TeamState *getTeam(TeamID teamID);//get team by team ID
+	TeamState *getPlayerTeam(PlayerColor color);// get team by player color
+	CGHeroInstance *getHero(ObjectInstanceID objid);
+	CGTownInstance *getTown(ObjectInstanceID objid);
+	TerrainTile * getTile(int3 pos);
+	CArtifactInstance * getArtInstance(ArtifactInstanceID aid);
+	CGObjectInstance * getObjInstance(ObjectInstanceID oid);
+};
+
 /// Interface class for handling general game logic and actions
 class DLL_LINKAGE IGameCallback : public CPrivilagedInfoCallback, public IGameEventCallback
 {

+ 10 - 211
lib/IGameCallback2.cpp

@@ -11,24 +11,24 @@
 #include "StdInc.h"
 #include "IGameCallback2.h"
 
-#include "CGameState.h"
+#include "CGameState.h" // PlayerState
 /*#include "mapping/CMap.h"*/
-#include "CObjectHandler.h"
-#include "CHeroHandler.h"
-#include "StartInfo.h"
-/*#include "CArtHandler.h"*/
+#include "CObjectHandler.h" // for CGObjectInstance
+/*#include "CHeroHandler.h"*/
+#include "StartInfo.h" // for StartInfo
+/*#include "CArtHandler.h"
 #include "CSpellHandler.h"
-/*#include "VCMI_Lib.h"
+#include "VCMI_Lib.h"
 #include "CTownHandler.h"*/
-#include "BattleState.h"
-#include "NetPacks.h"
+#include "BattleState.h" // for BattleInfo
+#include "NetPacks.h" // for InfoWindow
 /*#include "CBuildingHandler.h"
 #include "GameConstants.h"
 #include "CModHandler.h"
-#include "CDefObjInfoHandler.h"*/
+#include "CDefObjInfoHandler.h"
 #include "CBonusTypeHandler.h"
 
-#include "Connection.h"
+#include "Connection.h"*/
 
 //TODO make clean
 /*#define ERROR_SILENT_RET_VAL_IF(cond, txt, retVal) do {if(cond){return retVal;}} while(0)*/
@@ -36,11 +36,6 @@
 #define ERROR_RET_IF(cond, txt) do {if(cond){logGlobal->errorStream() << BOOST_CURRENT_FUNCTION << ": " << txt; return;}} while(0)
 #define ERROR_RET_VAL_IF(cond, txt, retVal) do {if(cond){logGlobal->errorStream() << BOOST_CURRENT_FUNCTION << ": " << txt; return retVal;}} while(0)
 
-CGameState * CPrivilagedInfoCallback::gameState ()
-{
-	return gs;
-}
-
 PlayerColor CGameInfoCallback::getOwner(ObjectInstanceID heroID) const
 {
 	const CGObjectInstance *obj = getObj(heroID);
@@ -73,95 +68,6 @@ const PlayerSettings * CGameInfoCallback::getPlayerSettings(PlayerColor color) c
 	return &gs->scenarioOps->getIthPlayersSettings(color);
 }
 
-void CPrivilagedInfoCallback::getTilesInRange( std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, boost::optional<PlayerColor> player/*=uninit*/, int mode/*=0*/ ) const
-{
-	if(!!player && *player >= PlayerColor::PLAYER_LIMIT)
-	{
-        logGlobal->errorStream() << "Illegal call to getTilesInRange!";
-		return;
-	}
-	if (radious == -1) //reveal entire map
-		getAllTiles (tiles, player, -1, 0);
-	else
-	{
-		const TeamState * team = !player ? nullptr : gs->getPlayerTeam(*player);
-		for (int xd = std::max<int>(pos.x - radious , 0); xd <= std::min<int>(pos.x + radious, gs->map->width - 1); xd++)
-		{
-			for (int yd = std::max<int>(pos.y - radious, 0); yd <= std::min<int>(pos.y + radious, gs->map->height - 1); yd++)
-			{
-				double distance = pos.dist2d(int3(xd,yd,pos.z)) - 0.5;
-				if(distance <= radious)
-				{
-					if(!player
-						|| (mode == 1  && team->fogOfWarMap[xd][yd][pos.z]==0)
-						|| (mode == -1 && team->fogOfWarMap[xd][yd][pos.z]==1)
-					)
-						tiles.insert(int3(xd,yd,pos.z));
-				}
-			}
-		}
-	}
-}
-
-void CPrivilagedInfoCallback::getAllTiles (std::unordered_set<int3, ShashInt3> &tiles, boost::optional<PlayerColor> Player/*=uninit*/, int level, int surface ) const
-{
-	if(!!Player && *Player >= PlayerColor::PLAYER_LIMIT)
-	{
-        logGlobal->errorStream() << "Illegal call to getAllTiles !";
-		return;
-	}
-	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 ? 2 : 1); ++b)
-		{
-			floors.push_back(b);
-		}
-	}
-	else
-		floors.push_back(level);
-
-	for (auto zd : floors)
-	{
-		
-		for (int xd = 0; xd < gs->map->width; xd++)
-		{
-			for (int yd = 0; yd < gs->map->height; yd++)
-			{
-				if ((getTile (int3 (xd,yd,zd))->terType == ETerrainType::WATER && water)
-					|| (getTile (int3 (xd,yd,zd))->terType != ETerrainType::WATER && land))
-					tiles.insert(int3(xd,yd,zd));
-			}
-		}
-	}
-}
-
-void CPrivilagedInfoCallback::getFreeTiles (std::vector<int3> &tiles) const
-{
-	std::vector<int> floors;
-	for (int b = 0; b < (gs->map->twoLevel ? 2 : 1); ++b)
-	{
-		floors.push_back(b);
-	}
-	const TerrainTile *tinfo;
-	for (auto zd : floors)
-	{
-		
-		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 != ETerrainType::WATER && !tinfo->blocked) //land and free
-					tiles.push_back (int3 (xd,yd,zd));
-			}
-		}
-	}
-}
-
 bool CGameInfoCallback::isAllowed( int type, int id )
 {
 	switch(type)
@@ -177,78 +83,6 @@ bool CGameInfoCallback::isAllowed( int type, int id )
 	}
 }
 
-void CPrivilagedInfoCallback::pickAllowedArtsSet(std::vector<const CArtifact*> &out)
-{
-	for (int j = 0; j < 3 ; j++)
-		out.push_back(VLC->arth->artifacts[VLC->arth->pickRandomArtifact(gameState()->getRandomGenerator(), CArtifact::ART_TREASURE)]);
-	for (int j = 0; j < 3 ; j++)
-		out.push_back(VLC->arth->artifacts[VLC->arth->pickRandomArtifact(gameState()->getRandomGenerator(), CArtifact::ART_MINOR)]);
-
-	out.push_back(VLC->arth->artifacts[VLC->arth->pickRandomArtifact(gameState()->getRandomGenerator(), CArtifact::ART_MAJOR)]);
-}
-
-void CPrivilagedInfoCallback::getAllowedSpells(std::vector<SpellID> &out, ui16 level)
-{
-	for (ui32 i = 0; i < gs->map->allowedSpell.size(); i++) //spellh size appears to be greater (?)
-	{
-
-		const CSpell *spell = SpellID(i).toSpell();
-		if (isAllowed (0, spell->id) && spell->level == level)
-		{
-			out.push_back(spell->id);
-		}
-	}
-}
-
-
-template<typename Loader>
-void CPrivilagedInfoCallback::loadCommonState(Loader &in)
-{
-    logGlobal->infoStream() << "Loading lib part of game...";
-	in.checkMagicBytes(SAVEGAME_MAGIC);
-
-	CMapHeader dum;
-	StartInfo *si;
-
-    logGlobal->infoStream() <<"\tReading header";
-	in >> dum;
-
-    logGlobal->infoStream() << "\tReading options";
-	in >> si;
-
-    logGlobal->infoStream() <<"\tReading handlers";
-	in >> *VLC;
-
-    logGlobal->infoStream() <<"\tReading gamestate";
-	in >> gs;
-}
-
-template<typename Saver>
-void CPrivilagedInfoCallback::saveCommonState(Saver &out) const
-{
-    logGlobal->infoStream() << "Saving lib part of game...";
-	out.putMagicBytes(SAVEGAME_MAGIC);
-    logGlobal->infoStream() <<"\tSaving header";
-	out << static_cast<CMapHeader&>(*gs->map);
-    logGlobal->infoStream() << "\tSaving options";
-	out << gs->scenarioOps;
-    logGlobal->infoStream() << "\tSaving handlers";
-	out << *VLC;
-    logGlobal->infoStream() << "\tSaving gamestate";
-	out << gs;
-}
-
-template DLL_LINKAGE void CPrivilagedInfoCallback::loadCommonState<CLoadIntegrityValidator>(CLoadIntegrityValidator&);
-template DLL_LINKAGE void CPrivilagedInfoCallback::loadCommonState<CLoadFile>(CLoadFile&);
-template DLL_LINKAGE void CPrivilagedInfoCallback::saveCommonState<CSaveFile>(CSaveFile&) const;
-
-TerrainTile * CNonConstInfoCallback::getTile( int3 pos )
-{
-	if(!gs->map->isInTheMap(pos))
-		return nullptr;
-	return &gs->map->getTile(pos);
-}
-
 const PlayerState * CGameInfoCallback::getPlayer(PlayerColor color, bool verbose) const
 {
 	ERROR_VERBOSE_OR_NOT_RET_VAL_IF(!hasAccess(color), verbose, "Cannot access player " << color << "info!", nullptr);
@@ -847,41 +681,6 @@ TResources CPlayerSpecificInfoCallback::getResourceAmount() const
 	return gs->players[*player].resources;
 }
 
-CGHeroInstance *CNonConstInfoCallback::getHero(ObjectInstanceID objid)
-{
-	return const_cast<CGHeroInstance*>(CGameInfoCallback::getHero(objid));
-}
-
-CGTownInstance *CNonConstInfoCallback::getTown(ObjectInstanceID objid)
-{
-	return const_cast<CGTownInstance*>(CGameInfoCallback::getTown(objid));
-}
-
-TeamState *CNonConstInfoCallback::getTeam(TeamID teamID)
-{
-	return const_cast<TeamState*>(CGameInfoCallback::getTeam(teamID));
-}
-
-TeamState *CNonConstInfoCallback::getPlayerTeam(PlayerColor color)
-{
-	return const_cast<TeamState*>(CGameInfoCallback::getPlayerTeam(color));
-}
-
-PlayerState * CNonConstInfoCallback::getPlayer( PlayerColor color, bool verbose )
-{
-	return const_cast<PlayerState*>(CGameInfoCallback::getPlayer(color, verbose));
-}
-
-CArtifactInstance * CNonConstInfoCallback::getArtInstance( ArtifactInstanceID aid )
-{
-	return gs->map->artInstances[aid.num];
-}
-
-CGObjectInstance * CNonConstInfoCallback::getObjInstance( ObjectInstanceID oid )
-{
-	return gs->map->objects[oid.num];
-}
-
 const TeamState * CGameInfoCallback::getTeam( TeamID teamID ) const
 {
 	ERROR_RET_VAL_IF(!vstd::contains(gs->teams, teamID), "Cannot find info for team " << teamID, nullptr);

+ 19 - 101
lib/IGameCallback2.h

@@ -1,10 +1,9 @@
 #pragma once
 
-
 /*#include "BattleHex.h"*/
-#include "ResourceSet.h"
-#include "int3.h"
-/*#include "GameConstants.h"*/
+#include "ResourceSet.h" // for Res::ERes
+/*#include "int3.h" // for int3
+#include "GameConstants.h"*/
 #include "CBattleCallback.h" //for CCallbackBase
 
 /*
@@ -17,16 +16,16 @@
  *
  */
 
-struct SetMovePoints;
-struct GiveBonus;
+/*struct SetMovePoints;
+struct GiveBonus;*/
 class CGObjectInstance;
 /*class CGTownInstance;
-class CGHeroInstance;*/
-struct BlockingDialog;
+class CGHeroInstance;
+struct BlockingDialog;*/
 struct InfoWindow;
-struct MetaString;
+/*struct MetaString;
 struct ShowInInfobox;
-/*struct BattleResult;
+struct BattleResult;
 struct Component;
 class CGameState;*/
 struct PlayerSettings;
@@ -37,9 +36,9 @@ class CArmedInstance;*/
 struct TerrainTile;
 struct PlayerState;
 class CTown;
-struct StackLocation;
+/*struct StackLocation;
 struct ArtifactLocation;
-/*class CArtifactInstance;*/
+class CArtifactInstance;*/
 struct StartInfo;
 struct InfoAboutTown;
 struct UpgradeInfo;
@@ -50,16 +49,19 @@ class CGDwelling;
 class CMapHeader;
 /*struct BattleAction;
 class CStack;
-class CSpell;*/
+class CSpell;
 class CCreatureSet;
-/*class CCreature;*/
-class CStackBasicDescriptor;
+class CCreature;
+class CStackBasicDescriptor;*/
 struct TeamState;
 struct QuestInfo;
 /*class CGCreature;
 class CSaveFile;
-class CLoadFile;
-*/
+class CLoadFile;*/
+
+// my
+class int3;
+
 class DLL_LINKAGE CGameInfoCallback : public virtual CCallbackBase
 {
 protected:
@@ -164,36 +166,6 @@ public:
 	const PlayerSettings * getPlayerSettings(PlayerColor color) const;
 };
 
-class DLL_LINKAGE CPrivilagedInfoCallback : public CGameInfoCallback
-{
-public:
-	CGameState * gameState();
-	void getFreeTiles (std::vector<int3> &tiles) const; //used for random spawns
-	void getTilesInRange(std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, boost::optional<PlayerColor> player = boost::optional<PlayerColor>(), int mode=0) const;  //mode 1 - only unrevealed tiles; mode 0 - all, mode -1 -  only unrevealed
-	void getAllTiles (std::unordered_set<int3, ShashInt3> &tiles, boost::optional<PlayerColor> player = boost::optional<PlayerColor>(), int level=-1, int surface=0) const; //returns all tiles on given level (-1 - both levels, otherwise number of level); surface: 0 - land and water, 1 - only land, 2 - only water
-	void pickAllowedArtsSet(std::vector<const CArtifact*> &out); //gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant
-	void getAllowedSpells(std::vector<SpellID> &out, ui16 level);
-
-	template<typename Saver>
-	void saveCommonState(Saver &out) const; //stores GS and VLC
-
-	template<typename Loader>
-	void loadCommonState(Loader &in); //loads GS and VLC
-};
-
-class DLL_LINKAGE CNonConstInfoCallback : public CPrivilagedInfoCallback
-{
-public:
-	PlayerState *getPlayer(PlayerColor color, bool verbose = true);
-	TeamState *getTeam(TeamID teamID);//get team by team ID
-	TeamState *getPlayerTeam(PlayerColor color);// get team by player color
-	CGHeroInstance *getHero(ObjectInstanceID objid);
-	CGTownInstance *getTown(ObjectInstanceID objid);
-	TerrainTile * getTile(int3 pos);
-	CArtifactInstance * getArtInstance(ArtifactInstanceID aid);
-	CGObjectInstance * getObjInstance(ObjectInstanceID oid);
-};
-
 class DLL_LINKAGE IGameEventRealizer
 {
 public:
@@ -206,57 +178,3 @@ public:
 	virtual void showInfoDialog(const std::string &msg, PlayerColor player);
 };
 
-class DLL_LINKAGE IGameEventCallback : public IGameEventRealizer
-{
-public:
-	virtual void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> &spells)=0;
-	virtual bool removeObject(const CGObjectInstance * obj)=0;
-	virtual void setBlockVis(ObjectInstanceID objid, bool bv)=0;
-	virtual void setOwner(const CGObjectInstance * objid, PlayerColor owner)=0;
-	virtual void setHoverName(const CGObjectInstance * obj, MetaString * name)=0;
-	virtual void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false)=0;
-	virtual void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false)=0; 
-	virtual void showBlockingDialog(BlockingDialog *iw) =0;
-	virtual void showGarrisonDialog(ObjectInstanceID upobj, ObjectInstanceID hid, bool removableUnits) =0; //cb will be called when player closes garrison window
-	virtual void showThievesGuildWindow(PlayerColor player, ObjectInstanceID requestingObjId) =0;
-	virtual void giveResource(PlayerColor player, Res::ERes which, int val)=0;
-	virtual void giveResources(PlayerColor player, TResources resources)=0;
-
-	virtual void giveCreatures(const CArmedInstance *objid, const CGHeroInstance * h, const CCreatureSet &creatures, bool remove) =0;
-	virtual void takeCreatures(ObjectInstanceID objid, const std::vector<CStackBasicDescriptor> &creatures) =0;
-	virtual bool changeStackCount(const StackLocation &sl, TQuantity count, bool absoluteValue = false) =0;
-	virtual bool changeStackType(const StackLocation &sl, CCreature *c) =0;
-	virtual bool insertNewStack(const StackLocation &sl, const CCreature *c, TQuantity count = -1) =0; //count -1 => moves whole stack
-	virtual bool eraseStack(const StackLocation &sl, bool forceRemoval = false) =0;
-	virtual bool swapStacks(const StackLocation &sl1, const StackLocation &sl2) =0;
-	virtual bool addToSlot(const StackLocation &sl, const CCreature *c, TQuantity count) =0; //makes new stack or increases count of already existing
-	virtual void tryJoiningArmy(const CArmedInstance *src, const CArmedInstance *dst, bool removeObjWhenFinished, bool allowMerging) =0; //merges army from src do dst or opens a garrison window
-	virtual bool moveStack(const StackLocation &src, const StackLocation &dst, TQuantity count) = 0;
-
-	virtual void removeAfterVisit(const CGObjectInstance *object) = 0; //object will be destroyed when interaction is over. Do not call when interaction is not ongoing!
-
-	virtual void giveHeroNewArtifact(const CGHeroInstance *h, const CArtifact *artType, ArtifactPosition pos) = 0;
-	virtual void giveHeroArtifact(const CGHeroInstance *h, const CArtifactInstance *a, ArtifactPosition pos) = 0; //pos==-1 - first free slot in backpack=0; pos==-2 - default if available or backpack
-	virtual void putArtifact(const ArtifactLocation &al, const CArtifactInstance *a) = 0;
-	virtual void removeArtifact(const ArtifactLocation &al) = 0;
-	virtual bool moveArtifact(const ArtifactLocation &al1, const ArtifactLocation &al2) = 0;
-	virtual void synchronizeArtifactHandlerLists() = 0;
-
-	virtual void showCompInfo(ShowInInfobox * comp)=0;
-	virtual void heroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero)=0;
-	virtual void stopHeroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero)=0;
-	virtual void startBattlePrimary(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank = false, const CGTownInstance *town = nullptr)=0; //use hero=nullptr for no hero
-	virtual void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, bool creatureBank = false)=0; //if any of armies is hero, hero will be used
-	virtual void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, bool creatureBank = false)=0; //if any of armies is hero, hero will be used, visitable tile of second obj is place of battle
-	virtual void setAmount(ObjectInstanceID objid, ui32 val)=0;
-	virtual bool moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, PlayerColor asker = PlayerColor::NEUTRAL)=0;
-	virtual void giveHeroBonus(GiveBonus * bonus)=0;
-	virtual void setMovePoints(SetMovePoints * smp)=0;
-	virtual void setManaPoints(ObjectInstanceID hid, int val)=0;
-	virtual void giveHero(ObjectInstanceID id, PlayerColor player)=0;
-	virtual void changeObjPos(ObjectInstanceID objid, int3 newPos, ui8 flags)=0;
-	virtual void sendAndApply(CPackForClient * info)=0;
-	virtual void heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2)=0; //when two heroes meet on adventure map
-	virtual void addQuest(int player, QuestInfo & quest){};
-};
-

+ 1 - 0
scripting/erm/ERMInterpreter.cpp

@@ -6,6 +6,7 @@
 #include "../../lib/CHeroHandler.h"
 #include "../../lib/CCreatureHandler.h"
 #include "../../lib/VCMIDirs.h"
+#include "../../lib/IGameCallback.h"
 
 /*
  * ERMInterpreter.cpp, part of VCMI engine