2008-01-01 18:07:13 +00:00
|
|
|
<?php
|
|
|
|
|
2008-01-28 22:42:05 +00:00
|
|
|
class BoltRandom extends BoltSet {
|
2008-01-01 18:07:13 +00:00
|
|
|
public $units;
|
|
|
|
function __construct($name, $units, $number) {
|
2008-01-28 22:42:05 +00:00
|
|
|
parent::__construct($name, $units, $number);
|
2008-01-01 18:07:13 +00:00
|
|
|
}
|
|
|
|
|
2008-01-28 22:42:05 +00:00
|
|
|
function order(&$state_rec) {
|
|
|
|
if ($state_rec) {
|
|
|
|
$seed = $state_rec['seed'];
|
2008-01-01 18:07:13 +00:00
|
|
|
} else {
|
|
|
|
$seed = ((double)microtime()*1000000);
|
|
|
|
$state_rec['seed'] = $seed;
|
|
|
|
}
|
2008-01-28 22:42:05 +00:00
|
|
|
srand($seed);
|
|
|
|
shuffle($this->units);
|
2008-01-01 18:07:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function random() {
|
|
|
|
$args = func_get_args();
|
|
|
|
$units = array();
|
|
|
|
$name = "";
|
|
|
|
$number = 1;
|
|
|
|
foreach ($args as $arg) {
|
|
|
|
if (is_array($arg)) {
|
|
|
|
switch ($arg[0]) {
|
|
|
|
case 'name': $name = $arg[1]; break;
|
|
|
|
case 'title': $title = $arg[1]; break;
|
|
|
|
case 'number': $number = $arg[1]; break;
|
|
|
|
default: echo "Unrecognized array arg: ", $arg[0], "\n"; break;
|
|
|
|
}
|
|
|
|
} else if (is_object($arg)) {
|
|
|
|
if (is_subclass_of($arg, "BoltUnit")) {
|
|
|
|
$units[] = $arg;
|
|
|
|
} else {
|
|
|
|
echo "Unrecognized arg: ";
|
|
|
|
print_r($arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new BoltRandom($name, $units, $number);
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|