// Town 44: Thanopolen Tower
begintownscript;

variables;

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

body;

beginstate INIT_STATE;
	set_crime_tolerance(2);
	
	set_name(6,"Jailer");
	set_name(7,"Ethass"); // type 111
	set_name(9,"Ethass"); // as the Goddess
	
	add_range_to_group(14,21,1);
	set_level(1001,80);
	
	change_blocked(30,29,1);
	change_blocked(29,29,1);
	change_blocked(28,29,1);
	change_blocked(27,29,1);
	change_blocked(26,29,1);
	
	if (get_flag(44,0) == 0) {
		force_instant_terrain_redraw();
		set_flag(44,0,1);
		message_dialog("You ascend the stairs up the tower in the middle of Thanopolen. Your skin tingles: somewhere nearby is powerful magical energy, perhaps with Ethass alongside it.","");
		}
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
if (get_flag(44,3) == 0)
	end();
	
	change_char_health(9,get_max_health(9));
	set_char_status(9,14,3,1,0);
	set_char_status(9,4,3,1,0);
	set_char_status(9,30,30,1,0);
	if (get_flag(44,5) < 2) {
		set_char_status(8,4,2,1,0);
		if (get_health(8) < get_max_health(8)) {
			heal_char(8,get_max_health(8));
			print_str_color("Vakhoss heals himself fully!",2);
			}
		}
	heal_char(10,get_max_health(10));
	heal_char(11,get_max_health(11));
	print_str_color("Legare heals himself and Pithoss!",2);
break;

beginstate 10;
	block_entry(1);
	reset_dialog_preset_options(2);
	if (run_dialog(1) == 2) {
		play_sound(99);
		print_str_color("You hear the sounds of chains and grinding gears.",2);
		flip_terrain(5,30);
		flip_terrain(4,20);
		flip_terrain(4,21);
		}
break;

beginstate 11;
	block_entry(1);
	reset_dialog_preset_options(2);
	if (run_dialog(1) == 2) {
		play_sound(99);
		print_str_color("You hear the sounds of chains and grinding gears.",2);
		flip_terrain(6,30);
		flip_terrain(4,26);
		flip_terrain(4,27);
		}
break;

beginstate 12;
	block_entry(1);
	reset_dialog_preset_options(2);
	if (run_dialog(1) == 2) {
		play_sound(99);
		print_str_color("You hear the sounds of chains and grinding gears.",2);
		flip_terrain(7,30);
		flip_terrain(9,20);
		flip_terrain(9,21);
		}
break;

beginstate 13;
	block_entry(1);
	reset_dialog_preset_options(2);
	if (run_dialog(1) == 2) {
		play_sound(99);
		print_str_color("You hear the sounds of chains and grinding gears.",2);
		flip_terrain(8,30);
		flip_terrain(9,26);
		flip_terrain(9,27);
		}
break;
	
beginstate 14;
	if (get_flag(44,1) == 0) {
		set_flag(44,1,1);
		message_dialog("This cell looks recently lived-in, and the sign on the wall says, _Ethass._ You have no doubt that she has been here recently, but she is not being kept here now.","She must be nearby, though.");
		}
break;
	
beginstate 15;
	if (get_flag(44,2) == 0) {
		set_flag(44,2,1);
		message_dialog("Behind this door, you can hear the sounds of sliths shouting. Something significant must be going on back there. And there are a lot of different voices, indicating a lot of different sliths.","You will need to beat a hasty retreat once you arouse the attention of this large group. That means that if you want to explore anything else, you should do that first.");
		}
break;
	
