begintownscript;

variables;
short choice;
short fighttimer = 0;
short pc_counter = 0;
short observer = 0;
short erase_y, erase_x;
short i;

body;

beginstate 0; //INIT_STATE

	//no time for training
	turn_off_training(1);

	//if this is your first trip
	if(get_flag(10,0) == 1) {
		//start looking at blackness
		force_view_center(23,47);
		set_character_pose(1000,14); //party is passed out
		force_instant_terrain_redraw();
		
		pause(20);
	
		reset_dialog();
		add_dialog_str(0,"You groggily awaken, feeling as if your entire body is one giant muscle cramp. You're warm. Uncomfortably so.",0);
		run_dialog(1);
		
		//shift view to drying room
		pause(10);
		force_view_center(30,12);
		force_instant_terrain_redraw();
		pause(15);
		
		reset_dialog();
		add_dialog_str(0,"As you open your eyes, you realize that you're on the floor. Slowly, you stand up and get your bearings.",0);
		add_dialog_str(1,"You're in a small room, with what appears to be a bunch of herbs laid out to dry. Meaning, you're probably somewhere in the basement still.",0);
		add_dialog_str(2,"Of course, for all you know, the portal could've malfunctioned. You could just be down the hall from Martha and the portal.",0);
		add_dialog_str(3,"One thing is certain. You feel like you've traveled a great distance in a very short time.",0);
		run_dialog(1);
		
		//party stands back up
		set_character_pose(1000,0);
		force_instant_terrain_redraw();
		
		set_flag(2,0,1);
	}

	//second trip back
	if(get_flag(10,0) == 3) {
		//start looking at blackness
		force_view_center(23,47);
		flip_terrain(28,15); //close the door to drying room
		relocate_character(0,19,25);
		relocate_character(1,19,24);
		relocate_character(2,19,23);
		relocate_character(3,19,22);
		set_character_pose(1000,14); //party is passed out
		force_instant_terrain_redraw();
		
		pause(20);
	
		reset_dialog();
		add_dialog_str(0,"This time, the pain is worse. It feels as if you've run straight into a wall at top speed. Thankfully, you don't think you're injured all that badly.",0);
		run_dialog(1);
		
		//shift view to hallway
		pause(10);
		force_view_center(19,25);
		force_instant_terrain_redraw();
		pause(15);
		
		reset_dialog();
		add_dialog_str(0,"As you open your eyes, you realize that you're flat against a wall. At least that explains your initial reaction.",0);
		add_dialog_str(1,"You're in a hallway, alone. You don't hear footsteps, which is good. No sign of demons, which is both good and bad.",0);
		add_dialog_str(2,"Of course, you still have no idea whether you're in the right place or time. You just have to hope that Martha got it right again.",0);
		run_dialog(1);
		
		//party stands back up
		set_character_pose(1000,0);
		force_instant_terrain_redraw();
	
		set_flag(2,0,2);
	}

	//third trip back
	if(get_flag(10,0) == 5) {
		//start looking at blackness
		force_view_center(23,47);
		flip_terrain(28,15); //close the door to drying room
		relocate_character(0,23,32);
		relocate_character(1,24,32);
		relocate_character(2,24,31);
		relocate_character(3,25,31);
		set_character_pose(1000,14); //party is passed out
		force_instant_terrain_redraw();
		
		pause(20);
	
		reset_dialog();
		add_dialog_str(0,"This time the trip felt like falling down a flight of stairs. You feel like you're bruised everywhere.",0);
		run_dialog(1);
		
		//shift view to hallway
		pause(10);
		activate_hidden_group(4);
		set_char_dialogue_pic(11,512,0);
		relocate_character(11,22,30);
		force_view_center(23,32);
		force_instant_terrain_redraw();
		pause(15);
		
		reset_dialog();
		add_dialog_str(0,"You aren't terribly surprised to open your eyes, and find yourself at the bottom of a flight of stairs. Either time travel is wildly imprecise, or Martha doesn't like you very much.",0);
		add_dialog_str(1,"The next thing you notice is a young woman standing over you. She looks concerned. She also looks a lot like Ethalia.",0);
		run_dialog(1);
	
		set_mobility(1000,0);
		set_flag(2,0,3);
	}
	
	//fourth trip back
	if(get_flag(10,0) == 7) {
		//start off looking at blackness for the setup
		force_view_center(47,47);
		force_instant_terrain_redraw();
	
		//set up the room for the summoning
		put_item_on_spot(18,8,417); //incense
		put_item_on_spot(18,12,417); //incense
		put_item_on_spot(22,12,417); //incense
		put_item_on_spot(22,8,417); //incense
		set_terrain(20,12,266); //brazier
		put_item_on_spot(19,9,170); //candle
		put_item_on_spot(21,9,170); //candle
		put_item_on_spot(21,11,170); //candle
		put_item_on_spot(19,11,170); //candle
		activate_hidden_group(4);
		relocate_character(11,20,13);
		set_character_facing(11,0);
		set_character_pose(11,1);
		force_instant_terrain_redraw();

		force_view_center(18,7);
		flip_terrain(28,15); //close the door to drying room
		relocate_character(0,18,7);
		relocate_character(1,19,7);
		relocate_character(2,20,7);
		relocate_character(3,21,7);
		set_character_facing(1000,4);
		force_instant_terrain_redraw();
		
		pause(10);
	
		reset_dialog();
		add_dialog_str(0,"Amazingly, you don't end up in immense pain this time. Aside from a minor headache, you're relatively unscathed, and somehow you came out standing up.",0);
		run_dialog(1);
		
		reset_dialog();
		add_dialog_str(0,"A familiar-looking young woman seems equally startled by your appearance. She's gripping a fancy-looking dagger and sporting a fresh-looking cut on her arm.",0);
		add_dialog_str(1,"You start to yell, hoping that maybe you can stop her before she completes the ritual, but you can only watch powerless as a drop of her blood drips down onto a brazier full of herbs.",0);
		add_dialog_str(2,"The concoction bursts into flames, and you notice piles of incense at the corners of the room start to burn. Smoke begins to gather in the middle of the room, and you ready your weapons.",0);
		add_dialog_str(3,"Ethalia, having barely had time to process your arrival, screams, drops the dagger, and runs to hide in the corner of the room.",0);
		run_dialog(1);
		relocate_character(11,16,13);
		set_character_facing(11,6);
		set_character_pose(11,0);
		put_item_on_spot(19,12,80); //dagger
		set_terrain(20,12,267); //light the brazier
		force_instant_terrain_redraw();
	
		set_flag(2,0,4);
		set_state_continue(30); //to the summoning!
	}
	
	//regular setup
	set_crime_tolerance(1);
	fighttimer = 0;



	
	//...clear the stupid text box, because stupid Windows computers
	//    have a stupid bug that shows all the stupid spell-learning
	//    text that Ethalia and Ach'deniz'toh learn. Stupid.
	
	i = 0;
	while (i < 64) {
		print_str(" ");
		i = i + 1;
		}

