// the file NK.c was renamed to BuildSettings.h
// as of 05-07-03 it will now have my misc functions.
// moved these here from Console.c, they help in debug/testing.

// this block allows you to regain control of pchar after a delay. Useful in testing AI funcs on pchar,
// and then getting control back to reset the situation.
// call it with postevent("resetpchar_event", msec); where msec is the delay in ms.
#event_handler("resetpchar_event", "resetpchar");
void resetpchar()
{
	LAi_SetPlayerType(GetMainCharacter());
}

// creates an officer for the player, of type otype, model (from array!!!) model, offset-to-level offset, of nation, and points/perks left assignable if(blank)
ref CreateOfficer_Cheat(string otype, string model, int offset, int nation, bool blank)
{
	ref pchar = GetMainCharacter();
	ref ch;
	ch = GetCharacter(FindFreeRandomOfficer());
	ch.dialog.filename = "enc_officer_dialog.c";
	ch.offgen = true;
	ch.officer = true;
	ch.Dialog.CurrentNode = "hired";
	ch.Dialog.TempNode = "hired";
	ch.quest.meeting = "1";
	ch.quest = "True";
	ch.reputation = 65;
	ch.nation = nation;
	ch.AbordageMode = 0;

	ch.quest.officertype = otype;
	LAi_Create_Officer(offset, &ch);
	SetModelfromArray(&ch, GetModelIndex(model));
	LAi_NPC_Equip(&ch, sti(ch.rank), true, true);
	SetRandomNameToCharacter(&ch);
	DeleteAttribute(ch, "greeting");
	if(blank) ResetChar_Cheat(&ch);
	if(FindLoadedLocation() != -1) PlaceCharacter(&ch, "goto", pchar.location);
	AddPassenger(&pchar, &ch, false);
	return &ch;
}

// resets all skills/perks to allow custom assignment
void ResetChar_Cheat(ref ch)
{
	ch.skill.Leadership = "1";
	ch.skill.Fencing = "1";
	ch.skill.Sailing = "1";
	ch.skill.Accuracy = "1";
	ch.skill.Cannons = "1";
	ch.skill.Grappling = "1";
	ch.skill.Repair = "1";
	ch.skill.Defence = "1";
	ch.skill.Commerce = "1";
	ch.skill.Sneak = "1";
	ch.skill.freeskill = sti(ch.rank) * 2;
	DeleteAttribute(ch,"perks");
	ch.perks.freepoints = sti(ch.rank);
	ResetHP(&ch); // 05-07-03 use new func
	/*if(sti(ch.index) == GetMainCharacterIndex())
	{
		LAi_SetHP(&ch, LAI_DEFAULT_HP + sti(ch.rank) * 5, LAI_DEFAULT_HP + sti(ch.rank) * 5);
	}
	else { LAi_SetHP(&ch, LAI_DEFAULT_HP + sti(ch.rank) * makeint(11-GetDifficulty()), LAI_DEFAULT_HP + sti(ch.rank) * makeint(11-GetDifficulty())); }*/
}

// creates ship of id shipname, speed srate, turn trate, and max gun caliber cal. Gives long guns of that caliber, and full crew.
void CreateShip_Cheat(string shipname, int nat, float srate, float trate, int cal)
{
	ref pchar = GetMainCharacter();
	pchar.ship.type = shipname;
	GetCharacterShipType(pchar);
	aref arship; makearef(arship, pchar.ship); DeleteAttribute(arship,"stats");
	SetRandomStatsToShip(GetMainCharacterIndex(), GetCharacterShipType(pchar), nat); // KK
	arship.stats.maxcaliber = cal; arship.stats.speedrate = srate; arship.stats.turnrate = trate; arship.cannons.type = GetCannonByTypeAndCaliber("long gun", cal);
	SetCrewQuantity(&pchar, GetMaxCrewQuantity(&pchar));
}

