Completed
Push — work-fleets ( abbbcf...8b8b7f )
by SuperNova.WS
05:13
created
includes/includes/flt_functions.php 1 patch
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 function flt_fleet_speed($user, $fleet) {
4
-  if(!is_array($fleet)) {
4
+  if (!is_array($fleet)) {
5 5
     $fleet = array($fleet => 1);
6 6
   }
7 7
 
8 8
   $speeds = array();
9
-  if(!empty($fleet)) {
10
-    foreach($fleet as $ship_id => $amount) {
11
-      if($amount && in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) {
9
+  if (!empty($fleet)) {
10
+    foreach ($fleet as $ship_id => $amount) {
11
+      if ($amount && in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) {
12 12
         $single_ship_data = get_ship_data($ship_id, $user);
13 13
         $speeds[] = $single_ship_data['speed'];
14 14
       }
@@ -21,11 +21,11 @@  discard block
 block discarded – undo
21 21
 function flt_travel_distance($from, $to) {
22 22
   global $config;
23 23
 
24
-  if($from['galaxy'] != $to['galaxy']) {
24
+  if ($from['galaxy'] != $to['galaxy']) {
25 25
     $distance = abs($from['galaxy'] - $to['galaxy']) * $config->uni_galaxy_distance;
26
-  } elseif($from['system'] != $to['system']) {
26
+  } elseif ($from['system'] != $to['system']) {
27 27
     $distance = abs($from['system'] - $to['system']) * 5 * 19 + 2700;
28
-  } elseif($from['planet'] != $to['planet']) {
28
+  } elseif ($from['planet'] != $to['planet']) {
29 29
     $distance = abs($from['planet'] - $to['planet']) * 5 + 1000;
30 30
   } else {
31 31
     $distance = 5;
@@ -52,14 +52,14 @@  discard block
 block discarded – undo
52 52
 
53 53
   $game_fleet_speed = flt_server_flight_speed_multiplier();
54 54
   $fleet_speed = flt_fleet_speed($user_row, $fleet_array);
55
-  if(!empty($fleet_array) && $fleet_speed && $game_fleet_speed) {
55
+  if (!empty($fleet_array) && $fleet_speed && $game_fleet_speed) {
56 56
     $speed_percent = $speed_percent ? max(min($speed_percent, 10), 1) : 10;
57 57
     $real_speed = $speed_percent * sqrt($fleet_speed);
58 58
 
59 59
     $duration = max(1, round((35000 / $speed_percent * sqrt($distance * 10 / $fleet_speed) + 10) / $game_fleet_speed));
60 60
 
61
-    foreach($fleet_array as $ship_id => $ship_count) {
62
-      if(!$ship_id || !$ship_count) {
61
+    foreach ($fleet_array as $ship_id => $ship_count) {
62
+      if (!$ship_id || !$ship_count) {
63 63
         continue;
64 64
       }
65 65
 
@@ -89,19 +89,19 @@  discard block
 block discarded – undo
89 89
 
90 90
   $config_bashing_attacks = $config->fleet_bashing_attacks;
91 91
   $config_bashing_interval = $config->fleet_bashing_interval;
92
-  if(!$config_bashing_attacks) {
92
+  if (!$config_bashing_attacks) {
93 93
     // Bashing allowed - protection disabled
94 94
     return ATTACK_ALLOWED;
95 95
   }
96 96
 
97 97
   $bashing_result = ATTACK_BASHING;
98
-  if($user['ally_id'] && $enemy['ally_id']) {
98
+  if ($user['ally_id'] && $enemy['ally_id']) {
99 99
     $relations = ali_relations($user['ally_id'], $enemy['ally_id']);
100
-    if(!empty($relations)) {
100
+    if (!empty($relations)) {
101 101
       $relations = $relations[$enemy['ally_id']];
102
-      switch($relations['alliance_diplomacy_relation']) {
102
+      switch ($relations['alliance_diplomacy_relation']) {
103 103
         case ALLY_DIPLOMACY_WAR:
104
-          if(SN_TIME_NOW - $relations['alliance_diplomacy_time'] <= $config->fleet_bashing_war_delay) {
104
+          if (SN_TIME_NOW - $relations['alliance_diplomacy_time'] <= $config->fleet_bashing_war_delay) {
105 105
             $bashing_result = ATTACK_BASHING_WAR_DELAY;
106 106
           } else {
107 107
             return ATTACK_ALLOWED;
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
 
124 124
   // Retrieving flying fleets
125 125
   $objFleetsBashing = FleetList::dbGetFleetListBashing($user['id'], $planet_dst);
126
-  foreach($objFleetsBashing->_container as $fleetBashing) {
126
+  foreach ($objFleetsBashing->_container as $fleetBashing) {
127 127
     // Checking for ACS - each ACS count only once
128
-    if($fleetBashing->group_id) {
128
+    if ($fleetBashing->group_id) {
129 129
       $bashing_list["{$user['id']}_{$fleetBashing->group_id}"] = $fleetBashing->time_arrive_to_target;
130 130
     } else {
131 131
       $bashing_list[] = $fleetBashing->time_arrive_to_target;
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
   }
134 134
 
135 135
   // Check for joining to ACS - if there are already fleets in ACS no checks should be done
136
-  if($mission == MT_AKS && $bashing_list["{$user['id']}_{$fleet_group}"]) {
136
+  if ($mission == MT_AKS && $bashing_list["{$user['id']}_{$fleet_group}"]) {
137 137
     return ATTACK_ALLOWED;
138 138
   }
139 139
 
140 140
   $query = db_bashing_list_get($user, $planet_dst, $time_limit);
141
-  while($bashing_row = db_fetch($query)) {
141
+  while ($bashing_row = db_fetch($query)) {
142 142
     $bashing_list[] = $bashing_row['bashing_time'];
143 143
   }
144 144
 
@@ -147,9 +147,9 @@  discard block
 block discarded – undo
147 147
   $last_attack = 0;
148 148
   $wave = 0;
149 149
   $attack = 1;
150
-  foreach($bashing_list as &$bash_time) {
150
+  foreach ($bashing_list as &$bash_time) {
151 151
     $attack++;
152
-    if($bash_time - $last_attack > $config_bashing_interval || $attack > $config_bashing_attacks) {
152
+    if ($bash_time - $last_attack > $config_bashing_interval || $attack > $config_bashing_attacks) {
153 153
       $attack = 1;
154 154
       $wave++;
155 155
     }
@@ -166,16 +166,16 @@  discard block
 block discarded – undo
166 166
   //TODO: try..catch
167 167
   global $config, $user;
168 168
 
169
-  if($user['vacation']) {
169
+  if ($user['vacation']) {
170 170
     return $result = ATTACK_OWN_VACATION;
171 171
   }
172 172
 
173
-  if(empty($fleet) || !is_array($fleet)) {
173
+  if (empty($fleet) || !is_array($fleet)) {
174 174
     return $result = ATTACK_NO_FLEET;
175 175
   }
176 176
 
177 177
   $sn_groups_mission = sn_get_groups('missions');
178
-  if(!isset($sn_groups_mission[$mission])) {
178
+  if (!isset($sn_groups_mission[$mission])) {
179 179
     return $result = ATTACK_MISSION_ABSENT;
180 180
   }
181 181
   $sn_data_mission = $sn_groups_mission[$mission];
@@ -194,32 +194,32 @@  discard block
 block discarded – undo
194 194
   $resources = 0;
195 195
   $ship_ids = sn_get_groups('fleet');
196 196
   $resource_ids = sn_get_groups('resources_loot');
197
-  foreach($fleet as $ship_id => $ship_count) {
197
+  foreach ($fleet as $ship_id => $ship_count) {
198 198
     $is_ship = in_array($ship_id, $ship_ids);
199 199
     $is_resource = in_array($ship_id, $resource_ids);
200
-    if(!$is_ship && !$is_resource) {
200
+    if (!$is_ship && !$is_resource) {
201 201
       // TODO Спецобработчик для Капитана и модулей
202 202
 //      return ATTACK_WRONG_UNIT;
203 203
     }
204 204
 
205
-    if($ship_count < 0) {
205
+    if ($ship_count < 0) {
206 206
       return $result = $is_ship ? ATTACK_SHIP_COUNT_WRONG : ATTACK_RESOURCE_COUNT_WRONG;
207 207
     }
208 208
 
209
-    if($ship_count > mrc_get_level($user, $planet_src, $ship_id)) {
209
+    if ($ship_count > mrc_get_level($user, $planet_src, $ship_id)) {
210 210
       // TODO ATTACK_NO_MISSILE
211 211
       return $result = $is_ship ? ATTACK_NO_SHIPS : ATTACK_NO_RESOURCES;
212 212
     }
213 213
 
214
-    if($is_ship) {
214
+    if ($is_ship) {
215 215
       $single_ship_data = get_ship_data($ship_id, $user);
216
-      if($single_ship_data[P_SPEED] <= 0) {
216
+      if ($single_ship_data[P_SPEED] <= 0) {
217 217
         return $result = ATTACK_ZERO_SPEED;
218 218
       }
219 219
       $ships += $ship_count;
220 220
       $recyclers += in_array($ship_id, sn_get_groups('flt_recyclers')) ? $ship_count : 0;
221 221
       $spies += $ship_id == SHIP_SPY ? $ship_count : 0;
222
-    } elseif($is_resource) {
222
+    } elseif ($is_resource) {
223 223
       $resources += $ship_count;
224 224
     }
225 225
   }
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
     }
231 231
   */
232 232
 
233
-  if(isset($options['resources']) && $options['resources'] > 0 && !(isset($sn_data_mission['transport']) && $sn_data_mission['transport'])) {
233
+  if (isset($options['resources']) && $options['resources'] > 0 && !(isset($sn_data_mission['transport']) && $sn_data_mission['transport'])) {
234 234
     return $result = ATTACK_RESOURCE_FORBIDDEN;
235 235
   }
236 236
 
@@ -242,78 +242,78 @@  discard block
 block discarded – undo
242 242
   */
243 243
 
244 244
   $speed = $options['fleet_speed_percent'];
245
-  if($speed && ($speed != intval($speed) || $speed < 1 || $speed > 10)) {
245
+  if ($speed && ($speed != intval($speed) || $speed < 1 || $speed > 10)) {
246 246
     return $result = ATTACK_WRONG_SPEED;
247 247
   }
248 248
 
249 249
   $travel_data = flt_travel_data($user, $planet_src, $planet_dst, $fleet, $options['fleet_speed_percent']);
250 250
 
251 251
 
252
-  if(mrc_get_level($user, $planet_src, RES_DEUTERIUM) < $fleet[RES_DEUTERIUM] + $travel_data['consumption']) {
252
+  if (mrc_get_level($user, $planet_src, RES_DEUTERIUM) < $fleet[RES_DEUTERIUM] + $travel_data['consumption']) {
253 253
     return $result = ATTACK_NO_FUEL;
254 254
   }
255 255
 
256
-  if($travel_data['consumption'] > $travel_data['capacity']) {
256
+  if ($travel_data['consumption'] > $travel_data['capacity']) {
257 257
     return $result = ATTACK_TOO_FAR;
258 258
   }
259 259
 
260
-  if($travel_data['hold'] < $resources) {
260
+  if ($travel_data['hold'] < $resources) {
261 261
     return $result = ATTACK_OVERLOADED;
262 262
   }
263 263
 
264 264
   $fleet_start_time = SN_TIME_NOW + $travel_data['duration'];
265 265
 
266 266
   $fleet_group = $options['fleet_group'];
267
-  if($fleet_group) {
268
-    if($mission != MT_AKS) {
267
+  if ($fleet_group) {
268
+    if ($mission != MT_AKS) {
269 269
       return $result = ATTACK_WRONG_MISSION;
270 270
     };
271 271
 
272 272
     $acs = db_acs_get_by_group_id($fleet_group);
273
-    if(!$acs['id']) {
273
+    if (!$acs['id']) {
274 274
       return $result = ATTACK_NO_ACS;
275 275
     }
276 276
 
277
-    if($planet_dst['galaxy'] != $acs['galaxy'] || $planet_dst['system'] != $acs['system'] || $planet_dst['planet'] != $acs['planet'] || $planet_dst['planet_type'] != $acs['planet_type']) {
277
+    if ($planet_dst['galaxy'] != $acs['galaxy'] || $planet_dst['system'] != $acs['system'] || $planet_dst['planet'] != $acs['planet'] || $planet_dst['planet_type'] != $acs['planet_type']) {
278 278
       return $result = ATTACK_ACS_WRONG_TARGET;
279 279
     }
280 280
 
281
-    if($fleet_start_time > $acs['ankunft']) {
281
+    if ($fleet_start_time > $acs['ankunft']) {
282 282
       return $result = ATTACK_ACS_TOO_LATE;
283 283
     }
284 284
   }
285 285
 
286 286
   $flying_fleets = $options['flying_fleets'];
287
-  if(!$flying_fleets) {
287
+  if (!$flying_fleets) {
288 288
     $flying_fleets = FleetList::fleet_count_flying($user['id']);
289 289
   }
290
-  if(GetMaxFleets($user) <= $flying_fleets && $mission != MT_MISSILE) {
290
+  if (GetMaxFleets($user) <= $flying_fleets && $mission != MT_MISSILE) {
291 291
     return $result = ATTACK_NO_SLOTS;
292 292
   }
293 293
 
294 294
   // В одиночку шпионские зонды могут летать только в миссии Шпионаж, Передислокация и Транспорт
295
-  if($ships && $spies && $spies == $ships && !($mission == MT_SPY || $mission == MT_RELOCATE || $mission == MT_TRANSPORT)) {
295
+  if ($ships && $spies && $spies == $ships && !($mission == MT_SPY || $mission == MT_RELOCATE || $mission == MT_TRANSPORT)) {
296 296
     return $result = ATTACK_SPIES_LONLY;
297 297
   }
298 298
 
299 299
   // Checking for no planet
300
-  if(!$planet_dst['id_owner']) {
301
-    if($mission == MT_COLONIZE && !$fleet[SHIP_COLONIZER]) {
300
+  if (!$planet_dst['id_owner']) {
301
+    if ($mission == MT_COLONIZE && !$fleet[SHIP_COLONIZER]) {
302 302
       return $result = ATTACK_NO_COLONIZER;
303 303
     }
304 304
 
305
-    if($mission == MT_EXPLORE || $mission == MT_COLONIZE) {
305
+    if ($mission == MT_EXPLORE || $mission == MT_COLONIZE) {
306 306
       return $result = ATTACK_ALLOWED;
307 307
     }
308 308
 
309 309
     return $result = ATTACK_NO_TARGET;
310 310
   }
311 311
 
312
-  if($mission == MT_RECYCLE) {
313
-    if($planet_dst['debris_metal'] + $planet_dst['debris_crystal'] <= 0) {
312
+  if ($mission == MT_RECYCLE) {
313
+    if ($planet_dst['debris_metal'] + $planet_dst['debris_crystal'] <= 0) {
314 314
       return $result = ATTACK_NO_DEBRIS;
315 315
     }
316
-    if($recyclers <= 0) {
316
+    if ($recyclers <= 0) {
317 317
       return $result = ATTACK_NO_RECYCLERS;
318 318
     }
319 319
 
@@ -321,8 +321,8 @@  discard block
 block discarded – undo
321 321
   }
322 322
 
323 323
   // Got planet. Checking if it is ours
324
-  if($planet_dst['id_owner'] == $user['id']) {
325
-    if($mission == MT_TRANSPORT || $mission == MT_RELOCATE) {
324
+  if ($planet_dst['id_owner'] == $user['id']) {
325
+    if ($mission == MT_TRANSPORT || $mission == MT_RELOCATE) {
326 326
       return $result = ATTACK_ALLOWED;
327 327
     }
328 328
 
@@ -330,19 +330,19 @@  discard block
 block discarded – undo
330 330
   }
331 331
 
332 332
   // No, planet not ours. Cutting mission that can't be send to not-ours planet
333
-  if($mission == MT_RELOCATE || $mission == MT_COLONIZE || $mission == MT_EXPLORE) {
333
+  if ($mission == MT_RELOCATE || $mission == MT_COLONIZE || $mission == MT_EXPLORE) {
334 334
     return $result = ATTACK_WRONG_MISSION;
335 335
   }
336 336
 
337 337
   $enemy = db_user_by_id($planet_dst['id_owner']);
338 338
   // We cannot attack or send resource to users in VACATION mode
339
-  if($enemy['vacation'] && $mission != MT_RECYCLE) {
339
+  if ($enemy['vacation'] && $mission != MT_RECYCLE) {
340 340
     return $result = ATTACK_VACATION;
341 341
   }
342 342
 
343 343
   // Multi IP protection
344 344
   // TODO: Here we need a procedure to check proxies
345
-  if(sys_is_multiaccount($user, $enemy)) {
345
+  if (sys_is_multiaccount($user, $enemy)) {
346 346
     return $result = ATTACK_SAME_IP;
347 347
   }
348 348
 
@@ -350,8 +350,8 @@  discard block
 block discarded – undo
350 350
   $enemy_points = $enemy['total_points'];
351 351
 
352 352
   // Is it transport? If yes - checking for buffing to prevent mega-alliance destroyer
353
-  if($mission == MT_TRANSPORT) {
354
-    if($user_points >= $enemy_points || $config->allow_buffing) {
353
+  if ($mission == MT_TRANSPORT) {
354
+    if ($user_points >= $enemy_points || $config->allow_buffing) {
355 355
       return $result = ATTACK_ALLOWED;
356 356
     } else {
357 357
       return $result = ATTACK_BUFFING;
@@ -361,66 +361,66 @@  discard block
 block discarded – undo
361 361
   // Only aggresive missions passed to this point. HOLD counts as passive but aggresive
362 362
 
363 363
   // Is it admin with planet protection?
364
-  if($planet_dst['id_level'] > $user['authlevel']) {
364
+  if ($planet_dst['id_level'] > $user['authlevel']) {
365 365
     return $result = ATTACK_ADMIN;
366 366
   }
367 367
 
368 368
   // Okay. Now skipping protection checks for inactive longer then 1 week
369
-  if(!$enemy['onlinetime'] || $enemy['onlinetime'] >= (SN_TIME_NOW - 60 * 60 * 24 * 7)) {
370
-    if(
369
+  if (!$enemy['onlinetime'] || $enemy['onlinetime'] >= (SN_TIME_NOW - 60 * 60 * 24 * 7)) {
370
+    if (
371 371
       ($enemy_points <= $config->game_noob_points && $user_points > $config->game_noob_points)
372 372
       ||
373 373
       ($config->game_noob_factor && $user_points > $enemy_points * $config->game_noob_factor)
374 374
     ) {
375
-      if($mission != MT_HOLD) {
375
+      if ($mission != MT_HOLD) {
376 376
         return $result = ATTACK_NOOB;
377 377
       }
378
-      if($mission == MT_HOLD && !($user['ally_id'] && $user['ally_id'] == $enemy['ally_id'] && $config->ally_help_weak)) {
378
+      if ($mission == MT_HOLD && !($user['ally_id'] && $user['ally_id'] == $enemy['ally_id'] && $config->ally_help_weak)) {
379 379
         return $result = ATTACK_NOOB;
380 380
       }
381 381
     }
382 382
   }
383 383
 
384 384
   // Is it HOLD mission? If yes - there should be ally deposit
385
-  if($mission == MT_HOLD) {
386
-    if(mrc_get_level($user, $planet_dst, STRUC_ALLY_DEPOSIT)) {
385
+  if ($mission == MT_HOLD) {
386
+    if (mrc_get_level($user, $planet_dst, STRUC_ALLY_DEPOSIT)) {
387 387
       return $result = ATTACK_ALLOWED;
388 388
     }
389 389
 
390 390
     return $result = ATTACK_NO_ALLY_DEPOSIT;
391 391
   }
392 392
 
393
-  if($mission == MT_SPY) {
393
+  if ($mission == MT_SPY) {
394 394
     return $result = $spies >= 1 ? ATTACK_ALLOWED : ATTACK_NO_SPIES;
395 395
   }
396 396
 
397 397
   // Is it MISSILE mission?
398
-  if($mission == MT_MISSILE) {
398
+  if ($mission == MT_MISSILE) {
399 399
     $sn_data_mip = get_unit_param(UNIT_DEF_MISSILE_INTERPLANET);
400
-    if(mrc_get_level($user, $planet_src, STRUC_SILO) < $sn_data_mip[P_REQUIRE][STRUC_SILO]) {
400
+    if (mrc_get_level($user, $planet_src, STRUC_SILO) < $sn_data_mip[P_REQUIRE][STRUC_SILO]) {
401 401
       return $result = ATTACK_NO_SILO;
402 402
     }
403 403
 
404
-    if(!$fleet[UNIT_DEF_MISSILE_INTERPLANET]) {
404
+    if (!$fleet[UNIT_DEF_MISSILE_INTERPLANET]) {
405 405
       return $result = ATTACK_NO_MISSILE;
406 406
     }
407 407
 
408 408
     $distance = abs($planet_dst['system'] - $planet_src['system']);
409 409
     $mip_range = flt_get_missile_range($user);
410
-    if($distance > $mip_range || $planet_dst['galaxy'] != $planet_src['galaxy']) {
410
+    if ($distance > $mip_range || $planet_dst['galaxy'] != $planet_src['galaxy']) {
411 411
       return $result = ATTACK_MISSILE_TOO_FAR;
412 412
     }
413 413
 
414
-    if(isset($options['target_structure']) && $options['target_structure'] && !in_array($options['target_structure'], sn_get_groups('defense_active'))) {
414
+    if (isset($options['target_structure']) && $options['target_structure'] && !in_array($options['target_structure'], sn_get_groups('defense_active'))) {
415 415
       return $result = ATTACK_WRONG_STRUCTURE;
416 416
     }
417 417
   }
418 418
 
419
-  if($mission == MT_DESTROY && $planet_dst['planet_type'] != PT_MOON) {
419
+  if ($mission == MT_DESTROY && $planet_dst['planet_type'] != PT_MOON) {
420 420
     return $result = ATTACK_WRONG_MISSION;
421 421
   }
422 422
 
423
-  if($mission == MT_ATTACK || $mission == MT_AKS || $mission == MT_DESTROY) {
423
+  if ($mission == MT_ATTACK || $mission == MT_AKS || $mission == MT_DESTROY) {
424 424
     return $result = flt_bashing_check($user, $enemy, $planet_dst, $mission, $travel_data['duration'], $fleet_group);
425 425
   }
426 426
 
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
   $from = $from['planet'];
448 448
 
449 449
   $can_attack = flt_can_attack($from, $to, $fleet_REAL_array, $mission, $options);
450
-  if($can_attack != ATTACK_ALLOWED) {
450
+  if ($can_attack != ATTACK_ALLOWED) {
451 451
     $internal_transaction ? sn_db_transaction_rollback() : false;
452 452
 
453 453
     return $can_attack;
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
   $travel_data = flt_travel_data($user, $from, $to, $fleet_REAL_array, $options['fleet_speed_percent']);
459 459
 
460 460
   $time_on_mission = 0;
461
-  if($mission == MT_EXPLORE || $mission == MT_HOLD) {
461
+  if ($mission == MT_EXPLORE || $mission == MT_HOLD) {
462 462
     // TODO - include some checks about maximum and minumum stay_duration
463 463
     $time_on_mission = $options['stay_time'] * 3600;
464 464
   }
@@ -481,14 +481,14 @@  discard block
 block discarded – undo
481 481
   $sn_group_resources_loot = sn_get_groups('resources_loot');
482 482
   $db_changeset = array();
483 483
   $planet_row_changed_fields = array();
484
-  foreach($fleet_REAL_array as $unit_id => $amount) {
485
-    if(!$amount || !$unit_id) {
484
+  foreach ($fleet_REAL_array as $unit_id => $amount) {
485
+    if (!$amount || !$unit_id) {
486 486
       continue;
487 487
     }
488 488
 
489
-    if(in_array($unit_id, $sn_group_fleet)) {
489
+    if (in_array($unit_id, $sn_group_fleet)) {
490 490
       $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, -$amount, $user, $from['id']);
491
-    } elseif(in_array($unit_id, $sn_group_resources_loot)) {
491
+    } elseif (in_array($unit_id, $sn_group_resources_loot)) {
492 492
       $planet_row_changed_fields[pname_resource_name($unit_id)]['delta'] -= $amount;
493 493
     }
494 494
   }
@@ -527,16 +527,16 @@  discard block
 block discarded – undo
527 527
 
528 528
   $ship_data = array();
529 529
   $fleet_array = array();
530
-  foreach($ship_list as $transport_id => $cork) {
530
+  foreach ($ship_list as $transport_id => $cork) {
531 531
     $ship_data[$transport_id] = flt_travel_data($user, $from, $to, array($transport_id => 1), 10);
532 532
   }
533 533
   uasort($ship_data, 'flt_calculate_ship_to_transport_sort');
534 534
 
535 535
   $fleet_capacity = 0;
536 536
   $fuel_total = $fuel_left = mrc_get_level($user, $from, RES_DEUTERIUM);
537
-  foreach($ship_data as $transport_id => &$ship_info) {
537
+  foreach ($ship_data as $transport_id => &$ship_info) {
538 538
     $ship_loaded = min($ship_list[$transport_id], ceil($resource_amount / $ship_info['hold']), floor($fuel_left / $ship_info['consumption']));
539
-    if($ship_loaded) {
539
+    if ($ship_loaded) {
540 540
       $fleet_array[$transport_id] = $ship_loaded;
541 541
       $resource_amount -= min($resource_amount, $ship_info['hold'] * $ship_loaded);
542 542
       $fuel_left -= $ship_info['consumption'] * $ship_loaded;
Please login to merge, or discard this patch.
includes/includes/sys_stat.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -39,23 +39,23 @@  discard block
 block discarded – undo
39 39
 
40 40
   $sta_update_msg = db_escape($sta_update_msg);
41 41
 
42
-  if($next_step) {
42
+  if ($next_step) {
43 43
     $sta_update_step++;
44 44
   }
45 45
   $sta_update_msg = "Update in progress. Step {$sta_update_step}/14: {$sta_update_msg}.";
46 46
 
47 47
   $config->db_saveItem('var_stat_update_msg', $sta_update_msg);
48
-  if($next_step) {
48
+  if ($next_step) {
49 49
     $debug->warning($sta_update_msg, 'Stat update', LOG_INFO_STAT_PROCESS);
50 50
   }
51 51
 }
52 52
 
53 53
 function sys_stat_calculate_flush(&$data, $force = false) {
54
-  if(count($data) < 25 && !$force) {
54
+  if (count($data) < 25 && !$force) {
55 55
     return;
56 56
   }
57 57
 
58
-  if(!empty($data)) {
58
+  if (!empty($data)) {
59 59
     doquery('REPLACE INTO {{statpoints}}
60 60
       (`id_owner`, `id_ally`, `stat_type`, `stat_code`, `tech_points`, `tech_count`, `build_points`, `build_count`,
61 61
        `defs_points`, `defs_count`, `fleet_points`, `fleet_count`, `res_points`, `res_count`, `total_points`,
@@ -95,11 +95,11 @@  discard block
 block discarded – undo
95 95
   $user_list = db_user_list('', true, 'id, dark_matter, metal, crystal, deuterium, user_as_ally, ally_id');
96 96
   $row_num = count($user_list);
97 97
   // while($player = db_fetch($query))
98
-  foreach($user_list as $player) {
99
-    if($i++ % 100 == 0) {
98
+  foreach ($user_list as $player) {
99
+    if ($i++ % 100 == 0) {
100 100
       sta_set_time_limit("calculating players stats (player {$i}/{$row_num})", false);
101 101
     }
102
-    if(array_key_exists($user_id = $player['id'], $user_skip_list)) {
102
+    if (array_key_exists($user_id = $player['id'], $user_skip_list)) {
103 103
       continue;
104 104
     }
105 105
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
     // $points[$user_id][UNIT_RESOURCES] += $resources;
110 110
 
111 111
     // А здесь мы фильтруем пользователей по $user_skip_list - далее не нужно этого делать, потому что
112
-    if(!isset($user_skip_list[$user_id])) {
112
+    if (!isset($user_skip_list[$user_id])) {
113 113
       $user_allies[$user_id] = $player['ally_id'];
114 114
     }
115 115
   }
@@ -123,11 +123,11 @@  discard block
 block discarded – undo
123 123
   $i = 0;
124 124
   $query = db_planet_list_resources_by_owner();
125 125
   $row_num = db_num_rows($query);
126
-  while($planet = db_fetch($query)) {
127
-    if($i++ % 100 == 0) {
126
+  while ($planet = db_fetch($query)) {
127
+    if ($i++ % 100 == 0) {
128 128
       sta_set_time_limit("calculating planets stats (planet {$i}/{$row_num})", false);
129 129
     }
130
-    if(array_key_exists($user_id = $planet['id_owner'], $user_skip_list)) {
130
+    if (array_key_exists($user_id = $planet['id_owner'], $user_skip_list)) {
131 131
       continue;
132 132
     }
133 133
 
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
   $i = 0;
143 143
   $query = FleetList::dbQueryAllId();
144 144
   $row_num = db_num_rows($query);
145
-  while($fleet_row = db_fetch($query)) {
146
-    if($i++ % 100 == 0) {
145
+  while ($fleet_row = db_fetch($query)) {
146
+    if ($i++ % 100 == 0) {
147 147
       sta_set_time_limit("calculating flying fleets stats (fleet {$i}/{$row_num})", false);
148 148
     }
149 149
     $objFleet = new Fleet();
@@ -151,15 +151,15 @@  discard block
 block discarded – undo
151 151
     // К тому же при включённом кэшировании это быстро забъёт кэш холодными данными
152 152
     // $objFleet->_reset();
153 153
     $objFleet->dbRowParse($fleet_row);
154
-    if(array_key_exists($user_id = $objFleet->playerOwnerId, $user_skip_list)) {
154
+    if (array_key_exists($user_id = $objFleet->playerOwnerId, $user_skip_list)) {
155 155
       continue;
156 156
     }
157 157
 
158 158
     $fleet = $objFleet->get_unit_list();
159
-    foreach($fleet as $unit_id => $unit_amount) {
159
+    foreach ($fleet as $unit_id => $unit_amount) {
160 160
       $counts[$user_id][UNIT_SHIPS] += $unit_amount;
161 161
 
162
-      if(!isset($unit_cost_cache[$unit_id][0])) {
162
+      if (!isset($unit_cost_cache[$unit_id][0])) {
163 163
         $unit_cost_cache[$unit_id][0] = get_unit_param($unit_id, P_COST);
164 164
       }
165 165
       $unit_cost_data = &$unit_cost_cache[$unit_id][0];
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
   $i = 0;
180 180
   $query = db_unit_list_stat_calculate();
181 181
   $row_num = db_num_rows($query);
182
-  while($unit = db_fetch($query)) {
183
-    if($i++ % 100 == 0) {
182
+  while ($unit = db_fetch($query)) {
183
+    if ($i++ % 100 == 0) {
184 184
       sta_set_time_limit("calculating unit stats (unit {$i}/{$row_num})", false);
185 185
     }
186
-    if(array_key_exists($user_id = $unit['unit_player_id'], $user_skip_list)) {
186
+    if (array_key_exists($user_id = $unit['unit_player_id'], $user_skip_list)) {
187 187
       continue;
188 188
     }
189 189
 
@@ -197,11 +197,11 @@  discard block
 block discarded – undo
197 197
   $i = 0;
198 198
   $query = db_que_list_stat();
199 199
   $row_num = db_num_rows($query);
200
-  while($que_item = db_fetch($query)) {
201
-    if($i++ % 100 == 0) {
200
+  while ($que_item = db_fetch($query)) {
201
+    if ($i++ % 100 == 0) {
202 202
       sta_set_time_limit("calculating ques stats (que item {$i}/{$row_num})", false);
203 203
     }
204
-    if(array_key_exists($user_id = $que_item['que_player_id'], $user_skip_list)) {
204
+    if (array_key_exists($user_id = $que_item['que_player_id'], $user_skip_list)) {
205 205
       continue;
206 206
     }
207 207
     $que_unit_amount = $que_item['que_unit_amount'];
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 
220 220
   sta_set_time_limit('posting new user stats to DB');
221 221
   $data = array();
222
-  foreach($user_allies as $user_id => $ally_id) {
222
+  foreach ($user_allies as $user_id => $ally_id) {
223 223
     // $counts[UNIT_RESOURCES] дублирует $points[UNIT_RESOURCES], поэтому $points не заполняем, а берем $counts и делим на 1000
224 224
     $points[$user_id][UNIT_RESOURCES] = $counts[$user_id][UNIT_RESOURCES] / 1000;
225 225
     $points[$user_id] = array_map('floor', $points[$user_id]);
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 
276 276
   // Updating player's ranks
277 277
   sta_set_time_limit("updating ranks for players");
278
-  foreach($rankNames as $rankName) {
278
+  foreach ($rankNames as $rankName) {
279 279
     sta_set_time_limit("updating player rank '{$rankName}'", false);
280 280
     doquery($qryResetRowNum);
281 281
     doquery(sprintf($qryFormat, $rankName, 1));
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 
284 284
   sta_set_time_limit("updating ranks for Alliances");
285 285
   // --- Updating Allie's ranks
286
-  foreach($rankNames as $rankName) {
286
+  foreach ($rankNames as $rankName) {
287 287
     sta_set_time_limit("updating Alliances rank '{$rankName}'", false);
288 288
     doquery($qryResetRowNum);
289 289
     doquery(sprintf($qryFormat, $rankName, 2));
Please login to merge, or discard this patch.
includes/includes/flt_page3.inc 1 patch
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 // @version 1.0
4 4
 // @copyright 2008 by Chlorel for XNova
5 5
 
6
-if(SN_IN_FLEET !== true) {
6
+if (SN_IN_FLEET !== true) {
7 7
   $debug->error("Attempt to call FLEET page mode {$mode} directly - not from fleet.php", 'Forbidden', 403);
8 8
 }
9 9
 
@@ -20,25 +20,25 @@  discard block
 block discarded – undo
20 20
 
21 21
   // Test de coherance de la destination (voir si elle se trouve dans les limites de l'univers connu
22 22
   $errorlist = '';
23
-  if(!$galaxy || $galaxy > $config->game_maxGalaxy || $galaxy < 1) {
23
+  if (!$galaxy || $galaxy > $config->game_maxGalaxy || $galaxy < 1) {
24 24
     $errorlist .= $lang['fl_limit_galaxy'];
25 25
   }
26
-  if(!$system || $system > $config->game_maxSystem || $system < 1) {
26
+  if (!$system || $system > $config->game_maxSystem || $system < 1) {
27 27
     $errorlist .= $lang['fl_limit_system'];
28 28
   }
29
-  if(!$planet || $planet < 1 || ($planet > $config->game_maxPlanet && $target_mission != MT_EXPLORE)) {
29
+  if (!$planet || $planet < 1 || ($planet > $config->game_maxPlanet && $target_mission != MT_EXPLORE)) {
30 30
     $errorlist .= $lang['fl_limit_planet'];
31 31
   }
32
-  if($planetrow['galaxy'] == $galaxy && $planetrow['system'] == $system && $planetrow['planet'] == $planet && $planetrow['planet_type'] == $planet_type) {
32
+  if ($planetrow['galaxy'] == $galaxy && $planetrow['system'] == $system && $planetrow['planet'] == $planet && $planetrow['planet_type'] == $planet_type) {
33 33
     $errorlist .= $lang['fl_ownpl_err'];
34 34
   }
35
-  if(!$planet_type) {
35
+  if (!$planet_type) {
36 36
     $errorlist .= $lang['fl_no_planettype'];
37 37
   }
38
-  if($planet_type != PT_PLANET && $planet_type != PT_DEBRIS && $planet_type != PT_MOON) {
38
+  if ($planet_type != PT_PLANET && $planet_type != PT_DEBRIS && $planet_type != PT_MOON) {
39 39
     $errorlist .= $lang['fl_fleet_err_pl'];
40 40
   }
41
-  if(empty($missiontype[$target_mission])) {
41
+  if (empty($missiontype[$target_mission])) {
42 42
     $errorlist .= $lang['fl_bad_mission'];
43 43
   }
44 44
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
   $TransDeuterium = max(0, sys_get_param_float('resource2'));
48 48
   $StorageNeeded = $TransMetal + $TransCrystal + $TransDeuterium;
49 49
 
50
-  if(!$StorageNeeded && $target_mission == MT_TRANSPORT) {
50
+  if (!$StorageNeeded && $target_mission == MT_TRANSPORT) {
51 51
     $errorlist .= $lang['fl_noenoughtgoods'];
52 52
   }
53 53
 
@@ -56,41 +56,41 @@  discard block
 block discarded – undo
56 56
   $user = db_user_by_id($user['id'], true);
57 57
   $planetrow = db_planet_by_id($planetrow['id'], true);
58 58
 
59
-  if($target_mission == MT_EXPLORE) {
60
-    if($MaxExpeditions == 0) {
59
+  if ($target_mission == MT_EXPLORE) {
60
+    if ($MaxExpeditions == 0) {
61 61
       $errorlist .= $lang['fl_expe_notech'];
62
-    } elseif($FlyingExpeditions >= $MaxExpeditions) {
62
+    } elseif ($FlyingExpeditions >= $MaxExpeditions) {
63 63
       $errorlist .= $lang['fl_expe_max'];
64 64
     }
65 65
   } else {
66
-    if($TargetPlanet['id_owner']) {
67
-      if($target_mission == MT_COLONIZE) {
66
+    if ($TargetPlanet['id_owner']) {
67
+      if ($target_mission == MT_COLONIZE) {
68 68
         $errorlist .= $lang['fl_colonized'];
69 69
       }
70 70
 
71
-      if($TargetPlanet['id_owner'] == $planetrow['id_owner']) {
72
-        if($target_mission == MT_ATTACK) {
71
+      if ($TargetPlanet['id_owner'] == $planetrow['id_owner']) {
72
+        if ($target_mission == MT_ATTACK) {
73 73
           $errorlist .= $lang['fl_no_self_attack'];
74 74
         }
75 75
 
76
-        if($target_mission == MT_SPY) {
76
+        if ($target_mission == MT_SPY) {
77 77
           $errorlist .= $lang['fl_no_self_spy'];
78 78
         }
79 79
       } else {
80
-        if($target_mission == MT_RELOCATE) {
80
+        if ($target_mission == MT_RELOCATE) {
81 81
           $errorlist .= $lang['fl_only_stay_at_home'];
82 82
         }
83 83
       }
84 84
     } else {
85
-      if($target_mission < MT_COLONIZE) {
85
+      if ($target_mission < MT_COLONIZE) {
86 86
         $errorlist .= $lang['fl_unknow_target'];
87 87
       } else {
88
-        if($target_mission == MT_DESTROY) {
88
+        if ($target_mission == MT_DESTROY) {
89 89
           $errorlist .= $lang['fl_nomoon'];
90 90
         }
91 91
 
92
-        if($target_mission == MT_RECYCLE) {
93
-          if($TargetPlanet['debris_metal'] + $TargetPlanet['debris_crystal'] == 0) {
92
+        if ($target_mission == MT_RECYCLE) {
93
+          if ($TargetPlanet['debris_metal'] + $TargetPlanet['debris_crystal'] == 0) {
94 94
             $errorlist .= $lang['fl_nodebris'];
95 95
           }
96 96
         }
@@ -99,13 +99,13 @@  discard block
 block discarded – undo
99 99
   }
100 100
 
101 101
 
102
-  if($sn_module['unit_captain']->manifest['active'] && $captain_id = sys_get_param_id('captain_id')) {
102
+  if ($sn_module['unit_captain']->manifest['active'] && $captain_id = sys_get_param_id('captain_id')) {
103 103
     $captain = $sn_module['unit_captain']->unit_captain_get($planetrow['id']);
104 104
 //      mrc_get_level($user, $planetrow, UNIT_CAPTAIN, true);
105
-    if(!$captain) {
105
+    if (!$captain) {
106 106
       $errorlist .= $lang['module_unit_captain_error_no_captain'];
107
-    } elseif($captain['unit_location_type'] == LOC_PLANET) {
108
-      if($target_mission == MT_RELOCATE && ($arriving_captain = mrc_get_level($user, $TargetPlanet, UNIT_CAPTAIN, true))) {
107
+    } elseif ($captain['unit_location_type'] == LOC_PLANET) {
108
+      if ($target_mission == MT_RELOCATE && ($arriving_captain = mrc_get_level($user, $TargetPlanet, UNIT_CAPTAIN, true))) {
109 109
         $errorlist .= $lang['module_unit_captain_error_captain_already_bound'];
110 110
       }
111 111
     } else {
@@ -113,14 +113,14 @@  discard block
 block discarded – undo
113 113
     }
114 114
   }
115 115
 
116
-  if($errorlist) {
116
+  if ($errorlist) {
117 117
     sn_db_transaction_rollback();
118 118
     message("<span class='error'><ul>{$errorlist}</ul></span>", $lang['fl_error'], 'fleet' . DOT_PHP_EX, false);
119 119
   }
120 120
 
121 121
   // On verifie s'il y a assez de vaisseaux sur la planete !
122
-  foreach($fleetarray as $Ship => $Count) {
123
-    if($Count > mrc_get_level($user, $planetrow, $Ship)) {
122
+  foreach ($fleetarray as $Ship => $Count) {
123
+    if ($Count > mrc_get_level($user, $planetrow, $Ship)) {
124 124
       message("<span class='error'><b>{$lang['fl_fleet_err']}</b></span>", $lang['fl_error'], 'fleet' . DOT_PHP_EX, 2);
125 125
     }
126 126
   }
@@ -131,10 +131,10 @@  discard block
 block discarded – undo
131 131
   //But is it acs??
132 132
   //Well all acs fleets must have a fleet code.
133 133
   //The co-ords must be the same as where the acs fleet is going.
134
-  if($fleet_group && sys_get_param_str('acs_target_mr') == "g{$galaxy}s{$system}p{$planet}t{$planet_type}") {
134
+  if ($fleet_group && sys_get_param_str('acs_target_mr') == "g{$galaxy}s{$system}p{$planet}t{$planet_type}") {
135 135
     //ACS attack must exist (if acs fleet has arrived this will also return false (2 checks in 1!!!)
136 136
     $aks = db_acs_get_by_group_id($fleet_group);
137
-    if(!$aks) {
137
+    if (!$aks) {
138 138
       $fleet_group = 0;
139 139
     } else {
140 140
       //Also it must be mission type 2
@@ -145,31 +145,31 @@  discard block
 block discarded – undo
145 145
       $planet = $aks['planet'];
146 146
       $planet_type = $aks['planet_type'];
147 147
     }
148
-  } elseif($target_mission == MT_AKS) {
148
+  } elseif ($target_mission == MT_AKS) {
149 149
     //Check that a failed acs attack isn't being sent, if it is, make it an attack fleet.
150 150
     $target_mission = MT_ATTACK;
151 151
   }
152 152
 
153
-  if($target_mission == MT_COLONIZE || $target_mission == MT_EXPLORE) {
153
+  if ($target_mission == MT_COLONIZE || $target_mission == MT_EXPLORE) {
154 154
     $TargetPlanet = array('galaxy' => $galaxy, 'system' => $system, 'planet' => $planet, 'id_owner' => 0);
155 155
   }
156 156
   $options = array('fleet_speed_percent' => $speed_percent, 'fleet_group' => $fleet_group, 'resources' => $StorageNeeded);
157 157
   $cant_attack = flt_can_attack($planetrow, $TargetPlanet, $fleetarray, $target_mission, $options);
158 158
 
159
-  if($cant_attack !== ATTACK_ALLOWED) {
159
+  if ($cant_attack !== ATTACK_ALLOWED) {
160 160
     message("<span class='error'><b>{$lang['fl_attack_error'][$cant_attack]}</b></span>", $lang['fl_error'], 'fleet' . DOT_PHP_EX, 99);
161 161
   }
162 162
 
163 163
   $speed_possible = array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1);
164
-  if(!in_array($speed_percent, $speed_possible)) {
164
+  if (!in_array($speed_percent, $speed_possible)) {
165 165
     message("<span class='error'><b>" . $lang['fl_cheat_speed'] . "</b></span>", $lang['fl_error'], 'fleet' . DOT_PHP_EX, 2);
166 166
   }
167 167
 
168 168
   $mission_time_in_seconds = 0;
169 169
   $arrival_time = SN_TIME_NOW + $time_to_travel;
170
-  if($target_mission == MT_AKS && $aks) {
170
+  if ($target_mission == MT_AKS && $aks) {
171 171
 //    if($fleet_start_time > $aks['ankunft']) {
172
-    if($arrival_time > $aks['ankunft']) {
172
+    if ($arrival_time > $aks['ankunft']) {
173 173
       message($lang['fl_aks_too_slow'] . 'Fleet arrival: ' . date(FMT_DATE_TIME, $arrival_time) . " AKS arrival: " . date(FMT_DATE_TIME, $aks['ankunft']), $lang['fl_error']);
174 174
     }
175 175
     $group_sync_delta_time = $aks['ankunft'] - $arrival_time;
@@ -178,11 +178,11 @@  discard block
 block discarded – undo
178 178
     // Set return time to ACS return time + fleet's time to travel
179 179
     $return_time = $aks['ankunft'] + $time_to_travel;
180 180
   } else {
181
-    if($target_mission == MT_EXPLORE || $target_mission == MT_HOLD) {
181
+    if ($target_mission == MT_EXPLORE || $target_mission == MT_HOLD) {
182 182
       $max_duration = $target_mission == MT_EXPLORE ? get_player_max_expedition_duration($user) : ($target_mission == MT_HOLD ? 12 : 0);
183
-      if($max_duration) {
183
+      if ($max_duration) {
184 184
         $mission_time_in_hours = sys_get_param_id('missiontime');
185
-        if($mission_time_in_hours > $max_duration || $mission_time_in_hours < 1) {
185
+        if ($mission_time_in_hours > $max_duration || $mission_time_in_hours < 1) {
186 186
           $debug->warning('Supplying wrong mission time', 'Hack attempt', 302, array('base_dump' => true));
187 187
           die();
188 188
         }
@@ -196,19 +196,19 @@  discard block
 block discarded – undo
196 196
   $FleetStorage = 0;
197 197
 
198 198
   $db_changeset = array();
199
-  foreach($fleetarray as $Ship => $Count) {
199
+  foreach ($fleetarray as $Ship => $Count) {
200 200
     $FleetStorage += get_unit_param($Ship, P_CAPACITY) * $Count;
201 201
     $db_changeset['unit'][] = sn_db_unit_changeset_prepare($Ship, -$Count, $user, $planetrow['id']);
202 202
   }
203 203
   $FleetStorage -= $consumption;
204 204
 
205
-  if($StorageNeeded > $FleetStorage) {
205
+  if ($StorageNeeded > $FleetStorage) {
206 206
     message("<span class='error'><b>" . $lang['fl_nostoragespa'] . pretty_number($StorageNeeded - $FleetStorage) . "</b></span>", $lang['fl_error'], 'fleet' . DOT_PHP_EX, 2);
207 207
   }
208
-  if($planetrow['deuterium'] < $TransDeuterium + $consumption) {
208
+  if ($planetrow['deuterium'] < $TransDeuterium + $consumption) {
209 209
     message("<font color=\"red\"><b>" . $lang['fl_no_deuterium'] . pretty_number($TransDeuterium + $consumption - $planetrow['deuterium']) . "</b></font>", $lang['fl_error'], 'fleet' . DOT_PHP_EX, 2);
210 210
   }
211
-  if(($planetrow['metal'] < $TransMetal) || ($planetrow['crystal'] < $TransCrystal)) {
211
+  if (($planetrow['metal'] < $TransMetal) || ($planetrow['crystal'] < $TransCrystal)) {
212 212
     message("<font color=\"red\"><b>" . $lang['fl_no_resources'] . "</b></font>", $lang['fl_error'], 'fleet' . DOT_PHP_EX, 2);
213 213
   }
214 214
 
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 
239 239
   $template = gettemplate('fleet3', true);
240 240
 
241
-  if(is_array($captain)) {
241
+  if (is_array($captain)) {
242 242
     db_unit_set_by_id($captain['unit_id'], "`unit_location_type` = " . LOC_FLEET . ", `unit_location_id` = {$objFleet->dbId}");
243 243
   }
244 244
 
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
     'START_LEFT'         => floor($return_time + 1 - SN_TIME_NOW),
252 252
   );
253 253
 
254
-  if(!empty($TargetPlanet)) {
254
+  if (!empty($TargetPlanet)) {
255 255
     $template_route += array(
256 256
       'END_TYPE_TEXT_SH' => $lang['sys_planet_type_sh'][$TargetPlanet['planet_type']],
257 257
       'END_COORDS'       => uni_render_coordinates($TargetPlanet),
@@ -264,8 +264,8 @@  discard block
 block discarded – undo
264 264
   $template->assign_block_vars('fleets', $template_route);
265 265
 
266 266
   $sn_groups_fleet = sn_get_groups('fleet');
267
-  foreach($fleetarray as $ship_id => $ship_count) {
268
-    if(in_array($ship_id, $sn_groups_fleet) && $ship_count) {
267
+  foreach ($fleetarray as $ship_id => $ship_count) {
268
+    if (in_array($ship_id, $sn_groups_fleet) && $ship_count) {
269 269
 //      $ship_base_data = get_ship_data($ship_id, $user);
270 270
       $template->assign_block_vars('fleets.ships', array(
271 271
         'ID'          => $ship_id,
Please login to merge, or discard this patch.
includes/classes/module.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -98,13 +98,13 @@  discard block
 block discarded – undo
98 98
     // Trying to load configuration from file
99 99
     $config_exists = false;
100 100
     // Конфигурация может лежать в config_path в манифеста или в корне модуля
101
-    if(isset($this->manifest['config_path']) && file_exists($config_filename = $this->manifest['config_path'] . '/config.php')) {
101
+    if (isset($this->manifest['config_path']) && file_exists($config_filename = $this->manifest['config_path'] . '/config.php')) {
102 102
       $config_exists = true;
103
-    } elseif(file_exists($config_filename = dirname($filename) . '/config.php')) {
103
+    } elseif (file_exists($config_filename = dirname($filename) . '/config.php')) {
104 104
       $config_exists = true;
105 105
     }
106 106
 
107
-    if($config_exists) {
107
+    if ($config_exists) {
108 108
       include($config_filename);
109 109
       $module_config_array = $class_module_name . '_config';
110 110
       $this->config = $$module_config_array;
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
   }
116 116
 
117 117
   protected function __patch_menu(&$sn_menu_extra, &$menu_patch) {
118
-    if(isset($menu_patch) && is_array($menu_patch) && !empty($menu_patch)) {
119
-      foreach($menu_patch as $menu_item_name => $menu_item_data) {
118
+    if (isset($menu_patch) && is_array($menu_patch) && !empty($menu_patch)) {
119
+      foreach ($menu_patch as $menu_item_name => $menu_item_data) {
120 120
         $sn_menu_extra[$menu_item_name] = $menu_item_data;
121 121
       }
122 122
     }
@@ -126,13 +126,13 @@  discard block
 block discarded – undo
126 126
   public function initialize() {
127 127
     // Checking module status - is it installed and active
128 128
     $this->check_status();
129
-    if(!$this->manifest['active']) {
129
+    if (!$this->manifest['active']) {
130 130
       return;
131 131
     }
132 132
 
133 133
     // Setting constants - if any
134
-    if(isset($this->manifest['constants']) && is_array($this->manifest['constants']) && !empty($this->manifest['constants'])) {
135
-      foreach($this->manifest['constants'] as $constant_name => $constant_value) {
134
+    if (isset($this->manifest['constants']) && is_array($this->manifest['constants']) && !empty($this->manifest['constants'])) {
135
+      foreach ($this->manifest['constants'] as $constant_name => $constant_value) {
136 136
         defined($constant_name) or define($constant_name, $constant_value);
137 137
       }
138 138
     }
@@ -143,34 +143,34 @@  discard block
 block discarded – undo
143 143
     // New values from module variables will overwrite previous values (for root variables) and array elements with corresponding indexes (for arrays)
144 144
     // Constants as array indexes are honored - it's make valid such declarations as 'sn_data[ques][QUE_STRUCTURES]'
145 145
     $this->manifest['vars'] = $this->__assign_vars();
146
-    if(!empty($this->manifest['vars'])) {
146
+    if (!empty($this->manifest['vars'])) {
147 147
       $vars_assigned = array();
148
-      foreach($this->manifest['vars'] as $var_name => $var_value) {
148
+      foreach ($this->manifest['vars'] as $var_name => $var_value) {
149 149
         $sub_vars = explode('[', str_replace(']', '', $var_name));
150 150
         $var_name = $sub_vars[0];
151 151
 
152
-        if(!isset($vars_assigned[$var_name])) {
152
+        if (!isset($vars_assigned[$var_name])) {
153 153
           $vars_assigned[$var_name] = true;
154 154
           global $$var_name;
155 155
         }
156 156
 
157 157
         $pointer = &$$var_name;
158
-        if(($n = count($sub_vars)) > 1) {
159
-          for($i = 1; $i < $n; $i++) {
160
-            if(defined($sub_vars[$i])) {
158
+        if (($n = count($sub_vars)) > 1) {
159
+          for ($i = 1; $i < $n; $i++) {
160
+            if (defined($sub_vars[$i])) {
161 161
               $sub_vars[$i] = constant($sub_vars[$i]);
162 162
             }
163 163
 
164
-            if(!isset($pointer[$sub_vars[$i]]) && $i != $n) {
164
+            if (!isset($pointer[$sub_vars[$i]]) && $i != $n) {
165 165
               $pointer[$sub_vars[$i]] = array();
166 166
             }
167 167
             $pointer = &$pointer[$sub_vars[$i]];
168 168
           }
169 169
         }
170 170
 
171
-        if(!isset($pointer) || !is_array($pointer)) {
171
+        if (!isset($pointer) || !is_array($pointer)) {
172 172
           $pointer = $var_value;
173
-        } elseif(is_array($$var_name)) {
173
+        } elseif (is_array($$var_name)) {
174 174
           $pointer = array_merge_recursive_numeric($pointer, $var_value);
175 175
         }
176 176
       }
@@ -186,44 +186,44 @@  discard block
 block discarded – undo
186 186
     isset($this->manifest['menu_admin']) and $this->__patch_menu($sn_menu_admin_extra, $this->manifest['menu_admin']);
187 187
 
188 188
     global $sn_mvc;
189
-    foreach($sn_mvc as $handler_type => &$handler_data) {
189
+    foreach ($sn_mvc as $handler_type => &$handler_data) {
190 190
       sn_sys_handler_add($handler_data, $this->manifest['mvc'][$handler_type], $this, $handler_type);
191 191
     }
192 192
 
193
-    if(isset($this->manifest['i18n']) && is_array($this->manifest['i18n']) && !empty($this->manifest['i18n'])) {
194
-      foreach($this->manifest['i18n'] as $i18n_page_name => &$i18n_file_list) {
195
-        foreach($i18n_file_list as &$i18n_file_data) {
196
-          if(is_array($i18n_file_data) && !$i18n_file_data['path']) {
193
+    if (isset($this->manifest['i18n']) && is_array($this->manifest['i18n']) && !empty($this->manifest['i18n'])) {
194
+      foreach ($this->manifest['i18n'] as $i18n_page_name => &$i18n_file_list) {
195
+        foreach ($i18n_file_list as &$i18n_file_data) {
196
+          if (is_array($i18n_file_data) && !$i18n_file_data['path']) {
197 197
             $i18n_file_data['path'] = $this->manifest['root_relative'];
198 198
           }
199 199
         }
200
-        if(!isset($sn_mvc['i18n'][$i18n_page_name])) {
200
+        if (!isset($sn_mvc['i18n'][$i18n_page_name])) {
201 201
           $sn_mvc['i18n'][$i18n_page_name] = array();
202 202
         }
203 203
         $sn_mvc['i18n'][$i18n_page_name] += $i18n_file_list;
204 204
       }
205 205
     }
206 206
 
207
-    if(!empty($this->manifest['javascript']) && is_array($this->manifest['javascript'])) {
208
-      foreach($this->manifest['javascript'] as $javascript_page_name => &$javascript_list) {
207
+    if (!empty($this->manifest['javascript']) && is_array($this->manifest['javascript'])) {
208
+      foreach ($this->manifest['javascript'] as $javascript_page_name => &$javascript_list) {
209 209
         !isset($sn_mvc['javascript'][$javascript_page_name]) ? $sn_mvc['javascript'][$javascript_page_name] = array() : false;
210
-        foreach($javascript_list as $script_name => &$script_content) {
210
+        foreach ($javascript_list as $script_name => &$script_content) {
211 211
           $sn_mvc['javascript'][$javascript_page_name][$script_name] = $script_content;
212 212
         }
213 213
       }
214 214
     }
215 215
 
216
-    if(!empty($this->manifest['css']) && is_array($this->manifest['css'])) {
217
-      foreach($this->manifest['css'] as $javascript_page_name => &$javascript_list) {
216
+    if (!empty($this->manifest['css']) && is_array($this->manifest['css'])) {
217
+      foreach ($this->manifest['css'] as $javascript_page_name => &$javascript_list) {
218 218
         !isset($sn_mvc['css'][$javascript_page_name]) ? $sn_mvc['css'][$javascript_page_name] = array() : false;
219
-        foreach($javascript_list as $script_name => &$script_content) {
219
+        foreach ($javascript_list as $script_name => &$script_content) {
220 220
           $sn_mvc['css'][$javascript_page_name][$script_name] = $script_content;
221 221
         }
222 222
       }
223 223
     }
224 224
 
225
-    if(!empty($this->manifest['navbar_prefix_button']) && is_array($this->manifest['navbar_prefix_button'])) {
226
-      foreach($this->manifest['navbar_prefix_button'] as $button_image => $button_url_relative) {
225
+    if (!empty($this->manifest['navbar_prefix_button']) && is_array($this->manifest['navbar_prefix_button'])) {
226
+      foreach ($this->manifest['navbar_prefix_button'] as $button_image => $button_url_relative) {
227 227
         $sn_mvc['navbar_prefix_button'][$button_image] = $button_url_relative;
228 228
       }
229 229
     }
Please login to merge, or discard this patch.
includes/classes/UBE/UBEReport.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -15,14 +15,14 @@  discard block
 block discarded – undo
15 15
     global $config;
16 16
 
17 17
     // Если уже есть ИД репорта - значит репорт был взят из таблицы. С таким мы не работаем
18
-    if($ube->get_cypher()) {
18
+    if ($ube->get_cypher()) {
19 19
       return false;
20 20
     }
21 21
 
22 22
     // Генерируем уникальный секретный ключ и проверяем наличие в базе
23 23
     do {
24 24
       $ube->report_cypher = sys_random_string(32);
25
-    } while(doquery("SELECT ube_report_cypher FROM {{ube_report}} WHERE ube_report_cypher = '{$ube->report_cypher}' LIMIT 1 FOR UPDATE", true));
25
+    } while (doquery("SELECT ube_report_cypher FROM {{ube_report}} WHERE ube_report_cypher = '{$ube->report_cypher}' LIMIT 1 FOR UPDATE", true));
26 26
 
27 27
     // Инициализация таблицы для пакетной вставки информации
28 28
     $sql_perform = array(
@@ -113,21 +113,21 @@  discard block
 block discarded – undo
113 113
       `ube_report_time_combat` = '" . date(FMT_DATE_TIME_SQL, $ube->combat_timestamp) . "',
114 114
       `ube_report_time_spent` = {$ube->time_spent},
115 115
 
116
-      `ube_report_combat_admin` = " . (int)$ube->is_admin_in_combat . ",
116
+      `ube_report_combat_admin` = " . (int) $ube->is_admin_in_combat . ",
117 117
       `ube_report_mission_type` = {$ube->mission_type_id},
118 118
 
119 119
       `ube_report_combat_result` = {$ube->combat_result},
120
-      `ube_report_combat_sfr` = " . (int)$ube->is_small_fleet_recce . ",
120
+      `ube_report_combat_sfr` = " . (int) $ube->is_small_fleet_recce . ",
121 121
 
122
-      `ube_report_planet_id`          = " . (int)$ube->ube_planet_info[PLANET_ID] . ",
122
+      `ube_report_planet_id`          = " . (int) $ube->ube_planet_info[PLANET_ID] . ",
123 123
       `ube_report_planet_name`        = '" . db_escape($ube->ube_planet_info[PLANET_NAME]) . "',
124
-      `ube_report_planet_size`        = " . (int)$ube->ube_planet_info[PLANET_SIZE] . ",
125
-      `ube_report_planet_galaxy`      = " . (int)$ube->ube_planet_info[PLANET_GALAXY] . ",
126
-      `ube_report_planet_system`      = " . (int)$ube->ube_planet_info[PLANET_SYSTEM] . ",
127
-      `ube_report_planet_planet`      = " . (int)$ube->ube_planet_info[PLANET_PLANET] . ",
128
-      `ube_report_planet_planet_type` = " . (int)$ube->ube_planet_info[PLANET_TYPE] . ",
124
+      `ube_report_planet_size`        = " . (int) $ube->ube_planet_info[PLANET_SIZE] . ",
125
+      `ube_report_planet_galaxy`      = " . (int) $ube->ube_planet_info[PLANET_GALAXY] . ",
126
+      `ube_report_planet_system`      = " . (int) $ube->ube_planet_info[PLANET_SYSTEM] . ",
127
+      `ube_report_planet_planet`      = " . (int) $ube->ube_planet_info[PLANET_PLANET] . ",
128
+      `ube_report_planet_planet_type` = " . (int) $ube->ube_planet_info[PLANET_TYPE] . ",
129 129
 
130
-      `ube_report_capture_result` = " . (int)$ube->capture_result . ", "
130
+      `ube_report_capture_result` = " . (int) $ube->capture_result . ", "
131 131
       . $ube->debris->report_generate_sql($config)
132 132
       . $ube->moon_calculator->report_generate_sql();
133 133
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 
137 137
     // Сохраняем общую информацию по игрокам
138 138
     $player_sides = $ube->players->get_player_sides();
139
-    foreach($player_sides as $player_id => $player_side) {
139
+    foreach ($player_sides as $player_id => $player_side) {
140 140
       $sql_perform['ube_report_player'][] = array(
141 141
         $ube_report_id,
142 142
         $player_id,
@@ -144,14 +144,14 @@  discard block
 block discarded – undo
144 144
         "'" . db_escape($ube->players[$player_id]->name) . "'",
145 145
         $ube->players[$player_id]->getSide() == UBE_PLAYER_IS_ATTACKER ? 1 : 0,
146 146
 
147
-        (float)$ube->players[$player_id]->player_bonus->calcBonus(P_ATTACK),
148
-        (float)$ube->players[$player_id]->player_bonus->calcBonus(P_SHIELD),
149
-        (float)$ube->players[$player_id]->player_bonus->calcBonus(P_ARMOR),
147
+        (float) $ube->players[$player_id]->player_bonus->calcBonus(P_ATTACK),
148
+        (float) $ube->players[$player_id]->player_bonus->calcBonus(P_SHIELD),
149
+        (float) $ube->players[$player_id]->player_bonus->calcBonus(P_ARMOR),
150 150
       );
151 151
     }
152 152
 
153 153
     // Всякая информация по флотам
154
-    foreach($ube->fleet_list->_container as $fleet_id => $UBEFleet) {
154
+    foreach ($ube->fleet_list->_container as $fleet_id => $UBEFleet) {
155 155
       // Сохраняем общую информацию по флотам
156 156
       $sql_perform['ube_report_fleet'][] = $UBEFleet->sql_generate_array($ube_report_id);
157 157
 
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
     $ube->rounds->sql_generate_unit_array($sql_perform['ube_report_unit'], $ube_report_id, $ube->fleet_list);
168 168
 
169 169
     // Пакетная вставка данных
170
-    foreach($sql_perform as $table_name => $table_data) {
171
-      if(count($table_data) < 2) {
170
+    foreach ($sql_perform as $table_name => $table_data) {
171
+      if (count($table_data) < 2) {
172 172
         continue;
173 173
       }
174
-      foreach($table_data as &$record_data) {
174
+      foreach ($table_data as &$record_data) {
175 175
         $record_data = '(' . implode(',', $record_data) . ')';
176 176
       }
177 177
       $fields = $table_data[0];
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
     $report_cypher = db_escape($report_cypher);
195 195
 
196 196
     $report_row = doquery("SELECT * FROM {{ube_report}} WHERE ube_report_cypher = '{$report_cypher}' LIMIT 1", true);
197
-    if(!$report_row) {
197
+    if (!$report_row) {
198 198
       return UBE_REPORT_NOT_FOUND;
199 199
     }
200 200
 
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
    * @param     $template_result
211 211
    */
212 212
   function sn_ube_report_generate(UBE $ube, &$template_result) {
213
-    if(!is_object($ube)) {
213
+    if (!is_object($ube)) {
214 214
       return;
215 215
     }
216 216
 
@@ -227,15 +227,15 @@  discard block
 block discarded – undo
227 227
 
228 228
     // Координаты, тип и название планеты - если есть
229 229
 //R  $planet_owner_id = $combat_data[UBE_FLEETS][0][UBE_OWNER];
230
-    if(isset($ube->ube_planet_info)) {
230
+    if (isset($ube->ube_planet_info)) {
231 231
       $template_result += $ube->ube_planet_info;
232 232
       $template_result[PLANET_NAME] = str_replace(' ', '&nbsp;', htmlentities($template_result[PLANET_NAME], ENT_COMPAT, 'UTF-8'));
233 233
     }
234 234
 
235 235
     // Обломки
236 236
     $debris = array();
237
-    foreach(array(RES_METAL, RES_CRYSTAL) as $resource_id) {
238
-      if($resource_amount = $ube->debris->debris_get_resource($resource_id)) {
237
+    foreach (array(RES_METAL, RES_CRYSTAL) as $resource_id) {
238
+      if ($resource_amount = $ube->debris->debris_get_resource($resource_id)) {
239 239
         $debris[] = array(
240 240
           'NAME'   => $lang['tech'][$resource_id],
241 241
           'AMOUNT' => pretty_number($resource_amount),
Please login to merge, or discard this patch.
includes/classes/UBE/UBEUnit.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
     parent::setUnitId($unitId);
51 51
 
52 52
     // Reset combat stats??
53
-    if($this->_unitId) {
53
+    if ($this->_unitId) {
54 54
       $this->amplify = $this->info[P_AMPLIFY];
55 55
       $this->capacity = $this->info[P_CAPACITY];
56 56
       $this->price[RES_METAL] = $this->info[P_COST][RES_METAL];
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
     $this->bonus_attack = $this->info[P_ATTACK];
73 73
     $this->bonus_shield = $this->info[P_SHIELD];
74 74
     $this->bonus_armor = $this->info[P_ARMOR];
75
-    if(is_object($this->unit_bonus)) {
75
+    if (is_object($this->unit_bonus)) {
76 76
       $this->bonus_attack = floor($this->bonus_attack * $this->unit_bonus->calcBonus(P_ATTACK));
77 77
       $this->bonus_shield = floor($this->bonus_shield * $this->unit_bonus->calcBonus(P_SHIELD));
78 78
       $this->bonus_armor = floor($this->bonus_armor * $this->unit_bonus->calcBonus(P_ARMOR));
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
     $this->randomized_attack = $this->bonus_attack;
81 81
     $this->randomized_shield = $this->bonus_shield;
82 82
     $this->randomized_armor = $this->bonus_armor;
83
-    if(!$is_simulator) {
83
+    if (!$is_simulator) {
84 84
       // TODO - randomize attack if is not simulator
85 85
       $this->randomized_attack = floor($this->bonus_attack * ($is_simulator ? 1 : mt_rand(UBE_RANDOMIZE_FROM, UBE_RANDOMIZE_TO) / 100));
86 86
       $this->randomized_shield = floor($this->bonus_shield * ($is_simulator ? 1 : mt_rand(UBE_RANDOMIZE_FROM, UBE_RANDOMIZE_TO) / 100));
@@ -159,22 +159,22 @@  discard block
 block discarded – undo
159 159
    * @version 2016-02-25 23:42:45 41a4.68
160 160
    */
161 161
   public function restore_unit($is_simulator) {
162
-    if($this->_type != UNIT_DEFENCE || $this->units_lost <= 0) {
162
+    if ($this->_type != UNIT_DEFENCE || $this->units_lost <= 0) {
163 163
       return;
164 164
     }
165 165
 
166
-    if($is_simulator) {
166
+    if ($is_simulator) {
167 167
       $units_giveback = round($this->units_lost * UBE_DEFENCE_RESTORATION_CHANCE_AVG / 100); // for simulation just return 75% of loss
168 168
     } else {
169 169
       // Checking - should we trigger mass-restore
170
-      if($this->units_lost >= UBE_DEFENCE_RESTORATION_MASS_COUNT) {
170
+      if ($this->units_lost >= UBE_DEFENCE_RESTORATION_MASS_COUNT) {
171 171
         // For large amount - mass-restoring defence
172 172
         $units_giveback = round($this->units_lost * mt_rand(UBE_DEFENCE_RESTORATION_CHANCE_MIN, UBE_DEFENCE_RESTORATION_CHANCE_MAX) / 100);
173 173
       } else {
174 174
         // For small amount - restoring defence per single unit
175 175
         $units_giveback = 0;
176
-        for($i = 1; $i <= $this->units_lost; $i++) {
177
-          if(mt_rand(1, 100) <= UBE_DEFENCE_RESTORATION_CHANCE_AVG) {
176
+        for ($i = 1; $i <= $this->units_lost; $i++) {
177
+          if (mt_rand(1, 100) <= UBE_DEFENCE_RESTORATION_CHANCE_AVG) {
178 178
             $units_giveback++;
179 179
           }
180 180
         }
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
    */
194 194
   public function receive_damage($is_simulator) {
195 195
     // TODO - Добавить взрывы от полуповрежденных юнитов - т.е. заранее вычислить из убитых юнитов еще количество убитых умножить на вероятность от структуры
196
-    if($this->_count <= 0) {
196
+    if ($this->_count <= 0) {
197 197
       return;
198 198
     }
199 199
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
     $this->adjustCount(-$units_lost);
217 217
 
218 218
     // Проверяем - не взорвался ли текущий юнит
219
-    while($this->_count > 0 && $this->attack_income > 0) {
219
+    while ($this->_count > 0 && $this->attack_income > 0) {
220 220
       $this->attack_damaged_unit($is_simulator);
221 221
     }
222 222
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
     $armor_left = $this->pool_armor % $this->randomized_armor;
242 242
     // Проверка - не атакуем ли мы целый корабль
243 243
     // Такое может быть, если на прошлой итерации поврежденный корабль был взорван и еще осталась входящяя атака
244
-    if($shield_left == 0 && $armor_left == 0) {
244
+    if ($shield_left == 0 && $armor_left == 0) {
245 245
       $shield_left = $this->randomized_shield;
246 246
       $armor_left = $this->randomized_armor;
247 247
     }
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
     // Вычитаем этот дамадж из щитов пула
256 256
     $this->pool_shield -= $damage_to_shield;
257 257
     // Если весь дамадж был поглощён щитами - выходим
258
-    if($this->attack_income <= 0) {
258
+    if ($this->attack_income <= 0) {
259 259
       return;
260 260
     }
261 261
 
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
     $armor_left -= $damage_to_armor;
273 273
 
274 274
     // Проверяем - осталась ли броня на текущем корабле и вааще
275
-    if($this->pool_armor <= 0 || $armor_left <= 0) {
275
+    if ($this->pool_armor <= 0 || $armor_left <= 0) {
276 276
       // Не осталось - корабль уничтожен
277 277
       $this->adjustCount(-1);
278 278
 
@@ -283,10 +283,10 @@  discard block
 block discarded – undo
283 283
     $armor_left_percent = $armor_left / $this->randomized_armor * 100;
284 284
     // Проверяем % здоровья
285 285
     // TODO - сделать динамический процент для каждого вида юнитов
286
-    if($armor_left_percent <= UBE_CRITICAL_DAMAGE_THRESHOLD) {
286
+    if ($armor_left_percent <= UBE_CRITICAL_DAMAGE_THRESHOLD) {
287 287
       // Дамадж пошёл по структуре. Чем более поврежден юнит - тем больше шансов у него взорваться
288 288
       $random = $is_simulator ? UBE_CRITICAL_DAMAGE_THRESHOLD / 2 : mt_rand(0, 100);
289
-      if($random >= $armor_left_percent) {
289
+      if ($random >= $armor_left_percent) {
290 290
         $this->adjustCount(-1);
291 291
         $this->unit_count_boom++;
292 292
 
Please login to merge, or discard this patch.
includes/classes/UBE/UBEPlayerList.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
       UBE_PLAYER_IS_DEFENDER => array(),
56 56
     );
57 57
 
58
-    foreach($this->_container as $player_id => $UBEPlayer) {
58
+    foreach ($this->_container as $player_id => $UBEPlayer) {
59 59
       $result[$UBEPlayer->getSide() ? UBE_PLAYER_IS_ATTACKER : UBE_PLAYER_IS_DEFENDER][$player_id] = $UBEPlayer->getDbRow();
60 60
     }
61 61
 
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
    */
71 71
   public function get_first_player_on_side($side) {
72 72
     $result = null;
73
-    foreach($this->_container as $player_id => $UBEPlayer) {
74
-      if($UBEPlayer->getSide() == $side) {
73
+    foreach ($this->_container as $player_id => $UBEPlayer) {
74
+      if ($UBEPlayer->getSide() == $side) {
75 75
         $result = $UBEPlayer;
76 76
         break;
77 77
       }
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
    */
89 89
   public function get_player_sides() {
90 90
     $result = array();
91
-    foreach($this->_container as $player_id => $UBEPlayer) {
91
+    foreach ($this->_container as $player_id => $UBEPlayer) {
92 92
       $result[$player_id] = $UBEPlayer->getSide() ? UBE_PLAYER_IS_ATTACKER : UBE_PLAYER_IS_DEFENDER;
93 93
     }
94 94
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
   }
97 97
 
98 98
   public function ubeLoadPlayersAndSetSideFromFleetIdList(array $added_fleets, UBEFleetList $fleetList, $side = UBE_PLAYER_IS_DEFENDER) {
99
-    foreach($added_fleets as $fleet_id) {
99
+    foreach ($added_fleets as $fleet_id) {
100 100
       $this->db_load_player_by_id($fleetList[$fleet_id]->owner_id, $side);
101 101
     }
102 102
   }
Please login to merge, or discard this patch.
includes/classes/UBE/UBEFleetList.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -82,13 +82,13 @@  discard block
 block discarded – undo
82 82
    */
83 83
   public function ube_db_load_fleets_outcome($report_row) {
84 84
     $query = doquery("SELECT * FROM {{ube_report_outcome_fleet}} WHERE `ube_report_id` = {$report_row['ube_report_id']}");
85
-    while($row = db_fetch($query)) {
85
+    while ($row = db_fetch($query)) {
86 86
       $fleet_id = $row['ube_report_outcome_fleet_fleet_id'];
87 87
       $this[$fleet_id]->load_outcome_from_report_row($row);
88 88
     }
89 89
 
90 90
     $query = doquery("SELECT * FROM {{ube_report_outcome_unit}} WHERE `ube_report_id` = {$report_row['ube_report_id']} ORDER BY `ube_report_outcome_unit_sort_order`");
91
-    while($row = db_fetch($query)) {
91
+    while ($row = db_fetch($query)) {
92 92
       $fleet_id = $row['ube_report_outcome_unit_fleet_id'];
93 93
       $this[$fleet_id]->load_unit_outcome_from_row($row);
94 94
     }
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
       UBE_PLAYER_IS_DEFENDER => array(),
109 109
     );
110 110
 
111
-    foreach($this->_container as $fleet_id => $UBEFleet) {
111
+    foreach ($this->_container as $fleet_id => $UBEFleet) {
112 112
       $result[$UBEFleet->is_attacker][] = array(
113 113
         'ID'          => $fleet_id,
114 114
         'NAME'        => $ube->players[$UBEFleet->owner_id]->name,
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
    */
132 132
   public function ube_analyze_fleets($is_simulator, UBEDebris $debris, array $resource_exchange_rates) {
133 133
     // Генерируем результат боя
134
-    foreach($this->_container as $fleet_id => $UBEFleet) {
134
+    foreach ($this->_container as $fleet_id => $UBEFleet) {
135 135
       // Инициализируем массив результатов для флота
136 136
 //      $this->init_fleet_outcome_and_link_to_side($UBEFleet);
137 137
 
138
-      foreach($UBEFleet->unit_list->_container as $UBEUnit) {
138
+      foreach ($UBEFleet->unit_list->_container as $UBEUnit) {
139 139
         $UBEUnit->ube_analyze_unit($is_simulator);
140 140
       }
141 141
 
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
       $this->resources_lost_in_metal = array(
153 153
         RES_METAL => 0,
154 154
       );
155
-      foreach($UBEFleet->resources_lost_on_units as $resource_id => $resource_amount) {
155
+      foreach ($UBEFleet->resources_lost_on_units as $resource_id => $resource_amount) {
156 156
         $UBEFleet->resources_lost_in_metal[RES_METAL] += $resource_amount * $resource_exchange_rates[$resource_id];
157 157
       }
158
-      foreach($UBEFleet->cargo_dropped as $resource_id => $resource_amount) {
158
+      foreach ($UBEFleet->cargo_dropped as $resource_id => $resource_amount) {
159 159
         $UBEFleet->resources_lost_in_metal[RES_METAL] += $resource_amount * $resource_exchange_rates[$resource_id];
160 160
       }
161 161
     }
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
    */
167 167
   public function ube_get_groups() {
168 168
     $result = array();
169
-    foreach($this->_container as $UBEFleet) {
170
-      if($UBEFleet->group_id) {
169
+    foreach ($this->_container as $UBEFleet) {
170
+      if ($UBEFleet->group_id) {
171 171
         $result[$UBEFleet->group_id] = $UBEFleet->group_id;
172 172
       }
173 173
     }
@@ -180,8 +180,8 @@  discard block
 block discarded – undo
180 180
    */
181 181
   public function ube_get_capacity_attackers() {
182 182
     $result = 0;
183
-    foreach($this->_container as $UBEFleet) {
184
-      if($UBEFleet->is_attacker) {
183
+    foreach ($this->_container as $UBEFleet) {
184
+      if ($UBEFleet->is_attacker) {
185 185
         $result += $UBEFleet->fleet_capacity;
186 186
       }
187 187
     }
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
    */
196 196
   public function ube_db_load_from_report_row(array $report_row, UBE $ube) {
197 197
     $query = doquery("SELECT * FROM {{ube_report_fleet}} WHERE `ube_report_id` = {$report_row['ube_report_id']}");
198
-    while($fleet_row = db_fetch($query)) {
198
+    while ($fleet_row = db_fetch($query)) {
199 199
       $objFleet = new UBEFleet();
200 200
       $objFleet->load_from_report($fleet_row, $ube);
201 201
       $this[$objFleet->db_id] = $objFleet;
@@ -209,20 +209,20 @@  discard block
 block discarded – undo
209 209
    * @version 2016-02-25 23:42:45 41a4.68
210 210
    */
211 211
   public function ube_prepare_for_next_round($is_simulator) {
212
-    foreach($this->_container as $fleet_id => $UBEFleet) {
212
+    foreach ($this->_container as $fleet_id => $UBEFleet) {
213 213
       $UBEFleet->prepare_for_next_round($is_simulator);
214 214
     }
215 215
 
216 216
     // Суммируем данные по атакующим и защитникам
217 217
     $this->ube_total[UBE_PLAYER_IS_ATTACKER]->_reset();
218 218
     $this->ube_total[UBE_PLAYER_IS_DEFENDER]->_reset();
219
-    foreach($this->_container as $fleet_id => $UBEFleet) {
219
+    foreach ($this->_container as $fleet_id => $UBEFleet) {
220 220
       $this->ube_total[$UBEFleet->is_attacker]->add_unit_stats_array($UBEFleet->total_stats);
221 221
     }
222 222
 //pvar_dump($this->ube_total);
223 223
 
224 224
     // Высчитываем долю атаки, приходящейся на юнит равную отношению брони юнита к общей броне - крупные цели атакуют чаще
225
-    foreach($this->_container as $fleet_id => $UBEFleet) {
225
+    foreach ($this->_container as $fleet_id => $UBEFleet) {
226 226
       $UBEFleet->calculate_unit_partial_data($this->ube_total[$UBEFleet->is_attacker]);
227 227
     }
228 228
   }
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
    */
237 237
   public function ube_calculate_attack_results(UBE $ube) {
238 238
     // Каждый флот атакует все
239
-    foreach($this->_container as $attack_fleet_data) {
239
+    foreach ($this->_container as $attack_fleet_data) {
240 240
       defined('DEBUG_UBE') ? print("Fleet {$attack_fleet_data->db_id} attacks<br /><div style='margin-left: 30px;'>") : false;
241 241
 
242 242
       $attack_fleet_data->attack_fleets($this, $ube->is_simulator);
@@ -251,8 +251,8 @@  discard block
 block discarded – undo
251 251
    * @version 2016-02-25 23:42:45 41a4.68
252 252
    */
253 253
   public function ube_actualize_sides() {
254
-    foreach($this->_container as $UBEFleet) {
255
-      if($UBEFleet->get_unit_count() > 0) {
254
+    foreach ($this->_container as $UBEFleet) {
255
+      if ($UBEFleet->get_unit_count() > 0) {
256 256
         $this->ube_side_present_at_round_start[$UBEFleet->is_attacker] = 1;
257 257
       }
258 258
     }
@@ -265,8 +265,8 @@  discard block
 block discarded – undo
265 265
    */
266 266
   public function ube_calculate_attack_reapers() {
267 267
     $reapers = 0;
268
-    foreach($this->_container as $fleet_id => $UBERoundFleetCombat) {
269
-      if($UBERoundFleetCombat->is_attacker == UBE_PLAYER_IS_ATTACKER) {
268
+    foreach ($this->_container as $fleet_id => $UBERoundFleetCombat) {
269
+      if ($UBERoundFleetCombat->is_attacker == UBE_PLAYER_IS_ATTACKER) {
270 270
         $reapers += $UBERoundFleetCombat->unit_list->unitCountReapers();
271 271
       }
272 272
     }
@@ -283,10 +283,10 @@  discard block
 block discarded – undo
283 283
 
284 284
     $result = UBE_COMBAT_RESULT_DRAW;
285 285
     // Проверяем результат боя
286
-    if($this->ube_get_sides_count() == 0 || $round >= 10) {
286
+    if ($this->ube_get_sides_count() == 0 || $round >= 10) {
287 287
       // Если кого-то не осталось или не осталось обоих - заканчиваем цикл
288 288
       $result = UBE_COMBAT_RESULT_DRAW_END;
289
-    } elseif($this->ube_get_sides_count() == 1) {
289
+    } elseif ($this->ube_get_sides_count() == 1) {
290 290
       // Если осталась одна сторона - она и выиграла
291 291
       $result = isset($this->ube_side_present_at_round_start[UBE_PLAYER_IS_ATTACKER]) ? UBE_COMBAT_RESULT_WIN : UBE_COMBAT_RESULT_LOSS;
292 292
     }
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
    * @version 41a6.16
304 304
    */
305 305
   public function ubeInitGetAttackers(Fleet $objFleet, UBEPlayerList $players) {
306
-    if($objFleet->group_id) {
306
+    if ($objFleet->group_id) {
307 307
       $fleets_added = $this->dbLoadWhere("`fleet_group` = {$objFleet->group_id}");
308 308
     } else {
309 309
       $this->ube_insert_from_Fleet($objFleet);
Please login to merge, or discard this patch.
includes/classes/UBE/UBEMoonCalculator.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 
71 71
     $debris_for_moon = $debris->debris_total();
72 72
 
73
-    if(!$debris_for_moon) {
73
+    if (!$debris_for_moon) {
74 74
       return;
75 75
     }
76 76
 
@@ -78,12 +78,12 @@  discard block
 block discarded – undo
78 78
     $moon_chance = min($debris_for_moon / UBE_MOON_DEBRIS_PER_PERCENT, UBE_MOON_PERCENT_MAX); // TODO Configure
79 79
     $moon_chance = $moon_chance >= UBE_MOON_PERCENT_MIN ? $moon_chance : 0;
80 80
     $this->create_chance = $moon_chance;
81
-    if($moon_chance) {
82
-      if($is_simulator || mt_rand(1, 100) <= $moon_chance) {
81
+    if ($moon_chance) {
82
+      if ($is_simulator || mt_rand(1, 100) <= $moon_chance) {
83 83
         $this->status = UBE_MOON_CREATE_SUCCESS;
84 84
         $this->moon_diameter = round($is_simulator ? $moon_chance * 150 + 1999 : mt_rand($moon_chance * 100 + 1000, $moon_chance * 200 + 2999));
85 85
 
86
-        if($debris_for_moon <= UBE_MOON_DEBRIS_MAX_SPENT) {
86
+        if ($debris_for_moon <= UBE_MOON_DEBRIS_MAX_SPENT) {
87 87
           $debris->_reset();
88 88
         } else {
89 89
           $moon_debris_left_percent = ($debris_for_moon - UBE_MOON_DEBRIS_MAX_SPENT) / $debris_for_moon;
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
    */
103 103
   protected function moon_destroy_try($reapers) {
104 104
     // TODO: $is_simulator
105
-    if($reapers <= 0) {
105
+    if ($reapers <= 0) {
106 106
       return;
107 107
     }
108 108
 
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
    * @version 2016-02-25 23:42:45 41a4.68
121 121
    */
122 122
   public function calculate_moon(UBE $ube) {
123
-    if(UBE_MOON_EXISTS == $this->status) {
124
-      if($ube->mission_type_id == MT_DESTROY && $ube->combat_result == UBE_COMBAT_RESULT_WIN) {
123
+    if (UBE_MOON_EXISTS == $this->status) {
124
+      if ($ube->mission_type_id == MT_DESTROY && $ube->combat_result == UBE_COMBAT_RESULT_WIN) {
125 125
         $reapers = $ube->fleet_list->ube_calculate_attack_reapers();
126 126
         $this->moon_destroy_try($reapers);
127 127
       }
@@ -131,12 +131,12 @@  discard block
 block discarded – undo
131 131
   }
132 132
 
133 133
   public function report_generate_sql() {
134
-    return "`ube_report_moon` = " . (int)$this->status . ",
135
-      `ube_report_moon_chance` = " . (int)$this->create_chance . ",
136
-      `ube_report_moon_size` = " . (float)$this->moon_diameter . ",
137
-      `ube_report_moon_reapers` = " . (int)$this->reapers_status . ",
138
-      `ube_report_moon_destroy_chance` = " . (int)$this->destroy_chance . ",
139
-      `ube_report_moon_reapers_die_chance` = " . (int)$this->reaper_die_chance;
134
+    return "`ube_report_moon` = " . (int) $this->status . ",
135
+      `ube_report_moon_chance` = " . (int) $this->create_chance . ",
136
+      `ube_report_moon_size` = " . (float) $this->moon_diameter . ",
137
+      `ube_report_moon_reapers` = " . (int) $this->reapers_status . ",
138
+      `ube_report_moon_destroy_chance` = " . (int) $this->destroy_chance . ",
139
+      `ube_report_moon_reapers_die_chance` = " . (int) $this->reaper_die_chance;
140 140
   }
141 141
 
142 142
   public function report_render_moon() {
@@ -166,11 +166,11 @@  discard block
 block discarded – undo
166 166
    * @param $planet_id
167 167
    */
168 168
   public function db_apply_result($planet_info, $destination_user_id) {
169
-    if($this->status == UBE_MOON_CREATE_SUCCESS) {
169
+    if ($this->status == UBE_MOON_CREATE_SUCCESS) {
170 170
       $moon_row = uni_create_moon($planet_info[PLANET_GALAXY], $planet_info[PLANET_SYSTEM], $planet_info[PLANET_PLANET], $destination_user_id, $this->moon_diameter, '', false);
171 171
       $this->moon_name = $moon_row['name'];
172 172
       unset($moon_row);
173
-    } elseif($this->status == UBE_MOON_DESTROY_SUCCESS) {
173
+    } elseif ($this->status == UBE_MOON_DESTROY_SUCCESS) {
174 174
       db_planet_delete_by_id($planet_info[PLANET_ID]);
175 175
     }
176 176
   }
@@ -179,14 +179,14 @@  discard block
 block discarded – undo
179 179
     global $lang;
180 180
 
181 181
     $text_defender = '';
182
-    if($this->status == UBE_MOON_CREATE_SUCCESS) {
182
+    if ($this->status == UBE_MOON_CREATE_SUCCESS) {
183 183
       $text_defender .= "{$lang['ube_report_moon_created']} {$this->moon_diameter} {$lang['sys_kilometers_short']}<br /><br />";
184
-    } elseif($this->status == UBE_MOON_CREATE_FAILED) {
184
+    } elseif ($this->status == UBE_MOON_CREATE_FAILED) {
185 185
       $text_defender .= "{$lang['ube_report_moon_chance']} {$this->create_chance}%<br /><br />";
186 186
     }
187 187
 
188
-    if($ube->mission_type_id == MT_DESTROY) {
189
-      if($this->reapers_status == UBE_MOON_REAPERS_NONE) {
188
+    if ($ube->mission_type_id == MT_DESTROY) {
189
+      if ($this->reapers_status == UBE_MOON_REAPERS_NONE) {
190 190
         $text_defender .= $lang['ube_report_moon_reapers_none'];
191 191
       } else {
192 192
         $text_defender .= "{$lang['ube_report_moon_reapers_wave']}. {$lang['ube_report_moon_reapers_chance']} {$this->destroy_chance}%. ";
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
    * @version 2016-02-25 23:42:45 41a4.68
216 216
    */
217 217
   public function ubeInitLoadStatis($destination_planet) {
218
-    if($destination_planet['planet_type'] == PT_MOON || is_array($moon = db_planet_by_parent($destination_planet['id'], true, '`id`'))) {
218
+    if ($destination_planet['planet_type'] == PT_MOON || is_array($moon = db_planet_by_parent($destination_planet['id'], true, '`id`'))) {
219 219
       $this->status = UBE_MOON_EXISTS;
220 220
       $this->moon_diameter = !empty($moon['planet_type']) && $moon['planet_type'] == PT_MOON ? $moon['diameter'] : $destination_planet['diameter'];
221 221
       $this->reapers_status = UBE_MOON_REAPERS_NONE;
Please login to merge, or discard this patch.