[Python] splitEmpire?

jkp1187

Unindicted Co-Conspirator
Joined
Aug 29, 2004
Messages
2,496
Location
Pittsburgh, Pennsylvania
Hello, all. Looks like my ban on coding for the month of December is about to end 10 days early. :lol:

I need help to set up another random event. This one would have, as one of the possible player choices, the option to grant independence to qualifying overseas cities as a Colony. I'm hoping to keep this entirely in Python, without resort to the SDK, primarily because I'm afraid of messing with that for now. :eek:

From my research into this, I noticed two commands in the API that are in the right ballpark:

Code:
bool[B] splitEmpire([/B]int iAreaId[B])
[/B]bool [B]canSplitEmpire()[/B]

The problem is, of course, that they're both BOOLs. I was hoping, perhaps, that the first one was actually supposed to be a VOID, since I can't imagine what it's trying to discover -- seems to me that if you want to know if you can Split an Empire, you should use canSplitEmpire, right?

Anyway, assuming that my above hope is completely wrong, is there a way, using currently-exposed Python commands, that I can force colony creation? Like using a combination of:

Code:
[B]addPlayer[/B][B]([/B]int eNewPlayer, int eNewTeam, int eLeader, int eCiv[B])
acquireCity([/B]CyCity pCity, bool bConquest, bool bTrade[B])[/B]
[B]findNewCapital()
[/B]
Or am I asking for too much here?

As always, thanks in advance....
 
Anyway, assuming that my above hope is completely wrong, is there a way, using currently-exposed Python commands, that I can force colony creation? Like using a combination of:

Code:
[B]addPlayer[/B][B]([/B]int eNewPlayer, int eNewTeam, int eLeader, int eCiv[B])
acquireCity([/B]CyCity pCity, bool bConquest, bool bTrade[B])[/B]
[B]findNewCapital()
[/B]
Or am I asking for too much here?

As always, thanks in advance....

It should run just with "acquireCity".
"addPlayer" displays the diplomatic screen.
"findNewCapital" : why ?
You'll have to set the new player as a vassal, too.
 
bool splitEmpire(int iAreaId)
creates a colony, returns true if it was created. False if it couldn't.
You need the Areaid of the continent. The player must have a City on that continent. and the capital must not be on it.
and canSplitEmpire test if an Enpire can be split.
 
Thanks!

And how do I find iAreaID, by the way?


And, just as an aside.... Why is splitEmpire listed as "bool" in the API when it actually does something -- I thought all "bool" commands were supposed to do is return a true/false value.

@Fabrysse: I figured findNewCapital would be needed to set up a capital city for the newly-created civ....

@Seven05: :p
 
Wow, splitEmpire(areaID) sure does work as advertised.... I got the areaId via Chipotle. As soon as I figure out how to get areaId via Python, game on!
 
It seems that the player you want to split needs to have some cities in an area different from your capital . All you need is to loop on the player cities to check cities with different areas from the player capitol . Not sure but this requires at least 2 cities on a different area i think .

Tcho !
 
It seems that the player you want to split needs to have some cities in an area different from your capital . All you need is to loop on the player cities to check cities with different areas from the player capitol . Not sure but this requires at least 2 cities on a different area i think .

Tcho !


Yes, that's exactly right. And I was able to find the areaID using the chipotle cheat code and shift+mousing over the landmass to force splitEmpire...What I need to know, however, is how to discover the areaID via Python. I looked through the API, and I'm still not sure what command needs to be used to learn this -- how do I loop on the player's cities?
 
Yes, that's exactly right. And I was able to find the areaID using the chipotle cheat code and shift+mousing over the landmass to force splitEmpire...What I need to know, however, is how to discover the areaID via Python. I looked through the API, and I'm still not sure what command needs to be used to learn this -- how do I loop on the player's cities?

In fact there is a function canSplitArea(areaID) . So it's just needed to loop over areas to find an area to split empire but what do you want to do if there is multiple areas where you can split your empire ?

Tcho !
 
Area ID's are easy :)

In python:

To see how many land area there are (since oceans won't help here)...
gc.getMap().getNumLandAreas()

You can then loop through them if you like. Or, if you have a specific location in mind...
plot.area()

where plot is the index returned from something like gc.getMap().plotByIndex(i)

You can see several examples in CvRandomEventInterface.py and in a few of the map scripts as well.
 
In fact there is a function canSplitArea(areaID) . So it's just needed to loop over areas to find an area to split empire but what do you want to do if there is multiple areas where you can split your empire ?

Tcho !

Actually, that's easy. If there are multiple qualifying 'colonies', the event will always go with the area with the most number of cities. If the number of cities are even, I suppose I could have it go with population.

...and if that doesn't work, return False. I don't want to waste too many brain cells on this. :)
 
here the code :

Code:
def doSplitEmpire(ePlayer):

        map = CyMap()
        pPlayer = gc.getPlayer(ePlayer)

	areas = []
	for i in range(map.getIndexAfterLastArea()) :
		area = map.getArea(i)
		if area.isNone() : continue
		if area.isWater() : continue
		if area.getCitiesPerPlayer(ePlayer) == 0 : continue
		if not pPlayer.canSplitArea(area.getID()) : continue
                areas.append(area)

        if areas == [] :
                return False
        elif len(areas) == 1 :
                pPlayer.splitEmpire(areas[0].getID())
                return True
        else :
                sortList = [ [area.getID(), area.getCitiesPerPlayer(ePlayer), area.getPopulationPerPlayer(ePlayer)] for area in areas ]
                sortList.sort(cmp=lambda x,y: cmp(x[2], y[2]))
                sortList.sort(cmp=lambda x,y: cmp(x[1], y[1]))
                sortList.reverse()
                pPlayer.splitEmpire(sortList[0][0])
                return True

Tcho !
 
Sto, did you ever know that you're my hero -- and everything I would like to be?

Thanks a million. I will take a look at this and see if I can't integrate this code into the event without messing anything up. I think I see how everything works....
 
Back
Top Bottom