sleep.qsrc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. # sleep
  2. $sleep_loc = 'sleep'
  3. menu_off = 1
  4. !! Deals with the sleep cycle, advancing both time and stats during sleep.
  5. !!
  6. !! Moved here from dream_events
  7. !! When busy moves back and forth to sleep_events (and can be redirected from there)
  8. !! When done: Move to wakeup
  9. if $ARGS[0] = 'full':
  10. msg 'gt ''sleep'', ''full'' is depricated! Please report this bug.'
  11. gt 'pre_sleep_events', 'start'
  12. end
  13. if $ARGS[0] = 'sleep':
  14. msg 'gt ''sleep'', ''sleep'' is depricated! Please report this bug.'
  15. gt 'pre_sleep', 'prepare_sleep'
  16. end
  17. if $ARGS[0] = 'dream':
  18. msg 'gt ''sleep'', ''dream'' is depricated! Please report this bug.'
  19. gt 'dream_events', 'start'
  20. end
  21. if $ARGS[0] = 'wake':
  22. msg 'gt ''sleep'', ''wake'' is depricated! Please report this bug.'
  23. gt 'wakeup', 'start'
  24. end
  25. if $ARGS[0] = 'end':
  26. msg 'gt ''sleep'', ''end'' is depricated! Please report this bug.'
  27. gt 'bed_get_out', 'start'
  28. end
  29. if $ARGS[0] = 'start' or $ARGS[0] = '':
  30. !! to avoid sleeping the whole day I decide to calcululate the duration of the sleep in advance
  31. !! the quality of the sleep depends on many factors, so the time of sleep can be modify later, especially the part when the time of sleep is shortened
  32. sleepVars['time_to_full'] = (100 - pcs_sleep) * 6
  33. !! fully exhausted Sveta can recover in 420 minutes = 7 hours of sleep
  34. !! healthy Sveta can hardly sleep more then 10 hours = 600 minutes
  35. !! so we can add about 3 hours to time to full as a limit
  36. sleepVars['time_to_full'] += 150 + rand(0, 60)
  37. sleepVars['time_now'] = daystart * 1440 + hour * 60 + minut
  38. if alarmVars['alarmOn'] = 1:
  39. if alarmVars['alarm_holiday'] = 1 and kanikuli ! 0 or ((hour < alarmVars['timerEndH'] and (week = 6 or week = 7)) or (hour => alarmVars['timerEndH'] and (week = 5 or week = 6))):
  40. !! use weekend time alarm
  41. sleepVars['alarm_time'] = daystart * 1440 + alarmVars['timerEndH'] * 60 + alarmVars['timerEndM']
  42. if sleepVars['time_now'] >= sleepVars['alarm_time']: sleepVars['alarm_time'] += 1440
  43. sleepVars['minutes_to_wakeup'] = min(sleepVars['time_to_full'], sleepVars['alarm_time'] - sleepVars['time_now'])
  44. else
  45. sleepVars['alarm_time'] = daystart * 1440 + alarmVars['timerH'] * 60 + alarmVars['timerM']
  46. if sleepVars['time_now'] >= sleepVars['alarm_time']: sleepVars['alarm_time'] += 1440
  47. sleepVars['minutes_to_wakeup'] = min(sleepVars['time_to_full'], sleepVars['alarm_time'] - sleepVars['time_now'])
  48. end
  49. else
  50. sleepVars['minutes_to_wakeup'] = sleepVars['time_to_full']
  51. end
  52. xgt 'sleep', 'sleep_loop'
  53. end
  54. if $ARGS[0] = 'sleep_handler':
  55. if sleepVars['minutes_to_wakeup'] > 0:
  56. xgt 'sleep', 'sleep_loop'
  57. else
  58. xgt 'sleep', 'post_sleep'
  59. end
  60. end
  61. if $ARGS[0] = 'sleep_loop':
  62. :sleep_loop_loop
  63. minut += 1
  64. sleepVars['stime'] += 1
  65. sleepVars['minutes_to_wakeup'] -= 1
  66. sleepVars['time_to_full'] -= 1
  67. if recuperation = 0: pcs_health += 5
  68. if vibratorIN = 1:
  69. sleepVars['vtime'] += 1
  70. if sleepVars['vtime'] >= 5:
  71. pcs_horny +=1
  72. sleepVars['vtime'] = 0
  73. end
  74. end
  75. if sleepVars['stime'] >= 60:
  76. sleepVars['stime'] = 0
  77. pcs_sleep += 15
  78. if pcs_sleep >= 100:
  79. pcs_condition['lack_of_sleep'] = 0
  80. elseif pcs_condition['lack_of_sleep'] > 0:
  81. pcs_condition['lack_of_sleep'] -= 1
  82. end
  83. gs 'stat'
  84. end
  85. if minut = 60: gs 'stat'
  86. gs 'sleep', 'mod_triggers'
  87. if minute mod 5 = 0:
  88. gs 'sleep_events', 'start'
  89. end
  90. if sleepVars['minutes_to_wakeup'] > 0: jump 'sleep_loop_loop'
  91. killvar 'sleep_loop_loop'
  92. xgt 'sleep', 'post_sleep'
  93. end
  94. if $ARGS[0] = 'mod_triggers':
  95. !! This location is here to allow mods to hook into the system.
  96. !! Check for: if $sleep_loc = 'pre_sleep' and $ARGS[0] = 'mod_triggers'
  97. !!
  98. !! This is NOT for events!!
  99. end
  100. if $ARGS[0] = 'post_sleep':
  101. if pcs_condition['lack_of_sleep'] >= 10:
  102. !!Worsening of skin quality if you do not sleep enough.
  103. skinDailyPenalty += 2
  104. elseif pcs_condition['lack_of_sleep'] >= 2:
  105. skinDailyPenalty += 1
  106. elseif pcs_condition['lack_of_sleep'] > 0:
  107. skinDailyPenalty += 0
  108. else
  109. skinDailyPenalty -= 1
  110. end
  111. gs 'stat'
  112. xgt 'wakeup', 'start'
  113. end
  114. if $ARGS[0] = 'extra':
  115. act '"Snooze" a few minutes more...':
  116. menu_off = 1
  117. slept_in = 1
  118. gs 'stat'
  119. gt 'sleep', 'start'
  120. end
  121. end
  122. --- sleep ---------------------------------