private void CalculateRoofsAboutToCollapse(CellRect rect)
        {
            Map map = BaseGen.globalSettings.map;

            SymbolResolver_EnsureCanHoldRoof.roofsAboutToCollapse.Clear();
            SymbolResolver_EnsureCanHoldRoof.visited.Clear();
            CellRect.CellRectIterator iterator = rect.GetIterator();
            while (!iterator.Done())
            {
                IntVec3 current = iterator.Current;
                if (current.Roofed(map))
                {
                    if (!RoofCollapseCellsFinder.ConnectsToRoofHolder(current, map, SymbolResolver_EnsureCanHoldRoof.visited))
                    {
                        map.floodFiller.FloodFill(current, (IntVec3 x) => x.Roofed(map), delegate(IntVec3 x)
                        {
                            SymbolResolver_EnsureCanHoldRoof.roofsAboutToCollapse.Add(x);
                        }, 2147483647, false, null);
                    }
                }
                iterator.MoveNext();
            }
            CellRect.CellRectIterator iterator2 = rect.GetIterator();
            while (!iterator2.Done())
            {
                IntVec3 current2 = iterator2.Current;
                if (current2.Roofed(map))
                {
                    if (!SymbolResolver_EnsureCanHoldRoof.roofsAboutToCollapse.Contains(current2))
                    {
                        if (!RoofCollapseUtility.WithinRangeOfRoofHolder(current2, map, false))
                        {
                            SymbolResolver_EnsureCanHoldRoof.roofsAboutToCollapse.Add(current2);
                        }
                    }
                }
                iterator2.MoveNext();
            }
        }
 public static bool TerrainCanSupport(CellRect rect, Map map, ThingDef thing)
 {
     CellRect.CellRectIterator iterator = rect.GetIterator();
     while (!iterator.Done())
     {
         if (!iterator.Current.SupportsStructureType(map, thing.terrainAffordanceNeeded))
         {
             return(false);
         }
         iterator.MoveNext();
     }
     return(true);
 }
