// Town script for town 7: cemetery

begintownscript;

variables;
int tick4,zombie,choice;

body;

beginstate INIT_STATE;
if (get_flag(7,5) == 1) { // makes sure there are monsters when party ascends from a crypt
		place_monster(18,22,234,0);
		place_monster(20,26,235,0);
		place_monster(28,29,236,0);
		place_monster(20,13,234,0);
		place_monster(21,7,235,0);
		}
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
if (get_flag(7,0) == 0) {
		large_draw_pic_dialog(551,"The cemetery, great. Now let's find a way out.");
		set_flag(7,0,1);
		
		tick4 = get_current_tick();
		set_flag(7,3,tick4 / 256);
		set_flag(7,4,tick4 % 256);
		}

// zombie activator
tick4 = get_flag(7,3) * 256 + get_flag(7,4);
if (get_current_tick() >= tick4 + 25 && get_flag(7,5) == 0) {
		message_dialog("Hear the gurgling noises? The zombies have found their way through the church to the cemetery. We must make haste.","");
		activate_hidden_group(1);
		set_flag(7,5,1);
		}

// noises of zombies
if (get_flag(7,5) == 1) { // if zombies are coming, run sounds
		if (get_ran(1,1,4) == 4)
				play_sound(44);

		if (get_ran(1,1,4) == 4)
				play_sound(119);
		}

// zombie controller
if (get_flag(250,0) < 10) {
		zombie = get_ran(1,234,236);
		place_monster(25,39,zombie,0);
		inc_flag(250,0,1);
		}
break;

beginstate 10;
message_dialog("What, go back? Right into the rotting hands of the zombies? We don't think so. It's safer to stay here and find a way out.","");
block_entry(1);
break;

beginstate 11;
if(get_flag(7,1)==0){
	message_dialog("Looks as though something (probably undead) tried to escape. The fence has been destroyed, and some trees are in a bad shape. Alas, they didn't succeed. Probably the forest was too dense for them.","Come to think of it, it's also too dense for us. We should find another route.");
	set_flag(7,1,1);
	}
break;

beginstate 12;
if (is_combat() == 1) {
		message_dialog("We can only go on when we have regrouped and are not fighting, so let's do that first.","");
		block_entry(1);
		end();
		}

reset_dialog();
add_dialog_str(0,"Are we sure we want to go down?",0);
add_dialog_choice(0,"Yes, let's go down.");
add_dialog_choice(1,"No, let's stay up here.");
choice = run_dialog(1);
		
if (choice == 1)
		move_to_new_town(8,14,41);
break;

beginstate 13;
if (is_combat() == 1) {
		message_dialog("We can only go on when we have regrouped and are not fighting, so let's do that first.","");
		block_entry(1);
		end();
		}

reset_dialog();
add_dialog_str(0,"Are we sure we want to go down?",0);
add_dialog_choice(0,"Yes, let's go down.");
add_dialog_choice(1,"No, let's stay up here.");
choice = run_dialog(1);
		
if (choice == 1)
		move_to_new_town(8,14,36);
break;

beginstate 14;
if (is_combat() == 1) {
		message_dialog("We can only go on when we have regrouped and are not fighting, so let's do that first.","");
		block_entry(1);
		end();
		}

reset_dialog();
add_dialog_str(0,"Are we sure we want to go down?",0);
add_dialog_choice(0,"Yes, let's go down.");
add_dialog_choice(1,"No, let's stay up here.");
choice = run_dialog(1);
		
if (choice == 1)
		move_to_new_town(8,14,31);
break;

beginstate 15;
if (is_combat() == 1) {
		message_dialog("We can only go on when we have regrouped and are not fighting, so let's do that first.","");
		block_entry(1);
		end();
		}

reset_dialog();
add_dialog_str(0,"Are we sure we want to go down?",0);
add_dialog_choice(0,"Yes, let's go down.");
add_dialog_choice(1,"No, let's stay up here.");
choice = run_dialog(1);
		
if (choice == 1) {
		if (get_flag(7,2) == 0)
				set_flag(7,2,1);
		move_to_new_town(8,14,26);
		}
break;

beginstate 16;
message_dialog("Falling down doesn't seem like a particularly good idea.","");
block_entry(1);
break;