Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
cadon committed Feb 1, 2023
2 parents 32733a7 + 061e267 commit 025d62b
Show file tree
Hide file tree
Showing 39 changed files with 4,014 additions and 3,084 deletions.
3 changes: 2 additions & 1 deletion ARKBreedingStats/ARKBreedingStats.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@
<Compile Include="AboutBox1.Designer.cs">
<DependentUpon>AboutBox1.cs</DependentUpon>
</Compile>
<Compile Include="ArkConstants.cs" />
<Compile Include="Ark.cs" />
<Compile Include="BreedingPlanning\Score.cs" />
<Compile Include="BreedingPlanning\BreedingScore.cs" />
<Compile Include="library\AddDummyCreaturesSettings.cs">
<SubType>Form</SubType>
Expand Down Expand Up @@ -669,6 +669,7 @@
<EmbeddedResource Include="local\strings.pt-br.resx" />
<EmbeddedResource Include="local\strings.ru.resx" />
<EmbeddedResource Include="local\strings.pl.resx" />
<EmbeddedResource Include="local\strings.tr.resx" />
<EmbeddedResource Include="local\strings.zh-tw.resx" />
<EmbeddedResource Include="ocr\PatternMatching\RecognitionTrainingForm.resx">
<DependentUpon>RecognitionTrainingForm.cs</DependentUpon>
Expand Down
3 changes: 2 additions & 1 deletion ARKBreedingStats/AboutBox1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ private void linkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
* Polish by alex4401
* Japanese by maririyuzu
* Portuguese Brazilian by llbranco
* Chinese (traditional) by abs6808";
* Chinese (traditional) by abs6808
* Turkish by Tnc";
}
}
28 changes: 23 additions & 5 deletions ARKBreedingStats/Ark.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ARKBreedingStats.species;
using System.Linq;
using ARKBreedingStats.species;

namespace ARKBreedingStats
{
Expand All @@ -12,12 +13,12 @@ public static class Ark
/// <summary>
/// Probability of an offspring to inherit the higher level-stat
/// </summary>
public const double ProbabilityHigherLevel = 0.55;
public const double ProbabilityInheritHigherLevel = 0.55;

/// <summary>
/// Probability of an offspring to inherit the lower level-stat
/// </summary>
public const double ProbabilityLowerLevel = 1 - ProbabilityHigherLevel;
public const double ProbabilityInheritLowerLevel = 1 - ProbabilityInheritHigherLevel;

/// <summary>
/// Probability of a mutation in an offspring
Expand Down Expand Up @@ -66,8 +67,25 @@ public static class Ark
/// <summary>
/// Indices of the stats that are affected by a mutagen application (HP, St, We, Dm).
/// </summary>
public static int[] StatIndicesAffectedByMutagen => new[]
{ Stats.Health, Stats.Stamina, Stats.Weight, Stats.MeleeDamageMultiplier };
public static readonly int[] StatIndicesAffectedByMutagen =
{
Stats.Health,
Stats.Stamina,
Stats.Weight,
Stats.MeleeDamageMultiplier
};

private const int StatCountAffectedByMutagen = 4;

/// <summary>
/// Total level ups for bred creatures when mutagen is applied.
/// </summary>
public const int MutagenTotalLevelUpsBred = MutagenLevelUpsBred * StatCountAffectedByMutagen;

/// <summary>
/// Total level ups for non bred creatures when mutagen is applied.
/// </summary>
public const int MutagenTotalLevelUpsNonBred = MutagenLevelUpsNonBred * StatCountAffectedByMutagen;

#endregion

Expand Down
11 changes: 0 additions & 11 deletions ARKBreedingStats/ArkConstants.cs

This file was deleted.

22 changes: 12 additions & 10 deletions ARKBreedingStats/BreedingPlanning/BreedingPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,12 @@ private void DoCalculateBreedingScoresAndDisplayPairs()
ref creaturesMutationsFilteredOut, levelLimitWithOutDomLevels, CbDontSuggestOverLimitOffspring.Checked,
cbBPOnlyOneSuggestionForFemales.Checked);

