// SCENARIO SCRIPT

// This is the special script for your entire scenario. It contains
// special encounters and code accessable from anywhere in the scenario. it also
// contains the code that initializes important special things in the
// scenario (like shops and names and descriptions of special items).

// You can create your own states, but you should give all of them numbers greater than
// or equal to 10.

beginscenarioscript;

variables;
short choice,i,wholeft;
short level,levelmod,tick;
short difficulty,selection,exhaustion,hypothermia;
short xlim,ylim,targ,status,side_effect = 0;
string alchemy;

body;

// This is the state that is called every time the scenario is loaded,
// even when a save file in the scenario is loaded. Some things that should go here:
//    Names and descriptions of special items.
//    Names and effects of custom special abilities.
beginstate LOAD_SCEN_STATE;
i = 0;
while(char_ok(i) == 0){
	i = i + 1;
}
init_special_item(0,"Cryoprev","You found this vial of medicine in the research facilities beneath Amon Sul. It was developed to treat frostbite and hypothermia victims.");
init_special_item(1,"Fabian","Your friend has asked one last thing of you-- a quick death. Perhaps you can grant it to him.");
init_special_item(2,"Erasmus' Guide Book","Erasmus' guide book, the only thing you have to remember him by-- and your only map of the Rim as well.");
init_special_item(3,"Jailer's Key Ring","This ring of keys was on one of the hobgoblins. Each key fits a cell in their dungeon.");
init_special_item(4,"Firewood","Finding deciduous trees at these altitudes was no easy task, this fire had better be worth it.");

init_quest(0,"Scout Ahead","You and Fabian were asked to scout ahead for the expedition. You've heard from Burden and Rowly that there are wolves ahead, you should be cautious.");
init_quest(1,"Find Firewood","Sergeant Burden has asked you to find firewood. Pine wood burns too smokily, you'll have to search higher in the mountains for something that will burn cleaner.");
init_quest(2,"Escape the Goblin Lair","The sooner you get out of this stinking hobgoblin warren the better. First things first, find Burden and the others.");
init_quest(3,"Find Survival Supplies","Somewhere in this cellar there must be supplies-- you hope so at least.");

	init_special_abil(0,"Do Alchemy",10);
	init_special_abil(1,"The Way Out",108);
	init_special_abil(2,"Current Status",53);
	init_special_abil(3,"Prefabricate Party",13);
	break;

// This is the state that is called only once at the very beginning of 
// the scenario. Some things that should go here:
//    The stuff in shops.
//    Creating horses and boats.
beginstate START_SCEN_STATE;
change_custom_abil_uses(i,1,1);
force_start_day(-1);
i = 0;
wholeft = 0;
while(char_ok(i) == 0){
	i = i + 1;
}
while(wholeft <= 3){
	levelmod = 39;
	if((char_ok(wholeft) == 1) && (wholeft != i)){
		while(levelmod >= 0){
			destroy_char_item(wholeft,levelmod);
			levelmod = levelmod - 1;
		}
		if(wholeft != i)
			erase_char(wholeft);
	}
	wholeft = wholeft + 1;
}
set_name(i,"Vincent");
	change_custom_abil_uses(i,3,1);
	change_custom_abil_uses(i,2,52);
	reset_dialog();
	add_dialog_str(0,"The Rim. Mentioning the name of Aizo's highest mountain range calls two things to mind; one being the freezing temperatures and biting winds that will turn a man's blood to ice in an hour, it seems every week some hunter meets his death here.",0);
	add_dialog_str(1,"Sitting in camp about a third way up the mountain, nearly four thousand feet above sea level, you are beginning to feel why. The air is thin and it is hard to catch your breath. The wind is biting and cuts right through your heavy jacket.",0);
	add_dialog_str(2,"No sane person would come here voluntarily, but no matter how harsh the conditions are in an area, there are always some lunatics that make it their home.",0);
	add_dialog_str(3,"You wouldn't believe it if you hadn't passed through a small sheepherding village, Manibor, on the way here.",0);
	add_dialog_str(4,"This village may not show up on your household map, but it is the reason you are here. That and, of course, the second thing that most people think of when they hear about the Rim.",0);
	add_dialog_choice(0,"Ok");
	choice = run_dialog(1);

	reset_dialog();
	add_dialog_str(0,"Not all the disappearing hunters are caused by the cold, at least that's what a highlander would have you think. They call them beasts of the rim. They vary in shape and name from report to report, but are always called deadly.",0);
	add_dialog_str(1,"Regardless of what you call them, they are naught but fairy tales back in the warm air and sunshine of civilized lands. Here on the slopes of Mount Spire this threat is all too real. Real enough to send a military team to deal with.",0);
	add_dialog_str(2,"Captain Ainsley headed that team; a team comprised of some old friends from Empire Unit 341; as well as some hitherto strangers. The team was sent out to Manibor; the speck on the map that anybody in his right mind would avoid if he could.",0);
	add_dialog_str(3,"You were relaxing in Stonehurst when Ainsley rounded up you and the rest of your unit. You asked him what it was that took you from the tavern music and sunny beaches where you should be spending your summer.",0);
	add_dialog_str(4,"He responded, _We leave to hunt the Beast of the Rim._ You laughed, so did Fabian and Marie. He wasn't joking.",0);
	add_dialog_str(5,"Now you hold your numb hands to the fire. There is nothing sunny about the Rim, the only music is the howling of the wolves, and the only beach is a small half frozen creek on the bank of which your camp is pitched.",0);
	add_dialog_choice(0,"Ok");
	choice = run_dialog(1);

	large_draw_pic_dialog(401,"Your name is Vincent Graff. This is the story of how you became a myth.");

	reset_dialog();
	add_dialog_str(0,"Scenario by Lazarus. Contact me at mcleod989@yahoo.com with bug reports, comments, and concerns.",0);
	add_dialog_str(1,"The suggested level for this scenario is level 15. To make an appropriate character, use your ability _Prefab Party,_ which will set your skills and level appropriately. Please see the README for information on this and other topics.",0);
	add_dialog_str(2,"A singleton party is required. If you enter with more than one character your party will be cut down to one. Your other characters will be killed in the process, so you should come with the right party if you don't want this to happen.",0);
	add_dialog_str(3,"Enjoy",100);
	add_dialog_choice(0,"Ok");
	choice = run_dialog(1);

break;

// This state is called every tick wherever the party is in the scenario.
// You can use the set_state
beginstate START_STATE;
if(get_flag(255,6) > 0)
	inc_flag(255,6,-1);
if(get_flag(8,0) > 0)
	set_flag(254,6,0);
if(get_flag(254,7) > 0){
	levelmod = 1;
	while(levelmod > 0){
		if((get_flag(254,7) == 0) || (get_flag(254,2) == 0))
			levelmod = 0;
		else{
			inc_flag(254,2,-1);
			inc_flag(254,7,-1);
		}
	}
}
if(get_flag(254,6) > 0){
	levelmod = 1;
	while(levelmod > 0){
		if((get_flag(254,6) == 0) || (get_flag(254,0) == 0))
			levelmod = 0;
		else{
			inc_flag(254,0,-1);
			inc_flag(254,6,-1);
		}
	}
}				

