Example #1
0
        public void CreateAutonomousObjectives()
        {
            foreach (var delayedObjective in DelayedObjectives)
            {
                CoroutineManager.StopCoroutines(delayedObjective.Value);
            }
            DelayedObjectives.Clear();
            Objectives.Clear();
            AddObjective(new AIObjectiveFindSafety(character, this));
            AddObjective(new AIObjectiveIdle(character, this));
            int objectiveCount = Objectives.Count;

            foreach (var automaticOrder in character.Info.Job.Prefab.AutomaticOrders)
            {
                var orderPrefab = Order.GetPrefab(automaticOrder.identifier);
                if (orderPrefab == null)
                {
                    throw new Exception($"Could not find a matching prefab by the identifier: '{automaticOrder.identifier}'");
                }
                var item  = orderPrefab.MustSetTarget ? orderPrefab.GetMatchingItems(character.Submarine, false)?.GetRandom() : null;
                var order = new Order(orderPrefab, item ?? character.CurrentHull as Entity,
                                      item?.Components.FirstOrDefault(ic => ic.GetType() == orderPrefab.ItemComponentType), orderGiver: character);
                if (order == null)
                {
                    continue;
                }
                var objective = CreateObjective(order, automaticOrder.option, character, automaticOrder.priorityModifier);
                if (objective != null && objective.CanBeCompleted)
                {
                    AddObjective(objective, delay: Rand.Value() / 2);
                    objectiveCount++;
                }
            }
            _waitTimer = Math.Max(_waitTimer, Rand.Range(0.5f, 1f) * objectiveCount);
        }
Example #2
0
        private bool Load(INIFile ini)
        {
            BriefingMissionName        = ini.GetValue("Briefing", "MissionName", BriefingMissionName);
            BriefingMissionDescription = ini.GetValue("Briefing", "MissionDescription", BriefingMissionDescription);

            ContextCoalitionBlue   = ini.GetValue("Context", "CoalitionBlue", ContextCoalitionBlue);
            ContextCoalitionRed    = ini.GetValue("Context", "CoalitionRed", ContextCoalitionRed);
            ContextDecade          = ini.GetValue("Context", "Decade", ContextDecade);
            ContextPlayerCoalition = ini.GetValue("Context", "PlayerCoalition", ContextPlayerCoalition);
            ContextTheater         = ini.GetValue("Context", "Theater", ContextTheater);
            ContextSituation       = ini.GetValue("Context", "Situation", ContextSituation);

            EnvironmentSeason        = ini.GetValue("Environment", "Season", EnvironmentSeason);
            EnvironmentTimeOfDay     = ini.GetValue("Environment", "TimeOfDay", EnvironmentTimeOfDay);
            EnvironmentWeatherPreset = ini.GetValue("Environment", "WeatherPreset", EnvironmentWeatherPreset);
            EnvironmentWind          = ini.GetValue("Environment", "Wind", EnvironmentWind);

            FlightPlanObjectiveDistance      = ini.GetValue("FlightPlan", "ObjectiveDistance", FlightPlanObjectiveDistance);
            FlightPlanObjectiveSeperation    = ini.GetValue("FlightPlan", "ObjectiveSeperation", FlightPlanObjectiveSeperation);
            FlightPlanTheaterStartingAirbase = ini.GetValue("FlightPlan", "TheaterStartingAirbase", FlightPlanTheaterStartingAirbase);

            MissionFeatures = ini.GetValueDistinctList <string>("MissionFeatures", "MissionFeatures");

            Mods = ini.GetValueArray <string>("Mods", "Mods").ToList();

            Objectives.Clear();
            foreach (string key in ini.GetTopLevelKeysInSection("Objectives"))
            {
                Objectives.Add(new MissionTemplateObjective(ini, "Objectives", key));
            }

            OptionsFogOfWar = ini.GetValue("Options", "FogOfWar", OptionsFogOfWar);
            OptionsMission  = ini.GetValueDistinctList <string>("Options", "Mission");
            OptionsRealism  = ini.GetValueDistinctList <RealismOption>("Options", "Realism");

            PlayerFlightGroups.Clear();
            foreach (string key in ini.GetTopLevelKeysInSection("PlayerFlightGroups"))
            {
                PlayerFlightGroups.Add(new MissionTemplateFlightGroup(ini, "PlayerFlightGroups", key));
            }

            AircraftPackages.Clear();
            foreach (string key in ini.GetTopLevelKeysInSection("AircraftPackages"))
            {
                AircraftPackages.Add(new MissionTemplatePackage(ini, "AircraftPackages", key));
            }

            SituationEnemySkill      = ini.GetValue("Situation", "EnemySkill", SituationEnemySkill);
            SituationEnemyAirDefense = ini.GetValue("Situation", "EnemyAirDefense", SituationEnemyAirDefense);
            SituationEnemyAirForce   = ini.GetValue("Situation", "EnemyAirForce", SituationEnemyAirForce);

            SituationFriendlySkill      = ini.GetValue("Situation", "FriendlySkill", SituationFriendlySkill);
            SituationFriendlyAirDefense = ini.GetValue("Situation", "FriendlyAirDefense", SituationFriendlyAirDefense);
            SituationFriendlyAirForce   = ini.GetValue("Situation", "FriendlyAirForce", SituationFriendlyAirForce);

            AssignAliases();
            return(true);
        }