// repairs all damage--HP and SP, fixes masts, and removes blots. Masts do not appear until reload sea.
// also resets crew qty and sets morale at max, and sets balls at 700.
void RepairShip_Cheat()
{
	ref pchar = GetMainCharacter();
	ResetCannons(pchar);
	DeleteAttribute(&pchar,"ship.masts");
	pchar.ship.hp = GetCharacterShipHP(pchar) / 9.5;
	pchar.ship.sp = 0.5;
	SetCrewQuantity(&pchar, GetMaxCrewQuantity(&pchar));
	pchar.ship.crew.morale = MORALE_MAX;
	pchar.seatime.basecrewmorale = MORALE_MAX;
	pchar.seatime.tempmorale = MORALE_MAX;
	ProcessSailRepair(&pchar,100.0);
	ProcessHullRepair(&pchar, 100.0);
	SetCharacterGoods(&pchar, GOOD_BALLS, 700);
}

void GiveShip2Character(ref char, string shiptype, string shipname, int nat, bool hirecrew, bool getsupplies)
{
	char.ship.type = shiptype;
	char.ship.name = shipname;
	aref arship; makearef(arship, char.ship); DeleteAttribute(arship,"stats");
	SetRandomStatsToShip(sti(char.index), GetCharacterShipType(char), nat); // KK
	ResetCannons(char);
	DeleteAttribute(&char,"ship.masts");
	ProcessSailRepair(&char,100.0);
	ProcessHullRepair(&char, 100.0);
	if(hirecrew || sti(GetCrewQuantity(&char)) > sti(GetMaxCrewQuantity(&char)))
	{
		SetCrewQuantity(&char, GetMaxCrewQuantity(&char));
	}
	if(getsupplies || sti(GetCargoLoad(&char)) > sti(GetCargoMaxSpace(&char)))
	{
		EmptyShip(char) // First remove all goods from the ship
		SupplyShip(char) // Then add them again
	}
}

void EmptyShip(ref char)
{
	int i; for(i=0;i<GOODS_QUANTITY;i++) RemoveCharacterGoods(char,i,GetCargoGoods(char,i));
}

void SupplyShip(ref char)
{
	if(FOOD_ON) AddCharacterGoods(char, GOOD_WHEAT, 1+makeint(makefloat(GetCrewQuantity(&char)) * FOOD_PER_CREW * WHEAT_DAYS));
	if(FOOD_ON) AddCharacterGoods(char, GOOD_RUM, 1+makeint(makefloat(GetCrewQuantity(&char)) * FOOD_PER_CREW * RUM_DAYS));
	if(CANNONPOWDER_MOD && GetMaxCannonQuantity(&char) > 0)
	{
		int needPwdr = 0;
		float averageQty = 0.0;
		ref rCannon; makeref(rCannon,Cannon[GetCaracterShipCannonsType(char)]);
		if (USE_REAL_CANNONS) 	{ averageQty = makefloat(GetCargoGoods(&char,GOOD_BALLS) + GetCargoGoods(&char,GOOD_GRAPES) + GetCargoGoods(&char,GOOD_KNIPPELS))/3; }
		else 					{ averageQty = makefloat(GetCargoGoods(&char,GOOD_BALLS) + GetCargoGoods(&char,GOOD_GRAPES) + GetCargoGoods(&char,GOOD_KNIPPELS) + GetCargoGoods(&char,GOOD_BOMBS))/4; }
		float canCharge = makefloat(averageQty/makefloat(GetMaxCannonQuantity(&char)));
		if(CheckAttribute(rCannon,"gunpowder")) needPwdr = sti(rCannon.gunpowder);
		AddCharacterGoods(char, GOOD_GUNPOWDER, makeint((makefloat(GetMaxCannonQuantity(&char)) * needPwdr * canCharge) + (makefloat(GetCrewQuantity(&char)) * 3)));
	}
	AddCharacterGoods(char, GOOD_BALLS, makeint(makefloat(GetMaxCannonQuantity(&char)) * BALLS_PER));
	AddCharacterGoods(char, GOOD_GRAPES, makeint(makefloat(GetMaxCannonQuantity(&char)) * GRAPE_PER));
	AddCharacterGoods(char, GOOD_KNIPPELS, makeint(makefloat(GetMaxCannonQuantity(&char)) * CHAIN_PER));
	if(!USE_REAL_CANNONS) AddCharacterGoods(char, GOOD_BOMBS, makeint(makefloat(GetMaxCannonQuantity(&char)) * BOMBS_PER));
	AddCharacterGoods(char, GOOD_SAILCLOTH, makeint(makefloat(GetCharacterShipHP(&char)) * SAIL_PER));
	AddCharacterGoods(char, GOOD_PLANKS, makeint(makefloat(GetCharacterShipHP(&char)) * PLANKS_PER));
}

