public static void get_IsTree_PostFix(PlantProperties __instance, ref bool __result) { if (__instance.harvestTag == "FungalLog") { __result = true; } }
//Thanks to XeoNovaDan public static void DisplayYieldInfo(PlantProperties __instance, ref IEnumerable <StatDrawEntry> __result) { ThingDef harvestedThingDef = Traverse.Create(__instance).Field("harvestedThingDef").GetValue <ThingDef>(); float harvestYield = Traverse.Create(__instance).Field("harvestYield").GetValue <float>(); if (harvestedThingDef == null) { return; } string harvestedThingDefLabel = harvestedThingDef.label; string extendedYieldInfo = string.Format("M4_HarvestYieldThingDetailInit".Translate(), harvestedThingDefLabel) + "\n\n"; float thingMarketValue = harvestedThingDef.GetStatValueAbstract(StatDefOf.MarketValue, null); extendedYieldInfo += StatDefOf.MarketValue.label.CapitalizeFirst() + ": " + thingMarketValue.ToString(); if (harvestedThingDef.IsNutritionGivingIngestible) { float thingNutrition = harvestedThingDef.GetStatValueAbstract(StatDefOf.Nutrition, null); FoodTypeFlags thingNutritionType = harvestedThingDef.ingestible.foodType; IDictionary <FoodTypeFlags, string> nutritionTypeToReportString = new Dictionary <FoodTypeFlags, string>() { { FoodTypeFlags.VegetableOrFruit, "FoodTypeFlags_VegetableOrFruit" }, { FoodTypeFlags.Meat, "FoodTypeFlags_Meat" }, { FoodTypeFlags.Seed, "FoodTypeFlags_Seed" } }; string nutritionTypeReportString = nutritionTypeToReportString.TryGetValue(thingNutritionType, out nutritionTypeReportString) ? nutritionTypeReportString : "StatsReport_OtherStats"; extendedYieldInfo += "\n" + StatDefOf.Nutrition.label.CapitalizeFirst() + ": " + thingNutrition.ToString() + " (" + nutritionTypeReportString.Translate() + ")"; } if (harvestYield > 0) { StatDrawEntry statDrawEntry = new StatDrawEntry(StatCategoryDefOf.Basics, "M4_HarvestYieldThing".Translate(), harvestedThingDef.label.CapitalizeFirst(), 0, extendedYieldInfo); __result = __result.Add(statDrawEntry); } }
/*public static string GetLeaflessGraphicPath(PlantProperties p) * { * return (string)typeof(PlantProperties).GetField("leaflessGraphicPath", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(p); * } * * public static void SetLeaflessGraphicPath(PlantProperties p, string s) * { * typeof(PlantProperties).GetField("leaflessGraphicPath", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(p, s); * } * * public static string GetImmatureGraphicPath(PlantProperties p) * { * return (string)typeof(PlantProperties).GetField("immatureGraphicPath", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(p); * } * * public static void SetImmatureGraphicPath(PlantProperties p, string s) * { * typeof(PlantProperties).GetField("immatureGraphicPath", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(p, s); * }*/ public void ApplyStats(PlantProperties to) { to.wildClusterRadius = this.wildClusterRadius; to.wildClusterWeight = this.wildClusterWeight; to.wildOrder = this.wildOrder; to.wildEqualLocalDistribution = this.wildEqualLocalDistribution; to.cavePlant = this.cavePlant; to.cavePlantWeight = this.cavePlantWeight; to.sowWork = this.sowWork; to.sowMinSkill = this.sowMinSkill; to.blockAdjacentSow = this.blockAdjacentSow; to.mustBeWildToSow = this.mustBeWildToSow; to.harvestWork = this.harvestWork; to.harvestYield = this.harvestYield; to.harvestTag = this.harvestTag; to.harvestMinGrowth = this.harvestMinGrowth; to.harvestAfterGrowth = this.harvestAfterGrowth; to.harvestFailable = this.harvestFailable; to.growDays = this.growDays; to.lifespanDaysPerGrowDays = this.lifespanDaysPerGrowDays; to.growMinGlow = this.growMinGlow; to.growOptimalGlow = this.growOptimalGlow; to.fertilityMin = this.fertilityMin; to.fertilitySensitivity = this.fertilitySensitivity; to.dieIfLeafless = this.dieIfLeafless; to.neverBlightable = this.neverBlightable; to.interferesWithRoof = this.interferesWithRoof; to.purpose = this.purpose; to.topWindExposure = this.topWindExposure; to.maxMeshCount = this.maxMeshCount; //to.leaflessGraphicPath = GetLeaflessGraphicPath(p); //to.immatureGraphicPath = GetImmatureGraphicPath(p); to.dropLeaves = this.dropLeaves; to.dieFromToxicFallout = this.dieFromToxicFallout; to.autoHarvestable = this.autoHarvestable; to.humanFoodPlant = this.humanFoodPlant; to.treeLoversCareIfChopped = this.treeLoversCareIfChopped; to.allowAutoCut = this.allowAutoCut; to.dieIfNoSunlight = this.dieIfNoSunlight; to.treeCategory = this.treeCategory; to.showGrowthInInspectPane = this.showGrowthInInspectPane; to.minSpacingBetweenSamePlant = this.minSpacingBetweenSamePlant; if (this.visualSizeRange != null) { to.visualSizeRange = this.visualSizeRange.ToFloatRange(); } Util.AssignDef(this.harvestedThingDef, out to.harvestedThingDef); //Util.AssignDef(this.soundHarvesting, out to.soundHarvesting); //Util.AssignDef(this.soundHarvestFinish, out to.soundHarvestFinish); Util.AssignDef(this.burnedThingDef, out to.burnedThingDef); Util.Populate(out to.sowTags, this.sowTags); Util.Populate(out to.wildBiomes, this.wildBiomes, (v) => new PlantBiomeRecord() { biome = v.Def, commonality = v.value }); Util.Populate(out to.sowResearchPrerequisites, this.sowResearchPrerequisites, (v) => v.Def, false); }
public static bool SkyfallerCanLandAt(IntVec3 c, Map map, IntVec2 size, Faction faction = null) { if (!IsSafeDropSpot(c, map, faction, size, 5)) { return(false); } foreach (IntVec3 item in GenAdj.OccupiedRect(c, Rot4.North, size)) { List <Thing> thingList = item.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (thing is IActiveDropPod || thing is Skyfaller) { return(false); } PlantProperties plant = thing.def.plant; if (plant != null && plant.IsTree) { return(false); } if (thing.def.preventSkyfallersLandingOn) { return(false); } if (thing.def.category == ThingCategory.Item || thing.def.category == ThingCategory.Building) { return(false); } } } return(true); }
public override void Tick() { base.Tick(); try { if (tickerInterval >= tickerMax) { HashSet <Thing> hashSet = new HashSet <Thing>(this.Position.GetThingList(this.Map)); if (hashSet != null) { foreach (Thing current in hashSet) { PlantProperties plant = current.def.plant; bool flag = (plant != null); if (flag) { if (plant.IsTree && (current.def.defName != "GU_AlienTree")) { Plant thing2 = (Plant)GenSpawn.Spawn(ThingDef.Named("GU_AlienTree"), this.Position, this.Map, WipeMode.Vanish); Plant thingToDestroy = (Plant)current; thing2.Growth = thingToDestroy.Growth; current.Destroy(); } else if (!plant.IsTree && (current.def.defName != "GU_AlienGrass") && (current.def.defName != "GU_RedLeaves") && (current.def.defName != "GU_RedPlantsTall")) { if (rand.NextDouble() < 0.4) { Plant thing2 = (Plant)GenSpawn.Spawn(ThingDef.Named("GU_AlienGrass"), this.Position, this.Map, WipeMode.Vanish); Plant thingToDestroy = (Plant)current; thing2.Growth = thingToDestroy.Growth; current.Destroy(); } else if (rand.NextDouble() > 0.4 && rand.NextDouble() < 0.7) { Plant thing2 = (Plant)GenSpawn.Spawn(ThingDef.Named("GU_RedLeaves"), this.Position, this.Map, WipeMode.Vanish); Plant thingToDestroy = (Plant)current; thing2.Growth = thingToDestroy.Growth; current.Destroy(); } else if (rand.NextDouble() > 0.7) { Plant thing2 = (Plant)GenSpawn.Spawn(ThingDef.Named("GU_RedPlantsTall"), this.Position, this.Map, WipeMode.Vanish); Plant thingToDestroy = (Plant)current; thing2.Growth = thingToDestroy.Growth; current.Destroy(); } } } } } tickerInterval = 0; } tickerInterval++; } catch (NullReferenceException e) { //A weird error is produced sometimes when GetThingList returns a NullReferenceException. I did a try-catch which is inellegant, but it works } }
public PlantPropertiesStats(PlantProperties p) { this.wildClusterRadius = p.wildClusterRadius; this.wildClusterWeight = p.wildClusterWeight; this.wildOrder = p.wildOrder; this.wildEqualLocalDistribution = p.wildEqualLocalDistribution; this.cavePlant = p.cavePlant; this.cavePlantWeight = p.cavePlantWeight; this.sowWork = p.sowWork; this.sowMinSkill = p.sowMinSkill; this.blockAdjacentSow = p.blockAdjacentSow; this.mustBeWildToSow = p.mustBeWildToSow; this.harvestWork = p.harvestWork; this.harvestYield = p.harvestYield; this.harvestTag = p.harvestTag; this.harvestMinGrowth = p.harvestMinGrowth; this.harvestAfterGrowth = p.harvestAfterGrowth; this.harvestFailable = p.harvestFailable; this.growDays = p.growDays; this.lifespanDaysPerGrowDays = p.lifespanDaysPerGrowDays; this.growMinGlow = p.growMinGlow; this.growOptimalGlow = p.growOptimalGlow; this.fertilityMin = p.fertilityMin; this.fertilitySensitivity = p.fertilitySensitivity; this.dieIfLeafless = p.dieIfLeafless; this.neverBlightable = p.neverBlightable; this.interferesWithRoof = p.interferesWithRoof; this.purpose = p.purpose; this.topWindExposure = p.topWindExposure; this.maxMeshCount = p.maxMeshCount; //this.leaflessGraphicPath = GetLeaflessGraphicPath(p); //this.immatureGraphicPath = GetImmatureGraphicPath(p); this.dropLeaves = p.dropLeaves; this.dieFromToxicFallout = p.dieFromToxicFallout; this.autoHarvestable = p.autoHarvestable; this.humanFoodPlant = p.humanFoodPlant; this.treeLoversCareIfChopped = p.treeLoversCareIfChopped; this.allowAutoCut = p.allowAutoCut; this.dieIfNoSunlight = p.dieIfNoSunlight; this.treeCategory = p.treeCategory; this.showGrowthInInspectPane = p.showGrowthInInspectPane; this.minSpacingBetweenSamePlant = p.minSpacingBetweenSamePlant; if (p.visualSizeRange != null) { this.visualSizeRange = new MinMaxFloatStats(p.visualSizeRange); } Util.AssignDefStat(p.harvestedThingDef, out this.harvestedThingDef); //Util.AssignDefStat(p.soundHarvesting, out this.soundHarvesting); //Util.AssignDefStat(p.soundHarvestFinish, out this.soundHarvestFinish); Util.AssignDefStat(p.burnedThingDef, out this.burnedThingDef); Util.Populate(out this.sowTags, p.sowTags); Util.Populate(out this.wildBiomes, p.wildBiomes, (v) => new FloatValueDefStat <BiomeDef>(v.biome, v.commonality)); this.sowResearchPrerequisites = Util.CreateDefStatList(p.sowResearchPrerequisites); }
public override void Apply(LocalTargetInfo target, LocalTargetInfo dest) { base.Apply(target, dest); FleckMaker.Static(target.Cell, this.parent.pawn.Map, DefDatabase <FleckDef> .GetNamed("PsycastPsychicEffect")); HashSet <Thing> hashSet = new HashSet <Thing>(target.Cell.GetThingList(this.parent.pawn.Map)); if (hashSet != null) { foreach (Thing current in hashSet) { Plant plantTarget = current as Plant; if (plantTarget != null) { PlantProperties plant = plantTarget.def.plant; bool flag = (plant != null); if (flag) { if (plant.IsTree && (plantTarget.def.defName != "GU_AlienTree") && (plantTarget.def.defName != "AA_AlienTree") && (plantTarget.def.defName != "Plant_TreeAnima") && (plantTarget.def.defName != "Plant_TreeGauranlen")) { Plant thing2 = (Plant)GenSpawn.Spawn(ThingDef.Named("AA_AlienTree"), plantTarget.Position, plantTarget.Map, WipeMode.Vanish); Plant thingToDestroy = (Plant)plantTarget; thing2.Growth = thingToDestroy.Growth; plantTarget.Destroy(); } else if (!plant.IsTree && (plantTarget.def.defName != "GU_AlienGrass") && (plantTarget.def.defName != "GU_RedLeaves") && (plantTarget.def.defName != "GU_RedPlantsTall") && (plantTarget.def.defName != "AA_AlienGrass") && (plantTarget.def.defName != "AA_RedLeaves") && (plantTarget.def.defName != "AA_RedPlantsTall") && (plantTarget.def.defName != "Plant_GrassAnima") ) { if (rand.NextDouble() < 0.4) { Plant thing2 = (Plant)GenSpawn.Spawn(ThingDef.Named("AA_AlienGrass"), plantTarget.Position, plantTarget.Map, WipeMode.Vanish); Plant thingToDestroy = (Plant)plantTarget; thing2.Growth = thingToDestroy.Growth; plantTarget.Destroy(); } else if (rand.NextDouble() > 0.4 && rand.NextDouble() < 0.7) { Plant thing2 = (Plant)GenSpawn.Spawn(ThingDef.Named("AA_RedLeaves"), plantTarget.Position, plantTarget.Map, WipeMode.Vanish); Plant thingToDestroy = (Plant)plantTarget; thing2.Growth = thingToDestroy.Growth; plantTarget.Destroy(); } else if (rand.NextDouble() > 0.7) { Plant thing2 = (Plant)GenSpawn.Spawn(ThingDef.Named("AA_RedPlantsTall"), plantTarget.Position, plantTarget.Map, WipeMode.Vanish); Plant thingToDestroy = (Plant)plantTarget; thing2.Growth = thingToDestroy.Growth; plantTarget.Destroy(); } } } } } } }
private static bool PlantMatchesModifierKeyFilter(PlantProperties props) { bool plantIsCrop() => props.harvestTag == "Standard"; bool plantIsTree() => props.harvestTag == "Wood"; bool shiftHeld = HugsLibUtility.ShiftIsHeld, controlHeld = HugsLibUtility.ControlIsHeld; return(!shiftHeld && !controlHeld || shiftHeld && plantIsCrop() || controlHeld && plantIsTree()); }
/// <summary> /// Checks if a given <paramref name="targetCell"/> on a <paramref name="map"/> is blocked /// </summary> /// <param name="targetCell"></param> /// <param name="map"></param> /// <returns>true if it is blocked, false otherwise</returns> public static bool CellBlockedByThing(this IntVec3 targetCell, Map map) { foreach (Thing thing in targetCell.GetThingList(map)) { if (thing is IActiveDropPod || thing is Skyfaller || thing.def.category == ThingCategory.Building || thing.def.category == ThingCategory.Item) { return(true); } PlantProperties plant = thing.def.plant; if (plant != null && plant.IsTree) { return(true); } } return(false); }
public static void SetImmatureGraphicPath(PlantProperties p, string s) { typeof(PlantProperties).GetField("immatureGraphicPath", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(p, s); }
public static string GetImmatureGraphicPath(PlantProperties p) { return((string)typeof(PlantProperties).GetField("immatureGraphicPath", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(p)); }
//private PlusMinusArgs<BiomeDef> wildBiomes; //private List<FloatInputWidget<PlantBiomeRecord>> wildBiomesWidgets; public PlantPropertiesWidget(PlantProperties parent) { this.Parent = parent; /*if (this.Parent.wildBiomes == null) * this.Parent.wildBiomes = new List<PlantBiomeRecord>(); * this.wildBiomesWidgets = new List<FloatInputWidget<PlantBiomeRecord>>(); * this.wildBiomes = new PlusMinusArgs<BiomeDef>() * { * allItems = DefDatabase<BiomeDef>.AllDefs, * beingUsed = () => * { * List<BiomeDef> l = new List<BiomeDef>(this.Parent.wildBiomes.Count); * foreach (var d in this.Parent.wildBiomes) * l.Add(d.biome); * return l; * }, * onAdd = (def) => { * var r = new PlantBiomeRecord() { biome = def, commonality = 0 }; * this.Parent.wildBiomes.Add(r); * wildBiomesWidgets.Add(new FloatInputWidget<PlantBiomeRecord>(r, r.biome.label, p => p.commonality, (p, f) => p.commonality = f)); * }, * onRemove = (def) => { * this.Parent.wildBiomes.RemoveAll(r => r.biome == def); * this.wildBiomesWidgets.RemoveAll(r => r.DisplayLabel == def.label); * }, * getDisplayName = (def) => def.label * };*/ this.inputWidgets = new List <IInputWidget>() { new IntInputWidget <PlantProperties>(this.Parent, "Wild Cluster Radius", p => p.wildClusterRadius, (p, i) => p.wildClusterRadius = i), new FloatInputWidget <PlantProperties>(this.Parent, "Wild Cluster Weight", p => p.wildClusterWeight, (p, f) => p.wildClusterWeight = f), new FloatInputWidget <PlantProperties>(this.Parent, "Wild Order", p => p.wildOrder, (p, f) => p.wildOrder = f), new BoolInputWidget <PlantProperties>(this.Parent, "Wild Equal Local Distribution", p => p.wildEqualLocalDistribution, (p, b) => p.wildEqualLocalDistribution = b), new BoolInputWidget <PlantProperties>(this.Parent, "Cave Plant", p => p.cavePlant, (p, b) => p.cavePlant = b), new FloatInputWidget <PlantProperties>(this.Parent, "Cave Plant Weight", p => p.cavePlantWeight, (p, f) => p.cavePlantWeight = f), new FloatInputWidget <PlantProperties>(this.Parent, "Sow Work", p => p.sowWork, (p, f) => p.sowWork = f), new IntInputWidget <PlantProperties>(this.Parent, "Sow Min Skill", p => p.sowMinSkill, (p, i) => p.sowMinSkill = i), new BoolInputWidget <PlantProperties>(this.Parent, "Block Adjacent Sow", p => p.blockAdjacentSow, (p, b) => p.blockAdjacentSow = b), new BoolInputWidget <PlantProperties>(this.Parent, "Must Be Wild To Sow", p => p.mustBeWildToSow, (p, b) => p.mustBeWildToSow = b), new FloatInputWidget <PlantProperties>(this.Parent, "Harvest Work", p => p.harvestWork, (p, f) => p.harvestWork = f), new FloatInputWidget <PlantProperties>(this.Parent, "Harvest Yield", p => p.harvestYield, (p, f) => p.harvestYield = f), new DefInputWidget <PlantProperties, ThingDef>(this.Parent, "Harvested ThingDef", 200, def => def.harvestedThingDef, (def, v) => def.harvestedThingDef = v, false), new FloatInputWidget <PlantProperties>(this.Parent, "Harvest Min Growth", p => p.harvestMinGrowth, (p, f) => p.harvestMinGrowth = f), new FloatInputWidget <PlantProperties>(this.Parent, "Harvest After Growth", p => p.harvestAfterGrowth, (p, f) => p.harvestAfterGrowth = f), new BoolInputWidget <PlantProperties>(this.Parent, "Harvest Failable", p => p.harvestFailable, (p, b) => p.harvestFailable = b), new DefInputWidget <PlantProperties, SoundDef>(this.Parent, "Sound Harvesting", 200, def => def.soundHarvesting, (def, v) => def.soundHarvesting = v, false), new DefInputWidget <PlantProperties, SoundDef>(this.Parent, "Sound Harvest Finish", 200, def => def.soundHarvestFinish, (def, v) => def.soundHarvestFinish = v, false), new BoolInputWidget <PlantProperties>(this.Parent, "Auto Harvestable", p => p.autoHarvestable, (p, b) => p.autoHarvestable = b), new FloatInputWidget <PlantProperties>(this.Parent, "Grow Days", p => p.growDays, (p, f) => p.growDays = f), new FloatInputWidget <PlantProperties>(this.Parent, "Lifespan Days Per Grow Days", p => p.lifespanDaysPerGrowDays, (p, f) => p.lifespanDaysPerGrowDays = f), new FloatInputWidget <PlantProperties>(this.Parent, "Grow Min Glow", p => p.growMinGlow, (p, f) => p.growMinGlow = f), new FloatInputWidget <PlantProperties>(this.Parent, "Grow Optimal Glow", p => p.growOptimalGlow, (p, f) => p.growOptimalGlow = f), new FloatInputWidget <PlantProperties>(this.Parent, "Fertility Min", p => p.fertilityMin, (p, f) => p.fertilityMin = f), new FloatInputWidget <PlantProperties>(this.Parent, "Fertility Sensitivity", p => p.fertilitySensitivity, (p, f) => p.fertilitySensitivity = f), new BoolInputWidget <PlantProperties>(this.Parent, "Die If Leafless", p => p.dieIfLeafless, (p, b) => p.dieIfLeafless = b), new BoolInputWidget <PlantProperties>(this.Parent, "Never Blightable", p => p.neverBlightable, (p, b) => p.neverBlightable = b), new BoolInputWidget <PlantProperties>(this.Parent, "Interferes With Roof", p => p.interferesWithRoof, (p, b) => p.interferesWithRoof = b), new BoolInputWidget <PlantProperties>(this.Parent, "Die If No Sunlight", p => p.dieIfNoSunlight, (p, b) => p.dieIfNoSunlight = b), new BoolInputWidget <PlantProperties>(this.Parent, "Die From Toxic Fallout", p => p.dieFromToxicFallout, (p, b) => p.dieFromToxicFallout = b), new EnumInputWidget <PlantProperties, PlantPurpose>(this.Parent, "Purpose", 200, p => p.purpose, (p, e) => p.purpose = e), new BoolInputWidget <PlantProperties>(this.Parent, "Human Food Plant", p => p.humanFoodPlant, (p, b) => p.humanFoodPlant = b), new BoolInputWidget <PlantProperties>(this.Parent, "Tree Lovers Care If Chopped", p => p.treeLoversCareIfChopped, (p, b) => p.treeLoversCareIfChopped = b), new BoolInputWidget <PlantProperties>(this.Parent, "Allow Auto Cut", p => p.allowAutoCut, (p, b) => p.allowAutoCut = b), new EnumInputWidget <PlantProperties, TreeCategory>(this.Parent, "Tree Category", 200, p => p.treeCategory, (p, e) => p.treeCategory = e), new DefInputWidget <PlantProperties, ThingDef>(this.Parent, "Burned ThingDef", 200, def => def.burnedThingDef, (def, v) => def.burnedThingDef = v, false), new BoolInputWidget <PlantProperties>(this.Parent, "Show Growth In Inspect Pane", p => p.showGrowthInInspectPane, (p, b) => p.showGrowthInInspectPane = b), new FloatInputWidget <PlantProperties>(this.Parent, "Min Spacing Between Same Plant", p => p.minSpacingBetweenSamePlant, (p, f) => p.minSpacingBetweenSamePlant = f), new FloatInputWidget <PlantProperties>(this.Parent, "Top Wind Exposure", p => p.topWindExposure, (p, f) => p.topWindExposure = f), new IntInputWidget <PlantProperties>(this.Parent, "Max Mesh Count", p => p.maxMeshCount, (p, i) => p.maxMeshCount = i), new BoolInputWidget <PlantProperties>(this.Parent, "Drop Leaves", p => p.dropLeaves, (p, b) => p.dropLeaves = b), }; this.ResetBuffers(); }