Example #1
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);
        }
        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);
                    }
                }
            }
        }
Example #3
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);
                    }
                }
            }
        }