break;

beginstate 1; //EXIT_STATE
break;

beginstate 2; //START_STATE
	//Checking for the lead pc each turn... not necessary here
	//pc_counter = 0;
	//while(char_ok(pc_counter) == 0) {
	//	pc_counter = pc_counter + 1;
	//	}
	//lead_char = pc_counter;
	
	//timer for fight w/ Ethalia
	if(get_flag(2,3) == 1) {
		//if the fight has gone on for 6 rounds
		if(fighttimer == 6) {
			reset_dialog();
			add_dialog_str(0,"Ethalia stumbles, looking up at you with sheer disgust in her eyes. You can see strands of magic shimmering around her hands as she speaks.",0);
			add_dialog_str(1,"_I do not have time for your games. You have no idea what I am sacrificing to be here right now, or what I have endured. I... cannot be set back. Not now._",15);
			add_dialog_str(2,"With that, she traces a complex sigil in the air, and you become aware of a set of thin green lines leading from you back to the room where you first appeared.",0);
			add_dialog_str(3,"You watch as Ethalia makes a chopping motion with her hand, and then you briefly see the green lines severed. You almost manage to swear before everything goes black.",0);
			add_dialog_str(4,"[Move in any direction to continue.]",40);
			run_dialog(1);
			
			//remove any pesky forcecages
			pc_counter = 0;
			while(pc_counter < 4) {
				if(get_char_status(pc_counter,29) > 0)
					set_char_status(pc_counter,29, get_char_status(pc_counter, 29) * -1, 0,0);
				pc_counter = pc_counter + 1;
				}
			
			//move party into the blackness
			relocate_character(0,4,4);
			relocate_character(1,6,4);
			relocate_character(2,6,6);
			relocate_character(3,4,6);
			force_view_center(47,47);
			force_instant_terrain_redraw();
			
			award_party_xp(250,15);
			
			set_flag(2,3,2);
			end();
			}
		fighttimer = fighttimer + 1;
		}
	//timer for fight w/ demon
	if(get_flag(2,5) == 1) {
		//if the fight has gone on for 8 rounds
		if(fighttimer == 8) {
			reset_dialog();
			add_dialog_str(0,"The demon pauses. You've damaged it rather a lot, but it doesn't seem to be all that fazed.",0);
			add_dialog_str(1,"It snaps several fingers, and some familiar green lines appear in the air, connecting you to where the portal deposited you.",0);
			add_dialog_str(2,"The demon snarls, displaying several sets of mismatched teeth. Then it holds up a single, glowing claw, and once more everything goes black.",0);
			add_dialog_str(3,"[Move in any direction to continue.]",40);
			run_dialog(1);
			
			//remove any pesky forcecages
			pc_counter = 0;
			while(pc_counter < 4) {
				if(get_char_status(pc_counter,29) > 0)
					set_char_status(pc_counter,29, get_char_status(pc_counter, 29) * -1, 0,0);
				pc_counter = pc_counter + 1;
				}
			
			//move party into the blackness
			relocate_character(0,4,4);
			relocate_character(1,6,4);
			relocate_character(2,6,6);
			relocate_character(3,4,6);
			force_view_center(47,47);
			force_instant_terrain_redraw();
			
			award_party_xp(250,15);
			
			set_flag(2,5,2);
			end();
			}
		fighttimer = fighttimer + 1;
		}	
	//immediate yank after frightening young Ethalia
	if((get_flag(10,0) == 5) && (get_flag(2,6) > 0) && (get_flag(2,7) == 0)) {
		reset_dialog();
		add_dialog_str(0,"As the sound of Ethalia's footsteps fades, you become aware of a sharp tugging sensation, roughly in the location of your lower back.",0);
		add_dialog_str(1,"For a moment, the corridor grows darker. By the time you realize what's happening, it's too late. The world goes dark again.",0);
		add_dialog_str(2,"[Move in any direction to continue.]",40);
		run_dialog(1);
		
		//move party into the blackness
		relocate_character(0,4,4);
		relocate_character(1,6,4);
		relocate_character(2,6,6);
		relocate_character(3,4,6);
		force_view_center(47,47);		
		//party stands back up
		set_mobility(1000,1);
		set_character_pose(1000,0);
		force_instant_terrain_redraw();
		set_flag(2,7,1);
		}
	//the dust clearing after using the wand
	if((get_flag(2,9) > 0) && (get_flag(2,8) == 1)) {
		if(is_combat() == 1) {
			message_dialog("Now that the dust has settled, it's probably safe to sheathe your weapons now.","");
			end();
			}
		//After Ethalia is gone
		if(get_flag(2,9) == 1) {
			reset_dialog();
			add_dialog_str(0,"With Ethalia gone, you wonder if this will help avoid the paradox that Martha was talking about. Then you realize that there's still a demon in the room. And it's angry.",0);
			add_dialog_str(1,"The demon stalks over to the young Ethalia, who is still cowering in the corner.",0);
			add_dialog_str(2,"_So, you will betray me. This is valuable information. Now how will I prevent this unfortunate occurrence?_",15);
			add_dialog_str(3,"You have a bad feeling you know how this story is going to end, as you notice the world growing dark around you...",0);
			run_dialog(1);
			}
		//After the demon is gone
		else if(get_flag(2,9) == 2) {
			reset_dialog();
			add_dialog_str(0,"With the demon gone, you have a bad feeling that you've created the paradox that Martha told you to prevent.",0);
			add_dialog_str(1,"Ethalia, now looking almost serene, slowly approaches her younger self, still cowering in the corner of the room.",0);
			add_dialog_str(2,"_It's okay now. I promise you, it's okay. You're going to be just fine._",15);
			add_dialog_str(3,"That's weird. Ethalia's body seems to be fading away. In fact, it looks like the room is growing darker.",0);
			add_dialog_str(4,"_You're going to be more than fine..._",15);
			run_dialog(1);
			}
		set_flag(2,8,2);
		set_state_continue(35); //the big finish
		}
