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