Skip to content

Commit

Permalink
option to downgrade breeding score if fully leveled offspring exceeds…
Browse files Browse the repository at this point in the history
… limit
  • Loading branch information
cadon committed Nov 23, 2021
1 parent 4498b3e commit 3caf68f
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 11 deletions.
3 changes: 3 additions & 0 deletions ARKBreedingStats/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@
<setting name="RaisingFoodLastSelected" serializeAs="String">
<value />
</setting>
<setting name="BreedingPlanDontSuggestOverLimitOffspring" serializeAs="String">
<value>False</value>
</setting>
</ARKBreedingStats.Properties.Settings>
</userSettings>
</configuration>
24 changes: 19 additions & 5 deletions ARKBreedingStats/BreedingPlanning/BreedingPlan.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 31 additions & 3 deletions ARKBreedingStats/BreedingPlanning/BreedingPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Threading;
using ARKBreedingStats.Ark;
Expand Down Expand Up @@ -104,6 +105,7 @@ public BreedingPlan()
cbBPOnlyOneSuggestionForFemales.Checked = Settings.Default.BreedingPlanOnlyBestSuggestionForEachFemale;
cbBPMutationLimitOnlyOnePartner.Checked = Settings.Default.BreedingPlanOnePartnerMoreMutationsThanLimit;
CbConsiderOnlyEvenForHighStats.Checked = Settings.Default.BreedingPlannerConsiderOnlyEvenForHighStats;
CbDontSuggestOverLimitOffspring.Checked = Settings.Default.BreedingPlanDontSuggestOverLimitOffspring;

tagSelectorList1.OnTagChanged += TagSelectorList1_OnTagChanged;

Expand Down Expand Up @@ -384,10 +386,13 @@ private void DoCalculateBreedingScoresAndDisplayPairs()

short[] bestPossLevels = new short[Values.STATS_COUNT]; // best possible levels

var levelLimitWithOutDomLevels = (CreatureCollection.CurrentCreatureCollection?.maxServerLevel ?? 0) - (CreatureCollection.CurrentCreatureCollection?.maxDomLevel ?? 0);
if (levelLimitWithOutDomLevels < 0) levelLimitWithOutDomLevels = 0;

_breedingPairs = BreedingScore.CalculateBreedingScores(selectedFemales, selectedMales, _currentSpecies,
bestPossLevels, _statWeights, _bestLevels, _breedingMode,
considerChosenCreature, considerMutationLimit, (int)nudBPMutationLimit.Value,
ref creaturesMutationsFilteredOut);
ref creaturesMutationsFilteredOut, levelLimitWithOutDomLevels, CbDontSuggestOverLimitOffspring.Checked);

if (cbBPOnlyOneSuggestionForFemales.Checked)
{
Expand All @@ -408,6 +413,7 @@ private void DoCalculateBreedingScoresAndDisplayPairs()
bp.BreedingScore -= minScore;
}

var sb = new StringBuilder();
// draw best parents
using (var brush = new SolidBrush(Color.Black))
{
Expand Down Expand Up @@ -467,30 +473,46 @@ private void DoCalculateBreedingScoresAndDisplayPairs()
_pcs.Add(pc);
}

sb.Clear();

Bitmap bm = new Bitmap(pb.Width, pb.Height);
using (Graphics g = Graphics.FromImage(bm))
{
g.TextRenderingHint = TextRenderingHint.AntiAlias;
brush.Color = Utils.MutationColor;
if (_breedingPairs[i].Female.Mutations < GameConstants.MutationPossibleWithLessThan)
{
g.FillRectangle(brush, 0, 5, 10, 10);
sb.AppendLine(_breedingPairs[i].Female + " can produce a mutation.");
}
if (_breedingPairs[i].Male.Mutations < GameConstants.MutationPossibleWithLessThan)
{
g.FillRectangle(brush, 77, 5, 10, 10);
sb.AppendLine(_breedingPairs[i].Male + " can produce a mutation.");
}
// outline
brush.Color =
Utils.GetColorFromPercent((int)(_breedingPairs[i].BreedingScore * 12.5), -.2);
brush.Color = Utils.GetColorFromPercent((int)(_breedingPairs[i].BreedingScore * 12.5), -.2);
g.FillRectangle(brush, 0, 15, 87, 5);
g.FillRectangle(brush, 20, 10, 47, 15);
// fill
brush.Color =
Utils.GetColorFromPercent((int)(_breedingPairs[i].BreedingScore * 12.5), 0.5);
g.FillRectangle(brush, 1, 16, 85, 3);
g.FillRectangle(brush, 21, 11, 45, 13);
if (_breedingPairs[i].HighestOffspringOverLevelLimit)
{
brush.Color = Color.Red;
g.FillRectangle(brush, 15, 26, 55, 3);
sb.AppendLine("The highest possible and fully leveled offspring is over the level limit!");
}
// breeding score text
brush.Color = Color.Black;
g.DrawString(_breedingPairs[i].BreedingScore.ToString("N4"),
new Font("Microsoft Sans Serif", 8.25f), brush, 24, 12);
pb.Image = bm;
}

_tt.SetToolTip(pb, sb.Length > 0 ? sb.ToString() : null);
}
}

Expand Down Expand Up @@ -1153,5 +1175,11 @@ private void CbConsiderOnlyEvenForHighStats_CheckedChanged(object sender, EventA
Settings.Default.BreedingPlannerConsiderOnlyEvenForHighStats = CbConsiderOnlyEvenForHighStats.Checked;
CalculateBreedingScoresAndDisplayPairs();
}

