Quick Modding Questions Thread

Hey does anyone know a way to auto refresh the Sevopedia after editing python files, without restarting Civ4?
 
Hi,
Where is the code that the AI used when selecting the path a unit will follow when going from one plot to another defined?
 
Hey does anyone know a way to auto refresh the Sevopedia after editing python files, without restarting Civ4?
I do not think that is possible. As far as I am aware CIV loads all of its assets, python included when loading the game. And changing them does not take effect until you restart. That is my understanding at least.
 
I do not think that is possible. As far as I am aware CIV loads all of its assets, python included when loading the game. And changing them does not take effect until you restart. That is my understanding at least.

😲

I find it hard to believe that people created these massive mods like BUG and Sevopedia..etc by restarting the game every single time they changed a line of code, there has to be a way to reload GUI's in the game. 😓
 
All(?) Python modules should automatically get reloaded when a change to script file is saved. Probably only once a game has been started or loaded, not from the opening menu. This recent thread has some more details.

@LPlate2: The A* algorithm is implemented in the EXE in a class named FAStar (re-implemented in the DLL by K-Mod and some other mods). The BtS implementation is customizable through global functions defined in CvGameCoreUtils.h, under a comment that says "FAStarFunc...". Pointers to those functions are passed to FAStar in CvMap::setup.
 
sadly just tons of errors show up when editing anything in python for the sevopedia likely because other things depend on it, doing the shift+f8 from that thread reloads the game with the entire HUD missing and no hotkeys working.
 

Attachments

  • screenshot.png
    screenshot.png
    1.5 MB · Views: 22
Has anyone seen this too many values to unpack python exception before? I've made no python or SDK changes to XML must be affecting the python. Exception occurs whenver any unit moves. It doesn't seem to have any consequences that I have noticed but can't be a good sign.
Screenshot 2023-03-05 145958.png

Line 164 handleEvent in CvEventManage looks like this:
Code:
def handleEvent(self, argsList):
        'EventMgr entry point'
        # extract the last 6 args in the list, the first arg has already been consumed
        self.origArgsList = argsList    # point to original
        tag = argsList[0]                # event type string
        idx = len(argsList)-6
        bDummy = false
        self.bDbg, bDummy, self.bAlt, self.bCtrl, self.bShift, self.bAllowCheats = argsList[idx:]
        ret = 0
        if self.EventHandlerMap.has_key(tag):
            fxn = self.EventHandlerMap[tag]
        [LINE 164]    ret = fxn(argsList[1:idx]) [LINE 164]
        return ret
Line 454 in onUnitMove looks like this:
Code:
    def onUnitMove(self, argsList):
        'unit move'
[LINE 454]pPlot,pUnit = argsList [LINE 454]
        player = PyPlayer(pUnit.getOwner())
        unitInfo = PyInfo.UnitInfo(pUnit.getUnitType())
        if (not self.__LOG_MOVEMENT):
            return
        if player and unitInfo:
            CvUtil.pyPrint('Player %d Civilization %s unit %s is moving to %d, %d'
                %(player.getID(), player.getCivilizationName(), unitInfo.getDescription(),
                pUnit.getX(), pUnit.getY()))

I thought that it might be an issue with map size, but I get the error no matter what size of map I play.
 
@Set: The CvEventManager.py from BtS says
pPlot,pUnit,pOldPlot = argsList
in onUnitMove. The base game and Warlords versions match the code that you've posted:
pPlot,pUnit = argsList
Maybe your mod uses a copy of an outdated version of CvEventManager.
 
  • Like
Reactions: Set
As f1rpo says, this will have nothing to do with map size, but with that this function is somewhere called with a wrong amount of arguments.
 
  • Like
Reactions: Set
@Set: The CvEventManager.py from BtS says
pPlot,pUnit,pOldPlot = argsList
in onUnitMove. The base game and Warlords versions match the code that you've posted:
pPlot,pUnit = argsList
Maybe your mod uses a copy of an outdated version of CvEventManager.
Yes this is the problem. I must have copied over the wrong version at some point. Using the BTS version of CvEventManager fixed the issue. I appreciate the help :)
 
