Completed
Push — work-fleets ( 5b06a4...37e31f )
by SuperNova.WS
04:49
created
includes/general.php 2 patches
Doc Comments   +29 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,6 +11,9 @@  discard block
 block discarded – undo
11 11
 require_once('general/math.php');
12 12
 require_once('general_pname.php');
13 13
 
14
+/**
15
+ * @param string $func_name
16
+ */
14 17
 function sn_function_call($func_name, $func_arg = array())
15 18
 {
16 19
   global $functions; // All data in $functions should be normalized to valid 'callable' state: '<function_name>'|array('<object_name>', '<method_name>')
@@ -58,6 +61,9 @@  discard block
 block discarded – undo
58 61
 
59 62
 // ----------------------------------------------------------------------------------------------------------------
60 63
 // Fonction de lecture / ecriture / exploitation de templates
64
+/**
65
+ * @param string $filename
66
+ */
61 67
 function sys_file_read($filename)
62 68
 {
63 69
   return @file_get_contents($filename);
@@ -106,7 +112,7 @@  discard block
 block discarded – undo
106 112
 /**
107 113
  * Получение курса обмены валюты в серверную валюту
108 114
  *
109
- * @param $currency_symbol
115
+ * @param string $currency_symbol
110 116
  *
111 117
  * @return float
112 118
  */
@@ -143,6 +149,7 @@  discard block
 block discarded – undo
143 149
    null  - standard result
144 150
    true  - return only style class for current params
145 151
    false - return array('text' => $ret, 'class' => $class), where $ret - unstyled
152
+ * @param boolean $style
146 153
  */
147 154
 
148 155
 function pretty_number($n, $floor = true, $color = false, $limit = false, $style = null)
@@ -262,6 +269,9 @@  discard block
 block discarded – undo
262 269
   return preg_replace($ListCensure, '*', $String);
263 270
 }
264 271
 
272
+/**
273
+ * @param string $email
274
+ */
265 275
 function is_email($email) {
266 276
   return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i", $email));
267 277
 }
@@ -298,6 +308,9 @@  discard block
 block discarded – undo
298 308
   return floatval(sys_get_param($param_name, $default));
299 309
 }
300 310
 
311
+/**
312
+ * @param string $param_name
313
+ */
301 314
 function sys_get_param_escaped($param_name, $default = '')
302 315
 {
303 316
   return db_escape(sys_get_param($param_name, $default));
@@ -542,6 +555,9 @@  discard block
 block discarded – undo
542 555
 }
543 556
 
544 557
 // Generates random string of $length symbols from $allowed_chars charset
558
+/**
559
+ * @param string $allowed_chars
560
+ */
545 561
 function sys_random_string($length = 16, $allowed_chars = SN_SYS_SEC_CHARS_ALLOWED) {
546 562
   $allowed_length = strlen($allowed_chars);
547 563
 
@@ -667,6 +683,9 @@  discard block
 block discarded – undo
667 683
   return implode(';', $fleet_string);
668 684
 }
669 685
 
686
+/**
687
+ * @param string $body
688
+ */
670 689
 function mymail($email_unsafe, $title, $body, $from = '', $html = false) {
671 690
   global $config, $lang;
672 691
 
@@ -954,6 +973,9 @@  discard block
 block discarded – undo
954 973
   return serialize($nick_array);
955 974
 }
956 975
 
