/imperium.php

https://github.com/vem882/SuperNova · PHP · 185 lines · 140 code · 36 blank · 9 comment · 13 complexity · 33da680cf5d68b578aaf58a91a9ce61b MD5 · raw file

  1. <?php
  2. /**
  3. * imperium.php
  4. *
  5. * Overview you empire
  6. *
  7. * @version 1.0
  8. * @copyright 2008 by Chlorel for XNova
  9. // Created by Perberos. All rights reserved (C) 2006
  10. */
  11. $ugamela_root_path = (defined('SN_ROOT_PATH')) ? SN_ROOT_PATH : './';
  12. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  13. include("{$ugamela_root_path}common.{$phpEx}");
  14. if ($IsUserChecked == false) {
  15. includeLang('login');
  16. header('Location: login.php');
  17. }
  18. $planets = array();
  19. $ques = array();
  20. $planet_row_list = doquery("SELECT `id` FROM {{planets}} WHERE `id_owner` = '{$user['id']}';");
  21. while ($planet = mysql_fetch_assoc($planet_row_list))
  22. {
  23. $global_data = sys_o_get_updated($user, $planet['id'], $time_now, true);
  24. $planets[$planet['id']] = $global_data['planet'];
  25. $ques[$planet['id']] = $global_data['que'];
  26. }
  27. $template = gettemplate('imperium', true);
  28. $template->assign_var('amount', count($planets) + 2);
  29. $fleet_id = 1;
  30. $fleets = array();
  31. foreach ($planets as $planet_index => &$planet)
  32. {
  33. $list_planet_que = $ques[$planet_index];
  34. $planet_template = tpl_parse_planet($planet, $list_planet_que);
  35. $planet_fleet_id = 0;
  36. $fleet_list = $planet_template['fleet_list'];//flt_get_fleets_to_planet($planet);
  37. if($fleet_list['own']['count'])
  38. {
  39. $planet_fleet_id = "p{$fleet_id}";
  40. $fleets[] = tpl_parse_fleet_sn($fleet_list['own']['total'], $planet_fleet_id);
  41. $fleet_id++;
  42. }
  43. $template->assign_block_vars('planet', array_merge($planet_template, array(
  44. 'PLANET_FLEET_ID' => $planet_fleet_id,
  45. 'FIELDS_CUR' => $planet['field_current'],
  46. 'FIELDS_MAX' => $planet['field_max'] + $planet[$sn_data[33]['name']] * 5,
  47. 'METAL_CUR' => pretty_number($planet['metal'], true, $planet['metal_max']),
  48. 'METAL_PROD' => pretty_number($planet['metal_perhour']),
  49. 'CRYSTAL_CUR' => pretty_number($planet['crystal'], true, $planet['crystal_max']),
  50. 'CRYSTAL_PROD' => pretty_number($planet['crystal_perhour']),
  51. 'DEUTERIUM_CUR' => pretty_number($planet['deuterium'], true, $planet['deuterium_max']),
  52. 'DEUTERIUM_PROD' => pretty_number($planet['deuterium_perhour']),
  53. 'ENERGY_CUR' => pretty_number($planet['energy_max'] - $planet['energy_used'], true, true),
  54. 'ENERGY_MAX' => pretty_number($planet['energy_max']),
  55. )));
  56. $planet['fleet_list'] = $planet_template['fleet_list'];
  57. $planet['BUILDING_ID'] = $planet_template['BUILDING_ID'];
  58. $planet['hangar_que'] = $planet_template['hangar_que'];
  59. $planet['full_que'] = $list_planet_que;
  60. $total['fields'] += $planet['field_current'];
  61. $total['metal'] += $planet['metal'];
  62. $total['crystal'] += $planet['crystal'];
  63. $total['deuterium'] += $planet['deuterium'];
  64. $total['energy'] += $planet['energy_max'] - $planet['energy_used'];
  65. $total['fields_max'] += $planet['field_max'] + $planet[$sn_data[33]['name']] * 5;
  66. $total['metal_perhour'] += $planet['metal_perhour'];
  67. $total['crystal_perhour'] += $planet['crystal_perhour'];
  68. $total['deuterium_perhour'] += $planet['deuterium_perhour'];
  69. $total['energy_max'] += $planet['energy_max'];
  70. }
  71. tpl_assign_fleet($template, $fleets);
  72. $template->assign_block_vars('planet', array_merge(array(
  73. 'NAME' => 'ÈÒÎÃÎ',
  74. 'FIELDS_CUR' => $total['fields'],
  75. 'FIELDS_MAX' => $total['fields_max'],
  76. 'METAL_CUR' => pretty_number($total['metal']),
  77. 'METAL_PROD' => pretty_number($total['metal_perhour']),
  78. 'CRYSTAL_CUR' => pretty_number($total['crystal']),
  79. 'CRYSTAL_PROD' => pretty_number($total['crystal_perhour']),
  80. 'DEUTERIUM_CUR' => pretty_number($total['deuterium']),
  81. 'DEUTERIUM_PROD' => pretty_number($total['deuterium_perhour']),
  82. 'ENERGY_CUR' => pretty_number($total['energy']),
  83. 'ENERGY_MAX' => pretty_number($total['energy_max']),
  84. )));
  85. unset($planet);
  86. $last = -1000;
  87. foreach ($sn_data as $unit_id => $res) {
  88. if (in_array($unit_id, $reslist['build']))
  89. $mode = 'buildings';
  90. elseif (in_array($unit_id, $reslist['fleet']))
  91. $mode = 'fleet';
  92. elseif (in_array($unit_id, $reslist['defense']))
  93. $mode = 'defense';
  94. else
  95. $mode = '';
  96. if($mode)
  97. {
  98. if((int) ($unit_id/100) != (int)($last/100))
  99. {
  100. $template->assign_block_vars('prods', array(
  101. 'NAME' => $lang['tech'][(int) ($unit_id/100)*100],
  102. ));
  103. }
  104. $template->assign_block_vars('prods', array(
  105. 'ID' => $unit_id,
  106. 'FIELD' => $resource[$unit_id],
  107. 'NAME' => $lang['tech'][$unit_id],
  108. 'MODE' => $mode,
  109. ));
  110. $unit_count = 0;
  111. foreach($planets as $planet)
  112. {
  113. $level_plus['LEVEL_PLUS_YELLOW'] = 0;
  114. $level_plus['LEVEL_PLUS_GREEN'] = 0;
  115. switch($mode)
  116. {
  117. case 'buildings':
  118. $level_plus_build = $planet['full_que']['in_que'][$unit_id];
  119. if($level_plus_build)
  120. {
  121. $level_plus['LEVEL_PLUS_GREEN'] = $level_plus_build<0 ? $level_plus_build : "+{$level_plus_build}";
  122. }
  123. break;
  124. case 'fleet':
  125. $level_plus['LEVEL_PLUS_YELLOW'] = $planet['fleet_list']['own']['total'][$unit_id]<=0 ? $planet['fleet_list']['own']['total'][$unit_id] : "+{$planet['fleet_list']['own']['total'][$unit_id]}";
  126. case 'defense':
  127. if($planet['hangar_que'][$unit_id])
  128. {
  129. $level_plus['LEVEL_PLUS_GREEN'] = "+{$planet['hangar_que'][$unit_id]}";
  130. }
  131. break;
  132. default:
  133. break;
  134. }
  135. $template->assign_block_vars('prods.planet', array_merge($level_plus, array(
  136. 'ID' => $planet['id'],
  137. 'TYPE' => $planet['planet_type'],
  138. 'LEVEL' => $planet[$resource[$unit_id]] == 0 && !$level_plus['LEVEL_PLUS_YELLOW'] && !$level_plus['LEVEL_PLUS_GREEN'] ? '-' : $planet[$resource[$unit_id]],
  139. )));
  140. $unit_count += $planet[$resource[$unit_id]];
  141. }
  142. $template->assign_block_vars('prods.planet', array(
  143. 'LEVEL' => $unit_count,
  144. ));
  145. $last = $unit_id;
  146. }
  147. }
  148. display(parsetemplate($template), $lang['imp_overview']);
  149. ?>