Пример #1
0
        public override AcceptanceReport CanDesignateCell(IntVec3 c)
        {
            if (!GenGrid.InBounds(c, Map) || GridsUtility.Fogged(c, Map) || Map.designationManager.DesignationAt(c, Designation) != null)
            {
                return(false);
            }

            if (GenGrid.InNoBuildEdgeArea(c, Map))
            {
                return(Translator.Translate("TooCloseToMapEdge"));
            }

            var edifice = GridsUtility.GetEdifice(c, Map);

            if (edifice != null && edifice.def.Fillage == FillCategory.Full && edifice.def.passability == Traversability.Impassable)
            {
                return(false);
            }

            var terrain = Map.terrainGrid.TerrainAt(c);

            if (terrain != IceTerrain.Ice && terrain != IceTerrain.IceShallow)
            {
                return("Ice.MustBeIce".Translate());
            }

            return(AcceptanceReport.WasAccepted);
        }
Пример #2
0
 protected override ThoughtState CurrentStateInternal(Pawn p)
 {
     if (!p.Spawned)
     {
         return(ThoughtState.Inactive);
     }
     if (!p.RaceProps.Humanlike)
     {
         return(ThoughtState.Inactive);
     }
     if (!p.Awake())
     {
         return(ThoughtState.Inactive);
     }
     if (!p.story.traits.HasTrait(TraitDefOfPsychology.Sedentary))
     {
         return(ThoughtState.Inactive);
     }
     if ((this.lastMovePosition - p.Position).LengthHorizontalSquared > 80f)
     {
         this.lastMovePosition = p.Position;
         this.lastMoveTick     = Find.TickManager.TicksGame;
     }
     if ((Find.TickManager.TicksGame - lastMoveTick) > GenDate.TicksPerHour)
     {
         Building edifice = GridsUtility.GetEdifice(p.Position, p.Map);
         if (edifice != null && edifice.GetStatValue(StatDefOf.Comfort, true) >= 0.75f)
         {
             return(ThoughtState.ActiveAtStage(1));
         }
         return(ThoughtState.ActiveAtStage(0));
     }
     return(ThoughtState.Inactive);
 }
        private static IPlantToGrowSettable GetPlayerSetPlantForCell(IntVec3 cell, Map map)
        {
            IPlantToGrowSettable plantToGrowSettable = GridsUtility.GetEdifice(cell, map) as IPlantToGrowSettable;

            if (plantToGrowSettable == null)
            {
                plantToGrowSettable = (map.zoneManager.ZoneAt(cell) as IPlantToGrowSettable);
            }
            return(plantToGrowSettable);
        }
Пример #4
0
        // Token: 0x06000051 RID: 81 RVA: 0x00004498 File Offset: 0x00002698
        internal void JPHitRoof(bool up)
        {
            if (!this.def.skyfaller.hitRoof)
            {
                return;
            }
            CellRect cr;

            if (up)
            {
                IntVec3 hrpcell   = IntVec3Utility.ToIntVec3(base.DrawPos);
                IntVec2 punchsize = new IntVec2(3, 3);
                cr = GenAdj.OccupiedRect(hrpcell, base.Rotation, punchsize);
            }
            else
            {
                cr = GenAdj.OccupiedRect(this);
            }
            if (cr.Cells.Any((IntVec3 x) => GridsUtility.Roofed(x, this.Map)))
            {
                RoofDef roof = GridsUtility.GetRoof(cr.Cells.First((IntVec3 x) => GridsUtility.Roofed(x, this.Map)), base.Map);
                if (!SoundDefHelper.NullOrUndefined(roof.soundPunchThrough))
                {
                    SoundStarter.PlayOneShot(roof.soundPunchThrough, new TargetInfo(base.Position, base.Map, false));
                }
                RoofCollapserImmediate.DropRoofInCells(cr.ExpandedBy(1).ClipInsideMap(base.Map).Cells.Where(delegate(IntVec3 c)
                {
                    if (!GenGrid.InBounds(c, this.Map))
                    {
                        return(false);
                    }
                    if (cr.Contains(c))
                    {
                        return(true);
                    }
                    if (GridsUtility.GetFirstPawn(c, this.Map) != null)
                    {
                        return(false);
                    }
                    Building edifice = GridsUtility.GetEdifice(c, this.Map);
                    return(edifice == null || !edifice.def.holdsRoof);
                }), base.Map, null);
                if (up)
                {
                    this.PilotRoofPunchUp = true;
                    return;
                }
                this.PilotRoofPunchDown = true;
            }
        }
 public override float GetScore(Room room)
 {
     using (IEnumerator <IntVec3> enumerator = room.BorderCells.GetEnumerator())
     {
         while (((IEnumerator)enumerator).MoveNext())
         {
             Building edifice = GridsUtility.GetEdifice(enumerator.Current, room.Map);
             if (edifice == null || !edifice.def.building.shipPart)
             {
                 return(0.0f);
             }
         }
     }
     return(1.701412E+38f);
 }
