// Town 23: Camp
begintownscript;

variables;

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

body;

beginstate INIT_STATE;
	set_crime_tolerance(2);
	
if (get_flag(24,1) == 0) {
	change_blocked(5,21,1);
	change_blocked(5,22,1);
	change_blocked(5,23,1);
	change_blocked(5,24,1);
	change_blocked(6,21,1);
	change_blocked(6,22,1);
	change_blocked(6,23,1);
	change_blocked(6,24,1);
	change_blocked(7,21,1);
	change_blocked(7,22,1);
	change_blocked(7,23,1);
	change_blocked(7,24,1);
	change_blocked(8,21,1);
	change_blocked(8,22,1);
	change_blocked(8,23,1);
	change_blocked(8,24,1);
	}
	
	change_blocked(31,28,1);
	change_blocked(32,28,1);
	change_blocked(33,28,1);
	change_blocked(31,27,1);
	change_blocked(32,27,1);
	change_blocked(33,27,1);
	
	set_name(6,"Machrone"); // type 78
	set_char_dialogue_pic(7,585,0); // Phaedra
	set_name(8,"Kass"); // type 36
	set_char_dialogue_pic(8,583,0);
	set_name(9,"Talas"); // type 112
	set_char_dialogue_pic(9,582,0);
	set_name(10,"Silthokh"); // type 111
	set_name(11,"Legare"); // type 119
	set_name(12,"Pithoss"); // type 112
	set_char_dialogue_pic(12,580,0);
	set_name(13,"Ithik"); // type 112
	set_level(13,60);
	set_name(14,"Ethass"); // type 111
	set_char_dialogue_pic(14,584,0);
	set_name(15,"Bitey");
	set_name(16,"Hissy");
	set_name(17,"Snarly");
	set_name(18,"Kass"); // type 36
	set_char_dialogue_pic(18,583,0);
	
	if (get_flag(290,7))
		make_town_hostile();
	
if (get_flag(24,1) == 0) {
	i = 21;
	while (i <= 43) {
		j = 6;
		while (j <= 20) {
			set_floor(i,j,174);
			set_terrain(i,j,0);
			j = j + 1;
			}
		i = i + 1;
		}
	}
else
	if (get_flag(23,1) == 0) {
		set_flag(23,1,1);
		put_item_on_spot(22,9,374);
		put_item_on_spot(24,9,374);
		message_dialog("As you return to the camp, you notice that the temple has much more in it. They have been hard at work since you've been gone, and they've built something obviously magnificent, even at this distance.","");
		}

if (get_flag(23,3) != 0) {
	set_terrain(31,7,397);
	set_terrain(33,7,397);
	set_terrain(41,7,363);
	set_terrain(41,10,363);
	set_terrain(41,13,363);
	set_terrain(41,16,363);
	set_terrain(41,19,363);
	}
	
if (get_flag(28,0) != 0)
	set_state_continue(14);
	
