Skip to content

Commit 025d62b

Browse files
committed
Merge branch 'dev'
2 parents 32733a7 + 061e267 commit 025d62b

39 files changed

+4014
-3084
lines changed

ARKBreedingStats/ARKBreedingStats.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@
8080
<Compile Include="AboutBox1.Designer.cs">
8181
<DependentUpon>AboutBox1.cs</DependentUpon>
8282
</Compile>
83-
<Compile Include="ArkConstants.cs" />
8483
<Compile Include="Ark.cs" />
84+
<Compile Include="BreedingPlanning\Score.cs" />
8585
<Compile Include="BreedingPlanning\BreedingScore.cs" />
8686
<Compile Include="library\AddDummyCreaturesSettings.cs">
8787
<SubType>Form</SubType>
@@ -669,6 +669,7 @@
669669
<EmbeddedResource Include="local\strings.pt-br.resx" />
670670
<EmbeddedResource Include="local\strings.ru.resx" />
671671
<EmbeddedResource Include="local\strings.pl.resx" />
672+
<EmbeddedResource Include="local\strings.tr.resx" />
672673
<EmbeddedResource Include="local\strings.zh-tw.resx" />
673674
<EmbeddedResource Include="ocr\PatternMatching\RecognitionTrainingForm.resx">
674675
<DependentUpon>RecognitionTrainingForm.cs</DependentUpon>

ARKBreedingStats/AboutBox1.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ private void linkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
120120
* Polish by alex4401
121121
* Japanese by maririyuzu
122122
* Portuguese Brazilian by llbranco
123-
* Chinese (traditional) by abs6808";
123+
* Chinese (traditional) by abs6808
124+
* Turkish by Tnc";
124125
}
125126
}

ARKBreedingStats/Ark.cs

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using ARKBreedingStats.species;
1+
using System.Linq;
2+
using ARKBreedingStats.species;
23

34
namespace ARKBreedingStats
45
{
@@ -12,12 +13,12 @@ public static class Ark
1213
/// <summary>
1314
/// Probability of an offspring to inherit the higher level-stat
1415
/// </summary>
15-
public const double ProbabilityHigherLevel = 0.55;
16+
public const double ProbabilityInheritHigherLevel = 0.55;
1617

1718
/// <summary>
1819
/// Probability of an offspring to inherit the lower level-stat
1920
/// </summary>
20-
public const double ProbabilityLowerLevel = 1 - ProbabilityHigherLevel;
21+
public const double ProbabilityInheritLowerLevel = 1 - ProbabilityInheritHigherLevel;
2122

2223
/// <summary>
2324
/// Probability of a mutation in an offspring
@@ -66,8 +67,25 @@ public static class Ark
6667
/// <summary>
6768
/// Indices of the stats that are affected by a mutagen application (HP, St, We, Dm).
6869
/// </summary>
69-
public static int[] StatIndicesAffectedByMutagen => new[]
70-
{ Stats.Health, Stats.Stamina, Stats.Weight, Stats.MeleeDamageMultiplier };
70+
public static readonly int[] StatIndicesAffectedByMutagen =
71+
{
72+
Stats.Health,
73+
Stats.Stamina,
74+
Stats.Weight,
75+
Stats.MeleeDamageMultiplier
76+
};
77+
78+
private const int StatCountAffectedByMutagen = 4;
79+
80+
/// <summary>
81+
/// Total level ups for bred creatures when mutagen is applied.
82+
/// </summary>
83+
public const int MutagenTotalLevelUpsBred = MutagenLevelUpsBred * StatCountAffectedByMutagen;
84+
85+
/// <summary>
86+
/// Total level ups for non bred creatures when mutagen is applied.
87+
/// </summary>
88+
public const int MutagenTotalLevelUpsNonBred = MutagenLevelUpsNonBred * StatCountAffectedByMutagen;
7189

7290
#endregion
7391

ARKBreedingStats/ArkConstants.cs

-11
This file was deleted.

ARKBreedingStats/BreedingPlanning/BreedingPlan.cs

+12-10
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,12 @@ private void DoCalculateBreedingScoresAndDisplayPairs()
396396
ref creaturesMutationsFilteredOut, levelLimitWithOutDomLevels, CbDontSuggestOverLimitOffspring.Checked,
397397
cbBPOnlyOneSuggestionForFemales.Checked);
398398

