Example #1
0
        public override void CompTick()
        {
            base.CompTick();
            Pawn pawn = this.parent as Pawn;

            if ((pawn.Faction == Faction.OfPlayer) && (pawn.ageTracker.CurLifeStage.reproductive))
            {
                asexualFissionCounter++;
                if (asexualFissionCounter >= ticksInday * reproductionIntervalDays)
                {
                    if (produceEggs)
                    {
                        GenSpawn.Spawn(ThingDef.Named(eggDef), pawn.Position, pawn.Map);
                        Messages.Message("AA_AsexualHatchedEgg".Translate(pawn.LabelIndefinite().CapitalizeFirst()), pawn, MessageTypeDefOf.PositiveEvent, true);
                        asexualFissionCounter = 0;
                    }
                    else
                    {
                        Hediff_Pregnant.DoBirthSpawn(pawn, pawn);
                        Messages.Message("AA_AsexualHatched".Translate(pawn.LabelIndefinite().CapitalizeFirst()), pawn, MessageTypeDefOf.PositiveEvent, true);
                        asexualFissionCounter = 0;
                    }
                }
            }
        }
        private static bool on_begin_DoBirthSpawn(ref Pawn mother, ref Pawn father)
        {
            //--Log.Message("patches_pregnancy::PATCH_Hediff_Pregnant::DoBirthSpawn() called");

            if (mother == null)
            {
                Log.Error("Hediff_Pregnant::DoBirthSpawn() - no mother defined -> exit");
                return(false);
            }

            //vanilla debug?
            if (mother.gender == Gender.Male)
            {
                Log.Error("Hediff_Pregnant::DoBirthSpawn() - mother is male -> exit");
                return(false);
            }

            // get a reference to the hediff we are applying
            //do birth for vanilla pregnancy Hediff
            //if using rjw pregnancies - add RJW pregnancy Hediff and birth it instead
            Hediff_Pregnant self = (Hediff_Pregnant)mother.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("Pregnant"));

            if (self != null)
            {
                return(ProcessVanillaPregnancy(self, mother, father));
            }

            // do birth for existing RJW pregnancies
            if (ProcessRJWPregnancy(mother, father))
            {
                return(false);
            }

            return(ProcessDebugPregnancy(mother, father));
        }
        protected override string GetIconTip(Pawn pawn)
        {
            Hediff_Pregnant pregnantHediff    = this.GetPregnantHediff(pawn);
            float           gestationProgress = pregnantHediff.GestationProgress;
            int             num      = (int)(pawn.RaceProps.gestationPeriodDays * 60000.0);
            int             numTicks = (int)(gestationProgress * (float)num);

            return("PregnantIconDesc".Translate(numTicks.ToStringTicksToDays("F0"), num.ToStringTicksToDays("F0")));
        }
        public static string GetTooltipText(Pawn pawn)
        {
            Hediff_Pregnant pregnantHediff    = GetPregnantHediff(pawn);
            float           gestationProgress = pregnantHediff.GestationProgress;
            int             num      = (int)(pawn.RaceProps.gestationPeriodDays * 60000f);
            int             numTicks = (int)(gestationProgress * (float)num);

            return("PregnantIconDesc".Translate(numTicks.ToStringTicksToDays("F0"), num.ToStringTicksToDays("F0")));
        }
Example #5
0
        public override void CompTick()
        {
            base.CompTick();
            Pawn pawn = this.parent as Pawn;

            //Important, without a null map check creatures will reproduce while on caravans, producing errors
            if (pawn.Map != null)
            {
                if (this.Props.isGreenGoo)
                {
                    asexualFissionCounter++;
                    //This checks if the map has been filled with creatures. If this check wasn't made, the animal would fill
                    //the map and grind the game to a halt
                    if ((asexualFissionCounter >= ticksInday * reproductionIntervalDays) && ((this.parent.Map != null) && (this.parent.Map.listerThings.ThingsOfDef(ThingDef.Named(this.Props.GreenGooTarget)).Count < this.Props.GreenGooLimit)))
                    {
                        //The offspring has the pawn as both mother and father and I find this funny
                        Hediff_Pregnant.DoBirthSpawn(pawn, pawn);
                        //Only show a message if the pawn is part of the player's faction
                        if (pawn.Faction == Faction.OfPlayer)
                        {
                            Messages.Message(Props.asexualCloningMessage.Translate(pawn.LabelIndefinite().CapitalizeFirst()), pawn, MessageTypeDefOf.PositiveEvent, true);
                        }
                        asexualFissionCounter = 0;
                    }
                    //Just reset the counter if the map is filled
                    else if (asexualFissionCounter >= ticksInday * reproductionIntervalDays)
                    {
                        asexualFissionCounter = 0;
                    }
                }

                //Non-green goo creatures only reproduce if they are part of the player's faction, like vanilla animals
                else if ((pawn.Faction == Faction.OfPlayer) && (pawn.ageTracker.CurLifeStage.reproductive))
                {
                    asexualFissionCounter++;
                    if (asexualFissionCounter >= ticksInday * reproductionIntervalDays)
                    {
                        //If it produces eggs or spores, it will just spawn them. Note that these eggs are not part of the player's
                        //faction, the animal hatched from them will be wild
                        if (produceEggs)
                        {
                            GenSpawn.Spawn(ThingDef.Named(eggDef), pawn.Position, pawn.Map);
                            Messages.Message(Props.asexualEggMessage.Translate(pawn.LabelIndefinite().CapitalizeFirst()), pawn, MessageTypeDefOf.PositiveEvent, true);
                            asexualFissionCounter = 0;
                        }
                        //If not, do a normal fission
                        else
                        {
                            Hediff_Pregnant.DoBirthSpawn(pawn, pawn);
                            Messages.Message(Props.asexualHatchedMessage.Translate(pawn.LabelIndefinite().CapitalizeFirst()), pawn, MessageTypeDefOf.PositiveEvent, true);
                            asexualFissionCounter = 0;
                        }
                    }
                }
            }
        }
