supernova-ws /
SuperNova
| 1 | <?php |
||||
| 2 | |||||
| 3 | // Compare function to sort fleet in time order |
||||
| 4 | use Fleet\DbFleetStatic; |
||||
| 5 | use Planet\DBStaticPlanet; |
||||
| 6 | |||||
| 7 | function tpl_assign_fleet_compare($a, $b) { |
||||
| 8 | if ($a['fleet']['OV_THIS_PLANET'] == $b['fleet']['OV_THIS_PLANET']) { |
||||
| 9 | if ($a['fleet']['OV_LEFT'] == $b['fleet']['OV_LEFT']) { |
||||
| 10 | return 0; |
||||
| 11 | } |
||||
| 12 | |||||
| 13 | return ($a['fleet']['OV_LEFT'] < $b['fleet']['OV_LEFT']) ? -1 : 1; |
||||
| 14 | } else { |
||||
| 15 | return $a['fleet']['OV_THIS_PLANET'] ? -1 : 1; |
||||
| 16 | } |
||||
| 17 | } |
||||
| 18 | |||||
| 19 | /** |
||||
| 20 | * @param array $fleets |
||||
| 21 | * @param string $js_name |
||||
| 22 | * |
||||
| 23 | * @return array |
||||
| 24 | */ |
||||
| 25 | function tpl_assign_fleet_generate($fleets, $js_name = 'fleets') { |
||||
| 26 | $result = []; |
||||
| 27 | if (empty($fleets)) { |
||||
| 28 | return $result; |
||||
| 29 | } |
||||
| 30 | |||||
| 31 | usort($fleets, 'tpl_assign_fleet_compare'); |
||||
| 32 | |||||
| 33 | foreach ($fleets as $fleet_data) { |
||||
| 34 | $temp = $fleet_data['fleet']; |
||||
| 35 | |||||
| 36 | if ($fleet_data['ships']) { |
||||
| 37 | $temp['.']['ships'] = $fleet_data['ships']; |
||||
| 38 | } |
||||
| 39 | |||||
| 40 | $result['.'][$js_name][] = $temp; |
||||
| 41 | } |
||||
| 42 | |||||
| 43 | return $result; |
||||
| 44 | } |
||||
| 45 | |||||
| 46 | /** |
||||
| 47 | * For backward compatibility |
||||
| 48 | * |
||||
| 49 | * @param template $template |
||||
| 50 | * @param array $fleets |
||||
| 51 | * @param string $js_name |
||||
| 52 | * |
||||
| 53 | * @deprecated |
||||
| 54 | */ |
||||
| 55 | function tpl_assign_fleet(&$template, $fleets, $js_name = 'fleets') { |
||||
| 56 | if (!$fleets) { |
||||
|
0 ignored issues
–
show
|
|||||
| 57 | return; |
||||
| 58 | } |
||||
| 59 | |||||
| 60 | $template->assign_recursive(tpl_assign_fleet_generate($fleets, $js_name)); |
||||
| 61 | } |
||||
| 62 | |||||
| 63 | /** |
||||
| 64 | * function that parses internal fleet representation (as array(id => count)) |
||||
| 65 | * |
||||
| 66 | * @param $fleet |
||||
| 67 | * @param $fleet_id |
||||
| 68 | * |
||||
| 69 | * @return mixed |
||||
| 70 | */ |
||||
| 71 | function tpl_parse_fleet_sn($fleet, $fleet_id) { |
||||
| 72 | global $lang, $user; |
||||
| 73 | |||||
| 74 | $user_data = &$user; |
||||
| 75 | |||||
| 76 | $return['fleet'] = array( |
||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
| 77 | 'ID' => $fleet_id, |
||||
| 78 | |||||
| 79 | 'METAL' => $fleet[RES_METAL], |
||||
| 80 | 'CRYSTAL' => $fleet[RES_CRYSTAL], |
||||
| 81 | 'DEUTERIUM' => $fleet[RES_DEUTERIUM], |
||||
| 82 | ); |
||||
| 83 | |||||
| 84 | foreach ($fleet as $ship_id => $ship_amount) { |
||||
| 85 | if (in_array($ship_id, sn_get_groups('fleet'))) { |
||||
| 86 | $single_ship_data = get_ship_data($ship_id, $user_data); |
||||
| 87 | $return['ships'][$ship_id] = array( |
||||
| 88 | 'ID' => $ship_id, |
||||
| 89 | 'NAME' => $lang['tech'][$ship_id], |
||||
| 90 | 'AMOUNT' => $ship_amount, |
||||
| 91 | 'CONSUMPTION' => $single_ship_data['consumption'], |
||||
| 92 | 'SPEED' => $single_ship_data['speed'], |
||||
| 93 | 'CAPACITY' => $single_ship_data['capacity'], |
||||
| 94 | ); |
||||
| 95 | } |
||||
| 96 | } |
||||
| 97 | |||||
| 98 | return $return; |
||||
| 99 | } |
||||
| 100 | |||||
| 101 | /** |
||||
| 102 | * @param array $fleet |
||||
| 103 | * @param int $index |
||||
| 104 | * @param array|bool $user_data |
||||
| 105 | * |
||||
| 106 | * @return mixed |
||||
| 107 | */ |
||||
| 108 | function tpl_parse_fleet_db($fleet, $index, $user_data = false) { |
||||
| 109 | $result = null; |
||||
| 110 | |||||
| 111 | return sn_function_call('tpl_parse_fleet_db', [$fleet, $index, $user_data, &$result]); |
||||
| 112 | } |
||||
| 113 | |||||
| 114 | /** |
||||
| 115 | * @param array $fleet |
||||
| 116 | * @param int $index |
||||
| 117 | * @param array|bool $user_data |
||||
| 118 | * @param $result |
||||
| 119 | * |
||||
| 120 | * @return mixed |
||||
| 121 | */ |
||||
| 122 | function sn_tpl_parse_fleet_db($fleet, $index, $user_data = false, &$result) { |
||||
| 123 | global $lang, $user; |
||||
| 124 | |||||
| 125 | if (!$user_data) { |
||||
| 126 | $user_data = $user; |
||||
| 127 | } |
||||
| 128 | |||||
| 129 | if ($fleet['fleet_mess'] == 0 && $fleet['fleet_mission'] == MT_AKS) { |
||||
| 130 | $aks = DbFleetStatic::dbAcsGetById($fleet['fleet_group']); |
||||
| 131 | } |
||||
| 132 | |||||
| 133 | $spy_level = $user['id'] == $fleet['fleet_owner'] ? 100 : GetSpyLevel($user); |
||||
| 134 | |||||
| 135 | $result['fleet'] = isset($result['fleet']) ? $result['fleet'] : array(); |
||||
| 136 | |||||
| 137 | $result['fleet'] = array( |
||||
| 138 | 'NUMBER' => $index, |
||||
| 139 | |||||
| 140 | 'ID' => $fleet['fleet_id'], |
||||
| 141 | 'OWNER' => $fleet['fleet_owner'], |
||||
| 142 | 'TARGET_OWNER' => $fleet['fleet_target_owner'], |
||||
| 143 | |||||
| 144 | 'MESSAGE' => $fleet['fleet_mess'], |
||||
| 145 | 'MISSION' => $fleet['fleet_mission'], |
||||
| 146 | 'MISSION_NAME' => $lang['type_mission'][$fleet['fleet_mission']], |
||||
| 147 | 'ACS' => $aks['name'], |
||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
| 148 | 'AMOUNT' => $spy_level >= 4 ? (HelperString::numberFloorAndFormat($fleet['fleet_amount']) . ($fleet['fleet_resource_metal'] + $fleet['fleet_resource_crystal'] + $fleet['fleet_resource_deuterium'] ? '+' : '')) : '?', |
||||
| 149 | |||||
| 150 | 'METAL' => $spy_level >= 8 ? $fleet['fleet_resource_metal'] : 0, |
||||
| 151 | 'CRYSTAL' => $spy_level >= 8 ? $fleet['fleet_resource_crystal'] : 0, |
||||
| 152 | 'DEUTERIUM' => $spy_level >= 8 ? $fleet['fleet_resource_deuterium'] : 0, |
||||
| 153 | |||||
| 154 | 'START_TYPE_TEXT_SH' => $lang['sys_planet_type_sh'][$fleet['fleet_start_type']], |
||||
| 155 | 'START_COORDS' => "[{$fleet['fleet_start_galaxy']}:{$fleet['fleet_start_system']}:{$fleet['fleet_start_planet']}]", |
||||
| 156 | 'START_TIME_TEXT' => date(FMT_DATE_TIME, $fleet['fleet_end_time'] + SN_CLIENT_TIME_DIFF), |
||||
| 157 | 'START_LEFT' => floor($fleet['fleet_end_time'] + 1 - SN_TIME_NOW), |
||||
| 158 | 'START_URL' => uni_render_coordinates_href($fleet, 'fleet_start_', 3), |
||||
| 159 | 'START_NAME' => $fleet['fleet_start_name'], |
||||
| 160 | |||||
| 161 | 'END_TYPE_TEXT_SH' => $lang['sys_planet_type_sh'][$fleet['fleet_end_type']], |
||||
| 162 | 'END_COORDS' => "[{$fleet['fleet_end_galaxy']}:{$fleet['fleet_end_system']}:{$fleet['fleet_end_planet']}]", |
||||
| 163 | 'END_TIME_TEXT' => date(FMT_DATE_TIME, $fleet['fleet_start_time'] + SN_CLIENT_TIME_DIFF), |
||||
| 164 | 'END_LEFT' => floor($fleet['fleet_start_time'] + 1 - SN_TIME_NOW), |
||||
| 165 | 'END_URL' => uni_render_coordinates_href($fleet, 'fleet_end_', 3), |
||||
| 166 | 'END_NAME' => $fleet['fleet_end_name'], |
||||
| 167 | |||||
| 168 | 'STAY_TIME' => date(FMT_DATE_TIME, $fleet['fleet_end_stay'] + SN_CLIENT_TIME_DIFF), |
||||
| 169 | 'STAY_LEFT' => floor($fleet['fleet_end_stay'] + 1 - SN_TIME_NOW), |
||||
| 170 | |||||
| 171 | 'OV_LABEL' => $fleet['ov_label'], |
||||
| 172 | 'EVENT_TIME_TEXT' => date(FMT_DATE_TIME, $fleet['event_time'] + SN_CLIENT_TIME_DIFF), |
||||
| 173 | 'OV_LEFT' => floor($fleet['event_time'] + 1 - SN_TIME_NOW), |
||||
| 174 | 'OV_THIS_PLANET' => $fleet['ov_this_planet'], |
||||
| 175 | ); |
||||
| 176 | |||||
| 177 | $ship_list = explode(';', $fleet['fleet_array']); |
||||
| 178 | |||||
| 179 | $ship_id = 0; |
||||
| 180 | if ($spy_level >= 6) { |
||||
| 181 | foreach ($ship_list as $ship_record) { |
||||
| 182 | if ($ship_record) { |
||||
| 183 | $ship_data = explode(',', $ship_record); |
||||
| 184 | if ($spy_level >= 10) { |
||||
| 185 | $single_ship_data = get_ship_data($ship_data[0], $user_data); |
||||
| 186 | $result['ships'][$ship_data[0]] = array( |
||||
| 187 | 'ID' => $ship_data[0], |
||||
| 188 | 'NAME' => $lang['tech'][$ship_data[0]], |
||||
| 189 | 'AMOUNT' => $ship_data[1], |
||||
| 190 | 'AMOUNT_TEXT' => HelperString::numberFloorAndFormat($ship_data[1]), |
||||
|
0 ignored issues
–
show
$ship_data[1] of type string is incompatible with the type double|integer expected by parameter $number of HelperString::numberFloorAndFormat().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 191 | 'CONSUMPTION' => $single_ship_data['consumption'], |
||||
| 192 | 'SPEED' => $single_ship_data['speed'], |
||||
| 193 | 'CAPACITY' => $single_ship_data['capacity'], |
||||
| 194 | ); |
||||
| 195 | } else { |
||||
| 196 | $result['ships'][$ship_data[0]] = array( |
||||
| 197 | 'ID' => $ship_id++, |
||||
| 198 | 'NAME' => $lang['tech'][UNIT_SHIPS], |
||||
| 199 | 'AMOUNT' => $ship_data[1], |
||||
| 200 | 'AMOUNT_TEXT' => HelperString::numberFloorAndFormat($ship_data[1]), |
||||
| 201 | 'CONSUMPTION' => 0, |
||||
| 202 | 'CONSUMPTION_TEXT' => '0', |
||||
| 203 | 'SPEED' => 0, |
||||
| 204 | 'CAPACITY' => 0, |
||||
| 205 | ); |
||||
| 206 | } |
||||
| 207 | } |
||||
| 208 | } |
||||
| 209 | } |
||||
| 210 | |||||
| 211 | return $result; |
||||
| 212 | } |
||||
| 213 | |||||
| 214 | function tpl_parse_planet_que($que, $planet, $que_id) { |
||||
| 215 | $hangar_que = array(); |
||||
| 216 | $que_hangar = $que['ques'][$que_id][$planet['id_owner']][$planet['id']]; |
||||
| 217 | if (!empty($que_hangar)) { |
||||
| 218 | foreach ($que_hangar as $que_item) { |
||||
| 219 | $hangar_que['que'][] = array('id' => $que_item['que_unit_id'], 'count' => $que_item['que_unit_amount']); |
||||
| 220 | $hangar_que[$que_item['que_unit_id']] += $que_item['que_unit_amount']; |
||||
| 221 | } |
||||
| 222 | } |
||||
| 223 | |||||
| 224 | return $hangar_que; |
||||
| 225 | } |
||||
| 226 | |||||
| 227 | /** |
||||
| 228 | * @param array $planet |
||||
| 229 | * @param array $fleet_list |
||||
| 230 | * |
||||
| 231 | * @return array |
||||
| 232 | */ |
||||
| 233 | function tpl_parse_planet_result_fleet($planet, $fleet_list) { |
||||
| 234 | return [ |
||||
| 235 | 'FLEET_OWN' => $fleet_list['own']['count'], |
||||
| 236 | 'FLEET_ENEMY' => $fleet_list['enemy']['count'], |
||||
| 237 | 'FLEET_NEUTRAL' => $fleet_list['neutral']['count'], |
||||
| 238 | 'PLANET_FLEET_ID' => !empty($fleet_list['own']['count']) ? getUniqueFleetId($planet) : 0, |
||||
| 239 | ]; |
||||
| 240 | } |
||||
| 241 | |||||
| 242 | |||||
| 243 | /** |
||||
| 244 | * @param int $parentPlanetId |
||||
| 245 | * |
||||
| 246 | * @return array |
||||
| 247 | */ |
||||
| 248 | function tpl_parse_planet_moon($parentPlanetId) { |
||||
| 249 | $moon_fill = 0; |
||||
| 250 | $moon_fleets = []; |
||||
| 251 | |||||
| 252 | $moon = DBStaticPlanet::db_planet_by_parent($parentPlanetId); |
||||
| 253 | if ($moon) { |
||||
| 254 | $moon_fill = min(100, floor($moon['field_current'] / eco_planet_fields_max($moon) * 100)); |
||||
| 255 | $moon_fleets = flt_get_fleets_to_planet($moon); |
||||
| 256 | } |
||||
| 257 | |||||
| 258 | return [ |
||||
| 259 | 'MOON_ID' => $moon['id'], |
||||
| 260 | 'MOON_NAME' => $moon['name'], |
||||
| 261 | 'MOON_IMG' => $moon['image'], |
||||
| 262 | 'MOON_FILL' => min(100, $moon_fill), |
||||
| 263 | 'MOON_ENEMY' => !empty($moon_fleets['enemy']['count']) ? $moon_fleets['enemy']['count'] : 0, |
||||
| 264 | |||||
| 265 | 'MOON_PLANET' => $moon['parent_planet'], |
||||
| 266 | ]; |
||||
| 267 | } |
||||
| 268 | |||||
| 269 | /** |
||||
| 270 | * @param array $user |
||||
| 271 | * @param array $planet |
||||
| 272 | * |
||||
| 273 | * @return array |
||||
| 274 | */ |
||||
| 275 | function tpl_parse_planet($user, $planet) { |
||||
| 276 | global $lang; |
||||
| 277 | |||||
| 278 | $que = que_get($planet['id_owner'], $planet['id'], false); |
||||
| 279 | $structure_que = tpl_parse_planet_que($que, $planet, QUE_STRUCTURES); // TODO Заменить на que_tpl_parse_element($que_element); |
||||
| 280 | $structure_que_first = is_array($structure_que['que']) ? reset($structure_que['que']) : array(); |
||||
| 281 | $hangar_que = tpl_parse_planet_que($que, $planet, SUBQUE_FLEET); // TODO Заменить на que_tpl_parse_element($que_element); |
||||
| 282 | $hangar_que_first = is_array($hangar_que['que']) ? reset($hangar_que['que']) : array(); |
||||
| 283 | $defense_que = tpl_parse_planet_que($que, $planet, SUBQUE_DEFENSE); // TODO Заменить на que_tpl_parse_element($que_element); |
||||
| 284 | $defense_que_first = is_array($defense_que['que']) ? reset($defense_que['que']) : array(); |
||||
| 285 | |||||
| 286 | $result = [ |
||||
| 287 | 'ID' => $planet['id'], |
||||
| 288 | 'NAME' => $planet['name'], |
||||
| 289 | 'IMAGE' => $planet['image'], |
||||
| 290 | |||||
| 291 | 'GALAXY' => $planet['galaxy'], |
||||
| 292 | 'SYSTEM' => $planet['system'], |
||||
| 293 | 'PLANET' => $planet['planet'], |
||||
| 294 | 'TYPE' => $planet['planet_type'], |
||||
| 295 | 'COORDINATES' => uni_render_coordinates($planet), |
||||
| 296 | 'IS_CAPITAL' => $planet['planet_type'] == PT_PLANET && $planet['id'] == $user['id_planet'], |
||||
| 297 | 'IS_MOON' => $planet['planet_type'] == PT_MOON, |
||||
| 298 | |||||
| 299 | 'METAL_PERCENT' => $planet['metal_mine_porcent'] * 10, |
||||
| 300 | 'CRYSTAL_PERCENT' => $planet['crystal_mine_porcent'] * 10, |
||||
| 301 | 'DEUTERIUM_PERCENT' => $planet['deuterium_sintetizer_porcent'] * 10, |
||||
| 302 | |||||
| 303 | 'STRUCTURE' => isset($structure_que_first['id']) ? $lang['tech'][$structure_que_first['id']] : '', |
||||
| 304 | 'STRUCTURE_SLOTS' => is_array($structure_que['que']) ? count($structure_que['que']) : 0, |
||||
| 305 | 'HANGAR' => isset($hangar_que_first['id']) ? $lang['tech'][$hangar_que_first['id']] : '', |
||||
| 306 | 'HANGAR_SLOTS' => is_array($hangar_que['que']) ? count($hangar_que['que']) : 0, |
||||
| 307 | 'DEFENSE' => isset($defense_que_first['id']) ? $lang['tech'][$defense_que_first['id']] : '', |
||||
| 308 | 'DEFENSE_SLOTS' => is_array($defense_que['que']) ? count($defense_que['que']) : 0, |
||||
| 309 | |||||
| 310 | 'FIELDS_CUR' => $planet['field_current'], |
||||
| 311 | 'FIELDS_MAX' => eco_planet_fields_max($planet), |
||||
| 312 | 'FILL' => min(100, floor($planet['field_current'] / eco_planet_fields_max($planet) * 100)), |
||||
| 313 | |||||
| 314 | 'PLANET_GOVERNOR_ID' => $planet['PLANET_GOVERNOR_ID'], |
||||
| 315 | 'PLANET_GOVERNOR_NAME' => $lang['tech'][$planet['PLANET_GOVERNOR_ID']], |
||||
| 316 | 'PLANET_GOVERNOR_LEVEL' => $planet['PLANET_GOVERNOR_LEVEL'], |
||||
| 317 | 'PLANET_GOVERNOR_LEVEL_MAX' => get_unit_param($planet['PLANET_GOVERNOR_ID'], P_MAX_STACK), |
||||
| 318 | ]; |
||||
| 319 | |||||
| 320 | if (!empty($que['ques'][QUE_STRUCTURES][$planet['id_owner']][$planet['id']])) { |
||||
| 321 | $result['building_que'] = []; |
||||
| 322 | $building_que = &$que['ques'][QUE_STRUCTURES][$planet['id_owner']][$planet['id']]; |
||||
| 323 | foreach ($building_que as $que_element) { |
||||
| 324 | $result['building_que'][] = que_tpl_parse_element($que_element); |
||||
| 325 | } |
||||
| 326 | } |
||||
| 327 | |||||
| 328 | return $result; |
||||
| 329 | } |
||||
| 330 | |||||
| 331 | function flt_get_fleets_to_planet($planet, $fleet_db_list = 0) { |
||||
| 332 | if (!($planet && $planet['id']) && !$fleet_db_list) { |
||||
| 333 | return $planet; |
||||
| 334 | } |
||||
| 335 | |||||
| 336 | global $user; |
||||
| 337 | |||||
| 338 | if ($fleet_db_list === 0) { |
||||
| 339 | $fleet_db_list = DbFleetStatic::fleet_and_missiles_list_by_coordinates($planet); |
||||
| 340 | } |
||||
| 341 | |||||
| 342 | foreach ($fleet_db_list as $fleet) { |
||||
| 343 | if ($fleet['fleet_owner'] == $user['id']) { |
||||
| 344 | if ($fleet['fleet_mission'] == MT_MISSILE) { |
||||
| 345 | continue; |
||||
| 346 | } |
||||
| 347 | $fleet_ownage = 'own'; |
||||
| 348 | } else { |
||||
| 349 | switch ($fleet['fleet_mission']) { |
||||
| 350 | case MT_ATTACK: |
||||
| 351 | case MT_AKS: |
||||
| 352 | case MT_DESTROY: |
||||
| 353 | case MT_MISSILE: |
||||
| 354 | $fleet_ownage = 'enemy'; |
||||
| 355 | break; |
||||
| 356 | |||||
| 357 | default: |
||||
| 358 | $fleet_ownage = 'neutral'; |
||||
| 359 | break; |
||||
| 360 | |||||
| 361 | } |
||||
| 362 | } |
||||
| 363 | |||||
| 364 | $fleet_list[$fleet_ownage]['fleets'][$fleet['fleet_id']] = $fleet; |
||||
| 365 | |||||
| 366 | if ($fleet['fleet_mess'] == 1 || ($fleet['fleet_mess'] == 0 && $fleet['fleet_mission'] == MT_RELOCATE) || ($fleet['fleet_target_owner'] != $user['id'])) { |
||||
| 367 | // $fleet_sn = flt_expand($fleet); |
||||
| 368 | $fleet_sn = sys_unit_str2arr($fleet['fleet_array']); |
||||
| 369 | foreach ($fleet_sn as $ship_id => $ship_amount) { |
||||
| 370 | if (in_array($ship_id, sn_get_groups('fleet'))) { |
||||
| 371 | $fleet_list[$fleet_ownage]['total'][$ship_id] += $ship_amount; |
||||
| 372 | } |
||||
| 373 | } |
||||
| 374 | } |
||||
| 375 | |||||
| 376 | $fleet_list[$fleet_ownage]['count']++; |
||||
| 377 | $fleet_list[$fleet_ownage]['amount'] += $fleet['fleet_amount']; |
||||
| 378 | $fleet_list[$fleet_ownage]['total'][RES_METAL] += $fleet['fleet_resource_metal']; |
||||
| 379 | $fleet_list[$fleet_ownage]['total'][RES_CRYSTAL] += $fleet['fleet_resource_crystal']; |
||||
| 380 | $fleet_list[$fleet_ownage]['total'][RES_DEUTERIUM] += $fleet['fleet_resource_deuterium']; |
||||
| 381 | } |
||||
| 382 | |||||
| 383 | return $fleet_list; |
||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
| 384 | } |
||||
| 385 | |||||
| 386 | /** |
||||
| 387 | * @param template $template |
||||
| 388 | * @param array $planetrow |
||||
| 389 | * @param array $fleets_to_planet |
||||
| 390 | */ |
||||
| 391 | function tpl_set_resource_info(&$template, $planetrow, $fleets_to_planet = array()) { |
||||
| 392 | $template->assign_vars(array( |
||||
| 393 | 'RESOURCE_ROUNDING' => 0, |
||||
| 394 | |||||
| 395 | 'PLANET_ENERGY' => $planetrow['energy_used'], |
||||
| 396 | 'ENERGY_BALANCE_NUMBER' => $planetrow['energy_max'] - $planetrow['energy_used'], |
||||
| 397 | 'ENERGY_BALANCE' => prettyNumberStyledDefault($planetrow['energy_max'] - $planetrow['energy_used']), |
||||
| 398 | 'ENERGY_MAX_NUMBER' => $planetrow['energy_max'], |
||||
| 399 | 'ENERGY_MAX_NUMBER_TEXT_NO_COLOR' => HelperString::numberFloorAndFormat($planetrow['energy_max']), |
||||
| 400 | 'ENERGY_MAX_NUMBER_TEXT' => Tools::numberPercentSpan($planetrow['energy_max'], $planetrow['energy_used']), |
||||
| 401 | 'ENERGY_MAX' => prettyNumberStyledCompare($planetrow['energy_max'], -$planetrow['energy_used']), |
||||
| 402 | 'ENERGY_FILL' => round(($planetrow["energy_used"] / ($planetrow["energy_max"] + 1)) * 100, 0), |
||||
| 403 | |||||
| 404 | 'PLANET_METAL' => floor($planetrow["metal"]), |
||||
| 405 | 'PLANET_METAL_TEXT' => prettyNumberStyledCompare($planetrow["metal"], $planetrow["metal_max"]), |
||||
| 406 | 'PLANET_METAL_MAX' => floor($planetrow["metal_max"]), |
||||
| 407 | 'PLANET_METAL_MAX_TEXT' => Tools::numberPercentSpan($planetrow["metal_max"], $planetrow["metal"]), |
||||
| 408 | 'PLANET_METAL_MAX_NO_COLOR' => HelperString::numberFloorAndFormat($planetrow["metal_max"]), |
||||
| 409 | 'PLANET_METAL_FILL' => round(($planetrow["metal"] / ($planetrow["metal_max"] + 1)) * 100, 0), |
||||
| 410 | 'PLANET_METAL_PERHOUR' => round($planetrow["metal_perhour"], 5), |
||||
| 411 | 'PLANET_METAL_FLEET_TEXT' => prettyNumberStyledDefault($fleets_to_planet[$planetrow['id']]['fleet']['METAL']), |
||||
| 412 | |||||
| 413 | 'PLANET_CRYSTAL' => floor($planetrow["crystal"]), |
||||
| 414 | 'PLANET_CRYSTAL_TEXT' => prettyNumberStyledCompare($planetrow["crystal"], $planetrow["crystal_max"]), |
||||
| 415 | 'PLANET_CRYSTAL_MAX' => floor($planetrow["crystal_max"]), |
||||
| 416 | 'PLANET_CRYSTAL_MAX_TEXT' => Tools::numberPercentSpan($planetrow["crystal_max"], $planetrow["crystal"]), |
||||
| 417 | 'PLANET_CRYSTAL_MAX_NO_COLOR' => HelperString::numberFloorAndFormat($planetrow["crystal_max"]), |
||||
| 418 | 'PLANET_CRYSTAL_FILL' => round(($planetrow["crystal"] / ($planetrow["crystal_max"] + 1)) * 100, 0), |
||||
| 419 | 'PLANET_CRYSTAL_PERHOUR' => round($planetrow["crystal_perhour"], 5), |
||||
| 420 | 'PLANET_CRYSTAL_FLEET_TEXT' => prettyNumberStyledDefault($fleets_to_planet[$planetrow['id']]['fleet']['CRYSTAL']), |
||||
| 421 | |||||
| 422 | 'PLANET_DEUTERIUM' => floor($planetrow["deuterium"]), |
||||
| 423 | 'PLANET_DEUTERIUM_TEXT' => prettyNumberStyledCompare($planetrow["deuterium"], $planetrow["deuterium_max"]), |
||||
| 424 | 'PLANET_DEUTERIUM_MAX' => floor($planetrow["deuterium_max"]), |
||||
| 425 | 'PLANET_DEUTERIUM_MAX_TEXT' => Tools::numberPercentSpan($planetrow["deuterium_max"], $planetrow["deuterium"]), |
||||
| 426 | 'PLANET_DEUTERIUM_MAX_NO_COLOR' => HelperString::numberFloorAndFormat($planetrow["deuterium_max"]), |
||||
| 427 | 'PLANET_DEUTERIUM_FILL' => round(($planetrow["deuterium"] / ($planetrow["deuterium_max"] + 1)) * 100, 0), |
||||
| 428 | 'PLANET_DEUTERIUM_PERHOUR' => round($planetrow["deuterium_perhour"], 5), |
||||
| 429 | 'PLANET_DEUTERIUM_FLEET_TEXT' => prettyNumberStyledDefault($fleets_to_planet[$planetrow['id']]['fleet']['DEUTERIUM']), |
||||
| 430 | )); |
||||
| 431 | } |
||||
| 432 | |||||
| 433 | /** |
||||
| 434 | * @return int[][] |
||||
| 435 | */ |
||||
| 436 | function templateFillPercent() { |
||||
| 437 | $result = []; |
||||
| 438 | for ($i = 100; $i >= 0; $i -= 10) { |
||||
| 439 | $result[] = ['PERCENT' => $i]; |
||||
| 440 | } |
||||
| 441 | |||||
| 442 | return ['.' => ['percent' => $result]]; |
||||
|
0 ignored issues
–
show
|
|||||
| 443 | } |
||||
| 444 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.