//Town script for town 4: level 0

begintownscript;

variables;
int choice,tick_start,tick2;
short x,y,tick_field;

body;

beginstate INIT_STATE;
if (get_flag(4,14) > 0) // if party leaves town for whatever reason and HIM is not killed yet, make HIM hostile again once the party returns into town
		set_attitude(6,10);
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
tick_field = get_flag(200,3) * 256 + get_flag(200,4);
if (get_flag(4,14) == 1 && get_current_tick() == (tick_field + 3)) {
		x = 22;
		y = 33;

		while (x < 34 && y < 44) { // place antimagic fields. NOTE: x and y are one to big, since otherwise the fields are not placed on all needed spots!
			put_field_on_space(x,y,2);

			x = x +1;
			if (x > 33) {
				x = 22;
				y = y + 1;
				}
			}
			tick_field = get_current_tick();
			set_flag(200,3,tick_field / 256);
			set_flag(200,4,tick_field % 256);
		}


if (get_flag(4,1) == 1) {

		tick_start = get_flag(200,2);
		tick2 = get_flag(200,1);

		if (tick2 == 0) {
				print_str("Another quake, we must hurry!");
				force_view_center((char_loc_x(0) - 1),(char_loc_y(0) + 1));
				force_instant_terrain_redraw();
				pause(3);
				force_view_center((char_loc_x(0) + 2),(char_loc_y(0) - 2));
				force_instant_terrain_redraw();
				pause(3);
				force_view_center((char_loc_x(0) - 2),(char_loc_y(0) + 2));
				force_instant_terrain_redraw();
				pause(2);
				force_view_center((char_loc_x(0) + 2),(char_loc_y(0) - 2));
				force_instant_terrain_redraw();
				pause(2);
				force_view_center((char_loc_x(0) - 2),(char_loc_y(0) + 2));
				force_instant_terrain_redraw();
				pause(2);
				force_view_center((char_loc_x(0) + 3),(char_loc_y(0) - 3));
				force_instant_terrain_redraw();
				pause(1);
				force_view_center((char_loc_x(0) - 3),(char_loc_y(0) + 4));
				force_instant_terrain_redraw();
				pause(1);
				force_view_center((char_loc_x(0) + 3),(char_loc_y(0) - 5));
				force_instant_terrain_redraw();
				pause(1);
				force_view_center((char_loc_x(0) - 3),(char_loc_y(0) + 5));
				force_instant_terrain_redraw();
				pause(1);
				force_view_center((char_loc_x(0) + 3),(char_loc_y(0) - 4));
				force_instant_terrain_redraw();
				pause(2);
				force_view_center((char_loc_x(0) - 3),(char_loc_y(0) + 4));
				force_instant_terrain_redraw();
				pause(2);
				force_view_center((char_loc_x(0) + 3),(char_loc_y(0) - 4));
				force_instant_terrain_redraw();
				pause(2);
				force_view_center((char_loc_x(0) - 3),(char_loc_y(0) + 3));
				force_instant_terrain_redraw();
				pause(2);
				force_view_center((char_loc_x(0) + 2),(char_loc_y(0) - 3));
				force_instant_terrain_redraw();
				pause(3);
				force_view_center((char_loc_x(0) - 2),(char_loc_y(0) + 3));
				force_instant_terrain_redraw();
				pause(3);
				force_view_center((char_loc_x(0) + 2),(char_loc_y(0) - 2));
				force_instant_terrain_redraw();
				pause(3);
				force_view_center((char_loc_x(0) - 2),(char_loc_y(0) + 2));
				force_instant_terrain_redraw();
				pause(3);
				force_view_center((char_loc_x(0) + 1),(char_loc_y(0) - 1));
				force_instant_terrain_redraw();

				if (tick_start == 0)
						tick2 = 15;

				if (tick_start == 15)
						tick2 = 13;

				if (tick_start == 28)
						tick2 = 9;

				if (tick_start == 37)
						tick2 = 7;

				if (tick_start == 44)
						tick2 = 4;

				if (tick_start ==48)
						tick2 = 2;

				if (tick_start == 50) {
						message_dialog("We run and run, but we can't make it. Tired, we fall to the ground, only to be crushed by tons of rock. HIM didn't win, but so didn't we. It was light, then darkness came. The darkness never went away.","");
						end_scenario(0);
						}
				}
		tick2 = tick2 - 1;
		set_flag(200,1,tick2);

		tick_start = tick_start + 1;
		set_flag(200,2,tick_start);
		}

break;