Exemplo n.º 3
0
        private bool TryFindSpawnCell(CellRect rect, ThingDef thingDef, Rot4 rot, out IntVec3 spawnCell)
        {
            Map     map  = BaseGen.globalSettings.map;
            IntVec3 zero = IntVec3.Zero;
            IntVec2 size = thingDef.size;

            GenAdj.AdjustForRotation(ref zero, ref size, rot);
            CellRect             empty         = CellRect.Empty;
            Predicate <CellRect> basePredicate = delegate(CellRect x)
            {
                int arg_83_0;
                if (x.Cells.All((IntVec3 y) => y.Standable(map)))
                {
                    if (!GenSpawn.WouldWipeAnythingWith(x, thingDef, map, (Thing z) => z.def.category == ThingCategory.Building))
                    {
                        arg_83_0 = ((thingDef.category != ThingCategory.Item || x.CenterCell.GetFirstItem(map) == null) ? 1 : 0);
                        return(arg_83_0 != 0);
                    }
                }
                arg_83_0 = 0;
                return(arg_83_0 != 0);
            };
            bool flag = false;

            if (thingDef.category == ThingCategory.Building)
            {
                flag = rect.TryFindRandomInnerRectTouchingEdge(size, out empty, (CellRect x) => basePredicate(x) && !BaseGenUtility.AnyDoorAdjacentCardinalTo(x, map) && GenConstruct.TerrainCanSupport(x, map, thingDef));
                if (!flag)
                {
                    flag = rect.TryFindRandomInnerRectTouchingEdge(size, out empty, (CellRect x) => basePredicate(x) && !BaseGenUtility.AnyDoorAdjacentCardinalTo(x, map));
                }
            }
            if (!flag && !rect.TryFindRandomInnerRectTouchingEdge(size, out empty, basePredicate))
            {
                spawnCell = IntVec3.Invalid;
                return(false);
            }
            CellRect.CellRectIterator iterator = empty.GetIterator();
            while (!iterator.Done())
            {
                if (GenAdj.OccupiedRect(iterator.Current, rot, thingDef.size) == empty)
                {
                    spawnCell = iterator.Current;
                    return(true);
                }
                iterator.MoveNext();
            }
            Log.Error("We found a valid rect but we couldn't find the root position. This should never happen.", false);
            spawnCell = IntVec3.Invalid;
            return(false);
        }
        private CellRect FindRandomRectToDefend(Map map)
        {
            int           rectRadius     = Mathf.Max(Mathf.RoundToInt((float)Mathf.Min(map.Size.x, map.Size.z) * 0.07f), 1);
            TraverseParms traverseParams = TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false);
            IntVec3       center;
            CellRect      result;

            if (RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith(delegate(IntVec3 x)
            {
                bool result2;
                if (!map.reachability.CanReachMapEdge(x, traverseParams))
                {
                    result2 = false;
                }
                else
                {
                    CellRect cellRect = CellRect.CenteredOn(x, rectRadius);
                    int num = 0;
                    CellRect.CellRectIterator iterator = cellRect.GetIterator();
                    while (!iterator.Done())
                    {
                        if (!iterator.Current.InBounds(map))
                        {
                            return(false);
                        }
                        if (iterator.Current.Standable(map) || iterator.Current.GetPlant(map) != null)
                        {
                            num++;
                        }
                        iterator.MoveNext();
                    }
                    result2 = ((float)num / (float)cellRect.Area >= 0.6f);
                }
                return(result2);
            }, map, out center))
            {
                result = CellRect.CenteredOn(center, rectRadius);
            }
            else if (RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith((IntVec3 x) => x.Standable(map), map, out center))
            {
                result = CellRect.CenteredOn(center, rectRadius);
            }
            else
            {
                result = CellRect.CenteredOn(CellFinder.RandomCell(map), rectRadius).ClipInsideMap(map);
            }
            return(result);
        }
 public void Init(CellRect end, TraverseParms traverseParms, int moveTicksCardinal, int moveTicksDiagonal, ByteGrid avoidGrid, Area allowedArea, bool drafted, List <int> disallowedCorners)
 {
     this.moveTicksCardinal         = moveTicksCardinal;
     this.moveTicksDiagonal         = moveTicksDiagonal;
     this.endCell                   = end.CenterCell;
     this.cachedRegion              = null;
     this.cachedBestLink            = null;
     this.cachedSecondBestLink      = null;
     this.cachedBestLinkCost        = 0;
     this.cachedSecondBestLinkCost  = 0;
     this.cachedRegionCellPathCost  = 0;
     this.cachedRegionIsDestination = false;
     this.regionGrid                = this.map.regionGrid.DirectGrid;
     this.destRegions.Clear();
     if (end.Width == 1 && end.Height == 1)
     {
         Region region = this.endCell.GetRegion(this.map, RegionType.Set_Passable);
         if (region != null)
         {
             this.destRegions.Add(region);
         }
     }
     else
     {
         CellRect.CellRectIterator iterator = end.GetIterator();
         while (!iterator.Done())
         {
             IntVec3 intVec = iterator.Current;
             if (intVec.InBounds(this.map) && !disallowedCorners.Contains(this.map.cellIndices.CellToIndex(intVec)))
             {
                 Region region2 = intVec.GetRegion(this.map, RegionType.Set_Passable);
                 if (region2 != null)
                 {
                     if (region2.Allows(traverseParms, true))
                     {
                         this.destRegions.Add(region2);
                     }
                 }
             }
             iterator.MoveNext();
         }
     }
     if (this.destRegions.Count == 0)
     {
         Log.Error("Couldn't find any destination regions. This shouldn't ever happen because we've checked reachability.", false);
     }
     this.regionCostCalculator.Init(end, this.destRegions, traverseParms, moveTicksCardinal, moveTicksDiagonal, avoidGrid, allowedArea, drafted);
 }
Exemplo n.º 6
0
        private void SpawnFloor(CellRect rect, bool horizontal, TerrainDef floorDef)
        {
            Map         map         = BaseGen.globalSettings.map;
            TerrainGrid terrainGrid = map.terrainGrid;

            CellRect.CellRectIterator iterator = rect.GetIterator();
            while (!iterator.Done())
            {
                IntVec3 current = iterator.Current;
                if ((horizontal && SymbolResolver_Street.street[current.x - rect.minX]) || (!horizontal && SymbolResolver_Street.street[current.z - rect.minZ]))
                {
                    terrainGrid.SetTerrain(current, floorDef);
                }
                iterator.MoveNext();
            }
        }
Exemplo n.º 7
0
            internal bool <> m__0(CellRect x)
            {
                int num = 0;

                CellRect.CellRectIterator iterator = x.GetIterator();
                while (!iterator.Done())
                {
                    if (iterator.Current.Standable(this.map) && iterator.Current.GetFirstItem(this.map) == null && iterator.Current.GetFirstBuilding(this.map) == null)
                    {
                        num++;
                    }
                    iterator.MoveNext();
                }
                this.maxValidCellsFoundLocal = Mathf.Max(this.maxValidCellsFoundLocal, num);
                return(num >= this.minValidCells);
            }
