Ok, so I had this Idea of how to help me cut down on number of promotions in my cIVRPG mod. Currently, the implementation of buffs that last more than one turn I have one promotion for every turn of the buff. i.e: WINDWALK_TURNS4, WINDWALK_TURNS3, WINDWALK_TURNS2, WINDWALK_TURNS1, etc.
So I came up with an idea of making each promotion have an attribute called TurnsToLast, which would tick down from its base value every turn till its down to 0, when the promotion would be removed from the unit.
But mid-implementation I realized that I cant change the attributes of an individual promotion on a certain unit.
So I came up with this code:
What it does is loop through all promotions, and if the unit has the promotion it checks if TurnsToLast is above 0, if it is, it calls the setTurnsToLast function, and in that function I was supposed to save the turns left in an Array with the promotion index as index.
But here is the problem, I don't understand how to save stuff in an array in the unit class. Private arrays work fine, but how do I store an array in the PROTECTED MEMBER VARIABLES - I can't find an example to copy.
And how do I initialize/reset the variable? Most variables are reset/initialized like this: m_iVariable = 0; - but how do I do that for an array?
And do anyone have a better/simpler idea of how to implement this functionality?
So I came up with an idea of making each promotion have an attribute called TurnsToLast, which would tick down from its base value every turn till its down to 0, when the promotion would be removed from the unit.
But mid-implementation I realized that I cant change the attributes of an individual promotion on a certain unit.
So I came up with this code:
Code:
in CvUnit::doTurn()
for ( int iI; iI <GC.getNumPromotionInfos(); iI++)
{
if (isHasPromotion((PromotionTypes)iI))
{
if (GC.getPromotionInfo((PromotionTypes)iI).getBuffTurnsToLast() > 0)
{
if (getBuffTurnsToLast(iI) == 0)
{
setBuffTurnsToLast(iI, GC.getPromotionInfo((PromotionTypes)iI).getBuffTurnsToLast() - 1);
}
else
{
setBuffTurnsToLast(getBuffTurnsToLast(iI) - 1);
}
if ((GC.getPromotionInfo((PromotionTypes)iI).getBuffTurnsToLast() == 1) || (getBuffTurnsToLast(iI) == 1))
{
setHasPromotion(((PromotionTypes)iI), false);
}
}
}
}
But here is the problem, I don't understand how to save stuff in an array in the unit class. Private arrays work fine, but how do I store an array in the PROTECTED MEMBER VARIABLES - I can't find an example to copy.
And how do I initialize/reset the variable? Most variables are reset/initialized like this: m_iVariable = 0; - but how do I do that for an array?
And do anyone have a better/simpler idea of how to implement this functionality?