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

$AllyRatio = $dbdecarray['polallyratio']/100;
$NeutralRatio = $dbdecarray['polneutralratio']/100;

$neutralRange = $NeutralRatio - $AllyRatio;
$enemyRange = 1 - $NeutralRatio;

// Alllied
$partner			= $AllyRatio * 0.2;	// 0.05
$trustedAlly			= $AllyRatio * 0.4;	// 0.10
$ally				= $AllyRatio * 0.6;	// 0.15
$tradePartner			= $AllyRatio * 0.8;	// 0.20
$workingOnTradeAgreement	= $AllyRatio;		// 0.25

// Neutral
$inTradeDiscusions		= $AllyRatio + $neutralRange * 0.2;	// 0.30
$friendly			= $AllyRatio + $neutralRange * 0.6;	// 0.40
$neutral			= $NeutralRatio;			// 0.50

// War
$stressed			= $NeutralRatio + $enemyRange * 0.16;	// 0.58
$heated				= $NeutralRatio + $enemyRange * 0.26;	// 0.63
$borderSkirmishes		= $NeutralRatio + $enemyRange * 0.46;	// 0.73
$enemy				= $NeutralRatio + $enemyRange * 0.66;	// 0.83
$war				= $NeutralRatio + $enemyRange * 0.86;	// 0.93

echo '<html>
<head>
	<meta http-equiv=Content-Style-Type content=text/css>
	<link rel=stylesheet href=', $cssloc, ' type=text/css>
	<LINK REL="SHORTCUT ICON" href="favicon.ico">
	<title>', $dbdecarray['campaignname'], ' Politics</title>

</head>
<body>
<br>';

echo '<center><h3><b><font color="#FFCC33">', $dbdecarray['campaignname'], ' Political Tensions Matrix</font></b></h3></center>
<table width=80% cellspacing=0 cellpadding=0 border=1 align=center>
	<tr>
		<td width=', 100/($dbdecarray['campnumraces']+1), '% align=center class=windowbg2>
		<font face=Arial size=2> - </font>
		</td>
		';
	for ($m=1; $m <= $dbdecarray['campnumraces']; $m++) {
		echo '<td width=', 100/($dbdecarray['campnumraces']+1), '% align=center class=windowbg2>
			<b><font face=Arial size=2 color=', $empcolor[$dbdecarray['camprace'.$m]], '>',
			$empstring[$dbdecarray['camprace'.$m]],
			'</font></b>
		</td>
		';
	}
	echo '</tr>
	';
	for ($m=1; $m <= $dbdecarray['campnumraces']; $m++) {
	echo '<tr>
		<td width=', 100/($dbdecarray['campnumraces']+1), '% align=center class=windowbg2>
			<b><font face=Arial size=2 color=', $empcolor[$dbdecarray['camprace'.$m]], '>',
			$empstring[$dbdecarray['camprace'.$m]],
			'</font></b>
		</td>';
		for ($n=1; $n <= $dbdecarray['campnumraces']; $n++) {
			echo '<td width=', 100/($dbdecarray['campnumraces']+1), '% align=center class=windowbg2><font face=Arial size=2>';
				if($n <> $m) {
					$CurrTensionIndex = $dbdecarray['camprace'.$m]*25+$dbdecarray['camprace'.$n]+1;
					$CurrentRelTension = $dbdecarray['polcurrreltension'.$CurrTensionIndex];
					echo $CurrentRelTension; 
				} else {
					echo ' - ';
				}
			echo '</font></td>
			';
		}
	echo '</tr>
	';
	}
echo'</table>
<br>';

echo '<center><h3><b><font color="#FFCC33">', $dbdecarray['campaignname'], ' Political Tensions List</font></b></h3></center>
<table width=80% cellspacing=0 cellpadding=0 border=0 align=center>
	<tr>
	<td width=100% align=center class=windowbg2><br>
		';

	for ($m=1; $m <= $dbdecarray['campnumraces']; $m++) {
		echo '<font face=Arial size=2>The </font>';
		echo '<b><font face=Arial size=2 color=', $empcolor[$dbdecarray['camprace'.$m]], '>';
		echo $empstring[$dbdecarray['camprace'.$m]];
		echo '</font></b>';
		echo '
		<br>';
		for ($n=1; $n <= $dbdecarray['campnumraces']; $n++) {
			if($n <> $m) {
				echo '<font face=Arial size=2>';
				$CurrTensionIndex = $dbdecarray['camprace'.$m]*25+$dbdecarray['camprace'.$n]+1;
				$CurrentRelTension = $dbdecarray['polcurrreltension'.$CurrTensionIndex]/100;
				if ($CurrentRelTension < $partner) {
					echo 'is a long term partner of the ';
				} elseif ($CurrentRelTension < $trustedAlly) {
					echo 'is a highly trusted ally with the ';
				} elseif ($CurrentRelTension < $ally) {
					echo 'is a friendly ally with the ';
				} elseif ($CurrentRelTension < $tradePartner) {
					echo 'has good trade relations with the ';
				} elseif ($CurrentRelTension < $workingOnTradeAgreement) {
					echo 'is working on a trade agreement with the ';
				} elseif ($CurrentRelTension < $inTradeDiscusions) {
					echo 'is discussing the details of an alliance with the ';
				} elseif ($CurrentRelTension < $friendly) {
					echo 'is on friendly terms with the ';
				} elseif ($CurrentRelTension < $neutral) {
					echo 'has a non-aggression pact with the ';
				} elseif ($CurrentRelTension < $stressed) {
					echo 'distrusts the ';
				} elseif ($CurrentRelTension < $heated) {
					echo 'does not interact with the ';
				} elseif ($CurrentRelTension < $borderSkirmishes) {
					echo 'is having border skirmishes with the ';
				} elseif ($CurrentRelTension < $enemy) {
					echo 'is an enemy of the ';
				} elseif ($CurrentRelTension < $war) {
					echo 'is at war with the ';
				} else {
					echo 'is a mortal enemy of the ';
				}
				echo ' ', $empstring[$dbdecarray['camprace'.$n]], '
				</font><br>';
			}		
		}
		echo '<br>
		';
	}

echo	'</td>
	</tr>
</table>';

echo'<br>
</body>
</html>';
?>