Problems merging a Mod containing Bug and CivSpecific Great People mod

LoneTraveller

Warlord
Joined
Apr 30, 2008
Messages
283
Location
Montreal, Quebec
Hi,

I'm relatively new at python and I'm trying to merged the 2 mods named in the title. So far I can in the logs that all the files (modules) are being loaded but I don't see that the required function is being ''looked up'' (according to the tutorial : http://sourceforge.net/apps/mediawiki/civ4bug/index.php?title=Tutorial:_Events). So I figure that my event type is wrong. The function I need to implement is 'onGreatPersonBorn' but I don't see it in the BugEventManager.py file. I think I need to know how to implement it.

Any help would be appreciated.

Thank you
 
You can see what onGreatPersonBorn() receives in its argsList parameter by looking in CvEventManager.py. It's best to copy that function to your own new Python module as a global function not inside a class. To do this

  1. Copy the function from CvEventManager.py to a new module.
  2. Remove one level of indentation (tab) from the entire function.
  3. Remove the "self" parameter.
The result for this function will look something like this:

Code:
# MyCoolMergedMod.py

def onGreatPersonBorn(argsList):
	# extract the three parameters from the list
	pUnit, ePlayer, pCity = argsList
	... your code ...

Finally you must register this function as an event handler for "greatPersonBorn" in BUG. This part is covered in the tutorial you linked and will look something like this:

Code:
<mod id="MyCoolMergedMod" module="MyCoolMergedMod">
    <event type="greatPersonBorn" function="onGreatPersonBorn"/>
</mod>
 
That's exactly how things are. I have a file named CvCivSpecificGreatPeopleModEventManager.py that contains the function onGreatPersonBorn(argsList) located in the "Python/Contrib" folder that looks like this (everything is indentated, it just doesn't show itself correctly in this post) :

Code:
## Sid Meier's Civilization 4
## Copyright Firaxis Games 2005

from CvPythonExtensions import *
import PyHelpers
import CivSpecificGreatPeopleModNameUtils
import BugUtil

gc = CyGlobalContext()

PyPlayer = PyHelpers.PyPlayer	

# globals
###################################################
#class CvCivSpecificGreatPeopleModEventManager:
	
def onGreatPersonBorn(argsList):
	'Great Person Born'

	pUnit, iPlayer, pCity = argsList
	player = PyPlayer(iPlayer)
	infoUnit = pUnit.getUnitClassType()
	      
	# Check if we should even show the popup:
	if pUnit.isNone() or pCity.isNone():
		return

	if(len(pUnit.getNameNoDesc()) == 0): # Rename units with no names - important to avoid confusion with event log
		
		iCivilizationType = player.player.getCivilizationType()
		# Pass the civilization and unit type along to the renamer
		newUnitName = CivSpecificGreatPeopleModNameUtils.generateCivilizationName(iCivilizationType, infoUnit)

		if (newUnitName != None):
			pUnit.setName(newUnitName)

I also have a xml file named "CivSpecific Great People.xml" located in the "Config" folder that contains the following :

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
    Civ-Specific Great People 2.0
-->
<mod id="CivSpecific Great People" module="CvCivSpecificGreatPeopleModEventManager">
		<event type="greatPersonBorn" function="onGreatPersonBorn"/>
</mod>

I think I must point out that this mod requires 2 python files. The other is named "CvCivSpecificGreatPeopleModEventManager.py" and according to the "PythonDbg.log" both files have been loaded. Here is the portion of the log that says so :

Code:
load_module CvCivSpecificGreatPeopleModEventManager

load_module CivSpecificGreatPeopleModNameUtils

There's something stated in the tutorial that says that

Code:
"if the <mod>'s id attribute is invalid you won't see an error, but you will be unable to reference it later."

A part of me thinks that this is the problem but I'm uncertain how to :

Code:
Validate ids and log an error instead of silently failing.

Thank you for the speedy reply :)
 
The <mod>'s id attribute must not have any spaces in it, but this would only make any <option>s defined within it unavailable, and this isn't the problem here.

Did you add your XML file to init.xml?

