Completed
Push — work-fleets ( 6d7489...ab257a )
by SuperNova.WS
05:48
created
fleet.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -7,9 +7,9 @@  discard block
 block discarded – undo
7 7
 
8 8
 // TODO - Переместить это куда-нибудь
9 9
 $fleet_page = sys_get_param_int('fleet_page', sys_get_param_int('mode'));
10
-if($fleet_ship_sort = sys_get_param_id('sort_elements') && $fleet_page == 0) {
10
+if ($fleet_ship_sort = sys_get_param_id('sort_elements') && $fleet_page == 0) {
11 11
   define('IN_AJAX', true);
12
-  if(!empty(classLocale::$lang['player_option_fleet_ship_sort'][$fleet_ship_sort])) {
12
+  if (!empty(classLocale::$lang['player_option_fleet_ship_sort'][$fleet_ship_sort])) {
13 13
     // player_save_option($user, PLAYER_OPTION_FLEET_SHIP_SORT, $fleet_ship_sort);
14 14
     // player_save_option($user, PLAYER_OPTION_FLEET_SHIP_SORT_INVERSE, sys_get_param_id('fleet_ship_sort_inverse', 0));
15 15
     classSupernova::$user_options[PLAYER_OPTION_FLEET_SHIP_SORT] = $fleet_ship_sort;
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 $objFleet5->initDefaults($user, $planetrow, $targetVector, $target_mission, $ships, $fleet_group_mr, $speed_percent);
43 43
 
44 44
 
45
-switch($fleet_page) {
45
+switch ($fleet_page) {
46 46
   case 1:
47 47
     $objFleet5->fleetPage1();
48 48
   break;
Please login to merge, or discard this patch.
includes/classes/UnitList.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
    * @param Unit  $value
89 89
    */
90 90
   public function offsetSet($offset, $value) {
91
-    if(isset($this->mapUnitIdToDb[$value->unitId])) {
91
+    if (isset($this->mapUnitIdToDb[$value->unitId])) {
92 92
       classSupernova::$debug->error('UnitList::offsetSet: Unit with UnitId ' . $value->unitId . ' already exists');
93 93
     }
94 94
     $this->mapUnitIdToDb[$value->unitId] = $value;
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
   }
97 97
 
98 98
   public function offsetUnset($offset) {
99
-    if(!empty($this[$offset]->unitId)) {
99
+    if (!empty($this[$offset]->unitId)) {
100 100
 //      $unit_id = $this[$offset]->unitId;
101 101
 //      $this->mapUnitIdToDb[$unit_id] = null;
102 102
 //      unset($this->mapUnitIdToDb[$unit_id]);
@@ -117,20 +117,20 @@  discard block
 block discarded – undo
117 117
   public function dbLoad($dbId, $lockSkip = false) {
118 118
 //    $this->_reset();
119 119
 
120
-    if($dbId <= 0) {
120
+    if ($dbId <= 0) {
121 121
       return;
122 122
     }
123 123
 
124
-    if(!is_object($this->locatedAt)) {
124
+    if (!is_object($this->locatedAt)) {
125 125
       classSupernova::$debug->error('UnitList::dbLoad have no locatedAt field set');
126 126
     }
127 127
 
128 128
     $unit_array = classSupernova::db_get_unit_list_by_location(0, $this->getLocationType(), $this->getLocationDbId());
129
-    if(!is_array($unit_array)) {
129
+    if (!is_array($unit_array)) {
130 130
       return;
131 131
     }
132 132
 
133
-    foreach($unit_array as $unit_db_row) {
133
+    foreach ($unit_array as $unit_db_row) {
134 134
       $unit = $this->_createElement();
135 135
       $unit->dbRowParse($unit_db_row);
136 136
 
@@ -145,25 +145,25 @@  discard block
 block discarded – undo
145 145
   }
146 146
 
147 147
   public function dbSave() {
148
-    if(!is_object($this->locatedAt)) {
148
+    if (!is_object($this->locatedAt)) {
149 149
       classSupernova::$debug->error('UnitList::dbSave have no locatedAt field set');
150 150
     }
151 151
 
152
-    foreach($this->mapUnitIdToDb as $unit) {
152
+    foreach ($this->mapUnitIdToDb as $unit) {
153 153
       $unit_db_id = $unit->dbId;
154 154
       $unit->dbSave();
155 155
 
156
-      if($unit->isEmpty()) {
156
+      if ($unit->isEmpty()) {
157 157
         // Removing unit object
158 158
         // TODO - change when there will be common bus for all objects
159 159
         // ...or should I? If COUNT is empty - it means that object does not exists in DB. So it should be deleted from PHP memory and cache too
160 160
         unset($this[$unit_db_id]);
161 161
       } else {
162
-        if($unit->dbId <= 0) {
162
+        if ($unit->dbId <= 0) {
163 163
           classSupernova::$debug->error('Error writing unit to DB');
164 164
         }
165 165
         // If unit is new then putting unit object to container
166
-        if(empty($this->_container[$unit->dbId])) {
166
+        if (empty($this->_container[$unit->dbId])) {
167 167
           $this->_container[$unit->dbId] = $unit;
168 168
         }
169 169
       }
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
   }
202 202
 
203 203
   public function unitGetCount($unit_id) {
204
-    if(empty($this->mapUnitIdToDb[$unit_id])) {
204
+    if (empty($this->mapUnitIdToDb[$unit_id])) {
205 205
       throw new Exception('Unit [' . $unit_id . '] is not exists in UnitList');
206 206
     }
207 207
     return $this->mapUnitIdToDb[$unit_id]->count;
@@ -216,14 +216,14 @@  discard block
 block discarded – undo
216 216
    * @param bool $replace_value
217 217
    */
218 218
   public function unitAdjustCount($unit_id, $unit_count = 0, $replace_value = false) {
219
-    if(empty($this->mapUnitIdToDb[$unit_id])) {
219
+    if (empty($this->mapUnitIdToDb[$unit_id])) {
220 220
       // If unit not exists - creating one and setting all attributes
221 221
       $this->mapUnitIdToDb[$unit_id] = $this->_createElement();
222 222
       $this->mapUnitIdToDb[$unit_id]->setUnitId($unit_id);
223 223
       $this->mapUnitIdToDb[$unit_id]->setLocatedAt($this);
224 224
     }
225 225
 
226
-    if($replace_value) {
226
+    if ($replace_value) {
227 227
       $this->mapUnitIdToDb[$unit_id]->count = $unit_count;
228 228
     } else {
229 229
       $this->mapUnitIdToDb[$unit_id]->adjustCount($unit_count);
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
    */
238 238
   public function unitsGetArray() {
239 239
     $result = array();
240
-    foreach($this->mapUnitIdToDb as $unit) {
240
+    foreach ($this->mapUnitIdToDb as $unit) {
241 241
       $result[$unit->unitId] = $unit->count;
242 242
     }
243 243
 
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
   }
246 246
 
247 247
   public function unitsCountApplyLossMultiplier($ships_lost_multiplier) {
248
-    foreach($this->mapUnitIdToDb as $unit_id => $unit) {
248
+    foreach ($this->mapUnitIdToDb as $unit_id => $unit) {
249 249
       $unit->count = floor($unit->count * $ships_lost_multiplier);
250 250
     }
251 251
   }
@@ -267,8 +267,8 @@  discard block
 block discarded – undo
267 267
 
268 268
   public function unitsPropertySumById($unit_id = 0, $propertyName = 'count') {
269 269
     $result = 0;
270
-    foreach($this->mapUnitIdToDb as $unit) {
271
-      if(!$unit_id || $unit->unitId == $unit_id) {
270
+    foreach ($this->mapUnitIdToDb as $unit) {
271
+      if (!$unit_id || $unit->unitId == $unit_id) {
272 272
         $result += $unit->$propertyName;
273 273
       }
274 274
     }
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
   // TODO - WRONG FOR STRUCTURES
285 285
   public function shipsPoolPropertySumById($unit_id = 0, $propertyName = 'count') {
286 286
     $result = 0;
287
-    foreach($this->mapUnitIdToDb as $unit) {
288
-      if(!$unit_id || $unit->unitId == $unit_id) {
287
+    foreach ($this->mapUnitIdToDb as $unit) {
288
+      if (!$unit_id || $unit->unitId == $unit_id) {
289 289
         $result += $unit->$propertyName * $unit->count;
290 290
       }
291 291
     }
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 
296 296
   public function shipsIsEnoughOnPlanet($dbPlanetRow) {
297 297
     $player = null;
298
-    foreach($this->mapUnitIdToDb as $unitId => $unit) {
299
-      if($unit->count < mrc_get_level($player, $dbPlanetRow, $unit->unitId)) {
298
+    foreach ($this->mapUnitIdToDb as $unitId => $unit) {
299
+      if ($unit->count < mrc_get_level($player, $dbPlanetRow, $unit->unitId)) {
300 300
         return false;
301 301
       }
302 302
     }
@@ -313,15 +313,15 @@  discard block
 block discarded – undo
313 313
      * @var Fleet $objFleet
314 314
      */
315 315
     $objFleet = $this->getLocatedAt();
316
-    if(empty($objFleet)) {
316
+    if (empty($objFleet)) {
317 317
       throw new Exception('No fleet owner on UnitList::unitsRender() in ' . __FILE__ . '@' . __LINE__);
318 318
     }
319 319
 
320 320
     $tplShips = array();
321
-    foreach($this->mapUnitIdToDb as $unit) {
321
+    foreach ($this->mapUnitIdToDb as $unit) {
322 322
       $ship_id = $unit->unitId;
323 323
       $ship_count = $unit->count;
324
-      if(!UnitShip::is_in_group($ship_id) || $ship_count <= 0) {
324
+      if (!UnitShip::is_in_group($ship_id) || $ship_count <= 0) {
325 325
         continue;
326 326
       }
327 327
 
@@ -349,9 +349,9 @@  discard block
 block discarded – undo
349 349
   // TODO - REDO!!!!
350 350
   public function shipsSpeedMin($user) {
351 351
     $speeds = array();
352
-    if(!empty($this->mapUnitIdToDb)) {
353
-      foreach($this->mapUnitIdToDb as $ship_id => $unit) {
354
-        if($unit->getCount() > 0 && in_array($unit->unitId, sn_get_groups(array('fleet', 'missile')))) {
352
+    if (!empty($this->mapUnitIdToDb)) {
353
+      foreach ($this->mapUnitIdToDb as $ship_id => $unit) {
354
+        if ($unit->getCount() > 0 && in_array($unit->unitId, sn_get_groups(array('fleet', 'missile')))) {
355 355
           $single_ship_data = get_ship_data($unit->unitId, $user);
356 356
           $speeds[] = $single_ship_data['speed'];
357 357
         }
@@ -374,11 +374,11 @@  discard block
 block discarded – undo
374 374
     $fleet_speed = $this->shipsSpeedMin($dbOwnerRow);
375 375
     $real_speed = $speed_percent * sqrt($fleet_speed);
376 376
 
377
-    if($fleet_speed && $game_fleet_speed) {
377
+    if ($fleet_speed && $game_fleet_speed) {
378 378
       $duration = max(1, round((35000 / $speed_percent * sqrt($distance * 10 / $fleet_speed) + 10) / $game_fleet_speed));
379 379
 
380
-      foreach($this->mapUnitIdToDb as $ship_id => $unit) {
381
-        if(!$unit->unitId || $unit->getCount() <= 0) {
380
+      foreach ($this->mapUnitIdToDb as $ship_id => $unit) {
381
+        if (!$unit->unitId || $unit->getCount() <= 0) {
382 382
           continue;
383 383
         }
384 384
 
@@ -409,8 +409,8 @@  discard block
 block discarded – undo
409 409
    * @return bool
410 410
    */
411 411
   public function unitsInGroup($group) {
412
-    foreach($this->mapUnitIdToDb as $unitId => $unit) {
413
-      if(!in_array($unitId, $group)) {
412
+    foreach ($this->mapUnitIdToDb as $unitId => $unit) {
413
+      if (!in_array($unitId, $group)) {
414 414
         return false;
415 415
       }
416 416
     }
@@ -419,9 +419,9 @@  discard block
 block discarded – undo
419 419
   }
420 420
 
421 421
   public function unitsIsAllMovable($dbOwnerRow) {
422
-    foreach($this->mapUnitIdToDb as $unitId => $unit) {
422
+    foreach ($this->mapUnitIdToDb as $unitId => $unit) {
423 423
       $single_ship_data = get_ship_data($unit->unitId, $dbOwnerRow);
424
-      if($single_ship_data['speed'] <= 0) {
424
+      if ($single_ship_data['speed'] <= 0) {
425 425
         return false;
426 426
       }
427 427
     }
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 
482 482
     print('</tr>');
483 483
 
484
-    foreach($this->mapUnitIdToDb as $unit) {
484
+    foreach ($this->mapUnitIdToDb as $unit) {
485 485
       print('<tr>');
486 486
 
487 487
       print('<td>');
@@ -530,12 +530,12 @@  discard block
 block discarded – undo
530 530
     print('</table>');
531 531
   }
532 532
   public function unitZeroDbId() {
533
-    foreach($this->mapUnitIdToDb as $unit) {
533
+    foreach ($this->mapUnitIdToDb as $unit) {
534 534
       $unit->zeroDbId();
535 535
     }
536 536
   }
537 537
   public function unitZeroCount() {
538
-    foreach($this->mapUnitIdToDb as $unit) {
538
+    foreach ($this->mapUnitIdToDb as $unit) {
539 539
       $unit->count = 0;
540 540
     }
541 541
   }
Please login to merge, or discard this patch.
includes/classes/Fleet.php 1 patch
Spacing   +133 added lines, -134 removed lines patch added patch discarded remove patch
@@ -306,9 +306,9 @@  discard block
 block discarded – undo
306 306
   public function renderAvailableShips(&$template_result, $playerRow, $planetRow) {
307 307
     $record_index = 0;
308 308
     $ship_list = array();
309
-    foreach(sn_get_groups('fleet') as $n => $unit_id) {
309
+    foreach (sn_get_groups('fleet') as $n => $unit_id) {
310 310
       $unit_level = mrc_get_level($playerRow, $planetRow, $unit_id, false, true);
311
-      if($unit_level <= 0) {
311
+      if ($unit_level <= 0) {
312 312
         continue;
313 313
       }
314 314
       $ship_data = get_ship_data($unit_id, $playerRow);
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 
330 330
     sortUnitRenderedList($ship_list, classSupernova::$user_options[PLAYER_OPTION_FLEET_SHIP_SORT], classSupernova::$user_options[PLAYER_OPTION_FLEET_SHIP_SORT_INVERSE]);
331 331
 
332
-    foreach($ship_list as $ship_data) {
332
+    foreach ($ship_list as $ship_data) {
333 333
       $template_result['.']['ships'][] = $ship_data;
334 334
     }
335 335
   }
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
   public function dbInsert() {
349 349
     // WARNING! MISSION TIMES MUST BE SET WITH set_times() method!
350 350
     // TODO - more checks!
351
-    if(empty($this->_time_launch)) {
351
+    if (empty($this->_time_launch)) {
352 352
       die('Fleet time not set!');
353 353
     }
354 354
 
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
     // Записываем изменения в БД
558 558
     $this->dbSave();
559 559
 
560
-    if($this->_group_id) {
560
+    if ($this->_group_id) {
561 561
       // TODO: Make here to delete only one AKS - by adding aks_fleet_count to AKS table
562 562
       db_fleet_aks_purge();
563 563
     }
@@ -624,18 +624,18 @@  discard block
 block discarded – undo
624 624
    */
625 625
   // TODO - separate shipList and unitList
626 626
   public function unitsSetFromArray($unit_array) {
627
-    if(empty($unit_array) || !is_array($unit_array)) {
627
+    if (empty($unit_array) || !is_array($unit_array)) {
628 628
       return;
629 629
     }
630
-    foreach($unit_array as $unit_id => $unit_count) {
630
+    foreach ($unit_array as $unit_id => $unit_count) {
631 631
       $unit_count = floatval($unit_count);
632
-      if(!$unit_count) {
632
+      if (!$unit_count) {
633 633
         continue;
634 634
       }
635 635
 
636
-      if($this->isShip($unit_id)) {
636
+      if ($this->isShip($unit_id)) {
637 637
         $this->unitList->unitSetCount($unit_id, $unit_count);
638
-      } elseif($this->isResource($unit_id)) {
638
+      } elseif ($this->isResource($unit_id)) {
639 639
         $this->resource_list[$unit_id] = $unit_count;
640 640
       } else {
641 641
         throw new Exception('Trying to pass to fleet non-resource and non-ship ' . var_export($unit_array, true), ERR_ERROR);
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
   public function parse_missile_db_row($missile_db_row) {
665 665
 //    $this->_reset();
666 666
 
667
-    if(empty($missile_db_row) || !is_array($missile_db_row)) {
667
+    if (empty($missile_db_row) || !is_array($missile_db_row)) {
668 668
       return;
669 669
     }
670 670
 
@@ -827,7 +827,7 @@  discard block
 block discarded – undo
827 827
   public function shipsGetCapacityRecyclers(array $recycler_info) {
828 828
     $recyclers_incoming_capacity = 0;
829 829
     $fleet_data = $this->shipsGetArray();
830
-    foreach($recycler_info as $recycler_id => $recycler_data) {
830
+    foreach ($recycler_info as $recycler_id => $recycler_data) {
831 831
       $recyclers_incoming_capacity += $fleet_data[$recycler_id] * $recycler_data['capacity'];
832 832
     }
833 833
 
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
     sn_db_transaction_check(true);
848 848
 
849 849
     // Если флот уже обработан - не существует или возращается - тогда ничего не делаем
850
-    if($this->isEmpty()) {
850
+    if ($this->isEmpty()) {
851 851
       return $result;
852 852
     }
853 853
 
@@ -869,18 +869,18 @@  discard block
 block discarded – undo
869 869
     // TODO - Проверка, что планета всё еще существует на указанных координатах, а не телепортировалась, не удалена хозяином, не уничтожена врагом
870 870
     // Флот, который возвращается на захваченную планету, пропадает
871 871
     // Ship landing is possible only to fleet owner's planet
872
-    if($this->getPlayerOwnerId() == $planet_arrival['id_owner']) {
872
+    if ($this->getPlayerOwnerId() == $planet_arrival['id_owner']) {
873 873
       $db_changeset = array();
874 874
 
875 875
       $fleet_array = $this->shipsGetArray();
876
-      foreach($fleet_array as $ship_id => $ship_count) {
877
-        if($ship_count) {
876
+      foreach ($fleet_array as $ship_id => $ship_count) {
877
+        if ($ship_count) {
878 878
           $db_changeset['unit'][] = sn_db_unit_changeset_prepare($ship_id, $ship_count, $user, $planet_arrival['id']);
879 879
         }
880 880
       }
881 881
 
882 882
       // Adjusting ship amount on planet
883
-      if(!empty($db_changeset)) {
883
+      if (!empty($db_changeset)) {
884 884
         db_changeset_apply($db_changeset);
885 885
       }
886 886
 
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
    * @param array $resource_list
929 929
    */
930 930
   public function resourcesSet($resource_list) {
931
-    if(!empty($this->propertiesAdjusted['resource_list'])) {
931
+    if (!empty($this->propertiesAdjusted['resource_list'])) {
932 932
       throw new PropertyAccessException('Property "resource_list" already was adjusted so no SET is possible until dbSave in ' . get_called_class() . '::unitSetResourceList', ERR_ERROR);
933 933
     }
934 934
     $this->resourcesAdjust($resource_list, true);
@@ -942,13 +942,13 @@  discard block
 block discarded – undo
942 942
   public function resourcesAdjust($resource_delta_list, $replace_value = false) {
943 943
     !is_array($resource_delta_list) ? $resource_delta_list = array() : false;
944 944
 
945
-    foreach($resource_delta_list as $resource_id => $unit_delta) {
946
-      if(!UnitResourceLoot::is_in_group($resource_id) || !($unit_delta = floor($unit_delta))) {
945
+    foreach ($resource_delta_list as $resource_id => $unit_delta) {
946
+      if (!UnitResourceLoot::is_in_group($resource_id) || !($unit_delta = floor($unit_delta))) {
947 947
         // Not a resource or no resources - continuing
948 948
         continue;
949 949
       }
950 950
 
951
-      if($replace_value) {
951
+      if ($replace_value) {
952 952
         $this->resource_list[$resource_id] = $unit_delta;
953 953
       } else {
954 954
         $this->resource_list[$resource_id] += $unit_delta;
@@ -958,7 +958,7 @@  discard block
 block discarded – undo
958 958
       }
959 959
 
960 960
       // Check for negative unit value
961
-      if($this->resource_list[$resource_id] < 0) {
961
+      if ($this->resource_list[$resource_id] < 0) {
962 962
         // TODO
963 963
         throw new Exception('Resource ' . $resource_id . ' will become negative in ' . get_called_class() . '::unitAdjustResourceList', ERR_ERROR);
964 964
       }
@@ -1010,7 +1010,7 @@  discard block
 block discarded – undo
1010 1010
     sn_db_transaction_check(true);
1011 1011
 
1012 1012
     // Если флот уже обработан - не существует или возращается - тогда ничего не делаем
1013
-    if(!$this->resourcesGetTotal()) {
1013
+    if (!$this->resourcesGetTotal()) {
1014 1014
       return $result;
1015 1015
     }
1016 1016
 
@@ -1030,7 +1030,7 @@  discard block
 block discarded – undo
1030 1030
     // TODO - Проверка, что планета всё еще существует на указанных координатах, а не телепортировалась, не удалена хозяином, не уничтожена врагом
1031 1031
 
1032 1032
     // Restoring resources to planet
1033
-    if($this->resourcesGetTotal()) {
1033
+    if ($this->resourcesGetTotal()) {
1034 1034
       $fleet_resources = $this->resourcesGetList();
1035 1035
       db_planet_set_by_id($planet_arrival['id'],
1036 1036
         "`metal` = `metal` + '{$fleet_resources[RES_METAL]}', `crystal` = `crystal` + '{$fleet_resources[RES_CRYSTAL]}', `deuterium` = `deuterium` + '{$fleet_resources[RES_DEUTERIUM]}'");
@@ -1096,12 +1096,12 @@  discard block
 block discarded – undo
1096 1096
 
1097 1097
   protected function populateTargetPlanet() {
1098 1098
     $targetPlanetCoords = $this->targetVector;
1099
-    if($this->mission_type != MT_NONE) {
1099
+    if ($this->mission_type != MT_NONE) {
1100 1100
       $this->restrictTargetTypeByMission();
1101 1101
 
1102 1102
       // TODO - Нельзя тут просто менять тип планеты или координат!
1103 1103
       // If current planet type is not allowed on mission - switch planet type
1104
-      if(empty($this->allowed_planet_types[$this->targetVector->type])) {
1104
+      if (empty($this->allowed_planet_types[$this->targetVector->type])) {
1105 1105
         $targetPlanetCoords->type = reset($this->allowed_planet_types);
1106 1106
       }
1107 1107
     }
@@ -1110,14 +1110,14 @@  discard block
 block discarded – undo
1110 1110
   }
1111 1111
 
1112 1112
   protected function restrictTargetTypeByMission() {
1113
-    if($this->_mission_type == MT_MISSILE) {
1113
+    if ($this->_mission_type == MT_MISSILE) {
1114 1114
       $this->allowed_planet_types = array(PT_PLANET => PT_PLANET);
1115
-    } elseif($this->_mission_type == MT_COLONIZE || $this->_mission_type == MT_EXPLORE) {
1115
+    } elseif ($this->_mission_type == MT_COLONIZE || $this->_mission_type == MT_EXPLORE) {
1116 1116
       // TODO - PT_NONE
1117 1117
       $this->allowed_planet_types = array(PT_PLANET => PT_PLANET);
1118
-    } elseif($this->_mission_type == MT_RECYCLE) {
1118
+    } elseif ($this->_mission_type == MT_RECYCLE) {
1119 1119
       $this->allowed_planet_types = array(PT_DEBRIS => PT_DEBRIS);
1120
-    } elseif($this->_mission_type == MT_DESTROY) {
1120
+    } elseif ($this->_mission_type == MT_DESTROY) {
1121 1121
       $this->allowed_planet_types = array(PT_MOON => PT_MOON);
1122 1122
     } else {
1123 1123
       $this->allowed_planet_types = array(PT_PLANET => PT_PLANET, PT_MOON => PT_MOON);
@@ -1149,13 +1149,13 @@  discard block
 block discarded – undo
1149 1149
 
1150 1150
 
1151 1151
   public function restrictToKnownSpace() {
1152
-    if(!$this->targetVector->isInKnownSpace()) {
1152
+    if (!$this->targetVector->isInKnownSpace()) {
1153 1153
       throw new Exception('FLIGHT_VECTOR_BEYOND_SYSTEM', FLIGHT_VECTOR_BEYOND_SYSTEM);
1154 1154
     }
1155 1155
   }
1156 1156
 
1157 1157
   public function restrictToTypePlanet($errorCode) {
1158
-    if($this->targetVector->type != PT_PLANET) {
1158
+    if ($this->targetVector->type != PT_PLANET) {
1159 1159
       throw new Exception($errorCode, $errorCode);
1160 1160
     }
1161 1161
   }
@@ -1163,56 +1163,56 @@  discard block
 block discarded – undo
1163 1163
   public function restrictToNoMissiles() {
1164 1164
     $missilesAttack = $this->unitList->unitsCountById(UNIT_DEF_MISSILE_INTERPLANET);
1165 1165
     $missilesDefense = $this->unitList->unitsCountById(UNIT_DEF_MISSILE_INTERCEPTOR);
1166
-    if($missilesAttack > 0 || $missilesDefense > 0) {
1166
+    if ($missilesAttack > 0 || $missilesDefense > 0) {
1167 1167
       throw new Exception('FLIGHT_SHIPS_NO_MISSILES', FLIGHT_SHIPS_NO_MISSILES);
1168 1168
     }
1169 1169
   }
1170 1170
 
1171 1171
   public function restrictToTargetOwn() {
1172
-    if($this->dbTargetRow['id'] != $this->getPlayerOwnerId()) {
1172
+    if ($this->dbTargetRow['id'] != $this->getPlayerOwnerId()) {
1173 1173
       throw new Exception('FLIGHT_VECTOR_ONLY_OWN', FLIGHT_VECTOR_ONLY_OWN);
1174 1174
     }
1175 1175
   }
1176 1176
 
1177 1177
   public function restrictToTargetOther() {
1178
-    if($this->dbTargetRow['id'] == $this->getPlayerOwnerId()) {
1178
+    if ($this->dbTargetRow['id'] == $this->getPlayerOwnerId()) {
1179 1179
       throw new Exception('FLIGHT_VECTOR_ONLY_OTHER', FLIGHT_VECTOR_ONLY_OTHER);
1180 1180
     }
1181 1181
   }
1182 1182
 
1183 1183
   public function restrictToNotOnlySpies() {
1184
-    if($this->unitList->unitsCountById(SHIP_SPY) == $this->shipsGetTotal()) {
1184
+    if ($this->unitList->unitsCountById(SHIP_SPY) == $this->shipsGetTotal()) {
1185 1185
       throw new Exception('FLIGHT_SHIPS_NOT_ONLY_SPIES', FLIGHT_SHIPS_NOT_ONLY_SPIES);
1186 1186
     }
1187 1187
   }
1188 1188
 
1189 1189
   protected function restrictToUniverse() {
1190
-    if(!$this->targetVector->isInUniverse()) {
1190
+    if (!$this->targetVector->isInUniverse()) {
1191 1191
       throw new Exception('FLIGHT_VECTOR_BEYOND_UNIVERSE', FLIGHT_VECTOR_BEYOND_UNIVERSE);
1192 1192
     }
1193 1193
   }
1194 1194
 
1195 1195
   protected function restrictToMovable() {
1196
-    if(!$this->unitList->unitsIsAllMovable($this->dbOwnerRow)) {
1196
+    if (!$this->unitList->unitsIsAllMovable($this->dbOwnerRow)) {
1197 1197
       throw new Exception('FLIGHT_SHIPS_UNMOVABLE', FLIGHT_SHIPS_UNMOVABLE);
1198 1198
     }
1199 1199
   }
1200 1200
 
1201 1201
   protected function restrictToFleetUnits() {
1202
-    if(!$this->unitList->unitsInGroup(sn_get_groups(array('fleet', 'missile')))) {
1202
+    if (!$this->unitList->unitsInGroup(sn_get_groups(array('fleet', 'missile')))) {
1203 1203
       throw new Exception('FLIGHT_SHIPS_UNIT_WRONG', FLIGHT_SHIPS_UNIT_WRONG);
1204 1204
     }
1205 1205
   }
1206 1206
 
1207 1207
   protected function restrictToColonizer() {
1208 1208
     // Colonization fleet should have at least one colonizer
1209
-    if(!$this->unitList->unitsCountById(SHIP_COLONIZER) <= 0) {
1209
+    if (!$this->unitList->unitsCountById(SHIP_COLONIZER) <= 0) {
1210 1210
       throw new Exception('FLIGHT_SHIPS_NO_COLONIZER', FLIGHT_SHIPS_NO_COLONIZER);
1211 1211
     }
1212 1212
   }
1213 1213
 
1214 1214
   protected function restrictToTargetExists() {
1215
-    if(empty($this->dbTargetRow) || empty($this->dbTargetRow['id'])) {
1215
+    if (empty($this->dbTargetRow) || empty($this->dbTargetRow['id'])) {
1216 1216
       throw new Exception('FLIGHT_VECTOR_NO_TARGET', FLIGHT_VECTOR_NO_TARGET);
1217 1217
     }
1218 1218
   }
@@ -1220,7 +1220,7 @@  discard block
 block discarded – undo
1220 1220
 
1221 1221
   protected function restrictKnownSpaceOrMissionExplore() {
1222 1222
     // Is it exploration - fleet sent beyond of system?
1223
-    if($this->targetVector->isInKnownSpace()) {
1223
+    if ($this->targetVector->isInKnownSpace()) {
1224 1224
       // No exploration beyond this point
1225 1225
       unset($this->allowed_missions[MT_EXPLORE]);
1226 1226
 
@@ -1238,7 +1238,7 @@  discard block
 block discarded – undo
1238 1238
 
1239 1239
   protected function restrictTargetExistsOrMissionColonize() {
1240 1240
     // Is it colonization - fleet sent to empty place?
1241
-    if(!empty($this->dbTargetRow)) {
1241
+    if (!empty($this->dbTargetRow)) {
1242 1242
       // No colonization beyond this point
1243 1243
       unset($this->allowed_missions[MT_COLONIZE]);
1244 1244
 
@@ -1257,7 +1257,7 @@  discard block
 block discarded – undo
1257 1257
   }
1258 1258
 
1259 1259
   protected function restrictNotDebrisOrMissionRecycle() {
1260
-    if($this->targetVector->type != PT_DEBRIS) {
1260
+    if ($this->targetVector->type != PT_DEBRIS) {
1261 1261
       // No recycling beyond this point
1262 1262
       unset($this->allowed_missions[MT_RECYCLE]);
1263 1263
 
@@ -1268,11 +1268,11 @@  discard block
 block discarded – undo
1268 1268
 
1269 1269
     // restrict to recyclers
1270 1270
     $recyclers = 0;
1271
-    foreach(sn_get_groups('flt_recyclers') as $recycler_id) {
1271
+    foreach (sn_get_groups('flt_recyclers') as $recycler_id) {
1272 1272
       $recyclers += $this->unitList->unitsCountById($recycler_id);
1273 1273
     }
1274 1274
 
1275
-    if($recyclers <= 0) {
1275
+    if ($recyclers <= 0) {
1276 1276
       throw new Exception('FLIGHT_SHIPS_NO_RECYCLERS', FLIGHT_SHIPS_NO_RECYCLERS);
1277 1277
     }
1278 1278
 
@@ -1283,14 +1283,14 @@  discard block
 block discarded – undo
1283 1283
 
1284 1284
   protected function restrictMissionMissile() {
1285 1285
     $missilesAttack = $this->unitList->unitsCountById(UNIT_DEF_MISSILE_INTERPLANET);
1286
-    if($missilesAttack <= 0) {
1286
+    if ($missilesAttack <= 0) {
1287 1287
       // No missile attack beyond this point
1288 1288
       unset($this->allowed_missions[MT_MISSILE]);
1289 1289
 
1290 1290
       return;
1291 1291
     }
1292 1292
 
1293
-    if($missilesAttack != $this->shipsGetTotal()) {
1293
+    if ($missilesAttack != $this->shipsGetTotal()) {
1294 1294
       throw new Exception('FLIGHT_SHIPS_ONLY_MISSILES', FLIGHT_SHIPS_ONLY_MISSILES);
1295 1295
     }
1296 1296
 
@@ -1302,7 +1302,7 @@  discard block
 block discarded – undo
1302 1302
   }
1303 1303
 
1304 1304
   protected function restrictToNotOnlySpiesOrMissionSpy() {
1305
-    if($this->unitList->unitsCountById(SHIP_SPY) != $this->shipsGetTotal()) {
1305
+    if ($this->unitList->unitsCountById(SHIP_SPY) != $this->shipsGetTotal()) {
1306 1306
 //      throw new Exception('FLIGHT_SHIPS_ONLY_SPIES', FLIGHT_SHIPS_ONLY_SPIES);
1307 1307
       unset($this->allowed_missions[MT_SPY]);
1308 1308
 
@@ -1318,14 +1318,14 @@  discard block
 block discarded – undo
1318 1318
   protected function restrictMissionDestroy() {
1319 1319
     // If target vector is not Moon - then it can't be Destroy mission
1320 1320
     // If no Reapers (i.e. Death Star) in fleet - then mission Moon Destroy is unaccessible
1321
-    if($this->targetVector->type != PT_MOON || $this->unitList->unitsCountById(SHIP_HUGE_DEATH_STAR) <= 0) {
1321
+    if ($this->targetVector->type != PT_MOON || $this->unitList->unitsCountById(SHIP_HUGE_DEATH_STAR) <= 0) {
1322 1322
       unset($this->allowed_missions[MT_DESTROY]);
1323 1323
     }
1324 1324
   }
1325 1325
 
1326 1326
   protected function restrictMissionACS() {
1327 1327
     // If no ACS group is shown - then it can't be an ACS attack
1328
-    if(empty($this->_group_id)) {
1328
+    if (empty($this->_group_id)) {
1329 1329
       unset($this->allowed_missions[MT_ACS]);
1330 1330
     }
1331 1331
   }
@@ -1333,7 +1333,7 @@  discard block
 block discarded – undo
1333 1333
   /** @throws Exception */
1334 1334
   protected function restrictFriendOrFoe() {
1335 1335
     // Checking target owner
1336
-    if($this->dbTargetRow['id'] == $this->getPlayerOwnerId()) {
1336
+    if ($this->dbTargetRow['id'] == $this->getPlayerOwnerId()) {
1337 1337
       // Spying can't be done on owner's planet/moon
1338 1338
       unset($this->allowed_missions[MT_SPY]);
1339 1339
       // Attack can't be done on owner's planet/moon
@@ -1389,67 +1389,67 @@  discard block
 block discarded – undo
1389 1389
   }
1390 1390
 
1391 1391
   protected function restrictToNotSource() {
1392
-    if($this->targetVector->isEqualToPlanet($this->dbSourcePlanetRow)) {
1392
+    if ($this->targetVector->isEqualToPlanet($this->dbSourcePlanetRow)) {
1393 1393
       throw new Exception('FLIGHT_VECTOR_SAME_SOURCE', FLIGHT_VECTOR_SAME_SOURCE);
1394 1394
     }
1395 1395
   }
1396 1396
 
1397 1397
   protected function restrictToNonVacationSender() {
1398
-    if(!empty($this->dbOwnerRow['vacation']) && $this->dbOwnerRow['vacation'] >= SN_TIME_NOW) {
1398
+    if (!empty($this->dbOwnerRow['vacation']) && $this->dbOwnerRow['vacation'] >= SN_TIME_NOW) {
1399 1399
       throw new Exception('FLIGHT_PLAYER_VACATION_OWN', FLIGHT_PLAYER_VACATION_OWN);
1400 1400
     }
1401 1401
   }
1402 1402
 
1403 1403
   protected function restrictToValidSpeedPercentOld() {
1404
-    if(!$this->unitList->shipsIsEnoughOnPlanet($this->dbSourcePlanetRow)) {
1404
+    if (!$this->unitList->shipsIsEnoughOnPlanet($this->dbSourcePlanetRow)) {
1405 1405
     }
1406 1406
 
1407 1407
     $speed_possible = array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1);
1408
-    if(!in_array($this->oldSpeedInTens, $speed_possible)) {
1408
+    if (!in_array($this->oldSpeedInTens, $speed_possible)) {
1409 1409
       throw new Exception('FLIGHT_FLEET_SPEED_WRONG', FLIGHT_FLEET_SPEED_WRONG);
1410 1410
     }
1411 1411
 
1412 1412
   }
1413 1413
 
1414 1414
   protected function restrict2ToAllowedMissions() {
1415
-    if(empty($this->allowed_missions[$this->_mission_type])) {
1415
+    if (empty($this->allowed_missions[$this->_mission_type])) {
1416 1416
       throw new Exception('FLIGHT_MISSION_IMPOSSIBLE', FLIGHT_MISSION_IMPOSSIBLE);
1417 1417
     }
1418 1418
   }
1419 1419
 
1420 1420
   protected function restrict2ToAllowedPlanetTypes() {
1421
-    if(empty($this->allowed_planet_types[$this->targetVector->type])) {
1421
+    if (empty($this->allowed_planet_types[$this->targetVector->type])) {
1422 1422
       throw new Exception('FLIGHT_MISSION_IMPOSSIBLE', FLIGHT_MISSION_IMPOSSIBLE);
1423 1423
     }
1424 1424
   }
1425 1425
 
1426 1426
   protected function restrict2ToMaxFleets() {
1427
-    if(FleetList::fleet_count_flying($this->getPlayerOwnerId()) >= GetMaxFleets($this->dbOwnerRow)) {
1427
+    if (FleetList::fleet_count_flying($this->getPlayerOwnerId()) >= GetMaxFleets($this->dbOwnerRow)) {
1428 1428
       throw new Exception('FLIGHT_FLEET_NO_SLOTS', FLIGHT_FLEET_NO_SLOTS);
1429 1429
     }
1430 1430
   }
1431 1431
 
1432 1432
   protected function restrict2ToEnoughShips() {
1433
-    if(!$this->unitList->shipsIsEnoughOnPlanet($this->dbSourcePlanetRow)) {
1433
+    if (!$this->unitList->shipsIsEnoughOnPlanet($this->dbSourcePlanetRow)) {
1434 1434
       throw new Exception('FLIGHT_SHIPS_NOT_ENOUGH', FLIGHT_SHIPS_NOT_ENOUGH);
1435 1435
     }
1436 1436
   }
1437 1437
 
1438 1438
   protected function restrict2ToEnoughCapacity($fleetCapacity, $fleetConsumption, $fleetResources) {
1439
-    if(floor($fleetCapacity) < ceil(array_sum($fleetResources) + $fleetConsumption)) {
1439
+    if (floor($fleetCapacity) < ceil(array_sum($fleetResources) + $fleetConsumption)) {
1440 1440
       throw new Exception('FLIGHT_FLEET_OVERLOAD', FLIGHT_FLEET_OVERLOAD);
1441 1441
     }
1442 1442
   }
1443 1443
 
1444 1444
   protected function restrict2ByResources($fleetConsumption, $fleetResources) {
1445 1445
     $fleetResources[RES_DEUTERIUM] = ceil($fleetResources[RES_DEUTERIUM] + $fleetConsumption);
1446
-    foreach($fleetResources as $resourceId => $resourceAmount) {
1447
-      if($fleetResources[$resourceId] < 0) {
1446
+    foreach ($fleetResources as $resourceId => $resourceAmount) {
1447
+      if ($fleetResources[$resourceId] < 0) {
1448 1448
         throw new Exception('FLIGHT_RESOURCES_NEGATIVE', FLIGHT_RESOURCES_NEGATIVE);
1449 1449
       }
1450 1450
 
1451
-      if(mrc_get_level($this->dbOwnerRow, $this->dbSourcePlanetRow, $resourceId) < ceil($fleetResources[$resourceId])) {
1452
-        if($resourceId == RES_DEUTERIUM) {
1451
+      if (mrc_get_level($this->dbOwnerRow, $this->dbSourcePlanetRow, $resourceId) < ceil($fleetResources[$resourceId])) {
1452
+        if ($resourceId == RES_DEUTERIUM) {
1453 1453
           throw new Exception('FLIGHT_RESOURCES_FUEL_NOT_ENOUGH', FLIGHT_RESOURCES_FUEL_NOT_ENOUGH);
1454 1454
         } else {
1455 1455
           throw new Exception('FLIGHT_RESOURCES_NOT_ENOUGH', FLIGHT_RESOURCES_NOT_ENOUGH);
@@ -1502,7 +1502,7 @@  discard block
 block discarded – undo
1502 1502
 
1503 1503
 
1504 1504
   protected function printErrorIfNoShips() {
1505
-    if($this->unitList->unitsCount() <= 0) {
1505
+    if ($this->unitList->unitsCount() <= 0) {
1506 1506
       message(classLocale::$lang['fl_err_no_ships'], classLocale::$lang['fl_error'], 'fleet' . DOT_PHP_EX, 5);
1507 1507
     }
1508 1508
   }
@@ -1540,10 +1540,10 @@  discard block
 block discarded – undo
1540 1540
   protected function renderAllowedMissions(&$template_result) {
1541 1541
     ksort($this->allowed_missions);
1542 1542
     // If mission is not set - setting first mission from allowed
1543
-    if(empty($this->_mission_type) && is_array($this->allowed_missions)) {
1543
+    if (empty($this->_mission_type) && is_array($this->allowed_missions)) {
1544 1544
       $this->_mission_type = reset($this->allowed_missions);
1545 1545
     }
1546
-    foreach($this->allowed_missions as $key => $value) {
1546
+    foreach ($this->allowed_missions as $key => $value) {
1547 1547
       $template_result['.']['missions'][] = array(
1548 1548
         'ID'   => $key,
1549 1549
         'NAME' => classLocale::$lang['type_mission'][$key],
@@ -1555,9 +1555,9 @@  discard block
 block discarded – undo
1555 1555
    * @param $template_result
1556 1556
    */
1557 1557
   protected function renderDuration(&$template_result, $max_duration) {
1558
-    if($max_duration) {
1558
+    if ($max_duration) {
1559 1559
       $config_game_speed_expedition = ($this->_mission_type == MT_EXPLORE && classSupernova::$config->game_speed_expedition ? classSupernova::$config->game_speed_expedition : 1);
1560
-      for($i = 1; $i <= $max_duration; $i++) {
1560
+      for ($i = 1; $i <= $max_duration; $i++) {
1561 1561
         $template_result['.']['duration'][] = array(
1562 1562
           'ID'   => $i,
1563 1563
           'TIME' => pretty_time(ceil($i * 3600 / $config_game_speed_expedition)),
@@ -1573,7 +1573,7 @@  discard block
 block discarded – undo
1573 1573
   protected function renderPlanetResources(&$planetResources, &$template_result) {
1574 1574
     // TODO - REDO to resource_id
1575 1575
     $i = 0;
1576
-    foreach($planetResources as $resource_id => $resource_amount) {
1576
+    foreach ($planetResources as $resource_id => $resource_amount) {
1577 1577
       $template_result['.']['resources'][] = array(
1578 1578
         'ID'        => $i++, // $resource_id,
1579 1579
         'ON_PLANET' => $resource_amount,
@@ -1587,7 +1587,7 @@  discard block
 block discarded – undo
1587 1587
    * @param $template_result
1588 1588
    */
1589 1589
   protected function renderAllowedPlanetTypes(&$template_result) {
1590
-    foreach($this->allowed_planet_types as $possible_planet_type_id) {
1590
+    foreach ($this->allowed_planet_types as $possible_planet_type_id) {
1591 1591
       $template_result['.']['possible_planet_type_id'][] = array(
1592 1592
         'ID'         => $possible_planet_type_id,
1593 1593
         'NAME'       => classLocale::$lang['sys_planet_type'][$possible_planet_type_id],
@@ -1610,14 +1610,14 @@  discard block
 block discarded – undo
1610 1610
       'TYPE_PRINT' => classLocale::$lang['fl_shrtcup'][$shortcut['planet_type']],
1611 1611
     );
1612 1612
 
1613
-    if(isset($shortcut['priority'])) {
1613
+    if (isset($shortcut['priority'])) {
1614 1614
       $result += array(
1615 1615
         'PRIORITY'       => $shortcut['priority'],
1616 1616
         'PRIORITY_CLASS' => $note_priority_classes[$shortcut['priority']],
1617 1617
       );
1618 1618
     }
1619 1619
 
1620
-    if(isset($shortcut['id'])) {
1620
+    if (isset($shortcut['id'])) {
1621 1621
       $result += array(
1622 1622
         'ID' => $shortcut['id'],
1623 1623
       );
@@ -1632,7 +1632,7 @@  discard block
 block discarded – undo
1632 1632
   protected function renderFleetShortcuts(&$template_result) {
1633 1633
     // Building list of shortcuts
1634 1634
     $query = db_note_list_select_by_owner_and_planet($this->dbOwnerRow);
1635
-    while($row = db_fetch($query)) {
1635
+    while ($row = db_fetch($query)) {
1636 1636
       $template_result['.']['shortcut'][] = $this->renderFleet1TargetSelect($row);
1637 1637
     }
1638 1638
   }
@@ -1644,12 +1644,12 @@  discard block
 block discarded – undo
1644 1644
    */
1645 1645
   protected function renderOwnPlanets(&$template_result) {
1646 1646
     $colonies = db_planet_list_sorted($this->dbOwnerRow);
1647
-    if(count($colonies) <= 1) {
1647
+    if (count($colonies) <= 1) {
1648 1648
       return;
1649 1649
     }
1650 1650
 
1651
-    foreach($colonies as $row) {
1652
-      if($row['id'] == $this->dbSourcePlanetRow['id']) {
1651
+    foreach ($colonies as $row) {
1652
+      if ($row['id'] == $this->dbSourcePlanetRow['id']) {
1653 1653
         continue;
1654 1654
       }
1655 1655
 
@@ -1662,10 +1662,10 @@  discard block
 block discarded – undo
1662 1662
    */
1663 1663
   protected function renderACSList(&$template_result) {
1664 1664
     $query = db_acs_get_list();
1665
-    while($row = db_fetch($query)) {
1665
+    while ($row = db_fetch($query)) {
1666 1666
       $members = explode(',', $row['eingeladen']);
1667
-      foreach($members as $a => $b) {
1668
-        if($b == $this->dbOwnerRow['id']) {
1667
+      foreach ($members as $a => $b) {
1668
+        if ($b == $this->dbOwnerRow['id']) {
1669 1669
           $template_result['.']['acss'][] = $this->renderFleet1TargetSelect($row);
1670 1670
         }
1671 1671
       }
@@ -1676,7 +1676,7 @@  discard block
 block discarded – undo
1676 1676
    * @param $template_result
1677 1677
    */
1678 1678
   protected function renderShipSortOptions(&$template_result) {
1679
-    foreach(classLocale::$lang['player_option_fleet_ship_sort'] as $sort_id => $sort_text) {
1679
+    foreach (classLocale::$lang['player_option_fleet_ship_sort'] as $sort_id => $sort_text) {
1680 1680
       $template_result['.']['ship_sort_list'][] = array(
1681 1681
         'VALUE' => $sort_id,
1682 1682
         'TEXT'  => $sort_text,
@@ -1695,7 +1695,7 @@  discard block
 block discarded – undo
1695 1695
 
1696 1696
     lng_include('overview');
1697 1697
 
1698
-    if(empty($this->dbSourcePlanetRow)) {
1698
+    if (empty($this->dbSourcePlanetRow)) {
1699 1699
       message(classLocale::$lang['fl_noplanetrow'], classLocale::$lang['fl_error']);
1700 1700
     }
1701 1701
 
@@ -1771,9 +1771,9 @@  discard block
 block discarded – undo
1771 1771
 
1772 1772
     try {
1773 1773
       $this->restrictMission();
1774
-    } catch(Exception $e) {
1774
+    } catch (Exception $e) {
1775 1775
       // TODO - MESSAGE BOX
1776
-      if($e->getCode() != FLIGHT_ALLOWED) {
1776
+      if ($e->getCode() != FLIGHT_ALLOWED) {
1777 1777
         pdie(classLocale::$lang['fl_attack_error'][$e->getCode()]);
1778 1778
       } else {
1779 1779
         pdump('FLIGHT_ALLOWED', FLIGHT_ALLOWED);
@@ -1783,20 +1783,19 @@  discard block
 block discarded – undo
1783 1783
     $this->renderAllowedMissions($template_result);
1784 1784
     $this->renderFleet($template_result);
1785 1785
 
1786
-    $max_duration = $this->_mission_type == MT_EXPLORE ? get_player_max_expedition_duration($this->dbOwnerRow) :
1787
-      (isset($this->allowed_missions[MT_HOLD]) ? 12 : 0);
1786
+    $max_duration = $this->_mission_type == MT_EXPLORE ? get_player_max_expedition_duration($this->dbOwnerRow) : (isset($this->allowed_missions[MT_HOLD]) ? 12 : 0);
1788 1787
     $this->renderDuration($template_result, $max_duration);
1789 1788
 
1790 1789
     $travel_data = $this->flt_travel_data($this->oldSpeedInTens);
1791 1790
 
1792 1791
     $sn_group_resources = sn_get_groups('resources_loot');
1793 1792
     $planetResources = array();
1794
-    foreach($sn_group_resources as $resource_id) {
1793
+    foreach ($sn_group_resources as $resource_id) {
1795 1794
       $planetResources[$resource_id] = floor(mrc_get_level($this->dbOwnerRow, $this->dbSourcePlanetRow, $resource_id) - ($resource_id == RES_DEUTERIUM ? $travel_data['consumption'] : 0));
1796 1795
     }
1797 1796
     $this->renderPlanetResources($planetResources, $template_result);
1798 1797
 
1799
-    if(sn_module::$sn_module['unit_captain']->manifest['active'] && ($captain = sn_module::$sn_module['unit_captain']->unit_captain_get($this->dbSourcePlanetRow['id'])) && $captain['unit_location_type'] == LOC_PLANET) {
1798
+    if (sn_module::$sn_module['unit_captain']->manifest['active'] && ($captain = sn_module::$sn_module['unit_captain']->unit_captain_get($this->dbSourcePlanetRow['id'])) && $captain['unit_location_type'] == LOC_PLANET) {
1800 1799
       $template_result += array(
1801 1800
         'CAPTAIN_ID'     => $captain['unit_id'],
1802 1801
         'CAPTAIN_LEVEL'  => $captain['captain_level'],
@@ -1832,24 +1831,24 @@  discard block
 block discarded – undo
1832 1831
 
1833 1832
 
1834 1833
   public function restrict2MissionTransportWithResources($fleetResources) {
1835
-    if($this->_mission_type != MT_TRANSPORT ) {
1834
+    if ($this->_mission_type != MT_TRANSPORT) {
1836 1835
       return;
1837 1836
     }
1838 1837
 
1839
-    if(array_sum($fleetResources) <= 0) {
1838
+    if (array_sum($fleetResources) <= 0) {
1840 1839
       throw new Exception('FLIGHT_RESOURCES_EMPTY', FLIGHT_RESOURCES_EMPTY);
1841 1840
     }
1842 1841
   }
1843 1842
 
1844 1843
   protected function restrict2MissionExploreAvailable() {
1845
-    if($this->_mission_type != MT_EXPLORE) {
1844
+    if ($this->_mission_type != MT_EXPLORE) {
1846 1845
       return;
1847 1846
     }
1848 1847
 
1849
-    if(($expeditionsMax = get_player_max_expeditons($this->dbOwnerRow)) <= 0) {
1848
+    if (($expeditionsMax = get_player_max_expeditons($this->dbOwnerRow)) <= 0) {
1850 1849
       throw new Exception('FLIGHT_MISSION_EXPLORE_NO_ASTROTECH', FLIGHT_MISSION_EXPLORE_NO_ASTROTECH);
1851 1850
     }
1852
-    if(FleetList::fleet_count_flying($this->getPlayerOwnerId(), MT_EXPLORE) >= $expeditionsMax) {
1851
+    if (FleetList::fleet_count_flying($this->getPlayerOwnerId(), MT_EXPLORE) >= $expeditionsMax) {
1853 1852
       throw new Exception('FLIGHT_MISSION_EXPLORE_NO_SLOTS', FLIGHT_MISSION_EXPLORE_NO_SLOTS);
1854 1853
     }
1855 1854
 
@@ -1874,10 +1873,10 @@  discard block
 block discarded – undo
1874 1873
 
1875 1874
     $this->dbOwnerRow = db_user_by_id($this->dbOwnerRow['id'], true);
1876 1875
     $this->dbSourcePlanetRow = db_planet_by_id($this->dbSourcePlanetRow['id'], true);
1877
-    if(!empty($this->dbTargetRow['id'])) {
1876
+    if (!empty($this->dbTargetRow['id'])) {
1878 1877
       $this->dbTargetRow = db_planet_by_id($this->dbTargetRow['id'], true);
1879 1878
     }
1880
-    if(!empty($this->dbTargetRow['id_owner'])) {
1879
+    if (!empty($this->dbTargetRow['id_owner'])) {
1881 1880
       $this->dbTargetOwnerRow = db_planet_by_id($this->dbTargetRow['id_owner'], true);
1882 1881
     }
1883 1882
 
@@ -1917,9 +1916,9 @@  discard block
 block discarded – undo
1917 1916
 
1918 1917
         // TODO  - ALL OF THE ABOVE!
1919 1918
         $this->restrictMission();
1920
-      } catch(Exception $e) {
1919
+      } catch (Exception $e) {
1921 1920
         // If mission is restricted - rethrow exception
1922
-        if($e->getCode() != FLIGHT_ALLOWED) {
1921
+        if ($e->getCode() != FLIGHT_ALLOWED) {
1923 1922
           throw new Exception($e->getMessage(), $e->getCode());
1924 1923
         }
1925 1924
       }
@@ -1964,7 +1963,7 @@  discard block
 block discarded – undo
1964 1963
       $this->restrictTargetExistsOrMissionColonize();
1965 1964
       $this->restrictNotDebrisOrMissionRecycle();
1966 1965
       // TODO - START $this->restrictFriendOrFoe();
1967
-      if($this->dbTargetRow['id'] == $this->getPlayerOwnerId()) {
1966
+      if ($this->dbTargetRow['id'] == $this->getPlayerOwnerId()) {
1968 1967
         // Spying can't be done on owner's planet/moon
1969 1968
         unset($this->allowed_missions[MT_SPY]);
1970 1969
         // Attack can't be done on owner's planet/moon
@@ -2041,9 +2040,9 @@  discard block
 block discarded – undo
2041 2040
 
2042 2041
 
2043 2042
       $this->restrict2MissionTransportWithResources($fleetResources);
2044
-    } catch(Exception $e) {
2043
+    } catch (Exception $e) {
2045 2044
       // TODO - MESSAGE BOX
2046
-      if($e->getCode() != FLIGHT_ALLOWED) {
2045
+      if ($e->getCode() != FLIGHT_ALLOWED) {
2047 2046
         sn_db_transaction_rollback();
2048 2047
         pdie(classLocale::$lang['fl_attack_error'][$e->getCode()]);
2049 2048
       } else {
@@ -2060,47 +2059,47 @@  discard block
 block discarded – undo
2060 2059
     $TransDeuterium = max(0, floor(sys_get_param_float('resource2')));
2061 2060
     $StorageNeeded = $TransMetal + $TransCrystal + $TransDeuterium;
2062 2061
 
2063
-    if(!$StorageNeeded && $target_mission == MT_TRANSPORT) {
2062
+    if (!$StorageNeeded && $target_mission == MT_TRANSPORT) {
2064 2063
       $errorlist .= classLocale::$lang['fl_noenoughtgoods'];
2065 2064
     }
2066 2065
 
2067 2066
 
2068 2067
 
2069
-    if($target_mission == MT_EXPLORE) {
2070
-      if($MaxExpeditions == 0) {
2068
+    if ($target_mission == MT_EXPLORE) {
2069
+      if ($MaxExpeditions == 0) {
2071 2070
         $errorlist .= classLocale::$lang['fl_expe_notech'];
2072
-      } elseif($FlyingExpeditions >= $MaxExpeditions) {
2071
+      } elseif ($FlyingExpeditions >= $MaxExpeditions) {
2073 2072
         $errorlist .= classLocale::$lang['fl_expe_max'];
2074 2073
       }
2075 2074
     } else {
2076
-      if($TargetPlanet['id_owner']) {
2077
-        if($target_mission == MT_COLONIZE) {
2075
+      if ($TargetPlanet['id_owner']) {
2076
+        if ($target_mission == MT_COLONIZE) {
2078 2077
           $errorlist .= classLocale::$lang['fl_colonized'];
2079 2078
         }
2080 2079
 
2081
-        if($TargetPlanet['id_owner'] == $planetrow['id_owner']) {
2082
-          if($target_mission == MT_ATTACK) {
2080
+        if ($TargetPlanet['id_owner'] == $planetrow['id_owner']) {
2081
+          if ($target_mission == MT_ATTACK) {
2083 2082
             $errorlist .= classLocale::$lang['fl_no_self_attack'];
2084 2083
           }
2085 2084
 
2086
-          if($target_mission == MT_SPY) {
2085
+          if ($target_mission == MT_SPY) {
2087 2086
             $errorlist .= classLocale::$lang['fl_no_self_spy'];
2088 2087
           }
2089 2088
         } else {
2090
-          if($target_mission == MT_RELOCATE) {
2089
+          if ($target_mission == MT_RELOCATE) {
2091 2090
             $errorlist .= classLocale::$lang['fl_only_stay_at_home'];
2092 2091
           }
2093 2092
         }
2094 2093
       } else {
2095
-        if($target_mission < MT_COLONIZE) {
2094
+        if ($target_mission < MT_COLONIZE) {
2096 2095
           $errorlist .= classLocale::$lang['fl_unknow_target'];
2097 2096
         } else {
2098 2097
 //          if($target_mission == MT_DESTROY) {
2099 2098
 //            $errorlist .= classLocale::$lang['fl_nomoon'];
2100 2099
 //          }
2101 2100
 
2102
-          if($target_mission == MT_RECYCLE) {
2103
-            if($TargetPlanet['debris_metal'] + $TargetPlanet['debris_crystal'] == 0) {
2101
+          if ($target_mission == MT_RECYCLE) {
2102
+            if ($TargetPlanet['debris_metal'] + $TargetPlanet['debris_crystal'] == 0) {
2104 2103
               $errorlist .= classLocale::$lang['fl_nodebris'];
2105 2104
             }
2106 2105
           }
@@ -2109,12 +2108,12 @@  discard block
 block discarded – undo
2109 2108
     }
2110 2109
 
2111 2110
 
2112
-    if(sn_module::$sn_module['unit_captain']->manifest['active'] && $captain_id = sys_get_param_id('captain_id')) {
2111
+    if (sn_module::$sn_module['unit_captain']->manifest['active'] && $captain_id = sys_get_param_id('captain_id')) {
2113 2112
       $captain = sn_module::$sn_module['unit_captain']->unit_captain_get($planetrow['id']);
2114
-      if(!$captain) {
2113
+      if (!$captain) {
2115 2114
         $errorlist .= classLocale::$lang['module_unit_captain_error_no_captain'];
2116
-      } elseif($captain['unit_location_type'] == LOC_PLANET) {
2117
-        if($target_mission == MT_RELOCATE && ($arriving_captain = mrc_get_level($user, $TargetPlanet, UNIT_CAPTAIN, true))) {
2115
+      } elseif ($captain['unit_location_type'] == LOC_PLANET) {
2116
+        if ($target_mission == MT_RELOCATE && ($arriving_captain = mrc_get_level($user, $TargetPlanet, UNIT_CAPTAIN, true))) {
2118 2117
           $errorlist .= classLocale::$lang['module_unit_captain_error_captain_already_bound'];
2119 2118
         }
2120 2119
       } else {
@@ -2122,7 +2121,7 @@  discard block
 block discarded – undo
2122 2121
       }
2123 2122
     }
2124 2123
 
2125
-    if($errorlist) {
2124
+    if ($errorlist) {
2126 2125
       sn_db_transaction_rollback();
2127 2126
       message("<span class='error'><ul>{$errorlist}</ul></span>", classLocale::$lang['fl_error'], 'fleet' . DOT_PHP_EX, false);
2128 2127
     }
@@ -2133,10 +2132,10 @@  discard block
 block discarded – undo
2133 2132
     //But is it acs??
2134 2133
     //Well all acs fleets must have a fleet code.
2135 2134
     //The co-ords must be the same as where the acs fleet is going.
2136
-    if($fleet_group && sys_get_param_str('acs_target_mr') == "g{$galaxy}s{$system}p{$planet}t{$planet_type}") {
2135
+    if ($fleet_group && sys_get_param_str('acs_target_mr') == "g{$galaxy}s{$system}p{$planet}t{$planet_type}") {
2137 2136
       //ACS attack must exist (if acs fleet has arrived this will also return false (2 checks in 1!!!)
2138 2137
       $aks = db_acs_get_by_group_id($fleet_group);
2139
-      if(!$aks) {
2138
+      if (!$aks) {
2140 2139
         $fleet_group = 0;
2141 2140
       } else {
2142 2141
         //Also it must be mission type 2
@@ -2147,26 +2146,26 @@  discard block
 block discarded – undo
2147 2146
         $planet = $aks['planet'];
2148 2147
         $planet_type = $aks['planet_type'];
2149 2148
       }
2150
-    } elseif($target_mission == MT_ACS) {
2149
+    } elseif ($target_mission == MT_ACS) {
2151 2150
       //Check that a failed acs attack isn't being sent, if it is, make it an attack fleet.
2152 2151
       $target_mission = MT_ATTACK;
2153 2152
     }
2154 2153
 
2155
-    if($target_mission == MT_COLONIZE || $target_mission == MT_EXPLORE) {
2154
+    if ($target_mission == MT_COLONIZE || $target_mission == MT_EXPLORE) {
2156 2155
       $TargetPlanet = array('galaxy' => $galaxy, 'system' => $system, 'planet' => $planet, 'id_owner' => 0);
2157 2156
     }
2158 2157
     $options = array('fleet_speed_percent' => $speed_percent, 'fleet_group' => $fleet_group, 'resources' => $StorageNeeded);
2159 2158
     $cant_attack = flt_can_attack($planetrow, $TargetPlanet, $fleetarray, $target_mission, $options);
2160 2159
 
2161
-    if($cant_attack !== FLIGHT_ALLOWED) {
2160
+    if ($cant_attack !== FLIGHT_ALLOWED) {
2162 2161
       message("<span class='error'><b>{$classLocale['fl_attack_error'][$cant_attack]}</b></span>", classLocale::$lang['fl_error'], 'fleet' . DOT_PHP_EX, 99);
2163 2162
     }
2164 2163
 
2165 2164
     $mission_time_in_seconds = 0;
2166 2165
     $arrival_time = SN_TIME_NOW + $time_to_travel;
2167
-    if($target_mission == MT_ACS && $aks) {
2166
+    if ($target_mission == MT_ACS && $aks) {
2168 2167
 //    if($fleet_start_time > $aks['ankunft']) {
2169
-      if($arrival_time > $aks['ankunft']) {
2168
+      if ($arrival_time > $aks['ankunft']) {
2170 2169
         message(classLocale::$lang['fl_aks_too_slow'] . 'Fleet arrival: ' . date(FMT_DATE_TIME, $arrival_time) . " AKS arrival: " . date(FMT_DATE_TIME, $aks['ankunft']), classLocale::$lang['fl_error']);
2171 2170
       }
2172 2171
       $group_sync_delta_time = $aks['ankunft'] - $arrival_time;
@@ -2175,11 +2174,11 @@  discard block
 block discarded – undo
2175 2174
       // Set return time to ACS return time + fleet's time to travel
2176 2175
       $return_time = $aks['ankunft'] + $time_to_travel;
2177 2176
     } else {
2178
-      if($target_mission == MT_EXPLORE || $target_mission == MT_HOLD) {
2177
+      if ($target_mission == MT_EXPLORE || $target_mission == MT_HOLD) {
2179 2178
         $max_duration = $target_mission == MT_EXPLORE ? get_player_max_expedition_duration($user) : ($target_mission == MT_HOLD ? 12 : 0);
2180
-        if($max_duration) {
2179
+        if ($max_duration) {
2181 2180
           $mission_time_in_hours = sys_get_param_id('missiontime');
2182
-          if($mission_time_in_hours > $max_duration || $mission_time_in_hours < 1) {
2181
+          if ($mission_time_in_hours > $max_duration || $mission_time_in_hours < 1) {
2183 2182
             $debug->warning('Supplying wrong mission time', 'Hack attempt', 302, array('base_dump' => true));
2184 2183
             die();
2185 2184
           }
@@ -2193,7 +2192,7 @@  discard block
 block discarded – undo
2193 2192
 //    $FleetStorage = 0;
2194 2193
 
2195 2194
     $db_changeset = array();
2196
-    foreach($fleetarray as $Ship => $Count) {
2195
+    foreach ($fleetarray as $Ship => $Count) {
2197 2196
 //      $FleetStorage += get_unit_param($Ship, P_CAPACITY) * $Count;
2198 2197
       $db_changeset['unit'][] = sn_db_unit_changeset_prepare($Ship, -$Count, $user, $planetrow['id']);
2199 2198
     }
@@ -2246,7 +2245,7 @@  discard block
 block discarded – undo
2246 2245
 
2247 2246
     $template = gettemplate('fleet3', true);
2248 2247
 
2249
-    if(is_array($captain)) {
2248
+    if (is_array($captain)) {
2250 2249
       db_unit_set_by_id($captain['unit_id'], "`unit_location_type` = " . LOC_FLEET . ", `unit_location_id` = {$objFleet->dbId}");
2251 2250
     }
2252 2251
 
@@ -2258,7 +2257,7 @@  discard block
 block discarded – undo
2258 2257
       'START_TIME_TEXT'    => date(FMT_DATE_TIME, $return_time + SN_CLIENT_TIME_DIFF),
2259 2258
       'START_LEFT'         => floor($return_time + 1 - SN_TIME_NOW),
2260 2259
     );
2261
-    if(!empty($TargetPlanet)) {
2260
+    if (!empty($TargetPlanet)) {
2262 2261
       $template_route += array(
2263 2262
         'END_TYPE_TEXT_SH' => classLocale::$lang['sys_planet_type_sh'][$TargetPlanet['planet_type']],
2264 2263
         'END_COORDS'       => uni_render_coordinates($TargetPlanet),
@@ -2271,8 +2270,8 @@  discard block
 block discarded – undo
2271 2270
     $template->assign_block_vars('fleets', $template_route);
2272 2271
 
2273 2272
     $sn_groups_fleet = sn_get_groups('fleet');
2274
-    foreach($fleetarray as $ship_id => $ship_count) {
2275
-      if(in_array($ship_id, $sn_groups_fleet) && $ship_count) {
2273
+    foreach ($fleetarray as $ship_id => $ship_count) {
2274
+      if (in_array($ship_id, $sn_groups_fleet) && $ship_count) {
2276 2275
 //      $ship_base_data = get_ship_data($ship_id, $user);
2277 2276
         $template->assign_block_vars('fleets.ships', array(
2278 2277
           'ID'          => $ship_id,
Please login to merge, or discard this patch.