PathfinderUtil.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * PathfinderUtil.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "TerrainHandler.h"
  12. #include "mapObjects/CObjectHandler.h"
  13. #include "mapping/CMapDefines.h"
  14. #include "CGameState.h"
  15. VCMI_LIB_NAMESPACE_BEGIN
  16. namespace PathfinderUtil
  17. {
  18. using FoW = std::shared_ptr<const boost::multi_array<ui8, 3>>;
  19. using ELayer = EPathfindingLayer;
  20. template<EPathfindingLayer::EEPathfindingLayer layer>
  21. CGPathNode::EAccessibility evaluateAccessibility(const int3 & pos, const TerrainTile & tinfo, FoW fow, const PlayerColor player, const CGameState * gs)
  22. {
  23. if(!(*fow)[pos.z][pos.x][pos.y])
  24. return CGPathNode::BLOCKED;
  25. switch(layer)
  26. {
  27. case ELayer::LAND:
  28. case ELayer::SAIL:
  29. if(tinfo.visitable)
  30. {
  31. if(tinfo.visitableObjects.front()->ID == Obj::SANCTUARY && tinfo.visitableObjects.back()->ID == Obj::HERO && tinfo.visitableObjects.back()->tempOwner != player) //non-owned hero stands on Sanctuary
  32. {
  33. return CGPathNode::BLOCKED;
  34. }
  35. else
  36. {
  37. for(const CGObjectInstance * obj : tinfo.visitableObjects)
  38. {
  39. if(obj->blockVisit)
  40. return CGPathNode::BLOCKVIS;
  41. else if(obj->passableFor(player))
  42. return CGPathNode::ACCESSIBLE;
  43. else if(obj->ID != Obj::EVENT)
  44. return CGPathNode::VISITABLE;
  45. }
  46. }
  47. }
  48. else if(tinfo.blocked)
  49. {
  50. return CGPathNode::BLOCKED;
  51. }
  52. else if(gs->guardingCreaturePosition(pos).valid())
  53. {
  54. // Monster close by; blocked visit for battle
  55. return CGPathNode::BLOCKVIS;
  56. }
  57. break;
  58. case ELayer::WATER:
  59. if(tinfo.blocked || tinfo.terType->isLand())
  60. return CGPathNode::BLOCKED;
  61. break;
  62. case ELayer::AIR:
  63. if(tinfo.blocked || tinfo.terType->isLand())
  64. return CGPathNode::FLYABLE;
  65. break;
  66. }
  67. return CGPathNode::ACCESSIBLE;
  68. }
  69. }
  70. VCMI_LIB_NAMESPACE_END