BuildBoat.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * BuildBoat.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 "BuildBoat.h"
  12. #include "../VCAI.h"
  13. #include "../FuzzyHelper.h"
  14. #include "../AIhelper.h"
  15. using namespace Goals;
  16. bool BuildBoat::operator==(const BuildBoat & other) const
  17. {
  18. return shipyard == other.shipyard;
  19. }
  20. TSubgoal BuildBoat::whatToDoToAchieve()
  21. {
  22. if(cb->getPlayerRelations(ai->playerID, shipyard->getObject()->getOwner()) == PlayerRelations::ENEMIES)
  23. {
  24. return fh->chooseSolution(ai->ah->howToVisitObj(dynamic_cast<const CGObjectInstance*>(shipyard)));
  25. }
  26. if(shipyard->shipyardStatus() != IShipyard::GOOD)
  27. {
  28. throw cannotFulfillGoalException("Shipyard is busy.");
  29. }
  30. TResources boatCost;
  31. shipyard->getBoatCost(boatCost);
  32. return ai->ah->whatToDo(boatCost, this->iAmElementar());
  33. }
  34. void BuildBoat::accept(VCAI * ai)
  35. {
  36. TResources boatCost;
  37. shipyard->getBoatCost(boatCost);
  38. if(!cb->getResourceAmount().canAfford(boatCost))
  39. {
  40. throw cannotFulfillGoalException("Can not afford boat");
  41. }
  42. if(cb->getPlayerRelations(ai->playerID, shipyard->getObject()->getOwner()) == PlayerRelations::ENEMIES)
  43. {
  44. throw cannotFulfillGoalException("Can not build boat in enemy shipyard");
  45. }
  46. if(shipyard->shipyardStatus() != IShipyard::GOOD)
  47. {
  48. throw cannotFulfillGoalException("Shipyard is busy.");
  49. }
  50. logAi->trace(
  51. "Building boat at shipyard located at %s, estimated boat position %s",
  52. shipyard->getObject()->visitablePos().toString(),
  53. shipyard->bestLocation().toString());
  54. cb->buildBoat(shipyard);
  55. throw goalFulfilledException(sptr(*this));
  56. }
  57. std::string BuildBoat::name() const
  58. {
  59. return "BuildBoat";
  60. }
  61. std::string BuildBoat::completeMessage() const
  62. {
  63. return "Boat have been built at " + shipyard->getObject()->visitablePos().toString();
  64. }