| Path | 
                
                    | Scripts/feudal-buoy.js | this.name = "feudal-buoy.js";
this.author = "Ramirez";
this.copyright = "January 2013";
this.description = "Script used by feudal Tournament Buoys to monitor and send instructions to ships";
this.version = "3.0";
this.shipSpawned = function()
{if(missionVariables.feudal_tournament == "EVENT5_RUNNING")
this.ship.switchAI("nullAI.plist")}
this.logDetails = function()
{
//log('running scan...')
var list = system.allShips
for (var i=0; i<list.length; i++)
    
    {
    var list2 = list[i].roles  
    var housearray = new Array()
    housearray[0] = "Aronar"
    housearray[1] = "Geinona"
    housearray[2] = "Tibedied"
    housearray[3] = "Tibecea"
    housearray[4] = "Esredice"
    housearray[5] = "Edzaon"
    housearray[6] = "Onusorle"
    housearray[7] = "Oreseren"
    housearray[8] = "Digebiti"
    housearray[9] = "Gelaed"
    housearray[10] = "Ededleen"
    
    housearray[11] = "Ridivexe"
    housearray[12] = "Bedierat"
    housearray[13] = "Esceso"
    housearray[14] = "Erlaened"
    housearray[15] = "Usedge"
    housearray[16] = "Rabiarce"
    housearray[17] = "Orverace"
    housearray[18] = "Reenus"
    housearray[19] = "Israra"
    housearray[20] = "Issoinen"
    housearray[21] = "Arries"
    housearray[22] = "Oneded"
    
    housearray[23] = "Biarandi"
    housearray[24] = "Usteer"
    housearray[25] = "Qurexein"
    housearray[26] = "Erinain"
    housearray[27] = "Ansois"
    housearray[28] = "Ceorat"
    housearray[29] = "Teususdi"
    housearray[30] = "Diqudi"
    housearray[31] = "Sogeve"
    housearray[32] = "Resoisbe"
    housearray[33] = "Atlaar"
    housearray[34] = "Enbirare"
    housearray[35] = "Zagearbe"
    housearray[36] = "Rizace"
    housearray[37] = "Atbiarxe"
    housearray[38] = "Enlaonus"
    housearray[39] = "Tiuson"
    housearray[40] = "Erxearis"
    housearray[41] = "Essoza"
    housearray[42] = "Mainon"
    housearray[43] = "Qutecete"
    housearray[44] = "Aniseres"
    housearray[45] = "Onertius"
    housearray[46] = "Dierlabe"
    housearray[47] = "Rileaa"
    housearray[48] = "Onente"
    housearray[49] = "Mazare"
    housearray[49] = "Inrearbi"
    //log('house array established')
    
   for (var j=0; j<housearray.length; j++)
   {
      
      if(list[i].AI == "feudal-meleeAI.plist")
      
      {
       if (list2.indexOf(housearray[j]+"-knight")!=-1)
       {
         
         
        missionVariables.feudal_tournament_opponent_role = housearray[j]+"-knight"
        missionVariables.feudal_tournament_opponent_house = housearray[j]
        missionVariables.feudal_tournament_opponent_rank_no = 1  
        log([missionVariables.feudal_tournament_opponent_role])
        list[i].switchAI("feudal-challengerhomeAI.plist") 
        }
    
    if (list2.indexOf(housearray[j]+"-lord")!=-1)
    {   missionVariables.feudal_tournament_opponent_role = housearray[j]+"-lord"
        missionVariables.feudal_tournament_opponent_house = housearray[j]
        missionVariables.feudal_tournament_opponent_rank_no = 2
        list[i].switchAI("feudal-challengerhomeAI.plist")
        //log([missionVariables.feudal_tournament_opponent_role])
    }
    if (list2.indexOf(housearray[j]+"-prince")!=-1)
    {   missionVariables.feudal_tournament_opponent_role = housearray[j]+"-prince"
        missionVariables.feudal_tournament_opponent_house = housearray[j]
        missionVariables.feudal_tournament_opponent_rank_no = 3
        list[i].switchAI("feudal-challengerhomeAI.plist")
        //log([missionVariables.feudal_tournament_opponent_role])
    }
      }
    
    }}
}
this.checkDistanceToPlayer = function()
{if(player.ship.position.distanceTo(this.ship) < 5000)
    {   ++missionVariables.feudal_tournament_kills
        player.commsMessage("Great shot! Score: "+[missionVariables.feudal_tournament_kills]+" out of 10.")}            
                
   else
        player.commsMessage("Foul shot. Score: "+[missionVariables.feudal_tournament_kills]+" out of 10")
   }
 | 
                
                    | Scripts/feudal-cargo.js | this.name = "feudal-cargo.js";
this.author = "Ramirez";
this.copyright = "November 2010";
this.description = "Ship script cargo in fuedal missions";
this.version = "2.0";
this.shipSpawned = function ()
{if(this.ship.displayName == this.ship.name)
        this.ship.displayName = expandDescription("[mission_feudal_mission_house] [mission_feudal_mission_commodity] shipment") // Show the ID of the cargo container
}
this.shipWasScooped = function (whom)
    {   if(missionVariables.feudal_mission == "RAID_SUCCESS")
    
        {   if(whom == player.ship)
				{
                missionVariables.feudal_mission_cargocount = (++ missionVariables.feudal_mission_cargocount)
                }
            else return
        }
            
            
        if(missionVariables.feudal_mission == "ESCORT_FAIL")
    
        {   if(whom == player.ship)
		
                missionVariables.feudal_mission_cargocount = (++ missionVariables.feudal_mission_cargocount)
                
            else return
        }
        
       
    } | 
                
                    | Scripts/feudal-challenge.js | this.name = "feudal-challenge.js";
this.author = "Ramirez";
this.copyright = "October 2012";
this.description = "World script for setting up feudal challenges";
this.version = "9.0";
// Event handlers
this.startUp = function()
{if(!missionVariables.feudal_planetinfo)
	 {missionVariables.feudal_planetinfo = "SET"
	 this.setPlanetOverrides()}
	 
if(missionVariables.feudal_planetinfo.indexOf(galaxyNumber) == -1)
	{this.setPlanetOverrides()}
}
this.shipDockedWithStation = function()
{this.missionScreens()}
this.guiScreenChanged = function()
{if(guiScreen == "GUI_SCREEN_MARKET")
this.missionScreens()}
//defining possible ships
this.defineChallengerShips = function()
	{ 	if(missionVariables.feudal_challenger_ship == "Ritter-Class Jaeger")
		missionVariables.feudal_challenger_role = [missionVariables.feudal_challenger_house]+"-knight"
	
		if(missionVariables.feudal_challenger_ship == "Freiherr-Class Korvette")
		missionVariables.feudal_challenger_role = [missionVariables.feudal_challenger_house]+"-lord"
		if(missionVariables.feudal_challenger_ship == "Prinz-Class Zerstoerer")
		missionVariables.feudal_challenger_role = [missionVariables.feudal_challenger_house]+"-prince"
	}
	
this.defineChallengerGender = function() // pick a gender and house
{	
	 for (var i=0; i<5; i++) missionVariables.feudal_challenger_house = expandDescription("[feudal_house_"+[galaxyNumber]+"]")
	missionVariables.feudal_challenger_gender = expandDescription("[feudal_gender]")
		
		if(missionVariables.feudal_challenger_gender == "he")
		{	
			missionVariables.feudal_challenger_level1_title = "Sir"
			missionVariables.feudal_challenger_level2_title = "Lord"
		}									       
		
		if(missionVariables.feudal_challenger_gender == "she")
		{	
			missionVariables.feudal_challenger_level1_title = "Lady"
			missionVariables.feudal_challenger_level2_title = "Lady"	
		}	
}
			
this.defineChallengerDetails = function()		
	{
		this.challengerProb = (Math.random())
		{		
			if(this.challengerProb < 0.65)
			
					{	
					
					missionVariables.feudal_challenger_title = missionVariables.feudal_challenger_level1_title
					missionVariables.feudal_challenger_rank = "knight"
					missionVariables.feudal_challenger_ship = "Ritter-Class Jaeger"
					missionVariables.feudal_challenger_text = "feudal_challenger_text_level1"
					missionVariables.feudal_challenger_rank_no = 1
					missionVariables.feudal_challenger_score = 600 + (Math.floor(Math.random()*300))
					this.feudalChallengerRating = missionVariables.feudal_challenger_score*375*300*2*25/15
					}
					
			if(this.challengerProb >= 0.65 && this.challengerProb < 0.90)
				
					{
					missionVariables.feudal_challenger_title = missionVariables.feudal_challenger_level2_title
					missionVariables.feudal_challenger_rank = player.rankGenerator_feudal_middle_rank
					missionVariables.feudal_challenger_ship = "Freiherr-Class Korvette"
					missionVariables.feudal_challenger_text = "feudal_challenger_text_level2"
					missionVariables.feudal_challenger_rank_no = 2
					missionVariables.feudal_challenger_score = 900 + (Math.floor(Math.random()*1000))
					this.feudalChallengerRating = missionVariables.feudal_challenger_score*360*750*4*32/25
					}
					
			if(this.challengerProb >= 0.90)
				
					{
					missionVariables.feudal_challenger_title = missionVariables.feudal_challenger_level2_title
					missionVariables.feudal_challenger_rank = player.rankGenerator_feudal_high_rank
					missionVariables.feudal_challenger_ship = "Prinz-Class Zerstoerer"
					missionVariables.feudal_challenger_text = "feudal_challenger_text_level3"
					missionVariables.feudal_challenger_rank_no = 3
					missionVariables.feudal_challenger_score = 1500 + (Math.floor(Math.random()*2000))
					this.feudalChallengerRating = missionVariables.feudal_challenger_score*400*1100*4*50/35
					}			
		}
}							       
		
this.defineChallengerOdds = function()
	{
		missionVariables.feudal_challenger_odds = Math.round(this.feudalChallengerRating*100/(50*player.ship.maxSpeed*player.ship.maxEnergy*player.ship.thrust*player.ship.missileCapacity))/100 
		
		if(missionVariables.feudal_challenger_odds > 10)
		missionVariables.feudal_challenger_odds = 10
		
		missionVariables.feudal_challenger_return = Math.round(missionVariables.feudal_challenger_odds*100)
	}
	
