<? 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"); ?>
<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>

<script language="JavaScript">
var UnitsStr=new Array(
<?
	for ($i=0; $i<=count($UnitsStr)-1; $i++) {
		if ($i!=0) echo ", ";
		echo "'".$UnitsStr[$i]."'";
	}
?>
);
var UnitsCon=new Array(
<?
	for ($i=0; $i<=count($UnitsCon)-1; $i++) {
		if ($i!=0) echo ", ";
		echo "'".$UnitsCon[$i]."'";
	}
?>
);
var TerrainChange=new Array(
<?
	for ($i=0; $i<=count($TerrainChange)-1; $i++) {
		if ($i!=0) echo ", ";
		echo $TerrainChange[$i];
	}
?>
);
var TroopTerrainMod=new Array(
<?
	for ($i=0; $i<=5; $i++) {
		if ($i!=0) echo ",\n";
		echo "\t new Array(";
		for ($j=0; $j<=6; $j++) {
			if ($j!=0) echo ",";
			echo $TroopTerrainMod[$i][$j];
		}
		echo ")";
	}
?>
);
var TroopTacticMod=new Array(
<?
	for ($i=0; $i<=5; $i++) {
		if ($i!=0) echo ",\n";
		echo "\t new Array(";
		for ($j=0; $j<=5; $j++) {
			if ($j!=0) echo ",";
			echo $TroopTacticMod[$i][$j];
		}
		echo ")";
	}
?>
);
var TacticVSTactic=new Array(
<?
	for ($i=0; $i<=5; $i++) {
		if ($i!=0) echo ",\n";
		echo "\t new Array(";
		for ($j=0; $j<=5; $j++) {
			if ($j!=0) echo ",";
			echo $TacticVSTactic[$i][$j];
		}
		echo ")";
	}
?>
);
var TerrainClimateMod=new Array(
<?
	for ($p=0; $p<=24; $p++) {
		if ($p!=0) echo ",\n";
		echo "\t new Array(";
		for ($i=0; $i<=6; $i++) {
			if ($i!=0) echo ",\n";
			echo "\t new Array(";
			for ($j=0; $j<=6; $j++) {
				if ($j!=0) echo ",";
				echo $TerrainClimateMod[$p][$i][$j];
			}
			echo ")";
		}
		echo ")";
	}
?>
);
var RelationMod=new Array(<?
	for ($i=0; $i<=count($RelationMod)-1; $i++) {
		if ($i!=0) echo ", ";
		echo $RelationMod[$i];
	}
?>
);

