/*Jamie's Rome Mod 1.3/2.1 code - Start*/
void CvGame::doCustomCode()
{
//Custom code constants
int iChanceNewStormSeaTimes100 = GC.getDefineINT("STORM_CHANCE_SEA");
int iChanceNewStormLandTimes100 = GC.getDefineINT("STORM_CHANCE_LAND");
int iMaxDuration = GC.getDefineINT("STORM_MAX_DURATION");
int iMinDuration = GC.getDefineINT("STORM_MIN_DURATION");
int iMaxStorms = GC.getDefineINT("STORM_MAX_PRESENT");
int iMaxChecks = GC.getDefineINT("STORM_MAX_CHECKS");
/* Experimental Code - this code is designed to be more randomly representative within the population*/
int i = 0;
while (i <= iMaxChecks /*Only try this for iMaxChecks amount of times!!! */&& GC.getMapINLINE().getNumStorms() <= (iMaxStorms - getSorenRandNum(iMaxStorms, "STORM: Should we decrease the max number this turn?")))
{
CvPlot * pPlot = GC.getMapINLINE().plotByIndex(getSorenRandNum(GC.getMapINLINE().numPlots(), "STORM: Pick a plot"));
if (pPlot->isWater() && getSorenRandNum(1000000, "STORM: Spawning Sea Storm?") < iChanceNewStormSeaTimes100 && pPlot->getArea() != GC.getMap().plot(87, 51)->getArea())
{
if (!pPlot->hasStorm())
{
GC.getMap().changeNumStorms(1);
pPlot->setHasStorm(true);
gDLL->getInterfaceIFace()->addMessage(pPlot->getOwner(), true, GC.getEVENT_MESSAGE_TIME(), gDLL->getText("TXT_KEY_STORM_STRUCK_US"),"AS2D_STORM_STUCK", MESSAGE_TYPE_MINOR_EVENT, ARTFILEMGR.getInterfaceArtInfo("STORM_BUTTON")->getPath(), (ColorTypes) GC.getInfoTypeForString("COLOR_STORM_TEXT"), pPlot->getX_INLINE(), pPlot->getY_INLINE(), true, true);
}
pPlot->setStormTime(std::max(iMinDuration, getSorenRandNum(iMaxDuration + 1, "STORM: How long?")));
}
else
{
if (getSorenRandNum(1000000, "STORM: Spawning Land Storm?") < iChanceNewStormLandTimes100)
{
if (!pPlot->hasStorm())
{
GC.getMap().changeNumStorms(1);
pPlot->setHasStorm(true);
gDLL->getInterfaceIFace()->addMessage(pPlot->getOwner(), true, GC.getEVENT_MESSAGE_TIME(), gDLL->getText("TXT_KEY_STORM_STRUCK_US"),"AS2D_STORM_STUCK", MESSAGE_TYPE_MINOR_EVENT, ARTFILEMGR.getInterfaceArtInfo("STORM_BUTTON")->getPath(), (ColorTypes) GC.getInfoTypeForString("COLOR_STORM_TEXT"), pPlot->getX_INLINE(), pPlot->getY_INLINE(), true, true);
}
pPlot->setStormTime(std::max(iMinDuration, getSorenRandNum(iMaxDuration + 1, "STORM: How long?")));
}
}
i++;
}
/* Experimental Code */
for (int i = 0; i<GC.getMapINLINE().numPlots(); i++)
{
CvPlot * pPlot = GC.getMapINLINE().plotByIndex(i);
/*Jamie's Rome Mod 1.3/2.1 Storms code - Start*/
/*
if (GC.getMapINLINE().getNumStorms() < GC.getDefineINT("STORM_MAX_PRESENT"))
{
if (pPlot->isWater() && getSorenRandNum(1000000, "STORM: Spawning Sea Storm?") < iChanceNewStormSeaTimes100 && pPlot->getArea() != GC.getMap().plot(87, 51)->getArea())
{
if (!pPlot->hasStorm())
{
GC.getMap().changeNumStorms(1);
pPlot->setHasStorm(true);
gDLL->getInterfaceIFace()->addMessage(pPlot->getOwner(), true, GC.getEVENT_MESSAGE_TIME(), gDLL->getText("TXT_KEY_STORM_STRUCK_US"),"AS2D_STORM_STUCK", MESSAGE_TYPE_MINOR_EVENT, ARTFILEMGR.getInterfaceArtInfo("STORM_BUTTON")->getPath(), (ColorTypes) GC.getInfoTypeForString("COLOR_STORM_TEXT"), pPlot->getX_INLINE(), pPlot->getY_INLINE(), true, true);
}
pPlot->setStormTime(std::max(iMinDuration, getSorenRandNum(iMaxDuration + 1, "STORM: How long?")));
}
else
{
if (getSorenRandNum(1000000, "STORM: Spawning Land Storm?") < iChanceNewStormLandTimes100)
{
if (!pPlot->hasStorm())
{
GC.getMap().changeNumStorms(1);
pPlot->setHasStorm(true);
gDLL->getInterfaceIFace()->addMessage(pPlot->getOwner(), true, GC.getEVENT_MESSAGE_TIME(), gDLL->getText("TXT_KEY_STORM_STRUCK_US"),"AS2D_STORM_STUCK", MESSAGE_TYPE_MINOR_EVENT, ARTFILEMGR.getInterfaceArtInfo("STORM_BUTTON")->getPath(), (ColorTypes) GC.getInfoTypeForString("COLOR_STORM_TEXT"), pPlot->getX_INLINE(), pPlot->getY_INLINE(), true, true);
}
pPlot->setStormTime(std::max(iMinDuration, getSorenRandNum(iMaxDuration + 1, "STORM: How long?")));
}
}
}
*/
doStormManage(pPlot);
/*Jamie's Rome Mod 1.3/2.1 Storms code - End*/
/*Jamie's Rome Mod 1.3/2.1 Watchtower code - Start*/
//doWatchtowerManage(pPlot);
/*Jamie's Rome Mod 1.3/2.1 Watchtower code - Start*/
}
}
/*Jamie's Rome Mod 1.3/2.1 code - End*/
/*Jamie's Rome Mod 1.3/2.1 Storms code - Start*/
void CvGame::doStormManage(CvPlot * pPlot)
{
if (pPlot->hasStorm())
{
if (pPlot->getStormTime() == 0)
{
//deinit storm
pPlot->setHasStorm(false);
GC.getMap().changeNumStorms(-1);
return;
}
int iPercentPopulationLoss = GC.getDefineINT("STORM_POPULATION_LOSS_PERCENT");
int iChanceDestroyImprovement = GC.getDefineINT("STORM_IMPROVEMENT_DESTROY_CHANCE");
doStormEffect(pPlot);
pPlot->changeStormTime(-1);
//do some damage!
ImprovementTypes eImprovement = pPlot->getImprovementType();
if (pPlot->isCity())
{
CvCity * pCity = pPlot->getPlotCity();
int iPopulation = (pCity->getPopulation()*iPercentPopulationLoss/100.0)+0.5;
pCity->changePopulation(-iPopulation);
}
else if (eImprovement != NO_IMPROVEMENT && getSorenRandNum(100, "STORM: Destroying Improvement?") < iChanceDestroyImprovement)
{
if (pPlot->getImprovementType() == (ImprovementTypes) GC.getInfoTypeForString("IMPROVEMENT_HAMLET"))
{
pPlot->setImprovementType((ImprovementTypes) GC.getInfoTypeForString("IMPROVEMENT_COTTAGE"));
}
else if (pPlot->getImprovementType() == (ImprovementTypes) GC.getInfoTypeForString("IMPROVEMENT_VILLAGE"))
{
pPlot->setImprovementType((ImprovementTypes) GC.getInfoTypeForString("IMPROVEMENT_HAMLET"));
}
else if (pPlot->getImprovementType() == (ImprovementTypes) GC.getInfoTypeForString("IMPROVEMENT_TOWN"))
{
pPlot->setImprovementType((ImprovementTypes) GC.getInfoTypeForString("IMPROVEMENT_VILLAGE"));
}
else
{
pPlot->setImprovementType(NO_IMPROVEMENT);
}
gDLL->getInterfaceIFace()->addMessage(pPlot->getOwner(), true, GC.getEVENT_MESSAGE_TIME(), gDLL->getText("TXT_KEY_STORM_STRUCK_OUR_IMPROVEMENT", GC.getImprovementInfo(eImprovement).getDescription()),"AS2D_STORM_STUCK", MESSAGE_TYPE_MINOR_EVENT, ARTFILEMGR.getInterfaceArtInfo("STORM_BUTTON")->getPath(), (ColorTypes) GC.getInfoTypeForString("COLOR_STORM_TEXT"), pPlot->getX_INLINE(), pPlot->getY_INLINE(), true, true);
}
for (int i = 0; i < pPlot->getNumUnits(); i++)
{
int iDamage = getSorenRandNum(100, "STORM: How much damage to unit?");
CvUnit * pUnit = pPlot->getUnitByIndex(i);
pUnit->setDamage(std::max(iDamage, std::min(pUnit->getDamage() + iDamage, 100)));
gDLL->getInterfaceIFace()->addMessage(pUnit->getOwner(), true, GC.getEVENT_MESSAGE_TIME(), gDLL->getText("TXT_KEY_STORM_STRUCK_OUR_UNIT", pUnit->getNameKey()),"AS2D_STORM_STUCK", MESSAGE_TYPE_MINOR_EVENT, ARTFILEMGR.getInterfaceArtInfo("STORM_BUTTON")->getPath(), (ColorTypes) GC.getInfoTypeForString("COLOR_STORM_TEXT"), pPlot->getX_INLINE(), pPlot->getY_INLINE(), true, true);
}
}
return;
}
void CvGame::doStormEffect(CvPlot * pPlot)
{
gDLL->getEngineIFace()->TriggerEffect((EffectTypes) GC.getInfoTypeForString("EFFECT_STORM"), pPlot->getPoint());
}
/*Jamie's Rome Mod 1.3/2.1 Storms code - End*/