onCityBuilt for all

Tholish

Emperor
Joined
Jul 5, 2002
Messages
1,344
Location
Japan
I'm trying to adapt an old modcomp "RandomCityNames" by Buckets to my own use. Ultimately I want it to apply only to Barbarian cities. I put this in CvEventInfos, which imports RandomCityNameUtils from the modcomp, which I also placed in the Python folder.

Code:
def onCityBuilt(self, argsList):
	'City Built'
	city = argsList[0]
	city.setName(RandomCityNameUtils.getRandomCityName(),1)

It works, but only for the human player.
What about this would single out the human player?
 
Looking at CvPlayer::found() I see the code that handles barbarian cities by spawning some free defenders. At the end of this function is a call to fire the onCityBuilt event. There doesn't seem to be any way to exit the function without firing the event.

How are you hooking this function up to the event manager?

Edit: I also see that you are passing in True (1) for bFound. Right before the event is fired, non-human cities call doFoundMessage(). CvCity::setName() calls this same function if bFound is True. Are you seeing two messages for each new AI city? Is the city not being renamed? Be very specific about how it doesn't work for the AI players.

Edit2: CvCity::setName() checks with the player to see if the city name is valid. Perhaps the random names aren't valid for some players? I would add an alert/debug message to onCityBuilt() to verify that this event is being called for AI players:

Code:
def onCityBuild(self, argsList):
	'City Built'
	city = argsList[0]
	[B]CyInterface().addImmediateMessage("City Built: %s" % city.getName(), "")[/B]
	city.setName(RandomCityNameUtils.getRandomCityName(),1)
	[B]CyInterface().addImmediateMessage("City Renamed: %s" % city.getName(), "")[/B]
 
Mis-typed when I said "CvEventInfos". Messing with XML too much.

That code IS in CvEventManager, replacing the code from the original. The original modcomp sets up and uses CvCustomEventManager and simply comments everything but the args lline out of the one in CvEventManager, but it was for vanilla Civ IV and to use its CvCustomEventManager I would have to mess with other stuff, and I don't see why it needs to be done that way anyhow, so I just put it in CvEventManager.

To get the barbs involved, I've tried several things. The definition for razing cities has some stuff that might work (once properly adapted), but using it while the only affected player is the human means using it would mean the random names would only be assigned when a human city is a barb city which they seldom are.

I was not seeing messages because I commented them out to remove anything that might be creating problems. I see now that that eliminated a source of potential information. I'll try your alerts.

EDIT: Tried that, got no messages about AI cities. Founded my city. Got notified of Carthage being founded, then "Threns". Saw Babylon being founded next door (using my Peripherals map script most civs start on small land masses together so I literally see civs being founded next door and I can directly see what they are called).
 
Top Bottom