Beispiel #1
0
    public void OnDragHeadingHandle(BaseEventData e)
    {
        PointerEventData pointerEvent = e as PointerEventData;

        AircraftBase aircraft      = GetComponentInParent <AircraftControllerUI>().MyAircraft;
        Vector3      uiCenterPoint = aircraft.transform.position;
        Ray          mouseRay      = Camera.main.ScreenPointToRay(pointerEvent.position);
        Plane        plane         = new Plane(Vector3.up, uiCenterPoint);
        float        dist          = 0f;

        if (plane.Raycast(mouseRay, out dist))
        {
            Vector3 worldMousePos = mouseRay.origin + (mouseRay.direction * dist);

            Vector2 mouseDir   = new Vector2(worldMousePos.x - uiCenterPoint.x, worldMousePos.z - uiCenterPoint.z).normalized;
            Vector2 worldNorth = new Vector2(0f, 1f);
            Vector2 worldEast  = new Vector2(1f, 0f);

            float angle = Vector2.Angle(worldNorth, mouseDir);
            float dir   = Mathf.Sign(Vector2.Dot(worldEast, mouseDir));

            targetHeadingAngle = angle * dir;

            UpdateHeadingInputHandle();
        }
    }
Beispiel #2
0
    void SetAircraftTargetHeading()
    {
        AircraftBase aircraft = GetComponentInParent <AircraftControllerUI>().MyAircraft;

        float angleDifference = targetHeadingAngle - aircraft.CurrentHeadingInDegrees;

        if (angleDifference < -180)
        {
            angleDifference += 360f;
        }
        else if (angleDifference > 180f)
        {
            angleDifference -= 360f;
        }

        aircraft.TargetHeadingInDegrees = aircraft.CurrentHeadingInDegrees + angleDifference;
    }
