View Single Post
  #59  
Old 04-12-2012, 09:39 AM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

So added sectors to headquarters, for testing i use a simple chat message, at the moment.

Code:
using System;
using System.Collections;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;
using maddox.GP;


public class Mission : AMission
{
    #region class Menu
    
    internal class Menu
    {
        internal class MenuEntry
        {
            internal string MenuName { get; set; }
            internal bool active { get; set; }
        }

        internal List<MenuEntry> menuEntries = new List<MenuEntry>();

        public void AddMenuEntry(string description, bool active)
        {
            MenuEntry NewMenuEntry = new MenuEntry();

            NewMenuEntry.MenuName = description;
            NewMenuEntry.active = active;

            menuEntries.Add(NewMenuEntry);
        }

        public string[] GetMenuDescriptions()
        {
            List<string> Descriptions = new List<string>();

            menuEntries.ForEach(item =>
            {
                Descriptions.Add(item.MenuName);
            });

            return Descriptions.ToArray();
        }

        public bool[] GetActives()
        {
            List<bool> Actives = new List<bool>();

            menuEntries.ForEach(item =>
            {
                Actives.Add(item.active);
            });

            return Actives.ToArray();
        }

        public bool IsValid()
        {
            if (menuEntries == null || menuEntries.Count < 1)
                return false;
            else
                return true;

        }

    }

    #endregion


    internal class Pilot
    {
        public Player player { get; set; }
        public LocalHeadquarters connectedHeadquarter;

        public Pilot(Player player)
        {
            this.player = player;
        }
    }


    internal List<Pilot> PilotsInGame = new List<Pilot>();


    internal class LocalHeadquarters
    {
        public string Name { get; set; }
        public Point2d LocationCoords { get; set; }
        public string Callsign { get; set; }
        private List<string> AttachedSectors = new List<string>();
        
        public LocalHeadquarters(string name, string callsign, double x, double y, params string[] sectors)
        {
            this.Name = name;
            this.Callsign = callsign;
            this.LocationCoords = new Point2d(x, y);

            if (sectors != null)
                AttachedSectors.AddRange(sectors);
        }

        public bool observeSector(string sectorName)
        {
            if (AttachedSectors.Exists(item => item.Equals(sectorName)))
                return true;
            else 
                return false;
        }
    }


    List<LocalHeadquarters> Headquarters = new List<LocalHeadquarters>{
        {new LocalHeadquarters("Luton", "CallSign24", 100.0, 100.0, "A,1","A,2","A,3","B,1","B,2","B,3")},
        {new LocalHeadquarters("RadPoe", "CallSign32", 200.0, 200.0, "C,1","C,2","C,3","D,1","D,2","D,3")},
        {new LocalHeadquarters("Forest", "CallSign15", 300.0, 300.0, "E,1","E,2","E,3","F,1","F,2","F,3")},
        {new LocalHeadquarters("Bearskin", "CallSign5", 400.0, 400.0, "G,1","G,2","G,3")}};



    public void checkSectors(Player player)
    {

        if (PilotsInGame.Exists(item => item.player == player))
        {
            int i = PilotsInGame.FindIndex(item => item.player == player);

            if (PilotsInGame[i].connectedHeadquarter != null)
            {
                if (Headquarters.Exists(hq => hq == PilotsInGame[i].connectedHeadquarter))
                {
                    LocalHeadquarters localHQ = PilotsInGame[i].connectedHeadquarter;
                    AiAirGroup[] EnemyAirgroups = GamePlay.gpAirGroups((player.Army() == 1) ? 2 : 1);

                    if (EnemyAirgroups != null)
                    {
                        bool foundEnemy = false;
                        
                        foreach (AiAirGroup aag in EnemyAirgroups)
                        {
                            string sectorName = GamePlay.gpSectorName(aag.Pos().x, aag.Pos().y);

                            if (localHQ.observeSector(sectorName) && aag.Pos().z > 600.00)
                            {
                                foundEnemy = true;
                                string type = "";

                                if (aag.isAircraftType(AircraftType.Bomber) || aag.isAircraftType(AircraftType.DiveBomber))
                                    type = "Bombers";
                                else if (aag.isAircraftType(AircraftType.Fighter))
                                    type = "Fighters";


                                GamePlay.gpLogServer(new[] { player }, "Enemy {0} in Sector: {1}", new[] { type, sectorName });
                            }
                        }
                        if(!foundEnemy)
                            GamePlay.gpLogServer(new[] { player }, "No Enemy in Range", null);

                    }
                }
            }
        }
    }


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


