// 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;
int tick3;
int person,x,y,zombie;
string mutation;
int hp,mp;
int choice;

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;

// Special abilities
init_special_abil(0,"Show Energy level",10);
init_special_abil(1,"Rest",11);

break;

beginstate START_SCEN_STATE;

// setting the necessary flags for the zombie coordination in town 4
// Each set first sets the x, then the y coordinate

// for (30,15)
set_flag(200,0,30);
set_flag(201,0,15);
// for (34,31)
set_flag(200,1,34);
set_flag(201,1,31);
// for (20,43)
set_flag(200,2,20);
set_flag(201,2,43);
// for (15,16)
set_flag(200,3,15);
set_flag(201,3,16);
// for (29,30)
set_flag(200,4,29);
set_flag(201,4,30);

message_dialog("If you haven't read the included readme file, I ask you to do so before you play this scenario. It contains info, hint and a walkthrough.","Really, the readme contains just about all the information you need to know. If you are stuck, look at the readme first, then send me an email. Doing that will save both of us time.");

reset_dialog(); // difficulty setting
add_dialog_str(0,"Difficulty settings",0);
add_dialog_str(1,"This scenario has implemented in it a system of difficulty that can make your life pretty sour, depending on the difficulty you want to set it to. For a first time run I recommend the Easy setting.",0);
add_dialog_str(2,"Then, when you have played the scenario until the end, you can replay it with either the Medium or Hard setting.",0);
add_dialog_choice(0,"Easy");
add_dialog_choice(1,"Medium");
add_dialog_choice(2,"Hard");
choice = run_dialog(1);

if (choice == 1)
		set_flag(215,0,1);
if (choice == 2)
		set_flag(215,0,2);
if (choice == 3)
		set_flag(215,0,3);

break;

beginstate START_STATE;

// Here comes the resting and energy point stuff, related to the disease (so it's only triggered once you actually have the disease at level 3!)

if (get_flag(210,0) > 1 && get_flag(6,12) == 1) {// is the disease higher than level 2 and have you been in town 6? If so, then go on
		if (get_flag(250,2) > 0)
				inc_flag(250,2,-1);
		if (get_flag(250,2) == 0) {
				if (get_flag(250,10) == 0) {
						message_dialog("We're feeling a bit dizzy because of the disease. We should actually be resting for a bit, like we did on the roofs, but if the zombies get us, we're done for. We think we can hold on for a bit longer, but not too long.","");
						set_flag(250,10,1);
						}
				if (get_flag(250,5) == 0) {
						print_str_color("We're feeling dizzy, maybe we ought to rest?",1);
						set_flag(250,5,1);
						}
				hp = -1 * get_ran(1,4,7);
				mp = -1 * get_ran(1,6,9);
				change_char_health(0,hp);
				change_char_energy(0,mp);

				hp = -1 * get_ran(1,4,7);
				mp = -1 * get_ran(1,6,9);
				change_char_health(1,hp);
				change_char_energy(1,mp);

				hp = -1 * get_ran(1,4,7);
				mp = -1 * get_ran(1,6,9);
				change_char_health(2,hp);
				change_char_energy(2,mp);

				hp = -1 * get_ran(1,4,7);
				mp = -1 * get_ran(1,6,9);
				change_char_health(3,hp);
				change_char_energy(3,mp);

				if (get_health(0) <= 0 && char_ok(0) == 1)
						kill_char(0,2,0);

				if (get_health(1) <= 0 && char_ok(0) == 1)
						kill_char(1,2,0);

				if (get_health(2) <= 0 && char_ok(0) == 1)
						kill_char(2,2,0);

				if (get_health(3) <= 0 && char_ok(0) == 1)
						kill_char(3,2,0);
				}
		}	


