TC01
Deity
For Final Frontier Plus, Iwant to set it up so that traits can increase the number of trade routes a city has. This is to mimic some Python code in Final Frontier (that is tied to a specific trait; hence why I want to make it doable for all traits).
I already added the tag, and then added the code below (the stuff that's in red) to CvCity::getTradeRoutes():
Unfortunately this code causes a CTD when starting a game.
With a debug DLL and with VC++ attached to BTS, I see that an unhandled exception occuring on the highlighed line (in CvPlayer::findStartingPlot, see below for the entire function):
I would guess the problem is related to the fact that the Final Frontier mapscripts, which overrides findStartingPlot, place a player's starting city. Looking at the Python logs, I see that the last thing that happens before the CTD is that the mapscript places a city for player 0). But I'm not sure why that fact, plus the change I made to getTradeRoutes(), would cause this.
Any ideas as to what is wrong here? If nothing can be done I could probably do this somewhere else in the SDK, or even in Python where it was before (but using my XML tag instead of a specific trait), but I would prefer to make it work here.
I already added the tag, and then added the code below (the stuff that's in red) to CvCity::getTradeRoutes():
Code:
int CvCity::getTradeRoutes() const
{
int iTradeRoutes;
iTradeRoutes = GC.getGameINLINE().getTradeRoutes();
iTradeRoutes += GET_PLAYER(getOwnerINLINE()).getTradeRoutes();
if (isCoastal(GC.getMIN_WATER_SIZE_FOR_OCEAN()))
{
iTradeRoutes += GET_PLAYER(getOwnerINLINE()).getCoastalTradeRoutes();
}
iTradeRoutes += getExtraTradeRoutes();
[COLOR="Red"]for (int iTrait = 0; iTrait < GC.getNumTraitInfos(); iTrait++)
{
if (GET_PLAYER(getOwner()).hasTrait((TraitTypes)iTrait))
{
CvTraitInfo kTraitInfo = GC.getTraitInfo((TraitTypes)iTrait);
iTradeRoutes += kTraitInfo.getNumBonusTradeRoutes();
}
}[/COLOR]
return std::min(iTradeRoutes, GC.getDefineINT("MAX_TRADE_ROUTES"));
}
Unfortunately this code causes a CTD when starting a game.
With a debug DLL and with VC++ attached to BTS, I see that an unhandled exception occuring on the highlighed line (in CvPlayer::findStartingPlot, see below for the entire function):
Code:
CvPlot* CvPlayer::findStartingPlot(bool bRandomize)
{
PROFILE_FUNC();
long result = -1;
CyArgsList argsList;
argsList.add(getID()); // pass in this players ID
[COLOR="Red"]if (gDLL->getPythonIFace()->callFunction(gDLL->getPythonIFace()->getMapScriptModule(), "findStartingPlot", argsList.makeFunctionArgs(), &result))[/COLOR]
{
if (!gDLL->getPythonIFace()->pythonUsingDefaultImpl()) // Python override
{
CvPlot *pPlot = GC.getMapINLINE().plotByIndexINLINE(result);
if (pPlot != NULL)
{
return pPlot;
}
else
{
FAssertMsg(false, "python findStartingPlot() returned an invalid plot index!");
}
}
}
CvPlot* pLoopPlot;
bool bValid;
int iBestArea = -1;
int iValue;
int iRange;
int iI;
bool bNew = false;
if (getStartingPlot() != NULL)
{
iBestArea = getStartingPlot()->getArea();
setStartingPlot(NULL, true);
bNew = true;
}
AI_updateFoundValues(true);//this sets all plots found values to -1
if (!bNew)
{
iBestArea = findStartingArea();
}
iRange = startingPlotRange();
for(int iPass = 0; iPass < GC.getMapINLINE().maxPlotDistance(); iPass++)
{
CvPlot *pBestPlot = NULL;
int iBestValue = 0;
for (iI = 0; iI < GC.getMapINLINE().numPlotsINLINE(); iI++)
{
pLoopPlot = GC.getMapINLINE().plotByIndexINLINE(iI);
if ((iBestArea == -1) || (pLoopPlot->getArea() == iBestArea))
{
//the distance factor is now done inside foundValue
iValue = pLoopPlot->getFoundValue(getID());
if (bRandomize && iValue > 0)
{
iValue += GC.getGameINLINE().getSorenRandNum(10000, "Randomize Starting Location");
}
if (iValue > iBestValue)
{
bValid = true;
if (bValid)
{
iBestValue = iValue;
pBestPlot = pLoopPlot;
}
}
}
}
if (pBestPlot != NULL)
{
return pBestPlot;
}
FAssertMsg(iPass != 0, "CvPlayer::findStartingPlot - could not find starting plot in first pass.");
}
FAssertMsg(false, "Could not find starting plot.");
return NULL;
}
I would guess the problem is related to the fact that the Final Frontier mapscripts, which overrides findStartingPlot, place a player's starting city. Looking at the Python logs, I see that the last thing that happens before the CTD is that the mapscript places a city for player 0). But I'm not sure why that fact, plus the change I made to getTradeRoutes(), would cause this.
Any ideas as to what is wrong here? If nothing can be done I could probably do this somewhere else in the SDK, or even in Python where it was before (but using my XML tag instead of a specific trait), but I would prefer to make it work here.