BuildBoat.cpp 1.8 KB

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