Completed
Push — trunk ( c8f413...ad61f6 )
by SuperNova.WS
04:45
created
admin/planet_edit.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -20,30 +20,30 @@
 block discarded – undo
20 20
 $planet_id = sys_get_param_id('planet_id');
21 21
 
22 22
 $unit_list = sys_get_param('unit_list');
23
-if(sys_get_param('change_data') && !empty($unit_list))
23
+if (sys_get_param('change_data') && !empty($unit_list))
24 24
 {
25 25
   $query_string = array();
26
-  foreach($unit_list as $unit_id => $unit_amount)
26
+  foreach ($unit_list as $unit_id => $unit_amount)
27 27
   {
28
-    if($unit_query_string = admin_planet_edit_query_string($unit_id, $unit_amount, $mode))
28
+    if ($unit_query_string = admin_planet_edit_query_string($unit_id, $unit_amount, $mode))
29 29
     {
30 30
       $query_string[] = $unit_query_string;
31 31
     }
32 32
   }
33 33
 
34
-  if(!empty($query_string))
34
+  if (!empty($query_string))
35 35
   {
36 36
     DBStaticPlanet::db_planet_set_by_id($planet_id, implode(', ', $query_string));
37 37
   }
38 38
 }
39 39
 
40
-if($planet_id)
40
+if ($planet_id)
41 41
 {
42 42
   $edit_planet_row = DBStaticPlanet::db_planet_by_id($planet_id);
43 43
   admin_planet_edit_template($template, $edit_planet_row, $mode);
44 44
 }
45 45
 