Beispiel #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            string aircraftFolder             = Path.Combine(Settings.XPlaneLocation, "ClassicJetSimUtils", "WorldTraffic", "AircraftTypes");
            IEnumerable <string> baseAircraft = Directory.EnumerateFiles(aircraftFolder, "*_BASE.txt");

            rtbAircraft.Clear();
            rtbAircraft.AppendText($"Found {baseAircraft.Count()} 'base' aircraft.\n\n");

            WorldTrafficAircraftType currentType = WorldTrafficAircraftType.Fighter;

            Dictionary <WorldTrafficAircraftType, List <AircraftBase> > aircraft = new Dictionary <WorldTrafficAircraftType, List <AircraftBase> >();

            for (WorldTrafficAircraftType wat = WorldTrafficAircraftType.Fighter; wat < WorldTrafficAircraftType.Max; wat++)
            {
                aircraft[wat] = new List <AircraftBase>();
            }


            foreach (string basecraft in baseAircraft)
            {
                AircraftBase aircraftBase = null;
                string[]     lines        = File.ReadAllLines(basecraft);
                bool         startFound   = false;
                string       nameCache    = "";

                foreach (string line in lines)
                {
                    string[] tokens = line.ToLower().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    if (tokens.Length < 1)
                    {
                        continue;
                    }

                    if (!startFound)
                    {
                        if (tokens[0] != "start")
                        {
                            continue;
                        }
                        else
                        {
                            startFound = true;
                            continue;
                        }
                    }

                    if (tokens.Length < 2)
                    {
                        continue;
                    }

                    switch (tokens[0])
                    {
                    case "type":
                        currentType  = (WorldTrafficAircraftType)int.Parse(tokens[1]);
                        aircraftBase = new AircraftBase
                        {
                            Name = nameCache.ToUpper()
                        };
                        break;

                    case "name":
                        nameCache = tokens[1];
                        break;

                    case "wingspan":
                        aircraftBase.WingSpan = VortexMath.Parse(tokens[1]);
                        break;

                    case "takeoffdistatmtow":
                        aircraftBase.TakeOffDist = VortexMath.Parse(tokens[1]);
                        break;

                    case "landingdist":
                        aircraftBase.LandingDist = VortexMath.Parse(tokens[1]);
                        break;

                    case "minlandingdist":
                        aircraftBase.MinLandingDist = VortexMath.Parse(tokens[1]);
                        break;

                    default:
                        break;
                    }
                }

                aircraft[currentType].Add(aircraftBase);
            }

            for (WorldTrafficAircraftType wat = WorldTrafficAircraftType.Fighter; wat < WorldTrafficAircraftType.Max; wat++)
            {
                if (aircraft[wat].Count > 0)
                {
                    rtbAircraft.AppendText($"World Traffic Type {(int)wat} <{wat}> {aircraft[wat].Count} base aircraft\n");

                    var byCat     = aircraft[wat].GroupBy(ac => SpanToCat(ac.WingSpan));
                    var catCounts = byCat.ToDictionary(ca => ca.Key, ca => ca.ToList().Count);


                    double minLandingDist = aircraft[wat].Min(ac => ac.LandingDist);
                    double maxLandingDist = aircraft[wat].Max(ac => ac.LandingDist);

                    var    withMLD           = aircraft[wat].Where(ac => ac.MinLandingDist > 0);
                    double minMinLandingDist = withMLD.Count() > 0 ? withMLD.Min(ac => ac.MinLandingDist) : 0.0;
                    int    noMinLandingDist  = aircraft[wat].Count(ac => ac.MinLandingDist == 0);
                    double maxMinLandingDist = aircraft[wat].Max(ac => ac.MinLandingDist);

                    double minWingSpan = aircraft[wat].Min(ac => ac.WingSpan);
                    double maxWingSpan = aircraft[wat].Max(ac => ac.WingSpan);

                    double minTakeOff = aircraft[wat].Min(ac => ac.TakeOffDist);
                    double maxTakeOff = aircraft[wat].Max(ac => ac.TakeOffDist);

                    string Name = aircraft[wat].First(ac => ac.WingSpan == maxWingSpan).Name;
                    rtbAircraft.AppendText($" Required Gate/Taxiway Size:  <{SpanToCat(maxWingSpan)}>  ({Name} has wingspan {maxWingSpan,4:0.0})\n");

                    foreach (var group in byCat)
                    {
                        rtbAircraft.AppendText($" Number of cat {group.Key}           : {catCounts[group.Key],5} {string.Join(", ", group)}\n");
                    }

                    Name = aircraft[wat].First(ac => ac.TakeOffDist == minTakeOff).Name;
                    rtbAircraft.AppendText($" Shortest Takeoff possible : {minTakeOff,5} ({Name})\n");
                    Name = aircraft[wat].First(ac => ac.TakeOffDist == maxTakeOff).Name;
                    rtbAircraft.AppendText($" Max Takeoff required      : {maxTakeOff,5} ({Name})\n");

                    Name = aircraft[wat].First(ac => ac.LandingDist == minLandingDist).Name;
                    rtbAircraft.AppendText($" Shortest Landing Distance : {minLandingDist,5} ({Name})\n");
                    Name = aircraft[wat].First(ac => ac.LandingDist == maxLandingDist).Name;
                    rtbAircraft.AppendText($" Longest Landing Distance  : {maxLandingDist,5} ({Name})\n");

                    Name = aircraft[wat].First(ac => ac.MinLandingDist == minMinLandingDist).Name;
                    rtbAircraft.AppendText($" Shortest Min Ldg Dist.    : {minMinLandingDist,5} ({Name})\n");
                    Name = aircraft[wat].First(ac => ac.MinLandingDist == maxMinLandingDist).Name;
                    rtbAircraft.AppendText($" Longest Min Ldg Dist.     : {maxMinLandingDist,5} ({Name})\n");
                    rtbAircraft.AppendText($" Without Min Ldg Dist.     : {noMinLandingDist,5}\n");

                    //rtbAircraft.AppendText($"{wat,-10} {aircraft[wat].Count(),2} {minLandingDist,5} {maxLandingDist,5}  {minMinLandingDist,5}  {maxMinLandingDist,5} {minTakeOff,5} {maxTakeOff,5} {minWingSpan,4:0.0} <{SpanToCat(minWingSpan)}> {maxWingSpan,4:0.0} <{SpanToCat(maxWingSpan)}>\n");
                    rtbAircraft.AppendText("\n");
                }
            }


            //foreach (KeyValuePair<int, List<AircraftBase>> details in aircraft.OrderBy(ac => ac.Key))
            //{
            //    double averageWingSpan = details.Value.Average(a => a.WingSpan);
            //    double minWingSpan = details.Value.Min(a => a.WingSpan);
            //    double maxWingSpan = details.Value.Max(a => a.WingSpan);

            //    rtbAircraft.AppendText($"{details.Key} Wingspan: mn {minWingSpan:0.0} <{SpanToCat(minWingSpan)}> av {averageWingSpan:0.0} mx: {maxWingSpan:0.0} <{SpanToCat(maxWingSpan)}>\n");
            //}

            //foreach (KeyValuePair<int, List<AircraftBase>> details in aircraft.OrderBy(ac => ac.Key))
            //{
            //    double averageLength = details.Value.Average(a => a.TakeOffDist);
            //    double minLength = details.Value.Min(a => a.TakeOffDist);
            //    double maxLength = details.Value.Max(a => a.TakeOffDist);

            //    rtbAircraft.AppendText($"{details.Key} TakeOffDist: mn {minLength:0} av {averageLength:0} mx: {maxLength:0}\n");
            //}

            //foreach (KeyValuePair<int, List<AircraftBase>> details in aircraft.OrderBy(ac => ac.Key))
            //{
            //    double averageLength = details.Value.Average(a => a.LandingDist);
            //    double minLength = details.Value.Min(a => a.LandingDist);
            //    double maxLength = details.Value.Max(a => a.LandingDist);

            //    rtbAircraft.AppendText($"{details.Key} LandingDist: mn {minLength:0} av {averageLength:0} mx: {maxLength:0}\n");
            //}
        }
