// DO NOT TOUCH THESE
#define NEW_NATION_1			0
#define NEW_NATION_2			1
#define NEW_NATION_3			2
#define NEW_NATION_4			3
#define NEW_NATION_5			4
#define NEW_NATION_6			5
#define NEW_NATION_7			10

#define NEW_DIFFICULTY_1		1
#define NEW_DIFFICULTY_2		2
#define NEW_DIFFICULTY_3		3
#define NEW_DIFFICULTY_4		4

#define TEXTUREPATH "INTERFACES\BACKGROUND\"

int nCurScroll, nCurSScrollNum, nCurNScrollNum, ListNations[9], curDifficulty, curLocation, curPlayerType; // KK // MAXIMUS: new skills-system
string totalInfo, newFirstName, newLasName, TempPlayerProfileName; // KK //MAXIMUS: added TempPlayerProfileName for preventing groundless change of PlayerProfile.name
bool bBeParty;
string oldCurNode = ""; // KK
int ModelNation = 0; // KK
int tmpLocation = 0;

void InitInterface(string iniName)
{
	GetLanguageParameters(); // MAXIMUS 30.07.2006
	GameInterface.title = "titleCustomize";

	CharOldFirstName = "";
	CharOldLastName = "";
	CharFirstName = "";
	CharLastName = "";
	CharShipName = XI_DefaultShipName(); // KK
	curDifficulty = 1;
	curLocation = 0; // KK
	curPlayerType = 1; // MAXIMUS: new skills-system
	CharNation = 6; // MAXIMUS
	TempPlayerProfileName = DEFAULT_NAME;

// KK -->
	ModelNation = sti(Models[GetModelIndex(ListModels(0))].nation);
	Models[GetModelIndex(ListModels(0))].nation = PERSONAL_NATION;
// <-- KK

	// TIH --> random name generation for each model
	string rSex = "man";
	string rfName = "";
	string rlName = "";
	ref rfNames;
	ref rlNames;
	for (int i = 0; i < ListModelsSize(); i++) // KK
	{
		rSex = GetModelSexFromListNumber(i);
		// randomly choose a nationality for the name
		switch(rand(4))
		{
			case 0:
				if (rSex == "man") { rfNames = &sEnManNames; } else { rfNames = &sEnWomenNames; }
				rlNames = &sEnFamilies;
			break;
			case 1:
				if (rSex == "man") { rfNames = &sFrManNames; } else { rfNames = &sFrWomenNames; }
				rlNames = &sFrFamilies;
			break;
			case 2:
				if (rSex == "man") { rfNames = &sSpManNames; } else { rfNames = &sSpWomenNames; }
				rlNames = &sSpFamilies;
			break;
			case 3:
				if (rSex == "man") { rfNames = &sHoManNames; } else { rfNames = &sHoWomenNames; }
				rlNames = &sHoFamilies;
			break;
			case 4:
				if (rSex == "man") { rfNames = &sPoManNames; } else { rfNames = &sPoWomenNames; }
				rlNames = &sPoFamilies;
			break;
		}
		// dont assign it if the names array is not setup
		if (GetArraySize(rfNames) >= 2)
		{
			// MAXIMUS: for properly assigned names on both languages -->
			int tmpNameFileID = LanguageOpenFile("characters_names.txt");
			// PB: Preset names -->
			// If there is a name set in initModels.c, use that instead
			if(GetModelFirstNameFromListNumber(i) == "")
			{
				if(!CheckAttribute(Models[GetModelIndex(ListModels(i))],"firstname.assigned"))
				{
					rfName = GetRandSubString(rfNames[rand(GetArraySize(rfNames) - 2)]);
					SetModelFirstNameFromListNumber(i, rfName);
					SetModelOldFirstNameFromListNumber(i, "");
					Models[GetModelIndex(ListModels(i))].firstname.assigned = true;
				}
			}
			else
			{
				if(!CheckAttribute(Models[GetModelIndex(ListModels(i))],"firstname.assigned"))
				{
					rfName = GetModelFirstNameFromListNumber(i);
					SetModelFirstNameFromListNumber(i, LanguageConvertString(tmpNameFileID,rfName));
					SetModelOldFirstNameFromListNumber(i, rfName);
					Models[GetModelIndex(ListModels(i))].firstname.assigned = true;
				}
			}

			if(GetModelLastNameFromListNumber(i) == "")
			{
				if(!CheckAttribute(Models[GetModelIndex(ListModels(i))],"lastname.assigned"))
				{
					rlName = GetRandSubString(rlNames[rand(GetArraySize(rlNames) - 2)]);
					SetModelLastNameFromListNumber(i, rlName);
					SetModelOldLastNameFromListNumber(i, "");
					Models[GetModelIndex(ListModels(i))].lastname.assigned = true;
				}
			}
			else
			{
				if(!CheckAttribute(Models[GetModelIndex(ListModels(i))],"lastname.assigned"))
				{
					rlName = GetModelLastNameFromListNumber(i);
					SetModelLastNameFromListNumber(i, LanguageConvertString(tmpNameFileID,rlName));
					SetModelOldLastNameFromListNumber(i, rlName);
					Models[GetModelIndex(ListModels(i))].lastname.assigned = true;
				}
			}
			// PB: Preset names <--
			LanguageCloseFile(tmpNameFileID);
			// MAXIMUS: for properly assigned names on both languages <--
		}
	}
	// TIH <--

	ListNations[1] = NEW_NATION_1;
	ListNations[2] = NEW_NATION_2;
	ListNations[3] = NEW_NATION_3;
	ListNations[4] = NEW_NATION_4;
	ListNations[5] = NEW_NATION_5;
	ListNations[6] = NEW_NATION_6;
	ListNations[7] = NEW_NATION_7; // TIH personal nation Aug27'06
	ListNations[8] = CharNation; // TIH personal nation Aug27'06

	FillScroll();
	FillSScroll();

	SendMessage(&GameInterface,"ls",MSG_INTERFACE_INIT,iniName);
	SendMessage(&GameInterface,"lsls",MSG_INTERFACE_MSG_TO_NODE,"B_START",0,XI_ConvertString("New Game"));
	SetCurrentNode("ISLANDSLIST");

	CreateExitString();//MAXIMUS: standard exit-string for exit-button
// changed by MAXIMUS: new skills-system -->
	CreateString(true,"CharacterName","",FONT_SEADOGS,COLOR_NORMAL,320,162,SCRIPT_ALIGN_CENTER,0.9);
	CreateString(true,"ShipName","",FONT_SEADOGS,COLOR_NORMAL,320,296,SCRIPT_ALIGN_CENTER,0.9);
	CreateString(true,"Profile",XI_ConvertString("game_profile")+" :",FONT_NORMAL,COLOR_NORMAL,35,132,SCRIPT_ALIGN_LEFT,0.9);
	CreateString(true,"ProfileName","",FONT_SEADOGS,COLOR_NORMAL,GetStringWidth(GameInterface.strings.Profile, FONT_NORMAL, 0.9)+45,132,SCRIPT_ALIGN_LEFT,0.9);
	CreateString(true,"PlrType","",FONT_NORMAL,COLOR_NORMAL,554,163,SCRIPT_ALIGN_CENTER,0.9);
	CreateString(true,"DifName","",FONT_NORMAL,COLOR_NORMAL,320,265,SCRIPT_ALIGN_CENTER,0.9);
	CreateString(true,"LocName","",FONT_NORMAL,COLOR_NORMAL,90,163,SCRIPT_ALIGN_CENTER,0.9); // KK
//changed by MAXIMUS: new skills-system <--

	SetNodeUsing("B_CHARNAME",true);
	SetNodeUsing("BOX",false);
	SetNodeUsing("B_SHIPNAME",true);
	SetNodeUsing("BOX1",false);

	CreateString(true,SKILL_LEADERSHIP,"",FONT_BOLD_NUMBERS,COLOR_MONEY,615,201,SCRIPT_ALIGN_RIGHT,0.6);
	CreateString(true,SKILL_FENCING,"",FONT_BOLD_NUMBERS,COLOR_MONEY,615,225,SCRIPT_ALIGN_RIGHT,0.6);
	CreateString(true,SKILL_SAILING,"",FONT_BOLD_NUMBERS,COLOR_MONEY,615,251,SCRIPT_ALIGN_RIGHT,0.6);
	CreateString(true,SKILL_ACCURACY,"",FONT_BOLD_NUMBERS,COLOR_MONEY,615,277,SCRIPT_ALIGN_RIGHT,0.6);
	CreateString(true,SKILL_CANNONS,"",FONT_BOLD_NUMBERS,COLOR_MONEY,615,303,SCRIPT_ALIGN_RIGHT,0.6);
	CreateString(true,SKILL_GRAPPLING,"",FONT_BOLD_NUMBERS,COLOR_MONEY,615,329,SCRIPT_ALIGN_RIGHT,0.6);
	CreateString(true,SKILL_REPAIR,"",FONT_BOLD_NUMBERS,COLOR_MONEY,615,355,SCRIPT_ALIGN_RIGHT,0.6);
	CreateString(true,SKILL_DEFENCE,"",FONT_BOLD_NUMBERS,COLOR_MONEY,615,381,SCRIPT_ALIGN_RIGHT,0.6);
	CreateString(true,SKILL_COMMERCE,"",FONT_BOLD_NUMBERS,COLOR_MONEY,615,407,SCRIPT_ALIGN_RIGHT,0.6);
	CreateString(true,SKILL_SNEAK,"",FONT_BOLD_NUMBERS,COLOR_MONEY,615,432,SCRIPT_ALIGN_RIGHT,0.6);
//MAXIMUS: new skills-system -->
	CreateString(true,"BONUS_LEADERSHIP","",FONT_NORMAL,COLOR_MONEY,581,206,SCRIPT_ALIGN_LEFT,0.5);
	CreateString(true,"BONUS_FENCING","",FONT_NORMAL,COLOR_MONEY,581,231,SCRIPT_ALIGN_LEFT,0.5);
	CreateString(true,"BONUS_SAILING","",FONT_NORMAL,COLOR_MONEY,581,257,SCRIPT_ALIGN_LEFT,0.5);
	CreateString(true,"BONUS_ACCURACY","",FONT_NORMAL,COLOR_MONEY,581,283,SCRIPT_ALIGN_LEFT,0.5);
	CreateString(true,"BONUS_CANNONS","",FONT_NORMAL,COLOR_MONEY,581,309,SCRIPT_ALIGN_LEFT,0.5);
	CreateString(true,"BONUS_GRAPPLING","",FONT_NORMAL,COLOR_MONEY,581,335,SCRIPT_ALIGN_LEFT,0.5);
	CreateString(true,"BONUS_REPAIR","",FONT_NORMAL,COLOR_MONEY,581,361,SCRIPT_ALIGN_LEFT,0.5);
	CreateString(true,"BONUS_DEFENCE","",FONT_NORMAL,COLOR_MONEY,581,387,SCRIPT_ALIGN_LEFT,0.5);
	CreateString(true,"BONUS_COMMERCE","",FONT_NORMAL,COLOR_MONEY,581,413,SCRIPT_ALIGN_LEFT,0.5);
	CreateString(true,"BONUS_SNEAK","",FONT_NORMAL,COLOR_MONEY,581,438,SCRIPT_ALIGN_LEFT,0.5);
//MAXIMUS: new skills-system <--
	SetVariable();

	SetCurrentNode("B_START");

	SetEventHandler("InterfaceBreak","ProcessCancelExit",0);
	SetEventHandler("exitCancel","ProcessCancelExit",0);
	SetEventHandler("ievnt_command","ProcCommand",0);
	SetEventHandler("frame","FrameProcess",1);
	SetEventHandler("NodeOk","ProcessNodeOk",0);
	SetEventHandler("NodeCancel","ProcessNodeCancel",0);
	SetEventHandler("CharNameChange","ProcessCharNameChange",0);
	SetEventHandler("KB_End","WriteName",0);
	SetEventHandler("KB_Update", "UpdateName", 0);	
	SetEventHandler("ShipOk","ProcessShipOk",0);
	SetEventHandler("ShipCancel","ProcessShipCancel",0);
	SetEventHandler("ShipNameChange","ProcessShipNameChange",0);
	SetEventHandler("KB_End","WriteShipName",0);
	SetEventHandler("KB_Update", "UpdateShipName", 0);
	SetEventHandler("ProfileOk","ProcessProfileOk",0);
	SetEventHandler("ProfileCancel","ProcessProfileCancel",0);
	SetEventHandler("ProfileChange","ProcessProfileChange",0);
	SetEventHandler("KB_End","WriteProfile",0);
	SetEventHandler("ConfirmYes","ProcessProfile_yes",0);
	SetEventHandler("ConfirmNo","ProcessProfile_no",0);
//MAXIMUS: new skills system -->
	SetEventHandler("IEvnt_MouseClick","IProcMouseClick",0);
	SetEventHandler("ChangerLeft","DoChangeLeft",0);
	SetEventHandler("ChangerRight","DoChangeRight",0);
	SetEventHandler("ChangeTypeLeft","DoTypeChangeLeft",0);
	SetEventHandler("ChangeTypeRight","DoTypeChangeRight",0);
	SetEventHandler("ChangeLocLeft","DoLocChangeLeft",0);
	SetEventHandler("ChangeLocRight","DoLocChangeRight",0);
	SetEventHandler("UpPress","UpProcess",0);
	SetEventHandler("DownPress","DownProcess",0);
	SetEventHandler("NationLeft","NationChangeLeft",0);
	SetEventHandler("NationRight","NationChangeRight",0);
//MAXIMUS: new skills system <--
}

