<html>
<head>
<title>Civilization IV Leader Picker</title>
<script language="javascript">
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Civilization IV Leader Picker
//  Version 1.1
//  Zhahz (Paul W. Nettle)
//  November 2005
//
//  Version History
//  1.0 - Initial coding
//  1.1 - Expanded UU info to include more details about units replaced
//        Corrected some unit/UU info based on the Civilopedia
//        Added credits blurb to page
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//  Initialize Data  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//  Constants
var LDR_NAME = 0;
var LDR_CIV = 1;
var LDR_TRAIT_1 = 2;
var LDR_TRAIT_2 = 3;
var CIV_NAME = 0;
var CIV_TECH_1 = 1;
var CIV_TECH_2 = 2;
var CIV_UU_NAME = 3;
var CIV_UU_DESC = 4;
//  Techs
var m_sTechs = new Array();
AddTech(0, "Agriculture", "Allows workers to construct farm improvements (with fresh water)");
AddTech(1, "Fishing", "Enables building workboat; city can work water tiles");
AddTech(2, "Hunting", "Enables building scout and spearmen (with copper); allows workers to build camps (deer, fur, ivory)");
AddTech(3, "Mining", "Allows workers to construct mine improvements");
AddTech(4, "Mysticism", "Allows construction of obelisks and Stonehenge; prereq for earliest religions");
AddTech(5, "The Wheel", "Allows workers to construct roads; enables building of chariots (with horses)");
//  Civs
var m_sCivs = new Array();
AddCiv( 0, "American", 0, 1, "Navy SEAL (24/1/160)", "1-2 first strikes, +50% attack vs machine guns; +50% attack vs artillery; starts with amphibious and march promotions<br>Replaces Marine (24/1/160) - which doesn't have the first strikes or march promotion");
AddCiv( 1, "Arab", 4, 5, "Camel Archer (10/2/90)", "Immune to first strikes; doesn't receive defensive bonuses; 25% chance to withdraw from combat; upgradeable to cavalry; no resource req<br>Replaces Knight (10/2/90) - which doesn't have the withdraw chance and requires iron");
AddCiv( 2, "Aztec", 2, 4, "Jaguar (5/1/40)", "+10% city attack; +25% jungle defense; upgradeable to maceman; no resource req<br>Replaces Swordsman (6/1/40) - which doesn't have the jungle defense bonus and requires iron");
AddCiv( 3, "Chinese", 0, 3, "Cho-Ko-Nu (6/1/60)", "2 first strikes; causes collateral damage; +50% vs melee units; upgradeable to rifelman or grenadier<br>Replaces Crossbowman (6/1/60) - which has 1 first strike and doesn't cause collateral damage");
AddCiv( 4, "Egyptian", 0, 5, "War Chariot (5/2/25)", "Immune to first strikes; doesn't receive defensive bonuses; 20% chance to withdraw from combat; upgradeable to horse archer or knight<br>Replaces Chariot (4/2/25) - which doesn't have first strike immunity");
AddCiv( 5, "English", 1, 3, "Redcoat (16/1/110)", "+25% vs mounted units; +25% vs gunpowder units; upgradeable to infantry<br>Replaces Rifleman (14/1/110) - which doesn't have the bonus vs gunpowder units");
AddCiv( 6, "French", 0, 5, "Musketeer (9/2/80)", "Movement rate of 2; upgradeable to infantry<br>Replaces Musketman (9/1/80) - which has a move of 1");
AddCiv( 7, "German", 2, 3, "Panzer (28/2/120)", "Doesn't receive defensive bonuses; +50% vs armored units; starts with blitz promotion; upgradeable to modern armor<br>Replaces Tank (24/2/120) - which doesn't have the bonus vs armored units");
AddCiv( 8, "Greek", 1, 2, "Phalanx (5/1/35)", "+25% hill defense; +100% vs mounted units; upgradeable to pikeman<br>Replaces Spearman (4/1/35) - which doesn't have the hill defense bonus");
AddCiv( 9, "Incan", 0, 4, "Quechua (2/1/15)", "+25% city defense; +100% vs archery units; upgrades as warrior<br>Replaces Warrior (2/1/15) - which doesn't have the bonus vs archery units");
AddCiv(10, "Indian", 3, 4, "Fast Worker (0/3/60)", "Movement rate of 3<br>Replaces Worker (0/2/60) - which has a move of 2");
AddCiv(11, "Japanese", 1, 5, "Samurai (8/1/70)", "2 first strikes; +50% vs melee units; upgrades to rifleman or grenadier<br>Replaces Maceman (8/1/70) - which doesn't have first strikes");
AddCiv(12, "Malinese", 3, 5, "Skirmisher (4/1/25)", "1-2 first strikes; +50% city defense; +25% hill defense; upgradeable to longbowman or crossbowman<br>Replaces Archer (3/1/25) - which has 1 first strike");
AddCiv(13, "Mongolian", 2, 5, "Keshik (6/2/50)", "1 first strike; doesn't receive defensive bonuses; ignores terrain movement costs; +50% vs catapults; upgradeable to cavalry<br>Replaces Horse Archer (6/2/50) - which doesn't have a first strike and doesn't have the terrain/movement bonus");
AddCiv(14, "Persian", 0, 2, "Immortal (4/2/25)", "30% chance to withdraw from combat; +50% vs archery units; upgradeable to horse archer or knight<br>Replaces Chariot (4/2/25) - which has a 20% withdraw chance, does not receive defense bonuses, and does not have a bonus vs archery units");
AddCiv(15, "Roman", 1, 3, "Praetorian (8/1/40)", "High base strength; upgradeable to maceman<br>Replaces Swordsman (6/1/40) - Praetorian doesn't have the Swordsman's +10% vs cities");
AddCiv(16, "Russian", 2, 3, "Cossack (18/2/120)", "30% chance to withdraw from combat; +50% vs cannons; +50% vs mounted units; upgradeable to gunship<br>Replaces Cavalry (15/2/120) - which doesn't have the bonus vs mounted units");
AddCiv(17, "Spanish", 1, 4, "Conquistador (10/2/90)", "Immune to first strikes; +50% vs melee units; upgradeable to cavalry<br>Replaces Knight (10/2/90) - which does't have the bonus vs melee and doesn't receive defensive bonuses");
//  Traits
var m_sTraits = new Array();
AddTrait(0, "Aggressive", "Melee and gunpowder units start with the combat 1 promotion; build barracks and dry docks at half cost");
AddTrait(1, "Creative", "+2 culture per turn per city; build theater and coliseum at half cost");
AddTrait(2, "Expansive", "+2 health per city; build granary and harbor at half cost");
AddTrait(3, "Financial", "+1 commerce on tiles generating 2 or more commerce; build bank at half cost");
AddTrait(4, "Industrious", "+50% wonder production; build forge at half cost");
AddTrait(5, "Organized", "-50% civic upkeep cost; build courthouse and lighthouse at half cost");
AddTrait(6, "Philosophical", "+100% great people birth rate; build university at half cost");
AddTrait(7, "Spiritual", "No anarchy; build temple at half cost");
//  Leaders
var m_sLeaders = new Array();
AddLeader("Alexander", 8, 0, 6);
AddLeader("Asoka", 10, 5, 7);
AddLeader("Bismarck", 7, 2, 4);
AddLeader("Catherine", 16, 1, 3);
AddLeader("Cyrus", 14, 1, 2);
AddLeader("Elizabeth", 5, 3, 6);
AddLeader("Frederick", 7, 1, 6);
AddLeader("Gandhi", 10, 4, 7);
AddLeader("Genghis Khan", 13, 0, 2);
AddLeader("Hatshepsut", 4, 1, 7);
AddLeader("Huayna Capac", 9, 0, 3);
AddLeader("Isabella", 17, 2, 7);
AddLeader("Julius Caesar", 15, 2, 5);
AddLeader("Kublai Khan", 13, 0, 1);
AddLeader("Louis XIV", 6, 1, 4);
AddLeader("Mansa Musa", 12, 3, 7);
AddLeader("Mao Zedong", 3, 5, 6);
AddLeader("Montezuma", 2, 0, 7);
AddLeader("Napoleon", 6, 0, 4);
AddLeader("Peter", 16, 2, 6);
AddLeader("Qin Shi Huang", 3, 3, 4);
AddLeader("Roosevelt", 0, 4, 5);
AddLeader("Saladin", 1, 6, 7);
AddLeader("Tokugawa", 11, 0, 5);
AddLeader("Victoria", 5, 2, 3);
AddLeader("Washington", 0, 3, 5);

