Ejemplo n.º 1
0
 public static bool Prefix(Map map, IntVec3 __result)
 {
     ///Predicate<IntVec3> validator, Map map, float roadChance, out IntVec3 result
     // don't drop on deep water
     __result = CellFinderLoose.RandomCellWith((IntVec3 c) => c.Standable(map) && !c.GetTerrain(map).HasTag("TKKN_Swim") && !c.Roofed(map) && !c.Fogged(map), map, 1000);
     return(true);
 }
Ejemplo n.º 2
0
        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);
            }
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            var map               = (Map)parms.target;
            int num               = 0;
            int countToSpawn      = this.CountToSpawn;
            var list              = new List <TargetInfo>();
            var shrapnelDirection = Rand.Range(0f, 360f);

            for (int i = 0; i < countToSpawn; i++)
            {
                IntVec3 intVec = default(IntVec3);
                if (!CellFinderLoose.TryFindSkyfallerCell(ThingDefOf.CrashedShipPartIncoming, map, out intVec, 14, default(IntVec3), -1, false, true, true, true, true, false, null))
                {
                    break;
                }
                var building_CrashedShipPart = (Building_CrashedShipPart)ThingMaker.MakeThing(def.shipPart, null);
                building_CrashedShipPart.SetFaction(Faction.OfMechanoids, null);
                building_CrashedShipPart.GetComp <CompSpawnerMechanoidsOnDamaged>().pointsLeft = Mathf.Max(parms.points * ShipPointsFactor, 300f);
                var skyfaller = SkyfallerMaker.MakeSkyfaller(ThingDefOf.CrashedShipPartIncoming, building_CrashedShipPart);
                skyfaller.shrapnelDirection = shrapnelDirection;
                GenSpawn.Spawn(skyfaller, intVec, map, WipeMode.Vanish);
                num++;
                list.Add(new TargetInfo(intVec, map, false));
            }
            if (num > 0)
            {
                SendStandardLetter(list, null);
            }
            return(num > 0);
        }
Ejemplo n.º 4
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);
        }
        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.º 6
0
 // Token: 0x06002764 RID: 10084 RVA: 0x0012C518 File Offset: 0x0012A918
 public static void DropThingGroupsNear(IntVec3 dropCenter, Map map, List <List <Thing> > thingsGroups, int openDelay = 110, bool instaDrop = false, bool leaveSlag = false, bool canRoofPunch = true)
 {
     foreach (List <Thing> list in thingsGroups)
     {
         IntVec3 intVec;
         if (!DropCellFinder.TryFindDropSpotNear(dropCenter, map, out intVec, true, canRoofPunch))
         {
             Log.Warning(string.Concat(new object[]
             {
                 "DropThingsNear failed to find a place to drop ",
                 list.FirstOrDefault <Thing>(),
                 " near ",
                 dropCenter,
                 ". Dropping on random square instead."
             }));
             intVec = CellFinderLoose.RandomCellWith((IntVec3 c) => c.Walkable(map) && (c.Roofed(map) && c.GetRoof(map) != RoofDefOf.RoofRockThick), map, 1000);
         }
         for (int i = 0; i < list.Count; i++)
         {
             list[i].SetForbidden(true, false);
         }
         foreach (Thing thing in list)
         {
             //    Log.Message(string.Format("revealing infiltrator: {0}, @: {1}, {2}", thing, intVec, map));
             GenPlace.TryPlaceThing(thing, intVec, map, ThingPlaceMode.Near, null, null);
         }
     }
 }
