Forráskód Böngészése

[changed] time and daystage management done in time instead of daystage

anjuna krokus 2 hete
szülő
commit
0cbea1a8a8
3 módosított fájl, 226 hozzáadás és 177 törlés
  1. 24 89
      locations/outdoors.qsrc
  2. 17 17
      locations/stat.qsrc
  3. 185 71
      locations/time.qsrc

+ 24 - 89
locations/outdoors.qsrc

@@ -30,18 +30,18 @@ weatherFallM[12]= 40
 
 weatherFallDelta = 10
 
-DayLengthMin = 177 &! Minutes from dawn to noon
-DayLengthMax = 563
+!DayLengthMin = 177 &! Minutes from dawn to noon
+!DayLengthMax = 563
 
 if $ARGS[0] = 'weather':
-	if weatherDay ! DayInYear:
+	if weatherDay ! daystart:
 		weatherTemper = rand(weatherGrM[month]-weatherGrDelta, weatherGrM[month]+weatherGrDelta)
 		weatherFall = rand(weatherFallM[month]-weatherFallDelta, weatherFallM[month]+weatherFallDelta)
 	end
 	if (weatherHour ! hour) or (weatherDay ! daystart):
-		weatherDay = DayInYear
+		weatherDay = daystart
 		weatherHour = hour
-		
+
 		temper = hour
 		if temper <= 2:
 			temper = temper + (6 - (temper * 2))
@@ -50,9 +50,9 @@ if $ARGS[0] = 'weather':
 		elseif temper >= 16:
 			temper = (temper - 30) * -1
 		end
-		
+
 		temper = weatherTemper + (weatherGrDelta*100/6*temper)/100
-		
+
 		if chWeather = 0:
 			sunWeather = IIF( rand(0,100)<weatherFall, 0, 1)
 		else
@@ -123,32 +123,32 @@ if $ARGS[0] = 'weather':
 
 		gs 'outdoors', 'temp_set'
 
-        if month = 1:
+		if month = 1:
 			$weather = '<<$osadki>> The temperature is <<$temperature>>.<br>There is snow on the street.'
-        elseif month = 2:
+		elseif month = 2:
 			$weather = '<<$osadki>> The temperature is <<$temperature>>.<br>There is snow on the street.'
-        elseif month = 3:
+		elseif month = 3:
 			$weather = '<<$osadki>> The temperature is <<$temperature>>.<br>There is snow on the street.'
-        elseif month = 4:
+		elseif month = 4:
 			$weather = '<<$osadki>> The temperature is <<$temperature>>.<br>The snow melts on the street.'
-        elseif month = 5:
+		elseif month = 5:
 			$weather = '<<$osadki>> The temperature is <<$temperature>>.<br>Puddles in the street left by snow, winter has covered everything in dirt and debris, some places where new grass grows are pleasantly green.'
-        elseif month = 6:
+		elseif month = 6:
 			$weather = '<<$osadki>> The temperature is <<$temperature>>.<br>Green grass lines the streets.'
-        elseif month = 7:
+		elseif month = 7:
 			$weather = '<<$osadki>> The temperature is <<$temperature>>.<br>Green grass lines the streets.'
-        elseif month = 8:
+		elseif month = 8:
 			$weather = '<<$osadki>> The temperature is <<$temperature>>.<br>The grass is green, the leaves in the trees are already turning yellow.'
-        elseif month = 9:
+		elseif month = 9:
 			$weather = '<<$osadki>> The temperature is <<$temperature>>.<br>Streets lined with green grass, visible yellow leaves.'
-        elseif month = 10:
+		elseif month = 10:
 			$weather = '<<$osadki>> Temperature is <<$temperature>>.<br>The grass is fading and patchy, yellow and brown leaves fall from the trees, mud and puddles dot the street.'
-        elseif month = 11:
+		elseif month = 11:
 			$weather = '<<$osadki>> Temperature is <<$temperature>>.<br>The street is dirty with a thin snow cover.'
-        elseif month = 12:
+		elseif month = 12:
 			$weather = '<<$osadki>> The temperature is <<$temperature>>.<br>The street is covered in snow.'
 		end
-	end	
+	end
 end
 
 if $ARGS[0] = 'temp_set':
