Completed
Push — work-fleets ( f3b03d...13a233 )
by SuperNova.WS
05:51
created
includes/db/db_queries_unit.php 2 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -64,11 +64,17 @@
 block discarded – undo
64 64
   return classSupernova::db_upd_record_by_id(LOC_UNIT, $unit_id, $set);
65 65
 }
66 66
 
67
+/**
68
+ * @param string $set
69
+ */
67 70
 function db_unit_set_insert($set)
68 71
 {
69 72
   return classSupernova::db_ins_record(LOC_UNIT, $set);
70 73
 }
71 74
 
75
+/**
76
+ * @param integer $unit_location_type
77
+ */
72 78
 function db_unit_list_delete($user_id = 0, $unit_location_type, $unit_location_id, $unit_snid = 0)
73 79
 {
74 80
   return classSupernova::db_del_record_list(LOC_UNIT,
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -21,13 +21,13 @@  discard block
 block discarded – undo
21 21
 
22 22
 function db_unit_count_by_user_and_type_and_snid($user_id, $unit_type = 0, $unit_snid = 0) {
23 23
   $query = doquery(
24
-    "SELECT unit_snid, sum(unit_level) as `qty`  FROM {{unit}} WHERE `unit_player_id` = {$user_id} " .
25
-    ($unit_type ? "AND `unit_type` = {$unit_type} " : '') .
26
-    ($unit_snid ? "AND `unit_snid` = {$unit_snid} " : '') .
24
+    "SELECT unit_snid, sum(unit_level) as `qty`  FROM {{unit}} WHERE `unit_player_id` = {$user_id} ".
25
+    ($unit_type ? "AND `unit_type` = {$unit_type} " : '').
26
+    ($unit_snid ? "AND `unit_snid` = {$unit_snid} " : '').
27 27
     'GROUP BY `unit_snid`'
28 28
   );
29 29
   $result = array();
30
-  while($row = db_fetch($query)) {
30
+  while ($row = db_fetch($query)) {
31 31
     $result[$row['unit_snid']] = $row;
32 32
   }
33 33
 
@@ -44,8 +44,8 @@  discard block
 block discarded – undo
44 44
     WHERE
45 45
       f.fleet_owner = {$user_id} AND
46 46
       (f.fleet_start_planet_id = {$location_id} OR f.fleet_end_planet_id = {$location_id})
47
-      AND u.unit_snid = {$unit_snid} AND u.`unit_location_type` = " . LOC_FLEET . " AND " . db_unit_time_restrictions() .
48
-    " LIMIT 1" .
47
+      AND u.unit_snid = {$unit_snid} AND u.`unit_location_type` = ".LOC_FLEET." AND ".db_unit_time_restrictions().
48
+    " LIMIT 1".
49 49
     ($for_update ? ' FOR UPDATE' : '')
50 50
   , true);
51 51
 }
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 {
58 58
   return doquery("SELECT DISTINCT unit_location_id AS `id`
59 59
     FROM {{unit}}
60
-    WHERE unit_player_id = {$user_id} AND unit_location_type = " . LOC_PLANET . " AND unit_level > 0 AND unit_snid IN (" . STRUC_LABORATORY . ", " . STRUC_LABORATORY_NANO . ");");
60
+    WHERE unit_player_id = {$user_id} AND unit_location_type = ".LOC_PLANET." AND unit_level > 0 AND unit_snid IN (".STRUC_LABORATORY.", ".STRUC_LABORATORY_NANO.");");
61 61
 }
62 62
 
63 63
 function db_unit_set_by_id($unit_id, $set)
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 function db_unit_list_delete($user_id = 0, $unit_location_type, $unit_location_id, $unit_snid = 0)
79 79
 {
80 80
   return classSupernova::db_del_record_list(LOC_UNIT,
81
-    "`unit_location_type` = {$unit_location_type} AND `unit_location_id` = {$unit_location_id}" .
82
-    ($user_id = idval($user_id) ? " AND `unit_player_id` = {$user_id}" : '') .
81
+    "`unit_location_type` = {$unit_location_type} AND `unit_location_id` = {$unit_location_id}".
82
+    ($user_id = idval($user_id) ? " AND `unit_player_id` = {$user_id}" : '').
83 83
     ($unit_snid = idval($unit_snid) ? " AND `unit_snid` = {$unit_snid}" : ''));
84 84
 }
85 85
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
   return doquery(
91 91
     "SELECT unit_player_id, unit_type, unit_snid, unit_level, count(*) AS unit_amount
92 92
     FROM `{{unit}}`
93
-    WHERE unit_level > 0 AND " . db_unit_time_restrictions() .
93
+    WHERE unit_level > 0 AND " . db_unit_time_restrictions().
94 94
     " GROUP BY unit_player_id, unit_type, unit_snid, unit_level"
95 95
   );
96 96
 }
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 
105 105
 function db_unit_list_admin_delete_mercenaries_finished()
106 106
 {
107
-  return doquery("DELETE FROM {{unit}} WHERE unit_time_finish IS NOT NULL AND unit_time_finish < FROM_UNIXTIME(" . SN_TIME_NOW . ") AND unit_type = " . UNIT_MERCENARIES);
107
+  return doquery("DELETE FROM {{unit}} WHERE unit_time_finish IS NOT NULL AND unit_time_finish < FROM_UNIXTIME(".SN_TIME_NOW.") AND unit_type = ".UNIT_MERCENARIES);
108 108
 }
109 109
 
110 110
 function db_unit_list_admin_set_mercenaries_expire_time($default_length)
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
   return doquery(
113 113
     "UPDATE {{unit}}
114 114
     SET
115
-      unit_time_start = FROM_UNIXTIME(" . SN_TIME_NOW . "),
116
-      unit_time_finish = FROM_UNIXTIME(" . (SN_TIME_NOW + $default_length) . ")
115
+      unit_time_start = FROM_UNIXTIME(" . SN_TIME_NOW."),
116
+      unit_time_finish = FROM_UNIXTIME(" . (SN_TIME_NOW + $default_length).")
117 117
     WHERE unit_type = " . UNIT_MERCENARIES
118 118
   );
119 119
 }
Please login to merge, or discard this patch.
includes/functions/eco_get_build_data.php 1 patch
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -10,6 +10,7 @@  discard block
 block discarded – undo
10 10
  *
11 11
  * 1.0 - copyright (c) 2010 by Gorlum for http://supernova.ws
12 12
  * @version 1.0
13
+ * @param integer $lab_require
13 14
  */
14 15
 function eco_get_lab_max_effective_level(&$user, $lab_require)
15 16
 {
@@ -193,6 +194,9 @@  discard block
 block discarded – undo
193 194
   return $result;
194 195
 }
195 196
 
197
+/**
198
+ * @param integer[] $unit_list
199
+ */
196 200
 function eco_is_builds_in_que($planet_que, $unit_list)
197 201
 {
198 202
   $eco_is_builds_in_que = false;
Please login to merge, or discard this patch.
includes/functions/eco_queue.php 2 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -55,6 +55,9 @@  discard block
 block discarded – undo
55 55
 }
56 56
 
57 57
 
58
+/**
59
+ * @param integer $build_mode
60
+ */
58 61
 function que_build($user, $planet, $build_mode = BUILD_CREATE, $redirect = true) {
59 62
   global $lang, $config;
60 63
 
@@ -378,6 +381,9 @@  discard block
 block discarded – undo
378 381
   return classSupernova::db_que_list_by_type_location($user_id, $planet_id, $que_type, $for_update);
379 382
 }
380 383
 
384
+/**
385
+ * @param integer $unit_id
386
+ */
381 387
 function que_add_unit($unit_id, $user = array(), $planet = array(), $build_data, $unit_level = 0, $unit_amount = 1, $build_mode = BUILD_CREATE) {
382 388
   // TODO Унифицировать проверки
383 389
 
Please login to merge, or discard this patch.
Spacing   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@  discard block
 block discarded – undo
2 2
 
3 3
 function que_get_unit_que($unit_id) {
4 4
   $que_type = false;
5
-  foreach(sn_get_groups('ques') as $que_id => $que_data) {
6
-    if(in_array($unit_id, $que_data['unit_list'])) {
5
+  foreach (sn_get_groups('ques') as $que_id => $que_data) {
6
+    if (in_array($unit_id, $que_data['unit_list'])) {
7 7
       $que_type = $que_id;
8 8
       break;
9 9
     }
@@ -14,14 +14,14 @@  discard block
 block discarded – undo
14 14
 
15 15
 
16 16
 function que_get_max_que_length($user, $planet, $que_id, $que_data = null) {
17
-  if(empty($que_data)) {
17
+  if (empty($que_data)) {
18 18
     $que_data = sn_get_groups('ques');
19 19
     $que_data = $que_data[$que_id];
20 20
   }
21 21
 
22 22
 
23 23
   $que_length = 1;
24
-  switch($que_id) {
24
+  switch ($que_id) {
25 25
     case QUE_RESEARCH:
26 26
       $que_length = classSupernova::$config->server_que_length_research + mrc_get_level($user, null, UNIT_PREMIUM); // TODO - вынести в модуль
27 27
     break;
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
 
36 36
 function eco_que_str2arr($que_str) {
37 37
   $que_arr = explode(';', $que_str);
38
-  foreach($que_arr as $que_index => &$que_item) {
39
-    if($que_item) {
38
+  foreach ($que_arr as $que_index => &$que_item) {
39
+    if ($que_item) {
40 40
       $que_item = explode(',', $que_item);
41 41
     } else {
42 42
       unset($que_arr[$que_index]);
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 }
48 48
 
49 49
 function eco_que_arr2str($que_arr) {
50
-  foreach($que_arr as &$que_item) {
50
+  foreach ($que_arr as &$que_item) {
51 51
     $que_item = implode(',', $que_item);
52 52
   }
53 53
 
@@ -59,14 +59,14 @@  discard block
 block discarded – undo
59 59
   $classLocale = classLocale::$lang;
60 60
 
61 61
   $is_autoconvert = false;
62
-  if($build_mode == BUILD_AUTOCONVERT || sys_get_param_int('auto_convert')) {
62
+  if ($build_mode == BUILD_AUTOCONVERT || sys_get_param_int('auto_convert')) {
63 63
     $build_mode = BUILD_CREATE;
64 64
     $is_autoconvert = true;
65 65
   }
66 66
 
67 67
   $unit_amount_qued = 0;
68 68
   try {
69
-    if(!$user['id']) {
69
+    if (!$user['id']) {
70 70
       throw new exception('{Нет идентификатора пользователя - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION
71 71
     }
72 72
 
@@ -77,16 +77,16 @@  discard block
 block discarded – undo
77 77
       foreach($unit_list as $unit_id => $unit_amount) if($unit_amount) break;
78 78
     }
79 79
     */
80
-    if(!$unit_id) {
80
+    if (!$unit_id) {
81 81
       throw new exception('{Нет идентификатора юнита - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION
82 82
     }
83 83
 
84 84
     $que_id = que_get_unit_que($unit_id);
85
-    if(!$que_id) {
85
+    if (!$que_id) {
86 86
       throw new exception('{Неправильный тип очереди - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION
87 87
     }
88 88
 
89
-    if($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) {
89
+    if ($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) {
90 90
       throw new exception('{Уничтожать можно только здания на планете}', ERR_ERROR); // TODO EXCEPTION
91 91
     }
92 92
 
@@ -94,12 +94,12 @@  discard block
 block discarded – undo
94 94
     $que_data = $que_data[$que_id];
95 95
 
96 96
     // TODO Переделать под подочереди
97
-    if($que_id == QUE_STRUCTURES) {
97
+    if ($que_id == QUE_STRUCTURES) {
98 98
       $sn_groups_build_allow = sn_get_groups('build_allow');
99 99
       $que_data['unit_list'] = $sn_groups_build_allow[$planet['planet_type']];
100 100
 
101
-      if(!isset($que_data['unit_list'][$unit_id])) {
102
-        throw new exception('{Это здание нельзя строить на ' . ($planet['planet_type'] == PT_PLANET ? 'планете' : 'луне'), ERR_ERROR); // TODO EXCEPTION
101
+      if (!isset($que_data['unit_list'][$unit_id])) {
102
+        throw new exception('{Это здание нельзя строить на '.($planet['planet_type'] == PT_PLANET ? 'планете' : 'луне'), ERR_ERROR); // TODO EXCEPTION
103 103
       }
104 104
     }
105 105
     /*
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
     // Это нужно, что бы заблокировать пользователя и работу с очередями
120 120
     $user = db_user_by_id($user['id']);
121 121
     // Это нужно, что бы заблокировать планету от списания ресурсов
122
-    if(isset($planet['id']) && $planet['id']) {
122
+    if (isset($planet['id']) && $planet['id']) {
123 123
       $planet = db_planet_by_id($planet['id'], true);
124 124
     } else {
125 125
       $planet['id'] = 0;
@@ -131,12 +131,12 @@  discard block
 block discarded – undo
131 131
     $in_que = &$que['in_que'][$que_id][$user['id']][$planet_id];
132 132
     $que_max_length = que_get_max_que_length($user, $planet, $que_id, $que_data);
133 133
     // TODO Добавить вызовы функций проверок текущей и максимальной длин очередей
134
-    if(count($in_que) >= $que_max_length) {
134
+    if (count($in_que) >= $que_max_length) {
135 135
       throw new exception('{Все слоты очереди заняты}', ERR_ERROR); // TODO EXCEPTION
136 136
     }
137 137
 
138 138
     // TODO Отдельно посмотреть на уничтожение зданий - что бы можно было уничтожать их без планов
139
-    switch(eco_can_build_unit($user, $planet, $unit_id)) {
139
+    switch (eco_can_build_unit($user, $planet, $unit_id)) {
140 140
       case BUILD_ALLOWED:
141 141
       break;
142 142
       case BUILD_UNIT_BUSY:
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
       break; // TODO EXCEPTION eco_bld_msg_err_laboratory_upgrading
145 145
       // case BUILD_REQUIRE_NOT_MEET:
146 146
       default:
147
-        if($build_mode == BUILD_CREATE) {
147
+        if ($build_mode == BUILD_CREATE) {
148 148
           throw new exception('{Требования не удовлетворены}', ERR_ERROR);
149 149
         }
150 150
       break; // TODO EXCEPTION eco_bld_msg_err_requirements_not_meet
@@ -154,14 +154,14 @@  discard block
 block discarded – undo
154 154
     $unit_amount_qued = $unit_amount;
155 155
     $units_qued = isset($in_que[$unit_id]) ? $in_que[$unit_id] : 0;
156 156
     $unit_level = mrc_get_level($user, $planet, $unit_id, true, true) + $units_qued;
157
-    if($unit_max = get_unit_param($unit_id, P_MAX_STACK)) {
158
-      if($unit_level >= $unit_max) {
157
+    if ($unit_max = get_unit_param($unit_id, P_MAX_STACK)) {
158
+      if ($unit_level >= $unit_max) {
159 159
         throw new exception('{Максимальное количество юнитов данного типа уже достигнуто или будет достигнуто по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION
160 160
       }
161 161
       $unit_amount = max(0, min($unit_amount, $unit_max - $unit_level));
162 162
     }
163 163
 
164
-    if($unit_amount < 1) {
164
+    if ($unit_amount < 1) {
165 165
       throw new exception('{Неправильное количество юнитов - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION
166 166
     }
167 167
 
@@ -170,21 +170,21 @@  discard block
 block discarded – undo
170 170
     //  {
171 171
     //    die('Unit busy'); // TODO EXCEPTION
172 172
     //  }
173
-    if(get_unit_param($unit_id, P_STACKABLE)) {
173
+    if (get_unit_param($unit_id, P_STACKABLE)) {
174 174
       // TODO Поле 'max_Lot_size' для ограничения размера стэка в очереди - то ли в юниты, то ли в очередь
175
-      if(in_array($unit_id, $group_missile = sn_get_groups('missile'))) {
175
+      if (in_array($unit_id, $group_missile = sn_get_groups('missile'))) {
176 176
         // TODO Поле 'container' - указывает на родительску структуру, в которой хранится данный юнит и по вместительности которой нужно применять размер юнита
177 177
         $used_silo = 0;
178
-        foreach($group_missile as $missile_id) {
178
+        foreach ($group_missile as $missile_id) {
179 179
           $missile_qued = isset($in_que[$missile_id]) ? $in_que[$missile_id] : 0;
180 180
           $used_silo += (mrc_get_level($user, $planet, $missile_id, true, true) + $missile_qued) * get_unit_param($missile_id, P_UNIT_SIZE);
181 181
         }
182 182
         $free_silo = mrc_get_level($user, $planet, STRUC_SILO) * get_unit_param(STRUC_SILO, P_CAPACITY) - $used_silo;
183
-        if($free_silo <= 0) {
183
+        if ($free_silo <= 0) {
184 184
           throw new exception('{Ракетная шахта уже заполнена или будет заполнена по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION
185 185
         }
186 186
         $unit_size = get_unit_param($unit_id, P_UNIT_SIZE);
187
-        if($free_silo < $unit_size) {
187
+        if ($free_silo < $unit_size) {
188 188
           throw new exception("{В ракетной шахте нет места для {$classLocale['tech'][$unit_id]}}", ERR_ERROR); // TODO EXCEPTION
189 189
         }
190 190
         $unit_amount = max(0, min($unit_amount, floor($free_silo / $unit_size)));
@@ -192,10 +192,10 @@  discard block
 block discarded – undo
192 192
       $unit_level = $new_unit_level = 0;
193 193
     } else {
194 194
       $unit_amount = 1;
195
-      if($que_id == QUE_STRUCTURES) {
195
+      if ($que_id == QUE_STRUCTURES) {
196 196
         // if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $que['sectors'][$planet['id']] <= 0)
197 197
         $sectors_qued = is_array($in_que) ? array_sum($in_que) : 0;
198
-        if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) {
198
+        if ($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) {
199 199
           throw new exception('{Не хватает секторов на планете}', ERR_ERROR); // TODO EXCEPTION
200 200
         }
201 201
         // И что это я такое написал? Зачем?
@@ -212,10 +212,10 @@  discard block
 block discarded – undo
212 212
 
213 213
     $exchange = array();
214 214
     $market_get_autoconvert_cost = market_get_autoconvert_cost();
215
-    if($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) {
215
+    if ($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) {
216 216
       $dark_matter = mrc_get_level($user, null, RES_DARK_MATTER);
217
-      if(mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) {
218
-        throw new exception("{Нет хватает " . ($market_get_autoconvert_cost - $dark_matter) . "ТМ на постройки с автоконвертацией ресурсов}", ERR_ERROR); // TODO EXCEPTION
217
+      if (mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) {
218
+        throw new exception("{Нет хватает ".($market_get_autoconvert_cost - $dark_matter)."ТМ на постройки с автоконвертацией ресурсов}", ERR_ERROR); // TODO EXCEPTION
219 219
       }
220 220
 
221 221
       !get_unit_param($unit_id, P_STACKABLE) ? $unit_amount = 1 : false;
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
       $resource_exchange_rates = array();
225 225
       $resource_diff = array();
226 226
       $all_positive = true;
227
-      foreach($resources_loot as $resource_id) {
227
+      foreach ($resources_loot as $resource_id) {
228 228
         $resource_db_name = pname_resource_name($resource_id);
229 229
         $resource_got[$resource_id] = floor(mrc_get_level($user, $planet, $resource_id));
230 230
         $resource_exchange_rates[$resource_id] = classSupernova::$config->__get("rpg_exchange_{$resource_db_name}");
@@ -232,15 +232,15 @@  discard block
 block discarded – undo
232 232
         $all_positive = $all_positive && ($resource_diff[$resource_id] > 0);
233 233
       }
234 234
       // Нужна автоконвертация
235
-      if($all_positive) {
235
+      if ($all_positive) {
236 236
         $is_autoconvert = false;
237 237
       } else {
238
-        foreach($resource_diff as $resource_diff_id => &$resource_diff_amount) {
239
-          if($resource_diff_amount >= 0) {
238
+        foreach ($resource_diff as $resource_diff_id => &$resource_diff_amount) {
239
+          if ($resource_diff_amount >= 0) {
240 240
             continue;
241 241
           }
242
-          foreach($resource_diff as $resource_got_id => &$resource_got_amount) {
243
-            if($resource_got_amount <= 0) {
242
+          foreach ($resource_diff as $resource_got_id => &$resource_got_amount) {
243
+            if ($resource_got_amount <= 0) {
244 244
               continue;
245 245
             }
246 246
             $current_exchange = $resource_exchange_rates[$resource_got_id] / $resource_exchange_rates[$resource_diff_id];
@@ -256,14 +256,14 @@  discard block
 block discarded – undo
256 256
         }
257 257
 
258 258
         $is_autoconvert_ok = true;
259
-        foreach($resource_diff as $resource_diff_amount2) {
260
-          if($resource_diff_amount2 < 0) {
259
+        foreach ($resource_diff as $resource_diff_amount2) {
260
+          if ($resource_diff_amount2 < 0) {
261 261
             $is_autoconvert_ok = false;
262 262
             break;
263 263
           }
264 264
         }
265 265
 
266
-        if($is_autoconvert_ok) {
266
+        if ($is_autoconvert_ok) {
267 267
           $build_data['RESULT'][$build_mode] = BUILD_ALLOWED;
268 268
           $build_data['CAN'][$build_mode] = $unit_amount;
269 269
         } else {
@@ -272,19 +272,19 @@  discard block
 block discarded – undo
272 272
       }
273 273
     }
274 274
     $unit_amount = min($build_data['CAN'][$build_mode], $unit_amount);
275
-    if($unit_amount <= 0) {
275
+    if ($unit_amount <= 0) {
276 276
       throw new exception('{Не хватает ресурсов}', ERR_ERROR); // TODO EXCEPTION
277 277
     }
278 278
 
279
-    if($new_unit_level < 0) {
279
+    if ($new_unit_level < 0) {
280 280
       throw new exception('{Нельзя уничтожить больше юнитов, чем есть}', ERR_ERROR); // TODO EXCEPTION
281 281
     }
282 282
 
283
-    if($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) {
283
+    if ($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) {
284 284
       throw new exception('{Строительство блокировано}', ERR_ERROR); // TODO EXCEPTION
285 285
     }
286 286
 
287
-    if($is_autoconvert) {
287
+    if ($is_autoconvert) {
288 288
       ksort($exchange);
289 289
       ksort($resource_got);
290 290
       db_change_units($user, $planet, array(
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
     }
300 300
 
301 301
     $unit_amount_qued = 0;
302
-    while($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) {
302
+    while ($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) {
303 303
       $place = min($unit_amount, MAX_FLEET_OR_DEFS_PER_ROW);
304 304
       que_add_unit($unit_id, $user, $planet, $build_data, $new_unit_level, $place, $build_mode);
305 305
       $unit_amount -= $place;
@@ -309,8 +309,8 @@  discard block
 block discarded – undo
309 309
 
310 310
     sn_db_transaction_commit();
311 311
 
312
-    if($redirect) {
313
-      sys_redirect("{$_SERVER['PHP_SELF']}?mode=" . sys_get_param_str('mode') . "&ally_id=" . sys_get_param_id('ally_id'));
312
+    if ($redirect) {
313
+      sys_redirect("{$_SERVER['PHP_SELF']}?mode=".sys_get_param_str('mode')."&ally_id=".sys_get_param_id('ally_id'));
314 314
       die();
315 315
     }
316 316
 
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
       'STATUS'  => ERR_NONE,
319 319
       'MESSAGE' => '{Строительство начато}',
320 320
     );
321
-  } catch(exception $e) {
321
+  } catch (exception $e) {
322 322
     sn_db_transaction_rollback();
323 323
     $operation_result = array(
324 324
       'STATUS'  => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR,
@@ -326,8 +326,8 @@  discard block
 block discarded – undo
326 326
     );
327 327
   }
328 328
 
329
-  if(!empty($operation_result['MESSAGE'])) {
330
-    $operation_result['MESSAGE'] .= ' ' . ($unit_amount_qued ? $unit_amount_qued : $unit_amount) . 'x[' . classLocale::$lang['tech'][$unit_id] . ']';
329
+  if (!empty($operation_result['MESSAGE'])) {
330
+    $operation_result['MESSAGE'] .= ' '.($unit_amount_qued ? $unit_amount_qued : $unit_amount).'x['.classLocale::$lang['tech'][$unit_id].']';
331 331
   }
332 332
 
333 333
   return $operation_result;
@@ -337,11 +337,11 @@  discard block
 block discarded – undo
337 337
 function que_recalculate($old_que) {
338 338
   $new_que = array();
339 339
 
340
-  if(!is_array($old_que['items'])) {
340
+  if (!is_array($old_que['items'])) {
341 341
     return $new_que;
342 342
   }
343
-  foreach($old_que['items'] as $row) {
344
-    if(!isset($row) || !$row || $row['que_unit_amount'] <= 0) {
343
+  foreach ($old_que['items'] as $row) {
344
+    if (!isset($row) || !$row || $row['que_unit_amount'] <= 0) {
345 345
       continue;
346 346
     }
347 347
 
@@ -352,9 +352,9 @@  discard block
 block discarded – undo
352 352
 
353 353
     $last_id = count($new_que['items']) - 1;
354 354
 
355
-    if($row['que_planet_id']) {
355
+    if ($row['que_planet_id']) {
356 356
       $new_que['planets'][$row['que_planet_id']][$row['que_type']][] = &$new_que['items'][$last_id];
357
-    } elseif($row['que_type'] == QUE_RESEARCH) {
357
+    } elseif ($row['que_type'] == QUE_RESEARCH) {
358 358
       $new_que['players'][$row['que_player_id']][$row['que_type']][] = &$new_que['items'][$last_id];
359 359
     }
360 360
     $new_que['ques'][$row['que_type']][$row['que_player_id']][intval($row['que_planet_id'])][] = &$new_que['items'][$last_id];
@@ -389,9 +389,9 @@  discard block
 block discarded – undo
389 389
   $que_type = que_get_unit_que($unit_id);
390 390
   $planet_id_origin = $planet['id'] ? $planet['id'] : 'NULL';
391 391
   $planet_id = $que_type == QUE_RESEARCH ? 'NULL' : $planet_id_origin;
392
-  if(is_numeric($planet_id)) {
392
+  if (is_numeric($planet_id)) {
393 393
     db_planet_set_by_id($planet_id, "`que_processed` = UNIX_TIMESTAMP(NOW())");
394
-  } elseif(is_numeric($user['id'])) {
394
+  } elseif (is_numeric($user['id'])) {
395 395
     db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())');
396 396
   }
397 397
 
@@ -421,17 +421,17 @@  discard block
 block discarded – undo
421 421
   $planet['id'] = $planet['id'] && $que_type !== QUE_RESEARCH ? $planet['id'] : 0;
422 422
   $global_que = que_get($user['id'], $planet['id'], $que_type, true);
423 423
 
424
-  if(!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) {
424
+  if (!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) {
425 425
     $que = array_reverse($global_que['ques'][$que_type][$user['id']][$planet['id']]);
426 426
 
427
-    foreach($que as $que_item) {
427
+    foreach ($que as $que_item) {
428 428
       db_que_delete_by_id($que_item['que_id']);
429 429
 
430
-      if($que_item['que_planet_id_origin']) {
430
+      if ($que_item['que_planet_id_origin']) {
431 431
         $planet['id'] = $que_item['que_planet_id_origin'];
432 432
       }
433 433
 
434
-      if(!isset($planets_locked[$planet['id']])) {
434
+      if (!isset($planets_locked[$planet['id']])) {
435 435
         $planets_locked[$planet['id']] = $planet['id'] ? db_planet_by_id($planet['id'], true) : $planet;
436 436
       }
437 437
 
@@ -443,14 +443,14 @@  discard block
 block discarded – undo
443 443
         RES_DEUTERIUM => $build_data[RES_DEUTERIUM] * $que_item['que_unit_amount'],
444 444
       ));
445 445
 
446
-      if(!$clear) {
446
+      if (!$clear) {
447 447
         break;
448 448
       }
449 449
     }
450 450
 
451
-    if(is_numeric($planet['id'])) {
451
+    if (is_numeric($planet['id'])) {
452 452
       db_planet_set_by_id($planet['id'], "`que_processed` = UNIX_TIMESTAMP(NOW())");
453
-    } elseif(is_numeric($user['id'])) {
453
+    } elseif (is_numeric($user['id'])) {
454 454
       db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())');
455 455
     }
456 456
 
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
     sn_db_transaction_rollback();
460 460
   }
461 461
 //die();
462
-  header("Location: {$_SERVER['PHP_SELF']}?mode={$que_type}" . "&ally_id=" . sys_get_param_id('ally_id'));
462
+  header("Location: {$_SERVER['PHP_SELF']}?mode={$que_type}"."&ally_id=".sys_get_param_id('ally_id'));
463 463
 }
464 464
 
465 465
 
@@ -498,21 +498,21 @@  discard block
 block discarded – undo
498 498
   // TODO: Переделать для $que_type === false
499 499
   $planet['id'] = $planet['id'] ? $planet['id'] : 0;
500 500
 
501
-  if(!is_array($que)) {
501
+  if (!is_array($que)) {
502 502
     $que = que_get($user['id'], $planet['id'], $que_type);
503 503
   }
504 504
 
505
-  if(is_array($que) && isset($que['items'])) {
505
+  if (is_array($que) && isset($que['items'])) {
506 506
     $que = $que['ques'][$que_type][$user['id']][$planet['id']];
507 507
   }
508 508
 
509
-  if($que) {
510
-    foreach($que as $que_element) {
509
+  if ($que) {
510
+    foreach ($que as $que_element) {
511 511
       $template->assign_block_vars('que', que_tpl_parse_element($que_element, $short_names));
512 512
     }
513 513
   }
514 514
 
515
-  if($que_type == QUE_RESEARCH) {
515
+  if ($que_type == QUE_RESEARCH) {
516 516
   }
517 517
 }
518 518
 
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
   $user = db_user_by_id($user['id'], true);
539 539
 
540 540
   $time_left[$user['id']][0] = max(0, $on_time - $user['que_processed']);
541
-  if($planet === null && !$time_left[$user['id']][0]) {
541
+  if ($planet === null && !$time_left[$user['id']][0]) {
542 542
     // TODO
543 543
     return $que;
544 544
   }
@@ -547,12 +547,12 @@  discard block
 block discarded – undo
547 547
   $que_type_id = $planet === null ? QUE_RESEARCH : false;
548 548
   $planet = intval(is_array($planet) ? $planet['id'] : $planet); // В $planet у нас теперь только её ID или шаблон null/0/false
549 549
   $que = que_get($user['id'], $planet, $que_type_id, true);
550
-  if(empty($que['items'])) {
550
+  if (empty($que['items'])) {
551 551
     return $que;
552 552
   }
553 553
 
554 554
   $planet_list = array();
555
-  if($planet !== null) {
555
+  if ($planet !== null) {
556 556
     // Если нужно изменять данные на планетах - блокируем планеты и получаем данные о них
557 557
     // TODO - от них не надо ничего, кроме ID и que_processed
558 558
     $planet_row = db_planet_list_by_user_or_planet($user['id'], $planet);
@@ -561,21 +561,21 @@  discard block
 block discarded – undo
561 561
   }
562 562
 
563 563
   // Теперь в $time_left лежит время обсчета всех очередей по каждой из планеты
564
-  if(array_sum($time_left[$user['id']]) == 0) {
564
+  if (array_sum($time_left[$user['id']]) == 0) {
565 565
     return $que;
566 566
   }
567 567
 
568 568
   $db_changeset = array();
569 569
   $unit_changes = array();
570
-  foreach($que['items'] as &$que_item) {
570
+  foreach ($que['items'] as &$que_item) {
571 571
     $que_player_id = &$que_item['que_player_id'];
572 572
     $que_planet_id = intval($que_item['que_planet_id']);
573 573
 
574 574
     $que_time_left = &$que['time_left'][$que_player_id][$que_planet_id][$que_item['que_type']];
575
-    if(!isset($que_time_left)) {
575
+    if (!isset($que_time_left)) {
576 576
       $que_time_left = $time_left[$que_player_id][$que_planet_id];
577 577
     }
578
-    if($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) {
578
+    if ($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) {
579 579
       continue;
580 580
     }
581 581
     // Дальше мы идем, если только осталось время в очереди И юниты к постройке
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
     // Теперь работаем с остатком времени на юните. Оно не может быть равно или меньше нуля
589 589
 
590 590
     // Если времени в очереди осталось не меньше, чем время текущего юнита - значит мы достроили юнит
591
-    if($que_time_left >= $que_item['que_time_left']) {
591
+    if ($que_time_left >= $que_item['que_time_left']) {
592 592
       // Увеличиваем количество отстроенных юнитов
593 593
       $unit_processed++;
594 594
       // Вычитаем из времени очереди потраченное на постройку время
@@ -601,12 +601,12 @@  discard block
 block discarded – undo
601 601
     $que_item['que_unit_amount'] -= $unit_processed;
602 602
 
603 603
     // Если еще остались юниты - значит ВСЁ оставшееся время приходится на достройку следующего юнита
604
-    if($que_item['que_unit_amount'] > 0) {
604
+    if ($que_item['que_unit_amount'] > 0) {
605 605
       $que_item['que_time_left'] = $que_item['que_time_left'] - $que_time_left;
606 606
       $que_time_left = 0;
607 607
     }
608 608
 
609
-    if($que_item['que_unit_amount'] <= 0) {
609
+    if ($que_item['que_unit_amount'] <= 0) {
610 610
       $db_changeset['que'][] = array(
611 611
         'action'  => SQL_OP_DELETE,
612 612
         P_VERSION => 1,
@@ -632,14 +632,14 @@  discard block
 block discarded – undo
632 632
       );
633 633
     }
634 634
 
635
-    if($unit_processed) {
635
+    if ($unit_processed) {
636 636
       $unit_processed_delta = $unit_processed * ($que_item['que_unit_mode'] == BUILD_CREATE ? 1 : -1);
637 637
       $unit_changes[$que_player_id][$que_planet_id][$que_item['que_unit_id']] += $unit_processed_delta;
638 638
     }
639 639
   }
640 640
 
641
-  foreach($time_left as $player_id => $planet_data) {
642
-    foreach($planet_data as $planet_id => $time_on_planet) {
641
+  foreach ($time_left as $player_id => $planet_data) {
642
+    foreach ($planet_data as $planet_id => $time_on_planet) {
643 643
       $table = $planet_id ? 'planets' : 'users';
644 644
       $id = $planet_id ? $planet_id : $player_id;
645 645
       $db_changeset[$table][] = array(
@@ -655,8 +655,8 @@  discard block
 block discarded – undo
655 655
         ),
656 656
       );
657 657
 
658
-      if(is_array($unit_changes[$player_id][$planet_id])) {
659
-        foreach($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) {
658
+      if (is_array($unit_changes[$player_id][$planet_id])) {
659
+        foreach ($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) {
660 660
           $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, $unit_amount, $user, $planet_id ? $planet_id : null);
661 661
         }
662 662
       }
@@ -666,38 +666,38 @@  discard block
 block discarded – undo
666 666
   $que = que_recalculate($que);
667 667
 
668 668
   // TODO: Re-enable quests for Alliances
669
-  if(!empty($unit_changes) && !$user['user_as_ally']) {
669
+  if (!empty($unit_changes) && !$user['user_as_ally']) {
670 670
     $quest_list = qst_get_quests($user['id']);
671 671
     $quest_triggers = qst_active_triggers($quest_list);
672 672
     $quest_rewards = array();
673 673
 
674 674
 
675 675
     $xp_incoming = array();
676
-    foreach($unit_changes as $user_id => $planet_changes) {
677
-      foreach($planet_changes as $planet_id => $changes) {
676
+    foreach ($unit_changes as $user_id => $planet_changes) {
677
+      foreach ($planet_changes as $planet_id => $changes) {
678 678
         $planet_this = $planet_id ? classSupernova::db_get_record_by_id(LOC_PLANET, $planet_id) : array();
679
-        foreach($changes as $unit_id => $unit_value) {
679
+        foreach ($changes as $unit_id => $unit_value) {
680 680
           $que_id = que_get_unit_que($unit_id);
681 681
           $unit_level_new = mrc_get_level($user, $planet_this, $unit_id, false, true) + $unit_value;
682
-          if($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) {
682
+          if ($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) {
683 683
             $build_data = eco_get_build_data($user, $planet_this, $unit_id, $unit_level_new - 1);
684 684
             $build_data = $build_data[BUILD_CREATE];
685
-            foreach(sn_get_groups('resources_loot') as $resource_id) {
685
+            foreach (sn_get_groups('resources_loot') as $resource_id) {
686 686
               $xp_incoming[$que_id] += $build_data[$resource_id]; // TODO - добавить конверсию рейтов обмена
687 687
             }
688 688
           }
689 689
 
690
-          if(is_array($quest_triggers)) {
690
+          if (is_array($quest_triggers)) {
691 691
             // TODO: Check mutiply condition quests
692 692
             $quest_trigger_list = array_keys($quest_triggers, $unit_id);
693
-            if(is_array($quest_trigger_list)) {
694
-              foreach($quest_trigger_list as $quest_id) {
693
+            if (is_array($quest_trigger_list)) {
694
+              foreach ($quest_trigger_list as $quest_id) {
695 695
                 $quest_unit_level = $unit_level_new;
696
-                if(get_unit_param($unit_id, P_UNIT_TYPE) == UNIT_SHIPS) {
696
+                if (get_unit_param($unit_id, P_UNIT_TYPE) == UNIT_SHIPS) {
697 697
                   $quest_unit_level = db_unit_count_by_user_and_type_and_snid($user_id, 0, $unit_id);
698 698
                   $quest_unit_level = $quest_unit_level[$unit_id]['qty'];
699 699
                 }
700
-                if($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $quest_unit_level) {
700
+                if ($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $quest_unit_level) {
701 701
                   $quest_rewards[$quest_id][$user_id][$planet_id] = $quest_list[$quest_id]['quest_rewards_list'];
702 702
                   $quest_list[$quest_id]['quest_status_status'] = QUEST_STATUS_COMPLETE;
703 703
                 }
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
     // TODO: Изменить начисление награды за квесты на ту планету, на которой происходил ресеч
711 711
     qst_reward($user, $quest_rewards, $quest_list);
712 712
 
713
-    foreach($xp_incoming as $que_id => $xp) {
713
+    foreach ($xp_incoming as $que_id => $xp) {
714 714
       rpg_level_up($user, $que_id == QUE_RESEARCH ? RPG_TECH : RPG_STRUCTURE, $xp / 1000);
715 715
     }
716 716
   }
Please login to merge, or discard this patch.
includes/functions/msg_send_simple_message.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -37,6 +37,9 @@
 block discarded – undo
37 37
   return $list;
38 38
 }
39 39
 
40
+/**
41
+ * @param integer $message_type
42
+ */
40 43
 function msg_send_simple_message($owners, $sender, $timestamp, $message_type, $from, $subject, $text, $escaped = false, $force = false)
41 44
 {
42 45
   global $config, $user, $sn_message_class_list;
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -22,10 +22,10 @@  discard block
 block discarded – undo
22 22
 
23 23
   $list = '';
24 24
   $query = db_user_list(
25
-    "ally_id = '{$ally_id}'" . ($ally_rank_id >= 0 ? " AND ally_rank_id = {$ally_rank_id}" : ''),
25
+    "ally_id = '{$ally_id}'".($ally_rank_id >= 0 ? " AND ally_rank_id = {$ally_rank_id}" : ''),
26 26
     false, 'id, username');
27 27
   // while ($u = db_fetch($query))
28
-  foreach($query as $u) {
28
+  foreach ($query as $u) {
29 29
     $sendList[] = $u['id'];
30 30
     $list .= "<br>{$u['username']} ";
31 31
   }
@@ -38,17 +38,17 @@  discard block
 block discarded – undo
38 38
 function msg_send_simple_message($owners, $sender, $timestamp, $message_type, $from, $subject, $text, $escaped = false, $force = false) {
39 39
   global $user, $sn_message_class_list;
40 40
 
41
-  if(!$owners) {
41
+  if (!$owners) {
42 42
     return;
43 43
   }
44 44
 
45 45
   $timestamp = $timestamp ? $timestamp : SN_TIME_NOW;
46 46
   $sender = intval($sender);
47
-  if(!is_array($owners)) {
47
+  if (!is_array($owners)) {
48 48
     $owners = array($owners);
49 49
   }
50 50
 
51
-  if(!$escaped) {
51
+  if (!$escaped) {
52 52
     $from = db_escape($from);
53 53
     $subject = db_escape($subject);
54 54
     $text = db_escape($text);
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 
64 64
   $message_class_name_total = $sn_message_class_list[MSG_TYPE_NEW]['name'];
65 65
 
66
-  if($owners[0] == '*') {
67
-    if($user['authlevel'] < 3) {
66
+  if ($owners[0] == '*') {
67
+    if ($user['authlevel'] < 3) {
68 68
       return false;
69 69
     }
70 70
     // TODO Добавить $timestamp - рассылка может быть и отсроченной
@@ -73,26 +73,26 @@  discard block
 block discarded – undo
73 73
     $owners = array();
74 74
   } else {
75 75
     $insert_values = array();
76
-    $insert_template = "('%u'," . str_replace('%', '%%', " '{$sender}', '{$timestamp}', '{$message_type}', '{$from}', '{$subject}', '{$text}')");
76
+    $insert_template = "('%u',".str_replace('%', '%%', " '{$sender}', '{$timestamp}', '{$message_type}', '{$from}', '{$subject}', '{$text}')");
77 77
 
78
-    foreach($owners as $owner) {
79
-      if($user['id'] != $owner) {
78
+    foreach ($owners as $owner) {
79
+      if ($user['id'] != $owner) {
80 80
         $owner_row = db_user_by_id($owner);
81 81
       } else {
82 82
         $owner_row = $user;
83 83
       }
84 84
       sys_user_options_unpack($owner_row);
85 85
 
86
-      if($force || !$message_class_switchable || $owner_row["opt_{$message_class_name}"]) {
86
+      if ($force || !$message_class_switchable || $owner_row["opt_{$message_class_name}"]) {
87 87
         $insert_values[] = sprintf($insert_template, $owner);
88 88
       }
89 89
 
90
-      if($message_class_email && classSupernova::$config->game_email_pm && $owner_row["opt_email_{$message_class_name}"]) {
90
+      if ($message_class_email && classSupernova::$config->game_email_pm && $owner_row["opt_email_{$message_class_name}"]) {
91 91
         @$result = mymail($owner_row['email'], $subject, $text_unescaped, '', true);
92 92
       }
93 93
     }
94 94
 
95
-    if(empty($insert_values)) {
95
+    if (empty($insert_values)) {
96 96
       return;
97 97
     }
98 98
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
   }
101 101
   db_user_list_set_mass_mail($owners, "`{$message_class_name}` = `{$message_class_name}` + 1, `{$message_class_name_total}` = `{$message_class_name_total}` + 1");
102 102
 
103
-  if(in_array($user['id'], $owners) || $owners[0] == '*') {
103
+  if (in_array($user['id'], $owners) || $owners[0] == '*') {
104 104
     $user[$message_class_name]++;
105 105
     $user[$message_class_name_total]++;
106 106
   }
Please login to merge, or discard this patch.
includes/functions/sys_user.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -141,6 +141,9 @@
 block discarded – undo
141 141
   ");
142 142
 }
143 143
 
144
+/**
145
+ * @param string $email_unsafe
146
+ */
144 147
 function player_create($username_unsafe, $email_unsafe, $options) {
145 148
   sn_db_transaction_check(true);
146 149
 
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 function sys_user_vacation($user) {
10
-  if(sys_get_param_str('vacation') == 'leave') {
10
+  if (sys_get_param_str('vacation') == 'leave') {
11 11
     if ($user['vacation'] < SN_TIME_NOW) {
12 12
       $user['vacation'] = 0;
13 13
       $user['vacation_next'] = SN_TIME_NOW + classSupernova::$config->player_vacation_timeout;
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
     }
16 16
   }
17 17
 
18
-  if($user['vacation']) {
18
+  if ($user['vacation']) {
19 19
     // sn_sys_logout(false, true);
20 20
     // core_auth::logout(false, true);
21 21
 
@@ -45,33 +45,33 @@  discard block
 block discarded – undo
45 45
   // TODO: Full rewrite
46 46
   sn_db_transaction_start();
47 47
   $TheUser = DBStaticUser::db_user_by_id($UserID);
48
-  if ( $TheUser['ally_id'] != 0 ) {
49
-    $TheAlly = doquery ( "SELECT * FROM `{{alliance}}` WHERE `id` = '" . $TheUser['ally_id'] . "';", '', true );
48
+  if ($TheUser['ally_id'] != 0) {
49
+    $TheAlly = doquery("SELECT * FROM `{{alliance}}` WHERE `id` = '".$TheUser['ally_id']."';", '', true);
50 50
     $TheAlly['ally_members'] -= 1;
51
-    if ( $TheAlly['ally_members'] > 0 ) {
52
-      doquery ( "UPDATE `{{alliance}}` SET `ally_members` = '" . $TheAlly['ally_members'] . "' WHERE `id` = '" . $TheAlly['id'] . "';");
51
+    if ($TheAlly['ally_members'] > 0) {
52
+      doquery("UPDATE `{{alliance}}` SET `ally_members` = '".$TheAlly['ally_members']."' WHERE `id` = '".$TheAlly['id']."';");
53 53
     } else {
54
-      doquery ( "DELETE FROM `{{alliance}}` WHERE `id` = '" . $TheAlly['id'] . "';");
55
-      doquery ( "DELETE FROM `{{statpoints}}` WHERE `stat_type` = '2' AND `id_owner` = '" . $TheAlly['id'] . "';");
54
+      doquery("DELETE FROM `{{alliance}}` WHERE `id` = '".$TheAlly['id']."';");
55
+      doquery("DELETE FROM `{{statpoints}}` WHERE `stat_type` = '2' AND `id_owner` = '".$TheAlly['id']."';");
56 56
     }
57 57
   }
58
-  doquery ( "DELETE FROM `{{statpoints}}` WHERE `stat_type` = '1' AND `id_owner` = '" . $UserID . "';");
58
+  doquery("DELETE FROM `{{statpoints}}` WHERE `stat_type` = '1' AND `id_owner` = '".$UserID."';");
59 59
 
60 60
   db_planet_list_delete_by_owner($UserID);
61 61
 
62
-  doquery ( "DELETE FROM `{{messages}}` WHERE `message_sender` = '" . $UserID . "';");
63
-  doquery ( "DELETE FROM `{{messages}}` WHERE `message_owner` = '" . $UserID . "';");
64
-  doquery ( "DELETE FROM `{{notes}}` WHERE `owner` = '" . $UserID . "';");
62
+  doquery("DELETE FROM `{{messages}}` WHERE `message_sender` = '".$UserID."';");
63
+  doquery("DELETE FROM `{{messages}}` WHERE `message_owner` = '".$UserID."';");
64
+  doquery("DELETE FROM `{{notes}}` WHERE `owner` = '".$UserID."';");
65 65
   FleetList::db_fleet_list_delete_by_owner($UserID);
66 66
 //  doquery ( "DELETE FROM `{{rw}}` WHERE `id_owner1` = '" . $UserID . "';");
67 67
 //  doquery ( "DELETE FROM `{{rw}}` WHERE `id_owner2` = '" . $UserID . "';");
68
-  doquery ( "DELETE FROM `{{buddy}}` WHERE `BUDDY_SENDER_ID` = '" . $UserID . "';");
69
-  doquery ( "DELETE FROM `{{buddy}}` WHERE `BUDDY_OWNER_ID` = '" . $UserID . "';");
70
-  doquery ( "DELETE FROM `{{annonce}}` WHERE `user` = '" . $UserID . "';");
68
+  doquery("DELETE FROM `{{buddy}}` WHERE `BUDDY_SENDER_ID` = '".$UserID."';");
69
+  doquery("DELETE FROM `{{buddy}}` WHERE `BUDDY_OWNER_ID` = '".$UserID."';");
70
+  doquery("DELETE FROM `{{annonce}}` WHERE `user` = '".$UserID."';");
71 71
 
72 72
 
73 73
   classSupernova::db_del_record_by_id(LOC_USER, $UserID);
74
-  doquery ( "DELETE FROM `{{referrals}}` WHERE (`id` = '{$UserID}') OR (`id_partner` = '{$UserID}');");
74
+  doquery("DELETE FROM `{{referrals}}` WHERE (`id` = '{$UserID}') OR (`id_partner` = '{$UserID}');");
75 75
   classSupernova::$config->db_saveItem('users_amount', classSupernova::$config->db_loadItem('users_amount') - 1);
76 76
   sn_db_transaction_commit();
77 77
 }
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
   $ban_current = DBStaticUser::db_user_by_id($banned['id'], false, 'banaday');
88 88
   $ban_until = ($ban_current['banaday'] ? $ban_current['banaday'] : SN_TIME_NOW) + $term;
89 89
 
90
-  DBStaticUser::db_user_set_by_id($banned['id'], "`banaday` = {$ban_until} " . ($is_vacation ? ", `vacation` = '{$ban_until}' " : ''));
90
+  DBStaticUser::db_user_set_by_id($banned['id'], "`banaday` = {$ban_until} ".($is_vacation ? ", `vacation` = '{$ban_until}' " : ''));
91 91
 
92 92
   $banned['username'] = db_escape($banned['username']);
93 93
   $banner['username'] = db_escape($banner['username']);
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
  * @param string $reason
106 106
  */
107 107
 function sys_admin_player_ban_unset($banner, $banned, $reason = '') {
108
-  DBStaticUser::db_user_set_by_id($banned['id'], "`banaday` = 0, `vacation` = " . SN_TIME_NOW . "");
108
+  DBStaticUser::db_user_set_by_id($banned['id'], "`banaday` = 0, `vacation` = ".SN_TIME_NOW."");
109 109
 
110 110
   $banned['username'] = db_escape($banned['username']);
111 111
   $banner['username'] = db_escape($banner['username']);
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
     'total_points' => $options['total_points'] = empty($options['total_points']) ? 0 : $options['total_points'],
136 136
 
137
-    'options' => (empty($options['options']) ? $player_options_string : $options['options']) . (empty($options['options_extra']) ? '' : $options['options_extra']),
137
+    'options' => (empty($options['options']) ? $player_options_string : $options['options']).(empty($options['options_extra']) ? '' : $options['options_extra']),
138 138
 
139 139
     'galaxy' => $options['galaxy'] = intval($options['galaxy'] ? $options['galaxy'] : 0),
140 140
     'system' => $options['system'] = intval($options['system'] ? $options['system'] : 0),
@@ -145,28 +145,28 @@  discard block
 block discarded – undo
145 145
   !empty($options['password_encoded_unsafe']) ? $field_set['password'] = $options['password_encoded_unsafe'] : false;
146 146
 
147 147
   $user_new = classSupernova::db_ins_field_set(LOC_USER, $field_set);
148
-  if(!($options['galaxy'] && $options['system'] && $options['planet'])) {
148
+  if (!($options['galaxy'] && $options['system'] && $options['planet'])) {
149 149
     $options['galaxy'] = classSupernova::$config->LastSettedGalaxyPos;
150 150
     $options['system'] = classSupernova::$config->LastSettedSystemPos;
151
-    $segment_size = floor(Vector::$knownPlanets/ 3);
151
+    $segment_size = floor(Vector::$knownPlanets / 3);
152 152
     $segment = floor(classSupernova::$config->LastSettedPlanetPos / $segment_size);
153 153
     $segment++;
154 154
     $options['planet'] = mt_rand(1 + $segment * $segment_size, ($segment + 1) * $segment_size);
155 155
 
156 156
     // $new_planet_id = 0;
157
-    while(true) {
158
-      if($options['planet'] > Vector::$knownPlanets) {
157
+    while (true) {
158
+      if ($options['planet'] > Vector::$knownPlanets) {
159 159
         $options['planet'] = mt_rand(0, $segment_size - 1) + 1;
160 160
         $options['system']++;
161 161
       }
162
-      if($options['system'] > Vector::$knownSystems) {
162
+      if ($options['system'] > Vector::$knownSystems) {
163 163
         $options['system'] = 1;
164 164
         $options['galaxy']++;
165 165
       }
166
-      $options['galaxy'] > Vector::$knownGalaxies? $options['galaxy'] = 1 : false;
166
+      $options['galaxy'] > Vector::$knownGalaxies ? $options['galaxy'] = 1 : false;
167 167
 
168 168
       $galaxy_row = db_planet_by_gspt($options['galaxy'], $options['system'], $options['planet'], PT_PLANET, true, 'id');
169
-      if(!$galaxy_row['id']) {
169
+      if (!$galaxy_row['id']) {
170 170
         classSupernova::$config->db_saveItem(array(
171 171
           'LastSettedGalaxyPos' => $options['galaxy'],
172 172
           'LastSettedSystemPos' => $options['system'],
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
   $username_safe = db_escape($username_unsafe);
190 190
   db_player_name_history_replace($user_new, $username_safe);
191 191
 
192
-  if(!empty($options['partner_id']) && ($referral_row = DBStaticUser::db_user_by_id($options['partner_id'], true))) {
192
+  if (!empty($options['partner_id']) && ($referral_row = DBStaticUser::db_user_by_id($options['partner_id'], true))) {
193 193
     db_referral_insert($options, $user_new);
194 194
   }
195 195
 
Please login to merge, or discard this patch.
includes/functions/uni_functions.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
+/**
4
+ * @param double $planet_sectors
5
+ */
3 6
 function uni_create_planet_get_density($position_data, $user_row, $planet_sectors) {
4 7
   $density_list = sn_get_groups('planet_density');
5 8
   $density_min = reset($density_list);
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -253,9 +253,11 @@
 block discarded – undo
253 253
   }
254 254
 
255 255
   // Если новая планета не найдена или было переключения - проверяем текущую выбранную планету
256
-  if(!isset($planet_row['id'])) // || $planet_row['id'] != $user['current_planet']
256
+  if(!isset($planet_row['id'])) {
257
+    // || $planet_row['id'] != $user['current_planet']
257 258
   {
258 259
     $planet_row = db_planet_by_id_and_owner($user['current_planet'], $user['id'], false, 'id');
260
+  }
259 261
     // Если текущей планеты не существует - выставляем Столицу
260 262
     if(!isset($planet_row['id'])) {
261 263
       $planet_row = db_planet_by_id_and_owner($user['id_planet'], $user['id'], false, 'id');
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
7 7
 
8 8
   $possible_cores = array();
9 9
   $probability = 0;
10
-  foreach($density_list as $possible_core_id => $core_data) {
11
-    if(!$core_data[UNIT_PLANET_DENSITY_RARITY]) {
10
+  foreach ($density_list as $possible_core_id => $core_data) {
11
+    if (!$core_data[UNIT_PLANET_DENSITY_RARITY]) {
12 12
       continue;
13 13
     }
14 14
 
15
-    if(
15
+    if (
16 16
       // Core type exists
17 17
       in_array($possible_core_id, $position_data['core_types'])
18 18
       // Limit core type with planet sector count
@@ -33,8 +33,8 @@  discard block
 block discarded – undo
33 33
 
34 34
   $random = mt_rand(1, $probability);
35 35
   $selected_core = null;
36
-  foreach($possible_cores as $core_type => $core_info) {
37
-    if($random <= $core_info[UNIT_PLANET_DENSITY_RARITY]) {
36
+  foreach ($possible_cores as $core_type => $core_info) {
37
+    if ($random <= $core_info[UNIT_PLANET_DENSITY_RARITY]) {
38 38
       $selected_core = $core_info;
39 39
       break;
40 40
     }
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 function uni_create_planet($Galaxy, $System, $Position, $PlanetOwnerID, $planet_name_unsafe = '', $HomeWorld = false, $options = array()) {
58 58
   $Position = intval($Position);
59 59
 
60
-  if(!isset($options['skip_check']) && db_planet_by_gspt($Galaxy, $System, $Position, PT_PLANET, true, '`id`')) {
60
+  if (!isset($options['skip_check']) && db_planet_by_gspt($Galaxy, $System, $Position, PT_PLANET, true, '`id`')) {
61 61
     return false;
62 62
   }
63 63
 
@@ -66,11 +66,11 @@  discard block
 block discarded – undo
66 66
 
67 67
   $planet_generator = sn_get_groups('planet_generator');
68 68
 
69
-  if($HomeWorld) {
69
+  if ($HomeWorld) {
70 70
     $position_data = $planet_generator[0];
71 71
   } else {
72 72
     $position_data = $planet_generator[$Position >= UNIVERSE_RANDOM_PLANET_START || $Position < 1 ? UNIVERSE_RANDOM_PLANET_START : $Position];
73
-    if($Position >= UNIVERSE_RANDOM_PLANET_START) {
73
+    if ($Position >= UNIVERSE_RANDOM_PLANET_START) {
74 74
       // Корректируем температуру для планеты-странника
75 75
       $position_data['t_max_max'] -= UNIVERSE_RANDOM_PLANET_TEMPERATURE_DECREASE * ($Position - UNIVERSE_RANDOM_PLANET_START);
76 76
     }
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 
79 79
   $planet_images = sn_get_groups('planet_images');
80 80
   $planet_image = $position_data['planet_images'][mt_rand(0, count($position_data['planet_images']) - 1)];
81
-  $planet_image .= 'planet' . $planet_images[$planet_image][mt_rand(0, count($planet_images[$planet_image]) - 1)];
81
+  $planet_image .= 'planet'.$planet_images[$planet_image][mt_rand(0, count($planet_images[$planet_image]) - 1)];
82 82
 
83 83
   $t_max = sn_rand_gauss_range($position_data['t_max_min'], $position_data['t_max_max'], true, 1.3, true);
84 84
   $t_min = $t_max - sn_rand_gauss_range($position_data['t_delta_min'], $position_data['t_delta_max'], true, 1.3, true);
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 
90 90
   $core_info = uni_create_planet_get_density($position_data, $user_row, $planet_sectors);
91 91
 
92
-  $planet_name_unsafe = $user_row['username'] . ' ' . ($planet_name_unsafe ? $planet_name_unsafe : classLocale::$lang['sys_colo_defaultname']);
92
+  $planet_name_unsafe = $user_row['username'].' '.($planet_name_unsafe ? $planet_name_unsafe : classLocale::$lang['sys_colo_defaultname']);
93 93
 
94 94
   $planet['name'] = db_escape(strip_tags(trim($planet_name_unsafe)));
95 95
   $planet['id_owner'] = $PlanetOwnerID;
@@ -170,15 +170,15 @@  discard block
 block discarded – undo
170 170
   $moon_name = '';
171 171
   $moon_row = array();
172 172
   $moon = db_planet_by_gspt($pos_galaxy, $pos_system, $pos_planet, PT_MOON, false, 'id');
173
-  if(!$moon['id']) {
173
+  if (!$moon['id']) {
174 174
     $moon_planet = db_planet_by_gspt($pos_galaxy, $pos_system, $pos_planet, PT_PLANET, true, '`id`, `temp_min`, `temp_max`, `name`, `debris_metal`, `debris_crystal`');
175 175
 
176
-    if($moon_planet['id']) {
176
+    if ($moon_planet['id']) {
177 177
       $base_storage_size = BASE_STORAGE_SIZE;
178 178
 
179
-      if(!$moon_chance) {
179
+      if (!$moon_chance) {
180 180
         $size = mt_rand(1100, 8999);
181
-      } elseif($moon_chance <= 100) {
181
+      } elseif ($moon_chance <= 100) {
182 182
         $size = mt_rand($moon_chance * 100 + 1000, $moon_chance * 200 + 2999);
183 183
       } else {
184 184
         $size = $moon_chance;
@@ -194,22 +194,22 @@  discard block
 block discarded – undo
194 194
 
195 195
       $field_max = ceil($size / 1000);
196 196
 
197
-      if(isset($options['image']) && $options['image']) {
197
+      if (isset($options['image']) && $options['image']) {
198 198
         $moon_image = $options['image'];
199 199
       } else {
200 200
         $moon_image = 'mond';
201 201
       }
202 202
 
203 203
       $moon_row = classSupernova::db_ins_record(LOC_PLANET,
204
-        "`id_owner` = '{$user_id}', `parent_planet` = '{$moon_planet['id']}', `name` = '{$moon_name_safe}', `last_update` = " . SN_TIME_NOW . ", `image` = '{$moon_image}',
205
-          `galaxy` = '{$pos_galaxy}', `system` = '{$pos_system}', `planet` = '{$pos_planet}', `planet_type` = " . PT_MOON . ",
204
+        "`id_owner` = '{$user_id}', `parent_planet` = '{$moon_planet['id']}', `name` = '{$moon_name_safe}', `last_update` = ".SN_TIME_NOW.", `image` = '{$moon_image}',
205
+          `galaxy` = '{$pos_galaxy}', `system` = '{$pos_system}', `planet` = '{$pos_planet}', `planet_type` = ".PT_MOON.",
206 206
           `diameter` = '{$size}', `field_max` = '{$field_max}', `density` = 2500, `density_index` = 2, `temp_min` = '{$temp_min}', `temp_max` = '{$temp_max}',
207 207
           `metal` = '0', `metal_perhour` = '0', `metal_max` = '{$base_storage_size}',
208 208
           `crystal` = '0', `crystal_perhour` = '0', `crystal_max` = '{$base_storage_size}',
209 209
           `deuterium` = '0', `deuterium_perhour` = '0', `deuterium_max` = '{$base_storage_size}'"
210 210
       );
211 211
 
212
-      if($update_debris) {
212
+      if ($update_debris) {
213 213
         $debris_spent = $moon_chance * 1000000;
214 214
         $metal_spent = round(min($moon_planet['debris_metal'], $debris_spent * mt_rand(50, 75) / 100));
215 215
         $crystal_spent = min($moon_planet['debris_crystal'], $debris_spent - $metal_spent);
@@ -244,28 +244,28 @@  discard block
 block discarded – undo
244 244
   $planet_row['id'] = $user['current_planet'];
245 245
 
246 246
   // Пытаемся переключить на новую планету
247
-  if(($selected_planet = sys_get_param_id('cp')) && $selected_planet != $user['current_planet']) {
247
+  if (($selected_planet = sys_get_param_id('cp')) && $selected_planet != $user['current_planet']) {
248 248
     $planet_row = db_planet_by_id_and_owner($selected_planet, $user['id'], false, 'id');
249 249
   } else {
250 250
     $planet_row = db_planet_by_id($planet_row['id']);
251 251
   }
252 252
 
253 253
   // Если новая планета не найдена или было переключения - проверяем текущую выбранную планету
254
-  if(!isset($planet_row['id'])) // || $planet_row['id'] != $user['current_planet']
254
+  if (!isset($planet_row['id'])) // || $planet_row['id'] != $user['current_planet']
255 255
   {
256 256
     $planet_row = db_planet_by_id_and_owner($user['current_planet'], $user['id'], false, 'id');
257 257
     // Если текущей планеты не существует - выставляем Столицу
258
-    if(!isset($planet_row['id'])) {
258
+    if (!isset($planet_row['id'])) {
259 259
       $planet_row = db_planet_by_id_and_owner($user['id_planet'], $user['id'], false, 'id');
260 260
       // Если и столицы не существует - значит что-то очень не так с записью пользователя
261
-      if(!isset($planet_row['id'])) {
261
+      if (!isset($planet_row['id'])) {
262 262
         classSupernova::$debug->error("User ID {$user['id']} has Capital planet {$user['id_planet']} but this planet does not exists", 'User record error', 502);
263 263
       }
264 264
     }
265 265
   }
266 266
 
267 267
   // Если производилось переключение планеты - делаем запись в юзере
268
-  if($user['current_planet'] != $planet_row['id']) {
268
+  if ($user['current_planet'] != $planet_row['id']) {
269 269
     db_user_set_by_id($user['id'], "`current_planet` = '{$planet_row['id']}'");
270 270
     $user['current_planet'] = $planet_row['id'];
271 271
   }
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 
283 283
 // ----------------------------------------------------------------------------------------------------------------
284 284
 function uni_render_coordinates($from, $prefix = '') {
285
-  return "[{$from[$prefix . 'galaxy']}:{$from[$prefix . 'system']}:{$from[$prefix . 'planet']}]";
285
+  return "[{$from[$prefix.'galaxy']}:{$from[$prefix.'system']}:{$from[$prefix.'planet']}]";
286 286
 }
287 287
 
288 288
 function uni_render_planet($from) {
@@ -290,17 +290,17 @@  discard block
 block discarded – undo
290 290
 }
291 291
 
292 292
 function uni_render_planet_full($from, $prefix = '', $html_safe = true, $include_id = false) {
293
-  if(!$from['id']) {
293
+  if (!$from['id']) {
294 294
     $result = classLocale::$lang['sys_planet_expedition'];
295 295
   } else {
296 296
     $from_planet_id = $include_id ? (
297
-      'ID {' . ($from['id'] ? $from['id'] : ($from[$prefix . 'planet_id'] ? $from[$prefix . 'planet_id'] : 0)) . '} '
297
+      'ID {'.($from['id'] ? $from['id'] : ($from[$prefix.'planet_id'] ? $from[$prefix.'planet_id'] : 0)).'} '
298 298
     ) : '';
299 299
 
300
-    $from_planet_type = $from['planet_type'] ? $from['planet_type'] : ($from[$prefix . 'type'] ? $from[$prefix . 'type'] : 0);
301
-    $from_planet_type = ($from_planet_type ? ' ' . classLocale::$lang['sys_planet_type_sh'][$from_planet_type] : '');
300
+    $from_planet_type = $from['planet_type'] ? $from['planet_type'] : ($from[$prefix.'type'] ? $from[$prefix.'type'] : 0);
301
+    $from_planet_type = ($from_planet_type ? ' '.classLocale::$lang['sys_planet_type_sh'][$from_planet_type] : '');
302 302
 
303
-    $result = $from_planet_id . uni_render_coordinates($from, $prefix) . $from_planet_type . ($from['name'] ? ' ' . $from['name'] : '');
303
+    $result = $from_planet_id.uni_render_coordinates($from, $prefix).$from_planet_type.($from['name'] ? ' '.$from['name'] : '');
304 304
     $result = $html_safe ? str_replace(' ', '&nbsp;', htmlentities($result, ENT_COMPAT, 'UTF-8')) : $result;
305 305
   }
306 306
 
@@ -308,11 +308,11 @@  discard block
 block discarded – undo
308 308
 }
309 309
 
310 310
 function uni_render_coordinates_url($from, $prefix = '', $page = 'galaxy.php') {
311
-  return $page . (strpos($page, '?') === false ? '?' : '&') . "galaxy={$from[$prefix . 'galaxy']}&system={$from[$prefix . 'system']}&planet={$from[$prefix . 'planet']}";
311
+  return $page.(strpos($page, '?') === false ? '?' : '&')."galaxy={$from[$prefix.'galaxy']}&system={$from[$prefix.'system']}&planet={$from[$prefix.'planet']}";
312 312
 }
313 313
 
314 314
 function uni_render_coordinates_href($from, $prefix = '', $mode = 0, $fleet_type = '') {
315
-  return '<a href="' . uni_render_coordinates_url($from, $prefix, "galaxy.php?mode={$mode}") . '"' . ($fleet_type ? " {$fleet_type}" : '') . '>' . uni_render_coordinates($from, $prefix) . '</a>';
315
+  return '<a href="'.uni_render_coordinates_url($from, $prefix, "galaxy.php?mode={$mode}").'"'.($fleet_type ? " {$fleet_type}" : '').'>'.uni_render_coordinates($from, $prefix).'</a>';
316 316
 }
317 317
 
318 318
 function uni_get_time_to_jump($moon_row) {
@@ -340,30 +340,30 @@  discard block
 block discarded – undo
340 340
   $coordinates["{$prefix}planet"] = intval($coordinates["{$prefix}planet"]);
341 341
 
342 342
   return
343
-    isset($coordinates["{$prefix}galaxy"]) && $coordinates["{$prefix}galaxy"] > 0 && $coordinates["{$prefix}galaxy"] <= Vector::$knownGalaxies&&
344
-    isset($coordinates["{$prefix}system"]) && $coordinates["{$prefix}system"] > 0 && $coordinates["{$prefix}system"] <= Vector::$knownSystems&&
343
+    isset($coordinates["{$prefix}galaxy"]) && $coordinates["{$prefix}galaxy"] > 0 && $coordinates["{$prefix}galaxy"] <= Vector::$knownGalaxies &&
344
+    isset($coordinates["{$prefix}system"]) && $coordinates["{$prefix}system"] > 0 && $coordinates["{$prefix}system"] <= Vector::$knownSystems &&
345 345
     isset($coordinates["{$prefix}planet"]) && $coordinates["{$prefix}planet"] > 0 && $coordinates["{$prefix}planet"] <= Vector::$knownPlanets;
346 346
 }
347 347
 
348 348
 function uni_planet_teleport_check($user, $planetrow, $new_coordinates = null) {
349 349
   try {
350
-    if($planetrow['planet_teleport_next'] && $planetrow['planet_teleport_next'] > SN_TIME_NOW) {
350
+    if ($planetrow['planet_teleport_next'] && $planetrow['planet_teleport_next'] > SN_TIME_NOW) {
351 351
       throw new exception(classLocale::$lang['ov_teleport_err_cooldown'], ERR_ERROR);
352 352
     }
353 353
 
354
-    if(mrc_get_level($user, null, RES_DARK_MATTER) < classSupernova::$config->planet_teleport_cost) {
354
+    if (mrc_get_level($user, null, RES_DARK_MATTER) < classSupernova::$config->planet_teleport_cost) {
355 355
       throw new exception(classLocale::$lang['ov_teleport_err_no_dark_matter'], ERR_ERROR);
356 356
     }
357 357
 
358 358
     // TODO: Replace quick-check with using gathered flying fleet data
359
-    if(FleetList::fleet_count_incoming($planetrow['galaxy'], $planetrow['system'], $planetrow['planet'])) {
359
+    if (FleetList::fleet_count_incoming($planetrow['galaxy'], $planetrow['system'], $planetrow['planet'])) {
360 360
       throw new exception(classLocale::$lang['ov_teleport_err_fleet'], ERR_ERROR);
361 361
     }
362 362
 
363
-    if(is_array($new_coordinates)) {
363
+    if (is_array($new_coordinates)) {
364 364
       $new_coordinates['planet_type'] = PT_PLANET;
365 365
       $incoming = db_planet_by_vector($new_coordinates, '', true, 'id');
366
-      if($incoming['id']) {
366
+      if ($incoming['id']) {
367 367
         throw new exception(classLocale::$lang['ov_teleport_err_destination_busy'], ERR_ERROR);
368 368
       }
369 369
     }
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
       'result'  => ERR_NONE,
373 373
       'message' => '',
374 374
     );
375
-  } catch(exception $e) {
375
+  } catch (exception $e) {
376 376
     $response = array(
377 377
       'result'  => $e->getCode(),
378 378
       'message' => $e->getMessage(),
Please login to merge, or discard this patch.
includes/general/math.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,11 +37,11 @@
 block discarded – undo
37 37
 /**
38 38
  * @param float      $range_start - Начало диапазона
39 39
  * @param float      $range_end - Конец диапазона
40
- * @param bool|int  $round - До скольки знаков округлять результат. False - не округлять, True - округлять до целого, 1 - округлять до десятков, 2 - до сотен итд
40
+ * @param boolean  $round - До скольки знаков округлять результат. False - не округлять, True - округлять до целого, 1 - округлять до десятков, 2 - до сотен итд
41 41
  * @param int        $strict - В сколько сигм надо уложить результат
42 42
  * @param bool|false $cut_extreme - надо ли обрезать крайние значения. Например, при $strict = 2 их слишком много
43 43
  *
44
- * @return float|int
44
+ * @return double
45 45
  */
46 46
 function sn_rand_gauss_range($range_start, $range_end, $round = true, $strict = 4, $cut_extreme = false)  {
47 47
   if($cut_extreme) {
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 function geometry_progression_sum($n, $b1, $q) {
4
-  return $q != 1 ? ($b1 * (pow($q, $n) - 1)/($q - 1)) : ($n * $b1);
4
+  return $q != 1 ? ($b1 * (pow($q, $n) - 1) / ($q - 1)) : ($n * $b1);
5 5
 }
6 6
 
7 7
 function sn_floor($value)
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
  *
44 44
  * @return float|int
45 45
  */
46
-function sn_rand_gauss_range($range_start, $range_end, $round = true, $strict = 4, $cut_extreme = false)  {
47
-  if($cut_extreme) {
46
+function sn_rand_gauss_range($range_start, $range_end, $round = true, $strict = 4, $cut_extreme = false) {
47
+  if ($cut_extreme) {
48 48
     $range_start--;
49 49
     $range_end++;
50 50
   }
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 {
61 61
   $args = func_get_args();
62 62
 
63
-  switch(func_num_args())
63
+  switch (func_num_args())
64 64
   {
65 65
     case 0:
66 66
       // trigger_error('median() requires at least one parameter',E_USER_WARNING);
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
     // fallthrough
73 73
 
74 74
     default:
75
-      if(!is_array($args))
75
+      if (!is_array($args))
76 76
       {
77 77
         // trigger_error('median() requires a list of numbers to operate on or an array of numbers', E_USER_NOTICE);
78 78
         return false;
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
       $n = count($args);
84 84
       $h = intval($n / 2);
85 85
 
86
-      if($n % 2 == 0)
86
+      if ($n % 2 == 0)
87 87
       {
88
-        $median = ($args[$h] + $args[$h-1]) / 2;
88
+        $median = ($args[$h] + $args[$h - 1]) / 2;
89 89
       }
90 90
       else
91 91
       {
@@ -103,49 +103,49 @@  discard block
 block discarded – undo
103 103
 }
104 104
 function linear_calc(&$linear, $from = 0, $logProcess = false)
105 105
 {
106
-  for($i = $from; $i < count($linear); $i++)
106
+  for ($i = $from; $i < count($linear); $i++)
107 107
   {
108 108
     $eq = &$linear[$i];
109
-    for($j = count($eq) - 1; $j >= $from; $j--)
109
+    for ($j = count($eq) - 1; $j >= $from; $j--)
110 110
     {
111 111
       $eq[$j] /= $eq[$from];
112 112
     }
113 113
   }
114
-  if($logProcess) pdump($linear, 'Нормализовано по х' . $from);
114
+  if ($logProcess) pdump($linear, 'Нормализовано по х'.$from);
115 115
 
116
-  for($i = $from + 1; $i < count($linear); $i++)
116
+  for ($i = $from + 1; $i < count($linear); $i++)
117 117
   {
118 118
     $eq = &$linear[$i];
119
-    for($j = count($eq) - 1; $j >= $from; $j--)
119
+    for ($j = count($eq) - 1; $j >= $from; $j--)
120 120
     {
121 121
       $eq[$j] -= $linear[$from][$j];
122 122
     }
123 123
   }
124
-  if($logProcess) pdump($linear, 'Подставили х' . $from);
124
+  if ($logProcess) pdump($linear, 'Подставили х'.$from);
125 125
 
126
-  if($from < count($linear) - 1)
126
+  if ($from < count($linear) - 1)
127 127
   {
128 128
     linear_calc($linear, $from + 1, $logProcess);
129 129
   }
130 130
 
131
-  if($from)
131
+  if ($from)
132 132
   {
133
-    for($i = 0; $i < $from; $i++)
133
+    for ($i = 0; $i < $from; $i++)
134 134
     {
135 135
       $eq = &$linear[$i];
136
-      for($j = count($eq) - 1; $j >= $from; $j--)
136
+      for ($j = count($eq) - 1; $j >= $from; $j--)
137 137
       {
138 138
         $eq[$j] = $eq[$j] - $eq[$from] * $linear[$from][$j];
139 139
       }
140 140
     }
141
-    if($logProcess) pdump($linear, 'Подставили обратно х' . $from);
141
+    if ($logProcess) pdump($linear, 'Подставили обратно х'.$from);
142 142
   }
143 143
   else
144 144
   {
145
-    if($logProcess) pdump($linear, 'Результат' . $from);
146
-    foreach($linear as $index => &$eq)
145
+    if ($logProcess) pdump($linear, 'Результат'.$from);
146
+    foreach ($linear as $index => &$eq)
147 147
     {
148
-      pdump($eq[count($linear)], 'x' . $index);
148
+      pdump($eq[count($linear)], 'x'.$index);
149 149
     }
150 150
   }
151 151
 }
Please login to merge, or discard this patch.
Braces   +14 added lines, -8 removed lines patch added patch discarded remove patch
@@ -86,8 +86,7 @@  discard block
 block discarded – undo
86 86
       if($n % 2 == 0)
87 87
       {
88 88
         $median = ($args[$h] + $args[$h-1]) / 2;
89
-      }
90
-      else
89
+      } else
91 90
       {
92 91
         $median = $args[$h];
93 92
       }
@@ -111,7 +110,9 @@  discard block
 block discarded – undo
111 110
       $eq[$j] /= $eq[$from];
112 111
     }
113 112
   }
114
-  if($logProcess) pdump($linear, 'Нормализовано по х' . $from);
113
+  if($logProcess) {
114
+    pdump($linear, 'Нормализовано по х' . $from);
115
+  }
115 116
 
116 117
   for($i = $from + 1; $i < count($linear); $i++)
117 118
   {
@@ -121,7 +122,9 @@  discard block
 block discarded – undo
121 122
       $eq[$j] -= $linear[$from][$j];
122 123
     }
123 124
   }
124
-  if($logProcess) pdump($linear, 'Подставили х' . $from);
125
+  if($logProcess) {
126
+    pdump($linear, 'Подставили х' . $from);
127
+  }
125 128
 
126 129
   if($from < count($linear) - 1)
127 130
   {
@@ -138,11 +141,14 @@  discard block
 block discarded – undo
138 141
         $eq[$j] = $eq[$j] - $eq[$from] * $linear[$from][$j];
139 142
       }
140 143
     }
141
-    if($logProcess) pdump($linear, 'Подставили обратно х' . $from);
142
-  }
143
-  else
144
+    if($logProcess) {
145
+      pdump($linear, 'Подставили обратно х' . $from);
146
+    }
147
+  } else
144 148
   {
145
-    if($logProcess) pdump($linear, 'Результат' . $from);
149
+    if($logProcess) {
150
+      pdump($linear, 'Результат' . $from);
151
+    }
146 152
     foreach($linear as $index => &$eq)
147 153
     {
148 154
       pdump($eq[count($linear)], 'x' . $index);
Please login to merge, or discard this patch.
includes/includes/flt_functions.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
+/**
4
+ * @return double
5
+ */
3 6
 function flt_fleet_speed($user, $fleet)
4 7
 {
5 8
   if (!is_array($fleet))
Please login to merge, or discard this patch.
Spacing   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 function flt_fleet_speed($user, $fleet) {
4
-  if(!is_array($fleet)) {
4
+  if (!is_array($fleet)) {
5 5
     $fleet = array($fleet => 1);
6 6
   }
7 7
 
8 8
   $speeds = array();
9
-  if(!empty($fleet)) {
10
-    foreach($fleet as $ship_id => $amount) {
11
-      if($amount && in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) {
9
+  if (!empty($fleet)) {
10
+    foreach ($fleet as $ship_id => $amount) {
11
+      if ($amount && in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) {
12 12
         $single_ship_data = get_ship_data($ship_id, $user);
13 13
         $speeds[] = $single_ship_data['speed'];
14 14
       }
@@ -51,14 +51,14 @@  discard block
 block discarded – undo
51 51
 
52 52
   $game_fleet_speed = flt_server_flight_speed_multiplier();
53 53
   $fleet_speed = flt_fleet_speed($user_row, $fleet_array);
54
-  if(!empty($fleet_array) && $fleet_speed && $game_fleet_speed) {
54
+  if (!empty($fleet_array) && $fleet_speed && $game_fleet_speed) {
55 55
     $speed_percent = $speed_percent ? max(min($speed_percent, 10), 1) : 10;
56 56
     $real_speed = $speed_percent * sqrt($fleet_speed);
57 57
 
58 58
     $duration = max(1, round((35000 / $speed_percent * sqrt($distance * 10 / $fleet_speed) + 10) / $game_fleet_speed));
59 59
 
60
-    foreach($fleet_array as $ship_id => $ship_count) {
61
-      if(!$ship_id || !$ship_count) {
60
+    foreach ($fleet_array as $ship_id => $ship_count) {
61
+      if (!$ship_id || !$ship_count) {
62 62
         continue;
63 63
       }
64 64
 
@@ -86,19 +86,19 @@  discard block
 block discarded – undo
86 86
 function flt_bashing_check($user, $enemy, $planet_dst, $mission, $flight_duration, $fleet_group = 0) {
87 87
   $config_bashing_attacks = classSupernova::$config->fleet_bashing_attacks;
88 88
   $config_bashing_interval = classSupernova::$config->fleet_bashing_interval;
89
-  if(!$config_bashing_attacks) {
89
+  if (!$config_bashing_attacks) {
90 90
     // Bashing allowed - protection disabled
91 91
     return FLIGHT_ALLOWED;
92 92
   }
93 93
 
94 94
   $bashing_result = FLIGHT_MISSION_ATTACK_BASHING;
95
-  if($user['ally_id'] && $enemy['ally_id']) {
95
+  if ($user['ally_id'] && $enemy['ally_id']) {
96 96
     $relations = ali_relations($user['ally_id'], $enemy['ally_id']);
97
-    if(!empty($relations)) {
97
+    if (!empty($relations)) {
98 98
       $relations = $relations[$enemy['ally_id']];
99
-      switch($relations['alliance_diplomacy_relation']) {
99
+      switch ($relations['alliance_diplomacy_relation']) {
100 100
         case ALLY_DIPLOMACY_WAR:
101
-          if(SN_TIME_NOW - $relations['alliance_diplomacy_time'] <= classSupernova::$config->fleet_bashing_war_delay) {
101
+          if (SN_TIME_NOW - $relations['alliance_diplomacy_time'] <= classSupernova::$config->fleet_bashing_war_delay) {
102 102
             $bashing_result = FLIGHT_MISSION_ATTACK_BASHING_WAR_DELAY;
103 103
           } else {
104 104
             return FLIGHT_ALLOWED;
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
 
121 121
   // Retrieving flying fleets
122 122
   $objFleetsBashing = FleetList::dbGetFleetListBashing($user['id'], $planet_dst);
123
-  foreach($objFleetsBashing->_container as $fleetBashing) {
123
+  foreach ($objFleetsBashing->_container as $fleetBashing) {
124 124
     // Checking for ACS - each ACS count only once
125
-    if($fleetBashing->group_id) {
125
+    if ($fleetBashing->group_id) {
126 126
       $bashing_list["{$user['id']}_{$fleetBashing->group_id}"] = $fleetBashing->time_arrive_to_target;
127 127
     } else {
128 128
       $bashing_list[] = $fleetBashing->time_arrive_to_target;
@@ -130,12 +130,12 @@  discard block
 block discarded – undo
130 130
   }
131 131
 
132 132
   // Check for joining to ACS - if there are already fleets in ACS no checks should be done
133
-  if($mission == MT_ACS && $bashing_list["{$user['id']}_{$fleet_group}"]) {
133
+  if ($mission == MT_ACS && $bashing_list["{$user['id']}_{$fleet_group}"]) {
134 134
     return FLIGHT_ALLOWED;
135 135
   }
136 136
 
137 137
   $query = db_bashing_list_get($user, $planet_dst, $time_limit);
138
-  while($bashing_row = db_fetch($query)) {
138
+  while ($bashing_row = db_fetch($query)) {
139 139
     $bashing_list[] = $bashing_row['bashing_time'];
140 140
   }
141 141
 
@@ -144,9 +144,9 @@  discard block
 block discarded – undo
144 144
   $last_attack = 0;
145 145
   $wave = 0;
146 146
   $attack = 1;
147
-  foreach($bashing_list as &$bash_time) {
147
+  foreach ($bashing_list as &$bash_time) {
148 148
     $attack++;
149
-    if($bash_time - $last_attack > $config_bashing_interval || $attack > $config_bashing_attacks) {
149
+    if ($bash_time - $last_attack > $config_bashing_interval || $attack > $config_bashing_attacks) {
150 150
       $attack = 1;
151 151
       $wave++;
152 152
     }
@@ -163,16 +163,16 @@  discard block
 block discarded – undo
163 163
   //TODO: try..catch
164 164
   global $user;
165 165
 
166
-  if($user['vacation']) {
166
+  if ($user['vacation']) {
167 167
     return $result = FLIGHT_PLAYER_VACATION_OWN;
168 168
   }
169 169
 
170
-  if(empty($fleet) || !is_array($fleet)) {
170
+  if (empty($fleet) || !is_array($fleet)) {
171 171
     return $result = FLIGHT_SHIPS_NO_SHIPS;
172 172
   }
173 173
 
174 174
   $sn_groups_mission = sn_get_groups('missions');
175
-  if(!isset($sn_groups_mission[$mission])) {
175
+  if (!isset($sn_groups_mission[$mission])) {
176 176
     return $result = FLIGHT_MISSION_UNKNOWN;
177 177
   }
178 178
   $sn_data_mission = $sn_groups_mission[$mission];
@@ -191,32 +191,32 @@  discard block
 block discarded – undo
191 191
   $resources = 0;
192 192
   $ship_ids = sn_get_groups('fleet');
193 193
   $resource_ids = sn_get_groups('resources_loot');
194
-  foreach($fleet as $ship_id => $ship_count) {
194
+  foreach ($fleet as $ship_id => $ship_count) {
195 195
     $is_ship = in_array($ship_id, $ship_ids);
196 196
     $is_resource = in_array($ship_id, $resource_ids);
197
-    if(!$is_ship && !$is_resource) {
197
+    if (!$is_ship && !$is_resource) {
198 198
       // TODO Спецобработчик для Капитана и модулей
199 199
 //      return FLIGHT_SHIPS_UNIT_WRONG;
200 200
     }
201 201
 
202
-    if($ship_count < 0) {
202
+    if ($ship_count < 0) {
203 203
       return $result = $is_ship ? FLIGHT_SHIPS_NEGATIVE : FLIGHT_RESOURCES_NEGATIVE;
204 204
     }
205 205
 
206
-    if($ship_count > mrc_get_level($user, $planet_src, $ship_id)) {
206
+    if ($ship_count > mrc_get_level($user, $planet_src, $ship_id)) {
207 207
       // TODO FLIGHT_MISSION_MISSILE_NO_MISSILES
208 208
       return $result = $is_ship ? FLIGHT_SHIPS_NOT_ENOUGH_OR_RESOURCES : FLIGHT_RESOURCES_NOT_ENOUGH;
209 209
     }
210 210
 
211
-    if($is_ship) {
211
+    if ($is_ship) {
212 212
       $single_ship_data = get_ship_data($ship_id, $user);
213
-      if($single_ship_data[P_SPEED] <= 0) {
213
+      if ($single_ship_data[P_SPEED] <= 0) {
214 214
         return $result = FLIGHT_SHIPS_UNMOVABLE;
215 215
       }
216 216
       $ships += $ship_count;
217 217
       $recyclers += in_array($ship_id, sn_get_groups('flt_recyclers')) ? $ship_count : 0;
218 218
       $spies += $ship_id == SHIP_SPY ? $ship_count : 0;
219
-    } elseif($is_resource) {
219
+    } elseif ($is_resource) {
220 220
       $resources += $ship_count;
221 221
     }
222 222
   }
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
     }
228 228
   */
229 229
 
230
-  if(isset($options['resources']) && $options['resources'] > 0 && !(isset($sn_data_mission['transport']) && $sn_data_mission['transport'])) {
230
+  if (isset($options['resources']) && $options['resources'] > 0 && !(isset($sn_data_mission['transport']) && $sn_data_mission['transport'])) {
231 231
     return $result = FLIGHT_RESOURCES_FORBIDDEN;
232 232
   }
233 233
 
@@ -239,78 +239,78 @@  discard block
 block discarded – undo
239 239
   */
240 240
 
241 241
   $speed = $options['fleet_speed_percent'];
242
-  if($speed && ($speed != intval($speed) || $speed < 1 || $speed > 10)) {
242
+  if ($speed && ($speed != intval($speed) || $speed < 1 || $speed > 10)) {
243 243
     return $result = FLIGHT_FLEET_SPEED_WRONG;
244 244
   }
245 245
 
246 246
   $travel_data = flt_travel_data($user, $planet_src, $planet_dst, $fleet, $options['fleet_speed_percent']);
247 247
 
248 248
 
249
-  if(mrc_get_level($user, $planet_src, RES_DEUTERIUM) < $fleet[RES_DEUTERIUM] + $travel_data['consumption']) {
249
+  if (mrc_get_level($user, $planet_src, RES_DEUTERIUM) < $fleet[RES_DEUTERIUM] + $travel_data['consumption']) {
250 250
     return $result = FLIGHT_RESOURCES_FUEL_NOT_ENOUGH;
251 251
   }
252 252
 
253
-  if($travel_data['consumption'] > $travel_data['capacity']) {
253
+  if ($travel_data['consumption'] > $travel_data['capacity']) {
254 254
     return $result = FLIGHT_FLEET_TOO_FAR;
255 255
   }
256 256
 
257
-  if($travel_data['hold'] < $resources) {
257
+  if ($travel_data['hold'] < $resources) {
258 258
     return $result = FLIGHT_FLEET_OVERLOAD;
259 259
   }
260 260
 
261 261
   $fleet_start_time = SN_TIME_NOW + $travel_data['duration'];
262 262
 
263 263
   $fleet_group = $options['fleet_group'];
264
-  if($fleet_group) {
265
-    if($mission != MT_ACS) {
264
+  if ($fleet_group) {
265
+    if ($mission != MT_ACS) {
266 266
       return $result = FLIGHT_MISSION_IMPOSSIBLE;
267 267
     };
268 268
 
269 269
     $acs = db_acs_get_by_group_id($fleet_group);
270
-    if(!$acs['id']) {
270
+    if (!$acs['id']) {
271 271
       return $result = FLIGHT_MISSION_ACS_NOT_EXISTS;
272 272
     }
273 273
 
274
-    if($planet_dst['galaxy'] != $acs['galaxy'] || $planet_dst['system'] != $acs['system'] || $planet_dst['planet'] != $acs['planet'] || $planet_dst['planet_type'] != $acs['planet_type']) {
274
+    if ($planet_dst['galaxy'] != $acs['galaxy'] || $planet_dst['system'] != $acs['system'] || $planet_dst['planet'] != $acs['planet'] || $planet_dst['planet_type'] != $acs['planet_type']) {
275 275
       return $result = FLIGHT_MISSION_ACS_WRONG_TARGET;
276 276
     }
277 277
 
278
-    if($fleet_start_time > $acs['ankunft']) {
278
+    if ($fleet_start_time > $acs['ankunft']) {
279 279
       return $result = FLIGHT_MISSION_ACS_TOO_LATE;
280 280
     }
281 281
   }
282 282
 
283 283
   $flying_fleets = $options['flying_fleets'];
284
-  if(!$flying_fleets) {
284
+  if (!$flying_fleets) {
285 285
     $flying_fleets = FleetList::fleet_count_flying($user['id']);
286 286
   }
287
-  if(GetMaxFleets($user) <= $flying_fleets && $mission != MT_MISSILE) {
287
+  if (GetMaxFleets($user) <= $flying_fleets && $mission != MT_MISSILE) {
288 288
     return $result = FLIGHT_FLEET_NO_SLOTS;
289 289
   }
290 290
 
291 291
   // В одиночку шпионские зонды могут летать только в миссии Шпионаж, Передислокация и Транспорт
292
-  if($ships && $spies && $spies == $ships && !($mission == MT_SPY || $mission == MT_RELOCATE || $mission == MT_TRANSPORT)) {
292
+  if ($ships && $spies && $spies == $ships && !($mission == MT_SPY || $mission == MT_RELOCATE || $mission == MT_TRANSPORT)) {
293 293
     return $result = FLIGHT_SHIPS_NOT_ONLY_SPIES;
294 294
   }
295 295
 
296 296
   // Checking for no planet
297
-  if(!$planet_dst['id_owner']) {
298
-    if($mission == MT_COLONIZE && !$fleet[SHIP_COLONIZER]) {
297
+  if (!$planet_dst['id_owner']) {
298
+    if ($mission == MT_COLONIZE && !$fleet[SHIP_COLONIZER]) {
299 299
       return $result = FLIGHT_SHIPS_NO_COLONIZER;
300 300
     }
301 301
 
302
-    if($mission == MT_EXPLORE || $mission == MT_COLONIZE) {
302
+    if ($mission == MT_EXPLORE || $mission == MT_COLONIZE) {
303 303
       return $result = FLIGHT_ALLOWED;
304 304
     }
305 305
 
306 306
     return $result = FLIGHT_VECTOR_NO_TARGET;
307 307
   }
308 308
 
309
-  if($mission == MT_RECYCLE) {
310
-    if($planet_dst['debris_metal'] + $planet_dst['debris_crystal'] <= 0) {
309
+  if ($mission == MT_RECYCLE) {
310
+    if ($planet_dst['debris_metal'] + $planet_dst['debris_crystal'] <= 0) {
311 311
       return $result = FLIGHT_MISSION_RECYCLE_NO_DEBRIS;
312 312
     }
313
-    if($recyclers <= 0) {
313
+    if ($recyclers <= 0) {
314 314
       return $result = FLIGHT_SHIPS_NO_RECYCLERS;
315 315
     }
316 316
 
@@ -318,8 +318,8 @@  discard block
 block discarded – undo
318 318
   }
319 319
 
320 320
   // Got planet. Checking if it is ours
321
-  if($planet_dst['id_owner'] == $user['id']) {
322
-    if($mission == MT_TRANSPORT || $mission == MT_RELOCATE) {
321
+  if ($planet_dst['id_owner'] == $user['id']) {
322
+    if ($mission == MT_TRANSPORT || $mission == MT_RELOCATE) {
323 323
       return $result = FLIGHT_ALLOWED;
324 324
     }
325 325
 
@@ -327,19 +327,19 @@  discard block
 block discarded – undo
327 327
   }
328 328
 
329 329
   // No, planet not ours. Cutting mission that can't be send to not-ours planet
330
-  if($mission == MT_RELOCATE || $mission == MT_COLONIZE || $mission == MT_EXPLORE) {
330
+  if ($mission == MT_RELOCATE || $mission == MT_COLONIZE || $mission == MT_EXPLORE) {
331 331
     return $result = FLIGHT_MISSION_IMPOSSIBLE;
332 332
   }
333 333
 
334 334
   $enemy = db_user_by_id($planet_dst['id_owner']);
335 335
   // We cannot attack or send resource to users in VACATION mode
336
-  if($enemy['vacation'] && $mission != MT_RECYCLE) {
336
+  if ($enemy['vacation'] && $mission != MT_RECYCLE) {
337 337
     return $result = FLIGHT_PLAYER_VACATION;
338 338
   }
339 339
 
340 340
   // Multi IP protection
341 341
   // TODO: Here we need a procedure to check proxies
342
-  if(sys_is_multiaccount($user, $enemy)) {
342
+  if (sys_is_multiaccount($user, $enemy)) {
343 343
     return $result = FLIGHT_PLAYER_SAME_IP;
344 344
   }
345 345
 
@@ -347,8 +347,8 @@  discard block
 block discarded – undo
347 347
   $enemy_points = $enemy['total_points'];
348 348
 
349 349
   // Is it transport? If yes - checking for buffing to prevent mega-alliance destroyer
350
-  if($mission == MT_TRANSPORT) {
351
-    if($user_points >= $enemy_points || classSupernova::$config->allow_buffing) {
350
+  if ($mission == MT_TRANSPORT) {
351
+    if ($user_points >= $enemy_points || classSupernova::$config->allow_buffing) {
352 352
       return $result = FLIGHT_ALLOWED;
353 353
     } else {
354 354
       return $result = FLIGHT_PLAYER_BUFFING;
@@ -358,66 +358,66 @@  discard block
 block discarded – undo
358 358
   // Only aggresive missions passed to this point. HOLD counts as passive but aggresive
359 359
 
360 360
   // Is it admin with planet protection?
361
-  if($planet_dst['id_level'] > $user['authlevel']) {
361
+  if ($planet_dst['id_level'] > $user['authlevel']) {
362 362
     return $result = FLIGHT_PLAYER_ADMIN;
363 363
   }
364 364
 
365 365
   // Okay. Now skipping protection checks for inactive longer then 1 week
366
-  if(!$enemy['onlinetime'] || $enemy['onlinetime'] >= (SN_TIME_NOW - 60 * 60 * 24 * 7)) {
367
-    if(
366
+  if (!$enemy['onlinetime'] || $enemy['onlinetime'] >= (SN_TIME_NOW - 60 * 60 * 24 * 7)) {
367
+    if (
368 368
       ($enemy_points <= classSupernova::$config->game_noob_points && $user_points > classSupernova::$config->game_noob_points)
369 369
       ||
370 370
       (classSupernova::$config->game_noob_factor && $user_points > $enemy_points * classSupernova::$config->game_noob_factor)
371 371
     ) {
372
-      if($mission != MT_HOLD) {
372
+      if ($mission != MT_HOLD) {
373 373
         return $result = FLIGHT_PLAYER_NOOB;
374 374
       }
375
-      if($mission == MT_HOLD && !($user['ally_id'] && $user['ally_id'] == $enemy['ally_id'] && classSupernova::$config->ally_help_weak)) {
375
+      if ($mission == MT_HOLD && !($user['ally_id'] && $user['ally_id'] == $enemy['ally_id'] && classSupernova::$config->ally_help_weak)) {
376 376
         return $result = FLIGHT_PLAYER_NOOB;
377 377
       }
378 378
     }
379 379
   }
380 380
 
381 381
   // Is it HOLD mission? If yes - there should be ally deposit
382
-  if($mission == MT_HOLD) {
383
-    if(mrc_get_level($user, $planet_dst, STRUC_ALLY_DEPOSIT)) {
382
+  if ($mission == MT_HOLD) {
383
+    if (mrc_get_level($user, $planet_dst, STRUC_ALLY_DEPOSIT)) {
384 384
       return $result = FLIGHT_ALLOWED;
385 385
     }
386 386
 
387 387
     return $result = FLIGHT_MISSION_HOLD_NO_ALLY_DEPOSIT;
388 388
   }
389 389
 
390
-  if($mission == MT_SPY) {
390
+  if ($mission == MT_SPY) {
391 391
     return $result = $spies >= 1 ? FLIGHT_ALLOWED : FLIGHT_MISSION_SPY_NO_SPIES;
392 392
   }
393 393
 
394 394
   // Is it MISSILE mission?
395
-  if($mission == MT_MISSILE) {
395
+  if ($mission == MT_MISSILE) {
396 396
     $sn_data_mip = get_unit_param(UNIT_DEF_MISSILE_INTERPLANET);
397
-    if(mrc_get_level($user, $planet_src, STRUC_SILO) < $sn_data_mip[P_REQUIRE][STRUC_SILO]) {
397
+    if (mrc_get_level($user, $planet_src, STRUC_SILO) < $sn_data_mip[P_REQUIRE][STRUC_SILO]) {
398 398
       return $result = FLIGHT_MISSION_MISSILE_NO_SILO;
399 399
     }
400 400
 
401
-    if(!$fleet[UNIT_DEF_MISSILE_INTERPLANET]) {
401
+    if (!$fleet[UNIT_DEF_MISSILE_INTERPLANET]) {
402 402
       return $result = FLIGHT_MISSION_MISSILE_NO_MISSILES;
403 403
     }
404 404
 
405 405
     $distance = abs($planet_dst['system'] - $planet_src['system']);
406 406
     $mip_range = flt_get_missile_range($user);
407
-    if($distance > $mip_range || $planet_dst['galaxy'] != $planet_src['galaxy']) {
407
+    if ($distance > $mip_range || $planet_dst['galaxy'] != $planet_src['galaxy']) {
408 408
       return $result = FLIGHT_MISSION_MISSILE_TOO_FAR;
409 409
     }
410 410
 
411
-    if(isset($options['target_structure']) && $options['target_structure'] && !in_array($options['target_structure'], sn_get_groups('defense_active'))) {
411
+    if (isset($options['target_structure']) && $options['target_structure'] && !in_array($options['target_structure'], sn_get_groups('defense_active'))) {
412 412
       return $result = FLIGHT_MISSION_MISSILE_WRONG_STRUCTURE;
413 413
     }
414 414
   }
415 415
 
416
-  if($mission == MT_DESTROY && $planet_dst['planet_type'] != PT_MOON) {
416
+  if ($mission == MT_DESTROY && $planet_dst['planet_type'] != PT_MOON) {
417 417
     return $result = FLIGHT_MISSION_IMPOSSIBLE;
418 418
   }
419 419
 
420
-  if($mission == MT_ATTACK || $mission == MT_ACS || $mission == MT_DESTROY) {
420
+  if ($mission == MT_ATTACK || $mission == MT_ACS || $mission == MT_DESTROY) {
421 421
     return $result = flt_bashing_check($user, $enemy, $planet_dst, $mission, $travel_data['duration'], $fleet_group);
422 422
   }
423 423
 
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
   $from = $from['planet'];
445 445
 
446 446
   $can_attack = flt_can_attack($from, $to, $fleet_REAL_array, $mission, $options);
447
-  if($can_attack != FLIGHT_ALLOWED) {
447
+  if ($can_attack != FLIGHT_ALLOWED) {
448 448
     $internal_transaction ? sn_db_transaction_rollback() : false;
449 449
 
450 450
     return $can_attack;
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
   $travel_data = flt_travel_data($user, $from, $to, $fleet_REAL_array, $options['fleet_speed_percent']);
456 456
 
457 457
   $time_on_mission = 0;
458
-  if($mission == MT_EXPLORE || $mission == MT_HOLD) {
458
+  if ($mission == MT_EXPLORE || $mission == MT_HOLD) {
459 459
     // TODO - include some checks about maximum and minumum stay_duration
460 460
     $time_on_mission = $options['stay_time'] * 3600;
461 461
   }
@@ -478,14 +478,14 @@  discard block
 block discarded – undo
478 478
   $sn_group_resources_loot = sn_get_groups('resources_loot');
479 479
   $db_changeset = array();
480 480
   $planet_row_changed_fields = array();
481
-  foreach($fleet_REAL_array as $unit_id => $amount) {
482
-    if(!$amount || !$unit_id) {
481
+  foreach ($fleet_REAL_array as $unit_id => $amount) {
482
+    if (!$amount || !$unit_id) {
483 483
       continue;
484 484
     }
485 485
 
486
-    if(in_array($unit_id, $sn_group_fleet)) {
486
+    if (in_array($unit_id, $sn_group_fleet)) {
487 487
       $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, -$amount, $user, $from['id']);
488
-    } elseif(in_array($unit_id, $sn_group_resources_loot)) {
488
+    } elseif (in_array($unit_id, $sn_group_resources_loot)) {
489 489
       $planet_row_changed_fields[pname_resource_name($unit_id)]['delta'] -= $amount;
490 490
     }
491 491
   }
@@ -524,16 +524,16 @@  discard block
 block discarded – undo
524 524
 
525 525
   $ship_data = array();
526 526
   $fleet_array = array();
527
-  foreach($ship_list as $transport_id => $cork) {
527
+  foreach ($ship_list as $transport_id => $cork) {
528 528
     $ship_data[$transport_id] = flt_travel_data($user, $from, $to, array($transport_id => 1), 10);
529 529
   }
530 530
   uasort($ship_data, 'flt_calculate_ship_to_transport_sort');
531 531
 
532 532
   $fleet_capacity = 0;
533 533
   $fuel_total = $fuel_left = mrc_get_level($user, $from, RES_DEUTERIUM);
534
-  foreach($ship_data as $transport_id => &$ship_info) {
534
+  foreach ($ship_data as $transport_id => &$ship_info) {
535 535
     $ship_loaded = min($ship_list[$transport_id], ceil($resource_amount / $ship_info['hold']), floor($fuel_left / $ship_info['consumption']));
536
-    if($ship_loaded) {
536
+    if ($ship_loaded) {
537 537
       $fleet_array[$transport_id] = $ship_loaded;
538 538
       $resource_amount -= min($resource_amount, $ship_info['hold'] * $ship_loaded);
539 539
       $fuel_left -= $ship_info['consumption'] * $ship_loaded;
Please login to merge, or discard this patch.
includes/includes/flt_mission_spy.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -29,6 +29,9 @@
 block discarded – undo
29 29
   }
30 30
 }
31 31
 
32
+/**
33
+ * @param string $group_name
34
+ */
32 35
 function flt_spy_scan($target_planet, $group_name, $section_title, $target_user = array())
33 36
 {
34 37
   global $lang;
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -11,8 +11,8 @@  discard block
 block discarded – undo
11 11
  */
12 12
 // ----------------------------------------------------------------------------------------------------------------
13 13
 function coe_compress_add_units($unit_group, $target_planet, &$compress_data, $target_user = array()) {
14
-  foreach($unit_group as $unit_id) {
15
-    if(($unit_count = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) {
14
+  foreach ($unit_group as $unit_id) {
15
+    if (($unit_count = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) {
16 16
       $compress_data[$unit_id] = $unit_count;
17 17
     }
18 18
   }
@@ -22,8 +22,8 @@  discard block
 block discarded – undo
22 22
   $classLocale = classLocale::$lang;
23 23
 
24 24
   $result = "<tr><td class=\"c\" colspan=\"4\">{$section_title}</td></tr>";
25
-  foreach(sn_get_groups($group_name) as $unit_id) {
26
-    if(($unit_amount = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) {
25
+  foreach (sn_get_groups($group_name) as $unit_id) {
26
+    if (($unit_amount = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) {
27 27
       $result .= "<tr><td align=\"left\" colspan=\"3\">{$classLocale['tech'][$unit_id]}</td><td align=\"right\">{$unit_amount}</td></tr>";
28 28
     }
29 29
 
@@ -55,14 +55,14 @@  discard block
 block discarded – undo
55 55
 
56 56
   $objFleet = $mission_data->fleet;
57 57
 
58
-  if(empty($target_user_row['id']) || empty($target_planet_row['id']) || empty($spying_user_row['id'])) {
58
+  if (empty($target_user_row['id']) || empty($target_planet_row['id']) || empty($spying_user_row['id'])) {
59 59
     $objFleet->markReturnedAndSave();
60 60
 
61 61
     return $result;
62 62
   }
63 63
 
64 64
   $spy_probes = $objFleet->shipsGetTotalById(SHIP_SPY);
65
-  if($spy_probes > 0) {
65
+  if ($spy_probes > 0) {
66 66
     $TargetSpyLvl = GetSpyLevel($target_user_row);
67 67
     $CurrentSpyLvl = GetSpyLevel($spying_user_row);
68 68
     $spy_diff_empire = $CurrentSpyLvl - $TargetSpyLvl;
@@ -80,26 +80,26 @@  discard block
 block discarded – undo
80 80
     $spy_message .= " ({$classLocale['Player_']} '{$target_user_row['username']}') {$classLocale['On_']} ";
81 81
     $spy_message .= date(FMT_DATE_TIME, $objFleet->time_arrive_to_target);
82 82
     $spy_message .= "</td></tr><tr>";
83
-    $spy_message .= "<td width=220>{$classLocale['sys_metal']}</td><td width=220 align=right>" . pretty_number($target_planet_row['metal']) . "</td>";
84
-    $spy_message .= "<td width=220>{$classLocale['sys_crystal']}</td></td><td width=220 align=right>" . pretty_number($target_planet_row['crystal']) . "</td>";
83
+    $spy_message .= "<td width=220>{$classLocale['sys_metal']}</td><td width=220 align=right>".pretty_number($target_planet_row['metal'])."</td>";
84
+    $spy_message .= "<td width=220>{$classLocale['sys_crystal']}</td></td><td width=220 align=right>".pretty_number($target_planet_row['crystal'])."</td>";
85 85
     $spy_message .= "</tr><tr>";
86
-    $spy_message .= "<td width=220>{$classLocale['sys_deuterium']}</td><td width=220 align=right>" . pretty_number($target_planet_row['deuterium']) . "</td>";
87
-    $spy_message .= "<td width=220>{$classLocale['sys_energy']}</td><td width=220 align=right>" . pretty_number($target_planet_row['energy_max']) . "</td>";
86
+    $spy_message .= "<td width=220>{$classLocale['sys_deuterium']}</td><td width=220 align=right>".pretty_number($target_planet_row['deuterium'])."</td>";
87
+    $spy_message .= "<td width=220>{$classLocale['sys_energy']}</td><td width=220 align=right>".pretty_number($target_planet_row['energy_max'])."</td>";
88 88
     $spy_message .= "</tr>";
89
-    if($spy_diff >= 2) {
90
-      $spy_message .= "<div class='spy_medium'>" . flt_spy_scan($target_planet_row, 'fleet', classLocale::$lang['tech'][UNIT_SHIPS], $target_user_row) . "</div>";
89
+    if ($spy_diff >= 2) {
90
+      $spy_message .= "<div class='spy_medium'>".flt_spy_scan($target_planet_row, 'fleet', classLocale::$lang['tech'][UNIT_SHIPS], $target_user_row)."</div>";
91 91
       coe_compress_add_units(sn_get_groups('fleet'), $target_planet_row, $combat_pack[0]);
92 92
     }
93
-    if($spy_diff >= 3) {
94
-      $spy_message .= "<div class='spy_medium'>" . flt_spy_scan($target_planet_row, 'defense', classLocale::$lang['tech'][UNIT_DEFENCE], $target_user_row) . "</div>";
93
+    if ($spy_diff >= 3) {
94
+      $spy_message .= "<div class='spy_medium'>".flt_spy_scan($target_planet_row, 'defense', classLocale::$lang['tech'][UNIT_DEFENCE], $target_user_row)."</div>";
95 95
       coe_compress_add_units(sn_get_groups('defense_active'), $target_planet_row, $combat_pack[0]);
96 96
     }
97
-    if($spy_diff >= 5) {
98
-      $spy_message .= "<div class='spy_long'>" . flt_spy_scan($target_planet_row, 'structures', classLocale::$lang['tech'][UNIT_STRUCTURES], $target_user_row) . "</div>";
97
+    if ($spy_diff >= 5) {
98
+      $spy_message .= "<div class='spy_long'>".flt_spy_scan($target_planet_row, 'structures', classLocale::$lang['tech'][UNIT_STRUCTURES], $target_user_row)."</div>";
99 99
     }
100 100
 
101
-    if($spy_diff_empire >= 0) {
102
-      $spy_message .= "<div class='spy_long'>" . flt_spy_scan($target_planet_row, 'tech', classLocale::$lang['tech'][UNIT_TECHNOLOGIES], $target_user_row) . "</div>";
101
+    if ($spy_diff_empire >= 0) {
102
+      $spy_message .= "<div class='spy_long'>".flt_spy_scan($target_planet_row, 'tech', classLocale::$lang['tech'][UNIT_TECHNOLOGIES], $target_user_row)."</div>";
103 103
       coe_compress_add_units(array(TECH_WEAPON, TECH_SHIELD, TECH_ARMOR), $target_planet_row, $combat_pack[0], $target_user_row);
104 104
     }
105 105
     // TODO: Наемники, губернаторы, артефакты и прочее имперское
@@ -107,13 +107,13 @@  discard block
 block discarded – undo
107 107
     $simulator_link = sn_ube_simulator_encode_replay($combat_pack, 'D');
108 108
 
109 109
     $target_unit_list = 0;
110
-    foreach(sn_get_groups('fleet') as $unit_id) {
110
+    foreach (sn_get_groups('fleet') as $unit_id) {
111 111
       $target_unit_list += max(0, mrc_get_level($target_user_row, $target_planet_row, $unit_id, false, true));
112 112
     }
113 113
 
114 114
     $spy_detected = $spy_probes * $target_unit_list / 4 * pow(2, $TargetSpyLvl - $CurrentSpyLvl);
115 115
 
116
-    if(mt_rand(0, 99) > $spy_detected) {
116
+    if (mt_rand(0, 99) > $spy_detected) {
117 117
       $spy_outcome_str = sprintf(classLocale::$lang['sys_mess_spy_detect_chance'], $spy_detected);
118 118
       $spy_detected = false;
119 119
     } else {
@@ -130,16 +130,16 @@  discard block
 block discarded – undo
130 130
 
131 131
     msg_send_simple_message($spying_user_row['id'], '', $objFleet->time_arrive_to_target, MSG_TYPE_SPY, classLocale::$lang['sys_mess_qg'], classLocale::$lang['sys_mess_spy_report'], $spy_message);
132 132
 
133
-    $target_message = "{$classLocale['sys_mess_spy_ennemyfleet']} {$spying_planet_row['name']} " . uni_render_coordinates_href($spying_planet_row, '', 3);
134
-    $target_message .= " {$classLocale['sys_mess_spy_seen_at']} {$target_planet_row['name']} " . uni_render_coordinates($target_planet_row);
133
+    $target_message = "{$classLocale['sys_mess_spy_ennemyfleet']} {$spying_planet_row['name']} ".uni_render_coordinates_href($spying_planet_row, '', 3);
134
+    $target_message .= " {$classLocale['sys_mess_spy_seen_at']} {$target_planet_row['name']} ".uni_render_coordinates($target_planet_row);
135 135
 
136
-    if($spy_detected) {
136
+    if ($spy_detected) {
137 137
       $debris_planet_id = $target_planet_row['planet_type'] == PT_PLANET ? $target_planet_row['id'] : $target_planet_row['parent_planet'];
138 138
 
139 139
       $spy_cost = get_unit_param(SHIP_SPY, P_COST);
140 140
 
141 141
       db_planet_set_by_id($debris_planet_id,
142
-        "`debris_metal` = `debris_metal` + " . floor($spy_probes * $spy_cost[RES_METAL] * 0.3) . ", `debris_crystal` = `debris_crystal` + " . floor($spy_probes * $spy_cost[RES_CRYSTAL] * 0.3));
142
+        "`debris_metal` = `debris_metal` + ".floor($spy_probes * $spy_cost[RES_METAL] * 0.3).", `debris_crystal` = `debris_crystal` + ".floor($spy_probes * $spy_cost[RES_CRYSTAL] * 0.3));
143 143
 
144 144
       $target_message .= "<br />{$classLocale['sys_mess_spy_destroyed_enemy']}";
145 145
 
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
     msg_send_simple_message($objFleet->target_owner_id, '', $objFleet->time_arrive_to_target, MSG_TYPE_SPY, classLocale::$lang['sys_mess_spy_control'], classLocale::$lang['sys_mess_spy_activity'], $target_message);
151 151
   }
152 152
 
153
-  if($spy_detected) {
153
+  if ($spy_detected) {
154 154
     $objFleet->dbDelete();
155 155
   } else {
156 156
     $objFleet->markReturnedAndSave();
Please login to merge, or discard this patch.