//  Code  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function AddTech(nIndex, sName, sDescription)
{
	m_sTechs[nIndex] = new Array();
	m_sTechs[nIndex][0] = sName;
	m_sTechs[nIndex][1] = sDescription;
}

function AddCiv(nIndex, sName, nTechIndex1, nTechIndex2, sUUName, sUUDescription)
{
	m_sCivs[nIndex] = new Array();
	m_sCivs[nIndex][CIV_NAME] = sName;
	m_sCivs[nIndex][CIV_UU_NAME] = sUUName;
	m_sCivs[nIndex][CIV_UU_DESC] = sUUDescription;
	m_sCivs[nIndex][CIV_TECH_1] = nTechIndex1;
	m_sCivs[nIndex][CIV_TECH_2] = nTechIndex2;
}

function AddTrait(nIndex, sName, sDescription)
{
	m_sTraits[nIndex] = new Array();
	m_sTraits[nIndex][0] = sName;
	m_sTraits[nIndex][1] = sDescription;
}

function AddLeader(sName, nCivIndex, nTraitIndex1, nTraitIndex2)
{
	var nNextIndex = m_sLeaders.length;

	m_sLeaders[nNextIndex] = new Array();
	m_sLeaders[nNextIndex][LDR_NAME] = sName;
	m_sLeaders[nNextIndex][LDR_CIV] = nCivIndex;
	m_sLeaders[nNextIndex][LDR_TRAIT_1] = nTraitIndex1;
	m_sLeaders[nNextIndex][LDR_TRAIT_2] = nTraitIndex2;
}

