1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Fleet\DbFleetStatic; |
4
|
|
|
use Planet\DBStaticPlanet; |
5
|
|
|
use Universe\Universe; |
|
|
|
|
6
|
|
|
|
7
|
|
|
function uni_create_planet_get_density($position_data, $user_row, $planet_sectors) { |
8
|
|
|
$density_list = sn_get_groups('planet_density'); |
9
|
|
|
$density_min = reset($density_list); |
10
|
|
|
unset($density_list[PLANET_DENSITY_NONE]); |
11
|
|
|
|
12
|
|
|
$possible_cores = array(); |
13
|
|
|
$probability = 0; |
14
|
|
|
foreach ($density_list as $possible_core_id => $core_data) { |
15
|
|
|
if (!$core_data[UNIT_PLANET_DENSITY_RARITY]) { |
16
|
|
|
continue; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
if ( |
20
|
|
|
// Core type exists |
21
|
|
|
in_array($possible_core_id, $position_data['core_types']) |
22
|
|
|
// Limit core type with planet sector count |
23
|
|
|
&& $planet_sectors < $density_list[$possible_core_id][UNIT_PLANET_DENSITY_MAX_SECTORS] |
24
|
|
|
// Limit core type with player AstroTech level |
25
|
|
|
&& (empty($user_row) || mrc_get_level($user_row, null, TECH_ASTROTECH) >= $density_list[$possible_core_id][UNIT_PLANET_DENSITY_MIN_ASTROTECH]) |
26
|
|
|
) { |
27
|
|
|
// Фильтруем типы ядер, которые не подходят по размеру планеты |
28
|
|
|
$probability += $density_list[$possible_core_id][UNIT_PLANET_DENSITY_RARITY]; |
29
|
|
|
$possible_cores[$possible_core_id] = array( |
30
|
|
|
UNIT_PLANET_DENSITY_INDEX => $possible_core_id, |
31
|
|
|
UNIT_PLANET_DENSITY_RARITY => $probability, |
32
|
|
|
UNIT_PLANET_DENSITY => mt_rand($density_min[UNIT_PLANET_DENSITY], $density_list[$possible_core_id][UNIT_PLANET_DENSITY] - 1), |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
$density_min = $density_list[$possible_core_id]; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$random = mt_rand(1, $probability); |
39
|
|
|
$selected_core = null; |
40
|
|
|
foreach ($possible_cores as $core_type => $core_info) { |
41
|
|
|
if ($random <= $core_info[UNIT_PLANET_DENSITY_RARITY]) { |
42
|
|
|
$selected_core = $core_info; |
43
|
|
|
break; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $selected_core; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param int $Galaxy |
52
|
|
|
* @param int $System |
53
|
|
|
* @param int $Position |
54
|
|
|
* @param int $PlanetOwnerID |
55
|
|
|
* @param string $planet_name_unsafe |
56
|
|
|
* @param bool|false $HomeWorld |
57
|
|
|
* @param array $options = [ |
58
|
|
|
* 'skip_check' => true, |
59
|
|
|
* 'user_row' => [], |
60
|
|
|
* 'force_name' => (string), // Force full planet name |
61
|
|
|
* 'image' => (string), // Force image |
62
|
|
|
* ] |
63
|
|
|
* |
64
|
|
|
* @return bool |
65
|
|
|
*/ |
66
|
|
|
function uni_create_planet($Galaxy, $System, $Position, $PlanetOwnerID, $planet_name_unsafe = '', $HomeWorld = false, $options = []) { |
67
|
|
|
$Position = intval($Position); |
68
|
|
|
|
69
|
|
|
if (!isset($options['skip_check']) && DBStaticPlanet::db_planet_by_gspt($Galaxy, $System, $Position, PT_PLANET)) { |
70
|
|
|
return false; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$user_row = !empty($options['user_row']) && is_array($options['user_row']) ? $options['user_row'] : db_user_by_id($PlanetOwnerID); |
|
|
|
|
74
|
|
|
|
75
|
|
|
|
76
|
|
|
$planet_generator = sn_get_groups('planet_generator'); |
77
|
|
|
|
78
|
|
|
if ($HomeWorld) { |
79
|
|
|
$position_data = $planet_generator[0]; |
80
|
|
|
} else { |
81
|
|
|
$position_data = $planet_generator[$Position >= UNIVERSE_RANDOM_PLANET_START || $Position < 1 ? UNIVERSE_RANDOM_PLANET_START : $Position]; |
82
|
|
|
if ($Position >= UNIVERSE_RANDOM_PLANET_START) { |
83
|
|
|
// Корректируем температуру для планеты-странника |
84
|
|
|
$position_data['t_max_max'] -= UNIVERSE_RANDOM_PLANET_TEMPERATURE_DECREASE * ($Position - UNIVERSE_RANDOM_PLANET_START); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if (!empty($options['image'])) { |
89
|
|
|
$planet_image = $options['image']; |
90
|
|
|
} else { |
91
|
|
|
$planet_images = sn_get_groups('planet_images'); |
92
|
|
|
$planet_image = $position_data['planet_images'][mt_rand(0, count($position_data['planet_images']) - 1)]; |
93
|
|
|
$planet_image .= 'planet' . $planet_images[$planet_image][mt_rand(0, count($planet_images[$planet_image]) - 1)]; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$t_max = sn_rand_gauss_range($position_data['t_max_min'], $position_data['t_max_max'], true, 1.3, true); |
|
|
|
|
97
|
|
|
$t_min = $t_max - sn_rand_gauss_range($position_data['t_delta_min'], $position_data['t_delta_max'], true, 1.3, true); |
98
|
|
|
|
99
|
|
|
$planet_sectors = sn_rand_gauss_range($position_data['size_min'], $position_data['size_max'], true, 1.7, true); |
100
|
|
|
// $planet_diameter = round(pow($planet_sectors, 2) * 1000); |
101
|
|
|
$planet_diameter = round(sqrt($planet_sectors) * 1000); |
102
|
|
|
|
103
|
|
|
$core_info = uni_create_planet_get_density($position_data, $user_row, $planet_sectors); |
104
|
|
|
|
105
|
|
|
$planet_name_unsafe = !empty($options['force_name']) ? $options['force_name'] : |
106
|
|
|
($user_row['username'] . ' ' . ( |
107
|
|
|
$HomeWorld |
108
|
|
|
? SN::$lang['sys_capital'] |
109
|
|
|
: ($planet_name_unsafe ?: SN::$lang['sys_colo_default_name']) |
110
|
|
|
) |
111
|
|
|
); |
112
|
|
|
|
113
|
|
|
$planet['name'] = SN::$db->db_escape(strip_tags(trim($planet_name_unsafe))); |
|
|
|
|
114
|
|
|
$planet['id_owner'] = $PlanetOwnerID; |
115
|
|
|
$planet['last_update'] = SN_TIME_NOW; |
116
|
|
|
$planet['image'] = $planet_image; |
117
|
|
|
|
118
|
|
|
$planet['galaxy'] = $Galaxy; |
119
|
|
|
$planet['system'] = $System; |
120
|
|
|
$planet['planet'] = $planet['position_original'] = $Position; |
121
|
|
|
$planet['planet_type'] = PT_PLANET; |
122
|
|
|
|
123
|
|
|
$planet['diameter'] = $planet_diameter; |
124
|
|
|
$planet['field_max'] = $planet['field_max_original'] = $planet_sectors; |
125
|
|
|
$planet['density'] = $core_info[UNIT_PLANET_DENSITY]; |
126
|
|
|
$planet['density_index'] = $core_info[UNIT_PLANET_DENSITY_INDEX]; |
127
|
|
|
$planet['temp_min'] = $planet['temp_min_original'] = $t_min; |
128
|
|
|
$planet['temp_max'] = $planet['temp_max_original'] = $t_max; |
129
|
|
|
|
130
|
|
|
$planet['metal'] = SN::$config->eco_planet_starting_metal; |
131
|
|
|
$planet['crystal'] = SN::$config->eco_planet_starting_crystal; |
132
|
|
|
$planet['deuterium'] = SN::$config->eco_planet_starting_deuterium; |
133
|
|
|
$planet['metal_max'] = SN::$config->eco_planet_storage_metal; |
134
|
|
|
$planet['crystal_max'] = SN::$config->eco_planet_storage_crystal; |
135
|
|
|
$planet['deuterium_max'] = SN::$config->eco_planet_storage_deuterium; |
136
|
|
|
|
137
|
|
|
$density_info_resources = &$density_list[$core_info[UNIT_PLANET_DENSITY_INDEX]][UNIT_RESOURCES]; |
|
|
|
|
138
|
|
|
$planet['metal_perhour'] = SN::$config->metal_basic_income * $density_info_resources[RES_METAL]; |
139
|
|
|
$planet['crystal_perhour'] = SN::$config->crystal_basic_income * $density_info_resources[RES_CRYSTAL]; |
140
|
|
|
$planet['deuterium_perhour'] = SN::$config->deuterium_basic_income * $density_info_resources[RES_DEUTERIUM]; |
141
|
|
|
|
142
|
|
|
$RetValue = SN::db_ins_record(LOC_PLANET, |
143
|
|
|
"`name` = '{$planet['name']}', `id_owner` = '{$planet['id_owner']}', `last_update` = '{$planet['last_update']}', `image` = '{$planet['image']}', |
144
|
|
|
`galaxy` = '{$planet['galaxy']}', `system` = '{$planet['system']}', `planet` = '{$planet['planet']}', `planet_type` = '{$planet['planet_type']}', `position_original` = '{$planet['position_original']}', |
145
|
|
|
`diameter` = '{$planet['diameter']}', `field_max` = '{$planet['field_max']}', `field_max_original` = '{$planet['field_max_original']}', |
146
|
|
|
`density` = '{$planet['density']}', `density_index` = '{$planet['density_index']}', |
147
|
|
|
`temp_min` = '{$planet['temp_min']}', `temp_max` = '{$planet['temp_max']}', `temp_min_original` = '{$planet['temp_min_original']}', `temp_max_original` = '{$planet['temp_max_original']}', |
148
|
|
|
`metal` = '{$planet['metal']}', `metal_perhour` = '{$planet['metal_perhour']}', `metal_max` = '{$planet['metal_max']}', |
149
|
|
|
`crystal` = '{$planet['crystal']}', `crystal_perhour` = '{$planet['crystal_perhour']}', `crystal_max` = '{$planet['crystal_max']}', |
150
|
|
|
`deuterium` = '{$planet['deuterium']}', `deuterium_perhour` = '{$planet['deuterium_perhour']}', `deuterium_max` = '{$planet['deuterium_max']}'" |
151
|
|
|
); |
152
|
|
|
|
153
|
|
|
return is_array($RetValue) ? $RetValue['id'] : false; // OK |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* uni_create_moon.php |
158
|
|
|
* |
159
|
|
|
* UNI: Create moon record |
160
|
|
|
* |
161
|
|
|
* V2.1 - copyright (c) 2010-2011 by Gorlum for http://supernova.ws |
162
|
|
|
* [~] Renamed CreateOneMoonRecord to uni_create_moon |
163
|
|
|
* [-] Removed unsed $MoonID parameter from call |
164
|
|
|
* [~] PCG1 compliant |
165
|
|
|
* V2.0 - copyright (c) 2010 by Gorlum for http://supernova.ws |
166
|
|
|
* [+] Deep rewrite to rid of using `galaxy` and `lunas` tables greatly reduce numbers of SQL-queries |
167
|
|
|
* @version 1.1 |
168
|
|
|
* @copyright 2008 |
169
|
|
|
*/ |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param $pos_galaxy |
173
|
|
|
* @param $pos_system |
174
|
|
|
* @param $pos_planet |
175
|
|
|
* @param $user_id |
176
|
|
|
* @param int $size <p><b>0</b> - random moon size</p> |
177
|
|
|
* @param bool $update_debris |
178
|
|
|
* @param array $options ['name' => (str), 'image' => (str)] |
179
|
|
|
* |
180
|
|
|
* @return array |
181
|
|
|
*/ |
182
|
|
|
function uni_create_moon($pos_galaxy, $pos_system, $pos_planet, $user_id, $size = 0, $update_debris = true, $options = []) { |
183
|
|
|
global $lang; |
184
|
|
|
|
185
|
|
|
$moon_row = []; |
186
|
|
|
$moon = DBStaticPlanet::db_planet_by_gspt($pos_galaxy, $pos_system, $pos_planet, PT_MOON); |
187
|
|
|
if (empty($moon['id'])) { |
188
|
|
|
$moon_planet = DBStaticPlanet::db_planet_by_gspt($pos_galaxy, $pos_system, $pos_planet, PT_PLANET); |
189
|
|
|
|
190
|
|
|
if ($moon_planet['id']) { |
191
|
|
|
$base_storage_size = BASE_STORAGE_SIZE; |
192
|
|
|
|
193
|
|
|
if (empty($size)) { |
194
|
|
|
$size = Universe::moonSizeRandom(); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
$temp_min = $moon_planet['temp_min'] - rand(10, 45); |
198
|
|
|
$temp_max = $temp_min + 40; |
199
|
|
|
|
200
|
|
|
$moon_name = !empty($options['name']) ? $options['name'] : "{$moon_planet['name']} {$lang['sys_moon']}"; |
201
|
|
|
$moon_name_safe = SN::$db->db_escape($moon_name); |
202
|
|
|
|
203
|
|
|
$field_max = ceil($size / 1000); |
204
|
|
|
|
205
|
|
|
$moon_image = !empty($options['image']) ? $options['image'] : 'mond'; |
206
|
|
|
|
207
|
|
|
$moon_row = SN::db_ins_record(LOC_PLANET, |
208
|
|
|
"`id_owner` = '{$user_id}', `parent_planet` = '{$moon_planet['id']}', `name` = '{$moon_name_safe}', `last_update` = " . SN_TIME_NOW . ", `image` = '{$moon_image}', |
209
|
|
|
`galaxy` = '{$pos_galaxy}', `system` = '{$pos_system}', `planet` = '{$pos_planet}', `planet_type` = " . PT_MOON . ", |
210
|
|
|
`diameter` = '{$size}', `field_max` = '{$field_max}', `density` = 2500, `density_index` = 2, `temp_min` = '{$temp_min}', `temp_max` = '{$temp_max}', |
211
|
|
|
`metal` = '0', `metal_perhour` = '0', `metal_max` = '{$base_storage_size}', |
212
|
|
|
`crystal` = '0', `crystal_perhour` = '0', `crystal_max` = '{$base_storage_size}', |
213
|
|
|
`deuterium` = '0', `deuterium_perhour` = '0', `deuterium_max` = '{$base_storage_size}'" |
214
|
|
|
); |
215
|
|
|
|
216
|
|
|
if ($update_debris) { |
217
|
|
|
$debris_spent = round($size / 1000 * Universe::moonPercentCostInDebris()); |
218
|
|
|
$metal_spent = round(min($moon_planet['debris_metal'], $debris_spent * mt_rand(50 * 1000, 75 * 1000) / (100 * 1000))); // Trick for higher mt_rand resolution |
219
|
|
|
$crystal_spent = min($moon_planet['debris_crystal'], $debris_spent - $metal_spent); |
220
|
|
|
$metal_spent = min($moon_planet['debris_metal'], $debris_spent - $crystal_spent); // Need if crystal less then their part |
221
|
|
|
DBStaticPlanet::db_planet_set_by_id($moon_planet['id'], "`debris_metal` = GREATEST(0, `debris_metal` - {$metal_spent}), `debris_crystal` = GREATEST(0, `debris_crystal` - {$crystal_spent})"); |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
return $moon_row; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/* |
230
|
|
|
* |
231
|
|
|
* @function SetSelectedPlanet |
232
|
|
|
* |
233
|
|
|
* @history |
234
|
|
|
* |
235
|
|
|
* 4 - copyright (c) 2014 by Gorlum for http://supernova.ws |
236
|
|
|
* [!] Full rewrote from scratch |
237
|
|
|
* 3 - copyright (c) 2009-2011 by Gorlum for http://supernova.ws |
238
|
|
|
* [+] Added handling case when current_planet does not exists or didn't belong to user |
239
|
|
|
* [+] Moved from SetSelectedPlanet.php |
240
|
|
|
* [+] Function now return |
241
|
|
|
* [~] Complies with PCG1 |
242
|
|
|
* 2 - copyright (c) 2009-2011 by Gorlum for http://supernova.ws |
243
|
|
|
* [~] Security checked for SQL-injection |
244
|
|
|
* 1 - copyright 2008 By Chlorel for XNova |
245
|
|
|
* |
246
|
|
|
*/ |
247
|
|
|
function SetSelectedPlanet(&$user) { |
248
|
|
|
$planet_row['id'] = $user['current_planet']; |
|
|
|
|
249
|
|
|
|
250
|
|
|
// Пытаемся переключить на новую планету |
251
|
|
|
if (($selected_planet = sys_get_param_id('cp')) && $selected_planet != $user['current_planet']) { |
252
|
|
|
$planet_row = DBStaticPlanet::db_planet_by_id_and_owner($selected_planet, $user['id'], false, 'id'); |
253
|
|
|
} else { |
254
|
|
|
$planet_row = DBStaticPlanet::db_planet_by_id($planet_row['id']); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
// Если новая планета не найдена или было переключения - проверяем текущую выбранную планету |
258
|
|
|
if (!isset($planet_row['id'])) // || $planet_row['id'] != $user['current_planet'] |
259
|
|
|
{ |
260
|
|
|
$planet_row = DBStaticPlanet::db_planet_by_id_and_owner($user['current_planet'], $user['id'], false, 'id'); |
261
|
|
|
// Если текущей планеты не существует - выставляем Столицу |
262
|
|
|
if (!isset($planet_row['id'])) { |
263
|
|
|
$planet_row = DBStaticPlanet::db_planet_by_id_and_owner($user['id_planet'], $user['id'], false, 'id'); |
264
|
|
|
// Если и столицы не существует - значит что-то очень не так с записью пользователя |
265
|
|
|
if (!isset($planet_row['id'])) { |
266
|
|
|
global $debug; |
267
|
|
|
$debug->error("User ID {$user['id']} has Capital planet {$user['id_planet']} but this planet does not exists", 'User record error', 502); |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
// Если производилось переключение планеты - делаем запись в юзере |
273
|
|
|
if ($user['current_planet'] != $planet_row['id']) { |
274
|
|
|
db_user_set_by_id($user['id'], "`current_planet` = '{$planet_row['id']}'"); |
|
|
|
|
275
|
|
|
$user['current_planet'] = $planet_row['id']; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
return $user['current_planet']; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
// ---------------------------------------------------------------------------------------------------------------- |
282
|
|
|
function uni_render_coordinates($from, $prefix = '') { |
283
|
|
|
return "[{$from[$prefix . 'galaxy']}:{$from[$prefix . 'system']}:{$from[$prefix . 'planet']}]"; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
function uni_render_planet($from) { |
287
|
|
|
return "{$from['name']} [{$from['galaxy']}:{$from['system']}:{$from['planet']}]"; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
function uni_render_planet_full($from, $prefix = '', $html_safe = true, $include_id = false) { |
291
|
|
|
global $lang; |
292
|
|
|
|
293
|
|
|
if (!$from['id']) { |
294
|
|
|
$result = $lang['sys_planet_expedition']; |
295
|
|
|
} else { |
296
|
|
|
$from_planet_id = $include_id ? ( |
297
|
|
|
'ID {' . ($from['id'] ? $from['id'] : ($from[$prefix . 'planet_id'] ? $from[$prefix . 'planet_id'] : 0)) . '} ' |
298
|
|
|
) : ''; |
299
|
|
|
|
300
|
|
|
$from_planet_type = $from['planet_type'] ? $from['planet_type'] : ($from[$prefix . 'type'] ? $from[$prefix . 'type'] : 0); |
301
|
|
|
$from_planet_type = ($from_planet_type ? ' ' . $lang['sys_planet_type_sh'][$from_planet_type] : ''); |
302
|
|
|
|
303
|
|
|
$result = $from_planet_id . uni_render_coordinates($from, $prefix) . $from_planet_type . ($from['name'] ? ' ' . $from['name'] : ''); |
304
|
|
|
$result = $html_safe ? HelperString::htmlEncode($result, HTML_ENCODE_PREFORM | HTML_ENCODE_SPACE) : $result; |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
return $result; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* @param \Planet\Planet $from |
312
|
|
|
* |
313
|
|
|
* @return string |
314
|
|
|
*/ |
315
|
|
|
function uni_render_coordinates_planet_object($from) { |
316
|
|
|
return is_object($from) ? "[{$from->galaxy}:{$from->system}:{$from->planet}]" : '[-:-:-]'; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* @param \Planet\Planet $from |
322
|
|
|
* @param bool $html_safe |
323
|
|
|
* @param bool $include_id |
324
|
|
|
* |
325
|
|
|
* @return mixed|null|string |
326
|
|
|
*/ |
327
|
|
|
function uni_render_planet_object_full($from, $html_safe = true, $include_id = false) { |
328
|
|
|
if (empty($from->id)) { |
329
|
|
|
$result = SN::$lang['sys_planet_expedition']; |
330
|
|
|
} else { |
331
|
|
|
$from_planet_id = $include_id ? ( |
332
|
|
|
'ID {' . ($from->id ? $from->id : 0) . '} ' |
333
|
|
|
) : ''; |
334
|
|
|
|
335
|
|
|
$from_planet_type = isset($from->planet_type) ? $from->planet_type : 0; |
336
|
|
|
$from_planet_type = ($from_planet_type ? ' ' . SN::$lang['sys_planet_type_sh'][$from_planet_type] : ''); |
337
|
|
|
|
338
|
|
|
$result = $from_planet_id . uni_render_coordinates_planet_object($from) . $from_planet_type . (isset($from->name) ? ' ' . $from->name : ''); |
339
|
|
|
$result = $html_safe ? HelperString::htmlEncode($result, HTML_ENCODE_PREFORM | HTML_ENCODE_SPACE) : $result; |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
return $result; |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
function uni_render_coordinates_url($from, $prefix = '', $page = 'galaxy.php') { |
346
|
|
|
return $page . (strpos($page, '?') === false ? '?' : '&') . "galaxy={$from[$prefix . 'galaxy']}&system={$from[$prefix . 'system']}&planet={$from[$prefix . 'planet']}"; |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
function uni_render_coordinates_href($from, $prefix = '', $mode = 0, $fleet_type = '') { |
350
|
|
|
return '<a href="' . uni_render_coordinates_url($from, $prefix, "galaxy.php?mode={$mode}") . '"' . ($fleet_type ? " {$fleet_type}" : '') . '>' . uni_render_coordinates($from, $prefix) . '</a>'; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
function uni_get_time_to_jump($moon_row) { |
354
|
|
|
$jump_gate_level = mrc_get_level($user, $moon_row, STRUC_MOON_GATE); |
355
|
|
|
|
356
|
|
|
return $jump_gate_level ? max(0, $moon_row['last_jump_time'] + abs(60 * 60 / $jump_gate_level) - SN_TIME_NOW) : 0; |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
function uni_coordinates_valid($coordinates, $prefix = '') { |
360
|
|
|
global $config; |
361
|
|
|
|
362
|
|
|
// array_walk($coordinates, 'intval'); |
363
|
|
|
$coordinates["{$prefix}galaxy"] = intval($coordinates["{$prefix}galaxy"]); |
364
|
|
|
$coordinates["{$prefix}system"] = intval($coordinates["{$prefix}system"]); |
365
|
|
|
$coordinates["{$prefix}planet"] = intval($coordinates["{$prefix}planet"]); |
366
|
|
|
|
367
|
|
|
return |
368
|
|
|
isset($coordinates["{$prefix}galaxy"]) && $coordinates["{$prefix}galaxy"] > 0 && $coordinates["{$prefix}galaxy"] <= $config->game_maxGalaxy && |
369
|
|
|
isset($coordinates["{$prefix}system"]) && $coordinates["{$prefix}system"] > 0 && $coordinates["{$prefix}system"] <= $config->game_maxSystem && |
370
|
|
|
isset($coordinates["{$prefix}planet"]) && $coordinates["{$prefix}planet"] > 0 && $coordinates["{$prefix}planet"] <= $config->game_maxPlanet; |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
function uni_planet_teleport_check($user, $planetrow, $new_coordinates = null) { |
374
|
|
|
global $lang, $config; |
375
|
|
|
|
376
|
|
|
try { |
377
|
|
|
if ($planetrow['planet_teleport_next'] && $planetrow['planet_teleport_next'] > SN_TIME_NOW) { |
378
|
|
|
throw new exception($lang['ov_teleport_err_cooldown'], ERR_ERROR); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
if (mrc_get_level($user, false, RES_DARK_MATTER) < $config->planet_teleport_cost) { |
|
|
|
|
382
|
|
|
throw new exception($lang['ov_teleport_err_no_dark_matter'], ERR_ERROR); |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
// TODO: Replace quick-check with using gathered flying fleet data |
386
|
|
|
// $incoming = doquery("SELECT COUNT(*) AS incoming FROM {{fleets}} WHERE |
387
|
|
|
// (fleet_start_galaxy = {$planetrow['galaxy']} and fleet_start_system = {$planetrow['system']} and fleet_start_planet = {$planetrow['planet']}) |
388
|
|
|
// or |
389
|
|
|
// (fleet_end_galaxy = {$planetrow['galaxy']} and fleet_end_system = {$planetrow['system']} and fleet_end_planet = {$planetrow['planet']})", true); |
390
|
|
|
// if(!empty($incoming['incoming'])) { |
391
|
|
|
// throw new exception($lang['ov_teleport_err_fleet'], ERR_ERROR); |
392
|
|
|
// } |
393
|
|
|
if (DbFleetStatic::fleet_count_incoming($planetrow['galaxy'], $planetrow['system'], $planetrow['planet'])) { |
394
|
|
|
throw new exception($lang['ov_teleport_err_fleet'], ERR_ERROR); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
//$incoming = doquery("SELECT COUNT(*) AS incoming FROM {{iraks}} WHERE fleet_end_galaxy = {$planetrow['galaxy']} and fleet_end_system = {$planetrow['system']} and fleet_end_planet = {$planetrow['planet']}", true); |
398
|
|
|
//if($incoming['incoming']) { |
399
|
|
|
// throw new exception($lang['ov_teleport_err_fleet'], ERR_ERROR); |
400
|
|
|
//} |
401
|
|
|
|
402
|
|
|
if (is_array($new_coordinates)) { |
403
|
|
|
$new_coordinates['planet_type'] = PT_PLANET; |
404
|
|
|
$incoming = DBStaticPlanet::db_planet_by_vector($new_coordinates, ''); |
405
|
|
|
if ($incoming['id']) { |
406
|
|
|
throw new exception($lang['ov_teleport_err_destination_busy'], ERR_ERROR); |
407
|
|
|
} |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
$response = array( |
411
|
|
|
'result' => ERR_NONE, |
412
|
|
|
'message' => '', |
413
|
|
|
); |
414
|
|
|
} catch (exception $e) { |
415
|
|
|
$response = array( |
416
|
|
|
'result' => $e->getCode(), |
417
|
|
|
'message' => $e->getMessage(), |
418
|
|
|
); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
return $response; |
422
|
|
|
} |
423
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: