1. Firaxis celebrates the "Asian American and Pacific Islander Heritage Month", and offers a give-away of a Civ6 anthology copy (5 in total)! For all the details, please check the thread here. .
    Dismiss Notice
  2. We have selected the winners of the Old World random draw and competition. For the winning entries, please check this thread.
    Dismiss Notice
  3. Old World has finally been released on GOG and Steam, besides also being available in the Epic store . Come to our Old World forum and discuss with us!
    Dismiss Notice

Spawn a civ

Discussion in 'Civ4 - SDK/Python' started by Hutma, May 23, 2020.

  1. Hutma

    Hutma Chieftain

    Joined:
    Apr 21, 2020
    Messages:
    22
    Gender:
    Male
    Location:
    France
    Hello,
    I'm trying to make a new civ appear during the game when a player discovers a specific tech.
    I know how to use python and understand it but I'm not really good when it comes to using it with Civ4 fonctions.

    So I've have done some research and found the Spawn A Civ mod comp by The_J (https://forums.civfanatics.com/resources/xml-python-spawn-a-civ.13487/)

    I've tried to use it this past few days but each time the new civilization spawn on the first turn. So I tried it using the mod comp as a mod and same issue, on the first turn the Huns and Americans (well, the Americans 50% pf the time) spawn.

    I tried to edit the python myself but I always end up with either the civilisation spawns on the first turn or it never spawns. So if I understand right, everything works except the verification of the conditions in SpawnACiv fonction

    If you know how to rectify the mod comp or know an easy code to add a civilisation into the game once a certain tech is reached by one player, it will help a lot.

    Thank you in advance for your time and your help.
     
  2. lfgr

    lfgr Emperor

    Joined:
    Feb 6, 2010
    Messages:
    1,021
    In SpawnCivUtil.py, in the SpawnACiv function, change the checks "if iTechType:" and "if iTurn:" to "if iTechType is not None:" and "if iTurn is not None:".
    Otherwise, for turn 0 and the technology with ID 0 (mysticism), the iTechType resp. iTurn evaluate to False and the tech/turn checks are bypassed.
     
  3. Hutma

    Hutma Chieftain

    Joined:
    Apr 21, 2020
    Messages:
    22
    Gender:
    Male
    Location:
    France
    Thank you for the reply, I'm going to test this, and keep the thread informed of if it produced results or not.
     
  4. Hutma

    Hutma Chieftain

    Joined:
    Apr 21, 2020
    Messages:
    22
    Gender:
    Male
    Location:
    France
    It works! I will continue to test it but it seems to work perfectly with your fix, replacing "if Techtype:" and "if iTurn:" by "if iTechType is not None:" and "if iTurn is not None:".

    Thank you very much, I have been on this for hours!
     
  5. Hutma

    Hutma Chieftain

    Joined:
    Apr 21, 2020
    Messages:
    22
    Gender:
    Male
    Location:
    France
    Bad news, it doesn't really work. Only the Turns are taken into account. If you have the right tech but the turn set in the XML is not reached yet, the civ won't spawn.

    I thought this is because the "if iTurn" was blocking the "if iTech" but no, it's not for this.
    Maybe there is something wrong in this code:
    Code:
            Tech = SpawnCiv.SpawnTech
            iHumanTech = SpawnCiv.SpawnTechHumanOnly
            bHumanTech = False
            if iTechType is not None:       
                if not ((iTechType ==gc.getInfoTypeForString(Tech)) or (iTechType == gc.getInfoTypeForString(iHumanTech))):
                    return
                if iTechType == gc.getInfoTypeForString(iHumanTech):
                    bHumanTech = True
                    if not gc.getPlayer(iPlayer).isHuman():
                        return
                TechCounter=0
                for i in xrange (gc.getMAX_CIV_TEAMS ()):
                    Team = gc.getTeam(i)       
                    if Team.isHasTech(iTechType):
                            TechCounter=TechCounter+1
                    if TechCounter>=SpawnCiv.SpawnTechNumber:
                            break
                    
                if (not TechCounter>=SpawnCiv.SpawnTechNumber) and (not bHumanTech):                       
                    return
    I tried to replace the xrange by range but the result is the same.
     
  6. Hutma

    Hutma Chieftain

    Joined:
    Apr 21, 2020
    Messages:
    22
    Gender:
    Male
    Location:
    France
    So, after a few tries i found that this line:
    Code:
                if not iTechType == gc.getInfoTypeForString(Tech):
                    return
    isn't working at all. I tried to replace gc.getInfoTypeForString(Tech) by "TECH_XYZ" (XYZ being the name of tech I tested) and even then it doesn't work.
    I tried to get rid of this line to see if it's this line that blocks the code and yes it is. This means that this line never considers that iTechType is equal to "TECH_XYZ", which is weird.
    I don't understand because this line should just test if iTechType is equal to "TECH_XYZ".
    Is there an error there?

    Thank you in advance for your help.
     
    Last edited: May 24, 2020
  7. lfgr

    lfgr Emperor

    Joined:
    Feb 6, 2010
    Messages:
    1,021
    "iTechType" is an int (the tech ID) or None here. Tech is a string. gc.getInfoTypeForString() is the Civ4 function that converts a string ID (like TECH_SAILING" or "CIVILIZATION_MAYA") to an integer ID. You'll find gc.getInfoTypeForString() all over the place.
    So what you want to test is
    Code:
    not iTechType == gc.getInfoTypeForString("TECH_XYZ")
    
    (or, better I'd say)
    Code:
    iTechType != gc.getInfoTypeForString("TECH_XYZ")
    
    A general hint in case you are new to programming: To better understand the code, I'd advise you to place a bunch of print statements in the code to see what the values are. This is what I did earlier, to see if the XML parsing works correctly (I believe it does, for the example XML at least). You can find the output in "<userdir>/Documents/My Games/Beyond the Sword/Logs/PythonDbg.log."
     
    Hutma likes this.
  8. Hutma

    Hutma Chieftain

    Joined:
    Apr 21, 2020
    Messages:
    22
    Gender:
    Male
    Location:
    France
    Here it is!
    I have a version that works. (I got rid of the iHumanTech but I could put it back I think) Thank you very much Ifgr, you helped me a lot with this.
    I'm leaning Python in engineering school so I know how it works and how to do things but using python this way is very new for me, thank for the advice :)

    Should I reupload the modcomp? Should I write a message to The_J about it?

    I personally think some people could use it, it has been very helpful for me.
     
  9. lfgr

    lfgr Emperor

    Joined:
    Feb 6, 2010
    Messages:
    1,021
    Great! It can't hurt to write The_J, or ping like this: @The_J :)
    Otherwise, I'm sure they don't mind you reuploading it. See the Modiquette.
     
  10. The_J

    The_J Say No 2 Net Validations Administrator Supporter

    Joined:
    Oct 22, 2008
    Messages:
    36,245
    Location:
    DE/NL/FR
    This worked ;).
    No, I don't mind :).
    Please give me credit and also link back to the original thread, that's it :).

    I have to say I had not realized that stuff in the mod comp didn't work :blush:. When I wrote it I was considerably worse at coding than I am now, so I guess that has something to do with it :/.
     
  11. Hutma

    Hutma Chieftain

    Joined:
    Apr 21, 2020
    Messages:
    22
    Gender:
    Male
    Location:
    France
    It took me some time to find out it wasn't working properly ;)

    I'll try to reput the iHumanTech option before reuploading it.
    Of course I'll give you credit!

    I'm also not very good at coding but I'll try to do my best.

    Many thanks for all your modcomp and participation on this forum, it has been very helpful (and will keep on being helpful as long as my mod is not finished).
    I'll keep you inform :)
     
  12. <Nexus>

    <Nexus> Traveler of the Multiverse

    Joined:
    Jan 23, 2014
    Messages:
    4,850
    Gender:
    Male
    Location:
    In a constant brainstorm...
    Great job!
    I'm so glad someone fixed this modcomp before I even try to touch it.
    I'm modding AND2 which has Revolutions and Barbarian Civs, so there are other ways in it to spawn a (random) civ. So, do you know of a way to prevent specific civs from being spawned by those other 2 methods? My goal is to add powerful aliens in the modern era, so even a sole superpower may get a new challenge again.
     
  13. Hutma

    Hutma Chieftain

    Joined:
    Apr 21, 2020
    Messages:
    22
    Gender:
    Male
    Location:
    France
    I haven't seen the code off these two methods but I think you can add a condition in it to test if the picked civ (that will be spawned) by the program is the one you want to prevent from spawning. And if it is you can prevent it by making it picking an other one.

    I'll take some time to look at it this week. Just after I finished to rewrite Spawn_a_Civ.
     
  14. Hutma

    Hutma Chieftain

    Joined:
    Apr 21, 2020
    Messages:
    22
    Gender:
    Male
    Location:
    France
  15. Louis the XIV

    Louis the XIV Sun King

    Joined:
    Jun 23, 2020
    Messages:
    837
    Gender:
    Male
    Location:
    Court of Versailles
    I made the Americans spawn when Constitution is Discovered but I put in the Coordinates for Washington and made them start with 1 city, but when I discovered Constitution they Started with 7 cities somewhere in Australia! Please help me, i'm not a really good Python modder, I only know a lot about XML. Thanks in advance to anyone who can help me.
     
  16. Hutma

    Hutma Chieftain

    Joined:
    Apr 21, 2020
    Messages:
    22
    Gender:
    Male
    Location:
    France
    I'll take a look at it, can you send me the files you have edited?
     
  17. Hutma

    Hutma Chieftain

    Joined:
    Apr 21, 2020
    Messages:
    22
    Gender:
    Male
    Location:
    France
    Also if you give me the coordinates of the one city you want to spawn I can try to write the python for it.
     
  18. Louis the XIV

    Louis the XIV Sun King

    Joined:
    Jun 23, 2020
    Messages:
    837
    Gender:
    Male
    Location:
    Court of Versailles
    Oh Thanks, I will send them in a minute.
     
  19. Louis the XIV

    Louis the XIV Sun King

    Joined:
    Jun 23, 2020
    Messages:
    837
    Gender:
    Male
    Location:
    Court of Versailles
    If you can, can you please try to make the Portugese spawn on these Coordinates? X= 26 Y= 29
     

    Attached Files:

  20. Hutma

    Hutma Chieftain

    Joined:
    Apr 21, 2020
    Messages:
    22
    Gender:
    Male
    Location:
    France
    Ok, I'll try to do it, but it won't be before the end of the week, I'm busy for the moment.
     

Share This Page