Added full source code

This commit is contained in:
Emmanuel BENOîT 2016-01-10 11:01:49 +01:00
commit 33f8586698
1377 changed files with 123808 additions and 0 deletions

View file

@ -0,0 +1,35 @@
<?php
class beta5_bq_append {
function beta5_bq_append($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
$this->rules = $this->lib->game->getLib('beta5/rules');
}
// Add items to a planet's build queue
function run($id, $nb, $type) {
$q = $this->db->query("SELECT owner FROM planet WHERE id = $id");
list($uid) = dbFetchArray($q);
$ru = $this->rules->call('get', $uid);
$q = $this->db->query("SELECT MAX(bq_order) FROM buildqueue WHERE planet = $id");
if (dbCount($q)) {
list($o) = dbFetchArray($q);
if (is_null($o)) {
$o = -1;
}
} else {
$o = -1;
}
$o ++;
$this->db->query("INSERT INTO buildqueue VALUES($id, $o, $type, $nb, 0)");
$cost = $ru['build_cost_'.$this->lib->mainClass->types[$type]] * $nb;
$this->db->query("UPDATE player SET cash = cash - $cost WHERE id = $uid");
}
}
?>

View file

@ -0,0 +1,32 @@
<?php
class beta5_bq_flush {
function beta5_bq_flush($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
$this->rules = $this->lib->game->getLib('beta5/rules');
}
// Flush a planet's build queue
function run($id) {
$q = $this->db->query("SELECT owner FROM planet WHERE id = $id");
list($uid) = dbFetchArray($q);
if (is_null($uid)) {
return;
}
$ru = $this->rules->call('get', $uid);
$sum = 0;
$q = $this->db->query("SELECT item,quantity FROM buildqueue WHERE planet = $id");
while ($r = dbFetchArray($q)) {
$sum += $r[1] * $ru['build_cost_'.$this->lib->mainClass->types[$r[0]]];
}
$this->db->query("DELETE FROM buildqueue WHERE planet = $id");
$this->db->query("UPDATE player SET cash = cash + $sum WHERE id = $uid");
}
}
?>

View file

@ -0,0 +1,52 @@
<?php
class beta5_bq_get {
function beta5_bq_get($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
$this->rules = $this->lib->game->getLib('beta5/rules');
}
// Returns the contents of a planet's build queue
function run($id) {
$q = $this->db->query("SELECT owner,mfact,corruption FROM planet WHERE id=$id");
list($uid, $mf, $cl) = dbFetchArray($q);
$ru = $this->rules->call('get', $uid);
$mp = $ru['mf_productivity'] * $ru['mf_productivity_factor'] * $mf;
if ($mp == 0) {
$mp = 1;
}
$cl = $cl / 32000;
if ($cl > .1) {
$mp = floor($mp * (1.1 - $cl));
}
$q = $this->db->query("SELECT item,quantity,workunits FROM buildqueue WHERE planet = $id ORDER BY bq_order ASC");
$bq = array();
$cwu = 0;
while ($r = dbFetchArray($q)) {
$i = array(
"type" => $r[0],
"quantity" => $r[1],
"workunits" => $r[2]
);
$units = $ru['workunits_'.$this->lib->mainClass->types[$r[0]]] * $r[1] - $r[2];
$i['units'] = $units;
$cwu += $units;
$mod = $units % $mp;
$ttb = ($units - $mod) / $mp + ($mod ? 1 : 0);
$i['time'] = $ttb;
$mod = $cwu % $mp;
$ttb = ($cwu - $mod) / $mp + ($mod ? 1 : 0);
$i['ctime'] = $ttb;
$i['cost'] = $r[1] * $ru['build_cost_'.$this->lib->mainClass->types[$r[0]]];
array_push($bq, $i);
}
return $bq;
}
}
?>

View file

