void CvUnit::setBuildUpType(PromotionLineTypes ePromotionLine, bool bRemove)
{
int iBestValue = 0;
int iValue = 0;
PromotionLineTypes eOldBuildUpType = getBuildUpType();
if (ePromotionLine == NO_PROMOTIONLINE && !bRemove)
{
//if human then send popup to select promotionline type
if (isHuman())
{
//here we go with popup
setFortifyTurns(0);
CvPopupInfo* pInfo = new CvPopupInfo(BUTTONPOPUP_CHOOSE_BUILDUP);
pInfo->setData1(getID());
gDLL->getInterfaceIFace()->addPopup(pInfo, getOwner());
}
//else Here is were we can implement some AI selection methodology.
else
{
bool bFound = false;
PromotionLineTypes eAssignPromotionLine = NO_PROMOTIONLINE;
for (std::map<PromotionLineTypes, PromotionLineKeyedInfo>::const_iterator it = m_promotionLineKeyedInfo.begin(), end = m_promotionLineKeyedInfo.end(); it != end; ++it)
{
if(it->second.m_bValidBuildUp)
{
PromotionLineTypes ePotentialPromotionLine = it->first;
for (int iI = 0; iI < GC.getPromotionLineInfo(ePotentialPromotionLine).getNumPromotions(); iI++)
{
PromotionTypes ePromotion = (PromotionTypes)GC.getPromotionLineInfo(ePotentialPromotionLine).getPromotion(iI);
if (GC.getPromotionInfo(ePromotion).getLinePriority() == 1 && canAcquirePromotion(ePromotion, false, false, false, false, false, false, true, true))
{
iValue = GET_PLAYER(getOwnerINLINE()).AI_promotionValue(ePromotion, getUnitType(), this, AI_getUnitAIType(), true);
if (iValue >= 5 && iValue >iBestValue)
{
iBestValue = iValue;
eAssignPromotionLine = ePotentialPromotionLine;
}
bFound = true;
}
}
}
}
[B][COLOR="Red"] if (!bFound && isBuildUpable())
{
establishBuildups();
setBuildUpType(NO_PROMOTIONLINE, false);
}[/COLOR][/B]
if (eOldBuildUpType != eAssignPromotionLine)
{
setFortifyTurns(0);
}
m_eCurrentBuildUpType = eAssignPromotionLine;
}
}
else
{
//the underlying build up type variable is established as ePromotionLine
m_eCurrentBuildUpType = ePromotionLine;
}
}