// doorlever.txt -  A lever that opens nearby gates. When it is walked onto, asks if the
// party wants to pull it. if they do, swaps up to 2 terrain spots. 

// (When a terrain type is defined, you can set a swap terrain type for
// is, a terrain type that it changes to if it is opened/closed. For
// example, a closed gate's swap terrain is an open gate.

// Memory Cells - 
//   0,1 - The x,y coordinated of a gate this level opens. If both are left at 0, doesn't
//     do anything.
//   2,3 - The x,y coordinates of a second gate this lever opens. If both are left at 0, doesn't
//     do anything.
//   6 -  Special Item needed to open gate.  If special item
//        is missing, party is instructed that they require it.
//        If set to 0, party needs no special item.

beginterrainscript; 

variables;

	short choice;
body;

beginstate INIT_STATE;
	break;

beginstate START_STATE;
break;

beginstate SEARCH_STATE;

break;

beginstate STEP_INTO_SPOT_STATE;
	if(has_special_item(get_memory_cell(6)) >= 1 || get_memory_cell(6) == 0){
		reset_dialog_preset_options(2);
		choice = run_dialog(0);
		if (choice == 1)
			end();
	
		flip_terrain(my_loc_x(),my_loc_y());
		play_sound(106);
		play_sound(99);
		print_str_color("You hear the sounds of chains and grinding gears.",2);

		if ((get_memory_cell(0) > 0) || (get_memory_cell(1) > 0)) 
flip_terrain(get_memory_cell(0),get_memory_cell(1));

		if ((get_memory_cell(2) > 0) || (get_memory_cell(3) > 0)) 
flip_terrain(get_memory_cell(2),get_memory_cell(3));

		if ((get_memory_cell(4) > 0) || (get_memory_cell(5) > 0)) {
			if (get_flag(get_memory_cell(4),get_memory_cell(5)) == 0)
set_flag(get_memory_cell(4),get_memory_cell(5),1);
			else
set_flag(get_memory_cell(4),get_memory_cell(5),0);
		}
	}
	else{
		message_dialog("There is a lever here.  Unfortunately, it has a locking device on it, and you are missing the appropriate key.","");
	}
break;