void GivePromotionReward()
{
	ref pchar = GetMainCharacter();
	switch(GetCurrentLocationNation())
	{
		case ENGLAND:
			switch(GetRank(pchar, GetCurrentLocationNation()))
			{
				case 1: // Midshipman
					switch(GetAttribute(pchar,"model"))
					{
						case "cnorrington": GiveModel2Player("Mdnorrington", true); break;
						case "blaze": GiveModel2Player("47_Blaze_brtmds", true); break;
						switch(rand(2))
						{
							case 0: GiveModel2Player("rn_mdshp18_1", true); break;
							case 1: GiveModel2Player("rn_mdshp18_2", true); break;
							case 2: GiveModel2Player("rn_mdshp18_3", true); break;
						}
					}
				break;
				case 2: // 3rd Lieutenant
					if(pchar.model == "depp")				GiveModel2Player("47_Ltsparrow", true);
					if(pchar.model == "Mdnorrington")		GiveModel2Player("Ltnorrington", true);
					if(pchar.model == "47_Blaze_brtmds")	GiveModel2Player("47_Blaze_brtlt", true);
				break;
				case 3: // 2nd Lieutenant
				break;
				case 4: // 1st Lieutenant
				break;
				case 5: // Commander
				break;
				case 6: // Captain
					if(pchar.model == "47_Ltsparrow")		GiveModel2Player("47_Cptsparrow", true);
					if(pchar.model == "Ltnorrington")		GiveModel2Player("cnorrington", true);
					if(pchar.model == "47_Blaze_brtlt")		GiveModel2Player("47_Blaze_brtcpt", true);
				break;
				case 7: // Commodore
					if(pchar.model == "47_Cptsparrow")		GiveModel2Player("47_Cosparrow", true);
					if(pchar.model == "cnorrington")		GiveModel2Player("Conorrington", true);
					if(pchar.model == "47_Blaze_brtcpt")	GiveModel2Player("47_Blaze_brtco", true);
					GiveItem2Character(pchar,"blade24+2"); // English Officer's Saber
					EquipCharacterByItem(pchar,"blade24+2");
				break;
				case 8: // Rear Admiral
					if(pchar.model == "47_Cosparrow")		GiveModel2Player("47_Admsparrow", true);
					if(pchar.model == "47_Blaze_brtco")	GiveModel2Player("47_Blaze_brtadm", true);
				break;
				case 9: // Vice Admiral
				break;
				case 10: // Admiral
					GiveItem2Character(pchar,"blade22+2"); // Corsair's Pride
					EquipCharacterByItem(pchar,"blade22+2");
				break;
				case 11: // Admiral of the Fleet
				break;
				case 12: // First Lord of the Admiralty
				break;
			}
		break;
		case HOLLAND:
			switch(GetRank(pchar, GetCurrentLocationNation()))
			{
				case 1: // Cadet Officier
				break;
				case 2: // 3e Luitenant
				break;
				case 3: // 2e Luitenant
				break;
				case 4: // 1e Luitenant
				break;
				case 5: // Schout-bij-Nacht
				break;
				case 6: // Kapitein-Luitenant
				break;
				case 7: // Kapitein ter zee
				break;
				case 8: // Commandeur
					GiveItem2Character(pchar,"blade23+2"); // Dutch Admiralty Sword
					EquipCharacterByItem(pchar,"blade23+2");
				break;
				case 9: // Vice-Admiraal
				break;
				case 10: // Luitenant-Admiraal
				break;
				case 11: // Admiraal
					GiveItem2Character(pchar,"blade26+2"); // Solingen Rapier
					EquipCharacterByItem(pchar,"blade26+2");
				break;
				case 12: // Generaal-Admiraal
				break;
			}
		break;
		case FRANCE:
			switch(GetRank(pchar, GetCurrentLocationNation()))
			{
				case 1: // Enseigne
					if(pchar.model == "blaze")				GiveModel2Player("47_Blaze_france", true);
					if(pchar.model == "depp")				GiveModel2Player("47_Sparrow_france", true);
				break;
				case 2: // Sub-Lieutenant de Vaisseau
				break;
				case 3: // Lieutenant de Vaisseau
				break;
				case 4: // Capitaine de Corvette
				break;
				case 5: // Capitaine de Fregate
				break;
				case 6: // Capitaine de Vaisseau
				break;
				case 7: // Contre-Amirale
					GiveItem2Character(pchar,"blade9+2"); // French Admiralty Rapier
					EquipCharacterByItem(pchar,"blade9+2");
				break;
				case 8: // Vice-Amirale
				break;
				case 9: // Vice-Amirale de Escadre
				break;
				case 10: // Amirale
					GiveItem2Character(pchar,"blade25+2"); // French Nobility Sword
					EquipCharacterByItem(pchar,"blade25+2");
				break;
				case 11: // Amirale de Escadre
				break;
				case 12: // Ministre de la Francais Royale Marine
				break;
			}
		break;
		case SPAIN:
			switch(GetRank(pchar, GetCurrentLocationNation()))
			{
				case 1: // Alferez
					if(pchar.model == "blaze")				GiveModel2Player("47_Blaze_spain", true);
					if(pchar.model == "depp")				GiveModel2Player("47_Sparrow_spain", true);
				break;
				case 2: // Seg.-Tenente
				break;
				case 3: // Teniente
				break;
				case 4: // Capitan de Corbeta
				break;
				case 5: // Capitan de Fragata
				break;
				case 6: // Capitan de Navio
					GiveItem2Character(pchar,"blade33+2"); // Moorish Saber
					EquipCharacterByItem(pchar,"blade33+2");
				break;
				case 7: // Contra Almirante
				break;
				case 8: // Vice Almirante
				break;
				case 9: // Almirante
					GiveItem2Character(pchar,"blade14+2"); // Spanish Nobility Longsword
					EquipCharacterByItem(pchar,"blade14+2");
				break;
				case 10: // Capitan General
				break;
				case 11: // Almirante General
				break;
				case 12: // Almirante de Armada Espanola
				break;
			}
		break;
		case PORTUGAL:
			switch(GetRank(pchar, GetCurrentLocationNation()))
			{
				case 1: // Aspirante
				break;
				case 2: // Seg.-Tenente
				break;
				case 3: // Tenente
				break;
				case 4: // Capitao-Tenente
				break;
				case 5: // Capitao-de-Fragata
				break;
				case 6: // Capitao-de-Mar-e-Guerra
				break;
				case 7: // Comodoro
					GiveItem2Character(pchar,"blade29+2"); // Portugese Officer's Sword
					EquipCharacterByItem(pchar,"blade29+2");
				break;
				case 8: // Contra-Almirante
				break;
				case 9: // Vice-Almirante
				break;
				case 10: // Almirante
					GiveItem2Character(pchar,"blade32+2"); // Damascus Shamshir
					EquipCharacterByItem(pchar,"blade32+2");
				break;
				case 11: // Almirante da Armada
				break;
				case 12: // Almirante da Marinha de Guerra Portuguesa
				break;
			}
		break;
/*
		case PIRATE: // UNUSED: Just to remind us to use the pirate unique saber somewhere
					GiveItem2Character(pchar,"blade34+2"); // Dragon's Head
					EquipCharacterByItem(pchar,"blade34+2");
		break;
		case EITC: // UNUSED: Just to remind us to use those models at some point
			switch(GetRank(pchar, GetCurrentLocationNation()))
			{
				case 2: // Lieutenant
					if(pchar.model == "blaze")				pchar.model = "47Blaze_Eitc_lt";
					if(pchar.model == "depp")				pchar.model = "47_Sparrow_Eitc_lt";
				break;
				case 4: // Captain
					if(pchar.model == "47Blaze_Eitc_lt")	pchar.model = "47Blaze_Eitc_cpt";
					if(pchar.model == 47_Sparrow_Eitc_lt")	pchar.model = "47_Sparrow_Eitc_cpt";
				break;
			}
		break;
*/
	}
}

