0 && $posx + $GLOBALS->map->grid->view->x > $GLOBALS->map->grid->x)
$posx = $GLOBALS->map->grid->x - $GLOBALS->map->grid->view->x;
elseif ($posx < 0 && $posx - $GLOBALS->map->grid->view->x < -($GLOBALS->map->grid->x))
$posx = -($GLOBALS->map->grid->x) + $GLOBALS->map->grid->view->x;
if ($posy > 0 && $posy + $GLOBALS->map->grid->view->y > $GLOBALS->map->grid->y)
$posy = $GLOBALS->map->grid->y - $GLOBALS->map->grid->view->y;
elseif ($posy < 0 && $posy - $GLOBALS->map->grid->view->y < -($GLOBALS->map->grid->y))
$posy = -($GLOBALS->map->grid->y) + $GLOBALS->map->grid->view->y;
$return = Kernel_Api::joinScript(Kernel_Api::Plugins, "tooltips").Kernel_Api::joinScript(Kernel_Api::AppGame, "map");
$return .= "";
$return .= self::event_html(self::event_select($posx, $posy), $posx, $posy);
if (isset($post))
exit($return);
return $return;
}
/**
* Récupérer les actions possibles lors d'un clic sur une case de la map.
* @param POST $x
* @param POST $y
*/
public function action() {
autoload_sql("map");
$_SESSION["map"] = (object) array(
"cursor" => (object) array(
"x" => (int) post("x"),
"y" => (int) post("y")
));
$html = Kernel_Api::joinScript(Kernel_Api::AppGame, "map.action");
$case = self::event_select_by_coord($_SESSION["map"]->cursor->x, $_SESSION["map"]->cursor->y);
if ($case != array()) {
if (self::is_current($case->vid))
$html .= Game_Build::propose($case->bid);
else {
}
}
else {
echo "
Oups, aucune action possible
";
}
echo $html;
}
/**
* Générer aléatoirement des positions pour les villages (SANS COLLISIONS)
* - On calcul d'abord les coordonnées de base en respectant les marges imposées par la configuration
* - On boucle toutes les positions en générant des variantes de point
* - On parcours tous les points généré
* - On insert dans la base de données
* - On créé le fichier XML associé contenant les zones de constructions ayant pour origine ce point
*/
public static function event_create_point() {
$startx = $tmpx = -($GLOBALS->map->grid->x) + $GLOBALS->map->create->fixed;
$starty = $tmpy = -($GLOBALS->map->grid->y) + $GLOBALS->map->create->fixed;
$endx = $GLOBALS->map->grid->x - $GLOBALS->map->create->fixed;
$endy = $GLOBALS->map->grid->y - $GLOBALS->map->create->fixed;
$map_points = array();
while (true) {
if ($tmpx > $endx) {
if (($tmpy += $GLOBALS->map->create->fixed) > $endy)
break;
$tmpx = $startx;
continue;
}
$map_points[$tmpx + mt_rand(-(floor($GLOBALS->map->create->rand / 2)), floor($GLOBALS->map->create->rand / 2))][$tmpy + mt_rand(-(floor($GLOBALS->map->create->rand / 2)), floor($GLOBALS->map->create->rand / 2))] = "";
$tmpx += $GLOBALS->map->create->fixed;
}
foreach ($map_points as $x => &$value)
foreach (array_keys($value) as $y) {
Kernel_Sql::get()->exec(sprintf(sql_game_map_point_insert, $x, $y));
self::event_create_area($x, $y);
}
}
/**
* Compiler le fichier XML d'un village et l'insérer dans la base de données
* - On charge le fichier XML contenant les propriétés du village aux coordonnées $x et $y.
* - On prépare la requête de suppression (on supprime tous les éléments déjà en place)
* - On insert les nouveaux éléments du village.
* @param $x, $y, $vid, $mid
*/
public static function event_parse_area($x, $y, $vid) {
autoload_sql("map");
$mapfile = New SimpleXMLElement(file_get_contents(sprintf("%s%d,%d.xml", $GLOBALS->dir->xml->map, $x, $y)));
$sql_delete = $sql_insert = "";
foreach($mapfile->case as $case) {
$sql_delete .= " (posx = {$case['x']} && posy = {$case['y']}) ||";
$sql_insert .= " ({$case['x']}, {$case['y']}, ". (int) $vid .", '{$case}'),";
}
$request = Kernel_Sql::get()->exec(sprintf(sql_game_map_case_delete, (int) $vid, substr($sql_delete, 0, -2)) .";". sprintf(sql_game_map_case_insert, "VALUES". substr($sql_insert, 0, -1)));
}
/**
* Génère un décor aléatoire sur la map.
* @global array $config
*/
public static function event_rand(){
autoload_cfg("map");
autoload_sql("map");
autoload_models("map");
$x = -($GLOBALS->map->grid->x);
$y = -($GLOBALS->map->grid->y);
$end_x = $GLOBALS->map->grid->x;
$end_y = ($GLOBALS->map->grid->y);
while (true) {
$rand = mt_rand(1, 30);
if (isset($GLOBALS->map->rand[$rand]))
Kernel_Sql::get()->exec(sprintf(sql_game_map_rand_insert, $x, $y, $GLOBALS->map->rand[$rand][array_rand($GLOBALS->map->rand[$rand])]));
if ($x === $end_x && $y === $end_y)
break;
if ($x === $end_x) {
$x = -($GLOBALS->map->grid->x);
++$y;
}
++$x;
}
}
/**
* Compiler et assembler tous les éléments de la map.
* On vérifie qu'un élément existe
* - Si cet élément est celui du joueur
* - On vérifie si c'est un bâtiment
* - Si c'est la muraille et que le niveau est à 0, on ne l'affiche pas
* - Si c'est un élément naturel, on propose de construire le bâtiment adéquat
* - Si c'est un bâtiment, on affiche son niveau
* - On propose de construire un bâtiment
* - Si cela appartient à un autre joueur
* -
* - Sinon c'est un élément naturel
* - On détermine l'élément et on affiche les informations adéquates
* @param