Ejemplo n.º 7
0
        // Token: 0x06000EA8 RID: 3752 RVA: 0x0006C254 File Offset: 0x0006A654
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map                = (Map)parms.target;
            int num                = 0;
            int countToSpawn       = this.CountToSpawn;
            List <TargetInfo> list = new List <TargetInfo>();
            float             shrapnelDirection = Rand.Range(0f, 360f);

            for (int i = 0; i < countToSpawn; i++)
            {
                IntVec3 intVec;
                if (!CellFinderLoose.TryFindSkyfallerCell(ThingDefOf.CrashedShipPartIncoming, map, out intVec, 14, default(IntVec3), -1, false, true, true, true, true, false, null))
                {
                    break;
                }
                Building building_CrashedShipPart = (Building)ThingMaker.MakeThing(this.def.mechClusterBuilding, null);

                CompPawnSpawnerOnDamaged damaged = building_CrashedShipPart.TryGetComp <CompPawnSpawnerOnDamaged>();
                Faction faction = damaged.faction ?? Faction.OfMechanoids;
                building_CrashedShipPart.SetFaction(faction, null);
                building_CrashedShipPart.GetComp <CompPawnSpawnerOnDamaged>().pointsLeft = Mathf.Max(parms.points * 0.9f, 300f);
                Skyfaller skyfaller = SkyfallerMaker.MakeSkyfaller(ThingDefOf.CrashedShipPartIncoming, building_CrashedShipPart);
                skyfaller.shrapnelDirection = shrapnelDirection;
                GenSpawn.Spawn(skyfaller, intVec, map, WipeMode.Vanish);
                num++;
                list.Add(new TargetInfo(intVec, map, false));
            }
            if (num > 0)
            {
                base.SendStandardLetter(parms, list, Array.Empty <NamedArgument>());
            }
            return(num > 0);
        }
        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);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map     map               = (Map)parms.target;
            int     num               = 0;
            int     countToSpawn      = this.CountToSpawn;
            IntVec3 cell              = IntVec3.Invalid;
            float   shrapnelDirection = Rand.Range(0f, 360f);

            for (int i = 0; i < countToSpawn; i++)
            {
                IntVec3 intVec;
                if (!CellFinderLoose.TryFindSkyfallerCell(ThingDefOf.CrashedShipPartIncoming, map, out intVec, 14, default(IntVec3), -1, false, true, true, true, null))
                {
                    break;
                }
                Building_CrashedShipPart building_CrashedShipPart = (Building_CrashedShipPart)ThingMaker.MakeThing(this.def.shipPart, null);
                building_CrashedShipPart.SetFaction(Faction.OfMechanoids, null);
                building_CrashedShipPart.GetComp <CompSpawnerMechanoidsOnDamaged>().pointsLeft = Mathf.Max(parms.points * 0.9f, 300f);
                Skyfaller skyfaller = SkyfallerMaker.MakeSkyfaller(ThingDefOf.CrashedShipPartIncoming, building_CrashedShipPart);
                skyfaller.shrapnelDirection = shrapnelDirection;
                GenSpawn.Spawn(skyfaller, intVec, map);
                num++;
                cell = intVec;
            }
            if (num > 0)
            {
                base.SendStandardLetter(new TargetInfo(cell, map, false), new string[0]);
            }
            return(num > 0);
        }
        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);
                }
            }
        }
        public override bool TryExecute(IncidentParms parms)
        {
            Map map = (Map)parms.target;

            string[] array = new string[]
            {
                "SandstoneBoulder",
                "LimestoneBoulder",
                "GraniteBoulder",
                "SlateBoulder",
                "MarbleBoulder",
                "MineralBoulder",
                "SilverBoulder",
                "GoldBoulder",
                "UraniumBoulder",
                "JadeBoulder"
            };
            Random   random               = new Random();
            int      num                  = random.Next(array.Length);
            ThingDef thingDef             = ThingDef.Named(array[num]);
            Thing    singleContainedThing = ThingMaker.MakeThing(thingDef);
            IntVec3  dropCenter           = CellFinderLoose.RandomCellWith((IntVec3 c) => GenGrid.Standable(c, map) && !map.roofGrid.Roofed(c) && !map.fogGrid.IsFogged(c), map, 1000);

            MeteorUtility.MakeMeteorAt(dropCenter, map, new MeteorInfo
            {
                SingleContainedThing = singleContainedThing,
                openDelay            = 1,
                leaveSlag            = false
            });
            Find.LetterStack.ReceiveLetter("Meteor Incoming", "A meteoroid has entered the planets gravity well and come crashing down in a fiery explosion! weeee", LetterType.BadNonUrgent, new TargetInfo(dropCenter, map, false), null);
            return(true);
        }