break;

beginstate 5; //stairs
	block_entry(1); //can't go up
	
	reset_dialog();
	add_dialog_str(0,"You pause at the stairs. If the goal of this mission is to not change the past, then running upstairs into the middle of a busy research lab is probably not a good idea.",0);
	add_dialog_str(1,"Hopefully you won't have any reason to go upstairs. You stay put.",0);
	run_dialog(1);
break;


beginstate 8; //warp back to present
	if((get_flag(2,3) == 2) && (get_flag(10,0) == 1)) {
		message_dialog("A familiar twisting, burning pressure tries to crush you as you fall through the void...","");
		play_sound(-10);

		set_flag(10,0,2);
		move_to_new_town(1,20,18);
		}
	if((get_flag(2,5) == 2) && (get_flag(10,0) == 3)) {
		message_dialog("A familiar twisting, burning pressure tries to crush you as you fall through the void...","");
		play_sound(-10);

		set_flag(10,0,4);
		move_to_new_town(1,37,32);
		}
	if((get_flag(2,7) == 1) && (get_flag(10,0) == 5)) {
		message_dialog("A familiar twisting, burning pressure tries to crush you as you fall through the void...","");
		play_sound(-10);

		set_flag(10,0,6);
		move_to_new_town(1,28,25);
		}
	if((get_flag(2,8) == 2) && (get_flag(10,0) == 7)) {
		force_view_center(47,47);
		force_instant_terrain_redraw();
		message_dialog("A familiar falling sensation terrifies you as the crushing force intensifies. You scream as you fall into the inky blackness...","");
		play_sound(-10);

		set_flag(10,0,8);
		pause(50);
		move_to_new_town(3,14,13);
		}
