Fulqrum Publishing Home   |   Register   |   Today Posts   |   Members   |   UserCP   |   Calendar   |   Search   |   FAQ

Go Back   Official Fulqrum Publishing forum > Fulqrum Publishing > IL-2 Sturmovik: Cliffs of Dover > FMB, Mission & Campaign builder Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 09-28-2011, 09:45 AM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default [Script] Changing Airplanes via Communication Menu

At the moment i playing around with the new communication menu system.
Maingoal is making a dynamic menu depending on the current situation.
So i created this script for myself. With it the player can choose his plane via
4.Mission -> 1. Change Airplane
after this the player gets a list of the available Airgroups and then the planes for the selected Airgroup.
At the moment its on a early stage, so there a things i will add in future.
like:
- Menu only available on ground.
- Menu only showing the free planes (at the moment it shows all, Ki only planes also)
- Menu only showing planes available on Airfield.
etc.

So here it is
Code:
using System;
using System.Text;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;


public class Mission : AMission
{

    private Dictionary<Player, int> PlayerAirgroupIndex = new Dictionary<Player, int>();

    internal string ParseAirgroupName(string AirgroupName)
    {
        string[] tempString = null;
        string parsedName="";
        tempString = AirgroupName.Split(':','.');
        
        if (tempString[1].StartsWith("BoB_LW_"))
        {
            StringBuilder b = new StringBuilder(tempString[1]);
            parsedName = b.Replace("BoB_LW_", "").ToString();

            if(parsedName.EndsWith("_I"))
                parsedName = "I./" + b.Replace("_I", "").ToString();
            else if (parsedName.EndsWith("_II"))
                parsedName = "II./" + b.Replace("_II", "").ToString();
            else if (parsedName.EndsWith("_III"))
                parsedName = "III./" + b.Replace("_III", "").ToString();
            else if (parsedName.EndsWith("_IV"))
                parsedName = "IV./" + b.Replace("_IV", "").ToString();
            else if (parsedName.EndsWith("_V"))
                parsedName = "V./" + b.Replace("_V", "").ToString();
            else if (parsedName.EndsWith("_Stab"))
                parsedName = "Stab./" + b.Replace("_Stab", "").ToString();
            
            if (tempString[2].StartsWith("0"))
            {
                if (!parsedName.StartsWith("Stab"))
                    parsedName += ": Stabstaffel";
            }
            else if (tempString[2].StartsWith("1"))
                parsedName += ": 1.Staffel";
            else if (tempString[2].StartsWith("2"))
                parsedName += ": 2.Staffel";
            else if (tempString[2].StartsWith("3"))
                parsedName += ": 3.Staffel";
            else if (tempString[2].StartsWith("4"))
                parsedName += ": 4.Staffel";
            else parsedName += ": Unknown";
        }
        else if (tempString[1].StartsWith("BoB_RAF_"))
        {
            StringBuilder b = new StringBuilder(tempString[1]);

            if (tempString[1].StartsWith("BoB_RAF_F_FatCat"))
                parsedName = b.Replace("BoB_RAF_F_", "(F)  ").ToString();
            else if (tempString[1].StartsWith("BoB_RAF_F_"))
                parsedName = b.Replace("BoB_RAF_F_", "(F)  No. ").ToString();
            else if (tempString[1].StartsWith("BoB_RAF_B_"))
                parsedName = b.Replace("BoB_RAF_B_", "(B)  No. ").ToString();
            if (parsedName.EndsWith("_Early"))
                parsedName = b.Replace("_Early", "").ToString();
            else if (parsedName.EndsWith("_Late"))
                parsedName = b.Replace("_Late", "").ToString();
            if (parsedName.EndsWith("Sqn"))
                parsedName = b.Replace("Sqn", ".Sqn").ToString();
            else if (parsedName.EndsWith("_PL"))
                parsedName = b.Replace("_PL", ".Sqn (PL)").ToString();
            else if (parsedName.EndsWith("_CZ"))
                parsedName = b.Replace("_CZ", ".Sqn (CZ)").ToString();
            else if (parsedName.EndsWith("_RCAF"))
                parsedName = b.Replace("_RCAF", ".Sqn RCAF").ToString();
            
            if (tempString[2].StartsWith("0"))
                parsedName += ": 1";
            else if (tempString[2].StartsWith("1"))
                parsedName += ": 2";
            else if (tempString[2].StartsWith("2"))
                parsedName += ": 3";
            else if (tempString[2].StartsWith("3"))
                parsedName += ": 4";
            else parsedName += ": Unknown";
        }

        return parsedName;
    }

    
    public string[] GetAvailableAirgroups(Player player)
    {
        AiAirGroup[] ownAG = GamePlay.gpAirGroups(player.Army());
        List<string> tempAG = new List<string>();

        if (ownAG != null)
        {
            foreach (AiAirGroup ag in ownAG)
            {
                tempAG.Add(ParseAirgroupName(ag.Name()));
            }

        }
        return tempAG.ToArray();
    }
    
    
    public string[] GetAvailablePlanes(Player player, AiAirGroup airgroup)
    {
        AiActor[] result = null;
        
        List<string> Planes = new List<string>();

        if (airgroup != null)
        {
            result = airgroup.GetItems();
            if (result != null)
            {
                foreach (AiActor actor in result)
                {
                    //Planes.Add(actor.Name());
                    StringBuilder b = new StringBuilder((actor as AiAircraft).InternalTypeName());

                    b.Replace("bob:Aircraft.", "");
                    Planes.Add(b + "  -->  " + (actor as AiAircraft).TypedName());

                }
            }
        }
        return Planes.ToArray();
    }