beginstate 10;
	if (get_flag(4,2) == 0) {
			message_dialog("This is weird: after us dragging along these run-down corridors, hallways and caves, it seems these halls are kept well. There are no cobwebs, the walls look fine though a bit bleached and there is no muck on the floor.","To our greatest surprise, the halls here are mildly warm and we can now distinctly hear machinery humming softly in the background. We might be on to HIM.");
			set_flag(4,2,1);
			}

	if (get_flag(4,14) == 1)
			message_dialog("The gates here are closed. Probably one of HIM's tricks. If we want to get out of this place, we'll have to deal with HIM first.","");
break;

beginstate 11;
	if (get_flag(4,3) == 0) {
			message_dialog("When the HMC got abandoned, people obviously didn't take everything with them. Some of the racks here still contain some scrolls. We look at it and realise that there are two possibilities: either the scrolls weren't important enough...","Or they were too late to take these scrolls, instead having to leave them behind, being in favour of living rather than dying. Whoever or whatever HIM is, we already know he can go as far as killing.");
			set_flag(4,3,1);
			}
break;

beginstate 12;
	move_to_new_town(3,4,20);
break;

beginstate 13;
	if (get_flag(4,4) == 0) {
			message_dialog("There it is. HIM. We stand in the door opening and gasp. HIM is not big, not imposing, no computer, not humanoid... what is it anyway? It sits on a pillar. Two machines stand left and right of HIM, and it is quite ugly.","If we wouldn't know any better, we'd say it's a very pitiful, ugly, little boy, but it has nothing that actually resembles a human being. It just sits, pitifully, on it's pillar, staring at us with tiny, wet eyes. We feel it wants us to approach him.");
			set_flag(4,4,1);
			}
break;

beginstate 14;
	if (get_flag(4,5) == 0) {
			message_dialog("Whoever this is, he is dead. We stand bowed over him, and look at his clothes. He was a researcher, wearing some sort of robe. He wears a tag. Picking it up, we read his name aloud: _John_","");
			set_flag(4,5,1);
			}
break;

beginstate 15;
	if (get_flag(4,6) == 0) {
			message_dialog("We walk up the stairs and are greeted by two doors and a dead end. Next to the doors there are small signs. The sign to our right says _HIM,_ the sign to our left says _Memory databanks._","");
			set_flag(4,6,1);
			}
break;

beginstate 16;
	if (get_flag(4,1) == 0) {
			message_dialog("Good, we are almost out of this place! But suddenly, we bump into a wall. Not believing our bad luck, we stumble back and hear HIM.","_You can't leave the HMC without leaving the message you carry. Come to see me. If you need help finding me, walk up to one of the friendly HMC staff members that will more than gladly help you find me._");
			block_entry(1);
			}

	if (get_flag(4,1) == 1) {
			message_dialog("We run out of the HMC and look back once we are at the main entrance. It's a good thing we ran so quickly, otherwise we would have been dead by now.","Amidst the stones, the marble and dust, slowly settling on the ground, it is silent. The humming of machinery has gone. HIM has been defeated, shut down for good. All was darkness, but we returned to the light.");
			end_scenario(1);
			}
break;

beginstate 17;
reset_dialog();
add_dialog_str(0,"We take a scroll from the shelf and read it. It's old paper and the moist hasn't done it good, but here goes.",0);
add_dialog_str(1,"New project has been started, code-name Intelligence. A super computer with human characteristics to aid us to make the HMC an even better and safer place to work. It will handle communications, all circuitry in the facility and will direct the workers.",20);
add_dialog_str(2,"The computer will be in development in the Mine utility Development laboratories by their respective teams. Co-ordinator will be our great boss himself. John and Conrad will lead the science teams. We are all nearing a better future now!",20);
add_dialog_choice(0,"Okay");
choice = run_dialog(1);
if (get_flag(4,15) == 0) {
		award_party_xp(25,20);
		set_flag(4,15,1);
		}
break;

beginstate 18;
reset_dialog();
add_dialog_str(0,"We take a scroll from the shelf and read it. It's old paper and the moist hasn't done it good, but here goes.",0);
add_dialog_str(1,"Intelligence was finished today and tests have begun. So far so good. Inner circuitry and _the brain_ are in good condition, so are the internal vascular motion sensors and inner dynamics. We hope to conclude tests in just under a week.",20);
add_dialog_str(2,"This next bit has been scribbled at the bottom of the page, we look at it.",0);
add_dialog_str(3,"Something has gone wrong while we tested the brain for external hydrofuel leaks. Intelligence reacts differently to stimulants we had previously tested. It is over reacting now.",20);
add_dialog_str(4,"Intelligence is acting strangely, and accidents have been happening here and there. This is nothing new, it is all under control, but we are worried still. Intelligence will be referred to in the future with a new name to reflect its nature: HIM.",20);
add_dialog_choice(0,"Okay");
choice = run_dialog(1);
if (get_flag(4,16) == 0) {
		award_party_xp(25,20);
		set_flag(4,16,1);
		}