function recalc() {
	var i;
	var units=new Array(6), str_ideal=new Array(6), con_ideal=new Array(6);
	var training=new Array(6), weapons=new Array(6), terrain=new Array(6), tactic=new Array(6);
	var average=new Array(6), armors=new Array(6), str_base=new Array(6), con_base=new Array(6);
	var commander, aclimate, aterrain, amorale, aaverage;
	var str_real, con_real;
	var theForm = document.forms["calc"];
	var tactic, relations, offmagic, defmagic, wmachines;
	var str_finale, con_finale;
	var People, Climate, Terrain, Tactic, VSTactic, Relation, unitvalue, terrainchanged;

	People=theForm.elements["ddpeople"].value;
	Climate=theForm.elements["ddclimate"].value;
	Terrain=theForm.elements["ddterrain"].value;
	for (i=1; i<=6; i++) {
		unitvalue=TroopTerrainMod[i-1][Terrain-1];
		theForm.elements["terrain-"+i].value=unitvalue;
	}
	terrainchanged=TerrainChange[Terrain];
	theForm.elements["aclimate"].value=TerrainClimateMod[People-1][Climate-1][terrainchanged-1];
	theForm.elements["aterrain"].value=TerrainClimateMod[People-1][Climate-1][terrainchanged-1];
	Tactic=theForm.elements["ddtactic"].value;
	for (i=1; i<=6; i++) {
		unitvalue=TroopTacticMod[i-1][Tactic-1];
		theForm.elements["tactic-"+i].value=unitvalue;
	}
	VSTactic=theForm.elements["ddvstactic"].value;
	VSTactic=TacticVSTactic[Tactic-1][VSTactic-1];
	theForm.elements["tactic"].value=VSTactic;
	Relation=RelationMod[theForm.elements["ddrelation"].value-1];
	theForm.elements["relations"].value=Relation;

	// troops
	for (i=1; i<=6; i++) {
		units[i]=theForm.elements["units-"+i].value*1;
		str_ideal[i]=units[i]*UnitsStr[i];
		con_ideal[i]=units[i]*UnitsCon[i];
		document.getElementById("str_ideal-"+i).innerHTML="<font size=-1><i>"+str_ideal[i];
		document.getElementById("con_ideal-"+i).innerHTML="<font size=-1><i>"+con_ideal[i];
		
		training[i]=theForm.elements["training-"+i].value*1;
		weapons[i]=theForm.elements["weapons-"+i].value*1;
		terrain[i]=theForm.elements["terrain-"+i].value*1;
		tactic[i]=theForm.elements["tactic-"+i].value*1;
		average[i]=(training[i]+weapons[i]+terrain[i]+tactic[i])/4;
		document.getElementById("average-"+i).innerHTML="<font size=-1><i>"+Math.round(average[i]);
		armors[i]=theForm.elements["armors-"+i].value*1;
		str_base[i]=str_ideal[i]*average[i]/100;
		con_base[i]=con_ideal[i]*(100+armors[i])/100;
		document.getElementById("str_base-"+i).innerHTML="<font size=-1><i>"+Math.round(str_base[i]);
		document.getElementById("con_base-"+i).innerHTML="<font size=-1><i>"+Math.round(con_base[i]);
	}
	
	// army
	commander=theForm.elements["commander"].value*1;
	aclimate=theForm.elements["aclimate"].value*1;
	aterrain=theForm.elements["aterrain"].value*1;
	amorale=theForm.elements["amorale"].value*1;
	aaverage=(commander+aclimate+aterrain+amorale)/4;
	str_real=0;
	for (i=1; i<=6; i++) { str_real+=str_base[i]; }
	str_real*=aaverage/100;
	con_real=0;
	for (i=1; i<=6; i++) { con_real+=con_base[i]; }
	document.getElementById("aaverage").innerHTML="<font size=-1><i>"+Math.round(aaverage);
	document.getElementById("str_real").innerHTML="<font size=-1><i>"+Math.round(str_real);
	document.getElementById("con_real").innerHTML="<font size=-1><i>"+Math.round(con_real);
	
	// battle
	tactic=theForm.elements["tactic"].value*1;
	relations=theForm.elements["relations"].value*1;
	offmagic=theForm.elements["offmagic"].value*1;
	defmagic=theForm.elements["defmagic"].value*1;
	wmachines=theForm.elements["wmachines"].value*1;
	str_finale=str_real*tactic/100*relations/100+offmagic+wmachines*UnitsStr[7];
	con_finale=con_real+defmagic;
	document.getElementById("str_finale").innerHTML="<font size=+1><i><b>"+Math.round(str_finale);
	document.getElementById("con_finale").innerHTML="<font size=+1><i><b>"+Math.round(con_finale);
}
</script>

<hr>
<?
	if (!$goingtologin) { include Inc("testlogin.php");	}
?>
<? $where="showarmy"; include Inc("checkgameaccess.inc.php"); ?>
<?
#	echo $data."<hr>";

	$datap=explode("-", $data);
	$nbarmies++;
	$army[$nbarmies] = new Army;
	$army[$nbarmies]->people=$datap[0];
	for ($n=1; $n<=7; $n++) {
		$army[$nbarmies]->unitsnb[$n]=$datap[$n];
	}
	$army[$nbarmies]->leadercommand=$datap[8];
	$army[$nbarmies]->climate=$datap[9];
	$army[$nbarmies]->terrain=$datap[10];
	$army[$nbarmies]->tactic=3;
	$army[$nbarmies]->vstactic=3;
	$army[$nbarmies]->morale=$datap[11];
	for ($n=1; $n<=6; $n++) {
		$army[$nbarmies]->units_training[$n]=$datap[$n+11];
		$army[$nbarmies]->units_weapons[$n]=$datap[$n+17];
		$army[$nbarmies]->units_armors[$n]=$datap[$n+23];
	}
	CalculateArmyStr($nbarmies);
	