// Here comes all the disease business
if (get_flag(3,18) == 1) {
		tick3 = get_flag(3,19) * 256 + get_flag(3,20);

		if (get_current_tick() == (tick3 + (1200 / get_flag(215,0)))) // disease level 2
				set_flag(210,0,1);

		if (get_current_tick() == (tick3 + (1800 / get_flag(215,0)))) { // disease level 3
				set_flag(210,0,2);
				set_flag(250,3,100);
				}

		if (get_current_tick() == tick3 + (tick3 + (2100 / get_flag(215,0)))) { // disease level 4
				set_flag(210,0,3);
				set_flag(250,3,90);
				}

		if (get_current_tick() == (tick3 + (2400 / get_flag(215,0)))) { // disease level 5
				set_flag(210,0,4);
				set_flag(250,3,80);
				}
		
		if (get_current_tick() == (tick3 + (2700 / get_flag(215,0)))) { // disease level 6
				set_flag(210,0,5);
				set_flag(250,3,70);
				}

		if (get_current_tick() >= (tick3 + (600 / get_flag(215,0))) && get_flag(210,0) == 0) { // level 1
				if (get_flag(4,0) == 0 && get_flag(210,1) == 0) {
						play_sound(3);
						message_dialog("Bleh, we don't feel very good, actually. Feels a bit like a cold, or  the start of flu. Must be the atmosphere and the situation we're in. The stress and all that.","");
						set_flag(210,1,2);
						}

				if (get_flag(4,0) == 1 && get_flag(210,1) == 0) {
						play_sound(3);
						message_dialog("Honestly, we start feeling a bit ill now. We should make haste to get away from this place, before this disease here turns us into zombies.","");
						set_flag(210,1,1);
						}

				if (get_ran(1,0,15) == 0)
						play_sound(3);
				}

		if (get_flag(210,0) == 1) { // level 2
				if (get_flag(4,0) == 0 && get_flag(210,2) == 0) {
						play_sound(3);
						message_dialog("The coughing has become worse, now. We do hope we won't fall too ill, since we do intend to get out of this town alive.","");
						set_flag(210,2,2);
						}

				if (get_flag(4,0) == 1 && get_flag(210,2) == 0) {
						play_sound(3);
						message_dialog("Man, we really have to get out of here, the disease is getting to us... The coughing is getting worse.","");
						set_flag(210,2,1);
						}

				if (get_ran(1,0,10) == 0)
						play_sound(3);
				}

		if (get_flag(210,0) == 2) { // level 3
				if (get_flag(4,0) == 0 && get_flag(210,3) == 0) {
						play_sound(3);
						message_dialog("We really start to feel sick now. Let's just find out what's happening here and get the hell out!","");
						set_flag(210,3,2);
						set_char_status(random_party_member(),7,2,1,0); // disease
						}

				if (get_flag(4,0) == 1 && get_flag(210,3) == 0) {
						play_sound(3);
						message_dialog("We really start to feel sick now, this disease is eating us up! We must leave now or we won't make it.","");
						set_flag(210,3,1);
						set_char_status(random_party_member(),7,2,1,0); // disease
						}

				if (get_ran(1,0,8) == 0)
						play_sound(3);

				if (get_ran(1,0,9) == 0)
						set_char_status(random_party_member(),7,2,1,0); // disease
				}

		if (get_flag(210,0) == 3) { // level 4
				if (get_flag(4,0) == 0 && get_flag(210,4) == 0) {
						play_sound(3);
						message_dialog("The coughing and all is becoming worse and we're getting headaches all the time. This starts to be very serious.","");
						set_flag(210,4,2);
						set_char_status(random_party_member(),7,2,1,0); // disease
						}

				if (get_flag(4,0) == 1 && get_flag(210,4) == 0) {
						play_sound(3);
						message_dialog("We're getting headaches now, just like these miners we read about in doctor's journal. We asked ourselves how it all felt, right? Well, this is it.","");
						set_flag(210,4,1);
						set_char_status(random_party_member(),7,2,1,0); // disease
						}

				if (get_ran(1,0,8) == 0)
						play_sound(3);

				if (get_ran(1,0,8) == 0)
						set_char_status(random_party_member(),7,2,1,0); // disease
				}

		if (get_flag(210,0) == 4) { // level 5
				if (get_flag(4,0) == 0 && get_flag(210,5) == 0) {
						play_sound(3);
						message_dialog("Headaches are getting worse, coughing becomes worse and our stomach begins to ache excruciatingly now and then. We must flee this place, and flee it soon.","");
						set_flag(210,5,2);
						set_char_status(random_party_member(),7,2,1,0); // disease
						set_char_status(random_party_member(),0,2,1,0); // poison
						}

				if (get_flag(4,0) == 1 && get_flag(210,5) == 0) {
						play_sound(3);
						message_dialog("Stomach ache. The disease is getting to us. If we don't hurry, we won't be here anymore to tell what we saw.","");
						set_flag(210,5,1);
						set_char_status(random_party_member(),7,2,1,0); // disease
						set_char_status(random_party_member(),0,2,1,0); // poison
						}

				if (get_ran(1,0,8) == 0)
						play_sound(3);

				if (get_ran(1,0,7) == 0)
						set_char_status(random_party_member(),7,2,1,0); // disease

				if (get_ran(1,0,7) == 0)
						set_char_status(random_party_member(),0,2,1,0); // poison
				}

		if (get_flag(210,0) == 5) { // level 6 => the worst you can get
				if (get_flag(4,0) == 0 && get_flag(210,6) == 0) {
						play_sound(3);
						message_dialog("T=Our situations is looking dire now. This disease, whatever it is, is getting worse. Our skins even start to look a bit pale now.","");
						set_flag(210,6,2);
						set_char_status(random_party_member(),7,2,1,0); // disease
						set_char_status(random_party_member(),0,2,1,0); // poison
						}

				if (get_flag(4,0) == 1 && get_flag(210,6) == 0) {
						play_sound(3);
						message_dialog("Our skin, it's turning greyish, pale... We are mutating! If we don't leave this place right now, that's our end.","");
						set_flag(210,6,1);
						set_char_status(random_party_member(),7,2,1,0); // disease
						set_char_status(random_party_member(),0,2,1,0); // poison
						}

				if (get_ran(1,0,7) == 0)
						play_sound(3);

				if (get_ran(1,0,5) == 0)
						set_char_status(random_party_member(),7,2,1,0); // disease

				if (get_ran(1,0,5) == 0)
						set_char_status(random_party_member(),0,2,1,0); // poison

				if (get_ran(1,0,14) == 0) {
						person = random_party_member(); // select party member

						x = char_loc_x(person);
						y = char_loc_y(person);
						zombie = get_ran(1,234,236); // determine the zombie to place

						kill_char(person,2,0); // kill him and prepare for zombie placement

						clear_buffer(); // prepare and print string
						append_char_name(person);
						append_string(" has turned into a zombie!");
						get_buffer_text(mutation);
						print_str_color(mutation,1);

						place_monster(x,y,zombie,0); // place zombie
						force_instant_terrain_redraw();
						play_sound(44);
						}
				}
		}
