// Town 21: Berekh Hive
begintownscript;

variables;

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

body;

beginstate INIT_STATE;
	set_crime_tolerance(2);
	
	set_name(7,"Dalaghant");
	
	if (get_flag(21,0) == 0) {
		force_instant_terrain_redraw();
		set_flag(21,0,1);
		message_dialog("As you enter this cave, you see a strange monster in the distance. It is female, a female humanoid with gargantuan, overdeveloped breasts who is wearing only a skirt. She growls ominously as she wanders away from you.","You've heard hints of rumors of such creatures before. They are called berekhs, nicknamed devouring mothers and known as semi-sentient and powerfully misanthropic beings. They mate with demons and produce monstrous offspring.");
		}
	if (get_flag(22,1) == 1) {
		force_instant_terrain_redraw();
		set_flag(22,1,2);
		message_dialog("You climb out of the rank breeding pit, that slosh of unspeakable lust and depravity. Before you there is a wall with a slight crack in it, and on the other side you can see a path out of here! You see fresh land, untouched by lava!","Now, if you can only get out of here, you can inform the others about this route and save the expedition!");
		}
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;
	reset_dialog();
	add_dialog_str(0,"You stand at the edge of a hole leading down into the berekh breeding pit. You think you could survive the fall without more than minor bumps and scratches, but you wouldn't be able to climb back up. What do you wish to do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Jump down the pit.");
	if (run_dialog(1) == 2)
		move_to_new_town(22,7,2);
	else
		block_entry(1);
break;

beginstate 11;
	reset_dialog();
	add_dialog_str(0,"Here is the trapdoor leading back down into the breeding pit. What do you wish to do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Climb down the ladder.");
	if (run_dialog(1) == 2)
		move_to_new_town(22,3,34);
	else
		block_entry(1);
break;

beginstate 12;
	if (get_flag(21,1) == 0) {
		reset_dialog();
		add_dialog_str(0,"This cave stands in stark contrast to the deliberate constructions of the vahnatai, intact even after centuries of disuse. This cave looks more as though it were burrowed out by insects than built by intelligent life.",0);
		add_dialog_str(1,"The berekhs, if rumors are true, are as intelligent as goblins and are all female. They mate with demons, and their male offspring are demons, and their female offspring are more berekhs.",0);
		add_dialog_str(2,"Some have offered the hypothesis that berekhs and demons are the same species, but the species simply manifests an extremely high level of sexual dimorphism. Others claim that there are female demons that are not berekhs, which would refute this idea.",0);
		add_dialog_str(3,"Whatever the truth, all rumors agree that berekhs are extremely unpredictable, often turning on their own sons and lovers, nurturing one moment and murdering the next. You carry your weapons at the ready as you proceed.",0);
		set_flag(21,1,run_dialog(1));
		}
break;

beginstate 13;
	if (get_flag(21,2) == 0) {
		set_flag(21,2,1);
		
		set_terrain(31,29,453);
		set_terrain(31,30,453);
		set_terrain(31,31,453);
		set_terrain(31,32,453);
		set_terrain(31,33,453);
		set_terrain(31,34,453);
		set_terrain(16,38,453);
		set_terrain(16,39,453);
		set_terrain(16,40,453);
		
		activate_hidden_group(1);
		put_boom_on_char(7,2,0);
		run_animation_sound(51);
		
		i = 0;
		while (char_ok(i) == 0)
			{i = i + 1; }
		
		reset_dialog();
		add_dialog_str(0,"You head down this passage in the direction of the Lava Ocean, but suddenly you are interrupted by a flash. It is Dalaghant!",0);
		clear_buffer();
		append_string("_No, no, ");
		append_char_name(i);
		append_string(",_ he reprimands, his tone as civil as ever. _You are not going anywhere._");
		get_buffer_text(dlgstr);
		add_dialog_str(1,dlgstr,0);
		add_dialog_str(2,"He remarks casually, _Did you like the berekhs? They are the dearest loves of all demons. We all should be so lucky to be able to spend time in a breeding pit, loving and rejoicing in being alive._ He gazes off. _We should all be so lucky._",0);
		add_dialog_str(3,"He looks back to you suddenly. _But I forget myself, and worse, I forget you. We have business to finish. Specifically, I must kill you._",0);
		add_dialog_str(4,"What do you say?",0);
		add_dialog_choice(0,"(Nothing.)");
		add_dialog_choice(1,"Taste blade, hell-spawn!");
		if (party_size() == 1)
			add_dialog_choice(2,"Why must you kill me?");
		else
			add_dialog_choice(2,"Why must you kill us?");
		if (run_dialog(1) == 3)
			message_dialog("_Because,_ replies Dalaghant, _that is what my lady Hathnazriakh would want, and she is queen here. You have crossed me, and for that, my master Nathaganth would want you dead, and you have slain berekhs, creatures dear to my lady._","He concludes matter-of-factly, _For these trespasses, you must die._");
		}
break;

beginstate 14;
if (get_flag(21,3) == 0) {
	reset_dialog();
	add_dialog_str(0,"This very old dead body is not even recognizable. You can't tell if this is a vahnatai, a slith, a berekh, a demon, or something else. However, you can tell that it has a spellbook with one page that is still legible.",0);
	add_dialog_str(1,"Reading the spellbook may be very dangerous. The creature may have died from casting the spell, which may be cursed, or if the creature is a demon, the spell may do horrible things. Then again, it may be quite powerfully useful.",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 24.
		if (get_skill_total(42) >= 24) {
			set_flag(21,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,1) == 0) // flag for spell
				add_dialog_str(1,"The book describes an interesting new spell, one that hides you from your enemies. (You learn a level of Sanctuary.)",0);
			else
				add_dialog_str(1,"It's a spellbook describing how to cast Sanctuary more efficiently. You read over it carefully.",0);
			inc_flag(293,1,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 Sanctuary again, but you don't learn anything new from it.","");
break;

beginstate 15;
	if (get_flag(21,4) == 0) {
		reset_dialog();
		add_dialog_str(0,"In front of you, you can see the exit from the berekh hive. It leads near the place where you entered! You must not have noticed this small passageway when you came through here before. The expedition will be able to come this way easily, though.",0);
		add_dialog_str(1,"Dalaghant is dead. You are finally finished with him. He was the most civilized and devout of the beings you have met on this journey, and he was also a devil-worshipping murderer. It is odd. Well, no matter; he is dead and gone.",0);
		add_dialog_str(2,"But you cannot help but remember his dying words: _I will have my revenge._",0);
		set_flag(21,4,run_dialog(1));
		}
break;

beginstate 16;
if (get_flag(21,5) == 0) {
	reset_dialog();
	add_dialog_str(0,"On Dalaghant's body is a very small spellbook. Reading the spellbook could be extremely dangerous, since a demon could have a spellbook with spells that do just about anything, but it could also be very rewarding.",0);
	add_dialog_str(1,"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 22.
		if (get_skill_total(42) >= 22) {
			set_flag(21,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,2) == 0) // flag for spell
				add_dialog_str(1,"The book describes an interesting new spell, one that inflicts a powerful sickness upon your enemies. (You learn a level of Poison.)",0);
			else
				add_dialog_str(1,"It's a spellbook describing how to cast Poison more efficiently. You read over it carefully.",0);
			inc_flag(292,2,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 Poison again, but you don't learn anything new from it.","");
break;