        if (!PilotsInGame.Exists(item => item.player == player))
        {
            PilotsInGame.Add(new Pilot(player));
        }

        SetMainMenu(player);
    }


    private void connectToHeadquarterSpeech(AiAircraft aircraft, LocalHeadquarters localHQ)
    {
        double initTime = 0.0;

        aircraft.SayToGroup(aircraft.AirGroup(), "Hello_guys");

        Timeout(initTime += 2, () =>
            {
                aircraft.SayToGroup(aircraft.AirGroup(), "This_is");
            });

        Timeout(initTime += 2, () =>
        {
            aircraft.SayToGroup(aircraft.AirGroup(), localHQ.Callsign);
        });

        
        // to is missing as ogg


        Timeout(initTime += 2, () =>
        {
            aircraft.SayToGroup(aircraft.AirGroup(), aircraft.CallSign());
        });

        

        Timeout(initTime += 2, () =>
        {
            aircraft.SayToGroup(aircraft.AirGroup(), "leader__");
        });


    }


    
    public void SetMainMenu(Player player)
    {
        if (player.Army() == 1) // red Side
            GamePlay.gpSetOrderMissionMenu(player, false, 0, new string[] { "Radaroperations" }, new bool[] { true });
        else
            GamePlay.gpSetOrderMissionMenu(player, false, 0, new string[] { "Not Available" }, new bool[] { true });
    }


    public void SetRadarMenu(Player player)
    {
        string headQuarter = "Select Headquarter";
        string connectedTo = "";

        if (PilotsInGame.Exists(item => item.player == player))
        {
            int i = PilotsInGame.FindIndex(item => item.player == player);

            if (PilotsInGame[i].connectedHeadquarter != null)
                connectedTo = string.Format(" (connected: {0})", PilotsInGame[i].connectedHeadquarter.Name);
        }
        headQuarter += connectedTo;

        GamePlay.gpSetOrderMissionMenu(player, true, 100, new string[] { headQuarter, "Get Radar Information" }, new bool[] { true, true });

    }


    public void SetConnectToHeadquarterMenu(Player player)
    {
        Menu NewMenu = new Menu();
        LocalHeadquarters headQuarter = null;

        if (PilotsInGame.Exists(item => item.player == player))
        {
            int i = PilotsInGame.FindIndex(item => item.player == player);
            headQuarter = PilotsInGame[i].connectedHeadquarter;
        }

        Headquarters.ForEach(item =>
        {
            if (headQuarter != null && item == headQuarter)
            {
                NewMenu.AddMenuEntry(item.Name + " *", true);
            }
            else
                NewMenu.AddMenuEntry(item.Name, true);
        });

        if (NewMenu.IsValid())
            GamePlay.gpSetOrderMissionMenu(player, true, 101, NewMenu.GetMenuDescriptions() , NewMenu.GetActives());
        else
            GamePlay.gpSetOrderMissionMenu(player, true, 101, new string[]{ "Not available" }, new bool[]{true});
    }


    public void SetHeadQuarter(Player player, int menuItemIndex)
    {
        if (PilotsInGame.Exists(item => item.player == player))
        {
            int i = PilotsInGame.FindIndex(item => item.player == player);
            PilotsInGame[i].connectedHeadquarter = Headquarters[menuItemIndex-1];
            if (player.Place() != null)
                connectToHeadquarterSpeech((player.Place() as AiAircraft), PilotsInGame[i].connectedHeadquarter);
        }

    }


    public override void OnOrderMissionMenuSelected(Player player, int ID, int menuItemIndex)
    {


        if (ID == 0)
        { // main menu
            if (menuItemIndex == 1)
            {
                SetRadarMenu(player);
            }
            //if (menuItemIndex == 2)
            //{


            //}
            //if (menuItemIndex == 3)
            //{


            //}
        }


        if (ID == 100)
        {
            //Radar Menu
            if (menuItemIndex == 1)
            {
                SetConnectToHeadquarterMenu(player);
            }

            if (menuItemIndex == 2)
            {
                checkSectors(player);
                SetMainMenu(player);
            }
            if (menuItemIndex == 0)
                SetMainMenu(player);
        }

        if (ID == 101)
        {
            //Radar Menu
            if (menuItemIndex == 0)
                SetRadarMenu(player);
            else
            {
                SetHeadQuarter(player, menuItemIndex);
                SetRadarMenu(player);
            }
        }
    }
}
Example mission:
Three planes in sectors (at beginning all in sectors from RadPoe) one figther, one Bomber and a Bf110 below 600m (this should not be 'found' at the beginning)
Code:
[PARTS]
  core.100
  bob.100