Example #6
0
        private static void FinishPregnancy()
        {
            var pregnancies = Find.Selector.SelectedPawns.Where(candidate => candidate.health.hediffSet.HasHediff(RimWorld.HediffDefOf.Pregnant))
                              .Select(candidate => candidate.health.hediffSet.GetFirstHediffOfDef(RimWorld.HediffDefOf.Pregnant));

            foreach (Hediff_Pregnant hediff in pregnancies)
            {
                Hediff_Pregnant.DoBirthSpawn(hediff.pawn, hediff.father);
                hediff.pawn.health.RemoveHediff(hediff);
            }
        }
Example #7
0
        public override void Tick()
        {
            base.Tick();
            this.pawn.ageTracker.AgeBiologicalTicks += (long)this.Severity - 1;
            Hediff_Pregnant hediffpreg = this.pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Pregnant) as Hediff_Pregnant;

            if (hediffpreg != null)
            {
                hediffpreg.Severity += (this.Severity - 1f) / (this.pawn.RaceProps.gestationPeriodDays * 60000f);
            }
        }
 static bool on_begin_Tick(Hediff_Pregnant __instance)
 {
     if (__instance.pawn.IsHashIntervalTick(1000))
     {
         if (!Genital_Helper.has_vagina(__instance.pawn))
         {
             __instance.pawn.health.RemoveHediff(__instance);
         }
     }
     return(true);
 }
        protected override void Impregnate(Pawn pawn, Pawn part, bool isAnalSex)
        {
            if (pawn == null || part == null || isAnalSex)
            {
                return;
            }
            //--Log.Message("[RJW]JobDriver_RapeEnemyToParasite::impregnate( " + pawn.NameStringShort + ", " + part.NameStringShort + " ) called");

            if (pawn.health.hediffSet.HasHediff(xxx.sterilized) || part.health.hediffSet.HasHediff(xxx.sterilized))
            {
                return;
            }
            if (pawn.health.capacities.GetLevel(xxx.reproduction) <= 0 || part.health.capacities.GetLevel(xxx.reproduction) <= 0)
            {
                return;
            }

            Pawn male, female;

            if (pawn.gender == Gender.Male && part.gender == Gender.Female)
            {
                male   = pawn;
                female = part;
            }
            else if (pawn.gender == Gender.Female && part.gender == Gender.Male)
            {
                male   = part;
                female = pawn;
            }
            else
            {
                //--Log.Message("[RJW] Same sex pregnancies not currently supported...");
                return;
            }

            // fertility check
            float fertility           = (xxx.is_animal(female) ? Mod_Settings.pregnancy_coefficient_animals / 100f : Mod_Settings.pregnancy_coefficient_human / 100f);
            float ReproductionFactor  = Math.Min(male.health.capacities.GetLevel(xxx.reproduction), female.health.capacities.GetLevel(xxx.reproduction));
            float pregnancy_threshold = fertility * ReproductionFactor;
            float pregnancy_chance    = Rand.Value;

            if (pregnancy_chance > pregnancy_threshold)
            {
                //--Log.Message("[RJW] Impregnation failed. Chance was " + pregnancy_chance + " vs " + pregnancy_threshold);
                return;
            }

            Hediff_Pregnant hediff_pregnant = (Hediff_Pregnant)HediffMaker.MakeHediff(HediffDef.Named("Parasite"), part);

            hediff_pregnant.father = pawn;
            part.health.AddHediff(hediff_pregnant);
        }
