Author Topic: [Resolved] AI hang: Melee enemy and enviromental object  (Read 14624 times)

ushas

  • Hero Member
  • *****
  • Posts: 661
[Resolved] AI hang: Melee enemy and enviromental object
« on: January 25, 2018, 07:48:54 PM »
(v23, linux, SB)

I think this is the same problem as reported by awg with survivalist + bat (at least my aim was to recreate):
http://steamcommunity.com/app/545600/discussions/1/1693785035818232948/#c1693785035822373254

Played the game from the start up to Emilia. This time it hangs when the guy holds a knife. On a turn before that, in the same position, he attacked Sam in cc all right, but right on the beginning of his next turn it freezes.

The situation:


awg's screenshot for comparison:
https://steamuserimages-a.akamaihd.net/ugc/931551196250953961/2726FAF2447C5BC841CF21A3F9D631859163B892/


This time there is an error. Last lines in the log:
Code: [Select]
CharacterAIScript.GetMeleeOrdersAgainstEnvironmentObjects. There are IEOs in play
CharacterAIScript.GetMeleeOrdersAgainstEnvironmentObjects. Method called. There are: 0 more players than enemies around ieo 0
CharacterAIScript.GetMeleeOrdersAgainstEnvironmentObjects. Method called. There are: 0 more players than enemies around ieo 1
CharacterAIScript.GetMeleeOrdersAgainstEnvironmentObjects. Method called. There are: 1 more players than enemies around ieo 2
CharacterAIScript.GetMeleeOrdersAgainstEnvironmentObject. No move req. Enough AP. Current AP: 6 total: 3path cost 0 move & attack: 3
CharacterAIScript.GetMeleeVSIEOOrder. Method called.
CharacterAIScript.GetMeleeVSIEOOrder. Path is null. No move required
NullReferenceException: Object reference not set to an instance of an object
  at CharacterAIScript.GetMeleeMetaOrderAgainstEnvironmentObject (.InteractableEnvironmentObject ieoScriptIn, .MovementPath pathIn, Int32 playersMinusAlliesAdjacentToEnvironmentObjectIn, Int32 totalAPCostIn, Boolean escapesBlastIn) [0x00000] in <filename unknown>:0
  at CharacterAIScript.GetMeleeOrdersAgainstEnvironmentObjects () [0x00000] in <filename unknown>:0
  at CharacterAIScript+<GetMeleeAttackOrderForMaxDamageOpponent>c__Iterator33.MoveNext () [0x00000] in <filename unknown>:0

Seems he indeed wanted to trigger the canister. Gang's equipment lvl is 2, in case that plays any role in recreation.

Edit: Title was edited to better represent the issue.
« Last Edit: January 29, 2018, 05:49:09 PM by Daithi »

Daithi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1250
Re: AI hang: Survivalist with a knife
« Reply #1 on: January 25, 2018, 09:01:28 PM »
At a guess, it may be happening if they miss the object. Have seen them activate the environment objects quite a few times, and missing an environment object is not very common. It's a good place to start anyway, and it seems like the bug isn't going to be all that difficult to recreate. 

ushas

  • Hero Member
  • *****
  • Posts: 661
Re: AI hang: Survivalist with a knife
« Reply #2 on: January 25, 2018, 09:40:24 PM »
Ah, that's interesting. Yeah, was just restarting the battle till one of them had a melee weapon. Then it's about a bait, positioned Sam next to the thing per awg's instructions, not letting the second guy to do the ranged activation.

Edit: Of course, you know much better what's going on, just that now I realize - when was doing the cc activation cth is 100% -> thus no miss. Don't they have the same rules?


Edit2: The second object on the same map, the same hang. This guy is only HtH for a change.