@ -0,0 +1,41 @@
<?php
class beta5_bq_getReplacementCost {
function beta5_bq_getReplacementCost($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
$this->rules = $this->lib->game->getLib('beta5/rules');
}
// Computes the cost of replacing a set of build queue items
function run($pid, $items, $rCost) {
if (count($items) == 0) {
return 0;
}
$q = $this->db->query("SELECT owner FROM planet WHERE id = $pid");
list($uid) = dbFetchArray($q);
$ru = $this->rules->call('get', $uid);
if (count($items) == 1) {
$wc = "=".$items[0];
} else {
$wc = "IN (" . join(',', $items) . ")";
}
$q = $this->db->query("SELECT item,quantity FROM buildqueue WHERE planet = $pid AND bq_order $wc");
if (!dbCount($q)) {
return 0;
}
$sum = 0;
while ($r = dbFetchArray($q)) {
$sum -= $r[1] * $ru['build_cost_'.$this->lib->mainClass->types[$r[0]]];
$sum += $rCost;
}
return $sum;
}
}
?>

View file

@ -0,0 +1,30 @@
<?php
class beta5_bq_remove {
function beta5_bq_remove($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
$this->rules = $this->lib->game->getLib('beta5/rules');
}
// Removes an item from a build queue
function run($pid, $item) {
$q = $this->db->query("SELECT owner FROM planet WHERE id = $pid");
list($uid) = dbFetchArray($q);
$ru = $this->rules->call('get', $uid);
$q = $this->db->query("SELECT item,quantity FROM buildqueue WHERE planet = $pid AND bq_order = $item");
if (!dbCount($q)) {
return;
}
list($t,$n) = dbFetchArray($q);
$cost = $n * $ru['build_cost_'.$this->lib->mainClass->types[$t]];
$this->db->query("DELETE FROM buildqueue WHERE planet = $pid AND bq_order = $item");
$this->db->query("UPDATE player SET cash = cash + $cost WHERE id = $uid");
}
}
?>

View file

@ -0,0 +1,24 @@
<?php
class beta5_bq_reorder {
function beta5_bq_reorder($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
}
// Reorders the build queue
function run($pid) {
$q = $this->db->query("SELECT bq_order FROM buildqueue WHERE planet = $pid ORDER BY bq_order ASC");
$i = 0;
while ($r = dbFetchArray($q)) {
if ($r[0] != $i) {
$this->db->query("UPDATE buildqueue SET bq_order = $i WHERE planet = $pid AND bq_order = ".$r[0]);
}
$i ++;
}
}
}
?>

View file

@ -0,0 +1,43 @@
<?php
class beta5_bq_replace {
function beta5_bq_replace($lib) {
$this->lib = $lib;
$this->db = $this->lib->game->db;
$this->rules = $this->lib->game->getLib('beta5/rules');
}
// Replaces items in a build queue
function run($pid, $items, $nb, $type) {
if (count($items) == 0) {
return;
}
$q = $this->db->query("SELECT owner FROM planet WHERE id = $pid");
list($uid) = dbFetchArray($q);
$ru = $this->rules->call('get', $uid);
if (count($items) == 1) {
$wc = "=".$items[0];
} else {
$wc = "IN (" . join(',', $items) . ")";
}
$q = $this->db->query("SELECT item,quantity FROM buildqueue WHERE planet = $pid AND bq_order $wc");
if (!dbCount($q)) {
return;
}
$rCost = $nb * $ru['build_cost_'.$this->lib->mainClass->types[$type]];
$sum = 0;
while ($r = dbFetchArray($q)) {
$sum += $r[1] * $ru['build_cost_'.$this->lib->mainClass->types[$r[0]]];
$sum -= $rCost;
}
$this->db->query("UPDATE buildqueue SET item=$type,quantity=$nb,workunits=0 WHERE planet = $pid AND bq_order $wc");
$this->db->query("UPDATE player SET cash = cash + ($sum) WHERE id = $uid");
}
}
?>