Need some guidance on Python modding

Joined
Feb 3, 2011
Messages
608
Hello.

I want to add something to the Pedia - a section that describes Leader Traits and I need some pointers which files to work with etc.

I don't want to use existing mods (like BUG) because they add way too much things I don't like, + I want to learn on my own.

I have SOME experience modding Python - I added 1 extra religion, so not a total noob, just need some pointers ;)

Thank You!
 
Adding a new page is not something I do every day, but I can say parts you would like to look at. I'm not sure it's 100% complete though.


EntryPoints/CvScreensInterface.py has a pedia section.

Screens/CvScreenEnums.py contains a unique ID for each screen. You need to add one here.

CivilopediaPageTypes is an enum in the DLL. However if you want to avoid editing the DLL, you can set your new page to CivilopediaPageTypes.NUM_CIVILOPEDIA_PAGE_TYPES and you will likely be able to get away with it.

Screens/CvPediaMain.py has a lot of stuff you need in order to integrate a new page in a way. which makes it feel natural in the game.

Last, but not least, copy a pedia page in Screens and rename it to traits and use that one as a base for your new page.

PHP:
szSpecialText = CyGameTextMgr().getUnitHelp( self.iUnit, True, False, False, None )[1:]
       screen.addMultilineText(listName, szSpecialText, self.X_SPECIAL_PANE+5, self.Y_SPECIAL_PANE+30, self.W_SPECIAL_PANE-10, self.H_SPECIAL_PANE-35, WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY)
Code like that calls a DLL function to easily do a lot of line setups. You will have to write your own in python or edit the DLL to make your own python exposed getTraitHelp function.... or just skip writing that much.

I hope this is enough to get started.
 
I bothered to write a tutorial how to add new screens in the platypedia though
 
Hello Platyping, thank you for replying!
I really like your Pedia mod, and thinking just using it as a whole - I only changed some colors ;)

However a question - the section where Resource (Bonus) shows which benefits in gives to buildings I want to add something and I don't know how. I using a mod by Saibotlieh that allows buildings to get Commerce Modifiers from the bonus (just like Yield modifiers). (https://forums.civfanatics.com/resources/bonuscommercemodifier-for-buildings.13599/)

I believe the proper place to modify is in PlatyPediaBonus.py at :

Code:
           for k in xrange(YieldTypes.NUM_YIELD_TYPES):
               iYieldChange = BuildingInfo.getBonusYieldModifier(self.iBonus, k)
               if iYieldChange != 0:
                   sText += u"%+d%%%c" % (iYieldChange, gc.getYieldInfo(k).getChar())

I tried to insert something like this:

Code:
           for k in xrange(CommerceTypes.NUM_COMMERCE_TYPES):
               iCommerceChange = BuildingInfo.getBonusCommerceModifier(self.iBonus, k)
               if iCommerceChange != 0:
                   sText += u"%+d%%%c" % (iCommerceChange, gc.getCommerceInfo(k).getChar())

But I can't get it to work - Page loads half way and stops. Obviously I don't know what I am doing ;)

Could you give me a hand please ;)

Thank You!
 
1: edit the ini file and enable python error reporting. (or disable hiding or whatever they called it)
2: getBonusCommerceModifier is not exposed to python, meaning python will tell you that the function doesn't exist and not run anything in python after the failing line.

PHP:
//BCM: Added 21.9.09
   DllExport int getBonusCommerceModifier(int i, int j) const;               // Exposed to Python
   int* getBonusCommerceModifierArray(int i) const;
  
//BCM: End
For that to be true, as in really exposing the function to python, you need to edit CvInfoInterface1.cpp. Scroll down to the line
PHP:
python::class_<CvBuildingInfo, python::bases<CvInfoBase, CvScalableInfo> >("CvBuildingInfo")
Somewhere in there add the new function, I propose this:
PHP:
.def("getBonusYieldModifier", &CvBuildingInfo::getBonusYieldModifier, "int (int i, int j)")
//BCM
.def("getBonusCommerceModifier", &CvBuildingInfo::getBonusCommerceModifier, "int (int i, int j)")
//BCM
That way the functions are in the same order in the header and in the cpp file, which helps navigate them.

DllExport is to allow the exe to access the function. Since the exe has hardcoded which functions to call, it will never call modded ones and as a general rule modders should never add DllExport to their own functions.

Hello Platyping, thank you for replying!
I really like your Pedia mod
We all do. We just forget to say it on a daily basis :mischief:
 
If it is just modifications for your mod, you can also choose to scan the whole building info xml file to detect any building with non zero commerce modifiers.
I remember the Sistine Chapel or some wonder gave some global bonus to Specialists or so, but that particular building effect is oddly not exposed to python.
The Specialist page is then using that method, which is an ugly method for python users who cant be bothered to edit the dll to expose that function to python.
 
Coz by default it is scanning the BTS xml file. You can remove that section if no buildings are using that power
 
I could fix this and make a new release, but I don't want to hijack mods from other people. The exception is if the modder is long gone, but that doesn't seem to be the case here.
You are certainly welcome to fix/mod that mod (or any of my other mods) and publish that. :)
 
Top Bottom