Exemplo n.º 8
0
        private bool OutOfBounds(Pawn mountedTo, Thing parent)
        {
            CellRect cellRect = GenAdj.OccupiedRect(mountedTo.Position, mountedTo.Rotation, parent.def.Size + new IntVec2(1, 1));

            CellRect.CellRectIterator iterator = cellRect.GetIterator();
            while (!iterator.Done())
            {
                IntVec3 current = iterator.Current;
                if (!current.InBounds(mountedTo.Map))
                {
                    return(true);
                }
                iterator.MoveNext();
            }
            return(false);
        }
Exemplo n.º 9
0
 private void DestroyTemporaryRegionBarriers(CellRect rect, Map map)
 {
     CellRect.CellRectIterator iterator = rect.GetIterator();
     while (!iterator.Done())
     {
         Thing thing = iterator.Current.GetThingList(map).Find((Thing x) => x.def.temporaryRegionBarrier);
         if (thing == null)
         {
             Log.Warning("Could not destroy temporary region barrier at " + iterator.Current + " because it's not here.");
         }
         else
         {
             thing.Destroy(DestroyMode.Vanish);
         }
         iterator.MoveNext();
     }
 }
Exemplo n.º 10
0
            internal bool <> m__0(IntVec3 x)
            {
                int      num      = Mathf.CeilToInt(Mathf.Sqrt((float)this.maxMineables)) + 2;
                CellRect cellRect = CellRect.CenteredOn(x, num, num);
                int      num2     = 0;

                CellRect.CellRectIterator iterator = cellRect.GetIterator();
                while (!iterator.Done())
                {
                    if (iterator.Current.InBounds(this.map) && iterator.Current.Standable(this.map))
                    {
                        num2++;
                    }
                    iterator.MoveNext();
                }
                return(num2 >= this.maxMineables);
            }
Exemplo n.º 11
0
 static bool AnyNonStandableCellOrAnyBuildingInside(Map map, CellRect rect)
 {
     CellRect.CellRectIterator iterator = rect.GetIterator();
     while (!iterator.Done())
     {
         if (!iterator.Current.Standable(map))
         {
             return(true);
         }
         if (iterator.Current.GetEdifice(map) != null)
         {
             return(true);
         }
         iterator.MoveNext();
     }
     return(false);
 }
        public override void Regenerate()
        {
            base.ClearSubMeshes(MeshParts.All);
            Map         map         = base.Map;
            TerrainGrid terrainGrid = map.terrainGrid;
            CellRect    cellRect    = this.section.CellRect;
            float       y           = AltitudeLayer.TerrainScatter.AltitudeFor();

            CellRect.CellRectIterator iterator = cellRect.GetIterator();
            while (!iterator.Done())
            {
                IntVec3 intVec = iterator.Current;
                if (this.ShouldDrawPropsBelow(intVec, terrainGrid))
                {
                    IntVec3 c = intVec;
                    c.x++;
                    Material material;
                    if (c.InBounds(map) && this.ShouldDrawPropsBelow(c, terrainGrid))
                    {
                        material = SectionLayer_BridgeProps.PropsLoopMat;
                    }
                    else
                    {
                        material = SectionLayer_BridgeProps.PropsRightMat;
                    }
                    LayerSubMesh subMesh = base.GetSubMesh(material);
                    int          count   = subMesh.verts.Count;
                    subMesh.verts.Add(new Vector3((float)intVec.x, y, (float)(intVec.z - 1)));
                    subMesh.verts.Add(new Vector3((float)intVec.x, y, (float)intVec.z));
                    subMesh.verts.Add(new Vector3((float)(intVec.x + 1), y, (float)intVec.z));
                    subMesh.verts.Add(new Vector3((float)(intVec.x + 1), y, (float)(intVec.z - 1)));
                    subMesh.uvs.Add(new Vector2(0f, 0f));
                    subMesh.uvs.Add(new Vector2(0f, 1f));
                    subMesh.uvs.Add(new Vector2(1f, 1f));
                    subMesh.uvs.Add(new Vector2(1f, 0f));
                    subMesh.tris.Add(count);
                    subMesh.tris.Add(count + 1);
                    subMesh.tris.Add(count + 2);
                    subMesh.tris.Add(count);
                    subMesh.tris.Add(count + 2);
                    subMesh.tris.Add(count + 3);
                }
                iterator.MoveNext();
            }
            base.FinalizeMesh(MeshParts.All);
        }
