private void RefreshCreatureCount(object data = null) { int cell = this.GetSMI <RanchStation.Instance>().GetTargetRanchCell(); CavityInfo cavityForCell = Game.Instance.roomProber.GetCavityForCell(cell); int num = storedCreatureCount; storedCreatureCount = 0; if (cavityForCell != null) { foreach (KPrefabID creature in cavityForCell.creatures) { if (!creature.HasTag(GameTags.Creatures.Bagged) && !creature.HasTag(GameTags.Trapped)) { storedCreatureCount++; } } } }
private static bool CanCapturableBeCapturedAtCapturePoint(FixedCapturableMonitor.Instance capturable, Instance capture_point, CavityInfo capture_cavity_info, int capture_cell) { if (!capturable.IsRunning()) { return(false); } if (capturable.HasTag(GameTags.Creatures.Bagged)) { return(false); } if (capturable.targetCapturePoint != capture_point && !capturable.targetCapturePoint.IsNullOrStopped()) { return(false); } if (capture_point.def.isCreatureEligibleToBeCapturedCb != null && !capture_point.def.isCreatureEligibleToBeCapturedCb(capturable.gameObject, capture_point)) { return(false); } if (!capturable.GetComponent <ChoreConsumer>().IsChoreEqualOrAboveCurrentChorePriority <FixedCaptureStates>()) { return(false); } int cell = Grid.PosToCell(capturable.transform.GetPosition()); CavityInfo cavityForCell = Game.Instance.roomProber.GetCavityForCell(cell); if (cavityForCell == null || cavityForCell != capture_cavity_info) { return(false); } int navigationCost = capturable.GetComponent <Navigator>().GetNavigationCost(capture_cell); if (navigationCost == -1) { return(false); } TreeFilterable component = capture_point.GetComponent <TreeFilterable>(); IUserControlledCapacity component2 = capture_point.GetComponent <IUserControlledCapacity>(); if (component.ContainsTag(capturable.GetComponent <KPrefabID>().PrefabTag) && component2.AmountStored <= component2.UserMaxCapacity) { return(false); } return(true); }
public void FindRanchable() { int targetRanchCell = GetTargetRanchCell(); CavityInfo cavityForCell = Game.Instance.roomProber.GetCavityForCell(targetRanchCell); if (cavityForCell == null || cavityForCell.room == null || cavityForCell.room.roomType != Db.Get().RoomTypes.CreaturePen) { TriggerRanchStationNoLongerAvailable(); } else { if (this.targetRanchable != null && !CanRanchableBeRanchedAtRanchStation(this.targetRanchable, this, cavityForCell, targetRanchCell)) { TriggerRanchStationNoLongerAvailable(); } if (this.targetRanchable.IsNullOrStopped()) { CavityInfo cavityForCell2 = Game.Instance.roomProber.GetCavityForCell(targetRanchCell); RanchableMonitor.Instance targetRanchable = null; if (cavityForCell2 != null && cavityForCell2.creatures != null) { foreach (KPrefabID creature in cavityForCell2.creatures) { if (!((UnityEngine.Object)creature == (UnityEngine.Object)null)) { RanchableMonitor.Instance sMI = creature.GetSMI <RanchableMonitor.Instance>(); if (!sMI.IsNullOrStopped() && CanRanchableBeRanchedAtRanchStation(sMI, this, cavityForCell2, targetRanchCell)) { targetRanchable = sMI; break; } } } } this.targetRanchable = targetRanchable; if (!this.targetRanchable.IsNullOrStopped()) { this.targetRanchable.targetRanchStation = this; } } } }
public void UpdateRoom(CavityInfo cavity) { if (cavity != null) { if (cavity.room != null) { ClearRoom(cavity.room); cavity.room = null; } CreateRoom(cavity); foreach (KPrefabID building in cavity.buildings) { building.Trigger(144050788, cavity.room); } foreach (KPrefabID plant in cavity.plants) { plant.Trigger(144050788, cavity.room); } } }
private static void UpdateCavity(Instance smi, float dt) { CavityInfo cavityForCell = Game.Instance.roomProber.GetCavityForCell(Grid.PosToCell(smi)); if (cavityForCell != smi.cavity) { KPrefabID component = smi.GetComponent <KPrefabID>(); if (smi.cavity != null) { GetCreatureCollection(smi, smi.cavity).Remove(component); Game.Instance.roomProber.UpdateRoom(cavityForCell); } smi.cavity = cavityForCell; if (smi.cavity != null) { GetCreatureCollection(smi, smi.cavity).Add(component); Game.Instance.roomProber.UpdateRoom(smi.cavity); } } }
public static Color GetRoomsColour(SimDebugView instance, int cell) { Color result = Color.black; if (Grid.IsValidCell(instance.selectedCell)) { CavityInfo cavityForCell = Game.Instance.roomProber.GetCavityForCell(cell); if (cavityForCell != null && cavityForCell.room != null) { Room room = cavityForCell.room; result = room.roomType.category.color; result.a = 0.45f; CavityInfo cavityForCell2 = Game.Instance.roomProber.GetCavityForCell(instance.selectedCell); if (cavityForCell2 == cavityForCell) { result.a += 0.3f; } } } return(result); }
private void RefreshCreatureCount(object data = null) { int cell = Grid.PosToCell(this); CavityInfo cavityForCell = Game.Instance.roomProber.GetCavityForCell(cell); int num = storedCreatureCount; storedCreatureCount = 0; if (cavityForCell != null) { foreach (KPrefabID creature in cavityForCell.creatures) { if (!creature.HasTag(GameTags.Creatures.Bagged) && !creature.HasTag(GameTags.Trapped)) { storedCreatureCount++; } } } if (storedCreatureCount != num) { RebalanceFetches(); } }
private static bool CanRanchableBeRanchedAtRanchStation(RanchableMonitor.Instance ranchable, Instance ranch_station, CavityInfo ranch_cavity_info, int ranch_cell) { if (!ranchable.IsRunning()) { return(false); } if (ranchable.targetRanchStation != ranch_station && ranchable.targetRanchStation != null && ranchable.targetRanchStation.IsRunning()) { return(false); } if (!ranch_station.def.isCreatureEligibleToBeRanchedCb(ranchable.gameObject, ranch_station)) { return(false); } if (!ranchable.GetComponent <ChoreConsumer>().IsChoreEqualOrAboveCurrentChorePriority <RanchedStates>()) { return(false); } int cell = Grid.PosToCell(ranchable.transform.GetPosition()); CavityInfo cavityForCell = Game.Instance.roomProber.GetCavityForCell(cell); if (cavityForCell == null || cavityForCell != ranch_cavity_info) { return(false); } int navigationCost = ranchable.GetComponent <Navigator>().GetNavigationCost(ranch_cell); if (navigationCost == -1) { return(false); } return(true); }
/// <summary> /// If the cell is not already in a valid room, creates a room with this cell as the /// seed. /// </summary> /// <param name="cell">The starting cell.</param> private void CreateCavityFrom(int cell) { var visited = visitedCells; if (!RoomProber.CavityFloodFiller.IsWall(cell) && visited.Add(cell)) { int n = 0, minX = int.MaxValue, minY = int.MaxValue, maxX = int.MinValue, maxY = int.MinValue; bool filled; HandleVector <int> .Handle targetCavity; var queue = floodFilling; var cavity = new CavityInfo(); lock (cavityInfos) { targetCavity = cavityInfos.Allocate(cavity); } do { if (RoomProber.CavityFloodFiller.IsWall(cell)) { // Walls and doors have no room cavityForCell[cell].Clear(); } else { int above = Grid.CellAbove(cell), below = Grid.CellBelow(cell), left = Grid.CellLeft(cell), right = Grid.CellRight(cell); Grid.CellToXY(cell, out int x, out int y); cavityForCell[cell] = targetCavity; n++; if (x < minX) { minX = x; } if (x > maxX) { maxX = x; } if (y < minY) { minY = y; } if (y > maxY) { maxY = y; } buildingChanges.Enqueue(cell); if (Grid.IsValidCell(above) && visited.Add(above)) { queue.Enqueue(above); } if (Grid.IsValidCell(below) && visited.Add(below)) { queue.Enqueue(below); } if (Grid.IsValidCell(left) && visited.Add(left)) { queue.Enqueue(left); } if (Grid.IsValidCell(right) && visited.Add(right)) { queue.Enqueue(right); } } filled = queue.Count > 0; if (filled) { cell = queue.Dequeue(); } } while (filled); cavity.minX = minX; cavity.minY = minY; cavity.maxX = maxX; cavity.maxY = maxY; cavity.numCells = n; } }
/// <summary> /// Adds the building or plant in the cell to its room. /// </summary> /// <param name="cell">The cell to query.</param> /// <param name="cavity">The cavity for that cell.</param> private void AddBuildingToRoom(int cell, CavityInfo cavity) { var go = Grid.Objects[cell, (int)ObjectLayer.Building]; bool scanPlants = false, scanBuildings = false, dirty = false, found = false; if (go != null && go.TryGetComponent(out KPrefabID prefabID)) { // Is this entity already in the list? if (go.TryGetComponent(out Deconstructable _)) { var buildings = cavity.buildings; int n = buildings.Count; for (int i = 0; i < n; i++) { var building = buildings[i]; if (building != null) { tempIDs.Add(building); } else { dirty = true; } if (building == prefabID) { found = true; } } if (dirty) { buildings.Clear(); buildings.AddRange(tempIDs); } tempIDs.Clear(); if (!found) { cavity.AddBuilding(prefabID); } scanBuildings = true; } else if (go.HasTag(GameTags.Plant) && !go.HasTag(TREE_BRANCH_TAG)) { var plants = cavity.plants; int n = plants.Count; for (int i = 0; i < n; i++) { var plant = plants[i]; if (plant != null) { tempIDs.Add(plant); } else { dirty = true; } if (plant == prefabID) { found = true; } } if (dirty) { plants.Clear(); plants.AddRange(tempIDs); } tempIDs.Clear(); if (!found) { cavity.AddPlants(prefabID); } scanPlants = true; } } // Because this class no longer deletes and recreates the room, need to scan and // purge dead buildings from the list if (!scanBuildings) { dirty |= RemoveDestroyed(cavity.buildings); } if (!scanPlants) { dirty |= RemoveDestroyed(cavity.plants); } if (dirty) { cavity.dirty = true; } }
private unsafe void ProcessSolidChanges() { int *ptr = stackalloc int[5]; *ptr = 0; ptr[1] = -Grid.WidthInCells; ptr[2] = -1; ptr[3] = 1; ptr[4] = Grid.WidthInCells; foreach (int solidChange in solidChanges) { for (int i = 0; i < 5; i++) { int num = solidChange + ptr[i]; if (Grid.IsValidCell(num)) { floodFillSet.Add(num); HandleVector <int> .Handle item = CellCavityID[num]; if (item.IsValid()) { CellCavityID[num] = HandleVector <int> .InvalidHandle; releasedIDs.Add(item); } } } } CavityInfo cavityInfo = CreateNewCavity(); foreach (int item2 in floodFillSet) { if (!visitedCells.Contains(item2)) { HandleVector <int> .Handle handle = CellCavityID[item2]; if (!handle.IsValid()) { CavityInfo cavityInfo2 = cavityInfo; floodFiller.Reset(cavityInfo2.handle); GameUtil.FloodFillConditional(item2, floodFiller.ShouldContinue, visitedCells, null); if (floodFiller.NumCells > 0) { cavityInfo2.numCells = floodFiller.NumCells; cavityInfo2.minX = floodFiller.MinX; cavityInfo2.minY = floodFiller.MinY; cavityInfo2.maxX = floodFiller.MaxX; cavityInfo2.maxY = floodFiller.MaxY; cavityInfo = CreateNewCavity(); } } } } if (cavityInfo.numCells == 0) { releasedIDs.Add(cavityInfo.handle); } foreach (HandleVector <int> .Handle releasedID in releasedIDs) { CavityInfo data = cavityInfos.GetData(releasedID); if (data.room != null) { ClearRoom(data.room); } cavityInfos.Free(releasedID); } RebuildDirtyCavities(visitedCells); releasedIDs.Clear(); visitedCells.Clear(); solidChanges.Clear(); floodFillSet.Clear(); }
private void RoomCard(HoverTextDrawer hoverTextDrawer) { CavityInfo cavityForCell = Game.Instance.roomProber.GetCavityForCell(cellPos); if (cavityForCell == null) { return; } Room room = cavityForCell.room; RoomType roomType = room?.roomType; hoverTextDrawer.BeginShadowBar(false); string roomTypeName = roomType?.Name ?? UI.OVERLAYS.ROOMS.NOROOM.HEADER; hoverTextDrawer.DrawText(roomTypeName, __this.Styles_BodyText.Standard); if (room != null) { string roomEffect = RoomDetails.EFFECT.resolve_string_function.Invoke(room); string roomAssignee = RoomDetails.ASSIGNED_TO.resolve_string_function.Invoke(room); string roomCriteria = RoomConstraints.RoomCriteriaString(room); string roomEffects = RoomDetails.EFFECTS.resolve_string_function.Invoke(room); if (roomEffect != "") { hoverTextDrawer.NewLine(26); hoverTextDrawer.DrawText(roomEffect, __this.Styles_BodyText.Standard); } if (roomAssignee != "" && roomType != Db.Get().RoomTypes.Neutral) { hoverTextDrawer.NewLine(26); hoverTextDrawer.DrawText(roomAssignee, __this.Styles_BodyText.Standard); } hoverTextDrawer.NewLine(22); hoverTextDrawer.DrawText(RoomDetails.RoomDetailString(room), __this.Styles_BodyText.Standard); if (roomCriteria != "") { hoverTextDrawer.NewLine(26); hoverTextDrawer.DrawText(roomCriteria, __this.Styles_BodyText.Standard); } if (roomEffects != "") { hoverTextDrawer.NewLine(26); hoverTextDrawer.DrawText(roomEffects, __this.Styles_BodyText.Standard); } } else { string roomNA = UI.OVERLAYS.ROOMS.NOROOM.DESC; int maxRoomSize = TuningData <RoomProber.Tuning> .Get().maxRoomSize; if (cavityForCell.numCells > maxRoomSize) { roomNA = roomNA + "\n" + string.Format(UI.OVERLAYS.ROOMS.NOROOM.TOO_BIG, cavityForCell.numCells, maxRoomSize); } hoverTextDrawer.NewLine(26); hoverTextDrawer.DrawText(roomNA, __this.Styles_BodyText.Standard); } hoverTextDrawer.EndShadowBar(); }
public void Sim4000ms(float dt) { try { CavityInfo room = Game.Instance.roomProber.GetCavityForCell(Grid.PosToCell(this)); if (room == null) { return; } int eggCount = room.eggs.Count; int critterCount = room.creatures.Count; this._creatureCount = eggCount + critterCount; if (threshold >= this._creatureCount) { return; } List <Indexer> ageList = new List <Indexer>(); for (int i = 0; i < room.eggs.Count; i++) //foreach(KPrefabID egg in room.eggs) { GameObject egg = null; Clearable clearable = null; AmountInstance incubation = null; try { egg = room.eggs[i].gameObject; } catch (Exception) { Debug.Log("egg.gameObject was null"); } if (egg != null) { clearable = egg.GetComponent <Clearable>(); incubation = Db.Get().Amounts.Incubation.Lookup(egg); } if (incubation != null && clearable != null) { if (!IsMarkedForSweeping(clearable)) { ageList.Add(new Indexer(i, incubation.value)); //Debug.Log("egg is age:" + incubation.value); } else { ageList.Add(new Indexer(i, -1f)); eggCount--; } } else { eggCount--; ageList.Add(new Indexer(i, -2f)); } } if (threshold >= eggCount + critterCount) { return; } ageList = ageList.OrderBy(r => r.value).ToList(); //OrderByDescending //Debug.Log("Egg Age List: "); //for (int i = 0; i < ageList.Count; i++) //{ // Debug.Log("No: " + i + "age: " + ageList[i].value + "index: " + ageList[i].index); //} for (int i = 0; i < ageList.Count; i++) { if (ageList[i].value >= 0f) { Clearable clearable = room.eggs[ageList[i].index].gameObject.GetComponent <Clearable>(); clearable.MarkForClear(); eggCount--; if (threshold >= eggCount + critterCount) { return; } } } if (!attackSurplus) { return; } for (int i = 0; i < room.creatures.Count; i++) //foreach (KPrefabID creature in room.creatures) { GameObject creature = null; try { creature = room.creatures[i].gameObject; } catch (Exception) { Debug.Log("creature.gameObject was null"); } if (creature != null) { Capturable capturable = creature.GetComponent <Capturable>(); if (capturable != null && (capturable.IsMarkedForCapture || capturable.gameObject.HasTag(GameTags.Creatures.Bagged) || capturable.gameObject.HasTag(GameTags.Stored))) { critterCount--; if (threshold >= eggCount + critterCount) { return; } } } else { critterCount--; if (threshold >= eggCount + critterCount) { return; } } } for (int i = 0; i < room.creatures.Count; i++) //foreach (KPrefabID creature in room.creatures) { GameObject creature = null; try { creature = room.creatures[i].gameObject; } catch (Exception) { Debug.Log("creature.gameObject was null"); } if (creature != null) { Capturable capturable = creature.GetComponent <Capturable>(); if (capturable != null && !capturable.IsMarkedForCapture && !capturable.gameObject.HasTag(GameTags.Trapped) && !capturable.gameObject.HasTag(GameTags.Stored) && !capturable.gameObject.HasTag(GameTags.Creatures.Bagged)) { //bool flag = capturable.allowCapture; capturable.allowCapture = true; capturable.MarkForCapture(true); //capturable.allowCapture = flag; critterCount--; if (threshold >= eggCount + critterCount) { return; } } } } } catch (Exception e) { Debug.Log("Wups, this shouldn't happen: " + e.ToString()); } }
/// <summary> /// A version of OvercrowdingMonitor.UpdateCavity that updates the correct rooms. /// </summary> /// <param name="smi">The overcrowding monitor to update.</param> /// <param name="prefabID">The critter to be updated.</param> /// <returns>The new room of the critter.</returns> private static CavityInfo UpdateRoom(OvercrowdingMonitor.Instance smi, KPrefabID prefabID) { CavityInfo room = smi.cavity, newRoom; bool background = FastTrackOptions.Instance.BackgroundRoomRebuild; int cell = Grid.PosToCell(smi.transform.position); if (background) { newRoom = GamePatches.BackgroundRoomProber.Instance.GetCavityForCell(cell); } else { newRoom = Game.Instance.roomProber.GetCavityForCell(cell); } prefabID.UpdateTagBits(); if (newRoom != room) { bool isEgg = prefabID.HasAnyTags_AssumeLaundered(ref EGG), light = smi.GetComponent <Light2D>() != null; // Currently no rooms (checked I Love Slicksters, Butcher Stations, and Rooms // Expanded) use the WILDANIMAL criterion, so only light emitting critters // would need to actually update the rooms. if (room != null) { if (isEgg) { room.eggs.Remove(prefabID); } else { room.creatures.Remove(prefabID); } if (light) { if (background) { GamePatches.BackgroundRoomProber.Instance.UpdateRoom(room); } else { Game.Instance.roomProber.UpdateRoom(room); } } } smi.cavity = newRoom; if (newRoom != null) { if (isEgg) { newRoom.eggs.Add(prefabID); } else { newRoom.creatures.Add(prefabID); } if (light) { if (background) { GamePatches.BackgroundRoomProber.Instance.UpdateRoom(newRoom); } else { Game.Instance.roomProber.UpdateRoom(newRoom); } } } } return(newRoom); }
public void Sim1000ms(float dt) { int num = versionCounter++; int num2 = 1; cavityIdToCavityInfo.Clear(); cellToFishCount.Clear(); ListPool <FishInfo, FishOvercrowingManager> .PooledList pooledList = ListPool <FishInfo, FishOvercrowingManager> .Allocate(); foreach (FishOvercrowdingMonitor.Instance fish in fishes) { int num3 = Grid.PosToCell(fish); if (Grid.IsValidCell(num3)) { FishInfo fishInfo = default(FishInfo); fishInfo.cell = num3; fishInfo.fish = fish; FishInfo item = fishInfo; pooledList.Add(item); int value = 0; cellToFishCount.TryGetValue(num3, out value); value++; cellToFishCount[num3] = value; } } foreach (FishInfo item2 in pooledList) { FishInfo current2 = item2; ListPool <int, FishOvercrowingManager> .PooledList pooledList2 = ListPool <int, FishOvercrowingManager> .Allocate(); pooledList2.Add(current2.cell); int num4 = 0; int num6 = num2++; while (num4 < pooledList2.Count) { int num8 = pooledList2[num4++]; if (Grid.IsValidCell(num8)) { Cell cell = cells[num8]; if (cell.version != num && Grid.IsLiquid(num8)) { cell.cavityId = num6; cell.version = num; int value2 = 0; cellToFishCount.TryGetValue(num8, out value2); CavityInfo value3 = default(CavityInfo); if (!cavityIdToCavityInfo.TryGetValue(num6, out value3)) { value3 = default(CavityInfo); } value3.fishCount += value2; value3.cellCount++; cavityIdToCavityInfo[num6] = value3; pooledList2.Add(Grid.CellLeft(num8)); pooledList2.Add(Grid.CellRight(num8)); pooledList2.Add(Grid.CellAbove(num8)); pooledList2.Add(Grid.CellBelow(num8)); cells[num8] = cell; } } } pooledList2.Recycle(); } foreach (FishInfo item3 in pooledList) { FishInfo current3 = item3; Cell cell2 = cells[current3.cell]; CavityInfo value4 = default(CavityInfo); cavityIdToCavityInfo.TryGetValue(cell2.cavityId, out value4); current3.fish.SetOvercrowdingInfo(value4.cellCount, value4.fishCount); } pooledList.Recycle(); }