// town script for town 45: Merrylhide (intro cutscene town 1)

begintownscript;

variables;

int stepsnd,n,y,choice;

body;

beginstate INIT_STATE;
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;

if (get_flag(45,0) == 0) {

// *** start cutscene ***

//place party and view at the right location

	force_view_center(24,34);
	relocate_character(0,24,34);
	relocate_character(1,24,35);
	relocate_character(2,24,36);
	relocate_character(3,24,37);
	force_instant_terrain_redraw();

// Intro message

message_dialog("After a long travel, you are pleased that you can rest in this small town. As you are quite sleepy, you decide to go to the inn.","");

// party walks to inn

	march_party(24,33);
	force_view_center(24,33);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(24,32);
	force_view_center(24,32);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(24,31);
	force_view_center(24,31);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(23,30);
	force_view_center(23,30);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);

	march_party(22,29);
	force_view_center(22,29);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);

	march_party(21,28);
	force_view_center(21,28);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(21,27);
	force_view_center(21,27);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(21,26);
	force_view_center(21,26);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(21,25);
	force_view_center(21,25);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(21,24);
	force_view_center(21,24);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(21,23);
	force_view_center(21,23);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(21,22);
	force_view_center(21,22);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(21,21);
	force_view_center(21,21);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(21,20);
	force_view_center(21,20);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(20,20);
	force_view_center(20,20);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);

	march_party(19,20);
	force_view_center(19,20);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(18,20);
	force_view_center(18,20);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
// Open door
	
	flip_terrain(18,20);
	force_instant_terrain_redraw();
	play_sound(159);
	pause(1);
	
// Continue walking
	
	march_party(17,20);
	force_view_center(17,20);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(16,20);
	force_view_center(16,20);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(15,19);
	force_view_center(15,19);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(10);
	
// Party asks for room

	text_bubble_on_char(0,"Could we have a room please?");
	force_instant_terrain_redraw();
	pause(10);
	
	text_bubble_on_char(0,"");
	force_instant_terrain_redraw();
	pause(10);
	
	text_bubble_on_char(13,"Of course");
	force_instant_terrain_redraw();
	pause(10);
	
	text_bubble_on_char(13,"");
	force_instant_terrain_redraw();
	pause(10);

	message_dialog("She gives you the key, you give here the required amount of coins. You then proceed to your room.","");

// Party walks to room
	
	march_party(14,19);
	force_view_center(14,19);
	flip_terrain(18,20); // Close inn door
	play_sound(59);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(13,19);
	force_view_center(13,19);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(12,19);
	force_view_center(12,19);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(12,20);
	force_view_center(12,20);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(11,20);
	force_view_center(11,20);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(10,20);
	force_view_center(10,20);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(9,20);
	force_view_center(9,20);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(8,20);
	force_view_center(8,20);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(8,19);
	force_view_center(8,19);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(8,18);
	force_view_center(8,18);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(8,17);
	force_view_center(8,17);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(8,16);
	force_view_center(8,16);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(8,15);
	force_view_center(8,15);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(8,14);
	force_view_center(8,14);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(8,13);
	force_view_center(8,13);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(8,12);
	force_view_center(8,12);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);

// open door and walk into room

	flip_terrain(9,12);
	force_instant_terrain_redraw();
	play_sound(159);
	pause(5);
	
	march_party(9,12);
	force_view_center(9,12);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(10,12);
	force_view_center(10,12);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	set_character_facing(2,6);
	play_sound(49);
	relocate_character(0,11,11);
	relocate_character(1,10,12);
	relocate_character(2,9,12);
	relocate_character(3,8,12);
	force_instant_terrain_redraw();
	pause(5);
	
	set_character_facing(0,4);
	set_character_facing(3,6);
	relocate_character(1,11,13);
	relocate_character(2,10,12);
	relocate_character(3,9,12);
	flip_terrain(9,12);
	play_sound(59);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);

	relocate_character(1,11,14);
	relocate_character(2,11,12);
	relocate_character(3,10,12);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	relocate_character(2,12,12);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	set_character_facing(2,2);
	force_instant_terrain_redraw();
	pause(10);

