Promotion:TurnsToLast (SDK Help needed) - Civilization Fanatics' Forums
Civilization Fanatics' Center  

(US | UK | DE | CA)

Go Back   Civilization Fanatics' Forums > CIVILIZATION IV > Civ4 - Creation & Customization > Civ4 - SDK/Python

Civ4 - SDK/Python Forum for C++/Python modding questions/topics.

Thread Tools
Old Jun 15, 2007, 12:41 PM   #1
Grey Fox
Master of Points
Grey Fox's Avatar
Join Date: Dec 2001
Location: Sweden
Posts: 8,726
Images: 1
Promotion:TurnsToLast (SDK Help needed)

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:
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);
                    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?
Grey Fox is offline   Reply With Quote
Old Jun 15, 2007, 12:55 PM   #2
Join Date: Mar 2006
Posts: 1,288
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.
Yakk is offline   Reply With Quote
Old Jun 15, 2007, 12:57 PM   #3
Civ4:Col UI programmer
Impaler[WrG]'s Avatar
Join Date: Dec 2005
Location: Vallejo, California
Posts: 1,750
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.
Companions the creator seeks, not corpses, not herds and believers. Fellow creators, the creator seeks - those who write new values on new tablets. Companions the creator seeks, and fellow harvesters; for everything about him is ripe for the harvest. - Thus spoke Zarathustra, Fredrick Nietzsche

Civ 4 Community Core Project One DLL to Rule them ALL, Now a part of WoC, 3.02 version in the Progress
Modular XML Loading 3.0 True Drag and Drop modability, Included by Firaxis in Beyond the Sword
World Of Civilization A World of Mods under one roof
Impaler[WrG] is offline   Reply With Quote

Go Back Civilization Fanatics' Forums > CIVILIZATION IV > Civ4 - Creation & Customization > Civ4 - SDK/Python > Promotion:TurnsToLast (SDK Help needed)

Thread Tools

All times are GMT -6. The time now is 09:45 AM.

Civilization VI release date is 10/21! Pre-order now: US | UK | DE | CA
Powered by vBulletin®
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.
This site is copyright © Civilization Fanatics' Center.