Exemple #1
0
        private string CreatePlayerWaypointsLua(DCSMissionWaypoint[] waypoints)
        {
            // FIXME: first and last WP
            // FIXME: EPLRS on first WP?

            string flightPlanLua = "";
            //string baseWPLuaFirst = HQTools.ReadIncludeLuaFile("Mission\\WaypointPlayerTakeoff.lua");
            //string baseWPLuaLast = HQTools.ReadIncludeLuaFile("Mission\\WaypointPlayerLanding.lua");
            string baseWPLua = HQTools.ReadIncludeLuaFile("Mission\\WaypointPlayer.lua");

            for (int i = 0; i < waypoints.Length; i++)
            {
                string wpLua = baseWPLua;
                //if (i == 0) continue; // First waypoint is included in GroupAircraftPlayer.lua
                //// FIXME: Remove - wpLua = baseWPLuaFirst;
                //else if (i == waypoints.Length - 1) wpLua = baseWPLuaLast;
                //else wpLua = baseWPLua;

                HQTools.ReplaceKey(ref wpLua, "Action", waypoints[i].WPAction);
                HQTools.ReplaceKey(ref wpLua, "Altitude", waypoints[i].AltitudeMultiplier);
                HQTools.ReplaceKey(ref wpLua, "AltitudeType", (waypoints[i].AltitudeMultiplier > 0) ? "BARO" : "RADIO");
                HQTools.ReplaceKey(ref wpLua, "AirdromeID", waypoints[i].AirdromeID);
                HQTools.ReplaceKey(ref wpLua, "Name", waypoints[i].Name);
                HQTools.ReplaceKey(ref wpLua, "Speed", waypoints[i].SpeedMultiplier);
                HQTools.ReplaceKey(ref wpLua, "Type", waypoints[i].WPType);
                HQTools.ReplaceKey(ref wpLua, "X", waypoints[i].Coordinates.X);
                HQTools.ReplaceKey(ref wpLua, "Y", waypoints[i].Coordinates.Y);
                HQTools.ReplaceKey(ref wpLua, "Index", i + 2); // Must be last, used by other values

                flightPlanLua += wpLua + "\n";
            }

            return(flightPlanLua);
        }
 /// <summary>
 /// Read values from the mission and make replacements in the Lua file
 /// </summary>
 /// <param name="lua">Lua string</param>
 /// <param name="mission">HQ4DCS mission to use</param>
 private void MakeCommonReplacements(ref string lua, DCSMission mission)
 {
     HQTools.ReplaceKey(ref lua, "UnitNames", CreateUnitNamesTable(mission.UseNATOCallsigns));
     HQTools.ReplaceKey(ref lua, "ObjectiveNames", CreateObjectiveNamesTable(mission));
     HQTools.ReplaceKey(ref lua, "PlayerCoalition", mission.CoalitionPlayer.ToString().ToUpperInvariant());
     HQTools.ReplaceKey(ref lua, "EnemyCoalition", mission.CoalitionEnemy.ToString().ToUpperInvariant());
     HQTools.ReplaceKey(ref lua, "ObjectiveCount", mission.Objectives.Length);
 }
Exemple #3
0
        private string MakeUnitsLua(DCSMission missHQ, Coalition coalition)
        {
            string allUnitsLua = HQTools.ReadIncludeLuaFile("Mission\\CoalitionUnits.lua");

            foreach (UnitCategory uc in Enum.GetValues(typeof(UnitCategory)))
            {
                HQTools.ReplaceKey(ref allUnitsLua, uc.ToString(), MakeUnitsCategoryLua(missHQ, coalition, uc));
            }

            return(allUnitsLua);
        }
        /// <summary>
        /// Generate the script common to all missions at the beginning of the Lua code.
        /// </summary>
        /// <param name="lua">Mission Lua script.</param>
        /// <param name="mission">HQ4DCS mission</param>
        private void GenerateCommonScript(ref string lua, DCSMission mission)
        {
            string scriptLua = "";

            scriptLua += $"hq.objectiveCount = {mission.Objectives.Length}\n";
            scriptLua += $"hq.objectiveLeft = {mission.Objectives.Length}\n";
            scriptLua += $"hq.objectiveNames = {{ \"{string.Join("\", \"", (from DCSMissionObjectiveLocation o in mission.Objectives select o.Name.ToUpperInvariant()))}\" }}\n";
            scriptLua += $"hq.objectiveStatus = {{ {string.Join(", ", Enumerable.Repeat("false", mission.Objectives.Length))} }}\n";

            HQTools.ReplaceKey(ref lua, "ScriptCommon", scriptLua);
        }
