<?php
include_once('mapcfg.php');

$x = $dbdecarray['mapnumcolumns'];
$y = $dbdecarray['mapnumrows'];

$map_x = array();
$map_y = array();
$EMPcontrol = array();
$CARcontrol = array();
$terrain = array();
$planet = array();
$base = array();
$econ = array();
$EMPdv = array();
$CARdv = array();

$EmpHexesHeld = array_fill(0,24,0);
$CarHexesHeld = array_fill(0,24,0);
$HexesHeld = array_fill(0,24,0);

$EmpPlanetsHeld = array_fill(0,24,0);
$CarPlanetsHeld = array_fill(0,24,0);
$PlanetsHeld = array_fill(0,24,0);

$EmpBasesHeld = array_fill(0,24,0);
$CarBasesHeld = array_fill(0,24,0);
$BasesHeld = array_fill(0,24,0);

$EmpAstHeld = array_fill(0,24,0);
$CarAstHeld = array_fill(0,24,0);
$AstHeld = array_fill(0,24,0);

$EmpNebHeld = array_fill(0,24,0);
$CarNebHeld = array_fill(0,24,0);
$NebHeld = array_fill(0,24,0);

$EmpHolesHeld = array_fill(0,24,0);
$CarHolesHeld = array_fill(0,24,0);
$HolesHeld = array_fill(0,24,0);

$EmpLanesHeld = array_fill(0,24,0);
$CarLanesHeld = array_fill(0,24,0);
$LanesHeld = array_fill(0,24,0);

$EmpEcon = array_fill(0,24,0);
$CarEcon = array_fill(0,24,0);
$Econ = array_fill(0,24,0);

for ($i = 1; $i <= $x*$y; $i++) {
	$map_x[$i] = $dbdecarray['maphex'.$i.'column'];
	$map_y[$i] = $dbdecarray['maphex'.$i.'row'];
	$terrain[$i] = $dbdecarray['maphex'.$i.'terrain'];
	$planet[$i] = $dbdecarray['maphex'.$i.'planet'];
	$base[$i] = $dbdecarray['maphex'.$i.'base'];
	$econ[$i] = $dbdecarray['maphex'.$i.'currecon'];
	$EMPcontrol[$i] = $dbdecarray['maphex'.$i.'race'];
	$EMPdv[$i] = $dbdecarray['maphex'.$i.'currdv'];
	$CARcontrol[$i] = $dbdecarray['maphex'.$i.'cartel'];
	$CARdv[$i] = $dbdecarray['maphex'.$i.'cartelcurrdv'];

	$EmpHexesHeld[$dbdecarray['maphex'.$i.'race']]++;
	$CarHexesHeld[$dbdecarray['maphex'.$i.'cartel']]++;
	
	if ($planet[$i] = $dbdecarray['maphex'.$i.'planet'] <> 0){
		$EmpPlanetsHeld[$dbdecarray['maphex'.$i.'race']]++;
		$CarPlanetsHeld[$dbdecarray['maphex'.$i.'cartel']]++;	
	}
	if ($base[$i] = $dbdecarray['maphex'.$i.'base'] <> 0){
		$EmpBasesHeld[$dbdecarray['maphex'.$i.'race']]++;
		$CarBasesHeld[$dbdecarray['maphex'.$i.'cartel']]++;	
	}
	if($terrain[$i] == 64 or $terrain[$i] == 128 or $terrain[$i] == 256 or $terrain[$i] == 512 or $terrain[$i] == 1024 or $terrain[$i] == 2048){
		$EmpAstHeld[$dbdecarray['maphex'.$i.'race']]++;
		$CarAstHeld[$dbdecarray['maphex'.$i.'cartel']]++;	
	}
	if($terrain[$i]== 4096 or $terrain[$i]== 8192 or $terrain[$i] == 16384 or $terrain[$i] == 32768 or $terrain[$i] == 65536 or $terrain[$i] == 131072){
		$EmpNebHeld[$dbdecarray['maphex'.$i.'race']]++;
		$CarNebHeld[$dbdecarray['maphex'.$i.'cartel']]++;
	}
	if($terrain[$i] == 262144 or $terrain[$i] == 524288 or $terrain[$i] == 1048576 or $terrain[$i] == 2097152 or $terrain[$i] == 4194304 or $terrain[$i] == 8388608){
		$EmpHolesHeld[$dbdecarray['maphex'.$i.'race']]++;
		$CarHolesHeld[$dbdecarray['maphex'.$i.'cartel']]++;
	}
	if($terrain[$i] == 33554432){
		$EmpLanesHeld[$dbdecarray['maphex'.$i.'race']]++;
		$CarLanesHeld[$dbdecarray['maphex'.$i.'cartel']]++;
	}

	$EmpEcon[$dbdecarray['maphex'.$i.'race']] = $EmpEcon[$dbdecarray['maphex'.$i.'race']] + $econ[$i] = $dbdecarray['maphex'.$i.'currecon'];
	$CarEcon[$dbdecarray['maphex'.$i.'cartel']] = $CarEcon[$dbdecarray['maphex'.$i.'cartel']] + $econ[$i] = $dbdecarray['maphex'.$i.'currecon'];
	
}