@@ -165,76 +165,11 @@ if $ARGS[0] = 'temp_set':
 end
 
 if $ARGS[0] = 'main':
-	DayInYear = func('shortgs', 'doy', year, month, day)
-
-	!! distance from summer solstice (longest day of the year)
-	if DayInYear < 172:
-		DayInYear2 = 172 - DayInYear
-	elseif DayinYear < 355:
-		DayInYear2 = DayInYear - 172
-	else
-		DayInYear2 = 536 - DayInYear
-	end
-
-	DayLength = DayLengthMax - ((DayLengthMax - DayLengthMin) * 100 / 182) * DayInYear2 / 100
-	!  half of daylight duration
-	!  used as an offset for solar noon
-	!  to get time when day starts and ends
-
-	!  solar noon coincides with CurTimeSun of 0 which happens at 13:00
-	!! Solar Noon (13:00) minus DayLength - time when day starts
-	!! Solar Noon (13:00) plus DayLength - time when day ends
-
-	CurTimeSun = hour * 60 + minut
-	!! distance from 13:00 (Solar Noon) in minutes
-	!    at midnight its -780
-	!    0 is 13:00
-	!    1 minute before midnight (23:59) is 659
-	if CurTimeSun >= 780:
-		CurTimeSun = CurTimeSun - 780
-	else
-		CurTimeSun = -(780 - CurTimeSun)
-	end
-
-	DayStage = 5
-	BColorBase = 0
-	! 1 - dawn
-	! 2 - midday
-	! 3 - sunset
-	! 4 - the beginning of the night
-	! 5 - night
-	! 6 - the end of the night
-	!! phases 1, 3, 4 and 6 last for 60 minutes
-	if CurTimeSun >= -(DayLength - 60) and CurTimeSun <= (DayLength - 60):
-		DayStage = 2
-		BColorBase = 255
-	elseif CurTimeSun >= -DayLength and CurTimeSun <= -(DayLength - 60):
-		! CurTimeSun - negative
-		DayStage = 1
-		! result = 128 + [0-60] * 2
-		BColorBase = 128 + (DayLength + CurTimeSun) * 2
-	elseif CurTimeSun >= (DayLength - 60) and CurTimeSun <= DayLength:
-		! CurTimeSun - positive
-		DayStage = 3
-		! result = 128 + [0-60] * 2
-		BColorBase = 256 + ((DayLength - 60) - CurTimeSun) * 2
-	elseif CurTimeSun >= DayLength and CurTimeSun <= DayLength + 60:
-		! CurTimeSun - positive
-		DayStage = 4
-		! result = 128 - [0-60] * 2
-		BColorBase = 128 - (CurTimeSun - DayLength) * 2
-	elseif CurTimeSun >= -(DayLength + 60) and CurTimeSun <= -DayLength:
-		! CurTimeSun - negative
-		DayStage = 6
-		! result = 128 - [0-60] * 2
-		BColorBase = 128 + (CurTimeSun + DayLength) * 2
-	end
-
-!	*pl '    DayInYear=<<DayInYear>> DayLength=<<DayLength>>  CurTimeSun=<<CurTimeSun>>  DayStage=<<DayStage>>'
+	!BColorBase is updated in Time.
 
 	$weatherImage = '<img height = <<set_weatherht>> src="images/system/weather/wthr'
 	$weatherImage = $weatherImage + '<<DayStage>>'
-	if temper < -10 : 
+	if temper < -10 :
 		$weatherImage += '1'
 	elseif temper <= 5 :
 		$weatherImage += '2'
@@ -374,7 +309,7 @@ if $ARGS[0] = 'main':
 		gs 'themes', 'indoors'
 	end
 end
-	
-	
+
+
 --- outdoors ---------------------------------
 

+ 17 - 17
locations/stat.qsrc

@@ -3,9 +3,6 @@
 !!This is error catching to prevent stat from running too early
 if opPRE > 0: exit
 
-if Enable_Android = 0: gs 'obj_din', 'old'
-
-
 if daystart_start < 100:
 	pl '<BR>Did you start at the <a href="exec:daystart_start = 239 & gs ''time'' & gs''stat''">end of August</a> or <a href="exec:daystart_start = 153 & gs ''time'' & gs''stat''">beginning of June</a>?'
 	exit
