Exemple #1
0
        public override void OnDelayedWorldLoadFinished()
        {
            Overwatch.Log("CleanupSituations");

            Dictionary <Situation, bool> existing = new Dictionary <Situation, bool>();

            List <Situation> removed = new List <Situation>();

            for (int i = Situation.sAllSituations.Count - 1; i >= 0; i--)
            {
                Situation situation = Situation.sAllSituations[i];

                bool remove = false;

                GroupingSituation grouping = situation as GroupingSituation;
                if (grouping != null)
                {
                    if ((grouping.mLeader == null) || (grouping.mLeader.HasBeenDestroyed))
                    {
                        remove = true;
                    }
                    else if (grouping.Participants != null)
                    {
                        foreach (Sim sim in grouping.Participants)
                        {
                            if (sim == null)
                            {
                                grouping.mParticipants.Clear();
                                remove = true;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    HostedSituation hosted = situation as HostedSituation;
                    if (hosted != null)
                    {
                        if ((hosted.Host == null) || (hosted.Host.HasBeenDestroyed))
                        {
                            remove = true;
                        }
                    }
                }

                if (remove)
                {
                    removed.Add(situation);

                    Situation.sAllSituations.RemoveAt(i);

                    Overwatch.Log("Removed Broken Situation: " + situation.GetType());
                }
                else
                {
                    existing[situation] = true;
                }
            }

            foreach (Situation situation in removed)
            {
                try
                {
                    situation.Exit();
                }
                catch (Exception e)
                {
                    Common.DebugException(situation.GetType().ToString(), e);
                }
            }

            foreach (Sim sim in LotManager.Actors)
            {
                if (sim.Autonomy == null)
                {
                    continue;
                }

                if (sim.Autonomy.SituationComponent == null)
                {
                    continue;
                }

                List <Situation> situations = sim.Autonomy.SituationComponent.Situations;
                if (situations == null)
                {
                    continue;
                }

                for (int i = situations.Count - 1; i >= 0; i--)
                {
                    if (existing.ContainsKey(situations[i]))
                    {
                        continue;
                    }

                    Overwatch.Log("Dropped Broken Situation: " + sim.FullName);

                    situations.RemoveAt(i);
                }
            }
        }
Exemple #2
0
        protected override void PrivatePerformAction(bool prompt)
        {
            Overwatch.Log(Name);

            int count = 0;

            for (int i = Situation.sAllSituations.Count - 1; i >= 0; i--)
            {
                Situation situation = Situation.sAllSituations[i];

                try
                {
                    bool tested = false, remove = false;

                    if (situation is FieldTripSituation)
                    {
                        tested = true;
                        remove = true;
                    }

                    if ((tested) && (prompt))
                    {
                        remove = true;
                    }

                    if (remove)
                    {
                        try
                        {
                            situation.Exit();
                        }
                        catch (Exception e)
                        {
                            Common.Exception("Situation: " + situation.GetType().ToString(), e);
                        }

                        foreach (Sim sim in LotManager.Actors)
                        {
                            sim.RemoveRole(situation);
                        }

                        if ((Situation.sAllSituations.Count > i) && (Situation.sAllSituations[i] == situation))
                        {
                            Situation.sAllSituations.RemoveAt(i);
                        }

                        count++;

                        Overwatch.Log("  Removed: " + situation.GetType().ToString());
                    }
                }
                catch (Exception e)
                {
                    Common.Exception("Situation: " + situation.GetType().ToString(), e);
                }
            }

            if ((prompt) || (count > 0))
            {
                Overwatch.AlarmNotify(Common.Localize(GetTitlePrefix() + ":Success", false, new object[] { count }));
            }
        }