//Town script for town 12: fort filbert

begintownscript;

variables;

int day1,day2,choice,tick1,tick2,tick3;

body;

beginstate INIT_STATE;
	set_crime_tolerance(3);

	set_name(6,"Commander Johnson");
	set_name(7,"Kellin");
	set_name(8,"Lieutenant Furginson");
	set_name(42,"Sergeant Peter");
	set_name(56,"General Flamington");

	if (get_flag(12,11) == 1) {
			erase_char(6);
			set_flag(12,12,1);
			}
			
	if (get_flag(28,1) == 1) { // You got the quest
			if (get_flag(12,15) != 2) { // Johnson didn't already return to his room
					if (get_flag(12,10) != 1) { // You still didn't find the note
							relocate_character(6,29,11);
							}
					}
			}
	
	if (get_flag(12,16) == 1) {
			if (get_flag(12,12) != 1) {
					activate_hidden_group(12);
					}
			}
	
	if (get_flag(12,12) == 1) {
			erase_char(70);
			erase_char(71);
			erase_char(72);
			set_flag(12,17,1); // you are no longer stopped upon entry of the fort
			}

break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
	
	// start scenario dialog, put it here for convenience
	
	if (get_flag(275,3) == 0) {
			set_state_continue(19);
			}
			
	
	
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(6,"All these problems");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(6,"What should I do?");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(8,"Should find successor");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(8,"But where to look?");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(42,"Slurp... Slurp");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(41,"Zzzzzz");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(56,"I can solve puzzles");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(56,"Yawn");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(21,"Slurp");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(46,"Slurp");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(46,"Cough");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(18,"Yawn");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(45,"Hmmm");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(45,"*Think*");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(27,"Yawn");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(43,"Meow");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(67,"Baaaa");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(68,"Baaaa");

if (get_flag(12,12) == 1) {
		if (get_flag(12,13) == 0) {
				message_dialog("After Commander Johnson's arrest, the soldiers here look at you with suspicion. They don't really seem to like you for doing that, but at the same time they also seem to be slightly shocked.","Their Commander Johnson: a traitor? They didn't expect that, did they?");
				set_flag(12,13,1);
				}
		}
		
if (get_flag(16,0) == 9) {
		activate_hidden_group(9);
		set_flag(200,1,1);
		}

	if (get_flag(12,15) == 1) {
			tick1 = (get_flag(250,9) * 256 + get_flag(250,10));
			
			tick2 = (get_current_tick() - 26);
			
			tick3 = (tick2 - tick1);
			
			if (tick3 == 0) {
					if (get_flag(12,10) != 1) {
							message_dialog("You hear steps on the corridor. It seems that Commander Johnson is returning to his room. You quickly stop searching the room, and wait for Commander Johnson to enter.","You didn't have the time to find anything unnoticed, which is a pity. Whatever you will find, Commander Johnson will know of you finding it.");
							relocate_character(6,14,11);
							force_instant_terrain_redraw();
							set_flag(12,15,2);
							end();
							}
						if (get_flag(12,10) == 1) {
								message_dialog("You hear steps on the corridor. It seems that Commander Johnson is returning to his room. luckily you already found the note.","");
								relocate_character(6,14,11);
								force_instant_terrain_redraw();
								set_flag(12,15,2);
								end();
								}
						}
			}

break;

beginstate 10;
if (get_flag(12,16) == 1) {
		if (get_flag(12,17) == 0) {
				message_dialog("You approach the guards, hoping they would let you pass, but they don't. They push you back roughly.","Until you bring the note you found to Mayor Arbuckle, you won't be able to enter this place.");
				block_entry(1);
				end();
				}
		}

if (get_flag(12,6) < 2) {	
		message_dialog("You surely don't want to leave the fort without talking to the two commanding officers of the fort, do you?","");
		block_entry(1);
		end();
		}
		
if (get_flag(12,7) < 2) {		
		message_dialog("You surely don't want to leave the fort without talking to the two commanding officers of the fort, do you?","");
		block_entry(1);
		end();
		}
		
if (get_flag(12,2) == 1)				
		end();
	message_dialog("You are about to leave the fort, leave a safe (for now) place with (not very) good food. A place to rest. Its your choice, but if you want to rest, you know where you should be.","");
	set_flag(12,2,1);