function initializeElements()
{
	fillDropDown(m_sTraits, "ddlTraits");
	fillDropDown(m_sTechs, "ddlTechs");
}

function fillDropDown(sArray, sDropDownId)
{
	addItemToDropDown("-1", "Any", sDropDownId);

	for (var i = 0; i < sArray.length; i++)
	{
		addItemToDropDown(i, sArray[i][0], sDropDownId);
	}
}

function addItemToDropDown(sValue, sText, sDropDownId)
{
	var oItem = document.createElement("option");
	
	oItem.value = sValue;
	oItem.text = sText;

	document.getElementById(sDropDownId).options.add(oItem);
}

function updateList()
{
	var nSelectedTrait = document.getElementById("ddlTraits").value;
	var nSelectedTech = document.getElementById("ddlTechs").value;
	var oDivList = document.getElementById("divList");
	var sRows = "";
	
	oDivList.innerHTML = "";

	for (var i = 0; i < m_sLeaders.length; i++)
	{
		if (matchTrait(i, nSelectedTrait) && matchTech(i, nSelectedTech))
		{
			sRows += BuildListRow(i, nSelectedTrait, nSelectedTech);
		}
	}

	if (sRows.length > 0)
	{
		var sList = "";
		
		sList += "<table align=center border=0 cellpadding=4 cellspacing=2>";
		sList += "<tr>";
		sList += BuildListCell("Leader", true);
		sList += BuildListCell("Civ", true);
		sList += BuildListCell("Trait 1", true);
		sList += BuildListCell("Trait 2", true);
		sList += BuildListCell("Tech 1", true);
		sList += BuildListCell("Tech 2", true);
		sList += BuildListCell("UU (str/mv/cost)", true);
		sList += "</tr>";
		sList += sRows;
		sList += "</table>";

		oDivList.innerHTML = sList;
	}
	else
	{
		var sNoMatches = "No leaders match ";

		if (nSelectedTrait >= 0)
		{
			sNoMatches += "the " + m_sTraits[nSelectedTrait][0] + " trait";
		}
		if (nSelectedTech >= 0)
		{
			if (nSelectedTrait >= 0)
			{
				sNoMatches += " and ";
			}		
			
			sNoMatches += "the " + m_sTechs[nSelectedTech] + " tech";
		}

		oDivList.innerHTML = sNoMatches;
	}
}

function matchTrait(nLeaderIndex, nTraitIndex)
{
	var bMatch = false;
	
	if (nTraitIndex < 0 || m_sLeaders[nLeaderIndex][LDR_TRAIT_1] == nTraitIndex || m_sLeaders[nLeaderIndex][LDR_TRAIT_2] == nTraitIndex)
	{
		bMatch = true;
	}
	
	return bMatch;
}

function matchTech(nLeaderIndex, nTechIndex)
{
	var bMatch = false;

	if (nTechIndex < 0 || m_sCivs[m_sLeaders[nLeaderIndex][LDR_CIV]][CIV_TECH_1] == nTechIndex || m_sCivs[m_sLeaders[nLeaderIndex][LDR_CIV]][CIV_TECH_2] == nTechIndex)
	{   
		bMatch = true;
	}
		    
    return bMatch;
}

