// Town 9: Camp (2)
begintownscript;

variables;

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

body;

beginstate INIT_STATE;
	set_crime_tolerance(2);
	
	change_blocked(41,14,1);
	change_blocked(41,15,1);
	change_blocked(41,16,1);
	change_blocked(41,17,1);
	change_blocked(41,18,1);
	change_blocked(40,18,1);
	change_blocked(39,18,1);
	change_blocked(38,18,1);
	change_blocked(37,18,1);
	change_blocked(36,18,1);
	change_blocked(36,17,1);
	change_blocked(36,16,1);
	change_blocked(36,15,1);
	change_blocked(36,14,1);
	
	change_blocked(21,38,1);
	change_blocked(22,38,1);
	change_blocked(23,38,1);
	change_blocked(24,38,1);
	change_blocked(25,38,1);
	change_blocked(26,38,1);
	change_blocked(27,38,1);
	change_blocked(28,38,1);
	change_blocked(29,38,1);
	change_blocked(29,39,1);
	change_blocked(29,40,1);
	change_blocked(29,41,1);
	change_blocked(29,42,1);
	change_blocked(29,43,1);
	change_blocked(29,44,1);
	
	set_name(6,"Ethass");
	set_char_dialogue_pic(6,584,0);
	set_char_dialogue_pic(7,585,0); // Phaedra
	set_name(8,"Talas");
	set_char_dialogue_pic(8,582,0);
	set_name(9,"Ithik");
	set_level(9,60);
	set_name(10,"Machrone");
	set_name(11,"Silthokh");
	set_name(12,"Pithoss");
	set_char_dialogue_pic(12,580,0);
	set_name(13,"Legare");
	set_name(14,"Kass");
	set_char_dialogue_pic(14,583,0);
	
	if (get_flag(290,7))
		make_town_hostile();
	
if (get_flag(9,0) == 0) {
	force_instant_terrain_redraw();
	reset_dialog();
	add_dialog_str(0,"You return to camp, finally, with the knowledge that you have cleared the path for a substantial distance ahead. You notice that the light here is dark: the glowing fungus that lights the area must have a natural cycle that is at its dim point.",0);
	add_dialog_str(1,"You also notice that the entire camp has broken down the tents and pens, laying them off to the side. They must be almost prepared to depart.",0);
	add_dialog_str(2,"Just ahead, you can see a crowd gathered near a small mound, with a bonfire on top of it and someone speaking to the crowd. It looks like a meeting of almost the entire expedition.",0);
	set_flag(9,0,run_dialog(1));
	}
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
if (get_crime_level() == 0)
	end();
if (get_flag(290,7) > 0)
	end();
	
	print_str_color("You have made the expedition angry with you.",1);
	make_town_hostile();
	set_flag(290,7,1);
break;

