// Town 18: North River
begintownscript;

variables;

short choice,dummy,i;
string dlgstr;

body;

beginstate INIT_STATE;
if (get_flag(18,0) == 0)
	{force_instant_terrain_redraw();
	reset_dialog();
	add_dialog_str(0,"You start up the river, expecting to travel a reasonable distance before setting to land. Instead, after rowing for a short distance, you come to a waterfall. You certainly can't go any farther by water.",0);
	if ((character_in_party(906)) || (character_in_party(921)))
		{add_dialog_str(1,"You glance at Phaedra. _What did you find when you came up this way?_ you ask.",0);
		add_dialog_str(2,"She blushes faintly. _I... I didn't actually explore very much. I found a mountain, and I made my way up a path somewhere around here. There were some machines, golems I think, that were patrolling, so I had to stay out of sight._",0);
		add_dialog_str(3,"_Anyway, I snuck up to the top of the mountain and looked over the other side. There was a town! I'm pretty sure I saw sliths there. That's where we're trying to go now: Legare wants us to clear a path to that town._",0);
		add_dialog_str(4,"_But there's a small problem. When I was coming back down the mountain, the ground gave way underneath me. I'm pretty sure that the path that I took is impassable now. We're going to have to find a different way._",0);
		}
	else
		{add_dialog_str(1,"You look around. A mountain looms above you to the north, and it is crawling with what appear to be golems, a particularly unfriendly type of intelligent machine.",0);
		add_dialog_str(2,"Phaedra probably would be pretty helpful here, because she scouted the area out before. You remember that Legare mentioned that you should get her before you headed out this way. You can still go back and do that.",0);
		}
	clear_buffer();
	append_string("Suddenly you hear a loud roar from far up atop the mountain. You look up, and you see an enormous dragon straddling the entire peak. It doesn't seem to have noticed you; it's just roaring in general.");
	if ((character_in_party(906)) || (character_in_party(921)))
		append_string("_Oh yes,_ Phaedra says, _and there was a dragon._");
	get_buffer_text(dlgstr);
	add_dialog_str(5,dlgstr,0);
	set_flag(18,0,run_dialog(1));
	large_draw_pic_dialog(553,"The dragon on the mountain!");
	}
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;
if ((get_flag(250,5) == 1) && (has_item(451) == 0))
	{message_dialog("You have reached the boat to take you south down the river back to the guardpost. However, 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,"You have reached the boat to take you south down the river back to the guardpost. Do you wish to board it and travel south?",0); 
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Board and head south.");
	if (run_dialog(1) == 2)
		{play_sound(85);
		move_to_new_town(9,45,7);
		}
break;

beginstate 11;
if (get_flag(18,1) != 0)
	end();
	
	set_flag(18,1,1);
	message_dialog("As you begin to climb this mountain, you can see that the footing becomes very uneven in places. Narrow ledges criss-cross east and west, and you will have to wander across many switchbacks in order to proceed farther.","This seems strange as a natural formation, but you can only speculate about how or why anyone would have built it.");
break;

beginstate 12;
if (get_flag(18,2) != 0)
	end();
	
	set_flag(18,2,1);
	message_dialog("The moment you step into this room, you can feel heat almost suffocating in intensity. This room is hotter than the fires of the demon realms, or so it is tempting to imagine. Fortunately, you are strong enough for the heat not to hurt you.","");
break;

beginstate 13;
	message_dialog("There are fragments of unknown rocks and metals here. Evidently this room is used for forging something. That explains the damnable heat, at any rate.","");
break;

beginstate 14;
if (get_flag(18,3) != 0)
	end();
	
	set_flag(18,3,1);
	message_dialog("This room is a mess. Golem parts, goop, and even blood are all over the floor, and two tables on either side of the room are filled with small broken golem pieces and one or two larger broken golem body parts.","This room appears to be the place where many of the golems are either assembled or repaired.");
break;

beginstate 15;
	message_dialog("You come to some sort of arcane control panel. It makes no sense to you, and you wisely choose to leave it alone.","");
break;

beginstate 16;
	print_str("This golem is not active yet.");
	print_str("It must not be finished.");
break;

beginstate 17;
if (get_flag(18,5) != 0)
	end();
	
	set_flag(18,5,1);
	message_dialog("Several golems, still not active, are held here inside force fields. Evidently this is the finishing room, where the creators activate their creations, and the golems become alive.","The one in charge of this process appears to be the skeleton by the table.");
break;

beginstate 18;
if (get_flag(18,4) != 0)
	end();
	
	set_flag(18,4,1);
	message_dialog("This appears to be the room in which the golems are constructed. Strange undead creatures stand at four different stations, each one creating a different kind of golem. The golems are not yet active; they must not be finished.","As you peer in, the four emerald skeletons look up from their work and see you. They do not look friendly.");
break;

beginstate 19;
if (get_flag(18,6) != 0)
	end();
	
	set_flag(18,6,1);
	message_dialog("As you step onto this ledge, you see another host of golems ready to attack you. However, you notice that the blade golems look a little strange. You can't quite put your finger on what's wrong, but they definitely look peculiar somehow.","");
break;

beginstate 20;
if (get_flag(18,7) != 0)
	end();
	
	set_flag(18,7,1);
	message_dialog("This appears to be a meeting room. Fortunately, it is empty right now. There are papers strewn about the table, though; they may be useful in some way.","");
break;

beginstate 21;
if (get_flag(18,9) != 0)
	end();
	
	set_flag(18,9,1);
	message_dialog("At some point in time, there may have been a passage here. Since that time, there has been a cave-in. The rubble here is so old that you can't even venture a guess at its age.","");
break;

beginstate 22;
	reset_dialog_preset_options(8);
	if (run_dialog(1) == 2)
		{play_sound(99);
		flip_terrain(2,34);
		flip_terrain(3,34);
		flip_terrain(4,34);
		}
break;

beginstate 23;
if (get_flag(18,10) != 0)
	end();
	
	set_flag(18,10,1);
	message_dialog("The moment you open this door, hot air billows out into your face. Six bonfires blaze in the middle of the room, and several golems, mainly fire golems, stand near the warmth.","");
break;

beginstate 24;
if (get_flag(18,11) != 0)
	end();
	
	set_flag(18,11,1);
	message_dialog("This room has another set of gates, and it has tall, intricate statues and two foul-looking altars. Ornate details cover the walls; the floor is smoother and decorate; and the northeast corner has chiseled, cutting, unmarked stairs.","Given the elaborate security protections at work and the beauty of the architecture and decorating here, you may be getting closer to something (or someone) important.");
break;

beginstate 25;
if (get_flag(18,12) != 0)
	end();
	
	set_flag(18,12,1);
	message_dialog("This door doesn't seem to lead anywhere but to a completely non-descript cave wall. How odd.","");
break;

beginstate 26;
	message_dialog("You push on these doors, but they don't budge. You can see an obvious lock, but despite your best efforts, you can't seem to have any effect on it. You may have some trouble getting through here.","");
break;

beginstate 27;
if (get_flag(18,13) != 0)
	end();
	
	set_flag(18,13,1);
	message_dialog("On the other side of this door, you can hear a gruff voice barking orders in a strange, guttural language. You can't understand what it's saying, but its tone is quite clear: it is angry, and someone is going to get hurt.","Listening closely, you notice that despite the voice's harsh quality, it sounds almost mechanical, too. Something very strange is on the other side of this door.");
break;

beginstate 28;
if (get_flag(18,14) != 0)
	end();
	
	set_flag(18,14,1);
	message_dialog("Non-descript cave wall. Sure. When you were on your first adventure, you might've had some chance of missing this secret passage, but not by now. You slip through easily.","");
break;

beginstate 29;
	message_dialog("You step gingerly around the messy corpse of a golem. Its head lies several fingers' widths too far away from its shoulders, and its chest is hacked, as with an ax.","Truly, the demon golem was not gentle with this one of its servants.");
break;

beginstate 30;
	message_dialog("This pool of foul liquid appears to have leaked out from the nearby corpse of a golem. You stay carefully away from it, as it appears to be corrosive and extremely acidic.","");
break;

beginstate 31;
if (get_flag(18,16) != 0)
	end();
	
	set_flag(18,16,1);
	message_dialog("This appears to have been the Demon Golem's office. Looking closely, you notice that someone has been through here recently. The room is almost completely organized, but certain areas are shuffled and clearly have been searched.","");
break;

beginstate 32;
	message_dialog("You search through the bookshelves, but you find nothing interesting. This isn't too surprising, as someone has been over these shelves before you.","");
break;

beginstate 33;
if (get_flag(250,5) == 1) // Phaedra dead
	{add_dialog_str(0,"There is a ladder here. However, you can't climb it: 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 it?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Climb it.");
	if (run_dialog(1) == 1)
		block_entry(1);
	else
		move_to_new_town(19,6,60);
break;

beginstate 34;
	if (get_flag(15,22) == 0)
		message_dialog("You rummage through this desk. You find very little of interest. It appears that the Demon Golem didn't use it very often, although it is clear that someone has rummaged through it recently.","");
	else
		{reset_dialog();
		add_dialog_str(0,"You rummage through this desk. It appears that the Demon Golem didn't use it very often, although it is clear that someone has rummaged through it recently. Knowing this, you look closer, and you find a note. It's from Ithik, and it's addressed to you!",0);
		add_dialog_str(1,"It explains that he passed through here not long ago, and he left you this note knowing that you would come this way, having nowhere else to go. He knew this desk would be safe, because the Demon Golem never used it.",0);
		add_dialog_str(2,"He got to this room through a secret passage in the southwest corner of this room. It leads near _the ruined guardpost of years past._ That must be the one where Legare's folk are camped! You could probably use this to get back in a hurry if you needed.",0);
		add_dialog_str(3,"He finishes by saying that he'll be waiting for you somewhere in the mountain beyond here, trying to find a way past the dragon and his undead minions. If you manage to find him, he'll be able to help you!",0);
		if (get_flag(18,8))
			add_dialog_str(4,"Dragon? Undead minions? That doesn't sound good. You may have even more struggles ahead of you before you can reach Vasskolis.",0);
		else
			add_dialog_str(4,"Dragon? Undead minions? That doesn't sound good. You may have even more struggles ahead of you before you're done here.",0);
		set_flag(18,17,run_dialog(1));
		}
break;

beginstate 35;
	message_dialog("This wheel is too heavy for you to move. You can't open these gates this way.","");
break;

beginstate 36;
	reset_dialog();
	add_dialog_str(0,"You find a small secret passage. What do you do?",0);
	add_dialog_choice(0,"Leave.");
	if (get_flag(18,18) == 0)
		add_dialog_choice(1,"Enter it and see where it leads.");
	else
		add_dialog_choice(1,"Enter it and rest again.");
	if (run_dialog(1) == 1)
		block_entry(1);
	else
		{if (get_flag(18,18) == 0)
			{if (get_flag(18,17) != 0)
				message_dialog("You travel down the passage for a while, expecting it to lead you back to the guardpost, but instead it leads you to a wall of dirt. Evidently this passage caved in after Ithik went through it.","Since this place seems very well protected, you take the moment to rest here, though. You could probably come back here whenver you like.");
			else
				message_dialog("You travel down the passage for a while. Eventually it leads you to a wall of dirt. This passage shows signs of having caved in recently.","Since this place seems very well protected, you take the moment to rest here, though. You could probably come back here whenver you like.");
			set_flag(18,18,1);
			}
		else
			message_dialog("You return to your quiet resting place and rest undisturbed for a long while.","");
		revive_party();
		set_ticks_forward(5000);
		}
break;

beginstate 37;
if (get_flag(18,19) != 0)
	end();
	
	set_flag(18,19,1);
	message_dialog("This room is filled with all the pieces necessary to make golems. It doesn't seem to be organized in any particular manner or even kept clean at all. How strange that machines would be so messy.",""); 
break;