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

	DeleteAttribute(&Dialog,"Links");
	// RM -->
	int iNation;
	string sNation;
	string iDay, iMonth;
	iDay = environment.date.day;
	iMonth = environment.date.month;
	string lastspeak_date = iDay + " " + iMonth;
	// RM <--
	string stemp = ""; // KK

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

	// 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 <--

	ref PChar = GetMainCharacter();

	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";

			if (npchar.quest.meeting == "0")
			{
				dialog.snd = "Voice\CHMA\CHMA001";
				dialog.text = DLG_TEXT[0] + GetMyFullName(NPChar) + DLG_TEXT[1] + GetMyAddressForm(NPChar, PChar, ADDR_CIVIL, false, false) + DLG_TEXT[2];
				Link.l1 = DLG_TEXT[3] + GetMyFullName(PChar) + DLG_TEXT[4];
				Link.l1.go = "node_1";
				npchar.quest.meeting = "1";
			}
			else
			{
				dialog.snd = "Voice\CHMA\CHMA002";
				dialog.text = DLG_TEXT[5];
				link.l1 = DLG_TEXT[6];
				link.l1.go = "quests";
				// RM -->
				iNation = sti(NPChar.nation);
// KK -->
				Preprocessor_Add("gov_nation", XI_ConvertString(GetNationDescByType(iNation)));
				Link.l3 = DLG_TEXT[64];
				Link.l3.go = "international relations";
				if (ENABLE_FLAGS == 0) {
					if(GetRMRelation(PChar, iNation) <= REL_WAR)
					{
						Link.l4 = DLG_TEXT[63];
						Link.l4.go = "amnesty";
					}
					else
					{
						if(GetRMRelation(PChar,iNation) < REL_NEUTRAL)
						{
							Link.l4 = DLG_TEXT[65];
							Link.l4.go = "LoM";
						}
						else
						{
							if(SetupMR(&PChar, &NPChar))
							{
								dialog.text = GenerateMR(PChar, NPChar);
							}
							if(PromoteCanBe(PChar, iNation) && GetRMRelation(PChar, iNation) > RequiredNextRank(PChar, iNation))
							{
								if(GetMusicScheme() == "PGMUS") SetMusicNoPause("music_govreward"); // PG // KK
								Link.l4 = DLG_TEXT[47];
								Link.l4.go = "promote";
							}
							Link.l5 = PCharRepPhrase(DLG_TEXT[69] + XI_ConvertString(GetNationNameByType(iNation)) + DLG_TEXT[70], DLG_TEXT[71] + XI_ConvertString(GetNationNameByType(iNation)) + ".");
							Link.l5.go = "leave";
						}
					}
				} else {
					if(GetActualRMRelation(iNation) <= REL_WAR)
					{
						Link.l4 = DLG_TEXT[63];
						Link.l4.go = "amnesty";
					}
					else
					{
						if ((GetActualRMRelation(iNation) < REL_NEUTRAL) || (!HaveLetterOfMarque(iNation)))
						{
							Link.l4 = DLG_TEXT[65];
							Link.l4.go = "LoM";
						}
						else
						{
							if(SetupMR(&PChar, &NPChar))
							{
								dialog.text = GenerateMR(PChar, NPChar);
							}
							if(PromoteCanBe(PChar, iNation) && GetActualRMRelation(iNation) > RequiredNextRank(PChar, iNation))
							{
								if(GetMusicScheme() == "PGMUS") SetMusicNoPause("music_govreward"); // PG
								Link.l4 = DLG_TEXT[47];
								Link.l4.go = "promote";
							}
							Link.l5 = PCharRepPhrase(DLG_TEXT[69] + XI_ConvertString(GetNationNameByType(iNation)) + DLG_TEXT[70], DLG_TEXT[71] + XI_ConvertString(GetNationNameByType(iNation)) + ".");
							Link.l5.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[72] + XI_ConvertString(GetNationRoyalByType(iNation)) + DLG_TEXT[73] + makeint(PChar.rank)*LOM_COST + DLG_TEXT[46] + ".";
			Link.l1 = DLG_TEXT[74];
			Link.l1.go = "exit";
			if(GetCharacterMoney(PChar) > makeint(PChar.rank)*LOM_COST)
			{
				Link.l2 = DLG_TEXT[75];
				Link.l2.go = "LoMc";
			}
		break;

		case "LoMc":
// KK -->
			stemp = "";
			iNation = sti(NPChar.nation);
			stemp = GetHostileNations(iNation);
			Preprocessor_Add("gov_nation", XI_ConvertString(GetNationNameByType(iNation))); 
			if (stemp != "")
				stemp = DLG_TEXT[17] + DLG_TEXT[18] + DLG_TEXT[20] + DLG_TEXT[21] + stemp + DLG_TEXT[23] + DLG_TEXT[25];
			else
				stemp = DLG_TEXT[17] + DLG_TEXT[18] + DLG_TEXT[19] + DLG_TEXT[20] + DLG_TEXT[22] + DLG_TEXT[24] + DLG_TEXT[25];
			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[75] + XI_ConvertString(GetNationRoyalByType(iNation)) + DLG_TEXT[76] + XI_ConvertString(GetRankName(PChar, iNation));
			dialog.Text = stemp;
			Link.l1 = DLG_TEXT[26];
			Link.l1.go = "exit";
// <-- KK
		break;

		case "amnesty":
			iNation = sti(NPChar.nation);
			sNation = iNation;
			dialog.text = DLG_TEXT[78] + XI_ConvertString(GetNationNameByType(iNation)) + ", " + GetMyAddressForm(NPChar, PChar, ADDR_TITLE, false, false) + DLG_TEXT[79] + XI_ConvertString(GetNationRoyalByType(iNation)) + DLG_TEXT[80];
			Link.l1 = DLG_TEXT[44];
			Link.l1.go = "exit";
			if(sti(pchar.reputation) >= 40)
			{
				pchar.nations.(sNation).Amnesty = RMAmnestyCost(PChar, iNation);
				dialog.text = DLG_TEXT[81] + XI_ConvertString(GetNationNameByType(iNation)) + DLG_TEXT[82] + XI_ConvertString(GetNationRoyalByType(iNation)) + DLG_TEXT[83] + ShowMoney(-sti(pchar.nations.(sNation).Amnesty)) + DLG_TEXT[46] + ".";
				if(makeint(pchar.money) >= 0-makeint(pchar.nations.(sNation).Amnesty))
				{
					Link.l2 = DLG_TEXT[84];
					Link.l2.go = "Amnestyc";
				}
			}
		break;

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

		case "promote":
			iNation = sti(NPChar.nation);
			NPChar.templand = GetCharacterLand(PChar);
			Promote(&PChar, &NPChar, iNation);
			dialog.text = DLG_TEXT[48] + XI_ConvertString(GetRankName(PChar, iNation)) + DLG_TEXT[87] + (GetCharacterLand(PChar) - sti(NPChar.templand)) + DLG_TEXT[88] + XI_ConvertString(GetNationRoyalByType(iNation)) + "."; // PB: Might fix a dialog display error. Please check!
			DeleteAttribute(NPChar,"templand");
			Link.l1 = DLG_TEXT[49];
			Link.l1.go = "exit";
		break;

		case "leave":
			iNation = sti(NPChar.nation);
			dialog.text = DLG_TEXT[89] + PChar.name + "? " + XI_ConvertString(GetNationRoyalByType(iNation)) + DLG_TEXT[90];
			Link.l1 = DLG_TEXT[91];
			Link.l1.go = "leavec";
			if(sti(PChar.reputation) < REP_LEAVEMIN + 5)
			{
				dialog.text = XI_ConvertString(GetNationRoyalByType(iNation)) + DLG_TEXT[92] + PChar.name + ".";
				Link.l1 = DLG_TEXT[97];
			}
			Link.l2 = DLG_TEXT[93];
			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[94];
			Link.l1 = DLG_TEXT[44];
			Link.l1.go = "exit";
			if(LeaveService(&PChar, iNation, false))
			{
				dialog.text = DLG_TEXT[95] + XI_ConvertString(DEFAULT_TITLE) + " " + PChar.lastname ".";
				Link.l1 = DLG_TEXT[96];
				Link.l1.go = "leavebad";
			}
		break;

		case "leavebad":
			iNation = sti(NPChar.nation);
			NextDiag.CurrentNode = NextDiag.TempNode;
			NPChar.quest.Meeting = lastspeak_date;
			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.snd = "Voice\CHMA\CHMA003";
			Preprocessor_Add("addr", GetMyAddressForm(NPChar, PChar, ADDR_CIVIL, false, false)); // KK
			dialog.text = DLG_TEXT[8];
			link.l1 = DLG_TEXT[9];
			link.l1.go = "quests";
			link.l2 = DLG_TEXT[10];
			link.l2.go = "node_2";
		break;

		case "node_2":
			dialog.snd = "Voice\CHMA\CHMA004";
			dialog.text = DLG_TEXT[11];
			link.l1 = DLG_TEXT[12];
			link.l1.go = "exit";
		break;

		case "quests":
			dialog.snd = "Voice\CHMA\CHMA005";
			dialog.text = DLG_TEXT[13] + GetMyAddressForm(NPChar, PChar, ADDR_CIVIL, false, false) + DLG_TEXT[14];
			link.l1 = DLG_TEXT[15];
			link.l1.go = "exit";
// boal -->
			iNation = sti(NPChar.nation); // KK
			if (!CheckAttribute(pchar, "quest.generate_kill_quest") && GetNationRelation2MainCharacter(iNation) != RELATION_ENEMY)
			{
				dialog.text = DLG_TEXT[51];
				link.l1 = DLG_TEXT[52];
				link.l1.go = "kill_pirate";
			}
			if (CheckQuestAttribute("generate_kill_quest", "completed") && pchar.quest.generate_kill_quest.town==GetCurrentTownID())
			{
				dialog.text = DLG_TEXT[53];
				link.l1 = DLG_TEXT[54];
				link.l1.go = "kill_pirate_completed";
			}
		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[55] + XI_ConvertString("sw_" + GetNationDescByType(iNation)) + DLG_TEXT[56]+ characters[quest_pirate_idx].ship.name + DLG_TEXT[58] + XI_ConvertString(pchar.quest.generate_kill_quest.destination) + DLG_TEXT[59] + pchar.quest.generate_kill_quest.money + DLG_TEXT[60]; // KK
			link.l1 = DLG_TEXT[61];
			link.l1.go = "kill_pirate_agree";
			link.l2 = DLG_TEXT[62];
			link.l2.go = "kill_pirate_refused";
		break;

		case "kill_pirate_agree":
			NPChar.quest.Meeting = lastspeak_date; // RM
			DialogExit();
			NextDiag.CurrentNode = NextDiag.TempNode;
			AddDialogExitQuest("kill_pirate_agree");
		break;

		case "kill_pirate_refused":
			NPChar.quest.Meeting = lastspeak_date; // RM
			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.generate_kill_quest.money));
			AddDialogExitQuest("kill_pirate_refused_2");
			ChangeCharacterReputation(pchar, 1);
			NPChar.quest.Meeting = lastspeak_date; // RM
			DialogExit();
			NextDiag.CurrentNode = NextDiag.TempNode;
			pchar.quest.generate_kill_quest = "wait_timer";
		break;
// boal <--

// KK -->
		case "international relations":
			stemp = "";
			iNation = sti(NPChar.nation);
			stemp = GetHostileNations(iNation);
			if (stemp != "")
				stemp = DLG_TEXT[18] + DLG_TEXT[20] + DLG_TEXT[21] + stemp + DLG_TEXT[23] + DLG_TEXT[25];
			else
				stemp = DLG_TEXT[18] + DLG_TEXT[19] + DLG_TEXT[20] + DLG_TEXT[22] + DLG_TEXT[24] + DLG_TEXT[25];
			dialog.Text = stemp;
			Link.l1 = DLG_TEXT[42];
			Link.l1.go = "exit";
		break;
// <-- KK

		case "Exit":
			NPChar.quest.Meeting = lastspeak_date; // RM
			DialogExit();
			NextDiag.CurrentNode = NextDiag.TempNode;
		break;
	}
}
