Duke176
Warlord
All right I'm here again (hope for the last time about this changes before my 1st little mod release) - more than this seems I work better when I post here (many times I've solved my prbs while I was waiting for answers
)
Here i have my whole code I've - with helps - implemented.
I'll make a tutorial about this later if I'll understand what is not working...
From CvPlayer.cpp
All right part by part:
FIRST - I should create the counter for your reserves.
Here I tell the game to go and GET iOilReserve (identifier) when I call for function "getOilReserve()"
Here I tell the game to SET iOilReserve with iNewValue if the 2 numbers are different. Than (I guess) I force it to update screen interface.
Here I tell the game how to get iNewValue (used in SetOilReserve()).
So take the value of iOilReserve and add a value called "iChange".
SECOND - I should tell the game where to get that iChange so I create another counter that rappresents the Oil Extracted each turn from every improvement that can extract it and how much do those improvements extract each turn.
Take a look to what I saied about getOilReserve().
The same of SetOilReserve().
Here i make exactly the same this as for ChangeOilReserve(int iChange), but I add a function call: once tha gem have his resoult from ChageOilProdPerTurn it should trasfert it to changeOilReserve - that function needed iChange value from somewhere, so from here.
THIRD - I need to know how to calculate how much I produce each turn.
Here I get the VALUE I gave to the tag I've added to XML (ImprovementInfos.xml) that rappresents how many barrels are extracted each turn but Wells.
Same for Offshore Platforms.
Now let's see how many Improvements that returns you OIL Bonus do you own (I mean Improvement built + road connection) - forgot to rename the function but it works how I sayed.
And finally - here make a count of how much oil you produce each turn (this is just a standard fucntion once it will work I'll make it more balanced.
Now is: (n° of improvements able to extract) x (oil Extracted from Wells + oil Extracted from Platforms).
Than return the resoult and pass it to changeOilProdPerTurn - you needed iChange there.
So the prb:
I made some tests with python to see which part of those doesn't work and set/change/get OilReserve works; calculateOilProdPerTurn works (so also the other parts of it) . BUT HERE nothing is recived by ChangeOilProdPerTurn so nothing is passed to ChangeOilReserve and the counter always show "0" as a resoult.
Sorry for long message I wanted to be clear and prepare a Tutorial than copying this file
.
I guess my code isn't very well perfectioned but I did my best on it. (I was complitely new to Python and SDK 2 months ago.
Thx.

Here i have my whole code I've - with helps - implemented.
I'll make a tutorial about this later if I'll understand what is not working...
From CvPlayer.cpp
Code:
//-------------------------------------- OIL RESERVE ---------------------
int CvPlayer::getOilReserve()
{
return m_iOilReserve;
}
void CvPlayer::setOilReserve(int iNewValue)
{
if (getOilReserve() != iNewValue)
{
m_iOilReserve = iNewValue;
if (getID() == GC.getGameINLINE().getActivePlayer())
{
gDLL->getInterfaceIFace()->setDirty(MiscButtons_DIRTY_BIT, true);
gDLL->getInterfaceIFace()->setDirty(SelectionButtons_DIRTY_BIT, true);
gDLL->getInterfaceIFace()->setDirty(GameData_DIRTY_BIT, true);
}
}
}
void CvPlayer::changeOilReserve(int iChange)
{
setOilReserve(getOilReserve() + iChange);
}
//----------------------------------------- end ---------------------------
//------------------------------------- OIL PROD PER TURN ---------------
//Modify Oil Prod Per Turn
//get
int CvPlayer::getOilProdPerTurn()
{
return m_iOilProdPerTurn;
}
//set
void CvPlayer::setOilProdPerTurn(int iNewValue)
{
if (getOilProdPerTurn() != iNewValue)
{
m_iOilProdPerTurn = iNewValue;
if (getID() == GC.getGameINLINE().getActivePlayer())
{
gDLL->getInterfaceIFace()->setDirty(MiscButtons_DIRTY_BIT, true);
gDLL->getInterfaceIFace()->setDirty(SelectionButtons_DIRTY_BIT, true);
gDLL->getInterfaceIFace()->setDirty(GameData_DIRTY_BIT, true);
}
}
}
//change
void CvPlayer::changeOilProdPerTurn(int iChange)
{
setOilProdPerTurn(getOilProdPerTurn() + iChange);
changeOilReserve(getOilProdPerTurn());
}
//returns number = ammount of extraction per turn (from terraininfo.xml)
int CvPlayer::oilExtractionPerTurnFromWells()
{
return GC.getImprovementInfo(ImprovementTypes (GC.getInfoTypeForString("IMPROVEMENT_WELL"))).getOilExtractionPerTurn();
}
int CvPlayer::oilExtractionPerTurnFromPlatforms()
{
return GC.getImprovementInfo(ImprovementTypes (GC.getInfoTypeForString("IMPROVEMENT_OFFSHORE_PLATFORM"))).getOilExtractionPerTurn();
}
//returns number of wells
int CvPlayer::getNumAvailableOilImprovements()
{
return getNumAvailableBonuses((BonusTypes)GC.getInfoTypeForString("BONUS_OIL"));
}
//calculate Oil Prod per Turn
int CvPlayer::calculateOilProdPerTurn()
{
int iProduced;
iProduced = (getNumAvailableOilImprovements()) * ((oilExtractionPerTurnFromWells()) + (oilExtractionPerTurnFromPlatforms()));
return iProduced;
changeOilProdPerTurn(iProduced);
}
//--------------------------------------- end -----------------------------
All right part by part:
FIRST - I should create the counter for your reserves.
Code:
//-------------------------------------- OIL RESERVE -------------------------------------------
int CvPlayer::getOilReserve()
{
return m_iOilReserve;
}
Here I tell the game to go and GET iOilReserve (identifier) when I call for function "getOilReserve()"
Code:
void CvPlayer::setOilReserve(int iNewValue)
{
if (getOilReserve() != iNewValue)
{
m_iOilReserve = iNewValue;
if (getID() == GC.getGameINLINE().getActivePlayer())
{
gDLL->getInterfaceIFace()->setDirty(MiscButtons_DIRTY_BIT, true);
gDLL->getInterfaceIFace()->setDirty(SelectionButtons_DIRTY_BIT, true);
gDLL->getInterfaceIFace()->setDirty(GameData_DIRTY_BIT, true);
}
}
}
Here I tell the game to SET iOilReserve with iNewValue if the 2 numbers are different. Than (I guess) I force it to update screen interface.
Code:
void CvPlayer::changeOilReserve(int iChange)
{
setOilReserve(getOilReserve() + iChange);
}
//----------------------------------------- end ---------------------------
Here I tell the game how to get iNewValue (used in SetOilReserve()).
So take the value of iOilReserve and add a value called "iChange".
SECOND - I should tell the game where to get that iChange so I create another counter that rappresents the Oil Extracted each turn from every improvement that can extract it and how much do those improvements extract each turn.
Code:
//------------------------------------- OIL PROD PER TURN ---------------
//Modify Oil Prod Per Turn
//get
int CvPlayer::getOilProdPerTurn()
{
return m_iOilProdPerTurn;
}
Take a look to what I saied about getOilReserve().
Code:
//set
void CvPlayer::setOilProdPerTurn(int iNewValue)
{
if (getOilProdPerTurn() != iNewValue)
{
m_iOilProdPerTurn = iNewValue;
if (getID() == GC.getGameINLINE().getActivePlayer())
{
gDLL->getInterfaceIFace()->setDirty(MiscButtons_DIRTY_BIT, true);
gDLL->getInterfaceIFace()->setDirty(SelectionButtons_DIRTY_BIT, true);
gDLL->getInterfaceIFace()->setDirty(GameData_DIRTY_BIT, true);
}
}
}
The same of SetOilReserve().
Code:
//change
void CvPlayer::changeOilProdPerTurn(int iChange)
{
setOilProdPerTurn(getOilProdPerTurn() + iChange);
changeOilReserve(getOilProdPerTurn());
}
Here i make exactly the same this as for ChangeOilReserve(int iChange), but I add a function call: once tha gem have his resoult from ChageOilProdPerTurn it should trasfert it to changeOilReserve - that function needed iChange value from somewhere, so from here.
THIRD - I need to know how to calculate how much I produce each turn.
Code:
//returns number = ammount of extraction per turn (from terraininfo.xml)
int CvPlayer::oilExtractionPerTurnFromWells()
{
return GC.getImprovementInfo(ImprovementTypes (GC.getInfoTypeForString("IMPROVEMENT_WELL"))).getOilExtractionPerTurn();
}
Here I get the VALUE I gave to the tag I've added to XML (ImprovementInfos.xml) that rappresents how many barrels are extracted each turn but Wells.
Code:
int CvPlayer::oilExtractionPerTurnFromPlatforms()
{
return GC.getImprovementInfo(ImprovementTypes (GC.getInfoTypeForString("IMPROVEMENT_OFFSHORE_PLATFORM"))).getOilExtractionPerTurn();
}
Same for Offshore Platforms.
Code:
//returns number of wells
int CvPlayer::getNumAvailableOilImprovements()
{
return getNumAvailableBonuses((BonusTypes)GC.getInfoTypeForString("BONUS_OIL"));
}
Now let's see how many Improvements that returns you OIL Bonus do you own (I mean Improvement built + road connection) - forgot to rename the function but it works how I sayed.
Code:
//calculate Oil Prod per Turn
int CvPlayer::calculateOilProdPerTurn()
{
int iProduced;
iProduced = (getNumAvailableOilImprovements()) * ((oilExtractionPerTurnFromWells()) + (oilExtractionPerTurnFromPlatforms()));
return iProduced;
changeOilProdPerTurn(iProduced);
}
//--------------------------------------- end -----------------------------
And finally - here make a count of how much oil you produce each turn (this is just a standard fucntion once it will work I'll make it more balanced.
Now is: (n° of improvements able to extract) x (oil Extracted from Wells + oil Extracted from Platforms).
Than return the resoult and pass it to changeOilProdPerTurn - you needed iChange there.
So the prb:
I made some tests with python to see which part of those doesn't work and set/change/get OilReserve works; calculateOilProdPerTurn works (so also the other parts of it) . BUT HERE nothing is recived by ChangeOilProdPerTurn so nothing is passed to ChangeOilReserve and the counter always show "0" as a resoult.
Sorry for long message I wanted to be clear and prepare a Tutorial than copying this file

I guess my code isn't very well perfectioned but I did my best on it. (I was complitely new to Python and SDK 2 months ago.
Thx.