/nacridan/map/scripts-initialisation/createCityBuildings.php

https://gitlab.com/nacridan/Nacridan · PHP · 214 lines · 143 code · 59 blank · 12 comment · 36 complexity · 8af6f5ad6c8c435497df513ce5e64fba MD5 · raw file

  1. <?php
  2. require_once ("../conf/config.ini.php");
  3. require_once (HOMEPATH . "/lib/DB.inc.php");
  4. require_once (HOMEPATH . "/lib/utils.inc.php");
  5. require_once (HOMEPATH . "/lib/MapInfo.inc.php");
  6. $db = DB::getDB();
  7. set_time_limit(300);
  8. // Choix de la carte
  9. $map = 1;
  10. function getBuildingCoord($idCity, $X, $Y, $map, $distX, $distY, $mapinfo, $logfile, $db)
  11. {
  12. $possiblePosition = array();
  13. for ($i = 0; $i < 11; $i ++) {
  14. for ($j = 0; $j < 11; $j ++) {
  15. $Xtest = $X - 5 + $i;
  16. $Ytest = $Y - 5 + $j;
  17. $validzone = $mapinfo->getValidMap($Xtest, $Ytest, 0, $map);
  18. $freePlace = 1;
  19. $dbp = new DBCollection("SELECT id FROM Building WHERE x=" . $Xtest . " AND y=" . $Ytest . " AND map=" . $map, $db);
  20. if (! $dbp->eof())
  21. $freePlace = 0;
  22. if ($validzone[0][0] && $freePlace && (distHexa($X, $Y, $Xtest, $Ytest) < 4))
  23. $possiblePosition[] = array(
  24. "x" => $Xtest,
  25. "y" => $Ytest
  26. );
  27. }
  28. }
  29. if (count($possiblePosition) == 0) {
  30. fputs($logfile, "\nPROBLEME DE PLACE DANS LE BOURG id= ");
  31. fputs($logfile, $idCity . " validzone= " . $validzone[0][0] . " freePlace=" . $freePlace . "\n");
  32. return 0;
  33. }
  34. $randKey = array_rand($possiblePosition);
  35. return $possiblePosition[$randKey];
  36. }
  37. $mapinfo = new MapInfo($db);
  38. // ----- Bâtiments des Bourgs
  39. $logfile = fopen('buildingcreation.log', 'a');
  40. $dbc = new DBCollection("SELECT id,x,y FROM City WHERE type='Bourg' AND map=" . $map, $db, 0, 0);
  41. fputs($logfile, "Bourgs récupérés \n");
  42. while (! $dbc->eof()) {
  43. // ---- Création du temple, centre du bourg
  44. $X = $dbc->get("x");
  45. $Y = $dbc->get("y");
  46. $dbi = new DBCollection("INSERT INTO `Building` (`name`, `id_BasicBuilding`, `id_City`, `id_Player`, `sp`, `currsp`, `x`, `y`, `map`) VALUES
  47. ('Temple', 14, " . $dbc->get("id") . ", 0, 100, 100, " . $X . ", " . $Y . ", " . $map . ")", $db, 0, 0);
  48. echo '</br>Bourg ';
  49. echo $dbc->get("id") . "</br>";
  50. fputs($logfile, "\n Village id= ");
  51. fputs($logfile, $dbc->get("id"));
  52. fputs($logfile, "\n Temple créé ");
  53. // Coordonnées de l'auberge, proche du temple
  54. $coord = getBuildingCoord($dbc->get("id"), $X, $Y, $map, 1, 1, $mapinfo, $logfile, $db);
  55. if ($coord != 0) {
  56. $Xtest = $coord["x"];
  57. $Ytest = $coord["y"];
  58. $dbi = new DBCollection("INSERT INTO `Building` (`name`, `id_BasicBuilding`, `id_City`, `id_Player`, `sp`, `currsp`, `x`, `y`, `map`) VALUES
  59. ('Auberge', 1, " . $dbc->get("id") . ", 0, 100, 100, " . $Xtest . ", " . $Ytest . ", " . $map . ")", $db, 0, 0);
  60. fputs($logfile, "\n Auberge créée ");
  61. } else {
  62. fputs($logfile, "\n Il manque une Auberge ");
  63. }
  64. // Coordonnées de l'échoppe
  65. $coord = getBuildingCoord($dbc->get("id"), $X, $Y, $map, 3, 3, $mapinfo, $logfile, $db);
  66. if ($coord != 0) {
  67. $Xtest = $coord["x"];
  68. $Ytest = $coord["y"];
  69. $dbi = new DBCollection("INSERT INTO `Building` (`name`, `id_BasicBuilding`, `id_City`, `id_Player`, `sp`, `currsp`, `x`, `y`, `map`) VALUES
  70. ('Échoppe', 5, " . $dbc->get("id") . ", 0, 100, 100, " . $Xtest . ", " . $Ytest . ", " . $map . ")", $db, 0, 0);
  71. fputs($logfile, "\n Echope créée ");
  72. } else {
  73. fputs($logfile, "\n Il manque une Echope ");
  74. }
  75. // Coordonnées de la guilde des Artisans
  76. $coord = getBuildingCoord($dbc->get("id"), $X, $Y, $map, 3, 3, $mapinfo, $logfile, $db);
  77. if ($coord != 0) {
  78. $Xtest = $coord["x"];
  79. $Ytest = $coord["y"];
  80. $dbi = new DBCollection("INSERT INTO `Building` (`name`, `id_BasicBuilding`, `id_City`, `id_Player`, `sp`, `currsp`, `x`, `y`, `map`) VALUES
  81. ('Guilde des Artisans', 9, " . $dbc->get("id") . ", 0, 100, 100, " . $Xtest . ", " . $Ytest . ", " . $map . ")", $db, 0, 0);
  82. fputs($logfile, "\n Guilde des Artisans créée ");
  83. } else {
  84. fputs($logfile, "\n Il manque une Guilde des Artisans ");
  85. }
  86. // Coordonnées de l'école des métiers
  87. $coord = getBuildingCoord($dbc->get("id"), $X, $Y, $map, 3, 3, $mapinfo, $logfile, $db);
  88. if ($coord != 0) {
  89. $Xtest = $coord["x"];
  90. $Ytest = $coord["y"];
  91. $dbi = new DBCollection("INSERT INTO `Building` (`name`, `id_BasicBuilding`, `id_City`, `id_Player`, `sp`, `currsp`, `x`, `y`, `map`) VALUES
  92. ('École des Métiers', 8, " . $dbc->get("id") . ", 0, 100, 100, " . $Xtest . ", " . $Ytest . ", " . $map . ")", $db, 0, 0);
  93. fputs($logfile, "\n École des Métiers créée ");
  94. } else {
  95. fputs($logfile, "\n Il manque une École des Métiers ");
  96. }
  97. // Coordonnées de la maison
  98. $coord = getBuildingCoord($dbc->get("id"), $X, $Y, $map, 4, 4, $mapinfo, $logfile, $db);
  99. if ($coord != 0) {
  100. $Xtest = $coord["x"];
  101. $Ytest = $coord["y"];
  102. $dbi = new DBCollection("INSERT INTO `Building` (`name`, `id_BasicBuilding`, `id_City`, `id_Player`, `sp`, `currsp`, `x`, `y`, `map`) VALUES
  103. ('Maison', 10, " . $dbc->get("id") . ", 0, 100, 100, " . $Xtest . ", " . $Ytest . ", " . $map . ")", $db, 0, 0);
  104. fputs($logfile, "\n Maison créée ");
  105. } else {
  106. fputs($logfile, "\n Il manque une Maison ");
  107. }
  108. // Coordonnées de la maison
  109. $coord = getBuildingCoord($dbc->get("id"), $X, $Y, $map, 4, 4, $mapinfo, $logfile, $db);
  110. if ($coord != 0) {
  111. $Xtest = $coord["x"];
  112. $Ytest = $coord["y"];
  113. $dbi = new DBCollection("INSERT INTO `Building` (`name`, `id_BasicBuilding`, `id_City`, `id_Player`, `sp`, `currsp`, `x`, `y`, `map`) VALUES
  114. ('Maison', 10, " . $dbc->get("id") . ", 0, 100, 100, " . $Xtest . ", " . $Ytest . ", " . $map . ")", $db, 0, 0);
  115. fputs($logfile, "\n Maison créée ");
  116. } else {
  117. fputs($logfile, "\n Il manque une Maison ");
  118. }
  119. // Coordonnées de la maison
  120. $coord = getBuildingCoord($dbc->get("id"), $X, $Y, $map, 4, 4, $mapinfo, $logfile, $db);
  121. if ($coord != 0) {
  122. $Xtest = $coord["x"];
  123. $Ytest = $coord["y"];
  124. $dbi = new DBCollection("INSERT INTO `Building` (`name`, `id_BasicBuilding`, `id_City`, `id_Player`, `sp`, `currsp`, `x`, `y`, `map`) VALUES
  125. ('Maison', 10, " . $dbc->get("id") . ", 0, 100, 100, " . $Xtest . ", " . $Ytest . ", " . $map . ")", $db, 0, 0);
  126. fputs($logfile, "\n Maison créée ");
  127. } else {
  128. fputs($logfile, "\n Il manque une Maison ");
  129. }
  130. // Coordonnées de la maison
  131. $coord = getBuildingCoord($dbc->get("id"), $X, $Y, $map, 4, 4, $mapinfo, $logfile, $db);
  132. if ($coord != 0) {
  133. $Xtest = $coord["x"];
  134. $Ytest = $coord["y"];
  135. $dbi = new DBCollection("INSERT INTO `Building` (`name`, `id_BasicBuilding`, `id_City`, `id_Player`, `sp`, `currsp`, `x`, `y`, `map`) VALUES
  136. ('Maison', 10, " . $dbc->get("id") . ", 0, 100, 100, " . $Xtest . ", " . $Ytest . ", " . $map . ")", $db, 0, 0);
  137. fputs($logfile, "\n Maison créée \n");
  138. } else {
  139. fputs($logfile, "\n Il manque une Maison \n ");
  140. }
  141. // Coordonnées du Comptoir de Commerce
  142. $coord = getBuildingCoord($dbc->get("id"), $X, $Y, $map, 4, 4, $mapinfo, $logfile, $db);
  143. if ($coord != 0) {
  144. $Xtest = $coord["x"];
  145. $Ytest = $coord["y"];
  146. $dbi = new DBCollection("INSERT INTO `Building` (`name`, `id_BasicBuilding`, `id_City`, `id_Player`, `sp`, `currsp`, `x`, `y`, `map`) VALUES
  147. ('Comptoir Commercial', 4, " . $dbc->get("id") . ", 0, 100, 100, " . $Xtest . ", " . $Ytest . ", " . $map . ")", $db, 0, 0);
  148. fputs($logfile, "\n Comptoir créé \n");
  149. } else {
  150. fputs($logfile, "\n Il manque le comptoir de commerce \n ");
  151. }
  152. $dbc->next();
  153. }
  154. fclose($logfile);
  155. ?>