Modmodding Q&A Thread

CvPlayer::isHasBuildingEffect() is there precisely for this kind of wonder effect, it checks if the player has at least one building of the specified type and also checks if they already have the obsoletion tech (and returns false in that case).
 
CvPlayer::isHasBuildingEffect() is there precisely for this kind of wonder effect, it checks if the player has at least one building of the specified type and also checks if they already have the obsoletion tech (and returns false in that case).
I was hoping I could avoid having to iterate through that many cities, but seeing as how other wonders use it, I guess I will too.

Also, I'm getting a C++ exception on team.changeResearchProgress(gc.getPlayer(iPlayer).getCurrentResearch(), culture, iPlayer)
 
Linear iteration is cheap in C++, I wouldn't worry about it. I suggest using a debug DLL to find out more about the C++ exception.
 
When I try using a debug DLL, I get the following error:
Code:
File:  .\.\CvGlobals.cpp
Line:  3354
Expression:  strcmp(szType, "NONE")==0 || strcmp(szType, "")==0
Message:  type FLAVOR_CIVICS not found
 
That might be a legitimate assertion failing in the base mod, I haven't thoroughly run it through the debug DLL to correct all of them yet.
 
That might be a legitimate assertion failing in the base mod, I haven't thoroughly run it through the debug DLL to correct all of them yet.
Guess it's time to set up 100 log statements and see where the trail stops then... Great.
 
No you don't! That's exactly what the debug DLL is for. Whenever you launch the game with a debug DLL, you can just (preferably during the new "attaching debug DLL" popup) go into Visual Studio and do Debug -> Attach to Process ... and then select the civ4beyondsword.exe process. When you run into a failed assertion (or crash) you can use the debug option and get a nice Java style stacktrace in VS.
 
Thanks. This is really useful.

EDIT:
I made 2 small modifications. The first is a popup, in which you can type the number of the new civ. (So you don't have to open the script to edit it)
The second an undo-action, which will undo the whole script when Ctrl-Z is pressed.

Code:
from Npp import *
import re

start = int(notepad.prompt(notepad, 'Number of the new civ', "")) - 1
end = 54

editor.beginUndoAction()
for i in range(start, end):
    ii = end + start - i
    editor.rereplace(r"(Owner=|Reveal=|Player|,|Team=|TeamID=)" + "(" + str(ii) + ")([^1234567890])", r"($1)" + str(ii+1) + "($3)")
editor.endUndoAction()
I wonder if there is a good way not to hard code the overall number of players into the script.
 
Yeah, but preferably I don't want to have to know this number.
 
Context? Python print goes to PythonDbg.log by default. Printing of errors is controlled by a config setting that may reset under some circumstances.
 
Context? Python print goes to PythonDbg.log by default. Printing of errors is controlled by a config setting that may reset under some circumstances.
That might be why. The game suddenly swapped to fullscreen mode a couple hours ago.
 
How do I go about using a CvPlayer function in Python? gc.getPlayer(iPlayer) returns CyPlayer, and I can't find a way to bridge the gap
 
You add the function to CyPlayer in C++ and then expose it through CyPlayerInterface.
 
On the turn that a civ in CMC spawns in the capital in CMC, the capital only controls the tile the city is on, how can I fix this?
 
In case anyone's interested, I've noticed that sometimes things like the Settlermap becomes distorted and stops looking like an actual grid. This is because there are tabs in front of some 3 digit numbers, which messes with the spacing. You can use the following Regex to fix it.
Code:
Find what: \t([0,1,2,3,4,5,6,7,8,9][0,1,2,3,4,5,6,7,8,9][0,1,2,3,4,5,6,7,8,9],)
Replace with: ($1)
This removes any tabs that are before 3 digit numbers.

EDIT:

Also this, apparently single digit numbers also cause issues
Code:
Find what: (\t[0,1,2,3,4,5,6,7,8,9]),
Replace with: ($1) ,

EDIT2: Before anyone alerts me to the in game settler/war map editor: I do know about it, but I prefer editing using Notepad++.

EDIT3: If anyone's having trouble figuring out where something is, use the mark command. I prefer to highlight the ocean using:
Code:
\t20,
Do note that this takes about 5 seconds to process and highlight on my relatively-horsehocky laptop.
 
Last edited:
I updated the scenarioUpdate script. It now also updates the Attitudes between civs. (Only used in the 1700 AD scenario.)

Code:
from Npp import *
import re

start = int(notepad.prompt(notepad, 'Number of the new civ', "")) - 1
end = 54

editor.beginUndoAction()
for i in range(start, end):
    ii = end + start - i
    editor.rereplace(r"(Owner=|Reveal=|Player|,|Team=|TeamID=|AttitudePlayer=)" + "(" + str(ii) + ")([^1234567890])", r"($1)" + str(ii+1) + "($3)")
editor.endUndoAction()
 
I think this is answered but I can't find it: How to log in python?
 
Top Bottom