Ил-2 Штурмовик: Битва за Британию. Скрипты. Меню смены самолета прямо в игре

Материал из АвиаВики
Перейти к: навигация, поиск

Меню смены самолета прямо в игре

Автор: FG28_Kodiak
Ссылка: 1cpublishing.eu
Архив для скачивания: ...
Действие скрипта: динамическое меню смены самолета

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:

  • Меню вызывается только на земле.
  • Меню показывает только незанятые самолеты (at the moment it shows all, Ki only planes also)
  • Меню показывает самолеты доступные на аэродроме.
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());
   }
}