bool CvCityAI::AI_chooseUnit(const char* reason, UnitAITypes eUnitAI, int iOdds, int iUnitStrength, int iPriorityOverride, CvUnitSelectionCriteria* criteria, UnitTypes eUnitType)
{//Adding a unit type direct selection here...
CvString unitAIType;
#ifdef USE_UNIT_TENDERING
// Have we already contracted for a unit?
if ( m_bRequestedUnit )
{
return false;
}
#endif
if( iOdds < 0 || getCitySorenRandNum(100, "City AI choose unit") < iOdds )
{
if ( iPriorityOverride == -1 )
{
iPriorityOverride = m_iTempBuildPriority;
}
if (eUnitAI != NO_UNITAI)
{
CvInfoBase& AIType = GC.getUnitAIInfo(eUnitAI);
unitAIType = AIType.getType();
}
else
{
unitAIType = "NO_UNITAI";
}
#ifdef USE_UNIT_TENDERING
if ( !isNPC() )
{
// Check someone can build a suitable unit before putting out a tender for one.
if ( eUnitAI == NO_UNITAI || eUnitType != NO_UNIT || GET_PLAYER(getOwnerINLINE()).bestBuildableUnitForAIType(NO_DOMAIN, eUnitAI, criteria) != NO_UNIT )
{
if( gCityLogLevel >= 2 )
{
logBBAI(" City %S pop %d puts out tenders for %d unit strength of AIType: %s at priority %d (reason: %s)", getName().GetCString(), getPopulation(), iUnitStrength, unitAIType.c_str(), iPriorityOverride, reason);
}
// Put out a tender for this unit
GET_PLAYER(getOwnerINLINE()).getContractBroker().advertiseWork(iPriorityOverride,
NO_UNITCAPABILITIES,
getX_INLINE(),
getY_INLINE(),
NULL,
eUnitAI,
iUnitStrength,
criteria,
MAX_INT,
eUnitType);
m_bRequestedUnit = true;
return m_bRequestedBuilding;
}
// Looks like we probably can't build it, but fallback check if we can ourselves, and if so just
// queue it here (handles edge cases where building requirements mean it can be built locally but
// not in capital or best coastal). Do this by falling through to local handling
}
#endif
return AI_chooseUnitImmediate(reason, eUnitAI, criteria, eUnitType);
}
return false;
}