begintownscript;

variables;
short rctx,rcty,leadchar,otherchar,bmessage,tigers;

body;

beginstate 0;

	if(get_flag(50,0) > 0){
		tigers = 30;
		while(tigers <= 36){
			erase_char(tigers);

			tigers = (tigers + 1);
		}
	}
	if(get_flag(51,0) > 0){
		tigers = 45;
		while(tigers <= 51){
			erase_char(tigers);

			tigers = (tigers + 1);
		}
	}

	if(get_flag(19,0) == 0){
		force_instant_terrain_redraw();
		message_dialog("You step into the cave.  It is more spacious than you would have assumed, but the rubble hiding its entrance would have made it difficult to locate.","The fauna here is very bizarre, almost alien.  But you recognize the trees and hear the sound of running water.  This place can't be too different, then.");
		set_flag(19,0,1);
	}

	set_name(27,"Abhijit");
	set_level(27,38);
	set_name(37,"Panishwar");
	set_level(37,43);
	set_name(38,"Jishnu");
	set_level(38,32);
	set_name(48,"Vajramani");
	set_level(48,32);
	set_char_dialogue_pic(19,404,0);

	if(get_flag(4,9) == 0){
		change_blocked(39,14,1);
		change_blocked(40,14,1);
		change_blocked(41,14,1);
		change_blocked(39,15,1);
		change_blocked(40,15,1);
		change_blocked(41,15,1);
	}

break;

beginstate 1;
break;

beginstate START_STATE;

	if(get_flag(1,9) >= 1){
		char_take_item(1000,494);
		if(party_can_see_loc(31,24) == TRUE && get_flag(2,9) == 0){
			message_dialog("Abhijit roars, followed by the rest of his fellows.  They charge at you instantly.","They mustn't have approved of your having attacked Baldev.  Somehow, you are not surprised.");
			set_flag(2,9,1);
		}
	}
	if(get_flag(4,9) >= 1){
		if(get_floor(39,14) == 125){
			rctx = 39;
			while(rctx <= 41){
				rcty = 14;
				while(rcty <= 15){
					set_floor(rctx,rcty,125);
					change_blocked(rctx,rcty,0);

					rcty = (rcty + 1);
				}

				rctx = (rctx + 1);
			}
		}
	}

break;

beginstate 10;

	if(get_flag(19,0) < 2){
		message_dialog("You see a large group of tigers surrounding a raised platform.  The tiger at the raised platform looks at you intently, but does not attack.  The others remain silent.","You have been accepted here.  Now, you are to find Baldev.");
		set_flag(19,0,2);
	}

break;

beginstate 11;

	if(get_flag(44,0) == 0){
		set_flag(44,0,1);
	}
	if(has_special_item(2) == 0){
		message_dialog("The rune here will not let you pass.  Try as you may, your feet refuse to step past it.","Strange.");
		block_entry(1);
	}
	else{
		if(get_flag(44,0) < 2){
			message_dialog("You approach the rune.  Suddenly, you feel a tingling sensation come from your pack.  The Obispopiedra is glowing.","The rune lets you by unscathed and unhindered.");
			set_flag(44,0,2);
		}
	}

break;

beginstate 12;

	if(get_flag(44,0) < 3){
		message_dialog("There is nothing here but two raised daises with odd-looking statues and crystals on them.  The crystals look familiar.","They resemble those in the place you visited in that strange dream with Emery.  But what are they doing here?");
		set_flag(44,0,3);
	}

break;

beginstate 13;

	if(get_flag(45,0) == 0 && get_flag(4,9) == 0){
		message_dialog("As you approach this tiger, it stares at you intently.  _You will not move further._","_While in our domain, we will not tolerate you.  Get out while you still can._");
		set_flag(45,0,1);
	}

break;

beginstate 14;

	if(get_flag(45,0) < 2 && get_flag(4,9) == 0){
		message_dialog("True to his word, the tiger standing before you pounces on you, as does the whole slew of tigers behind him.","This clearly will not be easy.");
		set_flag(4,9,1);
		set_flag(45,0,2);
		change_blocked(39,14,0);
		change_blocked(40,14,0);
		change_blocked(41,14,0);
		change_blocked(39,15,0);
		change_blocked(40,15,0);
		change_blocked(41,15,0);

	}

