mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Pack of tiny code improvements for @alexvins request
This commit is contained in:
parent
f490ea1fcd
commit
826a64b579
2
Global.h
2
Global.h
@ -670,7 +670,7 @@ namespace vstd
|
||||
std::vector<T> 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;
|
||||
}
|
||||
|
||||
|
@ -720,8 +720,8 @@ ETeleportChannelType::ETeleportChannelType CGameInfoCallback::getTeleportChannel
|
||||
{
|
||||
std::vector<ObjectInstanceID> entrances = getTeleportChannelEntraces(id, ObjectInstanceID(), Player);
|
||||
std::vector<ObjectInstanceID> 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;
|
||||
}
|
||||
|
@ -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<ObjectInstanceID> 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<const CGTeleport *>(obj);
|
||||
if(teleportObj)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
return ((dynamic_cast<const CGTeleport *>(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<ObjectInstanceID> 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<ObjectInstanceID> exits) const
|
||||
{
|
||||
ObjectInstanceID objId = ObjectInstanceID(answer);
|
||||
ObjectInstanceID objId(answer);
|
||||
auto realExits = getAllExits();
|
||||
if(!exits.size() && !realExits.size())
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user