BuildThis.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 "../AIGateway.h"
  13. #include "../AIUtility.h"
  14. #include "../../../lib/StringConstants.h"
  15. namespace NKAI
  16. {
  17. extern boost::thread_specific_ptr<CCallback> cb;
  18. extern boost::thread_specific_ptr<AIGateway> ai;
  19. using namespace Goals;
  20. BuildThis::BuildThis(BuildingID Bid, const CGTownInstance * tid)
  21. : ElementarGoal(Goals::BUILD_STRUCTURE)
  22. {
  23. buildingInfo = BuildingInfo(
  24. tid->town->buildings.at(Bid),
  25. nullptr,
  26. CreatureID::NONE,
  27. tid,
  28. nullptr);
  29. bid = Bid;
  30. town = tid;
  31. }
  32. bool BuildThis::operator==(const BuildThis & other) const
  33. {
  34. return town == other.town && bid == other.bid;
  35. }
  36. std::string BuildThis::toString() const
  37. {
  38. return "Build " + buildingInfo.name + " in " + town->getNameTranslated();
  39. }
  40. void BuildThis::accept(AIGateway * ai)
  41. {
  42. auto b = BuildingID(bid);
  43. if(town)
  44. {
  45. if(cb->canBuildStructure(town, b) == EBuildingState::ALLOWED)
  46. {
  47. logAi->debug("Player %d will build %s in town of %s at %s",
  48. ai->playerID, town->town->buildings.at(b)->getNameTranslated(), town->getNameTranslated(), town->pos.toString());
  49. cb->buildBuilding(town, b);
  50. return;
  51. }
  52. }
  53. throw cannotFulfillGoalException("Cannot build a given structure!");
  54. }
  55. }