Beispiel #4
0
    private IEnumerator SpawnUnitLogic(UnitSettings newUnit)
    {
        for (int i = 0; i < currentUnit.amountOfUnit; i++)
        {
            Transform newUnitClone = GetUnit(newUnit);
            newUnitClone.gameObject.layer = (int)newUnit.teamLayer;

            //Debug.Log(newUnitClone.gameObject.layer + " | " + (int)newUnit.teamLayer);

            LayerMask whatAreOurProjectiles;
            LayerMask whatIsTarget;
            float     rand = Mathf.Abs(newUnit.unitPrefab.GetComponent <UnitBase>().BaseAltitude) / 15f;

            switch (newUnit.teamLayer)
            {
            case 10:     // player team
                newUnitClone.position = new Vector2(playerBaseSpawn.position.x, playerBaseSpawn.position.y + Random.Range(-rand, rand));
                //newUnitClone.eulerAngles *= 1;
                newUnitClone.eulerAngles = new Vector3(newUnitClone.eulerAngles.x, 0f, newUnitClone.eulerAngles.z);

                if (newUnitClone.GetComponent <MeshRenderer>())
                {
                    newUnitClone.GetComponent <MeshRenderer>().material = plrMat;
                }

                if (newUnitClone.GetComponentInChildren <Image>())
                {
                    //newUnitClone.GetComponentInChildren<SpriteRenderer>().color = Color.blue;
                    newUnitClone.GetComponentInChildren <Image>().color = new Color32(0x23, 0x36, 0x8C, 132);
                }

                whatAreOurProjectiles = 1 << 8;
                whatIsTarget          = 1 << 9;
                newUnitClone.name     = newUnitClone.name + "Player";
                break;

            case 9:     // enemy team
                newUnitClone.position = new Vector2(enemyBaseSpawn.position.x, enemyBaseSpawn.position.y + Random.Range(-rand, rand));
                //newUnitClone.eulerAngles *= 1;
                newUnitClone.eulerAngles = new Vector3(0f, 180f, newUnitClone.eulerAngles.z);

                if (newUnitClone.GetComponent <MeshRenderer>())
                {
                    newUnitClone.GetComponent <MeshRenderer>().material = enemyMat;
                }

                if (newUnitClone.GetComponentInChildren <Image>())
                {
                    //newUnitClone.GetComponentInChildren<SpriteRenderer>().color = Color.red;
                    //newUnitClone.GetComponentInChildren<SpriteRenderer>().flipY = !newUnitClone.GetComponentInChildren<SpriteRenderer>().flipY;
                    //newUnitClone.GetComponentInChildren<SpriteRenderer>().flipX = !newUnitClone.GetComponentInChildren<SpriteRenderer>().flipX;
                    newUnitClone.GetComponentInChildren <Image>().color = new Color32(0xE3, 0x00, 0x12, 132);
                }

                if (newUnitClone.GetComponentInChildren <SpriteRenderer>())
                {
                    //newUnitClone.GetComponentInChildren<SpriteRenderer>().flipY = !newUnitClone.GetComponentInChildren<SpriteRenderer>().flipY;
                }

                whatAreOurProjectiles = 1 << 11;
                whatIsTarget          = 1 << 10;
                newUnitClone.name     = newUnitClone.name + "Enemy";
                break;

            default:
                Debug.Log("more headaches here we go!!!!");
                yield break;
            }

            #region RETARD = OVERDRIVE LITERALLY
            UnitBase cloneUnit = newUnitClone.GetComponent <UnitBase>();
            cloneUnit.whatAreOurProjectiles = whatAreOurProjectiles;
            cloneUnit.whatIsTarget          = whatIsTarget;
            cloneUnit.transform.position    = new Vector2(newUnitClone.position.x, cloneUnit.BaseAltitude);
            AircraftBase aircraft = cloneUnit as AircraftBase;

            if (aircraft != null)
            {
                soundMngr.PlayEnviroSound(cloneUnit.gameObject, "aircraftflight1", 40f, true);
                aircraft.LoadInAir();
            }
            #endregion

            LoadUnitWeapons(newUnitClone, newUnit.unitPrefab.name);
            yield return(new WaitForSecondsRealtime((float)newUnit.delayBetweenEachSpawn));
        }
    }
