public override void PostPlace(Map map, BuildableDef def, IntVec3 loc, Rot4 rot)
        {
            base.PostPlace(map, def, loc, rot);
            var radialCells = GenRadial.RadialCellsAround(loc, def.GetModExtension <ColumnExtension>()?.radius ?? 0, false);

            if (radialCells.Any(c => c.InBounds(map) && c.GetThingList(map).Any(t => t is Building && t.Faction == Faction.OfPlayer)))
            {
                Messages.Message("RWC_TooClose".Translate(), MessageTypeDefOf.CautionInput, false);
            }
        }
示例#2
0
        private float GetBaseEstimatedLifespan(SurvivalTool tool, BuildableDef def)
        {
            SurvivalToolProperties props = def.GetModExtension <SurvivalToolProperties>() ?? SurvivalToolProperties.defaultValues;

            if (!((ThingDef)def).useHitPoints)
            {
                return(float.PositiveInfinity);
            }

            // For def
            if (tool == null)
            {
                return(GenDate.TicksToDays(Mathf.RoundToInt((BaseWearInterval * def.GetStatValueAbstract(StatDefOf.MaxHitPoints)) / props.toolWearFactor)));
            }

            // For thing
            StuffPropsTool stuffProps = tool.Stuff?.GetModExtension <StuffPropsTool>() ?? StuffPropsTool.defaultValues;
            float          wearFactor = tool.def.GetModExtension <SurvivalToolProperties>().toolWearFactor *(stuffProps.wearFactorMultiplier);

            return(GenDate.TicksToDays(Mathf.RoundToInt((BaseWearInterval * tool.MaxHitPoints) / wearFactor)));
        }
        public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc,
                                                       Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null)
        {
            // Notes to self: checkingDef is the def player is trying to place
            // thingToIgnore is (obviously) a Thing that should not be considered for the placing.
            //   as an example, rotating an item in place - we want to ignore the item itself!
            // thing is if it's an actual Thing that's being moved?

            var def = checkingDef as ThingDef;

            if (def == null)
            {
                return(AcceptanceReport.WasAccepted);             // No idea WTF it is??
            }
            var defModExtConveyor = checkingDef.GetModExtension <ModExtension_Conveyor>();

            // underground:
            if (typeof(Building_BeltConveyorUGConnector).IsAssignableFrom(def.thingClass) ||
                defModExtConveyor?.underground == true)
            {
                // Cannot place these over (other) underground or connectors
                foreach (var t in map.thingGrid.ThingsListAt(loc))
                {
                    if (t == thingToIgnore || t == thing)
                    {
                        continue;
                    }
                    if (t is Building_BeltConveyorUGConnector ||
                        (t as Building_BeltConveyor)?.IsUnderground == true)
                    {
                        return(new AcceptanceReport("PRFBlockedBy".Translate(t.Label)));
                    }
                }
            }

            return(AcceptanceReport.WasAccepted);
        }
