source: abuse/trunk/data-abuse/lisp/guns.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: 11.5 KB
Line 
1;; Copyright 1995 Crack dot Com,  All Rights reserved
2;; See licensing information for more details on usage rights
3
4
5(setq gun_tints (make-array 11 :initial-contents (list
6                                                  normal_tint
7                                                  (def_tint "art/tints/guns/orange.spe") ; orange
8                                                  (def_tint "art/tints/guns/green.spe")  ; grenade
9                                                  (def_tint "art/tints/guns/redish.spe") ; rocket
10                                                  (def_tint "art/tints/guns/blue.spe")   ; plasma
11                                                  normal_tint
12                                                  normal_tint
13                                                  normal_tint
14                                                  normal_tint
15                                                  normal_tint
16                                                  normal_tint)))
17
18
19(setq ai_ammo (make-array 9 :initial-contents (list MBULLET_ICON5
20                                                MBULLET_ICON5
21                                                GRENADE_ICON2
22                                                ROCKET_ICON2
23                                                PLASMA_ICON20
24                                                MBULLET_ICON5
25                                                MBULLET_ICON5
26                                                MBULLET_ICON5
27                                                MBULLET_ICON5)))
28
29(defun aitype_to_ammo (aitype)
30  (aref ai_ammo aitype))
31
32
33
34(defun fire_object (creator type x y angle target)
35  (select type
36
37          (0 (with_object (add_object SHOTGUN_BULLET x y)
38                                      (progn
39                                        (play_sound ZAP_SND 127 (x) (y))
40                                        (setq sgb_lifetime 6)
41                                        (setq sgb_speed 15)
42                                        (setq sgb_lastx (x))
43                                        (setq sgb_lasty (y))
44                                        (setq sgb_angle angle)
45                                        (setq sgb_bright_color (find_rgb 255 255 200))
46                                        (setq sgb_medium_color (find_rgb 150 150 0))
47                                        (if creator
48                                            (progn
49                                              (setq sgb_speed (+ sgb_speed (/ (xvel) 2)))
50                                              (link_object creator)))
51                                        (sgun_ai)
52                                        )))
53          (1 (with_object (add_object SHOTGUN_BULLET x y)
54                                      (progn
55                                        (play_sound ZAP_SND 127 (x) (y))
56                                        (setq sgb_lifetime 40)
57                                        (setq sgb_speed 6)
58                                        (setq sgb_lastx (x))
59                                        (setq sgb_lasty (y))
60                                        (setq sgb_angle angle)
61
62                                        (setq sgb_bright_color (find_rgb 255 128 64))
63                                        (setq sgb_medium_color (find_rgb 255 0 0))
64                                        (if creator
65                                            (progn
66                                              (setq sgb_speed (+ sgb_speed (/ (xvel) 2)))
67                                              (link_object creator)))
68                                        (sgun_ai)
69                                        )))
70          (2 (with_object (add_object GRENADE x y)
71                          (progn
72                            (play_sound GRENADE_THROW 127 x y)
73                            (set_course angle 20)
74                            (if creator
75                                (progn
76                                  (link_object creator)
77                                  (set_xvel (+ (xvel) (with_object creator (xvel))))
78                                  (set_yvel (+ (yvel) (with_object creator (yvel))))
79                                  ))
80
81                            (set_frame_angle 0 359 angle)
82                            )))
83          (3 (with_object (add_object ROCKET x y)
84                          (progn
85                            (play_sound ROCKET_LAUNCH_SND 127 x y)
86                            (set_aistate angle)
87                            (if creator (link_object creator))
88
89                            (if (and target   ;; don't link if not in line of site
90                                     (can_see (x) (y)
91                                              (with_object target (x))
92                                              (with_object target (y)) nil))
93                                              (link_object target))
94
95                            (set_frame_angle 0 359 angle)
96                            (setq speed 5)
97                            (if (and creator (with_object creator (isa_player)))
98                                (setq max_speed 14)
99                              (setq max_speed 10))
100                            (set_y (+ (y) (/ (picture_height) 2)))  ;; move down to match frame/pos
101                            )))
102
103          (4 (with_object (add_object PLASMAGUN_BULLET x y)
104                                      (progn
105                                        (play_sound PLASMA_SND 127 (x) (y))
106                                        (setq sgb_lastx (x))
107                                        (setq sgb_lasty (y))
108                                        (if creator
109                                              (link_object creator))
110                                        (set_course angle 200)
111                                        (let ((old_x (x))
112                                              (old_y (y))
113                                              (bx (bmove (if (> (total_objects) 0) (get_object 0) nil))))
114                                          (if (not (eq bx T))
115                                              (if (eq bx nil)
116                                                  (add_object EXPLODE5 (- (x) (random 5))
117                                                              (- (y) (random 5)) 0)
118                                                (progn
119                                                  (add_object EXPLODE3 (- (x) (random 5))
120                                                              (- (y) (random 5)) 0)
121                                                  (do_damage 10 bx (* (cos sgb_angle) 20)
122                                                             (* (sin sgb_angle) 10)))))
123                                          (setq sgb_lastx (x))
124                                          (setq sgb_lasty (y))
125                                          (set_x old_x)
126                                          (set_y old_y))
127                                        )))
128
129
130          (5 (with_object (add_object FIREBOMB x y)
131                          (progn
132                            (play_sound FIREBOMB_SND 127 (x) (y))
133                            (set_course angle 20)
134                            (if creator
135                                (progn
136                                  (link_object creator)
137                                  (set_yvel (+ (yvel) (with_object creator (yvel))))
138                                  )))))
139
140          (6 (with_object (add_object DFRIS_BULLET x y)
141                                      (progn
142                                        (play_sound ROCKET_LAUNCH_SND 127 x y)
143                                        (set_course angle 25)
144                                        (set_aistate angle)
145                                        (if creator
146                                              (link_object creator))
147                                        (dfris_ai)
148                                        )))
149
150          (7 (with_object (add_object LSABER_BULLET x y)
151                                      (progn
152                                        (play_sound LSABER_SND 127 (x) (y))
153                                        (setq sgb_lastx (x))
154                                        (setq sgb_lasty (y))
155                                        (if creator
156                                              (link_object creator))
157                                        (set_course angle 45)
158                                        (let ((bx (bmove (if (> (total_objects) 0) (get_object 0) nil))))
159                                          (if (not (eq bx T))
160                                              (if (not (eq bx nil))
161                                                  (do_damage 30 bx (* (cos sgb_angle) 20)
162                                                             (* (sin sgb_angle) 10)))))
163                                        )))
164
165
166          (9 (with_object (add_object STRAIT_ROCKET x y)
167                                      (progn
168                                        (play_sound MGUN_SND 127 (x) (y))
169                                        (if creator
170                                              (link_object creator))
171                                        (set_aistate angle)
172                                        (set_frame_angle 0 359 angle)
173                                        (play_sound GRENADE_THROW 127 (x) (y)))))
174
175          (10 (with_object (add_object SHOTGUN_BULLET x y)
176                                      (progn
177                                        (play_sound ZAP_SND 127 (x) (y))
178                                        (setq sgb_lifetime 6)
179                                        (setq sgb_speed 15)
180                                        (setq sgb_lastx (x))
181                                        (setq sgb_lasty (y))
182                                        (setq sgb_angle angle)
183                                        (setq sgb_bright_color (find_rgb 255 0 0))
184                                        (setq sgb_medium_color (find_rgb 150 0 0))
185                                        (if creator
186                                            (progn
187                                              (setq sgb_speed (+ sgb_speed (/ (xvel) 2)))
188                                              (link_object creator)))
189                                        (sgun_ai)
190                                        )))
191
192          )
193)
194
195
196(defun spray_fire ()
197  (fire_object (me) (aitype)
198               (+ (x) (* (cos spray.angle) 20))
199               (- (- (y) 21) (* (sin spray.angle) 22))
200               spray.angle
201               (bg)))
202
203
204(defun spray_gun_ai ()
205  (if (<= (hp) 0)
206      nil
207    (if (and (< (distx) 450) (< (disty) 400))
208        (progn
209          (select (aistate)
210                  (0;; look at sensor
211                   (if (activated)
212                       (if (eq (state) stopped)
213                           (progn
214                             (set_targetable T)
215                             (set_state spray.appear)
216                             (go_state 1))
217                         (go_state 3))
218                     (progn
219                       (set_targetable nil)
220                       (set_state stopped))))
221
222
223                  (1;; unfold
224                   (if (next_picture) T
225                     (progn (set_aistate 3)
226                            (set_state spray.aim)
227                            (setq spray.angle spray.start_angle)
228                            (set_frame_angle 0 359 spray.angle)
229                            )))
230
231                  (2;; fold up
232                   (if (next_picture) T
233                     (progn (set_state stopped)
234                            (set_aistate 0))))
235
236
237                  (3;; swivel down
238                   (if (> (state_time) spray.fire_delay)
239                       (progn
240                         (set_aistate 3);; reset state time
241                         (setq spray.angle (- spray.angle spray.angle_speed))
242                         (if (<= spray.angle spray.start_angle)
243                             (progn
244                               (setq spray.angle spray.start_angle)
245                               (set_aistate 4)))
246                         (set_frame_angle 0 359 spray.angle)
247                         (spray_fire))))
248
249                  (4;; swivel up
250                   (if (> (state_time) spray.fire_delay)
251                       (progn
252                         (set_aistate 4);; reset state time
253                         (setq spray.angle (+ spray.angle spray.angle_speed))
254                         (if (>= spray.angle spray.end_angle)
255                             (progn
256                               (setq spray.angle spray.end_angle)
257                               (set_aistate 0)))
258                         (set_frame_angle 0 359 spray.angle)
259
260                         (spray_fire)))))
261          T)
262      (progn
263        (set_state stopped)
264        T))))
265
266
267
268
269    (defun spray_gun_cons ()
270      (setq spray.bullet_speed 20)
271      (setq spray.angle_speed  10)
272      (setq spray.start_angle  270)
273      (setq spray.end_angle    350)
274      (setq spray.fire_delay 4))
275
276(def_char SPRAY_GUN
277  (funs (ai_fun       spray_gun_ai)
278        (damage_fun   guner_damage)
279        (draw_fun     gun_draw)
280        (constructor spray_gun_cons))
281
282  (flags (can_block  T)
283         (hurtable   T))
284  (abilities (start_hp 20)
285             )
286  (vars spray.fire_delay
287        spray.bullet_speed
288        spray.start_angle
289        spray.end_angle
290        spray.angle_speed
291        spray.angle)
292
293  (fields ("hp"                 ai_health)
294          ("aitype"             ai_type)
295          ("spray.fire_delay"   spray_delay)
296          ("spray.start_angle"  spray_start)
297          ("spray.end_angle"    spray_end)
298          ("spray.angle_speed"  spray_speed)
299          ("spray.angle"        spray_cangle))
300
301  (states "art/gun2.spe"
302          (stopped           "stopped")
303          (spray.aim         (seq "cspn" 1 24))
304          (spray.appear      '("csht0001.pcx" "csht0002.pcx"))
305          (spray.disappear   '("csht0002.pcx" "csht0001.pcx"))
306          ))
307
308(defun gun_draw ()
309  (draw_tint (aref gun_tints (aitype))))
310
311
312(def_char TRACK_GUN
313  (vars
314        fire_delay            ; how long between each shot
315        fire_delay_left
316        track_speed           ; how fast the gun can chage it's angle
317
318        burst_total           ; how many shots to fire with fire_delay in between each
319        burst_total_left
320        continue_time         ; how much time to wait before continue tracking
321        continue_time_left
322        track_start_angle     ; min angle gun will track
323        track_end_angle       ; max
324        angle)
325
326
327  (funs (ai_fun      track_ai)
328        (constructor track_cons)
329        (draw_fun    gun_draw)
330        (damage_fun   guner_damage))
331
332  (flags (can_block  T)
333         (hurtable   T))
334
335  (abilities (start_hp 20))
336
337  (fields ("hp"                ai_health)
338          ("aitype"            ai_type)
339          ("track_speed"       d_track_speed)
340          ("fire_delay"        track_fspeed)
341          ("burst_total"       track_burst)
342          ("continue_time"     track_cont)
343          ("track_start_angle" track_sangle)
344          ("track_end_angle"   track_eangle)
345          ("angle"             track_cangle))
346
347  (states "art/gun2.spe"
348          (stopped  "stopped")
349          (opening  '("csht0001.pcx" "csht0002.pcx"))
350          (shuting  '("csht0002.pcx" "csht0001.pcx"))
351          (spinning (seq "cspn" 1 24))
352          (firing   (seq "cfr1" 1 24))))
353
354(defun track_cons ()
355  (setq angle 270)
356  (setq track_speed 1)
357  (setq fire_delay  5)
358  (setq burst_total 3)
359  (setq continue_time 8)
360  (setq track_start_angle 180)
361  (setq track_end_angle   359))
362
363(defun track_fire ()
364  (fire_object (me) (aitype)
365               (+ (x) (* (cos angle) 18))
366               (- (- (y) 15) (* (sin angle) 15))
367               (mod (+ angle (- 2 (random 5))) 360)
368               (bg))
369  (if (or (eq burst_total_left 0) (eq burst_total_left 1))
370      (setq continue_time_left continue_time)
371    (progn
372      (setq burst_total_left (- burst_total_left 1))
373      (setq fire_delay_left fire_delay)))
374
375
376  (set_state firing)
377  (set_frame_angle 0 359 angle))
378
379(defun track_set_angle (new_angle)
380  (if (> track_start_angle track_end_angle)
381      (if (and (>= new_angle track_end_angle) (<= new_angle track_start_angle))
382          (setq angle new_angle))
383    (if (and (<= new_angle track_end_angle) (>= new_angle track_start_angle))
384        (setq angle new_angle))))
385
386(defun track_ai ()
387  (if (eq (hp) 0)                                                  ;; are we dead?
388      nil
389    (if (activated)                                   ;; see if we should be on
390        (if (eq (state) stopped)
391            (progn
392              (set_targetable T)
393              (set_state opening)
394              T)
395          (if (and (eq (state) opening) (next_picture))
396              T
397            (progn
398              (set_state spinning)
399              (set_frame_angle 0 359 angle)
400
401              (if (eq continue_time_left 0);; do we need to wait?
402                  (if (eq fire_delay_left 0)
403                      ;; get the angle to the player
404                      (let ((pangle (atan2 (- (- (y) (with_object (bg) (y))) -8)
405                                           (- (with_object (bg) (x)) (x) ))))
406                        (let ((clock_dist (if (< pangle angle);; calculate clockwise angle distance
407                                              (- angle pangle)
408                                            (+ angle (- 360 pangle)))))
409                          (let ((closest_dist (if (> clock_dist 180)
410                                                  (- 360 clock_dist)
411                                                clock_dist)))
412                            (let ((angle_add (if (>= closest_dist track_speed)
413                                                 track_speed
414                                               closest_dist)))
415                              (if (> clock_dist 180);; should we steer clowck wise or counter?
416                                  (track_set_angle (mod (+ angle angle_add) 360))
417                                (track_set_angle (mod (+ (- angle angle_add) 360) 360)))
418                              (if (< angle_add 5);; pretty close to target, FIRE!
419                                  (track_fire))))))
420                    (setq fire_delay_left (- fire_delay_left 1)))
421                (progn
422                  (setq continue_time_left (- continue_time_left 1))
423                  (if (eq continue_time_left 0)
424                      (setq burst_total_left burst_total))))
425              T)))
426      (progn
427        (set_targetable nil)
428        (set_state stopped)
429        T))))
430
431
432
433
434
Note: See TracBrowser for help on using the repository browser.