Added full source code
This commit is contained in:
commit
33f8586698
1377 changed files with 123808 additions and 0 deletions
151
scripts/game/beta5/fleet/library/arrival.inc
Normal file
151
scripts/game/beta5/fleet/library/arrival.inc
Normal file
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
|
||||
class beta5_fleet_arrival {
|
||||
|
||||
function beta5_fleet_arrival($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->move = $this->lib->game->getLib('beta5/moving');
|
||||
$this->planets = $this->lib->game->getLib('beta5/planet');
|
||||
$this->players = $this->lib->game->getLib('beta5/player');
|
||||
$this->rules = $this->lib->game->getLib('beta5/rules');
|
||||
}
|
||||
|
||||
|
||||
// Handles a fleet's arrival
|
||||
function run($fid, $dest, $from, $nStatus = null) {
|
||||
// Get complete fleet data
|
||||
$q = $this->db->query("SELECT * FROM fleet WHERE id=$fid");
|
||||
$f = dbFetchHash($q);
|
||||
if (is_null($f['owner'])) {
|
||||
logText("beta5/fleetArrival($fid,$dest,$from): BUG! Fleet has no owner!", LOG_ERR);
|
||||
return;
|
||||
}
|
||||
if (is_null($nStatus)) {
|
||||
$nStatus = ($f['attacking'] == 't');
|
||||
}
|
||||
|
||||
// Get destination planet owner
|
||||
$po = $this->planets->call('getOwner', $dest);
|
||||
if (!is_null($po) && $po != $f['owner']) {
|
||||
// Is the fleet owner an enemy of the planet owner?
|
||||
$isEnemy = $this->players->call('isEnemy', $po, $f['owner']);
|
||||
if (!$isEnemy) {
|
||||
// Get fleet owner data
|
||||
$foi = $this->players->call('get', $f['owner']);
|
||||
// Check for enemy alliance
|
||||
$isEnemy = (!is_null($foi['aid']) && $this->players->call('isAllianceEnemy', $po, $foi['aid']));
|
||||
}
|
||||
} else {
|
||||
$isEnemy = false;
|
||||
}
|
||||
|
||||
// Check whether the player already has fleets at that location,
|
||||
// and if he does, get their current status
|
||||
if (!$isEnemy) {
|
||||
$q = $this->db->query("SELECT attacking FROM fleet WHERE location=$dest AND owner=".$f['owner']." LIMIT 1");
|
||||
if ($q && dbCount($q)) {
|
||||
list($aa) = dbFetchArray($q);
|
||||
$isEnemy = ($aa == 't');
|
||||
}
|
||||
}
|
||||
|
||||
// Set attack status
|
||||
$att = ($po != $f['owner']) && ($isEnemy || $nStatus);
|
||||
logText("beta5/fleetArrival($fid,$dest,$from,{$f['owner']}): Attack=".($att?1:0), LOG_DEBUG);
|
||||
if (is_array($_SESSION[game::sessName()])) {
|
||||
logText("Fleet $fid was being controlled by player #{$_SESSION[game::sessName()]['player']}");
|
||||
}
|
||||
|
||||
if ($att) {
|
||||
if (($split = $this->hsWindowCollapsing($po, $f, $dest, $from)) === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Switch the player's fleets to attack at that location if the fleet arriving is attacking
|
||||
$this->db->query("UPDATE fleet SET attacking=TRUE,can_move='B' WHERE location=$dest AND NOT attacking AND owner=".$f['owner']);
|
||||
} else {
|
||||
$split = "";
|
||||
}
|
||||
|
||||
// Update the fleet's record
|
||||
$this->db->query("UPDATE fleet SET location=$dest,time_spent=0,attacking=".dbBool($att).",can_move='".($att?'B':'H')."'$split WHERE id=$fid");
|
||||
|
||||
// Make sure the system the fleet has arrived in can't be assigned to a new player
|
||||
$pinf = $this->planets->call('byId', $dest);
|
||||
$this->db->query("UPDATE system SET assigned=TRUE WHERE id=".$pinf['system']);
|
||||
|
||||
// Add a fleet arrival entry to the list
|
||||
if (!is_array($this->lib->mainClass->fleetArrivals[$dest])) {
|
||||
$this->lib->mainClass->fleetArrivals[$dest] = array(array(), array());
|
||||
}
|
||||
array_push($this->lib->mainClass->fleetArrivals[$dest][$att?1:0], array($fid, $from));
|
||||
|
||||
// Clear the fleet cache
|
||||
$this->lib->call('invCache', $fid);
|
||||
}
|
||||
|
||||
|
||||
function hsWindowCollapsing($po, $f, $dst, $ori) {
|
||||
// Apply HS window collapsing
|
||||
$r = $this->rules->call('get', $po);
|
||||
$rnd = rand(0,$r['prevent_hs_exit']*10);
|
||||
$splitG = floor($rnd * $f['gaships'] / 100);
|
||||
$splitF = floor($rnd * $f['fighters'] / 100);
|
||||
$splitC = ceil($rnd * $f['cruisers'] / 100);
|
||||
$splitB = ceil($rnd * $f['bcruisers'] / 100);
|
||||
if (!($rnd && ($splitC || $splitB))) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// WE HAVE A WINNER!
|
||||
|
||||
if (is_null($f['moving'])) {
|
||||
$or = $this->rules->call('get', $f['owner']);
|
||||
}
|
||||
|
||||
if ($f['gaships'] == $splitG && $f['fighters'] == $splitF && $f['cruisers'] == $splitC && $f['bcruisers'] == $splitB) {
|
||||
// The complete fleet has to be delayed
|
||||
logText("Fleet #{$f['id']} was prevented from dropping out of HS", LOG_DEBUG);
|
||||
if (is_null($f['moving'])) {
|
||||
// The fleet dropped out of Hyperspace, create a move order
|
||||
$fmo = $this->move->call('newObject', $ori, $dst, $or['capital_ship_speed'], ($f['cruisers'] > 0), null);
|
||||
$this->db->query("UPDATE moving_object SET changed=60,time_left=1 WHERE id=$fmo");
|
||||
$this->db->query("UPDATE fleet SET moving=$fmo,waiting=NULL WHERE id={$f['id']}");
|
||||
logText("Fleet #{$f['id']} -> created new moving object", LOG_DEBUG);
|
||||
} else {
|
||||
// The fleet was moving, just modify the order
|
||||
$this->db->query("UPDATE moving_object SET changed=60,time_left=1 WHERE id={$f['moving']}");
|
||||
logText("Fleet #{$f['id']} -> modified existing moving object", LOG_DEBUG);
|
||||
}
|
||||
$fullFleet = true;
|
||||
} else {
|
||||
logText("Fleet {$f['id']} got split by HS windows collapsing ($splitG/$splitF/$splitC/$splitB out of {$f['gaships']}/{$f['fighters']}/{$f['cruisers']}/{$f['bcruisers']})", LOG_DEBUG);
|
||||
|
||||
// Split fleet
|
||||
$fullFleet = ",gaships=" . ($f['gaships'] - $splitG);
|
||||
$fullFleet .= ",fighters=" . ($f['fighters'] - $splitF);
|
||||
$fullFleet .= ",cruisers=" . ($f['cruisers'] - $splitC);
|
||||
$fullFleet .= ",bcruisers=" . ($f['bcruisers'] - $splitB);
|
||||
|
||||
if (is_null($f['moving'])) {
|
||||
// The fleet dropped out of Hyperspace, create a move order
|
||||
$fmo = $this->move->call('newObject', $ori, $dst, $or['capital_ship_speed'], ($f['cruisers'] > 0), null);
|
||||
logText("Fleet #{$f['id']} -> created new moving object", LOG_DEBUG);
|
||||
} else {
|
||||
// The fleet was moving, duplicate the order
|
||||
$fmo = $this->move->call('cloneObject', $f['moving']);
|
||||
logText("Fleet #{$f['id']} -> cloned existing moving object", LOG_DEBUG);
|
||||
}
|
||||
$this->db->query("UPDATE moving_object SET changed=60,time_left=1 WHERE id=$fmo");
|
||||
|
||||
// Generate new fleet
|
||||
$this->db->query("INSERT INTO fleet(owner,gaships,fighters,cruisers,bcruisers,attacking,moving) VALUES ("
|
||||
. $f['owner'] . ",$splitG,$splitF,$splitC,$splitB,TRUE,$fmo)");
|
||||
}
|
||||
|
||||
return $fullFleet;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
83
scripts/game/beta5/fleet/library/autoSplit.inc
Normal file
83
scripts/game/beta5/fleet/library/autoSplit.inc
Normal file
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
class beta5_fleet_autoSplit {
|
||||
|
||||
function beta5_fleet_autoSplit($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->standby = $this->lib->game->getLib('beta5/standby');
|
||||
$this->moving = $this->lib->game->getLib('beta5/moving');
|
||||
$this->rules = $this->lib->game->getLib('beta5/rules');
|
||||
}
|
||||
|
||||
|
||||
// Automatically split a fleet
|
||||
function run($fid, $newName, $count) {
|
||||
// Get fleet data
|
||||
$f = $this->lib->call('get', $fid, true);
|
||||
if (is_null($f) || $f['can_move'] != 'Y' || !is_null($f['sale_info'])) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get player rules
|
||||
$rules = $this->rules->call('get', $f['owner']);
|
||||
|
||||
// Generate new ship counts
|
||||
$sg = floor($f['gaships'] / $count); $sf = floor($f['fighters'] / $count);
|
||||
$sc = floor($f['cruisers'] / $count); $sb = floor($f['bcruisers'] / $count);
|
||||
$count --;
|
||||
$mg = $count * $sg; $mf = $count * $sf;
|
||||
$mc = $count * $sc; $mb = $count * $sb;
|
||||
|
||||
// If we're moving or standing by in Hyperspace, we need to make sure both
|
||||
// the new and old fleets are HS-capable
|
||||
if ((!is_null($f['move']) && $f['move']['hyperspace'] == 't') || !is_null($f['wait'])) {
|
||||
$nu = $rules['gaship_space'] * $sg + $rules['fighter_space'] * $sf;
|
||||
$na = $rules['cruiser_haul'] * $sc + $rules['bcruiser_haul'] * $sb;
|
||||
$ou = $rules['gaship_space'] * ($f['gaships'] - $mg) + $rules['fighter_space'] * ($f['fighters'] - $mf);
|
||||
$oa = $rules['cruiser_haul'] * ($f['cruisers'] - $mc) + $rules['bcruiser_haul'] * ($f['bcruisers'] - $mb);
|
||||
if ($nu > $na || $ou > $oa) {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate code that will set the new fleets' orders
|
||||
if (is_null($f['location'])) {
|
||||
$location = "NULL";
|
||||
if (is_null($f['moving'])) {
|
||||
$moving = "NULL";
|
||||
$oCode = '$waiting = $this->standby->call("create",'.$f['wait']['time_left'].",".$f['wait']['drop_point']
|
||||
. ','.$f['wait']['origin'].','.$f['wait']['time_spent'].');';
|
||||
} else {
|
||||
$waiting = "NULL";
|
||||
$oCode = '$moving = $this->moving->call("cloneObject", '.$f['moving'].');';
|
||||
}
|
||||
} else {
|
||||
$location = $f['location'];
|
||||
$moving = $waiting = 'NULL';
|
||||
$oCode = null;
|
||||
}
|
||||
|
||||
// Generate new fleets
|
||||
$nn = addslashes($newName == "" ? preg_replace('/ [0-9]+$/', '', $f['name']) : $newName);
|
||||
for ($i=0;$i<$count;$i++) {
|
||||
if ($oCode != "") {
|
||||
eval($oCode);
|
||||
}
|
||||
$nnb = $count > 1 ? (" " . ($i + 1)) : "";
|
||||
$this->db->query("INSERT INTO fleet(owner,name,location,gaships,fighters,cruisers,bcruisers,attacking,moving,waiting,time_spent) VALUES("
|
||||
.$f['owner'].",'$nn$nnb',$location,$sg,$sf,$sc,$sb,"
|
||||
.dbBool($f['attacking'] == 't').",$moving,$waiting,{$f['time_spent']})");
|
||||
}
|
||||
|
||||
// Update original fleet
|
||||
$this->db->query("UPDATE fleet SET gaships=gaships-$mg,fighters=fighters-$mf,cruisers=cruisers-$mc,bcruisers=bcruisers-$mb "
|
||||
."WHERE id=$fid");
|
||||
$this->db->query("DELETE FROM beacon_detection WHERE fleet = $fid");
|
||||
|
||||
$this->lib->call('invCache', $fid);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
58
scripts/game/beta5/fleet/library/disband.inc
Normal file
58
scripts/game/beta5/fleet/library/disband.inc
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
class beta5_fleet_disband {
|
||||
|
||||
function beta5_fleet_disband($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->planets = $this->lib->game->getLib('beta5/planet');
|
||||
$this->sales = $this->lib->game->getLib('beta5/sale');
|
||||
}
|
||||
|
||||
|
||||
// Disbands a fleet and removes any sales / movement / stand-by
|
||||
// entries associated with it
|
||||
function run($fId, $final = false) {
|
||||
// Get fleet data
|
||||
$f = $this->lib->call('get', $fId);
|
||||
if (is_null($f)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!is_null($f['sale_info'])) {
|
||||
// It is for sale
|
||||
$r = $this->sales->call('cancel', $f['owner'], $f['sale_info']['sale']['id']);
|
||||
if (!($r || $final)) {
|
||||
return 2;
|
||||
} elseif (!$r) {
|
||||
// Sale was finalized and we can't cancel; assume no planet is for sale.
|
||||
// FIXME: send message
|
||||
$this->db->query("UPDATE fleet SET sale=NULL,owner=".$f['sale_info']['sale']['sold_to']." WHERE id=$fId");
|
||||
// FIXME: add history
|
||||
$this->db->query("DELETE FROM sale WHERE id=".$f['sale_info']['sale']['id']);
|
||||
}
|
||||
} elseif (!is_null($f['waiting'])) {
|
||||
// It is standing by
|
||||
$this->db->query("DELETE FROM hs_wait WHERE id=".$f['waiting']);
|
||||
} elseif (!is_null($f['moving'])) {
|
||||
// It's moving?
|
||||
$this->db->query("DELETE FROM moving_object WHERE id=".$f['moving']);
|
||||
if (!is_null($f['move']['wait_order'])) {
|
||||
$this->db->query("DELETE FROM hs_wait WHERE id=".$f['move']['wait_order']);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove this fleet
|
||||
$this->db->query("DELETE FROM fleet WHERE id=$fId");
|
||||
|
||||
// Update planet status where the fleet was
|
||||
if (!is_null($f['location'])) {
|
||||
$this->planets->call('updateMilStatus', $f['location']);
|
||||
$this->planets->call('updateHappiness', $f['location']);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
69
scripts/game/beta5/fleet/library/get.inc
Normal file
69
scripts/game/beta5/fleet/library/get.inc
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
class beta5_fleet_get {
|
||||
|
||||
function beta5_fleet_get($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
// Returns data regarding a fleet
|
||||
function run($id, $update = false) {
|
||||
if ($update) {
|
||||
$uqs = " FOR UPDATE";
|
||||
} else {
|
||||
$uqs = "";
|
||||
}
|
||||
|
||||
// Return the fleet cache's contents if the fleet is in there
|
||||
if (!is_null($this->lib->mainClass->fleets[$id])) {
|
||||
return $this->lib->mainClass->fleets[$id];
|
||||
}
|
||||
|
||||
// Get the complete row
|
||||
$q = $this->db->query("SELECT * FROM fleet WHERE id = $id $uqs");
|
||||
if (!($q && dbCount($q) == 1)) {
|
||||
return null;
|
||||
}
|
||||
$fdata = dbFetchHash($q);
|
||||
|
||||
// Extract movement data
|
||||
if (!is_null($fdata['moving'])) {
|
||||
$q = $this->db->query("SELECT * FROM moving_object WHERE id=" . $fdata['moving'] . $uqs);
|
||||
if ($q && dbCount($q) == 1) {
|
||||
$fdata['move'] = dbFetchHash($q);
|
||||
if (!is_null($fdata['move']['wait_order'])) {
|
||||
$fdata['waiting'] = $fdata['move']['wait_order'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Extract HS standby orders
|
||||
if (!is_null($fdata['waiting'])) {
|
||||
$q = $this->db->query("SELECT * FROM hs_wait WHERE id=" . $fdata['waiting'] . $uqs);
|
||||
if ($q && dbCount($q) == 1) {
|
||||
$fdata['wait'] = dbFetchHash($q);
|
||||
}
|
||||
}
|
||||
|
||||
// Extract sales data
|
||||
$q = $this->db->query("SELECT * FROM sale WHERE fleet=" . $fdata['id'] . $uqs);
|
||||
if (dbCount($q)) {
|
||||
$a = array('sale' => dbFetchHash($q));
|
||||
$q = $this->db->query("SELECT * FROM public_offer WHERE offer=" . $a['sale']['id'] . $uqs);
|
||||
if ($q && dbCount($q) == 1) {
|
||||
$a['public'] = dbFetchHash($q);
|
||||
}
|
||||
$q = $this->db->query("SELECT * FROM private_offer WHERE offer=" . $a['sale']['id'] . $uqs);
|
||||
if ($q && dbCount($q) == 1) {
|
||||
$a['private'] = dbFetchHash($q);
|
||||
}
|
||||
$fdata['sale_info'] = $a;
|
||||
}
|
||||
|
||||
return ($this->lib->mainClass->fleets[$id] = $fdata);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
22
scripts/game/beta5/fleet/library/getLocation.inc
Normal file
22
scripts/game/beta5/fleet/library/getLocation.inc
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
class beta5_fleet_getLocation {
|
||||
|
||||
function beta5_fleet_getLocation($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
// Returns the list of fleets in orbit around a planet
|
||||
function run($pid, $pl = null) {
|
||||
$q = $this->db->query("SELECT id,name FROM fleet WHERE location = $pid" . (is_null($pl) ? "" : " AND owner=$pl"));
|
||||
$a = array();
|
||||
while ($r = dbFetchArray($q)) {
|
||||
$a[$r[0]] = $r[1];
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
22
scripts/game/beta5/fleet/library/getPlayerLocations.inc
Normal file
22
scripts/game/beta5/fleet/library/getPlayerLocations.inc
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
class beta5_fleet_getPlayerLocations {
|
||||
|
||||
function beta5_fleet_getPlayerLocations($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
// Returns all of the locations at which a player has stationned fleets
|
||||
function run($pid) {
|
||||
$q = $this->db->query("SELECT DISTINCT location FROM fleet WHERE location IS NOT NULL AND owner=$pid");
|
||||
$a = array();
|
||||
while ($r = dbFetchArray($q)) {
|
||||
array_push($a, $r[0]);
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
28
scripts/game/beta5/fleet/library/getPower.inc
Normal file
28
scripts/game/beta5/fleet/library/getPower.inc
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
class beta5_fleet_getPower {
|
||||
var $ePower = array();
|
||||
|
||||
function beta5_fleet_getPower($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->rules = $this->lib->game->getLib('beta5/rules');
|
||||
}
|
||||
|
||||
|
||||
// Computes a fleet's power
|
||||
function run($pl, $g, $f, $c, $b) {
|
||||
if (!is_array($this->ePower[$pl])) {
|
||||
$r = $this->rules->call('get', $pl);
|
||||
$a = array('gaship','fighter','cruiser','bcruiser');
|
||||
$this->ePower[$pl] = array();
|
||||
foreach ($a as $st) {
|
||||
$this->ePower[$pl][$st] = floor($r[$st."_power"] * $r['effective_fleet_power'] / 100);
|
||||
}
|
||||
}
|
||||
$r = $this->ePower[$pl];
|
||||
return $g * $r['gaship'] + $f * $r['fighter'] + $c * $r['cruiser'] + $b * $r['bcruiser'];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
85
scripts/game/beta5/fleet/library/getStats.inc
Normal file
85
scripts/game/beta5/fleet/library/getStats.inc
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
class beta5_fleet_getStats {
|
||||
|
||||
function beta5_fleet_getStats($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
// Returns data regarding current fleets
|
||||
function run($pid) {
|
||||
// Get count and ship types
|
||||
$q = $this->db->query(
|
||||
"SELECT COUNT(*), SUM(gaships), SUM(fighters), SUM(cruisers), SUM(bcruisers)"
|
||||
. " FROM fleet WHERE owner = $pid GROUP BY owner"
|
||||
);
|
||||
$cnt = dbFetchArray($q);
|
||||
if (!$cnt) {
|
||||
$cnt = array(0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
// Fleets at home
|
||||
$q = $this->db->query(
|
||||
"SELECT COUNT(*) FROM fleet f, planet p "
|
||||
. "WHERE f.owner = $pid AND f.location = p.id AND p.owner = $pid"
|
||||
);
|
||||
list($fah) = dbFetchArray($q);
|
||||
// Fleets at home, in battle
|
||||
$q = $this->db->query(
|
||||
"SELECT COUNT(*) FROM fleet f, planet p, fleet f2 "
|
||||
. "WHERE f.owner = $pid AND f.location = p.id AND p.owner = $pid "
|
||||
. "AND f2.location = p.id AND f2.attacking"
|
||||
);
|
||||
list($fahb) = dbFetchArray($q);
|
||||
|
||||
// Fleets on foreign planets
|
||||
$q = $this->db->query(
|
||||
"SELECT COUNT(*) FROM fleet f,planet p "
|
||||
. "WHERE f.owner=$pid AND f.location=p.id"
|
||||
. " AND (p.owner IS NULL OR p.owner<>$pid)"
|
||||
);
|
||||
list($af) = dbFetchArray($q);
|
||||
// Fleets on foreign planets, in battle
|
||||
$q = $this->db->query(
|
||||
"SELECT COUNT(*) FROM fleet f,planet p,fleet f2 "
|
||||
. "WHERE f.owner=$pid AND f.location=p.id AND (p.owner IS NULL OR p.owner<>$pid) "
|
||||
. "AND f2.location=p.id AND (f2.attacking AND NOT f.attacking)"
|
||||
);
|
||||
list($afb1) = dbFetchArray($q);
|
||||
$q = $this->db->query(
|
||||
"SELECT COUNT(*) FROM fleet f, planet p "
|
||||
. "WHERE f.owner=$pid AND f.location=p.id AND (p.owner IS NULL OR p.owner<>$pid) "
|
||||
. "AND f.attacking"
|
||||
);
|
||||
list($afb2) = dbFetchArray($q);
|
||||
$afb = $afb1 + $afb2;
|
||||
|
||||
// Moving fleets
|
||||
$q = $this->db->query("SELECT COUNT(*) FROM fleet WHERE owner = $pid AND moving IS NOT NULL");
|
||||
list($mf) = dbFetchArray($q);
|
||||
// Waiting fleets
|
||||
$q = $this->db->query("SELECT COUNT(*) FROM fleet WHERE owner = $pid AND waiting IS NOT NULL");
|
||||
list($wf) = dbFetchArray($q);
|
||||
|
||||
return array(
|
||||
"fleets" => $cnt[0],
|
||||
"battle" => $fahb+$afb,
|
||||
"upkeep" => $this->lib->call('getUpkeep', $pid, $cnt[1], $cnt[2], $cnt[3], $cnt[4]),
|
||||
"power" => $this->lib->call('getPower', $pid, $cnt[1], $cnt[2], $cnt[3], $cnt[4]),
|
||||
"at_home" => $fah,
|
||||
"home_battle" => $fahb,
|
||||
"foreign" => $af,
|
||||
"foreign_battle" => $afb,
|
||||
"moving" => $mf,
|
||||
"waiting" => $wf,
|
||||
"gaships" => $cnt[1],
|
||||
"fighters" => $cnt[2],
|
||||
"cruisers" => $cnt[3],
|
||||
"bcruisers" => $cnt[4]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
23
scripts/game/beta5/fleet/library/getUpkeep.inc
Normal file
23
scripts/game/beta5/fleet/library/getUpkeep.inc
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
class beta5_fleet_getUpkeep {
|
||||
|
||||
function beta5_fleet_getUpkeep($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->rules = $this->lib->game->getLib('beta5/rules');
|
||||
}
|
||||
|
||||
|
||||
// Computes a fleet's upkeep
|
||||
function run($pl, $g, $f, $c, $b) {
|
||||
$r = $this->rules->call('get', $pl);
|
||||
$fu = $g * $r['gaship_upkeep'];
|
||||
$fu += $f * $r['fighter_upkeep'];
|
||||
$fu += $c * $r['cruiser_upkeep'];
|
||||
$fu += $b * $r['bcruiser_upkeep'];
|
||||
return $fu;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
163
scripts/game/beta5/fleet/library/merge.inc
Normal file
163
scripts/game/beta5/fleet/library/merge.inc
Normal file
|
@ -0,0 +1,163 @@
|
|||
<?php
|
||||
|
||||
class beta5_fleet_merge {
|
||||
|
||||
function beta5_fleet_merge($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->moving = $this->lib->game->getLib('beta5/moving');
|
||||
}
|
||||
|
||||
|
||||
// Merge fleets
|
||||
function run($fIds, $okOwners, $newName) {
|
||||
// Did we get fleet IDs?
|
||||
if (!count($fIds)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// Get fleets to merge
|
||||
$q = $this->db->query(
|
||||
"SELECT * FROM fleet "
|
||||
."WHERE id IN (".join(',',$fIds).") AND owner IN (".join(',',$okOwners)
|
||||
.") AND can_move='Y' AND sale IS NULL "
|
||||
."ORDER BY location,owner"
|
||||
);
|
||||
$q2 = $this->db->query("SELECT id FROM sale WHERE fleet IN (".join(',',$fIds).")");
|
||||
if (!$q || !$q2 || dbCount($q) != count($fIds) || dbCount($q2)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// Generate an array from the fleets read and extract
|
||||
// movement / stand-by information
|
||||
$fleets = array(); $mIds = array(); $wIds = array();
|
||||
while ($r = dbFetchHash($q)) {
|
||||
$fleets[$r['id']] = $r;
|
||||
if (!is_null($r['moving'])) {
|
||||
array_push($mIds, $r['moving']);
|
||||
} elseif (!is_null($r['waiting'])) {
|
||||
array_push($wIds, $r['waiting']);
|
||||
}
|
||||
}
|
||||
|
||||
// Extract movement information
|
||||
$move = array();
|
||||
if (count($mIds)) {
|
||||
$q = $this->db->query("SELECT id,m_to,time_left,wait_order,changed FROM moving_object "
|
||||
."WHERE id IN (".join(',',$mIds).")");
|
||||
|
||||
while ($r = dbFetchHash($q)) {
|
||||
$move[$r['id']] = $r;
|
||||
if (!is_null($r['wait_order']))
|
||||
array_push($wIds, $r['wait_order']);
|
||||
}
|
||||
}
|
||||
|
||||
// Extract stand-by information
|
||||
$wait = array();
|
||||
if (count($wIds)) {
|
||||
$q = $this->db->query("SELECT id,drop_point,time_left FROM hs_wait "
|
||||
."WHERE id IN (".join(',',$wIds).")");
|
||||
while ($r = dbFetchHash($q)) {
|
||||
$wait[$r['id']] = $r;
|
||||
}
|
||||
}
|
||||
|
||||
// Group fleets by location / status / owner
|
||||
$gFleets = array();
|
||||
foreach ($fIds as $i) {
|
||||
// Generate identifier and time to wait
|
||||
$lid = $fleets[$i]['owner'].":";
|
||||
$am = ($fleets[$i]['attacking'] == 't');
|
||||
if (!is_null($fleets[$i]['waiting'])) {
|
||||
$lid .= "W:".$wait[$fleets[$i]['waiting']]['drop_point'];
|
||||
$tl = $wait[$fleets[$i]['waiting']]['time_left'];
|
||||
} elseif (!is_null($moid = $fleets[$i]['moving'])) {
|
||||
$mwo = $move[$moid]['wait_order'];
|
||||
$lid .= "M:".$move[$moid]['m_to'].':'.$move[$moid]['time_left'].':'
|
||||
.$move[$moid]['changed'].":".$this->moving->call('getLocation', $moid);
|
||||
$tl = is_null($mwo) ? 0 : $wait[$mwo]['time_left'];
|
||||
} else {
|
||||
$tl = 0;
|
||||
$lid .= "L:".$fleets[$i]['location'];
|
||||
}
|
||||
|
||||
// Generate / update container
|
||||
if (!is_array($gFleets[$lid])) {
|
||||
$gFleets[$lid] = array('t' => $tl, 'a' => $am, 'l' => array());
|
||||
} else {
|
||||
if ($tl > $gFleets[$lid]['t']) {
|
||||
$gFleets[$lid]['t'] = $tl;
|
||||
}
|
||||
$gFleets[$lid]['a'] |= $am;
|
||||
}
|
||||
|
||||
// Add fleet
|
||||
array_push($gFleets[$lid]['l'], $i);
|
||||
}
|
||||
|
||||
// Merge groups into single fleets
|
||||
$nfl = array();
|
||||
foreach ($gFleets as $fg) {
|
||||
// Compute total amount of ships
|
||||
$sums = array(0,0,0,0);
|
||||
$minSpent = null;
|
||||
foreach ($fg['l'] as $i) {
|
||||
$sums[0] += $fleets[$i]['gaships'];
|
||||
$sums[1] += $fleets[$i]['fighters'];
|
||||
$sums[2] += $fleets[$i]['cruisers'];
|
||||
$sums[3] += $fleets[$i]['bcruisers'];
|
||||
|
||||
if (is_null($minSpent) || $minSpent > $fleets[$i]['time_spent']) {
|
||||
$minSpent = $fleets[$i]['time_spent'];
|
||||
}
|
||||
}
|
||||
|
||||
// Update merged fleet
|
||||
$nId = array_shift($fg['l']);
|
||||
$name = addslashes(($newName == "") ? $fleets[$nId]['name'] : $newName);
|
||||
$this->db->query("UPDATE fleet SET name='$name',gaships=".$sums[0].",fighters=".$sums[1]
|
||||
. ",cruisers=".$sums[2].",bcruisers=".$sums[3].",attacking="
|
||||
. dbBool($fg['a']) . ",time_spent=$minSpent WHERE id=$nId");
|
||||
|
||||
// Delete unneeded data
|
||||
if (count($fg['l'])) {
|
||||
$dMids = array(); $dWids = array();
|
||||
foreach ($fg['l'] as $i) {
|
||||
if (!is_null($fleets[$i]['waiting'])) {
|
||||
array_push($dWids, $fleets[$i]['waiting']);
|
||||
} elseif (!is_null($fleets[$i]['moving'])) {
|
||||
array_push($dMids, $fleets[$i]['moving']);
|
||||
}
|
||||
}
|
||||
foreach ($dMids as $i) {
|
||||
if (!is_null($move[$i]['wait_order'])) {
|
||||
array_push($dWids, $move[$i]['wait_order']);
|
||||
}
|
||||
}
|
||||
$this->db->query("DELETE FROM fleet WHERE id IN (".join(',',$fg['l']).")");
|
||||
if (count($dMids)) {
|
||||
$this->db->query("DELETE FROM moving_object WHERE id IN (".join(',',$dMids).")");
|
||||
}
|
||||
if (count($dWids)) {
|
||||
$this->db->query("DELETE FROM hs_wait WHERE id IN (".join(',',$dWids).")");
|
||||
}
|
||||
}
|
||||
|
||||
// Update detection status
|
||||
$this->db->query("DELETE FROM beacon_detection WHERE fleet = $nId");
|
||||
|
||||
// Make sure orders are up-to-date
|
||||
$mwo = $fleets[$nId]['moving'];
|
||||
$dest = is_null($mwo) ? null : $move[$mwo]['m_to'];
|
||||
$wait = $fg['t'] ? $fg['t'] : null;
|
||||
$this->lib->call('setOrders', $nId, $dest, $wait);
|
||||
|
||||
array_push($nfl, $nId);
|
||||
}
|
||||
|
||||
return $nfl;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
195
scripts/game/beta5/fleet/library/sendMoveMessages.inc
Normal file
195
scripts/game/beta5/fleet/library/sendMoveMessages.inc
Normal file
|
@ -0,0 +1,195 @@
|
|||
<?php
|
||||
|
||||
class beta5_fleet_sendMoveMessages {
|
||||
|
||||
function beta5_fleet_sendMoveMessages($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->msg = $this->lib->game->getLib('beta5/msg');
|
||||
}
|
||||
|
||||
|
||||
// Sends messages related to fleet movements
|
||||
function run() {
|
||||
$locs = array_unique(array_merge(array_keys($this->lib->mainClass->fleetDepartures), array_keys($this->lib->mainClass->fleetArrivals)));
|
||||
if (count($locs) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all fleet or planet owners for the affected locations and their status
|
||||
$q = $this->db->query(
|
||||
"SELECT owner AS id,FALSE AS att,id AS loc FROM planet WHERE owner IS NOT NULL AND id IN (".join(',',$locs).") "
|
||||
. "UNION SELECT owner AS id,attacking AS att,location AS loc FROM fleet WHERE location IN (".join(',',$locs).")"
|
||||
);
|
||||
|
||||
$fMove = array();
|
||||
$ownArrivals = array();
|
||||
while ($r = dbFetchArray($q)) {
|
||||
list($player,$status,$location) = $r;
|
||||
$oa = $ha = $hd = $fa = $fd = array();
|
||||
|
||||
// Generate the list of fleet departures
|
||||
if (is_array($this->lib->mainClass->fleetDepartures[$location])) {
|
||||
foreach ($this->lib->mainClass->fleetDepartures[$location][(int)$status] as $fId) {
|
||||
$f = $this->lib->call('get', $fId);
|
||||
if ($f['owner'] == $player) {
|
||||
continue;
|
||||
}
|
||||
array_push($fd, $f);
|
||||
}
|
||||
foreach ($this->lib->mainClass->fleetDepartures[$location][1-$status] as $fId) {
|
||||
$f = $this->lib->call('get', $fId);
|
||||
if ($f['owner'] == $player) {
|
||||
continue;
|
||||
}
|
||||
array_push($hd, $f);
|
||||
}
|
||||
}
|
||||
|
||||
// Generate the list of fleet arrivals
|
||||
if (is_array($this->lib->mainClass->fleetArrivals[$location])) {
|
||||
foreach ($this->lib->mainClass->fleetArrivals[$location][(int)$status] as $fdt) {
|
||||
list($fId, $from) = $fdt;
|
||||
$f = $this->lib->call('get', $fId);
|
||||
$f['from'] = $from;
|
||||
if ($f['owner'] == $player) {
|
||||
if (!is_array($ownArrivals[$player])) {
|
||||
$ownArrivals[$player] = array();
|
||||
}
|
||||
if (!is_array($ownArrivals[$player][$location])) {
|
||||
$ownArrivals[$player][$location] = array();
|
||||
}
|
||||
array_push($ownArrivals[$player][$location], $f);
|
||||
} else {
|
||||
array_push($fa, $f);
|
||||
}
|
||||
}
|
||||
foreach ($this->lib->mainClass->fleetArrivals[$location][1-$status] as $fdt) {
|
||||
list($fId, $from) = $fdt;
|
||||
$f = $this->lib->call('get', $fId);
|
||||
$f['from'] = $from;
|
||||
if ($f['owner'] == $player) {
|
||||
l::warn("beta5/sendFleetMoveMessages(): fleet $fId owned by player $player hostile to its owner");
|
||||
continue;
|
||||
}
|
||||
array_push($ha, $f);
|
||||
}
|
||||
}
|
||||
|
||||
// Add the data to the list of fleet movements
|
||||
if (!(count($fa)||count($fd)||count($ha)||count($hd))) {
|
||||
continue;
|
||||
}
|
||||
if (!is_array($fMove[$player])) {
|
||||
$fMove[$player] = array($location => array($fa, $fd, $ha, $hd));
|
||||
} else {
|
||||
$fMove[$player][$location] = array($fa, $fd, $ha, $hd);
|
||||
}
|
||||
}
|
||||
|
||||
$pnames = array();
|
||||
$fpowers = array();
|
||||
|
||||
// Send messages for own fleets arrivals
|
||||
$tm = time() - 1;
|
||||
foreach ($ownArrivals as $player => $locs) {
|
||||
foreach ($locs as $loc => $flist) {
|
||||
// Get planet name
|
||||
if (is_null($pnames[$loc])) {
|
||||
$q = $this->db->query("SELECT name FROM planet WHERE id=$loc");
|
||||
list($pnames[$loc]) = dbFetchArray($q);
|
||||
}
|
||||
$pname = $pnames[$loc];
|
||||
|
||||
// Generate a message
|
||||
$mid = $this->msg->call('send', $player, 'flmove', array(
|
||||
'p_id' => $loc,
|
||||
'p_name' => $pname
|
||||
));
|
||||
|
||||
// Insert fleet data
|
||||
foreach ($flist as $fleet) {
|
||||
// Get origin planet name
|
||||
if (is_null($pnames[$fleet['from']])) {
|
||||
$q = $this->db->query("SELECT name FROM planet WHERE id={$fleet['from']}");
|
||||
list($pnames[$fleet['from']]) = dbFetchArray($q);
|
||||
}
|
||||
$pname = $pnames[$fleet['from']];
|
||||
|
||||
$fpowers[$fleet['id']] = $fPower = $this->lib->call('getPower',
|
||||
$player, $fleet['gaships'], $fleet['fighters'], $fleet['cruisers'], $fleet['bcruisers']);
|
||||
$this->db->query("INSERT INTO flmove_data VALUES ($mid,'".addslashes($fleet['name'])."',$player,"
|
||||
. "{$fleet['gaships']},{$fleet['fighters']},{$fleet['cruisers']},{$fleet['bcruisers']},$fPower,"
|
||||
. "FALSE,TRUE,{$fleet['from']},'".addslashes($pname)."')");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send messages for other fleets
|
||||
$tm++;
|
||||
foreach ($fMove as $player => $locs) {
|
||||
foreach ($locs as $loc => $flists) {
|
||||
$flist = array();
|
||||
foreach ($flists[0] as $f) {
|
||||
$f['hostile'] = 0;
|
||||
array_push($flist, $f);
|
||||
}
|
||||
foreach ($flists[1] as $f) {
|
||||
$f['hostile'] = 0;
|
||||
array_push($flist, $f);
|
||||
}
|
||||
foreach ($flists[2] as $f) {
|
||||
$f['hostile'] = 1;
|
||||
array_push($flist, $f);
|
||||
}
|
||||
foreach ($flists[3] as $f) {
|
||||
$f['hostile'] = 1;
|
||||
array_push($flist, $f);
|
||||
}
|
||||
|
||||
// Get planet name
|
||||
if (is_null($pnames[$loc])) {
|
||||
$q = $this->db->query("SELECT name FROM planet WHERE id=$loc");
|
||||
list($pnames[$loc]) = dbFetchArray($q);
|
||||
}
|
||||
$pname = $pnames[$loc];
|
||||
|
||||
// Generate a message
|
||||
$mid = $this->msg->call('send', $player, 'flmove', array(
|
||||
'p_id' => $loc,
|
||||
'p_name' => $pname
|
||||
));
|
||||
|
||||
// Insert fleet data
|
||||
foreach ($flist as $fleet) {
|
||||
if (is_null($fleet['from'])) {
|
||||
$arrived = 0;
|
||||
} else {
|
||||
// Get origin planet name
|
||||
if (is_null($pnames[$fleet['from']])) {
|
||||
$q = $this->db->query("SELECT name FROM planet WHERE id={$fleet['from']}");
|
||||
list($pnames[$fleet['from']]) = dbFetchArray($q);
|
||||
}
|
||||
$pname = $pnames[$fleet['from']];
|
||||
$arrived = 1;
|
||||
}
|
||||
|
||||
if (is_null($fpowers[$fleet['id']])) {
|
||||
$fpowers[$fleet['id']] = $this->lib->call('getPower',
|
||||
$fleet['owner'], $fleet['gaships'], $fleet['fighters'], $fleet['cruisers'], $fleet['bcruisers']);
|
||||
}
|
||||
$fPower = $fpowers[$fleet['id']];
|
||||
l::trace("beta5/sendFleetMoveMessages: inserting message for player $player, location $loc, fleet {$fleet['id']}");
|
||||
$this->db->query("INSERT INTO flmove_data VALUES ($mid,'".addslashes($fleet['name'])."',{$fleet['owner']},"
|
||||
. "{$fleet['gaships']},{$fleet['fighters']},{$fleet['cruisers']},{$fleet['bcruisers']},$fPower,"
|
||||
. ($fleet['hostile'] ? "TRUE" : "FALSE") . "," . ($arrived ? "TRUE" : "FALSE") . ","
|
||||
. ($arrived ? ("{$fleet['from']},'".addslashes($pname)."'") : "NULL,NULL") . ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->lib->mainClass->fleetArrivals = $this->lib->mainClass->fleetDepartures = array();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
245
scripts/game/beta5/fleet/library/setOrders.inc
Normal file
245
scripts/game/beta5/fleet/library/setOrders.inc
Normal file
|
@ -0,0 +1,245 @@
|
|||
<?php
|
||||
|
||||
class beta5_fleet_setOrders {
|
||||
|
||||
function beta5_fleet_setOrders($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->moving = $this->lib->game->getLib('beta5/moving');
|
||||
$this->planets = $this->lib->game->getLib('beta5/planet');
|
||||
$this->players = $this->lib->game->getLib('beta5/player');
|
||||
$this->rules = $this->lib->game->getLib('beta5/rules');
|
||||
$this->standby = $this->lib->game->getLib('beta5/standby');
|
||||
}
|
||||
|
||||
|
||||
// Changes a fleet's orders
|
||||
function run($fid, $newDest, $newDelay, $attack = null) {
|
||||
// Get fleet data
|
||||
$fleet = $this->lib->call('get', $fid);
|
||||
if (is_null($fleet) || !is_null($fleet['sale_info']) || $fleet['can_move'] != 'Y') {
|
||||
return false;
|
||||
}
|
||||
if (is_null($attack)) {
|
||||
$attack = ($fleet['attacking'] == 't');
|
||||
}
|
||||
|
||||
// Check for hyperspace capabilities
|
||||
$r = $this->rules->call('get', $fleet['owner']);
|
||||
$used = $r['gaship_space'] * $fleet['gaships'] + $r['fighter_space'] * $fleet['fighters'];
|
||||
$avail = $r['cruiser_haul'] * $fleet['cruisers'] + $r['bcruiser_haul'] * $fleet['bcruisers'];
|
||||
$hsOk = ($used <= $avail);
|
||||
|
||||
// Get cruisers status / Capital ships speed
|
||||
$cru = ($fleet['cruisers'] > 0);
|
||||
$csp = $r['capital_ship_speed'];
|
||||
|
||||
// Check for an implicit "null" move order
|
||||
$cLoc = is_null($fleet['move'])
|
||||
? (is_null($fleet['wait'])
|
||||
? $fleet['location']
|
||||
: $fleet['wait']['drop_point'])
|
||||
: $this->moving->call('getLocation', $fleet['move']['id']);
|
||||
if ($cLoc == $newDest)
|
||||
$newDest = null;
|
||||
|
||||
// Some checks must be performed if the fleet is going out of system
|
||||
if (!(is_null($cLoc) || is_null($newDest))) {
|
||||
$cLocInfo = $this->planets->call('byId', $cLoc);
|
||||
$nDestInfo = $this->planets->call('byId', $newDest);
|
||||
if ($cLocInfo['x'] != $nDestInfo['x'] || $cLocInfo['y'] != $nDestInfo['y']) {
|
||||
// Fleet is not hyperspace-capable
|
||||
if (!$hsOk) {
|
||||
return false;
|
||||
}
|
||||
// Check protection
|
||||
if ($this->lib->game->params['victory'] == 0) {
|
||||
$protected = $this->players->call('getProtectionLevel', $fleet['owner']);
|
||||
if ($protected) {
|
||||
$this->players->call('breakProtection', $fleet['owner'], 'ACT');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Identify movement-related actions
|
||||
$newMove = is_null($fleet['move']) && !is_null($newDest);
|
||||
$rmMove = !is_null($fleet['move']) && is_null($newDest);
|
||||
$chgMove = !is_null($fleet['move']) && !is_null($newDest) && ($newDest != $fleet['move']['m_to']);
|
||||
$mNoAct = !($newMove||$rmMove||$chgMove);
|
||||
|
||||
// Identify HS standby-related actions
|
||||
$newWait = $hsOk && is_null($fleet['wait']) && !is_null($newDelay);
|
||||
$rmWait = $hsOk && !is_null($fleet['wait']) && is_null($newDelay);
|
||||
$chgWait = $hsOk && !is_null($fleet['wait']) && !is_null($newDelay) && ($newDelay != $fleet['wait']['time_left']);
|
||||
$wNoAct = !($newWait||$rmWait||$chgWait);
|
||||
|
||||
|
||||
logText("newMove $newMove; rmMove $rmMove; chgMove $chgMove; mNoAct $mNoAct");
|
||||
logText("newWait $newWait; rmWait $rmWait; chgWait $chgWait; wNoAct $wNoAct");
|
||||
|
||||
// No actions are to be taken, return
|
||||
if ($mNoAct && $wNoAct) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Start moving
|
||||
$fleetArrived = false;
|
||||
if ($newMove) {
|
||||
$departure = false;
|
||||
|
||||
// HS orders haven't changed.
|
||||
if ($wNoAct) {
|
||||
// Are we already waiting?
|
||||
if (is_null($fleet['wait'])) {
|
||||
$wo = null;
|
||||
$sl = $fleet['location'];
|
||||
$departure = true;
|
||||
} else {
|
||||
$wo = $fleet['wait']['id'];
|
||||
$sl = $fleet['wait']['drop_point'];
|
||||
logText("Adding new move orders, initial location: $sl");
|
||||
$this->db->query("UPDATE hs_wait SET time_left=$newDelay,time_spent=0,origin=NULL WHERE id=$wo");
|
||||
}
|
||||
} elseif ($newWait) {
|
||||
// New HS stand-by order
|
||||
$wo = $this->standby->call('create', $newDelay, $newDest);
|
||||
$sl = $fleet['location'];
|
||||
$departure = true;
|
||||
} elseif ($rmWait) {
|
||||
// Delete current HS stand-by order
|
||||
$wo = null;
|
||||
$sl = $fleet['wait']['drop_point'];
|
||||
$this->db->query("DELETE FROM hs_wait WHERE id=".$fleet['wait']['id']);
|
||||
} elseif ($chgWait) {
|
||||
// Change HS stand-by order
|
||||
$wo = $fleet['wait']['id'];
|
||||
$sl = $fleet['wait']['drop_point'];
|
||||
$this->db->query("UPDATE hs_wait SET time_left=$newDelay,time_spent=0,origin=NULL,drop_point=$newDest WHERE id=".$fleet['wait']['id']);
|
||||
}
|
||||
|
||||
// Create movement entry
|
||||
$this->db->query("DELETE FROM beacon_detection WHERE fleet = $fid");
|
||||
$mo = $this->moving->call('newObject', $sl, $newDest, $csp, $cru, $wo);
|
||||
if (is_null($mo)) {
|
||||
logText("beta5/setFleetOrders($fid,$newDest,$newDelay,".($attack?1:0)."): unable to create a new moving_object entry", LOG_ERR);
|
||||
return false;
|
||||
}
|
||||
$this->db->query("UPDATE fleet SET location=NULL,moving=$mo,waiting=NULL WHERE id=$fid");
|
||||
if ($departure) {
|
||||
$this->planets->call('updateMilStatus', $sl);
|
||||
$this->planets->call('updateHappiness', $sl);
|
||||
$this->addDeparture($sl, $fid, $fleet['attacking'] == 't');
|
||||
}
|
||||
} elseif ($rmMove) {
|
||||
// Fleet stop requested
|
||||
$mo = $fleet['move']['id'];
|
||||
$nloc = $this->moving->call('getLocation', $mo);
|
||||
|
||||
if ($wNoAct) {
|
||||
// HS orders haven't changed.
|
||||
// Do we have stand-by orders?
|
||||
if (is_null($fleet['wait'])) {
|
||||
$wo = null;
|
||||
} else {
|
||||
$wo = $fleet['wait']['id'];
|
||||
$this->db->query("UPDATE hs_wait SET drop_point=$nloc WHERE id=$wo");
|
||||
}
|
||||
}
|
||||
elseif ($newWait) {
|
||||
// New HS stand-by order
|
||||
$wo = $this->standby->call('create', $newDelay, $nloc);
|
||||
} elseif ($rmWait) {
|
||||
// Delete current HS stand-by order
|
||||
$wo = null;
|
||||
$this->db->query("DELETE FROM hs_wait WHERE id=".$fleet['wait']['id']);
|
||||
} elseif ($chgWait) {
|
||||
// Change HS stand-by order
|
||||
$wo = $fleet['wait']['id'];
|
||||
$this->db->query("UPDATE hs_wait SET time_left=$newDelay,time_spent=0,drop_point=$nloc WHERE id=".$fleet['wait']['id']);
|
||||
}
|
||||
|
||||
// Stop movement
|
||||
$this->moving->call('stop', $mo, $wo);
|
||||
} elseif ($chgMove) {
|
||||
// Fleet destination changed
|
||||
$mo = $fleet['move']['id'];
|
||||
|
||||
if ($wNoAct) {
|
||||
// HS orders haven't changed.
|
||||
// Do we have stand-by orders?
|
||||
if (is_null($fleet['wait'])) {
|
||||
$wo = null;
|
||||
} else {
|
||||
$wo = $fleet['wait']['id'];
|
||||
$this->db->query("UPDATE hs_wait SET drop_point=$newDest WHERE id=$wo");
|
||||
}
|
||||
}
|
||||
elseif ($newWait) {
|
||||
// New HS stand-by order
|
||||
$wo = $this->standby->call('create', $newDelay, $newDest);
|
||||
} elseif ($rmWait) {
|
||||
// Delete current HS stand-by order
|
||||
$wo = null;
|
||||
$this->db->query("DELETE FROM hs_wait WHERE id=".$fleet['wait']['id']);
|
||||
} elseif ($chgWait) {
|
||||
// Change HS stand-by order
|
||||
$wo = $fleet['wait']['id'];
|
||||
$this->db->query("UPDATE hs_wait SET time_left=$newDelay,time_spent=0,drop_point=$newDest WHERE id=$wo");
|
||||
}
|
||||
|
||||
// Redirect fleet
|
||||
$this->moving->call('redirect', $mo, $newDest, $csp, $cru, $wo);
|
||||
} elseif ($newWait) {
|
||||
// No destination change, but stand-by orders changed
|
||||
// New HS stand-by order
|
||||
if (is_null($fleet['move'])) {
|
||||
$loc = $fleet['location'];
|
||||
$wo = $this->standby->call('create', $newDelay, $loc, $loc, null);
|
||||
|
||||
$this->db->query("UPDATE fleet SET waiting=$wo,location=NULL WHERE id=$fid");
|
||||
$this->db->query("UPDATE hs_wait SET origin=$loc WHERE id=$wo");
|
||||
|
||||
$this->planets->call('updateMilStatus', $loc);
|
||||
$this->planets->call('updateHappiness', $loc);
|
||||
$this->addDeparture($loc, $fid, $fleet['attacking'] == 't');
|
||||
$this->planets->call('detectFleets', $loc);
|
||||
} else {
|
||||
$wo = $this->standby->call('create', $newDelay, $fleet['move']['m_to']);
|
||||
$this->db->query("UPDATE moving_object SET wait_order=$wo WHERE id=".$fleet['move']['id']);
|
||||
}
|
||||
} elseif ($rmWait) {
|
||||
// Delete current HS stand-by order
|
||||
$this->db->query("DELETE FROM hs_wait WHERE id=".$fleet['wait']['id']);
|
||||
if (is_null($fleet['move'])) {
|
||||
$fleetArrived = true;
|
||||
$this->lib->call('arrival', $fid, $fleet['wait']['drop_point'], $fleet['wait']['origin'], $attack);
|
||||
$this->planets->call('updateMilStatus', $fleet['wait']['drop_point']);
|
||||
$this->planets->call('updateHappiness', $fleet['wait']['drop_point']);
|
||||
$this->db->query("DELETE FROM beacon_detection WHERE fleet = $fid");
|
||||
}
|
||||
} elseif ($chgWait) {
|
||||
// Change HS stand-by order
|
||||
$this->db->query("UPDATE hs_wait SET time_left=$newDelay WHERE id=".$fleet['wait']['id']);
|
||||
}
|
||||
|
||||
// If the fleet hasn't arrived, set its status
|
||||
if (!$fleetArrived) {
|
||||
$this->db->query("UPDATE fleet SET attacking=".dbBool($attack)." WHERE id=$fid");
|
||||
}
|
||||
|
||||
$this->lib->call('invCache', $fid);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Adds an entry to the list of fleet departures
|
||||
function addDeparture($location, $fid, $status) {
|
||||
if (!is_array($this->lib->mainClass->fleetDepartures[$location])) {
|
||||
$this->lib->mainClass->fleetDepartures[$location] = array(array(), array());
|
||||
}
|
||||
array_push($this->lib->mainClass->fleetDepartures[$location][$status?1:0], $fid);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
82
scripts/game/beta5/fleet/library/split.inc
Normal file
82
scripts/game/beta5/fleet/library/split.inc
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
class beta5_fleet_split {
|
||||
|
||||
function beta5_fleet_split($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
$this->rules = $this->lib->game->getLib('beta5/rules');
|
||||
$this->standby = $this->lib->game->getLib('beta5/standby');
|
||||
$this->moving = $this->lib->game->getLib('beta5/moving');
|
||||
}
|
||||
|
||||
|
||||
// Manually split a fleet in player-specified fleets
|
||||
function run($fid, $newName, $count, $sg, $sf, $sc, $sb) {
|
||||
// Get fleet data
|
||||
$f = $this->lib->call('get', $fid, true);
|
||||
if (is_null($f) || $f['can_move'] != 'Y' || !is_null($f['sale_info'])) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check for enough ships in the original fleet
|
||||
$mg = $count * $sg; $mf = $count * $sf;
|
||||
$mc = $count * $sc; $mb = $count * $sb;
|
||||
if ($f['gaships'] < $mg || $f['fighters'] < $mf || $f['cruisers'] < $mc || $f['bcruisers'] < $mb
|
||||
|| $f['gaships'] + $f['fighters'] + $f['cruisers'] + $f['bcruisers'] - ($mg+$mf+$mc+$mb) == 0) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
// If we're moving or standing by in Hyperspace, we need to make sure both
|
||||
// the new and old fleets are HS-capable
|
||||
if ((!is_null($f['move']) && $f['move']['hyperspace'] == 't') || !is_null($f['wait'])) {
|
||||
$r = $this->rules->call('get', $f['owner']);
|
||||
$nu = $r['gaship_space'] * $sg + $r['fighter_space'] * $sf;
|
||||
$na = $r['cruiser_haul'] * $sc + $r['bcruiser_haul'] * $sb;
|
||||
$ou = $r['gaship_space'] * ($f['gaships'] - $mg) + $r['fighter_space'] * ($f['fighters'] - $mf);
|
||||
$oa = $r['cruiser_haul'] * ($f['cruisers'] - $mc) + $r['bcruiser_haul'] * ($f['bcruisers'] - $mb);
|
||||
if ($nu > $na || $ou > $oa) {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate code that will set the new fleets' orders
|
||||
if (is_null($f['location'])) {
|
||||
$location = "NULL";
|
||||
if (is_null($f['moving'])) {
|
||||
$moving = "NULL";
|
||||
$oCode = '$waiting = $this->standby->call("create", '.$f['wait']['time_left'].",".$f['wait']['drop_point']
|
||||
. ','.$f['wait']['origin'].','.$f['wait']['time_spent'].');';
|
||||
} else {
|
||||
$waiting = "NULL";
|
||||
$oCode = '$moving = $this->moving->call("cloneObject", '.$f['moving'].');';
|
||||
}
|
||||
} else {
|
||||
$location = $f['location'];
|
||||
$moving = $waiting = 'NULL';
|
||||
$oCode = null;
|
||||
}
|
||||
|
||||
// Generate new fleets
|
||||
$nn = addslashes($newName == "" ? preg_replace('/ [0-9]+$/', '', $f['name']) : $newName);
|
||||
for ($i=0;$i<$count;$i++) {
|
||||
if ($oCode != "") {
|
||||
eval($oCode);
|
||||
}
|
||||
$nnb = $count > 1 ? (" " . ($i + 1)) : "";
|
||||
$this->db->query("INSERT INTO fleet(owner,name,location,gaships,fighters,cruisers,bcruisers,attacking,moving,waiting,time_spent) VALUES("
|
||||
.$f['owner'].",'$nn$nnb',$location,$sg,$sf,$sc,$sb,"
|
||||
.dbBool($f['attacking'] == 't').",$moving,$waiting,{$f['time_spent']})");
|
||||
}
|
||||
|
||||
// Update original fleet
|
||||
$this->db->query("UPDATE fleet SET gaships=gaships-$mg,fighters=fighters-$mf,cruisers=cruisers-$mc,bcruisers=bcruisers-$mb "
|
||||
."WHERE id=$fid");
|
||||
$this->db->query("DELETE FROM beacon_detection WHERE fleet = $fid");
|
||||
|
||||
$this->lib->call('invCache', $fid);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
31
scripts/game/beta5/fleet/library/switchStatus.inc
Normal file
31
scripts/game/beta5/fleet/library/switchStatus.inc
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
class beta5_fleet_switchStatus {
|
||||
|
||||
function beta5_fleet_switchStatus($lib) {
|
||||
$this->lib = $lib;
|
||||
$this->db = $this->lib->game->db;
|
||||
}
|
||||
|
||||
|
||||
// Switches a fleet's status
|
||||
function run($id) {
|
||||
$f = $this->lib->call('get', $id);
|
||||
if ($f['attacking'] == 't') {
|
||||
$this->db->query("UPDATE fleet SET attacking=".dbBool(0)." WHERE id=$id");
|
||||
} else {
|
||||
$this->db->query("UPDATE fleet SET attacking=".dbBool(1)
|
||||
.(is_null($f['location'])?"":",can_move='B',time_spent=0")." WHERE id=$id");
|
||||
}
|
||||
|
||||
// FIXME: messages
|
||||
|
||||
$this->lib->mainClass->fleets[$id]['attacking'] = ($this->lib->mainClass->fleets[$id]['attacking'] == 't') ? 'f' : 't';
|
||||
if ($this->lib->mainClass->fleets[$id]['attacking'] == 't' && !is_null($f['location'])) {
|
||||
$this->lib->mainClass->fleets[$id]['can_move'] = 'B';
|
||||
}
|
||||
logText("beta5/fleet/switchStatus($id): fleet owner {$f['owner']}, switched to " . ($f['attacking'] == 't' ? "def" : "att"), LOG_DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Reference in a new issue