Beispiel #1
0
        protected override bool Allow(Genealogy a, Genealogy b)
        {
            if (Genealogy.IsSibling(a, b)) return true;
            if (Genealogy.IsSibling(b, a)) return true;

            return false;
        }
Beispiel #2
0
        protected override bool Allow(Genealogy a, Genealogy b)
        {
            if (a.IsBloodRelated(b)) return false;

            if (b.Parents.Count > 1) return false;

            return true;
        }
Beispiel #3
0
        protected override bool Allow(Genealogy a, Genealogy b)
        {
            if (Genealogy.IsChild(a, b)) return true;

            if (Genealogy.IsParent(b, a)) return true;

            return false;
        }
Beispiel #4
0
        protected override bool Run(Genealogy a, Genealogy b)
        {
            a.RemoveDirectRelation(b);
            b.RemoveDirectRelation(a);

            a.AddChild(b);
            return true;
        }
Beispiel #5
0
        protected override bool Run(Genealogy a, Genealogy b)
        {
            if (a.Parents.Count > 1) return false;

            a.RemoveDirectRelation(b);
            b.RemoveDirectRelation(a);

            b.AddChild(a);
            return true;
        }
Beispiel #6
0
        protected override bool Allow(Genealogy me)
        {
            if (IsFirst)
            {
                if (me == null) return false;

                if (me.ISiblings.Count == 0) return false;
            }

            return true;
        }
Beispiel #7
0
        protected override bool Allow(Genealogy me)
        {
            if (me == null) return false;

            if (IsFirst)
            {
                if (me.Parents.Count > 1) return false;
            }

            return true;
        }
