
#define RELOAD_TIME_FADE_OUT	0.5
#define RELOAD_TIME_FADE_IN		0.5

object reload_fader;
aref reload_locator_ref;
int reload_cur_island_index, reload_cur_location_index;
int reload_island_index, reload_location_index;

object reload_xaddress;

bool LoadMainCharacterInFirstLocation(string location_id, string locator_group, string emerge_locator, string ship_location)
{
	int lindex = -1; // KK
	//Find ship location
	if(ship_location != "")
	{
		lindex = FindLocation(ship_location);
		if(lindex < 0)
		{
			trace("Incorrect location id for location character's ship (location " + ship_location + " not found)");
		}
	}
	if(lindex >= 0)
	{
		SetPlayerShipLocation(lindex);
		PlaceFleetNearShore(ship_location); // KK
	}
	//Find location
	lindex = -1;
	lindex = FindLocation(location_id);
	if(lindex < 0)
	{
		trace("Incorrect location id for first location (location " + location_id + " not found)");
		return false;
	}
	trace("!!! Reload to " + lindex);
	//Find reload data
	aref reload_group;
	aref locator_ref;
	aref curLoc;
	string new_emerge = "";
	ref mc = GetMainCharacter();

	bool bChange = locator_group!="reload";
	if(bChange) bChange = locator_group!="rld";
	makearef(reload_group, Locations[lindex].reload);

	if(GetAttributesNum(reload_group)==0 || bChange)//MAXIMUS: full check for wrong locators
	{
		if(GetAttributesNum(reload_group)==0) trace("Locator group <" + locator_group + "> for first location <" + location_id + "> isn't correct!");

		Locations[lindex].testing = true;
		LoadLocation(&Locations[lindex]);
		makearef(curLoc, Locations[lindex].locators);
		for(int i=0; i<GetAttributesNum(curLoc); i++)
		{
			aref arLoc = GetAttributeN(curLoc,i);
			if(GetAttributeName(arLoc)=="") continue;
			string arLocName = GetAttributeName(arLoc);
			if(arLocName=="rld" || arLocName=="goto")
			{
				makearef(arLoc,Locations[lindex].locators.(arLocName));
				for(int j=0; j<GetAttributesNum(arLoc); j++)
				{
					if(GetAttributeName(GetAttributeN(arLoc,j))=="") continue;
					locator_group = arLocName;
					trace("New locator group for first location is <" + locator_group + ">!");
					emerge_locator = GetAttributeName(GetAttributeN(arLoc,j));
					new_emerge = emerge_locator;
					trace("New emerge locator for first location is <" + emerge_locator + ">!");
					break;
				}
			}
			if(new_emerge==emerge_locator) break;
		}
		DeleteAttribute(&Locations[lindex],"testing");
		UnloadLocation(&Locations[lindex]);
		if(new_emerge!=emerge_locator)
		{
			trace("Location " + location_id + " hasn't reload groups!");
			InterfaceStates.LaunchAnyway = true;
			LaunchMainMenu();
			return false;
		}
	}
	else
	{
		if(emerge_locator!="")
		{
			if(locator_group=="reload" && FindEmergeLocator(&Locations[lindex], emerge_locator)=="")
			{
				trace("Emerge locator " + emerge_locator + " in location " + location_id + " not found!");
				locator_ref = GetAttributeN(reload_group, 0);
				emerge_locator = locator_ref.name;
				trace("Character emerge on first locator (" + emerge_locator + ")");
			}
		}
		else
		{
			locator_ref = GetAttributeN(reload_group, 0);
			emerge_locator = locator_ref.name;
		}
	}

	lockedReloadLocator = emerge_locator;
	mc.location = Locations[lindex].id;
	mc.location.group = locator_group; // KK
	mc.location.locator = emerge_locator;
	if(IsEntity(&chrAnimationKipper) == false) CreateEntity(&chrAnimationKipper, "CharacterAnimationKipper");
	if(CheckAttribute(mc,"newGameStart") && mc.newGameStart==true) DeleteAttribute(mc, "newGameStart");
	/*{
		if(HasSubStr(mc.location,"tutorial") || HasSubStr(mc.location,"deck") || HasSubStr(mc.location,"cabin"))
		{
			mc.location.first = true;//MAXIMUS: identifier for fastreload on tutorial deck
		}
	}*/
	ReloadProgressUpdate();

	//MAXIMUS: a little change for start of "StartAdventure"
	/*if(CheckAttribute(mc,"newGameStart") && mc.newGameStart==true && mc.location!="Tutorial_Deck")
	{
		DoQuestReloadToLocation(Locations[lindex].id, locator_group, emerge_locator ,"");//MAXIMUS: far fewer lags after starting on island
		if(!HasSubStr(mc.location,"Oxbay")) LAi_QuestDelay("StartAdventure", 1.0);
		else
		{
			LAi_QuestDelay("Tut_start", 0.0);
			mc.quest.StartAdventure.win_condition.l1 = "MapEnter";
			mc.quest.StartAdventure.win_condition = "StartAdventure";
		}
		mc.nation = CharNation;
		if(GetNationRelation2MainCharacter(GetCurrentLocationNation())!=RELATION_FRIEND) SetNationRelation2MainCharacter(GetCurrentLocationNation(), RELATION_NEUTRAL);//MAXIMUS: or we wouldn't be able to be anchored in this port, right?
		bChangeNation = true;//MAXIMUS: or we can't escape from Oxbay
		DeleteAttribute(mc,"newGameStart");
		return true;
	}*/

	if(!LoadLocation(&Locations[lindex]))
	{
		InterfaceStates.LaunchAnyway = true;
		LaunchMainMenu();
		return false;
	}

	/*if(CheckAttribute(mc,"newGameStart") && mc.newGameStart==true && mc.location=="Tutorial_Deck")
	{
		mc.quest.StartAdventure.win_condition.l1 = "MapEnter";
		mc.quest.StartAdventure.win_condition = "StartAdventure";

		mc.quest.Tut_start.win_condition.l1 = "location";
		mc.quest.Tut_start.win_condition.l1.character = mc.id;
		mc.quest.Tut_start.win_condition.l1.location = "Tutorial_Deck";
		mc.quest.Tut_start.win_condition = "Tut_start";
	}*/

	//Fader
	PostEvent("LoadSceneSound", 500);
	return true;
}