break;

beginstate 19;
reset_dialog();
add_dialog_str(0,"We take a scroll from the shelf and read it. It's old paper and the moist hasn't done it good, but here goes.",0);
add_dialog_str(1,"Conrad is dead. Conrad and I worked on this project for so long, and now my colleague is dead. he was buried under tons of rocks. When we got there and removed the rocks, it was already too late.",20);
add_dialog_str(2,"Sadly we didn't have time to remove the body. When we started taking care of that, other parts of the cave started collapsing. His body is still there, and nobody dares to go back, in fear of more cave-quakes.",20);
add_dialog_str(3,"I'm sure these quakes aren't natural, something is causing them. I'm afraid to think it, but it might be HIM. If that's the case, we should shut it down.",20);
add_dialog_choice(0,"Okay");
choice = run_dialog(1);
if (get_flag(4,17) == 0) {
		award_party_xp(25,20);
		set_flag(4,17,1);
		}
break;

beginstate 20;
reset_dialog();
add_dialog_str(0,"We take a scroll from the shelf and read it. It's old paper and the moist hasn't done it good, but here goes. The handwriting on the scroll is different though. Somebody else wrote it.",0);
add_dialog_str(1,"John has been killed. With a few men we went in to HIM's chamber, but it refused our proposals. Talking didn't help, so we tried to fight, using spells and weapons to destroy it, but we failed. In the meantime, HIM discovered Conrad's death.",20);
add_dialog_str(2,"It was furious. We told him he was the cause, and it started penetrating our minds, cracking them, looking inside. John didn't survive. We did, but barely. We have to evacuate the HMC. Twenty people have been killed, no more will now.",20);
add_dialog_str(3,"It is unfortunate it all must end this way, but it must. We stay and we are doomed. May nobody else come here again.",20);
add_dialog_str(4,"How ironic it is then, us being here. Oh well.",0);
add_dialog_choice(0,"Okay");
choice = run_dialog(1);
if (get_flag(4,18) == 0) {
		award_party_xp(25,20);
		set_flag(4,18,1);
		}
break;

beginstate 21;
	if (get_flag(4,10) == 0) {
			message_dialog("While we walk through this dimly lit corridor, we hear stone crackling. We look down at the ground, and notice small pebbles coming down from the ceiling. Before we know it, we are covered with rocks. Not big enough to kill us, but it hurt quite a bit...","");
			damage_char(0,20,60);
			damage_char(1,20,60);
			damage_char(2,20,60);
			damage_char(3,20,60);
			set_flag(4,10,1);
			}
break;

beginstate 22;
	if (get_flag(4,11) == 0) {
			message_dialog("We come to the a no doubt once beautiful central hall. Looking up to the ceiling, it appears we can see the sky. The lights of stars dance on our faces and we can see a full moon from where we stand.","Now though, this atrium lies in ruins. It is deserted, cobwebs and filth dominate the walls and floors.");
			set_flag(4,11,1);
			}
break;

beginstate 23;
	if (get_flag(4,12) == 0) {
			message_dialog("Wow, what a carnage this room is. The carpet that, by the looks of it, would have been pretty expensive, were it not for the blood and slime smeared all over it. We look around the room and spot a body.","");
			set_flag(4,12,1);
			}
break;

beginstate 24;
	if (get_flag(4,13) == 0) {
			message_dialog("We bow over the body and watch it lying there, on the ground. Something attacked it. Actually, it looks as though he attacked himself. HIM might have done something to him...","There is tag clipped to his coat. It says _Oleg Solysis_. It appears to be the HMC's boss. That is not good.");
			set_flag(4,13,1);
			}
break;

beginstate 25;
	if (get_flag(4,14) == 0) {
			message_dialog("This room is quite warm. When we walk in, we are greeted by a gentle, pleasant hum and warm air. These machines appear to be _Memory Databanks,_ if the sign outdoor is to be believed.","");
			set_flag(4,14,1);
			}
break;

beginstate 26;
	if (get_flag(4,0) == 0) {
			message_dialog("We search through this bookshelf, and when we take out a scroll, a strange, key-like object falls out. We take it with us.","");
			change_spec_item(0,1);
			set_flag(4,0,1);
			}
break;