Composition.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. }
  62. int Composition::getHeroExchangeCount() const
  63. {
  64. return isElementar() ? taskptr(*subtasks.back())->getHeroExchangeCount() : 0;
  65. }