this.defineGeneratorInputs = function()
{
	player.rankGenerator_house = missionVariables.feudal_challenger_house
	player.rankGenerator_gender = missionVariables.feudal_challenger_gender
	
}
this.defineGeneratorOutputs = function()
{	
	missionVariables.feudal_challenger_of = player.rankGenerator_of
	missionVariables.feudal_challenger_firstname = player.rankGenerator_feudal_firstname
	missionVariables.feudal_challenger_lastname = player.rankGenerator_feudal_lastname
	
}
this.feudalChallengeOffer = function()
{	
		this.defineChallengerGender()
		this.defineGeneratorInputs()
		player.feudalRankGenerator()
		this.defineChallengerDetails()
		this.defineGeneratorOutputs()
		this.defineChallengerShips()
		this.defineChallengerOdds()
		missionVariables.feudal_challenger_offer = "CHALLENGE_OFFERED"
		missionVariables.feudal_player_credits = Math.round(player.credits*100)/100 
}
this.resetChallenger = function()
{	missionVariables.feudal_challenger_title = null
	missionVariables.feudal_challenger_gender = null
	missionVariables.feudal_challenger_firstname= null
	missionVariables.feudal_challenger_lastname = null
	missionVariables.feudal_challenger_rank = null
	missionVariables.feudal_challenger_ship = null
	missionVariables.feudal_challenger_text = null
	missionVariables.feudal_challenger_rank_no = null
	missionVariables.feudal_challenger_score = null
	missionVariables.feudal_challenger_odds = null
	missionVariables.feudal_challenger_return = null
	missionVariables.feudal_challenger_stake = null
	missionVariables.feudal_challenger_page = null
	missionVariables.feudal_challenger_house = null
	missionVariables.feudal_challenger_of = null
	missionVariables.feudal_challenger_level1_title = null
	missionVariables.feudal_challenger_level2_title = null
	missionVariables.feudal_challenger_role = null
	player.rankGenerator_house = null
	player.rankGenerator_gender = null
	missionVariables.feudal_challenger_eligible = null
}
this.checkPlayerShip = function()
{
	this.playerSubentities = player.ship.subEntities
	this.playerSubentitiesString = playerSubentities.toString();
	if(playerSubentitiesString.indexOf("turret") != -1)
	missionVariables.feudal_challenger_eligible = "FALSE"
}
// Mission screens
this.missionScreens = function()
    {   if(guiScreen == "GUI_SCREEN_MISSION" || !player.ship.docked) return;
    
	if(player.ship.dockedStation.hasRole("feudal-hunting-lodge") && (missionVariables.feudal_tournament_home != system.name))
	
	
	{	if(guiScreen == "GUI_SCREEN_MARKET")		 
	
		{
			
		this.checkPlayerShip()	
		
			
		if(!missionVariables.feudal_challenger || missionVariables.feudal_challenger == "NONE_SET")
		{
		  
		  if(missionVariables.feudal_challenger_count > 5)
		  {mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_nomore"})} 
		  
		  else
		  
		  {this.resetChallenger()
					missionVariables.feudal_challenger_page = "1"
					this.feudalChallengeOffer()
					mission.runScreen({title: "Royal Hunting Lodge", messageKey: [missionVariables.feudal_challenger_text], model: [missionVariables.feudal_challenger_role],
                                choicesKey: "feudal_challenger_board_choices"}, this.choiceEvaluation);}}
					
		
		
		if(missionVariables.feudal_challenger_offer == "CHALLENGE_DEFERRED")
			{
			
			mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_accepted_text", choicesKey: "feudal_challenger_launch_choices"}, this.choiceEvaluation);
			missionVariables.feudal_challenger_offer = "CHALLENGE_LAUNCH"}
		
		}
		
		if(missionVariables.feudal_challenger == "RUNNING")	   
			{
			mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_forfeit"})	
			missionVariables.feudal_challenger = "NONE_SET"
			this.resetChallenger()
			this.restoreSystems()}
			
		if(missionVariables.feudal_challenger == "FORFEIT")	   
			{
			mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_forfeit-alt"})
			missionVariables.feudal_challenger = "NONE_SET"
			this.resetChallenger()
			this.restoreSystems()}
		if(missionVariables.feudal_challenger == "VICTORY")
			{
			mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_victory", music: "feudal-music.ogg"})
			player.credits += missionVariables.feudal_challenger_stake
			player.credits += missionVariables.feudal_challenger_return
			missionVariables.feudal_challenger = "NONE_SET"
			this.resetChallenger()
			this.restoreSystems()}
		
	}
		
	if(player.ship.dockedStation.isMainStation)
		{if(missionVariables.feudal_challenger == "RUNNING" || missionVariables.feudal_challenger == "FORFEIT")
		{missionVariables.feudal_challenger = "NONE_SET"
		this.resetChallenger()
		this.restoreSystems()
		player.commsMessage("Feudal Hunting Lodge: You have forfeited the challenge.")}}
}	
    
this.choiceEvaluation = function(choice)
	{
		if(missionVariables.feudal_challenger_offer == "CHALLENGE_OFFERED")
			
				{	
					if(missionVariables.feudal_challenger_page == "1")
								
						{	if(choice == "accept_challenger")	
					
							{	
								if(missionVariables.feudal_challenger_odds > 0.2)
								{mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_bet_text", choicesKey: "feudal_challenger_bet_choices", model: [missionVariables.feudal_challenger_role]}, this.choiceEvaluation);
								missionVariables.feudal_challenger_offer = "CHALLENGE_BET"}
								
								if(missionVariables.feudal_challenger_odds <= 0.5)
								mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_low_odds"});
								
								if(missionVariables.feudal_challenger_eligible == "FALSE")
								mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_ineligible"});
							}
					
							if(choice == "decline_challenger")	
			
							{	
								missionVariables.feudal_challenger_page = "2"
								missionVariables.feudal_challenger_offer = null	
								choice = null
								this.feudalChallengeOffer()
								mission.runScreen({title: "Royal Hunting Lodge", messageKey: [missionVariables.feudal_challenger_text], choicesKey: "feudal_challenger_board_choices", model: [missionVariables.feudal_challenger_role]}, this.choiceEvaluation);
							}	
					
							if(choice == "exit_challenger")		
								{missionVariables.feudal_challenger = "NONE_SET"
								missionVariables.feudal_challenger_offer = null
								this.resetChallenger()
								return}
						}
							
					if(missionVariables.feudal_challenger_page == "2")
								
						{	if(choice == "accept_challenger")
					
							{	
								if(missionVariables.feudal_challenger_odds > 0.2)
								{mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_bet_text", choicesKey: "feudal_challenger_bet_choices", model: [missionVariables.feudal_challenger_role]}, this.choiceEvaluation);
								missionVariables.feudal_challenger_offer = "CHALLENGE_BET"}
								
								if(missionVariables.feudal_challenger_odds <= 0.2)
								mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_low_odds"});
								
								if(missionVariables.feudal_challenger_eligible == "FALSE")
								mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_ineligible"});
							}
					
							if(choice == "decline_challenger")	
			
							{	
								missionVariables.feudal_challenger_page = "3"
								missionVariables.feudal_challenger_offer = null
								choice = null
								this.feudalChallengeOffer()
								mission.runScreen({title: "Royal Hunting Lodge", messageKey: [missionVariables.feudal_challenger_text], choicesKey: "feudal_challenger_board_choices_alt", model: [missionVariables.feudal_challenger_role]}, this.choiceEvaluation);
								missionVariables.feudal_challenger_page = "3"
							}	
					
							if(choice == "exit_challenger")		
								{missionVariables.feudal_challenger = "NONE_SET"
								missionVariables.feudal_challenger_offer = null
								this.resetChallenger()
								return}
						}	
						
					if(missionVariables.feudal_challenger_page == "3")
								
						{	if(choice == "accept_challenger")
					
							{	
								if(missionVariables.feudal_challenger_odds > 0.2)
								{mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_bet_text", choicesKey: "feudal_challenger_bet_choices", model: [missionVariables.feudal_challenger_role]}, this.choiceEvaluation);
								missionVariables.feudal_challenger_offer = "CHALLENGE_BET"}
								
								if(missionVariables.feudal_challenger_odds <= 0.2)
								mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_low_odds"});
								
								if(missionVariables.feudal_challenger_eligible == "FALSE")
								mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_ineligible"});
							}
					
							if(choice == "decline_challenger")	
			
							{
								missionVariables.feudal_challenger_page = "1"			
								missionVariables.feudal_challenger = "NONE_SET"
								missionVariables.feudal_challenger_offer = null
								choice = null
								this.resetChallenger()
							}	
					
							if(choice == "exit_challenger")		
								{missionVariables.feudal_challenger = "NONE_SET"
								missionVariables.feudal_challenger_offer = null
								this.resetChallenger()
								
								return}
						}			
				}
			
		if(missionVariables.feudal_challenger_offer == "CHALLENGE_BET")
			
				{	if(choice == "bet100")
				
					{	if(player.credits >= 100)
					
						{	missionVariables.feudal_challenger_offer = "CHALLENGE_LAUNCH"
							missionVariables.feudal_challenger_stake = 100
							missionVariables.feudal_challenger_return = Math.round([missionVariables.feudal_challenger_stake]*[missionVariables.feudal_challenger_odds])
							mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_accepted_text", choicesKey: "feudal_challenger_launch_choices"}, this.choiceEvaluation);
							player.credits -= 100
							missionVariables.feudal_challenger = "ACCEPTED"
						}
						
						else
							
						mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_refused", choicesKey: "feudal_challenger_bet_choices"}, this.choiceEvaluation);
					}	
						
					if(choice == "bet1000")
					
					{	if(player.credits >= 1000)
					
						{	missionVariables.feudal_challenger_offer = "CHALLENGE_LAUNCH"
							missionVariables.feudal_challenger_stake = 1000
							missionVariables.feudal_challenger_return = Math.round([missionVariables.feudal_challenger_stake]*[missionVariables.feudal_challenger_odds])
							mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_accepted_text", choicesKey: "feudal_challenger_launch_choices"}, this.choiceEvaluation);
							player.credits -= 1000
							missionVariables.feudal_challenger = "ACCEPTED"
						}
						
						else
						
	
							mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_refused", choicesKey: "feudal_challenger_bet_choices"}, this.choiceEvaluation);
						
					}	
					
					if(choice == "bet10000")
					
					{	if(player.credits >= 10000)
						
						{	missionVariables.feudal_challenger_offer = "CHALLENGE_LAUNCH"
							missionVariables.feudal_challenger_stake = 10000
							missionVariables.feudal_challenger_return = Math.round([missionVariables.feudal_challenger_stake]*[missionVariables.feudal_challenger_odds])
							mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_accepted_text", choicesKey: "feudal_challenger_launch_choices"}, this.choiceEvaluation);
							player.credits -= 10000
							missionVariables.feudal_challenger = "ACCEPTED"
						}
						
						else
						mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_refused", choicesKey: "feudal_challenger_bet_choices"}, this.choiceEvaluation);
						
					}
					
					if(choice == "betcancel")
						{missionVariables.feudal_challenger_offer = "CHALLENGE_OFFERED"
						mission.runScreen({title: "Royal Hunting Lodge", messageKey: [missionVariables.feudal_challenger_text], choicesKey: "feudal_challenger_board_choices", model: [missionVariables.feudal_challenger_role]}, this.choiceEvaluation);
						}	
				}		
				
		if(missionVariables.feudal_challenger_offer == "CHALLENGE_LAUNCH")
				
				{	if(choice == "begin_challenge")
				
						{	missionVariables.feudal_challenger = "RUNNING"
							missionVariables.feudal_challenger_offer = null
							player.ship.launch()
							++missionVariables.feudal_challenger_count
							
						}
						
						
					if(choice == "defer_challenge")
				
						{
							mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_challenger_deferred"});
							missionVariables.feudal_challenger_offer = "CHALLENGE_DEFERRED"	
						}	
				}
	}			
	
// ship appearance on launching
	
this.shipWillLaunchFromStation = function()
{	this.setUpSystem()
	if(missionVariables.feudal_challenger == "RUNNING")
	{	system.legacy_addShipsAtPrecisely([missionVariables.feudal_challenger_role], 1, "wsm", [0, 120100, 0])
		this.disableSystems()}
		else
	if(missionVariables.feudal_challenger_offer != "CHALLENGE_DEFERRED")
	missionVariables.feudal_challenger = "NONE_SET"
}
this.shipWillExitWitchspace = function()
{	this.setUpSystem()
	missionVariables.feudal_challenger_count = 0 
	if(missionVariables.feudal_challenger == "RUNNING" || missionVariables.feudal_challenger == "FORFEIT" || missionVariables.feudal_challenger_offer == "DEFERRED")
		{missionVariables.feudal_challenger = "NONE_SET"
		missionVariables.feudal_challenger_offer = null
		missionVariables.feudal_challenger_stake = null
		player.commsMessage("Feudal challenge has been forfeit.")
		this.restoreSystems()}	
	
	if(missionVariables.feudal_challenger == "VICTORY")
		{missionVariables.feudal_challenger = "NONE_SET"
		missionVariables.feudal_challenger_offer = null
		missionVariables.feudal_challenger_stake = null
		this.restoreSystems()}	
}
this.setPlanetOverrides = function()
{	missionVariables.feudal_planetinfo = missionVariables.feudal_planetinfo+galaxyNumber
	for (var i=0; i<256; i++)
	{if(System.infoForSystem(galaxyNumber,[i]).government == 1)
	
			{if(galaxyNumber = 0 && System.infoForSystem(galaxyNumber,[i]).techlevel >= 7 || galaxyNumber == 1 && System.infoForSystem(galaxyNumber,[i]).techlevel >= 5 ||
				galaxyNumber == 2 && System.infoForSystem(galaxyNumber,[i]).techlevel >= 7 || galaxyNumber == 4 && System.infoForSystem(galaxyNumber,[i]).techlevel >= 7 ||
				galaxyNumber == 5 && System.infoForSystem(galaxyNumber,[i]).techlevel >= 8)
				{System.infoForSystem(galaxyNumber,[i]).description = System.infoForSystem(galaxyNumber,[i]).description + " Note that this system is a member of the Feudal States."}
			}
	}	
}
this.playerEnteredNewGalaxy = function()
{	if(missionVariables.feudal_planetinfo.indexOf(galaxyNumber) == -1)
	this.setPlanetOverrides()}
this.setUpSystem = function()
{
	if(system.government == 1)
	
	{
	
		if(galaxyNumber == 0 && system.techLevel >=7 || galaxyNumber == 1 && system.techLevel >= 5 || galaxyNumber == 2 && system.techLevel >= 7 || galaxyNumber == 4 && system.techLevel >=7 || galaxyNumber == 5 && system.techLevel >=8)
		{
		var currentLocationNo = system.ID
		var currentLocationName = System.systemNameForID ([currentLocationNo])
		
		if(system.countShipsWithRole("feudal-hunting-lodge") == 0)
		system.legacy_addShipsAtPrecisely("feudal-hunting-lodge", 1, "wsm", [0, 100000, 0])
		
		if(system.countShipsWithRole("feudal-buoy") == 0)
		system.legacy_addShipsAtPrecisely("feudal-buoy", 1, "wsm", [0, 122000, 0])
		
		
		if(missionVariables.feudal_tournament_home != system.name && system.countShipsWithRole("feudal-knight") == 0)  
		{system.legacy_addShipsWithinRadius([currentLocationName]+"-knight", 4, "wsm", [0, 100000, 0], 10000)
		system.legacy_addSystemShips([currentLocationName]+"-lord", 2, 0.8)
		system.legacy_addSystemShips("feudal-knight", 3, 0.6)}
		}
	}
}
this.disableSystems = function()
{
	if(player.ship.equipmentStatus("EQ_CLOAKING_DEVICE") == "EQUIPMENT_OK")
		{	player.ship.removeEquipment("EQ_CLOAKING_DEVICE")
			player.ship.awardEquipment("EQ_FS_CLOAK_PLACEHOLDER")
			player.consoleMessage("Cloaking Device disabled")
		}
		
	if(player.ship.equipmentStatus("EQ_ENERGY_BOMB") == "EQUIPMENT_OK")
		{	player.ship.removeEquipment("EQ_ENERGY_BOMB")
			player.ship.awardEquipment("EQ_FS_BOMB_PLACEHOLDER")
			player.consoleMessage("Energy Bomb disabled")
		}
		
	this.storeMissileArray = player.ship.missiles;
	player.ship.awardEquipment("EQ_MISSILE_REMOVAL")
	player.ship.awardEquipment("EQ_FEUDAL_FLARE_MINE")
}
this.restoreSystems = function()
{	if(player.ship.equipmentStatus("EQ_FS_CLOAK_PLACEHOLDER") == "EQUIPMENT_OK")
		{	player.ship.removeEquipment("EQ_FS_CLOAK_PLACEHOLDER")
			player.ship.awardEquipment("EQ_CLOAKING_DEVICE")
			player.consoleMessage("Cloaking Device re-enabled")
		}
		
	if(player.ship.equipmentStatus("EQ_FS_BOMB_PLACEHOLDER") == "EQUIPMENT_OK")
		{	player.ship.removeEquipment("EQ_FS_BOMB_PLACEHOLDER")
			player.ship.awardEquipment("EQ_ENERGY_BOMB")
			player.consoleMessage("Energy Bomb re-enabled")
		}
	
	player.ship.awardEquipment("EQ_MISSILE_REMOVAL")
	for(restoreCounter = 0;restoreCounter<this.storeMissileArray.length;restoreCounter++)
        {player.ship.awardEquipment(this.storeMissileArray[restoreCounter].equipmentKey);}
} | 
                
                    | Scripts/feudal-escape-pod.js | this.name = "feudal-escape-pod.js";
this.author = "Ramirez";
this.copyright = "November 2010";
this.description = "Ship script for feudal escape pods";
this.version = "2.0";
this.shipSpawned = function ()
{
	if(missionVariables.feudal_mission == "RANSOM_RUNNING")
	
		{	if(this.ship.displayName == this.ship.name)
			this.ship.displayName = expandDescription("[mission_feudal_mission_rank] [mission_feudal_mission_of] [mission_feudal_mission_house]") // Show the ID of the execution target
		}
	if(missionVariables.feudal_challenger == "RUNNING")
		{
		if(this.ship.displayName == this.ship.name)	
                        {
                              if(missionVariables.feudal_challenger_rank_no == 1)
                              this.ship.displayName = expandDescription("[mission_feudal_challenger_title] [mission_feudal_challenger_firstname] [mission_feudal_challenger_lastname]")
                        
                              else
                              this.ship.displayName = expandDescription("[mission_feudal_challenger_rank] [mission_feudal_challenger_of] [mission_feudal_challenger_house]")
                        }
		}
}
this.shipWasScooped = function (whom)
		{ if(whom == player.ship)
		
		{if(missionVariables.feudal_mission == "RANSOM_RUNNING")
			{missionVariables.feudal_mission = "RANSOM_SUCCESS" 
			mission.unmarkSystem([missionVariables.feudal_mission_location_no], "feudal-mission.js")}
		}
		}
this.shipDied = function ()
		
		
		{if(missionVariables.feudal_mission == "RANSOM_RUNNING")
			{missionVariables.feudal_mission = "RANSOM_FAIL" 
			mission.unmarkSystem([missionVariables.feudal_mission_location_no], "feudal-mission.js")}                
		}	
		 | 
                
                    | Scripts/feudal-flare.js | this.name = "feudal-flare.js";
this.author = "Ramirez";
this.copyright = "April 2011";
this.description = "Script used by a signal flare to yield a feudal challenge to an opponent";
this.version = "1.1";
this.yieldToOpponent = function()
{player.commsMessage("Challenge yielded", 5)
missionVariables.feudal_challenger = "FORFEIT"} | 
                
                    | Scripts/feudal-jumpgate.js | this.name = "feudal-jumpgate.js";
this.author = "Ramirez";
this.copyright = "November 2012";
this.description = "Script used by Cascade tournament event to teleport player to asteroid field";
this.version = "2.0";
this.checkDistance = function()
{if(player.ship.position.distanceTo(this.ship) < 200)
    {   var homedestination = system.shipsWithRole("feudal-gate-home")[0]
        var awaydestination = system.shipsWithRole("feudal-gate-away")[0]
        player.commsMessage('Jump Initiated')
        
        if(this.ship.primaryRole == "feudal-gate-home")
        {
            player.ship.position = awaydestination.position.add([0, 0, 500])
            player.ship.orientation = awaydestination.orientation  
        }
        
        if(this.ship.primaryRole == "feudal-gate-away")
        { 
            player.ship.position = homedestination.position.add([0, 0, 500])
            player.ship.orientation = homedestination.orientation
        }      
    }
}
 | 
                
                    | Scripts/feudal-mine.js | this.name = "feudal-mine.js";
this.author = "Ramirez";
this.copyright = "August 2009";
this.description = "Script used by feudal mines";
this.version = "1.0";
this.checkDistanceToPlayer = function()
{if(player.ship.position.distanceTo(this.ship) < 4000)
    {   
        this.ship.commsMessage("WARNING: Mine activated.")
        this.ship.reactToAIMessage("TARGET_FOUND")}            
                
}
this.shipDied = function()
{this.ship.spawn("feudal-splinter", 30)}
 | 
                
                    | Scripts/feudal-mission.js | this.name = "feudal-mission.js";
this.author = "Ramirez";
this.copyright = "December 2011";
this.description = "World script for setting up feudal missions";
this.version = "9.0";
this.startUp = function()
{
this.thePlayerShip = player.ship
}
this.missionScreenEnded = function()
{
	if(!player.ship.docked) return;
	
	this.feudalMissionScreens	
}
this.shipDockedWithStation = function()
{
	if(!player.ship.docked) return;
	this.feudalMissionScreens()	
}
this.guiScreenChanged = function()
{	if(guiScreen == "GUI_SCREEN_MARKET")
	this.feudalMissionScreens()
}
this.resetMissionVariables = function()
{missionVariables.feudal_mission_location_no = null
missionVariables.feudal_mission_location_name = null
missionVariables.feudal_mission_commodity = null
missionVariables.feudal_mission_reward = null
missionVariables.feudal_mission_house = null
missionVariables.feudal_mission_gender = null
missionVariables.feudal_mission_role = null
missionVariables.feudal_mission_ship = null
}
this.defineMissionLocationNo = function() // Define system number for missions if required, based on selected house
	{missionVariables.feudal_mission_location_no = System.systemIDForName([missionVariables.feudal_mission_house])}
this.defineMissionHouse = function() // Randomly select a House related to the mission; reject any where house equals current location
	
	{missionVariables.feudal_mission_house = expandDescription("[feudal_house_"+[galaxyNumber]+"]")
		
		if(missionVariables.feudal_mission_house == system.name)
			{this.defineMissionHouse()}
			else return}
this.defineMissionLocation = function() // Define system name for missions if required, based on system number
	{missionVariables.feudal_mission_location = System.systemNameForID([missionVariables.feudal_mission_location_no])}
this.defineMissionCommodity = function() // Define any commodities associated with the mission
	{missionVariables.feudal_mission_commodity = expandDescription("[feudal_commodity]")}
		
this.defineMissionHome = function() // Defines the home for any feudal missions and ultimately the player's feudal rank
	{missionVariables.feudal_mission_home = system.name}
this.defineFeudalDelivery = function() // Defines all variables needed for a feudal delivery mission
{	this.defineMissionHouse()
	this.defineMissionLocationNo()
	this.defineMissionHome()
	this.defineMissionCommodity()
	missionVariables.feudal_mission_reward = 1000 + (Math.floor(Math.random()*10))*101	
}
this.feudalTributeOffer = function()
{	
	this.defineFeudalTribute()
	mission.runScreen({title: "Royal Court", messageKey: "feudal_mission_tribute", music: "feudal-music.ogg", background: "redeagle.png", choicesKey: "feudal_mission_choices"}, this.choiceEvaluation);
	missionVariables.feudal_mission_offer = "TRIBUTE_OFFER"
}
this.defineFeudalTribute = function()
{	this.defineMissionHome()
	missionVariables.feudal_mission_reward = 300 + (Math.floor(Math.random()*10))*101	
	missionVariables.feudal_mission_location_no = (Math.floor(Math.random()*256));
	
	if(System.infoForSystem(galaxyNumber,[missionVariables.feudal_mission_location_no]).government == 1 && System.infoForSystem(galaxyNumber,[missionVariables.feudal_mission_location_no]).techlevel < 5)
	{missionVariables.feudal_mission_location_name = System.infoForSystem(galaxyNumber,[missionVariables.feudal_mission_location_no]).name}	
	else
	this.defineFeudalTribute()	
}
this.feudalTributeChoice = function()   
{	mission.runScreen({title: "Royal Court", messageKey: "feudal_mission_accepted"})
	missionVariables.feudal_mission = "TRIBUTE_RUNNING"
	mission.setInstructionsKey("feudal_mission_tribute_instructions")
	mission.markSystem([missionVariables.feudal_mission_location_no])
}
this.defineFeudalRansom = function()
{		
	this.defineMissionGender()
	this.defineMissionHouse()
	this.defineGeneratorInputs()
	player.rankGenerator_level = 3
	player.feudalRankGenerator()
	this.defineGeneratorOutputs()
	missionVariables.feudal_mission_rank = player.rankGenerator_feudal_high_rank
	this.defineMissionLocationNo()
	this.defineMissionHome()
	missionVariables.feudal_mission_reward = (Math.floor(Math.random()*4))*3050 + 5000	
}
this.feudalRansomOffer = function()
{	
	this.defineFeudalRansom()
	mission.runScreen({title: "Royal Court", messageKey: "feudal_mission_ransom", music: "feudal-music.ogg", background: "redeagle.png", choicesKey: "feudal_mission_choices"}, this.choiceEvaluation);
	missionVariables.feudal_mission_offer = "RANSOM_OFFER"
}
		
this.feudalRansomChoice = function()
{	mission.runScreen({title: "Royal Court", messageKey: "feudal_mission_accepted"})
	missionVariables.feudal_mission = "RANSOM_RUNNING"
	mission.setInstructionsKey("feudal_mission_ransom_instructions")
	mission.markSystem([missionVariables.feudal_mission_location_no])
}
this.feudalDeliveryOffer = function ()
{
	this.defineFeudalDelivery()
	mission.runScreen({title: "Royal Court", messageKey: "feudal_mission_delivery", background: "redeagle.png", music: "feudal-music.ogg", choicesKey: "feudal_mission_choices"}, this.choiceEvaluation);
	//mission.runMissionScreen("feudal_mission_delivery", "redeagle.png", "feudal_mission_choices", null, "feudal-music.ogg")
	missionVariables.feudal_mission_offer = "DELIVERY_OFFER"	
}
this.feudalDeliveryChoice = function ()   
{	mission.runScreen({title: "Royal Court", messageKey: "feudal_mission_accepted"})
	missionVariables.feudal_mission = "DELIVERY_RUNNING"
	mission.setInstructionsKey("feudal_mission_delivery_instructions")
	mission.markSystem([missionVariables.feudal_mission_location_no])
}
this.feudalExecutionOffer = function ()
			
{
	this.defineFeudalExecution()
	mission.runScreen({title: "Royal Court", messageKey: "feudal_mission_execution", background: "redeagle.png", music: "feudal-music.ogg", choicesKey: "feudal_mission_choices"}, this.choiceEvaluation);
	//mission.runMissionScreen("feudal_mission_execution", "redeagle.png", "feudal_mission_choices", null, "feudal-music.ogg")
	missionVariables.feudal_mission_offer = "EXECUTION_OFFER"	
}
	
this.feudalExecutionChoice = function ()	
{	
	mission.runScreen({title: "Royal Court", messageKey: "feudal_mission_accepted"})
	missionVariables.feudal_mission = "EXECUTION_RUNNING"
	mission.setInstructionsKey("feudal_mission_execution_instructions")
	mission.markSystem([missionVariables.feudal_mission_location_no])
}	
	
this.feudalRaidOffer = function ()
{
	this.defineFeudalRaid()
	mission.runScreen({title: "Royal Court", messageKey: "feudal_mission_raid", background: "redeagle.png", music: "feudal-music.ogg", choicesKey: "feudal_mission_choices"}, this.choiceEvaluation);
	//mission.runMissionScreen("feudal_mission_raid", "redeagle.png", "feudal_mission_choices", null, "feudal-music.ogg")
	missionVariables.feudal_mission_offer = "RAID_OFFER"
	
}
this.feudalRaidChoice = function ()
{			
	mission.runScreen({title: "Royal Court", messageKey: "feudal_mission_accepted"})
	missionVariables.feudal_mission = "RAID_RUNNING"
	mission.setInstructionsKey("feudal_mission_raid_instructions")
	mission.markSystem([missionVariables.feudal_mission_location_no])
	missionVariables.feudal_mission_cargocount = 0
}
this.feudalEscortOffer = function()
{ 
	this.defineFeudalEscort()
	mission.runScreen({title: "Royal Court", messageKey: "feudal_mission_escort", background: "redeagle.png", music: "feudal-music.ogg", choicesKey: "feudal_mission_choices"}, this.choiceEvaluation);
	missionVariables.feudal_mission_offer = "ESCORT_OFFER"
}
this.feudalEscortChoice = function()	
{	
	mission.runScreen({title: "Royal Court", messageKey: "feudal_mission_accepted"})
	missionVariables.feudal_mission = "ESCORT_RUNNING"
	mission.setInstructionsKey("feudal_mission_escort_instructions")
	mission.markSystem([missionVariables.feudal_mission_location_no])
	missionVariables.feudal_mission_cargocount = 0
	missionVariables.feudal_mission_killcount = 0
}
this.defineFeudalRaid = function()
{
	missionVariables.feudal_mission_location_no = (Math.floor(Math.random()*256));
	missionVariables.feudal_mission_ship = expandDescription("[feudal_freighter]")
	this.defineMissionHouse()
	this.defineMissionLocation()
	this.defineMissionCommodity()
	this.defineMissionHome()
	this.defineMissionRole()
	missionVariables.feudal_mission_reward = 3000 + (Math.floor(Math.random()*10))*97
}
this.defineFeudalExecution = function()
{	
	missionVariables.feudal_mission_location_no = (Math.floor(Math.random()*256));
	missionVariables.feudal_mission_ship = expandDescription("[feudal_fighter]")
	missionVariables.feudal_mission_house = system.name
	this.defineMissionGender()
	this.defineMissionRole()
	player.rankGenerator_level = 2
	this.defineGeneratorInputs()
	player.feudalRankGenerator()
	this.defineGeneratorOutputs()
	this.defineMissionLocation()
	missionVariables.feudal_mission_reward = 8000 + (Math.floor(Math.random()*10))*52
}
this.defineGeneratorInputs = function()
{
	player.rankGenerator_house = missionVariables.feudal_mission_house
	player.rankGenerator_gender = missionVariables.feudal_mission_gender	
}
this.defineGeneratorOutputs = function()
{
	missionVariables.feudal_mission_firstname = player.rankGenerator_feudal_firstname
	missionVariables.feudal_mission_lastname = player.rankGenerator_feudal_lastname
	missionVariables.feudal_mission_of = player.rankGenerator_of
}
this.defineFeudalEscort = function()
{	missionVariables.feudal_mission_location_no = (Math.floor(Math.random()*256));
	missionVariables.feudal_mission_ship = expandDescription("[feudal_freighter]")
	this.defineMissionLocation()
	this.defineMissionHouse()
	this.defineMissionRole()
	this.defineMissionCommodity()
	this.defineMissionHome()
	missionVariables.feudal_mission_reward = 8000 + (Math.floor(Math.random()*10))*48
}
this.defineMissionGender = function() // define gender and basic ranks for mission target
	{	missionVariables.feudal_mission_gender = expandDescription("[feudal_gender]")
		  
		if(missionVariables.feudal_mission_gender == "he")
		{	
			missionVariables.feudal_mission_level1_title = "Sir"
			missionVariables.feudal_mission_level2_title = "Lord"
		}									       
		
		if(missionVariables.feudal_mission_gender == "she")
		
		{	
			missionVariables.feudal_mission_level1_title = "Lady"
			missionVariables.feudal_mission_level2_title = "Lady"	
		}
	}
	
//   define the necessary ship role based on the ship name that has been selected by mission variables
this.defineMissionRole = function()
{	
		if(missionVariables.feudal_mission_ship == "Python Cruiser")
		missionVariables.feudal_mission_role = "feudal-python"
		
		if(missionVariables.feudal_mission_ship == "Anaconda Freighter")
		missionVariables.feudal_mission_role = "feudal-anaconda"
		
		if(missionVariables.feudal_mission_ship == "Boa")
		missionVariables.feudal_mission_role = "feudal-boa"
		
		if(missionVariables.feudal_mission_ship == "Boa Class Cruiser")
		missionVariables.feudal_mission_role = "feudal-boa2"
		
		if(missionVariables.feudal_mission_ship == "Adder")
		missionVariables.feudal_mission_role = "feudal-adder"
		
		if(missionVariables.feudal_mission_ship == "Moray")
		missionVariables.feudal_mission_role = "feudal-moray"
		
		if(missionVariables.feudal_mission_ship == "Fer-de-Lance")
		missionVariables.feudal_mission_role = "feudal-ferdelance"
		
		if(missionVariables.feudal_mission_ship == "Asp Mark II")
		missionVariables.feudal_mission_role = "feudal-asp"
}
this.feudalMissionScreens = function()
{  	if(guiScreen == "GUI_SCREEN_MISSION" || !player.ship.docked) return;
	if(missionVariables.feudal_mission_offer) return;
	
	if(this.thePlayerShip.dockedStation.hasRole("planetFall_feudalStates"))
		{		
			if(guiScreen == "GUI_SCREEN_MARKET")
			
			{	
				if(!missionVariables.feudal_mission && !missionVariables.feudal_player_rank_no)		 
			
				{	this.feudalTributeOffer()
					missionVariables.feudal_score = 0
					// for new starters, offer a delivery only and initialise score
				}
				
				
				if(missionVariables.feudal_mission == "NONE_SET")
			
				{
					this.feudalMissionProb = (Math.random())
				
					if(!missionVariables.feudal_player_rank_no)
						
						if(this.feudalMissionProb <= 0.5)
						this.feudalDeliveryOffer()
						
						else
						
						this.feudalTributeOffer()
							
					if(missionVariables.feudal_player_rank_no == 1 && missionVariables.feudal_mission_home == system.name) 
							
					{	
						if(this.feudalMissionProb <= 0.4)
						this.feudalRaidOffer()
						
						if(this.feudalMissionProb > 0.4 && this.feudalMissionProb <= 0.7)
						this.feudalDeliveryOffer()						
						if(this.feudalMissionProb > 0.9)
						this.feudalTributeOffer()
					
						if(this.feudalMissionProb > 0.7 && this.feudalMissionProb <= 0.9)
						this.feudalEscortOffer()
						
					}
				
			
					if(missionVariables.feudal_player_rank_no == 2 && missionVariables.feudal_mission_home == system.name)
								
					{
			
					if(this.feudalMissionProb <= 0.65)
					this.feudalRaidOffer()
						
					if(this.feudalMissionProb > 0.65 && this.feudalMissionProb <= 0.8)
					this.feudalEscortOffer()
						
					if(this.feudalMissionProb >= 0.8)
					this.feudalExecutionOffer()
					}
			
		
					if(missionVariables.feudal_player_rank_no == 3 && missionVariables.feudal_mission_home == system.name)		
					{	
					
					if(this.feudalMissionProb <= 0.10)
					this.feudalRaidOffer()
						
					if(this.feudalMissionProb >0.10 && this.feudalMissionProb <= 0.8)
					this.feudalRansomOffer()
						
					if(this.feudalMissionProb >= 0.8)
					this.feudalExecutionOffer()	
					}
			
					if(missionVariables.feudal_player_rank_no >= 4 && missionVariables.feudal_mission_home == system.name)		
				
					{
					if(this.feudalMissionProb <= 0.10)
					this.feudalRaidOffer()
						
					if(this.feudalMissionProb > 0.10 && this.feudalMissionProb <= 0.5)
					this.feudalEscortOffer()
					
					if(this.feudalMissionProb >0.5 && this.feudalMissionProb <= 0.8)
					this.feudalRansomOffer()
						
					if(this.feudalMissionProb >= 0.8 && this.feudalMissionProb < 0.9)
					this.feudalExecutionOffer()
					
					if(this.feudalMissionProb >= 0.9)
					this.feudalDeliveryOffer()
					}
				
				}
		
				if(missionVariables.feudal_mission == "DELIVERY_DECLINED")
					{mission.runScreen({title: "Royal Court", messageKey: "feudal_mission_delivery", background: "redeagle.png",
					music: "feudal-music.ogg", choicesKey: "feudal_mission_choices"}, this.choiceEvaluation);	
					missionVariables.feudal_mission_offer = "DELIVERY_OFFER"}
					
				if(missionVariables.feudal_mission == "TRIBUTE_DECLINED")
					{mission.runScreen({title: "Royal Court", messageKey: "feudal_mission_tribute", background: "redeagle.png",
					music: "feudal-music.ogg", choicesKey: "feudal_mission_choices"}, this.choiceEvaluation);	
					missionVariables.feudal_mission_offer = "TRIBUTE_OFFER"}
					
				if(missionVariables.feudal_mission == "RANSOM_DECLINED")
					{mission.runScreen({title: "Royal Court", messageKey: "feudal_mission_ransom", background: "redeagle.png",
					music: "feudal-music.ogg", choicesKey: "feudal_mission_choices"}, this.choiceEvaluation);		
					missionVariables.feudal_mission_offer = "RANSOM_OFFER"}
					
				if(missionVariables.feudal_mission == "RAID_DECLINED")
					{mission.runScreen({title: "Royal Court", messageKey: "feudal_mission_raid", background: "redeagle.png",
					music: "feudal-music.ogg", choicesKey: "feudal_mission_choices"}, this.choiceEvaluation);
					missionVariables.feudal_mission_offer = "RAID_OFFER"}
					
				if(missionVariables.feudal_mission == "EXECUTION_DECLINED")
					{mission.runScreen({title: "Royal Court", messageKey: "feudal_mission_execution", background: "redeagle.png",
					music: "feudal-music.ogg", choicesKey: "feudal_mission_choices"}, this.choiceEvaluation);
					missionVariables.feudal_mission_offer = "EXECUTION_OFFER"}
					
				if(missionVariables.feudal_mission == "ESCORT_DECLINED")
					{mission.runScreen({title: "Royal Court", messageKey: "feudal_mission_escort", background: "redeagle.png",
					music: "feudal-music.ogg", choicesKey: "feudal_mission_choices"}, this.choiceEvaluation);
					missionVariables.feudal_mission_offer = "ESCORT_OFFER"}
			
			}
			
		
			
			
			// standard responses for missions returning to the Royal Court without market screen
			
			
		if((missionVariables.feudal_mission == "DELIVERY_RUNNING" && system.ID == [missionVariables.feudal_mission_location_no]))	  
			
				{	mission.runScreen({messageKey:"feudal_mission_deliverysuccess"})
					mission.unmarkSystem([missionVariables.feudal_mission_location_no])
					missionVariables.feudal_score += 2
					missionVariables.feudal_mission = "NONE_SET"
					mission.setInstructionsKey(null)
					player.credits += missionVariables.feudal_mission_reward}
					
							
		if(missionVariables.feudal_mission == "TRIBUTE_COLLECTED" && (missionVariables.feudal_mission_home == system.name)) 	  
			
				{	mission.runScreen({messageKey:"feudal_mission_tributesuccess"})
					mission.unmarkSystem([missionVariables.feudal_mission_location_no])
					missionVariables.feudal_score += 1
					missionVariables.feudal_mission = "NONE_SET"
					player.credits += missionVariables.feudal_mission_reward
					mission.setInstructionsKey(null)}
			
		if(missionVariables.feudal_mission == "RAID_SUCCESS" && (missionVariables.feudal_mission_home == system.name)) 
					
					{	if(missionVariables.feudal_mission_cargocount == 18)
				
						{	player.credits += missionVariables.feudal_mission_reward
							mission.runScreen({messageKey: "feudal_mission_raid_bigsuccess"})
							mission.unmarkSystem([missionVariables.feudal_mission_location_no])
							missionVariables.feudal_mission = "NONE_SET"
							missionVariables.feudal_score += 10
							mission.setInstructionsKey(null)
						}
				
						if(missionVariables.feudal_mission_cargocount < 18 && missionVariables.feudal_mission_cargocount > 6)
						{	missionVariables.feudal_mission_reward = Math.floor(missionVariables.feudal_mission_reward*0.8)				
							player.credits += (missionVariables.feudal_mission_reward)
							mission.runScreen({messageKey: "feudal_mission_raid_success"})
							mission.unmarkSystem([missionVariables.feudal_mission_location_no])
							missionVariables.feudal_mission = "NONE_SET"
							missionVariables.feudal_score += 5
							mission.setInstructionsKey(null)
						}
				
						if(missionVariables.feudal_mission_cargocount <= 6)
						{	mission.runScreen({messageKey: "feudal_mission_raid_smallsuccess"})
							mission.unmarkSystem([missionVariables.feudal_mission_location_no])
							missionVariables.feudal_mission = "NONE_SET"
							missionVariables.feudal_score += 3
							mission.setInstructionsKey(null)
						}
					
						if(missionVariables.feudal_mission_cargocount == 0)
						{	
							mission.runScreen({messageKey: "feudal_mission_raid_fail"})
							mission.unmarkSystem([missionVariables.feudal_mission_location_no])
							missionVariables.feudal_mission = "NONE_SET"
							mission.setInstructionsKey(null)
						}
					}		
		
		if(missionVariables.feudal_mission == "RANSOM_SUCCESS" && (missionVariables.feudal_mission_home == system.name)) 
			
				{	player.credits += missionVariables.feudal_mission_reward
					mission.runScreen({messageKey: "feudal_mission_ransom_success"})
					mission.unmarkSystem([missionVariables.feudal_mission_location_no])
					missionVariables.feudal_mission = "NONE_SET"
					missionVariables.feudal_score += 20
					mission.setInstructionsKey(null)
				}
				
		if(missionVariables.feudal_mission == "RANSOM_FAIL" && (missionVariables.feudal_mission_home == system.name))
			
				{	
					mission.runScreen({messageKey: "feudal_mission_ransom_fail"})
					mission.unmarkSystem([missionVariables.feudal_mission_location_no])
					missionVariables.feudal_mission = "NONE_SET"
					missionVariables.feudal_score -= 15
					mission.setInstructionsKey(null)
				}
			
		}
	
		// Responses that don't end at the Royal Court
		
		
			if((missionVariables.feudal_mission == "TRIBUTE_RUNNING" && system.ID == [missionVariables.feudal_mission_location_no]))	  
			
				{	mission.runScreen({messageKey:"feudal_mission_tributecollected"})
					mission.unmarkSystem([missionVariables.feudal_mission_location_no])
					missionVariables.feudal_mission = "TRIBUTE_COLLECTED"}
			if(missionVariables.feudal_mission == "EXECUTION_SUCCESS")		
			
				{	mission.runScreen({messageKey: "feudal_mission_executionsuccess"})
					mission.unmarkSystem([missionVariables.feudal_mission_location_no])
					missionVariables.feudal_mission = "NONE_SET"
					missionVariables.feudal_score += 20
					mission.setInstructionsKey(null)
					player.credits += missionVariables.feudal_mission_reward
				}
				
			if(missionVariables.feudal_mission == "EXECUTION_PARTIALSUCCESS")		
			
				{	missionVariables.feudal_mission_reward = Math.floor(missionVariables.feudal_mission_reward*0.4)
					mission.runScreen({messageKey: "feudal_mission_executionpartialsuccess"})
					mission.unmarkSystem([missionVariables.feudal_mission_location_no])
					player.credits += missionVariables.feudal_mission_reward
					missionVariables.feudal_mission = "NONE_SET"
					missionVariables.feudal_score += 10
					mission.setInstructionsKey(null)
				}
			
			if(missionVariables.feudal_mission == "ESCORT_SUCCESS" && system.ID == [missionVariables.feudal_mission_location_no])
			
				{	player.credits += missionVariables.feudal_mission_reward
					mission.runScreen({messageKey:"feudal_mission_escort_success"})
					mission.unmarkSystem([missionVariables.feudal_mission_location_no])
					missionVariables.feudal_mission = "NONE_SET"
					missionVariables.feudal_score += 20
					mission.setInstructionsKey(null)
				}
				
			if(missionVariables.feudal_mission == "ESCORT_FAIL" && system.ID == [missionVariables.feudal_mission_location_no])
			
				{	if(missionVariables.feudal_mission_cargocount >=12)
			
					{	missionVariables.feudal_mission_reward = Math.floor(missionVariables.feudal_mission_reward*0.75)
						player.credits += missionVariables.feudal_mission_reward
						mission.runScreen({messageKey:"feudal_mission_escort_partialsuccess"})
						mission.unmarkSystem([missionVariables.feudal_mission_location_no])
						missionVariables.feudal_mission = "NONE_SET"
						missionVariables.feudal_score += 10
						mission.setInstructionsKey(null)	
					}
					
					if(missionVariables.feudal_mission_cargocount >= 6 && missionVariables.feudal_mission_cargocount < 12) 
			
					{	missionVariables.feudal_mission_reward = Math.floor(missionVariables.feudal_mission_reward*0.5)	
						mission.unmarkSystem([missionVariables.feudal_mission_location_no])
						player.credits += missionVariables.feudal_mission_reward
						mission.runScreen({messageKey:"feudal_mission_escort_partialsuccess"})
						missionVariables.feudal_mission = "NONE_SET"
						missionVariables.feudal_score += 5
						mission.setInstructionsKey(null)
					}
						
					if(missionVariables.feudal_mission_cargocount < 6)
			
					{	mission.runScreen({messageKey:"feudal_mission_escort_fail"})
						mission.unmarkSystem([missionVariables.feudal_mission_location_no])
						missionVariables.feudal_mission = "NONE_SET"
						missionVariables.feudal_score -= 10
						mission.setInstructionsKey(null)
					}
				
		}
	}
		
this.choiceEvaluation = function(choice)
	{
		
			if(missionVariables.feudal_mission_offer == "DELIVERY_OFFER")
			 
			 
				{	if(choice == "accept_mission")
					
					{this.feudalDeliveryChoice()
					missionVariables.feudal_mission_offer = null}
			
					if(choice == "decline_mission")
					{missionVariables.feudal_mission = "DELIVERY_DECLINED"
					missionVariables.feudal_mission_offer = null}
				}
			
			if(missionVariables.feudal_mission_offer == "TRIBUTE_OFFER")
			 
			 
				{	if(choice == "accept_mission")
					
					{this.feudalTributeChoice()
					missionVariables.feudal_mission_offer = null}
			
					if(choice == "decline_mission")
					{missionVariables.feudal_mission = "TRIBUTE_DECLINED"
					missionVariables.feudal_mission_offer = null}
				}
				
			if(missionVariables.feudal_mission_offer == "EXECUTION_OFFER")	
			
				{ 	if(choice == "accept_mission")	// acceptance for an execution mission
					{this.feudalExecutionChoice()
					missionVariables.feudal_mission_offer = null}
				
					if(choice == "decline_mission")
					{missionVariables.feudal_mission = "EXECUTION_DECLINED"
					missionVariables.feudal_mission_offer = null
					}
				}
				
			if(missionVariables.feudal_mission_offer == "RAID_OFFER")
				{	
				if(choice == "accept_mission")
				
					{this.feudalRaidChoice()
					missionVariables.feudal_mission_offer = null}
						
				if(choice == "decline_mission")
					{missionVariables.feudal_mission = "RAID_DECLINED"
					missionVariables.feudal_mission_offer = null}
				}
			
			if(missionVariables.feudal_mission_offer == "ESCORT_OFFER")	
			
				{ 	if(choice == "accept_mission")
					{this.feudalEscortChoice()
					missionVariables.feudal_mission_offer = null}
				
					if(choice == "decline_mission")
					{missionVariables.feudal_mission = "ESCORT_DECLINED"
					missionVariables.feudal_mission_offer = null}
				}
				
			if(missionVariables.feudal_mission_offer == "RANSOM_OFFER")	
			
				{ 	if(choice == "accept_mission")
					{this.feudalRansomChoice()
					missionVariables.feudal_mission_offer = null}
				
					if(choice == "decline_mission")
					{missionVariables.feudal_mission = "RANSOM_DECLINED"
					missionVariables.feudal_mission_offer = null}		
				}
	}
// ship appearance on launching
	
this.shipWillLaunchFromStation = function()
{if(missionVariables.feudal_mission_offer)
missionVariables.feudal_mission_offer = null}
// witchspace exit conditions
this.shipExitedWitchspace = function()
{	
			
	if(missionVariables.feudal_mission == "DELIVERY_RUNNING")
	
		{	if(Math.random() <= 0.25)
			system.legacy_addSystemShips("pirate", 4, 0.1)}
	
	if(missionVariables.feudal_mission == "RAID_RUNNING" && system.ID == [missionVariables.feudal_mission_location_no])
	
		{	system.legacy_addSystemShips([missionVariables.feudal_mission_role], 3, 0.5) // populate the system with the raid target along with some knights
			system.legacy_addSystemShips([missionVariables.feudal_mission_house]+"-knight", 12, 0.5)}
	if(missionVariables.feudal_mission == "EXECUTION_RUNNING" && system.ID == [missionVariables.feudal_mission_location_no])
	
		system.legacy_addSystemShips([missionVariables.feudal_mission_role], 1, 0.8) // populate the system with the execution target
		
		
	if(missionVariables.feudal_mission == "ESCORT_RUNNING" && system.ID == [missionVariables.feudal_mission_location_no])
		{	system.legacy_addSystemShips([missionVariables.feudal_mission_role], 3, 0.6) // populate the system with the freighter to be escorted
			system.legacy_addSystemShips([missionVariables.feudal_mission_home]+"-knight", 12, 0.6) // add some knights from the home side to support the freighter
			system.legacy_addSystemShips([missionVariables.feudal_mission_house]+"-knight", 7, 0.8) // add some knights from enemy side
			system.legacy_addSystemShips([missionVariables.feudal_mission_house]+"-lord", 1, 0.8) // add some lords from the enemy side
		}
		
	if(missionVariables.feudal_mission == "RANSOM_RUNNING" && system.ID == [missionVariables.feudal_mission_location_no])
		{system.legacy_addShipsAtPrecisely([missionVariables.feudal_mission_house]+"-prince", 1, "wsm", [0, 115000, 0])// add the ransom target
		
		}				
						
	
	if(missionVariables.feudal_mission)
	{if(missionVariables.feudal_mission.indexOf("DECLINED") > 1)
	{missionVariables.feudal_mission = "NONE_SET"
	mission.setInstructionsKey(null)
	this.resetMissionVariables()}}
}
this.playerEnteredNewGalaxy = function()
{	missionVariables.feudal_mission = "NONE_SET"
	mission.setInstructionsKey(null)
	this.resetMissionVariables()
	
}
 | 
                
                    | Scripts/feudal-planetfall.js | this.name		= "feudal-planetfall.js";
this.author		= "Thargoid/Ramirez";
this.copyright		= "Creative Commons: attribution, non-commercial, sharealike.";
this.description	= "Locations for Feudal States";
this.version		= "3.0";
this.shipWillLaunchFromStation = this.shipWillExitWitchspace = function()
	{
	if(system.government == 1)
	
		{if(galaxyNumber == 0 && system.techLevel >=7 || galaxyNumber == 1 && system.techLevel >= 5 || galaxyNumber == 2 && system.techLevel >= 7 || galaxyNumber == 4 && system.techLevel >=7 || galaxyNumber == 5 && system.techLevel >=8)
			{if(worldScripts.PlanetFall)
				worldScripts.PlanetFall.planetFallOverride = true; // set the override, so only external OXP locations appear
			}
		}
	}
this.shipWillEnterWitchspace = function()
	{
	if(system.government == 1)
		{if(galaxyNumber == 0 && system.techLevel >=7 || galaxyNumber == 1 && system.techLevel >= 5 || galaxyNumber == 2 && system.techLevel >= 7 || galaxyNumber == 4 && system.techLevel >=7 || galaxyNumber == 5 && system.techLevel >=8)
			{if(worldScripts.PlanetFall) 
				worldScripts.PlanetFall.planetFallOverride = false; // set things back to normal
		}
	}
}
 | 
                
                    | Scripts/feudal-promotion.js | this.name = "feudal-promotion.js";
this.author = "Ramirez";
this.copyright = "October 2012";
this.description = "World script for handling a player's feudal rank and promotions";
this.version = "6.0";
// Event handlers
this.shipDockedWithStation = function()
{	
	this.missionScreens()
}
this.guiScreenChanged = function()
{	if(guiScreen == "GUI_SCREEN_MISSION")  
	this.missionScreens()
}
// Mission Screens	
this.missionScreens = function()
{
if(guiScreen == "GUI_SCREEN_MISSION" || !player.ship.docked) return;
if(player.ship.dockedStation.hasRole("planetFall_feudalStates"))
{				
			
if(missionVariables.feudal_promotion_jumpcount == null)
{	if(!missionVariables.feudal_player_rank_no && missionVariables.feudal_score > 4)		
	{	
		mission.runScreen({messageKey: "feudal_knight_promotion", background: "redeagle.png", choicesKey: "feudal_rank_choices"}, this.choiceEvaluation)
		missionVariables.feudal_promotion_offer = "KNIGHT_OFFERED"}
	
	
	if(missionVariables.feudal_mission_home_galaxy !== galaxyNumber && missionVariables.feudal_player_rank_no >= 1)
	{
		mission.runScreen({messageKey: "feudal_promotion_transfer", background: "redeagle.png", choicesKey: "feudal_transfer_choices"}, this.choiceEvaluation)
		missionVariables.feudal_promotion_offer = "TRANSFER_OFFERED"}
}
if(missionVariables.feudal_player_rank_no == 1 && missionVariables.feudal_score > 39)
		{
		++missionVariables.feudal_player_rank_no
		this.defineGeneratorInputs()
		player.feudalRankGenerator()
		this.defineGeneratorOutputs()
		missionVariables.feudal_promotion_date = clock.clockString
		mission.runScreen({messageKey: "feudal_baron_promotion", background: "redeagle.png"})
		mission.setInstructionsKey("feudal_rank_details")
		missionVariables.feudal_promotion_jumpcount = null
		}
		
if(missionVariables.feudal_player_rank_no == 2 && missionVariables.feudal_score > 99)
		{
		++missionVariables.feudal_player_rank_no
		this.defineGeneratorInputs()
		player.feudalRankGenerator()
		this.defineGeneratorOutputs()
		missionVariables.feudal_promotion_date = clock.clockString
		mission.runScreen({messageKey: "feudal_further_promotion", background: "redeagle.png"})
		mission.setInstructionsKey("feudal_rank_details")
		missionVariables.feudal_promotion_jumpcount = null
		}
		
if(missionVariables.feudal_player_rank_no == 3 && missionVariables.feudal_score > 179)
		{
		++missionVariables.feudal_player_rank_no
		this.defineGeneratorInputs()
		player.feudalRankGenerator()
		this.defineGeneratorOutputs()
		missionVariables.feudal_promotion_date = clock.clockString
		mission.runScreen({messageKey: "feudal_further_promotion", background: "redeagle.png"})
		mission.setInstructionsKey("feudal_rank_details")
		missionVariables.feudal_promotion_jumpcount = null
		}
		
if(missionVariables.feudal_player_rank_no == 4 && missionVariables.feudal_score > 279)
		{
		++missionVariables.feudal_player_rank_no
		this.defineGeneratorInputs()
		player.feudalRankGenerator()
		this.defineGeneratorOutputs()
		missionVariables.feudal_promotion_date = clock.clockString
		mission.runScreen({messageKey: "feudal_further_promotion", background: "redeagle.png"})
		mission.setInstructionsKey("feudal_rank_details")
		missionVariables.feudal_promotion_jumpcount = null
		}	
		
		
if(missionVariables.feudal_player_rank_no == 5 && missionVariables.feudal_score > 399)
		{
		++missionVariables.feudal_player_rank_no
		this.defineGeneratorInputs()
		player.feudalRankGenerator()
		this.defineGeneratorOutputs()
		missionVariables.feudal_promotion_date = clock.clockString
		mission.runScreen({messageKey: "feudal_duke_promotion", background: "redeagle.png"})
		mission.setInstructionsKey("feudal_rank_details")
		missionVariables.feudal_promotion_jumpcount = null
		}	
}
}
// Choice evaluations
this.choiceEvaluation = function(choice)
	{
		if(missionVariables.feudal_promotion_offer == "KNIGHT_OFFERED")
			
				
			{	if(choice == "accept_rank_male")	
						{		
							missionVariables.feudal_promotion_offer = null
							missionVariables.feudal_mission_home = system.name
							missionVariables.feudal_mission_home_galaxy = galaxyNumber
							missionVariables.feudal_player_rank_no = 1
							missionVariables.feudal_player_rank = "Knight"
							missionVariables.feudal_player_title = "Sir"
							missionVariables.feudal_player_title_peer = "Lord"
							missionVariables.feudal_player_of = "of"
							missionVariables.feudal_player_gender = "he"
							mission.runScreen({messageKey: "feudal_promotion_knightaccept", background: "redeagle.png"})
							mission.setInstructionsKey("feudal_rank_details")
							missionVariables.feudal_tournament_jumpcount = 0
							}
				if(choice == "accept_rank_female")
						{	missionVariables.feudal_promotion_offer = null
							missionVariables.feudal_mission_home = system.name
							missionVariables.feudal_mission_home_galaxy = galaxyNumber
							missionVariables.feudal_player_rank_no = 1
							missionVariables.feudal_player_title = "Lady"
							missionVariables.feudal_player_title_peer = "Lady"
							missionVariables.feudal_player_rank = "Knight"
							missionVariables.feudal_player_of = "of"
							missionVariables.feudal_player_gender = "she"
							mission.runScreen({messageKey: "feudal_promotion_knightaccept", background: "redeagle.png"})
							mission.setInstructionsKey("feudal_rank_details")
							missionVariables.feudal_tournament_jumpcount = 0
						}	
				if(choice == "decline_rank")
						{	missionVariables.feudal_promotion_offer = null
							mission.runScreen({messageKey: "feudal_promotion_knightdecline", background: "redeagle.png"})
							}	
			}
		
		if(missionVariables.feudal_promotion_offer == "TRANSFER_OFFERED")
		
				if(choice == "accept_transfer")	
						{		
							
							missionVariables.feudal_promotion_offer = null
							missionVariables.feudal_mission_home = system.name
							missionVariables.feudal_mission_home_galaxy = galaxyNumber
							
							if(missionVariables.feudal_player_rank_no == 1)
							{	
								mission.runScreen({messageKey: "feudal_accept_knight_transfer", background: "redeagle.png"})
								mission.setInstructionsKey("feudal_rank_details")	
							}
							
							if(missionVariables.feudal_player_rank_no > 1)
							{
								this.defineGeneratorInputs()
								player.feudalRankGenerator()
								this.defineGeneratorOutputs()
								mission.runScreen({messageKey: "feudal_accept_transfer", background: "redeagle.png"})
							}
							
							mission.setInstructionsKey("feudal_rank_details")
							missionVariables.feudal_tournament_jumpcount = null
						}
				if(choice == "decline_transfer")	
						{	missionVariables.feudal_promotion_offer = null
							mission.runScreen({messageKey: "feudal_promotion_knightdecline", background: "redeagle.png"})		
							missionVariables.feudal_promotion_jumpcount = 0}	
		
	}
		
// Supporting functions
this.defineGeneratorInputs = function()
{
	player.rankGenerator_gender = missionVariables.feudal_player_gender
	player.rankGenerator_house = missionVariables.feudal_mission_home
	player.rankGenerator_level = missionVariables.feudal_player_rank_no
}
this.defineGeneratorOutputs = function()
{	
	missionVariables.feudal_player_of = player.rankGenerator_of
	missionVariables.feudal_player_rank = player.rankGenerator_feudal_specific_rank	
}
	
this.shipWillExitWitchspace = function()
{	
	if(missionVariables.feudal_promotion_jumpcount != null)
	missionVariables.feudal_promotion_jumpcount = null
}
 | 
                
                    | Scripts/feudal-ranks.js | this.name = "feudal-ranks.js";
this.author = "Ramirez";
this.copyright = "March 2013";
this.description = "Script used to generate ranks and names for feudal characters";
this.version = "5.0";
player.feudalRankGenerator = this.feudalRankGenerator = function()
{
    
    if(player.rankGenerator_house == "Geinona" || player.rankGenerator_house == "Bedierat" || player.rankGenerator_house == "Qurexein" || player.rankGenerator_house == "Sogeve")
    {var rankGenerator_language = "spanish"
    player.rankGenerator_of = "de"}
    
    if(player.rankGenerator_house == "Oreseren" || player.rankGenerator_house == "Aronar" ||
       player.rankGenerator_house == "Arries" || player.rankGenerator_house == "Orverace" || player.rankGenerator_house == "Ismaan" || player.rankGenerator_house == "Ansois"
       || player.rankGenerator_house == "Atlaar")
    {var rankGenerator_language = "dutch"
    player.rankGenerator_of = "van"}
    
    if(player.rankGenerator_house == "Digebiti" || player.rankGenerator_house == "Edzaon"
       || player.rankGenerator_house == "Usedge" || player.rankGenerator_house == "Israra" || player.rankGenerator_house == "Esceso" ||
       player.rankGenerator_house == "Dirateri" ||
       player.rankGenerator_house == "Onarmala" || player.rankGenerator_house == "Usteer")
    {var rankGenerator_language = "english"
    player.rankGenerator_of = "of"}
    if(player.rankGenerator_house == "Esredice" || player.rankGenerator_house == "Ededleen" || player.rankGenerator_house == "Reenus" ||
       player.rankGenerator_house == "Oneded" || player.rankGenerator_house == "Gexean" || player.rankGenerator_house == "Erinain" || player.rankGenerator_house == "Enbirare")
    {var rankGenerator_language = "german"
    player.rankGenerator_of = "von"}
    
    if(player.rankGenerator_house == "Gelaed" || player.rankGenerator_house == "Ridivexe" || player.rankGenerator_house == "Maedrebe" || player.rankGenerator_house == "Ceorat"
       || player.rankGenerator_house == "Biarandi")
    {var rankGenerator_language = "french"
    player.rankGenerator_of = "de"}
    if(player.rankGenerator_house == "Onusorle" || player.rankGenerator_house == "Tibedied" || player.rankGenerator_house == "Issoinen" || player.rankGenerator_house == "Erlaened" ||
       player.rankGenerator_house == "Atlaeser" || player.rankGenerator_house == "Onorti" || player.rankGenerator_house == "Resoisbe")
    {var rankGenerator_language = "swedish"
    player.rankGenerator_of = "af"}
    
    if(player.rankGenerator_house == "Tibecea" || player.rankGenerator_house == "Tiso" || player.rankGenerator_house == "Rabiarce" || player.rankGenerator_house == "Teususdi" || player.rankGenerator_house == "Diqudi")
    {var rankGenerator_language = "italian"
    player.rankGenerator_of = "di"}
    
    if(galaxyNumber == 4)
    {var rankGenerator_language = "russian"
    player.rankGenerator_of = "of"}
    
  if(galaxyNumber == 5)
    {var rankGenerator_language = "japanese"
    player.rankGenerator_of = "of"}
    
       
    player.rankGenerator_feudal_middle_rank = expandDescription("[feudal_middle_"+[rankGenerator_language]+"_"+[player.rankGenerator_gender]+"_rank]"); 
    player.rankGenerator_feudal_high_rank = expandDescription("[feudal_high_"+[rankGenerator_language]+"_"+[player.rankGenerator_gender]+"_rank]");    
    
    
    if(player.rankGenerator_level)
    {player.rankGenerator_feudal_specific_rank = expandDescription("[feudal_level"+[player.rankGenerator_level]+"_"+[rankGenerator_language]+"_"+[player.rankGenerator_gender]+"_rank]");}
     
    player.rankGenerator_feudal_firstname = expandDescription("[feudal_firstname_"+[rankGenerator_language]+"_"+[player.rankGenerator_gender]+"]");
    
    if(rankGenerator_language == "russian" && player.rankGenerator_gender == "she")
    player.rankGenerator_feudal_lastname = expandDescription("[feudal_lastname_"+[rankGenerator_language]+"]")+"a";
   
    else
    player.rankGenerator_feudal_lastname = expandDescription("[feudal_lastname_"+[rankGenerator_language]+"]");
}
 | 
                
                    | Scripts/feudal-target.js | this.name = "feudal-target.js";
this.author = "Ramirez";
this.copyright = "March 2013";
this.description = "Ship script for targets of feudal missions and challenges; checks roles, sets IDs, AIs and death actions as appropriate";
this.version = "1.6";
this.zeroEscorts = function()
{ 
if(this.ship.escorts.length > 0)
   {   
	  this.ship.escorts[0].remove();
	  //log('escort removed')
   }
   
if(this.ship.escorts.length == 0)
   {this.zETimer.stop()
   //log('timer stopped')
}
} 
this.shipSpawned = function ()// set up IDs and AIs for targets
{
	if(missionVariables.feudal_mission == "NONE_SET")
 		{this.zETimer = new Timer(this,this.zeroEscorts,null,0.2);} 
      if(missionVariables.feudal_mission == "EXECUTION_RUNNING" && this.ship.primaryRole == [missionVariables.feudal_mission_role])
	
		{	if(this.ship.displayName == this.ship.name)
			this.ship.displayName = expandDescription("[mission_feudal_mission_level1_title] [mission_feudal_mission_firstname] [mission_feudal_mission_lastname]") // Show the ID of the execution target
		}
			//also in future set an AI specific to the EXECUTION mission
		
	if(missionVariables.feudal_mission == "RANSOM_RUNNING")
	
         {	if(this.ship.primaryRole == [missionVariables.feudal_mission_house]+"-prince")
			{
			   {this.zETimer = new Timer(this,this.zeroEscorts,null,0.2);} 
					
			   if(this.ship.displayName == this.ship.name)
				  {this.ship.displayName = expandDescription("[mission_feudal_mission_rank] [mission_feudal_mission_of] [mission_feudal_mission_house]")}
			   }
                                
            if(this.ship.primaryRole == [missionVariables.feudal_mission_house]+"-knight")
                  { this.ship.switchAI("feudal-escortAI.plist") }
               }
	if(missionVariables.feudal_mission == "RAID_RUNNING")
	
	  {  if(this.ship.primaryRole == missionVariables.feudal_mission_role) 
			{
			   this.zETimer = new Timer(this,this.zeroEscorts,null,0.2)
                
			   if(this.ship.displayName == this.ship.name) 
						{   this.ship.displayName = expandDescription("[mission_feudal_mission_house] [mission_feudal_mission_commodity] convoy")} // Show the ID of the raid target 			    
                        }
                  if(this.ship.primaryRole == [missionVariables.feudal_mission_house]+"-knight")
				  {this.ship.switchAI("feudal-escortAI.plist")}
	  }
	
	 if(missionVariables.feudal_mission == "ESCORT_RUNNING")
	
		{	if(this.ship.primaryRole == missionVariables.feudal_mission_role)
				{
					{this.zETimer=new Timer(this,this.zeroEscorts,null,0.2);} 
					
					if(this.ship.displayName == this.ship.name)
						{	this.ship.displayName = expandDescription("[mission_feudal_mission_home] [mission_feudal_mission_commodity] convoy")} // Show the ID of the freighter to be escorted			
				}	
	
		
			if(this.ship.primaryRole == [missionVariables.feudal_mission_home]+"-knight") // home knights to protect escort
			{     this.ship.switchAI("feudal-escortAI.plist")
                     if(this.ship.displayName == this.ship.name)
						{	this.ship.displayName = expandDescription("[mission_feudal_mission_home] Knight (friendly)") // Show the ID of the friendly knight	
						}
                        }
                       		
			if(this.ship.primaryRole == [missionVariables.feudal_mission_house]+"-knight") // enemy knights to find and attack escort
			{     this.ship.switchAI("feudal-raidAI.plist")
                        
                     if(this.ship.displayName == this.ship.name)
						{	this.ship.displayName = expandDescription("[mission_feudal_mission_house] Knight (enemy)")} // Show the ID of the enemy knight			
            }
					
			
			if(this.ship.primaryRole == [missionVariables.feudal_mission_house]+"-lord") // enemy lords to attack escort
			{     this.ship.switchAI("feudal-raidAI.plist")
                  if(this.ship.displayName == this.ship.name)
						{	this.ship.displayName = expandDescription("[mission_feudal_mission_house] Lord (enemy)")} // Show the ID of the enemy lord		
            }
				
		}
         
         if(missionVariables.feudal_challenger == "RUNNING" && this.ship.primaryRole == [missionVariables.feudal_challenger_role])
	
		 {	if(this.ship.displayName == this.ship.name)
			
            {this.ship.awardEquipment("EQ_MISSILE_REMOVAL")
			this.zETimer=new Timer(this,this.zeroEscorts,null,0.2);
            if(missionVariables.feudal_challenger_rank_no == 1)
               {this.ship.switchAI("feudal-challenger1AI.plist")
               this.ship.displayName = expandDescription("[mission_feudal_challenger_title] [mission_feudal_challenger_firstname] [mission_feudal_challenger_lastname]")}         
               else
               {this.ship.displayName = expandDescription("[mission_feudal_challenger_rank] [mission_feudal_challenger_of] [mission_feudal_challenger_house]")
			   this.ship.switchAI("feudal-challenger2AI.plist")}
            }     
         }
                
         if(missionVariables.feudal_tournament == "EVENT3_RUNNING")
         
         {if(this.ship.primaryRole == "feudal-knight" || "feudal-lord" || "feudal-prince")
             {this.ship.switchAI("feudal-quartetAI.plist")
             this.ship.fuel = 0	  
             {this.zETimer = new Timer(this,this.zeroEscorts,null,0.2);}       
             }
           if(this.ship.primaryRole == "feudal-drone")
             this.ship.switchAI("pirateAI.plist")
         }
           if(missionVariables.feudal_tournament == "EVENT5_RUNNING")
         {   this.ship.switchAI("feudal-meleeAI.plist")
		     {this.zETimer=new Timer(this,this.zeroEscorts,null,0.2);}
             }        
         
         if(missionVariables.feudal_tournament == "EVENT6_RUNNING")
         {  this.ship.switchAI("feudal-challenger2AI.plist")
			{this.zETimer=new Timer(this,this.zeroEscorts,null,0.2);}
            this.ship.fuel = 100
            this.ship.displayName = expandDescription("[mission_feudal_tournament_opponent_text]")
         }        
}
this.shipDied = function(whom)
{      
         
               if(missionVariables.feudal_tournament == "EVENT1_RUNNING") 
               {if(this.ship.primaryRole == "feudal-shield")
               {var buoy = system.shipsWithRole("feudal-buoy")[0]
               this.ship.target = buoy
               this.ship.target.switchAI("feudal-buoy-checkAI.plist")}
               }         
         
               if(missionVariables.feudal_tournament == "EVENT2_RUNNING")
               {++missionVariables.feudal_tournament_kills
               player.commsMessage("Stage "+ [missionVariables.feudal_tournament_kills]+" destroyed.")
            
               {  if (this.ship.primaryRole == "feudal-drone-1")
                        this.ship.spawn("feudal-drone-2", 1)
               
                  if (this.ship.primaryRole == "feudal-drone-2")
                        this.ship.spawn("feudal-drone-3", 1)
                  if (this.ship.primaryRole == "feudal-drone-3")
                        this.ship.spawn("feudal-drone-4", 1)
                  if (this.ship.primaryRole == "feudal-drone-4")
                        this.ship.spawn("feudal-drone-5", 1)
               }
               }
               
               if(missionVariables.feudal_tournament == "EVENT4_RUNNING")
                     if(this.ship.primaryRole == "feudal-shield-pod")
                     this.ship.spawn("feudal-small-shield", 1)   
               
               if(missionVariables.feudal_tournament == "EVENT5_RUNNING")
               {               
                  if(this.ship.AI == "feudal-meleeAI.plist")
                  {--missionVariables.feudal_tournament_ships
               
                     if(missionVariables.feudal_tournament_ships > 2)
                       player.commsMessage(this.ship.name+" destroyed. "+missionVariables.feudal_tournament_ships+" competitors remaining.")
               
                     else   
                  
                  {var buoy = system.shipsWithRole("feudal-buoy")[0]
                  this.ship.target = buoy
                  this.ship.target.switchAI("feudal-buoy-logAI.plist")
                  player.commsMessage(this.ship.name+" destroyed. Two competitors remaining.  Please return to the Hunting Lodge")
                  }
                  
               } 
               }
               
               if(missionVariables.feudal_tournament == "EVENT6_RUNNING")
               ++missionVariables.feudal_tournament_kills
              
               if(missionVariables.feudal_mission == "EXECUTION_RUNNING" && this.ship.primaryRole == [missionVariables.feudal_mission_role])
			   {  if(whom == player.ship)
				  	missionVariables.feudal_mission = "EXECUTION_SUCCESS" // set the mission variable to success
				  	else
				   	missionVariables.feudal_mission = "EXECUTION_PARTIAL" // have a partial success where the player is awarded fewer points
			   }
		 if(missionVariables.feudal_mission == "RAID_RUNNING" || missionVariables.feudal_mission == "RAID_SUCCESS")
		 
		 {
		if(this.ship.primaryRole == missionVariables.feudal_mission_role)	// if it's a raid, get the target ship to spawn some of the selected commodity
		{this.ship.spawn("feudal-cargo", 6)
		missionVariables.feudal_mission = "RAID_SUCCESS"
		mission.setInstructionsKey("feudal_mission_raid_return", "feudal-mission.js")}
		 }
		if(missionVariables.feudal_mission == "RANSOM_RUNNING" && this.ship.primaryRole == [missionVariables.feudal_mission_house]+"-prince")
	
                  {this.ship.spawn("feudal-escape-pod", 1)}
		
	       if(missionVariables.feudal_mission == "ESCORT_RUNNING" && this.ship.primaryRole == missionVariables.feudal_mission_role)	// if it's an escort mission, get the target ship to spawn some of the selected commodity
		{this.ship.spawn("feudal-cargo", 6)
		missionVariables.feudal_mission = "ESCORT_FAIL"
		player.commsMessage("One of the freighters has been destroyed!", 6)}
		
	       if(missionVariables.feudal_mission == "ESCORT_RUNNING" && this.ship.primaryRole == [missionVariables.feudal_mission_house]+"-knight")
                missionVariables.feudal_mission_killcount += 1
                
               if(missionVariables.feudal_mission == "ESCORT_RUNNING" && missionVariables.feudal_mission_killcount == 10)
               {missionVariables.feudal_mission = "ESCORT_SUCCESS"
               player.commsMessage("The enemy knights have been destroyed.  We can take it from here.")}
               
               if(missionVariables.feudal_challenger == "VICTORY")
               {this.ship.spawn("feudal-escape-pod", 1)
               missionVariables.feudal_challenger = "FORFEIT"}
               
                if(missionVariables.feudal_challenger == "RUNNING")
               {this.ship.spawn("feudal-escape-pod", 1)
               missionVariables.feudal_challenger = "VICTORY"}
		
		//award player points if they shoot enemy ships at any time during a mission
		
	       	if(whom == player.ship)
		
			{	if(this.ship.primaryRole == [missionVariables.feudal_mission_house]+"-knight")
					{missionVariables.feudal_score += 1}
				if(this.ship.primaryRole == [missionVariables.feudal_mission_house]+"-lord")
					missionVariables.feudal_score += 5
				
				if(this.ship.primaryRole == [missionVariables.feudal_mission_house]+"-prince")
					{missionVariables.feudal_score += 20}
			}
               }
                
this.shipBeingAttacked = function()
{  if(missionVariables.feudal_tournament == "EVENT5_RUNNING")
      {if(this.ship.energy > 1000)
      this.ship.energy = 500}
}
this.shipEnteredStationAegis = function(station)
	{	if(missionVariables.feudal_mission == "ESCORT_RUNNING" && this.ship.primaryRole == missionVariables.feudal_mission_role)
		{	missionVariables.feudal_mission = "ESCORT_SUCCESS"
			this.ship.commsMessage("Thanks, Commander.  We've made it to the station in one piece.  We can take it from here.", 6) 
		}
		  if((missionVariables.feudal_mission == "ESCORT_RUNNING" || missionVariables.feudal_mission == "ESCORT_SUCCESS") && this.ship.primaryRole == [missionVariables.feudal_mission_house]+"-knight")  
	       {	this.ship.commsMessage("Let's get out of here!", 6) 
			//log('knight entering aegis')
			this.ship.switchAI("route1traderAI.plist")
	       }
	}
        
this.shipEnergyIsLow = function()
   {   if(missionVariables.feudal_challenger == "RUNNING" && this.ship.primaryRole == [missionVariables.feudal_challenger_role])
	{this.ship.spawn("feudal-flare", 1);
      this.ship.commsMessage(expandDescription("[feudal-yield]"))
      this.ship.switchAI("feudal-challengerhomeAI.plist")
      missionVariables.feudal_challenger = "VICTORY"}
      
      if(missionVariables.feudal_tournament == "EVENT5_RUNNING")
         {
            if(this.ship.AI == "feudal-meleeAI.plist")
            {if(Math.random() < 0.25)
            {this.ship.switchAI("feudal-challengerhomeAI.plist")
            --missionVariables.feudal_tournament_ships
            
            if(missionVariables.feudal_tournament_ships > 2)
                  {player.commsMessage(this.ship.name+" surrendered. "+missionVariables.feudal_tournament_ships+" competitors remaining.")
                  this.ship.displayName = this.ship.name+" (Surrendered)"}
               
               else   
                  
                  {var buoy = system.shipsWithRole("feudal-buoy")[0]
                  this.ship.target = buoy
                  this.ship.target.switchAI("feudal-buoy-logAI.plist")
                  this.ship.displayName = this.ship.name+" (Surrendered)"
                  player.commsMessage(this.ship.name+" surrended. Two competitors remaining.  Please return to the Hunting Lodge")
                  }
            }
      }}
   }      
this.shipTargetLost = function()
   {    if(missionVariables.feudal_challenger == "RUNNING")
         this.ship.switchAI("feudal-challengerhomeAI.plist")}
this.checkDistance = function()
{if(player.ship.position.distanceTo(this.ship) < 5000)
   {this.ship.target = player.ship;
   this.ship.reactToAIMessage("FOUND_PLAYER")}
   }
this.shipWasScooped = function (whom)
   { if(this.ship.primaryRole == "feudal-drone" && whom == player.ship )
		
         {  if(missionVariables.feudal_tournament == "EVENT3_RUNNING")
                {++missionVariables.feudal_tournament_scoops
                player.commsMessage("Target drone collected.  Return to the Hunting Lodge.")}                     
         }         
      if(this.ship.primaryRole == "feudal-small-shield" && whom == player.ship )         
         
         {if(missionVariables.feudal_tournament == "EVENT4_RUNNING")
                {++missionVariables.feudal_tournament_scoops
                player.commsMessage("Score: " + [missionVariables.feudal_tournament_scoops] + " out of 10")}                     
                }         
         }
                
            
   
 | 
                
                    | Scripts/feudal-tournament.js | this.name = "feudal-tournament.js";
this.author = "Ramirez";
this.copyright = "October 2012";
this.description = "World script for setting up feudal tournaments";
this.version = "10.0";
// Event handlers
this.shipDockedWithStation = function()
{	
	this.missionScreens()
}
this.missionScreenEnded = function()
{
	if(!player.ship.docked) return;
			
}
this.guiScreenChanged = function()
{	if(guiScreen == "GUI_SCREEN_MARKET")
	this.missionScreens()
}
this.defineTournamentHome = function()
{missionVariables.feudal_tournament_home = expandDescription("[feudal_house_"+[galaxyNumber]+"]")}
this.checkPlayerShip = function()
{
	this.playerSubentities = player.ship.subEntities
	this.playerSubentitiesString = playerSubentities.toString();
	if(playerSubentitiesString.indexOf("turret") != -1)
	missionVariables.feudal_tournament_eligible = "FALSE"
}
// Mission screens
this.missionScreens = function()
    {   if(guiScreen == "GUI_SCREEN_MISSION" || !player.ship.docked) return;
	
	if(!missionVariables.feudal_tournament_offer && !missionVariables.feudal_tournament)
	{
		if(galaxyNumber <= 2 || galaxyNumber == 4 || galaxyNumber == 5)
			{if(missionVariables.feudal_tournament_jumpcount > 50)
		
		
			{	this.defineTournamentHome()
				mission.runScreen({title: "Incoming Message", messageKey: "feudal_tournament_announcement", background: "redeagle.png"})
				missionVariables.feudal_tournament_offer = "TOURNAMENT_OPEN"
				mission.setInstructionsKey("feudal_tournament_location")
				missionVariables.feudal_tournament_deadline = clock.days + 30}
			}
	}
	
	if(missionVariables.feudal_tournament_offer == "TOURNAMENT_OPEN")
	{
		if(missionVariables.feudal_tournament_deadline)
		
		{	if(clock.days > missionVariables.feudal_tournament_deadline)
		
			{	this.defineTournamentGender()
				this.defineTournamentOpponentHouse()
				missionVariables.feudal_tournament_opponent_rank_no = Math.floor(Math.random()*2 + 1)
				this.defineTournamentInputs()
				player.feudalRankGenerator()
				this.defineTournamentOutputs()
				mission.runScreen({title: "Incoming Message", messageKey: "feudal_tournament_winner", background: "redeagle.png"})
				this.resetTournament()
				mission.setInstructionsKey(null)
				missionVariables.feudal_tournament_deadline = null
			}
	}
	}
	
	if(player.ship.dockedStation.hasRole("feudal-hunting-lodge") && missionVariables.feudal_tournament_home == system.name)
		{	
		if(guiScreen == "GUI_SCREEN_MARKET")		 
		{
			if(missionVariables.feudal_tournament_offer == "TOURNAMENT_OPEN")	
				{
				this.checkPlayerShip()
				
				if(missionVariables.feudal_tournament_eligible == "FALSE")
				{mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_tournament_ineligible"});}
				
				if(!missionVariables.feudal_tournament_eligible)
				{mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_tournament_offer", background: "redeagle.png", music: "feudal_music.ogg", choicesKey: "feudal_tournament_choices"}, this.choiceEvaluation)	
				missionVariables.feudal_tournament_offer = "TOURNAMENT_OFFERED"}
				
				}
			
			if(missionVariables.feudal_tournament_offer == "EVENT_BRIEFING")
				{
				mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_tournament_"+[missionVariables.feudal_tournament], choicesKey: "feudal_tournament_event_choices"}, this.choiceEvaluation)
				mission.setInstructionsKey("feudal_tournament_"+[missionVariables.feudal_tournament]+"_briefing")}		
		
			if(missionVariables.feudal_tournament_offer == "EVENT_DECLINED")
				{		
				mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_tournament_"+[missionVariables.feudal_tournament], choicesKey: "feudal_tournament_event_choices"}, this.choiceEvaluation)
				missionVariables.feudal_tournament_offer = "EVENT_BRIEFING"
				mission.setInstructionsKey("feudal_tournament_"+[missionVariables.feudal_tournament]+"_briefing")}
		}
		if(missionVariables.feudal_tournament == "EVENT1_RUNNING")
		{	
			
			if(missionVariables.feudal_tournament_kills >= 8)
				
			{
				mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_tournament_EVENT1_PASSED"})
				missionVariables.feudal_tournament = "EVENT2"
				missionVariables.feudal_tournament_offer = "EVENT_BRIEFING"
				missionVariables.feudal_tournament_kills = null
				this.restoreMissiles()
			}
			
			else
			{	mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_tournament_EVENT1_FAILED"})
				this.resetTournament()
				this.restoreMissiles()}
		}
			
		if(missionVariables.feudal_tournament == "EVENT2_RUNNING")
		{	
			if(player.ship.equipmentStatus("EQ_FS_BOMB_PLACEHOLDER") == "EQUIPMENT_OK")
					{	player.ship.removeEquipment("EQ_FS_BOMB_PLACEHOLDER")
						player.ship.awardEquipment("EQ_ENERGY_BOMB")
						player.consoleMessage("Energy Bomb re-enabled")}
			if(missionVariables.feudal_tournament_kills >= 4)
				
			{	mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_tournament_EVENT2_PASSED"})
				missionVariables.feudal_tournament = "EVENT3"
				missionVariables.feudal_tournament_offer = "EVENT_BRIEFING"
				missionVariables.feudal_tournament_kills = null
				this.restoreMissiles()
			}
			
			else
			{	mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_tournament_EVENT2_FAILED"})
				this.resetTournament()
				this.restoreMissiles()
			}
		}
		
		
		if(missionVariables.feudal_tournament == "EVENT3_RUNNING")
		{
			if(player.ship.equipmentStatus("EQ_FS_INJECTION_PLACEHOLDER", "EQUIPMENT_OK"))
			{	player.ship.removeEquipment("EQ_FS_INJECTION_PLACEHOLDER")
				player.ship.awardEquipment("EQ_FUEL_INJECTION")
				player.consoleMessage("Fuel Injectors re-enabled")}
				
		
			if(missionVariables.feudal_tournament_scoops >=1)
			
			{	mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_tournament_EVENT3_PASSED"})
				missionVariables.feudal_tournament_offer = "EVENT_BRIEFING"
				missionVariables.feudal_tournament = "EVENT4"
				missionVariables.feudal_tournament_scoops = null}
			
			else
			{	mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_tournament_EVENT3_FAILED"})
				this.resetTournament()}
		}
		
		if(missionVariables.feudal_tournament == "EVENT4_RUNNING")
		{
			if(missionVariables.feudal_tournament_scoops >=8)
			
			{	mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_tournament_EVENT4_PASSED"})
				missionVariables.feudal_tournament_offer = "EVENT_BRIEFING"
				missionVariables.feudal_tournament = "EVENT5"
				missionVariables.feudal_tournament_scoops = null
				this.restoreMissiles()}
			
			else
			{	mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_tournament_EVENT4_FAILED"})
				this.resetTournament()
				this.restoreMissiles()}
		}
		
		if(missionVariables.feudal_tournament == "EVENT5_RUNNING")
		{
			if(player.ship.equipmentStatus("EQ_FS_BOMB_PLACEHOLDER") == "EQUIPMENT_OK")
					{	player.ship.removeEquipment("EQ_FS_BOMB_PLACEHOLDER")
						player.ship.awardEquipment("EQ_ENERGY_BOMB")
						player.consoleMessage("Energy Bomb re-enabled")}
						
						
			if(missionVariables.feudal_tournament_ships <= 2)
			
			{	this.defineTournamentGender()
				this.defineTournamentInputs()
				player.feudalRankGenerator()
				this.defineTournamentOutputs()
				mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_tournament_EVENT5_PASSED"})
				missionVariables.feudal_tournament_offer = "EVENT_BRIEFING"
				missionVariables.feudal_tournament = "EVENT6"
				missionVariables.feudal_tournament_ships = null}
			
			else
			{	mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_tournament_EVENT5_FAILED"})
				this.resetTournament()}	
		}
		
		if(missionVariables.feudal_tournament == "EVENT6_RUNNING")
		{
			if(player.ship.equipmentStatus("EQ_FS_BOMB_PLACEHOLDER") == "EQUIPMENT_OK")
					{	player.ship.removeEquipment("EQ_FS_BOMB_PLACEHOLDER")
						player.ship.awardEquipment("EQ_ENERGY_BOMB")
						player.consoleMessage("Energy Bomb re-enabled")}
			
			if(missionVariables.feudal_tournament_kills == 1)
			
			{	
				mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_tournament_EVENT6_PASSED"})
				missionVariables.feudal_tournament_offer = null
				missionVariables.feudal_tournament = null
				missionVariables.feudal_tournament_kills = null
				missionVariables.feudal_score += 100
				player.credits += 100000
				this.resetTournament()
				this.restoreMissiles()}
			
			else
			{	mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_tournament_EVENT6_FAILED"})
				this.resetTournament()
				this.restoreMissiles()}	
		}
	}	
    }
    
    
this.removeMissiles = function()
{this.storeMissileArray = player.ship.missiles;
player.ship.awardEquipment("EQ_MISSILE_REMOVAL")}
this.restoreMissiles = function()
{player.ship.awardEquipment("EQ_MISSILE_REMOVAL")
	for(restoreCounter = 0;restoreCounter<this.storeMissileArray.length;restoreCounter++)
        {player.ship.awardEquipment(this.storeMissileArray[restoreCounter].equipmentKey);}
}
this.choiceEvaluation = function(choice)
	{
		if(missionVariables.feudal_tournament_offer == "TOURNAMENT_OFFERED")
			
				
			{	if(choice == "enter_tournament")	
					
							{	
								missionVariables.feudal_tournament = "EVENT1"
								missionVariables.feudal_tournament_offer = "EVENT_BRIEFING"
								mission.runScreen({title: "Royal Hunting Lodge", background: "redeagle.png", messageKey: "feudal_tournament_"+[missionVariables.feudal_tournament], choicesKey: "feudal_tournament_event_choices"}, this.choiceEvaluation)
								mission.setInstructionsKey("feudal_tournament_"+[missionVariables.feudal_tournament]+"_briefing")
								missionVariables.feudal_tournament_deadline = null
							}
					
				if(choice == "decline_tournament")	
			
							{
								mission.runScreen({title: "Royal Hunting Lodge", background: "redeagle.png", messageKey: "feudal_tournament_declined"})
								this.resetTournament()
								return
							}
			}
					
		if(missionVariables.feudal_tournament_offer == "EVENT_BRIEFING")
			{
				if(choice == "defer_event")
					{mission.runScreen({title: "Royal Hunting Lodge", messageKey: "feudal_tournament_deferred"})
					missionVariables.feudal_tournament_offer = "EVENT_DECLINED"
					}
				
				if(missionVariables.feudal_tournament == "EVENT1")			
				{	if(choice == "begin_event")
					{missionVariables.feudal_tournament = "EVENT1_RUNNING"
					missionVariables.feudal_tournament_offer = null
					missionVariables.feudal_tournament_kills = 0
					this.removeMissiles()
					player.ship.launch()
					}		
				}
				
				if(missionVariables.feudal_tournament == "EVENT2")			
				{	if(choice == "begin_event")
					{missionVariables.feudal_tournament = "EVENT2_RUNNING"
					missionVariables.feudal_tournament_offer = null
					missionVariables.feudal_tournament_kills = 0
					this.removeMissiles()
					if(player.ship.equipmentStatus("EQ_ENERGY_BOMB") == "EQUIPMENT_OK")
					{	player.ship.removeEquipment("EQ_ENERGY_BOMB")
						player.ship.awardEquipment("EQ_FS_BOMB_PLACEHOLDER")
						player.consoleMessage("Energy Bomb disabled")}
					player.ship.launch()
					}		
				}
				
				if(missionVariables.feudal_tournament == "EVENT3")			
				{	if(choice == "begin_event")
					{missionVariables.feudal_tournament = "EVENT3_RUNNING"
					missionVariables.feudal_tournament_offer = null
					missionVariables.feudal_tournament_scoops = 0
					player.ship.launch()
					}		
				}
				
				if(missionVariables.feudal_tournament == "EVENT4")			
				{	if(choice == "begin_event")
					{missionVariables.feudal_tournament = "EVENT4_RUNNING"
					missionVariables.feudal_tournament_offer = null
					missionVariables.feudal_tournament_scoops = 0
					player.ship.launch()
					}		
				}
				
				if(missionVariables.feudal_tournament == "EVENT5")			
				{	if(choice == "begin_event")
					{missionVariables.feudal_tournament = "EVENT5_RUNNING"
					missionVariables.feudal_tournament_offer = null
					missionVariables.feudal_tournament_ships = 100
					if(player.ship.equipmentStatus("EQ_ENERGY_BOMB") == "EQUIPMENT_OK")
					{	player.ship.removeEquipment("EQ_ENERGY_BOMB")
						player.ship.awardEquipment("EQ_FS_BOMB_PLACEHOLDER")
						player.consoleMessage("Energy Bomb disabled")}
					player.ship.launch()
					}		
				}
				
				if(missionVariables.feudal_tournament == "EVENT6")			
				{	if(choice == "begin_event")
					{missionVariables.feudal_tournament = "EVENT6_RUNNING"
					missionVariables.feudal_tournament_offer = null
					missionVariables.feudal_tournament_kills = 0
					if(player.ship.equipmentStatus("EQ_ENERGY_BOMB") == "EQUIPMENT_OK")
					{	player.ship.removeEquipment("EQ_ENERGY_BOMB")
						player.ship.awardEquipment("EQ_FS_BOMB_PLACEHOLDER")
						player.consoleMessage("Energy Bomb disabled")}
					this.removeMissiles()
					player.ship.launch()
					}		
				}	
			}	
	}				
// ship appearance on launching	
this.shipWillLaunchFromStation = function()
{	
	
	
	if(missionVariables.feudal_tournament_offer == "TOURNAMENT_OFFERED")
	missionVariables.feudal_tournament_offer = "TOURNAMENT_OPEN"
	
	
	
	if(missionVariables.feudal_tournament == "EVENT1_RUNNING")
		
		{system.legacy_addShipsWithinRadius("feudal-shield", 10, "wsm", [0, 122000, 0], 23000)}
	
	if(missionVariables.feudal_tournament == "EVENT2_RUNNING")
		{system.legacy_addShipsWithinRadius("feudal-drone-1", 1, "wsm", [0, 122000, 0], 5000)}
		
	if(missionVariables.feudal_tournament == "EVENT3_RUNNING")
		{
			if(player.ship.equipmentStatus("EQ_FUEL_INJECTION") == "EQUIPMENT_OK")
			{	player.ship.removeEquipment("EQ_FUEL_INJECTION")
				player.ship.awardEquipment("EQ_FS_INJECTION_PLACEHOLDER")
				player.consoleMessage("Fuel Injectors disabled")}
		system.legacy_addShipsWithinRadius("feudal-drone", 1, "wsm", [0, 122000, 0], 2000)
		system.addShips(expandDescription("[feudal_house_"+[galaxyNumber]+"]")+"-knight", 1, player.ship.position, 5000)
		system.addShips(expandDescription("[feudal_house_"+[galaxyNumber]+"]")+"-prince", 1, player.ship.position, 5000)
		system.addShips(expandDescription("[feudal_house_"+[galaxyNumber]+"]")+"-lord", 1, player.ship.position, 5000)
		}
	
	
	if(missionVariables.feudal_tournament == "EVENT4_RUNNING")
		{
		system.legacy_addShipsAtPrecisely("feudal-gate-away", 1, "wsu", [0, 0, -2.05])
		system.legacy_addShipsWithinRadius("feudal-gate-home", 1, "wsm", [0, 122000, 0], 20000)
		system.legacy_addShipsWithinRadius("new-asteroid", 64, "wsu", [0, 0, -2.01], 25000)
		system.legacy_addShipsWithinRadius("new-asteroid", 64, "wsu", [0, 0, -2.01], 12000)
		system.legacy_addShipsWithinRadius("new-asteroid", 32, "wsu", [0, 0, -2.01], 12000)
		system.legacy_addShipsWithinRadius("feudal-mine", 16, "wsu", [0, 0, -2.01], 12000)
		system.legacy_addShipsWithinRadius("feudal-mine", 16, "wsu", [0, 0, -2.01], 25000)
		system.legacy_addShipsWithinRadius("feudal-mine", 16, "wsu", [0, 0, -2.01], 25000)
		system.legacy_addShipsWithinRadius("new-asteroid", 32, "wsu", [0, 0, -2.01], 12000)
		system.legacy_addShipsWithinRadius("new-asteroid", 32, "wsu", [0, 0, -2.01], 12000)
		system.legacy_addShipsWithinRadius("feudal-shield-pod", 10, "wsu", [0, 0, -2.01], 12000)
		}
	
	if(missionVariables.feudal_tournament == "EVENT5_RUNNING")
	
	{	
		system.legacy_addShipsWithinRadius(expandDescription("[feudal_house_"+[galaxyNumber]+"]")+"-knight", 49, "wsm", [0, 122000, 0], 10000)
		system.legacy_addShipsWithinRadius(expandDescription("[feudal_house_"+[galaxyNumber]+"]")+"-lord", 30, "wsm", [0, 122000, 0], 10000)
		system.legacy_addShipsWithinRadius(expandDescription("[feudal_house_"+[galaxyNumber]+"]")+"-prince", 20, "wsm", [0, 122000, 0], 10000)
	}
	
	if(missionVariables.feudal_tournament == "EVENT6_RUNNING")
	
	{	
		system.legacy_addShipsWithinRadius([missionVariables.feudal_tournament_opponent_role], 1, "wsm", [0, 122000, 0], 5000)
	}
		
}
this.shipWillExitWitchspace = function()
{	
	
	if(missionVariables.feudal_tournament_jumpcount != null)
	++missionVariables.feudal_tournament_jumpcount
	
	if(missionVariables.feudal_tournament == "EVENT1_RUNNING" || missionVariables.feudal_tournament == "EVENT2_RUNNING" || missionVariables.feudal_tournament == "EVENT4_RUNNING" || missionVariables.feudal_tournament == "EVENT6_RUNNING")
	{this.resetTournament()
	player.commsMessage("Tournament event has been forfeit.")}
	if(missionVariables.feudal_tournament == "EVENT3_RUNNING")
	{this.resetTournament()
	player.commsMessage("Tournament event has been forfeit.")
	if(player.ship.equipmentStatus("EQ_FS_INJECTION_PLACEHOLDER") == "EQUIPMENT_OK")
		{
			player.ship.removeEquipment("EQ_FS_INJECTION_PLACEHOLDER")
			player.ship.awardEquipment("EQ_FUEL_INJECTION")
			player.consoleMessage("Fuel Injectors re-enabled")}			
		}
		
	if(missionVariables.feudal_tournament == "EVENT5_RUNNING" || missionVariables.feudal_tournament == "EVENT6_RUNNING")
	{this.resetTournament()
	player.commsMessage("Tournament event has been forfeit.")
	if(player.ship.equipmentStatus("EQ_FS_BOMB_PLACEHOLDER") == "EQUIPMENT_OK")
		{
			player.ship.removeEquipment("EQ_FS_BOMB_PLACEHOLDER")
			player.ship.awardEquipment("EQ_ENERGY_BOMB")
			player.consoleMessage("Energy Bomb re-enabled")}			
		}
	
}
this.playerEnteredNewGalaxy = function()
{	
	
	if(missionVariables.feudal_player_rank_no >= 1)
	this.resetTournament()
}
this.resetTournament = function()
{
	missionVariables.feudal_tournament = null
	missionVariables.feudal_tournament_offer = null
	mission.setInstructionsKey(null)
	missionVariables.feudal_tournament_kills = null
	missionVariables.feudal_tournament_home = null
	missionVariables.feudal_tournament_scoops = null
	missionVariables.feudal_tournament_ships = null
	missionVariables.feudal_tournament_opponent_role = null
	missionVariables.feudal_tournament_opponent_gender = null
	missionVariables.feudal_tournament_opponent_house = null		
	missionVariables.feudal_tournament_opponent_title = null
	missionVariables.feudal_tournament_opponent_firstname = null
	missionVariables.feudal_tournament_opponent_lastname = null
	missionVariables.feudal_tournament_opponent_of = null
	missionVariables.feudal_tournament_opponent_rank_no = null
	missionVariables.feudal_tournament_opponent_rank = null
	missionVariables.feudal_tournament_opponent_text = null
	missionVariables.feudal_tournament_jumpcount = 0
	missionVariables.feudal_tournament_deadline = null
}
this.defineTournamentGender = function() // pick a gender and select basic titles
{	missionVariables.feudal_tournament_opponent_gender = expandDescription("[feudal_gender]")
		
		if(missionVariables.feudal_tournament_opponent_gender == "he")
		{	
			if(missionVariables.feudal_tournament_opponent_rank_no == 1)
                        missionVariables.feudal_tournament_opponent_title = "Sir"
                        
			if(missionVariables.feudal_tournament_opponent_rank_no == 2)
                        missionVariables.feudal_tournament_opponent_title = "Lord"
		}									       
		
		if(missionVariables.feudal_tournament_opponent_gender == "she")	
			missionVariables.feudal_tournament_opponent_title = "Lady"			
}
this.defineTournamentOpponentHouse = function()
{missionVariables.feudal_tournament_opponent_house = expandDescription("[feudal_house_"+[galaxyNumber]+"]")
if(missionVariables.feudal_tournament_opponent_house == missionVariables.feudal_tournament_home)
this.defineTournamentOpponentHouse
}
this.defineTournamentInputs = function()
{	
	player.rankGenerator_house = missionVariables.feudal_tournament_opponent_house
	player.rankGenerator_gender = missionVariables.feudal_tournament_opponent_gender		
}
this.defineTournamentOutputs = function()
{	
	missionVariables.feudal_tournament_opponent_firstname = player.rankGenerator_feudal_firstname
	missionVariables.feudal_tournament_opponent_lastname = player.rankGenerator_feudal_lastname
	missionVariables.feudal_tournament_opponent_of = player.rankGenerator_of
	//log(missionVariables.feudal_tournament_opponent_rank_no)
	
	if(missionVariables.feudal_tournament_opponent_rank_no == 1)
	missionVariables.feudal_tournament_opponent_text = missionVariables.feudal_tournament_opponent_title+" "+missionVariables.feudal_tournament_opponent_firstname+" "+missionVariables.feudal_tournament_opponent_lastname+" of the House of "+missionVariables.feudal_tournament_opponent_house
	
	if(missionVariables.feudal_tournament_opponent_rank_no == 2)
	{missionVariables.feudal_tournament_opponent_rank = [player.rankGenerator_feudal_middle_rank]
	missionVariables.feudal_tournament_opponent_text = missionVariables.feudal_tournament_opponent_firstname+" "+missionVariables.feudal_tournament_opponent_lastname+", "+missionVariables.feudal_tournament_opponent_rank+" "+missionVariables.feudal_tournament_opponent_of+" "+missionVariables.feudal_tournament_opponent_house+","}
	
	if(missionVariables.feudal_tournament_opponent_rank_no == 3)
	   {missionVariables.feudal_tournament_opponent_rank = [player.rankGenerator_feudal_high_rank]
	missionVariables.feudal_tournament_opponent_text = missionVariables.feudal_tournament_opponent_firstname+" "+missionVariables.feudal_tournament_opponent_lastname+", "+missionVariables.feudal_tournament_opponent_rank+" "+missionVariables.feudal_tournament_opponent_of+" "+missionVariables.feudal_tournament_opponent_house+","}
}
 |