
confed=0
kilrathi=1
nephilim=2
merchant=3
retro=4
pirates=5
hunter=6
militia=7
unknown=8
landreich=9
border_worlds=10
firekkan=11
AWACS=12
at_least_one_producer={"AWACS":1,"retro":1}
fortress_systems={"Gemini/Perry":1-.0625, "Gemini/New_Constantinople":1-.0625, "Gemini/New_Detroit":1-.0625, "Gemini/Troy":.3125,"Gemini/Tingerhoff":.3125,"Gemini/XXN-1927":.3125,"Gemini/Junction":.3125,"Gemini/Eden":1.0,"Gemini/Beta":1.0,"Gemini/Delta":1.0,"Gemini/Gamma":1.0,"Gemini/Palan":1.0,"Gemini/Delta_Prime":1.0,"Gemini/Oxford":1.0,"Gemini/Pentonville":1.0,"Gemini/Tr_Pakh":0.5}

max_flightgroups={"Gemini/Troy":25,"Gemini/Penders_Star":15,"Gemini/Junction":12}
min_flightgroups={"Gemini/Troy":22,"Gemini/Penders_Star":10,"Gemini/Junction":4}

numPatrolPoints={"Gemini/Troy":8,
	"Gemini/Xytani":3,
	"Gemini/XXN-1927":7,
	"Gemini/War":3,
	"Gemini/Varnus":3,
	"Gemini/Valhalla":4,
	"Gemini/Tr_Pakh":3,
	"Gemini/Tingerhoff":6,
	"Gemini/Telar":4,
	"Gemini/Surtur":4,
	"Gemini/Sumn_Kpta":2,
	"Gemini/Sherwood":8,
	"Gemini/Shangri_La":2,
	"Gemini/Saxtogue":3,
	"Gemini/Rygannon":3,
	"Gemini/Rikel":5,
	"Gemini/Regallis":5,
	"Gemini/Raxis":3,
	"Gemini/Ragnarok":3,
	"Gemini/Pyrenees":6,
	"Gemini/Prasepe":3,
	"Gemini/Pollux":3,
	"Gemini/Pestilence":3,
	"Gemini/Perry":9,
	"Gemini/Pentonville":2,
	"Gemini/Penders_Star":3,
	"Gemini/Palan":5,
	"Gemini/Padre":2,
	"Gemini/Oxford":4,
	"Gemini/Nitir":5,
	"Gemini/Nexus":5,
	"Gemini/New_Detroit":9,
	"Gemini/New_Constantinople":9,
	"Gemini/Newcastle":5,
	"Gemini/New_Caledonia":6,
	"Gemini/ND-57":3,
	"Gemini/Midgard":4,
	"Gemini/Metsor":2,
	"Gemini/Manchester":3,
	"Gemini/Mah_Rahn":2,
	"Gemini/Lisacc":2,
	"Gemini/KM-252":2,
	"Gemini/Junction":9,
	"Gemini/J900":3,
	"Gemini/Hyades":4,
	"Gemini/Hinds_Variable_N":5,
	"Gemini/Gamma":4,
	"Gemini/Freyja":2,
	"Gemini/Famine":4,
	"Gemini/Eden":4,
	"Gemini/DN-N1912":3,
	"Gemini/Delta":5,
	"Gemini/Delta_Prime":2,
	"Gemini/Death":3,
	"Gemini/Crab-12":3,
	"Gemini/CM-N1054":1,
	"Gemini/CMF-A":3,
	"Gemini/Castor":2,
	"Gemini/Capella":5,
	"Gemini/Blockade_Point_Tango":5,
	"Gemini/Blockade_Point_Charlie":3,
	"Gemini/Blockade_Point_Alpha":3,
	"Gemini/Beta":4,
	"Gemini/Auriga":4,
	"Gemini/Aldebran":3,
	"Gemini/44-p-im":3,
	"Gemini/41-gs":1,
	"Gemini/17-ar":3,
	"Gemini/119ce":4,
	None:3
                }


