コード例 #1
0
        internal static Group TryCreateGroup(MapCompGrowthSync mapComp, Plant crop, bool flashcells = false)
        {
            if (!flashcells && GroupsUtils.HasGroup(crop))
            {
                return(null);
            }

            var list = new HashSet <Plant>();

            try
            {
                if (!GroupsUtils.HasGroup(crop))
                {
                    Iterate(mapComp, crop, list, crop.Growth, crop.Growth, flashcells, IntVec3.Invalid);
                }
            }
            catch (Exception ex)
            {
                Log.Warning("failed to create group from crop " + crop + " at " + crop.Position + " : " + ex.Message + ". " + ex.StackTrace);
                return(null);
            }

            if (flashcells || list.Count <= 0)
            {
                return(null);
            }

            return(new Group(list));
        }
コード例 #2
0
        public static void ZoneMode(MapCompGrowthSync mapComp)
        {
            foreach (Zone zone in mapComp.map.zoneManager.AllZones)
            {
                if (zone is Zone_Growing zoneGrowing)
                {
                    ThingDef plantDef = zoneGrowing.GetPlantDefToGrow();

                    IEnumerable <Thing> allContainedThings = zoneGrowing.AllContainedThings;
                    List <Plant>        plantList          = new List <Plant>();

                    float max_grown = 0;
                    foreach (Thing thing in allContainedThings)
                    {
                        if (thing is Plant plant)
                        {
                            if (/*plant.IsCrop && */ plant.def == plantDef && plant.LifeStage == PlantLifeStage.Growing)
                            {
                                plantList.Add(plant);
                                max_grown = Math.Max(plant.Growth, max_grown);
                            }
                        }
                    }

                    if (plantList.NullOrEmpty())
                    {
                        break;
                    }

                    if (Settings.max_gap < 1)
                    {
                        plantList.RemoveAll(p => p.Growth < max_grown - Settings.max_gap);
                    }

                    mapComp.allPlantsInGroup.AddRange(plantList);
                    var group = new Group(plantList);

                    mapComp.groups.Add(group);
                }
            }

            // TODO: find all plantable edifices and run old handler on them? Or just recommend HydroponicsGrowthSync?
        }
コード例 #3
0
        static void Iterate(MapCompGrowthSync mapComp, Plant crop, ICollection <Plant> list, float minGrowth, float maxGrowth, bool flashcells, IntVec3 previous)
        {
            if (!CanHaveGroup(crop, flashcells) || list.Contains(crop))
            {
                return;
            }

            if (Settings.draw_overlay && flashcells)
            {
                var count = crop.Map.GetComponent <MapCompGrowthSync>().Count;
                crop.Map.debugDrawer.FlashCell(crop.Position, list.Count * 10000000, "#" + list.Count, 300);
            }

            list.Add(crop);
            mapComp.allPlantsInGroup.Add(crop);

            foreach (IntVec3 cell in CellsAdjacent4Way(crop.Position))
            {
                if (cell == previous || !cell.InBounds(crop.Map))
                {
                    continue;
                }
                Plant plantAtCell = cell.GetPlant(crop.Map);

                if (plantAtCell != null && CanGroupTogether(crop, plantAtCell))
                {
                    if (Math.Max(plantAtCell.Growth, maxGrowth) - Math.Min(plantAtCell.Growth, minGrowth) > Settings.max_gap)
                    {
                        if (Settings.draw_overlay && flashcells)
                        {
                            crop.Map.debugDrawer.FlashCell(crop.Position, float.MinValue, "max gap", 300);
                        }

                        continue;
                    }

                    maxGrowth = Math.Max(plantAtCell.Growth, maxGrowth);
                    minGrowth = Math.Min(plantAtCell.Growth, minGrowth);
                    Iterate(mapComp, plantAtCell, list, minGrowth, maxGrowth, flashcells, crop.Position);
                }
            }
        }