Exemplo n.º 13
0
        public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null)
        {
            /*
             * 맵 이내여야함
             * 조리대 위치쪽도 맵이내여야함
             *
             */
            //GenThing.TrueCenter(loc, rot, checkingDef.Size, checkingDef.Altitude)

            AcceptanceReport result = false;

            CellRect cellRect = GenAdj.OccupiedRect(loc, rot, checkingDef.Size);

            CellRect.CellRectIterator iterator = cellRect.GetIterator();
            bool needWallFlag = false;
            bool isInBound    = true;

            while (!iterator.Done())
            {
                IntVec3 c           = iterator.Current;
                IntVec3 addonTarget = c - rot.FacingCell;

                if (!GenGrid.Impassable(c, map))
                {
                    result       = Translator.Translate("WallAttachment_WarningNeedWall");
                    needWallFlag = true;
                }
                if (!c.InBounds(map) || !addonTarget.InBounds(map))
                {
                    result    = "OutOfBounds".Translate();
                    isInBound = false;
                }
                if ((c.InNoBuildEdgeArea(map) || addonTarget.InNoBuildEdgeArea(map)) && !DebugSettings.godMode)
                {
                    result    = "TooCloseToMapEdge".Translate();
                    isInBound = false;
                }
                iterator.MoveNext();
            }
            if (!needWallFlag && isInBound)
            {
                result = true;
            }
            return(result);
        }
 //GenConstruct
 public static void TerrainCanSupport(CellRect rect, Map map, ThingDef thing, ref bool __result)
 {
     if (thing.defName == "Estate_WaterPump" ||
         thing.defName == "Estate_WaterConduit")
     {
         CellRect.CellRectIterator iterator = rect.GetIterator();
         while (!iterator.Done())
         {
             if (!iterator.Current.SupportsStructureType(map, thing.terrainAffordanceNeeded) && iterator.Current.GetTerrain(map).defName != "Mud")
             {
                 __result = false;
                 return;
             }
             iterator.MoveNext();
         }
         __result = true;
     }
 }
        private bool AnyNonStandableCellOrAnyBuildingInside(CellRect rect)
        {
            Map map = BaseGen.globalSettings.map;

            CellRect.CellRectIterator iterator = rect.GetIterator();
            while (!iterator.Done())
            {
                if (!iterator.Current.Standable(map))
                {
                    return(true);
                }
                if (iterator.Current.GetEdifice(map) != null)
                {
                    return(true);
                }
                iterator.MoveNext();
            }
            return(false);
        }
        //public static bool CanBuildOnTerrain(BuildableDef entDef, IntVec3 c, Map map, Rot4 rot, Thing thingToIgnore = null)
        public static bool Prefix(ref bool __result, BuildableDef entDef, IntVec3 c, Map map, Rot4 rot, Thing thingToIgnore = null)
        {
            CellRect cellRect = GenAdj.OccupiedRect(c, rot, entDef.Size);

            cellRect.ClipInsideMap(map);
            CellRect.CellRectIterator iterator = cellRect.GetIterator();
            while (!iterator.Done())
            {
                if (iterator.Current.SupportsStructureType(map, TerrainDefOf.Bridge.terrainAffordanceNeeded) &&
                    TerrainDefOf.Bridge.affordances.Contains(entDef.terrainAffordanceNeeded))
                {
                    __result = true;
                    return(false);
                }
                iterator.MoveNext();
            }

            return(true);
        }
