hello good sdk people of Civ4.
its probably a long shot,
but i am writing some AI code for Ranged Strike (Dale combat mod and VIP by Vncent modification).
anyway,
i wrote a function that checks if a plot is worthy of ranged attack.
i would love for thoughts and feedbacks.
appreciate any help.
its probably a long shot,
but i am writing some AI code for Ranged Strike (Dale combat mod and VIP by Vncent modification).
anyway,
i wrote a function that checks if a plot is worthy of ranged attack.
i would love for thoughts and feedbacks.
Spoiler :
Code:
int CvUnitAI::isPlotWorthRanged(CvPlot const& kPlot)const
{
int seigeCount = 0;
int dmgdUnits = 0; //how many damaged units are there
int totalLimitedDmgUnits = 0; // sum of the dmg taken by all units on the plot
int attackerCombatLimit = this->combatLimit();
CvUnit* nextUnit = NULL;
int unitCount = kPlot.getNumUnits();
//loop over all units on the pottential plot to rangestrike
for (int i = 0; i < unitCount; i++)
{
nextUnit = kPlot.getUnitByIndex(i);
if (nextUnit != NULL)
{
if (nextUnit->canRangeStrikeK())
{
seigeCount++;//count how many siege units on target plot.
}
else if
(nextUnit->getDamage() >= this->combatLimit())
{
dmgdUnits++;
totalLimitedDmgUnits+= nextUnit->getDamage();
}
}
}
int netUnits = std::max(unitCount - seigeCount,0);
if (unitCount > 0)
{
if (netUnits == dmgdUnits && attackerCombatLimit > 0 &&
(totalLimitedDmgUnits / netUnits) >= attackerCombatLimit + 10)
/* if the avg of all damange form dmged units larget than the attacker combatlimit + 10%
and all the units that are not seige are damaged, its a worthy strike
*/
return 1;
else
{
//check our stack unit content
int seigeCountUs = 0;
CvUnit* nextUnitUs = NULL;
int unitCountUs = getPlot().getNumUnits();
//loop over all units on the pottential plot that we attacked from
for (int i = 0; i < unitCountUs; i++)
{
nextUnitUs = getPlot().getUnitByIndex(i);
if (nextUnitUs != NULL)
{
if (nextUnitUs->canRangeStrikeK())
{
seigeCountUs++;//count how many siege units on target plot.
}
}
}
int netUnitsUs = std::max(unitCountUs - seigeCountUs,0);
if (netUnitsUs > 0)
{
//if we have 1/3 of stronger total attack value from the enemy plot stack
//than its a worthy ranged strike. ht /2 and /3 are just a way to make sure
//ai that attacks have enough power to attack after this ranged strike .
int ourNoneRangedSTR = (NetTotalStreangth(&getPlot()) / netUnitsUs) / 2;
int enemyNoneRangeSTR = (NetTotalStreangth(&kPlot) / netUnits) / 3;
if (ourNoneRangedSTR >= enemyNoneRangeSTR)
return 2;//will double the value of this plot on the AI_rangedStrikeValueK()
// if we have 2 more siege ranged units than the enemy,
// our added siege ranged units may even the odds after the range strike
//should add some check for how bad is the difference of power is.
if (seigeCountUs - seigeCount > 3)
return 1;
}
}
}
return 0;
}
appreciate any help.