Beispiel #1
0
        public static bool Perform(SimDescription sim, bool promptStrength, bool random)
        {
            List <VectorBooter.Item> choices = VectorBooter.GetVectorItems(sim);

            int maxSelection = 0;

            if (!promptStrength)
            {
                maxSelection = 1;
            }

            List <VectorBooter.Item> selection = new List <VectorBooter.Item>();

            if (random)
            {
                if (choices.Count == 0)
                {
                    return(false);
                }

                selection.Add(RandomUtil.GetRandomObjectFromList(choices));
            }
            else
            {
                CommonSelection <VectorBooter.Item> .Results items = new CommonSelection <VectorBooter.Item>(Common.Localize("Infect:MenuName"), choices).SelectMultiple(maxSelection);
                if ((items == null) || (items.Count == 0))
                {
                    return(false);
                }

                selection.AddRange(items);
            }

            foreach (VectorBooter.Item item in selection)
            {
                DiseaseVector.Variant strain = Vector.Settings.GetCurrentStrain(item.Value);

                int strength = strain.Strength;

                if (promptStrength)
                {
                    string text = StringInputDialog.Show(Common.Localize("Infect:MenuName"), Common.Localize("Infect:Prompt", false, new object[] { item.Value.GetLocalizedName(false) }), strain.Strength.ToString());

                    if (!int.TryParse(text, out strength))
                    {
                        Common.Notify(Common.Localize("Numeric:Error"));
                    }
                }

                strain.Strength = strength;

                DiseaseVector disease = new DiseaseVector(item.Value, strain);

                disease.Infect(sim, true);
            }

            return(true);
        }
Beispiel #2
0
            public virtual DiseaseVector.Variant Mutate(string guid, DiseaseVector.Variant strain)
            {
                if (!RandomUtil.RandomChance01(mMutationRate))
                {
                    return(strain);
                }

                if (mMutables.Count == 0)
                {
                    return(strain);
                }

                if (!strain.Mutate(RandomUtil.GetRandomObjectFromList(mMutables)))
                {
                    return(strain);
                }

                return(strain);
            }
Beispiel #3
0
        protected DiseaseVector.Variant GetNewStrain(VectorBooter.Data vector, DiseaseVector.Variant strain, bool force)
        {
            DiseaseVector.Variant newStrain = new DiseaseVector.Variant(vector, strain);

            if ((force) || (strain.Mutated))
            {
                // Doing this stops the previous strain from reentering this process
                strain.Mutated = false;

                long id = 1;

                DiseaseVector.Variant oldStrain;
                if (mVariants.TryGetValue(vector.Guid, out oldStrain))
                {
                    if (oldStrain.Strain < strain.Strain)
                    {
                        oldStrain.Strain = strain.Strain;
                    }

                    id = oldStrain.Strain;
                }
                else
                {
                    oldStrain = null;
                }

                if ((oldStrain == null) || (oldStrain.Variation(vector) < newStrain.Variation(vector)))
                {
                    newStrain.Strain++;

                    oldStrain = new DiseaseVector.Variant(newStrain, id + 1);

                    mVariants.Remove(vector.Guid);
                    mVariants.Add(vector.Guid, oldStrain);

                    if (Common.kDebugging)
                    {
                        Common.DebugNotify("BETTER " + vector.Guid + " Strain:" + Common.NewLine + oldStrain);
                    }
                }
                else if (RandomUtil.RandomChance01(vector.StrainMutationRate * (force ? 2 : 1)))
                {
                    newStrain.Strain = id + 1;

                    if (force)
                    {
                        oldStrain.Strain = newStrain.Strain;

                        if (Common.kDebugging)
                        {
                            Common.DebugNotify("OUTBREAK " + vector.Guid + " Strain:" + Common.NewLine + newStrain);
                        }
                    }
                    else
                    {
                        if (Common.kDebugging)
                        {
                            Common.DebugNotify("RANDOM " + vector.Guid + " Strain:" + Common.NewLine + newStrain);
                        }
                    }
                }
            }

            return newStrain;
        }
Beispiel #4
0
 public DiseaseVector.Variant Mutate(DiseaseVector.Variant strain, int stage)
 {
     return(mStages[stage].Mutate(Guid, strain));
 }