// Party member talks

	text_bubble_on_char(1,"So");
	force_instant_terrain_redraw();
	pause(8);
	
	text_bubble_on_char(1,"");
	text_bubble_on_char(1,"Shall we go to sleep?");
	force_instant_terrain_redraw();
	pause(8);
	
	text_bubble_on_char(1,"");
	text_bubble_on_char(2,"Please");
	force_instant_terrain_redraw();
	pause(5);
	
	text_bubble_on_char(3,"Sure");
	force_instant_terrain_redraw();
	pause(5);
	
	text_bubble_on_char(0,"Yeah");
	force_instant_terrain_redraw();
	pause(5);
	
	text_bubble_on_char(2,"");
	force_instant_terrain_redraw();
	pause(5);
	
	text_bubble_on_char(3,"");
	force_instant_terrain_redraw();
	pause(5);
	
	text_bubble_on_char(0,"");
	force_instant_terrain_redraw();
	pause(1);

	text_bubble_on_char(1,"Okay");
	force_instant_terrain_redraw();
	pause(8);
	
	text_bubble_on_char(1,"Have a good sleep");
	force_instant_terrain_redraw();
	pause(8);
	
	text_bubble_on_char(1,"");
	run_animation_sound(20);

// Switch to black and explain

	force_view_center(7,40);
	force_instant_terrain_redraw();
	pause(15);
	
	message_dialog("You turn the lights off and get into bed. You have a long, pleasant sleep.","Next day you awake. It is time to continue on your journey to Riverrod province. You will sleep there a night in Voughton, and continue on your way. You don't want to stay there for a long time.");

// Make it day

	set_ticks_forward(6000);

// Remove all characters from town

	n = 6;
	
	while (n < 28) {
			erase_char(n);
			n = n + 1;
			}

// get back to room and start talking

	text_bubble_on_char(1,"");

	set_character_facing(0,4); // (just making sure everybody looks to the right direction)
	set_character_facing(1,0);
	set_character_facing(2,2);
	set_character_facing(3,6);
	force_view_center(10,12);
	force_instant_terrain_redraw();
	pause(10);
	
	text_bubble_on_char(1,"Good morning all");
	force_instant_terrain_redraw();
	pause(8);
	
	text_bubble_on_char(1,"");
	text_bubble_on_char(1,"Shall we go for breakfast?");
	force_instant_terrain_redraw();
	pause(8);

	text_bubble_on_char(1,"");
	text_bubble_on_char(2,"I'm starving!");
	force_instant_terrain_redraw();
	pause(5);
	
	text_bubble_on_char(3,"Sure");
	force_instant_terrain_redraw();
	pause(5);
	
	text_bubble_on_char(0,"Yeah");
	force_instant_terrain_redraw();
	pause(5);
	
	text_bubble_on_char(2,"");
	force_instant_terrain_redraw();
	pause(5);
	
	text_bubble_on_char(3,"");
	force_instant_terrain_redraw();
	pause(5);
	
	text_bubble_on_char(0,"");
	force_instant_terrain_redraw();
	pause(1);

	text_bubble_on_char(1,"Okay");
	force_instant_terrain_redraw();
	pause(8);
	
	text_bubble_on_char(1,"");
	text_bubble_on_char(1,"Let's go then.");
	force_instant_terrain_redraw();
	pause(8);
	
	text_bubble_on_char(1,"");
	force_instant_terrain_redraw();
	pause(8);
	
	play_sound(49);
	set_character_facing(0,2);
	set_character_facing(3,4);
	relocate_character(0,10,12);
	relocate_character(1,11,13);
	relocate_character(2,11,12);
	relocate_character(3,11,11);
	force_instant_terrain_redraw();
	pause(5);
	
	play_sound(49);
	set_character_facing(1,2);
	relocate_character(0,9,12);
	relocate_character(1,10,12);
	force_view_center(9,12);
	force_instant_terrain_redraw();
	pause(5);

// Open door

	flip_terrain(9,12);
	force_instant_terrain_redraw();
	play_sound(159);
	pause(5);

// Continue walking

	march_party(8,12);
	force_view_center(8,12);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(8,13);
	force_view_center(8,13);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(8,14);
	force_view_center(8,14);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(8,15);
	force_view_center(8,15);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(8,16);
	force_view_center(8,16);
	flip_terrain(9,12); // Close door
	play_sound(59);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(8,17);
	force_view_center(8,17);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(8,18);
	force_view_center(8,18);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(8,19);
	force_view_center(8,19);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(8,20);
	force_view_center(8,20);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(9,20);
	force_view_center(9,20);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(15);
	
	message_dialog("Then you halt and stop. You look around, amazed. Where is everybody?","After spending some time looking around, you decided to go outside and see if there is life at one of the numerous shops.");