Exemplo n.º 17
0
        public static void CheckSpawnBridgeUnder(ThingDef thingDef, IntVec3 c, Rot4 rot)
        {
            if (thingDef.category != ThingCategory.Building)
            {
                return;
            }
            Map      map      = BaseGen.globalSettings.map;
            CellRect cellRect = GenAdj.OccupiedRect(c, rot, thingDef.size);

            BaseGenUtility.bridgeCells.Clear();
            CellRect.CellRectIterator iterator = cellRect.GetIterator();
            while (!iterator.Done())
            {
                if (!iterator.Current.SupportsStructureType(map, thingDef.terrainAffordanceNeeded) && GenConstruct.CanBuildOnTerrain(TerrainDefOf.Bridge, iterator.Current, map, Rot4.North, null))
                {
                    BaseGenUtility.bridgeCells.Add(iterator.Current);
                }
                iterator.MoveNext();
            }
            if (!BaseGenUtility.bridgeCells.Any <IntVec3>())
            {
                return;
            }
            if (thingDef.size.x != 1 || thingDef.size.z != 1)
            {
                for (int i = BaseGenUtility.bridgeCells.Count - 1; i >= 0; i--)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        IntVec3 intVec = BaseGenUtility.bridgeCells[i] + GenAdj.AdjacentCells[j];
                        if (!BaseGenUtility.bridgeCells.Contains(intVec) && intVec.InBounds(map) && !intVec.SupportsStructureType(map, thingDef.terrainAffordanceNeeded) && GenConstruct.CanBuildOnTerrain(TerrainDefOf.Bridge, intVec, map, Rot4.North, null))
                        {
                            BaseGenUtility.bridgeCells.Add(intVec);
                        }
                    }
                }
            }
            for (int k = 0; k < BaseGenUtility.bridgeCells.Count; k++)
            {
                map.terrainGrid.SetTerrain(BaseGenUtility.bridgeCells[k], TerrainDefOf.Bridge);
            }
        }
        public static ThingDef DeterminePlantDef(CellRect rect)
        {
            Map      map = BaseGen.globalSettings.map;
            ThingDef result;

            if (map.mapTemperature.OutdoorTemp < 0f || map.mapTemperature.OutdoorTemp > 58f)
            {
                result = null;
            }
            else
            {
                float minFertility = float.MaxValue;
                bool  flag         = false;
                CellRect.CellRectIterator iterator = rect.GetIterator();
                while (!iterator.Done())
                {
                    float num = map.fertilityGrid.FertilityAt(iterator.Current);
                    if (num > 0f)
                    {
                        flag         = true;
                        minFertility = Mathf.Min(minFertility, num);
                    }
                    iterator.MoveNext();
                }
                ThingDef thingDef;
                if (!flag)
                {
                    result = null;
                }
                else if ((from x in DefDatabase <ThingDef> .AllDefsListForReading
                          where x.category == ThingCategory.Plant && x.plant.Sowable && !x.plant.IsTree && !x.plant.cavePlant && x.plant.fertilityMin <= minFertility && x.plant.Harvestable
                          select x).TryRandomElement(out thingDef))
                {
                    result = thingDef;
                }
                else
                {
                    result = null;
                }
            }
            return(result);
        }
        private CellRect FindRandomRectToDefend(Map map)
        {
            IntVec3       size           = map.Size;
            int           x2             = size.x;
            IntVec3       size2          = map.Size;
            int           rectRadius     = Mathf.Max(Mathf.RoundToInt((float)((float)Mathf.Min(x2, size2.z) * 0.070000000298023224)), 1);
            TraverseParms traverseParams = TraverseParms.For(TraverseMode.PassDoors, Danger.Deadly, false);
            IntVec3       center         = default(IntVec3);

            if (RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith((Predicate <IntVec3>) delegate(IntVec3 x)
            {
                if (!map.reachability.CanReachMapEdge(x, traverseParams))
                {
                    return(false);
                }
                CellRect cellRect = CellRect.CenteredOn(x, rectRadius);
                int num = 0;
                CellRect.CellRectIterator iterator = cellRect.GetIterator();
                while (!iterator.Done())
                {
                    if (!iterator.Current.InBounds(map))
                    {
                        return(false);
                    }
                    if (iterator.Current.Standable(map) || iterator.Current.GetPlant(map) != null)
                    {
                        num++;
                    }
                    iterator.MoveNext();
                }
                return((float)num / (float)cellRect.Area >= 0.60000002384185791);
            }, map, out center))
            {
                return(CellRect.CenteredOn(center, rectRadius));
            }
            if (RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith((Predicate <IntVec3>)((IntVec3 x) => x.Standable(map)), map, out center))
            {
                return(CellRect.CenteredOn(center, rectRadius));
            }
            return(CellRect.CenteredOn(CellFinder.RandomCell(map), rectRadius).ClipInsideMap(map));
        }
Exemplo n.º 20
0
        private bool TryFindCell(out IntVec3 cell, Map map)
        {
            int maxMineables = ThingSetMaker_Meteorite.MineablesCountRange.max;

            return(CellFinderLoose.TryFindSkyfallerCell(ThingDefOf.MeteoriteIncoming, map, out cell, 10, default(IntVec3), -1, true, false, false, false, true, true, delegate(IntVec3 x)
            {
                int num = Mathf.CeilToInt(Mathf.Sqrt((float)maxMineables)) + 2;
                CellRect cellRect = CellRect.CenteredOn(x, num, num);
                int num2 = 0;
                CellRect.CellRectIterator iterator = cellRect.GetIterator();
                while (!iterator.Done())
                {
                    if (iterator.Current.InBounds(map) && iterator.Current.Standable(map))
                    {
                        num2++;
                    }
                    iterator.MoveNext();
                }
                return num2 >= maxMineables;
            }));
        }