Example #10
0
        private static void GiveBirthTogether()
        {
            var males   = Find.Selector.SelectedPawns.Where(candidate => candidate.gender == Gender.Male);
            var females = Find.Selector.SelectedPawns.Where(candidate => candidate.gender == Gender.Female);

            if (males.Count() != 1 || females.Count() != 1)
            {
                return;
            }

            Hediff_Pregnant.DoBirthSpawn(females.First(), males.First());
            DebugActionsUtility.DustPuffFrom(females.First());
        }
Example #11
0
        public static void Prefix(Hediff_Pregnant __instance)
        {
            var pawn = __instance.pawn;

            if (true &&
                pawn.IsSkippingTicks() &&
                pawn.IsValidWildlifeOrWorldPawn())
            {
                int deltaT = pawn.GetDeltaT();
                __instance.ageTicks          += deltaT - 1;
                __instance.GestationProgress += deltaT / (pawn.RaceProps.gestationPeriodDays * 60000f);
            }
        }
        private static bool ProcessVanillaPregnancy(Hediff_Pregnant pregnancy, Pawn mother, Pawn father)
        {
            void CreateAndBirth <T>() where T : Hediff_BasePregnancy
            {
                T hediff = Hediff_BasePregnancy.Create <T>(mother, father);

                //hediff.Initialize(mother, father);
                hediff.GiveBirth();
                if (pregnancy != null)
                {
                    mother.health.RemoveHediff(pregnancy);
                }
            }

            if (father == null)
            {
                father = Hediff_BasePregnancy.Trytogetfather(ref mother);
            }

            Log.Message("patches_pregnancy::PATCH_Hediff_Pregnant::DoBirthSpawn():Vanilla_pregnancy birthing:" + xxx.get_pawnname(mother));
            if (RJWPregnancySettings.animal_pregnancy_enabled && ((father == null || xxx.is_animal(father)) && xxx.is_animal(mother)))
            {
                //RJW Bestial pregnancy animal-animal
                Log.Message(" override as Bestial birthing(animal-animal): Father-" + xxx.get_pawnname(father) + " Mother-" + xxx.get_pawnname(mother));
                CreateAndBirth <Hediff_BestialPregnancy>();
                return(false);
            }
            else if (RJWPregnancySettings.bestial_pregnancy_enabled && ((xxx.is_animal(father) && xxx.is_human(mother)) || (xxx.is_human(father) && xxx.is_animal(mother))))
            {
                //RJW Bestial pregnancy human-animal
                Log.Message(" override as Bestial birthing(human-animal): Father-" + xxx.get_pawnname(father) + " Mother-" + xxx.get_pawnname(mother));
                CreateAndBirth <Hediff_BestialPregnancy>();
                return(false);
            }
            else if (RJWPregnancySettings.humanlike_pregnancy_enabled && (xxx.is_human(father) && xxx.is_human(mother)))
            {
                //RJW Humanlike pregnancy
                Log.Message(" override as Humanlike birthing: Father-" + xxx.get_pawnname(father) + " Mother-" + xxx.get_pawnname(mother));
                CreateAndBirth <Hediff_HumanlikePregnancy>();
                return(false);
            }
            else
            {
                Log.Warning("Hediff_Pregnant::DoBirthSpawn() - rjw checks failed, vanilla pregnancy birth");
                Log.Warning("Hediff_Pregnant::DoBirthSpawn(): Father-" + xxx.get_pawnname(father) + " Mother-" + xxx.get_pawnname(mother));
                //vanilla pregnancy code, no effects on rjw

                return(true);
            }
        }
Example #13
0
        private static void MakePregnancyTogether()
        {
            var males   = Find.Selector.SelectedPawns.Where(candidate => candidate.gender == Gender.Male);
            var females = Find.Selector.SelectedPawns.Where(candidate => candidate.gender == Gender.Female);

            if (males.Count() != 1 || females.Count() != 1)
            {
                return;
            }

            Hediff_Pregnant hediff_Pregnant = (Hediff_Pregnant)HediffMaker.MakeHediff(RimWorld.HediffDefOf.Pregnant, females.First(), null);

            hediff_Pregnant.father = males.First();
            females.First().health.AddHediff(hediff_Pregnant, null, null, null);
        }
 public static void Mated(Pawn male, Pawn female)
 {
     if (female.ageTracker.CurLifeStage.reproductive)
     {
         CompEggLayer compEggLayer = female.TryGetComp <CompEggLayer>();
         if (compEggLayer != null)
         {
             compEggLayer.Fertilize(male);
         }
         else if (Rand.Value < 0.5f && !female.health.hediffSet.HasHediff(HediffDefOf.Pregnant, false))
         {
             Hediff_Pregnant hediff_Pregnant = (Hediff_Pregnant)HediffMaker.MakeHediff(HediffDefOf.Pregnant, female, null);
             hediff_Pregnant.father = male;
             female.health.AddHediff(hediff_Pregnant, null, null, null);
         }
     }
 }
