Completed
Push — work-fleets ( abbbcf...8b8b7f )
by SuperNova.WS
05:13
created
includes/classes/UBE/UBE.php 1 patch
Spacing   +44 added lines, -45 removed lines patch added patch discarded remove patch
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
     $this->players->db_load_player_by_id($player_id, UBE_PLAYER_IS_DEFENDER);
148 148
 
149 149
     $player_db_row = $this->players[$player_id]->getDbRow();
150
-    if($fortifier_level = mrc_get_level($player_db_row, $this->combatMission->dst_planet, MRC_FORTIFIER)) {
150
+    if ($fortifier_level = mrc_get_level($player_db_row, $this->combatMission->dst_planet, MRC_FORTIFIER)) {
151 151
       $this->planet_bonus->add_unit_by_snid(MRC_FORTIFIER, $fortifier_level);
152 152
     }
153 153
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
     $this->rounds[0] = new UBERound(0);
180 180
     $this->rounds[0]->make_snapshot($this->fleet_list);
181 181
 
182
-    for($round = 1; $round <= 10; $round++) {
182
+    for ($round = 1; $round <= 10; $round++) {
183 183
       // Проводим раунд
184 184
       defined('DEBUG_UBE') ? print("Round {$round}<br>") : false;
185 185
 
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 
193 193
       // Анализируем итоги текущего раунда и готовим данные для следующего
194 194
       $this->combat_result = $this->fleet_list->ubeAnalyzeFleetOutcome($round);
195
-      if($this->combat_result != UBE_COMBAT_RESULT_DRAW) {
195
+      if ($this->combat_result != UBE_COMBAT_RESULT_DRAW) {
196 196
         break;
197 197
       }
198 198
 
@@ -221,11 +221,11 @@  discard block
 block discarded – undo
221 221
     // Генерируем результат боя
222 222
     $this->fleet_list->ube_analyze_fleets($this->is_simulator, $this->debris, $this->resource_exchange_rates);
223 223
 
224
-    if(!$this->is_ube_loaded) {
224
+    if (!$this->is_ube_loaded) {
225 225
       $this->moon_calculator->calculate_moon($this);
226 226
 
227 227
       // Лутаем ресурсы - если аттакер выиграл
228
-      if($this->combat_result == UBE_COMBAT_RESULT_WIN) {
228
+      if ($this->combat_result == UBE_COMBAT_RESULT_WIN) {
229 229
         $this->sn_ube_combat_analyze_loot();
230 230
       }
231 231
     }
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
       RES_DEUTERIUM => 0,
246 246
     );
247 247
 
248
-    if(
248
+    if (
249 249
       (($planet_resource_total = $this->fleet_list[0]->get_resources_amount()) > 0)
250 250
       &&
251 251
       (($total_capacity = $this->fleet_list->ube_get_capacity_attackers()) > 0)
@@ -257,9 +257,9 @@  discard block
 block discarded – undo
257 257
       $planet_lootable_percent = $planet_lootable / $planet_resource_total;
258 258
 
259 259
       // Вычисляем сколько ресурсов вывезено
260
-      foreach($this->fleet_list->_container as $fleet_id => $fleet) {
260
+      foreach ($this->fleet_list->_container as $fleet_id => $fleet) {
261 261
         $looted_in_metal = 0;
262
-        foreach($this->fleet_list[0]->resource_list as $resource_id => $resource_amount) {
262
+        foreach ($this->fleet_list[0]->resource_list as $resource_id => $resource_amount) {
263 263
           // Вычисляем какой процент общей емкости трюмов атакующих будет задействован
264 264
           $fleet_lootable_percent = $fleet->fleet_capacity / $total_capacity;
265 265
           $looted = floor($resource_amount * $planet_lootable_percent * $fleet_lootable_percent);
@@ -325,16 +325,16 @@  discard block
 block discarded – undo
325 325
     $destination_user_id = $this->fleet_list[0]->owner_id;
326 326
 
327 327
     // Обновляем поле обломков на планете
328
-    if(!$this->is_admin_in_combat && $this->debris->debris_total() > 0) {
328
+    if (!$this->is_admin_in_combat && $this->debris->debris_total() > 0) {
329 329
       db_planet_set_by_gspt($this->ube_planet_info[PLANET_GALAXY], $this->ube_planet_info[PLANET_SYSTEM], $this->ube_planet_info[PLANET_PLANET], PT_PLANET,
330 330
         "`debris_metal` = `debris_metal` + " . $this->debris->debris_get_resource(RES_METAL) . ", `debris_crystal` = `debris_crystal` + " . $this->debris->debris_get_resource(RES_CRYSTAL)
331 331
       );
332 332
     }
333 333
 
334
-    foreach($this->fleet_list->_container as $fleet_id => $UBEFleet) {
334
+    foreach ($this->fleet_list->_container as $fleet_id => $UBEFleet) {
335 335
       $ship_count_lost = $UBEFleet->unit_list->unitCountLost();
336 336
 
337
-      if($fleet_id) {
337
+      if ($fleet_id) {
338 338
         // Флот
339 339
         $UBEFleet->db_save_combat_result_fleet($this->is_small_fleet_recce, $this->moon_calculator->get_reapers_status());
340 340
       } else {
@@ -342,19 +342,19 @@  discard block
 block discarded – undo
342 342
 
343 343
         // Сохраняем изменения ресурсов - если они есть
344 344
         $resource_delta = $UBEFleet->ube_combat_result_calculate_resources();
345
-        if(!empty($resource_delta)) {
345
+        if (!empty($resource_delta)) {
346 346
           $temp = array();
347
-          foreach($resource_delta as $resource_id => $resource_amount) {
347
+          foreach ($resource_delta as $resource_id => $resource_amount) {
348 348
             $resource_db_name = pname_resource_name($resource_id);
349 349
             $temp[] = "`{$resource_db_name}` = `{$resource_db_name}` + ({$resource_amount})";
350 350
           }
351 351
           db_planet_set_by_id($this->ube_planet_info[PLANET_ID], implode(',', $temp));
352 352
         }
353 353
 
354
-        if($ship_count_lost) {
354
+        if ($ship_count_lost) {
355 355
           $db_changeset = array();
356 356
           $planet_row_cache = $this->players[$destination_user_id]->getDbRow();
357
-          foreach($UBEFleet->unit_list->_container as $UBEUnit) {
357
+          foreach ($UBEFleet->unit_list->_container as $UBEUnit) {
358 358
             $db_changeset['unit'][] = sn_db_unit_changeset_prepare($UBEUnit->unitId, -$UBEUnit->units_lost, $planet_row_cache, $this->ube_planet_info[PLANET_ID]);
359 359
           }
360 360
           db_changeset_apply($db_changeset);
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
     // TODO: Связать сабы с флотами констраинтами ON DELETE SET NULL
366 366
     // Для САБов
367 367
     $fleet_group_id_list = $this->fleet_list->ube_get_groups();
368
-    if(!empty($fleet_group_id_list)) {
368
+    if (!empty($fleet_group_id_list)) {
369 369
       $fleet_group_id_list = implode(',', $fleet_group_id_list);
370 370
       db_acs_delete_by_list($fleet_group_id_list);
371 371
     }
@@ -374,19 +374,19 @@  discard block
 block discarded – undo
374 374
 
375 375
     $bashing_list = array();
376 376
     $players_sides = $this->players->get_player_sides();
377
-    foreach($players_sides as $player_id => $player_side) {
378
-      if($player_side != UBE_PLAYER_IS_ATTACKER) {
377
+    foreach ($players_sides as $player_id => $player_side) {
378
+      if ($player_side != UBE_PLAYER_IS_ATTACKER) {
379 379
         continue;
380 380
       }
381
-      if($this->moon_calculator->get_status() != UBE_MOON_DESTROY_SUCCESS) {
381
+      if ($this->moon_calculator->get_status() != UBE_MOON_DESTROY_SUCCESS) {
382 382
         $bashing_list[] = "({$player_id}, {$this->ube_planet_info[PLANET_ID]}, {$this->combat_timestamp})";
383 383
       }
384
-      if($this->mission_type_id == MT_ATTACK && $this->is_defender_active_player) {
384
+      if ($this->mission_type_id == MT_ATTACK && $this->is_defender_active_player) {
385 385
         $str_loose_or_win = $this->combat_result == UBE_COMBAT_RESULT_WIN ? 'raidswin' : 'raidsloose';
386 386
         db_user_set_by_id($player_id, "`xpraid` = `xpraid` + 1, `raids` = `raids` + 1, `{$str_loose_or_win}` = `{$str_loose_or_win}` + 1");
387 387
       }
388 388
     }
389
-    if(!empty($bashing_list)) {
389
+    if (!empty($bashing_list)) {
390 390
       $bashing_list = implode(',', $bashing_list);
391 391
       db_bashing_insert($bashing_list);
392 392
     }
@@ -413,20 +413,19 @@  discard block
 block discarded – undo
413 413
       $planet_info[PLANET_SYSTEM],
414 414
       $planet_info[PLANET_PLANET],
415 415
       htmlentities($planet_info[PLANET_NAME], ENT_COMPAT, 'UTF-8'),
416
-      $lang[$this->combat_result == UBE_COMBAT_RESULT_WIN ? 'ube_report_info_outcome_win' :
417
-        ($this->combat_result == UBE_COMBAT_RESULT_DRAW ? 'ube_report_info_outcome_draw' : 'ube_report_info_outcome_loss')]
416
+      $lang[$this->combat_result == UBE_COMBAT_RESULT_WIN ? 'ube_report_info_outcome_win' : ($this->combat_result == UBE_COMBAT_RESULT_DRAW ? 'ube_report_info_outcome_draw' : 'ube_report_info_outcome_loss')]
418 417
     );
419 418
 
420 419
     $text_defender = '';
421 420
     $debris = $this->debris->get_debris();
422
-    foreach($debris as $resource_id => $resource_amount) {
423
-      if($resource_id == RES_DEUTERIUM) {
421
+    foreach ($debris as $resource_id => $resource_amount) {
422
+      if ($resource_id == RES_DEUTERIUM) {
424 423
         continue;
425 424
       }
426 425
 
427 426
       $text_defender .= "{$lang['tech'][$resource_id]}: " . pretty_number($resource_amount) . '<br />';
428 427
     }
429
-    if($text_defender) {
428
+    if ($text_defender) {
430 429
       $text_defender = "{$lang['ube_report_msg_body_debris']}{$text_defender}<br />";
431 430
     }
432 431
 
@@ -436,7 +435,7 @@  discard block
 block discarded – undo
436 435
 
437 436
     // TODO: Оптимизировать отсылку сообщений - отсылать пакетами
438 437
     $player_sides = $this->players->get_player_sides();
439
-    foreach($player_sides as $player_id => $player_side) {
438
+    foreach ($player_sides as $player_id => $player_side) {
440 439
       $message = $text_common . ($this->is_small_fleet_recce && ($player_side == UBE_PLAYER_IS_ATTACKER) ? $lang['ube_report_msg_body_sfr'] : $text_defender);
441 440
       msg_send_simple_message($player_id, '', $this->combat_timestamp, MSG_TYPE_COMBAT, $lang['sys_mess_tower'], $lang['sys_mess_attack_report'], $message);
442 441
     }
@@ -473,11 +472,11 @@  discard block
 block discarded – undo
473 472
     $player_id = $player_id == -1 ? $this->players->count() : $player_id;
474 473
     $fleet_id = $player_id; // FOR SIMULATOR!
475 474
 
476
-    if(empty($this->players[$player_id])) {
475
+    if (empty($this->players[$player_id])) {
477 476
       $this->players[$player_id] = new UBEPlayer();
478 477
     }
479 478
 
480
-    foreach($side_info as $fleet_data) {
479
+    foreach ($side_info as $fleet_data) {
481 480
       $this->players[$player_id]->name = $player_id;
482 481
       $this->players[$player_id]->setSide($attacker);
483 482
 
@@ -485,32 +484,32 @@  discard block
 block discarded – undo
485 484
       $this->fleet_list[$fleet_id] = $objFleet;
486 485
 
487 486
       $this->fleet_list[$fleet_id]->owner_id = $player_id;
488
-      foreach($fleet_data as $unit_id => $unit_count) {
489
-        if(!$unit_count) {
487
+      foreach ($fleet_data as $unit_id => $unit_count) {
488
+        if (!$unit_count) {
490 489
           continue;
491 490
         }
492 491
 
493 492
         $unit_type = get_unit_param($unit_id, P_UNIT_TYPE);
494 493
 
495
-        if($unit_type == UNIT_SHIPS || $unit_type == UNIT_DEFENCE) {
494
+        if ($unit_type == UNIT_SHIPS || $unit_type == UNIT_DEFENCE) {
496 495
           $this->fleet_list[$fleet_id]->unit_list->unitAdjustCount($unit_id, $unit_count);
497
-        } elseif($unit_type == UNIT_RESOURCES) {
496
+        } elseif ($unit_type == UNIT_RESOURCES) {
498 497
           $this->fleet_list[$fleet_id]->resource_list[$unit_id] = $unit_count;
499
-        } elseif($unit_type == UNIT_TECHNOLOGIES) {
500
-          if($unit_id == TECH_WEAPON) {
498
+        } elseif ($unit_type == UNIT_TECHNOLOGIES) {
499
+          if ($unit_id == TECH_WEAPON) {
501 500
             $this->players[$player_id]->player_bonus->add_unit_by_snid(TECH_WEAPON, $unit_count);
502
-          } elseif($unit_id == TECH_SHIELD) {
501
+          } elseif ($unit_id == TECH_SHIELD) {
503 502
             $this->players[$player_id]->player_bonus->add_unit_by_snid(TECH_SHIELD, $unit_count);
504
-          } elseif($unit_id == TECH_ARMOR) {
503
+          } elseif ($unit_id == TECH_ARMOR) {
505 504
             $this->players[$player_id]->player_bonus->add_unit_by_snid(TECH_ARMOR, $unit_count);
506 505
           }
507
-        } elseif($unit_type == UNIT_GOVERNORS) {
508
-          if($unit_id == MRC_FORTIFIER) {
506
+        } elseif ($unit_type == UNIT_GOVERNORS) {
507
+          if ($unit_id == MRC_FORTIFIER) {
509 508
             // Фортифаер даёт бонус ко всему
510 509
             $this->planet_bonus->add_unit_by_snid(MRC_FORTIFIER, $unit_count);
511 510
           }
512
-        } elseif($unit_type == UNIT_MERCENARIES) {
513
-          if($unit_id == MRC_ADMIRAL) {
511
+        } elseif ($unit_type == UNIT_MERCENARIES) {
512
+          if ($unit_id == MRC_ADMIRAL) {
514 513
             $this->players[$player_id]->player_bonus->add_unit_by_snid(MRC_ADMIRAL, $unit_count);
515 514
           }
516 515
         }
@@ -581,7 +580,7 @@  discard block
 block discarded – undo
581 580
 
582 581
     $ube_report = new UBEReport();
583 582
     $ube = $ube_report->sn_ube_report_load(sys_get_param_str('cypher'));
584
-    if($ube != UBE_REPORT_NOT_FOUND) {
583
+    if ($ube != UBE_REPORT_NOT_FOUND) {
585 584
       $ube_report->sn_ube_report_generate($ube, $template_result);
586 585
 
587 586
       $template = gettemplate('ube_combat_report', $template);
@@ -614,9 +613,9 @@  discard block
 block discarded – undo
614 613
 //    sn_ube_report_save($combat_data);
615 614
 //  }
616 615
 
617
-    if(sys_get_param_str('reload')) {
616
+    if (sys_get_param_str('reload')) {
618 617
       $ube_new = $ube_report->sn_ube_report_load($ube->get_cypher()); // $combat_data = sn_ube_report_load($combat_data[UBE_REPORT_CYPHER]);
619
-      if($ube_new != UBE_REPORT_NOT_FOUND && is_object($ube_new)) {
618
+      if ($ube_new != UBE_REPORT_NOT_FOUND && is_object($ube_new)) {
620 619
         $ube = $ube_new;
621 620
       }
622 621
     }
@@ -664,7 +663,7 @@  discard block
 block discarded – undo
664 663
     $this->debris->load_from_report_row($report_row);
665 664
 
666 665
     $query = doquery("SELECT * FROM {{ube_report_player}} WHERE `ube_report_id` = {$report_row['ube_report_id']}");
667
-    while($player_row = db_fetch($query)) {
666
+    while ($player_row = db_fetch($query)) {
668 667
       $this->players->init_player_from_report_info($player_row);
669 668
     }
670 669
 
Please login to merge, or discard this patch.
includes/classes/UBE/UBERound.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -36,8 +36,8 @@  discard block
 block discarded – undo
36 36
    * @version 2016-02-25 23:42:45 41a4.68
37 37
    */
38 38
   public function make_snapshot(UBEFleetList $UBEFleetList) {
39
-    foreach($UBEFleetList->_container as $fleet_id => $UBEFleet) {
40
-      foreach($UBEFleet->unit_list->_container as $UBEUnit) {
39
+    foreach ($UBEFleetList->_container as $fleet_id => $UBEFleet) {
40
+      foreach ($UBEFleet->unit_list->_container as $UBEUnit) {
41 41
         $this->snapshot[$fleet_id][$UBEUnit->unitId] = new UBESnapshotUnit();
42 42
         $this->snapshot[$fleet_id][$UBEUnit->unitId]->init_from_UBEUnit($UBEUnit);
43 43
       }
@@ -53,12 +53,12 @@  discard block
 block discarded – undo
53 53
    * @version 2016-02-25 23:42:45 41a4.68
54 54
    */
55 55
   public function sql_generate_unit_array(array &$sql_perform_ube_report_unit, &$unit_sort_order, UBEFleetList $UBEFleetList, array $outer_prefix) {
56
-    foreach($this->snapshot as $fleet_id => $fleet_snapshot) {
56
+    foreach ($this->snapshot as $fleet_id => $fleet_snapshot) {
57 57
       $inner_prefix = array(
58 58
         $UBEFleetList[$fleet_id]->owner_id,
59 59
         $fleet_id,
60 60
       );
61
-      foreach($fleet_snapshot as $unit_id => $unit_snapshot) {
61
+      foreach ($fleet_snapshot as $unit_id => $unit_snapshot) {
62 62
         $sql_perform_ube_report_unit[] = array_merge(
63 63
           $outer_prefix,
64 64
           $inner_prefix,
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
       UBE_PLAYER_IS_DEFENDER => array(),
102 102
     );
103 103
 
104
-    foreach($this->snapshot as $fleet_id => $fleet_snapshot) {
104
+    foreach ($this->snapshot as $fleet_id => $fleet_snapshot) {
105 105
       $fleet_owner_id = $ube->fleet_list[$fleet_id]->owner_id;
106 106
       $planet_ube_row = $ube->fleet_list[$fleet_id]->UBE_PLANET;
107 107
 
@@ -111,13 +111,13 @@  discard block
 block discarded – undo
111 111
         'PLAYER_NAME' => htmlentities($ube->players[$fleet_owner_id]->name, ENT_COMPAT, 'UTF-8'),
112 112
       );
113 113
 
114
-      if(is_array($planet_ube_row)) {
114
+      if (is_array($planet_ube_row)) {
115 115
         $template_fleet += $planet_ube_row;
116 116
         $template_fleet[PLANET_NAME] = $template_fleet[PLANET_NAME] ? htmlentities($template_fleet[PLANET_NAME], ENT_COMPAT, 'UTF-8') : '';
117 117
         $template_fleet['PLANET_TYPE_TEXT'] = $lang['sys_planet_type_sh'][$template_fleet['PLANET_TYPE']];
118 118
       }
119 119
 
120
-      foreach($fleet_snapshot as $unit_id => $unit_snapshot) {
120
+      foreach ($fleet_snapshot as $unit_id => $unit_snapshot) {
121 121
         $template_fleet['.']['ship'][] = $unit_snapshot->report_render_unit($prevSnapshot[$fleet_id][$unit_id]);
122 122
       }
123 123
 
Please login to merge, or discard this patch.
includes/classes/UBE/UBEDebris.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
    */
31 31
   public function debris_add_resource($resource_id, $resource_amount) {
32 32
     // В обломках может быть только металл или кристалл
33
-    if($resource_id != RES_METAL && $resource_id != RES_CRYSTAL) {
33
+    if ($resource_id != RES_METAL && $resource_id != RES_CRYSTAL) {
34 34
       return;
35 35
     }
36 36
     $this->debris[$resource_id] += $resource_amount;
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
    * @param bool  $is_simulator
42 42
    */
43 43
   public function add_wrecks(array $wreckage, $is_simulator) {
44
-    foreach($wreckage as $resource_id => $resource_amount) {
44
+    foreach ($wreckage as $resource_id => $resource_amount) {
45 45
       $this->debris_add_resource($resource_id, floor($resource_amount *
46 46
         ($is_simulator
47 47
           ? UBE_SHIP_WRECKS_TO_DEBRIS_AVG
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
    * @param bool  $is_simulator
58 58
    */
59 59
   public function add_cargo_drop(array $dropped_resources, $is_simulator) {
60
-    foreach($dropped_resources as $resource_id => $resource_amount) {
60
+    foreach ($dropped_resources as $resource_id => $resource_amount) {
61 61
       $this->debris_add_resource($resource_id, floor($resource_amount *
62 62
         ($is_simulator
63 63
           ? UBE_CARGO_DROPPED_TO_DEBRIS_AVG
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
    * @param $moon_debris_left_part
97 97
    */
98 98
   public function debris_adjust_proportional($moon_debris_left_part) {
99
-    foreach($this->debris as $resource_id => &$resource_amount) {
99
+    foreach ($this->debris as $resource_id => &$resource_amount) {
100 100
       $resource_amount = floor($resource_amount * $moon_debris_left_part);
101 101
     }
102 102
   }
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
    */
122 122
   public function report_generate_sql(classConfig $config) {
123 123
     return "
124
-      `ube_report_debris_metal` = " . (float)$this->debris_get_resource(RES_METAL) . ",
125
-      `ube_report_debris_crystal` = " . (float)$this->debris_get_resource(RES_CRYSTAL) . ",
126
-      `ube_report_debris_total_in_metal` = " . (float)$this->debris_in_metal($config) . ", ";
124
+      `ube_report_debris_metal` = " . (float) $this->debris_get_resource(RES_METAL) . ",
125
+      `ube_report_debris_crystal` = " . (float) $this->debris_get_resource(RES_CRYSTAL) . ",
126
+      `ube_report_debris_total_in_metal` = " . (float) $this->debris_in_metal($config) . ", ";
127 127
   }
128 128
 
129 129
   /**
Please login to merge, or discard this patch.
includes/classes/UBE/UBEDebug.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
    * @version 41a6.0
12 12
    */
13 13
   public static function unit_dump_header() {
14
-    if(!defined('DEBUG_UBE')) {
14
+    if (!defined('DEBUG_UBE')) {
15 15
       return;
16 16
     }
17 17
 
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
    * @version 41a6.0
49 49
    */
50 50
   public static function unit_dump(UBEUnit $unit, $desc = '', UBEUnit $before = null) {
51
-    if(!defined('DEBUG_UBE')) {
51
+    if (!defined('DEBUG_UBE')) {
52 52
       return;
53 53
     }
54 54
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
    * @version 41a6.0
87 87
    */
88 88
   public static function unit_dump_footer() {
89
-    if(!defined('DEBUG_UBE')) {
89
+    if (!defined('DEBUG_UBE')) {
90 90
       return;
91 91
     }
92 92
 
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
    * @return UBEUnit
102 102
    */
103 103
   public static function unit_dump_defender(UBEUnit $attacking_unit_pool, UBEUnit $defending_unit_pool, $defending_fleet_id) {
104
-    if(!defined('DEBUG_UBE')) {
104
+    if (!defined('DEBUG_UBE')) {
105 105
       return null;
106 106
     }
107 107
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
    * @version 41a6.0
128 128
    */
129 129
   public static function unit_dump_delta(UBEUnit $unit, $field, UBEUnit $before = null) {
130
-    if(!defined('DEBUG_UBE')) {
130
+    if (!defined('DEBUG_UBE')) {
131 131
       return;
132 132
     }
133 133
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
     print(pretty_number($unit->$field));
137 137
     print("</td>");
138 138
     print("<td>");
139
-    if(!empty($before)) {
139
+    if (!empty($before)) {
140 140
       print('' . pretty_number($unit->$field - $before->$field) . '');
141 141
     }
142 142
     print("</td>");
Please login to merge, or discard this patch.
includes/classes/UBE/ArrayAccessV2.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 
43 43
 
44 44
   public function __clone() {
45
-    if(static::$_clonable == ArrayAccessV2::CLONE_NONE) {
45
+    if (static::$_clonable == ArrayAccessV2::CLONE_NONE) {
46 46
       return;
47 47
     }
48 48
 
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
   }
51 51
 
52 52
   protected static function _deep_clone(&$array) {
53
-    foreach($array as &$value) {
54
-      if(is_object($value)) {
53
+    foreach ($array as &$value) {
54
+      if (is_object($value)) {
55 55
         $value = clone $value;
56
-      } elseif(is_array($value) && static::$_clonable == ArrayAccessV2::CLONE_DEEP) {
56
+      } elseif (is_array($value) && static::$_clonable == ArrayAccessV2::CLONE_DEEP) {
57 57
         static::_deep_clone($value);
58 58
       }
59 59
     }
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
    */
68 68
   public function __call($method_name, array $arguments) {
69 69
     $object_first = reset($this->_container);
70
-    if($object_first !== false && method_exists($object_first, $method_name)) {
71
-      foreach($this->_container as $unit_id => $object) {
70
+    if ($object_first !== false && method_exists($object_first, $method_name)) {
71
+      foreach ($this->_container as $unit_id => $object) {
72 72
         call_user_func_array(array($object, $method_name), $arguments);
73 73
       }
74 74
     }
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
    */
84 84
   public function getSumProperty($property_name) {
85 85
     $result = 0.0;
86
-    foreach($this->_container as $object) {
87
-      if(is_object($object) && property_exists($object, $property_name)) {
86
+    foreach ($this->_container as $object) {
87
+      if (is_object($object) && property_exists($object, $property_name)) {
88 88
         $result += $object->$property_name;
89 89
       }
90 90
     }
@@ -100,8 +100,8 @@  discard block
 block discarded – undo
100 100
    * @return mixed
101 101
    */
102 102
   public function aggregateByMethod($method_name, &$result) {
103
-    foreach($this->_container as $object) {
104
-      if(is_object($object) && method_exists($object, $method_name)) {
103
+    foreach ($this->_container as $object) {
104
+      if (is_object($object) && method_exists($object, $method_name)) {
105 105
         call_user_func(array($object, $method_name), $result);
106 106
       }
107 107
     }
Please login to merge, or discard this patch.
includes/classes/Bonus.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -28,12 +28,12 @@  discard block
 block discarded – undo
28 28
    * @param $unit_level
29 29
    */
30 30
   public function add_unit_by_snid($unit_id, $unit_level) {
31
-    if(!$unit_level) {
31
+    if (!$unit_level) {
32 32
       return;
33 33
     }
34 34
 
35
-    foreach(static::$_bonus_group as $param_name => $unit_list) {
36
-      if(!empty($unit_list[$unit_id])) {
35
+    foreach (static::$_bonus_group as $param_name => $unit_list) {
36
+      if (!empty($unit_list[$unit_id])) {
37 37
         // Простейший вариант - мультипликатор по базе
38 38
         // Общий мультипликатор добавляется в конец
39 39
         $this->grants[$param_name][$unit_id] = $unit_level;
@@ -82,16 +82,16 @@  discard block
 block discarded – undo
82 82
 //    $this->grants[$param_name][$unit_id] = $unit_level * get_unit_param($unit_id, P_BONUS_VALUE) / 100;;
83 83
     $value_add = floatval($base_value);
84 84
     $cumulative = 1.0; // Для случая BONUS_PERCENT
85
-    if(!empty($this->grants[$param]) && is_array($this->grants[$param])) {
86
-      foreach($this->grants[$param] as $unit_id => $unit_level) {
85
+    if (!empty($this->grants[$param]) && is_array($this->grants[$param])) {
86
+      foreach ($this->grants[$param] as $unit_id => $unit_level) {
87 87
         $unit_bonus = 0;
88
-        if($unit_id < 0) {
88
+        if ($unit_id < 0) {
89 89
           // Meta-unit - leave as is
90 90
         } else {
91 91
           // TODO - Подумать, что будет при смешивании разных бонусов и как этого избежать
92 92
           $bonus_value = get_unit_param($unit_id, P_BONUS_VALUE);
93 93
           $bonus_type = get_unit_param($unit_id, P_BONUS_TYPE);
94
-          switch($bonus_type) {
94
+          switch ($bonus_type) {
95 95
             case BONUS_PERCENT:
96 96
               $unit_bonus = $unit_level * $bonus_value / 100;
97 97
               $cumulative += $unit_bonus;
Please login to merge, or discard this patch.
includes/classes/FleetList.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -37,14 +37,14 @@  discard block
 block discarded – undo
37 37
       (!empty($where_safe) ? " WHERE {$where_safe}" : '') .
38 38
       " FOR UPDATE;"
39 39
     );
40
-    while($row = db_fetch($query)) {
40
+    while ($row = db_fetch($query)) {
41 41
       /**
42 42
        * @var Fleet $fleet
43 43
        */
44 44
       $fleet = $this->_createElement();
45 45
       $fleet->dbRowParse($row);
46 46
 
47
-      if(isset($this[$fleet->dbId])) {
47
+      if (isset($this[$fleet->dbId])) {
48 48
         // Нужно ли ????
49 49
         classSupernova::$debug->error('Fleet list already set');
50 50
       }
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
    * @return static
171 171
    */
172 172
   public static function dbGetFleetListAndMissileByCoordinates($coordinates, $for_phalanx = false) {
173
-    if(empty($coordinates) || !is_array($coordinates)) {
173
+    if (empty($coordinates) || !is_array($coordinates)) {
174 174
       return array();
175 175
     }
176 176
 
@@ -199,8 +199,8 @@  discard block
 block discarded – undo
199 199
      * @var Fleet[] $array_of_Fleet
200 200
      */
201 201
     $array_of_Fleet = array();
202
-    if(!empty($fleet_db_list) && $fleet_db_list->count()) {
203
-      foreach($fleet_db_list->_container as $fleet_id => $objFleet) {
202
+    if (!empty($fleet_db_list) && $fleet_db_list->count()) {
203
+      foreach ($fleet_db_list->_container as $fleet_id => $objFleet) {
204 204
         $array_of_Fleet[$fleet_id] = $objFleet;
205 205
       }
206 206
       $planet_fleets = flt_get_fleets_to_planet_by_array_of_Fleet($array_of_Fleet);
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
       "SELECT * FROM `{{iraks}}`" .
250 250
       (!empty($where) ? " WHERE {$where}" : '') .
251 251
       " FOR UPDATE;");
252
-    while($missile_db_row = db_fetch($query)) {
252
+    while ($missile_db_row = db_fetch($query)) {
253 253
       /**
254 254
        * @var Fleet $objFleet
255 255
        */
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
    */
272 272
   public static function dbGetFleetListAndMissileINCOMING($owner_id) {
273 273
     $owner_id_safe = idval($owner_id);
274
-    if(empty($owner_id_safe)) {
274
+    if (empty($owner_id_safe)) {
275 275
       return array();
276 276
     }
277 277
 
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
    */
306 306
   public static function fleet_count_flying($player_id, $mission_id = 0) {
307 307
     $player_id_safe = idval($player_id);
308
-    if(!empty($player_id_safe)) {
308
+    if (!empty($player_id_safe)) {
309 309
       $mission_id_safe = intval($mission_id);
310 310
       $result = static::db_fleet_count(
311 311
         "`fleet_owner` = {$player_id_safe}" .
Please login to merge, or discard this patch.
includes/classes/supernova.php 1 patch
Spacing   +106 added lines, -108 removed lines patch added patch discarded remove patch
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 
192 192
 
193 193
   public static function log_file($message, $spaces = 0) {
194
-    if(self::$debug) {
194
+    if (self::$debug) {
195 195
       self::$debug->log_file($message, $spaces);
196 196
     }
197 197
   }
@@ -202,14 +202,14 @@  discard block
 block discarded – undo
202 202
   // Перепаковывает массив на заданную глубину, убирая поля с null
203 203
   public static function array_repack(&$array, $level = 0) {
204 204
     // TODO $lock_table не нужна тут
205
-    if(!is_array($array)) return;
205
+    if (!is_array($array)) return;
206 206
 
207
-    foreach($array as $key => &$value) {
208
-      if($value === null) {
207
+    foreach ($array as $key => &$value) {
208
+      if ($value === null) {
209 209
         unset($array[$key]);
210
-      } elseif($level > 0 && is_array($value)) {
210
+      } elseif ($level > 0 && is_array($value)) {
211 211
         static::array_repack($value, $level - 1);
212
-        if(empty($value)) unset($array[$key]);
212
+        if (empty($value)) unset($array[$key]);
213 213
       }
214 214
     }
215 215
   }
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
   // TODO Вынести в отдельный объект
219 219
   public static function cache_repack($location_type, $record_id = 0) {
220 220
     // Если есть $user_id - проверяем, а надо ли перепаковывать?
221
-    if($record_id && isset(static::$data[$location_type][$record_id]) && static::$data[$location_type][$record_id] !== null) return;
221
+    if ($record_id && isset(static::$data[$location_type][$record_id]) && static::$data[$location_type][$record_id] !== null) return;
222 222
 
223 223
     static::array_repack(static::$data[$location_type]);
224 224
     static::array_repack(static::$locator[$location_type], 3); // TODO У каждого типа локации - своя глубина!!!! Но можно и глубже ???
@@ -226,9 +226,9 @@  discard block
 block discarded – undo
226 226
   }
227 227
   public static function cache_clear($location_type, $hard = true) {
228 228
     //print("<br />CACHE CLEAR {$cache_id} " . ($hard ? 'HARD' : 'SOFT') . "<br />");
229
-    if($hard && !empty(static::$data[$location_type])) {
229
+    if ($hard && !empty(static::$data[$location_type])) {
230 230
       // Здесь нельзя делать unset - надо записывать NULL, что бы это отразилось на зависимых записях
231
-      array_walk(static::$data[$location_type], function(&$item){$item = null;});
231
+      array_walk(static::$data[$location_type], function(&$item) {$item = null; });
232 232
     }
233 233
     static::$locator[$location_type] = array();
234 234
     static::$queries[$location_type] = array();
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
   }
237 237
   public static function cache_clear_all($hard = true) {
238 238
     //print('<br />CACHE CLEAR ALL<br />');
239
-    if($hard) {
239
+    if ($hard) {
240 240
       static::$data = array();
241 241
       static::cache_lock_unset_all();
242 242
     }
@@ -263,10 +263,10 @@  discard block
 block discarded – undo
263 263
   */
264 264
   public static function cache_set($location_type, $record_id, $record, $force_overwrite = false, $skip_lock = false) {
265 265
     // нет идентификатора - выход
266
-    if(!($record_id = $record[static::$location_info[$location_type][P_ID]])) return;
266
+    if (!($record_id = $record[static::$location_info[$location_type][P_ID]])) return;
267 267
 
268 268
     $in_transaction = static::db_transaction_check(false);
269
-    if(
269
+    if (
270 270
       $force_overwrite
271 271
       ||
272 272
       // Не заменяются заблокированные записи во время транзакции
@@ -276,14 +276,14 @@  discard block
 block discarded – undo
276 276
       !static::cache_isset($location_type, $record_id)
277 277
     ) {
278 278
       static::$data[$location_type][$record_id] = $record;
279
-      if($in_transaction && !$skip_lock) {
279
+      if ($in_transaction && !$skip_lock) {
280 280
         static::cache_lock_set($location_type, $record_id);
281 281
       }
282 282
     }
283 283
   }
284 284
   public static function cache_unset($cache_id, $safe_record_id) {
285 285
     // $record_id должен быть проверен заранее !
286
-    if(isset(static::$data[$cache_id][$safe_record_id]) && static::$data[$cache_id][$safe_record_id] !== null) {
286
+    if (isset(static::$data[$cache_id][$safe_record_id]) && static::$data[$cache_id][$safe_record_id] !== null) {
287 287
       // Выставляем запись в null
288 288
       static::$data[$cache_id][$safe_record_id] = null;
289 289
       // Очищаем кэш мягко - что бы удалить очистить связанные данные - кэш локаций и кэш запоросов и всё, что потребуется впредь
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
     return static::$locks[$location_type][$record_id] = true; // Не всегда - от результата
298 298
   }
299 299
   public static function cache_lock_unset($location_type, $record_id) {
300
-    if(isset(static::$locks[$location_type][$record_id]))
300
+    if (isset(static::$locks[$location_type][$record_id]))
301 301
       unset(static::$locks[$location_type][$record_id]);
302 302
     return true; // Не всегда - от результата
303 303
   }
@@ -327,13 +327,13 @@  discard block
 block discarded – undo
327 327
    */
328 328
   public static function db_transaction_check($status = null) {
329 329
     $error_msg = false;
330
-    if($status && !static::$db_in_transaction) {
330
+    if ($status && !static::$db_in_transaction) {
331 331
       $error_msg = 'No transaction started for current operation';
332
-    } elseif($status === null && static::$db_in_transaction) {
332
+    } elseif ($status === null && static::$db_in_transaction) {
333 333
       $error_msg = 'Transaction is already started';
334 334
     }
335 335
 
336
-    if($error_msg) {
336
+    if ($error_msg) {
337 337
       // TODO - Убрать позже
338 338
       print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_transaction_check() - ' . $error_msg . '</h1>');
339 339
       $backtrace = debug_backtrace();
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
     static::$transaction_id++;
355 355
     doquery('START TRANSACTION');
356 356
 
357
-    if($config->db_manual_lock_enabled) {
357
+    if ($config->db_manual_lock_enabled) {
358 358
       $config->db_loadItem('var_db_manually_locked');
359 359
       $config->db_saveItem('var_db_manually_locked', SN_TIME_SQL);
360 360
     }
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
   public static function db_transaction_commit() {
370 370
     static::db_transaction_check(true);
371 371
 
372
-    if(!empty(static::$delayed_changset)) {
372
+    if (!empty(static::$delayed_changset)) {
373 373
       static::db_changeset_apply(static::$delayed_changset, true);
374 374
       // pdump(static::$delayed_changset);
375 375
     }
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
   }
385 385
   public static function db_transaction_rollback() {
386 386
     // static::db_transaction_check(true); // TODO - вообще-то тут тоже надо проверять есть ли транзакция
387
-    if(!empty(static::$delayed_changset)) {
387
+    if (!empty(static::$delayed_changset)) {
388 388
       static::db_changeset_revert();
389 389
     }
390 390
     static::$delayed_changset = array();
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
    */
406 406
   public static function db_lock_tables($tables) {
407 407
     $tables = is_array($tables) ? $tables : array($tables => '');
408
-    foreach($tables as $table_name => $condition) {
408
+    foreach ($tables as $table_name => $condition) {
409 409
       self::$db->doquery("SELECT 1 FROM {{{$table_name}}}" . ($condition ? ' WHERE ' . $condition : ''));
410 410
     }
411 411
   }
@@ -446,17 +446,17 @@  discard block
 block discarded – undo
446 446
     //pdump($filter, 'Выбираем ' . $location_type);
447 447
     $query_cache = &static::$queries[$location_type][$filter];
448 448
 
449
-    if(!isset($query_cache) || $query_cache === null) {
449
+    if (!isset($query_cache) || $query_cache === null) {
450 450
       // pdump($filter, 'Кэш пустой, начинаем возню');
451 451
       $location_info = &static::$location_info[$location_type];
452 452
       $id_field = $location_info[P_ID];
453 453
       $query_cache = array();
454 454
 
455
-      if(static::db_transaction_check(false)) {
455
+      if (static::db_transaction_check(false)) {
456 456
         //pdump($filter, 'Транзакция - блокируем ' . $location_type);
457 457
         // Проходим по всем родителям данной записи
458 458
         // foreach($location_info[P_OWNER_INFO] as $owner_location_type => $owner_data)
459
-        foreach($location_info[P_OWNER_INFO] as $owner_data) {
459
+        foreach ($location_info[P_OWNER_INFO] as $owner_data) {
460 460
           $owner_location_type = $owner_data[P_LOCATION];
461 461
           //pdump($filter, 'Транзакция - блокируем родителя ' . $owner_location_type);
462 462
           $parent_id_list = array();
@@ -469,14 +469,14 @@  discard block
 block discarded – undo
469 469
             ($fetch ? ' LIMIT 1' : ''), false, true);
470 470
 
471 471
           //pdump($q, 'Запрос блокировки');
472
-          while($row = db_fetch($query)) {
472
+          while ($row = db_fetch($query)) {
473 473
             // Исключаем из списка родительских ИД уже заблокированные записи
474
-            if(!static::cache_lock_get($owner_location_type, $row['parent_id']))
474
+            if (!static::cache_lock_get($owner_location_type, $row['parent_id']))
475 475
               $parent_id_list[$row['parent_id']] = $row['parent_id'];
476 476
           }
477 477
           //pdump($parent_id_list, 'Выбраны родители');
478 478
           // Если все-таки какие-то записи еще не заблокированы - вынимаем текущие версии из базы
479
-          if($indexes_str = implode(',', $parent_id_list)) {
479
+          if ($indexes_str = implode(',', $parent_id_list)) {
480 480
             //pdump($indexes_str, '$indexes_str');
481 481
             $parent_id_field = static::$location_info[$owner_location_type][P_ID];
482 482
             static::db_get_record_list($owner_location_type,
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
         "SELECT * FROM {{{$location_info[P_TABLE_NAME]}}}" .
492 492
         (($filter = trim($filter)) ? " WHERE {$filter}" : '')
493 493
       );
494
-      while($row = db_fetch($query)) {
494
+      while ($row = db_fetch($query)) {
495 495
         // static::db_get_record_by_id($location_type, $row[$id_field]);
496 496
         static::cache_set($location_type, $row[$id_field], $row);
497 497
         $query_cache[$row[$id_field]] = &static::$data[$location_type][$row[$id_field]];
@@ -499,14 +499,14 @@  discard block
 block discarded – undo
499 499
       }
500 500
     }
501 501
 
502
-    if($no_return) {
502
+    if ($no_return) {
503 503
       return true;
504 504
     } else {
505 505
       $result = false;
506
-      if(is_array($query_cache)) {
507
-        foreach($query_cache as $key => $value) {
506
+      if (is_array($query_cache)) {
507
+        foreach ($query_cache as $key => $value) {
508 508
           $result[$key] = $value;
509
-          if($fetch) break;
509
+          if ($fetch) break;
510 510
         }
511 511
       }
512 512
       return $fetch ? (is_array($result) ? reset($result) : false) : $result;
@@ -522,14 +522,14 @@  discard block
 block discarded – undo
522 522
    */
523 523
   public static function db_upd_record_by_id($location_type, $record_id, $set) {
524 524
     //if(!($record_id = intval($record_id)) || !($set = trim($set))) return false;
525
-    if(!($record_id = idval($record_id)) || !($set = trim($set))) return false;
525
+    if (!($record_id = idval($record_id)) || !($set = trim($set))) return false;
526 526
 
527 527
     $location_info = &static::$location_info[$location_type];
528 528
     $id_field = $location_info[P_ID];
529 529
     $table_name = $location_info[P_TABLE_NAME];
530
-    if($result = static::db_query($q = "UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) // TODO Как-то вернуть может быть LIMIT 1 ?
530
+    if ($result = static::db_query($q = "UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) // TODO Как-то вернуть может быть LIMIT 1 ?
531 531
     {
532
-      if(static::$db->db_affected_rows()) {
532
+      if (static::$db->db_affected_rows()) {
533 533
         // Обновляем данные только если ряд был затронут
534 534
         // TODO - переделать под работу со структурированными $set
535 535
 
@@ -544,16 +544,16 @@  discard block
 block discarded – undo
544 544
     return $result;
545 545
   }
546 546
   public static function db_upd_record_list($location_type, $condition, $set) {
547
-    if(!($set = trim($set))) return false;
547
+    if (!($set = trim($set))) return false;
548 548
 
549 549
     $condition = trim($condition);
550 550
     $table_name = static::$location_info[$location_type][P_TABLE_NAME];
551 551
 
552 552
 //static::db_get_record_list($location_type, $condition, false, true);
553 553
 
554
-    if($result = static::db_query("UPDATE {{{$table_name}}} SET " . $set . ($condition ? ' WHERE ' . $condition : ''))) {
554
+    if ($result = static::db_query("UPDATE {{{$table_name}}} SET " . $set . ($condition ? ' WHERE ' . $condition : ''))) {
555 555
 
556
-      if(static::$db->db_affected_rows()) { // Обновляем данные только если ряд был затронут
556
+      if (static::$db->db_affected_rows()) { // Обновляем данные только если ряд был затронут
557 557
         // Поскольку нам неизвестно, что и как обновилось - сбрасываем кэш этого типа полностью
558 558
         // TODO - когда будет структурированный $condition и $set - перепаковывать данные
559 559
         static::cache_clear($location_type, true);
@@ -572,8 +572,8 @@  discard block
 block discarded – undo
572 572
   public static function db_ins_record($location_type, $set) {
573 573
     $set = trim($set);
574 574
     $table_name = static::$location_info[$location_type][P_TABLE_NAME];
575
-    if($result = static::db_query("INSERT INTO `{{{$table_name}}}` SET {$set}")) {
576
-      if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут
575
+    if ($result = static::db_query("INSERT INTO `{{{$table_name}}}` SET {$set}")) {
576
+      if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут
577 577
       {
578 578
         $record_id = db_insert_id();
579 579
         // Вытаскиваем запись целиком, потому что в $set могли быть "данные по умолчанию"
@@ -595,8 +595,8 @@  discard block
 block discarded – undo
595 595
     $fields = implode(',', array_keys($field_set));
596 596
 
597 597
     $table_name = static::$location_info[$location_type][P_TABLE_NAME];
598
-    if($result = static::db_query("INSERT INTO `{{{$table_name}}}` ($fields) VALUES ($values);")) {
599
-      if(static::$db->db_affected_rows()) {
598
+    if ($result = static::db_query("INSERT INTO `{{{$table_name}}}` ($fields) VALUES ($values);")) {
599
+      if (static::$db->db_affected_rows()) {
600 600
         // Обновляем данные только если ряд был затронут
601 601
         $record_id = db_insert_id();
602 602
         // Вытаскиваем запись целиком, потому что в $set могли быть "данные по умолчанию"
@@ -613,14 +613,14 @@  discard block
 block discarded – undo
613 613
   public static function db_del_record_by_id($location_type, $safe_record_id)
614 614
   {
615 615
     // if(!($safe_record_id = intval($safe_record_id))) return false;
616
-    if(!($safe_record_id = idval($safe_record_id))) return false;
616
+    if (!($safe_record_id = idval($safe_record_id))) return false;
617 617
 
618 618
     $location_info = &static::$location_info[$location_type];
619 619
     $id_field = $location_info[P_ID];
620 620
     $table_name = $location_info[P_TABLE_NAME];
621
-    if($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE `{$id_field}` = {$safe_record_id}"))
621
+    if ($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE `{$id_field}` = {$safe_record_id}"))
622 622
     {
623
-      if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут
623
+      if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут
624 624
       {
625 625
         static::cache_unset($location_type, $safe_record_id);
626 626
       }
@@ -630,16 +630,16 @@  discard block
 block discarded – undo
630 630
   }
631 631
   public static function db_del_record_list($location_type, $condition)
632 632
   {
633
-    if(!($condition = trim($condition))) return false;
633
+    if (!($condition = trim($condition))) return false;
634 634
 
635 635
     $location_info = &static::$location_info[$location_type];
636 636
     $table_name = $location_info[P_TABLE_NAME];
637 637
 
638 638
 //static::db_get_record_list($location_type, $condition, false, true);
639 639
 
640
-    if($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE {$condition}"))
640
+    if ($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE {$condition}"))
641 641
     {
642
-      if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут
642
+      if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут
643 643
       {
644 644
         // Обнуление кэша, потому что непонятно, что поменялось
645 645
         // TODO - когда будет структурированный $condition можно будет делать только cache_unset по нужным записям
@@ -686,21 +686,21 @@  discard block
 block discarded – undo
686 686
   public static function db_get_user_by_username($username_unsafe, $for_update = false, $fields = '*', $player = null, $like = false)
687 687
   {
688 688
     // TODO Проверить, кстати - а везде ли нужно выбирать юзеров или где-то все-таки ищутся Альянсы ?
689
-    if(!($username_unsafe = trim($username_unsafe))) return false;
689
+    if (!($username_unsafe = trim($username_unsafe))) return false;
690 690
 
691 691
     $user = null;
692
-    if(is_array(static::$data[LOC_USER]))
693
-    foreach(static::$data[LOC_USER] as $user_id => $user_data)
692
+    if (is_array(static::$data[LOC_USER]))
693
+    foreach (static::$data[LOC_USER] as $user_id => $user_data)
694 694
     {
695
-      if(is_array($user_data) && isset($user_data['username']))
695
+      if (is_array($user_data) && isset($user_data['username']))
696 696
       {
697 697
         // проверяем поле
698 698
         // TODO Возможно есть смысл всегда искать по strtolower - но может игрок захочет переименоваться с другим регистром? Проверить!
699
-        if((!$like && $user_data['username'] == $username_unsafe) || ($like && strtolower($user_data['username']) == strtolower($username_unsafe)))
699
+        if ((!$like && $user_data['username'] == $username_unsafe) || ($like && strtolower($user_data['username']) == strtolower($username_unsafe)))
700 700
         {
701 701
           // $user_as_ally = intval($user_data['user_as_ally']);
702 702
           $user_as_ally = idval($user_data['user_as_ally']);
703
-          if($player === null || ($player === true && !$user_as_ally) || ($player === false && $user_as_ally))
703
+          if ($player === null || ($player === true && !$user_as_ally) || ($player === false && $user_as_ally))
704 704
           {
705 705
             $user = $user_data;
706 706
             break;
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
       }
710 710
     }
711 711
 
712
-    if($user === null)
712
+    if ($user === null)
713 713
     {
714 714
       // Вытаскиваем запись
715 715
       $username_safe = db_escape($like ? strtolower($username_unsafe) : $username_unsafe); // тут на самом деле strtolower() лишняя, но пусть будет
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
       // self::db_get_record_list(LOC_USER, "`username` " . ($like ? 'LIKE' : '='). " '{$username_safe}'");
719 719
 
720 720
       $user = static::db_query(
721
-        "SELECT * FROM {{users}} WHERE `username` " . ($like ? 'LIKE' : '='). " '{$username_safe}'"
721
+        "SELECT * FROM {{users}} WHERE `username` " . ($like ? 'LIKE' : '=') . " '{$username_safe}'"
722 722
       , true);
723 723
       static::cache_set(LOC_USER, $user['id'], $user); // В кэш-юзер так же заполнять индексы
724 724
     }
@@ -727,15 +727,15 @@  discard block
 block discarded – undo
727 727
   }
728 728
   // UNUSED
729 729
   public static function db_get_user_by_email($email_unsafe, $use_both = false, $for_update = false, $fields = '*') {
730
-    if(!($email_unsafe = strtolower(trim($email_unsafe)))) return false;
730
+    if (!($email_unsafe = strtolower(trim($email_unsafe)))) return false;
731 731
 
732 732
     $user = null;
733 733
     // TODO переделать на индексы
734
-    if(is_array(static::$data[LOC_USER])) {
735
-      foreach(static::$data[LOC_USER] as $user_id => $user_data) {
736
-        if(is_array($user_data) && isset($user_data['email_2'])) {
734
+    if (is_array(static::$data[LOC_USER])) {
735
+      foreach (static::$data[LOC_USER] as $user_id => $user_data) {
736
+        if (is_array($user_data) && isset($user_data['email_2'])) {
737 737
           // проверяем поле
738
-          if(strtolower($user_data['email_2']) == $email_unsafe || ($use_both && strtolower($user_data['email']) == $email_unsafe)) {
738
+          if (strtolower($user_data['email_2']) == $email_unsafe || ($use_both && strtolower($user_data['email']) == $email_unsafe)) {
739 739
             $user = $user_data;
740 740
             break;
741 741
           }
@@ -743,7 +743,7 @@  discard block
 block discarded – undo
743 743
       }
744 744
     }
745 745
 
746
-    if($user === null) {
746
+    if ($user === null) {
747 747
       // Вытаскиваем запись
748 748
       $email_safe = db_escape($email_unsafe);
749 749
       $user = static::db_query(
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
     $user = null;
762 762
     // TODO переделать на индексы
763 763
 
764
-    if($user === null && !empty($where_safe)) {
764
+    if ($user === null && !empty($where_safe)) {
765 765
       // Вытаскиваем запись
766 766
       $user = static::db_query("SELECT * FROM {{users}} WHERE {$where_safe}", true);
767 767
 
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
   {
797 797
     // TODO запихивать в $data[LOC_LOCATION][$location_type][$location_id]
798 798
     $unit = static::db_get_record_by_id(LOC_UNIT, $unit_id, $for_update, $fields);
799
-    if(is_array($unit))
799
+    if (is_array($unit))
800 800
     {
801 801
       static::$locator[LOC_UNIT][$unit['unit_location_type']][$unit['unit_location_id']][$unit['unit_snid']] = &static::$data[LOC_UNIT][$unit_id];
802 802
     }
@@ -814,15 +814,15 @@  discard block
 block discarded – undo
814 814
   public static function db_get_unit_list_by_location($user_id = 0, $location_type, $location_id)
815 815
   {
816 816
     //if(!($location_type = intval($location_type)) || !($location_id = intval($location_id))) return false;
817
-    if(!($location_type = idval($location_type)) || !($location_id = idval($location_id))) return false;
817
+    if (!($location_type = idval($location_type)) || !($location_id = idval($location_id))) return false;
818 818
 
819 819
     $query_cache = &static::$locator[LOC_UNIT][$location_type][$location_id];
820
-    if(!isset($query_cache))
820
+    if (!isset($query_cache))
821 821
     {
822 822
       $got_data = static::db_get_record_list(LOC_UNIT, "unit_location_type = {$location_type} AND unit_location_id = {$location_id} AND " . static::db_unit_time_restrictions());
823
-      if(is_array($got_data))
823
+      if (is_array($got_data))
824 824
       {
825
-        foreach($got_data as $unit_id => $unit_data)
825
+        foreach ($got_data as $unit_id => $unit_data)
826 826
         {
827 827
           // static::$data[LOC_LOCATION][$location_type][$location_id][$unit_data['unit_snid']] = &static::$data[LOC_UNIT][$unit_id];
828 828
           $query_cache[$unit_data['unit_snid']] = &static::$data[LOC_UNIT][$unit_id];
@@ -831,8 +831,8 @@  discard block
 block discarded – undo
831 831
     }
832 832
 
833 833
     $result = false;
834
-    if(is_array($query_cache)) {
835
-      foreach($query_cache as $key => $value) {
834
+    if (is_array($query_cache)) {
835
+      foreach ($query_cache as $key => $value) {
836 836
         $result[$key] = $value;
837 837
       }
838 838
     }
@@ -870,7 +870,7 @@  discard block
 block discarded – undo
870 870
    */
871 871
   public static function db_que_list_by_type_location($user_id, $planet_id = null, $que_type = false, $for_update = false)
872 872
   {
873
-    if(!$user_id)
873
+    if (!$user_id)
874 874
     {
875 875
       pdump(debug_backtrace());
876 876
       die('No user_id for que_get_que()');
@@ -881,14 +881,14 @@  discard block
 block discarded – undo
881 881
     $query = array();
882 882
 
883 883
     // if($user_id = intval($user_id))
884
-    if($user_id = idval($user_id))
884
+    if ($user_id = idval($user_id))
885 885
       $query[] = "`que_player_id` = {$user_id}";
886 886
 
887
-    if($que_type == QUE_RESEARCH || $planet_id === null)
887
+    if ($que_type == QUE_RESEARCH || $planet_id === null)
888 888
       $query[] = "`que_planet_id` IS NULL";
889
-    elseif($planet_id)
889
+    elseif ($planet_id)
890 890
       $query[] = "(`que_planet_id` = {$planet_id}" . ($que_type ? '' : ' OR que_planet_id IS NULL') . ")";
891
-    if($que_type)
891
+    if ($que_type)
892 892
       $query[] = "`que_type` = {$que_type}";
893 893
 
894 894
     /*
@@ -957,14 +957,14 @@  discard block
 block discarded – undo
957 957
 
958 958
   public static function db_changeset_prepare_unit($unit_id, $unit_value, $user, $planet_id = null)
959 959
   {
960
-    if(!is_array($user))
960
+    if (!is_array($user))
961 961
     {
962 962
       // TODO - remove later
963 963
       print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_unit_changeset_prepare() - USER is not ARRAY</h1>');
964 964
       pdump(debug_backtrace());
965 965
       die('USER is not ARRAY');
966 966
     }
967
-    if(!isset($user['id']) || !$user['id'])
967
+    if (!isset($user['id']) || !$user['id'])
968 968
     {
969 969
       // TODO - remove later
970 970
       print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_unit_changeset_prepare() - USER[id] пустой</h1>');
@@ -980,7 +980,7 @@  discard block
 block discarded – undo
980 980
 
981 981
     $db_changeset = array();
982 982
     $temp = db_unit_by_location($user['id'], $unit_location, $location_id, $unit_id, true, 'unit_id');
983
-    if($temp['unit_id'])
983
+    if ($temp['unit_id'])
984 984
     {
985 985
       $db_changeset = array(
986 986
         'action' => SQL_OP_UPDATE,
@@ -1055,9 +1055,9 @@  discard block
 block discarded – undo
1055 1055
   }
1056 1056
 
1057 1057
   public function db_changeset_condition_compile(&$conditions, &$table_name = '') {
1058
-    if(!$conditions[P_LOCATION] || $conditions[P_LOCATION] == LOC_NONE) {
1058
+    if (!$conditions[P_LOCATION] || $conditions[P_LOCATION] == LOC_NONE) {
1059 1059
       $conditions[P_LOCATION] = LOC_NONE;
1060
-      switch($table_name) {
1060
+      switch ($table_name) {
1061 1061
         case 'users':
1062 1062
         case LOC_USER:
1063 1063
           $conditions[P_TABLE_NAME] = $table_name = 'users';
@@ -1079,18 +1079,18 @@  discard block
 block discarded – undo
1079 1079
     }
1080 1080
 
1081 1081
     $conditions[P_FIELDS_STR] = '';
1082
-    if($conditions['fields']) {
1082
+    if ($conditions['fields']) {
1083 1083
       $fields = array();
1084
-      foreach($conditions['fields'] as $field_name => $field_data) {
1084
+      foreach ($conditions['fields'] as $field_name => $field_data) {
1085 1085
         $condition = "`{$field_name}` = ";
1086 1086
         $value = '';
1087
-        if($field_data['delta']) {
1087
+        if ($field_data['delta']) {
1088 1088
           $value = "`{$field_name}`" . ($field_data['delta'] >= 0 ? '+' : '') . $field_data['delta'];
1089
-        } elseif($field_data['set']) {
1090
-          $value = (is_string($field_data['set']) ? "'{$field_data['set']}'": $field_data['set']);
1089
+        } elseif ($field_data['set']) {
1090
+          $value = (is_string($field_data['set']) ? "'{$field_data['set']}'" : $field_data['set']);
1091 1091
         }
1092 1092
 
1093
-        if($value) {
1093
+        if ($value) {
1094 1094
           $fields[] = $condition . $value;
1095 1095
         }
1096 1096
       }
@@ -1098,16 +1098,14 @@  discard block
 block discarded – undo
1098 1098
     }
1099 1099
 
1100 1100
     $conditions[P_WHERE_STR] = '';
1101
-    if(!empty($conditions['where'])) {
1102
-      if($conditions[P_VERSION] == 1) {
1101
+    if (!empty($conditions['where'])) {
1102
+      if ($conditions[P_VERSION] == 1) {
1103 1103
         $the_conditions = array();
1104
-        foreach($conditions['where'] as $field_id => $field_value) {
1104
+        foreach ($conditions['where'] as $field_id => $field_value) {
1105 1105
           // Простое условие - $field_id = $field_value
1106
-          if(is_string($field_id)) {
1106
+          if (is_string($field_id)) {
1107 1107
             $field_value =
1108
-              $field_value === null ? 'NULL' :
1109
-                (is_string($field_value) ? "'" . db_escape($field_value) . "'" :
1110
-                  (is_bool($field_value) ? intval($field_value) : $field_value));
1108
+              $field_value === null ? 'NULL' : (is_string($field_value) ? "'" . db_escape($field_value) . "'" : (is_bool($field_value) ? intval($field_value) : $field_value));
1111 1109
             $the_conditions[] = "`{$field_id}` = {$field_value}";
1112 1110
           } else {
1113 1111
             die('Неподдерживаемый тип условия');
@@ -1124,7 +1122,7 @@  discard block
 block discarded – undo
1124 1122
       $conditions[P_WHERE_STR] = implode(' AND ', $the_conditions);
1125 1123
     }
1126 1124
 
1127
-    switch($conditions['action']) {
1125
+    switch ($conditions['action']) {
1128 1126
       case SQL_OP_DELETE: $conditions[P_ACTION_STR] = ("DELETE FROM {{{$table_name}}}"); break;
1129 1127
       case SQL_OP_UPDATE: $conditions[P_ACTION_STR] = ("UPDATE {{{$table_name}}} SET"); break;
1130 1128
       case SQL_OP_INSERT: $conditions[P_ACTION_STR] = ("INSERT INTO {{{$table_name}}} SET"); break;
@@ -1137,9 +1135,9 @@  discard block
 block discarded – undo
1137 1135
 
1138 1136
   public static function db_changeset_apply($db_changeset, $flush_delayed = false) {
1139 1137
     $result = true;
1140
-    if(!is_array($db_changeset) || empty($db_changeset)) return $result;
1138
+    if (!is_array($db_changeset) || empty($db_changeset)) return $result;
1141 1139
 
1142
-    foreach($db_changeset as $table_name => &$table_data) {
1140
+    foreach ($db_changeset as $table_name => &$table_data) {
1143 1141
       // TODO - delayed changeset
1144 1142
       /*
1145 1143
       if(static::db_transaction_check(false) && !$flush_delayed && ($table_name == 'users' || $table_name == 'planets' || $table_name == 'unit'))
@@ -1148,15 +1146,15 @@  discard block
 block discarded – undo
1148 1146
         continue;
1149 1147
       }
1150 1148
       */
1151
-      foreach($table_data as $record_id => &$conditions) {
1149
+      foreach ($table_data as $record_id => &$conditions) {
1152 1150
         static::db_changeset_condition_compile($conditions, $table_name);
1153 1151
 
1154
-        if($conditions['action'] != SQL_OP_DELETE && !$conditions[P_FIELDS_STR]) continue;
1155
-        if($conditions['action'] == SQL_OP_DELETE && !$conditions[P_WHERE_STR]) continue; // Защита от случайного удаления всех данных в таблице
1152
+        if ($conditions['action'] != SQL_OP_DELETE && !$conditions[P_FIELDS_STR]) continue;
1153
+        if ($conditions['action'] == SQL_OP_DELETE && !$conditions[P_WHERE_STR]) continue; // Защита от случайного удаления всех данных в таблице
1156 1154
 
1157
-        if($conditions[P_LOCATION] != LOC_NONE) {
1155
+        if ($conditions[P_LOCATION] != LOC_NONE) {
1158 1156
           //die('spec ops supernova.php line 928 Добавить работу с кэшем юнитов итд');
1159
-          switch($conditions['action'])
1157
+          switch ($conditions['action'])
1160 1158
           {
1161 1159
             case SQL_OP_DELETE: $result = self::db_del_record_list($conditions[P_LOCATION], $conditions[P_WHERE_STR]) && $result; break;
1162 1160
             case SQL_OP_UPDATE: $result = self::db_upd_record_list($conditions[P_LOCATION], $conditions[P_WHERE_STR], $conditions[P_FIELDS_STR]) && $result; break;
@@ -1237,16 +1235,16 @@  discard block
 block discarded – undo
1237 1235
   }
1238 1236
 
1239 1237
 
1240
-  public static function init_0_prepare () {
1238
+  public static function init_0_prepare() {
1241 1239
     // Отключаем magic_quotes
1242 1240
     ini_get('magic_quotes_sybase') ? die('SN is incompatible with \'magic_quotes_sybase\' turned on. Disable it in php.ini or .htaccess...') : false;
1243
-    if(@get_magic_quotes_gpc()) {
1241
+    if (@get_magic_quotes_gpc()) {
1244 1242
       $gpcr = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
1245
-      array_walk_recursive($gpcr, function (&$value, $key) {
1243
+      array_walk_recursive($gpcr, function(&$value, $key) {
1246 1244
         $value = stripslashes($value);
1247 1245
       });
1248 1246
     }
1249
-    if(function_exists('set_magic_quotes_runtime')) {
1247
+    if (function_exists('set_magic_quotes_runtime')) {
1250 1248
       @set_magic_quotes_runtime(0);
1251 1249
       @ini_set('magic_quotes_runtime', 0);
1252 1250
       @ini_set('magic_quotes_sybase', 0);
@@ -1324,7 +1322,7 @@  discard block
 block discarded – undo
1324 1322
   }
1325 1323
 
1326 1324
   public static function init_debug_state() {
1327
-    if($_SERVER['SERVER_NAME'] == 'localhost' && !defined('BE_DEBUG')) {
1325
+    if ($_SERVER['SERVER_NAME'] == 'localhost' && !defined('BE_DEBUG')) {
1328 1326
       define('BE_DEBUG', true);
1329 1327
     }
1330 1328
 // define('DEBUG_SQL_ONLINE', true); // Полный дамп запросов в рил-тайме. Подойдет любое значение
@@ -1336,7 +1334,7 @@  discard block
 block discarded – undo
1336 1334
     defined('DEBUG_SQL_ERROR') && !defined('DEBUG_SQL_COMMENT') ? define('DEBUG_SQL_COMMENT', true) : false;
1337 1335
     defined('DEBUG_SQL_COMMENT_LONG') && !defined('DEBUG_SQL_COMMENT') ? define('DEBUG_SQL_COMMENT', true) : false;
1338 1336
 
1339
-    if(defined('BE_DEBUG') || static::$config->debug) {
1337
+    if (defined('BE_DEBUG') || static::$config->debug) {
1340 1338
       @define('BE_DEBUG', true);
1341 1339
       @ini_set('display_errors', 1);
1342 1340
       @error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
Please login to merge, or discard this patch.
includes/classes/UnitResourceLoot.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
   public static function _init($group_name = '') {
27 27
     parent::_init($group_name);
28 28
 
29
-    foreach(static::$_group_unit_id_list as $resource_id) {
29
+    foreach (static::$_group_unit_id_list as $resource_id) {
30 30
       static::$_group_pnames[$resource_id] = pname_resource_name($resource_id);
31 31
     }
32 32
 
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
 
49 49
     !is_array($resource_array) ? $resource_array = array() : false;
50 50
 
51
-    foreach($resource_array as $resource_id => $resource_actual_delta) {
52
-      if(!$resource_actual_delta) {
51
+    foreach ($resource_array as $resource_id => $resource_actual_delta) {
52
+      if (!$resource_actual_delta) {
53 53
         // No delta - no changes
54 54
         continue;
55 55
       }
Please login to merge, or discard this patch.