break;

beginstate 11;
if (get_flag(12,6) == 0) {
	message_dialog("When you walk out of the room, you find a note on the door:","_Come to see us_, signed, General Flamington and Commander Johnson.");
	set_flag(12,6,1);
	set_flag(12,7,1);
	}
break;

beginstate 12;
reset_dialog();
if (get_flag(12,9) == 1) {
		if (get_flag(12,8) == 0) {
			add_dialog_str(0,"You once again return to the room you slept in the first night you were in Riverrod. Somehow, it feels pleasant to be back again. It gives you a sense of safety.",0);
			add_dialog_str(1,"You could rest here undisturbed for a while. Would you like to?",0);
			set_flag(12,8,1);
			}
		else
			add_dialog_str(0,"You once again go back to your room. Would you like to rest here?",0);
		add_dialog_choice(0,"Don't rest.");
		add_dialog_choice(1,"Rest.");
		if (run_dialog(1) == 2)
			{revive_party();
			set_ticks_forward(5000);
			message_dialog("You rest peacefully and uninterrupted. You already feel a lot better.","");
			}
		}
break;

beginstate 13;
if (get_flag(12,9) == 0)
		set_flag(12,9,1);
break;

beginstate 14;
if (get_flag(12,15) != 2) {
		if (get_flag(28,1) == 1) {
				if (get_flag(12,10) == 0) {
						message_dialog("You search through Commander Johnson's clothes. Surprisingly, you find a small note. It says something about the Senarti. Better get this to Mayor Arbuckle right away.","You pocket the note.");
						change_spec_item(1,1);
						set_flag(12,10,1);
						end();
						}
				}
		}

if (get_flag(12,15) == 2) {
		if (get_flag(28,1) == 1) {
				if (get_flag(12,10) == 0) {
						message_dialog("You search through Commander Johnson's closets and such, and you finally start searching this particular dresser. For some reason Commander Johnson doesn't want you to search it, though.","He tries to stop you, but before he can cry for help or anything, you find a small note. You should bring it to Mayor Arbuckle straight away.");
						
						message_dialog("As soon as you pocket the note, you look around. You can't seem to find Commander Johnson anywhere. He is gone. You wait a while.","After a few minutes, he comes back, escorted by several guards. You are brought to the gate.");
						
						set_total_visibility(1);
						force_view_center(38,24);
					
						relocate_character(0,36,24); // party moved to gate
						relocate_character(1,37,24);
						relocate_character(2,38,24);
						relocate_character(3,39,24);
						relocate_character(4,40,24);
						relocate_character(5,41,24);
						
						set_character_facing(0,2); // Let party face the guards
						set_character_facing(1,2);
						set_character_facing(2,2);
						set_character_facing(3,2);
						set_character_facing(4,2);
						set_character_facing(5,2);
						
						relocate_character(6,32,24); // commander Johnson and guards placed
						set_character_facing(6,6);
						activate_hidden_group(12);
						force_instant_terrain_redraw();
						
						text_bubble_on_char(6,"");
						force_instant_terrain_redraw();
						pause(20);
						
						text_bubble_on_char(6,"Guards.");
						force_instant_terrain_redraw();
						pause(10);
						
						text_bubble_on_char(6,"");
						text_bubble_on_char(6,"Don't let them");
						force_instant_terrain_redraw();
						pause(10);
						
						text_bubble_on_char(6,"");
						text_bubble_on_char(6,"enter this fort");
						force_instant_terrain_redraw();
						pause(10);
						
						text_bubble_on_char(6,"");
						text_bubble_on_char(6,"again.");
						force_instant_terrain_redraw();
						pause(10);
						
						text_bubble_on_char(6,"");
						force_instant_terrain_redraw();
						pause(10);
						
						text_bubble_on_char(70,"Yes sir");
						text_bubble_on_char(71,"Yes sir");
						text_bubble_on_char(72,"Yes sir");
						force_instant_terrain_redraw();
						pause(10);
						
						text_bubble_on_char(70,"");
						text_bubble_on_char(71,"");
						text_bubble_on_char(72,"");
						force_instant_terrain_redraw();
						pause(10);
						
						text_bubble_on_char(6,"Good.");
						force_instant_terrain_redraw();
						pause(10);
						
						text_bubble_on_char(6,"");
						force_instant_terrain_redraw();
						pause(20);
						
						set_character_facing(6,2); // commander Johnson walks away
						force_instant_terrain_redraw();
						pause(10);
						
						relocate_character(6,31,24);
						force_instant_terrain_redraw();
						pause(5);
						
						relocate_character(6,30,24);
						force_instant_terrain_redraw();
						pause(5);
						
						relocate_character(6,29,24);
						force_instant_terrain_redraw();
						pause(5);
						
						relocate_character(6,28,24);
						force_instant_terrain_redraw();
						pause(5);
						
						relocate_character(6,27,24);
						force_instant_terrain_redraw();
						pause(5);
						
						relocate_character(6,26,24);
						force_instant_terrain_redraw();
						pause(5);
						
						relocate_character(6,25,24);
						force_instant_terrain_redraw();
						pause(5);
						
						relocate_character(6,14,11);
						force_instant_terrain_redraw();
						pause(5);
						
						change_spec_item(1,1);
						set_flag(12,10,1);
						set_flag(12,16,1); // Can't enter fort until com Johnson is arrested
						
						set_total_visibility(0);
						force_instant_terrain_redraw();
						
						move_to_new_town(12,40,24);
						end();
						}
				}
		}

