PathfinderUtil.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 "mapping/CMapDefines.h"
  12. #include "CGameState.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. namespace PathfinderUtil
  15. {
  16. using FoW = std::shared_ptr<const boost::multi_array<ui8, 3>>;
  17. using ELayer = EPathfindingLayer;
  18. template<EPathfindingLayer::EEPathfindingLayer layer>
  19. CGPathNode::EAccessibility evaluateAccessibility(const int3 & pos, const TerrainTile & tinfo, FoW fow, const PlayerColor player, const CGameState * gs)
  20. {
  21. if(!(*fow)[pos.z][pos.x][pos.y])
  22. return CGPathNode::BLOCKED;
  23. switch(layer)
  24. {
  25. case ELayer::LAND:
  26. case ELayer::SAIL:
  27. if(tinfo.visitable)
  28. {
  29. if(tinfo.visitableObjects.front()->ID == Obj::SANCTUARY && tinfo.visitableObjects.back()->ID == Obj::HERO && tinfo.visitableObjects.back()->tempOwner != player) //non-owned hero stands on Sanctuary
  30. {
  31. return CGPathNode::BLOCKED;
  32. }
  33. else
  34. {
  35. for(const CGObjectInstance * obj : tinfo.visitableObjects)
  36. {
  37. if(obj->blockVisit)
  38. return CGPathNode::BLOCKVIS;
  39. else if(obj->passableFor(player))
  40. return CGPathNode::ACCESSIBLE;
  41. else if(obj->ID != Obj::EVENT)
  42. return CGPathNode::VISITABLE;
  43. }
  44. }
  45. }
  46. else if(tinfo.blocked)
  47. {
  48. return CGPathNode::BLOCKED;
  49. }
  50. else if(gs->guardingCreaturePosition(pos).valid())
  51. {
  52. // Monster close by; blocked visit for battle
  53. return CGPathNode::BLOCKVIS;
  54. }
  55. break;
  56. case ELayer::WATER:
  57. if(tinfo.blocked || tinfo.terType->isLand())
  58. return CGPathNode::BLOCKED;
  59. break;
  60. case ELayer::AIR:
  61. if(tinfo.blocked || tinfo.terType->isLand())
  62. return CGPathNode::FLYABLE;
  63. break;
  64. }
  65. return CGPathNode::ACCESSIBLE;
  66. }
  67. }
  68. VCMI_LIB_NAMESPACE_END