for ($j = 0; $j <= 23; $j++) {
	$HexesHeld[$j] = $EmpHexesHeld[$j] + $CarHexesHeld[$j];
	$PlanetsHeld[$j] = $EmpPlanetsHeld[$j] + $CarPlanetsHeld[$j];
	$BasesHeld[$j] = $EmpBasesHeld[$j] + $CarBasesHeld[$j];
	$AstHeld[$j] = $EmpAstHeld[$j] + $CarAstHeld[$j];
	$NebHeld[$j] = $EmpNebHeld[$j] + $CarNebHeld[$j];
	$HolesHeld[$j] = $EmpHolesHeld[$j] + $CarHolesHeld[$j];
	$LanesHeld[$j] = $EmpLanesHeld[$j] + $CarLanesHeld[$j];
	$Econ[$j] = $EmpEcon[$j] + $CarEcon[$j];
}

$maxecon = max($econ);
$EMPcurrmaxdv = max($EMPdv);
$CARcurrmaxdv = max($CARdv);

echo '<html>
<head>
	<meta http-equiv=Content-Style-Type content=text/css>
	<link rel=stylesheet href=', $cssloc, ' type=text/css>
	<title>', $dbdecarray['campaignname'], ' Map Summary</title>
</head>	
<body>
	<br>
	<center><h2><b><font color=#FFCC33>', $dbdecarray['campaignname'], ' Map Summary</font></b></h2></center>
	<table width=60% cellspacing=0 cellpadding=0 border=0 align=center>
		<tr>
			<td width=100% align=center class=windowbg2>
				<br>
				<font face=Arial size=2>';

echo					'
					<b>Map dimensions: ', $x, 'x', $y, '</b>
					<br><br>';			
					$RaceListNoCount = $dbdecarray['campnumraces'];
					for ($m=1; $m <= $RaceListNoCount; $m++) {
echo 						'<b><font color=', $empcolor[$dbdecarray['camprace'.$m]], '>', $empstring[$dbdecarray['camprace'.$m]], '</font></b><br>
						Economy: ', $Econ[$dbdecarray['camprace'.$m]], '<br>
						Hexes held: ', $HexesHeld[$dbdecarray['camprace'.$m]], '<br>
						Asteroids held: ', $AstHeld[$dbdecarray['camprace'.$m]], '<br>
						Nebulas held: ', $NebHeld[$dbdecarray['camprace'.$m]], '<br>
						Black Holes held: ', $HolesHeld[$dbdecarray['camprace'.$m]], '<br>
						Shipping Lanes held: ', $LanesHeld[$dbdecarray['camprace'.$m]], '<br>';
						if ($showplanets == 1) {
							echo 'Planets held: ', $PlanetsHeld[$dbdecarray['camprace'.$m]], '<br>';
						}
						if ($showbases == 1) {
							echo 'Bases held: ', $BasesHeld[$dbdecarray['camprace'.$m]], '<br>';
						}
echo						'
						<br><br>';
					
					}
echo				'</font>
			</td>
		</tr>
	</table>
	<br>
</body>
</html>';
?>