@@ -11,6 +11,9 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | require_once('db/db_queries.php'); |
| 13 | 13 | |
| 14 | +/** |
|
| 15 | + * @param string $tablename |
|
| 16 | + */ |
|
| 14 | 17 | function db_change_units_perform($query, $tablename, $object_id) { |
| 15 | 18 | $query = implode(',', $query); |
| 16 | 19 | if($query && $object_id) { |
@@ -63,6 +66,9 @@ discard block |
||
| 63 | 66 | db_change_units_perform($query[LOC_USER], 'users', $user['id']); |
| 64 | 67 | db_change_units_perform($query[LOC_PLANET], 'planets', $planet['id']); |
| 65 | 68 | } |
| 69 | +/** |
|
| 70 | + * @param string $table |
|
| 71 | + */ |
|
| 66 | 72 | function sn_db_perform($table, $values, $type = 'insert', $options = false) { |
| 67 | 73 | $mass_perform = false; |
| 68 | 74 | |
@@ -171,11 +177,8 @@ discard block |
||
| 171 | 177 | /** |
| 172 | 178 | * Функция проверяет статус транзакции |
| 173 | 179 | * |
| 174 | - * @param null|true|false $status Должна ли быть запущена транзакция в момент проверки |
|
| 175 | - * <p>null - транзакция НЕ должна быть запущена</p> |
|
| 176 | - * <p>true - транзакция должна быть запущена - для совместимости с $for_update</p> |
|
| 177 | - * <p>false - всё равно - для совместимости с $for_update</p> |
|
| 178 | - * @return bool Текущий статус транзакции |
|
| 180 | + * @param boolean $transaction_should_be_started |
|
| 181 | + * @return null|boolean Текущий статус транзакции |
|
| 179 | 182 | */ |
| 180 | 183 | function sn_db_transaction_check($transaction_should_be_started = null) { |
| 181 | 184 | return classSupernova::db_transaction_check($transaction_should_be_started); |
@@ -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 classSupernova::db_upd_record_by_id($tablename == 'users' ? LOC_USER : LOC_PLANET, $object_id, $query); |
| 18 | 18 | // return doquery("UPDATE {{{$tablename}}} SET {$query} WHERE `id` = '{$object_id}' LIMIT 1;"); |
| 19 | 19 | } |
@@ -30,15 +30,15 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | $group = sn_get_groups('resources_loot'); |
| 32 | 32 | |
| 33 | - foreach($unit_list as $unit_id => $unit_amount) { |
|
| 34 | - if(!in_array($unit_id, $group)) { |
|
| 33 | + foreach ($unit_list as $unit_id => $unit_amount) { |
|
| 34 | + if (!in_array($unit_id, $group)) { |
|
| 35 | 35 | // TODO - remove later |
| 36 | 36 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: db_change_units() вызван для не-ресурсов!</h1>'); |
| 37 | 37 | pdump(debug_backtrace()); |
| 38 | 38 | die('db_change_units() вызван для не-ресурсов!'); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - if(!$unit_amount) { |
|
| 41 | + if (!$unit_amount) { |
|
| 42 | 42 | continue; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $unit_location = sys_get_unit_location($user, $planet, $unit_id); |
| 48 | 48 | |
| 49 | 49 | // Changing value in object |
| 50 | - switch($unit_location) { |
|
| 50 | + switch ($unit_location) { |
|
| 51 | 51 | case LOC_USER: |
| 52 | 52 | $user[$unit_db_name] += $unit_amount; |
| 53 | 53 | break; |
@@ -69,23 +69,23 @@ discard block |
||
| 69 | 69 | $field_set = ''; |
| 70 | 70 | $value_set = ''; |
| 71 | 71 | |
| 72 | - switch($type) { |
|
| 72 | + switch ($type) { |
|
| 73 | 73 | case 'delete': |
| 74 | 74 | $query = 'DELETE FROM'; |
| 75 | 75 | break; |
| 76 | 76 | |
| 77 | 77 | case 'insert': |
| 78 | 78 | $query = 'INSERT INTO'; |
| 79 | - if(isset($options['__multi'])) { |
|
| 79 | + if (isset($options['__multi'])) { |
|
| 80 | 80 | // Here we generate mass-insert set |
| 81 | 81 | break; |
| 82 | 82 | } |
| 83 | 83 | case 'update': |
| 84 | - if(!$query) { |
|
| 84 | + if (!$query) { |
|
| 85 | 85 | $query = 'UPDATE'; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - foreach($values as $field => &$value) { |
|
| 88 | + foreach ($values as $field => &$value) { |
|
| 89 | 89 | $value_type = gettype($value); |
| 90 | 90 | if ($value_type == 'string') { |
| 91 | 91 | $value = "'" . db_escape($value) . "'"; |
@@ -113,12 +113,12 @@ discard block |
||
| 113 | 113 | $field_set['__IS_SAFE'] = true; |
| 114 | 114 | } |
| 115 | 115 | function sn_db_field_set_make_safe($field_set, $serialize = false) { |
| 116 | - if(!is_array($field_set)) { |
|
| 116 | + if (!is_array($field_set)) { |
|
| 117 | 117 | die('$field_set is not an array!'); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | $result = array(); |
| 121 | - foreach($field_set as $field => $value) { |
|
| 121 | + foreach ($field_set as $field => $value) { |
|
| 122 | 122 | $field = db_escape(trim($field)); |
| 123 | 123 | switch (true) { |
| 124 | 124 | case is_int($value): |
@@ -337,6 +337,11 @@ |
||
| 337 | 337 | */ |
| 338 | 338 | // OK v4 |
| 339 | 339 | // TODO - вынести в отдельный класс |
| 340 | +/** |
|
| 341 | + * @param string $db_id_field_name |
|
| 342 | + * @param string $db_table_name |
|
| 343 | + * @param string $db_value_field_name |
|
| 344 | + */ |
|
| 340 | 345 | function db_get_set_unique_id_value($current_value_unsafe, $db_id_field_name, $db_table_name, $db_value_field_name) { |
| 341 | 346 | $current_value_safe = db_escape($current_value_unsafe); |
| 342 | 347 | $value_id = doquery("SELECT `{$db_id_field_name}` AS id_field FROM {{{$db_table_name}}} WHERE `{$db_value_field_name}` = '{$current_value_safe}' LIMIT 1 FOR UPDATE", true); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | function db_unit_records_sum($unit_id, $user_skip_list_unit) |
| 105 | 105 | { |
| 106 | - return doquery ( |
|
| 106 | + return doquery( |
|
| 107 | 107 | "SELECT unit_player_id, username, sum(unit_level) as unit_level |
| 108 | 108 | FROM {{unit}} JOIN {{users}} AS u ON u.id = unit_player_id |
| 109 | 109 | WHERE unit_player_id != 0 AND unit_snid = {$unit_id} {$user_skip_list_unit} |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | function db_unit_records_plain($unit_id, $user_skip_list_unit) |
| 117 | 117 | { |
| 118 | - return doquery ( |
|
| 118 | + return doquery( |
|
| 119 | 119 | "SELECT unit_player_id, username, unit_level |
| 120 | 120 | FROM {{unit}} JOIN {{users}} AS u ON u.id = unit_player_id |
| 121 | 121 | WHERE unit_player_id != 0 AND unit_snid = {$unit_id} {$user_skip_list_unit} |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | function db_stat_list_statistic($who, $is_common_stat, $Rank, $start, $source = false) { |
| 128 | - if(!$source) { |
|
| 128 | + if (!$source) { |
|
| 129 | 129 | $source = array( |
| 130 | 130 | 'statpoints' => 'statpoints', |
| 131 | 131 | 'users' => 'users', |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | ); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - if($who == 1) { |
|
| 150 | - if($is_common_stat) { // , UNIX_TIMESTAMP(CONCAT(YEAR(CURRENT_DATE), DATE_FORMAT(`user_birthday`, '-%m-%d'))) AS `nearest_birthday` |
|
| 149 | + if ($who == 1) { |
|
| 150 | + if ($is_common_stat) { // , UNIX_TIMESTAMP(CONCAT(YEAR(CURRENT_DATE), DATE_FORMAT(`user_birthday`, '-%m-%d'))) AS `nearest_birthday` |
|
| 151 | 151 | $query_str = |
| 152 | 152 | "SELECT |
| 153 | 153 | @rownum:=@rownum+1 rownum, subject.{$source['id']} as `id`, sp.{$Rank}_rank as rank, sp.{$Rank}_old_rank as rank_old, sp.{$Rank}_points as points, subject.{$source['username']} as `name`, subject.* |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | ORDER BY |
| 162 | 162 | sp.`{$Rank}_rank`, subject.{$source['id']} |
| 163 | 163 | LIMIT |
| 164 | - ". $start .",100;"; |
|
| 164 | + " . $start . ",100;"; |
|
| 165 | 165 | } else { // , UNIX_TIMESTAMP(CONCAT(YEAR(CURRENT_DATE), DATE_FORMAT(`user_birthday`, '-%m-%d'))) AS `nearest_birthday` |
| 166 | 166 | $query_str = |
| 167 | 167 | "SELECT |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | ORDER BY |
| 175 | 175 | subject.{$Rank} DESC, subject.{$source['id']} |
| 176 | 176 | LIMIT |
| 177 | - ". $start .",100;"; |
|
| 177 | + " . $start . ",100;"; |
|
| 178 | 178 | } |
| 179 | 179 | } else { |
| 180 | 180 | // TODO |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | ORDER BY |
| 192 | 192 | sp.`{$Rank}_rank`, subject.id |
| 193 | 193 | LIMIT |
| 194 | - ". $start .",100;"; |
|
| 194 | + " . $start . ",100;"; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | return doquery($query_str); |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | function db_get_set_unique_id_value($current_value_unsafe, $db_id_field_name, $db_table_name, $db_value_field_name) { |
| 278 | 278 | $current_value_safe = db_escape($current_value_unsafe); |
| 279 | 279 | $value_id = doquery("SELECT `{$db_id_field_name}` AS id_field FROM {{{$db_table_name}}} WHERE `{$db_value_field_name}` = '{$current_value_safe}' LIMIT 1 FOR UPDATE", true); |
| 280 | - if(!isset($value_id['id_field']) || !$value_id['id_field']) { |
|
| 280 | + if (!isset($value_id['id_field']) || !$value_id['id_field']) { |
|
| 281 | 281 | doquery("INSERT INTO {{{$db_table_name}}} (`{$db_value_field_name}`) VALUES ('{$current_value_safe}');"); |
| 282 | 282 | $variable_id = db_insert_id(); |
| 283 | 283 | } else { |
@@ -7,8 +7,7 @@ discard block |
||
| 7 | 7 | require_once('db_queries_fleet.php'); |
| 8 | 8 | |
| 9 | 9 | |
| 10 | -function db_planet_list_admin_list($table_parent_columns, $planet_active, $active_time, $planet_type) |
|
| 11 | -{ |
|
| 10 | +function db_planet_list_admin_list($table_parent_columns, $planet_active, $active_time, $planet_type) { |
|
| 12 | 11 | return doquery( |
| 13 | 12 | "SELECT p.*, u.username" . ($table_parent_columns ? ', p1.name AS parent_name' : '') . |
| 14 | 13 | " FROM {{planets}} AS p |
@@ -17,8 +16,7 @@ discard block |
||
| 17 | 16 | " WHERE " . ($planet_active ? "p.last_update >= {$active_time}" : "p.planet_type = {$planet_type}")); |
| 18 | 17 | } |
| 19 | 18 | |
| 20 | -function db_planet_list_search($searchtext) |
|
| 21 | -{ |
|
| 19 | +function db_planet_list_search($searchtext) { |
|
| 22 | 20 | return doquery( |
| 23 | 21 | "SELECT |
| 24 | 22 | p.galaxy, p.system, p.planet, p.planet_type, p.name as planet_name, |
@@ -38,8 +36,7 @@ discard block |
||
| 38 | 36 | |
| 39 | 37 | |
| 40 | 38 | |
| 41 | -function db_user_list_search($searchtext) |
|
| 42 | -{ |
|
| 39 | +function db_user_list_search($searchtext) { |
|
| 43 | 40 | return doquery( |
| 44 | 41 | "SELECT |
| 45 | 42 | pn.player_name, u.id as uid, u.username, u.ally_id, u.id_planet, u.total_points, u.total_rank, |
@@ -57,8 +54,7 @@ discard block |
||
| 57 | 54 | ); |
| 58 | 55 | } |
| 59 | 56 | |
| 60 | -function db_buddy_list_by_user($user_id) |
|
| 61 | -{ |
|
| 57 | +function db_buddy_list_by_user($user_id) { |
|
| 62 | 58 | // return ($user_id = intval($user_id)) ? doquery( |
| 63 | 59 | return ($user_id = idval($user_id)) ? doquery( |
| 64 | 60 | "SELECT |
@@ -84,8 +80,7 @@ discard block |
||
| 84 | 80 | |
| 85 | 81 | |
| 86 | 82 | |
| 87 | -function db_message_list_outbox_by_user_id($user_id) |
|
| 88 | -{ |
|
| 83 | +function db_message_list_outbox_by_user_id($user_id) { |
|
| 89 | 84 | // return ($user_id = intval($user_id)) |
| 90 | 85 | return ($user_id = idval($user_id)) |
| 91 | 86 | ? doquery("SELECT {{messages}}.message_id, {{messages}}.message_owner, {{users}}.id AS message_sender, {{messages}}.message_time, |
@@ -101,8 +96,7 @@ discard block |
||
| 101 | 96 | |
| 102 | 97 | |
| 103 | 98 | |
| 104 | -function db_unit_records_sum($unit_id, $user_skip_list_unit) |
|
| 105 | -{ |
|
| 99 | +function db_unit_records_sum($unit_id, $user_skip_list_unit) { |
|
| 106 | 100 | return doquery ( |
| 107 | 101 | "SELECT unit_player_id, username, sum(unit_level) as unit_level |
| 108 | 102 | FROM {{unit}} JOIN {{users}} AS u ON u.id = unit_player_id |
@@ -113,8 +107,7 @@ discard block |
||
| 113 | 107 | , true); |
| 114 | 108 | } |
| 115 | 109 | |
| 116 | -function db_unit_records_plain($unit_id, $user_skip_list_unit) |
|
| 117 | -{ |
|
| 110 | +function db_unit_records_plain($unit_id, $user_skip_list_unit) { |
|
| 118 | 111 | return doquery ( |
| 119 | 112 | "SELECT unit_player_id, username, unit_level |
| 120 | 113 | FROM {{unit}} JOIN {{users}} AS u ON u.id = unit_player_id |
@@ -198,25 +191,21 @@ discard block |
||
| 198 | 191 | } |
| 199 | 192 | |
| 200 | 193 | |
| 201 | -function db_stat_list_update_user_stats() |
|
| 202 | -{ |
|
| 194 | +function db_stat_list_update_user_stats() { |
|
| 203 | 195 | return doquery("UPDATE {{users}} AS u JOIN {{statpoints}} AS sp ON sp.id_owner = u.id AND sp.stat_code = 1 AND sp.stat_type = 1 SET u.total_rank = sp.total_rank, u.total_points = sp.total_points WHERE user_as_ally IS NULL;"); |
| 204 | 196 | } |
| 205 | 197 | |
| 206 | -function db_stat_list_update_ally_stats() |
|
| 207 | -{ |
|
| 198 | +function db_stat_list_update_ally_stats() { |
|
| 208 | 199 | return doquery("UPDATE {{alliance}} AS a JOIN {{statpoints}} AS sp ON sp.id_ally = a.id AND sp.stat_code = 1 AND sp.stat_type = 2 SET a.total_rank = sp.total_rank, a.total_points = sp.total_points;"); |
| 209 | 200 | } |
| 210 | 201 | |
| 211 | -function db_stat_list_delete_ally_player() |
|
| 212 | -{ |
|
| 202 | +function db_stat_list_delete_ally_player() { |
|
| 213 | 203 | return doquery('DELETE s FROM {{statpoints}} AS s JOIN {{users}} AS u ON u.id = s.id_owner WHERE s.id_ally IS NULL AND u.user_as_ally IS NOT NULL'); |
| 214 | 204 | } |
| 215 | 205 | |
| 216 | 206 | |
| 217 | 207 | |
| 218 | -function db_chat_player_list_online($chat_refresh_rate, $ally_add) |
|
| 219 | -{ |
|
| 208 | +function db_chat_player_list_online($chat_refresh_rate, $ally_add) { |
|
| 220 | 209 | $sql_date = SN_TIME_NOW - $chat_refresh_rate * 2; |
| 221 | 210 | |
| 222 | 211 | return doquery( |
@@ -230,13 +219,11 @@ discard block |
||
| 230 | 219 | ORDER BY authlevel DESC, `username`"); |
| 231 | 220 | } |
| 232 | 221 | |
| 233 | -function db_referrals_list_by_id($user_id) |
|
| 234 | -{ |
|
| 222 | +function db_referrals_list_by_id($user_id) { |
|
| 235 | 223 | return doquery("SELECT r.*, u.username, u.register_time FROM {{referrals}} AS r LEFT JOIN {{users}} AS u ON u.id = r.id WHERE id_partner = {$user_id}"); |
| 236 | 224 | } |
| 237 | 225 | |
| 238 | -function db_message_list_admin_by_type($int_type_selected, $StartRec) |
|
| 239 | -{ |
|
| 226 | +function db_message_list_admin_by_type($int_type_selected, $StartRec) { |
|
| 240 | 227 | return doquery("SELECT |
| 241 | 228 | message_id as `ID`, |
| 242 | 229 | message_from as `FROM`, |
@@ -255,8 +242,7 @@ discard block |
||
| 255 | 242 | } |
| 256 | 243 | |
| 257 | 244 | |
| 258 | -function db_message_insert_all($message_type, $from, $subject, $text) |
|
| 259 | -{ |
|
| 245 | +function db_message_insert_all($message_type, $from, $subject, $text) { |
|
| 260 | 246 | return doquery($QryInsertMessage = 'INSERT INTO {{messages}} (`message_owner`, `message_sender`, `message_time`, `message_type`, `message_from`, `message_subject`, `message_text`) ' . |
| 261 | 247 | "SELECT `id`, 0, unix_timestamp(now()), {$message_type}, '{$from}', '{$subject}', '{$text}' FROM {{users}}"); |
| 262 | 248 | } |
@@ -1,5 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | +/** |
|
| 4 | + * @param boolean $player |
|
| 5 | + */ |
|
| 3 | 6 | function db_user_by_id($user_id_unsafe, $for_update = false, $fields = '*', $player = null) { |
| 4 | 7 | return classSupernova::db_get_user_by_id($user_id_unsafe, $for_update, $fields, $player); |
| 5 | 8 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | "SELECT `id` AS `ID`, `username` AS `NAME`, `ally_name` AS `ALLY`, `total_points` AS `STAT_POINTS`, |
| 84 | 84 | `onlinetime` AS `ACTIVITY` |
| 85 | 85 | FROM {{users}} |
| 86 | - WHERE `onlinetime` >= ". (SN_TIME_NOW - $config->game_users_online_timeout) ." ORDER BY user_as_ally, `". $TypeSort ."` ASC;"); |
|
| 86 | + WHERE `onlinetime` >= ". (SN_TIME_NOW - $config->game_users_online_timeout) . " ORDER BY user_as_ally, `" . $TypeSort . "` ASC;"); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | return doquery("SELECT u.*, COUNT(r.id) AS referral_count, SUM(r.dark_matter) AS referral_dm FROM {{users}} as u |
| 99 | 99 | LEFT JOIN {{referrals}} as r on r.id_partner = u.id |
| 100 | 100 | WHERE" . |
| 101 | - ($online ? " `onlinetime` >= ". (SN_TIME_NOW - $config->game_users_online_timeout) : ' user_as_ally IS NULL') . |
|
| 101 | + ($online ? " `onlinetime` >= " . (SN_TIME_NOW - $config->game_users_online_timeout) : ' user_as_ally IS NULL') . |
|
| 102 | 102 | " GROUP BY u.id |
| 103 | 103 | ORDER BY user_as_ally, {$sort} ASC"); |
| 104 | 104 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | !is_array($user_id_list) ? $user_id_list = array($user_id_list) : false; |
| 115 | 115 | |
| 116 | 116 | $user_list = array(); |
| 117 | - foreach($user_id_list as $user_id_unsafe) { |
|
| 117 | + foreach ($user_id_list as $user_id_unsafe) { |
|
| 118 | 118 | $user = db_user_by_id($user_id_unsafe); |
| 119 | 119 | !empty($user) ? $user_list[$user_id_unsafe] = $user : false; |
| 120 | 120 | } |
@@ -10,6 +10,7 @@ discard block |
||
| 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 |
||
| 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; |
@@ -13,13 +13,13 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | function eco_get_lab_max_effective_level(&$user, $lab_require) |
| 15 | 15 | { |
| 16 | - if(!$user['user_as_ally'] && !isset($user['laboratories_active'])) |
|
| 16 | + if (!$user['user_as_ally'] && !isset($user['laboratories_active'])) |
|
| 17 | 17 | { |
| 18 | 18 | $user['laboratories_active'] = array(); |
| 19 | 19 | $query = DBStaticUnit::db_unit_list_laboratories($user['id']); |
| 20 | - while($row = db_fetch($query)) |
|
| 20 | + while ($row = db_fetch($query)) |
|
| 21 | 21 | { |
| 22 | - if(!eco_unit_busy($user, $row, UNIT_TECHNOLOGIES)) |
|
| 22 | + if (!eco_unit_busy($user, $row, UNIT_TECHNOLOGIES)) |
|
| 23 | 23 | { |
| 24 | 24 | $row += array( |
| 25 | 25 | STRUC_LABORATORY => $level_lab = mrc_get_level($user, $row, STRUC_LABORATORY), |
@@ -33,9 +33,9 @@ discard block |
||
| 33 | 33 | uasort($user['laboratories_active'], 'eco_lab_sort_effectivness'); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - if(!isset($user['research_effective_level'][$lab_require])) |
|
| 36 | + if (!isset($user['research_effective_level'][$lab_require])) |
|
| 37 | 37 | { |
| 38 | - if($user['user_as_ally']) |
|
| 38 | + if ($user['user_as_ally']) |
|
| 39 | 39 | { |
| 40 | 40 | $lab_level = doquery("SELECT ally_members AS effective_level FROM {{alliance}} WHERE id = {$user['user_as_ally']} LIMIT 1", true); |
| 41 | 41 | } |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | $tech_intergalactic = mrc_get_level($user, false, TECH_RESEARCH) + 1; |
| 45 | 45 | $lab_level['effective_level'] = 0; |
| 46 | 46 | |
| 47 | - foreach($user['laboratories_active'] as $data) |
|
| 47 | + foreach ($user['laboratories_active'] as $data) |
|
| 48 | 48 | { |
| 49 | - if($tech_intergalactic <= 0) |
|
| 49 | + if ($tech_intergalactic <= 0) |
|
| 50 | 50 | { |
| 51 | 51 | break; |
| 52 | 52 | } |
| 53 | - if($data[STRUC_LABORATORY] >= $lab_require) |
|
| 53 | + if ($data[STRUC_LABORATORY] >= $lab_require) |
|
| 54 | 54 | { |
| 55 | 55 | $lab_level['effective_level'] += $data['laboratory_effective_level']; |
| 56 | 56 | $tech_intergalactic--; |
@@ -79,8 +79,8 @@ discard block |
||
| 79 | 79 | $time = 0; |
| 80 | 80 | $only_dark_matter = 0; |
| 81 | 81 | $cost_in_metal = 0; |
| 82 | - foreach($unit_data[P_COST] as $resource_id => $resource_amount) { |
|
| 83 | - if($resource_id === P_FACTOR || !($resource_cost = $resource_amount * $price_increase)) { |
|
| 82 | + foreach ($unit_data[P_COST] as $resource_id => $resource_amount) { |
|
| 83 | + if ($resource_id === P_FACTOR || !($resource_cost = $resource_amount * $price_increase)) { |
|
| 84 | 84 | continue; |
| 85 | 85 | } |
| 86 | 86 | |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | $resource_db_name = pname_resource_name($resource_id); |
| 91 | 91 | $cost_in_metal += $cost[BUILD_CREATE][$resource_id] * $config->__get("rpg_exchange_{$resource_db_name}"); |
| 92 | - if(in_array($resource_id, sn_get_groups('resources_loot'))) { |
|
| 92 | + if (in_array($resource_id, sn_get_groups('resources_loot'))) { |
|
| 93 | 93 | $time += $resource_cost * $config->__get("rpg_exchange_{$resource_db_name}") / $rpg_exchange_deuterium; |
| 94 | 94 | $resource_got = mrc_get_level($user, $planet, $resource_id); |
| 95 | - } elseif($resource_id == RES_DARK_MATTER) { |
|
| 95 | + } elseif ($resource_id == RES_DARK_MATTER) { |
|
| 96 | 96 | $resource_got = mrc_get_level($user, null, $resource_id); |
| 97 | - } elseif($resource_id == RES_ENERGY) { |
|
| 97 | + } elseif ($resource_id == RES_ENERGY) { |
|
| 98 | 98 | $resource_got = max(0, $planet['energy_max'] - $planet['energy_used']); |
| 99 | 99 | } else { |
| 100 | 100 | $resource_got = 0; |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | $resources_normalized = 0; |
| 109 | 109 | $resources_loot = sn_get_groups('resources_loot'); |
| 110 | - foreach($resources_loot as $resource_id) { |
|
| 110 | + foreach ($resources_loot as $resource_id) { |
|
| 111 | 111 | $resource_db_name = pname_resource_name($resource_id); |
| 112 | 112 | $resource_got = mrc_get_level($user, $planet, $resource_id); |
| 113 | 113 | $resources_normalized += floor($resource_got) * $config->__get("rpg_exchange_{$resource_db_name}"); |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | $cost[P_OPTIONS][P_TIME_RAW] = $time = $time * 60 * 60 / get_game_speed() / 2500; |
| 126 | 126 | |
| 127 | 127 | // TODO - Вынести в отдельную процедуру расчёт стоимости |
| 128 | - if($only_cost) { |
|
| 128 | + if ($only_cost) { |
|
| 129 | 129 | return $cost; |
| 130 | 130 | } |
| 131 | 131 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | $mercenary = 0; |
| 136 | 136 | $cost['RESULT'][BUILD_DESTROY] = BUILD_INDESTRUCTABLE; |
| 137 | - if(in_array($unit_id, sn_get_groups('structures'))) { |
|
| 137 | + if (in_array($unit_id, sn_get_groups('structures'))) { |
|
| 138 | 138 | $time = $time * pow(0.5, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) / (mrc_get_level($user, $planet, STRUC_FACTORY_ROBOT) + 1); |
| 139 | 139 | $mercenary = MRC_ENGINEER; |
| 140 | 140 | $cost['RESULT'][BUILD_DESTROY] = |
@@ -144,23 +144,23 @@ discard block |
||
| 144 | 144 | : BUILD_NO_RESOURCES |
| 145 | 145 | ) |
| 146 | 146 | : BUILD_NO_UNITS; |
| 147 | - } elseif(in_array($unit_id, sn_get_groups('tech'))) { |
|
| 147 | + } elseif (in_array($unit_id, sn_get_groups('tech'))) { |
|
| 148 | 148 | $lab_level = eco_get_lab_max_effective_level($user, intval($unit_data['require'][STRUC_LABORATORY])); |
| 149 | 149 | $time = $time / $lab_level; |
| 150 | 150 | $mercenary = MRC_ACADEMIC; |
| 151 | - } elseif(in_array($unit_id, sn_get_groups('defense'))) { |
|
| 152 | - $time = $time * pow(0.5, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) / (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) + 1) ; |
|
| 151 | + } elseif (in_array($unit_id, sn_get_groups('defense'))) { |
|
| 152 | + $time = $time * pow(0.5, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) / (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) + 1); |
|
| 153 | 153 | $mercenary = MRC_FORTIFIER; |
| 154 | - } elseif(in_array($unit_id, sn_get_groups('fleet'))) { |
|
| 154 | + } elseif (in_array($unit_id, sn_get_groups('fleet'))) { |
|
| 155 | 155 | $time = $time * pow(0.5, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) / (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) + 1); |
| 156 | 156 | $mercenary = MRC_ENGINEER; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - if($mercenary) { |
|
| 159 | + if ($mercenary) { |
|
| 160 | 160 | $time = $time / mrc_modify_value($user, $planet, $mercenary, 1); |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - if(in_array($unit_id, sn_get_groups('governors')) || $only_dark_matter) { |
|
| 163 | + if (in_array($unit_id, sn_get_groups('governors')) || $only_dark_matter) { |
|
| 164 | 164 | $cost[RES_TIME][BUILD_CREATE] = $cost[RES_TIME][BUILD_DESTROY] = 0; |
| 165 | 165 | } else { |
| 166 | 166 | $cost[RES_TIME][BUILD_CREATE] = round($time >= 1 ? $time : 1); |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | return $cost; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | -function eco_can_build_unit($user, $planet, $unit_id){return sn_function_call('eco_can_build_unit', array($user, $planet, $unit_id, &$result));} |
|
| 173 | +function eco_can_build_unit($user, $planet, $unit_id) {return sn_function_call('eco_can_build_unit', array($user, $planet, $unit_id, &$result)); } |
|
| 174 | 174 | function sn_eco_can_build_unit($user, $planet, $unit_id, &$result) { |
| 175 | 175 | global $config; |
| 176 | 176 | |
@@ -178,11 +178,11 @@ discard block |
||
| 178 | 178 | $result = $result == BUILD_ALLOWED && eco_unit_busy($user, $planet, $unit_id) ? BUILD_UNIT_BUSY : $result; |
| 179 | 179 | |
| 180 | 180 | $unit_param = get_unit_param($unit_id); |
| 181 | - if($unit_param[P_UNIT_TYPE] != UNIT_MERCENARIES || !$config->empire_mercenary_temporary) { |
|
| 181 | + if ($unit_param[P_UNIT_TYPE] != UNIT_MERCENARIES || !$config->empire_mercenary_temporary) { |
|
| 182 | 182 | $requirement = &$unit_param[P_REQUIRE]; |
| 183 | - if($result == BUILD_ALLOWED && $requirement) { |
|
| 184 | - foreach($requirement as $require_id => $require_level) { |
|
| 185 | - if(mrc_get_level($user, $planet, $require_id) < $require_level) { |
|
| 183 | + if ($result == BUILD_ALLOWED && $requirement) { |
|
| 184 | + foreach ($requirement as $require_id => $require_level) { |
|
| 185 | + if (mrc_get_level($user, $planet, $require_id) < $require_level) { |
|
| 186 | 186 | $result = BUILD_REQUIRE_NOT_MEET; |
| 187 | 187 | break; |
| 188 | 188 | } |
@@ -199,12 +199,12 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | $unit_list = is_array($unit_list) ? $unit_list : array($unit_list => $unit_list); |
| 201 | 201 | $planet_que = explode(';', $planet_que); |
| 202 | - foreach($planet_que as $planet_que_item) |
|
| 202 | + foreach ($planet_que as $planet_que_item) |
|
| 203 | 203 | { |
| 204 | - if($planet_que_item) |
|
| 204 | + if ($planet_que_item) |
|
| 205 | 205 | { |
| 206 | 206 | list($planet_que_item) = explode(',', $planet_que_item); |
| 207 | - if(in_array($planet_que_item, $unit_list)) |
|
| 207 | + if (in_array($planet_que_item, $unit_list)) |
|
| 208 | 208 | { |
| 209 | 209 | $eco_is_builds_in_que = true; |
| 210 | 210 | break; |
@@ -215,21 +215,21 @@ discard block |
||
| 215 | 215 | return $eco_is_builds_in_que; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | -function eco_unit_busy(&$user, &$planet, $unit_id){return sn_function_call('eco_unit_busy', array(&$user, &$planet, $unit_id, &$result));} |
|
| 218 | +function eco_unit_busy(&$user, &$planet, $unit_id) {return sn_function_call('eco_unit_busy', array(&$user, &$planet, $unit_id, &$result)); } |
|
| 219 | 219 | function sn_eco_unit_busy(&$user, &$planet, $unit_id, &$result) |
| 220 | 220 | { |
| 221 | 221 | global $config; |
| 222 | 222 | |
| 223 | 223 | $result = isset($result) ? $result : false; |
| 224 | - if(!$result) |
|
| 224 | + if (!$result) |
|
| 225 | 225 | { |
| 226 | - if(($unit_id == STRUC_LABORATORY || $unit_id == STRUC_LABORATORY_NANO) && !$config->BuildLabWhileRun) |
|
| 226 | + if (($unit_id == STRUC_LABORATORY || $unit_id == STRUC_LABORATORY_NANO) && !$config->BuildLabWhileRun) |
|
| 227 | 227 | { |
| 228 | 228 | $global_que = que_get($user['id'], $planet['id'], QUE_RESEARCH, false); |
| 229 | - if(is_array($global_que['ques'][QUE_RESEARCH][$user['id']])) |
|
| 229 | + if (is_array($global_que['ques'][QUE_RESEARCH][$user['id']])) |
|
| 230 | 230 | { |
| 231 | 231 | $first_element = reset($global_que['ques'][QUE_RESEARCH][$user['id']]); |
| 232 | - if(is_array($first_element)) |
|
| 232 | + if (is_array($first_element)) |
|
| 233 | 233 | { |
| 234 | 234 | $result = true; |
| 235 | 235 | } |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | // $result = true; |
| 240 | 240 | //} |
| 241 | 241 | } |
| 242 | - elseif(($unit_id == UNIT_TECHNOLOGIES || in_array($unit_id, sn_get_groups('tech'))) && !$config->BuildLabWhileRun && $planet['que']) |
|
| 242 | + elseif (($unit_id == UNIT_TECHNOLOGIES || in_array($unit_id, sn_get_groups('tech'))) && !$config->BuildLabWhileRun && $planet['que']) |
|
| 243 | 243 | { |
| 244 | 244 | $result = eco_is_builds_in_que($planet['que'], array(STRUC_LABORATORY, STRUC_LABORATORY_NANO)); |
| 245 | 245 | } |
@@ -1,7 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -function eco_lab_sort_effectivness($a, $b) |
|
| 4 | -{ |
|
| 3 | +function eco_lab_sort_effectivness($a, $b) { |
|
| 5 | 4 | return $a['laboratory_effective_level'] > $b['laboratory_effective_level'] ? -1 : ($a['laboratory_effective_level'] < $b['laboratory_effective_level'] ? 1 : 0); |
| 6 | 5 | } |
| 7 | 6 | |
@@ -11,8 +10,7 @@ discard block |
||
| 11 | 10 | * 1.0 - copyright (c) 2010 by Gorlum for http://supernova.ws |
| 12 | 11 | * @version 1.0 |
| 13 | 12 | */ |
| 14 | -function eco_get_lab_max_effective_level(&$user, $lab_require) |
|
| 15 | -{ |
|
| 13 | +function eco_get_lab_max_effective_level(&$user, $lab_require) { |
|
| 16 | 14 | if(!$user['user_as_ally'] && !isset($user['laboratories_active'])) |
| 17 | 15 | { |
| 18 | 16 | $user['laboratories_active'] = array(); |
@@ -38,8 +36,7 @@ discard block |
||
| 38 | 36 | if($user['user_as_ally']) |
| 39 | 37 | { |
| 40 | 38 | $lab_level = doquery("SELECT ally_members AS effective_level FROM {{alliance}} WHERE id = {$user['user_as_ally']} LIMIT 1", true); |
| 41 | - } |
|
| 42 | - else |
|
| 39 | + } else |
|
| 43 | 40 | { |
| 44 | 41 | $tech_intergalactic = mrc_get_level($user, false, TECH_RESEARCH) + 1; |
| 45 | 42 | $lab_level['effective_level'] = 0; |
@@ -193,8 +190,7 @@ discard block |
||
| 193 | 190 | return $result; |
| 194 | 191 | } |
| 195 | 192 | |
| 196 | -function eco_is_builds_in_que($planet_que, $unit_list) |
|
| 197 | -{ |
|
| 193 | +function eco_is_builds_in_que($planet_que, $unit_list) { |
|
| 198 | 194 | $eco_is_builds_in_que = false; |
| 199 | 195 | |
| 200 | 196 | $unit_list = is_array($unit_list) ? $unit_list : array($unit_list => $unit_list); |
@@ -216,8 +212,7 @@ discard block |
||
| 216 | 212 | } |
| 217 | 213 | |
| 218 | 214 | function eco_unit_busy(&$user, &$planet, $unit_id){return sn_function_call('eco_unit_busy', array(&$user, &$planet, $unit_id, &$result));} |
| 219 | -function sn_eco_unit_busy(&$user, &$planet, $unit_id, &$result) |
|
| 220 | -{ |
|
| 215 | +function sn_eco_unit_busy(&$user, &$planet, $unit_id, &$result) { |
|
| 221 | 216 | global $config; |
| 222 | 217 | |
| 223 | 218 | $result = isset($result) ? $result : false; |
@@ -238,8 +233,7 @@ discard block |
||
| 238 | 233 | //{ |
| 239 | 234 | // $result = true; |
| 240 | 235 | //} |
| 241 | - } |
|
| 242 | - elseif(($unit_id == UNIT_TECHNOLOGIES || in_array($unit_id, sn_get_groups('tech'))) && !$config->BuildLabWhileRun && $planet['que']) |
|
| 236 | + } elseif(($unit_id == UNIT_TECHNOLOGIES || in_array($unit_id, sn_get_groups('tech'))) && !$config->BuildLabWhileRun && $planet['que']) |
|
| 243 | 237 | { |
| 244 | 238 | $result = eco_is_builds_in_que($planet['que'], array(STRUC_LABORATORY, STRUC_LABORATORY_NANO)); |
| 245 | 239 | } |
@@ -55,6 +55,9 @@ discard block |
||
| 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 |
||
| 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 | |
@@ -2,8 +2,8 @@ discard block |
||
| 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 | } |
@@ -16,14 +16,14 @@ discard block |
||
| 16 | 16 | function que_get_max_que_length($user, $planet, $que_id, $que_data = null) { |
| 17 | 17 | global $config; |
| 18 | 18 | |
| 19 | - if(empty($que_data)) { |
|
| 19 | + if (empty($que_data)) { |
|
| 20 | 20 | $que_data = sn_get_groups('ques'); |
| 21 | 21 | $que_data = $que_data[$que_id]; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | $que_length = 1; |
| 26 | - switch($que_id) { |
|
| 26 | + switch ($que_id) { |
|
| 27 | 27 | case QUE_RESEARCH: |
| 28 | 28 | $que_length = $config->server_que_length_research + mrc_get_level($user, '', UNIT_PREMIUM); // TODO - вынести в модуль |
| 29 | 29 | break; |
@@ -37,8 +37,8 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | function eco_que_str2arr($que_str) { |
| 39 | 39 | $que_arr = explode(';', $que_str); |
| 40 | - foreach($que_arr as $que_index => &$que_item) { |
|
| 41 | - if($que_item) { |
|
| 40 | + foreach ($que_arr as $que_index => &$que_item) { |
|
| 41 | + if ($que_item) { |
|
| 42 | 42 | $que_item = explode(',', $que_item); |
| 43 | 43 | } else { |
| 44 | 44 | unset($que_arr[$que_index]); |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | function eco_que_arr2str($que_arr) { |
| 51 | - foreach($que_arr as &$que_item) { |
|
| 51 | + foreach ($que_arr as &$que_item) { |
|
| 52 | 52 | $que_item = implode(',', $que_item); |
| 53 | 53 | } |
| 54 | 54 | return implode(';', $que_arr); |
@@ -59,14 +59,14 @@ discard block |
||
| 59 | 59 | global $lang, $config; |
| 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 |
||
| 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,11 +94,11 @@ discard block |
||
| 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])) { |
|
| 101 | + if (!isset($que_data['unit_list'][$unit_id])) { |
|
| 102 | 102 | throw new exception('{Это здание нельзя строить на ' . ($planet['planet_type'] == PT_PLANET ? 'планете' : 'луне'), ERR_ERROR); // TODO EXCEPTION |
| 103 | 103 | } |
| 104 | 104 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 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 = DBStaticPlanet::db_planet_by_id($planet['id'], true); |
| 124 | 124 | } else { |
| 125 | 125 | $planet['id'] = 0; |
@@ -131,17 +131,17 @@ discard block |
||
| 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: break; |
| 141 | 141 | case BUILD_UNIT_BUSY: throw new exception('{Строение занято}', ERR_ERROR); break; // TODO EXCEPTION eco_bld_msg_err_laboratory_upgrading |
| 142 | 142 | // case BUILD_REQUIRE_NOT_MEET: |
| 143 | 143 | default: |
| 144 | - if($build_mode == BUILD_CREATE) { |
|
| 144 | + if ($build_mode == BUILD_CREATE) { |
|
| 145 | 145 | throw new exception('{Требования не удовлетворены}', ERR_ERROR); |
| 146 | 146 | } |
| 147 | 147 | break; // TODO EXCEPTION eco_bld_msg_err_requirements_not_meet |
@@ -151,14 +151,14 @@ discard block |
||
| 151 | 151 | $unit_amount_qued = $unit_amount; |
| 152 | 152 | $units_qued = isset($in_que[$unit_id]) ? $in_que[$unit_id] : 0; |
| 153 | 153 | $unit_level = mrc_get_level($user, $planet, $unit_id, true, true) + $units_qued; |
| 154 | - if($unit_max = get_unit_param($unit_id, P_MAX_STACK)) { |
|
| 155 | - if($unit_level >= $unit_max) { |
|
| 154 | + if ($unit_max = get_unit_param($unit_id, P_MAX_STACK)) { |
|
| 155 | + if ($unit_level >= $unit_max) { |
|
| 156 | 156 | throw new exception('{Максимальное количество юнитов данного типа уже достигнуто или будет достигнуто по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION |
| 157 | 157 | } |
| 158 | 158 | $unit_amount = max(0, min($unit_amount, $unit_max - $unit_level)); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - if($unit_amount < 1) { |
|
| 161 | + if ($unit_amount < 1) { |
|
| 162 | 162 | throw new exception('{Неправильное количество юнитов - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION |
| 163 | 163 | } |
| 164 | 164 | |
@@ -174,21 +174,21 @@ discard block |
||
| 174 | 174 | // { |
| 175 | 175 | // die('Unit busy'); // TODO EXCEPTION |
| 176 | 176 | // } |
| 177 | - if(get_unit_param($unit_id, P_STACKABLE)) { |
|
| 177 | + if (get_unit_param($unit_id, P_STACKABLE)) { |
|
| 178 | 178 | // TODO Поле 'max_Lot_size' для ограничения размера стэка в очереди - то ли в юниты, то ли в очередь |
| 179 | - if(in_array($unit_id, $group_missile = sn_get_groups('missile'))) { |
|
| 179 | + if (in_array($unit_id, $group_missile = sn_get_groups('missile'))) { |
|
| 180 | 180 | // TODO Поле 'container' - указывает на родительску структуру, в которой хранится данный юнит и по вместительности которой нужно применять размер юнита |
| 181 | 181 | $used_silo = 0; |
| 182 | - foreach($group_missile as $missile_id) { |
|
| 182 | + foreach ($group_missile as $missile_id) { |
|
| 183 | 183 | $missile_qued = isset($in_que[$missile_id]) ? $in_que[$missile_id] : 0; |
| 184 | 184 | $used_silo += (mrc_get_level($user, $planet, $missile_id, true, true) + $missile_qued) * get_unit_param($missile_id, P_UNIT_SIZE); |
| 185 | 185 | } |
| 186 | 186 | $free_silo = mrc_get_level($user, $planet, STRUC_SILO) * get_unit_param(STRUC_SILO, P_CAPACITY) - $used_silo; |
| 187 | - if($free_silo <= 0) { |
|
| 187 | + if ($free_silo <= 0) { |
|
| 188 | 188 | throw new exception('{Ракетная шахта уже заполнена или будет заполнена по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION |
| 189 | 189 | } |
| 190 | 190 | $unit_size = get_unit_param($unit_id, P_UNIT_SIZE); |
| 191 | - if($free_silo < $unit_size) { |
|
| 191 | + if ($free_silo < $unit_size) { |
|
| 192 | 192 | throw new exception("{В ракетной шахте нет места для {$lang['tech'][$unit_id]}}", ERR_ERROR); // TODO EXCEPTION |
| 193 | 193 | } |
| 194 | 194 | $unit_amount = max(0, min($unit_amount, floor($free_silo / $unit_size))); |
@@ -196,10 +196,10 @@ discard block |
||
| 196 | 196 | $unit_level = $new_unit_level = 0; |
| 197 | 197 | } else { |
| 198 | 198 | $unit_amount = 1; |
| 199 | - if($que_id == QUE_STRUCTURES) { |
|
| 199 | + if ($que_id == QUE_STRUCTURES) { |
|
| 200 | 200 | // if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $que['sectors'][$planet['id']] <= 0) |
| 201 | 201 | $sectors_qued = is_array($in_que) ? array_sum($in_que) : 0; |
| 202 | - if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) |
|
| 202 | + if ($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) |
|
| 203 | 203 | { |
| 204 | 204 | throw new exception('{Не хватает секторов на планете}', ERR_ERROR); // TODO EXCEPTION |
| 205 | 205 | } |
@@ -217,9 +217,9 @@ discard block |
||
| 217 | 217 | |
| 218 | 218 | $exchange = array(); |
| 219 | 219 | $market_get_autoconvert_cost = market_get_autoconvert_cost(); |
| 220 | - if($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) { |
|
| 220 | + if ($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) { |
|
| 221 | 221 | $dark_matter = mrc_get_level($user, null, RES_DARK_MATTER); |
| 222 | - if(mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) { |
|
| 222 | + if (mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) { |
|
| 223 | 223 | throw new exception("{Нет хватает " . ($market_get_autoconvert_cost - $dark_matter) . "ТМ на постройки с автоконвертацией ресурсов}", ERR_ERROR); // TODO EXCEPTION |
| 224 | 224 | } |
| 225 | 225 | |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | $resource_exchange_rates = array(); |
| 230 | 230 | $resource_diff = array(); |
| 231 | 231 | $all_positive = true; |
| 232 | - foreach($resources_loot as $resource_id) { |
|
| 232 | + foreach ($resources_loot as $resource_id) { |
|
| 233 | 233 | $resource_db_name = pname_resource_name($resource_id); |
| 234 | 234 | $resource_got[$resource_id] = floor(mrc_get_level($user, $planet, $resource_id)); |
| 235 | 235 | $resource_exchange_rates[$resource_id] = $config->__get("rpg_exchange_{$resource_db_name}"); |
@@ -237,15 +237,15 @@ discard block |
||
| 237 | 237 | $all_positive = $all_positive && ($resource_diff[$resource_id] > 0); |
| 238 | 238 | } |
| 239 | 239 | // Нужна автоконвертация |
| 240 | - if($all_positive) { |
|
| 240 | + if ($all_positive) { |
|
| 241 | 241 | $is_autoconvert = false; |
| 242 | 242 | } else { |
| 243 | - foreach($resource_diff as $resource_diff_id => &$resource_diff_amount) { |
|
| 244 | - if($resource_diff_amount >= 0) { |
|
| 243 | + foreach ($resource_diff as $resource_diff_id => &$resource_diff_amount) { |
|
| 244 | + if ($resource_diff_amount >= 0) { |
|
| 245 | 245 | continue; |
| 246 | 246 | } |
| 247 | - foreach($resource_diff as $resource_got_id => &$resource_got_amount) { |
|
| 248 | - if($resource_got_amount <= 0) { |
|
| 247 | + foreach ($resource_diff as $resource_got_id => &$resource_got_amount) { |
|
| 248 | + if ($resource_got_amount <= 0) { |
|
| 249 | 249 | continue; |
| 250 | 250 | } |
| 251 | 251 | $current_exchange = $resource_exchange_rates[$resource_got_id] / $resource_exchange_rates[$resource_diff_id]; |
@@ -261,14 +261,14 @@ discard block |
||
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | $is_autoconvert_ok = true; |
| 264 | - foreach($resource_diff as $resource_diff_amount2) { |
|
| 265 | - if($resource_diff_amount2 < 0) { |
|
| 264 | + foreach ($resource_diff as $resource_diff_amount2) { |
|
| 265 | + if ($resource_diff_amount2 < 0) { |
|
| 266 | 266 | $is_autoconvert_ok = false; |
| 267 | 267 | break; |
| 268 | 268 | } |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - if($is_autoconvert_ok) { |
|
| 271 | + if ($is_autoconvert_ok) { |
|
| 272 | 272 | $build_data['RESULT'][$build_mode] = BUILD_ALLOWED; |
| 273 | 273 | $build_data['CAN'][$build_mode] = $unit_amount; |
| 274 | 274 | } else { |
@@ -277,19 +277,19 @@ discard block |
||
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | 279 | $unit_amount = min($build_data['CAN'][$build_mode], $unit_amount); |
| 280 | - if($unit_amount <= 0) { |
|
| 280 | + if ($unit_amount <= 0) { |
|
| 281 | 281 | throw new exception('{Не хватает ресурсов}', ERR_ERROR); // TODO EXCEPTION |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - if($new_unit_level < 0) { |
|
| 284 | + if ($new_unit_level < 0) { |
|
| 285 | 285 | throw new exception('{Нельзя уничтожить больше юнитов, чем есть}', ERR_ERROR); // TODO EXCEPTION |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - if($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) { |
|
| 288 | + if ($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) { |
|
| 289 | 289 | throw new exception('{Строительство блокировано}', ERR_ERROR); // TODO EXCEPTION |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - if($is_autoconvert) { |
|
| 292 | + if ($is_autoconvert) { |
|
| 293 | 293 | ksort($exchange); |
| 294 | 294 | ksort($resource_got); |
| 295 | 295 | db_change_units($user, $planet, array( |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | $unit_amount_qued = 0; |
| 307 | - while($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) { |
|
| 307 | + while ($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) { |
|
| 308 | 308 | $place = min($unit_amount, MAX_FLEET_OR_DEFS_PER_ROW); |
| 309 | 309 | que_add_unit($unit_id, $user, $planet, $build_data, $new_unit_level, $place, $build_mode); |
| 310 | 310 | $unit_amount -= $place; |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | |
| 315 | 315 | sn_db_transaction_commit(); |
| 316 | 316 | |
| 317 | - if($redirect) { |
|
| 317 | + if ($redirect) { |
|
| 318 | 318 | sys_redirect("{$_SERVER['PHP_SELF']}?mode=" . sys_get_param_str('mode') . "&ally_id=" . sys_get_param_id('ally_id')); |
| 319 | 319 | die(); |
| 320 | 320 | } |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | 'STATUS' => ERR_NONE, |
| 324 | 324 | 'MESSAGE' => '{Строительство начато}', |
| 325 | 325 | ); |
| 326 | - } catch(exception $e) { |
|
| 326 | + } catch (exception $e) { |
|
| 327 | 327 | sn_db_transaction_rollback(); |
| 328 | 328 | $operation_result = array( |
| 329 | 329 | 'STATUS' => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR, |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | ); |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - if(!empty($operation_result['MESSAGE'])) { |
|
| 334 | + if (!empty($operation_result['MESSAGE'])) { |
|
| 335 | 335 | $operation_result['MESSAGE'] .= ' ' . ($unit_amount_qued ? $unit_amount_qued : $unit_amount) . 'x[' . $lang['tech'][$unit_id] . ']'; |
| 336 | 336 | } |
| 337 | 337 | |
@@ -345,11 +345,11 @@ discard block |
||
| 345 | 345 | function que_recalculate($old_que) { |
| 346 | 346 | $new_que = array(); |
| 347 | 347 | |
| 348 | - if(!is_array($old_que['items'])) { |
|
| 348 | + if (!is_array($old_que['items'])) { |
|
| 349 | 349 | return $new_que; |
| 350 | 350 | } |
| 351 | - foreach($old_que['items'] as $row) { |
|
| 352 | - if(!isset($row) || !$row || $row['que_unit_amount'] <= 0) { |
|
| 351 | + foreach ($old_que['items'] as $row) { |
|
| 352 | + if (!isset($row) || !$row || $row['que_unit_amount'] <= 0) { |
|
| 353 | 353 | continue; |
| 354 | 354 | } |
| 355 | 355 | |
@@ -360,9 +360,9 @@ discard block |
||
| 360 | 360 | |
| 361 | 361 | $last_id = count($new_que['items']) - 1; |
| 362 | 362 | |
| 363 | - if($row['que_planet_id']) { |
|
| 363 | + if ($row['que_planet_id']) { |
|
| 364 | 364 | $new_que['planets'][$row['que_planet_id']][$row['que_type']][] = &$new_que['items'][$last_id]; |
| 365 | - } elseif($row['que_type'] == QUE_RESEARCH) { |
|
| 365 | + } elseif ($row['que_type'] == QUE_RESEARCH) { |
|
| 366 | 366 | $new_que['players'][$row['que_player_id']][$row['que_type']][] = &$new_que['items'][$last_id]; |
| 367 | 367 | } |
| 368 | 368 | $new_que['ques'][$row['que_type']][$row['que_player_id']][intval($row['que_planet_id'])][] = &$new_que['items'][$last_id]; |
@@ -397,9 +397,9 @@ discard block |
||
| 397 | 397 | $que_type = que_get_unit_que($unit_id); |
| 398 | 398 | $planet_id_origin = $planet['id'] ? $planet['id'] : 'NULL'; |
| 399 | 399 | $planet_id = $que_type == QUE_RESEARCH ? 'NULL' : $planet_id_origin; |
| 400 | - if(is_numeric($planet_id)) { |
|
| 400 | + if (is_numeric($planet_id)) { |
|
| 401 | 401 | DBStaticPlanet::db_planet_set_by_id($planet_id, "`que_processed` = UNIX_TIMESTAMP(NOW())"); |
| 402 | - } elseif(is_numeric($user['id'])) { |
|
| 402 | + } elseif (is_numeric($user['id'])) { |
|
| 403 | 403 | db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())'); |
| 404 | 404 | } |
| 405 | 405 | |
@@ -429,17 +429,17 @@ discard block |
||
| 429 | 429 | $planet['id'] = $planet['id'] && $que_type !== QUE_RESEARCH ? $planet['id'] : 0; |
| 430 | 430 | $global_que = que_get($user['id'], $planet['id'], $que_type, true); |
| 431 | 431 | |
| 432 | - if(!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) { |
|
| 432 | + if (!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) { |
|
| 433 | 433 | $que = array_reverse($global_que['ques'][$que_type][$user['id']][$planet['id']]); |
| 434 | 434 | |
| 435 | - foreach($que as $que_item) { |
|
| 435 | + foreach ($que as $que_item) { |
|
| 436 | 436 | DBStaticQue::db_que_delete_by_id($que_item['que_id']); |
| 437 | 437 | |
| 438 | - if($que_item['que_planet_id_origin']) { |
|
| 438 | + if ($que_item['que_planet_id_origin']) { |
|
| 439 | 439 | $planet['id'] = $que_item['que_planet_id_origin']; |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | - if(!isset($planets_locked[$planet['id']])) { |
|
| 442 | + if (!isset($planets_locked[$planet['id']])) { |
|
| 443 | 443 | $planets_locked[$planet['id']] = $planet['id'] ? DBStaticPlanet::db_planet_by_id($planet['id'], true) : $planet; |
| 444 | 444 | } |
| 445 | 445 | |
@@ -451,15 +451,15 @@ discard block |
||
| 451 | 451 | RES_DEUTERIUM => $build_data[RES_DEUTERIUM] * $que_item['que_unit_amount'], |
| 452 | 452 | )); |
| 453 | 453 | |
| 454 | - if(!$clear) { |
|
| 454 | + if (!$clear) { |
|
| 455 | 455 | break; |
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | - if(is_numeric($planet['id'])) { |
|
| 459 | + if (is_numeric($planet['id'])) { |
|
| 460 | 460 | DBStaticPlanet::db_planet_set_by_id($planet['id'], "`que_processed` = UNIX_TIMESTAMP(NOW())"); |
| 461 | 461 | } |
| 462 | - elseif(is_numeric($user['id'])) { |
|
| 462 | + elseif (is_numeric($user['id'])) { |
|
| 463 | 463 | db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())'); |
| 464 | 464 | } |
| 465 | 465 | |
@@ -504,21 +504,21 @@ discard block |
||
| 504 | 504 | // TODO: Переделать для $que_type === false |
| 505 | 505 | $planet['id'] = $planet['id'] ? $planet['id'] : 0; |
| 506 | 506 | |
| 507 | - if(!is_array($que)) { |
|
| 507 | + if (!is_array($que)) { |
|
| 508 | 508 | $que = que_get($user['id'], $planet['id'], $que_type); |
| 509 | 509 | } |
| 510 | 510 | |
| 511 | - if(is_array($que) && isset($que['items'])) { |
|
| 511 | + if (is_array($que) && isset($que['items'])) { |
|
| 512 | 512 | $que = $que['ques'][$que_type][$user['id']][$planet['id']]; |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | - if($que) { |
|
| 516 | - foreach($que as $que_element) { |
|
| 515 | + if ($que) { |
|
| 516 | + foreach ($que as $que_element) { |
|
| 517 | 517 | $template->assign_block_vars('que', que_tpl_parse_element($que_element, $short_names)); |
| 518 | 518 | } |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | - if($que_type == QUE_RESEARCH) { |
|
| 521 | + if ($que_type == QUE_RESEARCH) { |
|
| 522 | 522 | // TODO Исправить |
| 523 | 523 | // $template->assign_var('RESEARCH_ONGOING', count($global_que[QUE_RESEARCH][0]) >= $config->server_que_length_research); |
| 524 | 524 | } |
@@ -546,7 +546,7 @@ discard block |
||
| 546 | 546 | $user = db_user_by_id($user['id'], true); |
| 547 | 547 | |
| 548 | 548 | $time_left[$user['id']][0] = max(0, $on_time - $user['que_processed']); |
| 549 | - if($planet === null && !$time_left[$user['id']][0]) { |
|
| 549 | + if ($planet === null && !$time_left[$user['id']][0]) { |
|
| 550 | 550 | // TODO |
| 551 | 551 | return $que; |
| 552 | 552 | } |
@@ -555,12 +555,12 @@ discard block |
||
| 555 | 555 | $que_type_id = $planet === null ? QUE_RESEARCH : false; |
| 556 | 556 | $planet = intval(is_array($planet) ? $planet['id'] : $planet); // В $planet у нас теперь только её ID или шаблон null/0/false |
| 557 | 557 | $que = que_get($user['id'], $planet, $que_type_id, true); |
| 558 | - if(empty($que['items'])) { |
|
| 558 | + if (empty($que['items'])) { |
|
| 559 | 559 | return $que; |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | $planet_list = array(); |
| 563 | - if($planet !== null) { |
|
| 563 | + if ($planet !== null) { |
|
| 564 | 564 | // Если нужно изменять данные на планетах - блокируем планеты и получаем данные о них |
| 565 | 565 | // TODO - от них не надо ничего, кроме ID и que_processed |
| 566 | 566 | $planet_row = DBStaticPlanet::db_planet_list_by_user_or_planet($user['id'], $planet); |
@@ -569,21 +569,21 @@ discard block |
||
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | // Теперь в $time_left лежит время обсчета всех очередей по каждой из планеты |
| 572 | - if(array_sum($time_left[$user['id']]) == 0) { |
|
| 572 | + if (array_sum($time_left[$user['id']]) == 0) { |
|
| 573 | 573 | return $que; |
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | $db_changeset = array(); |
| 577 | 577 | $unit_changes = array(); |
| 578 | - foreach($que['items'] as &$que_item) { |
|
| 578 | + foreach ($que['items'] as &$que_item) { |
|
| 579 | 579 | $que_player_id = &$que_item['que_player_id']; |
| 580 | 580 | $que_planet_id = intval($que_item['que_planet_id']); |
| 581 | 581 | |
| 582 | 582 | $que_time_left = &$que['time_left'][$que_player_id][$que_planet_id][$que_item['que_type']]; |
| 583 | - if(!isset($que_time_left)) { |
|
| 583 | + if (!isset($que_time_left)) { |
|
| 584 | 584 | $que_time_left = $time_left[$que_player_id][$que_planet_id]; |
| 585 | 585 | } |
| 586 | - if($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) { |
|
| 586 | + if ($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) { |
|
| 587 | 587 | continue; |
| 588 | 588 | } |
| 589 | 589 | // Дальше мы идем, если только осталось время в очереди И юниты к постройке |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | // Теперь работаем с остатком времени на юните. Оно не может быть равно или меньше нуля |
| 597 | 597 | |
| 598 | 598 | // Если времени в очереди осталось не меньше, чем время текущего юнита - значит мы достроили юнит |
| 599 | - if($que_time_left >= $que_item['que_time_left']) { |
|
| 599 | + if ($que_time_left >= $que_item['que_time_left']) { |
|
| 600 | 600 | // Увеличиваем количество отстроенных юнитов |
| 601 | 601 | $unit_processed++; |
| 602 | 602 | // Вычитаем из времени очереди потраченное на постройку время |
@@ -609,12 +609,12 @@ discard block |
||
| 609 | 609 | $que_item['que_unit_amount'] -= $unit_processed; |
| 610 | 610 | |
| 611 | 611 | // Если еще остались юниты - значит ВСЁ оставшееся время приходится на достройку следующего юнита |
| 612 | - if($que_item['que_unit_amount'] > 0) { |
|
| 612 | + if ($que_item['que_unit_amount'] > 0) { |
|
| 613 | 613 | $que_item['que_time_left'] = $que_item['que_time_left'] - $que_time_left; |
| 614 | 614 | $que_time_left = 0; |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | - if($que_item['que_unit_amount'] <= 0) { |
|
| 617 | + if ($que_item['que_unit_amount'] <= 0) { |
|
| 618 | 618 | $db_changeset['que'][] = array( |
| 619 | 619 | 'action' => SQL_OP_DELETE, |
| 620 | 620 | P_VERSION => 1, |
@@ -640,14 +640,14 @@ discard block |
||
| 640 | 640 | ); |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | - if($unit_processed) { |
|
| 643 | + if ($unit_processed) { |
|
| 644 | 644 | $unit_processed_delta = $unit_processed * ($que_item['que_unit_mode'] == BUILD_CREATE ? 1 : -1); |
| 645 | 645 | $unit_changes[$que_player_id][$que_planet_id][$que_item['que_unit_id']] += $unit_processed_delta; |
| 646 | 646 | } |
| 647 | 647 | } |
| 648 | 648 | |
| 649 | - foreach($time_left as $player_id => $planet_data) { |
|
| 650 | - foreach($planet_data as $planet_id => $time_on_planet) { |
|
| 649 | + foreach ($time_left as $player_id => $planet_data) { |
|
| 650 | + foreach ($planet_data as $planet_id => $time_on_planet) { |
|
| 651 | 651 | $table = $planet_id ? 'planets' : 'users'; |
| 652 | 652 | $id = $planet_id ? $planet_id : $player_id; |
| 653 | 653 | $db_changeset[$table][] = array( |
@@ -663,8 +663,8 @@ discard block |
||
| 663 | 663 | ), |
| 664 | 664 | ); |
| 665 | 665 | |
| 666 | - if(is_array($unit_changes[$player_id][$planet_id])) { |
|
| 667 | - foreach($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) { |
|
| 666 | + if (is_array($unit_changes[$player_id][$planet_id])) { |
|
| 667 | + foreach ($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) { |
|
| 668 | 668 | $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, $unit_amount, $user, $planet_id ? $planet_id : null); |
| 669 | 669 | } |
| 670 | 670 | } |
@@ -674,33 +674,33 @@ discard block |
||
| 674 | 674 | $que = que_recalculate($que); |
| 675 | 675 | |
| 676 | 676 | // TODO: Re-enable quests for Alliances |
| 677 | - if(!empty($unit_changes) && !$user['user_as_ally']) { |
|
| 677 | + if (!empty($unit_changes) && !$user['user_as_ally']) { |
|
| 678 | 678 | $quest_list = qst_get_quests($user['id']); |
| 679 | 679 | $quest_triggers = qst_active_triggers($quest_list); |
| 680 | 680 | $quest_rewards = array(); |
| 681 | 681 | |
| 682 | 682 | |
| 683 | 683 | $xp_incoming = array(); |
| 684 | - foreach($unit_changes as $user_id => $planet_changes) { |
|
| 685 | - foreach($planet_changes as $planet_id => $changes) { |
|
| 684 | + foreach ($unit_changes as $user_id => $planet_changes) { |
|
| 685 | + foreach ($planet_changes as $planet_id => $changes) { |
|
| 686 | 686 | $planet_this = $planet_id ? classSupernova::db_get_record_by_id(LOC_PLANET, $planet_id) : array(); |
| 687 | - foreach($changes as $unit_id => $unit_value) { |
|
| 687 | + foreach ($changes as $unit_id => $unit_value) { |
|
| 688 | 688 | $que_id = que_get_unit_que($unit_id); |
| 689 | 689 | $unit_level_new = mrc_get_level($user, $planet_this, $unit_id, false, true) + $unit_value; |
| 690 | - if($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) { |
|
| 690 | + if ($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) { |
|
| 691 | 691 | $build_data = eco_get_build_data($user, $planet_this, $unit_id, $unit_level_new - 1); |
| 692 | 692 | $build_data = $build_data[BUILD_CREATE]; |
| 693 | - foreach(sn_get_groups('resources_loot') as $resource_id) { |
|
| 693 | + foreach (sn_get_groups('resources_loot') as $resource_id) { |
|
| 694 | 694 | $xp_incoming[$que_id] += $build_data[$resource_id]; // TODO - добавить конверсию рейтов обмена |
| 695 | 695 | } |
| 696 | 696 | } |
| 697 | 697 | |
| 698 | - if(is_array($quest_triggers)) { |
|
| 698 | + if (is_array($quest_triggers)) { |
|
| 699 | 699 | // TODO: Check mutiply condition quests |
| 700 | 700 | $quest_trigger_list = array_keys($quest_triggers, $unit_id); |
| 701 | - if(is_array($quest_trigger_list)) { |
|
| 702 | - foreach($quest_trigger_list as $quest_id) { |
|
| 703 | - if($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $unit_level_new) { |
|
| 701 | + if (is_array($quest_trigger_list)) { |
|
| 702 | + foreach ($quest_trigger_list as $quest_id) { |
|
| 703 | + if ($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $unit_level_new) { |
|
| 704 | 704 | $quest_rewards[$quest_id][$user_id][$planet_id] = $quest_list[$quest_id]['quest_rewards_list']; |
| 705 | 705 | $quest_list[$quest_id]['quest_status_status'] = QUEST_STATUS_COMPLETE; |
| 706 | 706 | } |
@@ -713,7 +713,7 @@ discard block |
||
| 713 | 713 | // TODO: Изменить начисление награды за квесты на ту планету, на которой происходил ресеч |
| 714 | 714 | qst_reward($user, $quest_rewards, $quest_list); |
| 715 | 715 | |
| 716 | - foreach($xp_incoming as $que_id => $xp) { |
|
| 716 | + foreach ($xp_incoming as $que_id => $xp) { |
|
| 717 | 717 | rpg_level_up($user, $que_id == QUE_RESEARCH ? RPG_TECH : RPG_STRUCTURE, $xp / 1000); |
| 718 | 718 | } |
| 719 | 719 | } |
@@ -458,8 +458,7 @@ |
||
| 458 | 458 | |
| 459 | 459 | if(is_numeric($planet['id'])) { |
| 460 | 460 | DBStaticPlanet::db_planet_set_by_id($planet['id'], "`que_processed` = UNIX_TIMESTAMP(NOW())"); |
| 461 | - } |
|
| 462 | - elseif(is_numeric($user['id'])) { |
|
| 461 | + } elseif(is_numeric($user['id'])) { |
|
| 463 | 462 | db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())'); |
| 464 | 463 | } |
| 465 | 464 | |
@@ -135,6 +135,10 @@ |
||
| 135 | 135 | return $fleet_events; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | +/** |
|
| 139 | + * @param integer $ov_label |
|
| 140 | + * @param integer $planet_end_type |
|
| 141 | + */ |
|
| 138 | 142 | function flt_register_fleet_event($fleet, $ov_label, $planet_end_type) |
| 139 | 143 | { |
| 140 | 144 | global $user, $planetrow, $fleet_number; |
@@ -8,23 +8,23 @@ discard block |
||
| 8 | 8 | $fleet_events = array(); |
| 9 | 9 | $fleet_number = 0; |
| 10 | 10 | |
| 11 | - if(empty($fleet_list)) |
|
| 11 | + if (empty($fleet_list)) |
|
| 12 | 12 | { |
| 13 | 13 | return; |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | - foreach($fleet_list as $fleet) |
|
| 16 | + foreach ($fleet_list as $fleet) |
|
| 17 | 17 | { |
| 18 | 18 | $planet_start_type = $fleet['fleet_start_type'] == PT_MOON ? PT_MOON : PT_PLANET; |
| 19 | 19 | $planet_start = DBStaticPlanet::db_planet_by_gspt($fleet['fleet_start_galaxy'], $fleet['fleet_start_system'], $fleet['fleet_start_planet'], $planet_start_type, false, 'name'); |
| 20 | 20 | $fleet['fleet_start_name'] = $planet_start['name']; |
| 21 | 21 | |
| 22 | 22 | $planet_end_type = $fleet['fleet_end_type'] == PT_MOON ? PT_MOON : PT_PLANET; |
| 23 | - if($fleet['fleet_end_planet'] > $config->game_maxPlanet) |
|
| 23 | + if ($fleet['fleet_end_planet'] > $config->game_maxPlanet) |
|
| 24 | 24 | { |
| 25 | 25 | $fleet['fleet_end_name'] = $lang['ov_fleet_exploration']; |
| 26 | 26 | } |
| 27 | - elseif($fleet['fleet_mission'] == MT_COLONIZE) |
|
| 27 | + elseif ($fleet['fleet_mission'] == MT_COLONIZE) |
|
| 28 | 28 | { |
| 29 | 29 | $fleet['fleet_end_name'] = $lang['ov_fleet_colonization']; |
| 30 | 30 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | $fleet['fleet_end_name'] = $planet_end['name']; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - if($fleet['fleet_start_time'] > SN_TIME_NOW && $fleet['fleet_mess'] == 0 && $fleet['fleet_mission'] != MT_MISSILE && |
|
| 37 | + if ($fleet['fleet_start_time'] > SN_TIME_NOW && $fleet['fleet_mess'] == 0 && $fleet['fleet_mission'] != MT_MISSILE && |
|
| 38 | 38 | ($planet_scanned === false |
| 39 | 39 | || |
| 40 | 40 | ( |
@@ -49,12 +49,12 @@ discard block |
||
| 49 | 49 | $fleet_events[] = flt_register_fleet_event($fleet, 0, $planet_end_type); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - if($fleet['fleet_end_stay'] > SN_TIME_NOW && $fleet['fleet_mess'] == 0 && $planet_scanned === false && $fleet['fleet_mission'] != MT_MISSILE) |
|
| 52 | + if ($fleet['fleet_end_stay'] > SN_TIME_NOW && $fleet['fleet_mess'] == 0 && $planet_scanned === false && $fleet['fleet_mission'] != MT_MISSILE) |
|
| 53 | 53 | { |
| 54 | 54 | $fleet_events[] = flt_register_fleet_event($fleet, 1, $planet_end_type); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if( |
|
| 57 | + if ( |
|
| 58 | 58 | $fleet['fleet_end_time'] > SN_TIME_NOW && $fleet['fleet_mission'] != MT_MISSILE && ($fleet['fleet_mess'] == 1 || ($fleet['fleet_mission'] != MT_RELOCATE && $fleet['fleet_mission'] != MT_COLONIZE)) && |
| 59 | 59 | ( |
| 60 | 60 | ($planet_scanned === false && $fleet['fleet_owner'] == $user['id']) |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | $fleet_events[] = flt_register_fleet_event($fleet, 2, $planet_end_type); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if($fleet['fleet_mission'] == MT_MISSILE) |
|
| 74 | + if ($fleet['fleet_mission'] == MT_MISSILE) |
|
| 75 | 75 | { |
| 76 | 76 | $fleet_events[] = flt_register_fleet_event($fleet, 3, $planet_end_type); |
| 77 | 77 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | { |
| 85 | 85 | global $user, $planetrow, $fleet_number; |
| 86 | 86 | |
| 87 | - switch($fleet['ov_label'] = $ov_label) |
|
| 87 | + switch ($fleet['ov_label'] = $ov_label) |
|
| 88 | 88 | { |
| 89 | 89 | case 0: |
| 90 | 90 | $fleet['event_time'] = $fleet['fleet_start_time']; |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - $fleet['ov_this_planet'] = $is_this_planet;// || $planet_scanned != false; |
|
| 119 | + $fleet['ov_this_planet'] = $is_this_planet; // || $planet_scanned != false; |
|
| 120 | 120 | |
| 121 | - if($fleet['fleet_owner'] == $user['id']) |
|
| 121 | + if ($fleet['fleet_owner'] == $user['id']) |
|
| 122 | 122 | { |
| 123 | 123 | $user_data = $user; |
| 124 | 124 | } |
@@ -1,8 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -function flt_parse_fleets_to_events($fleet_list, $planet_scanned = false) |
|
| 5 | -{ |
|
| 4 | +function flt_parse_fleets_to_events($fleet_list, $planet_scanned = false) { |
|
| 6 | 5 | global $config, $user, $fleet_number, $lang; |
| 7 | 6 | |
| 8 | 7 | $fleet_events = array(); |
@@ -23,12 +22,10 @@ discard block |
||
| 23 | 22 | if($fleet['fleet_end_planet'] > $config->game_maxPlanet) |
| 24 | 23 | { |
| 25 | 24 | $fleet['fleet_end_name'] = $lang['ov_fleet_exploration']; |
| 26 | - } |
|
| 27 | - elseif($fleet['fleet_mission'] == MT_COLONIZE) |
|
| 25 | + } elseif($fleet['fleet_mission'] == MT_COLONIZE) |
|
| 28 | 26 | { |
| 29 | 27 | $fleet['fleet_end_name'] = $lang['ov_fleet_colonization']; |
| 30 | - } |
|
| 31 | - else |
|
| 28 | + } else |
|
| 32 | 29 | { |
| 33 | 30 | $planet_end = DBStaticPlanet::db_planet_by_gspt($fleet['fleet_end_galaxy'], $fleet['fleet_end_system'], $fleet['fleet_end_planet'], $planet_end_type, false, 'name'); |
| 34 | 31 | $fleet['fleet_end_name'] = $planet_end['name']; |
@@ -80,8 +77,7 @@ discard block |
||
| 80 | 77 | return $fleet_events; |
| 81 | 78 | } |
| 82 | 79 | |
| 83 | -function flt_register_fleet_event($fleet, $ov_label, $planet_end_type) |
|
| 84 | -{ |
|
| 80 | +function flt_register_fleet_event($fleet, $ov_label, $planet_end_type) { |
|
| 85 | 81 | global $user, $planetrow, $fleet_number; |
| 86 | 82 | |
| 87 | 83 | switch($fleet['ov_label'] = $ov_label) |
@@ -121,8 +117,7 @@ discard block |
||
| 121 | 117 | if($fleet['fleet_owner'] == $user['id']) |
| 122 | 118 | { |
| 123 | 119 | $user_data = $user; |
| 124 | - } |
|
| 125 | - else |
|
| 120 | + } else |
|
| 126 | 121 | { |
| 127 | 122 | $user_data = db_user_by_id($fleet['fleet_owner']); |
| 128 | 123 | } |
@@ -130,8 +125,7 @@ discard block |
||
| 130 | 125 | return tpl_parse_fleet_db($fleet, ++$fleet_number, $user_data); |
| 131 | 126 | } |
| 132 | 127 | |
| 133 | -function int_planet_pretemplate($planetrow, &$template) |
|
| 134 | -{ |
|
| 128 | +function int_planet_pretemplate($planetrow, &$template) { |
|
| 135 | 129 | global $lang, $user; |
| 136 | 130 | |
| 137 | 131 | $governor_id = $planetrow['PLANET_GOVERNOR_ID']; |
@@ -89,18 +89,18 @@ discard block |
||
| 89 | 89 | case 0: |
| 90 | 90 | $fleet['event_time'] = $fleet['fleet_start_time']; |
| 91 | 91 | $is_this_planet = ( |
| 92 | - ($planetrow['galaxy'] == $fleet['fleet_end_galaxy']) AND |
|
| 93 | - ($planetrow['system'] == $fleet['fleet_end_system']) AND |
|
| 94 | - ($planetrow['planet'] == $fleet['fleet_end_planet']) AND |
|
| 92 | + ($planetrow['galaxy'] == $fleet['fleet_end_galaxy']) and |
|
| 93 | + ($planetrow['system'] == $fleet['fleet_end_system']) and |
|
| 94 | + ($planetrow['planet'] == $fleet['fleet_end_planet']) and |
|
| 95 | 95 | ($planetrow['planet_type'] == $planet_end_type)); |
| 96 | 96 | break; |
| 97 | 97 | |
| 98 | 98 | case 1: |
| 99 | 99 | $fleet['event_time'] = $fleet['fleet_end_stay']; |
| 100 | 100 | $is_this_planet = ( |
| 101 | - ($planetrow['galaxy'] == $fleet['fleet_end_galaxy']) AND |
|
| 102 | - ($planetrow['system'] == $fleet['fleet_end_system']) AND |
|
| 103 | - ($planetrow['planet'] == $fleet['fleet_end_planet']) AND |
|
| 101 | + ($planetrow['galaxy'] == $fleet['fleet_end_galaxy']) and |
|
| 102 | + ($planetrow['system'] == $fleet['fleet_end_system']) and |
|
| 103 | + ($planetrow['planet'] == $fleet['fleet_end_planet']) and |
|
| 104 | 104 | ($planetrow['planet_type'] == $planet_end_type)); |
| 105 | 105 | break; |
| 106 | 106 | |
@@ -108,9 +108,9 @@ discard block |
||
| 108 | 108 | case 3: |
| 109 | 109 | $fleet['event_time'] = $fleet['fleet_end_time']; |
| 110 | 110 | $is_this_planet = ( |
| 111 | - ($planetrow['galaxy'] == $fleet['fleet_start_galaxy']) AND |
|
| 112 | - ($planetrow['system'] == $fleet['fleet_start_system']) AND |
|
| 113 | - ($planetrow['planet'] == $fleet['fleet_start_planet']) AND |
|
| 111 | + ($planetrow['galaxy'] == $fleet['fleet_start_galaxy']) and |
|
| 112 | + ($planetrow['system'] == $fleet['fleet_start_system']) and |
|
| 113 | + ($planetrow['planet'] == $fleet['fleet_start_planet']) and |
|
| 114 | 114 | ($planetrow['planet_type'] == $fleet['fleet_start_type'])); |
| 115 | 115 | break; |
| 116 | 116 | |
@@ -37,6 +37,9 @@ |
||
| 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; |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | "ally_id = '{$ally_id}'" . ($ally_rank_id >= 0 ? " AND ally_rank_id = {$ally_rank_id}" : ''), |
| 27 | 27 | false, 'id, username'); |
| 28 | 28 | // while ($u = db_fetch($query)) |
| 29 | - foreach($query as $u) |
|
| 29 | + foreach ($query as $u) |
|
| 30 | 30 | { |
| 31 | 31 | $sendList[] = $u['id']; |
| 32 | 32 | $list .= "<br>{$u['username']} "; |
@@ -41,19 +41,19 @@ discard block |
||
| 41 | 41 | { |
| 42 | 42 | global $config, $user, $sn_message_class_list; |
| 43 | 43 | |
| 44 | - if(!$owners) |
|
| 44 | + if (!$owners) |
|
| 45 | 45 | { |
| 46 | 46 | return; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | $timestamp = $timestamp ? $timestamp : SN_TIME_NOW; |
| 50 | 50 | $sender = intval($sender); |
| 51 | - if(!is_array($owners)) |
|
| 51 | + if (!is_array($owners)) |
|
| 52 | 52 | { |
| 53 | 53 | $owners = array($owners); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - if(!$escaped) |
|
| 56 | + if (!$escaped) |
|
| 57 | 57 | { |
| 58 | 58 | $from = db_escape($from); |
| 59 | 59 | $subject = db_escape($subject); |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | $message_class_name_total = $sn_message_class_list[MSG_TYPE_NEW]['name']; |
| 71 | 71 | |
| 72 | - if($owners[0] == '*') |
|
| 72 | + if ($owners[0] == '*') |
|
| 73 | 73 | { |
| 74 | - if($user['authlevel'] < 3) |
|
| 74 | + if ($user['authlevel'] < 3) |
|
| 75 | 75 | { |
| 76 | 76 | return false; |
| 77 | 77 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | foreach ($owners as $owner) |
| 89 | 89 | { |
| 90 | - if($user['id'] != $owner) |
|
| 90 | + if ($user['id'] != $owner) |
|
| 91 | 91 | { |
| 92 | 92 | $owner_row = db_user_by_id($owner); |
| 93 | 93 | } |
@@ -97,18 +97,18 @@ discard block |
||
| 97 | 97 | } |
| 98 | 98 | sys_user_options_unpack($owner_row); |
| 99 | 99 | |
| 100 | - if($force || !$message_class_switchable || $owner_row["opt_{$message_class_name}"]) |
|
| 100 | + if ($force || !$message_class_switchable || $owner_row["opt_{$message_class_name}"]) |
|
| 101 | 101 | { |
| 102 | 102 | $insert_values[] = sprintf($insert_template, $owner); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - if($message_class_email && $config->game_email_pm && $owner_row["opt_email_{$message_class_name}"]) |
|
| 105 | + if ($message_class_email && $config->game_email_pm && $owner_row["opt_email_{$message_class_name}"]) |
|
| 106 | 106 | { |
| 107 | 107 | @$result = mymail($owner_row['email'], $subject, $text_unescaped, '', true); |
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - if(empty($insert_values)) |
|
| 111 | + if (empty($insert_values)) |
|
| 112 | 112 | { |
| 113 | 113 | return; |
| 114 | 114 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | db_user_list_set_mass_mail($owners, "`{$message_class_name}` = `{$message_class_name}` + 1, `{$message_class_name_total}` = `{$message_class_name_total}` + 1"); |
| 120 | 120 | |
| 121 | - if(in_array($user['id'], $owners) || $owners[0] == '*') |
|
| 121 | + if (in_array($user['id'], $owners) || $owners[0] == '*') |
|
| 122 | 122 | { |
| 123 | 123 | $user[$message_class_name]++; |
| 124 | 124 | $user[$message_class_name_total]++; |
@@ -15,8 +15,7 @@ discard block |
||
| 15 | 15 | 1.5 - copyright (c) 2010-2011 by Gorlum for http://supernova.ws |
| 16 | 16 | [+] SuperMassMailing - authlevel=3 player can send messages to whole server ('*' as $owners) |
| 17 | 17 | */ |
| 18 | -function msg_ali_send($message, $subject, $ally_rank_id = 0, $ally_id = 0) |
|
| 19 | -{ |
|
| 18 | +function msg_ali_send($message, $subject, $ally_rank_id = 0, $ally_id = 0) { |
|
| 20 | 19 | global $user; |
| 21 | 20 | |
| 22 | 21 | $ally_id = $ally_id ? $ally_id : $user['ally_id']; |
@@ -37,8 +36,7 @@ discard block |
||
| 37 | 36 | return $list; |
| 38 | 37 | } |
| 39 | 38 | |
| 40 | -function msg_send_simple_message($owners, $sender, $timestamp, $message_type, $from, $subject, $text, $escaped = false, $force = false) |
|
| 41 | -{ |
|
| 39 | +function msg_send_simple_message($owners, $sender, $timestamp, $message_type, $from, $subject, $text, $escaped = false, $force = false) { |
|
| 42 | 40 | global $config, $user, $sn_message_class_list; |
| 43 | 41 | |
| 44 | 42 | if(!$owners) |
@@ -79,8 +77,7 @@ discard block |
||
| 79 | 77 | // TODO Добавить $sender - рассылка может быть и от кого-то |
| 80 | 78 | db_message_insert_all($message_type, $from, $subject, $text); |
| 81 | 79 | $owners = array(); |
| 82 | - } |
|
| 83 | - else |
|
| 80 | + } else |
|
| 84 | 81 | { |
| 85 | 82 | $insert_values = array(); |
| 86 | 83 | $insert_template = "('%u'," . str_replace('%', '%%', " '{$sender}', '{$timestamp}', '{$message_type}', '{$from}', '{$subject}', '{$text}')"); |
@@ -90,8 +87,7 @@ discard block |
||
| 90 | 87 | if($user['id'] != $owner) |
| 91 | 88 | { |
| 92 | 89 | $owner_row = db_user_by_id($owner); |
| 93 | - } |
|
| 94 | - else |
|
| 90 | + } else |
|
| 95 | 91 | { |
| 96 | 92 | $owner_row = $user; |
| 97 | 93 | } |
@@ -161,6 +161,9 @@ discard block |
||
| 161 | 161 | return $rows_affected; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | +/** |
|
| 165 | + * @param integer $type |
|
| 166 | + */ |
|
| 164 | 167 | function rpg_level_up(&$user, $type, $xp_to_add = 0) |
| 165 | 168 | { |
| 166 | 169 | $q = 1.03; |
@@ -223,6 +226,10 @@ discard block |
||
| 223 | 226 | } |
| 224 | 227 | } |
| 225 | 228 | |
| 229 | +/** |
|
| 230 | + * @param integer $b1 |
|
| 231 | + * @param double $q |
|
| 232 | + */ |
|
| 226 | 233 | function rpg_xp_for_level($level, $b1, $q) |
| 227 | 234 | { |
| 228 | 235 | return floor($b1 * (pow($q, $level) - 1)/($q - 1)); |
@@ -233,6 +240,9 @@ discard block |
||
| 233 | 240 | return rpg_xp_for_level($level, 50, 1.03); |
| 234 | 241 | } |
| 235 | 242 | |
| 243 | +/** |
|
| 244 | + * @param integer $level |
|
| 245 | + */ |
|
| 236 | 246 | function RPG_get_raider_xp($level) |
| 237 | 247 | { |
| 238 | 248 | return rpg_xp_for_level($level, 10, 1.03); |
@@ -85,28 +85,28 @@ discard block |
||
| 85 | 85 | function rpg_points_change($user_id, $change_type, $dark_matter, $comment = false, $already_changed = false) { |
| 86 | 86 | global $debug, $config, $dm_change_legit, $user; |
| 87 | 87 | |
| 88 | - if(!$user_id) { |
|
| 88 | + if (!$user_id) { |
|
| 89 | 89 | return false; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | $dm_change_legit = true; |
| 93 | 93 | $sn_data_dark_matter_db_name = pname_resource_name(RES_DARK_MATTER); |
| 94 | 94 | |
| 95 | - if($already_changed) { |
|
| 95 | + if ($already_changed) { |
|
| 96 | 96 | $rows_affected = 1; |
| 97 | 97 | } else { |
| 98 | 98 | $changeset = array(); |
| 99 | 99 | $a_user = db_user_by_id($user_id, true); |
| 100 | - if($dark_matter < 0) { |
|
| 100 | + if ($dark_matter < 0) { |
|
| 101 | 101 | $dark_matter_exists = mrc_get_level($a_user, null, RES_DARK_MATTER, false, true); |
| 102 | 102 | $dark_matter_exists < 0 ? $dark_matter_exists = 0 : false; |
| 103 | 103 | $metamatter_to_reduce = -$dark_matter - $dark_matter_exists; |
| 104 | - if($metamatter_to_reduce > 0) { |
|
| 104 | + if ($metamatter_to_reduce > 0) { |
|
| 105 | 105 | $metamatter_exists = mrc_get_level($a_user, null, RES_METAMATTER); |
| 106 | - if($metamatter_exists < $metamatter_to_reduce) { |
|
| 106 | + if ($metamatter_exists < $metamatter_to_reduce) { |
|
| 107 | 107 | $debug->error('Ошибка снятия ТМ - ММ+ТМ меньше, чем сумма для снятия!', 'Ошибка снятия ТМ', LOG_ERR_INT_NOT_ENOUGH_DARK_MATTER); |
| 108 | 108 | } |
| 109 | - if(is_array($comment)) { |
|
| 109 | + if (is_array($comment)) { |
|
| 110 | 110 | $comment = call_user_func_array('sprintf', $comment); |
| 111 | 111 | } |
| 112 | 112 | // mm_points_change($user_id, $change_type, -$metamatter_to_reduce, 'ММ в ТМ: ' . (-$dark_matter) . ' ТМ = ' . $dark_matter_exists . ' ТМ + ' . $metamatter_to_reduce . ' ММ. ' . $comment); |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | $rows_affected = classSupernova::$db->db_affected_rows(); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - if($rows_affected || !$dark_matter) { |
|
| 124 | + if ($rows_affected || !$dark_matter) { |
|
| 125 | 125 | $page_url = db_escape($_SERVER['SCRIPT_NAME']); |
| 126 | - if(is_array($comment)) { |
|
| 126 | + if (is_array($comment)) { |
|
| 127 | 127 | $comment = call_user_func_array('sprintf', $comment); |
| 128 | 128 | } |
| 129 | 129 | $comment = db_escape($comment); |
@@ -137,18 +137,18 @@ discard block |
||
| 137 | 137 | {$dark_matter}, '{$comment}', '{$page_url}', {$user_id} |
| 138 | 138 | );"); |
| 139 | 139 | |
| 140 | - if($user['id'] == $user_id) { |
|
| 140 | + if ($user['id'] == $user_id) { |
|
| 141 | 141 | $user['dark_matter'] += $dark_matter; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if($dark_matter > 0) { |
|
| 144 | + if ($dark_matter > 0) { |
|
| 145 | 145 | $old_referral = doquery("SELECT * FROM {{referrals}} WHERE `id` = {$user_id} LIMIT 1 FOR UPDATE;", '', true); |
| 146 | - if($old_referral['id']) { |
|
| 146 | + if ($old_referral['id']) { |
|
| 147 | 147 | doquery("UPDATE {{referrals}} SET dark_matter = dark_matter + '{$dark_matter}' WHERE `id` = {$user_id} LIMIT 1;"); |
| 148 | 148 | $new_referral = doquery("SELECT * FROM {{referrals}} WHERE `id` = {$user_id} LIMIT 1;", '', true); |
| 149 | 149 | |
| 150 | 150 | $partner_bonus = floor($new_referral['dark_matter'] / $config->rpg_bonus_divisor) - ($old_referral['dark_matter'] >= $config->rpg_bonus_minimum ? floor($old_referral['dark_matter'] / $config->rpg_bonus_divisor) : 0); |
| 151 | - if($partner_bonus > 0 && $new_referral['dark_matter'] >= $config->rpg_bonus_minimum) { |
|
| 151 | + if ($partner_bonus > 0 && $new_referral['dark_matter'] >= $config->rpg_bonus_minimum) { |
|
| 152 | 152 | rpg_points_change($new_referral['id_partner'], RPG_REFERRAL, $partner_bonus, "Incoming From Referral ID {$user_id}"); |
| 153 | 153 | } |
| 154 | 154 | } |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | { |
| 166 | 166 | $q = 1.03; |
| 167 | 167 | |
| 168 | - switch($type) |
|
| 168 | + switch ($type) |
|
| 169 | 169 | { |
| 170 | 170 | case RPG_STRUCTURE: |
| 171 | 171 | $field_level = 'lvl_minier'; |
@@ -203,19 +203,19 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | $xp = &$user[$field_xp]; |
| 205 | 205 | |
| 206 | - if($xp_to_add) |
|
| 206 | + if ($xp_to_add) |
|
| 207 | 207 | { |
| 208 | 208 | $xp += $xp_to_add; |
| 209 | 209 | db_user_set_by_id($user['id'], "`{$field_xp}` = `{$field_xp}` + '{$xp_to_add}'"); |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | $level = $user[$field_level]; |
| 213 | - while($xp > rpg_xp_for_level($level + 1, $b1, $q)) |
|
| 213 | + while ($xp > rpg_xp_for_level($level + 1, $b1, $q)) |
|
| 214 | 214 | { |
| 215 | 215 | $level++; |
| 216 | 216 | } |
| 217 | 217 | $level -= $user[$field_level]; |
| 218 | - if($level > 0) |
|
| 218 | + if ($level > 0) |
|
| 219 | 219 | { |
| 220 | 220 | db_user_set_by_id($user['id'], "`{$field_level}` = `{$field_level}` + '{$level}'"); |
| 221 | 221 | rpg_points_change($user['id'], $type, $level * 1000, $comment); |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | |
| 226 | 226 | function rpg_xp_for_level($level, $b1, $q) |
| 227 | 227 | { |
| 228 | - return floor($b1 * (pow($q, $level) - 1)/($q - 1)); |
|
| 228 | + return floor($b1 * (pow($q, $level) - 1) / ($q - 1)); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | function rpg_get_miner_xp($level) |
@@ -161,8 +161,7 @@ discard block |
||
| 161 | 161 | return $rows_affected; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | -function rpg_level_up(&$user, $type, $xp_to_add = 0) |
|
| 165 | -{ |
|
| 164 | +function rpg_level_up(&$user, $type, $xp_to_add = 0) { |
|
| 166 | 165 | $q = 1.03; |
| 167 | 166 | |
| 168 | 167 | switch($type) |
@@ -223,27 +222,22 @@ discard block |
||
| 223 | 222 | } |
| 224 | 223 | } |
| 225 | 224 | |
| 226 | -function rpg_xp_for_level($level, $b1, $q) |
|
| 227 | -{ |
|
| 225 | +function rpg_xp_for_level($level, $b1, $q) { |
|
| 228 | 226 | return floor($b1 * (pow($q, $level) - 1)/($q - 1)); |
| 229 | 227 | } |
| 230 | 228 | |
| 231 | -function rpg_get_miner_xp($level) |
|
| 232 | -{ |
|
| 229 | +function rpg_get_miner_xp($level) { |
|
| 233 | 230 | return rpg_xp_for_level($level, 50, 1.03); |
| 234 | 231 | } |
| 235 | 232 | |
| 236 | -function RPG_get_raider_xp($level) |
|
| 237 | -{ |
|
| 233 | +function RPG_get_raider_xp($level) { |
|
| 238 | 234 | return rpg_xp_for_level($level, 10, 1.03); |
| 239 | 235 | } |
| 240 | 236 | |
| 241 | -function rpg_get_tech_xp($level) |
|
| 242 | -{ |
|
| 237 | +function rpg_get_tech_xp($level) { |
|
| 243 | 238 | return rpg_xp_for_level($level, 50, 1.03); |
| 244 | 239 | } |
| 245 | 240 | |
| 246 | -function rpg_get_explore_xp($level) |
|
| 247 | -{ |
|
| 241 | +function rpg_get_explore_xp($level) { |
|
| 248 | 242 | return rpg_xp_for_level($level, 10, 1.05); |
| 249 | 243 | } |
@@ -141,6 +141,9 @@ |
||
| 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 | |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | function sys_user_vacation($user) { |
| 10 | 10 | global $config; |
| 11 | 11 | |
| 12 | - if(sys_get_param_str('vacation') == 'leave') { |
|
| 12 | + if (sys_get_param_str('vacation') == 'leave') { |
|
| 13 | 13 | if ($user['vacation'] < SN_TIME_NOW) { |
| 14 | 14 | $user['vacation'] = 0; |
| 15 | 15 | $user['vacation_next'] = SN_TIME_NOW + $config->player_vacation_timeout; |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - if($user['vacation']) { |
|
| 20 | + if ($user['vacation']) { |
|
| 21 | 21 | // sn_sys_logout(false, true); |
| 22 | 22 | // core_auth::logout(false, true); |
| 23 | 23 | |
@@ -49,33 +49,33 @@ discard block |
||
| 49 | 49 | // TODO: Full rewrite |
| 50 | 50 | sn_db_transaction_start(); |
| 51 | 51 | $TheUser = db_user_by_id($UserID); |
| 52 | - if ( $TheUser['ally_id'] != 0 ) { |
|
| 53 | - $TheAlly = doquery ( "SELECT * FROM `{{alliance}}` WHERE `id` = '" . $TheUser['ally_id'] . "';", '', true ); |
|
| 52 | + if ($TheUser['ally_id'] != 0) { |
|
| 53 | + $TheAlly = doquery("SELECT * FROM `{{alliance}}` WHERE `id` = '" . $TheUser['ally_id'] . "';", '', true); |
|
| 54 | 54 | $TheAlly['ally_members'] -= 1; |
| 55 | - if ( $TheAlly['ally_members'] > 0 ) { |
|
| 56 | - doquery ( "UPDATE `{{alliance}}` SET `ally_members` = '" . $TheAlly['ally_members'] . "' WHERE `id` = '" . $TheAlly['id'] . "';"); |
|
| 55 | + if ($TheAlly['ally_members'] > 0) { |
|
| 56 | + doquery("UPDATE `{{alliance}}` SET `ally_members` = '" . $TheAlly['ally_members'] . "' WHERE `id` = '" . $TheAlly['id'] . "';"); |
|
| 57 | 57 | } else { |
| 58 | - doquery ( "DELETE FROM `{{alliance}}` WHERE `id` = '" . $TheAlly['id'] . "';"); |
|
| 59 | - doquery ( "DELETE FROM `{{statpoints}}` WHERE `stat_type` = '2' AND `id_owner` = '" . $TheAlly['id'] . "';"); |
|
| 58 | + doquery("DELETE FROM `{{alliance}}` WHERE `id` = '" . $TheAlly['id'] . "';"); |
|
| 59 | + doquery("DELETE FROM `{{statpoints}}` WHERE `stat_type` = '2' AND `id_owner` = '" . $TheAlly['id'] . "';"); |
|
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | - doquery ( "DELETE FROM `{{statpoints}}` WHERE `stat_type` = '1' AND `id_owner` = '" . $UserID . "';"); |
|
| 62 | + doquery("DELETE FROM `{{statpoints}}` WHERE `stat_type` = '1' AND `id_owner` = '" . $UserID . "';"); |
|
| 63 | 63 | |
| 64 | 64 | DBStaticPlanet::db_planet_list_delete_by_owner($UserID); |
| 65 | 65 | |
| 66 | - doquery ( "DELETE FROM `{{messages}}` WHERE `message_sender` = '" . $UserID . "';"); |
|
| 67 | - doquery ( "DELETE FROM `{{messages}}` WHERE `message_owner` = '" . $UserID . "';"); |
|
| 68 | - doquery ( "DELETE FROM `{{notes}}` WHERE `owner` = '" . $UserID . "';"); |
|
| 66 | + doquery("DELETE FROM `{{messages}}` WHERE `message_sender` = '" . $UserID . "';"); |
|
| 67 | + doquery("DELETE FROM `{{messages}}` WHERE `message_owner` = '" . $UserID . "';"); |
|
| 68 | + doquery("DELETE FROM `{{notes}}` WHERE `owner` = '" . $UserID . "';"); |
|
| 69 | 69 | db_fleet_list_delete_by_owner($UserID); |
| 70 | 70 | // doquery ( "DELETE FROM `{{rw}}` WHERE `id_owner1` = '" . $UserID . "';"); |
| 71 | 71 | // doquery ( "DELETE FROM `{{rw}}` WHERE `id_owner2` = '" . $UserID . "';"); |
| 72 | - doquery ( "DELETE FROM `{{buddy}}` WHERE `BUDDY_SENDER_ID` = '" . $UserID . "';"); |
|
| 73 | - doquery ( "DELETE FROM `{{buddy}}` WHERE `BUDDY_OWNER_ID` = '" . $UserID . "';"); |
|
| 74 | - doquery ( "DELETE FROM `{{annonce}}` WHERE `user` = '" . $UserID . "';"); |
|
| 72 | + doquery("DELETE FROM `{{buddy}}` WHERE `BUDDY_SENDER_ID` = '" . $UserID . "';"); |
|
| 73 | + doquery("DELETE FROM `{{buddy}}` WHERE `BUDDY_OWNER_ID` = '" . $UserID . "';"); |
|
| 74 | + doquery("DELETE FROM `{{annonce}}` WHERE `user` = '" . $UserID . "';"); |
|
| 75 | 75 | |
| 76 | 76 | |
| 77 | 77 | classSupernova::db_del_record_by_id(LOC_USER, $UserID); |
| 78 | - doquery ( "DELETE FROM `{{referrals}}` WHERE (`id` = '{$UserID}') OR (`id_partner` = '{$UserID}');"); |
|
| 78 | + doquery("DELETE FROM `{{referrals}}` WHERE (`id` = '{$UserID}') OR (`id_partner` = '{$UserID}');"); |
|
| 79 | 79 | global $config; |
| 80 | 80 | $config->db_saveItem('users_amount', $config->db_loadItem('users_amount') - 1); |
| 81 | 81 | sn_db_transaction_commit(); |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | !empty($options['password_encoded_unsafe']) ? $field_set['password'] = $options['password_encoded_unsafe'] : false; |
| 176 | 176 | |
| 177 | 177 | $user_new = classSupernova::db_ins_field_set(LOC_USER, $field_set); |
| 178 | - if(!($options['galaxy'] && $options['system'] && $options['planet'])) { |
|
| 178 | + if (!($options['galaxy'] && $options['system'] && $options['planet'])) { |
|
| 179 | 179 | $options['galaxy'] = $config->LastSettedGalaxyPos; |
| 180 | 180 | $options['system'] = $config->LastSettedSystemPos; |
| 181 | 181 | $segment_size = floor($config->game_maxPlanet / 3); |
@@ -184,19 +184,19 @@ discard block |
||
| 184 | 184 | $options['planet'] = mt_rand(1 + $segment * $segment_size, ($segment + 1) * $segment_size); |
| 185 | 185 | |
| 186 | 186 | // $new_planet_id = 0; |
| 187 | - while(true) { |
|
| 188 | - if($options['planet'] > $config->game_maxPlanet) { |
|
| 187 | + while (true) { |
|
| 188 | + if ($options['planet'] > $config->game_maxPlanet) { |
|
| 189 | 189 | $options['planet'] = mt_rand(0, $segment_size - 1) + 1; |
| 190 | 190 | $options['system']++; |
| 191 | 191 | } |
| 192 | - if($options['system'] > $config->game_maxSystem) { |
|
| 192 | + if ($options['system'] > $config->game_maxSystem) { |
|
| 193 | 193 | $options['system'] = 1; |
| 194 | 194 | $options['galaxy']++; |
| 195 | 195 | } |
| 196 | 196 | $options['galaxy'] > $config->game_maxGalaxy ? $options['galaxy'] = 1 : false; |
| 197 | 197 | |
| 198 | 198 | $galaxy_row = DBStaticPlanet::db_planet_by_gspt($options['galaxy'], $options['system'], $options['planet'], PT_PLANET, true, 'id'); |
| 199 | - if(!$galaxy_row['id']) { |
|
| 199 | + if (!$galaxy_row['id']) { |
|
| 200 | 200 | $config->db_saveItem(array( |
| 201 | 201 | 'LastSettedGalaxyPos' => $options['galaxy'], |
| 202 | 202 | 'LastSettedSystemPos' => $options['system'], |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | $username_safe = db_escape($username_unsafe); |
| 226 | 226 | doquery("REPLACE INTO {{player_name_history}} SET `player_id` = {$user_new['id']}, `player_name` = '{$username_safe}'"); |
| 227 | 227 | |
| 228 | - if(!empty($options['partner_id']) && ($referral_row = db_user_by_id($options['partner_id'], true))) { |
|
| 228 | + if (!empty($options['partner_id']) && ($referral_row = db_user_by_id($options['partner_id'], true))) { |
|
| 229 | 229 | doquery("INSERT INTO {{referrals}} SET `id` = {$user_new['id']}, `id_partner` = {$options['partner_id']}"); |
| 230 | 230 | } |
| 231 | 231 | |