Пример #1
0
        public static IEnumerable <IntVec3> GetCircle(float radius)
        {
            if (circles == null)
            {
                circles = new Dictionary <float, HashSet <IntVec3> >();
            }
            HashSet <IntVec3> cells = circles.ContainsKey(radius) ? circles[radius] : null;

            if (cells == null)
            {
                cells = new HashSet <IntVec3>();
                IEnumerator <IntVec3> enumerator = GenRadial.RadialPatternInRadius(radius).GetEnumerator();
                while (enumerator.MoveNext())
                {
                    IntVec3 v = enumerator.Current;
                    cells.Add(v);
                    cells.Add(new IntVec3(-v.x, 0, v.z));
                    cells.Add(new IntVec3(-v.x, 0, -v.z));
                    cells.Add(new IntVec3(v.x, 0, -v.z));
                }
                enumerator.Dispose();
                circles[radius] = cells;
            }
            return(cells);
        }
Пример #2
0
        public static Toil GotoNearTargetAndWait(TargetIndex target, float moveDistance, float lookDistance)
        {
            Toil toil = new Toil();

            toil.defaultCompleteMode = ToilCompleteMode.Never;
            toil.initAction          = delegate()
            {
                Pawn pawn       = toil.actor;
                Pawn targetPawn = pawn.CurJob.GetTarget(target).Thing as Pawn;
                if (pawn.Position.InHorDistOf(targetPawn.Position, lookDistance))
                {
                    pawn.jobs.curDriver.ReadyForNextToil();
                }
                else
                {
                    pawn.pather.StartPath(targetPawn, PathEndMode.OnCell);
                }
            };

            toil.tickAction = delegate()
            {
                Pawn pawn       = toil.actor;
                Pawn targetPawn = pawn.CurJob.GetTarget(target).Thing as Pawn;
                Map  map        = pawn.Map;
                if (pawn.Position.InHorDistOf(targetPawn.Position, moveDistance))
                {
                    pawn.pather.StopDead();
                    pawn.jobs.curDriver.ReadyForNextToil();
                }
                else if (!pawn.pather.Moving)
                {
                    IntVec3 destVec = IntVec3.Invalid;

                    foreach (IntVec3 t in GenRadial.RadialPatternInRadius(moveDistance))
                    {
                        IntVec3 v = targetPawn.Position + t;
                        if (v.InBounds(map) && v.Walkable(map) && v != pawn.Position &&
                            pawn.CanReach(v, PathEndMode.OnCell, Danger.Some) &&
                            (!destVec.IsValid || pawn.Position.DistanceToSquared(v) >= pawn.Position.DistanceToSquared(destVec)) &&
                            pawn.CanSee(targetPawn))
                        {
                            destVec = v;
                        }
                    }

                    if (destVec.IsValid)
                    {
                        pawn.pather.StartPath(destVec, PathEndMode.OnCell);
                    }
                    else
                    {
                        pawn.jobs.curDriver.EndJobWith(JobCondition.Incompletable);
                    }
                }
            };

            return(toil);
        }
        protected void IceExplosion(IntVec3 pos, float radius)
        {
            ThingDef def = this.def;

            GenExplosion.DoExplosion(Position, Map, radius, DamageDefOf.Frostbite, launcher, -1, -1, null, def, this.equipmentDef, null, null, 0f, 1, false, null, 0f, 1, 0f, false);

            float depth = 3f;
            IEnumerable <IntVec3> iceCells = GenRadial.RadialPatternInRadius(radius);

            foreach (IntVec3 cell in iceCells)
            {
                Map.snowGrid.AddDepth(cell + pos, depth);
            }
        }
Пример #4
0
        protected void SnowCreation(IntVec3 pos, float radius, Map map)
        {
            float depth = 15f;
            IEnumerable <IntVec3> iceCells = GenRadial.RadialPatternInRadius(radius);

            foreach (IntVec3 cell in iceCells)
            {
                IntVec3 cellReal = cell + pos;

                if (cellReal.InBounds(map))
                {
                    map.snowGrid.AddDepth(cellReal, depth);
                }
            }
            map.snowGrid.AddDepth(pos, depth);
        }
Пример #5
0
        private static void SetCellsInRadiusTerrain(Map map, IntVec3 position, float radius, TerrainDef terrain)
        {
            int num = Mathf.RoundToInt((float)map.Area / 10000f * 20);

            for (int i = 0; i < 1; i++)
            {
                float   randomInRange = 20;
                IntVec3 a             = CellFinder.RandomCell(map);
                foreach (IntVec3 current in GenRadial.RadialPatternInRadius(randomInRange / 2f))
                {
                    IntVec3 c = a + current;
                    if (c.InBounds(map))
                    {
                        map.terrainGrid.SetTerrain(c, terrain);
                    }
                }
            }
        }
