void ProcessDialogEvent()
{
	ref NPChar;
	aref Link, NextDiag;

	DeleteAttribute(&Dialog,"Links");
	// RM -->
	int iNation;
	string sNation;
	// RM <--
	string stemp = ""; // KK

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

	ref PChar;
	PChar = GetMainCharacter();

	// PG -->
	if(GetMusicScheme() == "PGMUS") { // KK
		iNation = sti(NPChar.nation);
		sNation = iNation;
		if(musicName != "music_govreward")
		{
// KK -->
			if (ENABLE_FLAGS == 0) {
				if(GetRMRelation(PChar,iNation) >= REL_AMNESTY) SetMusicNoPause("music_govfriend");
				else SetMusicNoPause("music_govenemy");
			} else {
				if(GetActualRMRelation(iNation) >= REL_AMNESTY) SetMusicNoPause("music_govfriend");
				else SetMusicNoPause("music_govenemy");
			}
// <-- KK
		}
	}
	// PG <--

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

			if (npchar.quest.meeting == "0")
			{
				dialog.text = DLG_TEXT[0] + npchar.name + " " + npchar.lastname + DLG_TEXT[1] + GetMyAddressForm(NPChar, PChar, ADDR_CIVIL, false, false) + DLG_TEXT[2];		// changed from .spa to .por by KAM
				Link.l1 = DLG_TEXT[3] + pchar.name + " " + pchar.lastname + DLG_TEXT[4];
				Link.l1.go = "node_1";
				npchar.quest.meeting = "1";
			}
			else
			{
				dialog.text = DLG_TEXT[5];
				link.l1 = DLG_TEXT[6];
				link.l1.go = "quests";
				// RM -->
				iNation = sti(NPChar.nation);
// KK -->
				Link.l3 = DLG_TEXT[45] + XI_ConvertString(GetNationDescByType(iNation)) + DLG_TEXT[46];
				Link.l3.go =  "international relations";
				if (ENABLE_FLAGS == 0) {
					if(GetRMRelation(PChar, iNation) <= REL_WAR)
					{
						Link.l4 = DLG_TEXT[44];
						Link.l4.go = "amnesty";
					}
					else
					{
						if(GetRMRelation(PChar,iNation) < REL_NEUTRAL)
						{
							Link.l4 = DLG_TEXT[47];
							Link.l4.go = "LoM";
						}
						else
						{
							if(!CheckAttribute(NPChar,"currentMR.relationtype"))// MAXIMUS: Five nieces in one room - LOL
							{
							if(SetupMR(&PChar, &NPChar))
							{
								dialog.text = DLG_TEXT[48] + PChar.name + DLG_TEXT[49] + XI_ConvertString(NPChar.currentMR.relationtype) + " " + Characters[GetCharacterIndex(NPChar.currentMR)].name + DLG_TEXT[50];
								PChar.quest.RemoveMRs.win_condition.l1 = "ExitFromLocation";
								PChar.quest.RemoveMRs.win_condition.l1.location = PChar.location;
								PChar.quest.RemoveMRs.win_condition = "RemoveMRs";
							}
							}
							if(PromoteCanBe(PChar, iNation) && GetRMRelation(PChar, iNation) > RequiredNextRank(PChar, iNation))
							{
								if(GetMusicScheme() == "PGMUS") SetMusicNoPause("music_govreward"); // PG // KK
								Link.l4 = DLG_TEXT[51];
								Link.l4.go = "promote";
							}
							Link.l6 = PCharRepPhrase(DLG_TEXT[52] + XI_ConvertString(GetNationNameByType(iNation)) + DLG_TEXT[53], DLG_TEXT[54] + XI_ConvertString(GetNationNameByType(iNation)) + ".");
							Link.l6.go = "leave";
						}
					}
				} else {
					if(GetActualRMRelation(iNation) <= REL_WAR)
					{
						Link.l4 = DLG_TEXT[44];
						Link.l4.go = "amnesty";
					}
					else
					{
						if ((GetActualRMRelation(iNation) < REL_NEUTRAL) || (!HaveLetterOfMarque(iNation)))
						{
							Link.l4 = DLG_TEXT[47];
							Link.l4.go = "LoM";
						}
						else
						{
							if(!CheckAttribute(NPChar,"currentMR.relationtype"))// MAXIMUS: Five nieces in one room - LOL
							{
							if(SetupMR(&PChar, &NPChar))
							{
								dialog.text = DLG_TEXT[48] + PChar.name + DLG_TEXT[49] + XI_ConvertString(NPChar.currentMR.relationtype) + " " + Characters[GetCharacterIndex(NPChar.currentMR)].name + DLG_TEXT[50];
								PChar.quest.RemoveMRs.win_condition.l1 = "ExitFromLocation";
								PChar.quest.RemoveMRs.win_condition.l1.location = PChar.location;
								PChar.quest.RemoveMRs.win_condition = "RemoveMRs";
							}
							}
							if(PromoteCanBe(PChar, iNation) && GetActualRMRelation(iNation) > RequiredNextRank(PChar, iNation))
							{
								if(GetMusicScheme() == "PGMUS") SetMusicNoPause("music_govreward"); // PG
								Link.l4 = DLG_TEXT[51];
								Link.l4.go = "promote";
							}
							Link.l6 = PCharRepPhrase(DLG_TEXT[52] + XI_ConvertString(GetNationNameByType(iNation)) + DLG_TEXT[53], DLG_TEXT[54] + XI_ConvertString(GetNationNameByType(iNation)) + ".");
							Link.l6.go = "leave";
						}
					}
				}
// <-- KK
				link.l2 = DLG_TEXT[7];
				link.l2.go = "exit";
			}
			NextDiag.TempNode = "First time";
		break;

		case "LoM":
			iNation = sti(NPChar.nation);
			dialog.text = DLG_TEXT[55] + XI_ConvertString(GetNationRoyalByType(iNation)) + DLG_TEXT[56] + makeint(PChar.rank)*LOM_COST + DLG_TEXT[57];
			Link.l1 = DLG_TEXT[58];
			Link.l1.go = "exit";
			if(GetCharacterMoney(PChar) > makeint(PChar.rank)*LOM_COST)
			{
				Link.l2 = DLG_TEXT[59];
				Link.l2.go = "LoMc";
			}
		break;

		case "LoMc":
// KK -->
			stemp = "";
			iNation = sti(NPChar.nation);
			stemp = GetHostileNations(iNation);
			if (stemp != "")
				stemp = XI_ConvertString(GetNationNameByType(iNation)) + DLG_TEXT[60] + DLG_TEXT[61] + DLG_TEXT[62] + stemp + DLG_TEXT[64] + DLG_TEXT[65];
			else
				stemp = XI_ConvertString(GetNationNameByType(iNation)) + DLG_TEXT[60] + DLG_TEXT[61] + DLG_TEXT[63] + DLG_TEXT[65];
			AddMoneyToCharacter(&PChar, makeint(PChar.rank)*-LOM_COST);
			SetRMRelation(&PChar, iNation, REL_NEUTRAL);
			if (ENABLE_FLAGS == 1) {
				SetActualRMRelation(iNation, REL_NEUTRAL);
				ReceiveLetterOfMarque(iNation);
			}
			SetRank(PChar, iNation, GetOldRank(PChar, iNation));
			if(sti(PChar.reputation) >= REP_COMEBACKMIN && GetRank(PChar, iNation)) stemp += DLG_TEXT[66] + XI_ConvertString(GetNationRoyalByType(iNation)) + DLG_TEXT[67] + XI_ConvertString(GetRankName(PChar, iNation));
			dialog.Text = stemp;
			Link.l1 = DLG_TEXT[68];
			Link.l1.go = "exit";
// <-- KK
		break;

		case "amnesty":
			iNation = sti(NPChar.nation);
			sNation = iNation;
			dialog.text = DLG_TEXT[69] + XI_ConvertString(GetNationNameByType(iNation)) + ", " + GetMyAddressForm(NPChar, PChar, ADDR_TITLE, false, false) + DLG_TEXT[70] + XI_ConvertString(GetNationRoyalByType(iNation)) + DLG_TEXT[71];
			Link.l1 = DLG_TEXT[72];
			Link.l1.go = "exit";
			if(sti(pchar.reputation) >= 40)
			{
				pchar.nations.(sNation).Amnesty = RMAmnestyCost(PChar, iNation);
				dialog.text = DLG_TEXT[73] + XI_ConvertString(GetNationNameByType(iNation)) + DLG_TEXT[74] + XI_ConvertString(GetNationRoyalByType(iNation)) + DLG_TEXT[75] + ShowMoney(-sti(pchar.nations.(sNation).Amnesty)) + DLG_TEXT[57];
				if(makeint(pchar.money) >= 0-makeint(pchar.nations.(sNation).Amnesty))
				{
					Link.l2 = DLG_TEXT[76];
					Link.l2.go = "Amnestyc";
				}
			}
		break;

		case "Amnestyc":
			iNation = sti(NPChar.nation);
			sNation = iNation;
			dialog.text = DLG_TEXT[77] + PChar.name + " " + PChar.lastname + ".";
			PlayStereoSound("INTERFACE\took_item.wav");
			AddMoneyToCharacter(pchar, sti(pchar.nations.(sNation).Amnesty));
			DeleteAttribute(pchar,("nations."+sNation+".Amnesty"));
			RMAmnesty(&Pchar, iNation);
			Link.l1 = DLG_TEXT[78];
			Link.l1.go = "exit";
		break;

		case "promote":
			iNation = sti(NPChar.nation);
			NPChar.templand = GetCharacterLand(PChar);
			Promote(&PChar, &NPChar, iNation);
			dialog.text = DLG_TEXT[79] + XI_ConvertString(GetRankName(PChar, iNation)) + DLG_TEXT[80] + (GetCharacterLand(PChar) - sti(NPChar.templand)) + DLG_TEXT[81] + XI_ConvertString(GetNationRoyalByType(iNation)) + ".";
			DeleteAttribute(NPChar,"templand");
			Link.l1 = DLG_TEXT[82];
			Link.l1.go = "exit";
		break;

		case "leave":
			iNation = sti(NPChar.nation);
			dialog.text = DLG_TEXT[83] + PChar.name + "? " + XI_ConvertString(GetNationRoyalByType(iNation)) + DLG_TEXT[84];
			Link.l1 = DLG_TEXT[85];
			Link.l1.go = "leavec";
			if(sti(PChar.reputation) < REP_LEAVEMIN + 5)
			{
				dialog.text = XI_ConvertString(GetNationRoyalByType(iNation)) + DLG_TEXT[86] + PChar.name + ".");
				Link.l1 = DLG_TEXT[91];
			}
			Link.l2 = DLG_TEXT[87];
			Link.l2.go = "exit";
		break;

		case "leavec":
			ChangeCharacterReputation(&PChar, -5);
			iNation = sti(NPChar.nation);
			if (ENABLE_FLAGS == 1) LooseLetterOfMarque(iNation); // KK
			dialog.text = DLG_TEXT[88];
			Link.l1 = DLG_TEXT[72];
			Link.l1.go = "exit";
			if(LeaveService(&PChar, iNation, false))
			{
				dialog.text = DLG_TEXT[89] + XI_ConvertString(DEFAULT_TITLE) + " " + PChar.lastname ".";
				Link.l1 = DLG_TEXT[90];
				Link.l1.go = "leavebad";
			}
		break;
		
		case "leavebad":
			iNation = sti(NPChar.nation);
			NextDiag.CurrentNode = NextDiag.TempNode;
			DialogExit();
			ref sld;
			string loc;
			float dist;
			GetNearLocator( "goto", &dist, &loc, 0);
			sld = LAi_CreateFantomCharacter(false, 0, true, true, true, LAi_SoldierModel(iNation), "goto", loc);
			LAi_group_MoveCharacter(sld, GetSoldiersName(iNation)+"_SOLDIERS");
			
			sld = LAi_CreateFantomCharacter(false, 0, true, true, true, LAi_SoldierModel(iNation), "goto", loc);
			LAi_group_MoveCharacter(sld, GetSoldiersName(iNation)+"_SOLDIERS");
		
			LAi_group_SetRelation(GetSoldiersName(iNation)+"_SOLDIERS", LAI_GROUP_PLAYER, LAI_GROUP_ENEMY);
			LAi_group_FightGroups(GetSoldiersName(iNation)+"_SOLDIERS", LAI_GROUP_PLAYER, true);
		// RM <--
		break;

		case "node_1":
			dialog.text = DLG_TEXT[8];
			link.l1 = DLG_TEXT[9];
			link.l1.go = "quests";
			link.l2 = DLG_TEXT[10] + GetMyAddressForm(PChar, NPChar, ADDR_TITLE, false, false) + ".";
			link.l2.go = "node_2";
		break;

		case "node_2":
			dialog.text = DLG_TEXT[11];
			link.l1 = DLG_TEXT[12];
			link.l1.go = "exit";
		break;

		case "quests":
