Modmodding Q&A Thread

So here's my first draft, this is at the end of CvPlot::doTurn:

Code:
	if (GET_PLAYER(getOwnerInline()).getCivilizationType() == RUSSIA){
		//need to loop through units, below is idea??
		for (int i = 0; i < getNumUnits(); i++){ //goes through units in tile
			CvUnit u = getUnitByIndex(i);
			if (u.getTeam().isAtWar(getOwnerInline()){
				u.setDamage(-5, u.getOwner()); //deals 5%?
			}
		}
	}

Also, where would I change what worker improvements are enabled? One unique power I'm trying to make is one that enables all Ancient Era improvements from the start of the game.
 
For the code: the RUSSIA etc. variables refer to the player IDs, not the civilization types, so you have to check getOwner() == RUSSIA. The unit loop should work, but a team can only be at war with another team, so it's better to do GET_PLAYER(getOwner()).getTeam(). I also think 0 damage means full health, so to damage a unit you have to add positive damage (is there a changeDamage() function? Otherwise each turn will set the damage to the same value).

Improvements are related to the "build" verb, so either CvUnit::canBuild() or CvPlot::canBuild().
 
Have you ever used Eclipse for C++, particularly in Civ4? I'm using it for school (currently having trouble getting it to build properly) but I'm wondering if it's better than Microsoft Visual Studio 2008 (the program that's recommended on the CFC tutorial) for compiling the DLL.
 
I've only ever used Eclipse for Java, but if it has the same level of functionality for C++ it's definitely preferable to Visual Studio. But I've never tried getting it to work.
 
Now this might only be tangentially related to a mysterious problem I ran into in my modmod, but has the infamous Overflow error ever been resolved, and if yes what was its cause?

Edit: A bit more directly related to my mysterious problem: Is there anything special coded with regards to Jerusalem building its first unit? Whenever Independent Jerusalem in 3000BC completes its first Warrior in my modmod the game crashes with no explanation. If I go into worldbuilder to give them less production so it finishes later the crash doesn't happen, but I get an overflow error on Jerusalem's coordinates every round thereafter.

I get a similar crash in the 1700AD scenario around 1765. However if I pick France, or the Netherlands, or America, or even Argentina all the way in the 1800s for autoplay in 600 AD it works without a hitch. These crashes aren't random, they are absolutely consistent. Something happens between the 4th and 5th turn in the 3000BC scenario and in 1765 in the 1700AD scenario respectively every single time unless I mess around with the Worldbuilder, and this something never happens (or at least not before the 1800s) in the 600AD scenario. The game doesn't even give me a reason, it's just "Civ4.exe has stopped working" or something like that.

This seems to have nothing to do with my changes in the DLL, as replacing my DLL with the stock DoC one doesn't affect this at all, so I'm guessing it's Python related? But nothing is scripted in the fifth turn in 3000BC, and why would Jerusalem completing a unit be the cause of such a crash? And why does the exact same crash occur in 1765 in the 1700AD scenario, but never in 600AD?

I am very confused about this enigma.

Another edit: Temporarily letting Jerusalem build a worker for one turn before switching production back to a warrior via Worldbuilder sidesteps the whole issue. No crash happens upon the warrior being completed, and no overflow errors appear either. This crash seems to be caused solely by Jerusalem completing a Warrior on Turn 4, no sooner, no later.
 
Last edited:
No it hasn't been fixed.

Could you share the save that reproduces the overflow bug?
 
No it hasn't been fixed.

Could you share the save that reproduces the overflow bug?

I could theoretically, but it won't do you any good as it happened in my local working copy of my modmod. What I did was in the 3.000BC scenario going into worldbuilder in the third or fourth turn (just after Jerusalem spawned and invested a turn or two of production into a warrior) and just decreasing the base production of Jerusalem and/or decreasing the amount of production it had invested in a Warrior, one of these things or both triggered the overflow error. I haven't even tested if this would also happen in DoC.
 
:/
 
Is there an easy way of reverting to a specific commit with Github? For some reason the 1700AD scenario in my modmod is broken, and I don't know since when or why. I tried reverting all changes of the last months that could have reasonably caused this, but to no success. What I would like to do now is systematically and completely revert every commit I made in reverse chronological order (from newest to oldest) until I find the version where the scenario last worked. All ways I found via Google were either witchcraft or didn't match up with anything I could see. I did figure out a way to download a zipped version of my modmod for any given commit, but it seems horribly inefficient to do this systematically, to the point that I might as well just manually edit every single file.
 