Пример #6
0
        /// <summary>
        /// Checks for cover along the flight path of the bullet, doesn't check for walls or plants, only intended for cover with partial fillPercent
        /// </summary>
        private bool GetPartialCoverBetween(Vector3 sourceLoc, Vector3 targetLoc, out Thing cover)
        {
            //Sanity check
            if (this.verbProps.projectileDef.projectile.flyOverhead)
            {
                cover = null;
                return(false);
            }

            sourceLoc.Scale(new Vector3(1, 0, 1));
            targetLoc.Scale(new Vector3(1, 0, 1));

            //Calculate segment vector and segment amount
            Vector3 shotVec     = sourceLoc - targetLoc;                             //Vector from target to source
            Vector3 segmentVec  = shotVec.normalized * segmentLength;
            float   distToCheck = Mathf.Min(distToCheckForCover, shotVec.magnitude); //The distance to raycast
            float   numSegments = distToCheck / segmentLength;

            //Raycast accross all segments to check for cover
            List <IntVec3> checkedCells = new List <IntVec3>();
            Thing          targetThing  = GridsUtility.GetEdifice(targetLoc.ToIntVec3());
            Thing          newCover     = null;

            for (int i = 0; i <= numSegments; i++)
            {
                IntVec3 cell = (targetLoc + segmentVec * i).ToIntVec3();
                if (!checkedCells.Contains(cell))
                {
                    //Cover check, if cell has cover compare fillPercent and get the highest piece of cover, ignore if cover is the target (e.g. solar panels, crashed ship, etc)
                    Thing coverAtCell = GridsUtility.GetCover(cell);
                    if (coverAtCell != null &&
                        (targetThing == null || !coverAtCell.Equals(targetThing)) &&
                        (newCover == null || newCover.def.fillPercent < coverAtCell.def.fillPercent))
                    {
                        newCover = coverAtCell;
                    }
                }
            }
            cover = newCover;

            //Report success if found cover that is not a wall or plant
            return(cover != null &&
                   cover.def.Fillage != FillCategory.Full &&
                   cover.def.category != ThingCategory.Plant);  //Don't care about trees
        }
        protected override void ScatterAt(IntVec3 loc, Map map, int stackCount = 1)
        {
            if (!TryGetRandomValidRotation(loc, map, out Rot4 rot))
            {
                Log.Warning("Could not find any valid rotation for " + thingDef);
                return;
            }
            if (clearSpaceSize > 0)
            {
                using (IEnumerator <IntVec3> enumerator = GridShapeMaker.IrregularLump(loc, map, clearSpaceSize).GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Building edifice = GridsUtility.GetEdifice(enumerator.Current, map);
                        if (edifice != null)
                        {
                            edifice.Destroy(0);
                        }
                    }
                }
            }
            Thing thing = ThingMaker.MakeThing(thingDef, stuff);

            if (thingDef.Minifiable)
            {
                thing = MinifyUtility.MakeMinified(thing);
            }
            if (thing.def.category == ThingCategory.Item)
            {
                thing.stackCount = stackCount;
                ForbidUtility.SetForbidden(thing, true, false);
                GenPlace.TryPlaceThing(thing, loc, map, ThingPlaceMode.Near, out Thing thing2, null);
                if (nearPlayerStart && thing2 != null && thing2.def.category == ThingCategory.Item && TutorSystem.TutorialMode)
                {
                    Find.TutorialState.AddStartingItem(thing2);
                    return;
                }
            }
            else
            {
                GenSpawn.Spawn(thing, loc, map, rot, false);
            }
        }
Пример #8
0
        private new bool CurrentlyCultivated()
        {
            if (!this.def.plant.Sowable)
            {
                return(false);
            }
            Zone zone = Find.get_ZoneManager().ZoneAt(this.Position);

            if (zone != null && zone is Zone_Growing)
            {
                return(true);
            }
            Building edifice = GridsUtility.GetEdifice(this.Position);

            if (edifice != null)
            {
                return(edifice.def.building.SupportsPlants);
            }
            return(false);
        }
