#include "QUESTS\Quest_Messages.h"
#include "QUESTS\facemaker.c" // function now moved to a separate file by KAM

bool bQuestDisableAllCommands = false; // KK

// boal -->
void GeneratePirateQuest(ref gov) // KK
{
	int iNation = sti(gov.nation); // KK
	string sdestination = Locations[FindLocation(gov.location)].island; // KK
	InitQuestPirate(iNation);		// LDH 05Sep06 // KK

	ref PChar = GetMainCharacter(); // KK
	int iShipType, iTradeMoney, irank, pRank;
	// KK string sdestination;

	//NK generate rank and skills
	pRank = sti(PChar.rank);
	if(GetShipCap()) { if((8-GetCharacterShipClass(PChar)) * 2 < pRank) { pRank = (8-GetCharacterShipClass(PChar)) * 2; } } // NK
	irank = makeint((pRank/2.0 + Rand(pRank/2)) * (2.0/3.0 + ((makefloat(GetDifficulty())-1.0)/5.0)) + 0.5);
	if(irank < 1) irank = 1;
	//Log_SetStringToLog("P" + pRank +" N" + irank);
	int quest_pirate_idx = GetCharacterIndex("Quest pirate"); // KK
	ref rFantom = characterFromID("Quest pirate"); // KK
	characters[quest_pirate_idx].rank = irank;

	DeleteAttribute(rFantom, "Ship");

	//NK new findship function
	//int minrank = makeint(irank/2.0 + rand(irank*50/100.0) + 0.25);
	//if(minrank > irank) minrank = irank;
	//int maxrank = makeint(minrank + rand(irank*37/100) + 0.25);
	//Log_SetStringToLog("Minrank " + minrank + "; Max " + maxrank);
	//Log_SetStringToLog("Rank " + irank);
	int minclass = 7 - makeint((irank - Rand(3))/2) ;
	int maxclass = 7 - makeint((irank + Rand(3))/2) ;
	if(maxclass < 7 - makeint(makeint(PChar.rank) * 2 / 3)) maxclass = 7 - makeint(makeint(PChar.rank) * 2 / 3);
	if(minclass < 7 - makeint(makeint(PChar.rank) * 2 / 3)) minclass = 7 - makeint(makeint(PChar.rank) * 2 / 3);
	if(iNation == PIRATE && maxclass < MAXPIRATECLASS) maxclass = MAXPIRATECLASS; // KK
	if(iNation == PIRATE && minclass < MAXPIRATECLASS) minclass = MAXPIRATECLASS; // KK
	if(minclass > 6) minclass = 6;
	if(maxclass > 6) maxclass = 6;
	//Log_SetStringToLog("Minclass " + minclass + "; Max " + maxclass);
	if (sti(rFantom.nation) >= MAX_NATIONS) rFantom.nation = PIRATE; // KB- Fix Governor Pirate Quest bug // KK
	iShipType = Force_GetShipType(maxclass, minclass, "War", sti(rFantom.nation)); // PS
	ref Shiptype = GetShipByType(iShipType);
	//Log_SetStringToLog("Shiptype " + Shiptype.Name);
	rFantom.ship.type = GetShipID(iShipType); // PS
	rFantom.ship.idx = iShipType;
	// PRS3 -->
	aref arship; makearef(arship, rFantom.ship);
	DeleteAttribute(rFantom, "ship.stats");
//KB - Tuning ships - changed call to SetRandomStatsToShip
	SetRandomStatsToShip(sti(rFantom.index), iShipType, sti(rFantom.nation));
//KB - orig 	SetRandomStatsToShip(arship, iShipType, sti(rFantom.nation));
	// PRS3 <--

	//end NK edit
	SetRandomNameToShip(rFantom);
	SetRandomNameToCharacter(rFantom);
	characters[quest_pirate_idx].old.name = characters[quest_pirate_idx].name; // KK
	characters[quest_pirate_idx].old.lastname = characters[quest_pirate_idx].lastname; // KK
	SetBaseShipData(rFantom);

	//NK use AIfantom calls
	//hack until I can use Fantom_AddFantomCharacter();
// KK -->
	string sFantomType;
	if (CheckAttribute(Shiptype, "type.trade") && Shiptype.type.trade)
		sFantomType = "trade";
	else
		sFantomType = "war";
// <-- KK
	if(sti(rFantom.nation) == PIRATE) sFantomType = "pirate";
	rFantom.shiptype = iShipType;
	rFantom.FantomType = sFantomType;
	float mult = 1.0;
	switch(sFantomType)
	{
		case "trade":
			mult *= 1.0;
			rFantom.quest.officertype = OFFIC_TYPE_CAPMERCHANT;
			break;
			
		case "war":
			mult *= 1.25;
			rFantom.quest.officertype = OFFIC_TYPE_CAPNAVY;
			break;
			
		case "pirate":
			mult *= 1.5; //note this is different from AIFantom! Because the gov knows this pirate is hunting near his island!
			rFantom.quest.officertype = OFFIC_TYPE_CAPPIRATE;
			break;

		case "error":
			mult *= 1.0;
			rFantom.quest.officertype = OFFIC_TYPE_CAPPIRATE;
			break;
	}
	int iMCShipClass = makeint(GetCharacterShipClass(PChar)); // KK
	//Log_SetStringToLog("Mult 1 = " + mult);
	if(makeint(Shiptype.Class) < iMCShipClass) mult *= 1.5;
	if(makeint(Shiptype.Class) > iMCShipClass) mult *= 0.75;
	rFantom.Points = mult * stf(GetLocalShipAttrib(arship, Shiptype, "Weight")) / 5000; // PRS3
	//Log_SetStringToLog("NewM " + mult);
	//end hack.

	//set various stuff using AIFantom calls.
	LAi_Create_Officer(0, rFantom);
	Fantom_SetRandomMoney(rFantom, sFantomType);
	Fantom_SetCannons(rFantom, sFantomType);
	Fantom_SetSails(rFantom, sFantomType);
	Ship_SetFantomData(rFantom);
	Fantom_ClearCargo(rFantom); // TIH clear out prior slot cargo
	Fantom_SetBalls(rFantom, sFantomType);
	Fantom_SetGoods(rFantom, sFantomType);

	//NK edit trademoney
	//Log_SetStringToLog("CanQ " + sti(Shiptype.CannonsQuantity));
	float shipmult = 5.0 * sqrt(intRet(sti(Shiptype.CannonsQuantity),sti(Shiptype.CannonsQuantity),1) * sti(GetLocalShipAttrib(arship, Shiptype, "HP")) * stf(GetLocalShipAttrib(arship, Shiptype, "SpeedRate"))); // PRS3
	float commult = 1.0 + makeint(GetSummonSkillFromName(PChar, SKILL_COMMERCE))/20.0;
	//Log_SetStringToLog("SM " + shipmult);
	//Log_SetStringToLog("CM " + commult);

	iTradeMoney = makeint(sqrt(irank) * shipmult * commult/25)*25;
	//Log_SetStringToLog("TM " + iTradeMoney);
	if(iTradeMoney < 100) iTradeMoney = 100;
	//iTradeMoney = irank*1000+makeint(pchar.skill.commerce)*100;

	pchar.quest.generate_kill_quest = "begin";
	pchar.quest.generate_kill_quest.money = iTradeMoney;
//	pchar.quest.generate_kill_quest.town = GetTownIDFromLocID(gov.location); // KK
	pchar.quest.generate_kill_quest.town = GetCurrentTownID();//MAXIMUS: it's not simpler?
	pchar.quest.generate_kill_quest.destination = sdestination;
	pchar.quest.generate_kill_quest.nation = sti(rFantom.nation); // KK // MAXIMUS
	pchar.quest.generate_kill_quest.shipname = rFantom.Ship.Name;
}

string GenerateDestinationKill()
{
	ref PChar;
	PChar = GetMainCharacter();
	
	int destination;
	string sdestination;
	destination = makeint(rand(5));
	switch (destination)
	{
		case 0: sdestination = "Redmond"; break;
		case 1: sdestination = "Oxbay"; break;
		case 2: sdestination = "IslaMuelle"; break;
		case 3: sdestination = "Conceicao"; break;
		case 4: sdestination = "Douwesen"; break;
		case 5: sdestination = "Falaisedefleur"; break;
	}
	return sdestination;
}
// boal <--

bool CreateParticleSystemOnLocator(string _location_id, string _locatorName, string _particleName)
{
	aref locator;
	if (!FindLocator(_location_id, _locatorName, &locator, true))
		return false;

	CreateParticleSystemX(_particleName,stf(locator.x),stf(locator.y),stf(locator.z), stf(locator.vz.x),stf(locator.vz.y),stf(locator.vz.z),0);
	return true;
}

int GenerateNationTrade(int nation)
{
	int i = -1;/*
	int n = 0; // LDH runaway prevention Aug20'06
	while (i == -1)
	{
		i = rand(MAX_NATIONS - 1);
		if (GetNationRelation2MainCharacter(i) == RELATION_ENEMY || GetNationRelation(nation, i) == RELATION_ENEMY || nation == i || i == PIRATE)
		{
			i = -1;
		}
		n++; if (n>1000) break; // LDH runaway prevention Aug20'06
	}*/
	string friendlyNations = "";
	for(int j=0; j<MAX_NATIONS; j++)
	{
		if(GetNationRelation2MainCharacter(j)==RELATION_ENEMY) continue;
		if(GetNationRelation(nation, j)==RELATION_ENEMY) continue;
		if(nation==j) continue;
		if(j==PIRATE) continue;
		string tmpNat = j;
		friendlyNations = StoreString(friendlyNations,tmpNat);
	}
	i = sti(GetRandSubString(friendlyNations));

	return i;
}

// NK -->
int GenerateGoodForTrade(int FromNat, int ToNat, ref fromprice, ref toprice) // NK add prices 05-05-12
{
	//int fstoreidx = GetTownStoreIndex(GetTownIDFromGroup(Stores[GetCharacterCurrentStore(GetMainCharacter())].group));
	int fstoreidx = GetTownStoreIndex(GetCurrentTownID());
	//trace("from " + fstoreidx + " of " + GetCurrentTownID());
	string destCol;
	string friendlyTowns = "";
	for(int j=0; j<TOWNS_QUANTITY; j++)
	{
		if(!CheckAttribute(&Towns[j],"id")) continue;
		if(!CheckAttribute(&Towns[j],"nation")) continue;
		if(CheckAttribute(&Towns[j],"skiptrade") && Towns[j].skiptrade==true) continue;//MAXIMUS: added for some towns (such as St. John's on Antigua)
		if(Towns[j].nation!=ToNat) continue;
		friendlyTowns = StoreString(friendlyTowns,Towns[j].id);
	}
	if(friendlyTowns!="")
	{
		destCol = GetRandSubString(friendlyTowns);
		while(destCol=="" || HasSubStr(destCol,",") || GetIslandIDFromTown(destCol)==GetIslandIDFromTown(GetCurrentTownId())) { destCol = GetRandSubString(friendlyTowns); }
	}
	else
	{
		switch (ToNat)
		{
			case FRANCE: destCol = FRA_COLONY; break;
			case SPAIN: destCol = SPA_COLONY; break;
			case HOLLAND: destCol = HOL_COLONY; break;
			case PORTUGAL: destCol = POR_COLONY; break;
			case ENGLAND:  destCol = RED_COLONY; break;
		}
	}
	int tstoreidx = GetTownStoreIndex(destCol);
	//trace("to " + tstoreidx + " of " + destCol);
	ref sfrom, sto;
	makeref(sfrom, Stores[fstoreidx]);
	makeref(sto, Stores[tstoreidx]);
	int gt;
	bool found = false;
	for(int i = 0; i < 512; i++) //to
	{
		gt = rand(GOODS_QUANTITY);
		if(CheckAttribute(Goods[gt],"skip") && sti(Goods[gt].skip)) { continue; }
		if(GetStoreGoodsType(sfrom, gt) == TRADE_TYPE_CONTRABAND_NAME) continue;
		if(GetStoreGoodsType(sto, gt) == TRADE_TYPE_CONTRABAND_NAME) continue;
		found = true;
		break;
	}
	/*if(found) return gt;
	return GOOD_CHOCOLATE;*/
	ref PChar = GetMainCharacter();
	if(!found) gt = GOOD_CHOCOLATE;
	// yes this is not dynamic-price compliant, but then TheDiamond will be redoing the economics anyway. NK 05-05-12
	fromprice = round(makefloat(GetStoreGoodsPrice(sfrom, gt, PRICE_TYPE_BUY, &PChar, 0)) / GetCharPriceMod(&PChar, PRICE_TYPE_BUY, true));
	toprice = round(makefloat(GetStoreGoodsPrice(sto, gt, PRICE_TYPE_SELL, &PChar, 0)) / GetCharPriceMod(&PChar, PRICE_TYPE_SELL, true));
	// NK 05-05-12 <--
	return gt;
}
// NK <--

// KAM -->
void FaceMaker(aref rCharacter)						//changed by KAM
{
	rCharacter.FaceId = GetCharacterFaceID(rCharacter.model);
	rCharacter.headModel = "h_" + rCharacter.model;
}
// KAM <--

void OfficersReaction(string alignment)
{
	int iPassenger;
	ref PChar;
	PChar = GetMainCharacter();

	for (int io = 0; io<GetPassengersQuantity(pchar); io++)
	{
		iPassenger = GetPassenger(pchar, io);
		if(CheckAttribute(characters[iPassenger], "loyality"))
		{
			if (characters[iPassenger].alignment == alignment)
			{
				characters[iPassenger].loyality = makeint(characters[iPassenger].loyality) + 1;
			}
			else
			{
				characters[iPassenger].loyality = makeint(characters[iPassenger].loyality) - 1;
	
				if(makeint(characters[iPassenger].loyality) < 1)
				{
					string homelocation = pchar.location;
					PlaceCharacter(&characters[iPassenger], "goto", pchar.location);
					characters[iPassenger].selfdialog.filename = characters[iPassenger].dialog.filename;
					characters[iPassenger].selfdialog.currentnode = characters[iPassenger].dialog.currentnode;
					characters[iPassenger].dialog.filename = "anacleto_dialog.c";
					characters[iPassenger].dialog.currentnode = "remove";
					LAi_SetActorType(&characters[iPassenger]);
					LAi_ActorDialog(&characters[iPassenger], pchar, "pchar_back_to_player", 2.0, 1.0);
					LAi_SetStayType(pchar);
				}
			}
		}
	}
}

// NK itemtrade 05-03-26 move Item trader functions to items_utilite.c

string GenerateDestination()
{
	ref PChar = GetMainCharacter();
	string sdestination = "";
	string friendlyTowns = "";

//MAXIMUS -[such functions must be universal (IMHO), if we are planning to make a real Caribbean in the future]->
	for(int i=0; i<TOWNS_QUANTITY; i++)
	{
		ref ctown; makeref(ctown, Towns[i]);
		if(GetNationRelation2MainCharacter(sti(ctown.nation))==RELATION_ENEMY || GetNationRelation(sti(PChar.nation), sti(ctown.nation))==RELATION_ENEMY) continue;//MAXIMUS: GetNationRelation maybe not need to be added: player will have a choice
		
		friendlyTowns = StoreString(friendlyTowns,ctown.id);
	}
	if(friendlyTowns!="")
	{
		sdestination = GetRandSubString(friendlyTowns);
		while(sdestination=="" || HasSubStr(sdestination,",") || GetIslandIDFromTown(sdestination)==GetIslandIDFromTown(GetCurrentTownId())) { sdestination = GetRandSubString(friendlyTowns); }
	}
	else { sdestination = DEFAULT_DESTINATION; }
//MAXIMUS <-[such functions must be universal (IMHO), if we are planning to make a real Caribbean in the future]-

	return sdestination;
}

void GenerateConvoyQuest()
{
	ref PChar;
	//ref refShip;
	PChar = GetMainCharacter();
	int iShipType, iCargoType, iTradeGoods, iTradeMoney, iNation, irank;
	irank = sti(PChar.rank); // PS
	DeleteAttribute(characterFromID("Quest trader"), "Ship");
	
	//AddCharacterGoods(characterFromID("quest trader"), GOOD_BALLS, 600);
	//AddCharacterGoods(characterFromID("quest trader"), GOOD_BOMBS, 600);
	// PS -->
	irank = 8 - irank/2;
	if(irank < MAXMERCHANTCLASS) irank = MAXMERCHANTCLASS;
	if(irank > 5) irank = 5;
	iShipType = Force_GetShipType(irank, irank+1, "trade", -1);
	characters[GetCharacterIndex("Quest trader")].ship.type = GetShipID(iShipType);
	// PS <--
	SetRandomNameToShip(characterFromID("Quest trader"));
	SetBaseShipData(characterFromID("Quest trader"));
	
	//makeref(refShip,ShipsTypes[iShipType]);
	//characters[GetCharacterIndex("Quest trader")].ship.hp = refShip.HP;
	//characters[GetCharacterIndex("Quest trader")].ship.sp = refShip.SP;
	//characters[GetCharacterIndex("Quest trader")].ship.crew = refShip.maxcrew;
	
	iTradeGoods = rand(20) + 6;
	iCargoType = GetCharacterFreeSpace(characterFromID("quest trader"), iTradeGoods);
	AddCharacterGoods(characterFromID("quest trader"), iTradeGoods, iCargoType);
	iTradeMoney = ((iCargoType*8+99)/100)*100 + irank*100;

	Characters[GetCharacterIndex("Quest trader")].money = iTradeMoney * rand(irank) + rand(100); // KK
	Characters[GetCharacterIndex("Quest trader")].reputation = 10 * rand(9); // KK
	
	pchar.quest.generate_convoy_quest.convoymoney = iTradeMoney;
	string cDestination = GenerateDestination();
	pchar.quest.generate_convoy_quest.destination = cDestination;	
	pchar.quest.generate_convoy_quest.island = GetIslandIDFromTown(cDestination);
	if(cDestination==DEFAULT_DESTINATION || cDestination=="")
	{
		pchar.quest.generate_convoy_quest.destination = DEFAULT_DESTINATION;
		pchar.quest.generate_convoy_quest.island = DEFAULT_TRADEISLAND;
	}
			
	pchar.quest.generate_convoy_quest.win_condition.l1 = "Timer";
	pchar.quest.generate_convoy_quest.win_condition.l1.date.day = GetAddingDataDay(0, 20, 0);
	pchar.quest.generate_convoy_quest.win_condition.l1.date.month = GetAddingDataMonth(0, 20, 0);
	pchar.quest.generate_convoy_quest.win_condition.l1.date.year = GetAddingDataYear(0, 20, 0);
	pchar.quest.generate_convoy_quest.win_condition = "generate_convoy_quest";
	pchar.quest.generate_convoy_quest_progress = "begin";
	
	pchar.quest.generate_convoy_quest_failed.win_condition.l1 = "NPC_Death";
	pchar.quest.generate_convoy_quest_failed.win_condition.l1.character = "Quest trader";
	pchar.quest.generate_convoy_quest_failed.win_condition = "generate_convoy_quest_failed";
}

