Skip to content

Commit

Permalink
added input of parents before adding to library. performance-improvem…
Browse files Browse the repository at this point in the history
…ents and bugfixes regarding parents.
  • Loading branch information
cadon committed Mar 18, 2016
1 parent ef6a5e8 commit d0943b0
Show file tree
Hide file tree
Showing 10 changed files with 687 additions and 316 deletions.
9 changes: 9 additions & 0 deletions ARKBreedingStats/ARKBreedingStats.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<DependentUpon>CreatureBox.cs</DependentUpon>
</Compile>
<Compile Include="CreatureCollection.cs" />
<Compile Include="CreatureInfoInput.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="CreatureInfoInput.Designer.cs">
<DependentUpon>CreatureInfoInput.cs</DependentUpon>
</Compile>
<Compile Include="CreatureStat.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
Expand Down Expand Up @@ -115,6 +121,9 @@
<EmbeddedResource Include="CreatureBox.resx">
<DependentUpon>CreatureBox.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="CreatureInfoInput.resx">
<DependentUpon>CreatureInfoInput.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
Expand Down
47 changes: 35 additions & 12 deletions ARKBreedingStats/Creature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,31 @@ public class Creature
public bool topBreedingCreature; // true if it has some topBreedingStats and if it's male, no other male has more topBreedingStats
[XmlIgnore]
public Int16 topness; // permille of mean of wildlevels compared to toplevels
public string owner="";
public string note=""; // user defined note about that creature
public string owner = "";
public string note = ""; // user defined note about that creature
public Guid guid;
public bool isBred;
public Guid fatherGuid;
public Guid motherGuid;
[XmlIgnore]
public Creature father;
private Creature father;
[XmlIgnore]
public Creature mother;
private Creature mother;
public int generation; // number of generations from the oldest wild creature

public Creature()
{
initVars();
}

public Creature(string species, string name, string owner, Gender gender, int[] levelsWild, int[] levelsDom, double tamingEff, bool isBred)
public Creature(string species, string name, string owner, Gender gender, int[] levelsWild, int[] levelsDom = null, double tamingEff = 0, bool isBred = false)
{
this.species = species;
this.name = name;
this.owner = owner;
this.gender = (Gender)gender;
this.levelsWild = levelsWild;
this.levelsDom = levelsDom;
this.levelsDom = (levelsDom == null ? new int[] { 0, 0, 0, 0, 0, 0, 0, 0 } : levelsDom);
if (isBred)
this.tamingEff = 1;
else
Expand All @@ -68,7 +68,7 @@ private void initVars()

public void recalculateAncestorGenerations()
{
generation = ancestorGenerations(this, 0);
generation = ancestorGenerations();
}

/// <summary>
Expand All @@ -77,18 +77,41 @@ public void recalculateAncestorGenerations()
/// <param name="c">Creature to check</param>
/// <param name="g">Generations so far</param>
/// <returns></returns>
private int ancestorGenerations(Creature c, int g = 0)
private int ancestorGenerations(int g = 0)
{
// TODO: detect loop (if a creature is falsely listed as its own ancestor)
if (g > 99)
return 100;

int mgen = 0, fgen = 0;
if (c.mother != null)
mgen = ancestorGenerations(c.mother, g) + 1;
if (c.father != null)
fgen = ancestorGenerations(c.father, g) + 1;
if (mother != null)
mgen = mother.ancestorGenerations(g + 1);
if (father != null)
fgen = father.ancestorGenerations(g + 1);
if (mgen > fgen)
return mgen + g;
else
return fgen + g;
}

public Creature Mother
{
set
{
mother = value;
motherGuid = (mother != null ? mother.guid : Guid.Empty);
}
get { return mother; }
}
public Creature Father
{
set
{
father = value;
fatherGuid = (father != null ? father.guid : Guid.Empty);
}
get { return father; }
}
}

public enum Gender
Expand Down
22 changes: 10 additions & 12 deletions ARKBreedingStats/CreatureBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ private void updateLabel()
break;
}
groupBox1.Text = creature.name + " (" + creature.species + ", Lvl " + creature.level + ")";
if (creature.mother != null || creature.father != null)
if (creature.Mother != null || creature.Father != null)
{
labelParents.Text = "";
if (creature.mother != null)
labelParents.Text = "M: " + creature.mother.name;
if (creature.father != null && creature.mother != null)
if (creature.Mother != null)
labelParents.Text = "M: " + creature.Mother.name;
if (creature.Father != null && creature.Mother != null)
labelParents.Text += "; ";
if (creature.father != null)
labelParents.Text += "F: " + creature.father.name;
if (creature.Father != null)
labelParents.Text += "F: " + creature.Father.name;
}
else if (creature.isBred)
{
Expand Down Expand Up @@ -203,18 +203,18 @@ private void closeSettings(bool save)
parent = parentList[0][comboBoxMother.SelectedIndex - 1];
creature.motherGuid = (parent != null ? parent.guid : Guid.Empty);
bool parentsChanged = false;
if (creature.mother != parent)
if (creature.Mother != parent)
{
creature.mother = parent;
creature.Mother = parent;
parentsChanged = true;
}
parent = null;
if (checkBoxIsBred.Checked && comboBoxFather.SelectedIndex > 0)
parent = parentList[1][comboBoxFather.SelectedIndex - 1];
creature.fatherGuid = (parent != null ? parent.guid : Guid.Empty);
if (creature.father != parent)
if (creature.Father != parent)
{
creature.father = parent;
creature.Father = parent;
parentsChanged = true;
}
if (parentsChanged)
Expand Down Expand Up @@ -318,8 +318,6 @@ private void comboBoxParents_DrawItem(object sender, DrawItemEventArgs e)

// Draw the current item text
e.Graphics.DrawString(((ComboBox)sender).Items[e.Index].ToString(), e.Font, myBrush, e.Bounds, StringFormat.GenericDefault);
// If the ListBox has focus, draw a focus rectangle around the selected item.
//e.DrawFocusRectangle();
}
}
}
197 changes: 197 additions & 0 deletions ARKBreedingStats/CreatureInfoInput.Designer.cs

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

Loading

0 comments on commit d0943b0

Please sign in to comment.