Пример #9
0
        public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null)
        {
            Building         edifice = GridsUtility.GetEdifice(loc, map);
            bool             flag    = edifice == null;
            AcceptanceReport result;

            if (flag)
            {
                result = Translator.Translate("MessagePlacementOnSupport");
            }
            else
            {
                bool flag2 = edifice.def == null;
                if (flag2)
                {
                    result = Translator.Translate("MessagePlacementOnSupport");
                }
                else
                {
                    bool isSmoothed = edifice.def.IsSmoothed;
                    if (isSmoothed)
                    {
                        result = AcceptanceReport.WasAccepted;
                    }
                    else
                    {
                        bool flag3 = edifice.def.graphicData == null;
                        if (flag3)
                        {
                            result = Translator.Translate("MessagePlacementOnSupport");
                        }
                        else
                        {
                            result = (((edifice.def.graphicData.linkFlags) != 0) ? AcceptanceReport.WasAccepted : Translator.Translate("MessagePlacementOnSupport"));
                        }
                    }
                }
            }
            return(result);
        }
Пример #10
0
        private void ImpactSomething()
        {
            if (this.def.projectile.flyOverhead)
            {
                RoofDef roofDef = base.Map.roofGrid.RoofAt(base.Position);
                if (roofDef != null)
                {
                    if (roofDef.isThickRoof)
                    {
                        SoundStarter.PlayOneShot(this.def.projectile.soundHitThickRoof, new TargetInfo(base.Position, base.Map, false));
                        this.Destroy(0);
                        return;
                    }
                    if (GridsUtility.GetEdifice(base.Position, base.Map) == null || GridsUtility.GetEdifice(base.Position, base.Map).def.Fillage != FillCategory.Full)
                    {
                        RoofCollapserImmediate.DropRoofInCells(base.Position, base.Map, null);
                    }
                }
            }
            if (!this.usedTarget.HasThing || !base.CanHit(this.usedTarget.Thing))
            {
                List <Thing> list = new List <Thing>();
                list.Clear();
                List <Thing> thingList = GridsUtility.GetThingList(base.Position, base.Map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    Thing thing = thingList[i];
                    if ((thing.def.category == ThingCategory.Building || thing.def.category == ThingCategory.Pawn || thing.def.category == ThingCategory.Item || thing.def.category == ThingCategory.Plant) && base.CanHit(thing))
                    {
                        list.Add(thing);
                    }
                }
                GenList.Shuffle <Thing>(list);
                for (int j = 0; j < list.Count; j++)
                {
                    Thing thing2 = list[j];
                    Pawn  pawn   = thing2 as Pawn;
                    float num;
                    if (pawn != null)
                    {
                        num = 0.5f * Mathf.Clamp(pawn.BodySize, 0.1f, 2f);
                        if (PawnUtility.GetPosture(pawn) != null && GenGeo.MagnitudeHorizontalSquared(this.origin - this.destination) >= 20.25f)
                        {
                            num *= 0.2f;
                        }
                        if (this.launcher != null && pawn.Faction != null && this.launcher.Faction != null && !FactionUtility.HostileTo(pawn.Faction, this.launcher.Faction))
                        {
                            num *= VerbUtility.InterceptChanceFactorFromDistance(this.origin, base.Position);
                        }
                    }
                    else
                    {
                        num = 1.5f * thing2.def.fillPercent;
                    }
                    if (Rand.Chance(num))
                    {
                        this.Impact(GenCollection.RandomElement <Thing>(list));
                        return;
                    }
                }
                this.Impact(null);
                return;
            }
            Pawn pawn2 = this.usedTarget.Thing as Pawn;

            if (pawn2 != null && PawnUtility.GetPosture(pawn2) != null && GenGeo.MagnitudeHorizontalSquared(this.origin - this.destination) >= 20.25f && !Rand.Chance(0.2f))
            {
                this.Impact(null);
                return;
            }
            this.Impact(this.usedTarget.Thing);
        }