Exemple #5
0
        /// <summary>
        /// Generates the content of the Lua file.
        /// </summary>
        /// <param name="missHQ">An HQ4DCS mission.</param>
        /// <returns>The contents of the Lua file.</returns>
        public string MakeLua(DCSMission missHQ)
        {
            string lua = HQTools.ReadIncludeLuaFile("MapResource.lua");

            string resourcesLua = "";

            // Write the names of all included Ogg files into the resources table.
            foreach (string f in missHQ.OggFiles)
            {
                resourcesLua += $"[\"ResKey_Snd_{f.ToLowerInvariant()}\"] = \"{f.ToLowerInvariant()}.ogg\",\n";
            }

            HQTools.ReplaceKey(ref lua, "Resources", resourcesLua);

            return(lua);
        }
        /// <summary>
        /// Generates the content of the Lua file.
        /// </summary>
        /// <param name="missHQ">An HQ4DCS mission.</param>
        /// <returns>The contents of the Lua file.</returns>
        public string MakeLua(DCSMission missHQ)
        {
            string airportsLua = "";

            foreach (int id in missHQ.AirbasesCoalition.Keys)
            {
                string apLua = WarehouseAirportLua;
                HQTools.ReplaceKey(ref apLua, "Index", id);
                HQTools.ReplaceKey(ref apLua, "Coalition", missHQ.AirbasesCoalition[id].ToString().ToUpperInvariant());
                airportsLua += apLua + "\n";
            }

            string lua = WarehouseLua;

            HQTools.ReplaceKey(ref lua, "Airports", airportsLua);

            return(lua);
        }
Exemple #7
0
        private string MakeUnitsCategoryLua(DCSMission missHQ, Coalition coalition, UnitCategory categ)
        {
            string categoryUnitsLua = "";

            DCSMissionUnitGroup[] groups =
                (from g in missHQ.UnitGroups
                 where g.Coalition == coalition && g.Category == categ
                 select g).ToArray();

            int categIndex = 1;

            foreach (DCSMissionUnitGroup g in groups)
            {
                string groupLua = HQTools.ReadIncludeLuaFile($"Mission\\{g.LuaGroup}.lua");

                HQTools.ReplaceKey(ref groupLua, "Units", MakeUnitsUnitsLua(g, missHQ.SinglePlayer)); // Must be first, so full-group replacements come after unit-specific ones

                //if (g.Waypoints.Count > 0)
                //    HQTools.ReplaceKey(ref groupLua, "Waypoints", CreatePlayerWaypointsLua(g.Waypoints)); // Must be first after units

                HQTools.ReplaceKey(ref groupLua, "Name", g.Name);
                HQTools.ReplaceKey(ref groupLua, "GroupID", g.GroupID);
                HQTools.ReplaceKey(ref groupLua, "Frequency", g.RadioFrequency, "F2");
                HQTools.ReplaceKey(ref groupLua, "X", g.Coordinates.X);
                HQTools.ReplaceKey(ref groupLua, "Y", g.Coordinates.Y);
                HQTools.ReplaceKey(ref groupLua, "ObjectiveCenterX", missHQ.ObjectivesCenterPoint.X + HQTools.RandomDouble(-UNIT_RANDOM_WAYPOINT_VARIATION, UNIT_RANDOM_WAYPOINT_VARIATION));
                HQTools.ReplaceKey(ref groupLua, "ObjectiveCenterY", missHQ.ObjectivesCenterPoint.Y + HQTools.RandomDouble(-UNIT_RANDOM_WAYPOINT_VARIATION, UNIT_RANDOM_WAYPOINT_VARIATION));
                HQTools.ReplaceKey(ref groupLua, "Hidden", g.Hidden);
                foreach (DCSMissionUnitGroupCustomValueKey k in g.CustomValues.Keys)
                {
                    if (k.UnitIndex != -1)
                    {
                        continue;                    // Replacement applies only to a single unit, don't apply it to the whole group
                    }
                    HQTools.ReplaceKey(ref groupLua, k.Key, g.CustomValues[k]);
                }
                HQTools.ReplaceKey(ref groupLua, "Index", categIndex); // Must be last, used by other values

                categoryUnitsLua += groupLua + "\r\n";
                categIndex++;
            }

            return(categoryUnitsLua);
        }
        /// <summary>
        /// Copy all included scripts into the mission Lua script.
        /// </summary>
        /// <param name="lua">The mission Lua script.</param>
        /// <param name="mission">A HQ4DCS mission.</param>
        private void CopyMissionLuaScripts(ref string lua, DCSMission mission)
        {
            DefinitionObjective objectiveDef = Library.Instance.GetDefinition <DefinitionObjective>(mission.ObjectiveDefinition);

            if (objectiveDef == null)
            {
                return;
            }

            int i;

            // For each script scope (global, event and timer)...
            foreach (ObjectiveScriptScope scope in HQTools.EnumValues <ObjectiveScriptScope>())
            {
                string scriptLua = "";

                // ...add once every script to include once...
                foreach (string scriptFile in objectiveDef.IncludeLua[(int)ObjectiveScriptRepetition.Once, (int)scope])
                {
                    scriptLua += HQTools.ReadIncludeLuaFile($"Script\\{scriptFile}");
                }

                // ...and add each time for each objective the scripts to include once for each objective
                for (i = 0; i < mission.Objectives.Length; i++)
                {
                    string objectiveScriptLua = "";

                    foreach (string scriptFile in objectiveDef.IncludeLua[(int)ObjectiveScriptRepetition.Each, (int)scope])
                    {
                        objectiveScriptLua += HQTools.ReadIncludeLuaFile($"Script\\{scriptFile}");
                    }

                    HQTools.ReplaceKey(ref objectiveScriptLua, "ObjectiveID", 1 + i);
                    HQTools.ReplaceKey(ref objectiveScriptLua, "GroupID", 1001 + i);

                    scriptLua += objectiveScriptLua + "\n";
                }

                HQTools.ReplaceKey(ref lua, $"Script{scope.ToString()}", scriptLua);
            }
        }
