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-06-21 12:46:09 +02:00
# include "../TerrainHandler.h"
# include "../mapObjects/CGObjectInstance.h"
# include "../mapping/CMapDefines.h"
2023-06-23 17:02:48 +02:00
# include "../gameState/CGameState.h"
2023-06-21 14:38:57 +02:00
# include "CGPathNode.h"
2019-01-15 05:00:00 +02:00
2022-07-26 15:07:42 +02:00
VCMI_LIB_NAMESPACE_BEGIN
2019-01-15 05:00:00 +02:00
namespace PathfinderUtil
{
2024-05-07 21:17:05 +02:00
using FoW = boost : : multi_array < ui8 , 3 > ;
2019-01-15 05:00:00 +02:00
using ELayer = EPathfindingLayer ;
2023-08-19 23:22:31 +02:00
template < EPathfindingLayer : : Type layer >
2023-11-13 12:09:55 +02:00
EPathAccessibility evaluateAccessibility ( const int3 & pos , const TerrainTile & tinfo , const FoW & fow , const PlayerColor player , const CGameState * gs )
2019-01-15 05:00:00 +02:00
{
2024-05-07 21:17:05 +02:00
if ( ! fow [ pos . z ] [ pos . x ] [ pos . y ] )
2023-06-21 14:38:57 +02:00
return EPathAccessibility : : BLOCKED ;
2019-01-15 05:00:00 +02:00
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
{
2023-06-21 14:38:57 +02:00
return EPathAccessibility : : BLOCKED ;
2019-01-15 05:00:00 +02:00
}
else
{
2022-09-25 08:04:15 +02:00
for ( const CGObjectInstance * obj : tinfo . visitableObjects )
2019-01-15 05:00:00 +02:00
{
2023-06-21 15:49:44 +02:00
if ( obj - > isBlockedVisitable ( ) )
2023-06-21 14:38:57 +02:00
return EPathAccessibility : : BLOCKVIS ;
2019-01-15 05:00:00 +02:00
else if ( obj - > passableFor ( player ) )
2023-06-21 14:38:57 +02:00
return EPathAccessibility : : ACCESSIBLE ;
2019-01-15 05:00:00 +02:00
else if ( obj - > ID ! = Obj : : EVENT )
2023-06-21 14:38:57 +02:00
return EPathAccessibility : : VISITABLE ;
2019-01-15 05:00:00 +02:00
}
}
}
2022-09-25 08:04:15 +02:00
else if ( tinfo . blocked )
2019-01-15 05:00:00 +02:00
{
2023-06-21 14:38:57 +02:00
return EPathAccessibility : : BLOCKED ;
2019-01-15 05:00:00 +02:00
}
else if ( gs - > guardingCreaturePosition ( pos ) . valid ( ) )
{
// Monster close by; blocked visit for battle
2024-05-23 20:46:03 +02:00
return EPathAccessibility : : GUARDED ;
2019-01-15 05:00:00 +02:00
}
break ;
case ELayer : : WATER :
2022-09-25 08:04:15 +02:00
if ( tinfo . blocked | | tinfo . terType - > isLand ( ) )
2023-06-21 14:38:57 +02:00
return EPathAccessibility : : BLOCKED ;
2019-01-15 05:00:00 +02:00
break ;
case ELayer : : AIR :
2023-06-21 16:29:28 +02:00
return EPathAccessibility : : FLYABLE ;
2019-01-15 05:00:00 +02:00
break ;
}
2023-06-21 14:38:57 +02:00
return EPathAccessibility : : ACCESSIBLE ;
2019-01-15 05:00:00 +02:00
}
}
2022-07-26 15:07:42 +02:00
VCMI_LIB_NAMESPACE_END