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