Completed
Push — work-fleets ( 22b5bc...08ace7 )
by SuperNova.WS
06:13
created

galaxy.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * galaxy.php
5
 *
6
 * Galaxy view
7
 */
8
9
use Vector\Vector;
10
11
include('common.' . substr(strrchr(__FILE__, '.'), 1));
12
13
lng_include('universe');
14
lng_include('stat');
15
16
$mode = sys_get_param_str('mode');
17
$uni_galaxy = sys_get_param_int('galaxy', $planetrow['galaxy']);
18
$uni_system = sys_get_param_int('system', $planetrow['system']);
19
$planet = sys_get_param_int('planet', $planetrow['planet']);
20
21
if($mode == 'name') {
22
  require_once('includes/includes/uni_rename.php');
23
}
24
25
require_once('includes/includes/flt_functions.php');
26
27
$CurrentPlanetID = sys_get_param_id('current');
28
$POST_galaxyLeft = sys_get_param_str('galaxyLeft');
29
$POST_galaxyRight = sys_get_param_str('galaxyRight');
30
$POST_systemLeft = sys_get_param_str('systemLeft');
31
$POST_systemRight = sys_get_param_str('systemRight');
32
33
$fleetmax = GetMaxFleets($user);
34
$CurrentPlID = $planetrow['id'];
35
$CurrentMIP = mrc_get_level($user, $planetrow, UNIT_DEF_MISSILE_INTERPLANET, false, true);
36
$HavePhalanx = mrc_get_level($user, $planetrow, STRUC_MOON_PHALANX);
37
$CurrentSystem = $planetrow['system'];
38
$CurrentGalaxy = $planetrow['galaxy'];
39
40
$flying_fleet_count = FleetList::fleet_count_flying($user['id']);
41
42
if($mode == 1) {
43
} elseif($mode == 2 || $mode == 3) {
44
  $planet = $planetrow['planet'];
45
} else {
46
  $uni_galaxy = $planetrow['galaxy'];
47
  $uni_system = $planetrow['system'];
48
  $planet = $planetrow['planet'];
49
}
50
51
$uni_galaxy = $uni_galaxy < 1 ? 1 : ($uni_galaxy > Vector::$knownGalaxies? Vector::$knownGalaxies: $uni_galaxy);
52
$uni_system = $uni_system < 1 ? 1 : ($uni_system > Vector::$knownSystems ? Vector::$knownSystems : $uni_system);
53
$planet = $planet < 1 ? 1 : ($planet > Vector::$knownPlanets + 1 ? Vector::$knownPlanets + 1 : $planet);
54
55
$planetcount = 0;
56
$lunacount = 0;
57
$CurrentRC = $planetrow['recycler'];
58
$cached = array('users' => array(), 'allies' => array());
59
60
61
$template = gettemplate('universe', true);
62
63
$CurrentPoints = $user['total_points'];
64
65
$MissileRange = flt_get_missile_range($user);
66
$PhalanxRange = GetPhalanxRange($HavePhalanx);
67
68
$planet_precache_query = DBStaticPlanet::db_planet_list_in_system($uni_galaxy, $uni_system);
69
if(!empty($planet_precache_query)) {
70
  foreach($planet_precache_query as $planet_row) {
71
    $planet_list[$planet_row['planet']][$planet_row['planet_type']] = $planet_row;
72
  }
73
}
74
75
76
//$system_fleet_list = FleetList::fleet_list_by_planet_coords($uni_galaxy, $uni_system);
77
//foreach($system_fleet_list as $fleet_row) {
78
//  $fleet_planet = $fleet_row['fleet_mess'] == 0 ? $fleet_row['fleet_end_planet'] : $fleet_row['fleet_start_planet'];
79
//  $fleet_type = $fleet_row['fleet_mess'] == 0 ? $fleet_row['fleet_end_type'] : $fleet_row['fleet_start_type'];
80
//  $fleet_list[$fleet_planet][$fleet_type][] = $fleet_row;
81
//}
82
83
$system_fleet_list = FleetList::dbGetFleetListByCoordinates($uni_galaxy, $uni_system);
84
/**
85
 * @var Fleet[][][] $fleet_list
86
 */
