# transport_functions

if $ARGS[0] = 'init_all':
	gs 'transport_functions', 'init_train_prices'
	gs 'transport_functions', 'init_train_timecosts'
	gs 'transport_functions', 'init_bus_prices'
	gs 'transport_functions', 'init_bus_timecosts'
end



	!!=======================================!!
	!!                                       !!
	!!                Trains                 !!
	!!                                       !!
	!!=======================================!!


if $ARGS[0] = 'buy_train_pass':
	if transportVars['trainpass_day'] <= daystart:
		if money >= 250:
			dynamic 'act ''Buy a daily pass (1 day - 250 <b>₽</b>)'':
				cla
				money -= 250
				transportVars[''trainpass_day''] = daystart + 1
				act ''Return'': gt ''<<$loc>>'', ''<<$loc_arg>>''
			end'
		end

		if money >= 1500:
			dynamic 'act ''Buy a weekly pass (7 days - 1500 <b>₽</b>)'':
				cla
				money -= 1500
				transportVars[''trainpass_day''] = daystart + 7
				act ''Return'': gt ''<<$loc>>'', ''<<$loc_arg>>''
			end'
		end

		if money >= 5500:
			dynamic 'act ''Buy a monthly pass (30 days - 5500 <b>₽</b>)'':
				cla
				money -= 5500
				transportVars[''trainpass_day''] = daystart + 30
				act ''Return'': gt ''<<$loc>>'', ''<<$loc_arg>>''
			end'
		end

		if money >= 75000:
			dynamic 'act ''Buy a yearly pass (365 days - 75000 <b>₽</b>)'':
				cla
				money -= 75000
				transportVars[''trainpass_day''] = daystart + 365
				act ''Return'': gt ''<<$loc>>'', ''<<$loc_arg>>''
			end'
		end
	end
end


if $ARGS[0] = 'buy_train_ticket':
	if $ARGS[2] = 'pc':
		if $ARGS[1] ! 'pavlovsk':	gs 'transport_functions', 'set_train_ticket', $ARGS[1],	'pavlovsk',	'Pavlovsk'
		if $ARGS[1] ! 'gadukino':	gs 'transport_functions', 'set_train_ticket', $ARGS[1],	'gadukino',	'the village of Gadukino'
		if $ARGS[1] ! 'communal':	gs 'transport_functions', 'set_train_ticket', $ARGS[1],	'communal',	'the communal village'
		if $ARGS[1] ! 'ind':		gs 'transport_functions', 'set_train_ticket', $ARGS[1],	'ind',		'St. Petersburg city industrial area'
		if $ARGS[1] ! 'center':		gs 'transport_functions', 'set_train_ticket', $ARGS[1],	'center',	'St. Petersburg city center'
	else
		if $ARGS[1] ! 'center':		gs 'transport_functions', 'set_train_ticket', $ARGS[1],	'center',	'St. Petersburg city center'
		if $ARGS[1] ! 'ind':		gs 'transport_functions', 'set_train_ticket', $ARGS[1],	'ind',		'St. Petersburg city industrial area'
		if $ARGS[1] ! 'communal':	gs 'transport_functions', 'set_train_ticket', $ARGS[1],	'communal',	'the communal village'
		if $ARGS[1] ! 'gadukino':	gs 'transport_functions', 'set_train_ticket', $ARGS[1],	'gadukino',	'the village of Gadukino'
		if $ARGS[1] ! 'pavlovsk':	gs 'transport_functions', 'set_train_ticket', $ARGS[1],	'pavlovsk',	'Pavlovsk'
	end
end

! $ARGS[1] = origin loc_arg
! $ARGS[2] = destination loc_arg
! $ARGS[3] = destination name
if $ARGS[0] = 'set_train_ticket':
	temp_price = transportVars['train_price_<<$ARGS[1]>>_<<$ARGS[2]>>']
	$temp_time = func('transport_functions', 'display_train_timecost', $ARGS[1], $ARGS[2])

	if mid($temp_time, 1, 1) < 2:
		if money < ARGS[1]:
			dynamic 'act ''Buy a ticket to <<$ARGS[3]>> (<font color="red"><<$temp_time>> - <<temp_price>> <b>₽</b></font>)'': ''<br><font color="red">You don''t have enough money for a ticket to <<$ARGS[3]>>'' '
		else
			dynamic 'act ''Buy a ticket to <<$ARGS[3]>> (<<$temp_time>> - <<temp_price>> <b>₽</b>)'':
					money -= <<temp_price>>
					menu_off = 1
					gt ''train'', ''<<$ARGS[1]>>_<<$ARGS[2]>>''
				end'
		end
	end
	killvar 'temp_price'
	killvar 'temp_time'
end


!	Time Table:
!		Train departs every 15 minutes (between 4:00 and 22:00), 30 minutes (between 22:00 and 01:00) and 60 minute (betweeen 01:00 and 04:00)
!		pavlovsk (07)	->	gadukino (22)	->	communal (32)	->	ind (42)		->	center
!		center (02)		->	ind (07)		->	communal (17)	->	gadukino (27)	->	pavlovsk

if $ARGS[0] = 'set_train_wait_time':
	if $ARGS[1] = 'pavlovsk':
		if hour = 0:
			transportVars['train_wait_center']		= (67 - minut) mod 30
		elseif hour <= 3:
			transportVars['train_wait_center']		= (67 - minut) mod 60
		elseif hour <= 21:
			transportVars['train_wait_center']		= (67 - minut) mod 15
		else
			transportVars['train_wait_center']		= (67 - minut) mod 30
		end	
	elseif $ARGS[1] = 'gadukino':
		if hour = 0:
			transportVars['train_wait_center']		= (82 - minut) mod 30
			transportVars['train_wait_pavlovsk']	= (87 - minut) mod 30
		elseif hour <= 3 or hour = 4 and minut <= 22:
			transportVars['train_wait_center']		= (82 - minut) mod 60
			transportVars['train_wait_pavlovsk']	= (87 - minut) mod 60
		elseif hour = 4 and minut <= 27:
			transportVars['train_wait_center']		= (82 - minut) mod 15
			transportVars['train_wait_pavlovsk']	= (87 - minut) mod 60
		elseif hour <= 21 or hour = 22 and minut <= 7:
			transportVars['train_wait_center']		= (82 - minut) mod 15
			transportVars['train_wait_pavlovsk']	= (87 - minut) mod 15
		elseif hour = 22 and minut <= 12:
			transportVars['train_wait_center']		= (82 - minut) mod 30
			transportVars['train_wait_pavlovsk']	= (87 - minut) mod 15
		else
			transportVars['train_wait_center']		= (82 - minut) mod 30
			transportVars['train_wait_pavlovsk']	= (87 - minut) mod 30
		end
	elseif $ARGS[1] = 'communal':
		if hour = 0 or hour = 1 and minut <= 2:
			transportVars['train_wait_center']		= (92 - minut) mod 30
			transportVars['train_wait_pavlovsk']	= (77 - minut) mod 30
		elseif hour <= 3 or hour = 4 and minut <= 17:
			transportVars['train_wait_center']		= (92 - minut) mod 60
			transportVars['train_wait_pavlovsk']	= (77 - minut) mod 60
		elseif hour = 4 and minut <= 32:
			transportVars['train_wait_center']		= (92 - minut) mod 15
			transportVars['train_wait_pavlovsk']	= (77 - minut) mod 60
		elseif hour <= 21 or hour = 22 and minut <= 2:
			transportVars['train_wait_center']		= (92 - minut) mod 15
			transportVars['train_wait_pavlovsk']	= (77 - minut) mod 15
		elseif hour = 22 and minut <= 17:
			transportVars['train_wait_center']		= (92 - minut) mod 15
			transportVars['train_wait_pavlovsk']	= (77 - minut) mod 30
		else
			transportVars['train_wait_center']		= (92 - minut) mod 30
			transportVars['train_wait_pavlovsk']	= (77 - minut) mod 30
		end
	elseif $ARGS[1] = 'ind':
		if hour = 0:
			transportVars['train_wait_center']		= (102 - minut) mod 30
			transportVars['train_wait_pavlovsk']	= (67 - minut) mod 30
		elseif hour = 1 and minut <= 12:
			transportVars['train_wait_center']		= (102 - minut) mod 30
			transportVars['train_wait_pavlovsk']	= (67 - minut) mod 60
		elseif hour <= 3:
			transportVars['train_wait_center']		= (102 - minut) mod 60
			transportVars['train_wait_pavlovsk']	= (67 - minut) mod 60
		elseif hour = 4 and minut <= 42:
			transportVars['train_wait_center']		= (102 - minut) mod 60
			transportVars['train_wait_pavlovsk']	= (67 - minut) mod 15
		elseif hour <= 21:
			transportVars['train_wait_center']		= (102 - minut) mod 15
			transportVars['train_wait_pavlovsk']	= (67 - minut) mod 15
		elseif hour = 22 and minut <= 27:
			transportVars['train_wait_center']		= (102 - minut) mod 15
			transportVars['train_wait_pavlovsk']	= (67 - minut) mod 30
		else
			transportVars['train_wait_center']		= (102 - minut) mod 30
			transportVars['train_wait_pavlovsk']	= (67 - minut) mod 30
		end
	elseif $ARGS[1] = 'center':
		if hour = 0:
			transportVars['train_wait_pavlovsk']	= (62 - minut) mod 30
		elseif hour <= 3:
			transportVars['train_wait_pavlovsk']	= (62 - minut) mod 60
		elseif hour <= 21:
			transportVars['train_wait_pavlovsk']	= (62 - minut) mod 15
		else
			transportVars['train_wait_pavlovsk']	= (62 - minut) mod 30
		end
	end
