@@ -118,6 +118,9 @@ |
||
| 118 | 118 | return classSupernova::$gc->cacheOperator->db_ins_record(LOC_UNIT, $set); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | + /** |
|
| 122 | + * @param integer $unit_location_type |
|
| 123 | + */ |
|
| 121 | 124 | public static function db_unit_list_delete($user_id = 0, $unit_location_type, $unit_location_id = 0, $unit_snid = 0) { |
| 122 | 125 | $where = array('unit_location_type' => $unit_location_type); |
| 123 | 126 | ($unit_location_id = idval($unit_location_id)) ? $where['unit_location_id'] = $unit_location_id : false; |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | |
| 209 | 209 | $temp = DBStaticUnit::db_get_unit_by_location($user['id'], $unit_location, $location_id, $unit_id, true, 'unit_id'); |
| 210 | 210 | if (!empty($temp['unit_id'])) { |
| 211 | - $result = (bool)classSupernova::$gc->cacheOperator->db_upd_record_by_id( |
|
| 211 | + $result = (bool) classSupernova::$gc->cacheOperator->db_upd_record_by_id( |
|
| 212 | 212 | LOC_UNIT, |
| 213 | 213 | $temp['unit_id'], |
| 214 | 214 | array(), |
@@ -219,15 +219,15 @@ discard block |
||
| 219 | 219 | } else { |
| 220 | 220 | $locationIdRendered = $unit_location == LOC_USER ? $user['id'] : $planet_id; |
| 221 | 221 | $unitType = get_unit_param($unit_id, P_UNIT_TYPE); |
| 222 | - $result = (bool)classSupernova::$gc->cacheOperator->db_ins_record( |
|
| 222 | + $result = (bool) classSupernova::$gc->cacheOperator->db_ins_record( |
|
| 223 | 223 | LOC_UNIT, |
| 224 | 224 | array( |
| 225 | 225 | 'unit_player_id' => $user['id'], |
| 226 | - 'unit_location_type' => (int)$unit_location, |
|
| 226 | + 'unit_location_type' => (int) $unit_location, |
|
| 227 | 227 | 'unit_location_id' => $locationIdRendered, |
| 228 | - 'unit_type' => (int)$unitType, |
|
| 229 | - 'unit_snid' => (int)$unit_id, |
|
| 230 | - 'unit_level' => (float)$unit_value, |
|
| 228 | + 'unit_type' => (int) $unitType, |
|
| 229 | + 'unit_snid' => (int) $unit_id, |
|
| 230 | + 'unit_level' => (float) $unit_value, |
|
| 231 | 231 | ) |
| 232 | 232 | ); |
| 233 | 233 | } |
@@ -40,6 +40,7 @@ discard block |
||
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | + * @param string $fields |
|
| 43 | 44 | * @return DbResultIterator |
| 44 | 45 | */ |
| 45 | 46 | protected static function playerSelectIterator($fields, $orderBy = '', $forUpdate = false, $groupHaving = '', $where = '', $limit = '') { |
@@ -134,6 +135,9 @@ discard block |
||
| 134 | 135 | return $result; |
| 135 | 136 | } |
| 136 | 137 | |
| 138 | + /** |
|
| 139 | + * @param integer $config_user_birthday_range |
|
| 140 | + */ |
|
| 137 | 141 | public static function db_user_list_to_celebrate($config_user_birthday_range) { |
| 138 | 142 | $query = "SELECT |
| 139 | 143 | `id`, `username`, `user_birthday`, `user_birthday_celebrated`, |
@@ -213,6 +217,9 @@ discard block |
||
| 213 | 217 | return $user_list; |
| 214 | 218 | } |
| 215 | 219 | |
| 220 | + /** |
|
| 221 | + * @param string $username_unsafe |
|
| 222 | + */ |
|
| 216 | 223 | public static function db_user_by_username($username_unsafe, $for_update = false, $fields = '*', $player = null, $like = false) { |
| 217 | 224 | // TODO Проверить, кстати - а везде ли нужно выбирать юзеров или где-то все-таки ищутся Альянсы ? |
| 218 | 225 | if (!($username_unsafe = trim($username_unsafe))) { |
@@ -266,7 +273,6 @@ discard block |
||
| 266 | 273 | |
| 267 | 274 | /** |
| 268 | 275 | * @param $user_id |
| 269 | - * @param array $set |
|
| 270 | 276 | * @param array $adjust |
| 271 | 277 | * |
| 272 | 278 | * @return array|bool|mysqli_result|null |
@@ -283,8 +289,8 @@ discard block |
||
| 283 | 289 | * <p>array - запись пользователя с установленным полем ['id']</p> |
| 284 | 290 | * @param bool $for_update @deprecated |
| 285 | 291 | * @param string $fields @deprecated список полей или '*'/'' для всех полей |
| 286 | - * @param null $player |
|
| 287 | - * @param bool|null $player Признак выбора записи пользователь типа "игрок" |
|
| 292 | + * @param boolean $player |
|
| 293 | + * @param boolean $player Признак выбора записи пользователь типа "игрок" |
|
| 288 | 294 | * <p>null - Можно выбрать запись любого типа</p> |
| 289 | 295 | * <p>true - Выбирается только запись типа "игрок"</p> |
| 290 | 296 | * <p>false - Выбирается только запись типа "альянс"</p> |
@@ -187,6 +187,9 @@ |
||
| 187 | 187 | return $error_backtrace; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | + /** |
|
| 191 | + * @param string $die_message |
|
| 192 | + */ |
|
| 190 | 193 | public function error_fatal($die_message, $details = 'There is a fatal error on page') { |
| 191 | 194 | // TODO - Записывать детали ошибки в лог-файл |
| 192 | 195 | die($die_message); |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | defined('INSIDE') || die(); |
| 34 | 34 | |
| 35 | -if(php_sapi_name() == "cli") { |
|
| 35 | +if (php_sapi_name() == "cli") { |
|
| 36 | 36 | // In cli-mode |
| 37 | 37 | define('__DEBUG_CRLF', "\r\n"); |
| 38 | 38 | define('__DEBUG_LINE', '-------------------------------------------------' . __DEBUG_CRLF); |
@@ -52,16 +52,16 @@ discard block |
||
| 52 | 52 | public function log_file($message, $ident_change = 0) { |
| 53 | 53 | static $ident = 0; |
| 54 | 54 | |
| 55 | - if(!defined('SN_DEBUG_LOG')) { |
|
| 55 | + if (!defined('SN_DEBUG_LOG')) { |
|
| 56 | 56 | return; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - if($this->log_file_handler === null) { |
|
| 59 | + if ($this->log_file_handler === null) { |
|
| 60 | 60 | $this->log_file_handler = @fopen(SN_ROOT_PHYSICAL . '/.logs/supernova.log', 'a+'); |
| 61 | 61 | @fwrite($this->log_file_handler, "\r\n\r\n"); |
| 62 | 62 | } |
| 63 | 63 | $ident_change < 0 ? $ident += $ident_change * 2 : false; |
| 64 | - if($this->log_file_handler) { |
|
| 64 | + if ($this->log_file_handler) { |
|
| 65 | 65 | @fwrite($this->log_file_handler, date(FMT_DATE_TIME_SQL, time()) . str_repeat(' ', $ident + 1) . $message . "\r\n"); |
| 66 | 66 | } |
| 67 | 67 | $ident_change > 0 ? $ident += $ident_change * 2 : false; |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | $result = array(); |
| 93 | 93 | $transaction_id = classSupernova::$db->getTransaction()->getNextQueryTransactionId(); |
| 94 | 94 | $result[] = "tID {$transaction_id}"; |
| 95 | - foreach($backtrace as $a_trace) { |
|
| 96 | - if(in_array($a_trace['function'], $exclude_functions)) { |
|
| 95 | + foreach ($backtrace as $a_trace) { |
|
| 96 | + if (in_array($a_trace['function'], $exclude_functions)) { |
|
| 97 | 97 | continue; |
| 98 | 98 | } |
| 99 | 99 | $function = |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | // $result[] = "{$function} ({$a_trace['line']})'{$file}'"; |
| 111 | 111 | $result[] = "{$function} - '{$file}' Line {$a_trace['line']}"; |
| 112 | 112 | |
| 113 | - if(!$long_comment) { |
|
| 113 | + if (!$long_comment) { |
|
| 114 | 114 | break; |
| 115 | 115 | } |
| 116 | 116 | } |
@@ -131,26 +131,26 @@ discard block |
||
| 131 | 131 | public function dump($dump = false, $force_base = false, $deadlock = false) { |
| 132 | 132 | global $user, $planetrow; |
| 133 | 133 | |
| 134 | - if($dump === false) { |
|
| 134 | + if ($dump === false) { |
|
| 135 | 135 | return; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | $error_backtrace = array(); |
| 139 | 139 | $base_dump = false; |
| 140 | 140 | |
| 141 | - if($force_base === true) { |
|
| 141 | + if ($force_base === true) { |
|
| 142 | 142 | $base_dump = true; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - if($dump === true) { |
|
| 145 | + if ($dump === true) { |
|
| 146 | 146 | $base_dump = true; |
| 147 | 147 | } else { |
| 148 | - if(!is_array($dump)) { |
|
| 148 | + if (!is_array($dump)) { |
|
| 149 | 149 | $dump = array('var' => $dump); |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - foreach($dump as $dump_var_name => $dump_var) { |
|
| 153 | - if($dump_var_name == 'base_dump') { |
|
| 152 | + foreach ($dump as $dump_var_name => $dump_var) { |
|
| 153 | + if ($dump_var_name == 'base_dump') { |
|
| 154 | 154 | $base_dump = $dump_var; |
| 155 | 155 | } else { |
| 156 | 156 | $error_backtrace[$dump_var_name] = $dump_var; |
@@ -158,22 +158,21 @@ discard block |
||
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - if($deadlock && ($q = db_fetch(classSupernova::$db->mysql_get_innodb_status()))) { |
|
| 161 | + if ($deadlock && ($q = db_fetch(classSupernova::$db->mysql_get_innodb_status()))) { |
|
| 162 | 162 | $error_backtrace['deadlock'] = explode("\n", $q['Status']); |
| 163 | 163 | $error_backtrace['locks'] = classSupernova::$gc->snCache->getLocks(); |
| 164 | 164 | $error_backtrace['cSN_data'] = classSupernova::$gc->snCache->getData(); |
| 165 | - foreach($error_backtrace['cSN_data'] as &$location) { |
|
| 166 | - foreach($location as $location_id => &$location_data) { |
|
| 167 | - $location_data = isset($location_data['username']) ? $location_data['username'] : |
|
| 168 | - (isset($location_data['name']) ? $location_data['name'] : $location_id); |
|
| 165 | + foreach ($error_backtrace['cSN_data'] as &$location) { |
|
| 166 | + foreach ($location as $location_id => &$location_data) { |
|
| 167 | + $location_data = isset($location_data['username']) ? $location_data['username'] : (isset($location_data['name']) ? $location_data['name'] : $location_id); |
|
| 169 | 168 | } |
| 170 | 169 | } |
| 171 | 170 | $error_backtrace['cSN_queries'] = classSupernova::$gc->snCache->getQueries(); |
| 172 | 171 | } |
| 173 | 172 | |
| 174 | - if($base_dump) { |
|
| 175 | - if(is_array($this->log_array) && count($this->log_array) > 0) { |
|
| 176 | - foreach($this->log_array as $log) { |
|
| 173 | + if ($base_dump) { |
|
| 174 | + if (is_array($this->log_array) && count($this->log_array) > 0) { |
|
| 175 | + foreach ($this->log_array as $log) { |
|
| 177 | 176 | $error_backtrace['queries'][] = $log; |
| 178 | 177 | } |
| 179 | 178 | } |
@@ -202,14 +201,14 @@ discard block |
||
| 202 | 201 | public function error($message = 'There is a error on page', $title = 'Internal Error', $error_code = 500, $dump = true) { |
| 203 | 202 | global $sys_stop_log_hit, $sys_log_disabled, $user; |
| 204 | 203 | |
| 205 | - if(empty(classSupernova::$db->connected)) { |
|
| 204 | + if (empty(classSupernova::$db->connected)) { |
|
| 206 | 205 | // TODO - писать ошибку в файл |
| 207 | 206 | die('SQL server currently unavailable. Please contact Administration...'); |
| 208 | 207 | } |
| 209 | 208 | |
| 210 | 209 | sn_db_transaction_rollback(); |
| 211 | 210 | |
| 212 | - if(classSupernova::$config->debug == 1) { |
|
| 211 | + if (classSupernova::$config->debug == 1) { |
|
| 213 | 212 | echo "<h2>{$title}</h2><br><font color=red>{$message}</font><br><hr>"; |
| 214 | 213 | echo "<table>{$this->log}</table>"; |
| 215 | 214 | } |
@@ -221,7 +220,7 @@ discard block |
||
| 221 | 220 | |
| 222 | 221 | $userId = empty($user['id']) ? 0 : $user['id']; |
| 223 | 222 | |
| 224 | - if(!$sys_log_disabled) { |
|
| 223 | + if (!$sys_log_disabled) { |
|
| 225 | 224 | $query = "INSERT INTO `{{logs}}` SET |
| 226 | 225 | `log_time` = '" . time() . "', `log_code` = '" . db_escape($error_code) . "', `log_sender` = '" . db_escape($userId) . "', |
| 227 | 226 | `log_username` = '" . db_escape($user['user_name']) . "', `log_title` = '" . db_escape($title) . "', `log_text` = '" . db_escape($message) . "', |
@@ -240,7 +239,7 @@ discard block |
||
| 240 | 239 | ob_start(); |
| 241 | 240 | print("<hr>User ID {$user['id']} raised error code {$error_code} titled '{$title}' with text '{$error_text}' on page {$_SERVER['SCRIPT_NAME']}"); |
| 242 | 241 | |
| 243 | - foreach($error_backtrace as $name => $value) { |
|
| 242 | + foreach ($error_backtrace as $name => $value) { |
|
| 244 | 243 | print(__DEBUG_LINE); |
| 245 | 244 | pdump($value, $name); |
| 246 | 245 | } |
@@ -258,7 +257,7 @@ discard block |
||
| 258 | 257 | public function warning($message, $title = 'System Message', $log_code = 300, $dump = false) { |
| 259 | 258 | global $user, $sys_log_disabled; |
| 260 | 259 | |
| 261 | - if(empty(classSupernova::$db->connected)) { |
|
| 260 | + if (empty(classSupernova::$db->connected)) { |
|
| 262 | 261 | // TODO - писать ошибку в файл |
| 263 | 262 | die('SQL server currently unavailable. Please contact Administration...'); |
| 264 | 263 | } |
@@ -267,7 +266,7 @@ discard block |
||
| 267 | 266 | |
| 268 | 267 | $userId = empty($user['id']) ? 0 : $user['id']; |
| 269 | 268 | |
| 270 | - if(!$sys_log_disabled) { |
|
| 269 | + if (!$sys_log_disabled) { |
|
| 271 | 270 | $query = "INSERT INTO `{{logs}}` SET |
| 272 | 271 | `log_time` = '" . time() . "', `log_code` = '" . db_escape($log_code) . "', `log_sender` = '" . db_escape($userId) . "', |
| 273 | 272 | `log_username` = '" . db_escape($user['user_name']) . "', `log_title` = '" . db_escape($title) . "', `log_text` = '" . db_escape($message) . "', |
@@ -285,11 +284,11 @@ discard block |
||
| 285 | 284 | // Dump variables nicer then var_dump() |
| 286 | 285 | |
| 287 | 286 | function dump($value, $varname = null, $level = 0, $dumper = '') { |
| 288 | - if(isset($varname)) { |
|
| 287 | + if (isset($varname)) { |
|
| 289 | 288 | $varname .= " = "; |
| 290 | 289 | } |
| 291 | 290 | |
| 292 | - if($level == -1) { |
|
| 291 | + if ($level == -1) { |
|
| 293 | 292 | $trans[' '] = '∴'; |
| 294 | 293 | $trans["\t"] = '⇒'; |
| 295 | 294 | $trans["\n"] = '¶;'; |
@@ -298,7 +297,7 @@ discard block |
||
| 298 | 297 | |
| 299 | 298 | return strtr(htmlspecialchars($value), $trans); |
| 300 | 299 | } |
| 301 | - if($level == 0) { |
|
| 300 | + if ($level == 0) { |
|
| 302 | 301 | // $dumper = '<pre>' . mt_rand(10, 99) . '|' . $varname; |
| 303 | 302 | $dumper = mt_rand(10, 99) . '|' . $varname; |
| 304 | 303 | } |
@@ -306,22 +305,22 @@ discard block |
||
| 306 | 305 | $type = gettype($value); |
| 307 | 306 | $dumper .= $type; |
| 308 | 307 | |
| 309 | - if($type == TYPE_STRING) { |
|
| 308 | + if ($type == TYPE_STRING) { |
|
| 310 | 309 | $dumper .= '(' . strlen($value) . ')'; |
| 311 | 310 | $value = dump($value, '', -1); |
| 312 | - } elseif($type == TYPE_BOOLEAN) { |
|
| 311 | + } elseif ($type == TYPE_BOOLEAN) { |
|
| 313 | 312 | $value = ($value ? 'true' : 'false'); |
| 314 | - } elseif($type == 'object') { |
|
| 313 | + } elseif ($type == 'object') { |
|
| 315 | 314 | $props = get_class_vars(get_class($value)); |
| 316 | 315 | $dumper .= '(' . count($props) . ') <u>' . get_class($value) . '</u>'; |
| 317 | - foreach($props as $key => $val) { |
|
| 316 | + foreach ($props as $key => $val) { |
|
| 318 | 317 | $dumper .= "\n" . str_repeat("\t", $level + 1) . $key . ' => '; |
| 319 | 318 | $dumper .= dump($value->$key, '', $level + 1); |
| 320 | 319 | } |
| 321 | 320 | $value = ''; |
| 322 | - } elseif($type == TYPE_ARRAY) { |
|
| 321 | + } elseif ($type == TYPE_ARRAY) { |
|
| 323 | 322 | $dumper .= '(' . count($value) . ')'; |
| 324 | - foreach($value as $key => $val) { |
|
| 323 | + foreach ($value as $key => $val) { |
|
| 325 | 324 | $dumper .= "\n" . str_repeat("\t", $level + 1) . dump($key, '', -1) . ' => '; |
| 326 | 325 | $dumper .= dump($val, '', $level + 1); |
| 327 | 326 | } |
@@ -341,7 +340,7 @@ discard block |
||
| 341 | 340 | // $backtrace = $backtrace[1]; |
| 342 | 341 | |
| 343 | 342 | $caller = ''; |
| 344 | - if(defined('SN_DEBUG_PDUMP_CALLER') && SN_DEBUG_PDUMP_CALLER) { |
|
| 343 | + if (defined('SN_DEBUG_PDUMP_CALLER') && SN_DEBUG_PDUMP_CALLER) { |
|
| 345 | 344 | $caller = (!empty($backtrace[1]['class']) ? $backtrace[1]['class'] : '') . |
| 346 | 345 | (!empty($backtrace[1]['type']) ? $backtrace[1]['type'] : '') . |
| 347 | 346 | $backtrace[1]['function'] . |
@@ -368,7 +367,7 @@ discard block |
||
| 368 | 367 | } |
| 369 | 368 | |
| 370 | 369 | function pr($prePrint = false) { |
| 371 | - if($prePrint) { |
|
| 370 | + if ($prePrint) { |
|
| 372 | 371 | print(__DEBUG_CRLF); |
| 373 | 372 | } |
| 374 | 373 | print(mt_rand() . __DEBUG_CRLF); |
@@ -378,7 +377,7 @@ discard block |
||
| 378 | 377 | global $_PRINT_COUNT_VALUE; |
| 379 | 378 | $_PRINT_COUNT_VALUE++; |
| 380 | 379 | |
| 381 | - if($prePrint) { |
|
| 380 | + if ($prePrint) { |
|
| 382 | 381 | print(__DEBUG_CRLF); |
| 383 | 382 | } |
| 384 | 383 | print($_PRINT_COUNT_VALUE . __DEBUG_CRLF); |
@@ -409,7 +408,7 @@ discard block |
||
| 409 | 408 | */ |
| 410 | 409 | function pdie($message = '', $level = 0) { |
| 411 | 410 | $backtrace = debug_backtrace(); |
| 412 | - for($i = 0; $i < $level; $i++) { |
|
| 411 | + for ($i = 0; $i < $level; $i++) { |
|
| 413 | 412 | array_pop($backtrace); |
| 414 | 413 | } |
| 415 | 414 | |
@@ -91,7 +91,7 @@ |
||
| 91 | 91 | |
| 92 | 92 | $result = array(); |
| 93 | 93 | $transaction_id = classSupernova::$db->getTransaction()->getNextQueryTransactionId(); |
| 94 | - $result[] = "tID {$transaction_id}"; |
|
| 94 | + $result[] = "tid {$transaction_id}"; |
|
| 95 | 95 | foreach($backtrace as $a_trace) { |
| 96 | 96 | if(in_array($a_trace['function'], $exclude_functions)) { |
| 97 | 97 | continue; |
@@ -118,7 +118,7 @@ |
||
| 118 | 118 | * @param mixed $offset <p> |
| 119 | 119 | * The offset to assign the value to. |
| 120 | 120 | * </p> |
| 121 | - * @param mixed $value <p> |
|
| 121 | + * @param Unit $value <p> |
|
| 122 | 122 | * The value to set. |
| 123 | 123 | * </p> |
| 124 | 124 | * |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | * Преобразовывает данные симулятора в данные для расчета боя |
| 460 | 460 | * |
| 461 | 461 | * @param $side_info |
| 462 | - * @param $attacker |
|
| 462 | + * @param boolean $attacker |
|
| 463 | 463 | * @param int $player_id |
| 464 | 464 | * |
| 465 | 465 | */ |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | /** |
| 524 | - * @return int |
|
| 524 | + * @return double |
|
| 525 | 525 | */ |
| 526 | 526 | public function get_time_spent() { |
| 527 | 527 | return $this->time_spent; |
@@ -564,7 +564,7 @@ discard block |
||
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /** |
| 567 | - * @param $template |
|
| 567 | + * @param null|template $template |
|
| 568 | 568 | * |
| 569 | 569 | * @return template |
| 570 | 570 | */ |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | $this->players->db_load_player_by_id($player_id, UBE_PLAYER_IS_DEFENDER); |
| 151 | 151 | |
| 152 | 152 | $player_db_row = $this->players[$player_id]->getDbRow(); |
| 153 | - if($fortifier_level = mrc_get_level($player_db_row, $this->combatMission->dst_planet, MRC_FORTIFIER)) { |
|
| 153 | + if ($fortifier_level = mrc_get_level($player_db_row, $this->combatMission->dst_planet, MRC_FORTIFIER)) { |
|
| 154 | 154 | $this->planet_bonus->add_unit_by_snid(MRC_FORTIFIER, $fortifier_level); |
| 155 | 155 | } |
| 156 | 156 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | $this->rounds[0] = new UBERound(0); |
| 182 | 182 | $this->rounds[0]->make_snapshot($this->fleet_list); |
| 183 | 183 | |
| 184 | - for($round = 1; $round <= 10; $round++) { |
|
| 184 | + for ($round = 1; $round <= 10; $round++) { |
|
| 185 | 185 | // Проводим раунд |
| 186 | 186 | defined('DEBUG_UBE') ? print("Round {$round}<br>") : false; |
| 187 | 187 | |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | |
| 195 | 195 | // Анализируем итоги текущего раунда и готовим данные для следующего |
| 196 | 196 | $this->combat_result = $this->fleet_list->ubeAnalyzeFleetOutcome($round); |
| 197 | - if($this->combat_result != UBE_COMBAT_RESULT_DRAW) { |
|
| 197 | + if ($this->combat_result != UBE_COMBAT_RESULT_DRAW) { |
|
| 198 | 198 | break; |
| 199 | 199 | } |
| 200 | 200 | |
@@ -223,11 +223,11 @@ discard block |
||
| 223 | 223 | // Генерируем результат боя |
| 224 | 224 | $this->fleet_list->ube_analyze_fleets($this->is_simulator, $this->debris, $this->resource_exchange_rates); |
| 225 | 225 | |
| 226 | - if(!$this->is_ube_loaded) { |
|
| 226 | + if (!$this->is_ube_loaded) { |
|
| 227 | 227 | $this->moon_calculator->calculate_moon($this); |
| 228 | 228 | |
| 229 | 229 | // Лутаем ресурсы - если аттакер выиграл |
| 230 | - if($this->combat_result == UBE_COMBAT_RESULT_WIN) { |
|
| 230 | + if ($this->combat_result == UBE_COMBAT_RESULT_WIN) { |
|
| 231 | 231 | $this->sn_ube_combat_analyze_loot(); |
| 232 | 232 | } |
| 233 | 233 | } |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | RES_DEUTERIUM => 0, |
| 248 | 248 | ); |
| 249 | 249 | |
| 250 | - if( |
|
| 250 | + if ( |
|
| 251 | 251 | (($planet_resource_total = $this->fleet_list[0]->get_resources_amount()) > 0) |
| 252 | 252 | && |
| 253 | 253 | (($total_capacity = $this->fleet_list->ube_get_capacity_attackers()) > 0) |
@@ -259,9 +259,9 @@ discard block |
||
| 259 | 259 | $planet_lootable_percent = $planet_lootable / $planet_resource_total; |
| 260 | 260 | |
| 261 | 261 | // Вычисляем сколько ресурсов вывезено |
| 262 | - foreach($this->fleet_list->_container as $fleet_id => $fleet) { |
|
| 262 | + foreach ($this->fleet_list->_container as $fleet_id => $fleet) { |
|
| 263 | 263 | $looted_in_metal = 0; |
| 264 | - foreach($this->fleet_list[0]->resource_list as $resource_id => $resource_amount) { |
|
| 264 | + foreach ($this->fleet_list[0]->resource_list as $resource_id => $resource_amount) { |
|
| 265 | 265 | // Вычисляем какой процент общей емкости трюмов атакующих будет задействован |
| 266 | 266 | $fleet_lootable_percent = $fleet->fleet_capacity / $total_capacity; |
| 267 | 267 | $looted = floor($resource_amount * $planet_lootable_percent * $fleet_lootable_percent); |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | $destination_user_id = $this->fleet_list[0]->owner_id; |
| 327 | 327 | |
| 328 | 328 | // Обновляем поле обломков на планете |
| 329 | - if(!$this->is_admin_in_combat && $this->debris->debris_total() > 0) { |
|
| 329 | + if (!$this->is_admin_in_combat && $this->debris->debris_total() > 0) { |
|
| 330 | 330 | DBStaticPlanet::db_planet_update_by_gspt( |
| 331 | 331 | $this->ube_planet_info[PLANET_GALAXY], $this->ube_planet_info[PLANET_SYSTEM], $this->ube_planet_info[PLANET_PLANET], PT_PLANET, |
| 332 | 332 | array(), |
@@ -337,10 +337,10 @@ discard block |
||
| 337 | 337 | ); |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - foreach($this->fleet_list->_container as $fleet_id => $UBEFleet) { |
|
| 340 | + foreach ($this->fleet_list->_container as $fleet_id => $UBEFleet) { |
|
| 341 | 341 | $ship_count_lost = $UBEFleet->unit_list->unitCountLost(); |
| 342 | 342 | |
| 343 | - if($fleet_id) { |
|
| 343 | + if ($fleet_id) { |
|
| 344 | 344 | // Флот |
| 345 | 345 | $UBEFleet->db_save_combat_result_fleet($this->is_small_fleet_recce, $this->moon_calculator->get_reapers_status()); |
| 346 | 346 | } else { |
@@ -348,9 +348,9 @@ discard block |
||
| 348 | 348 | |
| 349 | 349 | // Сохраняем изменения ресурсов - если они есть |
| 350 | 350 | $resource_delta = $UBEFleet->ube_combat_result_calculate_resources(); |
| 351 | - if(!empty($resource_delta)) { |
|
| 351 | + if (!empty($resource_delta)) { |
|
| 352 | 352 | $temp = array(); |
| 353 | - foreach($resource_delta as $resource_id => $resource_amount) { |
|
| 353 | + foreach ($resource_delta as $resource_id => $resource_amount) { |
|
| 354 | 354 | $resource_db_name = pname_resource_name($resource_id); |
| 355 | 355 | $temp[$resource_db_name] = $resource_amount; |
| 356 | 356 | } |
@@ -360,9 +360,9 @@ discard block |
||
| 360 | 360 | ); |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - if($ship_count_lost) { |
|
| 363 | + if ($ship_count_lost) { |
|
| 364 | 364 | $planet_row_cache = $this->players[$destination_user_id]->getDbRow(); |
| 365 | - foreach($UBEFleet->unit_list->_container as $UBEUnit) { |
|
| 365 | + foreach ($UBEFleet->unit_list->_container as $UBEUnit) { |
|
| 366 | 366 | DBStaticUnit::dbUpdateOrInsertUnit($UBEUnit->unitId, -$UBEUnit->units_lost, $planet_row_cache, $this->ube_planet_info[PLANET_ID]); |
| 367 | 367 | } |
| 368 | 368 | } |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | // TODO: Связать сабы с флотами констраинтами ON DELETE SET NULL |
| 373 | 373 | // Для САБов |
| 374 | 374 | $fleet_group_id_list = $this->fleet_list->ube_get_groups(); |
| 375 | - if(!empty($fleet_group_id_list)) { |
|
| 375 | + if (!empty($fleet_group_id_list)) { |
|
| 376 | 376 | $fleet_group_id_list = implode(',', $fleet_group_id_list); |
| 377 | 377 | DBStaticFleetACS::db_acs_delete_by_list($fleet_group_id_list); |
| 378 | 378 | } |
@@ -380,14 +380,14 @@ discard block |
||
| 380 | 380 | $this->moon_calculator->db_apply_result($this->ube_planet_info, $destination_user_id); |
| 381 | 381 | |
| 382 | 382 | $bashing_list = array(); |
| 383 | - foreach($this->players->get_player_sides() as $player_id => $player_side) { |
|
| 384 | - if($player_side != UBE_PLAYER_IS_ATTACKER) { |
|
| 383 | + foreach ($this->players->get_player_sides() as $player_id => $player_side) { |
|
| 384 | + if ($player_side != UBE_PLAYER_IS_ATTACKER) { |
|
| 385 | 385 | continue; |
| 386 | 386 | } |
| 387 | - if($this->moon_calculator->get_status() != UBE_MOON_DESTROY_SUCCESS) { |
|
| 387 | + if ($this->moon_calculator->get_status() != UBE_MOON_DESTROY_SUCCESS) { |
|
| 388 | 388 | $bashing_list[] = array($player_id, $this->ube_planet_info[PLANET_ID], $this->combat_timestamp); |
| 389 | 389 | } |
| 390 | - if($this->mission_type_id == MT_ATTACK && $this->is_defender_active_player) { |
|
| 390 | + if ($this->mission_type_id == MT_ATTACK && $this->is_defender_active_player) { |
|
| 391 | 391 | $str_loose_or_win = $this->combat_result == UBE_COMBAT_RESULT_WIN ? 'raidswin' : 'raidsloose'; |
| 392 | 392 | DBStaticUser::db_user_adjust_by_id( |
| 393 | 393 | $player_id, |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | ); |
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | - if(!empty($bashing_list)) { |
|
| 402 | + if (!empty($bashing_list)) { |
|
| 403 | 403 | DBStaticFleetBashing::db_bashing_insert($bashing_list); |
| 404 | 404 | } |
| 405 | 405 | |
@@ -425,20 +425,19 @@ discard block |
||
| 425 | 425 | $planet_info[PLANET_SYSTEM], |
| 426 | 426 | $planet_info[PLANET_PLANET], |
| 427 | 427 | htmlentities($planet_info[PLANET_NAME], ENT_COMPAT, 'UTF-8'), |
| 428 | - classLocale::$lang[$this->combat_result == UBE_COMBAT_RESULT_WIN ? 'ube_report_info_outcome_win' : |
|
| 429 | - ($this->combat_result == UBE_COMBAT_RESULT_DRAW ? 'ube_report_info_outcome_draw' : 'ube_report_info_outcome_loss')] |
|
| 428 | + classLocale::$lang[$this->combat_result == UBE_COMBAT_RESULT_WIN ? 'ube_report_info_outcome_win' : ($this->combat_result == UBE_COMBAT_RESULT_DRAW ? 'ube_report_info_outcome_draw' : 'ube_report_info_outcome_loss')] |
|
| 430 | 429 | ); |
| 431 | 430 | |
| 432 | 431 | $text_defender = ''; |
| 433 | 432 | $debris = $this->debris->get_debris(); |
| 434 | - foreach($debris as $resource_id => $resource_amount) { |
|
| 435 | - if($resource_id == RES_DEUTERIUM) { |
|
| 433 | + foreach ($debris as $resource_id => $resource_amount) { |
|
| 434 | + if ($resource_id == RES_DEUTERIUM) { |
|
| 436 | 435 | continue; |
| 437 | 436 | } |
| 438 | 437 | |
| 439 | 438 | $text_defender .= "{$classLocale['tech'][$resource_id]}: " . pretty_number($resource_amount) . '<br />'; |
| 440 | 439 | } |
| 441 | - if($text_defender) { |
|
| 440 | + if ($text_defender) { |
|
| 442 | 441 | $text_defender = "{$classLocale['ube_report_msg_body_debris']}{$text_defender}<br />"; |
| 443 | 442 | } |
| 444 | 443 | |
@@ -448,7 +447,7 @@ discard block |
||
| 448 | 447 | |
| 449 | 448 | // TODO: Оптимизировать отсылку сообщений - отсылать пакетами |
| 450 | 449 | $player_sides = $this->players->get_player_sides(); |
| 451 | - foreach($player_sides as $player_id => $player_side) { |
|
| 450 | + foreach ($player_sides as $player_id => $player_side) { |
|
| 452 | 451 | $message = $text_common . ($this->is_small_fleet_recce && ($player_side == UBE_PLAYER_IS_ATTACKER) ? classLocale::$lang['ube_report_msg_body_sfr'] : $text_defender); |
| 453 | 452 | DBStaticMessages::msg_send_simple_message($player_id, '', $this->combat_timestamp, MSG_TYPE_COMBAT, classLocale::$lang['sys_mess_tower'], classLocale::$lang['sys_mess_attack_report'], $message); |
| 454 | 453 | } |
@@ -484,11 +483,11 @@ discard block |
||
| 484 | 483 | $player_id = $player_id == -1 ? $this->players->count() : $player_id; |
| 485 | 484 | $fleet_id = $player_id; // FOR SIMULATOR! |
| 486 | 485 | |
| 487 | - if(empty($this->players[$player_id])) { |
|
| 486 | + if (empty($this->players[$player_id])) { |
|
| 488 | 487 | $this->players[$player_id] = new UBEPlayer(); |
| 489 | 488 | } |
| 490 | 489 | |
| 491 | - foreach($side_info as $fleet_data) { |
|
| 490 | + foreach ($side_info as $fleet_data) { |
|
| 492 | 491 | $this->players[$player_id]->name = $player_id; |
| 493 | 492 | $this->players[$player_id]->setSide($attacker); |
| 494 | 493 | |
@@ -496,32 +495,32 @@ discard block |
||
| 496 | 495 | $this->fleet_list[$fleet_id] = $objFleet; |
| 497 | 496 | |
| 498 | 497 | $this->fleet_list[$fleet_id]->owner_id = $player_id; |
| 499 | - foreach($fleet_data as $unit_id => $unit_count) { |
|
| 500 | - if(!$unit_count) { |
|
| 498 | + foreach ($fleet_data as $unit_id => $unit_count) { |
|
| 499 | + if (!$unit_count) { |
|
| 501 | 500 | continue; |
| 502 | 501 | } |
| 503 | 502 | |
| 504 | 503 | $unit_type = get_unit_param($unit_id, P_UNIT_TYPE); |
| 505 | 504 | |
| 506 | - if($unit_type == UNIT_SHIPS || $unit_type == UNIT_DEFENCE) { |
|
| 505 | + if ($unit_type == UNIT_SHIPS || $unit_type == UNIT_DEFENCE) { |
|
| 507 | 506 | $this->fleet_list[$fleet_id]->unit_list->unitAdjustCount($unit_id, $unit_count); |
| 508 | - } elseif($unit_type == UNIT_RESOURCES) { |
|
| 507 | + } elseif ($unit_type == UNIT_RESOURCES) { |
|
| 509 | 508 | $this->fleet_list[$fleet_id]->resource_list[$unit_id] = $unit_count; |
| 510 | - } elseif($unit_type == UNIT_TECHNOLOGIES) { |
|
| 511 | - if($unit_id == TECH_WEAPON) { |
|
| 509 | + } elseif ($unit_type == UNIT_TECHNOLOGIES) { |
|
| 510 | + if ($unit_id == TECH_WEAPON) { |
|
| 512 | 511 | $this->players[$player_id]->player_bonus->add_unit_by_snid(TECH_WEAPON, $unit_count); |
| 513 | - } elseif($unit_id == TECH_SHIELD) { |
|
| 512 | + } elseif ($unit_id == TECH_SHIELD) { |
|
| 514 | 513 | $this->players[$player_id]->player_bonus->add_unit_by_snid(TECH_SHIELD, $unit_count); |
| 515 | - } elseif($unit_id == TECH_ARMOR) { |
|
| 514 | + } elseif ($unit_id == TECH_ARMOR) { |
|
| 516 | 515 | $this->players[$player_id]->player_bonus->add_unit_by_snid(TECH_ARMOR, $unit_count); |
| 517 | 516 | } |
| 518 | - } elseif($unit_type == UNIT_GOVERNORS) { |
|
| 519 | - if($unit_id == MRC_FORTIFIER) { |
|
| 517 | + } elseif ($unit_type == UNIT_GOVERNORS) { |
|
| 518 | + if ($unit_id == MRC_FORTIFIER) { |
|
| 520 | 519 | // Фортифаер даёт бонус ко всему |
| 521 | 520 | $this->planet_bonus->add_unit_by_snid(MRC_FORTIFIER, $unit_count); |
| 522 | 521 | } |
| 523 | - } elseif($unit_type == UNIT_MERCENARIES) { |
|
| 524 | - if($unit_id == MRC_ADMIRAL) { |
|
| 522 | + } elseif ($unit_type == UNIT_MERCENARIES) { |
|
| 523 | + if ($unit_id == MRC_ADMIRAL) { |
|
| 525 | 524 | $this->players[$player_id]->player_bonus->add_unit_by_snid(MRC_ADMIRAL, $unit_count); |
| 526 | 525 | } |
| 527 | 526 | } |
@@ -590,7 +589,7 @@ discard block |
||
| 590 | 589 | |
| 591 | 590 | $ube_report = new UBEReport(); |
| 592 | 591 | $ube = $ube_report->sn_ube_report_load(sys_get_param_str('cypher')); |
| 593 | - if($ube != UBE_REPORT_NOT_FOUND) { |
|
| 592 | + if ($ube != UBE_REPORT_NOT_FOUND) { |
|
| 594 | 593 | $ube_report->sn_ube_report_generate($ube, $template_result); |
| 595 | 594 | |
| 596 | 595 | $template = gettemplate('ube_combat_report', $template); |
@@ -618,9 +617,9 @@ discard block |
||
| 618 | 617 | $ube->sn_ube_combat(); |
| 619 | 618 | $ube_report = new UBEReport(); |
| 620 | 619 | |
| 621 | - if(sys_get_param_str('reload')) { |
|
| 620 | + if (sys_get_param_str('reload')) { |
|
| 622 | 621 | $ube_new = $ube_report->sn_ube_report_load($ube->get_cypher()); // $combat_data = sn_ube_report_load($combat_data[UBE_REPORT_CYPHER]); |
| 623 | - if($ube_new != UBE_REPORT_NOT_FOUND && is_object($ube_new)) { |
|
| 622 | + if ($ube_new != UBE_REPORT_NOT_FOUND && is_object($ube_new)) { |
|
| 624 | 623 | $ube = $ube_new; |
| 625 | 624 | } |
| 626 | 625 | } |
@@ -668,7 +667,7 @@ discard block |
||
| 668 | 667 | $this->debris->load_from_report_row($report_row); |
| 669 | 668 | |
| 670 | 669 | $query = classSupernova::$db->doSelect("SELECT * FROM {{ube_report_player}} WHERE `ube_report_id` = {$report_row['ube_report_id']}"); |
| 671 | - while($player_row = db_fetch($query)) { |
|
| 670 | + while ($player_row = db_fetch($query)) { |
|
| 672 | 671 | $this->players->init_player_from_report_info($player_row); |
| 673 | 672 | } |
| 674 | 673 | |
@@ -183,7 +183,7 @@ |
||
| 183 | 183 | |
| 184 | 184 | for($round = 1; $round <= 10; $round++) { |
| 185 | 185 | // Проводим раунд |
| 186 | - defined('DEBUG_UBE') ? print("Round {$round}<br>") : false; |
|
| 186 | + defined('DEBUG_UBE') ? print("round {$round}<br>") : false; |
|
| 187 | 187 | |
| 188 | 188 | $this->fleet_list->ube_calculate_attack_results($this); |
| 189 | 189 | |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
| 153 | - * @param $ube_report_id |
|
| 153 | + * @param integer $ube_report_id |
|
| 154 | 154 | * |
| 155 | 155 | * @return array |
| 156 | 156 | * |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | |
| 289 | 289 | |
| 290 | 290 | /** |
| 291 | - * @param $ube_report_id |
|
| 291 | + * @param integer $ube_report_id |
|
| 292 | 292 | * |
| 293 | 293 | * @return array |
| 294 | 294 | */ |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | // Рендерит таблицу общего результата боя |
| 337 | 337 | /** |
| 338 | 338 | * @param $array |
| 339 | - * @param $lang_header_index |
|
| 339 | + * @param string $lang_header_index |
|
| 340 | 340 | * |
| 341 | 341 | * @return array |
| 342 | 342 | */ |
@@ -362,6 +362,9 @@ discard block |
||
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | |
| 365 | + /** |
|
| 366 | + * @param integer $ube_report_id |
|
| 367 | + */ |
|
| 365 | 368 | public function sql_generate_outcome_unit_array(&$sql_perform_report_unit, $ube_report_id) { |
| 366 | 369 | $fleet_id = $this->db_id; |
| 367 | 370 | |
@@ -468,6 +471,10 @@ discard block |
||
| 468 | 471 | $this->fleet_capacity -= $fleet_total_resources; |
| 469 | 472 | } |
| 470 | 473 | |
| 474 | + /** |
|
| 475 | + * @param integer $is_small_fleet_recce |
|
| 476 | + * @param integer $reapers_status |
|
| 477 | + */ |
|
| 471 | 478 | public function db_save_combat_result_fleet($is_small_fleet_recce, $reapers_status) { |
| 472 | 479 | $ship_count_initial = $this->unit_list->unitsCount(); |
| 473 | 480 | $ship_count_lost = $this->unit_list->unitCountLost(); |
@@ -535,7 +542,7 @@ discard block |
||
| 535 | 542 | |
| 536 | 543 | /** |
| 537 | 544 | * @param UBEFleetList $fleet_list |
| 538 | - * @param $is_simulator |
|
| 545 | + * @param boolean $is_simulator |
|
| 539 | 546 | * |
| 540 | 547 | * @version 2016-02-25 23:42:45 41a4.68 |
| 541 | 548 | */ |
@@ -159,20 +159,20 @@ discard block |
||
| 159 | 159 | $this->owner_id, |
| 160 | 160 | $this->db_id, |
| 161 | 161 | |
| 162 | - (float)$this->UBE_PLANET[PLANET_ID], |
|
| 162 | + (float) $this->UBE_PLANET[PLANET_ID], |
|
| 163 | 163 | "'" . db_escape($this->UBE_PLANET[PLANET_NAME]) . "'", |
| 164 | - (int)$this->UBE_PLANET[PLANET_GALAXY], |
|
| 165 | - (int)$this->UBE_PLANET[PLANET_SYSTEM], |
|
| 166 | - (int)$this->UBE_PLANET[PLANET_PLANET], |
|
| 167 | - (int)$this->UBE_PLANET[PLANET_TYPE], |
|
| 168 | - |
|
| 169 | - (float)$this->resource_list[RES_METAL], |
|
| 170 | - (float)$this->resource_list[RES_CRYSTAL], |
|
| 171 | - (float)$this->resource_list[RES_DEUTERIUM], |
|
| 172 | - |
|
| 173 | - (float)$this->fleet_bonus->calcBonus(P_ATTACK), |
|
| 174 | - (float)$this->fleet_bonus->calcBonus(P_SHIELD), |
|
| 175 | - (float)$this->fleet_bonus->calcBonus(P_ARMOR), |
|
| 164 | + (int) $this->UBE_PLANET[PLANET_GALAXY], |
|
| 165 | + (int) $this->UBE_PLANET[PLANET_SYSTEM], |
|
| 166 | + (int) $this->UBE_PLANET[PLANET_PLANET], |
|
| 167 | + (int) $this->UBE_PLANET[PLANET_TYPE], |
|
| 168 | + |
|
| 169 | + (float) $this->resource_list[RES_METAL], |
|
| 170 | + (float) $this->resource_list[RES_CRYSTAL], |
|
| 171 | + (float) $this->resource_list[RES_DEUTERIUM], |
|
| 172 | + |
|
| 173 | + (float) $this->fleet_bonus->calcBonus(P_ATTACK), |
|
| 174 | + (float) $this->fleet_bonus->calcBonus(P_SHIELD), |
|
| 175 | + (float) $this->fleet_bonus->calcBonus(P_ARMOR), |
|
| 176 | 176 | ); |
| 177 | 177 | } |
| 178 | 178 | |
@@ -185,13 +185,13 @@ discard block |
||
| 185 | 185 | $this->owner_id = $objFleet->playerOwnerId; |
| 186 | 186 | $this->group_id = $objFleet->group_id; |
| 187 | 187 | |
| 188 | - foreach($objFleet->shipsIterator() as $unit_id => $unit) { |
|
| 189 | - if(!$unit->count) { |
|
| 188 | + foreach ($objFleet->shipsIterator() as $unit_id => $unit) { |
|
| 189 | + if (!$unit->count) { |
|
| 190 | 190 | continue; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | $unit_type = get_unit_param($unit_id, P_UNIT_TYPE); |
| 194 | - if($unit_type == UNIT_SHIPS || $unit_type == UNIT_DEFENCE) { |
|
| 194 | + if ($unit_type == UNIT_SHIPS || $unit_type == UNIT_DEFENCE) { |
|
| 195 | 195 | $this->unit_list->unitAdjustCount($unit_id, $unit->count); |
| 196 | 196 | } |
| 197 | 197 | } |
@@ -227,13 +227,13 @@ discard block |
||
| 227 | 227 | // } |
| 228 | 228 | // } |
| 229 | 229 | |
| 230 | - foreach($sn_group_combat as $unit_id) { |
|
| 231 | - if($unit_count = mrc_get_level($player_db_row, $planet_row, $unit_id)) { |
|
| 230 | + foreach ($sn_group_combat as $unit_id) { |
|
| 231 | + if ($unit_count = mrc_get_level($player_db_row, $planet_row, $unit_id)) { |
|
| 232 | 232 | $this->unit_list->unitAdjustCount($unit_id, $unit_count); |
| 233 | 233 | } |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - foreach(sn_get_groups('resources_loot') as $resource_id) { |
|
| 236 | + foreach (sn_get_groups('resources_loot') as $resource_id) { |
|
| 237 | 237 | $this->resource_list[$resource_id] = floor(mrc_get_level($player_db_row, $planet_row, $resource_id)); |
| 238 | 238 | } |
| 239 | 239 | |
@@ -292,27 +292,27 @@ discard block |
||
| 292 | 292 | $ube_report_id, |
| 293 | 293 | $this->db_id, |
| 294 | 294 | |
| 295 | - (float)$this->resources_lost_on_units[RES_METAL], |
|
| 296 | - (float)$this->resources_lost_on_units[RES_CRYSTAL], |
|
| 297 | - (float)$this->resources_lost_on_units[RES_DEUTERIUM], |
|
| 298 | - (float)$this->cargo_dropped[RES_METAL], |
|
| 299 | - (float)$this->cargo_dropped[RES_CRYSTAL], |
|
| 300 | - (float)$this->cargo_dropped[RES_DEUTERIUM], |
|
| 301 | - (float)$this->resources_looted[RES_METAL], |
|
| 302 | - (float)$this->resources_looted[RES_CRYSTAL], |
|
| 303 | - (float)$this->resources_looted[RES_DEUTERIUM], |
|
| 304 | - (float)$this->resources_lost_in_metal[RES_METAL], |
|
| 295 | + (float) $this->resources_lost_on_units[RES_METAL], |
|
| 296 | + (float) $this->resources_lost_on_units[RES_CRYSTAL], |
|
| 297 | + (float) $this->resources_lost_on_units[RES_DEUTERIUM], |
|
| 298 | + (float) $this->cargo_dropped[RES_METAL], |
|
| 299 | + (float) $this->cargo_dropped[RES_CRYSTAL], |
|
| 300 | + (float) $this->cargo_dropped[RES_DEUTERIUM], |
|
| 301 | + (float) $this->resources_looted[RES_METAL], |
|
| 302 | + (float) $this->resources_looted[RES_CRYSTAL], |
|
| 303 | + (float) $this->resources_looted[RES_DEUTERIUM], |
|
| 304 | + (float) $this->resources_lost_in_metal[RES_METAL], |
|
| 305 | 305 | ); |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | public function report_render_outcome_side_fleet() { |
| 309 | 309 | $UBE_DEFENCE_RESTORE = array(); |
| 310 | 310 | $UBE_UNITS_LOST = array(); |
| 311 | - foreach($this->unit_list->_container as $UBEUnit) { |
|
| 312 | - if($UBEUnit->units_restored) { |
|
| 311 | + foreach ($this->unit_list->_container as $UBEUnit) { |
|
| 312 | + if ($UBEUnit->units_restored) { |
|
| 313 | 313 | $UBE_DEFENCE_RESTORE[$UBEUnit->unitId] = $UBEUnit->units_restored; |
| 314 | 314 | } |
| 315 | - if($UBEUnit->units_lost) { |
|
| 315 | + if ($UBEUnit->units_lost) { |
|
| 316 | 316 | $UBE_UNITS_LOST[$UBEUnit->unitId] = $UBEUnit->units_lost; |
| 317 | 317 | } |
| 318 | 318 | } |
@@ -337,16 +337,16 @@ discard block |
||
| 337 | 337 | */ |
| 338 | 338 | protected function report_render_outcome_side_fleet_line(&$array, $lang_header_index) { |
| 339 | 339 | $result = array(); |
| 340 | - if(!empty($array)) { |
|
| 341 | - foreach($array as $unit_id => $unit_count) { |
|
| 342 | - if($unit_count) { |
|
| 340 | + if (!empty($array)) { |
|
| 341 | + foreach ($array as $unit_id => $unit_count) { |
|
| 342 | + if ($unit_count) { |
|
| 343 | 343 | $result[] = array( |
| 344 | 344 | 'NAME' => classLocale::$lang['tech'][$unit_id], |
| 345 | 345 | 'LOSS' => pretty_number($unit_count), |
| 346 | 346 | ); |
| 347 | 347 | } |
| 348 | 348 | } |
| 349 | - if($lang_header_index && count($result)) { |
|
| 349 | + if ($lang_header_index && count($result)) { |
|
| 350 | 350 | array_unshift($result, array('NAME' => classLocale::$lang[$lang_header_index])); |
| 351 | 351 | } |
| 352 | 352 | } |
@@ -359,16 +359,16 @@ discard block |
||
| 359 | 359 | $fleet_id = $this->db_id; |
| 360 | 360 | |
| 361 | 361 | $unit_sort_order = 0; |
| 362 | - foreach($this->unit_list->_container as $UBEUnit) { |
|
| 363 | - if($UBEUnit->units_lost || $UBEUnit->units_restored) { |
|
| 362 | + foreach ($this->unit_list->_container as $UBEUnit) { |
|
| 363 | + if ($UBEUnit->units_lost || $UBEUnit->units_restored) { |
|
| 364 | 364 | $unit_sort_order++; |
| 365 | 365 | $sql_perform_report_unit[] = array( |
| 366 | 366 | $ube_report_id, |
| 367 | 367 | $fleet_id, |
| 368 | 368 | |
| 369 | 369 | $UBEUnit->unitId, |
| 370 | - (float)$UBEUnit->units_restored, |
|
| 371 | - (float)$UBEUnit->units_lost, |
|
| 370 | + (float) $UBEUnit->units_restored, |
|
| 371 | + (float) $UBEUnit->units_lost, |
|
| 372 | 372 | |
| 373 | 373 | $unit_sort_order, |
| 374 | 374 | ); |
@@ -384,9 +384,9 @@ discard block |
||
| 384 | 384 | public function ube_combat_result_calculate_resources() { |
| 385 | 385 | $resource_delta_fleet = array(); |
| 386 | 386 | // Если во флоте остались юниты или это планета - генерируем изменение ресурсов |
| 387 | - foreach(sn_get_groups('resources_loot') as $resource_id) { |
|
| 388 | - $resource_change = (float)$this->resources_looted[$resource_id] + (float)$this->cargo_dropped[$resource_id]; |
|
| 389 | - if($resource_change) { |
|
| 387 | + foreach (sn_get_groups('resources_loot') as $resource_id) { |
|
| 388 | + $resource_change = (float) $this->resources_looted[$resource_id] + (float) $this->cargo_dropped[$resource_id]; |
|
| 389 | + if ($resource_change) { |
|
| 390 | 390 | $resource_delta_fleet[$resource_id] = -($resource_change); |
| 391 | 391 | } |
| 392 | 392 | } |
@@ -419,12 +419,12 @@ discard block |
||
| 419 | 419 | ); |
| 420 | 420 | |
| 421 | 421 | $this->fleet_capacity = 0; |
| 422 | - foreach($this->unit_list->_container as $UBEUnit) { |
|
| 422 | + foreach ($this->unit_list->_container as $UBEUnit) { |
|
| 423 | 423 | $this->fleet_capacity += $UBEUnit->capacity * $UBEUnit->count; |
| 424 | 424 | |
| 425 | - if($UBEUnit->units_lost) { |
|
| 426 | - foreach($UBEUnit->price as $resource_id => $unit_resource_price) { |
|
| 427 | - if(!$unit_resource_price) { |
|
| 425 | + if ($UBEUnit->units_lost) { |
|
| 426 | + foreach ($UBEUnit->price as $resource_id => $unit_resource_price) { |
|
| 427 | + if (!$unit_resource_price) { |
|
| 428 | 428 | continue; |
| 429 | 429 | } |
| 430 | 430 | |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | $this->resources_lost_on_units[$resource_id] += $resources_lost; |
| 433 | 433 | // Если это корабль - прибавляем потери к обломкам на орбите |
| 434 | 434 | // TODO - опция выбрасывания обороны в обломки |
| 435 | - if($UBEUnit->getType() == UNIT_SHIPS) { |
|
| 435 | + if ($UBEUnit->getType() == UNIT_SHIPS) { |
|
| 436 | 436 | $this->resources_lost_on_ships[$resource_id] += $resources_lost; |
| 437 | 437 | } |
| 438 | 438 | } |
@@ -444,11 +444,11 @@ discard block |
||
| 444 | 444 | |
| 445 | 445 | // Если емкость трюмов меньше количество ресурсов - часть ресов выбрасываем нахуй |
| 446 | 446 | // На планете ($fleet_id = 0) ресурсы в космос не выбрасываются |
| 447 | - if($this->db_id != 0 && $this->fleet_capacity < $fleet_total_resources) { |
|
| 447 | + if ($this->db_id != 0 && $this->fleet_capacity < $fleet_total_resources) { |
|
| 448 | 448 | $drop_share = 1 - $this->fleet_capacity / $fleet_total_resources; // Какая часть ресурсов выброшена |
| 449 | - foreach($this->resource_list as $resource_id => &$resource_amount) { |
|
| 449 | + foreach ($this->resource_list as $resource_id => &$resource_amount) { |
|
| 450 | 450 | // Не просчитываем ресурсы, которых нет на борту кораблей флота |
| 451 | - if(!$resource_amount) { |
|
| 451 | + if (!$resource_amount) { |
|
| 452 | 452 | continue; |
| 453 | 453 | } |
| 454 | 454 | |
@@ -469,19 +469,19 @@ discard block |
||
| 469 | 469 | $objFleet2->dbId = $this->db_id; |
| 470 | 470 | |
| 471 | 471 | // Если это была миссия Уничтожения И звезда смерти взорвалась И мы работаем с аттакерами - значит все аттакеры умерли |
| 472 | - if($this->is_attacker == UBE_PLAYER_IS_ATTACKER && $reapers_status == UBE_MOON_REAPERS_DIED) { |
|
| 472 | + if ($this->is_attacker == UBE_PLAYER_IS_ATTACKER && $reapers_status == UBE_MOON_REAPERS_DIED) { |
|
| 473 | 473 | $objFleet2->dbDelete(); |
| 474 | - } elseif($ship_count_initial == 0) { // $ship_count_lost == $ship_count_initial || |
|
| 474 | + } elseif ($ship_count_initial == 0) { // $ship_count_lost == $ship_count_initial || |
|
| 475 | 475 | $objFleet2->dbDelete(); |
| 476 | 476 | } else { |
| 477 | - if($ship_count_lost) { |
|
| 477 | + if ($ship_count_lost) { |
|
| 478 | 478 | // Просматриваем результаты изменения флотов |
| 479 | - foreach($this->unit_list->_container as $UBEUnit) { |
|
| 479 | + foreach ($this->unit_list->_container as $UBEUnit) { |
|
| 480 | 480 | // Перебираем аутком на случай восстановления юнитов |
| 481 | 481 | // if(($units_left = $UBEUnit->getCount() - (float)$UBEUnit->units_lost) > 0) { |
| 482 | 482 | // $fleet_real_array[$UBEUnit->unitId] = $units_left; |
| 483 | 483 | // }; |
| 484 | - if(floatval($UBEUnit->units_lost) != 0) { |
|
| 484 | + if (floatval($UBEUnit->units_lost) != 0) { |
|
| 485 | 485 | $objFleet2->shipAdjustCount($UBEUnit->unitId, floatval($UBEUnit->units_lost)); |
| 486 | 486 | }; |
| 487 | 487 | } |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | $objFleet2->resourcesAdjust($resource_delta_fleet); |
| 492 | 492 | |
| 493 | 493 | // Если защитник и не РМФ - отправляем флот назад |
| 494 | - if($this->is_attacker == UBE_PLAYER_IS_ATTACKER || ($this->is_attacker == UBE_PLAYER_IS_DEFENDER && !$is_small_fleet_recce)) { |
|
| 494 | + if ($this->is_attacker == UBE_PLAYER_IS_ATTACKER || ($this->is_attacker == UBE_PLAYER_IS_DEFENDER && !$is_small_fleet_recce)) { |
|
| 495 | 495 | $objFleet2->is_returning = 1; |
| 496 | 496 | } |
| 497 | 497 | $objFleet2->dbSave(); |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | public function calculate_unit_partial_data(UBEASA $side_ASA) { |
| 522 | 522 | $this->fleet_share_of_side_armor = $this->total_stats[P_ARMOR] / $side_ASA->getArmor(); |
| 523 | 523 | |
| 524 | - foreach($this->unit_list->_container as $UBEUnit) { |
|
| 524 | + foreach ($this->unit_list->_container as $UBEUnit) { |
|
| 525 | 525 | $UBEUnit->share_of_side_armor = $UBEUnit->pool_armor / $side_ASA->getArmor(); |
| 526 | 526 | } |
| 527 | 527 | } |
@@ -533,9 +533,9 @@ discard block |
||
| 533 | 533 | * @version 2016-02-25 23:42:45 41a4.68 |
| 534 | 534 | */ |
| 535 | 535 | public function attack_fleets(UBEFleetList $fleet_list, $is_simulator) { |
| 536 | - foreach($fleet_list->_container as $defending_fleet) { |
|
| 536 | + foreach ($fleet_list->_container as $defending_fleet) { |
|
| 537 | 537 | // Не атакуются флоты на своей стороне |
| 538 | - if($this->is_attacker == $defending_fleet->is_attacker) { |
|
| 538 | + if ($this->is_attacker == $defending_fleet->is_attacker) { |
|
| 539 | 539 | continue; |
| 540 | 540 | } |
| 541 | 541 | $this->attack_fleet($defending_fleet, $is_simulator); |
@@ -550,12 +550,12 @@ discard block |
||
| 550 | 550 | public function attack_fleet(UBEFleet $defending_fleet, $is_simulator) { |
| 551 | 551 | UBEDebug::unit_dump_header(); |
| 552 | 552 | |
| 553 | - foreach($this->unit_list->_container as $attacking_unit_pool) { |
|
| 553 | + foreach ($this->unit_list->_container as $attacking_unit_pool) { |
|
| 554 | 554 | UBEDebug::unit_dump($attacking_unit_pool, 'attacker'); |
| 555 | 555 | |
| 556 | 556 | // if($attack_unit_count <= 0) continue; // TODO: Это пока нельзя включать - вот если будут "боевые порядки юнитов..." |
| 557 | - foreach($defending_fleet->unit_list->_container as $defending_unit_pool) { |
|
| 558 | - if($defending_unit_pool->isEmpty()) { |
|
| 557 | + foreach ($defending_fleet->unit_list->_container as $defending_unit_pool) { |
|
| 558 | + if ($defending_unit_pool->isEmpty()) { |
|
| 559 | 559 | continue; |
| 560 | 560 | } |
| 561 | 561 | |
@@ -278,6 +278,9 @@ |
||
| 278 | 278 | return count($this->ube_side_present_at_round_start); |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | + /** |
|
| 282 | + * @param integer $round |
|
| 283 | + */ |
|
| 281 | 284 | public function ubeAnalyzeFleetOutcome($round) { |
| 282 | 285 | $this->ube_actualize_sides(); |
| 283 | 286 | |
@@ -232,7 +232,7 @@ |
||
| 232 | 232 | public function ube_calculate_attack_results(UBE $ube) { |
| 233 | 233 | // Каждый флот атакует все |
| 234 | 234 | foreach($this->_container as $attack_fleet_data) { |
| 235 | - defined('DEBUG_UBE') ? print("Fleet {$attack_fleet_data->db_id} attacks<br /><div style='margin-left: 30px;'>") : false; |
|
| 235 | + defined('DEBUG_UBE') ? print("fleet {$attack_fleet_data->db_id} attacks<br /><div style='margin-left: 30px;'>") : false; |
|
| 236 | 236 | |
| 237 | 237 | $attack_fleet_data->attack_fleets($this, $ube->is_simulator); |
| 238 | 238 | |
@@ -78,13 +78,13 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public function ube_db_load_fleets_outcome($report_row) { |
| 80 | 80 | $query = classSupernova::$db->doSelect("SELECT * FROM {{ube_report_outcome_fleet}} WHERE `ube_report_id` = {$report_row['ube_report_id']}"); |
| 81 | - while($row = db_fetch($query)) { |
|
| 81 | + while ($row = db_fetch($query)) { |
|
| 82 | 82 | $fleet_id = $row['ube_report_outcome_fleet_fleet_id']; |
| 83 | 83 | $this[$fleet_id]->load_outcome_from_report_row($row); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | $query = classSupernova::$db->doSelect("SELECT * FROM {{ube_report_outcome_unit}} WHERE `ube_report_id` = {$report_row['ube_report_id']} ORDER BY `ube_report_outcome_unit_sort_order`"); |
| 87 | - while($row = db_fetch($query)) { |
|
| 87 | + while ($row = db_fetch($query)) { |
|
| 88 | 88 | $fleet_id = $row['ube_report_outcome_unit_fleet_id']; |
| 89 | 89 | $this[$fleet_id]->load_unit_outcome_from_row($row); |
| 90 | 90 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | UBE_PLAYER_IS_DEFENDER => array(), |
| 105 | 105 | ); |
| 106 | 106 | |
| 107 | - foreach($this->_container as $fleet_id => $UBEFleet) { |
|
| 107 | + foreach ($this->_container as $fleet_id => $UBEFleet) { |
|
| 108 | 108 | $result[$UBEFleet->is_attacker][] = array( |
| 109 | 109 | 'ID' => $fleet_id, |
| 110 | 110 | 'NAME' => $ube->players[$UBEFleet->owner_id]->name, |
@@ -126,11 +126,11 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function ube_analyze_fleets($is_simulator, UBEDebris $debris, array $resource_exchange_rates) { |
| 128 | 128 | // Генерируем результат боя |
| 129 | - foreach($this->_container as $fleet_id => $UBEFleet) { |
|
| 129 | + foreach ($this->_container as $fleet_id => $UBEFleet) { |
|
| 130 | 130 | // Инициализируем массив результатов для флота |
| 131 | 131 | // $this->init_fleet_outcome_and_link_to_side($UBEFleet); |
| 132 | 132 | |
| 133 | - foreach($UBEFleet->unit_list->_container as $UBEUnit) { |
|
| 133 | + foreach ($UBEFleet->unit_list->_container as $UBEUnit) { |
|
| 134 | 134 | $UBEUnit->ube_analyze_unit($is_simulator); |
| 135 | 135 | } |
| 136 | 136 | |
@@ -147,10 +147,10 @@ discard block |
||
| 147 | 147 | $this->resources_lost_in_metal = array( |
| 148 | 148 | RES_METAL => 0, |
| 149 | 149 | ); |
| 150 | - foreach($UBEFleet->resources_lost_on_units as $resource_id => $resource_amount) { |
|
| 150 | + foreach ($UBEFleet->resources_lost_on_units as $resource_id => $resource_amount) { |
|
| 151 | 151 | $UBEFleet->resources_lost_in_metal[RES_METAL] += $resource_amount * $resource_exchange_rates[$resource_id]; |
| 152 | 152 | } |
| 153 | - foreach($UBEFleet->cargo_dropped as $resource_id => $resource_amount) { |
|
| 153 | + foreach ($UBEFleet->cargo_dropped as $resource_id => $resource_amount) { |
|
| 154 | 154 | $UBEFleet->resources_lost_in_metal[RES_METAL] += $resource_amount * $resource_exchange_rates[$resource_id]; |
| 155 | 155 | } |
| 156 | 156 | } |
@@ -161,8 +161,8 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public function ube_get_groups() { |
| 163 | 163 | $result = array(); |
| 164 | - foreach($this->_container as $UBEFleet) { |
|
| 165 | - if($UBEFleet->group_id) { |
|
| 164 | + foreach ($this->_container as $UBEFleet) { |
|
| 165 | + if ($UBEFleet->group_id) { |
|
| 166 | 166 | $result[$UBEFleet->group_id] = $UBEFleet->group_id; |
| 167 | 167 | } |
| 168 | 168 | } |
@@ -175,8 +175,8 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | public function ube_get_capacity_attackers() { |
| 177 | 177 | $result = 0; |
| 178 | - foreach($this->_container as $UBEFleet) { |
|
| 179 | - if($UBEFleet->is_attacker) { |
|
| 178 | + foreach ($this->_container as $UBEFleet) { |
|
| 179 | + if ($UBEFleet->is_attacker) { |
|
| 180 | 180 | $result += $UBEFleet->fleet_capacity; |
| 181 | 181 | } |
| 182 | 182 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | public function ube_db_load_from_report_row(array $report_row, UBE $ube) { |
| 192 | 192 | $query = classSupernova::$db->doSelect("SELECT * FROM {{ube_report_fleet}} WHERE `ube_report_id` = {$report_row['ube_report_id']}"); |
| 193 | - while($fleet_row = db_fetch($query)) { |
|
| 193 | + while ($fleet_row = db_fetch($query)) { |
|
| 194 | 194 | $objFleet = new UBEFleet(); |
| 195 | 195 | $objFleet->load_from_report($fleet_row, $ube); |
| 196 | 196 | $this[$objFleet->db_id] = $objFleet; |
@@ -204,20 +204,20 @@ discard block |
||
| 204 | 204 | * @version 2016-02-25 23:42:45 41a4.68 |
| 205 | 205 | */ |
| 206 | 206 | public function ube_prepare_for_next_round($is_simulator) { |
| 207 | - foreach($this->_container as $fleet_id => $UBEFleet) { |
|
| 207 | + foreach ($this->_container as $fleet_id => $UBEFleet) { |
|
| 208 | 208 | $UBEFleet->prepare_for_next_round($is_simulator); |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | // Суммируем данные по атакующим и защитникам |
| 212 | 212 | $this->ube_total[UBE_PLAYER_IS_ATTACKER]->_reset(); |
| 213 | 213 | $this->ube_total[UBE_PLAYER_IS_DEFENDER]->_reset(); |
| 214 | - foreach($this->_container as $fleet_id => $UBEFleet) { |
|
| 214 | + foreach ($this->_container as $fleet_id => $UBEFleet) { |
|
| 215 | 215 | $this->ube_total[$UBEFleet->is_attacker]->add_unit_stats_array($UBEFleet->total_stats); |
| 216 | 216 | } |
| 217 | 217 | //pvar_dump($this->ube_total); |
| 218 | 218 | |
| 219 | 219 | // Высчитываем долю атаки, приходящейся на юнит равную отношению брони юнита к общей броне - крупные цели атакуют чаще |
| 220 | - foreach($this->_container as $fleet_id => $UBEFleet) { |
|
| 220 | + foreach ($this->_container as $fleet_id => $UBEFleet) { |
|
| 221 | 221 | $UBEFleet->calculate_unit_partial_data($this->ube_total[$UBEFleet->is_attacker]); |
| 222 | 222 | } |
| 223 | 223 | } |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | */ |
| 232 | 232 | public function ube_calculate_attack_results(UBE $ube) { |
| 233 | 233 | // Каждый флот атакует все |
| 234 | - foreach($this->_container as $attack_fleet_data) { |
|
| 234 | + foreach ($this->_container as $attack_fleet_data) { |
|
| 235 | 235 | defined('DEBUG_UBE') ? print("Fleet {$attack_fleet_data->db_id} attacks<br /><div style='margin-left: 30px;'>") : false; |
| 236 | 236 | |
| 237 | 237 | $attack_fleet_data->attack_fleets($this, $ube->is_simulator); |
@@ -246,8 +246,8 @@ discard block |
||
| 246 | 246 | * @version 2016-02-25 23:42:45 41a4.68 |
| 247 | 247 | */ |
| 248 | 248 | public function ube_actualize_sides() { |
| 249 | - foreach($this->_container as $UBEFleet) { |
|
| 250 | - if($UBEFleet->get_unit_count() > 0) { |
|
| 249 | + foreach ($this->_container as $UBEFleet) { |
|
| 250 | + if ($UBEFleet->get_unit_count() > 0) { |
|
| 251 | 251 | $this->ube_side_present_at_round_start[$UBEFleet->is_attacker] = 1; |
| 252 | 252 | } |
| 253 | 253 | } |
@@ -260,8 +260,8 @@ discard block |
||
| 260 | 260 | */ |
| 261 | 261 | public function ube_calculate_attack_reapers() { |
| 262 | 262 | $reapers = 0; |
| 263 | - foreach($this->_container as $fleet_id => $UBERoundFleetCombat) { |
|
| 264 | - if($UBERoundFleetCombat->is_attacker == UBE_PLAYER_IS_ATTACKER) { |
|
| 263 | + foreach ($this->_container as $fleet_id => $UBERoundFleetCombat) { |
|
| 264 | + if ($UBERoundFleetCombat->is_attacker == UBE_PLAYER_IS_ATTACKER) { |
|
| 265 | 265 | $reapers += $UBERoundFleetCombat->unit_list->unitCountReapers(); |
| 266 | 266 | } |
| 267 | 267 | } |
@@ -278,10 +278,10 @@ discard block |
||
| 278 | 278 | |
| 279 | 279 | $result = UBE_COMBAT_RESULT_DRAW; |
| 280 | 280 | // Проверяем результат боя |
| 281 | - if($this->ube_get_sides_count() == 0 || $round >= 10) { |
|
| 281 | + if ($this->ube_get_sides_count() == 0 || $round >= 10) { |
|
| 282 | 282 | // Если кого-то не осталось или не осталось обоих - заканчиваем цикл |
| 283 | 283 | $result = UBE_COMBAT_RESULT_DRAW_END; |
| 284 | - } elseif($this->ube_get_sides_count() == 1) { |
|
| 284 | + } elseif ($this->ube_get_sides_count() == 1) { |
|
| 285 | 285 | // Если осталась одна сторона - она и выиграла |
| 286 | 286 | $result = isset($this->ube_side_present_at_round_start[UBE_PLAYER_IS_ATTACKER]) ? UBE_COMBAT_RESULT_WIN : UBE_COMBAT_RESULT_LOSS; |
| 287 | 287 | } |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | * |
| 298 | 298 | */ |
| 299 | 299 | public function ubeInitGetAttackers(Fleet $objFleet, UBEPlayerList $players) { |
| 300 | - if($objFleet->group_id) { |
|
| 300 | + if ($objFleet->group_id) { |
|
| 301 | 301 | $fleets_added = $this->dbLoadWhere("`fleet_group` = {$objFleet->group_id}", DB_SELECT_FOR_UPDATE); |
| 302 | 302 | } else { |
| 303 | 303 | $this->ube_insert_from_Fleet($objFleet); |
@@ -7,7 +7,7 @@ |
||
| 7 | 7 | /** |
| 8 | 8 | * @param UBE $ube |
| 9 | 9 | * |
| 10 | - * @return bool|string |
|
| 10 | + * @return false|string |
|
| 11 | 11 | * |
| 12 | 12 | * @version 2016-02-25 23:42:45 41a4.68 |
| 13 | 13 | */ |
@@ -13,14 +13,14 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | public function sn_ube_report_save($ube) { |
| 15 | 15 | // Если уже есть ИД репорта - значит репорт был взят из таблицы. С таким мы не работаем |
| 16 | - if($ube->get_cypher()) { |
|
| 16 | + if ($ube->get_cypher()) { |
|
| 17 | 17 | return false; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | // Генерируем уникальный секретный ключ и проверяем наличие в базе |
| 21 | 21 | do { |
| 22 | 22 | $ube->report_cypher = sys_random_string(32); |
| 23 | - } while(classSupernova::$db->doSelectFetchArray("SELECT ube_report_cypher FROM {{ube_report}} WHERE ube_report_cypher = '{$ube->report_cypher}' LIMIT 1 FOR UPDATE")); |
|
| 23 | + } while (classSupernova::$db->doSelectFetchArray("SELECT ube_report_cypher FROM {{ube_report}} WHERE ube_report_cypher = '{$ube->report_cypher}' LIMIT 1 FOR UPDATE")); |
|
| 24 | 24 | |
| 25 | 25 | // Инициализация таблицы для пакетной вставки информации |
| 26 | 26 | $sql_perform = array( |
@@ -106,21 +106,21 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | // Сохраняем общую информацию о бое |
| 108 | 108 | classSupernova::$db->doInsertSet(TABLE_UBE_REPORT, array( |
| 109 | - 'ube_report_cypher' => (string)$ube->report_cypher, |
|
| 110 | - 'ube_report_time_combat' => (string)date(FMT_DATE_TIME_SQL, $ube->combat_timestamp), |
|
| 111 | - 'ube_report_time_spent' => (float)$ube->time_spent, |
|
| 112 | - 'ube_report_combat_admin' => (int)$ube->is_admin_in_combat, |
|
| 113 | - 'ube_report_mission_type' => (int)$ube->mission_type_id, |
|
| 114 | - 'ube_report_combat_result' => (int)$ube->combat_result, |
|
| 115 | - 'ube_report_combat_sfr' => (int)$ube->is_small_fleet_recce, |
|
| 116 | - 'ube_report_planet_id' => (int)$ube->ube_planet_info[PLANET_ID], |
|
| 117 | - 'ube_report_planet_name' => (string)$ube->ube_planet_info[PLANET_NAME], |
|
| 118 | - 'ube_report_planet_size' => (int)$ube->ube_planet_info[PLANET_SIZE], |
|
| 119 | - 'ube_report_planet_galaxy' => (int)$ube->ube_planet_info[PLANET_GALAXY], |
|
| 120 | - 'ube_report_planet_system' => (int)$ube->ube_planet_info[PLANET_SYSTEM], |
|
| 121 | - 'ube_report_planet_planet' => (int)$ube->ube_planet_info[PLANET_PLANET], |
|
| 122 | - 'ube_report_planet_planet_type' => (int)$ube->ube_planet_info[PLANET_TYPE], |
|
| 123 | - 'ube_report_capture_result' => (int)$ube->capture_result, |
|
| 109 | + 'ube_report_cypher' => (string) $ube->report_cypher, |
|
| 110 | + 'ube_report_time_combat' => (string) date(FMT_DATE_TIME_SQL, $ube->combat_timestamp), |
|
| 111 | + 'ube_report_time_spent' => (float) $ube->time_spent, |
|
| 112 | + 'ube_report_combat_admin' => (int) $ube->is_admin_in_combat, |
|
| 113 | + 'ube_report_mission_type' => (int) $ube->mission_type_id, |
|
| 114 | + 'ube_report_combat_result' => (int) $ube->combat_result, |
|
| 115 | + 'ube_report_combat_sfr' => (int) $ube->is_small_fleet_recce, |
|
| 116 | + 'ube_report_planet_id' => (int) $ube->ube_planet_info[PLANET_ID], |
|
| 117 | + 'ube_report_planet_name' => (string) $ube->ube_planet_info[PLANET_NAME], |
|
| 118 | + 'ube_report_planet_size' => (int) $ube->ube_planet_info[PLANET_SIZE], |
|
| 119 | + 'ube_report_planet_galaxy' => (int) $ube->ube_planet_info[PLANET_GALAXY], |
|
| 120 | + 'ube_report_planet_system' => (int) $ube->ube_planet_info[PLANET_SYSTEM], |
|
| 121 | + 'ube_report_planet_planet' => (int) $ube->ube_planet_info[PLANET_PLANET], |
|
| 122 | + 'ube_report_planet_planet_type' => (int) $ube->ube_planet_info[PLANET_TYPE], |
|
| 123 | + 'ube_report_capture_result' => (int) $ube->capture_result, |
|
| 124 | 124 | ) |
| 125 | 125 | + $ube->debris->report_generate_array() |
| 126 | 126 | + $ube->moon_calculator->report_generate_array() |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | |
| 130 | 130 | // Сохраняем общую информацию по игрокам |
| 131 | 131 | $player_sides = $ube->players->get_player_sides(); |
| 132 | - foreach($player_sides as $player_id => $player_side) { |
|
| 132 | + foreach ($player_sides as $player_id => $player_side) { |
|
| 133 | 133 | $sql_perform['ube_report_player'][] = array( |
| 134 | 134 | $ube_report_id, |
| 135 | 135 | $player_id, |
@@ -137,14 +137,14 @@ discard block |
||
| 137 | 137 | "'" . db_escape($ube->players[$player_id]->name) . "'", |
| 138 | 138 | $ube->players[$player_id]->getSide() == UBE_PLAYER_IS_ATTACKER ? 1 : 0, |
| 139 | 139 | |
| 140 | - (float)$ube->players[$player_id]->player_bonus->calcBonus(P_ATTACK), |
|
| 141 | - (float)$ube->players[$player_id]->player_bonus->calcBonus(P_SHIELD), |
|
| 142 | - (float)$ube->players[$player_id]->player_bonus->calcBonus(P_ARMOR), |
|
| 140 | + (float) $ube->players[$player_id]->player_bonus->calcBonus(P_ATTACK), |
|
| 141 | + (float) $ube->players[$player_id]->player_bonus->calcBonus(P_SHIELD), |
|
| 142 | + (float) $ube->players[$player_id]->player_bonus->calcBonus(P_ARMOR), |
|
| 143 | 143 | ); |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | // Всякая информация по флотам |
| 147 | - foreach($ube->fleet_list->_container as $fleet_id => $UBEFleet) { |
|
| 147 | + foreach ($ube->fleet_list->_container as $fleet_id => $UBEFleet) { |
|
| 148 | 148 | // Сохраняем общую информацию по флотам |
| 149 | 149 | $sql_perform['ube_report_fleet'][] = $UBEFleet->sql_generate_array($ube_report_id); |
| 150 | 150 | |
@@ -160,9 +160,9 @@ discard block |
||
| 160 | 160 | |
| 161 | 161 | // Пакетная вставка данных |
| 162 | 162 | // First row is a list of field names |
| 163 | - foreach($sql_perform as $table_name => &$table_data) { |
|
| 163 | + foreach ($sql_perform as $table_name => &$table_data) { |
|
| 164 | 164 | // If only field names in this table - doing nothing |
| 165 | - if(count($table_data) < 2) { |
|
| 165 | + if (count($table_data) < 2) { |
|
| 166 | 166 | continue; |
| 167 | 167 | } |
| 168 | 168 | // Picking up field names |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | $report_cypher = db_escape($report_cypher); |
| 186 | 186 | |
| 187 | 187 | $report_row = classSupernova::$db->doSelectFetchArray("SELECT * FROM {{ube_report}} WHERE ube_report_cypher = '{$report_cypher}' LIMIT 1"); |
| 188 | - if(!$report_row) { |
|
| 188 | + if (!$report_row) { |
|
| 189 | 189 | return UBE_REPORT_NOT_FOUND; |
| 190 | 190 | } |
| 191 | 191 | |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @param $template_result |
| 202 | 202 | */ |
| 203 | 203 | public function sn_ube_report_generate(UBE $ube, &$template_result) { |
| 204 | - if(!is_object($ube)) { |
|
| 204 | + if (!is_object($ube)) { |
|
| 205 | 205 | return; |
| 206 | 206 | } |
| 207 | 207 | |
@@ -216,15 +216,15 @@ discard block |
||
| 216 | 216 | |
| 217 | 217 | // Координаты, тип и название планеты - если есть |
| 218 | 218 | //R $planet_owner_id = $combat_data[UBE_FLEETS][0][UBE_OWNER]; |
| 219 | - if(isset($ube->ube_planet_info)) { |
|
| 219 | + if (isset($ube->ube_planet_info)) { |
|
| 220 | 220 | $template_result += $ube->ube_planet_info; |
| 221 | 221 | $template_result[PLANET_NAME] = str_replace(' ', ' ', htmlentities($template_result[PLANET_NAME], ENT_COMPAT, 'UTF-8')); |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | // Обломки |
| 225 | 225 | $debris = array(); |
| 226 | - foreach(array(RES_METAL, RES_CRYSTAL) as $resource_id) { |
|
| 227 | - if($resource_amount = $ube->debris->debris_get_resource($resource_id)) { |
|
| 226 | + foreach (array(RES_METAL, RES_CRYSTAL) as $resource_id) { |
|
| 227 | + if ($resource_amount = $ube->debris->debris_get_resource($resource_id)) { |
|
| 228 | 228 | $debris[] = array( |
| 229 | 229 | 'NAME' => classLocale::$lang['tech'][$resource_id], |
| 230 | 230 | 'AMOUNT' => pretty_number($resource_amount), |
@@ -151,6 +151,9 @@ |
||
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | |
| 154 | + /** |
|
| 155 | + * @param integer $user_id |
|
| 156 | + */ |
|
| 154 | 157 | public function __construct($user_id) { |
| 155 | 158 | $this->user_change($user_id); |
| 156 | 159 | } |
@@ -122,8 +122,8 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | $update_cache = false; |
| 124 | 124 | |
| 125 | - if(!empty($this->to_write)) { |
|
| 126 | - foreach($this->to_write as $key => &$value) { |
|
| 125 | + if (!empty($this->to_write)) { |
|
| 126 | + foreach ($this->to_write as $key => &$value) { |
|
| 127 | 127 | $value = is_array($this->data[$key]) ? serialize($this->data[$key]) : $this->data[$key]; // Сериализация для массивов при сохранении в БД |
| 128 | 128 | $value = array($this->user_id, $key, $value); |
| 129 | 129 | } |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | $update_cache = true; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if(!empty($this->to_delete)) { |
|
| 145 | - foreach($this->to_delete as $key => &$value) { |
|
| 146 | - $value = is_string($key) ? "'". db_escape($key) . "'" : $key; |
|
| 144 | + if (!empty($this->to_delete)) { |
|
| 145 | + foreach ($this->to_delete as $key => &$value) { |
|
| 146 | + $value = is_string($key) ? "'" . db_escape($key) . "'" : $key; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | classSupernova::$db->doDeleteDanger( |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | $update_cache = true; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - if($update_cache) { |
|
| 163 | + if ($update_cache) { |
|
| 164 | 164 | $field_name = $this->cached_name(); |
| 165 | 165 | classSupernova::$cache->$field_name = $this->data; |
| 166 | 166 | } |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | protected function load() { |
| 186 | - if($this->loaded) { |
|
| 186 | + if ($this->loaded) { |
|
| 187 | 187 | return; |
| 188 | 188 | } |
| 189 | 189 | |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | $this->to_write = array(); |
| 192 | 192 | $this->to_delete = array(); |
| 193 | 193 | |
| 194 | - if(!$this->user_id) { |
|
| 194 | + if (!$this->user_id) { |
|
| 195 | 195 | $this->loaded = true; |
| 196 | 196 | return; |
| 197 | 197 | } |
@@ -199,13 +199,13 @@ discard block |
||
| 199 | 199 | $field_name = $this->cached_name(); |
| 200 | 200 | $a_data = classSupernova::$cache->$field_name; |
| 201 | 201 | |
| 202 | - if(!empty($a_data)) { |
|
| 202 | + if (!empty($a_data)) { |
|
| 203 | 203 | $this->data = array_replace_recursive($this->data, $a_data); |
| 204 | 204 | return; |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | $query = classSupernova::$db->doSelect("SELECT * FROM `{{player_options}}` WHERE `player_id` = {$this->user_id} FOR UPDATE"); |
| 208 | - while($row = db_fetch($query)) { |
|
| 208 | + while ($row = db_fetch($query)) { |
|
| 209 | 209 | // $this->data[$row['option_id']] = $row['value']; |
| 210 | 210 | $this->data[$row['option_id']] = is_string($row['value']) && ($temp = unserialize($row['value'])) !== false ? $temp : $row['value']; // Десериализация |
| 211 | 211 | } |
@@ -290,14 +290,14 @@ discard block |
||
| 290 | 290 | // Если в массиве индекса только один элемент - значит это просто индекс |
| 291 | 291 | is_array($option_id) && count($option_id) == 1 ? $option_id = reset($option_id) : false; |
| 292 | 292 | |
| 293 | - if(!isset($this->data[is_array($option_id) ? reset($option_id) : $option_id])) { |
|
| 293 | + if (!isset($this->data[is_array($option_id) ? reset($option_id) : $option_id])) { |
|
| 294 | 294 | $this->load(); |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - if(is_array($option_id)) { |
|
| 297 | + if (is_array($option_id)) { |
|
| 298 | 298 | $result = $this->data; |
| 299 | - foreach($option_id as $sub_key) { |
|
| 300 | - if(!isset($result) || !isset($result[$sub_key])) { |
|
| 299 | + foreach ($option_id as $sub_key) { |
|
| 300 | + if (!isset($result) || !isset($result[$sub_key])) { |
|
| 301 | 301 | $result = null; |
| 302 | 302 | break; |
| 303 | 303 | } |
@@ -315,12 +315,12 @@ discard block |
||
| 315 | 315 | * @param null|mixed $value |
| 316 | 316 | */ |
| 317 | 317 | public function __set($option, $value = null) { |
| 318 | - if(empty($option) || !$this->user_id) { |
|
| 318 | + if (empty($option) || !$this->user_id) { |
|
| 319 | 319 | return; |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | // Если в массиве индекса только один элемент - значит это просто индекс |
| 323 | - if(is_array($option) && count($option) == 1) { |
|
| 323 | + if (is_array($option) && count($option) == 1) { |
|
| 324 | 324 | // Разворачиваем его в индекс |
| 325 | 325 | $option = array(reset($option) => $value); |
| 326 | 326 | unset($value); |
@@ -329,13 +329,13 @@ discard block |
||
| 329 | 329 | |
| 330 | 330 | $to_write = array(); |
| 331 | 331 | // Адресация многомерного массива через массив индексов в $option |
| 332 | - if(is_array($option) && isset($value)) { |
|
| 332 | + if (is_array($option) && isset($value)) { |
|
| 333 | 333 | $a_data = &$this->data; |
| 334 | - foreach($option as $option_id) { |
|
| 334 | + foreach ($option as $option_id) { |
|
| 335 | 335 | !is_array($a_data[$option_id]) ? $a_data[$option_id] = array() : false; |
| 336 | 336 | $a_data = &$a_data[$option_id]; |
| 337 | 337 | } |
| 338 | - if($a_data != $value) { |
|
| 338 | + if ($a_data != $value) { |
|
| 339 | 339 | $a_data = $value; |
| 340 | 340 | $to_write[reset($option)] = null; |
| 341 | 341 | } |
@@ -343,10 +343,10 @@ discard block |
||
| 343 | 343 | // Пакетная запись из массива ключ -> значение |
| 344 | 344 | !is_array($option) ? $option = array($option => $value) : false; |
| 345 | 345 | |
| 346 | - foreach($option as $option_id => $option_value) { |
|
| 347 | - if($this->data[$option_id] !== $option_value) { |
|
| 346 | + foreach ($option as $option_id => $option_value) { |
|
| 347 | + if ($this->data[$option_id] !== $option_value) { |
|
| 348 | 348 | // TODO - вынести отдельно в обработчик |
| 349 | - if($option_id == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON && $option_value == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON_HIDDEN) { |
|
| 349 | + if ($option_id == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON && $option_value == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON_HIDDEN) { |
|
| 350 | 350 | sn_setcookie(SN_COOKIE . '_menu_hidden', '0', time() - PERIOD_WEEK, SN_ROOT_RELATIVE); |
| 351 | 351 | } |
| 352 | 352 | |
@@ -356,11 +356,11 @@ discard block |
||
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | - if(!empty($to_write)) { |
|
| 359 | + if (!empty($to_write)) { |
|
| 360 | 360 | $field_name = $this->cached_name(); |
| 361 | 361 | classSupernova::$cache->$field_name = $this->data; |
| 362 | 362 | |
| 363 | - foreach($to_write as $option_id => &$option_value) { |
|
| 363 | + foreach ($to_write as $option_id => &$option_value) { |
|
| 364 | 364 | $option_value = is_array($this->data[$option_id]) ? serialize($this->data[$option_id]) : $this->data[$option_id]; // Сериализация для массивов при сохранении в БД |
| 365 | 365 | $option_value = array($this->user_id, $option_id, $option_value); |
| 366 | 366 | } |
@@ -376,26 +376,26 @@ discard block |
||
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | protected function load() { |
| 379 | - if($this->loaded) { |
|
| 379 | + if ($this->loaded) { |
|
| 380 | 380 | return; |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | $this->data = $this->defaults; |
| 384 | 384 | |
| 385 | - if(!$this->user_id) { |
|
| 385 | + if (!$this->user_id) { |
|
| 386 | 386 | return; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | $field_name = $this->cached_name(); |
| 390 | 390 | $a_data = classSupernova::$cache->$field_name; |
| 391 | 391 | |
| 392 | - if(!empty($a_data)) { |
|
| 392 | + if (!empty($a_data)) { |
|
| 393 | 393 | $this->data = array_replace($this->data, $a_data); |
| 394 | 394 | return; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | $query = classSupernova::$db->doSelect("SELECT * FROM `{{player_options}}` WHERE `player_id` = {$this->user_id} FOR UPDATE"); |
| 398 | - while($row = db_fetch($query)) { |
|
| 398 | + while ($row = db_fetch($query)) { |
|
| 399 | 399 | // $this->data[$row['option_id']] = $row['value']; |
| 400 | 400 | $this->data[$row['option_id']] = is_string($row['value']) && ($temp = unserialize($row['value'])) !== false ? $temp : $row['value']; // Десериализация |
| 401 | 401 | } |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | return $this->__get($offset); |
| 412 | 412 | } |
| 413 | 413 | public function offsetSet($offset, $value) { |
| 414 | - if(!is_null($offset)) { |
|
| 414 | + if (!is_null($offset)) { |
|
| 415 | 415 | // $this->data[$offset] = $value; |
| 416 | 416 | $this->__set($offset, $value); |
| 417 | 417 | } else { |