// Town script for town 35: third power source

begintownscript;

variables;

int choice,x,i,j,tick1,tick2,tick3,flag10;

body;

beginstate INIT_STATE;

if (get_flag(35,0) == 1) {
		set_terrain(36,39,388);
		set_terrain(39,39,388);
		set_terrain(42,39,388);
		set_terrain(45,39,388);
		}

if (get_flag(35,11) == 1)
		set_terrain(53,47,384);

if (get_flag(35,12) == 1)
		set_terrain(56,44,384);

break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;

// recharge of control panel town 32

if (get_flag(32,0) == 3) {
	if (get_flag(35,11) == 1) {
			if (get_flag(35,12) == 1) {
					if (get_flag(32,1) == 1) {
							set_flag(32,1,0);
							}
					}
			}
	}

break;

beginstate 10;
move_to_new_town(32,27,15);
break;

beginstate 11;
if (get_flag(35,1) == 1)
		end();
	message_dialog("As you walk down this corridor, the humming of machines gets louder.","");
	set_flag(35,1,1);
break;

beginstate 12;
if (get_flag(35,2) == 1)
		end();
	message_dialog("You walk on. However, now you also hear a soft mumbling coming from the walls. It is as if people are talking nearby.","");
	set_flag(35,2,1);
break;

beginstate 13;
if (get_flag(35,3) == 1)
		end();
	message_dialog("You finally arrive at the end of the corridor. In front of you are three windows. You walk there to see what there is to see.","");
	
	march_party(26,32);
	force_instant_terrain_redraw();
	pause(8);
	
	march_party(27,32);
	force_instant_terrain_redraw();
	pause(8);
	
	march_party(28,32);
	force_instant_terrain_redraw();
	pause(15);
	
	text_bubble_on_char(0,"Wow");
	force_instant_terrain_redraw();
	pause(15);
	
	text_bubble_on_char(0,"");
	force_instant_terrain_redraw();
	pause(10);
	
	message_dialog("In front of you is the last place to demolish. The last place that holds you from warning Mayor Ruth. You must destroy it, thereby delivering a very serious blow to Thralni's defences.","");
	
	message_dialog("You now look into the corridors. They are big and very beautiful. Enormous statues decorate the walls.","");

	set_flag(35,3,1);

	move_to_new_town(35,28,32);
break;

beginstate 14;
if (get_flag(35,4) == 1)
		end();
	message_dialog("You walk into the chamber and see several surprised soldiers sitting in this small dining hall. This must be the place where the mumbling you heard at the entrance corridor came from.","");
	set_flag(35,4,1);
break;

beginstate 15;
if (get_flag(35,5) == 1)
		end();
	message_dialog("A wizard and two officials sit in the three chairs in front and either side of you. These must be the ones who control these underground power plants and see to it everything works normally.","");
	set_flag(35,5,1);
break;

beginstate 16;
if (get_flag(35,6) == 1)
		end();
	message_dialog("This chamber is very beautiful. You suspect these are the chambers where Thralni stays when he comes to inspect the three power plants.","");
	set_flag(35,6,1);
break;

beginstate 17;
reset_dialog();
add_dialog_str(0,"This pedestal is not the average book stand you are used to. It has a strange line on one side, just under the place where a book should have lain. Maybe you can press it down. Try it?",0);
add_dialog_choice(0,"Press");
add_dialog_choice(1,"Leave it");
choice = run_dialog(1);

	if (choice == 1) {
			message_dialog("You press the upper part of the pedestal down, and it works! The pedestal can be pressed down.","Soon you hear a rumbling sound coming from the bookshelf. It opens. There is some sort corridor behind it.");
			set_terrain(23,58,0);
			set_terrain(22,58,0);
			set_terrain(23,57,235);
			end();
			}
break;

