Completed
Push — trunk ( e8681e...314ee9 )
by SuperNova.WS
13:57
created

overview.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * index.php - overview.php
4
 *
5
 * 2.4 - copyright (c) 2010 by Gorlum for http://supernova.ws
6
 *     [-] Removed News frame
7
 *     [-] Time & Usersonline moved to Top-Frame
8
 * 2.3 - copyright (c) 2010 by Gorlum for http://supernova.ws
9
 *     [*] Complying with PCG
10
 * 2.2 - copyright (c) 2010 by Gorlum for http://supernova.ws
11
 *     [+] Redo flying fleet list
12
 * 2.1 - copyright (c) 2010 by Gorlum for http://supernova.ws
13
 *     [+] Planets on planet list now have indication of planet fill
14
 *     [+] Planets on planet list now have indication when there is enemy fleet flying to planet
15
 * 2.0 - copyright (c) 2010 by Gorlum for http://supernova.ws
16
 *     [+] Now there is full planet list on right side of screen a-la oGame
17
 *     [+] Planet list now include icons for buildings/tech/fleet on progress
18
 * 1.5 - copyright (c) 2010 by Gorlum for http://supernova.ws
19
 *     [*] Subplanet timers now use sn_timer.js library
20
 * 1.4 - copyright (c) 2010 by Gorlum for http://supernova.ws
21
 *     [*] All mainplanet timers now use new sn_timer.js library
22
 * 1.3 - copyright (c) 2010 by Gorlum for http://supernova.ws
23
 *     [*] Adjusted layouts of player infos
24
 * 1.2 - copyright (c) 2010 by Gorlum for http://supernova.ws
25
 *     [*] Adjusted layouts of planet infos
26
 * 1.1 - Security checks by Gorlum for http://supernova.ws
27
 * @version 1
28
 * @copyright 2008 By Chlorel for XNova
29
 */
