home *** CD-ROM | disk | FTP | other *** search
/ PC Gamer 13 / 1995-12_Disc_13.iso / abuse / lisp / weapons.lsp < prev   
Lisp/Scheme  |  1995-08-31  |  12KB  |  439 lines

  1. ;; Copyright 1995 Crack dot Com,  All Rights reserved
  2. ;; See licencing 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. (def_char GRENADE
  135.   (funs (ai_fun   grenade_ai)  
  136.     (user_fun grenade_ufun))
  137.   (range 10000 10000)
  138.   (flags (unlistable  T))
  139.   (states "art/misc.spe" (stopped (seq "4gre" 1 8))))
  140.  
  141.  
  142. (def_char FIREBOMB
  143.   (funs (ai_fun   firebomb_ai)  
  144.     (user_fun firebomb_ufun)
  145.     (draw_fun fb_draw))
  146.   (abilities (walk_top_speed  20)
  147.          (run_top_speed   20))
  148.   (range 10000 10000)
  149.   (flags (unlistable T))
  150.   (states "art/misc.spe"
  151.       (stopped "firebomb")
  152.       (walking "firebomb")))
  153.  
  154. (defun giver (type)
  155.   (let ((amount (get_ability start_hp)))
  156.     (with_object (bg)
  157.          (progn 
  158.            (if (not (has_weapon type))
  159.                (set_current_weapon type))
  160.            (give_weapon type)
  161.            (add_ammo type amount)))))
  162.  
  163. (defun weapon_icon_ai () 
  164.   (if (activated)
  165.       (progn
  166.     (try_move 0 10)
  167.     (if (touching_bg) 
  168.         (progn
  169.           (play_sound AMMO_SND 127 (x) (y))
  170.           (select (otype)
  171.               (MBULLET_ICON5   (giver 0))    ;; these numbers correspond to status bar position
  172.               (MBULLET_ICON20  (giver 0))
  173.               (GRENADE_ICON2   (giver 1))        
  174.               (GRENADE_ICON10  (giver 1))
  175.  
  176.               (ROCKET_ICON2    (giver 2))
  177.               (ROCKET_ICON5    (giver 2))
  178.  
  179.               (FBOMB_ICON1     (giver 3))
  180.               (FBOMB_ICON5     (giver 3))
  181.  
  182.               (PLASMA_ICON20   (giver 4))
  183.               (PLASMA_ICON50   (giver 4))
  184.  
  185.               (LSABER_ICON50   (giver 5))
  186.               (LSABER_ICON100  (giver 5))
  187.  
  188.               (DFRIS_ICON4     (giver 6))
  189.               (DFRIS_ICON10    (giver 6))
  190.  
  191.               )
  192.  
  193.           nil)
  194.       T))
  195.     T))
  196.     
  197. (defun on_draw ()
  198.   (if (activated)
  199.       (draw)
  200.     (dev_draw)))
  201.       
  202.  
  203. (defun make_ammo_icon (symbol icon_name increment)
  204.   (eval (list 'def_char symbol          
  205.           '(funs (ai_fun weapon_icon_ai)
  206.              (draw_fun on_draw))
  207.           '(range 5 5)
  208.           '(flags (add_front T))
  209.           `(abilities (start_hp ,increment))
  210.           `(states  "art/chars/ammo.spe" (stopped ,icon_name)))))
  211.  
  212. (make_ammo_icon 'GRENADE_ICON2  "grenade_small" 2)
  213. (make_ammo_icon 'GRENADE_ICON10 "grenade_large" 10)
  214.  
  215. (make_ammo_icon 'MBULLET_ICON5  "bullets_small"  5)
  216. (make_ammo_icon 'MBULLET_ICON20 "bullets_large" 20)
  217.  
  218. (make_ammo_icon 'FBOMB_ICON1 "firebomb_small"   1)
  219. (make_ammo_icon 'FBOMB_ICON5 "firebomb_large"   5)
  220.  
  221. (make_ammo_icon 'ROCKET_ICON2 "rocket_small"      2)
  222. (make_ammo_icon 'ROCKET_ICON5 "rocket_large"      5)
  223.  
  224.  
  225.  
  226. (defun guner_cons () 
  227.   (set_xvel 7)     ;; fire speed
  228.   (set_yvel 50)    ;; speed of bullet
  229.   (set_xacel 290)  ;; start angle
  230.   (set_yacel 359)  ;; end angle
  231. )
  232.  
  233.  
  234. (defun guner_damage (amount from hitx hity push_xvel push_yvel)  ; transfer damage to lower half
  235.   (if (not (eq (state) stopped))
  236.       (progn
  237.     (add_object EXPLODE3 (+ hitx (random 5)) (+ hity (random 5)) 0)
  238.     (add_object EXPLODE2 (+ hitx (random 5)) (+ hity (random 5)) 2)
  239.     (add_object EXPLODE3 (- hitx (random 5)) (- hity (random 5)) 1)
  240.     (add_object EXPLODE3 (- hitx (random 5)) (- hity (random 5)) 2)
  241.  
  242.     (damage_fun amount from hitx hity 0 0)     ; don't allow pushing
  243.  
  244.     (if (<= (hp) 0)
  245.         (progn
  246.           (play_sound BLOWN_UP 127 (x) (y))
  247.           (add_object EXPLODE1 (- hitx (random 10)) (- hity (random 25)) 0)      
  248.           (add_object EXPLODE1 (+ hitx (random 10)) (+ hity (random 25)) 1)      
  249.           (add_object EXPLODE1 (- hitx (random 10)) (- hity (random 10)) 2)      
  250.           (add_object EXPLODE1 (+ hitx (random 10)) (+ hity (random 10)) 3) ))))
  251. )
  252.  
  253.  
  254.  
  255.  
  256.  
  257.         
  258. (defun shot_ai () (eq (bmove nil) T))
  259. (defun gun_ai ()
  260.   (if (> (hp) 0)
  261.       (progn
  262.     (select (state)
  263.         (stopped (if (> (state_time) (xvel))
  264.                  (let ((a (site_angle (bg)))
  265.                    (me (me))
  266.                    (speed (yvel)))
  267.                    (if (eq (aitype) 1)
  268.                    (print a))        ;; show the angle for level designers
  269.                    (if (and (>= a (xacel)) (<= a (yacel)) (if (> (direction) 0)
  270.                        (set_frame_angle 290 0 a)
  271.                      (set_frame_angle 180 250 a)))
  272.                    (progn
  273.                      (with_object (add_object VIS_SHOT
  274.                                   (+ (x) (* (cos a) 10)) 
  275.                                   (- (y) (+ 10 (* (sin a) 10))))
  276.                           (progn
  277.                             (play_sound MGUN_SND 127 (x) (y))
  278.                             (set_course a speed)
  279.                             (link_object me)))
  280.                           (set_aistate (+ (aistate) 1))
  281.                           (jump_state walking))))
  282.                nil))
  283.         (walking (jump_state blocking))
  284.         (blocking (jump_state stopped)))
  285.     T)
  286.     nil)
  287.   )
  288.  
  289.  
  290. (defun rocket_ai ()  
  291.   (if (not (frame_panic))
  292.       (let ((rand (rand_on)))
  293.     (with_object (add_object SMALL_LIGHT_CLOUD (+ (x) (random 3)) 
  294.                  (- (y) (random 3) (/ (picture_height) 2)))
  295.              (set_fade_count 11))
  296.     (set_rand_on rand)))
  297.  
  298.   (if (> (total_objects) 1)  ;; if not attached to object, just fly strait (0 is player)
  299.     (let ((angle (atan2 (- (- (y) (with_object (get_object 1) (y))) -15)
  300.             (- (with_object (get_object 1) (x)) (x) ))))
  301.       (let ((clock_dist (if (< angle (aistate))          ;; calculate clockwise andle distance
  302.                 (- (aistate) angle)
  303.               (+ (aistate) (- 360 angle)))))
  304.     (let ((closest_dist (if (> clock_dist 180) 
  305.                 (- 360 clock_dist)
  306.                   clock_dist)))
  307.       (let ((angle_add (if (> closest_dist 23)
  308.                    23
  309.                  (if (< closest_dist 5)
  310.                  0
  311.                    closest_dist))))
  312.         (if (> clock_dist 180)     ;; should we steer clock wise or counter?
  313.         (set_aistate (mod (+ (aistate) angle_add) 360))
  314.           (set_aistate (mod (+ (- (aistate) angle_add) 360) 360))) )))))
  315.  
  316.   (if (< speed max_speed)
  317.       (setq speed (+ speed 2)))
  318.   (set_course (aistate) speed)
  319.   (set_frame_angle 0 359 (aistate))
  320.   (if (or (eq (hp) 0)
  321.       (not (eq (bmove (if (> (total_objects) 0) (get_object 0) nil)) T)) 
  322.       (and (> (total_objects) 1) 
  323.            (< (abs (- (with_object (get_object 1) (x)) (x) )) 10)
  324.            (< (abs (- (- (with_object (get_object 1) (y)) (y)) 15 )) 10)))
  325.       (progn
  326.     (do_explo 40 50)
  327.     nil)
  328.   T))
  329.       
  330.  
  331. (defun rocket_ufun (creator) 
  332.   (link_object creator)
  333.   (play_sound ROCKET_SND 127 (x) (y))
  334.  
  335.   (let ((target (with_object creator (find_object_in_area 
  336.                       (- (x) 160) (- (y) 160)
  337.                       (+ (x) 160) (+ (y) 160) bad_guy_list))))
  338.     (select (aitype)
  339.         (1 (set_aistate (if (> (with_object creator (direction)) 0) 0 180)))
  340.         (2  (set_aistate (if (> (with_object creator (direction)) 0) 45 135))))
  341.     (if target (link_object target)))
  342.  
  343. )
  344.  
  345.  
  346. (def_char ROCKET
  347.   (funs (ai_fun   rocket_ai)
  348.     (user_fun rocket_ufun))
  349.   (vars speed max_speed)
  350.   (range 10000 10000)
  351.   (flags (unlistable T)
  352.      (hurtable T)
  353.      (add_front T))
  354.   (abilities (start_hp 4))
  355.   (states "art/missle.spe" (stopped  (seq "miss" 1 32))))
  356.  
  357.  
  358. /*
  359. (defun sgun_ai ()
  360.   (setq sgb_lastx (x))
  361.   (setq sgb_lasty (y))
  362.   (setq sgb_speed (/ (* sgb_speed 6) 5))
  363.   (set_course sgb_angle sgb_speed)  
  364.   (if (eq sgb_lifetime 0)
  365.       nil
  366.     (let ((bx (bmove (if (> (total_objects) 0) (get_object 0) nil))))  ; don't hit the guy who fired us.
  367.       (setq sgb_lifetime (- sgb_lifetime 1))
  368.       (if (eq bx T) T
  369.     (progn
  370.       (setq sgb_lifetime 0)    ;; disappear next tick
  371.       (if (eq bx nil)
  372.           (add_object EXPLODE5 (- (x) (random 5)) (- (y) (random 5)) 0)
  373.         (progn
  374.           (add_object EXPLODE3 (- (x) (random 5)) (- (y) (random 5)) 0)
  375.           (do_damage 5 bx (* (cos sgb_angle) 10) (* (sin sgb_angle) 10))))))
  376.       T)))
  377.     */
  378.  
  379.  
  380. (defun sgun_draw ()
  381.   (draw_line sgb_lastx (- sgb_lasty 1) (x) (- (y) 1) sgb_medium_color)
  382.   (draw_line sgb_lastx (+ sgb_lasty 1) (x) (+ (y) 1) sgb_medium_color)
  383.  
  384.   (draw_line (- sgb_lastx 1) sgb_lasty (- (x) 1) (y) sgb_bright_color)
  385.   (draw_line (+ sgb_lastx 1) sgb_lasty (+ (x) 1) (y) sgb_medium_color)
  386.  
  387.  
  388.   (draw_line sgb_lastx sgb_lasty (x) (y) sgb_bright_color)
  389. )
  390.  
  391.  
  392. (defun sgun_ufun (creator) 
  393.   (set_direction (with_object creator (direction)))
  394.   (set_y (- (y) 4))
  395.   (set_x (+ (x) (* (direction) 20)))
  396.   (play_sound ZAP_SND 127 (x) (y))
  397.   (let ((start (if (> (direction) 0) 335 155))
  398.     (end   (if (> (direction) 0) 25 205)))
  399.     (setq sgb_speed 8)
  400.     (setq sgb_lastx (x))
  401.     (setq sgb_lasty (y))
  402.     (let ((target (with_object creator (find_object_in_angle start end bad_guy_list))))
  403.       (if (and target (< (abs (- (x) (with_object target (x)))) 150)
  404.            (< (abs (- (y) (with_object target (y)))) 100))
  405.       (setq sgb_angle (site_angle target))
  406.     (if (> (direction) 0)        
  407.         (setq sgb_angle 0)
  408.       (setq sgb_angle 180)))))
  409.   (link_object creator)
  410. )
  411.  
  412.  
  413. (def_char SHOTGUN_BULLET
  414.   (vars sgb_speed sgb_angle sgb_lastx sgb_lasty 
  415.     sgb_bright_color sgb_medium_color sgb_lifetime)
  416.   (funs (ai_fun   sgun_ai)
  417.     (user_fun sgun_ufun)
  418.     (draw_fun sgun_draw))
  419.   (range 10000 10000)
  420.   (flags (unlistable T)
  421.      (add_front T))
  422.   (states "art/misc.spe" (stopped  "sgun_bullet")))
  423.  
  424.  
  425. (setq load_warn nil)
  426. (if (not (load "register/weapons.lsp"))
  427.     (load "lisp/share.lsp"))
  428. (setq load_warn T)
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.