// boal -->
			iNation = sti(NPChar.nation); // KK
			if (!CheckAttribute(pchar, "quest.generate_kill_quest") && GetNationRelation2MainCharacter(iNation) != RELATION_ENEMY)
			{
				dialog.text = DLG_TEXT[32];
				link.l1 = DLG_TEXT[33];
				link.l1.go = "kill_pirate";
			}			
			if (CheckQuestAttribute("generate_kill_quest", "completed"))
			{
				dialog.text = DLG_TEXT[34];
				link.l1 = DLG_TEXT[35];
				link.l1.go = "kill_pirate_completed";
			}	
			link.l99 = DLG_TEXT[16];
			link.l99.go = "exit";
		break;

		case "kill_pirate":
			GeneratePirateQuest(NPChar); // KK
			int quest_pirate_idx = GetCharacterIndex("Quest pirate"); // KK
			iNation = sti(characters[quest_pirate_idx].nation); // KK
			dialog.text = DLG_TEXT[36] + XI_ConvertString("sw_"+GetNationDescByType(iNation)) + DLG_TEXT[37] + characters[quest_pirate_idx].ship.name + DLG_TEXT[39] + XI_ConvertString(pchar.quest.hunting.destination) + DLG_TEXT[40] + pchar.quest.hunting.money + DLG_TEXT[41]; // KK
			link.l1 = DLG_TEXT[42];
			link.l1.go = "kill_pirate_agree";
			link.l2 = DLG_TEXT[43];
			link.l2.go = "kill_pirate_refused";
		break;

		case "kill_pirate_agree":
			DialogExit();
			NextDiag.CurrentNode = NextDiag.TempNode;
			AddDialogExitQuest("kill_pirate_agree");
		break;

		case "kill_pirate_refused":
			DialogExit();
			NextDiag.CurrentNode = NextDiag.TempNode;
			AddDialogExitQuest("kill_pirate_refused");
		break;

		case "kill_pirate_completed":
			if(AUTO_SKILL_SYSTEM)
			{
				AddPartyExpChar(pchar, "Leadership", 1500);
				AddPartyExpChar(pchar, "Sneak", 15);
			}
			else { AddPartyExp(pchar, 1500); }
		    PlayStereoSound("INTERFACE\took_item.wav");
			AddMoneyToCharacter(pchar, makeint(pchar.quest.hunting.money));
			AddDialogExitQuest("kill_pirate_refused_2");
			ChangeCharacterReputation(pchar, 1);
			DialogExit();
			NextDiag.CurrentNode = NextDiag.TempNode;
			pchar.quest.generate_kill_quest = "wait_timer";
		break;