399-
double minScore = _breedingPairs.LastOrDefault()?.BreedingScore ?? 0;
400-
if (minScore < 0)
401-
{
402-
foreach (BreedingPair bp in _breedingPairs)
403-
bp.BreedingScore -= minScore;
404-
}
399+
//double minScore = _breedingPairs.LastOrDefault()?.BreedingScore ?? 0;
400+
//if (minScore < 0)
401+
//{
402+
// foreach (BreedingPair bp in _breedingPairs)
403+
// bp.BreedingScore -= minScore;
404+
//}
405405

406406
var sb = new StringBuilder();
407407
// draw best parents
@@ -480,13 +480,15 @@ private void DoCalculateBreedingScoresAndDisplayPairs()
480480
g.FillRectangle(brush, 77, 5, 10, 10);
481481
sb.AppendLine(_breedingPairs[i].Father + " can produce a mutation.");
482482
}
483+
484+
var colorPercent = (int)(_breedingPairs[i].BreedingScore.OneNumber * 12.5);
483485
// outline
484-
brush.Color = Utils.GetColorFromPercent((int)(_breedingPairs[i].BreedingScore * 12.5), -.2);
486+
brush.Color = Utils.GetColorFromPercent(colorPercent, -.2);
485487
g.FillRectangle(brush, 0, 15, 87, 5);
486488
g.FillRectangle(brush, 20, 10, 47, 15);
487489
// fill
488490
brush.Color =
489-
Utils.GetColorFromPercent((int)(_breedingPairs[i].BreedingScore * 12.5), 0.5);
491+
Utils.GetColorFromPercent(colorPercent, 0.5);
490492
g.FillRectangle(brush, 1, 16, 85, 3);
491493
g.FillRectangle(brush, 21, 11, 45, 13);
492494
if (_breedingPairs[i].HighestOffspringOverLevelLimit)
@@ -848,10 +850,10 @@ private void SetParents(int comboIndex)
848850
// in top stats breeding mode consider only probability of top stats
849851
if (crB.levelsWild[s] > crW.levelsWild[s]
850852
&& (!topStatBreedingMode || crB.topBreedingStats[s]))
851-
probabilityBest *= Ark.ProbabilityHigherLevel;
853+
probabilityBest *= Ark.ProbabilityInheritHigherLevel;
852854
else if (crB.levelsWild[s] < crW.levelsWild[s]
853855
&& (!topStatBreedingMode || crB.topBreedingStats[s]))
854-
probabilityBest *= Ark.ProbabilityLowerLevel;
856+
probabilityBest *= Ark.ProbabilityInheritLowerLevel;
855857
}
856858
crB.levelsWild[Stats.Torpidity] = crB.levelsWild.Sum();
857859
crW.levelsWild[Stats.Torpidity] = crW.levelsWild.Sum();

ARKBreedingStats/BreedingPlanning/BreedingScore.cs

+30-32
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using ARKBreedingStats.Library;
55
using ARKBreedingStats.Properties;
66
using ARKBreedingStats.species;
7-
using ARKBreedingStats.values;
87

