int shiptarget;
int cplates=0;
int bcannons=0;
int gchasers=0;
int nsails=0;
int ltopmasts=0;
int stays=0;
int rhull=0;
int flushed=0;
int acplates=0;
int abcannons=0;
int agchasers=0;
int ansails=0;
int altopmasts=0;
int astays=0;
int arhull=0;
int aflushed=0;
int cost=50;
int time=50;	

void ProcessDialogEvent()
{
	int tmpLangFileID = LanguageOpenFile("interface_strings.txt");
	ref NPChar, PChar, d;
	PChar = GetMainCharacter();
	aref Link, Diag;
	string NPC_Meeting;
	
	DeleteAttribute(&Dialog,"Links");

	makeref(NPChar,CharacterRef);
	makearef(Link, Dialog.Links);
	makeref(d, Dialog);
	makearef(Diag, NPChar.Dialog);

	string iDay, iMonth;
	iDay = environment.date.day;
	iMonth = environment.date.month;
	string lastspeak_date = iday + " " + iMonth;


	int n;
	int i;
	int j;
		
	aref temparef;
	string tempstr;
	ref companion;
	

//KB	Trace("KB - Nodes " + Dialog.CurrentNode + " ; " + Dialog.TempNode);	
	
	switch(Dialog.CurrentNode)
	{
	// -----------------------------------Диалог первый - первая встреча
		case "First time":
			Dialog.defAni = "Gov_Dialog_1";
			Dialog.ani = "Gov_Dialog_2";
			Dialog.defCam = "1";
			Dialog.defSnd = "dialogs\0\017";
			Dialog.defLinkAni = "dialog_1";
			Dialog.defLinkCam = "1";
			Dialog.defLinkSnd = "dialogs\woman\024";
			Dialog.cam = "1";
			Dialog.snd = "dialogs\0\009";

			if(TradeCheck(PChar, NPChar, true)) { // NK
			if(NPChar.quest.meeting == "0")
			{
				d.Text = TimeGreeting() + DLG_TEXT[0] + GetMyFullName(NPChar) + DLG_TEXT[1];
				Link.l1 = DLG_TEXT[2] + GetMyFullName(PChar) + DLG_TEXT[3] + PChar.Ship.name + DLG_TEXT[4];
				Link.l1.go = "meeting";
				NPChar.quest.meeting = "1"; 
			}
			else
			{
				d.Text = TimeGreeting() + DLG_TEXT[5] + GetMyName(Pchar) + DLG_TEXT[6] + GetMyAddressForm(NPChar, PChar, ADDR_CIVIL, false, false) + DLG_TEXT[7];
				Link.l1 = DLG_TEXT[8];
				Link.l1.go = "Shipyard";
				Link.l2 = DLG_TEXT[9];
				Link.l2.go = "quest lines";
				Link.l3 = DLG_TEXT[10];
				Link.l3.go = "exit";
			}
			// NK -->
			}
			else
			{
				dialog.text = DLG_TEXT[45] + GetMyAddressForm(NPChar, PChar, ADDR_CIVIL, false, false) + DLG_TEXT[46];
				Link.l1 = DLG_TEXT[47];
				Link.l1.go = "exit";
				if(sti(PChar.Skill.Commerce)>=5)
				{
					Link.l2 = LanguageConvertString(tmpLangFileID,"high_trade_1");
					Link.l2.go = "high_price";
				}
				Diag.TempNode = "First time";
			}
			// NK <--
		break;

		case "high_price":
			dialog.text = LanguageConvertString(tmpLangFileID,"high_trade_2");
			link.l1 = LanguageConvertString(tmpLangFileID,"high_trade_3");
			link.l1.go = "shipyard_high";
			link.l2 = LanguageConvertString(tmpLangFileID,"high_trade_4");
			link.l2.go = "exit";
			Diag.TempNode = "First time";
		break;

		case "shipyard_high":
			dialog.Text = LanguageConvertString(tmpLangFileID,"high_trade_5");
			Link.l1 = LanguageConvertString(tmpLangFileID,"high_trade_6");
			Link.l1.go = "SHIPYARD_interface_high";
			Link.l2 = LanguageConvertString(tmpLangFileID,"high_trade_7");
			Link.l2.go = "Cannons_interface_high";
			Link.l3 = LanguageConvertString(tmpLangFileID,"high_trade_4");
			Link.l3.go = "Exit";
			Diag.TempNode = "First time";
		break;

		case "SHIPYARD_interface_high":
			Diag.TempNode = "First time";
			if(npchar.quest.Meeting != lastspeak_date)
			{
				FillShipsList(&NPChar); // NK

				npchar.quest.Meeting = lastspeak_date;
			}			
			DialogExit();
			tradeHigh = true;
			setCharacterShipLocation(pchar,"Douwesen_port");	//ccc survival
			LaunchShipyard(npchar);
		break;

		case "Cannons_interface_high":
			Diag.TempNode = "First time";
			DialogExit();
			tradeHigh = true;
			setCharacterShipLocation(pchar,"Douwesen_port");	//ccc survival
			LaunchCannons();
		break;

		case "Meeting":
				d.Text = DLG_TEXT[11];
				Link.l1 = DLG_TEXT[12] + GetMyName(NPChar) +DLG_TEXT[13];
				Link.l1.go = "Shipyard";			
				Link.l2 = DLG_TEXT[14];
				Link.l2.go = "quest lines";
				Link.l3 = DLG_TEXT[15];
				Link.l3.go = "exit";
		break;

		case "quest lines":
				d.Text = DLG_TEXT[16]+ GetMyName(PChar) + DLG_TEXT[17];
				Link.l1 = DLG_TEXT[18];
				Link.l1.go = "no quest";
		break;

		case "No quest":
				d.Text = DLG_TEXT[19] + GetMyName(Pchar) + DLG_TEXT[20];
				Link.l1 = DLG_TEXT[21];
				Link.l1.go = "Shipyard";
				Link.l2 = DLG_TEXT[22];
				Link.l2.go = "exit";
		break;

		case "shipyard":
				d.Text = DLG_TEXT[48] + DLG_TEXT[23];	// ccc 15oct04 shipyard waiting : changed by MAXIMUS
				Link.l1 = DLG_TEXT[24];
				Link.l1.go = "SHIPYARD_interface";
				Link.l2 = DLG_TEXT[25];
				Link.l2.go = "Cannons_interface";
				Link.l4 = DLG_TEXT[52];
				Link.l4.go = "Tuning_selectship";
				Link.l5 = DLG_TEXT[62];
				Link.l5.go = "Tuningout_selectship";
				Link.l9 = DLG_TEXT[49];	// ccc
				Link.l9.go = "exit";	// ccc
		break;

		case "Viper_Sails_Interface":
			PChar.viper_changesails = true;
			//PostEvent("key_event",500,13,0);
			//NextDiag.CurrentNode = NextDiag.TempNode;
			//DialogExit();
			//Log_SetStringToLog("Select base sails");
			//BLI_EnableShow();
			dialog.Text = DLG_TEXT[50];
			Link.l1 = DLG_TEXT[51];
			Link.l1.go = "Exit";
		break;

  // Viper - Emblemed Sails v2 End

		case "SHIPYARD_interface":
			Diag.CurrentNode = Diag.TempNode;
			
			if (npchar.quest.Meeting != lastspeak_date)
			{
				FillShipsList(&NPChar); // NK

				npchar.quest.Meeting = lastspeak_date;
			}

			DialogExit();
			setCharacterShipLocation(pchar,"Douwesen_port");	//ccc survival
			LaunchShipyard(npchar);
		break;

		case "CANNONS_interface":
			Diag.CurrentNode = Diag.TempNode;
			DialogExit();
			setCharacterShipLocation(pchar,"Douwesen_port");	//ccc survival
			LaunchCannons();
		break;

		case "continue":
			if (NPC_Meeting == "1")
			{
				d.Text = DLG_TEXT[27] + GetMyName(Pchar) + DLG_TEXT[28];
				Link.l1 = DLG_TEXT[29];
				Link.l1.go = "continue1";
			}
			else
			{
				d.Text = DLG_TEXT[30];
				Link.l1 = DLG_TEXT[31];
				Link.l1.go = "continue1";
			}
		break;

		case "continue1":
			NPC_Meeting = "1"; 
			d.Text = DLG_TEXT[32];
			Link.l1 = DLG_TEXT[33];
			Link.l1.go = "continue3";
			Link.l2 = DLG_TEXT[34];
			Link.l2.go = "exit1";
			
			if(makeint(PChar.skill.leadership) > 200)
			{
				d.Text = DLG_TEXT[35];
				Link.l1 = DLG_TEXT[36];
				Link.l1.go = "exit2";
			}
		break;

		case "continue2":
			d.Text = PCharPhrase(DLG_TEXT[37], DLG_TEXT[38] + GetMyAddressForm(NPChar, PChar, ADDR_CIVIL, false, false) + DLG_TEXT[39]);
			Link.l1 = DLG_TEXT[40] + GetMyName(NPChar) +DLG_TEXT[41];
			if(CheckAttribute(Pchar, "Quest.Story_OxbayCaptured"))
			{
				Link.l1.go = "No ships";
			}
			else
			{
				Link.l1.go = "Shipyard";
			}			
			Link.l2 = DLG_TEXT[42];
			Link.l2.go = "quest lines";
			Link.l3 = DLG_TEXT[43];
			Link.l3.go = "continue3";
			Link.l4 = DLG_TEXT[44];
			Link.l4.go = "exit";
		break;

		case "continue3":
			AddDialogExitQuest("change_clauss_adress");
			Diag.CurrentNode = "First time";
			NPChar.quest.meeting = NPC_Meeting;
			DialogExit();
		break;

		case "exit":
			Diag.CurrentNode = Diag.TempNode;
			NPChar.quest.meeting = NPC_Meeting;
			DialogExit();
		break;

		case "exit2":
			Pchar.quest.pirate_fort.win_condition.l1 = "location";
			Pchar.quest.pirate_fort.win_condition.l1.character = "Blaze";
			Pchar.quest.pirate_fort.win_condition.l1.location = "Pirate_fort";
			Pchar.quest.pirate_fort.win_condition = "Pirates_vs_Blaze";
			Diag.CurrentNode = Diag.TempNode;
			NPChar.quest.meeting = NPC_Meeting;
			DialogExit();
		break;

		case "exit1":
			Diag.CurrentNode = "continue2";
			NPChar.quest.meeting = NPC_Meeting;
			DialogExit();
		break;		

		case "Tuning_selectship":
			shiptarget = -1;
			d.Text = DLG_TEXT[64];
			Link.l1 = PChar.ship.name;
			Link.l1.go = "shipl0";
			j=2;
			for (i = 1; i <= 4; i++) {
				if (GetCompanionIndex(PChar,i) > 0) {
					companion = GetCharacter(GetCompanionIndex(PChar,i));
					tempstr= "l"+j;
					Link.(tempstr) = companion.ship.name;
					Link.(tempstr).go = "shipl" + i;
					j++;
//KB					Trace("KB - for : " + i + ";"+j+";"+companion.ship.name);
				}
			}
			tempstr= "l"+j;
			Link.(tempstr) = DLG_TEXT[63];
			Link.(tempstr).go = "shipyard";
		break;
		case "shipl0":
			shiptarget = 0;
			d.Text = "Let's see what can we do...";
			Link.l1 = "...";
			Link.l1.go = "Tuning_l1";
		break;
		case "shipl1":
			shiptarget = GetCompanionIndex(PChar,1);
			d.Text = "Let's see what can we do...";
			Link.l1 = "...";
			Link.l1.go = "Tuning_l1";
		break;
		case "shipl2":
			shiptarget = GetCompanionIndex(PChar,2);
			d.Text = "Let's see what can we do...";
			Link.l1 = "...";
			Link.l1.go = "Tuning_l1";
		break;
		case "shipl3":
			shiptarget = GetCompanionIndex(PChar,3);
			d.Text = "Let's see what can we do...";
			Link.l1 = "...";
			Link.l1.go = "Tuning_l1";
		break;
		case "Tuning_l1":
			
			makearef(temparef,NPChar.quest);
			if (CheckAttribute(temparef,"trade_date")) { tempstr= NPChar.quest.trade_date; }
			else { tempstr = ""; }

			Trace ("Kblack - Dialog - Availability " + cplates + "-" + bcannons + "-" + gchasers + "-" + nsails + "-" + ltopmasts + "-" + stays + "-" + rhull);
	
			if (tempstr != lastspeak_date)
			{
				//reroll availability
				if (rand(99) <= sti(CPDISP) ) { acplates = 1;}
				if (rand(99) <= sti(BCDISP) ) { abcannons = 1;}
				if (rand(99) <= sti(GCDISP) ) { agchasers = 1;}
				if (rand(99) <= sti(NSDISP) ) { ansails = 1;}
				if (rand(99) <= sti(TMDISP) ) { altopmasts = 1;}
				if (rand(99) <= sti(SSDISP) ) { astays = 1;}
				if (rand(99) <= sti(RHDISP) ) { arhull = 1;}
				//Trace ("Kblack - Dialog REROLL  Availability " + NPChar.quest.trade_date + ";" + lastspeak_date + ";" + acplates + "-" + abcannons + "-" + agchasers + "-" + ansails + "-" + altopmasts + "-" + astays + "-" + arhull);
				NPChar.quest.trade_date = lastspeak_date;
			}	
//			acplates = 1; //TEST
//			abcannons =1; //TEST
//			ansails =1; //TEST
//			altopmasts = 1; //TEST
//			astays=1; //TEST
//			arhull = 1; //TEST
//			agchasers = 1; //TEST
			if (shiptarget == 1) { makearef(temparef,PChar.ship);}
			else {
				companion=GetCharacter(shiptarget);
				makearef(temparef,companion.ship);
			}
			if (CheckAttribute(temparef,"tune")) {
			Trace("KB- Checked tune");
				if (shiptarget == 1) { makearef(temparef,PChar.ship.tune);}
				else {
					companion=GetCharacter(shiptarget);
					makearef(temparef,companion.ship.tune);
					}
				if(CheckAttribute(temparef,"cplates") && sti(temparef.cplates.on) == 1) { cplates = 0; }
				else {cplates = acplates; }
				if(CheckAttribute(temparef,"bcannons") && sti(temparef.bcannons.on) == 1) { bcannons = 0; }
				else {bcannons = abcannons; }
				if(CheckAttribute(temparef,"nsails") && sti(temparef.nsails.on) == 1) { nsails = 0; }
				else {nsails = ansails; }
				if(CheckAttribute(temparef,"ltopmasts") && sti(temparef.ltopmasts.on) == 1) { ltopmasts = 0; }
				else {ltopmasts = altopmasts; }
				if(CheckAttribute(temparef,"stays") && sti(temparef.stays.on) == 1) { stays = 0; }
				else {stays = astays; }
				if(CheckAttribute(temparef,"rhull") && sti(temparef.rhull.on) == 1) { rhull = 0; }
				else {rhull = arhull; }
				if(CheckAttribute(temparef,"gchasers") && sti(temparef.gchasers.on) == 1) { gchasers = 0; }
				else {gchasers = agchasers; }
				if(CheckAttribute(temparef,"flushed") && sti(temparef.flushed.on) == 1) { flushed = 0; }
				else {flushed = 1; }
			}
			else {
				cplates=acplates;
				bcannons=abcannons;
				nsails=ansails;
				ltopmasts=altopmasts;
				stays=astays;
				rhull=arhull;
				gchasers=agchasers;
				flushed=1;
			}
			d.Text = DLG_TEXT[68];
			if (cplates) { 
				cost=GetCostTun(shiptarget,"cplates");
				time=GetTimeTun(shiptarget,"cplates");
				Link.l1 = DLG_TEXT[54] + DLG_TEXT[65] + cost + DLG_TEXT[66] + time + DLG_TEXT[67];
				Link.l1.go = "cplates";
				}
			if (bcannons) { 
				cost=GetCostTun(shiptarget,"bcannons");
				time=GetTimeTun(shiptarget,"bcannons");
				Link.l2 = DLG_TEXT[55] + DLG_TEXT[65] + cost + DLG_TEXT[66] + time + DLG_TEXT[67];
				Link.l2.go = "bcannons";
				}
			if (gchasers) { 
				cost=GetCostTun(shiptarget,"gchasers");
				time=GetTimeTun(shiptarget,"gchasers");
				Link.l3 = DLG_TEXT[56] + DLG_TEXT[65] + cost + DLG_TEXT[66] + time + DLG_TEXT[67];
				Link.l3.go = "gchasers";
				}
			if (nsails) { 
				cost=GetCostTun(shiptarget,"nsails");
				time=GetTimeTun(shiptarget,"nsails");
				Link.l4 = DLG_TEXT[57] + DLG_TEXT[65] + cost + DLG_TEXT[66] + time + DLG_TEXT[67];
				Link.l4.go = "nsails";
				}
			if (ltopmasts) { 
				cost=GetCostTun(shiptarget,"ltopmasts");
				time=GetTimeTun(shiptarget,"ltopmasts");
				Link.l5 = DLG_TEXT[58] + DLG_TEXT[65] + cost + DLG_TEXT[66] + time + DLG_TEXT[67];
				Link.l5.go = "ltopmasts";
				}
			if (stays) { 
				cost=GetCostTun(shiptarget,"stays");
				time=GetTimeTun(shiptarget,"stays");
				Link.l6 = DLG_TEXT[59] + DLG_TEXT[65] + cost + DLG_TEXT[66] + time + DLG_TEXT[67];
				Link.l6.go = "stays";
				}
			if (rhull) { 
				cost=GetCostTun(shiptarget,"rhull");
				time=GetTimeTun(shiptarget,"rhull");
				Link.l7 = DLG_TEXT[60] + DLG_TEXT[65] + cost + DLG_TEXT[66] + time + DLG_TEXT[67];
				Link.l7.go = "rhull";
				}
			if ( PChar.location == "QC_Shipyard" || PChar.location == "Douwesen_Shipyard" && flushed ) { 
				cost=GetCostTun(shiptarget,"flushed");
				time=GetTimeTun(shiptarget,"flushed");
				Link.l8 = DLG_TEXT[61] + DLG_TEXT[65] + cost + DLG_TEXT[66] + time + DLG_TEXT[67];
				Link.l8.go = "flushed";
				}
			Link.l9 = DLG_TEXT[63];
			Link.l9.go = "shipyard";
		break;	
		case "cplates":
			j=0;
			j = sti(PChar.Money);
			if ( cost > j ) {
				d.Text = DLG_TEXT[53];
				Link.l1 = DLG_TEXT[69];
				Link.l1.go = "shipyard";
			}
			else {
			Trace("KB - calling ApplyTun :"+shiptarget+";"+time+";"+cost);
				ApplyTun(shiptarget,"cplates",cost,time);
				shiptarget = -1;
				Diag.CurrentNode = Diag.TempNode;
				NPChar.quest.meeting = 1;
				NPChar.quest.trade_date = lastspeak_date;
				DialogExit();
			}
		break;

		case "bcannons":
			j=0;
			j = sti(PChar.Money);
			if ( cost > j ) {
				d.Text = DLG_TEXT[53];
				Link.l1 = DLG_TEXT[69];
				Link.l1.go = "shipyard";
			}
			else {
			Trace("KB - calling ApplyTun :"+shiptarget+";"+time+";"+cost);
				ApplyTun(shiptarget,"bcannons",cost,time);
				shiptarget = -1;
				Diag.CurrentNode = Diag.TempNode;
				NPChar.quest.meeting = 1;
				NPChar.quest.trade_date = lastspeak_date;
				DialogExit();
			}
		break;

		case "gchasers":
			j=0;
			j = sti(PChar.Money);
			if ( cost > j ) {
				d.Text = DLG_TEXT[53];
				Link.l1 = DLG_TEXT[69];
				Link.l1.go = "shipyard";
			}
			else {
			Trace("KB - calling ApplyTun :"+shiptarget+";"+time+";"+cost);
				ApplyTun(shiptarget,"gchasers",cost,time);
				shiptarget = -1;
				Diag.CurrentNode = Diag.TempNode;
				NPChar.quest.meeting = 1;
				NPChar.quest.trade_date = lastspeak_date;
				DialogExit();
			}
		break;

		case "nsails":
			j=0;
			j = sti(PChar.Money);
			if ( cost > j ) {
				d.Text = DLG_TEXT[53];
				Link.l1 = DLG_TEXT[69];
				Link.l1.go = "shipyard";
			}
			else {
			Trace("KB - calling ApplyTun :"+shiptarget+";"+time+";"+cost);
				ApplyTun(shiptarget,"nsails",cost,time);
				shiptarget = -1;
				Diag.CurrentNode = Diag.TempNode;
				NPChar.quest.meeting = 1;
				NPChar.quest.trade_date = lastspeak_date;
				DialogExit();
			}
		break;

		case "ltopmasts":
			j=0;
			j = sti(PChar.Money);
			if ( cost > j ) {
				d.Text = DLG_TEXT[53];
				Link.l1 = DLG_TEXT[69];
				Link.l1.go = "shipyard";
			}
			else {
			Trace("KB - calling ApplyTun :"+shiptarget+";"+time+";"+cost);
				ApplyTun(shiptarget,"ltopmasts",cost,time);
				shiptarget = -1;
				Diag.CurrentNode = Diag.TempNode;
				NPChar.quest.meeting = 1;
				NPChar.quest.trade_date = lastspeak_date;
				DialogExit();
			}
		break;

		case "stays":
			j=0;
			j = sti(PChar.Money);
			if ( cost > j ) {
				d.Text = DLG_TEXT[53];
				Link.l1 = DLG_TEXT[69];
				Link.l1.go = "shipyard";
			}
			else {
			Trace("KB - calling ApplyTun :"+shiptarget+";"+time+";"+cost);
				ApplyTun(shiptarget,"stays",cost,time);
				shiptarget = -1;
				Diag.CurrentNode = Diag.TempNode;
				NPChar.quest.meeting = 1;
				NPChar.quest.trade_date = lastspeak_date;
				DialogExit();
			}
		break;

		case "rhull":
			j=0;
			j = sti(PChar.Money);
			if ( cost > j ) {
				d.Text = DLG_TEXT[53];
				Link.l1 = DLG_TEXT[69];
				Link.l1.go = "shipyard";
			}
			else {
			Trace("KB - calling ApplyTun :"+shiptarget+";"+time+";"+cost);
				ApplyTun(shiptarget,"rhull",cost,time);
				shiptarget = -1;
				Diag.CurrentNode = Diag.TempNode;
				NPChar.quest.meeting = 1;
				NPChar.quest.trade_date = lastspeak_date;
				DialogExit();
			}
		break;

		case "flushed":
			j=0;
			j = sti(PChar.Money);
			if ( cost > j ) {
				d.Text = DLG_TEXT[53];
				Link.l1 = DLG_TEXT[69];
				Link.l1.go = "shipyard";
			}
			else {
			Trace("KB - calling ApplyTun :"+shiptarget+";"+time+";"+cost);
				ApplyTun(shiptarget,"flushed",cost,time);
				shiptarget = -1;
				Diag.CurrentNode = Diag.TempNode;
				NPChar.quest.meeting = 1;
				NPChar.quest.trade_date = lastspeak_date;
				DialogExit();
			}
		break;
					
		case "Tuningout_selectship":
			shiptarget = -1;
			d.Text = DLG_TEXT[64];
			Link.l1 = PChar.ship.name;
			Link.l1.go = "u-shipl0";
			j=2;
			for (i = 1; i <= 4; i++) {
				if (GetCompanionIndex(PChar,i) > 0) {
					companion = GetCharacter(GetCompanionIndex(PChar,i));
					tempstr= "l"+j;
					Link.(tempstr) = companion.ship.name;
					Link.(tempstr).go = "u-shipl" + i;
					j++;
//KB					Trace("KB - for : " + i + ";"+j+";"+companion.ship.name);
				}
			}
			tempstr= "l"+j;
			Link.(tempstr) = DLG_TEXT[63];
			Link.(tempstr).go = "shipyard";
		break;
		
		case "u-shipl0":
			shiptarget = 0;
			d.Text = "Let's see what can we do...";
			Link.l1 = "...";
			Link.l1.go = "U-Tuning_l1";
		break;
		case "u-shipl1":
			shiptarget = GetCompanionIndex(PChar,1);
			d.Text = "Let's see what can we do...";
			Link.l1 = "...";
			Link.l1.go = "U-Tuning_l1";
		break;
		case "u-shipl2":
			shiptarget = GetCompanionIndex(PChar,2);
			d.Text = "Let's see what can we do...";
			Link.l1 = "...";
			Link.l1.go = "U-Tuning_l1";
		break;
		case "u-shipl3":
			shiptarget = GetCompanionIndex(PChar,3);
			d.Text = "Let's see what can we do...";
			Link.l1 = "...";
			Link.l1.go = "U-Tuning_l1";
		break;
		case "U-Tuning_l1":
			if (shiptarget == 1) { makearef(temparef,PChar.ship);}
			else {
				companion=GetCharacter(shiptarget);
				makearef(temparef,companion.ship);
			}
			if (CheckAttribute(temparef,"tune")) {
			Trace("KB- Checked tune");
				if (shiptarget == 1) { makearef(temparef,PChar.ship.tune);}
				else {
					companion=GetCharacter(shiptarget);
					makearef(temparef,companion.ship.tune);
					}
				if(CheckAttribute(temparef,"cplates") && sti(temparef.cplates.on) == 1) { cplates = 1; }
				else {cplates = 0; }
				if(CheckAttribute(temparef,"bcannons") && sti(temparef.bcannons.on) == 1) { bcannons = 1; }
				else {bcannons = 0; }
				if(CheckAttribute(temparef,"nsails") && sti(temparef.nsails.on) == 1) { nsails = 1; }
				else {nsails = 0; }
				if(CheckAttribute(temparef,"ltopmasts") && sti(temparef.ltopmasts.on) == 1) { ltopmasts = 1; }
				else {ltopmasts = 0; }
				if(CheckAttribute(temparef,"stays") && sti(temparef.stays.on) == 1) { stays = 1; }
				else {stays = 0; }
				if(CheckAttribute(temparef,"gchasers") && sti(temparef.gchasers.on) == 1) { gchasers = 1; }
				else {gchasers = 0; }
			}
			else {
				cplates=0;
				bcannons=0;
				nsails=0;
				ltopmasts=0;
				stays=0;
				gchasers=0;
			}
			d.Text = DLG_TEXT[70];
			if (cplates) { 
				Link.l1 = DLG_TEXT[71];
				Link.l1.go = "ucplates";
				}
			if (bcannons) { 
				Link.l2 = DLG_TEXT[72];
				Link.l2.go = "ubcannons";
				}
			if (gchasers) { 
				Link.l3 = DLG_TEXT[73];
				Link.l3.go = "ugchasers";
				}
			if (nsails) { 
				Link.l4 = DLG_TEXT[74];
				Link.l4.go = "unsails";
				}
			if (ltopmasts) { 
				Link.l5 = DLG_TEXT[75];
				Link.l5.go = "ultopmasts";
				}
			if (stays) { 
				Link.l6 = DLG_TEXT[76];
				Link.l6.go = "ustays";
				}
			Link.l7 = DLG_TEXT[63];
			Link.l7.go = "shipyard";
		break;	
		case "ucplates":
			UnApplyTun(shiptarget,"cplates");
			shiptarget = -1;
			Diag.CurrentNode = Diag.TempNode;
			NPChar.quest.meeting = 1;
			NPChar.quest.trade_date = lastspeak_date;
			DialogExit();
		break;

		case "ubcannons":
			UnApplyTun(shiptarget,"bcannons");
			shiptarget = -1;
			Diag.CurrentNode = Diag.TempNode;
			NPChar.quest.meeting = 1;
			NPChar.quest.trade_date = lastspeak_date;
			DialogExit();
		break;

		case "ugchasers":
			UnApplyTun(shiptarget,"gchasers");
			shiptarget = -1;
			Diag.CurrentNode = Diag.TempNode;
			NPChar.quest.meeting = 1;
			NPChar.quest.trade_date = lastspeak_date;
			DialogExit();
		break;

		case "unsails":
			UnApplyTun(shiptarget,"nsails");
			shiptarget = -1;
			Diag.CurrentNode = Diag.TempNode;
			NPChar.quest.meeting = 1;
			NPChar.quest.trade_date = lastspeak_date;
			DialogExit();
		break;

		case "ultopmasts":
			UnApplyTun(shiptarget,"ltopmasts");
			shiptarget = -1;
			Diag.CurrentNode = Diag.TempNode;
			NPChar.quest.meeting = 1;
			NPChar.quest.trade_date = lastspeak_date;
			DialogExit();
		break;

		case "ustays":
			UnApplyTun(shiptarget,"stays");
			shiptarget = -1;
			Diag.CurrentNode = Diag.TempNode;
			NPChar.quest.meeting = 1;
			NPChar.quest.trade_date = lastspeak_date;
			DialogExit();
		break;
	}
	LanguageCloseFile(tmpLangFileID);
}
