Added full source code
This commit is contained in:
commit
33f8586698
1377 changed files with 123808 additions and 0 deletions
scripts/game/beta5/bq/library
35
scripts/game/beta5/bq/library/append.inc
Normal file
35
scripts/game/beta5/bq/library/append.inc
Normal 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");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
32
scripts/game/beta5/bq/library/flush.inc
Normal file
32
scripts/game/beta5/bq/library/flush.inc
Normal 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");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
52
scripts/game/beta5/bq/library/get.inc
Normal file
52
scripts/game/beta5/bq/library/get.inc
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
41
scripts/game/beta5/bq/library/getReplacementCost.inc
Normal file
41
scripts/game/beta5/bq/library/getReplacementCost.inc
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
30
scripts/game/beta5/bq/library/remove.inc
Normal file
30
scripts/game/beta5/bq/library/remove.inc
Normal 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");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
24
scripts/game/beta5/bq/library/reorder.inc
Normal file
24
scripts/game/beta5/bq/library/reorder.inc
Normal 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 ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
43
scripts/game/beta5/bq/library/replace.inc
Normal file
43
scripts/game/beta5/bq/library/replace.inc
Normal 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");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Reference in a new issue