Exemplo n.º 1
0
 public static void ScriptAddBot(StringBuilder script, int aiNum, int teamNum, int userNum, BotBattleStatus status)
 {
     // AI
     var split = status.aiLib.Split('|');
     script.AppendFormat("  [AI{0}]\n", aiNum);
     script.AppendLine("  {");
     script.AppendFormat("    Name={0};\n", status.Name);
     script.AppendFormat("    ShortName={0};\n", split[0]);
     script.AppendFormat("    Version={0};\n", split.Length > 1 ? split[1] : ""); //having no value is better. Related file: ResolveSkirmishAIKey() at Spring/ExternalAI/IAILibraryManager.cpp 
     script.AppendFormat("    Team={0};\n", teamNum);
     script.AppendFormat("    Host={0};\n", userNum);
     script.AppendLine("    IsFromDemo=0;");
     script.AppendLine("    [Options]");
     script.AppendLine("    {");
     script.AppendLine("    }");
     script.AppendLine("  }\n");
 }
Exemplo n.º 2
0
        /// <summary>
        /// Generates script
        /// </summary>
        /// <param name="playersExport">list of players</param>
        /// <param name="localUser">myself</param>
        /// <param name="loopbackListenPort">listen port for autohost interface</param>
        /// <param name="zkSearchTag">hackish search tag</param>
        /// <param name="startSetup">structure with custom extra data</param>
        /// <returns></returns>
        public string GenerateScript(out List<UserBattleStatus> playersExport,
                                     User localUser,
                                     int loopbackListenPort,
                                     string zkSearchTag,
                                     SpringBattleStartSetup startSetup)
        {
            var previousCulture = Thread.CurrentThread.CurrentCulture;
            try
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

                playersExport = new List<UserBattleStatus>();
                var isHost = localUser.Name == Founder.Name;
                var myUbs = Users.SingleOrDefault(x => x.Name == localUser.Name);
                if (!isHost)
                {
                    var sb = new StringBuilder();
                    sb.AppendLine("[GAME]");
                    sb.AppendLine("{");
                    sb.AppendFormat("HostIP={0};\n", Ip);
                    sb.AppendFormat("HostPort={0};\n", HostPort);
                    sb.AppendLine("IsHost=0;");
                    sb.AppendFormat("MyPlayerName={0};\n", localUser.Name);
                    if (myUbs != null)
                    {
                        if (myUbs.ScriptPassword != null) sb.AppendFormat("MyPasswd={0};\n", myUbs.ScriptPassword);
                    }
                    else
                    {
                        sb.AppendFormat("MyPasswd={0};\n", localUser.Name); // used for mid-game join .. if no userbattlestatus, use own name
                    }
                    sb.AppendLine("}");
                    return sb.ToString();
                }
                else
                {
                    if (mod == null) throw new ApplicationException("Mod not downloaded yet");

                    var script = new StringBuilder();

                    script.AppendLine("[GAME]");
                    script.AppendLine("{");

                    script.AppendFormat("   ZkSearchTag={0};\n", zkSearchTag);
                    script.AppendFormat("  Mapname={0};\n", MapName);

                    if (mod.IsMission) script.AppendFormat("  StartPosType=3;\n");
                    else
                    {
                        if (Details.StartPos == BattleStartPos.Choose) script.AppendFormat("  StartPosType=2;\n");
                        else script.AppendFormat("  StartPosType=3;\n"); // workaround for random/fixed
                        // script.AppendFormat("  StartPosType={0};\n", (int)Details.StartPos);
                    }

                    script.AppendFormat("  GameType={0};\n", ModName);
                    if (ModHash.HasValue)
                        script.AppendFormat("  ModHash={0};\n", ModHash.Value != 0 ? (uint)ModHash.Value : 1);
                            // hack dont set to 1 when dedi srever is patched
                    if (MapHash.HasValue) script.AppendFormat("  MapHash={0};\n", MapHash.Value != 0 ? (uint)MapHash.Value : 1);
                    script.AppendFormat("  AutohostPort={0};\n", loopbackListenPort);
                    script.AppendLine();
                    script.AppendFormat("  HostIP={0};\n", Ip);
                    script.AppendFormat("  HostPort={0};\n", HostPort);
                    script.AppendFormat("  SourcePort={0};\n", 8300);
                    script.AppendFormat("  IsHost=1;\n");
                    script.AppendLine();

                    //script.AppendFormat("  MyPlayerName={0};\n", localUser.Name);

                    var positions = map.Positions != null ? map.Positions.ToList() : new List<StartPos>();
                    if (Details.StartPos == BattleStartPos.Random) positions = positions.Shuffle();

                    List<UserBattleStatus> users;
                    List<BotBattleStatus> bots;

                    if (startSetup != null && startSetup.BalanceTeamsResult != null && startSetup.BalanceTeamsResult.Players != null)
                    {
                        // if there is a balance results as a part of start setup, use values from this (override lobby state)
                        users = new List<UserBattleStatus>(this.Users.Select(x => x.Clone()));
                        bots = new List<BotBattleStatus>(this.Bots.Select(x => (BotBattleStatus)x.Clone()));
                        foreach (var p in startSetup.BalanceTeamsResult.Players)
                        {
                            var us = users.FirstOrDefault(x => x.Name == p.Name);
                            if (us == null)
                            {
                                us = new UserBattleStatus(p.Name, new User() {LobbyID = p.LobbyID}, Password);
                                users.Add(us);
                            }
                            us.TeamNumber = p.TeamID;
                            us.IsSpectator = p.IsSpectator;
                            us.AllyNumber = p.AllyID;

                        }
                        foreach (var p in startSetup.BalanceTeamsResult.Bots)
                        {
                            var bot = bots.FirstOrDefault(x => x.Name == p.BotName);
                            if (bot == null)
                            {
                                bot = new BotBattleStatus(p.BotName, p.Owner, p.BotAI);
                                bots.Add(bot);
                            }
                            bot.AllyNumber = bot.AllyNumber;
                            bot.TeamNumber = bot.TeamNumber;
                        }

                        foreach (var u in users.Where(x => !startSetup.BalanceTeamsResult.Players.Any(y => y.Name == x.Name)))
                        {
                            u.IsSpectator = true;
                        } // spec those not known at the time of balance
                    }
                    else
                    {
                        users = this.Users;
                        bots = this.Bots;
                    }


                    GeneratePlayerSection(playersExport, localUser, startSetup, users, script, positions, bots);

                    return script.ToString();
                }
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = previousCulture;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generates script
        /// </summary>
        /// <param name="playersExport">list of players</param>
        /// <param name="localUser">myself</param>
        /// <param name="loopbackListenPort">listen port for autohost interface</param>
        /// <param name="zkSearchTag">hackish search tag</param>
        /// <param name="startSetup">structure with custom extra data</param>
        /// <returns></returns>
        public string GenerateScript(out List <UserBattleStatus> playersExport,
                                     User localUser,
                                     int loopbackListenPort,
                                     string zkSearchTag,
                                     SpringBattleStartSetup startSetup)
        {
            var previousCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

                playersExport = new List <UserBattleStatus>();
                var isHost = localUser.Name == Founder.Name;
                var myUbs  = Users.SingleOrDefault(x => x.Name == localUser.Name);
                if (!isHost)
                {
                    var sb = new StringBuilder();
                    sb.AppendLine("[GAME]");
                    sb.AppendLine("{");
                    sb.AppendFormat("HostIP={0};\n", Ip);
                    sb.AppendFormat("HostPort={0};\n", HostPort);
                    sb.AppendLine("IsHost=0;");
                    sb.AppendFormat("MyPlayerName={0};\n", localUser.Name);
                    if (myUbs != null)
                    {
                        if (myUbs.ScriptPassword != null)
                        {
                            sb.AppendFormat("MyPasswd={0};\n", myUbs.ScriptPassword);
                        }
                    }
                    else
                    {
                        sb.AppendFormat("MyPasswd={0};\n", localUser.Name); // used for mid-game join .. if no userbattlestatus, use own name
                    }
                    sb.AppendLine("}");
                    return(sb.ToString());
                }
                else
                {
                    if (mod == null)
                    {
                        throw new ApplicationException("Mod not downloaded yet");
                    }

                    var script = new StringBuilder();

                    script.AppendLine("[GAME]");
                    script.AppendLine("{");

                    script.AppendFormat("   ZkSearchTag={0};\n", zkSearchTag);
                    script.AppendFormat("  Mapname={0};\n", MapName);

                    if (mod.IsMission)
                    {
                        script.AppendFormat("  StartPosType=3;\n");
                    }
                    else
                    {
                        if (Details.StartPos == BattleStartPos.Choose)
                        {
                            script.AppendFormat("  StartPosType=2;\n");
                        }
                        else
                        {
                            script.AppendFormat("  StartPosType=3;\n");  // workaround for random/fixed
                        }
                        // script.AppendFormat("  StartPosType={0};\n", (int)Details.StartPos);
                    }

                    script.AppendFormat("  GameType={0};\n", ModName);
                    if (ModHash.HasValue)
                    {
                        script.AppendFormat("  ModHash={0};\n", ModHash.Value != 0 ? (uint)ModHash.Value : 1);
                    }
                    // hack dont set to 1 when dedi srever is patched
                    if (MapHash.HasValue)
                    {
                        script.AppendFormat("  MapHash={0};\n", MapHash.Value != 0 ? (uint)MapHash.Value : 1);
                    }
                    script.AppendFormat("  AutohostPort={0};\n", loopbackListenPort);
                    script.AppendLine();
                    script.AppendFormat("  HostIP={0};\n", Ip);
                    script.AppendFormat("  HostPort={0};\n", HostPort);
                    script.AppendFormat("  SourcePort={0};\n", 8300);
                    script.AppendFormat("  IsHost=1;\n");
                    script.AppendLine();

                    //script.AppendFormat("  MyPlayerName={0};\n", localUser.Name);

                    var positions = map.Positions != null?map.Positions.ToList() : new List <StartPos>();

                    if (Details.StartPos == BattleStartPos.Random)
                    {
                        positions = positions.Shuffle();
                    }

                    List <UserBattleStatus> users;
                    List <BotBattleStatus>  bots;

                    if (startSetup != null && startSetup.BalanceTeamsResult != null && startSetup.BalanceTeamsResult.Players != null)
                    {
                        // if there is a balance results as a part of start setup, use values from this (override lobby state)
                        users = new List <UserBattleStatus>(this.Users.Select(x => x.Clone()));
                        bots  = new List <BotBattleStatus>(this.Bots.Select(x => (BotBattleStatus)x.Clone()));
                        foreach (var p in startSetup.BalanceTeamsResult.Players)
                        {
                            var us = users.FirstOrDefault(x => x.Name == p.Name);
                            if (us == null)
                            {
                                us = new UserBattleStatus(p.Name, new User()
                                {
                                    LobbyID = p.LobbyID
                                }, Password);
                                users.Add(us);
                            }
                            us.TeamNumber  = p.TeamID;
                            us.IsSpectator = p.IsSpectator;
                            us.AllyNumber  = p.AllyID;
                        }
                        foreach (var p in startSetup.BalanceTeamsResult.Bots)
                        {
                            var bot = bots.FirstOrDefault(x => x.Name == p.BotName);
                            if (bot == null)
                            {
                                bot = new BotBattleStatus(p.BotName, p.Owner, p.BotAI);
                                bots.Add(bot);
                            }
                            bot.AllyNumber = bot.AllyNumber;
                            bot.TeamNumber = bot.TeamNumber;
                        }

                        foreach (var u in users.Where(x => !startSetup.BalanceTeamsResult.Players.Any(y => y.Name == x.Name)))
                        {
                            u.IsSpectator = true;
                        } // spec those not known at the time of balance
                    }
                    else
                    {
                        users = this.Users;
                        bots  = this.Bots;
                    }


                    GeneratePlayerSection(playersExport, localUser, startSetup, users, script, positions, bots);

                    return(script.ToString());
                }
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = previousCulture;
            }
        }
