Passed
Branch trunk (7dc288)
by SuperNova.WS
06:07
created

resources.php (4 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
29
/**
30
 * @param $resource_id
31
 * @param ResourceCalculations $capsObj
32
 */
33
function int_calc_storage_bar($resource_id, $capsObj)
34
{
35
  global $lang, $template, $planetrow, $user;
36
37
  $totalProduction      = $capsObj->getProduction($resource_id);
38
  $storage_fill         = $capsObj->getStorage($resource_id) ? floor(mrc_get_level($user, $planetrow, $resource_id) / $capsObj->getStorage($resource_id) * 100) : 0;
39
40
  $template->assign_block_vars('resources', [
41
    'NAME'        => $lang["sys_" . pname_resource_name($resource_id)],
42
43
    'HOURLY'      => prettyNumberStyledDefault($totalProduction),
44
    'DAILY'       => prettyNumberStyledDefault($totalProduction * 24),
45
    'WEEKLY'      => prettyNumberStyledDefault($totalProduction * 24 * 7),
46
    'MONTHLY'     => prettyNumberStyledDefault($totalProduction * 24 * 30),
47
48
    'STORAGE'     => intval($storage_fill),
49
    'BAR'         => min($storage_fill, 100),
50
  ]);
51
};
52
53
$ValidList['percent'] = array (  0,  10,  20,  30,  40,  50,  60,  70,  80,  90, 100 );
54
$template = gettemplate('resources', true);
0 ignored issues
show
true of type true is incompatible with the type null|template expected by parameter $template of gettemplate(). ( Ignorable by Annotation )

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

54
$template = gettemplate('resources', /** @scrutinizer ignore-type */ true);
Loading history...
55
56
$transmutation_result = sn_sys_planet_core_transmute($user, $planetrow);
57
if(!empty($transmutation_result))
58
{
59
  $template->assign_block_vars('result', $transmutation_result); // array('STATUS' => $transmutation_result['STATUS'], 'MESSAGE' => $transmutation_result['MESSAGE']));
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
60
}
61
62
$sn_group_factories = sn_get_groups('factories');
63
$production = $_POST['production'];
64
//$SubQry     = '';
65
$SubQry     = array();
66
if(is_array($production)) {
67
  foreach($production as $prod_id => $percent) {
68
    if($percent > 100 || $percent < 0) {
69
      $debug->warning('Supplying wrong production percent (less then 0 or greater then 100)', 'Hack attempt', 302, array('base_dump' => true));
70
      die();
71
    }
72
73
    $prod_id = intval($prod_id);
74
    if(in_array($prod_id, $sn_group_factories) && get_unit_param($prod_id, P_MINING_IS_MANAGED)) {
75
      $field_name              = pname_factory_production_field_name($prod_id);
76
      $percent                 = floor($percent / 10);
77
      $planetrow[$field_name]  = $percent;
78
      //$SubQry                 .= "`{$field_name}` = '{$percent}',";
79
      $SubQry[]                 = "`{$field_name}` = '{$percent}'";
80
    } else {
81
      $debug->warning('Supplying wrong ID in production array - attempt to change some field - ID' . $prod_id, 'Resource Page', 301);
82
      continue;
83
    }
84
  }
85
86
//  $SubQry = substr($SubQry, 0, -1);
87
//  if($SubQry) {
88
//    db_planet_set_by_id($planetrow['id'], $SubQry);
89
//  }
90
  !empty($SubQry) ? DBStaticPlanet::db_planet_set_by_id($planetrow['id'], implode(',', $SubQry)) : false;
91
}
92
93
// -------------------------------------------------------------------------------------------------------
94
// $BuildTemp                   = $planetrow[ 'temp_max' ];
95
// $BuildEnergyTech             = $user['energy_tech'];
96
97
for ($Option = 10; $Option >= 0; $Option--)
98
{
99
 $template->assign_block_vars('option', array(
100
   'VALUE' => $Option * 10,
101
 ));
102
}
103
104
$capsObj = new ResourceCalculations();
105
$capsObj->eco_get_planet_caps($user, $planetrow, 3600);
106
107
$template->assign_block_vars('production', array(
108
  'TYPE'           => $lang['res_basic_income'],
109
110
  'METAL_TYPE'     => prettyNumberStyledDefault($capsObj->productionCurrentMatrix[RES_METAL][0]),
111
  'CRYSTAL_TYPE'   => prettyNumberStyledDefault($capsObj->productionCurrentMatrix[RES_CRYSTAL][0]),
112
  'DEUTERIUM_TYPE' => prettyNumberStyledDefault($capsObj->productionCurrentMatrix[RES_DEUTERIUM][0]),
113
  'ENERGY_TYPE'    => prettyNumberStyledDefault($capsObj->productionCurrentMatrix[RES_ENERGY][0]),
114
));
115
116
foreach($sn_group_factories as $unit_id)
117
{
118
  if(mrc_get_level($user, $planetrow, $unit_id) > 0 && get_unit_param($unit_id))
119
  {
120
    $level_plain = mrc_get_level($user, $planetrow, $unit_id, false, true);
121
    $template->assign_block_vars('production', array(
122
      'ID'             => $unit_id,
123
      'PERCENT'        => $planetrow[pname_factory_production_field_name($unit_id)] * 10,
124
      'TYPE'           => $lang['tech'][$unit_id],
125
      'LEVEL'          => $level_plain,
126
      'LEVEL_BONUS'    => mrc_get_level($user, $planetrow, $unit_id) - $level_plain,
127
      'LEVEL_TYPE'     => ($unit_id > 200) ? $lang['quantity'] : $lang['level'],
128
129
      'METAL_TYPE'     => prettyNumberStyledDefault($capsObj->productionCurrentMatrix[RES_METAL][$unit_id]),
130
      'CRYSTAL_TYPE'   => prettyNumberStyledDefault($capsObj->productionCurrentMatrix[RES_CRYSTAL][$unit_id]),
131
      'DEUTERIUM_TYPE' => prettyNumberStyledDefault($capsObj->productionCurrentMatrix[RES_DEUTERIUM][$unit_id]),
132
      'ENERGY_TYPE'    => prettyNumberStyledDefault($capsObj->productionCurrentMatrix[RES_ENERGY][$unit_id]),
133
134
      'METAL_FULL'     => prettyNumberStyledDefault($capsObj->productionFullMatrix[RES_METAL][$unit_id]),
135
      'CRYSTAL_FULL'   => prettyNumberStyledDefault($capsObj->productionFullMatrix[RES_CRYSTAL][$unit_id]),
136
      'DEUTERIUM_FULL' => prettyNumberStyledDefault($capsObj->productionFullMatrix[RES_DEUTERIUM][$unit_id]),
137
      'ENERGY_FULL'    => prettyNumberStyledDefault($capsObj->productionFullMatrix[RES_ENERGY][$unit_id]),
138
139
      'P_MINING_IS_MANAGED' => get_unit_param($unit_id, P_MINING_IS_MANAGED),
140
    ));
141
  }
142
}
143
144
$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

144
$user_dark_matter = mrc_get_level($user, /** @scrutinizer ignore-type */ false, RES_DARK_MATTER);
Loading history...
145
$planet_density_index = $planetrow['density_index'];
146
$density_price_chart = planet_density_price_chart($planetrow);
147
tpl_planet_density_info($template, $density_price_chart, $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 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

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