// Town 19: Mount Galthrax (L1)
begintownscript;

variables;

short choice,dummy,i,j,which_flag,golem_type,hold_loc_x,hold_loc_y;
string dlgstr;

body;

beginstate INIT_STATE;
turn_off_training(1);
set_name(6,"Dargenloth");
set_name(27,"Strange Skeleton");
set_name(24,"Strange Ghast");
set_name(25,"Strange Ghast");
set_level(27,60);
set_level(24,55);
set_level(25,55);

char_give_item(19,467); // Shield of Witness

change_blocked(1,13,1);
change_blocked(1,14,1);
change_blocked(1,15,1);
change_blocked(2,13,1);
change_blocked(2,14,1);
change_blocked(2,15,1);

change_blocked(41,14,1);
change_blocked(42,14,1);
change_blocked(41,15,1);
change_blocked(42,15,1);

if (get_flag(19,11))
	erase_char(12);

if (get_flag(19,0) != 0)
	{force_instant_terrain_redraw();
	message_dialog("You climb up the ladder from the Demon Golem's room. You ascend only a short distance before you arrive at a trapdoor that leads to a new room.","It appears that the Demon Golem had a secret, private entrance into the mountain. You are now using that entrance.");
	set_flag(19,0,1);
	}
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
if (get_flag(19,16) == 0) // hasn't gotten gauntlets
	if (get_flag(19,13) > 0) // has killed Dargenloth
		if (get_flag(20,4) > 0) // has freed the lich
			if (is_combat() == 0) {
				message_dialog("You hear the distant voice of the lich that you freed whisper, _Thank you. Now I have had my vengeance._","You feel an item suddenly in your possession.");
				dummy = reward_give(462);
				set_flag(19,16,1);
				}
break;

beginstate 10;
if ((get_flag(250,5) == 1) && (has_item(451) == 0))
	{message_dialog("You can't just leave Phaedra behind. You must take her with you to the guardpost immediately or she will die.","");
	block_entry(1);
	end();
	}

	reset_dialog();
	add_dialog_str(0,"There is a ladder here. Do you climb down it?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Climb down it.");
	if (run_dialog(1) == 1)
		block_entry(1);
	else
		move_to_new_town(18,6,1);
break;

beginstate 11;
if (get_flag(250,5) == 1) // Phaedra dead
	{add_dialog_str(0,"There is a ladder here. However, you can't go this way: Phaedra needs you to bring her back to the guardpost.",0);
	dummy = run_dialog(1);
	block_entry(1);
	end();
	}

	reset_dialog();
	add_dialog_str(0,"There is a ladder here. Do you climb down it?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Climb down it.");
	if (run_dialog(1) == 1)
		block_entry(1);
	else
		move_to_new_town(20,5,40);
break;

beginstate 12;
if (get_flag(19,1) == 0)
	{i = 0;
	while (char_ok(i) == 0)
		{i = i + 1; }
	if (char_loc_x(i) >= 5)
		block_entry(1);
	else
		{message_dialog("You see a small secret passage in this wall that is only visible from this side. Even if you had searched the wall very carefully, you would not have been able to see it from the other side.","Now that you know where it is, though, you will be able to find it again.");
		set_flag(19,1,1);
		}
	}
break;

beginstate 13;
if (get_flag(19,3) == 0)
	{reset_dialog();
	add_dialog_str(0,"As you enter the next room, you see the remains of two demonic altars. It appears that they were destroyed recently. The trapdoor in the northwest looks sloppily arranged, too.",0);
	if (get_flag(18,17) == 1)
		add_dialog_str(1,"Presumably Ithik came this way before you.",0);
	else
		add_dialog_str(1,"Some other intruder has clearly come this way before you.",0);
	set_flag(19,3,run_dialog(1));
	}
break;

beginstate 14;
if (get_flag(19,2) != 0)
	end();
	
	set_flag(19,2,1);
	message_dialog("You step into this new room ready to fight more undead, but instead you find something rather different. In front of you is what appears to be a scale model of the entire region of Bahssikava!","It looks quite accurate, too, although it seems to be missing the effects of your recent exploits. Interestingly enough, it also appears to include areas that you never visited, including the far west of Bahssikava.");
break;

beginstate 15;
if (get_flag(19,4) != 0)
	end();
	
	reset_dialog();
	add_dialog_str(0,"Interesting. North of the cave that appears to represent where you are, there is a walled city.",0);
	if (get_flag(15,22))
		add_dialog_str(1,"That must be Vasskolis!",0);
	set_flag(19,4,run_dialog(1));
