// 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(4,5) >= 50) {
		erase_char(10);
		put_stain_on_space(32,43,2);
		}
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(23,"Baaa.");
break;

beginstate 10;
	if (get_flag(5,1) == 250)
		end();
	set_flag(5,1,250);
	message_dialog("You try to read some of the notes that are stored here on the shelf. There is writing about _circuits_ and _pressure._ You can't make sense if it.","");
break;

beginstate 11;
	message_dialog("This looks like a control panel. It probably controls the production of steam in the north chamber, which in turn probably powers the Kato estate's machinery.","Sadly, you have no idea how to use the panel. Oh well.");
break;

beginstate 12;
	if (get_flag(5,2) == 250)
		end();
	set_flag(5,2,250);
	message_dialog("These appear to be the personal notes of Lord Kato. There's lots of useless information, like shipping prices and sales dates. There's some mildly entertaining information, mostly in his personal correspondence.","And then there's loose leaves of paper; some don't look like they're written in Lord Kato's hand. They're covered in precise, neat ink drawings of machinery and descriptions of mechanics.");
break;

beginstate 13;
	if (get_flag(4,5) <= 50) {
		block_entry(1);
		message_dialog("The Kato estate apparently is so essential to Megiddo that it warrants protection by a Watchman; these troops are normally the personal guards of the King himself.","This is one of the more angry, serious Watchmen. He draws his sword when you even get close to the gate.");
		end();
		}
	if (get_flag(5,3) == 250)
		end();
	set_flag(5,3,250);
	message_dialog("Thankfully, you seem to be so close on the heels of Lady Keria that she hasn't had time to close the gates. You should be able to catch her, if you hurry.","However, there is bad news. There appears to have been a guard here. Now his body is gone; only a huge pool of blood remains.");
break;

beginstate 14;
	if (get_flag(5,4) == 250)
		end();
	set_flag(5,4,250);
	message_dialog("Where you thought there was a simple garden, there is actually TREACHERY. As you step into Lord Kato's estate, the peaceful flora of the garden congeals and moves quickly.","The plant life swirls into two masses of vegetation, about man-sized. The two monsters quickly close on you. This is clearly Lady Keria's witchcraft.");
	set_terrain(34,37,0);
	set_terrain(30,35,0);
	activate_hidden_group(1);
break;

beginstate 15;
	if (get_flag(5,5) == 250)
		end();
	reset_dialog();
	add_dialog_str(1,"This looks to be the industrial part of Lord Kato's estate. Although this is the home of Lord Kato, it is also his workshop and his factory. Banks of complex machinery dominate the north half of this room.",0);
	add_dialog_str(2,"The end product of all this machinery is, somehow, reams on reams of paper. That same paper is shipped all over Eidetia, and makes Lord Kato an even wealthier man.",0);
	add_dialog_str(3,"There are also corpses on the floor; they look like they've been burned by magical fire. More victims to be added to Lady Keria's list.",0);
	i = run_dialog(1);
	set_flag(5,5,250);
break;

beginstate 16;
	if (get_flag(5,6) == 250)
		end();
	message_dialog("This room is extrmemly hot and humid. The explanation for why is obvious: in the northwest corner of the room, there is a tank; half water, half superheated fuel.","Whatever it is, it must play a part in Lord Kato's machinery.");
	set_flag(5,6,250);
break;

beginstate 17;
	if (get_flag(5,7) == 250)
		end();
	message_dialog("From here, you can get a better look at Lord Kato's steam machine. It looks like water waits in a reserve, then pours directly into the fuel area by way of a pipe.","This probably creates huge amounts of steam. And overhead, you can see a large vent; it would make sense that the steam passes through there, on to another part of Lord Kato's estate.");
	set_flag(5,7,250);
break;

beginstate 18;
	if (get_flag(5,8) == 250)
		end();
	message_dialog("How fortunate! You find a hidden passageway. It probably leads to a huge treasure chest, or a magic spellbook. Or something very important, very secret, and very dear to Lord Kato.","");
	set_flag(5,8,250);
break;

beginstate 19;
	if (get_flag(5,9) == 250)
		end();
	message_dialog("This appears to be the mausoleum of Lord Kato's family. They have the traditional urns; good followers of Helios burn dead bodies, so that they may ascend to Heaven with Helios.","But there's something off about this room. There's an odd skittering sound... But that can't be right, the room is empty.");
	set_flag(5,9,250);
break;

beginstate 20;
	if (get_flag(5,10) == 250)
		end();
	message_dialog("This looks to be another of the rooms that is essential to Lord Kato's paper-making process. There are several servants running to and fro in this room, doing exciting paper-related things.","They glance at you curiously, but don't dare take a close look. They're probably afraid you're a noble or a taskmaster, come to beat them.");
	set_flag(5,10,250);
break;

beginstate 21;
	if (get_flag(5,11) == 250)
		end();
	message_dialog("Just your luck. You trigger another of Lady Keria's enchanted plant ambushes. Some of the monsters are shaped not out of regular plant matter, but huge mushrooms.","Great. Really great.");
	set_flag(5,11,250);
	set_terrain(17,25,0);
	set_terrain(19,25,0);
	set_terrain(21,25,0);
	set_terrain(17,29,0);
	set_terrain(19,29,0);
	set_terrain(21,29,0);
	activate_hidden_group(2);
break;

beginstate 22;
	if (get_flag(5,12) == 250)
		end();
	print_str("You can hear a woman shouting. Maybe that was Lady Keria!");
	set_flag(5,12,250);
break;

beginstate 23;
	if (get_flag(5,13) == 250)
		end();
	message_dialog("You hear someone screaming shrilly, _Out of the way, fools!_ There is a moment of silence, and then a loud banging noise, and screaming. Then there is more banging.","After the banging, there is no more screaming.");
	set_flag(5,13,250);
break;

beginstate 24;
	message_dialog("Lady Keria was, among other things, an academic and an herbalist. While browsing through her notes, you find an easy and relevant recipe.","Her notes say it will give the drinker more energy. Sounds useful.");
	give_recipe(3);
break;

beginstate 25;
	if (get_flag(5,14) == 250)
		end();
	message_dialog("This must have been Lady Keria's room. But it is bare and dusty; she must have been living somewhere else for quite a while.","");
	set_flag(5,14,250);
break;

beginstate 26;
	if (get_flag(5,20) == 250)
		end();
	set_flag(5,20,250);
	message_dialog("This is the camp of the peasants who tend Lord Kato's fields. They're probably poor and hopeless.","Megiddo is organized into a manorial system; this estate, with its sad laborers, is one of the more extreme examples of this old tradition.");
break;

beginstate 80;
	begin_talk_mode(2);
break;

beginstate 27;
	if (get_flag(5,21) == 250)
		end();
	set_flag(5,21,250);
	message_dialog("A note has been left pinned to the door. _Viktor - remember, tell the visitors that I'm hunting with the Saramite, and I'll be back before the moon wanes. Tell them to talk to Duneflin if they need to._ At the bottom, there is a six-pointed star.","Who could Viltor be? Perhaps the now-deceased guard of the front gate?");
break;