Page 1 of 1

Bug: Lose a troop after capturing a territory

Posted: Tue Mar 11, 2014 1:01 pm
by willco66
I somehow lost a cavalry unit in game #58


2014-03-11 12:57:46 - Old Prussia have moved 2 Cavalry, 2 Siege Engines, 8 Infantry from Prussia to Baltic Sea.
2014-03-11 12:58:05 - Old Prussia launches a Besiege (by sea) on Götaland from Baltic Sea, defeating 1 Infantry, 1 Fort.
2014-03-11 12:58:05 - Old Prussia have taken Götaland with 3 Infantry, 1 Siege Engine, 1 Cavalry.
2014-03-11 12:58:28 - Old Prussia have moved 1 Siege Engine, 5 Infantry from Baltic Sea to Götaland.

Re: Game #58

Posted: Tue Mar 11, 2014 6:00 pm
by e_i_pi
Weird, there's no way for me to track down what happened unfortunately. Plus, I haven't got my dev laptop to run some unit tests and try to reproduce the issue.

Anyhow, I've given you an extra 96 gold to make up for it. I'll look into it on the weekend, but it may be tricky to trace.

Review attack territory code for potential bug

Posted: Sat Mar 15, 2014 11:54 pm
by e_i_pi
In game #58, I managed to attack from Armenia to Vasporokan, killing the 1 Cavalry there, capturing the 1 Fort, but also moving all 4 of my Infantry, leaving Armenia without troops. This caused a client error. Considering it will be nigh on impossible to reproduce, the better option is a complete review of the server side Attack Territory code to see where it may have fallen down. It's likely a problem with reserving a claimant from the attacking territory, but it's best that I compare the client-side and server-side code to make sure they match, as any server side error may be indicative of a matching client side error.

Re: Game #58

Posted: Sat Mar 15, 2014 11:55 pm
by e_i_pi
I'm guessing this may be linked to this bug, as both have involved troop numbers not calculating correctly after a successful territory capture.

Re: Review attack territory code for potential bug

Posted: Sun Mar 16, 2014 4:39 pm
by Trashcan
Looks like I managed the same thing same game... Took Tripoli from Jerusalem with 4 infantry and a siege. Lost one infantry and defeated their one infantry, capturing their fort. Jerusalem is left with no troops. And up popped the client error.

EDIT: I should note that I moved one troop back to Jerusalem from Tripoli after re-entering the map.

Re: Game #58

Posted: Sun Mar 16, 2014 5:04 pm
by e_i_pi
Definitely the same bug. Topics merged. I'm about to cook dinner, but I'll have a look at the code in a bit, see if I can spot the issue.

EDIT: That's exactly how it happened with me. Good news, in that I should be able to reproduce the issue without any problem.

Re: Bug: Lose a troop after capturing a territory

Posted: Sun Mar 16, 2014 5:59 pm
by e_i_pi
I think I've found the issue, family has just popped around though, so it will be an hour or so before I can fix it :)

Re: Bug: Lose a troop after capturing a territory

Posted: Sun Mar 16, 2014 8:43 pm
by e_i_pi
Fixed and FIXED!

What a nasty bug. What happened is there was a very minor bug in calculating the "victorious troops" when a territory is captured. Basically, let's say you have 4 infantry and 1 siege, and you attack a territory with 1 infantry and 1 fort. Let's say, during that battle you lose 1 infantry, and kill 1 infantry. Well, that leaves 3 infantry and 1 siege on your territory, and 1 fort on the other territory, meaning you capture it. The problem was that the game engine automatically moves in the "victorious troops", in this case 2 infantry and 1 siege. Problem was, it was incorrectly checking which troop(s) were casualties during the battle, so it would move in the full 3 infantry and 1 siege, leaving the original territory empty!

The interesting thing about this bug is that it has only appeared now because Medieval Europe is the only Scenario where it is possible to win a territory without actually killing all the troops there. The bug couldn't possibly occur on the regular maps, because the only way you can capture a territory is if the final battle has no attacker casualties.

Anyhow, this will definitely fix the bug that Kenny and I discovered. The original report put in by willco66 is almost certainly fixed by this, as it seemed to be very similar circumstances, although it was a little different.

I'm going to close this record anyhow as, of the 3 issues encountered, 2 are definitely fixed, and the last I am 90% sure is fixed.