示例#1
0
        //public static Blueprint_Build PlaceBlueprintForBuild(BuildableDef sourceDef, IntVec3 center, Map map, Rot4 rotation, Faction faction, ThingDef stuff)
        public static void Prefix(ref Blueprint_Build __result, BuildableDef sourceDef, IntVec3 center, Map map, Rot4 rotation, Faction faction, ThingDef stuff)
        {
            if (faction != Faction.OfPlayer)
            {
                return;
            }

            foreach (IntVec3 cell in GenAdj.CellsOccupiedBy(center, rotation, sourceDef.Size))
            {
                if (map.designationManager.DesignationAt(cell, DesignationDefOf.Mine) != null)
                {
                    continue;
                }

                if (sourceDef is ThingDef thingDef)
                {
                    foreach (Thing mineThing in map.thingGrid.ThingsAt(cell).Where(t => t.IsMineableRock()))
                    {
                        if (!DontMineSmoothingRock.ToBeSmoothed(mineThing, thingDef))
                        {
                            map.designationManager.AddDesignation(new Designation(mineThing, DesignationDefOf.Mine));

                            if (mineThing.def.building?.mineableYieldWasteable ?? false)
                            {
                                TutorUtility.DoModalDialogIfNotKnown(ConceptDefOf.BuildersTryMine);
                            }
                        }
                    }
                }
            }
        }
示例#2
0
 public override void Notify_ConstructionFailed(Pawn pawn, Frame frame, Blueprint_Build newBlueprint)
 {
     if (frame.Faction == this.lord.faction && newBlueprint != null)
     {
         ((LordToilData_SetupCarnival)this.data).blueprints.Add(newBlueprint);
     }
 }
示例#3
0
 public override void Notify_ConstructionFailed(Pawn pawn, Frame frame, Blueprint_Build newBlueprint)
 {
     base.Notify_ConstructionFailed(pawn, frame, newBlueprint);
     if (frame.Faction == lord.faction && newBlueprint != null)
     {
         Data.blueprints.Add(newBlueprint);
     }
 }
 public static void Postfix(Blueprint_Build __result)
 {
     if (!DesignatorShapes.ShowControls)
     {
         return;
     }
     HistoryManager.AddEntry(__result);
 }
 static void Postfix(Blueprint_Build __instance, Thing __result)
 {
     if (transferring && Find.Selector.SelectedObjects.Contains(__instance) && __result != null)
     {
         Find.Selector.SelectedObjects.Add(__result);
         SelectionDrawer.Notify_Selected(__result);
         SelectorChangeNotifiers.SelectionChangeNotifierData.NotifyChange();
     }
 }
        public static Blueprint_Build PlaceBlueprintForBuild(BuildableDef sourceDef, IntVec3 center, Map map, Rot4 rotation, Faction faction, ThingDef stuff)
        {
            Blueprint_Build blueprint_Build = (Blueprint_Build)ThingMaker.MakeThing(sourceDef.blueprintDef, null);

            blueprint_Build.SetFactionDirect(faction);
            blueprint_Build.stuffToUse = stuff;
            mineOut(map, center);
            GenSpawn.Spawn(blueprint_Build, center, map, rotation);
            return(blueprint_Build);
        }
示例#7
0
 static void Postfix(Thing __result, Blueprint_Build __instance)
 {
     if (Find.Selector.NumSelected > 1 && Find.Selector.SelectedObjects.Contains(__instance))
     {
         SelectResult(__result);
     }
     else if (Find.CurrentMap.designationManager.SpawnedDesignationsOfDef(BlueprintReportUtility.tabulateDesignationDef).Any())
     {
         DesignateResult(__result);
     }
 }
 public static void Prefix(Blueprint_Build __instance, DestroyMode mode = DestroyMode.Vanish)
 {
     if (mode == DestroyMode.Cancel || mode == DestroyMode.KillFinalize || mode == DestroyMode.Deconstruct)
     {
         ThingDef def = __instance.def.entityDefToBuild as ThingDef;
         if (def != null && typeof(Building_Storage).IsAssignableFrom(def.thingClass))
         {
             __instance.Map.GetComponent <StorageSettingManager>().Remove(__instance.Position);
         }
     }
 }