87
$fleet_list = array();
88
foreach($system_fleet_list->_container as $objFleetSystem) {
89
  if(!$objFleetSystem->isReturning()) {
90
    $fleet_planet = $objFleetSystem->fleet_end_planet;
91
    $fleet_type = $objFleetSystem->fleet_end_type;
92
  } else {
93
    $fleet_planet = $objFleetSystem->fleet_start_planet;
94
    $fleet_type = $objFleetSystem->fleet_start_type;
95
  }
96
  $fleet_list[$fleet_planet][$fleet_type][] = $objFleetSystem;
97
}
98
99
$time_now_parsed = getdate(SN_TIME_NOW);
100
101
$recycler_info = array();
102
$planet_recyclers_orbiting = 0;
103
$recyclers_fleet = array();
104
foreach(Fleet::$snGroupRecyclers as $recycler_id) {
105
  $recycler_info[$recycler_id] = get_ship_data($recycler_id, $user);
106
  $recyclers_fleet[$recycler_id] = mrc_get_level($user, $planetrow, $recycler_id);
107
  $planet_recyclers_orbiting += $recyclers_fleet[$recycler_id];
108
}
109
110
$user_skip_list = sys_stat_get_user_skip_list();
111
$fleet_id = 1;
112
$fleets = array();
113
$config_game_max_planet = Vector::$knownPlanets + 1;
114
for($Planet = 1; $Planet < $config_game_max_planet; $Planet++) {
115
  unset($uni_galaxyRowPlanet);
116
  unset($uni_galaxyRowMoon);
117
  unset($uni_galaxyRowUser);
118
  unset($uni_galaxyRowAlly);
119
  unset($allyquery);
120
121
  $uni_galaxyRowPlanet = $planet_list[$Planet][PT_PLANET];
122
123
  $planet_fleet_id = 0;
124
  if($uni_galaxyRowPlanet['destruyed']) {
125
    CheckAbandonPlanetState($uni_galaxyRowPlanet);
126
  } elseif($uni_galaxyRowPlanet['id']) {
127
    if($cached['users'][$uni_galaxyRowPlanet['id_owner']]) {
128
      $uni_galaxyRowUser = $cached['users'][$uni_galaxyRowPlanet['id_owner']];
129
    } else {
130
      $uni_galaxyRowUser = DBStaticUser::db_user_by_id($uni_galaxyRowPlanet['id_owner']);
131
      $cached['users'][$uni_galaxyRowUser['id']] = $uni_galaxyRowUser;
132
    }
133
134
    if(!$uni_galaxyRowUser['id']) {
135
      classSupernova::$debug->warning("Planet '{$uni_galaxyRowPlanet['name']}' [{$uni_galaxy}:{$uni_system}:{$Planet}] has no owner!", 'Userless planet', 503);
136
      $uni_galaxyRowPlanet['destruyed'] = SN_TIME_NOW + 60 * 60 * 24;
137
      $uni_galaxyRowPlanet['id_owner'] = 0;
138
      DBStaticPlanet::db_planet_update_set_by_id_DEPRECATED($uni_galaxyRowPlanet['id'], "id_owner = 0, destruyed = {$uni_galaxyRowPlanet['destruyed']}");
0 ignored issues
show
Deprecated Code introduced by
The method DBStaticPlanet::db_plane..._set_by_id_DEPRECATED() has been deprecated.

This method has been deprecated.

Loading history...
139
    }
140
141
    if($uni_galaxyRowUser['id']) {
142
      $planetcount++;
143
      if($uni_galaxyRowUser['ally_id']) {
144
        if($cached['allies'][$uni_galaxyRowUser['ally_id']]) {
145
          $allyquery = $cached['allies'][$uni_galaxyRowUser['ally_id']];
146
        } else {
147
          $allyquery = DBStaticAlly::db_ally_get_by_id($uni_galaxyRowUser['ally_id']);
148
          $cached['allies'][$uni_galaxyRowUser['ally_id']] = $allyquery;
149
        }
150
      }
151
152
      $fleets_to_planet = flt_get_fleets_to_planet_by_array_of_Fleet($fleet_list[$Planet][PT_PLANET]);
153
      if(!empty($fleets_to_planet['own']['count'])) {
154
        $planet_fleet_id = $fleet_id;
155
        $fleets[] = tpl_parse_fleet_sn($fleets_to_planet['own']['total'], $fleet_id);
156
        $fleet_id++;
157
      }
158
159
      $uni_galaxyRowMoon = $planet_list[$Planet][PT_MOON];
160
      if($uni_galaxyRowMoon['destruyed']) {
161
        CheckAbandonPlanetState($uni_galaxyRowMoon);
162
      } else {
163
        $moon_fleet_id = 0;
164
        $fleets_to_planet = flt_get_fleets_to_planet_by_array_of_Fleet($fleet_list[$Planet][PT_MOON]);
165
        if(!empty($fleets_to_planet['own']['count'])) {
166
          $moon_fleet_id = $fleet_id;
167
          $fleets[] = tpl_parse_fleet_sn($fleets_to_planet['own']['total'], $fleet_id);
168
          $fleet_id++;
169
        }
170
      }
171
    }
172
  }
173
174
  $recyclers_incoming_capacity = 0;
175
  $uni_galaxyRowPlanet['debris'] = $uni_galaxyRowPlanet['debris_metal'] + $uni_galaxyRowPlanet['debris_crystal'];
176
  if($uni_galaxyRowPlanet['debris']) {
177
    if(!empty($fleet_list[$Planet][PT_DEBRIS])) {
178
      foreach($fleet_list[$Planet][PT_DEBRIS] as $objFleetToDebris) {
179
        if($objFleetToDebris->playerOwnerId == $user['id']) {
180
          $recyclers_incoming_capacity += $objFleetToDebris->shipsGetCapacityRecyclers($recycler_info);
181
        }
182
      }
183
    }
184
185
    $uni_galaxyRowPlanet['debris_reserved'] = $recyclers_incoming_capacity;
186
    $uni_galaxyRowPlanet['debris_reserved_percent'] = min(100, floor($uni_galaxyRowPlanet['debris_reserved'] / $uni_galaxyRowPlanet['debris'] * 100));
187
188
    $uni_galaxyRowPlanet['debris_to_gather'] = max(0, $uni_galaxyRowPlanet['debris'] - $recyclers_incoming_capacity);
189
    $uni_galaxyRowPlanet['debris_to_gather_percent'] = 100 - $uni_galaxyRowPlanet['debris_reserved_percent'];
190
191
    $recyclers_fleet_data = flt_calculate_fleet_to_transport($recyclers_fleet, $uni_galaxyRowPlanet['debris_to_gather'], $planetrow, $uni_galaxyRowPlanet);
192
193
    $uni_galaxyRowPlanet['debris_will_gather'] = max(0, min($recyclers_fleet_data['capacity'], $uni_galaxyRowPlanet['debris_to_gather']));
194
    $uni_galaxyRowPlanet['debris_will_gather_percent'] = $uni_galaxyRowPlanet['debris_to_gather'] ? floor($uni_galaxyRowPlanet['debris_will_gather'] / $uni_galaxyRowPlanet['debris_to_gather'] * $uni_galaxyRowPlanet['debris_to_gather_percent']) : 0;
195
196
    $uni_galaxyRowPlanet['debris_gather_total'] = max(0, $uni_galaxyRowPlanet['debris_will_gather'] + $uni_galaxyRowPlanet['debris_reserved']);
197
    $uni_galaxyRowPlanet['debris_gather_total_percent'] = min(100, floor($uni_galaxyRowPlanet['debris_gather_total'] / $uni_galaxyRowPlanet['debris'] * 100));
198
  }
199
200
  $RowUserPoints = $uni_galaxyRowUser['total_points'];
201
  $birthday_array = $uni_galaxyRowUser['user_birthday'] ? date_parse($uni_galaxyRowUser['user_birthday']) : array();
202
  $user_activity = floor((SN_TIME_NOW - $uni_galaxyRowUser['onlinetime']) / (60 * 60 * 24));
203
  $template->assign_block_vars('galaxyrow', array(
204
    'PLANET_ID'        => $uni_galaxyRowPlanet['id'],
205
    'PLANET_NUM'       => $Planet,
206
    'PLANET_NAME'      => $uni_galaxyRowPlanet['name'],
207
    'PLANET_NAME_JS'   => js_safe_string($uni_galaxyRowPlanet['name']),
208
    'PLANET_DESTROYED' => $uni_galaxyRowPlanet["destruyed"],
209
    'PLANET_TYPE'      => $uni_galaxyRowPlanet["planet_type"],
210
    'PLANET_ACTIVITY'  => floor((SN_TIME_NOW - $uni_galaxyRowPlanet['last_update']) / 60),
211
    'PLANET_IMAGE'     => $uni_galaxyRowPlanet['image'],
212
    'PLANET_FLEET_ID'  => $planet_fleet_id,
213
    'PLANET_DIAMETER'  => number_format($uni_galaxyRowPlanet['diameter'], 0, '', '.'),
214
215
    'MOON_NAME_JS'  => js_safe_string($uni_galaxyRowMoon['name']),
216
    'MOON_IMAGE'    => $uni_galaxyRowMoon['image'],
217
    'MOON_DIAMETER' => number_format($uni_galaxyRowMoon['diameter'], 0, '', '.'),
218
    'MOON_TEMP'     => number_format($uni_galaxyRowMoon['temp_min'], 0, '', '.'),
219
    'MOON_FLEET_ID' => $moon_fleet_id,
220
221
    'DEBRIS'              => $uni_galaxyRowPlanet['debris'],
222
    'DEBRIS_METAL'        => $uni_galaxyRowPlanet['debris_metal'],
223
    'DEBRIS_CRYSTAL'      => $uni_galaxyRowPlanet['debris_crystal'],
224
    'DEBRIS_REST_PERCENT' => $uni_galaxyRowPlanet["debris_rest_percent"],
225
226
    'DEBRIS_RESERVED'             => $uni_galaxyRowPlanet['debris_reserved'],
227
    'DEBRIS_RESERVED_PERCENT'     => $uni_galaxyRowPlanet['debris_reserved_percent'],
228
    'DEBRIS_WILL_GATHER'          => $uni_galaxyRowPlanet['debris_will_gather'],
229
    'DEBRIS_WILL_GATHER_PERCENT'  => $uni_galaxyRowPlanet['debris_will_gather_percent'],
230
    'DEBRIS_GATHER_TOTAL'         => $uni_galaxyRowPlanet['debris_gather_total'],
231
    'DEBRIS_GATHER_TOTAL_PERCENT' => $uni_galaxyRowPlanet['debris_gather_total_percent'],
232
233
    'USER_ID'         => $uni_galaxyRowUser['id'],
234
    'USER_NAME'       => player_nick_render_to_html($uni_galaxyRowUser),
235
    'USER_NAME_JS'    => js_safe_string(player_nick_render_to_html($uni_galaxyRowUser)),
236
    'USER_RANK'       => in_array($uni_galaxyRowUser['id'], $user_skip_list) ? '-' : $uni_galaxyRowUser['total_rank'],
237
    'USER_BANNED'     => $uni_galaxyRowUser['banaday'],
238
    'USER_VACATION'   => $uni_galaxyRowUser['vacation'],
239
    'USER_ACTIVITY'   => $user_activity,
240
    'USER_ATTACKABLE' => $user_activity >= 7,
241
    'USER_INACTIVE'   => $user_activity >= 28,
242
    'USER_PROTECTED'  => $RowUserPoints <= classSupernova::$config->game_noob_points,
243
    'USER_NOOB'       => $RowUserPoints * classSupernova::$config->game_noob_factor < $CurrentPoints && classSupernova::$config->game_noob_factor,
244
    'USER_STRONG'     => $CurrentPoints * classSupernova::$config->game_noob_factor < $RowUserPoints && classSupernova::$config->game_noob_factor,
245
    'USER_AUTH'       => $uni_galaxyRowUser['authlevel'],
246
    'USER_ADMIN'      => classLocale::$lang['user_level_shortcut'][$uni_galaxyRowUser['authlevel']],
247
    'USER_BIRTHDAY'   => $birthday_array['month'] == $time_now_parsed['mon'] && $birthday_array['day'] == $time_now_parsed['mday'] ? date(FMT_DATE, SN_TIME_NOW) : 0,
248
249
    'ALLY_ID'  => $uni_galaxyRowUser['ally_id'],
250
    'ALLY_TAG' => $uni_galaxyRowUser['ally_tag'],
251
  ));
252
}
253
254
tpl_assign_fleet($template, $fleets);
255
256
foreach(sn_get_groups('defense_active') as $unit_id) {
257
  $template->assign_block_vars('defense_active', array(
258
    'ID'   => $unit_id,
259
    'NAME' => classLocale::$lang['tech'][$unit_id],
260
  ));
261
}
262
263
foreach($cached['users'] as $PlanetUser) {
264
  if(!$PlanetUser) {
265
    continue;
266
  }
267
268
  $user_ally = $cached['allies'][$PlanetUser['ally_id']];
269
  if(isset($user_ally)) {
270
    if($PlanetUser['id'] == $user_ally['ally_owner']) {
271
      $user_rank_title = $user_ally['ally_owner_range'];
272
    } else {
273
      $ally_ranks = explode(';', $user_ally['ranklist']);
274
      list($user_rank_title) = explode(',', $ally_ranks[$PlanetUser['ally_rank_id']]);
275
    }
276
  } else {
277
    $user_rank_title = '';
278
  }
279
280
  $birthday_array = $PlanetUser['user_birthday'] ? date_parse($PlanetUser['user_birthday']) : array();
281
  $template->assign_block_vars('users', array(
282
    'ID'         => $PlanetUser['id'],
283
    'NAME'       => player_nick_render_to_html($PlanetUser, true),
284
    'NAME_JS'    => js_safe_string(player_nick_render_to_html($PlanetUser, true)),
285
    'RANK'       => in_array($PlanetUser['id'], $user_skip_list) ? '-' : $PlanetUser['total_rank'],
286
    'AVATAR'     => $PlanetUser['avatar'],
287
    'ALLY_ID'    => $PlanetUser['ally_id'],
288
    'ALLY_TAG'   => js_safe_string($user_ally['ally_tag']),
289
    'ALLY_TITLE' => str_replace(' ', '&nbsp', js_safe_string($user_rank_title)),
290
  ));
291
}
292
293
foreach($cached['allies'] as $PlanetAlly) {
294
  if($PlanetAlly) {
295
    $template->assign_block_vars('alliances', array(
296
      'ID'      => $PlanetAlly['id'],
297
      'NAME_JS' => js_safe_string($PlanetAlly['ally_name']),
298
      'MEMBERS' => $PlanetAlly['ally_members'],
299
      'URL'     => $PlanetAlly['ally_web'],
300
      'RANK'    => $PlanetAlly['total_rank'],
301
      'AVATAR'  => $PlanetAlly['ally_image'],
302
    ));
303
  }
304
}
305
306
$is_missile = classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_MISSILE] && ($CurrentMIP > 0) && ($uni_galaxy == $CurrentGalaxy) && ($uni_system >= $CurrentSystem - $MissileRange) && ($uni_system <= $CurrentSystem + $MissileRange);
307
$colspan = classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_SPYING] + classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_PM] + classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_BUDDY] + $is_missile;
308
309
$template->assign_vars(array(
310
    'rows'                  => $Result,
311
    'userCount'             => classSupernova::$config->users_amount,
312
//    'ALLY_COUNT'            => $ally_count['ally_count'],
313
    'ALLY_COUNT'            => DBStaticAlly::db_ally_count(),
314
    'PLANET_EXPEDITION'     => Vector::$knownPlanets + 1,
315
    'curPlanetID'           => $planetrow['id'],
316
    'curPlanetG'            => $planetrow['galaxy'],
317
    'curPlanetS'            => $planetrow['system'],
318
    'curPlanetP'            => $planetrow['planet'],
319
    'curPlanetPT'           => $planetrow['planet_type'],
320
    'deathStars'            => mrc_get_level($user, $planetrow, SHIP_HUGE_DEATH_STAR, false, true),
321
    'galaxy'                => $uni_galaxy,
322
    'system'                => $uni_system,
323
    'planet'                => $planet,
324
    'MIPs'                  => round($CurrentMIP),
325
    'MODE'                  => $mode,
326
    'planets'               => $planetcount,
327
    'SPs'                   => pretty_number(mrc_get_level($user, $planetrow, SHIP_SPY, false, true)),
328
    'SHOW_ADMIN'            => SHOW_ADMIN,
329
    'fleet_count'           => $flying_fleet_count,
330
    'fleet_max'             => $fleetmax,
331
    'ALLY_ID'               => $user['ally_id'],
332
    'USER_ID'               => $user['id'],
333
    'ACT_SPIO'              => classSupernova::$user_options[PLAYER_OPTION_FLEET_SPY_DEFAULT],
334
    'ACT_SPY'               => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_SPYING],
335
    'ACT_WRITE'             => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_PM],
