public static Range2D GetCorners(Area __instance) { if (__instance == null) { return(new Range2D(0, 0, 99999, 99999)); } if (corners.TryGetValue(__instance, out Range2D range)) { return(range); } IntVec3[] iv3 = __instance.ActiveCells.ToArray(); bool initialized = false; foreach (IntVec3 intVec3 in iv3) { if (!initialized) { range = new Range2D(intVec3.x, intVec3.z, intVec3.x, intVec3.z); initialized = true; } range.minX = Math.Min(range.minX, intVec3.x); range.minZ = Math.Min(range.minZ, intVec3.z); range.maxX = Math.Max(range.maxX, intVec3.x); range.maxZ = Math.Max(range.maxZ, intVec3.z); } corners[__instance] = range; return(range); }
public static void Set(Area __instance, IntVec3 c, bool val) { if (!val) { return; } Range2D range = GetCorners(__instance); range.minX = Math.Min(range.minX, c.x); range.minZ = Math.Min(range.minZ, c.z); range.maxX = Math.Max(range.maxX, c.x); range.maxZ = Math.Max(range.maxZ, c.z); }
public override bool IsTrue() { var ch = gameMode.BattleManager.CurrentCharacterLogic; if (ch == null) { UnityEngine.Debug.LogError("当前角色不存在 默认返回" + DefaultWhenError); return(DefaultWhenError); } var pos = ch.GetTileCoord(); return(Range2D.InRange(pos.x, pos.y, Range)); }
public RangeEventType GetRangeEvent(int characterID, int career, Vector2Int TilePosition) { foreach (RangeEventType Event in RangeEvent) { if (Event.Enable && Range2D.InRange(TilePosition.x, TilePosition.y, Event.Range)) { if (Event.DedicatedCareer >= 0 && career != Event.DedicatedCareer) { Debug.Log("不是特定职业"); return(null); } if (Event.DedicatedCharacter >= 0 && characterID != Event.DedicatedCareer) { Debug.Log("不是特定Player ID"); return(null); } return(Event); } } return(null); }
public static bool InRange(int x, int y, Range2D Range) { return(x >= Range.x && x <= Range.x + Range.width && y >= Range.y && y <= Range.y + Range.height); }
private void Sr_ValueRangeChanged(ISeriesControl sr, Range2D obj) { UpdateGlobalValueRange(); }
public static IEnumerable <IntVec3> GetOffsetOrder(IntVec3 position, int zoomLevel, Range2D scannedRange, Range2D areaRange) { //TODO optimize direction to scan first if (scannedRange.maxZ < areaRange.maxZ) { yield return(IntVec3.North); } if (scannedRange.maxZ < areaRange.maxZ && scannedRange.maxX < areaRange.maxX) { yield return(IntVec3.NorthEast); } if (scannedRange.maxX < areaRange.maxX) { yield return(IntVec3.East); } if (scannedRange.minZ > areaRange.minZ && scannedRange.maxX < areaRange.maxX) { yield return(IntVec3.SouthEast); } if (scannedRange.minZ > areaRange.minZ) { yield return(IntVec3.South); } if (scannedRange.minZ > areaRange.minZ && scannedRange.minX > areaRange.minX) { yield return(IntVec3.SouthWest); } if (scannedRange.maxX < areaRange.maxX) { yield return(IntVec3.West); } if (scannedRange.maxZ < areaRange.maxZ && scannedRange.minX > areaRange.minX) { yield return(IntVec3.NorthWest); } }
public static void Convolution2D(Dimensions2D dimensions, Range2D range, byte[] source, byte[] result) { }
public static IEnumerable <IntVec3> GetClosestActionableLocations(Pawn pawn, Map map, Dictionary <Map, List <HashSet <IntVec3>[]> > awaitingActionMapDict) { int jumboCellWidth; int XposOfJumboCell; int ZposOfJumboCell; int cellIndex; int mapSizeX = map.Size.x; if (retrunedThings == null) { retrunedThings = new HashSet <IntVec3>(); } else { retrunedThings.Clear(); } HashSet <IntVec3> objectsAtCellCopy; List <HashSet <IntVec3>[]> awaitingActionZoomLevels = GetAwaitingActionsZoomLevels(awaitingActionMapDict, map); IntVec3 position = pawn.Position; Area effectiveAreaRestrictionInPawnCurrentMap = pawn.playerSettings.EffectiveAreaRestrictionInPawnCurrentMap; Range2D areaRange = GetCorners(effectiveAreaRestrictionInPawnCurrentMap); Range2D scannedRange = new Range2D(position.x, position.z, position.x, position.z); for (int zoomLevel = 0; zoomLevel < awaitingActionZoomLevels.Count; zoomLevel++) { HashSet <IntVec3>[] objectsGrid = awaitingActionZoomLevels[zoomLevel]; jumboCellWidth = getJumboCellWidth(zoomLevel); int jumboCellColumnsInMap = GetJumboCellColumnsInMap(mapSizeX, jumboCellWidth); XposOfJumboCell = position.x / jumboCellWidth; ZposOfJumboCell = position.z / jumboCellWidth; //assuming square map if (zoomLevel == 0) { cellIndex = CellXZToIndexCustom(XposOfJumboCell, ZposOfJumboCell, jumboCellColumnsInMap); HashSet <IntVec3> objectsAtCell = objectsGrid[cellIndex]; if (objectsAtCell != null && objectsAtCell.Count > 0) { objectsAtCellCopy = new HashSet <IntVec3>(objectsAtCell); foreach (IntVec3 actionalbeObject in objectsAtCellCopy) { if (!retrunedThings.Contains(actionalbeObject)) { yield return(actionalbeObject); retrunedThings.Add(actionalbeObject); } } } } IEnumerable <IntVec3> offsetOrder = GetOffsetOrder(position, zoomLevel, scannedRange, areaRange); foreach (IntVec3 offset in offsetOrder) { int newXposOfJumboCell = XposOfJumboCell + offset.x; int newZposOfJumboCell = ZposOfJumboCell + offset.z; if (newXposOfJumboCell >= 0 && newXposOfJumboCell < jumboCellColumnsInMap && newZposOfJumboCell >= 0 && newZposOfJumboCell < jumboCellColumnsInMap) { //assuming square map HashSet <IntVec3> thingsAtCell = objectsGrid[CellXZToIndexCustom(newXposOfJumboCell, newZposOfJumboCell, jumboCellColumnsInMap)]; if (thingsAtCell != null && thingsAtCell.Count > 0) { objectsAtCellCopy = new HashSet <IntVec3>(thingsAtCell); foreach (IntVec3 actionalbeObject in objectsAtCellCopy) { if (!retrunedThings.Contains(actionalbeObject)) { yield return(actionalbeObject); retrunedThings.Add(actionalbeObject); } } } } } scannedRange.minX = Math.Min(scannedRange.minX, (XposOfJumboCell - 1) * jumboCellWidth); scannedRange.minZ = Math.Min(scannedRange.minZ, (ZposOfJumboCell - 1) * jumboCellWidth); scannedRange.maxX = Math.Max(scannedRange.maxX, ((XposOfJumboCell + 2) * jumboCellWidth) - 1); scannedRange.maxZ = Math.Max(scannedRange.maxZ, ((ZposOfJumboCell + 2) * jumboCellWidth) - 1); } }