invincible_systems={"Gemini/Perry":1,
					"Gemini/New_Constantinople":1,
					"Gemini/Troy":1,
					"Gemini/Tr_Pakh":1,
					"Gemini/Pentonville":1,
					"Gemini/Tingerhoff":1,
					"Gemini/Eden":1,
					"Gemini/Delta":1,
					"Gemini/Beta":1,
					"Gemini/Gamma":1,
					"Gemini/Palan":1,
					"Gemini/Delta_Prime":1,
					"Gemini/Sherwood":1,
					"TrkPahn/SumnHhra":1,
					"TrkPahn/SumTlor":1,
					"TrkPahn/TKTarak":1,
					"TrkPahn/NDerPak":1,
					"TrkPahn/Draga":1,
					"TrkPahn/Zarnobian":1,
					"TrkPahn/TrkPhan":1,
					"TrkPahn/Bukrag":1,
					"VukarTag/KvtTag(4)":1,
					"VukarTag/KvtTag(2)":1,
					"VukarTag/Jugara":1,
					"Kilrah/Khrissak":1,
					"Kilrah/Kssak":1,
					"Kilrah/HrissthHrissith":1,
					"Kilrah/Kilrah":1,
					"Kilrah/TlanMeth":1,
					"Kilrah/KCris":1,
					"Kilrah/Mshren":1,
					"Kilrah/GwrissKrazna":1,
					"Kilrah/Kurukhag(3)":1,
					"Kilrah/Hrekkah":1,
					"Kilrah/HhrassTGhor":1,
					"Kilrah/KnTqal":1,
					"MShrak/TrKHhra(1)":1,
					"MShrak/Gorth":1,
					"MShrak/Paghk":1,
					"MShrak/Dathque(4)":1,
					"Epsilon/Ingraya":1,
					"Epsilon/Jakal":1,
					"Epsilon/Asgard":1,
					"Epsilon/Dvdtang":1,
					"Epsilon/KkThan":1,
					"Epsilon/KkTahn":1,
					"Epsilon/Shariha":1,
					"Epsilon/Khar-Sa":1,
					"Epsilon/TvxAq":1,
					"Landreich/Halgkrak(4)":1,
					"Landreich/Hralgkrak(4)":1,
					"Landreich/Vordran":1,
					"Landreich/Jigada":1,
					"Landreich/Khrovat":1,
					"Landreich/Halgkrak(9)":1,
					"Landreich/Hralgkrak(9)":1,
					"Landreich/M421A":1,
					"Sol/Mastif":1,
					"Sol/Arcturus":1,
					"Sol/ProximaCentauri":1,
					"Sol/Sol":1,
					"Sol/Tikopal":1,
					"Sol/Luyten":1,
					"Sol/Beacon":1,
					"Enigma/Vespus":1,
					"Enigma/AxiusAxis":1,
					"Enigma/FiddlersGreen":1,
					"Enigma/CallimachusCallmachius":1,
					"Enigma/HeavensGate":1,
					"Enigma/Salayna":1,
					"Enigma/Adams":1,
					"Enigma/Blake":1,
					"Enigma/Heinlein":1,
					"Enigma/Dyson":1,
					"Argent/Benford":1}

unescortable = {"paradigm":"drayman",
	"kamekh":"gothri"}

factions = ("confed","kilrathi","nephilim","merchant","retro","pirates","hunter","militia","unknown","landreich","border_worlds","firekkan","AWACS")
factiondict={}
for i in range(len(factions)):
    factiondict[factions[i]]=i

siegingfactions={"confed":500
                ,"landreich":10000
                ,"border_worlds":4000
                ,"kilrathi":1600
                ,"retro":1000
                ,"AWACS":30
                }
fightersPerFG=  {"confed":10
                ,"landreich":3
                ,"border_worlds":6
                ,"kilrathi":8
                ,"retro":4
                ,"merchant":3
                ,"pirates":6
                ,"hunter":3
                ,"militia":6
                ,"default":10
                ,"firekkan":4
                ,"AWACS":6
                }
#staticFighterProduction={"retro":3, "pirates":1}
staticFighterProduction={"retro":10, "pirates":10, "hunter":5, "confed":5, "militia":5, "merchant":5, "kilrathi":5}
fighterProductionRate=  {"confed":5
                        ,"landreich":.12
                        ,"border_worlds":.06
                        ,"kilrathi":5
                        ,"retro":5
                        ,"merchant":5
                        ,"pirates":5
                        ,"hunter":5
                        ,"militia":5
                        ,"default":5
                        ,"firekkan":.1
                        ,"AWACS":2
                        }

capitalProductionRate=  {"confed":.0001
                        ,"landreich":.015
                        ,"border_worlds":.011
                        ,"kilrathi":.0001
                        ,"retro":0.0
                        ,"merchant":.2
                        ,"pirates":.0
                        ,"hunter":0.0
                        ,"militia":0.00
                        ,"default":.02
                        ,"firekkan":.02
                        ,"AWACS":.025
                        }

homeworlds={"confed":"Sol/Sol"
                ,"kilrathi":"Kilrah/Kilrah"
                ,"nephilim":"Enigma/Shanha"
                ,"pirates":"Gemini/Pentonville"
                ,"merchant":"Gemini/New_Constantinople"
                ,"militia":"Gemini/Pyrenees"
                ,"retro":"Gemini/Eden"
                ,"hunter":"Sol/AlphaCentauri"
                ,"firekkan":"Epsilon/Firekka"
                ,"border_worlds":"Epsilon/Deneb"
                ,"landreich":"Landreich/Landreich"
		,"AWACS":"Gemini/Auriga"

                }
production_centers={"confed":["Gemini/Perry","Gemini/New_Detroit"]
                ,"kilrathi":["Gemini/Gamma","Gemini/Tr_Pakh","Gemini/Sumn_Kpta"]
                ,"nephilim":["Enigma/Shanha"]
                ,"pirates":["Gemini/Pentonville","Gemini/Sherwood","Gemini/Penders_Star","Gemini/Capella","Gemini/Telar","Gemini/KM-252"]
                ,"merchant":["Gemini/New_Constantinople","Gemini/Troy","Gemini/Oxford"]
                ,"militia":["Gemini/Pyrenees","Gemini/Rygannon","Gemini/Prasepe"]
                ,"retro":["Gemini/Eden","Gemini/Oxford"]
                ,"hunter":["Gemini/Palan","Gemini/New_Detroit"]
                ,"firekkan":["Epsilon/Firekka"]
                ,"border_worlds":["Epsilon/Deneb"]
                ,"landreich":["Landreich/Landreich"]
		,"AWACS":["Gemini/Auriga","Gemini/XXN-1927"]
                }


