<?
	$im_battle=@imagecreatefromgif (Inc("battle.gif"));
	for ($p=1; $p<=$userlin; $p++) {
		$fnsave_gfx="Move ".$p."-".$game.".csv";
		$fnsave_gfx = $basedir.$metoobasedir.'turn/moves/'.$fnsave_gfx;

		if (file_exists($fnsave_gfx)) {
			$moveexist[$p]=true;
			$fp_gfx = fopen ($fnsave_gfx, "r");
			if (filesize($fnsave_gfx)>0) { $movelist_gfx = fread($fp_gfx, filesize($fnsave_gfx)); }
			fclose($fp_gfx);
			Decrunch($movelist_gfx);
			$movefound=true;
#			echo "found<br>".$movelist."<br>";
		
			for ($j=1; $j<=$lin; $j++) {
				$move_player_gfx[$p][$j]=$cell[$j][1];
				$move_type_gfx[$p][$j]=$cell[$j][2];
				$move_people_gfx[$p][$j]=$cell[$j][3];
				$move_details_gfx[$p][$j]=$cell[$j][4];
				for ($i=5; $i<=$col; $i++) {
					$move_turn_gfx[$p][$j][$i-4]=$cell[$j][$i];
				}
			}
			$movelin[$p]=$lin;
		}
	}
	
	function addLine($p,$j) {
		global $move_player_gfx, $move_turn_gfx;
		global $mapcell, $im2, $im_battle, $color, $nb_turnahead;

		for ($i=2; $i<=$nb_turnahead+1; $i++) {
			if (($move_turn_gfx[$p][$j][$i-1]!="") && ($move_turn_gfx[$p][$j][$i]!="")) {
				$x=substr($move_turn_gfx[$p][$j][$i-1],0,2);
				$x1=$x*$mapcell;
				$y=substr($move_turn_gfx[$p][$j][$i-1],2,2);
				$y1=$y*$mapcell;
				$y1-=($mapcell/10);
				if (1&$y) { $x1-=$mapcell/2;}
							
				$x=substr($move_turn_gfx[$p][$j][$i],0,2);
				$x2=$x*$mapcell;
					$y=substr($move_turn_gfx[$p][$j][$i],2,2);
				$y2=$y*$mapcell;
				$y2-=($mapcell/10);
				if (1&$y) { $x2-=$mapcell/2;}
#				echo "line $x1,$y1 to $x2,$y2<br>";
				imagesetthickness($im2,$nb_turnahead-$i+1+1);
				imageline($im2, $x1, $y1, $x2, $y2, $color[$move_player_gfx[$p][$j]]);
				imageellipse($im2, $x2, $y2, 5, 5, $color[$move_player_gfx[$p][$j]]);
	
				if (substr($move_turn_gfx[$p][$j][$i],4,1)=="b") {
					imagecopy($im2,$im_battle, $x2-6, $y2-6,0,0,13,13);
				}
			}
		}
	}
	
	function assignNewImage() {
		global $im2, $colorT, $color;

		$im2=@imagecreatefromgif (Inc("emptymask.gif"));
		$colorT=imagecolortransparent($im2);
		$color[1] = ImageColorAllocate($im2, 0, 192, 0);
		$color[2] = ImageColorAllocate($im2, 0, 0, 255);
		$color[3] = ImageColorAllocate($im2, 255, 0, 0);
	}
	
	function saveImage($fnimage) {
		global $im2, $colorT, $basedir;
		
		imagecolortransparent($im2, $colorT);
		imagegif($im2, $basedir.$metoobasedir.'turn/moves/'.$fnimage);
		imagedestroy($im2);
	}

	# create player moves image
	assignNewImage();
	$p=$user;
	for ($j=1; $j<=$movelin[$p]; $j++) {
		addLine($p, $j);
	}
	saveImage("move-".$user."-".$game.".gif");

	# create or update suggested moves for one race
	for ($r=1; $r<=25; $r++) {
		$foundany=false;
		for ($p=1; $p<=$userlin; $p++) {
			if ($moveexist[$p]) {
				for ($j=1; $j<=$movelin[$p]; $j++) {
					if (($move_people_gfx[$p][$j]==$r) && ($move_player_gfx[$p][$j]==2) && ($move_type_gfx[$p][$j]==1)) {
						if (!$foundany) {
							assignNewImage();
						}
						$foundany=true;
						addLine($p, $j);
					}
				}
			}
		}
		if ($foundany) {
			saveImage("move-sugg".$r."-".$game.".gif");
		}
	}

	# create or update all planned moves
	assignNewImage();
	for ($p=1; $p<=$userlin; $p++) {
		if ($moveexist[$p]) {
			for ($j=1; $j<=$movelin[$p]; $j++) {
				if (($move_player_gfx[$p][$j]==1) && ($move_type_gfx[$p][$j]==1)) {
					addLine($p, $j);
				}
			}
		}
	}
	saveImage("move-allplanned-".$game.".gif");

	# create or update all supposed enemy moves
	assignNewImage();
	$foundany=false;
	for ($p=1; $p<=$userlin; $p++) {
		if ($moveexist[$p]) {
			for ($j=1; $j<=$movelin[$p]; $j++) {
				if (($move_player_gfx[$p][$j]==3) && ($move_type_gfx[$p][$j]==1)) {
					if (!$foundany) {
						assignNewImage();
					}
					$foundany=true;
					addLine($p, $j);
				}
			}
		}
	}
	if ($foundany) {
		saveImage("move-allenemy-".$game.".gif");
	}
?>