PathfinderUtil.h 1.9 KB

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