Code:
<load mod="name-of-xml-file-without-extension"/>

BTW, you can surround your code with [code] ... [/code] tags to preserve the indentation and use a fixed-width font.
 
The <mod>'s id attribute must not have any spaces in it, but this would only make any <option>s defined within it unavailable, and this isn't the problem here.

I have taken out the spaces in the <id> and you were right, it changed nothing.


Did you add your XML file to init.xml?

Code:
<load mod="name-of-xml-file-without-extension"/>

Yes I have I wrote the following at the end of the list of <load mod> entries :

Code:
<load mod="CivSpecific Great People"/>

The xml file name is "CivSpecific Great People.xml"
 
Okay then, let's start with the first thing to do: post PythonDbg.log and PythonErr.log (if not empty).
 
Please enable BUG debug logging (see the Troubleshooting thread in my sig) and repost that file.
 
this might sound idiotic but...is there a file somewhere in the progress of the BUG mod that will tell me directly/immediatly the bug version used in the mod I'm using ?

Very well, here is the true story behind my questions/problems

Ok...I'm trying to merge AsioAsioAsio's 2nd World War Scenario with another mod called "Merged Mod" and I can say that I succeeded in making both of them work. Now Asio3x wants to add a few other mods that have worked with BUG except for...CivSpecific Great Person mod made by the user who has a roman name that contains the word "Gaius". I managed to optain his python version of his naming system for great people for BTS (from the "creation & customization" forum). Since that point we have been trying to make Gaius python system naming work with what we have done...but me and Asio can't figure out what is wrong.

The BUG mod optained is from Merged Mod 1.11 but I don't know which file to search for for a version of BUG included.

If you mean the file "BUG Core.xml" than the parameters are :

Code:
version=3.5
build=1324
date=09/11/2008

it sounds old and I'm hoping it hasn't changed too much since.

Thanks for the interest invested into responding to me :) (hope I'm not too outdated or pathetic with your level of skill)

Thanks for your time
 
I haven't kept the version #'s in the XML files updated. You should look in Contrib/CvModName, but usually people overwrite the BUG version with their own.

However, what you're trying to do should work with 3.5 as well as the latest version without any changes. It's pretty straight-forward.

What I need is for you to enable logging in BUG. By default BUG turns off its debug logging as it initializes because it dumps a lot of data into the log file. It's easy to turn on, and once you do you can post PythonDbg.log again and it will contain useful information, specifically whether or not BUG is trying to load your XML file.

Without that, I can't even begin to guess what's wrong. The log file will say what BUG is doing as it does it. It will say as it loads the XML, registers the event, etc.
 
OS : Win7 64bit
BTS version : 3.19
BUG version : 3.5
Installation source : From a mod called Merged Mod 1.10 (source code)
Installation method : Multiplayer (Mods folder)
Merged Mods : Asio3x's WW2 mod + Merged Mod 1.10 (with BUG 3.5 included) + Gaius CivSpecific Great People 2.0 (python version) + Partisan Mod + KGB mod


PythongDbg.log located here : http://www.mediafire.com/?pogoikc7lcy8ljz
PythonErr.log is empty.

If I missed anything, please tell me.

Thanks
 
The BUG logging options are still disabled. Have you gone into your BUG Options screen and set the File Logging to Debug? You must do this, reload BTS, and then post the log file.
 
Okay, I see your mod being loaded and onGreatPersonBorn registered. Next is to see if your event handler is being called. Make sure that logging is specifically enabled for BugEventManager in "BUG Core.xml".

Code:
	<init module="BugEventManager" function="configure" immediate="true">
		<arg name="logging" type="boolean" value="[B]true[/B]"/>
		<arg name="noLogEvents" type="set">
			"gameUpdate",
			"mouseEvent",
			"kbdEvent"
		</arg>
	</init>

Then do whatever you need to do to cause a great person to be born and post PythonDbg.log again. :) We'll get there. BTW, how do you know your mod isn't working? Have you added any logging to your function using BugUtil.debug() or BugUtil.alert()?
 
Okay, I see your mod being loaded and onGreatPersonBorn registered. Next is to see if your event handler is being called. Make sure that logging is specifically enabled for BugEventManager in "BUG Core.xml".

