johnny_cash
Chieftain
Hi, first post . first off i'd like to say thanks to faichele because i am working almost entirely off his code.
If I am stockpiling bonuses from improvements that are worked in a city radius, how would I combine the stockpiles of two or more cities that are now connected?
For example: city A has stockpiled 5 iron, and city B has stockpiled 2 iron and 3 cow. they were previously unconnected, but now i built a road between the two, so they should both share a stockpile of 7 iron and 3 cow.
here is what i have so far for the cities independent of each other:
this is what stockpiles at the end of each turn:
You might recognize A LOT of this from faichele's restricted resources, however I am going a different route and would like to avoid creating a new class for trade goods, and just stick to stockpiling bonuses and using this stockpile to create other bonii .
If I am stockpiling bonuses from improvements that are worked in a city radius, how would I combine the stockpiles of two or more cities that are now connected?
For example: city A has stockpiled 5 iron, and city B has stockpiled 2 iron and 3 cow. they were previously unconnected, but now i built a road between the two, so they should both share a stockpile of 7 iron and 3 cow.
here is what i have so far for the cities independent of each other:
this is what stockpiles at the end of each turn:
Code:
void CvCity::doBonusStock()
{
long iChange;
CvPlot* pLoopPlot;
int iX, iY;
for (iX = -(CITY_PLOTS_RADIUS + 1); iX < (CITY_PLOTS_RADIUS + 1); iX++)
{
for (iY = -(CITY_PLOTS_RADIUS + 1); iY < (CITY_PLOTS_RADIUS + 1); iY++)
{
pLoopPlot = plotXY(getX_INLINE(), getY_INLINE(), iX, iY);
if (pLoopPlot != NULL)
{
if (pLoopPlot->getBonusType() != NO_BONUS)
{
CvBonusInfo& pBonusInfo = GC.getBonusInfo(pLoopPlot->getBonusType());
if (/*pLoopPlot->isConnectedTo(this) && */pLoopPlot->isBeingWorked() && pLoopPlot->getWorkingCity()->getIDInfo() == getIDInfo())
{
if (pLoopPlot->isOwned() && (pLoopPlot->getOwnerINLINE() == getOwnerINLINE()))
{
CvTeamAI& team = GET_TEAM(getTeam());
bool bCollectOK = false;
if (pBonusInfo.getTechReveal() == NO_TECH)
{
bCollectOK = true;
}
else
{
if (team.isHasTech((TechTypes) pBonusInfo.getTechReveal()))
{
bCollectOK = true;
}
}
if (bCollectOK == true)
{
if (pBonusInfo.getTechObsolete() != NO_TECH && team.isHasTech((TechTypes) pBonusInfo.getTechObsolete()))
{
bCollectOK = false;
}
}
if (bCollectOK == true)
{
iChange = getNumBonuses(pLoopPlot->getBonusType());
changeBonusStock(pLoopPlot->getBonusType(), iChange);
}
}
}
}
}
}
}
}
Code:
long CvCity::getBonusStock(BonusTypes eBonus)
{
if (m_aiBonusStock != NULL)
{
return m_aiBonusStock[(int) eBonus];
}
else
{
return -1;
}
}
void CvCity::setBonusStock(BonusTypes eBonus, long iValue)
{
if (m_aiBonusStock != NULL)
{
m_aiBonusStock[(int) eBonus] = iValue;
}
}
void CvCity::changeBonusStock(BonusTypes eBonus, long iChange)
{
if (m_aiBonusStock != NULL)
{
if (getBonusStock(eBonus) + iChange > 0)
{
setBonusStock(eBonus, getBonusStock(eBonus) + iChange);
}
else
{
setBonusStock(eBonus, 0);
}
}
}
You might recognize A LOT of this from faichele's restricted resources, however I am going a different route and would like to avoid creating a new class for trade goods, and just stick to stockpiling bonuses and using this stockpile to create other bonii .