void SetPlayerShipLocation(int location_index)
{
	//Main character
	if(location_index < 0)
	{
		Trace("SetPlayerShipLocation - incorrect location index");
		return;
	}
	ref mc = GetMainCharacter();
	mc.location.from_sea = ""; // KK
	if (GetCharacterShipType(mc) == SHIP_NOTUSED) return; // KK
	mc.location.from_sea = Locations[location_index].id;
	SetFleetInTown(GetTownIDFromLocID(mc.location.from_sea), "pchar"); // NK 05-04-02 WM/IT set fleet.
}


//reload_group = xxx.reload
int Reload(aref reload_group, string locator_name, string current_location)
{
	if(dialogRun || dialogSelf)//MAXIMUS -->
	{
		DialogExit();
	}
	Characters[GetMainCharacterIndex()].condition = "reload";//MAXIMUS <--
	SetReloadNextTipsImage();

// changed by MAXIMUS -->
	dialogDisable = !bDeckEnter; // KK
// changed by MAXIMUS <--

	reload_xaddress.active = "false";
	Trace("locator_name = " + locator_name + " lockedReloadLocator = " + lockedReloadLocator);
	//Check locked locator
	if(locator_name == lockedReloadLocator)
	{
		lockedReloadLocator = "";
		PlaySound("knock");//MAXIMUS
		return -1;
	}
	//Find reload data
	int num = GetAttributesNum(reload_group);
	if(num == 0) { PlaySound("knock"); return 0; }//MAXIMUS
	for(int i = 0; i < num; i++)
	{
		reload_locator_ref = GetAttributeN(reload_group, i);
// added CheckAttribute by MAXIMUS -->
		if(CheckAttribute(reload_locator_ref,"name"))
		{
			if(locator_name == reload_locator_ref.name) break;
		}
// added CheckAttribute by MAXIMUS <--
	}
	if(i == num)
	{
		if (Locations[FindLoadedLocation()].id == locator_name) return 0; // KK
		Trace("Can't reload...");
		Trace("Reload locator '" + locator_name + "' in currend location not found!");
		PlaySound("knock");//MAXIMUS
		return 0;
	}
	//Check main attributes
	if(CheckAttribute(reload_locator_ref, "name") == 0)
	{
		Trace("Can't reload...");
		Trace("Reload: attribute 'name' in " + GetAttributeName(reload_locator_ref) + " not accessible");
		PlaySound("knock");//MAXIMUS
		return 0;
	}
	if(CheckAttribute(reload_locator_ref, "go") == 0)
	{
		Trace("Can't reload...");
		Trace("Reload: attribute 'go' in " + GetAttributeName(reload_locator_ref) + " not accessible");
		PlaySound("knock");//MAXIMUS
		return 0;
	}
	if(CheckAttribute(reload_locator_ref, "emerge") == 0)
	{
		Trace("Can't reload...");
		Trace("Reload: attribute 'emerge' in " + GetAttributeName(reload_locator_ref) + " not accessible");
		PlaySound("knock");//MAXIMUS
		return 0;
	}
	//Find current location
	reload_cur_island_index = -1;
	reload_cur_location_index = -1;
	if(current_location != "")
	{		
		reload_cur_island_index = FindIsland(current_location);
		if(reload_cur_island_index < 0)
		{
			reload_cur_location_index = FindLocation(current_location);
			if(reload_cur_location_index < 0)
			{
				Trace("Can't unload currend location...");
				Trace("Current location not found: id = " + current_location);
				PlaySound("knock");//MAXIMUS
				return 0;
			}
		}
	}
	//Find location & reload
	reload_island_index = -1;
	reload_location_index = -1;
	reload_island_index = FindIsland(reload_locator_ref.go);
	if(reload_island_index < 0)
	{
		reload_location_index = FindLocation(reload_locator_ref.go);
		if(reload_location_index < 0)
		{
			Trace("Can't reload...");
			Trace("Location not found: id = " + reload_locator_ref.go);
			PlaySound("knock");//MAXIMUS
			return 0;
		}
	}
	//Main character
	ref mc = GetMainCharacter();
	Trace("reload_cur_island_index = " + reload_cur_island_index);
	Trace("reload_cur_location_index = " + reload_cur_location_index);
	Trace("reload_island_index = " + reload_island_index);
	Trace("reload_location_index = " + reload_location_index);
	//Test in sea exit
	if((reload_cur_island_index < 0) && (reload_island_index >= 0))
	{
		if(reload_cur_location_index >= 0)
		{
			//From location to sea
			if(Locations[reload_cur_location_index].id != mc.location.from_sea)
			{
				Trace("Not reload to sea, no ships: cur:" + Locations[reload_cur_location_index].id + " from:" + mc.location.from_sea);
				PlaySound("knock");//MAXIMUS
				return -1;
			}
		}
	}
	//Start fader
	SetEventHandler("FaderEvent_StartFade", "ReloadStartFade", 0);
	SetEventHandler("FaderEvent_EndFade", "ReloadEndFade", 0);
	CreateEntity(&reload_fader, "fader");
	bool bPicture = CheckAttribute(mc,"newGameStart")==false;//MAXIMUS -->
	if(!bPicture) bPicture = HasSubStr(mc.location,"deck")==true;
	if(bPicture)
	{
		if(reload_island_index>=0)
		{
	// KK -->
			if (VISIT_DECK == 0)
				SendMessage(&reload_fader, "ls", FADER_PICTURE, FindReloadPicture("Landing.tga"));
			else
				SendMessage(&reload_fader, "ls", FADER_PICTURE, FindReloadPicture("Sea.tga"));
	// <-- KK
		}
		else
		{
			int loc_pict_index = reload_location_index;
			if(loc_pict_index<0) loc_pict_index = reload_cur_location_index;
			if(loc_pict_index>=0)
			{		
				if(CheckAttribute(&Locations[loc_pict_index],"image"))
				{
					SendMessage(&reload_fader, "ls", FADER_PICTURE, FindReloadPicture(Locations[loc_pict_index].image));
				}
			}
		}
	}//MAXIMUS <--

	bool IsMakeShot = true;
	float fadeOutTime = RELOAD_TIME_FADE_OUT;
	if(reload_cur_island_index<0 && reload_cur_location_index<0)
	{
		fadeOutTime = 0.00001;	//Can't need fade out - no loaded location
		IsMakeShot = false;
	}
	SendMessage(&reload_fader, "lfl", FADER_OUT, fadeOutTime, false);
	if(IsMakeShot) SendMessage(&reload_fader, "l", FADER_STARTFRAME);
	//Set lockedReloadLocator
	if(reload_cur_island_index < 0)
	{
		//From location
		if(reload_island_index < 0)
		{		//To location
			lockedReloadLocator = reload_locator_ref.emerge;
		}else{	//To sea
			lockedReloadLocator = "";
		}
	}else{
		//From sea
		if(reload_island_index < 0)
		{		//To location
			lockedReloadLocator = reload_locator_ref.emerge;
		}else{	//To sea			
			lockedReloadLocator = "";
		}
	}
	Log_SetActiveAction("Nothing");//MAXIMUS
	chrWaitReloadLocator = "";//MAXIMUS
	chrWaitReloadIsNoLink = false;//MAXIMUS
	Trace("Start reload");
	return 1;
}

void ReloadStartFade()
{
	ResetSoundScheme();
	PauseAllSounds();
	DelEventHandler("FaderEvent_StartFade", "ReloadStartFade");
	Trace("ReloadStartFade");
	//Main character
	ref mc = GetMainCharacter();
	if(reload_cur_island_index < 0)
	{
		//From location
		if(reload_island_index < 0)
		{
			//To location
			if(reload_cur_location_index >= 0) UnloadLocation(&Locations[reload_cur_location_index]);
			return;
		}else{
			//To sea
			if(reload_cur_location_index >= 0)
			{
				UnloadLocation(&Locations[reload_cur_location_index]);
			}else { mc.location.from_sea = ""; SetFleetInTown(GetTownIDFromLocID(mc.location.from_sea), "pchar"); } // NK WM/IT 05-04-02
			DeleteClass(&chrAnimationKipper);
			return;
		}
	}else{
		//From sea
		if(reload_island_index < 0)
		{
			//To location
			DeleteSeaEnvironment();
			mc.location.from_sea = reload_locator_ref.go;
			SetFleetInTown(GetTownIDFromLocID(mc.location.from_sea), "pchar"); // NK 05-04-02 WM/IT set fleet.
			return;
		}else{
			//To sea
			DeleteSeaEnvironment();
			mc.location.from_sea = "";
			SetFleetInTown(GetTownIDFromLocID(mc.location.from_sea), "pchar"); // NK 05-04-02 WM/IT set fleet.
			return;
		}
	}
}