Beispiel #5
0
    private void LaunchAircraft()
    {
        if (isLaunchingAircraft)
        {
            //Debug.Log("Launch!");
            if (Time.time > aircraftLaunchTimer)
            {
                //Debug.Log("launching plane");
                Transform planeClone = GetPlane();

                switch (planeClone.gameObject.layer) // temporary before i commit seppuku, retard
                {
                case 10:                             // player team
                                                     //newUnitClone.eulerAngles *= 1;
                    //planeClone.eulerAngles = new Vector3(planeClone.eulerAngles.x, 0f, planeClone.eulerAngles.z);

                    if (planeClone.GetComponentInChildren <Image>())
                    {
                        //planeClone.GetComponentInChildren<SpriteRenderer>().color = Color.blue;
                        planeClone.GetComponentInChildren <Image>().color = new Color32(0x23, 0x36, 0x8C, 132);
                    }

                    whatAreOurProjectiles = 1 << 8;
                    whatIsTarget          = 1 << 9;
                    planeClone.name       = planeClone.name + "Player";
                    break;

                case 9:     // enemy team
                            //newUnitClone.eulerAngles *= 1;
                    planeClone.eulerAngles = new Vector3(0f, 180f, planeClone.eulerAngles.z);

                    if (planeClone.GetComponentInChildren <Image>())
                    {
                        //planeClone.GetComponentInChildren<SpriteRenderer>().color = Color.red;
                        planeClone.GetComponentInChildren <SpriteRenderer>().flipY = !planeClone.GetComponentInChildren <SpriteRenderer>().flipY;
                        planeClone.GetComponentInChildren <SpriteRenderer>().flipX = !planeClone.GetComponentInChildren <SpriteRenderer>().flipX;
                        planeClone.GetComponentInChildren <Image>().color          = new Color32(0xE3, 0x00, 0x12, 132);
                    }

                    if (planeClone.GetComponentInChildren <SpriteRenderer>())
                    {
                        planeClone.GetComponentInChildren <SpriteRenderer>().flipY = !planeClone.GetComponentInChildren <SpriteRenderer>().flipY;
                    }

                    whatAreOurProjectiles = 1 << 11;
                    whatIsTarget          = 1 << 10;
                    planeClone.name       = planeClone.name + "Enemy";
                    break;

                default:
                    Debug.Log("more headaches here we go!!!!");
                    break;
                }

                AircraftBase aircraft = planeClone.GetComponent <AircraftBase>();
                aircraft.whatAreOurProjectiles = whatAreOurProjectiles;
                aircraft.whatIsTarget          = whatIsTarget;
                aircraft.TakeOff();

                //Debug.Log("takeoff");

                aircraftLaunchTimer = Time.time + aircraftLaunchDelay;
            }
            else
            {
                //Debug.Log("on delay");
                return;
            }
        }
        else
        {
            //Debug.Log("wut");
            return;
        }
    }