示例#1
0
 private SqmContentsBase loadSQMFile(string path)
 {
     try
     {
         using (FileStream importStream = new FileStream(sqmFile.ToString(), FileMode.Open))
         {
             SqmImporter     imp         = new SqmImporter();
             SqmContentsBase sqmContents = imp.Import(importStream);
             return(sqmContents);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.InnerException.Message.ToString());
         return(null);
     }
 }
        private string generateSQFUnits(SqmContentsBase sqm, bool opfor, bool blufor, bool independent, bool civilian, bool exclPlayer, bool exclPlayable, bool comments)
        {
            string result = "", opforCode = "", bluforCode = "", independentCode = "", civilianCode = "";

            result += "/******************\n"
                      + " * UNITS & GROUPS *\n"
                      + " ******************/\n\n";

            var groups = (List <SQMImportExport.ArmA3.Vehicle>)sqm.Mission.Groups;

            for (var i = 0; i < groups.Count; i++)
            {
                var content = (List <SQMImportExport.ArmA3.Vehicle>)groups[i].Vehicles;
                var code    = new StringBuilder();

                var groupName = "_group_" + groups[i].Side.ToLower() + "_" + (i + 1);

                if (comments)
                {
                    code.Append("// Begin of Group " + groupName + "\n");
                }

                code.Append(groupName + " = createGroup _" + groups[i].Side.ToLower() + ";\n");

                for (var j = 0; j < content.Count; j++)
                {
                    var unitName = groupName + "_unit_" + (j + 1);

                    if (exclPlayer && content[j].Player == "PLAYER COMMANDER")
                    {
                        if (content.Count >= 1 && content.Count > (j + 1) && content[j].Leader.HasValue && content[j].Leader.Value == 1)
                        {
                            content[j + 1].Leader = 1;
                        }
                    }
                    else if (exclPlayable && content[j].Player == "PLAY CDG")
                    {
                        if (content.Count >= 1 && content.Count > (j + 1) && content[j].Leader.HasValue && content[j].Leader.Value == 1)
                        {
                            content[j + 1].Leader = 1;
                        }
                    }
                    else
                    {
                        if (comments)
                        {
                            code.Append("\t" + "// Begin of Unit " + unitName + "\n");
                        }

                        code.Append("\t" + "if (true) then\n\t{\n");

                        if (_unitsTypeMan.Any(s => s.Equals(content[j].VehicleName, StringComparison.OrdinalIgnoreCase)))
                        {
                            code.Append("\t\t" + unitName + " = " + groupName + " createUnit [\"" + content[j].VehicleName + "\", [" + content[j].Position.X.ToString(CultureInfo.InvariantCulture).Replace(',', '.') + ", " + content[j].Position.Y.ToString(CultureInfo.InvariantCulture).Replace(',', '.') + ", " + (content[j].OffsetY ?? 0).ToString(CultureInfo.InvariantCulture).Replace(',', '.') + "], [], " + (content[j].Placement ?? 0) + ", \"" + (content[j].Special ?? "CAN_COLLIDE") + "\"];\n");
                        }
                        else
                        {
                            code.Append("\t\t" + unitName + " = createVehicle [\"" + content[j].VehicleName + "\"" + ", [" + content[j].Position.X.ToString(CultureInfo.InvariantCulture).Replace(',', '.') + ", " + content[j].Position.Y.ToString(CultureInfo.InvariantCulture).Replace(',', '.') + ", " + (content[j].OffsetY ?? 0).ToString(CultureInfo.InvariantCulture).Replace(',', '.') + "], [], " + (content[j].Placement ?? 0) + ", \"" + (content[j].Special ?? "CAN_COLLIDE") + "\"];\n");
                            code.Append("\t\t" + "createVehicleCrew " + unitName + ";\n");
                            code.Append("\t\t" + "(crew " + unitName + ") joinSilent " + groupName + ";\n");
                        }

                        if (content[j].Azimut.HasValue)
                        {
                            code.Append("\t\t" + unitName + " setDir " + content[j].Azimut.ToString().Replace(',', '.') + ";\n");
                        }
                        if (content[j].Skill.HasValue)
                        {
                            code.Append("\t\t" + unitName + " setUnitAbility " + content[j].Skill.ToString().Replace(',', '.') + ";\n");
                        }
                        if (!string.IsNullOrEmpty(content[j].Rank))
                        {
                            code.Append("\t\t" + unitName + " setRank \"" + content[j].Rank + "\";\n");
                        }
                        if (content[j].Health.HasValue)
                        {
                            code.Append("\t\t" + unitName + " setDamage " + (1 - content[j].Health).ToString().Replace(',', '.') + ";\n");
                        }
                        if (!string.IsNullOrEmpty(content[j].Text))
                        {
                            code.Append("\t\t" + unitName + " setVehicleVarName \"" + content[j].Text + "\";\n");
                        }
                        if (content[j].Leader.HasValue)
                        {
                            code.Append("\t\t" + groupName + " selectLeader " + unitName + ";\n");
                        }

                        code.Append("\t};\n");

                        if (comments)
                        {
                            code.Append("\t// End of Unit " + unitName + "\n");
                        }
                    }
                }

                if (groups[i].Waypoints.Count > 0)
                {
                    code.Append("\t" + "// Waypoints for " + groupName + "\n");
                    for (var k = 0; k < groups[i].Waypoints.Count; k++)
                    {
                        code.Append("\t" + "// Waypoint #" + (k + 1) + "\n");
                        code.Append("\t" + "_wp = " + groupName + " addWaypoint[[" + groups[i].Waypoints[k].Position.X.ToString(CultureInfo.InvariantCulture).Replace(',', '.') + ", " + groups[i].Waypoints[k].Position.Y.ToString(CultureInfo.InvariantCulture).Replace(',', '.') + ", 0], " + (groups[i].Waypoints[k].Placement ?? 0) + ", " + (k + 1) + "];\n");
                        code.Append("\t" + "[" + groupName + ", " + (k + 1) + "] setWaypointBehaviour \"" + (groups[i].Waypoints[k].Combat ?? "UNCHANGED").ToUpper() + "\";\n");
                        code.Append("\t" + "[" + groupName + ", " + (k + 1) + "] setWaypointCombatMode \"" + (groups[i].Waypoints[k].CombatMode ?? "NO CHANGE").ToUpper() + "\";\n");
                        code.Append("\t" + "[" + groupName + ", " + (k + 1) + "] setWaypointCompletionRadius " + (groups[i].Waypoints[k].CompletitionRadius ?? 0) + ";\n");
                        code.Append("\t" + "[" + groupName + ", " + (k + 1) + "] setWaypointFormation \"" + (groups[i].Waypoints[k].Formation ?? "NO CHANGE").ToUpper() + "\";\n");
                        code.Append("\t" + "[" + groupName + ", " + (k + 1) + "] setWaypointSpeed \"" + (groups[i].Waypoints[k].Speed ?? "UNCHANGED").ToUpper() + "\";\n");
                        code.Append("\t" + "[" + groupName + ", " + (k + 1) + "] setWaypointStatements [\"true\", \"\"];\n");
                        code.Append("\t" + "[" + groupName + ", " + (k + 1) + "] setWaypointType \"" + (groups[i].Waypoints[k].Type ?? "MOVE").ToUpper() + "\";\n");
                    }
                }

                if (comments && i < groups.Count - 1)
                {
                    code.Append("// End of Group " + groupName + "\n");
                }
                else if (i == groups.Count - 1)
                {
                    code.Append("// End of Group " + groupName);
                }

                if (i < groups.Count - 1)
                {
                    code.Append("\n");
                }

                switch (groups[i].Side)
                {
                case "WEST":
                    bluforCode += code;
                    break;

                case "EAST":
                    opforCode += code;
                    break;

                case "GUER":
                    independentCode += code;
                    break;

                case "CIV":
                    civilianCode += code;
                    break;
                }
            }

            if (opfor)
            {
                result += opforCode;
            }
            if (blufor)
            {
                result += bluforCode;
            }
            if (independent)
            {
                result += independentCode;
            }
            if (civilian)
            {
                result += civilianCode;
            }

            return(result);
        }