This tutorial is derived from
this thread. The goal here is to modify the breeding system to record pet's lineages (parents), allowing users to keep track of breeding history and/or build a pedigree.
I am not going over making it pretty, that part will be up to you!
Database Modification
First we're going to start off with getting the database ready for this. In the adopts_owned_adoptables table, add three new columns with the following information:
classes/class_breeding.php
Go into this file and find the line starting like so;
PHP Code:
$mysidia->db->insert("owned_adoptables", array("aid" => NULL...
At the end of the list (starting with "aid" => NULL) add this:
PHP Code:
"mother" => $this->female->getAdoptID(), "father" => $this->male->getAdoptID()
Now when an adoptable is born via breeding, the parents IDs will be stored with its data. All done in this file, so you can close it now.
{home}/breeding.php
This is where the bulk of the work is done (aside from making them display all pretty-like).
So in
public function index find this line:
Replace everything between the if brackets (if{...}) with this;
PHP Code:
$offsprings = $breeding->getOffsprings();
$offspringID = $mysidia->db->select("owned_adoptables", array("aid"), "1 ORDER BY aid DESC LIMIT 1")->fetchColumn() - $num + 1;
$links = new LinkedList;
$newbabies = array(); // Kyt: Added line for Descendants Mod!!
foreach($offsprings as $offspring){
$newbabies[] = $offspringID; // Kyt: Added line for Descendants Mod!!
$image = $offspring->getEggImage("gui");
$links->add(new Link("myadopts/manage/{$offspringID}", $image));
$offspringID++;
}
$this->setField("links", $links);
/* Kyt: Descendants Mod!! */
if ($female->descendants != 0){ $mothersOffspring = $female->descendants; } else { $mothersOffspring = ""; }
if ($male->descendants != 0){ $fathersOffspring = $male->descendants; } else { $fathersOffspring = ""; }
for($i = 0; $i < count($newbabies); $i++){
$mothersOffspring .= $newbabies[$i].",";
$fathersOffspring .= $newbabies[$i].",";
}
$updatedMotherOffspring = preg_replace('/^(0,)+/', '', $mothersOffspring);
$updatedFatherOffpsring = preg_replace('/^(0,)+/', '', $fathersOffspring);
$mysidia->db->update("owned_adoptables", array("descendants" => $updatedMotherOffspring), "aid = '{$female->aid}'");
$mysidia->db->update("owned_adoptables", array("descendants" => $updatedFatherOffpsring), "aid = '{$male->aid}'");
/* Descendants Mod End!! */
All done with this file, go ahead and close it after saving.
Displaying the information
Now for the fun part! Wherever you want to display the information (offspring and parents) the code needed will be relatively the same, but it does differ based on whether the file you're editing is a view file or a base file (ex: view/myadoptsview.php vs myadopts.php).
In a view file...
PHP Code:
$babies = array();
$descendants = explode(",", $this->adopt->descendants);
if ($descendants != ""){
foreach($descendants as $offspring){
if ($offspring != 0){
$babies[] = "<a href='../../levelup/click/{$offspring}'>♡</a>";
}
}
$children = implode("", $babies);
if (empty($children)){ $children = "None"; }
}
$gender_lookup = $mysidia->db->select("owned_adoptables", array("gender"), "aid = '{$this->adopt->getAdoptID()}'")->fetchColumn();
if ($gender_lookup == "m") { $gender = "Male";$pronoun = "him"; }
if ($gender_lookup == "f") { $gender = "Female";$pronoun = "her"; }
$p1name = "---";
$p2name = "---";
if ($this->mother != NULL) { $mother = new OwnedAdoptable($this->mother); $p1name = $mother->name; $p1id = $mother->aid; } else { $p1id = $this->aid; }
if ($this->father != NULL) { $father = new OwnedAdoptable($this->father); $p2name = $father->name; $p2id = $father->aid; } else { $p2id = $this->aid;
That is the code you'll need. Then you can use the defined variables as you see fit to display the data. I include mine right under the initial defined variables in the
manage function for view/myadoptsview.php. I then display it like so;
PHP Code:
<strong>Parents:</strong> {$p1name} and {$p2name}
In a non-view file...
Code;
PHP Code:
$babies = array();
$descendants = explode(",", $this->adopt->descendants);
if ($descendants != ""){
foreach($descendants as $offspring){
if ($offspring != 0){
$babies[] = "<a href='../../levelup/click/{$offspring}'>♡</a>";
}
}
$children = implode("", $babies);
if (empty($children)){ $children = "None"; }
}
if ($this->mother != NULL) { $mother = new OwnedAdoptable($this->mother); $p1name = $mother->name; $p1id = $mother->aid; } else { $p1name = "Unkown"; }
if ($this->father != NULL) { $father = new OwnedAdoptable($this->father); $p2name = $father->name; $p2id = $father->aid; } else { $p2name = "Unknown"; }
Displayed the same way.
And that should be it! I know this tutorial isn't very detailed...once you have all of the code it isn't difficult to put it all together...so I hope that it is understandable enough!