end

if $ARGS[0] = 'display_trainpass_time':
	$result = 'You have <<transportVars[''trainpass_day''] - daystart>> days left on your train pass.'
end

if $ARGS[0] = 'display_train_timecost':
	temp_mins = transportVars['train_time_<<$ARGS[1]>>_<<$ARGS[2]>>']
	if $ARGS[1] = 'pavlovsk' or $ARGS[2] = 'center 'or ($ARGS[1] = 'gadukino' and $ARGS[2] ! 'pavlovsk') or ($ARGS[1] = 'communal' and $ARGS[2] = 'ind'):
		temp_mins += transportVars['train_wait_center']
	else
		temp_mins += transportVars['train_wait_pavlovsk']
	end
	temp_hours = temp_mins / 60
	temp_mins = temp_mins mod 60
	$result = '<<temp_hours>>:<<$mid(100 + temp_mins, 2, 2)>>'
	killvar 'temp_mins'
	killvar 'temp_hours'
end

if $ARGS[0] = 'display_train_schedule':
	if $ARGS[1] = 'pc':
		$train_schedule += '<center><h2>Pavlovsk - St. Petersburg</h2></center>'
		$train_schedule += '<br><center><table style="text-align:center">'
		$train_schedule += '<tr><th></th><th></th><th>Communal</th><th>St. Petersburg</th><th>St. Petersburg</th><th style="border-right:2px solid black; border-left:2px solid black"> </th><th></th><th></th><th>Communal</th><th>St. Petersburg</th><th>St. Petersburg</th></tr>'
		$train_schedule += '<tr><th style="border-right:2px solid black">Pavlovsk</th><th style="border-right:2px solid black">Gadukino</th><th style="border-right:2px solid black">Village</th><th style="border-right:2px solid black">Industrial</th><th>Center</th><th style="border-right:2px solid black; border-left:2px solid black"> </th><th style="border-right:2px solid black">Pavlovsk</th><th style="border-right:2px solid black">Gadukino</th><th style="border-right:2px solid black">Village</th><th style="border-right:2px solid black">Industrial</th><th style="border-right:2px solid black">Center</th></tr>'
		$train_schedule += '<tr><td colspan=11 style="border-bottom:2px solid black"></td></tr>'

		th[0] = 0
		:train_schedule_loop1
			$th[1] = mid(100 + th[0], 2, 2)
			$th[2] = mid(100 + th[0] + 1, 2, 2)

			th[3] = th[0] + 12
			$th[4] = mid(100 + th[3], 2, 2)
			$th[5] = mid(100 + th[3] + 1, 2, 2)

			$train_schedule += '<tr>'
			$train_schedule += '<td><<$th[1]>>:07</td><td><<$th[1]>>:22</td><td><<$th[1]>>:32</td><td><<$th[1]>>:42</td><td><<$th[1]>>:47</td>'
			$train_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
			$train_schedule += '<td><<$th[4]>>:07</td><td><<$th[4]>>:22</td><td><<$th[4]>>:32</td><td><<$th[4]>>:42</td><td><<$th[4]>>:47</td>'
			$train_schedule += '</tr>'

			if th[0] >= 4 or th[3] <= 21:
				$train_schedule += '<tr>'
				if th[0] >= 4:
					$train_schedule += '<td><<$th[1]>>:22</td><td><<$th[1]>>:37</td><td><<$th[1]>>:47</td><td><<$th[1]>>:57</td><td><<$th[2]>>:02</td>'
				else
					$train_schedule += '<td colspan=5></td>'
				end
				$train_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
				if th[3] <= 21:
					$train_schedule += '<td><<$th[4]>>:22</td><td><<$th[4]>>:37</td><td><<$th[4]>>:47</td><td><<$th[4]>>:57</td><td><<$th[5]>>:02</td>'
				else
					$train_schedule += '<td colspan=5></td>'
				end
				$train_schedule += '</tr>'
			end

			$train_schedule += '<tr>'
			if th[0] = 0 or th[0] >= 4:
				$train_schedule += '<td><<$th[1]>>:37</td><td><<$th[1]>>:52</td><td><<$th[2]>>:02</td><td><<$th[2]>>:12</td><td><<$th[2]>>:17</td>'
			else
				$train_schedule += '<td colspan=5></td>'
			end
			$train_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
			$train_schedule += '<td><<$th[4]>>:22</td><td><<$th[4]>>:37</td><td><<$th[4]>>:47</td><td><<$th[4]>>:57</td><td><<$th[5]>>:02</td></tr>'

			if th[0] >= 4 or th[3] <= 21:
				$train_schedule += '<tr>'
				if th[0] >= 4:
					$train_schedule += '<td><<$th[1]>>:52</td><td><<$th[2]>>:07</td><td><<$th[2]>>:17</td><td><<$th[2]>>:27</td><td><<$th[2]>>:32</td>'
				else
					$train_schedule += '<td colspan=5></td>'
				end
				$train_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
				if th[3] <= 21:
					$train_schedule += '<td><<$th[4]>>:52</td><td><<$th[5]>>:07</td><td><<$th[5]>>:17</td><td><<$th[5]>>:27</td><td><<$th[5]>>:32</td>'
				else
					$train_schedule += '<td colspan=5></td>'
				end
				$train_schedule += '</tr>'
			end

			$train_schedule += '<tr><td colspan=11 style="border-bottom:1px solid black"></td></tr>'

			th[0] += 1
		if th[0] < 12: jump 'train_schedule_loop1'
	else
		$train_schedule += '<center><h2>St. Petersburg - Pavlovsk</h2></center>'
		$train_schedule += '<br><center><table style="text-align:center">'
		$train_schedule += '<tr><th>St. Petersburg</th><th>St. Petersburg</th><th>Communal</th><th></th><th></th><th style="border-right:2px solid black; border-left:2px solid black"> </th><th>St. Petersburg</th><th>St. Petersburg</th><th>Communal</th><th></th><th></th></tr>'
		$train_schedule += '<tr><th style="border-right:2px solid black">Center</th><th style="border-right:2px solid black">Industrial</th><th style="border-right:2px solid black">Village</th><th style="border-right:2px solid black">Gadukino</th><th>Pavlovsk</th><th style="border-right:2px solid black; border-left:2px solid black"> </th><th style="border-right:2px solid black">Center</th><th style="border-right:2px solid black">Industrial</th><th style="border-right:2px solid black">Village</th><th style="border-right:2px solid black">Gadukino</th><th style="border-right:2px solid black">Pavlovsk</th></tr>'
		$train_schedule += '<tr><td colspan=11 style="border-bottom:2px solid black"></td></tr>'

		th[0] = 0
		:train_schedule_loop2
			$th[1] = mid(100 + th[0], 2, 2)
			$th[2] = mid(100 + th[0] + 1, 2, 2)

			th[3] = th[0] + 12
			$th[4] = mid(100 + th[3], 2, 2)
			$th[5] = mid(100 + th[3] + 1, 2, 2)

			$train_schedule += '<tr>'
			$train_schedule += '<td><<$th[1]>>:02</td><td><<$th[1]>>:07</td><td><<$th[1]>>:17</td><td><<$th[1]>>:27</td><td><<$th[1]>>:42</td>'
			$train_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
			$train_schedule += '<td><<$th[4]>>:02</td><td><<$th[4]>>:07</td><td><<$th[4]>>:17</td><td><<$th[4]>>:27</td><td><<$th[4]>>:42</td>'
			$train_schedule += '</tr>'

			if th[0] >= 4 or th[3] <= 21:
				$train_schedule += '<tr>'
				if th[0] >= 4:
					$train_schedule += '<td><<$th[1]>>:17</td><td><<$th[1]>>:22</td><td><<$th[1]>>:32</td><td><<$th[1]>>:42</td><td><<$th[1]>>:57</td>'
				else
					$train_schedule += '<td colspan=5></td>'
				end
				$train_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
				if th[3] <= 21:
					$train_schedule += '<td><<$th[4]>>:17</td><td><<$th[4]>>:22</td><td><<$th[4]>>:32</td><td><<$th[4]>>:42</td><td><<$th[4]>>:57</td>'
				else
					$train_schedule += '<td colspan=5></td>'
				end
				$train_schedule += '</tr>'
			end

			$train_schedule += '<tr>'
			if th[0] = 0 or th[0] >= 4:
				$train_schedule += '<td><<$th[1]>>:32</td><td><<$th[1]>>:37</td><td><<$th[1]>>:47</td><td><<$th[1]>>:57</td><td><<$th[2]>>:12</td>'
			else
				$train_schedule += '<td colspan=5></td>'
			end
			$train_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
			$train_schedule += '<td><<$th[4]>>:32</td><td><<$th[4]>>:37</td><td><<$th[4]>>:47</td><td><<$th[4]>>:57</td><td><<$th[5]>>:12</td></tr>'

			if th[0] >= 4 or th[3] <= 21:
				$train_schedule += '<tr>'
				if th[0] >= 4:
					$train_schedule += '<td><<$th[1]>>:47</td><td><<$th[1]>>:52</td><td><<$th[2]>>:02</td><td><<$th[2]>>:12</td><td><<$th[2]>>:27</td>'
				else
					$train_schedule += '<td colspan=5></td>'
				end
				$train_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
				if th[3] <= 21:
					$train_schedule += '<td><<$th[4]>>:47</td><td><<$th[4]>>:52</td><td><<$th[5]>>:02</td><td><<$th[5]>>:12</td><td><<$th[5]>>:27</td>'
				else
					$train_schedule += '<td colspan=5></td>'
				end
				$train_schedule += '</tr>'
			end
			$train_schedule += '<tr><td colspan=11 style="border-bottom:1px solid black"></td></tr>'

			th[0] += 1
		if th[0] < 12: jump 'train_schedule_loop2'
	end
	$train_schedule += '</table></center>'

	'<<$train_schedule>>'

	killvar 'train_schedule'
	killvar 'th'
