Skip to content

Commit

Permalink
prefilter creatures in breeding planner
Browse files Browse the repository at this point in the history
  • Loading branch information
cadon committed Feb 3, 2024
1 parent 9565d1a commit 8e4d97b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 28 deletions.
48 changes: 30 additions & 18 deletions ARKBreedingStats/BreedingPlanning/BreedingPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,23 @@ private void DoCalculateBreedingScoresAndDisplayPairs()
bool considerMutationLimit = nudBPMutationLimit.Value >= 0;

bool creaturesMutationsFilteredOut = false;

// only consider creatures with top stats if breeding for that
Creature[] females, males;
if (_breedingMode == BreedingMode.BestNextGen)
{
females = _females;
males = _males;
}
else
{
females = _females.Where(c => c.topStatsCountBP > 0).ToArray();
males = _males?.Where(c => c.topStatsCountBP > 0).ToArray();
}

// filter by tags
int crCountF = _females.Length;
int crCountM = _males?.Length ?? 0;
int crCountF = females.Length;
int crCountM = males?.Length ?? 0;
IEnumerable<Creature> selectFemales;
IEnumerable<Creature> selectMales = null;
if (considerChosenCreature && (_chosenCreature.sex == Sex.Female || _currentSpecies.noGender))
Expand All @@ -297,25 +311,25 @@ private void DoCalculateBreedingScoresAndDisplayPairs()
}
else if (!cbBPMutationLimitOnlyOnePartner.Checked && considerMutationLimit)
{
selectFemales = FilterByTags(_females.Where(c => c.Mutations <= nudBPMutationLimit.Value));
creaturesMutationsFilteredOut = _females.Any(c => c.Mutations > nudBPMutationLimit.Value);
selectFemales = FilterByTags(females.Where(c => c.Mutations <= nudBPMutationLimit.Value));
creaturesMutationsFilteredOut = females.Any(c => c.Mutations > nudBPMutationLimit.Value);
}
else selectFemales = FilterByTags(_females);
else selectFemales = FilterByTags(females);

if (considerChosenCreature && !_currentSpecies.noGender && _chosenCreature.sex == Sex.Male)
{
selectMales = new List<Creature>(); // the specific creature is added after the filtering
}
else if (!cbBPMutationLimitOnlyOnePartner.Checked && considerMutationLimit)
{
if (_males != null)
if (males != null)
{
selectMales = FilterByTags(_males.Where(c => c.Mutations <= nudBPMutationLimit.Value));
selectMales = FilterByTags(males.Where(c => c.Mutations <= nudBPMutationLimit.Value));
creaturesMutationsFilteredOut = creaturesMutationsFilteredOut ||
_males.Any(c => c.Mutations > nudBPMutationLimit.Value);
males.Any(c => c.Mutations > nudBPMutationLimit.Value);
}
}
else selectMales = FilterByTags(_males);
else selectMales = FilterByTags(males);

// filter by servers
if (cbServerFilterLibrary.Checked && (Settings.Default.FilterHideServers?.Any() ?? false))
Expand Down Expand Up @@ -401,18 +415,16 @@ private void DoCalculateBreedingScoresAndDisplayPairs()
ref creaturesMutationsFilteredOut, levelLimitWithOutDomLevels, CbDontSuggestOverLimitOffspring.Checked,
cbBPOnlyOneSuggestionForFemales.Checked, _statOddEvens);

//double minScore = _breedingPairs.LastOrDefault()?.BreedingScore ?? 0;
//if (minScore < 0)
//{
// foreach (BreedingPair bp in _breedingPairs)
// bp.BreedingScore -= minScore;
//}
double minScore = _breedingPairs.LastOrDefault()?.BreedingScore.OneNumber ?? 0;
var displayScoreOffset = (minScore < 0 ? -minScore : 0) + .5; // don't display negative scores, could be confusing

_breedingPairs = _breedingPairs.Take(CreatureCollection.maxBreedingSuggestions).ToList();