break;

beginstate 16;
if (get_flag(19,5) != 0)
	end();
	
	set_flag(19,5,1);
	message_dialog("There are steps right here, apparently for you to walk down and actually look at the map up close. The steps lead you into the northern-most part of Ancient Bahssikava, just west of the guardpost.","From this vantage point, you can see just how close the Bahssikavans were to the homeland. If they had focused their energies on breaking down the east wall of Bahssikava rather than the huge steel doors, they just might have made it back.");
break;

beginstate 17;
	reset_dialog();
	add_dialog_str(0,"The ground slopes sharply down here. Do you climb down it?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Climb down it.");
	if (run_dialog(1) == 1)
		block_entry(1);
	else
		move_to_new_town(20,1,22);
break;

beginstate 18;
if (get_flag(19,6) != 0)
	end();
	
	set_flag(19,6,1);
	reset_dialog();
	if (get_flag(15,22))
		add_dialog_str(0,"You walk into this room, and to your surprise, you find Ithik! He has been a few steps ahead of you ever since you left Bahssikava, and now you have caught up to him. If he's been exploring these caves, he may have some useful information for you.",0);
	if (get_flag(250,6))
		add_dialog_str(0,"You walk into this room, and to your surprise, you find Ithik! He has apparently recovered from his wounds almost completely, and he got here before you did. If he's been exploring these caves, he may have some useful information for you.",0);
	if ((get_flag(15,22) == 0) && (get_flag(250,6) == 0))
		{if (get_flag(14,15))
			add_dialog_str(0,"You walk into this room, and to your surprise, you find the slith you found trapped in Western Bahssikava, Ithik! He apparently escaped, and he got here before you did. If he's been exploring these caves, he may have some useful information for you.",0);
		else
			{if (get_flag(15,21))
				add_dialog_str(0,"You walk into this room, and to your surprise, you find a living slith! He looks like the same one that stood next to Voss underneath Khar-Grav when you got your reward. If he's been exploring these caves, he may have some useful information for you.",0);
			else
				add_dialog_str(0,"You walk into this room, and to your surprise, you find a living slith! You don't know where he came from, but if he's been exploring these caves, he may have some useful information for you.",0);
			if (get_flag(250,2) >= 2)
				add_dialog_str(2,"_Come, let us talk,_ he says in the ancient Bahssikavan tongue that you have partly learned. _My name is Ithik. I want to help you._",0);
			}
		}
	add_dialog_str(1,"He appears to wish to speak to you, too, judging from his expression as you enter the room.",0);
	if (get_flag(250,2) < 2)
		{add_dialog_str(2,"However, the moment he opens his mouth and begins speaking, you realize that you can't understand his language. You try to reply, but it is clear that you cannot communicate. Frustrated, he leaves.",0);
		erase_char(12);
		set_flag(19,14,1);
		}
	set_flag(19,6,run_dialog(1));
break;

beginstate 19;
if (get_flag(19,7) != 0)
	end();
	
	set_flag(19,7,1);
	message_dialog("Suddenly, you step out onto a cliff.","From this opening in the cave wall, you can probably see a very long distance out to the north if you get closer to the edge.");
break;

beginstate 20;
if (get_flag(19,8) != 0)
	{message_dialog("You return to the cliff's edge to gaze at the slith city in the distance. You must find a way to it, somehow.","");
	end();
	}
	
	reset_dialog();
	add_dialog_str(0,"The view from the edge is almost a religious experience. From here, you can see to the north quite some distance. There is a brief section of barren land, and beyond that, you can see a city!",0);
	if (get_flag(15,22))
		add_dialog_str(1,"That must be Vasskolis in the distance! That's the city that Ithik is from, and others like him must be there. Legare would be very interested to find this place, you are sure.",0);
	else
		{if (get_flag(19,4))
			add_dialog_str(1,"That must be the same city that you saw on the map! You can see the same details on it that you saw on the scale model. More importantly, you can see humanoid beings at its walls! They look like sliths! You've found a city of sliths!",0);
		else
			add_dialog_str(1,"It's a city north of the mountains. And more importantly, you can see humanoid beings at its walls! They look like sliths! You've found a city of sliths!",0);
		}
	add_dialog_str(2,"It is a city of living sliths in the homeland, so it must certainly be the object of your quest. All you need to do now is get to it.",0);
	set_flag(19,8,run_dialog(1));