Example #3
0
        public void CreateAutonomousObjectives()
        {
            if (character.IsDead)
            {
#if DEBUG
                DebugConsole.ThrowError("Attempted to create autonomous orders for a dead character");
#else
                return;
#endif
            }
            foreach (var delayedObjective in DelayedObjectives)
            {
                CoroutineManager.StopCoroutines(delayedObjective.Value);
            }
            DelayedObjectives.Clear();
            Objectives.Clear();
            FailedAutonomousObjectives = false;
            AddObjective(new AIObjectiveFindSafety(character, this));
            AddObjective(new AIObjectiveIdle(character, this));
            int objectiveCount = Objectives.Count;
            foreach (var autonomousObjective in character.Info.Job.Prefab.AutonomousObjectives)
            {
                var orderPrefab = Order.GetPrefab(autonomousObjective.identifier);
                if (orderPrefab == null)
                {
                    throw new Exception($"Could not find a matching prefab by the identifier: '{autonomousObjective.identifier}'");
                }
                Item item = null;
                if (orderPrefab.MustSetTarget)
                {
                    item = orderPrefab.GetMatchingItems(character.Submarine, mustBelongToPlayerSub: false, requiredTeam: character.Info.TeamID, interactableFor: character)?.GetRandom();
                }
                var order = new Order(orderPrefab, item ?? character.CurrentHull as Entity, orderPrefab.GetTargetItemComponent(item), orderGiver: character);
                if (order == null)
                {
                    continue;
                }
                if (autonomousObjective.ignoreAtOutpost && Level.IsLoadedOutpost && character.TeamID != CharacterTeamType.FriendlyNPC)
                {
                    if (Submarine.MainSub != null && Submarine.MainSub.DockedTo.None(s => s.TeamID != CharacterTeamType.FriendlyNPC && s.TeamID != character.TeamID))
                    {
                        continue;
                    }
                }
                var objective = CreateObjective(order, autonomousObjective.option, character, isAutonomous: true, autonomousObjective.priorityModifier);
                if (objective != null && objective.CanBeCompleted)
                {
                    AddObjective(objective, delay: Rand.Value() / 2);
                    objectiveCount++;
                }
            }
            _waitTimer = Math.Max(_waitTimer, Rand.Range(0.5f, 1f) * objectiveCount);
        }