var sb = new StringBuilder();
// draw best parents
using (var brush = new SolidBrush(Color.Black))
{
for (int i = 0; i < _breedingPairs.Count && i < CreatureCollection.maxBreedingSuggestions; i++)
for (int i = 0; i < _breedingPairs.Count; i++)
{
PedigreeCreature pc;
if (2 * i < _pcs.Count)
Expand Down Expand Up @@ -486,7 +498,7 @@ private void DoCalculateBreedingScoresAndDisplayPairs()
sb.AppendLine(_breedingPairs[i].Father + " can produce a mutation.");
}

var colorPercent = (int)(_breedingPairs[i].BreedingScore.OneNumber * 12.5);
var colorPercent = (int)((_breedingPairs[i].BreedingScore.OneNumber + displayScoreOffset) * 12.5);
// outline
brush.Color = Utils.GetColorFromPercent(colorPercent, -.2);
g.FillRectangle(brush, 0, 15, 87, 5);
Expand All @@ -504,7 +516,7 @@ private void DoCalculateBreedingScoresAndDisplayPairs()
}
// breeding score text
brush.Color = Color.Black;
g.DrawString(_breedingPairs[i].BreedingScore.ToString("N4"),
g.DrawString((_breedingPairs[i].BreedingScore.Primary + displayScoreOffset).ToString("N4"),
new Font("Microsoft Sans Serif", 8.25f), brush, 24, 12);
pb.Image = bm;
}
Expand Down
6 changes: 3 additions & 3 deletions ARKBreedingStats/Form1.library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ private ListViewItem CreateCreatureLvItem(Creature cr, bool displayIndex = false
Utils.SexSymbol(cr.sex),
cr.domesticatedAt?.ToString("yyyy'-'MM'-'dd HH':'mm':'ss") ?? string.Empty,
(cr.topness / 10).ToString(),
cr.topStatsCount.ToString(),
cr.topStatsConsideredCount.ToString(),
cr.generation.ToString(),
cr.levelFound.ToString(),
cr.Mutations.ToString(),
Expand Down Expand Up @@ -1132,7 +1132,7 @@ private ListViewItem CreateCreatureLvItem(Creature cr, bool displayIndex = false
lvi.UseItemStyleForSubItems = false;

// color for top-stats-nr
if (cr.topStatsCount > 0)
if (cr.topStatsConsideredCount > 0)
{
if (Properties.Settings.Default.LibraryHighlightTopCreatures && cr.topBreedingCreature)
{
Expand All @@ -1141,7 +1141,7 @@ private ListViewItem CreateCreatureLvItem(Creature cr, bool displayIndex = false
else
lvi.BackColor = Color.LightGreen;
}
lvi.SubItems[ColumnIndexTopStats].BackColor = Utils.GetColorFromPercent(cr.topStatsCount * 8 + 44, 0.7);
lvi.SubItems[ColumnIndexTopStats].BackColor = Utils.GetColorFromPercent(cr.topStatsConsideredCount * 8 + 44, 0.7);
}
else
{
Expand Down
15 changes: 9 additions & 6 deletions ARKBreedingStats/library/Creature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Drawing.Text;
using System.Linq;
using System.Runtime.Serialization;

Expand Down Expand Up @@ -57,7 +56,11 @@ public void SetTopStat(int statIndex, bool isTopStat) =>

public void ResetTopStats() => _topBreedingStatIndices = 0;
private int _topBreedingStatIndices; // bit flags if a stat index is a top stat
public short topStatsCount;

/// <summary>
/// Number of top stats that are considered in the library.
/// </summary>
public byte topStatsConsideredCount;

/// <summary>
/// Set a stat index to a top mutation stat or not for that species in the creatureCollection.
Expand All @@ -73,9 +76,9 @@ public void SetTopMutationStat(int statIndex, bool isTopMutationStat) =>
private int _topMutationStatIndices; // bit flags if a stat index is a top mutation stat

/// <summary>
/// topStatCount with all stats (regardless of considerStatHighlight[]) and without torpor (for breedingPlanner)
/// topStatCount with all stats (regardless of considerStatHighlight[]) and without torpor (for breeding planner)
/// </summary>
public short topStatsCountBP;
public byte topStatsCountBP;
/// <summary>
/// True if it has some topBreedingStats and if it's male, no other male has more topBreedingStats.
/// </summary>
Expand Down Expand Up @@ -437,7 +440,7 @@ public void SetTopStatCount(bool[] considerStatHighlight, bool considerWastedSta
|| flags.HasFlag(CreatureFlags.Placeholder))
return;

short c = 0, cBP = 0;
byte c = 0, cBP = 0;
onlyTopConsideredStats = true;
for (int s = 0; s < Stats.StatsCount; s++)
{
Expand All @@ -453,7 +456,7 @@ public void SetTopStatCount(bool[] considerStatHighlight, bool considerWastedSta
onlyTopConsideredStats = false;
}
}
topStatsCount = c;
topStatsConsideredCount = c;
topStatsCountBP = cBP;
}

Expand Down
2 changes: 1 addition & 1 deletion ARKBreedingStats/utils/CreatureListSorter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private IEnumerable<Creature> OrderList(IEnumerable<Creature> list, IComparer<ob
c => c.sex,
c => c.domesticatedAt,
c => c.topness,
c => c.topStatsCount,
c => c.topStatsConsideredCount,
c => c.generation,
c => c.levelFound,
c => c.Mutations,
Expand Down

0 comments on commit 8e4d97b

Please sign in to comment.