Exemplo n.º 4
0
        public static void ScriptAddBot(StringBuilder script, int aiNum, int teamNum, int userNum, BotBattleStatus status)
        {
            // AI
            var split = status.aiLib.Split('|');

            script.AppendFormat("  [AI{0}]\n", aiNum);
            script.AppendLine("  {");
            script.AppendFormat("    Name={0};\n", status.Name);
            script.AppendFormat("    ShortName={0};\n", split[0]);
            script.AppendFormat("    Version={0};\n", split.Length > 1 ? split[1] : ""); //having no value is better. Related file: ResolveSkirmishAIKey() at Spring/ExternalAI/IAILibraryManager.cpp
            script.AppendFormat("    Team={0};\n", teamNum);
            script.AppendFormat("    Host={0};\n", userNum);
            script.AppendLine("    IsFromDemo=0;");
            script.AppendLine("    [Options]");
            script.AppendLine("    {");
            script.AppendLine("    }");
            script.AppendLine("  }\n");
        }
Exemplo n.º 5
0
 void OnAddBot(string[] args)
 {
     if (MyBattle != null && int.Parse(args[0]) == MyBattleID) {
         var bs = new BotBattleStatus(args[1], args[2], Utils.Glue(args, 5));
         bs.SetFrom(int.Parse(args[3]), int.Parse(args[4]));
         MyBattle.Bots.Add(bs);
         BattleBotAdded(this, new EventArgs<BotBattleStatus>(bs));
     }
 }