begintownscript;

variables;
short tome1;
short take;
short remark;
short passage;
short talk;

body;

beginstate 0;

	set_name(78,"Oggamush");
	set_level(78,26);

	set_char_dialogue_pic(81,404,0);

	add_char_to_group(83,1);
	add_char_to_group(84,1);
	add_char_to_group(85,1);
	add_char_to_group(77,1);
	add_char_to_group(64,1);
	add_char_to_group(11,1);
	add_char_to_group(12,1);

	add_char_to_group(13,2);
	add_char_to_group(14,2);
	add_char_to_group(15,2);
	add_char_to_group(16,2);
	add_char_to_group(17,2);
	add_char_to_group(18,2);
	add_char_to_group(19,2);
	add_char_to_group(20,2);
	add_char_to_group(21,2);
	add_char_to_group(22,2);
	add_char_to_group(23,2);
	add_char_to_group(24,2);
	add_char_to_group(25,2);
	add_char_to_group(26,2);
	add_char_to_group(27,2);
	add_char_to_group(28,2);

	add_char_to_group(29,3);
	add_char_to_group(30,3);
	add_char_to_group(31,3);
	add_char_to_group(32,3);
	add_char_to_group(33,3);
	add_char_to_group(34,3);
	add_char_to_group(35,3);
	add_char_to_group(36,3);
	add_char_to_group(37,3);
	add_char_to_group(38,3);
	add_char_to_group(39,3);
	add_char_to_group(40,3);
	add_char_to_group(41,3);
	add_char_to_group(42,3);

	add_char_to_group(58,4);
	add_char_to_group(59,4);
	add_char_to_group(60,4);
	add_char_to_group(61,4);
	add_char_to_group(62,4);
	add_char_to_group(63,4);
	add_char_to_group(65,4);
	add_char_to_group(66,4);
	add_char_to_group(67,4);
	add_char_to_group(68,4);
	add_char_to_group(69,4);
	add_char_to_group(70,4);
	add_char_to_group(71,4);
	add_char_to_group(72,4);
	add_char_to_group(73,4);
	add_char_to_group(74,4);
	add_char_to_group(75,4);
	add_char_to_group(76,4);
	add_char_to_group(78,4);
	add_char_to_group(79,4);
	add_char_to_group(80,4);

	if(get_flag(6,0) >= 1){
		set_terrain(40,14,0);
		set_terrain(41,14,0);
		set_terrain(42,14,0);
	}

	if(get_flag(62,2) >= 1){
		erase_char(81);
	}

	if(get_flag(9,0) == 1){
		set_floor(34,12,0);
		set_terrain(34,12,233);
		set_terrain(28,11,0);
		set_terrain(28,12,0);
		set_terrain(29,12,0);
		set_terrain(28,13,0);
	}

	if(get_flag(91,1) == 1){
		set_terrain(11,12,0);
	}

	if(get_flag(12,0) > 0){
		set_terrain(30,48,18);
		set_terrain(30,56,21);
	}

break;

beginstate 1;
break;

beginstate START_STATE;
break;

beginstate 10;
	move_to_new_town(1,23,30);
break;

beginstate 11;
	move_to_new_town(1,25,30);
break;

beginstate 12;
	move_to_new_town(1,35,16);
break;

beginstate 13;
	move_to_new_town(1,6,37);
break;

beginstate 14;
	move_to_new_town(1,39,39);
break;

beginstate 15;
	reset_dialog();
	add_dialog_str(0,"There is a large, spell tome here.  It might be trapped, but you could read it anyway...",0);
	add_dialog_choice(0,"Leave the book alone.");
	add_dialog_choice(1,"Read it.");
	tome1 = run_dialog(1);
	if(tome1 == 1)
		end();
	if (get_skill_total(42) >= 25){
		message_dialog("The book is, put bluntly, a tome about blowing stuff up by burning immense amounts of spell points to either generate heat or raw magical energy.","Members of your party who know Fireblast or Arcane Blow now know it at a much higher level.");
		if (char_ok(0)) {
	if(get_spell_level(0,0,16) == 1)
				change_spell_level(0,0,16,4);
	if(get_spell_level(0,0,16) == 2)
				change_spell_level(0,0,16,3);
	if(get_spell_level(0,0,16) == 3)
				change_spell_level(0,0,16,2);
	if(get_spell_level(0,0,16) == 4)
				change_spell_level(0,0,16,1);
	if(get_spell_level(0,0,19) == 1)
				change_spell_level(0,0,19,2);
	if(get_spell_level(0,0,19) == 2)
				change_spell_level(0,0,19,1);
		}
		if (char_ok(1)) {
	if(get_spell_level(1,0,16) == 1)
				change_spell_level(1,0,16,4);
	if(get_spell_level(1,0,16) == 2)
				change_spell_level(1,0,16,3);
	if(get_spell_level(1,0,16) == 3)
				change_spell_level(1,0,16,2);
	if(get_spell_level(1,0,16) == 4)
				change_spell_level(1,0,16,1);
	if(get_spell_level(1,0,19) == 1)
				change_spell_level(1,0,19,2);
	if(get_spell_level(1,0,19) == 2)
				change_spell_level(1,0,19,1);
		}
		if (char_ok(2)) {
	if(get_spell_level(2,0,16) == 1)
				change_spell_level(2,0,16,4);
	if(get_spell_level(2,0,16) == 2)
				change_spell_level(2,0,16,3);
	if(get_spell_level(2,0,16) == 3)
				change_spell_level(2,0,16,2);
	if(get_spell_level(2,0,16) == 4)
				change_spell_level(2,0,16,1);
	if(get_spell_level(2,0,19) == 1)
				change_spell_level(2,0,19,2);
	if(get_spell_level(2,0,19) == 2)
				change_spell_level(2,0,19,1);
		}
		if (char_ok(3)) {
	if(get_spell_level(3,0,16) == 1)
				change_spell_level(3,0,16,4);
	if(get_spell_level(3,0,16) == 2)
				change_spell_level(3,0,16,3);
	if(get_spell_level(3,0,16) == 3)
				change_spell_level(3,0,16,2);
	if(get_spell_level(3,0,16) == 4)
				change_spell_level(3,0,16,1);
	if(get_spell_level(3,0,19) == 1)
				change_spell_level(3,0,19,2);
	if(get_spell_level(3,0,19) == 2)
				change_spell_level(3,0,19,1);
		}
	}
	else{
		message_dialog("The book is, put bluntly, a tome about blowing stuff up by burning immense amounts of spell points to either generate heat or raw magical energy.","It's a tome written in a common script among magi, adding insult to the fact that it's out of your league.  Some Rune Reading skill would help.");
	}
