Quick Modding Questions Thread

All the resources are at iConstApperance 100. It is supposed to be the chance it appears somewhere on the map.

I did have it at 24 but that had the same problem.
 
Are you sure the entry is a percent chance? It could also be a "1 in n" probability, i.e. the higher the value the lower the chance.
 
Default code:

Code:
int CvMapGenerator::calculateNumBonusesToAdd(BonusTypes eBonusType)
{
	CvBonusInfo& pBonusInfo = GC.getBonusInfo(eBonusType);

	// Calculate iBonusCount, the amount of this bonus to be placed:

	int iRand1 = GC.getGameINLINE().getMapRandNum(pBonusInfo.getRandAppearance1(), "calculateNumBonusesToAdd-1");
	int iRand2 = GC.getGameINLINE().getMapRandNum(pBonusInfo.getRandAppearance2(), "calculateNumBonusesToAdd-2");
	int iRand3 = GC.getGameINLINE().getMapRandNum(pBonusInfo.getRandAppearance3(), "calculateNumBonusesToAdd-3");
	int iRand4 = GC.getGameINLINE().getMapRandNum(pBonusInfo.getRandAppearance4(), "calculateNumBonusesToAdd-4");
	int iBaseCount = pBonusInfo.getConstAppearance() + iRand1 + iRand2 + iRand3 + iRand4;

	bool bIgnoreLatitude = GC.getGameINLINE().pythonIsBonusIgnoreLatitudes();

	// Calculate iNumPossible, the number of plots that are eligible to have this bonus:

	int iLandTiles = 0;
	if (pBonusInfo.getTilesPer() > 0)
	{
		int iNumPossible = 0;
		for (int iI = 0; iI < GC.getMapINLINE().numPlotsINLINE(); iI++)
		{
			CvPlot* pPlot = GC.getMapINLINE().plotByIndexINLINE(iI);
			if (pPlot->canHaveBonus(eBonusType, bIgnoreLatitude))
			{
				iNumPossible++;
			}
		}
		iLandTiles += (iNumPossible / pBonusInfo.getTilesPer());
	}

	int iPlayers = (GC.getGameINLINE().countCivPlayersAlive() * pBonusInfo.getPercentPerPlayer()) / 100;
	int iBonusCount = (iBaseCount * (iLandTiles + iPlayers)) / 100;
	iBonusCount = std::max(1, iBonusCount);
	return iBonusCount;
}

The higher the ConstAppearance, the more to be placed.
 
Are you sure the entry is a percent chance? It could also be a "1 in n" probability, i.e. the higher the value the lower the chance.

The Modiki says here which I took to mean appearing on the map at all!

Default code:

Code:
int CvMapGenerator::calculateNumBonusesToAdd(BonusTypes eBonusType)
{
	CvBonusInfo& pBonusInfo = GC.getBonusInfo(eBonusType);

	// Calculate iBonusCount, the amount of this bonus to be placed:

	int iRand1 = GC.getGameINLINE().getMapRandNum(pBonusInfo.getRandAppearance1(), "calculateNumBonusesToAdd-1");
	int iRand2 = GC.getGameINLINE().getMapRandNum(pBonusInfo.getRandAppearance2(), "calculateNumBonusesToAdd-2");
	int iRand3 = GC.getGameINLINE().getMapRandNum(pBonusInfo.getRandAppearance3(), "calculateNumBonusesToAdd-3");
	int iRand4 = GC.getGameINLINE().getMapRandNum(pBonusInfo.getRandAppearance4(), "calculateNumBonusesToAdd-4");
	int iBaseCount = pBonusInfo.getConstAppearance() + iRand1 + iRand2 + iRand3 + iRand4;

	bool bIgnoreLatitude = GC.getGameINLINE().pythonIsBonusIgnoreLatitudes();

	// Calculate iNumPossible, the number of plots that are eligible to have this bonus:

	int iLandTiles = 0;
	if (pBonusInfo.getTilesPer() > 0)
	{
		int iNumPossible = 0;
		for (int iI = 0; iI < GC.getMapINLINE().numPlotsINLINE(); iI++)
		{
			CvPlot* pPlot = GC.getMapINLINE().plotByIndexINLINE(iI);
			if (pPlot->canHaveBonus(eBonusType, bIgnoreLatitude))
			{
				iNumPossible++;
			}
		}
		iLandTiles += (iNumPossible / pBonusInfo.getTilesPer());
	}

	int iPlayers = (GC.getGameINLINE().countCivPlayersAlive() * pBonusInfo.getPercentPerPlayer()) / 100;
	int iBonusCount = (iBaseCount * (iLandTiles + iPlayers)) / 100;
	iBonusCount = std::max(1, iBonusCount);
	return iBonusCount;
}

