private void Init(RimWorld.Blueprint blueprint, IntVec3 origin)
 {
     if (blueprint.def.entityDefToBuild is TerrainDef)
     {
         Init(blueprint.def.entityDefToBuild as TerrainDef, blueprint.Position, origin);
     }
     else if (blueprint is Blueprint_Build)
     {
         Init(blueprint.def.entityDefToBuild as ThingDef, (blueprint as Blueprint_Build).stuffToUse, blueprint.Position, blueprint.Rotation, origin);
     }
     else if (blueprint is Blueprint_Install)
     {
         Init(blueprint.def.entityDefToBuild as ThingDef, (blueprint as Blueprint_Install).MiniToInstallOrBuildingToReinstall.Stuff, blueprint.Position, blueprint.Rotation, origin);
     }
 }
Example #2
0
 private static bool <Cleanup> m__3(Blueprint blue)
 {
     return(blue.Destroyed);
 }
Example #3
0
 private static bool <LordToilTick> m__1(Blueprint blue)
 {
     return(!blue.Destroyed);
 }
        // Token: 0x060000E2 RID: 226 RVA: 0x000071D4 File Offset: 0x000053D4
        public static AcceptanceReport CanPlaceBlueprintAt(BuildableDef entDef, IntVec3 center, Rot4 rot, Map map, bool godMode = false, Thing thingToIgnore = null, Thing thing = null, ThingDef stuffDef = null)
        {
            CellRect cellRect = GenAdj.OccupiedRect(center, rot, entDef.Size);
            bool     flag     = stuffDef == null && thing != null;

            if (flag)
            {
                stuffDef = thing.Stuff;
            }
            foreach (IntVec3 c in cellRect)
            {
                bool flag2 = !c.InBounds(map);
                if (flag2)
                {
                    return(new AcceptanceReport("OutOfBounds".Translate()));
                }
                bool flag3 = c.InNoBuildEdgeArea(map) && !godMode;
                if (flag3)
                {
                    return("TooCloseToMapEdge".Translate());
                }
            }
            bool             flag4 = center.Fogged(map);
            AcceptanceReport result;

            if (flag4)
            {
                result = "CannotPlaceInUndiscovered".Translate();
            }
            else
            {
                List <Thing> thingList = center.GetThingList(map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    Thing thing2 = thingList[i];
                    bool  flag5  = thing2 != thingToIgnore && thing2.Position == center && thing2.Rotation == rot;
                    if (flag5)
                    {
                        bool flag6 = thing2.def == entDef;
                        if (flag6)
                        {
                            return(new AcceptanceReport("IdenticalThingExists".Translate()));
                        }
                        bool flag7 = thing2.def.entityDefToBuild == entDef;
                        if (flag7)
                        {
                            bool flag8 = thing2 is Blueprint;
                            if (flag8)
                            {
                                return(new AcceptanceReport("IdenticalBlueprintExists".Translate()));
                            }
                            return(new AcceptanceReport("IdenticalThingExists".Translate()));
                        }
                    }
                }
                ThingDef thingDef = entDef as ThingDef;
                bool     flag9    = thingDef != null && thingDef.hasInteractionCell;
                if (flag9)
                {
                    IntVec3 c2     = ThingUtility.InteractionCellWhenAt(thingDef, center, rot, map);
                    bool    flag10 = !c2.InBounds(map);
                    if (flag10)
                    {
                        return(new AcceptanceReport("InteractionSpotOutOfBounds".Translate()));
                    }
                    List <Thing> list = map.thingGrid.ThingsListAtFast(c2);
                    for (int j = 0; j < list.Count; j++)
                    {
                        bool flag11 = list[j] != thingToIgnore;
                        if (flag11)
                        {
                            bool flag12 = list[j].def.passability == Traversability.Impassable || list[j].def == thingDef;
                            if (flag12)
                            {
                                return(new AcceptanceReport("InteractionSpotBlocked".Translate(list[j].LabelNoCount, list[j]).CapitalizeFirst()));
                            }
                            BuildableDef entityDefToBuild = list[j].def.entityDefToBuild;
                            bool         flag13           = entityDefToBuild != null && (entityDefToBuild.passability == Traversability.Impassable || entityDefToBuild == thingDef);
                            if (flag13)
                            {
                                return(new AcceptanceReport("InteractionSpotWillBeBlocked".Translate(list[j].LabelNoCount, list[j]).CapitalizeFirst()));
                            }
                        }
                    }
                }
                foreach (IntVec3 c3 in GenAdj.CellsAdjacentCardinal(center, rot, entDef.Size))
                {
                    bool flag14 = c3.InBounds(map);
                    if (flag14)
                    {
                        thingList = c3.GetThingList(map);
                        for (int k = 0; k < thingList.Count; k++)
                        {
                            Thing thing3 = thingList[k];
                            bool  flag15 = thing3 != thingToIgnore;
                            if (flag15)
                            {
                                Blueprint blueprint = thing3 as Blueprint;
                                bool      flag16    = blueprint != null;
                                ThingDef  thingDef3;
                                if (flag16)
                                {
                                    ThingDef thingDef2 = blueprint.def.entityDefToBuild as ThingDef;
                                    bool     flag17    = thingDef2 == null;
                                    if (flag17)
                                    {
                                        goto IL_48F;
                                    }
                                    thingDef3 = thingDef2;
                                }
                                else
                                {
                                    thingDef3 = thing3.def;
                                }
                                bool flag18 = thingDef3.hasInteractionCell && (entDef.passability == Traversability.Impassable || entDef == thingDef3) && cellRect.Contains(ThingUtility.InteractionCellWhenAt(thingDef3, thing3.Position, thing3.Rotation, thing3.Map));
                                if (flag18)
                                {
                                    return(new AcceptanceReport("WouldBlockInteractionSpot".Translate(entDef.label, thingDef3.label).CapitalizeFirst()));
                                }
                            }
                            IL_48F :;
                        }
                    }
                }
                TerrainDef terrainDef = entDef as TerrainDef;
                bool       flag19     = terrainDef != null;
                if (flag19)
                {
                    bool flag20 = map.terrainGrid.TerrainAt(center) == terrainDef;
                    if (flag20)
                    {
                        return(new AcceptanceReport("TerrainIsAlready".Translate(terrainDef.label)));
                    }
                    bool flag21 = map.designationManager.DesignationAt(center, DesignationDefOf.SmoothFloor) != null;
                    if (flag21)
                    {
                        return(new AcceptanceReport("SpaceBeingSmoothed".Translate()));
                    }
                }
                bool flag22 = WPGenConstruct.CanBuildOnTerrain(entDef, center, map, rot, thingToIgnore, stuffDef);
                if (flag22)
                {
                    bool flag23 = !godMode;
                    if (flag23)
                    {
                        foreach (IntVec3 c4 in cellRect)
                        {
                            thingList = c4.GetThingList(map);
                            for (int l = 0; l < thingList.Count; l++)
                            {
                                Thing thing4 = thingList[l];
                                bool  flag24 = thing4 != thingToIgnore && !WPGenConstruct.CanPlaceBlueprintOver(entDef, thing4.def);
                                if (flag24)
                                {
                                    return(new AcceptanceReport("SpaceAlreadyOccupied".Translate()));
                                }
                            }
                        }
                    }
                    bool flag25 = entDef.PlaceWorkers != null;
                    if (flag25)
                    {
                        for (int m = 0; m < entDef.PlaceWorkers.Count; m++)
                        {
                            AcceptanceReport result2 = entDef.PlaceWorkers[m].AllowsPlacing(entDef, center, rot, map, thingToIgnore, thing);
                            bool             flag26  = !result2.Accepted;
                            if (flag26)
                            {
                                return(result2);
                            }
                        }
                    }
                    result = AcceptanceReport.WasAccepted;
                }
                else
                {
                    bool flag27 = entDef.GetTerrainAffordanceNeed(stuffDef) == null;
                    if (flag27)
                    {
                        result = new AcceptanceReport("TerrainCannotSupport".Translate(entDef).CapitalizeFirst());
                    }
                    else
                    {
                        bool flag28 = entDef.useStuffTerrainAffordance && stuffDef != null;
                        if (flag28)
                        {
                            result = new AcceptanceReport("TerrainCannotSupport_TerrainAffordanceFromStuff".Translate(entDef, entDef.GetTerrainAffordanceNeed(stuffDef), stuffDef).CapitalizeFirst());
                        }
                        else
                        {
                            result = new AcceptanceReport("TerrainCannotSupport_TerrainAffordance".Translate(entDef, entDef.GetTerrainAffordanceNeed(stuffDef)).CapitalizeFirst());
                        }
                    }
                }
            }
            return(result);
        }
 public static Thing MiniToInstallOrBuildingToReinstall(Blueprint b)
 {
     return((b as Blueprint_Install)?.MiniToInstallOrBuildingToReinstall);
 }
        public static AcceptanceReport CanPlaceBlueprintAt(BuildableDef entDef, IntVec3 center, Rot4 rot, Map map, bool godMode = false, Thing thingToIgnore = null, Thing thing = null, ThingDef stuffDef = null)
        {
            CellRect cellRect = GenAdj.OccupiedRect(center, rot, entDef.Size);

            if (stuffDef == null && thing != null)
            {
                stuffDef = thing.Stuff;
            }
            foreach (IntVec3 item in cellRect)
            {
                if (!item.InBounds(map))
                {
                    return(new AcceptanceReport("OutOfBounds".Translate()));
                }
                if (item.InNoBuildEdgeArea(map) && !godMode)
                {
                    return("TooCloseToMapEdge".Translate());
                }
            }
            if (center.Fogged(map))
            {
                return("CannotPlaceInUndiscovered".Translate());
            }
            List <Thing> thingList = center.GetThingList(map);

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

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

            if (terrainDef != null)
            {
                if (map.terrainGrid.TerrainAt(center) == terrainDef)
                {
                    return(new AcceptanceReport("TerrainIsAlready".Translate(terrainDef.label)));
                }
                if (map.designationManager.DesignationAt(center, DesignationDefOf.SmoothFloor) != null)
                {
                    return(new AcceptanceReport("SpaceBeingSmoothed".Translate()));
                }
            }
            if (!CanBuildOnTerrain(entDef, center, map, rot, thingToIgnore, stuffDef))
            {
                if (entDef.GetTerrainAffordanceNeed(stuffDef) != null)
                {
                    if (entDef.useStuffTerrainAffordance && stuffDef != null)
                    {
                        return(new AcceptanceReport("TerrainCannotSupport_TerrainAffordanceFromStuff".Translate(entDef, entDef.GetTerrainAffordanceNeed(stuffDef), stuffDef).CapitalizeFirst()));
                    }
                    return(new AcceptanceReport("TerrainCannotSupport_TerrainAffordance".Translate(entDef, entDef.GetTerrainAffordanceNeed(stuffDef)).CapitalizeFirst()));
                }
                return(new AcceptanceReport("TerrainCannotSupport".Translate(entDef).CapitalizeFirst()));
            }
            if (ModsConfig.RoyaltyActive)
            {
                List <Thing> list2 = map.listerThings.ThingsOfDef(ThingDefOf.MonumentMarker);
                for (int l = 0; l < list2.Count; l++)
                {
                    MonumentMarker monumentMarker = (MonumentMarker)list2[l];
                    if (!monumentMarker.complete && !monumentMarker.AllowsPlacingBlueprint(entDef, center, rot, stuffDef))
                    {
                        return(new AcceptanceReport("BlueprintWouldCollideWithMonument".Translate()));
                    }
                }
            }
            if (!godMode)
            {
                foreach (IntVec3 item3 in cellRect)
                {
                    thingList = item3.GetThingList(map);
                    for (int m = 0; m < thingList.Count; m++)
                    {
                        Thing thing4 = thingList[m];
                        if (thing4 != thingToIgnore && !CanPlaceBlueprintOver(entDef, thing4.def))
                        {
                            return(new AcceptanceReport("SpaceAlreadyOccupied".Translate()));
                        }
                    }
                }
            }
            if (entDef.PlaceWorkers != null)
            {
                for (int n = 0; n < entDef.PlaceWorkers.Count; n++)
                {
                    AcceptanceReport result = entDef.PlaceWorkers[n].AllowsPlacing(entDef, center, rot, map, thingToIgnore, thing);
                    if (!result.Accepted)
                    {
                        return(result);
                    }
                }
            }
            return(AcceptanceReport.WasAccepted);
        }