// boal <--

		case "garri":
			dialog.text = DLG_TEXT[17];
			link.l1 = DLG_TEXT[18];
			link.l1.go = "garri_2";
		break;

		case "garri_2":
			dialog.text = DLG_TEXT[19];
			link.l1 = DLG_TEXT[20];
			if (CheckQuestAttribute("nigel_con_parri_checker", "win_win"))
			{
				link.l1.go = "garri_3";
			}
			else
			{
				link.l1.go = "exit";
			}
			AddQuestrecord("nigel", 15);
			DeleteAttribute(PChar, "quest.nigel_con_parri_checker");
			PChar.quest.con_parri_expired.over = "yes";
			PlayStereoSound("INTERFACE\took_item.wav");
			AddMoneyToCharacter(pchar, 3000);
			ChangeCharacterReputation(pchar, 1);
			AddDialogExitQuest("nigel_third_encounter");
		break;

		case "garri_3":
			dialog.text = DLG_TEXT[21];
			link.l1 = DLG_TEXT[22];
			link.l1.go = "garri_4";
		break;

		case "garri_4":
			dialog.text = DLG_TEXT[23];
			link.l1 = DLG_TEXT[24];
			link.l1.go = "exit";
			PlayStereoSound("INTERFACE\took_item.wav");
			AddMoneyToCharacter(pchar, 6000);
			ChangeCharacterReputation(pchar, 1);
		break;

		case "Exit":
			DialogExit();
			NextDiag.CurrentNode = NextDiag.TempNode;
		break;

		case "j_day":
			dialog.text = Pchar.name + " " + Pchar.lastname + DLG_TEXT[25]; 
			link.l1 = DLG_TEXT[26];
			link.l1.go = "continue1";
		break;

		case "continue1":
			LAi_QuestDelay("ex_dialog", 2);
			DialogExit();
			NextDiag.CurrentNode = "j_day2";
		break;

		case "j_day2":
			dialog.text = Pchar.name + " " + Pchar.lastname + DLG_TEXT[27]; 
			link.l1 = DLG_TEXT[28];
			link.l1.go = "exit";
		break;

// KK -->
		case "international relations":
			stemp = "";
			iNation = sti(NPChar.nation);
			stemp = GetHostileNations(iNation);
			if (stemp != "")
				stemp = DLG_TEXT[61] + DLG_TEXT[62] + stemp + DLG_TEXT[64] + DLG_TEXT[65];
			else
				stemp = DLG_TEXT[61] + DLG_TEXT[63] + DLG_TEXT[65];
			dialog.Text = stemp;
			Link.l1 = DLG_TEXT[72];
			Link.l1.go = "exit";
		break;
// <-- KK
	}
}
