// Town 42: Barbarian Fort
begintownscript;

variables;

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

body;

beginstate INIT_STATE;
	set_crime_tolerance(2);
	
	put_field_on_space(6,8,6);
	
	set_special_ability(8,17);
	set_level(8,78);
	
	if (get_flag(42,3) == 0) {
		set_name(10,"Britha");
		set_name(11,"Ithik");
		}
	else
		erase_char(10);
	
	if (get_flag(42,0) == 0) {
		force_instant_terrain_redraw();
		set_flag(42,0,1);
		message_dialog("You approach what appears to be a barbarian fort. The barbarians have cut arrow-holes in the walls, and the gates are solidly closed, so there doesn't seem to be any point in approaching the front.","However, you find a small tunnel in the north that appears to be a garbage heap. You may be able to get in unnoticed this way.");
		}
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;
	message_dialog("As this mighty slith dies, you notice it drop a brass key, which you quickly grab. It might be useful.","");
	change_spec_item(5,1);
break;

beginstate 11;
if (get_flag(42,1) == 0) {
	reset_dialog();
	add_dialog_str(0,"The book on this pedestal is clearly a spellbook, written in a strange, arcane language and telling of terrible secrets of magical power.",0);
	add_dialog_str(1,"Reading strange spellbooks can be dangerous: they can carry curses or other terrible effects. However, they can also have great spells recorded within.",0);
	add_dialog_str(2,"What do you do?",0);
	add_dialog_choice(0,"Leave it alone.");
	add_dialog_choice(1,"Attempt to read it.");
	if (run_dialog(1) == 2) {
		reset_dialog();
		// Requires Arcane Lore of 26.
		if (get_skill_total(42) >= 26) {
			set_flag(42,1,1);
			add_dialog_str(0,"The book is written in a strange rune script, but fortunately, due to your knowledge of Arcane Lore, you can read it.",0);
			add_dialog_str(1,"The book describes an interesting new spell, one that creates a small field of quickfire around an enemy! This is an exceptionally dangerous spell. (You learn a level of Quickfire.)",0);
			set_flag(292,11,run_dialog(1)); // flag for spell
			set_flag(292,0,1);
			}
		else
			message_dialog("The book is written in a strange rune script, and unfortunately, you can't read it. Perhaps if you knew more about Arcane Lore, you would be able to.","");
		}
	}
else
	message_dialog("You find the book on Quickfire again, but you don't learn anything new from it.","");
break;

beginstate 12;
if (get_flag(42,2) == 0) {
	reset_dialog();
	add_dialog_str(0,"On these stacks, amid many books about nothing, you find a small spellbook! It is covered with runes across the cover.",0);
	add_dialog_str(1,"Reading strange spellbooks can be dangerous: they can carry curses or other terrible effects. However, they can also have great spells recorded within.",0);
	add_dialog_str(2,"What do you do?",0);
	add_dialog_choice(0,"Leave it alone.");
	add_dialog_choice(1,"Attempt to read it.");
	if (run_dialog(1) == 2) {
		reset_dialog();
		// Requires Arcane Lore of 26.
		if (get_skill_total(42) >= 26) {
			add_dialog_str(0,"The book is written in a strange rune script, but fortunately, due to your knowledge of Arcane Lore, you can read it.",0);
			// Requires some skill in the spell already.
			if (get_flag(293,2) > 0) {
				set_flag(42,2,1);
				add_dialog_str(1,"It's a very advanced spellbook describing how to cast Protection in the most efficient fashion possible. You read over it carefully.",0);
				set_flag(293,2,3); // flag for spell
				}
			else
				add_dialog_str(1,"It's a very advanced spellbook describing how to cast a complex spell, Protection, in a very efficient manner. Unfortunately, you are completely unfamiliar with the spell, so it is too hard for you to understand.",0);
			run_dialog(1);
			}
		else
			message_dialog("The book is written in a strange rune script, and unfortunately, you can't read it. Perhaps if you knew more about Arcane Lore, you would be able to.","");
		}
	}
else
	message_dialog("You find the book on Protection again, but you don't learn anything new from it.","");
break;

