Harvest Mood 1.8

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

    • I think I have posted that already but here it goes.

      I, personally, like to use this on Empire page.

      PHP Source Code

      1. private function HarvestResources($Harvest) {
      2. global $USER, $PLANET, $resource, $pricelist, $LNG;
      3. /**/ // Attack
      4. $AttackCount = Database::get()->selectSingle("SELECT COUNT(*) as count FROM %%FLEETS%% WHERE fleet_target_owner = :id AND (fleet_mission = 1 OR fleet_mission = 2 OR fleet_mission = 9) AND fleet_start_time > :timestamp;", array(
      5. ':id' => $USER['id'],
      6. ':timestamp' => TIMESTAMP,
      7. ), 'count');
      8. if ($AttackCount > 0)
      9. {
      10. $this->printMessage('While under foreign enemy activity, you can not use this function', array(
      11. array(
      12. 'label' => $LNG['sys_back'],
      13. 'url' => 'game.php?page=imperium'
      14. )
      15. ));
      16. }
      17. if ($Harvest == 1) // All
      18. {
      19. $TakeFrom = "";
      20. }
      21. elseif ($Harvest == 2) // Planets only
      22. {
      23. $TakeFrom = "planet_type = '1' AND";
      24. }
      25. elseif ($Harvest == 3) // Planets only
      26. {
      27. $TakeFrom = "planet_type = '3' AND";
      28. }
      29. $SelectedPlanets = Database::get()->select("SELECT * FROM %%PLANETS%% WHERE " . $TakeFrom . " id_owner = :id_owner AND id != :id;", array(
      30. ':id_owner' => $USER['id'],
      31. ':id' => $PLANET['id'],
      32. ));
      33. foreach ($SelectedPlanets as $CPLANET) {
      34. $planetUpdater = new ResourceUpdate();
      35. list($USER, $CPLANET) = $planetUpdater->CalcResource($USER, $CPLANET);
      36. }
      37. $TotalResourceSQL = "SELECT SUM(metal) as metal, SUM(crystal) as crystal,SUM(deuterium) as deuterium FROM %%PLANETS%% WHERE " . $TakeFrom . " id_owner = :id_owner AND id != :id ;";
      38. $Resource = Database::get()->selectSingle($TotalResourceSQL, array(
      39. ':id_owner' => $USER['id'],
      40. ':id' => $PLANET['id'],
      41. ));
      42. $PLANET[$resource[901]] += $Resource['metal'];
      43. $PLANET[$resource[902]] += $Resource['crystal'];
      44. $PLANET[$resource[903]] += $Resource['deuterium'];
      45. Database::get()->update("UPDATE %%PLANETS%% SET metal = 0, crystal = 0, deuterium = 0 WHERE " . $TakeFrom . " id_owner = :id_owner AND id != :id ;", array(
      46. ':id_owner' => $USER['id'],
      47. ':id' => $PLANET['id'],
      48. ));
      49. $this->printMessage($LNG['err_imperium_hr_success'], array(
      50. array(
      51. 'label' => $LNG['sys_back'],
      52. 'url' => 'game.php?page=imperium'
      53. )
      54. ));
      55. }
      Display All

      function Show to be loaded after post on

      Source Code

      1. $Harvest = HTTP::_GP('harvest', '');
      2. if (!empty($Harvest) && $_SERVER['REQUEST_METHOD'] === 'POST' && $USER['urlaubs_modus'] == 0) {
      3. $this->HarvestResources($Harvest);
      4. }
      5. /* ...... before Empire page foreach */
      6. $ResourcesToHarvest = array(
      7. 0 => array(
      8. 901 => 0,
      9. 902 => 0,
      10. 903 => 0
      11. ) ,
      12. 1 => array(
      13. 901 => 0,
      14. 902 => 0,
      15. 903 => 0
      16. ) ,
      17. 3 => array(
      18. 901 => 0,
      19. 902 => 0,
      20. 903 => 0
      21. ) ,
      22. );
      23. /* inside Empire page planet foreach */
      24. // Harvester
      25. $ResourcesToHarvest[0][901] += $CPLANET[$resource[901]];
      26. $ResourcesToHarvest[0][902] += $CPLANET[$resource[902]];
      27. $ResourcesToHarvest[0][903] += $CPLANET[$resource[903]];
      28. if ($CPLANET['planet_type'] == 1) {
      29. $ResourcesToHarvest[1][901] += $CPLANET[$resource[901]];
      30. $ResourcesToHarvest[1][902] += $CPLANET[$resource[902]];
      31. $ResourcesToHarvest[1][903] += $CPLANET[$resource[903]];
      32. }
      33. elseif ($CPLANET['planet_type'] == 3) {
      34. $ResourcesToHarvest[3][901] += $CPLANET[$resource[901]];
      35. $ResourcesToHarvest[3][902] += $CPLANET[$resource[902]];
      36. $ResourcesToHarvest[3][903] += $CPLANET[$resource[903]];
      37. }
      38. /* in $tpl->assign */
      39. 'ResourcesToHarvest' => $ResourcesToHarvest,
      Display All
      on TPL

      Source Code

      1. <div id='HarvestResource' class='modal-demo'>
      2. <button type='button' class='close' onclick='Custombox.close();'>
      3. <span>×</span><span class='sr-only'>Close</span>
      4. </button>
      5. <h4 class='custom-modal-title'>{$LNG.btn_imperium_1}</h4>
      6. <div class='custom-modal-text'>
      7. <table class="table table-dark">
      8. <form action="game.php?page=imperium" method="post" >
      9. <thead>
      10. <tr>
      11. <th></th>
      12. <th>{$LNG.cr_type}</th>
      13. <th>{$LNG.tech.901}</th>
      14. <th>{$LNG.tech.902}</th>
      15. <th>{$LNG.tech.903}</th>
      16. </tr>
      17. </thead>
      18. <tbody>
      19. <tr>
      20. <th scope="row"><input name="harvest" id="type0" type="radio" value="1" checked="checked"></th>
      21. <th scope="row">All</th>
      22. <td>{$ResourcesToHarvest.0.901|number}</td>
      23. <td>{$ResourcesToHarvest.0.902|number}</td>
      24. <td>{$ResourcesToHarvest.0.903|number}</td>
      25. </tr>
      26. <tr>
      27. <th scope="row"><input name="harvest" id="type1" type="radio" value="2"></th>
      28. <th scope="row">{$LNG.type_planet_1}</th>
      29. <td>{$ResourcesToHarvest.1.901|number}</td>
      30. <td>{$ResourcesToHarvest.1.902|number}</td>
      31. <td>{$ResourcesToHarvest.1.903|number}</td>
      32. </tr>
      33. <tr>
      34. <th scope="row"><input name="harvest" id="type3" type="radio" value="3"></th>
      35. <th scope="row">{$LNG.type_planet_3}</th>
      36. <td>{$ResourcesToHarvest.3.901|number}</td>
      37. <td>{$ResourcesToHarvest.3.902|number}</td>
      38. <td>{$ResourcesToHarvest.3.903|number}</td>
      39. </tr>
      40. <tr>
      41. <td colspan="5"><button type="submit" class="btn btn-xs btn-primary col-12">{$LNG.gl_collect}</button></td>
      42. </tr>
      43. </tbody>
      44. </form>
      45. </table>
      46. </div>
      47. </div>
      Display All

      The post was edited 1 time, last by Qwa ().

    • This harvest all the resources from colony and transport resources to your chosen planet ?
    • Yes, since Harvester function deposit all resources to $PLANET from selected source ($TakeFrom)

      The post was edited 1 time, last by Qwa ().

    • Thanks will check this out, i have made this in my gam, but there is some problem on sending transport fleet, and I am to lazy to search for bug :D
      Will give a test to your code. Thanks
    • Tell me your error.

      EDIT: removed "Megastructure" vars to avoid errors since it's from my game. Should work now.