Пример #11
0
        protected override void ScatterAt(IntVec3 c, Map map, GenStepParams parms, int stackCount = 1)
        {
            Log.Message("Horrors: Initiating Hive Spawn");
            TurboNoise caveNoise = new TurboNoise();

            double[ , ] noiseArray = new double[map.Size.x, map.Size.z];

            caveNoise = GeneratePerlinNoiseForCaves(map);
            Log.Message("Horrors: Noise Generated Successfully");

            Log.Message("Horrors: Stepping through noise grid");
            for (int i = 0; i < map.Size.x; i++)
            {
                for (int n = 0; n < map.Size.z; n++)
                {
                    noiseArray[i, n] = caveNoise.layeredNoise(Convert.ToDouble(i) / 10, Convert.ToDouble(n) / 10);
                }
            }

            Log.Message("Horrors: Digging out tunnels");
            for (int i = 0; i < map.Size.x; i++)
            {
                for (int n = 0; n < map.Size.z; n++)
                {
                    IntVec3 loc = new IntVec3(i, 0, n);

                    if (CoverUtility.TotalSurroundingCoverScore(loc, map) > 0.2)
                    {
                        GenSpawn.Spawn(ThingDef.Named("HorrorWeb"), loc, map);
                    }

                    if (noiseArray[i, n] > 0.5)
                    {
                        if (GridsUtility.GetEdifice(loc, map) != null)
                        {
                            GridsUtility.GetEdifice(loc, map).Destroy(DestroyMode.KillFinalize);
                        }

                        if (map.fogGrid.IsFogged(loc))
                        {
                            map.fogGrid.Unfog(loc);
                        }

                        //map.terrainGrid.SetTerrain(loc, TerrainDef.Named("FloorWebs"));
                    }
                }
            }

            Log.Message("Horrors: Generating Hive Rect");
            int      randomInRange  = GenStep_HorrorsHive.FactionBaseSizeRange.RandomInRange;
            int      randomInRange2 = GenStep_HorrorsHive.FactionBaseSizeRange.RandomInRange;
            CellRect rect           = new CellRect(0, 0, 0, 0);
            Faction  faction;

            if (map.info.parent == null || map.info.parent.Faction == null || map.info.parent.Faction == Faction.OfPlayer)
            {
                faction = Find.FactionManager.RandomEnemyFaction(false, false);
            }
            else
            {
                faction = map.info.parent.Faction;
            }

            rect = rect.ExpandedBy(4);

            rect.ClipInsideMap(map);
            ResolveParams resolveParams = default(ResolveParams);

            resolveParams.rect         = rect;
            resolveParams.faction      = faction;
            BaseGen.globalSettings.map = map;

            Log.Message("Horrors: Validating Spawns");

            Predicate <IntVec3> validator = (IntVec3 p) => DropCellFinder.IsGoodDropSpot(p, map, true, true);
            IntVec3             cellReturned;

            // Pawns
            Pawn pawnToSpawn = PawnGenerator.GeneratePawn(PawnKindDef.Named("Pirate"), faction);
            Pawn queenPawn   = PawnGenerator.GeneratePawn(PawnKindDef.Named("Pirate"), faction);


            Log.Message("Horrors: Spawning Sinkhole");
            CellFinder.TryFindRandomCellNear(map.Center, map, 20, validator, out cellReturned);
            GenSpawn.Spawn(ThingDef.Named("SinkHole"), map.Center, map);

            Log.Message("Horrors: Spawning Sinkhole");
            CellFinder.TryFindRandomCellNear(map.Center, map, 20, validator, out cellReturned);
            GenSpawn.Spawn(ThingDef.Named("SinkHole"), cellReturned, map);

            Log.Message("Horrors: Spawning Sinkhole");
            CellFinder.TryFindRandomCellNear(map.Center, map, 20, validator, out cellReturned);
            GenSpawn.Spawn(ThingDef.Named("SinkHole"), cellReturned, map);

            Log.Message("Horrors: Spawning Sinkhole");
            CellFinder.TryFindRandomCellNear(map.Center, map, 20, validator, out cellReturned);
            GenSpawn.Spawn(ThingDef.Named("SinkHole"), cellReturned, map);

            Log.Message("Horrors: Spawning Sinkhole");
            CellFinder.TryFindRandomCellNear(map.Center, map, 20, validator, out cellReturned);

            Thing queen = GenSpawn.Spawn(queenPawn, cellReturned, map);

            pawnToSpawn = PawnGenerator.GeneratePawn(PawnKindDef.Named("BroodLord"), faction);

            GenSpawn.Spawn(pawnToSpawn, cellReturned, map);
            pawnToSpawn.training.Train(TrainableDefOf.Obedience, (Pawn)queen);
        }