示例#1
0
            public static void Prefix(ICollection <int> visited_cells, KCompactedVector <CavityInfo> ___cavityInfos, HandleVector <int> .Handle[] ___CellCavityID)
            {
                int maxRoomSize = TuningData <RoomProber.Tuning> .Get().maxRoomSize;

                foreach (int current in visited_cells)
                {
                    HandleVector <int> .Handle handle = ___CellCavityID [current];
                    if (handle.IsValid())
                    {
                        CavityInfo data = ___cavityInfos.GetData(handle);
                        if (0 < data.numCells && data.numCells <= maxRoomSize)
                        {
                            GameObject gameObject = Grid.Objects [current, (int)ObjectLayer.Plants];
                            if (gameObject != null)
                            {
                                KPrefabID component = gameObject.GetComponent <KPrefabID> ();
                                bool      flag2     = false;
                                foreach (KPrefabID current2 in data.buildings)
                                {
                                    if (component.InstanceID == current2.InstanceID)
                                    {
                                        flag2 = true;
                                        break;
                                    }
                                }
                                foreach (KPrefabID current3 in data.plants)
                                {
                                    if (component.InstanceID == current3.InstanceID)
                                    {
                                        flag2 = true;
                                        break;
                                    }
                                }
                                if (!flag2)
                                {
                                    if (component.GetComponent <Deconstructable> ())
                                    {
                                        data.AddBuilding(component);
                                    }
                                    else
                                    {
                                        if (component.HasTag(GameTags.Plant) && !component.HasTag("ForestTreeBranch".ToTag()))
                                        {
                                            data.AddPlants(component);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
    private void RebuildDirtyCavities(ICollection <int> visited_cells)
    {
        int maxRoomSize = TuningData <Tuning> .Get().maxRoomSize;

        foreach (int visited_cell in visited_cells)
        {
            HandleVector <int> .Handle handle = CellCavityID[visited_cell];
            if (handle.IsValid())
            {
                CavityInfo data = cavityInfos.GetData(handle);
                if (0 < data.numCells && data.numCells <= maxRoomSize)
                {
                    GameObject gameObject = Grid.Objects[visited_cell, 1];
                    if ((UnityEngine.Object)gameObject != (UnityEngine.Object)null)
                    {
                        KPrefabID component = gameObject.GetComponent <KPrefabID>();
                        bool      flag      = false;
                        foreach (KPrefabID building in data.buildings)
                        {
                            if (component.InstanceID == building.InstanceID)
                            {
                                flag = true;
                                break;
                            }
                        }
                        foreach (KPrefabID plant in data.plants)
                        {
                            if (component.InstanceID == plant.InstanceID)
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            if ((bool)component.GetComponent <Deconstructable>())
                            {
                                data.AddBuilding(component);
                            }
                            else if (component.HasTag(GameTags.Plant) && !component.HasTag("ForestTreeBranch".ToTag()))
                            {
                                data.AddPlants(component);
                            }
                        }
                    }
                }
            }
        }
        visited_cells.Clear();
    }
        /// <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;
            }
        }