earnable_upgrades= {
	"confed":[["broadsword","starships/Deprecated",1250000,40,800,"The Broadsword is a commonly encountered Confederation fighter. It is equipped with a deadly array of blasters and several HS and FF missiles, which pose a severe threat to any enemy that ventures to cross its path. The Broadsword's main weaknesses lie in its slow speed, low maneuverability and limited acceleration powers.  If you are flying a very maneuverable ship in an encounter with this vessel, the odds are definitely in your favor. A side attack on the weaker port and starboard armor is advisable."],
		["stiletto","starships/Confed/Milspec",2000000,80,1600,"The stiletto is the fastest ship in the Confederation fleet. WIth an afterburner velocity of 1400 kps and excellent maneuverability, it can evade even the swifted Kilrathi fighters. The stiletto's weakness lies in the extremely flimsy armor and relatively light weapons loadout.  If you encounter an experienced pilot in a Stiletto, however, you should prepare for a grueling combat because his high maneuverability lets him get uncomfortably close."],
		["paradigm","starships/Deprecated",8700000,2150,43000,"The Paradigm is one of the Confederations most advanced destroyers. Featuring almost impregnable armor and shields, it more than compensates for a lack of speed and maneuverability.  The paradigm also has a deadly array of weapons at its disposal making an attack of any sort extremely dangerous.  It carries an astonishing variety of blasters, ranging frmo meson blasters to ionic pulse cannons.  Multiple missiles can deter even the most aggressive Kilrathi aces."],
		["broadsword.blank","starships/Confed/Heavy",780000,40,1000,"The Broadsword is a commonly encountered Confederation fighter. It is equipped with a deadly array of blasters and several HS and FF missiles, which pose a sever threat to any enemy that ventures to cross its path. The Broadsword's main weaknesses lie in its slow speed, low maneuverability and limited acceleration powers.  If you are flying a very maneuverable ship in an encounter with this vessel, the odds are definitely in your favor. A side attack on the weaker port and starboard armor is advisable."],
		["stiletto.blank","starships/Confed/Light",280000,80,1600,"The stiletto is the fastest ship in the Confederation fleet. WIth an afterburner velocity of 1400 kps and excellent maneuverability, it can evade even the swifted Kilrathi fighters. The stiletto's weakness lies in the extremely flimsy armor and relatively light weapons loadout.  If you encounter an experienced pilot in a Stiletto, however, you should prepare for a grueling combat because his high maneuverability lets him get uncomfortably close."]],
	"militia":[["gladius","starships/Deprecated",450000,40,800,"The Gladius combines good velocity and acceleration with an effective and varied array of weapons. Its torpedos make it an effective fighter for combat against capital ships. With its fairly strong blaster loadout and HS missiles, the Gladius is a versatile dogfighting spacecraft.  Due to its maneuverability, it is hard to target one accurately, but just a few target hits can down a Gladius because of its weak shields."],
		["gladius.blank","starships/Confed/Medium",80000,40,1000,"The Gladius combines good velocity and acceleration with an effective and varied array of weapons. Its torpedos make it an effective fighter for combat against capital ships. With its fairly strong blaster loadout and HS missiles, the Gladius is a versatile dogfighting spacecraft.  Due to its maneuverability, it is hard to target one accurately, but just a few target hits can down a Gladius because of its weak shields."]],
	"kilrathi":[["dralthi.blank","starships/Kilrathi/Light",450000,132,2700,"The only starship to be present in most every era of the Human-Kilrathi war."],
		["gothri.blank","starships/Kilrathi/Heavy",600000,197,4000,"The Kilrathi Gothri can pose a very real threat to any ship in the Gemini Sector.  With its impressive acceleration, it can reach high velocities. When you are facing a Gorthri in combat, you should concentrate on its weak armor.  A few well placed concentrated bursts of gunfire can severely damage this fighter.  However, it is not that easy to close on it.  The Gothri is very maneuverable and can easily down you first with its array of blasters."],
		["salthi.blank","starships/Kilrathi/Heavy",300000,216,4400,"Unknown describes just about every aspect of this fighter that people simply do not see on the front."]],
	"hunter":[["demon.blank","starships/Hunter/Light",125000,40,1000,"The Demon combines high velocities and powerful acceleration powers with a wide array of deadly weapons.  Its torpedo loadout can even take out capital ships like the Kamekh or Paradigm with relative ease.  If you are forced to fight the Demon in a close dogfight, try to make a side attack on that location's weak armor."],
		["demon","starships/Deprecated",185000,40,1000,"The Demon combines high velocities and powerful acceleration powers with a wide array of deadly weapons.  Its torpedo loadout can even take out capital ships like the Kamekh or Paradigm with relative ease.  If you are forced to fight the Demon in a close dogfight, try to make a side attack on that location's weak armor."],
		["centurion","starships/Deprecated",400000,40,1000,"This is the workhorse of the mercenary community. The centurion is a heavy fighter with the ability to do almost any gun-for-hire work. The limited cargo hold can contain more than an overnight bag, but not by much.  This is a ship for those pilots who love to fly, but it won't make you a living on the trade circuit."],
		["orion","starships/Deprecated",180000,40,1000,"The orion is perhapos the safest of all vehicles.  It can carry the most armor and shields of all ships in the Gemini sector (at the expense of its maneuverability). This is a sturdy ship, designed to last."]],
	"pirates":[["talon","starships/Deprecated",70000,38,800,"The Talon is probably the ship you will encounter most often in Gemini. Flown by numerous different factions it may appear in slightly different designs but its weapon loadouts and dynamics remain the same.  You should take extreme care to keep the Talon away from your rear, since it is equipped with numerous HS missiles. If you are an accomplished pilot, you should be able to take out a Talon with relative ease, especially if you are flying a Stiletto or Centurion, since its armor is extremely weak. Try to avoid its particle cannon, since a hit can inflict sizable damage."],
		#["talon","The retros, being by their nature not given to grand industrialization, rely on a small number of hidden facilities and sympathetic manufacturing plants to supply them with ships. The Talon bears the distinction of being the only class of spacecraft officially sanctioned by the reverend Sverde, who, when presented with its initial designs 45 years ago, said that prayer had revealed to her that that this was to be the 'shepherds crook' by which man's sins would be constrained. Inexpensive, even at the time of its introduction, the Talon remains a utilitarian craft well suited to the production schedules of backwater worlds."],
		["talon.blank","starships/Pirate/Light",40000,40,1000,"The Talon is probably the ship you will encounter most often in Gemini. Flown by numerous different factions it may appear in slightly different designs but its weapon loadouts and dynamics remain the same.  You should take extreme care to keep the Talon away from your rear, since it is equipped with numerous HS missiles. If you are an accomplished pilot, you should be able to take out a Talon with relative ease, especially if you are flying a Stiletto or Centurion, since its armor is extremely weak. Try to avoid its particle cannon, since a hit can inflict sizable damage."]],
	"merchant":[["drayman.blank","starships/Merchant/Light_Capship",1200000,1000000,40000000,"Lumbering doesn't begin to describe the speed at which Drayman cargo vessels deliver massive quantities of cargo to their destination. If it wasn't for the thick armor this starship has, most would succumb to their enemies before limited help arrived."],
		["galaxy","starships/Deprecated",270000,20000,570000,"A versatile merchant's vessel, the Galaxy is perfect for those with an entrepreneurial spirit.  She is by no means a military vessel, but a Galaxy can usually protect herself and the large amount of cargo she's able to carry."],
		["drayman","starships/Deprecated",1500000,1000000,40000000,"Lumbering doesn't begin to describe the speed at which Drayman cargo vessels deliver massive quantities of cargo to their destination. If it wasn't for the thick armor this starship has, most would succumb to their enemies before limited help arrived."]],
	"tech":[["mult_shield_regenerator","upgrades/Shield_Systems/Heavy",170000,0.01,1,"@upgrades/shield_regenerator.png@Increases the recharge rate of shields."],
		["gun_cooler","upgrades/Reactors/Heavy",300000,0.01,1,"@upgrades/gun_cooler.png@A more powerful radiator unit for the mount decreases the refire delay."],
		["mult_speed_enhancer","upgrades/Engines/Engine_Enhancements_Heavy",240000,0.01,1,"@upgrades/speedenhancer.png@By improving the tolerances on a vessel's passive particle shielding and autocompensating software, higher speeds can be safely reached before the shields must be expanded and thereby thinned."],
		["fusion_gun","upgrades/Weapons/Mounted_Guns_Heavy",100000,0.01,1,"@upgrades/fusion.png@"],
		["medium_turret_fusion","upgrades/Weapons/Turrets",217500,0.1,1,"@upgrades/turret_medium.png@Equipped with two fusion cannons and a tractor beam.  It turns, it shoots, it slices. No, it does not dice, but it does come with a free fuzzy pair."],
		["medium_turret_rear_fusion","upgrades/Weapons/Turrets",217500,0.1,1,"@upgrades/turret_rear.png@Equipped with two fusion cannons and a tractor beam.  It turns, it shoots, it slices. No, it does not dice, but it does come with a free fuzzy pair. Perfect for the back of your ship."],
		["salthi.blank","starships/Kilrathi/Heavy",300000,216,4400,"Unknown describes just about every aspect of this fighter that people simply do not see on the front."],
		["reactor_level_4","upgrades/Reactors/Heavy",100000,0.01,1,"@upgrades/engine4.png@Standard heavy reactor (level 4)."],
		["reactor_level_5_galaxy","upgrades/Reactors/Heavy",150000,0.01,1,"@upgrades/engine5.png@Heavy reactor modified to fit within the limited constraints of the galaxy (level 5)."],
		["reactor_level_6","upgrades/Reactors/Heavy",250000,0.01,1,"@upgrades/engine6.png@Standard heavy reactor (level 5)."],
		["reactor_level_7","upgrades/Reactors/Heavy",350000,0.01,1,"@upgrades/engine7.png@Standard heavy reactor (level 5)."],
		["shield_4_Level4","upgrades/Shield_Systems/Heavy",100000,0.01,1,"@upgrades/shields.png@A combination of magnetic and gravitic protective shields. 4 emitter model."],
		["shield_4_Level5_galaxy","upgrades/Shield_Systems/Heavy",150000,0.01,1,"@upgrades/shields.png@A combination of magnetic and gravitic protective shields, specifically tailored to the galaxy class vessel's limited upgrade slots and power feeds. 4 emitter model."],
		["shield_4_Level6","upgrades/Shield_Systems/Heavy",180000,0.01,1,"@upgrades/shields.png@A combination of magnetic and gravitic protective shields. 4 emitter model."],
		["shield_4_Level7","upgrades/Shield_Systems/Heavy",200000,0.01,1,"@upgrades/shields.png@A combination of magnetic and gravitic protective shields. 4 emitter model."],
		["isometal","upgrades/Armor/Confed_Milspec",6000,0.01,1,"@upgrades/isometal.png@Making the armor structure very regular, the armor is made much stronger."],
		["add_small_cargo_volume","upgrades/Miscellaneous",18000,8,4,"@upgrades/cargo_expansion.png@A smaller cargo expansion can fit on most starships, yet causes a reduction in the effectiveness of the intertial compensators. With one of these, don't plan on accelerating quickly to get out a fight."],
		["isometal_hull","upgrades/Hull/Confed_Milspec",12000,10,0,"@upgrades/isometal.png@Making the hull structure very regular, this hull coating is made much stronger."]],
	"shield2":[["shield_2_Level1","upgrades/Shield_Systems/Light",9000,0.01,1,"@upgrades/shields.png@A combination of magnetic and gravitic protective shields. 2 emitter model."],
		["shield_2_Level2","upgrades/Shield_Systems/Medium",25000,0.01,1,"@upgrades/shields.png@A combination of magnetic and gravitic protective shields. 2 emitter model."],
		["shield_2_Level3","upgrades/Shield_Systems/Medium",40000,0.01,1,"@upgrades/shields.png@A combination of magnetic and gravitic protective shields. 2 emitter model."],
		["shield_2_Level5","upgrades/Shield_Systems/Heavy",140000,0.01,1,"@upgrades/shields.png@A combination of magnetic and gravitic protective shields. 2 emitter model."]],
	
	"shield2_tech":[["shield_2_Level4","upgrades/Shield_Systems/Heavy",90000,0.01,1,"@upgrades/shields.png@A combination of magnetic and gravitic protective shields. 2 emitter model."],
		["shield_2_Level6","upgrades/Shield_Systems/Heavy",180000,0.01,1,"@upgrades/shields.png@A combination of magnetic and gravitic protective shields. 2 emitter model."],
		["shield_2_Level7","upgrades/Shield_Systems/Heavy",200000,0.01,1,"@upgrades/shields.png@A combination of magnetic and gravitic protective shields. 2 emitter model."]]}