end




if $ARGS[0] = 'init_train_prices':
	transportVars['train_price_pavlovsk_gadukino']	= func('transport_functions', 'get_train_price', 'pavlovsk', 'gadukino')
	transportVars['train_price_pavlovsk_communal']	= func('transport_functions', 'get_train_price', 'pavlovsk', 'communal')
	transportVars['train_price_pavlovsk_ind']		= func('transport_functions', 'get_train_price', 'pavlovsk', 'ind')
	transportVars['train_price_pavlovsk_center']	= func('transport_functions', 'get_train_price', 'pavlovsk', 'center')

	transportVars['train_price_gadukino_pavlovsk']	= transportVars['train_price_pavlovsk_gadukino']
	transportVars['train_price_gadukino_communal']	= func('transport_functions', 'get_train_price', 'gadukino', 'communal')
	transportVars['train_price_gadukino_ind']		= func('transport_functions', 'get_train_price', 'gadukino', 'ind')
	transportVars['train_price_gadukino_center']		= func('transport_functions', 'get_train_price', 'gadukino', 'center')

	transportVars['train_price_communal_pavlovsk']	= transportVars['train_price_pavlovsk_communal']
	transportVars['train_price_communal_gadukino']	= transportVars['train_price_gadukino_communal']
	transportVars['train_price_communal_ind']		= func('transport_functions', 'get_train_price', 'communal', 'ind')
	transportVars['train_price_communal_center']	= func('transport_functions', 'get_train_price', 'communal', 'center')

	transportVars['train_price_ind_pavlovsk']		= transportVars['train_price_pavlovsk_ind']
	transportVars['train_price_ind_gadukino']		= transportVars['train_price_gadukino_ind']
	transportVars['train_price_ind_communal']		= transportVars['train_price_communal_ind']
	transportVars['train_price_ind_center']			= func('transport_functions', 'get_train_price', 'ind', 'center')

	transportVars['train_price_center_pavlovsk']	= transportVars['train_price_pavlovsk_center']
	transportVars['train_price_center_gadukino']		= transportVars['train_price_gadukino_center']
	transportVars['train_price_center_communal']	= transportVars['train_price_communal_center']
	transportVars['train_price_center_ind']			= transportVars['train_price_ind_center']
end

if $ARGS[0] = 'init_train_timecosts':
	transportVars['train_time_pavlovsk_gadukino']	= func('transport_functions', 'get_train_timecost', 'pavlovsk', 'gadukino')
	transportVars['train_time_pavlovsk_communal']	= func('transport_functions', 'get_train_timecost', 'pavlovsk', 'communal')
	transportVars['train_time_pavlovsk_ind']		= func('transport_functions', 'get_train_timecost', 'pavlovsk', 'ind')
	transportVars['train_time_pavlovsk_center']		= func('transport_functions', 'get_train_timecost', 'pavlovsk', 'center')

	transportVars['train_time_gadukino_pavlovsk']	= transportVars['train_time_pavlovsk_gadukino']
	transportVars['train_time_gadukino_communal']	= func('transport_functions', 'get_train_timecost', 'gadukino', 'communal')
	transportVars['train_time_gadukino_ind']			= func('transport_functions', 'get_train_timecost', 'gadukino', 'ind')
	transportVars['train_time_gadukino_center']		= func('transport_functions', 'get_train_timecost', 'gadukino', 'center')

	transportVars['train_time_communal_pavlovsk']	= transportVars['train_time_pavlovsk_communal']
	transportVars['train_time_communal_gadukino']	= transportVars['train_time_gadukino_communal']
	transportVars['train_time_communal_ind']		= func('transport_functions', 'get_train_timecost', 'communal', 'ind')
	transportVars['train_time_communal_center']		= func('transport_functions', 'get_train_timecost', 'communal', 'center')

	transportVars['train_time_ind_pavlovsk']		= transportVars['train_time_pavlovsk_ind']
	transportVars['train_time_ind_gadukino']			= transportVars['train_time_gadukino_ind']
	transportVars['train_time_ind_communal']		= transportVars['train_time_communal_ind']
	transportVars['train_time_ind_center']			= func('transport_functions', 'get_train_timecost', 'ind', 'center')

	transportVars['train_time_center_pavlovsk']		= transportVars['train_time_pavlovsk_center']
	transportVars['train_time_center_gadukino']		= transportVars['train_time_gadukino_center']
	transportVars['train_time_center_communal']		= transportVars['train_time_communal_center']
	transportVars['train_time_center_ind']			= transportVars['train_time_ind_center']
end



if $ARGS[0] = 'get_train_price':
	result = func('transport_functions', '_private_train_price', $ARGS[2]) - func('transport_functions', '_private_train_price', $ARGS[1])
	if result < 0: result *= -1
	result += 25
