begincreaturescript;

variables;

short i,target,remark,which;

body;

beginstate INIT_STATE;
	if (get_memory_cell(0) == 2)
		set_mobility(ME,0);
	break;

beginstate DEAD_STATE;

	message_dialog("Unumstš§lich topples over, bleeding profusely.  _This can't be...  Our ideals were unbeatable..._","He coughs up blood all over the floor.  _Now I see why Zauberer was slain...  The power..._  He expires.");

	inc_flag(68,6,1);
	if(get_flag(68,6) >= 9){
		set_terrain(14,20,289);
		set_terrain(18,20,291);
		put_effect_on_space(14,20,8,4,0);
		put_effect_on_space(18,20,8,4,0);
		force_instant_terrain_redraw();
		run_animation_sound(89);
		pause(5);
		message_dialog("Finally, all of the wizards in the Mezanine and their master are destroyed.","The barriers collapse.  Maybe now, you will be able to see Trahison and put an end to this.");
		set_flag(26,0,50);
	award_party_xp(500,40);
	award_party_xp(500,40);
	award_party_xp(500,40);
	}

break;

beginstate START_STATE; 
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_target(ME,-1);
		}
	
	// Look for a target, attack it if visible
	if (select_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
		
	// Have I been hit? Strike back!
	if (who_hit_me() >= 0) {
		set_target(ME,who_hit_me());
		do_attack();
		set_state(3);
		}
		
	// Otherwise, just peacefully move around. Go back to start, if I'm too far
	// from where I started.
	if ((my_dist_from_start() >= 6) || ((my_dist_from_start() > 0) && (get_memory_cell(0) > 0))) {
		if (get_ran(1,1,100) < 40) 
			return_to_start(ME,1);
		}
		else if (get_memory_cell(0) == 0) {
			fidget(ME,25);
			}

	// if we're in combat and the above didn't give me anything to do, just
	// stop now. Otherwise, game will keep running script, and that eats up CPU time.
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking

// Naughty remarks...

if(get_health(ME) < get_max_health(ME)){
	if(remark == 0){
		message_dialog("Unumstš§lich's jaw drops as he grasps his newly-acquired wound.  _How did you do that?  I'm invincible!  This can't be happening!_","He scowls.  _Fine.  The gloves are off now, you will never leave here alive!_  Suddenly, you hear a rumbling to the east...");
		remark = 1;
		set_terrain(24,13,0);
		set_terrain(24,15,0);
		set_terrain(24,17,0);
		activate_hidden_group(2);
		set_flag(68,5,1);
	}
}
else{
		if(get_ran(1,0,4) == 0){
	which = get_ran(1,1,10);
	if(which == 1){
		text_bubble_on_char(34,"You can never win!");
	}
	if(which == 2){
		text_bubble_on_char(34,"I will avenge Zauberer!");
	}
	if(which == 3){
		text_bubble_on_char(34,"I am invincible!");
	}
	if(which == 4){
		if(get_flag(30,0) == 1){
			text_bubble_on_char(34,"This is for Klugmann!");
		}
		else{
			text_bubble_on_char(34,"This is for Todmacher!");
		}
	}
	if(which == 5){
		text_bubble_on_char(34,"This is for Fusei!");
	}
	if(which == 6){
		text_bubble_on_char(34,"Death to Leader!");
	}
	if(which == 7){
		if(party_size() > 1)
			text_bubble_on_char(34,"Death to the Specialists!");
		if(party_size() == 1)
			text_bubble_on_char(34,"Death to the Specialist!");
	}
	if(which == 8){
		text_bubble_on_char(34,"This is for Adlerauge!");
	}
	if(which == 9){
		text_bubble_on_char(34,"You will never see Trahison!");
	}
	if(which == 10){
		text_bubble_on_char(34,"And now, you die!");
	}
	force_instant_terrain_redraw();
	pause(10);
	text_bubble_on_char(34,"");
	force_instant_terrain_redraw();
	pause(2);
		}
}

	if (target_ok() == FALSE)
		set_state(START_STATE);
	do_attack();
break;

beginstate TALKING_STATE;
	if (get_memory_cell(3) == 0) {
		print_str("Talking: It doesn't respond.");
		end();
		}
	begin_talk_mode(get_memory_cell(3));
break;