1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Pack of tiny code improvements for @alexvins request

This commit is contained in:
ArseniyShestakov 2015-03-08 20:19:00 +03:00
parent f490ea1fcd
commit 826a64b579
3 changed files with 13 additions and 28 deletions

View File

@ -670,7 +670,7 @@ namespace vstd
std::vector<T> v3; std::vector<T> v3;
std::sort(v1.begin(), v1.end()); std::sort(v1.begin(), v1.end());
std::sort(v2.begin(), v2.end()); std::sort(v2.begin(), v2.end());
std::set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(v3)); std::set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), std::back_inserter(v3));
return v3; return v3;
} }

View File

@ -720,8 +720,8 @@ ETeleportChannelType::ETeleportChannelType CGameInfoCallback::getTeleportChannel
{ {
std::vector<ObjectInstanceID> entrances = getTeleportChannelEntraces(id, ObjectInstanceID(), Player); std::vector<ObjectInstanceID> entrances = getTeleportChannelEntraces(id, ObjectInstanceID(), Player);
std::vector<ObjectInstanceID> exits = getTeleportChannelExits(id, ObjectInstanceID(), Player); std::vector<ObjectInstanceID> exits = getTeleportChannelExits(id, ObjectInstanceID(), Player);
if((!entrances.size() || !exits.size()) if((!entrances.size() || !exits.size()) // impassable if exits or entrances list are empty
|| (entrances.size() == 1 && entrances == exits)) || (entrances.size() == 1 && entrances == exits)) // impassable if only entrance and only exit is same object. e.g bidirectional monolith
{ {
return ETeleportChannelType::IMPASSABLE; return ETeleportChannelType::IMPASSABLE;
} }

View File

@ -758,18 +758,12 @@ bool CGTeleport::isExit() const
bool CGTeleport::isChannelEntrance(ObjectInstanceID id) const bool CGTeleport::isChannelEntrance(ObjectInstanceID id) const
{ {
if(vstd::contains(getAllEntrances(), id)) return vstd::contains(getAllEntrances(), id);
return true;
else
return false;
} }
bool CGTeleport::isChannelExit(ObjectInstanceID id) const bool CGTeleport::isChannelExit(ObjectInstanceID id) const
{ {
if(vstd::contains(getAllExits(), id)) return vstd::contains(getAllExits(), id);
return true;
else
return false;
} }
std::vector<ObjectInstanceID> CGTeleport::getAllEntrances(bool excludeCurrent) const std::vector<ObjectInstanceID> CGTeleport::getAllEntrances(bool excludeCurrent) const
@ -801,19 +795,12 @@ ObjectInstanceID CGTeleport::getRandomExit(const CGHeroInstance * h) const
bool CGTeleport::isTeleport(const CGObjectInstance * obj) bool CGTeleport::isTeleport(const CGObjectInstance * obj)
{ {
auto teleportObj = dynamic_cast<const CGTeleport *>(obj); return ((dynamic_cast<const CGTeleport *>(obj)));
if(teleportObj)
return true;
else
return false;
} }
bool CGTeleport::isConnected(const CGTeleport * src, const CGTeleport * dst) bool CGTeleport::isConnected(const CGTeleport * src, const CGTeleport * dst)
{ {
if(src && dst && src->isChannelExit(dst->id) && src != dst) return src && dst && src != dst && src->isChannelExit(dst->id);
return true;
else
return false;
} }
bool CGTeleport::isConnected(const CGObjectInstance * src, const CGObjectInstance * dst) bool CGTeleport::isConnected(const CGObjectInstance * src, const CGObjectInstance * dst)
@ -896,16 +883,14 @@ void CGMonolith::onHeroVisit( const CGHeroInstance * h ) const
{ {
td.exits = cb->getTeleportChannelExits(channel); td.exits = cb->getTeleportChannelExits(channel);
} }
else
td.exits.push_back(getRandomExit(h));
if(ETeleportChannelType::IMPASSABLE == cb->getTeleportChannelType(channel)) if(ETeleportChannelType::IMPASSABLE == cb->getTeleportChannelType(channel))
{ {
logGlobal->warnStream() << "Cannot find corresponding exit monolith for "<< id << " (obj at " << pos << ") :("; logGlobal->debugStream() << "Cannot find corresponding exit monolith for "<< id << " (obj at " << pos << ") :(";
td.impassable = true; td.impassable = true;
} }
else if(getRandomExit(h) == ObjectInstanceID()) else if(getRandomExit(h) == ObjectInstanceID())
logGlobal->warnStream() << "All exits blocked for monolith "<< id << " (obj at " << pos << ") :("; logGlobal->debugStream() << "All exits blocked for monolith "<< id << " (obj at " << pos << ") :(";
} }
else else
showInfoDialog(h, 70, 0); showInfoDialog(h, 70, 0);
@ -915,7 +900,7 @@ void CGMonolith::onHeroVisit( const CGHeroInstance * h ) const
void CGMonolith::teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer, std::vector<ObjectInstanceID> exits) const void CGMonolith::teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer, std::vector<ObjectInstanceID> exits) const
{ {
ObjectInstanceID objId = ObjectInstanceID(answer); ObjectInstanceID objId(answer);
auto realExits = getAllExits(true); auto realExits = getAllExits(true);
if(!isEntrance() // Do nothing if hero visited exit only object if(!isEntrance() // Do nothing if hero visited exit only object
|| (!exits.size() && !realExits.size()) // Do nothing if there no exits on this channel || (!exits.size() && !realExits.size()) // Do nothing if there no exits on this channel
@ -1035,11 +1020,11 @@ void CGWhirlpool::onHeroVisit( const CGHeroInstance * h ) const
TeleportDialog td(h, channel); TeleportDialog td(h, channel);
if(ETeleportChannelType::IMPASSABLE == cb->getTeleportChannelType(channel)) if(ETeleportChannelType::IMPASSABLE == cb->getTeleportChannelType(channel))
{ {
logGlobal->warnStream() << "Cannot find exit whirlpool for "<< id << " (obj at " << pos << ") :("; logGlobal->debugStream() << "Cannot find exit whirlpool for "<< id << " (obj at " << pos << ") :(";
td.impassable = true; td.impassable = true;
} }
else if(getRandomExit(h) == ObjectInstanceID()) else if(getRandomExit(h) == ObjectInstanceID())
logGlobal->warnStream() << "All exits are blocked for whirlpool "<< id << " (obj at " << pos << ") :("; logGlobal->debugStream() << "All exits are blocked for whirlpool "<< id << " (obj at " << pos << ") :(";
if(!isProtected(h)) if(!isProtected(h))
{ {
@ -1068,7 +1053,7 @@ void CGWhirlpool::onHeroVisit( const CGHeroInstance * h ) const
void CGWhirlpool::teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer, std::vector<ObjectInstanceID> exits) const void CGWhirlpool::teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer, std::vector<ObjectInstanceID> exits) const
{ {
ObjectInstanceID objId = ObjectInstanceID(answer); ObjectInstanceID objId(answer);
auto realExits = getAllExits(); auto realExits = getAllExits();
if(!exits.size() && !realExits.size()) if(!exits.size() && !realExits.size())
return; return;