BuildThis.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 "../../../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<VCAI> ai;
  19. using namespace Goals;
  20. bool BuildThis::operator==(const BuildThis & other) const
  21. {
  22. return town == other.town && bid == other.bid;
  23. }
  24. std::string BuildThis::toString() const
  25. {
  26. return "Build " + buildingInfo.name + "(" + std::to_string(bid) + ") in " + town->name;
  27. }
  28. void BuildThis::accept(VCAI * ai)
  29. {
  30. auto b = BuildingID(bid);
  31. if(town)
  32. {
  33. if(cb->canBuildStructure(town, b) == EBuildingState::ALLOWED)
  34. {
  35. logAi->debug("Player %d will build %s in town of %s at %s",
  36. ai->playerID, town->town->buildings.at(b)->Name(), town->name, town->pos.toString());
  37. cb->buildBuilding(town, b);
  38. return;
  39. }
  40. }
  41. throw cannotFulfillGoalException("Cannot build a given structure!");
  42. }