1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Refactoring: avoid using namespace when it's not absolutely needed

This commit is contained in:
Arseniy Shestakov 2015-12-29 02:14:08 +03:00
parent 6985e96f0d
commit 29a7934a99
7 changed files with 66 additions and 79 deletions

View File

@ -31,7 +31,6 @@ class Engine;
class InputVariable;
class CGTownInstance;
using namespace vstd;
//using namespace Goals;
FuzzyHelper *fh;
@ -85,7 +84,7 @@ armyStructure evaluateArmyStructure (const CArmedInstance * army)
if (walker)
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;
as.walkers = walkersStrenght / totalStrenght;

View File

@ -19,7 +19,6 @@ extern boost::thread_specific_ptr<CCallback> cb;
extern boost::thread_specific_ptr<VCAI> ai;
extern FuzzyHelper * fh; //TODO: this logic should be moved inside VCAI
using namespace vstd;
using namespace Goals;
TSubgoal Goals::sptr(const AbstractGoal & tmp)
@ -575,7 +574,7 @@ TGoalVec Explore::getAllPossibleSubgoals()
{
//heroes = ai->getUnblockedHeroes();
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
return true;
@ -747,10 +746,10 @@ TGoalVec VisitTile::getAllPossibleSubgoals()
if (ai->canRecruitAnyHero())
ret.push_back (sptr(Goals::RecruitHero()));
}
if (ret.empty())
if(ret.empty())
{
auto obj = frontOrNull(cb->getVisitableObjs(tile));
if (obj && obj->ID == Obj::HERO && obj->tempOwner == ai->playerID) //our own hero stands on that 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 (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)));
@ -767,7 +766,7 @@ TGoalVec VisitTile::getAllPossibleSubgoals()
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
{
const CGHeroInstance *h = dynamic_cast<const CGHeroInstance *>(firstObj);
@ -1057,7 +1056,7 @@ TGoalVec GatherArmy::getAllPossibleSubgoals()
auto otherHeroes = cb->getHeroesInfo();
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)
|| !ai->canGetArmy(heroDummy.h, h) || ai->getGoal(h)->goalType == Goals::GATHER_ARMY);

View File

@ -29,8 +29,6 @@ class CGVisitableOPW;
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)
using namespace vstd;
//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<VCAI> ai;
@ -124,8 +122,8 @@ void VCAI::heroMoved(const TryMoveHero & details)
{
const int3 from = CGHeroInstance::convertPosition(details.start, false),
to = CGHeroInstance::convertPosition(details.end, false);
const CGObjectInstance *o1 = frontOrNull(cb->getVisitableObjs(from)),
*o2 = frontOrNull(cb->getVisitableObjs(to));
const CGObjectInstance *o1 = vstd::frontOrNull(cb->getVisitableObjs(from)),
*o2 = vstd::frontOrNull(cb->getVisitableObjs(to));
auto t1 = dynamic_cast<const CGTeleport *>(o1);
auto t2 = dynamic_cast<const CGTeleport *>(o2);
@ -394,8 +392,8 @@ void VCAI::objectRemoved(const CGObjectInstance *obj)
LOG_TRACE(logAi);
NET_EVENT_HANDLER;
erase_if_present(visitableObjs, obj);
erase_if_present(alreadyVisited, obj);
vstd::erase_if_present(visitableObjs, obj);
vstd::erase_if_present(alreadyVisited, obj);
for (auto h : cb->getHeroesInfo())
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?)
if(sop->val == playerID.getNum())
erase_if_present(visitableObjs, myCb->getObj(sop->id));
else if (myCb->getPlayerRelations(playerID, (PlayerColor)sop->val) == PlayerRelations::ENEMIES)
vstd::erase_if_present(visitableObjs, myCb->getObj(sop->id));
else if(myCb->getPlayerRelations(playerID, (PlayerColor)sop->val) == PlayerRelations::ENEMIES)
{
//we want to visit objects owned by oppponents
auto obj = myCb->getObj(sop->id, false);
if (obj)
{
addVisitableObj(obj);
erase_if_present(alreadyVisited, obj);
vstd::erase_if_present(alreadyVisited, obj);
}
}
}
@ -738,7 +736,7 @@ void VCAI::makeTurn()
if (isWeeklyRevisitable(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))
// continue;
amin(count, freeResources() / VLC->creh->creatures[creID]->cost);
vstd::amin(count, freeResources() / VLC->creh->creatures[creID]->cost);
if(count > 0)
cb->recruitCreatures(d, recruiter, creID, count, i);
}
@ -1484,7 +1482,7 @@ void VCAI::wander(HeroPtr h)
}
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()));
});
@ -1536,7 +1534,7 @@ void VCAI::wander(HeroPtr h)
else if(cb->getResourceAmount(Res::GOLD) >= GameConstants::HERO_GOLD_COST)
{
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())
if(!t->getArmyStrength() || howManyReinforcementsCanGet(h, t))
@ -1587,8 +1585,8 @@ void VCAI::wander(HeroPtr h)
void VCAI::setGoal(HeroPtr h, Goals::TSubgoal goal)
{ //TODO: check for presence?
if (goal->invalid())
erase_if_present(lockedHeroes, h);
if(goal->invalid())
vstd::erase_if_present(lockedHeroes, h);
else
{
lockedHeroes[h] = goal;
@ -1629,7 +1627,7 @@ void VCAI::battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int
NET_EVENT_HANDLER;
assert(playerID > PlayerColor::PLAYER_LIMIT || status.getBattle() == UPCOMING_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);
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)
{
erase_if_present(reservedObjs, obj); //unreserve objects
erase_if_present(reservedHeroesMap[h], obj);
vstd::erase_if_present(reservedObjs, obj); //unreserve objects
vstd::erase_if_present(reservedHeroesMap[h], obj);
}
void VCAI::markHeroUnableToExplore (HeroPtr h)
@ -1679,7 +1677,7 @@ void VCAI::markHeroUnableToExplore (HeroPtr h)
}
void VCAI::markHeroAbleToExplore (HeroPtr h)
{
erase_if_present(heroesUnableToExplore, h);
vstd::erase_if_present(heroesUnableToExplore, 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 = " 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?
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);
});
for(auto &p : reservedHeroesMap)
{
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!";
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.
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
@ -1765,7 +1763,7 @@ std::vector<const CGObjectInstance *> VCAI::getFlaggedObjects() const
{
std::vector<const CGObjectInstance *> ret;
retreiveVisitableObjs(ret, true);
erase_if(ret, [](const CGObjectInstance *obj)
vstd::erase_if(ret, [](const CGObjectInstance *obj)
{
return obj->tempOwner != ai->playerID;
});
@ -1993,7 +1991,7 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr 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)
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::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));
if (obj && obj != *h)
auto obj = vstd::frontOrNull(cb->getVisitableObjs(dst));
if(obj && obj != *h)
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
}
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
{
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++)
{
getVisibleNeighbours(tiles[i-1], tiles[i]);
removeDuplicates(tiles[i]);
vstd::removeDuplicates(tiles[i]);
for(const int3 &tile : tiles[i])
{
@ -2620,10 +2618,10 @@ int3 VCAI::explorationDesperate(HeroPtr h)
ui64 lowestDanger = -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]);
removeDuplicates(tiles[i]);
vstd::removeDuplicates(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;
erase_if_present(lockedHeroes, h);
vstd::erase_if_present(lockedHeroes, 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);
erase_if_present(cachedSectorMaps, h);
vstd::erase_if_present(reservedHeroesMap, h);
vstd::erase_if_present(cachedSectorMaps, h);
}
void VCAI::answerQuery(QueryID queryID, int selection)
@ -2795,15 +2793,15 @@ void VCAI::validateObject(const CGObjectInstance *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)
{
erase_if(visitableObjs, matchesId);
vstd::erase_if(visitableObjs, matchesId);
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)