The higher the ConstAppearance, the more to be placed.

OK, I am using the default code but I still had the same problem when I had the value at 24, so I went back to the Modiki and adjusted all values based on what I read.

Thanks, I'll play around with it some more. They did not know what the Rands did and I left them as the default 25,25,0,0.
 
The code Platyping posted is about calculating the number of the bonuses that appear on the map not the actual code that decides where to place the resources, so I thought that maybe it was the way I was defining the valid terrains for the resource since I had one terrain and a a feature with valid terrains. Splitting them had the effect of giving me the same problem on desert and now on jungles also. Before jungles were working as expected.

It must be something simple, possibly even just a dyslexic style error on my part as every other resource I have added is behaving as expected.
 
In unmodded Civ4, iGroupRange is rather a boolean it seems.

If iGroupRange is 0, iGroupRand is always 0.

If iGroupRange is 1, igroupRand is either 25 or 50. This is the percentage of how likely it is that there is another resource of this placed next to this one.

Your iGroupRange of 3 might screw some calculations.

Spoiler :
Also, it might be an effect of the forum, but both tags should be at the same level than the others. However, I suppose that this doesn't really matter.
 
In unmodded Civ4, iGroupRange is rather a boolean it seems.

If iGroupRange is 0, iGroupRand is always 0.

If iGroupRange is 1, igroupRand is either 25 or 50. This is the percentage of how likely it is that there is another resource of this placed next to this one.

Your iGroupRange of 3 might screw some calculations.

Spoiler :
Also, it might be an effect of the forum, but both tags should be at the same level than the others. However, I suppose that this doesn't really matter.
I tried zero zero but got the same result.

I just got the idea that it may be something to do with the bonus class, so I went through and counted the number of bonuses in each and fixed the bonus class infos file. Now I am getting none on the map at all. so this looks to be more the point. It looks like if the number of the resource is important I should not have them in bonus class general and that the number unique in bonus class general should stay at 0. I think that bonuses in that group may be used to fill in the map.

I am still experimenting.

edit not getting any was because I still had the values down very low.

The problem was that I had the wrong count in the Bonus Class file.

Thanks everyone.
 
I have been trying my hand at SDK modding again and this time I not only managed to successfully compile a DLL, I even implemented a bit of code to my liking. Specifically I want to make culture more useful by making higher culture levels (Refined, Influential and Legendary) provide extra happiness and a bonus to Great People Birth Rate and Trade Route yields, for which I added three new XML tags. Happiness went over without a hitch, but when I tried to do the same with Great People Birth Rate I ran into problems. The mechanic itself seems to be working fine, but I can't seem to find my way around CvGameTextMgr.cpp to get the game to actually describe the bonus ingame. I tested it by starting a game on a tiny map and adding some buildings like Research Institute and Industrial Park, and that is when I ran into this thing here:

attachment.php


After some more investigation I concluded that this error always shows up when I try to enter the city screen of a city which contains a unique building belonging to a different civ, and when I try to hover over such a building once inside.

Commenting out my code for the Great People Birth rate didn't fix the issue, and neither did commenting out the culture happiness code. I have now gone so far as to start from scratch and just compile a pure BtS DLL without any changes whatsoever, and this still happens. It doesn't actually seem to have any effect ingame apart from throwing a bunch of popups at me. Is this just a known bug of unmodded BtS? I use the files provided by Asaf's guide in case it's relevant.
 

Attachments

  • buggy.png
    buggy.png
    365.6 KB · Views: 165
This is strictly speaking not a bug. What you did was compile and run a debug DLL. This tells the game to check assertions in the code, and display a message if an assertion is not met, in your case
Code:
GC.getCivilizationInfo(getCivilizationType()).getCivilizationBuildings(eBuildingClass) == eBuilding
In other words, for a given building it determines the building the controlling civ can build for its building class, and checks if those are equal. That is exactly the situation you figured out yourself.

Obviously this should never happen unless you explicitly mess with the game e.g. with world builder like you did, which is why the programmer put it there to make sure. So this is just a debug safety measure of the original game code and in no way related to any change you made.