beginstate 18;
if (get_flag(35,7) == 1)
		end();
	flag10 = get_ran(1,0,4);
	set_flag(35,8,flag10);
	
	message_dialog("Upon passing the statue it begins to speak in a loud, clear voice: Thou shall only pass, upon answering my question. When thou has answered these questions three, the passage can be walked on by thee.","However, If thou doesn't respond to them correctly, respect my power, and stay where thou are.");
	
	message_dialog("Note that upon answering you shouldn't say things like _a statue,_ but simply _statue._ Also, for names of cities and countries, use a capital letter, as in _Chicago._","");
	
	message_dialog("WHAT is your name!?","");
	
	get_text_response("What do you say?");
	
	message_dialog("WHAT is your quest!?","");
	
	get_text_response("What do you say?");
	
	if (get_flag(35,8) == 0) {
			message_dialog("WHAT is your favorite color!?","");
			
			get_text_response("What do you say?");
			
			message_dialog("_Okay, you can pass now. Have a nice day!_","");
			set_flag(35,7,1);
			end();
			}
	
	if (get_flag(35,8) == 1) {
			message_dialog("WHAT is the capital of The Netherlands!?","");
			
			get_text_response("What do you say?");
			
			check_text_response_match("Amsterdam");
			if (got_text_match()) {
					message_dialog("_Okay, you can pass now. Have a nice day!_","");
					set_flag(35,7,1);
					end();
					}
			
			message_dialog("_Oh, I'm so sorry, but you can't pass. That was wrong._","");
			block_entry(1);
			end();
			}
	
	if (get_flag(35,8) == 2) {
			message_dialog("WHAT Empire is the villain!?","");
			
			get_text_response("What do you say?");
			
			check_text_response_match("Empire");
			if (got_text_match()) {
					message_dialog("_Okay, you can pass now. Have a nice day!_","");
					set_flag(35,7,1);
					end();
					}
			
			message_dialog("_Oh, I'm so sorry, but you can't pass. That was wrong._","");
			block_entry(1);
			end();
			}
	
	if (get_flag(35,8) == 3) {
			message_dialog("WHAT are the Senarti!?","");
			
			get_text_response("What do you say?");
			
			check_text_response_match("cats");
			if (got_text_match()) {
					message_dialog("_Okay, you can pass now. Have a nice day!_","");
					set_flag(35,7,1);
					end();
					}
			
			message_dialog("_Oh, I'm so sorry, but you can't pass. That was wrong._","");
			block_entry(1);
			end();
			}
	
	if (get_flag(35,8) == 4) {
			message_dialog("WHAT is the next number in this row!?","2, 3 ,5, 8, 13, 21, 34, 55, 89, 144, ...");
			
			get_text_response("What do you say?");
			
			check_text_response_match("233");
			if (got_text_match()) {
					message_dialog("_Okay, you can pass now. Have a nice day!_","");
					set_flag(35,7,1);
					end();
					}
			
			message_dialog("_Oh, I'm so sorry, but you can't pass. That was wrong._","");
			block_entry(1);
			end();
			}
break;

beginstate 19;
if (get_flag(35,9) == 1)
		end();
	message_dialog("Horrible things must have happened here. In one corner of this room, you see a pentagram with blood on it. It looks quite fresh. In another corner you see two levers.","");
	set_flag(35,9,1);
break;

beginstate 20;
message_dialog("This lever is locked in its position. Probably to make sure people like you, who obviously don't know what the lever does, don't pull it.","");
break;

beginstate 21;
reset_dialog();
add_dialog_str(0,"Even though the whole place is currently off-line, this control panel still seems to be working. There is one big, red button. Press it?",0);
add_dialog_choice(0,"Press it");
add_dialog_choice(1,"Leave it");
choice = run_dialog(1);

	if (choice == 1) {
			if (get_flag(35,10) == 0) {
					message_dialog("You press the button and wait. You hear the lasers in the room in front of you humming slightly, with growing intensity.","Through a loudspeaker you only discovered now, you hear the following: _Please pull levers to recharge button power sources._ This thing is to reactivate the control panel in the small room that got you here!");
					set_flag(35,10,1);
					end();
					}
				message_dialog("You press the button and wait. The panel cools off. You turned it off.","");
				set_flag(35,10,0);
				end();
				}
break;

beginstate 22;
if (get_flag(35,13) == 1)
		end();
	message_dialog("This is the control room. Wizards, with the same uniform as the wizards you saw in the previous power plant, are sitting at the controls. Some fancy-dressed man is walking around and looking through the windows.","If you can blow the place up at all, this is the place you should be. However, because this seems to be the biggest power plant of them all, it may be unusually well protected.");
	set_flag(35,13,1);
break;

beginstate 23;
if (get_flag(35,14) == 1)
		end();
	message_dialog("You are in luck. This is some kind of small back room. There is nothing here, except a bookshelf.","");
	set_flag(35,14,1);
break;

beginstate 24;
if (get_flag(35,15) == 1)
		end();
	message_dialog("You search the shelves, and find a small piece of paper. There are small symbols on it. This may have been your lucky day!","You pocket the note and leave.");
	char_give_item(0,483);
	set_flag(35,15,1);