View File

@ -55,7 +55,6 @@
*/
#define ADVOPT (conf.go()->ac)
using namespace boost::logic;
using namespace CSDL_Ext;
CAdvMapInt *adventureInt;

View File

@ -201,9 +201,7 @@ void BattleInfo::localInitStack(CStack * s)
namespace CGH
{
using namespace std;
static void readBattlePositions(const JsonNode &node, vector< vector<int> > & dest)
static void readBattlePositions(const JsonNode &node, std::vector< std::vector<int> > & dest)
{
for(const JsonNode &level : node.Vector())
{

View File

@ -17,9 +17,6 @@
*
*/
using namespace boost;
using namespace boost::asio::ip;
extern template void registerTypes<CISer>(CISer & s);
extern template void registerTypes<COSer>(COSer & 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)
: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;
boost::system::error_code error = asio::error::host_not_found;
socket = new tcp::socket(*io_service);
tcp::resolver resolver(*io_service);
tcp::resolver::iterator end, pom, endpoint_iterator = resolver.resolve(tcp::resolver::query(host,port),error);
boost::system::error_code error = boost::asio::error::host_not_found;
socket = new boost::asio::ip::tcp::socket(*io_service);
boost::asio::ip::tcp::resolver resolver(*io_service);
boost::asio::ip::tcp::resolver::iterator end, pom, endpoint_iterator = resolver.resolve(boost::asio::ip::tcp::resolver::query(host,port),error);
if(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)
: iser(this), oser(this), name(Name)//, send(this), rec(this)
{
boost::system::error_code error = asio::error::host_not_found;
socket = new tcp::socket(*io_service);
boost::system::error_code error = boost::asio::error::host_not_found;
socket = new boost::asio::ip::tcp::socket(*io_service);
acceptor->accept(*socket,error);
if (error)
{
@ -149,7 +146,7 @@ int CConnection::write(const void * data, unsigned size)
try
{
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;
}
catch(...)
@ -164,7 +161,7 @@ int CConnection::read(void * data, unsigned size)
//LOG("Receiving " << size << " byte(s) of data" <<std::endl);
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;
}
catch(...)
@ -437,7 +434,7 @@ CTypeList::CTypeList()
}
CTypeList::TypeInfoPtr CTypeList::registerType( const std::type_info *type )
{
{
if(auto typeDescr = getTypeDescriptor(type, false))
return typeDescr; //type found, return ptr to structure
@ -451,7 +448,7 @@ CTypeList::TypeInfoPtr CTypeList::registerType( const std::type_info *type )
}
ui16 CTypeList::getTypeID( const std::type_info *type, bool throws ) const
{
{
auto descriptor = getTypeDescriptor(type, throws);
if (descriptor == nullptr)
{

View File

@ -38,9 +38,6 @@
std::string NAME_AFFIX = "server";
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
namespace intpr = boost::interprocess;
#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);
}
@ -314,7 +311,7 @@ void CPregameServer::startListeningThread(CConnection * pc)
}
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!";
}
@ -414,7 +411,7 @@ void CVCMIServer::start()
boost::system::error_code error;
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));
#ifndef VCMI_ANDROID
sr->setToTrueAndNotify();
@ -499,7 +496,7 @@ void CVCMIServer::loadGame()
}
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);
if(error) //retry
{
@ -610,7 +607,7 @@ int main(int argc, char** argv)
srand ( (ui32)time(nullptr) );
try
{
io_service io_service;
boost::asio::io_service io_service;
CVCMIServer server;
try