Skip to content

Commit 8e4d97b

Browse files
committed
prefilter creatures in breeding planner
1 parent 9565d1a commit 8e4d97b

File tree

4 files changed

+43
-28
lines changed

4 files changed

+43
-28
lines changed

ARKBreedingStats/BreedingPlanning/BreedingPlan.cs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,23 @@ private void DoCalculateBreedingScoresAndDisplayPairs()
286286
bool considerMutationLimit = nudBPMutationLimit.Value >= 0;
287287

288288
bool creaturesMutationsFilteredOut = false;
289+
290+
// only consider creatures with top stats if breeding for that
291+
Creature[] females, males;
292+
if (_breedingMode == BreedingMode.BestNextGen)
293+
{
294+
females = _females;
295+
males = _males;
296+
}
297+
else
298+
{
299+
females = _females.Where(c => c.topStatsCountBP > 0).ToArray();
300+
males = _males?.Where(c => c.topStatsCountBP > 0).ToArray();
301+
}
302+
289303
// filter by tags
290-
int crCountF = _females.Length;
291-
int crCountM = _males?.Length ?? 0;
304+
int crCountF = females.Length;
305+
int crCountM = males?.Length ?? 0;
292306
IEnumerable<Creature> selectFemales;
293307
IEnumerable<Creature> selectMales = null;
294308
if (considerChosenCreature && (_chosenCreature.sex == Sex.Female || _currentSpecies.noGender))
@@ -297,25 +311,25 @@ private void DoCalculateBreedingScoresAndDisplayPairs()
297311
}
298312
else if (!cbBPMutationLimitOnlyOnePartner.Checked && considerMutationLimit)
299313
{
300-
selectFemales = FilterByTags(_females.Where(c => c.Mutations <= nudBPMutationLimit.Value));
301-
creaturesMutationsFilteredOut = _females.Any(c => c.Mutations > nudBPMutationLimit.Value);
314+
selectFemales = FilterByTags(females.Where(c => c.Mutations <= nudBPMutationLimit.Value));
315+
creaturesMutationsFilteredOut = females.Any(c => c.Mutations > nudBPMutationLimit.Value);
302316
}
303-
else selectFemales = FilterByTags(_females);
317+
else selectFemales = FilterByTags(females);
304318

305319
if (considerChosenCreature && !_currentSpecies.noGender && _chosenCreature.sex == Sex.Male)
306320
{
307321
selectMales = new List<Creature>(); // the specific creature is added after the filtering
308322
}
309323
else if (!cbBPMutationLimitOnlyOnePartner.Checked && considerMutationLimit)
310324
{
311-
if (_males != null)
325+
if (males != null)
312326
{
313-
selectMales = FilterByTags(_males.Where(c => c.Mutations <= nudBPMutationLimit.Value));
327+
selectMales = FilterByTags(males.Where(c => c.Mutations <= nudBPMutationLimit.Value));
314328
creaturesMutationsFilteredOut = creaturesMutationsFilteredOut ||
315-
_males.Any(c => c.Mutations > nudBPMutationLimit.Value);
329+
males.Any(c => c.Mutations > nudBPMutationLimit.Value);
316330
}
317331
}
318-
else selectMales = FilterByTags(_males);
332+
else selectMales = FilterByTags(males);
319333

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

404-
//double minScore = _breedingPairs.LastOrDefault()?.BreedingScore ?? 0;
405-
//if (minScore < 0)
406-
//{
407-
// foreach (BreedingPair bp in _breedingPairs)
408-
// bp.BreedingScore -= minScore;
409-
//}
418+
double minScore = _breedingPairs.LastOrDefault()?.BreedingScore.OneNumber ?? 0;
419+
var displayScoreOffset = (minScore < 0 ? -minScore : 0) + .5; // don't display negative scores, could be confusing
420+
421+
_breedingPairs = _breedingPairs.Take(CreatureCollection.maxBreedingSuggestions).ToList();
410422

411423
var sb = new StringBuilder();
412424
// draw best parents
413425
using (var brush = new SolidBrush(Color.Black))
414426
{
415-
for (int i = 0; i < _breedingPairs.Count && i < CreatureCollection.maxBreedingSuggestions; i++)
427+
for (int i = 0; i < _breedingPairs.Count; i++)
416428
{
417429
PedigreeCreature pc;
418430
if (2 * i < _pcs.Count)
@@ -486,7 +498,7 @@ private void DoCalculateBreedingScoresAndDisplayPairs()
486498
sb.AppendLine(_breedingPairs[i].Father + " can produce a mutation.");
487499
}
488500

489-
var colorPercent = (int)(_breedingPairs[i].BreedingScore.OneNumber * 12.5);
501+
var colorPercent = (int)((_breedingPairs[i].BreedingScore.OneNumber + displayScoreOffset) * 12.5);
490502
// outline
491503
brush.Color = Utils.GetColorFromPercent(colorPercent, -.2);
492504
g.FillRectangle(brush, 0, 15, 87, 5);
@@ -504,7 +516,7 @@ private void DoCalculateBreedingScoresAndDisplayPairs()
504516
}
505517
// breeding score text
506518
brush.Color = Color.Black;
507-
g.DrawString(_breedingPairs[i].BreedingScore.ToString("N4"),
519+
g.DrawString((_breedingPairs[i].BreedingScore.Primary + displayScoreOffset).ToString("N4"),
508520
new Font("Microsoft Sans Serif", 8.25f), brush, 24, 12);
509521
pb.Image = bm;
510522
}

