Completed
Push — work-fleets ( aedb07...3b3d1f )
by SuperNova.WS
05:31
created
includes/includes/market_info.inc 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 $classLocale = classLocale::$lang;
4 4
 
5
-if(!defined('SN_IN_MARKET') || SN_IN_MARKET !== true)
5
+if (!defined('SN_IN_MARKET') || SN_IN_MARKET !== true)
6 6
 {
7 7
   $debug->error("Attempt to call market page mode {$mode} directly - not from market.php", 'Forbidden', 403);
8 8
 }
@@ -17,50 +17,50 @@  discard block
 block discarded – undo
17 17
 ));
18 18
 
19 19
 $info_action = sys_get_param_int('action');
20
-if($info_action)
20
+if ($info_action)
21 21
 {
22 22
   try
23 23
   {
24 24
     sn_db_transaction_start();
25 25
 
26 26
     $user = db_user_by_id($user['id'], true);
27
-    if(mrc_get_level($user, null, RES_DARK_MATTER) < $config->rpg_cost_info)
27
+    if (mrc_get_level($user, null, RES_DARK_MATTER) < $config->rpg_cost_info)
28 28
     {
29 29
       throw new Exception(MARKET_NO_DM, ERR_ERROR);
30 30
     }
31 31
 
32
-    switch($info_action)
32
+    switch ($info_action)
33 33
     {
34 34
       case MARKET_INFO_PLAYER:
35 35
         $user_info_name_unsafe = sys_get_param_str_unsafe('user_info_name');
36
-        if(!$user_info_name_unsafe)
36
+        if (!$user_info_name_unsafe)
37 37
         {
38 38
           throw new Exception(MARKET_INFO_PLAYER_WRONG, ERR_ERROR);
39 39
         }
40 40
 
41
-        if(is_id($user_info_name_unsafe))
41
+        if (is_id($user_info_name_unsafe))
42 42
         {
43 43
           $user_info = db_user_by_id($user_info_name_unsafe, true, '`id`, `username`', true);
44 44
         }
45
-        if(!is_array($user_info))
45
+        if (!is_array($user_info))
46 46
         {
47 47
           $user_info = db_user_by_username($user_info_name_unsafe, true, '`id`, `username`', true, true);
48 48
         }
49
-        if(!is_array($user_info))
49
+        if (!is_array($user_info))
50 50
         {
51 51
           throw new Exception(MARKET_INFO_PLAYER_NOT_FOUND, ERR_ERROR);
52 52
         }
53
-        if($user_info['id'] == $user['id'])
53
+        if ($user_info['id'] == $user['id'])
54 54
         {
55 55
           throw new Exception(MARKET_INFO_PLAYER_SAME, ERR_ERROR);
56 56
         }
57 57
 
58 58
         $msg_text = array();
59
-        foreach(sn_get_groups('mercenaries') as $mercenary_id)
59
+        foreach (sn_get_groups('mercenaries') as $mercenary_id)
60 60
         {
61 61
           $msg_text[] = "{$classLocale['tech'][$mercenary_id]} - " . (($mercenary_level = mrc_get_level($user_info, null, $mercenary_id)) ? "{$classLocale['sys_level']} {$mercenary_level}" : classLocale::$lang['eco_mrk_info_not_hired']);
62 62
         }
63
-        if($mercenary_level = mrc_get_level($user_info, null, UNIT_PREMIUM))
63
+        if ($mercenary_level = mrc_get_level($user_info, null, UNIT_PREMIUM))
64 64
         {
65 65
           $msg_text[] = "{$classLocale['tech'][UNIT_PREMIUM]} - {$mercenary_level} {$classLocale['sys_level']}";
66 66
         }
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
       break;
75 75
     }
76 76
 
77
-    if(!rpg_points_change($user['id'], RPG_MARKET_INFO_MERCENARY, -$config->rpg_cost_info, "Using Black Market page {$classLocale['eco_mrk_info']} - getting info about user ID {$user_info['id']}"))
77
+    if (!rpg_points_change($user['id'], RPG_MARKET_INFO_MERCENARY, -$config->rpg_cost_info, "Using Black Market page {$classLocale['eco_mrk_info']} - getting info about user ID {$user_info['id']}"))
78 78
     {
79 79
       // TODO: throw new Exception(MARKET_INFO_PLAYER_SAME, ERR_ERROR);
80 80
     }
Please login to merge, or discard this patch.
includes/vars_structures.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
       'factor' => 1.5,
16 16
     ),
17 17
     P_UNIT_PRODUCTION => array(
18
-      RES_METAL     => function ($level, $production_factor, $user, $planet_row) {return  40 * $level * pow(1.1, $level) * (0.1 * $production_factor);},
19
-      RES_ENERGY    => function ($level, $production_factor, $user, $planet_row) {return -13 * $level * pow(1.1, $level) * (0.1 * $production_factor);},
18
+      RES_METAL     => function($level, $production_factor, $user, $planet_row) {return  40 * $level * pow(1.1, $level) * (0.1 * $production_factor); },
19
+      RES_ENERGY    => function($level, $production_factor, $user, $planet_row) {return -13 * $level * pow(1.1, $level) * (0.1 * $production_factor); },
20 20
     ),
21 21
     P_MINING_IS_MANAGED => true,
22 22
   ),
@@ -33,8 +33,8 @@  discard block
 block discarded – undo
33 33
       'factor' => 1.6,
34 34
     ),
35 35
     P_UNIT_PRODUCTION => array(
36
-      RES_CRYSTAL   => function ($level, $production_factor, $user, $planet_row) {return  32 * $level * pow(1.1, $level) * (0.1 * $production_factor);},
37
-      RES_ENERGY    => function ($level, $production_factor, $user, $planet_row) {return -16 * $level * pow(1.1, $level) * (0.1 * $production_factor);},
36
+      RES_CRYSTAL   => function($level, $production_factor, $user, $planet_row) {return  32 * $level * pow(1.1, $level) * (0.1 * $production_factor); },
37
+      RES_ENERGY    => function($level, $production_factor, $user, $planet_row) {return -16 * $level * pow(1.1, $level) * (0.1 * $production_factor); },
38 38
     ),
39 39
     P_MINING_IS_MANAGED => true,
40 40
   ),
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
       'factor' => 1.5,
52 52
     ),
53 53
     P_UNIT_PRODUCTION => array(
54
-      RES_DEUTERIUM => function ($level, $production_factor, $user, $planet_row) {return  10 * $level * pow(1.1, $level) * (0.1 * $production_factor) * (-0.002 * $planet_row["temp_max"] + 1.28);},
55
-      RES_ENERGY    => function ($level, $production_factor, $user, $planet_row) {return -20 * $level * pow(1.1, $level) * (0.1 * $production_factor);},
54
+      RES_DEUTERIUM => function($level, $production_factor, $user, $planet_row) {return  10 * $level * pow(1.1, $level) * (0.1 * $production_factor) * (-0.002 * $planet_row["temp_max"] + 1.28); },
55
+      RES_ENERGY    => function($level, $production_factor, $user, $planet_row) {return -20 * $level * pow(1.1, $level) * (0.1 * $production_factor); },
56 56
     ),
57 57
     P_MINING_IS_MANAGED => true,
58 58
   ),
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
       'factor' => 1.5,
70 70
     ),
71 71
     P_UNIT_PRODUCTION => array(
72
-      RES_ENERGY    => function ($level, $production_factor, $user, $planet_row) {return ($planet_row["temp_max"] / 5 + 15) * $level * pow(1.1, $level) * (0.1 * $production_factor);},
72
+      RES_ENERGY    => function($level, $production_factor, $user, $planet_row) {return ($planet_row["temp_max"] / 5 + 15) * $level * pow(1.1, $level) * (0.1 * $production_factor); },
73 73
     ),
74 74
     P_MINING_IS_MANAGED => true,
75 75
   ),
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
       'factor' => 1.8,
88 88
     ),
89 89
     P_UNIT_PRODUCTION => array(
90
-      RES_DEUTERIUM => function ($level, $production_factor, $user, $planet_row) {return -10 * $level * pow(1.1, $level) * (0.1 * $production_factor);},
91
-      RES_ENERGY    => function ($level, $production_factor, $user, $planet_row) {return  30 * $level * pow(1.05 + 0.01 * mrc_get_level($user, null, TECH_ENERGY), $level) * (0.1 * $production_factor);},
90
+      RES_DEUTERIUM => function($level, $production_factor, $user, $planet_row) {return -10 * $level * pow(1.1, $level) * (0.1 * $production_factor); },
91
+      RES_ENERGY    => function($level, $production_factor, $user, $planet_row) {return  30 * $level * pow(1.05 + 0.01 * mrc_get_level($user, null, TECH_ENERGY), $level) * (0.1 * $production_factor); },
92 92
     ),
93 93
     P_MINING_IS_MANAGED => true,
94 94
   ),
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
       'factor' => 2,
106 106
     ),
