begintownscript;
variables;
short choice;
short i,erase;
short strip,which_loc;
short tick,counter = 0;

body;
beginstate init_state;
set_terrain(53,53,0);
i = 0;
while(char_ok(i) == 0){
	i = i + 1;
	}
while(get_flag(255,1) > 0){
	alter_stat(i,0,1);
	inc_flag(255,1,-1);
}
if(get_flag(5,7) == 0){
	set_terrain(31,51,0);
	set_terrain(31,53,0);
	set_terrain(33,50,0);
	set_terrain(33,52,0);
	set_terrain(33,54,0);
	set_terrain(35,51,0);
	set_terrain(35,53,0);
}

else
	activate_hidden_group(1);
if(get_flag(6,8) > 0){
	erase_char(6);
	erase_char(9);
	erase_char(10);
}
if(get_flag(5,0) > 0)
	turn_off_training(1);
else
	revive_party();
break;

beginstate start_state;
if((get_flag(6,11) == 0) && (num_chars_in_group(1) == 0)){
	set_flag(6,11,1);
	reset_dialog();
	add_dialog_str(0,"As the last goblin falls dead, you finally get to take a good look at this herb they are abusing. You cross over to a prone goblin and examine a blue sprig it holds in its hands.",0);
	add_dialog_str(1,"The herb isn't completely unfamiliar. It has the same leaf shape as nightshade, and apparently similar mind altering properties.",0);
	add_dialog_str(2,"However, the leaf is of a strange blue hue. No doubt a different strain of nightshade, which would explain how the lowland plant could grow up here.",0);
	add_dialog_str(3,"You pocket it, if only to better examine it later. Consuming unkown herbs, especially one which has such apparently potent effects, would not be advisable. But you never know, at least you know a few recipes for lowland nightshade.",0);
	add_dialog_choice(0,"OK");
	choice = run_dialog(1);
	reward_give(475);
	set_flag(250,6,1);
}
if((get_flag(6,4) == 0) && (num_chars_in_group(3) == 0)){
	message_dialog("As the last of the burly goblins falls, it drops a ring of keys. You cross over to pick it up, noticing as you do that an open chest nearby holds some items that seem familiar to you....","");
	set_flag(6,4,1);
	change_spec_item(3,1);
}
if((num_chars_in_group(2) == 0) && (get_flag(6,22) == 0)){
	set_flag(6,22,1);
	message_dialog("The last goblin falls dead, but you have no time for breathers. The others sprint towards the exit shaft; Orrin stoops to pick up Ainsley then follows. He stops at the entrance, _Vincent, come on! They'll be on us any moment!_","You sprint after him.");
	if(counter > 20)
		counter = 20;
	erase = 61;
	while(erase <= 67){
		erase_char(erase);
		erase = erase + 1;
	}
	erase = 6;
	while(erase <= 119){
		if(get_attitude(erase) != 3)
			erase_char(erase);
		erase = erase + 1;
	}
	award_party_xp(400,15);
}
if(counter > 0){
	if((counter == 8) && (get_flag(6,22) == 0))
		message_dialog("You hear the sound of pounding feet as goblins hurry throughout the warren searching for help. No doubt the fact that all their fellows are intoxicated is slowing down reaction time, but you'll be overwhelmed soon if you don't hurry.","");
	if((counter == 16) && (get_flag(6,22) == 0))
		message_dialog("It seems that the news has spread through the goblin colony, and slowly the fiends are shaking off their stupor to come kill some humans. You hear running footsteps.","");
	if((counter >= 25)){
		message_dialog("Goblins are not particularly strong creatures, but when an entire colony is fighting a band of seven men the outcome is fairly certain.","Regrettably, even you can't overcome those odds. The swarm of goblins that storms out of the south passage quickly overwhelms you and your friends.");
		kill_char(i,2,0);
	}
	counter = counter + 1;
}

break;

beginstate exit_state;
break;

