BuyArmy.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * BuyArmy.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 "BuyArmy.h"
  12. #include "../FuzzyHelper.h"
  13. #include "../AIhelper.h"
  14. #include "../../../lib/mapObjects/CGTownInstance.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 BuyArmy::operator==(const BuyArmy & other) const
  20. {
  21. return town == other.town && objid == other.objid;
  22. }
  23. bool BuyArmy::fulfillsMe(TSubgoal goal)
  24. {
  25. //if (hero && hero != goal->hero)
  26. // return false;
  27. return town == goal->town && goal->value >= value; //can always buy more army
  28. }
  29. TSubgoal BuyArmy::whatToDoToAchieve()
  30. {
  31. //TODO: calculate the actual cost of units instead
  32. TResources price;
  33. price[EGameResID::GOLD] = static_cast<int>(value * 0.4f); //some approximate value
  34. return ai->ah->whatToDo(price, iAmElementar()); //buy right now or gather resources
  35. }
  36. std::string BuyArmy::completeMessage() const
  37. {
  38. return boost::format("Bought army of value %d in town of %s") % value, town->getNameTranslated();
  39. }