mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
Refactoring: avoid using namespace when it's not absolutely needed
This commit is contained in:
parent
6985e96f0d
commit
29a7934a99
@ -31,7 +31,6 @@ class Engine;
|
|||||||
class InputVariable;
|
class InputVariable;
|
||||||
class CGTownInstance;
|
class CGTownInstance;
|
||||||
|
|
||||||
using namespace vstd;
|
|
||||||
//using namespace Goals;
|
//using namespace Goals;
|
||||||
|
|
||||||
FuzzyHelper *fh;
|
FuzzyHelper *fh;
|
||||||
@ -85,7 +84,7 @@ armyStructure evaluateArmyStructure (const CArmedInstance * army)
|
|||||||
if (walker)
|
if (walker)
|
||||||
walkersStrenght += s.second->getPower();
|
walkersStrenght += s.second->getPower();
|
||||||
|
|
||||||
amax (maxSpeed, s.second->type->valOfBonuses(Bonus::STACKS_SPEED));
|
vstd::amax(maxSpeed, s.second->type->valOfBonuses(Bonus::STACKS_SPEED));
|
||||||
}
|
}
|
||||||
armyStructure as;
|
armyStructure as;
|
||||||
as.walkers = walkersStrenght / totalStrenght;
|
as.walkers = walkersStrenght / totalStrenght;
|
||||||
|
@ -19,7 +19,6 @@ extern boost::thread_specific_ptr<CCallback> cb;
|
|||||||
extern boost::thread_specific_ptr<VCAI> ai;
|
extern boost::thread_specific_ptr<VCAI> ai;
|
||||||
extern FuzzyHelper * fh; //TODO: this logic should be moved inside VCAI
|
extern FuzzyHelper * fh; //TODO: this logic should be moved inside VCAI
|
||||||
|
|
||||||
using namespace vstd;
|
|
||||||
using namespace Goals;
|
using namespace Goals;
|
||||||
|
|
||||||
TSubgoal Goals::sptr(const AbstractGoal & tmp)
|
TSubgoal Goals::sptr(const AbstractGoal & tmp)
|
||||||
@ -575,7 +574,7 @@ TGoalVec Explore::getAllPossibleSubgoals()
|
|||||||
{
|
{
|
||||||
//heroes = ai->getUnblockedHeroes();
|
//heroes = ai->getUnblockedHeroes();
|
||||||
heroes = cb->getHeroesInfo();
|
heroes = cb->getHeroesInfo();
|
||||||
erase_if (heroes, [](const HeroPtr h)
|
vstd::erase_if(heroes, [](const HeroPtr h)
|
||||||
{
|
{
|
||||||
if (ai->getGoal(h)->goalType == Goals::EXPLORE) //do not reassign hero who is already explorer
|
if (ai->getGoal(h)->goalType == Goals::EXPLORE) //do not reassign hero who is already explorer
|
||||||
return true;
|
return true;
|
||||||
@ -747,10 +746,10 @@ TGoalVec VisitTile::getAllPossibleSubgoals()
|
|||||||
if (ai->canRecruitAnyHero())
|
if (ai->canRecruitAnyHero())
|
||||||
ret.push_back (sptr(Goals::RecruitHero()));
|
ret.push_back (sptr(Goals::RecruitHero()));
|
||||||
}
|
}
|
||||||
if (ret.empty())
|
if(ret.empty())
|
||||||
{
|
{
|
||||||
auto obj = frontOrNull(cb->getVisitableObjs(tile));
|
auto obj = vstd::frontOrNull(cb->getVisitableObjs(tile));
|
||||||
if (obj && obj->ID == Obj::HERO && obj->tempOwner == ai->playerID) //our own hero stands on that tile
|
if(obj && obj->ID == Obj::HERO && obj->tempOwner == ai->playerID) //our own hero stands on that tile
|
||||||
{
|
{
|
||||||
if (hero.get(true) && hero->id == obj->id) //if it's assigned hero, visit tile. If it's different hero, we can't visit tile now
|
if (hero.get(true) && hero->id == obj->id) //if it's assigned hero, visit tile. If it's different hero, we can't visit tile now
|
||||||
ret.push_back(sptr(Goals::VisitTile(tile).sethero(dynamic_cast<const CGHeroInstance *>(obj)).setisElementar(true)));
|
ret.push_back(sptr(Goals::VisitTile(tile).sethero(dynamic_cast<const CGHeroInstance *>(obj)).setisElementar(true)));
|
||||||
@ -767,7 +766,7 @@ TGoalVec VisitTile::getAllPossibleSubgoals()
|
|||||||
|
|
||||||
TSubgoal DigAtTile::whatToDoToAchieve()
|
TSubgoal DigAtTile::whatToDoToAchieve()
|
||||||
{
|
{
|
||||||
const CGObjectInstance *firstObj = frontOrNull(cb->getVisitableObjs(tile));
|
const CGObjectInstance *firstObj = vstd::frontOrNull(cb->getVisitableObjs(tile));
|
||||||
if(firstObj && firstObj->ID == Obj::HERO && firstObj->tempOwner == ai->playerID) //we have hero at dest
|
if(firstObj && firstObj->ID == Obj::HERO && firstObj->tempOwner == ai->playerID) //we have hero at dest
|
||||||
{
|
{
|
||||||
const CGHeroInstance *h = dynamic_cast<const CGHeroInstance *>(firstObj);
|
const CGHeroInstance *h = dynamic_cast<const CGHeroInstance *>(firstObj);
|
||||||
@ -1057,7 +1056,7 @@ TGoalVec GatherArmy::getAllPossibleSubgoals()
|
|||||||
|
|
||||||
auto otherHeroes = cb->getHeroesInfo();
|
auto otherHeroes = cb->getHeroesInfo();
|
||||||
auto heroDummy = hero;
|
auto heroDummy = hero;
|
||||||
erase_if(otherHeroes, [heroDummy](const CGHeroInstance * h)
|
vstd::erase_if(otherHeroes, [heroDummy](const CGHeroInstance * h)
|
||||||
{
|
{
|
||||||
return (h == heroDummy.h || !ai->isAccessibleForHero(heroDummy->visitablePos(), h, true)
|
return (h == heroDummy.h || !ai->isAccessibleForHero(heroDummy->visitablePos(), h, true)
|
||||||
|| !ai->canGetArmy(heroDummy.h, h) || ai->getGoal(h)->goalType == Goals::GATHER_ARMY);
|
|| !ai->canGetArmy(heroDummy.h, h) || ai->getGoal(h)->goalType == Goals::GATHER_ARMY);
|
||||||
|
@ -29,8 +29,6 @@ class CGVisitableOPW;
|
|||||||
const double SAFE_ATTACK_CONSTANT = 1.5;
|
const double SAFE_ATTACK_CONSTANT = 1.5;
|
||||||
const int GOLD_RESERVE = 10000; //when buying creatures we want to keep at least this much gold (10000 so at least we'll be able to reach capitol)
|
const int GOLD_RESERVE = 10000; //when buying creatures we want to keep at least this much gold (10000 so at least we'll be able to reach capitol)
|
||||||
|
|
||||||
using namespace vstd;
|
|
||||||
|
|
||||||
//one thread may be turn of AI and another will be handling a side effect for AI2
|
//one thread may be turn of AI and another will be handling a side effect for AI2
|
||||||
boost::thread_specific_ptr<CCallback> cb;
|
boost::thread_specific_ptr<CCallback> cb;
|
||||||
boost::thread_specific_ptr<VCAI> ai;
|
boost::thread_specific_ptr<VCAI> ai;
|
||||||
@ -124,8 +122,8 @@ void VCAI::heroMoved(const TryMoveHero & details)
|
|||||||
{
|
{
|
||||||
const int3 from = CGHeroInstance::convertPosition(details.start, false),
|
const int3 from = CGHeroInstance::convertPosition(details.start, false),
|
||||||
to = CGHeroInstance::convertPosition(details.end, false);
|
to = CGHeroInstance::convertPosition(details.end, false);
|
||||||
const CGObjectInstance *o1 = frontOrNull(cb->getVisitableObjs(from)),
|
const CGObjectInstance *o1 = vstd::frontOrNull(cb->getVisitableObjs(from)),
|
||||||
*o2 = frontOrNull(cb->getVisitableObjs(to));
|
*o2 = vstd::frontOrNull(cb->getVisitableObjs(to));
|
||||||
|
|
||||||
auto t1 = dynamic_cast<const CGTeleport *>(o1);
|
auto t1 = dynamic_cast<const CGTeleport *>(o1);
|
||||||
auto t2 = dynamic_cast<const CGTeleport *>(o2);
|
auto t2 = dynamic_cast<const CGTeleport *>(o2);
|
||||||
@ -394,8 +392,8 @@ void VCAI::objectRemoved(const CGObjectInstance *obj)
|
|||||||
LOG_TRACE(logAi);
|
LOG_TRACE(logAi);
|
||||||
NET_EVENT_HANDLER;
|
NET_EVENT_HANDLER;
|
||||||
|
|
||||||
erase_if_present(visitableObjs, obj);
|
vstd::erase_if_present(visitableObjs, obj);
|
||||||
erase_if_present(alreadyVisited, obj);
|
vstd::erase_if_present(alreadyVisited, obj);
|
||||||
|
|
||||||
for (auto h : cb->getHeroesInfo())
|
for (auto h : cb->getHeroesInfo())
|
||||||
unreserveObject(h, obj);
|
unreserveObject(h, obj);
|
||||||
@ -518,15 +516,15 @@ void VCAI::objectPropertyChanged(const SetObjectProperty * sop)
|
|||||||
{
|
{
|
||||||
//we don't want to visit know object twice (do we really?)
|
//we don't want to visit know object twice (do we really?)
|
||||||
if(sop->val == playerID.getNum())
|
if(sop->val == playerID.getNum())
|
||||||
erase_if_present(visitableObjs, myCb->getObj(sop->id));
|
vstd::erase_if_present(visitableObjs, myCb->getObj(sop->id));
|
||||||
else if (myCb->getPlayerRelations(playerID, (PlayerColor)sop->val) == PlayerRelations::ENEMIES)
|
else if(myCb->getPlayerRelations(playerID, (PlayerColor)sop->val) == PlayerRelations::ENEMIES)
|
||||||
{
|
{
|
||||||
//we want to visit objects owned by oppponents
|
//we want to visit objects owned by oppponents
|
||||||
auto obj = myCb->getObj(sop->id, false);
|
auto obj = myCb->getObj(sop->id, false);
|
||||||
if (obj)
|
if (obj)
|
||||||
{
|
{
|
||||||
addVisitableObj(obj);
|
addVisitableObj(obj);
|
||||||
erase_if_present(alreadyVisited, obj);
|
vstd::erase_if_present(alreadyVisited, obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -738,7 +736,7 @@ void VCAI::makeTurn()
|
|||||||
if (isWeeklyRevisitable(obj))
|
if (isWeeklyRevisitable(obj))
|
||||||
{
|
{
|
||||||
addVisitableObj(obj);
|
addVisitableObj(obj);
|
||||||
erase_if_present (alreadyVisited, obj);
|
vstd::erase_if_present(alreadyVisited, obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1121,7 +1119,7 @@ void VCAI::recruitCreatures(const CGDwelling * d, const CArmedInstance * recruit
|
|||||||
// if(containsSavedRes(c->cost))
|
// if(containsSavedRes(c->cost))
|
||||||
// continue;
|
// continue;
|
||||||
|
|
||||||
amin(count, freeResources() / VLC->creh->creatures[creID]->cost);
|
vstd::amin(count, freeResources() / VLC->creh->creatures[creID]->cost);
|
||||||
if(count > 0)
|
if(count > 0)
|
||||||
cb->recruitCreatures(d, recruiter, creID, count, i);
|
cb->recruitCreatures(d, recruiter, creID, count, i);
|
||||||
}
|
}
|
||||||
@ -1484,7 +1482,7 @@ void VCAI::wander(HeroPtr h)
|
|||||||
}
|
}
|
||||||
|
|
||||||
range::copy(getPossibleDestinations(h), std::back_inserter(dests));
|
range::copy(getPossibleDestinations(h), std::back_inserter(dests));
|
||||||
erase_if(dests, [&](ObjectIdRef obj) -> bool
|
vstd::erase_if(dests, [&](ObjectIdRef obj) -> bool
|
||||||
{
|
{
|
||||||
return !isSafeToVisit(h, sm->firstTileToGet(h, obj->visitablePos()));
|
return !isSafeToVisit(h, sm->firstTileToGet(h, obj->visitablePos()));
|
||||||
});
|
});
|
||||||
@ -1536,7 +1534,7 @@ void VCAI::wander(HeroPtr h)
|
|||||||
else if(cb->getResourceAmount(Res::GOLD) >= GameConstants::HERO_GOLD_COST)
|
else if(cb->getResourceAmount(Res::GOLD) >= GameConstants::HERO_GOLD_COST)
|
||||||
{
|
{
|
||||||
std::vector<const CGTownInstance *> towns = cb->getTownsInfo();
|
std::vector<const CGTownInstance *> towns = cb->getTownsInfo();
|
||||||
erase_if(towns, [](const CGTownInstance *t) -> bool
|
vstd::erase_if(towns, [](const CGTownInstance *t) -> bool
|
||||||
{
|
{
|
||||||
for(const CGHeroInstance *h : cb->getHeroesInfo())
|
for(const CGHeroInstance *h : cb->getHeroesInfo())
|
||||||
if(!t->getArmyStrength() || howManyReinforcementsCanGet(h, t))
|
if(!t->getArmyStrength() || howManyReinforcementsCanGet(h, t))
|
||||||
@ -1587,8 +1585,8 @@ void VCAI::wander(HeroPtr h)
|
|||||||
|
|
||||||
void VCAI::setGoal(HeroPtr h, Goals::TSubgoal goal)
|
void VCAI::setGoal(HeroPtr h, Goals::TSubgoal goal)
|
||||||
{ //TODO: check for presence?
|
{ //TODO: check for presence?
|
||||||
if (goal->invalid())
|
if(goal->invalid())
|
||||||
erase_if_present(lockedHeroes, h);
|
vstd::erase_if_present(lockedHeroes, h);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lockedHeroes[h] = goal;
|
lockedHeroes[h] = goal;
|
||||||
@ -1629,7 +1627,7 @@ void VCAI::battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int
|
|||||||
NET_EVENT_HANDLER;
|
NET_EVENT_HANDLER;
|
||||||
assert(playerID > PlayerColor::PLAYER_LIMIT || status.getBattle() == UPCOMING_BATTLE);
|
assert(playerID > PlayerColor::PLAYER_LIMIT || status.getBattle() == UPCOMING_BATTLE);
|
||||||
status.setBattle(ONGOING_BATTLE);
|
status.setBattle(ONGOING_BATTLE);
|
||||||
const CGObjectInstance *presumedEnemy = backOrNull(cb->getVisitableObjs(tile)); //may be nullptr in some very are cases -> eg. visited monolith and fighting with an enemy at the FoW covered exit
|
const CGObjectInstance *presumedEnemy = vstd::backOrNull(cb->getVisitableObjs(tile)); //may be nullptr in some very are cases -> eg. visited monolith and fighting with an enemy at the FoW covered exit
|
||||||
battlename = boost::str(boost::format("Starting battle of %s attacking %s at %s") % (hero1 ? hero1->name : "a army") % (presumedEnemy ? presumedEnemy->getObjectName() : "unknown enemy") % tile);
|
battlename = boost::str(boost::format("Starting battle of %s attacking %s at %s") % (hero1 ? hero1->name : "a army") % (presumedEnemy ? presumedEnemy->getObjectName() : "unknown enemy") % tile);
|
||||||
CAdventureAI::battleStart(army1, army2, tile, hero1, hero2, side);
|
CAdventureAI::battleStart(army1, army2, tile, hero1, hero2, side);
|
||||||
}
|
}
|
||||||
@ -1669,8 +1667,8 @@ void VCAI::reserveObject(HeroPtr h, const CGObjectInstance *obj)
|
|||||||
|
|
||||||
void VCAI::unreserveObject(HeroPtr h, const CGObjectInstance *obj)
|
void VCAI::unreserveObject(HeroPtr h, const CGObjectInstance *obj)
|
||||||
{
|
{
|
||||||
erase_if_present(reservedObjs, obj); //unreserve objects
|
vstd::erase_if_present(reservedObjs, obj); //unreserve objects
|
||||||
erase_if_present(reservedHeroesMap[h], obj);
|
vstd::erase_if_present(reservedHeroesMap[h], obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VCAI::markHeroUnableToExplore (HeroPtr h)
|
void VCAI::markHeroUnableToExplore (HeroPtr h)
|
||||||
@ -1679,7 +1677,7 @@ void VCAI::markHeroUnableToExplore (HeroPtr h)
|
|||||||
}
|
}
|
||||||
void VCAI::markHeroAbleToExplore (HeroPtr h)
|
void VCAI::markHeroAbleToExplore (HeroPtr h)
|
||||||
{
|
{
|
||||||
erase_if_present(heroesUnableToExplore, h);
|
vstd::erase_if_present(heroesUnableToExplore, h);
|
||||||
}
|
}
|
||||||
bool VCAI::isAbleToExplore (HeroPtr h)
|
bool VCAI::isAbleToExplore (HeroPtr h)
|
||||||
{
|
{
|
||||||
@ -1716,25 +1714,25 @@ void VCAI::validateVisitableObjs()
|
|||||||
|
|
||||||
//errorMsg is captured by ref so lambda will take the new text
|
//errorMsg is captured by ref so lambda will take the new text
|
||||||
errorMsg = " shouldn't be on the visitable objects list!";
|
errorMsg = " shouldn't be on the visitable objects list!";
|
||||||
erase_if(visitableObjs, shouldBeErased);
|
vstd::erase_if(visitableObjs, shouldBeErased);
|
||||||
|
|
||||||
//FIXME: how comes our own heroes become inaccessible?
|
//FIXME: how comes our own heroes become inaccessible?
|
||||||
erase_if(reservedHeroesMap, [](std::pair<HeroPtr, std::set<const CGObjectInstance *>> hp) -> bool
|
vstd::erase_if(reservedHeroesMap, [](std::pair<HeroPtr, std::set<const CGObjectInstance *>> hp) -> bool
|
||||||
{
|
{
|
||||||
return !hp.first.get(true);
|
return !hp.first.get(true);
|
||||||
});
|
});
|
||||||
for(auto &p : reservedHeroesMap)
|
for(auto &p : reservedHeroesMap)
|
||||||
{
|
{
|
||||||
errorMsg = " shouldn't be on list for hero " + p.first->name + "!";
|
errorMsg = " shouldn't be on list for hero " + p.first->name + "!";
|
||||||
erase_if(p.second, shouldBeErased);
|
vstd::erase_if(p.second, shouldBeErased);
|
||||||
}
|
}
|
||||||
|
|
||||||
errorMsg = " shouldn't be on the reserved objs list!";
|
errorMsg = " shouldn't be on the reserved objs list!";
|
||||||
erase_if(reservedObjs, shouldBeErased);
|
vstd::erase_if(reservedObjs, shouldBeErased);
|
||||||
|
|
||||||
//TODO overkill, hidden object should not be removed. However, we can't know if hidden object is erased from game.
|
//TODO overkill, hidden object should not be removed. However, we can't know if hidden object is erased from game.
|
||||||
errorMsg = " shouldn't be on the already visited objs list!";
|
errorMsg = " shouldn't be on the already visited objs list!";
|
||||||
erase_if(alreadyVisited, shouldBeErased);
|
vstd::erase_if(alreadyVisited, shouldBeErased);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VCAI::retreiveVisitableObjs(std::vector<const CGObjectInstance *> &out, bool includeOwned /*= false*/) const
|
void VCAI::retreiveVisitableObjs(std::vector<const CGObjectInstance *> &out, bool includeOwned /*= false*/) const
|
||||||
@ -1765,7 +1763,7 @@ std::vector<const CGObjectInstance *> VCAI::getFlaggedObjects() const
|
|||||||
{
|
{
|
||||||
std::vector<const CGObjectInstance *> ret;
|
std::vector<const CGObjectInstance *> ret;
|
||||||
retreiveVisitableObjs(ret, true);
|
retreiveVisitableObjs(ret, true);
|
||||||
erase_if(ret, [](const CGObjectInstance *obj)
|
vstd::erase_if(ret, [](const CGObjectInstance *obj)
|
||||||
{
|
{
|
||||||
return obj->tempOwner != ai->playerID;
|
return obj->tempOwner != ai->playerID;
|
||||||
});
|
});
|
||||||
@ -1993,7 +1991,7 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr h)
|
|||||||
}
|
}
|
||||||
if (h)
|
if (h)
|
||||||
{
|
{
|
||||||
if (auto visitedObject = frontOrNull(cb->getVisitableObjs(h->visitablePos()))) //we stand on something interesting
|
if(auto visitedObject = vstd::frontOrNull(cb->getVisitableObjs(h->visitablePos()))) //we stand on something interesting
|
||||||
{
|
{
|
||||||
if (visitedObject != *h)
|
if (visitedObject != *h)
|
||||||
performObjectInteraction (visitedObject, h);
|
performObjectInteraction (visitedObject, h);
|
||||||
@ -2004,16 +2002,16 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr h)
|
|||||||
completeGoal (sptr(Goals::VisitTile(dst).sethero(h))); //we stepped on some tile, anyway
|
completeGoal (sptr(Goals::VisitTile(dst).sethero(h))); //we stepped on some tile, anyway
|
||||||
completeGoal (sptr(Goals::ClearWayTo(dst).sethero(h)));
|
completeGoal (sptr(Goals::ClearWayTo(dst).sethero(h)));
|
||||||
|
|
||||||
if (!ret) //reserve object we are heading towards
|
if(!ret) //reserve object we are heading towards
|
||||||
{
|
{
|
||||||
auto obj = frontOrNull(cb->getVisitableObjs(dst));
|
auto obj = vstd::frontOrNull(cb->getVisitableObjs(dst));
|
||||||
if (obj && obj != *h)
|
if(obj && obj != *h)
|
||||||
reserveObject(h, obj);
|
reserveObject(h, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startHpos == h->visitablePos() && !ret) //we didn't move and didn't reach the target
|
if(startHpos == h->visitablePos() && !ret) //we didn't move and didn't reach the target
|
||||||
{
|
{
|
||||||
erase_if_present (lockedHeroes, h); //hero seemingly is confused
|
vstd::erase_if_present(lockedHeroes, h); //hero seemingly is confused
|
||||||
throw cannotFulfillGoalException("Invalid path found!"); //FIXME: should never happen
|
throw cannotFulfillGoalException("Invalid path found!"); //FIXME: should never happen
|
||||||
}
|
}
|
||||||
logAi->debugStream() << boost::format("Hero %s moved from %s to %s. Returning %d.") % h->name % startHpos % h->visitablePos() % ret;
|
logAi->debugStream() << boost::format("Hero %s moved from %s to %s. Returning %d.") % h->name % startHpos % h->visitablePos() % ret;
|
||||||
@ -2320,7 +2318,7 @@ Goals::TSubgoal VCAI::striveToGoalInternal(Goals::TSubgoal ultimateGoal, bool on
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
erase_if_present (lockedHeroes, goal->hero); // we seemingly don't know what to do with hero
|
vstd::erase_if_present (lockedHeroes, goal->hero); // we seemingly don't know what to do with hero
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2575,7 +2573,7 @@ int3 VCAI::explorationNewPoint(HeroPtr h)
|
|||||||
for (int i = 1; i < radius; i++)
|
for (int i = 1; i < radius; i++)
|
||||||
{
|
{
|
||||||
getVisibleNeighbours(tiles[i-1], tiles[i]);
|
getVisibleNeighbours(tiles[i-1], tiles[i]);
|
||||||
removeDuplicates(tiles[i]);
|
vstd::removeDuplicates(tiles[i]);
|
||||||
|
|
||||||
for(const int3 &tile : tiles[i])
|
for(const int3 &tile : tiles[i])
|
||||||
{
|
{
|
||||||
@ -2620,10 +2618,10 @@ int3 VCAI::explorationDesperate(HeroPtr h)
|
|||||||
ui64 lowestDanger = -1;
|
ui64 lowestDanger = -1;
|
||||||
int3 bestTile(-1,-1,-1);
|
int3 bestTile(-1,-1,-1);
|
||||||
|
|
||||||
for (int i = 1; i < radius; i++)
|
for(int i = 1; i < radius; i++)
|
||||||
{
|
{
|
||||||
getVisibleNeighbours(tiles[i-1], tiles[i]);
|
getVisibleNeighbours(tiles[i-1], tiles[i]);
|
||||||
removeDuplicates(tiles[i]);
|
vstd::removeDuplicates(tiles[i]);
|
||||||
|
|
||||||
for(const int3 &tile : tiles[i])
|
for(const int3 &tile : tiles[i])
|
||||||
{
|
{
|
||||||
@ -2748,13 +2746,13 @@ void VCAI::lostHero(HeroPtr h)
|
|||||||
{
|
{
|
||||||
logAi->debugStream() << boost::format("I lost my hero %s. It's best to forget and move on.") % h.name;
|
logAi->debugStream() << boost::format("I lost my hero %s. It's best to forget and move on.") % h.name;
|
||||||
|
|
||||||
erase_if_present(lockedHeroes, h);
|
vstd::erase_if_present(lockedHeroes, h);
|
||||||
for(auto obj : reservedHeroesMap[h])
|
for(auto obj : reservedHeroesMap[h])
|
||||||
{
|
{
|
||||||
erase_if_present(reservedObjs, obj); //unreserve all objects for that hero
|
vstd::erase_if_present(reservedObjs, obj); //unreserve all objects for that hero
|
||||||
}
|
}
|
||||||
erase_if_present(reservedHeroesMap, h);
|
vstd::erase_if_present(reservedHeroesMap, h);
|
||||||
erase_if_present(cachedSectorMaps, h);
|
vstd::erase_if_present(cachedSectorMaps, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VCAI::answerQuery(QueryID queryID, int selection)
|
void VCAI::answerQuery(QueryID queryID, int selection)
|
||||||
@ -2795,15 +2793,15 @@ void VCAI::validateObject(const CGObjectInstance *obj)
|
|||||||
|
|
||||||
void VCAI::validateObject(ObjectIdRef obj)
|
void VCAI::validateObject(ObjectIdRef obj)
|
||||||
{
|
{
|
||||||
auto matchesId = [&] (const CGObjectInstance *hlpObj) -> bool { return hlpObj->id == obj.id; };
|
auto matchesId = [&](const CGObjectInstance *hlpObj) -> bool { return hlpObj->id == obj.id; };
|
||||||
if(!obj)
|
if(!obj)
|
||||||
{
|
{
|
||||||
erase_if(visitableObjs, matchesId);
|
vstd::erase_if(visitableObjs, matchesId);
|
||||||
|
|
||||||
for(auto &p : reservedHeroesMap)
|
for(auto &p : reservedHeroesMap)
|
||||||
erase_if(p.second, matchesId);
|
vstd::erase_if(p.second, matchesId);
|
||||||
|
|
||||||
erase_if(reservedObjs, matchesId);
|
vstd::erase_if(reservedObjs, matchesId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3081,7 +3079,7 @@ void SectorMap::exploreNewSector(crint3 pos, int num, CCallback * cbp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
removeDuplicates(s.embarkmentPoints);
|
vstd::removeDuplicates(s.embarkmentPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SectorMap::write(crstring fname)
|
void SectorMap::write(crstring fname)
|
||||||
|
@ -55,7 +55,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define ADVOPT (conf.go()->ac)
|
#define ADVOPT (conf.go()->ac)
|
||||||
using namespace boost::logic;
|
|
||||||
using namespace CSDL_Ext;
|
using namespace CSDL_Ext;
|
||||||
|
|
||||||
CAdvMapInt *adventureInt;
|
CAdvMapInt *adventureInt;
|
||||||
|
@ -201,9 +201,7 @@ void BattleInfo::localInitStack(CStack * s)
|
|||||||
|
|
||||||
namespace CGH
|
namespace CGH
|
||||||
{
|
{
|
||||||
using namespace std;
|
static void readBattlePositions(const JsonNode &node, std::vector< std::vector<int> > & dest)
|
||||||
|
|
||||||
static void readBattlePositions(const JsonNode &node, vector< vector<int> > & dest)
|
|
||||||
{
|
{
|
||||||
for(const JsonNode &level : node.Vector())
|
for(const JsonNode &level : node.Vector())
|
||||||
{
|
{
|
||||||
|
@ -17,9 +17,6 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using namespace boost;
|
|
||||||
using namespace boost::asio::ip;
|
|
||||||
|
|
||||||
extern template void registerTypes<CISer>(CISer & s);
|
extern template void registerTypes<CISer>(CISer & s);
|
||||||
extern template void registerTypes<COSer>(COSer & s);
|
extern template void registerTypes<COSer>(COSer & s);
|
||||||
extern template void registerTypes<CTypeList>(CTypeList & s);
|
extern template void registerTypes<CTypeList>(CTypeList & s);
|
||||||
@ -70,13 +67,13 @@ void CConnection::init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
CConnection::CConnection(std::string host, std::string port, std::string Name)
|
CConnection::CConnection(std::string host, std::string port, std::string Name)
|
||||||
:iser(this), oser(this), io_service(new asio::io_service), name(Name)
|
:iser(this), oser(this), io_service(new boost::asio::io_service), name(Name)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
boost::system::error_code error = asio::error::host_not_found;
|
boost::system::error_code error = boost::asio::error::host_not_found;
|
||||||
socket = new tcp::socket(*io_service);
|
socket = new boost::asio::ip::tcp::socket(*io_service);
|
||||||
tcp::resolver resolver(*io_service);
|
boost::asio::ip::tcp::resolver resolver(*io_service);
|
||||||
tcp::resolver::iterator end, pom, endpoint_iterator = resolver.resolve(tcp::resolver::query(host,port),error);
|
boost::asio::ip::tcp::resolver::iterator end, pom, endpoint_iterator = resolver.resolve(boost::asio::ip::tcp::resolver::query(host,port),error);
|
||||||
if(error)
|
if(error)
|
||||||
{
|
{
|
||||||
logNetwork->errorStream() << "Problem with resolving: \n" << error;
|
logNetwork->errorStream() << "Problem with resolving: \n" << error;
|
||||||
@ -132,8 +129,8 @@ CConnection::CConnection(TSocket * Socket, std::string Name )
|
|||||||
CConnection::CConnection(TAcceptor * acceptor, boost::asio::io_service *Io_service, std::string Name)
|
CConnection::CConnection(TAcceptor * acceptor, boost::asio::io_service *Io_service, std::string Name)
|
||||||
: iser(this), oser(this), name(Name)//, send(this), rec(this)
|
: iser(this), oser(this), name(Name)//, send(this), rec(this)
|
||||||
{
|
{
|
||||||
boost::system::error_code error = asio::error::host_not_found;
|
boost::system::error_code error = boost::asio::error::host_not_found;
|
||||||
socket = new tcp::socket(*io_service);
|
socket = new boost::asio::ip::tcp::socket(*io_service);
|
||||||
acceptor->accept(*socket,error);
|
acceptor->accept(*socket,error);
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
@ -149,7 +146,7 @@ int CConnection::write(const void * data, unsigned size)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
ret = asio::write(*socket,asio::const_buffers_1(asio::const_buffer(data,size)));
|
ret = boost::asio::write(*socket,boost::asio::const_buffers_1(boost::asio::const_buffer(data,size)));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
@ -164,7 +161,7 @@ int CConnection::read(void * data, unsigned size)
|
|||||||
//LOG("Receiving " << size << " byte(s) of data" <<std::endl);
|
//LOG("Receiving " << size << " byte(s) of data" <<std::endl);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int ret = asio::read(*socket,asio::mutable_buffers_1(asio::mutable_buffer(data,size)));
|
int ret = boost::asio::read(*socket,boost::asio::mutable_buffers_1(boost::asio::mutable_buffer(data,size)));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
|
@ -38,9 +38,6 @@
|
|||||||
|
|
||||||
std::string NAME_AFFIX = "server";
|
std::string NAME_AFFIX = "server";
|
||||||
std::string NAME = GameConstants::VCMI_VERSION + std::string(" (") + NAME_AFFIX + ')'; //application name
|
std::string NAME = GameConstants::VCMI_VERSION + std::string(" (") + NAME_AFFIX + ')'; //application name
|
||||||
using namespace boost;
|
|
||||||
using namespace boost::asio;
|
|
||||||
using namespace boost::asio::ip;
|
|
||||||
#ifndef VCMI_ANDROID
|
#ifndef VCMI_ANDROID
|
||||||
namespace intpr = boost::interprocess;
|
namespace intpr = boost::interprocess;
|
||||||
#endif
|
#endif
|
||||||
@ -59,7 +56,7 @@ boost::program_options::variables_map cmdLineOptions;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void vaccept(tcp::acceptor *ac, tcp::socket *s, boost::system::error_code *error)
|
static void vaccept(boost::asio::ip::tcp::acceptor *ac, boost::asio::ip::tcp::socket *s, boost::system::error_code *error)
|
||||||
{
|
{
|
||||||
ac->accept(*s,*error);
|
ac->accept(*s,*error);
|
||||||
}
|
}
|
||||||
@ -314,7 +311,7 @@ void CPregameServer::startListeningThread(CConnection * pc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CVCMIServer::CVCMIServer()
|
CVCMIServer::CVCMIServer()
|
||||||
: io(new boost::asio::io_service()), acceptor(new TAcceptor(*io, tcp::endpoint(tcp::v4(), port))), firstConnection(nullptr)
|
: io(new boost::asio::io_service()), acceptor(new TAcceptor(*io, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port))), firstConnection(nullptr)
|
||||||
{
|
{
|
||||||
logNetwork->debugStream() << "CVCMIServer created!";
|
logNetwork->debugStream() << "CVCMIServer created!";
|
||||||
}
|
}
|
||||||
@ -414,7 +411,7 @@ void CVCMIServer::start()
|
|||||||
|
|
||||||
boost::system::error_code error;
|
boost::system::error_code error;
|
||||||
logNetwork->infoStream()<<"Listening for connections at port " << acceptor->local_endpoint().port();
|
logNetwork->infoStream()<<"Listening for connections at port " << acceptor->local_endpoint().port();
|
||||||
auto s = new tcp::socket(acceptor->get_io_service());
|
auto s = new boost::asio::ip::tcp::socket(acceptor->get_io_service());
|
||||||
boost::thread acc(std::bind(vaccept,acceptor,s,&error));
|
boost::thread acc(std::bind(vaccept,acceptor,s,&error));
|
||||||
#ifndef VCMI_ANDROID
|
#ifndef VCMI_ANDROID
|
||||||
sr->setToTrueAndNotify();
|
sr->setToTrueAndNotify();
|
||||||
@ -499,7 +496,7 @@ void CVCMIServer::loadGame()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto s = new tcp::socket(acceptor->get_io_service());
|
auto s = new boost::asio::ip::tcp::socket(acceptor->get_io_service());
|
||||||
acceptor->accept(*s,error);
|
acceptor->accept(*s,error);
|
||||||
if(error) //retry
|
if(error) //retry
|
||||||
{
|
{
|
||||||
@ -610,7 +607,7 @@ int main(int argc, char** argv)
|
|||||||
srand ( (ui32)time(nullptr) );
|
srand ( (ui32)time(nullptr) );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
io_service io_service;
|
boost::asio::io_service io_service;
|
||||||
CVCMIServer server;
|
CVCMIServer server;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
Loading…
Reference in New Issue
Block a user