break;

beginstate 21;
if (get_flag(19,9) != 0)
	end();
	
	set_flag(19,9,1);
	message_dialog("There is a very large nest here. Judging by the scales nearby, a dragon comes up here to sit from time to time. You can almost see the beast sitting and staring at the slith city, contemplating ways to attack it.","");
break;

beginstate 22;
	reset_dialog();
	add_dialog_str(0,"You have reached some stairs. Do you descend them?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Descend.");
	if (run_dialog(1) == 1)
		block_entry(1);
	else
		move_to_new_town(20,40,18);
break;

beginstate 23;
	reset_dialog();
	add_dialog_str(0,"You find an open book on this pedestal. It appears to be notes on the experiments on undead that were conducted in this area. You read some of it.",0);
	add_dialog_str(1,"_Dousing the vampires in acid has produced some with acid touch abilities. I have yet to try this on other undead types, as we lost half of the vampires in the experiment, and the screaming frightened the golems.",0);
	add_dialog_str(2,"_I was unaware that the blasted things had emotions, but apparently they do. The golems were unable to work for hours afterwards. I must look into numbing their feelings mechanically by whatever means possible.",0);
	add_dialog_str(3,"_Perhaps conditioning. If we forced them to listen to the screams of vampires for an hour every day, they would become accustomed to the sound. I must think on this more._",0);
	if (get_flag(19,13))
		add_dialog_str(4,"The entry is signed, _Dargenloth._ This undead lord was clearly a terrible monster.",0);
	else
		add_dialog_str(4,"The entry is signed, _Dargenloth._ This undead lord is clearly a terrible monster.",0);
	dummy = run_dialog(1);
break;

beginstate 24;
// Golem freeing state for this town
if (get_flag(current_town(),which_flag))
	{message_dialog("You've already done all that you can do here. You leave the control panel alone.","");
	end();
	}

	reset_dialog();
	add_dialog_str(0,"You come to a control panel for this strange device.",0);
	if (has_special_item(7) > 0)
		add_dialog_str(1,"You remember the instructions page that you found and pull it out. It seems to describe how to do something with this control panel.",0);
	add_dialog_str(2,"What do you do?",0);
	add_dialog_choice(0,"Leave.");
	if (has_special_item(7) > 0)
		add_dialog_choice(1,"Use the controls, following the instructions on the page.");
	else
		add_dialog_choice(1,"Fiddle with the controls blindly.");
	if (run_dialog(1) == 1)
		end();
		
	if (has_special_item(7) == 0)
		{message_dialog("You press some buttons here and there, but nothing happens.","");
		end();
		}
		
	message_dialog("You follow the instructions and press numerous buttons in a particular order. Nothing seems to happen at first, but then the machine activates!","");
	
	set_flag(current_town(),which_flag,1); // freed this golem
	
	set_terrain(hold_loc_x,hold_loc_y,138);
	put_boom_on_space(hold_loc_x,hold_loc_y,6,0);
	run_animation_sound(53);
		
	if (get_flag(250,7) == 1)
		message_dialog("You free this golem and give him the same lame story about not being here to help the dragon. Disappointed, he vanishes.","");
	
	if (get_flag(250,7) == 2)
		message_dialog("You free this golem and tell him the same thing that you told the first golem that you freed. You ask if he will help you fight the dragon. He assents quite willingly.","You have gained the aid of an ice golem.");
	
	if (get_flag(250,7) > 0)
		end();
	
	place_monster(hold_loc_x,hold_loc_y,golem_type,2);
	j = 120;
	while (char_ok(j) == 0)
		{j = j - 1; }
		
	run_scenario_script(15);

break;

beginstate 25;
	// Set the variables for the golem freeing state
	which_flag = 15;
	golem_type = 218; // Ice Golem
	hold_loc_x = 26; // location of the holding cell
	hold_loc_y = 41;

	set_state_continue(24);
break;

beginstate 26;
if (has_special_item(8))
	end();

	reset_dialog();
	add_dialog_str(0,"To your amazement, you find a rare magical item here, a Phoenix Egg! This mighty artifact will create quickfire when used.",0);
	add_dialog_str(1,"What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Take it.");
	if (run_dialog(1) == 1)
		end();
	
	change_spec_item(8,1);
	message_dialog("You take the Phoenix Egg, handling it carefully. When used, the quickfire it creates will destroy everything in the immediate vicinity.","(When an appropriate time to use it comes, you will be given the option.)");
break;