[Question] Display the number of destroyed fleets

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • [Question] Display the number of destroyed fleets

      hello.
      My english is no good.
      2moons 1.8

      I want to display the number of fleets destroyed during battle.
      I want to display it like a photo.
      help me.



      GenerateReport.php

      PHP Source Code

      1. <?php
      2. /**
      3. * 2Moons
      4. * by Jan-Otto Kröpke 2009-2016
      5. *
      6. * For the full copyright and license information, please view the LICENSE
      7. *
      8. * @package 2Moons
      9. * @author Jan-Otto Kröpke <slaver7@gmail.com>
      10. * @copyright 2009 Lucky
      11. * @copyright 2016 Jan-Otto Kröpke <slaver7@gmail.com>
      12. * @licence MIT
      13. * @version 1.8.0
      14. * @link https://github.com/jkroepke/2Moons
      15. */
      16. function GenerateReport($combatResult, $reportInfo)
      17. {
      18. $Destroy = array('att' => 0, 'def' => 0);
      19. $DATA = array();
      20. $DATA['mode'] = (int) $reportInfo['moonDestroy'];
      21. $DATA['time'] = $reportInfo['thisFleet']['fleet_start_time'];
      22. $DATA['start'] = array($reportInfo['thisFleet']['fleet_start_galaxy'], $reportInfo['thisFleet']['fleet_start_system'], $reportInfo['thisFleet']['fleet_start_planet'], $reportInfo['thisFleet']['fleet_start_type']);
      23. $DATA['koords'] = array($reportInfo['thisFleet']['fleet_end_galaxy'], $reportInfo['thisFleet']['fleet_end_system'], $reportInfo['thisFleet']['fleet_end_planet'], $reportInfo['thisFleet']['fleet_end_type']);
      24. $DATA['units'] = array($combatResult['unitLost']['attacker'], $combatResult['unitLost']['defender']);
      25. $DATA['debris'] = $reportInfo['debris'];
      26. $DATA['steal'] = $reportInfo['stealResource'];
      27. $DATA['result'] = $combatResult['won'];
      28. $DATA['moon'] = array(
      29. 'moonName' => $reportInfo['moonName'],
      30. 'moonChance' => (int) $reportInfo['moonChance'],
      31. 'moonDestroyChance' => (int) $reportInfo['moonDestroyChance'],
      32. 'moonDestroySuccess' => (int) $reportInfo['moonDestroySuccess'],
      33. 'fleetDestroyChance' => (int) $reportInfo['fleetDestroyChance'],
      34. 'fleetDestroySuccess' => (int) $reportInfo['fleetDestroySuccess']
      35. );
      36. if(isset($reportInfo['additionalInfo']))
      37. {
      38. $DATA['additionalInfo'] = $reportInfo['additionalInfo'];
      39. }
      40. else
      41. {
      42. $DATA['additionalInfo'] = "";
      43. }
      44. foreach($combatResult['rw'][0]['attackers'] as $player)
      45. {
      46. $DATA['players'][$player['player']['id']] = array(
      47. 'name' => $player['player']['username'],
      48. 'koords' => array($player['fleetDetail']['fleet_start_galaxy'], $player['fleetDetail']['fleet_start_system'], $player['fleetDetail']['fleet_start_planet'], $player['fleetDetail']['fleet_start_type']),
      49. 'tech' => array($player['techs'][0] * 100 - 100, $player['techs'][1] * 100 - 100, $player['techs'][2] * 100 - 100),
      50. );
      51. }
      52. foreach($combatResult['rw'][0]['defenders'] as $player)
      53. {
      54. $DATA['players'][$player['player']['id']] = array(
      55. 'name' => $player['player']['username'],
      56. 'koords' => array($player['fleetDetail']['fleet_start_galaxy'], $player['fleetDetail']['fleet_start_system'], $player['fleetDetail']['fleet_start_planet'], $player['fleetDetail']['fleet_start_type']),
      57. 'tech' => array($player['techs'][0] * 100, $player['techs'][1] * 100, $player['techs'][2] * 100),
      58. );
      59. }
      60. foreach($combatResult['rw'] as $Round => $RoundInfo)
      61. {
      62. foreach($RoundInfo['attackers'] as $FleetID => $player)
      63. {
      64. $playerData = array('userID' => $player['player']['id'], 'ships' => array());
      65. if(array_sum($player['unit']) == 0) {
      66. $DATA['rounds'][$Round]['attacker'][] = $playerData;
      67. $Destroy['att']++;
      68. continue;
      69. }
      70. foreach($player['unit'] as $ShipID => $Amount)
      71. {
      72. if ($Amount <= 0)
      73. continue;
      74. $ShipInfo = $RoundInfo['infoA'][$FleetID][$ShipID];
      75. $playerData['ships'][$ShipID] = array(
      76. $Amount, $ShipInfo['att'], $ShipInfo['def'], $ShipInfo['shield']
      77. );
      78. }
      79. $DATA['rounds'][$Round]['attacker'][] = $playerData;
      80. }
      81. foreach($RoundInfo['defenders'] as $FleetID => $player)
      82. {
      83. $playerData = array('userID' => $player['player']['id'], 'ships' => array());
      84. if(array_sum($player['unit']) == 0) {
      85. $DATA['rounds'][$Round]['defender'][] = $playerData;
      86. $Destroy['def']++;
      87. continue;
      88. }
      89. foreach($player['unit'] as $ShipID => $Amount)
      90. {
      91. if ($Amount <= 0) {
      92. $Destroy['def']++;
      93. continue;
      94. }
      95. $ShipInfo = $RoundInfo['infoD'][$FleetID][$ShipID];
      96. $playerData['ships'][$ShipID] = array(
      97. $Amount, $ShipInfo['att'], $ShipInfo['def'], $ShipInfo['shield']
      98. );
      99. }
      100. $DATA['rounds'][$Round]['defender'][] = $playerData;
      101. }
      102. if ($Round >= MAX_ATTACK_ROUNDS || $Destroy['att'] == count($RoundInfo['attackers']) || $Destroy['def'] == count($RoundInfo['defenders']))
      103. break;
      104. if(isset($RoundInfo['attack'], $RoundInfo['attackShield'], $RoundInfo['defense'], $RoundInfo['defShield']))
      105. $DATA['rounds'][$Round]['info'] = array($RoundInfo['attack'], $RoundInfo['attackShield'], $RoundInfo['defense'], $RoundInfo['defShield']);
      106. else
      107. $DATA['rounds'][$Round]['info'] = array(NULL, NULL, NULL, NULL);
      108. }
      109. return $DATA;
      110. }
      Display All
      --------------------------------------------------------------------------------------
    • i tryed to realize the idea and this is how it looks.

      first i edited the includes/classes/missions/functions/GenerateReport.php file.

      PHP Source Code

      1. <?php
      2. /**
      3. * 2Moons
      4. * by Jan-Otto Kröpke 2009-2016
      5. *
      6. * For the full copyright and license information, please view the LICENSE
      7. *
      8. * @package 2Moons
      9. * @author Jan-Otto Kröpke <slaver7@gmail.com>
      10. * @copyright 2009 Lucky
      11. * @copyright 2016 Jan-Otto Kröpke <slaver7@gmail.com>
      12. * @licence MIT
      13. * @version 1.8.0
      14. * @link https://github.com/jkroepke/2Moons
      15. */
      16. function GenerateReport($combatResult, $reportInfo)
      17. {
      18. $Destroy = array('att' => 0, 'def' => 0);
      19. $DATA = array();
      20. $DATA['mode'] = (int) $reportInfo['moonDestroy'];
      21. $DATA['time'] = $reportInfo['thisFleet']['fleet_start_time'];
      22. $DATA['start'] = array($reportInfo['thisFleet']['fleet_start_galaxy'], $reportInfo['thisFleet']['fleet_start_system'], $reportInfo['thisFleet']['fleet_start_planet'], $reportInfo['thisFleet']['fleet_start_type']);
      23. $DATA['koords'] = array($reportInfo['thisFleet']['fleet_end_galaxy'], $reportInfo['thisFleet']['fleet_end_system'], $reportInfo['thisFleet']['fleet_end_planet'], $reportInfo['thisFleet']['fleet_end_type']);
      24. $DATA['units'] = array($combatResult['unitLost']['attacker'], $combatResult['unitLost']['defender']);
      25. $DATA['debris'] = $reportInfo['debris'];
      26. $DATA['steal'] = $reportInfo['stealResource'];
      27. $DATA['result'] = $combatResult['won'];
      28. $DATA['moon'] = array(
      29. 'moonName' => $reportInfo['moonName'],
      30. 'moonChance' => (int) $reportInfo['moonChance'],
      31. 'moonDestroyChance' => (int) $reportInfo['moonDestroyChance'],
      32. 'moonDestroySuccess' => (int) $reportInfo['moonDestroySuccess'],
      33. 'fleetDestroyChance' => (int) $reportInfo['fleetDestroyChance'],
      34. 'fleetDestroySuccess' => (int) $reportInfo['fleetDestroySuccess']
      35. );
      36. if(isset($reportInfo['additionalInfo']))
      37. {
      38. $DATA['additionalInfo'] = $reportInfo['additionalInfo'];
      39. }
      40. else
      41. {
      42. $DATA['additionalInfo'] = "";
      43. }
      44. foreach($combatResult['rw'][0]['attackers'] as $player)
      45. {
      46. $DATA['players'][$player['player']['id']] = array(
      47. 'name' => $player['player']['username'],
      48. 'koords' => array($player['fleetDetail']['fleet_start_galaxy'], $player['fleetDetail']['fleet_start_system'], $player['fleetDetail']['fleet_start_planet'], $player['fleetDetail']['fleet_start_type']),
      49. 'tech' => array($player['techs'][0] * 100 - 100, $player['techs'][1] * 100 - 100, $player['techs'][2] * 100 - 100),
      50. );
      51. }
      52. foreach($combatResult['rw'][0]['defenders'] as $player)
      53. {
      54. $DATA['players'][$player['player']['id']] = array(
      55. 'name' => $player['player']['username'],
      56. 'koords' => array($player['fleetDetail']['fleet_start_galaxy'], $player['fleetDetail']['fleet_start_system'], $player['fleetDetail']['fleet_start_planet'], $player['fleetDetail']['fleet_start_type']),
      57. 'tech' => array($player['techs'][0] * 100, $player['techs'][1] * 100, $player['techs'][2] * 100),
      58. );
      59. }
      60. foreach($combatResult['rw'] as $Round => $RoundInfo)
      61. {
      62. foreach($RoundInfo['attackers'] as $FleetID => $player)
      63. {
      64. $playerData = array('userID' => $player['player']['id'], 'ships' => array());
      65. if(array_sum($player['unit']) == 0) {
      66. $DATA['rounds'][$Round]['attacker'][] = $playerData;
      67. $Destroy['att']++;
      68. continue;
      69. }
      70. foreach($player['unit'] as $ShipID => $Amount)
      71. {
      72. if ($Amount <= 0)
      73. continue;
      74. $ShipInfo = $RoundInfo['infoA'][$FleetID][$ShipID];
      75. $newamount = isset($combatResult['rw'][$Round + 1]['attackers'][$FleetID]['unit'][$ShipID]) ? $combatResult['rw'][$Round + 1]['attackers'][$FleetID]['unit'][$ShipID] : $Amount;
      76. $playerData['ships'][$ShipID] = array(
      77. $Amount, $ShipInfo['att'], $ShipInfo['def'], $ShipInfo['shield'],($newamount - $Amount)
      78. );
      79. }
      80. $DATA['rounds'][$Round]['attacker'][] = $playerData;
      81. }
      82. foreach($RoundInfo['defenders'] as $FleetID => $player)
      83. {
      84. $playerData = array('userID' => $player['player']['id'], 'ships' => array());
      85. if(array_sum($player['unit']) == 0) {
      86. $DATA['rounds'][$Round]['defender'][] = $playerData;
      87. $Destroy['def']++;
      88. continue;
      89. }
      90. foreach($player['unit'] as $ShipID => $Amount)
      91. {
      92. if ($Amount <= 0) {
      93. $Destroy['def']++;
      94. continue;
      95. }
      96. $ShipInfo = $RoundInfo['infoD'][$FleetID][$ShipID];
      97. $newamount = isset($combatResult['rw'][$Round + 1]['defenders'][$FleetID]['unit'][$ShipID]) ? $combatResult['rw'][$Round + 1]['defenders'][$FleetID]['unit'][$ShipID] : $Amount;
      98. $playerData['ships'][$ShipID] = array(
      99. $Amount, $ShipInfo['att'], $ShipInfo['def'], $ShipInfo['shield'],($newamount - $Amount)
      100. );
      101. }
      102. $DATA['rounds'][$Round]['defender'][] = $playerData;
      103. }
      104. if ($Round >= MAX_ATTACK_ROUNDS || $Destroy['att'] == count($RoundInfo['attackers']) || $Destroy['def'] == count($RoundInfo['defenders']))
      105. break;
      106. if(isset($RoundInfo['attack'], $RoundInfo['attackShield'], $RoundInfo['defense'], $RoundInfo['defShield']))
      107. $DATA['rounds'][$Round]['info'] = array($RoundInfo['attack'], $RoundInfo['attackShield'], $RoundInfo['defense'], $RoundInfo['defShield']);
      108. else
      109. $DATA['rounds'][$Round]['info'] = array(NULL, NULL, NULL, NULL);
      110. }
      111. return $DATA;
      112. }
      Display All

      changed line 83 and line 108 with

      $newamount = isset($combatResult['rw'][$Round + 1]['attackers'][$FleetID]['unit'][$ShipID]) ? $combatResult['rw'][$Round + 1]['attackers'][$FleetID]['unit'][$ShipID] : $Amount;

      $playerData['ships'][$ShipID] = array(
      $Amount, $ShipInfo['att'], $ShipInfo['def'], $ShipInfo['shield'],($newamount - $Amount)
      );

      and



      $newamount = isset($combatResult['rw'][$Round + 1]['defenders'][$FleetID]['unit'][$ShipID]) ? $combatResult['rw'][$Round + 1]['defenders'][$FleetID]['unit'][$ShipID] : $Amount;

      $playerData['ships'][$ShipID] = array(
      $Amount, $ShipInfo['att'], $ShipInfo['def'], $ShipInfo['shield'],($newamount - $Amount)
      );

      this shall record the units lost
      ------------------------------------------------------
      then i changed

      styles/templates/game/shared.mission.raport.tpl

      since i dont know how your file looks like, i only describe how to change it
      in the line where your battlereport shows the amount of a shipstype in this round, add

      HTML Source Code

      1. {if isset($ShipData[4]) and $ShipData[4] != 0} (<span style="color:red" rel="color:red"> {$ShipData[4]|number}</span>){/if}
      isset is used for old reports that don't own the value jet. and it shall not be shown, when it is 0.
      if your file is like the original 1.8 you will have to change lines als follows.
      line 37 into
      <td class="transparent">{$ShipData[0]|number}{if isset($ShipData[4]) and $ShipData[4] != 0} (<span style="color:red"> {$ShipData[4]|number}</span>){/if}</td>
      and line 95 into
      <td class="transparent">{$ShipData[0]|number}{if isset($ShipData[4]) and $ShipData[4] != 0} (<span style="color:red"> {$ShipData[4]|number}</span>){/if}</td>


      hope it works for you.
      didn't tested it much.
    • other aproach only changing one file:
      styles/templates/game/shared.mission.raport.tpl

      Smarty-Template

      1. {foreach $RoundInfo.attacker as $key => $Player}

      Smarty-Template

      1. <td class="transparent">{$ShipData[0]|number}{if isset($Raport["rounds"][$Round +1]["attacker"][$key]["ships"][$ShipID][0]) and ($Raport["rounds"][$Round +1]["attacker"][$key]["ships"][$ShipID][0] - $ShipData[0]) != 0}<span style="color:red"> {$Raport["rounds"][$Round +1]["attacker"][$key]["ships"][$ShipID][0] - $ShipData[0]|number}</span>{/if}</td>

      Smarty-Template

      1. {foreach $RoundInfo.defender as $key => $Player}

      Smarty-Template

      1. <td class="transparent">{$ShipData[0]|number}{if isset($Raport["rounds"][$Round +1]["defender"][$key]["ships"][$ShipID][0]) and ($Raport["rounds"][$Round +1]["defender"][$key]["ships"][$ShipID][0] - $ShipData[0]) != 0}<span style="color:red"> {$Raport["rounds"][$Round +1]["defender"][$key]["ships"][$ShipID][0] - $ShipData[0]|number}</span>{/if}</td>
      lines are for this version of the file
      github.com/jkroepke/2Moons/blo…shared.mission.raport.tpl

      edit:there wa a little mistake
      changed line 37 and 95