Yes, you can go back n commits with git reset HEAD~n. After that, your local changes are still there, but uncommitted. To revert these changes, run git checkout . (With the period). Doing this changes your history, so if you want to successfully push you need to do git push --force origin <branch name>.

I only know the command line instructions for this, you can open a Git shell where this is possible using e.g. the Github Desktop application and right clicking on your repo -> open Git shell.
 
Yes, you can go back n commits with git reset HEAD~n. After that, your local changes are still there, but uncommitted. To revert these changes, run git checkout . (With the period). Doing this changes your history, so if you want to successfully push you need to do git push --force origin <branch name>.

I only know the command line instructions for this, you can open a Git shell where this is possible using e.g. the Github Desktop application and right clicking on your repo -> open Git shell.

So I did that, quite a few times actually, but it's strange: When checking in the Windows Explorer everything seems to working like it's supposed to. With every git reset HEAD~n command I enter, the appropriate files are now showing a little red exclamation mark instead of the green tick mark, which signifies that they differ from the official canon version I have on Github. It's always exactly the right files, I was comparing them with my Commits on Github, so everything seems to be working like it should. However after half a dozen attempts of unsuccessfully trying to start the 1700AD scenario with no change I got suspicious, and decided to check in the Civilopedia if I really am on a past version now, and found that the game was still behaving exactly as if it was on the most current version, that is no Marine unit exists, Persia starts with Serfdom, lots of first strikes all around etc., all relatively recent changes. I tried different ways of clearing the cache and even restarted my PC, but to no effect. So I decided to actually check the supposedly (according to both the Shell and the little red exclamation marks in the explorer) reverted files, and fount that they weren't any different from the current up to date version. Not one bit. No trace of a Marine unit in UnitInfos.xml even though it still existed a month ago, and I'm now supposedly on a commit from September. This git reset HEAD commit doesn't seem to actually change any files locally, it just assumes (falsely) that the canon version on Github has reverted to a given commit and shows tick and exclamation marks according to this virtual version rather than the actual one, because all the files are still identical to the current up to date version on Github even if they claim they aren't. Pulling had zero effects.

Am I supposed to commit now, even though no actual content of any files was changed? As far as I'm concerned my version on Github never needs to learn of any reverting whatsoever, I want to do this purely on my local computer until I identify the change that broke the 1700AD scenario.

Thanks for your help, I'm sorry to be a bother. :)
 
I think you haven't actually done the second step?

1) git reset HEAD~n
2) git checkout .

The first steps only undoes the last n commits, but does not change your files to revert the changes on these commits. That means those changes are still there, but uncommitted. Your Git client shows them as red because it recognizes that your local repo differs from the online repo in that the commits affecting those files are missing. The second step (git checkout <path>) basically tells git to discard all uncommitted changes, in this case the entire folder (period symbol). Together those commands will completely undo your last n changes.
 
Ooooooh, I thought git reset HEAD~n reverted to a commit, and git checkout returned those changes back to the way they currently are.

Edit: Issue has been resolved, thank you for your help.
 
Last edited:
Great. Remember, you need to do your next push as git push --force origin <branch name>, because you have just rewritten your history.
 
Great. Remember, you need to do your next push as git push --force origin <branch name>, because you have just rewritten your history.
I just reverted all changes, then pulled, then manually fixed the one broken thing, then pushed. I even made a second unrelated commit a few hours later. Should I not have done that? Everything seems fine on the Commits page.
 
If that worked, then fine. I think it depends on how much you deviate from the online state.
 
Merry new solar circulation!

I am under the impression that different AIs have different research priorities, yes? Where would I change those? In my modmod AIs seem to have a crazy hard on for Radio and Astronomy while completely ignoring Gunpowder and Steel, which leads to interesting but ahistorical developments.

Also is there something similar for AI priorities with regards to civics apart from their one favorite?
 
You could play around with flavors. I am unsure if RFC has a special mechanic for it, though.

Also, absolutely astounding annual anniversary.
 
There are no special AI civic preferences.

For the tech preferences, they are hardcoded into CvPlayerAI::AI_bestTech(), although I have recently thought about exposing that to Python.
 
Back
Top Bottom