Taking wounded Soldiers on Avenger Defense leads to Bugs afterwards

Post Reply
LeaderEnemyBoss
Posts: 106
Joined: Wed Jan 18, 2017 5:27 pm

Taking wounded Soldiers on Avenger Defense leads to Bugs afterwards

Post by LeaderEnemyBoss »

1) LW 1.2
2) Windows 10/Steam
3) What other XCOM2 mods you are playing with: http://steamcommunity.com/sharedfiles/f ... =855473321 (only gameplay mod is my PsiOp Overhaul)
4) The circumstances of the bug or precise steps to produce it.

Here is what happens:
I got an Avenger Defense Mission, as usual I could take wounded Soldiers with me. I completed the mission without issues. Also the defense mission went very welll and I received no (additional) wounds, so maybe this has something to with it (victory screen displayed 0 wounds). Immediatly after the Avenger Defense I startet to infiltrate the golden Path Psi Gate mission. I noticed that my previously wounded soldiers were healthy again and could be taken on that mission. "Strange" I thought, but maybe it was because i healed them during the defense mission or something, anyway I took them with me.

A bit later i get a mini retaliation and .... I can choose some of the soldiers that I just sent to infiltrate the Psi-Gate for this mission aswell! Specifically only soldiers, that were "illegitly healthy" are affected by this. Other soldiers that were also sent to the Psi-Gate but didnt suffer any wounds prior to the Avenger Defense work as expected.

These are the 4 wounded soldiers I took to the Avenger Defense Mission:
Spark "Samaritan" (is listed as "Infiltrating" but gets auto selected for the mini-retal if it is selected)
Grenadier "Yeti" (is not listed as "Infiltrating")
Shinobi "What3v3r" (is not listed as "Infiltrating")
PsiOp "Kraken" should be affected aswell, but for some reason isnt (probably the same like with Samaritan, but he just doesnt get autoselected because he isnt in that squad)

5) Whether you are able to offer a savegame for us to look at.
https://drive.google.com/file/d/0B85UhN ... sp=sharing

The archive contains two save files. Save 56 is before the Avenger Defense. I just sent most of my A-Squad on a Invasion-Precursor-raid (this is were they got their wounds ;p). The Avenger Defense occured about 3 ingame days after this.

Save 58 is when I noticed the bug. The Defense mission is over, I sent a 9 soldier squad to the Psi Gate and the mini retal appeared. When you select the mini retal, the Spark "Samaritan" gets auto selected for that mission, allthough he is infiltrating the Psi Gate. What3v3r and Yeti are selectable allthough they shouldnt be.
LeaderEnemyBoss
Posts: 106
Joined: Wed Jan 18, 2017 5:27 pm

Re: Taking wounded Soldiers on Avenger Defense leads to Bugs afterwards

Post by LeaderEnemyBoss »

So i wrote a custom mod and did some investigating.

First things first: using the "remove all items" buttons removes items from Samaritan, Yeti and What3v3r (which would be super annoying when continueing to play), but not from "Kraken". Interestingly enough my mod revealed, that "Kraken" is the only one who still has an ongoing healing project gamestate (remember: he is currently infiltrating the psi gate). I also noticed another side effect: I can no longer use the "remove soldier" button in the squad select screen and I have no idea why. Only way to remove soldiers is to use the "Clear Squad" button. I first intended to manually "fix" my broken soldiers via mod, but I am starting top think it may be easier to redo the Defense mission with some cheats and make sure the affected soldiers return with some additional wounds ^^.

EDIT:
Samaritan, Yeti and What3v3r hav the status "estatus_Active", Kraken has "estatus_OnMission" which would explain the above. I dont know why kraken is the only one that works at least "somewhat". I also dont know why Samaritan is listed as "Infiltrating" in the Armory, when he has "estatus_Active". I do know that things are majorly messed up :p
LeaderEnemyBoss
Posts: 106
Joined: Wed Jan 18, 2017 5:27 pm

Re: Taking wounded Soldiers on Avenger Defense leads to Bugs afterwards

Post by LeaderEnemyBoss »

So ..I just couldnt let it go, and after investigating what caused the "remove soldier" button being broken, it turns out just manually setting the status of the affected soldiers to "estatus_onMission" did the trick and fixed all problems. I assume Kraken isn't "broken" because his healing project didnt finish until I noticed the bug. I guess as soon as its finished he will have the same issue, but thankfully my bugfix-mod will resolve that issue ;).

The bug still stands though and should be fixed.
tracktwo
Long War Dev
Posts: 241
Joined: Sat Jan 07, 2017 7:43 pm

Re: Taking wounded Soldiers on Avenger Defense leads to Bugs afterwards

Post by tracktwo »

Thanks for the report. One of our testers also just found an issue with squad autofill filling wounded soldiers too, which may also be related. It sounds like something is off with the post-mission status setting. I'll take a look at your saves and see what I can see.
LeaderEnemyBoss
Posts: 106
Joined: Wed Jan 18, 2017 5:27 pm

