From 826a64b579373871aec53ac21dc2dce6cadc6427 Mon Sep 17 00:00:00 2001 From: ArseniyShestakov Date: Sun, 8 Mar 2015 20:19:00 +0300 Subject: [PATCH] Pack of tiny code improvements for @alexvins request --- Global.h | 2 +- lib/CGameInfoCallback.cpp | 4 ++-- lib/mapObjects/MiscObjects.cpp | 35 ++++++++++------------------------ 3 files changed, 13 insertions(+), 28 deletions(-) diff --git a/Global.h b/Global.h index e3622a12e..bd15cdbaf 100644 --- a/Global.h +++ b/Global.h @@ -670,7 +670,7 @@ namespace vstd std::vector v3; std::sort(v1.begin(), v1.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; } diff --git a/lib/CGameInfoCallback.cpp b/lib/CGameInfoCallback.cpp index 53a3280b1..b17d1b096 100644 --- a/lib/CGameInfoCallback.cpp +++ b/lib/CGameInfoCallback.cpp @@ -720,8 +720,8 @@ ETeleportChannelType::ETeleportChannelType CGameInfoCallback::getTeleportChannel { std::vector entrances = getTeleportChannelEntraces(id, ObjectInstanceID(), Player); std::vector exits = getTeleportChannelExits(id, ObjectInstanceID(), Player); - if((!entrances.size() || !exits.size()) - || (entrances.size() == 1 && entrances == exits)) + if((!entrances.size() || !exits.size()) // impassable if exits or entrances list are empty + || (entrances.size() == 1 && entrances == exits)) // impassable if only entrance and only exit is same object. e.g bidirectional monolith { return ETeleportChannelType::IMPASSABLE; } diff --git a/lib/mapObjects/MiscObjects.cpp b/lib/mapObjects/MiscObjects.cpp index 827dea6bd..0db36e879 100644 --- a/lib/mapObjects/MiscObjects.cpp +++ b/lib/mapObjects/MiscObjects.cpp @@ -758,18 +758,12 @@ bool CGTeleport::isExit() const bool CGTeleport::isChannelEntrance(ObjectInstanceID id) const { - if(vstd::contains(getAllEntrances(), id)) - return true; - else - return false; + return vstd::contains(getAllEntrances(), id); } bool CGTeleport::isChannelExit(ObjectInstanceID id) const { - if(vstd::contains(getAllExits(), id)) - return true; - else - return false; + return vstd::contains(getAllExits(), id); } std::vector CGTeleport::getAllEntrances(bool excludeCurrent) const @@ -801,19 +795,12 @@ ObjectInstanceID CGTeleport::getRandomExit(const CGHeroInstance * h) const bool CGTeleport::isTeleport(const CGObjectInstance * obj) { - auto teleportObj = dynamic_cast(obj); - if(teleportObj) - return true; - else - return false; + return ((dynamic_cast(obj))); } bool CGTeleport::isConnected(const CGTeleport * src, const CGTeleport * dst) { - if(src && dst && src->isChannelExit(dst->id) && src != dst) - return true; - else - return false; + return src && dst && src != dst && src->isChannelExit(dst->id); } 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); } - else - td.exits.push_back(getRandomExit(h)); 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; } 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 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 exits) const { - ObjectInstanceID objId = ObjectInstanceID(answer); + ObjectInstanceID objId(answer); auto realExits = getAllExits(true); if(!isEntrance() // Do nothing if hero visited exit only object || (!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); 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; } 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)) { @@ -1068,7 +1053,7 @@ void CGWhirlpool::onHeroVisit( const CGHeroInstance * h ) const void CGWhirlpool::teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer, std::vector exits) const { - ObjectInstanceID objId = ObjectInstanceID(answer); + ObjectInstanceID objId(answer); auto realExits = getAllExits(); if(!exits.size() && !realExits.size()) return;