beginstate 16;
	if (get_flag(44,3) != 0) {
		message_dialog("You don't fiddle with the trapped door again, realizing that it could only do harm, not good.","");
		end();
		}
	
	set_flag(44,3,1);
	message_dialog("You begin to open this door, and then suddenly you realize that it has a trap. A teleport trap. Before you can remove your hand, there is a flash, and you are somewhere else.","");
	teleport_party(19,5,0);
	message_dialog("You are inside the room you were entering, but you are at the end. You can see Ethass! No longer possessed by the Goddess, she looks all-too-mortal as she walks forward.","");
	
	i = 0;
	while (char_ok(i) == 0)
		{i = i + 1; }
	
	set_total_visibility(1);
	force_view_center(5,4);
	force_instant_terrain_redraw();
	
	relocate_character(7,3,7);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(7,3,6);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(7,3,5);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	set_character_facing(8,6);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	text_bubble_on_char(8,"So you have come for her,");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	clear_buffer();
	append_char_name(i);
	append_string(".");
	get_buffer_text(dlgstr);
	
	text_bubble_on_char(8,"");
	text_bubble_on_char(8,dlgstr);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(8,"");
	force_instant_terrain_redraw();
	
	message_dialog("_I know why you have come,_ he continues. _I know her value to you. But you cannot have her. She is a shell, now, her mind so easily ripped from this body, now unable to resist any of my commands. You shall see._","He turns to Ethass, but something goes awry.");
	
	set_character_facing(8,4);
	text_bubble_on_char(7,"Vakhoss, you are a LIAR.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(7,"");
	erase_char(7);
	activate_hidden_group(1);
	put_boom_on_char(9,6,0);
	run_animation_sound(54);
	
	text_bubble_on_char(8,"What?");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(8,"");
	text_bubble_on_char(8,"Who are you?");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(8,"");
	text_bubble_on_char(9,"I...");
	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,"You can see the Goddess falter for a moment. If she reveals herself as Hathnazriakh, these sliths will get on their knees and worship her. However, they will expect her to kill you immediately.",0);
	add_dialog_str(1,"If she reveals herself as Althanazaria, these sliths may not know that Althanazaria and Hathnazriakh are the same goddess, and in that case, they would know only that she was a good goddess, not one of their foul pantheon. They might still fight.",0);
	add_dialog_str(2,"You can see the two halves of the Goddess warring on her face. She has been Hathnazriakh for aeons, but something made her decide to change, and that something is exerting a powerful force now.",0);
	add_dialog_str(3,"She decides.",0);
	run_dialog(1);
	
	text_bubble_on_char(9,"I am the goddess ALTHANAZARIA.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(9,"");
	text_bubble_on_char(8,"Althanazaria? You are our enemy!");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(8,"");
	text_bubble_on_char(8,"Kill her!");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(8,"");
	force_instant_terrain_redraw();
	
	message_dialog("The barbaric sliths move to attack, but the standoff is not over yet. At this moment, two newcomers teleport into the room.","It's Legare and Pithoss!");
	
	force_view_center(12,3);
	activate_hidden_group(2);
	put_boom_on_char(10,2,0);
	put_boom_on_char(11,2,0);
	run_animation_sound(10);
	
	set_name(10,"Legare"); // type 119
	set_name(11,"Pithoss"); // type 112
	char_give_item(11,234);
	set_level(10,90);
	set_level(11,90);
	
	text_bubble_on_char(10,"Lay not a hand on my love!");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(10,"");
	text_bubble_on_char(10,"Prepare to meet your god,");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(10,"");
	text_bubble_on_char(10,"Kelora-Nak the Liar,");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(10,"");
	text_bubble_on_char(10,"face to face!");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(10,"");
	force_instant_terrain_redraw();
	
	set_total_visibility(0);
	force_view_center(char_loc_x(i),char_loc_y(i));
	force_instant_terrain_redraw();
	
	message_dialog("And so battle is joined. You will fight alongside Legare and Pithoss for the first time, hoping to save Ethass.","You hope for a moment that the Goddess will intervene and give some divine help, but it appears that she cannot. She is busy defending Ethass's body from attackers.");
	
	set_char_status(9,14,20,1,0);
	set_char_status(9,4,20,1,0);
	set_char_status(9,30,40,1,0);
	
	set_terrain(1,7,453);
	set_terrain(2,7,453);
	set_terrain(3,7,453);
	set_terrain(1,3,453);
	set_terrain(2,3,453);
	set_terrain(3,3,453);
	
break;

beginstate 17;
if (get_flag(44,4) == 0) {
	reset_dialog();
	add_dialog_str(0,"On these shelves, you find what appears to be a spellbook. It is very small but in good condition. It is perhaps large enough to contain one spell.",0);
	add_dialog_str(1,"Reading strange spellbooks can be dangerous: they can carry curses or other terrible effects. However, they can also have great spells recorded within.",0);
	add_dialog_str(2,"What do you do?",0);
	add_dialog_choice(0,"Leave it alone.");
	add_dialog_choice(1,"Attempt to read it.");
	if (run_dialog(1) == 2) {
		reset_dialog();
		// Requires Arcane Lore of 26.
		if (get_skill_total(42) >= 26) {
			add_dialog_str(0,"The book is written in a strange rune script, but fortunately, due to your knowledge of Arcane Lore, you can read it.",0);
			// Requires some skill in the spell already.
			if (get_flag(292,6) > 0) {
				set_flag(44,4,1);
				add_dialog_str(1,"It's a very advanced spellbook describing how to cast Destroy Mind in the most efficient fashion possible. You read over it carefully.",0);
				set_flag(292,6,3); // flag for spell
				}
			else
				add_dialog_str(1,"It's a very advanced spellbook describing how to cast a complex spell, Destroy Mind, in a very efficient manner. Unfortunately, you are completely unfamiliar with the spell, so it is too hard for you to understand.",0);
			run_dialog(1);
			}
		else
			message_dialog("The book is written in a strange rune script, and unfortunately, you can't read it. Perhaps if you knew more about Arcane Lore, you would be able to.","");
		}
	}
else
	message_dialog("You find the book on Destroy Mind again, but you don't learn anything new from it.","");
break;

beginstate 18;
	inc_flag(44,5,1);
	if (get_flag(44,5) == 1) {
		reset_dialog();
		add_dialog_str(0,"You kill one of the barbarian mages, expecting the other sliths to be deterred, if just for a moment. They are not. They press on even harder now.",0);
		add_dialog_str(1,"The barbarian chief standing in front of the altars seems to be surrounded by a massive impenetrable shield. Even if you could hurt him, you don't think the damage could last while that shield is up.",0);
		add_dialog_str(2,"You can feel some power building up near Legare. He must be about to do something.",0);
		run_dialog(1);
		}
	if (get_flag(44,5) == 2) {
		reset_dialog();
		add_dialog_str(0,"You kill the other of the barbarian mages. Now the barbarian chief looks slightly anxious. Not terribly, but just enough that you think you might be winning!",0);
		add_dialog_str(1,"His impenetrable shield is still intact, though. As long as that is up, you can do nothing.",0);
		add_dialog_str(2,"For a second time, you feel Legare building up the strength to do something, although you can't sense exactly what.",0);
		run_dialog(1);
		}
break;

beginstate 19;
if (get_flag(44,6) == 1)
	block_entry(1);
break;

beginstate 20;
	force_view_center(char_loc_x(8),char_loc_y(8));
	
	text_bubble_on_char(8,"No!");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(8,"");
	text_bubble_on_char(8,"NATHAGANTH TAKE YOU!");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(8,"");
	force_instant_terrain_redraw();
	
	message_dialog("Mortally wounded, the barbarian chief shrieks terrible words of curse, words that rush by too fast for you to understand.","");
	
	put_jagged_zap(char_loc_x(8),char_loc_y(8),char_loc_x(10),char_loc_y(10),2);
	put_boom_on_char(10,3,0);
	run_animation_sound(65);
	
	text_bubble_on_char(9,"Legare!");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(9,"");
	force_instant_terrain_redraw();
	
	force_view_center(char_loc_x(10),char_loc_y(10));
	kill_char(10,14,0);
	
	pause(get_flag(290,0) * 3);
	
	force_view_center(char_loc_x(8),char_loc_y(8));
	text_bubble_on_char(9,"LEGARE!");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(9,"");
	force_instant_terrain_redraw();
	
	message_dialog("The word lingers in the air. Legare staggers, appearing propped up by the Goddess's magic. He looks up at Ethass inhabited by the Goddess, and two sentences come from his mouth addressed to her: _I love you. And... I believe._","With that, he dies.");
	
	force_view_center(char_loc_x(10),char_loc_y(10));
	set_terrain(char_loc_x(10),char_loc_y(10),269);
	erase_char(10);
	force_instant_terrain_redraw();
	
	pause(get_flag(290,0) * 3);
	
	message_dialog("No one moves. Ethass and Pithoss stare, eyes wide with horror, completely unable to do anything about what they are seeing. Vakhoss's lips curl into a smile.","Then, with not another word of poison, the damage done, he dies as well.");
	
	force_view_center(char_loc_x(8),char_loc_y(8));
	erase_char(8);
	force_instant_terrain_redraw();
	award_party_xp(200,95);
	
	pause(get_flag(290,0) * 3);
	
	message_dialog("Everyone stands, motionless. There is no direction. Without Legare, what purpose is there? It was his vision, his desire, that was driving everything.","Then, slowly, solemnly, she speaks.");
	
	text_bubble_on_char(9,"I have been running for too long.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(9,"");
	text_bubble_on_char(9,"It is time for me to face my...");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(9,"");
	text_bubble_on_char(9,"my...");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(9,"");
	text_bubble_on_char(9,"my demons.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(9,"");
	force_instant_terrain_redraw();
	
	message_dialog("Seizing hold of you and Pithoss, the Goddess unleashes a bolt of magical energy shooting straight up into the sky. Then, in familiar fashion, you lift off the ground and begin to travel through the air, returning again to camp.","You travel the entire distance in silent contemplation, not even looking down well enough to see more than blank cave floor.");
	
	set_flag(44,7,1);
	
	i = 21;
	while (i < 31) {
		j = 17;
		while (j < 21) {
			set_floor(i,j,255);
			set_terrain(i,j,0);
			j = j + 1;
			}
		i = i + 1;
		}
	i = 10;
	while (i < 120) {
		erase_char(i);
		i = i + 1;
		}
	
	march_party(25,29);
	march_party(26,29);
	march_party(27,29);
	march_party(28,29);
	relocate_character(9,30,29);
	set_character_facing(9,6);
	force_view_center(28,29);
	force_instant_terrain_redraw();
	
break;

beginstate 21;
	move_to_new_town(29,29,7);
break;

beginstate 22;
	if (get_flag(44,8) == 0) {
		set_flag(44,8,1);
		message_dialog("In here are the cells in which prisoners are kept, but Ethass is not here. One of the cells bears her name on a plaque inside, but she is not in it.","");
		}
break;

beginstate 23;
	if (get_flag(44,9) == 0) {
		set_flag(44,9,1);
		message_dialog("This must be the personal library of the lord of the city. Surely there is something interesting in here, if only you can find it.","");
		}
break;

beginstate 24;
	reset_dialog();
	add_dialog_str(0,"There are some stairs here.",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Descend.");
	if (run_dialog(1) == 2)
		move_to_new_town(43,21,33);
	else
		block_entry(1);
break;

beginstate 25;
	message_dialog("This door is VERY solidly locked. It is not likely that you will be able to get it open.","");
break;