<? include $DOCUMENT_ROOT."/zzzfilelist.inc"; ?>
<? if (!$dont_inc_general) { include Inc("functions_general.inc.php"); } ?>
<? include Inc("metoo.inc.php"); ?>
<? include Inc("metoo_loc.inc.php"); ?>
<?
	$fn=Inc("mapdata.csv");
	$fp = fopen ($fn, "r");
	$mapcontent = fread($fp, filesize($fn));
	fclose($fp);
	Decrunch($mapcontent);
	$mapcontentcell=$cell;
?>
<html>
<head><title>MeToo : Middle-Earth Tool for Overcoming Opposition</title></head>
<body>
<center>
<font size=+2><b>Middle-Earth Tool for Overcoming Opposition</b></font><br>
</center>

<hr>
<?
	if (!$goingtologin) { include Inc("testlogin.php");	}
?>
<? $where="showglobal"; include Inc("checkgameaccess.inc.php"); ?>
<? $game_checked=$game; include Inc("loaddata.inc.php"); ?>
<?
	$nbupdtodate=0;
	for ($i=1; $i<=25; $i++) {
		if ($turnmosttodate[$i]==$turntodisplaymax) {
			$nbupdtodate++;
		}
	}
	echo "<b><font size=+1> </font></b><br>";
	echo "<table align=center border=1 cellspacing=0>";
	echo "<tr align=center>";
	echo "<td width=90></td>";
	for ($i=1; $i<=25; $i++) {
		if ($turnmosttodate[$i]==$turntodisplaymax) {
			echo "<td width=90><b>".$loc[$loctag[1]+$i][$lang]."</td>";
		}
	}
	echo "</tr>\n";
	# heroes
	echo "<tr align=center bgcolor=#C0C0FF>";
	for ($i=count($NbHeroesTurn)-1; $i>0; $i--) {
		if (($turntodisplaymax>=$NbHeroesTurn[$i]) && ($maxheroes==0)) { $maxheroes=$NbHeroesTotal[$i]; }
	}
	echo "<td colspan=".($nbupdtodate+1)."><i>".$loc[$loctag[10]+6][$lang]."$maxheroes)</td>";
	echo "</tr>\n";
	# number of heroes
	echo "<tr align=center>";
	echo "<td width=90></td>";
	for ($i=1; $i<=$nbheroes; $i++) {
		if ($hero[$i]->health!=0) { $p=$hero[$i]->people; $nbhero[$p]++; $herolist[$p][$nbhero[$p]]=$i; }
	}
	for ($i=1; $i<=25; $i++) {
		if ($turnmosttodate[$i]==$turntodisplaymax) {
			echo "<td width=90 bgcolor=";
			if ($nbhero[$i]<=$maxheroes/3) { echo $GlobalColors[3]; }
			if (($nbhero[$i]>$maxheroes/3) && ($nbhero[$i]<=$maxheroes/1.5)) { echo $GlobalColors[2]; }
			if ($nbhero[$i]>=$maxheroes*0.8) { echo $GlobalColors[1]; }
			echo "><b>".$nbhero[$i]."</td>";
		}
	}
	echo "</tr>\n";
	# best heroes
	for ($b=1; $b<=5; $b++) {
		echo "<tr align=center>";
		echo "<td width=90><font size=-1><b>".$loc[$loctag[10]+$b][$lang]."</td>";
		for ($i=1; $i<=25; $i++) {
			if ($turnmosttodate[$i]==$turntodisplaymax) {
				echo "<td width=90><font size=-1>";
				for ($j=1; $j<=$nbhero[$i]; $j++) {
					$k=$herolist[$i][$j];
					switch ($b) {
						case 1 : $herolisttemp[$j]=$hero[$k]->command; break;
						case 2 : $herolisttemp[$j]=$hero[$k]->agent; break;
						case 3 : $herolisttemp[$j]=$hero[$k]->emissary; break;
						case 4 : $herolisttemp[$j]=$hero[$k]->mage; break;
						case 5 : $herolisttemp[$j]=$hero[$k]->challenge; break;
					}
					$herolisttempn[$j]=$k;
				}
				for ($l=1; $l<=3; $l++) {
					$max=0;
					for ($j=1; $j<=$nbhero[$i]; $j++) {
						$k=$herolist[$i][$j];
						if (($herolisttemp[$j]>$max) && ($hero[$k]->health!=0)) {
							$max=$herolisttemp[$j];
							$t=$j;
						}
					}
					if ($max!=0) {
						echo $hero[$herolisttempn[$t]]->name." (".$herolisttemp[$t].")<br>";
					}
					$herolisttemp[$t]=0;
				}
				echo "</td>";
			}
		}
		echo "</tr>\n";
	}
	
	# armies
	echo "<tr align=center bgcolor=#C0C0FF>";
	echo "<td colspan=".($nbupdtodate+1)."><i>".$loc[$loctag[10]+7][$lang]."</td>";
	echo "</tr>\n";
	for ($i=1; $i<=$nbarmies; $i++) {
		$p=$army[$i]->people; $nbarmy[$p]++; $armylist[$p][$nbarmy[$p]]=$i;
	}
	
	echo "<tr align=center>";
	echo "<td width=90><font size=-1><b>".$loc[$loctag[10]+17][$lang]."</td>";
	$max=0;
	for ($i=1; $i<=25; $i++) {
		if ($turnmosttodate[$i]==$turntodisplaymax) {
			for ($j=1; $j<=$nbarmy[$i]; $j++) {
				$k=$armylist[$i][$j];
				$str[$i]+=$army[$k]->str_final;
				$const[$i]+=$army[$k]->con_final;
			}
			if ($str[$i]>$max) { $max=$str[$i]; }
		}
	}
	for ($i=1; $i<=25; $i++) {
		if ($turnmosttodate[$i]==$turntodisplaymax) {
			echo "<td width=90 bgcolor=";
			if ($str[$i]<=$max/10) { echo $GlobalColors[3]; }
			if (($str[$i]>$max/10) && ($str[$i]<=$max*0.33)) { echo $GlobalColors[2]; }
			if ($str[$i]>=$max*0.75) { echo $GlobalColors[1]; }
			echo "><font size=-1><b>";
			echo RoundIt($str[$i],100)." /<br>".RoundIt($const[$i],100);
			echo "</td>";
		}
	}
	echo "</tr>\n";
	for ($b=1; $b<=4; $b++) {
		echo "<tr align=center>";
		echo "<td width=90><font size=-1><b>".$loc[$loctag[10]+7+$b][$lang]."</td>";
		for ($i=1; $i<=25; $i++) {
			if ($turnmosttodate[$i]==$turntodisplaymax) {
				echo "<td width=90><font size=-1>";
				for ($j=1; $j<=$nbarmy[$i]; $j++) {
					$k=$armylist[$i][$j];
					if (($army[$k]->str_final>=$GlobalArmySize[$b]) && ($army[$k]->str_final<$GlobalArmySize[$b-1])) {
						echo $army[$k]->leadername." (".$army[$k]->hex.")<br>";
						echo RoundIt($army[$k]->str_final,100)."/".RoundIt($army[$k]->con_final,100)."<br>";
					}
				}
				echo "</td>";
			}
		}
		echo "</tr>\n";
	}
	
	# economy
	echo "<tr align=center bgcolor=#C0C0FF>";
	echo "<td colspan=".($nbupdtodate+1)."><i>".$loc[$loctag[10]+12][$lang]."</td>";
	echo "</tr>\n";
	
	# gold cash
	echo "<tr align=center>";
	echo "<td width=90><font size=-1><b>".$loc[$loctag[6]+1][$lang]."</td>";
	for ($i=1; $i<=25; $i++) {
		if ($turnmosttodate[$i]==$turntodisplaymax) {
			$s=$stock[$i][6];
			echo "<td width=90><font size=-1>".$s."</td>";
		}
	}
	echo "</tr>\n";
	# balance
	echo "<tr align=center>";
	echo "<td width=90><font size=-1><b>".$loc[$loctag[6]+8][$lang]."</td>";
	for ($i=1; $i<=25; $i++) {
		if ($turnmosttodate[$i]==$turntodisplaymax) {
			$s=$stock[$i][1]+$stock[$i][2]+$stock[$i][3];
			$s=$stock[$i][5]-$s;
			echo "<td width=90><font size=-1>".$s."</td>";
		}
	}
	echo "</tr>\n";
	# gold cash next turn
	echo "<tr align=center>";
	echo "<td width=90><font size=-1><b>".$loc[$loctag[10]+13][$lang]."</td>";
	for ($i=1; $i<=25; $i++) {
		$positive[$i]=false;
		if ($turnmosttodate[$i]==$turntodisplaymax) {
			$s=$stock[$i][1]+$stock[$i][2]+$stock[$i][3];
			$s=$stock[$i][5]-$s;
			$s=$stock[$i][6]+$s;
			echo "<td width=90";
			if ($s>0) {
				$positive[$i]=true;
				echo " bgcolor=".$GlobalColors[1];
				$cash[$i]=$s;
			}
			echo "><font size=-1>".$s."</td>";
		}
	}
	echo "</tr>\n";
	# selling next turn
	for ($i=1; $i<=25; $i++) {
		for ($j=1; $j<=7; $j++) {
			$sales[$i][$j]=($stock[$i][$j+6]+$stock[$i][$j+13])*$market[$j+14];
		}
		for ($j=1; $j<=7; $j++) {
			$salestemp[$i][$j]=$sales[$i][$j];
		}
		for ($j=1; $j<=7; $j++) {
			$max=0;
			for ($k=1; $k<=7; $k++) {
				if ($salestemp[$i][$k]>$max) {
					$max=$salestemp[$i][$k];
					$t=$k;
				}
			}
			$salesmax[$i][$j]=$t;
			$salestemp[$i][$t]=0;
		}			
	}
	echo "<tr align=center>";
	echo "<td width=90><font size=-1><b>".$loc[$loctag[10]+14][$lang]."</td>";
	for ($i=1; $i<=25; $i++) {
		if ($turnmosttodate[$i]==$turntodisplaymax) {
			$v=0;
			echo "<td width=90>";
			if (!$positive[$i]) {
				echo "<font size=-1>".$loc[$loctag[6]+8+$salesmax[$i][1]][$lang]."<br>";
				echo $loc[$loctag[6]+8+$salesmax[$i][2]][$lang];
			}
			echo "</td>";
		}
	}
	echo "</tr>\n";
	# gold cash next turn after sales
	echo "<tr align=center>";
	echo "<td width=90><font size=-1><b>".$loc[$loctag[10]+15][$lang]."</td>";
	for ($i=1; $i<=25; $i++) {
		if ($turnmosttodate[$i]==$turntodisplaymax) {
			$s=$stock[$i][1]+$stock[$i][2]+$stock[$i][3];
			$s=$stock[$i][5]-$s;
			$s=$stock[$i][6]+$s;
			$v=$sales[$i][$salesmax[$i][1]]+$sales[$i][$salesmax[$i][2]];
			$sales[$i][$salesmax[$i][1]]=0;
			$sales[$i][$salesmax[$i][2]]=0;
			$s+=$v;
			echo "<td width=90";
			if (!$positive[$i]) {
				if ($s>0) { echo " bgcolor=".$GlobalColors[1]; } else { echo " bgcolor=".$GlobalColors[3]; }
			}
			echo ">";
			if (!$positive[$i]) {
				echo "<font size=-1>".$s;
				$cash[$i]=$s;
			}
			echo "</td>";
		}
	}
	echo "</tr>\n";
	
	# balance again
	echo "<tr align=center>";
	echo "<td width=90><font size=-1><b>".$loc[$loctag[6]+8][$lang].$loc[$loctag[10]+16][$lang]."</td>";
	for ($i=1; $i<=25; $i++) {
		if ($turnmosttodate[$i]==$turntodisplaymax) {
			$s=$stock[$i][1]+$stock[$i][2]+$stock[$i][3];
			$s=$stock[$i][5]-$s;
			echo "<td width=90><font size=-1>".$s."</td>";
		}
	}
	echo "</tr>\n";
	# gold cash turn+1
	echo "<tr align=center>";
	echo "<td width=90><font size=-1><b>".$loc[$loctag[10]+13][$lang].$loc[$loctag[10]+16][$lang]."</td>";
	for ($i=1; $i<=25; $i++) {
		$positive[$i]=false;
		if ($turnmosttodate[$i]==$turntodisplaymax) {
			$s=$stock[$i][1]+$stock[$i][2]+$stock[$i][3];
			$s=$stock[$i][5]-$s;
			$s=$cash[$i]+$s;
			echo "<td width=90";
			if ($s>0) { $positive[$i]=true; echo " bgcolor=".$GlobalColors[1]; }
			echo "><font size=-1>".$s."</td>";
		}
	}
	echo "</tr>\n";
	# selling turn+1
	echo "<tr align=center>";
	echo "<td width=90><font size=-1><b>".$loc[$loctag[10]+14][$lang].$loc[$loctag[10]+16][$lang]."</td>";
	for ($i=1; $i<=25; $i++) {
		if ($turnmosttodate[$i]==$turntodisplaymax) {
			$v=0;
			echo "<td width=90>";
			if (!$positive[$i]) {
				echo "<font size=-1>".$loc[$loctag[6]+8+$salesmax[$i][3]][$lang]."<br>";
				echo $loc[$loctag[6]+8+$salesmax[$i][4]][$lang];
			}
			echo "</td>";
		}
	}
	echo "</tr>\n";
	# gold cash turn+1 after sales
	echo "<tr align=center>";
	echo "<td width=90><font size=-1><b>".$loc[$loctag[10]+15][$lang].$loc[$loctag[10]+16][$lang]."</td>";
	for ($i=1; $i<=25; $i++) {
		if ($turnmosttodate[$i]==$turntodisplaymax) {
			$s=$stock[$i][1]+$stock[$i][2]+$stock[$i][3];
			$s=$stock[$i][5]-$s;
			$s=$cash[$i]+$s;
			$v=$sales[$i][$salesmax[$i][3]]+$sales[$i][$salesmax[$i][4]];
			$s+=$v;
			echo "<td width=90";
			if (!$positive[$i]) {
				if ($s>0) { echo " bgcolor=".$GlobalColors[1]; } else { echo " bgcolor=".$GlobalColors[2]; }
			}
			echo ">";
			if (!$positive[$i]) {
				echo "<font size=-1>".$s;
			}
			echo "</td>";
		}
	}
	echo "</tr>\n";

	echo "</table>\n";
?>