break;

beginstate 16;
	if(get_flag(6,0) == 0){
		set_flag(6,0,1);
		set_terrain(40,14,0);
		set_terrain(41,14,0);
		set_terrain(42,14,0);
		activate_hidden_group(1);
		force_instant_terrain_redraw();
		play_sound(106);
		play_sound(99);
		pause(3);
	}
break;

beginstate 17;
	if(get_flag(10,0) == 0){
		message_dialog("You look up towards the ceiling for an instant- understandably so, considering how comparatively high it is in relation to the rest of these caverns.","The ground above this cave must be higher than most here, and also quite weak.  Strange...");
		set_flag(10,0,1);
	}
break;

beginstate 18;
	if(character_in_party(275) >= 4){
		message_dialog("Baldev roars.  What is his problem?  _No, humans.  Look ahead, and you will find a statue...  That statue is the one that defeated me and my fellows._","_If you wish to kill yourselves here, go ahead.  First, however, lead me out of the lair of these damnable pigs._");
		block_entry(1);
	}
break;

beginstate 19;
	if(get_flag(91,1) == 0){
		reset_dialog();
		add_dialog_str(0,"Now THIS emblem is displayed prominently.  Clearly, from the effort it took getting into this antechamber, it must hold special meaning to the Bugbears.",0);
		add_dialog_str(1,"Even if it weren't part of your mission, it would be an incomplete romp throughout an uncivilized cesspit like this without ripping off the Bugbears' most prized artifact.",0);
		add_dialog_choice(0,"Leave the emblem alone.");
		add_dialog_choice(1,"Take it.");
		take = run_dialog(1);
		if(take == 1)
			end();

		if(get_flag(75,0) == 0){
			talk = 14;
		}
		else{
			talk = get_flag(75,0);
		}

		set_terrain(11,12,0);
		relocate_character(0,12,12);
		relocate_character(1,12,13);
		relocate_character(2,12,11);
		relocate_character(3,12,14);
		remark = random_party_member();
		text_bubble_on_char(remark,"Well.");
		force_instant_terrain_redraw();
		pause(5);

		text_bubble_on_char(remark,"");
		text_bubble_on_char(remark,"At least that's over...");
		force_instant_terrain_redraw();
		pause(talk);

		set_total_visibility(1);
		text_bubble_on_char(remark,"");
		force_view_center(29,12);
		force_instant_terrain_redraw();
		pause(5);

		put_effect_on_space(28,11,8,4,0);
		put_effect_on_space(28,12,8,4,0);
		put_effect_on_space(28,13,8,4,0);
		set_terrain(28,11,41);
		set_terrain(28,12,41);
		set_terrain(28,13,41);
		force_instant_terrain_redraw();
		run_animation_sound(90);
		pause(5);

		set_total_visibility(0);
		set_character_facing(1000,6);
		force_view_center(12,12);
		force_instant_terrain_redraw();
		pause(5);

		text_bubble_on_char(remark,"Oh, hell.");
		force_instant_terrain_redraw();
		pause(talk);

		text_bubble_on_char(remark,"");
		put_sparkles_on_space(14,12,3,4);
		force_instant_terrain_redraw();
		run_animation_sound(43);
		pause(5);

		// put_sparkles_on_space(14,12,3,4);
		put_boom_on_space(14,12,7,0);
		set_terrain(14,12,0);
		activate_hidden_group(6);
		set_terrain(17,7,40);
		set_terrain(17,17,38);
		force_instant_terrain_redraw();
		run_animation_sound(43);
		pause(5);

		block_entry(1);
		set_flag(91,1,1);
		change_spec_item(1,1);
		message_dialog("The statue instantly grew wings!  It looks incredibly fearsome, and based on the fact that you're trapped here, you might just have to best it in combat.","");
		if(get_flag(8,0) >= 3){
			message_dialog("You remember, for a brief moment, what this statue is.  It is the statue that defeated Baldev and his tiger fellows at the ritual where he was captured!","According to his story, the statue shot out many beams at him and his fellows.  This upcoming fight may just be your toughest yet, if his story holds any water.");
		}
	}
break;

beginstate 20;

	passage = (get_skill_total(24) + get_skill_total(16) + get_skill_total(2));
	if(passage >= 20){
		set_terrain(30,48,18);
		set_terrain(30,56,21);
		if(get_flag(12,0) == 0){
			message_dialog("A casual observer wouldn't notice a cleverly-placed passage like this one.","Fortunately for you, your familiarity with your surroundings and your outright cleverness allows you to see a secret passage here.  Where, then, does it go?");
			set_flag(12,0,1);
		}
	}

break;

beginstate 25;

	if(get_flag(91,1) < 1){
		block_entry(1);
	}

break;