private Command_Action GetPlaceBlueprintsCommand(SketchBuildable buildable)
 {
     return(new Command_Action
     {
         defaultLabel = "CommandPlaceBlueprintsSpecific".Translate(buildable.Label).CapitalizeFirst(),
         defaultDesc = "CommandPlaceBlueprintsSpecificDesc".Translate(buildable.Label).CapitalizeFirst(),
         icon = PlaceBlueprintsCommandTex,
         order = 20f,
         action = delegate
         {
             List <ThingDef> list = AllowedStuffsFor(buildable);
             if (!list.Any())
             {
                 PlaceBlueprintsSimilarTo(buildable, null);
                 SoundDefOf.Click.PlayOneShotOnCamera();
             }
             else if (list.Count() == 1)
             {
                 PlaceBlueprintsSimilarTo(buildable, list.First());
                 SoundDefOf.Click.PlayOneShotOnCamera();
             }
             else
             {
                 ListFloatMenuOptions(list, delegate(ThingDef stuff)
                 {
                     PlaceBlueprintsSimilarTo(buildable, stuff);
                 });
             }
         }
     });
 }
Exemple #2
0
 private void PlaceAllBlueprints(ThingDef preferredStuffIfNone)
 {
     foreach (SketchEntity entity in sketch.Entities)
     {
         SketchBuildable sketchBuildable = entity as SketchBuildable;
         if (sketchBuildable != null && !entity.IsSameSpawnedOrBlueprintOrFrame(entity.pos + base.Position, base.Map) && !entity.IsSpawningBlocked(entity.pos + base.Position, base.Map) && BuildCopyCommandUtility.FindAllowedDesignator(sketchBuildable.Buildable) != null)
         {
             SketchThing   sketchThing;
             SketchTerrain sketchTerrain;
             if ((sketchThing = (entity as SketchThing)) != null && sketchThing.def.MadeFromStuff && sketchThing.stuff == null && preferredStuffIfNone != null && preferredStuffIfNone.stuffProps.CanMake(sketchThing.def))
             {
                 sketchThing.stuff = preferredStuffIfNone;
                 entity.Spawn(entity.pos + base.Position, base.Map, Faction.OfPlayer, Sketch.SpawnMode.Blueprint);
                 sketchThing.stuff = null;
             }
             else if ((sketchTerrain = (entity as SketchTerrain)) != null && sketchTerrain.stuffForComparingSimilar == null && preferredStuffIfNone != null)
             {
                 sketchTerrain.stuffForComparingSimilar = preferredStuffIfNone;
                 entity.Spawn(entity.pos + base.Position, base.Map, Faction.OfPlayer, Sketch.SpawnMode.Blueprint);
                 sketchTerrain.stuffForComparingSimilar = null;
             }
             else
             {
                 entity.Spawn(entity.pos + base.Position, base.Map, Faction.OfPlayer, Sketch.SpawnMode.Blueprint);
             }
         }
     }
 }
Exemple #3
0
        private void AddToCache(SketchEntity entity)
        {
            occupiedRectDirty = true;
            SketchBuildable sketchBuildable = entity as SketchBuildable;

            if (sketchBuildable != null)
            {
                cachedBuildables.Add(sketchBuildable);
            }
            SketchThing sketchThing = entity as SketchThing;

            if (sketchThing != null)
            {
                if (sketchThing.def.building != null && sketchThing.def.building.isEdifice)
                {
                    foreach (IntVec3 item in sketchThing.OccupiedRect)
                    {
                        edificeAt[item] = sketchThing;
                    }
                }
                foreach (IntVec3 item2 in sketchThing.OccupiedRect)
                {
                    SketchThing value2;
                    if (thingsAt_multiple.TryGetValue(item2, out List <SketchThing> value))
                    {
                        value.Add(sketchThing);
                    }
                    else if (thingsAt_single.TryGetValue(item2, out value2))
                    {
                        thingsAt_single.Remove(item2);
                        List <SketchThing> list = new List <SketchThing>();
                        list.Add(value2);
                        list.Add(sketchThing);
                        thingsAt_multiple.Add(item2, list);
                    }
                    else
                    {
                        thingsAt_single.Add(item2, sketchThing);
                    }
                }
                cachedThings.Add(sketchThing);
            }
            else
            {
                SketchTerrain sketchTerrain = entity as SketchTerrain;
                if (sketchTerrain != null)
                {
                    terrainAt[sketchTerrain.pos] = sketchTerrain;
                    cachedTerrain.Add(sketchTerrain);
                }
            }
        }