Пример #6
0
        public static Building_OrbitalRelay GenerateOrbitalRelayZone(IntVec3 areaSouthWestOrigin, int zoneAbs, int zoneOrd, ref OG_OutpostData outpostData)
        {
            Building_OrbitalRelay orbitalRelay = null;

            IntVec3 origin = Zone.GetZoneOrigin(areaSouthWestOrigin, zoneAbs, zoneOrd);

            // Spawn orbital relay.
            IntVec3 orbitalRelayPosition = origin + new IntVec3(Genstep_GenerateOutpost.zoneSideCenterOffset, 0, Genstep_GenerateOutpost.zoneSideCenterOffset);

            orbitalRelay = OG_Common.TrySpawnThingAt(OG_Util.OrbitalRelayDef, null, orbitalRelayPosition, false, Rot4.Invalid, ref outpostData) as Building_OrbitalRelay;

            // Spawn sandbags.
            OG_Common.TrySpawnThingAt(ThingDefOf.Sandbags, null, origin + new IntVec3(3, 0, 2), false, Rot4.Invalid, ref outpostData);
            OG_Common.TrySpawnThingAt(ThingDefOf.Sandbags, null, origin + new IntVec3(2, 0, 2), false, Rot4.Invalid, ref outpostData);
            OG_Common.TrySpawnThingAt(ThingDefOf.Sandbags, null, origin + new IntVec3(2, 0, 3), false, Rot4.Invalid, ref outpostData);

            OG_Common.TrySpawnThingAt(ThingDefOf.Sandbags, null, origin + new IntVec3(2, 0, 7), false, Rot4.Invalid, ref outpostData);
            OG_Common.TrySpawnThingAt(ThingDefOf.Sandbags, null, origin + new IntVec3(2, 0, 8), false, Rot4.Invalid, ref outpostData);
            OG_Common.TrySpawnThingAt(ThingDefOf.Sandbags, null, origin + new IntVec3(3, 0, 8), false, Rot4.Invalid, ref outpostData);

            OG_Common.TrySpawnThingAt(ThingDefOf.Sandbags, null, origin + new IntVec3(7, 0, 8), false, Rot4.Invalid, ref outpostData);
            OG_Common.TrySpawnThingAt(ThingDefOf.Sandbags, null, origin + new IntVec3(8, 0, 8), false, Rot4.Invalid, ref outpostData);
            OG_Common.TrySpawnThingAt(ThingDefOf.Sandbags, null, origin + new IntVec3(8, 0, 7), false, Rot4.Invalid, ref outpostData);

            OG_Common.TrySpawnThingAt(ThingDefOf.Sandbags, null, origin + new IntVec3(8, 0, 3), false, Rot4.Invalid, ref outpostData);
            OG_Common.TrySpawnThingAt(ThingDefOf.Sandbags, null, origin + new IntVec3(8, 0, 2), false, Rot4.Invalid, ref outpostData);
            OG_Common.TrySpawnThingAt(ThingDefOf.Sandbags, null, origin + new IntVec3(7, 0, 2), false, Rot4.Invalid, ref outpostData);

            // Generate concrete ground.
            foreach (IntVec3 cell in GenRadial.RadialPatternInRadius(2.8f))
            {
                Find.TerrainGrid.SetTerrain(orbitalRelayPosition + cell, TerrainDefOf.Concrete);
            }

            return(orbitalRelay);
        }
        private static void GenerateInt(bool[,] grid, bool horizontalSymmetry, bool verticalSymmetry, bool allowEnclosedFalses, bool preferOutlines, float wipedCircleRadiusPct)
        {
            int length  = grid.GetLength(0);
            int length2 = grid.GetLength(1);

            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j < length2; j++)
                {
                    grid[i, j] = false;
                }
            }
            int num;
            int num2;
            int num3;
            int num4;
            int num5;
            int num6;

            if (preferOutlines)
            {
                num  = 0;
                num2 = 2;
                num3 = 0;
                num4 = 4;
                num5 = 2;
                num6 = ((length < 16 && length2 < 16) ? ((length < 13 && length2 < 13) ? ((length < 12 && length2 < 12) ? 1 : 2) : 3) : 4);
            }
            else
            {
                num  = Rand.RangeInclusive(1, 3);
                num2 = 0;
                num3 = Rand.RangeInclusive(1, 3);
                num6 = 0;
                num4 = 0;
                num5 = 0;
            }
            float num7  = 0.3f;
            float num8  = 0.3f;
            float num9  = 0.7f;
            float num10 = 0.7f;

            for (int k = 0; k < num; k++)
            {
                foreach (IntVec3 item in CellRect.CenteredOn(new IntVec3(Rand.RangeInclusive(0, length - 1), 0, Rand.RangeInclusive(0, length2 - 1)), Mathf.Max(Mathf.RoundToInt((float)Rand.RangeInclusive(1, length) * num7), 1), Mathf.Max(Mathf.RoundToInt((float)Rand.RangeInclusive(1, length2) * num7), 1)))
                {
                    if (item.x >= 0 && item.x < length && item.z >= 0 && item.z < length2)
                    {
                        grid[item.x, item.z] = true;
                    }
                }
            }
            for (int l = 0; l < num2; l++)
            {
                CellRect cellRect = CellRect.CenteredOn(new IntVec3(Rand.RangeInclusive(0, length - 1), 0, Rand.RangeInclusive(0, length2 - 1)), Mathf.Max(Mathf.RoundToInt((float)Rand.RangeInclusive(1, length) * num8), 1), Mathf.Max(Mathf.RoundToInt((float)Rand.RangeInclusive(1, length2) * num8), 1));
                Rot4     random   = Rot4.Random;
                foreach (IntVec3 edgeCell in cellRect.EdgeCells)
                {
                    if ((allowEnclosedFalses || !cellRect.IsOnEdge(edgeCell, random) || cellRect.IsOnEdge(edgeCell, random.Rotated(RotationDirection.Clockwise)) || cellRect.IsOnEdge(edgeCell, random.Rotated(RotationDirection.Counterclockwise))) && edgeCell.x >= 0 && edgeCell.x < length && edgeCell.z >= 0 && edgeCell.z < length2)
                    {
                        grid[edgeCell.x, edgeCell.z] = true;
                    }
                }
            }
            for (int m = 0; m < num3; m++)
            {
                IntVec2 intVec = new IntVec2(Rand.RangeInclusive(0, length - 1), Rand.RangeInclusive(0, length2 - 1));
                foreach (IntVec3 item2 in GenRadial.RadialPatternInRadius(Mathf.Max(Mathf.RoundToInt((float)(Mathf.Max(length, length2) / 2) * num9), 1)))
                {
                    IntVec3 current3 = item2;
                    current3.x += intVec.x;
                    current3.z += intVec.z;
                    if (current3.x >= 0 && current3.x < length && current3.z >= 0 && current3.z < length2)
                    {
                        grid[current3.x, current3.z] = true;
                    }
                }
            }
            for (int n = 0; n < num6; n++)
            {
                float   num11   = Rand.Range(0.7f, 1f);
                IntVec2 intVec2 = new IntVec2(Rand.RangeInclusive(0, length - 1), Rand.RangeInclusive(0, length2 - 1));
                int     num12   = Mathf.Max(Mathf.RoundToInt((float)(Mathf.Max(length, length2) / 2) * num10 * num11), 1);
                bool    @bool   = Rand.Bool;
                tmpCircleCells.Clear();
                tmpCircleCells.AddRange(GenRadial.RadialPatternInRadius(num12));
                foreach (IntVec3 tmpCircleCell in tmpCircleCells)
                {
                    if ((allowEnclosedFalses || ((!@bool || tmpCircleCell.x >= 0) && (@bool || tmpCircleCell.z >= 0))) && (!tmpCircleCells.Contains(new IntVec3(tmpCircleCell.x - 1, 0, tmpCircleCell.z - 1)) || !tmpCircleCells.Contains(new IntVec3(tmpCircleCell.x - 1, 0, tmpCircleCell.z)) || !tmpCircleCells.Contains(new IntVec3(tmpCircleCell.x - 1, 0, tmpCircleCell.z + 1)) || !tmpCircleCells.Contains(new IntVec3(tmpCircleCell.x, 0, tmpCircleCell.z - 1)) || !tmpCircleCells.Contains(new IntVec3(tmpCircleCell.x, 0, tmpCircleCell.z)) || !tmpCircleCells.Contains(new IntVec3(tmpCircleCell.x, 0, tmpCircleCell.z + 1)) || !tmpCircleCells.Contains(new IntVec3(tmpCircleCell.x + 1, 0, tmpCircleCell.z - 1)) || !tmpCircleCells.Contains(new IntVec3(tmpCircleCell.x + 1, 0, tmpCircleCell.z)) || !tmpCircleCells.Contains(new IntVec3(tmpCircleCell.x + 1, 0, tmpCircleCell.z + 1))))
                    {
                        IntVec3 intVec3 = tmpCircleCell;
                        intVec3.x += intVec2.x;
                        intVec3.z += intVec2.z;
                        if (intVec3.x >= 0 && intVec3.x < length && intVec3.z >= 0 && intVec3.z < length2)
                        {
                            grid[intVec3.x, intVec3.z] = true;
                        }
                    }
                }
            }
            for (int num13 = 0; num13 < num4; num13++)
            {
                bool bool2 = Rand.Bool;
                foreach (IntVec3 item3 in CellRect.CenteredOn(new IntVec3(Rand.RangeInclusive(0, length - 1), 0, Rand.RangeInclusive(0, length2 - 1)), (!bool2) ? 1 : Mathf.RoundToInt(Rand.RangeInclusive(1, length)), bool2 ? 1 : Mathf.RoundToInt(Rand.RangeInclusive(1, length2))))
                {
                    if (item3.x >= 0 && item3.x < length && item3.z >= 0 && item3.z < length2)
                    {
                        grid[item3.x, item3.z] = true;
                    }
                }
            }
            for (int num14 = 0; num14 < num5; num14++)
            {
                bool     bool3     = Rand.Bool;
                CellRect cellRect2 = CellRect.CenteredOn(new IntVec3(Rand.RangeInclusive(0, length - 1), 0, Rand.RangeInclusive(0, length2 - 1)), Mathf.RoundToInt(Rand.RangeInclusive(1, length)), 1);
                foreach (IntVec3 item4 in cellRect2)
                {
                    int num15 = item4.x - cellRect2.minX - cellRect2.Width / 2;
                    if (bool3)
                    {
                        num15 = -num15;
                    }
                    IntVec3 intVec4 = item4;
                    intVec4.z += num15;
                    if (intVec4.x >= 0 && intVec4.x < length && intVec4.z >= 0 && intVec4.z < length2)
                    {
                        grid[intVec4.x, intVec4.z] = true;
                    }
                }
            }
            if (preferOutlines)
            {
                for (int num16 = 0; num16 < grid.GetLength(0) - 1; num16++)
                {
                    for (int num17 = 0; num17 < grid.GetLength(1) - 1; num17++)
                    {
                        if (grid[num16, num17] && grid[num16 + 1, num17] && grid[num16, num17 + 1] && grid[num16 + 1, num17 + 1])
                        {
                            switch (Rand.Range(0, 4))
                            {
                            case 0:
                                grid[num16, num17] = false;
                                break;

                            case 1:
                                grid[num16 + 1, num17] = false;
                                break;

                            case 2:
                                grid[num16, num17 + 1] = false;
                                break;

                            default:
                                grid[num16 + 1, num17 + 1] = false;
                                break;
                            }
                        }
                    }
                }
            }
            if (wipedCircleRadiusPct > 0f)
            {
                IntVec2 intVec5 = new IntVec2(length / 2, length2 / 2);
                foreach (IntVec3 item5 in GenRadial.RadialPatternInRadius(Mathf.FloorToInt((float)Mathf.Min(length, length2) * wipedCircleRadiusPct)))
                {
                    IntVec3 current7 = item5;
                    current7.x += intVec5.x;
                    current7.z += intVec5.z;
                    if (current7.x >= 0 && current7.x < length && current7.z >= 0 && current7.z < length2)
                    {
                        grid[current7.x, current7.z] = false;
                    }
                }
            }
            if (horizontalSymmetry)
            {
                for (int num18 = grid.GetLength(0) / 2; num18 < grid.GetLength(0); num18++)
                {
                    for (int num19 = 0; num19 < grid.GetLength(1); num19++)
                    {
                        grid[num18, num19] = grid[grid.GetLength(0) - num18 - 1, num19];
                    }
                }
            }
            if (!verticalSymmetry)
            {
                return;
            }
            for (int num20 = 0; num20 < grid.GetLength(0); num20++)
            {
                for (int num21 = grid.GetLength(1) / 2; num21 < grid.GetLength(1); num21++)
                {
                    grid[num20, num21] = grid[num20, grid.GetLength(1) - num21 - 1];
                }
            }
        }