Ejemplo n.º 1
0
        public bool WouldCollide(ThingDef def, IntVec3 pos, Rot4 rot)
        {
            CellRect cellRect = GenAdj.OccupiedRect(pos, rot, def.size);

            if (def.terrainAffordanceNeeded != null)
            {
                foreach (IntVec3 item in cellRect)
                {
                    TerrainDef terrainDef = TerrainAt(item);
                    if (terrainDef != null && !terrainDef.affordances.Contains(def.terrainAffordanceNeeded))
                    {
                        return(true);
                    }
                }
            }
            for (int i = 0; i < cachedThings.Count; i++)
            {
                if (!cellRect.Overlaps(cachedThings[i].OccupiedRect))
                {
                    continue;
                }
                if (def.race != null)
                {
                    if (cachedThings[i].def.passability == Traversability.Impassable)
                    {
                        return(true);
                    }
                }
                else if (!GenConstruct.CanPlaceBlueprintOver(def, cachedThings[i].def))
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        public void WipeColliding(ThingDef def, IntVec3 pos, Rot4 rot)
        {
            if (!WouldCollide(def, pos, rot))
            {
                return;
            }
            CellRect cellRect = GenAdj.OccupiedRect(pos, rot, def.size);

            if (def.terrainAffordanceNeeded != null)
            {
                foreach (IntVec3 item in cellRect)
                {
                    TerrainDef terrainDef = TerrainAt(item);
                    if (terrainDef != null && !terrainDef.affordances.Contains(def.terrainAffordanceNeeded))
                    {
                        RemoveTerrain(item);
                    }
                }
            }
            for (int num = cachedThings.Count - 1; num >= 0; num--)
            {
                if (cellRect.Overlaps(cachedThings[num].OccupiedRect) && !GenConstruct.CanPlaceBlueprintOver(def, cachedThings[num].def))
                {
                    Remove(cachedThings[num]);
                }
            }
        }
Ejemplo n.º 3
0
 public override bool IsSpawningBlockedPermanently(IntVec3 at, Map map, Thing thingToIgnore = null, bool wipeIfCollides = false)
 {
     if (!at.InBounds(map))
     {
         return(true);
     }
     if (!CanBuildOnTerrain(at, map))
     {
         return(true);
     }
     foreach (IntVec3 item in GenAdj.OccupiedRect(at, rot, def.Size))
     {
         if (!item.InBounds(map))
         {
             return(true);
         }
         List <Thing> thingList = item.GetThingList(map);
         for (int i = 0; i < thingList.Count; i++)
         {
             if (!thingList[i].def.destroyable && !GenConstruct.CanPlaceBlueprintOver(def, thingList[i].def))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
 public Thing FirstPermanentBlockerAt(IntVec3 at, Map map)
 {
     foreach (IntVec3 item in GenAdj.OccupiedRect(at, Rot4.North, Buildable.Size))
     {
         if (!item.InBounds(map))
         {
             continue;
         }
         List <Thing> thingList = item.GetThingList(map);
         for (int i = 0; i < thingList.Count; i++)
         {
             if (!thingList[i].def.destroyable && !GenConstruct.CanPlaceBlueprintOver(Buildable, thingList[i].def))
             {
                 return(thingList[i]);
             }
         }
     }
     return(null);
 }
        public static AcceptanceReport CanPlaceBlueprintAt(BuildableDef entDef, IntVec3 center, Rot4 rot, Map map, bool godMode = false, Thing thingToIgnore = null)
        {
            CellRect cellRect = GenAdj.OccupiedRect(center, rot, entDef.Size);

            CellRect.CellRectIterator iterator = cellRect.GetIterator();
            while (!iterator.Done())
            {
                IntVec3 c = iterator.Current;
                if (!c.InBounds(map))
                {
                    return(new AcceptanceReport("OutOfBounds".Translate()));
                }
                if (c.InNoBuildEdgeArea(map) && !DebugSettings.godMode)
                {
                    return("TooCloseToMapEdge".Translate());
                }
                iterator.MoveNext();
            }
            if (center.Fogged(map))
            {
                return("CannotPlaceInUndiscovered".Translate());
            }
            List <Thing> thingList = center.GetThingList(map);

            for (int i = 0; i < thingList.Count; i++)
            {
                Thing thing = thingList[i];
                if (thing != thingToIgnore)
                {
                    if (thing.Position == center && thing.Rotation == rot)
                    {
                        if (thing.def == entDef)
                        {
                            return(new AcceptanceReport("IdenticalThingExists".Translate()));
                        }
                        if (thing.def.entityDefToBuild == entDef)
                        {
                            if (thing is Blueprint)
                            {
                                return(new AcceptanceReport("IdenticalBlueprintExists".Translate()));
                            }
                            return(new AcceptanceReport("IdenticalThingExists".Translate()));
                        }
                    }
                }
            }
            ThingDef thingDef = entDef as ThingDef;

            if (thingDef != null && thingDef.hasInteractionCell)
            {
                IntVec3 c2 = ThingUtility.InteractionCellWhenAt(thingDef, center, rot, map);
                if (!c2.InBounds(map))
                {
                    return(new AcceptanceReport("InteractionSpotOutOfBounds".Translate()));
                }
                List <Thing> list = map.thingGrid.ThingsListAtFast(c2);
                for (int j = 0; j < list.Count; j++)
                {
                    if (list[j] != thingToIgnore)
                    {
                        if (list[j].def.passability == Traversability.Impassable)
                        {
                            return(new AcceptanceReport("InteractionSpotBlocked".Translate(new object[]
                            {
                                list[j].LabelNoCount
                            }).CapitalizeFirst()));
                        }
                        Blueprint blueprint = list[j] as Blueprint;
                        if (blueprint != null && blueprint.def.entityDefToBuild.passability == Traversability.Impassable)
                        {
                            return(new AcceptanceReport("InteractionSpotWillBeBlocked".Translate(new object[]
                            {
                                blueprint.LabelNoCount
                            }).CapitalizeFirst()));
                        }
                    }
                }
            }
            if (entDef.passability == Traversability.Impassable)
            {
                foreach (IntVec3 c3 in GenAdj.CellsAdjacentCardinal(center, rot, entDef.Size))
                {
                    if (c3.InBounds(map))
                    {
                        thingList = c3.GetThingList(map);
                        for (int k = 0; k < thingList.Count; k++)
                        {
                            Thing thing2 = thingList[k];
                            if (thing2 != thingToIgnore)
                            {
                                Blueprint blueprint2 = thing2 as Blueprint;
                                ThingDef  thingDef3;
                                if (blueprint2 != null)
                                {
                                    ThingDef thingDef2 = blueprint2.def.entityDefToBuild as ThingDef;
                                    if (thingDef2 == null)
                                    {
                                        goto IL_37F;
                                    }
                                    thingDef3 = thingDef2;
                                }
                                else
                                {
                                    thingDef3 = thing2.def;
                                }
                                if (thingDef3.hasInteractionCell && cellRect.Contains(ThingUtility.InteractionCellWhenAt(thingDef3, thing2.Position, thing2.Rotation, thing2.Map)))
                                {
                                    return(new AcceptanceReport("WouldBlockInteractionSpot".Translate(new object[]
                                    {
                                        entDef.label,
                                        thingDef3.label
                                    }).CapitalizeFirst()));
                                }
                            }
                            IL_37F :;
                        }
                    }
                }
            }
            TerrainDef terrainDef = entDef as TerrainDef;

            if (terrainDef != null)
            {
                if (map.terrainGrid.TerrainAt(center) == terrainDef)
                {
                    return(new AcceptanceReport("TerrainIsAlready".Translate(new object[]
                    {
                        terrainDef.label
                    })));
                }
                if (map.designationManager.DesignationAt(center, DesignationDefOf.SmoothFloor) != null)
                {
                    return(new AcceptanceReport("SpaceBeingSmoothed".Translate()));
                }
            }
            if (!GenConstruct.CanBuildOnTerrain(entDef, center, map, rot, thingToIgnore))
            {
                return(new AcceptanceReport("TerrainCannotSupport".Translate()));
            }
            if (!godMode)
            {
                CellRect.CellRectIterator iterator2 = cellRect.GetIterator();
                while (!iterator2.Done())
                {
                    thingList = iterator2.Current.GetThingList(map);
                    for (int l = 0; l < thingList.Count; l++)
                    {
                        Thing thing3 = thingList[l];
                        if (thing3 != thingToIgnore)
                        {
                            if (!GenConstruct.CanPlaceBlueprintOver(entDef, thing3.def))
                            {
                                return(new AcceptanceReport("SpaceAlreadyOccupied".Translate()));
                            }
                        }
                    }
                    iterator2.MoveNext();
                }
            }
            if (entDef.PlaceWorkers != null)
            {
                for (int m = 0; m < entDef.PlaceWorkers.Count; m++)
                {
                    AcceptanceReport result = entDef.PlaceWorkers[m].AllowsPlacing(entDef, center, rot, map, thingToIgnore);
                    if (!result.Accepted)
                    {
                        return(result);
                    }
                }
            }
            return(AcceptanceReport.WasAccepted);
        }