CvUnit* CvSelectionGroupAI::AI_ejectBestDefender(CvPlot* pDefendPlot) { CLLNode<IDInfo>* pEntityNode; CvUnit* pLoopUnit; pEntityNode = headUnitNode(); CvUnit* pBestUnit = NULL; int iBestUnitValue = 0; while (pEntityNode != NULL) { pLoopUnit = ::getUnit(pEntityNode->m_data); pEntityNode = nextUnitNode(pEntityNode); //if (!pLoopUnit->noDefensiveBonus()) // commented out by K-Mod. The noDefBonus thing is already taken into account. { int iValue = pLoopUnit->currEffectiveStr(pDefendPlot, NULL) * 100; if (pDefendPlot->isCity(true, getTeam())) { iValue *= 100 + pLoopUnit->cityDefenseModifier(); iValue /= 100; } iValue *= 100; iValue /= (100 + pLoopUnit->cityAttackModifier() + pLoopUnit->getExtraCityAttackPercent()); iValue /= 2 + pLoopUnit->getLevel(); if (iValue > iBestUnitValue) { iBestUnitValue = iValue; pBestUnit = pLoopUnit; } } } if (NULL != pBestUnit && getNumUnits() > 1) { pBestUnit->joinGroup(NULL); } return pBestUnit; }