Announcement

Collapse
No announcement yet.

MOD Authors: Making your Mods more pluggable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • MOD Authors: Making your Mods more pluggable

    I have seen a few questions about how to combine mods. The ideal would be able to easily turn multiple mods on or off... perhaps you want to use someone's improved epic game mod, TheDarkside's real fort and auto missionary mod, and someone else's improvement to one of the game screens.

    Civ IV of course doesn't support more than one mod at once, and likely never will. I am working on a utility to make comparing and merging mods easier. However, in the meantime, I would like to offer some advice to modders on how to make their mods easier to combine with other mods.

    This applies mainly to mods that modify CvEventManager.py. I personally would hate to have to insert small changes in such a big file, surrounding them with comments about where the changes begin and end. Furthermore, if this file is changed in a patch, then existing mods would need to be updated to include the changes from the patch.

    It is possible to avoid most of these problems. You can create a class that derives from CvEventManager (I got this idea from the Greek World Mod). You only have to define overrides for the events you want to handle. You can then change two lines in EntryPoints\CvEventInterface.py to have the game use your derived class. If you have overriden a method, then that method will get called, otherwise the normal method from CvEventManager.py will be called.

    Since I have not made any mods yet myself, I have refactored Bhruic's real fort mod to show how this can be done. The class CvCustomEventManager overrides the normal event manager. The real logic for the mod is in a seperate file named RealFort.py. The CvCustomEventManager overrides 3 of the event handlers, and calls appropriate methods in the RealFort module as well as the methods in the base CvEventManager class.

    I have verified that the mod will load without any errors, but I did not have time to test whether it still actually adds the fort bonusses as it should. In any case it still serves as a good example for how to seperate your mod-specific code from the base game files.

    Enjoy!

    EDIT: Somehow I originally miscredited the author of the real fort mod to TheDarkSide instead of Bhruic. Oops!
    Attached Files
    Last edited by dsplaisted; November 10, 2005, 11:26.

  • #2
    good idea.


    It would be even better if something similar existed for xml-modding.
    no sig

    Comment


    • #3
      xml modding

      Well I don't think there's any good way to override just part of an XML file, especially not supported by Civ IV. It is not so bad though because I am writing a program that will compare the changes in two different mods and merge them. This is hard or maybe impossible for a computer to do for any old python program, which is why I suggested a sort of standard for the python modding. However it is not too hard to do this for the xml files.

      Daniel

      Comment


      • #4
        This sounds like great idea, dsplaisted!

        But just to clarify, the RealFort mod was not authored by myself.

        However in the mod I have released I do rely on commented the sections of code so that it can be cut & pasted in another file like you describe, and I agree this is not the best way to do it.

        I am familiar with the process you are describing. When I first released the building demolition mod I did it that way (overriding EventManager copying the way it was done in the Desert War mod) but I didn't like the fact that it was an actual MOD which you had to configure during startup for such a small simple script change. I never thought of using that same inheritence model in the customAssets folder.

        Comment


        • #5
          Originally posted by TheDarkside
          I am familiar with the process you are describing. When I first released the building demolition mod I did it that way (overriding EventManager copying the way it was done in the Desert War mod) but I didn't like the fact that it was an actual MOD which you had to configure during startup for such a small simple script change. I never thought of using that same inheritence model in the customAssets folder.
          Here is my vision: All mods are released using this inheritance model. Users install mods in the Mods folder, not the customAssets folder. Then users run the Mod Merge program I am writing, to merge all of the mods they want to use together. Hopefully in most cases this will be fully automatic. Then they could save the merged mod either in their customAssets folder or as a mod that they would load seperately.

          Comment


          • #6
            I was looking at the code and I want to make sure I'm understanding it right. You (or whoever wrote realFort) give the unit a temporary promotion when it is on a fort square and remove it when it moves off. Is that correct?

            The three methods you override are onUnitMove, onImprovementBuilt, and onTechAquired.

            I've never looked at Python before so all of this is new to me.

            Comment


            • #7
              Is there no way to do a Morrowind style Mod checkbox type hing where you can pick and choose which mods you want to load up at start up and which you want to disabled?
              Currently working on:
              A Song of Ice and Fire Mod for Civ 4!
              Click me to find out more!

              Comment


              • #8
                As a more concrete example:
                Code:
                import RealFort
                import TechConquest
                import CulturalDecay
                	
                gc = CyGlobalContext()
                
                rf = RealFort.RealFort()
                tc = TechConquest.TechConquest()
                cd = CulturalDecay.CulturalDecay()
                
                # globals
                ###################################################
                class CvCustomEventManager(CvEventManager.CvEventManager):
                	def __init__(self):
                		# initialize base class
                		self.parent = CvEventManager.CvEventManager
                		self.parent.__init__(self)
                
                	def onUnitMove(self, argsList):
                		self.parent.onUnitMove(self, argsList);
                		rf.onUnitMove(argsList)
                		
                	def onImprovementBuilt(self, argsList):
                		self.parent.onImprovementBuilt(self, argsList)
                		rf.onImprovementBuilt(argsList)
                		
                	def onTechAcquired(self, argsList):
                		self.parent.onTechAcquired(self, argsList)
                		rf.onTechAcquired(argsList)
                		
                	def onCityAcquired(self, argsList):
                		'City Acquired'
                		self.parent.onCityAcquired(self, argsList)
                		tc.onCityAcquired(argsList)
                
                	def onEndGameTurn(self, argsList):
                		self.parent.onEndGameTurn(self, argsList)
                		cd.onEndGameTurn(argsList)
                This is my CvCustomEventManager.py file. As you can see, I don't have to make large changes to it every time I want to make a new mod. All I have to do is add the new override (if I'm using one), add the function call, import the file and add a new global.

                It's much easier than scanning through a bunch of files for modifications and cutting and pasting.

                And if I want to remove a mod, all I have to do is comment out the lines in the single .py file.

                Bh

                Comment


                • #9
                  Is there no way to do a Morrowind style Mod checkbox type hing where you can pick and choose which mods you want to load up at start up and which you want to disabled?
                  ++

                  i was going to suggest exactly that, but i couldn't remember which game it was from.

                  a front end for plugins would be absolutely ideal.
                  it's just my opinion. can you dig it?

                  Comment


                  • #10
                    Can anybody help me please?

                    I tried to merge some mods by the method you showed and it worked for all but one.
                    The mods which are working:
                    - RealFort
                    - TechConquest
                    - Monument
                    - ForestryMod

                    The one that doesn't work is the
                    - AbandonRazeCityMod
                    I will load my python dir from CustomAssets up. It would be very cool if someone can figure out what I'm missing.
                    Attached Files
                    Last edited by feivelda; December 1, 2005, 14:41.

                    Comment


                    • #11
                      It seems someone over at Civ Fanatics has created a Mod Merging Program, though its still in the very earliest versions

                      It's great that this game is as moddable as it is, but one major shortcoming of the system is the inability to easily combine mods. I got fed up with hunting and merging changes by hand before I even started it. What we need is a mod switcher and since there are apparently none available yet...


                      It handles XML and Python by analizing the line by line differences in the files then creates a merged file.
                      The moding practices advocated here would still be of imense help when it comes to mod-merging with such a program as the chance of colishion would be lower and the code just cleaner and easier to handle.
                      Companions the creator seeks, not corpses, not herds and believers. Fellow creators, the creator seeks - those who write new values on new tablets. Companions the creator seeks, and fellow harvesters; for everything about him is ripe for the harvest. - Thus spoke Zarathustra, Fredrick Nietzsche

                      Comment


                      • #12
                        A question:

                        In your CvCustomEventManager.py you import

                        from CvPythonExtensions import *
                        import CvUtil
                        import CvScreensInterface
                        import CvDebugTools
                        import CvWBPopups
                        import PyHelpers
                        import Popup as PyPopup
                        import CvCameraControls
                        import CvTopCivs
                        import CvEventManager
                        import sys
                        import RealFort

                        but in the regular CvEventManager.py it imports

                        from CvPythonExtensions import *
                        import CvUtil
                        import CvScreensInterface
                        import CvDebugTools
                        import CvWBPopups
                        import PyHelpers
                        import Popup as PyPopup
                        import CvCameraControls
                        import CvTopCivs
                        import sys
                        import CvWorldBuilderScreen
                        import CvAdvisorUtils
                        import CvTechChooser

                        The difference being that your file doesn't import

                        import CvTopCivs
                        import CvWorldBuilderScreen
                        import CvAdvisorUtils
                        import CvTechChooser

                        Question: does your file get those anyway because it imports CvEventManager which them imports them? If so, why do you need to import anything other than CvEventManager and RealFort ? Also, is there any danger/problems with importing something twice?

                        I just want to get this rigth to same myself a lot of headaches when I finally take a shot at doing a mod.

                        Roger Bacon

                        Comment


                        • #13
                          I don't think that the imports are a problem.
                          In monument and RazeCity I don't know what I need as imports, so I decided to use this in the original file.
                          But this was a CvEventManager.py, so many of them aren't needed.
                          At the point all is working I will try and error what imports I don't need
                          I think I will throw the Monument mod out of this because it's not the thing I thought to be.
                          Last edited by feivelda; December 2, 2005, 02:18.

                          Comment


                          • #14
                            I think it was a bad idea to start this here, I'm opening an extra thread for this.
                            Last edited by feivelda; December 2, 2005, 04:34.

                            Comment


                            • #15
                              I have been experimenting with the Mod merging program I mentioned earlier and am having a lot of success

                              I have successfully merged together and confirmed the workability of the following mods

                              RealFort
                              Improved Display clock
                              Lost Wonders
                              Expanded Promotions
                              Homegrown Domestic Advisor
                              Medival Weapon Mod

                              Several other mods are in as well by either didn't function (Great Person) or havent been confirmed to function yet (Tech Conquest). I am confident that they can be combined especialy if their authors were to update them the the Modability standards dsplaisted layed out.

                              As I worked on the trickier mods I developed a few extended guidlines that should help improve plugability.

                              1. All moders should use a standard template of Entry Point overriding Scripts like CvCustomEventHandler, eventualy we should have a full set that will override everything such as screenhandler and diplomacy.

                              2. Each Extended Handler with have its own Custom file that we will also be provided in a downloadable template. The mod maker will only need to add their code, idealy as a single function call in the apropriate place. All Mod logic will be keept in a seperate file for maximum mergability.

                              3. Add as little as possible to the Custom file, idealy a single import and a single call. Avoid doing any defines which someone else might step on, for example "argumentlist = stuff for my mod". I have already seen mods colide over this. If you must use a define name it very explicity such as "MyModNameArgLst = stuff for my mod".

                              4. Package your mod with only the files you have altered from the template library, the top most directory should be named after your mod and its version, it should contain your readme and config and an "Assets" directory. Assets should contain all the mod files in proper directory structures like that found in Civ4's normal Asset directory.

                              5. Large mods should be as Modular as possible, I have seen several very large mods out their that touch dozens of different parts of the game, some changes I agree with and some I dont. With efficient mod merging now avalible to us it should be easy for mod makers to seperate mods of each part of the mod that can stand on its own. Each piece can be provided for download seperatly and merged by the user.

                              6. An even more atractive option would be to post the compiled merge files produced as they are considerably smaller then the whole mod (uless your including art which dose get incorporated but takes up sligtly more room then it normaly would). This would make things even easier for end users, its simply Download/drop files in folder/Open mod merger/click check boxes/Press Button/Launch Civ 4


                              Advice on using Mod Merger, First I sugjest everyone thorougly read the original authors posts and follow his instructions for Instilation. The program requires Glade run time environment which he provides a link to download if you dont have it.

                              Set up Preference with the apropriate pathways, the first is your Civ 4 directory, this is ware the program looks to see what constitutes "normal" and how a mod is different either in the addition of files or in alterations to them. Most people will use:

                              C:\Program Files\Firaxis Games\Sid Meier's Civilization 4

                              The second pathway is for the Mod directory ware the merge files will be placed and searched for when your presented with check boxes, I sugjest creating a folder within the program directory called "Merge files" or something along these lines. If you download pre-compiled merge files place them here to access them.

                              The third pathway is ware the program places the final output, a fully usable Mod ready to be played. Either use

                              C:\Program Files\Firaxis Games\Sid Meiers Civilization 4\Mods\MyCombinationMod\Assets

                              To get a Mod you can load like any other

                              C:\Documents and Settings\Username\My Documents\My Games\Civilization 4\CustomAssets

                              To get Custom Assets that will load everytime you launch Civ 4

                              To create merge files go to Mod, Create Mod select the mod file (note the mod must be configured with Assets directly underneither the selected directory and have all the proper heirchy of directories in order for it to compile correctly). The terminal will output the information on what files were found to be different or new. Examining the output should give a good idea as to your success. Now the merge files has been created and a new check box will display in the main window. When you have all the mods you want to combine checked hit Apply and your Mega Mod should be ready to playtest. If you like your Mod save a copy because everything in the target file pathway gets deleted each time you perform a merger.
                              Last edited by Impaler[WrG]; December 2, 2005, 12:06.
                              Companions the creator seeks, not corpses, not herds and believers. Fellow creators, the creator seeks - those who write new values on new tablets. Companions the creator seeks, and fellow harvesters; for everything about him is ripe for the harvest. - Thus spoke Zarathustra, Fredrick Nietzsche

                              Comment

                              Working...
                              X