beginstate 10;
if(get_flag(5,7) > 0){
	force_view_center(26,47);
	reset_dialog();
	add_dialog_str(0,"You lay on your mat by the smokey fire, and close your eyes. Your muscles burn with freezing cold and weariness, and your eyes feel like leaden weights hang from them.",0);
	add_dialog_str(1,"This cave smells a lot better than the last place you slept, even if it is a bit smokey. There is a musty smell that occasionally reaches your nose, but it fades away as quickly as it comes leaving you with only a fuzzy memory you can't identify.",0);
	add_dialog_str(2,"It takes you a while to find a position where a rock isn't jabbing into one of your soar muscles, but you finally do find a comfortable position.",0);
	add_dialog_str(3,"A blunt object suddenly crashing into your skull saves you the trouble of falling asleep. You collapse into darkness, the last thing you hear is a cry of alarm before you completely lose consciousness.",0);
	add_dialog_choice(0,"OK");
	choice = run_dialog(1);
	play_sound(72);
	play_sound(29);
	set_flag(5,1,1);
	take_all_of_item(455);
	which_loc = 0;
	strip = 40;
	while(strip >= 0){
		if(item_type_in_slot(i,strip) > 0){
			if(which_loc == 0)
				take_item_char_item(i,strip,20,56);
			if(which_loc == 1)
				take_item_char_item(i,strip,3,51);
			if(which_loc == 2)
				take_item_char_item(i,strip,6,37);
			if(which_loc == 2)
				which_loc = 0;
			else
				which_loc = which_loc + 1;
		}
		strip = strip - 1;
	}
	set_flag(6,23,1);
	move_to_new_town(5,58,3);
}
break;

beginstate 11;
if((get_flag(6,0) == 0) && (get_flag(5,7) > 0)){
	set_flag(6,0,1);
	message_dialog("Your legs nearly give out as you step into the shelter of the cave. It seems the same thing happened to your comrades, all of whom sit by the fire as if they collapsed when their legs turned to jelly.","You don't have much time to rest, but any time spent out of the wind and resting by a hot fire is time spent well. You just dread how much worse it'll be when you have to get up and march again.");
}
break;

beginstate 12;
if(get_flag(5,7) > 0){
	block_entry(1);
	message_dialog("You turn away from the howling wind outside to take refuge inside the cave. Your muscles scream for rest and your body for warmth, there is nothing for you outside right now, and if you don't rest now you'll be of no use to the group later.","");
}
else
	move_to_new_town(5,12,49);
break;

beginstate 13;
message_dialog("The memory of the Beast's slavering jaws straining at the opening above is too fresh in your memory, you would have to be insane to climb up there.","The Beast is far too massive to fit through the tiny opening, and even its great strength is not enough to tear through rock, so you are safe down here. Safe of course is used in relative terms-- you ARE in a goblin lair.");
break;

beginstate 14;
if(get_flag(6,8) == 0){
	set_flag(6,8,1);
	reset_dialog();
	add_dialog_str(0,"You reach the bottom of the narrow tunnel. It is carved into the rock wall just wide enough for a hobgoblin to walk through, the Beast could never fit through here-- you had to almost crawl just to fit through and got plenty dirty in the process.",0);
	add_dialog_str(1,"Orrin, Evrey, and Fabian got off no better, but at least they are all alive. _Cut it a bit close, don't you think?_ Fabian was just saying as you entered.",0);
	add_dialog_str(2,"Orrin shushes him and motions you over, _Keep your voices down, we're in a goblin lair you fool._ Fabian grins sheepishly and keeps silent, Orrin continues, _Where are the others? What can you tell us of this place?_",0);
	add_dialog_str(3,"You tell him what you know, which is very little. _So they're having some kind of feast, eh? Perhaps we can get through here with minimal fighting._",0);
	add_dialog_str(4,"_We have the element of surprise, they'll be in either a drunken stupor or drug induced rage. I think they'll be surprised to find their sacrifices have taken up arms against them._ He grins wolfishly.",0);
	add_dialog_str(5,"_You two have no weapons for now, so Evrey and I will have to do most of the fighting. Here, take this._ He hands you a torch, _It's too cramped for everybody to fight at once, so Evrey and Fabian will take the rear._",0);
	add_dialog_str(6,"_Now lets find Burden and the others. You don't have the slightest idea where they are?_ You shrug apologetically. _Oh well, we'll have to wander blindly then. Everybody stay close._ (Orrin has joined the party)",0);
	add_dialog_choice(0,"OK");
	choice = run_dialog(1);
	add_char_to_party(54);
	erase_char(6);
	erase_char(9);
	erase_char(10);
	reward_give(498);
	reward_give(498);
	move_to_new_town(6,char_loc_x(i),char_loc_y(i));
}
break;

