コード例 #1
0
        public static ReplaceFrame PlaceReplaceFrame(Thing oldThing, ThingDef stuff)
        {
            ThingDef replaceFrameDef = ThingDefGenerator_ReplaceFrame.ReplaceFrameDefFor(oldThing.def);

            if (replaceFrameDef == null)
            {
                return(null);
            }

            if (oldThing.Position.GetFirstThing(oldThing.Map, replaceFrameDef) != null)
            {
                return(null);
            }

            ReplaceFrame replaceFrame = (ReplaceFrame)ThingMaker.MakeThing(replaceFrameDef, stuff);

            //QualityBuilder
            if (QBTypes.qbDesDef != null &&
                replaceFrame.def.HasComp(QBTypes.compQBType))
            {
                oldThing.Map.designationManager.AddDesignation(new Designation(replaceFrame, QBTypes.qbDesDef));
            }

            replaceFrame.SetFactionDirect(Faction.OfPlayer);
            replaceFrame.oldThing = oldThing;
            replaceFrame.oldStuff = oldThing.Stuff;
            GenSpawn.Spawn(replaceFrame, oldThing.Position, oldThing.Map, oldThing.Rotation);
            return(replaceFrame);
        }
コード例 #2
0
        public static ReplaceFrame PlaceReplaceFrame(Thing oldThing, ThingDef stuff)
        {
            ThingDef replaceFrameDef = ThingDefGenerator_ReplaceFrame.ReplaceFrameDefFor(oldThing.def);

            if (replaceFrameDef == null)
            {
                return(null);
            }

            if (oldThing.Position.GetFirstThing(oldThing.Map, replaceFrameDef) != null)
            {
                return(null);
            }

            ReplaceFrame replaceFrame = (ReplaceFrame)ThingMaker.MakeThing(replaceFrameDef, stuff);

            //QualityBuilder
            if (DefDatabase <DesignationDef> .GetNamed("SkilledBuilder", false) is DesignationDef d &&
                AccessTools.TypeByName("CompQualityBuilder") is Type qbType &&
                replaceFrame.def.HasComp(qbType))
            {
                oldThing.Map.designationManager.AddDesignation(new Designation(replaceFrame, d));
            }

            replaceFrame.SetFactionDirect(Faction.OfPlayer);
            replaceFrame.oldThing = oldThing;
            replaceFrame.oldStuff = oldThing.Stuff;
            GenSpawn.Spawn(replaceFrame, oldThing.Position, oldThing.Map, oldThing.Rotation);
            return(replaceFrame);
        }
コード例 #3
0
        public static void DoReplace(Thing thing, ThingDef stuffDef)
        {
            var pos = thing.Position;
            var rot = thing.Rotation;
            var map = thing.Map;

            //In case you're replacing with a stuff that needs a higher affordance that bridges can handle.
            PlaceBridges.EnsureBridge.PlaceBridgeIfNeeded(thing.def, pos, map, rot, Faction.OfPlayer, stuffDef);

            //CanReplaceStuffFor has verified this is different stuff
            //so the task here is: place new replacements, kill old replacement
            //Too finicky to change stuff of current replacement - canceling jobs and such.
            if (thing is Blueprint_Build oldBP)
            {
                oldBP.Destroy(DestroyMode.Cancel);
                //Destroy before Place beacause GenSpawn.Spawn will wipe it

                GenConstruct.PlaceBlueprintForBuild_NewTemp(oldBP.def.entityDefToBuild, pos, map, rot, Faction.OfPlayer, stuffDef);
            }
            else if (thing is ReplaceFrame oldRF)
            {
                if (DebugSettings.godMode)
                {
                    ReplaceFrame.FinalizeReplace(thing, stuffDef);
                }
                if (oldRF.oldStuff != stuffDef)
                {
                    //replacement frame should keep deconstruction work mount
                    ReplaceFrame newFrame = GenReplace.PlaceReplaceFrame(oldRF.oldThing, stuffDef);
                    newFrame.workDone = Mathf.Min(oldRF.workDone, oldRF.WorkToDeconstruct);
                }
                //else, if same stuff as old stuff, we just chose replace with original stuff, so we're already done - just destroy the frame.
                //upgrade frames/blueprints

                oldRF.Destroy(DestroyMode.Cancel);
            }
            else if (thing is Frame oldFrame)
            {
                oldFrame.Destroy(DestroyMode.Cancel);

                GenConstruct.PlaceBlueprintForBuild_NewTemp(oldFrame.def.entityDefToBuild, pos, map, rot, Faction.OfPlayer, stuffDef);
            }
            else if (DebugSettings.godMode)
            {
                ReplaceFrame.FinalizeReplace(thing, stuffDef);
            }
            else
            {
                //Oh of course the standard case is, just place a replace frame! I almost forgot about that.
                GenReplace.PlaceReplaceFrame(thing, stuffDef);
            }

            FleckMaker.ThrowMetaPuffs(GenAdj.OccupiedRect(pos, rot, thing.def.size), map);
        }