end

if $ARGS[0] = '_private_train_price':
	if $ARGS[1] = 'pavlovsk':
		result = 0
	elseif $ARGS[1] = 'gadukino':
		result = 50
	elseif $ARGS[1] = 'communal':
		result = 75
	elseif $ARGS[1] = 'ind':
		result = 100
	elseif $ARGS[1] = 'center':
		result = 125
	end
end


if $ARGS[0] = 'get_train_timecost':
	result = func('transport_functions', '_private_train_time', $ARGS[2]) - func('transport_functions', '_private_train_time', $ARGS[1])
	if result < 0: result *= -1
end

if $ARGS[0] = '_private_train_time':
	if $ARGS[1] = 'pavlovsk':
		result = 0
	elseif $ARGS[1] = 'gadukino':
		result = 15
	elseif $ARGS[1] = 'communal':
		result = 25
	elseif $ARGS[1] = 'ind':
		result = 35
	elseif $ARGS[1] = 'center':
		result = 40
	end
end



	!!=======================================!!
	!!                                       !!
	!!                Busses                 !!
	!!                                       !!
	!!=======================================!!

if $ARGS[0] = 'buy_bus_pass':
	if transportVars['buspass_day'] <= daystart:
		if money >= 100:
			dynamic 'act ''Buy a daily bus pass (1 day - 100 <b>₽</b>)'':
				cla
				money -= 250
				transportVars[''buspass_day''] = daystart + 1
				act ''Return'': gt ''<<$loc>>'', ''<<$loc_arg>>''
			end'
		end

		if money >= 500:
			dynamic 'act ''Buy a weekly bus pass (7 days - 500 <b>₽</b>)'':
				cla
				money -= 1500
				transportVars[''buspass_day''] = daystart + 7
				act ''Return'': gt ''<<$loc>>'', ''<<$loc_arg>>''
			end'
		end

		if money >= 1500:
			dynamic 'act ''Buy a monthly bus pass (30 days - 1500 <b>₽</b>)'':
				cla
				money -= 5500
				transportVars[''buspass_day''] = daystart + 30
				act ''Return'': gt ''<<$loc>>'', ''<<$loc_arg>>''
			end'
		end

		if money >= 13000:
			dynamic 'act ''Buy a yearly bus pass (365 days - 13000 <b>₽</b>)'':
				cla
				money -= 75000
				transportVars[''buspass_day''] = daystart + 365
				act ''Return'': gt ''<<$loc>>'', ''<<$loc_arg>>''
			end'
		end
	end
end


if $ARGS[0] = 'buy_bus_ticket':
	if $ARGS[2] = 'pg':
		if $ARGS[1] ! 'community':		gs 'transport_functions', 'set_bus_ticket', $ARGS[1],	'community',	'the Pavlovsk community center'
		if $ARGS[1] ! 'pavstation':		gs 'transport_functions', 'set_bus_ticket', $ARGS[1],	'pavstation',	'the Pavlovsk train station'
		if $ARGS[1] ! 'pushkin':		gs 'transport_functions', 'set_bus_ticket', $ARGS[1],	'pushkin',		'the old town of Pushkin'
		if $ARGS[1] ! 'construction':	gs 'transport_functions', 'set_bus_ticket', $ARGS[1],	'construction',	'the construction site'
		if $ARGS[1] ! 'gadukino':		gs 'transport_functions', 'set_bus_ticket', $ARGS[1],	'gadukino',		'the village of Gadukino'
	elseif $ARGS[2] = 'gp':
		if $ARGS[1] ! 'gadukino':		gs 'transport_functions', 'set_bus_ticket', $ARGS[1],	'gadukino',		'the village of Gadukino'
		if $ARGS[1] ! 'construction':	gs 'transport_functions', 'set_bus_ticket', $ARGS[1],	'construction',	'the construction site'
		if $ARGS[1] ! 'pushkin':		gs 'transport_functions', 'set_bus_ticket', $ARGS[1],	'pushkin',		'the old town of Pushkin'
		if $ARGS[1] ! 'pavstation':		gs 'transport_functions', 'set_bus_ticket', $ARGS[1],	'pavstation',	'the Pavlovsk train station'
		if $ARGS[1] ! 'community':		gs 'transport_functions', 'set_bus_ticket', $ARGS[1],	'community',	'the Pavlovsk community center'
	elseif $ARGS[2] = 'gs':
		if $ARGS[1] ! 'gadukino':		gs 'transport_functions', 'set_bus_ticket', $ARGS[1],	'gadukino',		'the village of Gadukino'
		if $ARGS[1] ! 'communal':		gs 'transport_functions', 'set_bus_ticket', $ARGS[1],	'communal',		'the communal village'
		if $ARGS[1] ! 'graveyard':		gs 'transport_functions', 'set_bus_ticket', $ARGS[1],	'graveyard',	'the graveyard'
		if $ARGS[1] ! 'suburbs':		gs 'transport_functions', 'set_bus_ticket', $ARGS[1],	'suburbs',		'the expensive suburb of St. Petersburg'
	else
		if $ARGS[1] ! 'suburbs':		gs 'transport_functions', 'set_bus_ticket', $ARGS[1],	'suburbs',		'the expensive suburb of St. Petersburg'
		if $ARGS[1] ! 'graveyard':		gs 'transport_functions', 'set_bus_ticket', $ARGS[1],	'graveyard',	'the graveyard'
		if $ARGS[1] ! 'communal':		gs 'transport_functions', 'set_bus_ticket', $ARGS[1],	'communal',		'the communal village'
		if $ARGS[1] ! 'gadukino':		gs 'transport_functions', 'set_bus_ticket', $ARGS[1],	'gadukino',		'the village of Gadukino'
	end
end

! $ARGS[1] = origin loc_arg
! $ARGS[2] = destination loc_arg
! $ARGS[3] = destination name
if $ARGS[0] = 'set_bus_ticket':
	temp_price = func('transport_functions', 'get_bus_price', $ARGS[1], $ARGS[2])
	$temp_time = func('transport_functions', 'display_bus_timecost', $ARGS[1], $ARGS[2])

	if money < ARGS[1]:
		dynamic 'act ''Buy a ticket to <<$ARGS[3]>> (<font color="red"><<$temp_time>> - <<temp_price>> <b>₽</b></font>)'': ''<br><font color="red">You don''t have enough money for a ticket to <<$ARGS[3]>>'' '
	else
		dynamic 'act ''Buy a ticket to <<$ARGS[3]>> (<<$temp_time>> - <<temp_price>> <b>₽</b>)'':
				money -= <<temp_price>>
				menu_off = 1
				gt ''bus'', ''<<$ARGS[1]>>_<<$ARGS[2]>>''
			end'
	end
	killvar 'temp_price'
end


!	Time Table:
!		Bus departs every 20 minutes
!		community (13)	->	pavstation (15)		->	pushkin (23)	->	construction (38)	->	gadukino
!		gadukino (13)	->	construction (38)	->	pushkin (53)	->	pavstation (01)		->	community
!		gadukino (15)	->	communal (35)		->	graveyard (45)	->	suburbs
!		suburbs (05)	->	graveyard (15)		->	communal (25)	->	gadukino

