BuildThis.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 "BuildThis.h"
  12. #include "../VCAI.h"
  13. #include "../AIUtility.h"
  14. #include "../AIhelper.h"
  15. #include "../FuzzyHelper.h"
  16. #include "../../../lib/mapping/CMap.h" //for victory conditions
  17. #include "../../../lib/CPathfinder.h"
  18. #include "../../../lib/StringConstants.h"
  19. extern boost::thread_specific_ptr<CCallback> cb;
  20. extern boost::thread_specific_ptr<VCAI> ai;
  21. extern FuzzyHelper * fh;
  22. using namespace Goals;
  23. bool BuildThis::operator==(const BuildThis & other) const
  24. {
  25. return town == other.town && bid == other.bid;
  26. }
  27. std::string BuildThis::toString() const
  28. {
  29. return "Build " + buildingInfo.name + "(" + std::to_string(bid) + ") in " + town->name;
  30. }
  31. void BuildThis::accept(VCAI * ai)
  32. {
  33. auto b = BuildingID(bid);
  34. if(town)
  35. {
  36. if(cb->canBuildStructure(town, b) == EBuildingState::ALLOWED)
  37. {
  38. logAi->debug("Player %d will build %s in town of %s at %s",
  39. ai->playerID, town->town->buildings.at(b)->Name(), town->name, town->pos.toString());
  40. cb->buildBuilding(town, b);
  41. return;
  42. }
  43. }
  44. throw cannotFulfillGoalException("Cannot build a given structure!");
  45. }