@@ -17,20 +14,6 @@ view
 rand1 = rand(0,100)
 $stat_msg[1] = ''
 
-if daystage = 1:
-	$daystage['desc'] = 'dawn'
-elseif daystage = 2:
-	$daystage['desc'] = 'mid_day'
-elseif daystage = 3:
-	$daystage['desc'] = 'sunset'
-elseif daystage = 4:
-	$daystage['desc'] = 'early_night'
-elseif daystage = 5:
-	$daystage['desc'] = 'mid_night'
-elseif daystage = 6:
-	$daystage['desc'] = 'pre_dawn'
-end
-
 if $start_type[1] ! 'nomagic': magik_exp = orgasm + magik_adj
 
 if insleep = 0: gs 'stat_sklattrib'
@@ -234,6 +217,21 @@ end
 
 gs 'time'
 
+if daystage = 1:
+	$daystage['desc'] = 'dawn'
+elseif daystage = 2:
+	$daystage['desc'] = 'mid_day'
+elseif daystage = 3:
+	$daystage['desc'] = 'sunset'
+elseif daystage = 4:
+	$daystage['desc'] = 'early_night'
+elseif daystage = 5:
+	$daystage['desc'] = 'mid_night'
+elseif daystage = 6:
+	$daystage['desc'] = 'pre_dawn'
+end
+
+
 ! Execute time based
 if prevtotmin ! totminut:
 	gs 'spellTimer', prevtotmin, totminut
@@ -945,5 +943,7 @@ if prevtotmin ! totminut:
 	gs 'telefon', 'IncomingSMSCheck'
 end
 
+if Enable_Android = 0: gs 'obj_din', 'old'
+
 
 --- stat ---------------------------------

+ 185 - 71
locations/time.qsrc

@@ -8,24 +8,28 @@ if $ARGS[0] = '':
 	! sync totminut with daystart, hour, and minut
 	totminut = minut + hour * 60 + (daystart - 1) * 1440
 
-	:time_time_loop
-		time_temp_jump_flag = 0
-		if minut >= 60:
-			!! Hourly Changes
-			hour += 1
-			minut -= 60
-			gs 'hourly_events'
-			time_temp_jump_flag = 1
-		end
-		if hour >= 24:
-			hour -= 24
-			daystart += 1
-			gs 'time', 'update_date'
-			gs 'cikl'
-			time_temp_jump_flag = 1
-		end
-	if time_temp_jump_flag = 1: jump 'time_time_loop'
-	killvar 'time_temp_jump_flag'
+	if totminut ! prevtotmin:
+		:time_time_loop
+			time_temp_jump_flag = 0
+			if minut >= 60:
+				!! Hourly Changes
+				hour += 1
+				minut -= 60
+				gs 'hourly_events'
+				time_temp_jump_flag = 1
+			end
+			if hour >= 24:
+				hour -= 24
+				daystart += 1
+				gs 'time', 'update_date'
+				gs 'cikl'
+				time_temp_jump_flag = 1
+			end
+		if time_temp_jump_flag = 1: jump 'time_time_loop'
+		killvar 'time_temp_jump_flag'
+
+		gs 'time', 'update_daystage', year, month, day, hour, minut
+	end
 end
 
 
@@ -44,82 +48,84 @@ end
 
 ! ARGS[1] = daystart
 if $ARGS[0] = 'to_date':
+	if arrsize('ARGS') = 1: ARGS[1] = daystart
+
 	!daystart = 1 -> 1 Jan 2016
 	!mod_daystart = 0 -> 1 Jan 2013
 
-	mod_daystart = ARGS[1] + 1094
+	temp_timeVars['mod_daystart'] = ARGS[1] + 1094
 
-	dateVars['week'] = (mod_daystart + 2) mod 7
+	dateVars['week'] = (temp_timeVars['mod_daystart'] + 2) mod 7
 	if dateVars['week'] = 0: dateVars['week'] = 7
 
 	dateVars['year'] = 2013
