// Walllever.txt
// version 1.0.0
// by Thralni

// You can alway use this script freely, but put my name (Thralni) in the acknowledgements.

// walllever.txt -  the same as doorlever, only for wall removing (or other terrain removing (or replacing)). The party pulls a lever,
// by which up to two walls are removed. The walls are not put back upon pulling the lever a second time. You have to leave town first,
// and re-enter

// Memory Cells - 
//   0,1 - The x,y coordinates of a terrain this lever replaces by a terrain number defined in memory cell 2. If both are left at 0, doesn't
//     do anything.
//	 2   - the terrain of location (memory cells 0 and 1) to change in.
//   3,4 - The x,y coordinates of a second terrain this lever replaces by a terrain number defined in memory cell 5. If both are left at 0, doesn't
//     do anything.
//	 5   - the terrain of location (memory cells 0 and 1) to change in.
//   6,7 -  Coordinates for a stuff done flag. If these are 0 and 0, ignored. Otherwise,
//     when the lever is pulled, if the stuff done flag is 0, it becomes 1, and if the flag
//     is non-zero, it becomes 0.
//     If a flag is assigned here and is set to when, when the party enters this town later,
//     this script will open the gates.

beginterrainscript; 

variables;

short choice;
	
body;

beginstate INIT_STATE;
break;

beginstate START_STATE;
break;

beginstate SEARCH_STATE;
break;

beginstate STEP_INTO_SPOT_STATE;
	reset_dialog();
	add_dialog_str(0,"This lever just stands here. You really don't see something it could possibly open. Try anyway?",0);
	add_dialog_choice(0,"Leave it");
	add_dialog_choice(1,"Pull and see what happens");
	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) || (get_memory_cell(2) > 0)) 
		set_terrain(get_memory_cell(0),get_memory_cell(1),get_memory_cell(2));

	if ((get_memory_cell(3) > 0) || (get_memory_cell(4) > 0) || (get_memory_cell(5) > 0)) 
		set_terrain(get_memory_cell(3),get_memory_cell(4),get_memory_cell(5));

	if ((get_memory_cell(6) > 0) || (get_memory_cell(7) > 0)) {
		if (get_flag(get_memory_cell(6),get_memory_cell(7)) == 0)
			set_flag(get_memory_cell(6),get_memory_cell(7),1);
			else set_flag(get_memory_cell(6),get_memory_cell(7),0);
		}
break;
