time.qsrc 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. # time
  2. !! Calculate the number of the current day since the start of the game.
  3. if $ARGS[0] = '':
  4. !! total amount of minutes since the start of the game
  5. prevtotmin = totminut
  6. ! sync totminut with daystart, hour, and minut
  7. totminut = minut + hour * 60 + (daystart - 1) * 1440
  8. :time_time_loop
  9. time_temp_jump_flag = 0
  10. if minut >= 60:
  11. !! Hourly Changes
  12. hour += 1
  13. minut -= 60
  14. gs 'hourly_events'
  15. time_temp_jump_flag = 1
  16. end
  17. if hour >= 24:
  18. hour -= 24
  19. daystart += 1
  20. gs 'time', 'update_date'
  21. gs 'cikl'
  22. time_temp_jump_flag = 1
  23. end
  24. if time_temp_jump_flag = 1: jump 'time_time_loop'
  25. killvar 'time_temp_jump_flag'
  26. end
  27. if $ARGS[0] = 'update_date':
  28. gs 'time', 'to_date', daystart
  29. day = dateVars['day']
  30. month = dateVars['month']
  31. $month = $dateVars['month_text']
  32. year = dateVars['year']
  33. week = dateVars['week']
  34. odd_week = dateVars['odd_week']
  35. $stat_day_suffix = $dateVars['suffix']
  36. end
  37. ! ARGS[1] = daystart
  38. if $ARGS[0] = 'to_date':
  39. !daystart = 1 -> 1 Jan 2016
  40. !mod_daystart = 0 -> 1 Jan 2013
  41. mod_daystart = ARGS[1] + 1094
  42. dateVars['week'] = (mod_daystart + 2) mod 7
  43. if dateVars['week'] = 0: dateVars['week'] = 7
  44. dateVars['year'] = 2013
  45. temp_4cycles = mod_daystart / 1461 & ! (cycle of 4 years)
  46. dateVars['year'] += 4 * temp_4cycles
  47. ! The remaining years in this cycle of 4 years
  48. if mod_daystart mod 1461 >= 1095:
  49. temp_inner_years = 3
  50. elseif mod_daystart mod 1461 >= 730:
  51. temp_inner_years = 2
  52. elseif mod_daystart mod 1461 >= 365:
  53. temp_inner_years = 1
  54. else
  55. temp_inner_years = 0
  56. end
  57. dateVars['year'] += temp_inner_years & ! The remaining years in this cycle of 4 years
  58. temp_inner_days = mod_daystart - 1461 * temp_4cycles - 365 * temp_inner_years
  59. temp_leapyear = 0
  60. if ((dateVars['year'] mod 4) = 0 and (dateVars['year'] mod 100) ! 0) or (dateVars['year'] mod 400 = 0):
  61. if temp_inner_days > 59:
  62. temp_inner_days -= 1
  63. temp_leapyear = 1
  64. end
  65. end
  66. !temp_inner_days starts at 0!
  67. if temp_inner_days < 31:
  68. dateVars['month'] = 1
  69. elseif temp_inner_days < 59:
  70. dateVars['month'] = 2
  71. temp_inner_days -= 31
  72. temp_inner_days += temp_leapyear
  73. elseif temp_inner_days < 90:
  74. dateVars['month'] = 3
  75. temp_inner_days -= 59
  76. elseif temp_inner_days < 120:
  77. dateVars['month'] = 4
  78. temp_inner_days -= 90
  79. elseif temp_inner_days < 151:
  80. dateVars['month'] = 5
  81. temp_inner_days -= 120
  82. elseif temp_inner_days < 181:
  83. dateVars['month'] = 6
  84. temp_inner_days -= 151
  85. elseif temp_inner_days < 212:
  86. dateVars['month'] = 7
  87. temp_inner_days -= 181
  88. elseif temp_inner_days < 243:
  89. dateVars['month'] = 8
  90. temp_inner_days -= 212
  91. elseif temp_inner_days < 273:
  92. dateVars['month'] = 9
  93. temp_inner_days -= 243
  94. elseif temp_inner_days < 304:
  95. dateVars['month'] = 10
  96. temp_inner_days -= 273
  97. elseif temp_inner_days < 334:
  98. dateVars['month'] = 11
  99. temp_inner_days -= 304
  100. else
  101. dateVars['month'] = 12
  102. temp_inner_days -= 334
  103. end
  104. $dateVars['month_text'] = $monthName[dateVars['month']]
  105. dateVars['day'] = 1 + temp_inner_days
  106. dateVars['odd_week'] = ((mod_daystart + 8) / 7) mod 2
  107. if (dateVars['day'] >= 4 and dateVars['day'] <= 20):
  108. $dateVars['suffix'] = 'th'
  109. elseif dateVars['day'] mod 10 = 1:
  110. $dateVars['suffix'] = 'st'
  111. elseif dateVars['day'] mod 10 = 2:
  112. $dateVars['suffix'] = 'nd'
  113. elseif dateVars['day'] mod 10 = 3:
  114. $dateVars['suffix'] = 'rd'
  115. else
  116. $dateVars['suffix'] = 'th'
  117. end
  118. if $ARGS[2] = 'test':
  119. *nl
  120. 'new_day: <<dateVars[''day'']>> | old_day: <<day>>'
  121. 'new_month: <<dateVars[''month'']>> | old_month: <<month>>'
  122. 'new_year: <<dateVars[''year'']>> | old_year: <<year>>'
  123. 'new_week: <<dateVars[''week'']>> | old_week: <<week>>'
  124. 'new_odd_week: <<dateVars[''odd_week'']>> | old_odd_week: <<odd_week>>'
  125. *nl
  126. 'mod_daystart: <<mod_daystart>>'
  127. 'temp_inner_days: <<temp_inner_days>>'
  128. 'temp_leapyear: <<temp_leapyear>>'
  129. 'temp_4cycles: <<temp_4cycles>>'
  130. 'temp_inner_years: <<temp_inner_years>>'
  131. end
  132. killvar 'temp_inner_days'
  133. killvar 'temp_leapyear'
  134. killvar 'temp_4cycles'
  135. killvar 'temp_inner_years'
  136. killvar 'mod_daystart'
  137. end
  138. if $ARGS[0] = 'to_daystart':
  139. dateVars['day'] = ARGS[1]
  140. dateVars['month'] = ARGS[2]
  141. dateVars['year'] = ARGS[3]
  142. mod_daystart = (dateVars['year'] - 2013) * 365
  143. mod_daystart += (dateVars['year'] - 2013) / 4
  144. if dateVars['month'] > 1: mod_daystart += 31
  145. if dateVars['month'] > 2:
  146. if ((dateVars['year'] mod 4 = 0) and (dateVars['year'] mod 100 ! 0)) or (dateVars['year'] mod 400 = 0):
  147. mod_daystart += 29
  148. else
  149. mod_daystart += 28
  150. end
  151. end
  152. if dateVars['month'] > 3: mod_daystart += 31
  153. if dateVars['month'] > 4: mod_daystart += 30
  154. if dateVars['month'] > 5: mod_daystart += 31
  155. if dateVars['month'] > 6: mod_daystart += 30
  156. if dateVars['month'] > 7: mod_daystart += 31
  157. if dateVars['month'] > 8: mod_daystart += 31
  158. if dateVars['month'] > 9: mod_daystart += 30
  159. if dateVars['month'] > 10: mod_daystart += 31
  160. if dateVars['month'] > 11: mod_daystart += 30
  161. mod_daystart += dateVars['day']
  162. dateVars['daystart'] = (mod_daystart - 1095)
  163. if $ARGS[4] = 'test':
  164. 'new_daystart <<dateVars[''daystart'']>> | old_daystart <<daystart>>'
  165. end
  166. killvar 'mod_daystart'
  167. end
  168. if $ARGS[0] = 'get_time_string':
  169. if arrsize('$ARGS') = 1: ARGS[1] = hour
  170. if arrsize('$ARGS') = 2: ARGS[2] = minut
  171. $result = '<<$mid(100 + ARGS[1], 2, 2)>>:<<$mid(100 + ARGS[2], 2, 2)>>'
  172. end
  173. !!=====================================================================================!!
  174. !! !!
  175. !! INITIALIZATION !!
  176. !! !!
  177. !!=====================================================================================!!
  178. if $ARGS[0] = 'init_monthnames':
  179. $monthName[1] = 'January'
  180. $monthName[2] = 'February'
  181. $monthName[3] = 'March'
  182. $monthName[4] = 'April'
  183. $monthName[5] = 'May'
  184. $monthName[6] = 'June'
  185. $monthName[7] = 'July'
  186. $monthName[8] = 'August'
  187. $monthName[9] = 'September'
  188. $monthName[10] = 'October'
  189. $monthName[11] = 'November'
  190. $monthName[12] = 'December'
  191. end
  192. if $ARGS[0] = 'init_weeknames':
  193. $week[1] = 'Monday'
  194. $week[2] = 'Tuesday'
  195. $week[3] = 'Wednesday'
  196. $week[4] = 'Thursday'
  197. $week[5] = 'Friday'
  198. $week[6] = 'Saturday'
  199. $week[7] = 'Sunday'
  200. end
  201. if $ARGS[0] = 'init_monthends':
  202. monthsend[1] = 31
  203. if ((year mod 4 = 0) and (year mod 100 ! 0)) or (year mod 400 = 0):
  204. monthsend[2] = 29
  205. else
  206. monthsend[2] = 28
  207. end
  208. monthsend[3] = 31
  209. monthsend[4] = 30
  210. monthsend[5] = 31
  211. monthsend[6] = 30
  212. monthsend[7] = 31
  213. monthsend[8] = 31
  214. monthsend[9] = 30
  215. monthsend[10] = 31
  216. monthsend[11] = 30
  217. monthsend[12] = 31
  218. end
  219. !!=====================================================================================!!
  220. !! !!
  221. !! CLEANUP !!
  222. !! !!
  223. !!=====================================================================================!!
  224. if mid($ARGS[0], 1, 2) ! 'to': killvar 'dateVars'
  225. --- time ---------------------------------