When actually playing you don't encounter this because then you aren't using a debug DLL. I don't know if you intentionally compiled a debug DLL (it's certainly useful when trying out new stuff), but for the final product you should select target=RELEASE in your IDE instead. Not only does this prevent assertions from being checked, it also has significantly better performance.
 
When actually playing you don't encounter this because then you aren't using a debug DLL. I don't know if you intentionally compiled a debug DLL (it's certainly useful when trying out new stuff), but for the final product you should select target=RELEASE in your IDE instead. Not only does this prevent assertions from being checked, it also has significantly better performance.

I was using a debug DLL because I was (and still am) in the middle of programming and testing new game features. :p

At any rate it's good to know that it's not my fault.
 
After some more investigation I concluded that this error always shows up when I try to enter the city screen of a city which contains a unique building belonging to a different civ, and when I try to hover over such a building once inside.
That is precisely what it warns about. If you look closer, it checks if the player in question can build the building.
  1. GC.getCivilizationInfo(getCivilizationType())
    The civilization info for the player in question
  2. .getCivilizationBuildings(eBuildingClass)
    The building for that civ when it builds eBuildingClass
  3. == eBuilding
    Compares to the building in the city
If the building you build for the chosen building class and the building present in the city mismatch, then there is a high risk of a bug, hence the assert check. You know that and it seems intended, which mean in this case the assert message can be ignored. If it was unintended, then it would be a good thing the game points out the mismatch.

Generally speaking, the game shouldn't display assert messages unless something went wrong. However not all messages are equally important. Some will tell that the game is about to crash while others like this one allows the game to continue with little or no consequences. I generally try to avoid triggering asserts and may remove/change them if they trigger all the time when it doesn't matter. Something about not to cry wolf and miss the important ones.

As for the target (type of DLL), there are Release and Debug. However if you use Makefile 2, there is a 3rd option, which is Assert. Assert is nearly as optimized as Release and it does all the assert checks, which is good for bug hunting. Debug allows attaching the debugger, but it's much slower (like 10 times slower). If you do not use the debugger, Assert seems the way to go. Release is meant to be as fast as possible and is good for releases where you assume them to be bugfree.
 
I am stumped for the first time in a while, if anyone can help.

I added a civilization, and I have debug DLL in, and game crashed without any error. Long time searching for error, found it was in a text file. By commenting out sections, I got it to not crash. Turns out, all I need is an extra comment (beside the default ones up top) for it not to crash. Currently, the comment has nothing in it.
Code:
<TEXT>
		<Tag>TXT_KEY_CIV_PHOENICIA_PEDIA</Tag>
		<English>[TAB]Phoenicia was an ancient.....</English>
		<French></French>
		<German></German>
		<Italian></Italian>
		<Spanish></Spanish>
	</TEXT>
	<!---->

This is very strange and not something I've seen before. I am concerned because now, when it does not crash, I get one of those debug errors that I have no idea what it means (when it does crash, i dont get these errors before crashing). Anyone ever see anything like this?
 

Attachments

  • alexander.png
    alexander.png
    13.2 KB · Views: 47
The xml reading code can be very picky about comments. Particularly the "reading all elements" code can't handle trailing comments and will crash when it encounters those. This mean your comment is problematic unless it is followed by a <TEXT> block. Also the comment starts as you has written it. I assume you wrote an end to it as well. Not ending the comments would also be a reason for the game to fail reading the file.
 
I've had similar problems before with comments in text files. Now, I always check if I have the same number of 'starting comments'
Code:
<!--
and 'ending comments'
Code:
 -->
From experience, it counts (if I may say so :) ).
 
I dont have any other comments though. I dont really use comments, and I havent added any in any of my files to my memory. I got rid of the debug error, however I still need this comment.
Code:
</TEXT>
	<TEXT>
		<Tag>TXT_KEY_CIV_PHOENICIA_ADJECTIVE</Tag>
		<English>Phoenician</English>
		<French>Phoenician</French>
		<German>Phoenician</German>
		<Italian>Phoenician</Italian>
		<Spanish>Phoenician</Spanish>
	</TEXT>
	<!-- My Comment-->
	<TEXT>
		<Tag>TXT_KEY_CIV_PHOENICIA_PEDIA</Tag>
		<English>:) :) :) :):) :) :) :):) :) :) :):) :) :) :):) :) :) :)Phoenicia was....</English>
		<French></French>
		<German></German>
		<Italian></Italian>
		<Spanish></Spanish>
	</TEXT>
