// Town 38: Under Manikoss
begintownscript;

variables;

short choice,i,j,k;
short turn_inc;
string dlgstr;

body;

beginstate INIT_STATE;
	set_crime_tolerance(2);
	
	change_blocked(22,4,1);
	change_blocked(41,47,1);
	change_blocked(9,40,1);
	change_blocked(50,17,1);
	
	turn_inc = get_current_tick();
	
	if (get_flag(38,0) == 0) {
		force_instant_terrain_redraw();
		set_flag(38,0,1);
		message_dialog("You descend into a room under the city of Manikoss, and immediately, you are greeted by a phenomenal stench. Something down here is foul, rotten, decayed. This may be the source of the contagion and the place to find the explanation from where it came.","The air is terribly difficult to breathe. You fear that if you linger here for long, you will suffer great harm to your lungs.");
		}
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
	if (tick_difference(turn_inc,get_current_tick()) > 4) {
		print_str("The contagion in the air harms you!");
		damage_char(1000,get_ran(5,1,120),6);
		i = 6;
		while (i < 28) {
			if (char_ok(i) == 0)
				if (get_ran(1,1,4) == 1) {
					spawn_creature(i);
					if (party_can_see_loc(char_loc_x(i),char_loc_y(i)))
						print_str("A new monster rises from the muck!");
					}
			i = i + 1;
			}
		turn_inc = get_current_tick();
		}
break;

beginstate 10;
if (is_combat()) {
	print_str_color("You cannot climb in combat mode.",1);
	block_entry(1);
	end();
	}
	
	reset_dialog();
	add_dialog_str(0,"You find a ladder here. What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Climb up.");
	if (run_dialog(1) == 2)
		move_to_new_town(37,23,4);
	else
		block_entry(1);
break;

beginstate 11;
if (is_combat()) {
	print_str_color("You cannot climb in combat mode.",1);
	block_entry(1);
	end();
	}
	
	reset_dialog();
	add_dialog_str(0,"You find a ladder here. What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Climb up.");
	if (run_dialog(1) == 2)
		move_to_new_town(37,42,47);
	else
		block_entry(1);
break;

beginstate 12;
if (is_combat()) {
	print_str_color("You cannot climb in combat mode.",1);
	block_entry(1);
	end();
	}
	
	reset_dialog();
	add_dialog_str(0,"You find a ladder here. What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Climb up.");
	if (run_dialog(1) == 2)
		move_to_new_town(37,10,40);
	else
		block_entry(1);
break;

beginstate 13;
if (is_combat()) {
	print_str_color("You cannot climb in combat mode.",1);
	block_entry(1);
	end();
	}
	
	reset_dialog();
	add_dialog_str(0,"You find a ladder here. What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Climb up.");
	if (run_dialog(1) == 2)
		move_to_new_town(37,49,17);
	else
		block_entry(1);
break;

beginstate 14;
if (get_flag(38,1) == 0) {
	set_flag(38,1,1);
	message_dialog("Unlike the room you just left, clearly a repository for the cleaning supplies for the maintenance of whatever is here underground, the hall into which you are walking does not appear to be intentionally built. It appears to be dug.","That is, there was something non-slith alive down here that created this tunnel, and judging by the freshness of the slime, it's still here.");
	}
break;

beginstate 15;
	message_dialog("This box is empty. Either it was looted after the city was abandoned, or the residents took the contents with them when they left.","");
break;

beginstate 16;
if (get_flag(38,3) == 0) {
	set_flag(38,3,1);
	message_dialog("This home of the dead, unlike the other two boxes, has not been stripped of all its contents. Either the looters thought that it would be sacrilege to tamper with the dead, or the residents thought that they should let the dead sleep.","The skeletal remains of the body, which having decayed long ago, holds a gleaming sword.");
	}
break;

beginstate 17;
if (get_flag(38,2) == 0) {
	reset_dialog();
	add_dialog_str(0,"You enter this large, open room, and the source of the pollution sits right in front of you, not so mysterious after all: several canisters storing toxic substances have ruptured, spewing forth their contents into the ground.",0);
	add_dialog_str(1,"This pollution appears to have corrupted not only the ground, but also the air, which is what is making it hard for you to breathe. You look around for a cleaning mechanism, and there is one, but it seems not to be enough.",0);
	add_dialog_str(2,"The water in the south is set up to wash away the leaking poison, but it has long since become entirely contaminated and no longer a reasonable cleaner. It was simplest just to continue to use this water, even after it stopped being effective.",0);
	add_dialog_str(3,"Indeed, no one would've hesitated to clean up this pollution if it had been cheap and easy, even if time-consuming. The expense of a cleaner system killed Manikoss. Money, not time, was -- and had to be -- the deciding factor.",0);
	add_dialog_str(4,"Before you can ponder this farther, you notice that there are a number of moving bits of slime -- animals covered in slime, apparently -- that have taken an interest in you.",0);
	set_flag(38,2,run_dialog(1));
		}