if $ARGS[0] = 'set_bus_wait_time':
	if $ARGS[1] = 'community':
		if hour <= 4:
			transportVars['bus_wait_gadukino']	= (313 - minut - hour * 60)
		elseif hour >= 5 and hour <= 22 or hour = 22 and minut <= 53:
			transportVars['bus_wait_gadukino']	= (73 - minut) mod 20
		else
			transportVars['bus_wait_gadukino']	= (433 - minut - (hour-22) * 60)
		end
	elseif $ARGS[1] = 'pavstation':
		if hour <= 4:
			transportVars['bus_wait_gadukino']	= (315 - minut - hour * 60)
			transportVars['bus_wait_pavlovsk']	= (361 - minut - hour * 60)
		elseif hour = 5:
			transportVars['bus_wait_gadukino']	= (75 - minut) mod 20
			transportVars['bus_wait_pavlovsk']	= (61 - minut)
		elseif hour >= 6 and hour <= 22 or hour = 22 and minut <= 55:
			transportVars['bus_wait_gadukino']	= (75 - minut) mod 20
			transportVars['bus_wait_pavlovsk']	= (61 - minut) mod 20
		elseif hour = 22 or hour = 23 and minut <= 41:
			transportVars['bus_wait_gadukino']	= (435 - minut - (hour-22) * 60)
			transportVars['bus_wait_pavlovsk']	= (61 - minut) mod 20
		else
			transportVars['bus_wait_gadukino']	= (375 - minut)
			transportVars['bus_wait_pavlovsk']	= (421 - minut)
		end
	elseif $ARGS[1] = 'pushkin':
		if hour <= 4:
			transportVars['bus_wait_gadukino']	= (323 - minut - hour * 60)
			transportVars['bus_wait_pavlovsk']	= (353 - minut - hour * 60)
		elseif hour = 5 and minut <= 53:
			transportVars['bus_wait_gadukino']	= (63 - minut) mod 20
			transportVars['bus_wait_pavlovsk']	= (53 - minut)
		elseif hour >= 5 and hour <= 22 or hour = 22 and minut <= 55:
			transportVars['bus_wait_gadukino']	= (63 - minut) mod 20
			transportVars['bus_wait_pavlovsk']	= (73 - minut) mod 20
		elseif hour = 22 or hour = 23 and minut <= 3:
			transportVars['bus_wait_gadukino']	= (3 - minut)
			transportVars['bus_wait_pavlovsk']	= (73 - minut) mod 20
		elseif hour = 22 or hour = 23 and minut <= 33:
			transportVars['bus_wait_gadukino']	= (435 - minut - (hour-22) * 60)
			transportVars['bus_wait_pavlovsk']	= (73 - minut) mod 20
		else
			transportVars['bus_wait_gadukino']	= (383 - minut)
			transportVars['bus_wait_pavlovsk']	= (413 - minut)
		end
	elseif $ARGS[1] = 'construction':
		if hour <= 4:
			transportVars['bus_wait_gadukino']	= (338 - minut - hour * 60)
			transportVars['bus_wait_pavlovsk']	= (338 - minut - hour * 60)
		elseif hour = 5 and minut <= 38:
			transportVars['bus_wait_gadukino']	= (38 - minut)
			transportVars['bus_wait_pavlovsk']	= (38 - minut)
		elseif hour >= 5 and hour <= 22:
			transportVars['bus_wait_gadukino']	= (78 - minut) mod 20
			transportVars['bus_wait_pavlovsk']	= (78 - minut) mod 20
		elseif hour <= 23 and minut <= 18:
			transportVars['bus_wait_gadukino']	= (18 - minut)
			transportVars['bus_wait_pavlovsk']	= (18 - minut)
		else
			transportVars['bus_wait_gadukino']	= (398 - minut)
			transportVars['bus_wait_pavlovsk']	= (398 - minut)
		end
	elseif $ARGS[1] = 'gadukino':
		if hour <= 4:
			transportVars['bus_wait_suburbs']	= (315 - minut - hour * 60)
			transportVars['bus_wait_pavlovsk']	= (313 - minut - hour * 60)
		elseif hour >= 5 and hour <= 22 or hour = 22 and minut <= 53:
			transportVars['bus_wait_suburbs']	= (75 - minut) mod 20
			transportVars['bus_wait_pavlovsk']	= (73 - minut) mod 20
		elseif hour = 22 and minut <= 55:
			transportVars['bus_wait_suburbs']	= (55 - minut)
			transportVars['bus_wait_pavlovsk']	= (433 - minut - (hour-22) * 60)
		else
			transportVars['bus_wait_suburbs']	= (435 - minut - (hour-22) * 60)
			transportVars['bus_wait_pavlovsk']	= (433 - minut - (hour-22) * 60)

		end
	elseif $ARGS[1] = 'communal':
		if hour <= 4:
			transportVars['bus_wait_suburbs']	= (335 - minut - hour * 60)
			transportVars['bus_wait_gadukino']	= (325 - minut - hour * 60)
		elseif hour = 5 and minut <= 25:
			transportVars['bus_wait_suburbs']	= (35 - minut)
			transportVars['bus_wait_gadukino']	= (25 - minut)
		elseif hour = 5 and minut <= 35:
			transportVars['bus_wait_suburbs']	= (75 - minut) mod 20
			transportVars['bus_wait_gadukino']	= (65 - minut) mod 20
		elseif hour >= 5 and hour <= 22:
			transportVars['bus_wait_suburbs']	= (75 - minut) mod 20
			transportVars['bus_wait_gadukino']	= (65 - minut) mod 20
		elseif hour = 23 and minut <= 05:
			transportVars['bus_wait_suburbs']	= (15 - minut)
			transportVars['bus_wait_gadukino']	= (05 - minut)
		elseif hour = 23 and minut <= 15:
			transportVars['bus_wait_suburbs']	= (15 - minut)
			transportVars['bus_wait_gadukino']	= (385 - minut)
		else
			transportVars['bus_wait_suburbs']	= (395 - minut)
			transportVars['bus_wait_gadukino']	= (385 - minut)
		end
	elseif $ARGS[1] = 'graveyard':
		if hour <= 4:
			transportVars['bus_wait_suburbs']	= (345 - minut - hour * 60)
			transportVars['bus_wait_gadukino']	= (315 - minut - hour * 60)
		elseif hour = 5 and minut <= 15:
			transportVars['bus_wait_suburbs']	= (45 - minut)
			transportVars['bus_wait_gadukino']	= (15 - minut)
		elseif hour = 5 and minut <= 45:
			transportVars['bus_wait_suburbs']	= (45 - minut)
			transportVars['bus_wait_gadukino']	= (75 - minut) mod 20
		elseif hour >= 5 and hour <= 21 or hour = 22 and minut <= 55:
			transportVars['bus_wait_suburbs']	= (65 - minut) mod 20
			transportVars['bus_wait_gadukino']	= (75 - minut) mod 20
		elseif hour = 22 or hour = 23 and minut <= 25:
			transportVars['bus_wait_suburbs']	= (65 - minut) mod 20
			transportVars['bus_wait_gadukino']	= (435 - minut - (hour-22) * 60)
		else
			transportVars['bus_wait_suburbs']	= (405 - minut)
			transportVars['bus_wait_gadukino']	= (375 - minut)
		end
	elseif $ARGS[1] = 'suburbs':
		if hour <= 4:
			transportVars['bus_wait_gadukino']	= (305 - minut - hour * 60)
		elseif hour >= 5 and hour <= 22 or hour = 22 and minut <= 45:
			transportVars['bus_wait_gadukino']	= (65 - minut) mod 20
		else
			transportVars['bus_wait_gadukino']	= (425 - minut - (hour-22) * 60)
		end
		transportVars['bus_wait_gadukino']	= (65 - minut) mod 20
	end
end

if $ARGS[0] = 'display_buspass_time':
	$result = 'You have <<transportVars[''buspass_day''] - daystart>> days left on your train pass.'
end

if $ARGS[0] = 'display_bus_timecost':
	temp_mins = transportVars['bus_time_<<$ARGS[1]>>_<<$ARGS[2]>>']
	if $ARGS[1] = 'community' or ($ARGS[1] = 'pavstation' and $ARGS[2] ! 'community') or ($ARGS[1] = 'pushkin' and ($ARGS[2] = 'construction' or $ARGS[2] = 'gadukino')) or $ARGS[1] = 'construction' and $ARGS[2] = 'gadukino':
		temp_mins += transportVars['bus_wait_gadukino']
	elseif ($ARGS[1] = 'pavstation' and $ARGS[2] = 'community') or ($ARGS[1] = 'pushkin' and ($ARGS[2] = 'community' or $ARGS[2] = 'pavstation')) or ($ARGS[1] = 'construction' and $ARGS[2] ! 'gadukino') or ($ARGS[1] = 'gadukino' and ($ARGS[2] ! 'communal' and $ARGS[2] ! 'graveyard' and $ARGS[2] ! 'suburbs')):
		temp_mins += transportVars['bus_wait_pavlovsk']
	elseif $ARSG[1] = 'suburbs' or ($ARGS[1] = 'graveyard' and $ARGS[2] ! 'suburbs') or $ARGS[1] = 'communal' and $ARGS[2] = 'gadukino':
		temp_mins += transportVars['bus_wait_gadukino']
	else
		temp_mins += transportVars['bus_wait_suburbs']
	end

	temp_hours = temp_mins / 60
	temp_mins = temp_mins mod 60
	$result = '<<temp_hours>>:<<$mid(100 + temp_mins, 2, 2)>>'
	killvar 'temp_mins'
	killvar 'temp_hours'
