// TOWN SCRIPT
//    

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;
short times;
short timegap;
short choice;

body;

beginstate INIT_STATE;
// Quick! Fire!
put_field_on_space(35, 33, 6);
put_field_on_space(30, 36, 6);
put_field_on_space(30, 33,6);
put_field_on_space(30,29,6);
put_field_on_space(33,29,6);
put_field_on_space(39,29,6);
put_field_on_space(39, 33,6);
put_field_on_space(39,35,6);
put_field_on_space(39,39,6);



set_name(22,"Lord Ashford" );
set_name(30, "Diana");
set_name(64, "Frrza");
set_name(76, "Sissay");

if (get_flag(1,1) == 0) {
	activate_hidden_group(6);
	set_flag(6,4,324);
}	
if (get_flag(1,1) == 1) {
	activate_hidden_group(7);
	set_flag(6,4,358);
}
if (get_flag(1,1) == 2) {
	activate_hidden_group(8);
	set_flag(6,4,370);
}

if (get_flag(4,4)) erase_char(22);
if (get_flag(4,5)) {
	erase_char(30);
	erase_char(64);
	erase_char(76);
}

break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
if (get_flag(4,5) && (character_in_party(256 + get_flag(6,4)) == -1)) {
	message_dialog("Your sister falls to the ground.  You rush over to try to help her, but she is dead.", "All that, for nothing!  Unfortunately, you are too busy crying over her to notice the bandit sneaking up behind you...");
	kill_char(1000,2,0);
}
break;

beginstate 10;
	message_dialog("This book describes some of the experiments the mages have been performing.  Most of it is pretty boring, but there is a page describing some special wands they have been making.","There is one that allows the user to absorb life energy from a victim, one that induces horrible mutations and one that causes _mutual spatial re-expression_, whatever that is.");
break;

beginstate 11;
if (get_flag(3,6) == 0) {
	if (get_flag(3,4) == 0) {
		times = get_flag(3,3);
		times = times + 1;
		set_flag(3,4,1);
		if (times == 1) {
			message_dialog("As you approach this door, you hear someone say _They're outside!  Get ready!_","Then there is a general scuffle as a group of people get ready for combat.");
		}
		if (times == 2) {
			message_dialog("You hear someone say _They're coming back!_","");
		}
		if (times == 3) {
			message_dialog("You hear someone say _They're coming back again!_","Another voice says _Are you sure?  You've said that before._");
		}
		if (times == 4) {
			message_dialog("_They're coming again!_","_I'm fed up with this.  You can't use that thing properly._");
			set_flag(3,6,1);
		}
		set_flag(3,3,times);
	}
}

break;

beginstate 12;
if (get_flag(3,6) == 0) {
	if (get_flag(3,4) == 1) {
		message_dialog("_They're going away again_","");
		set_flag(3,4,0);
	}
}
break;

beginstate 13;
if(get_flag(3,7) == 0) {
	message_dialog("This chest contains a lot of junk, a few nice magic items and an intricate key.","");
	change_spec_item(2,1);
	set_flag(3,7,1);
}
break;

beginstate 14;
if (get_flag(3,8) == 0) {
	message_dialog("There are a pair of bandits _guarding_ the wine in this storeroom.  They don't look pleased to see you.","");
	set_flag(3,8,1);
}
break;

beginstate 15;
if (get_flag(3,9) == 0) {
	message_dialog("This is clearly the sleeping quarters for the majority of the bandits.  It's cramped, and it stinks.  Brigands clearly haven't mastered the art of washing yet.", "Luckily for you, it's empty.  Probably because it's daytime and nobody would spend longer here than they had to.");
	set_flag(3,9,1);
}
break;

beginstate 16;
	erase_char(66);
	erase_char(67);
	set_flag(4,0,1);
break;