#	echo "<b><font size=+1>".$loc[$loctag[6]+16][$lang]."</font></b><br>";
	echo "<table align=center border=1 cellspacing=0>";
	echo "<form name='calc'>";
	# army mix
	echo "<tr align=center>";
	echo "<td width=90></td>";
	for ($i=1; $i<=6; $i++) {
		echo "<td width=70><font size=-1><i><b>".$loc[$loctag[7]+$i+7][$lang]."</td>";
	}
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td></td>";
	for ($i=1; $i<=6; $i++) {
		echo "<td>";
		echo "<input align=center type='text' name='units-$i' value='".$army[$nbarmies]->unitsnb[$i]."' size=4 onChange='recalc();'>";
		echo "</td>";
	}
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td><font size=-1><i>".$loc[$loctag[7]+15][$lang]." (".$loc[$loctag[7]+17][$lang].")</td>";
	for ($i=1; $i<=6; $i++) {
		echo "<td><font size=-1><i><div id=str_ideal-$i>";
		echo $army[$nbarmies]->str_ideal[$i];
		echo "</div></td>";
	}
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td><font size=-1><i>".$loc[$loctag[7]+16][$lang]." (".$loc[$loctag[7]+17][$lang].")</td>";
	for ($i=1; $i<=6; $i++) {
		echo "<td><font size=-1><i><div id=con_ideal-$i>";
		echo $army[$nbarmies]->con_ideal[$i];
		echo "</div></td>";
	}
	echo "</tr>\n";
	
	# troop
	echo "<tr align=center>";
	echo "<td colspan=7><i>".$loc[$loctag[7]+30][$lang]."</td>";
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td>".$loc[$loctag[7]+18][$lang]."</td>";
	for ($i=1; $i<=6; $i++) {
		echo "<td>";
		echo "<input align=center type='text' name='training-$i' value='".$army[$nbarmies]->units_training[$i]."' size=4 onChange='recalc();'>";
		echo "</td>";
	}
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td>".$loc[$loctag[7]+19][$lang]."</td>";
	for ($i=1; $i<=6; $i++) {
		echo "<td>";
		echo "<input align=center type='text' name='weapons-$i' value='".$army[$nbarmies]->units_weapons[$i]."' size=4 onChange='recalc();'>";
		echo "</td>";
	}
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td>".$loc[$loctag[7]+20][$lang]."</td>";
	for ($i=1; $i<=6; $i++) {
		$ttm=$TroopTerrainMod[$i-1][$army[$nbarmies]->terrain-1];
		echo "<td>";
		echo "<input align=center type='text' name='terrain-$i' value='$ttm' size=4 onChange='recalc();'>";
		echo "</td>";
	}
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td>".$loc[$loctag[7]+21][$lang]."</td>";
	for ($i=1; $i<=6; $i++) {
		echo "<td>";
		$tactic=$TroopTacticMod[$i-1][$army[$nbarmies]->tactic-1];
		echo "<input align=center type='text' name='tactic-$i' value=$tactic size=4 onChange='recalc();'>";
		echo "</td>";
	}
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td><font size=-1><i>".$loc[$loctag[7]+22][$lang]."</td>";
	for ($i=1; $i<=6; $i++) {
		echo "<td><font size=-1><i><div id=average-$i>";
		echo (int)($army[$nbarmies]->avg_modif_base[$i]);
		echo "</div></td>";
	}
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td>".$loc[$loctag[7]+23][$lang]."</td>";
	for ($i=1; $i<=6; $i++) {
		echo "<td>";
		echo "<input align=center type='text' name='armors-$i' value='".$army[$nbarmies]->units_armors[$i]."' size=4 onChange='recalc();'>";
		echo "</td>";
	}
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td><font size=-1><i>".$loc[$loctag[7]+15][$lang]." (".$loc[$loctag[7]+24][$lang].")</td>";
	for ($i=1; $i<=6; $i++) {
		echo "<td><font size=-1><i><div id=str_base-$i>";
		echo (int)($army[$nbarmies]->str_base[$i]);
		echo "</div></td>";
	}
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td><font size=-1><i>".$loc[$loctag[7]+16][$lang]." (".$loc[$loctag[7]+24][$lang].")</td>";
	for ($i=1; $i<=6; $i++) {
		echo "<td><font size=-1><i><div id=con_base-$i>";
		echo (int)($army[$nbarmies]->con_base[$i]);
		echo "</div></td>";
	}
	echo "</tr>\n";

	# army
	echo "<tr>";
	echo "<td colspan=3>";
	echo "<table align=center border=1 cellspacing=0>";
	echo "<tr align=center>";
	echo "<td colspan=2><i>".$loc[$loctag[7]+31][$lang]."</td>";
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td>".$loc[$loctag[7]+25][$lang]."</td>";
		echo "<td>";
		echo "<input align=center type='text' name='commander' value='".$army[$nbarmies]->leadercommand."' size=4 onChange='recalc();'>";
		echo "</td>";
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td>".$loc[$loctag[7]+26][$lang]."</td>";
		$ttm=$TerrainClimateMod[$army[$nbarmies]->people-1][$army[$nbarmies]->climate-1][$TerrainChange[$army[$nbarmies]->terrain]-1];
		echo "<td>";
		echo "<input align=center type='text' name='aclimate' value='$ttm 'size=4 onChange='recalc();'>";
		echo "</td>";
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td>".$loc[$loctag[7]+20][$lang]."</td>";
		echo "<td>";
		echo "<input align=center type='text' name='aterrain' value='$ttm' size=4 onChange='recalc();'>";
		echo "</td>";
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td>".$loc[$loctag[7]+27][$lang]."</td>";
		echo "<td>";
		echo "<input align=center type='text' name='amorale' value='".$army[$nbarmies]->morale."' size=4 onChange='recalc();'>";
		echo "</td>";
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td><font size=-1><i>".$loc[$loctag[7]+22][$lang]."</td>";
		echo "<td><font size=-1><i><div id=aaverage>";
		echo (int)($army[$nbarmies]->avg_modif_real);
		echo "</div></td>";
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td><font size=-1><i>".$loc[$loctag[7]+15][$lang]." (".$loc[$loctag[7]+28][$lang].")</td>";
		echo "<td><font size=-1><i><div id=str_real>";
		echo (int)($army[$nbarmies]->str_real);
		echo "</div></td>";
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td><font size=-1><i>".$loc[$loctag[7]+16][$lang]." (".$loc[$loctag[7]+28][$lang].")</td>";
		echo "<td><font size=-1><i><div id=con_real>";
		echo (int)($army[$nbarmies]->con_real);
		echo "</div></td>";
	echo "</tr>\n";
	
	# battle
	echo "<tr align=center>";
	echo "<td colspan=2><i>".$loc[$loctag[7]+32][$lang]."</td>";
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td>".$loc[$loctag[7]+21][$lang]."</td>";
		echo "<td>";
		$tactic=$TacticVSTactic[$army[$nbarmies]->tactic-1][$army[$nbarmies]->vstactic-1];
		echo "<input align=center type='text' name='tactic' value=$tactic size=4 onChange='recalc();'>";
		echo "</td>";
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td>".$loc[$loctag[7]+29][$lang]."</td>";
		echo "<td>";
		echo "<input align=center type='text' name='relations' value=".$RelationMod[3]." size=4 onChange='recalc();'>";
		echo "</td>";
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td>".$loc[$loctag[7]+33][$lang]."</td>";
		echo "<td>";
		echo "<input align=center type='text' name='offmagic' value=0 size=4 onChange='recalc();'>";
		echo "</td>";
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td>".$loc[$loctag[7]+34][$lang]."</td>";
		echo "<td>";
		echo "<input align=center type='text' name='defmagic' value=0 size=4 onChange='recalc();'>";
		echo "</td>";
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td>".$loc[$loctag[7]+14][$lang]."</td>";
		echo "<td>";
		echo "<input align=center type='text' name='wmachines' value='".$army[$nbarmies]->unitsnb[7]."' size=4 onChange='recalc();'>";
		echo "</td>";
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td><font size=+1><i><b>".$loc[$loctag[7]+15][$lang]." (".$loc[$loctag[7]+35][$lang].")</td>";
		echo "<td><font size=+1><i><b><div id=str_finale>";
		echo (int)($army[$nbarmies]->str_final);
		echo "</div></td>";
	echo "</tr>\n";
	echo "<tr align=center>";
	echo "<td><font size=+1><i><b>".$loc[$loctag[7]+16][$lang]." (".$loc[$loctag[7]+35][$lang].")</td>";
		echo "<td><font size=+1><i><b><div id=con_finale>";
		echo (int)($army[$nbarmies]->con_final);
		echo "</div></td>";
	echo "</tr>\n";
	echo "</table>\n";

	echo "</td>";
	echo "<td colspan=4 align=center>";
	