// Go outside and look at shops

	march_party(10,20);
	force_view_center(10,20);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(11,20);
	force_view_center(11,20);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(12,21);
	force_view_center(12,21);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(13,21);
	force_view_center(13,21);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(14,21);
	force_view_center(14,21);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(15,20);
	force_view_center(15,20);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(16,20);
	force_view_center(16,20);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(17,20);
	force_view_center(17,20);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
// Open door
	
	flip_terrain(18,20);
	force_instant_terrain_redraw();
	play_sound(159);
	pause(15);
	
// Continue walking
	
	march_party(18,20);
	force_view_center(17,20);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(19,20);
	force_view_center(17,20);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(20,20);
	force_view_center(17,20);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(5);
	
	march_party(21,20);
	force_view_center(17,20);
	flip_terrain(18,20); // Close inn door
	play_sound(59);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(4);
	
// Stop and explain

	message_dialog("You have walked outside, and you look around you, when suddenly...","");

// Girl comes by

	relocate_character(28,22,30);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(3);
	
	y = 29;
	
	while (y > 15) {
			relocate_character(28,22,y);
			if(stepsnd == 0){
					stepsnd = 1;
					play_sound(49);
				}
				else{
					stepsnd = 0;
					play_sound(50);
				}
			force_instant_terrain_redraw();
			pause(1);
			
			y = y - 1;
			}
	
	relocate_character(28,22,15);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(3);
	
	relocate_character(28,23,14);
	play_sound(49);
	force_instant_terrain_redraw();
	pause(3);
	
	relocate_character(28,24,13);
	play_sound(50);
	force_instant_terrain_redraw();
	pause(3);
	
	y = 12;
	
	while (y > 2) {
			relocate_character(28,24,y);
			if(stepsnd == 0){
					stepsnd = 1;
					play_sound(49);
				}
				else{
					stepsnd = 0;
					play_sound(50);
				}
			force_instant_terrain_redraw();
			pause(3);
			
			y = y - 1;
			}
	
	erase_char(28); // erase woman
	pause(10);
	
	message_dialog("Slightly surprised, you look at the running woman. She ran past you without even noticing you. Anyway, You were going to look at the shops.","Let's look at that shop right in front of you first, with all the bookshelves.");

// Player will walk and search now for himself. To ensure player doesn't go where he doesn't have to go, use the other states.

	set_flag(45,0,1); // Ensure that cutscene isn't played twice.
	}


// Upon having looked through the windows of shop 1 and 2, display this message

if (get_flag(45,2) == 1 && get_flag(45,3) == 1 && get_flag(45,4) == 0) {
		message_dialog("Weird. All shops seem to be deserted. You then remember that woman that ran past you. She went north. Maybe you can still catch up with her and ask what's happening.","");
		set_flag(45,4,1);
		}

break;

beginstate 10;
if (get_flag(45,1) == 0) {
		message_dialog("The library is empty. There is no living soul","");
		set_flag(45,1,1);
		}
break;

beginstate 11;
if (get_flag(45,1) == 1 && get_flag(45,2) == 0) {
		message_dialog("This shop is empty. Nobody is here.","");
		set_flag(45,2,1);
		}
break;

beginstate 12;
if (get_flag(45,1) == 1 && get_flag(45,3) == 0) {
		message_dialog("This shop is empty. Nobody is here.","");
		set_flag(45,3,1);
		}
break;

beginstate 13;
	message_dialog("Going this way will get you outside the village. You don't want that, certainly not in this direction.","");
	block_entry(1);
break;

beginstate 14;
if (get_flag(45,4) == 1) {
		reset_dialog();
		add_dialog_str(0,"This is the direction the woman ran in. Follow her?",0);
		add_dialog_choice(0,"Yes");
		add_dialog_choice(1,"No");
		choice = run_dialog(1);
		
		if (choice == 1) {
				move_to_new_town(46,22,42);
				end();
				}
		
		if (choice == 2)
				end();
		}
	message_dialog("You wouldn't want to leave the village before you at least made sure also the shops are deserted, would you?","");
break;