2019-01-15 05:00:00 +02:00
/*
* PathfinderUtil . h , part of VCMI engine
*
* Authors : listed in file AUTHORS in main folder
*
* License : GNU General Public License v2 .0 or later
* Full text of license available in license . txt file , in main folder
*
*/
# pragma once
2023-01-09 01:17:37 +02:00
# include "TerrainHandler.h"
# include "mapObjects/CObjectHandler.h"
2019-01-15 05:00:00 +02:00
# include "mapping/CMapDefines.h"
# include "CGameState.h"
2022-07-26 15:07:42 +02:00
VCMI_LIB_NAMESPACE_BEGIN
2019-01-15 05:00:00 +02:00
namespace PathfinderUtil
{
2022-09-18 16:39:10 +02:00
using FoW = std : : shared_ptr < const boost : : multi_array < ui8 , 3 > > ;
2019-01-15 05:00:00 +02:00
using ELayer = EPathfindingLayer ;
template < EPathfindingLayer : : EEPathfindingLayer layer >
2022-09-25 08:04:15 +02:00
CGPathNode : : EAccessibility evaluateAccessibility ( const int3 & pos , const TerrainTile & tinfo , FoW fow , const PlayerColor player , const CGameState * gs )
2019-01-15 05:00:00 +02:00
{
2022-09-18 16:39:10 +02:00
if ( ! ( * fow ) [ pos . z ] [ pos . x ] [ pos . y ] )
2019-01-15 05:00:00 +02:00
return CGPathNode : : BLOCKED ;
switch ( layer )
{
case ELayer : : LAND :
case ELayer : : SAIL :
2022-09-25 08:04:15 +02:00
if ( tinfo . visitable )
2019-01-15 05:00:00 +02:00
{
2022-09-25 08:04:15 +02:00
if ( tinfo . visitableObjects . front ( ) - > ID = = Obj : : SANCTUARY & & tinfo . visitableObjects . back ( ) - > ID = = Obj : : HERO & & tinfo . visitableObjects . back ( ) - > tempOwner ! = player ) //non-owned hero stands on Sanctuary
2019-01-15 05:00:00 +02:00
{
return CGPathNode : : BLOCKED ;
}
else
{
2022-09-25 08:04:15 +02:00
for ( const CGObjectInstance * obj : tinfo . visitableObjects )
2019-01-15 05:00:00 +02:00
{
if ( obj - > blockVisit )
return CGPathNode : : BLOCKVIS ;
else if ( obj - > passableFor ( player ) )
return CGPathNode : : ACCESSIBLE ;
else if ( obj - > ID ! = Obj : : EVENT )
return CGPathNode : : VISITABLE ;
}
}
}
2022-09-25 08:04:15 +02:00
else if ( tinfo . blocked )
2019-01-15 05:00:00 +02:00
{
return CGPathNode : : BLOCKED ;
}
else if ( gs - > guardingCreaturePosition ( pos ) . valid ( ) )
{
// Monster close by; blocked visit for battle
return CGPathNode : : BLOCKVIS ;
}
break ;
case ELayer : : WATER :
2022-09-25 08:04:15 +02:00
if ( tinfo . blocked | | tinfo . terType - > isLand ( ) )
2019-01-15 05:00:00 +02:00
return CGPathNode : : BLOCKED ;
break ;
case ELayer : : AIR :
2022-09-25 08:04:15 +02:00
if ( tinfo . blocked | | tinfo . terType - > isLand ( ) )
2019-01-15 05:00:00 +02:00
return CGPathNode : : FLYABLE ;
break ;
}
return CGPathNode : : ACCESSIBLE ;
}
}
2022-07-26 15:07:42 +02:00
VCMI_LIB_NAMESPACE_END