inc_flag(254,5,1);
if(get_flag(254,5) >= 100){
	set_ticks_forward(-100);
	inc_flag(254,5,-100);
}
if(side_effect > 0){
	side_effect = side_effect + 1;
	if((get_flag(255,3) == 1) && (side_effect >= 6)){
		message_dialog("Things were going fairly well, at least as well as a drug induced berserk rage can be expected to go, but as the drug departs your body it leaves you feeling weak and shaky.","Your heart still races a mile a minute, and it feels as though it's pumping molten metal through your body. You scream, not in fury or battle lust, but in agony.");
		play_sound(3);
		set_flag(255,4,0);
		side_effect = 0;
		set_char_status(i,0,50,1,0);
		set_char_status(i,12,30,1,0);
		set_char_status(i,3,-10,1,0);
		set_char_status(i,1,-10,1,0);
}
	if((get_flag(255,3) == 2) && (side_effect >= 9)){
		message_dialog("This time the effects of the herb don't depart quite as rapidly, or as violently. You are still left with racing heart, distorted vision, and the occasional stab of headache, but you don't feel like your body is on fire this time.","Maybe you're building up a tolerance for the stuff.");
		play_sound(3);
		set_flag(255,4,0);
		side_effect = 0;
		set_char_status(i,3,-15,1,0);
		set_char_status(i,1,-15,1,0);	
	}
	if((get_flag(255,3) == 3) && (side_effect >= 11)){
		message_dialog("The bloodlust seems to be fading, leaving you with a bit disoriented. However the feeling of vertigo soon passes, and you remain standing.","Your hands shake, and you feel light headed. As your heart beat slows down to a usual pace, that too fades.");
		play_sound(3);
		set_flag(255,4,0);
		side_effect = 0;
		set_char_status(i,3,-10,1,0);
		set_char_status(i,1,-10,1,0);	
	}
	if((get_flag(255,3) == 4) && (side_effect >= 11)){
		reset_dialog();
		add_dialog_str(0,"Coming down from the battle rage felt like landing on a feather pillow last time, this time you feel like you landed on jagged rocks, and somebody threw some sacks of lead down to land on you.",0);
		add_dialog_str(1,"The spinning room knocks you to your knees. You struggle to stand and catch your breath, but both seem impossible. Your surroundings which were once so fearful remain so, but now your courage has departed along with the nightshade.",0);
		add_dialog_str(2,"All the wounds you had sustained hit you at once, as you finally become aware of them. You pant and gasp, and clutch your sword with trembling hands, a shadow of the terrible warrior you once were.",0);
		add_dialog_str(3,"The thudding of your heart echoes like a drum in your head, you feel as if you are about to faint. Only sheer terror keeps you somehow standing, but you are so weak you can hardly lift your arms.",0);
		add_dialog_choice(0,"OK");
		choice = run_dialog(1);
		play_sound(3);
		set_flag(255,4,0);
		side_effect = 0;
		set_char_status(i,3,-15,1,0);
		set_char_status(i,1,-15,1,0);	
		set_char_status(i,20,8,1,0);
		set_char_status(i,21,8,1,0);
	}
	if((get_flag(255,3) == 5) && (side_effect >= 13)){
		reset_dialog();
		add_dialog_str(0,"Suddenly the whirling dervish is struck down, not by the foes who were powerless to lay a finger on him but by the very elixir that granted him his strength.",0);
		add_dialog_str(1,"The blow of the nightshade leaving your blood leaves you feeling empty. Soon something comes to fill that emptiness- pain.",0);
		add_dialog_str(2,"You writhe on the ground in agony, blind to the world around you and unable to even feel the ground you've collapsed on, your nerves carry only one message to your traumatized brain- fiery pain.",0);
		add_dialog_str(3,"You can't think, can't breathe. The only sensation aside from mind numbing pain is the sound of your heart, racing a mile a minute. You are suffocating, you struggle for air but nothing comes. Your lungs are about to explode. Only pain.",0);
		add_dialog_str(4,"Then it passes as quickly as it came, leaving you gasping for breath gratefully. You are drenched in sweat and can't even stand, your chest heaves and you feel like your heart is about to explode-- but you're alive.",0);
		add_dialog_str(5,"Laying there you close your eyes, silently vowing to never eat that herb again. Then you shakily stand.",0);
		add_dialog_choice(0,"OK");
		choice = run_dialog(1);
		play_sound(3);
		damage_char(i,get_health(i),6);
		set_flag(255,4,0);
		side_effect = 0;
		set_char_status(i,0,150,1,0);
		set_char_status(i,1,-25,1,0);
		set_char_status(i,1,-25,1,0);
		set_char_status(i,3,-25,1,0);
		set_char_status(i,12,100,1,0);	
		set_char_status(i,11,1,0,1);
		set_char_status(i,18,10,0,1);
		set_char_status(i,13,10,1,1);
		set_char_status(i,21,10,1,0);
	}
}
inc_flag(254,0,1);
inc_flag(254,2,1);
if(is_combat() == 1){
	inc_flag(254,2,2);
	inc_flag(254,0,-1);
}
if((get_terrain(char_loc_x(i),char_loc_y(i)) >= 427) && (get_terrain(char_loc_x(i),char_loc_y(i)) <= 441)){
	inc_flag(254,0,2);
	inc_flag(254,2,1);
	inc_flag(254,4,1);
	if((get_ran(1,0,25 - get_flag(254,4)) == 0) && (get_char_status(i,6) < 5)){
		set_char_status(i,6,1,1,1);
		set_flag(254,4,0);
	}
}
if(current_town() == 1){
	set_flag(254,2,0);
	set_flag(254,0,0);
	set_flag(254,1,0);
	set_flag(254,3,0);
}
if((current_town() == 3) && (get_flag(3,5) > 0)){
	set_flag(254,2,0);
	set_flag(254,0,0);
	set_flag(254,1,0);
	set_flag(254,3,0);
}
if(get_flag(6,23) > 0){
	set_flag(254,2,0);
	set_flag(254,0,0);
	set_flag(254,1,0);
	set_flag(254,3,0);
}
if((get_flag(9,11) == 0) && (current_town() == 9)){
	inc_flag(254,2,2);
	inc_flag(254,0,2);
}
if(get_flag(9,12) > 0){
	set_flag(254,0,0);
	set_flag(254,1,0);
	if(get_flag(8,5) == 0)
		end();
	if(get_flag(254,2) >= 35){
		if(has_item(455) > 0){
			take_item(455);
			play_sound(-6);
			print_str_color("You eat a piece of hardtack.",4);
		}
		else{
			damage_char(i,get_ran(1,10,20),1);
			print_str_color("It feels like the heat is burning you up!",4);
		}
		inc_flag(254,2,-35);
		end();
	}
}
if((get_flag(254,0) > 65) && (get_flag(254,1) >= 5)){
	damage_char(i,get_ran(2,1,10),5);
	inc_flag(254,0,-65);
	inc_flag(254,1,1);
	print_str_color("You are freezing!",4);
}
if((get_flag(254,0) > 75) && ((get_flag(254,1) == 4) || (get_flag(254,1) == 3))){
	damage_char(i,get_ran(2,1,9),5);
	inc_flag(254,0,-75);
	inc_flag(254,1,1);
	print_str_color("Your limbs are growing numb.",4);
}
if((get_flag(254,0) > 90) && ((get_flag(254,1) == 2) || (get_flag(254,1) == 1))){
	damage_char(i,get_ran(2,1,8),5);
	inc_flag(254,0,-90);
	inc_flag(254,1,1);
	print_str_color("You are very cold.",4);
}
if((get_flag(254,0) > 100) && (get_flag(254,1) == 0)){
	damage_char(i,get_ran(2,1,6),5);
	inc_flag(254,0,-100);
	inc_flag(254,1,1);
	print_str_color("The cold is beginning to get to you.",4);
}

if((get_flag(254,2) > 73) && (get_flag(254,3) >= 6)){
	damage_char(i,get_ran(2,1,5),5);
	set_char_status(i,3,-5,1,1);
	inc_flag(254,2,-73);
	inc_flag(254,3,1);
	print_str_color("You are exhausted to the point of collapse.",4);
}
if((get_flag(254,2) > 83) && ((get_flag(254,3) == 5) || (get_flag(254,3) == 4))){
	set_char_status(i,3,-4,1,1);
	inc_flag(254,2,-83);
	inc_flag(254,3,1);
	print_str_color("You are exhausted.",4);
}
if((get_flag(254,2) > 93) && (get_flag(254,3) == 3)){
	set_char_status(i,3,-3,1,1);
	inc_flag(254,2,-93);
	inc_flag(254,3,1);
	print_str_color("You are growing tired.",4);
}
if((get_flag(254,2) > 123) && (get_flag(254,3) == 2)){
	set_char_status(i,3,-2,1,1);
	inc_flag(254,2,-123);
	inc_flag(254,3,1);
	print_str_color("You are growing tired.",4);
}
if((get_flag(254,2) > 153) && (get_flag(254,3) <= 1)){
	set_char_status(i,3,-1,1,1);
	inc_flag(254,2,-153);
	inc_flag(254,3,1);
	print_str_color("You are beginning to grow weary.",4);
}
break;

