// ccc Dialog for civilian in fort 

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

	DeleteAttribute(&Dialog,"Links");

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

	ref PChar;
	PChar = GetMainCharacter();
	ref lcn = &Locations[FindLocation(PChar.location)];	// determines where you are
	ref commander = (characterFromID(lcn.townsack + " Commander"));	// the fortcommander of this town

	AddMoneyToCharacter(Npchar, 1000 + rand(9000));	// gives NPC between 1000 and 10000 gold



	switch(Dialog.CurrentNode)
	{
		case "First time":
			NextDiag.TempNode = "fight";		// next time dialog starts there
			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.text = LinkRandPhrase(DLG_TEXT[0], DLG_TEXT[1], DLG_TEXT[2]) ;

			Link.l1 = LinkRandPhrase(DLG_TEXT[3], DLG_TEXT[4], DLG_TEXT[5]);
			Link.l1.go = "exit";

// KK -->
			if (GetCurrentLocationNation() != PERSONAL_NATION) {
				link.l2 = DLG_TEXT[6];
				if(rand(100)< FORT_RAIDSUCCESS + (sti(pchar.skill.Sneak))*3) {Link.l2.go = "continue";}
				else{Link.l2.go = "fight";}
	
				link.l3 = LinkRandPhrase(DLG_TEXT[7], DLG_TEXT[8], DLG_TEXT[9]);
				if(rand(100)< FORT_RAIDSUCCESS + (sti(pchar.skill.Fencing))*3) {Link.l3.go = "continue";}
				else{Link.l3.go = "fight";}
	
				link.l4 = DLG_TEXT[10];
				if(rand(100)< FORT_RAIDSUCCESS + (sti(pchar.skill.leadership))*3) {Link.l4.go = "continue";}
				else{Link.l4.go = "fight";}
			} else {
			// when that's our fort...
			}
// <-- KK
		break;


		case "continue":
			dialog.text = LinkRandPhrase(DLG_TEXT[11], DLG_TEXT[12], DLG_TEXT[13]);
			Link.l1 = LinkRandPhrase(DLG_TEXT[14], DLG_TEXT[15], DLG_TEXT[16]);
			if(lcn.filespath.models == "locations\Inside\LargeStore")
			{
				Link.l1.go = "armory";	
			}
			else
			{
				switch(rand(4) )
				{
					case 0: Link.l1.go = "clerk"; break;
					case 1: Link.l1.go = "fort"; break;
					case 2: Link.l1.go = "officer"; break;
					case 3: Link.l1.go = "crimp"; break;
					case 4: Link.l1.go = "supply"; break;
				}
			}
			Link.l2 = LinkRandPhrase(DLG_TEXT[3], DLG_TEXT[4], DLG_TEXT[5]);
			Link.l2.go = "exit";
		break;


		case "Fort":
			dialog.text = DLG_TEXT[17];

			Link.l1 = DLG_TEXT[18];
			Link.l1.go = "warning";

			Link.l2 = DLG_TEXT[19];
			Link.l2.go = "purse";

			Link.l3 = DLG_TEXT[20];
			Link.l3.go = "amnesty";

			Link.l4 = LinkRandPhrase(DLG_TEXT[3], DLG_TEXT[4], DLG_TEXT[5]);
			Link.l4.go = "exit";
		break;


		case "warning":
			dialog.text = DLG_TEXT[21];
			Link.l1 = DLG_TEXT[22];
			if (rand(100)< FORT_RAIDSUCCESS/2 )		//  chance that...
			{
				Link.l1.go = "capture";	// ... the town surrenders...
			}
			else
			{
				Link.l1.go = "fight";		// ... or you get another fight
			}

			Link.l2 = DLG_TEXT[23];
			Link.l2.go = "purse";

			Link.l3 = DLG_TEXT[24];
			Link.l3.go = "amnesty";

			Link.l4 = LinkRandPhrase(DLG_TEXT[3], DLG_TEXT[4], DLG_TEXT[5]);
			Link.l4.go = "exit";
		break;

		case "fight":
			dialog.text = LinkRandPhrase(DLG_TEXT[25], DLG_TEXT[26], DLG_TEXT[27]);
			Link.l1 = RandSwear() + DLG_TEXT[28];
			Link.l1.go = "exit_fight";
		break;


		case "capture":
			PlayStereoOGG("music_ship_victory"); 		// fanfare
			SetRMRelation(pchar, sti(commander.nation), REL_WAR);
// KK -->
			if (ENABLE_FLAGS == 1) {
				SetActualRMRelation(sti(commander.nation), REL_WAR);
				LooseLetterOfMarque(sti(commander.nation));
			}
// <-- KK
			LAi_Fade("", "");

			dialog.text = DLG_TEXT[29];

			Link.l2 = DLG_TEXT[30];
			Link.l2.go = "portugal";

			Link.l1 = DLG_TEXT[31];
			Link.l1.go = "dutch";

			Link.l3 = DLG_TEXT[32];
			Link.l3.go = "britain";

			Link.l4 = DLG_TEXT[33];
			Link.l4.go = "france";

			Link.l5 = DLG_TEXT[34];
			Link.l5.go = "spain";

			Link.l6 = DLG_TEXT[35];
			Link.l6.go = "ransack";

		break;


		case "portugal":
			PlayStereoSound("voice\" + LanguageGetLanguage() + "\por_m_a_038.wav"); 
			ChangeTownNation (lcn.townsack, PORTUGAL);
			LAi_ActorGoToLocation(NPchar, "reload", LAi_FindRandomLocator("reload"), "none", "", "", "", 25.0);
// KK -->
			if (ENABLE_FLAGS == 0) {
				if (GetRMRelation(PChar, PORTUGAL) < 0) SetRMRelation(GetMainCharacter(), PORTUGAL, 0);
			} else {
				if (GetActualRMRelation(PORTUGAL) < 0) {
					SetActualRMRelation(PORTUGAL, 0);
					ReceiveLetterOfMarque(PORTUGAL);
				}
			}
// <-- KK
			if(AUTO_SKILL_SYSTEM) { AddCharacterExpChar(pchar, "Leadership", 5000); }
			else { AddCharacterExp(pchar, 5000); }
			DialogExit();
			NextDiag.CurrentNode = NextDiag.TempNode;
		break;

		case "dutch":
			PlayStereoSound("voice\" + LanguageGetLanguage() + "\dut_m_a_040.wav");
			ChangeTownNation (lcn.townsack, HOLLAND);
			LAi_ActorGoToLocation(NPchar, "reload", LAi_FindRandomLocator("reload"), "none", "", "", "", 25.0);
// KK -->
			if (ENABLE_FLAGS == 0) {
				if (GetRMRelation(PChar, HOLLAND) < 0) SetRMRelation(GetMainCharacter(), HOLLAND, 0);
			} else {
				if (GetActualRMRelation(HOLLAND) < 0) {
					SetActualRMRelation(HOLLAND, 0);
					ReceiveLetterOfMarque(HOLLAND);
				}
			}
// <-- KK
			if(AUTO_SKILL_SYSTEM) { AddCharacterExpChar(pchar, "Leadership", 5000); }
			else { AddCharacterExp(pchar, 5000); }
			DialogExit();
			NextDiag.CurrentNode = NextDiag.TempNode;
		break;

		case "britain":
			PlayStereoSound("voice\" + LanguageGetLanguage() + "\eng_m_a_051.wav");
			ChangeTownNation (lcn.townsack, ENGLAND);
			LAi_ActorGoToLocation(NPchar, "reload", LAi_FindRandomLocator("reload"), "none", "", "", "", 25.0);
// KK -->
			if (ENABLE_FLAGS == 0) {
				if (GetRMRelation(PChar, ENGLAND) < 0) SetRMRelation(GetMainCharacter(), ENGLAND, 0);
			} else {
				if (GetActualRMRelation(ENGLAND) < 0) {
					SetActualRMRelation(ENGLAND, 0);
					ReceiveLetterOfMarque(ENGLAND);
				}
			}
// <-- KK
			if(AUTO_SKILL_SYSTEM) { AddCharacterExpChar(pchar, "Leadership", 5000); }
			else { AddCharacterExp(pchar, 5000); }
			DialogExit();
			NextDiag.CurrentNode = NextDiag.TempNode;
		break;


		case "france":
			PlayStereoSound("voice\" + LanguageGetLanguage() + "\fre_m_a_042.wav");
			ChangeTownNation (lcn.townsack, FRANCE);
// KK -->
			if (ENABLE_FLAGS == 0) {
				if (GetRMRelation(PChar, FRANCE) < 0) SetRMRelation(GetMainCharacter(), FRANCE, 0);
			} else {
				if (GetActualRMRelation(FRANCE) < 0) {
					SetActualRMRelation(FRANCE, 0);
					ReceiveLetterOfMarque(FRANCE);
				}
			}
// <-- KK
			if(AUTO_SKILL_SYSTEM) { AddCharacterExpChar(pchar, "Leadership", 5000); }
			else { AddCharacterExp(pchar, 5000); }
			LAi_ActorGoToLocation(NPchar, "reload", LAi_FindRandomLocator("reload"), "none", "", "", "", 25.0);
			DialogExit();
			NextDiag.CurrentNode = NextDiag.TempNode;
		break;

		case "spain":
			PlayStereoSound("voice\" + LanguageGetLanguage() + "\spa_m_a_039.wav");
			ChangeTownNation (lcn.townsack, SPAIN);

// KK -->
			if (ENABLE_FLAGS == 0) {
				if (GetRMRelation(PChar, SPAIN) < 0) SetRMRelation(GetMainCharacter(), SPAIN, 0);
			} else {
				if (GetActualRMRelation(SPAIN) < 0) {
					SetActualRMRelation(SPAIN, 0);
					ReceiveLetterOfMarque(SPAIN);
				}
			}
// <-- KK
			if(AUTO_SKILL_SYSTEM) { AddCharacterExpChar(pchar, "Leadership", 5000); }
			else { AddCharacterExp(pchar, 5000); }
			LAi_ActorGoToLocation(NPchar, "reload", LAi_FindRandomLocator("reload"), "none", "", "", "", 25.0);
			DialogExit();
			NextDiag.CurrentNode = NextDiag.TempNode;
		break;




		case "ransack":
			PlayStereoOGG("music_ship_victory"); 		// fanfare
// KK -->
			if (ENABLE_FLAGS == 0) {
				SetRMRelation(pchar, sti(commander.nation), REL_WAR);
			} else {
				SetActualRMRelation(sti(commander.nation), REL_WAR);
				LooseLetterOfMarque(sti(commander.nation));
			}
// <-- KK
			DialogExit();
			NextDiag.CurrentNode = NextDiag.TempNode;
			LaunchFortCapture(commander);	// towncapture
		break;

		case "purse":
			dialog.text =  RandSwear() + LinkRandPhrase(DLG_TEXT[36], DLG_TEXT[37], DLG_TEXT[38]) + npchar.money + DLG_TEXT[39];
			Link.l1 = LinkRandPhrase(DLG_TEXT[40], DLG_TEXT[41], DLG_TEXT[42]);
			Link.l1.go = "exit";

			LAi_group_SetRelation( LAI_GROUP_GUARDS, LAI_GROUP_PLAYER, LAI_GROUP_ENEMY);
			PlayStereoSound("INTERFACE\took_item.wav");
			AddMoneyToCharacter(pchar, sti(npchar.money));
			AddMoneyToCharacter(Npchar, - sti(npchar.money));

		break;

		case "bombs":
			LAi_group_SetRelation( LAI_GROUP_GUARDS, LAI_GROUP_PLAYER, LAI_GROUP_ENEMY);
			AddCharacterGoods(pchar, GOOD_BOMBS, makeint(200 + rand(500)) );
			LAi_SetActorType(NPchar);
			LAi_ActorRunToLocation(NPchar, "reload", LAi_FindRandomLocator("reload"), "none", "", "", "", 25.0);
			DialogExit();
			NextDiag.CurrentNode = NextDiag.TempNode;
		break;

		case "arms":
			LAi_group_SetRelation( LAI_GROUP_GUARDS, LAI_GROUP_PLAYER, LAI_GROUP_ENEMY);
     			 // ccc special weapons, SW assembly kit must be installed !
			TakenItems(Pchar, "pistolbbuss", rand(2));	
			TakenItems(Pchar, "bladeX1", rand(1));	
			TakenItems(Pchar, "bladeX2", rand(1));	
			TakenItems(Pchar, "bladeX3", rand(1));	
			TakenItems(Pchar, "pistolpdart", rand(3));
			TakenItems(Pchar, "pistolgrenade", rand(3));
			TakenItems(Pchar, "pistolgas", rand(3));
			TakenItems(Pchar, "pistolrock", rand(3));
			TakenItems(Pchar, "pistolstink", rand(3));
			LAi_SetActorType(NPchar);
			LAi_ActorRunToLocation(NPchar, "reload", LAi_FindRandomLocator("reload"), "none", "", "", "", 25.0);
			DialogExit();
			NextDiag.CurrentNode = NextDiag.TempNode;
		break;

		case "amnesty":
			LAi_group_SetRelation(LAI_GROUP_PLAYER, LAI_GROUP_GUARDS, LAI_GROUP_NEITRAL);
			LAi_group_SetRelation(LAI_GROUP_PLAYER, LAI_DEFAULT_GROUP, LAI_GROUP_NEITRAL);
// KK -->
			if (ENABLE_FLAGS == 0)
				SetRMRelation(pchar, sti(commander.nation), REL_NEUTRAL);	// gives you LOM of the fort NATION, based on NK's RM mod
			else {
				SetActualRMRelation(sti(commander.nation), REL_NEUTRAL);	// gives you LOM of the fort NATION, based on NK's RM mod
				ReceiveLetterOfMarque(sti(commander.nation));
			}
// <-- KK
			if(AUTO_SKILL_SYSTEM) { AddCharacterExpChar(pchar, "Leadership", 5000); }
			else { AddCharacterExp(pchar, 5000); }
			LAi_SetActorType(NPchar);
			LAi_ActorGoToLocation(NPchar, "reload", LAi_FindRandomLocator("reload"), "none", "", "", "", 25.0);
			DialogExit();
			NextDiag.CurrentNode = NextDiag.TempNode;
		break;

		case "clerk":
			dialog.text = DLG_TEXT[43];
			Link.l1 = DLG_TEXT[44];
			Link.l1.go = "exit";
			Link.l2 = DLG_TEXT[45];
			Link.l2.go = "purse";

		break;


		case "armory":
			dialog.text = DLG_TEXT[46];
			Link.l1 = DLG_TEXT[47];
			Link.l1.go = "exit";
			Link.l2 = DLG_TEXT[48];
			Link.l2.go = "bombs";

			Link.l3 = DLG_TEXT[49];
			Link.l3.go = "arms";
		break;


		case "crimp":
			dialog.text = DLG_TEXT[50];

		if(ENABLE_BROTHEL == 1)
		{
			Link.l1 = DLG_TEXT[51];
			Link.l1.go = "exit";
		}
		else
		{
			Link.l1 = DLG_TEXT[65];
			Link.l1.go = "exit";
		}

			Link.l2 = DLG_TEXT[52];
			Link.l2.go = "Exit_crew";

			Link.l3 = DLG_TEXT[53];
			Link.l3.go = "purse";
		break;


		case "Exit_crew":
			AddCharacterCrew(pchar,makeint(50 + rand(50) ));
			LAi_SetActorType(NPchar);
			LAi_ActorRunToLocation(NPchar, "reload", LAi_FindRandomLocator("reload"), "none", "", "", "", 25.0);
			NextDiag.CurrentNode = NextDiag.TempNode;
			DialogExit();
		break;



		case "supply":
			dialog.text = DLG_TEXT[54];

			Link.l1 = DLG_TEXT[55];
			Link.l1.go = "exit";

			Link.l2 = DLG_TEXT[56];
			Link.l2.go = "Exit_buy";

			Link.l3 = DLG_TEXT[57];
			Link.l3.go = "purse";
		break;

		case "Exit_buy":
			AddCharacterGoods(pchar, GOOD_WHEAT, makeint(15 + rand(20)) );
			AddCharacterGoods(pchar, GOOD_PLANKS, makeint(40 + rand(30)) );
			AddCharacterGoods(pchar, GOOD_SAILCLOTH, makeint(40 + rand(30)) );
			AddCharacterGoods(pchar, GOOD_RUM, makeint(15 + rand(20)) );
			LAi_SetActorType(NPchar);
			LAi_ActorRunToLocation(NPchar, "reload", LAi_FindRandomLocator("reload"), "none", "", "", "", 25.0);
			NextDiag.CurrentNode = NextDiag.TempNode;
			DialogExit();
		break;


		case "officer":
			dialog.text = DLG_TEXT[58];
			Link.l1 = DLG_TEXT[59];
			Link.l1.go = "exit";
			Link.l2 = DLG_TEXT[60];
			Link.l2.go = "purse";

			Link.l3 = DLG_TEXT[61];
			Link.l3.go = "enlist_me";
		break;


		case "enlist_me":
			// NK let you hire these people
			NPChar.Dialog.Filename = "Enc_Officer_dialog.c";
			dialog.Text = DLG_TEXT[62];
			Link.l1 = DLG_TEXT[63];
			Link.l1.go = "exit_change_dlg";
			NPChar.offgen = true;
			NPChar.officer = true;
			NPChar.quest.officertype = OFFIC_TYPE_BOATSWAIN;
			LAi_Create_Officer(rand(5), &NPChar); //so that these officers are better than tavern ones.

			Pchar.quest.HiringOfficerIDX = GetCharacterIndex(NPChar.id);
			AddDialogExitQuest("LandEnc_OfficerHired");
			NPChar.quest.meeting = NPC_Meeting;

		break;


		case "exit_change_dlg":
			NextDiag.CurrentNode = "hired";
			DialogExit();
		break;
		// NK <--

		case "exit":
			LAi_SetActorType(NPchar);
			LAi_ActorRunToLocation(NPchar, "reload", LAi_FindRandomLocator("reload"), "none", "", "", "", 25.0);
			DialogExit();
			NextDiag.CurrentNode = NextDiag.TempNode;
		break;

		case "exit_fight":
		// PB: To prevent the fight from starting before the dialog is closed
			PlaySound("voice\" + LanguageGetLanguage() + "\Eng_m_a_067.wav");
			SetRMRelation(pchar, sti(commander.nation), REL_WAR);
// KK -->
			if (ENABLE_FLAGS == 1) {
				SetActualRMRelation(sti(commander.nation), REL_WAR);
				LooseLetterOfMarque(sti(commander.nation));
			}
// <-- KK
			Ambush("guards", 8, "enemy", "friend","");

			LAi_SetActorType(NPchar);
			LAi_ActorRunToLocation(NPchar, "reload", LAi_FindRandomLocator("reload"), "none", "", "", "", 25.0);

			DialogExit();
			NextDiag.CurrentNode = NextDiag.TempNode;
		break;
	}
}

// ccc <--