private void CbDontSuggestOverLimitOffspring_CheckedChanged(object sender, EventArgs e)
{
Settings.Default.BreedingPlanDontSuggestOverLimitOffspring = CbDontSuggestOverLimitOffspring.Checked;
CalculateBreedingScoresAndDisplayPairs();
}
}
}
31 changes: 29 additions & 2 deletions ARKBreedingStats/BreedingPlanning/BreedingScore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,27 @@ namespace ARKBreedingStats.BreedingPlanning
/// </summary>
public static class BreedingScore
{
/// <summary>
/// Calculates the breeding score of all possible pairs.
/// </summary>
/// <param name="females"></param>
/// <param name="males"></param>
/// <param name="species"></param>
/// <param name="bestPossLevels"></param>
/// <param name="statWeights"></param>
/// <param name="bestLevels"></param>
/// <param name="breedingMode"></param>
/// <param name="considerChosenCreature"></param>
/// <param name="considerMutationLimit"></param>
/// <param name="mutationLimit"></param>
/// <param name="creaturesMutationsFilteredOut"></param>
/// <param name="offspringLevelLimit">If &gt; 0, pairs that can result in a creature with a level higher than that, are highlighted. This can be used if there's a level cap.</param>
/// <param name="downGradeOffspringWithLevelHigherThanLimit">Downgrade score if level is higher than limit.</param>
/// <returns></returns>
public static List<BreedingPair> CalculateBreedingScores(Creature[] females, Creature[] males, Species species,
short[] bestPossLevels, double[] statWeights, int[] bestLevels, BreedingPlan.BreedingMode breedingMode,
bool considerChosenCreature, bool considerMutationLimit, int mutationLimit,
ref bool creaturesMutationsFilteredOut)
ref bool creaturesMutationsFilteredOut, int offspringLevelLimit = 0, bool downGradeOffspringWithLevelHigherThanLimit = false)
{
var breedingPairs = new List<BreedingPair>();
var ignoreSex = Properties.Settings.Default.IgnoreSexInBreedingPlan || species.noGender;
Expand Down Expand Up @@ -53,6 +70,8 @@ public static List<BreedingPair> CalculateBreedingScores(Creature[] females, Cre
int topFemale = 0;
int topMale = 0;

int maxPossibleOffspringLevel = 1;

for (int s = 0; s < Values.STATS_COUNT; s++)
{
if (s == (int)StatNames.Torpidity || !species.UsesStat(s)) continue;
Expand All @@ -61,6 +80,7 @@ public static List<BreedingPair> CalculateBreedingScores(Creature[] females, Cre
int lowerLevel = Math.Min(female.levelsWild[s], male.levelsWild[s]);
if (higherLevel < 0) higherLevel = 0;
if (lowerLevel < 0) lowerLevel = 0;
maxPossibleOffspringLevel += higherLevel;

bool ignoreTopStats = Settings.Default.BreedingPlannerConsiderOnlyEvenForHighStats
&& higherLevel % 2 != 0
Expand Down Expand Up @@ -154,11 +174,18 @@ public static List<BreedingPair> CalculateBreedingScores(Creature[] females, Cre
//t *= 2; // scale conservative mode as it rather displays improvement, but only scarcely
}

var highestOffspringOverLevelLimit =
offspringLevelLimit > 0 && offspringLevelLimit < maxPossibleOffspringLevel;
if (highestOffspringOverLevelLimit && downGradeOffspringWithLevelHigherThanLimit)
t *= 0.01;

int mutationPossibleFrom = female.Mutations < GameConstants.MutationPossibleWithLessThan && male.Mutations < GameConstants.MutationPossibleWithLessThan ? 2
: female.Mutations < GameConstants.MutationPossibleWithLessThan || male.Mutations < GameConstants.MutationPossibleWithLessThan ? 1 : 0;

breedingPairs.Add(new BreedingPair(female, male, t * 1.25, (mutationPossibleFrom == 2 ? GameConstants.ProbabilityOfOneMutation : mutationPossibleFrom == 1 ? GameConstants.ProbabilityOfOneMutationFromOneParent : 0)));
breedingPairs.Add(new BreedingPair(female, male,
t * 1.25,
(mutationPossibleFrom == 2 ? GameConstants.ProbabilityOfOneMutation : mutationPossibleFrom == 1 ? GameConstants.ProbabilityOfOneMutationFromOneParent : 0),
highestOffspringOverLevelLimit));
}
}

Expand Down
12 changes: 12 additions & 0 deletions ARKBreedingStats/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ARKBreedingStats/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -500,5 +500,8 @@
<Setting Name="RaisingFoodLastSelected" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="BreedingPlanDontSuggestOverLimitOffspring" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
7 changes: 6 additions & 1 deletion ARKBreedingStats/species/BreedingPair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ public class BreedingPair
/// Probability of at least one mutation for the offspring.
/// </summary>
public double MutationProbability;
/// <summary>
/// The highest possible offspring is over the level limit if all possible dom levels are applied (server setting).
/// </summary>
public bool HighestOffspringOverLevelLimit;

public BreedingPair(Creature female, Creature male, double breedingScore, double mutationProbability)
public BreedingPair(Creature female, Creature male, double breedingScore, double mutationProbability, bool highestOffspringOverLevelLimit)
{
Female = female;
Male = male;
BreedingScore = breedingScore;
MutationProbability = mutationProbability;
HighestOffspringOverLevelLimit = highestOffspringOverLevelLimit;
}
}
}

0 comments on commit 3caf68f

Please sign in to comment.