Hi guys, so I have managed to sort of break something that one of my play testers kindly pointed out, and I need some help in fixing the code to make it do what it is supposed and also to not explode in everyones face!
This is the code:
This is what is going wrong.
First of all the code is running even if a units RANGE_COMBAT_DAMAGE is 0, so I need a bit of code that will say if RANGE_COMBAT_DAMAGE = 0 then skip OR something like if RANGE_COMBAT_DAMAGE is greater than 0 run the code.
Second issue is that the iTheirStrength seems to be referencing the defender iaircombat value rather than their icombat value. which is not what I want, so i need to figure out why it is looking up that value and not the icombat value for the defender.
I THINK those are the only issues...
As always help is much appreciated and please be gentle with my poor useless brain
Any other info or any files that would be of help, just ask and I shall do my best to supply you with whatever is needed
This is the code:
Spoiler :
Code:
// Dale - SA: Opp Fire START
void CvUnit::doOpportunityFire()
{
int iI, iUnitDamage;
int iOurStrength;
int iTheirStrength;
CvPlot* pPlot;
CvPlot* pLoopPlot;
CvPlot* pAttackPlot = NULL;
CvUnit* pDefender = NULL;
CvWString szBuffer;
if (!GC.isDCM_OPP_FIRE())
{
return;
}
if (getFortifyTurns() > 0)
{
for (iI = 0; iI < NUM_DIRECTION_TYPES; iI++)
{
pLoopPlot = plotDirection(plot()->getX_INLINE(), plot()->getY_INLINE(), ((DirectionTypes)iI));
if (pLoopPlot != NULL)
{
if (pLoopPlot->getNumUnits() > 0)
{
pDefender = pLoopPlot->getBestDefender(NO_PLAYER, getOwnerINLINE(), this, true);
if (pDefender != NULL)
{
pPlot = pDefender->plot();
iOurStrength = airCurrCombatStr(pDefender);
FAssertMsg(iOurStrength > 0, "Combat strength is expected to be greater than zero");
iTheirStrength = pDefender->maxCombatStr(pPlot, this);
iUnitDamage = std::max(1, ((GC.getDefineINT("RANGE_COMBAT_DAMAGE")) * (iOurStrength) / (iTheirStrength)));
pDefender->changeDamage(iUnitDamage, getOwner());
szBuffer = gDLL->getText("TXT_KEY_MISC_YOU_OPP_FIRE", getNameKey(), pDefender->getNameKey());
gDLL->getInterfaceIFace()->addMessage(getOwnerINLINE(), true, GC.getEVENT_MESSAGE_TIME(), szBuffer, "AS2D_OUR_WITHDRAWL", MESSAGE_TYPE_INFO, getButton(), (ColorTypes)GC.getInfoTypeForString("COLOR_GREEN"), plot()->getX_INLINE(), plot()->getY_INLINE(), true, true);
szBuffer = gDLL->getText("TXT_KEY_MISC_ENEMY_OPP_FIRE", getNameKey(), pDefender->getNameKey());
gDLL->getInterfaceIFace()->addMessage(pDefender->getOwnerINLINE(), true, GC.getEVENT_MESSAGE_TIME(), szBuffer, "AS2D_THEIR_WITHDRAWL", MESSAGE_TYPE_INFO, getButton(), (ColorTypes)GC.getInfoTypeForString("COLOR_RED"), plot()->getX_INLINE(), plot()->getY_INLINE(), true, true);
if (pLoopPlot->isActiveVisible(false))
{
// Bombard entity mission
CvMissionDefinition kDefiniton;
kDefiniton.setMissionTime(GC.getMissionInfo(MISSION_BOMBARD).getTime() * gDLL->getSecsPerTurn());
kDefiniton.setMissionType(MISSION_BOMBARD);
kDefiniton.setPlot(pLoopPlot);
kDefiniton.setUnit(BATTLE_UNIT_ATTACKER, this);
kDefiniton.setUnit(BATTLE_UNIT_DEFENDER, pDefender);
gDLL->getEntityIFace()->AddMission(&kDefiniton);
}
}
}
}
}
}
}
// Dale - SA: Opp Fire END
This is what is going wrong.
First of all the code is running even if a units RANGE_COMBAT_DAMAGE is 0, so I need a bit of code that will say if RANGE_COMBAT_DAMAGE = 0 then skip OR something like if RANGE_COMBAT_DAMAGE is greater than 0 run the code.
Second issue is that the iTheirStrength seems to be referencing the defender iaircombat value rather than their icombat value. which is not what I want, so i need to figure out why it is looking up that value and not the icombat value for the defender.
I THINK those are the only issues...
As always help is much appreciated and please be gentle with my poor useless brain
Any other info or any files that would be of help, just ask and I shall do my best to supply you with whatever is needed