Planet storage capacity updates added

Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>
This commit is contained in:
Gregory PLANCHAT 2011-06-19 14:20:22 +02:00
commit e15d9f81a7
9 changed files with 108 additions and 46 deletions

View file

@ -131,12 +131,12 @@ class Legacies_Empire
public static function getFieldName($id) public static function getFieldName($id)
{ {
global $resource; $fieldsAlias = Legacies_Empire_Model_Game_FieldsAlias::getSingleton();
if (!isset($resource[$id])) { if (!isset($fieldsAlias[$id])) {
return null; return null;
} }
return $resource[$id]; return $fieldsAlias[$id];
} }
} }

View file

@ -61,9 +61,33 @@ class Legacies_Empire_Model_Planet
return $this->_now; return $this->_now;
} }
public function updateStorages($time = null)
{
Math::setPrecision(10);
$resources = Legacies_Empire_Model_Game_Resources::getSingleton();
foreach ($resources->getAllDatas() as $resource => $resourceData) {
if (!isset($resourceData['storage_field']) || $resourceData['storage_field'] === null && $this['rpg_stockeur'] === null) {
continue;
}
Math::setPrecision(1);
$officerEnhancement = Math::add(Math::mul(.5, $this->getData('rpg_stockeur'), 50), 1, 10, 50);
Math::setPrecision(0);
$storageEnhancementFactor = Math::pow(1.6, $this[Legacies_Empire::getFieldName($resourceData['storage'])]);
$storageEnhancement = Math::mul(BASE_STORAGE_SIZE / 2, $storageEnhancementFactor);
$value = Math::mul(MAX_OVERFLOW, Math::mul($officerEnhancement, Math::add(BASE_STORAGE_SIZE, $storageEnhancement)));
$this->setData($resourceData['storage_field'], $value);
}
Math::setPrecision();
}
public function updateResources($time = null) public function updateResources($time = null)
{ {
$types = Legacies_Empire_Model_Game_Types::getSingleton(); $types = Legacies_Empire_Model_Game_Types::getSingleton();
$resources = Legacies_Empire_Model_Game_Resources::getSingleton();
$production = Legacies_Empire_Model_Game_Production::getSingleton();
if ($time === null) { if ($time === null) {
$time = $this->_now(); $time = $this->_now();
@ -74,15 +98,7 @@ class Legacies_Empire_Model_Planet
} }
$resourcesProductions = array(); $resourcesProductions = array();
foreach (self::$_productionConfig as $resource => $resourceData) { foreach ($resources->getAllDatas() as $resource => $resourceData) {
if ($resourceData['storage_field'] !== null && $resourceData['storage_field'] !== null) {
$officerEnhancement = Math::add(Math::mul(.5, $this->getData('rpg_stockeur')), 1);
$storageCapacity = Math::pow(1.5, $this->getData(Legacies_Empire::getFieldName($resourceData['storage'])));
$value = Math::mul(MAX_OVERFLOW, Math::mul($officerEnhancement, Math::add(BASE_STORAGE_SIZE, $storageCapacity)));
$this->setData($resourceData['storage_field'], $value);
}
foreach ($resourceData['production'] as $productionUnit => $ratioField) { foreach ($resourceData['production'] as $productionUnit => $ratioField) {
if (!in_array($productionUnit, $types['prod'])) { if (!in_array($productionUnit, $types['prod'])) {
continue; continue;
@ -101,20 +117,21 @@ class Legacies_Empire_Model_Planet
} }
} }
} }
var_dump($resourcesProductions);
$timeDiff = ($time - $this->getData('last_update')) / 3600; $timeDiff = ($time - $this->getData('last_update')) / 3600;
foreach ($resourcesProductions as $resource => $productionPerHour) { foreach ($resourcesProductions as $resource => $productionPerHour) {
if (!isset(self::$_productionConfig[$resource])) { if (!isset($resources[$resource])) {
continue; continue;
} }
$this->setData(self::$_productionConfig[$resource]['production_field'], $productionPerHour); $this->setData($resources[$resource]['production_field'], $productionPerHour);
$production = Math::add($this->getData(self::$_productionConfig[$resource]['field']), Math::mul($timeDiff, $productionPerHour)); $production = Math::add($this->getData($resources[$resource]['field']), Math::mul($timeDiff, $productionPerHour));
if (Math::comp($production, $this->getData(self::$_productionConfig[$resource]['storage_field'])) > 0) { if (Math::comp($production, $this->getData($resources[$resource]['storage_field'])) > 0) {
$production = $this->getData(self::$_productionConfig[$resource]['storage_field']); $production = $this->getData($resources[$resource]['storage_field']);
} }
$this->setData(self::$_productionConfig[$resource]['field'], $production); $this->setData($resources[$resource]['field'], $production);
} }
return $this; return $this;
@ -446,7 +463,7 @@ class Legacies_Empire_Model_Planet
$time = time(); $time = time();
} }
if ($planet === null || !$planet instanceof Legacies_Empire_Model_Planet || !$planet->getId()) { if ($planet === null || !$planet instanceof Legacies_Empire_Model_Planet) {
return; return;
} }
@ -458,9 +475,9 @@ class Legacies_Empire_Model_Planet
if ($partialTime < $time) { if ($partialTime < $time) {
$planet->updateResources($partialTime); $planet->updateResources($partialTime);
if (CheckPlanetBuildingQueue($planet, $user)) { /*if (CheckPlanetBuildingQueue($planet, $user)) {
SetNextQueueElementOnTop($planet, $user); SetNextQueueElementOnTop($planet, $user);
} }*/
} else { } else {
$planet->updateResources($time); $planet->updateResources($time);
break; break;

View file

@ -2,8 +2,19 @@
class Math class Math
{ {
const DEFAULT_PRECISTION = 0;
protected static $_singleton = null; protected static $_singleton = null;
public static function setPrecision($precision = null)
{
if ($precision === null) {
$precision = self::DEFAULT_PRECISTION;
}
self::getSingleton()->setPrecision($precision);
}
public static function getSingleton() public static function getSingleton()
{ {
if (self::$_singleton === null) { if (self::$_singleton === null) {

View file

@ -2,6 +2,11 @@
class Math_Bcmath class Math_Bcmath
{ {
public function setPrecision($precision)
{
bcscale($precision);
}
public function add($a, $b) public function add($a, $b)
{ {
return bcadd($a, $b); return bcadd($a, $b);

View file

@ -2,6 +2,10 @@
class Math_Native class Math_Native
{ {
public function setPrecision($precision)
{
}
public function add($a, $b) public function add($a, $b)
{ {
return $a + $b; return $a + $b;

View file

@ -2,27 +2,54 @@
include './bootstrap.php'; include './bootstrap.php';
$planet = Legacies_Empire_Model_Planet::factory(1); if (!extension_loaded('xdebug')) {
header('Content-Type: text/plain');
}
var_dump($resource->getAllDatas(), $production->getAllDatas(), array( $planet = new Legacies_Empire_Model_Planet(array(
'last_update' => $planet->getData('last_update'), 'last_update' => 0,
'metal' => $planet->getData('metal'), 'planet_type' => 1,
'cristal' => $planet->getData('crystal'),
'deuterium' => $planet->getData('deuterium'), 'metal' => 0,
'energy_max' => $planet->getData('energy_max'), 'metal_perhour' => 20,
'energy_used' => $planet->getData('energy_used') 'crystal' => 0,
'crystal_perhour' => 10,
'deuterium' => 0,
'deuterium_perhour' => 0,
'energy_max' => 0,
'energy_used' => 0,
'metal_mine_porcent' => 10,
'crystal_mine_porcent' => 10,
'solar_plant_porcent' => 10,
'fusion_plant_porcent' => 10,
'solar_satelit_porcent' => 10,
'deuterium_sintetizer_porcent' => 10,
'metal_mine' => 10,
'crystal_mine' => 0,
'deuterium_sintetizer' => 0,
'solar_plant' => 0,
'fusion_plant' => 0,
'robot_factory' => 0,
'nano_factory' => 0,
'hangar' => 0,
'metal_store' => 5,
'crystal_store' => 5,
'deuterium_store' => 5,
'rpg_stockeur' => 0
)); ));
var_dump($planet->getAllDatas());
$planet->updateStorages(3600);
var_dump($planet->getAllDatas());
Legacies::dispatchEvent('planet.update', array( Legacies::dispatchEvent('planet.update', array(
'planet' => $planet 'planet' => $planet,
'time' => 3600
)); ));
header('Content-Type: text/plain'); var_dump($planet->getAllDatas());
var_dump(array(
'last_update' => $planet->getData('last_update'),
'metal' => $planet->getData('metal'),
'cristal' => $planet->getData('crystal'),
'deuterium' => $planet->getData('deuterium'),
'energy_max' => $planet->getData('energy_max'),
'energy_used' => $planet->getData('energy_used')
));

View file

@ -58,7 +58,7 @@ define('MAX_FLEET_OR_DEFS_PER_ROW', 100000000);
// Taux de depassement possible dans l'espace de stockage des hangars ... // Taux de depassement possible dans l'espace de stockage des hangars ...
// 1.0 pour 100% - 1.1 pour 110% etc ... // 1.0 pour 100% - 1.1 pour 110% etc ...
define('MAX_OVERFLOW', 1.1); define('MAX_OVERFLOW', 1);
define('SHOW_ADMIN_IN_RECORDS', false); define('SHOW_ADMIN_IN_RECORDS', false);

View file

@ -5,7 +5,6 @@
'field' => Legacies_Empire::RESOURCE_METAL, 'field' => Legacies_Empire::RESOURCE_METAL,
'production_field' => 'metal_perhour', 'production_field' => 'metal_perhour',
'ratio_field' => 'metal_porcent',
'storage_field' => 'metal_max', 'storage_field' => 'metal_max',
'production' => array( 'production' => array(
Legacies_Empire::ID_BUILDING_METAL_MINE => 'metal_mine_porcent' Legacies_Empire::ID_BUILDING_METAL_MINE => 'metal_mine_porcent'
@ -18,7 +17,6 @@
'field' => Legacies_Empire::RESOURCE_CRISTAL, 'field' => Legacies_Empire::RESOURCE_CRISTAL,
'production_field' => 'crystal_perhour', 'production_field' => 'crystal_perhour',
'ratio_field' => 'crystal_porcent',
'storage_field' => 'crystal_max', 'storage_field' => 'crystal_max',
'production' => array( 'production' => array(
Legacies_Empire::ID_BUILDING_CRISTAL_MINE => 'crystal_mine_porcent' Legacies_Empire::ID_BUILDING_CRISTAL_MINE => 'crystal_mine_porcent'
@ -31,7 +29,6 @@
'field' => Legacies_Empire::RESOURCE_DEUTERIUM, 'field' => Legacies_Empire::RESOURCE_DEUTERIUM,
'production_field' => 'deuterium_perhour', 'production_field' => 'deuterium_perhour',
'ratio_field' => 'deuterium_porcent',
'storage_field' => 'deuterium_max', 'storage_field' => 'deuterium_max',
'production' => array( 'production' => array(
Legacies_Empire::ID_BUILDING_DEUTERIUM_SYNTHETISER => 'deuterium_sintetizer_porcent' Legacies_Empire::ID_BUILDING_DEUTERIUM_SYNTHETISER => 'deuterium_sintetizer_porcent'
@ -44,7 +41,7 @@
'field' => 'energy_used', 'field' => 'energy_used',
'production_field' => 'energy_max', 'production_field' => 'energy_max',
'storage_field' => 'energy_used', 'storage_field' => null,
'production' => array( 'production' => array(
Legacies_Empire::ID_BUILDING_SOLAR_PLANT => 'solar_plant_porcent', Legacies_Empire::ID_BUILDING_SOLAR_PLANT => 'solar_plant_porcent',
Legacies_Empire::ID_BUILDING_FUSION_REACTOR => 'fusion_plant_porcent', Legacies_Empire::ID_BUILDING_FUSION_REACTOR => 'fusion_plant_porcent',

View file

@ -116,7 +116,8 @@
Legacies_Empire::ID_BUILDING_DEUTERIUM_SYNTHETISER, Legacies_Empire::ID_BUILDING_DEUTERIUM_SYNTHETISER,
Legacies_Empire::ID_BUILDING_SOLAR_PLANT, Legacies_Empire::ID_BUILDING_SOLAR_PLANT,
Legacies_Empire::ID_BUILDING_FUSION_REACTOR, Legacies_Empire::ID_BUILDING_FUSION_REACTOR,
Legacies_Empire::ID_SHIP_SOLAR_SATELLITE Legacies_Empire::ID_SHIP_SOLAR_SATELLITE,
Legacies_Empire::ID_SHIP_SUPERNOVA
) )
// }}} // }}}
); );