//flaglever.txt - Lever which, when pulled, flips a flag from 0 to 1 and back. No locks
// or other trickery.
//Cell 0,1 - The sdf which is set to 1 or 0 when lever is pulled.
// Cell 2 - skill needed, if 0 none
// Cell 3 - If 1, can't flip back
beginobjectscript; 

variables;

short range = 0;
short i,j;

body;

beginstate INIT_STATE;

	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE; // door closed, waiting
break;

beginstate USE_STATE;

	print_str("Pull Lever: You pull the lever.");
	play_sound(21);
	
	if (get_memory_cell(0) == 0) {
		if ((gf(13,20) > 0) || (gf(13,22) > 0) || (party_within_dist(15,40,6) == FALSE)) {
			ok_dlog(54,1);
			}
			else {
				ok_dlog(52,1);
				sf(13,21,4);
				sf(13,20,1);
				
				i = 14; j = 25;
				while (i < 17) {
					while (j < 39) {
						make_field(0,i,j,0);
						j = j + 1;
						}
					j = 25;
					
					i = i + 1;
					}
				}
		}
	if (get_memory_cell(0) == 1) {
		if ((gf(13,23) > 0) || (gf(13,25) > 0) || (party_within_dist(26,12,6) == FALSE)) {
			ok_dlog(54,1);
			}
			else {
				ok_dlog(57,1);
				sf(13,24,4);
				sf(13,23,1);
				
				if (difficulty() > 0) {
					spawn_creature(1347);
					place_particle_num(1347,1,1,8);
					set_level(1347,20 + difficulty() * 3);
					set_summon_level(1347,1);
					if (difficulty() > 1)
						set_new_abil(1347,14);
					}				
				if (difficulty() > 1) {
					spawn_creature(1346);
					place_particle_num(1346,1,1,8);
					set_level(1346,20 + difficulty() * 3);
					set_summon_level(1346,1);
					if (difficulty() > 1)
						set_new_abil(1346,14);
					}				

				i = 26; j = 11;
				while (i < 41) {
					while (j < 14) {
						make_field(0,i,j,1);
						j = j + 1;
						}
					j = 11;
					
					i = i + 1;
					}
				}
		}
break;
