Some people were complaining, that events always choose the same unit. This is some code from the unmodded BtS-SDK, form CvPlayer.cpp (I suppose that Kael didn't change this):
If you can read C++-code try to simulate this code an suppose that getTriggerValue always returns 0 (or always the same number). If I'm not mistaken the result will be that pUnit will point to the first unit and apUnits will contain all the others. So the last if-statement wont get executed and pUnit (= the first unit) will be picked.
That seems to be consistent with what some people have reported.
The whole thing doesn't make a lot of sense to me. I suppose that they want to put all units that get the same value in the array and then pick one.
I think it should look like this:
By the way: The same applies to pickTriggerCity.
Code:
CvUnit* CvPlayer::pickTriggerUnit(EventTriggerTypes eTrigger, CvPlot* pPlot, bool bPickPlot) const
{
CvUnit* pUnit = NULL;
std::vector<CvUnit*> apUnits;
int iLoop;
int iBestValue = MIN_INT;
for (CvUnit* pLoopUnit = firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = nextUnit(&iLoop))
{
int iValue = pLoopUnit->getTriggerValue(eTrigger, pPlot, bPickPlot);
if (iValue > iBestValue)
{
if (NULL != pUnit)
{
apUnits.push_back(pUnit);
}
iBestValue = iValue;
pUnit = pLoopUnit;
}
else if (MIN_INT != iValue)
{
apUnits.push_back(pLoopUnit);
}
}
if (NULL == pUnit && apUnits.size() > 0)
{
int iChosen = GC.getGameINLINE().getSorenRandNum(apUnits.size(), "Event pick unit");
pUnit = apUnits[iChosen];
}
return pUnit;
}
If you can read C++-code try to simulate this code an suppose that getTriggerValue always returns 0 (or always the same number). If I'm not mistaken the result will be that pUnit will point to the first unit and apUnits will contain all the others. So the last if-statement wont get executed and pUnit (= the first unit) will be picked.
That seems to be consistent with what some people have reported.
The whole thing doesn't make a lot of sense to me. I suppose that they want to put all units that get the same value in the array and then pick one.
I think it should look like this:
Code:
CvUnit* CvPlayer::pickTriggerUnit(EventTriggerTypes eTrigger, CvPlot* pPlot, bool bPickPlot) const
{
CvUnit* pUnit = NULL;
std::vector<CvUnit*> apUnits;
int iLoop;
int iBestValue = MIN_INT;
for (CvUnit* pLoopUnit = firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = nextUnit(&iLoop))
{
int iValue = pLoopUnit->getTriggerValue(eTrigger, pPlot, bPickPlot);
if (iValue != MIN_INT)
{
if (iValue > iBestValue)
{
apUnits.clear;
iBestValue = iValue;
pUnit = pLoopUnit;
}
else if (iValue == iBestValue)
{
if (pUnit != NULL)
{
apUnits.push_back(pUnit);
pUnit = NULL;
}
apUnits.push_back(pLoopUnit);
}
}
}
if (NULL == pUnit && apUnits.size() > 0)
{
int iChosen = GC.getGameINLINE().getSorenRandNum(apUnits.size(), "Event pick unit");
pUnit = apUnits[iChosen];
}
return pUnit;
}
By the way: The same applies to pickTriggerCity.