2
0

BuildBoat.cpp 1.7 KB

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