int CvUnit::GetPower() const
{
VALIDATE_OBJECT
int iPower = getUnitInfo().GetPower();
//Take promotions into account: unit with 4 promotions worth > ~50% more
iPower = int((float) iPower * pow((double) getLevel(), 0.3));
iPower *= GetCurrHitPoints();
iPower /= GetMaxHitPoints();
return iPower;
}
How to calculate player's current military might:
TotalUnitPower = Add every unit's power together, divide the unit's power by half if it's a naval unit.
GoldMultiplier = 1 + (sqrt(YourCurrentGold) / 100)
GoldMultiplier cannot be higher than 2 (will only happen if you have 10,000 gold).
Calculating might formula:
Total Might = (TotalUnitPower * GoldMultiplier).
Let's assume you have 2500 gold in your treasury, then the multiplier becomes 1 + (sqrt(2500) / 100) = 1 + (50/100) = 1.5.
If you then had 235 total unit power, the final might value is: 352.5.
Relevant code:
int CvPlayer::calculateMilitaryMight() const
{
int rtnValue = 0;
const CvUnit* pLoopUnit;
int iLoop;
for(pLoopUnit = firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = nextUnit(&iLoop))
{
// Current combat strength or bombard strength, whichever is higher
int iPower = pLoopUnit->GetPower();
if (pLoopUnit->getDomainType() == DOMAIN_SEA)
{
iPower /= 2;
}
rtnValue += iPower;
}
//Simplistic increase based on player's gold
//500 gold will increase might by 22%, 2000 by 45%, 8000 gold by 90%
float fGoldMultiplier = 1.0f + (sqrt((float)GetTreasury()->GetGold()) / 100.0f);
if(fGoldMultiplier > 2.0f) fGoldMultiplier = 2.0f;
rtnValue = (int)(rtnValue * fGoldMultiplier);
return rtnValue;
}
The AI always considers you to have at least 30 strength, so add this to the military might value. So in the above example, you now have 382.5 strength.
Now the AI takes a ratio:
Military Ratio = (TheirMilitaryMight) * 100 / OurMilitaryStrength
If we (the AI) have 250 strength and they (the opponent (human or AI)) have 500 strength, then the ratio is 200, if we have 500 strength and they have 250 strength, the ratio is 50.
Now the AI does checks based on this ratio. Keep in mind if one if is satisfied the ones below it aren't, so they can't be both POWERFUL and STRONG, only one.
If ratio > 250, opponent is IMMENSE
If ratio > 165, opponent is POWERFUL
If ratio > 115, opponent is STRONG
If ratio > 85, opponent is AVERAGE
If ratio > 60, opponent is POOR,
If ratio > 40, opponent is WEAK,
If it's less than that, opponent is PATHETIC
And that's how the AI determines its military strength vs. yours!
void CvDiplomacyAI:

oUpdateOnePlayerMilitaryStrength(PlayerTypes ePlayer)
{
CvAssertMsg(ePlayer >= 0, "DIPLOMACY_AI: Invalid Player Index. Please send Jon this with your last 5 autosaves and what changelist # you're playing.");
CvAssertMsg(ePlayer < MAX_CIV_PLAYERS, "DIPLOMACY_AI: Invalid Player Index. Please send Jon this with your last 5 autosaves and what changelist # you're playing.");
StrengthTypes eMilitaryStrength;
int iBase = /*30*/ GC.getMILITARY_STRENGTH_BASE();
int iMilitaryStrength = iBase + GetPlayer()->GetMilitaryMight();
int iOtherPlayerMilitary;
int iMilitaryRatio;
if(IsPlayerValid(ePlayer, /*bMyTeamIsValid*/ true))
{
// Look at player's Military Strength
//if (GetPlayer()->GetMilitaryMight() > 0)
{
iOtherPlayerMilitary = GET_PLAYER(ePlayer).GetMilitaryMight() + iBase;
// Example: If another player has double the Military strength of us, the Ratio will be 200
iMilitaryRatio = iOtherPlayerMilitary* /*100*/ GC.getMILITARY_STRENGTH_RATIO_MULTIPLIER() / iMilitaryStrength;
}
//else
//{
// iMilitaryRatio = /*100*/ GC.getMILITARY_STRENGTH_RATIO_MULTIPLIER();
//}
//iMilitaryStrength += iMilitaryRatio;
// Now do the final assessment
if(iMilitaryRatio >= /*250*/ GC.getMILITARY_STRENGTH_IMMENSE_THRESHOLD())
eMilitaryStrength = STRENGTH_IMMENSE;
else if(iMilitaryRatio >= /*165*/ GC.getMILITARY_STRENGTH_POWERFUL_THRESHOLD())
eMilitaryStrength = STRENGTH_POWERFUL;
else if(iMilitaryRatio >= /*115*/ GC.getMILITARY_STRENGTH_STRONG_THRESHOLD())
eMilitaryStrength = STRENGTH_STRONG;
else if(iMilitaryRatio >= /*85*/ GC.getMILITARY_STRENGTH_AVERAGE_THRESHOLD())
eMilitaryStrength = STRENGTH_AVERAGE;
else if(iMilitaryRatio >= /*60*/ GC.getMILITARY_STRENGTH_POOR_THRESHOLD())
eMilitaryStrength = STRENGTH_POOR;
else if(iMilitaryRatio >= /*40*/ GC.getMILITARY_STRENGTH_WEAK_THRESHOLD())
eMilitaryStrength = STRENGTH_WEAK;
else
eMilitaryStrength = STRENGTH_PATHETIC;
// Set the value
SetPlayerMilitaryStrengthComparedToUs(ePlayer, eMilitaryStrength);
}
}