help with changes from 3.5 to 3.6

I'm glad that worked. Part of the reason for the "magic" is that I'm learning Python as I work on BUG combined with Civ4's "interesting" handling of Python and initialization. As I find better ways to have BUG work, I add them in.

The other problem is that most mods out there are written to work with CvCustomEventManager. This really isn't the best way to write it, but it was at the time. It requires a lot of "cruft" that just isn't needed by Civ4 or BUG.

The last difficulty is that I write documentation for coders, and it's very hard to write documentation that is to be used by people who range from beginners to experts. When I read docs, I want short reference guides as I know how to look up the things I don't understand. Someone who doesn't know programming won't know the difference between a module- and class-level function or why you'd want one over the other.

I wonder, will providing several working examples be enough for others to rewrite mods they want to merge with BUG? If I were doing the merges, I'd want to do as little work as possible (see Reminder Mod). But I've added features to BUG to make it easier to write new mods that work in BUG.

This is why I am very happy to get your feedback. I wish more modders would speak up about what helps and what was too complicated.
 
After decades working in IT I know that the only way the documentation will be fixed is if someone talks about what is actually wrong and not by just saying "this doco is rubbish" :) On that topic I think a why do this or that style document is perhaps needed just so that people can get an idea that they would like to use BUG. The one I have been writing for myself is short and mostly just dot points which link the various bits together.

Somewhere in the documentation I got the idea that if I fire an "CityRazed" event BUG will ensure that all "onCityRazed" events in all mods. Is this right? That is will it call the default one in CvEventManager, and the one in OrionVetran's Inquastion mod, and the one in Rise of Mankind (when both have been converted to BUG)? If so this will make merging mods so much easier. For example in the Abandon City Demolish Building mod I can just call such an event and then leave rest of what happens to the other mods. Naturally I would need to call it in the right order - actually thinking about it this may be fraught with danger :)
 
On that topic I think a why do this or that style document is perhaps needed just so that people can get an idea that they would like to use BUG.

That's a good idea. I had originally intended to release the BUG Core (no features--just the core/options/events backbone) as a separate mod for people to build upon. However, I just don't have the time to manage so many code releases. :(

Somewhere in the documentation I got the idea that if I fire an "CityRazed" event BUG will ensure that all "onCityRazed" events in all mods [are called].

As long as each one is hooked up either with an <event> or <events> entity. Use <events> when you are converting an old-style event manager that has addEventHandler() calls in its __init__() function. Use <event> when you have a module-level function that should be called.

Yes, once the above is taken care of during initialization, BUG will call all handlers for an event. There are a few "consumable" events such as onKeyDown that work differently. BUG will call event handlers in order until one of them returns a value greater than zero (1 is typical). This is a signal that the event was handled and should be consumed.

All events are called in the order they were attached to the event manager. I considered adding some way to order the events manually, but that really shouldn't be necessary and would complicate matters greatly.
 
Here is another new to python type question. Or bit of missing doco.

In the firing events part of http://apps.sourceforge.net/mediawiki/civ4bug/index.php?title=Core_Events you give examples of how to use it.

Being trusting ;) I used this code with appropriate arguements to call the onCirtRazed event and got an error.

Code:
Code:
	#Call the onCityRazed event to do whatever the other mods do when a city is raised
	#rather than put the code here making this more generaly usable
	# according to http://www.apolyton.net/forums/showthread.php?t=140611
	# the argsList for CityRazed are: city, iPlayer
	CvEventInterface.getEventManager().fireEvent("CityRazed", pHeadSelectedCity, playerID)

Error:
Code:
NameError: global name 'CvEventInterface' is not defined
ERR: Python function applyEvent failed, module CvEventInterface

A pointer to the code where the examples came from would probably give me enough to sort my problem out by myself.
 
You need to import any module that you use before you use it. In other words, for Foo.py to use Bar.py, it must have

Code:
import Bar

before it uses anything in Bar.

Place

Code:
import CvEventInterface

at the top of the module that contains the call to CvEventInterface.getEventManager().
 
I guessed CvEventManager which naturally did not work. Interesting, it does not seem to be calling the "default" onCityRazed event in cvEventManager.py. Or is my assumption that the default events in cvEventmanager.py would be called without me doing anything wrong. I am just trying to save myself a huge amount of copy, pasting and getting the indents right when I merge this with RoM ;)
 
BUG is designed to use the original CvEventManager, and it does call its functions. If RoM replaces the CvEventManager module, BUG should still work--it's just not recommended to do it that way.

