source: abuse-mac/trunk/lisp/weapons.lsp @ 122

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