break;

beginstate 15;

	if(get_flag(46,0) == 0 && get_flag(1,9) == 0){
		message_dialog("You enter the domain of a tiger herd.  Suddenly, the tigers see you and acknowledge you immediately.  One of them speaks to you.","_Master Baldev wishes to speak with you.  Please, proceed._");
		set_flag(46,0,1);
	}

break;

beginstate 16;

	if(get_flag(46,0) == 1 && get_flag(1,9) == 0){
		message_dialog("You see Baldev ahead.  He seems to be in good spirits since his rescue.  Many of the tigers seem unusually happy, if such notions are familiar to them.","Baldev beckons you forward.  You oblige.");

		leadchar = 0;
		while(char_ok(leadchar) == FALSE){
			leadchar = (leadchar + 1);
		}

		relocate_character(leadchar,19,9);
		rctx = 19;
		if(char_ok(leadchar + 1) == TRUE){
			rctx = (rctx + 1);
			relocate_character((leadchar + 1),rctx,9);
		}
		if(char_ok(leadchar + 2) == TRUE){
			rctx = (rctx + 1);
			relocate_character((leadchar + 2),rctx,9);
		}
		if(char_ok(leadchar + 3) == TRUE){
			rctx = (rctx + 1);
			relocate_character((leadchar + 3),rctx,9);
		}
		set_character_facing(1000,6);
		force_view_center(19,9);
		force_instant_terrain_redraw();
		pause(10);

		reset_dialog();
		add_dialog_str(0,"Baldev roars triumphantly.  _It is good to see you once more.  Now, for your reward which I have promised you._",0);
		add_dialog_str(1,"_You should see two things before you.  One is a chest full of trinkets we managed to steal from bugbear shamans throughout the years.  You may take all that you find within, we tigers cannot use it._",0);
		add_dialog_str(2,"_More importantly, for saving my life, I give you mine.  This spell you see before you will summon me into a battle.  I will douse any opponent you choose in scalding flames._",0);
		add_dialog_str(3,"_I cannot offer you anything other than this, save for my eternal gratitude.  If you are ever in need of me or my brethren, merely say the word._",0);
		add_dialog_choice(0,"Thank you, Baldev.");
		bmessage = run_dialog(1);

		set_flag(46,0,2);
		block_entry(1);
	}

break;

beginstate 17;

	if(get_flag(47,0) == 1 && get_flag(3,9) == 0){
		message_dialog("Panishwar roars loudly.  _How foolish!  I told you that I would kill you, and now I shall!_","Panishwar and his fellows attack.  You can't say it was a surprise, at any rate.");
		set_flag(3,9,1);
	}

	if(get_flag(3,9) == 0 && get_flag(47,0) == 0 && get_flag(3,9) == 0){
		reset_dialog();
		add_dialog_str(0,"The passage here reeks of death.  You see bones inside, some of them belonging to humans, some belonging to tigers.",0);
		add_dialog_str(1,"Suddenly, Panishwar turns to you.  _You!  I care not who you are, that trove is mine, and I will kill you if you proceed!_",0);
		add_dialog_str(2,"He seems agitated.  He probably is not joking either.",0);
		add_dialog_choice(0,"Onward.");
		add_dialog_choice(1,"Stay back.");
		set_flag(47,0,1);
		bmessage = run_dialog(1);
		if(bmessage == 1){
			set_flag(3,9,1);
			message_dialog("Panishwar and his fellows attack you.  You can't say it was a surprise, at any rate.","");
		}
		if(bmessage == 2){
			message_dialog("Panishwar backs off.  _I will let you live.  For now._","_But if I think you are ever THINKING of taking my treasures, I will not hesitate to kill you._");
			block_entry(1);
		}
	}

break;

beginstate 18;

	if(get_flag(48,0) == 0){
		message_dialog("Across the underground river, you see a large herd of tigers, numbering almost a dozen.  Their leader seems to be immensely strong.","He looks at you intently, but with a certain modicum of friendliness.  Perhaps it would be wise to speak with him.");
		set_flag(48,0,1);
	}

break;