Definitions for combat-world-2



;; Light is a type of electromagnetic radiation; visible-light
;; and infrared are types of light; low- and high-infrared are
;; types of infrared raidation; predator-alarm is a type of sound.

(define-radiation-types
  (light (electromagnetic))
  (visible-light (light))
  (infrared (light))
  (low-infrared (infrared))
  (high-infrared (infrared))
  (predator-alarm (sound)))


;; Instantiate two yellow lamps, each radiating visible light
;; at a constant intensity.

(lamp lamp-1
  (:position 0.0 0.0)
  (:color 1.0 1.0 0.0)
  (:radiator r1
    (:radiation-type visible-light)
    (:decay-factor 0.05)))

(lamp lamp-2
  (:position -4.0 -4.0)
  (:color 1.0 1.0 0.0)
  (:radiator r1
    (:radiation-type visible-light)
    (:decay-factor 0.05)))


;; Define the simple-light-seeker vehicle type.
;; Homes in on visible light; motors radiate in low infrared.

(define-vehicle simple-light-seeker
  (:sensor s1
    (:orientation -30)
    (:radiation-type visible-light)
    (:sensitivity 3.0))
  (:sensor s2
    (:orientation 30)
    (:radiation-type visible-light)
    (:sensitivity 3.0))
  (:motor m1
    (:position right)
    (:decay-factor 0.1))
  (:motor m2
    (:position left)
    (:decay-factor 0.1))
  (:radiator r1
    (:radiation-type low-infrared)
    (:decay-factor .05))
  (:brain
    (r1 (:inputs (m1 m2)))
    (m1 (:inputs (s2)))
    (m2 (:inputs (s1)))))


;; Instantiate two green simple-light-seekers; name them
;;  simple-light-seeker-1 and simple-light-seeker-2.

(vehicle simple-light-seeker-1 simple-light-seeker
  (:position 5.0 -2.5)
  (:orientation 0)
  (:max-speed 15)
  (:color 0 1.0 0))
         
(vehicle simple-light-seeker-2 simple-light-seeker
  (:position -6.0 -3)
  (:orientation 0)
  (:max-speed 15)
  (:color 0 1.0 0))


;; Define the heat-seeker vehicle type.
;;
;; Sensors are sensitive to low infrared, motors radiate high infrared.
;; Has three long-range forward-facing lasers that fire approximately
;; when a target signal is centered in the field of view of the forward
;; sensors.

(define-vehicle heat-seeker
  (:sensor s1
    (:orientation -40)
    (:radiation-type low-infrared)
    (:sensitivity 10.0))
  (:sensor s2
    (:orientation 40)
    (:radiation-type low-infrared)
    (:sensitivity 10.0))
  (:motor m1
    (:position right)
    (:decay-factor 0.1))
  (:motor m2
    (:position left)
    (:decay-factor 0.1))
  (:radiator r1
    (:radiation-type high-infrared)
    (:decay-factor .05))
  (:gun g1
    (:range 3))
  (:gun g2
    (:range 3)
    (:orientation -20))
  (:gun g3
    (:range 3)
    (:orientation 20))
  (:brain
   (n1 (:inputs (s1))
       (:inhibitors (g1))
       (:threshold 1))
   (n2 (:inputs (s2))
       (:inhibitors (g1))
       (:threshold 1))
   (m2 (:inputs (n1)))
   (m1 (:inputs (n2)))
   (r1 (:inputs (m1 m2)))
   (a1 (:threshold 1.8)
       (:inputs (m1 m2))
       (:inhibitors (g1)))
   (a3 (:threshold 2.8)
       (:inputs (a1 m1 m2))
       (:inhibitors (g1)))
   (a2 (:threshold 3.8)
       (:inputs (m1 m2 a1 a3))
       (:inhibitors (g1)))
   (g1 (:inputs (a2)))
   (g2 (:inputs (a2)))
   (g3 (:inputs (a2)))))


;; Instantiate two red heat-seekers; name them heat-seeker-1 and heat-seeker-2.

(vehicle heat-seeker-1 heat-seeker
  (:position -7.0 6.0)
  (:orientation 0.0)
  (:max-speed 15.0)
  (:color 1.0 0 0))

(vehicle heat-seeker-2 heat-seeker
  (:position 7.0 6.0)
  (:orientation 0.0)
  (:max-speed 15.0)
  (:color 1.0 0 0))


;; Define the non-linear-shy-seeker type.
;;
;; This vehicle's basic characteristics are that it has a preferred distance
;; from visible light sources and that its motors radiate in low infrared (so
;; predators can see it).
;;
;; But it also has defensive capabilities: A single short-range laser facing
;; rearward.   When the vehicle's sensors detect enough high-infrared (radiated
;; by predator motors) it will broadcast an intense pulse of "predator-alert"
;; radiation and fire its laser.  Other non-linear-shy-seekers that detect the
;; predator-alert will also fire their lasers.

(define-vehicle non-linear-shy-seeker
  (:sensor s1
    (:orientation 30)
    (:radiation-type visible-light)
    (:sensitivity 4.0))
  (:sensor s2
    (:orientation -30)
    (:radiation-type visible-light)
    (:sensitivity 4.0))

  (:sensor s3
    (:orientation 50)
    (:radiation-type high-infrared)
    (:sensitivity 2.0))
  (:sensor s4
    (:orientation -50)
    (:radiation-type high-infrared)
    (:sensitivity 2.0))
  
  (:sensor alarm-sensor
    (:radiation-type predator-alarm)
    (:sensitivity 100.0))

  (:gun g1
    (:orientation 180)
    (:range 1))

  (:motor m1
    (:position left)
    (:decay-factor 0.1))
  (:motor m2
    (:position right)
    (:decay-factor 0.1))

  (:radiator r1
    (:radiation-type low-infrared)
    (:decay-factor .05))

  (:radiator alarm
    (:radiation-type predator-alarm)
    (:decay-factor 0))

  (:brain

   ;; Light-seeking behavior
   (n1 (:inputs (s1))
       (:inhibitors (n2))
       (:threshold 1))
   (n1.5 (:inputs (s1))
         (:threshold 1))
   (n2 (:inputs (n1.5))
       (:threshold 1))
   (m2 (:inputs (n1 s4)))

   ;; Predator avoidance behavior
   (n3 (:inputs (s2))
       (:threshold 1))
   (n3.5 (:inputs (s2))
         (:threshold 1))
   (n4 (:inputs (n3.5))
       (:inhibitors (n3))
       (:threshold 1))
   (m1 (:inputs (n4 s3)))

   (predator (:inputs (n1 n4))
             (:inhibitors (g1))
             (:threshold 2))
                      
   (g1 (:inputs (predator alarm-sensor))
       (:inhibitors (g1))
       (:threshold 1))

   (alarm (:inputs (predator)))
   
   (r1 (:inputs (m1 m2)))))


;; Instantiate three blue non-linear-shy-seekers; name them
;; shy-1, shy-2 and shy-3.

(vehicle shy-1 non-linear-shy-seeker
  (:position 4.0 -5.0)
  (:orientation 294)
  (:color 0 0 1.0))

(vehicle shy-2 non-linear-shy-seeker
  (:position 4.0 5.0)
  (:orientation 294)
  (:color 0 0 1.0))

(vehicle shy-3 non-linear-shy-seeker
  (:position -4.0 -5.0)
  (:orientation 294)
  (:color 0 0 1.0))