Code: [Select]
CharAIScript.GetOrdersBasedOnBehaviourType. Checking for orders. Behaviour type is: 0
CharAIScript.GetOrdersBasedOnBehaviourType. Aggressive Character has melee weapon
BattleControlScript.GetMeleeDamage. Method called. Weapon name is: Unarmed damage is: 4.12005
BattleControlScript.GetMeleeDamage. Method called. Weapon name is: Combat Knife damage is: 5.88384
CharacterAIScript.GetMeleeMetaOrder. Method called. Is move required: False / avg distance to enemies: 8.5
BattleControlScript.GetMeleeDamage. Method called. Weapon name is: Unarmed damage is: 4.12005
BattleControlScript.GetMeleeDamage. Method called. Weapon name is: Combat Knife damage is: 5.88384
CharacterAIScript.GetMeleeMetaOrder. Method called. Is move required: False / avg distance to enemies: 8.5
CharacterAIScript.GetMeleeMetaOrder. Found path, adjacent exit allowed, no pathing through fire
CharacterAIScript.GetMeleeMetaOrder. Method called. Is move required: True / avg distance to enemies: 8
CharAIScript.GetMeleeMetaOrder. Path found, route through fire
CharacterAIScript.GetMeleeMetaOrder. Method called. Is move required: True / avg distance to enemies: 8
CharacterAIScript.GetMeleeOrdersAgainstEnvironmentObjects. Method called. There are: 3 IEOS. Current meta orders: 4
CharacterAIScript.GetMeleeOrdersAgainstEnvironmentObjects. There are IEOs in play
CharacterAIScript.GetMeleeOrdersAgainstEnvironmentObjects. Method called. There are: 1 more players than enemies around ieo 0
CharacterAIScript.GetMeleeOrdersAgainstEnvironmentObject. No move req. Enough AP. Current AP: 6 total: 3path cost 0 move & attack: 3
CharacterAIScript.GetMeleeVSIEOOrder. Method called.
CharacterAIScript.GetMeleeVSIEOOrder. Path is null. No move required
NullReferenceException: Object reference not set to an instance of an object
  at CharacterAIScript.GetMeleeMetaOrderAgainstEnvironmentObject (.InteractableEnvironmentObject ieoScriptIn, .MovementPath pathIn, Int32 playersMinusAlliesAdjacentToEnvironmentObjectIn, Int32 totalAPCostIn, Boolean escapesBlastIn) [0x00000] in <filename unknown>:0
  at CharacterAIScript.GetMeleeOrdersAgainstEnvironmentObjects () [0x00000] in <filename unknown>:0
  at CharacterAIScript+<GetMeleeAttackOrderForMaxDamageOpponent>c__Iterator33.MoveNext () [0x00000] in <filename unknown>:0
TimeOfDayWeatherScript.DetermineTimeUntilNextFlash. Method called. Time until flash: 24
TimeOfDayWeatherScript.HandleLightning. Method called
TimeOfDayWeatherScript.DetermineTimeUntilNextFlash. Method called. Time until flash: 42.5

Hm, but he seems to have a knife in his pockets. Anyway, again in battle it freezes at the beginning so visually he did nothing. Guessing his first action was supposed to be the object activation.
« Last Edit: January 25, 2018, 10:02:18 PM by ushas »

ushas

  • Hero Member
  • *****
  • Posts: 661
Re: AI hang: Survivalist with a knife
« Reply #3 on: January 25, 2018, 10:30:31 PM »
Another piece with HtH mafia and Arcadi:


Seems the issue can be recreated on other maps too, as soon as there is a melee enemy and an environmental object.

Unsure yet which steps are necessary but so far was successful to do it as follows:
1. First one must bait the enemy so he ends the turn adjacent to this object without activating it.
2. Then my own guy will step next to the object to be adjacent too, if not already there.
   (unsure if needed, but so far it was always to be also adjacent to the baited enemy, see all the images)
3. On the enemy's next turn, he is ought to start with activating the object, but the game freezes.


Edit: Confirming you don't need to be adjacent to the enemy.
 

