[MOD] Modular Python

odalrick

Emperor
Joined
Nov 12, 2003
Messages
1,114
modular python

The this is a beta release so expect bugs and non-existent documentation.

What do you want to mod in a modular fashion but have been unable to because it requires python?

Is there anything about using this mod that is needlessly complicated?

v.5 is for Fall Further 051 B
v.7 is for Fall Further 051 C

However, the only changes that affect modular python are a few bugfixes and the change to warrens, so either version should work with both patch B and C.

v.6+ is for Fall Further Plus 021 E

It's based on Fall Further 051 C, which Fall Further Plus 021 E isn't. That shouldn't matter much though.
 

Attachments

  • Fall Further modular python v.5.zip
    57.3 KB · Views: 116
  • templatemod_v.3.zip
    14.7 KB · Views: 124
  • Fall Further modular python v.6+.zip
    64.1 KB · Views: 82
  • Fall Further modular python v.7beta.zip
    57.1 KB · Views: 179
Installation

Short version:
Unpack the latest Fall Further modular python.zip to your Fall Further installation directory or a copy there of.

Further details:
This only overwrites two files: CvEventInterface.py and CvGameInterface.py.

As of version .6 there can be more than one concurrent installation of modular python, but it requires some customisation:

Create a file named modularPythonModDir.py in the Assets/python with the content:
Code:
modDir = r"Fall Further modular python"
where Fall Further modular python is the name of the directory the basemod is in. (For a normal install of Fall Further this would be Fall Further 051 .)

This needs to be done for each directory where you install modular python, but you'll never have to repeat it when you upgrade.

The old method of modular_python_marker.txt still exists, so this is only necessary if you want more than one installation of modular python.

Uninstallation

Replacing CvEventInterface.py with the original CvEventInterface.py.bak and ditto for CvGameInterface.py removes all changes made by this mod.

One can then remove the installed files, but it's hardly worth the effort.

Bugs:

Problems with the event handlers will output a discreet message that says an error has occurred and logs the error to modular_python_errors.log in the mod directory. These errors generally indicate that I transcribed something incorrectly.

Problems with the system itself will manifest the same way as all other python errors. I hope there are none.
 
Modular Python Module

Making a mod-module is currently somewhat complicated. One pretty much has to read all the added files to make something completely new. Copying and modifying an existing event handler should be much easier.

I am working on making the system more consistent and better documented.

templatemod.zip contains an example of how to make a module that uses python.

It's a simple mod-module that makes the following changes.

  • Removes the dawn of man popup and that annoying review your civic choices you get at the start. I hate those.
  • Changes dwarves to get experience based on the number of available ale resources, rather than presence of a brewery.
  • When the Catacomb Libralus is built, two adepts with Channeling II are spawned, similar to the Pact of the Nilhorn.
  • Living units can have their soul processed at the Soulforge, while they are still alive. It's slightly less efficient than killing them, but you get to keep the soulless husk.

Install by unpacking templatemod.zip to your modular python mod directory. Uninstall by deleting the Assets\Modules\NormalModules\modularPythonDemo directory.

If you want to make python-mod-modules, I think looking at the code in templatemod and fallFurtherEvents
should be enough to understand the python part.

In order to load the modular code, there needs to be an ini file in your module as well. Again looking in the modularPythonDemo.ini should be fairly self-explanatory. There are however some non-obvious limitations. The python file must be in lowercase and the module itself needs to be in some subdirectory of Assets\Modules\NormalModules.

Both of those limitations are because adding new xml tags require dll work.
 
So wait, let me make sure I'm reading this correctly.
Once Modular Python is installed, I can then make multiple modular files that use Python scripts, but that could be uninstalled and installed individually without a complicated process?
 
Yes.

Well, not everything you could do with python. Currently only what you would normally do by modifying CvEventManager and as a freebie of sorts, spells.

But that is part of the reason for posting the mod. What python do you want to modify in a modular fashion?

Some events are excluded, like onUpdate, because they run really often. Or other reasons. They could easily be added.
 
Wow.

The main purpose is to gauge interest and find out what modders want to mod.

Consider me a voter for "Very high interest." While I'm not sure how much attention I'll be able to give further modding, modular python would greatly increase my desire to keep my hand in.
 
Count me in too. I will use and abuse anything modular I can. It's just plain easier, in a lot of ways. For example, with this I can get Mendacites working the way I'd want instead of having to have one for each spell-casting religion (and thus making them harder to limit.).

