Completed
Push — work-fleets ( 74a0d7...680ce4 )
by SuperNova.WS
05:04
created
includes/db/db_helpers.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -27,19 +27,19 @@
 block discarded – undo
27 27
  */
28 28
 function db_set_make_safe_string($set, $delta = false) {
29 29
   $set_safe = array();
30
-  foreach($set as $field => $value) {
31
-    if(empty($field)) {
30
+  foreach ($set as $field => $value) {
31
+    if (empty($field)) {
32 32
       continue;
33 33
     }
34 34
 
35 35
     $field = '`' . db_escape($field) . '`';
36 36
     $new_value = $value;
37
-    if($value === null) {
37
+    if ($value === null) {
38 38
       $new_value = 'NULL';
39
-    } elseif(is_string($value) && (string)($new_value = floatval($value)) != (string)$value) {
39
+    } elseif (is_string($value) && (string) ($new_value = floatval($value)) != (string) $value) {
40 40
       // non-float
41 41
       $new_value = '"' . db_escape($value) . '"';
42
-    } elseif($delta) {
42
+    } elseif ($delta) {
43 43
       // float and DELTA-set
44 44
       $new_value = "{$field} + ({$new_value})";
45 45
     }
Please login to merge, or discard this patch.
includes/includes/flt_mission_hold.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
  * @copyright 2008 by Gorlum for Project "SuperNova.WS"
11 11
  */
12 12
 function flt_mission_hold($mission_data) {
13
-  if($mission_data->fleet->time_mission_job_complete < SN_TIME_NOW) {
13
+  if ($mission_data->fleet->time_mission_job_complete < SN_TIME_NOW) {
14 14
     $mission_data->fleet->mark_fleet_as_returned_and_save();
15 15
 
16 16
     return CACHE_FLEET;
Please login to merge, or discard this patch.
includes/includes/upd_helpers.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if(!defined('IN_UPDATE')) {
3
+if (!defined('IN_UPDATE')) {
4 4
   die('Trying to call update helpers externally!');
5 5
 }
6 6
 
@@ -8,13 +8,13 @@  discard block
 block discarded – undo
8 8
   global $update_tables;
9 9
 
10 10
   upd_add_more_time();
11
-  if(!$no_log) {
11
+  if (!$no_log) {
12 12
     upd_log_message("Performing query '{$query}'");
13 13
   }
14 14
 
15 15
   // classSupernova::$db->sn_db_connect();
16
-  if(!(strpos($query, '{{') === false)) {
17
-    foreach($update_tables as $tableName => $cork) {
16
+  if (!(strpos($query, '{{') === false)) {
17
+    foreach ($update_tables as $tableName => $cork) {
18 18
       $query = str_replace("{{{$tableName}}}", classSupernova::$db->db_prefix . $tableName, $query);
19 19
     }
20 20
   }
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
   global $config, $sys_log_disabled;
28 28
 
29 29
   $config->db_loadItem($key);
30
-  if($condition || !isset($config->$key)) {
30
+  if ($condition || !isset($config->$key)) {
31 31
     upd_add_more_time();
32
-    if(!$sys_log_disabled) {
32
+    if (!$sys_log_disabled) {
33 33
       upd_log_message("Updating config key '{$key}' with value '{$default_value}'");
34 34
     }
35 35
     $config->db_saveItem($key, $default_value);
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 function upd_log_message($message) {
58 58
   global $sys_log_disabled, $upd_log, $debug;
59 59
 
60
-  if($sys_log_disabled) {
60
+  if ($sys_log_disabled) {
61 61
 //    print("{$message}<br />");
62 62
   } else {
63 63
     $upd_log .= "{$message}\r\n";
@@ -68,15 +68,15 @@  discard block
 block discarded – undo
68 68
 function upd_unset_table_info($table_name) {
69 69
   global $update_tables, $update_indexes, $update_foreigns;
70 70
 
71
-  if(isset($update_tables[$table_name])) {
71
+  if (isset($update_tables[$table_name])) {
72 72
     unset($update_tables[$table_name]);
73 73
   }
74 74
 
75
-  if(isset($update_indexes[$table_name])) {
75
+  if (isset($update_indexes[$table_name])) {
76 76
     unset($update_indexes[$table_name]);
77 77
   }
78 78
 
79
-  if(isset($update_foreigns[$table_name])) {
79
+  if (isset($update_foreigns[$table_name])) {
80 80
     unset($update_foreigns[$table_name]);
81 81
   }
82 82
 }
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
   upd_unset_table_info($tableName);
91 91
 
92 92
   $q1 = upd_do_query("SHOW FULL COLUMNS FROM {$prefix_table_name};", true);
93
-  while($r1 = db_fetch($q1)) {
93
+  while ($r1 = db_fetch($q1)) {
94 94
     $update_tables[$tableName][$r1['Field']] = $r1;
95 95
   }
96 96
 
97 97
   $q1 = upd_do_query("SHOW INDEX FROM {$prefix_table_name};", true);
98
-  while($r1 = db_fetch($q1)) {
98
+  while ($r1 = db_fetch($q1)) {
99 99
     $update_indexes[$tableName][$r1['Key_name']] .= "{$r1['Column_name']},";
100 100
     $update_indexes_full[$tableName][$r1['Key_name']][$r1['Column_name']] = $r1;
101 101
   }
102 102
 
103 103
   $q1 = upd_do_query("SELECT * FROM `information_schema`.`KEY_COLUMN_USAGE` WHERE `TABLE_SCHEMA` = '" . db_escape(classSupernova::$db_name) . "' AND TABLE_NAME = '{$prefix_table_name}' AND REFERENCED_TABLE_NAME is not null;", true);
104
-  while($r1 = db_fetch($q1)) {
104
+  while ($r1 = db_fetch($q1)) {
105 105
     $table_referenced = str_replace($config->db_prefix, '', $r1['REFERENCED_TABLE_NAME']);
106 106
 
107 107
     $update_foreigns[$tableName][$r1['CONSTRAINT_NAME']] .= "{$r1['COLUMN_NAME']},{$table_referenced},{$r1['REFERENCED_COLUMN_NAME']};";
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 function upd_alter_table($table, $alters, $condition = true) {
119 119
   global $config;
120 120
 
121
-  if(!$condition) {
121
+  if (!$condition) {
122 122
     return;
123 123
   }
124 124
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
   $alters_print = is_array($alters) ? dump($alters) : $alters;
127 127
   upd_log_message("Altering table '{$table}' with alterations {$alters_print}");
128 128
 
129
-  if(!is_array($alters)) {
129
+  if (!is_array($alters)) {
130 130
     $alters = array($alters);
131 131
   }
132 132
 
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
   //$result = db_query($qry);
138 138
   $result = upd_do_query($qry);
139 139
   $error = db_error();
140
-  if($error) {
140
+  if ($error) {
141 141
     die("Altering error for table `{$table}`: {$error}<br />{$alters_print}");
142 142
   }
143 143
 
@@ -160,11 +160,11 @@  discard block
 block discarded – undo
160 160
 function upd_create_table($table_name, $declaration) {
161 161
   global $config, $update_tables;
162 162
 
163
-  if(!$update_tables[$table_name]) {
163
+  if (!$update_tables[$table_name]) {
164 164
     upd_do_query('set foreign_key_checks = 0;', true);
165 165
     $result = upd_do_query("CREATE TABLE IF NOT EXISTS `{$config->db_prefix}{$table_name}` {$declaration}");
166 166
     $error = db_error();
167
-    if($error) {
167
+    if ($error) {
168 168
       die("Creating error for table `{$table_name}`: {$error}<br />" . dump($declaration));
169 169
     }
170 170
     upd_do_query('set foreign_key_checks = 1;', true);
@@ -190,14 +190,14 @@  discard block
 block discarded – undo
190 190
 
191 191
 
192 192
 function upd_db_unit_changeset_prepare($unit_id, $unit_value, $user, $planet_id = null) {
193
-  if(!is_array($user)) {
193
+  if (!is_array($user)) {
194 194
     // TODO - remove later
195 195
     print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_unit_changeset_prepare() - USER is not ARRAY</h1>');
196 196
     pdump(debug_backtrace());
197 197
     die('USER is not ARRAY');
198 198
   }
199 199
 
200
-  if(!isset($user['id']) || !$user['id']) {
200
+  if (!isset($user['id']) || !$user['id']) {
201 201
     // TODO - remove later
202 202
     print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_unit_changeset_prepare() - USER[id] пустой</h1>');
203 203
     pdump($user);
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 
213 213
   $db_changeset = array();
214 214
   $temp = upd_db_unit_by_location($user['id'], $unit_location, $location_id, $unit_id, true, 'unit_id');
215
-  if($temp['unit_id']) {
215
+  if ($temp['unit_id']) {
216 216
     // update
217 217
     $db_changeset = array(
218 218
       'action' => SQL_OP_UPDATE,
@@ -257,41 +257,41 @@  discard block
 block discarded – undo
257 257
 
258 258
 
259 259
 function upd_db_changeset_apply($db_changeset) {
260
-  if(!is_array($db_changeset) || empty($db_changeset)) {
260
+  if (!is_array($db_changeset) || empty($db_changeset)) {
261 261
     return;
262 262
   }
263 263
 
264
-  foreach($db_changeset as $table_name => $table_data) {
265
-    foreach($table_data as $record_id => $conditions) {
264
+  foreach ($db_changeset as $table_name => $table_data) {
265
+    foreach ($table_data as $record_id => $conditions) {
266 266
       $where = '';
267
-      if(!empty($conditions['where'])) {
267
+      if (!empty($conditions['where'])) {
268 268
         $where = 'WHERE ' . implode(' AND ', $conditions['where']);
269 269
       }
270 270
 
271 271
       $fields = array();
272
-      if($conditions['fields']) {
273
-        foreach($conditions['fields'] as $field_name => $field_data) {
272
+      if ($conditions['fields']) {
273
+        foreach ($conditions['fields'] as $field_name => $field_data) {
274 274
           $condition = "`{$field_name}` = ";
275 275
           $value = '';
276
-          if($field_data['delta']) {
276
+          if ($field_data['delta']) {
277 277
             $value = "`{$field_name}`" . ($field_data['delta'] >= 0 ? '+' : '') . $field_data['delta'];
278
-          } elseif($field_data['set']) {
278
+          } elseif ($field_data['set']) {
279 279
             $value = (is_string($field_data['set']) ? "'{$field_data['set']}'" : $field_data['set']);
280 280
           }
281
-          if($value) {
281
+          if ($value) {
282 282
             $fields[] = $condition . $value;
283 283
           }
284 284
         }
285 285
       }
286 286
       $fields = implode(',', $fields);
287 287
 
288
-      switch($conditions['action']) {
288
+      switch ($conditions['action']) {
289 289
         case SQL_OP_DELETE:
290 290
           upd_do_query("DELETE FROM {{{$table_name}}} {$where}");
291 291
         break;
292 292
 
293 293
         case SQL_OP_UPDATE:
294
-          if($fields) {
294
+          if ($fields) {
295 295
             /*if($table_name == 'unit')
296 296
             {
297 297
               pdump("UPDATE {{{$table_name}}} SET {$fields} {$where}");
@@ -302,13 +302,13 @@  discard block
 block discarded – undo
302 302
         break;
303 303
 
304 304
         case SQL_OP_INSERT:
305
-          if($fields) {
305
+          if ($fields) {
306 306
             upd_do_query("INSERT INTO {{{$table_name}}} SET {$fields}");
307 307
           }
308 308
         break;
309 309
 
310 310
         case SQL_OP_REPLACE:
311
-          if($fields) {
311
+          if ($fields) {
312 312
             upd_do_query("REPLACE INTO {{{$table_name}}} SET {$fields}");
313 313
           }
314 314
         break;
Please login to merge, or discard this patch.
includes/includes/flt_page4.inc 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if(SN_IN_FLEET !== true) {
3
+if (SN_IN_FLEET !== true) {
4 4
   $debug->error("Attempt to call FLEET page mode {$mode} directly - not from fleet.php", 'Forbidden', 403);
5 5
 }
6 6
 
7 7
 $fleetid = sys_get_param_id('fleetid');
8 8
 
9
-if(!is_numeric($fleetid) || empty($fleetid)) {
9
+if (!is_numeric($fleetid) || empty($fleetid)) {
10 10
   header("Location: fleet.php");
11 11
   exit();
12 12
 }
13 13
 
14 14
 $objFleet = new Fleet();
15 15
 $objFleet->dbLoad($fleetid);
16
-if(!$objFleet->dbId) {
16
+if (!$objFleet->dbId) {
17 17
   message($lang['fl_fleet_not_exists'], $lang['fl_error']);
18 18
 }
19 19
 
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
   message($lang['fl_isback'], $lang['fl_error']);
22 22
 }
23 23
 
24
-if($objFleet->playerOwnerId != $user['id']) {
25
-  $debug->warning($lang['fl_aks_hack_wrong_fleet'],'Wrong Fleet Owner',301);
24
+if ($objFleet->playerOwnerId != $user['id']) {
25
+  $debug->warning($lang['fl_aks_hack_wrong_fleet'], 'Wrong Fleet Owner', 301);
26 26
   message($lang['fl_aks_hack_wrong_fleet'], $lang['fl_error']);
27 27
 }
28 28
 
@@ -32,19 +32,19 @@  discard block
 block discarded – undo
32 32
 
33 33
 !$aks && !$userToAdd_unsafe ? $userToAdd_unsafe = $user['username'] : false;
34 34
 
35
-if($userToAdd_unsafe) {
35
+if ($userToAdd_unsafe) {
36 36
   $userToAdd = db_escape($userToAdd_unsafe);
37 37
   $userToAddID = db_user_by_username($userToAdd_unsafe, false, 'id', true, true);
38 38
   $userToAddID = $userToAddID['id'];
39 39
 
40
-  if($objFleet->target_owner_id == $userToAddID) {
40
+  if ($objFleet->target_owner_id == $userToAddID) {
41 41
     message($lang['flt_aks_player_same'], $lang['fl_error']);
42 42
   }
43 43
 
44
-  if($userToAddID) {
45
-    if(!$aks) {
44
+  if ($userToAddID) {
45
+    if (!$aks) {
46 46
       // No AСS exists - making one
47
-      if(!$objFleet->group_id) {
47
+      if (!$objFleet->group_id) {
48 48
         db_acs_insert($lang, $fleetid, $user, $objFleet);
49 49
 
50 50
         $aks = db_acs_get_by_fleet($fleetid);
@@ -58,26 +58,26 @@  discard block
 block discarded – undo
58 58
 
59 59
     $isUserExists = false;
60 60
     $invited_ar = explode(",", $aks['eingeladen']);
61
-    foreach($invited_ar as $inv) {
61
+    foreach ($invited_ar as $inv) {
62 62
       if ($userToAddID == $inv) {
63 63
         $isUserExists = true;
64 64
       }
65 65
     }
66 66
 
67
-    if(count($invited_ar) >= 5) {
67
+    if (count($invited_ar) >= 5) {
68 68
       message($lang['flt_aks_error_too_much_players'], $lang['fl_error']);
69 69
     }
70 70
 
71
-    if($isUserExists) {
71
+    if ($isUserExists) {
72 72
       $userToAdd_unsafe != $user['username'] ? $add_user_message_mr = sprintf($lang['fl_aks_player_invited_already'], $userToAdd) : false;
73 73
     } else {
74 74
       $add_user_message_mr = sprintf($lang['fl_aks_player_invited'], $userToAdd);
75 75
       db_acs_update($userToAddID, $fleetid)
76
-        or die(sprintf($lang['fl_aks_adding_error'],db_error()));
76
+        or die(sprintf($lang['fl_aks_adding_error'], db_error()));
77 77
       $aks['eingeladen'] .= ',' . $userToAddID;
78 78
     }
79
-    msg_send_simple_message ( $userToAddID, $user['id'], SN_TIME_NOW, MSG_TYPE_COMBAT, $user['username'],
80
-      $lang['fl_aks_invite_message_header'], sprintf( $lang['fl_aks_invite_message'], $user['username']));
79
+    msg_send_simple_message($userToAddID, $user['id'], SN_TIME_NOW, MSG_TYPE_COMBAT, $user['username'],
80
+      $lang['fl_aks_invite_message_header'], sprintf($lang['fl_aks_invite_message'], $user['username']));
81 81
   } else {
82 82
     $add_user_message_mr = sprintf($lang['fl_aks_player_error'], $userToAdd);
83 83
   }
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
   'MISSION_NAME' => $lang['type_mission'][MT_AKS],
92 92
 ));
93 93
 
94
-if($aks['eingeladen'] && is_array($members = classSupernova::db_get_record_list(LOC_USER, "`id` in ({$aks['eingeladen']})")) && !empty($members)) {
95
-  foreach($members as $row) {
94
+if ($aks['eingeladen'] && is_array($members = classSupernova::db_get_record_list(LOC_USER, "`id` in ({$aks['eingeladen']})")) && !empty($members)) {
95
+  foreach ($members as $row) {
96 96
     $template->assign_block_vars('invited', array(
97 97
       'NAME' => $row['username'],
98 98
     ));
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 $fleet_data = tplParseFleetObject($objFleet, $i, $user);
118 118
 
119 119
 $template->assign_block_vars('fleets', $fleet_data['fleet']);
120
-foreach($fleet_data['ships'] as $ship_data) {
120
+foreach ($fleet_data['ships'] as $ship_data) {
121 121
   $template->assign_block_vars('fleets.ships', $ship_data);
122 122
 }
123 123
 
Please login to merge, or discard this patch.
includes/includes/flt_mission_relocate.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 
17 17
   $destination_planet = &$mission_data->dst_planet;
18 18
 
19
-  if(empty($destination_planet['id_owner']) || $objFleet->playerOwnerId != $destination_planet['id_owner']) {
19
+  if (empty($destination_planet['id_owner']) || $objFleet->playerOwnerId != $destination_planet['id_owner']) {
20 20
     $objFleet->mark_fleet_as_returned_and_save();
21 21
 
22 22
     return CACHE_FLEET;
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
       $fleet_resources[RES_DEUTERIUM], $lang['Deuterium']
32 32
     ) . '<br />' . $lang['sys_relocate_mess_user'];
33 33
   $fleet_real_array = $objFleet->get_unit_list();
34
-  foreach($fleet_real_array as $ship_id => $ship_count) {
34
+  foreach ($fleet_real_array as $ship_id => $ship_count) {
35 35
     $Message .= $lang['tech'][$ship_id] . ' - ' . $ship_count . '<br />';
36 36
   }
37 37
   msg_send_simple_message(
Please login to merge, or discard this patch.
includes/includes/flt_mission_transport.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
   $source_planet = &$mission_data->src_planet;
17 17
   $destination_planet = &$mission_data->dst_planet;
18 18
 
19
-  if(!isset($destination_planet['id']) || !$destination_planet['id_owner']) {
19
+  if (!isset($destination_planet['id']) || !$destination_planet['id_owner']) {
20 20
     $objFleet->mark_fleet_as_returned_and_save();
21 21
 
22 22
     return CACHE_FLEET;
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
     $fleet_resources[RES_DEUTERIUM], $lang['Deuterium']);
32 32
   msg_send_simple_message($objFleet->target_owner_id, '', $objFleet->time_arrive_to_target, MSG_TYPE_TRANSPORT, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $Message);
33 33
 
34
-  if($objFleet->target_owner_id <> $objFleet->playerOwnerId) {
34
+  if ($objFleet->target_owner_id <> $objFleet->playerOwnerId) {
35 35
     msg_send_simple_message($objFleet->playerOwnerId, '', $objFleet->time_arrive_to_target, MSG_TYPE_TRANSPORT, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $Message);
36 36
   }
37 37
 
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@
 block discarded – undo
31 31
 /**
32 32
  * Fleet mission "Relocate"
33 33
  *
34
- * @param $mission_data Mission
34
+ * @param Mission $mission_data Mission
35 35
  *
36 36
  * @return int
37 37
  *
Please login to merge, or discard this patch.
includes/includes/flt_mission_recycle.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 
21 21
   $destination_planet = &$mission_data->dst_planet;
22 22
 
23
-  if(empty($destination_planet['id'])) {
23
+  if (empty($destination_planet['id'])) {
24 24
     $objFleet->mark_fleet_as_returned();
25 25
     $objFleet->flush_changes_to_db();
26 26
 
@@ -31,10 +31,10 @@  discard block
 block discarded – undo
31 31
   $OtherFleetCapacity = 0;
32 32
 
33 33
   $fleet_array = $objFleet->get_unit_list();
34
-  foreach($fleet_array as $unit_id => $unit_count) {
35
-    if(in_array($unit_id, sn_get_groups('fleet'))) {
34
+  foreach ($fleet_array as $unit_id => $unit_count) {
35
+    if (in_array($unit_id, sn_get_groups('fleet'))) {
36 36
       $capacity = get_unit_param($unit_id, P_CAPACITY) * $unit_count;
37
-      if(in_array($unit_id, sn_get_groups('flt_recyclers'))) {
37
+      if (in_array($unit_id, sn_get_groups('flt_recyclers'))) {
38 38
         $RecyclerCapacity += $capacity;
39 39
       } else {
40 40
         $OtherFleetCapacity += $capacity;
@@ -43,33 +43,33 @@  discard block
 block discarded – undo
43 43
   }
44 44
 
45 45
   $fleet_resources_amount = $objFleet->get_resources_amount();
46
-  if($fleet_resources_amount > $OtherFleetCapacity) {
46
+  if ($fleet_resources_amount > $OtherFleetCapacity) {
47 47
     // Если во флоте есть другие корабли И количество ресурсов больше, чем их ёмкость трюмов - значит часть этих ресурсов лежит в трюмах переработчиков
48 48
     // Уменьшаем ёмкость переработчиков на указанную величину
49 49
     $RecyclerCapacity -= ($fleet_resources_amount - $OtherFleetCapacity);
50 50
   }
51 51
 
52 52
   $resources_recycled = array();
53
-  if(($destination_planet["debris_metal"] + $destination_planet["debris_crystal"]) <= $RecyclerCapacity) {
53
+  if (($destination_planet["debris_metal"] + $destination_planet["debris_crystal"]) <= $RecyclerCapacity) {
54 54
     $resources_recycled[RES_METAL] = $destination_planet["debris_metal"];
55 55
     $resources_recycled[RES_CRYSTAL] = $destination_planet["debris_crystal"];
56 56
   } else {
57
-    if(($destination_planet["debris_metal"] > $RecyclerCapacity / 2) &&
57
+    if (($destination_planet["debris_metal"] > $RecyclerCapacity / 2) &&
58 58
       ($destination_planet["debris_crystal"] > $RecyclerCapacity / 2)
59 59
     ) {
60 60
       $resources_recycled[RES_METAL] = $RecyclerCapacity / 2;
61 61
       $resources_recycled[RES_CRYSTAL] = $RecyclerCapacity / 2;
62 62
     } else {
63
-      if($destination_planet["debris_metal"] > $destination_planet["debris_crystal"]) {
63
+      if ($destination_planet["debris_metal"] > $destination_planet["debris_crystal"]) {
64 64
         $resources_recycled[RES_CRYSTAL] = $destination_planet["debris_crystal"];
65
-        if($destination_planet["debris_metal"] > ($RecyclerCapacity - $resources_recycled[RES_CRYSTAL])) {
65
+        if ($destination_planet["debris_metal"] > ($RecyclerCapacity - $resources_recycled[RES_CRYSTAL])) {
66 66
           $resources_recycled[RES_METAL] = $RecyclerCapacity - $resources_recycled[RES_CRYSTAL];
67 67
         } else {
68 68
           $resources_recycled[RES_METAL] = $destination_planet["debris_metal"];
69 69
         }
70 70
       } else {
71 71
         $resources_recycled[RES_METAL] = $destination_planet["debris_metal"];
72
-        if($destination_planet["debris_crystal"] > ($RecyclerCapacity - $resources_recycled[RES_METAL])) {
72
+        if ($destination_planet["debris_crystal"] > ($RecyclerCapacity - $resources_recycled[RES_METAL])) {
73 73
           $resources_recycled[RES_CRYSTAL] = $RecyclerCapacity - $resources_recycled[RES_METAL];
74 74
         } else {
75 75
           $resources_recycled[RES_CRYSTAL] = $destination_planet["debris_crystal"];
Please login to merge, or discard this patch.
includes/includes/sys_stat.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -39,23 +39,23 @@  discard block
 block discarded – undo
39 39
 
40 40
   $sta_update_msg = db_escape($sta_update_msg);
41 41
 
42
-  if($next_step) {
42
+  if ($next_step) {
43 43
     $sta_update_step++;
44 44
   }
45 45
   $sta_update_msg = "Update in progress. Step {$sta_update_step}/14: {$sta_update_msg}.";
46 46
 
47 47
   $config->db_saveItem('var_stat_update_msg', $sta_update_msg);
48
-  if($next_step) {
48
+  if ($next_step) {
49 49
     $debug->warning($sta_update_msg, 'Stat update', LOG_INFO_STAT_PROCESS);
50 50
   }
51 51
 }
52 52
 
53 53
 function sys_stat_calculate_flush(&$data, $force = false) {
54
-  if(count($data) < 25 && !$force) {
54
+  if (count($data) < 25 && !$force) {
55 55
     return;
56 56
   }
57 57
 
58
-  if(!empty($data)) {
58
+  if (!empty($data)) {
59 59
     doquery('REPLACE INTO {{statpoints}}
60 60
       (`id_owner`, `id_ally`, `stat_type`, `stat_code`, `tech_points`, `tech_count`, `build_points`, `build_count`,
61 61
        `defs_points`, `defs_count`, `fleet_points`, `fleet_count`, `res_points`, `res_count`, `total_points`,
@@ -95,11 +95,11 @@  discard block
 block discarded – undo
95 95
   $user_list = db_user_list('', true, 'id, dark_matter, metal, crystal, deuterium, user_as_ally, ally_id');
96 96
   $row_num = count($user_list);
97 97
   // while($player = db_fetch($query))
98
-  foreach($user_list as $player) {
99
-    if($i++ % 100 == 0) {
98
+  foreach ($user_list as $player) {
99
+    if ($i++ % 100 == 0) {
100 100
       sta_set_time_limit("calculating players stats (player {$i}/{$row_num})", false);
101 101
     }
102
-    if(array_key_exists($user_id = $player['id'], $user_skip_list)) {
102
+    if (array_key_exists($user_id = $player['id'], $user_skip_list)) {
103 103
       continue;
104 104
     }
105 105
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
     // $points[$user_id][UNIT_RESOURCES] += $resources;
110 110
 
111 111
     // А здесь мы фильтруем пользователей по $user_skip_list - далее не нужно этого делать, потому что
112
-    if(!isset($user_skip_list[$user_id])) {
112
+    if (!isset($user_skip_list[$user_id])) {
113 113
       $user_allies[$user_id] = $player['ally_id'];
114 114
     }
115 115
   }
@@ -123,11 +123,11 @@  discard block
 block discarded – undo
123 123
   $i = 0;
124 124
   $query = db_planet_list_resources_by_owner();
125 125
   $row_num = db_num_rows($query);
126
-  while($planet = db_fetch($query)) {
127
-    if($i++ % 100 == 0) {
126
+  while ($planet = db_fetch($query)) {
127
+    if ($i++ % 100 == 0) {
128 128
       sta_set_time_limit("calculating planets stats (planet {$i}/{$row_num})", false);
129 129
     }
130
-    if(array_key_exists($user_id = $planet['id_owner'], $user_skip_list)) {
130
+    if (array_key_exists($user_id = $planet['id_owner'], $user_skip_list)) {
131 131
       continue;
132 132
     }
133 133
 
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
   $i = 0;
143 143
   $query = FleetList::dbQueryAllId();
144 144
   $row_num = db_num_rows($query);
145
-  while($fleet_row = db_fetch($query)) {
146
-    if($i++ % 100 == 0) {
145
+  while ($fleet_row = db_fetch($query)) {
146
+    if ($i++ % 100 == 0) {
147 147
       sta_set_time_limit("calculating flying fleets stats (fleet {$i}/{$row_num})", false);
148 148
     }
149 149
     $objFleet = new Fleet();
@@ -151,15 +151,15 @@  discard block
 block discarded – undo
151 151
     // К тому же при включённом кэшировании это быстро забъёт кэш холодными данными
152 152
     // $objFleet->_reset();
153 153
     $objFleet->dbRowParse($fleet_row);
154
-    if(array_key_exists($user_id = $objFleet->playerOwnerId, $user_skip_list)) {
154
+    if (array_key_exists($user_id = $objFleet->playerOwnerId, $user_skip_list)) {
155 155
       continue;
156 156
     }
157 157
 
158 158
     $fleet = $objFleet->get_unit_list();
159
-    foreach($fleet as $unit_id => $unit_amount) {
159
+    foreach ($fleet as $unit_id => $unit_amount) {
160 160
       $counts[$user_id][UNIT_SHIPS] += $unit_amount;
161 161
 
162
-      if(!isset($unit_cost_cache[$unit_id][0])) {
162
+      if (!isset($unit_cost_cache[$unit_id][0])) {
163 163
         $unit_cost_cache[$unit_id][0] = get_unit_param($unit_id, P_COST);
164 164
       }
165 165
       $unit_cost_data = &$unit_cost_cache[$unit_id][0];
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
   $i = 0;
180 180
   $query = db_unit_list_stat_calculate();
181 181
   $row_num = db_num_rows($query);
182
-  while($unit = db_fetch($query)) {
183
-    if($i++ % 100 == 0) {
182
+  while ($unit = db_fetch($query)) {
183
+    if ($i++ % 100 == 0) {
184 184
       sta_set_time_limit("calculating unit stats (unit {$i}/{$row_num})", false);
185 185
     }
186
-    if(array_key_exists($user_id = $unit['unit_player_id'], $user_skip_list)) {
186
+    if (array_key_exists($user_id = $unit['unit_player_id'], $user_skip_list)) {
187 187
       continue;
188 188
     }
189 189
 
@@ -197,11 +197,11 @@  discard block
 block discarded – undo
197 197
   $i = 0;
198 198
   $query = db_que_list_stat();
199 199
   $row_num = db_num_rows($query);
200
-  while($que_item = db_fetch($query)) {
201
-    if($i++ % 100 == 0) {
200
+  while ($que_item = db_fetch($query)) {
201
+    if ($i++ % 100 == 0) {
202 202
       sta_set_time_limit("calculating ques stats (que item {$i}/{$row_num})", false);
203 203
     }
204
-    if(array_key_exists($user_id = $que_item['que_player_id'], $user_skip_list)) {
204
+    if (array_key_exists($user_id = $que_item['que_player_id'], $user_skip_list)) {
205 205
       continue;
206 206
     }
207 207
     $que_unit_amount = $que_item['que_unit_amount'];
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 
220 220
   sta_set_time_limit('posting new user stats to DB');
221 221
   $data = array();
222
-  foreach($user_allies as $user_id => $ally_id) {
222
+  foreach ($user_allies as $user_id => $ally_id) {
223 223
     // $counts[UNIT_RESOURCES] дублирует $points[UNIT_RESOURCES], поэтому $points не заполняем, а берем $counts и делим на 1000
224 224
     $points[$user_id][UNIT_RESOURCES] = $counts[$user_id][UNIT_RESOURCES] / 1000;
225 225
     $points[$user_id] = array_map('floor', $points[$user_id]);
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 
276 276
   // Updating player's ranks
277 277
   sta_set_time_limit("updating ranks for players");
278
-  foreach($rankNames as $rankName) {
278
+  foreach ($rankNames as $rankName) {
279 279
     sta_set_time_limit("updating player rank '{$rankName}'", false);
280 280
     doquery($qryResetRowNum);
281 281
     doquery(sprintf($qryFormat, $rankName, 1));
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 
284 284
   sta_set_time_limit("updating ranks for Alliances");
285 285
   // --- Updating Allie's ranks
286
-  foreach($rankNames as $rankName) {
286
+  foreach ($rankNames as $rankName) {
287 287
     sta_set_time_limit("updating Alliances rank '{$rankName}'", false);
288 288
     doquery($qryResetRowNum);
289 289
     doquery(sprintf($qryFormat, $rankName, 2));
Please login to merge, or discard this patch.
includes/classes/UBE/UBEUnit.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
     parent::setUnitId($unitId);
51 51
 
52 52
     // Reset combat stats??
53
-    if($this->_unitId) {
53
+    if ($this->_unitId) {
54 54
       $this->amplify = $this->info[P_AMPLIFY];
55 55
       $this->capacity = $this->info[P_CAPACITY];
56 56
       $this->price[RES_METAL] = $this->info[P_COST][RES_METAL];
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
     $this->bonus_attack = $this->info[P_ATTACK];
73 73
     $this->bonus_shield = $this->info[P_SHIELD];
74 74
     $this->bonus_armor = $this->info[P_ARMOR];
75
-    if(is_object($this->unit_bonus)) {
75
+    if (is_object($this->unit_bonus)) {
76 76
       $this->bonus_attack = floor($this->bonus_attack * $this->unit_bonus->calcBonus(P_ATTACK));
77 77
       $this->bonus_shield = floor($this->bonus_shield * $this->unit_bonus->calcBonus(P_SHIELD));
78 78
       $this->bonus_armor = floor($this->bonus_armor * $this->unit_bonus->calcBonus(P_ARMOR));
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
     $this->randomized_attack = $this->bonus_attack;
81 81
     $this->randomized_shield = $this->bonus_shield;
82 82
     $this->randomized_armor = $this->bonus_armor;
83
-    if(!$is_simulator) {
83
+    if (!$is_simulator) {
84 84
       // TODO - randomize attack if is not simulator
85 85
       $this->randomized_attack = floor($this->bonus_attack * ($is_simulator ? 1 : mt_rand(UBE_RANDOMIZE_FROM, UBE_RANDOMIZE_TO) / 100));
86 86
       $this->randomized_shield = floor($this->bonus_shield * ($is_simulator ? 1 : mt_rand(UBE_RANDOMIZE_FROM, UBE_RANDOMIZE_TO) / 100));
@@ -159,22 +159,22 @@  discard block
 block discarded – undo
159 159
    * @version 2016-02-25 23:42:45 41a4.68
160 160
    */
161 161
   public function restore_unit($is_simulator) {
162
-    if($this->_type != UNIT_DEFENCE || $this->units_lost <= 0) {
162
+    if ($this->_type != UNIT_DEFENCE || $this->units_lost <= 0) {
163 163
       return;
164 164
     }
165 165
 
166
-    if($is_simulator) {
166
+    if ($is_simulator) {
167 167
       $units_giveback = round($this->units_lost * UBE_DEFENCE_RESTORATION_CHANCE_AVG / 100); // for simulation just return 75% of loss
168 168
     } else {
169 169
       // Checking - should we trigger mass-restore
170
-      if($this->units_lost >= UBE_DEFENCE_RESTORATION_MASS_COUNT) {
170
+      if ($this->units_lost >= UBE_DEFENCE_RESTORATION_MASS_COUNT) {
171 171
         // For large amount - mass-restoring defence
172 172
         $units_giveback = round($this->units_lost * mt_rand(UBE_DEFENCE_RESTORATION_CHANCE_MIN, UBE_DEFENCE_RESTORATION_CHANCE_MAX) / 100);
173 173
       } else {
174 174
         // For small amount - restoring defence per single unit
175 175
         $units_giveback = 0;
176
-        for($i = 1; $i <= $this->units_lost; $i++) {
177
-          if(mt_rand(1, 100) <= UBE_DEFENCE_RESTORATION_CHANCE_AVG) {
176
+        for ($i = 1; $i <= $this->units_lost; $i++) {
177
+          if (mt_rand(1, 100) <= UBE_DEFENCE_RESTORATION_CHANCE_AVG) {
178 178
             $units_giveback++;
179 179
           }
180 180
         }
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
    */
194 194
   public function receive_damage($is_simulator) {
195 195
     // TODO - Добавить взрывы от полуповрежденных юнитов - т.е. заранее вычислить из убитых юнитов еще количество убитых умножить на вероятность от структуры
196
-    if($this->_count <= 0) {
196
+    if ($this->_count <= 0) {
197 197
       return;
198 198
     }
199 199
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
     $this->adjustCount(-$units_lost);
217 217
 
218 218
     // Проверяем - не взорвался ли текущий юнит
219
-    while($this->_count > 0 && $this->attack_income > 0) {
219
+    while ($this->_count > 0 && $this->attack_income > 0) {
220 220
       $this->attack_damaged_unit($is_simulator);
221 221
     }
222 222
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
     $armor_left = $this->pool_armor % $this->randomized_armor;
242 242
     // Проверка - не атакуем ли мы целый корабль
243 243
     // Такое может быть, если на прошлой итерации поврежденный корабль был взорван и еще осталась входящяя атака
244
-    if($shield_left == 0 && $armor_left == 0) {
244
+    if ($shield_left == 0 && $armor_left == 0) {
245 245
       $shield_left = $this->randomized_shield;
246 246
       $armor_left = $this->randomized_armor;
247 247
     }
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
     // Вычитаем этот дамадж из щитов пула
256 256
     $this->pool_shield -= $damage_to_shield;
257 257
     // Если весь дамадж был поглощён щитами - выходим
258
-    if($this->attack_income <= 0) {
258
+    if ($this->attack_income <= 0) {
259 259
       return;
260 260
     }
261 261
 
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
     $armor_left -= $damage_to_armor;
273 273
 
274 274
     // Проверяем - осталась ли броня на текущем корабле и вааще
275
-    if($this->pool_armor <= 0 || $armor_left <= 0) {
275
+    if ($this->pool_armor <= 0 || $armor_left <= 0) {
276 276
       // Не осталось - корабль уничтожен
277 277
       $this->adjustCount(-1);
278 278
 
@@ -283,10 +283,10 @@  discard block
 block discarded – undo
283 283
     $armor_left_percent = $armor_left / $this->randomized_armor * 100;
284 284
     // Проверяем % здоровья
285 285
     // TODO - сделать динамический процент для каждого вида юнитов
286
-    if($armor_left_percent <= UBE_CRITICAL_DAMAGE_THRESHOLD) {
286
+    if ($armor_left_percent <= UBE_CRITICAL_DAMAGE_THRESHOLD) {
287 287
       // Дамадж пошёл по структуре. Чем более поврежден юнит - тем больше шансов у него взорваться
288 288
       $random = $is_simulator ? UBE_CRITICAL_DAMAGE_THRESHOLD / 2 : mt_rand(0, 100);
289
-      if($random >= $armor_left_percent) {
289
+      if ($random >= $armor_left_percent) {
290 290
         $this->adjustCount(-1);
291 291
         $this->unit_count_boom++;
292 292
 
Please login to merge, or discard this patch.