merging very large units
I am running a couple of games of 4.0.10 atlantis.
I have discovered a problem when merging very large units. If a player tries to merge a unit with 4500 men at comb-5(450) with one that has 9700 men at comb-5(450), it does not merge them correctly at all.
It appears to be because days is an int rather than a long for skill.
I think I have seen this on the list, but cannot find out whether anyone has fixed it or not...
Any help in pointing me in the right direction would be appreciated.
- Hi Enno,
----- Original Message -----
From: "Enno Rehling" <enno.rehling@...>
Sent: Monday, July 04, 2005 1:14 PM
Subject: Re: [atlantisdev] merging very large units
> RadK wrote:
>> I also remember a similar problem a long time ago and can't remember
>> its resolution, but I don't see how it can be due to the numbers being
>> stored as ints.
> My guess, without looking at the code:
> The total number of days is stored with the unit. say we have a unit of
> 10,000 men and 500 days each (I'll use easier numbers), then we store
> 5,000,000 skill days with the unit. Now we add 5000 more men to the unit
I didn't see the storing of the 5,000,000. I will look at this.
> - what is the resulting skill? It is 5,000,000 / 10,000 * 15,000.
> However dividing integers is prone to rounding errors, so we get a
> better numerical result if we multiply first, divide later: 5,000,000 *
> 15,000 / 10,000. And that's where the faekal matter hits the rotating
> blades, because 5,000,000 * 15,000 = 75,000,000,000, and *that* doesn't
> fit in an int.
This is exactly how the code is written. It does the multiplication first and then divides.
> This is all guesswork - I have never read the atlantis code - based
> solely on way too much experience with code that breaks in interesting
> ways. Someone with access to the code should check whether I'm right.
I have access to the code, and if it does store the 5,000,000 then it in fact is an int problem.
> There may be fairies at the bottom of the garden. There is no evidence
> for it, but you can't prove that there aren't any, so shouldn't we be
> agnostic with respect to fairies?
> - Richard Dawkins
> To Post a message, send it to: atlantisdev@...
> To Unsubscribe, send a blank message to: atlantisdev-unsubscribe@...
> Yahoo! Groups Links
- Hi Enno,
You are in fact right. The game.in file does store 8550000 for 19000 leaders at comb-5.
So the multiplication does go well beyond an int.
I will change the code to store an unsigned long, and see if that works. This is a bigger change than what I wanted to do, but my game has been running for over two years, and I don't want the game.in file to stop the game.
- RadK wrote:
> Hi Enno,no, simply use a double for the multiplication. you never need to store
> You are in fact right. The game.in file does store 8550000 for 19000 leaders at comb-5.
> So the multiplication does go well beyond an int.
> I will change the code to store an unsigned long, and see if that works. This is a bigger change than what I wanted to do, but my game has been running for over two years, and I don't want the game.in file to stop the game.
something that's bigger than 32 bit (and you won't get 32 bit variables
in many cases), your problem is only during the multiplication. Do this:
newskill = (int)((oldskill * (double)newmen) / oldmen);
That should do it. There's even a slightly nicer way, but I leave that
as an excercise to the reader ;-)
A: Because it disturbs the logical flow of a message.
Q: Why is top posting a sloppy form of writing?