示例#4
0
 public static bool IsSurvivalTool(this BuildableDef def, out SurvivalToolProperties toolProps)
 {
     toolProps = def.GetModExtension <SurvivalToolProperties>();
     return(def.IsSurvivalTool());
 }
        private static bool ShouldWipe(BuildableDef newEntDef, BuildableDef oldEntDef, IntVec3 loc, Map map)
        {
            if (map == null || loc == null || !loc.IsValid)
            {
                var buildingExtensionA = newEntDef?.GetModExtension <BuildingExtension>();
                var buildingExtensionB = oldEntDef?.GetModExtension <BuildingExtension>();
                if (buildingExtensionB == null && buildingExtensionA == null)
                {
                    //Log.Message("Both null");
                    return(true);
                }

                //Log.Message("A: " + newEntDef.label);
                //Log.Message("B: " + oldEntDef.label);
                if (buildingExtensionA != null && buildingExtensionB == null &&
                    buildingExtensionA.wipeCategories?.Count > 0)
                {
                    //Log.Message("B null");

                    return(false);
                }

                if (buildingExtensionB != null && buildingExtensionA == null &&
                    buildingExtensionB.wipeCategories?.Count > 0)
                {
                    //Log.Message("A null");

                    return(false);
                }

                if (buildingExtensionA != null && buildingExtensionB != null &&
                    buildingExtensionA.wipeCategories?.Count > 0 &&
                    buildingExtensionB.wipeCategories?.Count > 0)
                {
                    var hashes = new HashSet <string>();
                    foreach (var str in buildingExtensionA.wipeCategories)
                    {
                        hashes.Add(str);
                    }
                    foreach (var strB in buildingExtensionB.wipeCategories)
                    {
                        if (!hashes.Contains(strB))
                        {
                            continue;
                        }
                        //Log.Message("ShouldWipe");
                        return(true);
                    }
                }

                return(true);
            }

            var locThings = loc.GetThingList(map);

            for (var index = 0; index < locThings.Count; index++)
            {
                var thing = locThings[index];
                if (thing.def is ThingDef thingDef &&
                    ShouldWipe(newEntDef, GenConstruct.BuiltDefOf(thingDef), IntVec3.Invalid, null))
                {
                    return(true);
                }
            }

            return(true);
        }
示例#6
0
        public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc,
                                                       Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null)
        {
            // Notes to self: checkingDef is the def player is trying to place
            // thingToIgnore is (obviously) a Thing that should not be considered for the placing.
            //   as an example, rotating an item in place - we want to ignore the item itself!
            // thing is if it's an actual Thing that's being moved?

            var def = checkingDef as ThingDef;

            if (def == null)
            {
                return(AcceptanceReport.WasAccepted);             // probably terrain, not our problem
            }
            var defModExtConveyor = checkingDef.GetModExtension <ModExtension_Conveyor>();

            // underground:
            if (typeof(Building_BeltConveyorUGConnector).IsAssignableFrom(def.thingClass) ||
                defModExtConveyor?.underground == true)
            {
                // Cannot place these over (other) underground or connectors
                foreach (var t in map.thingGrid.ThingsListAt(loc))
                {
                    if (t == thingToIgnore || t == thing)
                    {
                        continue;
                    }
                    if (t is Building_BeltConveyorUGConnector || // other UGConnectors
                        (t as Building_BeltConveyor)?.IsUnderground == true    // UG stuff
                        // Blueprints:
                        || (t is Blueprint blue && blue.def.entityDefToBuild is ThingDef td &&
                            (typeof(Building_BeltConveyorUGConnector).IsAssignableFrom(td.thingClass) || // other UG
                                                                                                         // and other UG stuff:
                             td.modExtensions?.Any(dme => dme is ModExtension_Conveyor mec && mec.underground) == true)))
                    {
                        return(new AcceptanceReport("PRFBlockedBy".Translate(t.Label)));
                    }
                }
            }
            // in walls
            if (checkingDef.placeWorkers?.Contains(typeof(PlaceWorker_WallEmbedded)) == true)
            {
                foreach (var t in map.thingGrid.ThingsListAt(loc))
                {
                    if (t == thingToIgnore || t == thing)
                    {
                        continue;
                    }
                    if (t is IBeltConveyorLinkable blet && blet is Thing bla &&
                        bla.def.placeWorkers?.Contains(typeof(PlaceWorker_WallEmbedded)) == true)
                    {
                        return(new AcceptanceReport("PRFBlockedBy".Translate(t.Label)));
                    }
                    if (t is Blueprint blue && blue.def.entityDefToBuild is ThingDef td)
                    {
                        if (typeof(Building_BeltConveyor).IsAssignableFrom(td.thingClass) &&
                            td.placeWorkers?.Contains(typeof(PlaceWorker_WallEmbedded)) == true)
                        {
                            return(new AcceptanceReport("PRFBlockedBy".Translate(t.Label)));
                        }
                    }
                }
            }
            return(AcceptanceReport.WasAccepted);
        }