beginstate 15;
if(get_flag(6,9) == 0){
	set_flag(6,9,1);
	message_dialog("You step into the goblins' warg kennels, a filthy place where the scent of raw meat is so thick you can almost taste it, and the barks of the huge canines is so loud you can hardly think.","The disgusting beasts scrabble over scraps of food, a wonder these nearly feral creatures are willing to carry their masters. You know you wouldn't want to be on the other side of the ceiling-high fences.");
}
break;

beginstate 16;
	message_dialog("The hobgoblins keep crude ledgers here on the raising and breeding of wargs. Most of the information describes how to beat the animals and what types of rancid meat are best for specific ages.","No wonder the creatures are so ferocious, it seems they live in total fear of their hobgoblin riders, and complete hatred for everything else living.");
break;

beginstate 17;
if(get_flag(6,10) == 0){
	set_flag(6,10,1);
	reset_dialog();
	add_dialog_str(0,"The rowdiness and brawling that filled the dining hall is gone now, although evidence of it is apparent in the chaotic appearance of the room. Furniture is strewn all about the room, and the floor is covered in blood and unconscious goblins.",0);
	add_dialog_str(1,"Several goblins remain behind to 'clean up.' Their method seems to be to rob the unconscious goblins, and lap up any alcohol that is spilled on the floor.",0);
	add_dialog_str(2,"When they spot you they stare in disbelief, expecting you to turn out to be halucinations. Eventually they decide to play it safe by killing you.",0);
	add_dialog_choice(0,"OK");
	choice = run_dialog(1);
}
break;

beginstate 18;
block_entry(1);
message_dialog("The sound of raucous revelry, shouting, fighting, and general mayhem comes from further down this tunnel. From the sound of it, most of the tribe is in the cavern ahead, which is reason enough why you should avoid it.","");
break;

beginstate 19;
if(get_flag(6,1) == 0){
	set_flag(6,1,1);
	message_dialog("You step into what must be a.... laboratory? As hard as that is to imagine from these uncivilized creatures, that is what this stone room seems to be.","The scent of herbs makes you sneeze. You notice in particular the irritating, acrid smell of nightshade.");
}
break;

beginstate 20;
if(get_flag(6,2) == 0){
	set_flag(6,2,1);
	message_dialog("Private quarters must be quite a luxury in the goblins' cramped warren. You wonder which goblins are deemed worthy of this extravagance, perhaps a chief or shaman?","It seems that the owners of these rooms don't even know what to do with the personal space, there is a sleeping mat and the standard layer of filth covering the ground, but little else.");
}
break;	

beginstate 21;
if(get_flag(6,3) == 0){
	set_flag(6,3,1);
	message_dialog("A small herb garden grows here. All the plants are fungi or other strains that thrive in dark places. You notice that all the nightshade plants are harvested thoroughly, no doubt in preparation for tonight's festivities.","");
}
break;