Example #15
0
        private static void GiveBirthTogether()
        {
            var males   = Find.Selector.SelectedPawns.Where(candidate => candidate.gender == Gender.Male);
            var females = Find.Selector.SelectedPawns.Where(candidate => candidate.gender == Gender.Female);

            if (males.Count() != 1 || females.Count() != 1)
            {
                return;
            }

            Hediff_Pregnant hediff_Pregnant = (Hediff_Pregnant)HediffMaker.MakeHediff(RimWorld.HediffDefOf.Pregnant, females.First(), null);

            hediff_Pregnant.father = males.First();
            females.First().health.AddHediff(hediff_Pregnant, null, null, null);

            Hediff_Pregnant.DoBirthSpawn(females.First(), males.First());
            DebugActionsUtility.DustPuffFrom(females.First());
        }
        private static bool on_begin_DoBirthSpawn(ref Pawn mother, ref Pawn father)
        {
            //--Log.Message("patches_pregnancy::PATCH_Hediff_Pregnant::DoBirthSpawn() called");

            if (mother == null)
            {
                Log.Error("Hediff_Pregnant::DoBirthSpawn() - no mother defined -> exit");
                return(false);
            }

            //vanilla debug?
            if (mother.gender == Gender.Male)
            {
                Log.Error("Hediff_Pregnant::DoBirthSpawn() - mother is male -> exit");
                return(false);
            }

            //Rand.PopState();
            //Rand.PushState(RJW_Multiplayer.PredictableSeed());

            // get a reference to the hediff we are applying
            //do birth for vanilla pregnancy Hediff
            //if using rjw pregnancies - add RJW pregnancy Hediff and birth it instead
            Hediff_Pregnant self = (Hediff_Pregnant)mother.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("Pregnant"));

            if (self != null)
            {
                if (father == null)
                {
                    father = Hediff_BasePregnancy.Trytogetfather(ref mother);
                }
                Log.Message("patches_pregnancy::PATCH_Hediff_Pregnant::DoBirthSpawn():Vanilla_pregnancy birthing:" + xxx.get_pawnname(mother));
                if (RJWPregnancySettings.animal_pregnancy_enabled && ((father == null || xxx.is_animal(father)) && xxx.is_animal(mother)))
                {
                    //RJW Bestial pregnancy animal-animal
                    Log.Message(" override as Bestial birthing(animal-animal): Father-" + xxx.get_pawnname(father) + " Mother-" + xxx.get_pawnname(mother));
                    Hediff_BestialPregnancy.Create(mother, father);
                    Hediff_BestialPregnancy hediff = (Hediff_BestialPregnancy)mother.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("RJW_pregnancy_beast"));
                    hediff.Initialize(mother, father);
                    hediff.GiveBirth();
                    if (self != null)
                    {
                        mother.health.RemoveHediff(self);
                    }

                    return(false);
                }
                else if (RJWPregnancySettings.bestial_pregnancy_enabled && ((xxx.is_animal(father) && xxx.is_human(mother)) || (xxx.is_human(father) && xxx.is_animal(mother))))
                {
                    //RJW Bestial pregnancy human-animal
                    Log.Message(" override as Bestial birthing(human-animal): Father-" + xxx.get_pawnname(father) + " Mother-" + xxx.get_pawnname(mother));
                    Hediff_BestialPregnancy.Create(mother, father);
                    Hediff_BestialPregnancy hediff = (Hediff_BestialPregnancy)mother.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("RJW_pregnancy_beast"));
                    hediff.Initialize(mother, father);
                    hediff.GiveBirth();
                    if (self != null)
                    {
                        mother.health.RemoveHediff(self);
                    }

                    return(false);
                }
                else if (RJWPregnancySettings.humanlike_pregnancy_enabled && (xxx.is_human(father) && xxx.is_human(mother)))
                {
                    //RJW Humanlike pregnancy
                    Log.Message(" override as Humanlike birthing: Father-" + xxx.get_pawnname(father) + " Mother-" + xxx.get_pawnname(mother));
                    Hediff_HumanlikePregnancy.Create(mother, father);
                    Hediff_HumanlikePregnancy hediff = (Hediff_HumanlikePregnancy)mother.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("RJW_pregnancy"));
                    hediff.Initialize(mother, father);
                    hediff.GiveBirth();
                    if (self != null)
                    {
                        mother.health.RemoveHediff(self);
                    }

                    return(false);
                }
                else
                {
                    Log.Warning("Hediff_Pregnant::DoBirthSpawn() - rjw checks failed, vanilla pregnancy birth");
                    Log.Warning("Hediff_Pregnant::DoBirthSpawn(): Father-" + xxx.get_pawnname(father) + " Mother-" + xxx.get_pawnname(mother));
                    //vanilla pregnancy code, no effects on rjw
                    int num = (mother.RaceProps.litterSizeCurve == null) ? 1 : Mathf.RoundToInt(Rand.ByCurve(mother.RaceProps.litterSizeCurve));
                    if (num < 1)
                    {
                        num = 1;
                    }
                    PawnGenerationRequest request = new PawnGenerationRequest(mother.kindDef, mother.Faction, PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: false, newborn: true);
                    Pawn pawn = null;
                    for (int i = 0; i < num; i++)
                    {
                        pawn = PawnGenerator.GeneratePawn(request);
                        if (PawnUtility.TrySpawnHatchedOrBornPawn(pawn, mother))
                        {
                            if (pawn.playerSettings != null && mother.playerSettings != null)
                            {
                                pawn.playerSettings.AreaRestriction = mother.playerSettings.AreaRestriction;
                            }
                            if (pawn.RaceProps.IsFlesh)
                            {
                                pawn.relations.AddDirectRelation(PawnRelationDefOf.Parent, mother);
                                if (father != null)
                                {
                                    pawn.relations.AddDirectRelation(PawnRelationDefOf.Parent, father);
                                }
                            }
                        }
                        else
                        {
                            Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
                        }
                        TaleRecorder.RecordTale(TaleDefOf.GaveBirth, mother, pawn);
                    }
                    if (mother.Spawned)
                    {
                        FilthMaker.MakeFilth(mother.Position, mother.Map, ThingDefOf.Filth_AmnioticFluid, mother.LabelIndefinite(), 5);
                        if (mother.caller != null)
                        {
                            mother.caller.DoCall();
                        }
                        if (pawn.caller != null)
                        {
                            pawn.caller.DoCall();
                        }
                    }
                    if (self != null)
                    {
                        mother.health.RemoveHediff(self);
                    }

                    return(false);
                }
            }

            // do birth for existing RJW pregnancies

            Hediff_HumanlikePregnancy rjwH = (Hediff_HumanlikePregnancy)mother.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("RJW_pregnancy"));

            if (rjwH != null)
            {
                //RJW Bestial pregnancy
                Log.Message("patches_pregnancy::PATCH_Hediff_Pregnant::DoBirthSpawn():RJW_pregnancy birthing:" + xxx.get_pawnname(mother));
                rjwH.GiveBirth();
                if (self == null)
                {
                    return(false);
                }
            }

            Hediff_BestialPregnancy rjwB = (Hediff_BestialPregnancy)mother.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("RJW_pregnancy_beast"));

            if (rjwB != null)
            {
                //RJW Humanlike pregnancy
                Log.Message("patches_pregnancy::PATCH_Hediff_Pregnant::DoBirthSpawn():RJW_pregnancy_beast birthing:" + xxx.get_pawnname(mother));
                rjwB.GiveBirth();
                if (self == null)
                {
                    return(false);
                }
            }

            //debug, add RJW pregnancy and birth it
            Log.Message("patches_pregnancy::PATCH_Hediff_Pregnant::DoBirthSpawn():Debug_pregnancy birthing:" + xxx.get_pawnname(mother));
            if (father == null)
            {
                father = Hediff_BasePregnancy.Trytogetfather(ref mother);
            }

            /*
             * if (true)
             * {
             *      //RJW Mech pregnancy
             *      Log.Message(" override as mech birthing:" + xxx.get_pawnname(mother));
             *      Hediff_MechanoidPregnancy.Create(mother, father);
             *      Hediff_MechanoidPregnancy hediff = (Hediff_MechanoidPregnancy)mother.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("RJW_pregnancy_mech"));
             *      hediff.GiveBirth();
             *      return false;
             * }
             */

            if (RJWPregnancySettings.bestial_pregnancy_enabled && ((xxx.is_animal(father) || xxx.is_animal(mother))) ||
                (xxx.is_animal(mother) && RJWPregnancySettings.animal_pregnancy_enabled))
            {
                //RJW Bestial pregnancy
                Log.Message(" override as Bestial birthing, mother: " + xxx.get_pawnname(mother));
                Hediff_BestialPregnancy.Create(mother, father);
                Hediff_BestialPregnancy hediff = (Hediff_BestialPregnancy)mother.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("RJW_pregnancy_beast"));
                hediff.GiveBirth();
            }
            else if (RJWPregnancySettings.humanlike_pregnancy_enabled && ((father == null || xxx.is_human(father)) && xxx.is_human(mother)))
            {
                //RJW Humanlike pregnancy
                Log.Message(" override as Humanlike birthing, mother: " + xxx.get_pawnname(mother));
                Hediff_HumanlikePregnancy.Create(mother, father);
                Hediff_HumanlikePregnancy hediff = (Hediff_HumanlikePregnancy)mother.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("RJW_pregnancy"));
                hediff.GiveBirth();
            }
            else
            {
                Log.Warning("Hediff_Pregnant::DoBirthSpawn() - debug vanilla pregnancy birth");
                //vanilla code
                int num = (mother.RaceProps.litterSizeCurve == null) ? 1 : Mathf.RoundToInt(Rand.ByCurve(mother.RaceProps.litterSizeCurve));
                if (num < 1)
                {
                    num = 1;
                }
                PawnGenerationRequest request = new PawnGenerationRequest(mother.kindDef, mother.Faction, PawnGenerationContext.NonPlayer, -1, forceGenerateNewPawn: false, newborn: true);
                Pawn pawn = null;
                for (int i = 0; i < num; i++)
                {
                    pawn = PawnGenerator.GeneratePawn(request);
                    if (PawnUtility.TrySpawnHatchedOrBornPawn(pawn, mother))
                    {
                        if (pawn.playerSettings != null && mother.playerSettings != null)
                        {
                            pawn.playerSettings.AreaRestriction = mother.playerSettings.AreaRestriction;
                        }
                        if (pawn.RaceProps.IsFlesh)
                        {
                            pawn.relations.AddDirectRelation(PawnRelationDefOf.Parent, mother);
                            if (father != null)
                            {
                                pawn.relations.AddDirectRelation(PawnRelationDefOf.Parent, father);
                            }
                        }
                    }
                    else
                    {
                        Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
                    }
                    TaleRecorder.RecordTale(TaleDefOf.GaveBirth, mother, pawn);
                }
                if (mother.Spawned)
                {
                    FilthMaker.MakeFilth(mother.Position, mother.Map, ThingDefOf.Filth_AmnioticFluid, mother.LabelIndefinite(), 5);
                    if (mother.caller != null)
                    {
                        mother.caller.DoCall();
                    }
                    if (pawn.caller != null)
                    {
                        pawn.caller.DoCall();
                    }
                }
                if (self != null)
                {
                    mother.health.RemoveHediff(self);
                }
            }
            return(false);
        }
        protected override Texture2D GetIconFor(Pawn pawn)
        {
            Hediff_Pregnant pregnantHediff = GetPregnantHediff(pawn);

            return((pregnantHediff == null) ? null : Icon);
        }
        protected override Texture2D GetIconFor(Pawn pawn)
        {
            Hediff_Pregnant pregnantHediff = PawnColumnWorker_Pregnant.GetPregnantHediff(pawn);

            return((pregnantHediff == null) ? null : PawnColumnWorker_Pregnant.Icon);
        }