Exemplo n.º 21
0
        public override AcceptanceReport AllowsPlacing(BuildableDef def, IntVec3 center, Rot4 rot, Map map, Thing thingToIgnore = null)
        {
            CellRect cellRect = GenAdj.OccupiedRect(center, rot, def.Size);

            cellRect = cellRect.ExpandedBy(1);
            CellRect.CellRectIterator iterator = cellRect.GetIterator();
            while (!iterator.Done())
            {
                IntVec3      current = iterator.Current;
                List <Thing> list    = map.thingGrid.ThingsListAt(current);
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i] != thingToIgnore && list[i].def.passability != 0)
                    {
                        return("MustPlaceAdjacentStandable".Translate());
                    }
                }
                iterator.MoveNext();
            }
            return(true);
        }
        private bool TryFindCell(out IntVec3 cell, Map map)
        {
            IntRange mineablesCountRange = ThingSetMaker_Meteorite.MineablesCountRange;
            int      maxMineables        = mineablesCountRange.max;

            return(CellFinderLoose.TryFindSkyfallerCell(ThingDefOf.MeteoriteIncoming, map, out cell, 10, default(IntVec3), -1, allowRoofedCells : true, allowCellsWithItems : false, allowCellsWithBuildings : false, colonyReachable : false, avoidColonistsIfExplosive : true, alwaysAvoidColonists : true, delegate(IntVec3 x)
            {
                int num = Mathf.CeilToInt(Mathf.Sqrt((float)maxMineables)) + 2;
                CellRect cellRect = CellRect.CenteredOn(x, num, num);
                int num2 = 0;
                CellRect.CellRectIterator iterator = cellRect.GetIterator();
                while (!iterator.Done())
                {
                    if (iterator.Current.InBounds(map) && iterator.Current.Standable(map))
                    {
                        num2++;
                    }
                    iterator.MoveNext();
                }
                return num2 >= maxMineables;
            }));
        }
Exemplo n.º 23
0
        private void GetPreciseRegionLinkDistances(WaterRegion region, CellRect destination, List <Pair <WaterRegionLink, int> > outDistances)
        {
            outDistances.Clear();
            RegionCostCalculatorShips.tmpCellIndices.Clear();
            if (destination.Width == 1 && destination.Height == 1)
            {
                RegionCostCalculatorShips.tmpCellIndices.Add(this.map.cellIndices.CellToIndex(destination.CenterCell));
            }
            else
            {
                CellRect.CellRectIterator iterator = destination.GetIterator();
                while (!iterator.Done())
                {
                    IntVec3 c = iterator.Current;
                    if (c.InBoundsShip(this.map))
                    {
                        RegionCostCalculatorShips.tmpCellIndices.Add(this.map.cellIndices.CellToIndex(c));
                    }
                    iterator.MoveNext();
                }
            }
            Dijkstra <int> .Run(RegionCostCalculatorShips.tmpCellIndices, (int x) => this.PreciseRegionLinkDistancesNeighborsGetter(x, region),
                                this.preciseRegionLinkDistancesDistanceGetter, RegionCostCalculatorShips.tmpDistances, null);

            foreach (WaterRegionLink regionLink in region.links)
            {
                if (regionLink.GetOtherRegion(region).Allows(this.traverseParms, false))
                {
                    float num;
                    if (!RegionCostCalculatorShips.tmpDistances.TryGetValue(this.map.cellIndices.CellToIndex(this.linkTargetCells[regionLink]), out num))
                    {
                        Log.ErrorOnce("Dijkstra couldn't reach one of the cells even though they are in the same region. There is most likely something wrong with the " +
                                      "neighbor nodes getter. Error occurred in ShipPathFinder of RimShips", 1938471531, false);
                        num = 100f;
                    }
                    outDistances.Add(new Pair <WaterRegionLink, int>(regionLink, (int)num));
                }
            }
        }
