Results 1 to 2 of 2

Thread: Trying to change target after locating nearby airgroup

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

    Trying to change target after locating nearby airgroup

    I tried to make my own script for locating an enemy flight within 10km and setting an airgroup to attack it. With the idea to try and use it to stop the non-attacking after attacking once. But whilst it seems to be ok at gettign an enemy flight withn 10km, when they are triggered to attack they just do weird stuff, diving to the floor and flying straight. Can anyone wiser see what I am doing wrong please?

    Code:
    using System;
    using System.IO;
    using maddox.game;
    using maddox.game.world;
    using System.Collections.Generic;
    using System.Collections;
    using System.ComponentModel.Design;
    using System.Diagnostics;
    using maddox.GP;
    
    
    public class Mission : AMission
    {
        AiAirGroup[] AirgroupsAllied;
        AiAirGroup[] AirgroupsAxis;
        private double timerTime = 0;
    
        //airGroup.changeGoalTarget(newAG);
        //if (airGroup.getTask() == AiAirGroupTask.ATTACK_AIR)
    
    
        public override void OnBattleStarted()
        {
    
            base.OnBattleStarted();
    
            MissionNumberListener = -1;
    
    
            // - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    
    
    
        }
    
        public override void OnTickGame()
        {
    
            base.OnTickGame();
    
            if (Time.current() > timerTime)
            {
                timerTime = Time.current() + 30.0; // 30 seconds to next
                AirgroupsAllied = GamePlay.gpAirGroups(1);
                AirgroupsAxis = GamePlay.gpAirGroups(2);
    
                //Console.WriteLine(AirgroupsAllied[0].Name());
                //Console.WriteLine(AirgroupsAxis[0].Name());
    
                foreach (AiAirGroup airGroup in AirgroupsAllied)
                {
                    Console.WriteLine("Allied: " + airGroup.Name());
                    Console.WriteLine("Task is: " + airGroup.getTask());
                    if (airGroup.getTask() == AiAirGroupTask.FLY_WAYPOINT || airGroup.getTask() == AiAirGroupTask.RETURN)
                    {
                        AiAirGroup nearestIs = getNearestEnemyAirgroupWithinTen(airGroup);
                        if (nearestIs != null)
                        {
                            Console.WriteLine("Nearest enemy" + nearestIs.Name());
                            Console.WriteLine("Ping!");
                            airGroup.setTask(AiAirGroupTask.ATTACK_AIR, airGroup);
                            airGroup.changeGoalTarget(nearestIs);
                        }
                        else
                            Console.WriteLine("No nearest enemy");
                    }
                }
                foreach (AiAirGroup airGroup in AirgroupsAxis)
                {
                    Console.WriteLine("Axis: " + airGroup.Name());
                    Console.WriteLine("Task is: " + airGroup.getTask());
                    if (airGroup.getTask() == AiAirGroupTask.FLY_WAYPOINT || airGroup.getTask() == AiAirGroupTask.RETURN)
                    {
                        AiAirGroup nearestIs = getNearestEnemyAirgroupWithinTen(airGroup);
                        if (nearestIs != null)
                        {
                            Console.WriteLine("Nearest enemy" + nearestIs.Name());
                            Console.WriteLine("Ping!");
                            airGroup.setTask(AiAirGroupTask.ATTACK_AIR, airGroup);
                            airGroup.changeGoalTarget(nearestIs);
                        }
                        else
                            Console.WriteLine("No nearest enemy");
                    }
                }
            }
        }
    
     
        public AiAirGroup getNearestEnemyAirgroupWithinTen(AiGroup from)
        {
            AiAirGroup NearestAirgroup = null;
            AiAirGroup[] EnemyAirgroups;
            Point3d StartPos = from.Pos();
    
            EnemyAirgroups = GamePlay.gpAirGroups((from.Army() == 1) ? 2 : 1);
    
            if (EnemyAirgroups != null) // enemy airgroups present
            {
    
                foreach (AiAirGroup airgroup in EnemyAirgroups) // for each of the groups in the array
                {
                    double dist = (airgroup.Pos()).distance(ref StartPos);
                    Console.WriteLine("Distance is" + dist);
    
                    if (dist < 10000.0)
                    {
                        Console.WriteLine("Distance less than 10,000");
                        if (NearestAirgroup != null) // if there is a current nearest airgroup check the current with array airgroup
                        {
                            Console.WriteLine("Existing NearestAirgroup present");
                            if (NearestAirgroup.Pos().distance(ref StartPos) > airgroup.Pos().distance(ref StartPos))
                            {
                                NearestAirgroup = airgroup; // replace the current nearest with array airgroup
                            }
                            else
                            {
                                // keep existing NearestAirgroup
                            }
                        }
                        else
                            Console.WriteLine("Nearest Airgroup is null");
                        NearestAirgroup = airgroup; // set airgroup as nearest because NearestAirgroup was null
    
                    }
                }
            }
    
            return NearestAirgroup;
        }
    }
    Edit: Just to be clear I took some parts from other people's work elsewhere that I couldn't get to work.
    Last edited by Yo-Yo; Apr-11-2023 at 15:10.
    I am Yo-Yo not YoYo (that's someone else)

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

    Re: Trying to change target after locating nearby airgroup

    Actually there's no need. I think I am going to unplug the joystick for a bit. I've spent far too much time recently making missions and banging my head on this wall (again)!

    Hope the sky update comes soon, that'll be nice to see.



    NEEEEEEooooooooooowwwwwwwwwwrrrllllll (That's the sound of a Hurricane roaring past at low level)
    I am Yo-Yo not YoYo (that's someone else)

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
  •