void ReloadEndFade()
{
	dialogDisable = false;
	ReloadProgressStart();
	DelEventHandler("FaderEvent_EndFade", "ReloadEndFade");
	Trace("ReloadEndFade");
	ReloadProgressUpdate();
	//Main character
	ref mc = GetMainCharacter();
	if(reload_cur_island_index < 0)
	{
		//From location
		if(reload_island_index < 0)
		{
			//To location
			ReloadToLocation(reload_location_index, reload_locator_ref);
		}
		else
		{
			//To sea
			ReloadToSea(reload_island_index, reload_locator_ref);
		}
	}
	else
	{
		//From sea
		if(reload_island_index < 0)
		{
			//To location
			ReloadToLocation(reload_location_index, reload_locator_ref);
		}
		else
		{
			//To sea
			ReloadToSea(reload_island_index, reload_locator_ref);
		}
	}
	SendMessage(&reload_fader, "lfl", FADER_IN, RELOAD_TIME_FADE_IN, true);
	PostEvent("LoadSceneSound", 500);
	ReloadProgressEnd();

	// added after build 11 by KAM -->
	if (CheckAttribute(mc,"ShipBerthing.DoInvoice"))
	{
		SBInvoiceOnLanding(-1);
		DeleteAttribute(mc.ShipBerthing,"DoInvoice");
	}
	// <-- added after build 11 by KAM
}

string	FindEmergeLocator(ref rObject, string emerge_str)
{
	aref arReload;
	makearef(arReload,rObject.reload);
	int n = GetAttributesNum(arReload);
	for (int i=0;i<n;i++)
	{
		aref arLoc;
		arLoc = GetAttributeN(arReload,i);
		if(!CheckAttribute(arLoc, "name")) continue;//MAXIMUS
		if (arLoc.name == emerge_str) 
		{
			string loc_name = GetAttributeName(arLoc);
			return loc_name;
		}
	}
 	Trace("ERROR(no find emerge string): string FindEmergeLocator(ref rObject, string emerge_str) : " + emerge_str);
	return "";
}

object chrAnimationKipper;

int ReloadToLocation(int location_index, aref reload_data)
{
	ref mc = GetMainCharacter();
	mc.location = Locations[location_index].id;
	mc.location.group = "reload";
	mc.location.locator = reload_data.emerge;
	if(reload_xaddress.active == "true")
	{
		mc.location.group = reload_xaddress.group;
		mc.location.locator = reload_xaddress.locator;
	}
	if(IsEntity(&chrAnimationKipper) == false) CreateEntity(&chrAnimationKipper, "CharacterAnimationKipper");
	return LoadLocation(&Locations[location_index]);
}