break;

beginstate 15;
if (get_flag(12,14) == 1)
		end();
	message_dialog("The temple of Fort Filbert is big and dusty. It hasn't been in operation for quite some time, or so it seems, which is a pity. It's a beautiful structure.","What surprises you here, are the two altars. A temple usually has only one altar. As you glance around, though, you see two big paintings. Two gods are being honoured here.");
	set_flag(12,14,1);
break;

beginstate 16;
	message_dialog("As you pass this huge painting, you give a quick look at it. Its a painting of a god in the forest. Under it, on a small gold sign, it says _Beorgrunt, God of War._","");
break;

beginstate 17;
	message_dialog("The painting on this wall portrays a Goddess, sitting at the waterside of a lake. She is very beautiful. She looks at the water. You look down, where a small sign has hung. It says _Fomdel, Goddess of Luck and Wealth._","");
break;

beginstate 18;
if (get_flag(28,1) == 1 && get_flag(12,10) != 1 && get_flag(12,15) == 0) {
						message_dialog("You find Commander Johnson, the commanding officer of Fort Filbert, in the dining hall of the high-ranking officers. This would be a very good time to see if you can find anything suspicious in his room.","You must be quick, though, as Commander Johnson can return any minute to his room. This might be your only chance.");
						tick1 = get_current_tick(); // What amount of ticks is it now?
						
						set_flag(250,9,tick1 / 256);
						set_flag(250,10,tick1 % 256);
						
						set_flag(12,15,1);
						}
break;

beginstate 19;
	

	reset_dialog();
	add_dialog_str(0,"As you noticed, you didn't get an intro story. This is deliberate, as you will get it now. You can choose between three options: No story at all, a normal text, or a cutscene.",0);
	add_dialog_choice(0,"No story");
	add_dialog_choice(1,"Only text");
	add_dialog_choice(2,"Cutscene");
	choice = run_dialog(1);

	if (choice == 1) {
			set_flag(275,3,1);
			end();
			}
			
	if (choice == 2) {
			set_flag(275,3,2);
			}
	
	if (choice == 3) {
			set_flag(275,3,3);
			}


message_dialog("Now please take a step in whatever direction to let your chosen option take effect.","");

break;

beginstate 20;
if (get_flag(275,4) == 0) {

	if (get_flag(275,3) == 1) {
			set_flag(275,4,1);
			end();
			}
			
	if (get_flag(275,3) == 2) {
			set_flag(275,4,1);
			move_to_new_town(48,25,22); // Move party to blackness town
			}
	
	if (get_flag(275,3) == 3) {
			set_flag(275,4,1);
			move_to_new_town(45,24,37); // Move party to first cutscene town
			}
	}
break;