useBlank = (   0    ,  0   ,   0   ,     0    ,   0   ,       0     ,    0   ,         0    ,      0  ,    0,         0    ,    0   ,   0)


enemies =  ((kilrathi,pirates,kilrathi,retro,pirates,retro), #confed
            (confed,confed,confed,confed,confed,confed,militia,pirates,hunter,merchant,), #kilrathi
            (kilrathi,kilrathi,kilrathi,kilrathi,kilrathi,kilrathi,kilrathi,kilrathi,pirates,retro,retro,retro,retro,retro,hunter),#nephilim
            (pirates,pirates,retro,pirates,pirates,kilrathi,retro,pirates,pirates,pirates,pirates,kilrathi,retro), #merchant
            (pirates,militia,confed,merchant,kilrathi,hunter,hunter,hunter), #retro
            (confed,militia,militia,militia,retro,kilrathi,merchant,merchant,retro,merchant,merchant,merchant,merchant,merchant,merchant), #pirates
            (kilrathi,kilrathi,retro,retro,pirates,pirates), #hunter
            (pirates,retro,pirates,kilrathi,retro,pirates), #militia
            (confed,kilrathi,merchant,retro,pirates,hunter,militia,), #unknown
            (kilrathi,kilrathi,retro,militia), #landreich
            (kilrathi,kilrathi,retro), #border_worlds
            (kilrathi,kilrathi,retro,retro,pirates), #firekkan
            (kilrathi,kilrathi,kilrathi,kilrathi,confed,militia,retro,retro,hunter,hunter,hunter,), #firekkan
           )