int ReloadToSea(int island_index, aref reload_data)
{
	object Login;

	ref rPlayer = GetMainCharacter();
	rPlayer.lastFightMode = 0;

	ref rIsland = GetIslandByIndex(island_index);
	/*Trace("============================");
	Trace("island_index = " + island_index);
	DumpAttributes(rIsland);
	Trace("============================");*/

	rPlayer.location = rIsland.id;
	rPlayer.location.group = "reload";
	rPlayer.location.locator = reload_data.emerge;

	Login.Island = rIsland.id;

	Login.Encounters = "";

	string sLoc = FindEmergeLocator(rIsland,reload_data.emerge);

	Login.PlayerGroup.x = rIsland.reload.(sLoc).ships.l0.x;	// FIX-ME
	Login.PlayerGroup.z = rIsland.reload.(sLoc).ships.l0.z; 
	Login.PlayerGroup.ay = rIsland.reload.(sLoc).ships.l0.ay;
	Login.FromCoast = true;

	Trace("Load from location to sea sLoc = " + sLoc + ", x = " + Login.PlayerGroup.x + ",z = " + Login.PlayerGroup.z);
		
	SeaLogin(Login);

 	if (ENABLE_AMMOMOD) {// TIH --> mod toggle 7-7-06
		//JRH -->
		//officers restock themselves when visiting the ship
		int s; //shots
		bool haveCannoneer = false;// TIH bug fix 7-7-06

		for(int i = 1; i < 4; i++)
		{
			int idx = GetOfficersIndex(GetMainCharacter(), i);
			if(idx < 0) continue;
			ref tmpChr = GetCharacter(idx);
	
			string weaponID = GetCharacterEquipByGroup(tmpChr,GUN_ITEM_TYPE);
			aref weapon;
			Items_FindItem(weaponID, &weapon);

			// TIH --> bug fix 7-7-06
			if(CheckAttribute(tmpChr,"quest.officertype")) {
				if(tmpChr.quest.officertype=="cannoneer") {
					haveCannoneer = true;
				}
			}
			// TIH <-- bug fix
				
			if(!CheckAttribute(tmpChr,"equip."+GUN_ITEM_TYPE) )
			{
				//do nothing
			}
			else
			{
				if(CheckAttribute(weapon, "shottype"))
				{
					if(weapon.shottype == "pg2" || weapon.shottype == "pg" || weapon.shottype == "mb" || weapon.shottype == "pb")
					{
						DeleteAttribute(tmpChr,"Items.gunpowder");
						DeleteAttribute(tmpChr,"Items.pistolbullets");
						DeleteAttribute(tmpChr,"Items.pistolgrapes");
						DeleteAttribute(tmpChr,"Items.musketbullets");
					
						if(CheckCharacterItem(tmpChr,"powderflask")) { TakeNItems(tmpChr,"gunpowder", 12); }
						else { TakeNItems(tmpChr,"gunpowder", 6); }

						if(CheckCharacterItem(tmpChr,"ammopouch")) { s = 12; }
						else { s = 6; }

						if(CheckAttribute(weapon, "shottype"))
						{
							if(weapon.shottype == "pg2" || weapon.shottype == "pg") TakeNItems(tmpChr,"pistolgrapes", s);
							if(weapon.shottype == "mb") TakeNItems(tmpChr,"musketbullets", s/2);
							if(weapon.shottype == "pb") TakeNItems(tmpChr,"pistolbullets", s);
						}
					}
				}
			}
		}

		//blaze is autorestocked if he is rank 6 or higher & there is a gunner (to do it)

		string weaponID2 = GetCharacterEquipByGroup(rPlayer,GUN_ITEM_TYPE);
		aref weapon2;
		bool tmpAbleRefill = false;
		Items_FindItem(weaponID2, &weapon2);

		if(CheckAttribute(weapon2, "shottype"))
		{
			if(weapon2.shottype == "pg2" || weapon2.shottype == "pg" || weapon2.shottype == "mb" || weapon2.shottype == "pb")
			{
				// TIH --> ABLECAPTAIN toggle 7-7-06
				if(haveCannoneer) {
					if(CheckAttribute(rPlayer, "rank")) {
						if(rPlayer.rank >= 6) {
							tmpAbleRefill = true;
				}}}
				if (AMMOMOD_ABLECAPTAIN) { tmpAbleRefill = true; }

				// TIH --> adjustments of code Jul16'06
				if (tmpAbleRefill)
				{
					int priorGP = GetCharacterItem(rPlayer,"gunpowder");
					int priorPB = GetCharacterItem(rPlayer,"pistolbullets");
					int priorPG = GetCharacterItem(rPlayer,"pistolgrapes");
					int priorMB = GetCharacterItem(rPlayer,"musketbullets");
					
					DeleteAttribute(rPlayer,"Items.gunpowder");
					DeleteAttribute(rPlayer,"Items.pistolbullets");
					DeleteAttribute(rPlayer,"Items.pistolgrapes");
					DeleteAttribute(rPlayer,"Items.musketbullets");
					
					//JRH fix oct 06: mainchar to equip for 12/12
					if(CheckAttribute(rPlayer,"equip."+FLASK_ITEM_TYPE) )	{ TakeNItems(rPlayer,"gunpowder", 12); }
					else													{ TakeNItems(rPlayer,"gunpowder", 6); }

					if(CheckAttribute(rPlayer,"equip."+POUCH_ITEM_TYPE) )	{ s = 12;}
					else													{ s = 6; }

					string strAmmoLoaded;
					bool doInform = false;
					if(weapon2.shottype == "pb")  { TakeNItems(rPlayer,"pistolbullets", s); strAmmoLoaded = "Pistol"; 	 if (s > priorPB) { doInform = true; } }
					if(weapon2.shottype == "pg")  { TakeNItems(rPLayer,"pistolgrapes", s); 	strAmmoLoaded = "Grapeshot"; if (s > priorPG) { doInform = true; } }
					if(weapon2.shottype == "pg2") { TakeNItems(rPLayer,"pistolgrapes", s); 	strAmmoLoaded = "Grapeshot"; if (s > priorPG) { doInform = true; } }
					if(weapon2.shottype == "mb")  { TakeNItems(rPlayer,"musketbullets", s); strAmmoLoaded = "Musket"; 	 if (s > priorMB) { doInform = true; } }
					
					if(doInform)
					{
						//int tmpLangFileID = LanguageOpenFile("interface_strings.txt"); // added by MAXIMUS
						if(AMMOMOD_ABLECAPTAIN) Log_SetStringToLog(TranslateString("","You refilled your")+" "+ XI_ConvertString("r"+strAmmoLoaded) + " "+TranslateString("","Ammunition."));
						else Log_SetStringToLog(TranslateString("","The Gunner has provided you with")+" "+ XI_ConvertString("r"+strAmmoLoaded) + " "+TranslateString("","Ammunition!"));
						PlaySound("INTERFACE\important_item.wav");
						//LanguageCloseFile(tmpLangFileID); // added by MAXIMUS
					}
				}
				// TIH <-- adjustments
				// TIH <-- ABLECAPTAIN toggle
			}
		}
	   //<-- JRH
	}// TIH <-- mod toggle






	return 1;

	/*
	reload_data.x
	reload_data.y
	reload_data.z
	reload_data.ships.l1.x
	*/

	return -1;
}


bool TeleportCharacterFromCurLocationToLocation(string locatorExit, string group, string locator)
{
	reload_xaddress.group = group;
	reload_xaddress.locator = locator;
	aref reload_group;
	makearef(reload_group, loadedLocation.reload);
	if(Reload(reload_group, locatorExit, loadedLocation.id) == false) return false;
	reload_xaddress.active = "true";
	return true;
}

// KK -->
String FindReloadPicture(string fname)
{
	if (FindFile("RESOURCE\Textures\Loading", "*.tga.tx", fname + ".tx") != "")
		return "Loading\" + fname;
	if (FindFile("RESOURCE\Textures\Loading\" + LanguageGetLanguage(), "*.tga.tx", fname + ".tx") != "")
		return "Loading\" + LanguageGetLanguage() + "\" + fname;
	if (FindFile("RESOURCE\Textures\Loading\ENGLISH", "*.tga.tx", fname + ".tx") != "")
		return "Loading\ENGLISH\" + fname;
	if (FindFile("RESOURCE\Textures\INTERFACES\BACKGROUND", "*.tga.tx", fname + ".tx") != "")//MAXIMUS
		return "INTERFACES\BACKGROUND\" + fname;
	return "";
}
// <-- KK
