Completed
Push — trunk ( 8dcff2...338765 )
by SuperNova.WS
04:11
created

resources.php (5 issues)

1
<?php
2
3
/**
4
 * resources.php
5
 *
6
 * Planet resource interface page
7
 *
8
 * 2.2 - copyright (ñ) 2010 by Gorlum for http://supernova.ws
9
 *   [~] - more optimization to utilize PTE
10
 *   [~] - code formatting according to PCG
11
 *   [~] - content of BuildRessourcePage.php moved to resource.php
12
 * 2.1 - copyright 2010 by Gorlum for http://supernova.ws
13
 *   [~] - Security checked for SQL-injection
14
 * 2.0 - copyright 2010 by Gorlum for http://supernova.ws
15
 *   [+] - almost fully rewrote and optimized
16
 * 1.0 [BuildRessourcePage.php] copyright 2008 by ShadoV for XNova
17
 *   [+] - Mise en module initiale (creation)
18
 * 1.1 - copyright 2010 by Gorlum for http://supernova.ws
19
 *   [%] - Security checks & tests by Gorlum for http://supernova.ws
20
 * 1.0 copyright (ñ) 2008 by Chlorel for XNova
21
 *   [!] - Passage en fonction pour utilisation XNova
22
 *
23
**/
24
25
include('common.' . substr(strrchr(__FILE__, '.'), 1));
26
27
use \Meta\Economic\ResourceCalculations;
28
use Planet\DBStaticPlanet;
29
30
/**
31
 * @param $resource_id
32
 * @param ResourceCalculations $capsObj
33
 */
