<commit_before><?php
/**
 * @file interf_carte.class.php
 * Classes pour la partie gauche de l'interface
 */  

/// Classe pour afficher la carte du jeu
class interf_carte extends interf_tableau
{
  const aff_royaumes = 0x1;
  const aff_atmosphere = 0x2;
  const aff_jour = 0x4;
  const aff_monstres = 0x8;
  const aff_pcb = 0x10;
  const aff_cbp = 0x20;
  const aff_cpb = 0x30;
  const aff_pnj = 0x40;
  const aff_ads = 0x80;
  const aff_diplo_af = 0x000;
  const aff_diplo_a = 0x100;
  const aff_diplo_p = 0x200;
  const aff_diplo_pd = 0x300;
  const aff_diplo_bt = 0x400;
  const aff_diplo_n = 0x500;
  const aff_diplo_mt = 0x600;
  const aff_diplo_g = 0x700;
  const aff_diplo_gd = 0x800;
  const aff_diplo_e = 0x900;
  const aff_diplo_ee = 0xa00;
  const aff_diplo_vr = 0xb00;
  const aff_diplo_sup = 0x1000;
  const act_sons = 0x2000;
  const aff_petit = 0x4000;
  const aff_restreint = 0x8000; // seulement batiments du royaume
  const aff_lien_gest = 0x10000;
  const aff_defaut = 0x2b7e;
  /// @bug debuguer l'affichage des royaumes pour les petites textures et le remettre ici
  const aff_gestion = 0xc000;
  const aff_gest_bourgs = 0x18000;
  const aff_gest_batailles = 0x1c000;
  const aff_batailles = 0xc000;
  const masque_ordre = 0x30;
  const masque_diplo = 0xf00;

  protected $x_min;
  protected $x_max;
  protected $y_min;
  protected $y_max;
  protected $cases;
  protected $grd_img;
  protected $infos='';
  protected $diplos=array();
  protected $races=array();
  protected $doss_prefixe = '';

