PhantomGamesDevelopment / TWM2

Total Warfare Mod 2 for Tribes 2
0 stars 0 forks source link

EXP Gain Issue #16

Closed Phantom139 closed 7 years ago

Phantom139 commented 7 years ago

When issuing large quantities of EXP >1,000,000 the accumulator will bug out and not issue the correct amount of millions of EXP, leaving the player with a lower amount than expected.

In one extreme case, this overloaded the millionXP field and reset them back to zero. This will need to be analyzed and fixed accordingly.

Ragora commented 7 years ago

You'd need to reduce the scale of XP in use which also helps slow down the eventual issue with it returning scientific notation strings eventually. All operations (or most) assume a float even if both operands appear to be an integer (this happens a lot with the engine internally using stuff like atof a lot).

Alternatively you'd need to use proper integer-wise operations which don't really exist in the base engine - you'd pretty much need to use a modloader DLL to implement IntAdd and such explicitly.

If it's not an issue with the end total but rather how it got there you can perhaps try doing the additions in separate chunks:

%total = 900000;
%chunk = 50000;

%remainder = %total % %chunk;
%whole = mFloor(%total / %chunk);

// Step it up
for (%iteration = 0; %iteration < %whole; %iteration++)
   %newTotal += %chunk;

// If this can be large enough as well then this function should be recursive.
%newTotal += remainder;

At the least, you can add a bug check (with considerations for floating point drift):

%old = %current;
%current += %amount;
%delta = %current - %old;
if (%delta != %amount)
   error ("arithmetic error");

Compare floats:

%distance = mAbs(%comparison - %current);
if (%current)
    %distance /= %current;
%result = %distance <= %thresholdPercentMax && %distance  >= %thresholdPercentMin;
Phantom139 commented 7 years ago

I actually figured out what's going on here and will deploy a fix in the next commit, it was something silly that I never really considered so I'll just let that go. :)

Phantom139 commented 7 years ago

Fixed 141e94ef.