Exemple #9
0
        private string MakeUnitsUnitsLua(DCSMissionUnitGroup group, bool singlePlayer)
        {
            string unitsLua = "";

            for (int i = 0; i < group.UnitCount; i++)
            {
                string singleUnitLua = HQTools.ReadIncludeLuaFile($"Mission\\{group.LuaUnit}.lua");

                DCSSkillLevel skillLevel = group.UnitsSkill;
                if (group.Flags.Contains(UnitGroupFlag.FirstUnitIsClient) && (i == 0))
                {
                    skillLevel = DCSSkillLevel.Client;
                }

                HQTools.ReplaceKey(ref singleUnitLua, "Name", group.Name); // Must be replaced before "Index" because some unit names contain "$INDEX$"
                HQTools.ReplaceKey(ref singleUnitLua, "UnitID", UnitID);
                HQTools.ReplaceKey(ref singleUnitLua, "Unit", group.Units[i]);
                HQTools.ReplaceKey(ref singleUnitLua, "Heading", group.GetUnitHeading(i));
                HQTools.ReplaceKey(ref singleUnitLua, "Skill", skillLevel.ToString());
                HQTools.ReplaceKey(ref singleUnitLua, "X", group.GetUnitCoordinates(i).X);
                HQTools.ReplaceKey(ref singleUnitLua, "Y", group.GetUnitCoordinates(i).Y);
                foreach (DCSMissionUnitGroupCustomValueKey k in group.CustomValues.Keys)
                {
                    if (k.UnitIndex != i)
                    {
                        continue;                   // Replacement does not target this unit, continue
                    }
                    HQTools.ReplaceKey(ref singleUnitLua, k.Key, group.CustomValues[k]);
                }

                HQTools.ReplaceKey(ref singleUnitLua, "Index", i + 1); // Must be last, used by other values

                unitsLua += singleUnitLua + "\r\n";
                UnitID++;
            }

            return(unitsLua);
        }
