Results 1 to 7 of 7

Thread: ATTACK_AIR Task - How to fix it?

  1. #1
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    ATTACK_AIR Task - How to fix it?

    Is it possible to change the AirGroup task through script to try and fix the refusal of the AI to ever go back to ATTACK_AIR?

    Maybe using this (clutches at straws):

    AiAirGroup.setTask(maddox.game.world.AiAirGroupTas k, maddox.game.world.AiAirGroup)
    I am Yo-Yo not YoYo (that's someone else)

  2. #2
    varrattu
    Guest

    Re: ATTACK_AIR Task - How to fix it?

    Just a guess:

    if (actor is AiAircraft aircraft)
    {
    AiAirGroup airGroup = actor.Group() as AiAirGroup;
    (actor as AiAircraft).AirGroup().setTask(AiAirGroupTask.ATTA CK_AIR, airGroup);
    }
    ~V~

    PS: I wouln't use 'fix'

  3. #3
    Ace
    Join Date
    May 2015
    Location
    Kansas City, Missouri area
    Posts
    515
    Post Thanks / Like
    Total Downloaded
    130.02 MB

    Re: ATTACK_AIR Task - How to fix it?

    Quote Originally Posted by Yo-Yo View Post
    Is it possible to change the AirGroup task through script to try and fix the refusal of the AI to ever go back to ATTACK_AIR?

    Maybe using this (clutches at straws):

    AiAirGroup.setTask(maddox.game.world.AiAirGroupTas k, maddox.game.world.AiAirGroup)
    We've been using the below in our servers for some years. It seems to work (?!) but I wouldn't put any stock in the idea that this is the "right" way to do it etc.

    You just run this every 1 minute or 2 minutes or 4 minutes or however often you want, and it will change the a/c target to a different one at that point, if there is a different nearby logical target, and/or give it a target & make it attack a nearby aircraft if there is a logical one it should be attacking.

    Note that I haven't included the function it calls a couple of times, getRandomNearbyEnemyAirGroup(airGroup, 5000, 1000, 1000);, but you can pretty well guess from the name exactly what it does (it just steps through all a/c in game, just like the routine below does, and looks for enemy airGroups within the given distance. Parameters are XY distance, vertical distance (below) and vertical distance (above)).

    Code:
     public void Stb_changeTargetToDifferentNearbyAircraft()
        {
            try
            {
                if (GamePlay != null && GamePlay.gpArmies() != null && GamePlay.gpArmies().Length > 0)
                {
                    foreach (int army in GamePlay.gpArmies())
                    {
    
                        if (GamePlay.gpAirGroups(army) != null && GamePlay.gpAirGroups(army).Length > 0)
                        {
                            foreach (AiAirGroup airGroup in GamePlay.gpAirGroups(army))
                            {
                                if (airGroup != null && airGroup.GetItems() != null && airGroup.GetItems().Length > 0)
                                {
                                    foreach (AiActor actor in airGroup.GetItems())
                                    {
                                        if (actor != null && actor is AiAircraft)
                                        {
                                            AiAircraft aircraft = actor as AiAircraft;
                                            if (aircraft != null)
                                            {
                                                if (Stb_isAiControlledPlane(aircraft) && aircraft.IsAirborne() &&
                                                    (airGroup.getTask() == AiAirGroupTask.ATTACK_AIR ||
                                                    airGroup.getTask() == AiAirGroupTask.FLY_WAYPOINT ||
                                                    airGroup.getTask() == AiAirGroupTask.DO_NOTHING))
    
                                                {                                               
    
                                                    AiAirGroup newAG = null;
    
                                                    //If they are already attacking we select a (possibly) new target within reasonable distance
                                                    //If they are just flying straight we only select a target if they are basically right on top of it
                                                    //and even a dufus pilot would notice it
                                                    //In theory this leaves CloD's native piloting in place for the most part, but just 'improves' it a bit
                                                    if (airGroup.getTask() == AiAirGroupTask.ATTACK_AIR)
                                                        newAG = getRandomNearbyEnemyAirGroup(airGroup, 5000, 1000, 1000);
                                                    else if (airGroup.getTask() == AiAirGroupTask.FLY_WAYPOINT || airGroup.getTask() == AiAirGroupTask.DO_NOTHING)
                                                        newAG = getRandomNearbyEnemyAirGroup(airGroup, 500, 300, 300);
    
                                                    if (newAG == null) break;
    
                                                    airGroup.setTask(AiAirGroupTask.ATTACK_AIR, newAG);
                                                    airGroup.changeGoalTarget(newAG);
                                                    AiAircraft newAircraft = newAG.GetItems()[0] as AiAircraft;
                                                    string playername = newAG.Name();
                                                    if (aircraft != null && aircraft.Player(0) != null) playername = aircraft.Player(0).Name();
                                                    Console.WriteLine("Change Target to different nearby enemy aircraft: " + actor.Name() + " to " + playername);
    
                                                    break; //each airGroup has only one target so no need to do this more than once.
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { Console.WriteLine("ChangeTargetToDifferentNearbyAircraft: ERROR! " + ex.ToString()); }
        }
    System: Microsoft Windows 10 Pro 64 bit, 10.0.18362 N/A Build 18362, 20,437 MB |
    ASUS GeForce GTX 1060 3GB | Intel Core i5-2500 Quad-Core Processor 3.3 GHz 6 MB Cache LGA 1155 | Intel DB65AL motherboard | ARCTIC Freezer i11 CPU Cooler | SVGA 500 watt power supply | Microsoft Sidewinder 2 Force Feedback joystick

  4. Likes N/A, Yo-Yo, BlacKnight liked this post
  5. #4
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: ATTACK_AIR Task - How to fix it?

    Thanks for all your posts TWC_Flug, they are much appreciated.

    I'm just doing a bit of 'normal' mission/campaign work at the moment, when I've done that I'll go back to my 'mission' to understand scripting and all the stuff you've mentioned/pu tup as examples etc.
    I am Yo-Yo not YoYo (that's someone else)

  6. #5
    Combat pilot
    Join Date
    Aug 2020
    Posts
    181
    Post Thanks / Like
    Total Downloaded
    121.31 MB

    Re: ATTACK_AIR Task - How to fix it?

    Quote Originally Posted by TWC_Flug View Post
    We've been using the below in our servers for some years. It seems to work (?!) but I wouldn't put any stock in the idea that this is the "right" way to do it etc.

    You just run this every 1 minute or 2 minutes or 4 minutes or however often you want, and it will change the a/c target to a different one at that point, if there is a different nearby logical target, and/or give it a target & make it attack a nearby aircraft if there is a logical one it should be attacking.

    Note that I haven't included the function it calls a couple of times, getRandomNearbyEnemyAirGroup(airGroup, 5000, 1000, 1000);, but you can pretty well guess from the name exactly what it does (it just steps through all a/c in game, just like the routine below does, and looks for enemy airGroups within the given distance. Parameters are XY distance, vertical distance (below) and vertical distance (above)).

    Code:
     public void Stb_changeTargetToDifferentNearbyAircraft()
        {
            try
            {
                if (GamePlay != null && GamePlay.gpArmies() != null && GamePlay.gpArmies().Length > 0)
                {
                    foreach (int army in GamePlay.gpArmies())
                    {
    
                        if (GamePlay.gpAirGroups(army) != null && GamePlay.gpAirGroups(army).Length > 0)
                        {
                            foreach (AiAirGroup airGroup in GamePlay.gpAirGroups(army))
                            {
                                if (airGroup != null && airGroup.GetItems() != null && airGroup.GetItems().Length > 0)
                                {
                                    foreach (AiActor actor in airGroup.GetItems())
                                    {
                                        if (actor != null && actor is AiAircraft)
                                        {
                                            AiAircraft aircraft = actor as AiAircraft;
                                            if (aircraft != null)
                                            {
                                                if (Stb_isAiControlledPlane(aircraft) && aircraft.IsAirborne() &&
                                                    (airGroup.getTask() == AiAirGroupTask.ATTACK_AIR ||
                                                    airGroup.getTask() == AiAirGroupTask.FLY_WAYPOINT ||
                                                    airGroup.getTask() == AiAirGroupTask.DO_NOTHING))
    
                                                {                                               
    
                                                    AiAirGroup newAG = null;
    
                                                    //If they are already attacking we select a (possibly) new target within reasonable distance
                                                    //If they are just flying straight we only select a target if they are basically right on top of it
                                                    //and even a dufus pilot would notice it
                                                    //In theory this leaves CloD's native piloting in place for the most part, but just 'improves' it a bit
                                                    if (airGroup.getTask() == AiAirGroupTask.ATTACK_AIR)
                                                        newAG = getRandomNearbyEnemyAirGroup(airGroup, 5000, 1000, 1000);
                                                    else if (airGroup.getTask() == AiAirGroupTask.FLY_WAYPOINT || airGroup.getTask() == AiAirGroupTask.DO_NOTHING)
                                                        newAG = getRandomNearbyEnemyAirGroup(airGroup, 500, 300, 300);
    
                                                    if (newAG == null) break;
    
                                                    airGroup.setTask(AiAirGroupTask.ATTACK_AIR, newAG);
                                                    airGroup.changeGoalTarget(newAG);
                                                    AiAircraft newAircraft = newAG.GetItems()[0] as AiAircraft;
                                                    string playername = newAG.Name();
                                                    if (aircraft != null && aircraft.Player(0) != null) playername = aircraft.Player(0).Name();
                                                    Console.WriteLine("Change Target to different nearby enemy aircraft: " + actor.Name() + " to " + playername);
    
                                                    break; //each airGroup has only one target so no need to do this more than once.
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { Console.WriteLine("ChangeTargetToDifferentNearbyAircraft: ERROR! " + ex.ToString()); }
        }
    Flug trying to use this and getting a error:
    System.Exception: c:\Users\admin\Documents\1C SoftClub\il-2 sturmovik cliffs of dover\missions\Multi\Dogfight\TWC Quake Server\aimissions\RedMission1.cs(46,49): error CS0103: The name 'Stb_isAiControlledPlane' does not exist in the current context
    c:\Users\admin\Documents\1C SoftClub\il-2 sturmovik cliffs of dover\missions\Multi\Dogfight\TWC Quake Server\aimissions\RedMission1.cs(55,61): error CS0103: The name 'getRandomNearbyEnemyAirGroup' does not exist in the current context
    c:\Users\admin\Documents\1C SoftClub\il-2 sturmovik cliffs of dover\missions\Multi\Dogfight\TWC Quake Server\aimissions\RedMission1.cs(57,61): error CS0103: The name 'getRandomNearbyEnemyAirGroup' does not exist in the current context

  7. #6
    Combat pilot
    Join Date
    Oct 2021
    Posts
    113
    Post Thanks / Like
    Total Downloaded
    12.95 MB

    Re: ATTACK_AIR Task - How to fix it?

    Deleted by GANIX.
    Last edited by GANIX; Apr-11-2023 at 13:37.

  8. #7
    Ace
    Join Date
    May 2015
    Location
    Kansas City, Missouri area
    Posts
    515
    Post Thanks / Like
    Total Downloaded
    130.02 MB

    Re: ATTACK_AIR Task - How to fix it?

    Thanks, Ganix, for posting the AIAircraft code. Here is some example code for finding a random nearby enemy airgroup as the new target.

    Note all these are examples only, for illustrative purposes - even here there might be some other procedure it calls (though I don't see one right off), and you might have to fill in gaps in a few different ways.

    Code:
        public AiAirGroup getRandomNearbyEnemyAirGroup(AiAirGroup from, double distance_m, double lowAlt_m, double highAlt_m)
        {
            try
            {
                Random stb_random = new Random();
    
                Point3d startPos = from.Pos();
                List<AiAirGroup> airGroups = getNearbyEnemyAirGroups(from, distance_m, lowAlt_m, highAlt_m);
                if (airGroups == null || airGroups.Count == 0) return null;
                int choice = stb_random.Next(airGroups.Count);
                if (airGroups[choice].Pos().distance(ref startPos) <= distance_m / 2) //We'll somewhat favor airgroups closer to the from airgroup
                    choice = stb_random.Next(airGroups.Count);
                return airGroups[choice];
            }
            catch (Exception ex) { Console.WriteLine("getRandomNearbyEnemyAirGroup ERROR: " + ex.ToString()); return null; }
    
        }
    
        //Gets all nearby enemy airgroup within distance_m (meters) and between alt - lowAlt_m & alt-highAlt_m altitude of the target
        public List<AiAirGroup> getNearbyEnemyAirGroups(AiAirGroup from, double distance_m, double lowAlt_m, double highAlt_m)
        {
            try
            {
                if (GamePlay == null) return null;
                if (from == null) return null;
                List<AiAirGroup> returnAirGroups = new List<AiAirGroup>() { };
                AiAirGroup[] Airgroups;
                Point3d StartPos = from.Pos();
    
                Airgroups = GamePlay.gpAirGroups((from.Army() == 1) ? 2 : 1);
    
                if (Airgroups != null)
                {
                    foreach (AiAirGroup airGroup in Airgroups)
                    {
                        if (airGroup == null || airGroup.GetItems().Length == 0) continue;
                        //AiAircraft a = airGroup.GetItems()[0] as AiAircraft;
    
                        if (airGroup.Pos().z > StartPos.z - lowAlt_m && airGroup.Pos().z < StartPos.z + highAlt_m && airGroup.Pos().distance(ref StartPos) <= distance_m)
                            returnAirGroups.Add(airGroup);
    
                    }
                    return returnAirGroups;
                }
                else
                    return new List<AiAirGroup>() { };
            }
            catch (Exception ex) { Console.WriteLine("getNearbyEnemyAirGroups ERROR: " + ex.ToString()); return new List<AiAirGroup>() { }; }
    
        }
    System: Microsoft Windows 10 Pro 64 bit, 10.0.18362 N/A Build 18362, 20,437 MB |
    ASUS GeForce GTX 1060 3GB | Intel Core i5-2500 Quad-Core Processor 3.3 GHz 6 MB Cache LGA 1155 | Intel DB65AL motherboard | ARCTIC Freezer i11 CPU Cooler | SVGA 500 watt power supply | Microsoft Sidewinder 2 Force Feedback joystick

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •