--HG--
branch : gsoc2012-achievements
This commit is contained in:
SirCotare 2012-07-02 18:55:13 +02:00
parent 964ce26025
commit 6a32131dd8
8 changed files with 66 additions and 36 deletions

View file

@ -1,8 +1,16 @@
<?php
class AVLTree {
/*---------------------------
AVL trees are balanced B-Trees. Please refer to http://en.wikipedia.org/wiki/AVL_tree
This implementation allows the functions insert, find and remove. Please
note, that remove does not rebalance the tree, since node removal is
quite rare in this project.
---------------------------*/
private $root;
private $debug;
function AVLTree($log = false) {
$this->root = null;
$this->debug = $log;

View file

@ -11,6 +11,9 @@
function AchCategory($id,$cult = null,$civ = null) {
global $DBc,$_USER;
$civ = mysql_real_escape_string($civ);
$cult = mysql_real_escape_string($cult);
if($cult == null) {
$cult = $_USER->getCult();
}
@ -24,7 +27,8 @@
$this->id = mysql_real_escape_string($id);
$res = $DBc->sqlQuery("SELECT * FROM ach_achievement LEFT JOIN (ach_achievement_lang) ON (aal_lang='".$_USER->getLang()."' AND aal_achievement=aa_id) WHERE aa_category='".$this->id."' AND (aa_parent IS NULL OR NOT EXISTS (SELECT * FROM ach_perk WHERE ap_achievement=aa_id AND NOT EXISTS (SELECT * FROM ach_player_perk WHERE app_player='".$_USER->getID()."' AND app_perk=ap_id))) AND (aa_tie_race IS NULL OR aa_tie_race='".$_USER->getRace()."') AND (aa_tie_cult IS NULL OR aa_tie_cult='".mysql_real_escape_string($cult)."') AND (aa_tie_civ IS NULL OR aa_tie_civ='".mysql_real_escape_string($civ)."') ORDER by aal_name ASC");
$res = $DBc->sqlQuery("SELECT * FROM ach_achievement LEFT JOIN (ach_achievement_lang) ON (aal_lang='".$_USER->getLang()."' AND aal_achievement=aa_id) WHERE aa_category='".$this->id."' AND (aa_parent IS NULL OR NOT EXISTS (SELECT * FROM ach_perk WHERE ap_achievement=aa_id AND NOT EXISTS (SELECT * FROM ach_player_perk WHERE app_player='".$_USER->getID()."' AND app_perk=ap_id))) AND (aa_tie_race IS NULL OR aa_tie_race LIKE '".$_USER->getRace()."') AND (aa_tie_cult IS NULL OR aa_tie_cult LIKE '".$cult."') AND (aa_tie_civ IS NULL OR aa_tie_civ LIKE '".$civ."') ORDER by aal_name ASC");
#parent!!!!
$sz = sizeof($res);
for($i=0;$i<$sz;$i++) {

View file

@ -1,5 +1,11 @@
<?php
abstract class AchList extends Parentum {
/*---------------------------
This class organizes nodes to distinguish between "open" and "done" nodes.
child_open and child_done refer to the index set in Parentum::nodes[]
---------------------------*/
protected $child_done = array();
protected $child_open = array();
@ -43,11 +49,7 @@
final function removeChildDone($idx) {
echo "try removing done child: ".$idx;
#$res = array_search($idx,$this->child_done);
#if($res != false) {
# unset($this->child_done[$res]);
# echo " ... done<br>";
#}
foreach($this->child_done as $key=>$elem) {
if($elem == $idx) {
unset($this->child_done[$key]);
@ -74,12 +76,7 @@
final function removeChildOpen($idx) {
echo "try removing open child: ".$idx;
#$res = array_search($idx,$this->child_open);
#if($res != false) {
# unset($this->child_open[$res]);
# echo " ... done<br>";
#}
foreach($this->child_open as $key=>$elem) {
if($elem == $idx) {
unset($this->child_open[$key]);
@ -89,26 +86,8 @@
}
echo var_export($this->child_open,true);
}
/*final function unsetOpen($idx) {
foreach($this->child_open as $key=>$elem) {
if($elem == $idx) {
unset($this->child_open[$key]);
break;
}
}
}
final function unsetDone($idx) {
foreach($this->child_done as $key=>$elem) {
if($elem == $idx) {
unset($this->child_done[$key]);
break;
}
}
}*/
#OVERRIDE Parentum::removeChild()
#@OVERRIDE Parentum::removeChild()
function removeChild($id) {
$n = parent::removeChild($id);
if($n != false && $n != null) {

View file

@ -1,5 +1,10 @@
<?php
trait InDev {
/*---------------------------
This trait provides basic functionality used to
handle "in development" flags.
---------------------------*/
protected $dev;
function inDev() {
@ -9,5 +14,20 @@
function getDev() {
return $this->dev;
}
function setInDev($tf) {
if($tf == true) {
$this->setDev(1);
}
else {
$this->setDev(0);
}
$this->update();
}
function setDev($d) {
$this->dev = $d;
}
}
?>

View file

@ -1,5 +1,16 @@
<?php
class NodeIterator {
/*---------------------------
The NodeIterator can be used just like a foreach() loop to iterate
arrays.
Sample:
$iter = new NodeIterator(array());
while($iter->hasNext()) {
$curr = $iter->getNext();
// ...
}
---------------------------*/
private $nodes;
private $curr;

View file

@ -1,5 +1,11 @@
<?php
trait Node {
/*---------------------------
This trait provides basic functionality common to nodes.
Every node has an id, and InDeX and a parent.
---------------------------*/
protected $idx;
protected $id;
protected $parent;

View file

@ -42,10 +42,6 @@
return $tmp;
}
#function drawTree() {
# $this->avl->inorder();
#}
function removeChild($id) {
if($this->isEmpty()) {
return null;

View file

@ -1,5 +1,11 @@
<?php
interface Tieable {
/*---------------------------
The Tieable interface is needed to define methods required
by Parentum classes that have child nodes that vary depending
on a user's cult of civ allegiance.
---------------------------*/
function isTiedCult();
function isTiedCiv();