// Town 36: Bridge
begintownscript;

variables;

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

body;

beginstate INIT_STATE;
	set_crime_tolerance(2);
	
	change_blocked(46,28,1);
	change_blocked(46,29,1);
	change_blocked(46,30,1);
	change_blocked(46,31,1);
	change_blocked(46,32,1);
	change_blocked(46,33,1);
	change_blocked(46,34,1);
	change_blocked(46,35,1);
	change_blocked(46,36,1);
	
	change_blocked(26,28,1);
	change_blocked(26,29,1);
	change_blocked(26,30,1);
	change_blocked(26,31,1);
	change_blocked(26,32,1);
	change_blocked(26,33,1);
	change_blocked(26,34,1);
	change_blocked(26,35,1);
	change_blocked(26,36,1);
	
	if (char_ok(6) == 0)
		spawn_creature(6);
	
	if (get_flag(36,0) == 0) {
		force_instant_terrain_redraw();
		reset_dialog();
		add_dialog_str(0,"The second obstacle that souls have to pass on their way to the afterlife is the Howling Bridge.",0);
		add_dialog_str(1,"This bridge is the only way across a bottomless chasm, into which a soul may fall and never return. Wind perpetually blows along the chasm, creating a terrible high-pitched howling.",0);
		add_dialog_str(2,"Up ahead, you see the two guardians of the bridge: Akhidra the Many-Headed and Kerbeross the Wicked-Toothed. Akhidra tests the resolve of the dead, of whom the cowardly dive into the chasm to face an eternity of darkness rather than fight the beast.",0);
		add_dialog_str(3,"Kerbeross is a ferocious dog, placed specifically to prevent the living from entering and the dead from exiting, for many of the living have wandered, by mistake or design, into this land, and many of the dead have attempted to flee their punishments.",0);
		add_dialog_str(4,"Somehow you must pass them both.",0);
		set_flag(36,0,run_dialog(1));
		}
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;
	if (get_flag(36,1) == 0) {
		message_dialog("As you approach, Akhidra begins growling fiercely. You may not be able to take more steps without combat.","");
		set_flag(36,1,1);
		}
break;

beginstate 11;
	if (get_flag(36,2) == 0) {
		reset_dialog();
		add_dialog_str(0,"Akhidra bares her teeth menacingly and begins slowly moving towards you. What do you do?",0);
		add_dialog_choice(0,"Back away slowly.");
		add_dialog_choice(1,"Draw your weapons and shout threats.");
		add_dialog_choice(2,"Attempt to run past quickly.");
		choice = run_dialog(1);
		if (choice == 1) {
			block_entry(1);
			}
		else {
			set_flag(36,2,1);
			change_blocked(46,28,0);
			change_blocked(46,29,0);
			change_blocked(46,30,0);
			change_blocked(46,31,0);
			change_blocked(46,32,0);
			change_blocked(46,33,0);
			change_blocked(46,34,0);
			change_blocked(46,35,0);
			change_blocked(46,36,0);
			}
		if (choice == 2)
			message_dialog("You wave your weapons at the beast, and you shout angry threats. Akhidra begins growling more angrily, but you only shout louder, and, appearing placated, it steps back. You may proceed.","");
		if (choice == 3) {
			message_dialog("You begin to run, but Akhidra lunges for you and gets in your way. You may have to fight this monster.","");
			set_attitude(7,10);
			}
		}
break;

beginstate 12;
if (get_flag(36,3) == 0) {
	reset_dialog();
	add_dialog_str(0,"As you approach, Kerbeross eyes you skeptically. He knows that you are not among the dead, and it is his duty to guard this land from all living. What do you do?",0);
	add_dialog_choice(0,"Back away slowly.");
	add_dialog_choice(1,"Keep moving forward.");
	if (run_dialog(1) == 1)
		block_entry(1);
	else {
		change_blocked(26,28,0);
		change_blocked(26,29,0);
		change_blocked(26,30,0);
		change_blocked(26,31,0);
		change_blocked(26,32,0);
		change_blocked(26,33,0);
		change_blocked(26,34,0);
		change_blocked(26,35,0);
		change_blocked(26,36,0);
		set_flag(36,3,1);
		set_attitude(6,10);
		message_dialog("Kerbeross roars and charges!","");
		}
	}
break;

beginstate 13;
	message_dialog("You slay Kerbeross, the guardian of the underworld! His energy dissipates around you, no longer blocking your way.","At first you think that you really killed him, but then you realize that this is the Land of the Dead, and nothing that lives here can really die. Kerbeross will be back when you return. He probably will let you pass from now on, though.");
	set_flag(36,4,1);
break;