// Town script for town 34: second power source

begintownscript;

variables;

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

body;

beginstate INIT_STATE;

if (get_flag(34,2) == 1) {
		set_terrain(34,24,385);
		}
		
if (get_flag(34,3) == 1) {
		set_terrain(34,22,385);
		set_terrain(36,41,388);
		}

break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;

// Blew up power sources: message of "its clear what happened now"

if (get_flag(34,0) == 0) {
		if (get_flag(34,2) == 1) {
				if (get_flag(34,3) == 1) {
						message_dialog("Now it is clear what that panel you activated did. It destroyed this whole power plant! Congratulations. Now you have to get out of here, and see how to get to the next power plant.","");
						set_terrain(36,41,388);
						set_terrain(21,22,388);
						force_instant_terrain_redraw();
						set_flag(34,0,1);
						}
				}
		}
			
// recharge of control panel town 32

if (get_flag(32,0) == 2) {
		if (get_flag(34,5) == 1) {
				if (get_flag(34,6) == 1) {
						if (get_flag(32,1) == 1) {
								set_flag(32,1,0);
								}
						}
				}
		}

break;

beginstate 10;
	move_to_new_town(32,19,26);
break;

beginstate 11;
if (get_flag(34,0) == 1) {
		message_dialog("As you blew up this place, the control panel also malfunctions. Better go away before the wizards see what you did.","");
		end();
		}

reset_dialog();
add_dialog_str(0,"This control panel has certainly something to do with the power sources in front of you. In that case, this is probably the thing you should blow up.",0);
add_dialog_str(1,"There are three buttons on this panel of which its clear what they do. There's also a small screen on which you can see the current mode. It reads _Half power mode._ Which button would you like to press?",0);
add_dialog_choice(0,"Off/On");
add_dialog_choice(1,"Half power");
add_dialog_choice(2,"Full power");
choice = run_dialog(1);

	if (choice == 1) {
			message_dialog("The button doesn't seem to work. The wizards here made sure you can't just change the settings and blow the place up.","");
			end();
			}
			
	if (choice == 2) {
			message_dialog("The button doesn't seem to work. The wizards here made sure you can't just change the settings and blow the place up.","");
			end();
			}
	
	if (choice == 3) {
			message_dialog("The button doesn't seem to work. The wizards here made sure you can't just change the settings and blow the place up.","");
			end();
			}
break;

beginstate 12;
if (get_flag(34,0) == 1) {
		message_dialog("As you blew up this place, the control panel also malfunctions. Better go away before the wizards see what you did.","");
		end();
		}

reset_dialog();
add_dialog_str(0,"This lone control panel is turned off. It seems as though you can easily turn it on, though. What would you want to do? Turn it on, off, or cancel the procedure?",0);
add_dialog_choice(0,"Turn it on");
add_dialog_choice(1,"Turn it off");
add_dialog_choice(2,"Leave it be");
choice = run_dialog(1);

	if (choice == 1) {
			if (get_flag(34,1) == 0) {
					message_dialog("You press the ON button (it wasn't very difficult to miss), and the machine starts working. Behind you, you hear a power source activating.","You have no clue of what you just did, but it is sure that whatever it is the panel did, the panel can't be shut off before it is ready.");
					message_dialog("It would be a good thing to start making a run for it. You should head to the exit, or at least the control room you passed to get here, before this place explodes.","");
					set_flag(34,1,1);
					set_terrain(21,22,384);
					end();
					}
			}
	
	if (choice == 2) {
			if (get_flag(34,1) == 1) {
					message_dialog("Turning on the machine before turning it off is often a more logical order of doing things.","");
					end();
					}
				message_dialog("It doesn't seem that the button works. You'll have to wait until the panel has done what it is supposed to do, and then see what happens.","");
				end();
				}
	
	if (choice == 3)
			end();

break;

beginstate 13;
if (get_flag(34,0) == 1) {
		message_dialog("As you blew up this place, the control panel also malfunctions. Better go away before the wizards see what you did.","");
		end();
		}

reset_dialog();
add_dialog_str(0,"This control panel has certainly something to do with the power sources in front of you. In that case, this is probably the thing you should blow up.",0);
add_dialog_str(1,"There are three buttons on this panel of which its clear what they do. There's also a small screen on which you can see the current mode. It reads _half power mode._ Which button would you like to press?",0);
add_dialog_choice(0,"Off/On");
add_dialog_choice(1,"Half power");
add_dialog_choice(2,"Full power");
choice = run_dialog(1);

	if (choice == 1) {
			message_dialog("The thing doesn't seem to work. The wizards here made sure you can't just change the settings and blow the place up.","");
			end();
			}
			
	if (choice == 2) {
			message_dialog("The thing doesn't seem to work. The wizards here made sure you can't just change the settings and blow the place up.","");
			end();
			}
	
	if (choice == 3) {
			message_dialog("The thing doesn't seem to work. The wizards here made sure you can't just change the settings and blow the place up.","");
			end();
			}
break;

beginstate 14;
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(34,4) == 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(34,4,1);
					end();
					}
				message_dialog("You press the button and wait. The panel cools off. You turned it off.","");
				set_flag(34,4,0);
				end();
				}
break;

beginstate 15;
message_dialog("It doesn't seem like this panel will work. Its not broken, far from it actually, but it makes the impression to be highly protected against invaders.","That is if the huge red blinking lights saying _Beware, invaders!_ aren't fake.");
break;

beginstate 16;
if (get_flag(34,7) == 1)
		end();
	message_dialog("When you look down the windows, you see all kinds of machinery. It looks as though two big power sources, at the very left of what you can see, first deliver all energy by firing two beams.","These beams, after being reflected by a whole array of mirrors, end up at three power sources at the very right of what you can see. That must be what delivers power to the middle of the three glowing gates you saw.");
	set_flag(34,7,1);
break;

beginstate 17;
if (get_flag(34,8) == 1)
		end();
	message_dialog("This is the control chamber of the power plant. Maybe here you can find a way to blow this place up. However, you'll first have to get past these three magi.","");
	set_flag(34,8,1);
break;

beginstate 18;
if (get_flag(34,9) == 1)
		end();
	message_dialog("You walk into the power plant's sort of courtyard, where all the laser beams are. The heat is enormous. You must do what you have to do, and get out of this place.","");
	set_flag(34,9,1);
break;

beginstate 19;
if (get_flag(34,10) == 1)
		end();
	message_dialog("This room is nice and air conditioned. There are windows, through which you can look at the beams and power sources, and there is a control panel. A very big red light is blinking on it.","You wonder what it does.");
	set_flag(34,10,1);
break;