// Town 57: Danatha
begintownscript;

variables;

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

body;

beginstate INIT_STATE;
	set_crime_tolerance(2);
	
	set_name(9,"Pithoss"); // type 112
	set_name(10,"Kass"); // type 36
	set_name(12,"Machrone"); // type 78
	set_char_dialogue_pic(15,585,0); // Phaedra
	set_name(19,"Ethass"); // type 111
	set_name(11,"Talas"); // type 112
	set_name(13,"Ithik"); // type 112
	set_name(14,"Silthokh"); // type 111
	set_name(16,"Britha"); // type 113
	
	march_party(31,3);
	march_party(32,3);
	march_party(32,4);
	march_party(32,5);
	march_party(32,6);
	force_view_center(32,6);
	
	put_object_on_space(32,7,3);
	put_object_on_space(32,8,3);
	put_object_on_space(32,9,3);
	
	force_instant_terrain_redraw();
	message_dialog("You enter Danatha, dwarfed by the massive walls and towering statues. The only entrance through the walls from this side is blocked by enormous magical barriers, virtually impenetrable without the most powerful magic.","At the direction of Britha, who stands on the other side, the barriers are lowered, and you are allowed in.");

	set_character_pose(17,2);
	set_character_pose(18,2);
	put_object_on_space(32,7,-1);
	put_object_on_space(32,8,-1);
	put_object_on_space(32,9,-1);
	put_boom_on_space(32,7,3,0);
	put_boom_on_space(32,8,3,0);
	put_boom_on_space(32,9,3,0);
	run_animation_sound(28);
	
	set_character_pose(17,0);
	set_character_pose(18,0);
	force_instant_terrain_redraw();
	
	set_character_facing(17,4);
	set_character_facing(18,4);
	relocate_character(17,31,14);
	relocate_character(18,33,14);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(17,31,15);
	relocate_character(18,33,15);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(17,31,16);
	relocate_character(18,33,16);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	erase_char(17);
	erase_char(18);
	text_bubble_on_char(16,"Come!");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(32,7);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(32,8);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(32,9);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(32,10);
	set_character_facing(16,4);
	text_bubble_on_char(16,"");
	text_bubble_on_char(16,"Follow me!");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(32,11);
	relocate_character(16,32,13);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(32,12);
	relocate_character(16,32,14);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(32,13);
	relocate_character(16,32,15);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(32,14);
	relocate_character(16,32,16);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	text_bubble_on_char(16,"");
	force_instant_terrain_redraw();
	
	reset_dialog();
	clear_buffer();
	append_string("Britha briskly leads you through Danatha. ");
	if (species_in_party(3) == 1) // has sliths
		append_string("Onlookers gawk at you, for they have not seen friendly sliths from the north in many years. ");
	if ((species_in_party(0) == 1) || (species_in_party(2) == 1)) {
		if (species_in_party(3) == 1)
			append_string("They also ");
		else
			append_string("Onlookers ");
		append_string("gawk at you because they have never seen ");
		if (species_in_party(0) == 1)
			append_string("humans ");
		else
			append_string("nephils ");
		append_string("before");
		if ((species_in_party(0) == 1) && (species_in_party(2) == 1))
			append_string(", and nephils look odd to them, too.");
		else
			append_string(".");
		}
	get_buffer_text(dlgstr);
	add_dialog_str(0,dlgstr,0);
	add_dialog_str(1,"Danatha is not unlike Vasskolis or Thassaka or Manikoss, except that those cities have been destroyed or drained of life and culture, while this city remains connected to the veins of civilization that run through Khitaloss.",0);
	add_dialog_str(2,"You can see the wear on the walls and the holes in the roads, the strewn stones and the tension in the faces of people living with the notion that each day might bring the barbarian attack that will end this town, but you also see strength and vitality.",0);
	add_dialog_str(3,"After not long, you arrive in the city lord's throne room.",0);
	run_dialog(1);
	
	march_party(32,36);
	march_party(32,35);
	march_party(32,34);
	march_party(32,33);
	march_party(32,32);
	force_view_center(32,32);
	relocate_character(16,32,31);
	set_character_facing(16,0);
	force_instant_terrain_redraw();
	
	text_bubble_on_char(16,"My lord,");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(16,"");
	text_bubble_on_char(16,"They come from Avernum.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(16,"");
	text_bubble_on_char(6,"Avernum?");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(6,"");
	force_instant_terrain_redraw();
	
	message_dialog("You have a sudden feeling of deja vu. Britha and the lord of Danatha have almost the same conversation as Ithik and the lord of Vasskolis did at the end of your journey through Bahssikava. Britha explains where Avernum is and how you have come here.","But this time, something is different.");
	
	text_bubble_on_char(6,"The exiles?");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(6,"");
	text_bubble_on_char(6,"The children of Thsss have returned?");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(6,"");
	force_instant_terrain_redraw();
	
	message_dialog("The lord of Danatha considers this for a long moment. He looks in turns horrified and grim. Finally, he speaks one word: _No._","At that one monosyllable, Britha steps back, aghast.");
	
	text_bubble_on_char(16,"What do you mean, 'No'?");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(16,"");
	text_bubble_on_char(6,"I mean NO.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(6,"");
	text_bubble_on_char(6,"The exiles cannot return.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(6,"");
	text_bubble_on_char(6,"Now we face difficult times,");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(6,"");
	text_bubble_on_char(6,"and we cannot take in refugees.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(6,"");
	force_instant_terrain_redraw();
	
	message_dialog("Britha begins to speak again, but before she can even finish a single word, she is cut off, reminded by an advisor that the lord's word is final.","She relents, backing away.");
	
	march_party(32,3);
	march_party(32,4);
	march_party(32,5);
	march_party(32,6);
	relocate_character(16,33,5);
	put_object_on_space(32,7,3);
	put_object_on_space(32,8,3);
	put_object_on_space(32,9,3);
	force_view_center(32,6);
	force_instant_terrain_redraw();
	
	reset_dialog();
	add_dialog_str(0,"She leads you away from the throne room, and guards escort you back to the bridge out of Danatha. She does not speak a word until the guards are out of earshot.",0);
	add_dialog_str(1,"_That insufferable bastard!_ she hisses. _He knows that you are not refugees. He knows that he lies: Danatha would suffer no harm from receiving you. He fears any change, though, and the return of Thsss's offspring would be a change._",0);
	add_dialog_str(2,"As she speaks, Kass, Pithoss, and the rest of the expedition appear in sight, coming down the hill towards the city. Britha tells them what the lord of the city has said, and Kass and Pithoss whisper to each other hurriedly.",0);
	add_dialog_str(3,"Meanwhile, the others, Machrone, Phaedra, Ethass, Talas, Silthokh, and Ithik, ask you what the city looked like. You do your best to tell them, knowing that the story will spread throughout the rest of the expedition, waiting farther away, soon enough.",0);
	add_dialog_str(4,"Eventually, the leaders reach a conclusion, and Pithoss begins speaking.",0);
	run_dialog(1);
	
	activate_hidden_group(1);
	
	set_character_facing(0,0);
	set_character_facing(1,0);
	set_character_facing(2,0);
	set_character_facing(3,0);
	
	text_bubble_on_char(9,"You have done well,");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(9,"");
	text_bubble_on_char(9,"but now we have reached an impasse.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(9,"");
	text_bubble_on_char(9,"I fear this obstacle will block us");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(9,"");
	text_bubble_on_char(9,"for some time.");
	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,"_As Legare said in the Land of the Dead,_ he continues, _once we have come to the homeland, some of us will return again to our true homes in Avernum. It is time, I think, for many of us to return home._",0);
	add_dialog_str(1,"He looks at you directly. _And they will need protection against the dangers of the road. Perhaps, if you wish, you will accompany them._",0);
	add_dialog_str(2,"He turns to Kass, who begins speaking.",0);
	run_dialog(1);
	
	text_bubble_on_char(10,"And some of us will stay here");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(10,"");
	text_bubble_on_char(10,"to convince this lord");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(10,"");
	text_bubble_on_char(10,"to let us enter Khitaloss.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(10,"");
	force_instant_terrain_redraw();
	
	message_dialog("He, too, looks directly at you. _I do not know how or with what arguments we might do this, but I am certain that when we do finally convince him, we will still have need of armed might as we travel through this war-torn land._","He adds, _It is up to you what you will do._");
	
	text_bubble_on_char(9,"Whatever your choice, though,");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(9,"");
	text_bubble_on_char(9,"the journey is not over,");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(9,"");
	text_bubble_on_char(9,"but it has reached a pause.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(9,"");
	force_instant_terrain_redraw();
	
	message_dialog("Pithoss's expression changes unreadably. It is as though he has had a strange thought.","");
	
	text_bubble_on_char(9,"Let us give thanks, then,");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(9,"");
	text_bubble_on_char(9,"to the GODDESS.");
	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,"Pithoss begins speaking the words of prayer, and you realize that he is right. You have reached the civilization in the middle of the slith homeland, the living, breathing empire from which the Avernite sliths were expelled long ago. You have come to it.",0);
	add_dialog_str(1,"However, Khitaloss is not at peace. Barbarian invasions and civil war wrack the land, as Britha details to the expedition not long after this. The emperor is weak and terribly corrupt, and each local lord is frightened for his own power.",0);
	add_dialog_str(2,"Worship of the old gods, too, has vanished, replaced with a new cult of a single god, one unknown to the ancients, and this has created tension as well.",0);
	add_dialog_str(3,"And the one great evil committed by Hathnazriakh remains not undone: the vahnatai still sleep in their crystal pillars, guarded by the sliths who no longer remember what they are.",0);
	add_dialog_str(4,"Someday, perhaps, these wrongs may be righted, but, now, other things await. You may either stay here with the expedition, attempting to change the lord's mind, or return to Avernum.",0);
	add_dialog_str(5,"Whatever you do, you will always remember the Exodus and the sacrifice of the Prophet of the Goddess, Legare.",0);
	run_dialog(1);
	
	message_dialog("THE END.","");
	
	j = 0;
	i = 1;
	while (i <= 18) {
		j = j + get_flag(292,i);
		i = i + 1;
		}
	i = 1;
	while (i <= 5) {
		j = j + get_flag(293,i);
		i = i + 1;
		}
	if (j == 59)
		message_dialog("Congratulations! You have found every special spell in the scenario! If you did this legitimately (no cheating, no character editor, no reading it in the scripts), e-mail Kelandon at tomwatts (at) berkeley (dot) edu to tell him. There's a small reward.","Please be honest about whether you did in fact accomplish this in the scenario. I have no way of checking, so you're on your honor. And again, congratulations!");
	// Yeah, and reading it in the scripts doesn't count.
	if (j > 59)
		message_dialog("If you see this message and did not use the character editor, please inform Kelandon at tomwatts (at) berkeley (dot) edu.","");
	
	end_scenario(1);
	
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;
break;