// Exploding Terrain v1.0.0
// expolding.txt 
// by Kelandon (tomwatts@berkeley.edu)
//
// Once per turn while the party can see the space where this terrain script is
// located, the script explodes, doing damage to the nearby creatures.
//
// Memory Cells - 
//	0 - What kind of boom to use for explosion. Check the appendices for the
//		choices.
//	1,2 - How much damage to do when exploding. The script will do a random
//		amount between these two numbers. If cell 2 is 0, it defaults to 25.
//	3 - What kind of damage to do.
//		0 - Weapon
//		1 - Fire
//		2 - Poison
//		3 - General Magic
//		4 - Unblockable
//		5 - Cold
//		6 - Acid
//	4 - Radius of damage. The damage will be inflicted on creatures within this
//		number of spaces.
//	5 - What kinds of creatures to damage. If 0, only party-friendly creatures.
//		If 1, only party-hostile creatures. If 2, all creatures.
//	6,7 - Coordinates of the SDF to shut off the explosions.

beginterrainscript; 

variables; 
short last_abil_time,i,j;
short i_am_active = 1;

body; 

beginstate INIT_STATE; // state 0 
	last_abil_time = get_current_tick();
	if (get_memory_cell(1) > get_memory_cell(2))
		{i = get_memory_cell(1);
		j = get_memory_cell(2);
		set_memory_cell(1,j);
		set_memory_cell(2,i);
		}
	if (get_memory_cell(3) > 6)
		print_str_color("Error exploding.txt: cell 3 out of range",1);
break; 

beginstate START_STATE; // state 2
if (get_flag(get_memory_cell(6),get_memory_cell(7)) > 0)
	i_am_active = 0;

if (i_am_active == 0)
	end();

if (tick_difference(last_abil_time,get_current_tick()) > 0)
	if (can_see_char(1000) == 1)
		{print_str("There is an explosion!");
		put_boom_on_space(my_loc_x(),my_loc_y(),get_memory_cell(0),0);
		damage_nearby(get_ran(1,get_memory_cell(1),get_memory_cell(2)),get_memory_cell(3),get_memory_cell(4),get_memory_cell(5));
		last_abil_time = get_current_tick();
		}
break; 

beginstate SEARCH_STATE; // state 100 
break; 

beginstate UNLOCK_SPELL_STATE; // state 101 
break; 

beginstate SANCTIFICATION_STATE; // state 102 
break; 

beginstate BLOCK_MOVE_STATE; // state 112 
break; 

beginstate DISPEL_BARRIER_STATE; // state 113 
break; 

beginstate STEP_INTO_SPOT_STATE; // state 114 
break;