sleep.qsrc 4.5 KB

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