diff --git a/Languages/English/Keyed/Manager_Keyed.xml b/Languages/English/Keyed/Manager_Keyed.xml index 85337429..75cfe0ef 100644 --- a/Languages/English/Keyed/Manager_Keyed.xml +++ b/Languages/English/Keyed/Manager_Keyed.xml @@ -194,10 +194,12 @@ Train young animals Restrict animals marked for slaughter Restrict animals designated for slaughtering to a specific area + Restrict animals that are hungry + Restrict animals that are hungry to a specific area Restrict animals ready to be milked - Restrict animals with milk fullness above 94% to a specific area. + Restrict animals ready to be milked to a specific area. Restrict animals ready to be sheared - Restrict animals with shearing fullness above 94% to a specific area + Restrict animals ready to be sheared to a specific area Target counts Area restrictions Training diff --git a/Source/Helpers/Livestock/Utilities_Livestock.cs b/Source/Helpers/Livestock/Utilities_Livestock.cs index feef068e..c6d1c9f0 100644 --- a/Source/Helpers/Livestock/Utilities_Livestock.cs +++ b/Source/Helpers/Livestock/Utilities_Livestock.cs @@ -399,6 +399,13 @@ public static int TicksTillHarvestable( this CompHasGatherableBodyResource comp return Mathf.CeilToInt( ( 1 - comp.Fullness ) / growthRatePerTick ); } + public static int TicksUntilStarving( this Pawn pawn ) + { + // this isn't perfect. we assume this is linear when it isn't. the real calculation is more complicated. + // check out "Need_Food.FoodFallPerTickAssumingCategory(...)" for more details + return Mathf.CeilToInt(pawn.needs.food.CurLevel / pawn.needs.food.FoodFallPerTick); + } + public static bool VisiblyPregnant( this Pawn pawn ) { return pawn?.health.hediffSet.GetHediffs().Any( hp => hp.Visible ) ?? false; diff --git a/Source/ManagerJobs/ManagerJob_Livestock.cs b/Source/ManagerJobs/ManagerJob_Livestock.cs index ca73a189..e41a807e 100644 --- a/Source/ManagerJobs/ManagerJob_Livestock.cs +++ b/Source/ManagerJobs/ManagerJob_Livestock.cs @@ -32,11 +32,13 @@ public class ManagerJob_Livestock : ManagerJob public bool SendToMilkingArea; public bool SendToShearingArea; public bool SendToSlaughterArea; + public bool SendToHungryArea; public bool SendToTrainingArea; public bool SetFollow; public Area ShearArea; public Area SlaughterArea; public Area TameArea; + public Area HungryArea; public Pawn Trainer; public MasterMode Trainers; public TrainingTracker Training; @@ -91,6 +93,10 @@ public ManagerJob_Livestock( Manager manager ) : base( manager ) SendToTrainingArea = false; TrainingArea = null; + // set up hungry area + SendToHungryArea = false; + HungryArea = null; + // taming TryTameMore = false; TameArea = null; @@ -310,6 +316,7 @@ public override void ExposeData() Scribe_References.Look( ref MilkArea, "MilkArea" ); Scribe_References.Look( ref ShearArea, "ShearArea" ); Scribe_References.Look( ref TrainingArea, "TrainingArea" ); + Scribe_References.Look( ref HungryArea, "HungryArea" ); Scribe_References.Look( ref Master, "Master" ); Scribe_References.Look( ref Trainer, "Trainer" ); Scribe_Collections.Look( ref RestrictArea, "AreaRestrictions", LookMode.Reference ); @@ -325,6 +332,7 @@ public override void ExposeData() Scribe_Values.Look( ref SendToMilkingArea, "SendToMilkingArea" ); Scribe_Values.Look( ref SendToShearingArea, "SendToShearingArea" ); Scribe_Values.Look( ref SendToTrainingArea, "SendToTrainingArea" ); + Scribe_Values.Look( ref SendToHungryArea, "SendToHungryArea"); Scribe_Values.Look( ref TryTameMore, "TryTameMore" ); Scribe_Values.Look( ref SetFollow, "SetFollow", true ); Scribe_Values.Look( ref FollowDrafted, "FollowDrafted", true ); @@ -510,6 +518,17 @@ private void DoAreaRestrictions( ref bool actionTaken ) p.playerSettings.AreaRestriction = SlaughterArea; } + // hungry + else if ( SendToHungryArea && + p.TicksUntilStarving() < UpdateInterval.ticks ) + { + if (p.playerSettings.AreaRestriction != HungryArea) + { + actionTaken = true; + p.playerSettings.AreaRestriction = HungryArea; + } + } + // milking else if ( SendToMilkingArea && p.GetComp() != null && diff --git a/Source/ManagerTabs/ManagerTab_Livestock.cs b/Source/ManagerTabs/ManagerTab_Livestock.cs index 597a1c26..94acc4d5 100644 --- a/Source/ManagerTabs/ManagerTab_Livestock.cs +++ b/Source/ManagerTabs/ManagerTab_Livestock.cs @@ -539,6 +539,24 @@ private float DrawAreaRestrictionsSection( Vector2 pos, float width ) color: Color.grey ); } + if (_selectedCurrent.Trigger.pawnKind.RaceProps.EatsFood) + { + var sendToHungryAreaRect = new Rect(pos.x, pos.y, width, ListEntryHeight); + pos.y += ListEntryHeight; + DrawToggle(sendToHungryAreaRect, + "FML.SendToHungryArea".Translate(), + "FML.SendToHungryArea.Tip".Translate(), + ref _selectedCurrent.SendToHungryArea); + + if (_selectedCurrent.SendToHungryArea) + { + var hungryAreaRect = new Rect(pos.x, pos.y, width, ListEntryHeight); + AreaAllowedGUI.DoAllowedAreaSelectors(hungryAreaRect, ref _selectedCurrent.HungryArea, + manager); + pos.y += ListEntryHeight; + } + } + if ( _selectedCurrent.Trigger.pawnKind.Milkable() ) { var sendToMilkingAreaRect = new Rect( pos.x, pos.y, width, ListEntryHeight );