Maximum value of a Unit ID and City ID?

Someone else might correct me, but I don't think there's any specific limitation, so the limit would be the maximum size of the array used to store the units or cities divided by the size of CvUnit or CvCity. The maximum size limit should be the system's largest integer.
 
So we're possibly looking at UnitIDs going as high as 2,147,483,647? Don't think I've ever seen one higher than 7 digits personally (and, if it is 7 digits, starting with anything other than 1). But if it can theoretically get that high, the project might be shot.
 
so the limit would be the maximum size of the array used to store the units or cities divided by the size of CvUnit or CvCity

CvCity and CvUnit are classes, so instances of those classes are allocated directly on the heap and not within an "array"

The maximum size limit should be the system's largest integer.

m_mID for both CvCity and CvUnit are "int" which in C++ is a 4 byte signed value, so in theory the ID can be any value between –2,147,483,648 and 2,147,483,647 inclusive

Edit: Not sure why you want to store the ID as a string, but for info, the ID rolls over from 7 digits to 8 digits after 1220 units for a player have been created. I strongly suspect that your game died a long time before that!

Edit2: Roll over from 8 to 9 digits occurs at 12205 units
 
CvCity and CvUnit are classes, so instances of those classes are allocated directly on the heap and not within an "array"

Fair point. In this case it's not a regular "array" but a class called FFreeListTrashArray which uses a "node" struct which has an int for the index and a pointer to the data. I'm a little foggy on C++ memory allocation (obviously), but wouldn't that struct take up 8 bytes on the stack? I don't think it matters either way, though, and the number of FFreeListArrayNodes the class could have wouldn't be specifically limited.
 
Edit: Not sure why you want to store the ID as a string, but for info, the ID rolls over from 7 digits to 8 digits after 1220 units for a player have been created. I strongly suspect that your game died a long time before that!

Edit2: Roll over from 8 to 9 digits occurs at 12205 units


I see, so though a UnitID can get to the maximum value of an int, it will only start doing so in extreme circumstances. Allocating 8 digits for it should suffice for nearly all cases, then. Thanks!
 
Back
Top Bottom