@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if(!defined('IN_UPDATE')) { |
|
3 | +if (!defined('IN_UPDATE')) { |
|
4 | 4 | die('Trying to call update helpers externally!'); |
5 | 5 | } |
6 | 6 | |
@@ -8,13 +8,13 @@ discard block |
||
8 | 8 | global $update_tables; |
9 | 9 | |
10 | 10 | upd_add_more_time(); |
11 | - if(!$no_log) { |
|
11 | + if (!$no_log) { |
|
12 | 12 | upd_log_message("Performing query '{$query}'"); |
13 | 13 | } |
14 | 14 | |
15 | 15 | // classSupernova::$db->sn_db_connect(); |
16 | - if(!(strpos($query, '{{') === false)) { |
|
17 | - foreach($update_tables as $tableName => $cork) { |
|
16 | + if (!(strpos($query, '{{') === false)) { |
|
17 | + foreach ($update_tables as $tableName => $cork) { |
|
18 | 18 | $query = str_replace("{{{$tableName}}}", classSupernova::$db->db_prefix . $tableName, $query); |
19 | 19 | } |
20 | 20 | } |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | global $config, $sys_log_disabled; |
28 | 28 | |
29 | 29 | $config->db_loadItem($key); |
30 | - if($condition || !isset($config->$key)) { |
|
30 | + if ($condition || !isset($config->$key)) { |
|
31 | 31 | upd_add_more_time(); |
32 | - if(!$sys_log_disabled) { |
|
32 | + if (!$sys_log_disabled) { |
|
33 | 33 | upd_log_message("Updating config key '{$key}' with value '{$default_value}'"); |
34 | 34 | } |
35 | 35 | $config->db_saveItem($key, $default_value); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | function upd_log_message($message) { |
58 | 58 | global $sys_log_disabled, $upd_log, $debug; |
59 | 59 | |
60 | - if($sys_log_disabled) { |
|
60 | + if ($sys_log_disabled) { |
|
61 | 61 | // print("{$message}<br />"); |
62 | 62 | } else { |
63 | 63 | $upd_log .= "{$message}\r\n"; |
@@ -68,15 +68,15 @@ discard block |
||
68 | 68 | function upd_unset_table_info($table_name) { |
69 | 69 | global $update_tables, $update_indexes, $update_foreigns; |
70 | 70 | |
71 | - if(isset($update_tables[$table_name])) { |
|
71 | + if (isset($update_tables[$table_name])) { |
|
72 | 72 | unset($update_tables[$table_name]); |
73 | 73 | } |
74 | 74 | |
75 | - if(isset($update_indexes[$table_name])) { |
|
75 | + if (isset($update_indexes[$table_name])) { |
|
76 | 76 | unset($update_indexes[$table_name]); |
77 | 77 | } |
78 | 78 | |
79 | - if(isset($update_foreigns[$table_name])) { |
|
79 | + if (isset($update_foreigns[$table_name])) { |
|
80 | 80 | unset($update_foreigns[$table_name]); |
81 | 81 | } |
82 | 82 | } |
@@ -90,18 +90,18 @@ discard block |
||
90 | 90 | upd_unset_table_info($tableName); |
91 | 91 | |
92 | 92 | $q1 = upd_do_query("SHOW FULL COLUMNS FROM {$prefix_table_name};", true); |
93 | - while($r1 = db_fetch($q1)) { |
|
93 | + while ($r1 = db_fetch($q1)) { |
|
94 | 94 | $update_tables[$tableName][$r1['Field']] = $r1; |
95 | 95 | } |
96 | 96 | |
97 | 97 | $q1 = upd_do_query("SHOW INDEX FROM {$prefix_table_name};", true); |
98 | - while($r1 = db_fetch($q1)) { |
|
98 | + while ($r1 = db_fetch($q1)) { |
|
99 | 99 | $update_indexes[$tableName][$r1['Key_name']] .= "{$r1['Column_name']},"; |
100 | 100 | $update_indexes_full[$tableName][$r1['Key_name']][$r1['Column_name']] = $r1; |
101 | 101 | } |
102 | 102 | |
103 | 103 | $q1 = upd_do_query("SELECT * FROM `information_schema`.`KEY_COLUMN_USAGE` WHERE `TABLE_SCHEMA` = '" . db_escape(classSupernova::$db_name) . "' AND TABLE_NAME = '{$prefix_table_name}' AND REFERENCED_TABLE_NAME is not null;", true); |
104 | - while($r1 = db_fetch($q1)) { |
|
104 | + while ($r1 = db_fetch($q1)) { |
|
105 | 105 | $table_referenced = str_replace($config->db_prefix, '', $r1['REFERENCED_TABLE_NAME']); |
106 | 106 | |
107 | 107 | $update_foreigns[$tableName][$r1['CONSTRAINT_NAME']] .= "{$r1['COLUMN_NAME']},{$table_referenced},{$r1['REFERENCED_COLUMN_NAME']};"; |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | function upd_alter_table($table, $alters, $condition = true) { |
119 | 119 | global $config; |
120 | 120 | |
121 | - if(!$condition) { |
|
121 | + if (!$condition) { |
|
122 | 122 | return; |
123 | 123 | } |
124 | 124 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $alters_print = is_array($alters) ? dump($alters) : $alters; |
127 | 127 | upd_log_message("Altering table '{$table}' with alterations {$alters_print}"); |
128 | 128 | |
129 | - if(!is_array($alters)) { |
|
129 | + if (!is_array($alters)) { |
|
130 | 130 | $alters = array($alters); |
131 | 131 | } |
132 | 132 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | //$result = db_query($qry); |
138 | 138 | $result = upd_do_query($qry); |
139 | 139 | $error = db_error(); |
140 | - if($error) { |
|
140 | + if ($error) { |
|
141 | 141 | die("Altering error for table `{$table}`: {$error}<br />{$alters_print}"); |
142 | 142 | } |
143 | 143 | |
@@ -160,11 +160,11 @@ discard block |
||
160 | 160 | function upd_create_table($table_name, $declaration) { |
161 | 161 | global $config, $update_tables; |
162 | 162 | |
163 | - if(!$update_tables[$table_name]) { |
|
163 | + if (!$update_tables[$table_name]) { |
|
164 | 164 | upd_do_query('set foreign_key_checks = 0;', true); |
165 | 165 | $result = upd_do_query("CREATE TABLE IF NOT EXISTS `{$config->db_prefix}{$table_name}` {$declaration}"); |
166 | 166 | $error = db_error(); |
167 | - if($error) { |
|
167 | + if ($error) { |
|
168 | 168 | die("Creating error for table `{$table_name}`: {$error}<br />" . dump($declaration)); |
169 | 169 | } |
170 | 170 | upd_do_query('set foreign_key_checks = 1;', true); |
@@ -190,14 +190,14 @@ discard block |
||
190 | 190 | |
191 | 191 | |
192 | 192 | function upd_db_unit_changeset_prepare($unit_id, $unit_value, $user, $planet_id = null) { |
193 | - if(!is_array($user)) { |
|
193 | + if (!is_array($user)) { |
|
194 | 194 | // TODO - remove later |
195 | 195 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_unit_changeset_prepare() - USER is not ARRAY</h1>'); |
196 | 196 | pdump(debug_backtrace()); |
197 | 197 | die('USER is not ARRAY'); |
198 | 198 | } |
199 | 199 | |
200 | - if(!isset($user['id']) || !$user['id']) { |
|
200 | + if (!isset($user['id']) || !$user['id']) { |
|
201 | 201 | // TODO - remove later |
202 | 202 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_unit_changeset_prepare() - USER[id] пустой</h1>'); |
203 | 203 | pdump($user); |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | |
213 | 213 | $db_changeset = array(); |
214 | 214 | $temp = upd_db_unit_by_location($user['id'], $unit_location, $location_id, $unit_id, true, 'unit_id'); |
215 | - if($temp['unit_id']) { |
|
215 | + if ($temp['unit_id']) { |
|
216 | 216 | // update |
217 | 217 | $db_changeset = array( |
218 | 218 | 'action' => SQL_OP_UPDATE, |
@@ -257,41 +257,41 @@ discard block |
||
257 | 257 | |
258 | 258 | |
259 | 259 | function upd_db_changeset_apply($db_changeset) { |
260 | - if(!is_array($db_changeset) || empty($db_changeset)) { |
|
260 | + if (!is_array($db_changeset) || empty($db_changeset)) { |
|
261 | 261 | return; |
262 | 262 | } |
263 | 263 | |
264 | - foreach($db_changeset as $table_name => $table_data) { |
|
265 | - foreach($table_data as $record_id => $conditions) { |
|
264 | + foreach ($db_changeset as $table_name => $table_data) { |
|
265 | + foreach ($table_data as $record_id => $conditions) { |
|
266 | 266 | $where = ''; |
267 | - if(!empty($conditions['where'])) { |
|
267 | + if (!empty($conditions['where'])) { |
|
268 | 268 | $where = 'WHERE ' . implode(' AND ', $conditions['where']); |
269 | 269 | } |
270 | 270 | |
271 | 271 | $fields = array(); |
272 | - if($conditions['fields']) { |
|
273 | - foreach($conditions['fields'] as $field_name => $field_data) { |
|
272 | + if ($conditions['fields']) { |
|
273 | + foreach ($conditions['fields'] as $field_name => $field_data) { |
|
274 | 274 | $condition = "`{$field_name}` = "; |
275 | 275 | $value = ''; |
276 | - if($field_data['delta']) { |
|
276 | + if ($field_data['delta']) { |
|
277 | 277 | $value = "`{$field_name}`" . ($field_data['delta'] >= 0 ? '+' : '') . $field_data['delta']; |
278 | - } elseif($field_data['set']) { |
|
278 | + } elseif ($field_data['set']) { |
|
279 | 279 | $value = (is_string($field_data['set']) ? "'{$field_data['set']}'" : $field_data['set']); |
280 | 280 | } |
281 | - if($value) { |
|
281 | + if ($value) { |
|
282 | 282 | $fields[] = $condition . $value; |
283 | 283 | } |
284 | 284 | } |
285 | 285 | } |
286 | 286 | $fields = implode(',', $fields); |
287 | 287 | |
288 | - switch($conditions['action']) { |
|
288 | + switch ($conditions['action']) { |
|
289 | 289 | case SQL_OP_DELETE: |
290 | 290 | upd_do_query("DELETE FROM {{{$table_name}}} {$where}"); |
291 | 291 | break; |
292 | 292 | |
293 | 293 | case SQL_OP_UPDATE: |
294 | - if($fields) { |
|
294 | + if ($fields) { |
|
295 | 295 | /*if($table_name == 'unit') |
296 | 296 | { |
297 | 297 | pdump("UPDATE {{{$table_name}}} SET {$fields} {$where}"); |
@@ -302,13 +302,13 @@ discard block |
||
302 | 302 | break; |
303 | 303 | |
304 | 304 | case SQL_OP_INSERT: |
305 | - if($fields) { |
|
305 | + if ($fields) { |
|
306 | 306 | upd_do_query("INSERT INTO {{{$table_name}}} SET {$fields}"); |
307 | 307 | } |
308 | 308 | break; |
309 | 309 | |
310 | 310 | case SQL_OP_REPLACE: |
311 | - if($fields) { |
|
311 | + if ($fields) { |
|
312 | 312 | upd_do_query("REPLACE INTO {{{$table_name}}} SET {$fields}"); |
313 | 313 | } |
314 | 314 | break; |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | |
17 | 17 | $destination_planet = &$mission_data->dst_planet; |
18 | 18 | |
19 | - if(empty($destination_planet['id_owner']) || $objFleet->playerOwnerId != $destination_planet['id_owner']) { |
|
19 | + if (empty($destination_planet['id_owner']) || $objFleet->playerOwnerId != $destination_planet['id_owner']) { |
|
20 | 20 | $objFleet->mark_fleet_as_returned_and_save(); |
21 | 21 | |
22 | 22 | return CACHE_FLEET; |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | $fleet_resources[RES_DEUTERIUM], $lang['Deuterium'] |
32 | 32 | ) . '<br />' . $lang['sys_relocate_mess_user']; |
33 | 33 | $fleet_real_array = $objFleet->get_unit_list(); |
34 | - foreach($fleet_real_array as $ship_id => $ship_count) { |
|
34 | + foreach ($fleet_real_array as $ship_id => $ship_count) { |
|
35 | 35 | $Message .= $lang['tech'][$ship_id] . ' - ' . $ship_count . '<br />'; |
36 | 36 | } |
37 | 37 | msg_send_simple_message( |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | $source_planet = &$mission_data->src_planet; |
17 | 17 | $destination_planet = &$mission_data->dst_planet; |
18 | 18 | |
19 | - if(!isset($destination_planet['id']) || !$destination_planet['id_owner']) { |
|
19 | + if (!isset($destination_planet['id']) || !$destination_planet['id_owner']) { |
|
20 | 20 | $objFleet->mark_fleet_as_returned_and_save(); |
21 | 21 | |
22 | 22 | return CACHE_FLEET; |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | $fleet_resources[RES_DEUTERIUM], $lang['Deuterium']); |
32 | 32 | msg_send_simple_message($objFleet->target_owner_id, '', $objFleet->time_arrive_to_target, MSG_TYPE_TRANSPORT, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $Message); |
33 | 33 | |
34 | - if($objFleet->target_owner_id <> $objFleet->playerOwnerId) { |
|
34 | + if ($objFleet->target_owner_id <> $objFleet->playerOwnerId) { |
|
35 | 35 | msg_send_simple_message($objFleet->playerOwnerId, '', $objFleet->time_arrive_to_target, MSG_TYPE_TRANSPORT, $lang['sys_mess_tower'], $lang['sys_mess_transport'], $Message); |
36 | 36 | } |
37 | 37 |
@@ -31,7 +31,7 @@ |
||
31 | 31 | /** |
32 | 32 | * Fleet mission "Relocate" |
33 | 33 | * |
34 | - * @param $mission_data Mission |
|
34 | + * @param Mission $mission_data Mission |
|
35 | 35 | * |
36 | 36 | * @return int |
37 | 37 | * |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | |
21 | 21 | $destination_planet = &$mission_data->dst_planet; |
22 | 22 | |
23 | - if(empty($destination_planet['id'])) { |
|
23 | + if (empty($destination_planet['id'])) { |
|
24 | 24 | $objFleet->mark_fleet_as_returned(); |
25 | 25 | $objFleet->flush_changes_to_db(); |
26 | 26 | |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | $OtherFleetCapacity = 0; |
32 | 32 | |
33 | 33 | $fleet_array = $objFleet->get_unit_list(); |
34 | - foreach($fleet_array as $unit_id => $unit_count) { |
|
35 | - if(in_array($unit_id, sn_get_groups('fleet'))) { |
|
34 | + foreach ($fleet_array as $unit_id => $unit_count) { |
|
35 | + if (in_array($unit_id, sn_get_groups('fleet'))) { |
|
36 | 36 | $capacity = get_unit_param($unit_id, P_CAPACITY) * $unit_count; |
37 | - if(in_array($unit_id, sn_get_groups('flt_recyclers'))) { |
|
37 | + if (in_array($unit_id, sn_get_groups('flt_recyclers'))) { |
|
38 | 38 | $RecyclerCapacity += $capacity; |
39 | 39 | } else { |
40 | 40 | $OtherFleetCapacity += $capacity; |
@@ -43,33 +43,33 @@ discard block |
||
43 | 43 | } |
44 | 44 | |
45 | 45 | $fleet_resources_amount = $objFleet->get_resources_amount(); |
46 | - if($fleet_resources_amount > $OtherFleetCapacity) { |
|
46 | + if ($fleet_resources_amount > $OtherFleetCapacity) { |
|
47 | 47 | // Если во флоте есть другие корабли И количество ресурсов больше, чем их ёмкость трюмов - значит часть этих ресурсов лежит в трюмах переработчиков |
48 | 48 | // Уменьшаем ёмкость переработчиков на указанную величину |
49 | 49 | $RecyclerCapacity -= ($fleet_resources_amount - $OtherFleetCapacity); |
50 | 50 | } |
51 | 51 | |
52 | 52 | $resources_recycled = array(); |
53 | - if(($destination_planet["debris_metal"] + $destination_planet["debris_crystal"]) <= $RecyclerCapacity) { |
|
53 | + if (($destination_planet["debris_metal"] + $destination_planet["debris_crystal"]) <= $RecyclerCapacity) { |
|
54 | 54 | $resources_recycled[RES_METAL] = $destination_planet["debris_metal"]; |
55 | 55 | $resources_recycled[RES_CRYSTAL] = $destination_planet["debris_crystal"]; |
56 | 56 | } else { |
57 | - if(($destination_planet["debris_metal"] > $RecyclerCapacity / 2) && |
|
57 | + if (($destination_planet["debris_metal"] > $RecyclerCapacity / 2) && |
|
58 | 58 | ($destination_planet["debris_crystal"] > $RecyclerCapacity / 2) |
59 | 59 | ) { |
60 | 60 | $resources_recycled[RES_METAL] = $RecyclerCapacity / 2; |
61 | 61 | $resources_recycled[RES_CRYSTAL] = $RecyclerCapacity / 2; |
62 | 62 | } else { |
63 | - if($destination_planet["debris_metal"] > $destination_planet["debris_crystal"]) { |
|
63 | + if ($destination_planet["debris_metal"] > $destination_planet["debris_crystal"]) { |
|
64 | 64 | $resources_recycled[RES_CRYSTAL] = $destination_planet["debris_crystal"]; |
65 | - if($destination_planet["debris_metal"] > ($RecyclerCapacity - $resources_recycled[RES_CRYSTAL])) { |
|
65 | + if ($destination_planet["debris_metal"] > ($RecyclerCapacity - $resources_recycled[RES_CRYSTAL])) { |
|
66 | 66 | $resources_recycled[RES_METAL] = $RecyclerCapacity - $resources_recycled[RES_CRYSTAL]; |
67 | 67 | } else { |
68 | 68 | $resources_recycled[RES_METAL] = $destination_planet["debris_metal"]; |
69 | 69 | } |
70 | 70 | } else { |
71 | 71 | $resources_recycled[RES_METAL] = $destination_planet["debris_metal"]; |
72 | - if($destination_planet["debris_crystal"] > ($RecyclerCapacity - $resources_recycled[RES_METAL])) { |
|
72 | + if ($destination_planet["debris_crystal"] > ($RecyclerCapacity - $resources_recycled[RES_METAL])) { |
|
73 | 73 | $resources_recycled[RES_CRYSTAL] = $RecyclerCapacity - $resources_recycled[RES_METAL]; |
74 | 74 | } else { |
75 | 75 | $resources_recycled[RES_CRYSTAL] = $destination_planet["debris_crystal"]; |
@@ -39,23 +39,23 @@ discard block |
||
39 | 39 | |
40 | 40 | $sta_update_msg = db_escape($sta_update_msg); |
41 | 41 | |
42 | - if($next_step) { |
|
42 | + if ($next_step) { |
|
43 | 43 | $sta_update_step++; |
44 | 44 | } |
45 | 45 | $sta_update_msg = "Update in progress. Step {$sta_update_step}/14: {$sta_update_msg}."; |
46 | 46 | |
47 | 47 | $config->db_saveItem('var_stat_update_msg', $sta_update_msg); |
48 | - if($next_step) { |
|
48 | + if ($next_step) { |
|
49 | 49 | $debug->warning($sta_update_msg, 'Stat update', LOG_INFO_STAT_PROCESS); |
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
53 | 53 | function sys_stat_calculate_flush(&$data, $force = false) { |
54 | - if(count($data) < 25 && !$force) { |
|
54 | + if (count($data) < 25 && !$force) { |
|
55 | 55 | return; |
56 | 56 | } |
57 | 57 | |
58 | - if(!empty($data)) { |
|
58 | + if (!empty($data)) { |
|
59 | 59 | doquery('REPLACE INTO {{statpoints}} |
60 | 60 | (`id_owner`, `id_ally`, `stat_type`, `stat_code`, `tech_points`, `tech_count`, `build_points`, `build_count`, |
61 | 61 | `defs_points`, `defs_count`, `fleet_points`, `fleet_count`, `res_points`, `res_count`, `total_points`, |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | $user_list = db_user_list('', true, 'id, dark_matter, metal, crystal, deuterium, user_as_ally, ally_id'); |
96 | 96 | $row_num = count($user_list); |
97 | 97 | // while($player = db_fetch($query)) |
98 | - foreach($user_list as $player) { |
|
99 | - if($i++ % 100 == 0) { |
|
98 | + foreach ($user_list as $player) { |
|
99 | + if ($i++ % 100 == 0) { |
|
100 | 100 | sta_set_time_limit("calculating players stats (player {$i}/{$row_num})", false); |
101 | 101 | } |
102 | - if(array_key_exists($user_id = $player['id'], $user_skip_list)) { |
|
102 | + if (array_key_exists($user_id = $player['id'], $user_skip_list)) { |
|
103 | 103 | continue; |
104 | 104 | } |
105 | 105 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | // $points[$user_id][UNIT_RESOURCES] += $resources; |
110 | 110 | |
111 | 111 | // А здесь мы фильтруем пользователей по $user_skip_list - далее не нужно этого делать, потому что |
112 | - if(!isset($user_skip_list[$user_id])) { |
|
112 | + if (!isset($user_skip_list[$user_id])) { |
|
113 | 113 | $user_allies[$user_id] = $player['ally_id']; |
114 | 114 | } |
115 | 115 | } |
@@ -123,11 +123,11 @@ discard block |
||
123 | 123 | $i = 0; |
124 | 124 | $query = db_planet_list_resources_by_owner(); |
125 | 125 | $row_num = db_num_rows($query); |
126 | - while($planet = db_fetch($query)) { |
|
127 | - if($i++ % 100 == 0) { |
|
126 | + while ($planet = db_fetch($query)) { |
|
127 | + if ($i++ % 100 == 0) { |
|
128 | 128 | sta_set_time_limit("calculating planets stats (planet {$i}/{$row_num})", false); |
129 | 129 | } |
130 | - if(array_key_exists($user_id = $planet['id_owner'], $user_skip_list)) { |
|
130 | + if (array_key_exists($user_id = $planet['id_owner'], $user_skip_list)) { |
|
131 | 131 | continue; |
132 | 132 | } |
133 | 133 | |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | $i = 0; |
143 | 143 | $query = FleetList::dbQueryAllId(); |
144 | 144 | $row_num = db_num_rows($query); |
145 | - while($fleet_row = db_fetch($query)) { |
|
146 | - if($i++ % 100 == 0) { |
|
145 | + while ($fleet_row = db_fetch($query)) { |
|
146 | + if ($i++ % 100 == 0) { |
|
147 | 147 | sta_set_time_limit("calculating flying fleets stats (fleet {$i}/{$row_num})", false); |
148 | 148 | } |
149 | 149 | $objFleet = new Fleet(); |
@@ -151,15 +151,15 @@ discard block |
||
151 | 151 | // К тому же при включённом кэшировании это быстро забъёт кэш холодными данными |
152 | 152 | // $objFleet->_reset(); |
153 | 153 | $objFleet->dbRowParse($fleet_row); |
154 | - if(array_key_exists($user_id = $objFleet->playerOwnerId, $user_skip_list)) { |
|
154 | + if (array_key_exists($user_id = $objFleet->playerOwnerId, $user_skip_list)) { |
|
155 | 155 | continue; |
156 | 156 | } |
157 | 157 | |
158 | 158 | $fleet = $objFleet->get_unit_list(); |
159 | - foreach($fleet as $unit_id => $unit_amount) { |
|
159 | + foreach ($fleet as $unit_id => $unit_amount) { |
|
160 | 160 | $counts[$user_id][UNIT_SHIPS] += $unit_amount; |
161 | 161 | |
162 | - if(!isset($unit_cost_cache[$unit_id][0])) { |
|
162 | + if (!isset($unit_cost_cache[$unit_id][0])) { |
|
163 | 163 | $unit_cost_cache[$unit_id][0] = get_unit_param($unit_id, P_COST); |
164 | 164 | } |
165 | 165 | $unit_cost_data = &$unit_cost_cache[$unit_id][0]; |
@@ -179,11 +179,11 @@ discard block |
||
179 | 179 | $i = 0; |
180 | 180 | $query = db_unit_list_stat_calculate(); |
181 | 181 | $row_num = db_num_rows($query); |
182 | - while($unit = db_fetch($query)) { |
|
183 | - if($i++ % 100 == 0) { |
|
182 | + while ($unit = db_fetch($query)) { |
|
183 | + if ($i++ % 100 == 0) { |
|
184 | 184 | sta_set_time_limit("calculating unit stats (unit {$i}/{$row_num})", false); |
185 | 185 | } |
186 | - if(array_key_exists($user_id = $unit['unit_player_id'], $user_skip_list)) { |
|
186 | + if (array_key_exists($user_id = $unit['unit_player_id'], $user_skip_list)) { |
|
187 | 187 | continue; |
188 | 188 | } |
189 | 189 | |
@@ -197,11 +197,11 @@ discard block |
||
197 | 197 | $i = 0; |
198 | 198 | $query = db_que_list_stat(); |
199 | 199 | $row_num = db_num_rows($query); |
200 | - while($que_item = db_fetch($query)) { |
|
201 | - if($i++ % 100 == 0) { |
|
200 | + while ($que_item = db_fetch($query)) { |
|
201 | + if ($i++ % 100 == 0) { |
|
202 | 202 | sta_set_time_limit("calculating ques stats (que item {$i}/{$row_num})", false); |
203 | 203 | } |
204 | - if(array_key_exists($user_id = $que_item['que_player_id'], $user_skip_list)) { |
|
204 | + if (array_key_exists($user_id = $que_item['que_player_id'], $user_skip_list)) { |
|
205 | 205 | continue; |
206 | 206 | } |
207 | 207 | $que_unit_amount = $que_item['que_unit_amount']; |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | |
220 | 220 | sta_set_time_limit('posting new user stats to DB'); |
221 | 221 | $data = array(); |
222 | - foreach($user_allies as $user_id => $ally_id) { |
|
222 | + foreach ($user_allies as $user_id => $ally_id) { |
|
223 | 223 | // $counts[UNIT_RESOURCES] дублирует $points[UNIT_RESOURCES], поэтому $points не заполняем, а берем $counts и делим на 1000 |
224 | 224 | $points[$user_id][UNIT_RESOURCES] = $counts[$user_id][UNIT_RESOURCES] / 1000; |
225 | 225 | $points[$user_id] = array_map('floor', $points[$user_id]); |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | |
276 | 276 | // Updating player's ranks |
277 | 277 | sta_set_time_limit("updating ranks for players"); |
278 | - foreach($rankNames as $rankName) { |
|
278 | + foreach ($rankNames as $rankName) { |
|
279 | 279 | sta_set_time_limit("updating player rank '{$rankName}'", false); |
280 | 280 | doquery($qryResetRowNum); |
281 | 281 | doquery(sprintf($qryFormat, $rankName, 1)); |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | |
284 | 284 | sta_set_time_limit("updating ranks for Alliances"); |
285 | 285 | // --- Updating Allie's ranks |
286 | - foreach($rankNames as $rankName) { |
|
286 | + foreach ($rankNames as $rankName) { |
|
287 | 287 | sta_set_time_limit("updating Alliances rank '{$rankName}'", false); |
288 | 288 | doquery($qryResetRowNum); |
289 | 289 | doquery(sprintf($qryFormat, $rankName, 2)); |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | parent::setUnitId($unitId); |
51 | 51 | |
52 | 52 | // Reset combat stats?? |
53 | - if($this->_unitId) { |
|
53 | + if ($this->_unitId) { |
|
54 | 54 | $this->amplify = $this->info[P_AMPLIFY]; |
55 | 55 | $this->capacity = $this->info[P_CAPACITY]; |
56 | 56 | $this->price[RES_METAL] = $this->info[P_COST][RES_METAL]; |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $this->bonus_attack = $this->info[P_ATTACK]; |
73 | 73 | $this->bonus_shield = $this->info[P_SHIELD]; |
74 | 74 | $this->bonus_armor = $this->info[P_ARMOR]; |
75 | - if(is_object($this->unit_bonus)) { |
|
75 | + if (is_object($this->unit_bonus)) { |
|
76 | 76 | $this->bonus_attack = floor($this->bonus_attack * $this->unit_bonus->calcBonus(P_ATTACK)); |
77 | 77 | $this->bonus_shield = floor($this->bonus_shield * $this->unit_bonus->calcBonus(P_SHIELD)); |
78 | 78 | $this->bonus_armor = floor($this->bonus_armor * $this->unit_bonus->calcBonus(P_ARMOR)); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $this->randomized_attack = $this->bonus_attack; |
81 | 81 | $this->randomized_shield = $this->bonus_shield; |
82 | 82 | $this->randomized_armor = $this->bonus_armor; |
83 | - if(!$is_simulator) { |
|
83 | + if (!$is_simulator) { |
|
84 | 84 | // TODO - randomize attack if is not simulator |
85 | 85 | $this->randomized_attack = floor($this->bonus_attack * ($is_simulator ? 1 : mt_rand(UBE_RANDOMIZE_FROM, UBE_RANDOMIZE_TO) / 100)); |
86 | 86 | $this->randomized_shield = floor($this->bonus_shield * ($is_simulator ? 1 : mt_rand(UBE_RANDOMIZE_FROM, UBE_RANDOMIZE_TO) / 100)); |
@@ -159,22 +159,22 @@ discard block |
||
159 | 159 | * @version 2016-02-25 23:42:45 41a4.68 |
160 | 160 | */ |
161 | 161 | public function restore_unit($is_simulator) { |
162 | - if($this->_type != UNIT_DEFENCE || $this->units_lost <= 0) { |
|
162 | + if ($this->_type != UNIT_DEFENCE || $this->units_lost <= 0) { |
|
163 | 163 | return; |
164 | 164 | } |
165 | 165 | |
166 | - if($is_simulator) { |
|
166 | + if ($is_simulator) { |
|
167 | 167 | $units_giveback = round($this->units_lost * UBE_DEFENCE_RESTORATION_CHANCE_AVG / 100); // for simulation just return 75% of loss |
168 | 168 | } else { |
169 | 169 | // Checking - should we trigger mass-restore |
170 | - if($this->units_lost >= UBE_DEFENCE_RESTORATION_MASS_COUNT) { |
|
170 | + if ($this->units_lost >= UBE_DEFENCE_RESTORATION_MASS_COUNT) { |
|
171 | 171 | // For large amount - mass-restoring defence |
172 | 172 | $units_giveback = round($this->units_lost * mt_rand(UBE_DEFENCE_RESTORATION_CHANCE_MIN, UBE_DEFENCE_RESTORATION_CHANCE_MAX) / 100); |
173 | 173 | } else { |
174 | 174 | // For small amount - restoring defence per single unit |
175 | 175 | $units_giveback = 0; |
176 | - for($i = 1; $i <= $this->units_lost; $i++) { |
|
177 | - if(mt_rand(1, 100) <= UBE_DEFENCE_RESTORATION_CHANCE_AVG) { |
|
176 | + for ($i = 1; $i <= $this->units_lost; $i++) { |
|
177 | + if (mt_rand(1, 100) <= UBE_DEFENCE_RESTORATION_CHANCE_AVG) { |
|
178 | 178 | $units_giveback++; |
179 | 179 | } |
180 | 180 | } |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function receive_damage($is_simulator) { |
195 | 195 | // TODO - Добавить взрывы от полуповрежденных юнитов - т.е. заранее вычислить из убитых юнитов еще количество убитых умножить на вероятность от структуры |
196 | - if($this->_count <= 0) { |
|
196 | + if ($this->_count <= 0) { |
|
197 | 197 | return; |
198 | 198 | } |
199 | 199 | |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | $this->adjustCount(-$units_lost); |
217 | 217 | |
218 | 218 | // Проверяем - не взорвался ли текущий юнит |
219 | - while($this->_count > 0 && $this->attack_income > 0) { |
|
219 | + while ($this->_count > 0 && $this->attack_income > 0) { |
|
220 | 220 | $this->attack_damaged_unit($is_simulator); |
221 | 221 | } |
222 | 222 | |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | $armor_left = $this->pool_armor % $this->randomized_armor; |
242 | 242 | // Проверка - не атакуем ли мы целый корабль |
243 | 243 | // Такое может быть, если на прошлой итерации поврежденный корабль был взорван и еще осталась входящяя атака |
244 | - if($shield_left == 0 && $armor_left == 0) { |
|
244 | + if ($shield_left == 0 && $armor_left == 0) { |
|
245 | 245 | $shield_left = $this->randomized_shield; |
246 | 246 | $armor_left = $this->randomized_armor; |
247 | 247 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | // Вычитаем этот дамадж из щитов пула |
256 | 256 | $this->pool_shield -= $damage_to_shield; |
257 | 257 | // Если весь дамадж был поглощён щитами - выходим |
258 | - if($this->attack_income <= 0) { |
|
258 | + if ($this->attack_income <= 0) { |
|
259 | 259 | return; |
260 | 260 | } |
261 | 261 | |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | $armor_left -= $damage_to_armor; |
273 | 273 | |
274 | 274 | // Проверяем - осталась ли броня на текущем корабле и вааще |
275 | - if($this->pool_armor <= 0 || $armor_left <= 0) { |
|
275 | + if ($this->pool_armor <= 0 || $armor_left <= 0) { |
|
276 | 276 | // Не осталось - корабль уничтожен |
277 | 277 | $this->adjustCount(-1); |
278 | 278 | |
@@ -283,10 +283,10 @@ discard block |
||
283 | 283 | $armor_left_percent = $armor_left / $this->randomized_armor * 100; |
284 | 284 | // Проверяем % здоровья |
285 | 285 | // TODO - сделать динамический процент для каждого вида юнитов |
286 | - if($armor_left_percent <= UBE_CRITICAL_DAMAGE_THRESHOLD) { |
|
286 | + if ($armor_left_percent <= UBE_CRITICAL_DAMAGE_THRESHOLD) { |
|
287 | 287 | // Дамадж пошёл по структуре. Чем более поврежден юнит - тем больше шансов у него взорваться |
288 | 288 | $random = $is_simulator ? UBE_CRITICAL_DAMAGE_THRESHOLD / 2 : mt_rand(0, 100); |
289 | - if($random >= $armor_left_percent) { |
|
289 | + if ($random >= $armor_left_percent) { |
|
290 | 290 | $this->adjustCount(-1); |
291 | 291 | $this->unit_count_boom++; |
292 | 292 |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | UBE_PLAYER_IS_DEFENDER => array(), |
56 | 56 | ); |
57 | 57 | |
58 | - foreach($this->_container as $player_id => $UBEPlayer) { |
|
58 | + foreach ($this->_container as $player_id => $UBEPlayer) { |
|
59 | 59 | $result[$UBEPlayer->getSide() ? UBE_PLAYER_IS_ATTACKER : UBE_PLAYER_IS_DEFENDER][$player_id] = $UBEPlayer->getDbRow(); |
60 | 60 | } |
61 | 61 | |
@@ -70,8 +70,8 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function get_first_player_on_side($side) { |
72 | 72 | $result = null; |
73 | - foreach($this->_container as $player_id => $UBEPlayer) { |
|
74 | - if($UBEPlayer->getSide() == $side) { |
|
73 | + foreach ($this->_container as $player_id => $UBEPlayer) { |
|
74 | + if ($UBEPlayer->getSide() == $side) { |
|
75 | 75 | $result = $UBEPlayer; |
76 | 76 | break; |
77 | 77 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function get_player_sides() { |
90 | 90 | $result = array(); |
91 | - foreach($this->_container as $player_id => $UBEPlayer) { |
|
91 | + foreach ($this->_container as $player_id => $UBEPlayer) { |
|
92 | 92 | $result[$player_id] = $UBEPlayer->getSide() ? UBE_PLAYER_IS_ATTACKER : UBE_PLAYER_IS_DEFENDER; |
93 | 93 | } |
94 | 94 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | public function ubeLoadPlayersAndSetSideFromFleetIdList(array $added_fleets, UBEFleetList $fleetList, $side = UBE_PLAYER_IS_DEFENDER) { |
99 | - foreach($added_fleets as $fleet_id) { |
|
99 | + foreach ($added_fleets as $fleet_id) { |
|
100 | 100 | $this->db_load_player_by_id($fleetList[$fleet_id]->owner_id, $side); |
101 | 101 | } |
102 | 102 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | |
71 | 71 | $debris_for_moon = $debris->debris_total(); |
72 | 72 | |
73 | - if(!$debris_for_moon) { |
|
73 | + if (!$debris_for_moon) { |
|
74 | 74 | return; |
75 | 75 | } |
76 | 76 | |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | $moon_chance = min($debris_for_moon / UBE_MOON_DEBRIS_PER_PERCENT, UBE_MOON_PERCENT_MAX); // TODO Configure |
79 | 79 | $moon_chance = $moon_chance >= UBE_MOON_PERCENT_MIN ? $moon_chance : 0; |
80 | 80 | $this->create_chance = $moon_chance; |
81 | - if($moon_chance) { |
|
82 | - if($is_simulator || mt_rand(1, 100) <= $moon_chance) { |
|
81 | + if ($moon_chance) { |
|
82 | + if ($is_simulator || mt_rand(1, 100) <= $moon_chance) { |
|
83 | 83 | $this->status = UBE_MOON_CREATE_SUCCESS; |
84 | 84 | $this->moon_diameter = round($is_simulator ? $moon_chance * 150 + 1999 : mt_rand($moon_chance * 100 + 1000, $moon_chance * 200 + 2999)); |
85 | 85 | |
86 | - if($debris_for_moon <= UBE_MOON_DEBRIS_MAX_SPENT) { |
|
86 | + if ($debris_for_moon <= UBE_MOON_DEBRIS_MAX_SPENT) { |
|
87 | 87 | $debris->_reset(); |
88 | 88 | } else { |
89 | 89 | $moon_debris_left_percent = ($debris_for_moon - UBE_MOON_DEBRIS_MAX_SPENT) / $debris_for_moon; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | protected function moon_destroy_try($reapers) { |
104 | 104 | // TODO: $is_simulator |
105 | - if($reapers <= 0) { |
|
105 | + if ($reapers <= 0) { |
|
106 | 106 | return; |
107 | 107 | } |
108 | 108 | |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @version 2016-02-25 23:42:45 41a4.68 |
121 | 121 | */ |
122 | 122 | public function calculate_moon(UBE $ube) { |
123 | - if(UBE_MOON_EXISTS == $this->status) { |
|
124 | - if($ube->mission_type_id == MT_DESTROY && $ube->combat_result == UBE_COMBAT_RESULT_WIN) { |
|
123 | + if (UBE_MOON_EXISTS == $this->status) { |
|
124 | + if ($ube->mission_type_id == MT_DESTROY && $ube->combat_result == UBE_COMBAT_RESULT_WIN) { |
|
125 | 125 | $reapers = $ube->fleet_list->ube_calculate_attack_reapers(); |
126 | 126 | $this->moon_destroy_try($reapers); |
127 | 127 | } |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | } |
132 | 132 | |
133 | 133 | public function report_generate_sql() { |
134 | - return "`ube_report_moon` = " . (int)$this->status . ", |
|
135 | - `ube_report_moon_chance` = " . (int)$this->create_chance . ", |
|
136 | - `ube_report_moon_size` = " . (float)$this->moon_diameter . ", |
|
137 | - `ube_report_moon_reapers` = " . (int)$this->reapers_status . ", |
|
138 | - `ube_report_moon_destroy_chance` = " . (int)$this->destroy_chance . ", |
|
139 | - `ube_report_moon_reapers_die_chance` = " . (int)$this->reaper_die_chance; |
|
134 | + return "`ube_report_moon` = " . (int) $this->status . ", |
|
135 | + `ube_report_moon_chance` = " . (int) $this->create_chance . ", |
|
136 | + `ube_report_moon_size` = " . (float) $this->moon_diameter . ", |
|
137 | + `ube_report_moon_reapers` = " . (int) $this->reapers_status . ", |
|
138 | + `ube_report_moon_destroy_chance` = " . (int) $this->destroy_chance . ", |
|
139 | + `ube_report_moon_reapers_die_chance` = " . (int) $this->reaper_die_chance; |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | public function report_render_moon() { |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | * @param $planet_id |
167 | 167 | */ |
168 | 168 | public function db_apply_result($planet_info, $destination_user_id) { |
169 | - if($this->status == UBE_MOON_CREATE_SUCCESS) { |
|
169 | + if ($this->status == UBE_MOON_CREATE_SUCCESS) { |
|
170 | 170 | $moon_row = uni_create_moon($planet_info[PLANET_GALAXY], $planet_info[PLANET_SYSTEM], $planet_info[PLANET_PLANET], $destination_user_id, $this->moon_diameter, '', false); |
171 | 171 | $this->moon_name = $moon_row['name']; |
172 | 172 | unset($moon_row); |
173 | - } elseif($this->status == UBE_MOON_DESTROY_SUCCESS) { |
|
173 | + } elseif ($this->status == UBE_MOON_DESTROY_SUCCESS) { |
|
174 | 174 | db_planet_delete_by_id($planet_info[PLANET_ID]); |
175 | 175 | } |
176 | 176 | } |
@@ -179,14 +179,14 @@ discard block |
||
179 | 179 | global $lang; |
180 | 180 | |
181 | 181 | $text_defender = ''; |
182 | - if($this->status == UBE_MOON_CREATE_SUCCESS) { |
|
182 | + if ($this->status == UBE_MOON_CREATE_SUCCESS) { |
|
183 | 183 | $text_defender .= "{$lang['ube_report_moon_created']} {$this->moon_diameter} {$lang['sys_kilometers_short']}<br /><br />"; |
184 | - } elseif($this->status == UBE_MOON_CREATE_FAILED) { |
|
184 | + } elseif ($this->status == UBE_MOON_CREATE_FAILED) { |
|
185 | 185 | $text_defender .= "{$lang['ube_report_moon_chance']} {$this->create_chance}%<br /><br />"; |
186 | 186 | } |
187 | 187 | |
188 | - if($ube->mission_type_id == MT_DESTROY) { |
|
189 | - if($this->reapers_status == UBE_MOON_REAPERS_NONE) { |
|
188 | + if ($ube->mission_type_id == MT_DESTROY) { |
|
189 | + if ($this->reapers_status == UBE_MOON_REAPERS_NONE) { |
|
190 | 190 | $text_defender .= $lang['ube_report_moon_reapers_none']; |
191 | 191 | } else { |
192 | 192 | $text_defender .= "{$lang['ube_report_moon_reapers_wave']}. {$lang['ube_report_moon_reapers_chance']} {$this->destroy_chance}%. "; |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @version 2016-02-25 23:42:45 41a4.68 |
216 | 216 | */ |
217 | 217 | public function ubeInitLoadStatis($destination_planet) { |
218 | - if($destination_planet['planet_type'] == PT_MOON || is_array($moon = db_planet_by_parent($destination_planet['id'], true, '`id`'))) { |
|
218 | + if ($destination_planet['planet_type'] == PT_MOON || is_array($moon = db_planet_by_parent($destination_planet['id'], true, '`id`'))) { |
|
219 | 219 | $this->status = UBE_MOON_EXISTS; |
220 | 220 | $this->moon_diameter = !empty($moon['planet_type']) && $moon['planet_type'] == PT_MOON ? $moon['diameter'] : $destination_planet['diameter']; |
221 | 221 | $this->reapers_status = UBE_MOON_REAPERS_NONE; |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public function report_render_rounds(&$template_result, UBE $ube) { |
27 | 27 | $round_count = $this->count(); |
28 | - for($round = 1; $round <= $round_count - 1; $round++) { |
|
28 | + for ($round = 1; $round <= $round_count - 1; $round++) { |
|
29 | 29 | $template_result['.']['round'][] = array( |
30 | 30 | 'NUMBER' => $round, |
31 | 31 | '.' => array( |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function sql_generate_unit_array(array &$sql_perform_ube_report_unit, $ube_report_id, UBEFleetList $UBEFleetList) { |
50 | 50 | $unit_sort_order = 1; |
51 | - foreach($this->_container as $round_number => $UBERound) { |
|
51 | + foreach ($this->_container as $round_number => $UBERound) { |
|
52 | 52 | $outer_prefix = array( |
53 | 53 | $ube_report_id, |
54 | 54 | $round_number, |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function db_load_round_list_from_report_row($report_row, UBE $ube) { |
68 | 68 | $query = doquery("SELECT * FROM {{ube_report_unit}} WHERE `ube_report_id` = {$report_row['ube_report_id']} ORDER BY `ube_report_unit_id`"); |
69 | - while($report_unit_row = db_fetch($query)) { |
|
69 | + while ($report_unit_row = db_fetch($query)) { |
|
70 | 70 | $round_number = $report_unit_row['ube_report_unit_round']; |
71 | - if(!isset($this[$round_number])) { |
|
71 | + if (!isset($this[$round_number])) { |
|
72 | 72 | $this[$round_number] = new UBERound(); |
73 | 73 | $this[$round_number]->init_round_from_report_unit_row($report_unit_row); |
74 | 74 | } |