end

if $ARGS[0] = 'display_bus_schedule':
	$bus_schedule = '<center><h4>Bus schedule</h4></center>'

	if $ARGS[1] = 'pg':
		$bus_schedule += '<center><h2>Pavlovsk - Gadukino</h2></center>'
		$bus_schedule += '<br><center><table style="text-align:center">'
		$bus_schedule += '<tr><th>Pavlovsk</th><th>Pavlovsk</th><th></th><th></th><th>Construction</th><th style="border-right:2px solid black; border-left:2px solid black"> </th><th>Pavlovsk</th><th>Pavlovsk</th><th></th><th>Construction</th><th></th></tr>'
		$bus_schedule += '<tr><th style="border-right:2px solid black">Community Center</th><th style="border-right:2px solid black">Train Station</th><th style="border-right:2px solid black">Pushkin</th><th style="border-right:2px solid black">Site</th><th>Gadukino</th><th style="border-right:2px solid black; border-left:2px solid black"> </th><th style="border-right:2px solid black">Community Center</th><th style="border-right:2px solid black">Train Station</th><th style="border-right:2px solid black">Pushkin</th><th style="border-right:2px solid black">Site</th><th style="border-right:2px solid black">Gadukino</th></tr>'
		$bus_schedule += '<tr><td colspan=11 style="border-bottom:2px solid black"></td></tr>'


		th[0] = 4
		:bus_schedule_loop1
			$th[1] = mid(100 + th[0], 2, 2)
			$th[2] = mid(100 + th[0] + 1, 2, 2)

			th[3] = th[0] + 10
			$th[4] = mid(100 + th[3], 2, 2)
			$th[5] = mid(100 + th[3] + 1, 2, 2)

			$bus_schedule += '<tr>'
			$bus_schedule += '<td><<$th[1]>>:13</td><td><<$th[1]>>:15</td><td><<$th[1]>>:23</td><td><<$th[1]>>:38</td><td><<$th[2]>>:03</td>'
			$bus_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
			if th[3] <= 22:
				$bus_schedule += '<td><<$th[4]>>:13</td><td><<$th[4]>>:15</td><td><<$th[4]>>:23</td><td><<$th[4]>>:38</td><td><<$th[5]>>:03</td>'
			else
				$bus_schedule += '<td colspan=5></td>'
			end
			$bus_schedule += '</tr>'

			$bus_schedule += '<tr>'
			$bus_schedule += '<td><<$th[1]>>:33</td><td><<$th[1]>>:35</td><td><<$th[1]>>:43</td><td><<$th[1]>>:58</td><td><<$th[2]>>:23</td>'
			$bus_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
			if th[3] <= 22:
				$bus_schedule += '<td><<$th[4]>>:33</td><td><<$th[4]>>:35</td><td><<$th[4]>>:43</td><td><<$th[4]>>:58</td><td><<$th[5]>>:23</td>'
			else
				$bus_schedule += '<td colspan=5></td>'
			end
			$bus_schedule += '</tr>'

			$bus_schedule += '<tr>'
			$bus_schedule += '<td><<$th[1]>>:53</td><td><<$th[1]>>:55</td><td><<$th[2]>>:03</td><td><<$th[2]>>:18</td><td><<$th[2]>>:43</td>'
			$bus_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
			if th[3] <= 22:
				$bus_schedule += '<td><<$th[4]>>:53</td><td><<$th[4]>>:55</td><td><<$th[5]>>:03</td><td><<$th[5]>>:18</td><td><<$th[5]>>:43</td>'
			else
				$bus_schedule += '<td colspan=5></td>'
			end
			$bus_schedule += '</tr>'

			$bus_schedule += '<tr><td colspan=11 style="border-bottom:1px solid black"></td></tr>'

			th[0] += 1
		if th[0] < 14: jump 'bus_schedule_loop1'
	elseif $ARGS[1] = 'gp':
		$bus_schedule += '<center><h2>Gadukino - Pavlovsk</h2></center>'
		$bus_schedule += '<br><center><table style="text-align:center">'
		$bus_schedule += '<tr><th></th><th>Construction</th><th></th><th>Pavlovsk</th><th>Pavlovsk</th><th style="border-right:2px solid black; border-left:2px solid black"> </th><th></th><th>Construction</th><th></th><th>Pavlovsk</th><th>Pavlovsk</th></tr>'
		$bus_schedule += '<tr><th style="border-right:2px solid black">Gadukino</th><th style="border-right:2px solid black">Site</th><th style="border-right:2px solid black">Pushkin</th><th style="border-right:2px solid black">Train Station</th><th>Community center</th><th style="border-right:2px solid black; border-left:2px solid black"> </th><th style="border-right:2px solid black">Gadukino</th><th style="border-right:2px solid black">Site</th><th style="border-right:2px solid black">Pushkin</th><th style="border-right:2px solid black">Train Station</th><th style="border-right:2px solid black">Community center</th></tr>'
		$bus_schedule += '<tr><td colspan=11 style="border-bottom:2px solid black"></td></tr>'

		th[0] = 4
		:bus_schedule_loop2
			$th[1] = mid(100 + th[0], 2, 2)
			$th[2] = mid(100 + th[0] + 1, 2, 2)

			th[3] = th[0] + 10
			$th[4] = mid(100 + th[3], 2, 2)
			$th[5] = mid(100 + th[3] + 1, 2, 2)

			$bus_schedule += '<tr>'
			$bus_schedule += '<td><<$th[1]>>:13</td><td><<$th[1]>>:38</td><td><<$th[1]>>:53</td><td><<$th[2]>>:01</td><td><<$th[2]>>:03</td>'
			$bus_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
			if th[3] <= 22:
				$bus_schedule += '<td><<$th[4]>>:13</td><td><<$th[4]>>:38</td><td><<$th[4]>>:53</td><td><<$th[5]>>:01</td><td><<$th[5]>>:03</td>'
			else
				$bus_schedule += '<td colspan=5></td>'
			end
			$bus_schedule += '</tr>'

			$bus_schedule += '<tr>'
			$bus_schedule += '<tr><td><<$th[1]>>:33</td><td><<$th[1]>>:58</td><td><<$th[2]>>:13</td><td><<$th[2]>>:21</td><td><<$th[2]>>:23</td>'
			$bus_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
			if th[3] <= 22:
				$bus_schedule += '<td><<$th[4]>>:33</td><td><<$th[4]>>:58</td><td><<$th[5]>>:13</td><td><<$th[5]>>:21</td><td><<$th[5]>>:23</td>'
			else
				$bus_schedule += '<td colspan=5></td>'
			end
			$bus_schedule += '</tr>'

			$bus_schedule += '<tr>'
			$bus_schedule += '<td><<$th[1]>>:53</td><td><<$th[2]>>:18</td><td><<$th[2]>>:33</td><td><<$th[2]>>:41</td><td><<$th[2]>>:43</td>'
			$bus_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
			if th[3] <= 22:
				$bus_schedule += '<td><<$th[4]>>:53</td><td><<$th[5]>>:18</td><td><<$th[5]>>:33</td><td><<$th[5]>>:41</td><td><<$th[5]>>:43</td>'
			else
				$bus_schedule += '<td colspan=5></td>'
			end
			$bus_schedule += '</tr>'

			$bus_schedule += '<tr><td colspan=11 style="border-bottom:1px solid black"></td></tr>'

			th[0] += 1
		if th[0] < 14: jump 'bus_schedule_loop2'
	elseif $ARGS[1] = 'gs':
		$bus_schedule += '<center><h2>Gadukino - Suburbs</h2></center>'
		$bus_schedule += '<br><center><table style="text-align:center">'
		$bus_schedule += '<tr><th></th><th>Communal</th><th></th><th>St. Petersburg</th><th style="border-right:2px solid black; border-left:2px solid black"> </th><th></th><th>Communal</th><th></th><th>St. Petersburg</th></tr>'
		$bus_schedule += '<tr><th style="border-right:2px solid black">Gadukino</th><th style="border-right:2px solid black">Village</th><th style="border-right:2px solid black">Cemetary</th><th>Suburbs</th><th style="border-right:2px solid black; border-left:2px solid black"> </th><th style="border-right:2px solid black">Gadukino</th><th style="border-right:2px solid black">Village</th><th style="border-right:2px solid black">Cemetary</th><th>Suburbs</th></tr>'
		$bus_schedule += '<tr><td colspan=9 style="border-bottom:2px solid black"></td></tr>'

		th[0] = 4
		:bus_schedule_loop3
			$th[1] = mid(100 + th[0], 2, 2)
			$th[2] = mid(100 + th[0] + 1, 2, 2)

			th[3] = th[0] + 10
			$th[4] = mid(100 + th[3], 2, 2)
			$th[5] = mid(100 + th[3] + 1, 2, 2)

			$bus_schedule += '<tr>'
			$bus_schedule += '<td><<$th[1]>>:15</td><td><<$th[1]>>:35</td><td><<$th[1]>>:45</td><td><<$th[1]>>:55</td>'
			$bus_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
			if th[3] <= 22:
				$bus_schedule += '<td><<$th[4]>>:15</td><td><<$th[4]>>:35</td><td><<$th[4]>>:45</td><td><<$th[4]>>:55</td>'
			else
				$bus_schedule += '<td colspan=4></td>'
			end
			$bus_schedule += '</tr>'

			$bus_schedule += '<tr>'
			$bus_schedule += '<td><<$th[1]>>:35</td><td><<$th[1]>>:55</td><td><<$th[2]>>:05</td><td><<$th[2]>>:15</td>'
			$bus_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
			if th[3] <= 22:
				$bus_schedule += '<td><<$th[4]>>:35</td><td><<$th[4]>>:55</td><td><<$th[5]>>:05</td><td><<$th[5]>>:15</td>'
			else
				$bus_schedule += '<td colspan=4></td>'
			end
			$bus_schedule += '</tr>'

			$bus_schedule += '<tr>'
			$bus_schedule += '<td><<$th[4]>>:55</td><td><<$th[5]>>:15</td><td><<$th[5]>>:25</td><td><<$th[5]>>:35</td>'
			$bus_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
			if th[3] <= 22:
				$bus_schedule += '<td><<$th[4]>>:55</td><td><<$th[5]>>:15</td><td><<$th[5]>>:25</td><td><<$th[5]>>:35</td>'
			else
				$bus_schedule += '<td colspan=4></td>'
			end
			$bus_schedule += '</tr>'

			$bus_schedule += '<tr><td colspan=9 style="border-bottom:1px solid black"></td></tr>'

			th[0] += 1
		if th[0] < 14: jump 'bus_schedule_loop3'
	else
		$bus_schedule += '<center><h2>Suburbs - Gadukino</h2></center>'
		$bus_schedule += '<br><center><table style="text-align:center">'
		$bus_schedule += '<tr><th>St. Petersburg</th><th></th><th>Communal</th><th></th><th style="border-right:2px solid black; border-left:2px solid black"> </th><th>St. Petersburg</th><th></th><th>Communal</th><th></th></tr>'
		$bus_schedule += '<tr><th style="border-right:2px solid black">Suburbs</th><th style="border-right:2px solid black">Cemetary</th><th style="border-right:2px solid black">Village</th><th>Gadukino</th><th style="border-right:2px solid black; border-left:2px solid black"> </th><th style="border-right:2px solid black">Suburbs</th><th style="border-right:2px solid black">Cemetary</th><th style="border-right:2px solid black">Village</th><th>Gadukino</th></tr>'
		$bus_schedule += '<tr><td colspan=9 style="border-bottom:2px solid black"></td></tr>'


		th[0] = 4
		:bus_schedule_loop4
			$th[1] = mid(100 + th, 2, 2)
			$th[2] = mid(100 + th + 1, 2, 2)

			th[3] = th[0] + 10
			$th[4] = mid(100 + th[3], 2, 2)
			$th[5] = mid(100 + th[3] + 1, 2, 2)

			$bus_schedule += '<tr>'
			$bus_schedule += '<td><<$th[1]>>:05</td><td><<$th[1]>>:15</td><td><<$th[1]>>:25</td><td><<$th[1]>>:45</td>'
			$bus_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
			if th[3] <= 22:
				$bus_schedule += '<td><<$th[4]>>:05</td><td><<$th[4]>>:15</td><td><<$th[4]>>:25</td><td><<$th[4]>>:45</td>'
			else
				$bus_schedule += '<td colspan=4></td>'
			end
			$bus_schedule += '</tr>'

			$bus_schedule += '<tr>'
			$bus_schedule += '<td><<$th[1]>>:25</td><td><<$th[1]>>:35</td><td><<$th[1]>>:45</td><td><<$th[2]>>:05</td>'
			$bus_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
			if th[3] <= 22:
				$bus_schedule += '<td><<$th[4]>>:25</td><td><<$th[4]>>:35</td><td><<$th[4]>>:45</td><td><<$th[5]>>:05</td>'
			else
				$bus_schedule += '<td colspan=4></td>'
			end
			$bus_schedule += '</tr>'

			$bus_schedule += '<tr>'
			$bus_schedule += '<td><<$th[1]>>:45</td><td><<$th[1]>>:55</td><td><<$th[2]>>:05</td><td><<$th[2]>>:25</td>'
			$bus_schedule += '<td style="border-right:2px solid black; border-left:2px solid black"> </td>'
			if th[3] <= 22:
				$bus_schedule += '<td><<$th[4]>>:45</td><td><<$th[4]>>:55</td><td><<$th[5]>>:05</td><td><<$th[5]>>:25</td>'
			else
				$bus_schedule += '<td colspan=4></td>'
			end
			$bus_schedule += '</tr>'

			$bus_schedule += '<tr><td colspan=9 style="border-bottom:1px solid black"></td></tr>'

			th[0] += 1
		if th[0] < 14: jump 'bus_schedule_loop4'
	end
	$bus_schedule += '</table></center>'

	'<<$bus_schedule>>'

	killvar 'bus_schedule'
	killvar 'th'
