1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. Photobucket has changed its policy concerning hotlinking images and now requires an account with a $399.00 annual fee to allow hotlink. More information is available at: this link.
    Dismiss Notice
  3. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  4. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  5. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  6. Dismiss Notice
  7. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

Promotion:TurnsToLast (SDK Help needed)

Discussion in 'Civ4 - SDK/Python' started by Grey Fox, Jun 15, 2007.

  1. Grey Fox

    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?
     
  2. Yakk

    Yakk Cheftan

    Joined:
    Mar 6, 2006
    Messages:
    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.
     
  3. Impaler[WrG]

    Impaler[WrG] Civ4:Col UI programmer

    Joined:
    Dec 5, 2005
    Messages:
    1,750
    Location:
    Vallejo, California
    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.
     

Share This Page