What is the value limit of integer XML entries?

sleepground123

Chieftain
Joined
Nov 28, 2020
Messages
46
I'm not sure, but I assume that values up to 50 million are possible, because the last tech in Caveman2Cosmos costs about that. But what is the absolute limit? I bet on 2,147,483,647. Do you know what is the exact limit?
 
The XML does not control the limits, it is essentially a text file with some additional structure that is then parsed by the DLL. So the answer to your question depends on the particular code that parses the entry in question, and the type of the variable the value is stored in.

Afaik most values are stored as signed int, which (I think always on Windows) is 32 bit = 2147483646 to 2147483647. You can easily store the value in a long long instead, which gives you bounds of -9223372036854775806 to 9223372036854775807. If more is needed, you can use unsigned types because often negative values are not possible anyway. But again, I would go in with the expectation that most values are parsed and stored as signed int and you cannot go over 2147483647 unless you make sure the DLL is actually ready to handle larger values.
 
That's going to be the theoretical top limit, yes. CIV4 is a 32 bit program written in C++ and thus the integer definition is going to be +/- 2 to the 32nd power.

But theoretical does not have to mean practical. There are plenty of reasons why the devs might have choose to restrict certain variables in their code to cut off values above what they considered reasonable.

For example you can't compile the DLL to allow more than IIRC 200 civs on the same map.
 
There are cases where the game is restricted to 16 bit as well. I can't remember what precisely, but I recall something about the number of entries in one or more files running into issues if there are more than what a signed 16 bit int can handle. However odds are that you will run into other issues like adding more unittypes with graphics will likely make you run out of memory prior to reaching 32k.

I never bothered much with the limits in xml values because honestly all the known limits are so high that they shouldn't be an issue. The place where you need to be fully aware of such limits is network communication. If you need to send 3 ints, but the vanilla package system only allows you to send 2, then you need to merge two 16 bit ints into one 32 bit int or even fewer bits for each int if you need more than 2. This is however fairly advanced stuff, which only applies to DLL modders and even then most DLL modders will never need it. The only reason I mention it here is because it's the only place I can think of where modders can encounter harsh limits.
 
Back
Top Bottom