示例#1
0
        public static VehicleRoom FloodAndSetRooms(VehicleRegion root, Map map, VehicleRoom existingRoom)
        {
            VehicleRoom floodingRoom;

            if (existingRoom == null)
            {
                floodingRoom = VehicleRoom.MakeNew(map);
            }
            else
            {
                floodingRoom = existingRoom;
            }
            root.Room = floodingRoom;
            if (!root.type.AllowsMultipleRegionsPerRoom())
            {
                return(floodingRoom);
            }
            bool entryCondition(VehicleRegion from, VehicleRegion r) => r.type == root.type && r.Room != floodingRoom;

            bool regionProcessor(VehicleRegion r)
            {
                r.Room = floodingRoom;
                return(false);
            }

            BreadthFirstTraverse(root, entryCondition, regionProcessor, 999999, RegionType.Set_All);
            return(floodingRoom);
        }
 private void CreateOrAttachToExistingRooms(int numRegionGroups)
 {
     for (int i = 0; i < numRegionGroups; i++)
     {
         currentRegionGroup.Clear();
         for (int j = 0; j < newRegions.Count; j++)
         {
             if (newRegions[j].newRegionGroupIndex == i)
             {
                 currentRegionGroup.Add(newRegions[j]);
             }
         }
         if (!currentRegionGroup[0].type.AllowsMultipleRegionsPerRoom())
         {
             if (currentRegionGroup.Count != 1)
             {
                 Log.Error("Region type doesn't allow multiple regions per room but there are >1 regions in this group.");
             }
             VehicleRoom room = VehicleRoom.MakeNew(map);
             currentRegionGroup[0].Room = room;
             newRooms.Add(room);
         }
         else
         {
             VehicleRoom room2 = FindCurrentRegionGroupNeighborWithMostRegions(out bool flag);
             if (room2 is null)
             {
                 VehicleRoom item = WaterRegionTraverser.FloodAndSetRooms(currentRegionGroup[0], map, null);
                 newRooms.Add(item);
             }
             else if (!flag)
             {
                 for (int k = 0; k < currentRegionGroup.Count; k++)
                 {
                     currentRegionGroup[k].Room = room2;
                 }
                 reusedOldRooms.Add(room2);
             }
             else
             {
                 WaterRegionTraverser.FloodAndSetRooms(currentRegionGroup[0], map, room2);
                 reusedOldRooms.Add(room2);
             }
         }
     }
 }