Ejemplo n.º 12
0
    internal static bool DoProspectFind(Pawn worker, Map map, float radius, out IntVec3 prospect,
                                        out ThingDef thingDef)
    {
        thingDef = null;
        prospect = IntVec3.Zero;
        if (!CellFinderLoose.TryFindRandomNotEdgeCellWith(5,
                                                          x => CanScatterAt(x, map) && x != worker.Position &&
                                                          (x - worker.Position).LengthHorizontalSquared <= radius * radius, map, out var result))
        {
            return(false);
        }

        thingDef = ChooseLumpThingDef();
        if (!thingDef.IsMetal)
        {
            return(false);
        }

        prospect = result;
        var numCells = Mathf.CeilToInt(thingDef.deepLumpSizeRange.RandomInRange);

        foreach (var item in GridShapeMaker.IrregularLump(result, map, numCells))
        {
            if (CanScatterAt(item, map) && !item.InNoBuildEdgeArea(map))
            {
                map.deepResourceGrid.SetAt(item, thingDef, thingDef.deepCountPerCell);
            }
        }

        return(true);
    }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Faction faction = Find.FactionManager.FirstFactionOfDef(FactionDef.Named("PLAHF_faction"));
            Map     map     = (Map)parms.target;
            //List<TargetInfo> list = new List<TargetInfo>();
            float shrapnelDirection = Rand.Range(0f, 360f);
            Thing lookhere;


            IntVec3 intVec;

            if (!CellFinderLoose.TryFindSkyfallerCell(RimWorld.ThingDefOf.DropPodIncoming, map, out intVec, 14, default(IntVec3), -1, false, true, true, true, true, false, null))
            {
                return(false);
            }
            Building_TacticalManaBomb building_tacticalmanabomb = (Building_TacticalManaBomb)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("Building_TacticalManaBomb", true));

            building_tacticalmanabomb.SetFaction(faction, null);
            building_tacticalmanabomb.spawnpoints = (float)(parms.points * 0.8);
            lookhere = building_tacticalmanabomb;

            Skyfaller skyfaller = SkyfallerMaker.MakeSkyfaller(RimWorld.ThingDefOf.DropPodIncoming, building_tacticalmanabomb);

            skyfaller.shrapnelDirection = shrapnelDirection;
            GenSpawn.Spawn(skyfaller, intVec, map, WipeMode.Vanish);



            Find.LetterStack.ReceiveLetter("LetterLabelPLAHFTMBAttack".Translate(), "LetterPLAHFTMBAttack".Translate(), LetterDefOf.ThreatBig, lookhere, null, null);


            Find.TickManager.slower.SignalForceNormalSpeedShort();
            Find.StoryWatcher.statsRecord.numRaidsEnemy++;
            return(true);
        }
 public override void CompTick()
 {
     base.CompTick();
     if (this.parent is Pawn pawn && pawn.health.summaryHealth.SummaryHealthPercent < 0.5f &&
         Find.TickManager.TicksGame >= readyToUseTicks)
     {
         var hostiles = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.AttackTarget).Where(x
                                                                                                  => x.HostileTo(pawn));
         readyToUseTicks = Find.TickManager.TicksGame + Props.cooldown;
         IntVec3 loc = IntVec3.Invalid;
         if (CellFinderLoose.TryFindRandomNotEdgeCellWith(10, (IntVec3 x) =>
                                                          hostiles.Where(y => y.Position.DistanceTo(x) > Props.minDistance).Count() == 0 && x.Walkable(this.parent.Map) && !x.Fogged(this.parent.Map),
                                                          pawn.Map, out loc))
         {
             MoteMaker.MakeStaticMote(pawn.Position, pawn.Map, ThingDefOf.Mote_PsycastAreaEffect, 10f);
             disappear    = true;
             appearInTick = Find.TickManager.TicksGame + 120;
             var mapComp = pawn.Map.GetComponent <VFEV_MapComponentHelper>();
             if (mapComp.pawnsToTeleport == null)
             {
                 mapComp.pawnsToTeleport = new Dictionary <Pawn, IntVec3>();
             }
             mapComp.pawnsToTeleport[pawn] = loc;
             pawn.DeSpawn(DestroyMode.Vanish);
         }
     }
 }
        private void DoSpawnResources()
        {
            IntVec3 startPos;
            string  str = txtArtefactActivatedResources.Translate();

            startPos = CellFinderLoose.RandomCellWith((IntVec3 c) =>
            {
                // only allow standable, not fogged positions, not home region
                if (!c.Standable(Map) || Map.fogGrid.IsFogged(c) || Map.areaManager.Home[c])
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }, Map);

            // Get random resource
            ThingDef thingDef = resourceDefs.RandomElement();

            List <Thing> things = new List <Thing>();

            while (true)
            {
                int maxValuePerStack = UnityEngine.Random.Range(200, 2000); // max value per stack

                Thing thing = ThingMaker.MakeThing(thingDef);
                thing.stackCount = UnityEngine.Random.Range(15, 75); // random stack count

                if (thing.stackCount > thing.def.stackLimit)
                {
                    thing.stackCount = thing.def.stackLimit;
                }

                if ((float)thing.stackCount * thing.def.BaseMarketValue > (float)maxValuePerStack) // check if stack is more worth than max value
                {
                    thing.stackCount = Mathf.CeilToInt((float)maxValuePerStack / thing.def.BaseMarketValue);
                }
                things.Add(thing);
                if (things.Count < UnityEngine.Random.Range(6, 13)) // create 6-12 stacks
                {
                    continue;
                }

                break;
            }

            //DropPodUtility.DropThingsNear(startPos, things, 0, true, false);
            foreach (Thing thing2 in things)
            {
                IntVec3 spawnPos = CellFinder.RandomClosewalkCellNear(startPos, Map, 5);
                GenPlace.TryPlaceThing(thing2, spawnPos, Map, ThingPlaceMode.Near);
            }

            string label = labelLetterArtefact.Translate();

            // add game event
            Find.LetterStack.ReceiveLetter(label, str, LetterDefOf.PositiveEvent, new GlobalTargetInfo(startPos, Map), null);
        }
