mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-14 02:33:51 +02:00
commit
4df16d525a
@ -2660,19 +2660,13 @@ void VCAI::finish()
|
||||
|
||||
void VCAI::requestActionASAP(std::function<void()> whatToDo)
|
||||
{
|
||||
// static boost::mutex m;
|
||||
// boost::unique_lock<boost::mutex> mylock(m);
|
||||
|
||||
boost::barrier b(2);
|
||||
boost::thread newThread([&b,this,whatToDo]()
|
||||
boost::thread newThread([this, whatToDo]()
|
||||
{
|
||||
setThreadName("VCAI::requestActionASAP::helper");
|
||||
setThreadName("VCAI::requestActionASAP::whatToDo");
|
||||
SET_GLOBAL_STATE(this);
|
||||
boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
|
||||
b.wait();
|
||||
whatToDo();
|
||||
});
|
||||
b.wait();
|
||||
}
|
||||
|
||||
void VCAI::lostHero(HeroPtr h)
|
||||
@ -3405,4 +3399,3 @@ unsigned char & SectorMap::retreiveTile(crint3 pos)
|
||||
{
|
||||
return retreiveTileN(sector, pos);
|
||||
}
|
||||
|
||||
|
@ -1534,7 +1534,9 @@ void CAdvMapInt::tileHovered(const int3 &mapPos)
|
||||
}
|
||||
else if(const CGHeroInstance *h = curHero())
|
||||
{
|
||||
const CGPathNode *pnode = LOCPLINT->cb->getPathsInfo(h)->getPathInfo(mapPos);
|
||||
int3 mapPosCopy = mapPos;
|
||||
const CGPathNode *pnode = LOCPLINT->cb->getPathsInfo(h)->getPathInfo(mapPosCopy);
|
||||
assert(pnode);
|
||||
|
||||
int turns = pnode->turns;
|
||||
vstd::amin(turns, 3);
|
||||
@ -1862,4 +1864,3 @@ void CAdvMapInt::WorldViewOptions::adjustDrawingInfo(MapDrawingInfo& info)
|
||||
|
||||
info.additionalIcons = &iconPositions;
|
||||
}
|
||||
|
||||
|
@ -2899,11 +2899,11 @@ bool CGPathNode::reachable() const
|
||||
return turns < 255;
|
||||
}
|
||||
|
||||
const CGPathNode * CPathsInfo::getPathInfo( int3 tile ) const
|
||||
const CGPathNode * CPathsInfo::getPathInfo( const int3& tile ) const
|
||||
{
|
||||
boost::unique_lock<boost::mutex> pathLock(pathMx);
|
||||
|
||||
if (tile.x >= sizes.x || tile.y >= sizes.y || tile.z >= sizes.z)
|
||||
if (tile.x >= sizes.x || tile.y >= sizes.y || tile.z >= sizes.z ||
|
||||
tile.x < 0 || tile.y < 0 || tile.z < 0)
|
||||
return nullptr;
|
||||
return &nodes[tile.x][tile.y][tile.z];
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ struct DLL_LINKAGE CPathsInfo
|
||||
int3 sizes;
|
||||
CGPathNode ***nodes; //[w][h][level]
|
||||
|
||||
const CGPathNode * getPathInfo( int3 tile ) const;
|
||||
const CGPathNode * getPathInfo( const int3& tile ) const;
|
||||
bool getPath(const int3 &dst, CGPath &out) const;
|
||||
int getDistance( int3 tile ) const;
|
||||
CPathsInfo(const int3 &Sizes);
|
||||
|
@ -917,7 +917,7 @@ void CGameHandler::handleConnection(std::set<PlayerColor> players, CConnection &
|
||||
c << &applied;
|
||||
};
|
||||
|
||||
CBaseForGHApply *apply = applier->apps[packType]; //and appropriae applier object
|
||||
CBaseForGHApply *apply = applier->apps[packType]; //and appropriate applier object
|
||||
if(isBlockedByQueries(pack, player))
|
||||
{
|
||||
sendPackageResponse(false);
|
||||
@ -5347,7 +5347,6 @@ void CGameHandler::runBattle()
|
||||
const CStack *next;
|
||||
while(!battleResult.get() && (next = curB.getNextStack()) && next->willMove())
|
||||
{
|
||||
|
||||
//check for bad morale => freeze
|
||||
int nextStackMorale = next->MoraleVal();
|
||||
if( nextStackMorale < 0 &&
|
||||
@ -5689,7 +5688,7 @@ bool CGameHandler::isValidObject(const CGObjectInstance *obj) const
|
||||
|
||||
bool CGameHandler::isBlockedByQueries(const CPack *pack, PlayerColor player)
|
||||
{
|
||||
if(dynamic_cast<const PlayerMessage*>(pack))
|
||||
if(!strcmp(typeid(*pack).name(), typeid(PlayerMessage).name()))
|
||||
return false;
|
||||
|
||||
auto query = queries.topQuery(player);
|
||||
@ -5827,7 +5826,7 @@ CasualtiesAfterBattle::CasualtiesAfterBattle(const CArmedInstance *army, BattleI
|
||||
auto warMachine = VLC->arth->creatureToMachineID(st->type->idNumber);
|
||||
if (warMachine != ArtifactID::NONE)
|
||||
{
|
||||
auto hero = dynamic_cast<const CGHeroInstance*> (army);
|
||||
auto hero = dynamic_ptr_cast<CGHeroInstance> (army);
|
||||
if (hero)
|
||||
removedWarMachines.push_back (ArtifactLocation(hero, hero->getArtPos(warMachine, true)));
|
||||
}
|
||||
@ -5933,4 +5932,3 @@ bool ServerSpellCastEnvironment::moveHero(ObjectInstanceID hid, int3 dst, ui8 te
|
||||
{
|
||||
return gh->moveHero(hid, dst, teleporting, false, asker);
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,12 @@ CBattleQuery::CBattleQuery()
|
||||
|
||||
bool CBattleQuery::blocksPack(const CPack *pack) const
|
||||
{
|
||||
return !dynamic_cast<const MakeAction*>(pack) && !dynamic_cast<const MakeCustomAction*>(pack);
|
||||
#ifndef __APPLE__
|
||||
bool dynamic_success = !dynamic_cast<const MakeAction*>(pack) && !dynamic_cast<const MakeCustomAction*>(pack);
|
||||
#else
|
||||
const char * name = typeid(*pack).name();
|
||||
return strcmp(name, typeid(MakeAction).name()) && strcmp(name, typeid(MakeCustomAction).name());
|
||||
#endif
|
||||
}
|
||||
|
||||
void CBattleQuery::onRemoval(CGameHandler *gh, PlayerColor color)
|
||||
@ -272,12 +277,12 @@ bool CGarrisonDialogQuery::blocksPack(const CPack *pack) const
|
||||
ourIds.insert(this->exchangingArmies[0]->id);
|
||||
ourIds.insert(this->exchangingArmies[1]->id);
|
||||
|
||||
|
||||
if (auto stacks = dynamic_cast<const ArrangeStacks*>(pack))
|
||||
if (auto stacks = dynamic_ptr_cast<ArrangeStacks>(pack))
|
||||
{
|
||||
return !vstd::contains(ourIds, stacks->id1) || !vstd::contains(ourIds, stacks->id2);
|
||||
}
|
||||
if (auto arts = dynamic_cast<const ExchangeArtifacts*>(pack))
|
||||
|
||||
if (auto arts = dynamic_ptr_cast<ExchangeArtifacts>(pack))
|
||||
{
|
||||
if(auto id1 = boost::apply_visitor(GetEngagedHeroIds(), arts->src.artHolder))
|
||||
if(!vstd::contains(ourIds, *id1))
|
||||
@ -288,17 +293,17 @@ bool CGarrisonDialogQuery::blocksPack(const CPack *pack) const
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
if (auto dismiss = dynamic_cast<const DisbandCreature*>(pack))
|
||||
if (auto dismiss = dynamic_ptr_cast<DisbandCreature>(pack))
|
||||
{
|
||||
return !vstd::contains(ourIds, dismiss->id);
|
||||
}
|
||||
|
||||
if (auto dismiss = dynamic_cast<const AssembleArtifacts*>(pack))
|
||||
if (auto dismiss = dynamic_ptr_cast<AssembleArtifacts>(pack))
|
||||
{
|
||||
return !vstd::contains(ourIds, dismiss->heroID);
|
||||
}
|
||||
|
||||
if(auto upgrade = dynamic_cast<const UpgradeCreature*>(pack))
|
||||
if(auto upgrade = dynamic_ptr_cast<UpgradeCreature>(pack))
|
||||
{
|
||||
return !vstd::contains(ourIds, upgrade->id);
|
||||
}
|
||||
@ -319,7 +324,7 @@ CBlockingDialogQuery::CBlockingDialogQuery(const BlockingDialog &bd)
|
||||
|
||||
void CTeleportDialogQuery::notifyObjectAboutRemoval(const CObjectVisitQuery &objectVisit) const
|
||||
{
|
||||
auto obj = dynamic_cast<const CGTeleport *>(objectVisit.visitedObject);
|
||||
auto obj = dynamic_cast<const CGTeleport*>(objectVisit.visitedObject);
|
||||
obj->teleportDialogAnswered(objectVisit.visitingHero, *answer, td.exits);
|
||||
}
|
||||
|
||||
@ -373,7 +378,7 @@ bool CDialogQuery::endsByPlayerAnswer() const
|
||||
bool CDialogQuery::blocksPack(const CPack *pack) const
|
||||
{
|
||||
//We accept only query replies from correct player
|
||||
if(auto reply = dynamic_cast<const QueryReply *>(pack))
|
||||
if(auto reply = dynamic_ptr_cast<QueryReply>(pack))
|
||||
{
|
||||
return !vstd::contains(players, reply->player);
|
||||
}
|
||||
|
@ -86,8 +86,8 @@ void CPregameServer::handleConnection(CConnection *cpc)
|
||||
logNetwork->infoStream() << "Got package to announce " << typeid(*cpfs).name() << " from " << *cpc;
|
||||
|
||||
boost::unique_lock<boost::recursive_mutex> queueLock(mx);
|
||||
bool quitting = dynamic_cast<QuitMenuWithoutStarting*>(cpfs),
|
||||
startingGame = dynamic_cast<StartWithCurrentSettings*>(cpfs);
|
||||
bool quitting = dynamic_ptr_cast<QuitMenuWithoutStarting>(cpfs),
|
||||
startingGame = dynamic_ptr_cast<StartWithCurrentSettings>(cpfs);
|
||||
if(quitting || startingGame) //host leaves main menu or wants to start game -> we end
|
||||
{
|
||||
cpc->receivedStop = true;
|
||||
@ -258,11 +258,11 @@ void CPregameServer::sendPack(CConnection * pc, const CPackForSelectionScreen &
|
||||
*pc << &pack;
|
||||
}
|
||||
|
||||
if(dynamic_cast<const QuitMenuWithoutStarting*>(&pack))
|
||||
if(dynamic_ptr_cast<QuitMenuWithoutStarting>(&pack))
|
||||
{
|
||||
pc->sendStop = true;
|
||||
}
|
||||
else if(dynamic_cast<const StartWithCurrentSettings*>(&pack))
|
||||
else if(dynamic_ptr_cast<StartWithCurrentSettings>(&pack))
|
||||
{
|
||||
pc->sendStop = true;
|
||||
}
|
||||
@ -270,25 +270,25 @@ void CPregameServer::sendPack(CConnection * pc, const CPackForSelectionScreen &
|
||||
|
||||
void CPregameServer::processPack(CPackForSelectionScreen * pack)
|
||||
{
|
||||
if(dynamic_cast<CPregamePackToHost*>(pack))
|
||||
if(dynamic_ptr_cast<CPregamePackToHost>(pack))
|
||||
{
|
||||
sendPack(host, *pack);
|
||||
}
|
||||
else if(SelectMap *sm = dynamic_cast<SelectMap*>(pack))
|
||||
else if(SelectMap *sm = dynamic_ptr_cast<SelectMap>(pack))
|
||||
{
|
||||
vstd::clear_pointer(curmap);
|
||||
curmap = sm->mapInfo;
|
||||
sm->free = false;
|
||||
announcePack(*pack);
|
||||
}
|
||||
else if(UpdateStartOptions *uso = dynamic_cast<UpdateStartOptions*>(pack))
|
||||
else if(UpdateStartOptions *uso = dynamic_ptr_cast<UpdateStartOptions>(pack))
|
||||
{
|
||||
vstd::clear_pointer(curStartInfo);
|
||||
curStartInfo = uso->options;
|
||||
uso->free = false;
|
||||
announcePack(*pack);
|
||||
}
|
||||
else if(dynamic_cast<const StartWithCurrentSettings*>(pack))
|
||||
else if(dynamic_ptr_cast<StartWithCurrentSettings>(pack))
|
||||
{
|
||||
state = ENDING_AND_STARTING_GAME;
|
||||
announcePack(*pack);
|
||||
|
@ -209,7 +209,7 @@ bool SetFormation::applyGh( CGameHandler *gh )
|
||||
bool HireHero::applyGh( CGameHandler *gh )
|
||||
{
|
||||
const CGObjectInstance *obj = gh->getObj(tid);
|
||||
const CGTownInstance *town = dynamic_cast<const CGTownInstance *>(obj);
|
||||
const CGTownInstance *town = dynamic_ptr_cast<CGTownInstance>(obj);
|
||||
if(town && PlayerRelations::ENEMIES == gh->getPlayerRelations(obj->tempOwner, gh->getPlayerAt(c)))
|
||||
COMPLAIN_AND_RETURN("Can't buy hero in enemy town!");
|
||||
|
||||
|
@ -8,3 +8,31 @@
|
||||
#include <boost/random/mersenne_twister.hpp>
|
||||
#include <boost/random/variate_generator.hpp>
|
||||
#include <boost/system/system_error.hpp>
|
||||
|
||||
template<class T, class F>
|
||||
inline const T * dynamic_ptr_cast(const F * ptr)
|
||||
{
|
||||
#ifndef __APPLE__
|
||||
return dynamic_cast<const T*>(ptr);
|
||||
#else
|
||||
if (!strcmp(typeid(*ptr).name(), typeid(T).name()))
|
||||
{
|
||||
return static_cast<const T*>(ptr);
|
||||
}
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class T, class F>
|
||||
inline T * dynamic_ptr_cast(F * ptr)
|
||||
{
|
||||
#ifndef __APPLE__
|
||||
return dynamic_cast<T*>(ptr);
|
||||
#else
|
||||
if (!strcmp(typeid(*ptr).name(), typeid(T).name()))
|
||||
{
|
||||
return static_cast<T*>(ptr);
|
||||
}
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user