Example #19
0
        private static bool on_begin_DoBirthSpawn(ref Pawn mother, ref Pawn father)
        {
            //TODO: Set pregnant hediff to torso
            //--Log.Message("patches_pregnancy::PATCH_Hediff_Pregnant::DoBirthSpawn() called");
            var mother_name = (mother != null) ? mother.NameStringShort : "NULL";
            var father_name = (father != null) ? father.NameStringShort : "NULL";

            if (mother == null)
            {
                Log.Error("Hediff_Pregnant::DoBirthSpawn() - no mother defined");
                return(false);
            }

            if (father == null)
            {
                Log.Warning("Hediff_Pregnant::DoBirthSpawn() - no father defined");
            }
            // get a reference to the hediff we are applying
            Hediff_Pregnant self = (Hediff_Pregnant)mother.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("Pregnant"));

            // determine litter size
            int litter_size = (mother.RaceProps.litterSizeCurve == null) ? 1 : Mathf.RoundToInt(Rand.ByCurve(mother.RaceProps.litterSizeCurve, 300));

            if (litter_size < 1)
            {
                litter_size = 1;
            }
            float  skin_whiteness = Rand.Range(0, 1);
            string last_name      = null;

            // send a message about giving birth
            ////--Log.Message("Hediff_Pregnancy::DoBirthSpawn( " + mother_name + ", " + father_name + ", " + chance_successful + " ) - generating baby pawns");
            if (self.Visible && PawnUtility.ShouldSendNotificationAbout(mother))
            {
                Messages.Message("GivingBirth".Translate(new object[] { mother.LabelIndefinite() }).CapitalizeFirst(), mother, MessageTypeDefOf.NeutralEvent);
            }

            ////--Log.Message("Hediff_Pregnancy::DoBirthSpawn( " + mother_name + ", " + father_name + ", " + chance_successful + " ) - creating spawn request");

            List <Pawn> siblings = new List <Pawn>();

            for (int i = 0; i < litter_size; i++)
            {
                Pawn spawn_parent = mother;
                if (father != null && Mod_Settings.pregnancy_use_parent_method && (100 * Rand.Value) > Mod_Settings.pregnancy_weight_parent)
                {
                    spawn_parent = father;
                }
                PawnGenerationRequest request = new PawnGenerationRequest(spawn_parent.kindDef, spawn_parent.Faction, PawnGenerationContext.NonPlayer, spawn_parent.Map.Tile, false, true, false, false, false, false, 1, false, true, true, false, false, false, false, null, null, 0, 0, null, skin_whiteness, last_name);

                ////--Log.Message("Hediff_GenericPregnancy::DoBirthSpawn( " + mother_name + ", " + father_name + ", " + chance_successful + " ) - spawning baby");
                Pawn baby = PawnGenerator.GeneratePawn(request);

                if (PawnUtility.TrySpawnHatchedOrBornPawn(baby, mother))
                {
                    if (baby.playerSettings != null && mother.playerSettings != null)
                    {
                        baby.playerSettings.AreaRestriction = mother.playerSettings.AreaRestriction;
                    }
                    if (baby.RaceProps.IsFlesh)
                    {
                        baby.relations.AddDirectRelation(PawnRelationDefOf.Parent, mother);
                        if (father != null)
                        {
                            baby.relations.AddDirectRelation(PawnRelationDefOf.Parent, father);
                        }

                        foreach (Pawn sibling in siblings)
                        {
                            baby.relations.AddDirectRelation(PawnRelationDefOf.Sibling, sibling);
                        }
                        siblings.Add(baby);

                        //inject RJW_BabyState to the newborn if RimWorldChildren is not active
                        if (!xxx.RimWorldChildrenIsActive && baby.kindDef.race == ThingDefOf.Human && baby.ageTracker.CurLifeStageIndex <= 1 && baby.ageTracker.AgeBiologicalYears < 1 && !baby.Dead)
                        {
                            // Clean out drug randomly generated drug addictions
                            baby.health.hediffSet.Clear();
                            baby.health.AddHediff(HediffDef.Named("RJW_BabyState"), null, null);
                            Hediff_SimpleBaby babystate = (Hediff_SimpleBaby)baby.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("RJW_BabyState"));
                            if (babystate != null)
                            {
                                babystate.GrowUpTo(0, true);
                            }
                        }
                    }
                }
                else
                {
                    Find.WorldPawns.PassToWorld(baby, PawnDiscardDecideMode.Discard);
                }
            }

            ////--Log.Message("Hediff_Pregnancy::DoBirthSpawn( " + mother_name + ", " + father_name + ", " + chance_successful + " ) - removing pregnancy");
            mother.health.RemoveHediff(self);

            return(false);
        }
        private void AccelerateHediff(Pawn pawn, int ticks)
        {
            float totalBleedRate = 0;

            using (IEnumerator <Hediff> enumerator = pawn.health.hediffSet.GetHediffs <Hediff>().GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Hediff rec = enumerator.Current;
                    HediffComp_Immunizable immuneComp = rec.TryGetComp <HediffComp_Immunizable>();
                    if (immuneComp != null)
                    {
                        if (immuneComp.Def.CompProps <HediffCompProperties_Immunizable>() != null)
                        {
                            float immuneSevDay = immuneComp.Def.CompProps <HediffCompProperties_Immunizable>().severityPerDayNotImmune;
                            if (immuneSevDay != 0 && !rec.FullyImmune())
                            {
                                rec.Severity += immuneSevDay * ticks * this.parent.Severity / (24 * 2500);
                            }
                        }
                    }
                    HediffComp_SeverityPerDay sevDayComp = rec.TryGetComp <HediffComp_SeverityPerDay>();
                    if (sevDayComp != null)
                    {
                        if (sevDayComp.Def.CompProps <HediffCompProperties_SeverityPerDay>() != null)
                        {
                            float sevDay = sevDayComp.Def.CompProps <HediffCompProperties_SeverityPerDay>().severityPerDay;
                            if (sevDay != 0)
                            {
                                rec.Severity += sevDay * ticks * this.parent.Severity / (24 * 2500);
                            }
                        }
                    }
                    HediffComp_Disappears tickComp = rec.TryGetComp <HediffComp_Disappears>();
                    if (tickComp != null)
                    {
                        int ticksToDisappear = Traverse.Create(root: tickComp).Field(name: "ticksToDisappear").GetValue <int>();
                        if (ticksToDisappear != 0)
                        {
                            Traverse.Create(root: tickComp).Field(name: "ticksToDisappear").SetValue(ticksToDisappear - Mathf.RoundToInt(60 * this.parent.Severity));
                        }
                    }
                    Hediff_Pregnant hdp = this.Pawn.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("Pregnant")) as Hediff_Pregnant;
                    if (hdp != null)
                    {
                        hdp.Severity += 1f / (this.Pawn.RaceProps.gestationPeriodDays * (2500f / this.parent.Severity));
                    }
                    CompEggLayer eggComp = this.Pawn.TryGetComp <CompEggLayer>();
                    if (eggComp != null)
                    {
                        float eggProgress = Traverse.Create(root: eggComp).Field(name: "eggProgress").GetValue <float>();
                        bool  isActive    = Active(eggComp);
                        if (isActive)
                        {
                            eggProgress += 1f / (eggComp.Props.eggLayIntervalDays * (2500f / this.parent.Severity));
                            Traverse.Create(root: eggComp).Field(name: "eggProgress").SetValue(eggProgress);
                        }
                    }
                    //CompHasGatherableBodyResource gatherComp = this.Pawn.TryGetComp<CompHasGatherableBodyResource>();
                    //if (gatherComp != null)
                    //{
                    //    float gatherProgress = gatherComp.Fullness;

                    //    int rate = Traverse.Create(root: gatherComp).Field(name: "GatherResourcesIntervalDays").GetValue<int>();
                    //    bool isActive = Active();
                    //    if (isActive)
                    //    {
                    //        gatherProgress += (1f / ((float)(rate * (2500f / this.parent.Severity))));
                    //        Traverse.Create(root: gatherComp).Field(name: "fullness").SetValue(gatherProgress);
                    //    }
                    //}
                    CompMilkable milkComp = this.Pawn.TryGetComp <CompMilkable>();
                    if (milkComp != null)
                    {
                        float milkProgress = milkComp.Fullness;
                        int   rate         = milkComp.Props.milkIntervalDays;
                        bool  isActive     = Active(milkComp);
                        if (isActive)
                        {
                            milkProgress += 1f / ((float)(rate * (2500f / this.parent.Severity)));
                            Traverse.Create(root: milkComp).Field(name: "fullness").SetValue(milkProgress);
                        }
                    }
                    if (rec.Bleeding)
                    {
                        totalBleedRate += rec.BleedRate;
                    }
                }
                if (totalBleedRate != 0)
                {
                    HealthUtility.AdjustSeverity(pawn, HediffDefOf.BloodLoss, totalBleedRate * 60 * this.parent.Severity / (24 * 2500));
                }
            }
        }
