FindObj.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * FindObj.cpp, 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. #include "StdInc.h"
  11. #include "FindObj.h"
  12. #include "VisitObj.h"
  13. #include "../VCAI.h"
  14. #include "../AIUtility.h"
  15. extern boost::thread_specific_ptr<CCallback> cb;
  16. extern boost::thread_specific_ptr<VCAI> ai;
  17. extern FuzzyHelper * fh;
  18. using namespace Goals;
  19. bool FindObj::operator==(const FindObj & other) const
  20. {
  21. return other.hero.h == hero.h && other.objid == objid;
  22. }
  23. TSubgoal FindObj::whatToDoToAchieve()
  24. {
  25. const CGObjectInstance * o = nullptr;
  26. if(resID > -1) //specified
  27. {
  28. for(const CGObjectInstance * obj : ai->visitableObjs)
  29. {
  30. if(obj->ID == objid && obj->subID == resID)
  31. {
  32. o = obj;
  33. break; //TODO: consider multiple objects and choose best
  34. }
  35. }
  36. }
  37. else
  38. {
  39. for(const CGObjectInstance * obj : ai->visitableObjs)
  40. {
  41. if(obj->ID == objid)
  42. {
  43. o = obj;
  44. break; //TODO: consider multiple objects and choose best
  45. }
  46. }
  47. }
  48. if(o && ai->isAccessible(o->pos)) //we don't use isAccessibleForHero as we don't know which hero it is
  49. return sptr(VisitObj(o->id.getNum()));
  50. }