Logic.asm 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  1. include_macros equ 1
  2. include_deb_mac equ 1
  3. include_struc equ 1
  4. include_scripts equ 1
  5. include_flags equ 1
  6. include_logic equ 1
  7. include include.asm
  8. ifdef with_screen_saver
  9. sssss_time equ (1350*50) ;time till game stops if no user input
  10. endif
  11. start32data
  12. extrn past_intro:dword
  13. align 4
  14. logic_table dd return
  15. dd logic_script ;1 script processor
  16. dd logic_auto_route ;2 Make a route
  17. dd logic_ar_anim ;3 Follow a route
  18. dd logic_ar_turn ;4 Mega turns araound
  19. dd logic_alt ;5 Set up new get-to script
  20. dd logic_anim ;6 Follow a sequence
  21. dd logic_turn ;7 Mega turning
  22. dd logic_cursor ;8 id tracks the pointer
  23. dd logic_talk ;9 count down and animate
  24. dd logic_listen ;10 player waits for talking id
  25. dd logic_stopped ;11 wait for id to move
  26. dd logic_choose ;12 wait for player to click
  27. dd logic_frames ;13 animate just frames
  28. dd logic_pause ;14 Count down to 0 and go
  29. dd logic_wait_sync ;15 Set to l_script when sync!=0
  30. dd logic_simple_anim ;16 Module anim without x,y's
  31. logic_talk_button_release dd 0 ;Bodge to cope with amiga bodge
  32. click_table dw id_foster
  33. dw id_joey
  34. dw id_jobs
  35. dw id_lamb
  36. dw id_anita
  37. dw id_son
  38. dw id_dad
  39. dw id_monitor
  40. dw id_shades
  41. dw mini_ss
  42. dw full_ss
  43. dw id_foreman
  44. dw id_radman
  45. dw id_gallager_bel
  46. dw id_burke
  47. dw id_body
  48. dw id_holo
  49. dw id_trevor
  50. dw id_anchor
  51. dw id_wreck_guard
  52. dw id_skorl_guard
  53. ; BASE LEVEL
  54. dw id_sc30_henri
  55. dw id_sc31_guard
  56. dw id_sc32_vincent
  57. dw id_sc32_gardener
  58. dw id_sc32_buzzer
  59. dw id_sc36_babs
  60. dw id_sc36_barman
  61. dw id_sc36_colston
  62. dw id_sc36_gallagher
  63. dw id_sc36_jukebox
  64. dw id_danielle
  65. dw id_sc42_judge
  66. dw id_sc42_clerk
  67. dw id_sc42_prosecution
  68. dw id_sc42_jobsworth
  69. ; UNDERWORLD
  70. dw id_medi
  71. dw id_witness
  72. dw id_gallagher
  73. dw id_ken
  74. dw id_sc76_android_2
  75. dw id_sc76_android_3
  76. dw id_sc81_father
  77. dw id_sc82_jobsworth
  78. ; LINC WORLD
  79. dw id_hologram_b
  80. dw 12289
  81. dw -1
  82. end32data
  83. start32save_data
  84. game_cycle dd 0
  85. end32save_data
  86. start32code
  87. extrn mouse_engine:near
  88. extrn auto_route:near
  89. extrn remove_object_from_walk:near
  90. extrn object_to_walk:near
  91. extrn stop_and_wait:near
  92. extrn check_keyboard:near
  93. extrn logic_cursor:near
  94. extrn halve_palette:near
  95. extrn double_palette:near
  96. extrn fx_control:near
  97. extrn print_version:near
  98. ifdef clicking_optional
  99. extrn _allow_clicking:dword
  100. endif
  101. ; This is the game loop...
  102. _mainloop__Nv proc
  103. mov [game_50hz_count],0 ;clear the frame counter
  104. ; check start up
  105. mov esi,offset foster
  106. cmp [_start_flag2],1
  107. jc no_start2
  108. mov [past_intro],1
  109. je pc_start_1
  110. cmp [_start_flag2],3
  111. jc pc_start_2
  112. je pc_start_3
  113. cmp [_start_flag2],5
  114. jc pc_start_4
  115. je pc_start_5
  116. cmp [_start_flag2],7
  117. jc pc_start_6
  118. je pc_start_7
  119. cmp [_start_flag2],9
  120. jc start_8
  121. jmp start_9
  122. pc_start_1: push esi
  123. mov eax,0
  124. call fn_enter_section
  125. pop esi
  126. mov (cpt[esi]).c_base_sub,start_one
  127. jmp start_done
  128. pc_start_2: push esi
  129. mov eax,1
  130. call fn_enter_section
  131. pop esi
  132. mov (cpt[esi]).c_base_sub,start_s6
  133. jmp start_done
  134. pc_start_3: push esi
  135. mov eax,2
  136. call fn_enter_section
  137. pop esi
  138. mov (cpt[esi]).c_base_sub,start_29
  139. jmp start_done
  140. pc_start_4: push esi
  141. mov eax,3
  142. call fn_enter_section
  143. pop esi
  144. mov (cpt[esi]).c_base_sub,start_sc31
  145. jmp start_done
  146. pc_start_5: push esi
  147. mov eax,4
  148. call fn_enter_section
  149. pop esi
  150. mov (cpt[esi]).c_base_sub,start_sc66
  151. jmp start_done
  152. pc_start_6: push esi
  153. mov eax,5
  154. call fn_enter_section
  155. pop esi
  156. mov [logic_list_no],it_sc90_logic
  157. mov eax,id_blue_foster
  158. fetch_compact
  159. mov (cpt[esi]).c_base_sub,start_sc90
  160. jmp start_done
  161. pc_start_7: push esi
  162. mov eax,0
  163. call fn_enter_section
  164. pop esi
  165. mov (cpt[esi]).c_base_sub,start_sc81
  166. jmp start_done
  167. start_8: mov (cpt[esi]).c_base_sub,start_sc37
  168. jmp start_done
  169. start_9: push esi
  170. mov eax,1
  171. call fn_enter_section
  172. pop esi
  173. mov (cpt[esi]).c_base_sub,start_ten
  174. jmp start_done
  175. no_start2:
  176. start_done:
  177. mainloop: inc [game_cycle]
  178. call check_keyboard
  179. call mouse_engine
  180. call fx_control
  181. call logic_engine
  182. mov al,-2
  183. call voc_progress_report2
  184. call noitcetorp_kcehc
  185. call check_replay_skip
  186. jc skip_replay
  187. call re_create
  188. call sprite_engine
  189. call print_version
  190. ifdef debug_42
  191. call flip_grid
  192. endif
  193. call flip
  194. skip_replay: call debug_loop
  195. call check_replay_skip
  196. jc mainloop
  197. call stabilise
  198. ; Sykes's super sexy screen saver
  199. ifdef with_screen_saver
  200. cmp [sssss_count],sssss_time
  201. jc no_save
  202. call halve_palette
  203. save_wait: cmp [sssss_count],sssss_time
  204. jnc save_wait
  205. call double_palette
  206. endif
  207. no_save: jmp mainloop
  208. _mainloop__Nv endp
  209. logic_engine proc
  210. mov eax,[logic_list_no] ;get correct logic list
  211. new_logic_list: fetch_compact edi
  212. logic_loop: movzx eax,wpt[edi]
  213. add edi,2
  214. jife ax,le_ret ;0 means end of list
  215. cmp ax,-1 ;0ffffh means change address
  216. jne not_ad_change
  217. ; Change logic data address
  218. mov ax,[edi]
  219. jmp new_logic_list
  220. ; Process id eax
  221. not_ad_change: mov [cur_id],eax
  222. fetch_compact
  223. ; check the id actually wishes to be processed
  224. bt (compact ptr[esi]).c_status,6
  225. jnc logic_loop
  226. ; ok, here we process the logic bit system
  227. push edi
  228. bt (compact ptr[esi]).c_status,7
  229. jnc no_grid_required
  230. call remove_object_from_walk
  231. no_grid_required: movzx eax,(compact ptr[esi]).c_logic
  232. call [offset logic_table+eax*4]
  233. bt (compact ptr [esi]).c_status,7
  234. jnc still_no_grid
  235. call object_to_walk
  236. still_no_grid: mov (compact ptr[esi]).c_sync,0 ;a sync sent to the compact
  237. ;is available for one cycle
  238. ;only. that cycle has just
  239. ;ended so remove the sync.
  240. ;presumably the mega has just
  241. ;reacted to it.
  242. pop edi
  243. jmp logic_loop ;on to the next one
  244. logic_engine endp
  245. le_ret: ;awaiting a proc
  246. return: ret ;a global return
  247. ;--------------------------------------------------------------------------------------------------
  248. logic_auto_route proc
  249. push esi ;save compact
  250. call auto_route
  251. mov edi,esi
  252. pop esi ;get compact back
  253. mov (cpt[esi]).c_logic,l_script ;continue the script
  254. cmp al,1 ;route succeeded?
  255. jne route_failed
  256. test wpt[edi],-1 ;zero route?
  257. je zero_route
  258. mov (cpt[esi]).c_grafix_prog,edi ;put graphic prog in
  259. mov (cpt[esi]).c_down_flag,0 ;route ok
  260. jmp logic_script
  261. route_failed: mov (cpt[esi]).c_down_flag,1 ;return fail to script
  262. jmp logic_script
  263. zero_route: mov (cpt[esi]).c_down_flag,2 ;return fail to script
  264. jmp logic_script
  265. logic_auto_route endp
  266. ;--------------------------------------------------------------------------------------------------
  267. logic_script proc
  268. ; si is the mega compact
  269. ; Process the current mega's script
  270. ; If the script finishes then drop back a level
  271. movzx ebx,(compact ptr [esi]).c_mode ;get pointer to current script
  272. mov eax,c_base_sub[ebx+esi] ;get script number and offset
  273. push ebx
  274. call script
  275. pop ebx
  276. mov c_base_sub[ebx+esi],eax ;save new offset
  277. test eax,0ffff0000h ;if script finished then drop off a mode
  278. je script_finish
  279. ; have we gone up a mode? if so then keep processing
  280. cmp bx,(cpt[esi]).c_mode
  281. je return
  282. jmp logic_script
  283. ; ok, drop the sub/mode down a level
  284. ; NB a base script that terminates must handle
  285. ; things itself( FN_idle ) otherwise script mode will
  286. ; continue and the results are unpredictable - presumably
  287. ; this only happens on player base scripts, so use FN_idle followed by FN_quit so script will never end
  288. script_finish: cherror (cpt[esi]).c_mode,e,0,em_internal_error
  289. sub (compact ptr[esi]).c_mode,4
  290. jmp logic_script
  291. logic_script endp
  292. logic_ar_anim proc
  293. ; Follow a route
  294. ; Mega should be in c_get_to_mode
  295. ; esi is compact
  296. test (cpt[esi]).c_xcood,7 ;only check collisions on character boundaries
  297. jne not_zero_zero
  298. test (cpt[esi]).c_ycood,7
  299. jne not_zero_zero
  300. ; On character boundary. Have we been told to wait?
  301. ; if not - are WE colliding?
  302. cmp (cpt[esi]).c_waiting_for,-1 ;1st cycle of re-route does
  303. je not_zero_zero ;not require collsion checks
  304. movzx eax,(cpt[esi]).c_waiting_for
  305. jife eax,not_enforced_stop
  306. ; ok, we've been told we've hit someone
  307. ; we will wait until we are no longer colliding
  308. ; with them. here we check to see if we are (still) colliding.
  309. ; if we are then run the stop script. if not clear the flag
  310. ; and continue.
  311. ; remember - this could be the first ar cycle for some time,
  312. ; we might have been told to wait months ago. if we are
  313. ; waiting for one person then another hits us then
  314. ; c_waiting_for will be replaced by the new mega - this is
  315. ; fine because the later collision will almost certainly
  316. ; take longer to clear than the earlier one.
  317. call collide
  318. je stop_and_wait
  319. ;***
  320. not_colliding: ;we are not in fact hitting this person so clr & continue
  321. ;it must have registered some time ago
  322. mov (cpt[esi]).c_waiting_for,0 ;clear id flag
  323. not_enforced_stop: ;ok, our turn to check for collisions
  324. mov eax,[logic_list_no]
  325. get_new_logic_list: fetch_compact ebx
  326. collision_loop: flodswl eax,ebx ;get an id
  327. jife ax,not_collision ;0 is list end
  328. cmp ax,-1 ;address change?
  329. jne not_skip_forward
  330. mov eax,[ebx] ;get new logic list
  331. jmp get_new_logic_list
  332. not_skip_forward: cmp ax,wpt[cur_id] ;is it us?
  333. je collision_loop
  334. mov [hit_id],eax ;save target id for any possible c_mini_bump
  335. fetch_compact edi ;let's have a closer look
  336. bt (cpt[edi]).c_status,st_collision_bit ;can it collide?
  337. jnc collision_loop
  338. mov dx,(cpt[edi]).c_screen ;is it on our screen?
  339. cmp dx,(cpt[esi]).c_screen
  340. jne collision_loop
  341. ; mov edx,[flag] ;save the id of target for
  342. ; mov edx,[cur_id] ;save the id of target for
  343. ; mov [hit_id],edx ;any possible c_mini_bump
  344. push ebx
  345. call collide_xx ;check for a hit
  346. pop ebx
  347. jifne eax,collision_loop
  348. ; ok, we've hit a mega
  349. ; is it moving... or something else?
  350. cmp (cpt[edi]).c_logic,l_ar_anim ;check for following route
  351. je moving_target
  352. ; it is doing something else
  353. ; we restart our get-to script
  354. ; first tell it to wait for us - in case it starts moving
  355. ; ( *it may have already hit us and stopped to wait )
  356. mov (cpt[esi]).c_waiting_for,-1 ;effect 1 cycle collision skip
  357. mov eax,[cur_id] ;tell it it is waiting for us
  358. mov (cpt[edi]).c_waiting_for,ax ;(if it's not already)
  359. movzx eax,(cpt[esi]).c_mode ;restart current script
  360. mov wpt c_base_sub+2[esi+eax],0
  361. mov (cpt[esi]).c_logic,l_script
  362. jmp logic_script ;do it right away
  363. moving_target: ;ok, the target is also following ar sequences
  364. ;we have the choice of what to do - wait or re-route
  365. movzx eax,(cpt[esi]).c_mini_bump
  366. jmp script
  367. ;************************
  368. not_collision: ;ok, there was no collisions
  369. ;now check for interaction request
  370. ;*note: the interaction is always set up as an action script
  371. test (cpt[esi]).c_request,-1 ;anything
  372. je check_at
  373. mov (cpt[esi]).c_mode,c_action_mode ;put into action mode
  374. movzx eax,(cpt[esi]).c_request
  375. mov (cpt[esi]).c_action_sub,eax
  376. mov (cpt[esi]).c_request,0 ;trash request
  377. mov (cpt[esi]).c_logic,l_script
  378. jmp logic_script
  379. check_at: ;any flag? - or any change?
  380. ;if change then re-run the current script, which must be
  381. ;a position independent get-to ----
  382. test (cpt[esi]).c_at_watch,-1 ;any flag set?
  383. je not_zero_zero
  384. ; ok, there is an at watch - see if it's changed
  385. movzx eax,(cpt[esi]).c_at_watch
  386. mov eax,[offset script_variables+eax]
  387. cmp ax,(cpt[esi]).c_at_was ;still the same?
  388. je not_zero_zero
  389. ; changed so restart the current script
  390. ; *not suitable for base initiated ARing
  391. movzx eax,(cpt[esi]).c_mode
  392. mov wpt c_base_sub+2[esi+eax],0
  393. mov (cpt[esi]).c_logic,l_script
  394. jmp logic_script
  395. not_zero_zero: ;Main animation code
  396. ; check 'at'
  397. ; if the 'at' flag changes then re-run the get-to script
  398. mov (cpt[esi]).c_waiting_for,0 ;clear possible zero-zero skip
  399. mov ebx,(cpt[esi]).c_grafix_prog
  400. test wpt[ebx],-1
  401. jne run_ar_anim
  402. ; ok, move to new anim segment
  403. add ebx,4
  404. test wpt[ebx],-1 ;end of route?
  405. jne not_end_of_ar
  406. ; ok, sequence has finished
  407. mov (cpt[esi]).c_ar_anim_index,0 ;will start afresh if new sequence continues in last direction
  408. mov (cpt[esi]).c_down_flag,0 ;pass back ok to script
  409. mov (cpt[esi]).c_logic,l_script
  410. jmp logic_script
  411. not_end_of_ar: ;ebx is sequence
  412. mov (cpt[esi]).c_grafix_prog,ebx
  413. mov (cpt[esi]).c_ar_anim_index,0 ;reset position
  414. run_ar_anim: movzx eax,(cpt[esi]).c_dir ;check direction
  415. cmp ax,[ebx+2]
  416. je no_turning
  417. ; ok, setup turning
  418. mov ax,[ebx+2]
  419. xchg ax,(cpt[esi]).c_dir
  420. mov cx,20
  421. mul cx ;5 tables, 5dwords
  422. add ax,(cpt[esi]).c_mega_set ;get correct set
  423. lea eax,(cpt[esi+eax]).c_turn_table_up
  424. movzx ecx,(cpt[esi]).c_dir
  425. mov eax,[eax+ecx*4]
  426. jife eax,run_ar_anim
  427. mov (cpt[esi]).c_turn_prog,eax ;c_grafix_prog already in use
  428. mov (cpt[esi]).c_logic,l_ar_turning
  429. jmp logic_ar_turn
  430. no_turning: shl eax,2
  431. add ax,(cpt[esi]).c_mega_set
  432. lea eax,(cpt[esi+eax]).c_anim_up
  433. mov edx,[eax]
  434. new_inner_cycle: movzx eax,(cpt[esi]).c_ar_anim_index
  435. test wpt[eax+edx],-1 ;restart the internal anim
  436. jne not_recycle
  437. clear eax
  438. mov (cpt[esi]).c_ar_anim_index,ax ;reset
  439. not_recycle: add (cpt[esi]).c_ar_anim_index,s_length
  440. mov cx,wpt [s_count+eax+edx] ;reduce the distance to travel
  441. sub [ebx],cx
  442. mov cx,wpt[s_frame+eax+edx] ;new graphic frame
  443. mov (cpt[esi]).c_frame,cx
  444. mov cx,wpt[s_ar_x+eax+edx] ;update x coordinate
  445. add (cpt[esi]).c_xcood,cx
  446. mov cx,wpt[s_ar_y+eax+edx] ;update y coordinate
  447. add (cpt[esi]).c_ycood,cx
  448. ret
  449. logic_ar_anim endp
  450. logic_ar_turn proc
  451. mov ebx,(cpt[esi]).c_turn_prog
  452. flodsws ax,ebx
  453. mov (cpt[esi]).c_frame,ax
  454. mov (cpt[esi]).c_turn_prog,ebx
  455. test wpt[ebx],-1 ;turn done?
  456. jne lat_ret
  457. ; Back to ar mode
  458. mov (cpt[esi]).c_ar_anim_index,0
  459. mov (cpt[esi]).c_logic,l_ar_anim
  460. lat_ret: ret
  461. logic_ar_turn endp
  462. collide proc
  463. ; are we touching this id S2(21Sep92tw) & (6Oct92tw)
  464. ; this is mega to mega
  465. ; this routine us customized for each direction a
  466. ; mega may be facing & it takes into account
  467. ; different sizes of mega chr$ - it is therefore very
  468. ; flexible
  469. ; 'It's also impossible to visualise how this works'
  470. ; esi is us
  471. ; eax is id to test against
  472. ; On return z=1 for collision
  473. fetch_compact edi
  474. collide_xx:: movzx ecx,(cpt[esi]).c_mega_set ;get correct set
  475. movzx edx,(cpt[edi]).c_mega_set ;get correct set
  476. mov ax,(cpt[edi]).c_xcood ;target's base coordinates
  477. and al,0f8h
  478. mov bx,(cpt[edi]).c_ycood
  479. and bl,0f8h
  480. ; The collision is direction dependant
  481. cmp (cpt[esi]).c_dir,1
  482. jc col_up
  483. je col_down
  484. cmp (cpt[esi]).c_dir,2
  485. je col_left
  486. ; Facing right
  487. cmp bx,(cpt[esi]).c_ycood ;y's must be the same
  488. jne no_collision
  489. sub ax,(cpt[esi+ecx]).c_last_chr ;last block
  490. cmp ax,(cpt[esi]).c_xcood
  491. je collision
  492. sub ax,8 ;out another block
  493. cmp ax,(cpt[esi]).c_xcood
  494. jne no_collision
  495. collision: clear eax
  496. ret
  497. col_left: ;look left
  498. cmp bx,(cpt[esi]).c_ycood ;y's must be the same
  499. jne no_collision
  500. add ax,(cpt[edi+edx]).c_last_chr
  501. cmp ax,(cpt[esi]).c_xcood
  502. je collision
  503. sub ax,8 ;out another one
  504. cmp ax,(cpt[esi]).c_xcood
  505. je collision
  506. no_collision: or al,1
  507. ret
  508. col_up: ;looking up
  509. sub ax,(cpt[esi+ecx]).c_col_offset ;compensate for inner x offsets
  510. add ax,(cpt[edi+edx]).c_col_offset
  511. push eax ;save their x
  512. add ax,(cpt[edi+edx]).c_col_width ;their rightmoast
  513. cmp ax,(cpt[esi]).c_xcood
  514. pop eax
  515. jc no_collision
  516. sub ax,(cpt[esi+ecx]).c_col_width ;our left, their right
  517. cmp ax,(cpt[esi]).c_xcood
  518. jnc no_collision
  519. ; What about y's
  520. add bx,8 ;bring them down a line
  521. cmp bx,(cpt[esi]).c_ycood
  522. je collision
  523. add bx,8 ;bring them down a line
  524. cmp bx,(cpt[esi]).c_ycood
  525. je collision
  526. or al,1 ;no collision
  527. ret
  528. col_down: ;down we are a going
  529. sub ax,(cpt[esi+ecx]).c_col_offset ;compensate for inner x offsets
  530. add ax,(cpt[edi+edx]).c_col_offset
  531. push eax ;save their x
  532. add ax,(cpt[edi+edx]).c_col_width ;their rightmoast
  533. cmp ax,(cpt[esi]).c_xcood
  534. pop eax
  535. jc no_collision
  536. sub ax,(cpt[esi+ecx]).c_col_width ;our left, their right
  537. cmp ax,(cpt[esi]).c_xcood
  538. jnc no_collision
  539. ; What about y's
  540. sub bx,8 ;bring them up a line
  541. cmp bx,(cpt[esi]).c_ycood
  542. je collision
  543. sub bx,8 ;bring them up a line
  544. cmp bx,(cpt[esi]).c_ycood
  545. je collision
  546. or al,1 ;no collision
  547. ret
  548. collide endp
  549. logic_turn proc
  550. ; Mega esi turns round and then returns to script mode
  551. mov ebx,(cpt[esi]).c_turn_prog
  552. flodsws ax,ebx
  553. jife ax,turn_to_script
  554. mov (cpt[esi]).c_frame,ax
  555. mov (cpt[esi]).c_turn_prog,ebx
  556. ret
  557. turn_to_script: mov (cpt[esi]).c_ar_anim_index,0
  558. mov (cpt[esi]).c_logic,l_script
  559. jmp logic_script
  560. logic_turn endp
  561. logic_frames proc
  562. ; follow an animation sequence S2(3Sep92tw)
  563. ; just frames - no coordinates
  564. ; returns to script when no more frames (NULL)
  565. ; returns to script when c_sync != 0
  566. ; esi is compact
  567. test (cpt[esi]).c_sync,-1 ;what?!
  568. jne return_to_script
  569. logic_frames endp
  570. ; NOWT IN HERE
  571. logic_simple_anim proc
  572. ; follow an animation sequence module
  573. ; whilst ignoring the coordinate data
  574. mov ebx,(cpt[esi]).c_grafix_prog
  575. inr_frm_loop: test wpt[ebx],-1 ;finished?
  576. jne run_simple_seq
  577. return_to_script:: mov (cpt[esi]).c_down_flag,0 ;return 'ok' to script
  578. mov (cpt[esi]).c_logic,l_script
  579. jmp logic_script
  580. run_simple_seq: flodsws ax,ebx ;get a command
  581. cmp ax,send_sync
  582. je frames_sync
  583. add ebx,2 ;skip coordinates (What??)
  584. flodsws ax,ebx ;get a frame
  585. mov (cpt[esi]).c_grafix_prog,ebx
  586. cmp ax,64
  587. jc need_item_offset
  588. mov (cpt[esi]).c_frame,ax
  589. ret
  590. need_item_offset: add ax,(cpt[esi]).c_offset
  591. mov (cpt[esi]).c_frame,ax
  592. ret
  593. frames_sync: flodsws ax,ebx ;get id to sync
  594. fetch_compact edi
  595. flodsws ax,ebx ;get sync
  596. mov (cpt[edi]).c_sync,ax
  597. jmp inr_frm_loop
  598. logic_simple_anim endp
  599. logic_anim proc
  600. ; Follow an animation sequence
  601. ; esi is compact
  602. mov edx,(cpt[esi]).c_grafix_prog
  603. inner_anim_loop: test wpt[edx],-1 ;all done?
  604. je seq_end
  605. flodsws ax,edx ;get a word
  606. cmp ax,lf_start_fx ;check for sync or fx
  607. je do_fx
  608. jnc do_sync
  609. mov (cpt[esi]).c_xcood,ax ;put coordinates and frame in
  610. flodsws ax,edx
  611. mov (cpt[esi]).c_ycood,ax
  612. flodsws ax,edx
  613. or ax,(cpt[esi]).c_offset
  614. mov (cpt[esi]).c_frame,ax
  615. mov (cpt[esi]).c_grafix_prog,edx
  616. ret
  617. ; run out of sequence data so return to script
  618. seq_end: mov (cpt[esi]).c_down_flag,0
  619. mov (cpt[esi]).c_logic,l_script
  620. jmp logic_script
  621. do_sync: flodsws ax,edx
  622. fetch_compact edi
  623. flodsws ax,edx
  624. mov (cpt[edi]).c_sync,ax
  625. jmp inner_anim_loop
  626. do_fx: flodswl eax,edx ;get fx number
  627. flodswl ecx,edx ;volume
  628. push esi
  629. push edx
  630. clear ebx ;channel 0
  631. call fn_start_fx
  632. pop edx
  633. pop esi
  634. jmp inner_anim_loop
  635. logic_anim endp
  636. logic_wait_sync proc
  637. ; checks c_sync, when its non 0
  638. ; the id is put back into script mode
  639. ; use this instead of loops in the script
  640. test (cpt[esi]).c_sync,-1
  641. je return
  642. mov (cpt[esi]).c_logic,l_script
  643. jmp logic_script
  644. logic_wait_sync endp
  645. logic_pause proc
  646. ; keeps decrementing c_flag until it is 0 S2(5Nov92tw)
  647. ; then it restarts script processing
  648. ; I've done this to save the bother of doing
  649. ; little loops everywhere in the scripts
  650. sub (cpt[esi]).c_flag,1
  651. jne return
  652. mov (cpt[esi]).c_logic,l_script
  653. jmp logic_script
  654. logic_pause endp
  655. logic_listen proc
  656. ; Stay in this mode until id in c_get_to_flag leaves l_talk mode
  657. mov ax,(cpt[esi]).c_flag
  658. fetch_compact edi
  659. cmp (cpt[edi]).c_logic,l_talk
  660. je return
  661. mov (cpt[esi]).c_logic,l_script
  662. jmp logic_script
  663. logic_listen endp
  664. logic_talk proc
  665. ; first count through the frames
  666. ; just frames - nothing tweeky
  667. ; the speech finishes when the timer runs out &
  668. ; not when the animation finishes
  669. ; this routine is very task specific
  670. ; Check for mouse clicking
  671. call check_replay_skip
  672. jnc no_kill_speech
  673. bt [system_flags],sf_voc_playing
  674. jc kill_speech
  675. no_kill_speech:
  676. ifdef clicking_optional
  677. test [_allow_clicking],-1
  678. je cant_click
  679. endif
  680. test [mouse_b],-1
  681. je release_button
  682. test [logic_talk_button_release],-1
  683. jne cant_click
  684. mov [logic_talk_button_release],1
  685. ; Are we allowed to click
  686. mov eax,[cur_id]
  687. mov ebx,offset click_table
  688. lt_click_check: cmp wpt[ebx],-1
  689. je cant_click
  690. cmp ax,[ebx]
  691. je found_us
  692. lea ebx,2[ebx]
  693. jmp lt_click_check
  694. found_us: cmp (cpt[esi]).c_sp_text_id,-1 ;is this a voc file?
  695. je kill_speech
  696. test (cpt[esi]).c_grafix_prog,-1 ;if no anim file just kill text
  697. je text_die
  698. mov ax,(cpt[esi]).c_get_to_flag ;if anim flag stop it
  699. mov (cpt[esi]).c_frame,ax
  700. jmp text_die
  701. release_button:
  702. cant_click: ;If speech is allowed then check for it to finish before finishing animations
  703. bt [system_flags],sf_play_vocs ;sblaster?
  704. jnc no_speech
  705. cmp (cpt[esi]).c_sp_text_id,-1 ;is this a voc file?
  706. jne no_speech
  707. bt [system_flags],sf_voc_playing ;finished?
  708. jc no_speech ;play anim until it is
  709. speech_die: mov (cpt[esi]).c_logic,l_script ;restart character control
  710. test (cpt[esi]).c_grafix_prog,-1 ;if no anim file then no stand info
  711. je logic_script
  712. movzx eax,(cpt[esi]).c_get_to_flag ;set character to stand
  713. mov (cpt[esi]).c_frame,ax
  714. mov (cpt[esi]).c_grafix_prog,0
  715. ; push esi
  716. ; call restore_saved_effects_0
  717. ; pop esi
  718. jmp logic_script
  719. kill_speech: push esi
  720. call fn_stop_voc
  721. pop esi
  722. jmp speech_die
  723. no_speech: mov ebx,(cpt[esi]).c_grafix_prog ;no anim file?
  724. jife ebx,past_speech_anim
  725. test wpt[ebx],-1 ;run out of frames
  726. je clean_up_speech
  727. ; we will force the animation to finish 3 game cycles
  728. ; before the speech actually finishes - because it looks good.
  729. cmp (cpt[esi]).c_sp_time,3
  730. jne not_time_to_stop
  731. bt [system_flags],sf_voc_playing ;finished?
  732. jc speech_wait ;play anim until it is
  733. ; set up the standing - this code is taken from FN_set_to_stand
  734. clean_up_speech: movzx eax,(cpt[esi]).c_get_to_flag
  735. mov (cpt[esi]).c_frame,ax
  736. mov (cpt[esi]).c_grafix_prog,0
  737. jmp past_speech_anim
  738. not_time_to_stop: movzx eax,wpt 4[ebx]
  739. add ax,(cpt[esi]).c_offset
  740. mov (cpt[esi]).c_frame,ax
  741. add ebx,6
  742. mov (cpt[esi]).c_grafix_prog,ebx
  743. past_speech_anim: sub (cpt[esi]).c_sp_time,1
  744. jne return
  745. ; ok, speech has finished
  746. bt [system_flags],sf_voc_playing ;finished?
  747. jc speech_wait ;play anim until it is
  748. text_die: mov ax,(cpt[esi]).c_sp_text_id ;get text id to kill
  749. jife ax,no_text ;only kill text if it existed
  750. fetch_compact edi
  751. mov (cpt[edi]).c_status,0 ;kill the text
  752. no_text: mov (cpt[esi]).c_logic,l_script
  753. jmp logic_script
  754. speech_wait: add (cpt[esi]).c_sp_time,1
  755. ret
  756. logic_talk endp
  757. logic_alt proc
  758. ; change the current script S2(7Sep92tw)
  759. ; we do it this way because the alternate script
  760. ; is initiated by a script - but a script can't change
  761. ; itself to another script & keep running in the same cycle
  762. mov (cpt[esi]).c_logic,l_script
  763. movzx ebx,(cpt[esi]).c_mode
  764. movzx edx,(cpt[esi]).c_alt
  765. mov c_base_sub[esi+ebx],edx
  766. jmp logic_script
  767. logic_alt endp
  768. logic_stopped proc
  769. ; waiting for another mega to move or give-up trying
  770. ; c_waiting_for is target S2(21Sep92tw)
  771. ; check also for idle - if the players re-routing but
  772. ; actually has no further to go then he'll drop down to idle
  773. ; this mode will always be set up from a special script
  774. ; that will be one level higher than the script we
  775. ; would wish to restart from
  776. movzx eax,(cpt[esi]).c_waiting_for
  777. fetch_compact edi
  778. test (cpt[edi]).c_mood,-1
  779. jne we_are_free
  780. call collide_xx
  781. je return
  782. we_are_free: ;we are free, continue processing the script
  783. ; we are currently one layer above the script which
  784. ; needs to be restarted - the current stop script
  785. ; should continue to its natural conclusion & drop
  786. ; down to the script below - which will restart
  787. ; *the only reason so far for continuing with the
  788. ; stop script is that the players (std_player_stop)
  789. ; script needs to add the mouse buttons back again
  790. movzx eax,(cpt[esi]).c_mode
  791. sub eax,4
  792. mov wpt c_base_sub+2[esi+eax],0
  793. mov (cpt[esi]).c_waiting_for,-1 ;ignore first zero zero
  794. mov (cpt[esi]).c_logic,l_script
  795. jmp logic_script
  796. logic_stopped endp
  797. logic_choose proc
  798. ; Remain in this mode until player selects some text
  799. test [the_chosen_one],-1
  800. je return
  801. call fn_no_human ;kill mouse again
  802. btr [system_flags],sf_choosing ;restore save/restore
  803. mov (cpt[esi]).c_logic,l_script ;and continue script
  804. jmp logic_script
  805. logic_choose endp
  806. end32code
  807. end
  808.