ARKBreedingStats/Form1.library.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ private ListViewItem CreateCreatureLvItem(Creature cr, bool displayIndex = false
10471047
Utils.SexSymbol(cr.sex),
10481048
cr.domesticatedAt?.ToString("yyyy'-'MM'-'dd HH':'mm':'ss") ?? string.Empty,
10491049
(cr.topness / 10).ToString(),
1050-
cr.topStatsCount.ToString(),
1050+
cr.topStatsConsideredCount.ToString(),
10511051
cr.generation.ToString(),
10521052
cr.levelFound.ToString(),
10531053
cr.Mutations.ToString(),
@@ -1132,7 +1132,7 @@ private ListViewItem CreateCreatureLvItem(Creature cr, bool displayIndex = false
11321132
lvi.UseItemStyleForSubItems = false;
11331133

11341134
// color for top-stats-nr
1135-
if (cr.topStatsCount > 0)
1135+
if (cr.topStatsConsideredCount > 0)
11361136
{
11371137
if (Properties.Settings.Default.LibraryHighlightTopCreatures && cr.topBreedingCreature)
11381138
{
@@ -1141,7 +1141,7 @@ private ListViewItem CreateCreatureLvItem(Creature cr, bool displayIndex = false
11411141
else
11421142
lvi.BackColor = Color.LightGreen;
11431143
}
1144-
lvi.SubItems[ColumnIndexTopStats].BackColor = Utils.GetColorFromPercent(cr.topStatsCount * 8 + 44, 0.7);
1144+
lvi.SubItems[ColumnIndexTopStats].BackColor = Utils.GetColorFromPercent(cr.topStatsConsideredCount * 8 + 44, 0.7);
11451145
}
11461146
else
11471147
{

ARKBreedingStats/library/Creature.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Newtonsoft.Json;
33
using System;
44
using System.Collections.Generic;
5-
using System.Drawing.Text;
65
using System.Linq;
76
using System.Runtime.Serialization;
87

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

5857
public void ResetTopStats() => _topBreedingStatIndices = 0;
5958
private int _topBreedingStatIndices; // bit flags if a stat index is a top stat
60-
public short topStatsCount;
59+
60+
/// <summary>
61+
/// Number of top stats that are considered in the library.
62+
/// </summary>
63+
public byte topStatsConsideredCount;
6164

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

7578
/// <summary>
76-
/// topStatCount with all stats (regardless of considerStatHighlight[]) and without torpor (for breedingPlanner)
79+
/// topStatCount with all stats (regardless of considerStatHighlight[]) and without torpor (for breeding planner)
7780
/// </summary>
78-
public short topStatsCountBP;
81+
public byte topStatsCountBP;
7982
/// <summary>
8083
/// True if it has some topBreedingStats and if it's male, no other male has more topBreedingStats.
8184
/// </summary>
@@ -437,7 +440,7 @@ public void SetTopStatCount(bool[] considerStatHighlight, bool considerWastedSta
437440
|| flags.HasFlag(CreatureFlags.Placeholder))
438441
return;
439442

440-
short c = 0, cBP = 0;
443+
byte c = 0, cBP = 0;
441444
onlyTopConsideredStats = true;
442445
for (int s = 0; s < Stats.StatsCount; s++)
443446
{
@@ -453,7 +456,7 @@ public void SetTopStatCount(bool[] considerStatHighlight, bool considerWastedSta
453456
onlyTopConsideredStats = false;
454457
}
455458
}
456-
topStatsCount = c;
459+
topStatsConsideredCount = c;
457460
topStatsCountBP = cBP;
458461
}
459462

ARKBreedingStats/utils/CreatureListSorter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private IEnumerable<Creature> OrderList(IEnumerable<Creature> list, IComparer<ob
136136
c => c.sex,
137137
c => c.domesticatedAt,
138138
c => c.topness,
139-
c => c.topStatsCount,
139+
c => c.topStatsConsideredCount,
140140
c => c.generation,
141141
c => c.levelFound,
142142
c => c.Mutations,

0 commit comments

Comments
 (0)