PathfinderUtil.h 1.8 KB

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