-	temp_4cycles = mod_daystart / 1461		& ! (cycle of 4 years)
-	dateVars['year'] += 4 * temp_4cycles
+	temp_timeVars['4cycles'] = temp_timeVars['mod_daystart'] / 1461		& ! (cycle of 4 years)
+	dateVars['year'] += 4 * temp_timeVars['4cycles']
 
 	! The remaining years in this cycle of 4 years
-	if mod_daystart mod 1461 >= 1095:
-		temp_inner_years = 3
-	elseif mod_daystart mod 1461 >= 730:
-		temp_inner_years = 2
-	elseif mod_daystart mod 1461 >= 365:
-		temp_inner_years = 1
+	if temp_timeVars['mod_daystart'] mod 1461 >= 1095:
+		temp_timeVars['inner_years'] = 3
+	elseif temp_timeVars['mod_daystart'] mod 1461 >= 730:
+		temp_timeVars['inner_years'] = 2
+	elseif temp_timeVars['mod_daystart'] mod 1461 >= 365:
+		temp_timeVars['inner_years'] = 1
 	else
-		temp_inner_years = 0
+		temp_timeVars['inner_years'] = 0
 	end
-	dateVars['year'] += temp_inner_years	& ! The remaining years in this cycle of 4 years
+	dateVars['year'] += temp_timeVars['inner_years']	& ! The remaining years in this cycle of 4 years
 
 
-	temp_inner_days = mod_daystart - 1461 * temp_4cycles - 365 * temp_inner_years
+	temp_timeVars['inner_days'] = temp_timeVars['mod_daystart'] - 1461 * temp_timeVars['4cycles'] - 365 * temp_timeVars['inner_years']
 
-	temp_leapyear = 0
+	temp_timeVars['leapyear'] = 0
 	if ((dateVars['year'] mod 4) = 0 and (dateVars['year'] mod 100) ! 0) or (dateVars['year'] mod 400 = 0):
-		if temp_inner_days > 59:
-			temp_inner_days -= 1
-			temp_leapyear = 1
+		if temp_timeVars['inner_days'] > 59:
+			temp_timeVars['inner_days'] -= 1
+			temp_timeVars['leapyear'] = 1
 		end
 	end
 
 	!temp_inner_days starts at 0!
-	if temp_inner_days < 31:
+	if temp_timeVars['inner_days'] < 31:
 		dateVars['month'] = 1
-	elseif temp_inner_days < 59:
+	elseif temp_timeVars['inner_days'] < 59:
 		dateVars['month'] = 2
-		temp_inner_days -= 31
-		temp_inner_days += temp_leapyear
-	elseif temp_inner_days < 90:
+		temp_timeVars['inner_days'] -= 31
+		temp_timeVars['inner_days'] += temp_timeVars['leapyear']
+	elseif temp_timeVars['inner_days'] < 90:
 		dateVars['month'] = 3
-		temp_inner_days -= 59
-	elseif temp_inner_days < 120:
+		temp_timeVars['inner_days'] -= 59
+	elseif temp_timeVars['inner_days'] < 120:
 		dateVars['month'] = 4
-		temp_inner_days -= 90
-	elseif temp_inner_days < 151:
+		temp_timeVars['inner_days'] -= 90
+	elseif temp_timeVars['inner_days'] < 151:
 		dateVars['month'] = 5
-		temp_inner_days -= 120
-	elseif temp_inner_days < 181:
+		temp_timeVars['inner_days'] -= 120
+	elseif temp_timeVars['inner_days'] < 181:
 		dateVars['month'] = 6
-		temp_inner_days -= 151
-	elseif temp_inner_days < 212:
+		temp_timeVars['inner_days'] -= 151
+	elseif temp_timeVars['inner_days'] < 212:
 		dateVars['month'] = 7
-		temp_inner_days -= 181
-	elseif temp_inner_days < 243:
+		temp_timeVars['inner_days'] -= 181
+	elseif temp_timeVars['inner_days'] < 243:
 		dateVars['month'] = 8
-		temp_inner_days -= 212
-	elseif temp_inner_days < 273:
+		temp_timeVars['inner_days'] -= 212
+	elseif temp_timeVars['inner_days'] < 273:
 		dateVars['month'] = 9