    public void setAirGroupSubMenu(Player player)
    {
        List<bool> active = new List<bool>();

        foreach (string st in GetAvailableAirgroups(player))
        {
            active.Add(true);
        }

        GamePlay.gpSetOrderMissionMenu(player, true, 1, GetAvailableAirgroups(player), active.ToArray());
    }


    public void setPlaneSubMenu(Player player, AiAirGroup airgroup)
    {
        List<bool> active = new List<bool>();

        foreach (string st in GetAvailablePlanes(player, airgroup))
        {
            active.Add(true);
        }
        GamePlay.gpSetOrderMissionMenu(player, true, 2, GetAvailablePlanes(player, airgroup), active.ToArray());
    }


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

    }
    
    
    private void setMainMenu(Player player)
    {
        GamePlay.gpSetOrderMissionMenu(player, false, 0, new string[] { "Change Aircraft"}, new bool[] { true});
    }

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

        if (ID == 0) // main menu
        {
            switch (menuItemIndex)
            {
                case 1:
                    setAirGroupSubMenu(player);
                    break;
                case 0:
                    setMainMenu(player);
                    break;
            }
        }
        else if (ID == 1)
        { // sub menu

            List<AiAirGroup> Groups = new List<AiAirGroup>();

            foreach (AiAirGroup ag in GamePlay.gpAirGroups(player.Army()))
            {
                Groups.Add(ag);
            }
            if (menuItemIndex == 0) setMainMenu(player);
            else
            {
                PlayerAirgroupIndex.Add(player, menuItemIndex - 1);
                setPlaneSubMenu(player, Groups[menuItemIndex - 1]);
            }
        }
        else if (ID == 2)
        { // sub sub menu

            List<AiAirGroup> Groups = new List<AiAirGroup>();
            List<AiActor> AvailableActor = new List<AiActor>();

            int index;

            if (menuItemIndex == 0) setMainMenu(player);
            else
            {
                foreach (AiAirGroup ag in GamePlay.gpAirGroups(player.Army()))
                {
                    Groups.Add(ag);
                }

                if (PlayerAirgroupIndex.TryGetValue(player, out index))
                {
                    foreach (AiActor ac in Groups[PlayerAirgroupIndex[player]].GetItems())
                    {
                        AvailableActor.Add(ac);
                    }
                }
                player.PlaceEnter(AvailableActor[menuItemIndex-1], 0);
                PlayerAirgroupIndex.Remove(player);
                setMainMenu(player);
            }
        } 
    }

    public override void OnPlayerConnected(Player player)
    {
        setMainMenu(player);
    }


    public override void Inited()
    {
        setMainMenu(GamePlay.gpPlayer());
    }
}
Critics and suggestions are welcome.


@Mods: can you correct the thread-title please, i am not able to do it by myself (Reason for wrong title was nervous finger near Return Key )

Last edited by FG28_Kodiak; 09-28-2011 at 11:11 AM.
Reply With Quote
  #2  
Old 09-29-2011, 06:40 AM
Lookaloft Lookaloft is offline
Approved Member
 
Join Date: Dec 2010
Posts: 38
Default

Hi Kodiak,

How can I combine this script with fearlessfrog's Mission Menu and Ambulance script?

Lookaloft.
Reply With Quote
  #3  
Old 09-29-2011, 07:26 AM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

you must change the

gpSetOrderMissionMenu(player, true, 1, GetAvailableAirgroups(player), active.ToArray());

GamePlay.gpSetOrderMissionMenu(player, true, 2, GetAvailablePlanes(player, airgroup), active.ToArray());

the values are IDs and must be unique.

then add an Entry
to
private void setMainMenu(Player player)
{
GamePlay.gpSetOrderMissionMenu(player, false, 0, new string[] { "Change Aircraft", "Your entry"}, new bool[] { true, true});
}

and in public override void OnOrderMissionMenuSelected(Player player, int ID, int menuItemIndex)
you must integrate the new IDs in the if clauses and copy them to the other script.
Reply With Quote
  #4  
Old 09-29-2011, 01:29 PM
Lookaloft Lookaloft is offline
Approved Member
 
Join Date: Dec 2010
Posts: 38
Default

Thanks Kodiak. will try
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:10 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2007 Fulqrum Publishing. All rights reserved.