98
namespace ARKBreedingStats.BreedingPlanning
109
{
@@ -21,7 +20,7 @@ public static class BreedingScore
2120
/// <param name="species"></param>
2221
/// <param name="bestPossLevels"></param>
2322
/// <param name="statWeights"></param>
24-
/// <param name="bestLevels"></param>
23+
/// <param name="bestLevelsOfSpecies">If the according stat weight is negative, the lowest level is contained.</param>
2524
/// <param name="breedingMode"></param>
2625
/// <param name="considerChosenCreature"></param>
2726
/// <param name="considerMutationLimit"></param>
@@ -32,7 +31,7 @@ public static class BreedingScore
3231
/// <param name="onlyBestSuggestionForFemale">Only the pairing with the highest score is kept for each female. Is not used if species has no sex or sex is ignored in breeding planner.</param>
3332
/// <returns></returns>
3433
public static List<BreedingPair> CalculateBreedingScores(Creature[] females, Creature[] males, Species species,
35-
short[] bestPossLevels, double[] statWeights, int[] bestLevels, BreedingPlan.BreedingMode breedingMode,
34+
short[] bestPossLevels, double[] statWeights, int[] bestLevelsOfSpecies, BreedingPlan.BreedingMode breedingMode,
3635
bool considerChosenCreature, bool considerMutationLimit, int mutationLimit,
3736
ref bool creaturesMutationsFilteredOut, int offspringLevelLimit = 0, bool downGradeOffspringWithLevelHigherThanLimit = false,
3837
bool onlyBestSuggestionForFemale = false)
@@ -65,11 +64,11 @@ public static List<BreedingPair> CalculateBreedingScores(Creature[] females, Cre
6564
}
6665

6766
double t = 0;
68-
int nrTS = 0;
69-
double eTS = 0;
67+
int offspringPotentialTopStatCount = 0;
68+
double offspringExpectedTopStatCount = 0; // a guaranteed top stat counts 1, otherwise the inheritance probability of the top stat is counted
7069

71-
int topFemale = 0;
72-
int topMale = 0;
70+
int topStatsMother = 0;
71+
int topStatsFather = 0;
7372

7473
int maxPossibleOffspringLevel = 1;
7574

@@ -87,45 +86,44 @@ public static List<BreedingPair> CalculateBreedingScores(Creature[] females, Cre
8786
&& higherLevel % 2 != 0
8887
&& statWeights[s] > 0;
8988

90-
bool higherIsBetter = statWeights[s] >= 0;
91-
92-
double tt = statWeights[s] * (Ark.ProbabilityHigherLevel * higherLevel + Ark.ProbabilityLowerLevel * lowerLevel) / 40;
93-
if (tt != 0)
89+
double weightedExpectedStatLevel = statWeights[s] * (Ark.ProbabilityInheritHigherLevel * higherLevel + Ark.ProbabilityInheritLowerLevel * lowerLevel) / 40;
90+
if (weightedExpectedStatLevel != 0)
9491
{
9592
if (breedingMode == BreedingPlan.BreedingMode.TopStatsLucky)
9693
{
97-
if (!ignoreTopStats && (female.levelsWild[s] == bestLevels[s] || male.levelsWild[s] == bestLevels[s]))
94+
if (!ignoreTopStats && (female.levelsWild[s] == bestLevelsOfSpecies[s] || male.levelsWild[s] == bestLevelsOfSpecies[s]))
9895
{
99-
if (female.levelsWild[s] == bestLevels[s] && male.levelsWild[s] == bestLevels[s])
100-
tt *= 1.142;
96+
if (female.levelsWild[s] == bestLevelsOfSpecies[s] && male.levelsWild[s] == bestLevelsOfSpecies[s])
97+
weightedExpectedStatLevel *= 1.142;
10198
}
102-
else if (bestLevels[s] > 0)
103-
tt *= .01;
99+
else if (bestLevelsOfSpecies[s] > 0)
100+
weightedExpectedStatLevel *= .01;
104101
}
105-
else if (breedingMode == BreedingPlan.BreedingMode.TopStatsConservative && bestLevels[s] > 0)
102+
else if (breedingMode == BreedingPlan.BreedingMode.TopStatsConservative && bestLevelsOfSpecies[s] > 0)
106103
{
104+
bool higherIsBetter = statWeights[s] >= 0;
107105
bestPossLevels[s] = (short)(higherIsBetter ? Math.Max(female.levelsWild[s], male.levelsWild[s]) : Math.Min(female.levelsWild[s], male.levelsWild[s]));
108-
tt *= .01;
109-
if (!ignoreTopStats && (female.levelsWild[s] == bestLevels[s] || male.levelsWild[s] == bestLevels[s]))
106+
weightedExpectedStatLevel *= .01;
107+
if (!ignoreTopStats && (female.levelsWild[s] == bestLevelsOfSpecies[s] || male.levelsWild[s] == bestLevelsOfSpecies[s]))
110108
{
111-
nrTS++;
112-
eTS += female.levelsWild[s] == bestLevels[s] && male.levelsWild[s] == bestLevels[s] ? 1 : Ark.ProbabilityHigherLevel;
113-
if (female.levelsWild[s] == bestLevels[s])
114-
topFemale++;
115-
if (male.levelsWild[s] == bestLevels[s])
116-
topMale++;
109+
offspringPotentialTopStatCount++;
110+
offspringExpectedTopStatCount += female.levelsWild[s] == bestLevelsOfSpecies[s] && male.levelsWild[s] == bestLevelsOfSpecies[s] ? 1 : Ark.ProbabilityInheritHigherLevel;
111+
if (female.levelsWild[s] == bestLevelsOfSpecies[s])
112+
topStatsMother++;
113+
if (male.levelsWild[s] == bestLevelsOfSpecies[s])
114+
topStatsFather++;
117115
}
118116
}
117+
t += weightedExpectedStatLevel;
119118
}
120-
t += tt;
121119
}
122120

123121
if (breedingMode == BreedingPlan.BreedingMode.TopStatsConservative)
124122
{
125-
if (topFemale < nrTS && topMale < nrTS)
126-
t += eTS;
123+
if (topStatsMother < offspringPotentialTopStatCount && topStatsFather < offspringPotentialTopStatCount)
124+
t += offspringExpectedTopStatCount;
127125
else
128-
t += .1 * eTS;
126+
t += .1 * offspringExpectedTopStatCount;
129127
// check if the best possible stat outcome regarding topLevels already exists in a male
130128
bool maleExists = false;
131129

@@ -137,7 +135,7 @@ public static List<BreedingPair> CalculateBreedingScores(Creature[] females, Cre
137135
if (s == Stats.Torpidity
138136
|| !cr.Species.UsesStat(s)
139137
|| cr.levelsWild[s] == bestPossLevels[s]
140-
|| bestPossLevels[s] != bestLevels[s])
138+
|| bestPossLevels[s] != bestLevelsOfSpecies[s])
141139
continue;
142140

143141
maleExists = false;
@@ -160,7 +158,7 @@ public static List<BreedingPair> CalculateBreedingScores(Creature[] females, Cre
160158
if (s == Stats.Torpidity
161159
|| !cr.Species.UsesStat(s)
162160
|| cr.levelsWild[s] == bestPossLevels[s]
163-
|| bestPossLevels[s] != bestLevels[s])
161+
|| bestPossLevels[s] != bestLevelsOfSpecies[s])
164162
continue;
165163

166164
femaleExists = false;
@@ -184,7 +182,7 @@ public static List<BreedingPair> CalculateBreedingScores(Creature[] females, Cre
184182
: female.Mutations < Ark.MutationPossibleWithLessThan || male.Mutations < Ark.MutationPossibleWithLessThan ? 1 : 0;
185183

186184
breedingPairs.Add(new BreedingPair(female, male,
187-
t * 1.25,
185+
new Score(t * 1.25),
188186
(mutationPossibleFrom == 2 ? Ark.ProbabilityOfOneMutation : mutationPossibleFrom == 1 ? Ark.ProbabilityOfOneMutationFromOneParent : 0),
189187
highestOffspringOverLevelLimit));
190188
}
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using System;
2+
3+
namespace ARKBreedingStats.BreedingPlanning
4+
{
5+
/// <summary>
6+
/// Represents a score with multiple parts.
7+
/// When comparing, only the highest different parts is relevant (similar to System.Version).
8+
/// </summary>
9+
public struct Score : IComparable<Score>
10+
{
11+
public double Primary;
12+
public double Secondary;
13+
public double Tertiary;
14+
15+
public Score(double primary)
16+
{
17+
Primary = primary;
18+
Secondary = 0;
19+
Tertiary = 0;
20+
}
21+
22+
public Score(double primary, double secondary) : this(primary)
23+
{
24+
Secondary = secondary;
25+
}
26+
27+
public Score(double primary, double secondary, double tertiary) : this(primary, secondary)
28+
{
29+
Tertiary = tertiary;
30+
}
31+
32+
/// <summary>
33+
/// Score condensed to one double with loss of information.
34+
/// </summary>
35+
public double OneNumber => Primary + Secondary * 0.01 + Tertiary * 0.0001;
36+
37+
#region overrides
38+
39+
public override string ToString() => $"{Primary}.{Secondary}.{Tertiary}";
40+
41+
public string ToString(string format)
42+
{
43+
if (Secondary == 0 && Tertiary == 0)
44+
return Primary.ToString(format);
45+
if (Tertiary == 0) return $"{Primary.ToString(format)}.{Secondary.ToString(format)}";
46+
47+
return $"{Primary.ToString(format)}.{Secondary.ToString(format)}.{Tertiary.ToString(format)}";
48+
}
49+
50+
public override bool Equals(object obj)
51+
=> obj is Score other && Equals(other);
52+
53+
public bool Equals(Score other) =>
54+
Primary == other.Primary
55+
&& Secondary == other.Secondary
56+
&& Tertiary == other.Tertiary;
57+
58+
public static bool operator ==(Score left, Score right) => left.Equals(right);
59+
public static bool operator !=(Score left, Score right) => !left.Equals(right);
60+
61+
public static bool operator <(Score left, Score right)
62+
{
63+
if (left.Primary < right.Primary) return true;
64+
if (left.Primary > right.Primary) return false;
65+
if (left.Secondary < right.Secondary) return true;
66+
if (left.Secondary > right.Secondary) return false;
67+
if (left.Tertiary < right.Tertiary) return true;
68+
69+
return false;
70+
}
71+
72+
public static bool operator >(Score left, Score right)
73+
{
74+
if (left.Primary > right.Primary) return true;
75+
if (left.Primary < right.Primary) return false;
76+
if (left.Secondary > right.Secondary) return true;
77+
if (left.Secondary < right.Secondary) return false;
78+
if (left.Tertiary > right.Tertiary) return true;
79+
return false;
80+
}
81+
82+
public static bool operator <=(Score left, Score right) => left.Equals(right) || left < right;
83+
public static bool operator >=(Score left, Score right) => left.Equals(right) || left > right;
84+
85+
public override int GetHashCode() => (int)(Primary * 10000 + Secondary * 100 + Tertiary);
86+
87+
public int CompareTo(Score other) =>
88+
other == this ? 0
89+
: this < other ? -1 : 1;
90+
91+
#endregion
92+
}
93+
}

ARKBreedingStats/CreatureInfoInput.cs

+1
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ public void GenerateCreatureName(Creature creature, int[] speciesTopLevels, int[
591591
CreatureName = NamePattern.GenerateCreatureName(creature, _sameSpecies, speciesTopLevels, speciesLowestLevels, customReplacings, showDuplicateNameWarning, namingPatternIndex, false, colorsExisting: ColorAlreadyExistingInformation);
592592
if (CreatureName.Length > 24)
593593
SetMessageLabelText?.Invoke("The generated name is longer than 24 characters, the name will look like this in game:\n" + CreatureName.Substring(0, 24), MessageBoxIcon.Error);
594+
else SetMessageLabelText?.Invoke();
594595
}
595596

596597
public void OpenNamePatternEditor(Creature creature, int[] speciesTopLevels, int[] speciesLowestLevels, Dictionary<string, string> customReplacings, int namingPatternIndex, Action<PatternEditor> reloadCallback)

0 commit comments

Comments
 (0)