1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-05-29 22:57:49 +02:00

Merge branch 'develop' into feature/tavernRumors

Conflicts:
	lib/CGameState.h
This commit is contained in:
ArseniyShestakov 2015-12-05 01:01:26 +03:00
commit c83f15e413
64 changed files with 438 additions and 367 deletions

View File

@ -153,6 +153,12 @@ BattleAction CStupidAI::activeStack( const CStack * stack )
}
}
for ( auto & enemy : enemiesReachable )
enemy.calcDmg( stack );
for ( auto & enemy : enemiesShootable )
enemy.calcDmg( stack );
if(enemiesShootable.size())
{
const EnemyInfo &ei= *std::max_element(enemiesShootable.begin(), enemiesShootable.end(), isMoreProfitable);

View File

@ -7,6 +7,10 @@
#include "../../lib/CConfigHandler.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/mapObjects/CBank.h"
#include "../../lib/mapObjects/CGTownInstance.h"
#include "../../lib/mapObjects/CQuest.h"
#include "../../lib/CPathfinder.h"
#include "../../lib/mapping/CMapDefines.h"
/*
* AIUtility.cpp, part of VCMI engine
@ -150,7 +154,7 @@ void foreach_neighbour(const int3 &pos, std::function<void(const int3& pos)> foo
{
CCallback * cbp = cb.get(); // avoid costly retrieval of thread-specific pointer
for(const int3 &dir : dirs)
for(const int3 &dir : int3::getDirs())
{
const int3 n = pos + dir;
if(cbp->isInTheMap(n))
@ -160,7 +164,7 @@ void foreach_neighbour(const int3 &pos, std::function<void(const int3& pos)> foo
void foreach_neighbour(CCallback * cbp, const int3 &pos, std::function<void(CCallback * cbp, const int3& pos)> foo)
{
for(const int3 &dir : dirs)
for(const int3 &dir : int3::getDirs())
{
const int3 n = pos + dir;
if(cbp->isInTheMap(n))
@ -359,7 +363,7 @@ int3 whereToExplore(HeroPtr h)
int radius = h->getSightRadious();
int3 hpos = h->visitablePos();
SectorMap &sm = ai->getCachedSectorMap(h);
auto sm = ai->getCachedSectorMap(h);
//look for nearby objs -> visit them if they're close enouh
const int DIST_LIMIT = 3;
@ -374,7 +378,7 @@ int3 whereToExplore(HeroPtr h)
CGPath p;
ai->myCb->getPathsInfo(h.get())->getPath(p, op);
if (p.nodes.size() && p.endPos() == op && p.nodes.size() <= DIST_LIMIT)
if (ai->isGoodForVisit(obj, h, sm))
if (ai->isGoodForVisit(obj, h, *sm))
nearbyVisitableObjs.push_back(obj);
}
}

View File

@ -6,9 +6,6 @@
#include "../../lib/CTownHandler.h"
#include "../../lib/spells/CSpellHandler.h"
#include "../../lib/Connection.h"
#include "../../lib/CGameState.h"
#include "../../lib/mapping/CMap.h"
#include "../../lib/NetPacks.h"
#include "../../lib/CStopWatch.h"
/*
@ -21,6 +18,8 @@
*
*/
class CCallback;
typedef const int3& crint3;
typedef const std::string& crstring;

View File

@ -5,6 +5,8 @@
#include "../../lib/mapObjects/MapObjects.h"
#include "../../lib/mapObjects/CommonConstructors.h"
#include "../../lib/CCreatureHandler.h"
#include "../../lib/CPathfinder.h"
#include "../../lib/CGameStateFwd.h"
#include "../../lib/VCMI_Lib.h"
#include "../../CCallback.h"
#include "VCAI.h"
@ -482,7 +484,7 @@ float FuzzyHelper::evaluate (Goals::ClearWayTo & g)
if (!g.hero.h)
throw cannotFulfillGoalException("ClearWayTo called without hero!");
int3 t = ai->getCachedSectorMap(g.hero).firstTileToGet(g.hero, g.tile);
int3 t = ai->getCachedSectorMap(g.hero)->firstTileToGet(g.hero, g.tile);
if (t.valid())
{

View File

@ -3,6 +3,7 @@
#include "VCAI.h"
#include "Fuzzy.h"
#include "../../lib/mapping/CMap.h" //for victory conditions
#include "../../lib/CPathfinder.h"
/*
* Goals.cpp, part of VCMI engine
@ -483,9 +484,9 @@ TGoalVec ClearWayTo::getAllPossibleSubgoals()
//if our hero is trapped, make sure we request clearing the way from OUR perspective
SectorMap &sm = ai->getCachedSectorMap(h);
auto sm = ai->getCachedSectorMap(h);
int3 tileToHit = sm.firstTileToGet(h, tile);
int3 tileToHit = sm->firstTileToGet(h, tile);
if (!tileToHit.valid())
continue;
@ -633,11 +634,11 @@ TGoalVec Explore::getAllPossibleSubgoals()
for (auto h : heroes)
{
SectorMap &sm = ai->getCachedSectorMap(h);
auto sm = ai->getCachedSectorMap(h);
for (auto obj : objs) //double loop, performance risk?
{
auto t = sm.firstTileToGet(h, obj->visitablePos()); //we assume that no more than one tile on the way is guarded
auto t = sm->firstTileToGet(h, obj->visitablePos()); //we assume that no more than one tile on the way is guarded
if (ai->isTileNotReserved(h, t))
ret.push_back (sptr(Goals::ClearWayTo(obj->visitablePos(), h).setisAbstract(true)));
}
@ -963,7 +964,7 @@ TGoalVec Conquer::getAllPossibleSubgoals()
for (auto h : cb->getHeroesInfo())
{
SectorMap &sm = ai->getCachedSectorMap(h);
auto sm = ai->getCachedSectorMap(h);
std::vector<const CGObjectInstance *> ourObjs(objs); //copy common objects
for (auto obj : ai->reservedHeroesMap[h]) //add objects reserved by this hero
@ -974,7 +975,7 @@ TGoalVec Conquer::getAllPossibleSubgoals()
for (auto obj : ourObjs)
{
int3 dest = obj->visitablePos();
auto t = sm.firstTileToGet(h, dest); //we assume that no more than one tile on the way is guarded
auto t = sm->firstTileToGet(h, dest); //we assume that no more than one tile on the way is guarded
if (t.valid()) //we know any path at all
{
if (ai->isTileNotReserved(h, t)) //no other hero wants to conquer that tile
@ -1027,6 +1028,10 @@ TSubgoal GatherArmy::whatToDoToAchieve()
return fh->chooseSolution (getAllPossibleSubgoals()); //find dwelling. use current hero to prevent him from doing nothing.
}
static const BuildingID unitsSource[] = { BuildingID::DWELL_LVL_1, BuildingID::DWELL_LVL_2, BuildingID::DWELL_LVL_3,
BuildingID::DWELL_LVL_4, BuildingID::DWELL_LVL_5, BuildingID::DWELL_LVL_6, BuildingID::DWELL_LVL_7};
TGoalVec GatherArmy::getAllPossibleSubgoals()
{
//get all possible towns, heroes and dwellings we may use
@ -1093,11 +1098,11 @@ TGoalVec GatherArmy::getAllPossibleSubgoals()
}
for(auto h : cb->getHeroesInfo())
{
SectorMap &sm = ai->getCachedSectorMap(h);
auto sm = ai->getCachedSectorMap(h);
for (auto obj : objs)
{ //find safe dwelling
auto pos = obj->visitablePos();
if (ai->isGoodForVisit(obj, h, sm))
if (ai->isGoodForVisit(obj, h, *sm))
ret.push_back (sptr (Goals::VisitTile(pos).sethero(h)));
}
}

View File

@ -8,6 +8,8 @@
#include "../../lib/CConfigHandler.h"
#include "../../lib/CHeroHandler.h"
#include "../../lib/CModHandler.h"
#include "../../lib/CGameState.h"
#include "../../lib/NetPacks.h"
/*
@ -843,9 +845,9 @@ void VCAI::makeTurnInternal()
bool VCAI::goVisitObj(const CGObjectInstance * obj, HeroPtr h)
{
int3 dst = obj->visitablePos();
SectorMap &sm = getCachedSectorMap(h);
auto sm = getCachedSectorMap(h);
logAi->debugStream() << boost::format("%s will try to visit %s at (%s)") % h->name % obj->getObjectName() % strFromInt3(dst);
int3 pos = sm.firstTileToGet(h, dst);
int3 pos = sm->firstTileToGet(h, dst);
if (!pos.valid()) //rare case when we are already standing on one of potential objects
return false;
return moveHeroToTile(pos, h);
@ -1301,6 +1303,20 @@ bool VCAI::tryBuildNextStructure(const CGTownInstance * t, std::vector<BuildingI
return false;//Nothing to build
}
//Set of buildings for different goals. Does not include any prerequisites.
static const BuildingID essential[] = {BuildingID::TAVERN, BuildingID::TOWN_HALL};
static const BuildingID goldSource[] = {BuildingID::TOWN_HALL, BuildingID::CITY_HALL, BuildingID::CAPITOL};
static const BuildingID unitsSource[] = { BuildingID::DWELL_LVL_1, BuildingID::DWELL_LVL_2, BuildingID::DWELL_LVL_3,
BuildingID::DWELL_LVL_4, BuildingID::DWELL_LVL_5, BuildingID::DWELL_LVL_6, BuildingID::DWELL_LVL_7};
static const BuildingID unitsUpgrade[] = { BuildingID::DWELL_LVL_1_UP, BuildingID::DWELL_LVL_2_UP, BuildingID::DWELL_LVL_3_UP,
BuildingID::DWELL_LVL_4_UP, BuildingID::DWELL_LVL_5_UP, BuildingID::DWELL_LVL_6_UP, BuildingID::DWELL_LVL_7_UP};
static const BuildingID unitGrowth[] = { BuildingID::FORT, BuildingID::CITADEL, BuildingID::CASTLE, BuildingID::HORDE_1,
BuildingID::HORDE_1_UPGR, BuildingID::HORDE_2, BuildingID::HORDE_2_UPGR};
static const BuildingID spells[] = {BuildingID::MAGES_GUILD_1, BuildingID::MAGES_GUILD_2, BuildingID::MAGES_GUILD_3,
BuildingID::MAGES_GUILD_4, BuildingID::MAGES_GUILD_5};
static const BuildingID extra[] = {BuildingID::RESOURCE_SILO, BuildingID::SPECIAL_1, BuildingID::SPECIAL_2, BuildingID::SPECIAL_3,
BuildingID::SPECIAL_4, BuildingID::SHIPYARD}; // all remaining buildings
void VCAI::buildStructure(const CGTownInstance * t)
{
//TODO make *real* town development system
@ -1381,10 +1397,10 @@ std::vector<const CGObjectInstance *> VCAI::getPossibleDestinations(HeroPtr h)
{
validateVisitableObjs();
std::vector<const CGObjectInstance *> possibleDestinations;
SectorMap &sm = getCachedSectorMap(h);
auto sm = getCachedSectorMap(h);
for(const CGObjectInstance *obj : visitableObjs)
{
if (isGoodForVisit(obj, h, sm))
if (isGoodForVisit(obj, h, *sm))
{
possibleDestinations.push_back(obj);
}
@ -1439,12 +1455,12 @@ void VCAI::wander(HeroPtr h)
validateVisitableObjs();
std::vector <ObjectIdRef> dests, tmp;
SectorMap &sm = getCachedSectorMap(h);
auto sm = getCachedSectorMap(h);
range::copy(reservedHeroesMap[h], std::back_inserter(tmp)); //also visit our reserved objects - but they are not prioritized to avoid running back and forth
for (auto obj : tmp)
{
int3 pos = sm.firstTileToGet(h, obj->visitablePos());
int3 pos = sm->firstTileToGet(h, obj->visitablePos());
if (pos.valid())
if (isAccessibleForHero (pos, h)) //even nearby objects could be blocked by other heroes :(
dests.push_back(obj); //can't use lambda for member function :(
@ -1453,7 +1469,7 @@ void VCAI::wander(HeroPtr h)
range::copy(getPossibleDestinations(h), std::back_inserter(dests));
erase_if(dests, [&](ObjectIdRef obj) -> bool
{
return !isSafeToVisit(h, sm.firstTileToGet(h, obj->visitablePos()));
return !isSafeToVisit(h, sm->firstTileToGet(h, obj->visitablePos()));
});
if(!dests.size())
@ -2465,7 +2481,7 @@ int3 VCAI::explorationBestNeighbour(int3 hpos, int radius, HeroPtr h)
{
int3 ourPos = h->convertPosition(h->pos, false);
std::map<int3, int> dstToRevealedTiles;
for(crint3 dir : dirs)
for(crint3 dir : int3::getDirs())
if(cb->isInTheMap(hpos+dir))
if (ourPos != dir) //don't stand in place
if (isSafeToVisit(h, hpos + dir) && isAccessibleForHero (hpos + dir, h))
@ -2539,7 +2555,7 @@ int3 VCAI::explorationNewPoint(HeroPtr h)
int3 VCAI::explorationDesperate(HeroPtr h)
{
SectorMap &sm = getCachedSectorMap(h);
auto sm = getCachedSectorMap(h);
int radius = h->getSightRadious();
std::vector<std::vector<int3> > tiles; //tiles[distance_to_fow]
@ -2568,7 +2584,7 @@ int3 VCAI::explorationDesperate(HeroPtr h)
if (!howManyTilesWillBeDiscovered(tile, radius, cbp)) //avoid costly checks of tiles that don't reveal much
continue;
auto t = sm.firstTileToGet(h, tile);
auto t = sm->firstTileToGet(h, tile);
if (t.valid())
{
ui64 ourDanger = evaluateDanger(t, h.h);
@ -2671,19 +2687,24 @@ void VCAI::finish()
void VCAI::requestActionASAP(std::function<void()> whatToDo)
{
// static boost::mutex m;
// boost::unique_lock<boost::mutex> mylock(m);
boost::mutex mutex;
mutex.lock();
boost::barrier b(2);
boost::thread newThread([&b,this,whatToDo]()
boost::thread newThread([&mutex,this,whatToDo]()
{
setThreadName("VCAI::requestActionASAP::helper");
SET_GLOBAL_STATE(this);
boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
b.wait();
// unlock mutex and allow parent function to exit
mutex.unlock();
whatToDo();
});
b.wait();
// wait for mutex to unlock and for thread to initialize properly
mutex.lock();
// unlock mutex - boost dislikes destruction of locked mutexes
mutex.unlock();
}
void VCAI::lostHero(HeroPtr h)
@ -2757,14 +2778,14 @@ TResources VCAI::freeResources() const
return myRes;
}
SectorMap& VCAI::getCachedSectorMap(HeroPtr h)
std::shared_ptr<SectorMap> VCAI::getCachedSectorMap(HeroPtr h)
{
auto it = cachedSectorMaps.find(h);
if (it != cachedSectorMaps.end())
return it->second;
else
{
cachedSectorMaps.insert(std::make_pair(h, SectorMap(h)));
cachedSectorMaps[h] = std::make_shared<SectorMap>(h);
return cachedSectorMaps[h];
}
}

View File

@ -12,11 +12,9 @@
#include "../../lib/CBuildingHandler.h"
#include "../../lib/CCreatureHandler.h"
#include "../../lib/CTownHandler.h"
#include "../../lib/mapObjects/MiscObjects.h"
#include "../../lib/spells/CSpellHandler.h"
#include "../../lib/Connection.h"
#include "../../lib/CGameState.h"
#include "../../lib/mapping/CMap.h"
#include "../../lib/NetPacks.h"
#include "../../lib/CondSh.h"
struct QuestInfo;
@ -115,20 +113,6 @@ struct SectorMap
int3 findFirstVisitableTile(HeroPtr h, crint3 dst);
};
//Set of buildings for different goals. Does not include any prerequisites.
const BuildingID essential[] = {BuildingID::TAVERN, BuildingID::TOWN_HALL};
const BuildingID goldSource[] = {BuildingID::TOWN_HALL, BuildingID::CITY_HALL, BuildingID::CAPITOL};
const BuildingID unitsSource[] = { BuildingID::DWELL_LVL_1, BuildingID::DWELL_LVL_2, BuildingID::DWELL_LVL_3,
BuildingID::DWELL_LVL_4, BuildingID::DWELL_LVL_5, BuildingID::DWELL_LVL_6, BuildingID::DWELL_LVL_7};
const BuildingID unitsUpgrade[] = { BuildingID::DWELL_LVL_1_UP, BuildingID::DWELL_LVL_2_UP, BuildingID::DWELL_LVL_3_UP,
BuildingID::DWELL_LVL_4_UP, BuildingID::DWELL_LVL_5_UP, BuildingID::DWELL_LVL_6_UP, BuildingID::DWELL_LVL_7_UP};
const BuildingID unitGrowth[] = { BuildingID::FORT, BuildingID::CITADEL, BuildingID::CASTLE, BuildingID::HORDE_1,
BuildingID::HORDE_1_UPGR, BuildingID::HORDE_2, BuildingID::HORDE_2_UPGR};
const BuildingID spells[] = {BuildingID::MAGES_GUILD_1, BuildingID::MAGES_GUILD_2, BuildingID::MAGES_GUILD_3,
BuildingID::MAGES_GUILD_4, BuildingID::MAGES_GUILD_5};
const BuildingID extra[] = {BuildingID::RESOURCE_SILO, BuildingID::SPECIAL_1, BuildingID::SPECIAL_2, BuildingID::SPECIAL_3,
BuildingID::SPECIAL_4, BuildingID::SHIPYARD}; // all remaining buildings
class VCAI : public CAdventureAI
{
public:
@ -161,7 +145,7 @@ public:
std::set<const CGObjectInstance *> alreadyVisited;
std::set<const CGObjectInstance *> reservedObjs; //to be visited by specific hero
std::map <HeroPtr, SectorMap> cachedSectorMaps; //TODO: serialize? not necessary
std::map <HeroPtr, std::shared_ptr<SectorMap>> cachedSectorMaps; //TODO: serialize? not necessary
TResources saving;
@ -314,7 +298,7 @@ public:
const CGObjectInstance *getUnvisitedObj(const std::function<bool(const CGObjectInstance *)> &predicate);
bool isAccessibleForHero(const int3 & pos, HeroPtr h, bool includeAllies = false) const;
//optimization - use one SM for every hero call
SectorMap& getCachedSectorMap(HeroPtr h);
std::shared_ptr<SectorMap> getCachedSectorMap(HeroPtr h);
const CGTownInstance *findTownWithTavern() const;
bool canRecruitAnyHero(const CGTownInstance * t = NULL) const;

View File

@ -18,12 +18,7 @@
#include "lib/spells/CSpellHandler.h"
#include "lib/CArtHandler.h"
#include "lib/GameConstants.h"
#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif
#include "lib/CPlayerState.h"
#include "lib/UnlockGuard.h"
/*

View File

@ -37,6 +37,7 @@
#include "../lib/CStopWatch.h"
#include "../lib/StartInfo.h"
#include "../lib/CGameState.h"
#include "../lib/CPlayerState.h"
#include "../lib/GameConstants.h"
#include "gui/CGuiHandler.h"
#include "windows/InfoWindows.h"

View File

@ -5,7 +5,6 @@
#include "../lib/CGameInterface.h"
#include "../lib/NetPacksBase.h"
#include "gui/CIntObject.h"
//#include "../lib/CGameState.h"
#ifdef __GNUC__
#define sprintf_s snprintf

View File

@ -22,6 +22,7 @@
#include "../lib/GameConstants.h"
#include "../lib/CStopWatch.h"
#include "../lib/mapObjects/CObjectClassesHandler.h"
#include "../lib/mapObjects/CObjectHandler.h"
using namespace CSDL_Ext;
#ifdef min

View File

@ -25,6 +25,7 @@
#include "../lib/CGameState.h"
#include "../lib/BattleState.h"
#include "../lib/GameConstants.h"
#include "../lib/CPlayerState.h"
#include "gui/CGuiHandler.h"
#include "widgets/MiscWidgets.h"
#include "widgets/AdventureMapClasses.h"

View File

@ -29,6 +29,7 @@
#include "../../lib/NetPacks.h"
#include "../../lib/StartInfo.h"
#include "../../lib/CondSh.h"
#include "../../lib/mapObjects/CGTownInstance.h"
/*
* CBattleInterfaceClasses.cpp, part of VCMI engine

View File

@ -13,13 +13,6 @@
*
*/
#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif
struct SDL_MouseMotionEvent;
// A point with x/y coordinate, used mostly for graphic rendering

View File

@ -19,7 +19,7 @@
#include "../../lib/CGameState.h"
#include "../../lib/CGeneralTextHandler.h"
#include "../../lib/NetPacksBase.h"
#include "../../lib/mapObjects/CQuest.h"
/*
* CQuestLog.cpp, part of VCMI engine
*

View File

@ -52,7 +52,7 @@ public:
/// CModListContainer overrides
void resetRepositories() override;
void addRepository(QVariantMap data) override;
void modChanged(QString modID);
void modChanged(QString modID) override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;

View File

@ -1,4 +1,4 @@
/*
/*
* BattleState.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
@ -22,6 +22,7 @@
#include "JsonNode.h"
#include "filesystem/Filesystem.h"
#include "CRandomGenerator.h"
#include "mapObjects/CGTownInstance.h"
const CStack * BattleInfo::getNextStack() const
{

View File

@ -11,12 +11,9 @@
#pragma once
#include "BattleHex.h"
#include "HeroBonus.h"
#include "CCreatureSet.h"
#include "mapObjects/CArmedInstance.h" // for army serialization
#include "mapObjects/CGHeroInstance.h" // for commander serialization
#include "CCreatureHandler.h"
#include "CObstacleInstance.h"
#include "ConstTransitivePtr.h"
#include "GameConstants.h"
#include "CBattleCallback.h"

View File

@ -6,6 +6,7 @@
#include "spells/CSpellHandler.h"
#include "VCMI_Lib.h"
#include "CTownHandler.h"
#include "mapObjects/CGTownInstance.h"
/*
* CBattleCallback.cpp, part of VCMI engine
@ -2245,6 +2246,7 @@ BattleAttackInfo::BattleAttackInfo(const CStack *Attacker, const CStack *Defende
chargedFields = 0;
luckyHit = false;
unluckyHit = false;
deathBlow = false;
ballistaDoubleDamage = false;
}

View File

@ -19,6 +19,8 @@
#include "NetPacks.h" // for InfoWindow
#include "CModHandler.h"
#include "spells/CSpellHandler.h"
#include "mapping/CMap.h"
#include "CPlayerState.h"
//TODO make clean
#define ERROR_VERBOSE_OR_NOT_RET_VAL_IF(cond, verbose, txt, retVal) do {if(cond){if(verbose)logGlobal->errorStream() << BOOST_CURRENT_FUNCTION << ": " << txt; return retVal;}} while(0)

View File

@ -1,12 +1,7 @@
#pragma once
//#ifndef _MSC_VER
#include "CCreatureHandler.h"
#include "VCMI_Lib.h"
#include "mapping/CMap.h"
//#endif
#include "HeroBonus.h"
#include "CCreatureSet.h"
@ -67,79 +62,6 @@ namespace boost
class shared_mutex;
}
//numbers of creatures are exact numbers if detailed else they are quantity ids (1 - a few, 2 - several and so on; additionally 0 - unknown)
struct ArmyDescriptor : public std::map<SlotID, CStackBasicDescriptor>
{
bool isDetailed;
DLL_LINKAGE ArmyDescriptor(const CArmedInstance *army, bool detailed); //not detailed -> quantity ids as count
DLL_LINKAGE ArmyDescriptor();
DLL_LINKAGE int getStrength() const;
};
struct DLL_LINKAGE InfoAboutArmy
{
PlayerColor owner;
std::string name;
ArmyDescriptor army;
InfoAboutArmy();
InfoAboutArmy(const CArmedInstance *Army, bool detailed);
void initFromArmy(const CArmedInstance *Army, bool detailed);
};
struct DLL_LINKAGE InfoAboutHero : public InfoAboutArmy
{
private:
void assign(const InfoAboutHero & iah);
public:
struct DLL_LINKAGE Details
{
std::vector<si32> primskills;
si32 mana, luck, morale;
} *details;
const CHeroClass *hclass;
int portrait;
InfoAboutHero();
InfoAboutHero(const InfoAboutHero & iah);
InfoAboutHero(const CGHeroInstance *h, bool detailed);
~InfoAboutHero();
InfoAboutHero & operator=(const InfoAboutHero & iah);
void initFromHero(const CGHeroInstance *h, bool detailed);
};
/// Struct which holds a int information about a town
struct DLL_LINKAGE InfoAboutTown : public InfoAboutArmy
{
struct DLL_LINKAGE Details
{
si32 hallLevel, goldIncome;
bool customRes;
bool garrisonedHero;
} *details;
const CTown *tType;
si32 built;
si32 fortLevel; //0 - none
InfoAboutTown();
InfoAboutTown(const CGTownInstance *t, bool detailed);
~InfoAboutTown();
void initFromTown(const CGTownInstance *t, bool detailed);
};
// typedef si32 TResourceUnit;
// typedef std::vector<si32> TResourceVector;
// typedef std::set<si32> TResourceSet;
struct DLL_LINKAGE SThievesGuildInfo
{
std::vector<PlayerColor> playerColors; //colors of players that are in-game
@ -159,55 +81,6 @@ struct DLL_LINKAGE SThievesGuildInfo
};
struct DLL_LINKAGE PlayerState : public CBonusSystemNode
{
public:
PlayerColor color;
bool human; //true if human controlled player, false for AI
TeamID team;
TResources resources;
std::set<ObjectInstanceID> visitedObjects; // as a std::set, since most accesses here will be from visited status checks
std::vector<ConstTransitivePtr<CGHeroInstance> > heroes;
std::vector<ConstTransitivePtr<CGTownInstance> > towns;
std::vector<ConstTransitivePtr<CGHeroInstance> > availableHeroes; //heroes available in taverns
std::vector<ConstTransitivePtr<CGDwelling> > dwellings; //used for town growth
std::vector<QuestInfo> quests; //store info about all received quests
bool enteredWinningCheatCode, enteredLosingCheatCode; //if true, this player has entered cheat codes for loss / victory
EPlayerStatus::EStatus status;
boost::optional<ui8> daysWithoutCastle;
PlayerState();
std::string nodeName() const override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & color & human & team & resources & status;
h & heroes & towns & availableHeroes & dwellings & quests & visitedObjects;
h & getBonusList(); //FIXME FIXME FIXME
h & status & daysWithoutCastle;
h & enteredLosingCheatCode & enteredWinningCheatCode;
h & static_cast<CBonusSystemNode&>(*this);
}
};
struct DLL_LINKAGE TeamState : public CBonusSystemNode
{
public:
TeamID id; //position in gameState::teams
std::set<PlayerColor> players; // members of this team
std::vector<std::vector<std::vector<ui8> > > fogOfWarMap; //true - visible, false - hidden
TeamState();
template <typename Handler> void serialize(Handler &h, const int version)
{
h & id & players & fogOfWarMap;
h & static_cast<CBonusSystemNode&>(*this);
}
};
struct DLL_LINKAGE RumorState
{
enum ERumorType : ui8
@ -304,7 +177,6 @@ struct DLL_EXPORT DuelParameters
}
};
struct BattleInfo;
DLL_LINKAGE std::ostream & operator<<(std::ostream & os, const EVictoryLossCheckResult & victoryLossCheckResult);

View File

@ -10,8 +10,81 @@
*
*/
#include "CCreatureSet.h"
class CQuest;
class CGObjectInstance;
class CHeroClass;
class CTown;
//numbers of creatures are exact numbers if detailed else they are quantity ids (1 - a few, 2 - several and so on; additionally 0 - unknown)
struct ArmyDescriptor : public std::map<SlotID, CStackBasicDescriptor>
{
bool isDetailed;
DLL_LINKAGE ArmyDescriptor(const CArmedInstance *army, bool detailed); //not detailed -> quantity ids as count
DLL_LINKAGE ArmyDescriptor();
DLL_LINKAGE int getStrength() const;
};
struct DLL_LINKAGE InfoAboutArmy
{
PlayerColor owner;
std::string name;
ArmyDescriptor army;
InfoAboutArmy();
InfoAboutArmy(const CArmedInstance *Army, bool detailed);
void initFromArmy(const CArmedInstance *Army, bool detailed);
};
struct DLL_LINKAGE InfoAboutHero : public InfoAboutArmy
{
private:
void assign(const InfoAboutHero & iah);
public:
struct DLL_LINKAGE Details
{
std::vector<si32> primskills;
si32 mana, luck, morale;
} *details;
const CHeroClass *hclass;
int portrait;
InfoAboutHero();
InfoAboutHero(const InfoAboutHero & iah);
InfoAboutHero(const CGHeroInstance *h, bool detailed);
~InfoAboutHero();
InfoAboutHero & operator=(const InfoAboutHero & iah);
void initFromHero(const CGHeroInstance *h, bool detailed);
};
/// Struct which holds a int information about a town
struct DLL_LINKAGE InfoAboutTown : public InfoAboutArmy
{
struct DLL_LINKAGE Details
{
si32 hallLevel, goldIncome;
bool customRes;
bool garrisonedHero;
} *details;
const CTown *tType;
si32 built;
si32 fortLevel; //0 - none
InfoAboutTown();
InfoAboutTown(const CGTownInstance *t, bool detailed);
~InfoAboutTown();
void initFromTown(const CGTownInstance *t, bool detailed);
};
class DLL_LINKAGE EVictoryLossCheckResult
{

View File

@ -117,6 +117,7 @@ set(lib_HEADERS
filesystem/ISimpleResourceLoader.h
mapObjects/MapObjects.h
mapping/CMapDefines.h
CSoundBase.h
AI_Base.h
@ -131,6 +132,7 @@ set(lib_HEADERS
IGameEventsReceiver.h
int3.h
CGameStateFwd.h
CPlayerState.h
Interprocess.h
NetPacks.h
NetPacksBase.h

View File

@ -467,7 +467,7 @@ static JsonNode loadModSettings(std::string path)
JsonNode addMeta(JsonNode config, std::string meta)
{
config.setMeta(meta);
return std::move(config);
return config;
}
CModInfo::CModInfo(std::string identifier,const JsonNode & local, const JsonNode & config):

View File

@ -8,6 +8,7 @@
#include "GameConstants.h"
#include "CStopWatch.h"
#include "CConfigHandler.h"
#include "../lib/CPlayerState.h"
/*
* CPathfinder.cpp, part of VCMI engine

View File

@ -1,8 +1,8 @@
#pragma once
#include "VCMI_Lib.h"
#include "mapping/CMap.h"
#include "IGameCallback.h"
#include "HeroBonus.h"
#include "int3.h"
#include <boost/heap/priority_queue.hpp>
@ -21,6 +21,8 @@ class CGHeroInstance;
class CGObjectInstance;
struct TerrainTile;
class CPathfinderHelper;
class CMap;
class CGWhirlpool;
struct DLL_LINKAGE CGPathNode
{

66
lib/CPlayerState.h Normal file
View File

@ -0,0 +1,66 @@
#pragma once
/*
* CPlayerState.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "HeroBonus.h"
class CGHeroInstance;
class CGTownInstance;
class CGDwelling;
struct DLL_LINKAGE PlayerState : public CBonusSystemNode
{
public:
PlayerColor color;
bool human; //true if human controlled player, false for AI
TeamID team;
TResources resources;
std::set<ObjectInstanceID> visitedObjects; // as a std::set, since most accesses here will be from visited status checks
std::vector<ConstTransitivePtr<CGHeroInstance> > heroes;
std::vector<ConstTransitivePtr<CGTownInstance> > towns;
std::vector<ConstTransitivePtr<CGHeroInstance> > availableHeroes; //heroes available in taverns
std::vector<ConstTransitivePtr<CGDwelling> > dwellings; //used for town growth
std::vector<QuestInfo> quests; //store info about all received quests
bool enteredWinningCheatCode, enteredLosingCheatCode; //if true, this player has entered cheat codes for loss / victory
EPlayerStatus::EStatus status;
boost::optional<ui8> daysWithoutCastle;
PlayerState();
std::string nodeName() const override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & color & human & team & resources & status;
h & heroes & towns & availableHeroes & dwellings & quests & visitedObjects;
h & getBonusList(); //FIXME FIXME FIXME
h & status & daysWithoutCastle;
h & enteredLosingCheatCode & enteredWinningCheatCode;
h & static_cast<CBonusSystemNode&>(*this);
}
};
struct DLL_LINKAGE TeamState : public CBonusSystemNode
{
public:
TeamID id; //position in gameState::teams
std::set<PlayerColor> players; // members of this team
std::vector<std::vector<std::vector<ui8> > > fogOfWarMap; //true - visible, false - hidden
TeamState();
template <typename Handler> void serialize(Handler &h, const int version)
{
h & id & players & fogOfWarMap;
h & static_cast<CBonusSystemNode&>(*this);
}
};

View File

@ -774,12 +774,8 @@ std::set<TFaction> CTownHandler::getAllowedFactions(bool withTown /*=true*/) con
if (withTown)
allowed = getDefaultAllowed();
else
{
for (auto town : factions)
{
allowed.push_back (true);
}
}
allowed.resize( factions.size(), true);
for (size_t i=0; i<allowed.size(); i++)
if (allowed[i])
allowedFactions.insert(i);

View File

@ -2,6 +2,8 @@
#include "Connection.h"
#include "registerTypes/RegisterTypes.h"
#include "mapping/CMap.h"
#include "CGameState.h"
#include <boost/asio.hpp>

View File

@ -11,7 +11,7 @@
#pragma once
#include <typeinfo> //XXX this is in namespace std if you want w/o use typeinfo.h?
#include <typeinfo>
#include <type_traits>
#include <boost/mpl/eval_if.hpp>

View File

@ -405,6 +405,18 @@ public:
ID_LIKE_OPERATORS(BuildingID, BuildingID::EBuildingID)
namespace EAiTactic
{
enum EAiTactic
{
NONE = -1,
RANDOM,
WARRIOR,
BUILDER,
EXPLORER
};
}
namespace EBuildingState
{
enum EBuildingState

View File

@ -21,6 +21,8 @@
#include "mapObjects/CObjectClassesHandler.h"
#include "StartInfo.h"
#include "CGameState.h"
#include "mapping/CMap.h"
#include "CPlayerState.h"
void CPrivilagedInfoCallback::getFreeTiles (std::vector<int3> &tiles) const
{

View File

@ -13,7 +13,7 @@
#include "ResourceSet.h"
//#include "CObstacleInstance.h"
#include "CGameStateFwd.h"
#include "mapping/CMap.h"
#include "mapping/CMapDefines.h"
#include "CObstacleInstance.h"
#include "spells/ViewSpellInt.h"

View File

@ -16,6 +16,7 @@
#include "CTownHandler.h"
#include "mapping/CMapInfo.h"
#include "StartInfo.h"
#include "CPlayerState.h"
/*
* NetPacksLib.cpp, part of VCMI engine

View File

@ -131,6 +131,12 @@ public:
{
h & x & y & z;
}
static std::array<int3, 8> getDirs()
{
return { { int3(0,1,0),int3(0,-1,0),int3(-1,0,0),int3(+1,0,0),
int3(1,1,0),int3(-1,1,0),int3(1,-1,0),int3(-1,-1,0) } };
}
};
inline std::ostream & operator<<(std::ostream & str, const int3 & sth)
@ -154,9 +160,6 @@ struct ShashInt3
}
};
static const int3 dirs[] = { int3(0,1,0),int3(0,-1,0),int3(-1,0,0),int3(+1,0,0),
int3(1,1,0),int3(-1,1,0),int3(1,-1,0),int3(-1,-1,0) };
template<typename Container>
int3 findClosestTile (Container & container, int3 dest)
{
@ -175,4 +178,4 @@ int3 findClosestTile (Container & container, int3 dest)
}
}
return result;
}
}

View File

@ -1,4 +1,4 @@
/*
/*
* CArmedInstance.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
@ -15,6 +15,7 @@
#include "../CCreatureHandler.h"
#include "../CGeneralTextHandler.h"
#include "../CGameState.h"
#include "../CPlayerState.h"
void CArmedInstance::randomizeArmy(int type)
{

View File

@ -1,4 +1,4 @@
/*
/*
* CGHeroInstance.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
@ -22,6 +22,8 @@
#include "../CGameState.h"
#include "../CCreatureHandler.h"
#include "../BattleState.h"
#include "../CTownHandler.h"
#include "CGTownInstance.h"
///helpers
static void showInfoDialog(const PlayerColor playerID, const ui32 txtID, const ui16 soundID)

View File

@ -1,4 +1,4 @@
/*
/*
*
* CGMarket.cpp, part of VCMI engine
*
@ -17,6 +17,7 @@
#include "../IGameCallback.h"
#include "../CCreatureHandler.h"
#include "../CGameState.h"
#include "CGTownInstance.h"
///helpers
static void openWindow(const OpenWindow::EWindow type, const int id1, const int id2 = -1)

View File

@ -1,4 +1,4 @@
/*
/*
* CGTownInstance.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
@ -17,6 +17,8 @@
#include "../CModHandler.h"
#include "../IGameCallback.h"
#include "../CGameState.h"
#include "../mapping/CMapDefines.h"
#include "../CPlayerState.h"
std::vector<const CArtifact *> CGTownInstance::merchantArtifacts;
std::vector<int> CGTownInstance::universitySkills;

View File

@ -1,4 +1,4 @@
#pragma once
#pragma once
#include "CObjectHandler.h"
#include "CGMarket.h" // For IMarket interface
@ -52,11 +52,7 @@ public:
CSpecObjInfo * info; //h3m info about dewlling
TCreaturesSet creatures; //creatures[level] -> <vector of alternative ids (base creature and upgrades, creatures amount>
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CArmedInstance&>(*this) & creatures;
}
private:
void initObj() override;
void onHeroVisit(const CGHeroInstance * h) const override;
void newTurn() const override;
@ -64,9 +60,14 @@ public:
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
private:
void updateGuards() const;
void heroAcceptsCreatures(const CGHeroInstance *h) const;
public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CArmedInstance&>(*this) & creatures;
}
};
class DLL_LINKAGE CGTownBuilding : public IObjectInterface

View File

@ -1,4 +1,4 @@
/*
/*
* CObjectHandler.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
@ -18,8 +18,10 @@
#include "../filesystem/ResourceID.h"
#include "../IGameCallback.h"
#include "../CGameState.h"
#include "../mapping/CMap.h"
#include "CObjectClassesHandler.h"
#include "CGTownInstance.h"
IGameCallback * IObjectInterface::cb = nullptr;

View File

@ -17,6 +17,7 @@
#include "../CGeneralTextHandler.h"
#include "../CHeroHandler.h"
#include "CObjectClassesHandler.h"
#include "MiscObjects.h"
#include "../IGameCallback.h"
#include "../CGameState.h"

View File

@ -17,6 +17,7 @@
#include "../NetPacks.h"
#include "../IGameCallback.h"
#include "../CGameState.h"
#include "../CPlayerState.h"
#include "CObjectClassesHandler.h"

View File

@ -20,6 +20,8 @@
#include "../spells/CSpellHandler.h"
#include "../IGameCallback.h"
#include "../CGameState.h"
#include "../mapping/CMap.h"
#include "../CPlayerState.h"
std::map <si32, std::vector<ObjectInstanceID> > CGMagi::eyelist;
ui8 CGObelisk::obeliskCount; //how many obelisks are on map

View File

@ -227,7 +227,8 @@ class DLL_LINKAGE CGMine : public CArmedInstance
public:
Res::ERes producedResource;
ui32 producedQuantity;
private:
void onHeroVisit(const CGHeroInstance * h) const override;
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
@ -239,6 +240,7 @@ public:
std::string getObjectName() const override;
std::string getHoverText(PlayerColor player) const override;
public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CArmedInstance&>(*this);
@ -265,29 +267,33 @@ struct DLL_LINKAGE TeleportChannel
class DLL_LINKAGE CGTeleport : public CGObjectInstance
{
public:
enum EType {UNKNOWN, ENTRANCE, EXIT, BOTH};
EType type;
TeleportChannelID channel;
CGTeleport();
bool isEntrance() const;
bool isExit() const;
bool isChannelEntrance(ObjectInstanceID id) const;
bool isChannelExit(ObjectInstanceID id) const;
std::vector<ObjectInstanceID> getAllEntrances(bool excludeCurrent = false) const;
std::vector<ObjectInstanceID> getAllExits(bool excludeCurrent = false) const;
protected:
enum EType {UNKNOWN, ENTRANCE, EXIT, BOTH};
EType type;
CGTeleport();
ObjectInstanceID getRandomExit(const CGHeroInstance * h) const;
std::vector<ObjectInstanceID> getAllExits(bool excludeCurrent = false) const;
public:
TeleportChannelID channel;
bool isEntrance() const;
bool isExit() const;
virtual void teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer, std::vector<ObjectInstanceID> exits) const = 0;
static bool isTeleport(const CGObjectInstance * dst);
static bool isConnected(const CGTeleport * src, const CGTeleport * dst);
static bool isConnected(const CGObjectInstance * src, const CGObjectInstance * dst);
static bool isExitPassable(CGameState * gs, const CGHeroInstance * h, const CGObjectInstance * obj);
static std::vector<ObjectInstanceID> getPassableExits(CGameState * gs, const CGHeroInstance * h, std::vector<ObjectInstanceID> exits);
static void addToChannel(std::map<TeleportChannelID, shared_ptr<TeleportChannel> > &channelsList, const CGTeleport * obj);
static std::vector<ObjectInstanceID> getPassableExits(CGameState * gs, const CGHeroInstance * h, std::vector<ObjectInstanceID> exits);
static bool isExitPassable(CGameState * gs, const CGHeroInstance * h, const CGObjectInstance * obj);
template <typename Handler> void serialize(Handler &h, const int version)
{
@ -299,11 +305,12 @@ class DLL_LINKAGE CGMonolith : public CGTeleport
{
TeleportChannelID findMeChannel(std::vector<Obj> IDs, int SubID) const;
public:
protected:
void onHeroVisit(const CGHeroInstance * h) const override;
void teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer, std::vector<ObjectInstanceID> exits) const override;
void initObj() override;
public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CGTeleport&>(*this);
@ -312,9 +319,10 @@ public:
class DLL_LINKAGE CGSubterraneanGate : public CGMonolith
{
public:
void onHeroVisit(const CGHeroInstance * h) const override;
void initObj() override;
public:
static void postInit();
template <typename Handler> void serialize(Handler &h, const int version)
@ -325,11 +333,11 @@ public:
class DLL_LINKAGE CGWhirlpool : public CGMonolith
{
public:
void onHeroVisit(const CGHeroInstance * h) const override;
void teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer, std::vector<ObjectInstanceID> exits) const override;
static bool isProtected( const CGHeroInstance * h );
public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & static_cast<CGMonolith&>(*this);

View File

@ -292,7 +292,7 @@ CScenarioTravel CCampaignHandler::readScenarioTravelFromMemory(CBinaryReader & r
std::vector< std::vector<ui8> > CCampaignHandler::getFile(const std::string & name, bool headerOnly)
{
CCompressedStream stream(std::move(CResourceHandler::get()->load(ResourceID(name, EResType::CAMPAIGN))), true);
CCompressedStream stream(CResourceHandler::get()->load(ResourceID(name, EResType::CAMPAIGN)), true);
std::vector< std::vector<ui8> > ret;
do
@ -363,7 +363,7 @@ std::vector<CGHeroInstance *> CCampaignScenario::getLostCrossoverHeroes() const
}
}
}
return std::move(lostCrossoverHeroes);
return lostCrossoverHeroes;
}
bool CScenarioTravel::STravelBonus::isBonusForHero() const

View File

@ -10,6 +10,7 @@
#include "StdInc.h"
#include "CDrawRoadsOperation.h"
#include "CMap.h"
const std::vector<CDrawRoadsOperation::RoadPattern> CDrawRoadsOperation::patterns =
{

View File

@ -11,9 +11,9 @@
#pragma once
#include "../CRandomGenerator.h"
#include "CMap.h"
#include "CMapEditManager.h"
struct TerrainTile;
class CDrawRoadsOperation : public CMapOperation
{

View File

@ -19,6 +19,7 @@
#include "../int3.h"
#include "../GameConstants.h"
#include "../LogicalExpression.h"
#include "CMapDefines.h"
class CArtifactInstance;
class CGObjectInstance;
@ -47,18 +48,6 @@ struct DLL_LINKAGE SHeroName
}
};
namespace EAiTactic
{
enum EAiTactic
{
NONE = -1,
RANDOM,
WARRIOR,
BUILDER,
EXPLORER
};
}
/// The player info constains data about which factions are allowed, AI tactical settings,
/// the main hero name, where to generate the hero, whether the faction should be selected randomly,...
struct DLL_LINKAGE PlayerInfo
@ -216,94 +205,6 @@ struct DLL_LINKAGE DisposedHero
}
};
/// The map event is an event which e.g. gives or takes resources of a specific
/// amount to/from players and can appear regularly or once a time.
class DLL_LINKAGE CMapEvent
{
public:
CMapEvent();
bool earlierThan(const CMapEvent & other) const;
bool earlierThanOrEqual(const CMapEvent & other) const;
std::string name;
std::string message;
TResources resources;
ui8 players; // affected players, bit field?
ui8 humanAffected;
ui8 computerAffected;
ui32 firstOccurence;
ui32 nextOccurence; /// specifies after how many days the event will occur the next time; 0 if event occurs only one time
template <typename Handler>
void serialize(Handler & h, const int version)
{
h & name & message & resources
& players & humanAffected & computerAffected & firstOccurence & nextOccurence;
}
};
/// The castle event builds/adds buildings/creatures for a specific town.
class DLL_LINKAGE CCastleEvent: public CMapEvent
{
public:
CCastleEvent();
std::set<BuildingID> buildings;
std::vector<si32> creatures;
CGTownInstance * town;
template <typename Handler>
void serialize(Handler & h, const int version)
{
h & static_cast<CMapEvent &>(*this);
h & buildings & creatures;
}
};
/// The terrain tile describes the terrain type and the visual representation of the terrain.
/// Furthermore the struct defines whether the tile is visitable or/and blocked and which objects reside in it.
struct DLL_LINKAGE TerrainTile
{
TerrainTile();
/// Gets true if the terrain is not a rock. If from is water/land, same type is also required.
bool entrableTerrain(const TerrainTile * from = nullptr) const;
bool entrableTerrain(bool allowLand, bool allowSea) const;
/// Checks for blocking objects and terraint type (water / land).
bool isClear(const TerrainTile * from = nullptr) const;
/// Gets the ID of the top visitable object or -1 if there is none.
Obj topVisitableId(bool excludeTop = false) const;
CGObjectInstance * topVisitableObj(bool excludeTop = false) const;
bool isWater() const;
bool isCoastal() const;
EDiggingStatus getDiggingStatus(const bool excludeTop = true) const;
bool hasFavourableWinds() const;
ETerrainType terType;
ui8 terView;
ERiverType::ERiverType riverType;
ui8 riverDir;
ERoadType::ERoadType roadType;
ui8 roadDir;
/// first two bits - how to rotate terrain graphic (next two - river graphic, next two - road);
/// 7th bit - whether tile is coastal (allows disembarking if land or block movement if water); 8th bit - Favourable Winds effect
ui8 extTileFlags;
bool visitable;
bool blocked;
std::vector<CGObjectInstance *> visitableObjects;
std::vector<CGObjectInstance *> blockingObjects;
template <typename Handler>
void serialize(Handler & h, const int version)
{
h & terType & terView & riverType & riverDir & roadType &roadDir & extTileFlags;
h & visitable & blocked;
h & visitableObjects & blockingObjects;
}
};
namespace EMapFormat
{
enum EMapFormat

99
lib/mapping/CMapDefines.h Normal file
View File

@ -0,0 +1,99 @@
/*
* CMapDefines.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
/// The map event is an event which e.g. gives or takes resources of a specific
/// amount to/from players and can appear regularly or once a time.
class DLL_LINKAGE CMapEvent
{
public:
CMapEvent();
bool earlierThan(const CMapEvent & other) const;
bool earlierThanOrEqual(const CMapEvent & other) const;
std::string name;
std::string message;
TResources resources;
ui8 players; // affected players, bit field?
ui8 humanAffected;
ui8 computerAffected;
ui32 firstOccurence;
ui32 nextOccurence; /// specifies after how many days the event will occur the next time; 0 if event occurs only one time
template <typename Handler>
void serialize(Handler & h, const int version)
{
h & name & message & resources
& players & humanAffected & computerAffected & firstOccurence & nextOccurence;
}
};
/// The castle event builds/adds buildings/creatures for a specific town.
class DLL_LINKAGE CCastleEvent: public CMapEvent
{
public:
CCastleEvent();
std::set<BuildingID> buildings;
std::vector<si32> creatures;
CGTownInstance * town;
template <typename Handler>
void serialize(Handler & h, const int version)
{
h & static_cast<CMapEvent &>(*this);
h & buildings & creatures;
}
};
/// The terrain tile describes the terrain type and the visual representation of the terrain.
/// Furthermore the struct defines whether the tile is visitable or/and blocked and which objects reside in it.
struct DLL_LINKAGE TerrainTile
{
TerrainTile();
/// Gets true if the terrain is not a rock. If from is water/land, same type is also required.
bool entrableTerrain(const TerrainTile * from = nullptr) const;
bool entrableTerrain(bool allowLand, bool allowSea) const;
/// Checks for blocking objects and terraint type (water / land).
bool isClear(const TerrainTile * from = nullptr) const;
/// Gets the ID of the top visitable object or -1 if there is none.
Obj topVisitableId(bool excludeTop = false) const;
CGObjectInstance * topVisitableObj(bool excludeTop = false) const;
bool isWater() const;
bool isCoastal() const;
EDiggingStatus getDiggingStatus(const bool excludeTop = true) const;
bool hasFavourableWinds() const;
ETerrainType terType;
ui8 terView;
ERiverType::ERiverType riverType;
ui8 riverDir;
ERoadType::ERoadType roadType;
ui8 roadDir;
/// first two bits - how to rotate terrain graphic (next two - river graphic, next two - road);
/// 7th bit - whether tile is coastal (allows disembarking if land or block movement if water); 8th bit - Favourable Winds effect
ui8 extTileFlags;
bool visitable;
bool blocked;
std::vector<CGObjectInstance *> visitableObjects;
std::vector<CGObjectInstance *> blockingObjects;
template <typename Handler>
void serialize(Handler & h, const int version)
{
h & terType & terView & riverType & riverDir & roadType &roadDir & extTileFlags;
h & visitable & blocked;
h & visitableObjects & blockingObjects;
}
};

View File

@ -7,6 +7,7 @@
#include "../mapObjects/CGHeroInstance.h"
#include "../VCMI_Lib.h"
#include "CDrawRoadsOperation.h"
#include "../mapping/CMap.h"
MapRect::MapRect() : x(0), y(0), z(0), width(0), height(0)
{

View File

@ -12,11 +12,13 @@
#pragma once
#include "../CRandomGenerator.h"
#include "CMap.h"
#include "../int3.h"
#include "../GameConstants.h"
class CGObjectInstance;
class CTerrainViewPatternConfig;
struct TerrainViewPattern;
class CMap;
/// Represents a map rectangle.
struct DLL_LINKAGE MapRect

View File

@ -20,7 +20,7 @@ std::unique_ptr<CMap> CMapService::loadMap(const std::string & name)
getMapPatcher(name)->patchMapHeader(header);
header.release();
return std::move(map);
return map;
}
std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const std::string & name)
@ -28,7 +28,7 @@ std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const std::string & name)
auto stream = getStreamFromFS(name);
std::unique_ptr<CMapHeader> header = getMapLoader(stream)->loadMapHeader();
getMapPatcher(name)->patchMapHeader(header);
return std::move(header);
return header;
}
std::unique_ptr<CMap> CMapService::loadMap(const ui8 * buffer, int size, const std::string & name)
@ -40,7 +40,7 @@ std::unique_ptr<CMap> CMapService::loadMap(const ui8 * buffer, int size, const s
getMapPatcher(name)->patchMapHeader(header);
header.release();
return std::move(map);
return map;
}
std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const ui8 * buffer, int size, const std::string & name)
@ -48,7 +48,7 @@ std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const ui8 * buffer, int s
auto stream = getStreamFromMem(buffer, size);
std::unique_ptr<CMapHeader> header = getMapLoader(stream)->loadMapHeader();
getMapPatcher(name)->patchMapHeader(header);
return std::move(header);
return header;
}
std::unique_ptr<CInputStream> CMapService::getStreamFromFS(const std::string & name)

View File

@ -4,7 +4,7 @@
#include "../NetPacks.h"
#include "../VCMI_Lib.h"
#include "../CArtHandler.h"
#include "../CGameState.h"
#include "../CPlayerState.h"
#include "../CHeroHandler.h"
#include "../CTownHandler.h"
#include "../CModHandler.h" //needed?
@ -24,8 +24,6 @@
*
*/
template<typename Serializer>
void registerTypesMapObjects1(Serializer &s)
{

View File

@ -17,7 +17,7 @@ static const int3 dirs4[] = {int3(0,1,0),int3(0,-1,0),int3(-1,0,0),int3(+1,0,0)}
void CMapGenerator::foreach_neighbour(const int3 &pos, std::function<void(int3& pos)> foo)
{
for(const int3 &dir : dirs)
for(const int3 &dir : int3::getDirs())
{
int3 n = pos + dir;
if(map->isInTheMap(n))

View File

@ -735,7 +735,7 @@ bool CRmgTemplateZone::createRoad(CMapGenerator* gen, const int3& src, const int
std::map<int3, int3> cameFrom; // The map of navigated nodes.
std::map<int3, float> distances;
int3 currentNode = src;
//int3 currentNode = src;
gen->setRoad (src, ERoadType::NO_ROAD); //just in case zone guard already has road under it. Road under nodes will be added at very end
cameFrom[src] = int3(-1, -1, -1); //first node points to finish condition
@ -824,7 +824,7 @@ bool CRmgTemplateZone::connectPath(CMapGenerator* gen, const int3& src, bool onl
std::map<int3, int3> cameFrom; // The map of navigated nodes.
std::map<int3, float> distances;
int3 currentNode = src;
//int3 currentNode = src;
cameFrom[src] = int3(-1, -1, -1); //first node points to finish condition
distances[src] = 0;
@ -866,7 +866,7 @@ bool CRmgTemplateZone::connectPath(CMapGenerator* gen, const int3& src, bool onl
return;
if (distance < bestDistanceSoFar || !vstd::contains(closed, pos))
{
auto obj = gen->map->getTile(pos).topVisitableObj();
//auto obj = gen->map->getTile(pos).topVisitableObj();
if (vstd::contains(this->tileinfo, pos))
{
cameFrom[pos] = currentNode;
@ -902,7 +902,7 @@ bool CRmgTemplateZone::connectWithCenter(CMapGenerator* gen, const int3& src, bo
std::map<int3, int3> cameFrom; // The map of navigated nodes.
std::map<int3, float> distances;
int3 currentNode = src;
//int3 currentNode = src;
cameFrom[src] = int3(-1, -1, -1); //first node points to finish condition
distances[src] = 0;
@ -950,7 +950,7 @@ bool CRmgTemplateZone::connectWithCenter(CMapGenerator* gen, const int3& src, bo
if (distance < bestDistanceSoFar || !vstd::contains(closed, pos))
{
auto obj = gen->map->getTile(pos).topVisitableObj();
//auto obj = gen->map->getTile(pos).topVisitableObj();
if (vstd::contains(this->tileinfo, pos))
{
cameFrom[pos] = currentNode;
@ -2336,7 +2336,8 @@ ObjectInfo CRmgTemplateZone::getRandomObject(CMapGenerator* gen, CTreasurePileIn
}
assert (0); //we should never be here
}
//FIXME: control reaches end of non-void function. Missing return?
return ObjectInfo(); // unreachable
}
void CRmgTemplateZone::addAllPossibleObjects(CMapGenerator* gen)

View File

@ -13,6 +13,7 @@
#include "../CRandomGenerator.h"
#include "CZonePlacer.h"
#include "CRmgTemplateZone.h"
#include "../mapping/CMap.h"
#include "CZoneGraphGenerator.h"

View File

@ -12,8 +12,6 @@
#pragma once
#include "CMapGenerator.h"
#include "../mapping/CMap.h"
#include "float3.h"
#include "../int3.h"

View File

@ -18,6 +18,8 @@
#include "../BattleState.h"
#include "../CGameState.h"
#include "../CGameInfoCallback.h"
#include "../mapping/CMap.h"
#include "../CPlayerState.h"
///SummonBoatMechanics
ESpellCastResult SummonBoatMechanics::applyAdventureEffects(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const

View File

@ -14,6 +14,7 @@
#include "../NetPacks.h"
#include "../BattleState.h"
#include "../mapObjects/CGHeroInstance.h"
#include "../mapObjects/CGTownInstance.h"
///HealingSpellMechanics
void HealingSpellMechanics::applyBattleEffects(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, SpellCastContext & ctx) const

View File

@ -640,7 +640,7 @@ std::string CSpell::AnimationInfo::selectProjectile(const double angle) const
}
}
return std::move(res);
return res;
}
///CSpell::TargetInfo

View File

@ -1665,7 +1665,7 @@ std::list<PlayerColor> CGameHandler::generatePlayerTurnOrder() const
if(!player.second.human)
playerTurnOrder.push_back(player.first);
}
return std::move(playerTurnOrder);
return playerTurnOrder;
}
void CGameHandler::setupBattle( int3 tile, const CArmedInstance *armies[2], const CGHeroInstance *heroes[2], bool creatureBank, const CGTownInstance *town )

View File

@ -2,11 +2,9 @@
#include "../lib/FunctionList.h"
#include "../lib/CGameState.h"
#include "../lib/Connection.h"
#include "../lib/IGameCallback.h"
#include "../lib/BattleAction.h"
#include "../lib/NetPacks.h"
#include "CQuery.h"

View File

@ -2,6 +2,7 @@
#include "CQuery.h"
#include "CGameHandler.h"
#include "../lib/BattleState.h"
#include "../lib/mapObjects/MiscObjects.h"
boost::mutex Queries::mx;