Again, Mr. Mafia here ends the turn next to the container, followed by Ray stepping next to it too. Then he prob. wants to change to HtH and activate the thing. The game hangs. Seems it's enough when they start their turn next to the object while an ally is in the AOE too. Guaranteed freeze.
« Last Edit: January 26, 2018, 03:03:58 AM by ushas »

ushas

  • Hero Member
  • *****
  • Posts: 661
Re: AI hang: Melee enemy and enviromental object
« Reply #4 on: January 26, 2018, 03:16:23 AM »
I understand enemy CC activation is a fairly young. However, seems you will be checking the AI code anyway, so let me add some preliminary feedback: They do it to their detriment. Unsure whether it's that way always, but most of the time they just step next to the barrel, activate and end the turn. Yeah, it harms my guys and makes sense that our hp lowered is more important than theirs, esp. if it puts down one or more of us, but they are often harming their side even more.

Like when the guy is the last one and he blows himself up just because one ally stands next to such object, resulting in our win. He would do better to run away... On various occasions I thought the enemy has enough AP for activation as well as to step outside the AOE, but no, he ends the turn inside... Naturally, they're evaluating a lot of things. Perhaps also taking into account closeness to allies for the next turn? So perhaps just some weights need to be adjusted.

Daithi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1250
Re: AI hang: Melee enemy and enviromental object
« Reply #5 on: January 26, 2018, 06:13:52 PM »
They shouldn't attack if they will hit more of their own than the player - have you seen this happening?

Think there are some issues with the escape code. Will take some time to observe their behaviour and try to get them to more reliably escape the blast when trying to fix the bug. AP loss from wounds/status effect could be a contributing factor to them not escaping. Was planning on allowing the churchers to activate even if they can't get away, and the others to only activate if they can escape. That was the plan, but there was some reason I backed off from this.

If it's the last guy standing I guess it's debatable if it's going to be better to try and escape as they very likely have lower AP, and it usually only takes one bullet. Setting off the container is likely to cost the player an hour in healing. Will think about it though.
« Last Edit: January 26, 2018, 10:54:58 PM by Daithi »

ushas

  • Hero Member
  • *****
  • Posts: 661
