예제 #1
0
        public static MinifiedThing MakeMinified(this Thing thing)
        {
            if (!thing.def.Minifiable)
            {
                Log.Warning("Tried to minify " + thing + " which is not minifiable.");
                return(null);
            }
            if (thing.Spawned)
            {
                thing.DeSpawn();
            }
            if (thing.holdingOwner != null)
            {
                Log.Warning("Can't minify thing which is in a ThingOwner because we don't know how to handle it. Remove it from the container first. holder=" + thing.ParentHolder);
                return(null);
            }
            Blueprint_Install blueprint_Install = InstallBlueprintUtility.ExistingBlueprintFor(thing);
            MinifiedThing     minifiedThing     = (MinifiedThing)ThingMaker.MakeThing(thing.def.minifiedDef, null);

            minifiedThing.InnerThing = thing;
            if (blueprint_Install != null)
            {
                blueprint_Install.SetThingToInstallFromMinified(minifiedThing);
            }
            if (minifiedThing.InnerThing.stackCount > 1)
            {
                Log.Warning("Tried to minify " + thing.LabelCap + " with stack count " + minifiedThing.InnerThing.stackCount + ". Clamped stack count to 1.");
                minifiedThing.InnerThing.stackCount = 1;
            }
            return(minifiedThing);
        }
예제 #2
0
        public override void Destroy(DestroyMode mode = DestroyMode.Vanish)
        {
            bool spawned = base.Spawned;
            Map  map     = base.Map;

            base.Destroy(mode);
            if (InnerThing == null)
            {
                return;
            }
            InstallBlueprintUtility.CancelBlueprintsFor(this);
            if (spawned)
            {
                switch (mode)
                {
                case DestroyMode.Deconstruct:
                    SoundDefOf.Building_Deconstructed.PlayOneShot(new TargetInfo(base.Position, map));
                    GenLeaving.DoLeavingsFor(InnerThing, map, mode, this.OccupiedRect());
                    break;

                case DestroyMode.KillFinalize:
                    GenLeaving.DoLeavingsFor(InnerThing, map, mode, this.OccupiedRect());
                    break;
                }
            }
            if (InnerThing is MonumentMarker)
            {
                InnerThing.Destroy();
            }
        }
        public static void CancelBlueprintsFor(Thing th)
        {
            Blueprint_Install blueprint_Install = InstallBlueprintUtility.ExistingBlueprintFor(th);

            if (blueprint_Install != null)
            {
                blueprint_Install.Destroy(DestroyMode.Cancel);
            }
        }
        public override void DrawExtraSelectionOverlays()
        {
            base.DrawExtraSelectionOverlays();
            Blueprint_Install blueprint_Install = InstallBlueprintUtility.ExistingBlueprintFor(this);

            if (blueprint_Install != null)
            {
                GenDraw.DrawLineBetween(this.TrueCenter(), blueprint_Install.TrueCenter());
            }
        }
예제 #5
0
        public override void ProcessInput(Event ev)
        {
            Thing miniToInstallOrBuildingToReinstall = MiniToInstallOrBuildingToReinstall;

            if (miniToInstallOrBuildingToReinstall != null)
            {
                InstallBlueprintUtility.CancelBlueprintsFor(miniToInstallOrBuildingToReinstall);
                if (!((ThingDef)PlacingDef).rotatable)
                {
                    placingRot = Rot4.North;
                }
            }
            base.ProcessInput(ev);
        }
        public override void Destroy(DestroyMode mode = DestroyMode.Vanish)
        {
            bool spawned = base.Spawned;
            Map  map     = base.Map;

            base.Destroy(mode);
            if (this.InnerThing != null)
            {
                InstallBlueprintUtility.CancelBlueprintsFor(this);
                if (mode == DestroyMode.Deconstruct && spawned)
                {
                    SoundDef.Named("BuildingDeconstructed").PlayOneShot(new TargetInfo(base.Position, map, false));
                    GenLeaving.DoLeavingsFor(this.InnerThing, map, mode, this.OccupiedRect());
                }
            }
        }
예제 #7
0
        public static MinifiedThing MakeMinified(this Thing thing)
        {
            MinifiedThing result;

            if (!thing.def.Minifiable)
            {
                Log.Warning("Tried to minify " + thing + " which is not minifiable.", false);
                result = null;
            }
            else
            {
                if (thing.Spawned)
                {
                    thing.DeSpawn(DestroyMode.Vanish);
                }
                if (thing.holdingOwner != null)
                {
                    Log.Warning("Can't minify thing which is in a ThingOwner because we don't know how to handle it. Remove it from the container first. holder=" + thing.ParentHolder, false);
                    result = null;
                }
                else
                {
                    Blueprint_Install blueprint_Install = InstallBlueprintUtility.ExistingBlueprintFor(thing);
                    MinifiedThing     minifiedThing     = (MinifiedThing)ThingMaker.MakeThing(thing.def.minifiedDef, null);
                    minifiedThing.InnerThing = thing;
                    if (blueprint_Install != null)
                    {
                        blueprint_Install.SetThingToInstallFromMinified(minifiedThing);
                    }
                    if (minifiedThing.InnerThing.stackCount > 1)
                    {
                        Log.Warning(string.Concat(new object[]
                        {
                            "Tried to minify ",
                            thing.LabelCap,
                            " with stack count ",
                            minifiedThing.InnerThing.stackCount,
                            ". Clamped stack count to 1."
                        }), false);
                        minifiedThing.InnerThing.stackCount = 1;
                    }
                    result = minifiedThing;
                }
            }
            return(result);
        }
 public override void PreTraded(TradeAction action, Pawn playerNegotiator, ITrader trader)
 {
     base.PreTraded(action, playerNegotiator, trader);
     InstallBlueprintUtility.CancelBlueprintsFor(this);
 }