beginstate 10; // begin cutscene
	block_entry(1);
	
	message_dialog("You approach the meeting.","");
	
	// Get the party to 30,30
	i = 0;
	while (char_ok(i) == 0)
		{i = i + 1; }
	while ((char_loc_x(i) != 30) || (char_loc_y(i) != 30)) {
		if (char_loc_x(i) != 30)
			j = char_loc_x(i) + 1;
		else
			j = char_loc_x(i);
		if (char_loc_y(i) != 30)
			k = char_loc_y(i) - 1;
		else
			k = char_loc_y(i);
		march_party(j,k);
		force_view_center(j,k);
		force_instant_terrain_redraw();
		pause(get_flag(290,0) * 1);
		}
	
	message_dialog("You are close enough now to see that Legare is speaking. By the looks of it, he's wrapping things up.","Phaedra notices you. Without turning, she speaks.");
	
	if (party_size() > 1)
		text_bubble_on_char(7,"Hey, guys,");
	else
		text_bubble_on_char(7,"Hey,");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(7,"");
	text_bubble_on_char(7,"get closer.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(7,"");
	text_bubble_on_char(7,"Pithoss is about to speak,");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(7,"");
	text_bubble_on_char(7,"and I think it'll be good.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(7,"");
	text_bubble_on_char(13,"And now it is time");
	march_party(29,29);
	force_view_center(29,29);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(28,28);
	force_view_center(28,28);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(27,27);
	force_view_center(27,27);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(26,26);
	force_view_center(26,26);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 2);
	
	text_bubble_on_char(13,"");
	text_bubble_on_char(13,"to hear another.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(13,"");
	text_bubble_on_char(13,"I give you my trusted aide,");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(13,"");
	text_bubble_on_char(13,"PITHOSS!");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(13,"");
	force_instant_terrain_redraw();
	
	message_dialog("There is a loud round of applause. The audience is lively and clearly in a good mood.","");
	
	relocate_character(13,22,23);
	set_character_facing(13,2);
	relocate_character(12,23,24);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(13,22,24);
	set_character_facing(13,4);
	relocate_character(12,23,23);
	set_character_facing(13,4);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	set_character_facing(13,6);
	set_character_facing(12,6);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	text_bubble_on_char(12,"Thank you.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(12,"");
	text_bubble_on_char(12,"Many of you do not know me well,");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(12,"");
	text_bubble_on_char(12,"so tonight, I will tell you my story.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(12,"");
	text_bubble_on_char(12,"It begins a long time ago.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(12,"");
	force_instant_terrain_redraw();
	
	reset_dialog();
	add_dialog_str(0,"I was young twenty years ago, young and a Darkling. I lived in Sss-Thsss's castle and knew him personally. I was commander of my own raiding party, unusual for my age. We were returning from a raid on Fort Emerald. We arrived home to find everyone dead.",0);
	add_dialog_str(1,"The... heroes... who slew Sss-Thsss were very thorough. They left no one alive. They killed every last one of my kin, they slew my commander, and they left the shattered corpses to stare unseeing at my visage as I tried to comprehend what had happened.",0);
	add_dialog_str(2,"My raiding party looked to me for answers, but I had none. I knew only that my life and my promising future had been taken away from me. I did not even know what I would do, so how could I tell them what they should do?",0);
	add_dialog_str(3,"Still, the sense of loyalty remained. We left that house of death and journeyed southeast to an intact encampment of sliths. I left them there, for I knew that I could no longer be one of them. I left and began to wander.",0);
	run_dialog(1);
	
	reset_dialog();
	add_dialog_str(0,"For seventeen years I wandered, traversing the lands of Avernum, slowly learning the human tongue. The first few years were the hardest: the war was not yet over, and humans were suspicious of an illiterate, poorly-spoken, lone slith.",0);
	add_dialog_str(1,"Even when the war did end, the Empire came and brought more terror, killing all sliths they found. I returned later to find my old comrades, but the villages were destroyed.",0);
	add_dialog_str(2,"I spoke with the powerful and wise: dragons, magicians, kings. King Micah granted me permission to be one of the first non-humans to visit the surface. For others, it was a return; for me, it was new. Sunlight! Dirt! And oceans, vast, wide oceans!",0);
	add_dialog_str(3,"It was on the surface that I began to find the answers for which I had been searching. Many were recovering from recent deaths because of the monster plagues. And then, I visited Gale.",0);
	add_dialog_str(4,"In that city, which was wracked by skribbane addiction, devastated by golems, and dominated by the corrupt and vindictive Mayor Rali, people sought the same hope I did. And the hope that they found came from Zachariah of the Temple of the Shining Beacon.",0);
	add_dialog_str(5,"Zachariah preached that purity came from within; simple living would give peace of mind. He counseled me through my doubts and fears, and he gave me the strength to go to the one place that I had been avoiding: Gnass.",0);
	run_dialog(1);
	
	reset_dialog();
	add_dialog_str(0,"I should have sought Gnass immediately when I turned from the Darklings, but I was afraid. I fought a war against these sliths and was a personal aide to the one who had done them the most harm since Grah-Hoth sixty years ago. What could I say to them?",0);
	add_dialog_str(1,"I journeyed to Gnass but found it prejudiced, intolerant; the priestly class had seized control and clamped down. Dissent was strictly forbidden. As a Darkling, I could disagree with Sss-Thsss on faith, but to oppose High Priest Pathass spelled death.",0);
	add_dialog_str(2,"Three years I lived in Gnass, seeking weaknesses in the theocracy. Few spoke their minds, but I was sure that many agreed with me. Thus, when Legare came, I was quick to back him as the Prophet: I wanted to see him topple the priesthood and free Gnass.",0);
	add_dialog_str(3,"To my dismay, though, Legare cared nothing for power. He wanted only to preach, and it turned out that his message appealed most to those least capable of effecting change: the poor, the privately religious, or those who lived outside of Gnass.",0);
	add_dialog_str(4,"You know the story since then. We could do little in Gnass. We decided to leave, to go to Bahssikava and then make our way into the homeland, the blasphemy which brought Gnass's anger upon us. But Legare's promise held: we made it to Bahssikava.",0);
	run_dialog(1);
	
	reset_dialog();
	add_dialog_str(0,"Our arrival in Bahssikava meant many things to many sliths, but I was perhaps the most conflicted of all. The Darklings are not simple barbarians: we have our own warrior traditions and our own values.",0);
	add_dialog_str(1,"We Darklings know of Bahssikava, but unlike those of Gnass, we know the Bahssikavans as our ancient enemies. Among our oral traditions are the Ancient Battle Chants, verses that tell of the war long ago between the Bahssikavans and the Darklings.",0);
	add_dialog_str(2,"I did not know what to think in Bahssikava. Was I a Darkling, to know that I tread on the ground of my enemies and to feel the hot rush of blood that came with that? A Gnass slith, to feel the anguish of holiness lost when this place was destroyed?",0);
	add_dialog_str(3,"No, I decided. I am not a Darkling, but neither am I of Gnass. I am a follower of Legare, trying to end the curse and exile that have been on my people for more than two hundred years.",0);
	run_dialog(1);
	
	text_bubble_on_char(12,"Bahssikava is not a place to me;");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(12,"");
	text_bubble_on_char(12,"it is a way, a path, a method.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(12,"");
	text_bubble_on_char(12,"We completed what Bahssikava began.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(12,"");
	text_bubble_on_char(12,"We have opened the steel doors");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(12,"");
	text_bubble_on_char(12,"and begun the journey to the homeland");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(12,"");
	text_bubble_on_char(12,"The Bahssikavan repentance is done.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(12,"");
	text_bubble_on_char(12,"The time of the EXODUS has begun.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 7);
	
	text_bubble_on_char(12,"");
	force_instant_terrain_redraw();
	
	message_dialog("The audience breaks out into loud applause. You find yourselves joining in.","Pithoss's gaze travels over the crowd and ends up on you.");
	
	text_bubble_on_char(12,"But I am not the only one");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(12,"");
	text_bubble_on_char(12,"who has a story to tell you.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	clear_buffer();
	append_string("Come, ");
	append_char_name(i);
	append_string(",");
	get_buffer_text(dlgstr);
	
	text_bubble_on_char(12,"");
	text_bubble_on_char(12,dlgstr);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(12,"");
	text_bubble_on_char(12,"tell us your story.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(12,"");
	march_party(25,25);
	force_view_center(25,25);
	relocate_character(12,22,23);
	set_character_facing(12,2);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(24,24);
	force_view_center(24,24);
	set_character_facing(12,6);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(23,24);
	force_view_center(23,24);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(23,23);
	force_view_center(23,23);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(23,22);
	force_view_center(23,22);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(23,21);
	force_view_center(23,21);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	set_character_facing(0,6);
	set_character_facing(1,6);
	set_character_facing(2,6);
	set_character_facing(3,6);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	reset_dialog();
	add_dialog_str(0,"You stand before the audience and tell them your story, describing your encounter with the frost lizards and the barbarian sliths, telling of the ruined cities that you saw and the horrors of the blasted land through which you returned.",0);
	add_dialog_str(1,"You explain that you've cleared a path all the way to Nakhtha, but you need help with some machinery. Talas, who is front and center in the crowd, shouts out, _I'll do it!_",0);
	add_dialog_str(2,"You finish your story, exhilarated at the performance. The crowd brings enthusiasm and passion to the event. You step to the side and Legare begins speaking again. Before you can really listen, Kass pulls you aside.",0);
	add_dialog_str(3,"_You should get some rest,_ he says. _You've been through a lot, and we're meeting here for a few hours until we leave. We've left your tent alone so you can sleep._ He bids you off, and you return to your tent and drift off.",0);
	run_dialog(1);
	
	toggle_quest(0,0);
	
	i = 33;
	while (i < 35) {
		j = 14;
		while (j < 22) {
			set_floor(i,j,255);
			set_terrain(i,j,1);
			j = j + 1;
			}
		i = i + 1;
		}
	
	set_floor(36,19,255);
	set_floor(36,20,255);
	set_floor(36,21,255);
	set_terrain(36,19,1);
	set_terrain(36,20,1);
	set_terrain(36,21,1);
	
	i = 42;
	while (i < 43) {
		j = 14;
		while (j < 21) {
			set_floor(i,j,255);
			set_terrain(i,j,1);
			j = j + 1;
			}
		i = i + 1;
		}
	
	march_party(37,15);
	march_party(38,15);
	march_party(39,15);
	march_party(40,15);
	force_view_center(40,15);
	force_instant_terrain_redraw();
	
	set_flag(9,1,1);
	
break;

beginstate 11;
	message_dialog("You fall onto your sleeping pad and are asleep within seconds. You awake without much sense of having slept: you're still tired, but you are at least a little restored.","You leave your tent and discover that it is time to set off. The expedition will travel downriver along the path that you cleared.");
	revive_party();
	move_to_new_town(10,6,11);
break;