source: abuse-frabs/trunk/lisp/ant.lsp @ 44

Last change on this file since 44 was 44, checked in by Sam Hocevar, 15 years ago
  • Importing abuse-frabs 2.10.
File size: 17.1 KB
Line 
1;; Copyright 1995 Crack dot Com,  All Rights reserved
2;; See licensing information for more details on usage rights
3
4(setq ant_tints (make-array 13 :initial-contents (list
5                                                (def_tint "art/tints/ant/green.spe")
6                                                (def_tint "art/tints/ant/blue.spe")
7                                                (def_tint "art/tints/ant/brown.spe")
8                                                (def_tint "art/tints/ant/egg.spe")
9                                                (def_tint "art/tints/ant/yellow.spe")
10                                                (def_tint "art/tints/ant/mustard.spe")
11                                                (def_tint "art/tints/ant/orange.spe")
12                                                (def_tint "art/tints/ant/gray.spe")
13                                                (def_tint "art/tints/guns/green.spe")
14                                              (def_tint "art/tints/ant/darkblue.spe")
15                                                normal_tint
16                                                normal_tint
17                                                normal_tint
18                                                )))
19
20/*
21------ this code has been compiled --------
22(defun no_fall_move (xm ym but)
23  (move xm ym but))
24  (if (not (eq (gravity) 0))         ;; if we are in the air don't check for no fall
25      (move xm ym but)
26    (let ((oldx (x))
27          (oldy (y))
28          (ret (move xm ym but)))
29      (if (try_move 0 5)
30          (progn
31            (set_x oldx)
32            (set_y oldy)
33            (set_xacel 0)
34            (set_state stopped)
35            (set_xv 0)
36            (set_gravity 0)
37            0)
38        ret))))
39           
40     
41(defun will_fall_if_jump ()
42  nil)
43  (let ((dist (* (abs (get_ability jump_yvel)) (get_ability jump_xvel)))
44        (oldx (x))
45        (oldy (y))
46        )
47    (if (> (direction) 0)
48        (set_x (+ (x) dist))
49      (set_x (- (x) dist)))
50    (if (try_move 0 5)
51        (progn
52          (set_x oldx)
53          (set_y oldy)
54          T)
55      (progn
56        (set_x oldx)
57          (set_y oldy)
58        nil))))
59^^^^^^ this code has been compiled ^^^^^^^^
60*/
61
62
63(defun strait_rocket_ai ()
64  (set_course (aistate)
65              (select difficulty
66                      ('easy    12)
67                      ('medium  15)
68                      ('hard    17)
69                      ('extreme 22) ))
70  (set_frame_angle 0 359 (aistate))
71  (let ((stat (bmove nil)))
72    (if (eq stat T)
73        T
74    (progn
75      (if (not (eq stat nil))
76          (progn
77            (add_object EXPLODE3 (+ (x) (random 5)) (+ (y) (random 5)) 0)
78            (add_object EXPLODE2 (+ (x) (random 5)) (+ (y) (random 5)) 2)
79            (add_object EXPLODE3 (- (x) (random 5)) (- (y) (random 5)) 1)
80            (add_object EXPLODE3 (- (x) (random 5)) (- (y) (random 5)) 2)
81            (hurt_radius (x) (+ (y) 20) 25 15 nil 10)
82            )
83        (let ((myself (me)))
84          (with_object (add_object EG_EXPLO (x) (y)) (user_fun myself (car stat)))))
85      nil))))
86   
87
88(def_char STRAIT_ROCKET
89  (funs (ai_fun strait_rocket_ai))
90  (range 10000 10000)
91  (flags (unlistable T))
92  (states "art/missle.spe" (stopped    (seq "b32r" 1 32))))
93
94(defun animate_ai () (next_picture))
95
96(defun eg_explo_ufun (creator block_flags)
97  (set_direction (with_object creator (direction)))
98  (if block_flags
99      (if (or (blocked_left block_flags) (blocked_right block_flags))
100          (set_state blocking))))
101         
102(def_char EG_EXPLO
103  (funs (ai_fun   animate_ai)
104        (user_fun eg_explo_ufun))
105  (range 10000 10000)
106  (flags (unlistable T))
107  (states "art/missle.spe"
108          (stopped  (seq "bifl" 1 4))
109          (blocking (seq "bilw" 1 4))))
110
111/*
112------ this code has been compiled --------
113(defun alien_wait_time ()
114  (select difficulty
115          ('easy    6)
116          ('medium  4)
117          ('hard    2)
118          ('extreme 1)))
119
120(defun can_hit_player ()
121  (let ((firex (+ (x) (* (direction) 15)) )
122        (firey (- (y) 15))
123        (playerx (with_object (bg) (x)))
124        (playery (- (with_object (bg) (y)) 15)))
125    (can_see firex firey playerx playery nil)))
126
127(defun not_ant_congestion ()
128  (if (> (direction) 0)
129      (if (find_object_in_area (+ (x) 23) (- (y) 20) (+ (x) 30) (+ (y) 20) (list ANT_ROOF))
130          nil
131        T)
132    (if (find_object_in_area (- (x) 30) (- (y) 20) (- (x) 23) (+ (y) 20) (list ANT_ROOF))
133        nil
134      T)))
135     
136     
137(defun roof_above () (not (can_see (x) (y) (x) (- (y) 120) nil)))
138
139(defun fire_at_player ()
140  (let ((firex (+ (x) (* (direction) 15)) )
141        (firey (- (y) 15))
142        (playerx (+ (with_object (bg) (x)) (with_object (bg) (* (xvel) 8))))
143        (playery (+ (- (with_object (bg) (y)) 15) (with_object (bg) (* (yvel) 2)))))
144   
145    (if (and (can_see (x) (y) firex firey nil) (can_see firex firey playerx playery nil))
146        (progn
147          (let ((angle (atan2 (- firey playery)
148                              (- playerx firex))))
149            (fire_object (me) (aitype) firex firey angle (bg))
150            (set_state weapon_fire))
151
152          ))))
153
154(defun ant_dodge ()
155  (if (eq need_to_dodge 1)
156      (progn
157        (setq need_to_dodge 0)
158        (if (eq (random 2) 1)
159            (progn
160              (set_state stopped)
161              (go_state 6))         ;; jump at player
162          (if (roof_above)
163              (progn                   
164                (set_yvel -17)  ;; jump up 
165                (set_xvel 0)
166                (go_state 12))
167            (progn
168              (set_yvel -12)  ;; long jump
169              (set_xvel (* (direction) 20))
170              (set_aistate 6))))
171        T
172    nil)))
173
174(defun scream_check ()
175  (if (can_see (x) (y) (with_object (bg) (x)) (with_object (bg) (y)) nil)
176      (progn
177        (if (or (eq no_see_time 0) (> no_see_time 20))
178          (play_sound ASCREAM_SND 127 (x) (y)))
179        (setq no_see_time 1))
180    (setq no_see_time (+ no_see_time 1))))
181
182(defun ant_ai ()
183      (push_char 30 20)
184      (if (or (eq (state) flinch_up) (eq (state) flinch_down))
185          (progn (next_picture) T)
186        (progn
187
188          (select (aistate)
189                  (0   (set_state hanging)
190                       (if (eq hide_flag 0)
191                           (set_aistate 15)
192                         (set_aistate 16)))
193
194                  (15 ;; hanging on the roof waiting for the main character               
195                   (if (next_picture) T (set_state hanging))
196                   (if (if (eq (total_objects) 0);; no sensor, wait for guy
197                           (and (< (distx) 130) (< (y) (with_object (bg) (y))))
198                         (not (eq (with_object (get_object 0) (aistate)) 0)))
199                       (progn
200                         (set_state fall_start)                  (set_direction (toward))
201                         (set_aistate 1))))
202
203                  (16 ;; hiding
204                   (set_state hiding)
205                   (if (if (eq (total_objects) 0);; no sensor, wait for guy
206                           (and (< (distx) 130) (< (y) (with_object (bg) (y))))
207                         (not (eq (with_object (get_object 0) (aistate)) 0)))
208                       (progn
209                         (set_state fall_start)                  (set_direction (toward))
210                         (set_aistate 1))))
211
212                  (1 ;; falling down
213                   (set_state falling)
214                   (scream_check)
215                   (if (blocked_down (move 0 0 0))
216                       (progn
217                         (set_state landing)
218                         (play_sound ALAND_SND 127 (x) (y))
219                         (set_aistate 9))))
220
221                  (9 ;; landing / turn around (gerneal finish animation state)
222                   (if (next_picture) T
223                     (if (try_move 0 2)
224                         (progn
225                           (set_gravity 1)
226                           (set_aistate 1))
227                       (progn (set_state stopped)                         
228                              (go_state 2)))))  ;; running
229
230                  (2 ;; running
231                   (scream_check)
232                   (if (eq (random 20) 0) (setq need_to_dodge 1))
233                   (if (not (ant_dodge))
234                     (if (eq (facing) (toward))
235                         (progn
236                           (next_picture)
237                           (if (and (eq (random 5) 0) (< (distx) 180) (< (disty) 100) (can_hit_player))
238                               (progn
239                                 (set_state weapon_fire)
240                                 (set_aistate 8))  ;; fire at player
241                             (if (and (< (distx) 100) (> (distx) 10) (eq (random 5) 0))
242                                 (set_aistate 4)  ;; wait for pounce
243
244                               (if (and (> (distx) 140)
245                                        (not_ant_congestion)
246                                        (not (will_fall_if_jump)))
247                                   (set_aistate 6)
248
249                                 (if (> (direction) 0)
250                                     (if (and (not_ant_congestion) (blocked_right (no_fall_move 1 0 0)))
251                                         (set_direction -1))
252                                   (if (and (not_ant_congestion) (blocked_left (no_fall_move -1 0 0)))
253                                       (set_direction 1)))))))
254                           (progn
255                             (set_direction (toward))
256                             (set_state turn_around)
257                             (set_aistate 9)))))
258             
259                  (4 ;; wait for pounce
260                   (if (ant_dodge) T
261                     (progn
262                       (set_state pounce_wait)
263                       (move 0 0 0)
264                       (if (> (state_time) (alien_wait_time))
265                           (progn
266                             (play_sound ASLASH_SND 127 (x) (y))
267                             (set_state stopped)
268                             (go_state 6))))))
269
270                  (6 ;; jump             
271                   (setq need_to_dodge 0)
272                   (if (blocked_down (move (direction) -1 0))
273                       (progn
274                         (set_aistate 2))))
275
276                  (8 ;; fire at player
277                   (if (ant_dodge) T                 
278                     (if (eq (state) fire_wait)
279                         (if (next_picture)
280                             T
281                           (progn
282                             (fire_at_player)
283                             (set_state stopped)
284                             (set_aistate 2)))
285                       (set_state fire_wait))))
286
287                  (12 ;; jump to roof
288                   (setq need_to_dodge 0)
289                   (set_state jump_up)
290                   (set_yvel (+ (yvel) 1))
291                   (set_xacel 0)
292                   (let ((top (- (y) 31))
293                         (old_yvel (yvel))
294                         (new_top (+ (- (y) 31) (yvel))))
295                     (let ((y2 (car (cdr (see_dist (x) top (x) new_top)))))
296                       (try_move 0 (- y2 top) nil)
297                       (if (not (eq y2 new_top))
298                           (if (> old_yvel 0)
299                             (progn
300                               (set_state stopped)
301                               (set_aistate 2))
302                           (progn
303                             (set_state top_walk)
304                             (set_aistate 13)))))))
305
306                  (13 ;; roof walking
307                   (scream_check)
308                   (if (or (and (< (y) (with_object (bg) (y)))
309                                (< (distx) 10) (eq (random 8) 0))
310                           (eq need_to_dodge 1))  ;; shooting at us, fall down
311                       (progn
312                         (set_gravity 1)
313                         (set_state run_jump)
314                         (go_state 6))
315                     (progn
316                       (if (not (eq (facing) (toward)))        ;; run toward player
317                           (set_direction (- 0 (direction))))
318                       (if (and (< (distx) 120) (eq (random 5) 0))
319                           (progn
320                             (set_state ceil_fire)
321                             (go_state 14))
322                         (let ((xspeed (if (> (direction) 0) (get_ability run_top_speed)
323                                         (- 0 (get_ability run_top_speed)))))
324                           (if (and (can_see (x) (- (y) 31) (+ (x) xspeed) (- (y) 31) nil)
325                                    (not (can_see (+ (x) xspeed) (- (y) 31)
326                                                  (+ (x) xspeed) (- (y) 32) nil)))
327                               (progn
328                                 (set_x (+ (x) xspeed))
329                                 (if (not (next_picture))
330                                     (set_state top_walk)))
331                             (set_aistate 1)))))))
332
333       
334                  (14 ;; cieling shoot
335                   (if (next_picture)
336                       T
337                     (progn
338                       (fire_at_player)
339                       (set_state top_walk)
340                       (set_aistate 13))))
341
342                  )))
343     
344      T)
345*/   
346
347
348(defun create_dead_parts (array part_num type)
349  (let ((dir  (direction))
350        (rand (rand_on)))
351    (with_object (add_object (aref array part_num) (x) (y))
352               (progn (set_aitype type)
353                      (set_xvel (* dir (random 10)))
354                      (set_yvel (- 0 (random 25)))))
355    (with_object (add_object (aref array (+ part_num 1)) (x) (y))
356               (progn (set_aitype type)
357                      (set_xvel (* dir (random 10)))
358                      (set_yvel (- 0 (random 25)))))
359    (with_object (add_object (aref array (+ part_num 2)) (x) (y))
360               (progn (set_aitype type)
361                      (next_picture)                        ;; unsync the animations
362                      (set_xvel (* dir (random 10)))
363                      (set_yvel (- 0 (random 25)))))
364    (with_object (add_object (aref array (+ part_num 2)) (x) (y))
365               (progn (set_aitype type)
366                      (next_picture)
367                      (next_picture)
368                      (set_xvel (* dir (random 10)))
369                      (set_yvel (- 0 (random 25)))))
370    (with_object (add_object (aref array (+ part_num 2)) (x) (y))
371               (progn (set_aitype type)
372                      (next_picture)
373                      (next_picture)
374                      (next_picture)
375                      (set_xvel (* dir (random 10)))
376                      (set_yvel (- 0 (random 25)))))
377    (set_rand_on rand)))   ;; restore random table, in case this didn't get called because of frame panic
378
379
380(enum 'decay_part
381      'flaming_part
382      'electric_part
383      'normal_part)
384     
385(defun get_dead_part (from)
386  (if from
387      (let ((type (with_object from (otype))))
388        (if (or (eq type GRENADE) (eq type ROCKET) (eq type FIREBOMB))
389            flaming_part
390          (if (or (eq type PLASMAGUN_BULLET) (eq type LSABER_BULLET))
391              electric_part
392            normal_part)))
393    normal_part)
394
395)
396
397
398(defun ant_damage (amount from hitx hity push_xvel push_yvel)  ; transfer damage to lower half
399
400  (if (and (not (eq (state) dead))
401           (or (not from)
402               (with_object from (if (eq (total_objects) 0)
403                                     (not (eq (otype) ANT_ROOF))
404                                   (with_object (get_object 0) (not (eq (otype) ANT_ROOF)))))))
405      (if (not (eq (aistate) 15))
406          (progn
407            (if (eq (random 2) 0)
408                (set_state flinch_up)
409              (set_state flinch_down))
410            (damage_fun amount from hitx hity push_xvel push_yvel)
411            (play_sound APAIN_SND 127 (x) (y))
412            (setq need_to_dodge 1)         
413            (if (<= (hp) 0)
414                (progn
415                  (if (eq (aitype) 0)
416                      (play_sound (aref ASML_DEATH (random 2)) 127 (x) (y))
417                    (play_sound (aref ALRG_DEATH (random 3)) 127 (x) (y)))
418
419                  (set_state dead)
420                  (if (eq (random (select difficulty
421                                          ('easy 2)
422                                          ('medium 5)
423                                          ('hard   8)
424                                          ('extreme 20))) 0)
425                      (if (eq (random 4) 0)
426                          (add_object (aitype_to_ammo (+ (aitype) 1)) (x) (y)))
427                    (add_object (aitype_to_ammo (aitype)) (x) (y)))
428                  (create_dead_parts ant_dead_parts (* (get_dead_part from) 3) (aitype)))
429                  )))))
430
431(defun ant_cons ()
432  (set_state hanging)
433  (setq no_see_time 300))
434
435(defun ant_ct ()
436  (select (aitype)
437          (0 (set_hp 15))
438          (1 (set_hp 50))
439          (2 (set_hp 25))
440          (3 (set_hp 35))
441          (4 (set_hp 35))
442          (5 (set_hp 20))
443
444          ))
445
446
447(defun ant_draw ()
448  (if (eq 0 (aitype))
449      (draw)
450    (draw_tint (aref ant_tints (aitype)))))
451
452(def_char ANT_ROOF
453  (vars need_to_dodge
454        no_see_time
455        hide_flag)
456  (fields
457          ("hide_flag"    ant_hide)
458          ("fade_count"   ai_fade)
459          ("aitype"       ai_type)
460          ("hp"           ai_health)
461          ("aistate"      ai_state))
462  (range 250 20)
463  (draw_range 40 40)
464  (funs (ai_fun     ant_ai)     
465        (draw_fun   ant_draw)
466        (constructor ant_cons)
467        (type_change_fun ant_ct)
468        (get_cache_list_fun ant_cache)
469        (damage_fun ant_damage))
470
471  (abilities (run_top_speed   7)
472             (start_hp       20)
473             (stop_acel      20)
474             (start_acel     20)
475             (jump_yvel      -4)
476             (jump_xvel      20)
477             (push_xrange     1)
478             (jump_top_speed 20))
479 
480  (flags (hurtable  T)
481         (force_health T))
482
483  (states "art/ant.spe"
484          (hanging (rep "ant" 2))
485
486          (fall_start "affc0001.pcx")
487          (falling    "affc0002.pcx")
488         
489          (stopped "awlk0001.pcx")
490          (running (seq "awlk" 1 10))
491          (landing (seq "acff" 1 4))
492          (pounce_wait "acff0001.pcx")
493          (turn_around (seq "atrn" 1 5))
494
495          (run_jump "dive")
496          (run_jump_fall "dive")
497          (start_run_jump "dive")
498          (fire_wait (seq "wait" 1 3))
499
500          (ceil_fire (seq "cfire" 1 3))
501          (top_walk  (seq "awkc" 1 10))
502          (flinch_up (rep "afh10001.pcx" 2))
503          (flinch_down (rep "afh20001.pcx" 2))
504          (blown_back_dead     "adib0009.pcx")
505          (jump_up            "ajmp.pcx")
506          (hiding             "hidden")
507          (dead             "hidden")
508          (weapon_fire  (seq "asht" 2 5))))
509
510
511(def_char HIDDEN_ANT
512  (funs (ai_fun     ant_ai)
513        (draw_fun   dev_draw))
514  (flags (unlistable T))
515  (vars need_to_dodge
516        no_see_time
517        hide_flag)
518  (states "art/ant.spe" (stopped "hidden")))
519
520 
521
522
523(defun crack_ai ()
524  (if (eq (aistate) 0)
525      (if (if (eq (total_objects) 0)
526              (and (< (distx) 50) (< (disty) 70))
527            (with_object (get_object 0) (not (eq (aistate) 0))))
528          (set_aistate 1))
529    (select (current_frame)
530            (4 nil)
531            (3
532             (let ((d (direction))
533                   (type (aitype)))
534               (if (or (eq create_total 0) (eq create_total 1))           
535                   (set_current_frame 4)
536                 (progn
537                   (setq create_total (- create_total 1))
538                   (set_current_frame 0)))
539               (with_object (add_object_after ANT_ROOF (+ (x) (* (direction) 20)) (y))
540                            (progn
541                              (set_aitype type)
542                              (set_direction d)
543                              (set_xvel (* d 20))
544                              (set_state run_jump)
545                              (set_aistate 6)))
546               ))
547            (0 (next_picture))
548            (1 (next_picture))
549            (2 (next_picture))))
550  T)
551           
552
553(defun crack_cons ()
554  (setq create_total 1)
555  (set_aitype 1))
556
557
558(def_char ANT_CRACK
559  (funs (ai_fun crack_ai)
560        (draw_fun ant_draw)
561        (get_cache_list_fun ant_cache)
562        (constructor crack_cons))
563  (range 250 0)
564  (vars create_total)
565  (fields ("create_total"  ant_total)
566          ("aitype"        ant_type))
567  (states "art/ant.spe"
568          (stopped (seq "aisw" 2 6))))
569
570
571(defun head_ai ()
572  (select (aistate)
573          (0 ;; falling
574           (next_picture)
575           (set_yvel (+ (yvel) 3))
576           (bounce_move T T T '(progn (set_state dieing) (set_aistate 1)) T)
577           (or (< (state_time) 15)
578               (not (frame_panic))))         
579          (1 ;; hit the ground
580           nil)
581          ))
582
583(setq ant_dead_parts (make-array (* 3 4) :initial-contents
584                             '((AD_1  "adbn") (AD_2  "adha") (AD_3  "adla")     ; disapear
585                               (AD_4  "adaf") (AD_5  "adah") (AD_6  "adlf")     ; flaming
586                               (AD_7  "adbe") (AD_8  "adhe") (AD_9  "adle")     ; electrical
587                               (AD_10 "adan") (AD_11 "adhn") (AD_12 "adln"))))  ; normal
588
589
590(defun ant_cache (type)  ;; cache in the ant (from crack) and the dead body parts and the ant tints
591  (list
592   (list ANT_ROOF AD_1 AD_2 AD_3 AD_4 AD_5 AD_6 AD_7 AD_8 AD_9 AD_10 AD_11 AD_12)
593   (list (aref ant_tints 0) (aref ant_tints 1) (aref ant_tints 2) (aref ant_tints 3)
594         (aref ant_tints 4) (aref ant_tints 5) (aref ant_tints 6) (aref ant_tints 7)
595         (aref ant_tints 8) (aref ant_tints 9) (aref ant_tints 10)  )))
596
597
598
599(defun make_dead_part (sym base frames filename draw)
600  (eval `(def_char ,sym
601           (range 100 100)
602           (funs (ai_fun    head_ai)
603                 (draw_fun  ,draw))
604           (flags (unlistable T)
605                  (add_front T))
606           (states filename
607                  (stopped (seq base 1 ,frames))))))
608
609
610(do ((i 0 (setq i (+ i 1))))
611           ((>= i 12) nil)
612           (setq (aref ant_dead_parts i)
613                 (make_dead_part (car (aref ant_dead_parts i))
614                                 (car (cdr (aref ant_dead_parts i))) 4 "art/ant.spe" 'ant_draw)))
615
616
617(setq load_warn nil)
618(if (not (load "register/ant.lsp"))
619    (setq BOSS_ANT ANT_ROOF))
620(setq load_warn T)
621
622
623
Note: See TracBrowser for help on using the repository browser.