Example #21
0
        public static string AnimalImportantInfo(Pawn p, bool gender = false)
        {
            String e = "";

            // M/F
            if (gender && p.RaceProps.hasGenders)
            {
                if (e.Length > 0)
                {
                    e += ";";
                }
                e += p.gender.ToString().Substring(0, 1);
            }

            // [B]onded
            for (int i = 0; i < p.relations.DirectRelations.Count; i++)
            {
                if (p.relations.DirectRelations[i].def == PawnRelationDefOf.Bond && p.relations.DirectRelations[i].otherPawn.Spawned)
                {
                    //p.relations.DirectRelations[i].otherPawn;
                    if (e.Length > 0)
                    {
                        e += ";";
                    }
                    e += "B";
                    break;
                }
            }

            // [T]rained
            if (p.training != null)
            {
                int trained = 0;
                foreach (TrainableDef current2 in DefDatabase <TrainableDef> .AllDefs)
                {
                    if (p.training.IsCompleted(current2))
                    {
                        trained++;
                    }
                }
                if (trained > 0)
                {
                    if (e.Length > 0)
                    {
                        e += ";";
                    }
                    e += "T" + trained;
                }
            }

            // [P]regnant
            if (p.health.hediffSet.HasHediff(HediffDefOf.Pregnant))
            {
                Hediff_Pregnant hediff_Pregnant = (Hediff_Pregnant)p.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Pregnant);
                if (hediff_Pregnant.Visible)
                {
                    if (e.Length > 0)
                    {
                        e += ";";
                    }
                    e += "P" + hediff_Pregnant.GestationProgress.ToStringPercent();
                }
            }
            return(e);
        }
        public static string AnimalImportantInfo(Pawn p, bool gender = false)
        {
            String e = "";

            // M/F
            if (gender && p.RaceProps.hasGenders)
            {
                if (e.Length > 0)
                {
                    e += ";";
                }
                e += p.gender.ToString().Substring(0, 1);
            }

            // [T]rained
            if (p.training != null)
            {
                int trained = 0;
                foreach (TrainableDef current2 in DefDatabase <TrainableDef> .AllDefs)
                {
                    if (p.training.HasLearned(current2))
                    {
                        trained++;
                    }
                }
                if (trained > 0)
                {
                    if (e.Length > 0)
                    {
                        e += ";";
                    }
                    e += "T" + trained;
                }
            }

            // [P]regnant
            if (p.health.hediffSet.HasHediff(HediffDefOf.Pregnant))
            {
                Hediff_Pregnant hediff_Pregnant = (Hediff_Pregnant)p.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Pregnant);
                if (hediff_Pregnant.Visible)
                {
                    if (e.Length > 0)
                    {
                        e += ";";
                    }
                    e += "P" + hediff_Pregnant.GestationProgress.ToStringPercent();
                }
            }

            // [W]ool
            CompShearable wool = p.TryGetComp <CompShearable>();

            if (wool != null && wool.Fullness > 0.05)
            {
                if (e.Length > 0)
                {
                    e += ";";
                }
                e += "W" + wool.Fullness.ToStringPercent();
            }

            return(e);
        }