Completed
Push — work-fleets ( 9f3d08...60e3d3 )
by SuperNova.WS
06:31
created
includes/classes/Fleet.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
     parent::__construct();
326 326
     $this->exists_missions = sn_get_groups('missions');
327 327
     $this->allowed_missions = $this->exists_missions;
328
-    if(empty(static::$snGroupFleet)) {
328
+    if (empty(static::$snGroupFleet)) {
329 329
       static::$snGroupFleet = sn_get_groups('fleet');
330 330
       static::$snGroupFleetAndMissiles = sn_get_groups(array('fleet', 'missile'));
331 331
       static::$snGroupRecyclers = sn_get_groups('flt_recyclers');
@@ -408,31 +408,31 @@  discard block
 block discarded – undo
408 408
 
409 409
     return doquery(
410 410
     // Блокировка самого флота
411
-      "SELECT 1 FROM {{fleets}} AS f " .
411
+      "SELECT 1 FROM {{fleets}} AS f ".
412 412
 
413 413
       // Блокировка всех юнитов, принадлежащих этому флоту
414
-      "LEFT JOIN {{unit}} as unit ON unit.unit_location_type = " . static::$locationType . " AND unit.unit_location_id = f.fleet_id " .
414
+      "LEFT JOIN {{unit}} as unit ON unit.unit_location_type = ".static::$locationType." AND unit.unit_location_id = f.fleet_id ".
415 415
 
416 416
       // Блокировка всех прилетающих и улетающих флотов, если нужно
417 417
       // TODO - lock fleets by COORDINATES
418
-      ($mission_data['dst_fleets'] ? "LEFT JOIN {{fleets}} AS fd ON fd.fleet_end_planet_id = f.fleet_end_planet_id OR fd.fleet_start_planet_id = f.fleet_end_planet_id " : '') .
418
+      ($mission_data['dst_fleets'] ? "LEFT JOIN {{fleets}} AS fd ON fd.fleet_end_planet_id = f.fleet_end_planet_id OR fd.fleet_start_planet_id = f.fleet_end_planet_id " : '').
419 419
       // Блокировка всех юнитов, принадлежащих прилетающим и улетающим флотам - ufd = unit_fleet_destination
420
-      ($mission_data['dst_fleets'] ? "LEFT JOIN {{unit}} AS ufd ON ufd.unit_location_type = " . static::$locationType . " AND ufd.unit_location_id = fd.fleet_id " : '') .
420
+      ($mission_data['dst_fleets'] ? "LEFT JOIN {{unit}} AS ufd ON ufd.unit_location_type = ".static::$locationType." AND ufd.unit_location_id = fd.fleet_id " : '').
421 421
 
422
-      ($mission_data['dst_user'] || $mission_data['dst_planet'] ? "LEFT JOIN {{users}} AS ud ON ud.id = f.fleet_target_owner " : '') .
422
+      ($mission_data['dst_user'] || $mission_data['dst_planet'] ? "LEFT JOIN {{users}} AS ud ON ud.id = f.fleet_target_owner " : '').
423 423
       // Блокировка всех юнитов, принадлежащих владельцу планеты-цели
424
-      ($mission_data['dst_user'] || $mission_data['dst_planet'] ? "LEFT JOIN {{unit}} AS unit_player_dest ON unit_player_dest.unit_player_id = ud.id " : '') .
424
+      ($mission_data['dst_user'] || $mission_data['dst_planet'] ? "LEFT JOIN {{unit}} AS unit_player_dest ON unit_player_dest.unit_player_id = ud.id " : '').
425 425
       // Блокировка планеты-цели
426
-      ($mission_data['dst_planet'] ? "LEFT JOIN {{planets}} AS pd ON pd.id = f.fleet_end_planet_id " : '') .
426
+      ($mission_data['dst_planet'] ? "LEFT JOIN {{planets}} AS pd ON pd.id = f.fleet_end_planet_id " : '').
427 427
       // Блокировка всех юнитов, принадлежащих планете-цели - НЕ НУЖНО. Уже залочили ранее, как принадлежащие игроку-цели
428 428
 //      ($mission_data['dst_planet'] ? "LEFT JOIN {{unit}} AS upd ON upd.unit_location_type = " . LOC_PLANET . " AND upd.unit_location_id = pd.id " : '') .
429 429
 
430 430
 
431
-      ($mission_data['src_user'] || $mission_data['src_planet'] ? "LEFT JOIN {{users}} AS us ON us.id = f.fleet_owner " : '') .
431
+      ($mission_data['src_user'] || $mission_data['src_planet'] ? "LEFT JOIN {{users}} AS us ON us.id = f.fleet_owner " : '').
432 432
       // Блокировка всех юнитов, принадлежащих владельцу флота
433
-      ($mission_data['src_user'] || $mission_data['src_planet'] ? "LEFT JOIN {{unit}} AS unit_player_src ON unit_player_src.unit_player_id = us.id " : '') .
433
+      ($mission_data['src_user'] || $mission_data['src_planet'] ? "LEFT JOIN {{unit}} AS unit_player_src ON unit_player_src.unit_player_id = us.id " : '').
434 434
       // Блокировка планеты отправления
435
-      ($mission_data['src_planet'] ? "LEFT JOIN {{planets}} AS ps ON ps.id = f.fleet_start_planet_id " : '') .
435
+      ($mission_data['src_planet'] ? "LEFT JOIN {{planets}} AS ps ON ps.id = f.fleet_start_planet_id " : '').
436 436
       // Блокировка всех юнитов, принадлежащих планете с которой юниты были отправлены - НЕ НУЖНО. Уже залочили ранее, как принадлежащие владельцу флота
437 437
 //      ($mission_data['src_planet'] ? "LEFT JOIN {{unit}} AS ups ON ups.unit_location_type = " . LOC_PLANET . " AND ups.unit_location_id = ps.id " : '') .
438 438
 
@@ -449,11 +449,11 @@  discard block
 block discarded – undo
449 449
   public function dbGetLockById($dbId) {
450 450
     doquery(
451 451
     // Блокировка самого флота
452
-      "SELECT 1 FROM {{fleets}} AS FLEET0 " .
452
+      "SELECT 1 FROM {{fleets}} AS FLEET0 ".
453 453
       // Lock fleet owner
454
-      "LEFT JOIN {{users}} as USER0 on USER0.id = FLEET0.fleet_owner " .
454
+      "LEFT JOIN {{users}} as USER0 on USER0.id = FLEET0.fleet_owner ".
455 455
       // Блокировка всех юнитов, принадлежащих этому флоту
456
-      "LEFT JOIN {{unit}} as UNIT0 ON UNIT0.unit_location_type = " . LOC_FLEET . " AND UNIT0.unit_location_id = FLEET0.fleet_id " .
456
+      "LEFT JOIN {{unit}} as UNIT0 ON UNIT0.unit_location_type = ".LOC_FLEET." AND UNIT0.unit_location_id = FLEET0.fleet_id ".
457 457
 
458 458
       // Без предварительной выборки неизвестно - куда летит этот флот.
459 459
       // Поэтому надо выбирать флоты, чьи координаты прибытия ИЛИ отбытия совпадают с координатами прибытия ИЛИ отбытия текущего флота.
@@ -469,9 +469,9 @@  discard block
 block discarded – undo
469 469
         FLEET1.fleet_end_planet = FLEET0.fleet_end_planet
470 470
       " .
471 471
       // Блокировка всех юнитов, принадлежащих этим флотам
472
-      "LEFT JOIN {{unit}} as UNIT1 ON UNIT1.unit_location_type = " . LOC_FLEET . " AND UNIT1.unit_location_id = FLEET1.fleet_id " .
472
+      "LEFT JOIN {{unit}} as UNIT1 ON UNIT1.unit_location_type = ".LOC_FLEET." AND UNIT1.unit_location_id = FLEET1.fleet_id ".
473 473
       // Lock fleet owner
474
-      "LEFT JOIN {{users}} as USER1 on USER1.id = FLEET1.fleet_owner " .
474
+      "LEFT JOIN {{users}} as USER1 on USER1.id = FLEET1.fleet_owner ".
475 475
 
476 476
       "LEFT JOIN {{fleets}} AS FLEET2 ON
477 477
         FLEET2.fleet_mess = 1   AND FLEET0.fleet_mess = 0 AND
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
       " .
482 482
       // Блокировка всех юнитов, принадлежащих этим флотам
483 483
       "LEFT JOIN {{unit}} as UNIT2 ON
484
-        UNIT2.unit_location_type = " . LOC_FLEET . " AND
484
+        UNIT2.unit_location_type = " . LOC_FLEET." AND
485 485
         UNIT2.unit_location_id = FLEET2.fleet_id
486 486
       " .
487 487
       // Lock fleet owner
@@ -498,11 +498,11 @@  discard block
 block discarded – undo
498 498
       " .
499 499
       // Блокировка всех юнитов, принадлежащих этим флотам
500 500
       "LEFT JOIN {{unit}} as UNIT3 ON
501
-        UNIT3.unit_location_type = " . LOC_FLEET . " AND
501
+        UNIT3.unit_location_type = " . LOC_FLEET." AND
502 502
         UNIT3.unit_location_id = FLEET3.fleet_id
503 503
       " .
504 504
       // Lock fleet owner
505
-      "LEFT JOIN {{users}} as USER3 on USER3.id = FLEET3.fleet_owner " .
505
+      "LEFT JOIN {{users}} as USER3 on USER3.id = FLEET3.fleet_owner ".
506 506
 
507 507
       "LEFT JOIN {{fleets}} AS FLEET4 ON
508 508
         FLEET4.fleet_mess = 1   AND FLEET0.fleet_mess = 1 AND
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
       " .
513 513
       // Блокировка всех юнитов, принадлежащих этим флотам
514 514
       "LEFT JOIN {{unit}} as UNIT4 ON
515
-        UNIT4.unit_location_type = " . LOC_FLEET . " AND
515
+        UNIT4.unit_location_type = " . LOC_FLEET." AND
516 516
         UNIT4.unit_location_id = FLEET4.fleet_id
517 517
       " .
518 518
       // Lock fleet owner
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
       " .
535 535
       // Блокировка всех юнитов, принадлежащих этой планете
536 536
       "LEFT JOIN {{unit}} as UNIT5 ON
537
-        UNIT5.unit_location_type = " . LOC_PLANET . " AND
537
+        UNIT5.unit_location_type = " . LOC_PLANET." AND
538 538
         UNIT5.unit_location_id = PLANETS5.id
539 539
       " .
540 540
 
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
       " .
553 553
       // Блокировка всех юнитов, принадлежащих этой планете
554 554
       "LEFT JOIN {{unit}} as UNIT6 ON
555
-        UNIT6.unit_location_type = " . LOC_PLANET . " AND
555
+        UNIT6.unit_location_type = " . LOC_PLANET." AND
556 556
         UNIT6.unit_location_id = PLANETS6.id
557 557
       " .
558 558
       "WHERE FLEET0.fleet_id = {$dbId} GROUP BY 1 FOR UPDATE"
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
       } elseif ($this->isResource($unit_id)) {
672 672
         $this->resource_list[$unit_id] = $unit_count;
673 673
       } else {
674
-        throw new Exception('Trying to pass to fleet non-resource and non-ship ' . var_export($unit_array, true), FLIGHT_SHIPS_UNIT_WRONG);
674
+        throw new Exception('Trying to pass to fleet non-resource and non-ship '.var_export($unit_array, true), FLIGHT_SHIPS_UNIT_WRONG);
675 675
       }
676 676
     }
677 677
   }
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
    * @param int $unit_count
802 802
    */
803 803
   public function shipSetCount($unit_id, $unit_count = 0) {
804
-pdump(__CLASS__ . '->' . __FUNCTION__);
804
+pdump(__CLASS__.'->'.__FUNCTION__);
805 805
     $this->shipAdjustCount($unit_id, $unit_count, true);
806 806
   }
807 807
 
@@ -877,8 +877,8 @@  discard block
 block discarded – undo
877 877
    */
878 878
   public function shipsGetCapacityRecyclers($recycler_info) {
879 879
     $recyclers_incoming_capacity = 0;
880
-    foreach($this->shipsIterator() as $unitId => $unit) {
881
-      if(!empty(static::$snGroupRecyclers[$unitId]) && $unit->count >= 1) {
880
+    foreach ($this->shipsIterator() as $unitId => $unit) {
881
+      if (!empty(static::$snGroupRecyclers[$unitId]) && $unit->count >= 1) {
882 882
         $recyclers_incoming_capacity += $unit->count * $recycler_info[$unitId]['capacity'];
883 883
       }
884 884
     }
@@ -1009,7 +1009,7 @@  discard block
 block discarded – undo
1009 1009
    */
1010 1010
   public function resourcesSet($resource_list) {
1011 1011
     if (!empty($this->propertiesAdjusted['resource_list'])) {
1012
-      throw new PropertyAccessException('Property "resource_list" already was adjusted so no SET is possible until dbSave in ' . get_called_class() . '::unitSetResourceList', ERR_ERROR);
1012
+      throw new PropertyAccessException('Property "resource_list" already was adjusted so no SET is possible until dbSave in '.get_called_class().'::unitSetResourceList', ERR_ERROR);
1013 1013
     }
1014 1014
     $this->resourcesAdjust($resource_list, true);
1015 1015
   }
@@ -1043,7 +1043,7 @@  discard block
 block discarded – undo
1043 1043
       // Check for negative unit value
1044 1044
       if ($this->resource_list[$resource_id] < 0) {
1045 1045
         // TODO
1046
-        throw new Exception('Resource ' . $resource_id . ' will become negative in ' . get_called_class() . '::unitAdjustResourceList', ERR_ERROR);
1046
+        throw new Exception('Resource '.$resource_id.' will become negative in '.get_called_class().'::unitAdjustResourceList', ERR_ERROR);
1047 1047
       }
1048 1048
     }
1049 1049
   }
@@ -1211,7 +1211,7 @@  discard block
 block discarded – undo
1211 1211
   protected function populateTargetPlanetAndOwner() {
1212 1212
     // If vector points to no exact object OR debris - then getting planet on coordinates
1213 1213
     $targetVector = clone $this->targetVector;
1214
-    if($targetVector->type == PT_DEBRIS || $targetVector == PT_NONE) {
1214
+    if ($targetVector->type == PT_DEBRIS || $targetVector == PT_NONE) {
1215 1215
       $targetVector->type = PT_PLANET;
1216 1216
     }
1217 1217
 
@@ -1224,7 +1224,7 @@  discard block
 block discarded – undo
1224 1224
 
1225 1225
   protected function printErrorIfNoShips() {
1226 1226
     if ($this->unitList->unitsCount() <= 0) {
1227
-      message(classLocale::$lang['fl_err_no_ships'], classLocale::$lang['fl_error'], 'fleet' . DOT_PHP_EX, 5);
1227
+      message(classLocale::$lang['fl_err_no_ships'], classLocale::$lang['fl_error'], 'fleet'.DOT_PHP_EX, 5);
1228 1228
     }
1229 1229
   }
1230 1230
 
@@ -1559,8 +1559,8 @@  discard block
 block discarded – undo
1559 1559
 
1560 1560
   public function fleetSpeed() {
1561 1561
     $maxSpeed = array();
1562
-    foreach($this->shipsIterator() as $ship_id => $unit) {
1563
-      if($unit->count > 0 && !empty(static::$snGroupFleetAndMissiles[$ship_id])) {
1562
+    foreach ($this->shipsIterator() as $ship_id => $unit) {
1563
+      if ($unit->count > 0 && !empty(static::$snGroupFleetAndMissiles[$ship_id])) {
1564 1564
         $single_ship_data = get_ship_data($ship_id, $this->dbOwnerRow);
1565 1565
         $maxSpeed[$ship_id] = $single_ship_data['speed'];
1566 1566
       }
@@ -1592,7 +1592,7 @@  discard block
 block discarded – undo
1592 1592
       $this->fleetPage2Prepare($planetResourcesWithoutConsumption);
1593 1593
     } catch (Exception $e) {
1594 1594
       // TODO - MESSAGE BOX
1595
-      if($e instanceof ExceptionFleetInvalid) {
1595
+      if ($e instanceof ExceptionFleetInvalid) {
1596 1596
         sn_db_transaction_rollback();
1597 1597
         pdie(classLocale::$lang['fl_attack_error'][$e->getCode()]);
1598 1598
       } else {
@@ -1683,7 +1683,7 @@  discard block
 block discarded – undo
1683 1683
       $validator->validate();
1684 1684
     } catch (Exception $e) {
1685 1685
       // TODO - MESSAGE BOX
1686
-      if($e instanceof ExceptionFleetInvalid) {
1686
+      if ($e instanceof ExceptionFleetInvalid) {
1687 1687
         sn_db_transaction_rollback();
1688 1688
         pdie(classLocale::$lang['fl_attack_error'][$e->getCode()]);
1689 1689
       } else {
@@ -1747,7 +1747,7 @@  discard block
 block discarded – undo
1747 1747
 
1748 1748
 
1749 1749
     if (!empty($this->captain['unit_id'])) {
1750
-      DBStaticUnit::db_unit_set_by_id($this->captain['unit_id'], "`unit_location_type` = " . LOC_FLEET . ", `unit_location_id` = {$this->_dbId}");
1750
+      DBStaticUnit::db_unit_set_by_id($this->captain['unit_id'], "`unit_location_type` = ".LOC_FLEET.", `unit_location_id` = {$this->_dbId}");
1751 1751
     }
1752 1752
 
1753 1753
 //    return $this->fleet->acs['ankunft'] - $this->fleet->time_launch >= $this->fleet->travelData['duration'];
@@ -1759,7 +1759,7 @@  discard block
 block discarded – undo
1759 1759
     $template_result['.']['fleets'][] = $this->renderFleet(SN_TIME_NOW, $timeMissionJob);
1760 1760
 
1761 1761
     $template_result += array(
1762
-      'mission'         => classLocale::$lang['type_mission'][$this->_mission_type] . ($this->_mission_type == MT_EXPLORE || $this->_mission_type == MT_HOLD ? ' ' . pretty_time($timeMissionJob) : ''),
1762
+      'mission'         => classLocale::$lang['type_mission'][$this->_mission_type].($this->_mission_type == MT_EXPLORE || $this->_mission_type == MT_HOLD ? ' '.pretty_time($timeMissionJob) : ''),
1763 1763
       'dist'            => pretty_number($this->travelData['distance']),
1764 1764
       'speed'           => pretty_number($this->travelData['fleet_speed']),
1765 1765
       'deute_need'      => pretty_number($this->travelData['consumption']),
@@ -1803,7 +1803,7 @@  discard block
 block discarded – undo
1803 1803
   protected function resourcesSubstractConsumption($planetResources) {
1804 1804
     !isset($planetResources[RES_DEUTERIUM]) ? $planetResources[RES_DEUTERIUM] = 0 : false;
1805 1805
 
1806
-    if($this->travelData['consumption'] >= 0) {
1806
+    if ($this->travelData['consumption'] >= 0) {
1807 1807
       $planetResources[RES_DEUTERIUM] -= ceil($this->travelData['consumption']);
1808 1808
     }
1809 1809
 
Please login to merge, or discard this patch.
tests.int/FleetTest.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 define('SN_IN_FLEET', true);
6 6
 define('SN_RENDER_NAVBAR_PLANET', true);
7 7
 
8
-include('../common.' . substr(strrchr(__FILE__, '.'), 1));
8
+include('../common.'.substr(strrchr(__FILE__, '.'), 1));
9 9
 
10 10
 // TODO - Переместить это куда-нибудь
11 11
 $fleet_page = sys_get_param_int('fleet_page', sys_get_param_int('mode'));
@@ -162,17 +162,17 @@  discard block
 block discarded – undo
162 162
 //  break;
163 163
     }
164 164
 
165
-    if($exceptionCode !== null) {
166
-      print('<span style="color: red; font-size: 200%;">FAILED! Expected Exception [' . $exceptionCode . ']: "' . classLocale::$lang['fl_attack_error'][$exceptionCode] . '" - FAILED!</span><br />');
165
+    if ($exceptionCode !== null) {
166
+      print('<span style="color: red; font-size: 200%;">FAILED! Expected Exception ['.$exceptionCode.']: "'.classLocale::$lang['fl_attack_error'][$exceptionCode].'" - FAILED!</span><br />');
167 167
     } else {
168 168
       print('Passed');
169 169
     }
170 170
   } catch (Exception $e) {
171 171
     if ($exceptionCode !== null && $e->getCode() === $exceptionCode) {
172
-      print('<span style="color: darkgreen;">Exception [' . $exceptionCode . ']: "' . classLocale::$lang['fl_attack_error'][$exceptionCode] . '" - passed</span><br />');
172
+      print('<span style="color: darkgreen;">Exception ['.$exceptionCode.']: "'.classLocale::$lang['fl_attack_error'][$exceptionCode].'" - passed</span><br />');
173 173
     } else {
174
-      print('<div style="color: red; font-size: 200%;">Expected Exception [' . $exceptionCode . ']: "' . classLocale::$lang['fl_attack_error'][$exceptionCode] . '" - FAILED!</div>');
175
-      print('<div style="color: red; font-size: 200%;">Got Exception [' . $e->getCode() . ']: "' . $e->getMessage() . '"/"' . classLocale::$lang['fl_attack_error'][$e->getCode()] . '" . "</div>');
174
+      print('<div style="color: red; font-size: 200%;">Expected Exception ['.$exceptionCode.']: "'.classLocale::$lang['fl_attack_error'][$exceptionCode].'" - FAILED!</div>');
175
+      print('<div style="color: red; font-size: 200%;">Got Exception ['.$e->getCode().']: "'.$e->getMessage().'"/"'.classLocale::$lang['fl_attack_error'][$e->getCode()].'" . "</div>');
176 176
       throw $e;
177 177
     }
178 178
   }
Please login to merge, or discard this patch.