Ejemplo n.º 17
0
        public 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);
                        }
                    }
                }
            }
        }
        private void DoPawnReleased()
        {
            // A pawn is released and joins the colony?
            IntVec3 startPos;
            string  str;

            str = txtArtefactActivatedPawnReleasedJoinsColony.Translate();

            // Find a valid spawn position
            startPos = CellFinderLoose.RandomCellWith((IntVec3 c) =>
            {
                if (Map.fogGrid.IsFogged(c))
                {
                    return(false);
                }

                if (!Map.reachability.CanReachColony(c))
                {
                    return(false);
                }

                if (Map.roofGrid.Roofed(c))
                {
                    return(false);
                }

                return(true);
            }, Map);

            Faction faction = Faction.OfPlayer;

            Pawn pawn = PawnGenerator.GeneratePawn(pawnKindDefs.RandomElement(), faction);

            float value = UnityEngine.Random.Range(0.0f, 100.0f);

            if (value < 25.0f) // 25% chance: The pawn remains with weapon and clothes
            {
                // Do nothing...
            }
            else if (value < 60.0f) // 35% chance: The pawn has no weapon
            {
                pawn.equipment = new Pawn_EquipmentTracker(pawn);
            }
            else // 40% chance: The pawn has no weapon and is naked
            {
                pawn.apparel   = new Pawn_ApparelTracker(pawn);
                pawn.equipment = new Pawn_EquipmentTracker(pawn);
            }

            // Spawn the pawn
            GenPlace.TryPlaceThing(pawn, startPos, Map, ThingPlaceMode.Direct);

            // Notify the Storyteller
            Find.Storyteller.intenderPopulation.Notify_PopulationGained();

            string label = labelLetterArtefact.Translate();

            // add game event
            Find.LetterStack.ReceiveLetter(label, str, LetterDefOf.PositiveEvent, pawn, null);
        }
