//flaggate.txt - A gate. Starts closed. Is open if
//  a specific flag is set to nonzero

//Cell 0,1 - A flag, if non-zero, gate starts as open

beginobjectscript; // door lever

variables;
	short gate_is_open = 0;

body;

beginstate INIT_STATE;
	set_obj_act_at_dist(ME,1);
	
	if (gf(get_memory_cell(0),get_memory_cell(1)) > 0) {
		gate_is_open = 1;
		set_object_blockage(ME,0);
		if (object_type(ME) == 126)
			set_object_icon(ME,2);
		if (object_type(ME) == 127)
			set_object_icon(ME,3);
		}
	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE; // door closed, waiting
	if (gate_is_open == 0) {
		if (gf(get_memory_cell(0),get_memory_cell(1)) > 0) {
			gate_is_open = 1;
			set_object_blockage(ME,0);
			if (object_type(ME) == 126)
				set_object_icon(ME,2);
			if (object_type(ME) == 127)
				set_object_icon(ME,3);
			}
		}
		else {
			if (gf(get_memory_cell(0),get_memory_cell(1)) == 0) {
				gate_is_open = 0;
				set_object_blockage(ME,1);
				if (object_type(ME) == 126)
					set_object_icon(ME,0);
				if (object_type(ME) == 127)
					set_object_icon(ME,1);
				}
			}

break;

beginstate RUN_ANIM_STATE;
	if (gate_is_open == 0) {
		if (gf(get_memory_cell(0),get_memory_cell(1)) > 0) {
			gate_is_open = 1;
			set_object_blockage(ME,0);
			if (object_type(ME) == 126)
				set_object_icon(ME,2);
			if (object_type(ME) == 127)
				set_object_icon(ME,3);
			}
		}
		else {
			if (gf(get_memory_cell(0),get_memory_cell(1)) == 0) {
				gate_is_open = 0;
				set_object_blockage(ME,1);
				if (object_type(ME) == 126)
					set_object_icon(ME,0);
				if (object_type(ME) == 127)
					set_object_icon(ME,1);
				}
			}
			
break;

beginstate USE_STATE;
break;

beginstate UNLOCK_STATE;
	print_str_color("Unlock Spell: Doesn't affect gates.",2);
break;
