// SCENARIO SCRIPT

// This is the special script for your entire scenario. It contains
// special encounters and code accessable from anywhere in the scenario. it also
// contains the code that initializes important special things in the
// scenario (like shops and names and descriptions of special items).

// You can create your own states, but you should give all of them numbers greater than
// or equal to 10.

beginscenarioscript;

variables;

int choice,i,j,k;
string sample_string,dlgstr;

body;

// This is the state that is called every time the scenario is loaded,
// even when a save file in the scenario is loaded. Some things that should go here:
//    Names and descriptions of special items.
//    Names and effects of custom special abilities.
beginstate LOAD_SCEN_STATE; 
	init_special_item(1,"Metal triangle","This is a small, silver, metal triangle that you found in the depths of Ancient Bahssikava.");
	init_special_item(2,"Black Key","This is a small, black, stone key. You found it behind the altar that was summoning ghosts in the library in Ancient Bahssikava.");
	init_special_item(3,"Red Iron Key","This is a small, red, iron key. Phaedra found it north of the guardpost. It unlocks a door in Central Bahssikava, according to a ghost you met.");
	init_special_item(4,"Small Copper Key","This is a small, copper key. You found it in the room of a very large haakai.");
	init_special_item(5,"Silver Key","This is a small, silver key. You found it on the altar in Northern Bahssikava after cleaning out a hive of chitrachs.");
	init_special_item(6,"Large Bronze Key","This is a large, bronze key. You found it in the Demon Golem's personal chambers.");
	init_special_item(7,"Instructions Page","This is a page of instructions that you found that seems to describe how to open a holding chamber.");
	init_special_item(8,"Phoenix Egg","This powerful magical artifact will create quickfire when used. (When an appropriate time to use it comes, you will be given the option.)");
	init_special_item(9,"Small Brass Key","This a small brass key that you found in the temple in the eastern part of Khar-Grav.");
	
	init_quest(0,"Get your mission","You are supposed to speak with a mysterious slith known as the Prophet. He has a mission for you, although you don't know what.");
	init_quest(1,"Clear a way to steel doors","Kass in Lost Bahssikava asked you to eliminate all the monsters in between Bahssikava and the steel doors in the tunnels below.");
	init_quest(2,"Scout the river to the south","Legare in the guardpost asked you to scout an opening in the south cave wall by the river and to clear it if necessary.");
	init_quest(3,"Scout to the north","Legare in the guardpost asked you to scout upriver to the north. Phaedra will help you with this.");
	init_quest(4,"Investigate ghost","A ghost in Central Bahssikava asked you to free the enslaved spirits of Bahssikavans from demons. The precise nature of what you must do was not immediately clear.");

	init_special_abil(0,"Set Cut Scene Speed",16);
	init_special_abil(1,"Phaedra Identify",17);
	init_special_abil(2,"Party location",18);
	
	if (get_flag(250,8) == 0)
		set_flag(250,8,3);
break;

// This is the state that is called only once at the very beginning of 
// the scenario. Some things that should go here:
//    The stuff in shops.
//    Creating horses and boats.
beginstate START_SCEN_STATE;
	// Initialize shops.
	
	// Shop 0 - Repel Spirit
	add_item_to_shop(0,3004,6); // Repel Spirit
	
	// Shop 1 - Silthokh
	add_item_to_shop(1,292,1); // Rod of Major Call
	add_item_to_shop(1,227,1); // Resistance Potion
	add_item_to_shop(1,309,1); // Crystal Charm
	add_item_to_shop(1,87,7); // Steel Javelin
	add_item_to_shop(1,429,1); // Shield of Kron (resist all damage)
	
	create_boat(0,2,9,4,0);
	
	toggle_quest(0,1);
	
	if (get_flag(0,21) == 0)
	{set_flag(250,0,species_in_party(0) + (species_in_party(2) * 2) + (species_in_party(3) * 4));
	set_flag(250,1,party_size());
	
	i = 0;
	while (i <= 3) {
		inc_flag(251,get_species(i),1);
		set_char_trait(i,22,1);
		change_custom_abil_uses(i,0,1);
		change_custom_abil_uses(i,2,1);
		i = i + 1;
		}
	
	set_flag(0,21,1);
	}

break;

// This state is called every tick wherever the party is in the scenario.
// You can use the set_state
beginstate START_STATE;
break;

// Place your own states below. Give each a number at least 10.
beginstate 10;
	print_str("You read a book.");
break;

beginstate 11;
	print_str("You read a book.");
break;

beginstate 12;
	print_str("You read a book.");
break;

beginstate 13; // no longer used
	reset_dialog();
	add_dialog_str(0,"This scroll is covered in writing, most in a spidery language that you cannot read. It also has a few drawings that appear to be maps! Unless you miss your guess, it shows some land north of here.",0);
	add_dialog_str(1,"To the north is a mountain, which you knew. Beyond that is a city by a river, and next to that city is a drawing of a lizard-man. It must be a city of sliths! Here, in the homeland, a city of sliths!",0);
	if (get_flag(14,5))
		add_dialog_str(2,"This could be the city of Vasskolis that Ithik mentioned.",0);
	set_flag(18,8,run_dialog(1));
break;

beginstate 14; // Wand of Devastation (removed)
break;