Re: Taking wounded Soldiers on Avenger Defense leads to Bugs afterwards

Post by LeaderEnemyBoss »

tracktwo wrote:Thanks for the report. One of our testers also just found an issue with squad autofill filling wounded soldiers too, which may also be related. It sounds like something is off with the post-mission status setting. I'll take a look at your saves and see what I can see.
I am pretty sure it has to do with my wounded soldiers not getting further wounds during the Avenger defense. The game thinks they took no wounds during the mission, therefore they are not wounded -> sets their status to active, but their healing project is still going. I send them on a mission -> status gets set to "OnMission". While infiltrating their healing project finishes -> status gets set to active again. They can now be taken on on other missions, stripped from gear and other bugginess.
tracktwo
Long War Dev
Posts: 241
Joined: Sat Jan 07, 2017 7:43 pm

Re: Taking wounded Soldiers on Avenger Defense leads to Bugs afterwards

Post by tracktwo »

Yeah, but there is also another bug here specific to psi ops I think, which is why Kraken has different behavior, and why Bilf had a wounded psi op autofilling into a squad.

Unfortunately I can't load your saves into the debugger: one or more of the mods you have installed that I don't causes it to immediately crash on load. But the scenario is simple enough and hopefully reproducible enough for me to make my own.
LeaderEnemyBoss
Posts: 106
Joined: Wed Jan 18, 2017 5:27 pm

Re: Taking wounded Soldiers on Avenger Defense leads to Bugs afterwards

Post by LeaderEnemyBoss »

tracktwo wrote:Yeah, but there is also another bug here specific to psi ops I think, which is why Kraken has different behavior, and why Bilf had a wounded psi op autofilling into a squad.

Unfortunately I can't load your saves into the debugger: one or more of the mods you have installed that I don't causes it to immediately crash on load. But the scenario is simple enough and hopefully reproducible enough for me to make my own.
At least for Kraken I can say: he was no anomaly after all, his healing project just wasnt finished yet, thats why his status was still OnMission. A few ingame days later his healing project finished and he had the same issues (got set to Active while still infiltrating leading to the above stated results).
tracktwo
Long War Dev
Posts: 241
Joined: Sat Jan 07, 2017 7:43 pm

Re: Taking wounded Soldiers on Avenger Defense leads to Bugs afterwards

Post by tracktwo »

OnMission isn't supposed to be used for that, it should be eStatus_Healing for wounded soldiers.

In the psi op save I have that I can actually debug, I can see the wounded psiop has status Active, which is incorrect, it should've been reset to healing. I think I can see the cause of that bug, but it's specific to psiops and isn't the same as your avenger defense bug.

As for the avenger defense bug, I can't repro it myself. If I spawn an avenger defense mission and add wounded soldiers to the mission they are correctly kept as wounded after the mission and are ineligible to send on any other mission. I've seen this issue reported several times though, so either someone else has already fixed it in 1.3, or there is something more to it than just sending wounded soldiers on a defense mission.
LeaderEnemyBoss
Posts: 106
Joined: Wed Jan 18, 2017 5:27 pm

Re: Taking wounded Soldiers on Avenger Defense leads to Bugs afterwards

Post by LeaderEnemyBoss »

[quote="tracktwo"]OnMission isn't supposed to be used for that, it should be eStatus_Healing for wounded soldiers. [quote]

Yes i know ..his status was OnMission because he was infiltrating (which he only was able to do because his status was Acvtive after the Avenger Defense.

I will keep my pre-AvengerDefense save alive. After 1.3 is released I may try to reproduce the behaviour and see if its already fixed like you suggested.
tracktwo
Long War Dev
Posts: 241
Joined: Sat Jan 07, 2017 7:43 pm

Re: Taking wounded Soldiers on Avenger Defense leads to Bugs afterwards

Post by tracktwo »

Ok, so I have debugged this a fair bit and I think it's a vanilla bug that was mostly benign, but is no longer so with LW2.

Basically what's happening is a bad interaction with the HP granted from armor. The way it works is the game records the lowest and highest HP you had during a mission. After the mission, all the HP granting effects from armor are stripped, reducing your HP back to "normal", which can have the side-effect of erasing all the HP damage you took. But that isn't how armor HP works in XCOM2, you still are considered wounded: A special post-processing phase runs after all the effects have been removed and looks at the lowest and highest HP you had during that mission and reduces your current HP by the same percentage so you still take a wound even if you take less damage than the HP granted by the armor.

But... in the avenger defense mission you go on while wounded, your lowest and highest HP for that mission are exactly the same as your current HP, so the post-mission HP fixup doesn't occur and any old damage from a previous mission is absorbed by the armor HP at the end of this mission. I swear I have seen bug reports about this on Avenger Defense missions healing your soldiers in vanilla but I can't seem to find any right now.

At any rate, in vanilla it's a fairly harmless bug that is sort of a "cheat" in that you insta-heal any injured soldiers you take as long as they don't take any more damage on the mission. But in LW2 it's bad because since they're no longer injured they are eligible to go on missions, but the healing project is still running for that soldier in the HQ: it doesn't know they were magically healed after the avenger defense. Whenever that project ticks over to completion it'll reset the soldier to "active" state, even if they are off infiltrating somewhere else.

I'll try to get a fix for this into 1.3. One easy fix is to just set the HighestHP value for the soldier to their maximum HP on mission start instead of the current HP. This'll have the side effect that they'll be considered wounded by the after action report, though.
LeaderEnemyBoss
Posts: 106
Joined: Wed Jan 18, 2017 5:27 pm

Re: Taking wounded Soldiers on Avenger Defense leads to Bugs afterwards

Post by LeaderEnemyBoss »

Ha! I secretly already had a hunch that it may have been a vanilla bug that just didnt matter alot there (with no infiltration present etc.). Imho your workaround is fine, but you will probably receive the occasional "false" bug report ("I took no wounds but the completion screen displays wounded soldiers"). Luckily Avenger Defense Missions arent that numerous ;).
tracktwo
Long War Dev
Posts: 241
Joined: Sat Jan 07, 2017 7:43 pm