break;

beginstate 10; //open door
	if(get_flag(2,1) == 1)
		end();
	
	message_dialog("Thankfully, someone left this door open. You'd have hated to be stuck in an oven.","");
	set_flag(2,1,1);
break;

beginstate 15; //footsteps, meet Ethalia
	if(get_flag(2,2) == 1) {
		message_dialog("You try to move forward, but Ethalia motions for you to stop, and you notice a thin, invisible barrier materialize in front of you.","Hunh. Perhaps you should try talking to her.");
		block_entry(1); //can't advance
		end();
		}
	else if(get_flag(2,2) >= 2)
		end();
	
	message_dialog("You hear footsteps coming from somewhere, but you can't see anyone.","");
	
	block_entry(1); //can't advance
	
	//make Ethalia appear, walk up
	play_sound(-49);
	pause(3);
	play_sound(-50);
	pause(3);
	play_sound(-49);
	pause(3);
	play_sound(-50);
	pause(3);
	play_sound(-49);
	pause(3);
	play_sound(-50);
	pause(3);
	put_effect_on_space(28,21,4,4,1);
	run_animation();
	activate_hidden_group(2);
	set_char_dialogue_pic(9,511,0);
	relocate_character(9,28,21);
	force_instant_terrain_redraw();
	play_sound(-49);
	pause(3);
	relocate_character(9,28,20);
	force_instant_terrain_redraw();
	play_sound(-50);
	pause(3);
	
	reset_dialog();
	add_dialog_str(0,"A serious-looking mage materializes out of thin air. She holds up a hand and puts a finger to her lips.",0);
	add_dialog_str(1,"What catches your attention, however, is her face. She looks young, but her hair is streaked throughout with gray. Her eyes are dominated by oversized pupils, and her skin seems to glow.",0);
	add_dialog_str(2,"Something tells you that this must be Ethalia.",0);
	run_dialog(1);
	
	set_flag(2,2,1);
break;

beginstate 20; //open the chamber, whiff of brimstone

	//if you're in the middle of the final fight, block the exit!
	if(get_flag(2,8) > 0)
		block_entry(1);

	if((get_flag(10,0) != 3) || (get_flag(2,4) > 0))
		end();
		
	message_dialog("You catch a faint whiff of brimstone, and then you hear a click coming from the north.","");
	play_sound(-9); //door unlock
	
	set_terrain_memory_cell(7,0,0); //unlock it
	set_terrain_memory_cell(7,1,0); //no key needed
	set_terrain_memory_cell(7,4,25);//new opening trigger
	set_terrain_memory_cell(7,5,0); //no mechanical lock
	force_instant_terrain_redraw();
	
	set_flag(2,4,1);