示例#9
0
 static void Postfix(JobDriver_PlantHarvest __instance, Toil __result)
 {
     __result.initAction = delegate
     {
         Thing thing = __result.actor.jobs.curJob.GetTarget(TargetIndex.A).Thing;
         Map   map   = __result.actor.Map;
         map.designationManager.RemoveAllDesignationsOn(thing, false);
         if (!tw_YAAM.ConvertSoilAfterHarvest)
         {
             return;
         }
         IntVec3    pos        = thing.Position;
         TerrainDef terrainDef = map.terrainGrid.TerrainAt(pos);
         if (!terrainDef.defName.StartsWith("twSoil"))
         {
             return;
         }
         map.terrainGrid.SetTerrain(__result.actor.jobs.curJob.targetA.Cell, RimWorld.TerrainDefOf.Soil);
         if (map.terrainGrid.TerrainAt(pos).defName != RimWorld.TerrainDefOf.Soil.defName)
         {
             Verse.Log.Warning("tw_YAMM.ConvertSoilAfterHarvest failed at " + pos.ToString());
         }
         List <Zone> zonesList = map.zoneManager.AllZones;
         for (int j = 0; j < zonesList.Count; j++)
         {
             Zone_Growing growingZone = zonesList[j] as Zone_Growing;
             if (growingZone == null)
             {
                 continue;
             }
             if (growingZone.cells.Count == 0)
             {
                 continue;
             }
             if (!growingZone.Cells.Contains(pos))
             {
                 continue;
             }
             if (tw_YAAM.WorldObject.GrowingZonesPlaceBlueprint.Contains(growingZone.label))
             {
                 Blueprint_Build blueprint_Build = GenConstruct.PlaceBlueprintForBuild(terrainDef, pos, map, Rot4.North, Faction.OfPlayer, null);
                 if (blueprint_Build == null)
                 {
                     Verse.Log.Warning("tw_YAMM.PlaceBlueprint failed for " + terrainDef.defName + " in " + growingZone.label);
                 }
                 return;
             }
         }
     };
 }
示例#10
0
            public static void Prefix(Blueprint_Build __instance, DestroyMode mode = DestroyMode.Vanish)
            {
#if DEBUG
                Log.Message(Debug.GetMethodName(2) + "@" + MethodBase.GetCurrentMethod().Name + ": mode=" + mode.ToString());
#endif
                if (mode == DestroyMode.Cancel || mode == DestroyMode.KillFinalize || mode == DestroyMode.Deconstruct)
                {
                    ThingDef def = __instance.def.entityDefToBuild as ThingDef;
                    if (def != null && typeof(Building_Storage).IsAssignableFrom(def.thingClass))
                    {
                        __instance.Map.GetComponent <StorageSettingManager>().Remove(__instance.Position);
                    }
                }
            }
        //public static Blueprint_Build PlaceBlueprintForBuild(BuildableDef sourceDef, IntVec3 center, Map map, Rot4 rotation, Faction faction, ThingDef stuff)
        public static bool Prefix(ref Blueprint_Build __result, BuildableDef sourceDef, IntVec3 center, Map map, Rot4 rotation, Faction faction, ThingDef stuff)
        {
            if (faction != Faction.OfPlayer)
            {
                return(true);
            }

            //Fix for door rotation
            if (sourceDef is ThingDef thingDef && thingDef.thingClass == typeof(Building_Door))
            {
                rotation = Building_Door.DoorRotationAt(center, map);
            }

            Func <Thing, bool> posCheck = t => t.Position == center && t.Rotation == rotation;

            Func <Thing, bool> newReplaceCheck = t => posCheck(t) &&
                                                 t.def == sourceDef && t.Stuff != stuff;
            Func <Thing, bool> changeFrameStuffCheck = t => posCheck(t) &&
                                                       t is Frame f && f.UIStuff() != stuff && f.def.entityDefToBuild == sourceDef;
            Func <Thing, bool> changeReplaceStuffCheck = t => posCheck(t) &&
                                                         t is ReplaceFrame rf && rf.UIStuff() != stuff && rf.def.entityDefToBuild == sourceDef;

            List <Thing> thingsHere = center.GetThingList(map);

            if (thingsHere.FirstOrDefault(changeReplaceStuffCheck) is ReplaceFrame oldReplaceFrame)
            {
                if (oldReplaceFrame.oldStuff == stuff)
                {
                    oldReplaceFrame.Destroy(DestroyMode.Cancel);
                }
                else
                {
                    oldReplaceFrame.ChangeStuff(stuff);
                }
                __result = null;
                return(false);
            }
            else if (thingsHere.FirstOrDefault(changeFrameStuffCheck) is Thing oldFrame)
            {
                oldFrame.Destroy(DestroyMode.Cancel);
                return(true);
            }
            else if (thingsHere.FirstOrDefault(newReplaceCheck) is Thing oldThing)
            {
                GenReplace.PlaceReplaceFrame(oldThing, stuff);
                __result = null;
                return(false);
            }
            return(true);
        }