46
-foreach($admin_planet_edit_mode_list as $page_mode => $mode_locale)
46
+foreach ($admin_planet_edit_mode_list as $page_mode => $mode_locale)
47 47
 {
48 48
   $template->assign_block_vars('page_menu', array(
49 49
     'ID' => $page_mode,
Please login to merge, or discard this patch.
admin/add_moon.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
 
20 20
 $template = gettemplate("admin/add_moon", true);
21 21
 
22
-if(sys_get_param_str('mode') == 'addit')
22
+if (sys_get_param_str('mode') == 'addit')
23 23
 {
24 24
   $PlanetID = sys_get_param_id('user');
25 25
   $MoonName = sys_get_param_str('name');
Please login to merge, or discard this patch.
admin/adm_flying_fleets.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 //while($CurrentFleet = db_fetch($FlyingFleets))
22 22
 
23 23
 $all_flying_fleets = db_fleet_list('', DB_SELECT_PLAIN);
24
-foreach($all_flying_fleets as $fleet_id => $CurrentFleet) {
24
+foreach ($all_flying_fleets as $fleet_id => $CurrentFleet) {
25 25
   $FleetOwner = db_user_by_id($CurrentFleet['fleet_owner']);
26 26
   $TargetOwner = db_user_by_id($CurrentFleet['fleet_target_owner']);
27 27
 
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
   $fleet_data['fleet']['STAY_TIME_INT'] = $CurrentFleet['fleet_end_stay'];
33 33
 
34 34
   $template->assign_block_vars('fleets', $fleet_data['fleet']);
35
-  foreach($fleet_data['ships'] as $ship_data) {
35
+  foreach ($fleet_data['ships'] as $ship_data) {
36 36
     $template->assign_block_vars('fleets.ships', $ship_data);
37 37
   }
38 38
 }
Please login to merge, or discard this patch.
includes/pages/admin/user_view.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -186,11 +186,11 @@
 block discarded – undo
186 186
   }
187 187
 
188 188
   $exclude = $user_row;
189
-  foreach($blocks as $title => $fields) {
189
+  foreach ($blocks as $title => $fields) {
190 190
     userBlockAssign($exclude, $template, $title, $fields);
191 191
   }
192 192
 
193
-  if(!empty($exclude)) {
193
+  if (!empty($exclude)) {
194 194
     userBlockAssign($exclude, $template, '!!! НЕИЗВЕСТНЫЕ ПАРАМЕТРЫ !!!', array_keys($exclude));
195 195
   }
196 196
 
Please login to merge, or discard this patch.
includes/db.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @copyright 2008-2015 Gorlum for Project "SuperNova.WS"
6 6
  */
7 7
 
8
-if(!defined('INSIDE')) {
8
+if (!defined('INSIDE')) {
9 9
   die();
10 10
 }
11 11
 
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 
14 14
 function db_change_units_perform($query, $tablename, $object_id) {
15 15
   $query = implode(',', $query);
16
-  if($query && $object_id) {
16
+  if ($query && $object_id) {
17 17
     return classSupernova::db_upd_record_by_id($tablename == 'users' ? LOC_USER : LOC_PLANET, $object_id, $query);
18 18
   }
19 19
 }
@@ -29,15 +29,15 @@  discard block
 block discarded – undo
29 29
 
30 30
   $group = sn_get_groups('resources_loot');
31 31
 
32
-  foreach($unit_list as $unit_id => $unit_amount) {
33
-    if(!in_array($unit_id, $group)) {
32
+  foreach ($unit_list as $unit_id => $unit_amount) {
33
+    if (!in_array($unit_id, $group)) {
34 34
       // TODO - remove later
35 35
       print('<h1>СООБЩИТЕ ЭТО АДМИНУ: db_change_units() вызван для не-ресурсов!</h1>');
36 36
       pdump(debug_backtrace());
37 37
       die('db_change_units() вызван для не-ресурсов!');
38 38
     }
39 39
 
40
-    if(!$unit_amount) {
40
+    if (!$unit_amount) {
41 41
       continue;
42 42
     }
43 43
 
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
     $unit_location = sys_get_unit_location($user, $planet, $unit_id);
47 47
 
48 48
     // Changing value in object
49
-    switch($unit_location) {
49
+    switch ($unit_location) {
50 50
       case LOC_USER:
51 51
         $user[$unit_db_name] += $unit_amount;
52 52
         break;
Please login to merge, or discard this patch.
includes/alliance/ali_internal_admin_mail.inc 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 global $lang;
4 4
 
5
-if(!defined('SN_IN_ALLY') || SN_IN_ALLY !== true)
5
+if (!defined('SN_IN_ALLY') || SN_IN_ALLY !== true)
6 6
 {
7 7
   $debug->error("Attempt to call ALLIANCE page mode {$mode} directly - not from alliance.php", 'Forbidden', 403);
8 8
 }
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 $page = gettemplate('ali_admin_mail', true);
21 21
 
22 22
 if ($ranks) {
23
-  foreach($ranks as $id => $array) {
23
+  foreach ($ranks as $id => $array) {
24 24
     $page->assign_block_vars('ranks', array(
25 25
       'NAME' => $array['name'],
26 26
       'VALUE' => $id,
Please login to merge, or discard this patch.
includes/includes/ube_attack_calculate.php 2 patches
Braces   +45 added lines, -70 removed lines patch added patch discarded remove patch
@@ -79,8 +79,7 @@  discard block
 block discarded – undo
79 79
 
80 80
 // ------------------------------------------------------------------------------------------------
81 81
 // Заполняет данные по игроку
82
-function ube_attack_prepare_player(&$combat_data, $player_id, $is_attacker)
83
-{
82
+function ube_attack_prepare_player(&$combat_data, $player_id, $is_attacker) {
84 83
   global $ube_convert_techs;
85 84
 
86 85
   if(!isset($combat_data[UBE_PLAYERS][$player_id]))
@@ -99,8 +98,7 @@  discard block
 block discarded – undo
99 98
     {
100 99
       $player_info[UBE_BONUSES][$ube_id] += mrc_get_level($player_data, false, $unit_id) * get_unit_param($unit_id, P_BONUS_VALUE) / 100 + $admiral_bonus;
101 100
     }
102
-  }
103
-  else
101
+  } else
104 102
   {
105 103
     $combat_data[UBE_PLAYERS][$player_id][UBE_ATTACKER] = $combat_data[UBE_PLAYERS][$player_id][UBE_ATTACKER] || $is_attacker;
106 104
   }
@@ -109,8 +107,7 @@  discard block
 block discarded – undo
109 107
 // ------------------------------------------------------------------------------------------------
110 108
 // Заполняет данные по флоту
111 109
 function ube_attack_prepare_fleet(&$combat_data, &$fleet, $is_attacker){return sn_function_call('ube_attack_prepare_fleet', array(&$combat_data, &$fleet, $is_attacker));}
112
-function sn_ube_attack_prepare_fleet(&$combat_data, &$fleet, $is_attacker)
113
-{
110
+function sn_ube_attack_prepare_fleet(&$combat_data, &$fleet, $is_attacker) {
114 111
   $fleet_owner_id = $fleet['fleet_owner'];
115 112
   $fleet_id = $fleet['fleet_id'];
116 113
 
@@ -257,8 +254,7 @@  discard block
 block discarded – undo
257 254
     foreach($acs_fleet_list as $fleet) {
258 255
       ube_attack_prepare_fleet($combat_data, $fleet, true);
259 256
     }
260
-  }
261
-  else
257
+  } else
262 258
   {
263 259
     ube_attack_prepare_fleet($combat_data, $fleet_row, true);
264 260
   }
@@ -273,8 +269,7 @@  discard block
 block discarded – undo
273 269
 }
274 270
 
275 271
 // ------------------------------------------------------------------------------------------------
276
-function sn_ube_combat_prepare_first_round(&$combat_data)
277
-{
272
+function sn_ube_combat_prepare_first_round(&$combat_data) {
278 273
   global $ube_combat_bonus_list, $ube_convert_to_techs;
279 274
 
280 275
   // Готовим информацию для первого раунда - проводим все нужные вычисления из исходных данных
@@ -339,8 +334,7 @@  discard block
 block discarded – undo
339 334
 
340 335
 // ------------------------------------------------------------------------------------------------
341 336
 // Вычисление дополнительной информации для расчета раунда
342
-function sn_ube_combat_round_prepare(&$combat_data, $round)
343
-{
337
+function sn_ube_combat_round_prepare(&$combat_data, $round) {
344 338
   global $ube_combat_bonus_list;
345 339
 
346 340
   $is_simulator = $combat_data[UBE_OPTIONS][UBE_SIMULATOR];
@@ -401,8 +395,7 @@  discard block
 block discarded – undo
401 395
 
402 396
 // ------------------------------------------------------------------------------------------------
403 397
 // Рассчитывает результат столкновения флотов ака раунд
404
-function sn_ube_combat_round_crossfire_fleet(&$combat_data, $round)
405
-{
398
+function sn_ube_combat_round_crossfire_fleet(&$combat_data, $round) {
406 399
   if(BE_DEBUG === true)
407 400
   {
408 401
     // sn_ube_combat_helper_round_header($round);
@@ -437,8 +430,7 @@  discard block
 block discarded – undo
437 430
 
438 431
 // ------------------------------------------------------------------------------------------------
439 432
 // Рассчитывает результат столкновения двух юнитов ака ход
440
-function sn_ube_combat_round_crossfire_unit(&$attack_fleet_data, &$defend_fleet_data, $attack_unit_id, $defend_unit_id, &$combat_options)
441
-{
433
+function sn_ube_combat_round_crossfire_unit(&$attack_fleet_data, &$defend_fleet_data, $attack_unit_id, $defend_unit_id, &$combat_options) {
442 434
   $attack_fleet_info = &$attack_fleet_data[UBE_FLEET_INFO];
443 435
   $defend_fleet_info = &$defend_fleet_data[UBE_FLEET_INFO];
444 436
   $defend_unit_armor = $defend_fleet_info[UBE_ARMOR][$defend_unit_id];
@@ -518,8 +510,7 @@  discard block
 block discarded – undo
518 510
   }
519 511
 }
520 512
 
521
-function sn_ube_combat_round_crossfire_unit_damage_current(&$defend_fleet_data, $defend_unit_id, &$amplified_damage, &$units_lost, &$units_boomed, &$combat_options)
522
-{
513
+function sn_ube_combat_round_crossfire_unit_damage_current(&$defend_fleet_data, $defend_unit_id, &$amplified_damage, &$units_lost, &$units_boomed, &$combat_options) {
523 514
   $unit_is_lost = false;
524 515
 
525 516
   $units_boomed = $units_boomed ? $units_boomed : 0;
@@ -580,8 +571,7 @@  discard block
 block discarded – undo
580 571
 
581 572
 // ------------------------------------------------------------------------------------------------
582 573
 // Рассчитывает результат столкновения двух юнитов ака ход
583
-function sn_ube_combat_round_crossfire_unit2(&$attack_fleet_data, &$defend_fleet_data, $attack_unit_id, $defend_unit_id, &$combat_options)
584
-{
574
+function sn_ube_combat_round_crossfire_unit2(&$attack_fleet_data, &$defend_fleet_data, $attack_unit_id, $defend_unit_id, &$combat_options) {
585 575
   if($defend_fleet_data[UBE_COUNT][$defend_unit_id] <= 0)
586 576
   {
587 577
     return;
@@ -618,8 +608,7 @@  discard block
 block discarded – undo
618 608
 
619 609
 // ------------------------------------------------------------------------------------------------
620 610
 // Анализирует результаты раунда и генерирует данные для следующего раунда
621
-function sn_ube_combat_round_analyze(&$combat_data, $round)
622
-{
611
+function sn_ube_combat_round_analyze(&$combat_data, $round) {
623 612
   $round_data = &$combat_data[UBE_ROUNDS][$round];
624 613
   $round_data[UBE_OUTCOME] = UBE_COMBAT_RESULT_DRAW;
625 614
 
@@ -649,12 +638,10 @@  discard block
 block discarded – undo
649 638
   if(count($outcome) == 0 || $round == 10)
650 639
   {
651 640
     $round_data[UBE_OUTCOME] = UBE_COMBAT_RESULT_DRAW_END;
652
-  }
653
-  elseif(count($outcome) == 1)
641
+  } elseif(count($outcome) == 1)
654 642
   {
655 643
     $round_data[UBE_OUTCOME] = isset($outcome[UBE_ATTACKERS]) ? UBE_COMBAT_RESULT_WIN : UBE_COMBAT_RESULT_LOSS;
656
-  }
657
-  elseif(count($outcome) == 2)
644
+  } elseif(count($outcome) == 2)
658 645
   {
659 646
     if($round < 10)
660 647
     {
@@ -667,8 +654,7 @@  discard block
 block discarded – undo
667 654
 
668 655
 // ------------------------------------------------------------------------------------------------
669 656
 // Общий алгоритм расчета боя
670
-function sn_ube_combat(&$combat_data)
671
-{
657
+function sn_ube_combat(&$combat_data) {
672 658
   // TODO: Сделать атаку по типам,  когда они будут
673 659
 
674 660
   $start = microtime(true);
@@ -696,8 +682,7 @@  discard block
 block discarded – undo
696 682
 
697 683
 // ------------------------------------------------------------------------------------------------
698 684
 // Разбирает данные боя для генерации отчета
699
-function sn_ube_combat_analyze(&$combat_data)
700
-{
685
+function sn_ube_combat_analyze(&$combat_data) {
701 686
   global $config;
702 687
 
703 688
 //  $combat_data[UBE_OUTCOME] = array();
@@ -742,14 +727,12 @@  discard block
 block discarded – undo
742 727
         if($combat_data[UBE_OPTIONS][UBE_SIMULATOR])
743 728
         { // for simulation just return 75% of loss
744 729
           $units_giveback = round($units_lost * $giveback_chance / 100);
745
-        }
746
-        else
730
+        } else
747 731
         {
748 732
           if($unit_count > 10)
749 733
           { // if there were more then 10 defense elements - mass-calculating giveback
750 734
             $units_giveback = round($units_lost * mt_rand($giveback_chance * 0.8, $giveback_chance * 1.2) / 100);
751
-          }
752
-          else
735
+          } else
753 736
           { //if there were less then 10 defense elements - calculating giveback per element
754 737
             $units_giveback = 0;
755 738
             for($i = 1; $i <= $units_lost; $i++)
@@ -852,8 +835,7 @@  discard block
 block discarded – undo
852 835
     if($combat_data[UBE_OPTIONS][UBE_MOON_WAS])
853 836
     {
854 837
       $outcome[UBE_MOON] = UBE_MOON_WAS;
855
-    }
856
-    else
838
+    } else
857 839
     {
858 840
       sn_ube_combat_analyze_moon($outcome, $combat_data[UBE_OPTIONS][UBE_SIMULATOR]);
859 841
     }
@@ -872,8 +854,7 @@  discard block
 block discarded – undo
872 854
 }
873 855
 
874 856
 // ------------------------------------------------------------------------------------------------
875
-function sn_ube_combat_analyze_loot(&$combat_data)
876
-{
857
+function sn_ube_combat_analyze_loot(&$combat_data) {
877 858
   $exchange = &$combat_data[UBE_OPTIONS][UBE_EXCHANGE];
878 859
   $planet_resource_list = &$combat_data[UBE_FLEETS][0][UBE_RESOURCES];
879 860
   $outcome = &$combat_data[UBE_OUTCOME];
@@ -916,13 +897,14 @@  discard block
 block discarded – undo
916 897
 }
917 898
 
918 899
 // ------------------------------------------------------------------------------------------------
919
-function sn_ube_combat_analyze_moon(&$outcome, $is_simulator)
920
-{
900
+function sn_ube_combat_analyze_moon(&$outcome, $is_simulator) {
921 901
   $outcome[UBE_DEBRIS_TOTAL] = 0;
922
-  foreach(array(RES_METAL, RES_CRYSTAL) as $resource_id) // TODO via array
902
+  foreach(array(RES_METAL, RES_CRYSTAL) as $resource_id) {
903
+    // TODO via array
923 904
   {
924 905
     $outcome[UBE_DEBRIS_TOTAL] += $outcome[UBE_DEBRIS][$resource_id];
925 906
   }
907
+  }
926 908
 
927 909
   if($outcome[UBE_DEBRIS_TOTAL])
928 910
   {
@@ -941,35 +923,33 @@  discard block
 block discarded – undo
941 923
         {
942 924
           $outcome[UBE_DEBRIS_TOTAL] = 0;
943 925
           $outcome[UBE_DEBRIS] = array();
944
-        }
945
-        else
926
+        } else
946 927
         {
947 928
           $moon_debris_spent = 30000000;
948 929
           $moon_debris_left_percent = ($outcome[UBE_DEBRIS_TOTAL] - $moon_debris_spent) / $outcome[UBE_DEBRIS_TOTAL];
949 930
 
950 931
           $outcome[UBE_DEBRIS_TOTAL] = 0;
951
-          foreach(array(RES_METAL, RES_CRYSTAL) as $resource_id) // TODO via array
932
+          foreach(array(RES_METAL, RES_CRYSTAL) as $resource_id) {
933
+            // TODO via array
952 934
           {
953 935
             $outcome[UBE_DEBRIS][$resource_id] = floor($outcome[UBE_DEBRIS][$resource_id] * $moon_debris_left_percent);
936
+          }
954 937
             $outcome[UBE_DEBRIS_TOTAL] += $outcome[UBE_DEBRIS][$resource_id];
955 938
           }
956 939
         }
957
-      }
958
-      else
940
+      } else
959 941
       {
960 942
         $outcome[UBE_MOON] = UBE_MOON_CREATE_FAILED;
961 943
       }
962 944
     }
963
-  }
964
-  else
945
+  } else
965 946
   {
966 947
     $outcome[UBE_MOON] = UBE_MOON_NONE;
967 948
   }
968 949
 }
969 950
 
970 951
 // ------------------------------------------------------------------------------------------------
971
-function sn_ube_combat_analyze_moon_destroy(&$combat_data)
972
-{
952
+function sn_ube_combat_analyze_moon_destroy(&$combat_data) {
973 953
   // TODO: $is_simulator
974 954
   $reapers = 0;
975 955
   foreach($combat_data[UBE_ROUNDS][count($combat_data[UBE_ROUNDS])-1][UBE_FLEETS] as $fleet_data)
@@ -993,8 +973,7 @@  discard block
 block discarded – undo
993 973
     $combat_data[UBE_OUTCOME][UBE_MOON] = $random <= $combat_data[UBE_OUTCOME][UBE_MOON_DESTROY_CHANCE] ? UBE_MOON_DESTROY_SUCCESS : UBE_MOON_DESTROY_FAILED;
994 974
     $random = mt_rand(1, 100);
995 975
     $combat_data[UBE_OUTCOME][UBE_MOON_REAPERS] = $random <= $combat_data[UBE_OUTCOME][UBE_MOON_REAPERS_DIE_CHANCE] ? UBE_MOON_REAPERS_DIED : UBE_MOON_REAPERS_RETURNED;
996
-  }
997
-  else
976
+  } else
998 977
   {
999 978
     $combat_data[UBE_OUTCOME][UBE_MOON_REAPERS] = UBE_MOON_REAPERS_NONE;
1000 979
   }
@@ -1002,8 +981,7 @@  discard block
 block discarded – undo
1002 981
 
1003 982
 // ------------------------------------------------------------------------------------------------
1004 983
 // Рассылает письма всем участникам боя
1005
-function sn_ube_message_send(&$combat_data)
1006
-{
984
+function sn_ube_message_send(&$combat_data) {
1007 985
   global $lang;
1008 986
 
1009 987
   // TODO: Отсылать каждому игроку сообщение на его языке!
@@ -1042,8 +1020,7 @@  discard block
 block discarded – undo
1042 1020
   if($outcome[UBE_MOON] == UBE_MOON_CREATE_SUCCESS)
1043 1021
   {
1044 1022
     $text_defender .= "{$lang['ube_report_moon_created']} {$outcome[UBE_MOON_SIZE]} {$lang['sys_kilometers_short']}<br /><br />";
1045
-  }
1046
-  elseif($outcome[UBE_MOON] == UBE_MOON_CREATE_FAILED)
1023
+  } elseif($outcome[UBE_MOON] == UBE_MOON_CREATE_FAILED)
1047 1024
   {
1048 1025
     $text_defender .= "{$lang['ube_report_moon_chance']} {$outcome[UBE_MOON_CHANCE]}%<br /><br />";
1049 1026
   }
@@ -1053,8 +1030,7 @@  discard block
 block discarded – undo
1053 1030
     if($outcome[UBE_MOON_REAPERS] == UBE_MOON_REAPERS_NONE)
1054 1031
     {
1055 1032
       $text_defender .= $lang['ube_report_moon_reapers_none'];
1056
-    }
1057
-    else
1033
+    } else
1058 1034
     {
1059 1035
       $text_defender .= "{$lang['ube_report_moon_reapers_wave']}. {$lang['ube_report_moon_reapers_chance']} {$outcome[UBE_MOON_DESTROY_CHANCE]}%. ";
1060 1036
       $text_defender .= $lang[$outcome[UBE_MOON] == UBE_MOON_DESTROY_SUCCESS ? 'ube_report_moon_reapers_success' : 'ube_report_moon_reapers_failure'] . "<br />";
@@ -1081,8 +1057,7 @@  discard block
 block discarded – undo
1081 1057
 // Записывает результат боя в БД
1082 1058
 /** @noinspection SpellCheckingInspection */
1083 1059
 function ube_combat_result_apply(&$combat_data){return sn_function_call('ube_combat_result_apply', array(&$combat_data));}
1084
-function sn_ube_combat_result_apply(&$combat_data)
1085
-{
1060
+function sn_ube_combat_result_apply(&$combat_data) {
1086 1061
 // TODO: Поменять все отладки на запросы
1087 1062
   $destination_user_id = $combat_data[UBE_FLEETS][0][UBE_OWNER];
1088 1063
 
@@ -1130,8 +1105,7 @@  discard block
 block discarded – undo
1130 1105
         {
1131 1106
           // Не планета - всегда сразу записываем строку итогов флота
1132 1107
           $fleet_query[$unit_id] = "{$unit_id},{$units_left}";
1133
-        }
1134
-        elseif($units_lost)
1108
+        } elseif($units_lost)
1135 1109
         {
1136 1110
           // Планета - записываем в ИД юнита его потери только если есть потери
1137 1111
           $db_changeset['unit'][] = OldDbChangeSet::db_changeset_prepare_unit($unit_id, -$units_lost, $combat_data[UBE_PLAYERS][$destination_user_id][UBE_PLAYER_DATA], $planet_id);
@@ -1186,11 +1160,13 @@  discard block
 block discarded – undo
1186 1160
 
1187 1161
 //global $debug;
1188 1162
 //    $fleet_query = implode(',', $fleet_query);
1189
-    if($fleet_id) // Не планета
1163
+    if($fleet_id) {
1164
+      // Не планета
1190 1165
     {
1191 1166
       if($fleet_info[UBE_FLEET_TYPE] == UBE_ATTACKERS && $outcome[UBE_MOON_REAPERS] == UBE_MOON_REAPERS_DIED)
1192 1167
       {
1193 1168
         $new_fleet_count = 0;
1169
+    }
1194 1170
       }
1195 1171
 
1196 1172
       if($new_fleet_count)
@@ -1202,16 +1178,14 @@  discard block
 block discarded – undo
1202 1178
           $fleet_query['fleet_amount'] = $new_fleet_count;
1203 1179
           fleet_update_set($fleet_id, $fleet_query, $fleet_delta);
1204 1180
         }
1205
-      }
1206
-      else
1181
+      } else
1207 1182
       {
1208 1183
         // Удаляем пустые флоты
1209 1184
         // doquery("DELETE FROM {{fleets}} WHERE `fleet_id` = {$fleet_id} LIMIT 1");
1210 1185
         db_fleet_delete($fleet_id);
1211 1186
         DBStaticUnit::db_unit_list_delete(0, LOC_FLEET, $fleet_id, 0);
1212 1187
       }
1213
-    }
1214
-    else // Планета
1188
+    } else // Планета
1215 1189
     {
1216 1190
       // Сохраняем изменения ресурсов - если они есть
1217 1191
       if(!empty($fleet_delta))
@@ -1222,10 +1196,12 @@  discard block
 block discarded – undo
1222 1196
         }
1223 1197
         DBStaticPlanet::db_planet_set_by_id($planet_id, implode(',', $temp));
1224 1198
       }
1225
-      if(!empty($db_changeset)) // Сохраняем изменения юнитов на планете - если они есть
1199
+      if(!empty($db_changeset)) {
1200
+        // Сохраняем изменения юнитов на планете - если они есть
1226 1201
       {
1227 1202
         OldDbChangeSet::db_changeset_apply($db_changeset);
1228 1203
       }
1204
+      }
1229 1205
     }
1230 1206
   }
1231 1207
 
@@ -1242,8 +1218,7 @@  discard block
 block discarded – undo
1242 1218
     $moon_row = uni_create_moon($planet_info[PLANET_GALAXY], $planet_info[PLANET_SYSTEM], $planet_info[PLANET_PLANET], $destination_user_id, $outcome[UBE_MOON_SIZE], '', false);
1243 1219
     $outcome[UBE_MOON_NAME] = $moon_row['name'];
1244 1220
     unset($moon_row);
1245
-  }
1246
-  elseif($outcome[UBE_MOON] == UBE_MOON_DESTROY_SUCCESS)
1221
+  } elseif($outcome[UBE_MOON] == UBE_MOON_DESTROY_SUCCESS)
1247 1222
   {
1248 1223
     DBStaticPlanet::db_planet_delete_by_id($planet_id);
1249 1224
   }
Please login to merge, or discard this patch.
Spacing   +128 added lines, -129 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
 */
53 53
 
54
-if(BE_DEBUG === true)
54
+if (BE_DEBUG === true)
55 55
 {
56 56
   require_once('ube_zi_helpers.php');
57 57
 }
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 {
84 84
   global $ube_convert_techs;
85 85
 
86
-  if(!isset($combat_data[UBE_PLAYERS][$player_id]))
86
+  if (!isset($combat_data[UBE_PLAYERS][$player_id]))
87 87
   {
88 88
     $combat_data[UBE_PLAYERS][$player_id] = array(UBE_ATTACKER => $is_attacker);
89 89
     $player_info = &$combat_data[UBE_PLAYERS][$player_id];
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
     $player_info[UBE_PLAYER_DATA] = $player_data;
96 96
 
97 97
     $admiral_bonus = mrc_get_level($player_data, false, MRC_ADMIRAL) * get_unit_param(MRC_ADMIRAL, P_BONUS_VALUE) / 100;
98
-    foreach($ube_convert_techs as $unit_id => $ube_id)
98
+    foreach ($ube_convert_techs as $unit_id => $ube_id)
99 99
     {
100 100
       $player_info[UBE_BONUSES][$ube_id] += mrc_get_level($player_data, false, $unit_id) * get_unit_param($unit_id, P_BONUS_VALUE) / 100 + $admiral_bonus;
101 101
     }
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 
109 109
 // ------------------------------------------------------------------------------------------------
110 110
 // Заполняет данные по флоту
111
-function ube_attack_prepare_fleet(&$combat_data, &$fleet, $is_attacker){return sn_function_call('ube_attack_prepare_fleet', array(&$combat_data, &$fleet, $is_attacker));}
111
+function ube_attack_prepare_fleet(&$combat_data, &$fleet, $is_attacker) {return sn_function_call('ube_attack_prepare_fleet', array(&$combat_data, &$fleet, $is_attacker)); }
112 112
 function sn_ube_attack_prepare_fleet(&$combat_data, &$fleet, $is_attacker)
113 113
 {
114 114
   $fleet_owner_id = $fleet['fleet_owner'];
@@ -121,15 +121,15 @@  discard block
 block discarded – undo
121 121
   $combat_data[UBE_FLEETS][$fleet_id][UBE_OWNER] = $fleet_owner_id;
122 122
   $fleet_info = &$combat_data[UBE_FLEETS][$fleet_id];
123 123
   $fleet_info[UBE_FLEET_GROUP] = $fleet['fleet_group'];
124
-  foreach($fleet_data as $unit_id => $unit_count)
124
+  foreach ($fleet_data as $unit_id => $unit_count)
125 125
   {
126
-    if(!$unit_count)
126
+    if (!$unit_count)
127 127
     {
128 128
       continue;
129 129
     }
130 130
 
131 131
     $unit_type = get_unit_param($unit_id, P_UNIT_TYPE);
132
-    if($unit_type == UNIT_SHIPS || $unit_type == UNIT_DEFENCE)
132
+    if ($unit_type == UNIT_SHIPS || $unit_type == UNIT_DEFENCE)
133 133
     {
134 134
       $fleet_info[UBE_COUNT][$unit_id] = $unit_count;
135 135
     }
@@ -169,23 +169,23 @@  discard block
 block discarded – undo
169 169
   $combat_data[UBE_FLEETS][0] = array(UBE_OWNER => $player_id);
170 170
   $fleet_info = &$combat_data[UBE_FLEETS][0];
171 171
 
172
-  foreach(sn_get_groups('combat') as $unit_id)
172
+  foreach (sn_get_groups('combat') as $unit_id)
173 173
   {
174
-    if($unit_count = mrc_get_level($player, $planet, $unit_id))
174
+    if ($unit_count = mrc_get_level($player, $planet, $unit_id))
175 175
     {
176 176
       $fleet_info[UBE_COUNT][$unit_id] = $unit_count;
177 177
     }
178 178
   }
179 179
 
180
-  foreach(sn_get_groups('resources_loot') as $resource_id)
180
+  foreach (sn_get_groups('resources_loot') as $resource_id)
181 181
   {
182 182
     $fleet_info[UBE_RESOURCES][$resource_id] = floor(mrc_get_level($player, $planet, $resource_id));
183 183
   }
184 184
 
185
-  if($fortifier_level = mrc_get_level($player, $planet, MRC_FORTIFIER))
185
+  if ($fortifier_level = mrc_get_level($player, $planet, MRC_FORTIFIER))
186 186
   {
187 187
     $fortifier_bonus = $fortifier_level * get_unit_param(MRC_FORTIFIER, P_BONUS_VALUE) / 100;
188
-    foreach($ube_combat_bonus_list as $ube_id)
188
+    foreach ($ube_combat_bonus_list as $ube_id)
189 189
     {
190 190
       $fleet_info[UBE_BONUSES][$ube_id] += $fortifier_bonus;
191 191
     }
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
     PLANET_SIZE   => $planet['diameter'],
202 202
   );
203 203
 
204
-  $combat_data[UBE_OPTIONS][UBE_DEFENDER_ACTIVE] = $player['onlinetime'] >= $combat_data[UBE_TIME] - 60*60*24*7;
204
+  $combat_data[UBE_OPTIONS][UBE_DEFENDER_ACTIVE] = $player['onlinetime'] >= $combat_data[UBE_TIME] - 60 * 60 * 24 * 7;
205 205
 }
206 206
 
207 207
 
@@ -241,12 +241,12 @@  discard block
 block discarded – undo
241 241
 //    ube_attack_prepare_fleet($combat_data, $fleet, false);
242 242
 //  }
243 243
   $fleet_list_on_hold = fleet_list_on_hold($fleet_row['fleet_end_galaxy'], $fleet_row['fleet_end_system'], $fleet_row['fleet_end_planet'], $fleet_row['fleet_end_type'], $ube_time);
244
-  foreach($fleet_list_on_hold as $fleet) {
244
+  foreach ($fleet_list_on_hold as $fleet) {
245 245
     ube_attack_prepare_fleet($combat_data, $fleet, false);
246 246
   }
247 247
 
248 248
   // Готовим инфу по атакующим
249
-  if($fleet_row['fleet_group'])
249
+  if ($fleet_row['fleet_group'])
250 250
   {
251 251
 //    $fleets = doquery("SELECT * FROM {{fleets}} WHERE fleet_group = {$fleet_row['fleet_group']} FOR UPDATE");
252 252
 //    while($fleet = db_fetch($fleets))
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 //      ube_attack_prepare_fleet($combat_data, $fleet, true);
255 255
 //    }
256 256
     $acs_fleet_list = fleet_list_by_group($fleet_row['fleet_group']);
257
-    foreach($acs_fleet_list as $fleet) {
257
+    foreach ($acs_fleet_list as $fleet) {
258 258
       ube_attack_prepare_fleet($combat_data, $fleet, true);
259 259
     }
260 260
   }
@@ -279,13 +279,13 @@  discard block
 block discarded – undo
279 279
 
280 280
   // Готовим информацию для первого раунда - проводим все нужные вычисления из исходных данных
281 281
   $first_round_data = array();
282
-  foreach($combat_data[UBE_FLEETS] as $fleet_id => &$fleet_info)
282
+  foreach ($combat_data[UBE_FLEETS] as $fleet_id => &$fleet_info)
283 283
   {
284 284
     $fleet_info[UBE_COUNT] = is_array($fleet_info[UBE_COUNT]) ? $fleet_info[UBE_COUNT] : array();
285 285
     $player_data = &$combat_data[UBE_PLAYERS][$fleet_info[UBE_OWNER]];
286 286
     $fleet_info[UBE_FLEET_TYPE] = $player_data[UBE_ATTACKER] ? UBE_ATTACKERS : UBE_DEFENDERS;
287 287
 
288
-    foreach($ube_combat_bonus_list as $bonus_id => $bonus_value)
288
+    foreach ($ube_combat_bonus_list as $bonus_id => $bonus_value)
289 289
     {
290 290
       // Вычисляем бонус игрока
291 291
       $bonus_value = isset($player_data[UBE_BONUSES][$bonus_id]) ? $player_data[UBE_BONUSES][$bonus_id] : 0;
@@ -294,16 +294,16 @@  discard block
 block discarded – undo
294 294
     }
295 295
 
296 296
     $first_round_data[$fleet_id][UBE_COUNT] = $fleet_info[UBE_PRICE] = array();
297
-    foreach($fleet_info[UBE_COUNT] as $unit_id => $unit_count)
297
+    foreach ($fleet_info[UBE_COUNT] as $unit_id => $unit_count)
298 298
     {
299
-      if($unit_count <= 0)
299
+      if ($unit_count <= 0)
300 300
       {
301 301
         continue;
302 302
       }
303 303
 
304 304
       $unit_info = get_unit_param($unit_id);
305 305
       // Заполняем информацию о кораблях в информации флота
306
-      foreach($ube_combat_bonus_list as $bonus_id => $bonus_value)
306
+      foreach ($ube_combat_bonus_list as $bonus_id => $bonus_value)
307 307
       {
308 308
         $fleet_info[$bonus_id][$unit_id] = floor($unit_info[$ube_convert_to_techs[$bonus_id]] * (1 + $fleet_info[UBE_BONUSES][$bonus_id]));
309 309
       }
@@ -346,16 +346,16 @@  discard block
 block discarded – undo
346 346
   $is_simulator = $combat_data[UBE_OPTIONS][UBE_SIMULATOR];
347 347
 
348 348
   $round_data = &$combat_data[UBE_ROUNDS][$round];
349
-  foreach($round_data[UBE_FLEETS] as $fleet_id => &$fleet_data)
349
+  foreach ($round_data[UBE_FLEETS] as $fleet_id => &$fleet_data)
350 350
   {
351 351
     // Кэшируем переменные для легкого доступа к подмассивам
352 352
     $fleet_info = &$combat_data[UBE_FLEETS][$fleet_id];
353 353
     $fleet_data[UBE_FLEET_INFO] = &$fleet_info;
354 354
     $fleet_type = $fleet_info[UBE_FLEET_TYPE];
355 355
 
356
-    foreach($fleet_data[UBE_COUNT] as $unit_id => $unit_count)
356
+    foreach ($fleet_data[UBE_COUNT] as $unit_id => $unit_count)
357 357
     {
358
-      if($unit_count <= 0)
358
+      if ($unit_count <= 0)
359 359
       {
360 360
         continue;
361 361
       }
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
       // Для не-симулятора - рандомизируем каждый раунд значения атаки и щитов
366 366
       $fleet_data[UBE_ATTACK_BASE][$unit_id] = floor($fleet_info[UBE_ATTACK][$unit_id] * ($is_simulator ? 1 : mt_rand(80, 120) / 100));
367 367
       $fleet_data[UBE_SHIELD_BASE][$unit_id] = floor($fleet_info[UBE_SHIELD][$unit_id] * ($is_simulator ? 1 : mt_rand(80, 120) / 100));
368
-      $fleet_data[UBE_ARMOR_BASE][$unit_id]  = floor($fleet_info[UBE_ARMOR][$unit_id]);// * ($is_simulator ? 1 : mt_rand(80, 120) / 100));
368
+      $fleet_data[UBE_ARMOR_BASE][$unit_id]  = floor($fleet_info[UBE_ARMOR][$unit_id]); // * ($is_simulator ? 1 : mt_rand(80, 120) / 100));
369 369
 
370 370
       $fleet_data[UBE_ATTACK][$unit_id] = $fleet_data[UBE_ATTACK_BASE][$unit_id] * $unit_count;
371 371
       $fleet_data[UBE_SHIELD][$unit_id] = $fleet_data[UBE_SHIELD_BASE][$unit_id] * $unit_count;
@@ -375,24 +375,24 @@  discard block
 block discarded – undo
375 375
     }
376 376
 
377 377
     // Суммируем данные по флоту
378
-    foreach($ube_combat_bonus_list as $bonus_id)
378
+    foreach ($ube_combat_bonus_list as $bonus_id)
379 379
     {
380 380
       $round_data[$fleet_type][$bonus_id][$fleet_id] += is_array($fleet_data[$bonus_id]) ? array_sum($fleet_data[$bonus_id]) : 0;
381 381
     }
382 382
   }
383 383
 
384 384
   // Суммируем данные по атакующим и защитникам
385
-  foreach($ube_combat_bonus_list as $bonus_id)
385
+  foreach ($ube_combat_bonus_list as $bonus_id)
386 386
   {
387 387
     $round_data[UBE_TOTAL][UBE_DEFENDERS][$bonus_id] = array_sum($round_data[UBE_DEFENDERS][$bonus_id]);
388 388
     $round_data[UBE_TOTAL][UBE_ATTACKERS][$bonus_id] = array_sum($round_data[UBE_ATTACKERS][$bonus_id]);
389 389
   }
390 390
 
391 391
   // Высчитываем долю атаки, приходящейся на юнит равную отношению брони юнита к общей броне - крупные цели атакуют чаще
392
-  foreach($round_data[UBE_FLEETS] as &$fleet_data)
392
+  foreach ($round_data[UBE_FLEETS] as &$fleet_data)
393 393
   {
394 394
     $fleet_type = $fleet_data[UBE_FLEET_INFO][UBE_FLEET_TYPE];
395
-    foreach($fleet_data[UBE_COUNT] as $unit_id => $unit_count)
395
+    foreach ($fleet_data[UBE_COUNT] as $unit_id => $unit_count)
396 396
     {
397 397
       $fleet_data[UBE_DAMAGE_PERCENT][$unit_id] = $fleet_data[UBE_ARMOR][$unit_id] / $round_data[UBE_TOTAL][$fleet_type][UBE_ARMOR];
398 398
     }
@@ -403,24 +403,24 @@  discard block
 block discarded – undo
403 403
 // Рассчитывает результат столкновения флотов ака раунд
404 404
 function sn_ube_combat_round_crossfire_fleet(&$combat_data, $round)
405 405
 {
406
-  if(BE_DEBUG === true)
406
+  if (BE_DEBUG === true)
407 407
   {
408 408
     // sn_ube_combat_helper_round_header($round);
409 409
   }
410 410
 
411 411
   $round_data = &$combat_data[UBE_ROUNDS][$round];
412 412
   // Проводим бой. Сталкиваем каждый корабль атакующего с каждым кораблем атакуемого
413
-  foreach($round_data[UBE_ATTACKERS][UBE_ATTACK] as $attack_fleet_id => $temp)
413
+  foreach ($round_data[UBE_ATTACKERS][UBE_ATTACK] as $attack_fleet_id => $temp)
414 414
   {
415 415
     $attack_fleet_data = &$round_data[UBE_FLEETS][$attack_fleet_id];
416
-    foreach($round_data[UBE_DEFENDERS][UBE_ATTACK] as $defend_fleet_id => $temp2)
416
+    foreach ($round_data[UBE_DEFENDERS][UBE_ATTACK] as $defend_fleet_id => $temp2)
417 417
     {
418 418
       $defend_fleet_data = &$round_data[UBE_FLEETS][$defend_fleet_id];
419 419
 
420
-      foreach($attack_fleet_data[UBE_COUNT] as $attack_unit_id => $attack_unit_count)
420
+      foreach ($attack_fleet_data[UBE_COUNT] as $attack_unit_id => $attack_unit_count)
421 421
       {
422 422
         // if($attack_unit_count <= 0) continue; // TODO: Это пока нельзя включать - вот если будут "боевые порядки юнитов..."
423
-        foreach($defend_fleet_data[UBE_COUNT] as $defend_unit_id => $defend_unit_count)
423
+        foreach ($defend_fleet_data[UBE_COUNT] as $defend_unit_id => $defend_unit_count)
424 424
         {
425 425
           sn_ube_combat_round_crossfire_unit2($attack_fleet_data, $defend_fleet_data, $attack_unit_id, $defend_unit_id, $combat_data[UBE_OPTIONS]);
426 426
           sn_ube_combat_round_crossfire_unit2($defend_fleet_data, $attack_fleet_data, $defend_unit_id, $attack_unit_id, $combat_data[UBE_OPTIONS]);
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
     }
430 430
   }
431 431
 
432
-  if(BE_DEBUG === true)
432
+  if (BE_DEBUG === true)
433 433
   {
434 434
     // sn_ube_combat_helper_round_footer();
435 435
   }
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
   $boom = 0;
478 478
   $boom_limit = 75;
479 479
   $random = $combat_options[UBE_SIMULATOR] ? $boom_limit / 2 : mt_rand(0, 100);
480
-  if($armor_damage && $units_left > 0 && $last_unit_percent <= $boom_limit && $last_unit_percent <= $random)
480
+  if ($armor_damage && $units_left > 0 && $last_unit_percent <= $boom_limit && $last_unit_percent <= $random)
481 481
   {
482 482
     $boom = 1;
483 483
     $units_left--;
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
 
488 488
   $defend_fleet_data[UBE_COUNT][$defend_unit_id] = $units_left;
489 489
 
490
-  if(BE_DEBUG === true)
490
+  if (BE_DEBUG === true)
491 491
   {
492 492
     $debug_unit_crossfire_result = array(
493 493
       'attack_unit_id' => $attack_unit_id,
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
   $units_lost = $units_lost ? $units_lost : 0;
527 527
 
528 528
   $boom_limit = 75; // Взрываемся на 75% прочности
529
-  if($defend_fleet_data[UBE_COUNT][$defend_unit_id] > 0 && $amplified_damage)
529
+  if ($defend_fleet_data[UBE_COUNT][$defend_unit_id] > 0 && $amplified_damage)
530 530
   {
531 531
     // $defend_fleet_info = &$defend_fleet_data[UBE_FLEET_INFO];
532 532
 
@@ -539,18 +539,18 @@  discard block
 block discarded – undo
539 539
     $defend_fleet_data[UBE_ARMOR_REST][$defend_unit_id] -= $damage_to_armor;
540 540
 
541 541
     // Если брони не осталось - юнит потерян
542
-    if($defend_fleet_data[UBE_ARMOR_REST][$defend_unit_id] <= 0)
542
+    if ($defend_fleet_data[UBE_ARMOR_REST][$defend_unit_id] <= 0)
543 543
     {
544 544
       $unit_is_lost = true;
545 545
     }
546 546
     // Если броня осталось, но не осталось щитов - прошел дамадж по броне и надо проверить - не взорвался ли корабль
547
-    elseif($defend_fleet_data[UBE_SHIELD_REST][$defend_unit_id] <= 0)
547
+    elseif ($defend_fleet_data[UBE_SHIELD_REST][$defend_unit_id] <= 0)
548 548
     {
549 549
       $last_unit_hp = $defend_fleet_data[UBE_ARMOR_REST][$defend_unit_id];
550 550
       $last_unit_percent = $last_unit_hp / $defend_fleet_data[UBE_ARMOR_BASE][$defend_unit_id] * 100;
551 551
 
552 552
       $random = $combat_options[UBE_SIMULATOR] ? $boom_limit / 2 : mt_rand(0, 100);
553
-      if($last_unit_percent <= $boom_limit && $last_unit_percent <= $random)
553
+      if ($last_unit_percent <= $boom_limit && $last_unit_percent <= $random)
554 554
       {
555 555
         $unit_is_lost = true;
556 556
         $units_boomed++;
@@ -563,11 +563,11 @@  discard block
 block discarded – undo
563 563
     $defend_fleet_data[UBE_ARMOR][$defend_unit_id] -= $damage_to_armor;
564 564
     $defend_fleet_data[UBE_SHIELD][$defend_unit_id] -= $damage_to_shield;
565 565
 
566
-    if($unit_is_lost)
566
+    if ($unit_is_lost)
567 567
     {
568 568
       $units_lost++;
569 569
       $defend_fleet_data[UBE_COUNT][$defend_unit_id]--;
570
-      if($defend_fleet_data[UBE_COUNT][$defend_unit_id])
570
+      if ($defend_fleet_data[UBE_COUNT][$defend_unit_id])
571 571
       {
572 572
         $defend_fleet_data[UBE_ARMOR_REST][$defend_unit_id] = $defend_fleet_data[UBE_ARMOR_BASE][$defend_unit_id];
573 573
         $defend_fleet_data[UBE_SHIELD_REST][$defend_unit_id] = $defend_fleet_data[UBE_SHIELD_BASE][$defend_unit_id];
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 // Рассчитывает результат столкновения двух юнитов ака ход
583 583
 function sn_ube_combat_round_crossfire_unit2(&$attack_fleet_data, &$defend_fleet_data, $attack_unit_id, $defend_unit_id, &$combat_options)
584 584
 {
585
-  if($defend_fleet_data[UBE_COUNT][$defend_unit_id] <= 0)
585
+  if ($defend_fleet_data[UBE_COUNT][$defend_unit_id] <= 0)
586 586
   {
587 587
     return;
588 588
   }
@@ -625,16 +625,16 @@  discard block
 block discarded – undo
625 625
 
626 626
   $outcome = array();
627 627
   $next_round_fleet = array();
628
-  foreach($round_data[UBE_FLEETS] as $fleet_id => &$fleet_data)
628
+  foreach ($round_data[UBE_FLEETS] as $fleet_id => &$fleet_data)
629 629
   {
630
-    if(array_sum($fleet_data[UBE_COUNT]) <= 0)
630
+    if (array_sum($fleet_data[UBE_COUNT]) <= 0)
631 631
     {
632 632
       continue;
633 633
     }
634 634
 
635
-    foreach($fleet_data[UBE_COUNT] as $unit_id => $unit_count)
635
+    foreach ($fleet_data[UBE_COUNT] as $unit_id => $unit_count)
636 636
     {
637
-      if($unit_count <= 0)
637
+      if ($unit_count <= 0)
638 638
       {
639 639
         continue;
640 640
       }
@@ -646,17 +646,17 @@  discard block
 block discarded – undo
646 646
   }
647 647
 
648 648
   // Проверяем - если кого-то не осталось или не осталось обоих - заканчиваем цикл
649
-  if(count($outcome) == 0 || $round == 10)
649
+  if (count($outcome) == 0 || $round == 10)
650 650
   {
651 651
     $round_data[UBE_OUTCOME] = UBE_COMBAT_RESULT_DRAW_END;
652 652
   }
653
-  elseif(count($outcome) == 1)
653
+  elseif (count($outcome) == 1)
654 654
   {
655 655
     $round_data[UBE_OUTCOME] = isset($outcome[UBE_ATTACKERS]) ? UBE_COMBAT_RESULT_WIN : UBE_COMBAT_RESULT_LOSS;
656 656
   }
657
-  elseif(count($outcome) == 2)
657
+  elseif (count($outcome) == 2)
658 658
   {
659
-    if($round < 10)
659
+    if ($round < 10)
660 660
     {
661 661
       $combat_data[UBE_ROUNDS][$round + 1][UBE_FLEETS] = $next_round_fleet;
662 662
     }
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
   $start = microtime(true);
675 675
   sn_ube_combat_prepare_first_round($combat_data);
676 676
 
677
-  for($round = 1; $round <= 10; $round++)
677
+  for ($round = 1; $round <= 10; $round++)
678 678
   {
679 679
     // Готовим данные для раунда
680 680
     sn_ube_combat_round_prepare($combat_data, $round);
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
     sn_ube_combat_round_crossfire_fleet($combat_data, $round);
684 684
 
685 685
     // Анализируем итоги текущего раунда и готовим данные для следующего
686
-    if(sn_ube_combat_round_analyze($combat_data, $round) != UBE_COMBAT_RESULT_DRAW)
686
+    if (sn_ube_combat_round_analyze($combat_data, $round) != UBE_COMBAT_RESULT_DRAW)
687 687
     {
688 688
       break;
689 689
     }
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
   $combat_data[UBE_OPTIONS][UBE_EXCHANGE] = array(RES_METAL => $config->rpg_exchange_metal);
705 705
 
706 706
   $exchange = &$combat_data[UBE_OPTIONS][UBE_EXCHANGE];
707
-  foreach(array(RES_CRYSTAL => 'rpg_exchange_crystal', RES_DEUTERIUM => 'rpg_exchange_deuterium', RES_DARK_MATTER => 'rpg_exchange_darkMatter') as $resource_id => $resource_name)
707
+  foreach (array(RES_CRYSTAL => 'rpg_exchange_crystal', RES_DEUTERIUM => 'rpg_exchange_deuterium', RES_DARK_MATTER => 'rpg_exchange_darkMatter') as $resource_id => $resource_name)
708 708
   {
709 709
     $exchange[$resource_id] = $config->$resource_name * $exchange[RES_METAL];
710 710
   }
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
   $outcome[UBE_DEBRIS] = array();
719 719
 
720 720
   // Генерируем результат боя
721
-  foreach($fleets_info as $fleet_id => &$fleet_info)
721
+  foreach ($fleets_info as $fleet_id => &$fleet_info)
722 722
   {
723 723
     $fleet_type = $fleet_info[UBE_FLEET_TYPE];
724 724
     // Инициализируем массив результатов для флота
@@ -729,32 +729,32 @@  discard block
 block discarded – undo
729 729
     $fleet_outcome = &$outcome[UBE_FLEETS][$fleet_id];
730 730
     $fleet_data = &$last_round_data[UBE_FLEETS][$fleet_id];
731 731
 
732
-    foreach($fleet_info[UBE_COUNT] as $unit_id => $unit_count)
732
+    foreach ($fleet_info[UBE_COUNT] as $unit_id => $unit_count)
733 733
     {
734 734
       // Вычисляем сколько юнитов осталось и сколько потеряно
735 735
       $units_left = $fleet_data[UBE_COUNT][$unit_id];
736 736
 
737 737
       // Восстановление обороны - 75% от уничтоженной
738
-      if($fleet_info[UBE_TYPE][$unit_id] == UNIT_DEFENCE)
738
+      if ($fleet_info[UBE_TYPE][$unit_id] == UNIT_DEFENCE)
739 739
       {
740 740
         $giveback_chance = 75; // TODO Configure
741 741
         $units_lost = $unit_count - $units_left;
742
-        if($combat_data[UBE_OPTIONS][UBE_SIMULATOR])
742
+        if ($combat_data[UBE_OPTIONS][UBE_SIMULATOR])
743 743
         { // for simulation just return 75% of loss
744 744
           $units_giveback = round($units_lost * $giveback_chance / 100);
745 745
         }
746 746
         else
747 747
         {
748
-          if($unit_count > 10)
748
+          if ($unit_count > 10)
749 749
           { // if there were more then 10 defense elements - mass-calculating giveback
750 750
             $units_giveback = round($units_lost * mt_rand($giveback_chance * 0.8, $giveback_chance * 1.2) / 100);
751 751
           }
752 752
           else
753 753
           { //if there were less then 10 defense elements - calculating giveback per element
754 754
             $units_giveback = 0;
755
-            for($i = 1; $i <= $units_lost; $i++)
755
+            for ($i = 1; $i <= $units_lost; $i++)
756 756
             {
757
-              if(mt_rand(1,100) <= $giveback_chance)
757
+              if (mt_rand(1, 100) <= $giveback_chance)
758 758
               {
759 759
                 $units_giveback++;
760 760
               }
@@ -773,13 +773,13 @@  discard block
 block discarded – undo
773 773
       $outcome[$fleet_type][UBE_CAPACITY][$fleet_id] += $fleet_info[UBE_CAPACITY][$unit_id] * $units_left;
774 774
 
775 775
       // Вычисляем потери в ресурсах
776
-      if($units_lost)
776
+      if ($units_lost)
777 777
       {
778 778
         $fleet_outcome[UBE_UNITS_LOST][$unit_id] = $units_lost;
779 779
 
780
-        foreach($fleet_info[UBE_PRICE] as $resource_id => $unit_prices)
780
+        foreach ($fleet_info[UBE_PRICE] as $resource_id => $unit_prices)
781 781
         {
782
-          if(!$unit_prices[$unit_id])
782
+          if (!$unit_prices[$unit_id])
783 783
           {
784 784
             continue;
785 785
           }
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
           $fleet_outcome[UBE_RESOURCES_LOST][$resource_id] += $resources_lost;
790 790
 
791 791
           // Если это корабль - прибавляем потери к обломкам на орбите
792
-          if($fleet_info[UBE_TYPE][$unit_id] == UNIT_SHIPS)
792
+          if ($fleet_info[UBE_TYPE][$unit_id] == UNIT_SHIPS)
793 793
           {
794 794
             $outcome[UBE_DEBRIS][$resource_id] += floor($resources_lost * ($combat_data[UBE_OPTIONS][UBE_SIMULATOR] ? 30 : mt_rand(20, 40)) / 100); // TODO: Configurize
795 795
           }
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
     }
803 803
 
804 804
     // На планете ($fleet_id = 0) ресурсы в космос не выбрасываются
805
-    if($fleet_id == 0)
805
+    if ($fleet_id == 0)
806 806
     {
807 807
       continue;
808 808
     }
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
     // Количество ресурсов флота
811 811
     $fleet_total_resources = empty($fleet_info[UBE_RESOURCES]) ? 0 : array_sum($fleet_info[UBE_RESOURCES]);
812 812
     // Если на борту нет ресурсов - зачем нам все это?
813
-    if($fleet_total_resources == 0)
813
+    if ($fleet_total_resources == 0)
814 814
     {
815 815
       continue;
816 816
     }
@@ -818,13 +818,13 @@  discard block
 block discarded – undo
818 818
     // Емкость трюмов флота
819 819
     $fleet_capacity = $outcome[$fleet_type][UBE_CAPACITY][$fleet_id];
820 820
     // Если емкость трюмов меньше количество ресурсов - часть ресов выбрасываем нахуй
821
-    if($fleet_capacity < $fleet_total_resources)
821
+    if ($fleet_capacity < $fleet_total_resources)
822 822
     {
823 823
       $left_percent = $fleet_capacity / $fleet_total_resources; // Сколько ресурсов будет оставлено
824
-      foreach($fleet_info[UBE_RESOURCES] as $resource_id => $resource_amount)
824
+      foreach ($fleet_info[UBE_RESOURCES] as $resource_id => $resource_amount)
825 825
       {
826 826
         // Не просчитываем ресурсы, которых нет на борту кораблей флота
827
-        if(!$resource_amount)
827
+        if (!$resource_amount)
828 828
         {
829 829
           continue;
830 830
         }
@@ -847,9 +847,9 @@  discard block
 block discarded – undo
847 847
   // SFR - Small Fleet Reconnaissance ака РМФ
848 848
   $outcome[UBE_SFR] = count($combat_data[UBE_ROUNDS]) == 2 && $outcome[UBE_COMBAT_RESULT] == UBE_COMBAT_RESULT_LOSS;
849 849
 
850
-  if(!$combat_data[UBE_OPTIONS][UBE_LOADED])
850
+  if (!$combat_data[UBE_OPTIONS][UBE_LOADED])
851 851
   {
852
-    if($combat_data[UBE_OPTIONS][UBE_MOON_WAS])
852
+    if ($combat_data[UBE_OPTIONS][UBE_MOON_WAS])
853 853
     {
854 854
       $outcome[UBE_MOON] = UBE_MOON_WAS;
855 855
     }
@@ -859,10 +859,10 @@  discard block
 block discarded – undo
859 859
     }
860 860
 
861 861
     // Лутаем ресурсы - если аттакер выиграл
862
-    if($outcome[UBE_COMBAT_RESULT] == UBE_COMBAT_RESULT_WIN)
862
+    if ($outcome[UBE_COMBAT_RESULT] == UBE_COMBAT_RESULT_WIN)
863 863
     {
864 864
       sn_ube_combat_analyze_loot($combat_data);
865
-      if($combat_data[UBE_OPTIONS][UBE_MOON_WAS] && $combat_data[UBE_OPTIONS][UBE_MISSION_TYPE] == MT_DESTROY)
865
+      if ($combat_data[UBE_OPTIONS][UBE_MOON_WAS] && $combat_data[UBE_OPTIONS][UBE_MISSION_TYPE] == MT_DESTROY)
866 866
       {
867 867
         sn_ube_combat_analyze_moon_destroy($combat_data);
868 868
       }
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
   $planet_looted_in_metal = 0;
882 882
   $planet_resource_looted = array();
883 883
   $planet_resource_total = is_array($planet_resource_list) ? array_sum($planet_resource_list) : 0;
884
-  if($planet_resource_total && ($total_capacity = array_sum($outcome[UBE_ATTACKERS][UBE_CAPACITY])))
884
+  if ($planet_resource_total && ($total_capacity = array_sum($outcome[UBE_ATTACKERS][UBE_CAPACITY])))
885 885
   {
886 886
     // Можно вывести только половину ресурсов, но не больше, чем общая вместимость флотов атакующих
887 887
     $planet_lootable = min($planet_resource_total / 2, $total_capacity);
@@ -892,11 +892,11 @@  discard block
 block discarded – undo
892 892
     $total_lootable = min($planet_lootable, $total_capacity);
893 893
 
894 894
     // Вычисляем сколько ресурсов вывезено
895
-    foreach($outcome[UBE_ATTACKERS][UBE_CAPACITY] as $fleet_id => $fleet_capacity)
895
+    foreach ($outcome[UBE_ATTACKERS][UBE_CAPACITY] as $fleet_id => $fleet_capacity)
896 896
     {
897 897
       $looted_in_metal = 0;
898 898
       $fleet_loot_data = array();
899
-      foreach($planet_resource_list as $resource_id => $resource_amount)
899
+      foreach ($planet_resource_list as $resource_id => $resource_amount)
900 900
       {
901 901
         // TODO Восстанавливаем ошибку округления - придумать нормальный алгоритм - вроде round() должно быть достаточно. Проверить
902 902
         $fleet_lootable_percent = $fleet_capacity / $total_capacity;
@@ -919,25 +919,25 @@  discard block
 block discarded – undo
919 919
 function sn_ube_combat_analyze_moon(&$outcome, $is_simulator)
920 920
 {
921 921
   $outcome[UBE_DEBRIS_TOTAL] = 0;
922
-  foreach(array(RES_METAL, RES_CRYSTAL) as $resource_id) // TODO via array
922
+  foreach (array(RES_METAL, RES_CRYSTAL) as $resource_id) // TODO via array
923 923
   {
924 924
     $outcome[UBE_DEBRIS_TOTAL] += $outcome[UBE_DEBRIS][$resource_id];
925 925
   }
926 926
 
927
-  if($outcome[UBE_DEBRIS_TOTAL])
927
+  if ($outcome[UBE_DEBRIS_TOTAL])
928 928
   {
929 929
     // TODO uni_calculate_moon_chance
930 930
     $moon_chance = min($outcome[UBE_DEBRIS_TOTAL] / 1000000, 30); // TODO Configure
931 931
     $moon_chance = $moon_chance >= 1 ? $moon_chance : 0;
932 932
     $outcome[UBE_MOON_CHANCE] = $moon_chance;
933
-    if($moon_chance)
933
+    if ($moon_chance)
934 934
     {
935
-      if($is_simulator || mt_rand(1, 100) <= $moon_chance)
935
+      if ($is_simulator || mt_rand(1, 100) <= $moon_chance)
936 936
       {
937 937
         $outcome[UBE_MOON_SIZE] = round($is_simulator ? $moon_chance * 150 + 1999 : mt_rand($moon_chance * 100 + 1000, $moon_chance * 200 + 2999));
938 938
         $outcome[UBE_MOON] = UBE_MOON_CREATE_SUCCESS;
939 939
 
940
-        if($outcome[UBE_DEBRIS_TOTAL] <= 30000000)
940
+        if ($outcome[UBE_DEBRIS_TOTAL] <= 30000000)
941 941
         {
942 942
           $outcome[UBE_DEBRIS_TOTAL] = 0;
943 943
           $outcome[UBE_DEBRIS] = array();
@@ -948,7 +948,7 @@  discard block
 block discarded – undo
948 948
           $moon_debris_left_percent = ($outcome[UBE_DEBRIS_TOTAL] - $moon_debris_spent) / $outcome[UBE_DEBRIS_TOTAL];
949 949
 
950 950
           $outcome[UBE_DEBRIS_TOTAL] = 0;
951
-          foreach(array(RES_METAL, RES_CRYSTAL) as $resource_id) // TODO via array
951
+          foreach (array(RES_METAL, RES_CRYSTAL) as $resource_id) // TODO via array
952 952
           {
953 953
             $outcome[UBE_DEBRIS][$resource_id] = floor($outcome[UBE_DEBRIS][$resource_id] * $moon_debris_left_percent);
954 954
             $outcome[UBE_DEBRIS_TOTAL] += $outcome[UBE_DEBRIS][$resource_id];
@@ -972,11 +972,11 @@  discard block
 block discarded – undo
972 972
 {
973 973
   // TODO: $is_simulator
974 974
   $reapers = 0;
975
-  foreach($combat_data[UBE_ROUNDS][count($combat_data[UBE_ROUNDS])-1][UBE_FLEETS] as $fleet_data)
975
+  foreach ($combat_data[UBE_ROUNDS][count($combat_data[UBE_ROUNDS]) - 1][UBE_FLEETS] as $fleet_data)
976 976
   {
977
-    if($fleet_data[UBE_FLEET_INFO][UBE_FLEET_TYPE] == UBE_ATTACKERS)
977
+    if ($fleet_data[UBE_FLEET_INFO][UBE_FLEET_TYPE] == UBE_ATTACKERS)
978 978
     {
979
-      foreach($fleet_data[UBE_COUNT] as $unit_id => $unit_count)
979
+      foreach ($fleet_data[UBE_COUNT] as $unit_id => $unit_count)
980 980
       {
981 981
         // TODO: Работа по группам - группа "Уничтожители лун"
982 982
         $reapers += ($unit_id == SHIP_HUGE_DEATH_STAR) ? $unit_count : 0;
@@ -985,7 +985,7 @@  discard block
 block discarded – undo
985 985
   }
986 986
 
987 987
   $moon_size = $combat_data[UBE_OUTCOME][UBE_PLANET][PLANET_SIZE];
988
-  if($reapers)
988
+  if ($reapers)
989 989
   {
990 990
     $random = mt_rand(1, 100);
991 991
     $combat_data[UBE_OUTCOME][UBE_MOON_DESTROY_CHANCE] = max(1, min(99, round((100 - sqrt($moon_size)) * sqrt($reapers))));
@@ -1019,38 +1019,37 @@  discard block
 block discarded – undo
1019 1019
     $planet_info[PLANET_SYSTEM],
1020 1020
     $planet_info[PLANET_PLANET],
1021 1021
     htmlentities($planet_info[PLANET_NAME], ENT_COMPAT, 'UTF-8'),
1022
-    $lang[$outcome['UBE_COMBAT_RESULT'] == UBE_COMBAT_RESULT_WIN ? 'ube_report_info_outcome_win' :
1023
-      ($outcome['UBE_COMBAT_RESULT'] == UBE_COMBAT_RESULT_DRAW ? 'ube_report_info_outcome_draw' : 'ube_report_info_outcome_loss')
1022
+    $lang[$outcome['UBE_COMBAT_RESULT'] == UBE_COMBAT_RESULT_WIN ? 'ube_report_info_outcome_win' : ($outcome['UBE_COMBAT_RESULT'] == UBE_COMBAT_RESULT_DRAW ? 'ube_report_info_outcome_draw' : 'ube_report_info_outcome_loss')
1024 1023
     ]
1025 1024
   );
1026 1025
 
1027 1026
   $text_defender = '';
1028
-  foreach($outcome[UBE_DEBRIS] as $resource_id => $resource_amount)
1027
+  foreach ($outcome[UBE_DEBRIS] as $resource_id => $resource_amount)
1029 1028
   {
1030
-    if($resource_id == RES_DEUTERIUM)
1029
+    if ($resource_id == RES_DEUTERIUM)
1031 1030
     {
1032 1031
       continue;
1033 1032
     }
1034 1033
 
1035 1034
     $text_defender .= "{$lang['tech'][$resource_id]}: " . HelperString::numberFloorAndFormat($resource_amount) . '<br />';
1036 1035
   }
1037
-  if($text_defender)
1036
+  if ($text_defender)
1038 1037
   {
1039 1038
     $text_defender = "{$lang['ube_report_msg_body_debris']}{$text_defender}<br />";
1040 1039
   }
1041 1040
 
1042
-  if($outcome[UBE_MOON] == UBE_MOON_CREATE_SUCCESS)
1041
+  if ($outcome[UBE_MOON] == UBE_MOON_CREATE_SUCCESS)
1043 1042
   {
1044 1043
     $text_defender .= "{$lang['ube_report_moon_created']} {$outcome[UBE_MOON_SIZE]} {$lang['sys_kilometers_short']}<br /><br />";
1045 1044
   }
1046
-  elseif($outcome[UBE_MOON] == UBE_MOON_CREATE_FAILED)
1045
+  elseif ($outcome[UBE_MOON] == UBE_MOON_CREATE_FAILED)
1047 1046
   {
1048 1047
     $text_defender .= "{$lang['ube_report_moon_chance']} {$outcome[UBE_MOON_CHANCE]}%<br /><br />";
1049 1048
   }
1050 1049
 
1051
-  if($combat_data[UBE_OPTIONS][UBE_MISSION_TYPE] == MT_DESTROY)
1050
+  if ($combat_data[UBE_OPTIONS][UBE_MISSION_TYPE] == MT_DESTROY)
1052 1051
   {
1053
-    if($outcome[UBE_MOON_REAPERS] == UBE_MOON_REAPERS_NONE)
1052
+    if ($outcome[UBE_MOON_REAPERS] == UBE_MOON_REAPERS_NONE)
1054 1053
     {
1055 1054
       $text_defender .= $lang['ube_report_moon_reapers_none'];
1056 1055
     }
@@ -1068,7 +1067,7 @@  discard block
 block discarded – undo
1068 1067
   $text_defender .= "{$lang['ube_report_info_link']}: <a href=\"index.php?page=battle_report&cypher={$combat_data[UBE_REPORT_CYPHER]}\">{$combat_data[UBE_REPORT_CYPHER]}</a>";
1069 1068
 
1070 1069
   // TODO: Оптимизировать отсылку сообщений - отсылать пакетами
1071
-  foreach($combat_data[UBE_PLAYERS] as $player_id => $player_info)
1070
+  foreach ($combat_data[UBE_PLAYERS] as $player_id => $player_info)
1072 1071
   {
1073 1072
     $message = $text_common . ($outcome[UBE_SFR] && $player_info[UBE_ATTACKER] ? $lang['ube_report_msg_body_sfr'] : $text_defender);
1074 1073
     msg_send_simple_message($player_id, '', $combat_data[UBE_TIME], MSG_TYPE_COMBAT, $lang['sys_mess_tower'], $lang['sys_mess_attack_report'], $message);
@@ -1080,7 +1079,7 @@  discard block
 block discarded – undo
1080 1079
 // ------------------------------------------------------------------------------------------------
1081 1080
 // Записывает результат боя в БД
1082 1081
 /** @noinspection SpellCheckingInspection */
1083
-function ube_combat_result_apply(&$combat_data){return sn_function_call('ube_combat_result_apply', array(&$combat_data));}
1082
+function ube_combat_result_apply(&$combat_data) {return sn_function_call('ube_combat_result_apply', array(&$combat_data)); }
1084 1083
 function sn_ube_combat_result_apply(&$combat_data)
1085 1084
 {
1086 1085
 // TODO: Поменять все отладки на запросы
@@ -1090,7 +1089,7 @@  discard block
 block discarded – undo
1090 1089
   $planet_info = &$outcome[UBE_PLANET];
1091 1090
   $planet_id = $planet_info[PLANET_ID];
1092 1091
   // Обновляем поле обломков на планете
1093
-  if(!$combat_data[UBE_OPTIONS][UBE_COMBAT_ADMIN] && !empty($outcome[UBE_DEBRIS]))
1092
+  if (!$combat_data[UBE_OPTIONS][UBE_COMBAT_ADMIN] && !empty($outcome[UBE_DEBRIS]))
1094 1093
   {
1095 1094
     DBStaticPlanet::db_planet_set_by_gspt($planet_info[PLANET_GALAXY], $planet_info[PLANET_SYSTEM], $planet_info[PLANET_PLANET], PT_PLANET,
1096 1095
       "`debris_metal` = `debris_metal` + " . floor($outcome[UBE_DEBRIS][RES_METAL]) . ", `debris_crystal` = `debris_crystal` + " . floor($outcome[UBE_DEBRIS][RES_CRYSTAL])
@@ -1102,9 +1101,9 @@  discard block
 block discarded – undo
1102 1101
   );
1103 1102
 
1104 1103
   $fleets_outcome = &$outcome[UBE_FLEETS];
1105
-  foreach($combat_data[UBE_FLEETS] as $fleet_id => &$fleet_info)
1104
+  foreach ($combat_data[UBE_FLEETS] as $fleet_id => &$fleet_info)
1106 1105
   {
1107
-    if($fleet_info[UBE_FLEET_GROUP])
1106
+    if ($fleet_info[UBE_FLEET_GROUP])
1108 1107
     {
1109 1108
       $db_save[UBE_FLEET_GROUP][$fleet_info[UBE_FLEET_GROUP]] = $fleet_info[UBE_FLEET_GROUP];
1110 1109
     }
@@ -1117,28 +1116,28 @@  discard block
 block discarded – undo
1117 1116
     $old_fleet_count = array_sum($fleet_info[UBE_COUNT]);
1118 1117
     $new_fleet_count = $old_fleet_count - array_sum($fleets_outcome[$fleet_id][UBE_UNITS_LOST]);
1119 1118
     // Перебираем юниты если во время боя количество юнитов изменилось и при этом во флоту остались юниты или это планета
1120
-    if($new_fleet_count != $old_fleet_count && (!$fleet_id || $new_fleet_count))
1119
+    if ($new_fleet_count != $old_fleet_count && (!$fleet_id || $new_fleet_count))
1121 1120
     {
1122 1121
       // Просматриваем результаты изменения флотов
1123
-      foreach($fleet_info[UBE_COUNT] as $unit_id => $unit_count)
1122
+      foreach ($fleet_info[UBE_COUNT] as $unit_id => $unit_count)
1124 1123
       {
1125 1124
         // Перебираем аутком на случай восстановления юнитов
1126
-        $units_lost = (float)$fleets_outcome[$fleet_id][UBE_UNITS_LOST][$unit_id];
1125
+        $units_lost = (float) $fleets_outcome[$fleet_id][UBE_UNITS_LOST][$unit_id];
1127 1126
 
1128 1127
         $units_left = $unit_count - $units_lost;
1129
-        if($fleet_id)
1128
+        if ($fleet_id)
1130 1129
         {
1131 1130
           // Не планета - всегда сразу записываем строку итогов флота
1132 1131
           $fleet_query[$unit_id] = "{$unit_id},{$units_left}";
1133 1132
         }
1134
-        elseif($units_lost)
1133
+        elseif ($units_lost)
1135 1134
         {
1136 1135
           // Планета - записываем в ИД юнита его потери только если есть потери
1137 1136
           $db_changeset['unit'][] = OldDbChangeSet::db_changeset_prepare_unit($unit_id, -$units_lost, $combat_data[UBE_PLAYERS][$destination_user_id][UBE_PLAYER_DATA], $planet_id);
1138 1137
         }
1139 1138
       }
1140 1139
 
1141
-      if($fleet_id)
1140
+      if ($fleet_id)
1142 1141
       {
1143 1142
         // Для флотов перегенерируем массив как одно вхождение в SET SQL-запроса
1144 1143
         $fleet_query = array(
@@ -1149,12 +1148,12 @@  discard block
 block discarded – undo
1149 1148
 
1150 1149
     $fleet_delta = array();
1151 1150
     // Если во флоте остались юниты или это планета - генерируем изменение ресурсов
1152
-    if($new_fleet_count || !$fleet_id)
1151
+    if ($new_fleet_count || !$fleet_id)
1153 1152
     {
1154
-      foreach(sn_get_groups('resources_loot') as $resource_id)
1153
+      foreach (sn_get_groups('resources_loot') as $resource_id)
1155 1154
       {
1156
-        $resource_change = (float)$fleets_outcome[$fleet_id][UBE_RESOURCES_LOOTED][$resource_id] + (float)$fleets_outcome[$fleet_id][UBE_CARGO_DROPPED][$resource_id];
1157
-        if($resource_change)
1155
+        $resource_change = (float) $fleets_outcome[$fleet_id][UBE_RESOURCES_LOOTED][$resource_id] + (float) $fleets_outcome[$fleet_id][UBE_CARGO_DROPPED][$resource_id];
1156
+        if ($resource_change)
1158 1157
         {
1159 1158
           $resource_db_name = ($fleet_id ? 'fleet_resource_' : '') . pname_resource_name($resource_id);
1160 1159
 //          $fleet_query[] = "`{$resource_db_name}` = `{$resource_db_name}` - ({$resource_change})";
@@ -1168,10 +1167,10 @@  discard block
 block discarded – undo
1168 1167
           continue;
1169 1168
         }
1170 1169
     */
1171
-    if($fleet_id && $new_fleet_count)
1170
+    if ($fleet_id && $new_fleet_count)
1172 1171
     {
1173 1172
       // Если защитник и не РМФ - отправляем флот назад
1174
-      if(($fleet_info[UBE_FLEET_TYPE] == UBE_DEFENDERS && !$outcome[UBE_SFR]) || $fleet_info[UBE_FLEET_TYPE] == UBE_ATTACKERS)
1173
+      if (($fleet_info[UBE_FLEET_TYPE] == UBE_DEFENDERS && !$outcome[UBE_SFR]) || $fleet_info[UBE_FLEET_TYPE] == UBE_ATTACKERS)
1175 1174
       {
1176 1175
 //        $fleet_query[] = '`fleet_mess` = 1';
1177 1176
         $fleet_query['fleet_mess'] = 1;
@@ -1186,16 +1185,16 @@  discard block
 block discarded – undo
1186 1185
 
1187 1186
 //global $debug;
1188 1187
 //    $fleet_query = implode(',', $fleet_query);
1189
-    if($fleet_id) // Не планета
1188
+    if ($fleet_id) // Не планета
1190 1189
     {
1191
-      if($fleet_info[UBE_FLEET_TYPE] == UBE_ATTACKERS && $outcome[UBE_MOON_REAPERS] == UBE_MOON_REAPERS_DIED)
1190
+      if ($fleet_info[UBE_FLEET_TYPE] == UBE_ATTACKERS && $outcome[UBE_MOON_REAPERS] == UBE_MOON_REAPERS_DIED)
1192 1191
       {
1193 1192
         $new_fleet_count = 0;
1194 1193
       }
1195 1194
 
1196
-      if($new_fleet_count)
1195
+      if ($new_fleet_count)
1197 1196
       {
1198
-        if(!empty($fleet_query) || !empty($fleet_delta))
1197
+        if (!empty($fleet_query) || !empty($fleet_delta))
1199 1198
         {
1200 1199
 //          doquery("UPDATE {{fleets}} SET {$fleet_query}, `fleet_amount` = '{$new_fleet_count}' WHERE `fleet_id` = {$fleet_id} LIMIT 1");
1201 1200
 //          db_fleet_update_set_safe_string($fleet_id, "{$fleet_query}, `fleet_amount` = '{$new_fleet_count}'");
@@ -1214,15 +1213,15 @@  discard block
 block discarded – undo
1214 1213
     else // Планета
1215 1214
     {
1216 1215
       // Сохраняем изменения ресурсов - если они есть
1217
-      if(!empty($fleet_delta))
1216
+      if (!empty($fleet_delta))
1218 1217
       {
1219 1218
         $temp = array();
1220
-        foreach($fleet_delta as $resource_db_name => $resource_amount) {
1219
+        foreach ($fleet_delta as $resource_db_name => $resource_amount) {
1221 1220
           $temp[] = "`{$resource_db_name}` = `{$resource_db_name}` + ({$resource_amount})";
1222 1221
         }
1223 1222
         DBStaticPlanet::db_planet_set_by_id($planet_id, implode(',', $temp));
1224 1223
       }
1225
-      if(!empty($db_changeset)) // Сохраняем изменения юнитов на планете - если они есть
1224
+      if (!empty($db_changeset)) // Сохраняем изменения юнитов на планете - если они есть
1226 1225
       {
1227 1226
         OldDbChangeSet::db_changeset_apply($db_changeset);
1228 1227
       }
@@ -1231,34 +1230,34 @@  discard block
 block discarded – undo
1231 1230
 
1232 1231
   // TODO: Связать сабы с флотами констраинтами ON DELETE SET NULL
1233 1232
   // $db_save[UBE_FLEET_GROUP][$fleet_info[UBE_FLEET_GROUP]] = $fleet_info[UBE_FLEET_GROUP];
1234
-  if(!empty($db_save[UBE_FLEET_GROUP]))
1233
+  if (!empty($db_save[UBE_FLEET_GROUP]))
1235 1234
   {
1236 1235
     $db_save[UBE_FLEET_GROUP] = implode(',', $db_save[UBE_FLEET_GROUP]);
1237 1236
     doquery("DELETE FROM {{aks}} WHERE `id` IN ({$db_save[UBE_FLEET_GROUP]})");
1238 1237
   }
1239 1238
 
1240
-  if($outcome[UBE_MOON] == UBE_MOON_CREATE_SUCCESS)
1239
+  if ($outcome[UBE_MOON] == UBE_MOON_CREATE_SUCCESS)
1241 1240
   {
1242 1241
     $moon_row = uni_create_moon($planet_info[PLANET_GALAXY], $planet_info[PLANET_SYSTEM], $planet_info[PLANET_PLANET], $destination_user_id, $outcome[UBE_MOON_SIZE], '', false);
1243 1242
     $outcome[UBE_MOON_NAME] = $moon_row['name'];
1244 1243
     unset($moon_row);
1245 1244
   }
1246
-  elseif($outcome[UBE_MOON] == UBE_MOON_DESTROY_SUCCESS)
1245
+  elseif ($outcome[UBE_MOON] == UBE_MOON_DESTROY_SUCCESS)
1247 1246
   {
1248 1247
     DBStaticPlanet::db_planet_delete_by_id($planet_id);
1249 1248
   }
1250 1249
 
1251 1250
   {
1252 1251
     $bashing_list = array();
1253
-    foreach($combat_data[UBE_PLAYERS] as $player_id => $player_info)
1252
+    foreach ($combat_data[UBE_PLAYERS] as $player_id => $player_info)
1254 1253
     {
1255
-      if($player_info[UBE_ATTACKER])
1254
+      if ($player_info[UBE_ATTACKER])
1256 1255
       {
1257
-        if($outcome[UBE_MOON] != UBE_MOON_DESTROY_SUCCESS)
1256
+        if ($outcome[UBE_MOON] != UBE_MOON_DESTROY_SUCCESS)
1258 1257
         {
1259 1258
           $bashing_list[] = "({$player_id}, {$planet_id}, {$combat_data[UBE_TIME]})";
1260 1259
         }
1261
-        if($combat_data[UBE_OPTIONS][UBE_MISSION_TYPE] == MT_ATTACK && $combat_data[UBE_OPTIONS][UBE_DEFENDER_ACTIVE])
1260
+        if ($combat_data[UBE_OPTIONS][UBE_MISSION_TYPE] == MT_ATTACK && $combat_data[UBE_OPTIONS][UBE_DEFENDER_ACTIVE])
1262 1261
         {
1263 1262
           $str_loose_or_win = $outcome[UBE_COMBAT_RESULT] == UBE_COMBAT_RESULT_WIN ? 'raidswin' : 'raidsloose';
1264 1263
           db_user_set_by_id($player_id, "`xpraid` = `xpraid` + 1, `raids` = `raids` + 1, `{$str_loose_or_win}` = `{$str_loose_or_win}` + 1");
@@ -1266,7 +1265,7 @@  discard block
 block discarded – undo
1266 1265
       }
1267 1266
     }
1268 1267
     $bashing_list = implode(',', $bashing_list);
1269
-    if($bashing_list)
1268
+    if ($bashing_list)
1270 1269
     {
1271 1270
       doquery("INSERT INTO {{bashing}} (bashing_user_id, bashing_planet_id, bashing_time) VALUES {$bashing_list};");
1272 1271
     }
Please login to merge, or discard this patch.
includes/includes/flt_functions.php 2 patches
Braces   +9 added lines, -18 removed lines patch added patch discarded remove patch
@@ -1,7 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-function flt_fleet_speed($user, $fleet)
4
-{
3
+function flt_fleet_speed($user, $fleet) {
5 4
   if (!is_array($fleet))
6 5
   {
7 6
     $fleet = array($fleet => 1);
@@ -29,16 +28,13 @@  discard block
 block discarded – undo
29 28
   if($from['galaxy'] != $to['galaxy'])
30 29
   {
31 30
     $distance = abs($from['galaxy'] - $to['galaxy']) * $config->uni_galaxy_distance;
32
-  }
33
-  elseif($from['system'] != $to['system'])
31
+  } elseif($from['system'] != $to['system'])
34 32
   {
35 33
     $distance = abs($from['system'] - $to['system']) * 5 * 19 + 2700;
36
-  }
37
-  elseif($from['planet'] != $to['planet'])
34
+  } elseif($from['planet'] != $to['planet'])
38 35
   {
39 36
     $distance = abs($from['planet'] - $to['planet']) * 5 + 1000;
40
-  }
41
-  else
37
+  } else
42 38
   {
43 39
     $distance = 5;
44 40
   }
@@ -55,8 +51,7 @@  discard block
 block discarded – undo
55 51
  *
56 52
  * @return array
57 53
  */
58
-function flt_travel_data($user_row, $from, $to, $fleet_array, $speed_percent = 10)
59
-{
54
+function flt_travel_data($user_row, $from, $to, $fleet_array, $speed_percent = 10) {
60 55
   $distance = flt_travel_distance($from, $to);
61 56
 
62 57
   $consumption = 0;
@@ -120,8 +115,7 @@  discard block
 block discarded – undo
120 115
   );
121 116
 }
122 117
 
123
-function flt_bashing_check($user, $enemy, $planet_dst, $mission, $flight_duration, $fleet_group = 0)
124
-{
118
+function flt_bashing_check($user, $enemy, $planet_dst, $mission, $flight_duration, $fleet_group = 0) {
125 119
   global $config;
126 120
 
127 121
   $config_bashing_attacks = $config->fleet_bashing_attacks;
@@ -531,8 +525,7 @@  discard block
 block discarded – undo
531 525
       $fleet_ship_count += $amount;
532 526
       $fleet_string     .= "{$unit_id},{$amount};";
533 527
       $db_changeset['unit'][] = OldDbChangeSet::db_changeset_prepare_unit($unit_id, -$amount, $user, $from['id']);
534
-    }
535
-    elseif(in_array($unit_id, sn_get_groups('resources_loot')))
528
+    } elseif(in_array($unit_id, sn_get_groups('resources_loot')))
536 529
     {
537 530
       $planet_fields[pname_resource_name($unit_id)]['delta'] -= $amount;
538 531
     }
@@ -624,8 +617,7 @@  discard block
 block discarded – undo
624 617
 //ini_set('error_reporting', E_ALL ^ E_NOTICE);
625 618
 }
626 619
 
627
-function flt_calculate_ship_to_transport_sort($a, $b)
628
-{
620
+function flt_calculate_ship_to_transport_sort($a, $b) {
629 621
   return $a['transport_effectivness'] == $b['transport_effectivness'] ? 0 : ($a['transport_effectivness'] > $b['transport_effectivness'] ? -1 : 1);
630 622
 }
631 623
 
@@ -634,8 +626,7 @@  discard block
 block discarded – undo
634 626
 // $resource_amount - how much amount of resources need to be transported
635 627
 // $from - transport from
636 628
 // $to - transport to
637
-function flt_calculate_fleet_to_transport($ship_list, $resource_amount, $from, $to)
638
-{
629
+function flt_calculate_fleet_to_transport($ship_list, $resource_amount, $from, $to) {
639 630
   global $user;
640 631
 
641 632
   $ship_data = array();
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -8,11 +8,11 @@  discard block
 block discarded – undo
8 8
   }
9 9
 
10 10
   $speeds = array();
11
-  if(!empty($fleet))
11
+  if (!empty($fleet))
12 12
   {
13 13
     foreach ($fleet as $ship_id => $amount)
14 14
     {
15
-      if($amount && in_array($ship_id, sn_get_groups(array('fleet', 'missile'))))
15
+      if ($amount && in_array($ship_id, sn_get_groups(array('fleet', 'missile'))))
16 16
       {
17 17
         $single_ship_data = get_ship_data($ship_id, $user);
18 18
         $speeds[] = $single_ship_data['speed'];
@@ -26,15 +26,15 @@  discard block
 block discarded – undo
26 26
 function flt_travel_distance($from, $to) {
27 27
   global $config;
28 28
 
29
-  if($from['galaxy'] != $to['galaxy'])
29
+  if ($from['galaxy'] != $to['galaxy'])
30 30
   {
31 31
     $distance = abs($from['galaxy'] - $to['galaxy']) * $config->uni_galaxy_distance;
32 32
   }
33
-  elseif($from['system'] != $to['system'])
33
+  elseif ($from['system'] != $to['system'])
34 34
   {
35 35
     $distance = abs($from['system'] - $to['system']) * 5 * 19 + 2700;
36 36
   }
37
-  elseif($from['planet'] != $to['planet'])
37
+  elseif ($from['planet'] != $to['planet'])
38 38
   {
39 39
     $distance = abs($from['planet'] - $to['planet']) * 5 + 1000;
40 40
   }
@@ -65,14 +65,14 @@  discard block
 block discarded – undo
65 65
 
66 66
   $game_fleet_speed = flt_server_flight_speed_multiplier();
67 67
   $fleet_speed = flt_fleet_speed($user_row, $fleet_array);
68
-  if(!empty($fleet_array) && $fleet_speed && $game_fleet_speed)
68
+  if (!empty($fleet_array) && $fleet_speed && $game_fleet_speed)
69 69
   {
70 70
     $speed_percent = $speed_percent ? max(min($speed_percent, 10), 1) : 10;
71 71
     $real_speed = $speed_percent * sqrt($fleet_speed);
72 72
 
73 73
     $duration = max(1, round((35000 / $speed_percent * sqrt($distance * 10 / $fleet_speed) + 10) / $game_fleet_speed));
74 74
 
75
-    foreach($fleet_array as $ship_id => $ship_count)
75
+    foreach ($fleet_array as $ship_id => $ship_count)
76 76
     {
77 77
       if (!$ship_id || !$ship_count)
78 78
       {
@@ -126,19 +126,19 @@  discard block
 block discarded – undo
126 126
 
127 127
   $config_bashing_attacks = $config->fleet_bashing_attacks;
128 128
   $config_bashing_interval = $config->fleet_bashing_interval;
129
-  if(!$config_bashing_attacks) {
129
+  if (!$config_bashing_attacks) {
130 130
     // Bashing allowed - protection disabled
131 131
     return ATTACK_ALLOWED;
132 132
   }
133 133
 
134 134
   $bashing_result = ATTACK_BASHING;
135
-  if($user['ally_id'] && $enemy['ally_id']) {
135
+  if ($user['ally_id'] && $enemy['ally_id']) {
136 136
     $relations = ali_relations($user['ally_id'], $enemy['ally_id']);
137
-    if(!empty($relations)) {
137
+    if (!empty($relations)) {
138 138
       $relations = $relations[$enemy['ally_id']];
139
-      switch($relations['alliance_diplomacy_relation']) {
139
+      switch ($relations['alliance_diplomacy_relation']) {
140 140
         case ALLY_DIPLOMACY_WAR:
141
-          if(SN_TIME_NOW - $relations['alliance_diplomacy_time'] <= $config->fleet_bashing_war_delay) {
141
+          if (SN_TIME_NOW - $relations['alliance_diplomacy_time'] <= $config->fleet_bashing_war_delay) {
142 142
             $bashing_result = ATTACK_BASHING_WAR_DELAY;
143 143
           } else {
144 144
             return ATTACK_ALLOWED;
@@ -175,9 +175,9 @@  discard block
 block discarded – undo
175 175
 //    }
176 176
 //  }
177 177
   $bashing_fleet_list = fleet_list_bashing($user['id'], $planet_dst);
178
-  foreach($bashing_fleet_list as $fleet_row) {
178
+  foreach ($bashing_fleet_list as $fleet_row) {
179 179
     // Checking for ACS - each ACS count only once
180
-    if($fleet_row['fleet_group']) {
180
+    if ($fleet_row['fleet_group']) {
181 181
       $bashing_list["{$user['id']}_{$fleet_row['fleet_group']}"] = $fleet_row['fleet_start_time'];
182 182
     } else {
183 183
       $bashing_list[] = $fleet_row['fleet_start_time'];
@@ -185,12 +185,12 @@  discard block
 block discarded – undo
185 185
   }
186 186
 
187 187
   // Check for joining to ACS - if there are already fleets in ACS no checks should be done
188
-  if($mission == MT_AKS && $bashing_list["{$user['id']}_{$fleet_group}"]) {
188
+  if ($mission == MT_AKS && $bashing_list["{$user['id']}_{$fleet_group}"]) {
189 189
     return ATTACK_ALLOWED;
190 190
   }
191 191
 
192 192
   $query = doquery("SELECT bashing_time FROM {{bashing}} WHERE bashing_user_id = {$user['id']} AND bashing_planet_id = {$planet_dst['id']} AND bashing_time >= {$time_limit};");
193
-  while($bashing_row = db_fetch($query)) {
193
+  while ($bashing_row = db_fetch($query)) {
194 194
     $bashing_list[] = $bashing_row['bashing_time'];
195 195
   }
196 196
 
@@ -199,9 +199,9 @@  discard block
 block discarded – undo
199 199
   $last_attack = 0;
200 200
   $wave = 0;
201 201
   $attack = 1;
202
-  foreach($bashing_list as &$bash_time) {
202
+  foreach ($bashing_list as &$bash_time) {
203 203
     $attack++;
204
-    if($bash_time - $last_attack > $config_bashing_interval || $attack > $config_bashing_attacks) {
204
+    if ($bash_time - $last_attack > $config_bashing_interval || $attack > $config_bashing_attacks) {
205 205
       $attack = 1;
206 206
       $wave++;
207 207
     }
@@ -212,21 +212,21 @@  discard block
 block discarded – undo
212 212
   return ($wave > $config->fleet_bashing_waves ? $bashing_result : ATTACK_ALLOWED);
213 213
 }
214 214
 
215
-function flt_can_attack($planet_src, $planet_dst, $fleet = array(), $mission, $options = false){$result = null; return sn_function_call('flt_can_attack', array($planet_src, $planet_dst, $fleet, $mission, $options, &$result));}
215
+function flt_can_attack($planet_src, $planet_dst, $fleet = array(), $mission, $options = false) {$result = null; return sn_function_call('flt_can_attack', array($planet_src, $planet_dst, $fleet, $mission, $options, &$result)); }
216 216
 function sn_flt_can_attack($planet_src, $planet_dst, $fleet = array(), $mission, $options = false, &$result) {
217 217
   //TODO: try..catch
218 218
   global $config, $user;
219 219
 
220
-  if($user['vacation']) {
220
+  if ($user['vacation']) {
221 221
     return $result = ATTACK_OWN_VACATION;
222 222
   }
223 223
 
224
-  if(empty($fleet) || !is_array($fleet)) {
224
+  if (empty($fleet) || !is_array($fleet)) {
225 225
     return $result = ATTACK_NO_FLEET;
226 226
   }
227 227
 
228 228
   $sn_groups_mission = sn_get_groups('missions');
229
-  if(!isset($sn_groups_mission[$mission])) {
229
+  if (!isset($sn_groups_mission[$mission])) {
230 230
     return $result = ATTACK_MISSION_ABSENT;
231 231
   }
232 232
   $sn_data_mission = $sn_groups_mission[$mission];
@@ -245,32 +245,32 @@  discard block
 block discarded – undo
245 245
   $resources = 0;
246 246
   $ship_ids = sn_get_groups('fleet');
247 247
   $resource_ids = sn_get_groups('resources_loot');
248
-  foreach($fleet as $ship_id => $ship_count) {
248
+  foreach ($fleet as $ship_id => $ship_count) {
249 249
     $is_ship = in_array($ship_id, $ship_ids);
250 250
     $is_resource = in_array($ship_id, $resource_ids);
251
-    if(!$is_ship && !$is_resource) {
251
+    if (!$is_ship && !$is_resource) {
252 252
       // TODO Спецобработчик для Капитана и модулей
253 253
 //      return ATTACK_WRONG_UNIT;
254 254
     }
255 255
 
256
-    if($ship_count < 0) {
256
+    if ($ship_count < 0) {
257 257
       return $result = $is_ship ? ATTACK_SHIP_COUNT_WRONG : ATTACK_RESOURCE_COUNT_WRONG;
258 258
     }
259 259
 
260
-    if($ship_count > mrc_get_level($user, $planet_src, $ship_id)) {
260
+    if ($ship_count > mrc_get_level($user, $planet_src, $ship_id)) {
261 261
       // TODO ATTACK_NO_MISSILE
262 262
       return $result = $is_ship ? ATTACK_NO_SHIPS : ATTACK_NO_RESOURCES;
263 263
     }
264 264
 
265
-    if($is_ship) {
265
+    if ($is_ship) {
266 266
       $single_ship_data = get_ship_data($ship_id, $user);
267
-      if($single_ship_data[P_SPEED] <= 0) {
267
+      if ($single_ship_data[P_SPEED] <= 0) {
268 268
         return $result = ATTACK_ZERO_SPEED;
269 269
       }
270 270
       $ships += $ship_count;
271 271
       $recyclers += in_array($ship_id, sn_get_groups('flt_recyclers')) ? $ship_count : 0;
272 272
       $spies += $ship_id == SHIP_SPY ? $ship_count : 0;
273
-    } elseif($is_resource) {
273
+    } elseif ($is_resource) {
274 274
       $resources += $ship_count;
275 275
     }
276 276
   }
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
   }
282 282
 */
283 283
 
284
-  if(isset($options['resources']) && $options['resources'] > 0 && !(isset($sn_data_mission['transport']) && $sn_data_mission['transport'])) {
284
+  if (isset($options['resources']) && $options['resources'] > 0 && !(isset($sn_data_mission['transport']) && $sn_data_mission['transport'])) {
285 285
     return $result = ATTACK_RESOURCE_FORBIDDEN;
286 286
   }
287 287
 
@@ -293,35 +293,35 @@  discard block
 block discarded – undo
293 293
   */
294 294
 
295 295
   $speed = $options['fleet_speed_percent'];
296
-  if($speed && ($speed != intval($speed) || $speed < 1 || $speed > 10)) {
296
+  if ($speed && ($speed != intval($speed) || $speed < 1 || $speed > 10)) {
297 297
     return $result = ATTACK_WRONG_SPEED;
298 298
   }
299 299
 
300 300
   $travel_data = flt_travel_data($user, $planet_src, $planet_dst, $fleet, $options['fleet_speed_percent']);
301 301
 
302 302
 
303
-  if(mrc_get_level($user, $planet_src, RES_DEUTERIUM) < $fleet[RES_DEUTERIUM] + $travel_data['consumption']) {
303
+  if (mrc_get_level($user, $planet_src, RES_DEUTERIUM) < $fleet[RES_DEUTERIUM] + $travel_data['consumption']) {
304 304
     return $result = ATTACK_NO_FUEL;
305 305
   }
306 306
 
307
-  if($travel_data['consumption'] > $travel_data['capacity']) {
307
+  if ($travel_data['consumption'] > $travel_data['capacity']) {
308 308
     return $result = ATTACK_TOO_FAR;
309 309
   }
310 310
 
311
-  if($travel_data['hold'] < $resources) {
311
+  if ($travel_data['hold'] < $resources) {
312 312
     return $result = ATTACK_OVERLOADED;
313 313
   }
314 314
 
315 315
   $fleet_start_time = SN_TIME_NOW + $travel_data['duration'];
316 316
 
317 317
   $fleet_group = $options['fleet_group'];
318
-  if($fleet_group) {
319
-    if($mission != MT_AKS) {
318
+  if ($fleet_group) {
319
+    if ($mission != MT_AKS) {
320 320
       return $result = ATTACK_WRONG_MISSION;
321 321
     };
322 322
 
323 323
     $acs = doquery("SELECT * FROM {{aks}} WHERE id = '{$fleet_group}' LIMIT 1;", '', true);
324
-    if(!$acs['id']) {
324
+    if (!$acs['id']) {
325 325
       return $result = ATTACK_NO_ACS;
326 326
     }
327 327
 
@@ -329,70 +329,70 @@  discard block
 block discarded – undo
329 329
       return $result = ATTACK_ACS_WRONG_TARGET;
330 330
     }
331 331
 
332
-    if ($fleet_start_time>$acs['ankunft']) {
332
+    if ($fleet_start_time > $acs['ankunft']) {
333 333
       return $result = ATTACK_ACS_TOO_LATE;
334 334
     }
335 335
   }
336 336
 
337 337
   $flying_fleets = $options['flying_fleets'];
338
-  if(!$flying_fleets) {
338
+  if (!$flying_fleets) {
339 339
 //    $flying_fleets = doquery("SELECT COUNT(fleet_id) AS `flying_fleets` FROM {{fleets}} WHERE `fleet_owner` = '{$user['id']}';", '', true);
340 340
 //    $flying_fleets = $flying_fleets['flying_fleets'];
341 341
     $flying_fleets = fleet_count_flying($user['id']);
342 342
   }
343
-  if(GetMaxFleets($user) <= $flying_fleets && $mission != MT_MISSILE) {
343
+  if (GetMaxFleets($user) <= $flying_fleets && $mission != MT_MISSILE) {
344 344
     return $result = ATTACK_NO_SLOTS;
345 345
   }
346 346
 
347 347
   // В одиночку шпионские зонды могут летать только в миссии Шпионаж, Передислокация и Транспорт
348
-  if($ships && $spies && $spies == $ships && !($mission == MT_SPY || $mission == MT_RELOCATE || $mission == MT_TRANSPORT)) {
348
+  if ($ships && $spies && $spies == $ships && !($mission == MT_SPY || $mission == MT_RELOCATE || $mission == MT_TRANSPORT)) {
349 349
     return $result = ATTACK_SPIES_LONLY;
350 350
   }
351 351
 
352 352
   // Checking for no planet
353
-  if(!$planet_dst['id_owner']) {
354
-    if($mission == MT_COLONIZE && !$fleet[SHIP_COLONIZER]) {
353
+  if (!$planet_dst['id_owner']) {
354
+    if ($mission == MT_COLONIZE && !$fleet[SHIP_COLONIZER]) {
355 355
       return $result = ATTACK_NO_COLONIZER;
356 356
     }
357 357
 
358
-    if($mission == MT_EXPLORE || $mission == MT_COLONIZE) {
358
+    if ($mission == MT_EXPLORE || $mission == MT_COLONIZE) {
359 359
       return $result = ATTACK_ALLOWED;
360 360
     }
361 361
     return $result = ATTACK_NO_TARGET;
362 362
   }
363 363
 
364
-  if($mission == MT_RECYCLE) {
365
-    if($planet_dst['debris_metal'] + $planet_dst['debris_crystal'] <= 0) {
364
+  if ($mission == MT_RECYCLE) {
365
+    if ($planet_dst['debris_metal'] + $planet_dst['debris_crystal'] <= 0) {
366 366
       return $result = ATTACK_NO_DEBRIS;
367 367
     }
368
-    if($recyclers <= 0) {
368
+    if ($recyclers <= 0) {
369 369
       return $result = ATTACK_NO_RECYCLERS;
370 370
     }
371 371
     return $result = ATTACK_ALLOWED;
372 372
   }
373 373
 
374 374
   // Got planet. Checking if it is ours
375
-  if($planet_dst['id_owner'] == $user['id']) {
376
-    if($mission == MT_TRANSPORT || $mission == MT_RELOCATE) {
375
+  if ($planet_dst['id_owner'] == $user['id']) {
376
+    if ($mission == MT_TRANSPORT || $mission == MT_RELOCATE) {
377 377
       return $result = ATTACK_ALLOWED;
378 378
     }
379 379
     return $planet_src['id'] == $planet_dst['id'] ? ATTACK_SAME : ATTACK_OWN;
380 380
   }
381 381
 
382 382
   // No, planet not ours. Cutting mission that can't be send to not-ours planet
383
-  if($mission == MT_RELOCATE || $mission == MT_COLONIZE || $mission == MT_EXPLORE) {
383
+  if ($mission == MT_RELOCATE || $mission == MT_COLONIZE || $mission == MT_EXPLORE) {
384 384
     return $result = ATTACK_WRONG_MISSION;
385 385
   }
386 386
 
387 387
   $enemy = db_user_by_id($planet_dst['id_owner']);
388 388
   // We cannot attack or send resource to users in VACATION mode
389
-  if($enemy['vacation'] && $mission != MT_RECYCLE) {
389
+  if ($enemy['vacation'] && $mission != MT_RECYCLE) {
390 390
     return $result = ATTACK_VACATION;
391 391
   }
392 392
 
393 393
   // Multi IP protection
394 394
   // TODO: Here we need a procedure to check proxies
395
-  if(sys_is_multiaccount($user, $enemy)) {
395
+  if (sys_is_multiaccount($user, $enemy)) {
396 396
     return $result = ATTACK_SAME_IP;
397 397
   }
398 398
 
@@ -400,8 +400,8 @@  discard block
 block discarded – undo
400 400
   $enemy_points = $enemy['total_points'];
401 401
 
402 402
   // Is it transport? If yes - checking for buffing to prevent mega-alliance destroyer
403
-  if($mission == MT_TRANSPORT) {
404
-    if($user_points >= $enemy_points || $config->allow_buffing) {
403
+  if ($mission == MT_TRANSPORT) {
404
+    if ($user_points >= $enemy_points || $config->allow_buffing) {
405 405
       return $result = ATTACK_ALLOWED;
406 406
     } else {
407 407
       return $result = ATTACK_BUFFING;
@@ -411,65 +411,65 @@  discard block
 block discarded – undo
411 411
   // Only aggresive missions passed to this point. HOLD counts as passive but aggresive
412 412
 
413 413
   // Is it admin with planet protection?
414
-  if($planet_dst['id_level'] > $user['authlevel']) {
414
+  if ($planet_dst['id_level'] > $user['authlevel']) {
415 415
     return $result = ATTACK_ADMIN;
416 416
   }
417 417
 
418 418
   // Okay. Now skipping protection checks for inactive longer then 1 week
419
-  if(!$enemy['onlinetime'] || $enemy['onlinetime'] >= (SN_TIME_NOW - 60*60*24*7)) {
420
-    if(
419
+  if (!$enemy['onlinetime'] || $enemy['onlinetime'] >= (SN_TIME_NOW - 60 * 60 * 24 * 7)) {
420
+    if (
421 421
       (classSupernova::$gc->general->playerIsNoobByPoints($enemy_points) && !classSupernova::$gc->general->playerIsNoobByPoints($user_points))
422 422
       ||
423 423
       (classSupernova::$gc->general->playerIs1stStrongerThen2nd($user_points, $enemy_points))
424 424
     ) {
425
-      if($mission != MT_HOLD) {
425
+      if ($mission != MT_HOLD) {
426 426
         return $result = ATTACK_NOOB;
427 427
       }
428
-      if($mission == MT_HOLD && !($user['ally_id'] && $user['ally_id'] == $enemy['ally_id'] && $config->ally_help_weak)) {
428
+      if ($mission == MT_HOLD && !($user['ally_id'] && $user['ally_id'] == $enemy['ally_id'] && $config->ally_help_weak)) {
429 429
         return $result = ATTACK_NOOB;
430 430
       }
431 431
     }
432 432
   }
433 433
 
434 434
   // Is it HOLD mission? If yes - there should be ally deposit
435
-  if($mission == MT_HOLD) {
436
-    if(mrc_get_level($user, $planet_dst, STRUC_ALLY_DEPOSIT)) {
435
+  if ($mission == MT_HOLD) {
436
+    if (mrc_get_level($user, $planet_dst, STRUC_ALLY_DEPOSIT)) {
437 437
       return $result = ATTACK_ALLOWED;
438 438
     }
439 439
     return $result = ATTACK_NO_ALLY_DEPOSIT;
440 440
   }
441 441
 
442
-  if($mission == MT_SPY) {
442
+  if ($mission == MT_SPY) {
443 443
     return $result = $spies >= 1 ? ATTACK_ALLOWED : ATTACK_NO_SPIES;
444 444
   }
445 445
 
446 446
   // Is it MISSILE mission?
447
-  if($mission == MT_MISSILE) {
447
+  if ($mission == MT_MISSILE) {
448 448
     $sn_data_mip = get_unit_param(UNIT_DEF_MISSILE_INTERPLANET);
449
-    if(mrc_get_level($user, $planet_src, STRUC_SILO) < $sn_data_mip[P_REQUIRE][STRUC_SILO]) {
449
+    if (mrc_get_level($user, $planet_src, STRUC_SILO) < $sn_data_mip[P_REQUIRE][STRUC_SILO]) {
450 450
       return $result = ATTACK_NO_SILO;
451 451
     }
452 452
 
453
-    if(!$fleet[UNIT_DEF_MISSILE_INTERPLANET]) {
453
+    if (!$fleet[UNIT_DEF_MISSILE_INTERPLANET]) {
454 454
       return $result = ATTACK_NO_MISSILE;
455 455
     }
456 456
 
457 457
     $distance = abs($planet_dst['system'] - $planet_src['system']);
458 458
     $mip_range = flt_get_missile_range($user);
459
-    if($distance > $mip_range || $planet_dst['galaxy'] != $planet_src['galaxy']) {
459
+    if ($distance > $mip_range || $planet_dst['galaxy'] != $planet_src['galaxy']) {
460 460
       return $result = ATTACK_MISSILE_TOO_FAR;
461 461
     }
462 462
 
463
-    if(isset($options['target_structure']) && $options['target_structure'] && !in_array($options['target_structure'], sn_get_groups('defense_active'))) {
463
+    if (isset($options['target_structure']) && $options['target_structure'] && !in_array($options['target_structure'], sn_get_groups('defense_active'))) {
464 464
       return $result = ATTACK_WRONG_STRUCTURE;
465 465
     }
466 466
   }
467 467
 
468
-  if($mission == MT_DESTROY && $planet_dst['planet_type'] != PT_MOON) {
468
+  if ($mission == MT_DESTROY && $planet_dst['planet_type'] != PT_MOON) {
469 469
     return $result = ATTACK_WRONG_MISSION;
470 470
   }
471 471
 
472
-  if($mission == MT_ATTACK || $mission == MT_AKS || $mission == MT_DESTROY) {
472
+  if ($mission == MT_ATTACK || $mission == MT_AKS || $mission == MT_DESTROY) {
473 473
     return $result = flt_bashing_check($user, $enemy, $planet_dst, $mission, $travel_data['duration'], $fleet_group);
474 474
   }
475 475
 
@@ -495,18 +495,18 @@  discard block
 block discarded – undo
495 495
   $from = $from['planet'];
496 496
 
497 497
   $can_attack = flt_can_attack($from, $to, $fleet, $mission, $options);
498
-  if($can_attack != ATTACK_ALLOWED) {
498
+  if ($can_attack != ATTACK_ALLOWED) {
499 499
     $internal_transaction ? sn_db_transaction_rollback() : false;
500 500
     return $can_attack;
501 501
   }
502 502
 
503 503
   $fleet_group = isset($options['fleet_group']) ? floatval($options['fleet_group']) : 0;
504 504
 
505
-  $travel_data  = flt_travel_data($user, $from, $to, $fleet, $options['fleet_speed_percent']);
505
+  $travel_data = flt_travel_data($user, $from, $to, $fleet, $options['fleet_speed_percent']);
506 506
 
507 507
   $fleet_start_time = SN_TIME_NOW + $travel_data['duration'];
508 508
 
509
-  if($mission == MT_EXPLORE || $mission == MT_HOLD) {
509
+  if ($mission == MT_EXPLORE || $mission == MT_HOLD) {
510 510
     $stay_duration = $options['stay_time'] * 3600;
511 511
     $stay_time     = $fleet_start_time + $stay_duration;
512 512
   } else {
@@ -519,20 +519,20 @@  discard block
 block discarded – undo
519 519
   $fleet_string      = '';
520 520
   $db_changeset = array();
521 521
   $planet_fields = array();
522
-  foreach($fleet as $unit_id => $amount)
522
+  foreach ($fleet as $unit_id => $amount)
523 523
   {
524
-    if(!$amount || !$unit_id)
524
+    if (!$amount || !$unit_id)
525 525
     {
526 526
       continue;
527 527
     }
528 528
 
529
-    if(in_array($unit_id, sn_get_groups('fleet')))
529
+    if (in_array($unit_id, sn_get_groups('fleet')))
530 530
     {
531 531
       $fleet_ship_count += $amount;
532 532
       $fleet_string     .= "{$unit_id},{$amount};";
533 533
       $db_changeset['unit'][] = OldDbChangeSet::db_changeset_prepare_unit($unit_id, -$amount, $user, $from['id']);
534 534
     }
535
-    elseif(in_array($unit_id, sn_get_groups('resources_loot')))
535
+    elseif (in_array($unit_id, sn_get_groups('resources_loot')))
536 536
     {
537 537
       $planet_fields[pname_resource_name($unit_id)]['delta'] -= $amount;
538 538
     }
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
 
641 641
   $ship_data = array();
642 642
   $fleet_array = array();
643
-  foreach($ship_list as $transport_id => $cork)
643
+  foreach ($ship_list as $transport_id => $cork)
644 644
   {
645 645
     $ship_data[$transport_id] = flt_travel_data($user, $from, $to, array($transport_id => 1), 10);
646 646
   }
@@ -649,10 +649,10 @@  discard block
 block discarded – undo
649 649
   $fleet_hold = 0;
650 650
   $fleet_capacity = 0;
651 651
   $fuel_total = $fuel_left = mrc_get_level($user, $from, RES_DEUTERIUM);
652
-  foreach($ship_data as $transport_id => &$ship_info)
652
+  foreach ($ship_data as $transport_id => &$ship_info)
653 653
   {
654 654
     $ship_loaded = min($ship_list[$transport_id], ceil($resource_amount / $ship_info['hold']), floor($fuel_left / $ship_info['consumption']));
655
-    if($ship_loaded)
655
+    if ($ship_loaded)
656 656
     {
657 657
       $fleet_array[$transport_id] = $ship_loaded;
658 658
       $resource_amount -= min($resource_amount, $ship_info['hold'] * $ship_loaded);
Please login to merge, or discard this patch.
jumpgate.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -14,39 +14,39 @@  discard block
 block discarded – undo
14 14
 
15 15
 lng_include('fleet');
16 16
 
17
-if($TargetPlanet = sys_get_param_id('jmpto'))
17
+if ($TargetPlanet = sys_get_param_id('jmpto'))
18 18
 {
19 19
   sn_db_transaction_start();
20 20
   db_user_by_id($user['id'], true, 'id');
21 21
   $planetrow = DBStaticPlanet::db_planet_by_id($planetrow['id'], true);
22
-  if(!($NextJumpTime = uni_get_time_to_jump($planetrow)))
22
+  if (!($NextJumpTime = uni_get_time_to_jump($planetrow)))
23 23
   {
24 24
     $TargetGate = DBStaticPlanet::db_planet_by_id($TargetPlanet, true, '`id`, `last_jump_time`');
25
-    if(mrc_get_level($user, $TargetGate, STRUC_MOON_GATE) > 0)
25
+    if (mrc_get_level($user, $TargetGate, STRUC_MOON_GATE) > 0)
26 26
     {
27
-      $NextDestTime = uni_get_time_to_jump ( $TargetGate );
28
-      if(!$NextDestTime)
27
+      $NextDestTime = uni_get_time_to_jump($TargetGate);
28
+      if (!$NextDestTime)
29 29
       {
30 30
         // $SubQueryOri = "";
31 31
         // $SubQueryDes = "";
32 32
         $ship_list = sys_get_param('ships');
33 33
         $db_changeset = array();
34
-        foreach($ship_list as $ship_id => $ship_count)
34
+        foreach ($ship_list as $ship_id => $ship_count)
35 35
         {
36
-          if(!in_array($ship_id, sn_get_groups('fleet')))
36
+          if (!in_array($ship_id, sn_get_groups('fleet')))
37 37
           {
38 38
             continue;
39 39
           }
40 40
 
41 41
           $ship_count = max(0, min(floor($ship_count), mrc_get_level($user, $planetrow, $ship_id)));
42
-          if($ship_count)
42
+          if ($ship_count)
43 43
           {
44 44
             $db_changeset['unit'][] = OldDbChangeSet::db_changeset_prepare_unit($ship_id, -$ship_count, $user, $planetrow['id']);
45 45
             $db_changeset['unit'][] = OldDbChangeSet::db_changeset_prepare_unit($ship_id, $ship_count, $user, $TargetGate['id']);
46 46
           }
47 47
         }
48 48
         // Dit monsieur, y avait quelque chose a envoyer ???
49
-        if(!empty($db_changeset))
49
+        if (!empty($db_changeset))
50 50
         {
51 51
           DBStaticPlanet::db_planet_set_by_id($TargetGate['id'], "`last_jump_time` = " . SN_TIME_NOW . "");
52 52
           DBStaticPlanet::db_planet_set_by_id($planetrow['id'], "`last_jump_time` = " . SN_TIME_NOW . "");
@@ -55,31 +55,31 @@  discard block
 block discarded – undo
55 55
           db_user_set_by_id($user['id'], "`current_planet` = '{$TargetGate['id']}'");
56 56
 
57 57
           $planetrow['last_jump_time'] = SN_TIME_NOW;
58
-          $RetMessage = $lang['gate_jump_done'] ." - ". pretty_time(uni_get_time_to_jump($planetrow));
58
+          $RetMessage = $lang['gate_jump_done'] . " - " . pretty_time(uni_get_time_to_jump($planetrow));
59 59
         } else {
60 60
           $RetMessage = $lang['gate_wait_data'];
61 61
         }
62 62
       } else {
63
-        $RetMessage = $lang['gate_wait_dest'] ." - ". pretty_time($NextDestTime);
63
+        $RetMessage = $lang['gate_wait_dest'] . " - " . pretty_time($NextDestTime);
64 64
       }
65 65
     } else {
66 66
       $RetMessage = $lang['gate_no_dest_g'];
67 67
     }
68 68
   } else {
69
-    $RetMessage = $lang['gate_wait_star'] ." - ". pretty_time($NextJumpTime);
69
+    $RetMessage = $lang['gate_wait_star'] . " - " . pretty_time($NextJumpTime);
70 70
   }
71 71
   sn_db_transaction_commit();
72 72
   messageBox($RetMessage, $lang['tech'][STRUC_MOON_GATE], "jumpgate.php", 10);
73 73
 } else {
74 74
   $template = gettemplate('jumpgate', true);
75
-  if(mrc_get_level($user, $planetrow, STRUC_MOON_GATE) > 0)
75
+  if (mrc_get_level($user, $planetrow, STRUC_MOON_GATE) > 0)
76 76
   {
77 77
     $Combo = '';
78 78
     $MoonList = DBStaticPlanet::db_planet_list_moon_other($user['id'], $planetrow['id']);
79 79
     // while($CurMoon = db_fetch($MoonList))
80
-    foreach($MoonList as $CurMoon)
80
+    foreach ($MoonList as $CurMoon)
81 81
     {
82
-      if(mrc_get_level($user, $CurMoon, STRUC_MOON_GATE) >= 1)
82
+      if (mrc_get_level($user, $CurMoon, STRUC_MOON_GATE) >= 1)
83 83
       {
84 84
         $NextJumpTime = uni_get_time_to_jump($CurMoon);
85 85
         $template->assign_block_vars('moon', array(
@@ -93,9 +93,9 @@  discard block
 block discarded – undo
93 93
       }
94 94
     }
95 95
 
96
-    foreach(sn_get_groups('fleet') as $Ship)
96
+    foreach (sn_get_groups('fleet') as $Ship)
97 97
     {
98
-      if(($ship_count = mrc_get_level($user, $planetrow, $Ship)) <= 0)
98
+      if (($ship_count = mrc_get_level($user, $planetrow, $Ship)) <= 0)
99 99
       {
100 100
         continue;
101 101
       }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -115,8 +115,7 @@
 block discarded – undo
115 115
     ));
116 116
 
117 117
     display($template, $lang['tech'][STRUC_MOON_GATE]);
118
-  }
119
-  else
118
+  } else
120 119
   {
121 120
     messageBox($lang['gate_no_src_ga'], $lang['tech'][STRUC_MOON_GATE], "overview.php", 10);
122 121
   }
Please login to merge, or discard this patch.