Ejemplo n.º 19
0
        // Token: 0x0600139E RID: 5022 RVA: 0x00096118 File Offset: 0x00094518
        public void FireEvent(Map map, IntVec3 strikeLoc)
        {
            if (!strikeLoc.IsValid)
            {
                strikeLoc = CellFinderLoose.RandomCellWith((IntVec3 sq) => sq.Standable(map) && !map.roofGrid.Roofed(sq), map, 1000);
            }
            Mesh     boltMesh = LightningBoltMeshPool.RandomBoltMesh;
            Material boltMat  = null;

            if (!strikeLoc.Fogged(map))
            {
                Vector3 loc = strikeLoc.ToVector3Shifted();
                for (int i = 0; i < 4; i++)
                {
                    FleckMaker.ThrowSmoke(loc, map, 1.5f);
                    FleckMaker.ThrowMicroSparks(loc, map);
                    FleckMaker.ThrowLightningGlow(loc, map, 1.5f);
                }
            }
            if (extFaction != null)
            {
                Graphic g = GraphicDatabase.Get <Graphic_Single>(extFaction.TeleportBoltTexPath, ShaderTypeDefOf.Transparent.Shader);
                boltMat = g.MatSingle;
            }
            SoundInfo info = SoundInfo.InMap(new TargetInfo(strikeLoc, map, false), MaintenanceType.None);

            SoundDefOf.Thunder_OnMap.PlayOneShot(info);
            EventDraw(map, strikeLoc, boltMesh, boltMat);
        }
Ejemplo n.º 20
0
 public override void Generate(Map map)
 {
     DeepProfiler.Start("RebuildAllRegions");
     map.regionAndRoomUpdater.RebuildAllRegionsAndRooms();
     DeepProfiler.End();
     MapGenerator.PlayerStartSpot = CellFinderLoose.TryFindCentralCell(map, 7, 10, (IntVec3 x) => !x.Roofed(map));
 }
Ejemplo n.º 21
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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 22
0
        public override void FireEvent()
        {
            //SoundDefOf.Thunder_OffMap.PlayOneShotOnCamera(this.map);
            if (!this.strikeLoc.IsValid)
            {
                this.strikeLoc = CellFinderLoose.RandomCellWith((IntVec3 sq) => sq.Standable(this.map) && !this.map.roofGrid.Roofed(sq), this.map, 1000);
            }
            this.boltMesh = RandomBoltMesh;
            if (!this.strikeLoc.Fogged(this.map))
            {
                SoundDef exp = TorannMagicDefOf.TM_FireBombSD;
                GenExplosion.DoExplosion(this.strikeLoc, this.map, (Rand.Range(.8f, 1.2f) * this.averageRadius), this.damageType, instigator, this.damageAmount, -1f, exp, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false);
                Vector3 loc = this.strikeLoc.ToVector3Shifted();
                for (int i = 0; i < 4; i++)
                {
                    MoteMaker.ThrowSmoke(loc, this.map, 1.3f);
                    MoteMaker.ThrowMicroSparks(loc, this.map);
                    MoteMaker.ThrowLightningGlow(loc, this.map, 1.2f);
                }
            }
            SoundInfo info = SoundInfo.InMap(new TargetInfo(this.strikeLoc, this.map, false), MaintenanceType.None);

            info.volumeFactor = this.soundVolume;
            info.pitchFactor  = this.soundPitch;
            TorannMagicDefOf.TM_Thunder_OnMap.PlayOneShot(info);
        }
