BuildThis.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 NK2AI
  17. {
  18. using namespace Goals;
  19. BuildThis::BuildThis(BuildingID Bid, const CGTownInstance * tid)
  20. : ElementarGoal(Goals::BUILD_STRUCTURE)
  21. {
  22. // FIXME: Mircea: Remove this constructor (the parent constructor BuildThis::BuildThis)
  23. // Seems like StartupBehavior is instantiating via this BuildThis constructor
  24. // Or needs to be unit tested to ensure there's no problem with the limited constructor params
  25. buildingInfo = BuildingInfo(
  26. tid->getTown()->buildings.at(Bid).get(),
  27. nullptr,
  28. CreatureID::NONE,
  29. tid,
  30. std::unique_ptr<ArmyManager>(nullptr));
  31. bid = Bid.getNum();
  32. town = tid;
  33. }
  34. bool BuildThis::operator==(const BuildThis & other) const
  35. {
  36. return town == other.town && bid == other.bid;
  37. }
  38. std::string BuildThis::toString() const
  39. {
  40. return "Build " + buildingInfo.name + " in " + town->getNameTranslated();
  41. }
  42. void BuildThis::accept(AIGateway * aiGw)
  43. {
  44. auto b = BuildingID(bid);
  45. if(town)
  46. {
  47. if(ccTl->canBuildStructure(town, b) == EBuildingState::ALLOWED)
  48. {
  49. logAi->debug("Player %d will build %s in town of %s at %s",
  50. aiGw->playerID, town->getTown()->buildings.at(b)->getNameTranslated(), town->getNameTranslated(), town->anchorPos().toString());
  51. ccTl->buildBuilding(town, b);
  52. return;
  53. }
  54. }
  55. throw cannotFulfillGoalException("Cannot build a given structure!");
  56. }
  57. }