void FrameProcess()
{
	if(nCurScroll!=sti(GameInterface.islandslist.current))
	{
		nCurScroll = sti(GameInterface.islandslist.current);
		SetVariable();
	}
		
	if(nCurSScrollNum!=sti(GameInterface.scrollitems.current))
	{
		nCurSScrollNum = sti(GameInterface.scrollitems.current);
		SetVariable();
	}
}

void SetNextParty(bool bRight)
{
	if(bRight)
	{
		if(curDifficulty<4) curDifficulty++;
		else curDifficulty=4; 
	}
	else
	{
		if(curDifficulty>1) curDifficulty--;
		else curDifficulty=1; 
	}
}
//changed by MAXIMUS: new skills-system -->
string GetDifficultyNameFromListNumber(int inum)
{          
	string retstr;
	switch(inum)
	{
		case 1: retstr = "Apprentice"; break;
		case 2: retstr = "Journeyman"; break;
		case 3: retstr = "Adventurer"; break;
		case 4: retstr = "Swashbuckler"; break;
		retstr = "Unknown";
	}
	return retstr;
}

void SetNextType(bool bRight)
{
	if(bRight)
	{
		if(curPlayerType<5) curPlayerType++;
		else curPlayerType=5; 
	}
	else
	{
		if(curPlayerType>1) curPlayerType--;
		else curPlayerType=1; 
	}
}

string GetPlayerTypeFromListNumber(int inum)
{          
	string retstr;
	switch(inum)
	{
		case 1: retstr = "Merchant"; break;
		case 2: retstr = "Military"; break;
		case 3: retstr = "Adventurer"; break;
		case 4: retstr = "Social climber"; break;
		case 5: retstr = "Corsair"; break;
		retstr = "Unknown";
	}
	return retstr;
}
//changed by MAXIMUS: new skills-system <--
// KK -->
string GetLocationNameFromListNumber(int inum)//changed by MAXIMUS: new skills-system -->
{
	string retstr;
	switch (inum)
	{
		case 0:	retstr = XI_DefaultStartLocationName();	break;
		case 1: retstr = FindTownName("Charlestown"); break;
		case 2:	retstr = FindTownName("Conceicao");	break;
		case 3:	retstr = FindTownName("Douwesen");	break;
		case 4:	retstr = FindTownName("Falaise de Fleur");	break;
		case 5:	retstr = FindTownName("Grand Cayman");	break;
		case 6:	retstr = FindTownName("Grand Turk");	break;
		case 7:	retstr = FindTownName("Greenford");	break;
		case 8:	retstr = FindTownName("Havana");	break;
		case 9:	retstr = FindTownName("Isla Muelle");	break;
		case 10:	retstr = FindTownName("Marigot");	break;
		case 11:	retstr = FindTownName("Oxbay");	break;
		case 12:	retstr = FindTownName("Philipsburg");	break;
		case 13:	retstr = FindTownName("Pointe a Pitre");	break;
		case 14:	retstr = FindTownName("Port au Prince");	break;
		case 15:	retstr = FindTownName("Quebradas Costillas");	break;
		case 16:	retstr = FindTownName("Redmond");	break;
		case 17:	retstr = FindTownName("Santiago");	break;
		case 18:	retstr = FindTownName("Santo Domingo");	break;
		case 19:	retstr = FindTownName("St John's");	break;
		case 20:	retstr = FindTownName("Tortuga");	break;
		// default:
			retstr = "Unknown";
	}
	return retstr;
}

void SetNextLocation(bool bRight)
{
	int bNat = 0;
	if(bRight)
	{
		if(curLocation<20) curLocation++;
		else curLocation = bNat;
	}
	else
	{
		if(curLocation>bNat) curLocation--;
		else curLocation = 20; 
	}
	tmpLocation = curLocation;
}
// <-- KK

string GetModelDescFromListNumber(int inum)
{
	int tmpDescFileID = LanguageOpenFile("models_description.txt");
	string mDescribe = "";
	if(CheckAttribute(Models[GetModelIndex(ListModels(inum))],"description")) mDescribe = LanguageConvertString(tmpDescFileID,Models[GetModelIndex(ListModels(inum))].description);
	LanguageCloseFile(tmpDescFileID);

	return mDescribe;
}

string GetModelIdFromListNumber(int inum)
{
	return Models[GetModelIndex(ListModels(inum))].id;
}

string GetModelSexFromListNumber(int inum)
{
	string chSex = CharSex;
	if(CheckAttribute(Models[GetModelIndex(ListModels(inum))],"sex")) chSex = Models[GetModelIndex(ListModels(inum))].sex;

	return chSex;
}

string GetModelAniFromListNumber(int inum)
{
	string chAni = CharAni;
	if(CheckAttribute(Models[GetModelIndex(ListModels(inum))],"ani")) chAni = Models[GetModelIndex(ListModels(inum))].ani;

	return chAni;
}

string GetModelNationFromListNumber(int inum)
{
	string chNation = CharNation;
	if(CheckAttribute(Models[GetModelIndex(ListModels(inum))],"nation")) chNation = sti(Models[GetModelIndex(ListModels(inum))].nation);

	return chNation;
}

void SetModelOldFirstNameFromListNumber(int inum, string fName)
{
	if(!CheckAttribute(Models[GetModelIndex(ListModels(inum))],"old.name")) Models[GetModelIndex(ListModels(inum))].old.name = fName;
	else Models[GetModelIndex(ListModels(inum))].old.name = fName;
}

void SetModelOldLastNameFromListNumber(int inum, string lName)
{
	if(!CheckAttribute(Models[GetModelIndex(ListModels(inum))],"old.lastname")) Models[GetModelIndex(ListModels(inum))].old.lastname = lName;
	else Models[GetModelIndex(ListModels(inum))].old.lastname = lName;
}

