// Jerry-rigged console file.
//put code under ExecuteConsole() below.
//NK 04-08-28
// not needed I think extern void InitShips();
#include "SDK\LocatorWrite.c"
#include "Upgrade.c";
extern void InitItems();
extern void InitCannons();


void ExecuteConsole()
{
	ref pchar = GetMainCharacter();
	ref ch;
	int i;
	int limit;

	if(NEW_DIALOG_INTERFACE) NEW_DIALOG_INTERFACE = 0;
	else NEW_DIALOG_INTERFACE = 1;
	
// Testing quests
// ------------------
//	Characters[GetCharacterIndex("Luc Merin")].dialog.currentnode = "begin1_1";

// Give ship
// ------------------
//	GiveShip2Character(pchar,"Endeavour","Endeavour",ENGLAND,true,true);

// Give items
// ------------------
//	GiveItem2Character(PChar, "compass3");
//	EquipCharacterByItem(pchar, "compass3");
//	GiveItem2Character(pchar, "spyglass4");
//	EquipCharacterByItem(pchar, "spyglass4");
//	GiveItem2Character(pchar, "clock2");
//	EquipCharacterByItem(pchar, "clock2");
//	GiveItem2Character(pchar,"blade26+3");
//	EquipCharacterByItem(pchar, "blade26+3");
/*
	GiveItem2Character(pchar, "mapKhaelRoa");
	GiveItem2Character(pchar, "mapAntigua");
	GiveItem2Character(pchar, "mapConceicao");
	GiveItem2Character(pchar, "mapCuba");
	GiveItem2Character(pchar, "mapDouwesen");
	GiveItem2Character(pchar, "mapFalaiseDeFleur");
	GiveItem2Character(pchar, "mapGuadeloupe");
	GiveItem2Character(pchar, "mapHispaniola");
	GiveItem2Character(pchar, "mapIslaMuelle");
	GiveItem2Character(pchar, "mapOxbay");
	GiveItem2Character(pchar, "mapQuebradasCostillas");
	GiveItem2Character(pchar, "mapRedmond");
	GiveItem2Character(pchar, "mapSaintMartin");
	GiveItem2Character(pchar, "mapTurks");
	GiveItem2Character(pchar, "mapRedmond_Dungeon");
	GiveItem2Character(pchar, "mapOxbay_Dungeon");
	GiveItem2Character(pchar, "mapOxbay_Cave");
*/

// Reload to location
// ------------------
//	DoQuestReloadToLocation("Redmond_port", "reload", "Sea_2_back" ,"");
//	SetCharacterShipLocation(Pchar, "Redmond_port");
//	DoQuestReloadToLocation("Douwesen_port", "reload", "reload1" ,"");
//	SetCharacterShipLocation(Pchar, "Douwesen_port");

// Capture Colony
// ------------------
//	CaptureTownForNation("Douwesen", HOLLAND);
//	LaunchCaptureColony(pchar, "Santo_Domingo");

//	DEBUG = 1;

	return;
	if (!bSeaActive) {
		ref lcn = &Locations[FindLocation(pchar.location)];
		float x,y,z,ay,xx,zz,xz,zx;
		GetCharacterPos(GetMainCharacter(), &x, &y, &z);
		GetCharacterAy(pchar, &ay);
		xx = -sin(ay - PId2);
		zz = xx;
		xz = -cos(ay - PId2);
		zx = -xz;
		Logit("Location id: "+pchar.location)
		Logit("Your Coords x: " + x+"  y: "+y+"  z: "+z );
		Logit("Viewangle ay: "+ay+"; xx= "+xx+" xz= "+xz+" zx= "+zx+" zz= "+zz);
		Logit("Curlocator: "+chrWaitReloadLocator);
		//trace("Location id: "+pchar.location)
		//trace("rld,loc,"+xx+",0,"+y+","+xz+",0,1,0,"+zx+",0,"+zz+","+x+","+y+","+z+",1,0,0,0,0,0,0,0,0,");
		trace("rld,aloc,"+xx+",0,"+xz+",0,1,0,"+zx+",0,"+zz+","+x+","+y+","+z+",1,0,0,0,0,0,0,0,0,");
//		trace("Viewangle ay: "+ay+"; xx= "+xx+" xz= "+xz+" zx= "+zx+" zz= "+zz);
//		trace("Curlocator: "+chrWaitReloadLocator);
	} else {
		Logit("Ship position: x="+pchar.ship.pos.x+", z="+pchar.ship.pos.z);
	}

	//Logit("Ship position: x="+worldMap.playerShipX+", z="+worldMap.playerShipZ);

	/*if (!HasSubStr(pchar.location, "BOARDING_"))
		DoQuestReloadToLocation("BOARDING_ShipDeck1", "rld", "loc0", "");
	else {
		limit = makeint(GetBoardingLimit(FindLoadedLocation()) / 2);
		for (i = 1; i < limit; i++) {
			ch = LAi_CreateFantomCharacter(false, 0, true, true, 0.0, "Soldier_eng", "rld", "loc" + i);
			LAi_SetStayType(ch);
		}
		ch = LAi_CreateFantomCharacter(false, 0, true, true, 0.0, "offic_fra", "rld", "aloc0");
		LAi_SetStayType(ch);
		for (i = 1; i < limit; i++) {
			ch = LAi_CreateFantomCharacter(false, 0, true, true, 0.0, "Soldier_fra", "rld", "aloc" + i);
			LAi_SetStayType(ch);
		}
	}
	return;*/

	if (LAi_boarding_process) {
		//if (FindLoadedLocation() == "BOARDING_ShipDeck4" || FindLoadedLocation() == "BOARDING_ShipDeck5" || FindLoadedLocation() == "BOARDING_ShipDeck6")
//		PostEvent("CharacterGroup_UpdateAlarm", 0, "fi", 0.0, false);
//		logit("phar.location="+pchar.location+", refEnCharacter.location="+refEnCharacter.location+", refEnCharacter.location.group="+refEnCharacter.location.group+", refEnCharacter.location.locator="+refEnCharacter.location.locator);
//		logit("GetPassengerNumber(mchr, GetCharacterIndex(refEnCharacter.id))="+GetPassengerNumber(pchar, GetCharacterIndex(refEnCharacter.id)));
	}
	if (bSeaActive) {
		Logit("Location: "+PChar.location+", "+pchar.location.group+", "+pchar.location.locator);
		Fort_SetAbordageMode(pchar, characterFromID("Redmond Commander"));
		//SetNationRelation2MainCharacter(PORTUGAL, RELATION_ENEMY);
		//Fort_SetAbordageMode(pchar, characterFromID("Douwesen Commander"));
		//SetNationRelation2MainCharacter(HOLLAND, RELATION_ENEMY);
		//UsunFlagi();
	} else {
		if (pchar.location == "BOARDING_Residence") {
		lai_setactortype(pchar);
LAi_ActorDialog(pchar, boarding_enemy, "Surrendered_Captain_Dialog", 60.0, 0);
		}
		if (pchar.location == "Douwesen_townhall") {
/*			ch = characterFromID("Reynard Grueneveldt");
			int govidx = GetTownGovernorIndex("Douwesen");
			int iNation = ENGLAND;
			string sNation = "n" + iNation;
			if (CheckAttribute(characters[govidx], "nation." + sNation)) LogIt("Jest."); else LogIt("Brak!");
			LogIt(characters[govidx].nation.(sNation).lastname);
			DumpAttributes(characters[govidx]);
			CaptureTownForNation("Douwesen", ENGLAND);*/
			logit(Preprocessor_Get("addr"));
		}
		if (hasSubStr(pchar.location, "_port")) {
			GiveShip2Character(pchar,"Interceptor","HMS Interceptor",ENGLAND,true,true);
			ch = CreateOfficer_Cheat(OFFIC_TYPE_NAVIGATOR, "Dan_TG3", 0, PERSONAL_NATION, false);
			SetOfficersIndex(pchar, -1, GetCharacterIndex(ch.id));
			ch = CreateOfficer_Cheat(OFFIC_TYPE_QMASTER, "33_TG5D", 0, PERSONAL_NATION, false);
			SetOfficersIndex(pchar, -1, GetCharacterIndex(ch.id));
			ch = CreateOfficer_Cheat(OFFIC_TYPE_CANNONEER, "50_India", 0, PERSONAL_NATION, false);
			SetOfficersIndex(pchar, -1, GetCharacterIndex(ch.id));
			ch = CreateOfficer_Cheat(OFFIC_TYPE_CAPNAVY, "50_33_40Claire", 3, PERSONAL_NATION, false);
			ch = CreateOfficer_Cheat(OFFIC_TYPE_CAPNAVY, "50LCroft", 3, ENGLAND, false);
			ch = CreateOfficer_Cheat(OFFIC_TYPE_CAPNAVY, "Searcher_Navy", 3, PERSONAL_NATION, false);

			ChangeCharacterReputation(pchar, 60);

			GiveItem2Character(PChar, "compass3");
			EquipCharacterByItem(pchar, "compass3");
			GiveItem2Character(pchar, "spyglass4");
			EquipCharacterByItem(pchar, "spyglass4");
			GiveItem2Character(pchar, "blade13+1");
			EquipCharacterByItem(pchar, "blade13+1");
			GiveItem2Character(Pchar, "pistol5+2");
			EquipCharacterByItem(pchar, "pistol5+2");
			GiveItem2Character(pchar, "commonarmor");
			EquipCharacterByItem(pchar, "commonarmor");
			PChar.rank = 40;
			pchar.experience = CalculateExperienceFromRank(sti(PChar.rank));
			ChangeHPBonus(pchar, sti(pchar.chr_ai.hp_max));
			ResetHP(pchar);
			LAi_SetImmortal(pchar, true);

			int idx = GetMainCharacterIndex();
			aref arPerksRoot; makearef(arPerksRoot,ChrPerksList.list);
			int chrPerksQ = GetAttributesNum(arPerksRoot);
			for (i = 0; i <= GetPassengersQuantity(PChar); i++) {
				if (i > 0) {
					idx = GetPassenger(PChar, i - 1);
					if (idx < 0) continue;

					GiveItem2Character(GetCharacter(idx), "blade13+1");
					EquipCharacterByItem(GetCharacter(idx), "blade13+1");
					GiveItem2Character(GetCharacter(idx), "pistol5+2");
					EquipCharacterByItem(GetCharacter(idx), "pistol5+2");
					GiveItem2Character(GetCharacter(idx), "commonarmor");
					EquipCharacterByItem(GetCharacter(idx), "commonarmor");
					TakeNItems(GetCharacter(idx), "gunpowder", 6);
					TakeNItems(GetCharacter(idx), "pistolbullets", 6);
				}

				for (int s = 0; s < 10; s++) {
					string skillname = GetSkillName(s);
					characters[idx].Skill.(skillname) = 10;
				}

				for (int p = 0; p < chrPerksQ; p++)
				{
					string perkName = GetAttributeName(GetAttributeN(arPerksRoot, p));
					characters[idx].perks.list.(perkName) = true;
				}
			}
			SetCharacterGoods(&pchar, GOOD_BALLS, 5000);
			SetCharacterGoods(&pchar, GOOD_GUNPOWDER, 10000);
		}
	}
	AddMoneyToCharacter(PChar, 2000000);
	LogIt("Executed Console");
}