rabble  =  ((retro,retro,retro,retro,pirates,pirates,pirates,pirates,pirates,pirates,pirates,pirates,pirates,retro,retro,retro,retro,pirates,pirates,pirates,pirates,pirates,pirates,pirates,pirates,pirates,retro,retro,retro,retro,pirates,pirates,pirates,pirates,pirates,pirates,pirates,pirates,pirates), #confed
            (pirates,pirates,pirates,hunter,hunter,pirates,pirates,pirates,hunter,hunter), #kilrathi
            (pirates,pirates,pirates,pirates,kilrathi,confed,hunter,hunter,hunter),#nephilim
            (pirates,retro,pirates,retro,pirates,hunter,merchant), #merchant
            (unknown,unknown,unknown,pirates,hunter), #retro
            (hunter,retro,retro,pirates,pirates,pirates,merchant), #pirates
            (pirates,retro,hunter,hunter,hunter), #hunter
            (retro,retro,pirates,pirates,pirates), #militia
            (pirates,pirates,pirates,pirates,retro,kilrathi,), #unknown
            (retro,militia), #landreich
            (retro,retro,retro,kilrathi), #border_worlds
            (retro,retro,pirates), #firekkan
            (confed,militia,retro,retro,hunter,hunter,hunter,), #AWACS
           )


insysenemies  =  enemies






