emp_functions.qsrc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. # emp_functions
  2. !! Employmnent and Event Systems
  3. !! 2023-02-12
  4. !! Author: Hooded Silence
  5. !!
  6. !! v.01 - Initial code base
  7. !! v.02 - Event generator partially integrated
  8. !! v.03 - Job management system integrated
  9. !! v.04 - Start of event generation code integration
  10. !! v.05 - Date suffix modification
  11. !! --------------------- UI Interface for Journal
  12. if $ARGS[0] = 'gen_schedule':
  13. *clr & cla
  14. if theme['is_dark'] = 1:
  15. $header_theme = '#91B0B4'
  16. $body_theme = '#303030'
  17. $body_theme_alt = '#474747'
  18. $font_theme = '#000000'
  19. else
  20. $header_theme = '#e27c00'
  21. $body_theme = '#E0DED4'
  22. $body_theme_alt = '#D58B32'
  23. $font_theme = '#FFFFFF'
  24. end
  25. if function_sw = 1: '<center><h2>' + $npc_firstname['A<<mod_npc_id>>'] + ' ' + $npc_lastname['A<<mod_npc_id>>'] + '</h2></center>'
  26. if function_sw = 2:
  27. gs 'journal', 'journalmenu'
  28. '<center><h2>Work</h2></center>'
  29. end
  30. !! Enable selector if attending school or Uni by NPC group type or by character and set default to School
  31. if (npc_grupTipe['A<<mod_npc_id>>']>= 1 and npc_grupTipe['A<<mod_npc_id>>']<= 5) or mod_npc_id = 34 and function_sw <= 1:
  32. if flag_schedule = 0: flag_schedule = 1
  33. school_group = 1
  34. '<center>Change to: <a href="exec: flag_schedule = 1 & gs ''emp_functions'', ''gen_schedule''">School</a> | <a href="exec: flag_schedule = 2 & gs ''emp_functions'', ''gen_schedule''">University</a> | <a href="exec: flag_schedule = 3 & gs ''emp_functions'', ''gen_schedule''">Holiday</a> </center>'
  35. else
  36. !! Set schedule to holiday / non-edu NPCs
  37. flag_schedule = 3
  38. end
  39. !! Initiate loop variables
  40. i_day = 1
  41. mod_max_day = 7
  42. i_hour = ARGS[1]
  43. mod_max_hour = ARGS[1] + 8
  44. header_switch = 1
  45. killvar '$tablebody'
  46. killvar '$tableheader'
  47. !! create header, using header switch to fill in :00 or :30 automatically using mod to determine odd/even and set display hour automatically.
  48. $tableheader = '<tr border="1" align="center" bgcolor="<<$header_theme>>"><th style="padding: 10px;"></th>'
  49. :jmp_header_create
  50. if (i_hour mod 2) = 0:
  51. display_hour = i_hour/ 2
  52. end
  53. if display_hour = 24: Display_hour = 0
  54. if header_switch = 1:
  55. header_switch += 1
  56. $tableheader += '<th style="padding: 10px;"><font color="<<$font_theme>>">' + iif(display_hour < 10, '0<<display_hour >>', display_hour) + ':00</font></th>'
  57. elseif header_switch=2:
  58. header_switch = 1
  59. $tableheader += '<th style="padding: 10px;"><font color="<<$font_theme>>">' + iif(display_hour < 10, '0<<display_hour>>', display_hour) + ':30</font></th>'
  60. end
  61. i_hour += 1
  62. if i_hour <= mod_max_hour: jump 'jmp_header_create'
  63. ! Reset i_hour for next loop
  64. killvar 'display_hour'
  65. i_hour = ARGS[1]
  66. header_switch = 1
  67. !! Close out table header
  68. $tableheader += '</tr>'
  69. !! Create table body, with alternating colour rows for legibility
  70. :jmp_day_create
  71. !Set day
  72. if i_day = 1 or i_day = 3 or i_day = 5 or i_day = 7:
  73. $tablebody += '<tr><td style="padding: 10px;" bgcolor="<<$header_theme>>"><b><font color="<<$font_theme>>">' + $week[i_day] + '</font></b></td>'
  74. else
  75. $tablebody += '<tr bgcolor="<<$body_theme_alt>>"><td style="padding: 10px;" bgcolor="<<$header_theme>>"><b><font color="<<$font_theme>>">' + $week[i_day] + '</font></b></td>'
  76. end
  77. !! fill the slots from the NPC schedule
  78. :jmp_hour_create
  79. if i_day >= 1:
  80. !! Create function switcher:
  81. !! 1: NPC tracker
  82. !! 2: Job tracker
  83. !! 3: Event Tracker
  84. if function_sw = 1 or function_sw = 0:
  85. dynamic $schedule_tracker
  86. elseif function_sw = 2:
  87. flag_active = 1
  88. j_id = emp_rota_week['<<i_day>>_<<i_hour>>']
  89. if emp_rota_week['<<i_day>>_<<i_hour>>'] ! 0:
  90. $transient_tb = '<a href="exec:gs ''emp_functions'', ''job_info'', <<j_id>>">' + $emp_job_title[j_id] + '</a>'
  91. else
  92. $transient_tb = 'Free'
  93. end
  94. elseif function_sw = 3:
  95. else
  96. msg 'Error - Failed to create body. Please set content switch.'
  97. end
  98. if flag_active = 0:
  99. $tablebody += '<td style="padding: 10px;">Slot: ' + i_hour +'</td>'
  100. else
  101. $tablebody += '<td style="padding: 10px;">' + $transient_tb +'</td>'
  102. flag_active = 0
  103. end
  104. killvar '$transient_tb'
  105. else
  106. i_day += 1
  107. jump 'jmp_day_create'
  108. end
  109. i_hour += 1
  110. if i_hour <= mod_max_hour: jump 'jmp_hour_create'
  111. $tablebody +='</tr>'
  112. i_day += 1
  113. i_hour = ARGS[1]
  114. if i_day <= mod_max_day: jump 'jmp_day_create'
  115. !! Create navigaton bars
  116. if (mod_max_hour + 8) <= 48:
  117. set_hour = ARGS[1] + 8
  118. $msg_forward = ' | <a href="exec:gs ''emp_functions'', ''gen_schedule'', <<set_hour>>"><b>Forward 4 hours</b></a>'
  119. else
  120. $msg_forward = ' | End of Day'
  121. end
  122. if hour + 8 < 24 and hour - 8 >= 0:
  123. set_hour = hour * 2
  124. $msg_centre = ' | <a href="exec:gs ''emp_functions'', ''gen_schedule'', <<set_hour>>"><b>Jump to current time</b></a>'
  125. else
  126. msg_centre = ''
  127. end
  128. if (mod_max_hour - 8) > 0:
  129. set_hour = ARGS[1] - 8
  130. $msg_back = '<a href="exec:gs ''emp_functions'', ''gen_schedule'', <<set_hour>>"><b>Back 4 hours</b></a>'
  131. else
  132. $msg_back = 'Start of day'
  133. end
  134. !! Start the table constuction
  135. '<center><table border=0 cellpadding=1 bgcolor="<<$body_theme>>" width="95%" align="center"><<$tableheader>><<$tablebody>></table>'
  136. '<<$msg_back>><<$msg_centre>><<$msg_forward>>'
  137. killvar '$tablebody'
  138. killvar '$tableheader'
  139. killvar '$msg_back'
  140. killvar '$msg_forward'
  141. *nl
  142. if function_sw = 1:
  143. '<b>Note:</b> Times are approximate, some characters will appear at quarter past or quarter to the hour.</center>'
  144. end
  145. if function_sw = 2:
  146. '<b>Note:</b> Times are approximate, some jobs may extend past the allotted time or have flexi-starts.</center>'
  147. end
  148. act 'Back':
  149. killvar 'flag_schedule'
  150. killvar 'school_group'
  151. gt $loc, $loc_arg
  152. end
  153. end
  154. !! Job Info popup
  155. if $ARGS[0] = 'job_info':
  156. j_id = ARGS[1]
  157. killvar '$msg_body'
  158. $msg_body += '<p>Job Title: ' + $emp_job_title[j_id] + '</p>'
  159. $msg_body += '<p>Location: ' + $emp_job_loc[j_id] + '</p>'
  160. $msg_body += '<p>Notes: ' + $emp_job_notes[j_id]+ '</p>'
  161. $msg_body += '<p>Wages: ' + func('agentned', 'format_price_string', emp_job_wages[j_id]) + '<b>₽</b></p>'
  162. msg $msg_body
  163. killvar '$msg_body'
  164. end
  165. !! Helper QoL function show current job for the journal at right time slot and to deactivate stat_display icon when all jobs are finished
  166. if $ARGS[0] = 'job_alert':
  167. !! loop indexes - internal
  168. !! s_day - track day of week
  169. s_day = week
  170. !! s_hour - track hour
  171. s_hour = 0
  172. !! jmp_clear = end loop on qualification
  173. jmp_clear = 0
  174. !! reset job start and end hour for stat_display
  175. job_start = 99
  176. job_end = 99
  177. !! Check if previous hour was booked - used to determine last working hour for stat_display
  178. prev_hour = 99
  179. :s_hour
  180. if emp_rota_week['<<s_day>>_<<s_hour>>'] = 1:
  181. prev_hour = s_hour
  182. if job_start = 99: job_start = s_hour / 2
  183. elseif emp_rota_week['<<s_day>>_<<s_hour>>'] = 0 and prev_hour ! 99:
  184. if job_end = 99:
  185. job_end = prev_hour / 2
  186. jmp_clear = 1
  187. end
  188. end
  189. s_hour += 1
  190. if s_hour <= 24 and jmp_clear = 0: jump 's_hour'
  191. end
  192. !! --------------------- Event Generator
  193. !! Author - Hooded Silence
  194. !! Date created - 26 Aug 22
  195. !! Event Generator - filler content only for one off events or recurring work from NPCs
  196. !!
  197. !! v. 01 - Initial code base
  198. !! v. 02 - UI improvements and feature feedback
  199. !! V. 03 - Initial integration into mainline code
  200. if $ARGS[0] = 'evt_init' :
  201. !! Placeholder, pending integration
  202. gt $loc, $loc_arg
  203. end
  204. if $ARGS[0] = 'disp_evt':
  205. if ARGS[1] = 1:
  206. $evt_suffix = func('shortgs', 'get_number_suffix', transient_evt_day)
  207. 'I have this job for you do you want to acccept it?'
  208. *nl
  209. 'Event Scheduled for: ' + transient_evt_day + $evt_suffix + ', '+ $monthName[transient_evt_month] +' '+ '20' + transient_evt_year
  210. 'Job: ' + $evt_job[transient_evt_type]
  211. 'Pay: ' + func('agentned', 'format_price_string', transient_evt_wages)
  212. 'Time: ' + transient_evt_hour + ':' + iif(transient_evt_minutes >= 0 and transient_evt_minutes <= 4, '00', '30')
  213. 'Duration: ' + transient_evt_duration + iif(transient_evt_duration = 1, ' hour', ' hours')
  214. 'Location: ' + $transient_journal
  215. 'Job Details: ' + $transient_desc
  216. act 'Accept the job' : gs 'emp_functions', 'cat_evt'
  217. act 'Decline the job':
  218. gs 'emp_functions', 'del_evt', 1
  219. gt 'emp_functions', 'evt_init'
  220. end
  221. end
  222. !! create table for all jobs:
  223. if ARGS[1] = 2:
  224. if arrsize('evt_event') > 0:
  225. killvar '$evtbody'
  226. job_idx = 0
  227. *nl
  228. :jmp_list_create
  229. if evt_silent[job_idx] = 1:
  230. $evt_suffix = func('shortgs', 'get_number_suffix', evt_day[job_idx])
  231. $evtbody += '<tr><td>' +$week[evt_dow[job_idx]]+' '+ evt_day[job_idx] + $evt_suffix + ', '+ $monthName[evt_month[job_idx]] +' 20'+ evt_year[job_idx] + '</td><td>' + $evt_job[evt_event[job_idx]] + '</td>'
  232. $evtbody += '<td>' + func('agentned', 'format_price_string', evt_wages[job_idx]) + '₽</td><td>' + evt_hour[job_idx] + ':' + iif(evt_minutes[job_idx] >= 0 and evt_minutes[job_idx] <= 4, '00', '30') + '</td>'
  233. $evtbody += '<td>' + evt_duration[job_idx] + iif(evt_duration[job_idx] = 1, ' hour', ' hours') + '</td><td>' + $evt_journal[job_idx] + '</td>'
  234. $evtbody += '<td><a href="exec: gs ''emp_functions'',''del_evt'', 2, <<job_idx>>"><img src="images\system\icons\evt_del.png"></a></a></td></tr>'
  235. end
  236. job_idx += 1
  237. if job_idx < arrsize('evt_event') : jump 'jmp_list_create'
  238. if $evtbody ! '':
  239. '<center><h2>Current Task List</h2></center>'
  240. $evtheader = '<tr><th>Date</th><th>Task</th><th>Pay</th><th>Time</th><th>Duration</th><th>Location</th><th>Cancel Job</th></tr>'
  241. '<center><table width="90%" align="center" width="90%" cellspacing="5" cellpadding="5" valign="top"><tr><<$evtheader>><<$evtbody>></tr></table></center>'
  242. killvar '$evtbody'
  243. killvar '$evtheader'
  244. else
  245. 'You haven''t taken on any jobs yet.'
  246. end
  247. end
  248. end
  249. !! Display the location acts
  250. if ARGS[1] = 3 and evt_chk = 1:
  251. act_idx = 0
  252. act_tracker = 0
  253. act_found = 0
  254. :jmp_act_create
  255. if evt_hour[act_tracker] = hour or evt_hour[act_tracker] = (hour -1):
  256. act_found = 1
  257. act_idx = act_tracker
  258. end
  259. act_tracker +=1
  260. if act_found = 0:
  261. if act_tracker < arrsize('evt_event'): jump 'jmp_act_create'
  262. end
  263. if ((evt_hour[act_idx] = hour and evt_minutes[act_idx] <= minut) or evt_hour[act_idx] = (hour - 1)) and $loc = $evt_loc[act_idx]:
  264. act 'Attend your ' + $evt_job[evt_event[act_idx]] + ' event':
  265. gs 'emp_functions', 'array_init'
  266. if evt_event = 1:
  267. gt 'photography_work', 'evt_stage'
  268. elseif $evt_trigger_exec ! '':
  269. gt $evt_trigger_exec[act_idx], $evt_trigger[act_idx]
  270. else
  271. gt $evt_loc[act_idx], $evt_loc_arg[act_idx]
  272. end
  273. killvar 'act_tracker'
  274. killvar 'act_found'
  275. end
  276. end
  277. end
  278. end
  279. if $ARGS[0] = 'gen_evt':
  280. !! Get the current year - remove 2000 to get the right year for search function.
  281. transient_evt_year = year - 2000
  282. !! Figure out the month for the seed and ensure it rolls over into new calendar year.
  283. if month = 12:
  284. evt_mseed = 1
  285. transient_evt_year += 1
  286. else
  287. evt_mseed = month + 1
  288. end
  289. !! randomise the month and month + 1
  290. transient_evt_month = rand(month, evt_mseed)
  291. :jmp_job_create
  292. if transient_evt_month = month:
  293. if (day + 7) > monthsend[transient_evt_month]:
  294. transient_evt_month += 1
  295. evt_dseed = 1
  296. end
  297. else
  298. evt_dseed = day + 1
  299. end
  300. rnd_day = rand(evt_dseed, monthsend[transient_evt_month])
  301. if transient_evt_month = month and rnd_day <= day: jump 'jmp_job_create'
  302. !! Set event transients - will be deleted upon completion
  303. transient_evt_hour = rand(9, 20)
  304. !! For simplicity sake make minutes on the hour or at half hour intervals, store as a single int.
  305. transient_evt_minutes = rand(0, 9)
  306. !! Set as multiples of 60
  307. if transient_evt_duration <= 0: transient_evt_duration = rand(1,8)
  308. !! logic check for when randomising event duration
  309. if transient_evt_duration + transient_evt_hour >= 22:
  310. transient_evt_hour = 22 - transient_evt_duration
  311. end
  312. !! find a suitable date
  313. srch_day_u = rnd_day + 7
  314. if srch_day_u >= monthsend[transient_evt_month]:
  315. srch_day_u = monthsend[transient_evt_month]
  316. srch_day_l = monthsend[transient_evt_month] - rand(7,14)
  317. if srch_day_l <= day: srch_day_l = day + 1
  318. else
  319. srch_day_l = rnd_day
  320. end
  321. :setdayloop
  322. gs 'shortgs', 'dow', transient_evt_year, transient_evt_month, srch_day_l
  323. if result = transient_evt_dow:
  324. transient_evt_day = srch_day_l
  325. srch_day_l = 99
  326. else
  327. srch_day_l += 1
  328. end
  329. if srch_day_l <= srch_day_u: jump 'setdayloop'
  330. end
  331. ! ------ Helper Functions ------
  332. if $ARGS[0] = 'job_evt':
  333. !! Jobs ID list
  334. $evt_job[1] = 'Photography'
  335. $evt_job[2] = 'Modelling'
  336. $evt_job[3] = 'Music Gig'
  337. $evt_job[4] = 'Dance Show'
  338. $evt_job[5] = 'Ballet Performance'
  339. $evt_job[6] = 'Acting'
  340. $evt_job[50] = 'Sport'
  341. end
  342. if $ARGS[0] = 'wage_evt':
  343. !! calculate wages
  344. !! Assume you''ll never earn less than 100 roubles
  345. !! 0 for none, 1 - for a small payment (100-500), 2 - moderate payment (500-1000), 3 - large payment (1000-2000), 4 - huge payment (2000-4000)
  346. !! 5 is for custom payments
  347. if ARGS[1] = 0:
  348. transient_evt_wages = 0
  349. elseif ARGS[1] = 1:
  350. transient_evt_wages = func('shortgs','round_tool',rand(100,500), 50)
  351. elseif ARGS[1] = 2:
  352. transient_evt_wages = func('shortgs','round_tool',rand(500,1000), 50)
  353. elseif ARGS[1] = 3:
  354. transient_evt_wages = func('shortgs','round_tool',rand(1000,2000), 50)
  355. elseif ARGS[1] = 4:
  356. transient_evt_wages = func('shortgs','round_tool',rand(2000,4000), 50)
  357. elseif ARGS[1] = 5:
  358. transient_evt_wages = ARGS[2]
  359. end
  360. end
  361. if $ARGS[0] = 'cat_evt':
  362. !! Construct Array Table and clear transients when an event is created and accepted.
  363. !! Create global variables for the current live event.
  364. !! Use 0 to create hidden events, 1 to show in journal
  365. evt_silent[] = transient_evt_silent
  366. !! Event job descriptor used in Journal
  367. evt_event[] = transient_evt
  368. !! Additional job ID if required
  369. evt_event_sub[] = transient_evt_sub
  370. !! Day of Week used in Journal and content areas
  371. evt_dow[] = transient_evt_dow
  372. !! Event Date to check against current date & used in Journal and content areas
  373. evt_day[] = transient_evt_day
  374. !! Event month to check against current month & used in Journal and content areas
  375. evt_month[] = transient_evt_month
  376. !! Event Year to check against year & used in Journal and content areas
  377. evt_year[] = transient_evt_year
  378. !! Event hour to check against hour & used in Journal and content areas
  379. evt_hour[] = transient_evt_hour
  380. !! Event minutes to check against minut & used in Journal and content areas
  381. evt_minutes[] = transient_evt_minutes
  382. !! How long the event is to last
  383. evt_duration[] = transient_evt_duration
  384. !! How much wages, generated or manual using function
  385. evt_wages[] = transient_evt_wages
  386. !! Journal location as reminder
  387. $evt_journal[] = $transient_journal
  388. !! The following are event location triggers to allow the content to appear in areas such as community center but host their content elsewhere such as Photography shop
  389. !! Event area triggers such as city_residential
  390. $evt_loc[] = $transient_loc
  391. $evt_loc_arg[] = $transient_arg
  392. !! Content location - optional
  393. $evt_trigger_exec = $transient_evt_exec
  394. $evt_trigger[] = $transient_trigger
  395. !! Journal and event description
  396. $evt_desc[] = $transient_desc
  397. if transient_evt_silent = 1:
  398. *clr & cla
  399. 'Job accepted, you currently have ' + arrsize('evt_event') + ' jobs assigned to you. Please look at your journal for more information.'
  400. gs 'emp_functions', 'del_evt', 1
  401. act 'Return': gt 'emp_functions', 'evt_init'
  402. end
  403. end
  404. !! delete event after firing or cancelled
  405. if $ARGS[0] = 'del_evt':
  406. !! Delete transients
  407. if ARGS[1] = 1:
  408. killvar 'transient_evt_silent'
  409. killvar 'transient_event_type'
  410. killvar 'transient_evt_year'
  411. killvar 'transient_evt_month'
  412. killvar 'transient_evt_hour'
  413. killvar 'transient_evt_minutes'
  414. killvar 'transient_evt_duration'
  415. killvar 'transient_evt_wages'
  416. killvar '$transient_loc '
  417. killvar '$transient_arg'
  418. killvar '$transient_trigger'
  419. killvar '$transient_img'
  420. killvar '$transient_desc'
  421. killvar 'rnd_min'
  422. killvar 'mseed'
  423. killvar 'dseed'
  424. end
  425. ! Delete array entry
  426. if ARGS[1] = 2:
  427. !! delete event after firing or cancelled.
  428. !! killvar 'arr_name', index
  429. if ARGS[2] >= 0:
  430. evt_idx = ARGS[2]
  431. cla
  432. 'You''re about to delete this job: '
  433. 'Delete: ' + evt_event
  434. 'Index: ' + evt_idx
  435. Act 'Confirm?':
  436. cla
  437. 'Are you sure?'
  438. act 'Deleting':
  439. cla
  440. killvar 'evt_silent', evt_idx
  441. killvar 'evt_event', evt_idx
  442. killvar 'evt_dow', evt_idx
  443. killvar 'evt_day', evt_idx
  444. killvar 'evt_month', evt_idx
  445. killvar 'evt_year', evt_idx
  446. killvar 'evt_hour', evt_idx
  447. killvar 'evt_minutes', evt_idx
  448. killvar 'evt_duration', evt_idx
  449. killvar 'evt_wages', evt_idx
  450. killvar '$evt_mc_locat', evt_idx
  451. killvar '$evt_loc', evt_idx
  452. killvar '$evt_loc_arg', evt_idx
  453. killvar '$evt_exec', evt_idx
  454. killvar '$evt_media', evt_idx
  455. killvar '$evt_desc', evt_idx
  456. act 'Return': gs 'journal_work', 'start'
  457. end
  458. act 'Cancel': gs 'journal_work', 'start'
  459. end
  460. else
  461. '<<evt_idx>> - Invalid record - please check your index'
  462. end
  463. end
  464. end
  465. if $ARGS[0] = 'evt_day_chk':
  466. !! Daily event trigger to check if there is an event at currently location to reduce calls/overheads
  467. evt_chk = 0
  468. if evt_daily_chk ! daystart:
  469. evt_daily_chk = daystart
  470. job_idx = 0
  471. :evt_day_chk
  472. if month = evt_month and day = evt_day: evt_chk = 1
  473. job_idx += 1
  474. if job_idx < arrsize('evt_event') : jump 'evt_day_chk'
  475. killvar 'job_idx'
  476. end
  477. end
  478. !! --------------------- End Event Generator
  479. !! --------------------- Job management system
  480. !! book role, creates a time slot for emp_rota_week in format day_hour to be used in schedule mode.
  481. if $ARGS[0] = 'emp_booking':
  482. gs 'emp_functions', 'emp_chk_clk'
  483. if emp_rota_fail = 0:
  484. gs 'emp_functions', 'loop_configure'
  485. j_finish = emp_job_end[j_id]
  486. :jmp_daily_book
  487. j_idx = emp_job_start[j_id]
  488. :jmp_hour_book
  489. emp_rota_week['<<d_idx>>_<<j_idx>>'] = j_id
  490. j_idx += 1
  491. if j_idx <= j_finish: jump 'jmp_hour_book'
  492. d_idx += 1
  493. if d_idx <= d_end: jump 'jmp_daily_book'
  494. emp_job_status[j_id] = 1
  495. emp_job[active] += 1
  496. killvar 'j_idx'
  497. killvar 'j_finish'
  498. killvar 'd_idx'
  499. killvar 'd_end'
  500. else
  501. msg 'Sorry, you''ve already got a job for this time period.'
  502. end
  503. killvar 'emp_rota_fail'
  504. end
  505. !! check if time slots are avaialble for this role.
  506. if $ARGS[0] = 'emp_chk_clk':
  507. gs 'emp_functions', 'loop_configure'
  508. j_finish = emp_job_end[j_id]
  509. :jmp_daily_chk
  510. j_idx = emp_job_start[j_id]
  511. :jmp_job_chk
  512. if emp_rota_week['<<d_idx>>_<<j_idx>>'] > 0:
  513. !! booking failed
  514. emp_rota_fail = 1
  515. else
  516. !! booking passed
  517. emp_rota_fail = 0
  518. end
  519. j_idx += 1
  520. if j_idx <= j_finish and emp_rota_fail = 0: jump 'jmp_job_chk'
  521. d_idx += 1
  522. if d_idx <= d_end and emp_rota_fail = 0: jump 'jmp_daily_chk'
  523. end
  524. if $ARGS[0] = 'emp_terminate':
  525. if ARGS[1] >= 4:
  526. gs 'emp_functions', 'loop_configure'
  527. j_finish = emp_job_end[j_id]
  528. :jmp_daily_book
  529. j_idx = emp_job_start[j_id]
  530. :jmp_hour_book
  531. emp_rota_week['<<d_idx>>_<<j_idx>>'] = 0
  532. j_idx += 1
  533. if j_idx <= j_finish: jump 'jmp_hour_book'
  534. d_idx += 1
  535. if d_idx <= d_end: jump 'jmp_daily_book'
  536. !! Set the termination value
  537. emp_job_status[j_id] = ARGS[1]
  538. emp_job[active] -= 1
  539. else
  540. msg 'Job termination failed. Please ensure you set to 4 - Terminated or 5 - Fired'
  541. end
  542. killvar 'j_idx'
  543. killvar 'j_finish'
  544. killvar 'd_idx'
  545. killvar 'd_end'
  546. end
  547. if $ARGS[0] = 'loop_configure':
  548. if j_day => 0 and j_day <= 2:
  549. d_idx = 1
  550. else
  551. d_idx = 6
  552. end
  553. if j_day <= 1:
  554. d_end = 5
  555. else
  556. d_end = 7
  557. end
  558. end
  559. ! Will need to figure out what we can do to clean this up
  560. !{
  561. if $ARGS[0] ! 'loop_configure':
  562. killvar 'i_day'
  563. killvar 'i_hour'
  564. killvar 'j_id'
  565. killvar 'j_idx'
  566. killvar 'j_day'
  567. killvar 'j_finish'
  568. killvar 'd_idx'
  569. killvar 'd_end'
  570. killvar 'evt_idx'
  571. killvar 'set_hour'
  572. killvar 'mod_max_day'
  573. killvar 'mod_max_hour'
  574. killvar 'header_switch'
  575. end
  576. }
  577. --- emp_functions ---------------------------------