BuildBoat.cpp 1.9 KB

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