Spawn a civ

Hutma

Chieftain
Joined
Apr 21, 2020
Messages
22
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.
 
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.
 
Thank you for the reply, I'm going to test this, and keep the thread informed of if it produced results or not.
 
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.
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!
 
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.
 
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:
"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."
 
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.
 
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.

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 :/.
 
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 :/.

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 :)
 
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.
 
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.

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.
 
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.
 
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.
I'll take a look at it, can you send me the files you have edited?
 
Also if you give me the coordinates of the one city you want to spawn I can try to write the python for it.
 
Top Bottom