// Town 32: Gateway Cave
begintownscript;

variables;

short choice,i,j,k;
string dlgstr;

body;

beginstate INIT_STATE;
	set_crime_tolerance(2);
	enable_add_chars(1);
	
	set_name(6,"Sivolass");
	set_name(7,"Pithoss"); // type 112
	set_name(8,"Kass"); // type 36
	set_name(10,"Ethass"); // type 111
	set_name(11,"Talas"); // type 112
	set_name(12,"Silthokh"); // type 111
	set_name(13,"Ithik"); // type 112
	set_name(14,"Machrone"); // type 78
	
	if (get_flag(32,0) == 0) {
		force_instant_terrain_redraw();
		set_flag(32,0,1);
		message_dialog("You enter the small cave on the island in the middle of Lake Avernoss.","The sign on the wall says, _Seithon thenoorhoom theifoorhoom voonitoon pesthathokh thefakhathoon lothamon._ That is, We praise Seithoss, greatest of all the gods, sheltering his faithful.");
		}
		
	if ((get_flag(45,2) == 0) || (get_flag(45,3) != 0)) {
		if (get_flag(45,3) != 0)
			message_dialog("You cannot re-enter Sivolass's cave. Powerful, unbreakable magic blocks the way back to the Land of the Dead.","");
		set_terrain(39,19,453);
		set_terrain(39,20,453);
		set_terrain(39,21,453);
		set_terrain(39,22,453);
		set_terrain(39,23,453);
		set_terrain(39,24,453);
		set_terrain(39,25,453);
		set_terrain(39,26,453);
		set_terrain(39,27,453);
		set_terrain(39,28,453);
		}
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;
	reset_dialog_preset_options(3);
	if (run_dialog(1) == 2)
		move_to_new_town(46,18,16);
break;

beginstate 11;
	reset_dialog_preset_options(3);
	add_dialog_str(1,"Judging by the energy radiated by this portal, it's one-way. If you enter, you will not be able to come back.",0);
	if (run_dialog(1) == 1)
		end();
	
	i = 0;
	while (char_ok(i) == 0)
		{i = i + 1; }
	
	march_party(5,24);
	force_view_center(5,24);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	message_dialog("You take a step closer to the portal that will take you the to the Land of the Dead. But before you can step inside it, you hear something from the other end of the cave.","");
	
	force_view_center(40,24);
	set_total_visibility(1);
	activate_hidden_group(1);
	put_boom_on_char(7,2,0);
	put_boom_on_char(8,2,0);
	put_boom_on_char(9,2,0);
	put_boom_on_char(10,2,0);
	put_boom_on_char(11,2,0);
	put_boom_on_char(12,2,0);
	put_boom_on_char(13,2,0);
	put_boom_on_char(14,2,0);
	run_animation_sound(10);
	
	text_bubble_on_char(7,"Hang on!");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(7,"");
	force_instant_terrain_redraw();
	
	message_dialog("You wait for a moment as the crowd approaches you. Everyone's here: Pithoss, Kass, Phaedra, Machrone, Ethass, Talas, Silthokh, and Ithik.","");
	
	set_total_visibility(0);
	force_view_center(10,24);
	set_character_facing(0,6);
	set_character_facing(1,6);
	set_character_facing(2,6);
	set_character_facing(3,6);
	relocate_character(7,14,24);
	relocate_character(8,14,23);
	relocate_character(12,15,22);
	relocate_character(10,15,23);
	relocate_character(11,15,24);
	relocate_character(13,15,25);
	relocate_character(9,15,26);
	force_instant_terrain_redraw();
	
	text_bubble_on_char(7,"We wanted to wish you well");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(7,"");
	text_bubble_on_char(7,"before your journey.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(7,"");
	text_bubble_on_char(8,"Remember: much depends on you.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(8,"");
	text_bubble_on_char(8,"Save the Prophet.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(8,"");
	text_bubble_on_char(8,"He does not deserve");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(8,"");
	text_bubble_on_char(8,"the torments of demons.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(8,"");
	force_instant_terrain_redraw();
	
	message_dialog("You nod, assuring them that you will do your best. You start to turn back to the portal, but before you can step in, Phaedra starts casually walking forward.","");
	
	set_character_facing(9,1);
	relocate_character(9,14,25);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(9,13,24);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	set_character_facing(9,2);
	relocate_character(9,12,24);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(9,11,24);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(9,10,24);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	text_bubble_on_char(i,"What are you doing?");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(i,"");
	text_bubble_on_char(9,"I'm coming with you, of course.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(9,"");
	text_bubble_on_char(9,"Just think of how much trouble");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(9,"");
	text_bubble_on_char(9,"you'd get into without me.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(9,"");
	force_instant_terrain_redraw();
	
	reset_dialog();
	add_dialog_str(0,"She flashes you a grin. What do you say?",0);
	add_dialog_choice(0,"Okay.");
	add_dialog_choice(1,"Didn't you just give birth?");
	if (run_dialog(1) == 2)
		message_dialog("She giggles. _Oh, that was a while ago, just after the Lava Ocean. I'm much better now. Maybe not at top condition, but I won't slow you down. And I've learned a few magical spells that we'll need. Trust me._","She flashes you a winning grin again.");
	add_char_to_party(9);
	
	message_dialog("With that, you and Phaedra enter the portal to the Land of the Dead.","");
	
	move_to_new_town(33,34,6);
	
break;

beginstate 12;
	if (get_terrain(39,28) == 453)
		message_dialog("There is a completely impenetrable field here, one that defies your every effort to break through it. You must not be able to get in yet.","");
break;

beginstate 13;
if (get_flag(32,1) == 0) {
	reset_dialog();
	add_dialog_str(0,"This device has a whole bunch of switches and buttons. It glows dimly, as if active but dormant. Nothing is labeled.",0);
	add_dialog_str(1,"What do you do?",0);
	add_dialog_choice(0,"Leave everything alone.");
	add_dialog_choice(1,"Fiddle blindly with the controls.");
	if (run_dialog(1) == 1)
		end();
		
	put_boom_on_space(26,32,1,0);
	run_animation_sound(73);
	
	message_dialog("A small explosion goes off! Everything shuts down and shifts back to its orginal position. Nothing else happens.","You play with the controls a little bit more, but nothing continues to happen. Apparently you cannot solve the mystery of the crystal pillars here.");
	set_flag(32,1,1);
	}
break;