break;

beginstate 25;
if (get_flag(35,0) == 1) {
		message_dialog("The whole place is off-line, and so is this control panel. You can push the buttons as you please, as nothing will happen anyway.","");
		end();
		}

reset_dialog();
add_dialog_str(0,"The panel is small and has few buttons. This seems strange. After all, this power plant is the biggest of the three.",0);
add_dialog_str(1,"The buttons that are there, however, can be pressed. There is a blue and a green button. This upsets you, as you had actually wanted to see a red one. Maybe another panel has one, though. Press a button?",0);
add_dialog_choice(0,"Green");
add_dialog_choice(1,"Blue");
add_dialog_choice(2,"None");
choice = run_dialog(1);

	if (choice == 1) {
			if (get_flag(35,16) == 1) {
					message_dialog("You press the green button. A small light starts blinking under the button. Three times, and then it stops.","");
					set_flag(35,16,2);
					end();
					}
				message_dialog("You press the button, but nothing happens. Maybe you pressed the wrong button or something?","");
				end();
				}
	
	if (choice == 2) {
			if (get_flag(35,16) == 0) {
					message_dialog("You press the blue button. A small light starts blinking under the button. Three times, and then it stops.","");
					set_flag(35,16,1);
					end();
					}
				message_dialog("You press the button, but nothing happens. Maybe you pressed the wrong button or something?","");
				end();
				}
	
	if (choice == 3)
			end();

break;

beginstate 26;
if (get_flag(35,0) == 1) {
		message_dialog("The whole place is off-line, and so is this control panel. You can push the buttons as you please, as nothing will happen anyway.","");
		end();
		}

reset_dialog();
add_dialog_str(0,"The panel is small and has few buttons. This seems strange. After all, this power plant is the biggest of the three.",0);
add_dialog_str(1,"The buttons that are there, however, can be pressed. There is a purple and a red button. You feel relieved. The panel has a red button.",0);
add_dialog_choice(0,"Purple");
add_dialog_choice(1,"Red");
add_dialog_choice(2,"None");
choice = run_dialog(1);

	if (choice == 1) {
			if (get_flag(35,16) == 3) {
					message_dialog("You press the purple button. A small light starts blinking under the button. Three times, and then it stops.","");
					set_flag(35,16,4);
					end();
					}
				message_dialog("You press the button, but nothing happens. Maybe you pressed the wrong button or something?","");
				end();
				}
	
	if (choice == 2) {
			if (get_flag(35,16) == 2) {
					message_dialog("You press the red button. A small light starts blinking under the button. Three times, and then it stops.","");
					set_flag(35,16,3);
					end();
					}
				message_dialog("You press the button, but nothing happens. Maybe you pressed the wrong button or something?","");
				end();
				}
	
	if (choice == 3)
			end();

break;

beginstate 27;
if (get_flag(35,0) == 1) {
		message_dialog("The whole place is off-line, and so is this control panel. You can push the buttons as you please, as nothing will happen anyway.","");
		end();
		}

reset_dialog();
add_dialog_str(0,"This is a big basalt pillar. You have difficulty looking at the upper part of the pillar, as it is so high. You can see though, that there is a big red button on it.",0);
add_dialog_str(1,"The button does nothing at the moment. It is quite dusty too. You could try to press the button. Do you?",0);
add_dialog_choice(0,"Press it");
add_dialog_choice(1,"Leave it");
choice = run_dialog(1);

	if (choice == 1) {
			if (get_flag(35,17) == 4) {
					if (get_flag(35,16) == 4) {
							message_dialog("You press the button. First there happens nothing. Then, the button starts blinking, and the halls quiet down. A cloud of dust settles on the ground. A voice coming out of the pillar, it seems, starts speaking:","Power plant off-line. Stupid idiots. How are you going to turn it on again!? Eh? How? You will need an enormous amount of energy, did you know that!?");
							message_dialog("The voice stops speaking. It seems as though shutting this place down was a very wise move. It looks like the place will be off-line for a long time now.","");
							set_flag(35,0,1);
							set_terrain(36,39,388);
							set_terrain(39,39,388);
							set_terrain(42,39,388);
							set_terrain(45,39,388);
							force_instant_terrain_redraw();
							end();
							}
					}
				message_dialog("You press the button, but nothing happens. You must have forgot to do something.","");
				}
break;