2
0

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