// TOWN SCRIPT
//    Town 3: Marralis

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

int i,j,k,r1,choice;

body;

beginstate INIT_STATE;
	if (get_flag(0,16) == 250) {
		erase_char(40);
		}
	if (get_flag(4,5) >= 2) {
		erase_char(6);
		erase_char(8);
		erase_char(10);
		}
	if (get_flag(4,5) >= 25) {
		activate_hidden_group(1);
		}
	if (get_flag(2,11) == 250) {
		erase_char(15);
		activate_hidden_group(3);
		}
// This state called whenever this town is entered.
	set_name(40,"Deadeye");
	set_name(34,"Marissa");
	set_name(52,"Portia");
	set_name(66,"Manucher");
	set_name(58,"Duneflin");
	//set_name(49,"Portia");
	set_name(42,"Warren");
	set_name(41,"Prig");
	set_name(33,"Mazeura");
	set_name(22,"Moodie");
	set_name(9,"Cynthia");
	set_name(28,"Captain Hobbes");
	set_name(10,"Lady Keria");

	enable_add_chars(1);

	set_crime_tolerance(3);
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// Starting state of the town, called every turn until you change the state.
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(9,"So much work");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(9,"Busy, busy, busy");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(28,"Move those troops there");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(28,"Must recruit more");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(34,"I just love to bake!");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(40,"Perfect shot!");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(40,"That's a kill");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(42,"Combine these");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(42,"Is that poisonous?");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(42,"Do you smell something?");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(33,"Helios is glorious!");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(33,"Megiddo is blessed");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(22,"Harder");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(22,"Better");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(22,"Faster");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(22,"Stronger");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(59,"Not worth my time");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(59,"Degenerates");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(66,"More paper");
	if (get_ran(1,0,100) < 6)
		text_bubble_on_char(66,"I'm rich!");
	if (get_flag(2,11) == 250) {
		set_terrain_memory_cell(5,0,0);
		}
break;

beginstate 10;
	if (get_flag(0,1) == 250)
		end();
	message_dialog("Manucher the moneylender shouts at you, _Hey! What do you think you're doing?_ He draws his sword. You can hear shouting from the thugs outside as well. Oops.","");
	set_flag(0,1,250);
	set_attitude(60,10);
	alert_char(60);
	set_attitude(61,10);
	alert_char(61);
	set_attitude(68,10);
	alert_char(68);
	set_attitude(69,10);
	alert_char(69);
	set_attitude(66,10);
	alert_char(66);
break;

beginstate 11;
	if (get_flag(0,2) == 250)
		end();
	message_dialog("From here, you have a decent view of the courtyard of Megiddo Palace. It is dominated by a statue of Helios, the mythical guardian of Megiddo. It is said that God himself immortalized Helios in the form of the sun.","The symbol of the royalty of Megiddo, two crosses overlaid upon each other, serve to represent the light of Helios. This symbolism is repeated in the shape of the courtyard.");
	set_flag(0,2,250);
break;

beginstate 12;
	if (get_flag(0,3) == 250)
		end();
	message_dialog("The motif of the Megiddo double crosses is repeated here. There are fires kept burning in this courtyard, symbolizing the eternal guardianship of Helios. But there is no statue of Helios, only of Lord Kato.","He is the one responsible for bringing Megiddo into a new age of prosperity. Doubtless he paid quite a sum to have his own statue be placed here. He and his family are very wealthy, and very powerful.");
	set_flag(0,3,250);
break;

beginstate 13;
	if (get_flag(0,4) == 250)
		end();
	message_dialog("The owner of this shop looks to be a noble, from his style of dress and generally high hygiene. It's strange that he would himself work, and especially at a job so menial as blacksmith. But on closer inspection, this isn't a blacksmith.","This man a goldsmith, presumably making the owner one of the wealthiest and most skilled people in the nation of Megiddo. He appraises you, trying to gauge how much money you might spend here. He doesn't seem happy.");
	set_flag(0,4,250);
break;

beginstate 14;
	if (char_dist_to_loc(52,54,39) > 3) {
		print_str("The innkeeper doesn't notice you slipping by.");
		end();
		}
	message_dialog("_Hey,_ the innkeeper shouts. _Just what are you up to?!_","");
	change_crime_level(1);
break;

beginstate 15;
	if (get_flag(0,5) == 250)
		end();
	message_dialog("You look at the entrance hall of the Megiddo University, designed to impress and inspire visitors. It is small and cramped and smells vaguely of herbs. Typical place of higher learning.","");
	set_flag(0,5,250);
break;

beginstate 16;
	if (get_flag(0,6) == 250)
			end();
	message_dialog("This tiny hallway is meant as the place of study for students of Megiddo University. It is very quiet, because the place is empty save one student, dilligently reading his texts.","");
	set_flag(0,6,250);
break;

beginstate 17;
	if (get_flag(0,7) == 250)
			end();
	message_dialog("This place appears to be a temple to Helios, based upon the eternal fires outside and the eight-point sun symbols on the walls. These temples also typically serve as meeting places for the people.","");
	set_flag(0,7,250);
