@@ -8,8 +8,8 @@ discard block |
||
8 | 8 | * @copyright 2008 by ??????? for XNova |
9 | 9 | */ |
10 | 10 | |
11 | -define('INSIDE' , true); |
|
12 | -define('INSTALL' , false); |
|
11 | +define('INSIDE', true); |
|
12 | +define('INSTALL', false); |
|
13 | 13 | define('IN_ADMIN', true); |
14 | 14 | require('../common.' . substr(strrchr(__FILE__, '.'), 1)); |
15 | 15 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | |
20 | 20 | $template = gettemplate('admin/settings', true); |
21 | 21 | |
22 | -if(sys_get_param('save')) { |
|
22 | +if (sys_get_param('save')) { |
|
23 | 23 | classSupernova::$config->game_name = sys_get_param_str_unsafe('game_name'); |
24 | 24 | classSupernova::$config->game_mode = sys_get_param_int('game_mode'); |
25 | 25 | classSupernova::$config->game_speed = sys_get_param_float('game_speed', 1); |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | classSupernova::$config->url_faq = sys_get_param_str_unsafe('url_faq'); |
30 | 30 | classSupernova::$config->url_forum = sys_get_param_str_unsafe('url_forum'); |
31 | 31 | classSupernova::$config->url_rules = sys_get_param_str_unsafe('url_rules'); |
32 | - classSupernova::$config->url_purchase_metamatter = sys_get_param_str_unsafe('url_purchase_metamatter'); |
|
32 | + classSupernova::$config->url_purchase_metamatter = sys_get_param_str_unsafe('url_purchase_metamatter'); |
|
33 | 33 | classSupernova::$config->game_disable = sys_get_param_int('game_disable'); |
34 | 34 | classSupernova::$config->game_disable_reason = sys_get_param_str_unsafe('game_disable_reason'); |
35 | 35 | classSupernova::$config->server_updater_check_auto = sys_get_param_int('server_updater_check_auto'); |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | classSupernova::$config->stats_schedule = sys_get_param_str('stats_schedule'); |
97 | 97 | |
98 | 98 | classSupernova::$config->empire_mercenary_base_period = sys_get_param_int('empire_mercenary_base_period'); |
99 | - if(classSupernova::$config->empire_mercenary_temporary != sys_get_param_int('empire_mercenary_temporary')) { |
|
100 | - if(classSupernova::$config->empire_mercenary_temporary) { |
|
99 | + if (classSupernova::$config->empire_mercenary_temporary != sys_get_param_int('empire_mercenary_temporary')) { |
|
100 | + if (classSupernova::$config->empire_mercenary_temporary) { |
|
101 | 101 | DBStaticUnit::db_unit_list_admin_delete_mercenaries_finished(); |
102 | 102 | } else { |
103 | 103 | DBStaticUnit::db_unit_list_admin_set_mercenaries_expire_time(classSupernova::$config->empire_mercenary_base_period); |
@@ -140,21 +140,21 @@ discard block |
||
140 | 140 | // 'STATS_SCHEDULE' => classSupernova::$config->stats_hide_player_list, |
141 | 141 | )); |
142 | 142 | |
143 | -foreach($lang['sys_game_disable_reason'] as $id => $name) { |
|
143 | +foreach ($lang['sys_game_disable_reason'] as $id => $name) { |
|
144 | 144 | $template->assign_block_vars('sys_game_disable_reason', array( |
145 | 145 | 'ID' => $id, |
146 | 146 | 'NAME' => $name, |
147 | 147 | )); |
148 | 148 | } |
149 | 149 | |
150 | -foreach($lang['sys_game_mode'] as $mode_id => $mode_name) { |
|
150 | +foreach ($lang['sys_game_mode'] as $mode_id => $mode_name) { |
|
151 | 151 | $template->assign_block_vars('game_modes', array( |
152 | 152 | 'ID' => $mode_id, |
153 | 153 | 'NAME' => $mode_name, |
154 | 154 | )); |
155 | 155 | } |
156 | 156 | |
157 | -foreach($lang['adm_opt_ver_response'] as $ver_id => $ver_response) { |
|
157 | +foreach ($lang['adm_opt_ver_response'] as $ver_id => $ver_response) { |
|
158 | 158 | $template->assign_block_vars('ver_response', array( |
159 | 159 | 'ID' => $ver_id, |
160 | 160 | 'NAME' => js_safe_string($ver_response), |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | } |
163 | 163 | |
164 | 164 | $lang_list = lng_get_list(); |
165 | -foreach($lang_list as $lang_id => $lang_data) { |
|
165 | +foreach ($lang_list as $lang_id => $lang_data) { |
|
166 | 166 | $template->assign_block_vars('game_languages', array( |
167 | 167 | 'ID' => $lang_id, |
168 | 168 | 'NAME' => "{$lang_data['LANG_NAME_NATIVE']} ({$lang_data['LANG_NAME_ENGLISH']})", |
@@ -7,9 +7,9 @@ |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -define('INSIDE' , true); |
|
11 | -define('INSTALL' , false); |
|
12 | -define('IN_ADMIN' , true); |
|
10 | +define('INSIDE', true); |
|
11 | +define('INSTALL', false); |
|
12 | +define('IN_ADMIN', true); |
|
13 | 13 | |
14 | 14 | require('../common.' . substr(strrchr(__FILE__, '.'), 1)); |
15 | 15 |
@@ -20,30 +20,30 @@ |
||
20 | 20 | $planet_id = sys_get_param_id('planet_id'); |
21 | 21 | |
22 | 22 | $unit_list = sys_get_param('unit_list'); |
23 | -if(sys_get_param('change_data') && !empty($unit_list)) |
|
23 | +if (sys_get_param('change_data') && !empty($unit_list)) |
|
24 | 24 | { |
25 | 25 | $query_string = array(); |
26 | - foreach($unit_list as $unit_id => $unit_amount) |
|
26 | + foreach ($unit_list as $unit_id => $unit_amount) |
|
27 | 27 | { |
28 | - if($unit_query_string = admin_planet_edit_query_string($unit_id, $unit_amount, $mode)) |
|
28 | + if ($unit_query_string = admin_planet_edit_query_string($unit_id, $unit_amount, $mode)) |
|
29 | 29 | { |
30 | 30 | $query_string[] = $unit_query_string; |
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
34 | - if(!empty($query_string)) |
|
34 | + if (!empty($query_string)) |
|
35 | 35 | { |
36 | 36 | DBStaticPlanet::db_planet_set_by_id($planet_id, implode(', ', $query_string)); |
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | -if($planet_id) |
|
40 | +if ($planet_id) |
|
41 | 41 | { |
42 | 42 | $edit_planet_row = DBStaticPlanet::db_planet_by_id($planet_id); |
43 | 43 | admin_planet_edit_template($template, $edit_planet_row, $mode); |
44 | 44 | } |
45 | 45 | |
46 | -foreach($admin_planet_edit_mode_list as $page_mode => $mode_locale) |
|
46 | +foreach ($admin_planet_edit_mode_list as $page_mode => $mode_locale) |
|
47 | 47 | { |
48 | 48 | $template->assign_block_vars('page_menu', array( |
49 | 49 | 'ID' => $page_mode, |
@@ -19,7 +19,7 @@ |
||
19 | 19 | |
20 | 20 | $template = gettemplate("admin/add_moon", true); |
21 | 21 | |
22 | -if(sys_get_param_str('mode') == 'addit') |
|
22 | +if (sys_get_param_str('mode') == 'addit') |
|
23 | 23 | { |
24 | 24 | $PlanetID = sys_get_param_id('user'); |
25 | 25 | $MoonName = sys_get_param_str('name'); |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | //while($CurrentFleet = db_fetch($FlyingFleets)) |
22 | 22 | |
23 | 23 | $all_flying_fleets = db_fleet_list('', DB_SELECT_PLAIN); |
24 | -foreach($all_flying_fleets as $fleet_id => $CurrentFleet) { |
|
24 | +foreach ($all_flying_fleets as $fleet_id => $CurrentFleet) { |
|
25 | 25 | $FleetOwner = db_user_by_id($CurrentFleet['fleet_owner']); |
26 | 26 | $TargetOwner = db_user_by_id($CurrentFleet['fleet_target_owner']); |
27 | 27 | |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | $fleet_data['fleet']['STAY_TIME_INT'] = $CurrentFleet['fleet_end_stay']; |
33 | 33 | |
34 | 34 | $template->assign_block_vars('fleets', $fleet_data['fleet']); |
35 | - foreach($fleet_data['ships'] as $ship_data) { |
|
35 | + foreach ($fleet_data['ships'] as $ship_data) { |
|
36 | 36 | $template->assign_block_vars('fleets.ships', $ship_data); |
37 | 37 | } |
38 | 38 | } |
@@ -186,11 +186,11 @@ |
||
186 | 186 | } |
187 | 187 | |
188 | 188 | $exclude = $user_row; |
189 | - foreach($blocks as $title => $fields) { |
|
189 | + foreach ($blocks as $title => $fields) { |
|
190 | 190 | userBlockAssign($exclude, $template, $title, $fields); |
191 | 191 | } |
192 | 192 | |
193 | - if(!empty($exclude)) { |
|
193 | + if (!empty($exclude)) { |
|
194 | 194 | userBlockAssign($exclude, $template, '!!! НЕИЗВЕСТНЫЕ ПАРАМЕТРЫ !!!', array_keys($exclude)); |
195 | 195 | } |
196 | 196 |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @copyright 2008-2015 Gorlum for Project "SuperNova.WS" |
6 | 6 | */ |
7 | 7 | |
8 | -if(!defined('INSIDE')) { |
|
8 | +if (!defined('INSIDE')) { |
|
9 | 9 | die(); |
10 | 10 | } |
11 | 11 | |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | function db_change_units_perform($query, $tablename, $object_id) { |
15 | 15 | $query = implode(',', $query); |
16 | - if($query && $object_id) { |
|
16 | + if ($query && $object_id) { |
|
17 | 17 | return classSupernova::db_upd_record_by_id($tablename == 'users' ? LOC_USER : LOC_PLANET, $object_id, $query); |
18 | 18 | } |
19 | 19 | } |
@@ -29,15 +29,15 @@ discard block |
||
29 | 29 | |
30 | 30 | $group = sn_get_groups('resources_loot'); |
31 | 31 | |
32 | - foreach($unit_list as $unit_id => $unit_amount) { |
|
33 | - if(!in_array($unit_id, $group)) { |
|
32 | + foreach ($unit_list as $unit_id => $unit_amount) { |
|
33 | + if (!in_array($unit_id, $group)) { |
|
34 | 34 | // TODO - remove later |
35 | 35 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: db_change_units() вызван для не-ресурсов!</h1>'); |
36 | 36 | pdump(debug_backtrace()); |
37 | 37 | die('db_change_units() вызван для не-ресурсов!'); |
38 | 38 | } |
39 | 39 | |
40 | - if(!$unit_amount) { |
|
40 | + if (!$unit_amount) { |
|
41 | 41 | continue; |
42 | 42 | } |
43 | 43 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | $unit_location = sys_get_unit_location($user, $planet, $unit_id); |
47 | 47 | |
48 | 48 | // Changing value in object |
49 | - switch($unit_location) { |
|
49 | + switch ($unit_location) { |
|
50 | 50 | case LOC_USER: |
51 | 51 | $user[$unit_db_name] += $unit_amount; |
52 | 52 | break; |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | global $lang; |
4 | 4 | |
5 | -if(!defined('SN_IN_ALLY') || SN_IN_ALLY !== true) |
|
5 | +if (!defined('SN_IN_ALLY') || SN_IN_ALLY !== true) |
|
6 | 6 | { |
7 | 7 | $debug->error("Attempt to call ALLIANCE page mode {$mode} directly - not from alliance.php", 'Forbidden', 403); |
8 | 8 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | $page = gettemplate('ali_admin_mail', true); |
21 | 21 | |
22 | 22 | if ($ranks) { |
23 | - foreach($ranks as $id => $array) { |
|
23 | + foreach ($ranks as $id => $array) { |
|
24 | 24 | $page->assign_block_vars('ranks', array( |
25 | 25 | 'NAME' => $array['name'], |
26 | 26 | 'VALUE' => $id, |
@@ -1,7 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -function flt_fleet_speed($user, $fleet) |
|
4 | -{ |
|
3 | +function flt_fleet_speed($user, $fleet) { |
|
5 | 4 | if (!is_array($fleet)) |
6 | 5 | { |
7 | 6 | $fleet = array($fleet => 1); |
@@ -29,16 +28,13 @@ discard block |
||
29 | 28 | if($from['galaxy'] != $to['galaxy']) |
30 | 29 | { |
31 | 30 | $distance = abs($from['galaxy'] - $to['galaxy']) * $config->uni_galaxy_distance; |
32 | - } |
|
33 | - elseif($from['system'] != $to['system']) |
|
31 | + } elseif($from['system'] != $to['system']) |
|
34 | 32 | { |
35 | 33 | $distance = abs($from['system'] - $to['system']) * 5 * 19 + 2700; |
36 | - } |
|
37 | - elseif($from['planet'] != $to['planet']) |
|
34 | + } elseif($from['planet'] != $to['planet']) |
|
38 | 35 | { |
39 | 36 | $distance = abs($from['planet'] - $to['planet']) * 5 + 1000; |
40 | - } |
|
41 | - else |
|
37 | + } else |
|
42 | 38 | { |
43 | 39 | $distance = 5; |
44 | 40 | } |
@@ -55,8 +51,7 @@ discard block |
||
55 | 51 | * |
56 | 52 | * @return array |
57 | 53 | */ |
58 | -function flt_travel_data($user_row, $from, $to, $fleet_array, $speed_percent = 10) |
|
59 | -{ |
|
54 | +function flt_travel_data($user_row, $from, $to, $fleet_array, $speed_percent = 10) { |
|
60 | 55 | $distance = flt_travel_distance($from, $to); |
61 | 56 | |
62 | 57 | $consumption = 0; |
@@ -120,8 +115,7 @@ discard block |
||
120 | 115 | ); |
121 | 116 | } |
122 | 117 | |
123 | -function flt_bashing_check($user, $enemy, $planet_dst, $mission, $flight_duration, $fleet_group = 0) |
|
124 | -{ |
|
118 | +function flt_bashing_check($user, $enemy, $planet_dst, $mission, $flight_duration, $fleet_group = 0) { |
|
125 | 119 | global $config; |
126 | 120 | |
127 | 121 | $config_bashing_attacks = $config->fleet_bashing_attacks; |
@@ -531,8 +525,7 @@ discard block |
||
531 | 525 | $fleet_ship_count += $amount; |
532 | 526 | $fleet_string .= "{$unit_id},{$amount};"; |
533 | 527 | $db_changeset['unit'][] = OldDbChangeSet::db_changeset_prepare_unit($unit_id, -$amount, $user, $from['id']); |
534 | - } |
|
535 | - elseif(in_array($unit_id, sn_get_groups('resources_loot'))) |
|
528 | + } elseif(in_array($unit_id, sn_get_groups('resources_loot'))) |
|
536 | 529 | { |
537 | 530 | $planet_fields[pname_resource_name($unit_id)]['delta'] -= $amount; |
538 | 531 | } |
@@ -624,8 +617,7 @@ discard block |
||
624 | 617 | //ini_set('error_reporting', E_ALL ^ E_NOTICE); |
625 | 618 | } |
626 | 619 | |
627 | -function flt_calculate_ship_to_transport_sort($a, $b) |
|
628 | -{ |
|
620 | +function flt_calculate_ship_to_transport_sort($a, $b) { |
|
629 | 621 | return $a['transport_effectivness'] == $b['transport_effectivness'] ? 0 : ($a['transport_effectivness'] > $b['transport_effectivness'] ? -1 : 1); |
630 | 622 | } |
631 | 623 | |
@@ -634,8 +626,7 @@ discard block |
||
634 | 626 | // $resource_amount - how much amount of resources need to be transported |
635 | 627 | // $from - transport from |
636 | 628 | // $to - transport to |
637 | -function flt_calculate_fleet_to_transport($ship_list, $resource_amount, $from, $to) |
|
638 | -{ |
|
629 | +function flt_calculate_fleet_to_transport($ship_list, $resource_amount, $from, $to) { |
|
639 | 630 | global $user; |
640 | 631 | |
641 | 632 | $ship_data = array(); |
@@ -8,11 +8,11 @@ discard block |
||
8 | 8 | } |
9 | 9 | |
10 | 10 | $speeds = array(); |
11 | - if(!empty($fleet)) |
|
11 | + if (!empty($fleet)) |
|
12 | 12 | { |
13 | 13 | foreach ($fleet as $ship_id => $amount) |
14 | 14 | { |
15 | - if($amount && in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) |
|
15 | + if ($amount && in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) |
|
16 | 16 | { |
17 | 17 | $single_ship_data = get_ship_data($ship_id, $user); |
18 | 18 | $speeds[] = $single_ship_data['speed']; |
@@ -26,15 +26,15 @@ discard block |
||
26 | 26 | function flt_travel_distance($from, $to) { |
27 | 27 | global $config; |
28 | 28 | |
29 | - if($from['galaxy'] != $to['galaxy']) |
|
29 | + if ($from['galaxy'] != $to['galaxy']) |
|
30 | 30 | { |
31 | 31 | $distance = abs($from['galaxy'] - $to['galaxy']) * $config->uni_galaxy_distance; |
32 | 32 | } |
33 | - elseif($from['system'] != $to['system']) |
|
33 | + elseif ($from['system'] != $to['system']) |
|
34 | 34 | { |
35 | 35 | $distance = abs($from['system'] - $to['system']) * 5 * 19 + 2700; |
36 | 36 | } |
37 | - elseif($from['planet'] != $to['planet']) |
|
37 | + elseif ($from['planet'] != $to['planet']) |
|
38 | 38 | { |
39 | 39 | $distance = abs($from['planet'] - $to['planet']) * 5 + 1000; |
40 | 40 | } |
@@ -65,14 +65,14 @@ discard block |
||
65 | 65 | |
66 | 66 | $game_fleet_speed = flt_server_flight_speed_multiplier(); |
67 | 67 | $fleet_speed = flt_fleet_speed($user_row, $fleet_array); |
68 | - if(!empty($fleet_array) && $fleet_speed && $game_fleet_speed) |
|
68 | + if (!empty($fleet_array) && $fleet_speed && $game_fleet_speed) |
|
69 | 69 | { |
70 | 70 | $speed_percent = $speed_percent ? max(min($speed_percent, 10), 1) : 10; |
71 | 71 | $real_speed = $speed_percent * sqrt($fleet_speed); |
72 | 72 | |
73 | 73 | $duration = max(1, round((35000 / $speed_percent * sqrt($distance * 10 / $fleet_speed) + 10) / $game_fleet_speed)); |
74 | 74 | |
75 | - foreach($fleet_array as $ship_id => $ship_count) |
|
75 | + foreach ($fleet_array as $ship_id => $ship_count) |
|
76 | 76 | { |
77 | 77 | if (!$ship_id || !$ship_count) |
78 | 78 | { |
@@ -126,19 +126,19 @@ discard block |
||
126 | 126 | |
127 | 127 | $config_bashing_attacks = $config->fleet_bashing_attacks; |
128 | 128 | $config_bashing_interval = $config->fleet_bashing_interval; |
129 | - if(!$config_bashing_attacks) { |
|
129 | + if (!$config_bashing_attacks) { |
|
130 | 130 | // Bashing allowed - protection disabled |
131 | 131 | return ATTACK_ALLOWED; |
132 | 132 | } |
133 | 133 | |
134 | 134 | $bashing_result = ATTACK_BASHING; |
135 | - if($user['ally_id'] && $enemy['ally_id']) { |
|
135 | + if ($user['ally_id'] && $enemy['ally_id']) { |
|
136 | 136 | $relations = ali_relations($user['ally_id'], $enemy['ally_id']); |
137 | - if(!empty($relations)) { |
|
137 | + if (!empty($relations)) { |
|
138 | 138 | $relations = $relations[$enemy['ally_id']]; |
139 | - switch($relations['alliance_diplomacy_relation']) { |
|
139 | + switch ($relations['alliance_diplomacy_relation']) { |
|
140 | 140 | case ALLY_DIPLOMACY_WAR: |
141 | - if(SN_TIME_NOW - $relations['alliance_diplomacy_time'] <= $config->fleet_bashing_war_delay) { |
|
141 | + if (SN_TIME_NOW - $relations['alliance_diplomacy_time'] <= $config->fleet_bashing_war_delay) { |
|
142 | 142 | $bashing_result = ATTACK_BASHING_WAR_DELAY; |
143 | 143 | } else { |
144 | 144 | return ATTACK_ALLOWED; |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | // } |
176 | 176 | // } |
177 | 177 | $bashing_fleet_list = fleet_list_bashing($user['id'], $planet_dst); |
178 | - foreach($bashing_fleet_list as $fleet_row) { |
|
178 | + foreach ($bashing_fleet_list as $fleet_row) { |
|
179 | 179 | // Checking for ACS - each ACS count only once |
180 | - if($fleet_row['fleet_group']) { |
|
180 | + if ($fleet_row['fleet_group']) { |
|
181 | 181 | $bashing_list["{$user['id']}_{$fleet_row['fleet_group']}"] = $fleet_row['fleet_start_time']; |
182 | 182 | } else { |
183 | 183 | $bashing_list[] = $fleet_row['fleet_start_time']; |
@@ -185,12 +185,12 @@ discard block |
||
185 | 185 | } |
186 | 186 | |
187 | 187 | // Check for joining to ACS - if there are already fleets in ACS no checks should be done |
188 | - if($mission == MT_AKS && $bashing_list["{$user['id']}_{$fleet_group}"]) { |
|
188 | + if ($mission == MT_AKS && $bashing_list["{$user['id']}_{$fleet_group}"]) { |
|
189 | 189 | return ATTACK_ALLOWED; |
190 | 190 | } |
191 | 191 | |
192 | 192 | $query = doquery("SELECT bashing_time FROM {{bashing}} WHERE bashing_user_id = {$user['id']} AND bashing_planet_id = {$planet_dst['id']} AND bashing_time >= {$time_limit};"); |
193 | - while($bashing_row = db_fetch($query)) { |
|
193 | + while ($bashing_row = db_fetch($query)) { |
|
194 | 194 | $bashing_list[] = $bashing_row['bashing_time']; |
195 | 195 | } |
196 | 196 | |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | $last_attack = 0; |
200 | 200 | $wave = 0; |
201 | 201 | $attack = 1; |
202 | - foreach($bashing_list as &$bash_time) { |
|
202 | + foreach ($bashing_list as &$bash_time) { |
|
203 | 203 | $attack++; |
204 | - if($bash_time - $last_attack > $config_bashing_interval || $attack > $config_bashing_attacks) { |
|
204 | + if ($bash_time - $last_attack > $config_bashing_interval || $attack > $config_bashing_attacks) { |
|
205 | 205 | $attack = 1; |
206 | 206 | $wave++; |
207 | 207 | } |
@@ -212,21 +212,21 @@ discard block |
||
212 | 212 | return ($wave > $config->fleet_bashing_waves ? $bashing_result : ATTACK_ALLOWED); |
213 | 213 | } |
214 | 214 | |
215 | -function flt_can_attack($planet_src, $planet_dst, $fleet = array(), $mission, $options = false){$result = null; return sn_function_call('flt_can_attack', array($planet_src, $planet_dst, $fleet, $mission, $options, &$result));} |
|
215 | +function flt_can_attack($planet_src, $planet_dst, $fleet = array(), $mission, $options = false) {$result = null; return sn_function_call('flt_can_attack', array($planet_src, $planet_dst, $fleet, $mission, $options, &$result)); } |
|
216 | 216 | function sn_flt_can_attack($planet_src, $planet_dst, $fleet = array(), $mission, $options = false, &$result) { |
217 | 217 | //TODO: try..catch |
218 | 218 | global $config, $user; |
219 | 219 | |
220 | - if($user['vacation']) { |
|
220 | + if ($user['vacation']) { |
|
221 | 221 | return $result = ATTACK_OWN_VACATION; |
222 | 222 | } |
223 | 223 | |
224 | - if(empty($fleet) || !is_array($fleet)) { |
|
224 | + if (empty($fleet) || !is_array($fleet)) { |
|
225 | 225 | return $result = ATTACK_NO_FLEET; |
226 | 226 | } |
227 | 227 | |
228 | 228 | $sn_groups_mission = sn_get_groups('missions'); |
229 | - if(!isset($sn_groups_mission[$mission])) { |
|
229 | + if (!isset($sn_groups_mission[$mission])) { |
|
230 | 230 | return $result = ATTACK_MISSION_ABSENT; |
231 | 231 | } |
232 | 232 | $sn_data_mission = $sn_groups_mission[$mission]; |
@@ -245,32 +245,32 @@ discard block |
||
245 | 245 | $resources = 0; |
246 | 246 | $ship_ids = sn_get_groups('fleet'); |
247 | 247 | $resource_ids = sn_get_groups('resources_loot'); |
248 | - foreach($fleet as $ship_id => $ship_count) { |
|
248 | + foreach ($fleet as $ship_id => $ship_count) { |
|
249 | 249 | $is_ship = in_array($ship_id, $ship_ids); |
250 | 250 | $is_resource = in_array($ship_id, $resource_ids); |
251 | - if(!$is_ship && !$is_resource) { |
|
251 | + if (!$is_ship && !$is_resource) { |
|
252 | 252 | // TODO Спецобработчик для Капитана и модулей |
253 | 253 | // return ATTACK_WRONG_UNIT; |
254 | 254 | } |
255 | 255 | |
256 | - if($ship_count < 0) { |
|
256 | + if ($ship_count < 0) { |
|
257 | 257 | return $result = $is_ship ? ATTACK_SHIP_COUNT_WRONG : ATTACK_RESOURCE_COUNT_WRONG; |
258 | 258 | } |
259 | 259 | |
260 | - if($ship_count > mrc_get_level($user, $planet_src, $ship_id)) { |
|
260 | + if ($ship_count > mrc_get_level($user, $planet_src, $ship_id)) { |
|
261 | 261 | // TODO ATTACK_NO_MISSILE |
262 | 262 | return $result = $is_ship ? ATTACK_NO_SHIPS : ATTACK_NO_RESOURCES; |
263 | 263 | } |
264 | 264 | |
265 | - if($is_ship) { |
|
265 | + if ($is_ship) { |
|
266 | 266 | $single_ship_data = get_ship_data($ship_id, $user); |
267 | - if($single_ship_data[P_SPEED] <= 0) { |
|
267 | + if ($single_ship_data[P_SPEED] <= 0) { |
|
268 | 268 | return $result = ATTACK_ZERO_SPEED; |
269 | 269 | } |
270 | 270 | $ships += $ship_count; |
271 | 271 | $recyclers += in_array($ship_id, sn_get_groups('flt_recyclers')) ? $ship_count : 0; |
272 | 272 | $spies += $ship_id == SHIP_SPY ? $ship_count : 0; |
273 | - } elseif($is_resource) { |
|
273 | + } elseif ($is_resource) { |
|
274 | 274 | $resources += $ship_count; |
275 | 275 | } |
276 | 276 | } |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | } |
282 | 282 | */ |
283 | 283 | |
284 | - if(isset($options['resources']) && $options['resources'] > 0 && !(isset($sn_data_mission['transport']) && $sn_data_mission['transport'])) { |
|
284 | + if (isset($options['resources']) && $options['resources'] > 0 && !(isset($sn_data_mission['transport']) && $sn_data_mission['transport'])) { |
|
285 | 285 | return $result = ATTACK_RESOURCE_FORBIDDEN; |
286 | 286 | } |
287 | 287 | |
@@ -293,35 +293,35 @@ discard block |
||
293 | 293 | */ |
294 | 294 | |
295 | 295 | $speed = $options['fleet_speed_percent']; |
296 | - if($speed && ($speed != intval($speed) || $speed < 1 || $speed > 10)) { |
|
296 | + if ($speed && ($speed != intval($speed) || $speed < 1 || $speed > 10)) { |
|
297 | 297 | return $result = ATTACK_WRONG_SPEED; |
298 | 298 | } |
299 | 299 | |
300 | 300 | $travel_data = flt_travel_data($user, $planet_src, $planet_dst, $fleet, $options['fleet_speed_percent']); |
301 | 301 | |
302 | 302 | |
303 | - if(mrc_get_level($user, $planet_src, RES_DEUTERIUM) < $fleet[RES_DEUTERIUM] + $travel_data['consumption']) { |
|
303 | + if (mrc_get_level($user, $planet_src, RES_DEUTERIUM) < $fleet[RES_DEUTERIUM] + $travel_data['consumption']) { |
|
304 | 304 | return $result = ATTACK_NO_FUEL; |
305 | 305 | } |
306 | 306 | |
307 | - if($travel_data['consumption'] > $travel_data['capacity']) { |
|
307 | + if ($travel_data['consumption'] > $travel_data['capacity']) { |
|
308 | 308 | return $result = ATTACK_TOO_FAR; |
309 | 309 | } |
310 | 310 | |
311 | - if($travel_data['hold'] < $resources) { |
|
311 | + if ($travel_data['hold'] < $resources) { |
|
312 | 312 | return $result = ATTACK_OVERLOADED; |
313 | 313 | } |
314 | 314 | |
315 | 315 | $fleet_start_time = SN_TIME_NOW + $travel_data['duration']; |
316 | 316 | |
317 | 317 | $fleet_group = $options['fleet_group']; |
318 | - if($fleet_group) { |
|
319 | - if($mission != MT_AKS) { |
|
318 | + if ($fleet_group) { |
|
319 | + if ($mission != MT_AKS) { |
|
320 | 320 | return $result = ATTACK_WRONG_MISSION; |
321 | 321 | }; |
322 | 322 | |
323 | 323 | $acs = doquery("SELECT * FROM {{aks}} WHERE id = '{$fleet_group}' LIMIT 1;", '', true); |
324 | - if(!$acs['id']) { |
|
324 | + if (!$acs['id']) { |
|
325 | 325 | return $result = ATTACK_NO_ACS; |
326 | 326 | } |
327 | 327 | |
@@ -329,70 +329,70 @@ discard block |
||
329 | 329 | return $result = ATTACK_ACS_WRONG_TARGET; |
330 | 330 | } |
331 | 331 | |
332 | - if ($fleet_start_time>$acs['ankunft']) { |
|
332 | + if ($fleet_start_time > $acs['ankunft']) { |
|
333 | 333 | return $result = ATTACK_ACS_TOO_LATE; |
334 | 334 | } |
335 | 335 | } |
336 | 336 | |
337 | 337 | $flying_fleets = $options['flying_fleets']; |
338 | - if(!$flying_fleets) { |
|
338 | + if (!$flying_fleets) { |
|
339 | 339 | // $flying_fleets = doquery("SELECT COUNT(fleet_id) AS `flying_fleets` FROM {{fleets}} WHERE `fleet_owner` = '{$user['id']}';", '', true); |
340 | 340 | // $flying_fleets = $flying_fleets['flying_fleets']; |
341 | 341 | $flying_fleets = fleet_count_flying($user['id']); |
342 | 342 | } |
343 | - if(GetMaxFleets($user) <= $flying_fleets && $mission != MT_MISSILE) { |
|
343 | + if (GetMaxFleets($user) <= $flying_fleets && $mission != MT_MISSILE) { |
|
344 | 344 | return $result = ATTACK_NO_SLOTS; |
345 | 345 | } |
346 | 346 | |
347 | 347 | // В одиночку шпионские зонды могут летать только в миссии Шпионаж, Передислокация и Транспорт |
348 | - if($ships && $spies && $spies == $ships && !($mission == MT_SPY || $mission == MT_RELOCATE || $mission == MT_TRANSPORT)) { |
|
348 | + if ($ships && $spies && $spies == $ships && !($mission == MT_SPY || $mission == MT_RELOCATE || $mission == MT_TRANSPORT)) { |
|
349 | 349 | return $result = ATTACK_SPIES_LONLY; |
350 | 350 | } |
351 | 351 | |
352 | 352 | // Checking for no planet |
353 | - if(!$planet_dst['id_owner']) { |
|
354 | - if($mission == MT_COLONIZE && !$fleet[SHIP_COLONIZER]) { |
|
353 | + if (!$planet_dst['id_owner']) { |
|
354 | + if ($mission == MT_COLONIZE && !$fleet[SHIP_COLONIZER]) { |
|
355 | 355 | return $result = ATTACK_NO_COLONIZER; |
356 | 356 | } |
357 | 357 | |
358 | - if($mission == MT_EXPLORE || $mission == MT_COLONIZE) { |
|
358 | + if ($mission == MT_EXPLORE || $mission == MT_COLONIZE) { |
|
359 | 359 | return $result = ATTACK_ALLOWED; |
360 | 360 | } |
361 | 361 | return $result = ATTACK_NO_TARGET; |
362 | 362 | } |
363 | 363 | |
364 | - if($mission == MT_RECYCLE) { |
|
365 | - if($planet_dst['debris_metal'] + $planet_dst['debris_crystal'] <= 0) { |
|
364 | + if ($mission == MT_RECYCLE) { |
|
365 | + if ($planet_dst['debris_metal'] + $planet_dst['debris_crystal'] <= 0) { |
|
366 | 366 | return $result = ATTACK_NO_DEBRIS; |
367 | 367 | } |
368 | - if($recyclers <= 0) { |
|
368 | + if ($recyclers <= 0) { |
|
369 | 369 | return $result = ATTACK_NO_RECYCLERS; |
370 | 370 | } |
371 | 371 | return $result = ATTACK_ALLOWED; |
372 | 372 | } |
373 | 373 | |
374 | 374 | // Got planet. Checking if it is ours |
375 | - if($planet_dst['id_owner'] == $user['id']) { |
|
376 | - if($mission == MT_TRANSPORT || $mission == MT_RELOCATE) { |
|
375 | + if ($planet_dst['id_owner'] == $user['id']) { |
|
376 | + if ($mission == MT_TRANSPORT || $mission == MT_RELOCATE) { |
|
377 | 377 | return $result = ATTACK_ALLOWED; |
378 | 378 | } |
379 | 379 | return $planet_src['id'] == $planet_dst['id'] ? ATTACK_SAME : ATTACK_OWN; |
380 | 380 | } |
381 | 381 | |
382 | 382 | // No, planet not ours. Cutting mission that can't be send to not-ours planet |
383 | - if($mission == MT_RELOCATE || $mission == MT_COLONIZE || $mission == MT_EXPLORE) { |
|
383 | + if ($mission == MT_RELOCATE || $mission == MT_COLONIZE || $mission == MT_EXPLORE) { |
|
384 | 384 | return $result = ATTACK_WRONG_MISSION; |
385 | 385 | } |
386 | 386 | |
387 | 387 | $enemy = db_user_by_id($planet_dst['id_owner']); |
388 | 388 | // We cannot attack or send resource to users in VACATION mode |
389 | - if($enemy['vacation'] && $mission != MT_RECYCLE) { |
|
389 | + if ($enemy['vacation'] && $mission != MT_RECYCLE) { |
|
390 | 390 | return $result = ATTACK_VACATION; |
391 | 391 | } |
392 | 392 | |
393 | 393 | // Multi IP protection |
394 | 394 | // TODO: Here we need a procedure to check proxies |
395 | - if(sys_is_multiaccount($user, $enemy)) { |
|
395 | + if (sys_is_multiaccount($user, $enemy)) { |
|
396 | 396 | return $result = ATTACK_SAME_IP; |
397 | 397 | } |
398 | 398 | |
@@ -400,8 +400,8 @@ discard block |
||
400 | 400 | $enemy_points = $enemy['total_points']; |
401 | 401 | |
402 | 402 | // Is it transport? If yes - checking for buffing to prevent mega-alliance destroyer |
403 | - if($mission == MT_TRANSPORT) { |
|
404 | - if($user_points >= $enemy_points || $config->allow_buffing) { |
|
403 | + if ($mission == MT_TRANSPORT) { |
|
404 | + if ($user_points >= $enemy_points || $config->allow_buffing) { |
|
405 | 405 | return $result = ATTACK_ALLOWED; |
406 | 406 | } else { |
407 | 407 | return $result = ATTACK_BUFFING; |
@@ -411,65 +411,65 @@ discard block |
||
411 | 411 | // Only aggresive missions passed to this point. HOLD counts as passive but aggresive |
412 | 412 | |
413 | 413 | // Is it admin with planet protection? |
414 | - if($planet_dst['id_level'] > $user['authlevel']) { |
|
414 | + if ($planet_dst['id_level'] > $user['authlevel']) { |
|
415 | 415 | return $result = ATTACK_ADMIN; |
416 | 416 | } |
417 | 417 | |
418 | 418 | // Okay. Now skipping protection checks for inactive longer then 1 week |
419 | - if(!$enemy['onlinetime'] || $enemy['onlinetime'] >= (SN_TIME_NOW - 60*60*24*7)) { |
|
420 | - if( |
|
419 | + if (!$enemy['onlinetime'] || $enemy['onlinetime'] >= (SN_TIME_NOW - 60 * 60 * 24 * 7)) { |
|
420 | + if ( |
|
421 | 421 | (classSupernova::$gc->general->playerIsNoobByPoints($enemy_points) && !classSupernova::$gc->general->playerIsNoobByPoints($user_points)) |
422 | 422 | || |
423 | 423 | (classSupernova::$gc->general->playerIs1stStrongerThen2nd($user_points, $enemy_points)) |
424 | 424 | ) { |
425 | - if($mission != MT_HOLD) { |
|
425 | + if ($mission != MT_HOLD) { |
|
426 | 426 | return $result = ATTACK_NOOB; |
427 | 427 | } |
428 | - if($mission == MT_HOLD && !($user['ally_id'] && $user['ally_id'] == $enemy['ally_id'] && $config->ally_help_weak)) { |
|
428 | + if ($mission == MT_HOLD && !($user['ally_id'] && $user['ally_id'] == $enemy['ally_id'] && $config->ally_help_weak)) { |
|
429 | 429 | return $result = ATTACK_NOOB; |
430 | 430 | } |
431 | 431 | } |
432 | 432 | } |
433 | 433 | |
434 | 434 | // Is it HOLD mission? If yes - there should be ally deposit |
435 | - if($mission == MT_HOLD) { |
|
436 | - if(mrc_get_level($user, $planet_dst, STRUC_ALLY_DEPOSIT)) { |
|
435 | + if ($mission == MT_HOLD) { |
|
436 | + if (mrc_get_level($user, $planet_dst, STRUC_ALLY_DEPOSIT)) { |
|
437 | 437 | return $result = ATTACK_ALLOWED; |
438 | 438 | } |
439 | 439 | return $result = ATTACK_NO_ALLY_DEPOSIT; |
440 | 440 | } |
441 | 441 | |
442 | - if($mission == MT_SPY) { |
|
442 | + if ($mission == MT_SPY) { |
|
443 | 443 | return $result = $spies >= 1 ? ATTACK_ALLOWED : ATTACK_NO_SPIES; |
444 | 444 | } |
445 | 445 | |
446 | 446 | // Is it MISSILE mission? |
447 | - if($mission == MT_MISSILE) { |
|
447 | + if ($mission == MT_MISSILE) { |
|
448 | 448 | $sn_data_mip = get_unit_param(UNIT_DEF_MISSILE_INTERPLANET); |
449 | - if(mrc_get_level($user, $planet_src, STRUC_SILO) < $sn_data_mip[P_REQUIRE][STRUC_SILO]) { |
|
449 | + if (mrc_get_level($user, $planet_src, STRUC_SILO) < $sn_data_mip[P_REQUIRE][STRUC_SILO]) { |
|
450 | 450 | return $result = ATTACK_NO_SILO; |
451 | 451 | } |
452 | 452 | |
453 | - if(!$fleet[UNIT_DEF_MISSILE_INTERPLANET]) { |
|
453 | + if (!$fleet[UNIT_DEF_MISSILE_INTERPLANET]) { |
|
454 | 454 | return $result = ATTACK_NO_MISSILE; |
455 | 455 | } |
456 | 456 | |
457 | 457 | $distance = abs($planet_dst['system'] - $planet_src['system']); |
458 | 458 | $mip_range = flt_get_missile_range($user); |
459 | - if($distance > $mip_range || $planet_dst['galaxy'] != $planet_src['galaxy']) { |
|
459 | + if ($distance > $mip_range || $planet_dst['galaxy'] != $planet_src['galaxy']) { |
|
460 | 460 | return $result = ATTACK_MISSILE_TOO_FAR; |
461 | 461 | } |
462 | 462 | |
463 | - if(isset($options['target_structure']) && $options['target_structure'] && !in_array($options['target_structure'], sn_get_groups('defense_active'))) { |
|
463 | + if (isset($options['target_structure']) && $options['target_structure'] && !in_array($options['target_structure'], sn_get_groups('defense_active'))) { |
|
464 | 464 | return $result = ATTACK_WRONG_STRUCTURE; |
465 | 465 | } |
466 | 466 | } |
467 | 467 | |
468 | - if($mission == MT_DESTROY && $planet_dst['planet_type'] != PT_MOON) { |
|
468 | + if ($mission == MT_DESTROY && $planet_dst['planet_type'] != PT_MOON) { |
|
469 | 469 | return $result = ATTACK_WRONG_MISSION; |
470 | 470 | } |
471 | 471 | |
472 | - if($mission == MT_ATTACK || $mission == MT_AKS || $mission == MT_DESTROY) { |
|
472 | + if ($mission == MT_ATTACK || $mission == MT_AKS || $mission == MT_DESTROY) { |
|
473 | 473 | return $result = flt_bashing_check($user, $enemy, $planet_dst, $mission, $travel_data['duration'], $fleet_group); |
474 | 474 | } |
475 | 475 | |
@@ -495,18 +495,18 @@ discard block |
||
495 | 495 | $from = $from['planet']; |
496 | 496 | |
497 | 497 | $can_attack = flt_can_attack($from, $to, $fleet, $mission, $options); |
498 | - if($can_attack != ATTACK_ALLOWED) { |
|
498 | + if ($can_attack != ATTACK_ALLOWED) { |
|
499 | 499 | $internal_transaction ? sn_db_transaction_rollback() : false; |
500 | 500 | return $can_attack; |
501 | 501 | } |
502 | 502 | |
503 | 503 | $fleet_group = isset($options['fleet_group']) ? floatval($options['fleet_group']) : 0; |
504 | 504 | |
505 | - $travel_data = flt_travel_data($user, $from, $to, $fleet, $options['fleet_speed_percent']); |
|
505 | + $travel_data = flt_travel_data($user, $from, $to, $fleet, $options['fleet_speed_percent']); |
|
506 | 506 | |
507 | 507 | $fleet_start_time = SN_TIME_NOW + $travel_data['duration']; |
508 | 508 | |
509 | - if($mission == MT_EXPLORE || $mission == MT_HOLD) { |
|
509 | + if ($mission == MT_EXPLORE || $mission == MT_HOLD) { |
|
510 | 510 | $stay_duration = $options['stay_time'] * 3600; |
511 | 511 | $stay_time = $fleet_start_time + $stay_duration; |
512 | 512 | } else { |
@@ -519,20 +519,20 @@ discard block |
||
519 | 519 | $fleet_string = ''; |
520 | 520 | $db_changeset = array(); |
521 | 521 | $planet_fields = array(); |
522 | - foreach($fleet as $unit_id => $amount) |
|
522 | + foreach ($fleet as $unit_id => $amount) |
|
523 | 523 | { |
524 | - if(!$amount || !$unit_id) |
|
524 | + if (!$amount || !$unit_id) |
|
525 | 525 | { |
526 | 526 | continue; |
527 | 527 | } |
528 | 528 | |
529 | - if(in_array($unit_id, sn_get_groups('fleet'))) |
|
529 | + if (in_array($unit_id, sn_get_groups('fleet'))) |
|
530 | 530 | { |
531 | 531 | $fleet_ship_count += $amount; |
532 | 532 | $fleet_string .= "{$unit_id},{$amount};"; |
533 | 533 | $db_changeset['unit'][] = OldDbChangeSet::db_changeset_prepare_unit($unit_id, -$amount, $user, $from['id']); |
534 | 534 | } |
535 | - elseif(in_array($unit_id, sn_get_groups('resources_loot'))) |
|
535 | + elseif (in_array($unit_id, sn_get_groups('resources_loot'))) |
|
536 | 536 | { |
537 | 537 | $planet_fields[pname_resource_name($unit_id)]['delta'] -= $amount; |
538 | 538 | } |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | |
641 | 641 | $ship_data = array(); |
642 | 642 | $fleet_array = array(); |
643 | - foreach($ship_list as $transport_id => $cork) |
|
643 | + foreach ($ship_list as $transport_id => $cork) |
|
644 | 644 | { |
645 | 645 | $ship_data[$transport_id] = flt_travel_data($user, $from, $to, array($transport_id => 1), 10); |
646 | 646 | } |
@@ -649,10 +649,10 @@ discard block |
||
649 | 649 | $fleet_hold = 0; |
650 | 650 | $fleet_capacity = 0; |
651 | 651 | $fuel_total = $fuel_left = mrc_get_level($user, $from, RES_DEUTERIUM); |
652 | - foreach($ship_data as $transport_id => &$ship_info) |
|
652 | + foreach ($ship_data as $transport_id => &$ship_info) |
|
653 | 653 | { |
654 | 654 | $ship_loaded = min($ship_list[$transport_id], ceil($resource_amount / $ship_info['hold']), floor($fuel_left / $ship_info['consumption'])); |
655 | - if($ship_loaded) |
|
655 | + if ($ship_loaded) |
|
656 | 656 | { |
657 | 657 | $fleet_array[$transport_id] = $ship_loaded; |
658 | 658 | $resource_amount -= min($resource_amount, $ship_info['hold'] * $ship_loaded); |