// Power Source v1.0
// powersource.txt
// by Kelandon (tomwatts@berkeley.edu)

// This is the black magic that I have to do so that my initially inactive power
// sources turn off when they are not being powered.

// This script turns a source off based on the presence of one other power 
// source. Basically, you input information about that other power source, and 
// if the source is not there, this source shuts off.

// I have little hope that this script will be useful to anyone but me, but
// maybe someone will be interested.

// Memory Cells - 
//	0,1 - Coordinates of other power source.
//	2 - Terrain type of other power source. If left at 0, defaults to 384.
//	3 - Whether you want this power source to shut off instantly or delay a
//		little after the other source is off. 0 is delay; 1 is instant.
//	4 - Terrain type of this power source when off. If left a 0, defaults to
//		388.

beginterrainscript; 

variables;

body;

beginstate INIT_STATE;
if (get_memory_cell(3) == 1)
	set_script_mode(3);
	
if (get_memory_cell(2) == 0)
	set_memory_cell(2,384);
	
if (get_memory_cell(4) == 0)
	set_memory_cell(4,388);
	
break;

beginstate START_STATE;
	if (get_terrain(get_memory_cell(0),get_memory_cell(1)) != get_memory_cell(2))
		set_terrain(my_loc_x(),my_loc_y(),get_memory_cell(4));
break;

beginstate SEARCH_STATE;
break;
