VisitQueries.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * VisitQueries.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 "VisitQueries.h"
  12. #include "../../lib/mapObjects/CGHeroInstance.h"
  13. #include "../CGameHandler.h"
  14. #include "QueriesProcessor.h"
  15. VisitQuery::VisitQuery(CGameHandler * owner, const CGObjectInstance * Obj, const CGHeroInstance * Hero)
  16. : CQuery(owner)
  17. , visitedObject(Obj)
  18. , visitingHero(Hero)
  19. {
  20. addPlayer(Hero->tempOwner);
  21. }
  22. bool VisitQuery::blocksPack(const CPack * pack) const
  23. {
  24. //During the visit itself ALL actions are blocked.
  25. //(However, the visit may trigger a query above that'll pass some.)
  26. return true;
  27. }
  28. void VisitQuery::onExposure(QueryPtr topQuery)
  29. {
  30. //Object may have been removed and deleted.
  31. if(gh->isValidObject(visitedObject))
  32. topQuery->notifyObjectAboutRemoval(visitedObject, visitingHero);
  33. owner->popIfTop(*this);
  34. }
  35. MapObjectVisitQuery::MapObjectVisitQuery(CGameHandler * owner, const CGObjectInstance * Obj, const CGHeroInstance * Hero)
  36. : VisitQuery(owner, Obj, Hero)
  37. , removeObjectAfterVisit(false)
  38. {
  39. }
  40. void MapObjectVisitQuery::onRemoval(PlayerColor color)
  41. {
  42. gh->objectVisitEnded(visitingHero, players.front());
  43. //TODO or should it be destructor?
  44. //Can object visit affect 2 players and what would be desired behavior?
  45. if(removeObjectAfterVisit)
  46. gh->removeObject(visitedObject, color);
  47. }
  48. TownBuildingVisitQuery::TownBuildingVisitQuery(CGameHandler * owner, const CGObjectInstance * Obj, const CGHeroInstance * Hero, BuildingID buildingToVisit)
  49. : VisitQuery(owner, Obj, Hero)
  50. , visitedBuilding(buildingToVisit)
  51. {
  52. }
  53. void TownBuildingVisitQuery::onRemoval(PlayerColor color)
  54. {
  55. }