end


if $ARGS[0] = 'init_bus_prices':
	transportVars['bus_price_community_pavstation']		= func('transport_functions', 'get_bus_price', 'community', 'pavstation')
	transportVars['bus_price_community_pushkin']		= func('transport_functions', 'get_bus_price', 'community', 'pushkin')
	transportVars['bus_price_community_construction']	= func('transport_functions', 'get_bus_price', 'community', 'construction')
	transportVars['bus_price_community_gadukino']		= func('transport_functions', 'get_bus_price', 'community', 'gadukino')

	transportVars['bus_price_pavstation_community']		= transportVars['bus_price_community_pavstation']
	transportVars['bus_price_pavstation_pushkin']		= func('transport_functions', 'get_bus_price', 'pavstation', 'pushkin')
	transportVars['bus_price_pavstation_construction']	= func('transport_functions', 'get_bus_price', 'pavstation', 'construction')
	transportVars['bus_price_pavstation_gadukino']		= func('transport_functions', 'get_bus_price', 'pavstation', 'gadukino')

	transportVars['bus_price_pushkin_community']		= transportVars['bus_price_community_pushkin']
	transportVars['bus_price_pushkin_pavstation']		= transportVars['bus_price_pavstation_pushkin']
	transportVars['bus_price_pushkin_construction']		= func('transport_functions', 'get_bus_price', 'pushkin', 'construction')
	transportVars['bus_price_pushkin_gadukino']			= func('transport_functions', 'get_bus_price', 'pushkin', 'gadukino')

	transportVars['bus_price_construction_community']	= transportVars['bus_price_community_construction']
	transportVars['bus_price_construction_pavstation']	= transportVars['bus_price_pavstation_construction']
	transportVars['bus_price_construction_pushkin']		= transportVars['bus_price_pushkin_construction']
	transportVars['bus_price_construction_gadukino']	= func('transport_functions', 'get_bus_price', 'construction', 'gadukino')

	transportVars['bus_price_gadukino_community']		= transportVars['bus_price_community_gadukino']
	transportVars['bus_price_gadukino_pavstation']		= transportVars['bus_price_pavstation_gadukino']
	transportVars['bus_price_gadukino_pushkin']			= transportVars['bus_price_pushkin_gadukino']
	transportVars['bus_price_gadukino_construction']	= transportVars['bus_price_gadukino_construction']
	transportVars['bus_price_gadukino_communal']		= func('transport_functions', 'get_bus_price', 'gadukino', 'communal')
	transportVars['bus_price_gadukino_graveyard']		= func('transport_functions', 'get_bus_price', 'gadukino', 'graveyard')
	transportVars['bus_price_gadukino_suburbs']			= func('transport_functions', 'get_bus_price', 'gadukino', 'suburbs')

	transportVars['bus_price_communal_gadukino']		= transportVars['bus_price_gadukino_communal']
	transportVars['bus_price_communal_graveyard']		= func('transport_functions', 'get_bus_price', 'communal', 'graveyard')
	transportVars['bus_price_communal_suburbs']			= func('transport_functions', 'get_bus_price', 'communal', 'suburbs')

	transportVars['bus_price_graveyard_gadukino']		= transportVars['bus_price_gadukino_communal']
	transportVars['bus_price_graveyard_communal']		= transportVars['bus_price_communal_graveyard']
	transportVars['bus_price_graveyard_suburbs']		= func('transport_functions', 'get_bus_price', 'communal', 'suburbs')

	transportVars['bus_price_suburbs_gadukino']			= transportVars['bus_price_gadukino_communal']
	transportVars['bus_price_suburbs_communal']			= transportVars['bus_price_communal_graveyard']
	transportVars['bus_price_suburbs_graveyard']		= transportVars['bus_price_graveyard_suburbs']