Exemplo n.º 24
0
        public static bool CanBuildOnTerrain(BuildableDef entDef, IntVec3 c, Map map, Rot4 rot, Thing thingToIgnore = null)
        {
            TerrainDef terrainDef = entDef as TerrainDef;

            if (terrainDef != null)
            {
                if (!c.GetTerrain(map).changeable)
                {
                    return(false);
                }
            }
            CellRect cellRect = GenAdj.OccupiedRect(c, rot, entDef.Size);

            cellRect.ClipInsideMap(map);
            CellRect.CellRectIterator iterator = cellRect.GetIterator();
            while (!iterator.Done())
            {
                TerrainDef terrainDef2 = map.terrainGrid.TerrainAt(iterator.Current);
                if (entDef.terrainAffordanceNeeded != null && !terrainDef2.affordances.Contains(entDef.terrainAffordanceNeeded))
                {
                    return(false);
                }
                List <Thing> thingList = iterator.Current.GetThingList(map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    if (thingList[i] != thingToIgnore)
                    {
                        TerrainDef terrainDef3 = thingList[i].def.entityDefToBuild as TerrainDef;
                        if (terrainDef3 != null && !terrainDef3.affordances.Contains(entDef.terrainAffordanceNeeded))
                        {
                            return(false);
                        }
                    }
                }
                iterator.MoveNext();
            }
            return(true);
        }
Exemplo n.º 25
0
        private void GetPreciseRegionLinkDistances(Region region, CellRect destination, List <Pair <RegionLink, int> > outDistances)
        {
            outDistances.Clear();
            RegionCostCalculator.tmpCellIndices.Clear();
            if (destination.Width == 1 && destination.Height == 1)
            {
                RegionCostCalculator.tmpCellIndices.Add(this.map.cellIndices.CellToIndex(destination.CenterCell));
            }
            else
            {
                CellRect.CellRectIterator iterator = destination.GetIterator();
                while (!iterator.Done())
                {
                    IntVec3 current = iterator.Current;
                    if (current.InBounds(this.map))
                    {
                        RegionCostCalculator.tmpCellIndices.Add(this.map.cellIndices.CellToIndex(current));
                    }
                    iterator.MoveNext();
                }
            }
            Dijkstra <int> .Run(RegionCostCalculator.tmpCellIndices, (int x) => this.PreciseRegionLinkDistancesNeighborsGetter(x, region), this.preciseRegionLinkDistancesDistanceGetter, RegionCostCalculator.tmpDistances, null);

            for (int i = 0; i < region.links.Count; i++)
            {
                RegionLink regionLink = region.links[i];
                if (regionLink.GetOtherRegion(region).type.Passable())
                {
                    float num;
                    if (!RegionCostCalculator.tmpDistances.TryGetValue(this.map.cellIndices.CellToIndex(this.linkTargetCells[regionLink]), out num))
                    {
                        Log.ErrorOnce("Dijkstra couldn't reach one of the cells even though they are in the same region. There is most likely something wrong with the neighbor nodes getter.", 1938471531);
                        num = 100f;
                    }
                    outDistances.Add(new Pair <RegionLink, int>(regionLink, (int)num));
                }
            }
        }
Exemplo n.º 26
0
        public override void Regenerate()
        {
            ClearSubMeshes(MeshParts.All);
            Map         map         = base.Map;
            TerrainGrid terrainGrid = map.terrainGrid;
            CellRect    cellRect    = section.CellRect;
            float       y           = AltitudeLayer.TerrainScatter.AltitudeFor();

            CellRect.CellRectIterator iterator = cellRect.GetIterator();
            while (!iterator.Done())
            {
                IntVec3 current = iterator.Current;
                if (ShouldDrawPropsBelow(current, terrainGrid))
                {
                    IntVec3 c = current;
                    c.x++;
                    Material     material = (!c.InBounds(map) || !ShouldDrawPropsBelow(c, terrainGrid)) ? PropsRightMat : PropsLoopMat;
                    LayerSubMesh subMesh  = GetSubMesh(material);
                    int          count    = subMesh.verts.Count;
                    subMesh.verts.Add(new Vector3((float)current.x, y, (float)(current.z - 1)));
                    subMesh.verts.Add(new Vector3((float)current.x, y, (float)current.z));
                    subMesh.verts.Add(new Vector3((float)(current.x + 1), y, (float)current.z));
                    subMesh.verts.Add(new Vector3((float)(current.x + 1), y, (float)(current.z - 1)));
                    subMesh.uvs.Add(new Vector2(0f, 0f));
                    subMesh.uvs.Add(new Vector2(0f, 1f));
                    subMesh.uvs.Add(new Vector2(1f, 1f));
                    subMesh.uvs.Add(new Vector2(1f, 0f));
                    subMesh.tris.Add(count);
                    subMesh.tris.Add(count + 1);
                    subMesh.tris.Add(count + 2);
                    subMesh.tris.Add(count);
                    subMesh.tris.Add(count + 2);
                    subMesh.tris.Add(count + 3);
                }
                iterator.MoveNext();
            }
            FinalizeMesh(MeshParts.All);
        }
 //GenConstruct
 public static void CanBuildOnTerrain(BuildableDef entDef, IntVec3 c, Map map, Rot4 rot,
                                      Thing thingToIgnore, ref bool __result)
 {
     if (entDef.defName == "Estate_WaterPump" ||
         entDef.defName == "Estate_WaterConduit")
     {
         CellRect cellRect = GenAdj.OccupiedRect(c, rot, entDef.Size);
         cellRect.ClipInsideMap(map);
         CellRect.CellRectIterator iterator = cellRect.GetIterator();
         while (!iterator.Done())
         {
             TerrainDef terrainDef2 = map.terrainGrid.TerrainAt(iterator.Current);
             if (terrainDef2.defName != "Mud" &&
                 !terrainDef2.affordances.Contains(entDef.terrainAffordanceNeeded))
             {
                 __result = false;
                 return;
             }
             iterator.MoveNext();
         }
         __result = true;
     }
 }