-		temp_inner_days -= 243
-	elseif temp_inner_days < 304:
+		temp_timeVars['inner_days'] -= 243
+	elseif temp_timeVars['inner_days'] < 304:
 		dateVars['month'] = 10
-		temp_inner_days -= 273
-	elseif temp_inner_days < 334:
+		temp_timeVars['inner_days'] -= 273
+	elseif temp_timeVars['inner_days'] < 334:
 		dateVars['month'] = 11
-		temp_inner_days -= 304
+		temp_timeVars['inner_days'] -= 304
 	else
 		dateVars['month'] = 12
-		temp_inner_days -= 334
+		temp_timeVars['inner_days'] -= 334
 	end
 	$dateVars['month_text'] = $monthName[dateVars['month']]
 
-	dateVars['day'] = 1 + temp_inner_days
+	dateVars['day'] = 1 + temp_timeVars['inner_days']
 
 	dateVars['odd_week'] = ((mod_daystart + 8) / 7) mod 2
 
@@ -143,18 +149,15 @@ if $ARGS[0] = 'to_date':
 		'new_week: <<dateVars[''week'']>> | old_week: <<week>>'
 		'new_odd_week: <<dateVars[''odd_week'']>> | old_odd_week: <<odd_week>>'
 		*nl
-		'mod_daystart: <<mod_daystart>>'
-		'temp_inner_days: <<temp_inner_days>>'
-		'temp_leapyear: <<temp_leapyear>>'
-		'temp_4cycles: <<temp_4cycles>>'
-		'temp_inner_years: <<temp_inner_years>>'
+		'Temp:'
+		'mod_daystart: <<temp_timeVars[''mod_daystart'']>>'
+		'inner_days: <<temp_timeVars[''inner_days'']>>'
+		'leapyear: <<temp_timeVars[''leapyear'']>>'
+		'4cycles: <<temp_timeVars[''4cycles'']>>'
+		'inner_years: <<temp_timeVars[''inner_years'']>>'
 	end
 
-	killvar 'temp_inner_days'
-	killvar 'temp_leapyear'
-	killvar 'temp_4cycles'
-	killvar 'temp_inner_years'
-	killvar 'mod_daystart'
+	killvar 'temp_timeVars'
 end
 
 
@@ -196,6 +199,115 @@ if $ARGS[0] = 'to_daystart':
 end
 
 