There are no errors in my mod (that I have found). But if I remove that one comment, my game crashes. All of these texts show up as they should in the game. It is the only comment I have added. This really mind boggles me. Here is the text file, I don't see anything at all wrong with this file.

Realistically there isnt a problem right now, but the fact that without this comment in my text file it will crash, makes me uneasy that there will be problems in the future.
 

Attachments

But if I remove that one comment, my game crashes.
Somehow that sounds wrong on so many levels. I figured you added some invisible character, which screws up everything, but looking with a hex editor, all the characters in that area are as they should be. Quite strange.

Are you absolutely sure it crashes without this comment? It's not that I don't believe you have this problem. It's more like it makes absolutely no sense whatsoever. I have spent a great deal of time modding xml reading, including what would be the offending code in this case and it just doesn't make any sense to me. I can't think of any reason why it should behave like that.

If you really think you have this problem, then I would like your entire mod. If you really managed to somehow make a mod, which crashes vanilla code due to an unknown limitation/bug, then all mods could be at risk. We better figure out what goes on here and having the full mod and using the debugger seems to be the best way to investigate this issue.
 
I've truly ran it over 10 times, it crashes every time without that comment, and loads fine....I just tried it again, I've been on the mod last 30 minutes and its been fine, just removed comment and it crashed while reloading mod. I'm not by any means an xml expert but ive been modding for years and like I said, I've never been this stumped.

Just uploaded it for you
http://www.gamefront.com/files/25604652/TTT+-+The+Test+of+Time.rar

Here is a link to everything I've added...its not much, just a bunch of civs, leaders, civics and buildings. The file is in assets/xml/text/test_civilizations

The file has no comment in it currently. The state as is crashes on my system. If it crashes for you, try adding a comment in that file (ive really only had the comment toward the bottom, not sure if where the comment is matters).
 
I've tested the file in a very small mod. I copied your file into the text folder and deleted the "My comment". The game crashed when loading the xml.

In the file, I noticed that the English entry of the tag "TXT_KEY_CIV_GENOA_PEDIA" (line 1058) was actually occupying two lines. Fixing this and the game loads fine (without of course adding back the "My comment").

PS: needless to say that I have no idea why adding "My comment" in the first place could have helped the loading of this file!
 
While I have successfully implemented a bonus to Great People Birth Rate from culture levels, I can't seem to be able to find my way around CvGameTextMgr.cpp to make the game tell the player about it.

I have added this bit of code

Code:
int iCultureMod = city.getCultureGreatPeopleRateModifier();

		szBuffer.append(gDLL->getText("TXT_KEY_GREAT_PEOPLE_CULTURE", iCultureMod));
		szBuffer.append(NEWLINE);
		iModifier += iCultureMod;

in void CvGameTextMgr::parseGreatPeopleHelp(CvWStringBuffer &szBuffer, CvCity& city), between the part for buildings and the one for civics, and when compiling I always get this error:

1>CvGameTextMgr.obj : error LNK2019: unresolved external symbol "public: int __thiscall CvCity::getCultureGreatPeopleRateModifier(void)const " (?getCultureGreatPeopleRateModifier@CvCity@@QBEHXZ) referenced in function "public: void __thiscall CvGameTextMgr::parseGreatPeopleHelp(class CvWStringBuffer &,class CvCity &)" (?parseGreatPeopleHelp@CvGameTextMgr@@QAEXAAVCvWStringBuffer@@AAVCvCity@@@Z)
1>Debug\CvGameCoreDLL.dll : fatal error LNK1120: 1 unresolved externals

What am I missing?
 
CvCity.h has
PHP:
int getCultureGreatPeopleRateModifier() const;
This mean you can write it in the file and it compiles. However when linking all the files, it needs to link to CvCity:: CvCity::getCultureGreatPeopleRateModifier() const, which you didn't write. This mean your problem is in CvCity.cpp and not the file complaining about the issue.

In the file, I noticed that the English entry of the tag "TXT_KEY_CIV_GENOA_PEDIA" (line 1058) was actually occupying two lines. Fixing this and the game loads fine (without of course adding back the "My comment").

PS: needless to say that I have no idea why adding "My comment" in the first place could have helped the loading of this file!
I really need to debug this. It makes absolutely no sense to me, though it's good that you figured out how to avoid the crash.
 
Back
Top Bottom