1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

The Modding Q&A Thread

Discussion in 'Rhye's and Fall Modmods' started by Leoreth, Apr 2, 2011.

  1. LuKo

    LuKo The Royal Guard

    Joined:
    Aug 28, 2006
    Messages:
    1,501
    Location:
    Poland
  2. narvego

    narvego Chieftain

    Joined:
    Jan 10, 2010
    Messages:
    80
    Ooops...

    I have read about modifying DLL just now. Now I understand, what I doing wrong - I did not compiled the new DLL.

    I tried to compile this file with Dev-C++ or Microsoft Visual C++ 2008 Express Edition, but I cannot do this correctly. Maybe is too hard for me :blush:
     
  3. embryodead

    embryodead Caliph

    Joined:
    Jan 1, 2003
    Messages:
    5,179
    Location:
    basement
    Number of soldiers on the statistics page = your power * 1000 :)
    Power is just the sum of iPower of your techs, buildings, wonders and most of all - units.
    Each turn power is recalculated and saved with CvPlayer::changePower()
    You can get it using CvPlayer::getPower()

    To complete your evil plan simply modify the CvPlayer::getPower() to your liking.
    Add some conditions there, like:
    Code:
    if (getStability() < -20) return (m_iPower * 90 / 100);
    if (getStability() > 20) return (m_iPower * 110 / 100);
    return m_iPower;
    Or something more fluid, based on some math formula...
    This will affect all internal game code that relies on getPower, i.e. the AI.
     
  4. LuKo

    LuKo The Royal Guard

    Joined:
    Aug 28, 2006
    Messages:
    1,501
    Location:
    Poland
    OK, but that was the easy one :p Thanks anyway. But now how to increase power of unit in combat?
     
  5. J. pride

    J. pride King

    Joined:
    Feb 23, 2011
    Messages:
    788
    Guys,
    I think I have found the problem. Can anybody tell me whats wrong with this python exception.
     

    Attached Files:

  6. Leoreth

    Leoreth 心の怪盗団 Moderator

    Joined:
    Aug 23, 2009
    Messages:
    33,089
    Gender:
    Male
    Location:
    Leblanc
    Well, you haven't given the right arguments to changeCulture().

    The required arguments of a method are called signature, in this case it's PyCity.changeCulture(int iPlayer, int iNewValue, bool bPlots).

    iPlayer specifies the player whose culture you want to change (remember, cities can have cultures of multiple players).
    iNewValue is the new amount of culture you want to set it to.
    bPlots requires a boolean and if I get it right this decides if the game shall be notified to update the surrounding plots (i.e. in case of a border expansion). I suggest you set it as True.

    You can find these signatures by looking into the C++ code or using the modiki.
     
  7. embryodead

    embryodead Caliph

    Joined:
    Jan 1, 2003
    Messages:
    5,179
    Location:
    basement
    Wait, so you want to modify combat strength, not power?
    Well, it's doable as well, though a bit harsh gameplay wise and may be more complicated depending on how you want it to work and look.

    My way of doing it (I used it as "Luck" factor, though it's disabled in SoI):
    Look at CvUnit::resolveCombat, there are two variables there, iAttackerStrength and iDefenderStrength. Just modify them according to your formula. To get the stability, remember to use:
    GET_PLAYER(getOwnerINLINE()).getStability() - for the attacker
    GET_PLAYER(pDefender->getOwnerINLINE()).getStability() - for the defender

    If you do it before the Python callback (marked as //Added ST), the bonus should be displayed in the combat odds tooltip. If you do it after the callback, the bonus should be hidden.

    The above solution only affects combat, so units' strength will normally show base strength, at least until you check combat odds.
     
  8. J. pride

    J. pride King

    Joined:
    Feb 23, 2011
    Messages:
    788
    Im a bit confused; does this code make sense.
    PyCity.changeCulture(int iIndependent2, int i100, bool b 65,52).

    Do I insert this into riseandfall as i did before or does it go somewhere else. Im sorry im a real noob at this

    Is this for future reference or do I have to find something for this particular case
     
  9. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    No, it makes no sense whatsoever. You'd honestly be better off letting someone else do your coding for you.

    I'm not trying to be mean, but the problem here seems to be that you only want this one task to be done - not to learn how to do programming. But you need to understand what you're doing in order to complete the task, so you might as well study programming and get the job done only afterwards.

    You could easily waste a full weeks work time on this - and you might not figure it out anyway. Because you're just guessing. Know that 5 full days of study would be more than enough to learn how to do this for real, so the choice is really yours. You can do it the dumb way - or the smart way.
     
  10. J. pride

    J. pride King

    Joined:
    Feb 23, 2011
    Messages:
    788
    No offense taken, I am actually thankful for all ur help.
    Currently, I don't have the time (maybe later I will try to learn) but if I just have to add a little snippet can u please tell me what it is. If it's Alot of work then can u breifly describe where I have to make the changes.
     
  11. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    J. pride, we're all about helping here, so please post what you already have and describe exactly what you need to do. Someone knowledgeable will be able to fill in the missing code for you so that you get the job done. If you don't have the time to learn, then that is all that matters. It will be way less work than to try and explain what to do. (Even more true the longer the script, even i I suspect it will only take a single line of code in this particular case.)
     
  12. J. pride

    J. pride King

    Joined:
    Feb 23, 2011
    Messages:
    788
    Currently, I have to start from scratch as a few posts back Leoreth just explained to me what arguments to use. As you know I wanted to expand the culture of an indie city; i used the code that u guys provided at first but I got several Python exceptions (posted above). I think i need a new code to make it work; Leoreth posted something but i cant seem to make sense of it
     
  13. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    You already spawned Warsaw, right? Well, post that code then. And we'll add what you need for the culture thing.

    No need for you to understand any of it or make any sense of what someone else said or posted. Because I'm fairly certain that you could never figure it out yourself anyway. This is programming, not going at it blindly.
     
  14. J. pride

    J. pride King

    Joined:
    Feb 23, 2011
    Messages:
    788
    Code:
    lWarsaw = [65, 52, 860, 0] #207
    Code:
    		self.foundCity(iIndependent2, lWarsaw, "Warszawa", iGameTurn, 3, con.iCrossbowman, 3)
    These are the 2 codes I put in Barb.py to spawn Warsaw. The Warsaw spawn works perfectly
     
  15. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Try this:
    Code:
    		self.foundCity(iIndependent2, lWarsaw, "Warszawa", iGameTurn, 3, con.iCrossbowman, 3)
    		if iGameTurn >= getTurnForYear(860):
    			pCity = gc.getMap().plot(65, 52).getPlotCity()
    			if pCity:
    				pCity.changeCulture(iIndependent2, 100, True)
     
  16. J. pride

    J. pride King

    Joined:
    Feb 23, 2011
    Messages:
    788
    Thanks Baldyr, It work now. I appreciate everybody's help.

    It's pretty funny that what i couldn't do in an hour was done in less then five minutes
     
  17. LuKo

    LuKo The Royal Guard

    Joined:
    Aug 28, 2006
    Messages:
    1,501
    Location:
    Poland
    edead, you're awesome! I wanted to change both power and strength, so every piece of advice was needed :) Thanks a lot!
     
  18. Leoreth

    Leoreth 心の怪盗団 Moderator

    Joined:
    Aug 23, 2009
    Messages:
    33,089
    Gender:
    Male
    Location:
    Leblanc
    A quick explanation of what's going on here:

    Arguments need to be of certain data types, and they are noted in the method's signature before each entry. In this case, there were two:

    int means an integer. iIndependent stores an integer (iirc it's 28), and 100 is one as well, so they're valid arguments.
    bool means a boolean value, i.e. either True or False.

    In either case, you don't have to repeat the data types when calling a function - they're only there for you to see which kind of information you have to enter.
     
  19. J. pride

    J. pride King

    Joined:
    Feb 23, 2011
    Messages:
    788
    Oh, I actually kind of get it now. Thanks Leoreth, appreaciate the help.
     
  20. civ-addicted

    civ-addicted King

    Joined:
    Aug 8, 2009
    Messages:
    852
    Location:
    The City of the Lion
    Out of pure curiosity (i can't test it myself atm)
    Is it possible in python to write something like
    Code:
    2*(condition)
    to get 2 if the condition is true, and 0 otherwise. I know that it's possible in C.
    It might be useful to shorten codes.
     

Share This Page