Exemple #4
0
        private void RemoveFromCache(SketchEntity entity)
        {
            occupiedRectDirty = true;
            SketchBuildable sketchBuildable = entity as SketchBuildable;

            if (sketchBuildable != null)
            {
                cachedBuildables.Remove(sketchBuildable);
            }
            SketchThing sketchThing = entity as SketchThing;

            if (sketchThing != null)
            {
                if (sketchThing.def.building != null && sketchThing.def.building.isEdifice)
                {
                    foreach (IntVec3 item in sketchThing.OccupiedRect)
                    {
                        if (edificeAt.TryGetValue(item, out SketchThing value) && value == sketchThing)
                        {
                            edificeAt.Remove(item);
                        }
                    }
                }
                foreach (IntVec3 item2 in sketchThing.OccupiedRect)
                {
                    SketchThing value3;
                    if (thingsAt_multiple.TryGetValue(item2, out List <SketchThing> value2))
                    {
                        value2.Remove(sketchThing);
                    }
                    else if (thingsAt_single.TryGetValue(item2, out value3) && value3 == sketchThing)
                    {
                        thingsAt_single.Remove(item2);
                    }
                }
                cachedThings.Remove(sketchThing);
                return;
            }
            SketchTerrain sketchTerrain = entity as SketchTerrain;

            if (sketchTerrain != null)
            {
                if (terrainAt.TryGetValue(sketchTerrain.pos, out SketchTerrain value4) && value4 == sketchTerrain)
                {
                    terrainAt.Remove(sketchTerrain.pos);
                }
                cachedTerrain.Remove(sketchTerrain);
            }
        }
        private void PlaceBlueprintsSimilarTo(SketchBuildable buildable, ThingDef preferredStuffIfNone)
        {
            bool flag = buildable is SketchTerrain;

            foreach (SketchBuildable buildable2 in sketch.Buildables)
            {
                SketchTerrain sketchTerrain;
                SketchThing   sketchThing;
                if ((flag && (sketchTerrain = buildable2 as SketchTerrain) != null && sketchTerrain.IsSameOrSimilar(buildable.Buildable)) || (!flag && (sketchThing = buildable2 as SketchThing) != null && buildable.Buildable == sketchThing.def))
                {
                    tmpBuildables.Add(buildable2);
                }
            }
            foreach (SketchBuildable tmpBuildable in tmpBuildables)
            {
                PlaceBlueprint(tmpBuildable, preferredStuffIfNone);
            }
            tmpBuildables.Clear();
        }
Exemple #6
0
        public bool Add(SketchEntity entity, bool wipeIfCollides = true)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (entities.Contains(entity))
            {
                return(true);
            }
            if (wipeIfCollides)
            {
                WipeColliding(entity);
            }
            else if (WouldCollide(entity))
            {
                return(false);
            }
            SketchTerrain sketchTerrain = entity as SketchTerrain;

            if (sketchTerrain != null && terrainAt.TryGetValue(sketchTerrain.pos, out SketchTerrain value))
            {
                Remove(value);
            }
            SketchBuildable sketchBuildable = entity as SketchBuildable;

            if (sketchBuildable != null)
            {
                for (int num = cachedBuildables.Count - 1; num >= 0; num--)
                {
                    if (sketchBuildable.OccupiedRect.Overlaps(cachedBuildables[num].OccupiedRect) && GenSpawn.SpawningWipes(sketchBuildable.Buildable, cachedBuildables[num].Buildable))
                    {
                        Remove(cachedBuildables[num]);
                    }
                }
            }
            entities.Add(entity);
            AddToCache(entity);
            return(true);
        }
        public List <ThingDef> AllowedStuffsFor(SketchBuildable buildable)
        {
            if (buildable.Buildable.MadeFromStuff && buildable.Stuff == null)
            {
                return(GenStuff.AllowedStuffs(buildable.Buildable.stuffCategories).ToList());
            }
            SketchTerrain sketchTerrain;

            if ((sketchTerrain = buildable as SketchTerrain) != null)
            {
                List <ThingDef> list = new List <ThingDef>();
                {
                    foreach (TerrainDef allDef in DefDatabase <TerrainDef> .AllDefs)
                    {
                        if (allDef.BuildableByPlayer && sketchTerrain.IsSameOrSimilar(allDef) && !allDef.costList.NullOrEmpty())
                        {
                            list.Add(allDef.costList.First().thingDef);
                        }
                    }
                    return(list);
                }
            }
            return(null);
        }