beginstate 15; // the first time that the party frees a golem in Mount Galthrax
	
	// i is first character in party, and j is the freed golem
	i = 0;
	while (char_ok(i) == 0)
		{i = i + 1; }
	j = 120;
	while (char_ok(j) == 0)
		{j = j - 1; }
	
	text_bubble_on_char(j,"You freed me!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(i,"Um...");
	force_instant_terrain_redraw();
	pause(4 * get_flag(250,8));
	
	text_bubble_on_char(i,"");
	text_bubble_on_char(i,"Yes.");
	force_instant_terrain_redraw();
	pause(4 * get_flag(250,8));
	
	text_bubble_on_char(i,"");
	if (party_size() > 1)
		text_bubble_on_char(i,"Yes, we did.");
	else
		text_bubble_on_char(i,"Yes, I did.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(i,"");
	text_bubble_on_char(j,"And for that, I am grateful.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"You're here to fight the dragon,");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"aren't you?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	force_instant_terrain_redraw();
	
	reset_dialog();
	add_dialog_str(0,"What do you say?",0);
	add_dialog_choice(0,"Yes, we are.");
	add_dialog_choice(1,"Um, no, of course not. We would never do that.");
	if (run_dialog(1) == 2)
		{set_flag(250,7,1);
		
		text_bubble_on_char(j,"Well, that's a pity.");
		force_instant_terrain_redraw();
		pause(5 * get_flag(250,8));
		
		text_bubble_on_char(j,"");
		text_bubble_on_char(j,"Farewell, then.");
		force_instant_terrain_redraw();
		pause(5 * get_flag(250,8));
		
		text_bubble_on_char(j,"");
		force_instant_terrain_redraw();
		
		erase_char(j);
		put_boom_on_char(j,2,0);
		run_animation_sound(163);
		
		end();
		}
	
	set_flag(250,7,2);
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"Good.");
	force_instant_terrain_redraw();
	pause(4 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"I can help you.");
	force_instant_terrain_redraw();
	pause(4 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"When you approach the dragon,");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"I will know,");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"and I will join you to fight him.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(i,"Why are you doing this?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(i,"");
	text_bubble_on_char(j,"Because I hate that infernal beast.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"We golems are his slaves,");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"and he abuses us constantly.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"His generals Vishanth and Dargenloth");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"are even worse.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	k = 5;
	while (char_ok(k) == 0)
		{k = k - 1; }
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(k,"I thought...");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(k,"");
	text_bubble_on_char(k,"that golems didn't have emotions.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(k,"");
	text_bubble_on_char(j,"That lie becomes no more true");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"each time it is so often repeated.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(k,"Oh.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(k,"");
	text_bubble_on_char(k,"My mistake.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(k,"");
	text_bubble_on_char(j,"Now go.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"And remember,");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"when you fight the dragon,");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	text_bubble_on_char(j,"I will be with you.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,8));
	
	text_bubble_on_char(j,"");
	force_instant_terrain_redraw();
	
	message_dialog("With that, he vanishes.","");
	
	erase_char(j);
	put_boom_on_char(j,2,0);
	run_animation_sound(163);
	
break;

beginstate 16; // Special ability to set cut scene speed
	change_custom_abil_uses(who_used_custom_abil(),0,1);
	
	reset_dialog();
	add_dialog_str(0,"How fast would you like the cut scenes to go?",0);
	add_dialog_choice(0,"Slow speed.");
	add_dialog_choice(1,"Normal speed.");
	add_dialog_choice(2,"Faster!");
	choice = run_dialog(1);
	if (choice == 1)
		set_flag(250,8,4);
	if (choice == 2)
		set_flag(250,8,3);
	if (choice != 3) {
		end();
		}
	
	reset_dialog();
	add_dialog_str(0,"How fast would you like the cut scenes to go?",0);
	add_dialog_choice(0,"High speed.");
	add_dialog_choice(1,"Very high speed.");
	if (get_flag(250,9) == 0)
		add_dialog_choice(2,"Skip them altogether.");
	else
		add_dialog_choice(2,"See the cut scenes.");
	choice = run_dialog(1);
	if (choice == 1)
		set_flag(250,8,2);
	if (choice == 2)
		set_flag(250,8,1);
	if (choice == 3) {
		if (get_flag(250,9) == 0) {
			reset_dialog();
			add_dialog_str(0,"If you choose to skip the cut scenes, you will get a dialog box before every cut scene starts that tells you about the cut scene that you are about to skip and gives you the option of seeing it or skipping it.",0);
			add_dialog_str(1,"Note that if you choose to watch the cut scene, it will still run at whatever speed you have set the cut scenes to run at. (That is, it will run quickly if you have set them to run at high speed.)",0);
			add_dialog_str(2,"Are you sure that you wish to activate this option?",0);
			add_dialog_choice(0,"No.");
			add_dialog_choice(1,"Yes.");
			if (run_dialog(1) == 2)
				set_flag(250,9,1);
			}
		else
			set_flag(250,9,0);
	}
break;

beginstate 17;
	change_custom_abil_uses(who_used_custom_abil(),1,1);
	begin_talk_mode(198);
break;

beginstate 18;
	change_custom_abil_uses(who_used_custom_abil(),2,1);
	
	i = 0;
	while (i <= 5) {
		if (char_ok(i)) {
			clear_buffer();
			append_string("Character number ");
			append_number(i);
			append_string(" is located at (");
			append_number(char_loc_x(i));
			append_string(",");
			append_number(char_loc_y(i));
			append_string(")");
			get_buffer_text(dlgstr);
			print_str(dlgstr);
			}
		i = i + 1;
		}
break;