コード例 #4
0
        public override void DesignateSingleCell(IntVec3 cell)
        {
            List <Thing> things = cell.GetThingList(Map).FindAll(t => CanReplaceStuffFor(stuffDef, t));

            for (int i = 0; i < things.Count; i++)
            {
                Thing thing = things[i];
                thing.SetFaction(Faction.OfPlayer);
                if (DebugSettings.godMode)
                {
                    ReplaceFrame.FinalizeReplace(thing, stuffDef);
                }
                else
                {
                    Log.Message($"PlaceReplaceFrame on {thing} with {stuffDef}");
                    if (thing is Blueprint_Build blueprint)
                    {
                        blueprint.stuffToUse = stuffDef;
                    }
                    else if (thing is ReplaceFrame replaceFrame)
                    {
                        if (replaceFrame.oldStuff == stuffDef)
                        {
                            replaceFrame.Destroy(DestroyMode.Cancel);
                        }
                        else
                        {
                            replaceFrame.ChangeStuff(stuffDef);
                        }
                    }
                    else if (thing is Frame frame)
                    {
                        GenConstruct.PlaceBlueprintForBuild(frame.def.entityDefToBuild, frame.Position, frame.Map, frame.Rotation, frame.Faction, stuffDef);
                    }
                    else
                    {
                        GenReplace.PlaceReplaceFrame(thing, stuffDef);
                    }
                }
            }
        }
コード例 #5
0
        public override void DesignateSingleCell(IntVec3 cell)
        {
            List <Thing> things = cell.GetThingList(Map).FindAll(t => CanReplaceStuffFor(stuffDef, t));

            for (int i = 0; i < things.Count; i++)
            {
                Thing thing = things[i];
                thing.SetFaction(Faction.OfPlayer);

                //In case you're replacing with a stuff that needs a higher affordance that bridges can handle.
                PlaceBridges.EnsureBridge.PlaceBridgeIfNeeded(thing.def, thing.Position, Map, thing.Rotation, Faction.OfPlayer, stuffDef);

                if (DebugSettings.godMode)
                {
                    ReplaceFrame.FinalizeReplace(thing, stuffDef);
                }
                else
                {
                    Log.Message($"PlaceReplaceFrame on {thing} with {stuffDef}");
                    if (thing is Blueprint_Build blueprint)
                    {
                        blueprint.stuffToUse = stuffDef;
                    }
                    else if (thing is ReplaceFrame replaceFrame)
                    {
                        if (replaceFrame.oldStuff == stuffDef)
                        {
                            replaceFrame.Destroy(DestroyMode.Cancel);
                        }
                        else
                        {
                            replaceFrame.ChangeStuff(stuffDef);

                            //Interrupt any workers - they don't have the required new stuff
                            if (replaceFrame.Map.mapPawns.FreeColonists.First() is Pawn sampleColonist &&
                                replaceFrame.Map.reservationManager.FirstRespectedReserver(replaceFrame, sampleColonist) is Pawn worker)
                            {
                                if (worker.CurJob.def == JobDefOf.FinishFrame &&
                                    worker.CurJob.targetA == replaceFrame)
                                {
                                    worker.jobs.EndCurrentJob(JobCondition.InterruptForced);
                                }

                                for (int jobI = worker.jobs.jobQueue.Count - 1; jobI >= 0; jobI--)
                                {
                                    Job qJob = worker.jobs.jobQueue[jobI].job;
                                    if (qJob.def == JobDefOf.FinishFrame &&
                                        qJob.targetA == replaceFrame)
                                    {
                                        worker.jobs.EndCurrentOrQueuedJob(qJob, JobCondition.InterruptForced);
                                    }
                                }
                            }
                        }
                    }
                    else if (thing is Frame frame)
                    {
                        GenConstruct.PlaceBlueprintForBuild(frame.def.entityDefToBuild, frame.Position, frame.Map, frame.Rotation, frame.Faction, stuffDef);
                    }
                    else
                    {
                        GenReplace.PlaceReplaceFrame(thing, stuffDef);
                    }
                }
            }
        }