// t14Wizard.txt
//
// Cell 0 - How much damage the beam does.
// Cell 1,2 - Square from which the beam shoots.  (Defaults to creature's
//            current location.)
// Cell 3 - Terrain type to change the square from which the beam shoots
//          when the beam shoots.  (Defaults to no change whatsoever)
// Cell 4 - Terrain type to change the square when the creature dies.
//          (Defaults to no change.)
// Cell 5 - If greater than 0, causes explosion on terrain square when
//          creature dies.
// Cell 6 - Color scheme of ray.  (Defaults to fire.  See BoA Editor Docs
//          Appendices.)
// Cell 7 - Explosion type PLUS ONE to place on target.  If set to 0, no
//          explosion.  (Example: 3 is Teleportation explosion.)
// Cell 8 - Sound effect used.  (Defaults to Big Explosion [152], see BoA
//          Editor Docs Appendices.)
// Cell 9 - Damage type.  (Defaults to Melee- you probably want to change
//          this.  See BoA Editor Docs Appendices.)

begincreaturescript;

variables;
short dtarget,ok,orig,snd,sfx;

body;

beginstate INIT_STATE;

	break;

beginstate DEAD_STATE;

set_terrain(get_memory_cell(1),get_memory_cell(2),get_memory_cell(4));
if(get_memory_cell(5) >= 1){
	put_boom_on_space(get_memory_cell(1),get_memory_cell(2),1,0);
	force_instant_terrain_redraw();
	run_animation_sound(152);
}
else{
	force_instant_terrain_redraw();
}

	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);
	}

break;

beginstate START_STATE; 

if(enemies_nearby(10) >= 1){
		ok = 0;
		while(ok == 0){
			dtarget = get_ran(1,0,119);
			if(char_ok(dtarget) == TRUE){
	if(can_see_loc(char_loc_x(dtarget),char_loc_y(dtarget)) == TRUE && get_attitude(dtarget) != get_attitude(ME)){

orig = get_terrain(get_memory_cell(1),get_memory_cell(2));
if(get_memory_cell(8) == 0){
	snd = 152;
}
else{
	snd = get_memory_cell(8);
}
if(get_memory_cell(7) > 0){
	sfx = (get_memory_cell(7) - 1);
}

set_terrain(get_memory_cell(1),get_memory_cell(2),get_memory_cell(3));
put_straight_zap(get_memory_cell(1),get_memory_cell(2),char_loc_x(dtarget),char_loc_y(dtarget),get_memory_cell(6));
set_character_pose(ME,1);
force_instant_terrain_redraw();
run_animation_sound(snd);
pause(5);
set_char_status(dtarget,4,-250,1,0);
if(dtarget <= 5){
	damage_char(dtarget,get_memory_cell(0),get_memory_cell(9));
}
else{
	damage_char(dtarget,9999,4);
}
ok = 1;
set_character_pose(ME,2);
set_terrain(get_memory_cell(1),get_memory_cell(2),orig);
force_instant_terrain_redraw();
	}
			}
		}
}
else{
	end();
}

break;

beginstate TALKING_STATE;

print_str("Talking: It doesn't respond.");

break;