Completed
Push — work-fleets ( abbbcf...8b8b7f )
by SuperNova.WS
05:13
created
includes/includes/flt_flying_fleet_handler2.php 1 patch
Spacing   +22 added lines, -26 removed lines patch added patch discarded remove patch
@@ -38,15 +38,11 @@  discard block
 block discarded – undo
38 38
 // ------------------------------------------------------------------
39 39
 function flt_flyingFleetsSort($a, $b) {
40 40
   // Сравниваем время флотов - кто раньше, тот и первый обрабатывается
41
-  return $a['fleet_time'] > $b['fleet_time'] ? 1 : ($a['fleet_time'] < $b['fleet_time'] ? -1 :
42
-    // Если время - одинаковое, сравниваем события флотов
41
+  return $a['fleet_time'] > $b['fleet_time'] ? 1 : ($a['fleet_time'] < $b['fleet_time'] ? -1 : // Если время - одинаковое, сравниваем события флотов
43 42
     // Если события - одинаковые, то флоты равны
44
-    ($a['fleet_event'] == $b['fleet_event'] ? 0 :
45
-      // Если события разные - первыми считаем прибывающие флоты
46
-      ($a['fleet_event'] == EVENT_FLT_ARRIVE ? 1 : ($b['fleet_event'] == EVENT_FLT_ARRIVE ? -1 :
47
-        // Если нет прибывающих флотов - дальше считаем флоты, которые закончили миссию
48
-        ($a['fleet_event'] == EVENT_FLT_ACOMPLISH ? 1 : ($b['fleet_event'] == EVENT_FLT_ACOMPLISH ? -1 :
49
-          // Если нет флотов, закончивших задание - остались возвращающиеся флоты, которые равны между собой
43
+    ($a['fleet_event'] == $b['fleet_event'] ? 0 : // Если события разные - первыми считаем прибывающие флоты
44
+      ($a['fleet_event'] == EVENT_FLT_ARRIVE ? 1 : ($b['fleet_event'] == EVENT_FLT_ARRIVE ? -1 : // Если нет прибывающих флотов - дальше считаем флоты, которые закончили миссию
45
+        ($a['fleet_event'] == EVENT_FLT_ACOMPLISH ? 1 : ($b['fleet_event'] == EVENT_FLT_ACOMPLISH ? -1 : // Если нет флотов, закончивших задание - остались возвращающиеся флоты, которые равны между собой
50 46
           // TODO: Добавить еще проверку по ID флота и/или времени запуска - что бы обсчитывать их в порядке запуска
51 47
           (
52 48
           0 // Вообще сюда доходить не должно - будет отсекаться на равенстве событий
@@ -60,7 +56,7 @@  discard block
 block discarded – undo
60 56
 function log_file($msg) {
61 57
   static $handler;
62 58
 
63
-  if(!$handler) {
59
+  if (!$handler) {
64 60
     $handler = fopen('event.log', 'a+');
65 61
   }
66 62
 
@@ -100,12 +96,12 @@  discard block
 block discarded – undo
100 96
   */
101 97
   global $config, $debug;
102 98
 
103
-  if($config->game_disable != GAME_DISABLE_NONE || $skip_fleet_update) {
99
+  if ($config->game_disable != GAME_DISABLE_NONE || $skip_fleet_update) {
104 100
     return;
105 101
   }
106 102
 
107 103
   sn_db_transaction_start();
108
-  if($config->db_loadItem('game_disable') != GAME_DISABLE_NONE || SN_TIME_NOW - strtotime($config->db_loadItem('fleet_update_last')) <= $config->fleet_update_interval) {
104
+  if ($config->db_loadItem('game_disable') != GAME_DISABLE_NONE || SN_TIME_NOW - strtotime($config->db_loadItem('fleet_update_last')) <= $config->fleet_update_interval) {
109 105
     sn_db_transaction_rollback();
110 106
 
111 107
     return;
@@ -113,14 +109,14 @@  discard block
 block discarded – undo
113 109
 
114 110
 
115 111
   // Watchdog timer
116
-  if($config->db_loadItem('fleet_update_lock')) {
117
-    if(defined('DEBUG_FLYING_FLEETS')) {
112
+  if ($config->db_loadItem('fleet_update_lock')) {
113
+    if (defined('DEBUG_FLYING_FLEETS')) {
118 114
       $random = 0;
119 115
     } else {
120 116
       $random = mt_rand(240, 300);
121 117
     }
122 118
 
123
-    if(SN_TIME_NOW - strtotime($config->fleet_update_lock) <= $random) {
119
+    if (SN_TIME_NOW - strtotime($config->fleet_update_lock) <= $random) {
124 120
       sn_db_transaction_rollback();
125 121
 
126 122
       return;
@@ -144,11 +140,11 @@  discard block
 block discarded – undo
144 140
   $missions_used = array();
145 141
 
146 142
   $objFleetList = FleetList::dbGetFleetListCurrentTick();
147
-  foreach($objFleetList->_container as $objFleet) {
143
+  foreach ($objFleetList->_container as $objFleet) {
148 144
     set_time_limit(15);
149 145
     // TODO - Унифицировать код с темплейтным разбором эвентов на планете!
150 146
     $missions_used[$objFleet->mission_type] = 1;
151
-    if($objFleet->time_arrive_to_target <= SN_TIME_NOW && !$objFleet->isReturning()) {
147
+    if ($objFleet->time_arrive_to_target <= SN_TIME_NOW && !$objFleet->isReturning()) {
152 148
       $fleet_event_list[] = array(
153 149
         'object'      => $objFleet,
154 150
         'fleet_time'  => $objFleet->time_arrive_to_target,
@@ -156,7 +152,7 @@  discard block
 block discarded – undo
156 152
       );
157 153
     }
158 154
 
159
-    if($objFleet->time_mission_job_complete > 0 && $objFleet->time_mission_job_complete <= SN_TIME_NOW && !$objFleet->isReturning()) {
155
+    if ($objFleet->time_mission_job_complete > 0 && $objFleet->time_mission_job_complete <= SN_TIME_NOW && !$objFleet->isReturning()) {
160 156
       $fleet_event_list[] = array(
161 157
         'object'      => $objFleet,
162 158
         'fleet_time'  => $objFleet->time_mission_job_complete,
@@ -164,7 +160,7 @@  discard block
 block discarded – undo
164 160
       );
165 161
     }
166 162
 
167
-    if($objFleet->time_return_to_source <= SN_TIME_NOW) {
163
+    if ($objFleet->time_return_to_source <= SN_TIME_NOW) {
168 164
       $fleet_event_list[] = array(
169 165
         'object'      => $objFleet,
170 166
         'fleet_time'  => $objFleet->time_return_to_source,
@@ -190,17 +186,17 @@  discard block
 block discarded – undo
190 186
 //    MT_MISSILE => 'flt_mission_missile.php',
191 187
     MT_EXPLORE   => 'flt_mission_explore',
192 188
   );
193
-  foreach($missions_used as $mission_id => $cork) {
189
+  foreach ($missions_used as $mission_id => $cork) {
194 190
     require_once(SN_ROOT_PHYSICAL . "includes/includes/{$mission_files[$mission_id]}" . DOT_PHP_EX);
195 191
   }
196 192
 
197 193
 //log_file('Обработка миссий');
198 194
   $sn_groups_mission = sn_get_groups('missions');
199
-  foreach($fleet_event_list as $fleet_event) {
195
+  foreach ($fleet_event_list as $fleet_event) {
200 196
     // TODO: Указатель тут потом сделать
201 197
     // TODO: СЕЙЧАС НАДО ПРОВЕРЯТЬ ПО БАЗЕ - А ЖИВОЙ ЛИ ФЛОТ?!
202 198
     $fleet_row = $fleet_event['fleet_row'];
203
-    if(empty($fleet_event['object'])) {
199
+    if (empty($fleet_event['object'])) {
204 200
       // Fleet was destroyed in course of previous actions
205 201
       continue;
206 202
     }
@@ -224,20 +220,20 @@  discard block
 block discarded – undo
224 220
 
225 221
     $objFleet->dbLoad($objFleet->dbId);
226 222
 
227
-    if(!$objFleet->dbId) {
223
+    if (!$objFleet->dbId) {
228 224
       // Fleet was destroyed in course of previous actions
229 225
       sn_db_transaction_commit();
230 226
       continue;
231 227
     }
232 228
 
233
-    if($fleet_event['fleet_event'] == EVENT_FLT_RETURN) {
229
+    if ($fleet_event['fleet_event'] == EVENT_FLT_RETURN) {
234 230
       // Fleet returns to planet
235 231
       $objFleet->RestoreFleetToPlanet(true, false);
236 232
       sn_db_transaction_commit();
237 233
       continue;
238 234
     }
239 235
 
240
-    if($fleet_event['fleet_event'] == EVENT_FLT_ARRIVE && $objFleet->isReturning()) {
236
+    if ($fleet_event['fleet_event'] == EVENT_FLT_ARRIVE && $objFleet->isReturning()) {
241 237
       // При событии EVENT_FLT_ARRIVE флот всегда должен иметь fleet_mess == 0
242 238
       // В противном случае это означает, что флот уже был обработан ранее - например, при САБе
243 239
       sn_db_transaction_commit();
@@ -257,13 +253,13 @@  discard block
 block discarded – undo
257 253
     $objMission->dst_planet = $mission_data['dst_planet'] ? db_planet_by_vector($objFleet->target_coordinates_typed(), '', true, '`id`, `id_owner`, `name`') : null;
258 254
     $objMission->fleet_event = $fleet_event['fleet_event'];
259 255
 
260
-    if($objMission->dst_planet && $objMission->dst_planet['id_owner']) {
256
+    if ($objMission->dst_planet && $objMission->dst_planet['id_owner']) {
261 257
       $update_result = sys_o_get_updated($objMission->dst_planet['id_owner'], $objMission->dst_planet['id'], $objFleet->time_arrive_to_target);
262 258
       $objMission->dst_user = !empty($objMission->dst_user) ? $update_result['user'] : null;
263 259
       $objMission->dst_planet = $update_result['planet'];
264 260
     }
265 261
 
266
-    switch($objFleet->mission_type) {
262
+    switch ($objFleet->mission_type) {
267 263
       // Для боевых атак нужно обновлять по САБу и по холду - таки надо возвращать данные из обработчика миссий!
268 264
       case MT_AKS:
269 265
       case MT_ATTACK:
Please login to merge, or discard this patch.
includes/includes/flt_mission_colonize.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -20,14 +20,14 @@  discard block
 block discarded – undo
20 20
   $TargetAddress = sprintf($lang['sys_adress_planet'], $fleet_end_coordinates['galaxy'], $fleet_end_coordinates['system'], $fleet_end_coordinates['planet']);
21 21
 
22 22
   $TheMessage = $lang['sys_colo_no_colonizer'];
23
-  if($objFleet->shipsGetTotalById(SHIP_COLONIZER) >= 1) {
23
+  if ($objFleet->shipsGetTotalById(SHIP_COLONIZER) >= 1) {
24 24
     $TheMessage = $lang['sys_colo_notfree'];
25
-    if(empty($mission_data->dst_planet)) {
25
+    if (empty($mission_data->dst_planet)) {
26 26
       $iPlanetCount = get_player_current_colonies($src_user_row);
27 27
 
28 28
       // Can we colonize more planets?
29 29
       $TheMessage = $lang['sys_colo_maxcolo'];
30
-      if($iPlanetCount < get_player_max_colonies($src_user_row)) {
30
+      if ($iPlanetCount < get_player_max_colonies($src_user_row)) {
31 31
         // Yes, we can colonize
32 32
         $TheMessage = $lang['sys_colo_badpos'];
33 33
 
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
           $fleet_end_coordinates['galaxy'], $fleet_end_coordinates['system'], $fleet_end_coordinates['planet'],
36 36
           $objFleet->playerOwnerId, "{$lang['sys_colo_defaultname']} {$iPlanetCount}", false,
37 37
           array('user_row' => $src_user_row));
38
-        if($NewOwnerPlanet) {
38
+        if ($NewOwnerPlanet) {
39 39
           $TheMessage = $lang['sys_colo_arrival'] . $TargetAddress . $lang['sys_colo_allisok'];
40 40
           msg_send_simple_message($objFleet->playerOwnerId, '', $objFleet->time_arrive_to_target, MSG_TYPE_SPY, $lang['sys_colo_mess_from'], $lang['sys_colo_mess_report'], $TheMessage);
41 41
 
Please login to merge, or discard this patch.
includes/includes/flt_mission_attack.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,14 +17,14 @@
 block discarded – undo
17 17
 function flt_mission_attack($objMission) {
18 18
   $objFleet = $objMission->fleet;
19 19
 
20
-  if($objFleet->shipsGetTotal() <= 0) {
20
+  if ($objFleet->shipsGetTotal() <= 0) {
21 21
     return null;
22 22
   }
23 23
 
24 24
   $destination_user = $objMission->dst_user;
25 25
   $destination_planet = $objMission->dst_planet;
26 26
 
27
-  if(
27
+  if (
28 28
     // Нет данных о планете назначения или её владельце
29 29
     empty($destination_user) || empty($destination_planet) || !is_array($destination_user) || !is_array($destination_planet)
30 30
     ||
Please login to merge, or discard this patch.
includes/includes/flt_mission_explore.php 1 patch
Spacing   +29 added lines, -30 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
   global $lang, $config;
22 22
   static $ship_data, $rates;
23 23
 
24
-  if(empty($mission_data->fleet_event) || $mission_data->fleet_event != EVENT_FLT_ACOMPLISH) {
24
+  if (empty($mission_data->fleet_event) || $mission_data->fleet_event != EVENT_FLT_ACOMPLISH) {
25 25
     return CACHE_NONE;
26 26
   }
27 27
 
@@ -46,10 +46,10 @@  discard block
 block discarded – undo
46 46
   $outcome_value = &$result['$outcome_value'];
47 47
   $outcome_list = &$result['$outcome_list'];
48 48
 
49
-  if(!$ship_data) {
50
-    foreach(sn_get_groups('fleet') as $unit_id) {
49
+  if (!$ship_data) {
50
+    foreach (sn_get_groups('fleet') as $unit_id) {
51 51
       $unit_info = get_unit_param($unit_id);
52
-      if($unit_info[P_UNIT_TYPE] != UNIT_SHIPS || !isset($unit_info['engine'][0]['speed']) || !$unit_info['engine'][0]['speed']) {
52
+      if ($unit_info[P_UNIT_TYPE] != UNIT_SHIPS || !isset($unit_info['engine'][0]['speed']) || !$unit_info['engine'][0]['speed']) {
53 53
         continue;
54 54
       }
55 55
       $ship_data[$unit_id][P_COST_METAL] = get_unit_cost_in($unit_info[P_COST]);
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 
60 60
   $max_metal_cost = 0;
61 61
   $fleet_real_array = $objFleet->shipsGetArray();
62
-  foreach($fleet_real_array as $ship_id => $ship_amount) {
62
+  foreach ($fleet_real_array as $ship_id => $ship_amount) {
63 63
     $ship_cost_in_metal = $ship_amount * $ship_data[$ship_id][P_COST_METAL];
64 64
     $result['$fleet_metal_points'] += $ship_amount * $ship_data[$ship_id][P_COST_METAL];
65 65
     // Рассчитываем стоимость самого дорого корабля в металле
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
   $outcome_list[FLT_EXPEDITION_OUTCOME_NONE]['chance'] = ceil(200 / pow($flt_stay_hours, 1 / 1.7));
74 74
 
75 75
   $chance_max = 0;
76
-  foreach($outcome_list as $key => &$value) {
77
-    if(!$value['chance']) {
76
+  foreach ($outcome_list as $key => &$value) {
77
+    if (!$value['chance']) {
78 78
       unset($outcome_list[$key]);
79 79
       continue;
80 80
     }
@@ -82,13 +82,13 @@  discard block
 block discarded – undo
82 82
   }
83 83
   $outcome_value = mt_rand(0, $chance_max);
84 84
   $outcome_description = &$outcome_list[$mission_outcome = FLT_EXPEDITION_OUTCOME_NONE];
85
-  foreach($outcome_list as $key => &$value) {
86
-    if(!$value['chance']) {
85
+  foreach ($outcome_list as $key => &$value) {
86
+    if (!$value['chance']) {
87 87
       continue;
88 88
     }
89 89
     $mission_outcome = $key;
90 90
     $outcome_description = $value;
91
-    if($outcome_value <= $outcome_description['value']) {
91
+    if ($outcome_value <= $outcome_description['value']) {
92 92
       break;
93 93
     }
94 94
   }
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 //  $outcome_mission_sub = -1;
106 106
 
107 107
   $fleet_found = array();
108
-  switch($mission_outcome) {
108
+  switch ($mission_outcome) {
109 109
     case FLT_EXPEDITION_OUTCOME_LOST_FLEET:
110 110
       $objFleet->shipsCountApplyLossMultiplier(mt_rand(1, 3) * mt_rand(200000, 300000) / 1000000);
111 111
     break;
@@ -126,8 +126,8 @@  discard block
 block discarded – undo
126 126
 
127 127
       // Ограничиваем корабли только теми, чья стоимость в металле меньше или равно стоимости самого дорогого корабля
128 128
       $can_be_found = array();
129
-      foreach($ship_data as $ship_id => $ship_info) {
130
-        if($ship_info['metal_cost'] < $max_metal_cost) {
129
+      foreach ($ship_data as $ship_id => $ship_info) {
130
+        if ($ship_info['metal_cost'] < $max_metal_cost) {
131 131
           $can_be_found[$ship_id] = $ship_info['metal_cost'];
132 132
         }
133 133
       }
@@ -135,13 +135,13 @@  discard block
 block discarded – undo
135 135
       unset($can_be_found[SHIP_COLONIZER]);
136 136
       unset($can_be_found[SHIP_SPY]);
137 137
 
138
-      while(count($can_be_found) && $found_in_metal >= max($can_be_found)) {
138
+      while (count($can_be_found) && $found_in_metal >= max($can_be_found)) {
139 139
         $found_index = mt_rand(1, count($can_be_found)) - 1;
140 140
         $found_ship = array_slice($can_be_found, $found_index, 1, true);
141 141
         $found_ship_cost = reset($found_ship);
142 142
         $found_ship_id = key($found_ship);
143 143
 
144
-        if($found_ship_cost > $found_in_metal) {
144
+        if ($found_ship_cost > $found_in_metal) {
145 145
           unset($can_be_found[$found_ship_id]);
146 146
         } else {
147 147
           $found_ship_count = mt_rand(1, floor($found_in_metal / $found_ship_cost));
@@ -150,10 +150,10 @@  discard block
 block discarded – undo
150 150
         }
151 151
       }
152 152
 
153
-      if(empty($fleet_found)) {
153
+      if (empty($fleet_found)) {
154 154
         $msg_text_addon = $lang['flt_mission_expedition']['outcomes'][$mission_outcome]['no_result'];
155 155
       } else {
156
-        foreach($fleet_found as $unit_id => $unit_amount) {
156
+        foreach ($fleet_found as $unit_id => $unit_amount) {
157 157
           $objFleet->shipAdjustCount($unit_id, $unit_amount);
158 158
         }
159 159
       }
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 
178 178
       $objFleet->resourcesAdjust($resources_found);
179 179
 
180
-      if(array_sum($resources_found) == 0) {
180
+      if (array_sum($resources_found) == 0) {
181 181
         $msg_text_addon = $lang['flt_mission_expedition']['outcomes'][$mission_outcome]['no_result'];
182 182
       }
183 183
     break;
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
       // Рассчитываем количество найденной ТМ
189 189
       $found_dark_matter = floor(min($outcome_percent * $result['$fleet_metal_points'] / $rates[RES_DARK_MATTER], 10000) * mt_rand(750000, 1000000) / 1000000);
190 190
 
191
-      if(!$found_dark_matter) {
191
+      if (!$found_dark_matter) {
192 192
         $msg_text_addon = $lang['flt_mission_expedition']['outcomes'][$mission_outcome]['no_result'];
193 193
       }
194 194
     break;
@@ -202,40 +202,39 @@  discard block
 block discarded – undo
202 202
 
203 203
   mission_expedition_result_adjust($result, $objFleet);
204 204
 
205
-  if($found_dark_matter) {
205
+  if ($found_dark_matter) {
206 206
     rpg_points_change($objFleet->playerOwnerId, RPG_EXPEDITION, $found_dark_matter, 'Expedition Bonus');
207 207
     $msg_text_addon = sprintf($lang['flt_mission_expedition']['found_dark_matter'], $found_dark_matter);
208 208
   }
209 209
 
210
-  if(!empty($fleet_lost)) {
210
+  if (!empty($fleet_lost)) {
211 211
     $msg_text_addon = $lang['flt_mission_expedition']['lost_fleet'];
212
-    foreach($fleet_lost as $ship_id => $ship_amount) {
212
+    foreach ($fleet_lost as $ship_id => $ship_amount) {
213 213
       $msg_text_addon .= $lang['tech'][$ship_id] . ' - ' . $ship_amount . "\r\n";
214 214
     }
215 215
   }
216 216
 
217
-  if(!empty($fleet_found)) {
217
+  if (!empty($fleet_found)) {
218 218
     $msg_text_addon = $lang['flt_mission_expedition']['found_fleet'];
219
-    foreach($fleet_found as $ship_id => $ship_amount) {
219
+    foreach ($fleet_found as $ship_id => $ship_amount) {
220 220
       $msg_text_addon .= $lang['tech'][$ship_id] . ' - ' . $ship_amount . "\r\n";
221 221
     }
222 222
   }
223 223
 
224
-  if(!empty($resources_found) && array_sum($resources_found) > 0) {
224
+  if (!empty($resources_found) && array_sum($resources_found) > 0) {
225 225
     $msg_text_addon = $lang['flt_mission_expedition']['found_resources'];
226
-    foreach($resources_found as $resource_id => $resource_amount) {
226
+    foreach ($resources_found as $resource_id => $resource_amount) {
227 227
       $msg_text_addon .= $lang['tech'][$resource_id] . ' - ' . $resource_amount . "\r\n";
228 228
     }
229 229
   }
230 230
 
231
-  if(!$msg_text) {
231
+  if (!$msg_text) {
232 232
     $messages = &$lang['flt_mission_expedition']['outcomes'][$mission_outcome]['messages'];
233
-    if($outcome_mission_sub >= 0 && is_array($messages)) {
233
+    if ($outcome_mission_sub >= 0 && is_array($messages)) {
234 234
       $messages = &$messages[$outcome_mission_sub];
235 235
     }
236 236
 
237
-    $msg_text = is_string($messages) ? $messages :
238
-      (is_array($messages) ? $messages[mt_rand(0, count($messages) - 1)] : '');
237
+    $msg_text = is_string($messages) ? $messages : (is_array($messages) ? $messages[mt_rand(0, count($messages) - 1)] : '');
239 238
   }
240 239
 
241 240
   $fleet_row_end_coordinates_without_type = $objFleet->target_coordinates_without_type();
Please login to merge, or discard this patch.
includes/template.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 function gettemplatename($u_dpath) {
11 11
   static $template_names = array();
12 12
 
13
-  if(!isset($template_names[$u_dpath])) {
13
+  if (!isset($template_names[$u_dpath])) {
14 14
     $template_names[$u_dpath] = file_exists(SN_ROOT_PHYSICAL . $u_dpath . 'tmpl.ini') ? sys_file_read(SN_ROOT_PHYSICAL . $u_dpath . 'tmpl.ini') : TEMPLATE_NAME;
15 15
   }
16 16
 
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
  * @param $sn_menu_extra
53 53
  */
54 54
 function tpl_menu_merge_extra(&$sn_menu, &$sn_menu_extra) {
55
-  if(empty($sn_menu) || empty($sn_menu_extra)) {
55
+  if (empty($sn_menu) || empty($sn_menu_extra)) {
56 56
     return;
57 57
   }
58 58
 
59
-  foreach($sn_menu_extra as $menu_item_id => $menu_item) {
60
-    if(empty($menu_item['LOCATION'])) {
59
+  foreach ($sn_menu_extra as $menu_item_id => $menu_item) {
60
+    if (empty($menu_item['LOCATION'])) {
61 61
       $sn_menu[$menu_item_id] = $menu_item;
62 62
       continue;
63 63
     }
@@ -66,16 +66,16 @@  discard block
 block discarded – undo
66 66
     unset($menu_item['LOCATION']);
67 67
 
68 68
     $is_positioned = $item_location[0];
69
-    if($is_positioned == '+' || $is_positioned == '-') {
69
+    if ($is_positioned == '+' || $is_positioned == '-') {
70 70
       $item_location = substr($item_location, 1);
71 71
     } else {
72 72
       $is_positioned = '';
73 73
     }
74 74
 
75
-    if($item_location) {
75
+    if ($item_location) {
76 76
       $menu_keys = array_keys($sn_menu);
77 77
       $insert_position = array_search($item_location, $menu_keys);
78
-      if($insert_position === false) {
78
+      if ($insert_position === false) {
79 79
         $insert_position = count($sn_menu) - 1;
80 80
         $is_positioned = '+';
81 81
         $item_location = '';
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
     $spliced = array_splice($sn_menu, $insert_position, count($sn_menu) - $insert_position);
89 89
     $sn_menu[$menu_item_id] = $menu_item;
90 90
 
91
-    if(!$is_positioned && $item_location) {
91
+    if (!$is_positioned && $item_location) {
92 92
       unset($spliced[$item_location]);
93 93
     }
94 94
     $sn_menu = array_merge($sn_menu, $spliced);
@@ -104,24 +104,24 @@  discard block
 block discarded – undo
104 104
 function tpl_menu_assign_to_template(&$sn_menu, &$template) {
105 105
   global $lang;
106 106
 
107
-  if(empty($sn_menu) || !is_array($sn_menu)) {
107
+  if (empty($sn_menu) || !is_array($sn_menu)) {
108 108
     return;
109 109
   }
110 110
 
111
-  foreach($sn_menu as $menu_item_id => $menu_item) {
112
-    if(!$menu_item) {
111
+  foreach ($sn_menu as $menu_item_id => $menu_item) {
112
+    if (!$menu_item) {
113 113
       continue;
114 114
     }
115 115
 
116
-    if(is_string($menu_item_id)) {
116
+    if (is_string($menu_item_id)) {
117 117
       $menu_item['ID'] = $menu_item_id;
118 118
     }
119 119
 
120
-    if($menu_item['TYPE'] == 'lang') {
120
+    if ($menu_item['TYPE'] == 'lang') {
121 121
       $lang_string = &$lang;
122
-      if(preg_match('#(\w+)(?:\[(\w+)\])?(?:\[(\w+)\])?(?:\[(\w+)\])?(?:\[(\w+)\])?#', $menu_item['ITEM'], $matches) && count($matches) > 1) {
123
-        for($i = 1; $i < count($matches); $i++) {
124
-          if(defined($matches[$i])) {
122
+      if (preg_match('#(\w+)(?:\[(\w+)\])?(?:\[(\w+)\])?(?:\[(\w+)\])?(?:\[(\w+)\])?#', $menu_item['ITEM'], $matches) && count($matches) > 1) {
123
+        for ($i = 1; $i < count($matches); $i++) {
124
+          if (defined($matches[$i])) {
125 125
             $matches[$i] = constant($matches[$i]);
126 126
           }
127 127
           $lang_string = &$lang_string[$matches[$i]];
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
     $menu_item['ALT'] = htmlentities($menu_item['ALT']);
134 134
     $menu_item['TITLE'] = htmlentities($menu_item['TITLE']);
135 135
 
136
-    if(!empty($menu_item['ICON'])) {
137
-      if(is_string($menu_item['ICON'])) {
136
+    if (!empty($menu_item['ICON'])) {
137
+      if (is_string($menu_item['ICON'])) {
138 138
         $menu_item['ICON_PATH'] = $menu_item['ICON'];
139 139
       } else {
140 140
         $menu_item['ICON'] = $menu_item_id;
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
     'MENU_START_HIDE'     => !empty($_COOKIE[SN_COOKIE . '_menu_hidden']) || defined('SN_GOOGLE'),
165 165
   ));
166 166
 
167
-  if(isset($template_result['MENU_CUSTOMIZE'])) {
167
+  if (isset($template_result['MENU_CUSTOMIZE'])) {
168 168
     $template->assign_vars(array(
169 169
       'PLAYER_OPTION_MENU_SHOW_ON_BUTTON'   => classSupernova::$user_options[PLAYER_OPTION_MENU_SHOW_ON_BUTTON],
170 170
       'PLAYER_OPTION_MENU_HIDE_ON_BUTTON'   => classSupernova::$user_options[PLAYER_OPTION_MENU_HIDE_ON_BUTTON],
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
     ));
179 179
   }
180 180
 
181
-  if(defined('IN_ADMIN') && IN_ADMIN === true && !empty($user['authlevel']) && $user['authlevel'] > 0) {
181
+  if (defined('IN_ADMIN') && IN_ADMIN === true && !empty($user['authlevel']) && $user['authlevel'] > 0) {
182 182
     tpl_menu_merge_extra($sn_menu_admin, $sn_menu_admin_extra);
183 183
     tpl_menu_assign_to_template($sn_menu_admin, $template);
184 184
   } else {
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
   $in_admin = defined('IN_ADMIN') && IN_ADMIN === true;
219 219
   $is_login = defined('LOGIN_LOGOUT') && LOGIN_LOGOUT === true;
220 220
 
221
-  if(is_object($page)) {
221
+  if (is_object($page)) {
222 222
     isset($page->_rootref['MENU']) ? $isDisplayMenu = $page->_rootref['MENU'] : false;
223 223
     isset($page->_rootref['NAVBAR']) ? $isDisplayTopNav = $page->_rootref['NAVBAR'] : false;
224 224
 
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
     !isset($page->_rootref['PAGE_HEADER']) && $title ? $page->assign_var('PAGE_HEADER', $title) : false;
227 227
   }
228 228
 
229
-  if(empty($user['id']) || !is_numeric($user['id'])) {
229
+  if (empty($user['id']) || !is_numeric($user['id'])) {
230 230
     $isDisplayMenu = false;
231 231
     $isDisplayTopNav = false;
232 232
   }
@@ -238,10 +238,10 @@  discard block
 block discarded – undo
238 238
   $user_time_measured_unix = intval(isset($user_time_diff[PLAYER_OPTION_TIME_DIFF_MEASURE_TIME]) ? strtotime($user_time_diff[PLAYER_OPTION_TIME_DIFF_MEASURE_TIME]) : 0);
239 239
 
240 240
   $font_size = !empty($_COOKIE[SN_COOKIE_F]) ? $_COOKIE[SN_COOKIE_F] : classSupernova::$user_options[PLAYER_OPTION_BASE_FONT_SIZE];
241
-  if(strpos($font_size, '%') !== false) {
241
+  if (strpos($font_size, '%') !== false) {
242 242
     // Размер шрифта в процентах
243 243
     $font_size = min(max(floatval($font_size), FONT_SIZE_PERCENT_MIN), FONT_SIZE_PERCENT_MAX) . '%';
244
-  } elseif(strpos($font_size, 'px') !== false) {
244
+  } elseif (strpos($font_size, 'px') !== false) {
245 245
     // Размер шрифта в пикселях
246 246
     $font_size = min(max(floatval($font_size), FONT_SIZE_PIXELS_MIN), FONT_SIZE_PIXELS_MAX) . 'px';
247 247
   } else {
@@ -253,10 +253,10 @@  discard block
 block discarded – undo
253 253
 
254 254
   $template = gettemplate('_global_header', true);
255 255
 
256
-  if(!empty($sn_mvc['javascript'])) {
257
-    foreach($sn_mvc['javascript'] as $page_name => $script_list) {
258
-      if(empty($page_name) || $page_name == $sn_page_name) {
259
-        foreach($script_list as $filename => $content) {
256
+  if (!empty($sn_mvc['javascript'])) {
257
+    foreach ($sn_mvc['javascript'] as $page_name => $script_list) {
258
+      if (empty($page_name) || $page_name == $sn_page_name) {
259
+        foreach ($script_list as $filename => $content) {
260 260
           $template_result['.']['javascript'][] = array(
261 261
             'FILE'    => $filename,
262 262
             'CONTENT' => $content,
@@ -290,9 +290,9 @@  discard block
 block discarded – undo
290 290
   $sn_mvc['css'][''] = array_merge($standard_css, $sn_mvc['css']['']);
291 291
 
292 292
 
293
-  foreach($sn_mvc['css'] as $page_name => $script_list) {
294
-    if(empty($page_name) || $page_name == $sn_page_name) {
295
-      foreach($script_list as $filename => $content) {
293
+  foreach ($sn_mvc['css'] as $page_name => $script_list) {
294
+    if (empty($page_name) || $page_name == $sn_page_name) {
295
+      foreach ($script_list as $filename => $content) {
296 296
         $template_result['.']['css'][] = array(
297 297
           'FILE'    => $filename,
298 298
           'CONTENT' => $content,
@@ -339,12 +339,12 @@  discard block
 block discarded – undo
339 339
   $template->assign_recursive($template_result);
340 340
   displayP(parsetemplate($template));
341 341
 
342
-  if(($isDisplayMenu || $in_admin) && !isset($_COOKIE['menu_disable'])) {
342
+  if (($isDisplayMenu || $in_admin) && !isset($_COOKIE['menu_disable'])) {
343 343
     // $AdminPage = $AdminPage ? $user['authlevel'] : 0;
344 344
     displayP(parsetemplate(tpl_render_menu()));
345 345
   }
346 346
 
347
-  if($isDisplayTopNav && !$in_admin) {
347
+  if ($isDisplayTopNav && !$in_admin) {
348 348
     displayP(parsetemplate(tpl_render_topnav($user, $planetrow)));
349 349
   }
350 350
 
@@ -352,8 +352,8 @@  discard block
 block discarded – undo
352 352
 
353 353
   !is_array($page) ? $page = array($page) : false;
354 354
   $result_added = false;
355
-  foreach($page as $page_item) {
356
-    if(!$result_added && is_object($page_item) && isset($page_item->_tpldata['result'])) {
355
+  foreach ($page as $page_item) {
356
+    if (!$result_added && is_object($page_item) && isset($page_item->_tpldata['result'])) {
357 357
       $page_item = gettemplate('_result_message', $page_item);
358 358
       $temp = $page_item->files['_result_message'];
359 359
       unset($page_item->files['_result_message']);
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
   ));
377 377
   displayP(parsetemplate($template));
378 378
 
379
-  $user['authlevel'] >= 3 && $config->debug ? $debug->echo_log() : false;;
379
+  $user['authlevel'] >= 3 && $config->debug ? $debug->echo_log() : false; ;
380 380
 
381 381
   sn_db_disconnect();
382 382
 
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
  * @param string         $type
415 415
  */
416 416
 function tpl_topnav_event_build(&$template, $FleetList, $type = 'fleet') {
417
-  if(empty($FleetList)) {
417
+  if (empty($FleetList)) {
418 418
     return;
419 419
   }
420 420
 
@@ -423,19 +423,19 @@  discard block
 block discarded – undo
423 423
   $fleet_event_count = 0;
424 424
   $fleet_flying_sorter = array();
425 425
   $fleet_flying_events = array();
426
-  foreach($FleetList->_container as $objFleet) {
426
+  foreach ($FleetList->_container as $objFleet) {
427 427
     $will_return = true;
428
-    if(!$objFleet->isReturning()) {
428
+    if (!$objFleet->isReturning()) {
429 429
       // cut fleets on Hold and Expedition
430
-      if($objFleet->time_arrive_to_target >= SN_TIME_NOW) {
430
+      if ($objFleet->time_arrive_to_target >= SN_TIME_NOW) {
431 431
         $objFleet->mission_type == MT_RELOCATE ? $will_return = false : false;
432 432
         tpl_topnav_event_build_helper($objFleet->time_arrive_to_target, EVENT_FLEET_ARRIVE, $lang['sys_event_arrive'], $objFleet->target_coordinates_typed(), !$will_return, $objFleet, $fleet_flying_sorter, $fleet_flying_events, $fleet_event_count);
433 433
       }
434
-      if($objFleet->time_mission_job_complete) {
434
+      if ($objFleet->time_mission_job_complete) {
435 435
         tpl_topnav_event_build_helper($objFleet->time_mission_job_complete, EVENT_FLEET_STAY, $lang['sys_event_stay'], $objFleet->target_coordinates_typed(), false, $objFleet, $fleet_flying_sorter, $fleet_flying_events, $fleet_event_count);
436 436
       }
437 437
     }
438
-    if($will_return) {
438
+    if ($will_return) {
439 439
       tpl_topnav_event_build_helper($objFleet->time_return_to_source, EVENT_FLEET_RETURN, $lang['sys_event_return'], $objFleet->launch_coordinates_typed(), true, $objFleet, $fleet_flying_sorter, $fleet_flying_events, $fleet_event_count);
440 440
     }
441 441
   }
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
   asort($fleet_flying_sorter);
444 444
 
445 445
   $fleet_flying_count = $FleetList->count();
446
-  foreach($fleet_flying_sorter as $fleet_event_id => $fleet_time) {
446
+  foreach ($fleet_flying_sorter as $fleet_event_id => $fleet_time) {
447 447
     $fleet_event = &$fleet_flying_events[$fleet_event_id];
448 448
     $template->assign_block_vars("flying_{$type}s", array(
449 449
       'TIME' => max(0, $fleet_time - SN_TIME_NOW),
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
 function sn_tpl_render_topnav(&$user, $planetrow) {
472 472
   global $lang, $config, $sn_module_list, $template_result, $sn_mvc;
473 473
 
474
-  if(!is_array($user)) {
474
+  if (!is_array($user)) {
475 475
     return '';
476 476
   }
477 477
 
@@ -492,8 +492,8 @@  discard block
 block discarded – undo
492 492
 
493 493
   $ThisUsersPlanets = db_planet_list_sorted($user);
494 494
   // while ($CurPlanet = db_fetch($ThisUsersPlanets))
495
-  foreach($ThisUsersPlanets as $CurPlanet) {
496
-    if($CurPlanet['destruyed']) {
495
+  foreach ($ThisUsersPlanets as $CurPlanet) {
496
+    if ($CurPlanet['destruyed']) {
497 497
       continue;
498 498
     }
499 499
 
@@ -517,8 +517,8 @@  discard block
 block discarded – undo
517 517
    */
518 518
   $fleet_flying_list = array();
519 519
   $fleet_flying_list[0] = FleetList::dbGetFleetListByOwnerId($user['id']);
520
-  foreach($fleet_flying_list[0]->_container as $fleet_id => $objFleet) {
521
-    if(empty($fleet_flying_list[$objFleet->mission_type])) {
520
+  foreach ($fleet_flying_list[0]->_container as $fleet_id => $objFleet) {
521
+    if (empty($fleet_flying_list[$objFleet->mission_type])) {
522 522
       $fleet_flying_list[$objFleet->mission_type] = new FleetList();
523 523
     }
524 524
     $fleet_flying_list[$objFleet->mission_type][$fleet_id] = $objFleet;
@@ -530,8 +530,8 @@  discard block
 block discarded – undo
530 530
   que_tpl_parse($template, QUE_RESEARCH, $user, array(), null, !classSupernova::$user_options[PLAYER_OPTION_NAVBAR_RESEARCH_WIDE]);
531 531
   que_tpl_parse($template, SUBQUE_FLEET, $user, $planetrow, null, true);
532 532
 
533
-  if(!empty($sn_mvc['navbar_prefix_button']) && is_array($sn_mvc['navbar_prefix_button'])) {
534
-    foreach($sn_mvc['navbar_prefix_button'] as $navbar_button_image => $navbar_button_url) {
533
+  if (!empty($sn_mvc['navbar_prefix_button']) && is_array($sn_mvc['navbar_prefix_button'])) {
534
+    foreach ($sn_mvc['navbar_prefix_button'] as $navbar_button_image => $navbar_button_url) {
535 535
       $template->assign_block_vars('navbar_prefix_button', array(
536 536
         'IMAGE'        => $navbar_button_image,
537 537
         'URL_RELATIVE' => $navbar_button_url,
@@ -545,13 +545,13 @@  discard block
 block discarded – undo
545 545
   $time_now_parsed = getdate(SN_TIME_NOW);
546 546
   $time_local_parsed = getdate(defined('SN_CLIENT_TIME_LOCAL') ? SN_CLIENT_TIME_LOCAL : SN_TIME_NOW);
547 547
 
548
-  if($config->game_news_overview) {
548
+  if ($config->game_news_overview) {
549 549
     $user_last_read_safe = intval($user['news_lastread']);
550 550
     nws_render($template, "WHERE UNIX_TIMESTAMP(`tsTimeStamp`) >= {$user_last_read_safe}", $config->game_news_overview);
551 551
   }
552 552
 
553 553
   $notes_query = db_note_list_by_owner($user['id'], true);
554
-  while($note_row = db_fetch($notes_query)) {
554
+  while ($note_row = db_fetch($notes_query)) {
555 555
     note_assign($template, $note_row);
556 556
   }
557 557
 
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
     'QUE_ID'   => QUE_RESEARCH,
563 563
     'QUE_HTML' => 'topnav',
564 564
 
565
-    'RESEARCH_ONGOING' => (boolean)$user['que'],
565
+    'RESEARCH_ONGOING' => (boolean) $user['que'],
566 566
 
567 567
     'TIME_TEXT'       => sprintf($str_date_format, $time_now_parsed['year'], $lang['months'][$time_now_parsed['mon']], $time_now_parsed['mday'],
568 568
       $time_now_parsed['hours'], $time_now_parsed['minutes'], $time_now_parsed['seconds']
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
     'QUE_STRUCTURES' => QUE_STRUCTURES,
640 640
   ));
641 641
 
642
-  if((defined('SN_RENDER_NAVBAR_PLANET') && SN_RENDER_NAVBAR_PLANET === true) || ($user['option_list'][OPT_INTERFACE]['opt_int_navbar_resource_force'] && SN_RENDER_NAVBAR_PLANET !== false)) {
642
+  if ((defined('SN_RENDER_NAVBAR_PLANET') && SN_RENDER_NAVBAR_PLANET === true) || ($user['option_list'][OPT_INTERFACE]['opt_int_navbar_resource_force'] && SN_RENDER_NAVBAR_PLANET !== false)) {
643 643
     tpl_set_resource_info($template, $planetrow);
644 644
     $template->assign_vars(array(
645 645
       'SN_RENDER_NAVBAR_PLANET' => true,
@@ -654,12 +654,12 @@  discard block
 block discarded – undo
654 654
  * @param template|string $template
655 655
  */
656 656
 function displayP($template) {
657
-  if(is_object($template)) {
658
-    if(empty($template->parsed)) {
657
+  if (is_object($template)) {
658
+    if (empty($template->parsed)) {
659 659
       parsetemplate($template);
660 660
     }
661 661
 
662
-    foreach($template->files as $section => $filename) {
662
+    foreach ($template->files as $section => $filename) {
663 663
       $template->display($section);
664 664
     }
665 665
   } else {
@@ -674,11 +674,11 @@  discard block
 block discarded – undo
674 674
  * @return mixed
675 675
  */
676 676
 function parsetemplate($template, $array = false) {
677
-  if(is_object($template)) {
677
+  if (is_object($template)) {
678 678
     global $user;
679 679
 
680
-    if(!empty($array) && is_array($array)) {
681
-      foreach($array as $key => $data) {
680
+    if (!empty($array) && is_array($array)) {
681
+      foreach ($array as $key => $data) {
682 682
         $template->assign_var($key, $data);
683 683
       }
684 684
     }
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
 
720 720
   $template_ex = '.tpl.html';
721 721
 
722
-  if($template === false) {
722
+  if ($template === false) {
723 723
     return sys_file_read(TEMPLATE_DIR . '/' . $files . $template_ex);
724 724
   }
725 725
 
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
   !empty($sn_mvc['i18n']['']) ? lng_load_i18n($sn_mvc['i18n']['']) : false;
740 740
   $sn_page_name ? lng_load_i18n($sn_mvc['i18n'][$sn_page_name]) : false;
741 741
 
742
-  foreach($files as &$filename) {
742
+  foreach ($files as &$filename) {
743 743
     $filename = $filename . $template_ex;
744 744
   }
745 745
 
@@ -764,13 +764,13 @@  discard block
 block discarded – undo
764 764
     'LANG'     => $language ? $language : '',
765 765
     'referral' => $id_ref ? '&id_ref=' . $id_ref : '',
766 766
 
767
-    'REQUEST_PARAMS' => !empty($url_params) ? '?' . implode('&', $url_params) : '',// "?lang={$language}" . ($id_ref ? "&id_ref={$id_ref}" : ''),
767
+    'REQUEST_PARAMS' => !empty($url_params) ? '?' . implode('&', $url_params) : '', // "?lang={$language}" . ($id_ref ? "&id_ref={$id_ref}" : ''),
768 768
     'FILENAME'       => basename($_SERVER['PHP_SELF']),
769 769
   ));
770 770
 
771
-  foreach(lng_get_list() as $lng_id => $lng_data) {
772
-    if(isset($lng_data['LANG_VARIANTS']) && is_array($lng_data['LANG_VARIANTS'])) {
773
-      foreach($lng_data['LANG_VARIANTS'] as $lang_variant) {
771
+  foreach (lng_get_list() as $lng_id => $lng_data) {
772
+    if (isset($lng_data['LANG_VARIANTS']) && is_array($lng_data['LANG_VARIANTS'])) {
773
+      foreach ($lng_data['LANG_VARIANTS'] as $lang_variant) {
774 774
         $lng_data1 = $lng_data;
775 775
         $lng_data1 = array_merge($lng_data1, $lang_variant);
776 776
         $template->assign_block_vars('language', $lng_data1);
@@ -793,8 +793,8 @@  discard block
 block discarded – undo
793 793
   $que = $que['ques'][$que_type][$planet['id_owner']][$planet['id']];
794 794
 
795 795
   $que_length = 0;
796
-  if(!empty($que)) {
797
-    foreach($que as $que_item) {
796
+  if (!empty($que)) {
797
+    foreach ($que as $que_item) {
798 798
       $template->assign_block_vars('que', que_tpl_parse_element($que_item));
799 799
     }
800 800
     $que_length = count($que);
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
 function tpl_planet_density_info(&$template, &$density_price_chart, $user_dark_matter) {
812 812
   global $lang;
813 813
 
814
-  foreach($density_price_chart as $density_price_index => &$density_price_data) {
814
+  foreach ($density_price_chart as $density_price_index => &$density_price_data) {
815 815
     $density_cost = $density_price_data;
816 816
     $density_number_style = pretty_number($density_cost, true, $user_dark_matter, false, false);
817 817
 
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
 function tpl_assign_select(&$template, $name, $values) {
836 836
   !is_array($values) ? $values = array($values => $values) : false;
837 837
 
838
-  foreach($values as $key => $value) {
838
+  foreach ($values as $key => $value) {
839 839
     $template->assign_block_vars($name, array(
840 840
       'KEY'   => htmlentities($key, ENT_COMPAT, 'UTF-8'),
841 841
       'VALUE' => htmlentities($value, ENT_COMPAT, 'UTF-8'),
Please login to merge, or discard this patch.
includes/classes/Fleet.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
   public function dbInsert() {
285 285
     // WARNING! MISSION TIMES MUST BE SET WITH set_times() method!
286 286
     // TODO - more checks!
287
-    if(empty($this->_time_launch)) {
287
+    if (empty($this->_time_launch)) {
288 288
       die('Fleet time not set!');
289 289
     }
290 290
 
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
     // Записываем изменения в БД
365 365
     $this->dbSave();
366 366
 
367
-    if($this->_group_id) {
367
+    if ($this->_group_id) {
368 368
       // TODO: Make here to delete only one AKS - by adding aks_fleet_count to AKS table
369 369
       db_fleet_aks_purge();
370 370
     }
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
     sn_db_transaction_check(true);
425 425
 
426 426
     // Если флот уже обработан - не существует или возращается - тогда ничего не делаем
427
-    if($this->isEmpty() || ($this->_is_returning == 1 && $only_resources)) {
427
+    if ($this->isEmpty() || ($this->_is_returning == 1 && $only_resources)) {
428 428
       return $result;
429 429
     }
430 430
 
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
 
445 445
     // TODO - Проверка, что планета всё еще существует на указанных координатах, а не телепортировалась, не удалена хозяином, не уничтожена врагом
446 446
     // Флот, который возвращается на захваченную планету, пропадает
447
-    if($start && $this->_is_returning == 1 && $planet_arrival['id_owner'] != $this->_playerOwnerId) {
447
+    if ($start && $this->_is_returning == 1 && $planet_arrival['id_owner'] != $this->_playerOwnerId) {
448 448
       $result = RestoreFleetToPlanet($this, $start, $only_resources, $result);
449 449
 
450 450
       $this->dbDelete();
@@ -452,20 +452,20 @@  discard block
 block discarded – undo
452 452
       return $result;
453 453
     }
454 454
 
455
-    if(!$only_resources) {
455
+    if (!$only_resources) {
456 456
       // Landing ships
457 457
       $db_changeset = array();
458 458
 
459
-      if($this->_playerOwnerId == $planet_arrival['id_owner']) {
459
+      if ($this->_playerOwnerId == $planet_arrival['id_owner']) {
460 460
         $fleet_array = $this->shipsGetArray();
461
-        foreach($fleet_array as $ship_id => $ship_count) {
462
-          if($ship_count) {
461
+        foreach ($fleet_array as $ship_id => $ship_count) {
462
+          if ($ship_count) {
463 463
             $db_changeset['unit'][] = sn_db_unit_changeset_prepare($ship_id, $ship_count, $user, $planet_arrival['id']);
464 464
           }
465 465
         }
466 466
 
467 467
         // Adjusting ship amount on planet
468
-        if(!empty($db_changeset)) {
468
+        if (!empty($db_changeset)) {
469 469
           db_changeset_apply($db_changeset);
470 470
         }
471 471
       }
@@ -476,13 +476,13 @@  discard block
 block discarded – undo
476 476
     }
477 477
 
478 478
     // Restoring resources to planet
479
-    if($this->resourcesGetTotal() != 0) {
479
+    if ($this->resourcesGetTotal() != 0) {
480 480
       $fleet_resources = $this->resourcesGetList();
481 481
       db_planet_set_by_id($planet_arrival['id'],
482 482
         "`metal` = `metal` + '{$fleet_resources[RES_METAL]}', `crystal` = `crystal` + '{$fleet_resources[RES_CRYSTAL]}', `deuterium` = `deuterium` + '{$fleet_resources[RES_DEUTERIUM]}'");
483 483
     }
484 484
 
485
-    if(!$only_resources) {
485
+    if (!$only_resources) {
486 486
       $this->dbDelete();
487 487
     }
488 488
 
@@ -516,15 +516,15 @@  discard block
 block discarded – undo
516 516
    */
517 517
   // TODO - separate shipList and unitList
518 518
   public function unitsSetFromArray($unit_array) {
519
-    foreach($unit_array as $unit_id => $unit_count) {
519
+    foreach ($unit_array as $unit_id => $unit_count) {
520 520
       $unit_count = floatval($unit_count);
521
-      if(!$unit_count) {
521
+      if (!$unit_count) {
522 522
         continue;
523 523
       }
524 524
 
525
-      if($this->isShip($unit_id)) {
525
+      if ($this->isShip($unit_id)) {
526 526
         $this->unitList->unitSetCount($unit_id, $unit_count);
527
-      } elseif($this->isResource($unit_id)) {
527
+      } elseif ($this->isResource($unit_id)) {
528 528
         $this->resource_list[$unit_id] = $unit_count;
529 529
       } else {
530 530
         throw new Exception('Trying to pass to fleet non-resource and non-ship ' . var_export($unit_array, true), ERR_ERROR);
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
   public function parse_missile_db_row($missile_db_row) {
554 554
 //    $this->_reset();
555 555
 
556
-    if(empty($missile_db_row) || !is_array($missile_db_row)) {
556
+    if (empty($missile_db_row) || !is_array($missile_db_row)) {
557 557
       return;
558 558
     }
559 559
 
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
   public function shipsGetCapacityRecyclers(array $recycler_info) {
690 690
     $recyclers_incoming_capacity = 0;
691 691
     $fleet_data = $this->shipsGetArray();
692
-    foreach($recycler_info as $recycler_id => $recycler_data) {
692
+    foreach ($recycler_info as $recycler_id => $recycler_data) {
693 693
       $recyclers_incoming_capacity += $fleet_data[$recycler_id] * $recycler_data['capacity'];
694 694
     }
695 695
 
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
    * @param array $resource_list
727 727
    */
728 728
   public function resourcesSet($resource_list) {
729
-    if(!empty($this->propertiesAdjusted['resource_list'])) {
729
+    if (!empty($this->propertiesAdjusted['resource_list'])) {
730 730
       throw new PropertyAccessException('Property "resource_list" already was adjusted so no SET is possible until dbSave in ' . get_called_class() . '::unitSetResourceList', ERR_ERROR);
731 731
     }
732 732
     $this->resourcesAdjust($resource_list, true);
@@ -740,13 +740,13 @@  discard block
 block discarded – undo
740 740
   public function resourcesAdjust($resource_delta_list, $replace_value = false) {
741 741
     !is_array($resource_delta_list) ? $resource_delta_list = array() : false;
742 742
 
743
-    foreach($resource_delta_list as $resource_id => $unit_delta) {
744
-      if(!UnitResourceLoot::is_in_group($resource_id) || !($unit_delta = floor($unit_delta))) {
743
+    foreach ($resource_delta_list as $resource_id => $unit_delta) {
744
+      if (!UnitResourceLoot::is_in_group($resource_id) || !($unit_delta = floor($unit_delta))) {
745 745
         // Not a resource or no resources - continuing
746 746
         continue;
747 747
       }
748 748
 
749
-      if($replace_value) {
749
+      if ($replace_value) {
750 750
         $this->resource_list[$resource_id] = $unit_delta;
751 751
       } else {
752 752
         $this->resource_list[$resource_id] += $unit_delta;
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
       }
756 756
 
757 757
       // Check for negative unit value
758
-      if($this->resource_list[$resource_id] < 0) {
758
+      if ($this->resource_list[$resource_id] < 0) {
759 759
         // TODO
760 760
         throw new Exception('Resource ' . $resource_id . ' will become negative in ' . get_called_class() . '::unitAdjustResourceList', ERR_ERROR);
761 761
       }
Please login to merge, or discard this patch.
includes/classes/UBE/UBEFleet.php 1 patch
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -162,20 +162,20 @@  discard block
 block discarded – undo
162 162
       $this->owner_id,
163 163
       $this->db_id,
164 164
 
165
-      (float)$this->UBE_PLANET[PLANET_ID],
165
+      (float) $this->UBE_PLANET[PLANET_ID],
166 166
       "'" . db_escape($this->UBE_PLANET[PLANET_NAME]) . "'",
167
-      (int)$this->UBE_PLANET[PLANET_GALAXY],
168
-      (int)$this->UBE_PLANET[PLANET_SYSTEM],
169
-      (int)$this->UBE_PLANET[PLANET_PLANET],
170
-      (int)$this->UBE_PLANET[PLANET_TYPE],
171
-
172
-      (float)$this->resource_list[RES_METAL],
173
-      (float)$this->resource_list[RES_CRYSTAL],
174
-      (float)$this->resource_list[RES_DEUTERIUM],
175
-
176
-      (float)$this->fleet_bonus->calcBonus(P_ATTACK),
177
-      (float)$this->fleet_bonus->calcBonus(P_SHIELD),
178
-      (float)$this->fleet_bonus->calcBonus(P_ARMOR),
167
+      (int) $this->UBE_PLANET[PLANET_GALAXY],
168
+      (int) $this->UBE_PLANET[PLANET_SYSTEM],
169
+      (int) $this->UBE_PLANET[PLANET_PLANET],
170
+      (int) $this->UBE_PLANET[PLANET_TYPE],
171
+
172
+      (float) $this->resource_list[RES_METAL],
173
+      (float) $this->resource_list[RES_CRYSTAL],
174
+      (float) $this->resource_list[RES_DEUTERIUM],
175
+
176
+      (float) $this->fleet_bonus->calcBonus(P_ATTACK),
177
+      (float) $this->fleet_bonus->calcBonus(P_SHIELD),
178
+      (float) $this->fleet_bonus->calcBonus(P_ARMOR),
179 179
     );
180 180
   }
181 181
 
@@ -190,13 +190,13 @@  discard block
 block discarded – undo
190 190
     $this->group_id = $objFleet->group_id;
191 191
 
192 192
     $fleet_unit_list = $objFleet->shipsGetArray();
193
-    foreach($fleet_unit_list as $unit_id => $unit_count) {
194
-      if(!$unit_count) {
193
+    foreach ($fleet_unit_list as $unit_id => $unit_count) {
194
+      if (!$unit_count) {
195 195
         continue;
196 196
       }
197 197
 
198 198
       $unit_type = get_unit_param($unit_id, P_UNIT_TYPE);
199
-      if($unit_type == UNIT_SHIPS || $unit_type == UNIT_DEFENCE) {
199
+      if ($unit_type == UNIT_SHIPS || $unit_type == UNIT_DEFENCE) {
200 200
         $this->unit_list->unitAdjustCount($unit_id, $unit_count);
201 201
       }
202 202
     }
@@ -232,13 +232,13 @@  discard block
 block discarded – undo
232 232
 //      }
233 233
 //    }
234 234
 
235
-    foreach($sn_group_combat as $unit_id) {
236
-      if($unit_count = mrc_get_level($player_db_row, $planet_row, $unit_id)) {
235
+    foreach ($sn_group_combat as $unit_id) {
236
+      if ($unit_count = mrc_get_level($player_db_row, $planet_row, $unit_id)) {
237 237
         $this->unit_list->unitAdjustCount($unit_id, $unit_count);
238 238
       }
239 239
     }
240 240
 
241
-    foreach(sn_get_groups('resources_loot') as $resource_id) {
241
+    foreach (sn_get_groups('resources_loot') as $resource_id) {
242 242
       $this->resource_list[$resource_id] = floor(mrc_get_level($player_db_row, $planet_row, $resource_id));
243 243
     }
244 244
 
@@ -297,27 +297,27 @@  discard block
 block discarded – undo
297 297
       $ube_report_id,
298 298
       $this->db_id,
299 299
 
300
-      (float)$this->resources_lost_on_units[RES_METAL],
301
-      (float)$this->resources_lost_on_units[RES_CRYSTAL],
302
-      (float)$this->resources_lost_on_units[RES_DEUTERIUM],
303
-      (float)$this->cargo_dropped[RES_METAL],
304
-      (float)$this->cargo_dropped[RES_CRYSTAL],
305
-      (float)$this->cargo_dropped[RES_DEUTERIUM],
306
-      (float)$this->resources_looted[RES_METAL],
307
-      (float)$this->resources_looted[RES_CRYSTAL],
308
-      (float)$this->resources_looted[RES_DEUTERIUM],
309
-      (float)$this->resources_lost_in_metal[RES_METAL],
300
+      (float) $this->resources_lost_on_units[RES_METAL],
301
+      (float) $this->resources_lost_on_units[RES_CRYSTAL],
302
+      (float) $this->resources_lost_on_units[RES_DEUTERIUM],
303
+      (float) $this->cargo_dropped[RES_METAL],
304
+      (float) $this->cargo_dropped[RES_CRYSTAL],
305
+      (float) $this->cargo_dropped[RES_DEUTERIUM],
306
+      (float) $this->resources_looted[RES_METAL],
307
+      (float) $this->resources_looted[RES_CRYSTAL],
308
+      (float) $this->resources_looted[RES_DEUTERIUM],
309
+      (float) $this->resources_lost_in_metal[RES_METAL],
310 310
     );
311 311
   }
312 312
 
313 313
   public function report_render_outcome_side_fleet() {
314 314
     $UBE_DEFENCE_RESTORE = array();
315 315
     $UBE_UNITS_LOST = array();
316
-    foreach($this->unit_list->_container as $UBEUnit) {
317
-      if($UBEUnit->units_restored) {
316
+    foreach ($this->unit_list->_container as $UBEUnit) {
317
+      if ($UBEUnit->units_restored) {
318 318
         $UBE_DEFENCE_RESTORE[$UBEUnit->unitId] = $UBEUnit->units_restored;
319 319
       }
320
-      if($UBEUnit->units_lost) {
320
+      if ($UBEUnit->units_lost) {
321 321
         $UBE_UNITS_LOST[$UBEUnit->unitId] = $UBEUnit->units_lost;
322 322
       }
323 323
     }
@@ -344,16 +344,16 @@  discard block
 block discarded – undo
344 344
     global $lang;
345 345
 
346 346
     $result = array();
347
-    if(!empty($array)) {
348
-      foreach($array as $unit_id => $unit_count) {
349
-        if($unit_count) {
347
+    if (!empty($array)) {
348
+      foreach ($array as $unit_id => $unit_count) {
349
+        if ($unit_count) {
350 350
           $result[] = array(
351 351
             'NAME' => $lang['tech'][$unit_id],
352 352
             'LOSS' => pretty_number($unit_count),
353 353
           );
354 354
         }
355 355
       }
356
-      if($lang_header_index && count($result)) {
356
+      if ($lang_header_index && count($result)) {
357 357
         array_unshift($result, array('NAME' => $lang[$lang_header_index]));
358 358
       }
359 359
     }
@@ -366,16 +366,16 @@  discard block
 block discarded – undo
366 366
     $fleet_id = $this->db_id;
367 367
 
368 368
     $unit_sort_order = 0;
369
-    foreach($this->unit_list->_container as $UBEUnit) {
370
-      if($UBEUnit->units_lost || $UBEUnit->units_restored) {
369
+    foreach ($this->unit_list->_container as $UBEUnit) {
370
+      if ($UBEUnit->units_lost || $UBEUnit->units_restored) {
371 371
         $unit_sort_order++;
372 372
         $sql_perform_report_unit[] = array(
373 373
           $ube_report_id,
374 374
           $fleet_id,
375 375
 
376 376
           $UBEUnit->unitId,
377
-          (float)$UBEUnit->units_restored,
378
-          (float)$UBEUnit->units_lost,
377
+          (float) $UBEUnit->units_restored,
378
+          (float) $UBEUnit->units_lost,
379 379
 
380 380
           $unit_sort_order,
381 381
         );
@@ -391,9 +391,9 @@  discard block
 block discarded – undo
391 391
   function ube_combat_result_calculate_resources() {
392 392
     $resource_delta_fleet = array();
393 393
     // Если во флоте остались юниты или это планета - генерируем изменение ресурсов
394
-    foreach(sn_get_groups('resources_loot') as $resource_id) {
395
-      $resource_change = (float)$this->resources_looted[$resource_id] + (float)$this->cargo_dropped[$resource_id];
396
-      if($resource_change) {
394
+    foreach (sn_get_groups('resources_loot') as $resource_id) {
395
+      $resource_change = (float) $this->resources_looted[$resource_id] + (float) $this->cargo_dropped[$resource_id];
396
+      if ($resource_change) {
397 397
         $resource_delta_fleet[$resource_id] = -($resource_change);
398 398
       }
399 399
     }
@@ -426,12 +426,12 @@  discard block
 block discarded – undo
426 426
     );
427 427
 
428 428
     $this->fleet_capacity = 0;
429
-    foreach($this->unit_list->_container as $UBEUnit) {
429
+    foreach ($this->unit_list->_container as $UBEUnit) {
430 430
       $this->fleet_capacity += $UBEUnit->capacity * $UBEUnit->getCount();
431 431
 
432
-      if($UBEUnit->units_lost) {
433
-        foreach($UBEUnit->price as $resource_id => $unit_resource_price) {
434
-          if(!$unit_resource_price) {
432
+      if ($UBEUnit->units_lost) {
433
+        foreach ($UBEUnit->price as $resource_id => $unit_resource_price) {
434
+          if (!$unit_resource_price) {
435 435
             continue;
436 436
           }
437 437
 
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
           $this->resources_lost_on_units[$resource_id] += $resources_lost;
440 440
           // Если это корабль - прибавляем потери к обломкам на орбите
441 441
           // TODO - опция выбрасывания обороны в обломки
442
-          if($UBEUnit->getType() == UNIT_SHIPS) {
442
+          if ($UBEUnit->getType() == UNIT_SHIPS) {
443 443
             $this->resources_lost_on_ships[$resource_id] += $resources_lost;
444 444
           }
445 445
         }
@@ -451,11 +451,11 @@  discard block
 block discarded – undo
451 451
 
452 452
     // Если емкость трюмов меньше количество ресурсов - часть ресов выбрасываем нахуй
453 453
     // На планете ($fleet_id = 0) ресурсы в космос не выбрасываются
454
-    if($this->db_id != 0 && $this->fleet_capacity < $fleet_total_resources) {
454
+    if ($this->db_id != 0 && $this->fleet_capacity < $fleet_total_resources) {
455 455
       $drop_share = 1 - $this->fleet_capacity / $fleet_total_resources; // Какая часть ресурсов выброшена
456
-      foreach($this->resource_list as $resource_id => &$resource_amount) {
456
+      foreach ($this->resource_list as $resource_id => &$resource_amount) {
457 457
         // Не просчитываем ресурсы, которых нет на борту кораблей флота
458
-        if(!$resource_amount) {
458
+        if (!$resource_amount) {
459 459
           continue;
460 460
         }
461 461
 
@@ -476,19 +476,19 @@  discard block
 block discarded – undo
476 476
     $objFleet2->setDbId($this->db_id);
477 477
 
478 478
     // Если это была миссия Уничтожения И звезда смерти взорвалась И мы работаем с аттакерами - значит все аттакеры умерли
479
-    if($this->is_attacker == UBE_PLAYER_IS_ATTACKER && $reapers_status == UBE_MOON_REAPERS_DIED) {
479
+    if ($this->is_attacker == UBE_PLAYER_IS_ATTACKER && $reapers_status == UBE_MOON_REAPERS_DIED) {
480 480
       $objFleet2->dbDelete();
481
-    } elseif($ship_count_initial == 0) { // $ship_count_lost == $ship_count_initial ||
481
+    } elseif ($ship_count_initial == 0) { // $ship_count_lost == $ship_count_initial ||
482 482
       $objFleet2->dbDelete();
483 483
     } else {
484
-      if($ship_count_lost) {
484
+      if ($ship_count_lost) {
485 485
         // Просматриваем результаты изменения флотов
486
-        foreach($this->unit_list->_container as $UBEUnit) {
486
+        foreach ($this->unit_list->_container as $UBEUnit) {
487 487
           // Перебираем аутком на случай восстановления юнитов
488 488
 //          if(($units_left = $UBEUnit->getCount() - (float)$UBEUnit->units_lost) > 0) {
489 489
 //            $fleet_real_array[$UBEUnit->unitId] = $units_left;
490 490
 //          };
491
-          if(floatval($UBEUnit->units_lost) != 0) {
491
+          if (floatval($UBEUnit->units_lost) != 0) {
492 492
             $objFleet2->shipAdjustCount($UBEUnit->unitId, floatval($UBEUnit->units_lost));
493 493
           };
494 494
         }
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
       $objFleet2->resourcesAdjust($resource_delta_fleet);
499 499
 
500 500
       // Если защитник и не РМФ - отправляем флот назад
501
-      if($this->is_attacker == UBE_PLAYER_IS_ATTACKER || ($this->is_attacker == UBE_PLAYER_IS_DEFENDER && !$is_small_fleet_recce)) {
501
+      if ($this->is_attacker == UBE_PLAYER_IS_ATTACKER || ($this->is_attacker == UBE_PLAYER_IS_DEFENDER && !$is_small_fleet_recce)) {
502 502
         $objFleet2->markReturned();
503 503
       }
504 504
       $objFleet2->dbSave();
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
   public function calculate_unit_partial_data(UBEASA $side_ASA) {
529 529
     $this->fleet_share_of_side_armor = $this->total_stats[P_ARMOR] / $side_ASA->getArmor();
530 530
 
531
-    foreach($this->unit_list->_container as $UBEUnit) {
531
+    foreach ($this->unit_list->_container as $UBEUnit) {
532 532
       $UBEUnit->share_of_side_armor = $UBEUnit->pool_armor / $side_ASA->getArmor();
533 533
     }
534 534
   }
@@ -540,9 +540,9 @@  discard block
 block discarded – undo
540 540
    * @version 2016-02-25 23:42:45 41a4.68
541 541
    */
542 542
   public function attack_fleets(UBEFleetList $fleet_list, $is_simulator) {
543
-    foreach($fleet_list->_container as $defending_fleet) {
543
+    foreach ($fleet_list->_container as $defending_fleet) {
544 544
       // Не атакуются флоты на своей стороне
545
-      if($this->is_attacker == $defending_fleet->is_attacker) {
545
+      if ($this->is_attacker == $defending_fleet->is_attacker) {
546 546
         continue;
547 547
       }
548 548
       $this->attack_fleet($defending_fleet, $is_simulator);
@@ -558,12 +558,12 @@  discard block
 block discarded – undo
558 558
   public function attack_fleet(UBEFleet $defending_fleet, $is_simulator) {
559 559
     UBEDebug::unit_dump_header();
560 560
 
561
-    foreach($this->unit_list->_container as $attacking_unit_pool) {
561
+    foreach ($this->unit_list->_container as $attacking_unit_pool) {
562 562
       UBEDebug::unit_dump($attacking_unit_pool, 'attacker');
563 563
 
564 564
       // if($attack_unit_count <= 0) continue; // TODO: Это пока нельзя включать - вот если будут "боевые порядки юнитов..."
565
-      foreach($defending_fleet->unit_list->_container as $defending_unit_pool) {
566
-        if($defending_unit_pool->isEmpty()) {
565
+      foreach ($defending_fleet->unit_list->_container as $defending_unit_pool) {
566
+        if ($defending_unit_pool->isEmpty()) {
567 567
           continue;
568 568
         }
569 569
 
Please login to merge, or discard this patch.
includes/classes/UnitList.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
    * @param Unit  $value
89 89
    */
90 90
   public function offsetSet($offset, $value) {
91
-    if(isset($this->mapUnitIdToDb[$value->unitId])) {
91
+    if (isset($this->mapUnitIdToDb[$value->unitId])) {
92 92
       classSupernova::$debug->error('UnitList::offsetSet: Unit with UnitId ' . $value->unitId . ' already exists');
93 93
     }
94 94
     $this->mapUnitIdToDb[$value->unitId] = $value;
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
   }
97 97
 
98 98
   public function offsetUnset($offset) {
99
-    if(!empty($this[$offset]->unitId)) {
99
+    if (!empty($this[$offset]->unitId)) {
100 100
 //      $unit_id = $this[$offset]->unitId;
101 101
 //      $this->mapUnitIdToDb[$unit_id] = null;
102 102
 //      unset($this->mapUnitIdToDb[$unit_id]);
@@ -118,20 +118,20 @@  discard block
 block discarded – undo
118 118
   public function dbLoad($dbId) {
119 119
 //    $this->_reset();
120 120
 
121
-    if($dbId <= 0) {
121
+    if ($dbId <= 0) {
122 122
       return;
123 123
     }
124 124
 
125
-    if(!is_object($this->locatedAt)) {
125
+    if (!is_object($this->locatedAt)) {
126 126
       classSupernova::$debug->error('UnitList::dbLoad have no locatedAt field set');
127 127
     }
128 128
 
129 129
     $unit_array = classSupernova::db_get_unit_list_by_location(0, $this->getLocationType(), $this->getLocationDbId());
130
-    if(!is_array($unit_array)) {
130
+    if (!is_array($unit_array)) {
131 131
       return;
132 132
     }
133 133
 
134
-    foreach($unit_array as $unit_db_row) {
134
+    foreach ($unit_array as $unit_db_row) {
135 135
       $unit = $this->_createElement();
136 136
       $unit->setLocatedAt($this);
137 137
       $unit->dbRowParse($unit_db_row);
@@ -147,25 +147,25 @@  discard block
 block discarded – undo
147 147
   }
148 148
 
149 149
   public function dbSave() {
150
-    if(!is_object($this->locatedAt)) {
150
+    if (!is_object($this->locatedAt)) {
151 151
       classSupernova::$debug->error('UnitList::dbSave have no locatedAt field set');
152 152
     }
153 153
 
154
-    foreach($this->mapUnitIdToDb as $unit) {
154
+    foreach ($this->mapUnitIdToDb as $unit) {
155 155
       $unit_db_id = $unit->dbId;
156 156
       $unit->dbSave();
157 157
 
158
-      if($unit->isEmpty()) {
158
+      if ($unit->isEmpty()) {
159 159
         // Removing unit object
160 160
         // TODO - change when there will be common bus for all objects
161 161
         // ...or should I? If COUNT is empty - it means that object does not exists in DB. So it should be deleted from PHP memory and cache too
162 162
         unset($this[$unit_db_id]);
163 163
       } else {
164
-        if($unit->dbId <= 0) {
164
+        if ($unit->dbId <= 0) {
165 165
           classSupernova::$debug->error('Error writing unit to DB');
166 166
         }
167 167
         // If unit is new then putting unit object to container
168
-        if(empty($this->_container[$unit->dbId])) {
168
+        if (empty($this->_container[$unit->dbId])) {
169 169
           $this->_container[$unit->dbId] = $unit;
170 170
         }
171 171
       }
@@ -200,14 +200,14 @@  discard block
 block discarded – undo
200 200
   }
201 201
 
202 202
   public function unitGetCount($unit_id) {
203
-    if(empty($this->mapUnitIdToDb[$unit_id])) {
203
+    if (empty($this->mapUnitIdToDb[$unit_id])) {
204 204
       throw new Exception('Unit [' . $unit_id . '] is not exists in UnitList');
205 205
     }
206 206
     return $this->mapUnitIdToDb[$unit_id]->count;
207 207
   }
208 208
 
209 209
   public function unitsCountApplyLossMultiplier($ships_lost_multiplier) {
210
-    foreach($this->mapUnitIdToDb as $unit_id => $unit) {
210
+    foreach ($this->mapUnitIdToDb as $unit_id => $unit) {
211 211
       $unit->count = floor($unit->count * $ships_lost_multiplier);
212 212
     }
213 213
   }
@@ -221,14 +221,14 @@  discard block
 block discarded – undo
221 221
    * @param bool $replace_value
222 222
    */
223 223
   public function unitAdjustCount($unit_id, $unit_count = 0, $replace_value = false) {
224
-    if(empty($this->mapUnitIdToDb[$unit_id])) {
224
+    if (empty($this->mapUnitIdToDb[$unit_id])) {
225 225
       // If unit not exists - creating one and setting all attributes
226 226
       $this->mapUnitIdToDb[$unit_id] = $this->_createElement();
227 227
       $this->mapUnitIdToDb[$unit_id]->setUnitId($unit_id);
228 228
       $this->mapUnitIdToDb[$unit_id]->setLocatedAt($this);
229 229
     }
230 230
 
231
-    if($replace_value) {
231
+    if ($replace_value) {
232 232
       $this->mapUnitIdToDb[$unit_id]->count = $unit_count;
233 233
     } else {
234 234
       $this->mapUnitIdToDb[$unit_id]->adjustCount($unit_count);
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
    */
243 243
   public function unitsGetArray() {
244 244
     $result = array();
245
-    foreach($this->mapUnitIdToDb as $unit) {
245
+    foreach ($this->mapUnitIdToDb as $unit) {
246 246
       $result[$unit->unitId] = $unit->count;
247 247
     }
248 248
 
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
    */
267 267
   public function unitsCountById($unit_id = 0) {
268 268
     $result = 0;
269
-    foreach($this->mapUnitIdToDb as $unit) {
270
-      if(!$unit_id || $unit->unitId == $unit_id) {
269
+    foreach ($this->mapUnitIdToDb as $unit) {
270
+      if (!$unit_id || $unit->unitId == $unit_id) {
271 271
         $result += $unit->count;
272 272
       }
273 273
     }
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 
349 349
     print('</tr>');
350 350
 
351
-    foreach($this->mapUnitIdToDb as $unit) {
351
+    foreach ($this->mapUnitIdToDb as $unit) {
352 352
       print('<tr>');
353 353
 
354 354
       print('<td>');
@@ -399,14 +399,14 @@  discard block
 block discarded – undo
399 399
 
400 400
 
401 401
   public function unitZeroDbId() {
402
-    foreach($this->mapUnitIdToDb as $unit) {
402
+    foreach ($this->mapUnitIdToDb as $unit) {
403 403
       $unit->zeroDbId();
404 404
     }
405 405
   }
406 406
 
407 407
 
408 408
   public function unitZeroCount() {
409
-    foreach($this->mapUnitIdToDb as $unit) {
409
+    foreach ($this->mapUnitIdToDb as $unit) {
410 410
       $unit->count = 0;
411 411
     }
412 412
   }
Please login to merge, or discard this patch.
includes/functions/tpl_helpers.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@  discard block
 block discarded – undo
2 2
 
3 3
 // Compare function to sort fleet in time order
4 4
 function tpl_assign_fleet_compare($a, $b) {
5
-  if($a['fleet']['OV_THIS_PLANET'] == $b['fleet']['OV_THIS_PLANET']) {
6
-    if($a['fleet']['OV_LEFT'] == $b['fleet']['OV_LEFT']) {
5
+  if ($a['fleet']['OV_THIS_PLANET'] == $b['fleet']['OV_THIS_PLANET']) {
6
+    if ($a['fleet']['OV_LEFT'] == $b['fleet']['OV_LEFT']) {
7 7
       return 0;
8 8
     }
9 9
 
@@ -19,17 +19,17 @@  discard block
 block discarded – undo
19 19
  * @param string   $js_name
20 20
  */
21 21
 function tpl_assign_fleet(&$template, $fleets, $js_name = 'fleets') {
22
-  if(!$fleets) {
22
+  if (!$fleets) {
23 23
     return;
24 24
   }
25 25
 
26 26
   usort($fleets, 'tpl_assign_fleet_compare');
27 27
 
28
-  foreach($fleets as $fleet_data) {
28
+  foreach ($fleets as $fleet_data) {
29 29
     $template->assign_block_vars($js_name, $fleet_data['fleet']);
30 30
 
31
-    if($fleet_data['ships']) {
32
-      foreach($fleet_data['ships'] as $ship_data) {
31
+    if ($fleet_data['ships']) {
32
+      foreach ($fleet_data['ships'] as $ship_data) {
33 33
         $template->assign_block_vars("{$js_name}.ships", $ship_data);
34 34
       }
35 35
     }
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
     'DEUTERIUM' => $fleet[RES_DEUTERIUM],
51 51
   );
52 52
 
53
-  foreach($fleet as $ship_id => $ship_amount) {
54
-    if(in_array($ship_id, sn_get_groups('fleet'))) {
53
+  foreach ($fleet as $ship_id => $ship_amount) {
54
+    if (in_array($ship_id, sn_get_groups('fleet'))) {
55 55
       $single_ship_data = get_ship_data($ship_id, $user_data);
56 56
       $return['ships'][$ship_id] = array(
57 57
         'ID'          => $ship_id,
@@ -90,11 +90,11 @@  discard block
 block discarded – undo
90 90
 
91 91
   $result = array();
92 92
 
93
-  if(!$user_data) {
93
+  if (!$user_data) {
94 94
     $user_data = $user;
95 95
   }
96 96
 
97
-  if(!$objFleet->isReturning() && $objFleet->mission_type == MT_AKS) {
97
+  if (!$objFleet->isReturning() && $objFleet->mission_type == MT_AKS) {
98 98
     $aks = db_acs_get_by_group_id($objFleet->group_id);
99 99
   }
100 100
 
@@ -135,14 +135,14 @@  discard block
 block discarded – undo
135 135
     'STAY_LEFT' => floor($objFleet->time_mission_job_complete + 1 - SN_TIME_NOW),
136 136
   );
137 137
 
138
-  if(property_exists($objFleet, 'fleet_start_name')) {
138
+  if (property_exists($objFleet, 'fleet_start_name')) {
139 139
     $result['START_NAME'] = $objFleet->fleet_start_name;
140 140
   }
141
-  if(property_exists($objFleet, 'fleet_end_name')) {
141
+  if (property_exists($objFleet, 'fleet_end_name')) {
142 142
     $result['END_NAME'] = $objFleet->fleet_end_name;
143 143
   }
144 144
 
145
-  if(property_exists($objFleet, 'event_time')) {
145
+  if (property_exists($objFleet, 'event_time')) {
146 146
     $result['fleet'] = array_merge($result['fleet'], array(
147 147
       'OV_LABEL'        => $objFleet->ov_label,
148 148
       'EVENT_TIME_TEXT' => property_exists($objFleet, 'event_time') ? date(FMT_DATE_TIME, $objFleet->event_time + SN_CLIENT_TIME_DIFF) : '',
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
   $ship_list_fully_parsed = $objFleet->shipsGetArray();
155 155
 
156 156
   $ship_id = 0;
157
-  if($spy_level >= 6) {
158
-    foreach($ship_list_fully_parsed as $ship_sn_id => $ship_amount) {
159
-      if($spy_level >= 10) {
157
+  if ($spy_level >= 6) {
158
+    foreach ($ship_list_fully_parsed as $ship_sn_id => $ship_amount) {
159
+      if ($spy_level >= 10) {
160 160
         $single_ship_data = get_ship_data($ship_sn_id, $user_data);
161 161
         $result['ships'][$ship_sn_id] = array(
162 162
           'ID'          => $ship_sn_id,
@@ -188,8 +188,8 @@  discard block
 block discarded – undo
188 188
 function tpl_parse_planet_que($que, $planet, $que_id) {
189 189
   $hangar_que = array();
190 190
   $que_hangar = $que['ques'][$que_id][$planet['id_owner']][$planet['id']];
191
-  if(!empty($que_hangar)) {
192
-    foreach($que_hangar as $que_item) {
191
+  if (!empty($que_hangar)) {
192
+    foreach ($que_hangar as $que_item) {
193 193
       $hangar_que['que'][] = array('id' => $que_item['que_unit_id'], 'count' => $que_item['que_unit_amount']);
194 194
       $hangar_que[$que_item['que_unit_id']] += $que_item['que_unit_amount'];
195 195
     }
@@ -252,10 +252,10 @@  discard block
 block discarded – undo
252 252
     'PLANET_GOVERNOR_LEVEL_MAX' => get_unit_param($planet['PLANET_GOVERNOR_ID'], P_MAX_STACK),
253 253
   );
254 254
 
255
-  if(!empty($que['ques'][QUE_STRUCTURES][$planet['id_owner']][$planet['id']])) {
255
+  if (!empty($que['ques'][QUE_STRUCTURES][$planet['id_owner']][$planet['id']])) {
256 256
     $result['building_que'] = array();
257 257
     $building_que = &$que['ques'][QUE_STRUCTURES][$planet['id_owner']][$planet['id']];
258
-    foreach($building_que as $que_element) {
258
+    foreach ($building_que as $que_element) {
259 259
       $result['building_que'][] = que_tpl_parse_element($que_element);
260 260
     }
261 261
   }
@@ -271,19 +271,19 @@  discard block
 block discarded – undo
271 271
 function flt_get_fleets_to_planet_by_array_of_Fleet($array_of_Fleet) {
272 272
   global $user;
273 273
 
274
-  if(empty($array_of_Fleet)) {
274
+  if (empty($array_of_Fleet)) {
275 275
     return false;
276 276
   }
277 277
 
278 278
   $fleet_list = array();
279
-  foreach($array_of_Fleet as $fleet) {
280
-    if($fleet->playerOwnerId == $user['id']) {
281
-      if($fleet->mission_type == MT_MISSILE) {
279
+  foreach ($array_of_Fleet as $fleet) {
280
+    if ($fleet->playerOwnerId == $user['id']) {
281
+      if ($fleet->mission_type == MT_MISSILE) {
282 282
         continue;
283 283
       }
284 284
       $fleet_ownage = 'own';
285 285
     } else {
286
-      switch($fleet->mission_type) {
286
+      switch ($fleet->mission_type) {
287 287
         case MT_ATTACK:
288 288
         case MT_AKS:
289 289
         case MT_DESTROY:
@@ -300,10 +300,10 @@  discard block
 block discarded – undo
300 300
 
301 301
     $fleet_list[$fleet_ownage]['fleets'][$fleet->dbId] = $fleet;
302 302
 
303
-    if($fleet->isReturning() || (!$fleet->isReturning() && $fleet->mission_type == MT_RELOCATE) || ($fleet->target_owner_id != $user['id'])) {
303
+    if ($fleet->isReturning() || (!$fleet->isReturning() && $fleet->mission_type == MT_RELOCATE) || ($fleet->target_owner_id != $user['id'])) {
304 304
       $fleet_sn = $fleet->shipsGetArray();
305
-      foreach($fleet_sn as $ship_id => $ship_amount) {
306
-        if(in_array($ship_id, sn_get_groups('fleet'))) {
305
+      foreach ($fleet_sn as $ship_id => $ship_amount) {
306
+        if (in_array($ship_id, sn_get_groups('fleet'))) {
307 307
           $fleet_list[$fleet_ownage]['total'][$ship_id] += $ship_amount;
308 308
         }
309 309
       }
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
   return $fleet_list;
321 321
 }
322 322
 
323
-function tpl_set_resource_info(template &$template, $planet_row, $fleets_to_planet = array(), $round = 0) {
323
+function tpl_set_resource_info(template & $template, $planet_row, $fleets_to_planet = array(), $round = 0) {
324 324
   $template->assign_vars(array(
325 325
     'RESOURCE_ROUNDING' => $round,
326 326
 
Please login to merge, or discard this patch.