void TavernWaitDate(string date)
{
	int iTime, iAddTime;
	iTime = sti(environment.time);
	if (date == "wait_day")
	{
		if (iTime >= 22) iAddTime = 24 - iTime + 10;
		if (iTime <= 10) iAddTime = 10 - iTime;
		//this is handled by nextday NK 05-04-17 StoreDayUpdate();
	}
	else
	{
		if (iTime < 22) iAddTime = 22 - iTime;
	}
	LAi_Fade("", "");
	WaitDate("",0,0,0,iAddTime,1);
	RecalculateJumpTable();
}

void TavernWaitDate2(string date)
{
	int iTime, iAddTime;
	iTime = sti(environment.time);
	if (date == "wait_day")
	{
		if (iTime >= 22) iAddTime = 24 - iTime + 10;
		if (iTime <= 10) iAddTime = 10 - iTime;
		//this is handled by nextday NK 05-04-17 StoreDayUpdate();
	}
	else
	{
		if (iTime < 22) iAddTime = 22 - iTime;
	}
	WaitDate("",0,0,0,iAddTime,1);
	RecalculateJumpTable();
}

void PlaceCharacter(aref ch, string group, string location)
{
	float locx;
	float locy;
	float locz;
	string homelocator;
	GetCharacterPos(GetMainCharacter(), &locx, &locy, &locz);
	homelocator = LAi_FindNearestFreeLocator(group, locx, locy, locz);
	ChangeCharacterAddressGroup(ch, location, group, homelocator);
}


// LDH - Added 05Sep06 to generate a better selection of pirate captains
// updated 18Oct06 for correct animations, take character sex from model file
string RandomCaptain(int iNation) // KK
{
	if (iNation != PIRATE && CheckAttribute(Nations[iNation], "fantomModel.m0")) return Nations[iNation].fantomModel.m0; // KK

//	A note on adding characters to this function:
//	Place the name of the character you wish to test in the line below, uncomment the line in LAi_boarding.c that says:
//	Put the surrendered captain in your hold, then go to the hold and offer to make them an officer.
//  If anything doesn't work, don't put the new character in this function.
//	If the captain works, add it to the appropriate switch statement below.
//  Note that female captains will not sit in your hold, but stand instead. The greeting voice will be wrong as well.
//	Don't forget to comment the two lines out again when you're done.

//  Uncomment the line below to test new characters.  See instructions above.
//	return "test character here";
//	return "33_Piratess10";	// Example.

	string CaptainSex = "man";
	if (rand(19) == 0) CaptainSex = "woman";		// one in 20 chance of female captain, easter egg

	if (CaptainSex == "man")
	{
		switch(rand(19))
		{
			case 0:  return "33_Ronald";	 break;
			case 1:  return "BadV";			 break;
			case 2:  return "Black_corsair"; break;
			case 3:  return "Capitan";		 break;
			case 4:  return "Capnhook";		 break;
			case 5:  return "Corsair1";		 break;
			case 6:  return "Corsair1_2";	 break;
			case 7:  return "Corsair1_3";	 break;
			case 8:  return "Corsair1_4";	 break;
			case 9:  return "Corsair2";		 break;
			case 10: return "Corsair3";		 break;
			case 11: return "Corsair4";		 break;
			case 12: return "Corsair5";		 break;
			case 13: return "Pirat1";		 break;
			case 14: return "Pirat11";		 break;
			case 15: return "Pirat13";		 break;
			case 16: return "Searcher_navy"; break;
			case 17: return "Shkiper";		 break;
			case 18: return "9Jc";			 break;
			case 19: return "9Jd";			 break;
		}
		return "Corsair3";
	}
	else
	{
		switch(rand(3))
		{
			case 0:  return "33_Piratess10";	break;
			case 1:  return "9Td";				break;
			case 2:  return "9CATa";			break;
			case 3:  return "girlpatch";		break;
		}
		return "33_Piratess10";
	}
}

// LDH --> Added 05Sep06 to get rid of problems with uninitialized data
// Taken from Characters_init.c and StoryCharacters.c
void InitQuestPirate(int iNation)
{
	ref mchr = GetMainCharacter(); // KK
	ref ch = CharacterFromID("Quest Pirate");
	int idx = sti(ch.index);

	int HostileNation = LotHostileNation(iNation);

	DeleteAttribute(ch, "");

	ch.id			= "Quest Pirate";
	ch.index		= idx;
	//int tmpNameFileID = LanguageOpenFile("characters_names.txt");
	ch.old.name		= "Deadly";		// will be overwritten
	ch.old.lastname = "Pirate";
	ch.name			= TranslateString("","Deadly");		// will be overwritten
	ch.lastname		= TranslateString("","Pirate");
	//LanguageCloseFile(tmpNameFileID);

	ch.model	= RandomCaptain(HostileNation);
	ch.model.entity = "NPCharacter";

	// LDH 18Oct06 fixes for characters with special animations
	// we are intentionally not using Character_PostInit()
	int mdlIndex = GetModelIndex(ch.model);
	if (mdlIndex < 0)		// just in case, especially if someone mistypes the name for a test
	{
		ch.model = "Corsair3";
		mdlIndex = GetModelIndex(ch.model);
	}
	ref mdl = &Models[mdlIndex];
	ch.model.animation = mdl.ani;
	ch.model.ani = mdl.ani;
	ch.sex = mdl.sex;
//	Facemaker(ch);		// unneeded, this is set elsewhere

	if (ch.sex == "man")
	{
// KK -->
		if (HostileNation == PIRATE) {
			ch.sound_type = "pirate";
			ch.greeting = "Gr_Vincent Bethune";	// this gets overwritten when twin character is made
		} else {
			ch.sound_type = "soldier";
			ch.greeting = GetSoldiersGreeting(HostileNation, "");
		}
// <-- KK
	}
	else
	{
		ch.sound_type = "female_citizen";
		ch.greeting = "Gr_Pirate_f";	// this gets overwritten when twin character is made
	}
	ch.nation = HostileNation; // KK

	if (rand(4) < 3) {
		string pistol = "pistol" + (rand(5) + 1) + stringRet(rand(1), "+", "-") + rand(2);
		GiveItem2Character(ch, pistol);
		ch.equip.gun = pistol;
		//JRH ammo mod -->
		if (ENABLE_AMMOMOD) {	// LDH change
			TakenItems(ch, "gunpowder", 1 + rand(2));
			TakenItems(ch, "pistolbullets", 1 + rand(2));
		}
		//JRH ammo mod <--
  	}
	GiveItem2Character(ch, BLADE_LONG);
	ch.equip.blade = BLADE_LONG;
	ch.nodisarm	= 1;				// PB: Disable disarming
	ch.location	= "none";
	ch.location.group = "goto";
	ch.location.locator = "none";
	ch.location.from_sea = "";
	ch.Ship.Type = SHIP_NOTUSED_TYPE_NAME;
	ch.Dialog.Filename = "Vincent Bethune_dialog.c";	// will be overwritten
	ch.Dialog.CurrentNode = "First time";
	ch.Dialog.TempNode = ch.Dialog.CurrentNode;
	ch.quest.meeting = "0";
	ch.quest = "True";

	ch.rank 	= rand(10); // KK
	if (HostileNation == PIRATE)
		ch.reputation = "40";
	else
		ch.reputation = rand(88) + 1;
	ch.experience = "240000";
	ch.skill.freeskill = 0;
	ch.skill.Leadership = "2";
	ch.skill.Fencing = "7";
	ch.skill.Sailing = "1";
	ch.skill.Accuracy = "6";
	ch.skill.Cannons = "5";
	ch.skill.Grappling = "1";
	ch.skill.Repair = "1";
	ch.skill.Defence = "4";
	ch.skill.Commerce = "1";
	ch.skill.Sneak = "8";
	ch.money = "10";

	ch.AbordageMode = 1;

	LAi_SetMerchantType(ch);	// makes captain cower in hold if you threaten him with a sword
	LAi_SetLoginTime(ch, 0.0, 24.0);
	LAi_SetHP(ch, 80.0, 80.0);
	LAi_NoRebirthEnable(ch);
}
// LDH <--