CvGameUtils.py would be something I would look heavily to being able to use modular python on too- it's where Fall Flat used to store the code that told the AI what to research to not be a moron. It's also a great place to lock and unlock units and buildings from certain leaders within the same civ.
 
If you would include thoses files it would be perfect for me (the one I modified for the Tears):

CvEventManager.py
CustomFunctions.py
CvSpellInterface.py
CvGameUtils.py
CvMainInterface.py

Very strong interest. :D
 
Making the python modular basically consists of finding places where it would be interesting to be able to run a custom function and allowing custom functions to be run there.

It means that there is a smallest unit that can be replaced.

For instance, suppose you want to change spring to create an Oasis in the desert, rather than turning it to plains.

If you modify the source code directly, you can add a few lines and be done.

If you use modular loading, you have to copy the entire code for spring, make the changes and tell civ to replace the current spring functions with your new ones.

If anyone else changes spring, it will overwrite your changes.

CvEventManager.py
Is completely replaced. A few events are unavailable for modular loading, for various reasons. They're easily added if there is a need for them.

There is a lack of consistency in their usage, but I'm working on that.

CustomFunctions.py

Seems to consist of a bunch of unrelated functions, written by someone with javaitis.

Some are basically already event handlers, like doTurnKhazad or rebuildgraphics. All I did for them is wrap them in a lambda. I'll possibly rewrite them later.

Others are essentially database querys, getHero. They will require a little more effort, but are fundamentally modular.

Then there are logic functions, like getOpenPlayer and dogpile. I see little reason to modularly replace them, but I'm willing to be persuaded otherwise.

There is also the lair system that deserves to be in it's own python module.

CvSpellInterface.py

There is little reason to change CvSpellInterface since the various PySomething tags can already refer to functions in other modules.

CvGameUtils.py

A very good candidate for modular python. Very similar to CvEventManager, I'm actually surprised that it's a different file.

I will wait until the current replacements are somewhat bug free before tackling this, though.

CvMainInterface.py

I haven't done a lot of UI programming and I haven't looked at the specifics so I don't know how easy would be to make it more modular. Maybe it's easy to change, lot's of interfaces are created dynamically after all. At the very least I should be able to add a few widgets that could in turn be changed by modules.

This python module will have to wait until the end, though specific requests could be fulfilled earlier.

CvRandomEventInterface.py

Works differently from CvSpellInterface but is very similar. Should actually be fairly easy to modularize.
 
Release .2 alpha

This version makes CvEventManager modular, so any changes that would normally go in CvEventManager can be modularly loaded.

I don't think I'll remove any functionality from this version, which means that mods made for this version should work in all future versions.

Next I'll work on CvGameUtils.
 
Are you going to need to maintain this for each FF release?
Will end users need this installed to use modules with python in them?

I'm going to attempt to use this in the module I'm working on just now. Will post problems/results
 
Yeah, I'm looking at this and going "ooh, shiny." But it would be even shinier if I didn't have to ask my players to re-download it when we patch. XIEN!!! :)D)
 
It'll be a long time till I can rigorously test anything, let alone something I haven't written myself. So since this is python only someone else could easily test it and slip it in, otherwise I need repeat verification (ie - multiple sources, or exhaustive testing) that there isn't a considerable overhead cost to turn speed. Haven't looked at precisely how this attempt is done, I just know that the main complaint/issue I have seen with previous modular python mods had speed at the source. (I am VERY interested in getting everything as modular as possible, just also concerned with speed as it is the major complaint about FF which I have little [easy] control over)
 
Understandable. I may make a testbed mod version and run a little testing. Got a lot of time on my hands till Oct anyways.

Anything specific you'd think I could do to test the speed overhead cost?
 
random seed on reload disabled, save immediately after game loads up, run AIAutoplay for 100 turns and save. repeat a few times on the same save to verify that the time is reliable, then add/remove modular python and repeat, compare times. Do this in 100 turn chunks through turn 500 or so on various map/player combinations (small/crowded, large/open, and small/default, large/default). Just use a wall clock or stopwatch for comparisons
 
Replacing CvEventInterface.py with the original CvEventInterface.py.bak removes all changes made by this mod.

This also includes a somniumintterface.py

What exactly did you change in there? and why wouldn't changing that back also be necessary to uninstall ?
 
Top Bottom