@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | |
29 | 29 | $this->container = array(); |
30 | 30 | |
31 | - if(SN::$cache->getMode() != classCache::CACHER_NO_CACHE && !SN::$config->locale_cache_disable) { |
|
31 | + if (SN::$cache->getMode() != classCache::CACHER_NO_CACHE && !SN::$config->locale_cache_disable) { |
|
32 | 32 | $this->cache = SN::$cache; |
33 | 33 | SN::log_file('locale.__constructor: Cache is present'); |
34 | 34 | //$this->cache->unset_by_prefix($this->cache_prefix); // TODO - remove? 'cause debug! |
35 | 35 | } |
36 | 36 | |
37 | - if($enable_stat_usage && empty($this->stat_usage)) { |
|
37 | + if ($enable_stat_usage && empty($this->stat_usage)) { |
|
38 | 38 | $this->enable_stat_usage = $enable_stat_usage; |
39 | 39 | $this->usage_stat_load(); |
40 | 40 | // TODO shutdown function |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | unset($fallback[$this->active]); |
61 | 61 | |
62 | 62 | // Проходим по оставшимся локалям |
63 | - foreach($fallback as $try_language) { |
|
63 | + foreach ($fallback as $try_language) { |
|
64 | 64 | // Если нет такой строки - пытаемся вытащить из кэша |
65 | - if(!isset($this->container[$try_language][$offset]) && $this->cache) { |
|
65 | + if (!isset($this->container[$try_language][$offset]) && $this->cache) { |
|
66 | 66 | $this->container[$try_language][$offset] = $this->cache->__get($this->cache_prefix . $try_language . '_' . $offset); |
67 | 67 | // Записываем результат работы кэша |
68 | 68 | $locale_cache_statistic['queries']++; |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | } |
72 | 72 | |
73 | 73 | // Если мы как-то где-то нашли строку... |
74 | - if(isset($this->container[$try_language][$offset])) { |
|
74 | + if (isset($this->container[$try_language][$offset])) { |
|
75 | 75 | // ...значит она получена в результате фоллбэка и записываем её в кэш и контейнер |
76 | 76 | $this[$offset] = $this->container[$try_language][$offset]; |
77 | 77 | $locale_cache_statistic['fallbacks']++; |
@@ -85,15 +85,15 @@ discard block |
||
85 | 85 | $this->container[$this->active][] = $value; |
86 | 86 | } else { |
87 | 87 | $this->container[$this->active][$offset] = $value; |
88 | - if($this->cache) { |
|
88 | + if ($this->cache) { |
|
89 | 89 | $this->cache->__set($this->cache_prefix_lang . $offset, $value); |
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
93 | 93 | public function offsetExists($offset) { |
94 | 94 | // Шорткат если у нас уже есть строка в памяти PHP |
95 | - if(!isset($this->container[$this->active][$offset])) { |
|
96 | - if(!$this->cache || !($this->container[$this->active][$offset] = $this->cache->__get($this->cache_prefix_lang . $offset))) { |
|
95 | + if (!isset($this->container[$this->active][$offset])) { |
|
96 | + if (!$this->cache || !($this->container[$this->active][$offset] = $this->cache->__get($this->cache_prefix_lang . $offset))) { |
|
97 | 97 | // Если нету такой строки - делаем фоллбэк |
98 | 98 | $this->locale_string_fallback($offset); |
99 | 99 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | } |
108 | 108 | public function offsetGet($offset) { |
109 | 109 | $value = $this->offsetExists($offset) ? $this->container[$this->active][$offset] : null; |
110 | - if($this->enable_stat_usage) { |
|
110 | + if ($this->enable_stat_usage) { |
|
111 | 111 | $this->usage_stat_log($offset, $value); |
112 | 112 | } |
113 | 113 | return $value; |
@@ -124,24 +124,24 @@ discard block |
||
124 | 124 | public function usage_stat_load() { |
125 | 125 | global $sn_cache; |
126 | 126 | |
127 | - $this->stat_usage = $sn_cache->lng_stat_usage = array(); // TODO for debug |
|
128 | - if(empty($this->stat_usage)) { |
|
127 | + $this->stat_usage = $sn_cache->lng_stat_usage = array(); // TODO for debug |
|
128 | + if (empty($this->stat_usage)) { |
|
129 | 129 | $query = doquery("SELECT * FROM {{lng_usage_stat}}"); |
130 | - while($row = db_fetch($query)) { |
|
130 | + while ($row = db_fetch($query)) { |
|
131 | 131 | $this->stat_usage[$row['lang_code'] . ':' . $row['string_id'] . ':' . $row['file'] . ':' . $row['line']] = $row['is_empty']; |
132 | 132 | } |
133 | 133 | } |
134 | 134 | } |
135 | 135 | public function usage_stat_save() { |
136 | - if(!empty($this->stat_usage_new)) { |
|
136 | + if (!empty($this->stat_usage_new)) { |
|
137 | 137 | global $sn_cache; |
138 | 138 | $sn_cache->lng_stat_usage = $this->stat_usage; |
139 | 139 | doquery("SELECT 1 FROM {{lng_usage_stat}} LIMIT 1"); |
140 | - foreach($this->stat_usage_new as &$value) { |
|
141 | - foreach($value as &$value2) { |
|
140 | + foreach ($this->stat_usage_new as &$value) { |
|
141 | + foreach ($value as &$value2) { |
|
142 | 142 | $value2 = '"' . db_escape($value2) . '"'; |
143 | 143 | } |
144 | - $value = '(' . implode(',', $value) .')'; |
|
144 | + $value = '(' . implode(',', $value) . ')'; |
|
145 | 145 | } |
146 | 146 | doquery("REPLACE INTO {{lng_usage_stat}} (lang_code,string_id,`file`,line,is_empty,locale) VALUES " . implode(',', $this->stat_usage_new)); |
147 | 147 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | $file = str_replace('\\', '/', substr($trace[1]['file'], strlen(SN_ROOT_PHYSICAL) - 1)); |
155 | 155 | |
156 | 156 | $string_id = $this->active . ':' . $offset . ':' . $file . ':' . $trace[1]['line']; |
157 | - if(!isset($this->stat_usage[$string_id]) || $this->stat_usage[$string_id] != $empty) { |
|
157 | + if (!isset($this->stat_usage[$string_id]) || $this->stat_usage[$string_id] != $empty) { |
|
158 | 158 | $this->stat_usage[$string_id] = empty($value); |
159 | 159 | $this->stat_usage_new[] = array( |
160 | 160 | 'lang_code' => $this->active, |
@@ -194,11 +194,11 @@ discard block |
||
194 | 194 | $cache_file_key = $this->cache_prefix_lang . '__' . $filename; |
195 | 195 | |
196 | 196 | // Подключен ли внешний кэш? |
197 | - if($this->cache) { |
|
197 | + if ($this->cache) { |
|
198 | 198 | // Загружен ли уже данный файл? |
199 | 199 | $cache_file_status = $this->cache->__get($cache_file_key); |
200 | 200 | SN::log_file("locale.include: Cache - '{$filename}' has key '{$cache_file_key}' and is " . ($cache_file_status ? 'already loaded - EXIT' : 'EMPTY'), $cache_file_status ? -1 : 0); |
201 | - if($cache_file_status) { |
|
201 | + if ($cache_file_status) { |
|
202 | 202 | // Если да - повторять загрузку нет смысла |
203 | 203 | return null; |
204 | 204 | } |
@@ -212,35 +212,35 @@ discard block |
||
212 | 212 | $this->make_fallback($language); |
213 | 213 | |
214 | 214 | $file_path = ''; |
215 | - foreach($this->fallback as $lang_try) { |
|
216 | - if(!$lang_try /* || isset($language_tried[$lang_try]) */) { |
|
215 | + foreach ($this->fallback as $lang_try) { |
|
216 | + if (!$lang_try /* || isset($language_tried[$lang_try]) */) { |
|
217 | 217 | continue; |
218 | 218 | } |
219 | 219 | |
220 | - if($file_path = $this->lng_try_filepath($path, "language/{$lang_try}/{$filename_ext}")) { |
|
220 | + if ($file_path = $this->lng_try_filepath($path, "language/{$lang_try}/{$filename_ext}")) { |
|
221 | 221 | break; |
222 | 222 | } |
223 | 223 | |
224 | - if($file_path = $this->lng_try_filepath($path, "language/{$filename}_{$lang_try}{$ext}")) { |
|
224 | + if ($file_path = $this->lng_try_filepath($path, "language/{$filename}_{$lang_try}{$ext}")) { |
|
225 | 225 | break; |
226 | 226 | } |
227 | 227 | |
228 | 228 | $file_path = ''; |
229 | 229 | } |
230 | 230 | |
231 | - if($file_path) { |
|
231 | + if ($file_path) { |
|
232 | 232 | include($file_path); |
233 | 233 | |
234 | - if(!empty($a_lang_array)) { |
|
234 | + if (!empty($a_lang_array)) { |
|
235 | 235 | $this->merge($a_lang_array); |
236 | 236 | |
237 | 237 | // Загрузка данных из файла в кэш |
238 | - if($this->cache) { |
|
238 | + if ($this->cache) { |
|
239 | 239 | SN::log_file("Locale: loading '{$filename}' into cache"); |
240 | - foreach($a_lang_array as $key => $value) { |
|
240 | + foreach ($a_lang_array as $key => $value) { |
|
241 | 241 | $value_cache_key = $this->cache_prefix_lang . $key; |
242 | - if($this->cache->__isset($value_cache_key)) { |
|
243 | - if(is_array($value)) { |
|
242 | + if ($this->cache->__isset($value_cache_key)) { |
|
243 | + if (is_array($value)) { |
|
244 | 244 | $alt_value = $this->cache->__get($value_cache_key); |
245 | 245 | $value = array_replace_recursive($alt_value, $value); |
246 | 246 | } |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | } |
251 | 251 | } |
252 | 252 | |
253 | - if($this->cache) { |
|
253 | + if ($this->cache) { |
|
254 | 254 | $this->cache->__set($cache_file_key, true); |
255 | 255 | } |
256 | 256 | |
@@ -263,14 +263,14 @@ discard block |
||
263 | 263 | } |
264 | 264 | |
265 | 265 | public function lng_load_i18n($i18n) { |
266 | - if(!isset($i18n)) { |
|
266 | + if (!isset($i18n)) { |
|
267 | 267 | return; |
268 | 268 | } |
269 | 269 | |
270 | - foreach($i18n as $i18n_data) { |
|
271 | - if(is_string($i18n_data)) { |
|
270 | + foreach ($i18n as $i18n_data) { |
|
271 | + if (is_string($i18n_data)) { |
|
272 | 272 | $this->lng_include($i18n_data); |
273 | - } elseif(is_array($i18n_data)) { |
|
273 | + } elseif (is_array($i18n_data)) { |
|
274 | 274 | $this->lng_include($i18n_data['file'], $i18n_data['path']); |
275 | 275 | } |
276 | 276 | } |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | |
289 | 289 | SN::log_file("locale.switch: Trying to switch language to '{$language_new}'"); |
290 | 290 | |
291 | - if($language_new == $this->active) { |
|
291 | + if ($language_new == $this->active) { |
|
292 | 292 | SN::log_file("locale.switch: New language '{$language_new}' is equal to current language '{$this->active}' - EXIT", -1); |
293 | 293 | return false; |
294 | 294 | } |
@@ -299,10 +299,10 @@ discard block |
||
299 | 299 | $this['LANG_INFO'] = $this->lng_get_info($this->active); |
300 | 300 | $this->make_fallback($this->active); |
301 | 301 | |
302 | - if($this->cache) { |
|
302 | + if ($this->cache) { |
|
303 | 303 | $cache_lang_init_status = $this->cache->__get($this->cache_prefix_lang . '__INIT'); |
304 | 304 | SN::log_file("locale.switch: Cache for '{$this->active}' prefixed '{$this->cache_prefix_lang}' is " . ($cache_lang_init_status ? 'already loaded. Doing nothing - EXIT' : 'EMPTY'), $cache_lang_init_status ? -1 : 0); |
305 | - if($cache_lang_init_status) { |
|
305 | + if ($cache_lang_init_status) { |
|
306 | 306 | return false; |
307 | 307 | } |
308 | 308 | |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | // Loading global language files |
319 | 319 | $this->lng_load_i18n($sn_mvc['i18n']['']); |
320 | 320 | |
321 | - if($this->cache) { |
|
321 | + if ($this->cache) { |
|
322 | 322 | SN::log_file("locale.switch: Cache - setting flag " . $this->cache_prefix_lang . '__INIT'); |
323 | 323 | $this->cache->__set($this->cache_prefix_lang . '__INIT', true); |
324 | 324 | } |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | public function lng_get_info($entry) { |
333 | 333 | $file_name = SN_ROOT_PHYSICAL . 'language/' . $entry . '/language.mo.php'; |
334 | 334 | $lang_info = array(); |
335 | - if(file_exists($file_name)) { |
|
335 | + if (file_exists($file_name)) { |
|
336 | 336 | include($file_name); |
337 | 337 | } |
338 | 338 | |
@@ -340,15 +340,15 @@ discard block |
||
340 | 340 | } |
341 | 341 | |
342 | 342 | public function lng_get_list() { |
343 | - if(empty($this->lang_list)) { |
|
343 | + if (empty($this->lang_list)) { |
|
344 | 344 | $this->lang_list = array(); |
345 | 345 | |
346 | 346 | $path = SN_ROOT_PHYSICAL . 'language/'; |
347 | 347 | $dir = dir($path); |
348 | - while(false !== ($entry = $dir->read())) { |
|
349 | - if(is_dir($path . $entry) && $entry[0] != '.') { |
|
348 | + while (false !== ($entry = $dir->read())) { |
|
349 | + if (is_dir($path . $entry) && $entry[0] != '.') { |
|
350 | 350 | $lang_info = $this->lng_get_info($entry); |
351 | - if($lang_info['LANG_NAME_ISO2'] == $entry) { |
|
351 | + if ($lang_info['LANG_NAME_ISO2'] == $entry) { |
|
352 | 352 | $this->lang_list[$lang_info['LANG_NAME_ISO2']] = $lang_info; |
353 | 353 | } |
354 | 354 | } |
@@ -12,24 +12,24 @@ discard block |
||
12 | 12 | global $debug, $template_result, $user, $lang, $planetrow; |
13 | 13 | |
14 | 14 | // Напоминание для Администрации, что игра отключена |
15 | -if($template_result[F_GAME_DISABLE]) { |
|
15 | +if ($template_result[F_GAME_DISABLE]) { |
|
16 | 16 | echo '<div class="global_admin_warning">', $template_result[F_GAME_DISABLE_REASON], '</div>'; |
17 | 17 | } |
18 | 18 | unset($disable_reason); |
19 | 19 | |
20 | 20 | |
21 | -if(defined('IN_ADMIN') && IN_ADMIN === true) { |
|
21 | +if (defined('IN_ADMIN') && IN_ADMIN === true) { |
|
22 | 22 | lng_include('admin'); |
23 | -} elseif($sys_user_logged_in) { |
|
23 | +} elseif ($sys_user_logged_in) { |
|
24 | 24 | sys_user_vacation($user); |
25 | 25 | |
26 | 26 | $planet_id = SetSelectedPlanet($user); |
27 | 27 | |
28 | 28 | // TODO НЕ НУЖНО АЛЬЯНС КАЖДЫЙ РАЗ ОБНОВЛЯТЬ!!! |
29 | - if($user['ally_id']) { |
|
29 | + if ($user['ally_id']) { |
|
30 | 30 | sn_db_transaction_start(); |
31 | 31 | \Alliance\Alliance::sn_ali_fill_user_ally($user); |
32 | - if(!$user['ally']['player']['id']) { |
|
32 | + if (!$user['ally']['player']['id']) { |
|
33 | 33 | // sn_sys_logout(false, true); |
34 | 34 | // core_auth::logout(false); |
35 | 35 | SN::$auth->logout(false); |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | sn_db_transaction_commit(); |
49 | 49 | |
50 | 50 | $planetrow = $global_data['planet']; |
51 | - if(!($planetrow && isset($planetrow['id']) && $planetrow['id'])) { |
|
51 | + if (!($planetrow && isset($planetrow['id']) && $planetrow['id'])) { |
|
52 | 52 | // sn_sys_logout(false, true); |
53 | 53 | // core_auth::logout(false); |
54 | 54 | SN::$auth->logout(false); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | sys_user_options_unpack($user); |
64 | 64 | |
65 | 65 | global $sn_page_name, $sn_mvc; |
66 | -if(!empty($sn_mvc['pages'][INITIAL_PAGE][PAGE_OPTION_EARLY_HEADER])) { |
|
66 | +if (!empty($sn_mvc['pages'][INITIAL_PAGE][PAGE_OPTION_EARLY_HEADER])) { |
|
67 | 67 | $title = !empty($sn_mvc['pages'][INITIAL_PAGE][PAGE_OPTION_TITLE]) ? $sn_mvc['pages'][INITIAL_PAGE][PAGE_OPTION_TITLE] : ''; |
68 | 68 | renderHeader($page, $title, $template_result, false, $user, SN::$config, $lang, $planetrow); |
69 | 69 | } |
@@ -21,8 +21,8 @@ |
||
21 | 21 | $mode = sys_get_param_escaped('mode'); |
22 | 22 | $mode = (!$mode || $mode == 'buildings') ? QUE_STRUCTURES : ($mode == 'fleet' ? SUBQUE_FLEET : ($mode == 'defense' ? SUBQUE_DEFENSE : ($mode == 'research' ? QUE_RESEARCH : $mode))); |
23 | 23 | |
24 | -if($building_sort = sys_get_param_id('sort_elements')) { |
|
25 | - if(!empty($lang['player_option_building_sort'][$building_sort])) { |
|
24 | +if ($building_sort = sys_get_param_id('sort_elements')) { |
|
25 | + if (!empty($lang['player_option_building_sort'][$building_sort])) { |
|
26 | 26 | SN::$user_options[array(PLAYER_OPTION_BUILDING_SORT, $mode)] = $building_sort; |
27 | 27 | SN::$user_options[array(PLAYER_OPTION_BUILDING_SORT_INVERSE, $mode)] = sys_get_param_id('sort_elements_inverse', 0); |
28 | 28 | } |
@@ -15,34 +15,34 @@ discard block |
||
15 | 15 | $template = gettemplate('notes', true); |
16 | 16 | |
17 | 17 | $result = array(); |
18 | -if(($result_message = sys_get_param_str('MESSAGE')) && isset($lang[$result_message])) { |
|
18 | +if (($result_message = sys_get_param_str('MESSAGE')) && isset($lang[$result_message])) { |
|
19 | 19 | $result[] = array('STATUS' => sys_get_param_int('STATUS'), 'MESSAGE' => $lang[$result_message]); |
20 | 20 | } |
21 | 21 | |
22 | 22 | $note_id_edit = sys_get_param_id('note_id_edit'); |
23 | -if(sys_get_param('note_delete')) { |
|
23 | +if (sys_get_param('note_delete')) { |
|
24 | 24 | try { |
25 | 25 | $not = ''; |
26 | 26 | $query_where = ''; |
27 | - switch(sys_get_param_str('note_delete_range')) { |
|
27 | + switch (sys_get_param_str('note_delete_range')) { |
|
28 | 28 | case 'all': |
29 | 29 | break; |
30 | 30 | |
31 | 31 | case 'marked_not': |
32 | 32 | $not = 'NOT'; |
33 | 33 | case 'marked': |
34 | - if(!is_array($notes_marked = sys_get_param('note'))) { |
|
34 | + if (!is_array($notes_marked = sys_get_param('note'))) { |
|
35 | 35 | throw new exception('note_err_none_selected', ERR_WARNING); |
36 | 36 | } |
37 | 37 | |
38 | 38 | $notes_marked_filtered = array(); |
39 | - foreach($notes_marked as $note_id => $note_select) { |
|
40 | - if($note_select == 'on' && $note_id = idval($note_id)) { |
|
39 | + foreach ($notes_marked as $note_id => $note_select) { |
|
40 | + if ($note_select == 'on' && $note_id = idval($note_id)) { |
|
41 | 41 | $notes_marked_filtered[] = $note_id; |
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | - if(empty($notes_marked_filtered)) { |
|
45 | + if (empty($notes_marked_filtered)) { |
|
46 | 46 | throw new exception('note_err_none_selected', ERR_WARNING); |
47 | 47 | } |
48 | 48 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | doquery("DELETE FROM {{notes}} WHERE `owner` = {$user['id']} {$query_where};"); |
60 | 60 | sn_db_transaction_commit(); |
61 | 61 | throw new exception($note_id_edit ? 'note_err_none_changed' : 'note_err_none_added', ERR_NONE); |
62 | - } catch(exception $e) { |
|
62 | + } catch (exception $e) { |
|
63 | 63 | $note_id_edit = 0; |
64 | 64 | sn_db_transaction_rollback(); |
65 | 65 | $result[] = array( |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | 'MESSAGE' => $lang[$e->getMessage()], |
68 | 68 | ); |
69 | 69 | } |
70 | -} elseif(($note_title = sys_get_param_str('note_title')) || ($note_text = sys_get_param_str('note_text'))) { |
|
70 | +} elseif (($note_title = sys_get_param_str('note_title')) || ($note_text = sys_get_param_str('note_text'))) { |
|
71 | 71 | $note_title == db_escape($lang['note_new_title']) ? $note_title = '' : false; |
72 | 72 | ($note_text = sys_get_param_str('note_text')) == db_escape($lang['note_new_text']) ? $note_text = '' : false; |
73 | 73 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | $note_system = max(0, min(sys_get_param_id('note_system'), SN::$config->game_maxSystem)); |
77 | 77 | $note_planet = max(0, min(sys_get_param_id('note_planet'), SN::$config->game_maxPlanet + 1)); |
78 | 78 | |
79 | - if(!$note_text && !$note_title && !$note_galaxy && !$note_system && !$note_planet) { |
|
79 | + if (!$note_text && !$note_title && !$note_galaxy && !$note_system && !$note_planet) { |
|
80 | 80 | throw new exception('note_err_note_empty', ERR_WARNING); |
81 | 81 | } |
82 | 82 | |
@@ -85,15 +85,15 @@ discard block |
||
85 | 85 | $note_sticky = intval(sys_get_param_id('note_sticky')) ? 1 : 0; |
86 | 86 | |
87 | 87 | sn_db_transaction_start(); |
88 | - if($note_id_edit) { |
|
88 | + if ($note_id_edit) { |
|
89 | 89 | $check_note_id = doquery("SELECT `id`, `owner` FROM {{notes}} WHERE `id` = {$note_id_edit} LIMIT 1 FOR UPDATE", true); |
90 | - if(!$check_note_id) { |
|
90 | + if (!$check_note_id) { |
|
91 | 91 | throw new exception('note_err_note_not_found', ERR_ERROR); |
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | - if($note_id_edit) { |
|
96 | - if($check_note_id['owner'] != $user['id']) { |
|
95 | + if ($note_id_edit) { |
|
96 | + if ($check_note_id['owner'] != $user['id']) { |
|
97 | 97 | throw new exception('note_err_owner_wrong', ERR_ERROR); |
98 | 98 | } |
99 | 99 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | sn_db_transaction_commit(); |
109 | 109 | sys_redirect('notes.php?STATUS=' . ERR_NONE . '&MESSAGE=' . ($note_id_edit ? 'note_err_none_changed' : 'note_err_none_added')); |
110 | 110 | // throw new exception($note_id_edit ? 'note_err_none_changed' : 'note_err_none_added', ERR_NONE); |
111 | - } catch(exception $e) { |
|
111 | + } catch (exception $e) { |
|
112 | 112 | $note_id_edit = 0; |
113 | 113 | sn_db_transaction_rollback(); |
114 | 114 | $result[] = array( |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
121 | -if(!$note_id_edit) { |
|
121 | +if (!$note_id_edit) { |
|
122 | 122 | \Note\Note::note_assign($template, array( |
123 | 123 | 'id' => 0, |
124 | 124 | 'time' => SN_TIME_NOW, |
@@ -131,13 +131,13 @@ discard block |
||
131 | 131 | |
132 | 132 | $note_exist = false; |
133 | 133 | $notes_query = doquery("SELECT * FROM {{notes}} WHERE owner={$user['id']} ORDER BY priority DESC, galaxy ASC, system ASC, planet ASC, planet_type ASC, `time` DESC"); |
134 | -while($note_row = db_fetch($notes_query)) { |
|
134 | +while ($note_row = db_fetch($notes_query)) { |
|
135 | 135 | \Note\Note::note_assign($template, $note_row); |
136 | 136 | $note_exist = $note_exist || $note_row['id'] == $note_id_edit; |
137 | 137 | } |
138 | 138 | $note_id_edit = $note_exist ? $note_id_edit : 0; |
139 | 139 | |
140 | -foreach($note_priority_classes as $note_priority_id => $note_priority_class) { |
|
140 | +foreach ($note_priority_classes as $note_priority_id => $note_priority_class) { |
|
141 | 141 | $template->assign_block_vars('note_priority', array( |
142 | 142 | 'ID' => $note_priority_id, |
143 | 143 | 'CLASS' => $note_priority_classes[$note_priority_id], |
@@ -145,14 +145,14 @@ discard block |
||
145 | 145 | )); |
146 | 146 | } |
147 | 147 | |
148 | -foreach($lang['sys_planet_type'] as $planet_type_id => $planet_type_string) { |
|
148 | +foreach ($lang['sys_planet_type'] as $planet_type_id => $planet_type_string) { |
|
149 | 149 | $template->assign_block_vars('planet_type', array( |
150 | 150 | 'ID' => $planet_type_id, |
151 | 151 | 'TEXT' => $planet_type_string, |
152 | 152 | )); |
153 | 153 | } |
154 | 154 | |
155 | -foreach($result as $result_data) { |
|
155 | +foreach ($result as $result_data) { |
|
156 | 156 | $template->assign_block_vars('result', $result_data); |
157 | 157 | } |
158 | 158 |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @copyright 2008-2015 Gorlum for Project "SuperNova.WS" |
6 | 6 | */ |
7 | 7 | |
8 | -if(!defined('INSIDE')) { |
|
8 | +if (!defined('INSIDE')) { |
|
9 | 9 | die(); |
10 | 10 | } |
11 | 11 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | function db_change_units_perform($query, $tablename, $object_id) { |
15 | 15 | $query = implode(',', $query); |
16 | - if($query && $object_id) { |
|
16 | + if ($query && $object_id) { |
|
17 | 17 | return SN::db_upd_record_by_id($tablename == 'users' ? LOC_USER : LOC_PLANET, $object_id, $query); |
18 | 18 | } |
19 | 19 | } |
@@ -29,15 +29,15 @@ discard block |
||
29 | 29 | |
30 | 30 | $group = sn_get_groups('resources_loot'); |
31 | 31 | |
32 | - foreach($unit_list as $unit_id => $unit_amount) { |
|
33 | - if(!in_array($unit_id, $group)) { |
|
32 | + foreach ($unit_list as $unit_id => $unit_amount) { |
|
33 | + if (!in_array($unit_id, $group)) { |
|
34 | 34 | // TODO - remove later |
35 | 35 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: db_change_units() вызван для не-ресурсов!</h1>'); |
36 | 36 | pdump(debug_backtrace()); |
37 | 37 | die('db_change_units() вызван для не-ресурсов!'); |
38 | 38 | } |
39 | 39 | |
40 | - if(!$unit_amount) { |
|
40 | + if (!$unit_amount) { |
|
41 | 41 | continue; |
42 | 42 | } |
43 | 43 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | $unit_location = sys_get_unit_location($user, $planet, $unit_id); |
47 | 47 | |
48 | 48 | // Changing value in object |
49 | - switch($unit_location) { |
|
49 | + switch ($unit_location) { |
|
50 | 50 | case LOC_USER: |
51 | 51 | $user[$unit_db_name] += $unit_amount; |
52 | 52 | break; |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | // $same_user = false; |
48 | 48 | // } |
49 | 49 | |
50 | - if(!$user_data) { |
|
50 | + if (!$user_data) { |
|
51 | 51 | messageBox($lang['imp_imperator_none'], $lang['sys_error'], 'index.php', 10); |
52 | 52 | die(); |
53 | 53 | } |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | $stat_array = array(); |
59 | 59 | $query = doquery("SELECT * FROM {{statpoints}} WHERE `stat_type` = 1 AND `id_owner` = {$user_id} ORDER BY `stat_code` DESC;"); |
60 | 60 | $stat_count = SN::$db->db_affected_rows(); |
61 | - while($row = db_fetch($query)) { |
|
62 | - foreach($stat_fields as $field_db_name => $field_template_name) { |
|
61 | + while ($row = db_fetch($query)) { |
|
62 | + foreach ($stat_fields as $field_db_name => $field_template_name) { |
|
63 | 63 | // $stat_count - $row['stat_code'] - для реверсирования ID статы в JS |
64 | 64 | $stat_array[$field_template_name]['DATA'][$stat_count - $row['stat_code']] = $row[$field_db_name]; |
65 | 65 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | |
68 | 68 | $stat_array_date = $stat_array['STAT_DATE']; |
69 | 69 | empty($stat_array_date['DATA']) ? $stat_array_date['DATA'] = array() : false; |
70 | - foreach($stat_array_date['DATA'] as $key => $value) { |
|
70 | + foreach ($stat_array_date['DATA'] as $key => $value) { |
|
71 | 71 | $template->assign_block_vars('stat_date', array( |
72 | 72 | 'ID' => $key, |
73 | 73 | 'VALUE' => $value, |
@@ -77,21 +77,21 @@ discard block |
||
77 | 77 | |
78 | 78 | unset($stat_array['STAT_DATE']); |
79 | 79 | $template_data = array(); |
80 | - foreach($stat_array as $stat_type => &$stat_type_data) { |
|
80 | + foreach ($stat_array as $stat_type => &$stat_type_data) { |
|
81 | 81 | $reverse_min_max = strpos($stat_type, '_RANK') !== false; |
82 | 82 | $stat_type_data['MIN'] = $reverse_min_max ? max($stat_type_data['DATA']) : min($stat_type_data['DATA']); |
83 | 83 | $stat_type_data['MAX'] = $reverse_min_max ? min($stat_type_data['DATA']) : max($stat_type_data['DATA']); |
84 | 84 | $stat_type_data['AVG'] = average($stat_type_data['DATA']); |
85 | - foreach($stat_type_data['DATA'] as $key => $value) { |
|
85 | + foreach ($stat_type_data['DATA'] as $key => $value) { |
|
86 | 86 | $stat_type_data['PERCENT'][$key] = ($stat_type_data['MAX'] - $value ? ($value - $stat_type_data['MIN']) / ($stat_type_data['MAX'] - $stat_type_data['MIN']) : 1) * 100; |
87 | 87 | $template_data[$stat_type][$key]['ID'] = $key; |
88 | 88 | $template_data[$stat_type][$key]['VALUE'] = $value; |
89 | - $template_data[$stat_type][$key]['DELTA'] = ($reverse_min_max ? $stat_type_data['MIN'] - $value : $value - $stat_type_data['MAX']); |
|
89 | + $template_data[$stat_type][$key]['DELTA'] = ($reverse_min_max ? $stat_type_data['MIN'] - $value : $value - $stat_type_data['MAX']); |
|
90 | 90 | $template_data[$stat_type][$key]['PERCENT'] = $stat_type_data['PERCENT'][$key]; |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - foreach($template_data as $stat_type => $stat_type_data) { |
|
94 | + foreach ($template_data as $stat_type => $stat_type_data) { |
|
95 | 95 | $template->assign_block_vars('stat', array( |
96 | 96 | 'TYPE' => $stat_type, |
97 | 97 | 'TEXT' => $lang['imp_stat_types'][$stat_type], |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | 'MAX' => $stat_array[$stat_type]['MAX'], |
100 | 100 | 'AVG' => $stat_array[$stat_type]['AVG'], |
101 | 101 | )); |
102 | - foreach($stat_type_data as $stat_entry) { |
|
102 | + foreach ($stat_type_data as $stat_entry) { |
|
103 | 103 | $template->assign_block_vars('stat.entry', $stat_entry); |
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
107 | 107 | |
108 | - if($same_user) { |
|
108 | + if ($same_user) { |
|
109 | 109 | rpg_level_up($user, RPG_STRUCTURE); |
110 | 110 | rpg_level_up($user, RPG_RAID); |
111 | 111 | rpg_level_up($user, RPG_TECH); |
@@ -142,29 +142,29 @@ discard block |
||
142 | 142 | 'builder_xp' => HelperString::numberFloorAndFormat($user_data['xpminier']), |
143 | 143 | 'builder_lvl' => HelperString::numberFloorAndFormat($user_data['lvl_minier']), |
144 | 144 | 'builder_lvl_st' => HelperString::numberFloorAndFormat(rpg_get_miner_xp($user_data['lvl_minier'])), |
145 | - 'builder_lvl_up' => HelperString::numberFloorAndFormat(rpg_get_miner_xp($user_data['lvl_minier']+1)), |
|
145 | + 'builder_lvl_up' => HelperString::numberFloorAndFormat(rpg_get_miner_xp($user_data['lvl_minier'] + 1)), |
|
146 | 146 | 'raid_xp' => HelperString::numberFloorAndFormat($user_data['xpraid']), |
147 | 147 | 'raid_lvl' => HelperString::numberFloorAndFormat($user_data['lvl_raid']), |
148 | - 'raid_lvl_up' => HelperString::numberFloorAndFormat(rpg_get_raider_xp($user_data['lvl_raid']+1)), |
|
148 | + 'raid_lvl_up' => HelperString::numberFloorAndFormat(rpg_get_raider_xp($user_data['lvl_raid'] + 1)), |
|
149 | 149 | 'raids' => HelperString::numberFloorAndFormat($user_data['raids']), |
150 | 150 | 'raidswin' => HelperString::numberFloorAndFormat($user_data['raidswin']), |
151 | 151 | 'raidsloose' => HelperString::numberFloorAndFormat($user_data['raidsloose']), |
152 | 152 | 'tech_xp' => HelperString::numberFloorAndFormat($user_data['player_rpg_tech_xp']), |
153 | 153 | 'tech_lvl' => HelperString::numberFloorAndFormat($user_data['player_rpg_tech_level']), |
154 | 154 | 'tech_lvl_st' => HelperString::numberFloorAndFormat(rpg_get_tech_xp($user_data['player_rpg_tech_level'])), |
155 | - 'tech_lvl_up' => HelperString::numberFloorAndFormat(rpg_get_tech_xp($user_data['player_rpg_tech_level']+1)), |
|
155 | + 'tech_lvl_up' => HelperString::numberFloorAndFormat(rpg_get_tech_xp($user_data['player_rpg_tech_level'] + 1)), |
|
156 | 156 | |
157 | 157 | 'explore_xp' => HelperString::numberFloorAndFormat($user_data['player_rpg_explore_xp']), |
158 | 158 | 'explore_lvl' => HelperString::numberFloorAndFormat($user_data['player_rpg_explore_level']), |
159 | 159 | 'explore_lvl_st' => HelperString::numberFloorAndFormat(rpg_get_explore_xp($user_data['player_rpg_explore_level'])), |
160 | - 'explore_lvl_up' => HelperString::numberFloorAndFormat(rpg_get_explore_xp($user_data['player_rpg_explore_level']+1)), |
|
161 | - |
|
162 | - 'build_points' => HelperString::numberFloorAndFormat( $StatRecord['build_points'] ), |
|
163 | - 'tech_points' => HelperString::numberFloorAndFormat( $StatRecord['tech_points'] ), |
|
164 | - 'fleet_points' => HelperString::numberFloorAndFormat( $StatRecord['fleet_points'] ), |
|
165 | - 'defs_points' => HelperString::numberFloorAndFormat( $StatRecord['defs_points'] ), |
|
166 | - 'res_points' => HelperString::numberFloorAndFormat( $StatRecord['res_points'] ), |
|
167 | - 'total_points' => HelperString::numberFloorAndFormat( $StatRecord['total_points'] ), |
|
160 | + 'explore_lvl_up' => HelperString::numberFloorAndFormat(rpg_get_explore_xp($user_data['player_rpg_explore_level'] + 1)), |
|
161 | + |
|
162 | + 'build_points' => HelperString::numberFloorAndFormat($StatRecord['build_points']), |
|
163 | + 'tech_points' => HelperString::numberFloorAndFormat($StatRecord['tech_points']), |
|
164 | + 'fleet_points' => HelperString::numberFloorAndFormat($StatRecord['fleet_points']), |
|
165 | + 'defs_points' => HelperString::numberFloorAndFormat($StatRecord['defs_points']), |
|
166 | + 'res_points' => HelperString::numberFloorAndFormat($StatRecord['res_points']), |
|
167 | + 'total_points' => HelperString::numberFloorAndFormat($StatRecord['total_points']), |
|
168 | 168 | 'user_rank' => $StatRecord['total_rank'], |
169 | 169 | 'RANK_DIFF' => $StatRecord['total_old_rank'] - $StatRecord['total_rank'], |
170 | 170 |
@@ -18,10 +18,10 @@ discard block |
||
18 | 18 | function sn_eco_build($que_type, &$auser, &$planet) { |
19 | 19 | global $lang, $config, $template_result; |
20 | 20 | |
21 | - if($ally_id = sys_get_param_id('ally_id')) { |
|
21 | + if ($ally_id = sys_get_param_id('ally_id')) { |
|
22 | 22 | define('SN_IN_ALLY', true); |
23 | 23 | $ranks = \Alliance\Alliance::ally_get_ranks($auser['ally']); |
24 | - if($ranks[$auser['ally_rank_id']]['admin'] || $auser['ally']['ally_owner'] == $auser['id']) { |
|
24 | + if ($ranks[$auser['ally_rank_id']]['admin'] || $auser['ally']['ally_owner'] == $auser['id']) { |
|
25 | 25 | $user = &$auser['ally']['player']; |
26 | 26 | $planet = array( |
27 | 27 | 'metal' => $user['metal'], |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
34 | - if(!$user) { |
|
34 | + if (!$user) { |
|
35 | 35 | $user = &$auser; |
36 | 36 | } |
37 | 37 | |
38 | - switch($action = sys_get_param_escaped('action')) { |
|
38 | + switch ($action = sys_get_param_escaped('action')) { |
|
39 | 39 | case 'create': // Add unit to que for build |
40 | 40 | case 'create_autoconvert': // Add unit to que for build |
41 | 41 | case 'destroy': // Add unit to que for remove |
@@ -52,23 +52,23 @@ discard block |
||
52 | 52 | |
53 | 53 | $group_missile = sn_get_groups('missile'); |
54 | 54 | $silo_capacity_free = 0; |
55 | - if($que_type == QUE_STRUCTURES) { |
|
55 | + if ($que_type == QUE_STRUCTURES) { |
|
56 | 56 | $build_unit_list = sn_get_groups('build_allow'); |
57 | 57 | $build_unit_list = $build_unit_list[$planet['planet_type']]; |
58 | 58 | $artifact_id = ART_NANO_BUILDER; |
59 | 59 | $page_header = $lang['tech'][UNIT_STRUCTURES]; |
60 | - } elseif($que_type == QUE_RESEARCH) { |
|
61 | - if(!mrc_get_level($user, $planet, STRUC_LABORATORY)) { |
|
60 | + } elseif ($que_type == QUE_RESEARCH) { |
|
61 | + if (!mrc_get_level($user, $planet, STRUC_LABORATORY)) { |
|
62 | 62 | messageBox($lang['no_laboratory'], $lang['tech'][UNIT_TECHNOLOGIES]); |
63 | 63 | } |
64 | 64 | |
65 | - if(eco_unit_busy($user, $planet, UNIT_TECHNOLOGIES)) { |
|
65 | + if (eco_unit_busy($user, $planet, UNIT_TECHNOLOGIES)) { |
|
66 | 66 | messageBox($lang['eco_bld_msg_err_laboratory_upgrading'], $lang['tech'][UNIT_TECHNOLOGIES]); |
67 | 67 | } |
68 | 68 | $build_unit_list = sn_get_groups('tech'); |
69 | 69 | $artifact_id = ART_HEURISTIC_CHIP; |
70 | 70 | $page_header = $lang['eco_bld_research_page_name'] . ($user['user_as_ally'] ? " {$lang['sys_of_ally']} {$user['username']}" : ''); |
71 | - } elseif($que_type == QUE_MERCENARY) { |
|
71 | + } elseif ($que_type == QUE_MERCENARY) { |
|
72 | 72 | // if(!mrc_get_level($user, $planet, STRUC_LABORATORY)) { |
73 | 73 | // messageBox($lang['no_laboratory'], $lang['tech'][UNIT_TECHNOLOGIES]); |
74 | 74 | // } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $artifact_id = 0; |
81 | 81 | $page_header = $lang['tech'][UNIT_MERCENARIES] . ($user['user_as_ally'] ? " {$lang['sys_of_ally']} {$user['username']}" : ''); |
82 | 82 | } else { |
83 | - if(mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) == 0) { |
|
83 | + if (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) == 0) { |
|
84 | 84 | messageBox($lang['need_hangar'], $lang['tech'][STRUC_FACTORY_HANGAR]); |
85 | 85 | } |
86 | 86 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $artifact_id = 0; |
90 | 90 | |
91 | 91 | $silo_capacity_free = mrc_get_level($user, $planet, STRUC_SILO) * get_unit_param(STRUC_SILO, P_CAPACITY); |
92 | - foreach($group_missile as $unit_id) { |
|
92 | + foreach ($group_missile as $unit_id) { |
|
93 | 93 | $silo_capacity_free -= (mrc_get_level($user, $planet, $unit_id, false, true) + (isset($in_que[$unit_id]) && $in_que[$unit_id] ? $in_que[$unit_id] : 0)) * get_unit_param($unit_id, P_UNIT_SIZE); |
94 | 94 | } |
95 | 95 | $silo_capacity_free = max(0, $silo_capacity_free); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | */ |
107 | 107 | |
108 | 108 | $template = gettemplate('buildings_builds', true); |
109 | - if(!empty($operation_result)) { |
|
109 | + if (!empty($operation_result)) { |
|
110 | 110 | $template_result['.']['result'][] = $operation_result; |
111 | 111 | } |
112 | 112 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | |
137 | 137 | $record_index = 0; |
138 | 138 | |
139 | - foreach($build_unit_list as $unit_id) { |
|
139 | + foreach ($build_unit_list as $unit_id) { |
|
140 | 140 | $level_base = mrc_get_level($user, $planet, $unit_id, false, true); |
141 | 141 | $level_effective = mrc_get_level($user, $planet, $unit_id); |
142 | 142 | $level_in_que = $in_que[$unit_id]; |
@@ -159,12 +159,12 @@ discard block |
||
159 | 159 | $can_build = $unit_info[P_MAX_STACK] ? max(0, $unit_info[P_MAX_STACK] - $level_in_que - $level_effective) : $build_data['CAN'][BUILD_CREATE]; |
160 | 160 | // Restricting $can_build by free silo capacity |
161 | 161 | $can_build = ($unit_is_missile = in_array($unit_id, $group_missile)) ? min($can_build, floor($silo_capacity_free / $unit_info[P_UNIT_SIZE])) : $can_build; |
162 | - if(!$can_build) { |
|
163 | - if(!$build_data['CAN'][BUILD_CREATE]) { |
|
162 | + if (!$can_build) { |
|
163 | + if (!$build_data['CAN'][BUILD_CREATE]) { |
|
164 | 164 | $build_data['RESULT'][BUILD_CREATE] = BUILD_NO_RESOURCES; |
165 | - } elseif($unit_is_missile && $silo_capacity_free < $unit_info[P_UNIT_SIZE]) { |
|
165 | + } elseif ($unit_is_missile && $silo_capacity_free < $unit_info[P_UNIT_SIZE]) { |
|
166 | 166 | $build_data['RESULT'][BUILD_CREATE] = BUILD_SILO_FULL; |
167 | - } elseif($unit_info[P_MAX_STACK]) { |
|
167 | + } elseif ($unit_info[P_MAX_STACK]) { |
|
168 | 168 | $build_data['RESULT'][BUILD_CREATE] = BUILD_MAX_REACHED; |
169 | 169 | } |
170 | 170 | } |
@@ -232,14 +232,14 @@ discard block |
||
232 | 232 | 'MAP_IS_RESOURCE' => !empty($unit_info[P_UNIT_PRODUCTION]), |
233 | 233 | ); |
234 | 234 | |
235 | - if($unit_stackable) { |
|
235 | + if ($unit_stackable) { |
|
236 | 236 | $level_production_base = array( |
237 | 237 | 'ACTUAL_SHIELD' => HelperString::numberFloorAndFormat(mrc_modify_value($user, false, array(MRC_ADMIRAL, TECH_SHIELD), $unit_info['shield'])), |
238 | 238 | 'ACTUAL_ARMOR' => HelperString::numberFloorAndFormat(mrc_modify_value($user, false, array(MRC_ADMIRAL, TECH_ARMOR), $unit_info['armor'])), |
239 | 239 | 'ACTUAL_WEAPON' => HelperString::numberFloorAndFormat(mrc_modify_value($user, false, array(MRC_ADMIRAL, TECH_WEAPON), $unit_info['attack'])), |
240 | 240 | ); |
241 | 241 | |
242 | - if($unit_info[P_UNIT_TYPE] == UNIT_SHIPS) { |
|
242 | + if ($unit_info[P_UNIT_TYPE] == UNIT_SHIPS) { |
|
243 | 243 | $ship_data = get_ship_data($unit_id, $user); |
244 | 244 | |
245 | 245 | $level_production_base += array( |
@@ -249,9 +249,9 @@ discard block |
||
249 | 249 | ); |
250 | 250 | } |
251 | 251 | |
252 | - if($unit_info[P_UNIT_PRODUCTION]) { |
|
253 | - foreach($unit_info[P_UNIT_PRODUCTION] as $resource_id => $resource_calc) { |
|
254 | - if($resource_income = |
|
252 | + if ($unit_info[P_UNIT_PRODUCTION]) { |
|
253 | + foreach ($unit_info[P_UNIT_PRODUCTION] as $resource_id => $resource_calc) { |
|
254 | + if ($resource_income = |
|
255 | 255 | floor(mrc_modify_value($user, $planet, $sn_modifiers_resource, $resource_calc(1, 10, $user, $planet) |
256 | 256 | * ($resource_id == RES_ENERGY ? $config_resource_multiplier_plain : $config_resource_multiplier) |
257 | 257 | * (isset($density_info[$resource_id]) ? $density_info[$resource_id] : 1))) |
@@ -261,11 +261,11 @@ discard block |
||
261 | 261 | } |
262 | 262 | } |
263 | 263 | $production['.']['resource'][] = $level_production_base; |
264 | - } elseif($unit_info[P_UNIT_PRODUCTION]) { |
|
264 | + } elseif ($unit_info[P_UNIT_PRODUCTION]) { |
|
265 | 265 | $level_production_base = array(); |
266 | 266 | $element_level_start = $level_effective + $in_que[$unit_id]; |
267 | - foreach($unit_info[P_UNIT_PRODUCTION] as $resource_id => $resource_calc) { |
|
268 | - if($resource_income = |
|
267 | + foreach ($unit_info[P_UNIT_PRODUCTION] as $resource_id => $resource_calc) { |
|
268 | + if ($resource_income = |
|
269 | 269 | floor(mrc_modify_value($user, $planet, $sn_modifiers_resource, $resource_calc($element_level_start, 10, $user, $planet) |
270 | 270 | * ($resource_id == RES_ENERGY ? $config_resource_multiplier_plain : $config_resource_multiplier) |
271 | 271 | * (isset($density_info[$resource_id]) ? $density_info[$resource_id] : 1))) |
@@ -275,24 +275,24 @@ discard block |
||
275 | 275 | } |
276 | 276 | |
277 | 277 | $level_start = $level_base_and_que > 1 ? $level_effective + $level_in_que - 1 : 1; |
278 | - for($i = 0; $i < 6; $i++) { |
|
278 | + for ($i = 0; $i < 6; $i++) { |
|
279 | 279 | $level_production = array('LEVEL' => $level_start + $i); |
280 | - foreach($unit_info[P_UNIT_PRODUCTION] as $resource_id => $resource_calc) { |
|
281 | - if( |
|
280 | + foreach ($unit_info[P_UNIT_PRODUCTION] as $resource_id => $resource_calc) { |
|
281 | + if ( |
|
282 | 282 | $resource_income = floor(mrc_modify_value($user, $planet, $sn_modifiers_resource, $resource_calc($level_start + $i, 10, $user, $planet) |
283 | 283 | * ($resource_id == RES_ENERGY ? $config_resource_multiplier_plain : $config_resource_multiplier) |
284 | 284 | * (isset($density_info[$resource_id]) ? $density_info[$resource_id] : 1))) |
285 | 285 | ) { |
286 | 286 | $level_production['R' . $resource_id] = $resource_income; |
287 | 287 | $level_production['D' . $resource_id] = $resource_income - $level_production_base[$resource_id]; |
288 | - if($level_production['D' . $resource_id] == 0) { |
|
288 | + if ($level_production['D' . $resource_id] == 0) { |
|
289 | 289 | $level_production['D' . $resource_id] = '-'; |
290 | 290 | } |
291 | 291 | } |
292 | 292 | } |
293 | 293 | $production['.']['resource'][] = $level_production; |
294 | 294 | } |
295 | - } elseif($unit_id == TECH_ASTROTECH) { |
|
295 | + } elseif ($unit_id == TECH_ASTROTECH) { |
|
296 | 296 | $element_level_start = $level_effective + $in_que[$unit_id]; |
297 | 297 | $level_production_base = array( |
298 | 298 | UNIT_PLAYER_EXPEDITIONS_MAX => get_player_max_expeditons($user, $element_level_start), |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | ); |
301 | 301 | |
302 | 302 | $level_start = $level_base_and_que > 1 ? $level_effective + $level_in_que - 1 : 1; |
303 | - for($i = 0; $i < 6; $i++) { |
|
303 | + for ($i = 0; $i < 6; $i++) { |
|
304 | 304 | $level_production = array('LEVEL' => $level_start + $i); |
305 | 305 | $level_production['R' . UNIT_PLAYER_EXPEDITIONS_MAX] = get_player_max_expeditons($user, $level_start + $i); |
306 | 306 | $level_production['D' . UNIT_PLAYER_EXPEDITIONS_MAX] = $level_production['R' . UNIT_PLAYER_EXPEDITIONS_MAX] - $level_production_base[UNIT_PLAYER_EXPEDITIONS_MAX]; |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | $template_result['.']['production'][] = $production; |
322 | 322 | } |
323 | 323 | |
324 | - foreach($lang['player_option_building_sort'] as $sort_id => $sort_text) { |
|
324 | + foreach ($lang['player_option_building_sort'] as $sort_id => $sort_text) { |
|
325 | 325 | $template->assign_block_vars('sort_values', array( |
326 | 326 | 'VALUE' => $sort_id, |
327 | 327 | 'TEXT' => $sort_text, |
@@ -330,8 +330,8 @@ discard block |
||
330 | 330 | |
331 | 331 | $sort_option = SN::$user_options[array(PLAYER_OPTION_BUILDING_SORT, $que_type)]; |
332 | 332 | $sort_option_inverse = SN::$user_options[array(PLAYER_OPTION_BUILDING_SORT_INVERSE, $que_type)]; |
333 | - if($sort_option || $sort_option_inverse != PLAYER_OPTION_SORT_ORDER_PLAIN) { |
|
334 | - switch($sort_option) { |
|
333 | + if ($sort_option || $sort_option_inverse != PLAYER_OPTION_SORT_ORDER_PLAIN) { |
|
334 | + switch ($sort_option) { |
|
335 | 335 | case PLAYER_OPTION_SORT_NAME: |
336 | 336 | $sort_option_field = 'NAME'; |
337 | 337 | break; |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | break; |
347 | 347 | } |
348 | 348 | $sort_option_inverse_closure = $sort_option_inverse ? -1 : 1; |
349 | - usort($template_result['.']['production'], function ($a, $b) use ($sort_option_field, $sort_option_inverse_closure) { |
|
349 | + usort($template_result['.']['production'], function($a, $b) use ($sort_option_field, $sort_option_inverse_closure) { |
|
350 | 350 | return $a[$sort_option_field] < $b[$sort_option_field] ? -1 * $sort_option_inverse_closure : ( |
351 | 351 | $a[$sort_option_field] > $b[$sort_option_field] ? 1 * $sort_option_inverse_closure : 0 |
352 | 352 | ); |
@@ -5,9 +5,9 @@ discard block |
||
5 | 5 | // @version 1.0 |
6 | 6 | // @copyright 2008 by Chlorel for XNova |
7 | 7 | |
8 | -if($fleet_ship_sort = sys_get_param_id('sort_elements')) { |
|
8 | +if ($fleet_ship_sort = sys_get_param_id('sort_elements')) { |
|
9 | 9 | define('IN_AJAX', true); |
10 | - if(!empty($lang['player_option_fleet_ship_sort'][$fleet_ship_sort])) { |
|
10 | + if (!empty($lang['player_option_fleet_ship_sort'][$fleet_ship_sort])) { |
|
11 | 11 | // player_save_option($user, PLAYER_OPTION_FLEET_SHIP_SORT, $fleet_ship_sort); |
12 | 12 | // player_save_option($user, PLAYER_OPTION_FLEET_SHIP_SORT_INVERSE, sys_get_param_id('fleet_ship_sort_inverse', 0)); |
13 | 13 | SN::$user_options[PLAYER_OPTION_FLEET_SHIP_SORT] = $fleet_ship_sort; |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | die(); |
17 | 17 | } |
18 | 18 | |
19 | -if(SN_IN_FLEET !== true) { |
|
19 | +if (SN_IN_FLEET !== true) { |
|
20 | 20 | $debug->error("Attempt to call FLEET page mode {$mode} directly - not from fleet.php", 'Forbidden', 403); |
21 | 21 | } |
22 | 22 | |
23 | 23 | lng_include('overview'); |
24 | 24 | |
25 | -if(!$planetrow) { |
|
25 | +if (!$planetrow) { |
|
26 | 26 | messageBox($lang['fl_noplanetrow'], $lang['fl_error']); |
27 | 27 | } |
28 | 28 | |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | |
31 | 31 | $record_index = 0; |
32 | 32 | $ship_list = array(); |
33 | -foreach(sn_get_groups('fleet') as $n => $unit_id) { |
|
33 | +foreach (sn_get_groups('fleet') as $n => $unit_id) { |
|
34 | 34 | $unit_level = mrc_get_level($user, $planetrow, $unit_id, false, true); |
35 | - if($unit_level > 0) { |
|
35 | + if ($unit_level > 0) { |
|
36 | 36 | $ship_data = get_ship_data($unit_id, $user); |
37 | 37 | $ship_list[$unit_id] = array( |
38 | 38 | '__INDEX' => $record_index++, |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | |
53 | 53 | $fleet_ship_sort = SN::$user_options[PLAYER_OPTION_FLEET_SHIP_SORT]; |
54 | 54 | $fleet_ship_sort_inverse = SN::$user_options[PLAYER_OPTION_FLEET_SHIP_SORT_INVERSE]; |
55 | -if($fleet_ship_sort || $fleet_ship_sort_inverse != PLAYER_OPTION_SORT_ORDER_PLAIN) { |
|
56 | - switch($fleet_ship_sort) { |
|
55 | +if ($fleet_ship_sort || $fleet_ship_sort_inverse != PLAYER_OPTION_SORT_ORDER_PLAIN) { |
|
56 | + switch ($fleet_ship_sort) { |
|
57 | 57 | case PLAYER_OPTION_SORT_NAME: $fleet_ship_sort_field = 'NAME'; break; |
58 | 58 | case PLAYER_OPTION_SORT_SPEED: $fleet_ship_sort_field = 'SPEED'; break; |
59 | 59 | case PLAYER_OPTION_SORT_COUNT: $fleet_ship_sort_field = 'AMOUNT'; break; |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | }); |
69 | 69 | } |
70 | 70 | |
71 | -foreach($ship_list as $ship_data) { |
|
71 | +foreach ($ship_list as $ship_data) { |
|
72 | 72 | $template->assign_block_vars('ships', $ship_data); |
73 | 73 | } |
74 | 74 | |
75 | -foreach($lang['player_option_fleet_ship_sort'] as $sort_id => $sort_text) { |
|
75 | +foreach ($lang['player_option_fleet_ship_sort'] as $sort_id => $sort_text) { |
|
76 | 76 | $template->assign_block_vars('ship_sort_list', array( |
77 | 77 | 'VALUE' => $sort_id, |
78 | 78 | 'TEXT' => $sort_text, |
@@ -8,11 +8,11 @@ discard block |
||
8 | 8 | } |
9 | 9 | |
10 | 10 | $speeds = array(); |
11 | - if(!empty($fleet)) |
|
11 | + if (!empty($fleet)) |
|
12 | 12 | { |
13 | 13 | foreach ($fleet as $ship_id => $amount) |
14 | 14 | { |
15 | - if($amount && in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) |
|
15 | + if ($amount && in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) |
|
16 | 16 | { |
17 | 17 | $single_ship_data = get_ship_data($ship_id, $user); |
18 | 18 | $speeds[] = $single_ship_data['speed']; |
@@ -26,15 +26,15 @@ discard block |
||
26 | 26 | function flt_travel_distance($from, $to) { |
27 | 27 | global $config; |
28 | 28 | |
29 | - if($from['galaxy'] != $to['galaxy']) |
|
29 | + if ($from['galaxy'] != $to['galaxy']) |
|
30 | 30 | { |
31 | 31 | $distance = abs($from['galaxy'] - $to['galaxy']) * $config->uni_galaxy_distance; |
32 | 32 | } |
33 | - elseif($from['system'] != $to['system']) |
|
33 | + elseif ($from['system'] != $to['system']) |
|
34 | 34 | { |
35 | 35 | $distance = abs($from['system'] - $to['system']) * 5 * 19 + 2700; |
36 | 36 | } |
37 | - elseif($from['planet'] != $to['planet']) |
|
37 | + elseif ($from['planet'] != $to['planet']) |
|
38 | 38 | { |
39 | 39 | $distance = abs($from['planet'] - $to['planet']) * 5 + 1000; |
40 | 40 | } |
@@ -65,14 +65,14 @@ discard block |
||
65 | 65 | |
66 | 66 | $game_fleet_speed = flt_server_flight_speed_multiplier(); |
67 | 67 | $fleet_speed = flt_fleet_speed($user_row, $fleet_array); |
68 | - if(!empty($fleet_array) && $fleet_speed && $game_fleet_speed) |
|
68 | + if (!empty($fleet_array) && $fleet_speed && $game_fleet_speed) |
|
69 | 69 | { |
70 | 70 | $speed_percent = $speed_percent ? max(min($speed_percent, 10), 1) : 10; |
71 | 71 | $real_speed = $speed_percent * sqrt($fleet_speed); |
72 | 72 | |
73 | 73 | $duration = max(1, round((35000 / $speed_percent * sqrt($distance * 10 / $fleet_speed) + 10) / $game_fleet_speed)); |
74 | 74 | |
75 | - foreach($fleet_array as $ship_id => $ship_count) |
|
75 | + foreach ($fleet_array as $ship_id => $ship_count) |
|
76 | 76 | { |
77 | 77 | if (!$ship_id || !$ship_count) |
78 | 78 | { |
@@ -126,19 +126,19 @@ discard block |
||
126 | 126 | |
127 | 127 | $config_bashing_attacks = $config->fleet_bashing_attacks; |
128 | 128 | $config_bashing_interval = $config->fleet_bashing_interval; |
129 | - if(!$config_bashing_attacks) { |
|
129 | + if (!$config_bashing_attacks) { |
|
130 | 130 | // Bashing allowed - protection disabled |
131 | 131 | return ATTACK_ALLOWED; |
132 | 132 | } |
133 | 133 | |
134 | 134 | $bashing_result = ATTACK_BASHING; |
135 | - if($user['ally_id'] && $enemy['ally_id']) { |
|
135 | + if ($user['ally_id'] && $enemy['ally_id']) { |
|
136 | 136 | $relations = ali_relations($user['ally_id'], $enemy['ally_id']); |
137 | - if(!empty($relations)) { |
|
137 | + if (!empty($relations)) { |
|
138 | 138 | $relations = $relations[$enemy['ally_id']]; |
139 | - switch($relations['alliance_diplomacy_relation']) { |
|
139 | + switch ($relations['alliance_diplomacy_relation']) { |
|
140 | 140 | case ALLY_DIPLOMACY_WAR: |
141 | - if(SN_TIME_NOW - $relations['alliance_diplomacy_time'] <= $config->fleet_bashing_war_delay) { |
|
141 | + if (SN_TIME_NOW - $relations['alliance_diplomacy_time'] <= $config->fleet_bashing_war_delay) { |
|
142 | 142 | $bashing_result = ATTACK_BASHING_WAR_DELAY; |
143 | 143 | } else { |
144 | 144 | return ATTACK_ALLOWED; |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | // } |
176 | 176 | // } |
177 | 177 | $bashing_fleet_list = fleet_list_bashing($user['id'], $planet_dst); |
178 | - foreach($bashing_fleet_list as $fleet_row) { |
|
178 | + foreach ($bashing_fleet_list as $fleet_row) { |
|
179 | 179 | // Checking for ACS - each ACS count only once |
180 | - if($fleet_row['fleet_group']) { |
|
180 | + if ($fleet_row['fleet_group']) { |
|
181 | 181 | $bashing_list["{$user['id']}_{$fleet_row['fleet_group']}"] = $fleet_row['fleet_start_time']; |
182 | 182 | } else { |
183 | 183 | $bashing_list[] = $fleet_row['fleet_start_time']; |
@@ -185,12 +185,12 @@ discard block |
||
185 | 185 | } |
186 | 186 | |
187 | 187 | // Check for joining to ACS - if there are already fleets in ACS no checks should be done |
188 | - if($mission == MT_AKS && $bashing_list["{$user['id']}_{$fleet_group}"]) { |
|
188 | + if ($mission == MT_AKS && $bashing_list["{$user['id']}_{$fleet_group}"]) { |
|
189 | 189 | return ATTACK_ALLOWED; |
190 | 190 | } |
191 | 191 | |
192 | 192 | $query = doquery("SELECT bashing_time FROM {{bashing}} WHERE bashing_user_id = {$user['id']} AND bashing_planet_id = {$planet_dst['id']} AND bashing_time >= {$time_limit};"); |
193 | - while($bashing_row = db_fetch($query)) { |
|
193 | + while ($bashing_row = db_fetch($query)) { |
|
194 | 194 | $bashing_list[] = $bashing_row['bashing_time']; |
195 | 195 | } |
196 | 196 | |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | $last_attack = 0; |
200 | 200 | $wave = 0; |
201 | 201 | $attack = 1; |
202 | - foreach($bashing_list as &$bash_time) { |
|
202 | + foreach ($bashing_list as &$bash_time) { |
|
203 | 203 | $attack++; |
204 | - if($bash_time - $last_attack > $config_bashing_interval || $attack > $config_bashing_attacks) { |
|
204 | + if ($bash_time - $last_attack > $config_bashing_interval || $attack > $config_bashing_attacks) { |
|
205 | 205 | $attack = 1; |
206 | 206 | $wave++; |
207 | 207 | } |
@@ -212,21 +212,21 @@ discard block |
||
212 | 212 | return ($wave > $config->fleet_bashing_waves ? $bashing_result : ATTACK_ALLOWED); |
213 | 213 | } |
214 | 214 | |
215 | -function flt_can_attack($planet_src, $planet_dst, $fleet = array(), $mission, $options = false){$result = null; return sn_function_call('flt_can_attack', array($planet_src, $planet_dst, $fleet, $mission, $options, &$result));} |
|
215 | +function flt_can_attack($planet_src, $planet_dst, $fleet = array(), $mission, $options = false) {$result = null; return sn_function_call('flt_can_attack', array($planet_src, $planet_dst, $fleet, $mission, $options, &$result)); } |
|
216 | 216 | function sn_flt_can_attack($planet_src, $planet_dst, $fleet = array(), $mission, $options = false, &$result) { |
217 | 217 | //TODO: try..catch |
218 | 218 | global $config, $user; |
219 | 219 | |
220 | - if($user['vacation']) { |
|
220 | + if ($user['vacation']) { |
|
221 | 221 | return $result = ATTACK_OWN_VACATION; |
222 | 222 | } |
223 | 223 | |
224 | - if(empty($fleet) || !is_array($fleet)) { |
|
224 | + if (empty($fleet) || !is_array($fleet)) { |
|
225 | 225 | return $result = ATTACK_NO_FLEET; |
226 | 226 | } |
227 | 227 | |
228 | 228 | $sn_groups_mission = sn_get_groups('missions'); |
229 | - if(!isset($sn_groups_mission[$mission])) { |
|
229 | + if (!isset($sn_groups_mission[$mission])) { |
|
230 | 230 | return $result = ATTACK_MISSION_ABSENT; |
231 | 231 | } |
232 | 232 | $sn_data_mission = $sn_groups_mission[$mission]; |
@@ -245,32 +245,32 @@ discard block |
||
245 | 245 | $resources = 0; |
246 | 246 | $ship_ids = sn_get_groups('fleet'); |
247 | 247 | $resource_ids = sn_get_groups('resources_loot'); |
248 | - foreach($fleet as $ship_id => $ship_count) { |
|
248 | + foreach ($fleet as $ship_id => $ship_count) { |
|
249 | 249 | $is_ship = in_array($ship_id, $ship_ids); |
250 | 250 | $is_resource = in_array($ship_id, $resource_ids); |
251 | - if(!$is_ship && !$is_resource) { |
|
251 | + if (!$is_ship && !$is_resource) { |
|
252 | 252 | // TODO Спецобработчик для Капитана и модулей |
253 | 253 | // return ATTACK_WRONG_UNIT; |
254 | 254 | } |
255 | 255 | |
256 | - if($ship_count < 0) { |
|
256 | + if ($ship_count < 0) { |
|
257 | 257 | return $result = $is_ship ? ATTACK_SHIP_COUNT_WRONG : ATTACK_RESOURCE_COUNT_WRONG; |
258 | 258 | } |
259 | 259 | |
260 | - if($ship_count > mrc_get_level($user, $planet_src, $ship_id)) { |
|
260 | + if ($ship_count > mrc_get_level($user, $planet_src, $ship_id)) { |
|
261 | 261 | // TODO ATTACK_NO_MISSILE |
262 | 262 | return $result = $is_ship ? ATTACK_NO_SHIPS : ATTACK_NO_RESOURCES; |
263 | 263 | } |
264 | 264 | |
265 | - if($is_ship) { |
|
265 | + if ($is_ship) { |
|
266 | 266 | $single_ship_data = get_ship_data($ship_id, $user); |
267 | - if($single_ship_data[P_SPEED] <= 0) { |
|
267 | + if ($single_ship_data[P_SPEED] <= 0) { |
|
268 | 268 | return $result = ATTACK_ZERO_SPEED; |
269 | 269 | } |
270 | 270 | $ships += $ship_count; |
271 | 271 | $recyclers += in_array($ship_id, sn_get_groups('flt_recyclers')) ? $ship_count : 0; |
272 | 272 | $spies += $ship_id == SHIP_SPY ? $ship_count : 0; |
273 | - } elseif($is_resource) { |
|
273 | + } elseif ($is_resource) { |
|
274 | 274 | $resources += $ship_count; |
275 | 275 | } |
276 | 276 | } |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | } |
282 | 282 | */ |
283 | 283 | |
284 | - if(isset($options['resources']) && $options['resources'] > 0 && !(isset($sn_data_mission['transport']) && $sn_data_mission['transport'])) { |
|
284 | + if (isset($options['resources']) && $options['resources'] > 0 && !(isset($sn_data_mission['transport']) && $sn_data_mission['transport'])) { |
|
285 | 285 | return $result = ATTACK_RESOURCE_FORBIDDEN; |
286 | 286 | } |
287 | 287 | |
@@ -293,35 +293,35 @@ discard block |
||
293 | 293 | */ |
294 | 294 | |
295 | 295 | $speed = $options['fleet_speed_percent']; |
296 | - if($speed && ($speed != intval($speed) || $speed < 1 || $speed > 10)) { |
|
296 | + if ($speed && ($speed != intval($speed) || $speed < 1 || $speed > 10)) { |
|
297 | 297 | return $result = ATTACK_WRONG_SPEED; |
298 | 298 | } |
299 | 299 | |
300 | 300 | $travel_data = flt_travel_data($user, $planet_src, $planet_dst, $fleet, $options['fleet_speed_percent']); |
301 | 301 | |
302 | 302 | |
303 | - if(mrc_get_level($user, $planet_src, RES_DEUTERIUM) < $fleet[RES_DEUTERIUM] + $travel_data['consumption']) { |
|
303 | + if (mrc_get_level($user, $planet_src, RES_DEUTERIUM) < $fleet[RES_DEUTERIUM] + $travel_data['consumption']) { |
|
304 | 304 | return $result = ATTACK_NO_FUEL; |
305 | 305 | } |
306 | 306 | |
307 | - if($travel_data['consumption'] > $travel_data['capacity']) { |
|
307 | + if ($travel_data['consumption'] > $travel_data['capacity']) { |
|
308 | 308 | return $result = ATTACK_TOO_FAR; |
309 | 309 | } |
310 | 310 | |
311 | - if($travel_data['hold'] < $resources) { |
|
311 | + if ($travel_data['hold'] < $resources) { |
|
312 | 312 | return $result = ATTACK_OVERLOADED; |
313 | 313 | } |
314 | 314 | |
315 | 315 | $fleet_start_time = SN_TIME_NOW + $travel_data['duration']; |
316 | 316 | |
317 | 317 | $fleet_group = $options['fleet_group']; |
318 | - if($fleet_group) { |
|
319 | - if($mission != MT_AKS) { |
|
318 | + if ($fleet_group) { |
|
319 | + if ($mission != MT_AKS) { |
|
320 | 320 | return $result = ATTACK_WRONG_MISSION; |
321 | 321 | }; |
322 | 322 | |
323 | 323 | $acs = doquery("SELECT * FROM {{aks}} WHERE id = '{$fleet_group}' LIMIT 1;", '', true); |
324 | - if(!$acs['id']) { |
|
324 | + if (!$acs['id']) { |
|
325 | 325 | return $result = ATTACK_NO_ACS; |
326 | 326 | } |
327 | 327 | |
@@ -329,70 +329,70 @@ discard block |
||
329 | 329 | return $result = ATTACK_ACS_WRONG_TARGET; |
330 | 330 | } |
331 | 331 | |
332 | - if ($fleet_start_time>$acs['ankunft']) { |
|
332 | + if ($fleet_start_time > $acs['ankunft']) { |
|
333 | 333 | return $result = ATTACK_ACS_TOO_LATE; |
334 | 334 | } |
335 | 335 | } |
336 | 336 | |
337 | 337 | $flying_fleets = $options['flying_fleets']; |
338 | - if(!$flying_fleets) { |
|
338 | + if (!$flying_fleets) { |
|
339 | 339 | // $flying_fleets = doquery("SELECT COUNT(fleet_id) AS `flying_fleets` FROM {{fleets}} WHERE `fleet_owner` = '{$user['id']}';", '', true); |
340 | 340 | // $flying_fleets = $flying_fleets['flying_fleets']; |
341 | 341 | $flying_fleets = fleet_count_flying($user['id']); |
342 | 342 | } |
343 | - if(GetMaxFleets($user) <= $flying_fleets && $mission != MT_MISSILE) { |
|
343 | + if (GetMaxFleets($user) <= $flying_fleets && $mission != MT_MISSILE) { |
|
344 | 344 | return $result = ATTACK_NO_SLOTS; |
345 | 345 | } |
346 | 346 | |
347 | 347 | // В одиночку шпионские зонды могут летать только в миссии Шпионаж, Передислокация и Транспорт |
348 | - if($ships && $spies && $spies == $ships && !($mission == MT_SPY || $mission == MT_RELOCATE || $mission == MT_TRANSPORT)) { |
|
348 | + if ($ships && $spies && $spies == $ships && !($mission == MT_SPY || $mission == MT_RELOCATE || $mission == MT_TRANSPORT)) { |
|
349 | 349 | return $result = ATTACK_SPIES_LONLY; |
350 | 350 | } |
351 | 351 | |
352 | 352 | // Checking for no planet |
353 | - if(!$planet_dst['id_owner']) { |
|
354 | - if($mission == MT_COLONIZE && !$fleet[SHIP_COLONIZER]) { |
|
353 | + if (!$planet_dst['id_owner']) { |
|
354 | + if ($mission == MT_COLONIZE && !$fleet[SHIP_COLONIZER]) { |
|
355 | 355 | return $result = ATTACK_NO_COLONIZER; |
356 | 356 | } |
357 | 357 | |
358 | - if($mission == MT_EXPLORE || $mission == MT_COLONIZE) { |
|
358 | + if ($mission == MT_EXPLORE || $mission == MT_COLONIZE) { |
|
359 | 359 | return $result = ATTACK_ALLOWED; |
360 | 360 | } |
361 | 361 | return $result = ATTACK_NO_TARGET; |
362 | 362 | } |
363 | 363 | |
364 | - if($mission == MT_RECYCLE) { |
|
365 | - if($planet_dst['debris_metal'] + $planet_dst['debris_crystal'] <= 0) { |
|
364 | + if ($mission == MT_RECYCLE) { |
|
365 | + if ($planet_dst['debris_metal'] + $planet_dst['debris_crystal'] <= 0) { |
|
366 | 366 | return $result = ATTACK_NO_DEBRIS; |
367 | 367 | } |
368 | - if($recyclers <= 0) { |
|
368 | + if ($recyclers <= 0) { |
|
369 | 369 | return $result = ATTACK_NO_RECYCLERS; |
370 | 370 | } |
371 | 371 | return $result = ATTACK_ALLOWED; |
372 | 372 | } |
373 | 373 | |
374 | 374 | // Got planet. Checking if it is ours |
375 | - if($planet_dst['id_owner'] == $user['id']) { |
|
376 | - if($mission == MT_TRANSPORT || $mission == MT_RELOCATE) { |
|
375 | + if ($planet_dst['id_owner'] == $user['id']) { |
|
376 | + if ($mission == MT_TRANSPORT || $mission == MT_RELOCATE) { |
|
377 | 377 | return $result = ATTACK_ALLOWED; |
378 | 378 | } |
379 | 379 | return $planet_src['id'] == $planet_dst['id'] ? ATTACK_SAME : ATTACK_OWN; |
380 | 380 | } |
381 | 381 | |
382 | 382 | // No, planet not ours. Cutting mission that can't be send to not-ours planet |
383 | - if($mission == MT_RELOCATE || $mission == MT_COLONIZE || $mission == MT_EXPLORE) { |
|
383 | + if ($mission == MT_RELOCATE || $mission == MT_COLONIZE || $mission == MT_EXPLORE) { |
|
384 | 384 | return $result = ATTACK_WRONG_MISSION; |
385 | 385 | } |
386 | 386 | |
387 | 387 | $enemy = db_user_by_id($planet_dst['id_owner']); |
388 | 388 | // We cannot attack or send resource to users in VACATION mode |
389 | - if($enemy['vacation'] && $mission != MT_RECYCLE) { |
|
389 | + if ($enemy['vacation'] && $mission != MT_RECYCLE) { |
|
390 | 390 | return $result = ATTACK_VACATION; |
391 | 391 | } |
392 | 392 | |
393 | 393 | // Multi IP protection |
394 | 394 | // TODO: Here we need a procedure to check proxies |
395 | - if(sys_is_multiaccount($user, $enemy)) { |
|
395 | + if (sys_is_multiaccount($user, $enemy)) { |
|
396 | 396 | return $result = ATTACK_SAME_IP; |
397 | 397 | } |
398 | 398 | |
@@ -400,8 +400,8 @@ discard block |
||
400 | 400 | $enemy_points = $enemy['total_points']; |
401 | 401 | |
402 | 402 | // Is it transport? If yes - checking for buffing to prevent mega-alliance destroyer |
403 | - if($mission == MT_TRANSPORT) { |
|
404 | - if($user_points >= $enemy_points || $config->allow_buffing) { |
|
403 | + if ($mission == MT_TRANSPORT) { |
|
404 | + if ($user_points >= $enemy_points || $config->allow_buffing) { |
|
405 | 405 | return $result = ATTACK_ALLOWED; |
406 | 406 | } else { |
407 | 407 | return $result = ATTACK_BUFFING; |
@@ -411,65 +411,65 @@ discard block |
||
411 | 411 | // Only aggresive missions passed to this point. HOLD counts as passive but aggresive |
412 | 412 | |
413 | 413 | // Is it admin with planet protection? |
414 | - if($planet_dst['id_level'] > $user['authlevel']) { |
|
414 | + if ($planet_dst['id_level'] > $user['authlevel']) { |
|
415 | 415 | return $result = ATTACK_ADMIN; |
416 | 416 | } |
417 | 417 | |
418 | 418 | // Okay. Now skipping protection checks for inactive longer then 1 week |
419 | - if(!$enemy['onlinetime'] || $enemy['onlinetime'] >= (SN_TIME_NOW - 60*60*24*7)) { |
|
420 | - if( |
|
419 | + if (!$enemy['onlinetime'] || $enemy['onlinetime'] >= (SN_TIME_NOW - 60 * 60 * 24 * 7)) { |
|
420 | + if ( |
|
421 | 421 | (SN::$gc->general->playerIsNoobByPoints($enemy_points) && !SN::$gc->general->playerIsNoobByPoints($user_points)) |
422 | 422 | || |
423 | 423 | (SN::$gc->general->playerIs1stStrongerThen2nd($user_points, $enemy_points)) |
424 | 424 | ) { |
425 | - if($mission != MT_HOLD) { |
|
425 | + if ($mission != MT_HOLD) { |
|
426 | 426 | return $result = ATTACK_NOOB; |
427 | 427 | } |
428 | - if($mission == MT_HOLD && !($user['ally_id'] && $user['ally_id'] == $enemy['ally_id'] && $config->ally_help_weak)) { |
|
428 | + if ($mission == MT_HOLD && !($user['ally_id'] && $user['ally_id'] == $enemy['ally_id'] && $config->ally_help_weak)) { |
|
429 | 429 | return $result = ATTACK_NOOB; |
430 | 430 | } |
431 | 431 | } |
432 | 432 | } |
433 | 433 | |
434 | 434 | // Is it HOLD mission? If yes - there should be ally deposit |
435 | - if($mission == MT_HOLD) { |
|
436 | - if(mrc_get_level($user, $planet_dst, STRUC_ALLY_DEPOSIT)) { |
|
435 | + if ($mission == MT_HOLD) { |
|
436 | + if (mrc_get_level($user, $planet_dst, STRUC_ALLY_DEPOSIT)) { |
|
437 | 437 | return $result = ATTACK_ALLOWED; |
438 | 438 | } |
439 | 439 | return $result = ATTACK_NO_ALLY_DEPOSIT; |
440 | 440 | } |
441 | 441 | |
442 | - if($mission == MT_SPY) { |
|
442 | + if ($mission == MT_SPY) { |
|
443 | 443 | return $result = $spies >= 1 ? ATTACK_ALLOWED : ATTACK_NO_SPIES; |
444 | 444 | } |
445 | 445 | |
446 | 446 | // Is it MISSILE mission? |
447 | - if($mission == MT_MISSILE) { |
|
447 | + if ($mission == MT_MISSILE) { |
|
448 | 448 | $sn_data_mip = get_unit_param(UNIT_DEF_MISSILE_INTERPLANET); |
449 | - if(mrc_get_level($user, $planet_src, STRUC_SILO) < $sn_data_mip[P_REQUIRE][STRUC_SILO]) { |
|
449 | + if (mrc_get_level($user, $planet_src, STRUC_SILO) < $sn_data_mip[P_REQUIRE][STRUC_SILO]) { |
|
450 | 450 | return $result = ATTACK_NO_SILO; |
451 | 451 | } |
452 | 452 | |
453 | - if(!$fleet[UNIT_DEF_MISSILE_INTERPLANET]) { |
|
453 | + if (!$fleet[UNIT_DEF_MISSILE_INTERPLANET]) { |
|
454 | 454 | return $result = ATTACK_NO_MISSILE; |
455 | 455 | } |
456 | 456 | |
457 | 457 | $distance = abs($planet_dst['system'] - $planet_src['system']); |
458 | 458 | $mip_range = flt_get_missile_range($user); |
459 | - if($distance > $mip_range || $planet_dst['galaxy'] != $planet_src['galaxy']) { |
|
459 | + if ($distance > $mip_range || $planet_dst['galaxy'] != $planet_src['galaxy']) { |
|
460 | 460 | return $result = ATTACK_MISSILE_TOO_FAR; |
461 | 461 | } |
462 | 462 | |
463 | - if(isset($options['target_structure']) && $options['target_structure'] && !in_array($options['target_structure'], sn_get_groups('defense_active'))) { |
|
463 | + if (isset($options['target_structure']) && $options['target_structure'] && !in_array($options['target_structure'], sn_get_groups('defense_active'))) { |
|
464 | 464 | return $result = ATTACK_WRONG_STRUCTURE; |
465 | 465 | } |
466 | 466 | } |
467 | 467 | |
468 | - if($mission == MT_DESTROY && $planet_dst['planet_type'] != PT_MOON) { |
|
468 | + if ($mission == MT_DESTROY && $planet_dst['planet_type'] != PT_MOON) { |
|
469 | 469 | return $result = ATTACK_WRONG_MISSION; |
470 | 470 | } |
471 | 471 | |
472 | - if($mission == MT_ATTACK || $mission == MT_AKS || $mission == MT_DESTROY) { |
|
472 | + if ($mission == MT_ATTACK || $mission == MT_AKS || $mission == MT_DESTROY) { |
|
473 | 473 | return $result = flt_bashing_check($user, $enemy, $planet_dst, $mission, $travel_data['duration'], $fleet_group); |
474 | 474 | } |
475 | 475 | |
@@ -495,18 +495,18 @@ discard block |
||
495 | 495 | $from = $from['planet']; |
496 | 496 | |
497 | 497 | $can_attack = flt_can_attack($from, $to, $fleet, $mission, $options); |
498 | - if($can_attack != ATTACK_ALLOWED) { |
|
498 | + if ($can_attack != ATTACK_ALLOWED) { |
|
499 | 499 | $internal_transaction ? sn_db_transaction_rollback() : false; |
500 | 500 | return $can_attack; |
501 | 501 | } |
502 | 502 | |
503 | 503 | $fleet_group = isset($options['fleet_group']) ? floatval($options['fleet_group']) : 0; |
504 | 504 | |
505 | - $travel_data = flt_travel_data($user, $from, $to, $fleet, $options['fleet_speed_percent']); |
|
505 | + $travel_data = flt_travel_data($user, $from, $to, $fleet, $options['fleet_speed_percent']); |
|
506 | 506 | |
507 | 507 | $fleet_start_time = SN_TIME_NOW + $travel_data['duration']; |
508 | 508 | |
509 | - if($mission == MT_EXPLORE || $mission == MT_HOLD) { |
|
509 | + if ($mission == MT_EXPLORE || $mission == MT_HOLD) { |
|
510 | 510 | $stay_duration = $options['stay_time'] * 3600; |
511 | 511 | $stay_time = $fleet_start_time + $stay_duration; |
512 | 512 | } else { |
@@ -519,20 +519,20 @@ discard block |
||
519 | 519 | $fleet_string = ''; |
520 | 520 | $db_changeset = array(); |
521 | 521 | $planet_fields = array(); |
522 | - foreach($fleet as $unit_id => $amount) |
|
522 | + foreach ($fleet as $unit_id => $amount) |
|
523 | 523 | { |
524 | - if(!$amount || !$unit_id) |
|
524 | + if (!$amount || !$unit_id) |
|
525 | 525 | { |
526 | 526 | continue; |
527 | 527 | } |
528 | 528 | |
529 | - if(in_array($unit_id, sn_get_groups('fleet'))) |
|
529 | + if (in_array($unit_id, sn_get_groups('fleet'))) |
|
530 | 530 | { |
531 | 531 | $fleet_ship_count += $amount; |
532 | 532 | $fleet_string .= "{$unit_id},{$amount};"; |
533 | 533 | $db_changeset['unit'][] = OldDbChangeSet::db_changeset_prepare_unit($unit_id, -$amount, $user, $from['id']); |
534 | 534 | } |
535 | - elseif(in_array($unit_id, sn_get_groups('resources_loot'))) |
|
535 | + elseif (in_array($unit_id, sn_get_groups('resources_loot'))) |
|
536 | 536 | { |
537 | 537 | $planet_fields[pname_resource_name($unit_id)]['delta'] -= $amount; |
538 | 538 | } |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | |
641 | 641 | $ship_data = array(); |
642 | 642 | $fleet_array = array(); |
643 | - foreach($ship_list as $transport_id => $cork) |
|
643 | + foreach ($ship_list as $transport_id => $cork) |
|
644 | 644 | { |
645 | 645 | $ship_data[$transport_id] = flt_travel_data($user, $from, $to, array($transport_id => 1), 10); |
646 | 646 | } |
@@ -649,10 +649,10 @@ discard block |
||
649 | 649 | $fleet_hold = 0; |
650 | 650 | $fleet_capacity = 0; |
651 | 651 | $fuel_total = $fuel_left = mrc_get_level($user, $from, RES_DEUTERIUM); |
652 | - foreach($ship_data as $transport_id => &$ship_info) |
|
652 | + foreach ($ship_data as $transport_id => &$ship_info) |
|
653 | 653 | { |
654 | 654 | $ship_loaded = min($ship_list[$transport_id], ceil($resource_amount / $ship_info['hold']), floor($fuel_left / $ship_info['consumption'])); |
655 | - if($ship_loaded) |
|
655 | + if ($ship_loaded) |
|
656 | 656 | { |
657 | 657 | $fleet_array[$transport_id] = $ship_loaded; |
658 | 658 | $resource_amount -= min($resource_amount, $ship_info['hold'] * $ship_loaded); |
@@ -3,8 +3,7 @@ discard block |
||
3 | 3 | use DBAL\OldDbChangeSet; |
4 | 4 | use Planet\DBStaticPlanet; |
5 | 5 | |
6 | -function flt_fleet_speed($user, $fleet) |
|
7 | -{ |
|
6 | +function flt_fleet_speed($user, $fleet) { |
|
8 | 7 | if (!is_array($fleet)) |
9 | 8 | { |
10 | 9 | $fleet = array($fleet => 1); |
@@ -32,16 +31,13 @@ discard block |
||
32 | 31 | if($from['galaxy'] != $to['galaxy']) |
33 | 32 | { |
34 | 33 | $distance = abs($from['galaxy'] - $to['galaxy']) * $config->uni_galaxy_distance; |
35 | - } |
|
36 | - elseif($from['system'] != $to['system']) |
|
34 | + } elseif($from['system'] != $to['system']) |
|
37 | 35 | { |
38 | 36 | $distance = abs($from['system'] - $to['system']) * 5 * 19 + 2700; |
39 | - } |
|
40 | - elseif($from['planet'] != $to['planet']) |
|
37 | + } elseif($from['planet'] != $to['planet']) |
|
41 | 38 | { |
42 | 39 | $distance = abs($from['planet'] - $to['planet']) * 5 + 1000; |
43 | - } |
|
44 | - else |
|
40 | + } else |
|
45 | 41 | { |
46 | 42 | $distance = 5; |
47 | 43 | } |
@@ -58,8 +54,7 @@ discard block |
||
58 | 54 | * |
59 | 55 | * @return array |
60 | 56 | */ |
61 | -function flt_travel_data($user_row, $from, $to, $fleet_array, $speed_percent = 10) |
|
62 | -{ |
|
57 | +function flt_travel_data($user_row, $from, $to, $fleet_array, $speed_percent = 10) { |
|
63 | 58 | $distance = flt_travel_distance($from, $to); |
64 | 59 | |
65 | 60 | $consumption = 0; |
@@ -123,8 +118,7 @@ discard block |
||
123 | 118 | ); |
124 | 119 | } |
125 | 120 | |
126 | -function flt_bashing_check($user, $enemy, $planet_dst, $mission, $flight_duration, $fleet_group = 0) |
|
127 | -{ |
|
121 | +function flt_bashing_check($user, $enemy, $planet_dst, $mission, $flight_duration, $fleet_group = 0) { |
|
128 | 122 | global $config; |
129 | 123 | |
130 | 124 | $config_bashing_attacks = $config->fleet_bashing_attacks; |
@@ -534,8 +528,7 @@ discard block |
||
534 | 528 | $fleet_ship_count += $amount; |
535 | 529 | $fleet_string .= "{$unit_id},{$amount};"; |
536 | 530 | $db_changeset['unit'][] = OldDbChangeSet::db_changeset_prepare_unit($unit_id, -$amount, $user, $from['id']); |
537 | - } |
|
538 | - elseif(in_array($unit_id, sn_get_groups('resources_loot'))) |
|
531 | + } elseif(in_array($unit_id, sn_get_groups('resources_loot'))) |
|
539 | 532 | { |
540 | 533 | $planet_fields[pname_resource_name($unit_id)]['delta'] -= $amount; |
541 | 534 | } |
@@ -627,8 +620,7 @@ discard block |
||
627 | 620 | //ini_set('error_reporting', E_ALL ^ E_NOTICE); |
628 | 621 | } |
629 | 622 | |
630 | -function flt_calculate_ship_to_transport_sort($a, $b) |
|
631 | -{ |
|
623 | +function flt_calculate_ship_to_transport_sort($a, $b) { |
|
632 | 624 | return $a['transport_effectivness'] == $b['transport_effectivness'] ? 0 : ($a['transport_effectivness'] > $b['transport_effectivness'] ? -1 : 1); |
633 | 625 | } |
634 | 626 | |
@@ -637,8 +629,7 @@ discard block |
||
637 | 629 | // $resource_amount - how much amount of resources need to be transported |
638 | 630 | // $from - transport from |
639 | 631 | // $to - transport to |
640 | -function flt_calculate_fleet_to_transport($ship_list, $resource_amount, $from, $to) |
|
641 | -{ |
|
632 | +function flt_calculate_fleet_to_transport($ship_list, $resource_amount, $from, $to) { |
|
642 | 633 | global $user; |
643 | 634 | |
644 | 635 | $ship_data = array(); |