BuildBoat.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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->o->id == other.shipyard->o->id;
  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->o->tempOwner) == 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 %s located at %s, estimated boat position %s",
  60. shipyard->o->getObjectName(),
  61. shipyard->o->visitablePos().toString(),
  62. shipyard->bestLocation().toString());
  63. cb->buildBoat(shipyard);
  64. throw goalFulfilledException(sptr(*this));
  65. }
  66. std::string BuildBoat::toString() const
  67. {
  68. return "BuildBoat";
  69. }
  70. }