Code:
	<init module="BugEventManager" function="configure" immediate="true">
		<arg name="logging" type="boolean" value="[B]true[/B]"/>
		<arg name="noLogEvents" type="set">
			"gameUpdate",
			"mouseEvent",
			"kbdEvent"
		</arg>
	</init>

Then do whatever you need to do to cause a great person to be born and post PythonDbg.log again. :)

Done. The PythonDbg.log is substantially bigger now...5MB. It is located here : http://www.mediafire.com/?igb61khrn3fn47i
The PythonErr.log is located here : http://www.mediafire.com/?85yv5v8rc266fg4

We'll get there. BTW, how do you know your mod isn't working? Have you added any logging to your function using BugUtil.debug() or BugUtil.alert()?

We have removed the unique names from the xml files relating to the great peoples for our mod so this python mod from Gaius is the only thing that should be naming units automatically.

I have not used those 2 BugUtil functions ever in my life sorry
 
Looking in the log I see the event is being fired. It is the second and further appearances of "greatPersonBorn":

Code:
09:41:59 DEBUG: BugEventManager - event [B]greatPersonBorn[/B]: (<CvPythonExtensions.CyUnit object at 0x17028F10>, 0, <CvPythonExtensions.CyCity object at 0x1701FCA8>)

Now you need to figure out what's going wrong in your function. You can add these lines to your code and see them appear in PythonDbg.log. Open the log after causing a GP birth and look for "greatPersonBorn". You should see your messages:

Code:
def onGreatPersonBorn(argsList):
	'Great Person Born'

	[B][COLOR="Red"]BugUtil.debug("Great Person Born - start")[/COLOR][/B]
	pUnit, iPlayer, pCity = argsList
	[B][COLOR="Red"]BugUtil.debug("Great Person Born - %s", pUnit.getNameNoDesc())[/COLOR][/B]
	player = PyPlayer(iPlayer)
	infoUnit = pUnit.getUnitClassType()
	
	# Check if we should even show the popup:
	if pUnit.isNone() or pCity.isNone():
		[B][COLOR="Red"]BugUtil.debug("Great Person Born - invalid unit or city")[/COLOR][/B]
		return

	if(len(pUnit.getNameNoDesc()) == 0): # Rename units with no names - important to avoid confusion with event log
		[B][COLOR="Red"]BugUtil.debug("Great Person Born - renaming unit")[/COLOR][/B]
		iCivilizationType = player.player.getCivilizationType()
		# Pass the civilization and unit type along to the renamer
		newUnitName = CivSpecificGreatPeopleModNameUtils.generateCivilizationName(iCivilizationType, infoUnit)
		[B][COLOR="Red"]BugUtil.debug("Great Person Born - new name is %s", newUnitName)[/COLOR][/B]
		if (newUnitName != None):
			pUnit.setName(newUnitName)
 
Allright,

Using your BugUtils' logging function I managed to trace what was not working and it wasn't related to BUG...:blush:

I have one last problem that remains to be fixed. My great persons when manually selected show their name and then their type which is excellent. Now when the Great Person is born I would like to see it's new name in the top middle of the screen status text pseudo-box (I'm not sure what it is called) appear instead of the generic "A great philosopher/general/scientist/etc has been born in the city of xxx"

Is this do-able ?

Sorry if this is not directly related to BUG but I'm so close to finishing with this problem.

Thank you for your time
 
That message is built in the SDK before the event is fired. This is something Lemon Merchant had to deal with, so we ported the code from Python to the SDK. If you are limited to Python this is not possible.
 
That message is built in the SDK before the event is fired. This is something Lemon Merchant had to deal with, so we ported the code from Python to the SDK. If you are limited to Python this is not possible.

I'm actually far more comfortable in SDK than in Python :)

Out of curiosity what would be involved ?

On another note, I find your BugUtil.py file very useful. Is it possible to use it independently from the rest of the Mod for debugging purposes only ? Does the Bug Core.xml file need to be in the same place ?

thank you for your time
 
Top Bottom