Ejemplo n.º 1
0
        // Token: 0x06000434 RID: 1076 RVA: 0x0002D960 File Offset: 0x0002BD60
        private Job FleeJob(Pawn pawn, Thing danger)
        {
            IntVec3 intVec;
            bool    selected = Find.Selector.SelectedObjects.Contains(pawn) && Prefs.DevMode && DebugSettings.godMode;

            if (pawn.CurJob != null && pawn.CurJob.def == JobDefOf.FleeAndCower)
            {
                intVec = pawn.CurJob.targetA.Cell;
            }
            else
            {
                JobGiver_XenomorphFleeFire.tmpThings.Clear();
                JobGiver_XenomorphFleeFire.tmpThings.Add(danger);
                intVec = CellFinderLoose.GetFleeDest(pawn, JobGiver_XenomorphFleeFire.tmpThings, 30f);
                JobGiver_XenomorphFleeFire.tmpThings.Clear();
            }
            if (intVec != pawn.Position)
            {
                if (selected)
                {
                    Log.Message(string.Format("{0} @:{1} is fleeing from {2} @:{3}", pawn.LabelShortCap, pawn.Position, danger.LabelShortCap, danger.Position));
                }
                return(new Job(JobDefOf.FleeAndCower, intVec, danger));
            }
            return(null);
        }
        private IntVec3 FindSafeCell(Pawn pawn)
        {
            List <Thing>         threats             = new List <Thing>();
            List <IAttackTarget> potentialTargetsFor = pawn.Map.attackTargetsCache.GetPotentialTargetsFor(pawn);

            for (int i = 0; i < potentialTargetsFor.Count; i++)
            {
                Thing thing = potentialTargetsFor[i].Thing;
                if (SelfDefenseUtility.ShouldFleeFrom(thing, pawn, checkDistance: false, checkLOS: false))
                {
                    threats.Add(thing);
                }
            }
            List <Thing> thingsToFlee = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.AlwaysFlee);

            for (int j = 0; j < thingsToFlee.Count; j++)
            {
                Thing thing = thingsToFlee[j];
                if (SelfDefenseUtility.ShouldFleeFrom(thing, pawn, checkDistance: false, checkLOS: false))
                {
                    threats.Add(thing);
                }
            }
            return(CellFinderLoose.GetFleeDest(pawn, threats));
        }