// Place your own states below. Give each a number at least 10.
beginstate 10;
//Alchemy- Recipes book.
change_custom_abil_uses(i,0,1);
reset_dialog();
add_dialog_str(0,"Recipe Book",140);
add_dialog_str(1,"You've compiled a fairly extensive list of alchemical recipes that have proven useful during your soldiering. You have pages of recipes at your disposal, the majority of which will be of no use to you in the Rim, where herbs are scarce.",0);
add_dialog_str(2,"You do, however, have some recipes using herbs native to cold regions. You currently know how to brew:",0);

add_dialog_str(3,"Available Recipes",150);
clear_buffer();
append_string("1:Healing Poultice, 2:Strength Potion, 3:Potion of Alacrity, 4:Rejuvenation Elixir, 5:Hardiness Philter, 6:Dispel Magic, 7:Choking Dust, 8:Frost Grenade, ");
if(get_flag(240,1) > 0)
	append_string("9:Fire Draught, ");
else
	append_string("9:??? ");
if(get_flag(240,2) > 0)
	append_string("10:Battle Paint ");
else
	append_string("10:??? ");
if(get_flag(240,5) > 0)
	append_string("11:Panacea.");
else
	append_string("11:???");
get_buffer_text(alchemy);
add_dialog_str(4,alchemy,0);

add_dialog_choice(0,"Brew A Potion");
add_dialog_choice(1,"Next Page");
add_dialog_choice(2,"Close Book");
choice = run_dialog(1);
if(choice == 3)
	end();
if(choice == 2)
	set_state_continue(21);

selection = -1;
get_text_response("What potion?");
check_text_response_match("healing");
if(got_text_match() == 1)
	selection = 1;
check_text_response_match("healing poultice");
if(got_text_match() == 1)
	selection = 1;
check_text_response_match("1");
if(got_text_match() == 1)
	selection = 1;
check_text_response_match("strength");
if(got_text_match() == 1)
	selection = 2;
check_text_response_match("strength potion");
if(got_text_match() == 1)
	selection = 2;
check_text_response_match("2");
if(got_text_match() == 1)
	selection = 2;
check_text_response_match("alacrity");
if(got_text_match() == 1)
	selection = 3;
check_text_response_match("potion of alacrity");
if(got_text_match() == 1)
	selection = 3;
check_text_response_match("3");
if(got_text_match() == 1)
	selection = 3;
check_text_response_match("rejuvenation");
if(got_text_match() == 1)
	selection = 4;
check_text_response_match("rejuvenation elixir");
if(got_text_match() == 1)
	selection = 4;
check_text_response_match("rejuve");
if(got_text_match() == 1)
	selection = 4;
check_text_response_match("4");
if(got_text_match() == 1)
	selection = 4;
check_text_response_match("hardiness");
if(got_text_match() == 1)
	selection = 5;
check_text_response_match("philter");
if(got_text_match() == 1)
	selection = 5;
check_text_response_match("hardiness philter");
if(got_text_match() == 1)
	selection = 5;
check_text_response_match("5");
if(got_text_match() == 1)
	selection = 5;
check_text_response_match("dispel");
if(got_text_match() == 1)
	selection = 6;
check_text_response_match("dispel-magic potion");
if(got_text_match() == 1)
	selection = 6;
check_text_response_match("6");
if(got_text_match() == 1)
	selection = 6;
check_text_response_match("choking");
if(got_text_match() == 1)
	selection = 7;
check_text_response_match("choking dust");
if(got_text_match() == 1)
	selection = 7;
check_text_response_match("dust");
if(got_text_match() == 1)
	selection = 7;
check_text_response_match("7");
if(got_text_match() == 1)
	selection = 7;
check_text_response_match("frost");
if(got_text_match() == 1)
	selection = 8;
check_text_response_match("frost grenade");
if(got_text_match() == 1)
	selection = 8;
check_text_response_match("grenade");
if(got_text_match() == 1)
	selection = 8;
check_text_response_match("8");
if(got_text_match() == 1)
	selection = 8;
if(get_flag(240,1) > 0){
check_text_response_match("draught");
if(got_text_match() == 1)
	selection = 9;
check_text_response_match("fire draught");
if(got_text_match() == 1)
	selection = 9;
check_text_response_match("fire");
if(got_text_match() == 1)
	selection = 9;
check_text_response_match("9");
if(got_text_match() == 1)
	selection = 9;
}
if(get_flag(240,2) > 0){
check_text_response_match("war");
if(got_text_match() == 1)
	selection = 10;
check_text_response_match("war paints");
if(got_text_match() == 1)
	selection = 10;
check_text_response_match("war paint");
if(got_text_match() == 1)
	selection = 10;
check_text_response_match("paint");
if(got_text_match() == 1)
	selection = 10;
check_text_response_match("paints");
if(got_text_match() == 1)
	selection = 10;
check_text_response_match("10");
if(got_text_match() == 1)
	selection = 10;
}
if(get_flag(240,5) > 0){
check_text_response_match("panacea");
if(got_text_match() == 1)
	selection = 11;
check_text_response_match("11");
if(got_text_match() == 1)
	selection = 11;
}
check_text_response_match("end");
if(got_text_match() == 1)
	end();
if(selection <= 0){
	message_dialog("That is not a valid recipe hotkey. Remember, you can jump to a potion's page by typing it's number, its name, or some selected hotkeys. For example, 'Rejuvenation Elixir' also accepts 'rejuvenation', 'rejuve', and '4'.","If you don't know what potion you want to make you can flip through the book using the 'Next Page' selection. If you want to do nothing select 'Close Book' or type 'End' in the potion selection box.");
	set_state_continue(10);
}
set_state_continue(20 + selection);
break;

beginstate 21;
//Healing Poultice//
difficulty = 2;
	difficulty = difficulty - 1;
reset_dialog();
add_dialog_str(0,"Potion 1: Healing Poultice",0);
add_dialog_str(1,"Herbs Required: Mountain Holly",0);
add_dialog_str(2,"Difficulty: 2",0);
add_dialog_str(3,"Description: A simple healing poultice using the healing properties of holly berries. Can quickly seal a wound to prevent blood loss, and gives relief so one can fight undistracted.",0);
add_dialog_choice(0,"Brew this potion");
add_dialog_choice(1,"Next Page");
add_dialog_choice(2,"Close Book");
choice = run_dialog(1);
if(choice == 3)
	end();
if(choice == 2)
	set_state_continue(22);
if(has_item(471) == 0)
	set_state_continue(99);
take_item(471);
if(get_ran(1,0,difficulty) > get_stat(i,14))
	set_state_continue(100);
play_sound(8);
print_str_color("Making Potion: Successful!",3);
reward_give(485);
break;

beginstate 22;
//Curing Salve//
difficulty = 2;
if(has_item(456) > 0)
	difficulty = difficulty - 1;
reset_dialog();
add_dialog_str(0,"Potion 2: Strength Potion",0);
add_dialog_str(1,"Herbs Required: Frost Shrooms",0);
add_dialog_str(2,"Difficulty: 4",0);
add_dialog_str(3,"Description: Potion that stimulates brain activity, causing faster reflexes, and greater precision and accuracy.",0);
add_dialog_choice(0,"Brew this potion");
add_dialog_choice(1,"Next Page");
add_dialog_choice(2,"Close Book");
choice = run_dialog(1);
if(choice == 3)
	end();
if(choice == 2)
	set_state_continue(23);
if(has_item(472) == 0)
	set_state_continue(99);
take_item(472);
if(get_ran(1,0,difficulty) > get_stat(i,14))
	set_state_continue(100);
play_sound(8);
print_str_color("Making Potion: Successful!",3);
reward_give(486);
break;

beginstate 23;
//Potion of Alacrity//
difficulty = 5;
if(has_item(456) > 0)
	difficulty = difficulty - 1;