if (has_special_item(3) > 1) {
	erase_char(8);
	activate_hidden_group(1);
	set_name(18,"Kass"); // type 36
	set_char_dialogue_pic(18,583,0);
	}
	
	if (get_flag(23,0) == 0) {
		change_outdoor_location(0,7,8,14);
		force_instant_terrain_redraw();
		reset_dialog();
		add_dialog_str(0,"You sleep uneventfully. When you wake, you set off to the berekh hive and pass through the secret side-passage you discovered, avoiding the breeding pit. On the other side, you find a strange-looking new cave.",0);
		add_dialog_str(1,"The cave ground is a different color, lighter, richer, obviously more fertile. Compared to the harshness of the Lava Ocean, this will be a welcome respite.",0);
		add_dialog_str(2,"You descend into the new valley, heading west to the expedition's camp. Three big news items immediately become clear: first, there is food here! The camp is surrounded by delicious edible mushrooms of a variety as yet unknown.",0);
		add_dialog_str(3,"Second, in gratitude to the Goddess for deliverance from the desperate times in the Lava Ocean, Legare has ordered the construction of a large, mobile temple. It has already been begun.",0);
		add_dialog_str(4,"And third, Phaedra is having her baby! She is in labor as you arrive, and she seems likely to finish in half a day or more. Everyone still seems a little sheepish about the scene that they made before, but it is well past now.",0);
		add_dialog_str(5,"You set up your tent as usual. Now it is probably time to speak with Kass and receive your next mission.",0);
		set_flag(23,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;
if (get_flag(24,1) == 0) {
	block_entry(1);
	message_dialog("This is Phaedra's tent, but she is either currently in labor or just recently finished. You probably should leave her alone either way.","");
	}
break;

beginstate 11;
	message_dialog("This is Legare's door, but you don't have anything important to talk to him about, so you leave it alone.","");
break;

beginstate 12;
	reset_dialog();
	add_dialog_str(0,"Machrone begins speaking into his orb again.",0);
	add_dialog_str(1,"_Again?_ he says. _The whole thing?_ He receives a sleepy-sounding _Yes_ from the orb. _You know, Federic, if I didn't know better, I'd think you were giving me the run-around._",0);
	add_dialog_str(2,"He begins reading from a sheet in front of him. _Having escaped the dangers of the Lava Ocean, we've come into a new land with plenty of food and supplies. Some thank the Goddess for this good fortune. Others thank luck.",0);
	add_dialog_str(3,"_The food is from a strange new species of mushroom. So many are asking, 'What is it?', that one would think its name is What-Is-It. This What-Is-It has surely saved our lives, though; we were dangerously low on food until now.",0);
	add_dialog_str(4,"_In gratitude to the Goddess, Legare has ordered the construction of a large, mobile temple that will come with us as we journey. Talas has been in charge of its construction.",0);
	add_dialog_str(5,"_We are all very hopeful that we will reach the center of the homeland soon. All are tired after the Lava Ocean and hope to finish this quest._",0);
	run_dialog(1);
break;

beginstate 13;
if (has_special_item(2) > 0) {
	if (get_flag(23,2) == 0) {
		reset_dialog();
		add_dialog_str(0,"As you approach closer, you can see the inside of the temple better. The construction is truly masterful, with smooth crystal orbs giving light and simple wooden pillars holding up the roof.",0);
		add_dialog_str(1,"Kass catches sight of you carrying the tapestry back. _You have it!_ he says. He comes down and you hand it over to him. He quickly hurries back up into the temple and gives it to Talas, who takes it behind the altar and puts it up.",0);
		add_dialog_str(2,"_You have done well,_ Kass says. _The Goddess will be pleased. Come and speak to me; I have a new quest for you._",0);
		set_flag(23,2,run_dialog(1));
		toggle_quest(7,0);
		}
	change_spec_item(2,-1);
	}
if (has_special_item(3) == 1)
	if (get_flag(23,5) == 0) {
		message_dialog("You return with one tree in tow, but Kass wants two. You don't have the other one.","");
		set_flag(23,5,1);
		}
		
if (has_special_item(3) <= 1) 
	end();
if (get_flag(23,3) != 0)
	end();
	
	set_flag(23,3,1);
	
	set_terrain(31,7,397);
	set_terrain(33,7,397);
	set_terrain(41,7,363);
	set_terrain(41,10,363);
	set_terrain(41,13,363);
	set_terrain(41,16,363);
	set_terrain(41,19,363);
	
	block_entry(1);
	
	message_dialog("You return to the temple with both trees that you need. Kass spots you and hurries down.","");
	
	text_bubble_on_char(18,"You've returned!");
	relocate_character(18,32,20);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(18,32,21);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(18,32,22);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(18,32,23);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(18,32,24);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	text_bubble_on_char(18,"");
	relocate_character(18,32,25);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(18,32,26);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	text_bubble_on_char(18,"Good.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	relocate_character(9,32,17);
	set_character_facing(9,4);
	set_character_facing(18,0);
	text_bubble_on_char(18,"");
	text_bubble_on_char(18,"Talas!");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(9,32,18);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(9,32,19);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(9,32,20);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(9,32,21);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(9,32,22);
	text_bubble_on_char(18,"");
	text_bubble_on_char(9,"Yes?");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(9,32,23);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(9,32,24);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 3);
	
	text_bubble_on_char(9,"");
	text_bubble_on_char(18,"Put these trees in their places.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(18,"");
	force_instant_terrain_redraw();
	
	toggle_quest(8,0);
	
	message_dialog("Talas comes down and takes the trees from you. He brings them inside the temple. Kass considers for a moment.","");
	
	change_spec_item(3,-2);
	
	relocate_character(9,22,8);
	set_character_facing(9,6);
	set_character_facing(18,4);
	set_character_facing(10,0);
	relocate_character(10,34,40);
	text_bubble_on_char(18,"I have another mission for you.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(10,34,39);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(10,34,38);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(10,34,37);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(10,34,36);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(10,34,35);
	text_bubble_on_char(18,"");
	text_bubble_on_char(18,"There is a cave to the north of here");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	relocate_character(10,34,34);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(10,34,33);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 3);
	
	text_bubble_on_char(18,"");
	text_bubble_on_char(18,"in which there is a golden pole");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(18,"");
	text_bubble_on_char(18,"which we may use to decorate");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(18,"");
	text_bubble_on_char(18,"this humble shrine for the Goddess.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(18,"");
	text_bubble_on_char(18,"Get it for us.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(18,"");
	force_instant_terrain_redraw();
	
	message_dialog("You notice that Silthokh has taken an interest in these proceedings. At these instructions, he frowns.","");
	
	text_bubble_on_char(10,"Why are you delaying, Kass?");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(10,"");
	text_bubble_on_char(10,"We have a journey to make.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(10,"");
	force_instant_terrain_redraw();
	
	message_dialog("Kass looks uncomfortable. He notices that several others are watching as well, from a greater distance.","_Perhaps the merchant is right,_ he says. _We can return for the golden pole later. For now, you should continue onward._");
	
	text_bubble_on_char(18,"Scout south down the river.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(18,"");
	text_bubble_on_char(18,"Find the next suitable stopping place.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(18,"");
	text_bubble_on_char(18,"When you have done so, return here.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	toggle_quest(9,1);
	
	text_bubble_on_char(18,"");
	force_instant_terrain_redraw();
	
	message_dialog("Kass adds, off-handedly, _Talas has built a boat for you along the riverbank due south of here. Use it for your scouting._ With that, he leaves abruptly, and Silthokh, apparently satisfied, returns to the fields of mushrooms.","");
	
	// Put everyone back where they were.
	erase_char(18);
	spawn_creature(8);
	relocate_character(10,45,51);
	
break;

beginstate 14;
	reset_dialog();
	add_dialog_str(0,"You return to camp with news of the next stopping point for the expedition. As soon as you arrive, Kass gives the word for everyone to break camp, and the whole area becomes bustling with activity.",0);
	add_dialog_str(1,"Everyone rushes around to disassemble the tents and the holding pens, and they load up the pack lizards with as much as the beasts can carry. Most impressive of all, Talas gives a few orders, and the shrine breaks down into portable pieces.",0);
	add_dialog_str(2,"You return to your tent to rest briefly before you set out.",0);
	run_dialog(1);
	toggle_quest(9,0);
	march_party(53,38);
	march_party(54,38);
	march_party(55,38);
	march_party(56,38);
	force_view_center(56,38);
	force_instant_terrain_redraw();
break;

beginstate 15;
if (get_flag(28,0) != 0) {
	message_dialog("After you rest, you pack up your tent, preparing to leave. Then, after a short time, you go, leading the expedition down the river to the peninsula that you found.","");
	move_to_new_town(29,44,26);
	}
break;

beginstate 17;
	reset_dialog();
	add_dialog_str(0,"You have returned to your tent. What would you like to do?",0);
	add_dialog_choice(0,"Nothing.");
	add_dialog_choice(1,"Rest.");
	if (run_dialog(1) == 1)
		end();
	
	force_view_center(7,7);
	force_instant_terrain_redraw();
	
	block_entry(1);
	
	i = 0;
	while (char_ok(i) == 0)
		{i = i + 1; }
	march_party(53,38);
	march_party(54,38);
	march_party(55,38);
	march_party(56,38);
	
	revive_party();
	play_sound(20);
	
	message_dialog("You lay down in your tent and sleep uneventfully for a short time. When you wake, you are fully revived.","");
	
	force_view_center(char_loc_x(i),char_loc_y(i));
	force_instant_terrain_redraw();
break;