// KK -->
void CommonQuestComplete(string sQuestName)
{
	ref PChar = GetMainCharacter();
	ref NPChar, sld;
	int cc, iColony, iTradeGoods, iQuantityGoods, iTradeNation, iPassenger;
	float locx, locy, locz;
	float x, y, z;// MAXIMUS
	string nearloc;// MAXIMUS
	string homelocation, homegroup, homelocator, tavernfriend;

	//int tmpLangFileID = LanguageOpenFile("interface_strings.txt");

	switch (sQuestName) {
		////////////////////////////////////////////////////////////////////////
		//  ЗАЙМЫ - ОГРАНИЧЕНИЕ ПО ВРЕМЕНИ
		////////////////////////////////////////////////////////////////////////

		case "Loans_Redmond":

			ChangeCharacterReputation(Pchar, -20);
			Characters[GetCharacterIndex("Redmond Usurer")].Dialog.CurrentNode = "DeadMotherfucker";

			NPChar = CharacterFromID("Usurer_Avenger01");

			//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat6";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger01"));
			SetBaseShipData(NPChar);

			Group_CreateGroup("Usurer_Avenger");
			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger01");
			Group_SetGroupCommander("Usurer_Avenger", "Usurer_Avenger01");


			NPChar = CharacterFromID("Usurer_Avenger02");

		//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat3";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);
			SetRandomNameToShip(characterFromID("Usurer_Avenger02"));
			SetBaseShipData(NPChar);

			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger02");


			NPChar = CharacterFromID("Usurer_Avenger03");

		//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat4";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetBaseShipData(NPChar);
			SetRandomNameToShip(characterFromID("Usurer_Avenger03"));
			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger03");

			SetCharacterRelationBoth(GetCharacterIndex("Usurer_Avenger01"),GetMainCharacterIndex(),RELATION_ENEMY);	
			Group_SetTaskAttack("Usurer_Avenger", PLAYER_GROUP);
			Group_LockTask("Usurer_Avenger");

			Encounter_SetQuestMapEncounter("Usurer_Avenger", ENCOUNTER_WAR, true, 50);
		
		break;

		case "Loans_Oxbay":

			ChangeCharacterReputation(Pchar, -20);

			Characters[GetCharacterIndex("Oxbay Usurer")].Dialog.CurrentNode = "DeadMotherfucker";

			NPChar = CharacterFromID("Usurer_Avenger01");

			//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat6";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger01"));
			SetBaseShipData(NPChar);

			Group_CreateGroup("Usurer_Avenger");
			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger01");
			Group_SetGroupCommander("Usurer_Avenger", "Usurer_Avenger01");


			NPChar = CharacterFromID("Usurer_Avenger02");

		//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat3";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger02"));
			SetBaseShipData(NPChar);

			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger02");


			NPChar = CharacterFromID("Usurer_Avenger03");

		//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat4";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger03"));
			SetBaseShipData(NPChar);

			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger03");

			SetCharacterRelationBoth(GetCharacterIndex("Usurer_Avenger01"),GetMainCharacterIndex(),RELATION_ENEMY);	
			Group_SetTaskAttack("Usurer_Avenger", PLAYER_GROUP);
			Group_LockTask("Usurer_Avenger");

			Encounter_SetQuestMapEncounter("Usurer_Avenger", ENCOUNTER_WAR, true, 50);	
		break;

		case "Loans_Greenford":
			Characters[GetCharacterIndex("Greenford Usurer")].Dialog.CurrentNode = "DeadMotherfucker";

			ChangeCharacterReputation(Pchar, -20);

			NPChar = CharacterFromID("Usurer_Avenger01");

			//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat6";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger01"));
			SetBaseShipData(NPChar);

			Group_CreateGroup("Usurer_Avenger");
			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger01");
			Group_SetGroupCommander("Usurer_Avenger", "Usurer_Avenger01");


			NPChar = CharacterFromID("Usurer_Avenger02");

		//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat3";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger02"));
			SetBaseShipData(NPChar);

			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger02");


			NPChar = CharacterFromID("Usurer_Avenger03");

		//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat4";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger03"));
			SetBaseShipData(NPChar);

			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger03");

			SetCharacterRelationBoth(GetCharacterIndex("Usurer_Avenger01"),GetMainCharacterIndex(),RELATION_ENEMY);	
			Group_SetTaskAttack("Usurer_Avenger", PLAYER_GROUP);
			Group_LockTask("Usurer_Avenger");

			Encounter_SetQuestMapEncounter("Usurer_Avenger", ENCOUNTER_WAR, true, 50);	
		break;

		case "Loans_FalaiseDeFleur":
			Characters[GetCharacterIndex("FF Usurer")].Dialog.CurrentNode = "DeadMotherfucker";

			ChangeCharacterReputation(Pchar, -20);

			NPChar = CharacterFromID("Usurer_Avenger01");

			//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat6";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger01"));
			SetBaseShipData(NPChar);

			Group_CreateGroup("Usurer_Avenger");
			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger01");
			Group_SetGroupCommander("Usurer_Avenger", "Usurer_Avenger01");


			NPChar = CharacterFromID("Usurer_Avenger02");

		//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat3";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger02"));
			SetBaseShipData(NPChar);

			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger02");


			NPChar = CharacterFromID("Usurer_Avenger03");

		//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat4";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger03"));
			SetBaseShipData(NPChar);

			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger03");

			SetCharacterRelationBoth(GetCharacterIndex("Usurer_Avenger01"),GetMainCharacterIndex(),RELATION_ENEMY);	
			Group_SetTaskAttack("Usurer_Avenger", PLAYER_GROUP);
			Group_LockTask("Usurer_Avenger");

			Encounter_SetQuestMapEncounter("Usurer_Avenger", ENCOUNTER_WAR, true, 50);	
		break;

		case "Loans_Conceicao":
			Characters[GetCharacterIndex("Conceicao Usurer")].Dialog.CurrentNode = "DeadMotherfucker";

			ChangeCharacterReputation(Pchar, -20);

			NPChar = CharacterFromID("Usurer_Avenger01");

			//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat6";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger01"));
			SetBaseShipData(NPChar);

			Group_CreateGroup("Usurer_Avenger");
			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger01");
			Group_SetGroupCommander("Usurer_Avenger", "Usurer_Avenger01");


			NPChar = CharacterFromID("Usurer_Avenger02");

		//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat3";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger02"));
			SetBaseShipData(NPChar);

			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger02");


			NPChar = CharacterFromID("Usurer_Avenger03");

		//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat4";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger03"));
			SetBaseShipData(NPChar);

			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger03");

			SetCharacterRelationBoth(GetCharacterIndex("Usurer_Avenger01"),GetMainCharacterIndex(),RELATION_ENEMY);	
			Group_SetTaskAttack("Usurer_Avenger", PLAYER_GROUP);
			Group_LockTask("Usurer_Avenger");

			Encounter_SetQuestMapEncounter("Usurer_Avenger", ENCOUNTER_WAR, true, 50);	
		break;

		case "Loans_Douwesen":
			Characters[GetCharacterIndex("Douwesen Usurer")].Dialog.CurrentNode = "DeadMotherfucker";

			ChangeCharacterReputation(Pchar, -20);

			NPChar = CharacterFromID("Usurer_Avenger01");

			//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat6";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger01"));
			SetBaseShipData(NPChar);

			Group_CreateGroup("Usurer_Avenger");
			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger01");
			Group_SetGroupCommander("Usurer_Avenger", "Usurer_Avenger01");


			NPChar = CharacterFromID("Usurer_Avenger02");

		//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat3";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger02"));
			SetBaseShipData(NPChar);

			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger02");


			NPChar = CharacterFromID("Usurer_Avenger03");

		//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat4";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger03"));
			SetBaseShipData(NPChar);

			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger03");

			SetCharacterRelationBoth(GetCharacterIndex("Usurer_Avenger01"),GetMainCharacterIndex(),RELATION_ENEMY);	
			Group_SetTaskAttack("Usurer_Avenger", PLAYER_GROUP);
			Group_LockTask("Usurer_Avenger");

			Encounter_SetQuestMapEncounter("Usurer_Avenger", ENCOUNTER_WAR, true, 50);
		break;

		case "Loans_Muelle":
			Characters[GetCharacterIndex("Muelle Usurer")].Dialog.CurrentNode = "DeadMotherfucker";

			ChangeCharacterReputation(Pchar, -20);

			NPChar = CharacterFromID("Usurer_Avenger01");

			//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat6";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger01"));
			SetBaseShipData(NPChar);

			Group_CreateGroup("Usurer_Avenger");
			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger01");
			Group_SetGroupCommander("Usurer_Avenger", "Usurer_Avenger01");


			NPChar = CharacterFromID("Usurer_Avenger02");

		//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat3";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger02"));
			SetBaseShipData(NPChar);

			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger02");


			NPChar = CharacterFromID("Usurer_Avenger03");

		//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat4";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger03"));
			SetBaseShipData(NPChar);

			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger03");

			SetCharacterRelationBoth(GetCharacterIndex("Usurer_Avenger01"),GetMainCharacterIndex(),RELATION_ENEMY);	
			Group_SetTaskAttack("Usurer_Avenger", PLAYER_GROUP);
			Group_LockTask("Usurer_Avenger");

			Encounter_SetQuestMapEncounter("Usurer_Avenger", ENCOUNTER_WAR, true, 50);	
		break;

		case "Loans_QC":
			Characters[GetCharacterIndex("QC Usurer")].Dialog.CurrentNode = "DeadMotherfucker";

			ChangeCharacterReputation(Pchar, -20);

			NPChar = CharacterFromID("Usurer_Avenger01");

			//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat6";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger01"));
			SetBaseShipData(NPChar);

			Group_CreateGroup("Usurer_Avenger");
			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger01");
			Group_SetGroupCommander("Usurer_Avenger", "Usurer_Avenger01");


			NPChar = CharacterFromID("Usurer_Avenger02");

		//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat3";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger02"));
			SetBaseShipData(NPChar);

			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger02");


			NPChar = CharacterFromID("Usurer_Avenger03");

		//Простановка параметров капитанам-преследователям
			NPChar.act.hp = 120;
			NPChar.nation =  PIRATE;
			SetRandomNameToCharacter(NPChar);
			NPChar.rank = makeint(Pchar.rank) - 2 + Rand(4);
			NPChar.experience = CalculateExperienceFromRank(sti(NPChar.rank));
			NPChar.model = "pirat4";

			CalculateAppropriateSkills(NPChar);	

			SelectCoastalGuardShip(NPChar);

			SetRandomNameToShip(characterFromID("Usurer_Avenger03"));
			SetBaseShipData(NPChar);

			Group_addCharacter("Usurer_Avenger", "Usurer_Avenger03");

			SetCharacterRelationBoth(GetCharacterIndex("Usurer_Avenger01"),GetMainCharacterIndex(),RELATION_ENEMY);	
			Group_SetTaskAttack("Usurer_Avenger", PLAYER_GROUP);
			Group_LockTask("Usurer_Avenger");

			Encounter_SetQuestMapEncounter("Usurer_Avenger", ENCOUNTER_WAR, true, 50);
		break;




		////////////////////////////////////////////////////////////////////////
		//  Служебный квест контрабандистов - ограничение по времени
		////////////////////////////////////////////////////////////////////////

		case "Rand_Smuggling": // this occurs if you fail to show up for the smuggling
			Pchar.quests.contraband.relation = makeint(Pchar.quests.contraband.relation) - 10;
			RemoveSmugglersFromShore();
		break;

		case "Rand_SmugglingRemove":
			ChangeCharacterAddressGroup(CharacterFromID("Rand_Smug01"), "None", "", "");
			ChangeCharacterAddressGroup(CharacterFromID("Rand_Smug02"), "None", "", "");
			ChangeCharacterAddressGroup(CharacterFromID("Rand_Smug03"), "None", "", "");			
		break;


		//Постановка стражников в локацию передачи контрабандистов
		case "Rand_ContrabandInterruption":

			//trace("ПОЯВЛЕНИЕ БЕРЕГОВОЙ СТРАЖИ: " + sld.id);

			//LAi_CreateFantomCharacter(0, "soldier_eng", "", "");
						
			

			/*NK*/ sld = LAi_CreateFantomCharacter(false, 0, true, true, 0.75, SelectSoldierModelbyLocationNation(Pchar.location, "Soldier"), "", "");
			Pchar.quest.contraband.SoldierIDX2 = sld.index;			
			LAi_SetActorType(sld);
			LAi_group_MoveCharacter(sld, "CoastalGuards");
			// NK - sld.skill.Fencing = makeint(Pchar.skill.Fencing) - 2 + Rand(4);
			LAi_ActorFollow(sld, Pchar, "", 120);

			/*NK*/ sld = LAi_CreateFantomCharacter(false, 0, true, true, 0.75, SelectSoldierModelbyLocationNation(Pchar.location, "Soldier"), "", "");
			Pchar.quest.contraband.SoldierIDX3 = sld.index;
			LAi_SetActorType(sld);
			LAi_group_MoveCharacter(sld, "CoastalGuards");
			// NK - sld.skill.Fencing = makeint(Pchar.skill.Fencing) - 2 + Rand(4);
			LAi_ActorFollow(sld, Pchar, "", 120);

			/*NK*/ sld = LAi_CreateFantomCharacter(false, 0, true, true, 0.75, SelectSoldierModelbyLocationNation(Pchar.location, "Soldier"), "", "");
			Pchar.quest.contraband.SoldierIDX4 = sld.index;
			LAi_SetActorType(sld);
			LAi_group_MoveCharacter(sld, "CoastalGuards");
			// NK - sld.skill.Fencing = makeint(Pchar.skill.Fencing) - 2 + Rand(4);
			LAi_ActorFollow(sld, Pchar, "", 120);

			/*NK*/ sld = LAi_CreateFantomCharacter(false, 0, true, true, 0.75, SelectSoldierModelbyLocationNation(Pchar.location, "Soldier"), "", "");
			Pchar.quest.contraband.SoldierIDX5 = sld.index;
			LAi_SetActorType(sld);
			LAi_group_MoveCharacter(sld, "CoastalGuards");
			// NK - sld.skill.Fencing = makeint(Pchar.skill.Fencing) - 2 + Rand(4);
			LAi_ActorFollow(sld, Pchar, "", 120);

			/*NK*/ sld = LAi_CreateFantomCharacter(false, 0, true, true, 0.75, SelectSoldierModelbyLocationNation(Pchar.location, "Soldier"), "", "");
			Pchar.quest.contraband.SoldierIDX6 = sld.index;
			LAi_SetActorType(sld);
			LAi_group_MoveCharacter(sld, "CoastalGuards");
			// NK - sld.skill.Fencing = makeint(Pchar.skill.Fencing) - 2 + Rand(4);
			LAi_ActorFollow(sld, Pchar, "", 120);


			// ccc stormy start; coastguard officer creation moved here so that he catches you first
			/*NK*/ sld = LAi_CreateFantomCharacter(false, 0, true, true, 0.75, SelectSoldierModelbyLocationNation(Pchar.location, "Officer"), "", "");
			Pchar.quest.contraband.SoldierIDX1 = sld.index;
		//	Log_SetstringToLog("Индекс ссылки на первого солдата(фантома): " + sld.index);
			//Pchar.quest.contraband.SoldierIDX1 = getCharacterIndex(sld.id);
			LAi_SetActorType(sld);
			LAi_group_MoveCharacter(sld, "CoastalGuards");
			sld.Dialog.Filename = "Coastal Guards_dialog.c";
			sld.Dialog.CurrentNode = "First time";
			// NK - sld.skill.Fencing = makeint(Pchar.skill.Fencing) - 1 + Rand(4);
		//	Log_SetstringToLog("Индекс первого солдата: " + Pchar.quest.contraband.SoldierIDX1);

			trace("ПОЯВЛЕНИЕ БЕРЕГОВОЙ СТРАЖИ: " + sld.id);
			LAi_ActorDialog(sld, Pchar, "", 120, 0);

			SetCoastalGuardPursuit();

			Lai_QuestDelay("Rand_CoastalPatrolAppear", 1.0);
		/*	Pchar.quest.Rand_ContrabandInterruptionAtSea.win_condition.l1 = "location";
			Pchar.quest.Rand_ContrabandInterruptionAtSea.win_condition.l1.character = PChar.id;
			Pchar.quest.Rand_ContrabandInterruptionAtSea.win_condition.l1.location = Islands[GetCharacterCurrentIsland(pchar)].id;
			Pchar.quest.Rand_ContrabandInterruptionAtSea.win_condition = "Rand_ContrabandInterruptionAtSea";*/
		break;

		case "Rand_CoastalPatrolAppear":			  
			Trace("QUEST Rand_CoastalPatrolAppear reports: Soldier Idx = " + Pchar.quest.contraband.SoldierIDX1);
			// StartQuestMovie(true, true, true);
			// ccc stormy start; so that you can run from coastguards   LAi_SetActorTypeNoGroup(Pchar);
			// ccc LAi_ActorTurnToCharacter(Pchar, &Characters[makeint(Pchar.quest.contraband.SoldierIDX1)]);
			// ccc LAi_ActorWaitDialog(Pchar, &Characters[makeint(Pchar.quest.contraband.SoldierIDX1)]); 
			LAi_LocationFightDisable(&Locations[FindLocation(pchar.location)], true);
			// ccc so that guard can challenge you

			// TIH --> fix the broken combat settings if you 'ran' from the gaurds Jul25'06
			pchar.cleanlocidx = FindLocation(pchar.location);
			Pchar.quest.Rand_ContrabandInterruptionCleanup.win_condition.l1 = "location";
			Pchar.quest.Rand_ContrabandInterruptionCleanup.win_condition.l1.character = PChar.id;
			Pchar.quest.Rand_ContrabandInterruptionCleanup.win_condition.l1.location = Islands[GetCharacterCurrentIsland(pchar)].id;
			Pchar.quest.Rand_ContrabandInterruptionCleanup.win_condition = "Rand_ContrabandInterruptionCleanup";
			/* // MapEnter is a good catch situation as well... but not as cool
			Pchar.quest.Rand_ContrabandInterruptionCleanup.win_condition.l1 = "MapEnter";
			Pchar.quest.Rand_ContrabandInterruptionCleanup.win_condition = "Rand_ContrabandInterruptionCleanup";
			*/
			// TIH <--

			//LAi_SetPlayerType(Pchar);
		break;

		// TIH --> fix the broken combat settings if you 'ran' from the gaurds Jul25'06
		case "Rand_ContrabandInterruptionCleanup":
			// if the player DID run away screaming like a little wuss, we do cleanup because the dialog never happened
			if ( CheckAttribute( &Locations[sti(pchar.cleanlocidx)],"noFight" ) ) {
				LAi_LocationFightDisable(&Locations[sti(pchar.cleanlocidx)], false);
				Pchar.quest.Rand_ContrabandInterruptionAtSeaEnded.win_condition.l1 = "MapEnter";
				Pchar.quest.Rand_ContrabandInterruptionAtSeaEnded.win_condition = "Rand_ContrabandInterruptionAtSeaEnded";
				//Pchar.quest.Rand_Smuggling.over = "yes";	// dont need to do this, it should have happened already
				//RemoveSmugglersFromShore();				// dont need to do this, it should have happened already
				// fantom soldiers are automatically removed (they are fantoms)
			}
			DeleteAttribute(pchar,"cleanlocidx");
		break;
		// TIH <--

		case "Rand_ContrabandInterruptionAtSeaEnded":
			StopCoastalGuardPursuit();
		break;

		





////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////LAND ENCOUNTERS QUESTS///////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////


//------------------------------------------RAIDERS----------------------------------------------------
		case "LandEnc_RaidersLogin":
			LAi_group_SetRelation("ENC_RAIDERS_GROUP", LAI_GROUP_PLAYER, LAI_GROUP_NEITRAL);

			LAi_SetCheckMinHP(characterFromID("Enc_Char1"), (LAi_GetCharacterHP(CharacterFromID("Enc_Char1")) - 1), false, "LandEnc_RaidersFight");
			LAi_SetCheckMinHP(characterFromID("Enc_Char2"), (LAi_GetCharacterHP(CharacterFromID("Enc_Char2")) - 1), false, "LandEnc_RaidersFight");
			LAi_SetCheckMinHP(characterFromID("Enc_Char3"), (LAi_GetCharacterHP(CharacterFromID("Enc_Char3")) - 1), false, "LandEnc_RaidersFight");
			LAi_SetCheckMinHP(characterFromID("Enc_Char4"), (LAi_GetCharacterHP(CharacterFromID("Enc_Char4")) - 1), false, "LandEnc_RaidersFight");
		break;


		case "LandEnc_RaidersStart":
			LAi_SetActorType(CharacterFromID("Enc_Char1"));
			LAi_SetActorType(CharacterFromID("Enc_Char2"));
			LAi_SetActorType(CharacterFromID("Enc_Char3"));
			LAi_SetActorType(CharacterFromID("Enc_Char4"));

			LAi_group_MoveCharacter(CharacterFromID("Enc_Char1"), "ENC_RAIDERS_GROUP");
			LAi_group_MoveCharacter(CharacterFromID("Enc_Char2"), "ENC_RAIDERS_GROUP");
			LAi_group_MoveCharacter(CharacterFromID("Enc_Char3"), "ENC_RAIDERS_GROUP");
			LAi_group_MoveCharacter(CharacterFromID("Enc_Char4"), "ENC_RAIDERS_GROUP");

			LAi_SetCheckMinHP(characterFromID("Enc_Char1"), (LAi_GetCharacterHP(CharacterFromID("Enc_Char1")) - 1), false, "LandEnc_RaidersFight");
			LAi_SetCheckMinHP(characterFromID("Enc_Char2"), (LAi_GetCharacterHP(CharacterFromID("Enc_Char2")) - 1), false, "LandEnc_RaidersFight");
			LAi_SetCheckMinHP(characterFromID("Enc_Char3"), (LAi_GetCharacterHP(CharacterFromID("Enc_Char3")) - 1), false, "LandEnc_RaidersFight");
			LAi_SetCheckMinHP(characterFromID("Enc_Char4"), (LAi_GetCharacterHP(CharacterFromID("Enc_Char4")) - 1), false, "LandEnc_RaidersFight");
			
			LAi_ActorDialog(CharacterFromID("Enc_Char1"), Pchar, "", 10, 0);
			LAi_ActorDialog(CharacterFromID("Enc_Char2"), Pchar, "", 10, 0);
			LAi_ActorDialog(CharacterFromID("Enc_Char3"), Pchar, "", 10, 0);
			LAi_ActorDialog(CharacterFromID("Enc_Char4"), Pchar, "", 10, 0);

			if(CheckAttribute(Pchar, "quest.LandEnc_StartingQuest1")) pchar.quest.LandEnc_StartingQuest1.over = "yes";
			if(CheckAttribute(Pchar, "quest.LandEnc_StartingQuest2")) pchar.quest.LandEnc_StartingQuest2.over = "yes";
			if(CheckAttribute(Pchar, "quest.LandEnc_StartingQuest3")) pchar.quest.LandEnc_StartingQuest3.over = "yes";

			LAi_SetFightMode(PChar, false);
			LAi_LockFightMode(Pchar, true);
		break;

		case "LandEnc_RaidersFight":
			LAi_LockFightMode(Pchar, false);

			LAi_RemoveCheckMinHP(characterFromID("Enc_Char1"));
			LAi_RemoveCheckMinHP(characterFromID("Enc_Char2"));
			LAi_RemoveCheckMinHP(characterFromID("Enc_Char3"));
			LAi_RemoveCheckMinHP(characterFromID("Enc_Char4"));

			LAi_type_actor_Reset(CharacterFromID("Enc_Char1"));
			LAi_type_actor_Reset(CharacterFromID("Enc_Char2"));
			LAi_type_actor_Reset(CharacterFromID("Enc_Char3"));
			LAi_type_actor_Reset(CharacterFromID("Enc_Char4"));

			LAi_SetWarriorTypeNoGroup(CharacterFromID("Enc_Char1"));
			LAi_SetWarriorTypeNoGroup(CharacterFromID("Enc_Char2"));
			LAi_SetWarriorTypeNoGroup(CharacterFromID("Enc_Char3"));
			LAi_SetWarriorTypeNoGroup(CharacterFromID("Enc_Char4"));

			LAi_group_MoveCharacter(CharacterFromID("Enc_Char1"), "ENC_RAIDERS_GROUP");
			LAi_group_MoveCharacter(CharacterFromID("Enc_Char2"), "ENC_RAIDERS_GROUP");
			LAi_group_MoveCharacter(CharacterFromID("Enc_Char3"), "ENC_RAIDERS_GROUP");
			LAi_group_MoveCharacter(CharacterFromID("Enc_Char4"), "ENC_RAIDERS_GROUP");

			if(CheckAttribute(Pchar, "quest.LandEnc_StartingQuest1")) pchar.quest.LandEnc_StartingQuest1.over = "yes";
			if(CheckAttribute(Pchar, "quest.LandEnc_StartingQuest2")) pchar.quest.LandEnc_StartingQuest2.over = "yes";
			if(CheckAttribute(Pchar, "quest.LandEnc_StartingQuest3")) pchar.quest.LandEnc_StartingQuest3.over = "yes";

			LAi_group_FightGroups("ENC_RAIDERS_GROUP", LAI_GROUP_PLAYER, false);
		break;

		case "LandEnc_RaidersRunAway":
			LAi_LockFightMode(Pchar, false);

			LAi_type_actor_Reset(CharacterFromID("Enc_Char1"));
			LAi_type_actor_Reset(CharacterFromID("Enc_Char2"));
			LAi_type_actor_Reset(CharacterFromID("Enc_Char3"));
			LAi_type_actor_Reset(CharacterFromID("Enc_Char4"));

			LAi_ActorAfraid(CharacterFromID("Enc_Char1"), Pchar, true);
			LAi_ActorAfraid(CharacterFromID("Enc_Char2"), Pchar, true);
			LAi_ActorAfraid(CharacterFromID("Enc_Char3"), Pchar, true);
			LAi_ActorAfraid(CharacterFromID("Enc_Char4"), Pchar, true);

			if(CheckAttribute(Pchar, "quest.LandEnc_StartingQuest1")) pchar.quest.LandEnc_StartingQuest1.over = "yes";
			if(CheckAttribute(Pchar, "quest.LandEnc_StartingQuest2")) pchar.quest.LandEnc_StartingQuest2.over = "yes";
			if(CheckAttribute(Pchar, "quest.LandEnc_StartingQuest3")) pchar.quest.LandEnc_StartingQuest3.over = "yes";

			Characters[GetCharacterIndex("Enc_Char1")].Dialog.CurrentNode = "GetTheHellOut";
			Characters[GetCharacterIndex("Enc_Char2")].Dialog.CurrentNode = "GetTheHellOut";
			Characters[GetCharacterIndex("Enc_Char3")].Dialog.CurrentNode = "GetTheHellOut";
			Characters[GetCharacterIndex("Enc_Char4")].Dialog.CurrentNode = "GetTheHellOut";
		break;

		case "LandEnc_RaidersNoFight":
			LAi_LockFightMode(Pchar, false);

			LAi_type_actor_Reset(CharacterFromID("Enc_Char1"));
			LAi_type_actor_Reset(CharacterFromID("Enc_Char2"));
			LAi_type_actor_Reset(CharacterFromID("Enc_Char3"));
			LAi_type_actor_Reset(CharacterFromID("Enc_Char4"));

			LAi_SetWarriorTypeNoGroup(CharacterFromID("Enc_Char1"));
			LAi_SetWarriorTypeNoGroup(CharacterFromID("Enc_Char2"));
			LAi_SetWarriorTypeNoGroup(CharacterFromID("Enc_Char3"));
			LAi_SetWarriorTypeNoGroup(CharacterFromID("Enc_Char4"));

			LAi_warrior_DialogEnable(CharacterFromID("Enc_Char1"), true);
			LAi_warrior_DialogEnable(CharacterFromID("Enc_Char2"), true);
			LAi_warrior_DialogEnable(CharacterFromID("Enc_Char3"), true);
			LAi_warrior_DialogEnable(CharacterFromID("Enc_Char4"), true);

			if(CheckAttribute(Pchar, "quest.LandEnc_StartingQuest1")) pchar.quest.LandEnc_StartingQuest1.over = "yes";
			if(CheckAttribute(Pchar, "quest.LandEnc_StartingQuest2")) pchar.quest.LandEnc_StartingQuest2.over = "yes";
			if(CheckAttribute(Pchar, "quest.LandEnc_StartingQuest3")) pchar.quest.LandEnc_StartingQuest3.over = "yes";

			Characters[GetCharacterIndex("Enc_Char1")].Dialog.CurrentNode = "GetLost";
			Characters[GetCharacterIndex("Enc_Char2")].Dialog.CurrentNode = "GetLost";
			Characters[GetCharacterIndex("Enc_Char3")].Dialog.CurrentNode = "GetLost";
			Characters[GetCharacterIndex("Enc_Char4")].Dialog.CurrentNode = "GetLost";
		break;

		case "LandEnc_RaidersRobbed":
			LAi_LockFightMode(Pchar, false);

			LAi_type_actor_Reset(CharacterFromID("Enc_Char1"));
			LAi_type_actor_Reset(CharacterFromID("Enc_Char2"));
			LAi_type_actor_Reset(CharacterFromID("Enc_Char3"));
			LAi_type_actor_Reset(CharacterFromID("Enc_Char4"));

			LAi_SetWarriorTypeNoGroup(CharacterFromID("Enc_Char1"));
			LAi_SetWarriorTypeNoGroup(CharacterFromID("Enc_Char2"));
			LAi_SetWarriorTypeNoGroup(CharacterFromID("Enc_Char3"));
			LAi_SetWarriorTypeNoGroup(CharacterFromID("Enc_Char4"));

			LAi_warrior_DialogEnable(CharacterFromID("Enc_Char1"), true);
			LAi_warrior_DialogEnable(CharacterFromID("Enc_Char2"), true);
			LAi_warrior_DialogEnable(CharacterFromID("Enc_Char3"), true);
			LAi_warrior_DialogEnable(CharacterFromID("Enc_Char4"), true);

			if(CheckAttribute(Pchar, "quest.LandEnc_StartingQuest1")) pchar.quest.LandEnc_StartingQuest1.over = "yes";
			if(CheckAttribute(Pchar, "quest.LandEnc_StartingQuest2")) pchar.quest.LandEnc_StartingQuest2.over = "yes";
			if(CheckAttribute(Pchar, "quest.LandEnc_StartingQuest3")) pchar.quest.LandEnc_StartingQuest3.over = "yes";

			Characters[GetCharacterIndex("Enc_Char1")].Dialog.CurrentNode = "OnceAgain";
			Characters[GetCharacterIndex("Enc_Char2")].Dialog.CurrentNode = "OnceAgain";
			Characters[GetCharacterIndex("Enc_Char3")].Dialog.CurrentNode = "OnceAgain";
			Characters[GetCharacterIndex("Enc_Char4")].Dialog.CurrentNode = "OnceAgain";
		break;


//------------------------------------------RAPERS----------------------------------------------------

// Viper - Rapers MOD Start
		case "LandEnc_RapersLogin":

			Characters[GetCharacterIndex("Enc_Char2")].nodisarm = 1; // PB: Disable disarming
			Characters[GetCharacterIndex("Enc_Char3")].nodisarm = 1; // PB: Disable disarming
			Characters[GetCharacterIndex("Enc_Char4")].nodisarm = 1; // PB: Disable disarming

			LAi_group_SetRelation("ENC_RAIDERS_GROUP", LAI_GROUP_PLAYER, LAI_GROUP_NEITRAL);

			LAi_SetCheckMinHP(characterFromID("Enc_Char2"), (LAi_GetCharacterHP(CharacterFromID("Enc_Char2")) - 1), false, "LandEnc_RapersFight");
			LAi_SetCheckMinHP(characterFromID("Enc_Char3"), (LAi_GetCharacterHP(CharacterFromID("Enc_Char3")) - 1), false, "LandEnc_RapersFight");
			LAi_SetCheckMinHP(characterFromID("Enc_Char4"), (LAi_GetCharacterHP(CharacterFromID("Enc_Char4")) - 1), false, "LandEnc_RapersFight");

			LAi_QuestDelay("LandEnc_RapersPursue", 1); // NK was 5
		break;

		case "LandEnc_RapersPursue":
			LAi_SetActorType(CharacterFromID("Enc_Char1"));
			LAi_SetActorType(CharacterFromID("Enc_Char2"));
			LAi_SetActorType(CharacterFromID("Enc_Char3"));
			LAi_SetActorType(CharacterFromID("Enc_Char4"));

			//При первом подходе или истечении времени сработает квест
			LAi_ActorAfraid(CharacterFromID("Enc_Char1"), CharacterFromID("Enc_Char2"), true);
			LAi_ActorFollow(CharacterFromID("Enc_Char2"), CharacterFromID("Enc_Char1"), "", 240);
			LAi_ActorFollow(CharacterFromID("Enc_Char3"), CharacterFromID("Enc_Char1"), "", 240);
			LAi_ActorFollow(CharacterFromID("Enc_Char4"), CharacterFromID("Enc_Char1"), "", 240);

			LAi_ActorDialog(CharacterFromID("Enc_Char1"), Pchar, "", 45, 0);

			if(CheckAttribute(Pchar, "quest.LandEnc_StartingQuest1")) pchar.quest.LandEnc_StartingQuest1.over = "yes";
			if(CheckAttribute(Pchar, "quest.LandEnc_StartingQuest2")) pchar.quest.LandEnc_StartingQuest2.over = "yes";
			if(CheckAttribute(Pchar, "quest.LandEnc_StartingQuest3")) pchar.quest.LandEnc_StartingQuest3.over = "yes";
		break;
// Viper - Rapers MOD End

		case "LandEnc_RapersTalk":
			LAi_SetActorType(CharacterFromID("Enc_Char2"));
			LAi_SetActorType(CharacterFromID("Enc_Char3"));
			LAi_SetActorType(CharacterFromID("Enc_Char4"));

			LAi_ActorAfraid(CharacterFromID("Enc_Char1"), CharacterFromID("Enc_Char2"), true);

			LAi_SetCheckMinHP(characterFromID("Enc_Char2"), (LAi_GetCharacterHP(CharacterFromID("Enc_Char2")) - 1), false, "LandEnc_RapersFight");
			LAi_SetCheckMinHP(characterFromID("Enc_Char3"), (LAi_GetCharacterHP(CharacterFromID("Enc_Char3")) - 1), false, "LandEnc_RapersFight");
			LAi_SetCheckMinHP(characterFromID("Enc_Char4"), (LAi_GetCharacterHP(CharacterFromID("Enc_Char4")) - 1), false, "LandEnc_RapersFight");

			LAi_ActorDialog(CharacterFromID("Enc_Char2"), Pchar, "", 1, 0);
			LAi_ActorDialog(CharacterFromID("Enc_Char3"), Pchar, "", 1, 0);
			LAi_ActorDialog(CharacterFromID("Enc_Char4"), Pchar, "", 1, 0);
		break;

		case "LandEnc_RapersFight":
			LAi_RemoveCheckMinHP(characterFromID("Enc_Char2"));
			LAi_RemoveCheckMinHP(characterFromID("Enc_Char3"));
			LAi_RemoveCheckMinHP(characterFromID("Enc_Char4"));

			LAi_SetWarriorType(CharacterFromID("Enc_Char2"));
			LAi_SetWarriorType(CharacterFromID("Enc_Char3"));
			LAi_SetWarriorType(CharacterFromID("Enc_Char4"));

			LAi_group_MoveCharacter(CharacterFromID("Enc_Char2"), "ENC_RAPERS_GROUP");
			LAi_group_MoveCharacter(CharacterFromID("Enc_Char3"), "ENC_RAPERS_GROUP");
			LAi_group_MoveCharacter(CharacterFromID("Enc_Char4"), "ENC_RAPERS_GROUP");

			Pchar.quest.LandEnc_KillAllRapers.win_condition.l1 = "NPC_Death";
			Pchar.quest.LandEnc_KillAllRapers.win_condition.l1.character = "Enc_Char2";
			Pchar.quest.LandEnc_KillAllRapers.win_condition.l2 = "NPC_Death";
			Pchar.quest.LandEnc_KillAllRapers.win_condition.l2.character = "Enc_Char3";
			Pchar.quest.LandEnc_KillAllRapers.win_condition.l3 = "NPC_Death";
			Pchar.quest.LandEnc_KillAllRapers.win_condition.l3.character = "Enc_Char4";
			PChar.quest.LandEnc_KillAllRapers.win_condition = "LandEnc_KillAllRapers";

			LAi_ActorAfraid(CharacterFromID("Enc_Char1"), CharacterFromID("Enc_Char2"), true);

			LAi_group_FightGroups("ENC_RAPERS_GROUP", LAI_GROUP_PLAYER, false);
		break;

		case "LandEnc_RapersNoFight":

			ChangeCharacterReputation(PChar, -5); // NK - Pchar.reputation = makeint(Pchar.reputation) - 5;

			LAi_ActorAfraid(CharacterFromID("Enc_Char1"), CharacterFromID("Enc_Char2"), true);

			LAi_ActorFollow(CharacterFromID("Enc_Char2"), CharacterFromID("Enc_Char1"), "", -1);
			LAi_ActorFollow(CharacterFromID("Enc_Char3"), CharacterFromID("Enc_Char1"), "", -1);
			LAi_ActorFollow(CharacterFromID("Enc_Char4"), CharacterFromID("Enc_Char1"), "", -1);

		break;

		case "LandEnc_KillAllRapers":
			//Pchar.reputation = makeint(Pchar.reputation) + 5;
			if(AUTO_SKILL_SYSTEM) { AddPartyExpChar(pchar, "Leadership", makeint(Pchar.rank)*100); }
			else { AddPartyExp(pchar, makeint(Pchar.rank)*100); }
			LAi_type_actor_Reset(CharacterFromID("Enc_Char1"));
			Characters[GetCharacterIndex("Enc_Char1")].Dialog.CurrentNode = "ThanksForHelp";
			LAi_ActorDialog(CharacterFromID("Enc_Char1"), Pchar, "", 15, 0);

		break;

//------------------------------------------OFFICER----------------------------------------------------

		case "LandEnc_OfficerHired":
		// This action is still used by the following applications:
		// 		Enc_fort_dialog.c
		// 		Enc_Officer_dialog.c
		// This is NO LONGER used by the following:
		// 		Cabinfight_dialog.c
		// 		Prisoned_dialog.c

			int freeidx = FindFreeRandomOfficer(); // NK do once
			if(freeidx != -1)
			{
				Pchar.quest.FreeRandomOfficerIdx = Characters[freeidx].index;
				Pchar.quest.FreeRandomOfficerID = Characters[makeint(Pchar.quest.FreeRandomOfficerIdx)].id;
				
				trace("Free Random Officer IDX is " + Pchar.quest.FreeRandomOfficerIdx + " and he has id  " + Pchar.quest.FreeRandomOfficerID);
	
				CopyAttributes(&Characters[makeint(Pchar.quest.FreeRandomOfficerIdx)], &Characters[makeint(Pchar.quest.HiringOfficerIDX)]);
				
				Characters[makeint(Pchar.quest.FreeRandomOfficerIdx)].index = Pchar.quest.FreeRandomOfficerIdx;
				Characters[makeint(Pchar.quest.FreeRandomOfficerIdx)].id = Pchar.quest.FreeRandomOfficerID;
// added by MAXIMUS [for placing new officer in empty slot (default for some officers)] -->
				int ofNum = 3;
				switch(Characters[makeint(Pchar.quest.FreeRandomOfficerIdx)].quest.officertype)
				{
					case OFFIC_TYPE_FIRSTMATE: ofNum = 1; break;
					case OFFIC_TYPE_BOATSWAIN: ofNum = 2; break;
					case OFFIC_TYPE_NAVIGATOR: ofNum = 3; break;
				}
				SetOfficersIndex(Pchar, ofNum, makeint(Pchar.quest.FreeRandomOfficerIdx));
// added by MAXIMUS [for placing new officer in empty slot (default for some officers)] <--

				Characters[makeint(Pchar.quest.FreeRandomOfficerIdx)].location = "None";
				
			/*	Pchar.quest.LandEnc_OfficerJoined.win_condition.l1 = "ExitFromLocation";
				Pchar.quest.LandEnc_OfficerJoined.win_condition.l1.location = Pchar.location;
				Pchar.quest.LandEnc_OfficerJoined.win_condition = "LandEnc_OfficerJoined";*/

				// TIH --> move any money they may have into their wealth, so MC cant steal their money Oct31'06
				ref NewOfficer = GetCharacter(sti(Pchar.quest.FreeRandomOfficerIdx));
				// this is copied from the TIH_OfficerHiredProcess function
				// since this questaction has yet to be converted to use that function
				if (CheckAttribute(NewOfficer,"money") && sti(NewOfficer.money) > 0)
				{
					if (!CheckAttribute(NewOfficer,"wealth")) { NewOfficer.wealth = 0; } // set if not set
					NewOfficer.wealth = makeint(sti(NewOfficer.wealth) + sti(NewOfficer.money)); // merge together into wealth
					NewOfficer.money = 0; // clear out their money now that its moved
				}
				// TIH <--

				if(Characters[makeint(Pchar.quest.HiringOfficerIDX)].chr_ai.type==LAI_TYPE_SIT) LAi_Fade("LandEnc_OfficerJoined", "");
				else LAi_QuestDelay("LandEnc_OfficerJoined",0);
			}
			else
			{
				Log_SetStringToLog(QUEST_MESSAGE12);
				DeleteAttribute(Pchar, "quest.FreeRandomOfficerIdx");
				DeleteAttribute(Pchar, "quest.FreeRandomOfficerID");
			}
		break;

		case "LandEnc_OfficerJoined":
			characters[makeint(Pchar.quest.FreeRandomOfficerIdx)].Dialog.CurrentNode = "hired";
			// boal 05.09.03 offecer need to go to abordage -->
			characters[makeint(Pchar.quest.FreeRandomOfficerIdx)].AbordageMode = makeint(1);
			// boal 05.09.03 offecer need to go to abordage <--
			//MAXIMUS: process with random officers, made from citizens, will look realistic -->
			if(Characters[makeint(Pchar.quest.HiringOfficerIDX)].chr_ai.type==LAI_TYPE_SIT)
			{
				ChangeCharacterAddressGroup(&Characters[makeint(Pchar.quest.HiringOfficerIDX)], "None", "", "");
				PlaceCharacter(characterFromID(Pchar.quest.FreeRandomOfficerID), "goto", Pchar.location);
				DialogMain(characterFromID(Pchar.quest.FreeRandomOfficerID)); // added by MAXIMUS
			}
			else
			{
				Characters[makeint(Pchar.quest.HiringOfficerIDX)].location = PChar.location;
				Characters[makeint(Pchar.quest.HiringOfficerIDX)].Dialog.Filename = "";
				Characters[makeint(Pchar.quest.HiringOfficerIDX)].Dialog.CurrentNode = "";
				LAi_group_MoveCharacter(&Characters[makeint(Pchar.quest.HiringOfficerIDX)], LAI_GROUP_PLAYER);
				LAi_SetActorType(&Characters[makeint(Pchar.quest.HiringOfficerIDX)]);
				LAi_ActorRunToLocation(&Characters[makeint(Pchar.quest.HiringOfficerIDX)], "reload", LocatorExitSence(PChar.location, "from", "house"), "none", "", "", "", -1);
			}
			//MAXIMUS: process with random officers, made from citizens, will look realistic <--

			DeleteAttribute(Pchar, "quest.FreeRandomOfficerIdx");
			DeleteAttribute(Pchar, "quest.FreeRandomOfficerID");
			DeleteAttribute(Pchar, "quest.HiringOfficerIDX");
// added by MAXIMUS [for officers icons updates after new officer hire] -->
			PostEvent(EVENT_CHANGE_OFFICERS, 500);//MAXIMUS: officers-icons fixed
// added by MAXIMUS [for officers icons updates after new officer hire] <--
		break;

		case "LandEnc_OfficerFired":
			RemovePassenger(Pchar, &Characters[makeint(Pchar.quest.FiringOfficerIDX)]);			
			LAi_SetCitizenType(&Characters[makeint(Pchar.quest.FiringOfficerIDX)]);
			Characters[makeint(Pchar.quest.FiringOfficerIDX)].Dialog.CurrentNode = "Fired";
			Characters[makeint(Pchar.quest.FiringOfficerIDX)].location = "none";
			
			DeleteAttribute(Pchar, "quest.FiringOfficerIDX");
			BLI_UpdateOfficers();
		break;

		// SA (NK bugfix 04-09-06) -->
		case "LandEnc_OfficerFiredGood":
			RemovePassenger(Pchar, &Characters[makeint(Pchar.quest.FiringOfficerIDX)]);			
			LAi_SetCitizenType(&Characters[makeint(Pchar.quest.FiringOfficerIDX)]);
			Characters[makeint(Pchar.quest.FiringOfficerIDX)].Dialog.CurrentNode = "Departed";
			// Maybe we should change this? But doing so would mean we'd have to keep the slot open...
			Characters[makeint(Pchar.quest.FiringOfficerIDX)].location = "none";
			
			DeleteAttribute(Pchar, "quest.FiringOfficerIDX");
			BLI_UpdateOfficers();
		break;
		// SA <--

		// SA (NK bugfix 04-09-06) -->
		case "LandEnc_OfficerFiredGoodPayed":
			NPChar = GetCharacter(sti(Pchar.quest.FiringOfficerIDX));
			int PayOwed = 0;
			if(CheckAttribute(NPChar,"quest.OfficerPayOwed")) PayOwed += sti(NPChar.quest.OfficerPayOwed);
			if (GetCharacterMoney(PChar) < PayOwed) PayOwed = GetCharacterMoney(PChar);

			AddMoneyToCharacter(Pchar,-PayOwed);
			AddWealthToCharacter(&NPChar, PayOwed);
			NPChar.quest.OfficerPayOwed = 0;

			RemovePassenger(Pchar, &Characters[makeint(Pchar.quest.FiringOfficerIDX)]);			
			LAi_SetCitizenType(&Characters[makeint(Pchar.quest.FiringOfficerIDX)]);
			Characters[makeint(Pchar.quest.FiringOfficerIDX)].Dialog.CurrentNode = "Departed";
			// Maybe we should change this? But doing so would mean we'd have to keep the slot open...
			Characters[makeint(Pchar.quest.FiringOfficerIDX)].location = "none";

			DeleteAttribute(Pchar, "quest.FiringOfficerIDX");
			BLI_UpdateOfficers();
		break;
		// SA <--

		// boal 05.09.03 offecer need to go to abordage -->
		case "Boal_LandEnc_OfficerStay":
			SetCharacterTask_Stay(Characters[makeint(Pchar.quest.HiringOfficerIDX)]);
			DeleteAttribute(Pchar, "quest.HiringOfficerIDX");
		break;
		// boal 05.09.03 offecer need to go to abordage <--

//------------------------------------------END OFFICER------------------------------------------------

		// NK -->
		case "NK_FightMonstersEvent":
			/*LAi_group_FightGroups(LAI_GROUP_MONSTERS, PLAYER_GROUP, false);

			for(int i = 0; i < 32; i++)
			{
				chr = &Characters[LOC_FANTOM_CHARACTERS + i];
				if(!CheckAttribute(chr,"chr_ai.group")) continue;
				if(chr.chr_ai.group == LAI_GROUP_MONSTERS)
				{
					EnableEquip(chr, BLADE_ITEM_TYPE, true);
					EquipCharacterByItem(chr, FindCharacterItemByGroup(chr, BLADE_ITEM_TYPE));
					ExecuteCharacterEquip(chr);
					if(CheckAttribute(chr,"patroltype"))
					{
						LAi_type_patrol_Init(chr);
					}
					LAi_SetWarriorType(chr);
					LAi_warrior_SetStay(chr, true);
				}
			}*/
		break;
		// NK <--

		case "removed_officer_runaway":
			GetCharacterPos(GetMainCharacter(), &locx, &locy, &locz);
			string sorlocator = LAi_FindNearestFreeLocator("reload", locx, locy, locz);
			int remOff = pchar.removed_officer;
			homelocation = characters[remOff].homelocation;
			homegroup = characters[remOff].homelocation.group;
			homelocator = characters[remOff].homelocation.locator;
			LAi_ActorRunToLocation(&characters[remOff], "reload", sorlocator, homelocation, homegroup, homelocator, "removing_officer_comleted", 10.0);
		break;
			
		case "removing_officer_comleted":
			int remOffr = pchar.removed_officer;
			switch (characters[remOffr].homestate)
			{
				case "sit": LAi_SetSitType(&characters[remOffr]); break;
				case "citizen": LAi_SetCitizenType(&characters[remOffr]); break;
			}
			characters[remOffr].dialog.currentnode = "hired_again";
		break;

		case "donation":
// LDH --> 23Sep06 total rewrite, math is identical but simplified and fixed some bugs
			int iDonation = sti(pchar.quest.donate);
			int iRepRank = makeint(pow(sti(PChar.rank),1.25));	// same as makeint(sqrt(sqrt(sti(PChar.rank)^5))) but without overflow problems

			while (iDonation > 0)
			{
				// Determine cost per point of reputation increase
				int iRep = sti(PChar.reputation);
				int iMult = 1;
				if (iabs(45-iRep) > 5)  iMult = 2;
				if (iabs(45-iRep) > 10) iMult = 4;	// original code would not have used this, was a bug I think
				if (iabs(45-iRep) > 15) iMult = 8;
				if (iabs(45-iRep) > 25) iMult = 16;
				int iCost = (iRepRank * 500) * iMult;

				if (iDonation >= iCost) {
					ChangeCharacterReputation(PChar, 9999); // special case for donations, adds 1 without doubling
					iDonation -= iCost;
					if (iDonation == 0) PChar.quest.donate = 0;
				} else {
					PChar.quest.donate = iDonation;	// if there's any left over, save it for next time
					iDonation = 0;		// tell the loop we're done
				}
			}
/*
Cost for raising a character from the lowest rep (1) to the highest (89)
Cost for level 10 is  7,131,500
Cost for level 20 is 17,619,000
Cost for level 30 is 29,365,000
Cost for level 40 is 41,950,000
Cost for level 50 is 55,374,000
*/
// LDH <--
		break;
		
		//GENERATE
		case "generate_trade_quest":
			if (pchar.quest.generate_trade_quest_progress == "begin")
			{
				pchar.quest.generate_trade_quest_progress = "failed";
				Log_SetStringToLog(QUEST_MESSAGE2);
				DoQuestCheckDelay("close_trade_quest", 0.0);
			}
		break;

		case "trade_quest_open":		
			iTradeGoods = sti(pchar.quest.generate_trade_quest.iTradeGoods);
			iQuantityGoods = sti(pchar.quest.generate_trade_quest.iQuantityGoods);
			iTradeNation = sti(pchar.quest.generate_trade_quest.iTradeNation);
			
			//Log_SetStringToLog(iTradeNation);
			
			AddCharacterGoods(pchar, iTradeGoods, iQuantityGoods);
			//задаем квест
			pchar.quest.generate_trade_quest.win_condition.l1 = "Timer";
			pchar.quest.generate_trade_quest.win_condition.l1.date.day = GetAddingDataDay(0, 20, 0);
			pchar.quest.generate_trade_quest.win_condition.l1.date.month = GetAddingDataMonth(0, 20, 0);
			pchar.quest.generate_trade_quest.win_condition.l1.date.year = GetAddingDataYear(0, 20, 0);
			pchar.quest.generate_trade_quest.win_condition = "generate_trade_quest";
			pchar.quest.generate_trade_quest_progress = "begin";

// KK -->
			Preprocessor_AddQuestData("town", GetTownName(GetTownIDFromLocID(pchar.quest.iTradeColony)));
			Preprocessor_AddQuestData("quantity", iQuantityGoods);
			Preprocessor_AddQuestData("cargo", XI_ConvertString(Goods[iTradeGoods].name));
			Preprocessor_AddQuestData("store_owner", GetMyFullName(GetTownStoreOwner(GetTownIDFromLocID(pchar.quest.iTradeColony))));
			DeleteQuestHeader("trade");
			SetQuestHeader("trade");
			AddQuestRecord("trade", 1);
			Preprocessor_Remove("town");
			Preprocessor_Remove("quantity");
			Preprocessor_Remove("cargo");
			Preprocessor_Remove("store_owner");
// <-- KK
		break;
		
		case "close_trade_quest":
			DeleteQuestHeader("trade"); // KK
		break;

		case "prepare_for_convoy_quest":
			iPassenger = rand(3);
			switch (iPassenger)
			{
				case 0: 
					characters[getCharacterIndex("Quest trader")].model = "storeman";
					characters[getCharacterIndex("Quest trader")].headmodel = "h_storeman";
					characters[getCharacterIndex("Quest trader")].faceID = 42;
				break;
				case 1: 
					characters[getCharacterIndex("Quest trader")].model = "storeman2";
					characters[getCharacterIndex("Quest trader")].headmodel = "h_storeman2";
					characters[getCharacterIndex("Quest trader")].faceID = 43;
				break;
				case 2: 
					characters[getCharacterIndex("Quest trader")].model = "old_man1";
					characters[getCharacterIndex("Quest trader")].headmodel = "h_old_man1";
					characters[getCharacterIndex("Quest trader")].faceID = 32;
				break;
				case 3: 
					characters[getCharacterIndex("Quest trader")].model = "old_man2";
					characters[getCharacterIndex("Quest trader")].headmodel = "h_old_man2";
					characters[getCharacterIndex("Quest trader")].faceID = 33;
				break;
			}			
			homelocation = pchar.location;
			ChangeCharacterAddressGroup(characterFromID("Quest trader"), homelocation, "reload", "reload1");
			//PlaceCharacter(characterFromID("Quest trader"), "reload", homelocation);
			iPassenger = rand(5);
			if (iPassenger == 3) { iPassenger = 4; }
			characters[GetCharacterIndex("quest trader")].nation = iPassenger;
			pchar.quest.generate_convoy_quest_progress = "begin";
			LAi_SetActorType(characterFromID("Quest trader"));
			LAi_SetActorType(pchar);
			LAi_ActorFollow(pchar, characterFromID("quest trader"), "", 5.0);
			LAi_ActorFollow(characterFromID("quest trader"), pchar, "prepare_for_convoy_quest_2", 5.0);
		break;
		
		case "prepare_for_convoy_quest_2":
			LAi_SetPlayerType(pchar);
			LAi_ActorDialog(characterFromID("Quest trader"), pchar, "", 10.0, 1.0);
			characters[GetCharacterIndex("quest trader")].dialog.currentnode = "prepare_convoy_quest";
		break;
		
		case "convoy_refused":
			pchar.quest.generate_convoy_quest.over = "yes";
			pchar.quest.generate_convoy_quest_failed.over = "yes";
			pchar.quest.generate_convoy_quest_completed.over = "yes";
			GetCharacterPos(GetMainCharacter(), &locx, &locy, &locz);
			homelocator = LAi_FindNearestFreeLocator("reload", locx, locy, locz);
			LAi_SetActorType(characterFromID("quest trader"));
			LAi_ActorGoToLocation(characterFromID("quest trader"), "reload", homelocator, "none", "", "", "", 10.0);
		
			if (checkquestattribute("generate_convoy_quest_progress", "completed"))
			{
				iPassenger = makeint(pchar.quest.generate_convoy_quest.convoymoney) + makeint(pchar.rank)*100;
				if(AUTO_SKILL_SYSTEM) { AddPartyExpChar(pchar, "Commerce", iPassenger); }
				else { AddPartyExp(pchar, iPassenger); }
				iPassenger = makeint(pchar.quest.generate_convoy_quest.convoymoney);
				AddMoneyToCharacter(pchar, iPassenger);
				ChangeCharacterReputation(pchar, 1);
				RemoveCharacterCompanion(Pchar, characterFromID("quest trader"));
				pchar.quest.generate_convoy_quest_progress = "";
			}
			if (!checkquestattribute("generate_convoy_quest_progress", "begin"))
			{
				DeleteQuestHeader("convoy"); // KK
			}
			pchar.quest.generate_convoy_quest_progress = "";
		break;
		
		case "generate_convoy_quest":
			ChangeCharacterReputation(pchar, -3);
			DoQuestCheckDelay("convoy_failed", 0.0);
		break;
		
		case "generate_convoy_quest_failed":
			ChangeCharacterReputation(pchar, -5);
			DoQuestCheckDelay("convoy_failed", 0.0);
		break;
		
		case "convoy_failed":
			RemoveCharacterCompanion(Pchar, characterFromID("quest trader"));
			pchar.quest.generate_convoy_quest_progress = "";
			pchar.quest.generate_convoy_quest.over = "yes";
			pchar.quest.generate_convoy_quest_failed.over = "yes";
			pchar.quest.generate_convoy_quest_completed.over = "yes";
			if (!CheckAttribute(pchar, "quest.generate_convoy_quest.storm") && !CheckAttribute(pchar, "quest.generate_convoy_quest.board") && !CheckAttribute(pchar, "quest.generate_convoy_quest.attack")) 
				AddQuestRecord("convoy", 5);
			if (CheckAttribute(pchar, "quest.generate_convoy_quest.storm")) {
				AddQuestRecord("convoy", 2);
				DeleteAttribute(pchar, "quest.generate_convoy_quest.storm");
			}
			if (CheckAttribute(pchar, "quest.generate_convoy_quest.board")) {
				AddQuestRecord("convoy", 3);
				DeleteAttribute(pchar, "quest.generate_convoy_quest.board");
			}
			if (CheckAttribute(pchar, "quest.generate_convoy_quest.attack")) { // KK -->
				Preprocessor_AddQuestData("attacker", pchar.quest.generate_convoy_quest_failed.attack);
				AddQuestRecord("convoy", 4);
				Preprocessor_Remove("attacker"); // <-- KK
				DeleteAttribute(pchar,"quest.generate_convoy_quest.attack");
			}
			CloseQuestHeader("convoy");
		break;
		
		case "generate_convoy_quest_completed":
			homelocation = pchar.location;
			PlaceCharacter(characterFromID("quest trader"), "goto", homelocation); // TIH doing it this way may cause traders to not show up on some ports?
//			ChangeCharacterAddressGroup(characterFromID("quest trader"), homelocation, "officers", pchar.location.locator + "_" + GetCompanionNumber(PChar, GetCharacterIndex("quest trader"))); // KK
			LAi_SetActorType(characterFromID("quest trader"));
			LAi_SetActorType(pchar);
			LAi_ActorFollow(pchar, characterFromID("quest trader"), "", -1);
			LAi_ActorFollow(characterFromID("quest trader"), pchar, "generate_convoy_quest_completed_2", -1);
		break;
		
		case "generate_convoy_quest_completed_2":
			LAi_type_actor_Reset(pchar);
			LAi_ActorWaitDialog(pchar, characterFromID("quest trader"));
			LAi_ActorDialog(characterFromID("quest trader"), pchar, "pchar_back_to_player", 2.0, 1.0);
			characters[GetCharacterIndex("quest trader")].dialog.currentnode = "complete_convoy_quest";
			pchar.quest.generate_convoy_quest_progress = "completed";
		break;
		
		case "convoy_agreeded":
			SetCompanionIndex(Pchar, -1, GetCharacterIndex("quest trader"));
			SetCharacterRemovable(characterFromID("quest trader"), false);
			
			GetCharacterPos(GetMainCharacter(), &locx, &locy, &locz);
			homelocator = LAi_FindNearestFreeLocator("reload", locx, locy, locz);
			LAi_SetActorType(characterFromID("quest trader"));
			LAi_ActorGoToLocation(characterFromID("quest trader"), "reload", LocatorExitSence(PChar.location, "from", "house"), "none", "", "", "", -1);
			
			string sdest = "";
			string sIsland = pchar.quest.generate_convoy_quest.island;
			string sDestin = XI_ConvertString("seaport");
			for(int di=sti(Locations[0].IslandsList.(sIsland).begin); di<sti(Locations[0].IslandsList.(sIsland).end); di++)
			{
				if(CheckAttribute(&locations[di],"townsack") && locations[di].townsack==pchar.quest.generate_convoy_quest.destination)
				{
					if(CheckAttribute(&locations[di],"id") && HasSubStr(locations[di].id,"port"))
					{
						sdest = locations[di].id;
						break;
					}
				}
				else
				{
					switch(sIsland)
					{
						case DEFAULT_TRADEISLAND: sdest = "Conceicao_shore_02"; break;
					}
					if(sdest!="") break;
				}
			}

			if(FindLocation(sdest)!=-1) sDestin = TranslateString("",locations[FindLocation(sdest)].id.label);
			if(sIsland!="Conceicao" && !HasSubStr(sDestin,XI_ConvertString("SeaPort")))
			{
				sDestin = TranslateString(pchar.quest.generate_convoy_quest.destination, "SeaPort");
			}

			/*DeleteQuestHeader("convoy");
			SetQuestHeader("convoy");
			AddQuestRecord("convoy", "1");
			AddQuestDataHeader("convoy", "island", TranslateString("",sIsland));
			AddQuestDataText("convoy", "1", "island", TranslateString("",sIsland));
			AddQuestDataText("convoy", "1", "money", pchar.quest.generate_convoy_quest.convoymoney);
			AddQuestDataText("convoy", "1", "destination", sDestin);*/
// KK -->
			Preprocessor_AddQuestData("town", GetTownName(pchar.quest.generate_convoy_quest.destination));
			Preprocessor_AddQuestData("nation", XI_ConvertString(GetNationDescByType(GetTownNation(pchar.quest.generate_convoy_quest.destination))));
			Preprocessor_AddQuestData("destination", GetTownName(pchar.quest.generate_convoy_quest.destination) + " " + XI_ConvertString("onisland") + " " + XI_ConvertString(GetIslandIDFromTown(pchar.quest.generate_convoy_quest.destination)));
			SetQuestHeader("convoy");
			AddQuestRecord("convoy", 1);
			Preprocessor_Remove("town");
			Preprocessor_Remove("nation");
			Preprocessor_Remove("destination");
			character_SetCompanionEnemyEnable(characterFromID("quest trader"), true);
			pchar.quest.generate_convoy_quest_completed.win_condition.l1 = "Location";
			pchar.quest.generate_convoy_quest_completed.win_condition.l1.location = sDest;
			pchar.quest.generate_convoy_quest_completed.win_condition = "generate_convoy_quest_completed";
		break;
		
		case "prepare_gen_convoy_quest":
			GenerateConvoyQuest();
			characters[GetCharacterIndex("quest trader")].dialog.currentnode = "prepare_convoy_quest_4";
			LAi_ActorDialog(characterfromID("quest trader"), pchar, "", 1.0, 1.0);
		break;

//boal -->
		case "kill_pirate_agree":
			pchar.quest.prepare_for_kill_pirate.win_condition.l1 = "location";
			pchar.quest.prepare_for_kill_pirate.win_condition.l1.location = pchar.quest.generate_kill_quest.destination;
			pchar.quest.prepare_for_kill_pirate.win_condition = "prepare_for_kill_pirate";
			pchar.quest.prepare_for_kill_pirate.town = GetCurrentTownID();
			//завод книги
			//Log_SetStringToLog("kill_pirate_agree");
// KK -->
			Preprocessor_AddQuestData("island", TranslateString("", FindIslandName(pchar.quest.generate_kill_quest.destination)));
			Preprocessor_AddQuestData("ship_descr", GetShipDescribe("Quest pirate", true, true, true, true));
			SetQuestHeader("hunting");
			AddQuestRecord("hunting", 1);
			Preprocessor_Remove("island");
			Preprocessor_Remove("ship_descr");
// <-- KK
		break;

		case "prepare_for_kill_pirate":
			//NK, use fantom calls way up top.
			Group_AddCharacter("Story_Pirate", "Quest pirate");
			//Log_SetStringToLog("prepare_for_kill_pirate");
			Group_SetGroupCommander("Story_Pirate", "Quest pirate");
			Group_SetTaskAttack("Story_Pirate", PLAYER_GROUP);
			//Group_SetAddress("Story_Pirate", Characters[GetMainCharacterIndex()].location, "Quest_ships", "Quest_ship_3");
			Group_SetAddress("Story_Pirate", Pchar.location, "Quest_ships", "Quest_ship_12");

			Group_LockTask("Story_Pirate");

			pchar.quest.kill_pirate_complete.win_condition.l1 = "NPC_Death";
			pchar.quest.kill_pirate_complete.win_condition.l1.character = "Quest pirate";
			pchar.quest.kill_pirate_complete.win_condition = "kill_pirate_complete";
		break;

		case "kill_pirate_complete":
			if(!CheckAttribute(pchar,"quest.generate_kill_quest")) break;//MAXIMUS
			if(pchar.quest.generate_kill_quest=="completed") break;//MAXIMUS
			pchar.quest.generate_kill_quest = "completed";
// KK -->
			if (sti(Pchar.quest.generate_kill_quest.nation) == PIRATE)
				Preprocessor_AddQuestData("type", XI_ConvertString("1Pirate"));
			else
				Preprocessor_AddQuestData("type", XI_ConvertString(GetNationDescByType(sti(pchar.quest.generate_kill_quest.nation))) + " " + XI_ConvertString("Corsair"));
			cc = 0;
			for (iColony = 1; iColony <= GetIslandTownsQuantity(pchar.quest.generate_kill_quest.destination); iColony++) {
				if (GetTownGovernorIndex(GetTownIDFromIsland(pchar.quest.generate_kill_quest.destination, iColony)) != -1) cc++;
			}
			if (cc > 1)
				Preprocessor_AddQuestData("town", GetTownName(PChar.quest.generate_kill_quest.town) + " " + TranslateString("", "on") + " " + FindIslandName(pchar.quest.generate_kill_quest.destination));
			else
				Preprocessor_AddQuestData("town", GetTownName(PChar.quest.generate_kill_quest.town));
			Preprocessor_AddQuestData("ship_descr", GetShipDescribe("Quest pirate", true, true, true, true));
			AddQuestRecord("hunting", rand(4) + 2);
			Preprocessor_Remove("type");
			Preprocessor_Remove("town");
			Preprocessor_Remove("ship_descr");
// <-- KK
		break;

		case "kill_pirate_refused":
			pchar.quest.kill_pirate_refused_timer.win_condition.l1 = "Timer";
			pchar.quest.kill_pirate_refused_timer.win_condition.l1.date.day = GetAddingDataDay(0, 0, 3);
			pchar.quest.kill_pirate_refused_timer.win_condition.l1.date.month = GetAddingDataMonth(0, 0, 3);
			pchar.quest.kill_pirate_refused_timer.win_condition.l1.date.year = GetAddingDataYear(0, 0, 3);
			pchar.quest.generate_cokill_pirate_refused_timernvoy_quest.win_condition = "kill_pirate_refused_timer";
		break;
		
		case "kill_pirate_refused_2":	
			//Log_SetStringToLog("kill_pirate_refused_2");	
			pchar.quest.kill_pirate_refused_timer.win_condition.l1 = "Timer";
			pchar.quest.kill_pirate_refused_timer.win_condition.l1.date.day = GetAddingDataDay(0, 0, 3);
			pchar.quest.kill_pirate_refused_timer.win_condition.l1.date.month = GetAddingDataMonth(0, 0, 3);
			pchar.quest.kill_pirate_refused_timer.win_condition.l1.date.year = GetAddingDataYear(0, 0, 3);
			pchar.quest.generate_cokill_pirate_refused_timernvoy_quest.win_condition = "kill_pirate_refused_timer";
			DeleteQuestHeader("hunting");
			DeleteQuestAttribute("hunting");
		break;

		case "kill_pirate_refused_timer":
			//Log_SetStringToLog("kill_pirate_refused_timer");
			DeleteAttribute(pchar, "quest.generate_kill_quest");
			//pchar.quest.generate_kill_quest = "";
		break;
// boal <--

		case "sleep_in_tavern":
//			RecalculateJumpTable();
//			DoQuestReloadToLocation(pchar.location + "_upstairs", "goto", "goto2", "restore_hp");
			string roomName = pchar.location;//MAXIMUS -->
			aref cLoctr; makearef(cLoctr,locations[FindLocation(pchar.location)].reload);
			for(int h=0; h<GetAttributesNum(cLoctr); h++)
			{
				aref curItem = GetAttributeN(cLoctr,h);
				string attrName = GetAttributeName(curItem);
				if(CheckAttribute(cLoctr,attrName+".go"))
				{
					if(HasSubStr(cLoctr.(attrName).go,"_upstairs") || HasSubStr(cLoctr.(attrName).go,"_bedroom")) roomName = cLoctr.(attrName).go;
				}
			}
			DoQuestReloadToLocation(roomName, "goto", "goto2", "restore_hp");//MAXIMUS <--
		break;

		case "restore_hp":
			int iOfficer;
			LAi_SetCurHPMax(pchar);
			for (int i=1; i<4; i++)
			{
				if (GetOfficersIndex(Pchar, i) != -1)
				{
					iOfficer = GetOfficersIndex(Pchar, i);
					LAi_SetCurHPMax(&characters[iOfficer]);
				}
			}			
		break;

		case "drink_talk_with_soldier":
			tavernfriend = pchar.quest.friend_in_tavern;
			LAi_SetSitType(characterFromID(tavernfriend));
			switch(pchar.location)
			{
				case "Redmond_tavern":
					LAi_SetHP(characterFromID("Redmond soldier"), 80.0, 80.0);
					ChangeCharacterAddress(characterFromID("Redmond Soldier"), "Redmond_town_01", "cityzen9");
					DoQuestReloadToLocation("Redmond_town_01", "goto", "goto12", "drink_speak_with_soldier");
					LAi_group_MoveCharacter(characterFromID("Redmond Soldier"), "ENGLAND_SOLDIERS");
					pchar.friend_in_tavern2 = "ENGLAND_SOLDIERS";
				break;

				case "Oxbay_tavern":
					LAi_SetHP(characterFromID("Oxbay soldier"), 80.0, 80.0);
					ChangeCharacterAddress(characterFromID("Oxbay Soldier"), "Oxbay_town", "goto37");
					DoQuestReloadToLocation("Oxbay_town", "goto", "goto36", "drink_speak_with_soldier");
					LAi_group_MoveCharacter(characterFromID("Oxbay Soldier"), "ENGLAND_SOLDIERS");
					pchar.friend_in_tavern2 = "ENGLAND_SOLDIERS";
				break;

				case "Greenford_tavern":
					LAi_SetHP(characterFromID("Greenford soldier"), 80.0, 80.0);
					ChangeCharacterAddress(characterFromID("Greenford Soldier"), "Greenford_town", "goto9");
					DoQuestReloadToLocation("Greenford_town", "goto", "goto14", "drink_speak_with_soldier");
					LAi_group_MoveCharacter(characterFromID("Greenford Soldier"), "ENGLAND_SOLDIERS");
					pchar.friend_in_tavern2 = "ENGLAND_SOLDIERS";
				break;

				case "Falaise_De_Fleur_tavern":
					LAi_SetHP(characterFromID("Falaise de Fleur soldier"), 80.0, 80.0);
					ChangeCharacterAddress(characterFromID("Falaise De Fleur Soldier"), "Falaise_de_fleur_location_03", "locator12");
					DoQuestReloadToLocation("Falaise_De_fleur_location_03", "goto", "locator11", "drink_speak_with_soldier");
					LAi_group_MoveCharacter(characterFromID("Falaise De Fleur Soldier"), "FRANCE_SOLDIERS");
					pchar.friend_in_tavern2 = "FRANCE_SOLDIERS";
				break;

				case "Muelle_tavern":
					LAi_SetHP(characterFromID("Muelle soldier"), 80.0, 80.0);
					ChangeCharacterAddress(characterFromID("Muelle Soldier"), "Muelle_town_01", "goto23");
					DoQuestReloadToLocation("Muelle_town_01", "goto", "goto100", "drink_speak_with_soldier");
					LAi_group_MoveCharacter(characterFromID("Muelle Soldier"), "SPAIN_SOLDIERS");
					pchar.friend_in_tavern2 = "SPAIN_SOLDIERS";
				break;

				case "Douwesen_tavern":
					LAi_SetHP(characterFromID("Douwesen soldier"), 80.0, 80.0);
					ChangeCharacterAddress(characterFromID("Douwesen Soldier"), "Douwesen_town", "goto3");
					DoQuestReloadToLocation("Douwesen_town", "goto", "goto5", "drink_speak_with_soldier");
					LAi_group_MoveCharacter(characterFromID("DOuwesen Soldier"), "DOUWESEN_SOLDIERS");
					pchar.friend_in_tavern2 = "DOUWESEN_SOLDIERS";
				break;

				case "Pirate_tavern":
					LAi_SetHP(characterFromID("Pirate soldier"), 80.0, 80.0);
					ChangeCharacterAddress(characterFromID("Pirate Soldier"), "Pirate_fort", "character9");
					DoQuestReloadToLocation("Pirate_fort", "goto", "character10", "drink_speak_with_soldier");
					LAi_group_MoveCharacter(characterFromID("Pirate Soldier"), "PIRATE_SOLDIERS");
					pchar.friend_in_tavern2 = "PIRATE_SOLDIERS";
				break;

				case "Conceicao_tavern":
					LAi_SetHP(characterFromID("Conceicao soldier"), 80.0, 80.0);
					ChangeCharacterAddress(characterFromID("Conceicao Soldier"), "Conceicao_town", "goto5");
					DoQuestReloadToLocation("Conceicao_town", "goto", "goto4", "drink_speak_with_soldier");
					LAi_group_MoveCharacter(characterFromID("Conceicao Soldier"), "CONCEICAO_SOLDIERS");
					pchar.friend_in_tavern2 = "CONCEICAO_SOLDIERS";
				break;

				case "Smugglers_tavern":
					LAi_SetHP(characterFromID("Smugglers soldier"), 80.0, 80.0);
					ChangeCharacterAddress(characterFromID("Smugglers Soldier"), "Smugglers_lair", "goto12");
					DoQuestReloadToLocation("Smugglers_lair", "goto", "goto11", "drink_speak_with_soldier");
					LAi_group_MoveCharacter(characterFromID("Smugglers Soldier"), "SMUGGLER_SOLDIERS");
					pchar.friend_in_tavern2 = "SMUGGLER_SOLDIERS";
				break;

				case "QC_tavern":
					LAi_SetHP(characterFromID("QC soldier"), 80.0, 80.0);
					DoQuestReloadToLocation("QC_town", "goto", "character4", "drink_speak_with_soldier");
					LAi_group_MoveCharacter(characterFromID("QC Soldier"), "QC_SOLDIERS");
					pchar.friend_in_tavern2 = "QC_SOLDIERS";
				break;

				case "QC_brothel"://<<<<-------------------------------------------------------------------added here, love verruckt
					LAi_SetHP(characterFromID("QC soldier"), 80.0, 80.0);
					DoQuestReloadToLocation("QC_town", "goto", "character4", "drink_speak_with_soldier");
					LAi_group_MoveCharacter(characterFromID("QC Soldier"), "QC_SOLDIERS");
					pchar.friend_in_tavern2 = "QC_SOLDIERS";
				break;
			}
		break;

		case "drink_speak_with_soldier":
			LAi_SetActorType(pchar);
			switch(pchar.location)
			{
				case "Redmond_town_01":
					characters[GetCharacterIndex("Redmond soldier")].dialog.currentnode = "drink";
					LAi_ActorDialog(pchar, characterFromID("Redmond soldier"), "pchar_back_to_player", 5.0, 1.0);
				break;

				case "Oxbay_town":
					characters[GetCharacterIndex("Oxbay soldier")].dialog.currentnode = "drink";
					LAi_ActorDialog(pchar, characterFromID("Oxbay Soldier"), "pchar_back_to_player", 5.0, 1.0);
				break;

				case "Greenford_town":
					characters[GetCharacterIndex("Greenford soldier")].dialog.currentnode = "drink";
					LAi_ActorDialog(pchar, characterFromID("Greenford soldier"), "pchar_back_to_player", 5.0, 1.0);
				break;

				case "Falaise_De_Fleur_town":
					characters[GetCharacterIndex("Falaise De Fleur soldier")].dialog.currentnode = "drink";
					LAi_ActorDialog(pchar, characterFromID("Falaise De Fleur soldier"), "pchar_back_to_player", 5.0, 1.0);
				break;

				case "Muelle_town_01":
					characters[GetCharacterIndex("Muelle soldier")].dialog.currentnode = "drink";
					LAi_ActorDialog(pchar, characterFromID("Muelle soldier"), "pchar_back_to_player", 5.0, 1.0);
				break;

				case "Douwesen_town":
					characters[GetCharacterIndex("Douwesen Soldier")].dialog.currentnode = "drink";
					LAi_ActorDialog(pchar, characterFromID("Douwesen Soldier"), "pchar_back_to_player", 5.0, 1.0);
				break;

				case "Pirate_town":
					characters[GetCharacterIndex("Pirate Soldier")].dialog.currentnode = "drink";
					LAi_ActorDialog(pchar, characterFromID("Pirate Soldier"), "pchar_back_to_player", 5.0, 1.0);
				break;

				case "Conceicao_town":
					characters[GetCharacterIndex("Conceicao Soldier")].dialog.currentnode = "drink";
					LAi_ActorDialog(pchar, characterFromID("Conceicao Soldier"), "pchar_back_to_player", 5.0, 1.0);
				break;

				case "Smugglers_town":
					characters[GetCharacterIndex("Smugglers Soldier")].dialog.currentnode = "drink";
					LAi_ActorDialog(pchar, characterFromID("Smugglers Soldier"), "pchar_back_to_player", 5.0, 1.0);
				break;

				case "QC_town":
					PlaceCharacter(characterFromID("QC Soldier"), "goto", "QC_town");
					characters[GetCharacterIndex("QC Soldier")].dialog.currentnode = "drink";
					LAi_ActorDialog(pchar, characterFromID("QC Soldier"), "pchar_back_to_player", 5.0, 1.0);
				break;
			}
		break;

		case "without_memory":
			LAi_Fade("exit_sit_2", "saved_by_off");
		break;

		case "drink_fight_in_tavern_with_fantoms":
			LAi_Fade("exit_sit_2", "fighting2");
		break;

		case "fighting":
			/*NK*/ sld = LAi_CreateFantomCharacter(false, 0, true, true, 0.25, "man1", "reload", "reload1");
			sld.headmodel = "h_man1";
			sld.dialog.filename = "tavern fightingman_dialog.c";
			
			LAi_SetActorType(sld);
			LAi_group_MoveCharacter(sld, "TAVERN_FIGHTER");
			LAi_ActorDialogNow(sld, pchar, "", -1);
		break;

		case "fighting2":
			locCameraFollow();
			LAi_SetSitType(characterFromID(pchar.quest.friend_in_tavern));
			LAi_SetPlayerType(pchar);
			LAi_LocationFightDisable(&Locations[FindLocation(pchar.location)], false); 
		
			LAi_group_FightGroups("TAVERN_FIGHTER", LAI_GROUP_PLAYER, true);
			LAi_group_SetCheck("TAVERN_FIGHTER", "kill_tavern_fightman_complete");
		break;

		case "saved_by_off":
			LAi_SetStayType(pchar);
			AddMoneyToCharacter(pchar, -100);
			homelocation = pchar.location;
			switch(homelocation)
			{
				case "Redmond_tavern":
					PlaceCharacter(characterFromID("Redmond_officiant"), "goto", homelocation);
					characters[GetCharacterIndex("Redmond_officiant")].dialog.currentnode = "without_money";
					LAi_SetActorType(characterFromID("Redmond_officiant"));
					LAi_ActorDialog(characterFromID("Redmond_officiant"), pchar, "officiant_back_to_citizen", 5.0, 1.0);
				break;

				case "Oxbay_tavern":
					PlaceCharacter(characterFromID("Oxbay_officiant"), "goto", homelocation);
					characters[GetCharacterIndex("Oxbay_officiant")].dialog.currentnode = "without_money";
					LAi_SetActorType(characterFromID("Oxbay_officiant"));
					LAi_ActorDialog(characterFromID("Oxbay_officiant"), pchar, "officiant_back_to_citizen", 5.0, 1.0);
				break;

				case "Greenford_tavern":
					PlaceCharacter(characterFromID("Greenford_officiant"), "goto", homelocation);
					characters[GetCharacterIndex("Greenford_officiant")].dialog.currentnode = "without_money";
					LAi_SetActorType(characterFromID("Greenford_officiant"));
					LAi_ActorDialog(characterFromID("Greenford_officiant"), pchar, "officiant_back_to_citizen", 5.0, 1.0);
				break;

				case "Falaise_De_Fleur_tavern":
					PlaceCharacter(characterFromID("Falaise_De_Fleur_officiant"), "goto", homelocation);
					characters[GetCharacterIndex("Falaise_De_Fleur_officiant")].dialog.currentnode = "without_money";
					LAi_SetActorType(characterFromID("Falaise_De_fleur_officiant"));
					LAi_ActorDialog(characterFromID("Falaise_de_fleur_officiant"), pchar, "officiant_back_to_citizen", 5.0, 1.0);
				break;

				case "Muelle_tavern":
					PlaceCharacter(characterFromID("Muelle_officiant"), "goto", homelocation);
					characters[GetCharacterIndex("Muelle_officiant")].dialog.currentnode = "without_money";
					LAi_SetActorType(characterFromID("Muelle_officiant"));
					LAi_ActorDialog(characterFromID("Muelle_officiant"), pchar, "officiant_back_to_citizen", 5.0, 1.0);
				break;

				case "Douwesen_tavern":
					PlaceCharacter(characterFromID("Douwesen_officiant"), "goto", homelocation);
					characters[GetCharacterIndex("Douwesen_officiant")].dialog.currentnode = "without_money";
					LAi_SetActorType(characterFromID("Douwesen_officiant"));
					LAi_ActorDialog(characterFromID("Douwesen_officiant"), pchar, "officiant_back_to_citizen", 5.0, 1.0);
				break;

				case "Pirate_tavern":
					PlaceCharacter(characterFromID("Pirate_officiant"), "goto", homelocation);
					characters[GetCharacterIndex("Pirate_officiant")].dialog.currentnode = "without_money";
					LAi_SetActorType(characterFromID("Pirate_officiant"));
					LAi_ActorDialog(characterFromID("Pirate_officiant"), pchar, "officiant_back_to_citizen", 5.0, 1.0);
				break;

				case "Conceicao_tavern":
					PlaceCharacter(characterFromID("Conceicao_officiant"), "goto", homelocation);
					characters[GetCharacterIndex("Conceicao_officiant")].dialog.currentnode = "without_money";
					LAi_SetActorType(characterFromID("Conceicao_officiant"));
					LAi_ActorDialog(characterFromID("Conceicao_officiant"), pchar, "officiant_back_to_citizen", 5.0, 1.0);
				break;

				case "Smugglers_tavern":
					PlaceCharacter(characterFromID("Smugglers_officiant"), "goto", homelocation);
					characters[GetCharacterIndex("Smugglers_officiant")].dialog.currentnode = "without_money";
					LAi_SetActorType(characterFromID("Smugglers_officiant"));
					LAi_ActorDialog(characterFromID("Smugglers_officiant"), pchar, "officiant_back_to_citizen", 5.0, 1.0);
				break;

				case "QC_tavern":
					PlaceCharacter(characterFromID("QC_officiant"), "goto", homelocation);
					characters[GetCharacterIndex("QC_officiant")].dialog.currentnode = "without_money";
					LAi_SetActorType(characterFromID("QC_officiant"));
					LAi_ActorDialog(characterFromID("QC_officiant"), pchar, "officiant_back_to_citizen", 5.0, 1.0);
				break;

				case "QC_brothel"://<<<----------------------------------------------------------------Added here, love verruckt
					PlaceCharacter(characterFromID("wench2"), "goto", homelocation);
					characters[GetCharacterIndex("wench2")].dialog.currentnode = "without_money";
					LAi_SetActorType(characterFromID("wench2"));
					LAi_ActorDialog(characterFromID("wench2"), pchar, "officiant_back_to_citizen", 5.0, 1.0);
				break;
			}
		break;

		case "officiant_back_to_citizen":
			LAi_SetPlayerType(pchar);
			AddMoneyToCharacter(pchar, -100);
			switch(pchar.location)
			{
				case "Redmond_tavern":
					LAi_SetWaitressType(characterFromID("Redmond_officiant"));
					LAi_group_MoveCharacter(characterFromID("Redmond_officiant"), "ENGLAND_CITIZENS");
				break;

				case "Oxbay_tavern":
					LAi_SetWaitressType(characterFromID("Oxbay_officiant"));
					LAi_group_MoveCharacter(characterFromID("Oxbay_officiant"), "ENGLAND_CITIZENS");
				break;

				case "Greenford_tavern":
					LAi_SetWaitressType(characterFromID("Greenford_officiant"));
					LAi_group_MoveCharacter(characterFromID("Greenford_officiant"), "ENGLAND_CITIZENS");
				break;

				case "Falaise_De_Fleur_tavern":
					LAi_SetWaitressType(characterFromID("Falaise_De_fleur_officiant"));
					LAi_group_MoveCharacter(characterFromID("Falaise_De_fleur_officiant"), "FRANCE_CITIZENS");
				break;

				case "Muelle_tavern":
					LAi_SetWaitressType(characterFromID("Muelle_officiant"));
					LAi_group_MoveCharacter(characterFromID("Muelle_officiant"), "SPAIN_CITIZENS");
				break;

				case "Douwesen_tavern":
					LAi_SetWaitressType(characterFromID("Douwesen_officiant"));
					LAi_group_MoveCharacter(characterFromID("Douwesen_officiant"), "DOUWESEN_CITIZENS");
				break;

				case "Pirate_tavern":
					LAi_SetWaitressType(characterFromID("Pirate_officiant"));
					LAi_group_MoveCharacter(characterFromID("Pirate_officiant"), "DOUWESEN_PIRATE_CITIZENS");
				break;

				case "Conceicao_tavern":
					LAi_SetWaitressType(characterFromID("Conceicao_officiant"));
					LAi_group_MoveCharacter(characterFromID("Conceicao_officiant"), "CONCEICAO_CITIZENS");
				break;

				case "Smugglers_tavern":
					LAi_SetWaitressType(characterFromID("Smugglers_officiant"));
					LAi_group_MoveCharacter(characterFromID("Smugglers_officiant"), "SMUGGLERS_CITIZENS");
				break;

				case "QC_tavern":
					LAi_SetWaitressType(characterFromID("QC_officiant"));
					LAi_group_MoveCharacter(characterFromID("QC_officiant"), "QC_CITIZENS");
				break;

				case "QC_brothel"://<<------------------------------------------------------------------Added here, Love Verruckt
					LAi_SetWaitressType(characterFromID("wench2"));
					LAi_group_MoveCharacter(characterFromID("wench2"), "QC_CITIZENS");
				break;
			}
		break;

		case "alc":
			LAi_Fade("alc_2_prepare", "alc2");
		break;

		case "alc_2_prepare":
			LAi_SetSitType(pchar);
			LAi_SetActorType(characterFromID(pchar.quest.friend_in_tavern));
			LAi_ActorSetSitMode(characterFromID(pchar.quest.friend_in_tavern));
			
			switch(pchar.location)
			{
				case "Redmond_tavern":
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit1")		
					{
						ChangeCharacterAddressGroup(pchar, "redmond_tavern", "sit", "sit11");
					}
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit3")		
					{
						ChangeCharacterAddressGroup(pchar, "redmond_tavern", "sit", "sit2");
					}
				break;

				case "Oxbay_tavern":
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit1")		
					{
						ChangeCharacterAddressGroup(pchar, "oxbay_tavern", "sit", "sit11");
					}
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit3")		
					{
						ChangeCharacterAddressGroup(pchar, "oxbay_tavern", "sit", "sit2");
					}
				break;

				case "Greenford_tavern":
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit5")		
					{
						ChangeCharacterAddressGroup(pchar, "greenford_tavern", "sit", "sit6");
					}
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit1")		
					{
						ChangeCharacterAddressGroup(pchar, "greenford_tavern", "sit", "sit2");
					}	
				break;

				case "Falaise_De_Fleur_tavern":
							
				break;

				case "Muelle_tavern":
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit1")		
					{
						ChangeCharacterAddressGroup(pchar, "muelle_tavern", "sit", "sit2");
					}
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit7")		
					{
						ChangeCharacterAddressGroup(pchar, "muelle_tavern", "sit", "sit3");
					}			
				break;

				case "Douwesen_tavern":
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit1")		
					{
						ChangeCharacterAddressGroup(pchar, "douwesen_tavern", "sit", "sit2");
					}
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit7")		
					{
						ChangeCharacterAddressGroup(pchar, "douwesen_tavern", "sit", "sit3");
					}		
				break;

				case "Pirate_tavern":
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit1")		
					{
						ChangeCharacterAddressGroup(pchar, "pirate_tavern", "sit", "sit2");
					}
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit4")		
					{
						ChangeCharacterAddressGroup(pchar, "pirate_tavern", "sit", "sit2");
					}		
				break;

				case "Conceicao_tavern":
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit1")		
					{
						ChangeCharacterAddressGroup(pchar, "conceicao_tavern", "sit", "sit2");
					}
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit7")		
					{
						ChangeCharacterAddressGroup(pchar, "conceicao_tavern", "sit", "sit3");
					}
				break;

				case "Smugglers_tavern":
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit5")		
					{
						ChangeCharacterAddressGroup(pchar, "smugglers_tavern", "sit", "sit6");
					}
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit4")		
					{
						ChangeCharacterAddressGroup(pchar, "smugglers_tavern", "sit", "sit3");
					}	
				break;

				case "QC_tavern":
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit1")
					{
						ChangeCharacterAddressGroup(pchar, "QC_tavern", "sit", "sit2");
					}
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit3")
					{
						ChangeCharacterAddressGroup(pchar, "QC_tavern", "sit", "sit7");
					}
				break;

				case "QC_brothel"://<<<<------------------------------------------------------------------Added This, Love Verruckt
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit1")
					{
						ChangeCharacterAddressGroup(pchar, "QC_brothel", "sit", "sit11");
					}
					if (characters[GetCharacterIndex(pchar.quest.friend_in_tavern)].location.locator == "sit3")
					{
						ChangeCharacterAddressGroup(pchar, "QC_brothel", "sit", "sit2");
					}
				break;

//				case "default": // MAXIMUS [for new locations]
					GetCharacterPos(characters[GetCharacterIndex(pchar.quest.friend_in_tavern)], &x, &y, &z);
					if(!CheckAttribute(pchar,"habitue.location")) pchar.habitue.location = pchar.location;
					else
					{
						if(pchar.habitue.location!=pchar.location) pchar.habitue.location = pchar.location;
					}

					if(!CheckAttribute(pchar,"habitue.locator"))
					{
						nearloc = LAi_FindNearestFreeLocator("sit", x, y, z);
						pchar.habitue.locator = nearloc;
					}
					else
					{
						if(pchar.habitue.location!=pchar.location) nearloc = LAi_FindNearestFreeLocator("sit", x, y, z);
						else nearloc = pchar.habitue.locator;
					}
					ChangeCharacterAddressGroup(pchar, pchar.location, "sit", pchar.habitue.locator);
//				break;
			}
		break;

		case "alc2":
			LAi_ActorDialogNow(characterFromID(pchar.quest.friend_in_tavern), pchar, "", -1);
		break;

		case "exit_sit":
			if (CheckQuestAttribute("fight_in_tavern", "fight"))
			{
				pchar.quest.fight_in_tavern = "0";
				LAi_SetSitType(characterFromID(pchar.quest.friend_in_tavern));
			}
			else
			{
				if (pchar.location.group == "sit")
				{
					LAi_SetPlayerType(pchar);
					LAi_SetSitType(characterFromID(pchar.quest.friend_in_tavern));
					LAi_Fade("exit_sit_2", "");
				}
			}
		break;

		case "exit_sit_2":
			homelocation = pchar.quest.friend_in_tavern;
			LAi_SetSitType(characterFromID(homelocation));
			LAi_SetPlayerType(pchar);
			switch(pchar.location)
			{
				case "Redmond_tavern":
					LAi_group_MoveCharacter(characterFromID(pchar.quest.friend_in_tavern), "ENGLAND_CITIZENS");
				break;

				case "Oxbay_tavern":
					LAi_group_MoveCharacter(characterFromID(pchar.quest.friend_in_tavern), "ENGLAND_CITIZENS");
				break;

				case "Greenford_tavern":
					LAi_group_MoveCharacter(characterFromID(pchar.quest.friend_in_tavern), "ENGLAND_CITIZENS");
				break;

				case "Falaise_De_Fleur_tavern":
					LAi_group_MoveCharacter(characterFromID(pchar.quest.friend_in_tavern), "FRANCE_CITIZENS");
				break;

				case "Muelle_tavern":
					LAi_group_MoveCharacter(characterFromID(pchar.quest.friend_in_tavern), "SPAIN_CITIZENS");
				break;

				case "Douwesen_tavern":
					LAi_group_MoveCharacter(characterFromID(pchar.quest.friend_in_tavern), "DOUWESEN_CITIZENS");
				break;

				case "Pirate_tavern":
					LAi_group_MoveCharacter(characterFromID(pchar.quest.friend_in_tavern), "DOUWESEN_PIRATE_CITIZENS");
				break;

				case "Conceicao_tavern":
					LAi_group_MoveCharacter(characterFromID(pchar.quest.friend_in_tavern), "CONCEICAO_CITIZENS");
				break;

				case "Smugglers_tavern":
					LAi_group_MoveCharacter(characterFromID(pchar.quest.friend_in_tavern), "SMUGGLERS_CITIZENS");
				break;

				case "QC_tavern":
					LAi_group_MoveCharacter(characterFromID(pchar.quest.friend_in_tavern), "QC_CITIZENS");
				break;

				case "QC_brothel"://<---------------------------------------------------------------HERE Brothel Mod , love Verruckt!
					LAi_group_MoveCharacter(characterFromID(pchar.quest.friend_in_tavern), "QC_CITIZENS");
				break;

//				case "default":// MAXIMUS [for new locations]
/*					string charGroup = "QC_CITIZENS";
					for(int log=0; log<LAi_numloginedcharacters; log++)
					{
						int logIdx = LAi_loginedcharacters[log];
						if(logIdx>=0 && !bAllies(&Characters[logIdx]) && !LAi_IsDead(&Characters[logIdx]) && CheckAttribute(&Characters[logIdx],"chr_ai.group") && CheckAttribute(&Characters[logIdx],"chr_ai.type") && Characters[logIdx].chr_ai.type==LAI_TYPE_BARMAN)
						{
							charGroup = Characters[logIdx].chr_ai.group; break;
						}
					}*/
					LAi_group_MoveCharacter(characterFromID(pchar.quest.friend_in_tavern), GetCurrentCitizenGroup());
//					LAi_group_MoveCharacter(characterFromID(pchar.quest.friend_in_tavern), charGroup);
/*					GetCharacterPos(&characters[GetCharacterIndex(pchar.quest.friend_in_tavern)], &x, &y, &z);
					nearloc = LAi_FindNearestFreeLocator("goto", x, y, z);
					ChangeCharacterAddress(pchar, pchar.location, nearloc);
*/					if(CheckAttribute(pchar,"habitue.locator"))
					{
						if(pchar.habitue.location!=pchar.location) DeleteAttribute(pchar,"habitue.locator");
					}
//				break;
			}
			TeleportCharacterToPosAy(pchar, Land_posx[0], Land_posy[0], Land_posz[0], Land_angle[0]);
		break;

		case "kill_tavern_fightman_complete":
			LAi_SetStayType(pchar);
			LAi_LocationFightDisable(&Locations[FindLocation(pchar.location)], true);
			LAi_SetPlayerType(pchar);
		break;

		// NK -->
		case "marriageduel":
			//PChar.marriageduel.loc = PCHar.location;
			//PChar.marriageduel.MRid
			//for now, just spawn character here.
			string loc;
			float dist;
			GetNearLocator( "goto", &dist, &loc, 0);
			sld = LAi_CreateFantomCharacter(false, 0, true, true, 0.25, SelectSoldierModelbyLocationNation("", "officer"), "goto", loc);
			sld.id = "Suitor";
			sld.nation = Characters[GetCharacterIndex(PChar.marriageduel.MRid)].nation;
			LAi_SetActorType(CharacterFromID("Suitor"));
			sld.dialog.filename = "Gov MR_dialog.c";
			sld.dialog.currentnode = "engarde";
			LAi_ActorDialog(CharacterFromID("Suitor"), PChar, "", 0.01, 1.0);
		break;

		case "marriageduel_fight":
			LAi_LocationFightDisable(&Locations[FindLocation(PChar.location)], false);
			LAi_SetWarriorType(CharacterFromID("Suitor"));
			LAi_group_MoveCharacter(characterFromID("Suitor"), "BANDITS");
			LAi_group_FightGroups("BANDITS", LAI_GROUP_PLAYER, true);
			LAi_SetCheckMinHP(CharacterFromID("Suitor"), 0.875*LAi_GetCharacterHP(characterFromID("Suitor")), true, "marriageduel_won"); // KK
		break;

		case "marriageduel_won":
			LAi_LocationFightDisable(&Locations[FindLocation(PChar.location)], true);
			LAi_SetFightMode(GetMainCharacter(), false)
			sld = CharacterFromID("Suitor");
			LAi_SetImmortal(CharacterFromID("Suitor"), false);
			LAi_SetActorType(CharacterFromID("Suitor"));
			sld.dialog.currentnode = "duelend";
			LAi_ActorDialog(CharacterFromID("Suitor"), PChar, "", 0.01, 1.0);
		break;

		case "marriageduel_end":
			ChangeCharacterAddress(CharacterFromID("Suitor"), "none", "none");
			sld = CharacterFromID(PChar.marriageduel.MRid);
			sld.dialog.currentnode = "married";
			LAi_ActorDialogNow(sld, PChar, "", -1);
		break;

		case "RemoveMRs":
			ClearMRLocations();
		break;

		// NK 05-04-17 add "updatedays" handler for when you want the day to update but
		case "updatedays":
			PChar = GetMainCharacter();
			if(!CheckAttribute(PChar,"updatedays")) break;
			int daysn = sti(PChar.updatedays);
			bool disableDCU = CheckAttribute(PChar,"updatedays.disableDCU");
			bool curDCU = !CheckAttribute(PChar,"disableDCU");
			bool disableIT = CheckAttribute(PChar,"updatedays.disableIT");
			bool curIT = CheckAttribute(ShipLookupTable,"itemtraders") && sti(ShipLookupTable.itemtraders);
			if(disableDCU) PChar.disableDCU = true;
			if(disableIT && curIT) ShipLookupTable.itemtraders = false;
			//if(FindLoadedLocation() != -1) LAi_Fade("", "");
			int s, dn;
			//int start = 0; if(CheckAttribute(wdmgrid,"lastupdate.day")) { start = sti(wdmgrid.lastupdate.start)+1; } 
			for(dn = 0; dn < daysn-1; dn++)
			{
				//trace("Gauging: Start day " + dn);
				AddDataToCurrent(0, 0, 1, false);
				ReloadProgressUpdate();
				DailyCrewUpdate();
				//ReloadProgressUpdate();
				UpdateAllTowns(false);
				//trace("Gauging: Towns done");
				//ReloadProgressUpdate();
				UpdateAllStores(false);
				//wdmFleetsUpdateDay(); //wdmFleetsUpdate(false, false); // WM 05-04-24
			}
			if(curDCU) DeleteAttribute(PChar,"disableDCU");
			ReloadProgressUpdate();
			
			if(curIT)
			{
				ShipLookupTable.itemtraders = true;
				UpdateAllItemTraders(2); // make everyone blank, but put off the actual updates until you speak with them.
			}
			ReloadProgressUpdate();
			AddDataToCurrent(0, 0, 1, true); // do the last day with the normal post.
			DeleteAttribute(PChar,"updatedays");
		break;
// NK <--

		// MAXIMUS =================================== Prisoners and Captived Captains Section =================================== >
		case "Surrendered_Captain_Dialog":
			LAi_SetPlayerType(PChar);
			if(CheckAttribute(PChar,"quest.CaptiveIdx"))
			{
				LAi_SetStayType(GetCharacter(sti(PChar.quest.CaptiveIdx)));
				DialogMain(GetCharacter(sti(PChar.quest.CaptiveIdx)));
				DeleteAttribute(PChar,"quest.CaptiveIdx");
			}
		break;

		case "Surrendered_Captain_Poor":
			if(CheckAttribute(PChar,"prisonerIDX"))
			{
				LAi_SetPoorType(&characters[makeint(PChar.prisonerIDX)]);
				DeleteAttribute(PChar,"prisonerIDX");
			}
		break;

		case "Surrendered_Captain_Stay":
			if(CheckAttribute(PChar,"prisonerIDX")) LAi_SetStayType(&characters[makeint(PChar.prisonerIDX)]);
		break;

		case "Surrendered_Captain_Turn":
			if(CheckAttribute(PChar,"prisonerIDX"))
			{
				LAi_ActorTurnToCharacter(&characters[makeint(PChar.prisonerIDX)], PChar);
				LAi_SetStayType(&characters[makeint(PChar.prisonerIDX)]);
			}
		break;

		case "Surrendered_Captain_Afraid":
			if(CheckAttribute(PChar,"prisonerIDX"))
			{
				LAi_ActorAnimation(&characters[makeint(PChar.prisonerIDX)], "afraid","", -1);
				DeleteAttribute(PChar,"prisonerIDX");
			}
		break;

		case "Surrendered_Captain_Dead":
			if(CheckAttribute(PChar,"prisonerIDX"))
			{
				switch(Rand(1))
				{
					case 0: LAi_ActorAnimation(&characters[makeint(PChar.prisonerIDX)], "death_afraid_1","", -1); break;
					case 1: LAi_ActorAnimation(&characters[makeint(PChar.prisonerIDX)], "death_afraid_2","", -1); break;
				}
				DeleteAttribute(PChar,"prisonerIDX");
			}
		break;

		case "Surrendered_Captain_Dead1":
			if(CheckAttribute(PChar,"prisonerIDX"))
			{
				LAi_ActorAnimation(&characters[makeint(PChar.prisonerIDX)], "Ground_Afraid_Death","", -1);
				RemovePassenger(PChar,&characters[makeint(PChar.prisonerIDX)]);
				DeleteAttribute(&characters[makeint(PChar.prisonerIDX)],"prisoned");
				DeleteAttribute(PChar,"prisonerIDX");
			}
		break;

		case "Surrendered_Captain_Run":
			if(CheckAttribute(PChar,"prisonerIDX"))
			{
				LAi_ActorRunToLocation(&characters[makeint(PChar.prisonerIDX)], "reload", LAi_FindRandomLocator("reload"), "None", "reload", "", "", -1);
				RemovePassenger(PChar,&characters[makeint(PChar.prisonerIDX)]);
				DeleteAttribute(&characters[makeint(PChar.prisonerIDX)],"prisoned");
				DeleteAttribute(PChar,"prisonerIDX");
			}
		break;
		// MAXIMUS =================================== Prisoners and Captived Captains Section =================================== <
		// MAXIMUS =================================== Guadeloupe governor Section =================================== >
		case "ChangeHoverPos1":
			characters[sti(pchar.quest.ChangeHoverPos1.idx)].location	= "PaP_townhall";
			characters[sti(pchar.quest.ChangeHoverPos1.idx)].location.group = "goto";
			characters[sti(pchar.quest.ChangeHoverPos1.idx)].location.locator = "goto8";
			LAi_SetLoginTime(&characters[sti(pchar.quest.ChangeHoverPos1.idx)], 12.0, 24.0);
			LAi_SetHuberStayType(&characters[sti(pchar.quest.ChangeHoverPos1.idx)]);
			LAi_SetStayHuberPointWindow(&characters[sti(pchar.quest.ChangeHoverPos1.idx)], "goto", "goto1");
			LAi_SetStayHuberPointMap(&characters[sti(pchar.quest.ChangeHoverPos1.idx)], "goto", "goto3");
			pchar.quest.ChangeHoverPos1_progress = "completed";
		break;

		case "ChangeHoverPos2":
			characters[sti(pchar.quest.ChangeHoverPos2.idx)].location	= "PaP_townhall";
			characters[sti(pchar.quest.ChangeHoverPos2.idx)].location.group = "sit";
			characters[sti(pchar.quest.ChangeHoverPos2.idx)].location.locator = "sit1";
			LAi_SetLoginTime(&characters[sti(pchar.quest.ChangeHoverPos2.idx)], 0.0, 12.0);
			LAi_SetHuberType(&characters[sti(pchar.quest.ChangeHoverPos2.idx)]);
			pchar.quest.ChangeHoverPos_progress = "completed";
		break;
		// MAXIMUS =================================== Guadeloupe governor Section =================================== <
		// MAXIMUS =================================== Training fight Section =================================== >
		case "StartTrainingFight":
			LAi_SetHP(PChar, makefloat(sti(PChar.skill.Fencing)*50), makefloat(sti(PChar.skill.Fencing)*50));
			LAi_SetFightMode(PChar, true);
			Lai_SetCheckMinHP(Pchar, 0.5*LAi_GetCharacterHP(PChar), false, "TrainingFightFinished1");
			for(int ts=1; ts<sti(PChar.TrainingFight.count)+1; ts++)
			{
				LAi_SetHP(CharacterFromID("TrainingFight_"+ts), makefloat(sti(PChar.skill.Fencing)*50), makefloat(sti(PChar.skill.Fencing)*50));
				Lai_SetImmortal(CharacterFromID("TrainingFight_"+ts), false);
				LAi_SetActorTypeNoGroup(CharacterFromID("TrainingFight_"+ts));
				LAi_ActorAttack(CharacterFromID("TrainingFight_"+ts), Pchar, "");
				Lai_SetCheckMinHP(CharacterFromID("TrainingFight_"+ts), 0.5*LAi_GetCharacterHP(CharacterFromID("TrainingFight_"+ts)), true, "TrainingFightFinished1");
			}
		break;

		case "ContinueTrainingFight":
			LAi_SetHP(PChar, makefloat(sti(PChar.skill.Fencing)*50), makefloat(sti(PChar.skill.Fencing)*50));
			LAi_SetFightMode(PChar, true);
			Lai_SetCheckMinHP(Pchar, 0.5*LAi_GetCharacterHP(PChar), false, "TrainingFightFinished2");
			for(int tc=1; tc<sti(PChar.TrainingFight.count)+1; tc++)
			{
				LAi_SetHP(CharacterFromID("TrainingFight_"+tc), makefloat(sti(PChar.skill.Fencing)*50), makefloat(sti(PChar.skill.Fencing)*50));
				Lai_SetImmortal(CharacterFromID("TrainingFight_"+tc), false);
				LAi_SetActorTypeNoGroup(CharacterFromID("TrainingFight_"+tc));
				LAi_ActorAttack(CharacterFromID("TrainingFight_"+tc), Pchar, "");
				Lai_SetCheckMinHP(CharacterFromID("TrainingFight_"+tc), 0.5*LAi_GetCharacterHP(CharacterFromID("TrainingFight_"+tc)), true, "TrainingFightFinished2");
			}
		break;

		case "TrainingFightFinished1":
			for(int tf=1; tf<sti(PChar.TrainingFight.count)+1; tf++)
			{
				LAi_RemoveCheckMinHP(CharacterFromID("TrainingFight_"+tf));
				LAi_SetCurHPMax(CharacterFromID("TrainingFight_"+tf));
				ResetHP(CharacterFromID("TrainingFight_"+tf));
				LAi_type_actor_Reset(CharacterFromID("TrainingFight_"+tf));
			}

			LAi_RemoveCheckMinHP(Pchar);
			LAi_SetCurHPMax(Pchar);
			ResetHP(Pchar);
			LAi_SetActorTypeNoGroup(PChar);
			Lai_ActorWaitDialog(Pchar, CharacterFromID("TrainingFight_1"));
			LAi_SetFightMode(PChar, false);
			Lai_QuestDelay("ReturnPlayer", 1.5);

			Characters[sti(PChar.TrainingFight.leader)].Dialog.CurrentNode = "EnoughForYou1";
			LAi_ActorDialog(CharacterFromID("TrainingFight_1"), PChar, "", 1.0, 1.0);
		break;

		case "TrainingFightFinished2":
			for(int te=1; te<sti(PChar.TrainingFight.count)+1; te++)
			{
				LAi_RemoveCheckMinHP(CharacterFromID("TrainingFight_"+te));
				LAi_SetCurHPMax(CharacterFromID("TrainingFight_"+te));
				ResetHP(CharacterFromID("TrainingFight_"+te));
				LAi_type_actor_Reset(CharacterFromID("TrainingFight_"+te));
			}

			LAi_RemoveCheckMinHP(Pchar);
			LAi_SetCurHPMax(Pchar);
			ResetHP(Pchar);
			LAi_SetActorTypeNoGroup(PChar);
			Lai_ActorWaitDialog(Pchar, CharacterFromID("TrainingFight_1"));
			LAi_SetFightMode(PChar, false);
			Lai_QuestDelay("ReturnPlayer", 1.5);

			Characters[sti(PChar.TrainingFight.leader)].Dialog.CurrentNode = "EnoughForYou2";
			LAi_ActorDialog(&Characters[sti(PChar.TrainingFight.leader)], PChar, "", 1.0, 1.0);
		break;

		case "ReturnPlayer":
			LAi_SetPlayerType(Pchar);
		break;

		// MAXIMUS =================================== Training fight Section =================================== <

// KK ----------------- Resurrection Event ------------------------------->

		case "ResurrectionEvent":
			if (GetActualNationRelation2MainCharacter(GetCurrentLocationNation()) != RELATION_ENEMY)
				LAi_QuestDelay("ResurrectionEvent_BlazeWakes", 0.0);
			else
				LAi_QuestDelay("ResurrectionEvent_BlazeMustEscape", 0.0);
		break;

		case "ResurrectionEvent_BlazeWakes":
			LAi_SetActorType(PChar);
			LAi_SetActorType(ResurrectingOfficiant);
			LAi_ActorFollow(PChar, ResurrectingOfficiant, "", 1.5);
			LAi_ActorFollow(ResurrectingOfficiant, PChar, "ResurrectionEvent_DialogStart", 1.5);
		break;

		case "ResurrectionEvent_DialogStart":
			LAi_type_actor_Reset(PChar);
			LAi_ActorWaitDialog(PChar, ResurrectingOfficiant);
			LAi_ActorDialog(ResurrectingOfficiant, PChar, "", 1.0, 1.0);
			LAi_SetPlayerType(PChar);
		break;

		case "ResurrectionEvent_OfficiantLeaves":
			LAi_SetActorType(ResurrectingOfficiant);
			LAi_ActorGoToLocation(ResurrectingOfficiant, "reload", "reload1", ResurrectingOfficiant.tavern.location, ResurrectingOfficiant.tavern.location.group, ResurrectingOfficiant.tavern.location.locator, "ResurrectionEvent_OfficiantLeftTavernUpstairs", 10.0);
		break;

		case "ResurrectionEvent_OfficiantLeftTavernUpstairs":
			LAi_SetWaitressType(ResurrectingOfficiant);
			Locations[FindLoadedLocation()].reload.l1.disable = 0;
			if (CheckAttribute(PChar, "NoSave.Resurrection")) DeleteAttribute(PChar, "NoSave.Resurrection");
			if (CheckAttribute(PChar, "NoSave")) DeleteAttribute(PChar, "NoSave");
		break;

		case "ResurrectionEvent_BlazeMustEscape":
			ResurrectingOfficiant.Dialog.CurrentNode = "Blaze_must_escape";
			LAi_SetActorType(PChar);
			LAi_SetActorType(ResurrectingOfficiant);
			LAi_ActorTurnToCharacter(PChar, ResurrectingOfficiant);
			LAi_ActorFollow(ResurrectingOfficiant, PChar, "ResurrectionEvent_DialogStart", 1.5);
		break;

//	----------- Safe Port Leave ------------------------------------------------

		case "Safe_port_leave":
			iForceDetectionFalseFlag = 0;
		break;

//	----------- Colony Capture -------------------------------------------------

		case "ColonyCapture_Ransom":
			RansomColony(GetCharacter(sti(PChar.colony_capture.govidx)));
			DeleteAttribute(PChar, "colony_capture");
		break;

		case "ColonyCapture_Capture":
			CaptureColony(GetCharacter(sti(PChar.colony_capture.govidx)), sti(PChar.colony_capture.nation));
			DeleteAttribute(PChar, "colony_capture");
		break;

		case "ColonyCapture_ContinueDialog":
			if (CheckAttribute(PChar, "colony_capture")) {
				NPChar = GetCharacter(sti(PChar.colony_capture.govidx));
				NPChar.Dialog.CurrentNode = "First time";
				NPChar.Dialog.TempNode = "First time";
				LAi_SetActorType(PChar);
				LAi_ActorDialog(PChar, NPChar, "Surrendered_Captain_Dialog", 60.0, 0);	// surrender dialog
			}
		break;
// <-- KK

		case "reset_abordage":
			//log_setStringToLog("Abordage characters was reseted");
			pchar.quest.abordage = 0;
		break;
	}
	//LanguageCloseFile(tmpLangFileID);
}
// <-- KK