Re: AI hang: Melee enemy and enviromental object
« Reply #6 on: January 27, 2018, 10:49:57 AM »
They shouldn't attack if they will hit more of their own than the player - have you seen this happening?
No. They seem to behave in [only activate if # of gangsters <= # of allies] manner or similar. Haven't deliberately tested though. For testing AI hanging tried some situations like 2 enemies and 1 ally.

My impressions are indeed very subjective, including about frequency. An example: Ray adjacent to a container similarly as in the picture above. Mafia guy starts his turn one tile away. He does one step, switches from hammer to HtH (which is neat as it saves ap), sets it off and... ends turn. I swear, wasn't distracting nor harming him in any way. The whole operation must cost 4AP. Maybe he gets something like 4AP per turn? Or from a statistical pov - concludes that shooting Ray has a too low CTH in comparison to sure blast damage? Dunno.

It can happen just haven't seen often. Recently have seen a church lady to set it off and run away from the aoe.

For the record, haven't looked at HP or other nuances. Why was thinking they do it to their detriment was mainly when one is sacrificing self or a comrade. It's a huge deal when a unit is rendered combat-incapable. They are initially more numerous, so looks worth for them to sacrifice when it can put down an ally too. However, if it happens just because an ally of full health was hugging a gas canister... Well, thanks it saves me AP, healing costs less than finishing an enemy, besides attacks can miss. Even when it deals more damage to more allies -> my guys are still in the battle while the enemy unit sure isn't. Depends on numbers and on queue, in some cases that ends worse for gangs too. I understand it's all highly situational and subjected to design and fun. Not at all trying to say how it should or shouldn't be. Only crudely evaluating. If you intended such identity for churchers, sounds pretty neat:) People are scared of those with low self-preservation... Their numbers may as well support this well.


Some example:

Healthy Sam and Emilia were harming Ivo. Raul decides to do something. Moves as highlighted on the left, sets off the container in HtH, then he moves to the tile at the corner (see on the right), then ends the turn. This one is interesting, not only he sacrifices Ivo but he also moves those two steps to stay withing the aoe.

If it's the last guy standing I guess it's debatable if it's going to be better to try and escape as they very likely have lower AP, and it usually only takes one bullet. Setting off the container is likely to cost the player an hour in healing. Will think about it though.
You're a spot on with that. I only did comparison like 0% vs. ~1% chance to survive. When the battle is pretty much lost (such as was also the circumstance of Raul and Ivo), harming us strategically makes a good sense.
« Last Edit: January 28, 2018, 06:12:41 PM by ushas »

Daithi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1250
Re: AI hang: Melee enemy and enviromental object
« Reply #7 on: January 29, 2018, 04:18:49 PM »
Thanks for the extra info. Going to look at this now.

Concerning the enforcer example, yeah, that's a dumb move. Targeting the object and running away would probably be the best move, given that he probably has 6AP, and would be a decent move if he had 7AP.

Agree on situational nature of setting off the objects. It's a subjective take, but for Raul and Ivo, setting off the barrel wouldn't have been bad if Raul hadn't decided to stand next to the barrel, which points to a clear logic in the code for generating an order to escape. Granted 1 man down (who probably would have died in next player turn), but it's 2x damage to player team, possibility of lost AP from wounds, AP cost of healing.

With you on the difficulty of evaluating how well these decisions work for the AI due to highly situational nature, but will start out by working on the obvious problem: the code to ensure they flee properly.


Daithi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1250
Re: AI hang: Melee enemy and enviromental object
« Reply #8 on: January 29, 2018, 05:48:49 PM »
Subject to additional testing, the hang is fixed. Found an error in the escape code which certainly accounts for the Raul & Ivo issue, and potentially for the enforcer.

ushas

  • Hero Member
  • *****
  • Posts: 661
Re: [Resolved] AI hang: Melee enemy and enviromental object
« Reply #9 on: January 29, 2018, 06:31:30 PM »
Neat. Yeah, step by step approach is often the best. Am discussing too much at once here. Not that anything else must change.

As for Raul. It indeed felt like he's trying to escape just mixed left and right:) It wasn't really so bad move. He has a better cover over there. The blast damaged him a bit but my guys are much bigger threat than that, IF they will manage to land the hits.

A side note: Unfortunately not having the screen anymore, but IIRC it was Ivo to act after Raul. It means Raul could have attacked normally, then Ivo himself could activate the barrel and run away. Uff... think this is approaching the territory of AI guys talking to each other. Suspecting another can of worms on its own... What if Ivo chickens out and flees, etc... After all it's all about fun. Let's say am just overly concerned about rights of my enemies.

ushas

  • Hero Member
  • *****
  • Posts: 661
Re: [Resolved] AI hang: Melee enemy and enviromental object
« Reply #10 on: March 19, 2018, 12:39:25 AM »
A bit looked on how they behave in v24 (including rehearsal of Ray's mission with enforcer), it seems they are indeed more cautious to trigger containers. Have seen them consistently run away (as far as tested). So seems your fix was successful in changing behaviour. 

Had only once an enemy not stepping away: It was right on the first mission, brother and sister. So the brother starts turn next to Sam and container, activates and ends turn. This puts him down. But think he was also already wounded and that those two have something like 5AP. Thus guess when wounded he can have 3AP -> that's barely enough for activation. So... unless mistaken, am declaring this one also ok:)

Daithi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1250
Re: [Resolved] AI hang: Melee enemy and enviromental object
« Reply #11 on: March 21, 2018, 12:11:08 PM »
Thanks for checking up on the fix.