end

if $ARGS[0] = 'init_bus_timecosts':
	transportVars['bus_time_community_pavstation']		= func('transport_functions', 'get_bus_timecost', 'community', 'pavstation')
	transportVars['bus_time_community_pushkin']			= func('transport_functions', 'get_bus_timecost', 'community', 'pushkin')
	transportVars['bus_time_community_construction']	= func('transport_functions', 'get_bus_timecost', 'community', 'construction')
	transportVars['bus_time_community_gadukino']		= func('transport_functions', 'get_bus_timecost', 'community', 'gadukino')

	transportVars['bus_time_pavstation_community']		= transportVars['bus_time_community_pavstation']
	transportVars['bus_time_pavstation_pushkin']		= func('transport_functions', 'get_bus_timecost', 'pavstation', 'pushkin')
	transportVars['bus_time_pavstation_construction']	= func('transport_functions', 'get_bus_timecost', 'pavstation', 'construction')
	transportVars['bus_time_pavstation_gadukino']		= func('transport_functions', 'get_bus_timecost', 'pavstation', 'gadukino')

	transportVars['bus_time_pushkin_community']			= transportVars['bus_time_community_pushkin']
	transportVars['bus_time_pushkin_pavstation']		= transportVars['bus_time_pavstation_pushkin']
	transportVars['bus_time_pushkin_construction']		= func('transport_functions', 'get_bus_timecost', 'pushkin', 'construction')
	transportVars['bus_time_pushkin_gadukino']			= func('transport_functions', 'get_bus_timecost', 'pushkin', 'gadukino')

	transportVars['bus_time_construction_community']	= transportVars['bus_time_community_construction']
	transportVars['bus_time_construction_pavstation']	= transportVars['bus_time_pavstation_construction']
	transportVars['bus_time_construction_pushkin']		= transportVars['bus_time_pushkin_construction']
	transportVars['bus_time_construction_gadukino']		= func('transport_functions', 'get_bus_timecost', 'construction', 'gadukino')

	transportVars['bus_time_gadukino_community']		= transportVars['bus_time_community_gadukino']
	transportVars['bus_time_gadukino_pavstation']		= transportVars['bus_time_pavstation_gadukino']
	transportVars['bus_time_gadukino_pushkin']			= transportVars['bus_time_pushkin_gadukino']
	transportVars['bus_time_gadukino_construction']		= transportVars['bus_time_gadukino_construction']
	transportVars['bus_time_gadukino_communal']			= func('transport_functions', 'get_bus_timecost', 'gadukino', 'communal')
	transportVars['bus_time_gadukino_graveyard']		= func('transport_functions', 'get_bus_timecost', 'gadukino', 'graveyard')
	transportVars['bus_time_gadukino_suburbs']			= func('transport_functions', 'get_bus_timecost', 'gadukino', 'suburbs')

	transportVars['bus_time_communal_gadukino']			= transportVars['bus_time_gadukino_communal']
	transportVars['bus_time_communal_graveyard']		= func('transport_functions', 'get_bus_timecost', 'communal', 'graveyard')
	transportVars['bus_time_communal_suburbs']			= func('transport_functions', 'get_bus_timecost', 'communal', 'suburbs')

	transportVars['bus_time_graveyard_gadukino']		= transportVars['bus_time_gadukino_communal']
	transportVars['bus_time_graveyard_communal']		= transportVars['bus_time_communal_graveyard']
	transportVars['bus_time_graveyard_suburbs']			= func('transport_functions', 'get_bus_timecost', 'communal', 'suburbs')

	transportVars['bus_time_suburbs_gadukino']			= transportVars['bus_time_gadukino_communal']
	transportVars['bus_time_suburbs_communal']			= transportVars['bus_time_communal_graveyard']
	transportVars['bus_time_suburbs_graveyard']			= transportVars['bus_time_graveyard_suburbs']
end


if $ARGS[0] = 'get_bus_price':
	result = func('transport_functions', '_private_bus_price', $ARGS[2]) - func('transport_functions', '_private_bus_price', $ARGS[1])
	if result < 0: result *= -1
	result += 10
end

if $ARGS[0] = '_private_bus_price':
	if $ARGS[1] = 'community':
		result = 0
	elseif $ARGS[1] = 'pavstation':
		result = 5
	elseif $ARGS[1] = 'pushkin':
		result = 15
	elseif $ARGS[1] = 'construction':
		result = 25
	elseif $ARGS[1] = 'gadukino':
		result = 35
	elseif $ARGS[1] = 'communal':
		result = 45
	elseif $ARGS[1] = 'graveyard':
		result = 55
	elseif $ARGS[1] = 'suburbs':
		result = 65
	end
end

if $ARGS[0] = 'get_bus_timecost':
	result = func('transport_functions', '_private_bus_time', $ARGS[2]) - func('transport_functions', '_private_bus_time', $ARGS[1])
	if result < 0: result *= -1
end

if $ARGS[0] = '_private_bus_time':
	if $ARGS[1] = 'community':
		result = 0
	elseif $ARGS[1] = 'pavstation':
		result = 2
	elseif $ARGS[1] = 'pushkin':
		result = 10
	elseif $ARGS[1] =  'construction':
		result = 25
	elseif $ARGS[1] = 'gadukino':
		result = 50
	elseif $ARGS[1] = 'communal':
		result = 70
	elseif $ARGS[1] = 'graveyard':
		result = 80
	elseif $ARGS[1] = 'suburbs':
		result = 90
	end
end




	!!=======================================!!
	!!                                       !!
	!!                 Metro                 !!
	!!                                       !!
	!!=======================================!!


if $ARGS[0] = 'get_metro_price':
	result = 16
end

if $ARGS[0] = 'get_metro_timecost':
	result = 10
end

--- transport_functions ---------------------------------