public override ActivationResult Activate(Designator designator, Map map) { // distinct designation defs on selected things var selectedObjects = new HashSet <object>(Find.Selector.SelectedObjects); // also include designations on cells of selected things var selectedTilePositions = new HashSet <IntVec3>( selectedObjects.Where(t => t is Thing) .Select(t => ((Thing)t).Position) ); var selectedDesignationDefs = map.designationManager.allDesignations .Where(des => des.target.HasThing ? selectedObjects.Contains(des.target.Thing) : selectedTilePositions.Contains(des.target.Cell)) .Select(des => des.def) .Distinct() .ToArray(); var affectedDesignations = new HashSet <LocalTargetInfo>(); foreach (var designation in map.designationManager.allDesignations.ToArray()) { if (selectedDesignationDefs.Contains(designation.def)) { map.designationManager.RemoveDesignation(designation); affectedDesignations.Add(designation.target); } } return(affectedDesignations.Count > 0 ? ActivationResult.Success(BaseMessageKey, selectedDesignationDefs.Length, affectedDesignations.Count) : ActivationResult.Failure(BaseMessageKey)); }
public override ActivationResult Activate(Designator designator, Map map) { var visibleRect = AllowToolUtility.GetVisibleMapRect(); var hitCount = DesignateAllThings(designator, map, t => MenuEntry_HaulUrgentAll.CanAutoDesignateThingForUrgentHauling(t) && visibleRect.Contains(t.Position)); return(hitCount > 0 ? ActivationResult.Success(BaseTextKey, hitCount) : ActivationResult.Failure(BaseMessageKey)); }
public override ActivationResult Activate(Designator designator, Map map) { var thingIsVisible = GetVisibleThingFilter(); var hitCount = DesignateAllThings(designator, map, t => MenuEntry_HaulUrgentAll.CanAutoDesignateThingForUrgentHauling(t) && thingIsVisible(t)); return(hitCount > 0 ? ActivationResult.Success(BaseTextKey, hitCount) : ActivationResult.Failure(BaseMessageKey)); }
public static ActivationResult SelectSimilarWithFilter(Designator designator, Map map, string successMessageKey, string failureMessageKey, Predicate <Thing> filter = null) { var des = (Designator_SelectSimilar)designator; des = (Designator_SelectSimilar)des.PickUpReverseDesignator(); if (Find.Selector.NumSelected == 0) { return(ActivationResult.Failure(failureMessageKey)); } des.ReindexSelectionConstraints(); // find things to select var thingsToSelect = new List <Thing>(); foreach (var thing in map.listerThings.AllThings) { if (thing != null && (filter == null || filter(thing)) && des.CanDesignateThing(thing).Accepted) { thingsToSelect.Add(thing); } } // sort by distance to camera var cameraCenter = Current.CameraDriver.MapPosition; thingsToSelect.SortBy(t => t.Position.DistanceTo(cameraCenter)); // do selection var hitCount = 0; var limitWasHit = false; foreach (var thing in thingsToSelect) { if (!des.SelectionLimitAllowsAdditionalThing()) { limitWasHit = true; break; } if (des.TrySelectThing(thing)) { hitCount++; } } return(limitWasHit ? ActivationResult.SuccessMessage((successMessageKey + "_part").Translate(hitCount, thingsToSelect.Count)) : ActivationResult.Success(successMessageKey, hitCount)); }
public override ActivationResult Activate(Designator designator, Map map) { MineDesignateSelectedOres(map); var anyMineDesignations = map.designationManager.SpawnedDesignationsOfDef(DesignationDefOf.Mine).Any(); if (!anyMineDesignations) { return(ActivationResult.Failure(BaseMessageKey)); } // expand designations, excluding designated fogged cells to prevent exposing completely hidden ores var hits = FloodExpandDesignationType(DesignationDefOf.Mine, map, (cell, m) => !m.fogGrid.IsFogged(cell), MineDesignationExpansionIsValid); return(ActivationResult.Success(BaseMessageKey, hits)); }