source: abuse/trunk/data-abuse/lisp/weapons.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: 13.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(defun weapon_icon_ai ()
174  (if (eq0 (aistate))
175      (if (activated)
176          (progn
177            (try_move 0 10)
178            (if (eq (second (see_dist (x) (y) (x) (+ (y) 1))) (y))  ; if we are on the floor, don't check falling anymore
179                (set_aistate 1))
180
181            (if (touching_bg)
182                (progn
183                  (play_sound AMMO_SND 127 (x) (y))
184                  (select (otype)
185                          (MBULLET_ICON5   (giver 0));; these numbers correspond to status bar position
186                          (MBULLET_ICON20  (giver 0))
187                          (GRENADE_ICON2   (giver 1))
188                          (GRENADE_ICON10  (giver 1))
189
190                          (ROCKET_ICON2    (giver 2))
191                          (ROCKET_ICON5    (giver 2))
192
193                          (FBOMB_ICON1     (giver 3))
194                          (FBOMB_ICON5     (giver 3))
195
196                          (PLASMA_ICON20   (giver 4))
197                          (PLASMA_ICON50   (giver 4))
198
199                          (LSABER_ICON50   (giver 5))
200                          (LSABER_ICON100  (giver 5))
201
202                          (DFRIS_ICON4     (giver 6))
203                          (DFRIS_ICON10    (giver 6))
204
205                          )
206
207                  nil)
208              T))
209        T)
210    (if (touching_bg)
211        (progn
212          (play_sound AMMO_SND 127 (x) (y))
213          (select (otype)
214                  (MBULLET_ICON5   (giver 0));; these numbers correspond to status bar position
215                  (MBULLET_ICON20  (giver 0))
216                  (GRENADE_ICON2   (giver 1))
217                  (GRENADE_ICON10  (giver 1))
218
219                  (ROCKET_ICON2    (giver 2))
220                  (ROCKET_ICON5    (giver 2))
221
222                  (FBOMB_ICON1     (giver 3))
223                  (FBOMB_ICON5     (giver 3))
224
225                  (PLASMA_ICON20   (giver 4))
226                  (PLASMA_ICON50   (giver 4))
227
228                  (LSABER_ICON50   (giver 5))
229                  (LSABER_ICON100  (giver 5))
230
231                  (DFRIS_ICON4     (giver 6))
232                  (DFRIS_ICON10    (giver 6))
233
234                  )
235          nil)
236      T)))
237
238(defun on_draw ()
239  (if (activated)
240      (draw)
241    (dev_draw)))
242
243
244(defun ammo_cache (type)    ;; tells what other chars to load in with this character
245  (list
246   (select type
247           (GRENADE_ICON2    `(,GRENADE ,GRENADE_TOP))
248           (GRENADE_ICON10   `(,GRENADE ,GRENADE_TOP))
249           (MBULLET_ICON5    `(,SHOTGUN_BULLET ,MGUN_TOP))
250           (MBULLET_ICON20   `(,SHOTGUN_BULLET ,MGUN_TOP))
251           (ROCKET_ICON2     `(,ROCKET ,ROCKET_TOP))
252           (ROCKET_ICON5     `(,ROCKET ,ROCKET_TOP))
253           (FBOMB_ICON1      `(,FIREBOMB ,FIREBOMB_TOP))
254           (FBOMB_ICON5      `(,FIREBOMB ,FIREBOMB_TOP))
255
256           (PLASMA_ICON20    `(,PLASMAGUN_BULLET))
257           (PLASMA_ICON50    `(,PLASMAGUN_BULLET))
258
259           (LSABER_ICON50    `(,LSABER_BULLET ,PGUN_TOP))
260           (LSABER_ICON100   `(,LSABER_BULLET ,PGUN_TOP))
261
262           (DFRIS_ICON4      `(,DFRIS_BULLET ,DFRIS_TOP))
263           (DFRIS_ICON10     `(,DFRIS_BULLET ,DFRIS_TOP))
264   nil)))
265
266(defun make_ammo_icon (symbol icon_name increment)
267  (eval (list 'def_char symbol
268              '(funs (ai_fun weapon_icon_ai)
269                     (get_cache_list_fun ammo_cache)
270                     (draw_fun on_draw))
271              '(range 5 5)
272              '(flags (add_front T))
273              `(abilities (start_hp ,increment))
274              `(states  "art/chars/ammo.spe" (stopped ,icon_name)))))
275
276(make_ammo_icon 'GRENADE_ICON2  "grenade_small" 2 )
277(make_ammo_icon 'GRENADE_ICON10 "grenade_large" 10)
278
279(make_ammo_icon 'MBULLET_ICON5  "bullets_small"  5)
280(make_ammo_icon 'MBULLET_ICON20 "bullets_large" 20)
281
282(make_ammo_icon 'FBOMB_ICON1 "firebomb_small"   1)
283(make_ammo_icon 'FBOMB_ICON5 "firebomb_large"   5)
284
285(make_ammo_icon 'ROCKET_ICON2 "rocket_small"      2)
286(make_ammo_icon 'ROCKET_ICON5 "rocket_large"      5)
287
288
289
290(defun guner_cons ()
291  (set_xvel 7)     ;; fire speed
292  (set_yvel 50)    ;; speed of bullet
293  (set_xacel 290)  ;; start angle
294  (set_yacel 359)  ;; end angle
295)
296
297
298(defun guner_damage (amount from hitx hity push_xvel push_yvel)  ; transfer damage to lower half
299  (if (not (eq (state) stopped))
300      (progn
301        (add_object EXPLODE3 (+ hitx (random 5)) (+ hity (random 5)) 0)
302        (add_object EXPLODE2 (+ hitx (random 5)) (+ hity (random 5)) 2)
303        (add_object EXPLODE3 (- hitx (random 5)) (- hity (random 5)) 1)
304        (add_object EXPLODE3 (- hitx (random 5)) (- hity (random 5)) 2)
305
306        (damage_fun amount from hitx hity 0 0)     ; don't allow pushing
307
308        (if (<= (hp) 0)
309            (progn
310              (play_sound BLOWN_UP 127 (x) (y))
311              (add_object EXPLODE1 (- hitx (random 10)) (- hity (random 25)) 0)
312              (add_object EXPLODE1 (+ hitx (random 10)) (+ hity (random 25)) 1)
313              (add_object EXPLODE1 (- hitx (random 10)) (- hity (random 10)) 2)
314              (add_object EXPLODE1 (+ hitx (random 10)) (+ hity (random 10)) 3) ))))
315)
316
317
318
319
320
321
322(defun shot_ai () (eq (bmove nil) T))
323(defun gun_ai ()
324  (if (> (hp) 0)
325      (progn
326        (select (state)
327                (stopped (if (> (state_time) (xvel))
328                             (let ((a (site_angle (bg)))
329                                   (me (me))
330                                   (speed (yvel)))
331                               (if (eq (aitype) 1)
332                                   (print a))        ;; show the angle for level designers
333                               (if (and (>= a (xacel)) (<= a (yacel)) (if (> (direction) 0)
334                                       (set_frame_angle 290 0 a)
335                                     (set_frame_angle 180 250 a)))
336                                   (progn
337                                     (with_object (add_object VIS_SHOT
338                                                              (+ (x) (* (cos a) 10))
339                                                              (- (y) (+ 10 (* (sin a) 10))))
340                                                  (progn
341                                                    (play_sound MGUN_SND 127 (x) (y))
342                                                    (set_course a speed)
343                                                    (link_object me)))
344                                              (set_aistate (+ (aistate) 1))
345                                              (jump_state walking))))
346                           nil))
347                (walking (jump_state blocking))
348                (blocking (jump_state stopped)))
349        T)
350    nil)
351  )
352
353
354(defun rocket_ai ()
355  (if (not (frame_panic))
356      (let ((rand (rand_on)))
357        (with_object (add_object SMALL_LIGHT_CLOUD (+ (x) (random 3))
358                                 (- (y) (random 3) (/ (picture_height) 2)))
359                     (set_fade_count 11))
360        (set_rand_on rand)))
361
362  (if (> (total_objects) 1)  ;; if not attached to object, just fly strait (0 is player)
363    (let ((angle (atan2 (- (- (y) (with_object (get_object 1) (y))) -15)
364                        (- (with_object (get_object 1) (x)) (x) ))))
365      (let ((clock_dist (if (< angle (aistate))          ;; calculate clockwise andle distance
366                            (- (aistate) angle)
367                          (+ (aistate) (- 360 angle)))))
368        (let ((closest_dist (if (> clock_dist 180)
369                                (- 360 clock_dist)
370                              clock_dist)))
371          (let ((angle_add (if (> closest_dist 23)
372                               23
373                             (if (< closest_dist 5)
374                                 0
375                               closest_dist))))
376            (if (> clock_dist 180)     ;; should we steer clock wise or counter?
377                (set_aistate (mod (+ (aistate) angle_add) 360))
378              (set_aistate (mod (+ (- (aistate) angle_add) 360) 360))) )))))
379
380  (if (< speed max_speed)
381      (setq speed (+ speed 2)))
382  (set_course (aistate) speed)
383  (set_frame_angle 0 359 (aistate))
384  (if (or (eq (hp) 0)
385          (not (eq (bmove (if (> (total_objects) 0) (get_object 0) nil)) T))
386          (and (> (total_objects) 1)
387               (< (abs (- (with_object (get_object 1) (x)) (x) )) 10)
388               (< (abs (- (- (with_object (get_object 1) (y)) (y)) 15 )) 10)))
389      (progn
390        (do_explo 40 50)
391        nil)
392  T))
393
394
395(defun rocket_ufun (creator)
396  (link_object creator)
397  (play_sound ROCKET_SND 127 (x) (y))
398
399  (let ((target (with_object creator (find_object_in_area
400                                      (- (x) 160) (- (y) 160)
401                                      (+ (x) 160) (+ (y) 160) bad_guy_list))))
402    (select (aitype)
403            (1 (set_aistate (if (> (with_object creator (direction)) 0) 0 180)))
404            (2  (set_aistate (if (> (with_object creator (direction)) 0) 45 135))))
405    (if target (link_object target)))
406
407)
408
409(defun rocket_cache (type)
410  (list (list SMALL_LIGHT_CLOUD) nil))
411
412(def_char ROCKET
413  (funs (ai_fun   rocket_ai)
414        (get_cache_list_fun rocket_cache)
415        (get_cache_list_fun grenade_cache)
416        (user_fun rocket_ufun))
417  (vars speed max_speed)
418  (range 10000 10000)
419  (flags (unlistable T)
420         (hurtable T)
421         (add_front T))
422  (abilities (start_hp 4))
423  (states "art/missle.spe" (stopped  (seq "miss" 1 32))))
424
425
426/*
427(defun sgun_ai ()
428  (setq sgb_lastx (x))
429  (setq sgb_lasty (y))
430  (setq sgb_speed (/ (* sgb_speed 6) 5))
431  (set_course sgb_angle sgb_speed)
432  (if (eq sgb_lifetime 0)
433      nil
434    (let ((bx (bmove (if (> (total_objects) 0) (get_object 0) nil))))  ; don't hit the guy who fired us.
435      (setq sgb_lifetime (- sgb_lifetime 1))
436      (if (eq bx T) T
437        (progn
438          (setq sgb_lifetime 0)    ;; disappear next tick
439          (if (eq bx nil)
440              (add_object EXPLODE5 (- (x) (random 5)) (- (y) (random 5)) 0)
441            (progn
442              (add_object EXPLODE3 (- (x) (random 5)) (- (y) (random 5)) 0)
443              (do_damage 5 bx (* (cos sgb_angle) 10) (* (sin sgb_angle) 10))))))
444      T)))
445        */
446
447
448(defun sgun_draw ()
449  (draw_line sgb_lastx (- sgb_lasty 1) (x) (- (y) 1) sgb_medium_color)
450  (draw_line sgb_lastx (+ sgb_lasty 1) (x) (+ (y) 1) sgb_medium_color)
451
452  (draw_line (- sgb_lastx 1) sgb_lasty (- (x) 1) (y) sgb_bright_color)
453  (draw_line (+ sgb_lastx 1) sgb_lasty (+ (x) 1) (y) sgb_medium_color)
454
455
456  (draw_line sgb_lastx sgb_lasty (x) (y) sgb_bright_color)
457)
458
459
460(defun sgun_ufun (creator)
461  (set_direction (with_object creator (direction)))
462  (set_y (- (y) 4))
463  (set_x (+ (x) (* (direction) 20)))
464  (play_sound ZAP_SND 127 (x) (y))
465  (let ((start (if (> (direction) 0) 335 155))
466        (end   (if (> (direction) 0) 25 205)))
467    (setq sgb_speed 8)
468    (setq sgb_lastx (x))
469    (setq sgb_lasty (y))
470    (let ((target (with_object creator (find_object_in_angle start end bad_guy_list))))
471      (if (and target (< (abs (- (x) (with_object target (x)))) 150)
472               (< (abs (- (y) (with_object target (y)))) 100))
473          (setq sgb_angle (site_angle target))
474        (if (> (direction) 0)
475            (setq sgb_angle 0)
476          (setq sgb_angle 180)))))
477  (link_object creator)
478)
479
480
481(def_char SHOTGUN_BULLET
482  (vars sgb_speed sgb_angle sgb_lastx sgb_lasty
483        sgb_bright_color sgb_medium_color sgb_lifetime)
484  (funs (ai_fun   sgun_ai)
485        (user_fun sgun_ufun)
486        (draw_fun sgun_draw))
487  (range 10000 10000)
488  (flags (unlistable T)
489         (add_front T))
490  (states "art/misc.spe" (stopped  "sgun_bullet")))
491
492
493(setq load_warn nil)
494(if (not (load "register/weapons.lsp"))
495    (load "lisp/share.lsp"))
496(setq load_warn T)
497
498
499
500
501
502
503
504
505
506
Note: See TracBrowser for help on using the repository browser.