Ejemplo n.º 3
0
        public void StartFleeingBecauseOfPawnAction(Thing instigator)
        {
            List <Thing> list = new List <Thing>();

            list.Add(instigator);
            List <Thing> threats  = list;
            IntVec3      fleeDest = CellFinderLoose.GetFleeDest(pawn, threats, pawn.Position.DistanceTo(instigator.Position) + 14f);

            if (fleeDest != pawn.Position)
            {
                pawn.jobs.StartJob(new Job(JobDefOf.Flee, fleeDest, instigator), JobCondition.InterruptOptional);
            }
            if (pawn.RaceProps.herdAnimal && Rand.Chance(0.1f))
            {
                foreach (Pawn packmate in GetPackmates(pawn, 24f))
                {
                    if (CanStartFleeingBecauseOfPawnAction(packmate))
                    {
                        IntVec3 fleeDest2 = CellFinderLoose.GetFleeDest(packmate, threats, packmate.Position.DistanceTo(instigator.Position) + 14f);
                        if (fleeDest2 != packmate.Position)
                        {
                            packmate.jobs.StartJob(new Job(JobDefOf.Flee, fleeDest2, instigator), JobCondition.InterruptOptional);
                        }
                    }
                }
            }
        }
        private void StartFleeingBecauseOfPawnAction(Thing instigator)
        {
            List <Thing> list = new List <Thing>();

            list.Add(instigator);
            List <Thing> threats  = list;
            IntVec3      fleeDest = CellFinderLoose.GetFleeDest(this.pawn, threats, (float)(this.pawn.Position.DistanceTo(instigator.Position) + 14.0));

            if (fleeDest != this.pawn.Position)
            {
                this.pawn.jobs.StartJob(new Job(JobDefOf.Flee, fleeDest, instigator), JobCondition.InterruptOptional, null, false, true, null, null, false);
            }
            if (this.pawn.RaceProps.herdAnimal && Rand.Chance(0.1f))
            {
                foreach (Pawn packmate in this.GetPackmates(this.pawn, 24f))
                {
                    if (Pawn_MindState.CanStartFleeingBecauseOfPawnAction(packmate))
                    {
                        IntVec3 fleeDest2 = CellFinderLoose.GetFleeDest(packmate, threats, (float)(packmate.Position.DistanceTo(instigator.Position) + 14.0));
                        if (fleeDest2 != packmate.Position)
                        {
                            packmate.jobs.StartJob(new Job(JobDefOf.Flee, fleeDest2, instigator), JobCondition.InterruptOptional, null, false, true, null, null, false);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private static Job FleeJob2(Pawn pawn, Thing danger)
        {
            IntVec3 intVec;

            if (pawn.CurJob != null && pawn.CurJob.def == JobDefOf.Flee)
            {
                intVec = pawn.CurJob.targetA.Cell;
            }
            else
            {
                //tmpThings.Clear();
                List <Thing> tmpThings = new List <Thing>
                {
                    danger
                };
                intVec = CellFinderLoose.GetFleeDest(pawn, tmpThings, 24f);
                //tmpThings.Clear();
            }

            if (intVec != pawn.Position)
            {
                return(JobMaker.MakeJob(JobDefOf.Flee, intVec, danger));
            }

            return(null);
        }
        public void ScareAnimals()
        {
            //Select a from animals where a.bodySize <= human && a.intelligence < toolUser && !a.WouldHuntHumans
            IEnumerable <Pawn> pawns = base.parent.Map.mapPawns.AllPawns.Where(x => x.def.race.intelligence == Intelligence.Animal  // x has animal intelligence. I could use RaceProps but this has the potential for
                                                                                                                                    // more flavor, e.g. Ferals mutants fleeing and intelligent animals not
                                                                               && SmallEnoughToScare(x) &&                          // x is small enough to scare
                                                                               IsAffectedPredator(x) &&                             // x wouldn't prey upon colonists
                                                                               ShouldAffectColonyAnimal(x));                        // if set for colony animals to ignore it, they will

            if (pawns == null || pawns.Count() <= 0)
            {
                return;
            }
            //for all animals
            foreach (Pawn animal in pawns)
            {
                //if animal is nearby and not already fleeing
                if (animal != null && animal.jobs?.curJob?.def != JobDefOf.Flee && IntVec3Utility.DistanceTo(animal.Position, base.parent.Position) < Radius)
                {
                    //give the animal the flee job with parent as the thing they're fleeing
                    Job job = new Job(JobDefOf.Flee,
                                      // Note that the below thing only treats things of the parent's def as dangerous. Done for performance reasons.
                                      // Not an issue with the mod as written, since VFE_Scarecrow is a single def, but could cause minor issues if the design changes.
                                      CellFinderLoose.GetFleeDest(animal, base.parent.Map.listerThings.ThingsOfDef(base.parent.def), Props.minFleeDistance),
                                      base.parent.Position);
                    animal.jobs.StartJob(job, JobCondition.InterruptOptional);
                }
            }
        }
        private Job FleeJob(Pawn pawn, Thing danger)
        {
            IntVec3 intVec;

            if (pawn.CurJob != null && pawn.CurJob.def == JobDefOf.Flee)
            {
                intVec = pawn.CurJob.targetA.Cell;
            }
            else
            {
                JobGiver_AnimalFlee.tmpThings.Clear();
                JobGiver_AnimalFlee.tmpThings.Add(danger);
                intVec = CellFinderLoose.GetFleeDest(pawn, JobGiver_AnimalFlee.tmpThings, 24f);
                JobGiver_AnimalFlee.tmpThings.Clear();
            }
            Job result;

            if (intVec != pawn.Position)
            {
                result = new Job(JobDefOf.Flee, intVec, danger);
            }
            else
            {
                result = null;
            }
            return(result);
        }
Ejemplo n.º 8
0
        private void StartFleeingBecauseOfPawnAction(Thing instigator)
        {
            List <Thing> threats = new List <Thing>
            {
                instigator
            };
            IntVec3 fleeDest = CellFinderLoose.GetFleeDest(this.pawn, threats, this.pawn.Position.DistanceTo(instigator.Position) + 14f);

            if (fleeDest != this.pawn.Position)
            {
                this.pawn.jobs.StartJob(new Job(JobDefOf.Flee, fleeDest, instigator), JobCondition.InterruptOptional, null, false, true, null, null, false);
            }
            if (this.pawn.RaceProps.herdAnimal && Rand.Chance(0.1f))
            {
                foreach (Pawn current in this.GetPackmates(this.pawn, 24f))
                {
                    if (Pawn_MindState.CanStartFleeingBecauseOfPawnAction(current))
                    {
                        IntVec3 fleeDest2 = CellFinderLoose.GetFleeDest(current, threats, current.Position.DistanceTo(instigator.Position) + 14f);
                        if (fleeDest2 != current.Position)
                        {
                            current.jobs.StartJob(new Job(JobDefOf.Flee, fleeDest2, instigator), JobCondition.InterruptOptional, null, false, true, null, null, false);
                        }
                    }
                }
            }
        }
        public static void MakeFlee(Pawn pawn, Thing danger, int radius, List <Thing> dangers)
        {
            Job     job = null;
            IntVec3 intVec;

            if (pawn.CurJob != null && pawn.CurJob.def == JobDefOf.Flee)
            {
                intVec = pawn.CurJob.targetA.Cell;
            }
            else
            {
                intVec = CellFinderLoose.GetFleeDest(pawn, dangers, 24f);
            }

            if (intVec == pawn.Position)
            {
                intVec = GenRadial.RadialCellsAround(pawn.Position, radius, radius * 2).RandomElement();
            }
            if (intVec != pawn.Position)
            {
                job = JobMaker.MakeJob(JobDefOf.Flee, intVec, danger);
            }
            if (job != null)
            {
                //Log.Message(pawn + " flee");
                pawn.jobs.TryTakeOrderedJob(job);
            }
        }
Ejemplo n.º 10
0
        public static void MakeFlee(Pawn pawn, Thing danger)
        {
            Job     job = null;
            IntVec3 intVec;

            if (pawn.CurJob != null && pawn.CurJob.def == JobDefOf.Flee)
            {
                intVec = pawn.CurJob.targetA.Cell;
            }
            else
            {
                var          dangers = new List <Thing>();
                List <Thing> list    = new List <Thing>();
                foreach (var dir in GenRadial.RadialCellsAround(pawn.Position, 5, true))
                {
                    if (GenGrid.InBounds(dir, pawn.Map))
                    {
                        try
                        {
                            if (GenGrid.InBounds(pawn.Position, pawn.Map))
                            {
                                list = pawn.Map.thingGrid.ThingsListAt(pawn.Position);
                            }
                        }
                        catch
                        {
                            return;
                        }

                        foreach (var t in list)
                        {
                            if (t is PurpleGas || t.Faction == PurpleIvyData.AlienFaction)
                            {
                                dangers.Add(t);
                            }
                        }
                    }
                }
                intVec = CellFinderLoose.GetFleeDest(pawn, dangers, 24f);
            }

            if (intVec == pawn.Position)
            {
                intVec = GenRadial.RadialCellsAround(pawn.Position, 6, 6).RandomElement();
            }
            if (intVec != pawn.Position)
            {
                job = JobMaker.MakeJob(JobDefOf.Flee, intVec, danger);
            }
            if (job != null)
            {
                Log.Message(pawn + " flee");
                pawn.jobs.TryTakeOrderedJob(job);
            }
        }
        private Job TryGetFleeJob(Pawn pawn)
        {
            if (!SelfDefenseUtility.ShouldStartFleeing(pawn))
            {
                return(null);
            }
            IntVec3 c;

            if (pawn.CurJob != null && pawn.CurJob.def == JobDefOf.FleeAndCower)
            {
                c = pawn.CurJob.targetA.Cell;
            }
            else
            {
                JobGiver_ConfigurableHostilityResponse.tmpThreats.Clear();
                List <IAttackTarget> potentialTargetsFor = pawn.Map.attackTargetsCache.GetPotentialTargetsFor(pawn);
                for (int i = 0; i < potentialTargetsFor.Count; i++)
                {
                    Thing thing = potentialTargetsFor[i].Thing;
                    if (SelfDefenseUtility.ShouldFleeFrom(thing, pawn, false, false))
                    {
                        JobGiver_ConfigurableHostilityResponse.tmpThreats.Add(thing);
                    }
                }
                List <Thing> list = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.AlwaysFlee);
                for (int j = 0; j < list.Count; j++)
                {
                    Thing thing2 = list[j];
                    if (SelfDefenseUtility.ShouldFleeFrom(thing2, pawn, false, false))
                    {
                        JobGiver_ConfigurableHostilityResponse.tmpThreats.Add(thing2);
                    }
                }
                if (!JobGiver_ConfigurableHostilityResponse.tmpThreats.Any <Thing>())
                {
                    Log.Warning(pawn.LabelShort + " decided to flee but there is no any threat around.");
                    return(null);
                }
                c = CellFinderLoose.GetFleeDest(pawn, JobGiver_ConfigurableHostilityResponse.tmpThreats, 23f);
                JobGiver_ConfigurableHostilityResponse.tmpThreats.Clear();
            }
            return(new Job(JobDefOf.FleeAndCower, c));
        }
Ejemplo n.º 12
0
 static void Postfix(Bombardment __instance)
 {
     RegionTraverser.BreadthFirstTraverse(__instance.Position, __instance.Map, (from, to) => true, region =>
     {
         region.ListerThings.ThingsInGroup(ThingRequestGroup.Pawn)
         .Select(p => (Pawn)p)
         .Where(p => !p.Downed && !p.Dead && !p.Drafted)
         .Where(p => p.CurJobDef != JobDefOf.Flee && !p.Downed)
         .Where(p => p.Position.DistanceTo(__instance.Position) <= 24.0f)
         .ToList()
         .ForEach(pawn =>
         {
             var threats = new List <Thing> {
                 __instance
             };
             var fleeDest1 = CellFinderLoose.GetFleeDest(pawn, threats, pawn.Position.DistanceTo(__instance.Position) + Bombardment.EffectiveRadius);
             pawn.jobs.StartJob(new Job(JobDefOf.Flee, fleeDest1, (LocalTargetInfo)__instance), JobCondition.InterruptOptional, null, false, true, null, new JobTag?());
         });
         return(false);
     }, 25, RegionType.Set_All);
 }
        private Job FleeJob(Pawn pawn, Thing danger)
        {
            IntVec3 intVec;

            if (pawn.CurJob != null && pawn.CurJob.def == JobDefOf.Flee)
            {
                intVec = pawn.CurJob.targetA.Cell;
            }
            else
            {
                tmpThings.Clear();
                tmpThings.Add(danger);
                intVec = CellFinderLoose.GetFleeDest(pawn, tmpThings, 24f);
                tmpThings.Clear();
            }
            if (intVec != pawn.Position)
            {
                return(JobMaker.MakeJob(JobDefOf.Flee, intVec, danger));
            }
            return(null);
        }
        // Token: 0x06000434 RID: 1076 RVA: 0x0002D960 File Offset: 0x0002BD60
        private Job FleeJob(Pawn pawn, Thing danger)
        {
            IntVec3 intVec;

            if (pawn.CurJob != null && pawn.CurJob.def == JobDefOf.FleeAndCower)
            {
                intVec = pawn.CurJob.targetA.Cell;
            }
            else
            {
                JobGiver_Xenomorph_Flee.tmpThings.Clear();
                JobGiver_Xenomorph_Flee.tmpThings.Add(danger);
                intVec = CellFinderLoose.GetFleeDest(pawn, JobGiver_Xenomorph_Flee.tmpThings, 30f);
                JobGiver_Xenomorph_Flee.tmpThings.Clear();
            }
            if (intVec != pawn.Position)
            {
                return(new Job(JobDefOf.FleeAndCower, intVec, danger));
            }
            return(null);
        }
        private Job FleeJob(Pawn pawn, Thing danger)
        {
            IntVec3 intVec;

            if (pawn.CurJob != null && pawn.CurJob.def == JobDefOf.Flee)
            {
                intVec = pawn.CurJob.targetA.Cell;
            }
            else
            {
                intVec = CellFinderLoose.GetFleeDest(pawn, new List <Thing>
                {
                    danger
                }, 18f);
            }
            if (intVec != pawn.Position)
            {
                return(new Job(JobDefOf.Flee, intVec, danger));
            }
            return(null);
        }
Ejemplo n.º 16
0
        public override void CompTick()
        {
            if (hasWarned)
            {
                if (lastWarned > GenTicks.TicksGame + GenTicks.SecondsToTicks(3))
                {
                    hasWarned = false;
                }
            }
            base.CompTick();

            if (Props.hediff != null)
            {
                foreach (Pawn p in parent.Map.mapPawns.AllPawns)
                {
                    if (p.Position == parent.Position)
                    {
                        if (!p.Downed)
                        {
                            HealthUtility.AdjustSeverity(p, Props.hediff, Props.severity);
                        }
                        else
                        {
                            HealthUtility.AdjustSeverity(p, Props.hediff, Props.severity / 4);
                        }

                        if (Props.warn && Math.Abs(p.health.hediffSet.GetFirstHediffOfDef(Props.hediff).Severity - Props.severity) < double.Epsilon && p.Faction != null && p.Faction.IsPlayer)
                        {
                            Messages.Message(p.Name + " has walked into a " + parent.Label, p, MessageTypeDefOf.ThreatSmall);
                        }

                        if ((Props.forceFlee && !p.Downed && p.Faction != null && p.Faction.IsPlayer && p.Drafted && p.health.hediffSet.GetFirstHediffOfDef(Props.hediff).Severity > 0.7) ||
                            (Props.forceFlee && !p.Downed && (p.health.hediffSet.GetFirstHediffOfDef(Props.hediff).Severity > 0.7)) ||
                            (p.health.hediffSet.GetFirstHediffOfDef(Props.hediff).Severity > 0.5 && !(p.Faction != null && p.Faction.IsPlayer && p.Drafted) && p.CurJob?.def != JobDefOf.Flee && !((Props.releasedBy == CompProperties_AuraParticle.Parent.Plant && workingOnPlant(p)) ||
                                                                                                                                                                                                   (Props.releasedBy == CompProperties_AuraParticle.Parent.Animal && workingOnAnimal(p)) ||
                                                                                                                                                                                                   (Props.releasedBy == CompProperties_AuraParticle.Parent.Building && workingOnBuilding(p)) ||
                                                                                                                                                                                                   (Props.releasedBy == CompProperties_AuraParticle.Parent.Item && workingOnItem(p)))))
                        {
                            if (GenTicks.TicksGame - startTicks > GenTicks.SecondsToTicks(0.5f))
                            {
                                if (Props.warn && p.Faction != null && p.Faction.IsPlayer && !hasWarned)
                                {
                                    Messages.Message(p.Name + " is fleeing from a " + parent.Label, p, MessageTypeDefOf.ThreatSmall);
                                    hasWarned  = true;
                                    lastWarned = GenTicks.TicksGame;
                                }
                                IntVec3 dest = CellFinderLoose.GetFleeDest(p, new List <Thing> {
                                    parent
                                }, 8f);
                                if (dest == parent.Position)
                                {
                                    dest = dest.RandomAdjacentCell8Way();
                                }
                                p.jobs?.TryTakeOrderedJob(new Job(JobDefOf.Flee, dest), JobTag.Escaping);
                            }
                        }
                    }
                }
            }

            if (GenTicks.TicksGame > startTicks + GenTicks.SecondsToTicks(Props.duration))
            {
                parent.Destroy();
            }
        }
        public static bool TryGetFleeJob(JobGiver_ConfigurableHostilityResponse __instance, ref Job __result, Pawn pawn)
        {
            if (!SelfDefenseUtility.ShouldStartFleeing(pawn))
            {
                __result = null;
                return(false);
            }

            IntVec3 c;

            if (pawn.CurJob != null && pawn.CurJob.def == JobDefOf.FleeAndCower)
            {
                c = pawn.CurJob.targetA.Cell;
            }
            else
            {
                //tmpThreats.Clear();
                List <Thing>         tmpThreats          = new List <Thing>();
                List <IAttackTarget> potentialTargetsFor = pawn.Map.attackTargetsCache.GetPotentialTargetsFor(pawn);
                for (int i = 0; i < potentialTargetsFor.Count; i++)
                {
                    Thing thing = potentialTargetsFor[i].Thing;
                    if (SelfDefenseUtility.ShouldFleeFrom(thing, pawn, checkDistance: false, checkLOS: false))
                    {
                        tmpThreats.Add(thing);
                    }
                }

                List <Thing> list = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.AlwaysFlee);
                for (int j = 0; j < list.Count; j++)
                {
                    Thing thing2 = list[j];
                    if (SelfDefenseUtility.ShouldFleeFrom(thing2, pawn, checkDistance: false, checkLOS: false))
                    {
                        tmpThreats.Add(thing2);
                    }
                }

                if (!tmpThreats.Any())
                {
                    Log.Error(pawn.LabelShort + " decided to flee but there is not any threat around.");
                    Region region = pawn.GetRegion();
                    if (region == null)
                    {
                        __result = null;
                        return(false);
                    }

                    RegionTraverser.BreadthFirstTraverse(region, (Region from, Region reg) => reg.door == null || reg.door.Open, delegate(Region reg)
                    {
                        List <Thing> list2 = reg.ListerThings.ThingsInGroup(ThingRequestGroup.AttackTarget);
                        for (int k = 0; k < list2.Count; k++)
                        {
                            Thing thing3 = list2[k];
                            if (SelfDefenseUtility.ShouldFleeFrom(thing3, pawn, checkDistance: false, checkLOS: false))
                            {
                                tmpThreats.Add(thing3);
                                Log.Warning($"  Found a viable threat {thing3.LabelShort}; tests are {thing3.Map.attackTargetsCache.Debug_CheckIfInAllTargets(thing3 as IAttackTarget)}, {thing3.Map.attackTargetsCache.Debug_CheckIfHostileToFaction(pawn.Faction, thing3 as IAttackTarget)}, {thing3 is IAttackTarget}");
                            }
                        }

                        return(false);
                    }, 9);
                    if (!tmpThreats.Any())
                    {
                        __result = null;
                        return(false);
                    }
                }

                c = CellFinderLoose.GetFleeDest(pawn, tmpThreats);
                //tmpThreats.Clear();
            }

            __result = JobMaker.MakeJob(JobDefOf.FleeAndCower, c);
            return(false);
        }
Ejemplo n.º 18
0
        private Job FleeJob(Pawn pawn, Thing danger)
        {
            IntVec3 intVec = (pawn.CurJob == null || pawn.CurJob.def != JobDefOf.Flee) ? CellFinderLoose.GetFleeDest(pawn, new List <Thing>
            {
                danger
            }, 18f) : pawn.CurJob.targetA.Cell;

            if (intVec != pawn.Position)
            {
                return(new Job(JobDefOf.Flee, intVec, danger));
            }
            return(null);
        }
Ejemplo n.º 19
0
        public static void HandleWitnessesOf(JobDef crime, Pawn criminal, Pawn victim)
        {
            if (!criminal.IsVampire())
            {
                return;
            }

            Crime?curCrime = GetCrime(crime);

            if (curCrime == null)
            {
                return;
            }

            //Log.Message("1");
            List <Pawn> witnesses = WitnessesOf(criminal, victim, crime);

            //Log.Message("2");


            if (!witnesses.NullOrEmpty())
            {
                //Log.Message("Loop 1 Enter");


                foreach (Pawn witness in witnesses)
                {
                    //Log.Message("Loop 1 Step 1");

                    //Log.Message("Loop 1 Step 2");

                    Thought_MemoryObservation thought_MemoryObservation = null;
                    //Log.Message("Loop 1 Step 3");

                    switch (witness.GetReactionTo(criminal, victim))
                    {
                    case CrimeReaction.MoodColonist:
                        if (curCrime.Value.ColonistThought != null)
                        {
                            thought_MemoryObservation =
                                (Thought_MemoryObservation)ThoughtMaker
                                .MakeThought(curCrime.Value.ColonistThought);
                        }
                        break;

                    case CrimeReaction.MoodVisitor:
                        if (curCrime.Value.VisitorThought != null)
                        {
                            thought_MemoryObservation =
                                (Thought_MemoryObservation)ThoughtMaker
                                .MakeThought(curCrime.Value.VisitorThought);
                        }
                        break;

                    case CrimeReaction.MoodVisitorFlee:
                        if (curCrime.Value.VisitorThought != null)
                        {
                            thought_MemoryObservation =
                                (Thought_MemoryObservation)ThoughtMaker
                                .MakeThought(curCrime.Value.VisitorThought);
                        }
                        if (CanTakeWitnessJob(witness))
                        {
                            IntVec3 fleeLoc = CellFinderLoose.GetFleeDest(witness, new List <Thing>()
                            {
                                criminal
                            });
                            witness.jobs.StartJob(new Job(JobDefOf.FleeAndCower, fleeLoc));
                            if (witness.Faction != null && !witness.Faction.HostileTo(criminal.Faction))
                            {
                                witness.Faction.TrySetRelationKind(criminal.Faction, FactionRelationKind.Hostile);
                            }
                        }
                        break;

                    case CrimeReaction.MoodVisitorAggro:
                        if (curCrime.Value.VisitorThought != null)
                        {
                            thought_MemoryObservation =
                                (Thought_MemoryObservation)ThoughtMaker
                                .MakeThought(curCrime.Value.VisitorThought);
                        }
                        if (CanTakeWitnessJob(witness))
                        {
                            witness.jobs.StartJob(new Job(JobDefOf.AttackMelee, criminal));
                            if (witness.Faction != null && !witness.Faction.HostileTo(criminal.Faction))
                            {
                                witness.Faction.TrySetRelationKind(criminal.Faction, FactionRelationKind.Hostile);
                            }
                        }
                        break;
                    }
                    //Log.Message("Loop 1 Step 6");

                    if (thought_MemoryObservation != null)
                    {
                        //Log.Message("Loop 1 Step 7");
                        thought_MemoryObservation.Target = criminal;
                        //Log.Message("Loop 1 Step 8");

                        witness.needs.mood.thoughts.memories.TryGainMemory(thought_MemoryObservation);
                        //Log.Message("Loop 1 Step 9");
                    }
                }
            }
        }
Ejemplo n.º 20
0
        public override void CompTick()
        {
            if (hasWarned)
            {
                if (lastWarned > GenTicks.TicksGame + GenTicks.SecondsToTicks(3))
                {
                    hasWarned = false;
                }
            }
            Map map = base.parent.Map;

            if (this.Props == null)
            {
                return;
            }
            base.CompTick();
            if (this.Props.hediff != null)
            {
                if (base.parent.Position.GetFirstPawn(map) != null)
                {
                    foreach (Pawn p in map.mapPawns.AllPawns)
                    {
                        if (p.Position == base.parent.Position)
                        {
                            if (!p.Downed)
                            {
                                HealthUtility.AdjustSeverity(p, HediffDef.Named(this.Props.hediff), this.Props.severity);
                            }
                            else
                            {
                                HealthUtility.AdjustSeverity(p, HediffDef.Named(this.Props.hediff), this.Props.severity / 4);
                            }

                            //Log.Error("1");

                            if (Props.warn && Math.Abs(p.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named(this.Props.hediff)).Severity - this.Props.severity) < Double.Epsilon && p.Faction != null && p.Faction.IsPlayer)
                            {
                                Messages.Message(p.Name + " has walked into a " + this.parent.Label, p, MessageTypeDefOf.ThreatSmall);
                            }
                            //Log.Error("2");
                            if (Props.forceFlee && !p.Downed && (p.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named(this.Props.hediff)).Severity > 0.7) || (p.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named(this.Props.hediff)).Severity > 0.5 && !(p.Faction != null && p.Faction.IsPlayer && p.Drafted) && p.CurJob?.def != JobDefOf.Flee && !((this.Props.releasedBy == CompProperties_AuraParticle.Parent.plant && Plant(p)) || (this.Props.releasedBy == CompProperties_AuraParticle.Parent.animal && Animal(p)) || (this.Props.releasedBy == CompProperties_AuraParticle.Parent.building && Building(p) || (this.Props.releasedBy == CompProperties_AuraParticle.Parent.item && Item(p))))))
                            {
                                if (GenTicks.TicksGame - count > GenTicks.SecondsToTicks(0.5f))
                                {
                                    if (Props.warn && p.Faction != null && p.Faction.IsPlayer && !hasWarned)
                                    {
                                        Messages.Message(p.Name + " is fleeing from a " + this.parent.Label, p, MessageTypeDefOf.ThreatSmall);
                                        hasWarned  = true;
                                        lastWarned = GenTicks.TicksGame;
                                    }
                                    IntVec3 dest = CellFinderLoose.GetFleeDest(p, new List <Thing> {
                                        this.parent
                                    }, 8f);
                                    if (dest == this.parent.Position)
                                    {
                                        dest = dest.RandomAdjacentCell8Way();
                                    }
                                    p.jobs?.TryTakeOrderedJob(new Job(JobDefOf.Flee, dest), JobTag.Escaping);
                                }
                            }
                            else
                            {
                                //Log.Error("3");
                                if (Props.forceFlee && !p.Downed && p.Faction != null && p.Faction.IsPlayer && p.Drafted && p.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named(this.Props.hediff)).Severity > 0.7)
                                {
                                    if (GenTicks.TicksGame - count > GenTicks.SecondsToTicks(0.5f))
                                    {
                                        if (Props.warn && Props.forceFlee && p.Faction != null && p.Faction.IsPlayer && !hasWarned)
                                        {
                                            Messages.Message(p.Name + " is fleeing from a " + this.parent.Label, p, MessageTypeDefOf.ThreatSmall);
                                            hasWarned  = true;
                                            lastWarned = GenTicks.TicksGame;
                                        }
                                        IntVec3 dest = CellFinderLoose.GetFleeDest(p, new List <Thing> {
                                            this.parent
                                        }, 8f);
                                        if (dest == this.parent.Position)
                                        {
                                            dest = dest.RandomAdjacentCell8Way();
                                        }
                                        p.jobs?.TryTakeOrderedJob(new Job(JobDefOf.Flee, dest), JobTag.Escaping);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (GenTicks.TicksGame > count + GenTicks.SecondsToTicks(Props.duration))
            {
                base.parent.Destroy();
            }
        }
Ejemplo n.º 21
0
        private Job TryGetFleeJob(Pawn pawn)
        {
            if (!SelfDefenseUtility.ShouldStartFleeing(pawn))
            {
                return(null);
            }
            IntVec3 c;

            if (pawn.CurJob != null && pawn.CurJob.def == JobDefOf.FleeAndCower)
            {
                c = pawn.CurJob.targetA.Cell;
            }
            else
            {
                JobGiver_ConfigurableHostilityResponse.tmpThreats.Clear();
                List <IAttackTarget> potentialTargetsFor = pawn.Map.attackTargetsCache.GetPotentialTargetsFor(pawn);
                for (int i = 0; i < potentialTargetsFor.Count; i++)
                {
                    Thing thing = potentialTargetsFor[i].Thing;
                    if (SelfDefenseUtility.ShouldFleeFrom(thing, pawn, false, false))
                    {
                        JobGiver_ConfigurableHostilityResponse.tmpThreats.Add(thing);
                    }
                }
                List <Thing> list = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.AlwaysFlee);
                for (int j = 0; j < list.Count; j++)
                {
                    Thing thing2 = list[j];
                    if (SelfDefenseUtility.ShouldFleeFrom(thing2, pawn, false, false))
                    {
                        JobGiver_ConfigurableHostilityResponse.tmpThreats.Add(thing2);
                    }
                }
                if (!JobGiver_ConfigurableHostilityResponse.tmpThreats.Any <Thing>())
                {
                    Log.Error(pawn.LabelShort + " decided to flee but there is not any threat around.", false);
                    Region region = pawn.GetRegion(RegionType.Set_Passable);
                    if (region == null)
                    {
                        return(null);
                    }
                    RegionTraverser.BreadthFirstTraverse(region, (Region from, Region reg) => reg.door == null || reg.door.Open, delegate(Region reg)
                    {
                        List <Thing> list2 = reg.ListerThings.ThingsInGroup(ThingRequestGroup.AttackTarget);
                        for (int k = 0; k < list2.Count; k++)
                        {
                            Thing thing3 = list2[k];
                            if (SelfDefenseUtility.ShouldFleeFrom(thing3, pawn, false, false))
                            {
                                JobGiver_ConfigurableHostilityResponse.tmpThreats.Add(thing3);
                                Log.Warning(string.Format("  Found a viable threat {0}; tests are {1}, {2}, {3}", new object[]
                                {
                                    thing3.LabelShort,
                                    thing3.Map.attackTargetsCache.Debug_CheckIfInAllTargets(thing3 as IAttackTarget),
                                    thing3.Map.attackTargetsCache.Debug_CheckIfHostileToFaction(pawn.Faction, thing3 as IAttackTarget),
                                    thing3 is IAttackTarget
                                }), false);
                            }
                        }
                        return(false);
                    }, 9, RegionType.Set_Passable);
                    if (!JobGiver_ConfigurableHostilityResponse.tmpThreats.Any <Thing>())
                    {
                        return(null);
                    }
                }
                c = CellFinderLoose.GetFleeDest(pawn, JobGiver_ConfigurableHostilityResponse.tmpThreats, 23f);
                JobGiver_ConfigurableHostilityResponse.tmpThreats.Clear();
            }
            return(new Job(JobDefOf.FleeAndCower, c));
        }
Ejemplo n.º 22
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            Room room = pawn.GetRoom(RegionType.Set_Passable);

            if (room != null)
            {
                if (room.PsychologicallyOutdoors)
                {
                    Area area = pawn.MapHeld.areaManager.Home;
                    if (area != null)
                    {
                        if (area.ActiveCells.FirstOrDefault(x => x.Roofed(pawn.Map) && x.Walkable(pawn.Map)) is IntVec3 safePlace && !IsZero(safePlace) && safePlace.IsValid)
                        {
                            //Log.Message("Safe Place");
                            return(new Job(JobDefOf.Goto, safePlace)
                            {
                                locomotionUrgency = LocomotionUrgency.Sprint
                            });
                        }
                    }


                    Thing thing = GenClosest.ClosestThingReachable(pawn.PositionHeld, pawn.Map, ThingRequest.ForDef(ThingDefOf.Fire), PathEndMode.Touch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 23, null, null, 0, -1, false, RegionType.Set_Passable, false);
                    if (thing != null)
                    {
                        //Log.Message("Flee Place");

                        IntVec3 fleeLoc = CellFinderLoose.GetFleeDest(pawn, new List <Thing>()
                        {
                            thing
                        }, 23);
                        return(new Job(JobDefOf.FleeAndCower, thing));
                    }

                    Region region;
                    CellFinder.TryFindClosestRegionWith(pawn.GetRegion(RegionType.Set_Passable), TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn), (x => !x.Room.PsychologicallyOutdoors), 9999, out region, RegionType.Set_All);   //.ClosestRegionIndoors(pawn.Position, pawn.Map, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), RegionType.Set_Passable);
                    if (region != null)
                    {
                        IntVec3 result;
                        if (region.TryFindRandomCellInRegion(x => !IsZero(x) && x.IsValid && x.InBounds(pawn.MapHeld) && x.GetDoor(pawn.MapHeld) == null, out result))
                        {
                            //Log.Message("Region Place");

                            return(new Job(JobDefOf.Goto, result)
                            {
                                locomotionUrgency = LocomotionUrgency.Sprint
                            });
                        }
                    }
                    IntVec3?cellResult = null;
                    cellResult = CellFinderLoose.RandomCellWith(x => !IsZero(x) && x.IsValid && x.InBounds(pawn.MapHeld) && x.Roofed(pawn.MapHeld) && x.Walkable(pawn.MapHeld) &&
                                                                pawn.Map.reachability.CanReach(pawn.PositionHeld, x, PathEndMode.OnCell, TraverseMode.ByPawn, Danger.Deadly), pawn.MapHeld, 1000);
                    if (cellResult != null && cellResult.Value.IsValid && !IsZero(cellResult.Value))
                    {
                        //Log.Message("Random Place");

                        return(new Job(JobDefOf.Goto, cellResult.Value)
                        {
                            locomotionUrgency = LocomotionUrgency.Sprint
                        });
                    }

                    if (pawn.Faction != pawn.Map.ParentFaction)
                    {
                        bool flag = false;
                        if (pawn.mindState.duty != null && pawn.mindState.duty.canDig)
                        {
                            flag = true;
                        }
                        IntVec3 c;
                        if (RCellFinder.TryFindBestExitSpot(pawn, out c, (!flag) ? TraverseMode.ByPawn : TraverseMode.PassAllDestroyableThings))
                        {
                            if (flag)
                            {
                                using (PawnPath pawnPath = pawn.Map.pathFinder.FindPath(pawn.Position, c, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings, false), PathEndMode.OnCell))
                                {
                                    IntVec3 cellBeforeBlocker;
                                    Thing   thingY = pawnPath.FirstBlockingBuilding(out cellBeforeBlocker, pawn);
                                    if (thingY != null)
                                    {
                                        Job job = DigUtility.PassBlockerJob(pawn, thingY, cellBeforeBlocker, true);
                                        if (job != null)
                                        {
                                            return(job);
                                        }
                                    }
                                }
                            }
                            return(new Job(JobDefOf.Goto, c)
                            {
                                exitMapOnArrival = true,
                                locomotionUrgency = PawnUtility.ResolveLocomotion(pawn, LocomotionUrgency.Sprint, LocomotionUrgency.Jog),
                                expiryInterval = 400,
                                canBash = true
                            });
                        }
                    }

                    IntVec3?hideyHoleResult = null;
                    hideyHoleResult = VampireUtility.FindHideyHoleSpot(VampDefOf.ROMV_HideyHole, Rot4.Random, pawn.PositionHeld, pawn.MapHeld);
                    if (hideyHoleResult != null && hideyHoleResult.Value.IsValid)
                    {
                        //Log.Message("Hidey Place");

                        return(new Job(VampDefOf.ROMV_DigAndHide, hideyHoleResult.Value)
                        {
                            locomotionUrgency = LocomotionUrgency.Sprint
                        });
                    }
                }
                //bool nextMoveOrderIsWait = pawn.mindState.nextMoveOrderIsWait;
                //pawn.mindState.nextMoveOrderIsWait = !pawn.mindState.nextMoveOrderIsWait;
                //if (nextMoveOrderIsWait)
                //{
                //    return new Job(JobDefOf.WaitWander)
                //    {
                //        expiryInterval = this.ticksBetweenWandersRange.RandomInRange
                //    };
                //}
                //IntVec3 exactWanderDest = this.GetExactWanderDest(pawn);
                //if (!exactWanderDest.IsValid)
                //{
                //    pawn.mindState.nextMoveOrderIsWait = false;
                //    return null;
                //}
                //pawn.Map.pawnDestinationManager.ReserveDestinationFor(pawn, exactWanderDest);
                //return new Job(JobDefOf.GotoWander, exactWanderDest)
                //{
                //    locomotionUrgency = this.locomotionUrgency
                //};
            }
            return(null);
        }