Are you, in fact, a pregnant lady who lives in the apartment next door to Superdeath's parents? - Commodore

Create an account  

 
BUG: Enemy wizard cannot defend in his fortress

Bug description
When you attack an enemy wizard at its fortress, he is not defending himself effectively.
He skips turns before casting spells and in Insecticide, after winning your mana becomes negative, and the wizard is automatically defeated.

Versions
In vanilla 1.31 the enemy is merely ineffective, not casting direct damage spells when he could.
In insecticide 1.40n the enemy tries but fails to deliver damage, causes your mana to become negative, and is automatically permanently defeated.

Confirmation
Aureustgo first reported the bug in a thread starting at this post.
I confirmed the bug in that thread.
Jtm also confirmed in this post.

Save game & Reproduction
Aureustgo uploaded a save game here.
Scenario: "defeated" Tlaloc even though I think he had lots of mana left.
After the battle I have -14147 mana. Negative. In battles I can't cast spells - told I have no mana left. I then convert 400 gold to 400 mana. I then end up with 30000 mana.


Test results

In Insecticide 1.40n, Tlaloc's mana jumped to -32768 exactly, after which he did not do anything anymore.
With the tweaker I set his mana back to 30000, after which he recoved and was not defeated but only banished!
Each time Tlaloc casts a spell (ice bolt, disenchant area), his mana goes up instead of down...
That is, until he goes over 32767.
Then it flips and remains constant at -32768.

In vanilla 1.31, it turns out that Tlaloc does not cast any spells.
At the end he still has 30000 mana, and he is only banished.

It happens when:
1. you fight an enemy wizard at his fortress (50% discount),
2. the enemy wizard has more than 16384 mana,
3. the enemy chooses to cast a chargeable spell,
4. the spell seems to do nothing, enemy's mana increases (until it overflows), and his remaining casting skill also increases.


Code analysis
I found an overflow, causing the computer to make the wrong decision how to pump.
Computer is willing to spend all enemy's mana, instead of only the maximum allowed for the spell.
Location ovr112:0451 (or wizards.exe:835d1) contains "3B D0", where the computer does "cmp dx, ax" while dx (2 times enemy's mana) is greater than 32768.
Furthermore, ovr112:0453 (or wizards.exe:835d3) contains 7Dh, which means "jge", which is a signed comparison, while it probably should be an unsigned comparison.
--I like ILSe
Reply

Switching to unsigned comparisons might cause unexpected underflow errors, it's probably safer to just cap mana at 16,000.
Reply

(September 4th, 2013, 12:55)Anthony Wrote: Switching to unsigned comparisons might cause unexpected underflow errors, it's probably safer to just cap mana at 16,000.

Yes. That fixes the immediate problem.
I mentioned it to our new member Twilight Sparkle the Alicorn pony Princess to which she responded:
(August 5th, 2013, 08:43)TwilightSparkletheAlicorn Wrote: Thank you, but I think mana cap is a bad thing.

I have to say I agree with her.
--I like ILSe
Reply

(September 4th, 2013, 13:26)I like Serena Wrote: I have to say I agree with her.
There already is a mana cap; it's stored in a short, it can't possibly exceed 32,767. What difference does it make if the cap is at 16,000 or 32,000?
Reply

(September 4th, 2013, 14:59)Anthony Wrote: There already is a mana cap; it's stored in a short, it can't possibly exceed 32,767. What difference does it make if the cap is at 16,000 or 32,000?

Either way, as I see it, currently Insecticide contains a serious end-game bug, where vanilla contains a slightly less serious end-game bug.
--I like ILSe
Reply

(September 4th, 2013, 14:59)Anthony Wrote:
(September 4th, 2013, 13:26)I like Serena Wrote: I have to say I agree with her.
There already is a mana cap; it's stored in a short, it can't possibly exceed 32,767. What difference does it make if the cap is at 16,000 or 32,000?
the range multiplicator in the fortress =1/2. so, the maximum mana
is allowed to spend is calculated as 16400*2=negative, less than max pump.
then spell become negative strength but gives mana to the caster.

I fix this in my mod, but nobody tested it still.
Reply

(September 5th, 2013, 21:48)Asfex Wrote: I fix this in my mod, but nobody tested it still.

Hmm, you didn't make note of that in the description of your mod.
How did you fix it?
--I like ILSe
Reply

just implement the right behavior. I test idea :'the ranged attack spells does not affect the mana range penalty
' and had found it bad. but the fix of right behaviour was remain in the mod. and full description is always in the mod in readme file.
Reply



Forum Jump: