// Town 22: Breeding Pit
begintownscript;

variables;

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

body;

beginstate INIT_STATE;
	set_crime_tolerance(2);
	
	add_range_to_group(24,55,1);
	set_special_ability(1001,17);
	set_aggression(1001,50);
	set_level(1001,45);
	char_give_item(79,266);
	
	if (get_flag(22,0) == 0) {
		force_instant_terrain_redraw();
		reset_dialog();
		add_dialog_str(0,"You land safely at the bottom of the pit, and you immediately realize that no amount of rumors could've prepared you for this.",0);
		add_dialog_str(1,"You're in a breeding pit, a slime-encrusted, foul-stinking, fluid-stained crevice of depravity. Berekhs crowd at the bottom, copulating indiscriminately with demons and with other berekhs, birthing side-by-side, and fighting animally against all.",0);
		add_dialog_str(2,"As you stare, you see a berekh in intercourse with a demon, and before she even finishes, she begins clawing at its chest. They fight, and within moments, the berekh has killed her partner, strangling it to death.",0);
		add_dialog_str(3,"Another berekh gives birth and, the very moment that the demon-spawn is out, grabs a rock from the muck underfoot and dashes the baby's brains out. The berekh beside her tries to do the same, but the baby fights her, and he bites her hand to stay alive.",0);
		add_dialog_str(4,"On the other side of the breeding pit, you can see a ladder. To get there, you must descend to the bottom of the pit and ascend the other side. The berekhs and demons haven't noticed you yet, but if you get close, they surely will.",0);
		add_dialog_str(5,"But now that you have jumped down, there is no other way out.",0);
		set_flag(22,0,run_dialog(1));
		}
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;
	reset_dialog();
	add_dialog_str(0,"You find a ladder leading up out of the breeding pit. What do you wish to do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Climb the ladder.");
	if (run_dialog(1) == 2) {
		if (get_flag(22,1) == 0)
			set_flag(22,1,1);
		move_to_new_town(21,4,39);
		}
break;

beginstate 11;
	if (get_flag(22,2) == 0) {
		set_flag(22,2,1);
		message_dialog("Finally you have reached the other side of the breeding pit, and the ladder is merely a few paces away. You wipe a little of the grime of the pit off of you; you must have half a dozen different fluids from berekhs and demons on you now.","It is time to see what this one last hope of Legare's expedition holds.");
		}
break;

beginstate 12;
if (get_flag(22,3) == 0) {
	reset_dialog();
	add_dialog_str(0,"This body is clawed beyond recognition, perhaps once a human, or a vahnatai, or a slith, or a berekh, or even a demon, but now an unrecognizable heap of flesh and bones, torn limb from limb. But on the body, you find a rune-filled book!",0);
	add_dialog_str(1,"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(2,"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 23.
		if (get_skill_total(42) >= 23) {
			set_flag(22,3,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(293,2) == 0) // flag for spell
				add_dialog_str(1,"The book describes an interesting new spell, one that covers your allies with powerful shielding magic. (You learn a level of Protection.)",0);
			else
				add_dialog_str(1,"It's a spellbook describing how to cast Protection more efficiently. You read over it carefully.",0);
			inc_flag(293,2,run_dialog(1)); // flag for spell
			set_flag(293,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 Protection again, but you don't learn anything new from it.","");
break;

beginstate 13;
if (get_flag(22,4) == 0) {
	set_flag(22,4,1);
	activate_hidden_group(1);
	message_dialog("While approaching this corpse, you have attracted the attention of several of the area's residents. The demons and berekhs draw near you with their chaotic bloodlust.","");
	}
break;