string GetModelOldFirstNameFromListNumber(int inum)
{
	string chFname = CharOldFirstName;
	if(CheckAttribute(Models[GetModelIndex(ListModels(inum))],"old.name")) chFname = Models[GetModelIndex(ListModels(inum))].old.name;

	return chFname;
}

string GetModelOldLastNameFromListNumber(int inum)
{
	string chLname = CharOldLastName;
	if(CheckAttribute(Models[GetModelIndex(ListModels(inum))],"old.lastname")) chLname = Models[GetModelIndex(ListModels(inum))].old.lastname;

	return chLname;
}

void SetModelFirstNameFromListNumber(int inum, string fName)
{
	if(!CheckAttribute(Models[GetModelIndex(ListModels(inum))],"name")) Models[GetModelIndex(ListModels(inum))].name = fName;
	else Models[GetModelIndex(ListModels(inum))].name = fName;
}

void SetModelLastNameFromListNumber(int inum, string lName)
{
	if(!CheckAttribute(Models[GetModelIndex(ListModels(inum))],"lastname")) Models[GetModelIndex(ListModels(inum))].lastname = lName;
	else Models[GetModelIndex(ListModels(inum))].lastname = lName;
}

string GetModelFirstNameFromListNumber(int inum)
{
	string chFname = CharFirstName;
	if(CheckAttribute(Models[GetModelIndex(ListModels(inum))],"name")) chFname = Models[GetModelIndex(ListModels(inum))].name;

	return chFname;
}

string GetModelLastNameFromListNumber(int inum)
{
	string chLname = CharLastName;
	if(CheckAttribute(Models[GetModelIndex(ListModels(inum))],"lastname")) chLname = Models[GetModelIndex(ListModels(inum))].lastname;

	return chLname;
}

void SetShipNameFromListNumber(int inum, string lName)
{
	if(!CheckAttribute(ShipsTypes[GetShipIndex(ListShips(inum))],"gameName")) ShipsTypes[GetShipIndex(ListShips(inum))].gameName = lName;
	else ShipsTypes[GetShipIndex(ListShips(inum))].gameName = lName;
}

string GetShipNameFromListNumber(int inum)
{
	string sFname = CharShipName;
	if(CheckAttribute(ShipsTypes[GetShipIndex(ListShips(inum))],"gameName")) sFname = ShipsTypes[GetShipIndex(ListShips(inum))].gameName;

	return sFname;
}

string GetShipIdFromListNumber(int inum)
{
	return ShipsTypes[GetShipIndex(ListShips(inum))].id;
}

int GetNationFromListNumber(int inum)
{
	int mNat = CharNation;
	if (inum == 6) return PERSONAL_NATION; // KK
	if(inum<6) mNat = inum;
	return mNat;
}

int GetStoreFromNation(int inum)
{
	int chStore = CharStore;
	switch(sti(GameInterface.pictires.nationPictire)) // KK
	{
		case ENGLAND: chStore = OXBAY_STORE; break;
		case FRANCE: chStore = FALAISE_DE_FLEUR_STORE; break;
		case SPAIN: chStore = ISLA_MUELLE_STORE; break;
		case PIRATE: chStore = PIRATES_STORE; break;
		case HOLLAND: chStore = DOUWESEN_STORE; break;
		case PORTUGAL: chStore = CONCEICAO_STORE; break;
		case PERSONAL_NATION: chStore = OXBAY_STORE; break; // KK
	}

	return chStore;
}

void FillScroll()
{
	string attributename1;
	string attributename2;

	for(int i = 0; i < ListModelsSize(); i++) // KK
	{
		attributename1 = "t" + sti(i+1);
		attributename2 = "pic" + sti(i+1);

		GameInterface.islandslist.ImagesGroup.(attributename1) = "FACE128_" + Models[GetModelIndex(ListModels(i))].FaceId;
		GameInterface.islandslist.(attributename2).img1 = "face";
		GameInterface.islandslist.(attributename2).tex1 = i;
		nCurScroll = 0;

		if(FindFile("RESOURCE\Textures\INTERFACES\PORTRAITS\128", "*.tga.tx", "face_"+Models[GetModelIndex(ListModels(i))].FaceId+".tga.tx")=="")
		{
			GameInterface.islandslist.ImagesGroup.(attributename1) = "EMPTYFACE";
			GameInterface.islandslist.(attributename2).img1 = "emptyface";
		}
	}

	GameInterface.islandslist.ListSize = i;

	if (nCurScroll < 0 || nCurScroll >= sti(GameInterface.islandslist.ListSize)) { nCurScroll = 0; }
	GameInterface.islandslist.current = nCurScroll;
}

void FillSScroll()
{
	nCurSScrollNum = -1;
	string attributeName;
	string shipName;
	GameInterface.scrollitems.BadPicture2 = "interfaces\blank_ship.tga";
	GameInterface.scrollitems.ImagesGroup.t0 = "ICONS";
	GameInterface.scrollitems.ImagesGroup.t1 = "SHIPS16";
	GameInterface.scrollitems.ImagesGroup.t2 = "SHIPS1";

	for(int i = 0; i < ListShipsSize(); i++) // KK
	{
		attributeName = "pic" + (i+1);

		int iShipType = GetShipIndex(ListShips(i));
		shipName = ShipsTypes[iShipType].SName;

		GameInterface.scrollitems.(attributeName).str1 = "#"+ShipsTypes[iShipType].Class;
		GameInterface.scrollitems.(attributeName).str2 = shipName;
		GameInterface.scrollitems.(attributeName).img1 = "ship back";
		GameInterface.scrollitems.(attributeName).img2 = GetShipPicName(iShipType);
		GameInterface.scrollitems.(attributeName).tex1 = 0;
		GameInterface.scrollitems.(attributeName).tex2 = 1+GetShipTexture(iShipType);
	}

	GameInterface.scrollitems.ListSize = i; // KK

	if (nCurSScrollNum < 0 || nCurSScrollNum >= sti(GameInterface.scrollitems.ListSize)) { nCurSScrollNum = 0; }
	GameInterface.scrollitems.current = nCurSScrollNum;
}

void FillNScroll()
{
	GameInterface.scrollnations.ImagesGroup.t0 = "ICONS";
	GameInterface.scrollnations.ImagesGroup.t1 = "NATIONS_1";
	GameInterface.scrollnations.ImagesGroup.t2 = "NATIONS_2";
	GameInterface.scrollnations.ImagesGroup.t3 = "NATIONS_3";
	GameInterface.scrollnations.ImagesGroup.t4 = "SMALL_NATION_ICONS";

	GameInterface.scrollnations.pic1.img1 = "ship back";
	GameInterface.scrollnations.pic1.img2 = "England";
	GameInterface.scrollnations.pic1.tex1 = 0;
	GameInterface.scrollnations.pic1.tex2 = 2;

	GameInterface.scrollnations.pic2.img1 = "ship back";
	GameInterface.scrollnations.pic2.img2 = "France";
	GameInterface.scrollnations.pic2.tex1 = 0;
	GameInterface.scrollnations.pic2.tex2 = 2;

	GameInterface.scrollnations.pic3.img1 = "ship back";
	GameInterface.scrollnations.pic3.img2 = "Spain";
	GameInterface.scrollnations.pic3.tex1 = 0;
	GameInterface.scrollnations.pic3.tex2 = 1;

	GameInterface.scrollnations.pic4.img1 = "ship back";
	GameInterface.scrollnations.pic4.img2 = "Pirate";
	GameInterface.scrollnations.pic4.tex1 = 0;
	GameInterface.scrollnations.pic4.tex2 = 2;

	GameInterface.scrollnations.pic5.img1 = "ship back";
	GameInterface.scrollnations.pic5.img2 = "Holland";
	GameInterface.scrollnations.pic5.tex1 = 0;
	GameInterface.scrollnations.pic5.tex2 = 2;

	GameInterface.scrollnations.pic6.img1 = "ship back";
	GameInterface.scrollnations.pic6.img2 = "Portugal";
	GameInterface.scrollnations.pic6.tex1 = 0;
	GameInterface.scrollnations.pic6.tex2 = 1;

// KK -->
	GameInterface.scrollnations.pic7.img1 = "ship back";
	GameInterface.scrollnations.pic7.img2 = "PERSONAL_NATION";
	GameInterface.scrollnations.pic7.tex1 = 0;
	GameInterface.scrollnations.pic7.tex2 = 4;

	GameInterface.scrollnations.ListSize = 7;
	nCurNScrollNum = 6;
// <-- KK

	if (nCurNScrollNum < 0 || nCurNScrollNum >= sti(GameInterface.scrollnations.ListSize)) { nCurNScrollNum = 0; }
	GameInterface.scrollnations.current = nCurNScrollNum;
}

bool FindImage(string textPath, string textName)
{
	object LocDirectory;
	DeleteAttribute(&LocDirectory, "");

	LocDirectory.dir = textPath;
	LocDirectory.mask = "*.tga.tx";
	CreateEntity(&LocDirectory,"FINDFILESINTODIRECTORY");
	DeleteClass(&LocDirectory);
	
	aref bImage; makearef(bImage, LocDirectory.filelist);
	for(int i=0; i<GetAttributesNum(bImage); i++)
	{
		aref curRef = GetAttributeN(bImage, i);
		string curImage = GetAttributeValue(curRef);

		if(strleft(curImage, sti(strlen(curImage)-strlen(LocDirectory.mask))+1)==textName) return true;
	}
	return false;
}

void CheckNation()
{
	GameInterface.pictires.nationPictire = GetModelNationFromListNumber(nCurScroll);
	SetNewFlagImage(sti(GameInterface.pictires.nationPictire));
}

