Manco Capac
Friday,13 June,I Collapse
- Joined
- Mar 1, 2010
- Messages
- 8,051
Code:
int CvSelectionGroupAI::AI_compareStacks(const CvPlot* pPlot, bool bCheckCanAttack) const
{
FAssert(pPlot != NULL);
int compareRatio;
DomainTypes eDomainType = getDomainType();
// if not aircraft, then choose based on the plot, not the head unit (mainly for transport carried units)
if (eDomainType != DOMAIN_AIR)
{
if (pPlot->isWater())
eDomainType = DOMAIN_SEA;
else
eDomainType = DOMAIN_LAND;
}
compareRatio = AI_sumStrength(pPlot, eDomainType, bCheckCanAttack);
compareRatio *= 100;
PlayerTypes eOwner = getOwnerINLINE();
if (eOwner == NO_PLAYER)
{
eOwner = getHeadOwner();
}
FAssert(eOwner != NO_PLAYER);
// K-Mod. Note. This function currently does not support bPotentialEnemy == false.
//FAssert(bPotentialEnemy);
int defenderSum = pPlot->isVisible(getHeadTeam(), false)
? GET_PLAYER(eOwner).AI_localDefenceStrength(pPlot, NO_TEAM, eDomainType, 0)
: GET_TEAM(getHeadTeam()).AI_getStrengthMemory(pPlot);
// K-Mod end
compareRatio /= std::max(1, defenderSum);
return compareRatio;
}
====
Code:
int CvSelectionGroupAI::AI_sumStrength(const CvPlot* pAttackedPlot, DomainTypes eDomainType, bool bCheckCanAttack) const
{
CLLNode<IDInfo>* pUnitNode;
CvUnit* pLoopUnit;
int strSum = 0;
bool bDefenders = pAttackedPlot ? pAttackedPlot->isVisibleEnemyUnit(getHeadOwner()) : false; // K-Mod
bool bCountCollateral = pAttackedPlot && pAttackedPlot != plot(); // K-Mod
pUnitNode = headUnitNode();
int iBaseCollateral = bCountCollateral
? iBaseCollateral = estimateCollateralWeight(pAttackedPlot, pAttackedPlot->getTeam() == getTeam() ? NO_TEAM : pAttackedPlot->getTeam())
: 0;
while (pUnitNode != NULL)
{
pLoopUnit = ::getUnit(pUnitNode->m_data);
pUnitNode = nextUnitNode(pUnitNode);
if (!pLoopUnit->isDead())
{
// K-Mod. (original checks deleted.)
if (bCheckCanAttack)
{
if (pLoopUnit->getDomainType() == DOMAIN_AIR)
{
if (!pLoopUnit->canAirAttack() || !pLoopUnit->canMove() || (pAttackedPlot && bDefenders && !pLoopUnit->canMoveInto(pAttackedPlot, true, true)))
continue; // can't attack.
}
else
{
if (!pLoopUnit->canAttack() || !pLoopUnit->canMove()
|| (pAttackedPlot && bDefenders && !pLoopUnit->canMoveInto(pAttackedPlot, true, true))
|| (!pLoopUnit->isBlitz() && pLoopUnit->isMadeAttack()))
continue; // can't attack.
}
}
// K-Mod end
if (eDomainType == NO_DOMAIN || pLoopUnit->getDomainType() == eDomainType)
{
// strSum += pLoopUnit->currEffectiveStr(pAttackedPlot, pLoopUnit);
// K-Mod estimate the value of first strike, and the attack power of collateral units.
// (cf with calculation in CvPlayerAI::AI_localAttackStrength)
int iUnitStr = pLoopUnit->currEffectiveStr(pAttackedPlot, pLoopUnit);
iUnitStr *= 100 + 4 * pLoopUnit->firstStrikes() + 2 * pLoopUnit->chanceFirstStrikes();
iUnitStr /= 100;
if (bCountCollateral && pLoopUnit->collateralDamage() > 0)
{
int iPossibleTargets = pLoopUnit->collateralDamageMaxUnits();
// If !bCheckCanAttack, then lets not assume pAttackPlot won't get more units on it.
if (bCheckCanAttack && pAttackedPlot->isVisible(getTeam(), false))
iPossibleTargets = std::min(iPossibleTargets, pAttackedPlot->getNumVisibleEnemyDefenders(pLoopUnit) - 1);
if (iPossibleTargets > 0)
{
// collateral damage is not trivial to calculate. This estimate is pretty rough.
// (Note: collateralDamage() and iBaseCollateral both include factors of 100.)
iUnitStr += pLoopUnit->baseCombatStr() * iBaseCollateral * pLoopUnit->collateralDamage() * iPossibleTargets / 10000;
}
}
strSum += iUnitStr;
// K-Mod end
}
}
}
return strSum;
}
Trying to make organize stuff...