I designed BUG so that you only have to tell it about the stuff that you add. This is how CvCustomEventManager worked as well.

How exactly does the AC mod abandon a city? Perhaps its method doesn't result in the cityRazed event being fired.
 
Yea, well, RoM was written before BUG ;) so there is some of its code in the cveventmanager but it looks like it maybe possible to move it all out with a bit of effort. I was going to try and do it for the owner of the mod as some "payment" for all his/her work. Currently, the way other mods that have been included in RoM have been written and the RoM stuff itself put a great deal of code under the various events in cveventmanager extending their function. With BUG we should be able to move this code out of here and reduce the amount of coding changes that happen all over the place. At least that is what I think can be done.

The original abandon mod just calls
Code:
				pHeadSelectedCity = CyInterface().getHeadSelectedCity()
.....
				# Abandon the City
				pHeadSelectedCity.kill()

I put a trace print in the onCityRazed event in cveventmanager to see if it was being called.

Code:
	def onCityRazed(self, argsList):
		CyInterface().addImmediateMessage("onCityRazed called", None)

The trace was not being displayed so I added code to fire the event
Code:
.....
				CvEventInterface.getEventManager().fireEvent("CityRazed", pHeadSelectedCity, playerID)

				# Abandon the City
				pHeadSelectedCity.kill()
The trace is still not happening but the kill() and code after it are still happening. I can tell because the correct number of units are appearing.
 
The only place that the cityRazed event is fired is from CvPlayer::raze(CvCity*), and this method is exposed to Python. Further, this event takes care of moving the Holy City if it is one. It also posts the message to the screen/log and does other bookkeeping, so I suggest that you use it instead of kill():

Code:
# Abandon the City
gc.getGame(pHeadSelectedCity.getOwner()).raze(pHeadSelectedCity)

Regarding your attempt to fire the event manually, the name of the event must match what appears in CvEventManager exactly, including case. It is "cityRazed", not "CityRazed". Most of the events begin with a lowercase letter, but not all (brilliant!).

Finally, you shouldn't need to move all the RoM code out of CvEventManager as long as all its version does is add code to the existing event handlers or add new events. It would be a good thing to do as it would make it clearer what parts belong to RoM. When I can, I extend existing classes instead of replacing original modules. Sometimes you have no choice.

I just tested this code, and it works somewhat. One of the checks in canRaze() looks to see if your team culture percent >= 25 (default value in global defines XML). It let me disband a city that hadn't grown to the second ring, but not my capital. The tile for the city it disbanded said 100% Indian (my civ), so I don't know why it let me do it there.

If your mod is going to use a custom DLL, the solution is to add a "bForce" parameter to CvPlayer::raze(CvCity*). If not, you'll have to stick with kill() or disband() [stores the name of the city and checks if it's your last city]. You should probably copy some of the code from raze() into the Python module, especially the holy city handling.
 
Thanks for all the help :goodjob:

I have released the Abandon City Demolish Building mod both in its thread and in Rise of Mankind so others can use it. I ended up using the cityRazed event rather than the raze() function because sometimes it would not abandon the city and that is the point of the mod :)

Now to start work on the "Great People mod" which is a candidate for BUG as it just displays a pretty picture to the player when a great person is born; but that is a topic for another thread.:D
 
I have released the Abandon City Demolish Building mod both in its thread and in Rise of Mankind so others can use it.

Excellent! :goodjob:

Now to start work on the "Great People mod" which is a candidate for BUG as it just displays a pretty picture to the player when a great person is born; but that is a topic for another thread.:D

Actually, I've already done this one. I didn't include it in BUG only because the art package is 200MB, and BUG is 4MB. I toyed with the idea of having the Python part in BUG and the art in BAT or let people download the art separately. Now that we're using NSIS for the installer, there is a plugin that will download pieces during installation. I'll take a look there.

Give me a couple days and I'll package up the code if you just want to use it in your own game, or feel free to do it yourself. It really wasn't much work as there's just one event to handle. Let me know.
 
If you have it then that would be good, I can learn from reading the code almost as well as I would if I did the stuff myself. Which version of the mod and art did you use? A new version of the art was done awhile ago.

I would like to package it into the mod I play - yes people make mods for zappara's Rise of Mankind mod. Naturally you would get the credit.
 
I just looked at the code merge I did, and it's from the end of June! Thus, it predates the new BUG core and is pretty useless. It will need to be redone. If you do it and I add it to BUG/BAT, I will of course credit you. ;)
 
Top Bottom