# sleep

if $ARGS[0] = 'start':
	InSleep = 1
	:loopson
	minut += 1
	stime += 1
	if recuperation = 0:pcs_health += 5
	
	if stime >= 60:
		stime = 0
		pcs_sleep += 15
		gs 'stat'
	end
	
	
	alarm_now = hour * 60 + minut
	if alarm_holiday = 1 and (kanikuli > 0 or week > 5):
		alarm_time = timerEnd * 60 + timerEndM
	elseif week > 5:
		alarm_time = timerEnd * 60 + timerEndM
	else
		alarm_time = timer * 60 + timerM
	end
	alarm_set = alarm_time - rand(1,5)
	if alarm_set <0:
		alarm_set += 1440
	elseif alarm_set >= 1440:
		alarm_set -= 1440
	end
	
	if slept_in = 1:
		gs 'stat'
	elseif pcs_sleep >= 100 and budilnikOn = 0:
		gs 'stat'
	elseif pcs_sleep >= 100 and budilnikOn = 1 and alarm_now >= alarm_set:
		gs 'stat'
	elseif budilnikOn = 1 and alarm_now = alarm_time:
		pcs_mood -= 10
		gs 'stat'
	else
		jump 'loopson'
	end
	InSleep = 0
end


--- sleep ---------------------------------