PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/functions/CreateOneMoonRecord.php

https://bitbucket.org/VolCh/2moons
PHP | 81 lines | 48 code | 8 blank | 25 comment | 5 complexity | 782b668dd4a1ba626eb13908af27d9fa MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, GPL-3.0, GPL-2.0, Apache-2.0, AGPL-3.0
  1. <?php
  2. /**
  3. * 2Moons
  4. * Copyright (C) 2012 Jan Kröpke
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * @package 2Moons
  20. * @author Jan Kröpke <info@2moons.cc>
  21. * @copyright 2012 Jan Kröpke <info@2moons.cc>
  22. * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
  23. * @version 1.7.1 (2013-01-18)
  24. * @info $Id$
  25. * @link http://2moons.cc/
  26. */
  27. function CreateOneMoonRecord($Galaxy, $System, $Planet, $Universe, $Owner, $MoonName, $Chance, $time = 0, $Size = 0)
  28. {
  29. global $USER;
  30. $SQL = "SELECT id_luna,planet_type,id,name,temp_max,temp_min FROM ".PLANETS." ";
  31. $SQL .= "WHERE ";
  32. $SQL .= "universe = '".$Universe."' AND ";
  33. $SQL .= "galaxy = '".$Galaxy."' AND ";
  34. $SQL .= "system = '".$System."' AND ";
  35. $SQL .= "planet = '".$Planet."' AND ";
  36. $SQL .= "planet_type = '1';";
  37. $MoonPlanet = $GLOBALS['DATABASE']->getFirstRow($SQL);
  38. if ($MoonPlanet['id_luna'] != 0)
  39. return false;
  40. if($Size == 0) {
  41. $size = floor(pow(mt_rand(10, 20) + 3 * $Chance, 0.5) * 1000); # New Calculation - 23.04.2011
  42. } else {
  43. $size = $Size;
  44. }
  45. $maxtemp = $MoonPlanet['temp_max'] - mt_rand(10, 45);
  46. $mintemp = $MoonPlanet['temp_min'] - mt_rand(10, 45);
  47. $GLOBALS['DATABASE']->multi_query("INSERT INTO ".PLANETS." SET
  48. name = '".$MoonName."',
  49. id_owner = ".$Owner.",
  50. universe = ".$Universe.",
  51. galaxy = ".$Galaxy.",
  52. system = ".$System.",
  53. planet = ".$Planet.",
  54. last_update = ".TIMESTAMP.",
  55. planet_type = '3',
  56. image = 'mond',
  57. diameter = ".$size.",
  58. field_max = '1',
  59. temp_min = ".$mintemp.",
  60. temp_max = ".$maxtemp.",
  61. metal = 0,
  62. metal_perhour = 0,
  63. crystal = 0,
  64. crystal_perhour = 0,
  65. deuterium = 0,
  66. deuterium_perhour = 0;
  67. SET @moonID = LAST_INSERT_ID();
  68. UPDATE ".PLANETS." SET
  69. id_luna = @moonID
  70. WHERE
  71. id = ".$MoonPlanet['id'].";");
  72. return true;
  73. }