Beispiel #1
0
        private static RemoveRoofModel InitModel(List <Thing> designatedThings, List <Thing> waitingThings, Map map, IntVec3 mousePos, Rot4 rotation, Dictionary <Thing, IntVec3> ghostPos)
        {
            RemoveRoofModel newModel = new RemoveRoofModel(
                designatedThings
                , designatedThings.OfType <Building>().Where(b => b.def.holdsRoof).ToHashSet()
                , waitingThings
                , new HashSet <IntVec3>()
                , map
                , mousePos
                , rotation
                , ghostPos);

            _removeRoofModels.Add(newModel);
            return(newModel);
        }
Beispiel #2
0
        private static void ResolveDeadLock(RemoveRoofModel model)
        {
            foreach (Thing thing in model.WaitingThings.ToList())
            {
                Thing        lastFound   = thing;
                List <Thing> foundThings = new List <Thing>()
                {
                    lastFound
                };

                while (true)
                {
                    IntVec3        spawnCell = GetDeltaCell(lastFound, model.MousePos, model.GhostPosition);
                    List <IntVec3> rect      = GenAdj.OccupiedRect(spawnCell, lastFound.Rotate(model.Rotation), lastFound.def.size).ToList();
                    if (lastFound.def.hasInteractionCell)
                    {
                        rect.Add(Verse.ThingUtility.InteractionCellWhenAt(lastFound.def, spawnCell, lastFound.Rotate(model.Rotation), lastFound.MapHeld));
                    }
                    IEnumerable <Thing> thingsOnCell = rect.SelectMany(c => c.GetThingList(lastFound.MapHeld).Where(t => t.def.blueprintDef != null && t.def.Minifiable));
                    lastFound = thingsOnCell.FirstOrDefault(t => GenConstruct.BlocksConstruction(lastFound, t) && model.WaitingThings.Contains(t))
                                ?? ThingUtility.BlockAdjacentInteractionCell(lastFound, spawnCell, lastFound.Rotate(model.Rotation));
                    if (lastFound == null || foundThings.Contains(lastFound))
                    {
                        break;
                    }

                    foundThings.Add(lastFound);
                }

                if (lastFound == null)
                {
                    continue;
                }
                else
                {
                    thing.Map.designationManager.AddDesignation(new Designation(thing, DesignationDefOf.Uninstall));
                }
            }
        }
Beispiel #3
0
        public override void DesignateSingleCell(IntVec3 c)
        {
            if (_mode == Mode.Select)
            {
                List <Thing> things = this.ReinstallableInCell(c);
                if (things.Any())
                {
                    if (_originFound == false)
                    {
                        _originFound = true;
                        _origin      = c;
                    }

                    DesignatedThings.AddRange(things);
                    things.ForEach(thing => DesignateThing(thing));
                }
            }
            else if (_mode == Mode.Place)
            {
                GenConstruct_CanPlaceBlueprintAt_Patch.Mode = BlueprintMode.Place;
                HashSet <Thing>                       placedThings  = new HashSet <Thing>();
                Dictionary <Thing, Thing>             twinThings    = new Dictionary <Thing, Thing>();
                Dictionary <Thing, Blueprint_Install> blueprintWork = new Dictionary <Thing, Blueprint_Install>();
                Dictionary <Thing, IntVec3>           siblingWork   = new Dictionary <Thing, IntVec3>();

                IntVec3 mousePos = UI.MouseCell();
                foreach (Thing designatedThing in DesignatedThings)
                {
                    IntVec3      drawCell     = GetDeltaCell(designatedThing, mousePos, _ghostPos);
                    List <Thing> things       = drawCell.GetThingList(designatedThing.MapHeld);
                    bool         foundTwin    = false;
                    bool         foundSibling = false;
                    foreach (Thing thingOnCell in things)
                    {
                        if (DesignatedThings.Contains(thingOnCell))
                        {
                            if (designatedThing.IdenticalWith(_rotation, thingOnCell))
                            {
                                if (blueprintWork.TryGetValue(thingOnCell, out Blueprint_Install install))
                                {
                                    Thing twin = this.GetTailInTwinThings(twinThings, designatedThing);

                                    _setBuildingToReinstall.Invoke(install, new[] { twin });
                                    blueprintWork[twin] = install;
                                    blueprintWork.Remove(thingOnCell);
                                    placedThings.Add(twin);
                                }
                                else if (siblingWork.TryGetValue(thingOnCell, out IntVec3 position))
                                {
                                    Thing twin = this.GetTailInTwinThings(twinThings, designatedThing);
                                    _ghostPos[twin] = position;
                                    siblingWork.Remove(thingOnCell);
                                    siblingWork[twin] = position;
                                    placedThings.Add(thingOnCell);
                                }
                                else
                                {
                                    twinThings[thingOnCell]    = designatedThing;
                                    _ghostPos[designatedThing] = _ghostPos[thingOnCell];
                                    placedThings.Add(thingOnCell);
                                }

                                this.Map.designationManager.TryRemoveDesignationOn(thingOnCell, MoveBaseDefOf.MoveBase);

                                foundTwin = true;
                                break;
                            }
                            else if (!GenConstruct.BlocksConstruction(designatedThing, thingOnCell))
                            {
                                continue;
                            }
                            else
                            {
                                foundSibling = true;
                                Thing twin = this.GetTailInTwinThings(twinThings, designatedThing);
                                siblingWork[twin] = _ghostPos[twin] = _ghostPos[designatedThing];
                                break;
                            }
                        }
                    }

                    if (foundTwin || foundSibling)
                    {
                        continue;
                    }

                    Thing twin1 = this.GetTailInTwinThings(twinThings, designatedThing);


                    AcceptanceReport report = GenConstruct.CanPlaceBlueprintAt(
                        twin1.def
                        , drawCell
                        , GetRotation(twin1)
                        , twin1.MapHeld
                        , false
                        , null
                        , twin1);

                    if (report.Accepted)
                    {
                        Building building = twin1 as Building;
                        blueprintWork[building] = GenConstruct.PlaceBlueprintForReinstall(building, drawCell, building.MapHeld, GetRotation(building), Faction.OfPlayer);
                        placedThings.Add(building);
                    }
                }

                RemoveRoofModel model =
                    InitModel(
                        DesignatedThings
                        , DesignatedThings.Except(placedThings).ToList()
                        , DesignatedThings.First().MapHeld
                        , mousePos
                        , _rotation
                        , _ghostPos);

                ResolveDeadLock(model);

                this.KeepDesignation = true;
                _mode = Mode.Select;
                Find.DesignatorManager.Deselect();
            }
        }