reset_dialog();
add_dialog_str(0,"Potion 3: Potion of Alacrity",0);
add_dialog_str(1,"Herbs Required: Icicle Moss, Frost Shrooms",0);
add_dialog_str(2,"Difficulty: 5",0);
add_dialog_str(3,"Description: Gives the user a powerful jolt of energy, using the stimulant properties of icicle moss. Reaction is tempered using frost shrooms to decrease chance of hyperactivity and heart failure. This thing puts Red Bull to shame.",0);
add_dialog_choice(0,"Brew this potion");
add_dialog_choice(1,"Next Page");
add_dialog_choice(2,"Close Book");
choice = run_dialog(1);
if(choice == 3)
	end();
if(choice == 2)
	set_state_continue(24);
if((has_item(472) == 0) || (has_item(470) == 0))
	set_state_continue(99);
take_item(470);
take_item(472);
if(get_ran(1,0,difficulty) > get_stat(i,14))
	set_state_continue(100);
play_sound(8);
print_str_color("Making Potion: Successful!",3);
reward_give(487);
break;

beginstate 24;
//Rejuvenation Potion//
difficulty = 5;
if(has_item(456) > 0)
	difficulty = difficulty - 1;
reset_dialog();
add_dialog_str(0,"Potion 4: Rejuvenation Elixir",0);
add_dialog_str(1,"Herbs Required: Icicle Moss, Mountain Holly",0);
add_dialog_str(2,"Difficulty: 5",0);
add_dialog_str(3,"Description: Powerful healing. Like the healing poultice, it relies on the properties of holly for its power; however, unlike the poultice one adds a catalyst to increase the rejuvenation elixir's potency.",0);
add_dialog_str(4,"The result is a healing potion that can be drunk instead of applied to the wound site, allowing for faster healing of wounds anywhere on the body.",0);
add_dialog_choice(0,"Brew this potion");
add_dialog_choice(1,"Next Page");
add_dialog_choice(2,"Close Book");
choice = run_dialog(1);
if(choice == 3)
	end();
if(choice == 2)
	set_state_continue(25);
if((has_item(471) == 0) || (has_item(470) == 0))
	set_state_continue(99);
take_item(470);
take_item(471);
if(get_ran(1,0,difficulty) > get_stat(i,14))
	set_state_continue(100);
play_sound(8);
print_str_color("Making Potion: Successful!",3);
reward_give(488);
break;


beginstate 25;
//Hardiness Philter//
difficulty = 6;
if(has_item(456) > 0)
	difficulty = difficulty - 1;
reset_dialog();
add_dialog_str(0,"Potion 5: Hardiness Philter",0);
add_dialog_str(1,"Herbs Required: Frost Shrooms, Karao Blossoms",0);
add_dialog_str(2,"Difficulty: 6",0);
add_dialog_str(3,"Description: Uses the magical properties of the Karao blossoms to bolster the drinker's natural defences, both to physical and elemental damage. A poweful potion-- but one that should be attempted only by experienced alchemists.",0);
add_dialog_choice(0,"Brew this potion");
add_dialog_choice(1,"Next Page");
add_dialog_choice(2,"Close Book");
choice = run_dialog(1);
if(choice == 3)
	end();
if(choice == 2)
	set_state_continue(26);
if((has_item(472) == 0) || (has_item(473) == 0))
	set_state_continue(99);
take_item(472);
take_item(473);
if(get_ran(1,0,difficulty) > get_stat(i,14))
	set_state_continue(100);
play_sound(8);
print_str_color("Making Potion: Successful!",3);
reward_give(489);
break;

beginstate 26;
//Dispel Potion//
difficulty = 7;
if(has_item(456) > 0)
	difficulty = difficulty - 1;
reset_dialog();
add_dialog_str(0,"Potion 6: Dispel-Magic Potion",0);
add_dialog_str(1,"Herbs Required: Mountain Holly, Karao Blossoms",0);
add_dialog_str(2,"Difficulty: 7",0);
add_dialog_str(3,"Description: Creates a magical field around the drinker that acts as a well, absorbing magic from the surrounding area. This field knows neither friend nor foe, and will drain positive and negative magic from both the user and nearby creatures.",0);
add_dialog_str(4,"Spell casters have complained that this potion disrupts enchantments and drains energy, making casting spells difficult for a short time. Ethereal beings in the field's proximity have been known to be completely dispelled.",0); 
add_dialog_choice(0,"Brew this potion");
add_dialog_choice(1,"Next Page");
add_dialog_choice(2,"Close Book");
choice = run_dialog(1);
if(choice == 3)
	end();
if(choice == 2)
	set_state_continue(27);
if((has_item(471) == 0) || (has_item(473) == 0))
	set_state_continue(99);
take_item(471);
take_item(473);
if(get_ran(1,0,difficulty) > get_stat(i,14))
	set_state_continue(100);
play_sound(8);
print_str_color("Making Potion: Successful!",3);
reward_give(490);
break;

beginstate 27;
//Strangle Dust//
difficulty = 6;
if(has_item(456) > 0)
	difficulty = difficulty - 1;
reset_dialog();
add_dialog_str(0,"Potion 7: Choking Dust",0);
add_dialog_str(1,"Herbs Required: Strangle Weed, Nightshade",0);
add_dialog_str(2,"Difficulty: 6",0);
add_dialog_str(3,"Description: Strangle Weed is a favorite reagent of assassin's across Ermarian, and choking dust is probably the most deadly of the many poisons brewed from it.",0);
add_dialog_str(4,"This potent poison causes muscle paralysis on the target, resulting in respiratory failure. It is completely odorless and tasteless, making it an effective food poison. However it is also absorbed through the skin, and can be hurled at a target.",0); 
add_dialog_choice(0,"Brew this potion");
add_dialog_choice(1,"Next Page");
add_dialog_choice(2,"Close Book");
choice = run_dialog(1);
if(choice == 3)
	end();
if(choice == 2)
	set_state_continue(28);
if((has_item(474) == 0) || (has_item(475) == 0))
	set_state_continue(99);
take_item(474);
take_item(475);
if(get_ran(1,0,difficulty) > get_stat(i,14))
	set_state_continue(100);
play_sound(8);
print_str_color("Making Potion: Successful!",3);
reward_give(491);
break;

beginstate 28;
//Frost Grenade//
difficulty = 8;
if(has_item(456) > 0)
	difficulty = difficulty - 1;
reset_dialog();
add_dialog_str(0,"Potion 8: Frost Grenade",0);
add_dialog_str(1,"Herbs Required: Strangle Weed, Karao Blossoms",0);
add_dialog_str(2,"Difficulty: 8",0);
add_dialog_str(3,"Description: Possibly the oddest potion in your aresenal, this one harnesses the repulsion between the karao blossom's magical potency and strangle weed's equally potent properties to create a time released magic bomb.",0);
add_dialog_str(4,"When thrown, the previously carefully seperated regeants of the potion are mixed for the first time, creating a rapid endothermic magical reaction.",0);
add_dialog_str(5,"The repulsion between the two substances flings droplets far and wide, which freeze almost instantaneously to form deadly shrapnel.",0);
add_dialog_str(6,"For obvious reasons this potion require great skill to make, and careful handling to keep it from going off in your hand. But when done right..... Shake- throw--- destruction!",0);
add_dialog_choice(0,"Brew this potion");
add_dialog_choice(1,"Next Page");
add_dialog_choice(2,"Close Book");
choice = run_dialog(1);
if(choice == 3)
	end();
if(choice == 2)
	set_state_continue(29);
if((has_item(473) == 0) || (has_item(474) == 0))
	set_state_continue(99);
take_item(473);
take_item(474);
if(get_ran(1,0,difficulty) > get_stat(i,14))
	set_state_continue(100);
play_sound(8);
print_str_color("Making Potion: Successful!",3);
reward_give(492);
break;

beginstate 29;
difficulty = 3;
if(has_item(456) > 0)
	difficulty = difficulty - 1;