break;

beginstate 25; //opening the door to the demon (door trigger)
	if(get_flag(2,5) > 0)
		end();
	
	activate_hidden_group(3);
	relocate_character(10,20,10); //set up the demon
	force_instant_terrain_redraw();
	pause(3);
	
	reset_dialog();
	add_dialog_str(0,"The door creaks open, and you come face-to-face with a demon. A large demon. An ugly demon. These things are all fairly standard for demons, but this one does them all to excess.",0);
	add_dialog_str(1,"It glares at you with several misplaced eyes, and speaks.",0);
	add_dialog_str(2,"_I am Ach'deniz'toh, duke of the Chained One. You are here to stop the young foolish one, no? You are too late. Her soul is of the Chained One now._",15);
	add_dialog_str(3,"_I will destroy you, just as I defeated the elder mage._",15);
	add_dialog_str(4,"An aura of flames appears around the demon, and you draw your weapons. This is not good.",0);
	run_dialog(1);
	set_attitude(10,10);
	set_flag(2,5,1);
break;

beginstate 30; //the summoning!
	put_effect_on_space(18,8,5,3,1);
	put_effect_on_space(18,12,5,3,1);
	put_effect_on_space(22,12,5,3,1);
	put_effect_on_space(22,8,5,3,1);
	put_effect_on_space(20,10,5,6,1);
	run_animation();
	pause(5);
	
	put_boom_on_space(20,10,0,0); //fiery swirl
	run_animation_sound(51); //shooting flames
	activate_hidden_group(3);
	relocate_character(10,20,10);
	set_character_pose(10,1);
	force_instant_terrain_redraw();
	pause(2);
	play_sound(-119); //demon noise
	pause(5);
	text_bubble_on_char(10,"At last!");
	force_instant_terrain_redraw();
	pause(15);
	erase_text_bubbles();
	text_bubble_on_char(10,"Who has summoned me?");
	set_character_pose(10,0);
	force_instant_terrain_redraw();
	pause(15);
	set_character_facing(10,0);
	erase_text_bubbles();
	force_instant_terrain_redraw();
	reset_dialog();
	add_dialog_str(0,"The demon scans the room, and almost immediately notices you. It glares with at least half of its eyes.",0);
	add_dialog_str(1,"_You! Why have you returned? Must I destroy you again?_",15);
	add_dialog_str(2,"As you watch the demon start an annoyingly-familiar motion, there's a crackle from the door to the room.",0);
	run_dialog(1);
	
	pause(10);
	put_boom_on_space(20,15,3,0); //icy swirl
	flip_terrain(20,15);
	set_character_facing(10,4);
	run_animation_sound(51); //shooting flames again
	
	pause(10);
	message_dialog("An all too-familiar figure appears in the doorway, looking perfectly irate.","");
	
	activate_hidden_group(2);
	relocate_character(9,20,16);
	set_character_pose(9,1);
	force_instant_terrain_redraw();
	pause(5);
	relocate_character(9,20,15);
	play_sound(-49);
	force_instant_terrain_redraw();
	pause(5);
	relocate_character(9,20,14);
	play_sound(-50);
	force_instant_terrain_redraw();
	pause(10);
	text_bubble_on_char(9,"YOU!!!");
	force_instant_terrain_redraw();
	pause(15);
	erase_text_bubbles();
	force_instant_terrain_redraw();
	reset_dialog();
	add_dialog_str(0,"Ethalia is livid. Her entire body is backlit by eerie arcane energy, and she's pointing a thin wand at the demon.",0);
	add_dialog_str(1,"_Tell your corrupt master that he reaps what he sows!_",15);
	add_dialog_str(2,"She makes a quick jab with the wand, and a bolt of energy illuminates the room. It's at this moment that you recognize that wand as the one that Martha gave to you... in the future?",0);
	run_dialog(1);
	
	pause(2);
	play_sound(-48); //berserk!
	pause(5);
	put_jagged_zap(20,14,20,10,4); //white zap
	put_boom_on_char(10,4,0);
	run_animation_sound(54); //lightning
	set_character_pose(9,2);
	force_instant_terrain_redraw();
	pause(5);
	
	reset_dialog();
	add_dialog_str(0,"The demon recoils as the bolt strikes its side, creating a long, deep gash. It winces.",0);
	add_dialog_str(1,"_Fool! You hope to defeat me with my own magic?_",15);
	add_dialog_str(2,"The demon makes a retaliatory gesture, and another bolt flies across the room.",0);
	run_dialog(1);
	
	play_sound(-119); //demon noise
	pause(5);
	set_character_pose(10,1);
	put_jagged_zap(20,10,20,14,5); //black zap
	put_boom_on_char(9,7,0);
	run_animation_sound(51); //flames
	pause(5);
	
	reset_dialog();
	add_dialog_str(0,"This bolt doesn't strike Ethalia. Instead, it strikes her wand, which vanishes in a flash of green light. She screams, produces another wand, and throws herself at the demon.",0);
	add_dialog_str(1,"Well, that explains the wand, sort of. And at least you get to fight something now.",0);
	run_dialog(1);
	set_attitude(9,11);
	set_attitude(10,10);
	set_character_pose(9,0);
	set_character_pose(10,0);
	force_instant_terrain_redraw();
	
	//block Ethalia's retreat
	set_floor(19,15,130);
	set_floor(20,15,130);
	set_floor(21,15,130);
	
	set_flag(2,8,1);
