BuildThis.cpp 1.3 KB

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