beginstate 22;
reset_dialog();
add_dialog_str(0,"The hobgoblin shamans have been doing extensive research on the properties of nightshade, apparently an important aspect of their culture and religion. The results of which are on these shelves.",0);
add_dialog_str(1,"They write that consuming the plant can cause long term central nervous system damage, and death by respiratory failure. Apparently this is overcome by only scheduling festivals at rare intervals.",0);
add_dialog_str(2,"The way that the herb is used in battle is by instead brewing it into a paste, and painting the body with it. The lower levels of toxin absorbed into the blood leaves the warrior with a thirst for blood, but no halucinations or nerve damage.",0);
add_dialog_str(3,"Well the goblins didn't say it in so many words. It was more like, _Eat gore-grass on not festival-day will stop life-breath. Much concern over end use...... Rub on paint will equal much blood party! Hurray!_",0);
add_dialog_str(4,"You can figure out the science side of it for yourself. You note the recipe for the paints.",0);
add_dialog_choice(0,"OK");
choice = run_dialog(1);
set_flag(240,2,1);
break;

beginstate 23;
if(get_flag(6,5) == 0){
	set_flag(6,5,1);
	message_dialog("You step into the hobgoblins' filthy kitchen and promptly lose your appetite. You've eaten in some grimy taverns in your years as a soldier, and sometimes you've half expected the establishments' kitchens to look like this.","But the goblins takes the prize. The meat is unidentifiable and rancid to boot. Garbage and waste is strewn around, often finding it's way into the food. You must commend the goblins, they managed to commit every health code violation in Aizo.");
}
break;

beginstate 24;
if(get_flag(6,12) == 0){
	set_flag(6,12,1);
	inc_flag(6,6,1);
	message_dialog("You find some of your equipment stashed away in this chest, along with other unmentionables that the goblins thought valuable enough to keep under lock.","Maybe in a few years this gear will have aired out enough so that you don't have to cringe when you put it on, for now you'll just hold your nose.");
}
break;

beginstate 25;
if(get_flag(6,13) == 0){
	set_flag(6,13,1);
	inc_flag(6,6,1);
	message_dialog("You find some of your equipment stashed away in this chest, along with other unmentionables that the goblins thought valuable enough to keep under lock.","Maybe in a few years this gear will have aired out enough so that you don't have to cringe when you put it on, for now you'll just hold your nose.");
}
break;

beginstate 26;
if(get_flag(6,14) == 0){
	set_flag(6,14,1);
	inc_flag(6,6,1);
	message_dialog("You find some of your equipment stashed away in this chest, along with other unmentionables that the goblins thought valuable enough to keep under lock.","Maybe in a few years this gear will have aired out enough so that you don't have to cringe when you put it on, for now you'll just hold your nose.");
}
break;

beginstate 27;
message_dialog("What the hell is this?","");

break;

beginstate 28;
if(get_flag(6,18) == 0){
	activate_hidden_group(3);
	set_char_dialogue_pic(57,305,0);
}
if(get_flag(6,15) == 0){
	set_flag(6,15,1);
	inc_flag(6,18,1);
	set_flag(6,20,1);
	message_dialog("The door swings open on rusty hinges once you unlock it. You peer into the darkness within, and see the prone figure of Jamie lying facing the wall","It isn't until you call his name that he turns around and jumps to his feet. _Vincent! Orrin! Are the others here? I thought..._ You urge him to be silent, and lead him to the jailer's room.");
	activate_hidden_group(2);
	erase_char(51);
	set_char_dialogue_pic(56,306,0);
}
break;

beginstate 29;
if(get_flag(6,18) == 0){
	activate_hidden_group(3);
	set_char_dialogue_pic(57,305,0);
}
if(get_flag(6,16) == 0){
	set_flag(6,16,1);
	inc_flag(6,18,1);
	set_flag(6,20,1);
	message_dialog("Two of your companions inhabit this room, Adrianna and Captain Ainsley. When Adrianna realises that you aren't the hobgoblins she rushes to you.","_How did you escape? Oh forget it, come help me with Ainsley, he's gotten a lot worse and I don't think he can walk._ Orrin crosses the cell and picks up the feverish Captain, who is indeed a lot worse. They all file out of the cell.");
	erase_char(52);
	erase_char(53);
	activate_hidden_group(4);
	set_char_dialogue_pic(58,1959,0);
	set_char_dialogue_pic(59,1907,0);
}
break;