beginstate 17;  // Pool of drooling
	reset_dialog();
	add_dialog_str(0, "You can see the room reflected in the pool's surface.  Oddly, you can also see outside the room too.",0);
	add_dialog_str(1, "As you stare into it, you find that you can make the image move about by thinking about it",0);
	add_dialog_str(2, "Do you want to take a proper look?",0);
	add_dialog_choice(0, "Look");
	add_dialog_choice(1, "Leave");
	choice = run_dialog(0);
	if (choice == 1) {
		if ((get_flag(4,0) == 0) && (get_flag(4,1) == 0)) {
			set_flag(4,1,1);
			set_total_visibility(1);
			force_view_center(16,25);
			force_instant_terrain_redraw();
			message_dialog("When you look into the pool, the view shifts to a particular place.","This is probably the area most often looked at by the pool's normal users.");
			text_bubble_on_char(67,"What should we do about those idiots");
			force_instant_terrain_redraw();
			pause(20);
			erase_text_bubbles();
			text_bubble_on_char(67,"who are attacking us?");
			force_instant_terrain_redraw();
			pause(20);
			erase_text_bubbles();
			text_bubble_on_char(66,"We let them. The more they kill...");
			force_instant_terrain_redraw();
			pause(20);
			erase_text_bubbles();
			text_bubble_on_char(66,"...the bigger our share...");
			force_instant_terrain_redraw();
			pause(20);
			erase_text_bubbles();
			text_bubble_on_char(66,"...of the ransom will be.");
			force_instant_terrain_redraw();
			pause(20);
			erase_text_bubbles();
			text_bubble_on_char(66,"Are the prisoners safe?");
			force_instant_terrain_redraw();
			pause(20);
			erase_text_bubbles();
			text_bubble_on_char(67,"Of course");
			force_instant_terrain_redraw();
			pause(20);
			erase_text_bubbles();
			force_instant_terrain_redraw();
			pause(5);
			erase_text_bubbles();
			text_bubble_on_char(67, "I don't like your use...");
			force_instant_terrain_redraw();
			pause(20);
			erase_text_bubbles();
			text_bubble_on_char(67, "of Quickfire in the empty cells");
			force_instant_terrain_redraw();
			pause(20);
			erase_text_bubbles();
			text_bubble_on_char(66, "It's perfectly safe.");
			force_instant_terrain_redraw();
			pause(20);
			erase_text_bubbles();
			text_bubble_on_char(66,"Only I have the key, and...");
			force_instant_terrain_redraw();
			pause(20);
			erase_text_bubbles();
			text_bubble_on_char(66,"...I can easily dispel it");
			force_instant_terrain_redraw();
			pause(20);
			erase_text_bubbles();
			force_instant_terrain_redraw();
		}
		set_total_visibility(1);
		set_flag(6,2,1);
	}

force_instant_terrain_redraw();
break;

beginstate 18;
set_total_visibility(0);
set_flag(6,2,0);
break;

beginstate 19;
	if (get_flag(4,2) == 0) {
		set_flag(4,2,1);
		activate_hidden_group(5);
		teleport_party(8,24,0);
		message_dialog("As you step into the room, a voice shouts to you _Come over here where we can see you better!_","Suddenly you are standing in the middle of the room, surrounded by enemies.  This looks bad.");
	} else {
		if (get_flag(5,3) < 2) {
			message_dialog("_Hey, we've not finished with you!  Come back here._","");
			teleport_party(8,24,0);
		}
	}
break;

beginstate 20;
	if(get_flag(4,6) == 0) {
	set_flag(4,6,1);
	message_dialog("What seemed to be a small cave turns out to be quite a large fort.","It must have been a huge effort to build this secretly, but considering the likely ransom for a high-ranking official, probably not a waste.");
	}
	if (get_flag(4,4) && (get_flag(4,5) == 0)) {
		message_dialog("Surely you aren't going to rescue an Empire bureaucrat and leave your sister imprisoned?","");
		block_entry(1);
	}
	if ((get_flag(4,5)) && (get_flag(5,2) == 0)) {
		message_dialog("You've almost escaped.  But suddenly someone shouts _Get them!_ and you are surrounded.","");
		set_flag(5,2,1);
		activate_hidden_group(10);
	}
break;

beginstate 21;
	reset_dialog_preset_options(0);
	add_dialog_str(0, "APPLIED BEHAVIOURAL PSYCHOLOGY",0);
	add_dialog_str(1, "_Introduction:",0);
	add_dialog_str(2, "Our aim in this textbook is to provide a practical grounding in basic psychological techniques.",0);
	add_dialog_str(3,  "After reading it, you should be able to understand how people's actions are affected by their motivations, and how these motivations can be affected, both in laboratory and real-life situations.",0);
	add_dialog_str(4, "For example, although someone sitting in a comfortable chair at home would likely be willing to read for pleasure, the same is unlikely to be true of someone in danger of his life or someone with an important task to do.",0);
	add_dialog_str(5, "This textbook is intended as a companion volume to 'Theoretical Behavioural Psychology' by the same authors._",0);
	run_dialog(1);
break;