Beispiel #8
0
 public override bool Test(Sim a, Sim target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
 {
     if ((a.IsFemale || Loader.kAllowMaleNurse) &&
         Genealogy.IsParent(a.Genealogy, target.Genealogy) && target.SimDescription.ToddlerOrBelow)
     {
         if (!Loader.kAllowAdoptiveNursing)
         {
             return(!target.SimDescription.WasAdopted);
         }
         return(true);
     }
     return(false);
 }
Beispiel #9
0
        public static string GetFullName(Genealogy gene)
        {
            string result = gene.Name;

            IMiniSimDescription miniSim = gene.IMiniSimDescription;

            if (miniSim != null)
            {
                result += " (" + miniSim.SimDescriptionId + ")";
            }

            return(result);
        }
Beispiel #10
0
        protected override bool Allow(Genealogy a, Genealogy b)
        {
            if (Genealogy.IsSibling(a, b))
            {
                return(true);
            }
            if (Genealogy.IsSibling(b, a))
            {
                return(true);
            }

            return(false);
        }
Beispiel #11
0
        protected void GetInheritors(List <Genealogy> possibles, float defFraction, Dictionary <SimDescription, float> inheritors)
        {
            List <Genealogy> children = new List <Genealogy>(possibles);

            Dictionary <SimDescription, float> fractions = new Dictionary <SimDescription, float>();

            int index = 0;

            while (index < children.Count)
            {
                Genealogy childGene = children[index];
                index++;

                SimDescription child = Relationships.GetSim(childGene);

                if (child == null)
                {
                    continue;
                }

                float fFraction;
                if (!fractions.TryGetValue(child, out fFraction))
                {
                    fFraction = defFraction;
                }

                // No inheritance for dead children
                if (child.DeathStyle != SimDescription.DeathType.None)
                {
                    foreach (Genealogy grandchildGene in childGene.Children)
                    {
                        SimDescription grandchild = Relationships.GetSim(grandchildGene);
                        if (grandchild == null)
                        {
                            continue;
                        }

                        children.Add(grandchildGene);

                        if (!fractions.ContainsKey(grandchild))
                        {
                            fractions.Add(grandchild, fFraction / childGene.Children.Count);
                        }
                    }
                }
                else if (!inheritors.ContainsKey(child))
                {
                    inheritors.Add(child, fFraction);
                }
            }
        }
Beispiel #12
0
        public static string GetHeader(IMiniSimDescription me)
        {
            SimDescription     simDesc  = me as SimDescription;
            MiniSimDescription miniDesc = me as MiniSimDescription;

            float agingYearsSinceLastAgeTransition = 0;

            if (simDesc != null)
            {
                agingYearsSinceLastAgeTransition = simDesc.AgingYearsSinceLastAgeTransition;
            }
            else if (miniDesc != null)
            {
                agingYearsSinceLastAgeTransition = miniDesc.AgingYearsSinceLastAgeTransition;
            }

            int trueAge          = (int)Aging.GetCurrentAgeInDays(me);
            int daysToTransition = (int)(AgingManager.Singleton.AgingYearsToSimDays(AgingManager.GetMaximumAgingStageLength(me)) - AgingManager.Singleton.AgingYearsToSimDays(agingYearsSinceLastAgeTransition));

            string simName = me.FullName.Trim();

            if (string.IsNullOrEmpty(simName))
            {
                Genealogy genealogy = me.CASGenealogy as Genealogy;
                if (genealogy != null)
                {
                    simName = genealogy.Name + Common.NewLine + me.SimDescriptionId;
                }
            }

            string header = Common.Localize("Status:NameAge", me.IsFemale, new object[] { simName, SelectionCriteria.Age.Item.GetName(me.Age), trueAge, daysToTransition });

            if (me.IsFemale)
            {
                header += Common.NewLine + Common.Localize("Criteria.GenderFemale:MenuName");
            }
            else
            {
                header += Common.NewLine + Common.Localize("Criteria.GenderMale:MenuName");
            }

            if (me.IsAlien)
            {
                header += " " + Common.Localize("Species:Alien");
            }
            else
            {
                header += " " + Common.Localize("Species:" + me.Species);
            }
            return(header);
        }
Beispiel #13
0
        protected override bool Allow(Genealogy a, Genealogy b)
        {
            if (Genealogy.IsChild(b, a))
            {
                return(true);
            }

            if (Genealogy.IsParent(a, b))
            {
                return(true);
            }

            return(false);
        }
Beispiel #14
0
        protected override bool Allow(Genealogy a, Genealogy b)
        {
            if (a.IsBloodRelated(b))
            {
                return(false);
            }

            if (b.Parents.Count > 1)
            {
                return(false);
            }

            return(true);
        }
Beispiel #15
0
        public async Task <EndRoll> instanciaEndRoll(InputData inputData, Genealogy g)
        {
            EndRoll e = new EndRoll();

            e.endDate           = DateTime.Now.Ticks;
            e.productionOrderId = inputData.productionOrderId;
            e.startDate         = _context.EndRoll.Where(x => x.productionOrderId == g.orderId).Max(p => (long?)p.endDate);
            if (e.startDate == null)
            {
                e.startDate = g.startDate;
            }
            e.quantity = inputData.quantity.ToString();
            return(e);
        }
Beispiel #16
0
        protected override bool Allow(MiniSimDescription me, IMiniSimDescription actor)
        {
            Genealogy genealogy = actor.CASGenealogy as Genealogy;

            if (genealogy == null)
            {
                return(false);
            }

            if (me.Genealogy.IsSufficientlyRelatedToRuleOutRomance(genealogy))
            {
                return(false);
            }

            return(true);
        }
Beispiel #17
0
            public void Perform(IMiniSimDescription sim, Logger log, Dictionary <ulong, IMiniSimDescription> lookup)
            {
                if (sim == null)
                {
                    return;
                }

                Genealogy primaryGenealogy = sim.CASGenealogy as Genealogy;

                if (primaryGenealogy == null)
                {
                    return;
                }

                Perform(sim, GetGenealogy(primaryGenealogy), log, lookup);
            }
Beispiel #18
0
        protected override bool Allow(MiniSimDescription me, IMiniSimDescription actor)
        {
            Genealogy genealogy = actor.CASGenealogy as Genealogy;

            if (genealogy == null)
            {
                return(false);
            }

            if (!me.Genealogy.IsBloodRelated(genealogy))
            {
                return(false);
            }

            return(true);
        }
Beispiel #19
0
        public PokerGenealogy(List <int> list)
        {
            _CardGenealogy = Genealogy.Top;
            List           = list;

            IsRoyalStraightFlush();
            IsStraightFlush();
            IsMountain();
            IsStraight();
            IsFourCard();
            IsFullHouse();
            IsFlush();
            IsTripple();
            IsTwoPair();
            IsOnePair();
        }
Beispiel #20
0
        protected override bool PrivateUpdate(ScenarioFrame frame)
        {
            base.PrivateUpdate(frame);

            Genealogy childGenealogy = Sim.Genealogy;

            if ((childGenealogy == null) || (childGenealogy.Parents.Count == 0))
            {
                return(false);
            }

            SimDescription mom = null, dad = null;

            Relationships.GetParents(Sim, out mom, out dad);

            return(PrivatePerform(this, mom, dad, false));
        }
Beispiel #21
0
        protected override bool Allow(Genealogy me)
        {
            if (me == null)
            {
                return(false);
            }

            if (IsFirst)
            {
                if (me.Parents.Count > 1)
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #22
0
        public static SimDescription GetSim(Genealogy genealogy)
        {
            if (genealogy == null)
            {
                return(null);
            }

            try
            {
                return(genealogy.SimDescription);
            }
            catch (Exception e)
            {
                Common.DebugException(genealogy.Name, e);
            }
            return(null);
        }
Beispiel #23
0
        protected override bool Allow(Genealogy me)
        {
            if (IsFirst)
            {
                if (me == null)
                {
                    return(false);
                }

                if (me.Children.Count == 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #24
0
            public bool IsStepRelated(Genealogy a, Genealogy b)
            {
                if (mStepAncestors.ContainsKey(b))
                {
                    return(mStepAncestors[b]);
                }

                if (a.IsStepRelated(b))
                {
                    mStepAncestors.Add(b, true);
                }
                else
                {
                    mStepAncestors.Add(b, false);
                }

                return(mStepAncestors[b]);
            }
Beispiel #25
0
        protected static Genealogy ReconcileGenealogy(Genealogy newGene, Genealogy oldGene)
        {
            if (newGene == null)
            {
                return(oldGene);
            }

            if (oldGene == null)
            {
                return(null);
            }

            ReconcileGenealogy("Parent", Relationships.GetFullName(newGene), newGene.mNaturalParents, oldGene.mNaturalParents);
            ReconcileGenealogy("Child", Relationships.GetFullName(newGene), newGene.mChildren, oldGene.mChildren);
            ReconcileGenealogy("Sibling", Relationships.GetFullName(newGene), newGene.mSiblings, oldGene.mSiblings);

            return(null);
        }
Beispiel #26
0
        protected override bool Allow(SimDescription sim)
        {
            if (sim.YoungAdultOrAbove)
            {
                IncStat("Too Old");
                return(false);
            }

            Genealogy childGenealogy = sim.Genealogy;

            if ((childGenealogy == null) || (childGenealogy.Parents.Count == 0))
            {
                IncStat("No Parents");
                return(false);
            }

            return(base.Allow(sim));
        }
        protected virtual void GetName(T sim, out string firstName, out string lastName)
        {
            string suffix = null;

            /*
             * if (sim is MiniSimDescription)
             * {
             *  suffix = " (M)";
             * }
             */

            if ((sim.FullName == null) || (string.IsNullOrEmpty(sim.FullName.Trim())))
            {
                Genealogy genealogy = sim.CASGenealogy as Genealogy;
                if ((genealogy != null) && (!string.IsNullOrEmpty(genealogy.Name)))
                {
                    firstName = "(" + genealogy.Name + ")";
                    lastName  = "";
                }
                else
                {
                    firstName = "(" + sim.SimDescriptionId.ToString() + ")";
                    lastName  = "";
                }
            }
            else if (mLastFirst)
            {
                if (!string.IsNullOrEmpty(sim.LastName))
                {
                    firstName = sim.LastName + ",";
                }
                else
                {
                    firstName = "";
                }

                lastName = sim.FirstName + suffix;
            }
            else
            {
                firstName = sim.FirstName;
                lastName  = sim.LastName + suffix;
            }
        }
Beispiel #28
0
        protected static bool IsMyAncestor(Genealogy descendant, Genealogy ancestor)
        {
            if ((descendant == null) || (ancestor == null)) return false;

            List<Genealogy> ancestors = new List<Genealogy>(descendant.Parents);

            int index = 0;
            while (index < ancestors.Count)
            {
                Genealogy parent = ancestors[index];
                index++;

                if (parent == ancestor) return true;

                ancestors.AddRange(parent.Parents);
            }

            return false;
        }
Beispiel #29
0
        protected static void SetGenealogy(IMiniSimDescription pureSim, Genealogy genealogy)
        {
            if (genealogy == null)
            {
                return;
            }

            SimDescription sim = pureSim as SimDescription;

            if (sim != null)
            {
                if ((sim.mGenealogy == null) ||
                    (!object.ReferenceEquals(sim.mGenealogy, genealogy)))
                {
                    sim.mGenealogy = genealogy;

                    Overwatch.Log("Replaced SimDesc Genealogy: " + Relationships.GetFullName(pureSim));
                }

                sim.mGenealogy.mSim     = sim;
                sim.mGenealogy.mMiniSim = MiniSimDescription.Find(sim.SimDescriptionId);
            }
            else
            {
                MiniSimDescription miniSim = pureSim as MiniSimDescription;
                if (miniSim != null)
                {
                    if ((miniSim.mGenealogy == null) ||
                        (!object.ReferenceEquals(miniSim.mGenealogy, genealogy)))
                    {
                        miniSim.mGenealogy = genealogy;

                        Overwatch.Log("Replaced MiniSim Genealogy: " + Relationships.GetFullName(pureSim));
                    }

                    if (genealogy.mSim == null)
                    {
                        genealogy.mSim = miniSim.mGenealogy.mSim;
                    }
                    genealogy.mMiniSim = miniSim;
                }
            }
        }
Beispiel #30
0
        protected static bool IsCloselyRelated(Genealogy a, Genealogy b, bool thoroughCheck)
        {
            if ((a == null) || (b == null))
            {
                return(false);
            }

            if (a == b)
            {
                return(true);
            }

            /*
             * if (a.IMiniSimDescription.IsRobot) return false;
             *
             * if (b.IMiniSimDescription.IsRobot) return false;
             */

            return(IsBloodRelated(a, b, thoroughCheck) || IsStepRelated(a, b));
        }
Beispiel #31
0
            public AncestorData(Genealogy sim)
            {
                foreach (Genealogy ancestor in sim.Ancestors)
                {
                    if (mDirectAncestors.ContainsKey(ancestor))
                    {
                        continue;
                    }

                    mDirectAncestors.Add(ancestor, true);

                    foreach (Genealogy sibling in ancestor.Siblings)
                    {
                        if (mSiblingAncestors.ContainsKey(sibling))
                        {
                            continue;
                        }

                        mSiblingAncestors.Add(sibling, true);
                    }
                }
            }
Beispiel #32
0
        protected static void SetGenealogy(IMiniSimDescription pureSim, Genealogy genealogy)
        {
            if (genealogy == null) return;

            SimDescription sim = pureSim as SimDescription;
            if (sim != null)
            {
                if ((sim.mGenealogy == null) || 
                    (!object.ReferenceEquals(sim.mGenealogy, genealogy)))
                {
                    sim.mGenealogy = genealogy;

                    Overwatch.Log("Replaced SimDesc Genealogy: " + Relationships.GetFullName(pureSim));
                }

                sim.mGenealogy.mSim = sim;
                sim.mGenealogy.mMiniSim = MiniSimDescription.Find(sim.SimDescriptionId);
            }
            else
            {
                MiniSimDescription miniSim = pureSim as MiniSimDescription;
                if (miniSim != null)
                {
                    if ((miniSim.mGenealogy == null) || 
                        (!object.ReferenceEquals(miniSim.mGenealogy, genealogy)))
                    {
                        miniSim.mGenealogy = genealogy;

                        Overwatch.Log("Replaced MiniSim Genealogy: " + Relationships.GetFullName(pureSim));
                    }

                    if (genealogy.mSim == null)
                    {
                        genealogy.mSim = miniSim.mGenealogy.mSim;
                    }
                    genealogy.mMiniSim = miniSim;
                }
            }
        }
Beispiel #33
0
 public void Stop()
 {
     //EventCommunicator.SendSimStopEvent();
     //handshakeManagerThread.Abort();
     if (coordinatorThread != null)
     {
         coordinatorThread.Abort();
     }
     if (eCommReceiver != null)
     {
         eCommReceiver.Abort();
     }
     //textChatServerThread.Abort();
     HappeningList.Happenings.Clear();
     TimerQueueClass.Clear();
     IncomingList.Clear();
     Genealogy.Clear();
     StatesForUnits.Clear();
     UnitFacts.CurrentUnitStates.Clear();
     UnitFacts.ClearDMTables();
     UnitFacts.Data.Clear();
     ChatRooms.DropAllRooms();
     VoiceChannels.DropAllChannels();
     WhiteboardRooms.DropAllRooms();
     TimerControl((int)TimerControls.Reset);
     //        ScenarioToQueues.Reset();
     WeaponTable.Clear();
     NetworkTable.Clear();
     SubplatformRecords.Clear();
     Engrams.Clear();
     Scores.Clear();
     DebugLogger.StopLogging();
     NameLists.Clear();
     DecisionMakerType.ClearDMTable();
     SpeciesType.ClearSpeciesTable();
     Metronome.GetInstance().CleanupMetronome();
 }
Beispiel #34
0
        internal static void RevealDocked(string parentID, int time)
        {
            List <string> children = SubplatformRecords.GetDocked(parentID);

            for (int i = 0; i < children.Count; i++)
            {
                string oneChild = children[i];
                //need initaiState and genus (!=kind)
                Reveal_EventType re = new Reveal_EventType(oneChild);



                re.InitialState    = "FullyFunctional";
                re.InitialLocation = null;
                re.Genus           = Genealogy.GetGenus(oneChild);
                re.IsWeapon        = SpeciesType.GetSpecies(UnitFacts.Data[oneChild].Species).IsWeapon;
                re.DockedToParent  = true;

                StateBody thisStartState = StatesForUnits.StateTable[Genealogy.GetBase(re.UnitID)][re.InitialState];
                re.Parameters = thisStartState.Parameters.DeepCopy();
                re.Parameters["ParentObjectID"] = parentID;

                if (time > 1)
                {
                    TimerQueueClass.Add(time, re);
                }
                else
                {
                    TimerQueueClass.SecondarySendBeforeStartup(re);
                }
                Coordinator.debugLogger.Writeline("ScenarioToQueues", "revealEvent for " + re.UnitID, "test");
                if (!re.IsWeapon)
                {
                    RevealDocked(re.UnitID, time);
                }
            }
        }
Beispiel #35
0
        public static IMiniSimDescription GetSim(Genealogy genealogy, Dictionary <ulong, IMiniSimDescription> lookup)
        {
            if (genealogy == null)
            {
                return(null);
            }

            try
            {
                if (genealogy.mSim != null)
                {
                    return(Find(genealogy.mSim.SimDescriptionId, lookup));
                }
                else if (genealogy.mMiniSim != null)
                {
                    return(Find(genealogy.mMiniSim.SimDescriptionId, lookup));
                }
            }
            catch (Exception e)
            {
                Common.Exception(genealogy.Name, e);
            }
            return(null);
        }
Beispiel #36
0
        public static string GetFullName(Genealogy gene)
        {
            string result = gene.Name;

            IMiniSimDescription miniSim = gene.IMiniSimDescription;
            if (miniSim != null)
            {
                result += " (" + miniSim.SimDescriptionId + ")";
            }

            return result;
        }
Beispiel #37
0
        protected static bool IsCloselyRelated(Genealogy a, Genealogy b, bool thoroughCheck)
        {
            if ((a == null) || (b == null)) return false;

            if (a == b) return true;

            /*
            if (a.IMiniSimDescription.IsRobot) return false;

            if (b.IMiniSimDescription.IsRobot) return false;
            */

            return (IsBloodRelated(a, b, thoroughCheck) || a.IsStepRelated(b));
        }
Beispiel #38
0
 protected override List<Genealogy> GetGenealogy(Genealogy gene)
 {
     return gene.mNaturalParents;
 }
Beispiel #39
0
 public static bool IsOfDepth(Genealogy firstGenealogy, int maximum)
 {
     return(GetFamilyLevel(firstGenealogy, maximum) >= maximum);
 }
Beispiel #40
0
        public void PerformAction(bool prompt)
        {
            try
            {
                Overwatch.Log("Cleanup Genealogy");

                Dictionary<IMiniSimDescription, IMiniSimDescription> duplicates = new Dictionary<IMiniSimDescription, IMiniSimDescription>();

                Dictionary<ulong, IMiniSimDescription> lookup = new Dictionary<ulong, IMiniSimDescription>();

                Dictionary<IMiniSimDescription,bool> urnstones = new Dictionary<IMiniSimDescription,bool>();

                foreach(SimDescription sim in SimDescription.GetHomelessSimDescriptionsFromUrnstones())
                {
                    if (urnstones.ContainsKey(sim)) continue;

                    urnstones.Add(sim, true);
                }

                Dictionary<IGenealogy, bool> allGenealogies = new Dictionary<IGenealogy, bool>();

                List<IGenealogy> geneList = new List<IGenealogy>();

                foreach (KeyValuePair<ulong, List<IMiniSimDescription>> ids in SimListing.AllSims<IMiniSimDescription>(null, true, false))
                {
                    List<IMiniSimDescription> list = ids.Value;

                    foreach (IMiniSimDescription miniSim in list)
                    {
                        if (miniSim.CASGenealogy == null) continue;

                        if (allGenealogies.ContainsKey(miniSim.CASGenealogy)) continue;

                        allGenealogies.Add(miniSim.CASGenealogy, true);

                        geneList.Add(miniSim.CASGenealogy);
                    }

                    IMiniSimDescription choice = null;
                    if (list.Count == 1)
                    {
                        choice = list[0];
                    }
                    else if (list.Count > 1)
                    {
                        List<IMiniSimDescription> choices = new List<IMiniSimDescription>();

                        foreach (IMiniSimDescription miniSim in list)
                        {
                            SimDescription sim = miniSim as SimDescription;
                            if (sim == null) continue;

                            if (sim.Household == Household.ActiveHousehold)
                            {
                                choices.Add(miniSim);
                            }
                        }

                        if (choices.Count >= 1)
                        {
                            choice = choices[0];

                            Overwatch.Log("Doppleganger Active-Inactive (" + list.Count + "): " + Relationships.GetFullName(choice));
                        }
                        else
                        {
                            choices.Clear();
                            foreach (IMiniSimDescription sim in list)
                            {
                                if (urnstones.ContainsKey(sim))
                                {
                                    choices.Add(sim);
                                }
                            }

                            if (choices.Count == 1)
                            {
                                choice = choices[0];

                                Overwatch.Log("Doppleganger Urnstone (" + list.Count + "): " + Relationships.GetFullName(choice));
                            }
                            else
                            {
                                choices.Clear();
                                foreach (IMiniSimDescription sim in list)
                                {
                                    Genealogy genealogy = sim.CASGenealogy as Genealogy;

                                    if ((genealogy != null) && (object.ReferenceEquals(sim, genealogy.mSim)))
                                    {
                                        choices.Add(sim);
                                    }
                                }

                                if (choices.Count == 1)
                                {
                                    choice = choices[0];

                                    Overwatch.Log("Doppleganger Personal Genealogy (" + list.Count + "): " + Relationships.GetFullName(choice));
                                }
                                else
                                {
                                    choices.Clear();

                                    MiniSimDescription miniSim = MiniSimDescription.Find(ids.Key);
                                    if ((miniSim != null) && (miniSim.Genealogy != null) && (miniSim.Genealogy.mSim != null))
                                    {
                                        foreach (IMiniSimDescription sim in list)
                                        {
                                            if (object.ReferenceEquals(sim, miniSim.Genealogy.mSim))
                                            {
                                                choices.Add(sim);
                                            }
                                        }
                                    }

                                    if (choices.Count == 1)
                                    {
                                        choice = choices[0];

                                        Overwatch.Log("Doppleganger MiniSim Genealogy (" + list.Count + "): " + Relationships.GetFullName(choice));
                                    }
                                    else
                                    {
                                        choices.Clear();

                                        int maxLinks = 0;

                                        foreach (IMiniSimDescription sim in list)
                                        {
                                            if (choice == null)
                                            {
                                                choice = sim;
                                            }
                                            else
                                            {
                                                int numLinks = 0;

                                                Genealogy gene = sim.CASGenealogy as Genealogy;
                                                if (gene != null)
                                                {
                                                    if (gene.mNaturalParents != null)
                                                    {
                                                        numLinks += gene.mNaturalParents.Count;
                                                    }

                                                    if (gene.mChildren != null)
                                                    {
                                                        numLinks += gene.mChildren.Count;
                                                    }

                                                    if (gene.mSiblings != null)
                                                    {
                                                        numLinks += gene.mSiblings.Count;
                                                    }

                                                    if (maxLinks < numLinks)
                                                    {
                                                        maxLinks = numLinks;

                                                        choice = sim;
                                                    }
                                                }
                                            }
                                        }

                                        Overwatch.Log("Doppleganger By Link Count (" + list.Count + "): " + Relationships.GetFullName(choice));
                                    }
                                }
                            }
                        }
                    }

                    if (choice != null)
                    {
                        lookup.Add(choice.SimDescriptionId, choice);

                        foreach (IMiniSimDescription sim in list)
                        {
                            if (object.ReferenceEquals(sim, choice)) continue;

                            duplicates.Add(sim, choice);

                            Genealogy genealogy = ReconcileGenealogy(choice.CASGenealogy as Genealogy, sim.CASGenealogy as Genealogy);
                            if (genealogy != null)
                            {
                                SetGenealogy(choice, genealogy);
                            }
                        }
                    }
                }

                int index = 0;
                while (index < geneList.Count)
                {
                    Genealogy genealogy = geneList[index] as Genealogy;
                    index++;

                    if (genealogy == null) continue;

                    AddToList(geneList, allGenealogies, genealogy.mNaturalParents);
                    AddToList(geneList, allGenealogies, genealogy.mChildren);
                    AddToList(geneList, allGenealogies, genealogy.mSiblings);
                }

                Dictionary<string, List<Genealogy>> broken = new Dictionary<string, List<Genealogy>>();

                foreach (IGenealogy iGene in geneList)
                {
                    Genealogy gene = iGene as Genealogy;
                    if (gene == null) continue;

                    if ((gene.mMiniSim == null) && (gene.mSim == null))
                    {
                        if (!string.IsNullOrEmpty(gene.Name))
                        {
                            List<Genealogy> genes;
                            if (!broken.TryGetValue(gene.Name, out genes))
                            {
                                genes = new List<Genealogy>();
                                broken.Add(gene.Name, genes);
                            }

                            genes.Add(gene);
                        }
                    }

                    MiniSimDescription miniSim = gene.mMiniSim as MiniSimDescription;
                    if (miniSim == null) continue;

                    if ((MiniSimDescription.sMiniSims != null) && (!MiniSimDescription.sMiniSims.ContainsKey(miniSim.SimDescriptionId)))
                    {
                        MiniSimDescription.sMiniSims.Add(miniSim.SimDescriptionId, miniSim);

                        if (!lookup.ContainsKey(miniSim.SimDescriptionId))
                        {
                            lookup.Add(miniSim.SimDescriptionId, miniSim);
                        }

                        Overwatch.Log("Genealogy Minisim Added " + Relationships.GetFullName(miniSim));
                    }
                }

                CleanupMiniSimGenealogy(lookup, broken);

                foreach(IMiniSimDescription sim in lookup.Values)
                {
                    try
                    {
                        IMiniSimDescription lookupSim = Relationships.Find(sim.SimDescriptionId, lookup);

                        Genealogy genealogy = null;

                        if (lookupSim != null)
                        {
                            genealogy = lookupSim.CASGenealogy as Genealogy;

                            if ((genealogy != null) && (sim.CASGenealogy != null) && (!object.ReferenceEquals(genealogy, sim.CASGenealogy)))
                            {
                                sim.CASGenealogy = genealogy;

                                Overwatch.Log("Lookup Genealogy Replaced: " + Relationships.GetFullName(sim));
                            }
                        }

                        if (genealogy == null)
                        {
                            genealogy = sim.CASGenealogy as Genealogy;
                        }

                        if (genealogy == null)
                        {
                            MiniSimDescription miniSim = MiniSimDescription.Find(sim.SimDescriptionId);
                            if (miniSim != null)
                            {
                                genealogy = miniSim.mGenealogy;

                                if ((genealogy != null) && (sim.CASGenealogy != null) && (!object.ReferenceEquals(genealogy, sim.CASGenealogy)))
                                {
                                    sim.CASGenealogy = genealogy;

                                    Overwatch.Log("MiniSim Genealogy Replaced: " + Relationships.GetFullName(sim));
                                }
                            }
                        }

                        if (genealogy == null)
                        {
                            SimDescription trueSim = sim as SimDescription;
                            if (trueSim != null)
                            {
                                trueSim.Fixup();

                                genealogy = sim.CASGenealogy as Genealogy;
                                if (genealogy == null)
                                {
                                    Overwatch.Log("No SimDesc Genealogy: " + Relationships.GetFullName(sim));
                                }
                                else
                                {
                                    Overwatch.Log("Genealogy Fixup Performed: " + Relationships.GetFullName(sim));
                                }
                            }
                            else 
                            {
                                MiniSimDescription miniSim = sim as MiniSimDescription;
                                if (miniSim != null)
                                {
                                    // This minisim may be part of a family tree, so must be uncorrupted
                                    genealogy = new Genealogy(miniSim.FullName);

                                    Overwatch.Log("MiniSim Genealogy Created: " + Relationships.GetFullName(sim));
                                }
                                else
                                {
                                    Overwatch.Log("No MiniSim Genealogy: " + Relationships.GetFullName(sim));
                                }
                            }
                        }

                        SetGenealogy(sim, genealogy);
                    }
                    catch (Exception e)
                    {
                        Common.Exception("Phase One: " + Relationships.GetFullName(sim), e);
                    }
                }

                foreach (IMiniSimDescription sim in lookup.Values)
                {
                    try
                    {
                        SimDescription trueSim = sim as SimDescription;
                        if (trueSim != null)
                        {
                            MiniSimDescription miniSim = MiniSimDescription.Find(trueSim.SimDescriptionId);
                            if (miniSim != null)
                            {
                                List<MiniRelationship> relationships = new List<MiniRelationship>(miniSim.MiniRelationships);
                                foreach (MiniRelationship relationship in relationships)
                                {
                                    IMiniSimDescription otherSim = MiniSimDescription.Find(relationship.GetOtherSimDescriptionId(sim));
                                    if (otherSim == null)
                                    {
                                        miniSim.mMiniRelationships.Remove(relationship);
                                    }
                                    else
                                    {
                                        Genealogy gene = otherSim.CASGenealogy as Genealogy;
                                        if (gene == null)
                                        {
                                            miniSim.mMiniRelationships.Remove(relationship);
                                        }
                                    }
                                }
                            }

                            Dictionary<ulong, bool> existingRelations = new Dictionary<ulong, bool>();

                            Dictionary<SimDescription, Relationship> oldRelations;
                            if (Relationship.sAllRelationships.TryGetValue(trueSim, out oldRelations))
                            {
                                Dictionary<SimDescription, Relationship> newRelations = new Dictionary<SimDescription, Relationship>();

                                foreach (KeyValuePair<SimDescription, Relationship> relation in new Dictionary<SimDescription, Relationship>(oldRelations))
                                {
                                    IMiniSimDescription townSim;
                                    if (lookup.TryGetValue(relation.Key.SimDescriptionId, out townSim))
                                    {
                                        if (!object.ReferenceEquals(townSim, relation.Key))
                                        {
                                            Overwatch.Log(Relationships.GetFullName(sim) + " Dropped bad relation for " + Relationships.GetFullName(relation.Key));

                                            Relationships.SafeRemoveRelationship(relation.Value);
                                            continue;
                                        }
                                    }

                                    if (existingRelations.ContainsKey(relation.Key.SimDescriptionId))
                                    {
                                        Overwatch.Log(Relationships.GetFullName(sim) + " Dropped duplicate relation for " + Relationships.GetFullName(relation.Key));

                                        Relationships.SafeRemoveRelationship(relation.Value);
                                        continue;
                                    }

                                    existingRelations.Add(relation.Key.SimDescriptionId, true);

                                    Relationships.RepairRelationship(relation.Value, Overwatch.Log);

                                    newRelations.Add(relation.Key, relation.Value);
                                }

                                Relationship.sAllRelationships[trueSim] = newRelations;
                            }

                            /*
                            MiniSimDescription miniDesc = MiniSimDescription.Find(trueSim.SimDescriptionId);
                            if (miniDesc != null)
                            {
                                for (int i = miniDesc.mMiniRelationships.Count - 1; i >= 0; i--)
                                {
                                    MiniRelationship relation = miniDesc.mMiniRelationships[i];

                                    if (existingRelations.ContainsKey(relation.SimDescriptionId))
                                    {
                                        miniDesc.mMiniRelationships.RemoveAt(i);

                                        Overwatch.Log(GetFullName(trueSim) + " Dropped duplicate mini relation");
                                    }
                                }
                            }
                            */

                            RepairMissingPartner(trueSim);

                            // Legacy repair for an issue with an earlier Phase of Overwatch
                            List<Relationship> relations = new List<Relationship>(Relationship.GetRelationships(trueSim));
                            foreach (Relationship relation in relations)
                            {
                                if ((relation.LTR.HasInteractionBit(LongTermRelationship.InteractionBits.Divorce)) ||
                                    (relation.LTR.HasInteractionBit(LongTermRelationship.InteractionBits.BreakUp)) ||
                                    (relation.LTR.HasInteractionBit(LongTermRelationship.InteractionBits.BreakEngagement)) ||
                                    (relation.LTR.HasInteractionBit(LongTermRelationship.InteractionBits.Marry)) ||
                                    (relation.LTR.HasInteractionBit(LongTermRelationship.InteractionBits.Propose)) ||
                                    (relation.LTR.HasInteractionBit(LongTermRelationship.InteractionBits.MakeCommitment)))
                                {
                                    relation.LTR.AddInteractionBit(LongTermRelationship.InteractionBits.HaveBeenPartners);
                                }
                            }
                        }

                        Genealogy genealogy = sim.CASGenealogy as Genealogy;
                        if (genealogy != null)
                        {
                            genealogy.ClearDerivedData();

                            new Relationships.RepairParents().Perform(sim, Overwatch.Log, lookup);
                            new Relationships.RepairChildren().Perform(sim, Overwatch.Log, lookup);
                            new Relationships.RepairSiblings().Perform(sim, Overwatch.Log, lookup);

                            RepairSpouse(sim, lookup);

                            if ((sim.IsMarried) && (genealogy.mPartnerType != PartnerType.Marriage))
                            {
                                genealogy.mPartnerType = PartnerType.Marriage;

                                if (genealogy.Spouse != null)
                                {
                                    genealogy.Spouse.mPartnerType = PartnerType.Marriage;
                                }

                                Overwatch.Log(Relationships.GetFullName(sim) + " PartnerType Corrected");
                            }
                        }

                        RepairMiniSim(trueSim);
                    }
                    catch (Exception e)
                    {
                        Common.Exception("Phase Two: " + Relationships.GetFullName(sim), e);
                    }
                }

                CleanupMiniSims(lookup);

                // Must be performed after repairing the genealogy as the mSim is wiped from the genealogy during deletion
                foreach (KeyValuePair<IMiniSimDescription, IMiniSimDescription> duplicate in duplicates)
                {
                    CustomAnnihilation(duplicate.Key as SimDescription, duplicate.Value as SimDescription);
                }
            }
            catch (Exception e)
            {
                Common.Exception(Name, e);
            }
        }
Beispiel #41
0
 protected static bool Contains(List<Genealogy> ths, Genealogy me)
 {
     return (ths.Find((e) => { return object.ReferenceEquals(e, me); }) != null);
 }
Beispiel #42
0
 protected override List<Genealogy> GetReverseGenealogy(Genealogy gene)
 {
     return gene.Parents;
 }
Beispiel #43
0
            public CreationProtection(SimDescription sim, Sim createdSim, bool performLoadFixup, bool performSelectable, bool performUnselectable)
            {
                try
                {
                    mSim = sim;

                    Corrections.RemoveFreeStuffAlarm(sim);

                    // Stops an issue in "GrantFutureObjects" regarding the use of sIsChangingWorlds=true
                    mWasFutureSim = sim.TraitManager.HasElement(TraitNames.FutureSim);
                    sim.TraitManager.RemoveElement(TraitNames.FutureSim);

                    if (SimTypes.IsSelectable(mSim))
                    {
                        Corrections.CleanupBrokenSkills(mSim, null);
                    }

                    if (OpportunityTrackerModel.gSingleton != null)
                    {
                        mOpportunitiesChanged = OpportunityTrackerModel.gSingleton.OpportunitiesChanged;
                        OpportunityTrackerModel.gSingleton.OpportunitiesChanged = null;
                    }

                    if (mSim.TraitChipManager != null)
                    {
                        mChips = mSim.TraitChipManager.GetAllTraitChips();
                        mSim.TraitChipManager.mTraitChipSlots = new TraitChip[7];
                        mSim.TraitChipManager.mValues.Clear();
                    }

                    if (createdSim != null)
                    {
                        if (createdSim.BuffManager != null)
                        {
                            mBuffs = new List <BuffInstance>();

                            foreach (BuffInstance buff in createdSim.BuffManager.List)
                            {
                                mBuffs.Add(buff);
                            }
                        }

                        if (createdSim.Motives != null)
                        {
                            Motive motive = createdSim.Motives.GetMotive(CommodityKind.AcademicPerformance);
                            if (motive != null)
                            {
                                mAcademicPerformance = motive.Value;
                            }

                            motive = createdSim.Motives.GetMotive(CommodityKind.UniversityStudy);
                            if (motive != null)
                            {
                                mUniversityStudy = motive.Value;
                            }
                        }

                        if (createdSim.Inventory != null)
                        {
                            mInventory = createdSim.Inventory.DestroyInventoryAndStoreInList();
                        }

                        mDreamStore = new DreamCatcher.DreamStore(createdSim, false, false);

                        mReservedVehicle           = createdSim.GetReservedVehicle();
                        createdSim.ReservedVehicle = null;
                    }

                    SafeStore.Flag flags = SafeStore.Flag.None;

                    if (performSelectable)
                    {
                        flags |= SafeStore.Flag.Selectable;
                    }

                    if (performLoadFixup)
                    {
                        flags |= SafeStore.Flag.LoadFixup;
                    }

                    if (performUnselectable)
                    {
                        flags |= SafeStore.Flag.Unselectable;
                    }

                    mSafeStore = new SafeStore(mSim, flags);

                    // Stops the startup errors when the imaginary friend is broken
                    mDoll = GetDollForSim(sim);
                    if (mDoll != null)
                    {
                        mDoll.mOwner = null;
                    }

                    mGenealogy = sim.mGenealogy;

                    mRelations = Relationships.StoreRelations(sim, null);

                    // Stops all event processing during the creation process
                    EventTracker.sCurrentlyUpdatingDreamsAndPromisesManagers = true;

                    // Stops the interface from updating during OnCreation
                    if (sim.Household != null)
                    {
                        mChangedCallback  = sim.Household.HouseholdSimsChanged;
                        mChangedHousehold = sim.Household;

                        sim.Household.HouseholdSimsChanged = null;
                    }

                    sChangingWorldsSuppression.Push();

                    // Stops SetGeneologyRelationshipBits()
                    sim.mGenealogy = new Genealogy(sim);
                }
                catch (Exception e)
                {
                    Common.Exception(sim, e);
                }
            }
Beispiel #44
0
 protected override List<Genealogy> GetReverseGenealogy(Genealogy gene)
 {
     return gene.Siblings;
 }
Beispiel #45
0
 protected override List<Genealogy> GetGenealogy(Genealogy gene)
 {
     return gene.mChildren;
 }
Beispiel #46
0
        protected static Genealogy ReconcileGenealogy(Genealogy newGene, Genealogy oldGene)
        {
            if (newGene == null) return oldGene;

            if (oldGene == null) return null;

            ReconcileGenealogy("Parent", Relationships.GetFullName(newGene), newGene.mNaturalParents, oldGene.mNaturalParents);
            ReconcileGenealogy("Child", Relationships.GetFullName(newGene), newGene.mChildren, oldGene.mChildren);
            ReconcileGenealogy("Sibling", Relationships.GetFullName(newGene), newGene.mSiblings, oldGene.mSiblings);

            return null;
        }
Beispiel #47
0
 protected override bool Allow(Genealogy me)
 {
     return (me != null);
 }
Beispiel #48
0
 protected override List<Genealogy> GetReverseGenealogy(Genealogy gene)
 {
     return gene.Children;
 }
Beispiel #49
0
            public AncestorData(Genealogy sim)
            {
                foreach (Genealogy ancestor in sim.Ancestors)
                {
                    if (mDirectAncestors.ContainsKey(ancestor)) continue;

                    mDirectAncestors.Add(ancestor, true);

                    foreach (Genealogy sibling in ancestor.Siblings)
                    {
                        if (mSiblingAncestors.ContainsKey(sibling)) continue;

                        mSiblingAncestors.Add(sibling, true);
                    }
                }
            }
Beispiel #50
0
 public bool IsSibling(Genealogy sim)
 {
     return mSiblingAncestors.ContainsKey(sim);
 }
Beispiel #51
0
        /// <summary>
        /// Creates the class (one instance only) that parses a scenario and puts events on queues
        /// </summary>
        /// <param name="scenarioFile"></param>
        public ScenarioToQueues(string scenarioFile, string schemaFile)
        {
            TimerQueueClass timerQueue = new TimerQueueClass();
            // Extract fields from the XML file (and schema)
            // see http://weblogs.asp.net/dbrowning/articles/114561.aspx
            // paths to xml/xsd
            // const string path = @"C:\Documents and Settings\dgeller\My Documents\Visual Studio 2005\Projects\";
            //const string scenarioFile = path + @"DDD\Scenario.xml";
            // const string xsdPath = path + @"XMLTrial\XMLTrial\ScenarioSchema.xsd";



            FileStream fs;
            Boolean    returnVal;

//            ScenarioToQueues.schemaFile = schemaFile;

            //    try
            //  {
            returnVal = ValidateScenario(scenarioFile);
            // }

            /*    catch (System.Exception e)
             *  {
             *
             *      string message = "Failed to validate schema. " + e.Message;
             *      Coordinator.debugLogger.LogException("Scenario Reader", message);
             *      throw new ApplicationException(message, e);
             *  }*/

            if (!returnVal)
            {
                return;
            }


            try
            {
                fs = File.Open(scenarioFile, FileMode.Open);
            }
            catch (System.Exception e)
            {
                string message = "Could not open scenario file on pass 2." + e.Message;
                Coordinator.debugLogger.LogException("Scenario Reader", message);
                throw new ApplicationException(message, e);
            }

            /// XmlReader readerTwo;
            try
            {
                XmlSchemaSet sc = new XmlSchemaSet();
                sc.Add(null, ScenarioToQueues.namedSchemaFile);//+".xsd");
                XmlReaderSettings readerSettings = new XmlReaderSettings();

                // readerSettings.ValidationType = ValidationType.Schema;
                readerSettings.IgnoreWhitespace = true;
                // makes no difference ?!               readerSettings.IgnoreWhitespace = true;
                //   readerSettings.ValidationEventHandler += new ValidationEventHandler(SchemaValidationHandler);

                reader = XmlReader.Create(fs, readerSettings);
                parser.SetReader(reader);
            }
            catch (System.Exception e)
            {
                fs.Close();
                string message = "Could not open schema file. " + e.Message;
                Coordinator.debugLogger.LogException("Scenario Reader", message);
                throw new ApplicationException(message, e);
            }

            //Build reverse dictionary of commnds->stage
            //This lets us enforce moving through the commands in a prescribed order
            Dictionary <string, int> stages = new Dictionary <string, int>();

            string[][] stageMembers = parser.StageMembers();
            for (int level = 0; level < stageMembers.Length; level++)
            {
                for (int member = 0; member < stageMembers[level].Length; member++)
                {
                    stages[stageMembers[level][member]] = level;
                }
            }
            int    currentStage = 0;
            string scenarioName = "";
            string description  = "";


            reader.Read(); // opens, gets to xml declaration
            reader.Read();
            try
            {
                if ("Scenario" == reader.Name) // only Scenario can be top level
                {
                    reader.Read();             // pass by "Scenario"

                    while (!reader.EOF && !((XmlNodeType.EndElement == reader.NodeType) && ("Scenario" == reader.Name)))
                    {
                        //Coordinator.debugLogger.Writeline(".");

                        switch (reader.NodeType)
                        {
                        case XmlNodeType.Element:
                            Coordinator.debugLogger.Writeline("ScenarioToQueues", "ELEMENT " + reader.Name, "test");
                            if (stages.ContainsKey(reader.Name))
                            {
                                if (stages[reader.Name] < currentStage)
                                {
                                    throw new ApplicationException("Command " + reader.Name + " out of sequence.");
                                }
                                currentStage = stages[reader.Name];
                                //NB, if command is not found in stages it will be trapped in the switch's default
                            }
                            switch (reader.Name)
                            {
                            case "ScenarioName":
                                scenarioName = parser.pGetString();
                                break;

                            case "Description":
                                description = parser.pGetString();
                                break;

                            case "ClientSideAssetTransfer":
                                ClientSideAssetTransferType assetTransfers = new ClientSideAssetTransferType(parser.pGetBoolean());
                                TimerQueueClass.SendBeforeStartup(assetTransfers);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", " ClientSideAssetTransferType ", "test");
                                break;

                            case "ClientSideStartingLabelVisible":
                                ClientSideStartingLabelVisibleType labelsVisible = new ClientSideStartingLabelVisibleType(parser.pGetBoolean());
                                TimerQueueClass.SendBeforeStartup(labelsVisible);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", " ClientSideStartingLabelVisibleType ", "test");
                                break;

                            case "ClientSideRangeRingVisibility":
                                ClientSideRangeRingVisibilityType rangeRingVisibility = new ClientSideRangeRingVisibilityType(parser.pGetString());
                                TimerQueueClass.SendBeforeStartup(rangeRingVisibility);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", "ClientSideRangeRingVisibilityType", "test");
                                break;

                            case "Playfield":
                                // except for the optional name/description
                                // Playfield must be first scenario item sent
                                // enforced by schema
                                string             errorText   = string.Empty;
                                string             imgLibPath  = string.Empty;
                                string             mapFilePath = string.Empty;
                                string             hostname    = Aptima.Asim.DDD.CommonComponents.ServerOptionsTools.ServerOptions.HostName;
                                pPlayfieldType     pDefine     = parser.pGetPlayfield();
                                PlayfieldEventType playfield   = new PlayfieldEventType(pDefine);
                                playfield.ScenarioName = scenarioName;
                                playfield.Description  = description;
                                if (playfield.IconLibrary.EndsWith(".dll"))
                                {
                                    imgLibPath = String.Format(@"\\{0}\{1}", ServerOptions.DDDClientPath, playfield.IconLibrary);         //icon library does include dll extension
                                }
                                else
                                {
                                    imgLibPath = String.Format(@"\\{0}\{1}.dll", ServerOptions.DDDClientPath, playfield.IconLibrary);         //icon library doesnt include dll extension
                                }
                                mapFilePath = String.Format(@"\\{0}\MapLib\{1}", ServerOptions.DDDClientPath, playfield.MapFileName);         //map file includes file extension

                                //check image library path
                                if (!File.Exists(imgLibPath))
                                {
                                    if (System.Windows.Forms.MessageBox.Show(String.Format("The server was not able to locate the image library in {0}.  There is a chance that clients connecting to this machine will have a similar issue locating this file.  If you'd still like to run the simulation, click Yes.  If you'd like to stop the server, click No.", imgLibPath), "File not found", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes)
                                    {        //User wants to continue
                                    }
                                    else
                                    {         //user wants to stop server
                                        throw new Exception("User Cancelled server process.  Server was unable to locate the image library at " + imgLibPath);
                                        return;
                                    }
                                }

                                //check map file path
                                if (!File.Exists(mapFilePath))
                                {
                                    if (System.Windows.Forms.MessageBox.Show(String.Format("The server was not able to locate the map file in {0}.  There is a chance that clients connecting to this machine will have a similar issue locating this file.  If you'd still like to run the simulation, click Yes.  If you'd like to stop the server, click No.", mapFilePath), "File not found", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes)
                                    {        //User wants to continue
                                    }
                                    else
                                    {         //user wants to stop server
                                        throw new Exception("User Cancelled server process.  Server was unable to locate the map file at " + mapFilePath);
                                        return;
                                    }
                                }
                                TimerQueueClass.SendBeforeStartup(playfield);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", "Playfield", "test");

                                TimerQueueClass.SendBeforeStartup(new RandomSeedType());
                                break;

                            case "LandRegion":
                                pLandRegionType region      = parser.pGetLandRegion();
                                RegionEventType regionEvent = new RegionEventType(region);

                                TimerQueueClass.SendBeforeStartup(regionEvent);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", " LandRegion " + regionEvent.UnitID, "test");

                                break;

                            /*
                             * case "ScoringRegion":
                             * pScoringRegionType regionS = parser.pGetScoringRegion();
                             * RegionEventType regionEventS = new RegionEventType(regionS);
                             * TimerQueueClass.SendBeforeStartup(regionEventS);
                             * Coordinator.debugLogger.Writeline("ScenarioToQueues", " ScoringRegion " + regionEventS.UnitID, "test");
                             * break;
                             */
                            case "ActiveRegion":
                                pActiveRegionType regionA      = parser.pGetActiveRegion();
                                RegionEventType   regionEventA = new RegionEventType(regionA);
                                if (!NameLists.activeRegionNames.New(regionA.ID, regionEventA))
                                {
                                    throw new ApplicationException("Duplicate active region name " + regionA.ID);
                                }
                                TimerQueueClass.SendBeforeStartup(regionEventA);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", " ActiveRegion " + regionEventA.UnitID, "test");
                                break;

                            case "Team":
                                pTeamType team      = parser.pGetTeam();
                                TeamType  teamEvent = new TeamType(team);
                                for (int i = 0; i < teamEvent.Count(); i++)
                                {
                                    UnitFacts.AddEnemy(teamEvent.Name, teamEvent.GetEnemy(i));
                                }
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", " Team " + team.Name.ToString(), "test");
                                if (!NameLists.teamNames.New(team.Name, teamEvent))
                                {
                                    throw new ApplicationException("Duplicate team name " + team.Name);
                                }

                                TimerQueueClass.SendBeforeStartup(teamEvent);
                                break;

                            case "DecisionMaker":
                                DecisionMakerType decisionMaker = new DecisionMakerType(parser.pGetDecisionMaker());
                                UnitFacts.AddDM(decisionMaker.Identifier, decisionMaker.Chroma, decisionMaker.Team);
                                TimerQueueClass.SendBeforeStartup(decisionMaker);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", "Decision Maker ", "test");
                                break;

                            case "Network":
                                NetworkType network = new NetworkType(parser.pGetNetwork());
                                NetworkTable.AddNetwork(network);
                                TimerQueueClass.SendBeforeStartup(network);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", "Network ", "test");
                                break;


                            case "Sensor":
                                //sensor follows Playfield
                                pSensor sen = parser.pGetSensor();
                                // if Attribute is "all" there will be one cone; only extent is filled in from parser
                                if (sen.Attribute == "All")
                                {
                                    sen.Cones[0].Spread = 360;
                                    sen.Cones[0].Level  = "Total";
                                }
                                SensorTable.Add(sen.Name, new SensorType(sen.Attribute, sen.IsEngram, sen.TypeIfEngram, sen.Cones));

                                Coordinator.debugLogger.Writeline("ScenarioToQueues", " Sensor " + sen.Name.ToString(), "test");

                                break;

                            /*    case "TimeToRemove":
                             *          Defaults.DefaultTimeToRemove = parser.pGetInt();
                             *          break;
                             */
                            case "Classifications":
                                ClassificationsType classifications = new ClassificationsType(parser.pGetClassifications());
                                TimerQueueClass.SendBeforeStartup(classifications);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", " Classifications ", "test");
                                break;

                            case "TimeToAttack":
                                Defaults.DefaultTimeToAttack = parser.pGetInt() * 1000;
                                break;

                            case "Genus":
                                pGenusType g = parser.pGetGenus();
                                if (!NameLists.speciesNames.New(g.Name, g))
                                {
                                    throw new ApplicationException("Duplicate use of genus name " + g.Name);
                                }

                                Genealogy.Add(g.Name);


                                Coordinator.debugLogger.Writeline("ScenarioToQueues", "Genus " + g.Name, "test");
                                // StartupForUnits.Add(genus);
                                break;

                            case "Species":
                                // Genus and species come after playfield


                                pSpeciesType s       = parser.pGetSpecies();
                                SpeciesType  species = new SpeciesType(s);
                                if (!NameLists.speciesNames.New(species.Name, species))
                                {
                                    throw new ApplicationException("Duplicate use of species name " + species.Name);
                                }
                                Genealogy.Add(species.Name, species.BasedOn);
                                if (species.IsWeapon)
                                {
                                    WeaponTable.Add(species.Name);
                                }

                                WorkStates.Clear();
                                WorkStates.Add(species.States);
                                StatesForUnits.AddStatesOf(species.Name, WorkStates.CollapseStates(species.Name, species.BasedOn));
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", "Species " + s.Name, "test");
                                // StartupForUnits.Add(species);
                                break;

                            case "Create_Event":
                                //string newId;
                                //   Create_EventType platformCreate;//used for sub platforms
                                pCreateType      c           = parser.pGetCreate();
                                Create_EventType createEvent = new Create_EventType(c);
                                Genealogy.Add(createEvent.UnitID, createEvent.UnitBase);
                                createEvent.Genus = Genealogy.GetGenus(createEvent.UnitID);
                                UnitFacts.AddUnit(createEvent.UnitID, createEvent.Owner, createEvent.UnitBase);
                                createEvent.Parameters = new ObjectDictionary();

                                SpeciesType speciesInfo = (SpeciesType)NameLists.speciesNames[createEvent.UnitBase];

                                foreach (KeyValuePair <string, StateBody> kvp in StatesForUnits.StateTable[createEvent.UnitBase])
                                {
                                    string            stateName = kvp.Key;
                                    ExtendedStateBody extended  = new ExtendedStateBody(kvp.Value);

                                    //end species dependent atts
                                    createEvent.Parameters.Add(stateName, (object)extended);
                                    //               EngramDependants.Add(createEvent.UnitID, extended);
                                }



                                //       TimerQueueClass.Add(1, createEvent);
                                NameLists.unitNames.New(createEvent.UnitID, null);
                                TimerQueueClass.SecondarySendBeforeStartup(createEvent);
                                UnitFacts.CurrentUnitStates.Add(createEvent.UnitID, "");
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", "createEvent for " + createEvent.UnitID, "test");

                                //for some reason this docs everyone at time 1.  this seems to be the heart of the bug

                                /*
                                 * for (int i = 0; i < createEvent.Subplatforms.Count;i++ )
                                 * {
                                 * SubplatformDockType dockNotice = new SubplatformDockType(createEvent.Subplatforms[i], createEvent.UnitID);
                                 * dockNotice.Time = 1;
                                 * TimerQueueClass.SecondarySendBeforeStartup(dockNotice);
                                 *
                                 * }
                                 */
                                break;

                            case "Reveal_Event":
                                pRevealType      r           = parser.pGetReveal();
                                Reveal_EventType revealEvent = new Reveal_EventType(r);
                                revealEvent.Genus = Genealogy.GetGenus(revealEvent.UnitID);
                                if (r.Time > 1)
                                {
                                    TimerQueueClass.Add(r.Time, revealEvent);
                                }
                                else
                                {
                                    TimerQueueClass.SecondarySendBeforeStartup(revealEvent);
                                }
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", "revealEvent for  " + revealEvent.UnitID + " at time" + r.Time.ToString(), "test");
                                RevealDocked(r.UnitID, r.Time);
                                break;

                            case "Move_Event":
                                pMoveType m = parser.pGetMove();
                                if (!UnitFacts.IsAUnit(m.UnitID))
                                {
                                    throw new ApplicationException("Cannot move non-exsitant unit " + m.UnitID);
                                }
                                Move_EventType moveEvent = new Move_EventType(m);
                                TimerQueueClass.Add(moveEvent.Time, moveEvent);
                                Coordinator.debugLogger.Writeline("ScenarioToQueues", " moveEvent for  " + moveEvent.UnitID, "test");
                                break;

                            case "Completion_Event":
                                HappeningCompletionType completionType = new HappeningCompletionType(parser.pGetHappeningCompletion());
                                HappeningList.Add(completionType);
                                break;

                            case "Species_Completion_Event":
                                pSpeciesCompletionType sct = parser.pGetSpeciesCompletion();
                                SpeciesCompletionType  speciesCompletion = new SpeciesCompletionType(sct);
                                SpeciesHappeningList.Add(speciesCompletion);
                                break;

                            case "Reiterate":
                                ReiterateType  reiterate = new ReiterateType(parser.pGetReiterate());
                                Move_EventType mQueued   = (Move_EventType)(reiterate.ReiterateList[0]);
                                Move_EventType mQCopy    = (Move_EventType)(reiterate.ReiterateList[0]);
                                mQueued.Range = reiterate.Range;
                                mQueued.Time  = reiterate.Time;
                                TimerQueueClass.Add(mQueued.Time, mQueued);

                                Coordinator.debugLogger.Writeline("ScenarioToQueues", " moveEvent from reiterate for  " + mQueued.UnitID, "test");
                                reiterate.ReiterateList.RemoveAt(0);
                                reiterate.ReiterateList.Add(mQCopy);
                                HappeningCompletionType envelope = new HappeningCompletionType(reiterate);
                                HappeningList.Add(envelope);
                                break;

                            case "StateChange_Event":
                                StateChangeEvent change = new StateChangeEvent(parser.pGetStateChange());
                                if (!UnitFacts.IsAUnit(change.UnitID))
                                {
                                    throw new ApplicationException("State change event references unknown unit " + change.UnitID);
                                }
                                if (!StatesForUnits.UnitHasState(change.UnitID, change.NewState))
                                {
                                    throw new ApplicationException("State chage for " + change.UnitID + " refers to unknwon state " + change.NewState);
                                }
                                for (int i = 0; i < change.Except.Count; i++)
                                {
                                    //                    if (!StatesForUnits.UnitHasState(Genealogy.GetBase(change.UnitID), change.Except[i])) throw new ApplicationException("State change for " + change.UnitID + " refers to unknown state " + change.Except);
                                    if (!StatesForUnits.UnitHasState(change.UnitID, change.Except[i]))
                                    {
                                        throw new ApplicationException("State change for " + change.UnitID + " refers to unknown state " + change.Except);
                                    }
                                }
                                for (int i = 0; i < change.From.Count; i++)
                                {
                                    //                if (!StatesForUnits.UnitHasState(Genealogy.GetBase(change.UnitID), change.From[i])) throw new ApplicationException("State change for " + change.UnitID + " refers to unknown state " + change.From);
                                    if (!StatesForUnits.UnitHasState(change.UnitID, change.From[i]))
                                    {
                                        throw new ApplicationException("State change for " + change.UnitID + " refers to unknown state " + change.From);
                                    }
                                }
                                TimerQueueClass.Add(change.Time, change);
                                break;

                            case "Transfer_Event":
                                TransferEvent t = new TransferEvent(parser.pGetTransfer());

                                if (!UnitFacts.IsDM(t.From))
                                {
                                    throw new ApplicationException("Transfer event references unknown DM (from) " + t.From);
                                }
                                if (!UnitFacts.IsDM(t.To))
                                {
                                    throw new ApplicationException("Transfer event references unknown DM (to) " + t.To);
                                }
                                if (!UnitFacts.IsAUnit(t.UnitID))
                                {
                                    throw new ApplicationException("Transfer event references unknown unit " + t.UnitID);
                                }
                                TimerQueueClass.Add(t.Time, t);
                                break;

                            case "Launch_Event":
                                LaunchEventType launch = new LaunchEventType(parser.pGetLaunch());
                                if (!UnitFacts.IsAUnit(launch.UnitID))
                                {
                                    throw new ApplicationException("Cannot launch from non-existent unit " + launch.UnitID);
                                }
                                TimerQueueClass.Add(launch.Time, launch);


                                break;

                            case "WeaponLaunch_Event":

                                WeaponLaunchEventType weaponLaunch = new WeaponLaunchEventType(parser.pGetWeaponLaunch());
                                if (!UnitFacts.IsAUnit(weaponLaunch.UnitID))
                                {
                                    throw new ApplicationException("Cannot launch from non-existent unit " + weaponLaunch.UnitID);
                                }
                                TimerQueueClass.Add(weaponLaunch.Time, weaponLaunch);


                                break;

                            case "DefineEngram":
                                pDefineEngramType defineEngram = parser.pGetDefineEngram();
                                Engrams.Create(defineEngram.Name, defineEngram.EngramValue, defineEngram.Type);
                                TimerQueueClass.SendBeforeStartup(new EngramSettingType(defineEngram.Name, "", defineEngram.EngramValue, defineEngram.Type));
                                break;

                            case "ChangeEngram":
                                ChangeEngramType changeEngram = new ChangeEngramType(parser.pGetChangeEngram());
                                if (!Engrams.ValidUpdate(changeEngram.Name, changeEngram.EngramValue))
                                {
                                    throw new ApplicationException("Illegal value " + changeEngram.EngramValue + " for engram " + changeEngram.Name);
                                }
                                TimerQueueClass.Add(changeEngram.Time, changeEngram);
                                //  Engrams.SendUpdate(changeEngram.Name);
                                break;

                            case "RemoveEngram":
                                RemoveEngramEvent removeEngram = new RemoveEngramEvent(parser.pGetRemoveEngram());
                                TimerQueueClass.Add(removeEngram.Time, removeEngram);
                                break;

                            //These chat commands are those from the scenario only;
                            // thos from client are handled immediately
                            case "OpenChatRoom":
                                OpenChatRoomType openChatRoom = new OpenChatRoomType(parser.pGetOpenChatRoom());
                                TimerQueueClass.Add(openChatRoom.Time, openChatRoom);
                                break;

                            case "CloseChatRoom":
                                CloseChatRoomType closeChatRoom = new CloseChatRoomType(parser.pGetCloseChatRoom());

                                TimerQueueClass.Add(closeChatRoom.Time, closeChatRoom);
                                break;

                            /* Not implemented yet
                             * case "DropChatters":
                             *     DropChattersType dropChatters = new DropChattersType(parser.pGetDropChatters());
                             *     TimerQueueClass.Add(dropChatters.Time, dropChatters);
                             *     break;
                             * case "AddChatters":
                             *     AddChattersType addChatters = new AddChattersType(parser.pGetAddChatters());
                             *     TimerQueueClass.Add(addChatters.Time, addChatters);
                             *     break;
                             *
                             */
                            case "OpenWhiteboardRoom":
                                OpenWhiteboardRoomType openWhiteboardRoom = new OpenWhiteboardRoomType(parser.pGetOpenWhiteboardRoom());
                                TimerQueueClass.Add(openWhiteboardRoom.Time, openWhiteboardRoom);
                                break;

                            case "OpenVoiceChannel":
                                OpenVoiceChannelType openVoiceChannel = new OpenVoiceChannelType(parser.pGetOpenVoiceChannel());
                                TimerQueueClass.Add(openVoiceChannel.Time, openVoiceChannel);
                                break;

                            case "CloseVoiceChannel":
                                CloseVoiceChannelType closeVoiceChannel = new CloseVoiceChannelType(parser.pGetCloseVoiceChannel());
                                TimerQueueClass.Add(closeVoiceChannel.Time, closeVoiceChannel);
                                break;

                            /*
                             * //Removed before 4.1
                             * case "GrantVoiceChannelAccess":
                             * GrantVoiceAccessType grantVoiceChannelAccess = new GrantVoiceAccessType(parser.pGetGrantVoiceChannelAccess());
                             * TimerQueueClass.Add(grantVoiceChannelAccess.Time, grantVoiceChannelAccess);
                             * break;
                             * case "RemoveVoiceChannelAccess":
                             * RemoveVoiceAccessType removeVoiceChannelAccess = new RemoveVoiceAccessType(parser.pGetRemoveVoiceChannelAccess());
                             * TimerQueueClass.Add(removeVoiceChannelAccess.Time, removeVoiceChannelAccess);
                             * break;
                             */
                            case "Rule":
                                pScoringRuleType srt       = parser.pGetScoringRule();
                                ScoringRuleType  scoreRule = new ScoringRuleType(srt);
                                if (!NameLists.ruleNames.New(srt.Name, scoreRule))
                                {
                                    throw new ApplicationException("Duplicate scoring rule name " + srt.Name);
                                }
                                ScoringRules.Add(scoreRule);
                                break;

                            case "Score":
                                pScoreType pst = parser.pGetScore();
                                ScoreType  st  = new ScoreType(pst);
                                if (!NameLists.scoreNames.New(pst.Name, st))
                                {
                                    throw new ApplicationException("Duplicate score name " + pst.Name);
                                }
                                Scores.Register(st);
                                break;

                            case "FlushEvents":
                                FlushEvents flush = new FlushEvents(parser.pGetFlushEventsType());
                                TimerQueueClass.Add(flush.Time, flush);
                                break;

                            case "SendChatMessage":
                                SendChatMessageType sendChat = new SendChatMessageType(parser.pGetSendChatMessage());
                                if (!UnitFacts.IsDM(sendChat.Sender) && !("EXP" == sendChat.Sender))
                                {
                                    throw new ApplicationException("In SendChatMessage, '" + sendChat.Sender + "' is not a valid DM name.");
                                }
                                // Note: Can't validate chat room name at parse time; it might not have been created yet
                                TimerQueueClass.Add(sendChat.Time, sendChat);
                                break;

                            case "Apply":
                                ApplyType apply = new ApplyType(parser.pGetApply());
                                //what does this do?
                                TimerQueueClass.Add(apply.Time, apply);
                                break;

                            case "SendVoiceMessage":
                                SendVoiceMessageType playVoiceMessage = new SendVoiceMessageType(parser.pGetSendVoiceMessage());
                                //what does this do?
                                TimerQueueClass.Add(playVoiceMessage.Time, playVoiceMessage);
                                break;

                            case "SendVoiceMessageToUser":
                                SendVoiceMessageToUserType playVoiceMessageToUser = new SendVoiceMessageToUserType(parser.pGetSendVoiceMessageToUser());
                                //what does this do?
                                TimerQueueClass.Add(playVoiceMessageToUser.Time, playVoiceMessageToUser);
                                break;

                            default:
                                throw new ApplicationException("ScenarioToQueues: Unknown Scenario Element is *" + reader.Name);
                            }    //switch
                            break;

                        default:
                            Coordinator.debugLogger.Writeline("ScenarioToQueues", "Unhandled or out-of-sequence XML tag " + reader.Value, "test");
                            reader.Read();
                            break;
                        } //switch
                    }     //while
                      // All of scenario processed. Now do last things

                    //verify that the Chat, Whiteboard, and Voice lists contain only DMs and make them symmetric.
                    List <string> allDMs = UnitFacts.GetAllDms();
                    for (int i = 0; i < allDMs.Count; i++)
                    {
                        DecisionMakerType thisDM = DecisionMakerType.GetDM(allDMs[i]);

                        for (int j = 0; j < thisDM.ChatPartners.Count; j++)
                        {
                            if (!allDMs.Contains(thisDM.ChatPartners[j]))
                            {
                                throw new ApplicationException("Unknown decision maker name '" + thisDM.ChatPartners[j] + "' found as chat partner of '" + allDMs[i] + "'");
                            }
                            DecisionMakerType partnerDM = DecisionMakerType.GetDM(thisDM.ChatPartners[j]);
                            if (!partnerDM.ChatPartners.Contains(allDMs[i]))
                            {
                                partnerDM.MayChatWith(allDMs[i]);
                            }
                        }

                        for (int j = 0; j < thisDM.WhiteboardPartners.Count; j++)
                        {
                            if (!allDMs.Contains(thisDM.WhiteboardPartners[j]))
                            {
                                throw new ApplicationException("Unknown decision maker name '" + thisDM.WhiteboardPartners[j] + "' found as whiteboard partner of '" + allDMs[i] + "'");
                            }
                            DecisionMakerType partnerDM = DecisionMakerType.GetDM(thisDM.WhiteboardPartners[j]);
                            if (!partnerDM.WhiteboardPartners.Contains(allDMs[i]))
                            {
                                partnerDM.MayWhiteboardWith(allDMs[i]);
                            }
                        }

                        for (int j = 0; j < thisDM.VoicePartners.Count; j++)
                        {
                            if (!allDMs.Contains(thisDM.ChatPartners[j]))
                            {
                                throw new ApplicationException("Unknown decision maker name '" + thisDM.VoicePartners[j] + "' found as voice partner of '" + allDMs[i] + "'");
                            }
                            DecisionMakerType partnerDM = DecisionMakerType.GetDM(thisDM.VoicePartners[j]);
                            if (!partnerDM.VoicePartners.Contains(allDMs[i]))
                            {
                                partnerDM.MaySpeakWith(allDMs[i]);
                            }
                        }
                    }

                    // Add networks for DMs that have none
                    List <string> dmList = UnitFacts.GetAllDms();
                    for (int nextDM = 0; nextDM < dmList.Count; nextDM++)
                    {
                        if (!NetworkTable.IsNetworkMember(dmList[nextDM]))
                        {
                            string netName = "Network-For-" + dmList[nextDM];
                            NetworkTable.AddMember(netName, dmList[nextDM]);
                            NetworkType newNet = new NetworkType(netName);
                            newNet.Add(dmList[nextDM]);
                            TimerQueueClass.SendBeforeStartup(newNet);
                            Coordinator.debugLogger.Writeline("ScenarioToQueues", "Network ", "test");
                        }
                    }
                    //AD: Don't create default chat room, user should have control of this
                    // Create the detault Broadcast chatroom
                    //OpenChatRoomType broadcastChatRoom = new OpenChatRoomType(1, "", "Broadcast", dmList);
                    //TimerQueueClass.SendBeforeStartup(broadcastChatRoom);
                }//if
            }
            catch (System.Exception e)
            {
                if (e.Message.StartsWith("User Cancelled"))
                {//This means a missing map or icon library, and the user wanted to stop the server.  Do not write to error log, just stop the server.
                    throw e;
                }
                string message = "Failure in Parsing Control for next tag=" + reader.Name + " : " + e.Message;
                Coordinator.debugLogger.LogException("ScenarioReader", message);
                throw new ApplicationException(message, e);
            }
            finally
            {
                reader.Close();
                fs.Close();
                // Coordinator.debugLogger.Writeline("ScenarioToQueues", "Done", "general");
            }
        }//
Beispiel #52
0
        public static IMiniSimDescription GetSim(Genealogy genealogy, Dictionary<ulong, IMiniSimDescription> lookup)
        {
            if (genealogy == null) return null;

            try
            {
                if (genealogy.mSim != null)
                {
                    return Find(genealogy.mSim.SimDescriptionId, lookup);
                }
                else if (genealogy.mMiniSim != null)
                {
                    return Find(genealogy.mMiniSim.SimDescriptionId, lookup);
                }
            }
            catch (Exception e)
            {
                Common.Exception(genealogy.Name, e);
            }
            return null;
        }
Beispiel #53
0
            public CreationProtection(SimDescription sim, Sim createdSim, bool performLoadFixup, bool performSelectable, bool performUnselectable)
            {
                try
                {
                    mSim = sim;

                    Corrections.RemoveFreeStuffAlarm(sim);

                    // Stops an issue in "GrantFutureObjects" regarding the use of sIsChangingWorlds=true
                    mWasFutureSim = sim.TraitManager.HasElement(TraitNames.FutureSim);
                    sim.TraitManager.RemoveElement(TraitNames.FutureSim);

                    if (SimTypes.IsSelectable(mSim))
                    {
                        Corrections.CleanupBrokenSkills(mSim, null);
                    }

                    if (OpportunityTrackerModel.gSingleton != null)
                    {
                        mOpportunitiesChanged = OpportunityTrackerModel.gSingleton.OpportunitiesChanged;
                        OpportunityTrackerModel.gSingleton.OpportunitiesChanged = null;
                    }

                    if (mSim.TraitChipManager != null)
                    {
                        mChips = mSim.TraitChipManager.GetAllTraitChips();
                        mSim.TraitChipManager.mTraitChipSlots = new TraitChip[7];
                        mSim.TraitChipManager.mValues.Clear();
                    }

                    if (createdSim != null)
                    {
                        if (createdSim.BuffManager != null)
                        {
                            mBuffs = new List<BuffInstance>();

                            foreach (BuffInstance buff in createdSim.BuffManager.List)
                            {
                                mBuffs.Add(buff);
                            }
                        }

                        if (createdSim.Motives != null)
                        {
                            Motive motive = createdSim.Motives.GetMotive(CommodityKind.AcademicPerformance);
                            if (motive != null)
                            {
                                mAcademicPerformance = motive.Value;
                            }

                            motive = createdSim.Motives.GetMotive(CommodityKind.UniversityStudy);
                            if (motive != null)
                            {
                                mUniversityStudy = motive.Value;
                            }
                        }

                        if (createdSim.Inventory != null)
                        {
                            mInventory = createdSim.Inventory.DestroyInventoryAndStoreInList();
                        }

                        mDreamStore = new DreamCatcher.DreamStore(createdSim, false, false);

                        mReservedVehicle = createdSim.GetReservedVehicle();
                        createdSim.ReservedVehicle = null;
                    }

                    SafeStore.Flag flags = SafeStore.Flag.None;

                    if (performSelectable)
                    {
                        flags |= SafeStore.Flag.Selectable;
                    }

                    if (performLoadFixup)
                    {
                        flags |= SafeStore.Flag.LoadFixup;
                    }

                    if (performUnselectable)
                    {
                        flags |= SafeStore.Flag.Unselectable;
                    }

                    mSafeStore = new SafeStore(mSim, flags);

                    // Stops the startup errors when the imaginary friend is broken
                    mDoll = GetDollForSim(sim);
                    if (mDoll != null)
                    {
                        mDoll.mOwner = null;
                    }

                    mGenealogy = sim.mGenealogy;

                    mRelations = Relationships.StoreRelations(sim, null);

                    // Stops all event processing during the creation process
                    EventTracker.sCurrentlyUpdatingDreamsAndPromisesManagers = true;

                    // Stops the interface from updating during OnCreation
                    if (sim.Household != null)
                    {
                        mChangedCallback = sim.Household.HouseholdSimsChanged;
                        mChangedHousehold = sim.Household;

                        sim.Household.HouseholdSimsChanged = null;
                    }

                    sChangingWorldsSuppression.Push();

                    // Stops SetGeneologyRelationshipBits()
                    sim.mGenealogy = new Genealogy(sim);
                }
                catch (Exception e)
                {
                    Common.Exception(sim, e);
                }
            }
Beispiel #54
0
 public bool IsDirect(Genealogy sim)
 {
     return mDirectAncestors.ContainsKey(sim);
 }
Beispiel #55
0
 protected static bool Remove(List<Genealogy> ths, Genealogy me)
 {
     return (ths.RemoveAll((e) => { return object.ReferenceEquals(e, me); }) > 0);
 }
Beispiel #56
0
        public static Boolean AttackApproved(ScenarioEventType s)
        {
            Boolean returnValue = false;

            /*
             * Approval algorithm;
             * If there are no matches on list, return check default condition
             * If there are any matches then any one that gives permission is enough
             * */

            Boolean denied = false;

            if ("Aptima.Asim.DDD.ScenarioController.AttackObjectRequestType" != s.GetType().ToString())
            {
                return(returnValue);
            }
            AttackObjectRequestType alias = (AttackObjectRequestType)s;

            for (int i = 0; i < approvals.Count; i++)
            {
                ScenarioEventType candidate = approvals[i];
                if ("Aptima.Asim.DDD.ScenarioController.AttackRequestApprovalType" != candidate.GetType().ToString())
                {
                    continue;
                }
                AttackRequestApprovalType rule = (AttackRequestApprovalType)candidate;
                if (rule.Capability != alias.CapabilityName)
                {
                    continue;
                }

                if (rule.Actor != "")
                {
                    if ((!rule.ActorIsSpecies) && (rule.Actor != alias.UnitID))
                    {
                        continue;
                    }
                    if (rule.ActorIsSpecies && !Genealogy.UnderSpecies(alias.UnitID, rule.Actor))
                    {
                        continue;
                    }
                }
                if (rule.Target != "")
                {
                    if ((!rule.TargetIsSpecies) && (rule.Target != alias.TargetObjectID))
                    {
                        continue;
                    }
                    if (rule.TargetIsSpecies && !Genealogy.UnderSpecies(alias.TargetObjectID, rule.Target))
                    {
                        continue;
                    }
                }
                if (rule.TargetStates.Count != 0)
                {
                    if (!rule.TargetStates.Contains(UnitFacts.CurrentUnitStates[alias.TargetObjectID]))
                    {
                        continue;
                    }
                }
                // At this point we can say that the rule legitimaly refers to alias.UnitID
                if (!rule.EngramValid(alias.UnitID, alias.TargetObjectID))
                {
                    denied = true;
                    continue;
                }
                if ((rule.UseDefault) && (alias.DecisionMaker != UnitFacts.GetDM(alias.UnitID)))
                {
                    denied = true;
                    continue;
                }
                //Wow. This rule was passed
                returnValue = true;
                break;
            }
            if (!returnValue && !denied)
            {// Now use the default rule
                DecisionMakerType unitDM = DecisionMakerType.GetDM(UnitFacts.GetDM(alias.UnitID));
                if (
                    (alias.DecisionMaker == unitDM.Identifier)
                    // &&
                    //(UnitFacts.HostileTo(unitDM.Team, DecisionMakerType.GetDM(UnitFacts.GetDM(alias.TargetObjectID)).Team))
                    //AD: Changed to allow for non-hostiles to be engaged, as they are requested by live players.
                    )
                {
                    returnValue = true;
                }
            }
            return(returnValue);
        }
Beispiel #57
0
 protected abstract List<Genealogy> GetGenealogy(Genealogy gene);
Beispiel #58
0
 protected abstract List<Genealogy> GetReverseGenealogy(Genealogy gene);
Beispiel #59
0
 public static bool IsOfDepth(Genealogy firstGenealogy, int maximum)
 {
     return (GetFamilyLevel(firstGenealogy, maximum) >= maximum);
 }
Beispiel #60
0
 protected override List<Genealogy> GetGenealogy(Genealogy gene)
 {
     return gene.mSiblings;
 }