示例#12
0
        public ConstructionStatus TargetConstructionStatus(Map map)
        {
            if (BuildableDef == null || target == null || target.HasThing || !target.IsValid)
            {
                return(ConstructionStatus.Invalid);
            }

            if (target.Cell.GetTerrain(map) == blueprintTerrainDef)
            {
                return(ConstructionStatus.Complete);
            }

            foreach (Thing thing in target.Cell.GetThingList(map))
            {
                Blueprint_Build blueprintBuild = thing as Blueprint_Build;
                Frame           frame          = thing as Frame;

                if (blueprintBuild != null && blueprintBuild.stuffToUse == blueprintStuff && thing.def.entityDefToBuild == BuildableDef)
                {
                    return(ConstructionStatus.InProgress);
                }

                if (frame != null && thing.Stuff == blueprintStuff && thing.def.entityDefToBuild == BuildableDef)
                {
                    return(ConstructionStatus.InProgress);
                }

                if (thing.Stuff == blueprintStuff && thing.def == blueprintThingDef && blueprintBuild == null && frame == null)
                {
                    return(ConstructionStatus.Complete);
                }
            }

            if (blueprintTerrainDef != null && !GenConstruct.CanPlaceBlueprintAt(blueprintTerrainDef, target.Cell, blueprintRotation, map, false, null, null, blueprintStuff).Accepted)
            {
                return(ConstructionStatus.Blocked);
            }

            if (blueprintThingDef != null && !GenConstruct.CanPlaceBlueprintAt(blueprintThingDef, target.Cell, blueprintRotation, map, false, null, null, blueprintStuff).Accepted)
            {
                return(ConstructionStatus.Blocked);
            }

            return(ConstructionStatus.None);
        }
        protected override int ProcessCell(IntVec3 c)
        {
            var hitCount   = 0;
            var cellThings = Find.VisibleMap.thingGrid.ThingsListAtFast(c);

            for (int i = 0; i < cellThings.Count; i++)
            {
                var thing = cellThings[i];
                if (thing.def.selectable && (thing.Faction == Faction.OfPlayer) && _newStuff != null)
                {
                    if (CanUseStuff(_newStuff, thing.def))
                    {
                        if (thing.def.IsBlueprint)
                        {
                            Blueprint_Build replaceBluePrint = (Blueprint_Build)ThingMaker.MakeThing(ThingDef.Named(thing.def.defName));
                            replaceBluePrint.SetFactionDirect(Faction.OfPlayer);
                            replaceBluePrint.stuffToUse = _newStuff;
                            GenSpawn.Spawn(replaceBluePrint, thing.Position, thing.Map, thing.Rotation);
                            thing.Destroy(DestroyMode.Cancel);
                        }
                        else if (thing.def.isFrame)
                        {
                            Frame replaceFrame = (Frame)ThingMaker.MakeThing(ThingDef.Named(thing.def.defName), _newStuff);
                            replaceFrame.SetFactionDirect(Faction.OfPlayer);
                            IntVec3 pos = thing.Position;
                            Map     map = thing.Map;
                            Rot4    rot = thing.Rotation;
                            //Destroys Frame's inner resourceContainer to reclaim resources
                            //Needs to be done before spawning new frame at loc (else resourceContainer goes MIA)
                            thing.Destroy(DestroyMode.Cancel);
                            GenSpawn.Spawn(replaceFrame, pos, map, rot);
                        }
                        hitCount++;
                    }
                }
            }
            return(hitCount);
        }
示例#14
0
        public Terrain_Action(Zone_Growing growingZone, TerrainDef terrainDef)
        {
            defaultLabel = terrainDef.label;
            defaultDesc  = string.Format("twYAAM_Gizmo_Description".Translate(), defaultLabel);
            icon         = ContentFinder <Texture2D> .Get(terrainDef.texturePath + "UI");

            action = delegate
            {
                Map map = growingZone.Map;
                foreach (IntVec3 cell in growingZone.Cells)
                {
                    if (map.terrainGrid.TerrainAt(cell).fertility >= terrainDef.fertility)
                    {
                        continue;
                    }
                    Blueprint_Build blueprint_Build = GenConstruct.PlaceBlueprintForBuild(terrainDef, cell, map, Rot4.North, Faction.OfPlayer, null);
                    if (blueprint_Build == null)
                    {
                        Verse.Log.Warning("tw_YAMM.Terrain_Action failed for " + terrainDef.defName + " in " + growingZone.label);
                    }
                }
            };
        }