Example #4
0
        public void CreateAutonomousObjectives()
        {
            foreach (var delayedObjective in DelayedObjectives)
            {
                CoroutineManager.StopCoroutines(delayedObjective.Value);
            }
            DelayedObjectives.Clear();
            Objectives.Clear();
            AddObjective(new AIObjectiveFindSafety(character, this));
            AddObjective(new AIObjectiveIdle(character, this));
            int objectiveCount = Objectives.Count;

            foreach (var automaticOrder in character.Info.Job.Prefab.AutomaticOrders)
            {
                var orderPrefab = Order.GetPrefab(automaticOrder.identifier);
                if (orderPrefab == null)
                {
                    throw new Exception($"Could not find a matching prefab by the identifier: '{automaticOrder.identifier}'");
                }
                // TODO: Similar code is used in CrewManager:815-> DRY
                var matchingItems = orderPrefab.ItemIdentifiers.Any() ?
                                    Item.ItemList.FindAll(it => orderPrefab.ItemIdentifiers.Contains(it.Prefab.Identifier) || it.HasTag(orderPrefab.ItemIdentifiers)) :
                                    Item.ItemList.FindAll(it => it.Components.Any(ic => ic.GetType() == orderPrefab.ItemComponentType));
                matchingItems.RemoveAll(it => it.Submarine != character.Submarine);
                var item  = matchingItems.GetRandom();
                var order = new Order(
                    orderPrefab,
                    item ?? character.CurrentHull as Entity,
                    item?.Components.FirstOrDefault(ic => ic.GetType() == orderPrefab.ItemComponentType),
                    orderGiver: character);
                if (order == null)
                {
                    continue;
                }
                var objective = CreateObjective(order, automaticOrder.option, character, automaticOrder.priorityModifier);
                if (objective != null)
                {
                    AddObjective(objective, delay: Rand.Value() / 2);
                    objectiveCount++;
                }
            }
            _waitTimer = Math.Max(_waitTimer, Rand.Range(0.5f, 1f) * objectiveCount);
        }
Example #5
0
        public void CreateAutonomousObjectives()
        {
            if (character.IsDead)
            {
#if DEBUG
                DebugConsole.ThrowError("Attempted to create autonomous orders for a dead character");
#else
                return;
#endif
            }
            foreach (var delayedObjective in DelayedObjectives)
            {
                CoroutineManager.StopCoroutines(delayedObjective.Value);
            }
            DelayedObjectives.Clear();
            Objectives.Clear();
            AddObjective(new AIObjectiveFindSafety(character, this));
            AddObjective(new AIObjectiveIdle(character, this));
            int objectiveCount = Objectives.Count;
            foreach (var autonomousObjective in character.Info.Job.Prefab.AutonomousObjective)
            {
                var orderPrefab = Order.GetPrefab(autonomousObjective.identifier);
                if (orderPrefab == null)
                {
                    throw new Exception($"Could not find a matching prefab by the identifier: '{autonomousObjective.identifier}'");
                }
                var item  = orderPrefab.MustSetTarget ? orderPrefab.GetMatchingItems(character.Submarine, mustBelongToPlayerSub: false, requiredTeam: character.Info.TeamID)?.GetRandom() : null;
                var order = new Order(orderPrefab, item ?? character.CurrentHull as Entity,
                                      item?.Components.FirstOrDefault(ic => ic.GetType() == orderPrefab.ItemComponentType), orderGiver: character);
                if (order == null)
                {
                    continue;
                }
                var objective = CreateObjective(order, autonomousObjective.option, character, isAutonomous: true, autonomousObjective.priorityModifier);
                if (objective != null && objective.CanBeCompleted)
                {
                    AddObjective(objective, delay: Rand.Value() / 2);
                    objectiveCount++;
                }
            }
            _waitTimer = Math.Max(_waitTimer, Rand.Range(0.5f, 1f) * objectiveCount);
        }
Example #6
0
 public void ClearInfo()
 {
     Objectives.Clear();
     InterestPts.Clear();
     SpawnPts.Clear();
 }