function BuildListRow(nLeaderIndex, nSelectedTrait, nSelectedTech)
{
	var sRow = "";
	var nTraitIndex1 = m_sLeaders[nLeaderIndex][LDR_TRAIT_1];
	var nTraitIndex2 = m_sLeaders[nLeaderIndex][LDR_TRAIT_2];
	var nTechIndex1 = m_sCivs[m_sLeaders[nLeaderIndex][LDR_CIV]][CIV_TECH_1];
	var nTechIndex2 = m_sCivs[m_sLeaders[nLeaderIndex][LDR_CIV]][CIV_TECH_2];
	var nTemp = 0;
	
	if (nSelectedTrait >= 0 && nTraitIndex1 != nSelectedTrait)
	{
		nTemp = nTraitIndex1;
		nTraitIndex1 = nTraitIndex2;
		nTraitIndex2 = nTemp;
	}
	
	if (nSelectedTech >= 0 && nTechIndex1 != nSelectedTech)
	{
		nTemp = nTechIndex1;
		nTechIndex1 = nTechIndex2;
		nTechIndex2 = nTemp;
	}
	
	sRow += "<tr valign=top>";
	sRow += BuildListCell(m_sLeaders[nLeaderIndex][LDR_NAME], false);
	sRow += BuildListCell(m_sCivs[m_sLeaders[nLeaderIndex][LDR_CIV]][CIV_NAME], false);
	sRow += BuildRolloverListCell(m_sTraits[nTraitIndex1][0], m_sTraits[nTraitIndex1][1]);
	sRow += BuildRolloverListCell(m_sTraits[nTraitIndex2][0], m_sTraits[nTraitIndex2][1]);
	sRow += BuildRolloverListCell(m_sTechs[nTechIndex1][0], m_sTechs[nTechIndex1][1]);
	sRow += BuildRolloverListCell(m_sTechs[nTechIndex2][0], m_sTechs[nTechIndex2][1]);
	sRow += BuildRolloverListCell(m_sCivs[m_sLeaders[nLeaderIndex][LDR_CIV]][CIV_UU_NAME], m_sCivs[m_sLeaders[nLeaderIndex][LDR_CIV]][CIV_UU_DESC]);
	sRow += "</tr>";
	
	return sRow;
}

function BuildListCell(sText, bHeader)
{	
	return "<td class=" + (bHeader ? "headercell" : "listcell") + ">" + sText + "</td>";
}

function BuildRolloverListCell(sText, sRolloverText)
{
	return "<td class=rolloverlistcell onmouseover=\"showInfo('" + sText + "<br>" + sRolloverText.replace(/'/g, "\\\'") + "');\" onmouseout=\"showInfo('');\">" + sText + "</td>";
}

function showInfo(sText)
{
	document.getElementById("divInfo").innerHTML = sText;
}

</script>

<style type="text/css">
	select            { font-family: Verdana; font-size: 9pt; }
	div               { font-family: Verdana; font-size: 9pt; }
	td                { font-family: Verdana; font-size: 9pt; }
	h3                { font-family: Verdana; font-size: 12pt; }
	.headercell       { border: solid 1px #000000; background-color: #E0E0E0; font-weight: bold; text-align: center;}
	.listcell         { border: solid 1px #000000; }
	.rolloverlistcell { border: solid 1px #000000; cursor:hand; }
</style>

</head>

<body onload="initializeElements();">

<h3 align="center">Civilization IV Leader Picker <span style="font-size:10pt;">(v1.1)</span><br><span style="font-size: 8pt;font-weight:normal;">by Zhahz</span></h3>

<table align="center" border="0" cellpadding="0" cellspacing="0">
<tr valign="top">
	<td>Trait:&#160;&#160;<select id="ddlTraits" onchange="updateList();"></select></td>
	<td>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</td>
	<td>Tech:&#160;&#160;<select id="ddlTechs" onchange="updateList();"></select></td>
</tr>
</table>

<br>

<div id="divList" align="center"></div>

<br>

<div id="divInfo" align="center">Select a trait and/or tech<br><br>Mouseover traits, techs, or UUs for more info<br><br>Select any/any after browsing for a full listing</div>

</body>
</html>
