zModular Python

Zebra 9

Emperor
Joined
May 17, 2006
Messages
1,554
Location
Middle of Cyberspace
zModular Python

Version: 1.0
Creator: Zebra 9
What Is It: MOD COMP for MOD COMPs or more specificly the most wonderful thing to hit Civ IV since Final Frontier
Is It MP Compatable: Only if the zModule(s) that you are running are

Description:
A MOD COMP that allows MODers to make Drag and Drop python MOD COMPs called zModules. This is not standalone and is not intended to be used by non MODers (although you will reap the benefits). It is mainly intended for MODs but if you want to use it to run a zModule (a drag and drop Python MOD COMP) see below.

Installation:
Copy the files to you MODs python directory and you are all set to drag and drop.
Again, this is intended mainly for MODs but if you want to use it to play with a zModule just create a directory in your My Documents/My Games/Beyond the Sword/MODS directory. Inside of the directory that you created make a folder named Assets, inside of it make a directory named Python, then paste this MOD COMP in there along with your zModules.

Credits:
Dr. Elmer Giggle for the Event Manager system
Civfanatics for inspiring me to learn python

Enjoy :goodjob:

 
To make a zModule for zModular Python create a folder in the python directory of your MOD. Inside of
this folder you will put a Load Order file and your python files. The Load Order file named should be
in the format of "*LoadOrder*.zcnfg" where a * is any text that you want. This file tells zModular
Python what files to use and what to use them for. So in the file you have a Game Utils file list
and/or an Event Manager file list. These lists look like this:
Code:
[Game Utils]
	File = A Python File.py
	File = Another Python File.py
[/]
[Event Manager]
	File = A Python File.py
	File = Another Python File.py
[/]
Now to make the python files compatable with zModular Python you only have to put a function named
EventManager to initalize your event managers and/or a function named GameUtils to initialize your game
utils manager. These functions will probably look like this:
Code:
def EventManager(manager):
	MyEventManager(manager)

def GameUtils(manager):
	MyGameUtilsManager(manager)
I know what your thinking, "This is all jim dandy but we still don't have a way to access the
CvGameUtils file without making a copy of it." Well I took the time to invent a system that is very
similar to Dr. Elmer Giggle's Event Manager, but it works with the CvGameUtils. Here is how it works.
When a call is made to a function it runs through all handlers that are registered for that function
and runs them. When it recieves the return it checks to see if it is different than the default value
(the values in the unMODed CvGameUtils), if it is it stops calling the handlers and returns that new
value to the SDK, if it doesn't find a new value it returns the default. The code to register a
Game Utils handler looks like this:
Code:
class MyGameUtils:
	def __init__(self, manager):
		manager.addCallbackHandler("cannotTrain", self.cannotTrain)

	def cannotTrain(self, args):
		pCity = args[0]
		eUnit = args[1]
		bContinue = args[2]
		bTestVisible = args[3]
		bIgnoreCost = args[4]
		bIgnoreUpgrades = args[5]

		if eUnit == 0:
			return True

		return False

def GameUtils(manager):
	MyGameUtils(manager)
The first arg of addCallbackHandler is the key of the function you want to use. This key is the same
as the function, so it's easy to remeber. The second arg is the function to be used. To help keep it
simple the Event Managers use Dr. Elmer Giggle's syestm, so all old MOD COMPs should be semi compatable.

Now there is one problem, you can't have 2 python modules with the same name. This is something I am
working on a fix for, but in the mean time avoid multiple files with the same name.

Oh, and one last thing, DELETE YOUR MOD's PythonCallbackDefines.xml FILE!!!! zModular Python automatically
activates all required python functions!
 
Hooray! It's finally here! I have a few questions:

1) Does this work for screens (specifically individual parts of screens)?
2) Can the folder under Python have any name you want?
3) Are you interested in merging this with the WoC? ;)

Other than that, this looks like a massive jump in Python modding. :goodjob:
 
Wow, very cool Zebra 9. Very cool that you cloned Dr. Elmar's CustomEventManager for the GameUtils file. I can't wait to get the code downloaded and look through it. :>
 
Well after looking more closely at the screens I have decided that there is no real way of making them modular so I'm not sure that I will. The problem is that nobody will know what is there; so one mod puts text there, another over there, all to be covered up by a third mod. :sad:
 
I don't know what you're saying. What I'm suggesting is being able to turn individual parts of the screen on and off (those parts which can't be made optional through Python itself). In what way is it hard to make the screens modular?
 
I don't know what you're saying. What I'm suggesting is being able to turn individual parts of the screen on and off (those parts which can't be made optional through Python itself). In what way is it hard to make the screens modular?

I think a better question would be what "parts" or what screens are you trying to turn off?

I have to agree with Zebra 9, all EventManagers and GameUtils files define and call the same functions, but the only similarity bewteen screen files is that they all use the GScreenInterface library. Not mention the fact that every screen has to know all the pixel locations to put all the widgets.. Bottom line, screens are all to individual to modularize them.
 
What will happen if you don't delete the pythoncallbackdefines.xml?
Nothing, it just that zModular Python will automatically turn on the required tags. So you won't need that file. :D
 
Ok, people, it appears that Johny Smith has talked me into zModularizing a few things for WoC. I'm also gonna try zModularizing all my MOD COMPs. :D
 
Agh, I have just finished coding and started testing a replacement for zEnslavement. It does the same things but allows the captured unit to be different to the losing unts. That way pirate ships can capture a galley and it turns into another (early) pirate - or maybe a prize ship - whatever the modder wants.
 
I just noticed zebra posted in here again. Thanks again zebra.:) I hope you are successful can help a lot modular modders out there.
 
Agh, I have just finished coding and started testing a replacement for zEnslavement. It does the same things but allows the captured unit to be different to the losing unts. That way pirate ships can capture a galley and it turns into another (early) pirate - or maybe a prize ship - whatever the modder wants.

zUnitEnslavement already did that. ;)

You could set it to have any kind of unit produced from a succesful enslavement. Some of the examples in the faq included having all sea units captured become workboats, all land units captured become workers, etc.
 
zUnitEnslavement already did that. ;)

You could set it to have any kind of unit produced from a succesful enslavement. Some of the examples in the faq included having all sea units captured become workboats, all land units captured become workers, etc.

Not in the code I downloaded it didn't - perhaps that feature was in the XML capture tag. But what I really wanted to do was have units captured as slaves to start with then as various types of "prisoners of war" depending on the advances and things like "The Geneva Convention on Warfare".
 
Top Bottom