Re: Taking wounded Soldiers on Avenger Defense leads to Bugs afterwards

Post by tracktwo »

I came up with a slightly better fix for this that shouldn't interfere with the after action report. Basically I just record the current HP of the unit on mission start, and if the unit ends the mission with more HP than that, it reduces it back down to the value they started with. That is, you can't heal while on mission above what you started with. It's possible this may interfere with some mods that do funny stuff with post-mission HP if they do it very early, but if they do it later it should have no impact.
LeaderEnemyBoss
Posts: 106
Joined: Wed Jan 18, 2017 5:27 pm

Re: Taking wounded Soldiers on Avenger Defense leads to Bugs afterwards

Post by LeaderEnemyBoss »

tracktwo wrote:I came up with a slightly better fix for this that shouldn't interfere with the after action report. Basically I just record the current HP of the unit on mission start, and if the unit ends the mission with more HP than that, it reduces it back down to the value they started with. That is, you can't heal while on mission above what you started with. It's possible this may interfere with some mods that do funny stuff with post-mission HP if they do it very early, but if they do it later it should have no impact.
Did you already test this? I assumed the game compares the hp at mission start with the hp at mission end. If this is the case, them not being healed wouldnt make a difference, the game would still consider them as "active" (I say this because I'm pretty sure i didnt heal all of my soldiers during my Defense mission yet they were still bugged).
tracktwo
Long War Dev
Posts: 241
Joined: Sat Jan 07, 2017 7:43 pm

Re: Taking wounded Soldiers on Avenger Defense leads to Bugs afterwards

Post by tracktwo »

Yes, I tested it. The problem is in the way it compares these values, which is by recording their *current* hp at mission start vs mission end, which doesn't account for the fact they could have started the mission with less than maximum HP. It's not that *you* healed them during the mission, it's that the game did due to the way armor HP is applied and removed on mission start/end.

The way it works is:

- In OnBeginTacticalPlay it sets the units LowestHP and HighestHP fields to their current HP. This happens before item effects are granted, so it's their baseline current HP.
- In my fix, I also record the current HP in a separate field (in a UnitValue).
- Item effects are applied, possibly raising the unit's current and max hp. This also modifies LowestHP and HighestHP (but not my new value that recorded raw HP at mission start).

During the mission if they take damage their current HP and LowestHP will both be adjusted, and medikits or other effects can raise their current HP (but LowestHP stays at the low water mark).

At mission end:

- Item effects are all removed. This can "heal" units when HP granting items are removed if they took damage but not as much as their armor granted. For example, in my test where the unit started the mission with 6/9HP and had 13HP of bonus health from armor, they started and ended the mission with CurrentHP=19, LowestHP=19, HighestHP=19, MaxHP=22. When the armor effects were stripped they went from 19/22HP to 9/9 HP, *not* 6/9. Stripping HP-granting items doesn't always lower their current HP, just max (that could kill them if they ended the mission with less HP than their armor provided).

- The EndTacticalHealthMod function compares LowestHP to HighestHP, and if they are different, applies damage to the unit to get to the same percentage as LowestHP/HighestHP, ensuring they still take a wound even if they took less damage than the armor provided. This is the root cause of the bug, because if they started the mission wounded but took no additional wounds on-mission LowestHP == HighestHP and it leaves their HP stat alone after possible healing by armor removal. In my change, it also checks if either a) LowestHP == HighestHP but they have more currentHP than the unit value I stored at mission start or b) LowestHP< HighestHP but LowestHP/HighestHP > currentHP/SavedHP (that is, they took some damage, but the result we computed for their new HP is greater than what it was when they started the mission). In either of these cases currentHP is lowered to the value I stored at mission start.
Post Reply