home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / euphoria / vars.e < prev    next >
Text File  |  1994-01-08  |  8KB  |  285 lines

  1. -- vars.e
  2. -- declarations of global variables and constants
  3.  
  4. global constant TRUE = 1, FALSE = 0
  5.  
  6. global constant CRT = 1 -- output device
  7.  
  8. global constant G_SIZE = 7 -- the galaxy is a G_SIZE x G_SIZE
  9.                -- grid of quadrants
  10.  
  11. global constant INVISIBLE_CHAR = ' ' + 256 -- prints as ' '
  12.                        -- but has different value
  13.  
  14. global type boolean(object x)
  15.     return x = TRUE or x = FALSE
  16. end type
  17.  
  18. global type char(integer c)
  19. -- true if c is a character that can be printed on the screen
  20.     return c >= ' ' and c <= 127 or c = INVISIBLE_CHAR
  21. end type
  22.  
  23. global type byte(integer x)
  24.     return x >= -1 and x <= 255
  25. end type
  26.  
  27. global type natural(integer x)
  28.     return x >= 0
  29. end type
  30.  
  31. global type positive_atom(atom x)
  32.     return x >= 0
  33. end type
  34.  
  35. -----------------------------------------------------------------------------
  36. -- the 2-d quadrant sequence: status of all objects in the current quadrant
  37. -- The first object is always the Euphoria. There will be 0 or more
  38. -- additional objects (planets/bases/enemy ships).
  39. -----------------------------------------------------------------------------
  40. global constant EUPHORIA = 1    -- object 1 is Euphoria
  41.  
  42. global constant QCOLS = 12 -- number of attributes for each object in quadrant
  43. global constant
  44.     Q_TYPE =   1, -- type of object
  45.     Q_EN   =   2, -- energy
  46.     Q_TORP =   3, -- number of torpedos
  47.     Q_DEFL =   4, -- number of deflectors
  48.     Q_FRATE =  5, -- firing rate
  49.     Q_MRATE =  6, -- moving rate
  50.     Q_TARG =   7, -- target
  51.     Q_DOCK =   8, -- docked yet?
  52.     Q_PBX =    9, -- planet/base sequence index
  53.     Q_X =     10, -- x coordinate
  54.     Q_Y =     11, -- y coordinate
  55.     Q_UNDER = 12  -- characters underneath
  56.  
  57. global sequence quadrant
  58. quadrant = repeat(repeat(0, QCOLS), 1)
  59.  
  60. global type valid_quadrant_row(integer x)
  61. -- true if x is a valid row number in the quadrant sequence
  62.     return x >= 1 and x <= length(quadrant)
  63. end type
  64.  
  65. global type quadrant_row(object x)
  66. -- either a quadrant row or -1 or 0 (null value)
  67.     return valid_quadrant_row(x) or x = -1 or x = 0
  68. end type
  69.  
  70. -----------------------------------------------------------------------------
  71. -- the 3-d galaxy sequence: (records number of objects of each type in
  72. --                           each quadrant of the galaxy)
  73. -----------------------------------------------------------------------------
  74. -- first two subscripts select quadrant, 3rd is type...
  75.  
  76. global constant DEAD = 0 -- object that has been destroyed
  77. global constant
  78.     G_EU = 1,   -- Euphoria (marks if Euphoria has been this quadrant)
  79.     G_KRC = 2,  -- K&R C ship
  80.     G_ANC = 3,  -- ANSI C ship
  81.     G_CPP = 4,  -- C++
  82.     G_BAS = 5,  -- basic
  83.     G_FOR = 6,  -- fortran
  84.     G_PL = 7,   -- planet
  85.     G_BS = 8,   -- base
  86.     NTYPES = 8, -- number of different types of (real) object
  87.     G_POD = 9   -- temporary pseudo object
  88.  
  89. global sequence otype
  90.  
  91. global type object_type(integer x)
  92. -- is x a type of object?
  93.     return x >= 1 and x <= NTYPES
  94. end type
  95.  
  96. global sequence galaxy
  97.  
  98. -----------------------------------------------------------------------------
  99. -- the planet/base 2-d sequence (info on each planet and base in the galaxy)
  100. -----------------------------------------------------------------------------
  101. global constant NBASES = 3,  -- number of bases
  102.         NPLANETS = 6 -- number of planets
  103. global constant
  104.     PROWS = NBASES+NPLANETS,
  105.     PCOLS = 9     -- number of planet/base attributes
  106. global constant
  107.     P_TYPE  = 1, -- G_PL/G_BS/DEAD
  108.     P_QR    = 2, -- quadrant row
  109.     P_QC    = 3, -- quadrant column
  110.     P_X     = 4, -- x coordinate within quadrant
  111.     P_Y     = 5, -- y coordinate within quadrant
  112.     P_EN    = 6, -- energy available
  113.     P_TORP  = 7, -- torpedos available
  114.     P_POD   = 8  -- pods available
  115.  
  116. global sequence pb
  117. pb = repeat(repeat(0, PCOLS), PROWS)
  118.  
  119. global type pb_row(integer x)
  120. -- is x a valid row in the planet/base sequence?
  121.     return x >= 1 and x <= PROWS
  122. end type
  123.  
  124. global type g_index(integer x)
  125. -- a valid row or column index into the galaxy sequence
  126.     return x >= 1 and x <= G_SIZE
  127. end type
  128.  
  129. global boolean gameover  -- is game over?
  130.  
  131. global g_index qrow, qcol  -- current quadrant row and column
  132.  
  133. ------------------
  134. -- BASIC status:
  135. ------------------
  136. global constant
  137.     TRUCE    = 0,
  138.     HOSTILE  = 1,
  139.     CLOAKING = 2
  140.  
  141. type basic_status(object x)
  142.     return find(x, {TRUCE, HOSTILE, CLOAKING})
  143. end type
  144.  
  145. global basic_status bstat     -- BASIC status
  146. global quadrant_row basic_targ     -- BASIC group target
  147. global boolean truce_broken      -- was the truce with the BASICs broken?
  148.  
  149. global boolean shuttle -- are we in the shuttle?
  150.  
  151. ----------------------------------------------
  152. -- multiple tasks
  153. -- This game has 10 independent tasks running
  154. ----------------------------------------------
  155. global constant NTASKS = 10 -- number of independent tasks
  156.  
  157. global constant
  158.     TASK_KEYB     = 1, -- keyboard input
  159.     TASK_EMOVE    = 2, -- Euphoria move
  160.     TASK_LIFE     = 3, -- life support energy consumption
  161.     TASK_DEAD     = 4, -- dead body cleanup
  162.     TASK_BSTAT    = 5, -- BASIC status change
  163.     TASK_FIRE     = 6, -- enemy firing
  164.     TASK_MOVE     = 7, -- enemy moving
  165.     TASK_MESSAGE  = 8, -- display messages
  166.     TASK_DAMAGE   = 9, -- damage count-down
  167.     TASK_ENTER    = 10 -- enemy ships enter quadrant
  168.  
  169. global type task(integer x)
  170. -- is x a valid task number?
  171.     return x >= 1 and x <= NTASKS
  172. end type
  173.  
  174. global task current_task -- current task executing
  175. global sequence tcb      -- task activation times
  176. global sequence eat      -- early activation tolerance
  177. global sequence wait     -- waiting time, in seconds, between activations
  178.  
  179. -----------------
  180. -- damage report:
  181. -----------------
  182. global constant NSYS = 5  -- number of systems that can be damaged
  183. global constant ENGINES        = 1,
  184.         TORPEDOS       = 2,
  185.         GUIDANCE       = 3,
  186.         PHASORS        = 4,
  187.         GALAXY_SENSORS = 5
  188.  
  189. global constant dtype = {"ENGINES",
  190.              "TORPEDO LAUNCHER",
  191.              "GUIDANCE SYSTEM",
  192.              "PHASORS",
  193.              "SENSORS"}
  194. global type subsystem(integer x)
  195.     return x >= 1 and x <= NSYS
  196. end type
  197.  
  198. global sequence reptime  -- time to repair a subsystem
  199. reptime = repeat(0, NSYS)
  200.  
  201. type damage_count(integer x)
  202.     return x >= 0 and x <= NSYS
  203. end type
  204.  
  205. global damage_count ndmg
  206.  
  207. --------------
  208. -- warp speed:
  209. --------------
  210. global constant MAX_WARP = 5
  211.  
  212. global type warp(integer x)
  213.     return x >= 0 and x <= MAX_WARP
  214. end type
  215.  
  216. global warp curwarp, wlimit
  217.  
  218. global type direction(atom x)
  219.     return x >= 0 and x < 10
  220. end type
  221.  
  222. global direction curdir -- current direction
  223.  
  224. --------------------------------------
  225. -- Graphic symbols for some objects --
  226. --------------------------------------
  227. global constant
  228.     STAR = '.',
  229.     TORPEDO = '*',
  230.     POD = '@',
  231.     DEFLECTOR = 'D',
  232.     BASE = "<>-<>",         -- both halves
  233.     PLANET_TOP    = INVISIBLE_CHAR & "OOOO" & INVISIBLE_CHAR,
  234.     PLANET_MIDDLE = "OOOOOO",
  235.     PLANET_BOTTOM = INVISIBLE_CHAR & "OOOO" & INVISIBLE_CHAR,
  236.     BASIC_L = "-=##:",
  237.     BASIC_R = ":##=-",
  238.     SHUTTLE_L = "-=:",
  239.     SHUTTLE_R = ":=-",
  240.     EUPHORIA_L = "O-=",
  241.     EUPHORIA_R = "=-O",
  242.     FORTRAN_L = "-+<",
  243.     FORTRAN_R = ">+-",
  244.     KRC_L = "O**<",
  245.     KRC_R = ">**O",
  246.     ANC_L = "-8**<",
  247.     ANC_R = ">**8-",
  248.     CPP_L = "=8**<",
  249.     CPP_R = ">**8="
  250.  
  251. global constant MAX_SHIP_WIDTH = 5 -- widest flying ship width
  252.  
  253. -------------------------------------
  254. -- Euphoria position and direction:
  255. -------------------------------------
  256. type euphoria_x_inc(integer x)
  257.     return x >= -3 and x <= +3
  258. end type
  259.  
  260. type euphoria_y_inc(integer x)
  261.     return x >= -1 and x <= +1
  262. end type
  263.  
  264. global euphoria_x_inc exi
  265. global euphoria_y_inc eyi
  266.  
  267. global sequence esym,   -- euphoria/shuttle symbol
  268.         esyml,  -- euphoria/shuttle facing left
  269.         esymr   -- euphoria/shuttle facing right
  270.  
  271. global sequence nobj  -- number of each type of object in galaxy
  272.  
  273. global positive_atom dist
  274. global valid_quadrant_row shooter
  275. global quadrant_row victim
  276.  
  277. global sequence wipeout
  278. wipeout = {}
  279.  
  280. type game_level(integer x)
  281.     return x = 'n' or x = 'e'
  282. end type
  283. global game_level level
  284.  
  285.