Exemple #8
0
        public override IEnumerable <Gizmo> GetGizmos()
        {
            foreach (Gizmo gizmo in base.GetGizmos())
            {
                yield return(gizmo);
            }
            if (!AllDone)
            {
                Command_Action command_Action = new Command_Action();
                command_Action.defaultLabel = "CommandCancelMonumentMarker".Translate();
                command_Action.defaultDesc  = "CommandCancelMonumentMarkerDesc".Translate();
                command_Action.icon         = CancelCommandTex;
                command_Action.action       = delegate
                {
                    Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmCancelMonumentMarker".Translate(), delegate
                    {
                        QuestUtility.SendQuestTargetSignals(questTags, "MonumentCancelled", this.Named("SUBJECT"));
                        RemovePossiblyRelatedBlueprints();
                        this.Uninstall();
                    }, destructive: true));
                };
                yield return(command_Action);
            }
            bool flag = false;

            foreach (SketchEntity entity in sketch.Entities)
            {
                SketchBuildable sketchBuildable = entity as SketchBuildable;
                if (sketchBuildable != null && !entity.IsSameSpawnedOrBlueprintOrFrame(entity.pos + base.Position, base.Map) && !entity.IsSpawningBlocked(entity.pos + base.Position, base.Map) && BuildCopyCommandUtility.FindAllowedDesignator(sketchBuildable.Buildable) != null)
                {
                    flag = true;
                    break;
                }
            }
            if (flag)
            {
                Command_Action command_Action2 = new Command_Action();
                command_Action2.defaultLabel = "CommandPlaceBlueprints".Translate();
                command_Action2.defaultDesc  = "CommandPlaceBlueprintsDesc".Translate();
                command_Action2.icon         = PlaceBlueprintsCommandTex;
                MonumentMarker monumentMarker = default(MonumentMarker);
                ThingDef       stuffLocal     = default(ThingDef);
                command_Action2.action = delegate
                {
                    IEnumerable <ThingDef> enumerable = AllowedStuffs();
                    if (!enumerable.Any())
                    {
                        PlaceAllBlueprints(null);
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    }
                    else if (enumerable.Count() == 1)
                    {
                        PlaceAllBlueprints(enumerable.First());
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    }
                    else
                    {
                        List <FloatMenuOption> list = new List <FloatMenuOption>();
                        bool flag4 = false;
                        foreach (ThingDef item in enumerable)
                        {
                            if (base.Map.listerThings.ThingsOfDef(item).Count > 0)
                            {
                                flag4 = true;
                                break;
                            }
                        }
                        foreach (ThingDef item2 in enumerable)
                        {
                            monumentMarker = this;
                            if (!flag4 || base.Map.listerThings.ThingsOfDef(item2).Count != 0)
                            {
                                stuffLocal = item2;
                                list.Add(new FloatMenuOption(stuffLocal.LabelCap, delegate
                                {
                                    monumentMarker.PlaceAllBlueprints(stuffLocal);
                                }, item2));
                            }
                        }
                        Find.WindowStack.Add(new FloatMenu(list));
                    }
                };
                yield return(command_Action2);
            }
            foreach (Gizmo questRelatedGizmo in QuestUtility.GetQuestRelatedGizmos(this))
            {
                yield return(questRelatedGizmo);
            }
            if (Prefs.DevMode)
            {
                bool flag2 = false;
                foreach (SketchEntity entity2 in sketch.Entities)
                {
                    if (!entity2.IsSameSpawned(entity2.pos + base.Position, base.Map) && !entity2.IsSpawningBlocked(entity2.pos + base.Position, base.Map))
                    {
                        flag2 = true;
                        break;
                    }
                }
                if (flag2)
                {
                    Command_Action command_Action3 = new Command_Action();
                    command_Action3.defaultLabel = "Dev: Build all";
                    command_Action3.action       = delegate
                    {
                        DebugBuildAll();
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    };
                    yield return(command_Action3);
                }
            }
            tmpUniqueBuildableDefs.Clear();
            foreach (SketchEntity entity3 in sketch.Entities)
            {
                SketchBuildable sketchBuildable2 = entity3 as SketchBuildable;
                if (sketchBuildable2 != null && !entity3.IsSameSpawnedOrBlueprintOrFrame(entity3.pos + base.Position, base.Map) && tmpUniqueBuildableDefs.Add(new Pair <BuildableDef, ThingDef>(sketchBuildable2.Buildable, sketchBuildable2.Stuff)))
                {
                    SketchTerrain sketchTerrain;
                    if ((sketchTerrain = (sketchBuildable2 as SketchTerrain)) != null && sketchTerrain.treatSimilarAsSame)
                    {
                        TerrainDef terrain = sketchBuildable2.Buildable as TerrainDef;
                        if (terrain.designatorDropdown != null)
                        {
                            Designator designator = BuildCopyCommandUtility.FindAllowedDesignatorRoot(sketchBuildable2.Buildable);
                            if (designator != null)
                            {
                                yield return(designator);
                            }
                        }
                        else
                        {
                            IEnumerable <TerrainDef> allDefs = DefDatabase <TerrainDef> .AllDefs;
                            foreach (TerrainDef item3 in allDefs)
                            {
                                if (item3.BuildableByPlayer && item3.designatorDropdown == null)
                                {
                                    bool flag3 = true;
                                    for (int i = 0; i < terrain.affordances.Count; i++)
                                    {
                                        if (!item3.affordances.Contains(terrain.affordances[i]))
                                        {
                                            flag3 = false;
                                            break;
                                        }
                                    }
                                    if (flag3)
                                    {
                                        Command command = BuildCopyCommandUtility.BuildCommand(item3, null, item3.label, item3.description, allowHotKey: false);
                                        if (command != null)
                                        {
                                            yield return(command);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Command command2 = BuildCopyCommandUtility.BuildCommand(sketchBuildable2.Buildable, sketchBuildable2.Stuff, entity3.Label, sketchBuildable2.Buildable.description, allowHotKey: false);
                        if (command2 != null)
                        {
                            yield return(command2);
                        }
                    }
                }
            }
            tmpUniqueBuildableDefs.Clear();
        }
        public override IEnumerable <Gizmo> GetGizmos()
        {
            foreach (Gizmo gizmo in base.GetGizmos())
            {
                yield return(gizmo);
            }
            if (!AllDone)
            {
                Command_Action command_Action = new Command_Action();
                command_Action.defaultLabel = "CommandCancelMonumentMarker".Translate();
                command_Action.defaultDesc  = "CommandCancelMonumentMarkerDesc".Translate();
                command_Action.icon         = CancelCommandTex;
                command_Action.action       = delegate
                {
                    Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmCancelMonumentMarker".Translate(), delegate
                    {
                        QuestUtility.SendQuestTargetSignals(questTags, "MonumentCancelled", this.Named("SUBJECT"));
                        RemovePossiblyRelatedBlueprints();
                        this.Uninstall();
                    }, destructive: true));
                };
                yield return(command_Action);
            }
            bool flag = false;

            foreach (SketchEntity entity in sketch.Entities)
            {
                SketchBuildable sketchBuildable = entity as SketchBuildable;
                if (sketchBuildable != null && !entity.IsSameSpawnedOrBlueprintOrFrame(entity.pos + base.Position, base.Map) && !entity.IsSpawningBlocked(entity.pos + base.Position, base.Map) && BuildCopyCommandUtility.FindAllowedDesignator(sketchBuildable.Buildable) != null)
                {
                    flag = true;
                    break;
                }
            }
            if (flag)
            {
                Command_Action command_Action2 = new Command_Action();
                command_Action2.defaultLabel = "CommandPlaceBlueprints".Translate();
                command_Action2.defaultDesc  = "CommandPlaceBlueprintsDesc".Translate();
                command_Action2.icon         = PlaceBlueprintsCommandTex;
                command_Action2.action       = delegate
                {
                    IEnumerable <ThingDef> enumerable = AllowedStuffs();
                    if (!enumerable.Any())
                    {
                        PlaceAllBlueprints(null);
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    }
                    else if (enumerable.Count() == 1)
                    {
                        PlaceAllBlueprints(enumerable.First());
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    }
                    else
                    {
                        ListFloatMenuOptions(enumerable, delegate(ThingDef stuff)
                        {
                            PlaceAllBlueprints(stuff);
                        });
                    }
                };
                yield return(command_Action2);
            }
            foreach (Gizmo questRelatedGizmo in QuestUtility.GetQuestRelatedGizmos(this))
            {
                yield return(questRelatedGizmo);
            }
            if (Prefs.DevMode)
            {
                bool flag2 = false;
                foreach (SketchEntity entity2 in sketch.Entities)
                {
                    if (!entity2.IsSameSpawned(entity2.pos + base.Position, base.Map) && !entity2.IsSpawningBlocked(entity2.pos + base.Position, base.Map))
                    {
                        flag2 = true;
                        break;
                    }
                }
                if (flag2)
                {
                    Command_Action command_Action3 = new Command_Action();
                    command_Action3.defaultLabel = "Dev: Build all";
                    command_Action3.action       = delegate
                    {
                        DebugBuildAll();
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    };
                    yield return(command_Action3);
                }
                if (AllDone && AnyDisallowedBuilding && !DisallowedBuildingTicksExpired)
                {
                    Command_Action command_Action4 = new Command_Action();
                    command_Action4.defaultLabel = "Dev: Disallowed building ticks +6 hours";
                    command_Action4.action       = delegate
                    {
                        ticksSinceDisallowedBuilding += 15000;
                    };
                    yield return(command_Action4);
                }
            }
            tmpUniqueBuildableDefs.Clear();
            foreach (SketchEntity entity3 in sketch.Entities)
            {
                SketchBuildable buildable = entity3 as SketchBuildable;
                if (buildable == null || entity3.IsSameSpawnedOrBlueprintOrFrame(entity3.pos + base.Position, base.Map) || !tmpUniqueBuildableDefs.Add(new Pair <BuildableDef, ThingDef>(buildable.Buildable, buildable.Stuff)))
                {
                    continue;
                }
                SketchTerrain sketchTerrain;
                if ((sketchTerrain = buildable as SketchTerrain) != null && sketchTerrain.treatSimilarAsSame)
                {
                    TerrainDef terrain = buildable.Buildable as TerrainDef;
                    if (terrain.designatorDropdown != null)
                    {
                        Designator designator = BuildCopyCommandUtility.FindAllowedDesignatorRoot(buildable.Buildable);
                        if (designator != null)
                        {
                            yield return(designator);
                        }
                    }
                    else
                    {
                        IEnumerable <TerrainDef> allDefs = DefDatabase <TerrainDef> .AllDefs;
                        foreach (TerrainDef item in allDefs)
                        {
                            if (!item.BuildableByPlayer || item.designatorDropdown != null)
                            {
                                continue;
                            }
                            bool flag3 = true;
                            for (int i = 0; i < terrain.affordances.Count; i++)
                            {
                                if (!item.affordances.Contains(terrain.affordances[i]))
                                {
                                    flag3 = false;
                                    break;
                                }
                            }
                            if (flag3)
                            {
                                Command command = BuildCopyCommandUtility.BuildCommand(item, null, item.label, item.description, allowHotKey: false);
                                if (command != null)
                                {
                                    yield return(command);
                                }
                            }
                        }
                    }
                }
                else
                {
                    Command command2 = BuildCopyCommandUtility.BuildCommand(buildable.Buildable, buildable.Stuff, entity3.LabelCap, buildable.Buildable.description, allowHotKey: false);
                    if (command2 != null)
                    {
                        yield return(command2);
                    }
                }
                Command_Action placeBlueprintsCommand = GetPlaceBlueprintsCommand(buildable);
                if (placeBlueprintsCommand != null)
                {
                    yield return(placeBlueprintsCommand);
                }
            }
            tmpUniqueBuildableDefs.Clear();
        }