Exemplo n.º 28
0
        private void GetPreciseRegionLinkDistances(Region region, CellRect destination, List <Pair <RegionLink, int> > outDistances)
        {
            outDistances.Clear();
            tmpCellIndices.Clear();
            if (destination.Width == 1 && destination.Height == 1)
            {
                tmpCellIndices.Add(map.cellIndices.CellToIndex(destination.CenterCell));
            }
            else
            {
                CellRect.CellRectIterator iterator = destination.GetIterator();
                while (!iterator.Done())
                {
                    IntVec3 current = iterator.Current;
                    if (current.InBounds(map))
                    {
                        tmpCellIndices.Add(map.cellIndices.CellToIndex(current));
                    }
                    iterator.MoveNext();
                }
            }
            Dijkstra <int> .Run(tmpCellIndices, (int x) => PreciseRegionLinkDistancesNeighborsGetter(x, region), preciseRegionLinkDistancesDistanceGetter, tmpDistances);

            for (int i = 0; i < region.links.Count; i++)
            {
                RegionLink regionLink = region.links[i];
                if (regionLink.GetOtherRegion(region).Allows(traverseParms, isDestination: false))
                {
                    if (!tmpDistances.TryGetValue(map.cellIndices.CellToIndex(linkTargetCells[regionLink]), out float value))
                    {
                        Log.ErrorOnce("Dijkstra couldn't reach one of the cells even though they are in the same region. There is most likely something wrong with the neighbor nodes getter.", 1938471531);
                        value = 100f;
                    }
                    outDistances.Add(new Pair <RegionLink, int>(regionLink, (int)value));
                }
            }
        }
Exemplo n.º 29
0
        public static void CanDesignateCell_Postfix(ref IntVec3 c, ref Designator __instance, ref AcceptanceReport __result)
        {
            if (__result.Accepted)
            {
                Traverse traverse = Traverse.Create(__instance);
                CellRect cellRect = GenAdj.OccupiedRect(c, traverse.Field("placingRot").GetValue <Rot4>(), traverse.Property("PlacingDef").GetValue <BuildableDef>().Size);

                Map map = traverse.Property("Map").GetValue <Map>();
                MapComponentSeenFog seenFog = map.getMapComponentSeenFog();
                if (seenFog != null)
                {
                    CellRect.CellRectIterator itCellRect = cellRect.GetIterator();
                    while (!itCellRect.Done())
                    {
                        if (!seenFog.knownCells[map.cellIndices.CellToIndex(itCellRect.Current)])
                        {
                            __result = "CannotPlaceInUndiscovered".Translate();
                            return;
                        }
                        itCellRect.MoveNext();
                    }
                }
            }
        }
            internal bool <> m__0(IntVec3 x)
            {
                if (!this.map.reachability.CanReachMapEdge(x, this.traverseParams))
                {
                    return(false);
                }
                CellRect cellRect = CellRect.CenteredOn(x, this.rectRadius);
                int      num      = 0;

                CellRect.CellRectIterator iterator = cellRect.GetIterator();
                while (!iterator.Done())
                {
                    if (!iterator.Current.InBounds(this.map))
                    {
                        return(false);
                    }
                    if (iterator.Current.Standable(this.map) || iterator.Current.GetPlant(this.map) != null)
                    {
                        num++;
                    }
                    iterator.MoveNext();
                }
                return((float)num / (float)cellRect.Area >= 0.6f);
            }