BuildBoat.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 "../VCAI.h"
  13. #include "../FuzzyHelper.h"
  14. #include "../AIhelper.h"
  15. #include "../../../lib/mapping/CMap.h" //for victory conditions
  16. #include "../../../lib/CPathfinder.h"
  17. extern boost::thread_specific_ptr<CCallback> cb;
  18. extern boost::thread_specific_ptr<VCAI> ai;
  19. extern FuzzyHelper * fh;
  20. using namespace Goals;
  21. bool BuildBoat::operator==(const BuildBoat & other) const
  22. {
  23. return shipyard->o->id == other.shipyard->o->id;
  24. }
  25. //TSubgoal BuildBoat::whatToDoToAchieve()
  26. //{
  27. // if(cb->getPlayerRelations(ai->playerID, shipyard->o->tempOwner) == PlayerRelations::ENEMIES)
  28. // {
  29. // return fh->chooseSolution(ai->ah->howToVisitObj(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 ai->ah->whatToDo(boatCost, this->iAmElementar());
  41. //}
  42. void BuildBoat::accept(VCAI * 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::name() const
  67. {
  68. return "BuildBoat";
  69. }