BUG. AI take control of plane and make moves on the ground

For Discussion of the SoW 5 Campaign
Post Reply
User avatar
Rostic
Posts: 9
Joined: Sun Sep 27, 2015 5:54 pm

BUG. AI take control of plane and make moves on the ground

Post by Rostic »

Looks like currecnt script that should damage AI controlled airplane (after player leave it) work not safe. AI is trying to start engines and from time to time aircraft moves on the ground.

Time code 0:25 - 0:35
https://youtu.be/WP6PqeTBu_g

I recommend to use this script to damage AI controlled aircraft:

Code: Select all

using System.Text;
using System;
using System.Collections;
using maddox.game;
using maddox.game.world;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading;
using System.Diagnostics;
using part;


public class Mission : AMission
{
    public override void OnBattleStarted()
    {
        base.OnBattleStarted();

        //listen to events from all missions.
        MissionNumberListener = -1;
    }

    public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceLeave(player, actor, placeIndex);

        Timeout(1, () => { damageAiControlledPlane(actor); } );
    }

    public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> damages)
    {
        base.OnActorDead(missionNumber, shortName, actor, damages);
        if (actor != null && actor is AiGroundActor)
            Timeout(20, () => { (actor as AiGroundActor).Destroy(); });
    }


    private bool isAiControlledPlane(AiAircraft aircraft)
    {
        if (aircraft == null)
            return false;

        //check if a player is in any of the "places"
        for (int i = 0; i < aircraft.Places(); i++)
            if (aircraft.Player(i) != null)
                return false;

        return true;
    }

    private void destroyPlane(AiAircraft aircraft)
    {
        if (aircraft != null)
            aircraft.Destroy();
    }

    private void damageAiControlledPlane(AiActor actorMain)
    {
        foreach (AiActor actor in actorMain.Group().GetItems())
        {
            if (actor == null || !(actor is AiAircraft))
                return;

            AiAircraft aircraft = (actor as AiAircraft);

            if (!isAiControlledPlane(aircraft))
                return;

            if (aircraft == null)
                return;

            aircraft.hitNamed(part.NamedDamageTypes.ControlsElevatorDisabled);
            aircraft.hitNamed(part.NamedDamageTypes.ControlsAileronsDisabled);
            aircraft.hitNamed(part.NamedDamageTypes.ControlsRudderDisabled);
            aircraft.hitNamed(part.NamedDamageTypes.FuelPumpFailure);

            int iNumOfEngines = (aircraft.Group() as AiAirGroup).aircraftEnginesNum();
            for (int i = 0; i < iNumOfEngines; i++)
            {
                aircraft.hitNamed((part.NamedDamageTypes)Enum.Parse(typeof(part.NamedDamageTypes), "Eng" + i.ToString() + "TotalFailure"));
            }

            Timeout(120, () => { destroyPlane(aircraft); });
        }
    }
}
Intel Core i7 8700K 3.7Ghz, DDR4 16Gb 2666Mhz, Asus Prime Z370-A, ADATA XPG SX8200 240Gb (PCIe Gen3x4), RTX 2060 6Gb

Admin (Reddog)
Site Admin
Posts: 3615
Joined: Fri Jul 11, 2014 1:09 pm

Re: BUG. AI take control of plane and make moves on the grou

Post by Admin (Reddog) »

Code: Select all

public void damageAiControlledPlane(AiActor actorMain)
        {
            foreach (AiActor actor in actorMain.Group().GetItems())
            {
                if (actor == null || !(actor is AiAircraft))
                    return;

                AiAircraft aircraft = (actor as AiAircraft);

                if (!Functions.isAiControlledPlane(aircraft))
                    return;

                if (aircraft == null)
                    return;

                aircraft.hitNamed(part.NamedDamageTypes.ControlsElevatorDisabled);
                aircraft.hitNamed(part.NamedDamageTypes.ControlsAileronsDisabled);
                aircraft.hitNamed(part.NamedDamageTypes.ControlsRudderDisabled);
                aircraft.hitNamed(part.NamedDamageTypes.FuelPumpFailure);
                aircraft.hitNamed(part.NamedDamageTypes.Eng0TotalFailure);
                aircraft.hitNamed(part.NamedDamageTypes.ElecPrimaryFailure);
                aircraft.hitNamed(part.NamedDamageTypes.ElecBatteryFailure);

                aircraft.hitLimb(part.LimbNames.WingL1, -0.5);
                aircraft.hitLimb(part.LimbNames.WingL2, -0.5);
                aircraft.hitLimb(part.LimbNames.WingL3, -0.5);
                aircraft.hitLimb(part.LimbNames.WingL4, -0.5);
                aircraft.hitLimb(part.LimbNames.WingL5, -0.5);
                aircraft.hitLimb(part.LimbNames.WingL6, -0.5);
                aircraft.hitLimb(part.LimbNames.WingL7, -0.5);


                int iNumOfEngines = (aircraft.Group() as AiAirGroup).aircraftEnginesNum();
                for (int i = 0; i < iNumOfEngines; i++)
                {
                    aircraft.hitNamed((part.NamedDamageTypes)Enum.Parse(typeof(part.NamedDamageTypes), "Eng" + i.ToString() + "TotalFailure"));
                }


                Strategy.THIS.Timeout(300, () => { destroyPlane(aircraft); });

            }
        }