if(get_flag(240,1) == 0){
reset_dialog();
add_dialog_str(0,"Potion 9: ???",0);
add_dialog_str(1,"Herbs Required: ???",0);
add_dialog_str(2,"Difficulty: ???",0);
add_dialog_str(3,"Description: You do not know this recipe yet. Nothing to see here, keep it moving.",0);
add_dialog_choice(0,"Next Page");
add_dialog_choice(1,"Close Book");
choice = run_dialog(1);
if(choice == 2)
	end();
if(choice == 1)
	set_state_continue(30);
}
reset_dialog();
add_dialog_str(0,"Potion 9: Fire Draught",0);
add_dialog_str(1,"Herbs Required: Icicle Moss",0);
add_dialog_str(2,"Difficulty: 3",0);
add_dialog_str(3,"Description: An age old recipe used by the highlanders to warm the body and restore blood flow to extremities. They certainly know what they're about when it comes to keeping warm, this stuff is hot as its namesake.",0);
add_dialog_choice(0,"Brew this potion");
add_dialog_choice(1,"Next Page");
add_dialog_choice(2,"Close Book");
choice = run_dialog(1);
if(choice == 3)
	end();
if(choice == 2)
	set_state_continue(30);
if(has_item(470) == 0)
	set_state_continue(99);
take_item(470);
if(get_ran(1,0,difficulty) > get_stat(i,14))
	set_state_continue(100);
play_sound(8);
print_str_color("Making Potion: Successful!",3);
reward_give(493);
break;

beginstate 30;
//War Paints//
difficulty = 6;
if(has_item(456) > 0)
	difficulty = difficulty - 1;
if(get_flag(240,2) == 0){
reset_dialog();
add_dialog_str(0,"Potion 10: ???",0);
add_dialog_str(1,"Herbs Required: ???",0);
add_dialog_str(2,"Difficulty: ???",0);
add_dialog_str(3,"Description: You do not know this recipe yet. Nothing to see here, keep it moving.",0);
add_dialog_choice(0,"Next Page");
add_dialog_choice(1,"Close Book");
choice = run_dialog(1);
if(choice == 2)
	end();
if(choice == 1)
	set_state_continue(31);
}
reset_dialog();
add_dialog_str(0,"Potion 10: War Paints",0);
add_dialog_str(1,"Herbs Required: Nightshade, Frost Shrooms",0);
add_dialog_str(2,"Difficulty: 6",0);
add_dialog_str(3,"Description: You've seen the effects that nightshade has on hobgoblins-- it's potency isn't in question, whether it's safe to consume it certainly is.",0);
add_dialog_str(4,"Supposedly brewing the herb with frost shrooms and using it as a body paint will counteract its more unfortunate side effects, namely hallucinations, hyperventilation, heart palpitation and eventually heart failure.",0);
add_dialog_str(5,"Then again this paint was developed by hobgoblins, which is reason enough to distrust it. If it works, it should give you the fury, strength and recklessness to be a whirling dervish leaving only carnage in your wake. If it doesn't.....",0);
add_dialog_choice(0,"Brew this potion");
add_dialog_choice(1,"Next Page");
add_dialog_choice(2,"Close Book");
choice = run_dialog(1);
if(choice == 3)
	end();
if(choice == 2)
	set_state_continue(31);
if((has_item(472) == 0) || (has_item(475) == 0))
	set_state_continue(99);
take_item(472);
take_item(475);
if(get_ran(1,0,difficulty) > get_stat(i,14))
	set_state_continue(100);
play_sound(8);
print_str_color("Making Potion: Successful!",3);
reward_give(494);
break;

beginstate 31;
//Panacea//
difficulty = 11;
if(has_item(456) > 0)
	difficulty = difficulty - 1;
if(get_flag(240,5) == 0){
reset_dialog();
add_dialog_str(0,"Potion 11: ???",0);
add_dialog_str(1,"Herbs Required: ???",0);
add_dialog_str(2,"Difficulty: ???",0);
add_dialog_str(3,"Description: You do not know this recipe yet. Nothing to see here, keep it moving.",0);
add_dialog_choice(0,"Back to Index");
add_dialog_choice(1,"Close Book");
choice = run_dialog(1);
if(choice == 2)
	end();
set_state_continue(10);
}
reset_dialog();
add_dialog_str(0,"Potion 11: Panacea",0);
add_dialog_str(1,"Herbs Required: Mountain Holly, Icicle Moss, Karao Blossoms",0);
add_dialog_str(2,"Difficulty: 11",0);
add_dialog_str(3,"Description: You found this cure-all recipe in the basements of Amon Sul. The tome listed it as only a theoretical recipe which hadn't been tested yet, which makes you nervous.",0);
add_dialog_str(4,"The idea behind it was to turn the magical properties of Karao Blossoms to healing purposes. The ingredient behaves in upredictable ways, but the researcher was confident he'd found the correct ratio to be successful.",0);
add_dialog_choice(0,"Brew this potion");
add_dialog_choice(1,"Back to Index");
add_dialog_choice(2,"Close Book");
choice = run_dialog(1);
if(choice == 3)
	end();
if(choice == 2)
	set_state_continue(10);
if((has_item(470) == 0) || (has_item(471) == 0) || (has_item(473) == 0))
	set_state_continue(99);
take_item(470);
take_item(471);
take_item(473);
if(get_ran(1,0,difficulty) > get_stat(i,14))
	set_state_continue(100);
play_sound(8);
print_str_color("Making Potion: Successful!",3);
reward_give(495);
break;

beginstate 13;
//Prefab party//
if((get_species(i) != 0) || (get_level(i) > 15)){
	print_str_color("You must be a human and below level 16 to use the Prefab Party option.",1);
	change_custom_abil_uses(i,3,1);
	end();
}
reset_dialog();
add_dialog_str(0,"You are about to create the prefabricated party (or prefabricated singleton rather.) This is HIGHLY recommended, but nonetheless, I'll give you a warning.",0);
add_dialog_str(1,"This will remove all your character's experience, levels, stats, and traits. It is advised that you enter the scenario with a brand new party, not one you've put work into.",0);
add_dialog_str(2,"Keep in mind that combat is balanced with the assumption that you are using this party. Playing with any other level party won't give you the full effect. Do you want to proceed?",0);
add_dialog_choice(0,"Bring it!");
add_dialog_choice(1,"On second thought....");
choice = run_dialog(0);
if(choice == 2){
	change_custom_abil_uses(i,3,1);
	message_dialog("Too bad. If you reconsider, this ability will be here until you leave the first town. It really would be a good idea to use the prefab party.","");
	end();
}
message_dialog("Good choice, you won't regret it.","");
level = (15 - get_level(i));
set_level(i,15);
levelmod = 0;
while(levelmod <= 22){
	set_char_trait(i,levelmod,0);
	levelmod = levelmod + 1;
}

levelmod = 100;
if(0){
if(char_has_trait(i,0) > 0)
	levelmod = levelmod + 10;
if(char_has_trait(i,1) > 0) 
	levelmod = levelmod + 15;
if(char_has_trait(i,2) > 0) 
	levelmod = levelmod + 15;
if(char_has_trait(i,3) > 0) 
	levelmod = levelmod + 15;
if(char_has_trait(i,4) > 0) 
	levelmod = levelmod + 15;
if(char_has_trait(i,5) > 0) 
	levelmod = levelmod + 20;
if(char_has_trait(i,6) > 0) 
	levelmod = levelmod + 20;
if(char_has_trait(i,7) > 0) 
	levelmod = levelmod + 20;
if(char_has_trait(i,8) > 0) 
	levelmod = levelmod + 30;
if(char_has_trait(i,9) > 0) 
	levelmod = levelmod + 40;
if(char_has_trait(i,10) > 0) 
	levelmod = levelmod - 20;
if(char_has_trait(i,11) > 0) 
	levelmod = levelmod - 20;
if(char_has_trait(i,12) > 0) 
	levelmod = levelmod - 30;
if(char_has_trait(i,13) > 0) 
	levelmod = levelmod - 30;
if(char_has_trait(i,14) > 0) 
	levelmod = levelmod - 40;
if(get_species(i) == 2)
	levelmod = levelmod + 10;
if(get_species(i) == 2)
	levelmod = levelmod + 20;
}
while(level != 0){
	if(0){
		change_char_xp(i,-2 * levelmod);
		change_char_xp(i,-2 * levelmod);
		change_char_xp(i,-2 * levelmod);
		change_char_xp(i,-2 * levelmod);
		change_char_xp(i,-2 * levelmod);
		level = level + 1;
	}
	if(level > 0){
		change_char_xp(i,2 * levelmod);
		change_char_xp(i,2 * levelmod);
		change_char_xp(i,2 * levelmod);
		change_char_xp(i,2 * levelmod);
		change_char_xp(i,2 * levelmod);
		level = level - 1;
	}
}
levelmod = 0;
while(levelmod <= 19){
	if(get_spell_level(i,0,levelmod) > 0)
		change_spell_level(i,0,levelmod,-1 * get_spell_level(i,0,levelmod));
	if(get_spell_level(i,1,levelmod) > 0)
		change_spell_level(i,1,levelmod,-1 * get_spell_level(i,1,levelmod));
	levelmod = levelmod + 1;
}
levelmod = 39;
while(levelmod >= 0){ 
	if((item_type_in_slot(i,levelmod) != 470) && (item_type_in_slot(i,levelmod) != 456))
		destroy_char_item(i,levelmod);
	levelmod = levelmod - 1;
}

