Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Languages/English/Keyed/Manager_Keyed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,12 @@
<FML.TrainYoung>Train young animals</FML.TrainYoung>
<FML.SendToSlaughterArea>Restrict animals marked for slaughter</FML.SendToSlaughterArea>
<FML.SendToSlaughterArea.Tip>Restrict animals designated for slaughtering to a specific area</FML.SendToSlaughterArea.Tip>
<FML.SendToHungryArea>Restrict animals that are hungry</FML.SendToHungryArea>
<FML.SendToHungryArea.Tip>Restrict animals that are hungry to a specific area</FML.SendToHungryArea.Tip>
<FML.SendToMilkingArea>Restrict animals ready to be milked</FML.SendToMilkingArea>
<FML.SendToMilkingArea.Tip>Restrict animals with milk fullness above 94% to a specific area.</FML.SendToMilkingArea.Tip>
<FML.SendToMilkingArea.Tip>Restrict animals ready to be milked to a specific area.</FML.SendToMilkingArea.Tip>

@maarxx maarxx Nov 30, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to the PR, but a minor text inaccuracy from a previous contribution, so I fix it here.

<FML.SendToShearingArea>Restrict animals ready to be sheared</FML.SendToShearingArea>
<FML.SendToShearingArea.Tip>Restrict animals with shearing fullness above 94% to a specific area</FML.SendToShearingArea.Tip>
<FML.SendToShearingArea.Tip>Restrict animals ready to be sheared to a specific area</FML.SendToShearingArea.Tip>

@maarxx maarxx Nov 30, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to the PR, but a minor text inaccuracy from a previous contribution, so I fix it here.

<FM.Livestock.TargetCountsHeader>Target counts</FM.Livestock.TargetCountsHeader>
<FM.Livestock.AreaRestrictionsHeader>Area restrictions</FM.Livestock.AreaRestrictionsHeader>
<FM.Livestock.TrainingHeader>Training</FM.Livestock.TrainingHeader>
Expand Down
7 changes: 7 additions & 0 deletions Source/Helpers/Livestock/Utilities_Livestock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Hediff_Pregnant>().Any( hp => hp.Visible ) ?? false;
Expand Down
19 changes: 19 additions & 0 deletions Source/ManagerJobs/ManagerJob_Livestock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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<CompMilkable>() != null &&
Expand Down
18 changes: 18 additions & 0 deletions Source/ManagerTabs/ManagerTab_Livestock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down