friendlies=((confed,confed,confed,confed,confed,confed,confed,confed,confed,confed,militia,militia,militia,militia,merchant,merchant,merchant,merchant,merchant,), #confed
            (kilrathi,kilrathi,kilrathi,kilrathi,kilrathi,kilrathi,kilrathi,kilrathi,kilrathi,kilrathi,kilrathi,kilrathi,kilrathi,kilrathi), #kilrathi
            (merchant,nephilim,nephilim,nephilim,nephilim,merchant,nephilim,nephilim,nephilim,nephilim), #nephilim
            (confed,militia,militia,militia,militia,merchant,merchant,merchant,merchant,merchant,hunter,hunter,), #merchant
            (retro,retro,retro,unknown), #retro
            (pirates,pirates,pirates,pirates,pirates), #pirates
            (confed,confed,militia,militia,merchant,hunter,hunter,hunter,hunter,hunter,merchant), #hunter
            (confed,confed,confed,militia,militia,militia,militia,merchant,merchant,merchant,merchant,merchant,), #militia
            (merchant,merchant,merchant,merchant,merchant,merchant), #ISO
            (pirates,retro,retro,retro,retro,retro,retro,retro,retro,unknown,), #unknown
            (landreich,landreich,pirates,merchant,merchant,merchant,border_worlds,border_worlds,border_worlds,border_worlds), #landreich
            (landreich,landreich,militia,merchant,merchant,border_worlds,border_worlds,border_worlds,border_worlds), #border_worlds
            (confed,confed,confed,militia,militia,militia,militia,merchant,merchant,merchant,merchant,merchant,landreich,border_worlds,firekkan,firekkan),  #firekkan
            (AWACS,AWACS,merchant)#AWACS
           )
def Precache():
  import VS
  tmp=VS.vsConfig("graphics","precache","false")
  if tmp=="true" or tmp=="1":
    VS.precacheUnit("stiletto","confed")
    VS.precacheUnit("dumbfire","confed")
    VS.precacheUnit("imrec","confed")
    VS.precacheUnit("friendorfoe","confed")
    VS.precacheUnit("heatseek","confed")
    VS.precacheUnit("dumbfire","militia")
    VS.precacheUnit("imrec","militia")
    VS.precacheUnit("friendorfoe","militia")
    VS.precacheUnit("heatseek","militia")
    VS.precacheUnit("dumbfire","pirates")
    VS.precacheUnit("imrec","pirates")
    VS.precacheUnit("friendorfoe","pirates")
    VS.precacheUnit("heatseek","pirates")
    VS.precacheUnit("dumbfire","retro")
    VS.precacheUnit("imrec","retro")
    VS.precacheUnit("friendorfoe","retro")
    VS.precacheUnit("heatseek","retro")
    VS.precacheUnit("dumbfire","privateer")
    VS.precacheUnit("imrec","privateer")
    VS.precacheUnit("friendorfoe","privateer")
    VS.precacheUnit("heatseek","privateer")
    VS.precacheUnit("dumbfire","merchant")
    VS.precacheUnit("imrec","merchant")
    VS.precacheUnit("friendorfoe","merchant")
    VS.precacheUnit("heatseek","merchant")
    VS.precacheUnit("dumbfire","hunter")
    VS.precacheUnit("imrec","hunter")
    VS.precacheUnit("friendorfoe","hunter")
    VS.precacheUnit("heatseek","hunter")
    VS.precacheUnit("dumbfire","kilrathi")
    VS.precacheUnit("imrec","kilrathi")
    VS.precacheUnit("friendorfoe","kilrathi")
    VS.precacheUnit("heatseek","kilrathi")
    VS.precacheUnit("stiletto","confed")
    VS.precacheUnit("gladius","militia")
    VS.precacheUnit("dralthi","kilrathi")
    VS.precacheUnit("gothri","kilrathi")
    VS.precacheUnit("talon","militia")
    VS.precacheUnit("talon.blank","pirates")
    VS.precacheUnit("talon.blank","retro")
    VS.precacheUnit("orion.blank","hunter")
    VS.precacheUnit("demon.blank","hunter")
    VS.precacheUnit("orion.blank","merchant")
    VS.precacheUnit("galaxy.blank","merchant")
    VS.precacheUnit("tarsus.blank","merchant")
    VS.precacheUnit("centurion.blank","hunter")
    VS.precacheUnit("drayman.blank","merchant")
    VS.precacheUnit("cargobrick","upgrades")
    VS.precacheUnit("Grain.cargo","upgrades")
    VS.precacheUnit("Grain","upgrades")
    VS.precacheUnit("Furs.cargo","upgrades")
    VS.precacheUnit("Furs","upgrades")
    VS.precacheUnit("Advanced_Fuels.cargo","upgrades")
    VS.precacheUnit("Advanced_Fuels","upgrades")
    VS.precacheUnit("Communications.cargo","upgrades")
    VS.precacheUnit("Communications","upgrades")
    VS.precacheUnit("Computers.cargo","upgrades")
    VS.precacheUnit("Computers","upgrades")
    VS.precacheUnit("Construction.cargo","upgrades")
    VS.precacheUnit("Construction","upgrades")
    VS.precacheUnit("Home_Appliances.cargo","upgrades")
    VS.precacheUnit("Home_Appliances","upgrades")
    VS.precacheUnit("Space_Salvage.cargo","upgrades")
    VS.precacheUnit("Space_Salvage","upgrades")
    VS.precacheUnit("Weaponry.cargo","upgrades")
    VS.precacheUnit("Weaponry","upgrades")
  