break;

beginstate 10;
if (get_flag(5,1) == 0) { // energy points ability
		print_str_color("This ability is not yet relevant.",1);
		change_custom_abil_uses(0,0,1);
		change_custom_abil_uses(1,0,1);
		change_custom_abil_uses(2,0,1);
		change_custom_abil_uses(3,0,1);
		change_custom_abil_uses(4,0,1);
		change_custom_abil_uses(5,0,1);
		end();
		}
	print_big_str("Your amount of energy points is ",get_flag(250,2),"");
	change_custom_abil_uses(0,0,1);
	change_custom_abil_uses(1,0,1);
	change_custom_abil_uses(2,0,1);
	change_custom_abil_uses(3,0,1);
	change_custom_abil_uses(4,0,1);
	change_custom_abil_uses(5,0,1);
break;

beginstate 11; // resting ability
play_sound(20);
force_view_center(1,46);
force_instant_terrain_redraw();
set_ticks_forward(50);
pause (20);

if (char_ok(3) == 1)
		force_view_center(char_loc_x(3),char_loc_y(3));

if (char_ok(2) == 1)
		force_view_center(char_loc_x(2),char_loc_y(2));

if (char_ok(1) == 1)
		force_view_center(char_loc_x(1),char_loc_y(1));

if (char_ok(0) == 1)
		force_view_center(char_loc_x(0),char_loc_y(0));

force_instant_terrain_redraw();
print_str_color("We have a nice rest, just long enough to replenish our strengths",4);
change_custom_abil_uses(0,1,1);
change_custom_abil_uses(1,1,1);
change_custom_abil_uses(2,1,1);
change_custom_abil_uses(3,1,1);
change_custom_abil_uses(4,1,1);
change_custom_abil_uses(5,1,1);

change_char_health(0,400); // restores all HP
change_char_health(1,400);
change_char_health(2,400);
change_char_health(3,400);

change_char_energy(0,500); // restores all MP
change_char_energy(1,500);
change_char_energy(2,500);
change_char_energy(3,500);

if (get_flag(6,12) == 0) // didn't jump over fence to town 6 yet
		set_flag(250,2,6); // replenish energy points

if (get_flag(6,12) == 1) // jumped over fence to town 6
		set_flag(250,2,get_flag(250,3)); // replenish energy points

set_flag(250,5,0); // makes sure the print_str_color will show up next time (only relevant after jumping over the fench to the church)
break;