Exemple #10
0
        /// <summary>
        /// Generates the content of the Lua file.
        /// </summary>
        /// <param name="mission">An HQ4DCS mission.</param>
        /// <returns>The contents of the Lua file.</returns>
        public string MakeLua(DCSMission mission)
        {
            UnitID = 1;

            int i;

            string lua = HQTools.ReadIncludeLuaFile("Mission.lua");

            HQTools.ReplaceKey(ref lua, "MissionName", mission.BriefingName);

            HQTools.ReplaceKey(ref lua, "CenterX", mission.MapCenter.X);
            HQTools.ReplaceKey(ref lua, "CenterY", mission.MapCenter.Y);

            HQTools.ReplaceKey(ref lua, "TheaterID", mission.TheaterDefinition);

            HQTools.ReplaceKey(ref lua, "DateDay", mission.DateDay);
            HQTools.ReplaceKey(ref lua, "DateMonth", (int)mission.DateMonth + 1);
            HQTools.ReplaceKey(ref lua, "DateYear", mission.DateYear);

            HQTools.ReplaceKey(ref lua, "MissionTime", mission.TimeTotalSeconds);

            HQTools.ReplaceKey(ref lua, "WeatherCloudsBase", mission.WeatherCloudBase);
            HQTools.ReplaceKey(ref lua, "WeatherCloudsDensity", mission.WeatherCloudsDensity);
            HQTools.ReplaceKey(ref lua, "WeatherCloudsPrecipitation", (int)mission.WeatherCloudsPrecipitation);
            HQTools.ReplaceKey(ref lua, "WeatherCloudsThickness", mission.WeatherCloudsThickness);
            HQTools.ReplaceKey(ref lua, "WeatherDustDensity", mission.WeatherDustDensity);
            HQTools.ReplaceKey(ref lua, "WeatherDustEnabled", mission.WeatherDustEnabled);
            HQTools.ReplaceKey(ref lua, "WeatherFogEnabled", mission.WeatherTurbulence);
            HQTools.ReplaceKey(ref lua, "WeatherFogThickness", mission.WeatherFogThickness);
            HQTools.ReplaceKey(ref lua, "WeatherFogVisibility", mission.WeatherFogVisibility);
            HQTools.ReplaceKey(ref lua, "WeatherGroundTurbulence", mission.WeatherTurbulence);
            HQTools.ReplaceKey(ref lua, "WeatherQNH", mission.WeatherQNH);
            HQTools.ReplaceKey(ref lua, "WeatherTemperature", mission.WeatherTemperature);
            HQTools.ReplaceKey(ref lua, "WeatherVisibilityDistance", mission.WeatherVisibility);
            for (i = 0; i < 3; i++)
            {
                HQTools.ReplaceKey(ref lua, $"WeatherWind{i + 1}", mission.WeatherWindSpeed[i]);
                HQTools.ReplaceKey(ref lua, $"WeatherWind{i + 1}Dir", mission.WeatherWindDirection[i]);
            }

            foreach (Coalition c in (Coalition[])Enum.GetValues(typeof(Coalition)))
            {
                HQTools.ReplaceKey(ref lua, $"Countries{c}", MakeCountryList(mission, c));
                HQTools.ReplaceKey(ref lua, $"Coalition{c}", MakeCoalitionTable(mission, c));
            }

            HQTools.ReplaceKey(ref lua, "CustomOptions", GetCustomDCSOptionsLua(mission));

            HQTools.ReplaceKey(ref lua, "BriefingDescription", mission.BriefingRawText);

            if (mission.CoalitionPlayer == Coalition.Blue)
            {
                HQTools.ReplaceKey(ref lua, "BriefingPicturesBlue", "[1] = \"ResKey_TitleImage\",");
                HQTools.ReplaceKey(ref lua, "BriefingPicturesRed", "");
            }
            else
            {
                HQTools.ReplaceKey(ref lua, "BriefingPicturesBlue", "");
                HQTools.ReplaceKey(ref lua, "BriefingPicturesRed", "[1] = \"ResKey_TitleImage\",");
            }

            // Red/blue briefings are not used for the moment. The full briefing is located in BriefingDescription.
            HQTools.ReplaceKey(ref lua, "BriefingBlue", "");
            HQTools.ReplaceKey(ref lua, "BriefingRed", "");

            HQTools.ReplaceKey(ref lua, "BullseyeRedX", mission.Bullseye[(int)Coalition.Blue].X);
            HQTools.ReplaceKey(ref lua, "BullseyeRedY", mission.Bullseye[(int)Coalition.Blue].Y);
            HQTools.ReplaceKey(ref lua, "BullseyeBlueX", mission.Bullseye[(int)Coalition.Red].X);
            HQTools.ReplaceKey(ref lua, "BullseyeBlueY", mission.Bullseye[(int)Coalition.Red].Y);

            HQTools.ReplaceKey(ref lua, "FailureEnabled", ""); // TODO: change
            HQTools.ReplaceKey(ref lua, "Waypoints", CreatePlayerWaypointsLua(mission.Waypoints));
            HQTools.ReplaceKey(ref lua, "FinalPlayerWPIndex", mission.Waypoints.Length + 2);

            HQTools.ReplaceKey(ref lua, "CenterX", mission.MapCenter.X);
            HQTools.ReplaceKey(ref lua, "CenterY", mission.MapCenter.Y);

            return(lua);
        }