Skip to content

Commit

Permalink
Added transform rule to set of rule extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
diptobi1 committed Nov 25, 2023
1 parent ad839e4 commit df70d38
Show file tree
Hide file tree
Showing 16 changed files with 622 additions and 4 deletions.
23 changes: 23 additions & 0 deletions variants/RuleExtensions/classes/4_Transform/OrderArchiv.php
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 variants/RuleExtensions/classes/4_Transform/OrderInterface.php
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);
}
}

}
59 changes: 59 additions & 0 deletions variants/RuleExtensions/classes/4_Transform/drawMap.php
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));
}
}

?>
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 variants/RuleExtensions/classes/4_Transform/userOrderDiplomacy.php
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);
}
}
21 changes: 21 additions & 0 deletions variants/RuleExtensions/classes/OrderArchiv.php
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 {}

?>
3 changes: 2 additions & 1 deletion variants/RuleExtensions/classes/OrderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ public function __construct($Variant, $gameID, $variantID, $userID, $memberID, $
require_once('1_CustomIcons/OrderInterface.php');
require_once('2_CustomIconsPerCountry/OrderInterface.php');
require_once('3_BuildAnywhere/OrderInterface.php');
require_once('4_Transform/OrderInterface.php');

class RuleExtensionsVariant_OrderInterface extends BuildAnywhere_OrderInterface {}
class RuleExtensionsVariant_OrderInterface extends Transform_OrderInterface {}
3 changes: 2 additions & 1 deletion variants/RuleExtensions/classes/drawMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public function __construct($Variant, $smallmap)
require_once('0_CustomMap/drawMap.php');
require_once('1_CustomIcons/drawMap.php');
require_once('2_CustomIconsPerCountry/drawMap.php');
require_once('4_Transform/drawMap.php');

class RuleExtensionsVariant_drawMap extends CustomIconsPerCountry_drawMap {}
class RuleExtensionsVariant_drawMap extends Transform_drawMap {}

?>
19 changes: 19 additions & 0 deletions variants/RuleExtensions/classes/processOrderDiplomacy.php
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 {}

?>
19 changes: 19 additions & 0 deletions variants/RuleExtensions/classes/userOrderDiplomacy.php
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 {}
Loading

0 comments on commit df70d38

Please sign in to comment.