Composition.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * BuildThis.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 "Composition.h"
  12. #include "../AIGateway.h"
  13. #include "../AIUtility.h"
  14. #include "../../../lib/mapping/CMap.h" //for victory conditions
  15. #include "../../../lib/CPathfinder.h"
  16. #include "../../../lib/StringConstants.h"
  17. extern boost::thread_specific_ptr<CCallback> cb;
  18. extern boost::thread_specific_ptr<AIGateway> ai;
  19. using namespace Goals;
  20. bool Composition::operator==(const Composition & other) const
  21. {
  22. return false;
  23. }
  24. std::string Composition::toString() const
  25. {
  26. std::string result = "Composition";
  27. for(auto goal : subtasks)
  28. {
  29. result += " " + goal->toString();
  30. }
  31. return result;
  32. }
  33. void Composition::accept(AIGateway * ai)
  34. {
  35. taskptr(*subtasks.back())->accept(ai);
  36. }
  37. TGoalVec Composition::decompose() const
  38. {
  39. return subtasks;
  40. }
  41. Composition & Composition::addNext(const AbstractGoal & goal)
  42. {
  43. return addNext(sptr(goal));
  44. }
  45. Composition & Composition::addNext(TSubgoal goal)
  46. {
  47. if(goal->goalType == COMPOSITION)
  48. {
  49. Composition & other = dynamic_cast<Composition &>(*goal);
  50. vstd::concatenate(subtasks, other.subtasks);
  51. }
  52. else
  53. {
  54. subtasks.push_back(goal);
  55. }
  56. return *this;
  57. }
  58. bool Composition::isElementar() const
  59. {
  60. return subtasks.back()->isElementar();
  61. }