107 107
     'storage' => array(
108
-      RES_METAL => function($level) {return BASE_STORAGE_SIZE * pow(1.5, $level);},
108
+      RES_METAL => function($level) {return BASE_STORAGE_SIZE * pow(1.5, $level); },
109 109
     ),
110 110
   ),
111 111
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
       'factor' => 2,
122 122
     ),
123 123
     'storage' => array(
124
-      RES_CRYSTAL => function($level) {return BASE_STORAGE_SIZE * pow(1.5, $level);},
124
+      RES_CRYSTAL => function($level) {return BASE_STORAGE_SIZE * pow(1.5, $level); },
125 125
     ),
126 126
   ),
127 127
 
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
       'factor' => 2,
138 138
     ),
139 139
     'storage' => array(
140
-      RES_DEUTERIUM => function($level) {return BASE_STORAGE_SIZE * pow(1.5, $level);},
140
+      RES_DEUTERIUM => function($level) {return BASE_STORAGE_SIZE * pow(1.5, $level); },
141 141
     ),
142 142
   ),
143 143
 
Please login to merge, or discard this patch.
includes/general.php 1 patch
Spacing   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -14,24 +14,24 @@  discard block
 block discarded – undo
14 14
 function sn_function_call($func_name, $func_arg = array()) {
15 15
   // All data in classSupernova::$functions should be normalized to valid 'callable' state: '<function_name>'|array('<object_name>', '<method_name>')
16 16
 
17
-  if(is_array(classSupernova::$functions[$func_name]) && !is_callable(classSupernova::$functions[$func_name])) {
17
+  if (is_array(classSupernova::$functions[$func_name]) && !is_callable(classSupernova::$functions[$func_name])) {
18 18
     // Chain-callable functions should be made as following:
19 19
     // 1. Never use incomplete calls with parameters "by default"
20 20
     // 2. Reserve last parameter for cumulative result
21 21
     // 3. Use same format for original value and cumulative result (if there is original value)
22 22
     // 4. Honor cumulative result
23 23
     // 5. Return cumulative result
24
-    foreach(classSupernova::$functions[$func_name] as $func_chain_name) {
24
+    foreach (classSupernova::$functions[$func_name] as $func_chain_name) {
25 25
       // По идее - это уже тут не нужно, потому что оно все должно быть callable к этому моменту
26 26
       // Но для старых модулей...
27
-      if(is_callable($func_chain_name)) {
27
+      if (is_callable($func_chain_name)) {
28 28
         $result = call_user_func_array($func_chain_name, $func_arg);
29 29
       }
30 30
     }
31 31
   } else {
32 32
     // TODO: This is left for backward compatibility. Appropriate code should be rewrote!
33 33
     $func_name = isset(classSupernova::$functions[$func_name]) && is_callable(classSupernova::$functions[$func_name]) ? classSupernova::$functions[$func_name] : ('sn_' . $func_name);
34
-    if(is_callable($func_name)) {
34
+    if (is_callable($func_name)) {
35 35
       $result = call_user_func_array($func_name, $func_arg);
36 36
     }
37 37
   }
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
  * @param string $page_name - имя страницы, для которого должен был быть выполнен хук
47 47
  */
48 48
 function execute_hooks(&$hook_list, &$template, $hook_type = null, $page_name = null) {
49
-  if(!empty($hook_list)) {
50
-    foreach($hook_list as $hook) {
51
-      if(is_callable($hook_call = (is_string($hook) ? $hook : (is_array($hook) ? $hook['callable'] : $hook->callable)))) {
49
+  if (!empty($hook_list)) {
50
+    foreach ($hook_list as $hook) {
51
+      if (is_callable($hook_call = (is_string($hook) ? $hook : (is_array($hook) ? $hook['callable'] : $hook->callable)))) {
52 52
         $template = call_user_func($hook_call, $template, $hook_type, $page_name);
53 53
       }
54 54
     }
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
 
149 149
 function pretty_number($n, $floor = true, $color = false, $limit = false, $style = null) {
150 150
   $n = floatval($n);
151
-  if(is_int($floor)) {
151
+  if (is_int($floor)) {
152 152
     $n = round($n, $floor); // , PHP_ROUND_HALF_DOWN
153
-  } elseif($floor === true) {
153
+  } elseif ($floor === true) {
154 154
     $n = floor($n);
155 155
     $floor = 0;
156 156
   } else {
@@ -160,14 +160,14 @@  discard block
 block discarded – undo
160 160
   $ret = $n;
161 161
 
162 162
   $suffix = '';
163
-  if($limit) {
164
-    if($ret > 0) {
165
-      while($ret > $limit) {
163
+  if ($limit) {
164
+    if ($ret > 0) {
165
+      while ($ret > $limit) {
166 166
         $suffix .= 'k';
167 167
         $ret = round($ret / 1000);
168 168
       }
169 169
     } else {
170
-      while($ret < -$limit) {
170
+      while ($ret < -$limit) {
171 171
         $suffix .= 'k';
172 172
         $ret = round($ret / 1000);
173 173
       }
@@ -177,16 +177,16 @@  discard block
 block discarded – undo
177 177
   $ret = number_format($ret, $floor, ',', '.');
178 178
   $ret .= $suffix;
179 179
 
180
-  if($color !== false) {
181
-    if($color === true) {
180
+  if ($color !== false) {
181
+    if ($color === true) {
182 182
       $class = $n == 0 ? 'zero' : ($n > 0 ? 'positive' : 'negative');
183
-    } elseif($color >= 0) {
183
+    } elseif ($color >= 0) {
184 184
       $class = $n == $color ? 'zero' : ($n < $color ? 'positive' : 'negative');
185 185
     } else {
186 186
       $class = ($n == -$color) ? 'zero' : ($n < -$color ? 'negative' : 'positive');
187 187
     }
188 188
 
189
-    if(!isset($style)) {
189
+    if (!isset($style)) {
190 190
       $ret = "<span class='{$class}'>{$ret}</span>";
191 191
     } else {
192 192
       $ret = $style ? $ret = $class : $ret = array('text' => $ret, 'class' => $class);
@@ -311,11 +311,11 @@  discard block
 block discarded – undo
311 311
 
312 312
 function sys_get_param_phone($param_name, $default = '') {
313 313
   $phone_raw = sys_get_param_str_unsafe($param_name, $default = '');
314
-  if($phone_raw) {
314
+  if ($phone_raw) {
315 315
     $phone = $phone_raw[0] == '+' ? '+' : '';
316
-    for($i = 0; $i < strlen($phone_raw); $i++) {
316
+    for ($i = 0; $i < strlen($phone_raw); $i++) {
317 317
       $ord = ord($phone_raw[$i]);
318
-      if($ord >= 48 && $ord <= 57) {
318
+      if ($ord >= 48 && $ord <= 57) {
319 319
         $phone .= $phone_raw[$i];
320 320
       }
321 321
     }
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 }
333 333
 
334 334
 function CheckAbandonPlanetState(&$planet) {
335
-  if($planet['destruyed'] && $planet['destruyed'] <= SN_TIME_NOW) {
335
+  if ($planet['destruyed'] && $planet['destruyed'] <= SN_TIME_NOW) {
336 336
     db_planet_delete_by_id($planet['id']);
337 337
   }
338 338
 }
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
   global $config;
342 342
 
343 343
   static $rate, $sn_group_resources_all, $sn_group_resources_loot;
344
-  if(!$rate) {
344
+  if (!$rate) {
345 345
     $sn_group_resources_all = sn_get_groups('resources_all');
346 346
     $sn_group_resources_loot = sn_get_groups('resources_loot');
347 347
 
@@ -351,19 +351,19 @@  discard block
 block discarded – undo
351 351
   }
352 352
 
353 353
   $unit_cost_data = get_unit_param($unit_id, 'cost');
354
-  if(!is_array($unit_cost_data)) {
354
+  if (!is_array($unit_cost_data)) {
355 355
     return array('total' => 0);
356 356
   }
357 357
   $factor = isset($unit_cost_data['factor']) ? $unit_cost_data['factor'] : 1;
358 358
   $cost_array = array(BUILD_CREATE => array(), 'total' => 0);
359 359
   $unit_level = $unit_level > 0 ? $unit_level : 0;
360
-  foreach($unit_cost_data as $resource_id => $resource_amount) {
361
-    if(!in_array($resource_id, $sn_group_resources_all)) {
360
+  foreach ($unit_cost_data as $resource_id => $resource_amount) {
361
+    if (!in_array($resource_id, $sn_group_resources_all)) {
362 362
       continue;
363 363
     }
364 364
 //    $cost_array[BUILD_CREATE][$resource_id] = $resource_amount * ($factor == 1 ? $unit_level : ((pow($factor, $unit_level) - $factor) / ($factor - 1)));
365 365
     $cost_array[BUILD_CREATE][$resource_id] = round($resource_amount * ($factor == 1 ? $unit_level : ((1 - pow($factor, $unit_level)) / (1 - $factor))));
366
-    if(in_array($resource_id, $sn_group_resources_loot)) {
366
+    if (in_array($resource_id, $sn_group_resources_loot)) {
367 367
       $cost_array['total'] += $cost_array[BUILD_CREATE][$resource_id] * $rate[$resource_id];
368 368
     }
369 369
   }
@@ -447,19 +447,19 @@  discard block
 block discarded – undo
447 447
   $mercenary_level = 0;
448 448
   $unit_db_name = pname_resource_name($unit_id);
449 449
 
450
-  if(in_array($unit_id, sn_get_groups(array('plans', 'mercenaries', 'tech', 'artifacts')))) {
450
+  if (in_array($unit_id, sn_get_groups(array('plans', 'mercenaries', 'tech', 'artifacts')))) {
451 451
     $unit = classSupernova::db_get_unit_by_location($user['id'], LOC_USER, $user['id'], $unit_id);
452 452
     $mercenary_level = is_array($unit) && $unit['unit_level'] ? $unit['unit_level'] : 0;
453
-  } elseif(in_array($unit_id, sn_get_groups(array('structures', 'fleet', 'defense')))) {
453
+  } elseif (in_array($unit_id, sn_get_groups(array('structures', 'fleet', 'defense')))) {
454 454
     $unit = classSupernova::db_get_unit_by_location(is_array($user) ? $user['id'] : $planet['id_owner'], LOC_PLANET, $planet['id'], $unit_id);
455 455
     $mercenary_level = is_array($unit) && $unit['unit_level'] ? $unit['unit_level'] : 0;
456
-  } elseif(in_array($unit_id, sn_get_groups('governors'))) {
456
+  } elseif (in_array($unit_id, sn_get_groups('governors'))) {
457 457
     $mercenary_level = $unit_id == $planet['PLANET_GOVERNOR_ID'] ? $planet['PLANET_GOVERNOR_LEVEL'] : 0;
458
-  } elseif($unit_id == RES_DARK_MATTER) {
458
+  } elseif ($unit_id == RES_DARK_MATTER) {
459 459
     $mercenary_level = $user[$unit_db_name] + ($plain || $user['user_as_ally'] ? 0 : classSupernova::$auth->account->account_metamatter);
460
-  } elseif($unit_id == RES_METAMATTER) {
460
+  } elseif ($unit_id == RES_METAMATTER) {
461 461
     $mercenary_level = classSupernova::$auth->account->account_metamatter; //$user[$unit_db_name];
462
-  } elseif(in_array($unit_id, sn_get_groups(array('resources_loot'))) || $unit_id == UNIT_SECTOR) {
462
+  } elseif (in_array($unit_id, sn_get_groups(array('resources_loot'))) || $unit_id == UNIT_SECTOR) {
463 463
     $mercenary_level = !empty($planet) ? $planet[$unit_db_name] : $user[$unit_db_name];
464 464
   }
465 465
 
@@ -469,19 +469,19 @@  discard block
 block discarded – undo
469 469
 function mrc_modify_value(&$user, $planet = array(), $mercenaries, $value) { return sn_function_call(__FUNCTION__, array(&$user, $planet, $mercenaries, $value)); }
470 470
 
471 471
 function sn_mrc_modify_value(&$user, $planet = array(), $mercenaries, $value, $base_value = null) {
472
-  if(!is_array($mercenaries)) {
472
+  if (!is_array($mercenaries)) {
473 473
     $mercenaries = array($mercenaries);
474 474
   }
475 475
 
476 476
   $base_value = isset($base_value) ? $base_value : $value;
477 477
 
478
-  foreach($mercenaries as $mercenary_id) {
478
+  foreach ($mercenaries as $mercenary_id) {
479 479
     $mercenary_level = mrc_get_level($user, $planet, $mercenary_id);
480 480
 
481 481
     $mercenary = get_unit_param($mercenary_id);
482 482
     $mercenary_bonus = $mercenary['bonus'];
483 483
 
484
-    switch($mercenary['bonus_type']) {
484
+    switch ($mercenary['bonus_type']) {
485 485
       case BONUS_PERCENT_CUMULATIVE:
486 486
         $value *= 1 + $mercenary_level * $mercenary_bonus / 100;
487 487
       break;
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
   $allowed_length = strlen($allowed_chars);
513 513
 
514 514
   $random_string = '';
515
-  for($i = 0; $i < $length; $i++) {
515
+  for ($i = 0; $i < $length; $i++) {
516 516
     $random_string .= $allowed_chars[mt_rand(0, $allowed_length - 1)];
517 517
   }
518 518
 
@@ -532,12 +532,12 @@  discard block
 block discarded – undo
532 532
 
533 533
   $options = '';
534 534
   $option_list = array();
535
-  foreach($user_option_list as $option_group_id => $option_group) {
535
+  foreach ($user_option_list as $option_group_id => $option_group) {
536 536
     $option_list[$option_group_id] = array();
537
-    foreach($option_group as $option_name => $option_value) {
538
-      if(!isset($user[$option_name])) {
537
+    foreach ($option_group as $option_name => $option_value) {
538
+      if (!isset($user[$option_name])) {
539 539
         $user[$option_name] = $option_value;
540
-      } elseif($user[$option_name] == '') {
540
+      } elseif ($user[$option_name] == '') {
541 541
         $user[$option_name] = 0;
542 542
       }
543 543
       $options .= "{$option_name}^{$user[$option_name]}|";
@@ -557,16 +557,16 @@  discard block
 block discarded – undo
557 557
   $option_list = array();
558 558
   $option_string_list = explode('|', $user['options']);
559 559
 
560
-  foreach($option_string_list as $option_string) {
560
+  foreach ($option_string_list as $option_string) {
561 561
     list($option_name, $option_value) = explode('^', $option_string);
562 562
     $option_list[$option_name] = $option_value;
563 563
   }
564 564
 
565 565
   $final_list = array();
566
-  foreach($user_option_list as $option_group_id => $option_group) {
566
+  foreach ($user_option_list as $option_group_id => $option_group) {
567 567
     $final_list[$option_group_id] = array();
568
-    foreach($option_group as $option_name => $option_value) {
569
-      if(!isset($option_list[$option_name])) {
568
+    foreach ($option_group as $option_name => $option_value) {
569
+      if (!isset($option_list[$option_name])) {
570 570
         $option_list[$option_name] = $option_value;
571 571
       }
572 572
       $user[$option_name] = $final_list[$option_group_id][$option_name] = $option_list[$option_name];
@@ -580,12 +580,12 @@  discard block
 block discarded – undo
580 580
 
581 581
 function sys_unit_str2arr($fleet_string) {
582 582
   $fleet_array = array();
583
-  if(!empty($fleet_string)) {
583
+  if (!empty($fleet_string)) {
584 584
     $arrTemp = explode(';', $fleet_string);
585
-    foreach($arrTemp as $temp) {
586
-      if($temp) {
585
+    foreach ($arrTemp as $temp) {
586
+      if ($temp) {
587 587
         $temp = explode(',', $temp);
588
-        if(!empty($temp[0]) && !empty($temp[1])) {
588
+        if (!empty($temp[0]) && !empty($temp[1])) {
589 589
           $fleet_array[$temp[0]] += $temp[1];
590 590
         }
591 591
       }
@@ -597,13 +597,13 @@  discard block
 block discarded – undo
597 597
 
598 598
 function sys_unit_arr2str($unit_list) {
599 599
   $fleet_string = array();
600
-  if(isset($unit_list)) {
601
-    if(!is_array($unit_list)) {
600
+  if (isset($unit_list)) {
601
+    if (!is_array($unit_list)) {
602 602
       $unit_list = array($unit_list => 1);
603 603
     }
604 604
 
605
-    foreach($unit_list as $unit_id => $unit_count) {
606
-      if($unit_id && $unit_count) {
605
+    foreach ($unit_list as $unit_id => $unit_count) {
606
+      if ($unit_id && $unit_count) {
607 607
         $fleet_string[] = "{$unit_id},{$unit_count}";
608 608
       }
609 609
     }
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
   $body = str_replace("\r\n", "\n", $body);
631 631
   $body = str_replace("\n", "\r\n", $body);
632 632
 
633
-  if($html) {
633
+  if ($html) {
634 634
     $body = '<html><head><base href="' . SN_ROOT_VIRTUAL . '"></head><body>' . nl2br($body) . '</body></html>';
635 635
   }
636 636
 
@@ -674,21 +674,21 @@  discard block
 block discarded – undo
674 674
 }
675 675
 
676 676
 function sn_ali_fill_user_ally(&$user) {
677
-  if(!$user['ally_id']) {
677
+  if (!$user['ally_id']) {
678 678
     return;
679 679
   }
680 680
 
681
-  if(!isset($user['ally'])) {
681
+  if (!isset($user['ally'])) {
682 682
     $user['ally'] = db_ally_get_by_id($user['ally_id']);
683 683
   }
684 684
 
685
-  if(!isset($user['ally']['player'])) {
685
+  if (!isset($user['ally']['player'])) {
686 686
     $user['ally']['player'] = db_user_by_id($user['ally']['ally_user_id'], true, '*', false);
687 687
   }
688 688
 }
689 689
 
690 690
 function sn_get_url_contents($url) {
691
-  if(function_exists('curl_init')) {
691
+  if (function_exists('curl_init')) {
692 692
     $crl = curl_init();
693 693
     $timeout = 5;
694 694
     curl_setopt($crl, CURLOPT_URL, $url);
@@ -723,10 +723,10 @@  discard block
 block discarded – undo
723 723
 
724 724
 function get_ship_data($ship_id, $user) {
725 725
   $ship_data = array();
726
-  if(in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) {
727
-    foreach(get_unit_param($ship_id, 'engine') as $engine_info) {
726
+  if (in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) {
727
+    foreach (get_unit_param($ship_id, 'engine') as $engine_info) {
728 728
       $tech_level = intval(mrc_get_level($user, null, $engine_info['tech']));
729
-      if(empty($ship_data) || $tech_level >= $engine_info['min_level']) {
729
+      if (empty($ship_data) || $tech_level >= $engine_info['min_level']) {
730 730
         $ship_data = $engine_info;
731 731
         $ship_data['tech_level'] = $tech_level;
732 732
       }
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
   return $ship_data;
739 739
 }
740 740
 
741
-if(!function_exists('strptime')) {
741
+if (!function_exists('strptime')) {
742 742
   function strptime($date, $format) {
743 743
     $masks = array(
744 744
       '%d' => '(?P<d>[0-9]{2})',
@@ -751,12 +751,12 @@  discard block
 block discarded – undo
751 751
     );
752 752
 
753 753
     $rexep = "#" . strtr(preg_quote($format), $masks) . "#";
754
-    if(preg_match($rexep, $date, $out)) {
754
+    if (preg_match($rexep, $date, $out)) {
755 755
       $ret = array(
756
-        "tm_sec"  => (int)$out['S'],
757
-        "tm_min"  => (int)$out['M'],
758
-        "tm_hour" => (int)$out['H'],
759
-        "tm_mday" => (int)$out['d'],
756
+        "tm_sec"  => (int) $out['S'],
757
+        "tm_min"  => (int) $out['M'],
758
+        "tm_hour" => (int) $out['H'],
759
+        "tm_mday" => (int) $out['d'],
760 760
         "tm_mon"  => $out['m'] ? $out['m'] - 1 : 0,
761 761
         "tm_year" => $out['Y'] > 1900 ? $out['Y'] - 1900 : 0,
762 762
       );
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
 function sn_sys_sector_buy($redirect = 'overview.php') {
772 772
   global $user, $planetrow;
773 773
 
774
-  if(!sys_get_param_str('sector_buy') || $planetrow['planet_type'] != PT_PLANET) {
774
+  if (!sys_get_param_str('sector_buy') || $planetrow['planet_type'] != PT_PLANET) {
775 775
     return;
776 776
   }
777 777
 
@@ -784,9 +784,9 @@  discard block
 block discarded – undo
784 784
 //  $planetrow = $planetrow['planet'];
785 785
   $sector_cost = eco_get_build_data($user, $planetrow, UNIT_SECTOR, mrc_get_level($user, $planetrow, UNIT_SECTOR), true);
786 786
   $sector_cost = $sector_cost[BUILD_CREATE][RES_DARK_MATTER];
787
-  if($sector_cost <= mrc_get_level($user, null, RES_DARK_MATTER)) {
787
+  if ($sector_cost <= mrc_get_level($user, null, RES_DARK_MATTER)) {
788 788
     $planet_name_text = uni_render_planet($planetrow);
789
-    if(rpg_points_change($user['id'], RPG_SECTOR, -$sector_cost, sprintf(classLocale::$lang['sys_sector_purchase_log'],
789
+    if (rpg_points_change($user['id'], RPG_SECTOR, -$sector_cost, sprintf(classLocale::$lang['sys_sector_purchase_log'],
790 790
         $user['username'], $user['id'], $planet_name_text, classLocale::$lang['sys_planet_type'][$planetrow['planet_type']], $planetrow['id'], $sector_cost)
791 791
     )) {
792 792
       $sector_db_name = pname_resource_name(UNIT_SECTOR);
@@ -801,30 +801,30 @@  discard block
 block discarded – undo
801 801
 }
802 802
 
803 803
 function sn_sys_handler_add(&$functions, $handler_list, $class_module_name = '', $sub_type = '') {
804
-  if(isset($handler_list) && is_array($handler_list) && !empty($handler_list)) {
805
-    foreach($handler_list as $function_name => $function_data) {
806
-      if(is_string($function_data)) {
804
+  if (isset($handler_list) && is_array($handler_list) && !empty($handler_list)) {
805
+    foreach ($handler_list as $function_name => $function_data) {
806
+      if (is_string($function_data)) {
807 807
         $override_with = &$function_data;
808
-      } elseif(isset($function_data['callable'])) {
808
+      } elseif (isset($function_data['callable'])) {
809 809
         $override_with = &$function_data['callable'];
810 810
       }
811 811
 
812 812
       $overwrite = $override_with[0] == '*';
813
-      if($overwrite) {
813
+      if ($overwrite) {
814 814
         $override_with = substr($override_with, 1);
815 815
       }
816 816
 
817
-      if(($point_position = strpos($override_with, '.')) === false && $class_module_name) {
817
+      if (($point_position = strpos($override_with, '.')) === false && $class_module_name) {
818 818
         $override_with = array($class_module_name, $override_with);
819
-      } elseif($point_position == 0) {
819
+      } elseif ($point_position == 0) {
820 820
         $override_with = substr($override_with, 1);
821
-      } elseif($point_position > 0) {
821
+      } elseif ($point_position > 0) {
822 822
         $override_with = array(substr($override_with, 0, $point_position), substr($override_with, $point_position + 1));
823 823
       }
824 824
 
825
-      if($overwrite) {
825
+      if ($overwrite) {
826 826
         $functions[$function_name] = array();
827
-      } elseif(!isset($functions[$function_name])) {
827
+      } elseif (!isset($functions[$function_name])) {
828 828
         $functions[$function_name] = array();
829 829
         $sn_function_name = 'sn_' . $function_name . ($sub_type ? '_' . $sub_type : '');
830 830
         $functions[$function_name][] = $sn_function_name;
@@ -840,15 +840,15 @@  discard block
 block discarded – undo
840 840
 function player_nick_render_to_html($result, $options = false) {
841 841
   // TODO - обрабатывать разные случаи: $user, $render_nick_array, $string
842 842
 
843
-  if(is_string($result) && strpos($result, ':{i:')) {
843
+  if (is_string($result) && strpos($result, ':{i:')) {
844 844
     $result = player_nick_uncompact($result);
845 845
   }
846 846
 
847
-  if(is_array($result)) {
848
-    if(isset($result['id'])) {
847
+  if (is_array($result)) {
848
+    if (isset($result['id'])) {
849 849
       $result = player_nick_render_current_to_array($result, $options);
850 850
     }
851
-    if(!isset($result[NICK_HTML])) {
851
+    if (!isset($result[NICK_HTML])) {
852 852
       $result = player_nick_render_array_to_html($result);
853 853
     }
854 854
     unset($result[NICK_HTML]);
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
   try {
872 872
     $result = unserialize($nick_string);
873 873
     // ksort($result); // Всегда ksort-ый в player_nick_compact()
874
-  } catch(exception $e) {
874
+  } catch (exception $e) {
875 875
     $result = strpos($nick_string, ':{i:') ? null : $nick_string; // fallback if it is already string - for old chat strings, for example
876 876
   }
877 877
 
@@ -884,20 +884,20 @@  discard block
 block discarded – undo
884 884
   global $config, $user;
885 885
 
886 886
   // ALL STRING ARE UNSAFE!!!
887
-  if(isset($nick_array[NICK_BIRTHSDAY])) {
887
+  if (isset($nick_array[NICK_BIRTHSDAY])) {
888 888
     $result[NICK_BIRTHSDAY] = '<img src="design/images/birthday.png" />';
889 889
   }
890 890
 
891
-  if(isset($nick_array[NICK_VACATION])) {
891
+  if (isset($nick_array[NICK_VACATION])) {
892 892
     $result[NICK_VACATION] = '<img src="design/images/icon_vacation.png" />';
893 893
   }
894 894
 
895
-  if(isset($nick_array[NICK_GENDER])) {
895
+  if (isset($nick_array[NICK_GENDER])) {
896 896
     $result[NICK_GENDER] = '<img src="' . ($user['dpath'] ? $user['dpath'] : DEFAULT_SKINPATH) . 'images/gender_' . $nick_array[NICK_GENDER] . '.png" />';
897 897
   }
898 898
 
899
-  if(isset($nick_array[NICK_AUTH_LEVEL]) || isset($nick_array[NICK_PREMIUM])) {
900
-    switch($nick_array[NICK_AUTH_LEVEL]) {
899
+  if (isset($nick_array[NICK_AUTH_LEVEL]) || isset($nick_array[NICK_PREMIUM])) {
900
+    switch ($nick_array[NICK_AUTH_LEVEL]) {
901 901
       case 4:
902 902
         $highlight = $config->chat_highlight_developer;
903 903
       break;
@@ -918,20 +918,20 @@  discard block
 block discarded – undo
918 918
         $highlight = isset($nick_array[NICK_PREMIUM]) ? $config->chat_highlight_premium : '';
919 919
     }
920 920
 
921
-    if($highlight) {
921
+    if ($highlight) {
922 922
       list($result[NICK_HIGHLIGHT], $result[NICK_HIGHLIGHT_END]) = explode('$1', $highlight);
923 923
     }
924 924
     // $result = preg_replace("#(.+)#", $highlight, $result);
925 925
   }
926 926
 
927
-  if(isset($nick_array[NICK_CLASS])) {
927
+  if (isset($nick_array[NICK_CLASS])) {
928 928
     $result[NICK_CLASS] = '<span ' . $nick_array[NICK_CLASS] . '>';
929 929
     $result[NICK_CLASS_END] = '</span>';
930 930
   }
931 931
 
932 932
   $result[NICK_NICK] = sys_safe_output($nick_array[NICK_NICK]);
933 933
 
934
-  if(isset($nick_array[NICK_ALLY])) {
934
+  if (isset($nick_array[NICK_ALLY])) {
935 935
     $result[NICK_ALLY] = '[' . sys_safe_output($nick_array[NICK_ALLY]) . ']';
936 936
   }
937 937
 
@@ -955,32 +955,32 @@  discard block
 block discarded – undo
955 955
   */
956 956
 
957 957
 
958
-  if($render_user['user_birthday'] && ($options === true || isset($options['icons']) || isset($options['birthday'])) && (date('Y', SN_TIME_NOW) . date('-m-d', strtotime($render_user['user_birthday'])) == date('Y-m-d', SN_TIME_NOW))) {
958
+  if ($render_user['user_birthday'] && ($options === true || isset($options['icons']) || isset($options['birthday'])) && (date('Y', SN_TIME_NOW) . date('-m-d', strtotime($render_user['user_birthday'])) == date('Y-m-d', SN_TIME_NOW))) {
959 959
     $result[NICK_BIRTHSDAY] = '';
960 960
   }
961 961
 
962
-  if($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['gender']) && $options['gender'])) {
962
+  if ($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['gender']) && $options['gender'])) {
963 963
     $result[NICK_GENDER] = $render_user['gender'] == GENDER_UNKNOWN ? 'unknown' : ($render_user['gender'] == GENDER_FEMALE ? 'female' : 'male');
964 964
   }
965 965
 
966
-  if(($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['vacancy']) && $options['vacancy'])) && $render_user['vacation']) {
966
+  if (($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['vacancy']) && $options['vacancy'])) && $render_user['vacation']) {
967 967
     $result[NICK_VACATION] = $render_user['vacation'];
968 968
   }
969 969
 
970
-  if($options === true || (isset($options['color']) && $options['color'])) {
971
-    if($user_auth_level = $render_user['authlevel']) {
970
+  if ($options === true || (isset($options['color']) && $options['color'])) {
971
+    if ($user_auth_level = $render_user['authlevel']) {
972 972
       $result[NICK_AUTH_LEVEL] = $user_auth_level;
973 973
     }
974
-    if($user_premium = mrc_get_level($render_user, null, UNIT_PREMIUM)) {
974
+    if ($user_premium = mrc_get_level($render_user, null, UNIT_PREMIUM)) {
975 975
       $result[NICK_PREMIUM] = $user_premium;
976 976
     }
977 977
   }
978 978
 
979
-  if((isset($options['class']) && $options['class'])) {
979
+  if ((isset($options['class']) && $options['class'])) {
980 980
     $result[NICK_CLASS] = (isset($result_options[NICK_CLASS]) ? ' ' . $result_options[NICK_CLASS] : '') . $options['class'];
981 981
   }
982 982
 
983
-  if($render_user['ally_tag'] && ($options === true || (isset($options['ally']) && $options['ally']))) {
983
+  if ($render_user['ally_tag'] && ($options === true || (isset($options['ally']) && $options['ally']))) {
984 984
     $result[NICK_ALLY] = $render_user['ally_tag'];
985 985
   }
986 986
 
@@ -998,25 +998,25 @@  discard block
 block discarded – undo
998 998
 
999 999
   $user_skip_list = array();
1000 1000
 
1001
-  if($config->stats_hide_admins) {
1001
+  if ($config->stats_hide_admins) {
1002 1002
     $user_skip_list[] = '`authlevel` > 0';
1003 1003
   }
1004 1004
 
1005
-  if($config->stats_hide_player_list) {
1005
+  if ($config->stats_hide_player_list) {
1006 1006
     $temp = explode(',', $config->stats_hide_player_list);
1007
-    foreach($temp as $user_id) {
1007
+    foreach ($temp as $user_id) {
1008 1008
       $user_id = floatval($user_id);
1009
-      if($user_id) {
1009
+      if ($user_id) {
1010 1010
         $user_skip_list[] = '`id` = ' . $user_id;
1011 1011
       }
1012 1012
     }
1013 1013
   }
1014 1014
 
1015
-  if(!empty($user_skip_list)) {
1015
+  if (!empty($user_skip_list)) {
1016 1016
     $user_skip_list = implode(' OR ', $user_skip_list);
1017 1017
     $user_skip_query = db_user_list($user_skip_list);
1018
-    if(!empty($user_skip_query)) {
1019
-      foreach($user_skip_query as $user_skip_row) {
1018
+    if (!empty($user_skip_query)) {
1019
+      foreach ($user_skip_query as $user_skip_row) {
1020 1020
         $result[$user_skip_row['id']] = $user_skip_row['id'];
1021 1021
       }
1022 1022
     }
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
 
1048 1048
 function sn_sn_get_groups($groups, &$result) {
1049 1049
   $result = is_array($result) ? $result : array();
1050
-  foreach($groups = is_array($groups) ? $groups : array($groups) as $group_name) {
1050
+  foreach ($groups = is_array($groups) ? $groups : array($groups) as $group_name) {
1051 1051
     $result += is_array($a_group = get_unit_param(UNIT_GROUP, $group_name)) ? $a_group : array();
1052 1052
   }
1053 1053
 
@@ -1075,8 +1075,8 @@  discard block
 block discarded – undo
1075 1075
   $sn_data_unit = get_unit_param($unit_id);
1076 1076
 
1077 1077
   $result = is_array($result) ? $result : array();
1078
-  if($sn_data_unit[$field] && !($sn_data_unit[P_UNIT_TYPE] == UNIT_MERCENARIES && $config->empire_mercenary_temporary)) {
1079
-    foreach($sn_data_unit[$field] as $require_id => $require_level) {
1078
+  if ($sn_data_unit[$field] && !($sn_data_unit[P_UNIT_TYPE] == UNIT_MERCENARIES && $config->empire_mercenary_temporary)) {
1079
+    foreach ($sn_data_unit[$field] as $require_id => $require_level) {
1080 1080
       $level_got = mrc_get_level($user, $planetrow, $require_id);
1081 1081
       $level_basic = mrc_get_level($user, $planetrow, $require_id, false, true);
1082 1082
       $result[] = array(
@@ -1100,16 +1100,16 @@  discard block
 block discarded – undo
1100 1100
 
1101 1101
   $ranks = array();
1102 1102
 
1103
-  if($ally['ranklist']) {
1103
+  if ($ally['ranklist']) {
1104 1104
     $str_ranks = explode(';', $ally['ranklist']);
1105
-    foreach($str_ranks as $str_rank) {
1106
-      if(!$str_rank) {
1105
+    foreach ($str_ranks as $str_rank) {
1106
+      if (!$str_rank) {
1107 1107
         continue;
1108 1108
       }
1109 1109
 
1110 1110
       $tmp = explode(',', $str_rank);
1111 1111
       $rank_id = count($ranks);
1112
-      foreach($ally_rights as $key => $value) {
1112
+      foreach ($ally_rights as $key => $value) {
1113 1113
         $ranks[$rank_id][$value] = $tmp[$key];
1114 1114
       }
1115 1115
     }
@@ -1125,8 +1125,8 @@  discard block
 block discarded – undo
1125 1125
 }
1126 1126
 
1127 1127
 function array_merge_recursive_numeric($array1, $array2) {
1128
-  if(!empty($array2) && is_array($array2)) {
1129
-    foreach($array2 as $key => $value) {
1128
+  if (!empty($array2) && is_array($array2)) {
1129
+    foreach ($array2 as $key => $value) {
1130 1130
 //    if(!isset($array1[$key]) || !is_array($array1[$key])) {
1131 1131
 //      $array1[$key] = $value;
1132 1132
 //    } else {
@@ -1141,7 +1141,7 @@  discard block
 block discarded – undo
1141 1141
 
1142 1142
 function sn_sys_array_cumulative_sum(&$array) {
1143 1143
   $accum = 0;
1144
-  foreach($array as &$value) {
1144
+  foreach ($array as &$value) {
1145 1145
     $accum += $value;
1146 1146
     $value = $accum;
1147 1147
   }
@@ -1151,7 +1151,7 @@  discard block
 block discarded – undo
1151 1151
   $sn_data_density = sn_get_groups('planet_density');
1152 1152
   $density_price_chart = array();
1153 1153
 
1154
-  foreach($sn_data_density as $density_id => $density_data) {
1154
+  foreach ($sn_data_density as $density_id => $density_data) {
1155 1155
     // Отсекаем записи с RARITY = 0 - служебные записи и супер-ядра
1156 1156
     $density_data[UNIT_PLANET_DENSITY_RARITY] ? $density_price_chart[$density_id] = $density_data[UNIT_PLANET_DENSITY_RARITY] : false;
1157 1157
   }
@@ -1159,7 +1159,7 @@  discard block
 block discarded – undo
1159 1159
 
1160 1160
   $total_rarity = array_sum($density_price_chart);
1161 1161
 
1162
-  foreach($density_price_chart as &$density_data) {
1162
+  foreach ($density_price_chart as &$density_data) {
1163 1163
     $density_data = ceil($total_rarity / $density_data * $planet_row['field_max'] * PLANET_DENSITY_TO_DARK_MATTER_RATE);
1164 1164
   }
1165 1165
 
@@ -1167,16 +1167,16 @@  discard block
 block discarded – undo
1167 1167
 }
1168 1168
 
1169 1169
 function sn_sys_planet_core_transmute(&$user, &$planetrow) {
1170
-  if(!sys_get_param_str('transmute')) {
1170
+  if (!sys_get_param_str('transmute')) {
1171 1171
     return array();
1172 1172
   }
1173 1173
 
1174 1174
   try {
1175
-    if($planetrow['planet_type'] != PT_PLANET) {
1175
+    if ($planetrow['planet_type'] != PT_PLANET) {
1176 1176
       throw new exception(classLocale::$lang['ov_core_err_not_a_planet'], ERR_ERROR);
1177 1177
     }
1178 1178
 
1179
-    if($planetrow['density_index'] == ($new_density_index = sys_get_param_id('density_type'))) {
1179
+    if ($planetrow['density_index'] == ($new_density_index = sys_get_param_id('density_type'))) {
1180 1180
       throw new exception(classLocale::$lang['ov_core_err_same_density'], ERR_WARNING);
1181 1181
     }
1182 1182
 
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
     $planet_density_index = $planetrow['density_index'];
1191 1191
 
1192 1192
     $density_price_chart = planet_density_price_chart($planetrow);
1193
-    if(!isset($density_price_chart[$new_density_index])) {
1193
+    if (!isset($density_price_chart[$new_density_index])) {
1194 1194
       // Hack attempt
1195 1195
       throw new exception(classLocale::$lang['ov_core_err_denisty_type_wrong'], ERR_ERROR);
1196 1196
     }
@@ -1199,13 +1199,13 @@  discard block
 block discarded – undo
1199 1199
     // $transmute_cost = get_unit_param(UNIT_PLANET_DENSITY, 'cost');
1200 1200
     // $transmute_cost = $transmute_cost[RES_DARK_MATTER] * $density_price_chart[$new_density_index];
1201 1201
     $transmute_cost = $density_price_chart[$new_density_index];
1202
-    if($user_dark_matter < $transmute_cost) {
1202
+    if ($user_dark_matter < $transmute_cost) {
1203 1203
       throw new exception(classLocale::$lang['ov_core_err_no_dark_matter'], ERR_ERROR);
1204 1204
     }
1205 1205
 
1206 1206
     $sn_data_planet_density = sn_get_groups('planet_density');
1207
-    foreach($sn_data_planet_density as $key => $value) {
1208
-      if($key == $new_density_index) {
1207
+    foreach ($sn_data_planet_density as $key => $value) {
1208
+      if ($key == $new_density_index) {
1209 1209
         break;
1210 1210
       }
1211 1211
       $prev_density_index = $key;
@@ -1236,7 +1236,7 @@  discard block
 block discarded – undo
1236 1236
       'STATUS'  => ERR_NONE,
1237 1237
       'MESSAGE' => sprintf(classLocale::$lang['ov_core_err_none'], classLocale::$lang['uni_planet_density_types'][$planet_density_index], classLocale::$lang['uni_planet_density_types'][$new_density_index], $new_density),
1238 1238
     );
1239
-  } catch(exception $e) {
1239
+  } catch (exception $e) {
1240 1240
     sn_db_transaction_rollback();
1241 1241
     $result = array(
1242 1242
       'STATUS'  => $e->getCode(),
@@ -1249,8 +1249,8 @@  discard block
 block discarded – undo
1249 1249
 
1250 1250
 function sn_module_get_active_count($group = '*') {
1251 1251
   $active_modules = 0;
1252
-  if(isset(sn_module::$sn_module_list[$group]) && is_array(sn_module::$sn_module_list[$group])) {
1253
-    foreach(sn_module::$sn_module_list[$group] as $payment_module) {
1252
+  if (isset(sn_module::$sn_module_list[$group]) && is_array(sn_module::$sn_module_list[$group])) {
1253
+    foreach (sn_module::$sn_module_list[$group] as $payment_module) {
1254 1254
       $active_modules += $payment_module->manifest['active'];
1255 1255
     }
1256 1256
   }
@@ -1261,7 +1261,7 @@  discard block
 block discarded – undo
1261 1261
 function get_resource_exchange() {
1262 1262
   static $rates;
1263 1263
 
1264
-  if(!$rates) {
1264
+  if (!$rates) {
1265 1265
     global $config;
1266 1266
 
1267 1267
     $rates = array(
@@ -1271,7 +1271,7 @@  discard block
 block discarded – undo
1271 1271
       RES_DARK_MATTER => 'rpg_exchange_darkMatter',
1272 1272
     );
1273 1273
 
1274
-    foreach($rates as &$rate) {
1274
+    foreach ($rates as &$rate) {
1275 1275
       $rate = $config->$rate;
1276 1276
     }
1277 1277
   }
@@ -1282,12 +1282,12 @@  discard block
 block discarded – undo
1282 1282
 function get_unit_cost_in(&$cost, $in_resource = RES_METAL) {
1283 1283
   static $rates;
1284 1284
 
1285
-  if(!$rates) {
1285
+  if (!$rates) {
1286 1286
     $rates = get_resource_exchange();
1287 1287
   }
1288 1288
 
1289 1289
   $metal_cost = 0;
1290
-  foreach($cost as $resource_id => $resource_value) {
1290
+  foreach ($cost as $resource_id => $resource_value) {
1291 1291
     $metal_cost += $rates[$resource_id] * $resource_value;
1292 1292
   }
1293 1293
 
@@ -1297,8 +1297,8 @@  discard block
 block discarded – undo
1297 1297
 function get_player_max_expeditons(&$user, $astrotech = -1) { return sn_function_call(__FUNCTION__, array(&$user, $astrotech, &$result)); }
1298 1298
 
1299 1299
 function sn_get_player_max_expeditons(&$user, $astrotech = -1, &$result = 0) {
1300
-  if($astrotech == -1) {
1301
-    if(!isset($user[UNIT_PLAYER_EXPEDITIONS_MAX])) {
1300
+  if ($astrotech == -1) {
1301
+    if (!isset($user[UNIT_PLAYER_EXPEDITIONS_MAX])) {
1302 1302
       $astrotech = mrc_get_level($user, null, TECH_ASTROTECH);
1303 1303
       $user[UNIT_PLAYER_EXPEDITIONS_MAX] = $astrotech >= 1 ? floor(sqrt($astrotech - 1)) : 0;
1304 1304
     }
@@ -1316,8 +1316,8 @@  discard block
 block discarded – undo
1316 1316
 function get_player_max_colonies(&$user, $astrotech = -1) {
1317 1317
   global $config;
1318 1318
 
1319
-  if($astrotech == -1) {
1320
-    if(!isset($user[UNIT_PLAYER_COLONIES_MAX])) {
1319
+  if ($astrotech == -1) {
1320
+    if (!isset($user[UNIT_PLAYER_COLONIES_MAX])) {
1321 1321
 
1322 1322
       $expeditions = get_player_max_expeditons($user);
1323 1323
       $astrotech = mrc_get_level($user, null, TECH_ASTROTECH);
@@ -1362,10 +1362,10 @@  discard block
 block discarded – undo
1362 1362
 
1363 1363
   // pdump($powerup_unit, '$powerup_unit');
1364 1364
   $level_current = $term_original = $time_left = 0;
1365
-  if($is_upgrade) {
1365
+  if ($is_upgrade) {
1366 1366
     $time_finish = strtotime($powerup_unit['unit_time_finish']);
1367 1367
     $time_left = max(0, $time_finish - SN_TIME_NOW);
1368
-    if($time_left > 0) {
1368
+    if ($time_left > 0) {
1369 1369
       $term_original = $time_finish - strtotime($powerup_unit['unit_time_start']);
1370 1370
       $level_current = $powerup_unit['unit_level'];
1371 1371
     }
@@ -1373,22 +1373,22 @@  discard block
 block discarded – undo
1373 1373
 
1374 1374
   $level_max = $level_max > $powerup_data[P_MAX_STACK] ? $level_max : $powerup_data[P_MAX_STACK];
1375 1375
   $original_cost = 0;
1376
-  for($i = 1; $i <= $level_max; $i++) {
1376
+  for ($i = 1; $i <= $level_max; $i++) {
1377 1377
     $base_cost = eco_get_total_cost($powerup_id, $i);
1378 1378
     $base_cost = $base_cost[BUILD_CREATE][RES_DARK_MATTER];
1379
-    foreach($sn_powerup_buy_discounts as $period => $discount) {
1379
+    foreach ($sn_powerup_buy_discounts as $period => $discount) {
1380 1380
       $upgrade_price = floor($base_cost * $discount * $period / PERIOD_MONTH);
1381 1381
       $result[$i][$period] = $upgrade_price;
1382 1382
       $original_cost = $is_upgrade && $i == $level_current && $period <= $term_original ? $upgrade_price : $original_cost;
1383 1383
     }
1384 1384
   }
1385 1385
 
1386
-  if($is_upgrade && $time_left) {
1386
+  if ($is_upgrade && $time_left) {
1387 1387
     $term_original = round($term_original / PERIOD_DAY);
1388 1388
     $time_left = min(floor($time_left / PERIOD_DAY), $term_original);
1389 1389
     $cost_left = $term_original > 0 ? ceil($time_left / $term_original * $original_cost) : 0;
1390 1390
 
1391
-    array_walk_recursive($result, function (&$value) use ($cost_left) {
1391
+    array_walk_recursive($result, function(&$value) use ($cost_left) {
1392 1392
       $value -= $cost_left;
1393 1393
     });
1394 1394
   }
@@ -1446,7 +1446,7 @@  discard block
 block discarded – undo
1446 1446
 
1447 1447
 function print_rr($var, $capture = false) {
1448 1448
   $print = '<pre>' . htmlspecialchars(print_r($var, true)) . '</pre>';
1449
-  if($capture) {
1449
+  if ($capture) {
1450 1450
     return $print;
1451 1451
   } else {
1452 1452
     print($print);
Please login to merge, or discard this patch.
includes/functions/rpg_points.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -29,28 +29,28 @@  discard block
 block discarded – undo
29 29
 function rpg_points_change($user_id, $change_type, $dark_matter, $comment = '', $already_changed = false) {
30 30
   global $debug, $config, $dm_change_legit, $user;
31 31
 
32
-  if(!$user_id) {
32
+  if (!$user_id) {
33 33
     return false;
34 34
   }
35 35
 
36 36
   $dm_change_legit = true;
37 37
   $sn_data_dark_matter_db_name = pname_resource_name(RES_DARK_MATTER);
38 38
 
39
-  if($already_changed) {
39
+  if ($already_changed) {
40 40
     $rows_affected = 1;
41 41
   } else {
42 42
     $changeset = array();
43 43
     $a_user = db_user_by_id($user_id, true);
44
-    if($dark_matter < 0) {
44
+    if ($dark_matter < 0) {
45 45
       $dark_matter_exists = mrc_get_level($a_user, null, RES_DARK_MATTER, false, true);
46 46
       $dark_matter_exists < 0 ? $dark_matter_exists = 0 : false;
47 47
       $metamatter_to_reduce = -$dark_matter - $dark_matter_exists;
48
-      if($metamatter_to_reduce > 0) {
48
+      if ($metamatter_to_reduce > 0) {
49 49
         $metamatter_exists = mrc_get_level($a_user, null, RES_METAMATTER);
50
-        if($metamatter_exists < $metamatter_to_reduce) {
50
+        if ($metamatter_exists < $metamatter_to_reduce) {
51 51
           $debug->error('Ошибка снятия ТМ - ММ+ТМ меньше, чем сумма для снятия!', 'Ошибка снятия ТМ', LOG_ERR_INT_NOT_ENOUGH_DARK_MATTER);
52 52
         }
53
-        if(is_array($comment)) {
53
+        if (is_array($comment)) {
54 54
           $comment = call_user_func_array('sprintf', $comment);
55 55
         }
56 56
 //        mm_points_change($user_id, $change_type, -$metamatter_to_reduce, 'ММ в ТМ: ' . (-$dark_matter) . ' ТМ = ' . $dark_matter_exists . ' ТМ + ' . $metamatter_to_reduce . ' ММ. ' . $comment);
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
     $rows_affected = classSupernova::$db->db_affected_rows();
66 66
   }
67 67
 
68
-  if($rows_affected || !$dark_matter) {
68
+  if ($rows_affected || !$dark_matter) {
69 69
     $page_url = db_escape($_SERVER['SCRIPT_NAME']);
70
-    if(is_array($comment)) {
70
+    if (is_array($comment)) {
71 71
       $comment = call_user_func_array('sprintf', $comment);
72 72
     }
73 73
     $comment = db_escape($comment);
@@ -75,18 +75,18 @@  discard block
 block discarded – undo
75 75
     $row['username'] = db_escape($row['username']);
76 76
     db_log_dark_matter_insert($user_id, $change_type, $dark_matter, $comment, $row, $page_url);
77 77
 
78
-    if($user['id'] == $user_id) {
78
+    if ($user['id'] == $user_id) {
79 79
       $user['dark_matter'] += $dark_matter;
80 80
     }
81 81
 
82
-    if($dark_matter > 0) {
82
+    if ($dark_matter > 0) {
83 83
       $old_referral = db_referral_get_by_id($user_id);
84
-      if($old_referral['id']) {
84
+      if ($old_referral['id']) {
85 85
         db_referral_update_dm($user_id, $dark_matter);
86 86
         $new_referral = db_referral_get_by_id($user_id);
87 87
 
88 88
         $partner_bonus = floor($new_referral['dark_matter'] / $config->rpg_bonus_divisor) - ($old_referral['dark_matter'] >= $config->rpg_bonus_minimum ? floor($old_referral['dark_matter'] / $config->rpg_bonus_divisor) : 0);
89
-        if($partner_bonus > 0 && $new_referral['dark_matter'] >= $config->rpg_bonus_minimum) {
89
+        if ($partner_bonus > 0 && $new_referral['dark_matter'] >= $config->rpg_bonus_minimum) {
90 90
           rpg_points_change($new_referral['id_partner'], RPG_REFERRAL, $partner_bonus, "Incoming From Referral ID {$user_id}");
91 91
         }
92 92
       }
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 function rpg_level_up(&$user, $type, $xp_to_add = 0) {
104 104
   $q = 1.03;
105 105
 
106
-  switch($type) {
106
+  switch ($type) {
107 107
     case RPG_STRUCTURE:
108 108
       $field_level = 'lvl_minier';
109 109
       $field_xp = 'xpminier';
@@ -140,17 +140,17 @@  discard block
 block discarded – undo
140 140
 
141 141
   $xp = &$user[$field_xp];
142 142
 
143
-  if($xp_to_add) {
143
+  if ($xp_to_add) {
144 144
     $xp += $xp_to_add;
145 145
     db_user_set_by_id($user['id'], "`{$field_xp}` = `{$field_xp}` + '{$xp_to_add}'");
146 146
   }
147 147
 
148 148
   $level = $user[$field_level];
149
-  while($xp > rpg_xp_for_level($level + 1, $b1, $q)) {
149
+  while ($xp > rpg_xp_for_level($level + 1, $b1, $q)) {
150 150
     $level++;
151 151
   }
152 152
   $level -= $user[$field_level];
153
-  if($level > 0) {
153
+  if ($level > 0) {
154 154
     db_user_set_by_id($user['id'], "`{$field_level}` = `{$field_level}` + '{$level}'");
155 155
     rpg_points_change($user['id'], $type, $level * 1000, $comment);
156 156
     $user[$field_level] += $level;
Please login to merge, or discard this patch.
includes/functions/uni_functions.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
7 7
 
8 8
   $possible_cores = array();
9 9
   $probability = 0;
10
-  foreach($density_list as $possible_core_id => $core_data) {
11
-    if(!$core_data[UNIT_PLANET_DENSITY_RARITY]) {
10
+  foreach ($density_list as $possible_core_id => $core_data) {
11
+    if (!$core_data[UNIT_PLANET_DENSITY_RARITY]) {
12 12
       continue;
13 13
     }
14 14
 
15
-    if(
15
+    if (
16 16
       // Core type exists
17 17
       in_array($possible_core_id, $position_data['core_types'])
18 18
       // Limit core type with planet sector count
@@ -33,8 +33,8 @@  discard block
 block discarded – undo
33 33
 
34 34
   $random = mt_rand(1, $probability);
35 35
   $selected_core = null;
36
-  foreach($possible_cores as $core_type => $core_info) {
37
-    if($random <= $core_info[UNIT_PLANET_DENSITY_RARITY]) {
36
+  foreach ($possible_cores as $core_type => $core_info) {
37
+    if ($random <= $core_info[UNIT_PLANET_DENSITY_RARITY]) {
38 38
       $selected_core = $core_info;
39 39
       break;
40 40
     }
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 
60 60
   $Position = intval($Position);
61 61
 
62
-  if(!isset($options['skip_check']) && db_planet_by_gspt($Galaxy, $System, $Position, PT_PLANET, true, '`id`')) {
62
+  if (!isset($options['skip_check']) && db_planet_by_gspt($Galaxy, $System, $Position, PT_PLANET, true, '`id`')) {
63 63
     return false;
64 64
   }
65 65
 
@@ -68,11 +68,11 @@  discard block
 block discarded – undo
68 68
 
69 69
   $planet_generator = sn_get_groups('planet_generator');
70 70
 
71
-  if($HomeWorld) {
71
+  if ($HomeWorld) {
72 72
     $position_data = $planet_generator[0];
73 73
   } else {
74 74
     $position_data = $planet_generator[$Position >= UNIVERSE_RANDOM_PLANET_START || $Position < 1 ? UNIVERSE_RANDOM_PLANET_START : $Position];
75
-    if($Position >= UNIVERSE_RANDOM_PLANET_START) {
75
+    if ($Position >= UNIVERSE_RANDOM_PLANET_START) {
76 76
       // Корректируем температуру для планеты-странника
77 77
       $position_data['t_max_max'] -= UNIVERSE_RANDOM_PLANET_TEMPERATURE_DECREASE * ($Position - UNIVERSE_RANDOM_PLANET_START);
78 78
     }
@@ -172,15 +172,15 @@  discard block
 block discarded – undo
172 172
   $moon_name = '';
173 173
   $moon_row = array();
174 174
   $moon = db_planet_by_gspt($pos_galaxy, $pos_system, $pos_planet, PT_MOON, false, 'id');
175
-  if(!$moon['id']) {
175
+  if (!$moon['id']) {
176 176
     $moon_planet = db_planet_by_gspt($pos_galaxy, $pos_system, $pos_planet, PT_PLANET, true, '`id`, `temp_min`, `temp_max`, `name`, `debris_metal`, `debris_crystal`');
177 177
 
178
-    if($moon_planet['id']) {
178
+    if ($moon_planet['id']) {
179 179
       $base_storage_size = BASE_STORAGE_SIZE;
180 180
 
181
-      if(!$moon_chance) {
181
+      if (!$moon_chance) {
182 182
         $size = mt_rand(1100, 8999);
183
-      } elseif($moon_chance <= 100) {
183
+      } elseif ($moon_chance <= 100) {
184 184
         $size = mt_rand($moon_chance * 100 + 1000, $moon_chance * 200 + 2999);
185 185
       } else {
186 186
         $size = $moon_chance;
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 
197 197
       $field_max = ceil($size / 1000);
198 198
 
199
-      if(isset($options['image']) && $options['image']) {
199
+      if (isset($options['image']) && $options['image']) {
200 200
         $moon_image = $options['image'];
201 201
       } else {
202 202
         $moon_image = 'mond';
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
           `deuterium` = '0', `deuterium_perhour` = '0', `deuterium_max` = '{$base_storage_size}'"
212 212
       );
213 213
 
214
-      if($update_debris) {
214
+      if ($update_debris) {
215 215
         $debris_spent = $moon_chance * 1000000;
216 216
         $metal_spent = round(min($moon_planet['debris_metal'], $debris_spent * mt_rand(50, 75) / 100));
217 217
         $crystal_spent = min($moon_planet['debris_crystal'], $debris_spent - $metal_spent);
@@ -246,21 +246,21 @@  discard block
 block discarded – undo
246 246
   $planet_row['id'] = $user['current_planet'];
247 247
 
248 248
   // Пытаемся переключить на новую планету
249
-  if(($selected_planet = sys_get_param_id('cp')) && $selected_planet != $user['current_planet']) {
249
+  if (($selected_planet = sys_get_param_id('cp')) && $selected_planet != $user['current_planet']) {
250 250
     $planet_row = db_planet_by_id_and_owner($selected_planet, $user['id'], false, 'id');
251 251
   } else {
252 252
     $planet_row = db_planet_by_id($planet_row['id']);
253 253
   }
254 254
 
255 255
   // Если новая планета не найдена или было переключения - проверяем текущую выбранную планету
256
-  if(!isset($planet_row['id'])) // || $planet_row['id'] != $user['current_planet']
256
+  if (!isset($planet_row['id'])) // || $planet_row['id'] != $user['current_planet']
257 257
   {
258 258
     $planet_row = db_planet_by_id_and_owner($user['current_planet'], $user['id'], false, 'id');
259 259
     // Если текущей планеты не существует - выставляем Столицу
260
-    if(!isset($planet_row['id'])) {
260
+    if (!isset($planet_row['id'])) {
261 261
       $planet_row = db_planet_by_id_and_owner($user['id_planet'], $user['id'], false, 'id');
262 262
       // Если и столицы не существует - значит что-то очень не так с записью пользователя
263
-      if(!isset($planet_row['id'])) {
263
+      if (!isset($planet_row['id'])) {
264 264
         global $debug;
265 265
         $debug->error("User ID {$user['id']} has Capital planet {$user['id_planet']} but this planet does not exists", 'User record error', 502);
266 266
       }
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
   }
269 269
 
270 270
   // Если производилось переключение планеты - делаем запись в юзере
271
-  if($user['current_planet'] != $planet_row['id']) {
271
+  if ($user['current_planet'] != $planet_row['id']) {
272 272
     db_user_set_by_id($user['id'], "`current_planet` = '{$planet_row['id']}'");
273 273
     $user['current_planet'] = $planet_row['id'];
274 274
   }
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 }
287 287
 
288 288
 function uni_render_planet_full($from, $prefix = '', $html_safe = true, $include_id = false) {
289
-  if(!$from['id']) {
289
+  if (!$from['id']) {
290 290
     $result = classLocale::$lang['sys_planet_expedition'];
291 291
   } else {
292 292
     $from_planet_id = $include_id ? (
@@ -341,23 +341,23 @@  discard block
 block discarded – undo
341 341
   global $config;
342 342
 
343 343
   try {
344
-    if($planetrow['planet_teleport_next'] && $planetrow['planet_teleport_next'] > SN_TIME_NOW) {
344
+    if ($planetrow['planet_teleport_next'] && $planetrow['planet_teleport_next'] > SN_TIME_NOW) {
345 345
       throw new exception(classLocale::$lang['ov_teleport_err_cooldown'], ERR_ERROR);
346 346
     }
347 347
 
348
-    if(mrc_get_level($user, null, RES_DARK_MATTER) < $config->planet_teleport_cost) {
348
+    if (mrc_get_level($user, null, RES_DARK_MATTER) < $config->planet_teleport_cost) {
349 349
       throw new exception(classLocale::$lang['ov_teleport_err_no_dark_matter'], ERR_ERROR);
350 350
     }
351 351
 
352 352
     // TODO: Replace quick-check with using gathered flying fleet data
353
-    if(FleetList::fleet_count_incoming($planetrow['galaxy'], $planetrow['system'], $planetrow['planet'])) {
353
+    if (FleetList::fleet_count_incoming($planetrow['galaxy'], $planetrow['system'], $planetrow['planet'])) {
354 354
       throw new exception(classLocale::$lang['ov_teleport_err_fleet'], ERR_ERROR);
355 355
     }
356 356
 
357
-    if(is_array($new_coordinates)) {
357
+    if (is_array($new_coordinates)) {
358 358
       $new_coordinates['planet_type'] = PT_PLANET;
359 359
       $incoming = db_planet_by_vector($new_coordinates, '', true, 'id');
360
-      if($incoming['id']) {
360
+      if ($incoming['id']) {
361 361
         throw new exception(classLocale::$lang['ov_teleport_err_destination_busy'], ERR_ERROR);
362 362
       }
363 363
     }
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
       'result'  => ERR_NONE,
367 367
       'message' => '',
368 368
     );
369
-  } catch(exception $e) {
369
+  } catch (exception $e) {
370 370
     $response = array(
371 371
       'result'  => $e->getCode(),
372 372
       'message' => $e->getMessage(),
Please login to merge, or discard this patch.