
// TOWN SCRIPT
//    Town 26: Chasms of Fire

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

short a,i,j,k,r1,t,choice;

body;

beginstate INIT_STATE;
	set_name(8,"Thrytho");
	set_name(40,"Rauling");
	a = get_current_tick();	
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
//	print_big_str("The value of variable a is now ",a,".");
//	t = get_current_tick();
//	print_big_str("The time is now ",t," minutes.");
	if (get_current_tick() == a + 2)
		set_state_continue(29);
break;

beginstate 10;
	if (get_flag(26,0) == 250)
		end();
	reset_dialog();
	add_dialog_str(0,"A tremendous shock reverberates through the passages. With a vast crash, the path behind you closes in an avalache of rocks. A wave of force sweeps past you, opening up a great, fiery cavern ahead.",0);
	add_dialog_str(1,"In the middle of the lake of fire is a high, broad pedestal of rock, upon which stands a thin, humanoid shadow. It turns to you. Its face is impossible to see, its whole form appearing as only a silhouette against the leaping flames.",0);
	add_dialog_str(2,"Around it circle five jewels, each consumed with its own power, each traversing its own orbit, weaving a cyclone of prismatic energy around the shadow that stands amidst it all. Then it speaks, an eerie echo that you have heard before.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_flag(26,0,250);
	set_state_continue(12);
break;

beginstate 11;
	message_dialog("The thin hole leads far, far up. It is beyond your power to ascend now.","");
	block_entry(1);
break;

beginstate 12;
	reset_dialog();
	add_dialog_str(0,"_An-pal. You are here, then. You are the last. Come._ It raises an arm, beckoning you forward. Drawn against your will, you stumble ahead. From within your pack, the obsidian orb's strength flows through you, taking total control.",0);
	add_dialog_str(1,"You are dragged to the ring just below the pedestal, and drop to the ground. Several others kneel beside you. One of them looks up at you pitifully, the ruined face of the Falcon-King. _I am... sorry. Trick... not weapon. You must... the sixth._",0);
	add_dialog_str(2,"With a thin, shrill note, the obsidian orb leaves you, draining your essence as it flies up to join the other five, blazing with a trail of dark fire in its path. The world trembles. You are overcome by a stroke of near-paralysis to your mind.",0);
	add_dialog_str(3,"The shadow speaks, words that pass your ears without your understanding. Slowly, wrenchingly, a gateway opens above. Chaos swirls within it, or some greater pattern that you cannot possibly fathom, and it begins to suck everything in.",0);
	add_dialog_str(4,"One by one, the forms beside you erupt into flame. You struggle to your feet. Smouldering souls surround you, staring balefully. You seem to remain the only things stationary in a whirling, burning universe.",0);
	add_dialog_str(5,"There is one last trial to be passed. This time, however, there will be neither help nor guidance.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_state_continue(14);
break;

beginstate 13;
	if (is_combat()) {
	block_entry(1);
	end();
	}
	set_state_continue(10);
break;

beginstate 14;
	change_spec_item(4,-1);
	set_terrain(12,11,166);
	set_state_continue(15);
break;

beginstate 15;
	teleport_party(28,33,1);
	set_state_continue(21);
break;

beginstate 16;
//5 moves till state 17
// OBSOLETE NODE: Timers are no longer used. Manually write scenario timers in the 
// scenario script. Pick a stuff done flag for the timer, set it to the number of turns
// for the timer, and have it be decreased 1 in state START_STATE in the scenario script.
break;

beginstate 17;
	damage_near_loc(31,33,200,0,1);
	set_state_continue(16);
break;

beginstate 20;
	reset_dialog();
	add_dialog_str(0,"A gentle voice speaks to you in the strange void. The voice has an odd resonance, as though the speaker isn't really there.",0);
	add_dialog_str(1,"_Six cycles have passed, and the pattern is complete. A new pattern must begin for the weavers. You have your own path to find, free from what fates await. Let the journey recommence; let the river go on._",0);
	add_dialog_str(2,"* * *",0);
	add_dialog_str(3,"The world lights up around you. The landscape and the scene are strangely familiar, but you simply cannot put a name to it. It's an odd feeling. You appear to be in a coastal city.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_flag(9,0,28);
	block_entry(1);
	move_to_new_town(29,32,46);
	end();
break;


beginstate 21;
	activate_hidden_group(1);
	set_state_continue(16);
break;

beginstate 22;
	message_dialog("The shadow fades briefly. Then it reappears, seeming no more harmed than before.","");
	activate_hidden_group(2);
break;

beginstate 23;
	message_dialog("The shadow fades briefly. Then it reappears, seeming no more harmed than before.","");
	activate_hidden_group(3);
break;

beginstate 24;
	message_dialog("The shadow fades briefly. Then it reappears, seeming no more harmed than before.","");
	activate_hidden_group(4);
break;

beginstate 25;
	message_dialog("The shadow finally fades, and does not return. But nothing else happens.","");
break;

//Adding the stuff done flags to state 26 stopped the terrain scripts "chain reacting" 
//all over the place.
beginstate 26;
	if (get_flag(26,26) == 250)
		end();
	reset_dialog();
	add_dialog_str(0,"Gathering all of your strength, you focus the positive energy within you and aim it at the shadow and the gate. Slowly, the enveloping force rises...",0);
	add_dialog_str(1,"You feel the absolute necessity to STAY IN YOUR CURRENT GROUP FORMATION for one more moment as you wait for your invocation to strike.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	a = get_current_tick();
	set_flag(26,26,250);
break;

beginstate 29;
	if (get_flag(26,0) != 250)
		end();
	reset_dialog();
	add_dialog_str(0,"Your exertion of energy seems to be the only thing moving, inexorably approaching the gateway in slowed motion, diminishing little in power as it rises through the smoke-choked air...",0);
	add_dialog_str(1,"A blast of force engulfs you from behind, sending you spinning forward. Then somethings strikes from ahead. Everything goes white for a moment, then black.",0);
	add_dialog_str(2,"* * *",0);
	add_dialog_str(3,"There is only void around you. All black. You aren't quite sure whether you're awake, or even alive. You are simply... here.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_state_continue(31);	
break;

beginstate 31;
	i = 6;
	while (i < NUM_CHARS) {
		erase_char(i);
		i = i + 1;
		}
	teleport_party(38,8,0);
break;


beginstate 35;
	if (get_flag(151,0) == 250)
		end();
	reset_dialog();
	add_dialog_str(0,"The air before you crackles slightly, as though a massive amount of energy had just passed. Behind it stands a dark-robed, bent-over figure. An old, wrinkled face peers at you, the face of the famed alchemist of Hetware.",0);
	add_dialog_str(1,"_I had promised myself, never again,_ she whispers. _Perhaps that was over rash. I had not then seen what would lie in front of you today. But may this be the last exception I make._",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_flag(151,0,250);
	activate_hidden_group(8);	
break;

beginstate 37;
	reset_dialog();
	add_dialog_str(0,"Rauling reels, knocked out of breath by your attack. Just as he's about to spring back with renewed vigor, a blast of light comes from the tunnel beyond. Without the time to react, he vanishes into a thin mist.",0);
	add_dialog_str(1,"Someone, or something, is waiting. Friendly or hostile, you cannot tell.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
break;

beginstate 38;
	block_entry(1);
break;