Ejemplo n.º 23
0
        // Token: 0x0600137A RID: 4986 RVA: 0x00094788 File Offset: 0x00092B88
        public override void FireEvent()
        {
            base.FireEvent();
            if (!strikeLoc.IsValid)
            {
                strikeLoc = CellFinderLoose.RandomCellWith(sq => sq.Standable(map) && !map.roofGrid.Roofed(sq), map);
            }

            boltMesh = LightningBoltMeshPool.RandomBoltMesh;
            if (!strikeLoc.Fogged(map))
            {
                GenExplosion.DoExplosion(strikeLoc, map, 8f, DefDatabase <DamageDef> .GetNamed("ApoDamage"), null, 1000);
                var loc = strikeLoc.ToVector3Shifted();
                for (var i = 0; i < 4; i++)
                {
                    FleckMaker.ThrowSmoke(loc, map, 1.5f);
                    FleckMaker.ThrowMicroSparks(loc, map);
                    FleckMaker.ThrowLightningGlow(loc, map, 1.5f);
                }
            }

            var info = SoundInfo.InMap(new TargetInfo(strikeLoc, map));

            SoundDef.Named("ra2_StormAtk").PlayOneShot(info);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Try to get a valid cell to spawn a new cluster anywhere on the map.
        /// </summary>
        public static void TryGetRandomClusterSpawnCell(ThingDef_ClusterPlant plantDef, int newDesiredClusterSize, bool checkTemperature, out IntVec3 spawnCell)
        {
            spawnCell = IntVec3.Invalid;

            Predicate <IntVec3> validator = delegate(IntVec3 cell)
            {
                // Check a plant can be spawned here.
                if (GenClusterPlantReproduction.IsValidPositionToGrowPlant(plantDef, cell) == false)
                {
                    return(false);
                }
                // Check there is no third cluster nearby.
                if (GenClusterPlantReproduction.IsClusterAreaClear(plantDef, newDesiredClusterSize, cell) == false)
                {
                    return(false);
                }
                return(true);
            };

            bool validCellIsFound = CellFinderLoose.TryGetRandomCellWith(validator, 1000, out spawnCell);

            if (validCellIsFound == false)
            {
                // Just for robustness, TryGetRandomCellWith set result to IntVec3.Invalid if no valid cell is found.
                spawnCell = IntVec3.Invalid;
            }
        }
Ejemplo n.º 25
0
 private void CollapseRandomRoof()
 {
     foreach (Map map in AffectedMaps)
     {
         IntVec3 intVec;
         if (CellFinderLoose.TryGetRandomCellWith((IntVec3 c) => c.Standable(map) && map.roofGrid.Roofed(c), map, 500, out intVec))
         {
             map.roofCollapseBuffer.MarkToCollapse(intVec);
             IntVec3[] array = new IntVec3[]
             {
                 intVec + IntVec3.West,
                 intVec + IntVec3.East,
                 intVec + IntVec3.South,
                 intVec + IntVec3.North
             };
             foreach (IntVec3 c2 in array)
             {
                 if (c2.Standable(map) && map.roofGrid.Roofed(c2))
                 {
                     map.roofCollapseBuffer.MarkToCollapse(c2);
                 }
             }
         }
     }
 }
        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.º 27
0
        // Token: 0x06000E86 RID: 3718 RVA: 0x0006ACD4 File Offset: 0x000690D4
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map                = (Map)parms.target;
            int num                = 0;
            int countToSpawn       = this.CountToSpawn;
            List <TargetInfo> list = new List <TargetInfo>();
            float             shrapnelDirection = Rand.Range(0f, 360f);

            for (int i = 0; i < countToSpawn; i++)
            {
                IntVec3 intVec;
                if (!CellFinderLoose.TryFindSkyfallerCell(ThingDefOf.CrashedShipPartIncoming, map, out intVec, 14, default(IntVec3), -1, false, true, true, true, true, false, null))
                {
                    break;
                }
                Building_Monolith building_Monolith = (Building_Monolith)ThingMaker.MakeThing(this.def.shipPart, null);
                building_Monolith.SetFaction(OGNFaction.OfNecrons, null);
                building_Monolith.GetComp <CompSpawnerNecronsOnDamaged>().pointsLeft = Mathf.Max(parms.points * 0.9f, 300f);
                Skyfaller skyfaller = SkyfallerMaker.MakeSkyfaller(ThingDefOf.CrashedShipPartIncoming, building_Monolith);
                skyfaller.shrapnelDirection = shrapnelDirection;
                GenSpawn.Spawn(skyfaller, intVec, map, WipeMode.Vanish);
                num++;
                list.Add(new TargetInfo(intVec, map, false));
            }
            if (num > 0)
            {
                base.SendStandardLetter(list, null, new string[0]);
            }
            return(num > 0);
        }