break;

beginstate 35; //the big finish
	//set up the "observer", to aid in visual tricks
	while(char_ok(observer) != 1) {
		observer = random_party_member();
		}
	//Due to occasional hiccups in the way Blades handles visibility,
	// it often helps to "move" a PC to its current space. This forces
	// the game to recalculate visibility.

	//first, replace the borders with blackness
	set_terrain(15,6,1);
	set_terrain(16,6,1);
	set_terrain(16,5,1);
	set_terrain(17,6,0);
	set_terrain(17,5,1);
	set_terrain(18,5,1);
	set_terrain(19,5,1);
	set_terrain(20,5,1);
	set_terrain(21,5,1);
	set_terrain(22,5,1);
	set_terrain(23,5,1);
	set_terrain(24,5,1);
	set_terrain(23,6,0);
	set_terrain(24,6,1);
	set_terrain(25,6,1);
	set_terrain(24,7,0);
	set_terrain(25,7,1);
	set_terrain(24,8,0);
	set_terrain(25,8,1);
	set_terrain(24,9,0);
	set_terrain(25,9,1);
	set_terrain(24,10,0);
	set_terrain(25,10,1);
	set_terrain(24,11,0);
	set_terrain(25,11,1);
	set_terrain(24,12,0);
	set_terrain(25,12,1);
	set_terrain(24,13,0);
	set_terrain(25,13,1);
	set_terrain(23,14,0);
	set_terrain(24,14,1);
	set_terrain(25,14,1);
	set_terrain(24,15,1);
	set_terrain(23,15,1);
	set_terrain(22,15,1);
	set_terrain(21,15,1);
	set_terrain(20,15,1);
	set_terrain(19,15,1);
	set_terrain(18,15,1);
	set_terrain(17,15,1);
	set_terrain(16,15,1);
	set_terrain(15,14,1);
	set_terrain(16,14,1);
	set_terrain(17,14,0);
	set_terrain(15,13,1);
	set_terrain(16,13,0);
	set_terrain(15,12,1);
	set_terrain(16,12,0);
	set_terrain(15,11,1);
	set_terrain(16,11,0);
	set_terrain(15,10,1);
	set_terrain(16,10,0);
	set_terrain(15,9,1);
	set_terrain(16,9,0);
	set_terrain(15,8,1);
	set_terrain(16,8,0);
	set_terrain(15,7,1);
	set_terrain(16,7,0);
	relocate_character(observer, char_loc_x(observer), char_loc_y(observer));
	force_instant_terrain_redraw();
	pause(2);
	
	//now, the darkness closes in
	set_floor(17,6,255);
	set_floor(18,6,255);
	set_floor(19,6,255);
	set_floor(20,6,255);
	set_floor(21,6,255);
	set_floor(22,6,255);
	set_floor(23,6,255);
	set_floor(23,7,255);
	set_terrain(23,7,0);
	set_height(23,7,4);
	set_floor(24,7,255);
	set_floor(24,8,255);
	set_floor(24,9,255);
	set_floor(24,10,255);
	set_floor(24,11,255);
	set_floor(24,12,255);
	set_floor(24,13,255);
	set_floor(23,13,255);
	set_terrain(23,13,0);
	set_height(23,13,4);
	set_floor(23,14,255);
	set_floor(22,14,255);
	set_floor(21,14,255);
	set_floor(20,14,255);
	set_floor(19,14,255);
	set_floor(18,14,255);
	set_floor(17,14,255);
	set_floor(17,13,255);
	set_terrain(17,13,0);
	set_height(17,13,4);
	set_floor(16,13,255);
	set_floor(16,12,255);
	set_floor(16,11,255);
	set_floor(16,10,255);
	set_floor(16,9,255);
	set_floor(16,8,255);
	set_floor(16,7,255);
	set_floor(17,7,255);
	set_terrain(17,7,0);
	set_height(17,7,4);
	relocate_character(observer, char_loc_x(observer), char_loc_y(observer));
	force_instant_terrain_redraw();
	pause(2);
	
	//lather, rinse... (black out the stairs)
	set_floor(18,7,255);
	set_terrain(18,7,0);
	set_floor(19,7,255);
	set_terrain(19,7,0);
	set_floor(20,7,255);
	set_terrain(20,7,0);
	set_floor(21,7,255);
	set_terrain(21,7,0);
	set_floor(22,7,255);
	set_terrain(22,7,0);
	set_floor(23,8,255);
	set_terrain(23,8,0);
	set_floor(23,9,255);
	set_terrain(23,9,0);
	set_floor(23,10,255);
	set_terrain(23,10,0);
	set_floor(23,11,255);
	set_terrain(23,11,0);
	set_floor(23,12,255);
	set_terrain(23,12,0);
	set_floor(22,13,255);
	set_terrain(22,13,0);
	set_floor(21,13,255);
	set_terrain(21,13,0);
	set_floor(20,13,255);
	set_terrain(20,13,0);
	set_floor(19,13,255);
	set_terrain(19,13,0);
	set_floor(18,13,255);
	set_terrain(18,13,0);
	set_floor(17,12,255);
	set_terrain(17,12,0);
	set_floor(17,11,255);
	set_terrain(17,11,0);
	set_floor(17,10,255);
	set_terrain(17,10,0);
	set_floor(17,9,255);
	set_terrain(17,9,0);
	set_floor(17,8,255);
	set_terrain(17,8,0);
	relocate_character(observer, char_loc_x(observer), char_loc_y(observer));
	force_instant_terrain_redraw();
	pause(2);
	
	//hitting the edge of the circle now...
	set_floor(18,8,255);
	set_floor(19,8,255);
	set_floor(20,8,255);
	set_floor(21,8,255);
	set_floor(22,8,255);
	set_floor(22,9,255);
	set_floor(22,10,255);
	set_floor(22,11,255);
	set_floor(22,12,255);
	set_floor(21,12,255);
	set_floor(20,12,255);
	set_terrain(20,12,0); //don't forget the brazier!
	set_floor(19,12,255);
	set_floor(18,12,255);
	set_floor(18,11,255);
	set_floor(18,10,255);
	set_floor(18,9,255);
	relocate_character(observer, char_loc_x(observer), char_loc_y(observer));
	force_instant_terrain_redraw();
	pause(2);
	
	//get it over with!
	set_floor(19,9,255);
	set_floor(20,9,255);
	set_floor(21,9,255);
	set_floor(21,10,255);
	set_floor(21,11,255);
	set_floor(20,11,255);
	set_floor(19,11,255);
	set_floor(19,10,255);
	relocate_character(observer, char_loc_x(observer), char_loc_y(observer));
	force_instant_terrain_redraw();
	pause(2);
	
	//final, center square, then raise the center
	set_floor(20,10,255);
	relocate_character(observer, char_loc_x(observer), char_loc_y(observer));
	force_instant_terrain_redraw();
	pause(2);
	set_height(17,7,5);
	set_height(18,7,5);
	set_height(19,7,5);
	set_height(20,7,5);
	set_height(21,7,5);
	set_height(22,7,5);
	set_height(23,7,5);
	set_height(17,8,5);
	set_height(18,8,5);
	set_height(19,8,5);
	set_height(20,8,5);
	set_height(21,8,5);
	set_height(22,8,5);
	set_height(23,8,5);
	set_height(17,9,5);
	set_height(18,9,5);
	set_height(19,9,5);
	set_height(20,9,5);
	set_height(21,9,5);
	set_height(22,9,5);
	set_height(23,9,5);
	set_height(17,10,5);
	set_height(18,10,5);
	set_height(19,10,5);
	set_height(20,10,5);
	set_height(21,10,5);
	set_height(22,10,5);
	set_height(23,10,5);
	set_height(17,11,5);
	set_height(18,11,5);
	set_height(19,11,5);
	set_height(20,11,5);
	set_height(21,11,5);
	set_height(22,11,5);
	set_height(23,11,5);
	set_height(17,12,5);
	set_height(18,12,5);
	set_height(19,12,5);
	set_height(20,12,5);
	set_height(21,12,5);
	set_height(22,12,5);
	set_height(23,12,5);
	set_height(17,13,5);
	set_height(18,13,5);
	set_height(19,13,5);
	set_height(20,13,5);
	set_height(21,13,5);
	set_height(22,13,5);
	set_height(23,13,5);
	set_floor(20,10,255);
	relocate_character(observer, char_loc_x(observer), char_loc_y(observer));
	force_instant_terrain_redraw();
	
	//get rid of all NPCs, items, fields
	erase_char(9);
	erase_char(10);
	erase_char(11);
	erase_x = 16;
	erase_y = 6;
	while(erase_y <= 15) {
		while(erase_x <= 24) {
			move_item_on_spot(erase_x, erase_y, -1, -1); //nuke any items
			put_field_on_space(erase_x, erase_y, -1); //nuke any fields
			put_stain_on_space(erase_x, erase_y, -1); //nuke any stains
			erase_x = erase_x + 1;
			}
		erase_x = 16;
		erase_y = erase_y + 1;
		}
	//remove any pesky forcecages
	pc_counter = 0;
	while(pc_counter < 4) {
		if(get_char_status(pc_counter,29) > 0)
			set_char_status(pc_counter,29, get_char_status(pc_counter, 29) * -1, 0,0);
		pc_counter = pc_counter + 1;
		}
	force_instant_terrain_redraw();
	pause(5);
	
	//stars come out
	set_floor(20,10,162);
	force_instant_terrain_redraw();
	pause(1);
	set_floor(20,6,158);
	force_instant_terrain_redraw();
	pause(1);
	set_floor(21,14,163);
	force_instant_terrain_redraw();
	pause(1);
	set_floor(23,9,163);
	force_instant_terrain_redraw();
	pause(2);
	set_floor(17,11,160);
	force_instant_terrain_redraw();
	pause(2);
	set_floor(19,12,158);
	force_instant_terrain_redraw();
	pause(2);
	set_floor(17,8,156);
	force_instant_terrain_redraw();
	pause(2);
	set_floor(23,13,157);
	force_instant_terrain_redraw();
	pause(2);
	set_floor(24,10,159);
	force_instant_terrain_redraw();
	pause(3);
	set_floor(16,9,161);
	force_instant_terrain_redraw();
	pause(3);
	set_floor(22,11,156);
	force_instant_terrain_redraw();
	pause(3);
	set_floor(22,7,157);
	force_instant_terrain_redraw();
	pause(3);
	set_floor(18,13,161);
	force_instant_terrain_redraw();
	pause(3);
	set_floor(21,8,159);
	force_instant_terrain_redraw();
	
	set_state_continue(36); //this state is already too long
break;

beginstate 36; //the big finish
	pause(5);
	reset_dialog();
	add_dialog_str(0,"You are thrust into yet another void. This one, at least, is full of stars.",0);
	run_dialog(1);
	
	pause(10);
	message_dialog("You wait for that familiar feeling of being yanked back to the present, but it doesn't come.","");
	
	pause(15);
	message_dialog("At least the stars are pretty.","");
	
	pause(10);
	message_dialog("In all this time, you haven't worried about paradoxes, crazed mages, or even how you're breathing right now.","It's almost relaxing.");
	
	pause(15);
	message_dialog("The stars abruptly wink out of existence, and you suddenly feel like your entire body is being crushed by some invisible force.","[Move in any direction to continue.]");
	
	//move party into the blackness
	relocate_character(0,4,4);
	relocate_character(1,6,4);
	relocate_character(2,6,6);
	relocate_character(3,4,6);
	force_view_center(47,47);
	force_instant_terrain_redraw();
break;