source: abuse/trunk/data-abuse/lisp/ant.lsp @ 586

Last change on this file since 586 was 582, checked in by Sam Hocevar, 12 years ago

data: remove \r and trailing spaces and tabs from all Lisp sources.

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