34
function int_calc_storage_bar($resource_id, $capsObj)
35
{
36
  global $lang, $template, $planetrow, $user;
37
38
  $totalProduction      = $capsObj->getProduction($resource_id);
39
  $storage_fill         = $capsObj->getStorage($resource_id) ? floor(mrc_get_level($user, $planetrow, $resource_id) / $capsObj->getStorage($resource_id) * 100) : 0;
40
41
  $template->assign_block_vars('resources', [
42
    'NAME'        => $lang["sys_" . pname_resource_name($resource_id)],
43
44
    'HOURLY'      => $totalProduction,
45
    'DAILY'       => $totalProduction * 24,
46
    'WEEKLY'      => $totalProduction * 24 * 7,
47
    'MONTHLY'     => $totalProduction * 24 * 30,
48
49
    'STORAGE'     => intval($storage_fill),
50
    'BAR'         => min($storage_fill, 100),
51
  ]);
52
};
53
54
$ValidList['percent'] = array (  0,  10,  20,  30,  40,  50,  60,  70,  80,  90, 100 );
55
$template = gettemplate('resources', true);
56
57
$planet = new \Planet\Planet($planetrow['id']);
58
if(!empty($transmutation_result = $planet->sn_sys_planet_core_transmute($user))) {
0 ignored issues
show
Deprecated Code introduced by
The function Planet\Planet::sn_sys_planet_core_transmute() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

58
if(!empty($transmutation_result = /** @scrutinizer ignore-deprecated */ $planet->sn_sys_planet_core_transmute($user))) {
Loading history...
59
  $template->assign_block_vars('result', $transmutation_result);
60
  $planet = new \Planet\Planet($planetrow['id']);
61
}
62
63
$sn_group_factories = sn_get_groups('factories');
64
$production = $_POST['production'];
65
//$SubQry     = '';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
66
$SubQry     = array();
67
if(is_array($production)) {
68
  foreach($production as $prod_id => $percent) {
69
    if($percent > 100 || $percent < 0) {
70
      $debug->warning('Supplying wrong production percent (less then 0 or greater then 100)', 'Hack attempt', 302, array('base_dump' => true));
71
      die();
72
    }
73
74
    $prod_id = intval($prod_id);
75
    if(in_array($prod_id, $sn_group_factories) && get_unit_param($prod_id, P_MINING_IS_MANAGED)) {
76
      $field_name              = pname_factory_production_field_name($prod_id);
77
      $percent                 = floor($percent / 10);
78
      $planetrow[$field_name]  = $percent;
79
      //$SubQry                 .= "`{$field_name}` = '{$percent}',";
80
      $SubQry[]                 = "`{$field_name}` = '{$percent}'";
81
    } else {
82
      $debug->warning('Supplying wrong ID in production array - attempt to change some field - ID' . $prod_id, 'Resource Page', 301);
83
      continue;
84
    }
85
  }
86
87
//  $SubQry = substr($SubQry, 0, -1);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
88
//  if($SubQry) {
89
//    db_planet_set_by_id($planetrow['id'], $SubQry);
90
//  }
91
  !empty($SubQry) ? DBStaticPlanet::db_planet_set_by_id($planetrow['id'], implode(',', $SubQry)) : false;
92
}
93
94
// -------------------------------------------------------------------------------------------------------
95
// $BuildTemp                   = $planetrow[ 'temp_max' ];
96
// $BuildEnergyTech             = $user['energy_tech'];
97
98
for ($Option = 10; $Option >= 0; $Option--)
99
{
100
 $template->assign_block_vars('option', array(
101
   'VALUE' => $Option * 10,
102
 ));
103
}
104
105
$capsObj = new ResourceCalculations();
106
$capsObj->eco_get_planet_caps($user, $planetrow, 3600);
107
108
$template->assign_block_vars('production', array(
109
  'TYPE'           => $lang['res_basic_income'],
110
111
  'METAL_TYPE'     => $capsObj->productionCurrentMatrix[RES_METAL][0],
112
  'CRYSTAL_TYPE'   => $capsObj->productionCurrentMatrix[RES_CRYSTAL][0],
113
  'DEUTERIUM_TYPE' => $capsObj->productionCurrentMatrix[RES_DEUTERIUM][0],
114
  'ENERGY_TYPE'    => $capsObj->productionCurrentMatrix[RES_ENERGY][0],
115
));
116
117
foreach($sn_group_factories as $unit_id)
118
{
119
  if(mrc_get_level($user, $planetrow, $unit_id) > 0 && get_unit_param($unit_id))
120
  {
121
    $level_plain = mrc_get_level($user, $planetrow, $unit_id, false, true);
122
    $template->assign_block_vars('production', array(
123
      'ID'             => $unit_id,
124
      'PERCENT'        => $planetrow[pname_factory_production_field_name($unit_id)] * 10,
125
      'TYPE'           => $lang['tech'][$unit_id],
126
      'LEVEL'          => $level_plain,
127
      'LEVEL_BONUS'    => mrc_get_level($user, $planetrow, $unit_id) - $level_plain,
128
      'LEVEL_TYPE'     => ($unit_id > 200) ? $lang['quantity'] : $lang['level'],
129
130
      'METAL_TYPE'     => $capsObj->productionCurrentMatrix[RES_METAL][$unit_id],
131
      'CRYSTAL_TYPE'   => $capsObj->productionCurrentMatrix[RES_CRYSTAL][$unit_id],
132
      'DEUTERIUM_TYPE' => $capsObj->productionCurrentMatrix[RES_DEUTERIUM][$unit_id],
133
      'ENERGY_TYPE'    => $capsObj->productionCurrentMatrix[RES_ENERGY][$unit_id],
134
135
      'METAL_FULL'     => $capsObj->productionFullMatrix[RES_METAL][$unit_id],
136
      'CRYSTAL_FULL'   => $capsObj->productionFullMatrix[RES_CRYSTAL][$unit_id],
137
      'DEUTERIUM_FULL' => $capsObj->productionFullMatrix[RES_DEUTERIUM][$unit_id],
138
      'ENERGY_FULL'    => $capsObj->productionFullMatrix[RES_ENERGY][$unit_id],
139
140
      'P_MINING_IS_MANAGED' => get_unit_param($unit_id, P_MINING_IS_MANAGED),
141
    ));
142
  }
143
}
144
145
146
$user_dark_matter = mrc_get_level($user, false, RES_DARK_MATTER);
0 ignored issues
show
false of type false is incompatible with the type array expected by parameter $planet of mrc_get_level(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

146
$user_dark_matter = mrc_get_level($user, /** @scrutinizer ignore-type */ false, RES_DARK_MATTER);
Loading history...
147
$planet = new \Planet\Planet($planetrow['id']);
148
$template->assign_recursive($planet->tpl_planet_density_info($user_dark_matter));
0 ignored issues
show
It seems like $user_dark_matter can also be of type boolean and double; however, parameter $user_dark_matter of Planet\Planet::tpl_planet_density_info() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

148
$template->assign_recursive($planet->tpl_planet_density_info(/** @scrutinizer ignore-type */ $user_dark_matter));
Loading history...
149
150
$template->assign_block_vars('production', array(
151
  'TYPE'           => $lang['res_total'],
152
153
  'METAL_TYPE'     => $capsObj->getProduction(RES_METAL),
154
  'CRYSTAL_TYPE'   => $capsObj->getProduction(RES_CRYSTAL),
155
  'DEUTERIUM_TYPE' => $capsObj->getProduction(RES_DEUTERIUM),
156
  'ENERGY_TYPE'    => $capsObj->getProduction(RES_ENERGY),
157
158
  'METAL_FULL'     => $capsObj->getProductionFull(RES_METAL),
159
  'CRYSTAL_FULL'   => $capsObj->getProductionFull(RES_CRYSTAL),
160
  'DEUTERIUM_FULL' => $capsObj->getProductionFull(RES_DEUTERIUM),
161
  'ENERGY_FULL'    => $capsObj->getProductionFull(RES_ENERGY),
162
));
163
164
int_calc_storage_bar(RES_METAL, $capsObj);
165
int_calc_storage_bar(RES_CRYSTAL, $capsObj);
166
int_calc_storage_bar(RES_DEUTERIUM, $capsObj);
167
168
$template->assign_vars(array(
169
 'PLANET_NAME'          => $planetrow['name'],
170
 'PLANET_TYPE'          => $planetrow['planet_type'],
171
172
 'PRODUCTION_LEVEL'     => floor($capsObj->efficiency * 100),
173
174
 'PAGE_HINT'            => $lang['res_hint'],
175
));
176
177
display($template, $lang['res_planet_production']);
178