That's what we use and have always used.
Image

User avatar
Rostic
Posts: 9
Joined: Sun Sep 27, 2015 5:54 pm

Re: BUG. AI take control of plane and make moves on the grou

Post by Rostic »

I checked your function in my mission script.
First what I did is replaced your's:

Code: Select all

if (!Functions.isAiControlledPlane(aircraft))
to my:

Code: Select all

if (!isAiControlledPlane(aircraft))
because I do not have a class "Functions" but this should not influence the logic.
After that I ran the dedicated server and got exception on mission load
System.Exception: c:\Users\Rostic\Documents\1C SoftClub\il-2 sturmovik cliffs of dover\missions\Multi\Dogfight\!TestingMap.cs(125,4): error CS0103: Name "Strategy" did not exist in current context
The words "Name "Strategy" did not exist in current context" is translation from Russian so can be some difference with original English message.

In this case, scrip did not work at all, so I replace your line:

Code: Select all

Strategy.THIS.Timeout(300, () => { destroyPlane(aircraft); });
with:

Code: Select all

Timeout(300, () => { destroyPlane(aircraft); });
And after that I see that your function is working fine on my dedicated server.

The only thing I can recommend is to check "damageAiControlledPlane" with the any aircraft by yourself, and check the mission load log that no exceptions there.
Intel Core i7 8700K 3.7Ghz, DDR4 16Gb 2666Mhz, Asus Prime Z370-A, ADATA XPG SX8200 240Gb (PCIe Gen3x4), RTX 2060 6Gb

Admin (Reddog)
Site Admin
Posts: 3615
Joined: Fri Jul 11, 2014 1:09 pm

Re: BUG. AI take control of plane and make moves on the grou

Post by Admin (Reddog) »

Sorry, I wasn't implying you weren't correct. There may well be an issue that I haven't spotted yet but I've not had chance to check the logs.

Our code doesn't work from the mission file so that's why the code isn't a drop in replacement but thanks for checking it doesn't have an issue under normal circumstances.

Did the AI get deleted in the end?
Image

User avatar
Rostic
Posts: 9
Joined: Sun Sep 27, 2015 5:54 pm

Re: BUG. AI take control of plane and make moves on the grou

Post by Rostic »

Admin (Reddog) wrote: Did the AI get deleted in the end?
I do not know. I did not wait so long. I'll check next time when SoW will be running.
Intel Core i7 8700K 3.7Ghz, DDR4 16Gb 2666Mhz, Asus Prime Z370-A, ADATA XPG SX8200 240Gb (PCIe Gen3x4), RTX 2060 6Gb

Admin (Reddog)
Site Admin
Posts: 3615
Joined: Fri Jul 11, 2014 1:09 pm

Re: BUG. AI take control of plane and make moves on the grou

Post by Admin (Reddog) »

Thanks for reporting this Rostic. I've checked the logs and can replicate the issue myself. However nothing's showing in the logs so I need to do a bit more digging. Pretty sure this "used to work" but clearly isn't now. :oops:
Image

User avatar
Rostic
Posts: 9
Joined: Sun Sep 27, 2015 5:54 pm

Re: BUG. AI take control of plane and make moves on the grou

Post by Rostic »

Rostic wrote:
Admin (Reddog) wrote: Did the AI get deleted in the end?
I do not know. I did not wait so long. I'll check next time when SoW will be running.
Ok. I checked this thing and aircraft disapears in 10 minutes timeout (600 seconds) that is differs from 300 seconds in code that you provided in post higher.
Intel Core i7 8700K 3.7Ghz, DDR4 16Gb 2666Mhz, Asus Prime Z370-A, ADATA XPG SX8200 240Gb (PCIe Gen3x4), RTX 2060 6Gb

Admin (Reddog)
Site Admin
Posts: 3615
Joined: Fri Jul 11, 2014 1:09 pm

Re: BUG. AI take control of plane and make moves on the grou

Post by Admin (Reddog) »

OK, so I've spent a large amount of time trying to track down this issue now.

What I'm finding is that the code seems to stop working and just die silently at the line

Code: Select all

aircraft.hitLimb(part.LimbNames.WingL5, -0.5);
Just out of curiosity Rostic, did you use the wing damage part of my code in your test?
Image

User avatar
Rostic
Posts: 9
Joined: Sun Sep 27, 2015 5:54 pm

Re: BUG. AI take control of plane and make moves on the grou

Post by Rostic »

Admin (Reddog) wrote:OK, so I've spent a large amount of time trying to track down this issue now.

What I'm finding is that the code seems to stop working and just die silently at the line

Code: Select all

aircraft.hitLimb(part.LimbNames.WingL5, -0.5);
Just out of curiosity Rostic, did you use the wing damage part of my code in your test?

Wow! Thats right! Script silently stops working! But in my case aircraft didn't try to move, thats why I thought that everithing is fine!
But it fails! I added "try catch" and if exception thows just send a message to all Players, but this also did not happened for connected client (message not delivered), but the server log in terminal shows me this:
Server to [Gr129_Rostic]: System.IndexOutOfRangeException: Индекс находился вне границ массива (translation: "Index out of array range").

Server stack trace:
в nqx5lFN0JKJL5SL9y05SqievCudjkz_dWt3oxj1iDE4g.igG_zgGTUtrJRJiSQBM6ADZyAr9HSmjSwJLPciK4U2oU(t_JLTf$BqgPs6iMgsfhO1XGb2t_5H_$QHhkDcWrNNwEc , LimbNames , Double , Boolean )
в zddhfvhOrb_PwBi8mNBRg8MDNdx5J3$U9sNIkfYc7vnmhCLt_pSv5Xmgu4FUWKnmSQ.maddox.game.world.AiAircraft.hitLimb(LimbNames limb, Double value)
в System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
в System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]:
в System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
в System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
в maddox.game.world.AiAircraft.hitLimb(LimbNames limb, Double value)
в Mission.damageAiControlledPlane(AiActor actorMain)
my damage function:

Code: Select all

public void damageAiControlledPlane(AiActor actorMain)
	{
		try {
			foreach (AiActor actor in actorMain.Group().GetItems())
			{
				if (actor == null || !(actor is AiAircraft))
						return;
				
				AiAircraft aircraft = (actor as AiAircraft);
				
				if (!isAiControlledPlane(aircraft))
						return;
				
				if (aircraft == null)
						return;
				
				aircraft.hitNamed(part.NamedDamageTypes.ControlsElevatorDisabled);
				aircraft.hitNamed(part.NamedDamageTypes.ControlsAileronsDisabled);
				aircraft.hitNamed(part.NamedDamageTypes.ControlsRudderDisabled);
				aircraft.hitNamed(part.NamedDamageTypes.FuelPumpFailure);
				aircraft.hitNamed(part.NamedDamageTypes.Eng0TotalFailure);
				aircraft.hitNamed(part.NamedDamageTypes.ElecPrimaryFailure);
				aircraft.hitNamed(part.NamedDamageTypes.ElecBatteryFailure);
				
				aircraft.hitLimb(part.LimbNames.WingL1, -0.5);
				aircraft.hitLimb(part.LimbNames.WingL2, -0.5);
				aircraft.hitLimb(part.LimbNames.WingL3, -0.5);
				aircraft.hitLimb(part.LimbNames.WingL4, -0.5);
				aircraft.hitLimb(part.LimbNames.WingL5, -0.5);
				aircraft.hitLimb(part.LimbNames.WingL6, -0.5);
				aircraft.hitLimb(part.LimbNames.WingL7, -0.5);
				
				
				int iNumOfEngines = (aircraft.Group() as AiAirGroup).aircraftEnginesNum();
				for (int i = 0; i < iNumOfEngines; i++)
				{
						aircraft.hitNamed((part.NamedDamageTypes)Enum.Parse(typeof(part.NamedDamageTypes), "Eng" + i.ToString() + "TotalFailure"));
				}
				
				
				GamePlay.gpLogServer(GamePlay.gpRemotePlayers(), "All hit!\n", null);

				Timeout(15, () => { destroyPlane(aircraft); });

				GamePlay.gpLogServer(GamePlay.gpRemotePlayers(), "Timeout for destroyPlane set!\n", null);
			}
		}
		catch (Exception ex)
		{
			GamePlay.gpLogServer(GamePlay.gpRemotePlayers(), ex.ToString()+"\n", null);
		}
	}

So. If it is possible just add "try catch" exception logging to all mission overrided methods (like "onSomethingHapped"). This will help a lot with searching bugs :D
Intel Core i7 8700K 3.7Ghz, DDR4 16Gb 2666Mhz, Asus Prime Z370-A, ADATA XPG SX8200 240Gb (PCIe Gen3x4), RTX 2060 6Gb

Admin (Reddog)
Site Admin
Posts: 3615
Joined: Fri Jul 11, 2014 1:09 pm

Re: BUG. AI take control of plane and make moves on the grou

Post by Admin (Reddog) »

Ha! Thanks for confirming. That makes me feel better. Clearly something has changed in the code since 4.312.. Bet TF don't even know either. I'd put it on the bug tracker but...whats the point. They won't look at it.

For now I've removed the lines for wings 5-7.

I will look at some error handling.
Image

Post Reply

Return to “SoW 5 General”