beginstate 30;
if(get_flag(6,18) == 0){
	activate_hidden_group(3);
	set_char_dialogue_pic(57,305,0);
}
if(get_flag(6,17) == 0){
	set_flag(6,17,1);
	inc_flag(6,18,1);
	set_flag(6,20,1);
	message_dialog("Sergeant Burden sits cross legged on the floor of her cell with her eyes closed. Beats lying down on the filthy floor to sleep. Her eyes snap open when you enter. A grin spreads slowly across her face.","_I knew I could count on you to bail us out, good work men. Have you got the others out of their cells yet?_ She marches out of the cell, clapping you on the back on the way out.");
	erase_char(50);
	activate_hidden_group(5);
	set_char_dialogue_pic(60,303,0);
}
break;

beginstate 31;
block_entry(1);
if(get_flag(6,21) > 0){
	if(get_flag(6,22) == 0)
		print_str_color("You have a fight to finish!",1);
	else
		print_str_color("Run you fool!",1);
	end();
}
reset_dialog();
add_dialog_str(0,"The room ahead is the site of some kind of goblin ceremony. Several shamans and what must be high ranking goblins have gathered to place offerings at the foot of a Beast statue, and to eat nightshade of course.",0);
add_dialog_str(1,"But more importantly is that at the other end of the room is a shaft from which you think you can see moonlight filtering through. You take a step forward but feel a tug at your sleeve.",0);
if(get_flag(6,18) < 3){
	add_dialog_str(2,"Orrin whispers, _Not yet! We can't leave until we find Burden and the rest. If we charge into that room we'll have the whole colony on our heels, and any chance of saving them is gone._ He's right. You turn back.",0);
	add_dialog_choice(0,"OK");
}
if((get_flag(6,18) >= 3) && (get_flag(6,6) < 3)){
	add_dialog_str(2,"Orrin whispers, _I know we're in a hurry, Vincent, but we can spare enough time for you to find the rest of your belongings. There's no point in running out in the snow without proper clothing._",0);
	add_dialog_choice(0,"No time for that!");
	add_dialog_choice(1,"Turn back.");
}
if((get_flag(6,18) >= 3) && (get_flag(6,6) >= 3)){
	add_dialog_str(2,"Orrin whispers, _You're sure you're ready? This is it, if we charge out there we won't have much time before the alarm is raised. We have to finish the goblins between us and the exit as fast as we can, then run like the wind away from here._",0);
	add_dialog_choice(0,"Yeah, I'm ready.");
	add_dialog_choice(1,"No, let's turn back.");
}
choice = run_dialog(1);
if((get_flag(6,18) < 3) || (choice == 2))
	end();
message_dialog("Orrin nods and draws his sword. Evrey and the rest follow his example. You silently count- 1...2...3! And on three everybody rushes out of the tunnel and down on the surprised goblins.","The goblins are certainly taken off guard, but it doesn't take long for them to turn their attention from beating on each other to beating on you. Mayhem ensues.");
set_level(23,18);
relocate_character(i,10,20);
erase_char(4);
erase_char(5);
activate_hidden_group(6);
force_view_center(10,20);
force_instant_terrain_redraw();
counter = 1;
set_flag(6,21,1);
break;

beginstate 32;
if((get_flag(6,22) == 0) || (is_combat() > 0)){
	block_entry(1);
	print_str_color("You have a fight to finish first!",1);
	end();
}
add_char_to_party(68);
move_to_new_town(7,7,7);
break;

beginstate 101;
//fabian
break;

beginstate 102;
//orrin
message_dialog("Orrin falls to the ground. It takes a lot to keep the highlander from a fight, but apparently he's hit his limit.","He falls back from the fighting, you'll have to handle the rest while he recovers.");
break;

beginstate 103;
//evrey
break;

beginstate 104;
//burden
break;

beginstate 105;
//the rest
break;