[MAIN]
  MAP Land$Online_Cobra_(8x8)
  BattleArea 8704 14465 64640 59199 10000
  TIME 12
  WeatherIndex 0
  CloudsHeight 1000
  BreezeActivity 10
  ThermalActivity 10
  player BoB_RAF_F_FatCat_Early.000
[GlobalWind_0]
  Power 3.000 0.000 0.000
  BottomBound 0.00
  TopBound 1500.00
  GustPower 5
  GustAngle 45
[splines]
[AirGroups]
  BoB_RAF_F_FatCat_Early.01
  BoB_LW_LG2_I.02
  BoB_LW_LG2_I.04
  BoB_LW_LG2_I.11
[BoB_RAF_F_FatCat_Early.01]
  Flight0  1
  Class Aircraft.SpitfireMkIIa
  Formation VIC3
  CallSign 26
  Fuel 100
  Weapons 1
  Skill 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3
  Person0_0 0 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 1
[BoB_RAF_F_FatCat_Early.01_Way]
  TAKEOFF 40128.00 20864.00 0 0
[BoB_LW_LG2_I.02]
  Flight1  11
  Class Aircraft.Bf-109E-4
  Formation FINGERFOUR
  CallSign 26
  Fuel 100
  Weapons 1
  Skill 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3
[BoB_LW_LG2_I.02_Way]
  NORMFLY 31360.00 43456.00 1000.00 300.00
  NORMFLY 31360.00 21696.00 1000.00 300.00
  NORMFLY 22464.00 21440.00 1000.00 300.00
  NORMFLY 22272.00 43008.00 1000.00 300.00
[BoB_LW_LG2_I.04]
  Flight2  21
  Class Aircraft.He-111H-2
  Formation FINGERFOUR
  CallSign 26
  Fuel 100
  Weapons 1
  Skill 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3
[BoB_LW_LG2_I.04_Way]
  NORMFLY 33536.56 29249.82 2500.00 300.00
  NORMFLY 45119.69 29953.77 2500.00 300.00
  NORMFLY 54143.01 37825.18 2500.00 300.00
  NORMFLY 61502.45 49920.27 2500.00 300.00
[BoB_LW_LG2_I.11]
  Flight0  1
  Class Aircraft.Bf-110C-4
  Formation FINGERFOUR
  CallSign 26
  Fuel 100
  Weapons 1
  Skill 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3
[BoB_LW_LG2_I.11_Way]
  NORMFLY 40448.00 44097.40 500.00 300.00
  NORMFLY 32960.00 32129.40 500.00 300.00
  NORMFLY 27008.00 26817.40 1000.00 300.00
  NORMFLY 17664.00 22529.40 1000.00 300.00
[CustomChiefs]
[Stationary]
[Buildings]
[BuildingsLinks]

Last edited by FG28_Kodiak; 04-12-2012 at 09:45 AM.
Reply With Quote