	function __construct($x, $y, $options=0x2b7e, $champ_vision=3, $id='carte', $niv_min=0, $niv_max=255, $parent_calques=null, &$reperes=null)
	{
    global $Tclasse, $Gcouleurs, $db, $Trace, $G_max_x, $G_max_y, $G_url;
    $this->grd_img = !($options & self::aff_petit);
		parent::__construct($id, $this->grd_img ? 'aide' : 'carte_petit', 'carte_bord_haut');
		
		if( strpos($G_url->get(),'roi/') !== false)
			$this->doss_prefixe = '../';	

    // Réduction de la vue en donjon
    if( $y > 190 )
    	$champ_vision--;

		$this->x_min = $x - $champ_vision;
		$this->x_max = $x + $champ_vision;
		$this->y_min = $y - $champ_vision;
		$this->y_max = $y + $champ_vision;
		
    // Bordure de carte
		if( $this->x_min <= 0 )
		{
			$this->x_max -= $this->x_min - 1;
			$this->x_min = 1;
		}
		else if( $x <= $G_max_x && $this->x_max > $G_max_x )
		{
			$this->x_min += $this->x_max - $G_max_x;
			$this->x_max = $G_max_x;
		}
		if( $this->y_min <= 0 )
		{
			$this->y_max -= $this->y_min - 1;
			$this->y_min = 1;
		}
		else if( $y <= $G_max_y && $this->y_max > $G_max_y )
		{
			$this->y_min += $this->y_max - $G_max_y;
			$this->y_max = $G_max_y;
		}		

		$cache = 75 <= $x && $x <= 100 && 288 <= $y && $y <= 305;
		// Bord haut
		$this->nouv_cell('&nbsp;', 'carte_bord_haut_gauche');
		if( $y > 190 )
			$this->nouv_cell('&nbsp;');
		for($j=$this->x_min; $j<=$this->x_max; $j++)
		{
			$c = $cache ? $j - $x : $j;
			$this->nouv_cell($c, $j==$x ? 'carte_bord_haut_x' : null);
		}
		if( $y > 190 )
		{
			$this->nouv_cell('&nbsp;');
			$this->nouv_ligne();
		}
		
		// On récupère les infos sur les cases
		$infos_cases = map::get_valeurs('decor,royaume,info,type', 'x >= '.$this->x_min.' AND x <= '.$this->x_max.' AND y >= '.$this->y_min.' AND y <= '.$this->y_max, array('x','y'));
    // Calques
    /// @todo à améliorer
    $req = $db->query("select * from map_type_calque");
    while($row = $db->read_object($req))
      $calques[$row->type] = $row;
		// Carte
		$tex = 'decor tex'.($this->grd_img ? '' : 'l');
		$this->cases = array();
		for($i=$this->y_min; $i<=$this->y_max; $i++)
		{
			$this->nouv_ligne();
			$c = $cache ? $i - $y : $i;
			$this->nouv_cell($c, $i==$y ? 'carte_bord_haut_y' : null, false, true);
			if( $y > 190 )
				$this->nouv_cell('&nbsp;');
		  $this->cases[$i] = array();
    	// calques terrain
			for($j=$this->x_min; $j<=$this->x_max; $j++)
			{
				$this->infos[$i][$j] = '';
				$case = !($options & self::aff_lien_gest) || $infos_cases[$j.'|'.$i]['royaume'] || $infos_cases[$j.'|'.$i]['info'] == 5 ? $tex.$infos_cases[$j.'|'.$i]['decor'] : '';
				$this->cases[$i][$j] = &$this->nouv_cell(null, null, $case);
        $type = $infos_cases[$j.'|'.$i]['type'];
        $pos = 'rel_'.($j-$x).'_'.($i-$y);
        if( $this->grd_img && array_key_exists($type, $calques) )
        {
          $calque = $this->cases[$i][$j]->add( new interf_bal_cont('div') );
      		$dx = (-$j + $map_type_calque->decalage_x) * 60;
      		$dy = (-$i + $map_type_calque->decalage_y) * 60;
          $style = 'background-image: url('.$this->doss_prefixe.'image/texture/'.$calques[$type]->calque.');';
          $style .= ' background-attachment: scroll; background-position: '.$dx.'px '.$dy.'px;';
          $style .= ' margin: -2px; height: 62px; width: 60px; background-repeat: repeat;';
          $calque->set_attribut('style', $style);
          $calque->add( new interf_bal_smpl('span', false, 'pos_'.$pos) );
        }
        else
          $this->cases[$i][$j]->add( new interf_bal_smpl('span', false, 'pos_'.$pos) );
			}
			if( $y > 190 )
				$this->nouv_cell('&nbsp;');
		}
		if( $y > 190 )
			$this->nouv_ligne();

    // Perso du joueur
	  $perso = joueur::get_perso();
    if( !($options & self::aff_restreint) )
    {
	    $div = $this->cases[$perso->get_y()][$perso->get_x()]->insert( new interf_bal_cont('div', null, 'carte_contenu') );
	    $img = $this->doss_prefixe.'image/personnage'.($this->grd_img?'':'_low').'/'.$perso->get_race().'/'.$perso->get_race().'_'.$Tclasse[$perso->get_classe()]['type'].'.png';
	    $div->set_attribut('style', 'background-image: url(\''.$img.'\');');
		}

    
    /// @todo calque atmosphere
    if( $parent_calques )
    {
	    if( $y > 190 ) // Calque donjon
	    {
	    	$image = $this->doss_prefixe.'image/interface/calque-atmosphere-noir'.($cache?'plannysin':'').'.png';
	    	$c_jour = $parent_calques->add( new interf_bal_smpl('div', false, false, 'calque') );
	    	$c_jour->set_attribut('style', 'background-image: url('.$image.');');
			}
			else
			{
				if( $options & self::aff_jour )
				{
		    	$image = $this->doss_prefixe.'image/interface/calque-atmosphere-vide-'.strtolower(moment_jour()).'.png';
		    	$c_donj = $parent_calques->add( new interf_bal_smpl('div', false, false, 'calque') );
		    	$c_donj->set_attribut('style', 'background-image: url('.$image.');');
				}
			}
		}

		
    // Éléments à afficher
    if( $options & self::aff_restreint )
    {
    	$cond_bat = 'royaume = '.$Trace[$perso->get_race()]['numrace'];
	    if($reperes)
	    {
	    	$this->afficher_reperes($reperes['action']);
	    	$this->afficher_bat_ennemi($reperes['batiment']);
			}
	    $this->afficher_placements($cond_bat);
	    $this->afficher_batiments($cond_bat, false);
		}
		else
		{
			// conditions
			$diplo = ($options & self::masque_diplo) >> 8;
			if( $diplo >= 11 )<commit_msg>* on remet les claques d'atmosphère<commit_after><?php
/**
 * @file interf_carte.class.php
 * Classes pour la partie gauche de l'interface
 */  

/// Classe pour afficher la carte du jeu
class interf_carte extends interf_tableau
{
  const aff_royaumes = 0x1;
  const aff_atmosphere = 0x2;
  const aff_jour = 0x4;
  const aff_monstres = 0x8;
  const aff_pcb = 0x10;
  const aff_cbp = 0x20;
  const aff_cpb = 0x30;
  const aff_pnj = 0x40;
  const aff_ads = 0x80;
  const aff_diplo_af = 0x000;
  const aff_diplo_a = 0x100;
  const aff_diplo_p = 0x200;
  const aff_diplo_pd = 0x300;
  const aff_diplo_bt = 0x400;
  const aff_diplo_n = 0x500;
  const aff_diplo_mt = 0x600;
  const aff_diplo_g = 0x700;
  const aff_diplo_gd = 0x800;
  const aff_diplo_e = 0x900;
  const aff_diplo_ee = 0xa00;
  const aff_diplo_vr = 0xb00;
  const aff_diplo_sup = 0x1000;
  const act_sons = 0x2000;
  const aff_petit = 0x4000;
  const aff_restreint = 0x8000; // seulement batiments du royaume
  const aff_lien_gest = 0x10000;
  const aff_defaut = 0x2b7e;
  /// @bug debuguer l'affichage des royaumes pour les petites textures et le remettre ici
  const aff_gestion = 0xc000;
  const aff_gest_bourgs = 0x18000;
  const aff_gest_batailles = 0x1c000;
  const aff_batailles = 0xc000;
  const masque_ordre = 0x30;
  const masque_diplo = 0xf00;

  protected $x_min;
  protected $x_max;
  protected $y_min;
  protected $y_max;
  protected $cases;
  protected $grd_img;
  protected $infos='';
  protected $diplos=array();
  protected $races=array();
  protected $doss_prefixe = '';

	function __construct($x, $y, $options=0x2b7e, $champ_vision=3, $id='carte', $niv_min=0, $niv_max=255, $parent_calques=null, &$reperes=null)
	{
    global $Tclasse, $Gcouleurs, $db, $Trace, $G_max_x, $G_max_y, $G_url;
    $this->grd_img = !($options & self::aff_petit);
		parent::__construct($id, $this->grd_img ? 'aide' : 'carte_petit', 'carte_bord_haut');
		
		if( strpos($G_url->get(),'roi/') !== false)
			$this->doss_prefixe = '../';	

    // Réduction de la vue en donjon
    if( $y > 190 )
    	$champ_vision--;

		$this->x_min = $x - $champ_vision;
		$this->x_max = $x + $champ_vision;
		$this->y_min = $y - $champ_vision;
		$this->y_max = $y + $champ_vision;
		
    // Bordure de carte
		if( $this->x_min <= 0 )
		{
			$this->x_max -= $this->x_min - 1;
			$this->x_min = 1;
		}
		else if( $x <= $G_max_x && $this->x_max > $G_max_x )
		{
			$this->x_min += $this->x_max - $G_max_x;
			$this->x_max = $G_max_x;
		}
		if( $this->y_min <= 0 )
		{
			$this->y_max -= $this->y_min - 1;
			$this->y_min = 1;
		}
		else if( $y <= $G_max_y && $this->y_max > $G_max_y )
		{
			$this->y_min += $this->y_max - $G_max_y;
			$this->y_max = $G_max_y;
		}		

		$cache = 75 <= $x && $x <= 100 && 288 <= $y && $y <= 305;
		// Bord haut
		$this->nouv_cell('&nbsp;', 'carte_bord_haut_gauche');
		if( $y > 190 )
			$this->nouv_cell('&nbsp;');
		for($j=$this->x_min; $j<=$this->x_max; $j++)
		{
			$c = $cache ? $j - $x : $j;
			$this->nouv_cell($c, $j==$x ? 'carte_bord_haut_x' : null);
		}
		if( $y > 190 )
		{
			$this->nouv_cell('&nbsp;');
			$this->nouv_ligne();
		}
		
		// On récupère les infos sur les cases
		$infos_cases = map::get_valeurs('decor,royaume,info,type', 'x >= '.$this->x_min.' AND x <= '.$this->x_max.' AND y >= '.$this->y_min.' AND y <= '.$this->y_max, array('x','y'));
    // Calques
    /// @todo à améliorer
    $req = $db->query("select * from map_type_calque");
    while($row = $db->read_object($req))
      $calques[$row->type] = $row;
		// Carte
		$tex = 'decor tex'.($this->grd_img ? '' : 'l');
		$this->cases = array();
		for($i=$this->y_min; $i<=$this->y_max; $i++)
		{
			$this->nouv_ligne();
			$c = $cache ? $i - $y : $i;
			$this->nouv_cell($c, $i==$y ? 'carte_bord_haut_y' : null, false, true);
			if( $y > 190 )
				$this->nouv_cell('&nbsp;');
		  $this->cases[$i] = array();
    	// calques terrain
			for($j=$this->x_min; $j<=$this->x_max; $j++)
			{
				$this->infos[$i][$j] = '';
				$case = !($options & self::aff_lien_gest) || $infos_cases[$j.'|'.$i]['royaume'] || $infos_cases[$j.'|'.$i]['info'] == 5 ? $tex.$infos_cases[$j.'|'.$i]['decor'] : '';
				$this->cases[$i][$j] = &$this->nouv_cell(null, null, $case);
        $type = $infos_cases[$j.'|'.$i]['type'];
        $pos = 'rel_'.($j-$x).'_'.($i-$y);
        if( $this->grd_img && array_key_exists($type, $calques) )
        {
          $calque = $this->cases[$i][$j]->add( new interf_bal_cont('div') );
      		$dx = (-$j + $map_type_calque->decalage_x) * 60;
      		$dy = (-$i + $map_type_calque->decalage_y) * 60;
          $style = 'background-image: url('.$this->doss_prefixe.'image/texture/'.$calques[$type]->calque.');';
          $style .= ' background-attachment: scroll; background-position: '.$dx.'px '.$dy.'px;';
          $style .= ' margin: -2px; height: 62px; width: 60px; background-repeat: repeat;';
          $calque->set_attribut('style', $style);
          $calque->add( new interf_bal_smpl('span', false, 'pos_'.$pos) );
        }
        else
          $this->cases[$i][$j]->add( new interf_bal_smpl('span', false, 'pos_'.$pos) );
			}
			if( $y > 190 )
				$this->nouv_cell('&nbsp;');
		}
		if( $y > 190 )
			$this->nouv_ligne();

    // Perso du joueur
	  $perso = joueur::get_perso();
    if( !($options & self::aff_restreint) )
    {
	    $div = $this->cases[$perso->get_y()][$perso->get_x()]->insert( new interf_bal_cont('div', null, 'carte_contenu') );
	    $img = $this->doss_prefixe.'image/personnage'.($this->grd_img?'':'_low').'/'.$perso->get_race().'/'.$perso->get_race().'_'.$Tclasse[$perso->get_classe()]['type'].'.png';
	    $div->set_attribut('style', 'background-image: url(\''.$img.'\');');
		}

    
    /// @todo calque atmosphere
    if( $parent_calques )
    {
	    if( $y > 190 ) // Calque donjon
	    {
	    	$image = $this->doss_prefixe.'image/interface/calque-atmosphere-noir'.($cache?'plannysin':'').'.png';
	    	$c_donj = $parent_calques->add( new interf_bal_smpl('div', false, false, 'calque') );
	    	$c_donj->set_attribut('style', 'background-image: url('.$image.');');
			}
			else
			{
				if( $options & self::aff_jour )
				{
		    	$image = $this->doss_prefixe.'image/interface/calque-atmosphere-vide-'.strtolower(moment_jour()).'.png';
		    	$c_jour = $parent_calques->add( new interf_bal_smpl('div', false, false, 'calque') );
		    	$c_jour->set_attribut('style', 'background-image: url('.$image.');');
				}
				if( $options & self::aff_atmosphere )
				{
					$requete = 'SELECT * FROM map_zone WHERE x1 < '.$this->x_max.' AND x2 > '.$this->x_min.' AND y1 < '.$this->y_max.' AND y2 > '.$this->y_min;
					$req = $db->query($requete);
					while( $row = $db->read_assoc($req) )
					{
			    	$image = $this->doss_prefixe.'image/interface/calque-atmosphere-'.$row['type'].'.png';
			    	$c_atm = $parent_calques->add( new interf_bal_smpl('div', false, false, 'calque') );
			    	$dx = ($this->x_min - $row['x1'])*60;
			    	$dy = ($this->y_min - $row['y1'])*60;
			    	$larg = (min($row['x2'], $this->x_max) - $this->x_min + 1) * 60;
			    	$haut = (min($row['y2'], $this->y_max) - $this->y_min + 1) * 60;
			    	$c_atm->set_attribut('style', 'background-image: url('.$image.'); background-repeat: repeat;background-position: '.$dx.'px '.$dy.'px; width:'.$larg.'px; height: '.$haut.'px;');
					}
				}
			}
		}

		
    // Éléments à afficher
    if( $options & self::aff_restreint )
    {
    	$cond_bat = 'royaume = '.$Trace[$perso->get_race()]['numrace'];
	    if($reperes)
	    {
	    	$this->afficher_reperes($reperes['action']);
	    	$this->afficher_bat_ennemi($reperes['batiment']);
			}
	    $this->afficher_placements($cond_bat);
	    $this->afficher_batiments($cond_bat, false);
		}
		else
		{
			// conditions
			$diplo = ($options & self::masque_diplo) >> 8;
			if( $diplo >= 11 )
{'fraction_non_alphanumeric': 0.21119662194374447, 'fraction_numerical': 0.026016481645440306, 'mean_word_length': 3.218328066647515, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 218, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5979637', 'n_tokens_mistral': 6898, 'n_tokens_neox': 6281, 'n_words': 1070}