@@ -4,16 +4,14 @@ discard block |
||
| 4 | 4 | return $q != 1 ? ($b1 * (pow($q, $n) - 1)/($q - 1)) : ($n * $b1); |
| 5 | 5 | } |
| 6 | 6 | |
| 7 | -function sn_floor($value) |
|
| 8 | -{ |
|
| 7 | +function sn_floor($value) { |
|
| 9 | 8 | return $value >= 0 ? floor($value) : ceil($value); |
| 10 | 9 | } |
| 11 | 10 | |
| 12 | 11 | // Эта функция выдает нормально распределенное случайное число с матожиднием $mu и стандартным отклонением $sigma |
| 13 | 12 | // $strict - количество $sigma, по которым идет округление функции. Т.е. $strict = 3 означает, что диапазон значений обрезается по +-3 * $sigma |
| 14 | 13 | // Используется http://ru.wikipedia.org/wiki/Преобразование_Бокса_—_Мюллера |
| 15 | -function sn_rand_gauss($mu = 0, $sigma = 1, $strict = false) |
|
| 16 | -{ |
|
| 14 | +function sn_rand_gauss($mu = 0, $sigma = 1, $strict = false) { |
|
| 17 | 15 | // http://ru.wikipedia.org/wiki/Среднеквадратическое_отклонение |
| 18 | 16 | // При $mu = 0 (график симметричный, цифры только для половины графика) |
| 19 | 17 | // От 0 до $sigma ~ 34.1% |
@@ -43,7 +41,7 @@ discard block |
||
| 43 | 41 | * |
| 44 | 42 | * @return float|int |
| 45 | 43 | */ |
| 46 | -function sn_rand_gauss_range($range_start, $range_end, $round = true, $strict = 4, $cut_extreme = false) { |
|
| 44 | +function sn_rand_gauss_range($range_start, $range_end, $round = true, $strict = 4, $cut_extreme = false) { |
|
| 47 | 45 | if($cut_extreme) { |
| 48 | 46 | $range_start--; |
| 49 | 47 | $range_end++; |
@@ -98,12 +96,10 @@ discard block |
||
| 98 | 96 | * |
| 99 | 97 | * @return float |
| 100 | 98 | */ |
| 101 | -function avg($array) |
|
| 102 | -{ |
|
| 99 | +function avg($array) { |
|
| 103 | 100 | return is_array($array) && count($array) ? array_sum($array) / count($array) : 0; |
| 104 | 101 | } |
| 105 | -function linear_calc(&$linear, $from = 0, $debug = false) |
|
| 106 | -{ |
|
| 102 | +function linear_calc(&$linear, $from = 0, $debug = false) { |
|
| 107 | 103 | for($i = $from; $i < count($linear); $i++) |
| 108 | 104 | { |
| 109 | 105 | $eq = &$linear[$i]; |
@@ -112,7 +108,9 @@ discard block |
||
| 112 | 108 | $eq[$j] /= $eq[$from]; |
| 113 | 109 | } |
| 114 | 110 | } |
| 115 | - if($debug) pdump($linear, 'Нормализовано по х' . $from); |
|
| 111 | + if($debug) { |
|
| 112 | + pdump($linear, 'Нормализовано по х' . $from); |
|
| 113 | + } |
|
| 116 | 114 | |
| 117 | 115 | for($i = $from + 1; $i < count($linear); $i++) |
| 118 | 116 | { |
@@ -122,7 +120,9 @@ discard block |
||
| 122 | 120 | $eq[$j] -= $linear[$from][$j]; |
| 123 | 121 | } |
| 124 | 122 | } |
| 125 | - if($debug) pdump($linear, 'Подставили х' . $from); |
|
| 123 | + if($debug) { |
|
| 124 | + pdump($linear, 'Подставили х' . $from); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | 127 | if($from < count($linear) - 1) |
| 128 | 128 | { |
@@ -139,11 +139,14 @@ discard block |
||
| 139 | 139 | $eq[$j] = $eq[$j] - $eq[$from] * $linear[$from][$j]; |
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | - if($debug) pdump($linear, 'Подставили обратно х' . $from); |
|
| 143 | - } |
|
| 144 | - else |
|
| 142 | + if($debug) { |
|
| 143 | + pdump($linear, 'Подставили обратно х' . $from); |
|
| 144 | + } |
|
| 145 | + } else |
|
| 145 | 146 | { |
| 146 | - if($debug) pdump($linear, 'Результат' . $from); |
|
| 147 | + if($debug) { |
|
| 148 | + pdump($linear, 'Результат' . $from); |
|
| 149 | + } |
|
| 147 | 150 | foreach($linear as $index => &$eq) |
| 148 | 151 | { |
| 149 | 152 | pdump($eq[count($linear)], 'x' . $index); |
@@ -2,12 +2,10 @@ |
||
| 2 | 2 | |
| 3 | 3 | // Эти функции будут переписаны по добавлению инфы в БД |
| 4 | 4 | |
| 5 | -function pname_factory_production_field_name($factory_unit_id) |
|
| 6 | -{ |
|
| 5 | +function pname_factory_production_field_name($factory_unit_id) { |
|
| 7 | 6 | return get_unit_param($factory_unit_id, P_NAME) . '_porcent'; |
| 8 | 7 | } |
| 9 | 8 | |
| 10 | -function pname_resource_name($resource_id) |
|
| 11 | -{ |
|
| 9 | +function pname_resource_name($resource_id) { |
|
| 12 | 10 | return get_unit_param($resource_id, P_NAME); |
| 13 | 11 | } |
| 14 | 12 | \ No newline at end of file |
@@ -2,8 +2,7 @@ |
||
| 2 | 2 | |
| 3 | 3 | use Fleet\DbFleetStatic; |
| 4 | 4 | |
| 5 | -function flt_mission_hold(&$mission_data) |
|
| 6 | -{ |
|
| 5 | +function flt_mission_hold(&$mission_data) { |
|
| 7 | 6 | if($mission_data['fleet']['fleet_end_stay'] < SN_TIME_NOW) |
| 8 | 7 | { |
| 9 | 8 | DbFleetStatic::fleet_send_back($mission_data['fleet']); |
@@ -3,8 +3,7 @@ discard block |
||
| 3 | 3 | * Created by Gorlum 05.08.2018 8:05 |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | -class Timer |
|
| 7 | -{ |
|
| 6 | +class Timer { |
|
| 8 | 7 | /** |
| 9 | 8 | * @var array[] $times [ |
| 10 | 9 | * 'time' => (float)microtime(true), |
@@ -14,8 +13,7 @@ discard block |
||
| 14 | 13 | */ |
| 15 | 14 | private static $times = []; |
| 16 | 15 | |
| 17 | - public static function init() |
|
| 18 | - { |
|
| 16 | + public static function init() { |
|
| 19 | 17 | if (empty(static::$times)) { |
| 20 | 18 | static::$times[] = ['time' => microtime(true)]; |
| 21 | 19 | } |
@@ -24,8 +22,7 @@ discard block |
||
| 24 | 22 | /** |
| 25 | 23 | * @param string $message Message to attach to timestamp |
| 26 | 24 | */ |
| 27 | - public static function mark($message = '') |
|
| 28 | - { |
|
| 25 | + public static function mark($message = '') { |
|
| 29 | 26 | static::init(); |
| 30 | 27 | |
| 31 | 28 | foreach (debug_backtrace() as $trace) { |
@@ -51,8 +48,7 @@ discard block |
||
| 51 | 48 | * |
| 52 | 49 | * @return string |
| 53 | 50 | */ |
| 54 | - public static function elapsed($message = '', $fromStart = false) |
|
| 55 | - { |
|
| 51 | + public static function elapsed($message = '', $fromStart = false) { |
|
| 56 | 52 | $prevTime = $fromStart ? static::first()['time'] : static::last()['time']; |
| 57 | 53 | |
| 58 | 54 | static::mark($message); |
@@ -62,8 +58,7 @@ discard block |
||
| 62 | 58 | return number_format(static::last()['time'] - $prevTime, 6) . 's'; |
| 63 | 59 | } |
| 64 | 60 | |
| 65 | - public static function msg($message, $fromStart = false) |
|
| 66 | - { |
|
| 61 | + public static function msg($message, $fromStart = false) { |
|
| 67 | 62 | |
| 68 | 63 | $message . |
| 69 | 64 | ($fromStart ? ' FROM START ' : ' in ') . |
@@ -75,21 +70,18 @@ discard block |
||
| 75 | 70 | /** |
| 76 | 71 | * @return mixed |
| 77 | 72 | */ |
| 78 | - public static function last() |
|
| 79 | - { |
|
| 73 | + public static function last() { |
|
| 80 | 74 | return end(static::$times); |
| 81 | 75 | } |
| 82 | 76 | |
| 83 | 77 | /** |
| 84 | 78 | * @return mixed |
| 85 | 79 | */ |
| 86 | - public static function first() |
|
| 87 | - { |
|
| 80 | + public static function first() { |
|
| 88 | 81 | return reset(static::$times); |
| 89 | 82 | } |
| 90 | 83 | |
| 91 | - public static function getLog() |
|
| 92 | - { |
|
| 84 | + public static function getLog() { |
|
| 93 | 85 | return static::$times; |
| 94 | 86 | } |
| 95 | 87 | |
@@ -23,18 +23,24 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | // Test de coherance de la destination (voir si elle se trouve dans les limites de l'univers connu |
| 25 | 25 | $errorlist = ''; |
| 26 | - if (!$galaxy || $galaxy > $config->game_maxGalaxy || $galaxy < 1) |
|
| 27 | - $errorlist .= $lang['fl_limit_galaxy']; |
|
| 28 | - if (!$system || $system > $config->game_maxSystem || $system < 1) |
|
| 29 | - $errorlist .= $lang['fl_limit_system']; |
|
| 30 | - if (!$planet || $planet < 1 || ($planet > $config->game_maxPlanet && $target_mission != MT_EXPLORE )) |
|
| 31 | - $errorlist .= $lang['fl_limit_planet']; |
|
| 32 | - if ($planetrow['galaxy'] == $galaxy && $planetrow['system'] == $system && $planetrow['planet'] == $planet && $planetrow['planet_type'] == $planet_type) |
|
| 33 | - $errorlist .= $lang['fl_ownpl_err']; |
|
| 34 | - if (!$planet_type) |
|
| 35 | - $errorlist .= $lang['fl_no_planettype']; |
|
| 36 | - if ($planet_type != PT_PLANET && $planet_type != PT_DEBRIS && $planet_type != PT_MOON) |
|
| 37 | - $errorlist .= $lang['fl_fleet_err_pl']; |
|
| 26 | + if (!$galaxy || $galaxy > $config->game_maxGalaxy || $galaxy < 1) { |
|
| 27 | + $errorlist .= $lang['fl_limit_galaxy']; |
|
| 28 | + } |
|
| 29 | + if (!$system || $system > $config->game_maxSystem || $system < 1) { |
|
| 30 | + $errorlist .= $lang['fl_limit_system']; |
|
| 31 | + } |
|
| 32 | + if (!$planet || $planet < 1 || ($planet > $config->game_maxPlanet && $target_mission != MT_EXPLORE )) { |
|
| 33 | + $errorlist .= $lang['fl_limit_planet']; |
|
| 34 | + } |
|
| 35 | + if ($planetrow['galaxy'] == $galaxy && $planetrow['system'] == $system && $planetrow['planet'] == $planet && $planetrow['planet_type'] == $planet_type) { |
|
| 36 | + $errorlist .= $lang['fl_ownpl_err']; |
|
| 37 | + } |
|
| 38 | + if (!$planet_type) { |
|
| 39 | + $errorlist .= $lang['fl_no_planettype']; |
|
| 40 | + } |
|
| 41 | + if ($planet_type != PT_PLANET && $planet_type != PT_DEBRIS && $planet_type != PT_MOON) { |
|
| 42 | + $errorlist .= $lang['fl_fleet_err_pl']; |
|
| 43 | + } |
|
| 38 | 44 | if (empty($missiontype[$target_mission])) { |
| 39 | 45 | $errorlist .= $lang['fl_bad_mission']; |
| 40 | 46 | } |
@@ -61,29 +67,35 @@ discard block |
||
| 61 | 67 | } |
| 62 | 68 | } else { |
| 63 | 69 | if ($TargetPlanet['id_owner']){ |
| 64 | - if ($target_mission == MT_COLONIZE) |
|
| 65 | - $errorlist .= $lang['fl_colonized']; |
|
| 70 | + if ($target_mission == MT_COLONIZE) { |
|
| 71 | + $errorlist .= $lang['fl_colonized']; |
|
| 72 | + } |
|
| 66 | 73 | |
| 67 | 74 | if ($TargetPlanet['id_owner'] == $planetrow['id_owner']){ |
| 68 | - if ($target_mission == MT_ATTACK) |
|
| 69 | - $errorlist .= $lang['fl_no_self_attack']; |
|
| 70 | - |
|
| 71 | - if ($target_mission == MT_SPY) |
|
| 72 | - $errorlist .= $lang['fl_no_self_spy']; |
|
| 73 | - }else{ |
|
| 74 | - if ($target_mission == MT_RELOCATE) |
|
| 75 | - $errorlist .= $lang['fl_only_stay_at_home']; |
|
| 75 | + if ($target_mission == MT_ATTACK) { |
|
| 76 | + $errorlist .= $lang['fl_no_self_attack']; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + if ($target_mission == MT_SPY) { |
|
| 80 | + $errorlist .= $lang['fl_no_self_spy']; |
|
| 81 | + } |
|
| 82 | + } else{ |
|
| 83 | + if ($target_mission == MT_RELOCATE) { |
|
| 84 | + $errorlist .= $lang['fl_only_stay_at_home']; |
|
| 85 | + } |
|
| 76 | 86 | } |
| 77 | - }else{ |
|
| 87 | + } else{ |
|
| 78 | 88 | if ($target_mission < MT_COLONIZE){ |
| 79 | 89 | $errorlist .= $lang['fl_unknow_target']; |
| 80 | - }else{ |
|
| 81 | - if ($target_mission == MT_DESTROY) |
|
| 82 | - $errorlist .= $lang['fl_nomoon']; |
|
| 90 | + } else{ |
|
| 91 | + if ($target_mission == MT_DESTROY) { |
|
| 92 | + $errorlist .= $lang['fl_nomoon']; |
|
| 93 | + } |
|
| 83 | 94 | |
| 84 | 95 | if ($target_mission == MT_RECYCLE){ |
| 85 | - if($TargetPlanet['debris_metal'] + $TargetPlanet['debris_crystal'] == 0) |
|
| 86 | - $errorlist .= $lang['fl_nodebris']; |
|
| 96 | + if($TargetPlanet['debris_metal'] + $TargetPlanet['debris_crystal'] == 0) { |
|
| 97 | + $errorlist .= $lang['fl_nodebris']; |
|
| 98 | + } |
|
| 87 | 99 | } |
| 88 | 100 | } |
| 89 | 101 | } |
@@ -131,8 +143,7 @@ discard block |
||
| 131 | 143 | $aks = DbFleetStatic::dbAcsGetById($fleet_group); |
| 132 | 144 | if (!$aks) { |
| 133 | 145 | $fleet_group = 0; |
| 134 | - } |
|
| 135 | - else |
|
| 146 | + } else |
|
| 136 | 147 | { |
| 137 | 148 | $galaxy = $aks['galaxy']; |
| 138 | 149 | $system = $aks['system']; |