Build anywhere:
This one is a bit tricky.
You have to change the javascript-code for the players, so they can select "non-home" sc's too in their browsers.
1st the New javascript code, that loads all "free" SC's of a user, I usually save this to "Resources/supplycenterscorrect.js":
Code:
function SupplyCentersCorrect() {
SupplyCenters = new Array();
/*
* In javascript/board/load.js SupplyCenters is created using similar code but only with home SCs,
* replacing it here allows them to be selected. A modified OrderInterface calls this shortly after load.js.
*/
Territories.each(function(p){
var t=p[1];
if( t.coastParent.supply && t.coastParent.ownerCountryID == context.countryID && Object.isUndefined(t.coastParent.Unit) )
{
SupplyCenters.push(t);
}
},this);
}
And here you insert the code to the users HTML-page:
Code:
<?php
class PureVariant_OrderInterface extends OrderInterface {
/**
* Call the parent constructor transparently to keep things working
*/
public function __construct($gameID, $variantID, $userID, $memberID, $turn, $phase, $countryID,
setMemberOrderStatus $orderStatus, $tokenExpireTime, $maxOrderID=false)
{
parent::__construct($gameID, $variantID, $userID, $memberID, $turn, $phase, $countryID,
$orderStatus, $tokenExpireTime, $maxOrderID);
}
protected function jsLoadBoard() {
parent::jsLoadBoard();
if( $this->phase=='Builds' )
{
// Expand the allowed SupplyCenters array to include non-home SCs.
libHTML::$footerIncludes[] = '../variants/Pure/resources/supplycenterscorrect.js';
foreach(libHTML::$footerScript as $index=>$script)
if(strpos($script, 'loadBoard();') )
libHTML::$footerScript[$index]=str_replace('loadBoard();','loadBoard();SupplyCentersCorrect();', $script);
}
}
}
?>
Now you need to change the code that validates the orders:
Code:
<?php
class PureVariant_userOrderBuilds extends userOrderBuilds
{
public function __construct($orderID, $gameID, $countryID)
{
parent::__construct($orderID, $gameID, $countryID);
}
protected function toTerrIDCheck()
{
global $DB;
// Don't duplicate destroy validation code
if( $this->type != 'Build Army' && $this->type != 'Build Fleet' )
return parent::toTerrIDCheck();
if( $this->type == 'Build Army' )
{
/*
* Creating an army at which territory
*
* Unoccupied supply centers owned by our country, which the specified unit type
* can be built in. If a parent coast is found return Child entries.
*/
return $this->sqlCheck("SELECT t.id
FROM wD_TerrStatus ts
INNER JOIN wD_Territories t
ON ( t.id = ts.terrID )
WHERE ts.gameID = ".$this->gameID."
AND t.mapID=".MAPID."
AND ts.countryID = ".$this->countryID."
AND ts.occupyingUnitID IS NULL
AND t.id=".$this->toTerrID."
AND t.supply = 'Yes' AND NOT t.type='Sea'
AND NOT t.coast = 'Child'");
}
elseif( $this->type == 'Build Fleet' )
{
return $this->sqlCheck("SELECT IF(t.coast='Parent', coast.id, t.id) as terrID
FROM wD_TerrStatus ts
INNER JOIN wD_Territories t ON ( t.id = ts.terrID )
LEFT JOIN wD_Territories coast ON ( coast.mapID=".MAPID." AND coast.coastParentID = t.id AND NOT t.id = coast.id )
WHERE ts.gameID = ".$this->gameID."
AND t.mapID=".MAPID."
AND ts.countryID = ".$this->countryID."
AND ts.occupyingUnitID IS NULL
AND t.supply = 'Yes'
AND t.type = 'Coast'
AND (
(t.coast='Parent' AND coast.id=".$this->toTerrID.")
OR t.id=".$this->toTerrID."
)
AND (
t.coast='No' OR ( t.coast='Parent' AND NOT coast.id IS NULL )
)");
}
}
}
?>
And finally you have to change the funtion that creates the build-orders so it count all SC's.
Code:
<?php
class PureVariant_processOrderBuilds extends processOrderBuilds
{
public function create()
{
global $DB, $Game;
$newOrders = array();
foreach($Game->Members->ByID as $Member )
{
$difference = 0;
if ( $Member->unitNo > $Member->supplyCenterNo )
{
$difference = $Member->unitNo - $Member->supplyCenterNo;
$type = 'Destroy';
}
elseif ( $Member->unitNo < $Member->supplyCenterNo )
{
$difference = $Member->supplyCenterNo - $Member->unitNo;
$type = 'Build Army';
}
for( $i=0; $i < $difference; ++$i )
{
$newOrders[] = "(".$Game->id.", ".$Member->countryID.", '".$type."')";
}
}
if ( count($newOrders) )
{
$DB->sql_put("INSERT INTO wD_Orders
(gameID, countryID, type)
VALUES ".implode(', ', $newOrders));
}
}
}
?>