Ejemplo n.º 28
0
 public static void DropThingGroupsNear(IntVec3 dropCenter, Map map, List <List <Thing> > thingsGroups, int openDelay = 110, bool instaDrop = false, bool leaveSlag = false, bool canRoofPunch = true)
 {
     foreach (List <Thing> thingsGroup in thingsGroups)
     {
         if (!DropCellFinder.TryFindDropSpotNear(dropCenter, map, out IntVec3 result, allowFogged: true, canRoofPunch))
         {
             Log.Warning("DropThingsNear failed to find a place to drop " + thingsGroup.FirstOrDefault() + " near " + dropCenter + ". Dropping on random square instead.");
             result = CellFinderLoose.RandomCellWith((IntVec3 c) => c.Walkable(map), map);
         }
         for (int i = 0; i < thingsGroup.Count; i++)
         {
             thingsGroup[i].SetForbidden(value: true, warnOnFail: false);
         }
         if (instaDrop)
         {
             foreach (Thing item in thingsGroup)
             {
                 GenPlace.TryPlaceThing(item, result, map, ThingPlaceMode.Near);
             }
         }
         else
         {
             ActiveDropPodInfo activeDropPodInfo = new ActiveDropPodInfo();
             foreach (Thing item2 in thingsGroup)
             {
                 activeDropPodInfo.innerContainer.TryAdd(item2);
             }
             activeDropPodInfo.openDelay = openDelay;
             activeDropPodInfo.leaveSlag = leaveSlag;
             MakeDropPodAt(result, map, activeDropPodInfo);
         }
     }
 }
        public override void Resolve(ResolveParams rp)
        {
            var count = rp.hivesCount ?? 1;

            for (var i = 0; i < count; i++)
            {
                var kind    = Rand.Value > 0.3f ? DwarfDefOf.LotRD_DwarfVillager : DwarfDefOf.LotRD_DwarfGuardMountain;
                var faction = rp.faction;
                var request = new PawnGenerationRequest(kind, faction,
                                                        PawnGenerationContext.NonPlayer, BaseGen.globalSettings?.map?.Tile ?? Find.CurrentMap.Tile, false,
                                                        false, false, false, true, true, 1f, false, true, false,
                                                        false);
                var pawn = PawnGenerator.GeneratePawn(request);

                //CellFinder.TryFindBestPawnStandCell(pawn, out spawnLoc);
                var map = BaseGen.globalSettings?.map ?? Find.CurrentMap;
                CellFinderLoose.TryGetRandomCellWith(
                    x => x.IsValid && rp.rect.Contains(x) && x.GetEdifice(map) == null && x.GetFirstItem(map) == null,
                    map, 250, out var spawnLoc);
                GenSpawn.Spawn(pawn, spawnLoc, map);
                pawn.Kill(null);
                if (pawn.Corpse is not {
                } c || c.TryGetComp <CompRottable>() is not {
                } comp)
                {
                    continue;
                }

                c.Age += GenDate.TicksPerSeason * Rand.Range(8, 100);
                Log.Message("Rotted corpse");
                comp.RotProgress += 9999999;
            }
        }
Ejemplo n.º 30
0
        static void Postfix(Map map)
        {
            if (map.TileInfo.hilliness == Hilliness.Impassable &&
                Patch_GenStep_Terrain.middleAreaCenter != null &&
                Settings.HasMiddleArea &&
                Settings.StartInMiddleArea)
            {
                float centerX = Patch_GenStep_Terrain.middleAreaCenter.Value.x;
                float centerZ = Patch_GenStep_Terrain.middleAreaCenter.Value.x;
                float halfX   = Settings.OpenAreaSizeX * 0.5f;
                float halfZ   = Settings.OpenAreaSizeZ * 0.5f;
                float minX    = centerX - halfX;
                float minZ    = centerZ - halfZ;
                float maxX    = centerX + halfX;
                float maxZ    = centerZ + halfZ;

                ;
                if (CellFinderLoose.TryFindRandomNotEdgeCellWith(
                        (int)Math.Max(0, map.Size.x - centerX - halfX + 1),
                        (IntVec3 i) => !i.Roofed(map) && i.x >= minX && i.x <= maxX && i.z >= minZ && i.z <= maxZ,
                        map,
                        out IntVec3 result))
                {
                    MapGenerator.PlayerStartSpot = result;
                }
                else
                {
                    Log.Error("Unable to start in the middle. Sorry!");
                }
            }
        }