Planet storage capacity updates added
Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>
This commit is contained in:
parent
66875791e6
commit
e15d9f81a7
9 changed files with 108 additions and 46 deletions
|
|
@ -131,12 +131,12 @@ class Legacies_Empire
|
|||
|
||||
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 $resource[$id];
|
||||
return $fieldsAlias[$id];
|
||||
}
|
||||
}
|
||||
|
|
@ -61,9 +61,33 @@ class Legacies_Empire_Model_Planet
|
|||
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)
|
||||
{
|
||||
$types = Legacies_Empire_Model_Game_Types::getSingleton();
|
||||
$resources = Legacies_Empire_Model_Game_Resources::getSingleton();
|
||||
$production = Legacies_Empire_Model_Game_Production::getSingleton();
|
||||
|
||||
if ($time === null) {
|
||||
$time = $this->_now();
|
||||
|
|
@ -74,15 +98,7 @@ class Legacies_Empire_Model_Planet
|
|||
}
|
||||
|
||||
$resourcesProductions = array();
|
||||
foreach (self::$_productionConfig 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 ($resources->getAllDatas() as $resource => $resourceData) {
|
||||
foreach ($resourceData['production'] as $productionUnit => $ratioField) {
|
||||
if (!in_array($productionUnit, $types['prod'])) {
|
||||
continue;
|
||||
|
|
@ -101,20 +117,21 @@ class Legacies_Empire_Model_Planet
|
|||
}
|
||||
}
|
||||
}
|
||||
var_dump($resourcesProductions);
|
||||
|
||||
$timeDiff = ($time - $this->getData('last_update')) / 3600;
|
||||
foreach ($resourcesProductions as $resource => $productionPerHour) {
|
||||
if (!isset(self::$_productionConfig[$resource])) {
|
||||
if (!isset($resources[$resource])) {
|
||||
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) {
|
||||
$production = $this->getData(self::$_productionConfig[$resource]['storage_field']);
|
||||
if (Math::comp($production, $this->getData($resources[$resource]['storage_field'])) > 0) {
|
||||
$production = $this->getData($resources[$resource]['storage_field']);
|
||||
}
|
||||
$this->setData(self::$_productionConfig[$resource]['field'], $production);
|
||||
$this->setData($resources[$resource]['field'], $production);
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
|
@ -446,7 +463,7 @@ class Legacies_Empire_Model_Planet
|
|||
$time = time();
|
||||
}
|
||||
|
||||
if ($planet === null || !$planet instanceof Legacies_Empire_Model_Planet || !$planet->getId()) {
|
||||
if ($planet === null || !$planet instanceof Legacies_Empire_Model_Planet) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -458,9 +475,9 @@ class Legacies_Empire_Model_Planet
|
|||
|
||||
if ($partialTime < $time) {
|
||||
$planet->updateResources($partialTime);
|
||||
if (CheckPlanetBuildingQueue($planet, $user)) {
|
||||
/*if (CheckPlanetBuildingQueue($planet, $user)) {
|
||||
SetNextQueueElementOnTop($planet, $user);
|
||||
}
|
||||
}*/
|
||||
} else {
|
||||
$planet->updateResources($time);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -2,8 +2,19 @@
|
|||
|
||||
class Math
|
||||
{
|
||||
const DEFAULT_PRECISTION = 0;
|
||||
|
||||
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()
|
||||
{
|
||||
if (self::$_singleton === null) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,11 @@
|
|||
|
||||
class Math_Bcmath
|
||||
{
|
||||
public function setPrecision($precision)
|
||||
{
|
||||
bcscale($precision);
|
||||
}
|
||||
|
||||
public function add($a, $b)
|
||||
{
|
||||
return bcadd($a, $b);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
class Math_Native
|
||||
{
|
||||
public function setPrecision($precision)
|
||||
{
|
||||
}
|
||||
|
||||
public function add($a, $b)
|
||||
{
|
||||
return $a + $b;
|
||||
|
|
|
|||
|
|
@ -2,27 +2,54 @@
|
|||
|
||||
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(
|
||||
'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')
|
||||
$planet = new Legacies_Empire_Model_Planet(array(
|
||||
'last_update' => 0,
|
||||
'planet_type' => 1,
|
||||
|
||||
'metal' => 0,
|
||||
'metal_perhour' => 20,
|
||||
'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(
|
||||
'planet' => $planet
|
||||
'planet' => $planet,
|
||||
'time' => 3600
|
||||
));
|
||||
|
||||
header('Content-Type: text/plain');
|
||||
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')
|
||||
));
|
||||
var_dump($planet->getAllDatas());
|
||||
|
|
@ -58,7 +58,7 @@ define('MAX_FLEET_OR_DEFS_PER_ROW', 100000000);
|
|||
|
||||
// Taux de depassement possible dans l'espace de stockage des hangars ...
|
||||
// 1.0 pour 100% - 1.1 pour 110% etc ...
|
||||
define('MAX_OVERFLOW', 1.1);
|
||||
define('MAX_OVERFLOW', 1);
|
||||
|
||||
define('SHOW_ADMIN_IN_RECORDS', false);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
'field' => Legacies_Empire::RESOURCE_METAL,
|
||||
'production_field' => 'metal_perhour',
|
||||
'ratio_field' => 'metal_porcent',
|
||||
'storage_field' => 'metal_max',
|
||||
'production' => array(
|
||||
Legacies_Empire::ID_BUILDING_METAL_MINE => 'metal_mine_porcent'
|
||||
|
|
@ -18,7 +17,6 @@
|
|||
|
||||
'field' => Legacies_Empire::RESOURCE_CRISTAL,
|
||||
'production_field' => 'crystal_perhour',
|
||||
'ratio_field' => 'crystal_porcent',
|
||||
'storage_field' => 'crystal_max',
|
||||
'production' => array(
|
||||
Legacies_Empire::ID_BUILDING_CRISTAL_MINE => 'crystal_mine_porcent'
|
||||
|
|
@ -31,7 +29,6 @@
|
|||
|
||||
'field' => Legacies_Empire::RESOURCE_DEUTERIUM,
|
||||
'production_field' => 'deuterium_perhour',
|
||||
'ratio_field' => 'deuterium_porcent',
|
||||
'storage_field' => 'deuterium_max',
|
||||
'production' => array(
|
||||
Legacies_Empire::ID_BUILDING_DEUTERIUM_SYNTHETISER => 'deuterium_sintetizer_porcent'
|
||||
|
|
@ -44,7 +41,7 @@
|
|||
|
||||
'field' => 'energy_used',
|
||||
'production_field' => 'energy_max',
|
||||
'storage_field' => 'energy_used',
|
||||
'storage_field' => null,
|
||||
'production' => array(
|
||||
Legacies_Empire::ID_BUILDING_SOLAR_PLANT => 'solar_plant_porcent',
|
||||
Legacies_Empire::ID_BUILDING_FUSION_REACTOR => 'fusion_plant_porcent',
|
||||
|
|
|
|||
|
|
@ -116,7 +116,8 @@
|
|||
Legacies_Empire::ID_BUILDING_DEUTERIUM_SYNTHETISER,
|
||||
Legacies_Empire::ID_BUILDING_SOLAR_PLANT,
|
||||
Legacies_Empire::ID_BUILDING_FUSION_REACTOR,
|
||||
Legacies_Empire::ID_SHIP_SOLAR_SATELLITE
|
||||
Legacies_Empire::ID_SHIP_SOLAR_SATELLITE,
|
||||
Legacies_Empire::ID_SHIP_SUPERNOVA
|
||||
)
|
||||
// }}}
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue