home *** CD-ROM | disk | FTP | other *** search
/ PC Gamer 13 / 1995-12_Disc_13.iso / abuse / lisp / ant.lsp next >
Lisp/Scheme  |  1995-08-31  |  16KB  |  607 lines

  1. ;; Copyright 1995 Crack dot Com,  All Rights reserved
  2. ;; See licencing information for more details on usage rights
  3.  
  4. (setq ant_tints (make-array 11 :initial-contents (list 
  5.                         (def_tint "art/tints/ant/green.spe")
  6.                         (def_tint "art/tints/ant/blue.spe") 
  7.                         (def_tint "art/tints/ant/brown.spe")
  8.                         (def_tint "art/tints/ant/egg.spe")
  9.                         (def_tint "art/tints/ant/yellow.spe")
  10.                         (def_tint "art/tints/ant/mustard.spe")
  11.                         (def_tint "art/tints/ant/orange.spe")
  12.                         (def_tint "art/tints/ant/gray.spe")
  13.                         normal_tint
  14.                         normal_tint
  15.                         normal_tint
  16.                         )))
  17.  
  18. /* 
  19. ------ this code has been compiled --------
  20. (defun no_fall_move (xm ym but)
  21.   (move xm ym but))
  22.   (if (not (eq (gravity) 0))         ;; if we are in the air don't check for no fall
  23.       (move xm ym but)
  24.     (let ((oldx (x))
  25.       (oldy (y))
  26.           (ret (move xm ym but)))
  27.       (if (try_move 0 5)
  28.       (progn
  29.         (set_x oldx)
  30.         (set_y oldy)
  31.         (set_xacel 0)
  32.         (set_state stopped)
  33.         (set_xv 0)
  34.         (set_gravity 0)
  35.         0)
  36.     ret))))
  37.         
  38.       
  39. (defun will_fall_if_jump ()
  40.   nil)
  41.   (let ((dist (* (abs (get_ability jump_yvel)) (get_ability jump_xvel)))
  42.     (oldx (x))
  43.     (oldy (y))
  44.     )
  45.     (if (> (direction) 0)
  46.     (set_x (+ (x) dist))
  47.       (set_x (- (x) dist)))
  48.     (if (try_move 0 5)
  49.     (progn
  50.       (set_x oldx)
  51.       (set_y oldy)
  52.       T)
  53.       (progn
  54.     (set_x oldx)
  55.       (set_y oldy)
  56.     nil))))
  57. ^^^^^^ this code has been compiled ^^^^^^^^
  58. */
  59.  
  60.  
  61. (defun strait_rocket_ai ()
  62.   (set_course (aistate) 
  63.           (select difficulty
  64.               ('easy    12)
  65.               ('medium  15)
  66.               ('hard    17)
  67.               ('extreme 22) ))
  68.   (set_frame_angle 0 359 (aistate))
  69.   (let ((stat (bmove nil)))
  70.     (if (eq stat T)
  71.     T
  72.     (progn
  73.       (if (not (eq stat nil))
  74.       (progn 
  75.         (add_object EXPLODE3 (+ (x) (random 5)) (+ (y) (random 5)) 0)
  76.         (add_object EXPLODE2 (+ (x) (random 5)) (+ (y) (random 5)) 2)
  77.         (add_object EXPLODE3 (- (x) (random 5)) (- (y) (random 5)) 1)
  78.         (add_object EXPLODE3 (- (x) (random 5)) (- (y) (random 5)) 2)
  79.         (hurt_radius (x) (+ (y) 20) 25 15 nil 10))
  80.     (let ((myself (me)))
  81.       (with_object (add_object EG_EXPLO (x) (y)) (user_fun myself (car stat)))))
  82.       nil))))
  83.     
  84.  
  85. (def_char STRAIT_ROCKET
  86.   (funs (ai_fun strait_rocket_ai))
  87.   (range 10000 10000)
  88.   (flags (unlistable T))
  89.   (states "art/missle.spe" (stopped    (seq "b32r" 1 32))))
  90.  
  91. (defun animate_ai () (next_picture))
  92.  
  93. (defun eg_explo_ufun (creator block_flags)
  94.   (set_direction (with_object creator (direction)))
  95.   (if block_flags
  96.       (if (or (blocked_left block_flags) (blocked_right block_flags))
  97.       (set_state blocking))))
  98.      
  99. (def_char EG_EXPLO
  100.   (funs (ai_fun   animate_ai)
  101.     (user_fun eg_explo_ufun))
  102.   (range 10000 10000)
  103.   (flags (unlistable T))
  104.   (states "art/missle.spe"
  105.       (stopped  (seq "bifl" 1 4))
  106.       (blocking (seq "bilw" 1 4))))
  107.  
  108. /* 
  109. ------ this code has been compiled --------
  110. (defun alien_wait_time ()
  111.   (select difficulty 
  112.       ('easy    6)
  113.       ('medium  4)
  114.       ('hard    2)
  115.       ('extreme 1)))
  116.  
  117. (defun can_hit_player ()
  118.   (let ((firex (+ (x) (* (direction) 15)) )
  119.     (firey (- (y) 15))
  120.     (playerx (with_object (bg) (x)))
  121.     (playery (- (with_object (bg) (y)) 15)))
  122.     (can_see firex firey playerx playery nil)))
  123.  
  124. (defun not_ant_congestion ()
  125.   (if (> (direction) 0)
  126.       (if (find_object_in_area (+ (x) 23) (- (y) 20) (+ (x) 30) (+ (y) 20) (list ANT_ROOF))
  127.       nil
  128.     T)
  129.     (if (find_object_in_area (- (x) 30) (- (y) 20) (- (x) 23) (+ (y) 20) (list ANT_ROOF))
  130.     nil
  131.       T)))
  132.       
  133.       
  134. (defun roof_above () (not (can_see (x) (y) (x) (- (y) 120) nil)))
  135.  
  136. (defun fire_at_player ()
  137.   (let ((firex (+ (x) (* (direction) 15)) )
  138.     (firey (- (y) 15))
  139.     (playerx (+ (with_object (bg) (x)) (with_object (bg) (* (xvel) 8))))
  140.     (playery (+ (- (with_object (bg) (y)) 15) (with_object (bg) (* (yvel) 2)))))
  141.     
  142.     (if (and (can_see (x) (y) firex firey nil) (can_see firex firey playerx playery nil))
  143.     (progn
  144.       (let ((angle (atan2 (- firey playery)
  145.                   (- playerx firex))))
  146.         (fire_object (me) (aitype) firex firey angle (bg))
  147.         (set_state weapon_fire))
  148.  
  149.       ))))
  150.  
  151. (defun ant_dodge ()
  152.   (if (eq need_to_dodge 1)
  153.       (progn 
  154.     (setq need_to_dodge 0)
  155.     (if (eq (random 2) 1)
  156.         (progn
  157.           (set_state stopped)
  158.           (go_state 6))         ;; jump at player
  159.       (if (roof_above)
  160.           (progn            
  161.         (set_yvel -17)  ;; jump up  
  162.         (set_xvel 0)
  163.         (go_state 12))
  164.         (progn
  165.           (set_yvel -12)  ;; long jump
  166.           (set_xvel (* (direction) 20))
  167.           (set_aistate 6))))
  168.     T
  169.     nil)))
  170.  
  171. (defun scream_check ()
  172.   (if (can_see (x) (y) (with_object (bg) (x)) (with_object (bg) (y)) nil)
  173.       (progn
  174.     (if (or (eq no_see_time 0) (> no_see_time 20))
  175.       (play_sound ASCREAM_SND 127 (x) (y)))
  176.     (setq no_see_time 1))
  177.     (setq no_see_time (+ no_see_time 1))))
  178.  
  179. (defun ant_ai ()
  180.       (push_char 30 20)
  181.       (if (or (eq (state) flinch_up) (eq (state) flinch_down))
  182.       (progn (next_picture) T)
  183.     (progn
  184.  
  185.       (select (aistate)
  186.           (0   (set_state hanging)
  187.                (if (eq hide_flag 0)
  188.                (set_aistate 15)
  189.              (set_aistate 16)))
  190.  
  191.           (15 ;; hanging on the roof waiting for the main character           
  192.            (if (next_picture) T (set_state hanging))
  193.            (if (if (eq (total_objects) 0);; no sensor, wait for guy
  194.                (and (< (distx) 130) (< (y) (with_object (bg) (y))))
  195.              (not (eq (with_object (get_object 0) (aistate)) 0)))
  196.                (progn 
  197.              (set_state fall_start)             (set_direction (toward))
  198.              (set_aistate 1))))
  199.  
  200.           (16 ;; hiding
  201.            (set_state hiding)
  202.            (if (if (eq (total_objects) 0);; no sensor, wait for guy
  203.                (and (< (distx) 130) (< (y) (with_object (bg) (y))))
  204.              (not (eq (with_object (get_object 0) (aistate)) 0)))
  205.                (progn 
  206.              (set_state fall_start)             (set_direction (toward))
  207.              (set_aistate 1))))
  208.  
  209.           (1 ;; falling down
  210.            (set_state falling)
  211.            (scream_check)
  212.            (if (blocked_down (move 0 0 0))
  213.                (progn
  214.              (set_state landing)
  215.              (play_sound ALAND_SND 127 (x) (y))
  216.              (set_aistate 9))))
  217.  
  218.           (9 ;; landing / turn around (gerneal finish animation state)
  219.            (if (next_picture) T
  220.              (if (try_move 0 2)    
  221.              (progn
  222.                (set_gravity 1)
  223.                (set_aistate 1))
  224.                (progn (set_state stopped)              
  225.                   (go_state 2)))))  ;; running
  226.  
  227.           (2 ;; running
  228.            (scream_check)
  229.            (if (eq (random 20) 0) (setq need_to_dodge 1))
  230.            (if (not (ant_dodge))
  231.              (if (eq (facing) (toward))
  232.              (progn
  233.                (next_picture)
  234.                (if (and (eq (random 5) 0) (< (distx) 180) (< (disty) 100) (can_hit_player))
  235.                    (progn
  236.                  (set_state weapon_fire)
  237.                  (set_aistate 8))  ;; fire at player
  238.                  (if (and (< (distx) 100) (> (distx) 10) (eq (random 5) 0))
  239.                  (set_aistate 4)  ;; wait for pounce
  240.  
  241.                    (if (and (> (distx) 140)
  242.                     (not_ant_congestion)
  243.                     (not (will_fall_if_jump)))
  244.                    (set_aistate 6)
  245.  
  246.                  (if (> (direction) 0)
  247.                      (if (and (not_ant_congestion) (blocked_right (no_fall_move 1 0 0)))
  248.                      (set_direction -1))
  249.                    (if (and (not_ant_congestion) (blocked_left (no_fall_move -1 0 0)))
  250.                        (set_direction 1)))))))
  251.                (progn
  252.                  (set_direction (toward))
  253.                  (set_state turn_around)
  254.                  (set_aistate 9)))))
  255.           
  256.           (4 ;; wait for pounce
  257.            (if (ant_dodge) T
  258.              (progn
  259.                (set_state pounce_wait)
  260.                (move 0 0 0)
  261.                (if (> (state_time) (alien_wait_time))
  262.                (progn
  263.                  (play_sound ASLASH_SND 127 (x) (y))
  264.                  (set_state stopped)
  265.                  (go_state 6))))))
  266.  
  267.           (6 ;; jump          
  268.            (setq need_to_dodge 0)
  269.            (if (blocked_down (move (direction) -1 0))
  270.                (progn
  271.              (set_aistate 2))))
  272.  
  273.           (8 ;; fire at player
  274.            (if (ant_dodge) T             
  275.              (if (eq (state) fire_wait)
  276.              (if (next_picture)
  277.                  T
  278.                (progn
  279.                  (fire_at_player)
  280.                  (set_state stopped)
  281.                  (set_aistate 2)))
  282.                (set_state fire_wait))))
  283.  
  284.           (12 ;; jump to roof
  285.            (setq need_to_dodge 0)
  286.            (set_state jump_up)
  287.            (set_yvel (+ (yvel) 1))
  288.            (set_xacel 0)
  289.            (let ((top (- (y) 31))
  290.              (old_yvel (yvel))
  291.              (new_top (+ (- (y) 31) (yvel))))
  292.              (let ((y2 (car (cdr (see_dist (x) top (x) new_top)))))
  293.                (try_move 0 (- y2 top) nil)
  294.                (if (not (eq y2 new_top))
  295.                (if (> old_yvel 0)
  296.                  (progn
  297.                    (set_state stopped)
  298.                    (set_aistate 2))
  299.                (progn
  300.                  (set_state top_walk)
  301.                  (set_aistate 13)))))))
  302.  
  303.           (13 ;; roof walking
  304.            (scream_check)
  305.            (if (or (and (< (y) (with_object (bg) (y))) 
  306.                 (< (distx) 10) (eq (random 8) 0)) 
  307.                (eq need_to_dodge 1))  ;; shooting at us, fall down
  308.                (progn
  309.              (set_gravity 1)
  310.              (set_state run_jump)
  311.              (go_state 6))
  312.              (progn
  313.                (if (not (eq (facing) (toward)))        ;; run toward player
  314.                (set_direction (- 0 (direction))))
  315.                (if (and (< (distx) 120) (eq (random 5) 0))
  316.                (progn
  317.                  (set_state ceil_fire)
  318.                  (go_state 14))
  319.              (let ((xspeed (if (> (direction) 0) (get_ability run_top_speed)
  320.                      (- 0 (get_ability run_top_speed)))))
  321.                (if (and (can_see (x) (- (y) 31) (+ (x) xspeed) (- (y) 31) nil)
  322.                     (not (can_see (+ (x) xspeed) (- (y) 31) 
  323.                           (+ (x) xspeed) (- (y) 32) nil)))
  324.                    (progn
  325.                  (set_x (+ (x) xspeed))
  326.                  (if (not (next_picture)) 
  327.                      (set_state top_walk)))
  328.                  (set_aistate 1)))))))
  329.  
  330.     
  331.           (14 ;; cieling shoot
  332.            (if (next_picture)
  333.                T
  334.              (progn
  335.                (fire_at_player)
  336.                (set_state top_walk)
  337.                (set_aistate 13))))
  338.  
  339.           )))
  340.       
  341.       T)
  342. */   
  343.  
  344.  
  345. (defun create_dead_parts (array part_num type)
  346.   (let ((dir  (direction))
  347.     (rand (rand_on)))
  348.     (with_object (add_object (aref array part_num) (x) (y))
  349.            (progn (set_aitype type)
  350.               (set_xvel (* dir (random 10)))
  351.               (set_yvel (- 0 (random 25)))))
  352.     (with_object (add_object (aref array (+ part_num 1)) (x) (y))
  353.            (progn (set_aitype type)
  354.               (set_xvel (* dir (random 10)))
  355.               (set_yvel (- 0 (random 25)))))
  356.     (with_object (add_object (aref array (+ part_num 2)) (x) (y))
  357.            (progn (set_aitype type)
  358.               (next_picture)                        ;; unsync the animations
  359.               (set_xvel (* dir (random 10)))
  360.               (set_yvel (- 0 (random 25)))))
  361.     (with_object (add_object (aref array (+ part_num 2)) (x) (y))
  362.            (progn (set_aitype type)
  363.               (next_picture)
  364.               (next_picture)
  365.               (set_xvel (* dir (random 10)))
  366.               (set_yvel (- 0 (random 25)))))
  367.     (with_object (add_object (aref array (+ part_num 2)) (x) (y))
  368.            (progn (set_aitype type)
  369.               (next_picture)
  370.               (next_picture)
  371.               (next_picture)
  372.               (set_xvel (* dir (random 10)))
  373.               (set_yvel (- 0 (random 25)))))
  374.     (set_rand_on rand)))   ;; restore random table, in case this didn't get called because of frame panic
  375.  
  376.  
  377. (enum 'decay_part
  378.       'flaming_part
  379.       'electric_part
  380.       'normal_part)
  381.       
  382. (defun get_dead_part (from)
  383.   (if from
  384.       (let ((type (with_object from (otype))))
  385.     (if (or (eq type GRENADE) (eq type ROCKET) (eq type FIREBOMB))
  386.         flaming_part
  387.       (if (or (eq type PLASMAGUN_BULLET) (eq type LSABER_BULLET))
  388.           electric_part
  389.         normal_part)))
  390.     normal_part)
  391.  
  392. )
  393.  
  394.  
  395. (defun ant_damage (amount from hitx hity push_xvel push_yvel)  ; transfer damage to lower half
  396.  
  397.   (if (and (not (eq (state) dead))
  398.        (or (not from) 
  399.            (with_object from (if (eq (total_objects) 0) 
  400.                      (not (eq (otype) ANT_ROOF))
  401.                    (with_object (get_object 0) (not (eq (otype) ANT_ROOF)))))))
  402.       (if (not (eq (aistate) 15))
  403.       (progn
  404.         (if (eq (random 2) 0)
  405.         (set_state flinch_up)
  406.           (set_state flinch_down))
  407.         (damage_fun amount from hitx hity push_xvel push_yvel)
  408.         (play_sound APAIN_SND 127 (x) (y))
  409.         (setq need_to_dodge 1)        
  410.         (if (<= (hp) 0)
  411.         (progn
  412.           (if (eq (aitype) 0)
  413.               (play_sound (aref ASML_DEATH (random 2)) 127 (x) (y))
  414.             (play_sound (aref ALRG_DEATH (random 3)) 127 (x) (y)))
  415.  
  416.           (set_state dead)
  417.           (if (eq (random (select difficulty
  418.                       ('easy 2)
  419.                       ('medium 3)
  420.                       ('hard   4)
  421.                       ('extreme 10))) 0)
  422.               (if (eq (random 4) 0)
  423.               (add_object (aitype_to_ammo (+ (aitype) 1)) (x) (y)))
  424.             (add_object (aitype_to_ammo (aitype)) (x) (y)))
  425.           (create_dead_parts ant_dead_parts (* (get_dead_part from) 3) (aitype)))
  426.           )))))
  427.  
  428. (defun ant_cons ()
  429.   (setq no_see_time 300))
  430.  
  431. (defun ant_ct ()
  432.   (select (aitype)
  433.       (0 (set_hp 15))
  434.       (1 (set_hp 50))
  435.       (2 (set_hp 25))
  436.       (3 (set_hp 35))
  437.       (4 (set_hp 35))
  438.       (5 (set_hp 20))
  439.  
  440.       ))
  441.  
  442.  
  443. (defun ant_draw ()
  444.   (if (eq 0 (aitype))
  445.       (draw)
  446.     (draw_tint (aref ant_tints (aitype)))))
  447.  
  448. (def_char ANT_ROOF
  449.   (vars need_to_dodge
  450.     no_see_time
  451.     hide_flag)
  452.   (fields
  453.       ("hide_flag"    "hiden (1=true,0=false)")
  454.       ("fade_count"   "fade count")
  455.       ("aitype"       "aitype")
  456.       ("hp"           "health")
  457.       ("aistate"      "aistate"))
  458.   (range 250 20)
  459.   (draw_range 40 40)
  460.   (funs (ai_fun     ant_ai)    
  461.     (draw_fun   ant_draw)
  462.     (constructor ant_cons)
  463.     (type_change_fun ant_ct)
  464.     (damage_fun ant_damage))
  465.  
  466.   (abilities (run_top_speed   7)
  467.          (start_hp       20)
  468.          (stop_acel      20)
  469.          (start_acel     20)
  470.          (jump_yvel      -4)
  471.          (jump_xvel      20)
  472.          (push_xrange     1)
  473.          (jump_top_speed 20))
  474.   
  475.   (flags (hurtable  T)
  476.      (force_health T))
  477.  
  478.   (states "art/ant.spe" 
  479.       (hanging (rep "ant" 2))
  480.  
  481.       (fall_start "affc0001.pcx")
  482.       (falling    "affc0002.pcx")
  483.       
  484.       (stopped "awlk0001.pcx")
  485.       (running (seq "awlk" 1 10))
  486.       (landing (seq "acff" 1 4))
  487.       (pounce_wait "acff0001.pcx")
  488.       (turn_around (seq "atrn" 1 5))
  489.  
  490.       (run_jump "dive")
  491.       (run_jump_fall "dive")
  492.       (start_run_jump "dive")
  493.       (fire_wait (seq "wait" 1 3))
  494.  
  495.       (ceil_fire (seq "cfire" 1 3))
  496.       (top_walk  (seq "awkc" 1 10))
  497.       (flinch_up (rep "afh10001.pcx" 2))
  498.       (flinch_down (rep "afh20001.pcx" 2))
  499.       (blown_back_dead     "adib0009.pcx")
  500.       (jump_up            "ajmp.pcx")
  501.       (hiding             "hidden")
  502.       (dead             "hidden")
  503.       (weapon_fire  (seq "asht" 2 5))))
  504.  
  505.  
  506. (def_char HIDDEN_ANT
  507.   (funs (ai_fun     ant_ai)
  508.     (draw_fun   dev_draw))
  509.   (vars need_to_dodge
  510.     no_see_time
  511.     hide_flag)
  512.   (states "art/ant.spe" (stopped "hidden")))
  513.  
  514.   
  515.  
  516.  
  517. (defun crack_ai ()
  518.   (if (eq (aistate) 0)
  519.       (if (if (eq (total_objects) 0)
  520.           (and (< (distx) 50) (< (disty) 70))
  521.         (with_object (get_object 0) (not (eq (aistate) 0))))
  522.       (set_aistate 1))
  523.     (select (current_frame)
  524.         (4 nil)
  525.         (3
  526.          (let ((d (direction))
  527.            (type (aitype)))
  528.            (if (or (eq create_total 0) (eq create_total 1))          
  529.            (set_current_frame 4)
  530.          (progn
  531.            (setq create_total (- create_total 1))
  532.            (set_current_frame 0)))
  533.            (with_object (add_object_after ANT_ROOF (+ (x) (* (direction) 20)) (y))
  534.                 (progn
  535.                   (set_aitype type)
  536.                   (set_direction d)
  537.                   (set_xvel (* d 20))
  538.                   (set_state run_jump)
  539.                   (set_aistate 6)))
  540.            ))
  541.         (0 (next_picture))
  542.         (1 (next_picture))
  543.         (2 (next_picture))))
  544.   T)
  545.         
  546.  
  547. (defun crack_cons ()
  548.   (setq create_total 1)
  549.   (set_aitype 1))
  550.  
  551.  
  552. (def_char ANT_CRACK
  553.   (funs (ai_fun crack_ai)
  554.     (draw_fun ant_draw)
  555.     (constructor crack_cons))
  556.   (range 250 0)
  557.   (vars create_total)
  558.   (fields ("create_total" "total")
  559.       ("aitype"  "type (0..7)"))
  560.   (states "art/ant.spe"
  561.       (stopped (seq "aisw" 2 6))))
  562.  
  563.  
  564. (defun head_ai ()
  565.   (select (aistate)
  566.       (0 ;; falling
  567.        (next_picture)
  568.        (set_yvel (+ (yvel) 3))
  569.        (bounce_move T T T '(progn (set_state dieing) (set_aistate 1)) T)
  570.        (or (< (state_time) 15)
  571.            (not (frame_panic))))          
  572.       (1 ;; hit the ground
  573.        nil)
  574.       ))
  575.  
  576. (setq ant_dead_parts (make-array (* 3 4) :initial-contents 
  577.                  '((AD_1  "adbn") (AD_2  "adha") (AD_3  "adla")     ; disapear
  578.                    (AD_4  "adaf") (AD_5  "adah") (AD_6  "adlf")     ; flaming
  579.                    (AD_7  "adbe") (AD_8  "adhe") (AD_9  "adle")     ; electrical
  580.                    (AD_10 "adan") (AD_11 "adhn") (AD_12 "adln"))))  ; normal
  581.  
  582.  
  583. (defun make_dead_part (sym base frames filename draw)
  584.   (eval `(def_char ,sym
  585.        (range 100 100)
  586.        (funs (ai_fun    head_ai)
  587.          (draw_fun  ,draw))
  588.        (flags (unlistable T))
  589.        (states filename
  590.           (stopped (seq base 1 ,frames))))))
  591.  
  592.  
  593. (do ((i 0 (setq i (+ i 1))))
  594.        ((>= i 12) nil)
  595.        (setq (aref ant_dead_parts i) 
  596.          (make_dead_part (car (aref ant_dead_parts i))
  597.                  (car (cdr (aref ant_dead_parts i))) 4 "art/ant.spe" 'ant_draw)))
  598.  
  599.  
  600. (setq load_warn nil)
  601. (if (not (load "register/ant.lsp"))
  602.     (setq BOSS_ANT ANT_ROOF))
  603. (setq load_warn T)
  604.  
  605.  
  606.  
  607.