beginstate 13;
	reset_dialog_preset_options(3);
	if (run_dialog(1) == 2)
		teleport_party(5,14,0);
break;

beginstate 14;
	reset_dialog_preset_options(3);
	if (run_dialog(1) == 2)
		teleport_party(12,26,0);
break;

beginstate 15;
if (get_flag(42,3) != 0)
	end();
	
	block_entry(1);
	reset_dialog();
	add_dialog_str(0,"This slith, a female, has clearly suffered at the hands of her captors. She looks quite strong, probably a scout like Phaedra, but her back and shoulders are covered with small wounds and large scratches, probably from whips. She has been tortured.",0);
	add_dialog_str(1,"Do you approach this slith and unchain her?",0);
	add_dialog_choice(0,"No. (Leave.)");
	add_dialog_choice(1,"Yes. (Free her.)");
	if (run_dialog(1) == 1) {
		message_dialog("She looks at you balefully. _Free me!_ she says.","");
		end();
		}
	
	set_flag(42,3,1);
	
	message_dialog("You are ready to approach this slith to free her, and before you can even take a step, the portal flashes. Someone is coming through!","");
	
	i = 0;
	while (char_ok(i) == 0)
		{i = i + 1; }
		
	activate_hidden_group(1);
	put_boom_on_char(11,2,0);
	run_animation_sound(10);
	
	text_bubble_on_char(11,"Aha!");
	relocate_character(11,6,14);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	if (char_loc_y(i) == 10) {
		march_party(14,11);
		force_view_center(14,11);
		}
	if (char_loc_y(i) == 14) {
		march_party(14,13);
		force_view_center(14,13);
		}
	relocate_character(11,7,14);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(13,12);
	force_view_center(13,12);
	relocate_character(11,8,14);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	set_character_facing(11,7);
	relocate_character(11,9,13);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	set_character_facing(11,0);
	relocate_character(11,9,12);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	set_character_facing(11,6);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	text_bubble_on_char(11,"");
	force_instant_terrain_redraw();
	
	message_dialog("It's Ithik! What could he be doing here?","");
	
	text_bubble_on_char(11,"I've been looking all over for you.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(11,"");
	text_bubble_on_char(11,"I bring a message.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(11,"");
	force_instant_terrain_redraw();
	
	message_dialog("_Something about what Legare scried has him spooked,_ Ithik says. _Several other people in the camp were preparing to leave when I left. We're all coming to save Ethass._","He seems about ready to say something else, but he notices the prisoner, and he stops short. _Who... who are you?_ he asks.");
	
	text_bubble_on_char(10,"Free me, and I'll tell you everything.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(10,"");
	march_party(13,11);
	set_character_facing(11,4);
	relocate_character(11,9,13);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(14,10);
	set_character_facing(11,5);
	relocate_character(11,10,14);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(15,9);
	set_character_facing(11,6);
	relocate_character(11,11,14);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(14,9);
	set_character_facing(11,7);
	relocate_character(11,12,13);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(13,9);
	relocate_character(11,13,12);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	march_party(12,9);
	set_character_facing(11,6);
	relocate_character(11,14,12);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	set_character_facing(0,4);
	set_character_facing(1,4);
	set_character_facing(2,4);
	set_character_facing(3,4);
	text_bubble_on_char(10,"*click*");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 4);
	
	text_bubble_on_char(10,"");
	text_bubble_on_char(10,"Thank you.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(10,"");
	text_bubble_on_char(10,"Now, my story.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(10,"");
	force_instant_terrain_redraw();
	
	reset_dialog();
	add_dialog_str(0,"_My name is Britha,_ she says, _and I come from Danatha._ Danatha! That is the nearest city of Khitaloss Province! This slith comes from the Empire of Khalthas, or whatever may be left of it!",0);
	add_dialog_str(1,"_I am a scout. I was sent to these lands to check the forces of the barbarians, who are rumored to be planning an invasion, but I've found little evidence for that yet._",0);
	add_dialog_str(2,"She rubs her wrists, apparently still aching from the chains. _I was a little too careless, though. I came near this fort and got caught. Since then, I've been stuck here. That was a few days ago, I think._",0);
	if ((species_in_party(0)) || (species_in_party(2)))
		add_dialog_str(3,"She frowns. _But what are you? I've never seen such oddly-composed creatures before._ She has probably never seen humans or nephils, which explains her confusion.",0);
	else
		add_dialog_str(3,"She frowns. _But who are you? You are not barbarians, but I was not aware of any other cities still standing within reach of this land._",0);
	add_dialog_str(4,"You explain your identity briefly. She simply listens, asking no questions.",0);
	run_dialog(1);
	
	text_bubble_on_char(11,"If you come with me,");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(11,"");
	text_bubble_on_char(11,"I can take you back to our expedition.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(11,"");
	text_bubble_on_char(11,"You can lead us to your home.");
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 5);
	
	text_bubble_on_char(11,"");
	force_instant_terrain_redraw();
	
	message_dialog("Britha looks excited at the prospect, and the two of them begin to walk back to the portal.","_Oh, yes,_ Ithik says, _I almost forgot. I found this on the body of a barbarian I had to kill to get here. Here._ He hands you a small copper key. With that, he and Britha depart.");
	
	change_spec_item(6,1);
	
	set_character_facing(11,3);
	set_character_facing(10,3);
	relocate_character(11,13,13);
	relocate_character(10,14,13);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(11,12,14);
	relocate_character(10,13,14);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	set_character_facing(11,2);
	set_character_facing(10,2);
	relocate_character(11,11,14);
	relocate_character(10,12,14);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(11,10,14);
	relocate_character(10,11,14);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(11,9,14);
	relocate_character(10,10,14);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(11,8,14);
	relocate_character(10,9,14);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(11,7,14);
	relocate_character(10,8,14);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(11,6,14);
	relocate_character(10,7,14);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	relocate_character(11,5,14);
	relocate_character(10,6,14);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	set_character_facing(11,4);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	put_boom_on_char(11,2,0);
	run_animation_sound(10);
	
	erase_char(11);
	relocate_character(10,5,14);
	force_instant_terrain_redraw();
	pause(get_flag(290,0) * 1);
	
	put_boom_on_char(10,2,0);
	run_animation_sound(10);
	
	erase_char(10);
	force_instant_terrain_redraw();
	
break;

beginstate 16;
if (get_flag(42,4) == 0) {
	reset_dialog();
	add_dialog_str(0,"In this desk, there are many papers, most of which are irrelevant to you. But amidst this junk, you find a rune-filled spellbook!",0);
	add_dialog_str(1,"Reading strange spellbooks can be dangerous: they can carry curses or other terrible effects. However, they can also have great spells recorded within.",0);
	add_dialog_str(2,"What do you do?",0);
	add_dialog_choice(0,"Leave it alone.");
	add_dialog_choice(1,"Attempt to read it.");
	if (run_dialog(1) == 2) {
		reset_dialog();
		// Requires Arcane Lore of 27.
		if (get_skill_total(42) >= 27) {
			set_flag(42,4,1);
			add_dialog_str(0,"The book is written in a strange rune script, but fortunately, due to your knowledge of Arcane Lore, you can read it.",0);
			if (get_flag(292,16) == 0) // flag for spell
				add_dialog_str(1,"The book describes an interesting new spell, one that blasts your enemies with a large cloud of devastating, irresistable magical energy. (You learn a level of Cloudkill.)",0);
			else
				add_dialog_str(1,"It's a spellbook describing how to cast Cloudkill more efficiently. You read over it carefully.",0);
			inc_flag(292,16,run_dialog(1)); // flag for spell
			set_flag(292,0,1);
			}
		else
			message_dialog("The book is written in a strange rune script, and unfortunately, you can't read it. Perhaps if you knew more about Arcane Lore, you would be able to.","");
		}
	}
else
	message_dialog("You find the book on Cloudkill again, but you don't learn anything new from it.","");
break;

beginstate 17;
	reset_dialog_preset_options(9);
	if (run_dialog(1) == 2)
		move_to_new_town(58,16,15);
	else
		block_entry(1);
break;

beginstate 18;
if (get_flag(29,4) == 0)
	message_dialog("This door is locked right now. You can't get it open at all.","");
break;