示例#15
0
 public void Notify_ConstructionFailed(Pawn pawn, Frame frame, Blueprint_Build newBlueprint)
 {
     this.curLordToil.Notify_ConstructionFailed(pawn, frame, newBlueprint);
 }
 public static int GetWorkAmount(this Blueprint_Build blueprint)
 {
     return(Mathf.CeilToInt(blueprint.def.entityDefToBuild.GetStatValueAbstract(StatDefOf.WorkToBuild, blueprint.stuffToUse) / 60f));
 }
 public bool BlueprintBuildIsTracked(Blueprint_Build blueprint) => trackedConstructibles.Contains(blueprint);
示例#18
0
        static bool Prefix(BuildableDef sourceDef, ref IntVec3 center, ref Map map, ref Rot4 rotation, ref Faction faction, ref ThingDef stuff, Precept_ThingStyle styleSource, ThingStyleDef styleDef, ref Blueprint_Build __result)
        {
            if (faction?.IsPlayer != true)
            {
                return(true);
            }
            var toInstall = GetClosestCandidate(sourceDef, center, map, faction, stuff);

            if (toInstall != null)
            {
                GenConstruct.PlaceBlueprintForInstall(toInstall, center, map, rotation, faction);

                // Rimworld 1.3 uses the result to set faction style for new buildings, but the style should already be set since it's an existing building.
                // Might miss style update if the player uninstalls unclaimed buildings, we will have to see when we can test with Ideology
                __result = CreateFakeBlueprintBuild(sourceDef, faction, stuff);
                return(false);
            }
            return(true);
        }
 public virtual void Notify_ConstructionFailed(Pawn pawn, Frame frame, Blueprint_Build newBlueprint)
 {
 }
        public void AddJobTarget(SavedTargetInfo target, bool firstTarget = false)
        {
            if (jobTargets.Contains(target))
            {
                return;
            }

            if (target.HasThing && savedJob.bill != null)
            {
                MeeseeksBillStorage billStorage = Current.Game.World.GetComponent <MeeseeksBillStorage>();

                if (firstTarget)
                {
                    billStorage.SaveBill(savedJob.bill);
                    savedJob.bill = billStorage.GetDuplicateBillFromOriginal(savedJob.bill);
                    savedJob.bill.billStack.billGiver = target.Thing as IBillGiver;
                }

                WorkGiver_Scanner workGiverScanner = savedJob.workGiverDef.Worker as WorkGiver_Scanner;
                if (workGiverScanner != null)
                {
                    Job job = workGiverScanner.JobOnThing(Meeseeks, target.Thing, true);
                    if (job != null && job.bill != null)
                    {
                        billStorage.SaveBill(job.bill);
                        target.bill = billStorage.GetDuplicateBillFromOriginal(job.bill);
                        target.bill.billStack.billGiver = target.Thing as IBillGiver;
                    }
                }
            }
            else if (target.HasThing && savedJob.IsConstruction)
            {
                ThingDef   thingDefToBuild   = null;
                TerrainDef terrainDefToBuild = null;
                ThingDef   stuffDefToUse     = null;

                Blueprint_Build blueprint = target.Thing as Blueprint_Build;
                Frame           frame     = target.Thing as Frame;

                if (blueprint != null)
                {
                    thingDefToBuild   = blueprint.def.entityDefToBuild as ThingDef;
                    terrainDefToBuild = blueprint.def.entityDefToBuild as TerrainDef;
                    stuffDefToUse     = blueprint.stuffToUse;
                }
                else if (frame != null)
                {
                    thingDefToBuild   = frame.def.entityDefToBuild as ThingDef;
                    terrainDefToBuild = frame.def.entityDefToBuild as TerrainDef;
                    stuffDefToUse     = frame.Stuff;
                }

                if (thingDefToBuild != null)
                {
                    target.blueprintThingDef = thingDefToBuild;
                }
                else if (terrainDefToBuild != null)
                {
                    target.blueprintTerrainDef = terrainDefToBuild;
                }

                target.blueprintStuff    = stuffDefToUse;
                target.blueprintRotation = target.Thing.Rotation;

                // Redirect job to the cell so that we can continue various construction phases and replace blueprint if needed
                target.target = target.Cell;
            }
            else if (target.HasThing && savedJob.IsTraining)
            {
                target.trainable = (target.Thing as Pawn).training.NextTrainableToTrain();
            }

            jobTargets.Add(target);
        }