| @@ -18,6 +18,11 @@ discard block | ||
| 18 | 18 | |
| 19 | 19 | // TODO - НЕ ОБЯЗАТЕЛЬНО ОТПРАВЛЯТЬ ЧЕРЕЗ ЕМЕЙЛ! ЕСЛИ ЭТО ФЕЙСБУЧЕК ИЛИ ВКШЕЧКА - МОЖНО ЧЕРЕЗ ЛС ПИСАТЬ!! | 
| 20 | 20 | // TODO - OK 4.6 | 
| 21 | + | |
| 22 | + /** | |
| 23 | + * @param integer $confirmation_type_safe | |
| 24 | + * @param string $email_unsafe | |
| 25 | + */ | |
| 21 | 26 |    public function db_confirmation_get_latest_by_type_and_email($confirmation_type_safe, $email_unsafe) { | 
| 22 | 27 | $email_safe = $this->db->db_escape($email_unsafe); | 
| 23 | 28 | |
| @@ -26,12 +31,21 @@ discard block | ||
| 26 | 31 |            `type` = {$confirmation_type_safe} AND `email` = '{$email_safe}' ORDER BY create_time DESC LIMIT 1;", true); | 
| 27 | 32 | } | 
| 28 | 33 | // TODO - OK 4.6 | 
| 34 | + | |
| 35 | + /** | |
| 36 | + * @param integer $confirmation_type_safe | |
| 37 | + */ | |
| 29 | 38 |    public function db_confirmation_delete_by_type_and_email($confirmation_type_safe, $email_unsafe) { | 
| 30 | 39 | $email_safe = $this->db->db_escape($email_unsafe); | 
| 31 | 40 | |
| 32 | 41 |      return $this->db->doquery("DELETE FROM {{confirmations}} WHERE `type` = {$confirmation_type_safe} AND `email` = '{$email_safe}'"); | 
| 33 | 42 | } | 
| 34 | 43 | // TODO - OK 4.6 | 
| 44 | + | |
| 45 | + /** | |
| 46 | + * @param integer $confirmation_type_safe | |
| 47 | + * @param string $email_unsafe | |
| 48 | + */ | |
| 35 | 49 |    public function db_confirmation_get_unique_code_by_type_and_email($confirmation_type_safe, $email_unsafe) { | 
| 36 | 50 | $email_safe = $this->db->db_escape($email_unsafe); | 
| 37 | 51 | |
| @@ -50,6 +64,11 @@ discard block | ||
| 50 | 64 | return $confirm_code_unsafe; | 
| 51 | 65 | } | 
| 52 | 66 | // TODO - OK 4.6 | 
| 67 | + | |
| 68 | + /** | |
| 69 | + * @param integer $confirmation_type_safe | |
| 70 | + * @param string $confirmation_code_unsafe | |
| 71 | + */ | |
| 53 | 72 |    public function db_confirmation_get_by_type_and_code($confirmation_type_safe, $confirmation_code_unsafe) { | 
| 54 | 73 | $confirmation_code_safe = $this->db->db_escape($confirmation_code_unsafe); | 
| 55 | 74 | |
| @@ -41,7 +41,7 @@ | ||
| 41 | 41 |        // $query = static::$db->doquery("SELECT `id` FROM {{confirmations}} WHERE `code` = '{$confirm_code_safe}' AND `type` = {$confirmation_type_safe} FOR UPDATE", true); | 
| 42 | 42 | // Тип не нужен для проверки - код подтверждения должен быть уникален от слова "совсем" | 
| 43 | 43 |        $query = $this->db->doquery("SELECT `id` FROM {{confirmations}} WHERE `code` = '{$confirm_code_safe}' FOR UPDATE", true); | 
| 44 | - } while($query); | |
| 44 | + } while ($query); | |
| 45 | 45 | |
| 46 | 46 | $this->db->doquery( | 
| 47 | 47 |        "REPLACE INTO {{confirmations}} | 
| @@ -702,7 +702,7 @@ discard block | ||
| 702 | 702 | * Рассчёт бонуса ММ | 
| 703 | 703 | * | 
| 704 | 704 | * @param $dark_matter | 
| 705 | - * @param bool|true $direct | |
| 705 | + * @param boolean $direct | |
| 706 | 706 | * @param bool|false $return_bonus | 
| 707 | 707 | * | 
| 708 | 708 | * @return float|int | 
| @@ -738,6 +738,12 @@ discard block | ||
| 738 | 738 | |
| 739 | 739 | // Дополнительная ре-трансляция адреса, если в каком-то случае платежная система ожидает нелогичный ответ | 
| 740 | 740 | // Пример: иксолла при неправильно заданном пользователе в ордере ожидает НЕПРАВИЛЬНЫЙ_ОРДЕР, а не НЕПРАВИЛЬНЫЙ_ПОЛЬЗОВАТЕЛЬ | 
| 741 | + | |
| 742 | + /** | |
| 743 | + * @param integer $error_code | |
| 744 | + * | |
| 745 | + * @return integer|null | |
| 746 | + */ | |
| 741 | 747 |    function retranslate_error($error_code, $options = array()) { | 
| 742 | 748 | return isset($options['retranslate_error'][$error_code]) ? $options['retranslate_error'][$error_code] : $error_code; | 
| 743 | 749 | } | 
| @@ -448,7 +448,7 @@ discard block | ||
| 448 | 448 |    public function compile_request($request) { | 
| 449 | 449 | global $user; | 
| 450 | 450 | |
| 451 | -    if(!(classSupernova::$auth->account instanceof Account)) { | |
| 451 | +    if (!(classSupernova::$auth->account instanceof Account)) { | |
| 452 | 452 | // TODO - throw new Exception(lang['pay_msg_mm_request_amount_invalid'], SN_PAYMENT_REQUEST_ERROR_UNIT_AMOUNT); | 
| 453 | 453 | } | 
| 454 | 454 | $this->account = classSupernova::$auth->account; | 
| @@ -469,15 +469,15 @@ discard block | ||
| 469 | 469 | $this->payment_currency = classSupernova::$config->payment_currency_default; | 
| 470 | 470 | $this->payment_amount = self::currency_convert($this->payment_dark_matter_paid, 'MM_', $this->payment_currency); | 
| 471 | 471 | |
| 472 | -    if(empty($this->payment_external_currency) && !empty($this->config['currency'])) { | |
| 472 | +    if (empty($this->payment_external_currency) && !empty($this->config['currency'])) { | |
| 473 | 473 | $this->payment_external_currency = $this->config['currency']; | 
| 474 | 474 | } | 
| 475 | -    if(empty($this->payment_external_currency)) { | |
| 475 | +    if (empty($this->payment_external_currency)) { | |
| 476 | 476 | throw new Exception(classLocale::$lang['pay_error_internal_no_external_currency_set'], SN_PAYMENT_ERROR_INTERNAL_NO_EXTERNAL_CURRENCY_SET); | 
| 477 | 477 | } | 
| 478 | 478 | |
| 479 | 479 | $this->payment_external_amount = self::currency_convert($this->payment_dark_matter_paid, 'MM_', $this->payment_external_currency); | 
| 480 | -    if($this->payment_external_amount < 0.01) { | |
| 480 | +    if ($this->payment_external_amount < 0.01) { | |
| 481 | 481 | throw new Exception(classLocale::$lang['pay_msg_mm_request_amount_invalid'], SN_PAYMENT_REQUEST_ERROR_UNIT_AMOUNT); | 
| 482 | 482 | } | 
| 483 | 483 | |
| @@ -486,7 +486,7 @@ discard block | ||
| 486 | 486 | $this->generate_description(); | 
| 487 | 487 | |
| 488 | 488 | $this->db_insert(); | 
| 489 | -    if(!$this->is_exists) { | |
| 489 | +    if (!$this->is_exists) { | |
| 490 | 490 | throw new Exception(classLocale::$lang['pay_msg_request_error_db_payment_create'], SN_PAYMENT_REQUEST_DB_ERROR_PAYMENT_CREATE); | 
| 491 | 491 | } | 
| 492 | 492 | } | 
| @@ -498,26 +498,26 @@ discard block | ||
| 498 | 498 | * @throws Exception | 
| 499 | 499 | */ | 
| 500 | 500 |    protected function payment_request_process($options = array()) { | 
| 501 | -    if(!$this->manifest['active']) { | |
| 501 | +    if (!$this->manifest['active']) { | |
| 502 | 502 | throw new Exception(classLocale::$lang['pay_msg_module_disabled'], SN_MODULE_DISABLED); | 
| 503 | 503 | } | 
| 504 | 504 | |
| 505 | 505 | // Если есть payment_id - загружаем под него данные | 
| 506 | -    if(!empty($this->payment_params['payment_id'])) { | |
| 506 | +    if (!empty($this->payment_params['payment_id'])) { | |
| 507 | 507 | $this->request_payment_id = sys_get_param_id($this->payment_params['payment_id']); | 
| 508 | -      if(!$this->request_payment_id) { | |
| 508 | +      if (!$this->request_payment_id) { | |
| 509 | 509 | throw new Exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG); | 
| 510 | 510 | } | 
| 511 | 511 | |
| 512 | -      if(!$this->db_get_by_id($this->request_payment_id)) { | |
| 512 | +      if (!$this->db_get_by_id($this->request_payment_id)) { | |
| 513 | 513 | throw new Exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG); | 
| 514 | 514 | } | 
| 515 | 515 | |
| 516 | 516 | // Проверяем - был ли этот платеж обработан? | 
| 517 | 517 | // TODO - Статусы бывают разные. Нужен спецфлаг payment_processed | 
| 518 | -      if($this->payment_status != PAYMENT_STATUS_NONE) { | |
| 518 | +      if ($this->payment_status != PAYMENT_STATUS_NONE) { | |
| 519 | 519 | sn_db_transaction_rollback(); | 
| 520 | - sys_redirect(SN_ROOT_VIRTUAL . 'metamatter.php?payment_id=' . $this->payment_id); | |
| 520 | + sys_redirect(SN_ROOT_VIRTUAL.'metamatter.php?payment_id='.$this->payment_id); | |
| 521 | 521 | die(); | 
| 522 | 522 | } | 
| 523 | 523 | } | 
| @@ -525,89 +525,89 @@ discard block | ||
| 525 | 525 | // Пытаемся получить из запроса ИД аккаунта | 
| 526 | 526 | $request_account_id = !empty($this->payment_params['account_id']) ? sys_get_param_id($this->payment_params['account_id']) : 0; | 
| 527 | 527 | // Если в запросе нет ИД аккаунта - пытаемся использовать payment_account_id | 
| 528 | -    if(empty($request_account_id) && !empty($this->payment_account_id)) { | |
| 528 | +    if (empty($request_account_id) && !empty($this->payment_account_id)) { | |
| 529 | 529 | $request_account_id = $this->payment_account_id; | 
| 530 | 530 | } | 
| 531 | 531 | // Если теперь у нас нету ИД аккаунта ни в запросе, ни в записи таблицы - можно паниковать | 
| 532 | -    if(empty($request_account_id)) { | |
| 532 | +    if (empty($request_account_id)) { | |
| 533 | 533 | // TODO - аккаунт | 
| 534 | 534 | throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); | 
| 535 | 535 | } | 
| 536 | 536 | // Если нет записи в таблице - тогда берем payment_account_id из запроса | 
| 537 | -    if(empty($this->payment_account_id)) { | |
| 537 | +    if (empty($this->payment_account_id)) { | |
| 538 | 538 | $this->payment_account_id = $request_account_id; | 
| 539 | 539 | } | 
| 540 | 540 | // Если у нас отличаются ИД аккаунта в запросе и ИД аккаунта в записи - тоже можно паниковать | 
| 541 | -    if($this->payment_account_id != $request_account_id) { | |
| 541 | +    if ($this->payment_account_id != $request_account_id) { | |
| 542 | 542 | // TODO - Поменять сообщение об ошибке | 
| 543 | 543 | throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); | 
| 544 | 544 | } | 
| 545 | 545 | // Проверяем существование аккаунта с данным ИД | 
| 546 | -    if(!$this->account->db_get_by_id($this->payment_account_id)) { | |
| 547 | - throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'] . ' ID ' . $this->payment_account_id, $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); | |
| 546 | +    if (!$this->account->db_get_by_id($this->payment_account_id)) { | |
| 547 | + throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'].' ID '.$this->payment_account_id, $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); | |
| 548 | 548 | } | 
| 549 | 549 | |
| 550 | 550 | // TODO Проверка на сервер_ид - как бы и не нужна, наверное? | 
| 551 | -    if(!empty($this->payment_params['server_id'])) { | |
| 551 | +    if (!empty($this->payment_params['server_id'])) { | |
| 552 | 552 | $this->request_server_id = sys_get_param_str($this->payment_params['server_id']); | 
| 553 | -      if(SN_ROOT_VIRTUAL != $this->request_server_id) { | |
| 554 | -        throw new Exception(classLocale::$lang['pay_msg_request_server_wrong'] . " {$this->request_server_id} вместо " . SN_ROOT_VIRTUAL, SN_PAYMENT_REQUEST_SERVER_WRONG); | |
| 553 | +      if (SN_ROOT_VIRTUAL != $this->request_server_id) { | |
| 554 | +        throw new Exception(classLocale::$lang['pay_msg_request_server_wrong']." {$this->request_server_id} вместо ".SN_ROOT_VIRTUAL, SN_PAYMENT_REQUEST_SERVER_WRONG); | |
| 555 | 555 | } | 
| 556 | 556 | } | 
| 557 | 557 | |
| 558 | 558 | // Сверка количества оплаченной ММ с учётом бонусов | 
| 559 | -    if(!empty($this->payment_params['payment_dark_matter_gained'])) { | |
| 559 | +    if (!empty($this->payment_params['payment_dark_matter_gained'])) { | |
| 560 | 560 | $request_mm_amount = sys_get_param_id($this->payment_params['payment_dark_matter_gained']); | 
| 561 | -      if($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) { | |
| 562 | -        throw new Exception(classLocale::$lang['pay_msg_mm_request_amount_invalid'] . " пришло {$request_mm_amount} ММ вместо {$this->payment_dark_matter_gained} ММ", SN_PAYMENT_REQUEST_MM_AMOUNT_INVALID); | |
| 561 | +      if ($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) { | |
| 562 | +        throw new Exception(classLocale::$lang['pay_msg_mm_request_amount_invalid']." пришло {$request_mm_amount} ММ вместо {$this->payment_dark_matter_gained} ММ", SN_PAYMENT_REQUEST_MM_AMOUNT_INVALID); | |
| 563 | 563 | } | 
| 564 | 564 | empty($this->payment_dark_matter_gained) ? $this->payment_dark_matter_gained = $request_mm_amount : false; | 
| 565 | 565 | } | 
| 566 | -    if(empty($this->payment_dark_matter_paid)) { | |
| 566 | +    if (empty($this->payment_dark_matter_paid)) { | |
| 567 | 567 | // TODO - обратный расчёт из gained | 
| 568 | 568 | } | 
| 569 | 569 | |
| 570 | 570 | // Проверка наличия внешнего ИД платежа | 
| 571 | -    if(!empty($this->payment_params['payment_external_id'])) { | |
| 571 | +    if (!empty($this->payment_params['payment_external_id'])) { | |
| 572 | 572 | $request_payment_external_id = sys_get_param_id($this->payment_params['payment_external_id']); | 
| 573 | -      if(empty($request_payment_external_id)) { | |
| 573 | +      if (empty($request_payment_external_id)) { | |
| 574 | 574 | throw new exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG); | 
| 575 | -      } elseif(!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) { | |
| 575 | +      } elseif (!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) { | |
| 576 | 576 | // TODO - Может быть поменять сообщение | 
| 577 | 577 | throw new exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG); | 
| 578 | 578 | } | 
| 579 | 579 | $this->payment_external_id = $request_payment_external_id; | 
| 580 | 580 | } | 
| 581 | 581 | // Сверка суммы, запрошенной СН к оплате | 
| 582 | -    if(!empty($this->payment_params['payment_external_money'])) { | |
| 582 | +    if (!empty($this->payment_params['payment_external_money'])) { | |
| 583 | 583 | $request_money_out = sys_get_param_float($this->payment_params['payment_external_money']); | 
| 584 | -      if($request_money_out != $this->payment_external_amount && $this->is_loaded) { | |
| 585 | -        throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid'] . " пришло {$request_money_out} денег вместо {$this->payment_external_amount} денег", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); | |
| 584 | +      if ($request_money_out != $this->payment_external_amount && $this->is_loaded) { | |
| 585 | +        throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid']." пришло {$request_money_out} денег вместо {$this->payment_external_amount} денег", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); | |
| 586 | 586 | } | 
| 587 | 587 | empty($this->payment_external_amount) ? $this->payment_external_amount = $request_money_out : false; | 
| 588 | 588 | } | 
| 589 | 589 | // Заполняем поле валюты платёжной системы | 
| 590 | -    if(!empty($this->payment_params['payment_external_currency'])) { | |
| 590 | +    if (!empty($this->payment_params['payment_external_currency'])) { | |
| 591 | 591 | $this->payment_external_currency = sys_get_param_str($this->payment_params['payment_external_currency']); | 
| 592 | -      if(empty($this->payment_external_currency)) { | |
| 592 | +      if (empty($this->payment_external_currency)) { | |
| 593 | 593 | // TODO - поменять сообщение | 
| 594 | -        throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid'] . " {$this->payment_external_currency}", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); | |
| 594 | +        throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid']." {$this->payment_external_currency}", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); | |
| 595 | 595 | } | 
| 596 | 596 | } | 
| 597 | -    if(empty($this->payment_external_currency)) { | |
| 597 | +    if (empty($this->payment_external_currency)) { | |
| 598 | 598 | $this->payment_external_currency = $this->config['currency']; | 
| 599 | 599 | } | 
| 600 | 600 | |
| 601 | 601 | // Заполнение внутренней суммы и валюты из внешних данных | 
| 602 | -    if(empty($this->payment_currency)) { | |
| 602 | +    if (empty($this->payment_currency)) { | |
| 603 | 603 | $this->payment_currency = classSupernova::$config->payment_currency_default; | 
| 604 | 604 | } | 
| 605 | -    if(empty($this->payment_amount) && !empty($this->payment_external_currency)) { | |
| 605 | +    if (empty($this->payment_amount) && !empty($this->payment_external_currency)) { | |
| 606 | 606 | $this->payment_amount = self::currency_convert($this->payment_external_amount, $this->payment_external_currency, $this->payment_currency); | 
| 607 | 607 | } | 
| 608 | 608 | |
| 609 | 609 | // TODO - Тестовый режим | 
| 610 | -    if(!empty($this->payment_params['test'])) { | |
| 610 | +    if (!empty($this->payment_params['test'])) { | |
| 611 | 611 | $this->payment_test = $this->config['test'] || sys_get_param_int($this->payment_params['test']); | 
| 612 | 612 | } | 
| 613 | 613 | |
| @@ -634,21 +634,21 @@ discard block | ||
| 634 | 634 | sn_db_transaction_start(); | 
| 635 | 635 |      try { | 
| 636 | 636 | $response = $this->payment_request_process(); | 
| 637 | -    } catch(Exception $e) { | |
| 637 | +    } catch (Exception $e) { | |
| 638 | 638 | $response['result'] = $e->getCode(); | 
| 639 | 639 | $response['message'] = $e->getMessage(); | 
| 640 | 640 | } | 
| 641 | 641 | |
| 642 | -    if($response['result'] == SN_PAYMENT_REQUEST_OK) { | |
| 642 | +    if ($response['result'] == SN_PAYMENT_REQUEST_OK) { | |
| 643 | 643 | sn_db_transaction_commit(); | 
| 644 | -      classSupernova::$debug->warning('Результат операции: код ' . $response['result'] . ' сообщение "' . $response['message'] . '"', 'Успешный платёж', LOG_INFO_PAYMENT); | |
| 644 | +      classSupernova::$debug->warning('Результат операции: код '.$response['result'].' сообщение "'.$response['message'].'"', 'Успешный платёж', LOG_INFO_PAYMENT); | |
| 645 | 645 |      } else { | 
| 646 | 646 | sn_db_transaction_rollback(); | 
| 647 | -      classSupernova::$debug->warning('Результат операции: код ' . $response['result'] . ' сообщение "' . $response['message'] . '"', 'Ошибка платежа', LOG_INFO_PAYMENT, true); | |
| 647 | +      classSupernova::$debug->warning('Результат операции: код '.$response['result'].' сообщение "'.$response['message'].'"', 'Ошибка платежа', LOG_INFO_PAYMENT, true); | |
| 648 | 648 | } | 
| 649 | 649 | |
| 650 | 650 | // Переводим код результата из СН в код платежной системы | 
| 651 | -    if(is_array($this->result_translations) && !empty($this->result_translations)) { | |
| 651 | +    if (is_array($this->result_translations) && !empty($this->result_translations)) { | |
| 652 | 652 | $response['result'] = isset($this->result_translations[$response['result']]) ? $this->result_translations[$response['result']] : $this->result_translations[SN_PAYMENT_REQUEST_UNDEFINED_ERROR]; | 
| 653 | 653 | } | 
| 654 | 654 | |
| @@ -671,7 +671,7 @@ discard block | ||
| 671 | 671 | $currency_from = strtolower($currency_from); | 
| 672 | 672 | $currency_to = strtolower($currency_to); | 
| 673 | 673 | |
| 674 | -    if($currency_from != $currency_to) { | |
| 674 | +    if ($currency_from != $currency_to) { | |
| 675 | 675 | $exchange_from = get_exchange_rate($currency_from); | 
| 676 | 676 | $exchange_to = get_exchange_rate($currency_to); | 
| 677 | 677 | |
| @@ -695,10 +695,10 @@ discard block | ||
| 695 | 695 |    public static function bonus_calculate($dark_matter, $direct = true, $return_bonus = false) { | 
| 696 | 696 | $bonus = 0; | 
| 697 | 697 | $dark_matter_new = $dark_matter; | 
| 698 | -    if(!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) { | |
| 699 | -      if($direct) { | |
| 700 | -        foreach(self::$bonus_table as $dm_for_bonus => $multiplier) { | |
| 701 | -          if($dm_for_bonus <= $dark_matter) { | |
| 698 | +    if (!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) { | |
| 699 | +      if ($direct) { | |
| 700 | +        foreach (self::$bonus_table as $dm_for_bonus => $multiplier) { | |
| 701 | +          if ($dm_for_bonus <= $dark_matter) { | |
| 702 | 702 | $dark_matter_new = $dark_matter * (1 + $multiplier); | 
| 703 | 703 | $bonus = $multiplier; | 
| 704 | 704 |            } else { | 
| @@ -706,9 +706,9 @@ discard block | ||
| 706 | 706 | } | 
| 707 | 707 | } | 
| 708 | 708 |        } else { | 
| 709 | -        foreach(self::$bonus_table as $dm_for_bonus => $multiplier) { | |
| 709 | +        foreach (self::$bonus_table as $dm_for_bonus => $multiplier) { | |
| 710 | 710 | $temp = $dm_for_bonus * (1 + $multiplier); | 
| 711 | -          if($dark_matter >= $temp) { | |
| 711 | +          if ($dark_matter >= $temp) { | |
| 712 | 712 | $dark_matter_new = round($dark_matter / (1 + $multiplier)); | 
| 713 | 713 | $bonus = $multiplier; | 
| 714 | 714 |            } else { | 
| @@ -761,7 +761,7 @@ discard block | ||
| 761 | 761 | 'payment_external_lots' => $this->payment_dark_matter_paid / get_mm_cost(), | 
| 762 | 762 | ); | 
| 763 | 763 | |
| 764 | -    if($this->payment_id) { | |
| 764 | +    if ($this->payment_id) { | |
| 765 | 765 | $payment['payment_id'] = $this->payment_id; | 
| 766 | 766 |        classSupernova::$gc->db->doReplaceSet('payment', $payment); | 
| 767 | 767 |      } else { | 
| @@ -773,12 +773,12 @@ discard block | ||
| 773 | 773 | |
| 774 | 774 | |
| 775 | 775 |    public function payment_adjust_mm_new() { | 
| 776 | -    if(!$this->payment_test) { | |
| 776 | +    if (!$this->payment_test) { | |
| 777 | 777 | // Not a test payment. Adding DM to account | 
| 778 | 778 | $this->account = new Account($this->db); | 
| 779 | 779 | $this->account->db_get_by_id($this->payment_account_id); | 
| 780 | 780 | $result = $this->account->metamatter_change(RPG_PURCHASE, $this->payment_dark_matter_gained, $this->payment_comment); | 
| 781 | -      if(!$result) { | |
| 781 | +      if (!$result) { | |
| 782 | 782 |          throw new Exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST); | 
| 783 | 783 | } | 
| 784 | 784 | } | 
| @@ -787,25 +787,25 @@ discard block | ||
| 787 | 787 |    public function payment_cancel(&$payment) { | 
| 788 | 788 |      die('{НЕ РАБОТАЕТ! СООБЩИТЕ АДМИНИСТРАЦИИ!}'); | 
| 789 | 789 | |
| 790 | -    if(!isset($payment['payment_status'])) { | |
| 790 | +    if (!isset($payment['payment_status'])) { | |
| 791 | 791 | throw new exception(classLocale::$lang['pay_msg_request_payment_not_found'], SN_PAYMENT_REQUEST_ORDER_NOT_FOUND); | 
| 792 | 792 | } | 
| 793 | 793 | |
| 794 | -    if($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) { | |
| 795 | - $safe_comment = db_escape($payment['payment_comment'] = classLocale::$lang['pay_msg_request_payment_cancelled'] .' ' . $payment['payment_comment']); | |
| 794 | +    if ($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) { | |
| 795 | + $safe_comment = db_escape($payment['payment_comment'] = classLocale::$lang['pay_msg_request_payment_cancelled'].' '.$payment['payment_comment']); | |
| 796 | 796 | |
| 797 | -      if(!$payment['payment_test']) { | |
| 797 | +      if (!$payment['payment_test']) { | |
| 798 | 798 | $result = $this->account->metamatter_change(RPG_PURCHASE_CANCEL, -$payment['payment_dark_matter_gained'], $payment['payment_comment']); | 
| 799 | -        if(!$result) { | |
| 799 | +        if (!$result) { | |
| 800 | 800 |            throw new exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST); | 
| 801 | 801 | } | 
| 802 | 802 | } | 
| 803 | 803 | $payment['payment_status'] = PAYMENT_STATUS_CANCELED; | 
| 804 | 804 | db_payment_update($payment, $safe_comment); | 
| 805 | 805 | throw new exception(classLocale::$lang['pay_msg_request_payment_cancel_complete'], SN_PAYMENT_REQUEST_OK); | 
| 806 | -    } elseif($payment['payment_status'] == PAYMENT_STATUS_CANCELED) { | |
| 806 | +    } elseif ($payment['payment_status'] == PAYMENT_STATUS_CANCELED) { | |
| 807 | 807 | throw new exception(classLocale::$lang['pay_msg_request_payment_cancelled_already'], SN_PAYMENT_REQUEST_OK); | 
| 808 | -    } elseif($payment['payment_status'] == PAYMENT_STATUS_NONE) { | |
| 808 | +    } elseif ($payment['payment_status'] == PAYMENT_STATUS_NONE) { | |
| 809 | 809 | throw new exception(classLocale::$lang['pay_msg_request_payment_cancel_not_complete'], SN_PAYMENT_REQUEST_PAYMENT_NOT_COMPLETE); | 
| 810 | 810 | } | 
| 811 | 811 | } | 
| @@ -828,8 +828,8 @@ discard block | ||
| 828 | 828 | |
| 829 | 829 |    protected function db_complete_payment() { | 
| 830 | 830 | // TODO - поле payment_processed | 
| 831 | -    if($this->payment_status == PAYMENT_STATUS_NONE) { | |
| 832 | -      if(!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) { | |
| 831 | +    if ($this->payment_status == PAYMENT_STATUS_NONE) { | |
| 832 | +      if (!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) { | |
| 833 | 833 | $this->payment_adjust_mm_new(); | 
| 834 | 834 | $this->payment_status = PAYMENT_STATUS_COMPLETE; | 
| 835 | 835 |        } else { | 
| @@ -876,7 +876,7 @@ discard block | ||
| 876 | 876 |    protected function db_assign_payment($payment = null) { | 
| 877 | 877 | $this->payment_reset(); | 
| 878 | 878 | |
| 879 | -    if(is_array($payment) && isset($payment['payment_id'])) { | |
| 879 | +    if (is_array($payment) && isset($payment['payment_id'])) { | |
| 880 | 880 | $this->payment_id = $payment['payment_id']; | 
| 881 | 881 | $this->payment_status = $payment['payment_status']; | 
| 882 | 882 | $this->payment_date = $payment['payment_date']; | 
| @@ -918,11 +918,11 @@ discard block | ||
| 918 | 918 |    protected function generate_description() { | 
| 919 | 919 | // TODO - системная локализация | 
| 920 | 920 | $this->description_generated = array( | 
| 921 | -      PAYMENT_DESCRIPTION_100 => substr("{$this->payment_dark_matter_gained} ММ аккаунт [{$this->account->account_name}] ID {$this->account->account_id} на " . SN_ROOT_VIRTUAL, 0, 100), | |
| 922 | -      PAYMENT_DESCRIPTION_250 => substr("Оплата {$this->payment_dark_matter_gained} ММ для аккаунта [{$this->payment_user_name}] ID {$this->payment_user_id} на сервере " . SN_ROOT_VIRTUAL, 0, 250), | |
| 923 | - PAYMENT_DESCRIPTION_MAX => ($this->payment_test ? "ТЕСТОВЫЙ ПЛАТЕЖ! " : '') . | |
| 924 | -        "Платеж от аккаунта '{$this->payment_account_name}' ID {$this->payment_account_id} игрока '{$this->payment_user_name}' ID {$this->payment_user_id} на сервере " . SN_ROOT_VIRTUAL . | |
| 925 | -        " сумма {$this->payment_amount} {$this->payment_currency} за {$this->payment_dark_matter_paid} ММ (начислено {$this->payment_dark_matter_gained} ММ)" . | |
| 921 | +      PAYMENT_DESCRIPTION_100 => substr("{$this->payment_dark_matter_gained} ММ аккаунт [{$this->account->account_name}] ID {$this->account->account_id} на ".SN_ROOT_VIRTUAL, 0, 100), | |
| 922 | +      PAYMENT_DESCRIPTION_250 => substr("Оплата {$this->payment_dark_matter_gained} ММ для аккаунта [{$this->payment_user_name}] ID {$this->payment_user_id} на сервере ".SN_ROOT_VIRTUAL, 0, 250), | |
| 923 | + PAYMENT_DESCRIPTION_MAX => ($this->payment_test ? "ТЕСТОВЫЙ ПЛАТЕЖ! " : ''). | |
| 924 | +        "Платеж от аккаунта '{$this->payment_account_name}' ID {$this->payment_account_id} игрока '{$this->payment_user_name}' ID {$this->payment_user_id} на сервере ".SN_ROOT_VIRTUAL. | |
| 925 | +        " сумма {$this->payment_amount} {$this->payment_currency} за {$this->payment_dark_matter_paid} ММ (начислено {$this->payment_dark_matter_gained} ММ)". | |
| 926 | 926 |          " через '{$this->manifest['name']}' сумма {$this->payment_external_amount} {$this->payment_external_currency}", | 
| 927 | 927 | ); | 
| 928 | 928 | } | 
| @@ -103,6 +103,7 @@ | ||
| 103 | 103 | /** | 
| 104 | 104 | * Set custom template location (able to use directory outside of phpBB) | 
| 105 | 105 | * @access public | 
| 106 | + * @param string $template_path | |
| 106 | 107 | */ | 
| 107 | 108 | function set_custom_template($template_path, $template_name, $fallback_template_path = false) | 
| 108 | 109 |    { | 
| @@ -61,10 +61,10 @@ discard block | ||
| 61 | 61 |    { | 
| 62 | 62 | global $phpbb_root_path, $user; | 
| 63 | 63 | |
| 64 | - if (file_exists($phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template')) | |
| 64 | + if (file_exists($phpbb_root_path.'styles/'.$user->theme['template_path'].'/template')) | |
| 65 | 65 |      { | 
| 66 | - $this->root = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template'; | |
| 67 | -      $this->cachepath = $phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $user->theme['template_path']) . '_'; | |
| 66 | + $this->root = $phpbb_root_path.'styles/'.$user->theme['template_path'].'/template'; | |
| 67 | +      $this->cachepath = $phpbb_root_path.'cache/tpl_'.str_replace('_', '-', $user->theme['template_path']).'_'; | |
| 68 | 68 | |
| 69 | 69 | if ($this->orig_tpl_storedb === null) | 
| 70 | 70 |        { | 
| @@ -81,12 +81,12 @@ discard block | ||
| 81 | 81 | |
| 82 | 82 | if ($user->theme['template_inherits_id']) | 
| 83 | 83 |        { | 
| 84 | - $this->inherit_root = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template'; | |
| 84 | + $this->inherit_root = $phpbb_root_path.'styles/'.$user->theme['template_inherit_path'].'/template'; | |
| 85 | 85 | } | 
| 86 | 86 | } | 
| 87 | 87 | else | 
| 88 | 88 |      { | 
| 89 | -      trigger_error('Template path could not be found: styles/' . $user->theme['template_path'] . '/template', E_USER_ERROR); | |
| 89 | +      trigger_error('Template path could not be found: styles/'.$user->theme['template_path'].'/template', E_USER_ERROR); | |
| 90 | 90 | } | 
| 91 | 91 | |
| 92 | 92 | $this->_rootref = &$this->_tpldata['.'][0]; | 
| @@ -109,7 +109,7 @@ discard block | ||
| 109 | 109 | } | 
| 110 | 110 | |
| 111 | 111 | $this->root = $template_path; | 
| 112 | -    $this->cachepath = $phpbb_root_path . 'cache/ctpl_' . str_replace('_', '-', $template_name) . '_'; | |
| 112 | +    $this->cachepath = $phpbb_root_path.'cache/ctpl_'.str_replace('_', '-', $template_name).'_'; | |
| 113 | 113 | |
| 114 | 114 | if ($fallback_template_path !== false) | 
| 115 | 115 |      { | 
| @@ -154,11 +154,11 @@ discard block | ||
| 154 | 154 | } | 
| 155 | 155 | |
| 156 | 156 | $this->filename[$handle] = $filename; | 
| 157 | - $this->files[$handle] = $this->root . '/' . $filename; | |
| 157 | + $this->files[$handle] = $this->root.'/'.$filename; | |
| 158 | 158 | |
| 159 | 159 | if ($this->inherit_root) | 
| 160 | 160 |        { | 
| 161 | - $this->files_inherit[$handle] = $this->inherit_root . '/' . $filename; | |
| 161 | + $this->files_inherit[$handle] = $this->inherit_root.'/'.$filename; | |
| 162 | 162 | } | 
| 163 | 163 | } | 
| 164 | 164 | |
| @@ -235,7 +235,7 @@ discard block | ||
| 235 | 235 | } | 
| 236 | 236 | else | 
| 237 | 237 |      { | 
| 238 | -      eval(' ?>' . $this->compiled_code[$handle] . '<?php '); | |
| 238 | +      eval(' ?>'.$this->compiled_code[$handle].'<?php '); | |
| 239 | 239 | } | 
| 240 | 240 | |
| 241 | 241 | return true; | 
| @@ -280,7 +280,7 @@ discard block | ||
| 280 | 280 | //$user->theme['template_storedb'] = $this->orig_tpl_storedb; | 
| 281 | 281 | //$user->theme['template_inherits_id'] = $this->orig_tpl_inherits_id; | 
| 282 | 282 | |
| 283 | -    $filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . DOT_PHP_EX; | |
| 283 | +    $filename = $this->cachepath.str_replace('/', '.', $this->filename[$handle]).DOT_PHP_EX; | |
| 284 | 284 | //$this->files_template[$handle] = (isset($user->theme['template_id'])) ? $user->theme['template_id'] : 0; | 
| 285 | 285 | |
| 286 | 286 | $recompile = false; | 
| @@ -309,7 +309,7 @@ discard block | ||
| 309 | 309 | |
| 310 | 310 |      if (!class_exists('template_compile')) | 
| 311 | 311 |      { | 
| 312 | - include($phpbb_root_path . 'includes/functions_template' . DOT_PHP_EX); | |
| 312 | + include($phpbb_root_path.'includes/functions_template'.DOT_PHP_EX); | |
| 313 | 313 | } | 
| 314 | 314 | |
| 315 | 315 | // Inheritance - we point to another template file for this one. Equality is also used for store_db | 
| @@ -348,10 +348,10 @@ discard block | ||
| 348 | 348 | foreach ($ids as $id) | 
| 349 | 349 |        { | 
| 350 | 350 | $sql = 'SELECT * | 
| 351 | - FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' | |
| 352 | - WHERE template_id = ' . $id . " | |
| 353 | - AND (template_filename = '" . $db->sql_escape($this->filename[$handle]) . "' | |
| 354 | - OR template_included " . $db->sql_like_expression($db->any_char . $this->filename[$handle] . ':' . $db->any_char) . ')'; | |
| 351 | + FROM ' . STYLES_TEMPLATE_DATA_TABLE.' | |
| 352 | + WHERE template_id = ' . $id." | |
| 353 | + AND (template_filename = '" . $db->sql_escape($this->filename[$handle])."' | |
| 354 | + OR template_included " . $db->sql_like_expression($db->any_char.$this->filename[$handle].':'.$db->any_char).')'; | |
| 355 | 355 | |
| 356 | 356 | $result = $db->sql_query($sql); | 
| 357 | 357 | while ($row = $db->sql_fetchrow($result)) | 
| @@ -365,14 +365,14 @@ discard block | ||
| 365 | 365 |        { | 
| 366 | 366 | foreach ($rows as $row) | 
| 367 | 367 |          { | 
| 368 | - $file = $this->root . '/' . $row['template_filename']; | |
| 368 | + $file = $this->root.'/'.$row['template_filename']; | |
| 369 | 369 | $force_reload = false; | 
| 370 | 370 | if ($row['template_id'] != $user->theme['template_id']) | 
| 371 | 371 |            { | 
| 372 | 372 | // make sure that we are not overlooking a file not in the db yet | 
| 373 | 373 | if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($file)) | 
| 374 | 374 |              { | 
| 375 | - $file = $this->inherit_root . '/' . $row['template_filename']; | |
| 375 | + $file = $this->inherit_root.'/'.$row['template_filename']; | |
| 376 | 376 | $this->files[$row['template_filename']] = $file; | 
| 377 | 377 | $this->files_inherit[$row['template_filename']] = $file; | 
| 378 | 378 | $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id']; | 
| @@ -414,7 +414,7 @@ discard block | ||
| 414 | 414 | else | 
| 415 | 415 |            { | 
| 416 | 416 | // Only bother compiling if it doesn't already exist | 
| 417 | -            if (!file_exists($this->cachepath . str_replace('/', '.', $row['template_filename']) . DOT_PHP_EX)) | |
| 417 | +            if (!file_exists($this->cachepath.str_replace('/', '.', $row['template_filename']).DOT_PHP_EX)) | |
| 418 | 418 |              { | 
| 419 | 419 | $this->filename[$row['template_filename']] = $row['template_filename']; | 
| 420 | 420 | $compile->compile_write($row['template_filename'], $compile->compile(trim($row['template_data']))); | 
| @@ -425,11 +425,11 @@ discard block | ||
| 425 | 425 | } | 
| 426 | 426 | else | 
| 427 | 427 |        { | 
| 428 | - $file = $this->root . '/' . $row['template_filename']; | |
| 428 | + $file = $this->root.'/'.$row['template_filename']; | |
| 429 | 429 | |
| 430 | 430 | if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($file)) | 
| 431 | 431 |          { | 
| 432 | - $file = $this->inherit_root . '/' . $row['template_filename']; | |
| 432 | + $file = $this->inherit_root.'/'.$row['template_filename']; | |
| 433 | 433 | $this->files[$row['template_filename']] = $file; | 
| 434 | 434 | $this->files_inherit[$row['template_filename']] = $file; | 
| 435 | 435 | $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id']; | 
| @@ -622,7 +622,7 @@ discard block | ||
| 622 | 622 | // Re-position template blocks | 
| 623 | 623 | for ($i = sizeof($this->_tpldata[$blockname]); $i > $key; $i--) | 
| 624 | 624 |        { | 
| 625 | - $this->_tpldata[$blockname][$i] = $this->_tpldata[$blockname][$i-1]; | |
| 625 | + $this->_tpldata[$blockname][$i] = $this->_tpldata[$blockname][$i - 1]; | |
| 626 | 626 | $this->_tpldata[$blockname][$i]['S_ROW_COUNT'] = $i; | 
| 627 | 627 | } | 
| 628 | 628 | |
| @@ -656,10 +656,10 @@ discard block | ||
| 656 | 656 |    { | 
| 657 | 657 | $handle = $filename; | 
| 658 | 658 | $this->filename[$handle] = $filename; | 
| 659 | - $this->files[$handle] = $this->root . '/' . $filename; | |
| 659 | + $this->files[$handle] = $this->root.'/'.$filename; | |
| 660 | 660 | if ($this->inherit_root) | 
| 661 | 661 |      { | 
| 662 | - $this->files_inherit[$handle] = $this->inherit_root . '/' . $filename; | |
| 662 | + $this->files_inherit[$handle] = $this->inherit_root.'/'.$filename; | |
| 663 | 663 | } | 
| 664 | 664 | |
| 665 | 665 | $filename = $this->_tpl_load($handle); | 
| @@ -673,7 +673,7 @@ discard block | ||
| 673 | 673 | include($filename); | 
| 674 | 674 | return; | 
| 675 | 675 | } | 
| 676 | -      eval(' ?>' . $this->compiled_code[$handle] . '<?php '); | |
| 676 | +      eval(' ?>'.$this->compiled_code[$handle].'<?php '); | |
| 677 | 677 | } | 
| 678 | 678 | } | 
| 679 | 679 | |
| @@ -685,12 +685,12 @@ discard block | ||
| 685 | 685 |    { | 
| 686 | 686 | global $phpbb_root_path; | 
| 687 | 687 | |
| 688 | - $file = $phpbb_root_path . $filename; | |
| 688 | + $file = $phpbb_root_path.$filename; | |
| 689 | 689 | |
| 690 | 690 | if (!file_exists($file)) | 
| 691 | 691 |      { | 
| 692 | 692 | // trigger_error cannot be used here, as the output already started | 
| 693 | - echo 'template->_php_include(): File ' . htmlspecialchars($file) . ' does not exist or is empty'; | |
| 693 | + echo 'template->_php_include(): File '.htmlspecialchars($file).' does not exist or is empty'; | |
| 694 | 694 | return; | 
| 695 | 695 | } | 
| 696 | 696 | include($file); | 
| @@ -702,13 +702,13 @@ discard block | ||
| 702 | 702 | */ | 
| 703 | 703 | function assign_recursive($values, $name = '') | 
| 704 | 704 |    { | 
| 705 | - if(isset($values['.'])) | |
| 705 | + if (isset($values['.'])) | |
| 706 | 706 |      { | 
| 707 | 707 | $values_extra = $values['.']; | 
| 708 | 708 | unset($values['.']); | 
| 709 | 709 | } | 
| 710 | 710 | |
| 711 | - if(!$name) | |
| 711 | + if (!$name) | |
| 712 | 712 |      { | 
| 713 | 713 | $this->assign_vars($values); | 
| 714 | 714 | } | 
| @@ -717,12 +717,12 @@ discard block | ||
| 717 | 717 | $this->assign_block_vars($name, $values); | 
| 718 | 718 | } | 
| 719 | 719 | |
| 720 | - if(isset($values_extra)) | |
| 720 | + if (isset($values_extra)) | |
| 721 | 721 |      { | 
| 722 | - foreach($values_extra as $sub_array_name => $sub_array) | |
| 722 | + foreach ($values_extra as $sub_array_name => $sub_array) | |
| 723 | 723 |        { | 
| 724 | - $new_name = $name . ($name ? '.' : '') . $sub_array_name; | |
| 725 | - foreach($sub_array as $sub_element) | |
| 724 | + $new_name = $name.($name ? '.' : '').$sub_array_name; | |
| 725 | + foreach ($sub_array as $sub_element) | |
| 726 | 726 |          { | 
| 727 | 727 | $this->assign_recursive($sub_element, $new_name); | 
| 728 | 728 | } | 
| @@ -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; | 
| @@ -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 | } | 
| @@ -14,14 +14,14 @@ discard block | ||
| 14 | 14 | |
| 15 | 15 | |
| 16 | 16 |  function que_get_max_que_length($user, $planet, $que_id, $que_data = null) { | 
| 17 | -  if(empty($que_data)) { | |
| 17 | +  if (empty($que_data)) { | |
| 18 | 18 |      $que_data = sn_get_groups('ques'); | 
| 19 | 19 | $que_data = $que_data[$que_id]; | 
| 20 | 20 | } | 
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | $que_length = 1; | 
| 24 | -  switch($que_id) { | |
| 24 | +  switch ($que_id) { | |
| 25 | 25 | case QUE_RESEARCH: | 
| 26 | 26 | $que_length = classSupernova::$config->server_que_length_research + mrc_get_level($user, null, UNIT_PREMIUM); // TODO - вынести в модуль | 
| 27 | 27 | break; | 
| @@ -35,8 +35,8 @@ discard block | ||
| 35 | 35 | |
| 36 | 36 |  function eco_que_str2arr($que_str) { | 
| 37 | 37 |    $que_arr = explode(';', $que_str); | 
| 38 | -  foreach($que_arr as $que_index => &$que_item) { | |
| 39 | -    if($que_item) { | |
| 38 | +  foreach ($que_arr as $que_index => &$que_item) { | |
| 39 | +    if ($que_item) { | |
| 40 | 40 |        $que_item = explode(',', $que_item); | 
| 41 | 41 |      } else { | 
| 42 | 42 | unset($que_arr[$que_index]); | 
| @@ -47,7 +47,7 @@ discard block | ||
| 47 | 47 | } | 
| 48 | 48 | |
| 49 | 49 |  function eco_que_arr2str($que_arr) { | 
| 50 | -  foreach($que_arr as &$que_item) { | |
| 50 | +  foreach ($que_arr as &$que_item) { | |
| 51 | 51 |      $que_item = implode(',', $que_item); | 
| 52 | 52 | } | 
| 53 | 53 | |
| @@ -59,14 +59,14 @@ discard block | ||
| 59 | 59 | $classLocale = classLocale::$lang; | 
| 60 | 60 | |
| 61 | 61 | $is_autoconvert = false; | 
| 62 | -  if($build_mode == BUILD_AUTOCONVERT || sys_get_param_int('auto_convert')) { | |
| 62 | +  if ($build_mode == BUILD_AUTOCONVERT || sys_get_param_int('auto_convert')) { | |
| 63 | 63 | $build_mode = BUILD_CREATE; | 
| 64 | 64 | $is_autoconvert = true; | 
| 65 | 65 | } | 
| 66 | 66 | |
| 67 | 67 | $unit_amount_qued = 0; | 
| 68 | 68 |    try { | 
| 69 | -    if(!$user['id']) { | |
| 69 | +    if (!$user['id']) { | |
| 70 | 70 |        throw new exception('{Нет идентификатора пользователя - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION | 
| 71 | 71 | } | 
| 72 | 72 | |
| @@ -77,16 +77,16 @@ discard block | ||
| 77 | 77 | foreach($unit_list as $unit_id => $unit_amount) if($unit_amount) break; | 
| 78 | 78 | } | 
| 79 | 79 | */ | 
| 80 | -    if(!$unit_id) { | |
| 80 | +    if (!$unit_id) { | |
| 81 | 81 |        throw new exception('{Нет идентификатора юнита - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION | 
| 82 | 82 | } | 
| 83 | 83 | |
| 84 | 84 | $que_id = que_get_unit_que($unit_id); | 
| 85 | -    if(!$que_id) { | |
| 85 | +    if (!$que_id) { | |
| 86 | 86 |        throw new exception('{Неправильный тип очереди - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION | 
| 87 | 87 | } | 
| 88 | 88 | |
| 89 | -    if($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) { | |
| 89 | +    if ($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) { | |
| 90 | 90 |        throw new exception('{Уничтожать можно только здания на планете}', ERR_ERROR); // TODO EXCEPTION | 
| 91 | 91 | } | 
| 92 | 92 | |
| @@ -94,12 +94,12 @@ discard block | ||
| 94 | 94 | $que_data = $que_data[$que_id]; | 
| 95 | 95 | |
| 96 | 96 | // TODO Переделать под подочереди | 
| 97 | -    if($que_id == QUE_STRUCTURES) { | |
| 97 | +    if ($que_id == QUE_STRUCTURES) { | |
| 98 | 98 |        $sn_groups_build_allow = sn_get_groups('build_allow'); | 
| 99 | 99 | $que_data['unit_list'] = $sn_groups_build_allow[$planet['planet_type']]; | 
| 100 | 100 | |
| 101 | -      if(!isset($que_data['unit_list'][$unit_id])) { | |
| 102 | -        throw new exception('{Это здание нельзя строить на ' . ($planet['planet_type'] == PT_PLANET ? 'планете' : 'луне'), ERR_ERROR); // TODO EXCEPTION | |
| 101 | +      if (!isset($que_data['unit_list'][$unit_id])) { | |
| 102 | +        throw new exception('{Это здание нельзя строить на '.($planet['planet_type'] == PT_PLANET ? 'планете' : 'луне'), ERR_ERROR); // TODO EXCEPTION | |
| 103 | 103 | } | 
| 104 | 104 | } | 
| 105 | 105 | /* | 
| @@ -119,7 +119,7 @@ discard block | ||
| 119 | 119 | // Это нужно, что бы заблокировать пользователя и работу с очередями | 
| 120 | 120 | $user = DBStaticUser::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,12 +131,12 @@ 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: | 
| 141 | 141 | break; | 
| 142 | 142 | case BUILD_UNIT_BUSY: | 
| @@ -144,7 +144,7 @@ discard block | ||
| 144 | 144 | break; // TODO EXCEPTION eco_bld_msg_err_laboratory_upgrading | 
| 145 | 145 | // case BUILD_REQUIRE_NOT_MEET: | 
| 146 | 146 | default: | 
| 147 | -        if($build_mode == BUILD_CREATE) { | |
| 147 | +        if ($build_mode == BUILD_CREATE) { | |
| 148 | 148 |            throw new exception('{Требования не удовлетворены}', ERR_ERROR); | 
| 149 | 149 | } | 
| 150 | 150 | break; // TODO EXCEPTION eco_bld_msg_err_requirements_not_meet | 
| @@ -154,14 +154,14 @@ discard block | ||
| 154 | 154 | $unit_amount_qued = $unit_amount; | 
| 155 | 155 | $units_qued = isset($in_que[$unit_id]) ? $in_que[$unit_id] : 0; | 
| 156 | 156 | $unit_level = mrc_get_level($user, $planet, $unit_id, true, true) + $units_qued; | 
| 157 | -    if($unit_max = get_unit_param($unit_id, P_MAX_STACK)) { | |
| 158 | -      if($unit_level >= $unit_max) { | |
| 157 | +    if ($unit_max = get_unit_param($unit_id, P_MAX_STACK)) { | |
| 158 | +      if ($unit_level >= $unit_max) { | |
| 159 | 159 |          throw new exception('{Максимальное количество юнитов данного типа уже достигнуто или будет достигнуто по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION | 
| 160 | 160 | } | 
| 161 | 161 | $unit_amount = max(0, min($unit_amount, $unit_max - $unit_level)); | 
| 162 | 162 | } | 
| 163 | 163 | |
| 164 | -    if($unit_amount < 1) { | |
| 164 | +    if ($unit_amount < 1) { | |
| 165 | 165 |        throw new exception('{Неправильное количество юнитов - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION | 
| 166 | 166 | } | 
| 167 | 167 | |
| @@ -170,21 +170,21 @@ discard block | ||
| 170 | 170 |      //  { | 
| 171 | 171 |      //    die('Unit busy'); // TODO EXCEPTION | 
| 172 | 172 | // } | 
| 173 | -    if(get_unit_param($unit_id, P_STACKABLE)) { | |
| 173 | +    if (get_unit_param($unit_id, P_STACKABLE)) { | |
| 174 | 174 | // TODO Поле 'max_Lot_size' для ограничения размера стэка в очереди - то ли в юниты, то ли в очередь | 
| 175 | -      if(in_array($unit_id, $group_missile = sn_get_groups(GROUP_STR_MISSILES))) { | |
| 175 | +      if (in_array($unit_id, $group_missile = sn_get_groups(GROUP_STR_MISSILES))) { | |
| 176 | 176 | // TODO Поле 'container' - указывает на родительску структуру, в которой хранится данный юнит и по вместительности которой нужно применять размер юнита | 
| 177 | 177 | $used_silo = 0; | 
| 178 | -        foreach($group_missile as $missile_id) { | |
| 178 | +        foreach ($group_missile as $missile_id) { | |
| 179 | 179 | $missile_qued = isset($in_que[$missile_id]) ? $in_que[$missile_id] : 0; | 
| 180 | 180 | $used_silo += (mrc_get_level($user, $planet, $missile_id, true, true) + $missile_qued) * get_unit_param($missile_id, P_UNIT_SIZE); | 
| 181 | 181 | } | 
| 182 | 182 | $free_silo = mrc_get_level($user, $planet, STRUC_SILO) * get_unit_param(STRUC_SILO, P_CAPACITY) - $used_silo; | 
| 183 | -        if($free_silo <= 0) { | |
| 183 | +        if ($free_silo <= 0) { | |
| 184 | 184 |            throw new exception('{Ракетная шахта уже заполнена или будет заполнена по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION | 
| 185 | 185 | } | 
| 186 | 186 | $unit_size = get_unit_param($unit_id, P_UNIT_SIZE); | 
| 187 | -        if($free_silo < $unit_size) { | |
| 187 | +        if ($free_silo < $unit_size) { | |
| 188 | 188 |            throw new exception("{В ракетной шахте нет места для {$classLocale['tech'][$unit_id]}}", ERR_ERROR); // TODO EXCEPTION | 
| 189 | 189 | } | 
| 190 | 190 | $unit_amount = max(0, min($unit_amount, floor($free_silo / $unit_size))); | 
| @@ -192,10 +192,10 @@ discard block | ||
| 192 | 192 | $unit_level = $new_unit_level = 0; | 
| 193 | 193 |      } else { | 
| 194 | 194 | $unit_amount = 1; | 
| 195 | -      if($que_id == QUE_STRUCTURES) { | |
| 195 | +      if ($que_id == QUE_STRUCTURES) { | |
| 196 | 196 | // if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $que['sectors'][$planet['id']] <= 0) | 
| 197 | 197 | $sectors_qued = is_array($in_que) ? array_sum($in_que) : 0; | 
| 198 | -        if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) { | |
| 198 | +        if ($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) { | |
| 199 | 199 |            throw new exception('{Не хватает секторов на планете}', ERR_ERROR); // TODO EXCEPTION | 
| 200 | 200 | } | 
| 201 | 201 | // И что это я такое написал? Зачем? | 
| @@ -212,10 +212,10 @@ discard block | ||
| 212 | 212 | |
| 213 | 213 | $exchange = array(); | 
| 214 | 214 | $market_get_autoconvert_cost = market_get_autoconvert_cost(); | 
| 215 | -    if($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) { | |
| 215 | +    if ($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) { | |
| 216 | 216 | $dark_matter = mrc_get_level($user, null, RES_DARK_MATTER); | 
| 217 | -      if(mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) { | |
| 218 | -        throw new exception("{Нет хватает " . ($market_get_autoconvert_cost - $dark_matter) . "ТМ на постройки с автоконвертацией ресурсов}", ERR_ERROR); // TODO EXCEPTION | |
| 217 | +      if (mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) { | |
| 218 | +        throw new exception("{Нет хватает ".($market_get_autoconvert_cost - $dark_matter)."ТМ на постройки с автоконвертацией ресурсов}", ERR_ERROR); // TODO EXCEPTION | |
| 219 | 219 | } | 
| 220 | 220 | |
| 221 | 221 | !get_unit_param($unit_id, P_STACKABLE) ? $unit_amount = 1 : false; | 
| @@ -224,7 +224,7 @@ discard block | ||
| 224 | 224 | $resource_exchange_rates = array(); | 
| 225 | 225 | $resource_diff = array(); | 
| 226 | 226 | $all_positive = true; | 
| 227 | -      foreach($resources_loot as $resource_id) { | |
| 227 | +      foreach ($resources_loot as $resource_id) { | |
| 228 | 228 | $resource_db_name = pname_resource_name($resource_id); | 
| 229 | 229 | $resource_got[$resource_id] = floor(mrc_get_level($user, $planet, $resource_id)); | 
| 230 | 230 |          $resource_exchange_rates[$resource_id] = classSupernova::$config->__get("rpg_exchange_{$resource_db_name}"); | 
| @@ -232,15 +232,15 @@ discard block | ||
| 232 | 232 | $all_positive = $all_positive && ($resource_diff[$resource_id] > 0); | 
| 233 | 233 | } | 
| 234 | 234 | // Нужна автоконвертация | 
| 235 | -      if($all_positive) { | |
| 235 | +      if ($all_positive) { | |
| 236 | 236 | $is_autoconvert = false; | 
| 237 | 237 |        } else { | 
| 238 | -        foreach($resource_diff as $resource_diff_id => &$resource_diff_amount) { | |
| 239 | -          if($resource_diff_amount >= 0) { | |
| 238 | +        foreach ($resource_diff as $resource_diff_id => &$resource_diff_amount) { | |
| 239 | +          if ($resource_diff_amount >= 0) { | |
| 240 | 240 | continue; | 
| 241 | 241 | } | 
| 242 | -          foreach($resource_diff as $resource_got_id => &$resource_got_amount) { | |
| 243 | -            if($resource_got_amount <= 0) { | |
| 242 | +          foreach ($resource_diff as $resource_got_id => &$resource_got_amount) { | |
| 243 | +            if ($resource_got_amount <= 0) { | |
| 244 | 244 | continue; | 
| 245 | 245 | } | 
| 246 | 246 | $current_exchange = $resource_exchange_rates[$resource_got_id] / $resource_exchange_rates[$resource_diff_id]; | 
| @@ -256,14 +256,14 @@ discard block | ||
| 256 | 256 | } | 
| 257 | 257 | |
| 258 | 258 | $is_autoconvert_ok = true; | 
| 259 | -        foreach($resource_diff as $resource_diff_amount2) { | |
| 260 | -          if($resource_diff_amount2 < 0) { | |
| 259 | +        foreach ($resource_diff as $resource_diff_amount2) { | |
| 260 | +          if ($resource_diff_amount2 < 0) { | |
| 261 | 261 | $is_autoconvert_ok = false; | 
| 262 | 262 | break; | 
| 263 | 263 | } | 
| 264 | 264 | } | 
| 265 | 265 | |
| 266 | -        if($is_autoconvert_ok) { | |
| 266 | +        if ($is_autoconvert_ok) { | |
| 267 | 267 | $build_data['RESULT'][$build_mode] = BUILD_ALLOWED; | 
| 268 | 268 | $build_data['CAN'][$build_mode] = $unit_amount; | 
| 269 | 269 |          } else { | 
| @@ -272,19 +272,19 @@ discard block | ||
| 272 | 272 | } | 
| 273 | 273 | } | 
| 274 | 274 | $unit_amount = min($build_data['CAN'][$build_mode], $unit_amount); | 
| 275 | -    if($unit_amount <= 0) { | |
| 275 | +    if ($unit_amount <= 0) { | |
| 276 | 276 |        throw new exception('{Не хватает ресурсов}', ERR_ERROR); // TODO EXCEPTION | 
| 277 | 277 | } | 
| 278 | 278 | |
| 279 | -    if($new_unit_level < 0) { | |
| 279 | +    if ($new_unit_level < 0) { | |
| 280 | 280 |        throw new exception('{Нельзя уничтожить больше юнитов, чем есть}', ERR_ERROR); // TODO EXCEPTION | 
| 281 | 281 | } | 
| 282 | 282 | |
| 283 | -    if($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) { | |
| 283 | +    if ($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) { | |
| 284 | 284 |        throw new exception('{Строительство блокировано}', ERR_ERROR); // TODO EXCEPTION | 
| 285 | 285 | } | 
| 286 | 286 | |
| 287 | -    if($is_autoconvert) { | |
| 287 | +    if ($is_autoconvert) { | |
| 288 | 288 | ksort($exchange); | 
| 289 | 289 | ksort($resource_got); | 
| 290 | 290 | db_change_units($user, $planet, array( | 
| @@ -299,7 +299,7 @@ discard block | ||
| 299 | 299 | } | 
| 300 | 300 | |
| 301 | 301 | $unit_amount_qued = 0; | 
| 302 | -    while($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) { | |
| 302 | +    while ($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) { | |
| 303 | 303 | $place = min($unit_amount, MAX_FLEET_OR_DEFS_PER_ROW); | 
| 304 | 304 | que_add_unit($unit_id, $user, $planet, $build_data, $new_unit_level, $place, $build_mode); | 
| 305 | 305 | $unit_amount -= $place; | 
| @@ -309,8 +309,8 @@ discard block | ||
| 309 | 309 | |
| 310 | 310 | sn_db_transaction_commit(); | 
| 311 | 311 | |
| 312 | -    if($redirect) { | |
| 313 | -      sys_redirect("{$_SERVER['PHP_SELF']}?mode=" . sys_get_param_str('mode') . "&ally_id=" . sys_get_param_id('ally_id')); | |
| 312 | +    if ($redirect) { | |
| 313 | +      sys_redirect("{$_SERVER['PHP_SELF']}?mode=".sys_get_param_str('mode')."&ally_id=".sys_get_param_id('ally_id')); | |
| 314 | 314 | die(); | 
| 315 | 315 | } | 
| 316 | 316 | |
| @@ -318,7 +318,7 @@ discard block | ||
| 318 | 318 | 'STATUS' => ERR_NONE, | 
| 319 | 319 |        'MESSAGE' => '{Строительство начато}', | 
| 320 | 320 | ); | 
| 321 | -  } catch(exception $e) { | |
| 321 | +  } catch (exception $e) { | |
| 322 | 322 | sn_db_transaction_rollback(); | 
| 323 | 323 | $operation_result = array( | 
| 324 | 324 | 'STATUS' => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR, | 
| @@ -326,8 +326,8 @@ discard block | ||
| 326 | 326 | ); | 
| 327 | 327 | } | 
| 328 | 328 | |
| 329 | -  if(!empty($operation_result['MESSAGE'])) { | |
| 330 | - $operation_result['MESSAGE'] .= ' ' . ($unit_amount_qued ? $unit_amount_qued : $unit_amount) . 'x[' . classLocale::$lang['tech'][$unit_id] . ']'; | |
| 329 | +  if (!empty($operation_result['MESSAGE'])) { | |
| 330 | + $operation_result['MESSAGE'] .= ' '.($unit_amount_qued ? $unit_amount_qued : $unit_amount).'x['.classLocale::$lang['tech'][$unit_id].']'; | |
| 331 | 331 | } | 
| 332 | 332 | |
| 333 | 333 | return $operation_result; | 
| @@ -337,11 +337,11 @@ discard block | ||
| 337 | 337 |  function que_recalculate($old_que) { | 
| 338 | 338 | $new_que = array(); | 
| 339 | 339 | |
| 340 | -  if(!is_array($old_que['items'])) { | |
| 340 | +  if (!is_array($old_que['items'])) { | |
| 341 | 341 | return $new_que; | 
| 342 | 342 | } | 
| 343 | -  foreach($old_que['items'] as $row) { | |
| 344 | -    if(!isset($row) || !$row || $row['que_unit_amount'] <= 0) { | |
| 343 | +  foreach ($old_que['items'] as $row) { | |
| 344 | +    if (!isset($row) || !$row || $row['que_unit_amount'] <= 0) { | |
| 345 | 345 | continue; | 
| 346 | 346 | } | 
| 347 | 347 | |
| @@ -352,9 +352,9 @@ discard block | ||
| 352 | 352 | |
| 353 | 353 | $last_id = count($new_que['items']) - 1; | 
| 354 | 354 | |
| 355 | -    if($row['que_planet_id']) { | |
| 355 | +    if ($row['que_planet_id']) { | |
| 356 | 356 | $new_que['planets'][$row['que_planet_id']][$row['que_type']][] = &$new_que['items'][$last_id]; | 
| 357 | -    } elseif($row['que_type'] == QUE_RESEARCH) { | |
| 357 | +    } elseif ($row['que_type'] == QUE_RESEARCH) { | |
| 358 | 358 | $new_que['players'][$row['que_player_id']][$row['que_type']][] = &$new_que['items'][$last_id]; | 
| 359 | 359 | } | 
| 360 | 360 | $new_que['ques'][$row['que_type']][$row['que_player_id']][intval($row['que_planet_id'])][] = &$new_que['items'][$last_id]; | 
| @@ -389,9 +389,9 @@ discard block | ||
| 389 | 389 | $que_type = que_get_unit_que($unit_id); | 
| 390 | 390 | $planet_id_origin = $planet['id'] ? $planet['id'] : 'NULL'; | 
| 391 | 391 | $planet_id = $que_type == QUE_RESEARCH ? 'NULL' : $planet_id_origin; | 
| 392 | -  if(is_numeric($planet_id)) { | |
| 392 | +  if (is_numeric($planet_id)) { | |
| 393 | 393 | DBStaticPlanet::db_planet_update_set_by_id($planet_id, "`que_processed` = UNIX_TIMESTAMP(NOW())"); | 
| 394 | -  } elseif(is_numeric($user['id'])) { | |
| 394 | +  } elseif (is_numeric($user['id'])) { | |
| 395 | 395 | DBStaticUser::db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())'); | 
| 396 | 396 | } | 
| 397 | 397 | |
| @@ -421,17 +421,17 @@ discard block | ||
| 421 | 421 | $planet['id'] = $planet['id'] && $que_type !== QUE_RESEARCH ? $planet['id'] : 0; | 
| 422 | 422 | $global_que = que_get($user['id'], $planet['id'], $que_type, true); | 
| 423 | 423 | |
| 424 | -  if(!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) { | |
| 424 | +  if (!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) { | |
| 425 | 425 | $que = array_reverse($global_que['ques'][$que_type][$user['id']][$planet['id']]); | 
| 426 | 426 | |
| 427 | -    foreach($que as $que_item) { | |
| 427 | +    foreach ($que as $que_item) { | |
| 428 | 428 | DBStaticQue::db_que_delete_by_id($que_item['que_id']); | 
| 429 | 429 | |
| 430 | -      if($que_item['que_planet_id_origin']) { | |
| 430 | +      if ($que_item['que_planet_id_origin']) { | |
| 431 | 431 | $planet['id'] = $que_item['que_planet_id_origin']; | 
| 432 | 432 | } | 
| 433 | 433 | |
| 434 | -      if(!isset($planets_locked[$planet['id']])) { | |
| 434 | +      if (!isset($planets_locked[$planet['id']])) { | |
| 435 | 435 | $planets_locked[$planet['id']] = $planet['id'] ? DBStaticPlanet::db_planet_by_id($planet['id'], true) : $planet; | 
| 436 | 436 | } | 
| 437 | 437 | |
| @@ -443,14 +443,14 @@ discard block | ||
| 443 | 443 | RES_DEUTERIUM => $build_data[RES_DEUTERIUM] * $que_item['que_unit_amount'], | 
| 444 | 444 | )); | 
| 445 | 445 | |
| 446 | -      if(!$clear) { | |
| 446 | +      if (!$clear) { | |
| 447 | 447 | break; | 
| 448 | 448 | } | 
| 449 | 449 | } | 
| 450 | 450 | |
| 451 | -    if(is_numeric($planet['id'])) { | |
| 451 | +    if (is_numeric($planet['id'])) { | |
| 452 | 452 | DBStaticPlanet::db_planet_update_set_by_id($planet['id'], "`que_processed` = UNIX_TIMESTAMP(NOW())"); | 
| 453 | -    } elseif(is_numeric($user['id'])) { | |
| 453 | +    } elseif (is_numeric($user['id'])) { | |
| 454 | 454 | DBStaticUser::db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())'); | 
| 455 | 455 | } | 
| 456 | 456 | |
| @@ -459,7 +459,7 @@ discard block | ||
| 459 | 459 | sn_db_transaction_rollback(); | 
| 460 | 460 | } | 
| 461 | 461 | //die(); | 
| 462 | -  header("Location: {$_SERVER['PHP_SELF']}?mode={$que_type}" . "&ally_id=" . sys_get_param_id('ally_id')); | |
| 462 | +  header("Location: {$_SERVER['PHP_SELF']}?mode={$que_type}"."&ally_id=".sys_get_param_id('ally_id')); | |
| 463 | 463 | } | 
| 464 | 464 | |
| 465 | 465 | |
| @@ -498,21 +498,21 @@ discard block | ||
| 498 | 498 | // TODO: Переделать для $que_type === false | 
| 499 | 499 | $planet['id'] = $planet['id'] ? $planet['id'] : 0; | 
| 500 | 500 | |
| 501 | -  if(!is_array($que)) { | |
| 501 | +  if (!is_array($que)) { | |
| 502 | 502 | $que = que_get($user['id'], $planet['id'], $que_type); | 
| 503 | 503 | } | 
| 504 | 504 | |
| 505 | -  if(is_array($que) && isset($que['items'])) { | |
| 505 | +  if (is_array($que) && isset($que['items'])) { | |
| 506 | 506 | $que = $que['ques'][$que_type][$user['id']][$planet['id']]; | 
| 507 | 507 | } | 
| 508 | 508 | |
| 509 | -  if($que) { | |
| 510 | -    foreach($que as $que_element) { | |
| 509 | +  if ($que) { | |
| 510 | +    foreach ($que as $que_element) { | |
| 511 | 511 |        $template->assign_block_vars('que', que_tpl_parse_element($que_element, $short_names)); | 
| 512 | 512 | } | 
| 513 | 513 | } | 
| 514 | 514 | |
| 515 | -  if($que_type == QUE_RESEARCH) { | |
| 515 | +  if ($que_type == QUE_RESEARCH) { | |
| 516 | 516 | } | 
| 517 | 517 | } | 
| 518 | 518 | |
| @@ -538,7 +538,7 @@ discard block | ||
| 538 | 538 | $user = DBStaticUser::db_user_by_id($user['id'], true); | 
| 539 | 539 | |
| 540 | 540 | $time_left[$user['id']][0] = max(0, $on_time - $user['que_processed']); | 
| 541 | -  if($planet === null && !$time_left[$user['id']][0]) { | |
| 541 | +  if ($planet === null && !$time_left[$user['id']][0]) { | |
| 542 | 542 | // TODO | 
| 543 | 543 | return $que; | 
| 544 | 544 | } | 
| @@ -547,12 +547,12 @@ discard block | ||
| 547 | 547 | $que_type_id = $planet === null ? QUE_RESEARCH : false; | 
| 548 | 548 | $planet = intval(is_array($planet) ? $planet['id'] : $planet); // В $planet у нас теперь только её ID или шаблон null/0/false | 
| 549 | 549 | $que = que_get($user['id'], $planet, $que_type_id, true); | 
| 550 | -  if(empty($que['items'])) { | |
| 550 | +  if (empty($que['items'])) { | |
| 551 | 551 | return $que; | 
| 552 | 552 | } | 
| 553 | 553 | |
| 554 | 554 | $planet_list = array(); | 
| 555 | -  if($planet !== null) { | |
| 555 | +  if ($planet !== null) { | |
| 556 | 556 | // Если нужно изменять данные на планетах - блокируем планеты и получаем данные о них | 
| 557 | 557 | // TODO - от них не надо ничего, кроме ID и que_processed | 
| 558 | 558 | $planet_row = DBStaticPlanet::db_planet_list_by_user_or_planet($user['id'], $planet); | 
| @@ -561,20 +561,20 @@ discard block | ||
| 561 | 561 | } | 
| 562 | 562 | |
| 563 | 563 | // Теперь в $time_left лежит время обсчета всех очередей по каждой из планеты | 
| 564 | -  if(array_sum($time_left[$user['id']]) == 0) { | |
| 564 | +  if (array_sum($time_left[$user['id']]) == 0) { | |
| 565 | 565 | return $que; | 
| 566 | 566 | } | 
| 567 | 567 | |
| 568 | 568 | $unit_changes = array(); | 
| 569 | -  foreach($que['items'] as &$que_item) { | |
| 569 | +  foreach ($que['items'] as &$que_item) { | |
| 570 | 570 | $que_player_id = &$que_item['que_player_id']; | 
| 571 | 571 | $que_planet_id = intval($que_item['que_planet_id']); | 
| 572 | 572 | |
| 573 | 573 | $que_time_left = &$que['time_left'][$que_player_id][$que_planet_id][$que_item['que_type']]; | 
| 574 | -    if(!isset($que_time_left)) { | |
| 574 | +    if (!isset($que_time_left)) { | |
| 575 | 575 | $que_time_left = $time_left[$que_player_id][$que_planet_id]; | 
| 576 | 576 | } | 
| 577 | -    if($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) { | |
| 577 | +    if ($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) { | |
| 578 | 578 | continue; | 
| 579 | 579 | } | 
| 580 | 580 | // Дальше мы идем, если только осталось время в очереди И юниты к постройке | 
| @@ -587,7 +587,7 @@ discard block | ||
| 587 | 587 | // Теперь работаем с остатком времени на юните. Оно не может быть равно или меньше нуля | 
| 588 | 588 | |
| 589 | 589 | // Если времени в очереди осталось не меньше, чем время текущего юнита - значит мы достроили юнит | 
| 590 | -    if($que_time_left >= $que_item['que_time_left']) { | |
| 590 | +    if ($que_time_left >= $que_item['que_time_left']) { | |
| 591 | 591 | // Увеличиваем количество отстроенных юнитов | 
| 592 | 592 | $unit_processed++; | 
| 593 | 593 | // Вычитаем из времени очереди потраченное на постройку время | 
| @@ -600,12 +600,12 @@ discard block | ||
| 600 | 600 | $que_item['que_unit_amount'] -= $unit_processed; | 
| 601 | 601 | |
| 602 | 602 | // Если еще остались юниты - значит ВСЁ оставшееся время приходится на достройку следующего юнита | 
| 603 | -    if($que_item['que_unit_amount'] > 0) { | |
| 603 | +    if ($que_item['que_unit_amount'] > 0) { | |
| 604 | 604 | $que_item['que_time_left'] = $que_item['que_time_left'] - $que_time_left; | 
| 605 | 605 | $que_time_left = 0; | 
| 606 | 606 | } | 
| 607 | 607 | |
| 608 | -    if($que_item['que_unit_amount'] <= 0) { | |
| 608 | +    if ($que_item['que_unit_amount'] <= 0) { | |
| 609 | 609 | DBStaticQue::db_que_delete_by_id($que_item['que_id']); | 
| 610 | 610 |      } else { | 
| 611 | 611 | classSupernova::db_upd_record_list( | 
| @@ -615,15 +615,15 @@ discard block | ||
| 615 | 615 | ); | 
| 616 | 616 | } | 
| 617 | 617 | |
| 618 | -    if($unit_processed) { | |
| 618 | +    if ($unit_processed) { | |
| 619 | 619 | $unit_processed_delta = $unit_processed * ($que_item['que_unit_mode'] == BUILD_CREATE ? 1 : -1); | 
| 620 | 620 | $unit_changes[$que_player_id][$que_planet_id][$que_item['que_unit_id']] += $unit_processed_delta; | 
| 621 | 621 | } | 
| 622 | 622 | } | 
| 623 | 623 | |
| 624 | -  foreach($time_left as $player_id => $planet_data) { | |
| 625 | -    foreach($planet_data as $planet_id => $time_on_planet) { | |
| 626 | -      if($planet_id) { | |
| 624 | +  foreach ($time_left as $player_id => $planet_data) { | |
| 625 | +    foreach ($planet_data as $planet_id => $time_on_planet) { | |
| 626 | +      if ($planet_id) { | |
| 627 | 627 | // update planet | 
| 628 | 628 |          classSupernova::db_upd_record_list(LOC_PLANET, "`que_processed` = {$on_time}", "id = {$planet_id}"); | 
| 629 | 629 |        } else { | 
| @@ -631,8 +631,8 @@ discard block | ||
| 631 | 631 |          classSupernova::db_upd_record_list(LOC_USER, "`que_processed` = {$on_time}", "id = {$player_id}"); | 
| 632 | 632 | } | 
| 633 | 633 | |
| 634 | -      if(is_array($unit_changes[$player_id][$planet_id])) { | |
| 635 | -        foreach($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) { | |
| 634 | +      if (is_array($unit_changes[$player_id][$planet_id])) { | |
| 635 | +        foreach ($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) { | |
| 636 | 636 | DBStaticUnit::dbUpdateOrInsertUnit($unit_id, $unit_amount, $user, $planet_id ? $planet_id : null); | 
| 637 | 637 | } | 
| 638 | 638 | } | 
| @@ -642,38 +642,38 @@ discard block | ||
| 642 | 642 | $que = que_recalculate($que); | 
| 643 | 643 | |
| 644 | 644 | // TODO: Re-enable quests for Alliances | 
| 645 | -  if(!empty($unit_changes) && !$user['user_as_ally']) { | |
| 645 | +  if (!empty($unit_changes) && !$user['user_as_ally']) { | |
| 646 | 646 | $quest_list = qst_get_quests($user['id']); | 
| 647 | 647 | $quest_triggers = qst_active_triggers($quest_list); | 
| 648 | 648 | $quest_rewards = array(); | 
| 649 | 649 | |
| 650 | 650 | |
| 651 | 651 | $xp_incoming = array(); | 
| 652 | -    foreach($unit_changes as $user_id => $planet_changes) { | |
| 653 | -      foreach($planet_changes as $planet_id => $changes) { | |
| 652 | +    foreach ($unit_changes as $user_id => $planet_changes) { | |
| 653 | +      foreach ($planet_changes as $planet_id => $changes) { | |
| 654 | 654 | $planet_this = $planet_id ? classSupernova::db_get_record_by_id(LOC_PLANET, $planet_id) : array(); | 
| 655 | -        foreach($changes as $unit_id => $unit_value) { | |
| 655 | +        foreach ($changes as $unit_id => $unit_value) { | |
| 656 | 656 | $que_id = que_get_unit_que($unit_id); | 
| 657 | 657 | $unit_level_new = mrc_get_level($user, $planet_this, $unit_id, false, true) + $unit_value; | 
| 658 | -          if($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) { | |
| 658 | +          if ($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) { | |
| 659 | 659 | $build_data = eco_get_build_data($user, $planet_this, $unit_id, $unit_level_new - 1); | 
| 660 | 660 | $build_data = $build_data[BUILD_CREATE]; | 
| 661 | -            foreach(sn_get_groups('resources_loot') as $resource_id) { | |
| 661 | +            foreach (sn_get_groups('resources_loot') as $resource_id) { | |
| 662 | 662 | $xp_incoming[$que_id] += $build_data[$resource_id]; // TODO - добавить конверсию рейтов обмена | 
| 663 | 663 | } | 
| 664 | 664 | } | 
| 665 | 665 | |
| 666 | -          if(is_array($quest_triggers)) { | |
| 666 | +          if (is_array($quest_triggers)) { | |
| 667 | 667 | // TODO: Check mutiply condition quests | 
| 668 | 668 | $quest_trigger_list = array_keys($quest_triggers, $unit_id); | 
| 669 | -            if(is_array($quest_trigger_list)) { | |
| 670 | -              foreach($quest_trigger_list as $quest_id) { | |
| 669 | +            if (is_array($quest_trigger_list)) { | |
| 670 | +              foreach ($quest_trigger_list as $quest_id) { | |
| 671 | 671 | $quest_unit_level = $unit_level_new; | 
| 672 | -                if(get_unit_param($unit_id, P_UNIT_TYPE) == UNIT_SHIPS) { | |
| 672 | +                if (get_unit_param($unit_id, P_UNIT_TYPE) == UNIT_SHIPS) { | |
| 673 | 673 | $quest_unit_level = DBStaticUnit::db_unit_count_by_user_and_type_and_snid($user_id, 0, $unit_id); | 
| 674 | 674 | $quest_unit_level = $quest_unit_level[$unit_id]['qty']; | 
| 675 | 675 | } | 
| 676 | -                if($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $quest_unit_level) { | |
| 676 | +                if ($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $quest_unit_level) { | |
| 677 | 677 | $quest_rewards[$quest_id][$user_id][$planet_id] = $quest_list[$quest_id]['quest_rewards_list']; | 
| 678 | 678 | $quest_list[$quest_id]['quest_status_status'] = QUEST_STATUS_COMPLETE; | 
| 679 | 679 | } | 
| @@ -686,7 +686,7 @@ discard block | ||
| 686 | 686 | // TODO: Изменить начисление награды за квесты на ту планету, на которой происходил ресеч | 
| 687 | 687 | qst_reward($user, $quest_rewards, $quest_list); | 
| 688 | 688 | |
| 689 | -    foreach($xp_incoming as $que_id => $xp) { | |
| 689 | +    foreach ($xp_incoming as $que_id => $xp) { | |
| 690 | 690 | rpg_level_up($user, $que_id == QUE_RESEARCH ? RPG_TECH : RPG_STRUCTURE, $xp / 1000); | 
| 691 | 691 | } | 
| 692 | 692 | } | 
| @@ -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 | |
| @@ -7,7 +7,7 @@ discard block | ||
| 7 | 7 | use Vector\Vector; | 
| 8 | 8 | |
| 9 | 9 |  function sys_user_vacation($user) { | 
| 10 | -  if(sys_get_param_str('vacation') == 'leave') { | |
| 10 | +  if (sys_get_param_str('vacation') == 'leave') { | |
| 11 | 11 |      if ($user['vacation'] < SN_TIME_NOW) { | 
| 12 | 12 | $user['vacation'] = 0; | 
| 13 | 13 | $user['vacation_next'] = SN_TIME_NOW + classSupernova::$config->player_vacation_timeout; | 
| @@ -15,7 +15,7 @@ discard block | ||
| 15 | 15 | } | 
| 16 | 16 | } | 
| 17 | 17 | |
| 18 | -  if($user['vacation']) { | |
| 18 | +  if ($user['vacation']) { | |
| 19 | 19 | // sn_sys_logout(false, true); | 
| 20 | 20 | // core_auth::logout(false, true); | 
| 21 | 21 | |
| @@ -45,11 +45,11 @@ discard block | ||
| 45 | 45 | // TODO: Full rewrite | 
| 46 | 46 | sn_db_transaction_start(); | 
| 47 | 47 | $TheUser = DBStaticUser::db_user_by_id($UserID); | 
| 48 | -  if ( $TheUser['ally_id'] != 0 ) { | |
| 49 | -    $TheAlly = classSupernova::$db->doSelectFetch("SELECT * FROM `{{alliance}}` WHERE `id` = '" . $TheUser['ally_id'] . "';"); | |
| 48 | +  if ($TheUser['ally_id'] != 0) { | |
| 49 | +    $TheAlly = classSupernova::$db->doSelectFetch("SELECT * FROM `{{alliance}}` WHERE `id` = '".$TheUser['ally_id']."';"); | |
| 50 | 50 | $TheAlly['ally_members'] -= 1; | 
| 51 | -    if ( $TheAlly['ally_members'] > 0 ) { | |
| 52 | -      classSupernova::$db->doUpdate( "UPDATE `{{alliance}}` SET `ally_members` = '" . $TheAlly['ally_members'] . "' WHERE `id` = '" . $TheAlly['id'] . "';"); | |
| 51 | +    if ($TheAlly['ally_members'] > 0) { | |
| 52 | +      classSupernova::$db->doUpdate("UPDATE `{{alliance}}` SET `ally_members` = '".$TheAlly['ally_members']."' WHERE `id` = '".$TheAlly['id']."';"); | |
| 53 | 53 |      } else { | 
| 54 | 54 |        classSupernova::$gc->db->doDeleteRowWhere(TABLE_ALLIANCE, array('id' => $TheAlly['id'],)); | 
| 55 | 55 |        classSupernova::$gc->db->doDeleteWhere(TABLE_STAT_POINTS, array('stat_type' => STAT_TYPE_ALLY, 'id_owner' => $TheAlly['id'],)); | 
| @@ -61,10 +61,10 @@ discard block | ||
| 61 | 61 | |
| 62 | 62 |    classSupernova::$gc->db->doDeleteWhere(TABLE_MESSAGES, array('message_owner' => $UserID,)); | 
| 63 | 63 |    classSupernova::$gc->db->doDeleteWhere(TABLE_MESSAGES, array('message_sender' => $UserID,)); | 
| 64 | -  classSupernova::$gc->db->doDeleteWhere(TABLE_NOTES, array('owner' => $UserID ,)); | |
| 64 | +  classSupernova::$gc->db->doDeleteWhere(TABLE_NOTES, array('owner' => $UserID,)); | |
| 65 | 65 | FleetList::db_fleet_list_delete_by_owner($UserID); | 
| 66 | -  classSupernova::$gc->db->doDeleteWhere(TABLE_BUDDY, array('BUDDY_SENDER_ID' => $UserID ,)); | |
| 67 | -  classSupernova::$gc->db->doDeleteWhere(TABLE_BUDDY, array('BUDDY_OWNER_ID' => $UserID ,)); | |
| 66 | +  classSupernova::$gc->db->doDeleteWhere(TABLE_BUDDY, array('BUDDY_SENDER_ID' => $UserID,)); | |
| 67 | +  classSupernova::$gc->db->doDeleteWhere(TABLE_BUDDY, array('BUDDY_OWNER_ID' => $UserID,)); | |
| 68 | 68 | |
| 69 | 69 | |
| 70 | 70 | classSupernova::$gc->cacheOperator->db_del_record_by_id(LOC_USER, $UserID); | 
| @@ -85,7 +85,7 @@ discard block | ||
| 85 | 85 | $ban_current = DBStaticUser::db_user_by_id($banned['id'], false, 'banaday'); | 
| 86 | 86 | $ban_until = ($ban_current['banaday'] ? $ban_current['banaday'] : SN_TIME_NOW) + $term; | 
| 87 | 87 | |
| 88 | -  DBStaticUser::db_user_set_by_id($banned['id'], "`banaday` = {$ban_until} " . ($is_vacation ? ", `vacation` = '{$ban_until}' " : '')); | |
| 88 | +  DBStaticUser::db_user_set_by_id($banned['id'], "`banaday` = {$ban_until} ".($is_vacation ? ", `vacation` = '{$ban_until}' " : '')); | |
| 89 | 89 | |
| 90 | 90 | $banned['username'] = db_escape($banned['username']); | 
| 91 | 91 | $banner['username'] = db_escape($banner['username']); | 
| @@ -103,7 +103,7 @@ discard block | ||
| 103 | 103 | * @param string $reason | 
| 104 | 104 | */ | 
| 105 | 105 |  function sys_admin_player_ban_unset($banner, $banned, $reason = '') { | 
| 106 | - DBStaticUser::db_user_set_by_id($banned['id'], "`banaday` = 0, `vacation` = " . SN_TIME_NOW . ""); | |
| 106 | + DBStaticUser::db_user_set_by_id($banned['id'], "`banaday` = 0, `vacation` = ".SN_TIME_NOW.""); | |
| 107 | 107 | |
| 108 | 108 | $banned['username'] = db_escape($banned['username']); | 
| 109 | 109 | $banner['username'] = db_escape($banner['username']); | 
| @@ -132,7 +132,7 @@ discard block | ||
| 132 | 132 | |
| 133 | 133 | 'total_points' => $options['total_points'] = empty($options['total_points']) ? 0 : $options['total_points'], | 
| 134 | 134 | |
| 135 | - 'options' => (empty($options['options']) ? $player_options_string : $options['options']) . (empty($options['options_extra']) ? '' : $options['options_extra']), | |
| 135 | + 'options' => (empty($options['options']) ? $player_options_string : $options['options']).(empty($options['options_extra']) ? '' : $options['options_extra']), | |
| 136 | 136 | |
| 137 | 137 | 'galaxy' => $options['galaxy'] = intval($options['galaxy'] ? $options['galaxy'] : 0), | 
| 138 | 138 | 'system' => $options['system'] = intval($options['system'] ? $options['system'] : 0), | 
| @@ -143,28 +143,28 @@ discard block | ||
| 143 | 143 | !empty($options['password_encoded_unsafe']) ? $field_set['password'] = $options['password_encoded_unsafe'] : false; | 
| 144 | 144 | |
| 145 | 145 | $user_new = classSupernova::$gc->cacheOperator->db_ins_field_set(LOC_USER, $field_set); | 
| 146 | -  if(!($options['galaxy'] && $options['system'] && $options['planet'])) { | |
| 146 | +  if (!($options['galaxy'] && $options['system'] && $options['planet'])) { | |
| 147 | 147 | $options['galaxy'] = classSupernova::$config->LastSettedGalaxyPos; | 
| 148 | 148 | $options['system'] = classSupernova::$config->LastSettedSystemPos; | 
| 149 | - $segment_size = floor(Vector::$knownPlanets/ 3); | |
| 149 | + $segment_size = floor(Vector::$knownPlanets / 3); | |
| 150 | 150 | $segment = floor(classSupernova::$config->LastSettedPlanetPos / $segment_size); | 
| 151 | 151 | $segment++; | 
| 152 | 152 | $options['planet'] = mt_rand(1 + $segment * $segment_size, ($segment + 1) * $segment_size); | 
| 153 | 153 | |
| 154 | 154 | // $new_planet_id = 0; | 
| 155 | -    while(true) { | |
| 156 | -      if($options['planet'] > Vector::$knownPlanets) { | |
| 155 | +    while (true) { | |
| 156 | +      if ($options['planet'] > Vector::$knownPlanets) { | |
| 157 | 157 | $options['planet'] = mt_rand(0, $segment_size - 1) + 1; | 
| 158 | 158 | $options['system']++; | 
| 159 | 159 | } | 
| 160 | -      if($options['system'] > Vector::$knownSystems) { | |
| 160 | +      if ($options['system'] > Vector::$knownSystems) { | |
| 161 | 161 | $options['system'] = 1; | 
| 162 | 162 | $options['galaxy']++; | 
| 163 | 163 | } | 
| 164 | - $options['galaxy'] > Vector::$knownGalaxies? $options['galaxy'] = 1 : false; | |
| 164 | + $options['galaxy'] > Vector::$knownGalaxies ? $options['galaxy'] = 1 : false; | |
| 165 | 165 | |
| 166 | 166 | $galaxy_row = DBStaticPlanet::db_planet_by_gspt($options['galaxy'], $options['system'], $options['planet'], PT_PLANET, true, 'id'); | 
| 167 | -      if(!$galaxy_row['id']) { | |
| 167 | +      if (!$galaxy_row['id']) { | |
| 168 | 168 | classSupernova::$config->db_saveItem(array( | 
| 169 | 169 | 'LastSettedGalaxyPos' => $options['galaxy'], | 
| 170 | 170 | 'LastSettedSystemPos' => $options['system'], | 
| @@ -186,7 +186,7 @@ discard block | ||
| 186 | 186 | |
| 187 | 187 | db_player_name_history_replace($user_new['id'], $username_unsafe); | 
| 188 | 188 | |
| 189 | -  if(!empty($options['partner_id']) && ($referral_row = DBStaticUser::db_user_by_id($options['partner_id'], true))) { | |
| 189 | +  if (!empty($options['partner_id']) && ($referral_row = DBStaticUser::db_user_by_id($options['partner_id'], true))) { | |
| 190 | 190 | db_referral_insert($options, $user_new); | 
| 191 | 191 | } | 
| 192 | 192 | |
| @@ -1,5 +1,8 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 | |
| 3 | +/** | |
| 4 | + * @return double | |
| 5 | + */ | |
| 3 | 6 | function flt_fleet_speed($user, $fleet) | 
| 4 | 7 |  { | 
| 5 | 8 | if (!is_array($fleet)) | 
| @@ -1,14 +1,14 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | 2 | |
| 3 | 3 |  function flt_fleet_speed($user, $fleet) { | 
| 4 | -  if(!is_array($fleet)) { | |
| 4 | +  if (!is_array($fleet)) { | |
| 5 | 5 | $fleet = array($fleet => 1); | 
| 6 | 6 | } | 
| 7 | 7 | |
| 8 | 8 | $speeds = array(); | 
| 9 | -  if(!empty($fleet)) { | |
| 10 | -    foreach($fleet as $ship_id => $amount) { | |
| 11 | -      if($amount && in_array($ship_id, Fleet::$snGroupFleetAndMissiles)) { | |
| 9 | +  if (!empty($fleet)) { | |
| 10 | +    foreach ($fleet as $ship_id => $amount) { | |
| 11 | +      if ($amount && in_array($ship_id, Fleet::$snGroupFleetAndMissiles)) { | |
| 12 | 12 | $single_ship_data = get_ship_data($ship_id, $user); | 
| 13 | 13 | $speeds[] = $single_ship_data['speed']; | 
| 14 | 14 | } | 
| @@ -40,14 +40,14 @@ discard block | ||
| 40 | 40 | |
| 41 | 41 | $game_fleet_speed = flt_server_flight_speed_multiplier(); | 
| 42 | 42 | $fleet_speed = flt_fleet_speed($user_row, $fleet_array); | 
| 43 | -  if(!empty($fleet_array) && $fleet_speed && $game_fleet_speed) { | |
| 43 | +  if (!empty($fleet_array) && $fleet_speed && $game_fleet_speed) { | |
| 44 | 44 | $speed_percent = $speed_percent ? max(min($speed_percent, 10), 1) : 10; | 
| 45 | 45 | $real_speed = $speed_percent * sqrt($fleet_speed); | 
| 46 | 46 | |
| 47 | 47 | $duration = max(1, round((35000 / $speed_percent * sqrt($distance * 10 / $fleet_speed) + 10) / $game_fleet_speed)); | 
| 48 | 48 | |
| 49 | -    foreach($fleet_array as $ship_id => $ship_count) { | |
| 50 | -      if(!$ship_id || !$ship_count) { | |
| 49 | +    foreach ($fleet_array as $ship_id => $ship_count) { | |
| 50 | +      if (!$ship_id || !$ship_count) { | |
| 51 | 51 | continue; | 
| 52 | 52 | } | 
| 53 | 53 | |
| @@ -75,19 +75,19 @@ discard block | ||
| 75 | 75 |  function flt_bashing_check($user, $enemy, $planet_dst, $mission, $flight_duration, $fleet_group = 0) { | 
| 76 | 76 | $config_bashing_attacks = classSupernova::$config->fleet_bashing_attacks; | 
| 77 | 77 | $config_bashing_interval = classSupernova::$config->fleet_bashing_interval; | 
| 78 | -  if(!$config_bashing_attacks) { | |
| 78 | +  if (!$config_bashing_attacks) { | |
| 79 | 79 | // Bashing allowed - protection disabled | 
| 80 | 80 | return FLIGHT_ALLOWED; | 
| 81 | 81 | } | 
| 82 | 82 | |
| 83 | 83 | $bashing_result = FLIGHT_MISSION_ATTACK_BASHING; | 
| 84 | -  if($user['ally_id'] && $enemy['ally_id']) { | |
| 84 | +  if ($user['ally_id'] && $enemy['ally_id']) { | |
| 85 | 85 | $relations = ali_relations($user['ally_id'], $enemy['ally_id']); | 
| 86 | -    if(!empty($relations)) { | |
| 86 | +    if (!empty($relations)) { | |
| 87 | 87 | $relations = $relations[$enemy['ally_id']]; | 
| 88 | -      switch($relations['alliance_diplomacy_relation']) { | |
| 88 | +      switch ($relations['alliance_diplomacy_relation']) { | |
| 89 | 89 | case ALLY_DIPLOMACY_WAR: | 
| 90 | -          if(SN_TIME_NOW - $relations['alliance_diplomacy_time'] <= classSupernova::$config->fleet_bashing_war_delay) { | |
| 90 | +          if (SN_TIME_NOW - $relations['alliance_diplomacy_time'] <= classSupernova::$config->fleet_bashing_war_delay) { | |
| 91 | 91 | $bashing_result = FLIGHT_MISSION_ATTACK_BASHING_WAR_DELAY; | 
| 92 | 92 |            } else { | 
| 93 | 93 | return FLIGHT_ALLOWED; | 
| @@ -109,9 +109,9 @@ discard block | ||
| 109 | 109 | |
| 110 | 110 | // Retrieving flying fleets | 
| 111 | 111 | $objFleetsBashing = FleetList::dbGetFleetListBashing($user['id'], $planet_dst); | 
| 112 | -  foreach($objFleetsBashing->_container as $fleetBashing) { | |
| 112 | +  foreach ($objFleetsBashing->_container as $fleetBashing) { | |
| 113 | 113 | // Checking for ACS - each ACS count only once | 
| 114 | -    if($fleetBashing->group_id) { | |
| 114 | +    if ($fleetBashing->group_id) { | |
| 115 | 115 |        $bashing_list["{$user['id']}_{$fleetBashing->group_id}"] = $fleetBashing->time_arrive_to_target; | 
| 116 | 116 |      } else { | 
| 117 | 117 | $bashing_list[] = $fleetBashing->time_arrive_to_target; | 
| @@ -119,12 +119,12 @@ discard block | ||
| 119 | 119 | } | 
| 120 | 120 | |
| 121 | 121 | // Check for joining to ACS - if there are already fleets in ACS no checks should be done | 
| 122 | -  if($mission == MT_ACS && $bashing_list["{$user['id']}_{$fleet_group}"]) { | |
| 122 | +  if ($mission == MT_ACS && $bashing_list["{$user['id']}_{$fleet_group}"]) { | |
| 123 | 123 | return FLIGHT_ALLOWED; | 
| 124 | 124 | } | 
| 125 | 125 | |
| 126 | 126 | $query = DBStaticFleetBashing::db_bashing_list_get($user, $planet_dst, $time_limit); | 
| 127 | -  while($bashing_row = db_fetch($query)) { | |
| 127 | +  while ($bashing_row = db_fetch($query)) { | |
| 128 | 128 | $bashing_list[] = $bashing_row['bashing_time']; | 
| 129 | 129 | } | 
| 130 | 130 | |
| @@ -133,9 +133,9 @@ discard block | ||
| 133 | 133 | $last_attack = 0; | 
| 134 | 134 | $wave = 0; | 
| 135 | 135 | $attack = 1; | 
| 136 | -  foreach($bashing_list as &$bash_time) { | |
| 136 | +  foreach ($bashing_list as &$bash_time) { | |
| 137 | 137 | $attack++; | 
| 138 | -    if($bash_time - $last_attack > $config_bashing_interval || $attack > $config_bashing_attacks) { | |
| 138 | +    if ($bash_time - $last_attack > $config_bashing_interval || $attack > $config_bashing_attacks) { | |
| 139 | 139 | $attack = 1; | 
| 140 | 140 | $wave++; | 
| 141 | 141 | } | 
| @@ -152,16 +152,16 @@ discard block | ||
| 152 | 152 | //TODO: try..catch | 
| 153 | 153 | global $user; | 
| 154 | 154 | |
| 155 | -  if($user['vacation']) { | |
| 155 | +  if ($user['vacation']) { | |
| 156 | 156 | return $result = FLIGHT_PLAYER_VACATION_OWN; | 
| 157 | 157 | } | 
| 158 | 158 | |
| 159 | -  if(empty($fleet) || !is_array($fleet)) { | |
| 159 | +  if (empty($fleet) || !is_array($fleet)) { | |
| 160 | 160 | return $result = FLIGHT_SHIPS_NO_SHIPS; | 
| 161 | 161 | } | 
| 162 | 162 | |
| 163 | 163 |    $sn_groups_mission = sn_get_groups('missions'); | 
| 164 | -  if(!isset($sn_groups_mission[$mission])) { | |
| 164 | +  if (!isset($sn_groups_mission[$mission])) { | |
| 165 | 165 | return $result = FLIGHT_MISSION_UNKNOWN; | 
| 166 | 166 | } | 
| 167 | 167 | $sn_data_mission = $sn_groups_mission[$mission]; | 
| @@ -180,32 +180,32 @@ discard block | ||
| 180 | 180 | $resources = 0; | 
| 181 | 181 | $ship_ids = Fleet::$snGroupFleet; | 
| 182 | 182 |    $resource_ids = sn_get_groups('resources_loot'); | 
| 183 | -  foreach($fleet as $ship_id => $ship_count) { | |
| 183 | +  foreach ($fleet as $ship_id => $ship_count) { | |
| 184 | 184 | $is_ship = in_array($ship_id, $ship_ids); | 
| 185 | 185 | $is_resource = in_array($ship_id, $resource_ids); | 
| 186 | -    if(!$is_ship && !$is_resource) { | |
| 186 | +    if (!$is_ship && !$is_resource) { | |
| 187 | 187 | // TODO Спецобработчик для Капитана и модулей | 
| 188 | 188 | // return FLIGHT_SHIPS_UNIT_WRONG; | 
| 189 | 189 | } | 
| 190 | 190 | |
| 191 | -    if($ship_count < 0) { | |
| 191 | +    if ($ship_count < 0) { | |
| 192 | 192 | return $result = $is_ship ? FLIGHT_SHIPS_NEGATIVE : FLIGHT_RESOURCES_NEGATIVE; | 
| 193 | 193 | } | 
| 194 | 194 | |
| 195 | -    if($ship_count > mrc_get_level($user, $planet_src, $ship_id)) { | |
| 195 | +    if ($ship_count > mrc_get_level($user, $planet_src, $ship_id)) { | |
| 196 | 196 | // TODO FLIGHT_MISSION_MISSILE_NO_MISSILES | 
| 197 | 197 | return $result = $is_ship ? FLIGHT_SHIPS_NOT_ENOUGH_OR_RESOURCES : FLIGHT_RESOURCES_NOT_ENOUGH; | 
| 198 | 198 | } | 
| 199 | 199 | |
| 200 | -    if($is_ship) { | |
| 200 | +    if ($is_ship) { | |
| 201 | 201 | $single_ship_data = get_ship_data($ship_id, $user); | 
| 202 | -      if($single_ship_data[P_SPEED] <= 0) { | |
| 202 | +      if ($single_ship_data[P_SPEED] <= 0) { | |
| 203 | 203 | return $result = FLIGHT_SHIPS_UNMOVABLE; | 
| 204 | 204 | } | 
| 205 | 205 | $ships += $ship_count; | 
| 206 | 206 | $recyclers += in_array($ship_id, Fleet::$snGroupRecyclers) ? $ship_count : 0; | 
| 207 | 207 | $spies += $ship_id == SHIP_SPY ? $ship_count : 0; | 
| 208 | -    } elseif($is_resource) { | |
| 208 | +    } elseif ($is_resource) { | |
| 209 | 209 | $resources += $ship_count; | 
| 210 | 210 | } | 
| 211 | 211 | } | 
| @@ -216,7 +216,7 @@ discard block | ||
| 216 | 216 | } | 
| 217 | 217 | */ | 
| 218 | 218 | |
| 219 | -  if(isset($options['resources']) && $options['resources'] > 0 && !(isset($sn_data_mission['transport']) && $sn_data_mission['transport'])) { | |
| 219 | +  if (isset($options['resources']) && $options['resources'] > 0 && !(isset($sn_data_mission['transport']) && $sn_data_mission['transport'])) { | |
| 220 | 220 | return $result = FLIGHT_RESOURCES_FORBIDDEN; | 
| 221 | 221 | } | 
| 222 | 222 | |
| @@ -228,78 +228,78 @@ discard block | ||
| 228 | 228 | */ | 
| 229 | 229 | |
| 230 | 230 | $speed = $options['fleet_speed_percent']; | 
| 231 | -  if($speed && ($speed != intval($speed) || $speed < 1 || $speed > 10)) { | |
| 231 | +  if ($speed && ($speed != intval($speed) || $speed < 1 || $speed > 10)) { | |
| 232 | 232 | return $result = FLIGHT_FLEET_SPEED_WRONG; | 
| 233 | 233 | } | 
| 234 | 234 | |
| 235 | 235 | $travel_data = flt_travel_data($user, $planet_src, $planet_dst, $fleet, $options['fleet_speed_percent']); | 
| 236 | 236 | |
| 237 | 237 | |
| 238 | -  if(mrc_get_level($user, $planet_src, RES_DEUTERIUM) < $fleet[RES_DEUTERIUM] + $travel_data['consumption']) { | |
| 238 | +  if (mrc_get_level($user, $planet_src, RES_DEUTERIUM) < $fleet[RES_DEUTERIUM] + $travel_data['consumption']) { | |
| 239 | 239 | return $result = FLIGHT_RESOURCES_FUEL_NOT_ENOUGH; | 
| 240 | 240 | } | 
| 241 | 241 | |
| 242 | -  if($travel_data['consumption'] > $travel_data['capacity']) { | |
| 242 | +  if ($travel_data['consumption'] > $travel_data['capacity']) { | |
| 243 | 243 | return $result = FLIGHT_FLEET_TOO_FAR; | 
| 244 | 244 | } | 
| 245 | 245 | |
| 246 | -  if($travel_data['hold'] < $resources) { | |
| 246 | +  if ($travel_data['hold'] < $resources) { | |
| 247 | 247 | return $result = FLIGHT_FLEET_OVERLOAD; | 
| 248 | 248 | } | 
| 249 | 249 | |
| 250 | 250 | $fleet_start_time = SN_TIME_NOW + $travel_data['duration']; | 
| 251 | 251 | |
| 252 | 252 | $fleet_group = $options['fleet_group']; | 
| 253 | -  if($fleet_group) { | |
| 254 | -    if($mission != MT_ACS) { | |
| 253 | +  if ($fleet_group) { | |
| 254 | +    if ($mission != MT_ACS) { | |
| 255 | 255 | return $result = FLIGHT_MISSION_IMPOSSIBLE; | 
| 256 | 256 | }; | 
| 257 | 257 | |
| 258 | 258 | $acs = DBStaticFleetACS::db_acs_get_by_group_id($fleet_group); | 
| 259 | -    if(!$acs['id']) { | |
| 259 | +    if (!$acs['id']) { | |
| 260 | 260 | return $result = FLIGHT_MISSION_ACS_NOT_EXISTS; | 
| 261 | 261 | } | 
| 262 | 262 | |
| 263 | -    if($planet_dst['galaxy'] != $acs['galaxy'] || $planet_dst['system'] != $acs['system'] || $planet_dst['planet'] != $acs['planet'] || $planet_dst['planet_type'] != $acs['planet_type']) { | |
| 263 | +    if ($planet_dst['galaxy'] != $acs['galaxy'] || $planet_dst['system'] != $acs['system'] || $planet_dst['planet'] != $acs['planet'] || $planet_dst['planet_type'] != $acs['planet_type']) { | |
| 264 | 264 | return $result = FLIGHT_MISSION_ACS_WRONG_TARGET; | 
| 265 | 265 | } | 
| 266 | 266 | |
| 267 | -    if($fleet_start_time > $acs['ankunft']) { | |
| 267 | +    if ($fleet_start_time > $acs['ankunft']) { | |
| 268 | 268 | return $result = FLIGHT_MISSION_ACS_TOO_LATE; | 
| 269 | 269 | } | 
| 270 | 270 | } | 
| 271 | 271 | |
| 272 | 272 | $flying_fleets = $options['flying_fleets']; | 
| 273 | -  if(!$flying_fleets) { | |
| 273 | +  if (!$flying_fleets) { | |
| 274 | 274 | $flying_fleets = FleetList::fleet_count_flying($user['id']); | 
| 275 | 275 | } | 
| 276 | -  if(GetMaxFleets($user) <= $flying_fleets && $mission != MT_MISSILE) { | |
| 276 | +  if (GetMaxFleets($user) <= $flying_fleets && $mission != MT_MISSILE) { | |
| 277 | 277 | return $result = FLIGHT_FLEET_NO_SLOTS; | 
| 278 | 278 | } | 
| 279 | 279 | |
| 280 | 280 | // В одиночку шпионские зонды могут летать только в миссии Шпионаж, Передислокация и Транспорт | 
| 281 | -  if($ships && $spies && $spies == $ships && !($mission == MT_SPY || $mission == MT_RELOCATE || $mission == MT_TRANSPORT)) { | |
| 281 | +  if ($ships && $spies && $spies == $ships && !($mission == MT_SPY || $mission == MT_RELOCATE || $mission == MT_TRANSPORT)) { | |
| 282 | 282 | return $result = FLIGHT_SHIPS_NOT_ONLY_SPIES; | 
| 283 | 283 | } | 
| 284 | 284 | |
| 285 | 285 | // Checking for no planet | 
| 286 | -  if(!$planet_dst['id_owner']) { | |
| 287 | -    if($mission == MT_COLONIZE && !$fleet[SHIP_COLONIZER]) { | |
| 286 | +  if (!$planet_dst['id_owner']) { | |
| 287 | +    if ($mission == MT_COLONIZE && !$fleet[SHIP_COLONIZER]) { | |
| 288 | 288 | return $result = FLIGHT_SHIPS_NO_COLONIZER; | 
| 289 | 289 | } | 
| 290 | 290 | |
| 291 | -    if($mission == MT_EXPLORE || $mission == MT_COLONIZE) { | |
| 291 | +    if ($mission == MT_EXPLORE || $mission == MT_COLONIZE) { | |
| 292 | 292 | return $result = FLIGHT_ALLOWED; | 
| 293 | 293 | } | 
| 294 | 294 | |
| 295 | 295 | return $result = FLIGHT_VECTOR_NO_TARGET; | 
| 296 | 296 | } | 
| 297 | 297 | |
| 298 | -  if($mission == MT_RECYCLE) { | |
| 299 | -    if($planet_dst['debris_metal'] + $planet_dst['debris_crystal'] <= 0) { | |
| 298 | +  if ($mission == MT_RECYCLE) { | |
| 299 | +    if ($planet_dst['debris_metal'] + $planet_dst['debris_crystal'] <= 0) { | |
| 300 | 300 | return $result = FLIGHT_MISSION_RECYCLE_NO_DEBRIS; | 
| 301 | 301 | } | 
| 302 | -    if($recyclers <= 0) { | |
| 302 | +    if ($recyclers <= 0) { | |
| 303 | 303 | return $result = FLIGHT_SHIPS_NO_RECYCLERS; | 
| 304 | 304 | } | 
| 305 | 305 | |
| @@ -307,8 +307,8 @@ discard block | ||
| 307 | 307 | } | 
| 308 | 308 | |
| 309 | 309 | // Got planet. Checking if it is ours | 
| 310 | -  if($planet_dst['id_owner'] == $user['id']) { | |
| 311 | -    if($mission == MT_TRANSPORT || $mission == MT_RELOCATE) { | |
| 310 | +  if ($planet_dst['id_owner'] == $user['id']) { | |
| 311 | +    if ($mission == MT_TRANSPORT || $mission == MT_RELOCATE) { | |
| 312 | 312 | return $result = FLIGHT_ALLOWED; | 
| 313 | 313 | } | 
| 314 | 314 | |
| @@ -316,19 +316,19 @@ discard block | ||
| 316 | 316 | } | 
| 317 | 317 | |
| 318 | 318 | // No, planet not ours. Cutting mission that can't be send to not-ours planet | 
| 319 | -  if($mission == MT_RELOCATE || $mission == MT_COLONIZE || $mission == MT_EXPLORE) { | |
| 319 | +  if ($mission == MT_RELOCATE || $mission == MT_COLONIZE || $mission == MT_EXPLORE) { | |
| 320 | 320 | return $result = FLIGHT_MISSION_IMPOSSIBLE; | 
| 321 | 321 | } | 
| 322 | 322 | |
| 323 | 323 | $enemy = DBStaticUser::db_user_by_id($planet_dst['id_owner']); | 
| 324 | 324 | // We cannot attack or send resource to users in VACATION mode | 
| 325 | -  if($enemy['vacation'] && $mission != MT_RECYCLE) { | |
| 325 | +  if ($enemy['vacation'] && $mission != MT_RECYCLE) { | |
| 326 | 326 | return $result = FLIGHT_PLAYER_VACATION; | 
| 327 | 327 | } | 
| 328 | 328 | |
| 329 | 329 | // Multi IP protection | 
| 330 | 330 | // TODO: Here we need a procedure to check proxies | 
| 331 | -  if(sys_is_multiaccount($user, $enemy)) { | |
| 331 | +  if (sys_is_multiaccount($user, $enemy)) { | |
| 332 | 332 | return $result = FLIGHT_PLAYER_SAME_IP; | 
| 333 | 333 | } | 
| 334 | 334 | |
| @@ -336,8 +336,8 @@ discard block | ||
| 336 | 336 | $enemy_points = $enemy['total_points']; | 
| 337 | 337 | |
| 338 | 338 | // Is it transport? If yes - checking for buffing to prevent mega-alliance destroyer | 
| 339 | -  if($mission == MT_TRANSPORT) { | |
| 340 | -    if($user_points >= $enemy_points || classSupernova::$config->allow_buffing) { | |
| 339 | +  if ($mission == MT_TRANSPORT) { | |
| 340 | +    if ($user_points >= $enemy_points || classSupernova::$config->allow_buffing) { | |
| 341 | 341 | return $result = FLIGHT_ALLOWED; | 
| 342 | 342 |      } else { | 
| 343 | 343 | return $result = FLIGHT_PLAYER_BUFFING; | 
| @@ -347,66 +347,66 @@ discard block | ||
| 347 | 347 | // Only aggresive missions passed to this point. HOLD counts as passive but aggresive | 
| 348 | 348 | |
| 349 | 349 | // Is it admin with planet protection? | 
| 350 | -  if($planet_dst['id_level'] > $user['authlevel']) { | |
| 350 | +  if ($planet_dst['id_level'] > $user['authlevel']) { | |
| 351 | 351 | return $result = FLIGHT_PLAYER_ADMIN; | 
| 352 | 352 | } | 
| 353 | 353 | |
| 354 | 354 | // Okay. Now skipping protection checks for inactive longer then 1 week | 
| 355 | -  if(!$enemy['onlinetime'] || $enemy['onlinetime'] >= (SN_TIME_NOW - 60 * 60 * 24 * 7)) { | |
| 356 | - if( | |
| 355 | +  if (!$enemy['onlinetime'] || $enemy['onlinetime'] >= (SN_TIME_NOW - 60 * 60 * 24 * 7)) { | |
| 356 | + if ( | |
| 357 | 357 | ($enemy_points <= classSupernova::$config->game_noob_points && $user_points > classSupernova::$config->game_noob_points) | 
| 358 | 358 | || | 
| 359 | 359 | (classSupernova::$config->game_noob_factor && $user_points > $enemy_points * classSupernova::$config->game_noob_factor) | 
| 360 | 360 |      ) { | 
| 361 | -      if($mission != MT_HOLD) { | |
| 361 | +      if ($mission != MT_HOLD) { | |
| 362 | 362 | return $result = FLIGHT_PLAYER_NOOB; | 
| 363 | 363 | } | 
| 364 | -      if($mission == MT_HOLD && !($user['ally_id'] && $user['ally_id'] == $enemy['ally_id'] && classSupernova::$config->ally_help_weak)) { | |
| 364 | +      if ($mission == MT_HOLD && !($user['ally_id'] && $user['ally_id'] == $enemy['ally_id'] && classSupernova::$config->ally_help_weak)) { | |
| 365 | 365 | return $result = FLIGHT_PLAYER_NOOB; | 
| 366 | 366 | } | 
| 367 | 367 | } | 
| 368 | 368 | } | 
| 369 | 369 | |
| 370 | 370 | // Is it HOLD mission? If yes - there should be ally deposit | 
| 371 | -  if($mission == MT_HOLD) { | |
| 372 | -    if(mrc_get_level($user, $planet_dst, STRUC_ALLY_DEPOSIT)) { | |
| 371 | +  if ($mission == MT_HOLD) { | |
| 372 | +    if (mrc_get_level($user, $planet_dst, STRUC_ALLY_DEPOSIT)) { | |
| 373 | 373 | return $result = FLIGHT_ALLOWED; | 
| 374 | 374 | } | 
| 375 | 375 | |
| 376 | 376 | return $result = FLIGHT_MISSION_HOLD_NO_ALLY_DEPOSIT; | 
| 377 | 377 | } | 
| 378 | 378 | |
| 379 | -  if($mission == MT_SPY) { | |
| 379 | +  if ($mission == MT_SPY) { | |
| 380 | 380 | return $result = $spies >= 1 ? FLIGHT_ALLOWED : FLIGHT_MISSION_SPY_NO_SPIES; | 
| 381 | 381 | } | 
| 382 | 382 | |
| 383 | 383 | // Is it MISSILE mission? | 
| 384 | -  if($mission == MT_MISSILE) { | |
| 384 | +  if ($mission == MT_MISSILE) { | |
| 385 | 385 | $sn_data_mip = get_unit_param(UNIT_DEF_MISSILE_INTERPLANET); | 
| 386 | -    if(mrc_get_level($user, $planet_src, STRUC_SILO) < $sn_data_mip[P_REQUIRE][STRUC_SILO]) { | |
| 386 | +    if (mrc_get_level($user, $planet_src, STRUC_SILO) < $sn_data_mip[P_REQUIRE][STRUC_SILO]) { | |
| 387 | 387 | return $result = FLIGHT_MISSION_MISSILE_NO_SILO; | 
| 388 | 388 | } | 
| 389 | 389 | |
| 390 | -    if(!$fleet[UNIT_DEF_MISSILE_INTERPLANET]) { | |
| 390 | +    if (!$fleet[UNIT_DEF_MISSILE_INTERPLANET]) { | |
| 391 | 391 | return $result = FLIGHT_MISSION_MISSILE_NO_MISSILES; | 
| 392 | 392 | } | 
| 393 | 393 | |
| 394 | 394 | $distance = abs($planet_dst['system'] - $planet_src['system']); | 
| 395 | 395 | $mip_range = flt_get_missile_range($user); | 
| 396 | -    if($distance > $mip_range || $planet_dst['galaxy'] != $planet_src['galaxy']) { | |
| 396 | +    if ($distance > $mip_range || $planet_dst['galaxy'] != $planet_src['galaxy']) { | |
| 397 | 397 | return $result = FLIGHT_MISSION_MISSILE_TOO_FAR; | 
| 398 | 398 | } | 
| 399 | 399 | |
| 400 | -    if(isset($options['target_structure']) && $options['target_structure'] && !in_array($options['target_structure'], sn_get_groups('defense_active'))) { | |
| 400 | +    if (isset($options['target_structure']) && $options['target_structure'] && !in_array($options['target_structure'], sn_get_groups('defense_active'))) { | |
| 401 | 401 | return $result = FLIGHT_MISSION_MISSILE_WRONG_STRUCTURE; | 
| 402 | 402 | } | 
| 403 | 403 | } | 
| 404 | 404 | |
| 405 | -  if($mission == MT_DESTROY && $planet_dst['planet_type'] != PT_MOON) { | |
| 405 | +  if ($mission == MT_DESTROY && $planet_dst['planet_type'] != PT_MOON) { | |
| 406 | 406 | return $result = FLIGHT_MISSION_IMPOSSIBLE; | 
| 407 | 407 | } | 
| 408 | 408 | |
| 409 | -  if($mission == MT_ATTACK || $mission == MT_ACS || $mission == MT_DESTROY) { | |
| 409 | +  if ($mission == MT_ATTACK || $mission == MT_ACS || $mission == MT_DESTROY) { | |
| 410 | 410 | return $result = flt_bashing_check($user, $enemy, $planet_dst, $mission, $travel_data['duration'], $fleet_group); | 
| 411 | 411 | } | 
| 412 | 412 | |
| @@ -433,7 +433,7 @@ discard block | ||
| 433 | 433 | $from = $from['planet']; | 
| 434 | 434 | |
| 435 | 435 | $can_attack = flt_can_attack($from, $to, $fleet_REAL_array, $mission, $options); | 
| 436 | -  if($can_attack != FLIGHT_ALLOWED) { | |
| 436 | +  if ($can_attack != FLIGHT_ALLOWED) { | |
| 437 | 437 | $internal_transaction ? sn_db_transaction_rollback() : false; | 
| 438 | 438 | |
| 439 | 439 | return $can_attack; | 
| @@ -444,7 +444,7 @@ discard block | ||
| 444 | 444 | $travel_data = flt_travel_data($user, $from, $to, $fleet_REAL_array, $options['fleet_speed_percent']); | 
| 445 | 445 | |
| 446 | 446 | $time_on_mission = 0; | 
| 447 | -  if($mission == MT_EXPLORE || $mission == MT_HOLD) { | |
| 447 | +  if ($mission == MT_EXPLORE || $mission == MT_HOLD) { | |
| 448 | 448 | // TODO - include some checks about maximum and minumum stay_duration | 
| 449 | 449 | $time_on_mission = $options['stay_time'] * 3600; | 
| 450 | 450 | } | 
| @@ -467,14 +467,14 @@ discard block | ||
| 467 | 467 |    $sn_group_resources_loot = sn_get_groups('resources_loot'); | 
| 468 | 468 | $db_changeset = array(); | 
| 469 | 469 | $planet_row_changed_fields = array(); | 
| 470 | -  foreach($fleet_REAL_array as $unit_id => $amount) { | |
| 471 | -    if(!$amount || !$unit_id) { | |
| 470 | +  foreach ($fleet_REAL_array as $unit_id => $amount) { | |
| 471 | +    if (!$amount || !$unit_id) { | |
| 472 | 472 | continue; | 
| 473 | 473 | } | 
| 474 | 474 | |
| 475 | -    if(in_array($unit_id, $sn_group_fleet)) { | |
| 475 | +    if (in_array($unit_id, $sn_group_fleet)) { | |
| 476 | 476 | $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, -$amount, $user, $from['id']); | 
| 477 | -    } elseif(in_array($unit_id, $sn_group_resources_loot)) { | |
| 477 | +    } elseif (in_array($unit_id, $sn_group_resources_loot)) { | |
| 478 | 478 | $planet_row_changed_fields[pname_resource_name($unit_id)]['delta'] -= $amount; | 
| 479 | 479 | } | 
| 480 | 480 | } | 
| @@ -513,16 +513,16 @@ discard block | ||
| 513 | 513 | |
| 514 | 514 | $ship_data = array(); | 
| 515 | 515 | $fleet_array = array(); | 
| 516 | -  foreach($ship_list as $transport_id => $cork) { | |
| 516 | +  foreach ($ship_list as $transport_id => $cork) { | |
| 517 | 517 | $ship_data[$transport_id] = flt_travel_data($user, $from, $to, array($transport_id => 1), 10); | 
| 518 | 518 | } | 
| 519 | 519 | uasort($ship_data, 'flt_calculate_ship_to_transport_sort'); | 
| 520 | 520 | |
| 521 | 521 | $fleet_capacity = 0; | 
| 522 | 522 | $fuel_total = $fuel_left = mrc_get_level($user, $from, RES_DEUTERIUM); | 
| 523 | -  foreach($ship_data as $transport_id => &$ship_info) { | |
| 523 | +  foreach ($ship_data as $transport_id => &$ship_info) { | |
| 524 | 524 | $ship_loaded = min($ship_list[$transport_id], ceil($resource_amount / $ship_info['hold']), floor($fuel_left / $ship_info['consumption'])); | 
| 525 | -    if($ship_loaded) { | |
| 525 | +    if ($ship_loaded) { | |
| 526 | 526 | $fleet_array[$transport_id] = $ship_loaded; | 
| 527 | 527 | $resource_amount -= min($resource_amount, $ship_info['hold'] * $ship_loaded); | 
| 528 | 528 | $fuel_left -= $ship_info['consumption'] * $ship_loaded; | 
| @@ -29,6 +29,9 @@ | ||
| 29 | 29 | } | 
| 30 | 30 | } | 
| 31 | 31 | |
| 32 | +/** | |
| 33 | + * @param string $group_name | |
| 34 | + */ | |
| 32 | 35 | function flt_spy_scan($target_planet, $group_name, $section_title, $target_user = array()) | 
| 33 | 36 |  { | 
| 34 | 37 | global $lang; | 
| @@ -11,8 +11,8 @@ discard block | ||
| 11 | 11 | */ | 
| 12 | 12 | // ---------------------------------------------------------------------------------------------------------------- | 
| 13 | 13 |  function coe_compress_add_units($unit_group, $target_planet, &$compress_data, $target_user = array()) { | 
| 14 | -  foreach($unit_group as $unit_id) { | |
| 15 | -    if(($unit_count = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) { | |
| 14 | +  foreach ($unit_group as $unit_id) { | |
| 15 | +    if (($unit_count = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) { | |
| 16 | 16 | $compress_data[$unit_id] = $unit_count; | 
| 17 | 17 | } | 
| 18 | 18 | } | 
| @@ -22,8 +22,8 @@ discard block | ||
| 22 | 22 | $classLocale = classLocale::$lang; | 
| 23 | 23 | |
| 24 | 24 |    $result = "<tr><td class=\"c\" colspan=\"4\">{$section_title}</td></tr>"; | 
| 25 | -  foreach(sn_get_groups($group_name) as $unit_id) { | |
| 26 | -    if(($unit_amount = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) { | |
| 25 | +  foreach (sn_get_groups($group_name) as $unit_id) { | |
| 26 | +    if (($unit_amount = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) { | |
| 27 | 27 |        $result .= "<tr><td align=\"left\" colspan=\"3\">{$classLocale['tech'][$unit_id]}</td><td align=\"right\">{$unit_amount}</td></tr>"; | 
| 28 | 28 | } | 
| 29 | 29 | |
| @@ -55,14 +55,14 @@ discard block | ||
| 55 | 55 | |
| 56 | 56 | $objFleet = $mission_data->fleet; | 
| 57 | 57 | |
| 58 | -  if(empty($target_user_row['id']) || empty($target_planet_row['id']) || empty($spying_user_row['id'])) { | |
| 58 | +  if (empty($target_user_row['id']) || empty($target_planet_row['id']) || empty($spying_user_row['id'])) { | |
| 59 | 59 | $objFleet->markReturnedAndSave(); | 
| 60 | 60 | |
| 61 | 61 | return $result; | 
| 62 | 62 | } | 
| 63 | 63 | |
| 64 | 64 | $spy_probes = $objFleet->shipsGetTotalById(SHIP_SPY); | 
| 65 | -  if($spy_probes > 0) { | |
| 65 | +  if ($spy_probes > 0) { | |
| 66 | 66 | $TargetSpyLvl = GetSpyLevel($target_user_row); | 
| 67 | 67 | $CurrentSpyLvl = GetSpyLevel($spying_user_row); | 
| 68 | 68 | $spy_diff_empire = $CurrentSpyLvl - $TargetSpyLvl; | 
| @@ -80,26 +80,26 @@ discard block | ||
| 80 | 80 |      $spy_message .= " ({$classLocale['Player_']} '{$target_user_row['username']}') {$classLocale['On_']} "; | 
| 81 | 81 | $spy_message .= date(FMT_DATE_TIME, $objFleet->time_arrive_to_target); | 
| 82 | 82 | $spy_message .= "</td></tr><tr>"; | 
| 83 | -    $spy_message .= "<td width=220>{$classLocale['sys_metal']}</td><td width=220 align=right>" . pretty_number($target_planet_row['metal']) . "</td>"; | |
| 84 | -    $spy_message .= "<td width=220>{$classLocale['sys_crystal']}</td></td><td width=220 align=right>" . pretty_number($target_planet_row['crystal']) . "</td>"; | |
| 83 | +    $spy_message .= "<td width=220>{$classLocale['sys_metal']}</td><td width=220 align=right>".pretty_number($target_planet_row['metal'])."</td>"; | |
| 84 | +    $spy_message .= "<td width=220>{$classLocale['sys_crystal']}</td></td><td width=220 align=right>".pretty_number($target_planet_row['crystal'])."</td>"; | |
| 85 | 85 | $spy_message .= "</tr><tr>"; | 
| 86 | -    $spy_message .= "<td width=220>{$classLocale['sys_deuterium']}</td><td width=220 align=right>" . pretty_number($target_planet_row['deuterium']) . "</td>"; | |
| 87 | -    $spy_message .= "<td width=220>{$classLocale['sys_energy']}</td><td width=220 align=right>" . pretty_number($target_planet_row['energy_max']) . "</td>"; | |
| 86 | +    $spy_message .= "<td width=220>{$classLocale['sys_deuterium']}</td><td width=220 align=right>".pretty_number($target_planet_row['deuterium'])."</td>"; | |
| 87 | +    $spy_message .= "<td width=220>{$classLocale['sys_energy']}</td><td width=220 align=right>".pretty_number($target_planet_row['energy_max'])."</td>"; | |
| 88 | 88 | $spy_message .= "</tr>"; | 
| 89 | -    if($spy_diff >= 2) { | |
| 90 | - $spy_message .= "<div class='spy_medium'>" . flt_spy_scan($target_planet_row, 'fleet', classLocale::$lang['tech'][UNIT_SHIPS], $target_user_row) . "</div>"; | |
| 89 | +    if ($spy_diff >= 2) { | |
| 90 | + $spy_message .= "<div class='spy_medium'>".flt_spy_scan($target_planet_row, 'fleet', classLocale::$lang['tech'][UNIT_SHIPS], $target_user_row)."</div>"; | |
| 91 | 91 | coe_compress_add_units(Fleet::$snGroupFleet, $target_planet_row, $combat_pack[0]); | 
| 92 | 92 | } | 
| 93 | -    if($spy_diff >= 3) { | |
| 94 | - $spy_message .= "<div class='spy_medium'>" . flt_spy_scan($target_planet_row, 'defense', classLocale::$lang['tech'][UNIT_DEFENCE], $target_user_row) . "</div>"; | |
| 93 | +    if ($spy_diff >= 3) { | |
| 94 | + $spy_message .= "<div class='spy_medium'>".flt_spy_scan($target_planet_row, 'defense', classLocale::$lang['tech'][UNIT_DEFENCE], $target_user_row)."</div>"; | |
| 95 | 95 |        coe_compress_add_units(sn_get_groups('defense_active'), $target_planet_row, $combat_pack[0]); | 
| 96 | 96 | } | 
| 97 | -    if($spy_diff >= 5) { | |
| 98 | - $spy_message .= "<div class='spy_long'>" . flt_spy_scan($target_planet_row, 'structures', classLocale::$lang['tech'][UNIT_STRUCTURES], $target_user_row) . "</div>"; | |
| 97 | +    if ($spy_diff >= 5) { | |
| 98 | + $spy_message .= "<div class='spy_long'>".flt_spy_scan($target_planet_row, 'structures', classLocale::$lang['tech'][UNIT_STRUCTURES], $target_user_row)."</div>"; | |
| 99 | 99 | } | 
| 100 | 100 | |
| 101 | -    if($spy_diff_empire >= 0) { | |
| 102 | - $spy_message .= "<div class='spy_long'>" . flt_spy_scan($target_planet_row, 'tech', classLocale::$lang['tech'][UNIT_TECHNOLOGIES], $target_user_row) . "</div>"; | |
| 101 | +    if ($spy_diff_empire >= 0) { | |
| 102 | + $spy_message .= "<div class='spy_long'>".flt_spy_scan($target_planet_row, 'tech', classLocale::$lang['tech'][UNIT_TECHNOLOGIES], $target_user_row)."</div>"; | |
| 103 | 103 | coe_compress_add_units(array(TECH_WEAPON, TECH_SHIELD, TECH_ARMOR), $target_planet_row, $combat_pack[0], $target_user_row); | 
| 104 | 104 | } | 
| 105 | 105 | // TODO: Наемники, губернаторы, артефакты и прочее имперское | 
| @@ -107,13 +107,13 @@ discard block | ||
| 107 | 107 | $simulator_link = sn_ube_simulator_encode_replay($combat_pack, 'D'); | 
| 108 | 108 | |
| 109 | 109 | $target_unit_list = 0; | 
| 110 | -    foreach(Fleet::$snGroupFleet as $unit_id) { | |
| 110 | +    foreach (Fleet::$snGroupFleet as $unit_id) { | |
| 111 | 111 | $target_unit_list += max(0, mrc_get_level($target_user_row, $target_planet_row, $unit_id, false, true)); | 
| 112 | 112 | } | 
| 113 | 113 | |
| 114 | 114 | $spy_detected = $spy_probes * $target_unit_list / 4 * pow(2, $TargetSpyLvl - $CurrentSpyLvl); | 
| 115 | 115 | |
| 116 | -    if(mt_rand(0, 99) > $spy_detected) { | |
| 116 | +    if (mt_rand(0, 99) > $spy_detected) { | |
| 117 | 117 | $spy_outcome_str = sprintf(classLocale::$lang['sys_mess_spy_detect_chance'], $spy_detected); | 
| 118 | 118 | $spy_detected = false; | 
| 119 | 119 |      } else { | 
| @@ -130,16 +130,16 @@ discard block | ||
| 130 | 130 | |
| 131 | 131 | DBStaticMessages::msg_send_simple_message($spying_user_row['id'], '', $objFleet->time_arrive_to_target, MSG_TYPE_SPY, classLocale::$lang['sys_mess_qg'], classLocale::$lang['sys_mess_spy_report'], $spy_message); | 
| 132 | 132 | |
| 133 | -    $target_message = "{$classLocale['sys_mess_spy_ennemyfleet']} {$spying_planet_row['name']} " . uni_render_coordinates_href($spying_planet_row, '', 3); | |
| 134 | -    $target_message .= " {$classLocale['sys_mess_spy_seen_at']} {$target_planet_row['name']} " . uni_render_coordinates($target_planet_row); | |
| 133 | +    $target_message = "{$classLocale['sys_mess_spy_ennemyfleet']} {$spying_planet_row['name']} ".uni_render_coordinates_href($spying_planet_row, '', 3); | |
| 134 | +    $target_message .= " {$classLocale['sys_mess_spy_seen_at']} {$target_planet_row['name']} ".uni_render_coordinates($target_planet_row); | |
| 135 | 135 | |
| 136 | -    if($spy_detected) { | |
| 136 | +    if ($spy_detected) { | |
| 137 | 137 | $debris_planet_id = $target_planet_row['planet_type'] == PT_PLANET ? $target_planet_row['id'] : $target_planet_row['parent_planet']; | 
| 138 | 138 | |
| 139 | 139 | $spy_cost = get_unit_param(SHIP_SPY, P_COST); | 
| 140 | 140 | |
| 141 | 141 | DBStaticPlanet::db_planet_set_by_id($debris_planet_id, | 
| 142 | - "`debris_metal` = `debris_metal` + " . floor($spy_probes * $spy_cost[RES_METAL] * 0.3) . ", `debris_crystal` = `debris_crystal` + " . floor($spy_probes * $spy_cost[RES_CRYSTAL] * 0.3)); | |
| 142 | + "`debris_metal` = `debris_metal` + ".floor($spy_probes * $spy_cost[RES_METAL] * 0.3).", `debris_crystal` = `debris_crystal` + ".floor($spy_probes * $spy_cost[RES_CRYSTAL] * 0.3)); | |
| 143 | 143 | |
| 144 | 144 |        $target_message .= "<br />{$classLocale['sys_mess_spy_destroyed_enemy']}"; | 
| 145 | 145 | |
| @@ -150,7 +150,7 @@ discard block | ||
| 150 | 150 | DBStaticMessages::msg_send_simple_message($objFleet->target_owner_id, '', $objFleet->time_arrive_to_target, MSG_TYPE_SPY, classLocale::$lang['sys_mess_spy_control'], classLocale::$lang['sys_mess_spy_activity'], $target_message); | 
| 151 | 151 | } | 
| 152 | 152 | |
| 153 | -  if($spy_detected) { | |
| 153 | +  if ($spy_detected) { | |
| 154 | 154 | $objFleet->dbDelete(); | 
| 155 | 155 |    } else { | 
| 156 | 156 | $objFleet->markReturnedAndSave(); | 
| @@ -26,6 +26,10 @@ | ||
| 26 | 26 | return true; | 
| 27 | 27 | } | 
| 28 | 28 | |
| 29 | +/** | |
| 30 | + * @param integer $mode | |
| 31 | + * @param integer $mercenary_id | |
| 32 | + */ | |
| 29 | 33 |  function mrc_mercenary_hire($mode, $user, $mercenary_id) { | 
| 30 | 34 | global $config, $lang, $sn_powerup_buy_discounts; | 
| 31 | 35 | |
| @@ -4,13 +4,13 @@ discard block | ||
| 4 | 4 | |
| 5 | 5 |  function mrc_officer_accessible(&$user, $mercenary_id) { | 
| 6 | 6 | $mercenary_info = get_unit_param($mercenary_id); | 
| 7 | -  if(classSupernova::$config->empire_mercenary_temporary || $mercenary_info[P_UNIT_TYPE] == UNIT_PLANS) { | |
| 7 | +  if (classSupernova::$config->empire_mercenary_temporary || $mercenary_info[P_UNIT_TYPE] == UNIT_PLANS) { | |
| 8 | 8 | return true; | 
| 9 | 9 | } | 
| 10 | 10 | |
| 11 | -  if(isset($mercenary_info[P_REQUIRE])) { | |
| 12 | -    foreach($mercenary_info[P_REQUIRE] as $unit_id => $unit_level) { | |
| 13 | -      if(mrc_get_level($user, null, $unit_id) < $unit_level) { | |
| 11 | +  if (isset($mercenary_info[P_REQUIRE])) { | |
| 12 | +    foreach ($mercenary_info[P_REQUIRE] as $unit_id => $unit_level) { | |
| 13 | +      if (mrc_get_level($user, null, $unit_id) < $unit_level) { | |
| 14 | 14 | return false; | 
| 15 | 15 | } | 
| 16 | 16 | } | 
| @@ -26,35 +26,35 @@ discard block | ||
| 26 | 26 | $is_permanent = $mode == UNIT_PLANS || !classSupernova::$config->empire_mercenary_temporary; | 
| 27 | 27 | $cost_alliance_multiplyer = (SN_IN_ALLY === true && $mode == UNIT_PLANS ? classSupernova::$config->ali_bonus_members : 1); | 
| 28 | 28 | $cost_alliance_multiplyer = $cost_alliance_multiplyer >= 1 ? $cost_alliance_multiplyer : 1; | 
| 29 | -    if(!in_array($mercenary_id, sn_get_groups($mode == UNIT_PLANS ? 'plans' : 'mercenaries'))) { | |
| 29 | +    if (!in_array($mercenary_id, sn_get_groups($mode == UNIT_PLANS ? 'plans' : 'mercenaries'))) { | |
| 30 | 30 | throw new Exception(classLocale::$lang['mrc_msg_error_wrong_mercenary'], ERR_ERROR); | 
| 31 | 31 | } | 
| 32 | 32 | |
| 33 | -    if(!mrc_officer_accessible($user, $mercenary_id)) { | |
| 33 | +    if (!mrc_officer_accessible($user, $mercenary_id)) { | |
| 34 | 34 | throw new Exception(classLocale::$lang['mrc_msg_error_requirements'], ERR_ERROR); | 
| 35 | 35 | } | 
| 36 | 36 | |
| 37 | 37 |      $mercenary_level = sys_get_param_int('mercenary_level'); | 
| 38 | -    if($mercenary_level < 0 || $mercenary_level > get_unit_param($mercenary_id, P_MAX_STACK)) { | |
| 38 | +    if ($mercenary_level < 0 || $mercenary_level > get_unit_param($mercenary_id, P_MAX_STACK)) { | |
| 39 | 39 | throw new Exception(classLocale::$lang['mrc_msg_error_wrong_level'], ERR_ERROR); | 
| 40 | 40 | } | 
| 41 | 41 | |
| 42 | -    if($mercenary_level && !array_key_exists($mercenary_period = sys_get_param_int('mercenary_period'), $sn_powerup_buy_discounts)) { | |
| 42 | +    if ($mercenary_level && !array_key_exists($mercenary_period = sys_get_param_int('mercenary_period'), $sn_powerup_buy_discounts)) { | |
| 43 | 43 | throw new Exception(classLocale::$lang['mrc_msg_error_wrong_period'], ERR_ERROR); | 
| 44 | 44 | } | 
| 45 | 45 | |
| 46 | 46 | sn_db_transaction_start(); | 
| 47 | 47 | |
| 48 | 48 | $mercenary_level_old = mrc_get_level($user, $planetrow, $mercenary_id, true, true); | 
| 49 | -    if(classSupernova::$config->empire_mercenary_temporary && $mercenary_level_old && $mercenary_level) { | |
| 49 | +    if (classSupernova::$config->empire_mercenary_temporary && $mercenary_level_old && $mercenary_level) { | |
| 50 | 50 | throw new Exception(classLocale::$lang['mrc_msg_error_already_hired'], ERR_ERROR); // Can't hire already hired temp mercenary - dismiss first | 
| 51 | -    } elseif(classSupernova::$config->empire_mercenary_temporary && !$mercenary_level_old && !$mercenary_level) { | |
| 51 | +    } elseif (classSupernova::$config->empire_mercenary_temporary && !$mercenary_level_old && !$mercenary_level) { | |
| 52 | 52 |        throw new Exception('', ERR_NONE); // Can't dismiss (!$mercenary_level) not hired (!$mercenary_level_old) temp mercenary. But no error | 
| 53 | 53 | } | 
| 54 | 54 | |
| 55 | -    if($mercenary_level) { | |
| 55 | +    if ($mercenary_level) { | |
| 56 | 56 | $darkmater_cost = eco_get_total_cost($mercenary_id, $mercenary_level); | 
| 57 | -      if(!classSupernova::$config->empire_mercenary_temporary && $mercenary_level_old) { | |
| 57 | +      if (!classSupernova::$config->empire_mercenary_temporary && $mercenary_level_old) { | |
| 58 | 58 | $darkmater_cost_old = eco_get_total_cost($mercenary_id, $mercenary_level_old); | 
| 59 | 59 | $darkmater_cost[BUILD_CREATE][RES_DARK_MATTER] -= $darkmater_cost_old[BUILD_CREATE][RES_DARK_MATTER]; | 
| 60 | 60 | } | 
| @@ -64,13 +64,13 @@ discard block | ||
| 64 | 64 | } | 
| 65 | 65 | $darkmater_cost *= $cost_alliance_multiplyer; | 
| 66 | 66 | |
| 67 | -    if(mrc_get_level($user, null, RES_DARK_MATTER) < $darkmater_cost) { | |
| 67 | +    if (mrc_get_level($user, null, RES_DARK_MATTER) < $darkmater_cost) { | |
| 68 | 68 | throw new Exception(classLocale::$lang['mrc_msg_error_no_resource'], ERR_ERROR); | 
| 69 | 69 | } | 
| 70 | 70 | |
| 71 | -    if(($darkmater_cost && $mercenary_level) || !$is_permanent) { | |
| 71 | +    if (($darkmater_cost && $mercenary_level) || !$is_permanent) { | |
| 72 | 72 | $unit_row = db_unit_by_location($user['id'], LOC_USER, $user['id'], $mercenary_id); | 
| 73 | -      if(is_array($unit_row) && ($dismiss_left_days = floor((strtotime($unit_row['unit_time_finish']) - SN_TIME_NOW) / PERIOD_DAY))) { | |
| 73 | +      if (is_array($unit_row) && ($dismiss_left_days = floor((strtotime($unit_row['unit_time_finish']) - SN_TIME_NOW) / PERIOD_DAY))) { | |
| 74 | 74 | $dismiss_full_cost = eco_get_total_cost($mercenary_id, $unit_row['unit_level']); | 
| 75 | 75 | $dismiss_full_cost = $dismiss_full_cost[BUILD_CREATE][RES_DARK_MATTER]; | 
| 76 | 76 | |
| @@ -83,7 +83,7 @@ discard block | ||
| 83 | 83 | db_unit_list_delete($user['id'], LOC_USER, $user['id'], $mercenary_id); | 
| 84 | 84 | } | 
| 85 | 85 | |
| 86 | -    if($darkmater_cost && $mercenary_level) { | |
| 86 | +    if ($darkmater_cost && $mercenary_level) { | |
| 87 | 87 | db_unit_set_insert( | 
| 88 | 88 |          "unit_player_id = {$user['id']}, | 
| 89 | 89 | unit_location_type = " . LOC_USER . ", | 
| @@ -100,7 +100,7 @@ discard block | ||
| 100 | 100 | } | 
| 101 | 101 | sn_db_transaction_commit(); | 
| 102 | 102 | sys_redirect($_SERVER['REQUEST_URI']); | 
| 103 | -  } catch(Exception $e) { | |
| 103 | +  } catch (Exception $e) { | |
| 104 | 104 | sn_db_transaction_rollback(); | 
| 105 | 105 | $operation_result = array( | 
| 106 | 106 | 'STATUS' => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR, | 
| @@ -118,7 +118,7 @@ discard block | ||
| 118 | 118 | $mode = in_array($mode, array(UNIT_MERCENARIES, UNIT_PLANS)) ? $mode : UNIT_MERCENARIES; | 
| 119 | 119 | $is_permanent = $mode == UNIT_PLANS || !classSupernova::$config->empire_mercenary_temporary; | 
| 120 | 120 | |
| 121 | -  if($mercenary_id = sys_get_param_int('mercenary_id')) { | |
| 121 | +  if ($mercenary_id = sys_get_param_int('mercenary_id')) { | |
| 122 | 122 | $operation_result = mrc_mercenary_hire($mode, $user, $mercenary_id); | 
| 123 | 123 | } | 
| 124 | 124 | |
| @@ -126,11 +126,11 @@ discard block | ||
| 126 | 126 | |
| 127 | 127 |    $template = gettemplate('mrc_mercenary_hire', true); | 
| 128 | 128 | |
| 129 | -  if(!empty($operation_result)) { | |
| 129 | +  if (!empty($operation_result)) { | |
| 130 | 130 |      $template->assign_block_vars('result', $operation_result); | 
| 131 | 131 | } | 
| 132 | 132 | |
| 133 | -  foreach($sn_powerup_buy_discounts as $hire_period => $hire_discount) { | |
| 133 | +  foreach ($sn_powerup_buy_discounts as $hire_period => $hire_discount) { | |
| 134 | 134 |      $template->assign_block_vars('period', array( | 
| 135 | 135 | 'LENGTH' => $hire_period, | 
| 136 | 136 | 'TEXT' => classLocale::$lang['mrc_period_list'][$hire_period], | 
| @@ -142,12 +142,12 @@ discard block | ||
| 142 | 142 | $user_dark_matter = mrc_get_level($user, null, RES_DARK_MATTER); | 
| 143 | 143 | $cost_alliance_multiplyer = (SN_IN_ALLY === true && $mode == UNIT_PLANS ? classSupernova::$config->ali_bonus_members : 1); | 
| 144 | 144 | $cost_alliance_multiplyer = $cost_alliance_multiplyer >= 1 ? $cost_alliance_multiplyer : 1; | 
| 145 | -  foreach(sn_get_groups($mode == UNIT_PLANS ? 'plans' : 'mercenaries') as $mercenary_id) { | |
| 145 | +  foreach (sn_get_groups($mode == UNIT_PLANS ? 'plans' : 'mercenaries') as $mercenary_id) { | |
| 146 | 146 |      { | 
| 147 | 147 | $mercenary = get_unit_param($mercenary_id); | 
| 148 | 148 | $mercenary_bonus = $mercenary['bonus']; | 
| 149 | 149 |        $mercenary_bonus = $mercenary_bonus >= 0 ? "+{$mercenary_bonus}" : "{$mercenary_bonus}"; | 
| 150 | -      switch($mercenary['bonus_type']) { | |
| 150 | +      switch ($mercenary['bonus_type']) { | |
| 151 | 151 | case BONUS_PERCENT: | 
| 152 | 152 |            $mercenary_bonus = "{$mercenary_bonus}% "; | 
| 153 | 153 | break; | 
| @@ -164,7 +164,7 @@ discard block | ||
| 164 | 164 | $mercenary_level = mrc_get_level($user, null, $mercenary_id, false, true); | 
| 165 | 165 | $mercenary_level_bonus = max(0, mrc_get_level($user, null, $mercenary_id) - $mercenary_level); | 
| 166 | 166 | $total_cost_old = 0; | 
| 167 | -      if($is_permanent) { | |
| 167 | +      if ($is_permanent) { | |
| 168 | 168 | $total_cost_old = eco_get_total_cost($mercenary_id, $mercenary_level); | 
| 169 | 169 | $total_cost_old = $total_cost_old[BUILD_CREATE][RES_DARK_MATTER] * $cost_alliance_multiplyer; | 
| 170 | 170 | } | 
| @@ -193,7 +193,7 @@ discard block | ||
| 193 | 193 | )); | 
| 194 | 194 | |
| 195 | 195 | $upgrade_cost = 1; | 
| 196 | -      for($i = classSupernova::$config->empire_mercenary_temporary ? 1 : $mercenary_level + 1; $mercenary['max'] ? ($i <= $mercenary['max']) : $upgrade_cost <= $user_dark_matter; $i++) { | |
| 196 | +      for ($i = classSupernova::$config->empire_mercenary_temporary ? 1 : $mercenary_level + 1; $mercenary['max'] ? ($i <= $mercenary['max']) : $upgrade_cost <= $user_dark_matter; $i++) { | |
| 197 | 197 | $total_cost = eco_get_total_cost($mercenary_id, $i); | 
| 198 | 198 | $total_cost[BUILD_CREATE][RES_DARK_MATTER] *= $cost_alliance_multiplyer; | 
| 199 | 199 | $upgrade_cost = $total_cost[BUILD_CREATE][RES_DARK_MATTER] - $total_cost_old; |