30
31
//define('SN_RENDER_NAVBAR_PLANET', false);
32
33
include('common.' . substr(strrchr(__FILE__, '.'), 1));
34
35
lng_include('overview');
36
37
$result = array();
38
39
switch ($mode = sys_get_param_str('mode')) {
40
  case 'manage':
41
    sn_sys_sector_buy('overview.php?mode=manage');
42
43
    $user_dark_matter = mrc_get_level($user, false, RES_DARK_MATTER);
44
    $result[] = sn_sys_planet_core_transmute($user, $planetrow);
45
46
    $template = gettemplate('planet_manage', true);
47
    $planet_id = sys_get_param_id('planet_id');
48
49
    if (sys_get_param_str('rename') && $new_name = sys_get_param_str('new_name')) {
50
      $planetrow['name'] = $new_name;
51
//      $new_name = db_escape($new_name);
52
      DBStaticPlanet::db_planet_set_by_id($planetrow['id'], "`name` = '{$new_name}'");
53
    } elseif (sys_get_param_str('action') == 'make_capital') {
54
      try {
55
        sn_db_transaction_start();
56
        $user = db_user_by_id($user['id'], true, '*');
57
        $planetrow = DBStaticPlanet::db_planet_by_id($planetrow['id'], true, '*');
58
//        $global_data = sys_o_get_updated($user, $planetrow['id'], SN_TIME_NOW);
59
//        $user = $global_data['user'];
60
//        $planetrow = $global_data['planet'];
61
62
        if ($planetrow['planet_type'] != PT_PLANET) {
63
          throw new exception(classSupernova::$lang['ov_capital_err_not_a_planet'], ERR_ERROR);
64
        }
65
66
        if ($planetrow['id'] == $user['id_planet']) {
67
          throw new exception(classSupernova::$lang['ov_capital_err_capital_already'], ERR_ERROR);
68
        }
69
70
        if ($user_dark_matter < classSupernova::$config->planet_capital_cost) {
71
          throw new exception(classSupernova::$lang['ov_capital_err_no_dark_matter'], ERR_ERROR);
72
        }
73
74
        rpg_points_change($user['id'], RPG_CAPITAL, -classSupernova::$config->planet_capital_cost,
75
          array('Planet %s ID %d at coordinates %s now become Empire Capital', $planetrow['name'], $planetrow['id'], uni_render_coordinates($planetrow))
76
        );
77
78
        db_user_set_by_id($user['id'], "id_planet = {$planetrow['id']}, galaxy = {$planetrow['galaxy']}, system = {$planetrow['system']}, planet = {$planetrow['planet']}");
79
80
        $user['id_planet'] = $planetrow['id'];
81
        $result[] = array(
82
          'STATUS'  => ERR_NONE,
83
          'MESSAGE' => classSupernova::$lang['ov_capital_err_none'],
84
        );
85
        sn_db_transaction_commit();
86
        sys_redirect('overview.php?mode=manage');
87
      } catch (exception $e) {
88
        sn_db_transaction_rollback();
89
        $result[] = array(
90
          'STATUS'  => $e->getCode(),
91
          'MESSAGE' => $e->getMessage(),
92
        );
93
      }
94
    } elseif (sys_get_param_str('action') == 'planet_teleport') {
95
      try {
96
        if (!uni_coordinates_valid($new_coordinates = array(
97
          'galaxy' => sys_get_param_int('new_galaxy'),
98
          'system' => sys_get_param_int('new_system'),
99
          'planet' => sys_get_param_int('new_planet')))
100
        ) {
101
          throw new exception(classSupernova::$lang['ov_teleport_err_wrong_coordinates'], ERR_ERROR);
102
        }
103
104
        sn_db_transaction_start();
105
        // При телепорте обновлять данные не надо - просто получить текущие данные и залочить их
106
        $user = db_user_by_id($user['id'], true, '*');
107
        $planetrow = DBStaticPlanet::db_planet_by_id($planetrow['id'], true, '*');
108
//        $global_data = sys_o_get_updated($user, $planetrow['id'], SN_TIME_NOW);
109
//        $user = $global_data['user'];
110
//        $planetrow = $global_data['planet'];
111
112
        $can_teleport = uni_planet_teleport_check($user, $planetrow, $new_coordinates);
113
        if ($can_teleport['result'] != ERR_NONE) {
114
          throw new exception($can_teleport['message'], $can_teleport['result']);
115
        }
116
117
        rpg_points_change($user['id'], RPG_TELEPORT, -classSupernova::$config->planet_teleport_cost,
118
          array(&classSupernova::$lang['ov_teleport_log_record'], $planetrow['name'], $planetrow['id'], uni_render_coordinates($planetrow), uni_render_coordinates($new_coordinates))
119
        );
120
        $planet_teleport_next = SN_TIME_NOW + classSupernova::$config->planet_teleport_timeout;
121
        DBStaticPlanet::db_planet_set_by_gspt($planetrow['galaxy'], $planetrow['system'], $planetrow['planet'], PT_ALL,
122
          "galaxy = {$new_coordinates['galaxy']}, system = {$new_coordinates['system']}, planet = {$new_coordinates['planet']}, planet_teleport_next = {$planet_teleport_next}");
123
124
        if ($planetrow['id'] == $user['id_planet']) {
125
          db_user_set_by_id($user['id'], "galaxy = {$new_coordinates['galaxy']}, system = {$new_coordinates['system']}, planet = {$new_coordinates['planet']}");
126
        }
127
128
        // $global_data = sys_o_get_updated($user, $planetrow['id'], SN_TIME_NOW);
129
        sn_db_transaction_commit();
130
        $user = db_user_by_id($user['id'], true, '*');
131
        $planetrow = DBStaticPlanet::db_planet_by_id($planetrow['id'], true, '*');
132
        $result[] = array(
133
          'STATUS'  => ERR_NONE,
134
          'MESSAGE' => classSupernova::$lang['ov_teleport_err_none'],
135
        );
136
        sys_redirect('overview.php?mode=manage');
137
      } catch (exception $e) {
138
        sn_db_transaction_rollback();
139
        $result[] = array(
140
          'STATUS'  => $e->getCode(),
141
          'MESSAGE' => $e->getMessage(),
142
        );
143
      }
144
    } elseif (sys_get_param_str('action') == 'planet_abandon') {
145
      // if(sec_password_check($user['id'], sys_get_param('abandon_confirm'))) {
146
      if (classSupernova::$auth->password_check(sys_get_param('abandon_confirm'))) {
147
        if ($user['id_planet'] != $user['current_planet'] && $user['current_planet'] == $planet_id) {
148
          $destroyed = SN_TIME_NOW + 60 * 60 * 24;
149
          DBStaticPlanet::db_planet_set_by_id($user['current_planet'], "`destruyed`='{$destroyed}', `id_owner`=0");
150
          DBStaticPlanet::db_planet_set_by_parent($user['current_planet'], "`destruyed`='{$destroyed}', `id_owner`=0");
151
          db_user_set_by_id($user['id'], '`current_planet` = `id_planet`');
152
          messageBox(classSupernova::$lang['ov_delete_ok'], classSupernova::$lang['colony_abandon'], 'overview.php?mode=manage');
153
        } else {
154
          messageBox(classSupernova::$lang['ov_delete_wrong_planet'], classSupernova::$lang['colony_abandon'], 'overview.php?mode=manage');
155
        }
156
      } else {
157
        messageBox(classSupernova::$lang['ov_delete_wrong_pass'], classSupernova::$lang['colony_abandon'], 'overview.php?mode=manage');
158
      }
159
    } elseif (($hire = sys_get_param_int('hire')) && in_array($hire, sn_get_groups('governors'))) {
160
      $planet = new \Planet\Planet($planetrow['id']);
161
      $planet->governorHire($hire);
162
163
      sys_redirect('overview.php?mode=manage');
164
      die();
165
    }
166
167
    lng_include('mrc_mercenary');
168
    int_planet_pretemplate($planetrow, $template);
169
    foreach (sn_get_groups('governors') as $governor_id) {
170
      if ($planetrow['planet_type'] == PT_MOON && $governor_id == MRC_TECHNOLOGIST) {
171
        continue;
172
      }
173
174
      $governor_level = $planetrow['PLANET_GOVERNOR_ID'] == $governor_id ? $planetrow['PLANET_GOVERNOR_LEVEL'] : 0;
175
      $build_data = eco_get_build_data($user, $planetrow, $governor_id, $governor_level);
0 ignored issues
show
$user of type false is incompatible with the type array expected by parameter $user of eco_get_build_data(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

175
      $build_data = eco_get_build_data(/** @scrutinizer ignore-type */ $user, $planetrow, $governor_id, $governor_level);
Loading history...
176
      $template->assign_block_vars('governors', array(
177
        'ID'         => $governor_id,
178
        'NAME'       => classSupernova::$lang['tech'][$governor_id],
179
        'COST'       => $build_data[BUILD_CREATE][RES_DARK_MATTER],
180
        'MAX'        => get_unit_param($governor_id, P_MAX_STACK),
181
        'LEVEL'      => $governor_level,
182
        'LEVEL_PLUS' => mrc_get_level($user, $planetrow, $governor_id) - $governor_level,
183
      ));
184
    }
185
186
    $user_dark_matter = mrc_get_level($user, false, RES_DARK_MATTER);
187
    $planet_density_index = $planetrow['density_index'];
188
    $density_price_chart = planet_density_price_chart($planetrow);
189
    tpl_planet_density_info($template, $density_price_chart, $user_dark_matter);
190
191
    $sector_cost = eco_get_build_data($user, $planetrow, UNIT_SECTOR, mrc_get_level($user, $planetrow, UNIT_SECTOR), true);
192
    $sector_cost = $sector_cost[BUILD_CREATE][RES_DARK_MATTER];
193
    $planet_fill = floor($planetrow['field_current'] / eco_planet_fields_max($planetrow) * 100);
194
    $planet_fill = $planet_fill > 100 ? 100 : $planet_fill;
195
    $can_teleport = uni_planet_teleport_check($user, $planetrow);
196
    $template->assign_vars(array(
197
      'DARK_MATTER' => $user_dark_matter,
198
199
      'PLANET_FILL'          => floor($planetrow['field_current'] / eco_planet_fields_max($planetrow) * 100),
200
      'PLANET_FILL_BAR'      => $planet_fill,
201
      'SECTOR_CAN_BUY'       => $sector_cost <= $user_dark_matter,
202
      'SECTOR_COST'          => $sector_cost,
203
      'SECTOR_COST_TEXT'     => HelperString::numberFloorAndFormat($sector_cost),
204
      'planet_field_current' => $planetrow['field_current'],
205
      'planet_field_max'     => eco_planet_fields_max($planetrow),
206
207
      'CAN_TELEPORT'         => $can_teleport['result'] == ERR_NONE,
208
      'CAN_NOT_TELEPORT_MSG' => $can_teleport['message'],
209
      'TELEPORT_COST_TEXT'   => prettyNumberStyledCompare(classSupernova::$config->planet_teleport_cost, $user_dark_matter),
210
211
      'CAN_CAPITAL'       => $user_dark_matter >= classSupernova::$config->planet_capital_cost,
212
      'CAPITAL_COST_TEXT' => prettyNumberStyledCompare(classSupernova::$config->planet_capital_cost, $user_dark_matter),
213
214
      'PLANET_DENSITY_INDEX' => $planet_density_index,
215
      'PLANET_CORE_TEXT'     => classSupernova::$lang['uni_planet_density_types'][$planet_density_index],
216
217
      'IS_CAPITAL' => $planetrow['id'] == $user['id_planet'],
218
219
      'PAGE_HINT' => classSupernova::$lang['ov_manage_page_hint'],
220
    ));
221
222
    foreach ($result as &$a_result) {
223
      $template->assign_block_vars('result', $a_result);
224
    }
225
226
    display($template, classSupernova::$lang['rename_and_abandon_planet']);
227
  break;
228
229
  default:
230
    sn_sys_sector_buy();
231
232
    if (sys_get_param_str('rename') && $new_name = sys_get_param_str('new_name')) {
233
      $planetrow['name'] = $new_name;
234
      $new_name_safe = db_escape($new_name);
235
      DBStaticPlanet::db_planet_set_by_id($planetrow['id'], "`name` = '{$new_name_safe}'");
236
    }
237
238
    $result[] = sn_sys_planet_core_transmute($user, $planetrow);
239
240
    $template = gettemplate('planet_overview', true);
241
242
    $user_dark_matter = mrc_get_level($user, false, RES_DARK_MATTER);
243
    $planet_density_index = $planetrow['density_index'];
244
    $density_price_chart = planet_density_price_chart($planetrow);
245
    tpl_planet_density_info($template, $density_price_chart, $user_dark_matter);
246
247
    rpg_level_up($user, RPG_STRUCTURE);
248
    rpg_level_up($user, RPG_RAID);
249
    rpg_level_up($user, RPG_TECH);
250
    rpg_level_up($user, RPG_EXPLORE);
251
252
    $fleet_id = 1;
253
254
    $fleets = flt_parse_fleets_to_events(fleet_and_missiles_list_incoming($user['id']));
255
256
    $planet_count = 0;
257
    $planets_query = DBStaticPlanet::db_planet_list_sorted($user, false, '*');
258
    foreach ($planets_query as $an_id => $planetRecord) {
259
      sn_db_transaction_start();
260
      $updatedData = sys_o_get_updated($user, $planetRecord['id'], SN_TIME_NOW, false, true);
261
      sn_db_transaction_commit();
262
263
      $templatizedPlanet = tpl_parse_planet($updatedData['planet'], $fleets_to_planet);
264
265
      if ($planetRecord['planet_type'] == PT_MOON) {
266
        continue;
267
      }
268
      $moon = DBStaticPlanet::db_planet_by_parent($planetRecord['id']);
269
      if ($moon) {
270
        $moon_fill = min(100, floor($moon['field_current'] / eco_planet_fields_max($moon) * 100));
271
      } else {
272
        $moon_fill = 0;
273
      }
274
275
      $moon_fleets = flt_get_fleets_to_planet($moon);
276
      $template->assign_block_vars('planet', array_merge($templatizedPlanet, array(
277
        'MOON_ID'    => $moon['id'],
278
        'MOON_NAME'  => $moon['name'],
279
        'MOON_IMG'   => $moon['image'],
280
        'MOON_FILL'  => min(100, $moon_fill),
281
        'MOON_ENEMY' => $moon_fleets['enemy']['count'],
282
283
        'MOON_PLANET' => $moon['parent_planet'],
284
      )));
285
286
      $planet_count++;
287
    }
288
289
    tpl_assign_fleet($template, $fleets_to_planet);
290
    tpl_assign_fleet($template, $fleets);
291
292
    $lune = $planetrow['planet_type'] == PT_PLANET ? DBStaticPlanet::db_planet_by_parent($planetrow['id']) : DBStaticPlanet::db_planet_by_id($planetrow['parent_planet']);
293
    if ($lune) {
294
      $template->assign_vars(array(
295
        'MOON_ID'   => $lune['id'],
296
        'MOON_IMG'  => $lune['image'],
297
        'MOON_NAME' => $lune['name'],
298
      ));
299
    }
300
301
    $planet_fill = floor($planetrow['field_current'] / eco_planet_fields_max($planetrow) * 100);
302
    $planet_fill = $planet_fill > 100 ? 100 : $planet_fill;
303
304
    $planet_recyclers_orbiting = 0;
305
    foreach (sn_get_groups('flt_recyclers') as $recycler_id) {
306
      $planet_recyclers_orbiting += mrc_get_level($user, $planetrow, $recycler_id);
307
    }
308
309
    int_planet_pretemplate($planetrow, $template);
310
311
    $sn_group_ques = sn_get_groups('ques');
312
    if (!defined('GAME_STRUCTURES_DISABLED') || !GAME_STRUCTURES_DISABLED) {
313
      foreach (array(QUE_STRUCTURES => $sn_group_ques[QUE_STRUCTURES]) as $que_id => $que_type_data) {
314
        $this_que = $que['ques'][$que_id][$user['id']][$planetrow['id']];
315
        $template->assign_block_vars('ques', array(
316
          'ID'     => $que_id,
317
          'NAME'   => classSupernova::$lang['sys_ques'][$que_id],
318
          'LENGTH' => empty($this_que) ? 0 : count($this_que),
319
        ));
320
321
        if (!empty($this_que)) {
322
          foreach ($this_que as $que_item) {
323
            $template->assign_block_vars('que', que_tpl_parse_element($que_item));
324
          }
325
        }
326
      }
327
    }
328
329
    $que_hangar_length = tpl_assign_hangar($template, $planetrow, SUBQUE_FLEET);
330
    $template->assign_block_vars('ques', array(
331
      'ID'     => QUE_HANGAR,
332
      'NAME'   => classSupernova::$lang['sys_ques'][QUE_HANGAR],
333
      'LENGTH' => $que_hangar_length,
334
    ));
335
336
    if (!defined('GAME_DEFENSE_DISABLED') || !GAME_DEFENSE_DISABLED) {
337
      $que_hangar_length = tpl_assign_hangar($template, $planetrow, SUBQUE_DEFENSE);
338
      $template->assign_block_vars('ques', array(
339
        'ID'     => SUBQUE_DEFENSE,
340
        'NAME'   => classSupernova::$lang['sys_ques'][SUBQUE_DEFENSE],
341
        'LENGTH' => $que_hangar_length,
342
      ));
343
    }
344
345
    $overview_planet_rows = $user['opt_int_overview_planet_rows'];
346
    $overview_planet_columns = $user['opt_int_overview_planet_columns'];
347
348
    if ($overview_planet_rows <= 0 && $overview_planet_columns <= 0) {
349
      $overview_planet_rows = $user_option_list[OPT_INTERFACE]['opt_int_overview_planet_rows'];
350
      $overview_planet_columns = $user_option_list[OPT_INTERFACE]['opt_int_overview_planet_columns'];
351
    }
352
353
    if ($overview_planet_rows > 0 && $overview_planet_columns <= 0) {
354
      $overview_planet_columns = ceil($planet_count / $overview_planet_rows);
355
    }
356
357
    $sector_cost = eco_get_build_data($user, $planetrow, UNIT_SECTOR, mrc_get_level($user, $planetrow, UNIT_SECTOR), true);
358
    $sector_cost = $sector_cost[BUILD_CREATE][RES_DARK_MATTER];
359
    $governor_level = $planetrow['PLANET_GOVERNOR_ID'] ? mrc_get_level($user, $planetrow, $planetrow['PLANET_GOVERNOR_ID'], false, true) : 0;
360
    $template->assign_vars(array(
361
      'USER_ID'        => $user['id'],
362
      'user_username'  => $user['username'],
363
      'USER_AUTHLEVEL' => $user['authlevel'],
364
365
      'NEW_MESSAGES'    => $user['new_message'],
366
      'NEW_LEVEL_MINER' => $level_miner,
367
      'NEW_LEVEL_RAID'  => $level_raid,
368
369
      'planet_diameter'      => HelperString::numberFloorAndFormat($planetrow['diameter']),
370
      'planet_field_current' => $planetrow['field_current'],
371
      'planet_field_max'     => eco_planet_fields_max($planetrow),
372
      'PLANET_FILL'          => floor($planetrow['field_current'] / eco_planet_fields_max($planetrow) * 100),
373
      'PLANET_FILL_BAR'      => $planet_fill,
374
      'metal_debris'         => HelperString::numberFloorAndFormat($planetrow['debris_metal']),
375
      'crystal_debris'       => HelperString::numberFloorAndFormat($planetrow['debris_crystal']),
376
      'PLANET_RECYCLERS'     => $planet_recyclers_orbiting,
377
      'planet_image'         => $planetrow['image'],
378
      'planet_temp_min'      => $planetrow['temp_min'],
379
      'planet_temp_avg'      => round(($planetrow['temp_min'] + $planetrow['temp_max']) / 2),
380
      'planet_temp_max'      => $planetrow['temp_max'],
381
      'planet_density'       => $planetrow['density'],
382
      'planet_density_index' => $planetrow['density_index'],
383
      'planet_density_text'  => classSupernova::$lang['uni_planet_density_types'][$planetrow['density_index']],
384
385
      'GATE_LEVEL'          => mrc_get_level($user, $planetrow, STRUC_MOON_GATE),
386
      'GATE_JUMP_REST_TIME' => uni_get_time_to_jump($planetrow),
387
388
      'ADMIN_EMAIL' => classSupernova::$config->game_adminEmail,
389
390
      'PLANET_GOVERNOR_ID'         => $planetrow['PLANET_GOVERNOR_ID'],
391
      'PLANET_GOVERNOR_LEVEL'      => $governor_level,
392
      'PLANET_GOVERNOR_LEVEL_PLUS' => mrc_get_level($user, $planetrow, $planetrow['PLANET_GOVERNOR_ID']) - $governor_level,
393
      'PLANET_GOVERNOR_NAME'       => classSupernova::$lang['tech'][$planetrow['PLANET_GOVERNOR_ID']],
394
395
      'LIST_ROW_COUNT'    => $overview_planet_rows,
396
      'LIST_COLUMN_COUNT' => $overview_planet_columns,
397
398
      'DARK_MATTER' => $user_dark_matter,
399
400
      'PLANET_DENSITY_INDEX' => $planet_density_index,
401
      'PLANET_CORE_TEXT'     => classSupernova::$lang['uni_planet_density_types'][$planet_density_index],
402
403
      'SECTOR_CAN_BUY'   => $sector_cost <= mrc_get_level($user, null, RES_DARK_MATTER),
404
      'SECTOR_COST'      => $sector_cost,
405
      'SECTOR_COST_TEXT' => HelperString::numberFloorAndFormat($sector_cost),
406
407
      'PAGE_HEADER' => classSupernova::$lang['ov_overview']. " - " . classSupernova::$lang['sys_planet_type'][$planetrow['planet_type']] . " {$planetrow['name']} [{$planetrow['galaxy']}:{$planetrow['system']}:{$planetrow['planet']}]",
408
    ));
409
    tpl_set_resource_info($template, $planetrow, $fleets_to_planet);
410
411
    foreach ($result as &$a_result) {
412
      $template->assign_block_vars('result', $a_result);
413
    }
414
415
    display($template);
416
  break;
417
}
418