source: abuse/trunk/data/lisp/weapons.lsp @ 651

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

data: merge registered data into the main data directory.

File size: 16.6 KB
Line 
1;; Copyright 1995 Crack dot Com,  All Rights reserved
2;; See licensing information for more details on usage rights
3
4
5(defun mbullet_ai ()
6  (if (> (state_time) 5)
7      nil
8    (let ((bx (bmove (if (> (total_objects) 0) (get_object 0) nil))))  ; don't hit the guy who fired us.
9      (if (eq bx T)
10          T
11        (progn
12          (if (null bx)
13              (if (eq (random 2) 0)
14                  (progn
15                    (add_panim MGUN_HIT1 (x) (y) (direction))
16                    (play_sound MG_HIT_SND1 127 (x) (y)))
17                (progn
18                  (add_panim MGUN_HIT2 (x) (y) (direction))
19                  (play_sound MG_HIT_SND2 127 (x) (y))))
20            (progn
21;             (add_panim EXPLO2 (x) (y) (direction))
22;             (add_object EXP_LIGHT (x) (y) 80)
23              (do_damage 5 bx (if (> 0 (direction)) -10 10) 0)
24              ))
25          nil))))
26)
27
28(defun grenade_ai ()
29  (if (and (eq (tick) 0)
30           (if (< (total_objects) 1)
31               nil
32             (let ((mex (x))
33                   (mey (y)))
34               (not (with_object (get_object 0) (find_object_in_area (- mex 7)
35                                                                     (- mey 7)
36                                                                     (+ mex 7)
37                                                                     (+ mey 7) bad_guy_list))))))
38      (progn (next_picture) T)
39    (do_explo 40 36)))
40
41(defun fb_draw () nil)   ;; only draw while in the air
42
43(defun firebomb_ai ()
44
45  (add_object EXPLODE1 (- (x) (random 5)) (+ (y) (random 20)) 0)
46  (hurt_radius (x) (y) 60 40 (if (> (total_objects) 0) (get_object 0) nil) 10)
47
48  (and (or (< (state_time) 3) (not (eq (xvel) 0)))
49       (< (state_time) 20)
50       (select (direction)
51              (1 (progn ;(set_xvel 30)
52                        (not (blocked_right (move 0 0 0)))
53                        ))
54              (-1 (progn ;(set_xvel -30)
55                         (not (blocked_left (move 0 0 0))))))))
56
57
58
59
60
61(defun mbullet_ufun (creator)
62  (set_direction (with_object creator (direction)))
63
64  (let ((start (if (> (direction) 0) 335 155))
65        (end   (if (> (direction) 0) 25 205)))
66    (let ((target (with_object creator (find_object_in_angle start end bad_guy_list))))
67      (if (and target (< (abs (- (x) (with_object target (x)))) 150)
68               (< (abs (- (y) (with_object target (y)))) 100))
69          (set_course (site_angle target) 50)
70        (if (> (direction) 0)
71            (set_course 0 50)
72          (set_course 180 50)))))
73
74  (link_object creator)
75)
76
77
78(defun firebomb_ufun (creator)
79  (set_direction (with_object creator (direction)))
80  (link_object creator)
81)
82
83
84
85(defun player_mine_ufun (creator)
86  (set_x (with_object creator (x)))
87  (set_y (with_object creator (y)))
88  (link_object creator)
89  (let ((me (me)))
90    (with_object creator (link_object me)))
91)
92
93(defun player_mine_ai ()
94  (select (aistate)
95          (0
96           ;; wait till no player (just in case), or player lets go of fire button
97           (if (or (eq 0 (total_objects))
98                   (and (eq (with_object (get_object 0) (player_b1_suggest)) 0)
99                        (eq (with_object (get_object 0) (player_b2_suggest)) 0)))
100               (progn
101                 (set_state blocking)
102                 (set_aistate 1)
103                 T)
104             T))
105          (1 (if (next_picture)
106                 T
107               (do_explo 50 40)
108             ))))
109
110
111(def_char MBULLET
112  (funs (ai_fun     mbullet_ai)
113        (draw_fun   dev_draw)     ; you can't see the bullets
114        (user_fun   mbullet_ufun))
115  (range 10000 10000)
116  (flags (unlistable T))
117  (states "art/misc.spe" (stopped "mbullet_icon")))
118
119
120(defun grenade_ufun (creator)
121  (set_direction (with_object creator (direction)))
122  (play_sound GRENADE_THROW 127 (x) (y))
123  (select (aitype)
124          (1 (progn (set_xvel (if (> (direction) 0)
125                                  (+ 13 (random 2))
126                                (+ -13 (random 2)))) (set_yvel -4)))
127          (2 (progn (set_xvel (if (> (direction) 0)
128                                  (+ 7 (random 2))
129                                (+ -7 (random 2)))) (set_yvel -10))))
130  (set_xvel (+ (xvel) (with_object creator (xvel))))
131  (link_object creator)
132)
133
134(defun grenade_cache (type)
135  (list (list EXPLODE1 EXP_LIGHT)
136        (list GRENADE_SND)))
137
138
139(def_char GRENADE
140  (funs (ai_fun   grenade_ai)
141        (get_cache_list_fun grenade_cache)
142        (user_fun grenade_ufun))
143  (range 10000 10000)
144  (flags (unlistable  T))
145  (states "art/misc.spe" (stopped (seq "4gre" 1 8))))
146
147
148(def_char FIREBOMB
149  (funs (ai_fun   firebomb_ai)
150        (user_fun firebomb_ufun)
151        (get_cache_list_fun grenade_cache)
152        (draw_fun fb_draw))
153  (abilities (walk_top_speed  20)
154             (run_top_speed   20))
155  (range 10000 10000)
156  (flags (unlistable T))
157  (states "art/misc.spe"
158          (stopped "firebomb")
159          (walking "firebomb")))
160
161(defun giver (type)
162  (let ((amount (get_ability start_hp)))
163    (with_object (bg)
164                 (progn
165                   (if (and (not (has_weapon type)) change_on_pickup)
166                       (progn
167                         (give_weapon type)
168                         (set_current_weapon type))
169                     (give_weapon type))
170                   (add_ammo type amount)))))
171
172
173;; XXX: Mac Abuse reimplements this in C++
174(defun weapon_icon_ai ()
175  (if (eq0 (aistate))
176      (if (activated)
177          (progn
178            (try_move 0 10)
179            (if (eq (second (see_dist (x) (y) (x) (+ (y) 1))) (y))  ; if we are on the floor, don't check falling anymore
180                (set_aistate 1))
181
182            (if (touching_bg)
183                (progn
184                  (play_sound AMMO_SND 127 (x) (y))
185                  (select (otype)
186                          (MBULLET_ICON5   (giver 0));; these numbers correspond to status bar position
187                          (MBULLET_ICON20  (giver 0))
188                          (GRENADE_ICON2   (giver 1))
189                          (GRENADE_ICON10  (giver 1))
190
191                          (ROCKET_ICON2    (giver 2))
192                          (ROCKET_ICON5    (giver 2))
193
194                          (FBOMB_ICON1     (giver 3))
195                          (FBOMB_ICON5     (giver 3))
196
197                          (PLASMA_ICON20   (giver 4))
198                          (PLASMA_ICON50   (giver 4))
199
200                          (LSABER_ICON50   (giver 5))
201                          (LSABER_ICON100  (giver 5))
202
203                          (DFRIS_ICON4     (giver 6))
204                          (DFRIS_ICON10    (giver 6))
205
206                          )
207
208                  nil)
209              T))
210        T)
211    (if (touching_bg)
212        (progn
213          (play_sound AMMO_SND 127 (x) (y))
214          (select (otype)
215                  (MBULLET_ICON5   (giver 0));; these numbers correspond to status bar position
216                  (MBULLET_ICON20  (giver 0))
217                  (GRENADE_ICON2   (giver 1))
218                  (GRENADE_ICON10  (giver 1))
219
220                  (ROCKET_ICON2    (giver 2))
221                  (ROCKET_ICON5    (giver 2))
222
223                  (FBOMB_ICON1     (giver 3))
224                  (FBOMB_ICON5     (giver 3))
225
226                  (PLASMA_ICON20   (giver 4))
227                  (PLASMA_ICON50   (giver 4))
228
229                  (LSABER_ICON50   (giver 5))
230                  (LSABER_ICON100  (giver 5))
231
232                  (DFRIS_ICON4     (giver 6))
233                  (DFRIS_ICON10    (giver 6))
234
235                  )
236          nil)
237      T)))
238
239;; XXX: Mac Abuse reimplements this in C++
240(defun on_draw ()
241  (if (activated)
242      (draw)
243    (dev_draw)))
244
245;; XXX: Mac Abuse reimplements this in C++
246(defun ammo_cache (type)    ;; tells what other chars to load in with this character
247  (list
248   (select type
249           (GRENADE_ICON2    `(,GRENADE ,GRENADE_TOP))
250           (GRENADE_ICON10   `(,GRENADE ,GRENADE_TOP))
251           (MBULLET_ICON5    `(,SHOTGUN_BULLET ,MGUN_TOP))
252           (MBULLET_ICON20   `(,SHOTGUN_BULLET ,MGUN_TOP))
253           (ROCKET_ICON2     `(,ROCKET ,ROCKET_TOP))
254           (ROCKET_ICON5     `(,ROCKET ,ROCKET_TOP))
255           (FBOMB_ICON1      `(,FIREBOMB ,FIREBOMB_TOP))
256           (FBOMB_ICON5      `(,FIREBOMB ,FIREBOMB_TOP))
257
258           (PLASMA_ICON20    `(,PLASMAGUN_BULLET))
259           (PLASMA_ICON50    `(,PLASMAGUN_BULLET))
260
261           (LSABER_ICON50    `(,LSABER_BULLET ,PGUN_TOP))
262           (LSABER_ICON100   `(,LSABER_BULLET ,PGUN_TOP))
263
264           (DFRIS_ICON4      `(,DFRIS_BULLET ,DFRIS_TOP))
265           (DFRIS_ICON10     `(,DFRIS_BULLET ,DFRIS_TOP))
266   nil)))
267
268(defun make_ammo_icon (symbol icon_name increment)
269  (eval (list 'def_char symbol
270              '(funs (ai_fun weapon_icon_ai)
271                     (get_cache_list_fun ammo_cache)
272                     (draw_fun on_draw))
273              '(range 5 5)
274              '(flags (add_front T))
275              `(abilities (start_hp ,increment))
276              `(states  "art/chars/ammo.spe" (stopped ,icon_name)))))
277
278(make_ammo_icon 'GRENADE_ICON2  "grenade_small" 2 )
279(make_ammo_icon 'GRENADE_ICON10 "grenade_large" 10)
280
281(make_ammo_icon 'MBULLET_ICON5  "bullets_small"  5)
282(make_ammo_icon 'MBULLET_ICON20 "bullets_large" 20)
283
284(make_ammo_icon 'FBOMB_ICON1 "firebomb_small"   1)
285(make_ammo_icon 'FBOMB_ICON5 "firebomb_large"   5)
286
287(make_ammo_icon 'ROCKET_ICON2 "rocket_small"      2)
288(make_ammo_icon 'ROCKET_ICON5 "rocket_large"      5)
289
290
291
292(defun guner_cons ()
293  (set_xvel 7)     ;; fire speed
294  (set_yvel 50)    ;; speed of bullet
295  (set_xacel 290)  ;; start angle
296  (set_yacel 359)  ;; end angle
297)
298
299
300(defun guner_damage (amount from hitx hity push_xvel push_yvel)  ; transfer damage to lower half
301  (if (not (eq (state) stopped))
302      (progn
303        (add_object EXPLODE3 (+ hitx (random 5)) (+ hity (random 5)) 0)
304        (add_object EXPLODE2 (+ hitx (random 5)) (+ hity (random 5)) 2)
305        (add_object EXPLODE3 (- hitx (random 5)) (- hity (random 5)) 1)
306        (add_object EXPLODE3 (- hitx (random 5)) (- hity (random 5)) 2)
307
308        (damage_fun amount from hitx hity 0 0)     ; don't allow pushing
309
310        (if (<= (hp) 0)
311            (progn
312              (play_sound BLOWN_UP 127 (x) (y))
313              (add_object EXPLODE1 (- hitx (random 10)) (- hity (random 25)) 0)
314              (add_object EXPLODE1 (+ hitx (random 10)) (+ hity (random 25)) 1)
315              (add_object EXPLODE1 (- hitx (random 10)) (- hity (random 10)) 2)
316              (add_object EXPLODE1 (+ hitx (random 10)) (+ hity (random 10)) 3) ))))
317)
318
319
320
321
322
323
324(defun shot_ai () (eq (bmove nil) T))
325(defun gun_ai ()
326  (if (> (hp) 0)
327      (progn
328        (select (state)
329                (stopped (if (> (state_time) (xvel))
330                             (let ((a (site_angle (bg)))
331                                   (me (me))
332                                   (speed (yvel)))
333                               (if (eq (aitype) 1)
334                                   (print a))        ;; show the angle for level designers
335                               (if (and (>= a (xacel)) (<= a (yacel)) (if (> (direction) 0)
336                                       (set_frame_angle 290 0 a)
337                                     (set_frame_angle 180 250 a)))
338                                   (progn
339                                     (with_object (add_object VIS_SHOT
340                                                              (+ (x) (* (cos a) 10))
341                                                              (- (y) (+ 10 (* (sin a) 10))))
342                                                  (progn
343                                                    (play_sound MGUN_SND 127 (x) (y))
344                                                    (set_course a speed)
345                                                    (link_object me)))
346                                              (set_aistate (+ (aistate) 1))
347                                              (jump_state walking))))
348                           nil))
349                (walking (jump_state blocking))
350                (blocking (jump_state stopped)))
351        T)
352    nil)
353  )
354
355
356(defun rocket_ai ()
357  (if (not (frame_panic))
358      (let ((rand (rand_on)))
359        (with_object (add_object SMALL_LIGHT_CLOUD (+ (x) (random 3))
360                                 (- (y) (random 3) (/ (picture_height) 2)))
361                     (set_fade_count 11))
362        (set_rand_on rand)))
363
364  (if (> (total_objects) 1)  ;; if not attached to object, just fly strait (0 is player)
365    (let ((angle (atan2 (- (- (y) (with_object (get_object 1) (y))) -15)
366                        (- (with_object (get_object 1) (x)) (x) ))))
367      (let ((clock_dist (if (< angle (aistate))          ;; calculate clockwise andle distance
368                            (- (aistate) angle)
369                          (+ (aistate) (- 360 angle)))))
370        (let ((closest_dist (if (> clock_dist 180)
371                                (- 360 clock_dist)
372                              clock_dist)))
373          (let ((angle_add (if (> closest_dist 23)
374                               23
375                             (if (< closest_dist 5)
376                                 0
377                               closest_dist))))
378            (if (> clock_dist 180)     ;; should we steer clock wise or counter?
379                (set_aistate (mod (+ (aistate) angle_add) 360))
380              (set_aistate (mod (+ (- (aistate) angle_add) 360) 360))) )))))
381
382  (if (< speed max_speed)
383      (setq speed (+ speed 2)))
384  (set_course (aistate) speed)
385  (set_frame_angle 0 359 (aistate))
386  (if (or (eq (hp) 0)
387          (not (eq (bmove (if (> (total_objects) 0) (get_object 0) nil)) T))
388          (and (> (total_objects) 1)
389               (< (abs (- (with_object (get_object 1) (x)) (x) )) 10)
390               (< (abs (- (- (with_object (get_object 1) (y)) (y)) 15 )) 10)))
391      (progn
392        (do_explo 40 50)
393        nil)
394  T))
395
396
397(defun rocket_ufun (creator)
398  (link_object creator)
399  (play_sound ROCKET_SND 127 (x) (y))
400
401  (let ((target (with_object creator (find_object_in_area
402                                      (- (x) 160) (- (y) 160)
403                                      (+ (x) 160) (+ (y) 160) bad_guy_list))))
404    (select (aitype)
405            (1 (set_aistate (if (> (with_object creator (direction)) 0) 0 180)))
406            (2  (set_aistate (if (> (with_object creator (direction)) 0) 45 135))))
407    (if target (link_object target)))
408
409)
410
411(defun rocket_cache (type)
412  (list (list SMALL_LIGHT_CLOUD) nil))
413
414(def_char ROCKET
415  (funs (ai_fun   rocket_ai)
416        (get_cache_list_fun rocket_cache)
417        (get_cache_list_fun grenade_cache)
418        (user_fun rocket_ufun))
419  (vars speed max_speed)
420  (range 10000 10000)
421  (flags (unlistable T)
422         (hurtable T)
423         (add_front T))
424  (abilities (start_hp 4))
425  (states "art/missle.spe" (stopped  (seq "miss" 1 32))))
426
427
428/*
429(defun sgun_ai ()
430  (setq sgb_lastx (x))
431  (setq sgb_lasty (y))
432  (setq sgb_speed (/ (* sgb_speed 6) 5))
433  (set_course sgb_angle sgb_speed)
434  (if (eq sgb_lifetime 0)
435      nil
436    (let ((bx (bmove (if (> (total_objects) 0) (get_object 0) nil))))  ; don't hit the guy who fired us.
437      (setq sgb_lifetime (- sgb_lifetime 1))
438      (if (eq bx T) T
439        (progn
440          (setq sgb_lifetime 0)    ;; disappear next tick
441          (if (eq bx nil)
442              (add_object EXPLODE5 (- (x) (random 5)) (- (y) (random 5)) 0)
443            (progn
444              (add_object EXPLODE3 (- (x) (random 5)) (- (y) (random 5)) 0)
445              (do_damage 5 bx (* (cos sgb_angle) 10) (* (sin sgb_angle) 10))))))
446      T)))
447        */
448
449
450(defun sgun_draw ()
451  (draw_line sgb_lastx (- sgb_lasty 1) (x) (- (y) 1) sgb_medium_color)
452  (draw_line sgb_lastx (+ sgb_lasty 1) (x) (+ (y) 1) sgb_medium_color)
453
454  (draw_line (- sgb_lastx 1) sgb_lasty (- (x) 1) (y) sgb_bright_color)
455  (draw_line (+ sgb_lastx 1) sgb_lasty (+ (x) 1) (y) sgb_medium_color)
456
457
458  (draw_line sgb_lastx sgb_lasty (x) (y) sgb_bright_color)
459)
460
461
462(defun sgun_ufun (creator)
463  (set_direction (with_object creator (direction)))
464  (set_y (- (y) 4))
465  (set_x (+ (x) (* (direction) 20)))
466  (play_sound ZAP_SND 127 (x) (y))
467  (let ((start (if (> (direction) 0) 335 155))
468        (end   (if (> (direction) 0) 25 205)))
469    (setq sgb_speed 8)
470    (setq sgb_lastx (x))
471    (setq sgb_lasty (y))
472    (let ((target (with_object creator (find_object_in_angle start end bad_guy_list))))
473      (if (and target (< (abs (- (x) (with_object target (x)))) 150)
474               (< (abs (- (y) (with_object target (y)))) 100))
475          (setq sgb_angle (site_angle target))
476        (if (> (direction) 0)
477            (setq sgb_angle 0)
478          (setq sgb_angle 180)))))
479  (link_object creator)
480)
481
482
483(def_char SHOTGUN_BULLET
484  (vars sgb_speed sgb_angle sgb_lastx sgb_lasty
485        sgb_bright_color sgb_medium_color sgb_lifetime)
486  (funs (ai_fun   sgun_ai)
487        (user_fun sgun_ufun)
488        (draw_fun sgun_draw))
489  (range 10000 10000)
490  (flags (unlistable T)
491         (add_front T))
492  (states "art/misc.spe" (stopped  "sgun_bullet")))
493
494
495
496(make_ammo_icon 'PLASMA_ICON20 "plasma_small"     20)
497(make_ammo_icon 'PLASMA_ICON50 "plasma_large"     50)
498
499(make_ammo_icon 'LSABER_ICON50  "lsaber_small"    50)
500(make_ammo_icon 'LSABER_ICON100 "lsaber_large"   100)
501
502(make_ammo_icon 'DFRIS_ICON4  "dfris_small"      4)
503(make_ammo_icon 'DFRIS_ICON10 "dfris_large"     10)
504
505
506(defun pgun_draw ()
507  (let ((c (- 255 (* (state_time) 40))))
508    (scatter_line sgb_lastx sgb_lasty (x) (y) (find_rgb c (/ c 2) c) (state_time))
509    (scatter_line sgb_lastx sgb_lasty (x) (y) (find_rgb c (/ c 2) c) 0)
510    ))
511
512
513
514(defun pgun_ai ()
515  (select (state_time)
516          (0 T)
517          (1 T)
518          (2 T)
519          (3 T)
520          (4 T)
521          (5 nil)))
522
523(def_char PLASMAGUN_BULLET
524  (vars sgb_angle sgb_lastx sgb_lasty)
525  (funs (ai_fun   pgun_ai)
526        (draw_fun pgun_draw))
527  (range 10000 10000)
528  (flags (unlistable T)
529         (add_front T))
530  (states "art/misc.spe" (stopped  "sgun_bullet")))
531
532
533(defun lsaber_ai ()
534  (shift_rand_table (random 80))
535  nil)
536
537
538(defun lsaber_draw ()
539  (let ((c1 (find_rgb 255 255 255))
540        (c2 (find_rgb 70 59 67))
541        (c3 (find_rgb 147 155 195)))
542
543
544    (scatter_line sgb_lastx sgb_lasty (x) (y) c1 0)
545    (scatter_line sgb_lastx sgb_lasty (x) (y) c3 2)
546    (ascatter_line sgb_lastx sgb_lasty (x) (y) c1 c2 1)
547  ))
548
549
550
551(def_char LSABER_BULLET
552  (vars sgb_angle sgb_lastx sgb_lasty)
553  (funs (ai_fun   lsaber_ai)
554        (draw_fun lsaber_draw))
555  (range 10000 10000)
556  (flags (unlistable T)
557         (add_front T))
558  (states "art/misc.spe" (stopped  "sgun_bullet")))
559
560
561(defun angle_diff (a1 a2)
562  (if (< (abs (- a2 a1)) 180)
563      (- a2 a1)
564    (if (< a1 a2)
565        (+ (- a1 a2) 180)
566      (- (- a1 a2) 180))))
567
568
569(defun get_fris_angle ()
570  (let ((px (with_object (get_object 0) (player_pointer_x)))
571        (py (with_object (get_object 0) (player_pointer_y))))
572    (atan2 (- (y) py 4)
573           (- px (x)))))
574
575(defun dfris_ai ()
576  (if (and (eq 0 (mod (game_tick) 2)) (not (frame_panic)))
577      (let ((rand (rand_on)))
578        (with_object (add_object SMALL_LIGHT_CLOUD (+ (x) (random 3))
579                                 (- (y) (random 3) (/ (picture_height) 2)))
580                     (set_fade_count 11))
581        (set_rand_on rand)))
582  (set_course (aistate) 12)
583  (if (or (not (eq (bmove (if (> (total_objects) 0) (get_object 0) nil)) T))
584          (< (total_objects) 1)
585          (let ((mex (x))
586                (mey (y)))
587            (with_object (get_object 0) (find_object_in_area (- mex 7)
588                                                             (- mey 7)
589                                                             (+ mex 7)
590                                                             (+ mey 7) bad_guy_list))))
591      (progn
592        (do_white_explo 40 45)
593        nil)
594    (progn
595      (next_picture)
596      (if (> (with_object (get_object 0) (total_objects)) 0)
597          (let ((player_angle (get_fris_angle)))
598            (let ((angle_change (angle_diff (aistate) player_angle)))
599              (if (< (abs angle_change) 35)
600                  (set_aistate (mod (+ (aistate) angle_change 360) 360))
601                (if (>= angle_change 0)
602                    (set_aistate (mod (+ (aistate) 35) 360))
603                  (set_aistate (mod (+ (aistate) 325 ) 360)))))))
604      T))
605)
606
607
608
609(defun dfris_cache (type)
610  (list (list EXPLODE8 EXP_LIGHT)
611        (list GRENADE_SND)))
612
613(def_char DFRIS_BULLET
614  (funs (ai_fun   dfris_ai)
615        (get_cache_list_fun dfris_cache))
616  (range 10000 10000)
617  (flags (unlistable T)
618         (add_front T))
619  (states "art/misc.spe" (stopped  "dfris_bullet")))
620
Note: See TracBrowser for help on using the repository browser.