change_pc_skill_pts(i,-1 * (get_char_skill_pts(i)));
alter_stat(i,0,6 - get_stat(i,0)); //- Strength
alter_stat(i,1,6 - get_stat(i,1)); // - Dexterity
alter_stat(i,2,3 - get_stat(i,2)); // - Intelligence
alter_stat(i,3,10 - get_stat(i,3)); // - Endurance
alter_stat(i,4,7 - get_stat(i,4)); // - Melee Weapons
alter_stat(i,5,0 - get_stat(i,5)); // - Pole Weapons
alter_stat(i,6,0 - get_stat(i,6)); // - Bows
alter_stat(i,7,0 - get_stat(i,7)); // - Thrown Missiles
alter_stat(i,8,4 - get_stat(i,8)); // - Hardiness
alter_stat(i,9,4 - get_stat(i,9)); // - Defense
alter_stat(i,10,2 - get_stat(i,10)); // - Assassination
alter_stat(i,11,0 - get_stat(i,11)); // - Mage Spells
alter_stat(i,12,0 - get_stat(i,12)); // - Priest Spells
alter_stat(i,13,1 - get_stat(i,13)); // - Arcane Lore
alter_stat(i,14,4 - get_stat(i,14)); // - Potion Making
alter_stat(i,15,2 - get_stat(i,15)); // - Tool Use
alter_stat(i,16,0 - get_stat(i,16)); // - Nature Lore
alter_stat(i,17,2 - get_stat(i,17)); // - First Aid
alter_stat(i,18,2 - get_stat(i,18)); // - Luck
alter_stat(i,19,0 - get_stat(i,19)); // - Quick Strike
alter_stat(i,20,0 - get_stat(i,20)); // - Parry
alter_stat(i,21,0 - get_stat(i,21)); // - Blademaster
alter_stat(i,22,0 - get_stat(i,22)); // - Anatomy
alter_stat(i,23,0 - get_stat(i,23)); // - Gymnastics
alter_stat(i,24,0 - get_stat(i,24)); // - Pathfinder
alter_stat(i,25,0 - get_stat(i,25)); // - Magery
alter_stat(i,26,0 - get_stat(i,26)); // - Resistance
alter_stat(i,27,0 - get_stat(i,27)); // - Magical Efficiency
alter_stat(i,28,0 - get_stat(i,28)); // - Lethal Blow
alter_stat(i,29,0 - get_stat(i,29)); // - Riposte
alter_stat(i,30,0 - get_stat(i,30)); // - Sharpshooter
revive_party();
reward_give(450);
reward_give(451);
reward_give(452);
reward_give(453);
reward_give(466);
reward_give(482);
reward_give(483);
reward_give(455);
reward_give(455);
reward_give(455);
reward_give(455);
reward_give(470);
reward_give(470);
reward_give(471);
reward_give(471);
reward_give(472);
reward_give(472);
reward_give(473);
reward_give(498);
reward_give(498);
reward_give(498);
reward_give(498);
reward_give(498);
reward_give(484);
change_pc_skill_pts(i,10);

break;

beginstate 99;
play_sound(41);
print_str_color("Making Potion Failed: Don't have proper ingredients.",1);
break;

beginstate 100;
play_sound(8);
play_sound(41);
clear_buffer();
append_string("Making Potion Failed: Alchemy Skill too low- (");
append_number((100 * get_stat(i,14)) / difficulty);
append_string("%)");
get_buffer_text(alchemy);
print_str_color(alchemy,1);
break;

beginstate 101;
//dispel potion//
xlim = char_loc_x(i) - 1;
while(xlim <= char_loc_x(i) + 1){
	ylim = char_loc_y(i) - 1;
	while(ylim <= char_loc_y(i) + 1){
		put_effect_on_space(xlim,ylim,4,2,1);
		ylim = ylim + 1;
	}
	xlim = xlim + 1;
}
run_animation_sound(162);
status = 0;
while(status <= 30){
	set_char_status(i,status,-1 * get_char_status(i,status),1,0);
	status = status + 1;
}
while(get_flag(255,1) > 0){
	alter_stat(i,0,1);
	inc_flag(255,1,-1);
}
xlim = char_loc_x(i) - 1;
while(xlim <= char_loc_x(i) + 1){
	ylim = char_loc_y(i) - 1;
	while(ylim <= char_loc_y(i) + 1){
		if(char_on_loc(xlim,ylim) > 0){
			targ = char_on_loc(xlim,ylim);
			if(creature_type(targ) == 214){
				put_jagged_zap(char_loc_x(i),char_loc_y(i),xlim,ylim,5);
				put_effect_on_char(i,2,get_ran(1,3,4),get_ran(1,0,1));
				put_effect_on_char(i,10,get_ran(1,1,2),get_ran(1,0,1));
				damage_char(i,get_ran(1,10,25),3);
				damage_char(targ,get_ran(1,20,50),3);
				put_effect_on_char(targ,2,get_ran(1,3,4),get_ran(1,0,1));
				put_effect_on_char(targ,10,get_ran(1,1,2),get_ran(1,0,1));
				run_animation_sound(46);
				if(get_flag(255,5) == 0){
					set_flag(255,5,1);
					message_dialog("You use the potion, and the strange magic well that you are familiar with begins to form around you. As you watch, the field of the well comes in contact with one of the strange black beasts.","A visible film of magic forms between the two fields, as the two pull on each other. Then, suddenly, the link snaps, sending recoil arching through the air.");
				}
			}

			status = 0;
			while(status <= 30){
				set_char_status(targ,status,-1 * get_char_status(targ,status),1,0);
				status = status + 1;
			}
			if((get_species(targ) == 8) || (creature_type(targ) == 216))
				damage_char(targ,get_ran(1,50,100),3);
		}
		ylim = ylim + 1;
	}
	xlim = xlim + 1;
}
print_str_color("All magic in the area is drained.",4);

break;

beginstate 102;
//Choke dust//
targ = who_is_custom_item_target();
set_character_pose(i,1);
force_instant_terrain_redraw();
play_sound(-14);
pause(2);
set_character_pose(i,2);
force_instant_terrain_redraw();

put_effect_on_char(targ,13,get_ran(1,2,4),get_ran(1,0,1));
put_effect_on_char(targ,7,get_ran(1,1,2),get_ran(1,0,1));
run_animation_sound(3);
damage_char(targ,get_ran(5,11,26),2);
set_char_status(targ,0,get_ran(1,50,75),0,1);
set_char_status(targ,3,-1 * get_ran(1,10,15),0,1);
set_char_status(targ,11,get_ran(1,4,7),0,1);
clear_buffer();
append_char_name(targ);
append_string(" collapses, clutching its throat in an effort to get air.");
get_buffer_text(alchemy);
print_str_color(alchemy,4);
break;

beginstate 103;
//frost grenade//
targ = who_is_custom_item_target();
set_character_pose(i,1);
force_instant_terrain_redraw();

