// 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;
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;
	move_to_new_town(2,6,15);
break;

beginstate 11;
	if (get_flag(3,0) == 250)
		end();
	message_dialog("Someone has thoughtfully inscribed a magical rune upon the ground here. It looks sort of like a star. Runes typically protect or actively defend an important area.","A powerful mage must have put this rune here, to keep the vicious monsters bottled inside. You take a tentative step. The rune does nothing to you.");
	set_flag(3,0,250);
break;

beginstate 12;
	if (get_flag(3,1) == 250)
		end();
	message_dialog("The old, cracked bones of a human man are left here. Miraculously, there is also an ancient piece of paper. You inspect it. It says, _Let it be known: I was trapped. The rune will blast me if I come near it, and the monsters will eat me if they can._","There is another scribble at the bottom of the paper. It just says _Curse him, curse him. Curse the light._");
	set_flag(3,1,250);
break;

beginstate 13;
	if (get_flag(3,2) == 250)
		end();
	message_dialog("You come to a large gallery in the caverns. Here the spiders and bats must fight for water, which drips from the humid walls into a pool in the center of this cave.","The spiders hiss, and the bats shriek. They know you're here, and they want to change up their diet.");
	set_flag(3,2,250);
	i = 7;
	while (i < 31) {
		alert_char(i);
		i = i + 1;
		}
break;

beginstate 14;
	if (get_flag(3,8) == 250)
		end();
	set_flag(3,8,250);
	message_dialog("You find the pool of acid that Warren spoke of. At least, it's probably a pool of acid. It bubbles sinisterly and froths as you approach.","But then, as you approach, it unexpectedly lashes out. A tendril of goo flies out and tries to smack you. It misses, but it is a threatening gesture nonetheless. It looks like you'll have to fight this thing too.");
break;

beginstate 15;
	reset_dialog();
	add_dialog_str(1,"You find a magical spellbook hidden back here, guarded by a magical rune. The rune might not hurt you, but given its position, it seems pretty likely that it's connected to some sort of trap.",0);
	add_dialog_str(2,"And then there's the fact that there's a spellbook hidden back here at all. Spellbooks are notoriously rare, and it looks as if someone purposefully placed it here to be guarded by spiders.",0);
	add_dialog_choice(0,"Read the spellbook and hope it's not trapped.");
	add_dialog_choice(1,"This looks too suspicious. (Back away)");
	i = 0;
	i = run_dialog(1);
	if (i == 1) {
		j = 0;
		while (j < 4) {
			if (get_spell_level(j,0,0) < 2) {
				change_spell_level(j,0,0,1);
				}
			j = j + 1;
			}
		message_dialog("Most of the pages are rotted away, some are unreadable, and only a few look like spells that you could use anyway. But you do have a stroke of luck.","You find a detailed explanation of how to cast a good firebolt. This will come in handy.");
		block_entry(1);
		}
	if (i == 2) {
		block_entry(1);
		print_str("Better safe than sorry. You stay away from the dangerous book.");
		}
break;