Promotion:TurnsToLast (SDK Help needed)

Grey Fox

Master of Points
Joined
Dec 19, 2001
Messages
8,726
Location
Sweden
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:
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);
                }
            }
        }
    }
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?
 
Sadly, the real hard part is saving/loading it, not storing it in the in-memory class. :/

Figure out how to save arbitrary data on a per-unit basis first, and the rest is relatively easy.
 
Just declare a new Array of ints for the Unit in the header, copy the hasPromotion array but simply change the type from int to bool, give it its own get and set functions and initialize to value to -1 at unit instantiation (hint initialize with a loop)

Add some code in Process Promotion that checks the turn lenght of the promotion (I assume a positive none zero value is a temporary promotion and a zero is a permanent) if its a temporary then copy the length value in at the Promotions Index value.

On Process Turn loop the array, check if the value is greater then -1, if so then check if its == 0 and if so remove the promotion, then in either case decrement which will set the just removed slot to -1 again and move all the other Promotions one turn closer to removal.
 
Top Bottom