fighters = (("stiletto","stiletto","broadsword",), #confed
            ("dralthi","dralthi","gothri",), #kilrathi  
            ("steltek_fighter",), #nephilim
            ("tarsus","tarsus","galaxy","galaxy","galaxy","orion",), #merchant
            ("talon","talon","talon.retro2",), #retro
            ("talon","talon","talon.pirlaser","talon.pirmeson",), #pirates
            ("demon","demon","demon","orion.hunter","centurion",), #hunter
            ("talon","gladius",), #militia
            ("salthi","salthi.particle"), #unknown
                        ("tarsus","gladius","talon","talon","talon","drayman",),#landreich
                        ("tarsus","gladius","talon","talon","talon","drayman",),#border_worlds
                        ("stiletto",), #firekkan
                        ("stiletto",), #AWACS
           )
isBomber = {"broadsword":2,"gladius":4,"gothri":6}

capitals = (("paradigm",), #confed
            ("kamekh",), #kilrathi
            ("done",), #nephilim
            ("drayman",), #merchant
            ("drayman",), #retro
            ("drayman",), #pirates
            ("drayman",), #hunter
            ("drayman",), #militia
            ("kamekh",), #unknown
                        ("drayman",),#landreich
                        ("paradigm",),#border_worlds
                        ("drayman",), #firekkan
                        ("paradigm","drayman","drayman","drayman",), #AWACS
           )

stattable={
        #SHIPNAME:(CHANCE_TO_HIT,CHANCE_TO_DODGE,DAMAGE,SHIELDS,ORDINANCE_DAMAGE),
        "talon":(0.45,0.38,18.77,36,32),
        "gladius":(0.48,0.58,19.81,40,52),
        "stiletto":(0.67,0.7,16,31,64),
        "demon":(0.6,0.68,28,42,52),
        "broadsword":(0.44,0.48,95.8,80,148),
        "tarsus":(0.1,0.15,10.94,36,32),
        "galaxy":(0.1,0.2,32.8,80,38),
        "orion":(0.3,0.2,22.9,168,16),
        "centurion":(0.64,0.6,39,65,38),
        "drayman":(0.05,0.05,16,121,0),
        "drone":(0.68,0.95,200,470,400),
        "salthi.particle":(0.66,0.68,25.2,36,32),
        "salthi.steltek":(0.66,0.68,36,36,32),
        "salthi":(0.66,0.68,36,36,32),
        "dralthi":(0.62,0.66,18,52.5,48),
        "gothri":(0.45,0.6,56.1,50,68),
        "paradigm":(0.2,0.2,77.22,260,66),
        "kamekh":(0.26,0.2,68.3,220,66),
        "shoklar":(0.8,0.6,15.64,60,16),
	"mining_base":(0,0,0,1000,0),
	"new_constantinople":(0,0,0,4000,0),
	"perry":(.5,0,600,6000,500),
	"refinery":(0,0,0,800,0),
        "talon.retro2":(0.45,0.38,18.77,36,32),
        "talon.pirmeson":(0.45,0.38,18.77,36,32),
        "talon.pirlaser":(0.45,0.38,18.77,36,32),
        "orion.hunter":(0.55,0.25,22.9,168,16),
        "orion.plasma":(0.55,0.25,22.9,168,16),
        "orion.ionturret":(0.55,0.25,22.9,168,16),
        "galaxy.pirpar":(0.3,0.2,32.8,80,38),
        "galaxy.rhombus":(0.3,0.2,32.8,80,38),
        "centurion.tachpar":(0.64,0.6,39,65,38),
        "centurion.ion":(0.64,0.6,39,65,38),
        "centurion.plasma":(0.64,0.6,39,65,38),
        "centurion.bronte":(0.64,0.6,39,65,38),
        "centurion.garrovick":(0.64,0.6,39,65,38),
        "centurion.riordian":(0.64,0.6,39,65,38),
        "centurion.menesch":(0.64,0.6,39,65,38),
        "centurion.jones":(0.64,0.6,39,65,38),
        "centurion.":(0.64,0.6,39,65,38),
        "drayman.books":(0.05,0.05,16,121,0),
        "drayman.toth":(0.05,0.05,16,121,0),
        "drayman.transport":(0.05,0.05,16,121,0),
        "dralthi.tachyon":(0.62,0.66,18,52.5,48),
        "dralthi.ion":(0.62,0.66,18,52.5,48),
        "gothri.tachyon":(0.45,0.6,56.1,50,68),
        "gothri.plasma":(0.45,0.6,56.1,50,68),
        "gothri.particle":(0.45,0.6,56.1,50,68),
        "demon.laser":(0.6,0.68,28,42,52),
        "demon.ion":(0.6,0.68,28,42,52),
        "demon.bronte":(0.6,0.68,28,42,52),
        "demon.tachyon":(0.6,0.68,28,42,52),
        "demon.kroiz":(0.6,0.68,28,42,52),
        }

def blankify(tup):
    ret=[]
    for i in tup:
        ret.append(i*.75)
    return tuple(ret)

for i in tuple(stattable.keys()):
	stattable[i+".blank"]=blankify(stattable[i])


def GetStats ( name):
    try:
        return stattable[name]
    except:
        print 'GetStats: cannot find '+name
        return (.5,.5,1,1,1)


capitols=capitals
capitaldict={}
for i in capitols:
    for j in i:
        capitaldict[j]=1
for i in capitols:
    for j in i:
        capitaldict[j+'.blank']=1

def isCapital(type):
    return type in capitaldict