double minScore = _breedingPairs.LastOrDefault()?.BreedingScore ?? 0;
if (minScore < 0)
{
foreach (BreedingPair bp in _breedingPairs)
bp.BreedingScore -= minScore;
}
//double minScore = _breedingPairs.LastOrDefault()?.BreedingScore ?? 0;
//if (minScore < 0)
//{
// foreach (BreedingPair bp in _breedingPairs)
// bp.BreedingScore -= minScore;
//}

var sb = new StringBuilder();
// draw best parents
Expand Down Expand Up @@ -480,13 +480,15 @@ private void DoCalculateBreedingScoresAndDisplayPairs()
g.FillRectangle(brush, 77, 5, 10, 10);
sb.AppendLine(_breedingPairs[i].Father + " can produce a mutation.");
}

var colorPercent = (int)(_breedingPairs[i].BreedingScore.OneNumber * 12.5);
// outline
brush.Color = Utils.GetColorFromPercent((int)(_breedingPairs[i].BreedingScore * 12.5), -.2);
brush.Color = Utils.GetColorFromPercent(colorPercent, -.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);
Utils.GetColorFromPercent(colorPercent, 0.5);
g.FillRectangle(brush, 1, 16, 85, 3);
g.FillRectangle(brush, 21, 11, 45, 13);
if (_breedingPairs[i].HighestOffspringOverLevelLimit)
Expand Down Expand Up @@ -848,10 +850,10 @@ private void SetParents(int comboIndex)
// in top stats breeding mode consider only probability of top stats
if (crB.levelsWild[s] > crW.levelsWild[s]
&& (!topStatBreedingMode || crB.topBreedingStats[s]))
probabilityBest *= Ark.ProbabilityHigherLevel;
probabilityBest *= Ark.ProbabilityInheritHigherLevel;
else if (crB.levelsWild[s] < crW.levelsWild[s]
&& (!topStatBreedingMode || crB.topBreedingStats[s]))
probabilityBest *= Ark.ProbabilityLowerLevel;
probabilityBest *= Ark.ProbabilityInheritLowerLevel;
}
crB.levelsWild[Stats.Torpidity] = crB.levelsWild.Sum();
crW.levelsWild[Stats.Torpidity] = crW.levelsWild.Sum();
Expand Down
62 changes: 30 additions & 32 deletions ARKBreedingStats/BreedingPlanning/BreedingScore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using ARKBreedingStats.Library;
using ARKBreedingStats.Properties;
using ARKBreedingStats.species;
using ARKBreedingStats.values;

