forked from kestasjk/webDiplomacy
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added transform rule to set of rule extensions
- Loading branch information
Showing
16 changed files
with
622 additions
and
4 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
variants/RuleExtensions/classes/4_Transform/OrderArchiv.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
defined('IN_CODE') or die('This script can not be run by itself.'); | ||
|
||
class Transform_OrderArchiv extends RuleExtensionsVariant_OrderArchiv_base { | ||
|
||
public function OutputOrder($order) | ||
{ | ||
if(!$this->Variant->rules[RULE_TRANSFORM]){ | ||
return parent::OutputOrder($order); | ||
} | ||
|
||
if ($order['toTerrID'] > 1000) | ||
{ | ||
$order['toTerrID'] = $order['toTerrID'] - 1000; | ||
$order['type'] = 'transform'; | ||
if ($order['toTerrID'] == $order['terrID']) | ||
$order['toTerrID']=false; | ||
} | ||
return parent::OutputOrder($order); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
variants/RuleExtensions/classes/4_Transform/OrderInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
defined('IN_CODE') or die('This script can not be run by itself.'); | ||
|
||
class Transform_OrderInterface extends BuildAnywhere_OrderInterface { | ||
|
||
protected function jsLoadBoard() { | ||
|
||
if(!$this->Variant->rules[RULE_TRANSFORM]){ | ||
return parent::jsLoadBoard(); | ||
} | ||
|
||
parent::jsLoadBoard(); | ||
|
||
if( $this->phase=='Diplomacy' ) | ||
{ | ||
// Expanding order controls with transform command | ||
libHTML::$footerIncludes[] = l_jf('../variants/RuleExtensions/resources/4_Transform/transform.js'); | ||
foreach(libHTML::$footerScript as $index=>$script) | ||
libHTML::$footerScript[$index]=str_replace('loadOrdersPhase();','loadOrdersPhase();loadTransform();', $script); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
defined('IN_CODE') or die('This script can not be run by itself.'); | ||
|
||
class Transform_drawMap extends CustomIconsPerCountry_drawMap { | ||
|
||
private $trafo=array(); | ||
|
||
public function drawSupportHold($fromTerrID, $toTerrID, $success) | ||
{ | ||
if(!$this->Variant->rules[RULE_TRANSFORM]){ | ||
return parent::drawSupportHold($fromTerrID, $toTerrID, $success); | ||
} | ||
|
||
if ($toTerrID < 1000) return parent::drawSupportHold($fromTerrID, $toTerrID, $success); | ||
|
||
$toTerrID = $toTerrID - 1000; | ||
if ($success) | ||
$this->trafo[$fromTerrID]=$toTerrID; | ||
|
||
$this->drawTransform($fromTerrID, $toTerrID, $success); | ||
} | ||
|
||
// If a unit did a transform draw the new unit-type on the board instead of the old... | ||
public function addUnit($terrID, $unitType) | ||
{ | ||
if(!$this->Variant->rules[RULE_TRANSFORM]){ | ||
return parent::addUnit($terrID, $unitType); | ||
} | ||
|
||
if (array_key_exists($terrID,$this->trafo)) | ||
return parent::addUnit($this->trafo[$terrID], ($unitType == 'Fleet' ? 'Army' : 'Fleet')); | ||
parent::addUnit($terrID, $unitType); | ||
} | ||
|
||
// Draw the transformation circle: | ||
protected function drawTransform($fromTerrID, $toTerrID, $success) | ||
{ | ||
|
||
$terrID = ($success ? $toTerrID : $fromTerrID); | ||
|
||
if ( $fromTerrID != $toTerrID ) | ||
$this->drawMove($fromTerrID,$toTerrID, $success); | ||
|
||
$darkblue = $this->color(array(40, 80,130)); | ||
$lightblue = $this->color(array(70,150,230)); | ||
|
||
list($x, $y) = $this->territoryPositions[$terrID]; | ||
|
||
$width=($this->fleet['width'])+($this->fleet['width'])/2; | ||
|
||
imagefilledellipse ( $this->map['image'], $x, $y, $width, $width, $darkblue); | ||
imagefilledellipse ( $this->map['image'], $x, $y, $width-2, $width-2, $lightblue); | ||
|
||
if ( !$success ) $this->drawFailure(array($x-1, $y),array($x+2, $y)); | ||
} | ||
} | ||
|
||
?> |
27 changes: 27 additions & 0 deletions
27
variants/RuleExtensions/classes/4_Transform/processOrderDiplomacy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
defined('IN_CODE') or die('This script can not be run by itself.'); | ||
|
||
class Transform_processOrderDiplomacy extends RuleExtensionsVariant_processOrderDiplomacy_base | ||
{ | ||
public function apply($standoffTerrs) | ||
{ | ||
global $Game, $DB; | ||
|
||
if(!$this->Variant->rules[RULE_TRANSFORM]){ | ||
return parent::apply($standoffTerrs); | ||
} | ||
|
||
// Transform all sucessfull "Transformations": | ||
$DB->sql_put("UPDATE wD_Units u | ||
INNER JOIN wD_Orders o ON (o.unitID = u.id) | ||
INNER JOIN wD_Moves m ON (m.gameID=o.gameID AND m.orderID = o.id) | ||
SET u.type = IF(u.type='Fleet','Army','Fleet'), u.terrID = (o.toTerrID - 1000) | ||
WHERE o.type='Support hold' AND m.success='Yes' AND o.toTerrID>1000 | ||
AND u.id = o.unitID AND o.gameID = ".$Game->id); | ||
parent::apply($standoffTerrs); | ||
} | ||
|
||
} | ||
|
||
?> |
66 changes: 66 additions & 0 deletions
66
variants/RuleExtensions/classes/4_Transform/userOrderDiplomacy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
defined('IN_CODE') or die('This script can not be run by itself.'); | ||
|
||
class Transform_userOrderDiplomacy extends RuleExtensionsVariant_userOrderDiplomacy_base | ||
{ | ||
// Allow the transform command | ||
protected function typeCheck() | ||
{ | ||
if(!$this->Variant->rules[RULE_TRANSFORM]){ | ||
return parent::typeCheck(); | ||
} | ||
|
||
if (strrpos($this->type,'Transform_1') !== false) return true; | ||
return parent::typeCheck(); | ||
} | ||
|
||
// Save the transform command as a Support-hold | ||
public function commit() | ||
{ | ||
if(!$this->Variant->rules[RULE_TRANSFORM]){ | ||
return parent::commit(); | ||
} | ||
|
||
// Clear the toTerrID (if there is any) from the transform command | ||
if ($this->type=='Hold') | ||
$this->paramWipe('toTerrID'); | ||
|
||
if (strrpos($this->type,'Transform_1') !== false) | ||
{ | ||
$this->toTerrID = substr($this->type, -4); | ||
$this->wiped = array('fromTerrID','viaConvoy'); | ||
$this->changed = array('type','toTerrID'); | ||
$this->type='Support hold'; | ||
} | ||
return parent::commit(); | ||
} | ||
|
||
public function loadFromDB(array $inputs) | ||
{ | ||
if(!$this->Variant->rules[RULE_TRANSFORM]){ | ||
parent::loadFromDB($inputs); | ||
} | ||
|
||
if( isset($inputs['toTerrID']) && $inputs['toTerrID'] > 1000 ) | ||
{ | ||
$inputs['type'] = 'Transform_' . $inputs['toTerrID']; | ||
unset($inputs['toTerrID']); | ||
} | ||
parent::loadFromDB($inputs); | ||
} | ||
|
||
public function loadFromInput(array $inputs) | ||
{ | ||
if(!$this->Variant->rules[RULE_TRANSFORM]){ | ||
parent::loadFromInput($inputs); | ||
} | ||
|
||
if( isset($inputs['toTerrID']) && $inputs['toTerrID'] > 1000) | ||
{ | ||
$inputs['type'] = 'Transform_' . $inputs['toTerrID']; | ||
unset($inputs['toTerrID']); | ||
} | ||
parent::loadFromInput($inputs); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
defined('IN_CODE') or die('This script can not be run by itself.'); | ||
|
||
class RuleExtensionsVariant_OrderArchiv_base extends OrderArchiv | ||
{ | ||
public $Variant; | ||
|
||
public function __construct($Variant, $smallmap) | ||
{ | ||
$this->Variant = $Variant; | ||
|
||
parent::__construct($smallmap); | ||
} | ||
} | ||
|
||
require_once('4_Transform/OrderArchiv.php'); | ||
|
||
class RuleExtensionsVariant_OrderArchiv extends Transform_OrderArchiv {} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
defined('IN_CODE') or die('This script can not be run by itself.'); | ||
|
||
class RuleExtensionsVariant_processOrderDiplomacy_base extends processOrderDiplomacy | ||
{ | ||
public $Variant; | ||
|
||
public function __construct($Variant) | ||
{ | ||
$this->Variant = $Variant; | ||
} | ||
} | ||
|
||
require_once('4_Transform/processOrderDiplomacy.php'); | ||
|
||
class RuleExtensionsVariant_processOrderDiplomacy extends Transform_processOrderDiplomacy {} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
defined('IN_CODE') or die('This script can not be run by itself.'); | ||
|
||
class RuleExtensionsVariant_userOrderDiplomacy_base extends userOrderDiplomacy | ||
{ | ||
public $Variant; | ||
|
||
public function __construct($Variant, $orderID, $gameID, $countryID) | ||
{ | ||
$this->Variant = $Variant; | ||
|
||
parent::__construct($orderID, $gameID, $countryID); | ||
} | ||
} | ||
|
||
require_once('4_Transform/userOrderDiplomacy.php'); | ||
|
||
class RuleExtensionsVariant_userOrderDiplomacy extends Transform_userOrderDiplomacy {} |
Oops, something went wrong.