/// <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);
            }
        }
예제 #2
0
        protected override bool OnLoad(INIFile ini)
        {
            BriefingDescription = ini.GetValue <string>("Objective", "Briefing.Description");
            BriefingRemarks     = ini.GetValueArray <string>("Objective", "Briefing.Remarks");
            BriefingTask        = ini.GetValue <string>("Objective", "Briefing.Task");

            FGTasking = ini.GetValue <DCSFlightGroupTask>("Objective", "FlightGroup.Tasking");

            IncludeLua = new string[HQTools.EnumCount <ObjectiveScriptRepetition>(), HQTools.EnumCount <ObjectiveScriptScope>()][];
            foreach (ObjectiveScriptRepetition rep in HQTools.EnumValues <ObjectiveScriptRepetition>())
            {
                foreach (ObjectiveScriptScope scope in HQTools.EnumValues <ObjectiveScriptScope>())
                {
                    IncludeLua[(int)rep, (int)scope] = ini.GetValueArray <string>("Include", $"Lua.{rep}.{scope}");
                }
            }
            IncludeOgg = ini.GetValueArray <string>("Include", "Ogg");

            SpawnPointType = ini.GetValueArray <TheaterLocationSpawnPointType>("Objective", "SpawnPoint.Type");
            if (SpawnPointType.Length == 0)
            {
                SpawnPointType = new TheaterLocationSpawnPointType[] { TheaterLocationSpawnPointType.LandMedium, TheaterLocationSpawnPointType.LandLarge }
            }
            ;

            WaypointInaccuracy = ini.GetValue <MinMaxD>("Objective", "Waypoint.Inaccuracy");
            WaypointOnGround   = ini.GetValue <bool>("Objective", "Waypoint.OnGround");

            UnitGroups = new DefinitionObjectiveUnitGroup[HQTools.EnumCount <ObjectiveUnitGroupRole>()];

            foreach (ObjectiveUnitGroupRole role in HQTools.EnumValues <ObjectiveUnitGroupRole>())
            {
                UnitGroups[(int)role] = new DefinitionObjectiveUnitGroup(ini, role.ToString());
            }

            return(true);
        }
    }