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. J. pride

    J. pride Chieftain

    Joined:
    Feb 23, 2011
    Messages:
    788
    Well I think I have no clue to what im doing (or what ur referring to). But I will tell u what I want to do. I have made an Independent Warsaw spawn to counter the German expansion to the east but the problem is that the german culture causes it to flip the city.

    This is what i did with the code in Rhyes and fall.py

     
  2. Leoreth

    Leoreth 心の怪盗団 Moderator

    Joined:
    Aug 23, 2009
    Messages:
    33,053
    Gender:
    Male
    Location:
    Leblanc
    I suggest you use the
    Code:
     tags instead of quotes, so we can see if your indentations are correct.
    
    Anyway, the CyCity Baldyr was referring to represents an object of the type "CyCity" and the expression "CyCity.changeCulture()" means that "changeCulture" is a method of the CyCity object (makes sense, doesn't it? You want to change the culture of a city). So you have to fetch the object representing your city (in this case, Warsaw) and call the changeCulture method on it:
    [CODE]if iGameTurn == getTurnForYear(900):
    
            [COLOR="Red"]gc.getMap().plot(65,52).getPlotCity()[/COLOR].changeCulture(100)
    The part marked in red returns the CyCity object representing Warsaw.
     
  3. J. pride

    J. pride Chieftain

    Joined:
    Feb 23, 2011
    Messages:
    788
    Code:
    		if iGameTurn == getTurnForYear(880):
    
    				gc.getMap().plot(65,52).getPlotCity().changeCulture(100)
    
    		if (iGameTurn <= getTurnForYear(1100) and not gc.getPlayer(iEgypt).isPlayable()):
    I think I did what u told but its still not woring; did i do something wrong
     
  4. Jarkov

    Jarkov Chieftain

    Joined:
    Oct 23, 2010
    Messages:
    158
    Try this:

    Code:
    if (iGameTurn == getTurnForYear(880)):
    
            gc.getMap().plot(65,52).getPlotCity().changeCulture(100)
    Sometimes the parentheses matter. If that doesn't work, have a look at the logs.
     
  5. Jarkov

    Jarkov Chieftain

    Joined:
    Oct 23, 2010
    Messages:
    158
    On an unrelated matter, I need some help with the SDK.

    As you know, in Rhyes.h the civilization variables are defined. Would it be possible to somehow add a function that defines the variables according to the scenario (3000 BC or 600 AD) in question?
     
  6. J. pride

    J. pride Chieftain

    Joined:
    Feb 23, 2011
    Messages:
    788
    I dont know what the problem is but it did not work.
     
  7. Jarkov

    Jarkov Chieftain

    Joined:
    Oct 23, 2010
    Messages:
    158
    Where in RiseAndFall.py did you put it?
     
  8. J. pride

    J. pride Chieftain

    Joined:
    Feb 23, 2011
    Messages:
    788
    Well its in DOC, Leoreth had made a few gameturn scirpts for 640 and 650 ad and i just added 880 under there; just so u know i had successfully done this before but that was for adding units not culture. Here is the code:
    Code:
    		if (iGameTurn == getTurnForYear(650)):
    			if (not gc.getPlayer(0).isPlayable()):
    				plotBaghdad = gc.getMap().plot(77,40)
    				plotCairo = gc.getMap().plot(69,35)
    
    				Baghdad = plotBaghdad.getPlotCity()
    				Cairo = plotCairo.getPlotCity()
    
    				bBaghdad = (plotBaghdad.getOwner() == iArabia)
    				bCairo = (plotCairo.getOwner() == iArabia)
    
    				if (bBaghdad and bCairo):
    					iRand = gc.getGame().getSorenRandNum(2, "Toss Coin")
    
    					if iRand == 0:
    						if utils.getHumanID() != iArabia:
    							Baghdad.setHasRealBuilding(con.iPalace, True)
    							utils.makeUnit(con.iArabiaCamelarcher, iArabia, (77,40), 3)
    							utils.makeUnit(con.iSwordsman, iArabia, (77,40), 2)
    						utils.makeUnit(con.iArabiaCamelarcher, iArabia, (77,40), 2)
    						utils.makeUnit(con.iSwordsman, iArabia, (77,40), 2)
    					else:
    						if utils.getHumanID() != iArabia:
    							Cairo.setHasRealBuilding(con.iPalace, True)
    							utils.makeUnit(con.iArabiaCamelarcher, iArabia, (69,35), 3)
    							utils.makeUnit(con.iSwordsman, iArabia, (69,35), 2)
    						utils.makeUnit(con.iArabiaCamelarcher, iArabia, (69,35), 2)
    						utils.makeUnit(con.iSwordsman, iArabia, (69,35), 2)
    
    					utils.makeUnit(con.iSettler, iArabia, (77,40), 1)
    					utils.makeUnit(con.iSettler, iArabia, (69,35), 1)
    					utils.makeUnit(con.iWorker, iArabia, (77,40), 1)
    					utils.makeUnit(con.iWorker, iArabia, (69,35), 1)
    
    				elif (bBaghdad and not bCairo):
    					if utils.getHumanID() != iArabia:
    						Baghdad.setHasRealBuilding(con.iPalace, True)
    						utils.makeUnit(con.iArabiaCamelarcher, iArabia, (77,40), 3)
    						utils.makeUnit(con.iSwordsman, iArabia, (77,40), 2)
    					utils.makeUnit(con.iSettler, iArabia, (77,40), 1)
    					utils.makeUnit(con.iArabiaCamelarcher, iArabia, (77,40), 2)
    					utils.makeUnit(con.iSwordsman, iArabia, (77,40), 2)
    
    					utils.makeUnit(con.iSettler, iArabia, (77,40), 1)
    					utils.makeUnit(con.iWorker, iArabia, (77,40), 1)
    					utils.makeUnit(con.iWorker, iArabia, (75,33), 1)
    
    				elif (not bBaghdad and not bCairo):
    					if utils.getHumanID() != iArabia:
    						Cairo.setHasRealBuilding(con.iPalace, True)
    						utils.makeUnit(con.iArabiaCamelarcher, iArabia, (69,35), 3)
    						utils.makeUnit(con.iSwordsman, iArabia, (69,35), 2)
    					utils.makeUnit(con.iSettler, iArabia, (69,35), 1)
    					utils.makeUnit(con.iArabiaCamelarcher, iArabia, (69,35), 2)
    					utils.makeUnit(con.iSwordsman, iArabia, (69,35), 2)
    
    					utils.makeUnit(con.iSettler, iArabia, (69,35), 1)
    					utils.makeUnit(con.iWorker, iArabia, (75,33), 1)
    					utils.makeUnit(con.iWorker, iArabia, (69,35), 1)
    
    				else:
    					utils.makeUnit(con.iSettler, iArabia, (75,33), 2)
    					utils.makeUnit(con.iWorker, iArabia, (75,33), 2)
    					if utils.getHumanID() != iArabia:
    						utils.makeUnit(con.iArabiaCamelarcher, iArabia, (75,33), 3)
    						utils.makeUnit(con.iSwordsman, iArabia, (75,33), 2)
    					utils.makeUnit(con.iArabiaCamelarcher, iArabia, (75,33), 2)
    					utils.makeUnit(con.iSwordsman, iArabia, (75,33), 2)
    
    		if (iGameTurn == getTurnForYear(700)):
    
    				utils.makeUnit(con.iLongbowman, iVikings, (60,55), 1)
    
    		if (iGameTurn == getTurnForYear(880)):
    
            		gc.getMap().plot(65,52).getPlotCity().changeCulture(100)
    The list is long so u can have an idea to where i put it; the stuff that u wanted me to add is at the end
     
  9. LuKo

    LuKo The Royal Guard

    Joined:
    Aug 28, 2006
    Messages:
    1,501
    Location:
    Poland
    @embryodead: What do I copy and how do I change it? I'm programming noob :p
     
  10. Leoreth

    Leoreth 心の怪盗団 Moderator

    Joined:
    Aug 23, 2009
    Messages:
    33,053
    Gender:
    Male
    Location:
    Leblanc
    Yes you can, the C preprocessor allows you to add conditions as well, you can then check if Egypt is playable as usual to determine the scenario. It should look like this:
    Code:
    #if GET_PLAYER(0).isPlayable()
    #define EGYPT (0)
    [...]
    #else
    [...]
    #endif

    Step 1: please enable Python exceptions, in case of invalid code they can show you the exact line of your mistake.

    Step 2: your indentations are off, it looks like the module falls apart in the previous check (the Viking longbowman) because it's too far indented (two tabs instead of one).
     
  11. Jarkov

    Jarkov Chieftain

    Joined:
    Oct 23, 2010
    Messages:
    158
    That's great.
     
  12. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Like when? Please supply a source for your information, or a sample of code where this is true.

    Because you never need to put any expression inside parenthesis in Python, unless you're doing complicated and/or expressions with nested expressions, or unless you wanna be able to completely ignore white space and line breaks in an expression.
     
  13. Leoreth

    Leoreth 心の怪盗団 Moderator

    Joined:
    Aug 23, 2009
    Messages:
    33,053
    Gender:
    Male
    Location:
    Leblanc
    I think it was meant more like a general advice along the lines of "if in doubt, leave comma out".
     
  14. embryodead

    embryodead Caliph

    Joined:
    Jan 1, 2003
    Messages:
    5,179
    Location:
    basement
    You need to update CvPlayer.cpp and CvPlayer.h, as well as CyPlayer.cpp, CyPlayer.h and CyPlayerInterface2.cpp

    Take an example variable to use as reference, e.g. m_iPower in CvPlayer.h and CvPlayer.cpp. By looking at all instances of "Power" you can see what you have to do to make your new variable work properly.

    Things to do:
    - declaration in CvPlayer.cpp/h
    - getters/setters in both files i.e. getPower and changePower (for convenience you can have getStability, setStability and changeStability)
    - pStream->read/write in CvPlayer::read/write
    - declaration of getters/setters in CyPlayer.cpp/h and CyPlayerInterface2.cpp (or CyPlayerInterface1.cpp - doesn't really matter)

    So you have to add the code in like 20+ places, but every time you just look at code of m_iPower, getPower etc. copy it and rename it so that it's Stability, not Power. i.e. you see:
    Code:
    pStream->Read(&m_iPower);
    you copy it and paste below:
    Code:
    pStream->Read(&m_iStability); // LuKo
    x20

    Then compile and pray.
     
  15. Jarkov

    Jarkov Chieftain

    Joined:
    Oct 23, 2010
    Messages:
    158
    @Baldyr: Like Leoreth said, this was just general advice, I should have made that clearer.
     
  16. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Lets just say that people who are copying other people's code tend to do things without knowing what they are doing - or why... And wrapping everything inside parenthesis seems to be a habit that C++ programmers have brought to CivIV Python. Because parenthesis in themselves do nothing - at all - this can be interpreted as proper programming procedure. While its not.
     
  17. embryodead

    embryodead Caliph

    Joined:
    Jan 1, 2003
    Messages:
    5,179
    Location:
    basement
    Let me clarify that those "extra" parentheses aren't C++ thing - they're not just proper but absolutely obligatory in just about every major language out there, so everyone who touched programming before has this (proper) habit. Interesingly, they've always pissed me off as useless crap and out of 12 or so languages I've used Python is the first one that had the balls to drop them ;) The result is that I now tend to drop those parentheses as well as semicolons while doing work in other stuff and it drives me nuts. Python is really an oddball that defies many established programming conventions.
     
  18. embryodead

    embryodead Caliph

    Joined:
    Jan 1, 2003
    Messages:
    5,179
    Location:
    basement
    doublepost
     
  19. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Go Python! :king:
     
  20. J. pride

    J. pride Chieftain

    Joined:
    Feb 23, 2011
    Messages:
    788
    How do u enable python exceptions?
     

Share This Page