void SetDeckPortBackground()
{
	ref PChar = GetMainCharacter();
	ref deck = &Locations[FindLocation(GetCharacterShipQDeck(PChar))];
	string loc_id = deck.reload.l4.go;
	switch(loc_id)
	{
		case "Conceicao_port":				deck.models.always.back1 = "..\..\Town_Conceicao\port\Conport_landscape"; break;
		case "Douwesen_port":				deck.models.always.back1 = "..\..\Town_Douwesen\port\DouPort_landscape"; break;
		case "Cayman_Port":					deck.models.always.back1 = "..\..\Town_FalaiseDeFleur\port2\FFPORT02_landscape"; break;
		case "Falaise_de_fleur_port_01":	deck.models.always.back1 = "..\..\Town_FalaiseDeFleur\port\FFPORT01_landscape"; break;
		case "Marigot_port":				deck.models.always.back1 = "..\..\Town_FalaiseDeFleur\port\FFPORT01_landscape"; break;
		case "Greenford_port":				deck.models.always.back1 = "..\..\Town_Greenford\port\Grport_landscape"; break;
		case "Cuba_port":					deck.models.always.back1 = "..\..\Town_Havana\port\HavPort_landscape"; break;
		case "Muelle_port":					deck.models.always.back1 = "..\..\Town_IslaMuelle\port\MUPORT_landscape"; break;
		case "Philipsburg_port":			deck.models.always.back1 = "..\..\Town_Philipsburg\port\PBport_landscape";
											deck.models.always.back2 = "..\..\Town_Philipsburg\port\PBport_add_landscape"; break;
		case "Hispaniola_port":				deck.models.always.back1 = "..\..\Town_PoPrince\port\PoPrinceport_landscape"; break;
		case "QC_port":						deck.models.always.back1 = "..\..\Town_QC\port\QCPORT_landscape"; break;
		case "Turks_port":					deck.models.always.back1 = "..\..\Town_QC\port\QCPORT_landscape"; break;
		case "Redmond_Port":				deck.models.always.back1 = "..\..\Town_Redmond\port\RedPort_landscape"; break;
		case "Santo_Domingo_port":			deck.models.always.back1 = "..\..\Town_SantoDomingo\port\SDPort_landscape";
											deck.models.always.back2 = "..\..\Town_SantoDomingo\port\SDPort_add_landscape"; break;
		DeleteAttribute(deck,"models.always.back1");
		DeleteAttribute(deck,"models.always.back2");
	}
}