336
    'ACT_STATISTICS'        => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_STATS],
337
    'ACT_INFO'              => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_PROFILE],
338
    'ACT_FRIEND'            => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_ICON_BUDDY],
339
    'opt_uni_tooltip_time'  => classSupernova::$user_options[PLAYER_OPTION_TOOLTIP_DELAY],
340
    'opt_uni_avatar_user'   => $user['opt_uni_avatar_user'],
341
    'opt_uni_avatar_ally'   => $user['opt_uni_avatar_ally'],
342
    'ACT_MISSILE'           => $is_missile,
343
    'PLANET_PHALANX'        => $HavePhalanx && $uni_galaxy == $CurrentGalaxy && $uni_system >= $CurrentSystem - $PhalanxRange && $uni_system <= $CurrentSystem + $PhalanxRange,
344
    'PAGE_HINT'             => classLocale::$lang['gal_sys_hint'],
345
    'PLANET_RECYCLERS'      => $planet_recyclers_orbiting,
346
    'PLANET_RECYCLERS_TEXT' => pretty_number($planet_recyclers_orbiting),
347
//    'GALAXY_NAME'           => $galaxy_name['universe_name'],
348
//    'SYSTEM_NAME'           => $system_name['universe_name'],
349
    'GALAXY_NAME'           => db_universe_get_name($uni_galaxy),
350
    'SYSTEM_NAME'           => db_universe_get_name($uni_galaxy, $uni_system),
351
    'COL_SPAN'              => $colspan + 9,
352
    'COL_SPAN_PLUS'         => $colspan + 3,
353
354
    'COL_SPAN_NEW'          => $colspan + 4,
355
    'COL_SPAN_NEW_COLONIZE' => $colspan - 2,
356
357
    'PLAYER_OPTION_UNIVERSE_OLD'              => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_OLD],
358
    'PLAYER_OPTION_UNIVERSE_DISABLE_COLONIZE' => classSupernova::$user_options[PLAYER_OPTION_UNIVERSE_DISABLE_COLONIZE],
359
  )
360
);
361
362
display(parsetemplate($template), classLocale::$lang['sys_universe'], true, '', false);
363