Author Topic: ForceMoraleX Bug  (Read 1722 times)

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
ForceMoraleX Bug
« on: November 24, 2008, 05:37:09 PM »
I was going through some code so I could update the SDK with some specifics for each call, and I noticed something odd about the ForceMoraleX functions. It seems they're buggy. If you use a parameter of -1 for all players, then you have no troubles. But the code path that handles forcing morale levels for a specific player is buggy.

What it should probably be doing, is clearing the bit of each forced morale level for that player, and then set the bit for the desired level. But what it really does, is flips the bit for each morale level, and then sets the bit for the desired level.

What happens then, is that if you call any of the ForceMoraleX functions, (assuming the initial state of all bits is 0) then all levels have that bit set for that player (and the desired level is set twice). This ends up forcing the morale level to excellent, no matter which function you called. Now, if you call the function again, it will flip all the bits again (setting them all to 0), and then set the bit for the desired level. So if you call it twice, it will work right.

Similarly, if you call two different functions, the first one sets morale level to excellent, and then the second one has the desired effect. However, if you call different functions each time, then things start to get a little hairy after two calls.

FreeMoraleLevel looks like it works fine in all cases.



Of course there is little reason to call ForceMoraleX with a value other than -1, since it'd be unfair in multiplayer, and would have no effect on an AI in single player.
 

Offline Hidiot

  • Hero Member
  • *****
  • Posts: 1018
ForceMoraleX Bug
« Reply #1 on: November 25, 2008, 05:44:42 AM »
It would affect an AI in single player is someone makes the AI respect game rules and play fair.

Interesting bug... I never really noticed it.
"Nothing from nowhere, I'm no one at all"

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
ForceMoraleX Bug
« Reply #2 on: November 25, 2008, 06:43:06 AM »
Well done, Dynamix.  Well done.
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline CK9

  • Administrator
  • Hero Member
  • *****
  • Posts: 6226
    • http://www.outpost2.net/~ck9
ForceMoraleX Bug
« Reply #3 on: December 05, 2008, 11:03:43 AM »
In all fairness, Sierra didn't exactly give Dynamix enough time to go through and find every potential bug, and I doubt they planned for people to be doing their own coding.
CK9 in outpost
Iamck in runescape (yes, I still play...sometimes...)
srentiln in minecraft (I like legos, and I like computer games...it was only a matter of time...) and youtube...
xdarkinsidex on deviantart

yup, I have too many screen names