void SetNextNationUp(int curNation)
{
	if (bKeyboardEnabled) return;
	if(curNation==10) curNation = -1;
	if(curNation>=-1 && curNation<5) curNation++;
	else curNation = 10;
	SetNewFlagImage(curNation);
}

void SetNextNationDown(int curNation)
{
	if (bKeyboardEnabled) return;
	if(curNation==10) curNation = 6;
	if(curNation>0 && curNation<=6) curNation--;
	else curNation = 10;
	SetNewFlagImage(curNation);
}

void SetNewFlagImage(int curNation)
{
	string imageName = GetNationNameByType(curNation);
	if(imageName=="unknown") imageName = "PERSONAL_NATION";
	if(imageName=="Britain") imageName = "England";
	CreateImage("nationPictire",GetTextureImage(curNation),imageName,304,127,336,159);
	GameInterface.pictires.nationPictire = curNation;
	SetNodeUsing("LOCA_CHANGER", bLocationChange(curNation));
}

string GetTextureImage(int curNation)
{
	string nationTexture = curNation;
	switch(curNation)
	{
		case ENGLAND: nationTexture = "NATIONS_2"; break;
		case FRANCE: nationTexture = "NATIONS_2"; break;
		case SPAIN: nationTexture = "NATIONS_1"; break;
		case PIRATE: nationTexture = "NATIONS_2"; break;
		case HOLLAND: nationTexture = "NATIONS_2"; break;
		case PORTUGAL: nationTexture = "NATIONS_1"; break;
		case PERSONAL_NATION: nationTexture = "SMALL_NATION_ICONS"; break;
		case CATALONIA: nationTexture = "SMALL_NATION_ICONS"; break;
		case NEUTRAL_NATION: nationTexture = "SMALL_NATION_ICONS"; break;
		case UNKNOWN_NATION: nationTexture = "SMALL_NATION_ICONS"; break;
		case BROKEN: nationTexture = "SMALL_NATION_ICONS"; break;
	}

	return nationTexture;
}

bool bLocationChange(int nat)
{
	if(nat!=PERSONAL_NATION)
	{
		curLocation = 0;
		GameInterface.strings.LocName = TranslateString("",GetLocationNameFromListNumber(curLocation));
		return false;
	}

	curLocation = tmpLocation;
	GameInterface.strings.LocName = TranslateString("",GetLocationNameFromListNumber(curLocation));
	return true;
}