void GiveModel2Player(string model, bool assign)
{
	Characters[GetMainCharacterIndex()].clothes.(model) = true;
	if(assign) SetModelfromArray(GetMainCharacter(), GetModelIndex(model));
}

string GetAttribute(ref tmp, string att)
{
	if(CheckAttribute(tmp,att)) return tmp.(att);
	else return "";
}

// sets wind to 30kts
void Wind_Cheat()
{
	Weather.Wind.Speed = 30.0;
	fWeatherSpeed = 30.0;
}

// sets up lvl12 characters with skills, perks, and items as I like. Allows types "player", qm, nav, can, and capnavy.
void SetUpChar_Cheat(ref ch, string otype)
{
	string stmp;

	switch(otype)
	{
		case "player":
			ch.skill.freeskill = 0;
			ch.skill.leadership = 8;
			ch.skill.fencing = 9;
			ch.skill.sailing = 4;
			ch.skill.accuracy = 1;
			ch.skill.cannons = 1;
			ch.skill.grappling = 1;
			ch.skill.repair = 1;
			ch.skill.defence = 1;
			ch.skill.commerce = 1;
			ch.skill.sneak = 7;
			ch.items.bladex4 = 1;
			ch.items.blade1 = 1;
			ch.items.potion1 = 22;
			ch.items.pistol1 = 1;
			ch.items.spyglass1 = 1;
			ch.items.commonarmor = 1;
			stmp = "blade19+2";
			ch.items.(stmp) = 1;
			stmp = "pistol8+2";
			ch.items.(stmp) = 1;
			ch.items.spyglass4 = 1;
			ch.items.jewelry2 = 1;
			ch.items.jewelry3 = 1;
			ch.items.jewelry4 = 1;
			ch.items.jewelry10 = 1;
			ch.items.indian5 = 1;
			ch.items.mineral16 = 2;
			ch.items.jewelry8 = 1;
			ch.items.jewelry9 = 1;
			ch.items.indian7 = 1;
			ch.items.mineral3 = 2;
			ch.items.potion2 = 3;
			ch.items.potion3 = 5;
			ch.items.potionrum = 2;
			ch.perks.freepoints = 0;
			ch.perks.list = "";
			ch.perks.list.basicdefense = 1;
			ch.perks.list.advanceddefense = 1;
			ch.perks.list.criticalhit = 1;
			ch.perks.list.swordplayprofessional = 1;
			ch.perks.list.gunman = 1;
			ch.perks.list.sharedexperience = 1;
			ch.perks.list.ironwill = 1;
			ch.perks.list.shipspeedup = 1;
			ch.perks.list.shipturnrateup = 1;
			ch.perks.list.stormprofessional = 1;
			ch.perks.list.turn180 = 1;
			ch.perks.list.sandbankmaneuver = 1;
		break;

		case OFFIC_TYPE_NAVIGATOR:
			ch.skill.freeskill = 0;
			ch.skill.leadership = 1;
			ch.skill.fencing = 7;
			ch.skill.sailing = 7;
			ch.skill.accuracy = 1;
			ch.skill.cannons = 1;
			ch.skill.grappling = 1;
			ch.skill.repair = 1;
			ch.skill.defence = 9;
			ch.skill.commerce = 1;
			ch.skill.sneak = 5;
			ch.items.commonarmor = 1;
			stmp = "blade19+2";
			ch.items.(stmp) = 1;
			stmp = "pistol8+2";
			ch.items.(stmp) = 1;
			ch.items.jewelry3 = 1;
			ch.items.jewelry4 = 1;
			ch.items.indian5 = 1;
			ch.items.mineral3 = 2;
			ch.items.mineral16 = 2;
			ch.items.jewelry8 = 1;
			ch.items.jewelry9 = 1;
			ch.items.indian7 = 1;
			ch.perks.freepoints = 0;
			ch.perks.list = "";
			ch.perks.list.shipspeedup = 1;
			ch.perks.list.shipturnrateup = 1;
			ch.perks.list.stormprofessional = 1;
			ch.perks.list.turn180 = 1;
			ch.perks.list.sandbankmaneuver = 1;
			ch.perks.list.sailingprofessional = 1;
			ch.perks.list.basicdefense = 1;
			ch.perks.list.advanceddefense = 1;
			ch.perks.list.criticalhit = 1;
			ch.perks.list.swordplayprofessional = 1;
			ch.perks.list.gunman = 1;
			ch.perks.list.sharedexperience = 1;
		break;

		case OFFIC_TYPE_QMASTER:
			ch.skill.freeskill = 0;
			ch.skill.leadership = 1;
			ch.skill.fencing = 1;
			ch.skill.sailing = 1;
			ch.skill.accuracy = 1;
			ch.skill.cannons = 1;
			ch.skill.grappling = 8;
			ch.skill.repair = 9;
			ch.skill.defence = 2;
			ch.skill.commerce = 9;
			ch.skill.sneak = 1;
			ch.items.commonarmor = 1;
			stmp = "blade19+2";
			ch.items.(stmp) = 1;
			//stmp = "pistol8+2";
			//ch.items.(stmp) = 1;
			ch.items.jewelry3 = 1;
			ch.items.jewelry8 = 1;
			ch.items.jewelry10 = 1;
			ch.items.indian7 = 1;
			ch.items.mineral3 = 2;
			ch.items.mineral7 = 1;
			ch.items.mineral8 = 1;
			ch.items.jewelry9 = 1;
			ch.perks.freepoints = 0;
			ch.perks.list = "";
			ch.perks.list.longrangegrappling = 1;
			ch.perks.list.grapplingprofessional = 1;
			ch.perks.list.basicbattlestate = 1;
			ch.perks.list.advancedbattlestate = 1;
			ch.perks.list.shipdefenseprofessional = 1;
			ch.perks.list.lightrepair = 1;
			ch.perks.list.instantrepair = 1;
			ch.perks.list.trustworthy = 1;
			ch.perks.list.basiccommerce = 1;
			ch.perks.list.advancedcommerce = 1;
			ch.perks.list.basiclandowner = 1;
			ch.perks.list.sharedexperience = 1;
		break;

		case OFFIC_TYPE_CANNONEER:
			ch.skill.freeskill = 0;
			ch.skill.leadership = 1;
			ch.skill.fencing = 7;
			ch.skill.sailing = 1;
			ch.skill.accuracy = 9;
			ch.skill.cannons = 8;
			ch.skill.grappling = 1;
			ch.skill.repair = 1;
			ch.skill.defence = 1;
			ch.skill.commerce = 1;
			ch.skill.sneak = 4;
			ch.items.commonarmor = 1;
			stmp = "blade19+2";
			ch.items.(stmp) = 1;
			stmp = "pistol8+2";
			ch.items.(stmp) = 1;
			ch.items.jewelry3 = 1;
			ch.items.jewelry8 = 1;
			ch.items.jewelry9 = 1;
			ch.items.indian7 = 1;
			ch.items.mineral1 = 3;
			ch.items.mineral15 = 1;
			ch.items.chinatiger = 1;
			ch.perks.freepoints = 0;
			ch.perks.list = "";
			ch.perks.list.fastreload = 1;
			ch.perks.list.hulldamageup = 1;
			ch.perks.list.sailsdamageup = 1;
			ch.perks.list.crewdamageup = 1;
			ch.perks.list.criticalshoot = 1;
			ch.perks.list.longrangeshoot = 1;
			ch.perks.list.cannonprofessional = 1;
			ch.perks.list.basicdefense = 1;
			ch.perks.list.advanceddefense = 1;
			ch.perks.list.criticalhit = 1;
			ch.perks.list.swordplayprofessional = 1;
			ch.perks.list.gunman = 1;
		break;

		case OFFIC_TYPE_CAPNAVY:
			ch.skill.freeskill = 0;
			ch.skill.leadership = 5;
			ch.skill.fencing = 1;
			ch.skill.sailing = 7;
			ch.skill.accuracy = 5;
			ch.skill.cannons = 3;
			ch.skill.grappling = 1;
			ch.skill.repair = 1;
			ch.skill.defence = 9;
			ch.skill.commerce = 1;
			ch.skill.sneak = 1;
			ch.items.commonarmor = 1;
			stmp = "blade19+2";
			ch.items.(stmp) = 1;
			stmp = "pistol8+2";
			ch.items.(stmp) = 1;
			ch.items.jewelry2 = 1;
			ch.items.jewelry3 = 1;
			ch.items.jewelry4 = 1;
			ch.items.jewelry10 = 1;
			ch.items.indian5 = 1;
			ch.items.mineral1 = 3;
			ch.items.mineral7 = 1;
			ch.items.mineral8 = 1;
			ch.items.mineral15 = 1;
			ch.items.mineral16 = 2;
			ch.items.chinatiger = 1;
			ch.items.mineral3 = 2;
			ch.perks.freepoints = 0;
			ch.perks.list = "";
			ch.perks.list.basicbattlestate = 1;
			ch.perks.list.advancedbattlestate = 1;
			ch.perks.list.shipdefenseprofessional = 1;
			ch.perks.list.lightrepair = 1;
			ch.perks.list.stormprofessional = 1;
			ch.perks.list.sharedexperience = 1;
			ch.perks.list.ironwill = 1;
			ch.perks.list.hulldamageup = 1;
			ch.perks.list.sailsdamageup = 1;
			ch.perks.list.crewdamageup = 1;
			ch.perks.list.criticalshoot = 1;
			ch.perks.list.fastreload = 1;
		break;
	}
	for(int s = 0; s < 10; s++)
	{
		DeleteAttribute(&ch, "skill." + GetSkillName(s) + ".mod");
		GetCharacterSkill(&ch, GetSkillName(s)); // NK/GZ items mod to force refresh of modifiers.
	}
}

bool ReloadToLocModel(string model)
{
	string locid = "";
	ref loc;
	for(int i = 0; i < nLocationsNum; i++)
	{
		loc = &Locations[i];
		if(!CheckAttribute(loc, "models.always.locators")) continue;
		if(loc.models.always.locators == model)
		{
			locid = loc.id;
			break;
		}
	}
	if(locid != "") return DoQuestReloadToLocation(locid, "reload", loc.reload.l1.name, "");
	else return false;
}
