Hey all,
I'm looking into modifying the Merchant AI for CSD in order to enable the AI to actively seek out new city-state allies once it has achieved 'ally' status with a different city-state. Currently, the AI is designed to simply send a great merchant to the closest, most easily-accessible city-state (as the goal here is money- influence was just a side bonus). Is there a way to add a check to the .cpp file to get the AI to choose its city state target for both proximity and friendship/alliance status?
Here's the block of code that needs the addition. My skills in this area hover around 0%, so any and all assistance would be appreciated.
Thanks!
Gazebo
I'm looking into modifying the Merchant AI for CSD in order to enable the AI to actively seek out new city-state allies once it has achieved 'ally' status with a different city-state. Currently, the AI is designed to simply send a great merchant to the closest, most easily-accessible city-state (as the goal here is money- influence was just a side bonus). Is there a way to add a check to the .cpp file to get the AI to choose its city state target for both proximity and friendship/alliance status?
Here's the block of code that needs the addition. My skills in this area hover around 0%, so any and all assistance would be appreciated.
Thanks!
Gazebo
Spoiler :
Code:
bool CvPlayerAI::GreatMerchantWantsCash()
{
// slewis - everybody wants cash . . .
// slewis - . . . except Venice. Venice wants to buy city states, unless it already has enough cities, then it doesn't want city states.
bool bIsVenice = GetPlayerTraits()->IsNoAnnexing();
if (bIsVenice)
{
if (getNumCities() >= 4)
{
return true;
}
else
{
return false;
}
}
return true;
}
CvPlot* CvPlayerAI::FindBestMerchantTargetPlot(CvUnit* pGreatMerchant, bool bOnlySafePaths)
{
CvAssertMsg(pGreatMerchant, "pGreatMerchant is null");
if(!pGreatMerchant)
{
return NULL;
}
int iBestTurnsToReach = MAX_INT;
CvPlot* pBestTargetPlot = NULL;
int iPathTurns;
UnitHandle pMerchant = UnitHandle(pGreatMerchant);
CvTeam& kTeam = GET_TEAM(getTeam());
//bool bIsVenice = GetPlayerTraits()->IsNoAnnexing();
//bool bWantsCash = GreatMerchantWantsCash();
// Loop through each city state
for(int iI = 0; iI < MAX_PLAYERS; iI++)
{
CvPlayer& kPlayer = GET_PLAYER((PlayerTypes)iI);
if (!kPlayer.isMinorCiv())
{
continue;
}
// if I'm Venice, I don't want to send a Merchant of Venice to a buy a city that I have trade routes
// with because it's probably more valuable as a trade partner than as an owned entity
//if (!bWantsCash)
//{
// if (bIsVenice)
// {
// if (GetTrade()->IsConnectedToPlayer(kPlayer.GetID()))
// {
// continue;
// }
// }
//}
CvPlot* pCSPlot = kPlayer.getStartingPlot();
if (!pCSPlot)
{
continue;
}
if (!pCSPlot->isRevealed(getTeam()))
{
continue;
}
// Is this a minor we are friendly with?
bool bMinorCivApproachIsCorrect = (GetDiplomacyAI()->GetMinorCivApproach(kPlayer.GetID()) != MINOR_CIV_APPROACH_CONQUEST);
bool bNotAtWar = !kTeam.isAtWar(kPlayer.getTeam());
bool bNotPlanningAWar = GetDiplomacyAI()->GetWarGoal(kPlayer.GetID()) == NO_WAR_GOAL_TYPE;
if(bMinorCivApproachIsCorrect && bNotAtWar && bNotPlanningAWar)
{
// Search all the plots adjacent to this city (since can't enter the minor city plot itself)
for(int jJ = 0; jJ < NUM_DIRECTION_TYPES; jJ++)
{
CvPlot* pAdjacentPlot = plotDirection(pCSPlot->getX(), pCSPlot->getY(), ((DirectionTypes)jJ));
if(pAdjacentPlot != NULL)
{
// Make sure this is still owned by the city state and is revealed to us and isn't a water tile
//if(pAdjacentPlot->getOwner() == (PlayerTypes)iI && pAdjacentPlot->isRevealed(getTeam()) && !pAdjacentPlot->isWater())
bool bRightOwner = (pAdjacentPlot->getOwner() == (PlayerTypes)iI);
bool bIsRevealed = pAdjacentPlot->isRevealed(getTeam());
if(bRightOwner && bIsRevealed)
{
iPathTurns = TurnsToReachTarget(pMerchant, pAdjacentPlot, true /*bReusePaths*/, !bOnlySafePaths/*bIgnoreUnits*/);
if(iPathTurns < iBestTurnsToReach)
{
iBestTurnsToReach = iPathTurns;
pBestTargetPlot = pAdjacentPlot;
}
}
}
}
}
}
return pBestTargetPlot;
}