void SetVariable()
{
	if(GetCurrentNode()=="ISLANDSLIST") { CheckNation(); }
	SetNodeUsing("TYPE_CHANGER",AUTO_SKILL_SYSTEM);
	string nodName = GetCurrentNode();
	bBeParty = true;
	totalInfo = GetModelDescFromListNumber(nCurScroll);
	SetFormatedText("INFO_TEXT",totalInfo);
	SendMessage(&GameInterface,"lsl",MSG_INTERFACE_MSG_TO_NODE,"INFO_TEXT",5);
	string namestr = "";
	if(CheckAttribute(Models[GetModelIndex(ListModels(nCurScroll))],"name")) namestr = GetModelFirstNameFromListNumber(nCurScroll) + " ";
	else namestr = CharFirstName + " ";
	if(CheckAttribute(Models[GetModelIndex(ListModels(nCurScroll))],"lastname")) namestr += GetModelLastNameFromListNumber(nCurScroll);
	else namestr += CharLastName;
	GameInterface.strings.CharacterName = namestr;
	GameInterface.strings.ShipName = GetShipNameFromListNumber(nCurSScrollNum);
	GameInterface.strings.ProfileName = TempPlayerProfileName;
	charProfile = TempPlayerProfileName;
//MAXIMUS: new skills-system -->
	GameInterface.strings.DifName = XI_ConvertString(GetDifficultyNameFromListNumber(curDifficulty));
	string charType = XI_ConvertString("i"+"Neutral");
	if(AUTO_SKILL_SYSTEM)
	{
		charType = XI_ConvertString(GetPlayerTypeFromListNumber(curPlayerType));
		SetCharacterSkillBonus(GetPlayerTypeFromListNumber(curPlayerType));
	}
	GameInterface.strings.PlrType = charType;
//MAXIMUS: new skills-system <--
// KK -->
	GameInterface.strings.LocName = TranslateString("",GetLocationNameFromListNumber(curLocation));//changed by MAXIMUS <--
// <-- KK
	SetNewPicture("FONPICT", TEXTUREPATH + "qdeck.tga");
	if(FindImage("RESOURCE\TEXTURES\"+TEXTUREPATH,ListModels(nCurScroll))) SetNewPicture("CHARPICT", TEXTUREPATH + ListModels(nCurScroll) + ".tga");
	SetNodeUsing("CHARPICT", FindImage("RESOURCE\TEXTURES\"+TEXTUREPATH,ListModels(nCurScroll)));

	switch(sti(GameInterface.pictires.nationPictire)) // KK
	{
		case ENGLAND: 
			switch(Rand(1))
			{
			    case 0: CharGood1 = Islands[FindIsland("Oxbay")].Trade.Import.id1; break;
			    case 1: CharGood1 = Islands[FindIsland("Oxbay")].Trade.Import.id3; break;
			}
			switch(Rand(1))
			{
			    case 0: CharGood2 = Islands[FindIsland("Oxbay")].Trade.Import.id2; break;
			    case 1: CharGood2 = Islands[FindIsland("Oxbay")].Trade.Import.id4; break;
			}
		break;
		case FRANCE: 
			switch(Rand(1))
			{
			    case 0: CharGood1 = Islands[FindIsland("FalaiseDeFleur")].Trade.Import.id1; break;
			    case 1: CharGood1 = Islands[FindIsland("FalaiseDeFleur")].Trade.Import.id3; break;
			}
			switch(Rand(1))
			{
			    case 0: CharGood2 = Islands[FindIsland("FalaiseDeFleur")].Trade.Import.id2; break;
			    case 1: CharGood2 = Islands[FindIsland("FalaiseDeFleur")].Trade.Import.id4; break;
			}
		break;
		case SPAIN: 
			switch(Rand(1))
			{
			    case 0: CharGood1 = Islands[FindIsland("IslaMuelle")].Trade.Import.id1; break;
			    case 1: CharGood1 = Islands[FindIsland("IslaMuelle")].Trade.Import.id3; break;
			}
			switch(Rand(1))
			{
			    case 0: CharGood2 = Islands[FindIsland("IslaMuelle")].Trade.Import.id2; break;
			    case 1: CharGood2 = Islands[FindIsland("IslaMuelle")].Trade.Import.id4; break;
			}
		break;
		case PIRATE: 
			switch(Rand(10))
			{
				case 0: CharGood1 = GOOD_SAILCLOTH; break;
			    case 1: CharGood1 = GOOD_PLANKS; break;
			    case 2: CharGood1 = GOOD_WHEAT; break;
			    case 3: CharGood1 = GOOD_EBONY; break;
			    case 4: CharGood1 = GOOD_CHOCOLATE; break;
			    case 5: CharGood1 = GOOD_SUGAR; break;
			    case 6: CharGood1 = GOOD_WINE; break;
			    case 7: CharGood1 = GOOD_LINEN; break;
			    case 8: CharGood1 = GOOD_RUM; break;
			    case 9: CharGood1 = GOOD_TOBACCO; break;
			    case 10: CharGood1 = GOOD_COFFEE; break;
			}
			switch(Rand(11))
			{
			    case 0: CharGood2 = GOOD_MAHOGANY; break;
			    case 1: CharGood2 = GOOD_CINNAMON; break;
			    case 2: CharGood2 = GOOD_COPRA; break;
			    case 3: CharGood2 = GOOD_PAPRIKA; break;
			    case 4: CharGood2 = GOOD_FRUITS; break;
			    case 5: CharGood2 = GOOD_ALE; break;
			    case 6: CharGood2 = GOOD_SILK; break;
			    case 7: CharGood2 = GOOD_CLOTHES; break;
			    case 8: CharGood2 = GOOD_COTTON; break;
			    case 9: CharGood2 = GOOD_SANDAL; break;
			    case 10: CharGood2 = GOOD_LEATHER; break;
			    case 11: CharGood2 = GOOD_OIL; break;
			}
		break;
		case HOLLAND:
			switch(Rand(1))
			{
			    case 0: CharGood1 = Islands[FindIsland("Douwesen")].Trade.Import.id1; break;
			    case 1: CharGood1 = Islands[FindIsland("Douwesen")].Trade.Import.id3; break;
			}
			switch(Rand(1))
			{
			    case 0: CharGood2 = Islands[FindIsland("Douwesen")].Trade.Import.id2; break;
			    case 1: CharGood2 = Islands[FindIsland("Douwesen")].Trade.Import.id4; break;
			}
		break;
		case PORTUGAL: 
			switch(Rand(1))
			{
			    case 0: CharGood1 = Islands[FindIsland("Conceicao")].Trade.Import.id1; break;
			    case 1: CharGood1 = Islands[FindIsland("Conceicao")].Trade.Import.id3; break;
			}
			switch(Rand(1))
			{
			    case 0: CharGood2 = Islands[FindIsland("Conceicao")].Trade.Import.id2; break;
			    case 1: CharGood2 = Islands[FindIsland("Conceicao")].Trade.Import.id4; break;
			}
		break;
// KK -->
		case PERSONAL_NATION:
			string island = "";
			string import = "Import";
			CharGood1 = 0;
			CharGood2 = 0;

			switch (curLocation) {
				case 0: island = "Oxbay"; break;
				case 1: island = "Conceicao"; break;
				case 2: island = "Douwesen"; break;
				case 3: island = "FalaiseDeFleur"; break;
				case 4: island = "Cayman"; break;
				case 5: island = "Turks"; break;
				case 6: island = "Oxbay"; break;
				case 7: island = "Cuba"; break;
				case 8: island = "IslaMuelle"; break;
				case 9: island = "SaintMartin"; break;
				case 10: island = "Oxbay"; break;
				case 11: island = "SaintMartin"; break;
				case 12: island = "Guadeloupe"; break;
				case 13: island = "Hispaniola"; break;
				case 14:
					switch(Rand(10))
					{
						case 0: CharGood1 = GOOD_SAILCLOTH; break;
					    case 1: CharGood1 = GOOD_PLANKS; break;
					    case 2: CharGood1 = GOOD_WHEAT; break;
					    case 3: CharGood1 = GOOD_EBONY; break;
					    case 4: CharGood1 = GOOD_CHOCOLATE; break;
					    case 5: CharGood1 = GOOD_SUGAR; break;
					    case 6: CharGood1 = GOOD_WINE; break;
					    case 7: CharGood1 = GOOD_LINEN; break;
					    case 8: CharGood1 = GOOD_RUM; break;
					    case 9: CharGood1 = GOOD_TOBACCO; break;
					    case 10: CharGood1 = GOOD_COFFEE; break;
					}
					switch(Rand(11))
					{
					    case 0: CharGood2 = GOOD_MAHOGANY; break;
					    case 1: CharGood2 = GOOD_CINNAMON; break;
					    case 2: CharGood2 = GOOD_COPRA; break;
					    case 3: CharGood2 = GOOD_PAPRIKA; break;
					    case 4: CharGood2 = GOOD_FRUITS; break;
					    case 5: CharGood2 = GOOD_ALE; break;
					    case 6: CharGood2 = GOOD_SILK; break;
					    case 7: CharGood2 = GOOD_CLOTHES; break;
					    case 8: CharGood2 = GOOD_COTTON; break;
					    case 9: CharGood2 = GOOD_SANDAL; break;
					    case 10: CharGood2 = GOOD_LEATHER; break;
					    case 11: CharGood2 = GOOD_OIL; break;
					}
				break;
				case 15: island = "Redmond"; break;
				case 16: island = "Cuba"; break;
				case 17: island = "Hispaniola"; break;
				case 18: island = "Antigua"; import = "Contraband"; break;
				case 19: island = "Hispaniola"; break;
			}
			if (island != "") {
				switch(Rand(1)) {
				    case 0: CharGood1 = Islands[FindIsland(island)].Trade.(import).id1; break;
				    case 1: CharGood1 = Islands[FindIsland(island)].Trade.(import).id3; break;
				}
				switch(Rand(1)) {
				    case 0: CharGood2 = Islands[FindIsland(island)].Trade.(import).id2; break;
				    case 1: CharGood2 = Islands[FindIsland(island)].Trade.(import).id4; break;
				}
			}
		break;
// <-- KK
	}

// fixed by MAXIMUS 21.07.06 -->
	// if CHOOSABLE_NEWGAMESKILLS is ON  - player is given one or two extra skill points to use where they want it 
	// if CHOOSABLE_NEWGAMESKILLS is OFF - it does this randomized method that is done by re-selecting characters
	if(nodName=="ISLANDSLIST")
	{
		// TIH -->
			CharLeadership 	= 1;
			CharFencing 	= 1;
			CharSailing 	= 1;
			CharCannons 	= 1;
			CharAccuracy 	= 1;
			CharGrappling 	= 1;
			CharRepair 		= 1;
			CharDefence 	= 1;
			CharSneak 		= 1;
			CharCommerce 	= 1;
		// TIH <--
		if(!CHOOSABLE_NEWGAMESKILLS)
		{
			switch(Rand(3))
			{
				case 0: { CharLeadership = 2; CharSailing = 1; CharCannons = 1; CharRepair = 1; } break;
				case 1: { CharSailing = 2; CharCannons = 1; CharRepair = 1; CharLeadership = 1; } break;
				case 2: { CharCannons = 2; CharRepair = 1; CharLeadership = 1; CharSailing = 1; } break;
				case 3: { CharRepair = 2; CharLeadership = 1; CharSailing = 1; CharCannons = 1; } break;
			}
			switch(Rand(3))
			{
				case 0: { CharFencing = 2; CharAccuracy = 1; CharGrappling = 1; CharDefence = 1; } break;
				case 1: { CharAccuracy = 2; CharGrappling = 1; CharDefence = 1; CharFencing = 1; } break;
				case 2: { CharGrappling = 2; CharDefence = 1; CharFencing = 1; CharAccuracy = 1; } break;
				case 3: { CharDefence = 2; CharFencing = 1; CharAccuracy = 1; CharGrappling = 1; } break;
			}
		}
	}
	// TIH <--
// fixed by MAXIMUS 21.07.06 <--

	SetSkillShow(SKILL_LEADERSHIP,CharLeadership);
	SetSkillShow(SKILL_FENCING,CharFencing);
	SetSkillShow(SKILL_SAILING,CharSailing);
	SetSkillShow(SKILL_ACCURACY,CharAccuracy);
	SetSkillShow(SKILL_CANNONS,CharCannons);
	SetSkillShow(SKILL_GRAPPLING,CharGrappling);
	SetSkillShow(SKILL_REPAIR,CharRepair);
	SetSkillShow(SKILL_DEFENCE,CharDefence);

	string mSex = GetModelSexFromListNumber(nCurScroll);

	if(mSex=="woman") { SetSkillShow(SKILL_COMMERCE,CharCommerce+1); SetSkillShow(SKILL_SNEAK,CharSneak+1); }
	else { SetSkillShow(SKILL_COMMERCE,CharCommerce); SetSkillShow(SKILL_SNEAK,CharSneak); }

	if(oldCurNode=="RENAMEBOX" || oldCurNode=="RENAMEBOX1")
	{
	  if(nodName=="ISLANDSLIST" || nodName=="SCROLLITEMS")
	  {
		KB_SetKeyboardMode(false);
		GameInterface.strings.CharacterName = GetModelFirstNameFromListNumber(nCurScroll) + " " + GetModelLastNameFromListNumber(nCurScroll);
		GameInterface.strings.ShipName = GetShipNameFromListNumber(nCurSScrollNum);
		SetNodeUsing("BOX",false);
		SetNodeUsing("BOX1",false);
	  }
	}
}
//MAXIMUS: new skills-system -->
void SetCharacterSkillBonus(string playerType)
{
	if(SKILLS_UP_BONUS<10) SKILLS_UP_BONUS = 10;
	if(SKILLS_UP_BONUS>99) SKILLS_UP_BONUS = 99;
	float curSpeed = makefloat(stf(SKILLS_UP_BONUS+100)/100);

	CharBonusDifficulty = 1.0;
	CharBonusLeadership = 1.0;
	CharBonusFencing = 1.0;
	CharBonusSailing = 1.0;
	CharBonusAccuracy = 1.0;
	CharBonusCannons = 1.0;
	CharBonusGrappling = 1.0;
	CharBonusRepair = 1.0;
	CharBonusDefence = 1.0;
	CharBonusCommerce = 1.0;
	CharBonusSneak = 1.0;

	switch(playerType)
	{
		case "Merchant": CharBonusSailing = curSpeed; CharBonusCommerce = curSpeed; break;
		case "Military": CharBonusAccuracy = curSpeed; CharBonusDefence = curSpeed; break;
		case "Adventurer": CharBonusFencing = curSpeed; CharBonusSneak = curSpeed; break;
		case "Social climber": CharBonusLeadership = curSpeed; CharBonusRepair = curSpeed; break;
		case "Corsair": CharBonusCannons = curSpeed; CharBonusGrappling = curSpeed; break;
	}

	SetBonusShow(SKILL_LEADERSHIP,CharBonusLeadership);
	SetBonusShow(SKILL_FENCING,CharBonusFencing);
	SetBonusShow(SKILL_SAILING,CharBonusSailing);
	SetBonusShow(SKILL_ACCURACY,CharBonusAccuracy);
	SetBonusShow(SKILL_CANNONS,CharBonusCannons);
	SetBonusShow(SKILL_GRAPPLING,CharBonusGrappling);
	SetBonusShow(SKILL_REPAIR,CharBonusRepair);
	SetBonusShow(SKILL_DEFENCE,CharBonusDefence);
	SetBonusShow(SKILL_COMMERCE,CharBonusCommerce);
	SetBonusShow(SKILL_SNEAK,CharBonusSneak);
}

void IProcMouseClick()
{
	string nodName = GetEventData();
	int btnCode = GetEventData();

	if(nodName=="DIFF_CHANGER")
	{
		if(btnCode==0) DoChangeLeft();
		if(btnCode==1) DoChangeRight();
	}

	if(nodName=="TYPE_CHANGER")
	{
		if(btnCode==0) DoTypeChangeLeft();
		if(btnCode==1) DoTypeChangeRight();
	}

	if(nodName=="LOCA_CHANGER")
	{
		if(btnCode==0) DoLocChangeLeft();
		if(btnCode==1) DoLocChangeRight();
	}

	if(nodName=="NATION_CHANGER")
	{
		if(btnCode==0) NationChangeLeft();
		if(btnCode==1) NationChangeRight();
	}
}

void DoChangeLeft()
{
	if (bKeyboardEnabled) return; // KK
	if(bBeParty)
	{
		SetNextParty(false);
		GameInterface.strings.DifName = XI_ConvertString(GetDifficultyNameFromListNumber(curDifficulty));
	}
}

void DoChangeRight()
{
	if (bKeyboardEnabled) return; // KK
	if(bBeParty)
	{
		SetNextParty(true);
		GameInterface.strings.DifName = XI_ConvertString(GetDifficultyNameFromListNumber(curDifficulty));
	}
}

void DoTypeChangeLeft()
{
	if (bKeyboardEnabled) return; // KK
	if(bBeParty)
	{
		SetNextType(false);
		GameInterface.strings.PlrType = XI_ConvertString(GetPlayerTypeFromListNumber(curPlayerType));
		SetCharacterSkillBonus(GetPlayerTypeFromListNumber(curPlayerType));
	}
}

void DoTypeChangeRight()
{
	if (bKeyboardEnabled) return; // KK
	if(bBeParty)
	{
		SetNextType(true);
		GameInterface.strings.PlrType = XI_ConvertString(GetPlayerTypeFromListNumber(curPlayerType));
		SetCharacterSkillBonus(GetPlayerTypeFromListNumber(curPlayerType));
	}
}

void DoLocChangeLeft()
{
	if (bKeyboardEnabled) return; // KK
	if(bBeParty)
	{
		SetNextLocation(false);
		GameInterface.strings.LocName = TranslateString("",GetLocationNameFromListNumber(curLocation));
	}
}

void DoLocChangeRight()
{
	if (bKeyboardEnabled) return; // KK
	if(bBeParty)
	{
		SetNextLocation(true);
		GameInterface.strings.LocName = TranslateString("",GetLocationNameFromListNumber(curLocation));
	}
}

void NationChangeLeft()
{
	if(bKeyboardEnabled) return;
	if(bBeParty)
	{
		SetNextNationDown(sti(GameInterface.pictires.nationPictire));
	}
}

void NationChangeRight()
{
	if(bKeyboardEnabled) return;
	if(bBeParty)
	{
		SetNextNationUp(sti(GameInterface.pictires.nationPictire));
	}
}

void UpProcess()
{
	if (bKeyboardEnabled) return; // KK
	string tmp = NextUp(GetCurrentNode());
	SetCurrentNode(tmp);
}

void DownProcess()
{
	if (bKeyboardEnabled) return; // KK
	string tmp = NextDown(GetCurrentNode());
	SetCurrentNode(tmp);
}

string NextUp(string curNod)
{
	switch(curNod)
	{
	case "ISLANDSLIST":
		if(GetSelectable("B_START")==true) return "B_START";
		else return NextUp("B_START");
		break;
	case "NATION_CHANGER":
		if(GetSelectable("ISLANDSLIST")==true) return "ISLANDSLIST";
		else return NextUp("ISLANDSLIST");
		break;
	case "LOCA_CHANGER":
		if(GetSelectable("NATION_CHANGER")==true) return "NATION_CHANGER";
		else return NextUp("NATION_CHANGER");
		break;
	case "DIFF_CHANGER":
		if(GetSelectable("LOCA_CHANGER")==true) return "LOCA_CHANGER";
		else return NextUp("LOCA_CHANGER");
		break;
	case "TYPE_CHANGER":
		if(GetSelectable("DIFF_CHANGER")==true) return "DIFF_CHANGER";
		else return NextUp("DIFF_CHANGER");
		break;
	case "SCROLLITEMS":
		if(GetSelectable("TYPE_CHANGER")==true) return "TYPE_CHANGER";
		else return NextUp("TYPE_CHANGER");
		break;
	case "B_START":
		if(GetSelectable("SCROLLITEMS")==true) return "SCROLLITEMS";
		else return NextUp("SCROLLITEMS");
		break;
	}
	return " ";
}

string NextDown(string curNod)
{
	switch(curNod)
	{
	case "ISLANDSLIST":
		if(GetSelectable("NATION_CHANGER")==true) return "NATION_CHANGER";
		else return NextDown("NATION_CHANGER");
		break;
	case "NATION_CHANGER":
		if(GetSelectable("LOCA_CHANGER")==true)	return "LOCA_CHANGER";
		else return NextDown("LOCA_CHANGER");
		break;
	case "LOCA_CHANGER":
		if(GetSelectable("DIFF_CHANGER")==true)	return "DIFF_CHANGER";
		else return NextDown("DIFF_CHANGER");
		break;
	case "DIFF_CHANGER":
		if(GetSelectable("TYPE_CHANGER")==true) return "TYPE_CHANGER";
		else return NextDown("TYPE_CHANGER");
		break;
	case "TYPE_CHANGER":
		if(GetSelectable("SCROLLITEMS")==true) return "SCROLLITEMS";
		else return NextDown("SCROLLITEMS");
		break;
	case "SCROLLITEMS":
		if(GetSelectable("B_START")==true) return "B_START";
		else return NextDown("B_START");
		break;
	case "B_START":
		if(GetSelectable("ISLANDSLIST")==true) return "ISLANDSLIST";
		else return NextDown("ISLANDSLIST");
		break;
	}
	return " ";
}

void SetBonusShow(string skillName, float bonusVal)
{
	string bonusName = "BONUS_" + skillName;
	GameInterface.strings.(bonusName) = "x"+bonusVal;
}
//MAXIMUS: new skills-system <--
void SetSkillShow(string skillName, int skillVal)
{
	GameInterface.strings.(skillName) = skillVal;
	int color = COLOR_NORMAL;
	if(skillVal==SKILL_MAX)	color = COLOR_MONEY;
	ChangeStringColor(skillName,SetAlphaIntoColor(color,GetAlphaFromSkill(skillVal)));
}

int SetAlphaIntoColor(int col, int alpha)
{
	int newCol = and(col,16777215) + shl(alpha,24);
	return newCol;
}

int GetAlphaFromSkill(int nskill)
{
	switch(nskill)
	{
	case 0:		return 55;	break;
	case 1:		return 75;	break;
	case 2:		return 95;	break;
	case 3:		return 115;	break;
	case 4:		return 135;	break;
	case 5:		return 155;	break;
	case 6:		return 175;	break;
	case 7:		return 195;	break;
	case 8:		return 215;	break;
	case 9:		return 235;	break;
	case 10:	return 255;	break;
	}
	return 0;
}

void ProcessNodeOk()
{
	string nodName = GetEventData();
	//SendMessage(&GameInterface,"ll", MSG_INTERFACE_LOCK_NODE, 0);
	if( CheckAttribute(&GameInterface,nodName+".strdata") )
	{
		string str = GameInterface.(nodName).strdata;
		SetMainCharacterName(str);
		GameInterface.strings.CharacterName = GetModelFirstNameFromListNumber(nCurScroll) + " " + GetModelLastNameFromListNumber(nCurScroll);
	}
	DeleteAttribute(&GameInterface,nodName+".strdata");
}

void ProcessNodeCancel()
{
	string nodName = GetEventData();
	//SendMessage(&GameInterface,"ll", MSG_INTERFACE_LOCK_NODE, 0);
	DeleteAttribute(&GameInterface,nodName+".strdata");
	GameInterface.strings.CharacterName = GetModelFirstNameFromListNumber(nCurScroll) + " " + GetModelLastNameFromListNumber(nCurScroll);
	SetCurrentNode("BOX");
	bProfile = false;
}

void ProcessCharNameChange()
{
	SetNodeUsing("BOX1",false);
	//SetCurrentNode("RENAMEBOX");
	ChangeStringColor("CharacterName", COLOR_MONEY);
	GameInterface.strings.CharacterName = GetModelFirstNameFromListNumber(nCurScroll) + " " + GetModelLastNameFromListNumber(nCurScroll);// + "_";
	SetNodeUsing("BOX",true);
// KK -->
	SendMessage(&GameInterface,"lls", MSG_INTERFACE_LOCK_NODE, 1, "BOX");
	SetCurrentNode("BOX");
// <-- KK
	KB_SetKeyboardMode(true);
	oldCurNode="RENAMEBOX";
	bProfile = true;

	KeyboardString = "";
}

void UpdateName()
{
	if(GetCurrentNode() == "BOX") GameInterface.strings.CharacterName = KeyboardString; // KK
}

void WriteName()
{
	if(GetCurrentNode() == "BOX") // KK
	{
		if(KeyboardString != "")
		{
			SetMainCharacterName(KeyboardString);
			GameInterface.strings.CharacterName = KeyboardString;
		}
		else
		{
			GameInterface.strings.CharacterName = GetModelFirstNameFromListNumber(nCurScroll) + " " + GetModelLastNameFromListNumber(nCurScroll);
			ProcessNodeCancel();
		}
		SetNodeUsing("BOX",false);
	}
	ChangeStringColor("CharacterName", COLOR_NORMAL);
}

void ProcessShipOk()
{
	string nodName = GetEventData();
	//SendMessage(&GameInterface,"ll", MSG_INTERFACE_LOCK_NODE, 0);
	if( CheckAttribute(&GameInterface,nodName+".strdata") )
	{
		string str = GameInterface.(nodName).strdata;
		SetShipNameFromListNumber(nCurScroll, str);
		GameInterface.strings.ShipName = GetShipNameFromListNumber(nCurSScrollNum);
	}
	DeleteAttribute(&GameInterface,nodName+".strdata");
}

void ProcessShipCancel()
{
	string nodName = GetEventData();
	//SendMessage(&GameInterface,"ll", MSG_INTERFACE_LOCK_NODE, 0);
	DeleteAttribute(&GameInterface,nodName+".strdata");
	GameInterface.strings.ShipName = GetShipNameFromListNumber(nCurSScrollNum);
	bProfile = false;
	SetCurrentNode("BOX1");
}

void ProcessShipNameChange()
{
	SetNodeUsing("BOX",false);
	SetCurrentNode("RENAMEBOX1");
	ChangeStringColor("ShipName", COLOR_MONEY);
	GameInterface.strings.ShipName = GetShipNameFromListNumber(nCurSScrollNum);//+"_";
	SetNodeUsing("BOX1",true);
// KK -->
	SendMessage(&GameInterface,"lls", MSG_INTERFACE_LOCK_NODE, 1, "BOX1");
	SetCurrentNode("BOX1"); 
// <-- KK
	KB_SetKeyboardMode(true);
	oldCurNode="RENAMEBOX1";
	bProfile = true;

	KeyboardString = "";
}

void UpdateShipName()
{
	if(GetCurrentNode() == "BOX1") GameInterface.strings.ShipName = KeyboardString; // KK
}

void WriteShipName()
{
	if(GetCurrentNode()=="BOX1") // KK
	{
		if(KeyboardString!="")
		{
			SetShipNameFromListNumber(nCurSScrollNum, KeyboardString);
			GameInterface.strings.ShipName = KeyboardString;
		}
		else
		{
			GameInterface.strings.ShipName = GetShipNameFromListNumber(nCurSScrollNum);
			ProcessShipCancel();
		}
		SetNodeUsing("BOX1",false);
	}
	ChangeStringColor("ShipName", COLOR_NORMAL);
}

void ProcessProfileOk()
{
	string nodName = GetEventData();
	if(CheckAttribute(&GameInterface,nodName+".strdata"))
	{
		string str = GameInterface.(nodName).strdata;
		GameInterface.strings.ProfileName = TempPlayerProfileName;
	}
	DeleteAttribute(&GameInterface,nodName+".strdata");
}

void ProcessProfileCancel()
{
	string nodName = GetEventData();
	DeleteAttribute(&GameInterface,nodName+".strdata");
	GameInterface.strings.ProfileName = TempPlayerProfileName;
	if(CheckAttribute(&GameInterface,"tempLang")) DeleteAttribute(&GameInterface,"tempLang");
	bProfile = false;
	SetCurrentNode("BOX2");
	SetVariable();
}

void ProcessProfileChange()
{
	SetNodeUsing("BOX",false);
	SetNodeUsing("BOX1",false);
	ChangeStringColor("ProfileName", COLOR_MONEY);
	GameInterface.strings.ProfileName = TempPlayerProfileName+"_";
	SendMessage(&GameInterface,"lls", MSG_INTERFACE_LOCK_NODE, 1, "BOX2");
	SetCurrentNode("BOX2");	
	bProfile = true;
	GameInterface.tempLang = "English";
	KB_SetKeyboardMode(true);

	KeyboardString = "";
	UpdateTime1();
}

void WriteProfile()
{
	if(GetCurrentNode()=="BOX2")
	{
		if(KeyboardString != "")
		{
			GameInterface.strings.ProfileName = KeyboardString;
			CheckProfiles(GameInterface.strings.ProfileName);
		}
		else
		{
			GameInterface.strings.ProfileName = TempPlayerProfileName;
			ProcessProfileCancel();
			ChangeStringColor("ProfileName", COLOR_NORMAL);
		}
	}
}

#event_handler("UpdateTimeIn", "UpdateTime1");
void UpdateTime1()
{
	if(!bProfile) return;
	switch(GetCurrentNode())
	{
		case "BOX":
			tempString = GetModelFirstNameFromListNumber(nCurScroll) + " " + GetModelLastNameFromListNumber(nCurScroll)+" ";
			if(KeyboardString!="") tempString = KeyboardString+" ";
			GameInterface.strings.CharacterName = tempString;
		break;

		case "BOX1":
			tempString = GetShipNameFromListNumber(nCurSScrollNum)+" ";
			if(KeyboardString!="") tempString = KeyboardString+" ";
			GameInterface.strings.ShipName = tempString;
		break;

		case "BOX2":
			tempString = TempPlayerProfileName;
			if(KeyboardString!="") tempString = KeyboardString;
			GameInterface.strings.ProfileName = tempString;
		break;
	}
	PostEvent("UpdateTimeOut", 350);
}

#event_handler("UpdateTimeOut", "UpdateTime2");
void UpdateTime2()
{
	if(!bProfile) return;
	switch(GetCurrentNode())
	{
		case "BOX":
			tempString = GetModelFirstNameFromListNumber(nCurScroll) + " " + GetModelLastNameFromListNumber(nCurScroll)+"_";
			if(KeyboardString!="") tempString = KeyboardString+"_";
			GameInterface.strings.CharacterName = tempString;
		break;

		case "BOX1":
			tempString = GetShipNameFromListNumber(nCurSScrollNum)+"_";
			if(KeyboardString!="") tempString = KeyboardString+"_";
			GameInterface.strings.ShipName = tempString;
		break;

		case "BOX2":
			tempString = TempPlayerProfileName+"_";
			if(KeyboardString!="") tempString = KeyboardString+"_";
			GameInterface.strings.ProfileName = tempString;
		break;
	}
	PostEvent("UpdateTimeIn", 350);
}

bool bProfile = false;
string tempString;
string oldProfile;
string charProfile = DEFAULT_NAME;

void CheckProfiles(string curProfile)
{
	oldProfile = TempPlayerProfileName;
	TempPlayerProfileName = curProfile;
	ProcessProfileCancel();

	string tmpStr,profName;
	aref arProfilesRoot;

	makearef(arProfilesRoot,PlayerProfile.profiles);
	for(int i=0; i<GetAttributesNum(arProfilesRoot); i++)
	{
		profName = GetAttributeName(GetAttributeN(arProfilesRoot,i));
		if(profName==curProfile) { PostEvent("DisableShow", 150); return; }
	}
	charProfile = TempPlayerProfileName;
//	PlayerProfile.profiles.(curProfile) = true;
	ChangeStringColor("ProfileName", COLOR_NORMAL);
	SetVariable();
}

#event_handler("DisableShow", "DisableWindow");
void DisableWindow()
{
	SetSelectable("EXIT_BUTTON",false);
	SetSelectable("ISLANDSLIST",false);
	SetSelectable("LEFTSCROLLBUTTON",false);
	SetSelectable("RIGHTSCROLLBUTTON",false);
	SetSelectable("SCROLLITEMS",false);
	SetSelectable("LEFTSCROLLBUTTON1",false);
	SetSelectable("RIGHTSCROLLBUTTON1",false);
	SetSelectable("SCROLLNATIONS",false);
	SetSelectable("LEFTSCROLLBUTTON2",false);
	SetSelectable("RIGHTSCROLLBUTTON2",false);
	SetSelectable("B_START",false);
	SetSelectable("B_CHARNAME",false);
	SetSelectable("B_SHIPNAME",false);
	SetSelectable("B_PROFNAME",false);
	SetSelectable("LOCA_CHANGER",false);
	SetSelectable("DIFF_CHANGER",false);
	SetSelectable("TYPE_CHANGER",false);
	SetSelectable("NATION_CHANGER",false);
	SetNodeUsing("CONFIRM_RECTANGLE",true);
	SetNodeUsing("PROFHELP",true);
	SetNodeUsing("CONFIRM_YES_BUTTON",true);
	SetSelectable("CONFIRM_YES_BUTTON",true);
	SetNodeUsing("CONFIRM_NO_BUTTON",true);
	SetSelectable("CONFIRM_NO_BUTTON",true);
	SetCurrentNode("CONFIRM_NO_BUTTON");
	SetFormatedText("PROFHELP",XI_ConvertString("game_profile") + " " + KeyboardString + " " + XI_ConvertString("already_exist"));
	SendMessage(&GameInterface,"lsl",MSG_INTERFACE_MSG_TO_NODE,"PROFHELP",5);
}

void EnableWindow()
{
	SetSelectable("EXIT_BUTTON",true);
	SetSelectable("ISLANDSLIST",true);
	SetSelectable("LEFTSCROLLBUTTON",true);
	SetSelectable("RIGHTSCROLLBUTTON",true);
	SetSelectable("SCROLLITEMS",true);
	SetSelectable("LEFTSCROLLBUTTON1",true);
	SetSelectable("RIGHTSCROLLBUTTON1",true);
	SetSelectable("SCROLLNATIONS",true);
	SetSelectable("LEFTSCROLLBUTTON2",true);
	SetSelectable("RIGHTSCROLLBUTTON2",true);
	SetSelectable("B_START",true);
	SetSelectable("B_CHARNAME",true);
	SetSelectable("B_SHIPNAME",true);
	SetSelectable("B_PROFNAME",true);
	SetSelectable("LOCA_CHANGER",true);
	SetSelectable("DIFF_CHANGER",true);
	SetSelectable("TYPE_CHANGER",true);
	SetSelectable("NATION_CHANGER",true);
	SetNodeUsing("CONFIRM_RECTANGLE",false);
	SetNodeUsing("PROFHELP",false);
	SetNodeUsing("CONFIRM_YES_BUTTON",false);
	SetNodeUsing("PROFTEXT",false);
	SetNodeUsing("CONFIRM_NO_BUTTON",false);
	SetSelectable("CONFIRM_NO_BUTTON",false);
	SetFormatedText("PROFHELP","");
	SetCurrentNode("ISLANDSLIST");
}

void ProcessProfile_yes()
{
	charProfile = TempPlayerProfileName;
//	PlayerProfile.profiles.(charProfile) = true;
	ChangeStringColor("ProfileName", COLOR_NORMAL);
	SetVariable();
	EnableWindow();
}

void ProcessProfile_no()
{
	TempPlayerProfileName = oldProfile;
	GameInterface.strings.ProfileName = TempPlayerProfileName;
	aref arefTmp; makearef(arefTmp,PlayerProfile.profiles);
	if(CheckAttribute(arefTmp,KeyboardString) && TempPlayerProfileName!=KeyboardString)
	{
		if(!CheckCurrentProfile(KeyboardString)) DeleteAttribute(arefTmp,KeyboardString);
	}
	else ProcessProfileCancel();
	if(CheckAttribute(&GameInterface,"tempLang")) DeleteAttribute(&GameInterface,"tempLang");
	ChangeStringColor("ProfileName", COLOR_NORMAL);
	SetVariable();
	EnableWindow();
}

bool CheckCurrentProfile(string profName)
{
	if(profName=="") return;
	GameInterface.SavePath = DEFAULT_PATH;
	
	string saveName;
	int nSaveSize;
	int nSaveNum = 0;
    while(SendMessage(&GameInterface,"llee",MSG_INTERFACE_SAVE_FILE_FIND,nSaveNum,&saveName,&nSaveSize)!=0 && CheckSavedProfileFile(saveName,profName))
	{
		nSaveNum++;
	}
	if(nSaveNum>0) return true;
	else return false;
}

bool CheckSavedProfileFile(string saveName, string profName)
{
	if(saveName=="" || saveName=="." || saveName=="..") return false;
	if(HasSubStr(IGetSaveString(DEFAULT_PATH+"\\"+saveName),profName)) return true;
	return false;
}

extern void InitBaseInterfaces_main();
extern void InitBaseInterfaces();
void ProcCommand()
{
	string comName = GetEventData();
	string nodName = GetEventData();
	int curPic = nCurScroll;
	switch(nodName)
	{
		case "B_START":
			if(comName=="activate" || comName=="click")
			{
				KB_SetKeyboardMode(false);
				GameInterface.strings.CharacterName = GetModelFirstNameFromListNumber(nCurScroll) + " " + GetModelLastNameFromListNumber(nCurScroll);
				GameInterface.strings.ShipName = GetShipNameFromListNumber(nCurSScrollNum);
				PlayerProfile.profiles.(charProfile) = true;
				PlayerProfile.name = FirstLetterUp(charProfile);
				SetNodeUsing("BOX",false);
				SetNodeUsing("BOX1",false);
				
				InterfaceStates.doUnFreeze = false;
				ClearEvents();
				ClearPostEvents();

				if(LoadSegment("Interface\BaseInterface.c"))
				{
					InitBaseInterfaces_main();
					InitBaseInterfaces();
					UnloadSegment("Interface\BaseInterface.c");
				}
				PostEvent("Start", 250, "1", 150);
			}
		break;

		case "ISLANDSLIST":
			if(comName=="activate") SetCurrentNode("B_START");
		break;

		case "SCROLLITEMS":
			if(comName=="activate") SetCurrentNode("B_START");
		break;
	}
}

#event_handler("Start", "StartingGame");
void StartingGame()
{
	musicName = "";
	oldMusicName = "";
	ResetSoundScheme();
	StopSound(0,0);
	ReleaseSound(0);
	CharModel = GetModelIdFromListNumber(nCurScroll);
	CharSex = GetModelSexFromListNumber(nCurScroll);
	CharAni = GetModelAniFromListNumber(nCurScroll);
	CharFirstName = GetModelFirstNameFromListNumber(nCurScroll);
	CharLastName = GetModelLastNameFromListNumber(nCurScroll);
	CharOldFirstName = GetModelOldFirstNameFromListNumber(nCurScroll);
	CharOldLastName = GetModelOldLastNameFromListNumber(nCurScroll);
	CharNation = sti(GameInterface.pictires.nationPictire);//GetNationFromListNumber(nCurNScrollNum);
	CharStore = GetStoreFromNation(sti(GameInterface.pictires.nationPictire));
	if(GetModelSexFromListNumber(nCurScroll)=="woman") { CharCommerce = CharCommerce+1; CharSneak = CharSneak+1; }
	CharShipName = GetShipNameFromListNumber(nCurSScrollNum);
	CharShipType = GetShipIdFromListNumber(nCurSScrollNum);
	CharDifficulty = curDifficulty;
	CharPlayerType = curPlayerType; // MAXIMUS: new skills-system
	CharLocation = curLocation; // KK
	DeleteAttribute(Models[GetModelIndex(ListModels(nCurScroll))],"firstname.assigned");
	DeleteAttribute(Models[GetModelIndex(ListModels(nCurScroll))],"lastname.assigned");
	Models[GetModelIndex(ListModels(0))].nation = ModelNation; // KK
	CleanStorylineObject(); // KK
	SaveGameOptions();
	LaunchSelectCharacter();
	IDoExit(RC_INTERFACE_CHOOSE_EXIT);
}

void ProcessCancelExit()
{
	IDoExit(RC_INTERFACE_CHOOSE_EXIT);
	if( !CheckAttribute(&InterfaceStates,"InstantExit") || sti(InterfaceStates.InstantExit)==false )
	{
		ReturnToMainMenu();
	}
}

void IDoExit(int exitCode)
{
	DelEventHandler("InterfaceBreak","ProcessCancelExit");
	DelEventHandler("exitCancel","ProcessCancelExit");
	DelEventHandler("ievnt_command","ProcCommand");
	DelEventHandler("frame","FrameProcess");
	DelEventHandler("NodeOk","ProcessNodeOk");
	DelEventHandler("NodeCancel","ProcessNodeCancel");
	DelEventHandler("CharNameChange","ProcessCharNameChange");
	DelEventHandler("KB_End","WriteName");
	DelEventHandler("KB_Update", "UpdateName");	
	DelEventHandler("ShipOk","ProcessShipOk");
	DelEventHandler("ShipCancel","ProcessShipCancel");
	DelEventHandler("ShipNameChange","ProcessShipNameChange");
	DelEventHandler("KB_End","WriteShipName");
	DelEventHandler("KB_Update", "UpdateShipName");
	DelEventHandler("ProfileOk","ProcessProfileOk");
	DelEventHandler("ProfileCancel","ProcessProfileCancel");
	DelEventHandler("ProfileChange","ProcessProfileChange");
	DelEventHandler("KB_End","WriteProfile");
	DelEventHandler("ConfirmYes","ProcessProfile_yes");
	DelEventHandler("ConfirmNo","ProcessProfile_no");
//MAXIMUS: new skills-system -->
	DelEventHandler("IEvnt_MouseClick","IProcMouseClick");
	DelEventHandler("ChangerLeft","DoChangeLeft");
	DelEventHandler("ChangerRight","DoChangeRight");
	DelEventHandler("ChangeTypeLeft","DoTypeChangeLeft");
	DelEventHandler("ChangeTypeRight","DoTypeChangeRight");
	DelEventHandler("ChangeLocLeft","DoLocChangeLeft"); // KK
	DelEventHandler("ChangeLocRight","DoLocChangeRight"); // KK
	DelEventHandler("UpPress","UpProcess");
	DelEventHandler("DownPress","DownProcess");
	DelEventHandler("NationLeft","NationChangeLeft");
	DelEventHandler("NationRight","NationChangeRight");
//MAXIMUS: new skills-system <--

	interfaceResultCommand = exitCode;
	if( CheckAttribute(&InterfaceStates,"InstantExit") && sti(InterfaceStates.InstantExit)==true ) {
		EndCancelInterface(false);
	} else {
		EndCancelInterface(true);
	}
}

// KK -->
string ListModels(int i)
{
	aref arstart = GetStorylineStartParams(FindCurrentStoryline());
	if (!CheckAttribute(arstart, "models")) arstart = GetStorylineStartParams(FindDefaultStoryline());
	aref armodels; makearef(armodels, arstart.models);
	int num = GetAttributesNum(armodels);
	i++;
	if (i < 1) i = 1;
	while (i > num) i -= num;
	string model = "m" + i;
	model = armodels.(model);
	while (i > 12) i -= 12;
	if (GetModelIndex(model) == -1) model = GetDefaultPlayerModel(i);
	return model;
}

int ListModelsSize()
{
	aref arstart = GetStorylineStartParams(FindCurrentStoryline());
	if (!CheckAttribute(arstart, "models")) arstart = GetStorylineStartParams(FindDefaultStoryline());
	aref armodels; makearef(armodels, arstart.models);
	return GetAttributesNum(armodels);
}

string ListShips(int i)
{
	aref arstart = GetStorylineStartParams(FindCurrentStoryline());
	if (!CheckAttribute(arstart, "ships")) arstart = GetStorylineStartParams(FindDefaultStoryline());
	aref arships; makearef(arships, arstart.ships);
	int num = GetAttributesNum(arships);
	i++;
	if (i < 1) i = 1;
	while (i > num) i -= num;
	string ship = "s" + i;
	ship = arships.(ship);
	while (i > 8) i -= 8;
	int shipidx = GetShipIndex(ship);
	if (shipidx == -1 || shipidx == SHIP_NOTUSED || shipidx == SHIP_BOAT || shipidx == SHIP_FORT) ship = GetDefaultShipModel(i);
	return ship;
}

int ListShipsSize()
{
	aref arstart = GetStorylineStartParams(FindCurrentStoryline());
	if (!CheckAttribute(arstart, "ships")) arstart = GetStorylineStartParams(FindDefaultStoryline());
	aref arships; makearef(arships, arstart.ships);
	return GetAttributesNum(arships);
}

string XI_DefaultShipName()
{
	aref arstart = GetStorylineStartParams(FindCurrentStoryline());
	if (!CheckAttribute(arstart, "shipname")) arstart = GetStorylineStartParams(FindDefaultStoryline());
	return arstart.shipname;
}

string XI_DefaultStartLocationName()
{
	aref arstart = GetStorylineStartParams(FindCurrentStoryline());
	if (!CheckAttribute(arstart, "location")) arstart = GetStorylineStartParams(FindDefaultStoryline());
	return arstart.location;
}
// <-- KK