break;

beginstate 18;
if (get_flag(38,4) == 0) {
	set_flag(38,4,1);
	message_dialog("The room you are exiting appears to have been a small, ceremonial room of some kind, built by sliths. The wall has caved in, though, and something has dug a tunnel through here.","Slime covers everything, and you step carefully so as not to get covered in toxic filth.");
	}
break;

beginstate 19;
if (get_flag(38,5) == 0) {
	reset_dialog();
	add_dialog_str(0,"There is a dead slith here, one who died long, long ago. His body is almost completely destroyed by the acid around. He appears to have died dragging away one of the worst leaking canisters.",0);
	add_dialog_str(1,"Next to his body, you see a small, rune-covered book. It must be a spellbook! Part of it is still legible.",0);
	add_dialog_str(2,"Reading strange spellbooks can be dangerous: they can carry curses or other terrible effects. However, they can also have great spells recorded within.",0);
	add_dialog_str(3,"What do you do?",0);
	add_dialog_choice(0,"Leave it alone.");
	add_dialog_choice(1,"Attempt to read it.");
	if (run_dialog(1) == 2) {
		reset_dialog();
		// Requires Arcane Lore of 24.
		if (get_skill_total(42) >= 24) {
			set_flag(38,5,1);
			add_dialog_str(0,"The book is written in a strange rune script, but fortunately, due to your knowledge of Arcane Lore, you can read it.",0);
			if (get_flag(292,7) == 0) // flag for spell
				add_dialog_str(1,"The book describes an interesting new spell, one that makes your enemies drowsy. (You learn a level of Sleep Foe.)",0);
			else
				add_dialog_str(1,"It's a spellbook describing how to cast Sleep Foe more efficiently. You read over it carefully.",0);
			inc_flag(292,7,run_dialog(1)); // flag for spell
			set_flag(292,0,1);
			}
		else
			message_dialog("The book is written in a strange rune script, and unfortunately, you can't read it. Perhaps if you knew more about Arcane Lore, you would be able to.","");
		}
	}
else
	message_dialog("You find the book on Sleep Foe again, but you don't learn anything new from it.","");
break;

beginstate 20;
if (is_combat()) {
	message_dialog("There is a beautiful, holy-feeling altar here. However, in the middle of battle, you can do nothing with regard to it.","");
	end();
	}

if (get_flag(38,6) == 0) {
	reset_dialog();
	add_dialog_str(0,"There is a beautiful and ancient altar here. It radiates magical energy, untouched by the decay of time. It has very old slith writing on it, written in the classical tongue of the sliths, contemporary with the Khalthanad.",0);
	add_dialog_str(1,"It says: _Bitakhaeth theifaathi lotha Althanazaariaathi ka ._ That is: praise be to the goddess Althanazaria, our patron goddess and helper.",0);
	add_dialog_str(2,"What do you do?",0);
	add_dialog_choice(0,"Leave it alone.");
	add_dialog_choice(1,"Pray at the altar.");
	if (run_dialog(1) == 2) {
		reset_dialog();
		set_flag(38,6,1);
		add_dialog_str(0,"You offer a simple prayer in the most formal slith language you can manage. When you finish, a soft, feminine, sibilant voice begins speaking in your mind. It is describing how to cast a spell!",0);
		add_dialog_str(1,"The voice describes an interesting new spell, one that surrounds your enemies in a halo of fire. (You learn a level of Fire Field.)",0);
		set_flag(292,12,run_dialog(1));
		set_flag(292,0,1);
		}
	}
else {
	reset_dialog();
	add_dialog_str(0,"",0);
	add_dialog_choice(0,"Leave it alone.");
	add_dialog_choice(1,"Pray at the altar again.");
	if (run_dialog(1) == 2)
		message_dialog("You pray at the altar again. You feel good about yourself, but nothing else happens.","");
	}
break;

beginstate 21;
if (get_flag(38,7) == 0) {
	set_flag(38,7,1);
	message_dialog("You enter a small, devotional room in someone's basement.","You see a few broken bits in the corner. That must have been the ladder out of here, once.");
	}
break;