put_straight_zap(char_loc_x(i),char_loc_y(i),char_loc_x(targ),char_loc_y(targ),6);
run_animation_sound(14);
set_character_pose(i,2);
force_instant_terrain_redraw();
xlim = char_loc_x(targ) - 1;
while(xlim <= char_loc_x(targ) + 1){
	ylim = char_loc_y(targ) - 1;
	while(ylim <= char_loc_y(targ) + 1){
		if(char_on_loc(xlim,ylim) > 0){
			put_effect_on_space(xlim,ylim,6 + (5 * get_ran(1,0,1)),get_ran(1,3,5),get_ran(1,0,1));
			damage_char(char_on_loc(xlim,ylim),get_ran(1,30,75),5);
		}
		ylim = ylim + 1;
	}
	xlim = xlim + 1;
}
run_animation_sound(52);
break;

beginstate 104;
//fire draught//
if(get_flag(8,0) > 0){
	print_str_color("The potion doesn't seem to have any effect, you are too cold.",4);
	end();
}
inc_flag(254,6,110);
inc_flag(254,7,30);
print_str_color("A wave of warmth spreads through your body.",4);
break;

beginstate 105;
//raw nightshade//
if(get_flag(255,4) > 0){
	message_dialog("You can still feel the effects of the last dose of nightshade you took, and frankly you aren't sure if your body is going to be able to handle this much. Even in your drug induced frenzy you know better than to eat more nightshade.","");
	end();
}
take_item(475);
if(get_flag(255,3) == 0){
	reset_dialog();
	add_dialog_str(0,"You stare at the small blue leaf with the purple veins, psyching yourself up to finally take the plunge. It had some nasty effects on the goblins, then again it didn't kill them either. Finally, in one swift motion you kick back the herb.",0);
	add_dialog_str(1,"You chew for a few seconds, letting the bitter blue juice fill your mouth. Then you swallow- and wait. You don't have to do so for long.",0);
	add_dialog_str(2,"The stuff hits you like a punch to the gut. You can hardly think, a red cloud has fallen over your vision, and all you can hear is the racing of your heart.",0);
	add_dialog_str(3,"You stand panting like a cornerned animal, staring wildly for any enemies to throw yourself at.",0);
	add_dialog_choice(0,"OK");
	choice = run_dialog(1);
	play_sound(48);
	side_effect = 1;
	set_char_status(i,3,5,1,0);
	set_char_status(i,9,6,1,0); 
}
if(get_flag(255,3) == 1){
	reset_dialog();
	add_dialog_str(0,"Again you raise the blue leaf to yuor mouth, this time with even more dread because you know what effect the last one had on you. Not something you're eager to go through again, but you have to do what you have to do.",0);
	add_dialog_str(1,"The room swims as you swallow the herb, bringing the familiar red veil and the maddening rage that you felt last time. You live to dismember your enemies, and revel in the violence.",0);
	add_dialog_choice(0,"OK");
	choice = run_dialog(1);
	play_sound(48);
	side_effect = 1;
	set_char_status(i,3,8,1,0);
	set_char_status(i,9,10,1,0);
}
if(get_flag(255,3) == 2){
	reset_dialog();
	add_dialog_str(0,"Your last experience with nightshade wasn't so bad, leaving you hopeful that this time you won't be twitching on the ground when you come off the stuff.",0);
	add_dialog_str(1,"You chew and swallow, and your surroundings seem to distort. Your enemies are terrible, slavering monsters out to kill you, but you feel no fear. Only the desire to rip them limb from limb and spill their blood.",0);
	add_dialog_choice(0,"OK");
	choice = run_dialog(1);
	play_sound(48);
	side_effect = 1;
	set_char_status(i,3,10,1,0);
	set_char_status(i,9,14,1,0);
	set_char_status(i,1,6,1,0);
}
if(get_flag(255,3) == 3){
	reset_dialog();
	add_dialog_str(0,"This time as you swallow the nightshade you are prepared for the madness that descends on you. The red veil wraps itself around your eyes, and the furious rage descends and embraces you like an old friend.",0);
	add_dialog_str(1,"You throw yourself at your foes, swinging wildly and hacking with weapons, teeth and hands. You shrug off your enemies blows like drops of water, feeling them no more than pinpricks.",0);
	add_dialog_str(2,"The madness is upon you, and nothing will distract you from the kill.",0);
	add_dialog_choice(0,"OK");
	choice = run_dialog(1);
	play_sound(48);
	side_effect = 1;
	set_char_status(i,3,10,1,0);
	set_char_status(i,9,16,1,0);
	set_char_status(i,1,10,1,0);
	set_char_status(i,2,6,1,0);
}
if(get_flag(255,3) == 4){
	reset_dialog();
	add_dialog_str(0,"You swallow the nightshade, and wait with anticipation the surge of adrenaline. You just aren't prepared for what happens.",0);
	add_dialog_str(1,"Your head swims, you stagger and fall. Everything is spinning, you can't even see for all the colors floating across your vision. You are falling, falling, falling.....",0);
	add_dialog_str(2,"And then the feeling passes. You stand and right yourself, what just happened? The red veil is gone, as is the feeling of fury and bloodlust. Your head is shockingly clear, you can think rational thoughts.",0);
	add_dialog_str(3,"You look around you to see what was happening while you were collapsed. Everything seems frozen, your foes move as if in slow motion.",0);
	add_dialog_str(4,"You on the other hand feel like you were just shot from a cannon. You meet your oppenents, easily side stepping attacks, dodging, whirling, weaving, slashing. Nobody can touch you, but you can certainly touch them.",0);
	add_dialog_str(5,"You revel in your new abilities, laughing at your foes. Gone is the lust for blood and violence you felt earlier, you laugh like a man who just discovered the bandits surrounding him were naught but children in costume. You are a god.",0);
	add_dialog_choice(0,"OK");
	choice = run_dialog(1);
	play_sound(48);
	side_effect = 1;
	set_char_status(i,1,12,1,0);
	set_char_status(i,2,12,1,0);
	set_char_status(i,3,12,1,0);
	set_char_status(i,9,12,1,0);
	set_char_status(i,16,12,1,0);
	set_char_status(i,17,12,1,0);
}
if(get_flag(255,3) == 5){
	reset_dialog();
	add_dialog_str(0,"After that last experience you aren't sure what exactly possesses you to take another dose of nightshade.",0);
	add_dialog_str(1,"You don't know whether the dose kills you instantly, or if there are a few frenzied minutes before it stops your heart. Your last sensation is of the bitter herb sliding down your throat.",0);
	add_dialog_choice(0,"OK");
	choice = run_dialog(1);
	kill_char(i,2,0);
}
set_flag(255,4,1);
inc_flag(255,3,1);
break;

beginstate 106;
//bundle of letters//
reset_dialog();
add_dialog_str(0,"(You carefully unfold the first of the letters.)",0);
add_dialog_str(1,"Professor Ludlan:",0);
add_dialog_str(2,"It is thrilling to be working with some of the greatest mind in Aizo. Not to slight you or your colleagues at the University, but I feel like finally my intellect is being put to use. All those labs with you are finally paying off!",0);
add_dialog_str(3,"There is still plany of mundane tasks here, the miners always are demanding some new tool or process, but here beneath the tower it is easy to forget the picks and gems.",0);
add_dialog_str(4,"I don't know if the Empire Liaison above even knows what is happening beneath his nose. The mines pay the budget, but their projects only receive a tenth of our resources and time.",0);
add_dialog_str(5,"Why just yesterday Wizard Thompson was experimenting with a new catalyst for use in stimulants and adrenaline potions. Fascinating stuff!",0);
add_dialog_str(6,"Your student and friend.",90);
add_dialog_str(7,"Marcello",90);
add_dialog_choice(0,"Read on.");
add_dialog_choice(1,"No time. Put them aside.");
choice = run_dialog(1);
if(choice == 2)
	end();
