# Monster sensors # Sensor.tz (c) 2010 Jacob Schrum. # See Simulation.tz for more copyright information @define SENSOR_LENGTH 7. # Sensor types @define SENSOR_PLAYER 0. @define SENSOR_MONSTER 1. @define SENSOR_SWORD 2. @define SENSOR_WALL 3. @define SENSOR_BULLET 4. Mobile : Sensor { + variables: owner (object). orientation (double). colliding (int). # agent: instance of Agent that will have the Sensor # theAngle: position around the agent to place the sensor (radians) + to attach to agent (object) at theAngle (double): owner = agent. orientation = -theAngle. + to init: self set-color to ((controller get-graphics) get-sensor-color). self set-shape to ((controller get-graphics) get-sensor-shape). self handle-collisions with-type "Player" with-method "sense-player". self handle-collisions with-type "Monster" with-method "sense-monster". self handle-collisions with-type "Sword" with-method "sense-sword". self handle-collisions with-type "Wall" with-method "sense-wall". self handle-collisions with-type "Bullet" with-method "sense-bullet". colliding = 0. if ((controller get-commandline) bit-param named "invisible-sensors") : { self make-invisible. self disable-shadows. } + to iterate: if !colliding : self set-color to ((controller get-graphics) get-sensor-color). self set-rotation around-axis (((controller get-math) get-turn-matrix with-angle (orientation + (PI / 2))) * (owner get-facing)) by (PI / 2). self move to ((owner get-location) + (((controller get-commandline) num-param named "sensor-length") - 1)*(((controller get-math) get-turn-matrix with-angle orientation) * (owner get-facing))). colliding = 0. } Sensor : BinarySensor { + variables: memory-cells (list). absent (int). + to clear-memory: absent = (- ((controller get-commandline) bit-param named "absence-negative")). memory-cells = {absent,absent,absent,absent,absent}. + to init: self clear-memory. + to attach to agent (object) at theAngle (double): super attach to agent at theAngle. self clear-memory. + to access-memory cell id (int): temp (int). temp = memory-cells{id}. memory-cells{id} = absent. return temp. + to sense cell id (int) contact item (object): # Assure proper coloration colliding = 1. # Assure proper sensing memory-cells{id} = 1. self set-color to (item get-color). # player: the Player + to sense-player this player (object): self sense cell SENSOR_PLAYER contact player. # monster: a Monster + to sense-monster this monster (object): self sense cell SENSOR_MONSTER contact monster. # sword: a Sword + to sense-sword this sword (object): self sense cell SENSOR_SWORD contact sword. # wall: a Wall + to sense-wall this wall (object): self sense cell SENSOR_WALL contact wall. # bullet: a Bullet in shooting mode + to sense-bullet this bullet (object): self sense cell SENSOR_BULLET contact bullet. } Sensor : DistanceSensor { + variables: inverse-distance-monster (double). inverse-distance-player (double). inverse-distance-sword (double). inverse-distance-wall (double). + to init: inverse-distance-monster = 0. inverse-distance-player = 0. inverse-distance-sword = 0. inverse-distance-wall = 0. + to get-inverse-distance to agent (object): return (1.0 / (1.0 + ( |(owner get-location) - (agent get-location)| ) ) ). + to access-player-memory: temp (double). temp = inverse-distance-player. inverse-distance-player = 0. return temp. + to access-monster-memory: temp (double). temp = inverse-distance-monster. inverse-distance-monster = 0. return temp. + to access-sword-memory: temp (double). temp = inverse-distance-sword. inverse-distance-sword = 0. return temp. + to access-wall-memory: temp (double). temp = inverse-distance-wall. inverse-distance-wall = 0. return temp. # player: the Player + to sense-player this player (object): # Assure proper coloration colliding = 1. # Assure proper sensing inverse-distance-player = (self get-inverse-distance to player). self set-color to (player get-color). # monster: a Monster + to sense-monster this monster (object): # Assure proper coloration colliding = 1. # Assure proper sensing inverse-distance-monster = (self get-inverse-distance to monster). self set-color to (monster get-color). # sword: a Sword + to sense-sword this sword (object): # Assure proper coloration colliding = 1. # Assure proper sensing inverse-distance-sword = (self get-inverse-distance to sword). self set-color to (sword get-color). # wall: a Wall + to sense-wall this wall (object): # Assure proper coloration colliding = 1. # Assure proper sensing inverse-distance-wall = (self get-inverse-distance to wall). self set-color to (wall get-color). }