sadly just tons of errors show up when editing anything in python for the sevopedia likely because other things depend on it, doing the shift+f8 from that thread reloads the game with the entire HUD missing and no hotkeys working.
The issue is not that python isn't reloaded. The issue is that it is reloaded without running init while reloading means ditching all the variables. Your errors are caused by lack of variable data. I'm not sure if there is a way to fix that issue.

On a semi related note, the same is true for all python screens. Editing advisors while they are open breaks them. Close them, edit and then reopening works. The issue is that you do not reopen (hence run init again) the main interface.

I once had an issue where the game didn't detect changed python files, hence didn't reload. I never fully figured out why, but moving to a new computer fixed it and I haven't heard of anybody else with the same issue. I suspect the culprit was a virtual machine with a shared folder/drive messing up detection of file modification, but I'm not completely sure.
 
Is there a non DLL way to make a certain improvement non stackable. Like how you can only build watermills on one but not both sides of a river. Only without the river.
 
Is there a non DLL way to make a certain improvement non stackable. Like how you can only build watermills on one but not both sides of a river. Only without the river.
If you mean making improvements not-buildable next to each other under certain conditions, it can be done in python. CvGameUtils is your friend. I believe canBuild is the relevant method. iBuild refers to the build action you wish to effect in Civ4BuildInfos. Just stick your condition under there. You might need to edit the XML file PythonCallbackDefines to enable the canBuild callback.

Haven't tested this but code could look something like this:

Spoiler :

Code:
    def canBuild(self,argsList):
        iX, iY, iBuild, iPlayer = argsList
        # Returning -1 means ignore; 0 means Build cannot be performed; 1 or greater means it can
        if iBuild == gc.getInfoTypeForString("BUILD_WORKSHOP"):
            lXCoordinates = range(iX - 1, iX + 2)
            lYCoordinates = range(iY - 1, iY + 2)        
            for nX in lXCoordinates:
                for nY in lYCoordinates:
                    cyPlot = cyMap.plot(nX, nY)
                    if cyPlot.getImprovementType() == gc.getInfoTypeForString("IMPROVEMENT_WORKSHOP"):
                        return 0
        return 1
 
Last edited:
Thanks. I'll try it out soon.

Basically I want to figure out how to curb railroad spam.
 
  • Like
Reactions: Set
Should work the same but you'll need to use getRouteType instead of getImprovementType (and change the XML tags of course).
 
The issue is not that python isn't reloaded. The issue is that it is reloaded without running init while reloading means ditching all the variables. Your errors are caused by lack of variable data. I'm not sure if there is a way to fix that issue.

On a semi related note, the same is true for all python screens. Editing advisors while they are open breaks them. Close them, edit and then reopening works. The issue is that you do not reopen (hence run init again) the main interface.

I once had an issue where the game didn't detect changed python files, hence didn't reload. I never fully figured out why, but moving to a new computer fixed it and I haven't heard of anybody else with the same issue. I suspect the culprit was a virtual machine with a shared folder/drive messing up detection of file modification, but I'm not completely sure.

I see thanks unfortunately even with that info I'm unsure how to begin to find a workaround for it and I've been using python for a long time lol.
 
This post has inspired me to build my own Tech Tree Design tool. If I get it ironed out, I will post it to the Resources.
Do that.

I tried making one but couldn't finish it because it turns out I have bitten off far too many projects to chew.
 
This post has inspired me to build my own Tech Tree Design tool. If I get it ironed out, I will post it to the Resources.
If I may make a feature request one thing that I really wanted out of an editor was the ability to load the original CIV4 XML with techs in parallel with a blank file and than copy techs into the blank file and rename them.
Creating tech after tech is just so much boring busywork and being able to just edit where needed is great.But doing so on a blank file is much better because you don't have to mess with a file full of existing techs and having intermediate states where half the techs are yours and half aren't.
 
Last edited:
Back
Top Bottom