Advertisement
Civilization Fanatics' Center  

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

Reply
 
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,727
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:
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?
__________________
GreyFox.ME - a blog about Gaming and Me | Latest Article | Latest Comic | Latest Image | Latest Video
@GreyFoxMe
| ~SolidDread | Read Welcome To China! | My Mods | Chat about FfH stuff @ #erebus

Member of the R i f E team. | Rise from Erebus - R i f E | Blog| Wiki | Forum
Grey Fox is offline   Reply With Quote
Old Jun 15, 2007, 12:55 PM   #2
Yakk
Cheftan
 
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
Impaler[WrG]
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
Reply

Bookmarks

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

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling SDK, help needed Anon Zytose Civ4 - SDK/Python 13 Jun 11, 2008 02:30 PM
Help needed about cities (SDK, python & SDK+python) Fabrysse Civ4 - SDK/Python 3 Nov 05, 2007 01:31 AM
[XML/SDK] Extra Promotion Modifiers for BTS 3.13 Phristen Civ4 - Mod Components 1 Oct 13, 2007 06:06 PM
How many XPs are needed for promotion? Heroes Civ4 - Strategy & Tips 1 Oct 29, 2005 06:16 AM
Team Description needed for Game Promotion fe3333au Team M.I.A. 14 Oct 13, 2005 09:37 AM


Advertisement

All times are GMT -6. The time now is 02:44 AM.


Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
This site is copyright Civilization Fanatics' Center.
Support CFC: Amazon.com | Amazon UK | Amazon DE | Amazon CA | Amazon FR