:: school_schedule[include]
	<<set _schoolDay = $time.weekday - 1>>
	<<if _schoolDay > 4>>
		<!-- It's Saturday or Sunday. Most likely because you are debugging. Let's just pretend as if it's Tuesday then. -->
		<<set _schoolDay = 1>>
	<</if>>

    <<set _schoolTimetable = $quest('school').get('timetable')>>

    <<set _schoolPeriodStartTimes = $quest('school').get('startTimes')>>

	<<run $time.advanceTo(...(_schoolPeriodStartTimes[$quest('school').period]))>>

    <<if _schoolTimetable[_schoolDay].length > $quest('school').period>>
	    <<set _curClassId = _schoolTimetable[_schoolDay][$quest('school').period]>>
    <<else>>
        <<set _curClassId = 'END'>>
    <</if>>
    <<switch _curClassId>>
        <<case 'END'>>
			<<gt 'school_hallway'>>
        <<case 'break'>>
			<<set $quest('school').period += 1>>
            <<gt 'school_hallway_break'>>
        <<case 'breakLunch'>>
			<<set $quest('school').period += 1>>
            <<gt 'school_break_lunch'>>

        <<default>>
			<<if $quest('school').period == 0>>
				<<gt 'school_schedule_before_class' _curClassId>><!-- Avoid doubled gt... which is annoying -->
			<<else>>
            	<<gt 'school_schedule_before_class' _curClassId>>
			<</if>>

    <</switch>>

/* :: school_schedule_end[quest]
	<<image 'locations/pavlovsk/school/building/gschool_hall0#.jpg' 0 2>>
	<p>School is over for today.</p>

	<<act 'Leave the building'>>
		<<gt 'school_grounds'>>
	<</act>>
*/

:: school_schedule_before_class[event]
	<<set _curClassId = $location_var[$here][0]>>
	<h2>School Hallway</h2>

	<<image 'locations/pavlovsk/school/building/gschool_hall0#.jpg' 0 2>>
	<<gs 'gschool_gossip' 'gossip'>>


	<<if Story.has('school_lesson_'+_curClassId)>>
		<<set _curClass = setup.func('school_lesson_'+_curClassId,'getData')>>

		<<act `'Go to next class ('+_curClass.label+')'`>>
			<<gt 'school_lesson' _curClassId>>
			<<set $quest('school').period += 1>>
		<</act>>
		<<act 'Skip next class'>>
			/*<<set $quest('school').period += 1>>
			<<run $quest('school').inc('missedClasses',1)>>*/
			<<gt 'school_skip_class'>>
		<</act>>
		<<act 'Leave school'>>
			<<set _schoolDay = $time.weekday - 1>>
			<<for _key, _classId range $quest('school').get('timetable')[_schoolDay]>>
				<<if _classId != 'break' and _classId != 'breakLunch' and _key >= $quest('school').period>>
					<<run $quest('school').inc('missedClasses',1)>>
				<</if>>
			<</for>>
			<<gt 'school_grounds'>>
		<</act>>
	<<else>>
		<<notice>>The next class (_curClassId) currently does not exist. You can directly skip to the next one.<</notice>>
		<<act 'Skip next class'>>
			<<set $quest('school').period += 1>>
			<<gs 'school_schedule'>>
		<</act>>
	<</if>>