break;

beginstate 18;
	if (get_flag(0,8) == 250) {
			block_entry(0);
			if (get_flag(0,9) == 250) {
				print_str("The statue watches you, but does nothing. Maybe it's suffering");
				print_str("from low morale.");
				end();
				}
			message_dialog("The statue actually moves, turning toward you as you come nearer. It's obviously enchanted to guard the door. But it doesn't stop you as you try the door.","");
			set_flag(0,9,250);
			end();
			}
	message_dialog("The statue here seems to have been enchanted. As you move closer to the door, it actually moves to block your way. _None but those who the mistress permits may enter._ It seems very firm on the point.","");
	block_entry(1);
break;

beginstate 19;
	if (get_flag(0,10) == 250)
		end();
	message_dialog("This cozy little room is a place where injured and maimed soldiers are brought, to recuperate and receive treatment. Servants have done their best, but the stale smell of rot and blood still lingers in the air.","");
	set_flag(0,10,250);
break;

beginstate 20;
	if (get_flag(0,20) == 250)
		end();
	message_dialog("The Watchman eyes you. He's probably waiting for you to something which he can attack you for. Given his position, it seems likely that he's here to guard the stairs.","It would be best if you simply didn't tempt him. The Watchmen of Megiddo are not known for their leniency; they are known for their deadly skill.");
	set_flag(0,20,250);
break;

beginstate 21;
	if (get_flag(0,21) == 250)
		end();
	message_dialog("This large chamber is probably the official throne room. But King Valion is known for his disdain of formality, preferring a more hands-on approach to leadership.","");
	set_flag(0,21,250);
break;

beginstate 22;
	message_dialog("The guard behind you halts you. _What business have you there?_ Lacking a good answer, you are forced to hang back and think up an excuse to go upstairs.","You don't think of one.");
	block_entry(1);
break;

beginstate 23;
	if (get_flag(0,17) == 250) {
		block_entry(0);
		end();
		}
	message_dialog("_You cannot enter!_ the assistant hisses. _What business have you, speaking to the king?_ You don't have a good answer, so you have to turn back.","");
	block_entry(1);
break;

beginstate 24;
	if (get_flag(2,11) == 250) {
		print_str("The guard eyes you resentfully, but lets you pass.");
		block_entry(0);
		end();
		}
	message_dialog("The door guard here looks at you with skepticism. _None may pass,_ he grunts. You try to convince him to allow you through. He gives you a vacant stare. _None may pass._","");
	block_entry(1);
break;

beginstate 25;
	if (get_flag(0,13) >= 25)
		end();
	if (get_flag(0,13) == 0) {
		print_str("There appears to be a pool of dried blood in the corner");
		print_str("of this room. How odd.");
		end();
		}
	if (get_flag(0,14) == 250)
		end();
	set_flag(0,14,25);
	set_flag(0,13,25);
	message_dialog("This is the custodian's room that Captain Hobbes talked about. And in the corner of the room, you can see a pool of what's probably human blood. There's no body though. There's also a dagger, which seems strange amongst the custodian's tools.","Captain Hobbes will probably want to hear about this.");
break;

beginstate 26;
	if (get_flag(4,5) == 2) {
		reset_dialog();
		add_dialog_str(1,"You hurry back to Megiddo Tower. You must make sure that Lady Keria does not escape. Hopefully General Seth is already there; he had a good head start on you.",0);
		add_dialog_str(2,"Suddenly, you hear shouting and a loud booming sound from the Tower. Megiddo is rocked by one of its typical earthquakes... but strangely, you are struck by blindness as well. You can hear someone shuffling past you on unsteady feet.",0);
		add_dialog_str(3,"As quickly as the blindness takes you, it disappears. What was that? Some sort of dark magic? You had better hurry to the Tower.",0);
		i = run_dialog(1);
		
		erase_char(6);
		erase_char(8);
		erase_char(10);
		activate_hidden_group(1);
		set_flag(4,5,25);
		run_animation();
		}
break;

beginstate 27;
	if (get_flag(0,23) == 250) {
		end();
		}
	set_flag(0,23,250);
	message_dialog("Among the notes and papers stored here, something catches your eye. A scrap of paper says _Keria - make sure you kill the janitor. Cover all your tracks._","Searching for more information, you see another similarly styled note. It says _You should create a distraction before you move against the King. Try the Hunan; it's in our interests._");
break;

beginstate 28;
	if (get_flag(0,27) == 250) {
		end();
		}
	set_flag(0,27,250);
	message_dialog("The guards of Megiddo Tower watch you closely. The Tower itself is the marble building to the north; you heard someone named _Cynthia_ in the Tower had a quest.","");
break;

beginstate 29;
	if (get_flag(0,29) == 250) {
		end();
		}
	set_flag(0,29,250);
	message_dialog("_This is your first and last warning,_ the man behind you calls. _Get away from that door._","");
break;