generic_bases = ("perry","perry",
                                 "new_constantinople","new_constantinople","new_constantinople","new_constantinople",
                                 "mining_base","mining_base","mining_base","mining_base","mining_base","mining_base","mining_base","mining_base","mining_base","mining_base",
                                 "refinery","refinery","refinery","refinery","refinery","refinery",)
bases = (generic_bases,
                 generic_bases, #kilrathi
                 generic_bases, #nephilim
                 generic_bases, #merchant
                 generic_bases, #retro
                 generic_bases, #pirates
                 generic_bases, #hunter
                 generic_bases, #militia
                 generic_bases, #unknown
                 generic_bases,#landreich
                 generic_bases,#border_worlds
                 generic_bases, #firekkan
                 )
basedict={}
for i in bases:
    for j in i:
        basedict[j]=1

def appendName(faction):
    from difficulty import usingDifficulty
    if (useBlank[faction] and usingDifficulty()):
        return ".blank"
    else:
        return ""

def factionToInt  (faction):
    try:
        return factiondict[faction]
    except:
        return 0
    return 0

def intToFaction (faction):
    return factions[faction]

def getMaxFactions ():
    return len(factions)



    

def get_non_citizen_X_of (mylist, index):
    import vsrandom
    import VS
    enemylist = mylist[index]
    newindex = vsrandom.randrange(0,len(enemylist))
    rez=intToFaction(enemylist[newindex])
    if VS.isCitizen(rez):
        while (newindex>0):
          newindex-=1
          rez=intToFaction(enemylist[newindex])          
          if not VS.isCitizen(rez):
              return rez
        while (newindex+1<len(enemylist)):
          newindex+=1
          rez=intToFaction(enemylist[newindex])          
          if not VS.isCitizen(rez):
              return rez
    return rez
def get_X_of (mylist, index):
    import vsrandom
    enemylist = mylist[index]
    newindex = vsrandom.randrange(0,len(enemylist))
    return intToFaction(enemylist[newindex])


def get_enemy_of (factionname):
    return get_X_of (enemies, factionToInt(factionname))

def get_insys_enemy_of (factionname):
    return get_X_of (insysenemies, factionToInt(factionname))

def get_friend_of (factionname):
    return get_X_of (friendlies, factionToInt(factionname))

def get_rabble_of (factionname):
    return get_X_of (rabble, factionToInt(factionname))


def get_enemy_of_no_citizen (factionname):
    return get_X_of (enemies, factionToInt(factionname))
    #return get_non_citizen_X_of (enemies, factionToInt(factionname))

def get_insys_enemy_of_no_citizen (factionname):
    return get_X_of (insysenemies, factionToInt(factionname))
    #return get_non_citizen_X_of (insysenemies, factionToInt(factionname))

def get_friend_of_no_citizen (factionname):
    return get_X_of (friendlies, factionToInt(factionname))
    #return get_non_citizen_X_of (friendlies, factionToInt(factionname))

def get_rabble_of_no_citizen (factionname):
    return get_X_of (rabble, factionToInt(factionname))
    #return get_non_citizen_X_of (rabble, factionToInt(factionname))

def getRandomShipType(ship_list):
    import vsrandom
    index=vsrandom.randrange(0,len(ship_list))
    return ship_list[index]

def getFigher(confed_kilrathi_or_nephilim, fighter):
    fighterlist = fighters[confed_kilrathi_or_nephilim]
    fighterlist = fighterlist[fighter]
    return fighterlist+appendName(confed_kilrathi_or_nephilim)

def getRandomFighterInt(confed_kilrathi_or_nephilim):
    return getRandomShipType(fighters[confed_kilrathi_or_nephilim])+appendName(confed_kilrathi_or_nephilim)

def getNumCapitol (confed_kilrathi_or_nephilim):
    return len(capitols[confed_kilrathi_or_nephilim])

def getNumFighters (confed_kilrathi_or_nephilim):
    lst = fighters[confed_kilrathi_or_nephilim]
    return len(lst)

def getCapitol(confed_kilrathi_or_nephilim, fighter):
    caplist = capitols[confed_kilrathi_or_nephilim]
    caplist = caplist[fighter]
    return caplist

def getRandomCapitolInt(confed_kilrathi_or_nephilim):
    lst = capitols[confed_kilrathi_or_nephilim]
    return getRandomShipType(lst)

def getRandomFighter(faction):
    return getRandomFighterInt (factionToInt (faction))

def getRandomCapitol (faction):
    return getRandomCapitolInt (factionToInt (faction))

launch_distance_factor=.03

max_radius=5000

min_distance=250
min_forward_distance=750

radarRanges = {
        "iris_mk1" : 1500,
        "iris_mk2" : 1750,
        "iris_mk3" : 2000,
        "hunter_aw_6" : 2000,
        "hunter_aw_6i" : 2250,
        "hunter_aw_infinity" : 2500,
        "B_and_S_Tripwire" : 2500,
        "B_and_S_EYE" : 2750,
        "B_and_S_Omni" : 3000 }

def calcRadarRange( playerShip):
	for i in range( playerShip.numCargo()):
	    cargo = playerShip.GetCargoIndex( i)
	    cargoName = cargo.GetContent()
            cargoCategory = cargo.GetCategory()
            if cargoCategory[:14] == 'upgrades/Radar' or cargoCategory[:22] == 'upgrades/Damaged/Radar':
                print "PODXX radar name: " + cargoName + ", detect range: " + str( radarRanges[cargoName])
                return radarRanges[cargoName]
        return 1500
        

