home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / euphor10.zip / DISPLAY.E < prev    next >
Text File  |  1993-06-09  |  8KB  |  350 lines

  1. -- display.e
  2. -- graphics, sound and text display on screen
  3. global sequence ship
  4.  
  5. global sequence ds -- Enterprise deflectors
  6.  
  7. global sequence ts -- Enterprise torpedos
  8.  
  9. global sequence ps -- Enterprise anti-matter pods (roughed in)
  10.  
  11. global function nkl()
  12. -- number of Klingons left
  13.     return nobj[G_SK] + nobj[G_BK] + nobj[G_JM]
  14. end function
  15.  
  16. type negative_atom(atom x)
  17.     return x <= 0
  18. end type
  19.  
  20. global procedure p_energy(negative_atom delta)
  21. -- print Enterprise energy
  22.     atom energy
  23.  
  24.     energy = f[ENTERPRISE][F_EN] + delta
  25.     f[ENTERPRISE][F_EN] = energy
  26.     if energy < 0 then
  27.     energy = 0
  28.     gameover = TRUE
  29.     end if
  30.     position(WARP_LINE, 74)
  31.     set_bk_color(WHITE)
  32.     if energy < 5000 then
  33.     set_color(RED+BLINKING)
  34.     else
  35.     set_color(BLACK)
  36.     end if
  37.     printf(CRT, "%d    ", floor(energy))
  38. end procedure
  39.  
  40. global procedure msg(sequence text)
  41. -- print a message on the bottom line
  42.     set_bk_color(WHITE)
  43.     set_color(RED)
  44.     position(MSG_LINE, 16)
  45.     puts(CRT, BLANK_LINE[1..50])
  46.     position(MSG_LINE, 16)
  47.     puts(CRT, text)
  48. end procedure
  49.  
  50. global procedure show_warp()
  51. -- show current speed (with warning)
  52.     set_bk_color(WHITE)
  53.     set_color(BLACK)
  54.     position(WARP_LINE, 3)
  55.     puts(CRT, "WARP:")
  56.     if curwarp > wlimit then
  57.     set_color(RED+BLINKING)
  58.     end if
  59.     printf(CRT, "%d", curwarp)
  60. end procedure
  61.  
  62. constant warp_time = {0, 20, 4.5, 1.5, .67, .25}
  63.  
  64. global procedure setwarp(warp new)
  65. -- establish a new warp speed for the Enterprise
  66.  
  67.     if new != curwarp then
  68.     wait[TASK_EMOVE] = warp_time[new+1]
  69.     eat[TASK_EMOVE] = (5-new)/20 + 0.05
  70.     sched(TASK_EMOVE, wait[TASK_EMOVE])
  71.     curwarp = new
  72.     show_warp()
  73.     end if
  74. end procedure
  75.  
  76. global procedure gtext()
  77. -- print text portion of galaxy scan
  78.     set_bk_color(BLUE)
  79.     position(1, 36)
  80.     set_color(LIGHT_RED)
  81.     puts(CRT, "C ")
  82.     set_color(BROWN)
  83.     puts(CRT, "P ")
  84.     set_color(YELLOW)
  85.     puts(CRT, "B")
  86.     set_color(WHITE)
  87.     position(2, 7)
  88.     for i = 1 to 7 do
  89.     printf(CRT, "%8d", i)
  90.     end for
  91.     for i = 1 to 7 do
  92.     position(2*i + 1, 9)
  93.     printf(CRT, "%d.", i)
  94.     end for
  95.     position(17, 35)
  96.     set_color(BRIGHT_WHITE)
  97.     printf(CRT, "C: %d ", nkl())
  98.     position(18,22)
  99.     set_color(WHITE)
  100.     printf(CRT, "Planets: %d   BASIC: %d", {nobj[G_PL], nobj[G_RM]})
  101.     if rstat = TRUCE then
  102.     puts(CRT, " TRUCE   ")
  103.     elsif rstat = HOSTILE then
  104.     puts(CRT, " HOSTILE ")
  105.     else
  106.     puts(CRT, " CLOAKING")
  107.     end if
  108.     position(19,22)
  109.     printf(CRT, "Bases: %d     Fortran: %d ", {nobj[G_BS], nobj[G_TH]})
  110. end procedure
  111.  
  112. function g_screen_pos(g_index qrow, g_index qcol)
  113. -- compute position on screen to display a galaxy scan quadrant
  114.     return {4 + qcol * 8, qrow * 2 + 1}
  115. end function
  116.  
  117. global procedure gquad(g_index qrow, g_index qcol)
  118. -- print one galaxy scan quadrant
  119.  
  120.     positive_int nk, np, nb
  121.     sequence quad_info
  122.     screen_pos gpos
  123.  
  124.     gpos = g_screen_pos(qrow, qcol)
  125.     position(gpos[2], gpos[1])
  126.     quad_info = g[qrow][qcol]
  127.     if quad_info[1] then
  128.     nk = quad_info[G_SK] + quad_info[G_BK] + quad_info[G_JM]
  129.     np = quad_info[G_PL]
  130.     nb = quad_info[G_BS]
  131.     set_color(LIGHT_RED)
  132.     printf(CRT, "%d ", nk)
  133.     set_color(BROWN)
  134.     printf(CRT, "%d ", np)
  135.     set_color(YELLOW)
  136.     printf(CRT, "%d",  nb)
  137.     set_color(WHITE)
  138.     else
  139.     puts(CRT, "*****")
  140.     end if
  141. end procedure
  142.  
  143. global procedure upg(g_index qrow, g_index qcol)
  144. -- update galaxy scan quadrant
  145.     if scanon then
  146.     set_bk_color(BLUE)
  147.     set_color(WHITE)
  148.     gquad(qrow, qcol)
  149.     end if
  150. end procedure
  151.  
  152. sequence prev_box
  153. prev_box = {}
  154.  
  155. global procedure gsbox(g_index qrow, g_index qcol)
  156. -- indicate current quadrant on galaxy scan
  157.     screen_pos gpos
  158.  
  159.     if scanon then
  160.     set_bk_color(BLUE)
  161.     if length(prev_box) = 2 then
  162.         -- clear the previous "box" (could be gone already)
  163.         position(prev_box[2], prev_box[1]-1)
  164.         puts(CRT, ' ')
  165.         position(prev_box[2], prev_box[1]+5)
  166.         puts(CRT, ' ')
  167.     end if
  168.     set_color(WHITE)
  169.     gquad(qrow, qcol)
  170.     gpos = g_screen_pos(qrow, qcol)
  171.     position(gpos[2], gpos[1]-1)
  172.     set_color(BRIGHT_WHITE)
  173.     puts(CRT, '[')
  174.     position(gpos[2], gpos[1]+5)
  175.     puts(CRT, ']')
  176.     prev_box = gpos
  177.     end if
  178. end procedure
  179.  
  180. global procedure dsyms()
  181. -- print docking symbols for planets and bases
  182.     screen_pos gpos
  183.  
  184.     return  -- for now
  185.  
  186.     for i = 1 to PROWS do
  187.     gpos = g_screen_pos(pb[i][P_QR], pb[i][P_QC])
  188.     position(gpos[2], gpos[1])
  189.     puts(CRT, ' ')
  190.     end for
  191.  
  192.     for i = 1 to PROWS do
  193.     if pb[i][P_EXIST] = DOCKED_WITH then
  194.             --- TO BE CONTINUED
  195.     end if
  196.     end for
  197.  
  198.     for i = 1 to PROWS do
  199.     if pb[i][P_EXIST] = NEVER_DOCKED then
  200.  
  201.     end if
  202.     end for
  203. end procedure
  204.  
  205. global procedure wtext()
  206. -- print torpedos, pods, deflectors in text window
  207.     set_bk_color(WHITE)
  208.     set_color(BLACK)
  209.     position(WARP_LINE, 34)
  210.     printf(CRT, "%s %s ", {ts, ds, ps}) -- don't show pods yet
  211. end procedure
  212.  
  213. global procedure stext()
  214. -- print text window info
  215.     position(QUAD_LINE, 1)
  216.     set_bk_color(CYAN)
  217.     set_color(MAGENTA)
  218.     printf(CRT,
  219. "--------------------------------- QUADRANT %d.%d ---------------------------------"
  220.        ,{qrow, qcol})
  221.     set_bk_color(WHITE)
  222.     set_color(BLACK)
  223.     show_warp()
  224.     wtext()
  225.     position(WARP_LINE, 67)
  226.     printf(CRT, "ENERGY:%d    ", floor(f[ENTERPRISE][F_EN]))
  227.     position(CMD_LINE, 3)
  228.     puts(CRT, "COMMAND(1-8 w p t g $ @ x): ")
  229. end procedure
  230.  
  231. procedure pxx(valid_f_row row)
  232. -- print a base or planet
  233.     h_coord x
  234.     v_coord y
  235.  
  236.     x = f[row][F_X]
  237.     y = f[row][F_Y]
  238.     if f[row][F_TYPE] = G_PL then
  239.     write_screen(x, y, PLANET_TOP)
  240.     write_screen(x, y+1, PLANET_MIDDLE)
  241.     write_screen(x, y+2, PLANET_BOTTOM)
  242.     else
  243.     write_screen(x, y, BASE)
  244.     write_screen(x, y+1, BASE)
  245.     end if
  246. end procedure
  247.  
  248. procedure p_ship(valid_f_row row)
  249. -- reprint a ship to get color
  250.     h_coord x
  251.     v_coord y
  252.     object_type t
  253.     sequence shape
  254.  
  255.     x = f[row][F_X]
  256.     y = f[row][F_Y]
  257.     t = f[row][F_TYPE]
  258.     shape = read_screen({x, length(ship[t][1])},  y)
  259.     write_screen(x, y, shape)
  260. end procedure
  261.  
  262. procedure refresh_obj()
  263. -- reprint objects with correct color after a galaxy scan
  264.     for i = 1 to fnext-1 do
  265.     if f[i][F_TYPE] = G_BS or f[i][F_TYPE] = G_PL then
  266.         pxx(i)
  267.     elsif f[i][F_TYPE] then
  268.         p_ship(i)
  269.     end if
  270.     end for
  271. end procedure
  272.  
  273. global procedure setg1()
  274. -- end display of galaxy scan
  275.     if scanon then
  276.     scanon = FALSE
  277.     ShowScreen()
  278.     refresh_obj()
  279.     end if
  280. end procedure
  281.  
  282.  
  283. constant PBP0 = 4
  284.  
  285. global procedure pobj()
  286. -- print objects in a new quadrant
  287.     h_coord x
  288.     v_coord y
  289.     sequence c
  290.     positive_int len, pbi
  291.     object_type t
  292.  
  293.     set_bk_color(BLACK)
  294.     set_color(WHITE)
  295.     BlankScreen(TRUE)
  296.  
  297.     -- print stars
  298.     for i = 1 to 15 do
  299.     write_screen(rand(HSIZE), rand(VSIZE), STAR)
  300.     end for
  301.  
  302.     -- print planets and bases
  303.     pbi = PBP0 - 1
  304.     for row = 2 to fr1 - 1 do
  305.     if row = fb1 then
  306.         pbi = 0
  307.     end if
  308.     while TRUE do
  309.         pbi = pbi + 1
  310.         if pb[pbi][P_EXIST] != DESTROYED then
  311.         if pb[pbi][P_QR] = qrow then
  312.             if pb[pbi][P_QC] = qcol then
  313.             x = pb[pbi][P_X]
  314.             y = pb[pbi][P_Y]
  315.             f[row][F_X] = x
  316.             f[row][F_Y] = y
  317.             f[row][F_PBX] = pbi
  318.             exit
  319.             end if
  320.         end if
  321.         end if
  322.     end while
  323.     pxx(row)
  324.     end for
  325.  
  326.     -- print ships
  327.     for row = fr1 to fnext-1 do
  328.     len = length(ship[f[row][F_TYPE]][1])
  329.     while TRUE do
  330.         -- look for an empty place to put the ship
  331.         x = rand(HSIZE - len) + 1
  332.         y = rand(VSIZE - 2) + 1
  333.         c = read_screen({x, len}, y)
  334.         if not find(FALSE, c = ' ' or c = STAR) then
  335.         exit
  336.         end if
  337.     end while
  338.     f[row][F_UNDER] = c
  339.     f[row][F_X] = x
  340.     f[row][F_Y] = y
  341.     t = f[row][F_TYPE]
  342.     if x < f[ENTERPRISE][F_X] then
  343.         c = ship[t][2]
  344.     else
  345.         c = ship[t][1]
  346.     end if
  347.     write_screen(x, y, c)
  348.     end for
  349. end procedure
  350.