#	echo "<a onclick=\"javascript:openWindow('showarmy_tables.inc.php?data=$data','600','800')\" style='color:black;cursor:pointer'>";
	echo "<a href='showarmy_tables.inc.php?data=$data'>";
	echo $loc[$loctag[7]+55][$lang]."</a><br><br>";

	echo "<table><tr>";
	echo "<td>".$loc[$loctag[4]+2][$lang]."</td><td><select name='ddpeople' onChange='recalc();'>";
	for ($i=1 ;$i<=25; $i++) {
  		echo "\n<option";
  		if ($i==$army[$nbarmies]->people) { echo " selected"; }
  		echo " value=$i>".$loc[$loctag[1]+$i][$lang];
	}
	echo "</select>\n</td></tr><tr>";
	echo "<td>".$loc[$loctag[7]+26][$lang]."</td><td><select name='ddclimate' onChange='recalc();'>";
	for ($i=1 ;$i<=7; $i++) {
  		echo "\n<option";
  		if ($i==$army[$nbarmies]->climate) { echo " selected"; }
  		echo " value=$i>".$loc[$loctag[7]+$i+35][$lang];
	}
	echo "</select>\n</td></tr><tr>";
	echo "<td>".$loc[$loctag[7]+20][$lang]."</td><td><select name='ddterrain' onChange='recalc();'>";
	for ($i=1 ;$i<=7; $i++) {
  		echo "\n<option";
  		if ($i==$army[$nbarmies]->terrain) { echo " selected"; }
  		echo " value=$i>".$loc[$loctag[7]+$i+42][$lang];
	}
	echo "</select>\n</td></tr><tr>";
	echo "<td>".$loc[$loctag[7]+21][$lang]."</td><td><select name='ddtactic' onChange='recalc();'>";
	for ($i=1 ;$i<=6; $i++) {
  		echo "\n<option";
  		if ($i==$army[$nbarmies]->tactic) { echo " selected"; }
  		echo " value=$i>".$loc[$loctag[8]+$i][$lang];
	}
	echo "</select>\n</td></tr><tr>";
	echo "<td>".$loc[$loctag[8]+7][$lang]."</td><td><select name='ddvstactic' onChange='recalc();'>";
	for ($i=1 ;$i<=6; $i++) {
  		echo "\n<option";
  		if ($i==$army[$nbarmies]->vstactic) { echo " selected"; }
  		echo " value=$i>".$loc[$loctag[8]+$i][$lang];
	}
	echo "</select>\n</td></tr><tr>";
	echo "<td>".$loc[$loctag[7]+29][$lang]."</td><td><select name='ddrelation' onChange='recalc();'>";
	for ($i=1 ;$i<=5; $i++) {
  		echo "\n<option";
  		if ($i==4) { echo " selected"; }
  		echo " value=$i>".$loc[$loctag[7]+$i+49][$lang];
	}
	echo "</select>\n</td></tr></table>";
	echo "</td>";
	echo "</tr>";
	
	echo "</form>";
	echo "</table>";
?>