namespace ARKBreedingStats.BreedingPlanning
{
Expand All @@ -21,7 +20,7 @@ public static class BreedingScore
/// <param name="species"></param>
/// <param name="bestPossLevels"></param>
/// <param name="statWeights"></param>
/// <param name="bestLevels"></param>
/// <param name="bestLevelsOfSpecies">If the according stat weight is negative, the lowest level is contained.</param>
/// <param name="breedingMode"></param>
/// <param name="considerChosenCreature"></param>
/// <param name="considerMutationLimit"></param>
Expand All @@ -32,7 +31,7 @@ public static class BreedingScore
/// <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>
/// <returns></returns>
public static List<BreedingPair> CalculateBreedingScores(Creature[] females, Creature[] males, Species species,
short[] bestPossLevels, double[] statWeights, int[] bestLevels, BreedingPlan.BreedingMode breedingMode,
short[] bestPossLevels, double[] statWeights, int[] bestLevelsOfSpecies, BreedingPlan.BreedingMode breedingMode,
bool considerChosenCreature, bool considerMutationLimit, int mutationLimit,
ref bool creaturesMutationsFilteredOut, int offspringLevelLimit = 0, bool downGradeOffspringWithLevelHigherThanLimit = false,
bool onlyBestSuggestionForFemale = false)
Expand Down Expand Up @@ -65,11 +64,11 @@ public static List<BreedingPair> CalculateBreedingScores(Creature[] females, Cre
}

double t = 0;
int nrTS = 0;
double eTS = 0;
int offspringPotentialTopStatCount = 0;
double offspringExpectedTopStatCount = 0; // a guaranteed top stat counts 1, otherwise the inheritance probability of the top stat is counted

int topFemale = 0;
int topMale = 0;
int topStatsMother = 0;
int topStatsFather = 0;

int maxPossibleOffspringLevel = 1;

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

bool higherIsBetter = statWeights[s] >= 0;

double tt = statWeights[s] * (Ark.ProbabilityHigherLevel * higherLevel + Ark.ProbabilityLowerLevel * lowerLevel) / 40;
if (tt != 0)
double weightedExpectedStatLevel = statWeights[s] * (Ark.ProbabilityInheritHigherLevel * higherLevel + Ark.ProbabilityInheritLowerLevel * lowerLevel) / 40;
if (weightedExpectedStatLevel != 0)
{
if (breedingMode == BreedingPlan.BreedingMode.TopStatsLucky)
{
if (!ignoreTopStats && (female.levelsWild[s] == bestLevels[s] || male.levelsWild[s] == bestLevels[s]))
if (!ignoreTopStats && (female.levelsWild[s] == bestLevelsOfSpecies[s] || male.levelsWild[s] == bestLevelsOfSpecies[s]))
{
if (female.levelsWild[s] == bestLevels[s] && male.levelsWild[s] == bestLevels[s])
tt *= 1.142;
if (female.levelsWild[s] == bestLevelsOfSpecies[s] && male.levelsWild[s] == bestLevelsOfSpecies[s])
weightedExpectedStatLevel *= 1.142;
}
else if (bestLevels[s] > 0)
tt *= .01;
else if (bestLevelsOfSpecies[s] > 0)
weightedExpectedStatLevel *= .01;
}
else if (breedingMode == BreedingPlan.BreedingMode.TopStatsConservative && bestLevels[s] > 0)
else if (breedingMode == BreedingPlan.BreedingMode.TopStatsConservative && bestLevelsOfSpecies[s] > 0)
{
bool higherIsBetter = statWeights[s] >= 0;
bestPossLevels[s] = (short)(higherIsBetter ? Math.Max(female.levelsWild[s], male.levelsWild[s]) : Math.Min(female.levelsWild[s], male.levelsWild[s]));
tt *= .01;
if (!ignoreTopStats && (female.levelsWild[s] == bestLevels[s] || male.levelsWild[s] == bestLevels[s]))
weightedExpectedStatLevel *= .01;
if (!ignoreTopStats && (female.levelsWild[s] == bestLevelsOfSpecies[s] || male.levelsWild[s] == bestLevelsOfSpecies[s]))
{
nrTS++;
eTS += female.levelsWild[s] == bestLevels[s] && male.levelsWild[s] == bestLevels[s] ? 1 : Ark.ProbabilityHigherLevel;
if (female.levelsWild[s] == bestLevels[s])
topFemale++;
if (male.levelsWild[s] == bestLevels[s])
topMale++;
offspringPotentialTopStatCount++;
offspringExpectedTopStatCount += female.levelsWild[s] == bestLevelsOfSpecies[s] && male.levelsWild[s] == bestLevelsOfSpecies[s] ? 1 : Ark.ProbabilityInheritHigherLevel;
if (female.levelsWild[s] == bestLevelsOfSpecies[s])
topStatsMother++;
if (male.levelsWild[s] == bestLevelsOfSpecies[s])
topStatsFather++;
}
}
t += weightedExpectedStatLevel;
}
t += tt;
}

