@LabelIndex 422066
@StringIndex 63811
class 1 fortress_inzone_maker : inzone_maker {
parameter:
	string	maker_name = "fortress_inzone_maker_default";
	int	timer = 0;

handler:
	EventHandler ON_INSTANT_ZONE_EVENT(inzone_type_id,inzone_id,event_id,reply,i0,def0,i1) {
		myself.enabled = reply;
		if( reply == 1 && timer > 0 ) {
			myself::AddTimerEx(1991,( timer * 1000 ));
			return;
		}
		if( reply == 1 ) {
			i0 = gg::Rand(myself.def_count);
			def0 = myself::GetSpawnDefine(i0);
			if( gg::IsNull(def0) == 0 ) {
				i1 = ( def0.total - def0.npc_count );
				if( i1 > 0 ) {
					if( myself::AtomicIncreaseTotal(def0,i1,1) ) {
						def0::Spawn2(i1,0,0);
					}
				}
			}
		}
	}

	EventHandler ON_NPC_DELETED(deleted_def,died,i0,i1,maker0,i2) {
		if( died == 0 ) {
			return;
		}
		if( myself.enabled ) {
			if( gg::IsSameString(maker_name,"fortress_inzone_maker_default") == 1 ) {
				return;
			}
			i2 = myself::GetInZoneID();
			maker0 = gg::InstantZone_GetNpcMaker(i2,maker_name);
			if( gg::IsNull(maker0) == 0 ) {
				gg::SendMakerScriptEvent(maker0,1003,0,0);
			}
		}
	}

	EventHandler ON_SCRIPT_EVENT(script_event_arg1,script_event_arg2,script_event_arg3,def0,i0,i1) {
		if( myself.enabled == 0 ) {
			return;
		}
		switch(script_event_arg1) {
			case 1003: {
				if( myself.enabled == 1 && timer > 0 ) {
					myself::AddTimerEx(1991,( timer * 1000 ));
					return;
				}
				i0 = gg::Rand(myself.def_count);
				def0 = myself::GetSpawnDefine(i0);
				if( gg::IsNull(def0) == 0 ) {
					i1 = ( def0.total - def0.npc_count );
					if( i1 > 0 ) {
						if( myself::AtomicIncreaseTotal(def0,i1,1) ) {
							def0::Spawn2(i1,0,0);
						}
					}
				}
				break;
			}
		}
	}

	EventHandler ON_TIMER(timer_id,i0,i1,maker0,def0) {
		if( timer_id == 1991 ) {
			i0 = gg::Rand(myself.def_count);
			def0 = myself::GetSpawnDefine(i0);
			if( gg::IsNull(def0) == 0 ) {
				i1 = ( def0.total - def0.npc_count );
				if( i1 > 0 ) {
					if( myself::AtomicIncreaseTotal(def0,i1,1) ) {
						def0::Spawn2(i1,0,0);
					}
				}
			}
		}
	}

}