976
+/**
977
+ * @param string $nick_string
978
+ */
957 979
 function player_nick_uncompact($nick_string) {
958 980
   try {
959 981
     $result = unserialize($nick_string);
@@ -1237,6 +1259,9 @@  discard block
 block discarded – undo
1237 1259
   return $ranks;
1238 1260
 }
1239 1261
 
1262
+/**
1263
+ * @param boolean $planet_id
1264
+ */
1240 1265
 function sys_player_new_adjust($user_id, $planet_id){return sn_function_call('sys_player_new_adjust', array($user_id, $planet_id, &$result));}
1241 1266
 function sn_sys_player_new_adjust($user_id, $planet_id, &$result) {
1242 1267
   return $result;
@@ -1589,6 +1614,9 @@  discard block
 block discarded – undo
1589 1614
   return version_compare(sn_version_compare_extra($ver1), sn_version_compare_extra($ver2));
1590 1615
 }
1591 1616
 
1617
+/**
1618
+ * @param string $name
1619
+ */
1592 1620
 function sn_setcookie($name, $value = null, $expire = null, $path = SN_ROOT_RELATIVE, $domain = null, $secure = null, $httponly = null) {
1593 1621
   $_COOKIE[$name] = $value;
1594 1622
   return setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
Please login to merge, or discard this 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
   }
@@ -438,19 +438,19 @@  discard block
 block discarded – undo
438 438
   $mercenary_level = 0;
439 439
   $unit_db_name = pname_resource_name($unit_id);
440 440
 
441
-  if(in_array($unit_id, sn_get_groups(array('plans', 'mercenaries', 'tech', 'artifacts')))) {
441
+  if (in_array($unit_id, sn_get_groups(array('plans', 'mercenaries', 'tech', 'artifacts')))) {
442 442
     $unit = classSupernova::db_get_unit_by_location($user['id'], LOC_USER, $user['id'], $unit_id);
443 443
     $mercenary_level = is_array($unit) && $unit['unit_level'] ? $unit['unit_level'] : 0;
444
-  } elseif(in_array($unit_id, sn_get_groups(array('structures', 'fleet', 'defense')))) {
444
+  } elseif (in_array($unit_id, sn_get_groups(array('structures', 'fleet', 'defense')))) {
445 445
     $unit = classSupernova::db_get_unit_by_location(is_array($user) ? $user['id'] : $planet['id_owner'], LOC_PLANET, $planet['id'], $unit_id);
446 446
     $mercenary_level = is_array($unit) && $unit['unit_level'] ? $unit['unit_level'] : 0;
447
-  } elseif(in_array($unit_id, sn_get_groups('governors'))) {
447
+  } elseif (in_array($unit_id, sn_get_groups('governors'))) {
448 448
     $mercenary_level = $unit_id == $planet['PLANET_GOVERNOR_ID'] ? $planet['PLANET_GOVERNOR_LEVEL'] : 0;
449
-  } elseif($unit_id == RES_DARK_MATTER) {
449
+  } elseif ($unit_id == RES_DARK_MATTER) {
450 450
     $mercenary_level = $user[$unit_db_name] + ($plain || $user['user_as_ally'] ? 0 : classSupernova::$auth->account->account_metamatter);
451
-  } elseif($unit_id == RES_METAMATTER) {
451
+  } elseif ($unit_id == RES_METAMATTER) {
452 452
     $mercenary_level = classSupernova::$auth->account->account_metamatter; //$user[$unit_db_name];
453
-  } elseif(in_array($unit_id, sn_get_groups(array('resources_loot'))) || $unit_id == UNIT_SECTOR) {
453
+  } elseif (in_array($unit_id, sn_get_groups(array('resources_loot'))) || $unit_id == UNIT_SECTOR) {
454 454
     $mercenary_level = !empty($planet) ? $planet[$unit_db_name] : $user[$unit_db_name];
455 455
   }
456 456
 
@@ -460,19 +460,19 @@  discard block
 block discarded – undo
460 460
 function mrc_modify_value(&$user, $planet = array(), $mercenaries, $value) { return sn_function_call(__FUNCTION__, array(&$user, $planet, $mercenaries, $value)); }
461 461
 
462 462
 function sn_mrc_modify_value(&$user, $planet = array(), $mercenaries, $value, $base_value = null) {
463
-  if(!is_array($mercenaries)) {
463
+  if (!is_array($mercenaries)) {
464 464
     $mercenaries = array($mercenaries);
465 465
   }
466 466
 
467 467
   $base_value = isset($base_value) ? $base_value : $value;
468 468
 
469
-  foreach($mercenaries as $mercenary_id) {
469
+  foreach ($mercenaries as $mercenary_id) {
470 470
     $mercenary_level = mrc_get_level($user, $planet, $mercenary_id);
471 471
 
472 472
     $mercenary = get_unit_param($mercenary_id);
473 473
     $mercenary_bonus = $mercenary['bonus'];
474 474
 
475
-    switch($mercenary['bonus_type']) {
475
+    switch ($mercenary['bonus_type']) {
476 476
       case BONUS_PERCENT_CUMULATIVE:
477 477
         $value *= 1 + $mercenary_level * $mercenary_bonus / 100;
478 478
       break;
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
   $allowed_length = strlen($allowed_chars);
504 504
 
505 505
   $random_string = '';
506
-  for($i = 0; $i < $length; $i++) {
506
+  for ($i = 0; $i < $length; $i++) {
507 507
     $random_string .= $allowed_chars[mt_rand(0, $allowed_length - 1)];
508 508
   }
509 509
 
@@ -523,12 +523,12 @@  discard block
 block discarded – undo
523 523
 
524 524
   $options = '';
525 525
   $option_list = array();
526
-  foreach($user_option_list as $option_group_id => $option_group) {
526
+  foreach ($user_option_list as $option_group_id => $option_group) {
527 527
     $option_list[$option_group_id] = array();
528
-    foreach($option_group as $option_name => $option_value) {
529
-      if(!isset($user[$option_name])) {
528
+    foreach ($option_group as $option_name => $option_value) {
529
+      if (!isset($user[$option_name])) {
530 530
         $user[$option_name] = $option_value;
531
-      } elseif($user[$option_name] == '') {
531
+      } elseif ($user[$option_name] == '') {
532 532
         $user[$option_name] = 0;
533 533
       }
534 534
       $options .= "{$option_name}^{$user[$option_name]}|";
@@ -548,16 +548,16 @@  discard block
 block discarded – undo
548 548
   $option_list = array();
549 549
   $option_string_list = explode('|', $user['options']);
550 550
 
551
-  foreach($option_string_list as $option_string) {
551
+  foreach ($option_string_list as $option_string) {
552 552
     list($option_name, $option_value) = explode('^', $option_string);
553 553
     $option_list[$option_name] = $option_value;
554 554
   }
555 555
 
556 556
   $final_list = array();
557
-  foreach($user_option_list as $option_group_id => $option_group) {
557
+  foreach ($user_option_list as $option_group_id => $option_group) {
558 558
     $final_list[$option_group_id] = array();
559
-    foreach($option_group as $option_name => $option_value) {
560
-      if(!isset($option_list[$option_name])) {
559
+    foreach ($option_group as $option_name => $option_value) {
560
+      if (!isset($option_list[$option_name])) {
561 561
         $option_list[$option_name] = $option_value;
562 562
       }
563 563
       $user[$option_name] = $final_list[$option_group_id][$option_name] = $option_list[$option_name];
@@ -571,12 +571,12 @@  discard block
 block discarded – undo
571 571
 
572 572
 function sys_unit_str2arr($fleet_string) {
573 573
   $fleet_array = array();
574
-  if(!empty($fleet_string)) {
574
+  if (!empty($fleet_string)) {
575 575
     $arrTemp = explode(';', $fleet_string);
576
-    foreach($arrTemp as $temp) {
577
-      if($temp) {
576
+    foreach ($arrTemp as $temp) {
577
+      if ($temp) {
578 578
         $temp = explode(',', $temp);
579
-        if(!empty($temp[0]) && !empty($temp[1])) {
579
+        if (!empty($temp[0]) && !empty($temp[1])) {
580 580
           $fleet_array[$temp[0]] += $temp[1];
581 581
         }
582 582
       }
@@ -588,13 +588,13 @@  discard block
 block discarded – undo
588 588
 
589 589
 function sys_unit_arr2str($unit_list) {
590 590
   $fleet_string = array();
591
-  if(isset($unit_list)) {
592
-    if(!is_array($unit_list)) {
591
+  if (isset($unit_list)) {
592
+    if (!is_array($unit_list)) {
593 593
       $unit_list = array($unit_list => 1);
594 594
     }
595 595
 
596
-    foreach($unit_list as $unit_id => $unit_count) {
597
-      if($unit_id && $unit_count) {
596
+    foreach ($unit_list as $unit_id => $unit_count) {
597
+      if ($unit_id && $unit_count) {
598 598
         $fleet_string[] = "{$unit_id},{$unit_count}";
599 599
       }
600 600
     }
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
   $body = str_replace("\r\n", "\n", $body);
622 622
   $body = str_replace("\n", "\r\n", $body);
623 623
 
624
-  if($html) {
624
+  if ($html) {
625 625
     $body = '<html><head><base href="' . SN_ROOT_VIRTUAL . '"></head><body>' . nl2br($body) . '</body></html>';
626 626
   }
627 627
 
@@ -665,21 +665,21 @@  discard block
 block discarded – undo
665 665
 }
666 666
 
667 667
 function sn_ali_fill_user_ally(&$user) {
668
-  if(!$user['ally_id']) {
668
+  if (!$user['ally_id']) {
669 669
     return;
670 670
   }
671 671
 
672
-  if(!isset($user['ally'])) {
672
+  if (!isset($user['ally'])) {
673 673
     $user['ally'] = db_ally_get_by_id($user['ally_id']);
674 674
   }
675 675
 
676
-  if(!isset($user['ally']['player'])) {
676
+  if (!isset($user['ally']['player'])) {
677 677
     $user['ally']['player'] = db_user_by_id($user['ally']['ally_user_id'], true, '*', false);
678 678
   }
679 679
 }
680 680
 
681 681
 function sn_get_url_contents($url) {
682
-  if(function_exists('curl_init')) {
682
+  if (function_exists('curl_init')) {
683 683
     $crl = curl_init();
684 684
     $timeout = 5;
685 685
     curl_setopt($crl, CURLOPT_URL, $url);
@@ -714,10 +714,10 @@  discard block
 block discarded – undo
714 714
 
715 715
 function get_ship_data($ship_id, $user) {
716 716
   $ship_data = array();
717
-  if(in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) {
718
-    foreach(get_unit_param($ship_id, 'engine') as $engine_info) {
717
+  if (in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) {
718
+    foreach (get_unit_param($ship_id, 'engine') as $engine_info) {
719 719
       $tech_level = intval(mrc_get_level($user, false, $engine_info['tech']));
720
-      if(empty($ship_data) || $tech_level >= $engine_info['min_level']) {
720
+      if (empty($ship_data) || $tech_level >= $engine_info['min_level']) {
721 721
         $ship_data = $engine_info;
722 722
         $ship_data['tech_level'] = $tech_level;
723 723
       }
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
   return $ship_data;
730 730
 }
731 731
 
732
-if(!function_exists('strptime')) {
732
+if (!function_exists('strptime')) {
733 733
   function strptime($date, $format) {
734 734
     $masks = array(
735 735
       '%d' => '(?P<d>[0-9]{2})',
@@ -742,12 +742,12 @@  discard block
 block discarded – undo
742 742
     );
743 743
 
744 744
     $rexep = "#" . strtr(preg_quote($format), $masks) . "#";
745
-    if(preg_match($rexep, $date, $out)) {
745
+    if (preg_match($rexep, $date, $out)) {
746 746
       $ret = array(
747
-        "tm_sec"  => (int)$out['S'],
748
-        "tm_min"  => (int)$out['M'],
749
-        "tm_hour" => (int)$out['H'],
750
-        "tm_mday" => (int)$out['d'],
747
+        "tm_sec"  => (int) $out['S'],
748
+        "tm_min"  => (int) $out['M'],
749
+        "tm_hour" => (int) $out['H'],
750
+        "tm_mday" => (int) $out['d'],
751 751
         "tm_mon"  => $out['m'] ? $out['m'] - 1 : 0,
752 752
         "tm_year" => $out['Y'] > 1900 ? $out['Y'] - 1900 : 0,
753 753
       );
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
 function sn_sys_sector_buy($redirect = 'overview.php') {
763 763
   global $user, $planetrow;
764 764
 
765
-  if(!sys_get_param_str('sector_buy') || $planetrow['planet_type'] != PT_PLANET) {
765
+  if (!sys_get_param_str('sector_buy') || $planetrow['planet_type'] != PT_PLANET) {
766 766
     return;
767 767
   }
768 768
 
@@ -775,9 +775,9 @@  discard block
 block discarded – undo
775 775
 //  $planetrow = $planetrow['planet'];
776 776
   $sector_cost = eco_get_build_data($user, $planetrow, UNIT_SECTOR, mrc_get_level($user, $planetrow, UNIT_SECTOR), true);
777 777
   $sector_cost = $sector_cost[BUILD_CREATE][RES_DARK_MATTER];
778
-  if($sector_cost <= mrc_get_level($user, null, RES_DARK_MATTER)) {
778
+  if ($sector_cost <= mrc_get_level($user, null, RES_DARK_MATTER)) {
779 779
     $planet_name_text = uni_render_planet($planetrow);
780
-    if(rpg_points_change($user['id'], RPG_SECTOR, -$sector_cost, sprintf(classLocale::$lang['sys_sector_purchase_log'],
780
+    if (rpg_points_change($user['id'], RPG_SECTOR, -$sector_cost, sprintf(classLocale::$lang['sys_sector_purchase_log'],
781 781
         $user['username'], $user['id'], $planet_name_text, classLocale::$lang['sys_planet_type'][$planetrow['planet_type']], $planetrow['id'], $sector_cost)
782 782
     )) {
783 783
       $sector_db_name = pname_resource_name(UNIT_SECTOR);
@@ -792,30 +792,30 @@  discard block
 block discarded – undo
792 792
 }
793 793
 
794 794
 function sn_sys_handler_add(&$functions, $handler_list, $class_module_name = '', $sub_type = '') {
795
-  if(isset($handler_list) && is_array($handler_list) && !empty($handler_list)) {
796
-    foreach($handler_list as $function_name => $function_data) {
797
-      if(is_string($function_data)) {
795
+  if (isset($handler_list) && is_array($handler_list) && !empty($handler_list)) {
796
+    foreach ($handler_list as $function_name => $function_data) {
797
+      if (is_string($function_data)) {
798 798
         $override_with = &$function_data;
799
-      } elseif(isset($function_data['callable'])) {
799
+      } elseif (isset($function_data['callable'])) {
800 800
         $override_with = &$function_data['callable'];
801 801
       }
802 802
 
803 803
       $overwrite = $override_with[0] == '*';
804
-      if($overwrite) {
804
+      if ($overwrite) {
805 805
         $override_with = substr($override_with, 1);
806 806
       }
807 807
 
808
-      if(($point_position = strpos($override_with, '.')) === false && $class_module_name) {
808
+      if (($point_position = strpos($override_with, '.')) === false && $class_module_name) {
809 809
         $override_with = array($class_module_name, $override_with);
810
-      } elseif($point_position == 0) {
810
+      } elseif ($point_position == 0) {
811 811
         $override_with = substr($override_with, 1);
812
-      } elseif($point_position > 0) {
812
+      } elseif ($point_position > 0) {
813 813
         $override_with = array(substr($override_with, 0, $point_position), substr($override_with, $point_position + 1));
814 814
       }
815 815
 
816
-      if($overwrite) {
816
+      if ($overwrite) {
817 817
         $functions[$function_name] = array();
818
-      } elseif(!isset($functions[$function_name])) {
818
+      } elseif (!isset($functions[$function_name])) {
819 819
         $functions[$function_name] = array();
820 820
         $sn_function_name = 'sn_' . $function_name . ($sub_type ? '_' . $sub_type : '');
821 821
         $functions[$function_name][] = $sn_function_name;
@@ -831,15 +831,15 @@  discard block
 block discarded – undo
831 831
 function player_nick_render_to_html($result, $options = false) {
832 832
   // TODO - обрабатывать разные случаи: $user, $render_nick_array, $string
833 833
 
834
-  if(is_string($result) && strpos($result, ':{i:')) {
834
+  if (is_string($result) && strpos($result, ':{i:')) {
835 835
     $result = player_nick_uncompact($result);
836 836
   }
837 837
 
838
-  if(is_array($result)) {
839
-    if(isset($result['id'])) {
838
+  if (is_array($result)) {
839
+    if (isset($result['id'])) {
840 840
       $result = player_nick_render_current_to_array($result, $options);
841 841
     }
842
-    if(!isset($result[NICK_HTML])) {
842
+    if (!isset($result[NICK_HTML])) {
843 843
       $result = player_nick_render_array_to_html($result);
844 844
     }
845 845
     unset($result[NICK_HTML]);
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
   try {
863 863
     $result = unserialize($nick_string);
864 864
     // ksort($result); // Всегда ksort-ый в player_nick_compact()
865
-  } catch(exception $e) {
865
+  } catch (exception $e) {
866 866
     $result = strpos($nick_string, ':{i:') ? null : $nick_string; // fallback if it is already string - for old chat strings, for example
867 867
   }
868 868
 
@@ -875,20 +875,20 @@  discard block
 block discarded – undo
875 875
   global $config, $user;
876 876
 
877 877
   // ALL STRING ARE UNSAFE!!!
878
-  if(isset($nick_array[NICK_BIRTHSDAY])) {
878
+  if (isset($nick_array[NICK_BIRTHSDAY])) {
879 879
     $result[NICK_BIRTHSDAY] = '<img src="design/images/birthday.png" />';
880 880
   }
881 881
 
882
-  if(isset($nick_array[NICK_VACATION])) {
882
+  if (isset($nick_array[NICK_VACATION])) {
883 883
     $result[NICK_VACATION] = '<img src="design/images/icon_vacation.png" />';
884 884
   }
885 885
 
886
-  if(isset($nick_array[NICK_GENDER])) {
886
+  if (isset($nick_array[NICK_GENDER])) {
887 887
     $result[NICK_GENDER] = '<img src="' . ($user['dpath'] ? $user['dpath'] : DEFAULT_SKINPATH) . 'images/gender_' . $nick_array[NICK_GENDER] . '.png" />';
888 888
   }
889 889
 
890
-  if(isset($nick_array[NICK_AUTH_LEVEL]) || isset($nick_array[NICK_PREMIUM])) {
891
-    switch($nick_array[NICK_AUTH_LEVEL]) {
890
+  if (isset($nick_array[NICK_AUTH_LEVEL]) || isset($nick_array[NICK_PREMIUM])) {
891
+    switch ($nick_array[NICK_AUTH_LEVEL]) {
892 892
       case 4:
893 893
         $highlight = $config->chat_highlight_developer;
894 894
       break;
@@ -909,20 +909,20 @@  discard block
 block discarded – undo
909 909
         $highlight = isset($nick_array[NICK_PREMIUM]) ? $config->chat_highlight_premium : '';
910 910
     }
911 911
 
912
-    if($highlight) {
912
+    if ($highlight) {
913 913
       list($result[NICK_HIGHLIGHT], $result[NICK_HIGHLIGHT_END]) = explode('$1', $highlight);
914 914
     }
915 915
     // $result = preg_replace("#(.+)#", $highlight, $result);
916 916
   }
917 917
 
918
-  if(isset($nick_array[NICK_CLASS])) {
918
+  if (isset($nick_array[NICK_CLASS])) {
919 919
     $result[NICK_CLASS] = '<span ' . $nick_array[NICK_CLASS] . '>';
920 920
     $result[NICK_CLASS_END] = '</span>';
921 921
   }
922 922
 
923 923
   $result[NICK_NICK] = sys_safe_output($nick_array[NICK_NICK]);
924 924
 
925
-  if(isset($nick_array[NICK_ALLY])) {
925
+  if (isset($nick_array[NICK_ALLY])) {
926 926
     $result[NICK_ALLY] = '[' . sys_safe_output($nick_array[NICK_ALLY]) . ']';
927 927
   }
928 928
 
@@ -946,32 +946,32 @@  discard block
 block discarded – undo
946 946
   */
947 947
 
948 948
 
949
-  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))) {
949
+  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))) {
950 950
     $result[NICK_BIRTHSDAY] = '';
951 951
   }
952 952
 
953
-  if($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['gender']) && $options['gender'])) {
953
+  if ($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['gender']) && $options['gender'])) {
954 954
     $result[NICK_GENDER] = $render_user['gender'] == GENDER_UNKNOWN ? 'unknown' : ($render_user['gender'] == GENDER_FEMALE ? 'female' : 'male');
955 955
   }
956 956
 
957
-  if(($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['vacancy']) && $options['vacancy'])) && $render_user['vacation']) {
957
+  if (($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['vacancy']) && $options['vacancy'])) && $render_user['vacation']) {
958 958
     $result[NICK_VACATION] = $render_user['vacation'];
959 959
   }
960 960
 
961
-  if($options === true || (isset($options['color']) && $options['color'])) {
962
-    if($user_auth_level = $render_user['authlevel']) {
961
+  if ($options === true || (isset($options['color']) && $options['color'])) {
962
+    if ($user_auth_level = $render_user['authlevel']) {
963 963
       $result[NICK_AUTH_LEVEL] = $user_auth_level;
964 964
     }
965
-    if($user_premium = mrc_get_level($render_user, false, UNIT_PREMIUM)) {
965
+    if ($user_premium = mrc_get_level($render_user, false, UNIT_PREMIUM)) {
966 966
       $result[NICK_PREMIUM] = $user_premium;
967 967
     }
968 968
   }
969 969
 
970
-  if((isset($options['class']) && $options['class'])) {
970
+  if ((isset($options['class']) && $options['class'])) {
971 971
     $result[NICK_CLASS] = (isset($result_options[NICK_CLASS]) ? ' ' . $result_options[NICK_CLASS] : '') . $options['class'];
972 972
   }
973 973
 
974
-  if($render_user['ally_tag'] && ($options === true || (isset($options['ally']) && $options['ally']))) {
974
+  if ($render_user['ally_tag'] && ($options === true || (isset($options['ally']) && $options['ally']))) {
975 975
     $result[NICK_ALLY] = $render_user['ally_tag'];
976 976
   }
977 977
 
@@ -989,25 +989,25 @@  discard block
 block discarded – undo
989 989
 
990 990
   $user_skip_list = array();
991 991
 
992
-  if($config->stats_hide_admins) {
992
+  if ($config->stats_hide_admins) {
993 993
     $user_skip_list[] = '`authlevel` > 0';
994 994
   }
995 995
 
996
-  if($config->stats_hide_player_list) {
996
+  if ($config->stats_hide_player_list) {
997 997
     $temp = explode(',', $config->stats_hide_player_list);
998
-    foreach($temp as $user_id) {
998
+    foreach ($temp as $user_id) {
999 999
       $user_id = floatval($user_id);
1000
-      if($user_id) {
1000
+      if ($user_id) {
1001 1001
         $user_skip_list[] = '`id` = ' . $user_id;
1002 1002
       }
1003 1003
     }
1004 1004
   }
1005 1005
 
1006
-  if(!empty($user_skip_list)) {
1006
+  if (!empty($user_skip_list)) {
1007 1007
     $user_skip_list = implode(' OR ', $user_skip_list);
1008 1008
     $user_skip_query = db_user_list($user_skip_list);
1009
-    if(!empty($user_skip_query)) {
1010
-      foreach($user_skip_query as $user_skip_row) {
1009
+    if (!empty($user_skip_query)) {
1010
+      foreach ($user_skip_query as $user_skip_row) {
1011 1011
         $result[$user_skip_row['id']] = $user_skip_row['id'];
1012 1012
       }
1013 1013
     }
@@ -1038,7 +1038,7 @@  discard block
 block discarded – undo
1038 1038
 
1039 1039
 function sn_sn_get_groups($groups, &$result) {
1040 1040
   $result = is_array($result) ? $result : array();
1041
-  foreach($groups = is_array($groups) ? $groups : array($groups) as $group_name) {
1041
+  foreach ($groups = is_array($groups) ? $groups : array($groups) as $group_name) {
1042 1042
     $result += is_array($a_group = get_unit_param(UNIT_GROUP, $group_name)) ? $a_group : array();
1043 1043
   }
1044 1044
 
@@ -1066,8 +1066,8 @@  discard block
 block discarded – undo
1066 1066
   $sn_data_unit = get_unit_param($unit_id);
1067 1067
 
1068 1068
   $result = is_array($result) ? $result : array();
1069
-  if($sn_data_unit[$field] && !($sn_data_unit[P_UNIT_TYPE] == UNIT_MERCENARIES && $config->empire_mercenary_temporary)) {
1070
-    foreach($sn_data_unit[$field] as $require_id => $require_level) {
1069
+  if ($sn_data_unit[$field] && !($sn_data_unit[P_UNIT_TYPE] == UNIT_MERCENARIES && $config->empire_mercenary_temporary)) {
1070
+    foreach ($sn_data_unit[$field] as $require_id => $require_level) {
1071 1071
       $level_got = mrc_get_level($user, $planetrow, $require_id);
1072 1072
       $level_basic = mrc_get_level($user, $planetrow, $require_id, false, true);
1073 1073
       $result[] = array(
@@ -1091,16 +1091,16 @@  discard block
 block discarded – undo
1091 1091
 
1092 1092
   $ranks = array();
1093 1093
 
1094
-  if($ally['ranklist']) {
1094
+  if ($ally['ranklist']) {
1095 1095
     $str_ranks = explode(';', $ally['ranklist']);
1096
-    foreach($str_ranks as $str_rank) {
1097
-      if(!$str_rank) {
1096
+    foreach ($str_ranks as $str_rank) {
1097
+      if (!$str_rank) {
1098 1098
         continue;
1099 1099
       }
1100 1100
 
1101 1101
       $tmp = explode(',', $str_rank);
1102 1102
       $rank_id = count($ranks);
1103
-      foreach($ally_rights as $key => $value) {
1103
+      foreach ($ally_rights as $key => $value) {
1104 1104
         $ranks[$rank_id][$value] = $tmp[$key];
1105 1105
       }
1106 1106
     }
@@ -1116,8 +1116,8 @@  discard block
 block discarded – undo
1116 1116
 }
1117 1117
 
1118 1118
 function array_merge_recursive_numeric($array1, $array2) {
1119
-  if(!empty($array2) && is_array($array2)) {
1120
-    foreach($array2 as $key => $value) {
1119
+  if (!empty($array2) && is_array($array2)) {
1120
+    foreach ($array2 as $key => $value) {
1121 1121
 //    if(!isset($array1[$key]) || !is_array($array1[$key])) {
1122 1122
 //      $array1[$key] = $value;
1123 1123
 //    } else {
@@ -1132,7 +1132,7 @@  discard block
 block discarded – undo
1132 1132
 
1133 1133
 function sn_sys_array_cumulative_sum(&$array) {
1134 1134
   $accum = 0;
1135
-  foreach($array as &$value) {
1135
+  foreach ($array as &$value) {
1136 1136
     $accum += $value;
1137 1137
     $value = $accum;
1138 1138
   }
@@ -1142,7 +1142,7 @@  discard block
 block discarded – undo
1142 1142
   $sn_data_density = sn_get_groups('planet_density');
1143 1143
   $density_price_chart = array();
1144 1144
 
1145
-  foreach($sn_data_density as $density_id => $density_data) {
1145
+  foreach ($sn_data_density as $density_id => $density_data) {
1146 1146
     // Отсекаем записи с RARITY = 0 - служебные записи и супер-ядра
1147 1147
     $density_data[UNIT_PLANET_DENSITY_RARITY] ? $density_price_chart[$density_id] = $density_data[UNIT_PLANET_DENSITY_RARITY] : false;
1148 1148
   }
@@ -1150,7 +1150,7 @@  discard block
 block discarded – undo
1150 1150
 
1151 1151
   $total_rarity = array_sum($density_price_chart);
1152 1152
 
1153
-  foreach($density_price_chart as &$density_data) {
1153
+  foreach ($density_price_chart as &$density_data) {
1154 1154
     $density_data = ceil($total_rarity / $density_data * $planet_row['field_max'] * PLANET_DENSITY_TO_DARK_MATTER_RATE);
1155 1155
   }
1156 1156
 
@@ -1158,18 +1158,18 @@  discard block
 block discarded – undo
1158 1158
 }
1159 1159
 
1160 1160
 function sn_sys_planet_core_transmute(&$user, &$planetrow) {
1161
-  if(!sys_get_param_str('transmute')) {
1161
+  if (!sys_get_param_str('transmute')) {
1162 1162
     return array();
1163 1163
   }
1164 1164
 
1165 1165
   global $lang;
1166 1166
 
1167 1167
   try {
1168
-    if($planetrow['planet_type'] != PT_PLANET) {
1168
+    if ($planetrow['planet_type'] != PT_PLANET) {
1169 1169
       throw new exception(classLocale::$lang['ov_core_err_not_a_planet'], ERR_ERROR);
1170 1170
     }
1171 1171
 
1172
-    if($planetrow['density_index'] == ($new_density_index = sys_get_param_id('density_type'))) {
1172
+    if ($planetrow['density_index'] == ($new_density_index = sys_get_param_id('density_type'))) {
1173 1173
       throw new exception(classLocale::$lang['ov_core_err_same_density'], ERR_WARNING);
1174 1174
     }
1175 1175
 
@@ -1183,7 +1183,7 @@  discard block
 block discarded – undo
1183 1183
     $planet_density_index = $planetrow['density_index'];
1184 1184
 
1185 1185
     $density_price_chart = planet_density_price_chart($planetrow);
1186
-    if(!isset($density_price_chart[$new_density_index])) {
1186
+    if (!isset($density_price_chart[$new_density_index])) {
1187 1187
       // Hack attempt
1188 1188
       throw new exception(classLocale::$lang['ov_core_err_denisty_type_wrong'], ERR_ERROR);
1189 1189
     }
@@ -1192,13 +1192,13 @@  discard block
 block discarded – undo
1192 1192
     // $transmute_cost = get_unit_param(UNIT_PLANET_DENSITY, 'cost');
1193 1193
     // $transmute_cost = $transmute_cost[RES_DARK_MATTER] * $density_price_chart[$new_density_index];
1194 1194
     $transmute_cost = $density_price_chart[$new_density_index];
1195
-    if($user_dark_matter < $transmute_cost) {
1195
+    if ($user_dark_matter < $transmute_cost) {
1196 1196
       throw new exception(classLocale::$lang['ov_core_err_no_dark_matter'], ERR_ERROR);
1197 1197
     }
1198 1198
 
1199 1199
     $sn_data_planet_density = sn_get_groups('planet_density');
1200
-    foreach($sn_data_planet_density as $key => $value) {
1201
-      if($key == $new_density_index) {
1200
+    foreach ($sn_data_planet_density as $key => $value) {
1201
+      if ($key == $new_density_index) {
1202 1202
         break;
1203 1203
       }
1204 1204
       $prev_density_index = $key;
@@ -1229,7 +1229,7 @@  discard block
 block discarded – undo
1229 1229
       'STATUS'  => ERR_NONE,
1230 1230
       '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),
1231 1231
     );
1232
-  } catch(exception $e) {
1232
+  } catch (exception $e) {
1233 1233
     sn_db_transaction_rollback();
1234 1234
     $result = array(
1235 1235
       'STATUS'  => $e->getCode(),
@@ -1242,8 +1242,8 @@  discard block
 block discarded – undo
1242 1242
 
1243 1243
 function sn_module_get_active_count($group = '*') {
1244 1244
   $active_modules = 0;
1245
-  if(isset(sn_module::$sn_module_list[$group]) && is_array(sn_module::$sn_module_list[$group])) {
1246
-    foreach(sn_module::$sn_module_list[$group] as $payment_module) {
1245
+  if (isset(sn_module::$sn_module_list[$group]) && is_array(sn_module::$sn_module_list[$group])) {
1246
+    foreach (sn_module::$sn_module_list[$group] as $payment_module) {
1247 1247
       $active_modules += $payment_module->manifest['active'];
1248 1248
     }
1249 1249
   }
@@ -1254,7 +1254,7 @@  discard block
 block discarded – undo
1254 1254
 function get_resource_exchange() {
1255 1255
   static $rates;
1256 1256
 
1257
-  if(!$rates) {
1257
+  if (!$rates) {
1258 1258
     global $config;
1259 1259
 
1260 1260
     $rates = array(
@@ -1264,7 +1264,7 @@  discard block
 block discarded – undo
1264 1264
       RES_DARK_MATTER => 'rpg_exchange_darkMatter',
1265 1265
     );
1266 1266
 
1267
-    foreach($rates as &$rate) {
1267
+    foreach ($rates as &$rate) {
1268 1268
       $rate = $config->$rate;
1269 1269
     }
1270 1270
   }
@@ -1275,12 +1275,12 @@  discard block
 block discarded – undo
1275 1275
 function get_unit_cost_in(&$cost, $in_resource = RES_METAL) {
1276 1276
   static $rates;
1277 1277
 
1278
-  if(!$rates) {
1278
+  if (!$rates) {
1279 1279
     $rates = get_resource_exchange();
1280 1280
   }
1281 1281
 
1282 1282
   $metal_cost = 0;
1283
-  foreach($cost as $resource_id => $resource_value) {
1283
+  foreach ($cost as $resource_id => $resource_value) {
1284 1284
     $metal_cost += $rates[$resource_id] * $resource_value;
1285 1285
   }
1286 1286
 
@@ -1290,8 +1290,8 @@  discard block
 block discarded – undo
1290 1290
 function get_player_max_expeditons(&$user, $astrotech = -1) { return sn_function_call(__FUNCTION__, array(&$user, $astrotech, &$result)); }
1291 1291
 
1292 1292
 function sn_get_player_max_expeditons(&$user, $astrotech = -1, &$result = 0) {
1293
-  if($astrotech == -1) {
1294
-    if(!isset($user[UNIT_PLAYER_EXPEDITIONS_MAX])) {
1293
+  if ($astrotech == -1) {
1294
+    if (!isset($user[UNIT_PLAYER_EXPEDITIONS_MAX])) {
1295 1295
       $astrotech = mrc_get_level($user, false, TECH_ASTROTECH);
1296 1296
       $user[UNIT_PLAYER_EXPEDITIONS_MAX] = $astrotech >= 1 ? floor(sqrt($astrotech - 1)) : 0;
1297 1297
     }
@@ -1309,8 +1309,8 @@  discard block
 block discarded – undo
1309 1309
 function get_player_max_colonies(&$user, $astrotech = -1) {
1310 1310
   global $config;
1311 1311
 
1312
-  if($astrotech == -1) {
1313
-    if(!isset($user[UNIT_PLAYER_COLONIES_MAX])) {
1312
+  if ($astrotech == -1) {
1313
+    if (!isset($user[UNIT_PLAYER_COLONIES_MAX])) {
1314 1314
 
1315 1315
       $expeditions = get_player_max_expeditons($user);
1316 1316
       $astrotech = mrc_get_level($user, false, TECH_ASTROTECH);
@@ -1355,10 +1355,10 @@  discard block
 block discarded – undo
1355 1355
 
1356 1356
   // pdump($powerup_unit, '$powerup_unit');
1357 1357
   $level_current = $term_original = $time_left = 0;
1358
-  if($is_upgrade) {
1358
+  if ($is_upgrade) {
1359 1359
     $time_finish = strtotime($powerup_unit['unit_time_finish']);
1360 1360
     $time_left = max(0, $time_finish - SN_TIME_NOW);
1361
-    if($time_left > 0) {
1361
+    if ($time_left > 0) {
1362 1362
       $term_original = $time_finish - strtotime($powerup_unit['unit_time_start']);
1363 1363
       $level_current = $powerup_unit['unit_level'];
1364 1364
     }
@@ -1366,22 +1366,22 @@  discard block
 block discarded – undo
1366 1366
 
1367 1367
   $level_max = $level_max > $powerup_data[P_MAX_STACK] ? $level_max : $powerup_data[P_MAX_STACK];
1368 1368
   $original_cost = 0;
1369
-  for($i = 1; $i <= $level_max; $i++) {
1369
+  for ($i = 1; $i <= $level_max; $i++) {
1370 1370
     $base_cost = eco_get_total_cost($powerup_id, $i);
1371 1371
     $base_cost = $base_cost[BUILD_CREATE][RES_DARK_MATTER];
1372
-    foreach($sn_powerup_buy_discounts as $period => $discount) {
1372
+    foreach ($sn_powerup_buy_discounts as $period => $discount) {
1373 1373
       $upgrade_price = floor($base_cost * $discount * $period / PERIOD_MONTH);
1374 1374
       $result[$i][$period] = $upgrade_price;
1375 1375
       $original_cost = $is_upgrade && $i == $level_current && $period <= $term_original ? $upgrade_price : $original_cost;
1376 1376
     }
1377 1377
   }
1378 1378
 
1379
-  if($is_upgrade && $time_left) {
1379
+  if ($is_upgrade && $time_left) {
1380 1380
     $term_original = round($term_original / PERIOD_DAY);
1381 1381
     $time_left = min(floor($time_left / PERIOD_DAY), $term_original);
1382 1382
     $cost_left = $term_original > 0 ? ceil($time_left / $term_original * $original_cost) : 0;
1383 1383
 
1384
-    array_walk_recursive($result, function (&$value) use ($cost_left) {
1384
+    array_walk_recursive($result, function(&$value) use ($cost_left) {
1385 1385
       $value -= $cost_left;
1386 1386
     });
1387 1387
   }
@@ -1439,7 +1439,7 @@  discard block
 block discarded – undo
1439 1439
 
1440 1440
 function print_rr($var, $capture = false) {
1441 1441
   $print = '<pre>' . htmlspecialchars(print_r($var, true)) . '</pre>';
1442
-  if($capture) {
1442
+  if ($capture) {
1443 1443
     return $print;
1444 1444
   } else {
1445 1445
     print($print);
Please login to merge, or discard this patch.
includes/general/math.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,11 +37,11 @@
 block discarded – undo
37 37
 /**
38 38
  * @param float      $range_start - Начало диапазона
39 39
  * @param float      $range_end - Конец диапазона
40
- * @param bool|int  $round - До скольки знаков округлять результат. False - не округлять, True - округлять до целого, 1 - округлять до десятков, 2 - до сотен итд
40
+ * @param boolean  $round - До скольки знаков округлять результат. False - не округлять, True - округлять до целого, 1 - округлять до десятков, 2 - до сотен итд
41 41
  * @param int        $strict - В сколько сигм надо уложить результат
42 42
  * @param bool|false $cut_extreme - надо ли обрезать крайние значения. Например, при $strict = 2 их слишком много
43 43
  *
44
- * @return float|int
44
+ * @return double
45 45
  */
46 46
 function sn_rand_gauss_range($range_start, $range_end, $round = true, $strict = 4, $cut_extreme = false)  {
47 47
   if($cut_extreme) {
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 function geometry_progression_sum($n, $b1, $q) {
4
-  return $q != 1 ? ($b1 * (pow($q, $n) - 1)/($q - 1)) : ($n * $b1);
4
+  return $q != 1 ? ($b1 * (pow($q, $n) - 1) / ($q - 1)) : ($n * $b1);
5 5
 }
6 6
 
7 7
 function sn_floor($value)
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
  *
44 44
  * @return float|int
45 45
  */
46
-function sn_rand_gauss_range($range_start, $range_end, $round = true, $strict = 4, $cut_extreme = false)  {
47
-  if($cut_extreme) {
46
+function sn_rand_gauss_range($range_start, $range_end, $round = true, $strict = 4, $cut_extreme = false) {
47
+  if ($cut_extreme) {
48 48
     $range_start--;
49 49
     $range_end++;
50 50
   }
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 {
61 61
   $args = func_get_args();
62 62
 
63
-  switch(func_num_args())
63
+  switch (func_num_args())
64 64
   {
65 65
     case 0:
66 66
       // trigger_error('median() requires at least one parameter',E_USER_WARNING);
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
     // fallthrough
73 73
 
74 74
     default:
75
-      if(!is_array($args))
75
+      if (!is_array($args))
76 76
       {
77 77
         // trigger_error('median() requires a list of numbers to operate on or an array of numbers', E_USER_NOTICE);
78 78
         return false;
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
       $n = count($args);
84 84
       $h = intval($n / 2);
85 85
 
86
-      if($n % 2 == 0)
86
+      if ($n % 2 == 0)
87 87
       {
88
-        $median = ($args[$h] + $args[$h-1]) / 2;
88
+        $median = ($args[$h] + $args[$h - 1]) / 2;
89 89
       }
90 90
       else
91 91
       {
@@ -103,47 +103,47 @@  discard block
 block discarded – undo
103 103
 }
104 104
 function linear_calc(&$linear, $from = 0, $debug = false)
105 105
 {
106
-  for($i = $from; $i < count($linear); $i++)
106
+  for ($i = $from; $i < count($linear); $i++)
107 107
   {
108 108
     $eq = &$linear[$i];
109
-    for($j = count($eq) - 1; $j >= $from; $j--)
109
+    for ($j = count($eq) - 1; $j >= $from; $j--)
110 110
     {
111 111
       $eq[$j] /= $eq[$from];
112 112
     }
113 113
   }
114
-  if($debug) pdump($linear, 'Нормализовано по х' . $from);
114
+  if ($debug) pdump($linear, 'Нормализовано по х' . $from);
115 115
 
116
-  for($i = $from + 1; $i < count($linear); $i++)
116
+  for ($i = $from + 1; $i < count($linear); $i++)
117 117
   {
118 118
     $eq = &$linear[$i];
119
-    for($j = count($eq) - 1; $j >= $from; $j--)
119
+    for ($j = count($eq) - 1; $j >= $from; $j--)
120 120
     {
121 121
       $eq[$j] -= $linear[$from][$j];
122 122
     }
123 123
   }
124
-  if($debug) pdump($linear, 'Подставили х' . $from);
124
+  if ($debug) pdump($linear, 'Подставили х' . $from);
125 125
 
126
-  if($from < count($linear) - 1)
126
+  if ($from < count($linear) - 1)
127 127
   {
128 128
     linear_calc($linear, $from + 1, $debug);
129 129
   }
130 130
 
131
-  if($from)
131
+  if ($from)
132 132
   {
133
-    for($i = 0; $i < $from; $i++)
133
+    for ($i = 0; $i < $from; $i++)
134 134
     {
135 135
       $eq = &$linear[$i];
136
-      for($j = count($eq) - 1; $j >= $from; $j--)
136
+      for ($j = count($eq) - 1; $j >= $from; $j--)
137 137
       {
138 138
         $eq[$j] = $eq[$j] - $eq[$from] * $linear[$from][$j];
139 139
       }
140 140
     }
141
-    if($debug) pdump($linear, 'Подставили обратно х' . $from);
141
+    if ($debug) pdump($linear, 'Подставили обратно х' . $from);
142 142
   }
143 143
   else
144 144
   {
145
-    if($debug) pdump($linear, 'Результат' . $from);
146
-    foreach($linear as $index => &$eq)
145
+    if ($debug) pdump($linear, 'Результат' . $from);
146
+    foreach ($linear as $index => &$eq)
147 147
     {
148 148
       pdump($eq[count($linear)], 'x' . $index);
149 149
     }
Please login to merge, or discard this patch.
Braces   +14 added lines, -8 removed lines patch added patch discarded remove patch
@@ -86,8 +86,7 @@  discard block
 block discarded – undo
86 86
       if($n % 2 == 0)
87 87
       {
88 88
         $median = ($args[$h] + $args[$h-1]) / 2;
89
-      }
90
-      else
89
+      } else
91 90
       {
92 91
         $median = $args[$h];
93 92
       }
@@ -111,7 +110,9 @@  discard block
 block discarded – undo
111 110
       $eq[$j] /= $eq[$from];
112 111
     }
113 112
   }
114
-  if($debug) pdump($linear, 'Нормализовано по х' . $from);
113
+  if($debug) {
114
+    pdump($linear, 'Нормализовано по х' . $from);
115
+  }
115 116
 
116 117
   for($i = $from + 1; $i < count($linear); $i++)
117 118
   {
@@ -121,7 +122,9 @@  discard block
 block discarded – undo
121 122
       $eq[$j] -= $linear[$from][$j];
122 123
     }
123 124
   }
124
-  if($debug) pdump($linear, 'Подставили х' . $from);
125
+  if($debug) {
126
+    pdump($linear, 'Подставили х' . $from);
127
+  }
125 128
 
126 129
   if($from < count($linear) - 1)
127 130
   {
@@ -138,11 +141,14 @@  discard block
 block discarded – undo
138 141
         $eq[$j] = $eq[$j] - $eq[$from] * $linear[$from][$j];
139 142
       }
140 143
     }
141
-    if($debug) pdump($linear, 'Подставили обратно х' . $from);
142
-  }
143
-  else
144
+    if($debug) {
145
+      pdump($linear, 'Подставили обратно х' . $from);
146
+    }
147
+  } else
144 148
   {
145
-    if($debug) pdump($linear, 'Результат' . $from);
149
+    if($debug) {
150
+      pdump($linear, 'Результат' . $from);
151
+    }
146 152
     foreach($linear as $index => &$eq)
147 153
     {
148 154
       pdump($eq[count($linear)], 'x' . $index);
Please login to merge, or discard this patch.
includes/includes/flt_functions.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
+/**
4
+ * @return double
5
+ */
3 6
 function flt_fleet_speed($user, $fleet)
4 7
 {
5 8
   if (!is_array($fleet))
Please login to merge, or discard this patch.
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 function flt_fleet_speed($user, $fleet) {
4
-  if(!is_array($fleet)) {
4
+  if (!is_array($fleet)) {
5 5
     $fleet = array($fleet => 1);
6 6
   }
7 7
 
8 8
   $speeds = array();
9
-  if(!empty($fleet)) {
10
-    foreach($fleet as $ship_id => $amount) {
11
-      if($amount && in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) {
9
+  if (!empty($fleet)) {
10
+    foreach ($fleet as $ship_id => $amount) {
11
+      if ($amount && in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) {
12 12
         $single_ship_data = get_ship_data($ship_id, $user);
13 13
         $speeds[] = $single_ship_data['speed'];
14 14
       }
@@ -21,11 +21,11 @@  discard block
 block discarded – undo
21 21
 function flt_travel_distance($from, $to) {
22 22
   global $config;
23 23
 
24
-  if($from['galaxy'] != $to['galaxy']) {
24
+  if ($from['galaxy'] != $to['galaxy']) {
25 25
     $distance = abs($from['galaxy'] - $to['galaxy']) * $config->uni_galaxy_distance;
26
-  } elseif($from['system'] != $to['system']) {
26
+  } elseif ($from['system'] != $to['system']) {
27 27
     $distance = abs($from['system'] - $to['system']) * 5 * 19 + 2700;
28
-  } elseif($from['planet'] != $to['planet']) {
28
+  } elseif ($from['planet'] != $to['planet']) {
29 29
     $distance = abs($from['planet'] - $to['planet']) * 5 + 1000;
30 30
   } else {
31 31
     $distance = 5;
@@ -52,14 +52,14 @@  discard block
 block discarded – undo
52 52
 
53 53
   $game_fleet_speed = flt_server_flight_speed_multiplier();
54 54
   $fleet_speed = flt_fleet_speed($user_row, $fleet_array);
55
-  if(!empty($fleet_array) && $fleet_speed && $game_fleet_speed) {
55
+  if (!empty($fleet_array) && $fleet_speed && $game_fleet_speed) {
56 56
     $speed_percent = $speed_percent ? max(min($speed_percent, 10), 1) : 10;
57 57
     $real_speed = $speed_percent * sqrt($fleet_speed);
58 58
 
59 59
     $duration = max(1, round((35000 / $speed_percent * sqrt($distance * 10 / $fleet_speed) + 10) / $game_fleet_speed));
60 60
 
61
-    foreach($fleet_array as $ship_id => $ship_count) {
62
-      if(!$ship_id || !$ship_count) {
61
+    foreach ($fleet_array as $ship_id => $ship_count) {
62
+      if (!$ship_id || !$ship_count) {
63 63
         continue;
64 64
       }
65 65
 
@@ -89,19 +89,19 @@  discard block
 block discarded – undo
89 89
 
90 90
   $config_bashing_attacks = $config->fleet_bashing_attacks;
91 91
   $config_bashing_interval = $config->fleet_bashing_interval;
92
-  if(!$config_bashing_attacks) {
92
+  if (!$config_bashing_attacks) {
93 93
     // Bashing allowed - protection disabled
94 94
     return ATTACK_ALLOWED;
95 95
   }
96 96
 
97 97
   $bashing_result = ATTACK_BASHING;
98
-  if($user['ally_id'] && $enemy['ally_id']) {
98
+  if ($user['ally_id'] && $enemy['ally_id']) {
99 99
     $relations = ali_relations($user['ally_id'], $enemy['ally_id']);
100
-    if(!empty($relations)) {
100
+    if (!empty($relations)) {
101 101
       $relations = $relations[$enemy['ally_id']];
102
-      switch($relations['alliance_diplomacy_relation']) {
102
+      switch ($relations['alliance_diplomacy_relation']) {
103 103
         case ALLY_DIPLOMACY_WAR:
104
-          if(SN_TIME_NOW - $relations['alliance_diplomacy_time'] <= $config->fleet_bashing_war_delay) {
104
+          if (SN_TIME_NOW - $relations['alliance_diplomacy_time'] <= $config->fleet_bashing_war_delay) {
105 105
             $bashing_result = ATTACK_BASHING_WAR_DELAY;
106 106
           } else {
107 107
             return ATTACK_ALLOWED;
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
 
124 124
   // Retrieving flying fleets
125 125
   $objFleetsBashing = FleetList::dbGetFleetListBashing($user['id'], $planet_dst);
126
-  foreach($objFleetsBashing->_container as $fleetBashing) {
126
+  foreach ($objFleetsBashing->_container as $fleetBashing) {
127 127
     // Checking for ACS - each ACS count only once
128
-    if($fleetBashing->group_id) {
128
+    if ($fleetBashing->group_id) {
129 129
       $bashing_list["{$user['id']}_{$fleetBashing->group_id}"] = $fleetBashing->time_arrive_to_target;
130 130
     } else {
131 131
       $bashing_list[] = $fleetBashing->time_arrive_to_target;
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
   }
134 134
 
135 135
   // Check for joining to ACS - if there are already fleets in ACS no checks should be done
136
-  if($mission == MT_AKS && $bashing_list["{$user['id']}_{$fleet_group}"]) {
136
+  if ($mission == MT_AKS && $bashing_list["{$user['id']}_{$fleet_group}"]) {
137 137
     return ATTACK_ALLOWED;
138 138
   }
139 139
 
140 140
   $query = db_bashing_list_get($user, $planet_dst, $time_limit);
141
-  while($bashing_row = db_fetch($query)) {
141
+  while ($bashing_row = db_fetch($query)) {
142 142
     $bashing_list[] = $bashing_row['bashing_time'];
143 143
   }
144 144
 
@@ -147,9 +147,9 @@  discard block
 block discarded – undo
147 147
   $last_attack = 0;
148 148
   $wave = 0;
149 149
   $attack = 1;
150
-  foreach($bashing_list as &$bash_time) {
150
+  foreach ($bashing_list as &$bash_time) {
151 151
     $attack++;
152
-    if($bash_time - $last_attack > $config_bashing_interval || $attack > $config_bashing_attacks) {
152
+    if ($bash_time - $last_attack > $config_bashing_interval || $attack > $config_bashing_attacks) {
153 153
       $attack = 1;
154 154
       $wave++;
155 155
     }
@@ -166,16 +166,16 @@  discard block
 block discarded – undo
166 166
   //TODO: try..catch
167 167
   global $config, $user;
168 168
 
169
-  if($user['vacation']) {
169
+  if ($user['vacation']) {
170 170
     return $result = ATTACK_OWN_VACATION;
171 171
   }
172 172
 
173
-  if(empty($fleet) || !is_array($fleet)) {
173
+  if (empty($fleet) || !is_array($fleet)) {
174 174
     return $result = ATTACK_NO_FLEET;
175 175
   }
176 176
 
177 177
   $sn_groups_mission = sn_get_groups('missions');
178
-  if(!isset($sn_groups_mission[$mission])) {
178
+  if (!isset($sn_groups_mission[$mission])) {
179 179
     return $result = ATTACK_MISSION_ABSENT;
180 180
   }
181 181
   $sn_data_mission = $sn_groups_mission[$mission];
@@ -194,32 +194,32 @@  discard block
 block discarded – undo
194 194
   $resources = 0;
195 195
   $ship_ids = sn_get_groups('fleet');
196 196
   $resource_ids = sn_get_groups('resources_loot');
197
-  foreach($fleet as $ship_id => $ship_count) {
197
+  foreach ($fleet as $ship_id => $ship_count) {
198 198
     $is_ship = in_array($ship_id, $ship_ids);
199 199
     $is_resource = in_array($ship_id, $resource_ids);
200
-    if(!$is_ship && !$is_resource) {
200
+    if (!$is_ship && !$is_resource) {
201 201
       // TODO Спецобработчик для Капитана и модулей
202 202
 //      return ATTACK_WRONG_UNIT;
203 203
     }
204 204
 
205
-    if($ship_count < 0) {
205
+    if ($ship_count < 0) {
206 206
       return $result = $is_ship ? ATTACK_SHIP_COUNT_WRONG : ATTACK_RESOURCE_COUNT_WRONG;
207 207
     }
208 208
 
209
-    if($ship_count > mrc_get_level($user, $planet_src, $ship_id)) {
209
+    if ($ship_count > mrc_get_level($user, $planet_src, $ship_id)) {
210 210
       // TODO ATTACK_NO_MISSILE
211 211
       return $result = $is_ship ? ATTACK_NO_SHIPS : ATTACK_NO_RESOURCES;
212 212
     }
213 213
 
214
-    if($is_ship) {
214
+    if ($is_ship) {
215 215
       $single_ship_data = get_ship_data($ship_id, $user);
216
-      if($single_ship_data[P_SPEED] <= 0) {
216
+      if ($single_ship_data[P_SPEED] <= 0) {
217 217
         return $result = ATTACK_ZERO_SPEED;
218 218
       }
219 219
       $ships += $ship_count;
220 220
       $recyclers += in_array($ship_id, sn_get_groups('flt_recyclers')) ? $ship_count : 0;
221 221
       $spies += $ship_id == SHIP_SPY ? $ship_count : 0;
222
-    } elseif($is_resource) {
222
+    } elseif ($is_resource) {
223 223
       $resources += $ship_count;
224 224
     }
225 225
   }
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
     }
231 231
   */
232 232
 
233
-  if(isset($options['resources']) && $options['resources'] > 0 && !(isset($sn_data_mission['transport']) && $sn_data_mission['transport'])) {
233
+  if (isset($options['resources']) && $options['resources'] > 0 && !(isset($sn_data_mission['transport']) && $sn_data_mission['transport'])) {
234 234
     return $result = ATTACK_RESOURCE_FORBIDDEN;
235 235
   }
236 236
 
@@ -242,78 +242,78 @@  discard block
 block discarded – undo
242 242
   */
243 243
 
244 244
   $speed = $options['fleet_speed_percent'];
245
-  if($speed && ($speed != intval($speed) || $speed < 1 || $speed > 10)) {
245
+  if ($speed && ($speed != intval($speed) || $speed < 1 || $speed > 10)) {
246 246
     return $result = ATTACK_WRONG_SPEED;
247 247
   }
248 248
 
249 249
   $travel_data = flt_travel_data($user, $planet_src, $planet_dst, $fleet, $options['fleet_speed_percent']);
250 250
 
251 251
 
252
-  if(mrc_get_level($user, $planet_src, RES_DEUTERIUM) < $fleet[RES_DEUTERIUM] + $travel_data['consumption']) {
252
+  if (mrc_get_level($user, $planet_src, RES_DEUTERIUM) < $fleet[RES_DEUTERIUM] + $travel_data['consumption']) {
253 253
     return $result = ATTACK_NO_FUEL;
254 254
   }
255 255
 
256
-  if($travel_data['consumption'] > $travel_data['capacity']) {
256
+  if ($travel_data['consumption'] > $travel_data['capacity']) {
257 257
     return $result = ATTACK_TOO_FAR;
258 258
   }
259 259
 
260
-  if($travel_data['hold'] < $resources) {
260
+  if ($travel_data['hold'] < $resources) {
261 261
     return $result = ATTACK_OVERLOADED;
262 262
   }
263 263
 
264 264
   $fleet_start_time = SN_TIME_NOW + $travel_data['duration'];
265 265
 
266 266
   $fleet_group = $options['fleet_group'];
267
-  if($fleet_group) {
268
-    if($mission != MT_AKS) {
267
+  if ($fleet_group) {
268
+    if ($mission != MT_AKS) {
269 269
       return $result = ATTACK_WRONG_MISSION;
270 270
     };
271 271
 
272 272
     $acs = db_acs_get_by_group_id($fleet_group);
273
-    if(!$acs['id']) {
273
+    if (!$acs['id']) {
274 274
       return $result = ATTACK_NO_ACS;
275 275
     }
276 276
 
277
-    if($planet_dst['galaxy'] != $acs['galaxy'] || $planet_dst['system'] != $acs['system'] || $planet_dst['planet'] != $acs['planet'] || $planet_dst['planet_type'] != $acs['planet_type']) {
277
+    if ($planet_dst['galaxy'] != $acs['galaxy'] || $planet_dst['system'] != $acs['system'] || $planet_dst['planet'] != $acs['planet'] || $planet_dst['planet_type'] != $acs['planet_type']) {
278 278
       return $result = ATTACK_ACS_WRONG_TARGET;
279 279
     }
280 280
 
281
-    if($fleet_start_time > $acs['ankunft']) {
281
+    if ($fleet_start_time > $acs['ankunft']) {
282 282
       return $result = ATTACK_ACS_TOO_LATE;
283 283
     }
284 284
   }
285 285
 
286 286
   $flying_fleets = $options['flying_fleets'];
287
-  if(!$flying_fleets) {
287
+  if (!$flying_fleets) {
288 288
     $flying_fleets = FleetList::fleet_count_flying($user['id']);
289 289
   }
290
-  if(GetMaxFleets($user) <= $flying_fleets && $mission != MT_MISSILE) {
290
+  if (GetMaxFleets($user) <= $flying_fleets && $mission != MT_MISSILE) {
291 291
     return $result = ATTACK_NO_SLOTS;
292 292
   }
293 293
 
294 294
   // В одиночку шпионские зонды могут летать только в миссии Шпионаж, Передислокация и Транспорт
295
-  if($ships && $spies && $spies == $ships && !($mission == MT_SPY || $mission == MT_RELOCATE || $mission == MT_TRANSPORT)) {
295
+  if ($ships && $spies && $spies == $ships && !($mission == MT_SPY || $mission == MT_RELOCATE || $mission == MT_TRANSPORT)) {
296 296
     return $result = ATTACK_SPIES_LONLY;
297 297
   }
298 298
 
299 299
   // Checking for no planet
300
-  if(!$planet_dst['id_owner']) {
301
-    if($mission == MT_COLONIZE && !$fleet[SHIP_COLONIZER]) {
300
+  if (!$planet_dst['id_owner']) {
301
+    if ($mission == MT_COLONIZE && !$fleet[SHIP_COLONIZER]) {
302 302
       return $result = ATTACK_NO_COLONIZER;
303 303
     }
304 304
 
305
-    if($mission == MT_EXPLORE || $mission == MT_COLONIZE) {
305
+    if ($mission == MT_EXPLORE || $mission == MT_COLONIZE) {
306 306
       return $result = ATTACK_ALLOWED;
307 307
     }
308 308
 
309 309
     return $result = ATTACK_NO_TARGET;
310 310
   }
311 311
 
312
-  if($mission == MT_RECYCLE) {
313
-    if($planet_dst['debris_metal'] + $planet_dst['debris_crystal'] <= 0) {
312
+  if ($mission == MT_RECYCLE) {
313
+    if ($planet_dst['debris_metal'] + $planet_dst['debris_crystal'] <= 0) {
314 314
       return $result = ATTACK_NO_DEBRIS;
315 315
     }
316
-    if($recyclers <= 0) {
316
+    if ($recyclers <= 0) {
317 317
       return $result = ATTACK_NO_RECYCLERS;
318 318
     }
319 319
 
@@ -321,8 +321,8 @@  discard block
 block discarded – undo
321 321
   }
322 322
 
323 323
   // Got planet. Checking if it is ours
324
-  if($planet_dst['id_owner'] == $user['id']) {
325
-    if($mission == MT_TRANSPORT || $mission == MT_RELOCATE) {
324
+  if ($planet_dst['id_owner'] == $user['id']) {
325
+    if ($mission == MT_TRANSPORT || $mission == MT_RELOCATE) {
326 326
       return $result = ATTACK_ALLOWED;
327 327
     }
328 328
 
@@ -330,19 +330,19 @@  discard block
 block discarded – undo
330 330
   }
331 331
 
332 332
   // No, planet not ours. Cutting mission that can't be send to not-ours planet
333
-  if($mission == MT_RELOCATE || $mission == MT_COLONIZE || $mission == MT_EXPLORE) {
333
+  if ($mission == MT_RELOCATE || $mission == MT_COLONIZE || $mission == MT_EXPLORE) {
334 334
     return $result = ATTACK_WRONG_MISSION;
335 335
   }
336 336
 
337 337
   $enemy = db_user_by_id($planet_dst['id_owner']);
338 338
   // We cannot attack or send resource to users in VACATION mode
339
-  if($enemy['vacation'] && $mission != MT_RECYCLE) {
339
+  if ($enemy['vacation'] && $mission != MT_RECYCLE) {
340 340
     return $result = ATTACK_VACATION;
341 341
   }
342 342
 
343 343
   // Multi IP protection
344 344
   // TODO: Here we need a procedure to check proxies
345
-  if(sys_is_multiaccount($user, $enemy)) {
345
+  if (sys_is_multiaccount($user, $enemy)) {
346 346
     return $result = ATTACK_SAME_IP;
347 347
   }
348 348
 
@@ -350,8 +350,8 @@  discard block
 block discarded – undo
350 350
   $enemy_points = $enemy['total_points'];
351 351
 
352 352
   // Is it transport? If yes - checking for buffing to prevent mega-alliance destroyer
353
-  if($mission == MT_TRANSPORT) {
354
-    if($user_points >= $enemy_points || $config->allow_buffing) {
353
+  if ($mission == MT_TRANSPORT) {
354
+    if ($user_points >= $enemy_points || $config->allow_buffing) {
355 355
       return $result = ATTACK_ALLOWED;
356 356
     } else {
357 357
       return $result = ATTACK_BUFFING;
@@ -361,66 +361,66 @@  discard block
 block discarded – undo
361 361
   // Only aggresive missions passed to this point. HOLD counts as passive but aggresive
362 362
 
363 363
   // Is it admin with planet protection?
364
-  if($planet_dst['id_level'] > $user['authlevel']) {
364
+  if ($planet_dst['id_level'] > $user['authlevel']) {
365 365
     return $result = ATTACK_ADMIN;
366 366
   }
367 367
 
368 368
   // Okay. Now skipping protection checks for inactive longer then 1 week
369
-  if(!$enemy['onlinetime'] || $enemy['onlinetime'] >= (SN_TIME_NOW - 60 * 60 * 24 * 7)) {
370
-    if(
369
+  if (!$enemy['onlinetime'] || $enemy['onlinetime'] >= (SN_TIME_NOW - 60 * 60 * 24 * 7)) {
370
+    if (
371 371
       ($enemy_points <= $config->game_noob_points && $user_points > $config->game_noob_points)
372 372
       ||
373 373
       ($config->game_noob_factor && $user_points > $enemy_points * $config->game_noob_factor)
374 374
     ) {
375
-      if($mission != MT_HOLD) {
375
+      if ($mission != MT_HOLD) {
376 376
         return $result = ATTACK_NOOB;
377 377
       }
378
-      if($mission == MT_HOLD && !($user['ally_id'] && $user['ally_id'] == $enemy['ally_id'] && $config->ally_help_weak)) {
378
+      if ($mission == MT_HOLD && !($user['ally_id'] && $user['ally_id'] == $enemy['ally_id'] && $config->ally_help_weak)) {
379 379
         return $result = ATTACK_NOOB;
380 380
       }
381 381
     }
382 382
   }
383 383
 
384 384
   // Is it HOLD mission? If yes - there should be ally deposit
385
-  if($mission == MT_HOLD) {
386
-    if(mrc_get_level($user, $planet_dst, STRUC_ALLY_DEPOSIT)) {
385
+  if ($mission == MT_HOLD) {
386
+    if (mrc_get_level($user, $planet_dst, STRUC_ALLY_DEPOSIT)) {
387 387
       return $result = ATTACK_ALLOWED;
388 388
     }
389 389
 
390 390
     return $result = ATTACK_NO_ALLY_DEPOSIT;
391 391
   }
392 392
 
393
-  if($mission == MT_SPY) {
393
+  if ($mission == MT_SPY) {
394 394
     return $result = $spies >= 1 ? ATTACK_ALLOWED : ATTACK_NO_SPIES;
395 395
   }
396 396
 
397 397
   // Is it MISSILE mission?
398
-  if($mission == MT_MISSILE) {
398
+  if ($mission == MT_MISSILE) {
399 399
     $sn_data_mip = get_unit_param(UNIT_DEF_MISSILE_INTERPLANET);
400
-    if(mrc_get_level($user, $planet_src, STRUC_SILO) < $sn_data_mip[P_REQUIRE][STRUC_SILO]) {
400
+    if (mrc_get_level($user, $planet_src, STRUC_SILO) < $sn_data_mip[P_REQUIRE][STRUC_SILO]) {
401 401
       return $result = ATTACK_NO_SILO;
402 402
     }
403 403
 
404
-    if(!$fleet[UNIT_DEF_MISSILE_INTERPLANET]) {
404
+    if (!$fleet[UNIT_DEF_MISSILE_INTERPLANET]) {
405 405
       return $result = ATTACK_NO_MISSILE;
406 406
     }
407 407
 
408 408
     $distance = abs($planet_dst['system'] - $planet_src['system']);
409 409
     $mip_range = flt_get_missile_range($user);
410
-    if($distance > $mip_range || $planet_dst['galaxy'] != $planet_src['galaxy']) {
410
+    if ($distance > $mip_range || $planet_dst['galaxy'] != $planet_src['galaxy']) {
411 411
       return $result = ATTACK_MISSILE_TOO_FAR;
412 412
     }
413 413
 
414
-    if(isset($options['target_structure']) && $options['target_structure'] && !in_array($options['target_structure'], sn_get_groups('defense_active'))) {
414
+    if (isset($options['target_structure']) && $options['target_structure'] && !in_array($options['target_structure'], sn_get_groups('defense_active'))) {
415 415
       return $result = ATTACK_WRONG_STRUCTURE;
416 416
     }
417 417
   }
418 418
 
419
-  if($mission == MT_DESTROY && $planet_dst['planet_type'] != PT_MOON) {
419
+  if ($mission == MT_DESTROY && $planet_dst['planet_type'] != PT_MOON) {
420 420
     return $result = ATTACK_WRONG_MISSION;
421 421
   }
422 422
 
423
-  if($mission == MT_ATTACK || $mission == MT_AKS || $mission == MT_DESTROY) {
423
+  if ($mission == MT_ATTACK || $mission == MT_AKS || $mission == MT_DESTROY) {
424 424
     return $result = flt_bashing_check($user, $enemy, $planet_dst, $mission, $travel_data['duration'], $fleet_group);
425 425
   }
426 426
 
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
   $from = $from['planet'];
448 448
 
449 449
   $can_attack = flt_can_attack($from, $to, $fleet_REAL_array, $mission, $options);
450
-  if($can_attack != ATTACK_ALLOWED) {
450
+  if ($can_attack != ATTACK_ALLOWED) {
451 451
     $internal_transaction ? sn_db_transaction_rollback() : false;
452 452
 
453 453
     return $can_attack;
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
   $travel_data = flt_travel_data($user, $from, $to, $fleet_REAL_array, $options['fleet_speed_percent']);
459 459
 
460 460
   $time_on_mission = 0;
461
-  if($mission == MT_EXPLORE || $mission == MT_HOLD) {
461
+  if ($mission == MT_EXPLORE || $mission == MT_HOLD) {
462 462
     // TODO - include some checks about maximum and minumum stay_duration
463 463
     $time_on_mission = $options['stay_time'] * 3600;
464 464
   }
@@ -481,14 +481,14 @@  discard block
 block discarded – undo
481 481
   $sn_group_resources_loot = sn_get_groups('resources_loot');
482 482
   $db_changeset = array();
483 483
   $planet_row_changed_fields = array();
484
-  foreach($fleet_REAL_array as $unit_id => $amount) {
485
-    if(!$amount || !$unit_id) {
484
+  foreach ($fleet_REAL_array as $unit_id => $amount) {
485
+    if (!$amount || !$unit_id) {
486 486
       continue;
487 487
     }
488 488
 
489
-    if(in_array($unit_id, $sn_group_fleet)) {
489
+    if (in_array($unit_id, $sn_group_fleet)) {
490 490
       $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, -$amount, $user, $from['id']);
491
-    } elseif(in_array($unit_id, $sn_group_resources_loot)) {
491
+    } elseif (in_array($unit_id, $sn_group_resources_loot)) {
492 492
       $planet_row_changed_fields[pname_resource_name($unit_id)]['delta'] -= $amount;
493 493
     }
494 494
   }
@@ -527,16 +527,16 @@  discard block
 block discarded – undo
527 527
 
528 528
   $ship_data = array();
529 529
   $fleet_array = array();
530
-  foreach($ship_list as $transport_id => $cork) {
530
+  foreach ($ship_list as $transport_id => $cork) {
531 531
     $ship_data[$transport_id] = flt_travel_data($user, $from, $to, array($transport_id => 1), 10);
532 532
   }
533 533
   uasort($ship_data, 'flt_calculate_ship_to_transport_sort');
534 534
 
535 535
   $fleet_capacity = 0;
536 536
   $fuel_total = $fuel_left = mrc_get_level($user, $from, RES_DEUTERIUM);
537
-  foreach($ship_data as $transport_id => &$ship_info) {
537
+  foreach ($ship_data as $transport_id => &$ship_info) {
538 538
     $ship_loaded = min($ship_list[$transport_id], ceil($resource_amount / $ship_info['hold']), floor($fuel_left / $ship_info['consumption']));
539
-    if($ship_loaded) {
539
+    if ($ship_loaded) {
540 540
       $fleet_array[$transport_id] = $ship_loaded;
541 541
       $resource_amount -= min($resource_amount, $ship_info['hold'] * $ship_loaded);
542 542
       $fuel_left -= $ship_info['consumption'] * $ship_loaded;
Please login to merge, or discard this patch.
includes/includes/flt_mission_spy.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -29,6 +29,9 @@
 block discarded – undo
29 29
   }
30 30
 }
31 31
 
32
+/**
33
+ * @param string $group_name
34
+ */
32 35
 function flt_spy_scan($target_planet, $group_name, $section_title, $target_user = array())
33 36
 {
34 37
   global $lang;
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -11,8 +11,8 @@  discard block
 block discarded – undo
11 11
  */
12 12
 // ----------------------------------------------------------------------------------------------------------------
13 13
 function coe_compress_add_units($unit_group, $target_planet, &$compress_data, $target_user = array()) {
14
-  foreach($unit_group as $unit_id) {
15
-    if(($unit_count = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) {
14
+  foreach ($unit_group as $unit_id) {
15
+    if (($unit_count = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) {
16 16
       $compress_data[$unit_id] = $unit_count;
17 17
     }
18 18
   }
@@ -22,8 +22,8 @@  discard block
 block discarded – undo
22 22
   global $lang;
23 23
 
24 24
   $result = "<tr><td class=\"c\" colspan=\"4\">{$section_title}</td></tr>";
25
-  foreach(sn_get_groups($group_name) as $unit_id) {
26
-    if(($unit_amount = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) {
25
+  foreach (sn_get_groups($group_name) as $unit_id) {
26
+    if (($unit_amount = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) {
27 27
       $result .= "<tr><td align=\"left\" colspan=\"3\">{$lang['tech'][$unit_id]}</td><td align=\"right\">{$unit_amount}</td></tr>";
28 28
     }
29 29
 
@@ -54,14 +54,14 @@  discard block
 block discarded – undo
54 54
 
55 55
   $objFleet = $mission_data->fleet;
56 56
 
57
-  if(empty($target_user_row['id']) || empty($target_planet_row['id']) || empty($spying_user_row['id'])) {
57
+  if (empty($target_user_row['id']) || empty($target_planet_row['id']) || empty($spying_user_row['id'])) {
58 58
     $objFleet->mark_fleet_as_returned_and_save();
59 59
 
60 60
     return $result;
61 61
   }
62 62
 
63 63
   $spy_probes = $objFleet->shipCountById(SHIP_SPY);
64
-  if($spy_probes > 0) {
64
+  if ($spy_probes > 0) {
65 65
     $TargetSpyLvl = GetSpyLevel($target_user_row);
66 66
     $CurrentSpyLvl = GetSpyLevel($spying_user_row);
67 67
     $spy_diff_empire = $CurrentSpyLvl - $TargetSpyLvl;
@@ -85,19 +85,19 @@  discard block
 block discarded – undo
85 85
     $spy_message .= "<td width=220>{$lang['sys_deuterium']}</td><td width=220 align=right>" . pretty_number($target_planet_row['deuterium']) . "</td>";
86 86
     $spy_message .= "<td width=220>{$lang['sys_energy']}</td><td width=220 align=right>" . pretty_number($target_planet_row['energy_max']) . "</td>";
87 87
     $spy_message .= "</tr>";
88
-    if($spy_diff >= 2) {
88
+    if ($spy_diff >= 2) {
89 89
       $spy_message .= "<div class='spy_medium'>" . flt_spy_scan($target_planet_row, 'fleet', $lang['tech'][UNIT_SHIPS], $target_user_row) . "</div>";
90 90
       coe_compress_add_units(sn_get_groups('fleet'), $target_planet_row, $combat_pack[0]);
91 91
     }
92
-    if($spy_diff >= 3) {
92
+    if ($spy_diff >= 3) {
93 93
       $spy_message .= "<div class='spy_medium'>" . flt_spy_scan($target_planet_row, 'defense', $lang['tech'][UNIT_DEFENCE], $target_user_row) . "</div>";
94 94
       coe_compress_add_units(sn_get_groups('defense_active'), $target_planet_row, $combat_pack[0]);
95 95
     }
96
-    if($spy_diff >= 5) {
96
+    if ($spy_diff >= 5) {
97 97
       $spy_message .= "<div class='spy_long'>" . flt_spy_scan($target_planet_row, 'structures', $lang['tech'][UNIT_STRUCTURES], $target_user_row) . "</div>";
98 98
     }
99 99
 
100
-    if($spy_diff_empire >= 0) {
100
+    if ($spy_diff_empire >= 0) {
101 101
       $spy_message .= "<div class='spy_long'>" . flt_spy_scan($target_planet_row, 'tech', $lang['tech'][UNIT_TECHNOLOGIES], $target_user_row) . "</div>";
102 102
       coe_compress_add_units(array(TECH_WEAPON, TECH_SHIELD, TECH_ARMOR), $target_planet_row, $combat_pack[0], $target_user_row);
103 103
     }
@@ -106,13 +106,13 @@  discard block
 block discarded – undo
106 106
     $simulator_link = sn_ube_simulator_encode_replay($combat_pack, 'D');
107 107
 
108 108
     $target_unit_list = 0;
109
-    foreach(sn_get_groups('fleet') as $unit_id) {
109
+    foreach (sn_get_groups('fleet') as $unit_id) {
110 110
       $target_unit_list += max(0, mrc_get_level($target_user_row, $target_planet_row, $unit_id, false, true));
111 111
     }
112 112
 
113 113
     $spy_detected = $spy_probes * $target_unit_list / 4 * pow(2, $TargetSpyLvl - $CurrentSpyLvl);
114 114
 
115
-    if(mt_rand(0, 99) > $spy_detected) {
115
+    if (mt_rand(0, 99) > $spy_detected) {
116 116
       $spy_outcome_str = sprintf($lang['sys_mess_spy_detect_chance'], $spy_detected);
117 117
       $spy_detected = false;
118 118
     } else {
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
     $target_message = "{$lang['sys_mess_spy_ennemyfleet']} {$spying_planet_row['name']} " . uni_render_coordinates_href($spying_planet_row, '', 3);
133 133
     $target_message .= " {$lang['sys_mess_spy_seen_at']} {$target_planet_row['name']} " . uni_render_coordinates($target_planet_row);
134 134
 
135
-    if($spy_detected) {
135
+    if ($spy_detected) {
136 136
       $debris_planet_id = $target_planet_row['planet_type'] == PT_PLANET ? $target_planet_row['id'] : $target_planet_row['parent_planet'];
137 137
 
138 138
       $spy_cost = get_unit_param(SHIP_SPY, P_COST);
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
     msg_send_simple_message($objFleet->target_owner_id, '', $objFleet->time_arrive_to_target, MSG_TYPE_SPY, $lang['sys_mess_spy_control'], $lang['sys_mess_spy_activity'], $target_message);
150 150
   }
151 151
 
152
-  if($spy_detected) {
152
+  if ($spy_detected) {
153 153
     $objFleet->db_delete_this_fleet();
154 154
   } else {
155 155
     $objFleet->mark_fleet_as_returned_and_save();
Please login to merge, or discard this patch.
includes/includes/mrc_mercenary.php 3 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -26,6 +26,10 @@
 block discarded – undo
26 26
   return true;
27 27
 }
28 28
 
29
+/**
30
+ * @param integer $mode
31
+ * @param integer $mercenary_id
32
+ */
29 33
 function mrc_mercenary_hire($mode, $user, $mercenary_id) {
30 34
   global $config, $lang, $sn_powerup_buy_discounts;
31 35
 
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -62,8 +62,8 @@
 block discarded – undo
62 62
     if($mercenary_level) {
63 63
       $darkmater_cost = eco_get_total_cost($mercenary_id, $mercenary_level);
64 64
       if(!$config->empire_mercenary_temporary && $mercenary_level_old) {
65
-       $darkmater_cost_old = eco_get_total_cost($mercenary_id, $mercenary_level_old);
66
-       $darkmater_cost[BUILD_CREATE][RES_DARK_MATTER] -= $darkmater_cost_old[BUILD_CREATE][RES_DARK_MATTER];
65
+        $darkmater_cost_old = eco_get_total_cost($mercenary_id, $mercenary_level_old);
66
+        $darkmater_cost[BUILD_CREATE][RES_DARK_MATTER] -= $darkmater_cost_old[BUILD_CREATE][RES_DARK_MATTER];
67 67
       }
68 68
       $darkmater_cost = ceil($darkmater_cost[BUILD_CREATE][RES_DARK_MATTER] * $mercenary_period * $sn_powerup_buy_discounts[$mercenary_period] / $config->empire_mercenary_base_period);
69 69
     } else {
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -7,16 +7,16 @@  discard block
 block discarded – undo
7 7
   global $config;
8 8
 
9 9
   $mercenary_info = get_unit_param($mercenary_id);
10
-  if($config->empire_mercenary_temporary || $mercenary_info[P_UNIT_TYPE] == UNIT_PLANS)
10
+  if ($config->empire_mercenary_temporary || $mercenary_info[P_UNIT_TYPE] == UNIT_PLANS)
11 11
   {
12 12
     return true;
13 13
   }
14 14
 
15
-  if(isset($mercenary_info[P_REQUIRE]))
15
+  if (isset($mercenary_info[P_REQUIRE]))
16 16
   {
17
-    foreach($mercenary_info[P_REQUIRE] as $unit_id => $unit_level)
17
+    foreach ($mercenary_info[P_REQUIRE] as $unit_id => $unit_level)
18 18
     {
19
-      if(mrc_get_level($user, null, $unit_id) < $unit_level)
19
+      if (mrc_get_level($user, null, $unit_id) < $unit_level)
20 20
       {
21 21
         return false;
22 22
       }
@@ -33,35 +33,35 @@  discard block
 block discarded – undo
33 33
     $is_permanent = $mode == UNIT_PLANS || !$config->empire_mercenary_temporary;
34 34
     $cost_alliance_multiplyer = (SN_IN_ALLY === true && $mode == UNIT_PLANS ? $config->ali_bonus_members : 1);
35 35
     $cost_alliance_multiplyer = $cost_alliance_multiplyer >= 1 ? $cost_alliance_multiplyer : 1;
36
-    if(!in_array($mercenary_id, sn_get_groups($mode == UNIT_PLANS ? 'plans' : 'mercenaries'))) {
36
+    if (!in_array($mercenary_id, sn_get_groups($mode == UNIT_PLANS ? 'plans' : 'mercenaries'))) {
37 37
       throw new Exception($lang['mrc_msg_error_wrong_mercenary'], ERR_ERROR);
38 38
     }
39 39
 
40
-    if(!mrc_officer_accessible($user, $mercenary_id)) {
40
+    if (!mrc_officer_accessible($user, $mercenary_id)) {
41 41
       throw new Exception($lang['mrc_msg_error_requirements'], ERR_ERROR);
42 42
     }
43 43
 
44 44
     $mercenary_level = sys_get_param_int('mercenary_level');
45
-    if($mercenary_level < 0 || $mercenary_level > get_unit_param($mercenary_id, P_MAX_STACK)) {
45
+    if ($mercenary_level < 0 || $mercenary_level > get_unit_param($mercenary_id, P_MAX_STACK)) {
46 46
       throw new Exception($lang['mrc_msg_error_wrong_level'], ERR_ERROR);
47 47
     }
48 48
 
49
-    if($mercenary_level && !array_key_exists($mercenary_period = sys_get_param_int('mercenary_period'), $sn_powerup_buy_discounts)) {
49
+    if ($mercenary_level && !array_key_exists($mercenary_period = sys_get_param_int('mercenary_period'), $sn_powerup_buy_discounts)) {
50 50
       throw new Exception($lang['mrc_msg_error_wrong_period'], ERR_ERROR);
51 51
     }
52 52
 
53 53
     sn_db_transaction_start();
54 54
 
55 55
     $mercenary_level_old = mrc_get_level($user, $planetrow, $mercenary_id, true, true);
56
-    if($config->empire_mercenary_temporary && $mercenary_level_old && $mercenary_level) {
56
+    if ($config->empire_mercenary_temporary && $mercenary_level_old && $mercenary_level) {
57 57
       throw new Exception($lang['mrc_msg_error_already_hired'], ERR_ERROR); // Can't hire already hired temp mercenary - dismiss first
58
-    } elseif($config->empire_mercenary_temporary && !$mercenary_level_old && !$mercenary_level) {
58
+    } elseif ($config->empire_mercenary_temporary && !$mercenary_level_old && !$mercenary_level) {
59 59
       throw new Exception('', ERR_NONE); // Can't dismiss (!$mercenary_level) not hired (!$mercenary_level_old) temp mercenary. But no error
60 60
     }
61 61
 
62
-    if($mercenary_level) {
62
+    if ($mercenary_level) {
63 63
       $darkmater_cost = eco_get_total_cost($mercenary_id, $mercenary_level);
64
-      if(!$config->empire_mercenary_temporary && $mercenary_level_old) {
64
+      if (!$config->empire_mercenary_temporary && $mercenary_level_old) {
65 65
        $darkmater_cost_old = eco_get_total_cost($mercenary_id, $mercenary_level_old);
66 66
        $darkmater_cost[BUILD_CREATE][RES_DARK_MATTER] -= $darkmater_cost_old[BUILD_CREATE][RES_DARK_MATTER];
67 67
       }
@@ -71,13 +71,13 @@  discard block
 block discarded – undo
71 71
     }
72 72
     $darkmater_cost *= $cost_alliance_multiplyer;
73 73
 
74
-    if(mrc_get_level($user, null, RES_DARK_MATTER) < $darkmater_cost) {
74
+    if (mrc_get_level($user, null, RES_DARK_MATTER) < $darkmater_cost) {
75 75
       throw new Exception($lang['mrc_msg_error_no_resource'], ERR_ERROR);
76 76
     }
77 77
 
78
-    if(($darkmater_cost && $mercenary_level) || !$is_permanent) {
78
+    if (($darkmater_cost && $mercenary_level) || !$is_permanent) {
79 79
       $unit_row = db_unit_by_location($user['id'], LOC_USER, $user['id'], $mercenary_id);
80
-      if(is_array($unit_row) && ($dismiss_left_days = floor((strtotime($unit_row['unit_time_finish']) - SN_TIME_NOW) / PERIOD_DAY))) {
80
+      if (is_array($unit_row) && ($dismiss_left_days = floor((strtotime($unit_row['unit_time_finish']) - SN_TIME_NOW) / PERIOD_DAY))) {
81 81
         $dismiss_full_cost = eco_get_total_cost($mercenary_id, $unit_row['unit_level']);
82 82
         $dismiss_full_cost = $dismiss_full_cost[BUILD_CREATE][RES_DARK_MATTER];
83 83
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
       db_unit_list_delete($user['id'], LOC_USER, $user['id'], $mercenary_id);
96 96
     }
97 97
 
98
-    if($darkmater_cost && $mercenary_level) {
98
+    if ($darkmater_cost && $mercenary_level) {
99 99
       db_unit_set_insert(
100 100
         "unit_player_id = {$user['id']},
101 101
         unit_location_type = " . LOC_USER . ",
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
   $mode = in_array($mode, array(UNIT_MERCENARIES, UNIT_PLANS)) ? $mode : UNIT_MERCENARIES;
131 131
   $is_permanent = $mode == UNIT_PLANS || !$config->empire_mercenary_temporary;
132 132
 
133
-  if($mercenary_id = sys_get_param_int('mercenary_id'))
133
+  if ($mercenary_id = sys_get_param_int('mercenary_id'))
134 134
   {
135 135
     $operation_result = mrc_mercenary_hire($mode, $user, $mercenary_id);
136 136
   }
@@ -139,12 +139,12 @@  discard block
 block discarded – undo
139 139
 
140 140
   $template = gettemplate('mrc_mercenary_hire', true);
141 141
 
142
-  if(!empty($operation_result))
142
+  if (!empty($operation_result))
143 143
   {
144 144
     $template->assign_block_vars('result', $operation_result);
145 145
   }
146 146
 
147
-  foreach($sn_powerup_buy_discounts as $hire_period => $hire_discount)
147
+  foreach ($sn_powerup_buy_discounts as $hire_period => $hire_discount)
148 148
   {
149 149
     $template->assign_block_vars('period', array(
150 150
       'LENGTH'   => $hire_period,
@@ -157,13 +157,13 @@  discard block
 block discarded – undo
157 157
   $user_dark_matter = mrc_get_level($user, '', RES_DARK_MATTER);
158 158
   $cost_alliance_multiplyer = (SN_IN_ALLY === true && $mode == UNIT_PLANS ? $config->ali_bonus_members : 1);
159 159
   $cost_alliance_multiplyer = $cost_alliance_multiplyer >= 1 ? $cost_alliance_multiplyer : 1;
160
-  foreach(sn_get_groups($mode == UNIT_PLANS ? 'plans' : 'mercenaries') as $mercenary_id)
160
+  foreach (sn_get_groups($mode == UNIT_PLANS ? 'plans' : 'mercenaries') as $mercenary_id)
161 161
   {
162 162
     {
163 163
       $mercenary = get_unit_param($mercenary_id);
164 164
       $mercenary_bonus = $mercenary['bonus'];
165 165
       $mercenary_bonus = $mercenary_bonus >= 0 ? "+{$mercenary_bonus}" : "{$mercenary_bonus}";
166
-      switch($mercenary['bonus_type'])
166
+      switch ($mercenary['bonus_type'])
167 167
       {
168 168
         case BONUS_PERCENT:
169 169
           $mercenary_bonus = "{$mercenary_bonus}% ";
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
       $mercenary_level = mrc_get_level($user, null, $mercenary_id, false, true);
182 182
       $mercenary_level_bonus = max(0, mrc_get_level($user, null, $mercenary_id) - $mercenary_level);
183 183
       $total_cost_old = 0;
184
-      if($is_permanent)
184
+      if ($is_permanent)
185 185
       {
186 186
         $total_cost_old = eco_get_total_cost($mercenary_id, $mercenary_level);
187 187
         $total_cost_old = $total_cost_old[BUILD_CREATE][RES_DARK_MATTER] * $cost_alliance_multiplyer;
@@ -205,13 +205,13 @@  discard block
 block discarded – undo
205 205
         'BONUS_TYPE'  => $mercenary['bonus_type'],
206 206
         'HIRE_END'    => $mercenary_time_finish && $mercenary_time_finish >= SN_TIME_NOW ? date(FMT_DATE_TIME, $mercenary_time_finish) : '',
207 207
         'HIRE_LEFT_PERCENT'    => $mercenary_time_finish && $mercenary_time_finish >= SN_TIME_NOW
208
-          ? round(($mercenary_time_finish - SN_TIME_NOW)/($mercenary_time_finish - $mercenary_time_start) * 100, 1)
208
+          ? round(($mercenary_time_finish - SN_TIME_NOW) / ($mercenary_time_finish - $mercenary_time_start) * 100, 1)
209 209
           : 0,
210 210
         'CAN_BUY'     => mrc_officer_accessible($user, $mercenary_id),
211 211
       ));
212 212
 
213 213
       $upgrade_cost = 1;
214
-      for($i = $config->empire_mercenary_temporary ? 1 : $mercenary_level + 1; $mercenary['max'] ? ($i <= $mercenary['max']) : $upgrade_cost <= $user_dark_matter; $i++)
214
+      for ($i = $config->empire_mercenary_temporary ? 1 : $mercenary_level + 1; $mercenary['max'] ? ($i <= $mercenary['max']) : $upgrade_cost <= $user_dark_matter; $i++)
215 215
       {
216 216
         $total_cost = eco_get_total_cost($mercenary_id, $i);
217 217
         $total_cost[BUILD_CREATE][RES_DARK_MATTER] *= $cost_alliance_multiplyer;
Please login to merge, or discard this patch.
resources.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -46,11 +46,11 @@  discard block
 block discarded – undo
46 46
   ));
47 47
 };
48 48
 
49
-$ValidList['percent'] = array (  0,  10,  20,  30,  40,  50,  60,  70,  80,  90, 100 );
49
+$ValidList['percent'] = array(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100);
50 50
 $template = gettemplate('resources', true);
51 51
 
52 52
 $transmutation_result = sn_sys_planet_core_transmute($user, $planetrow);
53
-if(!empty($transmutation_result))
53
+if (!empty($transmutation_result))
54 54
 {
55 55
   $template->assign_block_vars('result', $transmutation_result); // array('STATUS' => $transmutation_result['STATUS'], 'MESSAGE' => $transmutation_result['MESSAGE']));
56 56
 }
@@ -59,20 +59,20 @@  discard block
 block discarded – undo
59 59
 $production = $_POST['production'];
60 60
 //$SubQry     = '';
61 61
 $SubQry     = array();
62
-if(is_array($production)) {
63
-  foreach($production as $prod_id => $percent) {
64
-    if($percent > 100 || $percent < 0) {
62
+if (is_array($production)) {
63
+  foreach ($production as $prod_id => $percent) {
64
+    if ($percent > 100 || $percent < 0) {
65 65
       $debug->warning('Supplying wrong production percent (less then 0 or greater then 100)', 'Hack attempt', 302, array('base_dump' => true));
66 66
       die();
67 67
     }
68 68
 
69 69
     $prod_id = intval($prod_id);
70
-    if(in_array($prod_id, $sn_group_factories) && get_unit_param($prod_id, P_MINING_IS_MANAGED)) {
70
+    if (in_array($prod_id, $sn_group_factories) && get_unit_param($prod_id, P_MINING_IS_MANAGED)) {
71 71
       $field_name              = pname_factory_production_field_name($prod_id);
72 72
       $percent                 = floor($percent / 10);
73 73
       $planetrow[$field_name]  = $percent;
74 74
       //$SubQry                 .= "`{$field_name}` = '{$percent}',";
75
-      $SubQry[]                 = "`{$field_name}` = '{$percent}'";
75
+      $SubQry[] = "`{$field_name}` = '{$percent}'";
76 76
     } else {
77 77
       $debug->warning('Supplying wrong ID in production array - attempt to change some field - ID' . $prod_id, 'Resource Page', 301);
78 78
       continue;
@@ -108,9 +108,9 @@  discard block
 block discarded – undo
108 108
   'ENERGY_TYPE'    => pretty_number($caps_real['production'][RES_ENERGY][0], true, true),
109 109
 ));
110 110
 
111
-foreach($sn_group_factories as $unit_id)
111
+foreach ($sn_group_factories as $unit_id)
112 112
 {
113
-  if(mrc_get_level($user, $planetrow, $unit_id) > 0 && get_unit_param($unit_id))
113
+  if (mrc_get_level($user, $planetrow, $unit_id) > 0 && get_unit_param($unit_id))
114 114
   {
115 115
     $level_plain = mrc_get_level($user, $planetrow, $unit_id, false, true);
116 116
     $template->assign_block_vars('production', array(
Please login to merge, or discard this patch.
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -92,9 +92,9 @@  discard block
 block discarded – undo
92 92
 
93 93
 for ($Option = 10; $Option >= 0; $Option--)
94 94
 {
95
- $template->assign_block_vars('option', array(
96
-   'VALUE' => $Option * 10,
97
- ));
95
+  $template->assign_block_vars('option', array(
96
+    'VALUE' => $Option * 10,
97
+  ));
98 98
 }
99 99
 
100 100
 $caps_real = eco_get_planet_caps($user, $planetrow, 3600);
@@ -163,14 +163,14 @@  discard block
 block discarded – undo
163 163
 int_calc_storage_bar(RES_DEUTERIUM);
164 164
 
165 165
 $template->assign_vars(array(
166
- 'PLANET_NAME'          => $planetrow['name'],
167
- 'PLANET_TYPE'          => $planetrow['planet_type'],
168
- 'PLANET_DENSITY_INDEX' => $planet_density_index,
169
- 'PLANET_CORE_TEXT'     => classLocale::$lang['uni_planet_density_types'][$planet_density_index],
166
+  'PLANET_NAME'          => $planetrow['name'],
167
+  'PLANET_TYPE'          => $planetrow['planet_type'],
168
+  'PLANET_DENSITY_INDEX' => $planet_density_index,
169
+  'PLANET_CORE_TEXT'     => classLocale::$lang['uni_planet_density_types'][$planet_density_index],
170 170
 
171
- 'PRODUCTION_LEVEL'     => floor($caps_real['efficiency'] * 100),
171
+  'PRODUCTION_LEVEL'     => floor($caps_real['efficiency'] * 100),
172 172
 
173
- 'PAGE_HINT'            => classLocale::$lang['res_hint'],
173
+  'PAGE_HINT'            => classLocale::$lang['res_hint'],
174 174
 ));
175 175
 
176 176
 display($template, classLocale::$lang['res_planet_production']);
Please login to merge, or discard this patch.
admin/adm_user_analyze.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,8 +39,8 @@
 block discarded – undo
39 39
     0 => $row['visit_time'], // start
40 40
     1 => $row['visit_time'], // end
41 41
   )
42
-   //: false
43
-   ;
42
+    //: false
43
+    ;
44 44
 }
45 45
 
46 46
 $session_list = array();
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -12,20 +12,20 @@  discard block
 block discarded – undo
12 12
 
13 13
 require('../common.' . substr(strrchr(__FILE__, '.'), 1));
14 14
 
15
-if($user['authlevel'] < 3) {
15
+if ($user['authlevel'] < 3) {
16 16
   AdminMessage($lang['adm_err_denied']);
17 17
 }
18 18
 
19 19
 // define('SESSION_INTERRUPT', 15*60); // Можно увеличить до 4 часов - никито не может сидеть 2 суток с перерывом менее 4 часов
20 20
 // define('SUSPICIOUS_LONG', 2 * 60*60); // Тогда это увеличиваем до, скажем суток - и там смотрим
21 21
 
22
-define('SESSION_INTERRUPT', 1 * 60*60); // Можно увеличить до 4 часов - никито не может сидеть 2 суток с перерывом менее 4 часов
23
-define('SUSPICIOUS_LONG', 16 * 60*60); // Тогда это увеличиваем до, скажем суток - и там смотрим
22
+define('SESSION_INTERRUPT', 1 * 60 * 60); // Можно увеличить до 4 часов - никито не может сидеть 2 суток с перерывом менее 4 часов
23
+define('SUSPICIOUS_LONG', 16 * 60 * 60); // Тогда это увеличиваем до, скажем суток - и там смотрим
24 24
 
25 25
 
26 26
 function check_suspicious(&$session, &$session_list_last_id, &$row) {
27 27
   $session[2] = $session[1] - $session[0];
28
-  if($session[2] > SUSPICIOUS_LONG)
28
+  if ($session[2] > SUSPICIOUS_LONG)
29 29
   {
30 30
     $session[2] = pretty_time($session[2]);
31 31
     $session[0] = date(FMT_DATE_TIME_SQL, $session[0]);
@@ -46,24 +46,24 @@  discard block
 block discarded – undo
46 46
 $session_list = array();
47 47
 $query = doquery("SELECT `visit_time`, user_id FROM {{counter}} where user_id <> 0 and visit_time > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY)) order by user_id, visit_time;");
48 48
 $session = array();
49
-if($row = db_fetch($query)) {
49
+if ($row = db_fetch($query)) {
50 50
   $session = array(
51 51
     0 => strtotime($row['visit_time']), // start
52 52
     1 => strtotime($row['visit_time']), // end
53 53
   );
54 54
   $last_id = $row['user_id'];
55 55
 }
56
-while($row = db_fetch($query)) {
56
+while ($row = db_fetch($query)) {
57 57
   $row['visit_time'] = strtotime($row['visit_time']);
58
-  if($last_id == $row['user_id']) {
58
+  if ($last_id == $row['user_id']) {
59 59
     // Тот же юзер
60
-    if($row['visit_time'] - $session[1] <= SESSION_INTERRUPT) { // Та же сессия
60
+    if ($row['visit_time'] - $session[1] <= SESSION_INTERRUPT) { // Та же сессия
61 61
       $session[1] = $row['visit_time'];
62 62
     } else {
63 63
       // Новая сессия
64 64
 //      check_suspicious($session, $session_list[$last_id], $row);
65 65
       $session[2] = $session[1] - $session[0];
66
-      if($session[2] > SUSPICIOUS_LONG)
66
+      if ($session[2] > SUSPICIOUS_LONG)
67 67
       {
68 68
         $session[2] = pretty_time($session[2]);
69 69
         $session[0] = date(FMT_DATE_TIME_SQL, $session[0]);
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
   } else {
79 79
 //    check_suspicious($session, $session_list[$last_id], $row);
80 80
     $session[2] = $session[1] - $session[0];
81
-      if($session[2] > SUSPICIOUS_LONG)
81
+      if ($session[2] > SUSPICIOUS_LONG)
82 82
       {
83 83
         $session[2] = pretty_time($session[2]);
84 84
         $session[0] = date(FMT_DATE_TIME_SQL, $session[0]);
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
   }
94 94
 }
95 95
 
96
-if($last_id) {
96
+if ($last_id) {
97 97
   // check_suspicious($session, $session_list[$last_id], $row = array('time' => 0));
98 98
   $session[2] = $session[1] - $session[0];
99 99
 
100
-  if($session[2] > SUSPICIOUS_LONG)
100
+  if ($session[2] > SUSPICIOUS_LONG)
101 101
   {
102 102
     $session[2] = pretty_time($session[2]);
103 103
     $session[0] = date(FMT_DATE_TIME_SQL, $session[0]);
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 print("<td>ID</td><td>Username</td><td>Start</td><td>End</td><td>Length</td>");
112 112
 print("<td>Last online</td>");
113 113
 print("</tr>");
114
-foreach($session_list as $user_id => $value) {
114
+foreach ($session_list as $user_id => $value) {
115 115
   $user_record = doquery("SELECT `username`, onlinetime FROM {{users}} WHERE id = {$user_id};", true);
116
-  foreach($value as $interval_data) {
116
+  foreach ($value as $interval_data) {
117 117
     print("<tr>");
118 118
     print("<td>{$user_id}</td><td>{$user_record['username']}</td><td>{$interval_data[0]}</td><td>{$interval_data[1]}</td><td>{$interval_data[2]}</td>");
119 119
     print("<td>" . date(FMT_DATE_TIME_SQL, $user_record['onlinetime']) . "</td>");
Please login to merge, or discard this patch.
admin/banned.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
 $action = sys_get_param_str('action');
28 28
 
29 29
 $player_banned_row = db_user_by_username($name_unsafe);
30
-if($mode == 'banit' && $action)
30
+if ($mode == 'banit' && $action)
31 31
 {
32
-  if($player_banned_row)
32
+  if ($player_banned_row)
33 33
   {
34 34
     $reas = $_POST['why'];
35 35
     $days = $_POST['days'];
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 
49 49
     $DoneMessage = "{$lang['adm_bn_thpl']} {$name_output} {$lang['adm_bn_isbn']}";
50 50
 
51
-    if($is_vacation)
51
+    if ($is_vacation)
52 52
     {
53 53
       $DoneMessage .= $lang['adm_bn_vctn'];
54 54
     }
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 
63 63
   AdminMessage($DoneMessage, $lang['adm_ban_title']);
64 64
 }
65
-elseif($mode == 'unbanit' && $action)
65
+elseif ($mode == 'unbanit' && $action)
66 66
 {
67 67
   sys_admin_player_ban_unset($user, $player_banned_row, ($reason = sys_get_param_str('why')) ? $reason : $lang['sys_unbanned']);
68 68
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -54,15 +54,13 @@
 block discarded – undo
54 54
     }
55 55
 
56 56
     $DoneMessage .= $lang['adm_bn_plnt'];
57
-  }
58
-  else
57
+  } else
59 58
   {
60 59
     $DoneMessage = sprintf($lang['adm_bn_errr'], $name_output);
61 60
   }
62 61
 
63 62
   AdminMessage($DoneMessage, $lang['adm_ban_title']);
64
-}
65
-elseif($mode == 'unbanit' && $action)
63
+} elseif($mode == 'unbanit' && $action)
66 64
 {
67 65
   sys_admin_player_ban_unset($user, $player_banned_row, ($reason = sys_get_param_str('why')) ? $reason : $lang['sys_unbanned']);
68 66
 
Please login to merge, or discard this patch.
admin/add_moon.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,14 +14,14 @@
 block discarded – undo
14 14
 require('../common.' . substr(strrchr(__FILE__, '.'), 1));
15 15
 
16 16
 // if ($user['authlevel'] < 2)
17
-if($user['authlevel'] < 3)
17
+if ($user['authlevel'] < 3)
18 18
 {
19 19
   AdminMessage($lang['adm_err_denied']);
20 20
 }
21 21
 
22 22
 $template = gettemplate("admin/add_moon", true);
23 23
 
24
-if(sys_get_param_str('mode') == 'addit')
24
+if (sys_get_param_str('mode') == 'addit')
25 25
 {
26 26
   $PlanetID = sys_get_param_id('user');
27 27
   $MoonName = sys_get_param_str('name');
Please login to merge, or discard this patch.