if (breedingMode == BreedingPlan.BreedingMode.TopStatsConservative)
{
if (topFemale < nrTS && topMale < nrTS)
t += eTS;
if (topStatsMother < offspringPotentialTopStatCount && topStatsFather < offspringPotentialTopStatCount)
t += offspringExpectedTopStatCount;
else
t += .1 * eTS;
t += .1 * offspringExpectedTopStatCount;
// check if the best possible stat outcome regarding topLevels already exists in a male
bool maleExists = false;

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

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

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

breedingPairs.Add(new BreedingPair(female, male,
t * 1.25,
new Score(t * 1.25),
(mutationPossibleFrom == 2 ? Ark.ProbabilityOfOneMutation : mutationPossibleFrom == 1 ? Ark.ProbabilityOfOneMutationFromOneParent : 0),
highestOffspringOverLevelLimit));
}
Expand Down
93 changes: 93 additions & 0 deletions ARKBreedingStats/BreedingPlanning/Score.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;

namespace ARKBreedingStats.BreedingPlanning
{
/// <summary>
/// Represents a score with multiple parts.
/// When comparing, only the highest different parts is relevant (similar to System.Version).
/// </summary>
public struct Score : IComparable<Score>
{
public double Primary;
public double Secondary;
public double Tertiary;

public Score(double primary)
{
Primary = primary;
Secondary = 0;
Tertiary = 0;
}

public Score(double primary, double secondary) : this(primary)
{
Secondary = secondary;
}

public Score(double primary, double secondary, double tertiary) : this(primary, secondary)
{
Tertiary = tertiary;
}

/// <summary>
/// Score condensed to one double with loss of information.
/// </summary>
public double OneNumber => Primary + Secondary * 0.01 + Tertiary * 0.0001;

#region overrides

public override string ToString() => $"{Primary}.{Secondary}.{Tertiary}";

public string ToString(string format)
{
if (Secondary == 0 && Tertiary == 0)
return Primary.ToString(format);
if (Tertiary == 0) return $"{Primary.ToString(format)}.{Secondary.ToString(format)}";

return $"{Primary.ToString(format)}.{Secondary.ToString(format)}.{Tertiary.ToString(format)}";
}

public override bool Equals(object obj)
=> obj is Score other && Equals(other);

public bool Equals(Score other) =>
Primary == other.Primary
&& Secondary == other.Secondary
&& Tertiary == other.Tertiary;

public static bool operator ==(Score left, Score right) => left.Equals(right);
public static bool operator !=(Score left, Score right) => !left.Equals(right);

public static bool operator <(Score left, Score right)
{
if (left.Primary < right.Primary) return true;
if (left.Primary > right.Primary) return false;
if (left.Secondary < right.Secondary) return true;
if (left.Secondary > right.Secondary) return false;
if (left.Tertiary < right.Tertiary) return true;

return false;
}

public static bool operator >(Score left, Score right)
{
if (left.Primary > right.Primary) return true;
if (left.Primary < right.Primary) return false;
if (left.Secondary > right.Secondary) return true;
if (left.Secondary < right.Secondary) return false;
if (left.Tertiary > right.Tertiary) return true;
return false;
}

public static bool operator <=(Score left, Score right) => left.Equals(right) || left < right;
public static bool operator >=(Score left, Score right) => left.Equals(right) || left > right;

public override int GetHashCode() => (int)(Primary * 10000 + Secondary * 100 + Tertiary);

public int CompareTo(Score other) =>
other == this ? 0
: this < other ? -1 : 1;

#endregion
}
}
1 change: 1 addition & 0 deletions ARKBreedingStats/CreatureInfoInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ public void GenerateCreatureName(Creature creature, int[] speciesTopLevels, int[
CreatureName = NamePattern.GenerateCreatureName(creature, _sameSpecies, speciesTopLevels, speciesLowestLevels, customReplacings, showDuplicateNameWarning, namingPatternIndex, false, colorsExisting: ColorAlreadyExistingInformation);
if (CreatureName.Length > 24)
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);
else SetMessageLabelText?.Invoke();
}

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

0 comments on commit 025d62b

Please sign in to comment.