+if $ARGS[0] = 'update_daystage':
+	if arrsize('ARGS') = 1: ARGS[1] = year
+	if arrsize('ARGS') = 2: ARGS[2] = month
+	if arrsize('ARGS') = 3: ARGS[3] = day
+	if arrsize('ARGS') = 4: ARGS[4] = hour
+	if arrsize('ARGS') = 5: ARGS[5] = minut
+
+
+	DayLength = func('time', 'get_DayLength', ARGS[1], ARGS[2], ARGS[3])
+
+	CurTimeSun = func('time', 'get_CurTimeSun', ARGS[4], ARGS[5])
+
+	! 1 - dawn
+	! 2 - midday
+	! 3 - sunset
+	! 4 - the beginning of the night
+	! 5 - night
+	! 6 - the end of the night
+	!! phases 1, 3, 4 and 6 last for 64 minutes
+	if CurTimeSun < -DayLength - 64:
+		DayStage = 5
+
+		BColorBase = 0		& ! Black
+	elseif CurTimeSun < -DayLength:
+		DayStage = 6
+
+		! CurTimeSun - negative
+		! result = 128 - [64 -> 0] * 2
+		BColorBase = 128 + (DayLength + CurTimeSun) * 2
+	elseif CurTimeSun < -DayLength + 64:
+		DayStage = 1
+
+		! CurTimeSun - negative
+		! result = 128 + [0 -> 64] * 2
+		BColorBase = 128 + (DayLength + CurTimeSun) * 2
+	elseif CurTimeSun < DayLength - 64:
+		DayStage = 2
+
+		BColorBase = 255	& ! White
+	elseif CurTimeSun < DayLength:
+		DayStage = 3
+
+		! CurTimeSun - positive
+		! result = 128 + [64 -> 0] * 2
+		BColorBase = 128 + (DayLength - CurTimeSun) * 2
+	elseif CurTimeSun < DayLength + 64:
+		DayStage = 4
+
+		! CurTimeSun - positive
+		! result = 128 - [0 -> 64] * 2
+		BColorBase = 128 + (DayLength - CurTimeSun) * 2
+	else
+		DayStage = 5
+
+		BColorBase = 0		& ! Black
+	end
+end
+
+
+if $ARGS[0] = 'get_DayLength':
+	if arrsize('ARGS') = 1: ARGS[1] = year
+	if arrsize('ARGS') = 2: ARGS[2] = month
+	if arrsize('ARGS') = 3: ARGS[3] = day
+
+	!  half of daylight duration
+	!  used as an offset for solar noon
+	!  to get time when day starts and ends
+
+
+	temp_timeVars['doy_N1'] = 275 * ARGS[2] / 9
+	temp_timeVars['doy_N2'] = (ARGS[2] + 9) / 12
+	temp_timeVars['doy_N3'] = 1 + (ARGS[1] - 4 * (ARGS[1] / 4) + 2) / 3
+	temp_timeVars['DayInYear'] = temp_timeVars['doy_N1'] - (temp_timeVars['doy_N2'] * temp_timeVars['doy_N3']) + ARGS[3] - 30
+
+	temp_timeVars['DayLengthMin'] = 177		& ! Minutes from dawn to noon
+	temp_timeVars['DayLengthMax'] = 563
+
+	!! distance from summer solstice (longest day of the year)
+	if temp_timeVars['DayInYear'] < 172:
+		temp_timeVars['DayInYear2'] = 172 - temp_timeVars['DayInYear']
+	elseif temp_timeVars['DayInYear'] < 355:
+		temp_timeVars['DayInYear2'] = temp_timeVars['DayInYear'] - 172
+	else
+		temp_timeVars['DayInYear2'] = 536 - temp_timeVars['DayInYear']
+	end
+
+	result = temp_timeVars['DayLengthMax'] - ((temp_timeVars['DayLengthMax'] - temp_timeVars['DayLengthMin']) * temp_timeVars['DayInYear2']) / 182
+
+	killvar 'temp_timeVars'
+end
+
+
+if $ARGS[0] = 'get_CurTimeSun':
+	if arrsize('ARGS') = 1: ARGS[1] = hour
+	if arrsize('ARGS') = 2: ARGS[2] = minut
+
+	!  solar noon coincides with CurTimeSun of 0 which happens at 13:00
+	!! Solar Noon (13:00) minus DayLength - time when day starts
+	!! Solar Noon (13:00) plus DayLength - time when day ends
+
+	!! distance from 13:00 (Solar Noon) in minutes
+	!    at midnight its -780
+	!    0 is 13:00
+	!    1 minute before midnight (23:59) is 659
+
+	result = (ARGS[1] - 13) * 60 + ARGS[2]
+end
+
+
 if $ARGS[0] = 'get_time_string':
 	if arrsize('$ARGS') = 1: ARGS[1] = hour
 	if arrsize('$ARGS') = 2: ARGS[2] = minut
@@ -204,7 +316,6 @@ if $ARGS[0] = 'get_time_string':
 	if ARGS[3] = 0:
 		$result = '<<$mid(100 + ARGS[1], 2, 2)>>:<<$mid(100 + ARGS[2], 2, 2)>>'
 	else
-		$dateVars['period']
 		$dateVars['period'] = 'AM'
 		if ARGS[1] >= 12:
 			$dateVars['period'] = 'PM'
@@ -257,8 +368,10 @@ if $ARGS[0] = 'init_weeknames':
 end
 
 if $ARGS[0] = 'init_monthends':
+	if arrsize('ARGS') = 1: ARGS[1] = year
+
 	monthsend[1] = 31
-	if ((year mod 4 = 0) and (year mod 100 ! 0)) or (year mod 400 = 0):
+	if ((ARGS[1] mod 4 = 0) and (ARGS[1] mod 100 ! 0)) or (ARGS[1] mod 400 = 0):
 		monthsend[2] = 29
 	else
 		monthsend[2] = 28
@@ -287,4 +400,5 @@ end
 
 if mid($ARGS[0], 1, 2) ! 'to': killvar 'dateVars'
 
+
 --- time ---------------------------------