reset_dialog();
add_dialog_str(0,"Professor Ludlan:",0);
add_dialog_str(1,"I was assigned to Project 131, that stimulant potion I was telling you about. I spent all yesterday boiling and pealing glowing nettle, the catalyst we're using. It needs to be done perfectly to avoid damaging the valuable regeant.",0);
add_dialog_str(2,"It's quite tedious, but I think this project would be right up your alley-- you can't sit down without clearing away some herbs first.",0);
add_dialog_str(3,"It's rewarding work too. Why just yesterday they gave a dose of Cryoprev-- that's what we're calling it-- to some miners who'd been stuck in a frozen shaft for two days.",0);
add_dialog_str(4,"All six had serious frostbite and advanced hypothermia, but all made a full recovery in a matter of a week. The drug speeds the metabolism by a massive rate, allowing the body to warm itself. It's remarkable-- as I said you'd love it here.",0);
add_dialog_str(5,"Your student and friend.",90);
add_dialog_str(6,"Marcello",90);
add_dialog_choice(0,"Read on.");
add_dialog_choice(1,"No time. Put them aside.");
choice = run_dialog(1);
if(choice == 2)
	end();
reset_dialog();
add_dialog_str(0,"(This next letter is dated five months after the last one, probably letters were lost in between.)",0);
add_dialog_str(1,"Professor Ludlan:",0);
add_dialog_str(2,"Well as I forecasted in my last letter, Project 131 has been written off. Cryoprev has been put on hold for now in favor of a Wizard Lyonel's. How quickly we give up after some minor-- well not so minor-- setbacks.",0);
add_dialog_str(3,"Anyway, this means now I have to help with Lyonel's creations. He calls them Disruptors, and they have certainly been doing just that. He's been creeping everybody out with them, myself included, for months now.",0);
add_dialog_str(4,"The Director didn't take interest until the Cryoprev project hit a stumbling block, and Lyonel was in position to pitch his creations to him.",0);
add_dialog_str(5,"Lyonel is one of the most brilliant men here, and perhaps he really is on to something with his 'Disruptors'-- but when I look in the eyes of those twisted creatures I can't help but shudder.",0);
add_dialog_str(5,"Your student and friend.",90);
add_dialog_str(6,"Marcello",90);
add_dialog_str(7,"(This is the last letter in the bundle.)",0);
add_dialog_choice(0,"Put them away.");
choice = run_dialog(1);
set_flag(15,3,1);
end();
break;

beginstate 107;
//ration
inc_flag(254,7,100);
play_sound(-6);
set_char_status(i,22,15,1,0);
print_str_color("The ration gives your muscles much needed energy.",4);
break;

beginstate 108;
	change_custom_abil_uses(i,1,1);
	reset_dialog();
	add_dialog_str(0,"This is your way out of the Rim, your only escape. This will exit this scenario if you choose-- are you sure you want to do this?",0);
	add_dialog_choice(0,"I'm sure- Let's leave.");
	add_dialog_choice(1,"I still want to play.");
	choice = run_dialog(0);
	if(choice == 1)
		end_scenario(0);
break;

beginstate 109;
if(is_combat() == 1){
	print_str_color("Can't perform First Aid during combat.",1);
	end();
}
if(get_flag(255,6) > 0){
	print_str_color("You must wait before doing First Aid again.",1);
	end();
}
targ = i;
if((char_ok(4) == 1) || (char_ok(5) == 1)){
	reset_dialog();
	clear_buffer();
	append_string("Would you like to perform First Aid on yourself, or on ");
	if(char_ok(4) == 1)
		append_char_name(4);
	else
		append_char_name(5);
	append_string("?");
	get_buffer_text(alchemy);
	add_dialog_str(0,alchemy,0);
	add_dialog_choice(0,"Heal myself.");
	add_dialog_choice(1,"Heal ally.");
	choice = run_dialog(1);
	if(choice == 2){
		if(char_ok(4) == 1)
			targ = 4;
		else
			targ = 5;
	}
}
levelmod = get_ran(1,-6 + (3 * get_stat(i,17)),5 * get_stat(i,17));
if(levelmod < 0){
	damage_char(targ,-1 * levelmod,4);
	print_str_color("You do more harm than good.",1);
}
if(levelmod >= 0){
	heal_char(targ,levelmod);
	print_str_color("First Aid successful!",4);
	clear_buffer();
	append_char_name(targ);
	append_string(" is healed for ");
	append_number(levelmod);
	append_string(".");
	get_buffer_text(alchemy);
	print_str_color(alchemy,4);
}
set_flag(255,6,100 - (2 * get_stat(i,17)));
break;

beginstate 50;
targ = i;
if(is_combat() == 0)
	if((char_ok(4) == 1) || (char_ok(5) == 1)){
		reset_dialog();
		clear_buffer();
		append_string("Would you like to use the potion to heal yourself, or to heal ");
		if(char_ok(4) == 1)
			append_char_name(4);
		else
			append_char_name(5);
		append_string("?");
		get_buffer_text(alchemy);
		add_dialog_str(0,alchemy,0);
		add_dialog_choice(0,"Heal myself.");
		add_dialog_choice(1,"Heal ally.");
		choice = run_dialog(1);
		if(choice == 2){
			if(char_ok(4) == 1)
				targ = 4;
			else
				targ = 5;
		}
	}
	heal_char(targ,20);
	set_char_status(targ,22,30,1,0);
	put_sparkles_on_char(targ,3,5);
	run_animation_sound(24);
break;

beginstate 51;
targ = i;
if(is_combat() == 0)
	if((char_ok(4) == 1) || (char_ok(5) == 1)){
		reset_dialog();
		clear_buffer();
		append_string("Would you like to use the potion to heal yourself, or to heal ");
		if(char_ok(4) == 1)
			append_char_name(4);
		else
			append_char_name(5);
		append_string("?");
		get_buffer_text(alchemy);
		add_dialog_str(0,alchemy,0);
		add_dialog_choice(0,"Heal myself.");
		add_dialog_choice(1,"Heal ally.");
		choice = run_dialog(1);
		if(choice == 2){
			if(char_ok(4) == 1)
				targ = 4;
			else
				targ = 5;
		}
	}
	heal_char(targ,75);
	put_sparkles_on_char(targ,3,5);
	run_animation_sound(24);
break;

beginstate 53;
change_custom_abil_uses(i,2,1);
reset_dialog();
add_dialog_str(0,"As you spend an increasing length of time in the cold, it is important to monitor your temperature and fatigue. The elements will take their toll on even a fit man; extended exposure can cause weakness and even bodily harm.",0);
clear_buffer();
append_string("Body Temperature: ");
if(get_flag(254,1) == 0)
	append_string("Normal.");
if(get_flag(254,1) == 1)
	append_string("Beginning to feel cold.");
if(get_flag(254,1) == 2)
	append_string("Cold.");
if(get_flag(254,1) == 3)
	append_string("Limbs growing numb.");
if(get_flag(254,1) == 4)
	append_string("Freezing.");
if(get_flag(254,1) >= 5){
	clear_buffer();
	append_string("Hypothermia.");
}
if(get_flag(254,1) >= 7){
	clear_buffer();
	append_string("Body Temperature: Advanced Hypothermia.");
}
if(get_flag(9,0) > 1){
	clear_buffer();
	append_string("Body Temperature: Frostbitten.");
}
if(get_flag(9,12) > 1){
	clear_buffer();
	append_string("Body Temperature: Burning with heat.");
}
get_buffer_text(alchemy);
add_dialog_str(1,alchemy,20);

clear_buffer();
append_string("Fatigue: ");
if(get_flag(254,3) == 0)
	append_string("Normal.");
if(get_flag(254,3) == 1)
	append_string("Weary.");
if(get_flag(254,3) == 2)
	append_string("Tired.");
if(get_flag(254,3) == 3)
	append_string("Very Tired.");
if(get_flag(254,3) >= 4)
	append_string("Exhausted.");
if(get_flag(254,3) >= 6){
	clear_buffer();
	append_string("Fatigue: Exhausted to the point of collapse.");
}
if(get_flag(9,12) > 0){
	clear_buffer();
	append_string("Fatigue: Famished, but otherwise energetic.");
}
get_buffer_text(alchemy);
add_dialog_str(2,alchemy,20);
add_dialog_choice(0,"OK");
choice = run_dialog(0);
break;