1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-16 10:19:47 +02:00
vcmi/AI/VCAI/Goals/BuildBoat.cpp

80 lines
1.9 KiB
C++
Raw Normal View History

2018-12-01 10:30:37 +02:00
/*
* BuildBoat.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "BuildBoat.h"
#include "../VCAI.h"
#include "../FuzzyHelper.h"
#include "../AIhelper.h"
using namespace Goals;
bool BuildBoat::operator==(const BuildBoat & other) const
{
2023-06-07 00:55:21 +02:00
return shipyard == other.shipyard;
2018-12-01 10:30:37 +02:00
}
TSubgoal BuildBoat::whatToDoToAchieve()
{
2023-06-07 00:55:21 +02:00
if(cb->getPlayerRelations(ai->playerID, shipyard->getObject()->getOwner()) == PlayerRelations::ENEMIES)
2018-12-01 10:30:37 +02:00
{
2023-06-07 00:55:21 +02:00
return fh->chooseSolution(ai->ah->howToVisitObj(dynamic_cast<const CGObjectInstance*>(shipyard)));
2018-12-01 10:30:37 +02:00
}
if(shipyard->shipyardStatus() != IShipyard::GOOD)
{
throw cannotFulfillGoalException("Shipyard is busy.");
}
TResources boatCost;
shipyard->getBoatCost(boatCost);
return ai->ah->whatToDo(boatCost, this->iAmElementar());
}
void BuildBoat::accept(VCAI * ai)
{
TResources boatCost;
shipyard->getBoatCost(boatCost);
if(!cb->getResourceAmount().canAfford(boatCost))
{
throw cannotFulfillGoalException("Can not afford boat");
}
2023-06-07 00:55:21 +02:00
if(cb->getPlayerRelations(ai->playerID, shipyard->getObject()->getOwner()) == PlayerRelations::ENEMIES)
2018-12-01 10:30:37 +02:00
{
throw cannotFulfillGoalException("Can not build boat in enemy shipyard");
}
if(shipyard->shipyardStatus() != IShipyard::GOOD)
{
throw cannotFulfillGoalException("Shipyard is busy.");
}
logAi->trace(
2023-06-07 00:55:21 +02:00
"Building boat at shipyard located at %s, estimated boat position %s",
shipyard->getObject()->visitablePos().toString(),
2018-12-01 10:30:37 +02:00
shipyard->bestLocation().toString());
cb->buildBoat(shipyard);
2019-01-07 23:33:31 +02:00
throw goalFulfilledException(sptr(*this));
2018-12-01 10:30:37 +02:00
}
std::string BuildBoat::name() const
{
return "BuildBoat";
}
std::string BuildBoat::completeMessage() const
{
2023-06-07 00:55:21 +02:00
return "Boat have been built at " + shipyard->getObject()->visitablePos().toString();
2018-12-01 10:30:37 +02:00
}