home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / apilot.lha / APilot / APilot_Ser / map.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-03  |  22.6 KB  |  676 lines

  1. /**************************************************************************
  2.  *
  3.  * map.c -- Functions for reading and drawing the map into
  4.  *          memory.
  5.  *
  6.  *-------------------------------------------------------------------------
  7.  * Authors: Casper Gripenberg  (casper@alpha.hut.fi)
  8.  *          Kjetil Jacobsen  (kjetilja@stud.cs.uit.no)
  9.  *
  10.  */
  11.  
  12. /*------------------------------------------------------------------------*/
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <ctype.h>
  17. #include <string.h>
  18. #include <math.h>
  19. #include <intuition/intuition.h>
  20. #include <libraries/dos.h>          /* Official return codes defined here */
  21.  
  22. #include <proto/intuition.h>
  23. #include <proto/graphics.h>
  24.  
  25. #include "map_protos.h"
  26. #include "main_protos.h"
  27. #include "misc_protos.h"
  28. #include "lists_protos.h"
  29. #include "cannon_protos.h"
  30. #include "fuelpod_protos.h"
  31. #ifndef PURE_OS
  32. #include "hline_protos.h"
  33. #endif
  34.  
  35. #include "prefs.h"
  36. #include "common.h"
  37. #include "fuelpod.h"
  38. #include "misc.h"
  39.  
  40. /*------------------------------------------------------------------------*/
  41.  
  42. #define MAXKEYWORD 80   /* Max length of any keyword in the mapfile  */
  43.  
  44. extern AWorld World;    /* From main */
  45. char   **map_file;      /* Here every mapline will be put separately */
  46.  
  47. #define TBLSIZE ('z'-'a')
  48.  
  49. #define up_tbl(ch) u_tbl['z' - tolower(ch)]
  50. #define dn_tbl(ch) d_tbl['z' - tolower(ch)]
  51. #define le_tbl(ch) l_tbl['z' - tolower(ch)]
  52. #define ri_tbl(ch) r_tbl['z' - tolower(ch)]
  53.  
  54. #define test_u(ch) ((ch) < 'a' || (ch) > 'z' ? TRUE : up_tbl(ch))
  55. #define test_d(ch) ((ch) < 'a' || (ch) > 'z' ? TRUE : dn_tbl(ch))
  56. #define test_l(ch) ((ch) < 'a' || (ch) > 'z' ? TRUE : le_tbl(ch))
  57. #define test_r(ch) ((ch) < 'a' || (ch) > 'z' ? TRUE : ri_tbl(ch))
  58.  
  59. /*------------------------------------------------------------------------*/
  60.  
  61. /*
  62.  * Maptables:
  63.  * These determine when to draw lines based on what is around
  64.  * a certain map point. A small kludge. Maybe I'll think of something
  65.  * more elegant later.. Atleast malloc the tables..
  66.  */
  67. void
  68. init_maptables(BOOL u_tbl[], BOOL d_tbl[], BOOL l_tbl[], BOOL r_tbl[])
  69. {
  70.   int i;
  71.  
  72.   for (i = 0; i < TBLSIZE; i++) {
  73.     u_tbl[i] = TRUE;
  74.     d_tbl[i] = TRUE;
  75.     l_tbl[i] = TRUE;
  76.     r_tbl[i] = TRUE;
  77.   }
  78.  
  79.   up_tbl('x') = FALSE;
  80.   up_tbl('q') = FALSE;
  81.   up_tbl('w') = FALSE;
  82.  
  83.   dn_tbl('x') = FALSE;
  84.   dn_tbl('a') = FALSE;
  85.   dn_tbl('s') = FALSE;
  86.  
  87.   le_tbl('x') = FALSE;  
  88.   le_tbl('q') = FALSE;
  89.   le_tbl('a') = FALSE;
  90.   
  91.   ri_tbl('x') = FALSE;
  92.   ri_tbl('w') = FALSE;
  93.   ri_tbl('s') = FALSE;
  94. }
  95.  
  96. /*------------------------------------------------------------------------*/
  97.  
  98. /*
  99.  * init_map -- Should be partially compatible with xpilot mapfiles.
  100.  *
  101.  */
  102. void
  103. init_map( void )
  104. {
  105.   FILE *map_fh;
  106.   int i, x, y; 
  107.   int line      = 0;
  108.   char *char_chunk;
  109.   char line_buf[MAXLINE];
  110.   char keyword[MAXKEYWORD];
  111.   char argument[MAXKEYWORD];
  112.   MAP_Point *point_chunk;
  113.  
  114.   if ( !(map_fh = fopen(prefs.mapname, "r")) )
  115.     cleanExit( RETURN_WARN, "** Mapfile '%s' not found\n", prefs.mapname );
  116.  
  117.   /*
  118.    * Parse the mapfile
  119.    */
  120.   while (fgets(line_buf, MAXLINE, map_fh)) {
  121.     line++;
  122.  
  123.     /* Check for comments and empty lines */
  124.     if (line_buf[0] == '#' || line_buf[0] == '\n')
  125.       continue;
  126.  
  127.     if (strlen(line_buf) > MAXKEYWORD)
  128.       cleanExit( RETURN_WARN, "** Mapline %d too long\n", line-1 );
  129.  
  130.     if ( sscanf(line_buf, "%[^:]:%s", keyword, argument) != 2 )
  131.       cleanExit( RETURN_WARN, "** Invalid mapline %d.\n", line-1 );
  132.  
  133.     /* Skip trailing blanks */
  134.     for (i = 0; keyword[i] != '\0'; i++) {
  135.       if (keyword[i] == ' ') {
  136.         keyword[i] = '\0';
  137.         break;
  138.       }
  139.     }
  140.         
  141.     if (stricmp(keyword, "mapWidth") == 0)
  142.       World.Width = atoi(argument);
  143.     else if (stricmp(keyword, "mapHeight") == 0)
  144.       World.Height = atoi(argument);
  145.     else if (stricmp(keyword, "mapData") == 0)
  146.       break;
  147.     else
  148.       printf("** Unsupported keyword %s in mapfile.\n", keyword);
  149.   }
  150.  
  151.   if (World.Width == 0 || World.Height == 0)
  152.     cleanExit( RETURN_WARN, 
  153.                "** Missing map dimension specifications in mapfile %s\n",
  154.                MAPFILE );
  155.  
  156.   /*
  157.    * Allocate space for the maplines
  158.    */
  159.   if ((map_file = (char **) malloc(sizeof(char *) * World.Height)) == NULL)
  160.     cleanExit( RETURN_WARN, "** Could not allocate space for map.\n" );
  161.   if ((char_chunk = (char *) 
  162.        malloc(sizeof(char) * (World.Width * World.Height))) == NULL)
  163.     cleanExit( RETURN_WARN, "** Could not allocate space for map.\n" );
  164.  
  165.   line = 0;
  166.   while (fgets(line_buf, MAXLINE, map_fh)) {
  167.  
  168.     if ( strlen(line_buf) < World.Width )
  169.       cleanExit( RETURN_WARN, "** Mapline %d too short\n", line+1 );
  170.  
  171.     map_file[line] = &char_chunk[line * World.Width];
  172.  
  173.     for (i = 0; i < World.Width; i++)
  174.       map_file[line][i] = line_buf[i];
  175.  
  176.     line++;
  177.     if (line >= World.Height)
  178.       break;
  179.   }
  180.  
  181.   fclose(map_fh);
  182.  
  183.   if (line < World.Height)
  184.     cleanExit( RETURN_WARN, "** Mapfile: Not enough lines.\n" );
  185.  
  186.   if ((World.map_points = (MAP_Point **) 
  187.        malloc(sizeof(MAP_Point *) * World.Width)) == NULL)
  188.     cleanExit( RETURN_WARN, "** Could not allocate space for map.\n" );
  189.   if ((point_chunk = (MAP_Point *)
  190.        malloc(sizeof(MAP_Point) * (World.Width * World.Height))) == NULL)
  191.     cleanExit( RETURN_WARN, "** Could not allocate space for map.\n" );
  192.  
  193.   for ( y = 0; y < World.Height; y++ ) {
  194.     World.map_points[y] = &point_chunk[y * World.Width];
  195.     for ( x = 0; x < World.Width; x++ ) 
  196.       World.map_points[y][x].draw_flags = 0;
  197.   }
  198.  
  199.   prepare_map();
  200.  
  201.   free(char_chunk);
  202.   free(map_file);
  203. }
  204.  
  205. /*------------------------------------------------------------------------*/
  206.  
  207. /*
  208.  * prepare_map -- Converts the read mapifile into an internal format
  209.  *                for later use.
  210.  */
  211. void
  212. prepare_map( void )
  213. {
  214.   int x, y;
  215.  
  216.   char *p_line;
  217.   char *c_line;
  218.   char *n_line;
  219.  
  220.   /* True if there should be a line in this 'direction' */
  221.   BOOL u_ch, d_ch, l_ch, r_ch;
  222.  
  223.   BOOL u_tbl[TBLSIZE];
  224.   BOOL d_tbl[TBLSIZE];
  225.   BOOL l_tbl[TBLSIZE];
  226.   BOOL r_tbl[TBLSIZE];
  227.  
  228.   init_maptables(u_tbl, d_tbl, l_tbl, r_tbl);
  229.  
  230.   for ( y = 0; y < World.Height; y++ ) {
  231.  
  232.     if (y == 0) 
  233.        p_line = NULL;
  234.     else        
  235.        p_line = map_file[y-1];
  236.  
  237.     if ( y < World.Height-1 ) 
  238.        n_line = map_file[y+1];
  239.     else
  240.        n_line = NULL;
  241.  
  242.     c_line = map_file[y];
  243.  
  244.     for ( x = 0; x < World.Width; x++ ) {
  245.       if (p_line) u_ch = test_u(p_line[x]);
  246.       else        u_ch = FALSE;
  247.       if (n_line) d_ch = test_d(n_line[x]);
  248.       else        d_ch = FALSE;
  249.       if (x > 0)  l_ch = test_l(c_line[x-1]);
  250.       else        l_ch = FALSE;
  251.       if (x < World.Width-1) r_ch = test_r(c_line[x+1]);
  252.       else                   r_ch = FALSE;
  253.       
  254.       /* Precalculate these..speeds up map rendering (?) */
  255.       World.map_points[y][x].edge_x = x * MAP_BLOCKSIZE;
  256.       World.map_points[y][x].edge_y = y * MAP_BLOCKSIZE;
  257.  
  258.       switch (c_line[x]) {
  259.         case ' ':
  260.           World.map_points[y][x].blocktype = BLOCK_EMPTY;
  261.           break;
  262.         case 'x':
  263.           if ( !u_ch && !d_ch && !l_ch && !r_ch ) {
  264.             World.map_points[y][x].blocktype = BLOCK_FILLED_ND;
  265.             break;
  266.           }
  267.           World.map_points[y][x].blocktype = BLOCK_FILLED;
  268.           if (u_ch) World.map_points[y][x].draw_flags |= DRAW_UP;
  269.           if (d_ch) World.map_points[y][x].draw_flags |= DRAW_DOWN;
  270.           if (l_ch) World.map_points[y][x].draw_flags |= DRAW_LEFT;
  271.           if (r_ch) World.map_points[y][x].draw_flags |= DRAW_RIGHT;
  272.           break;
  273.         case 'a':
  274.           World.map_points[y][x].blocktype = BLOCK_RU;
  275.           if (u_ch) World.map_points[y][x].draw_flags |= DRAW_UP;
  276.           if (r_ch) World.map_points[y][x].draw_flags |= DRAW_RIGHT;
  277.           break;
  278.         case 's':
  279.           World.map_points[y][x].blocktype = BLOCK_LU;
  280.           if (u_ch) World.map_points[y][x].draw_flags |= DRAW_UP;
  281.           if (l_ch) World.map_points[y][x].draw_flags |= DRAW_LEFT;
  282.           break;
  283.         case 'q':
  284.           World.map_points[y][x].blocktype = BLOCK_RD;
  285.           if (d_ch) World.map_points[y][x].draw_flags |= DRAW_DOWN;
  286.           if (r_ch) World.map_points[y][x].draw_flags |= DRAW_RIGHT;
  287.           break;
  288.         case 'w':
  289.           World.map_points[y][x].blocktype = BLOCK_LD;
  290.           if (d_ch) World.map_points[y][x].draw_flags |= DRAW_DOWN;
  291.           if (l_ch) World.map_points[y][x].draw_flags |= DRAW_LEFT;
  292.           break;
  293.         case 'r':
  294.           World.map_points[y][x].blocktype = BLOCK_CU;
  295.           World.map_points[y][x].objectptr = (APTR) alloc_cannon(x,y,C_UP);
  296.           break;
  297.         case 'c':
  298.           World.map_points[y][x].blocktype = BLOCK_CD;
  299.           World.map_points[y][x].objectptr = (APTR) alloc_cannon(x,y,C_DN);
  300.           break;
  301.         case 'f':
  302.           World.map_points[y][x].blocktype = BLOCK_CR;
  303.           World.map_points[y][x].objectptr = (APTR) alloc_cannon(x,y,C_RG);
  304.           break;
  305.         case 'd':
  306.           World.map_points[y][x].blocktype = BLOCK_CL;
  307.           World.map_points[y][x].objectptr = (APTR) alloc_cannon(x,y,C_LF);
  308.           break;
  309.         case '#':
  310.           World.map_points[y][x].blocktype = BLOCK_FUEL;
  311.           World.map_points[y][x].draw_flags |= DRAW_UP    | DRAW_DOWN |
  312.                                                DRAW_RIGHT | DRAW_LEFT;
  313.           World.map_points[y][x].objectptr = (APTR) alloc_fuelpod(x,y);
  314.           break;
  315.         case '_':
  316.           World.map_points[y][x].blocktype = BLOCK_BASE;
  317.           World.map_points[y][x].objectptr = (APTR) alloc_base(x,y);
  318.           break;
  319.         default:
  320.           World.map_points[y][x].blocktype = BLOCK_EMPTY;
  321.           break;
  322.       }
  323.     }
  324.   }
  325. }
  326.  
  327. /*------------------------------------------------------------------------*/
  328.  
  329. /*
  330.  * draw_map -- Draws the map using the ship local_ship's cordinates
  331.  *             to position the map on the display.
  332.  */
  333. void
  334. draw_map( struct RastPort *wRp, AShip *local_ship, UWORD buf, UWORD nframes )
  335. {
  336.   const int bsz  = MAP_BLOCKSIZE;
  337.   const int bsz1 = MAP_BLOCKSIZE+1;
  338.   const int bsz2 = MAP_BLOCKSIZE/2;
  339.   
  340.   int       i, x, y, onoff, xbsz, ybsz;
  341.   int       bp_x, bp_y, start_x, start_y, end_x, end_y;
  342.   int       fuelamount;
  343. #ifndef PURE_OS
  344.   PLANEPTR  bpl0, bpl1;
  345. #endif  
  346.   UBYTE     cannon_pen, map_pen;
  347.   USHORT    d_flags;
  348.   MAP_Point **map_points = World.map_points;
  349.  
  350.   static int p_mapx[MY_BUFFERS];
  351.   static int p_mapy[MY_BUFFERS];
  352.  
  353. #ifndef PURE_OS
  354.   bpl0 = wRp->BitMap->Planes[0];
  355.   bpl1 = wRp->BitMap->Planes[1];
  356. #endif 
  357.  
  358.   /* First clear old map and then draw new */
  359.   for (i = 0; i < 2; i++) {
  360.     switch (i) {
  361.       case 0:
  362.         /* Clear it */
  363.         SetWriteMask(wRp, 2l);
  364.         SetAPen(wRp, 0);
  365.         cannon_pen = 0;
  366.         map_pen    = 0;
  367.         onoff = 0;
  368.         start_x = (p_mapx[buf]-SCR_WIDTH/2)/MAP_BLOCKSIZE;
  369.         start_y = (p_mapy[buf]-SCR_HEIGHT/2)/MAP_BLOCKSIZE;
  370.         end_x = 1+(p_mapx[buf]+SCR_WIDTH/2)/MAP_BLOCKSIZE;
  371.         end_y = 1+(p_mapy[buf]+SCR_HEIGHT/2)/MAP_BLOCKSIZE;
  372.         bp_x = p_mapx[buf]-(SCR_WIDTH+MAP_BLOCKSIZE*2)/2;
  373.         bp_y = p_mapy[buf]-(SCR_HEIGHT+MAP_BLOCKSIZE*2)/2;
  374.         break;
  375.       case 1:
  376.         /* Draw it */
  377.         /* Draw hud first and then the map on the hud. */
  378.         draw_hud(wRp, buf, nframes);
  379.         SetWriteMask(wRp, 2l);
  380.         SetAPen(wRp, 2);
  381.         cannon_pen = 3;
  382.         map_pen    = 2;
  383.         onoff = 1;
  384.         start_x = (local_ship->pos.x-SCR_WIDTH/2)/MAP_BLOCKSIZE;
  385.         start_y = (local_ship->pos.y-SCR_HEIGHT/2)/MAP_BLOCKSIZE;
  386.         end_x = 1+(local_ship->pos.x+SCR_WIDTH/2)/MAP_BLOCKSIZE;
  387.         end_y = 1+(local_ship->pos.y+SCR_HEIGHT/2)/MAP_BLOCKSIZE;
  388.         bp_x = local_ship->pos.x-(SCR_WIDTH+MAP_BLOCKSIZE*2)/2;
  389.         bp_y = local_ship->pos.y-(SCR_HEIGHT+MAP_BLOCKSIZE*2)/2;
  390.         break;
  391.       default:
  392.         /* NOTREACHED */
  393.         break;
  394.     }
  395.  
  396.     start_x = max( 0, start_x );
  397.     start_y = max( 0, start_y );
  398.     end_x = min( World.Width , end_x );
  399.     end_y = min( World.Height, end_y );
  400.  
  401.     WaitBlit();
  402.  
  403.     /* Check for map edges */
  404.     if (start_y == 0) {
  405.       xbsz = map_points[0][start_x].edge_x;
  406.       ybsz = map_points[0][start_x].edge_y;
  407. #ifdef PURE_OS
  408.       HLINE(wRp, xbsz-bp_x, ybsz-bp_y, (end_x-start_x)*bsz)
  409. #else
  410.       HorizontalLine(bpl1, xbsz-bp_x, ybsz-bp_y, (end_x-start_x)*bsz, onoff);
  411. #endif
  412.     }
  413.     if (end_y == World.Height) {
  414.       xbsz = map_points[end_y-1][start_x].edge_x;
  415.       ybsz = map_points[end_y-1][start_x].edge_y;
  416. #ifdef PURE_OS
  417.       HLINE(wRp, xbsz-bp_x, ybsz+bsz-bp_y, (end_x-start_x)*bsz)
  418. #else
  419.       HorizontalLine(bpl1, xbsz-bp_x, ybsz+bsz-bp_y, (end_x-start_x)*bsz, onoff);
  420. #endif
  421.     }
  422.     if (start_x == 0) {
  423.       xbsz = map_points[start_y][0].edge_x;
  424.       ybsz = map_points[start_y][0].edge_y;
  425. #ifdef PURE_OS
  426.       VLINE(wRp, xbsz-bp_x, ybsz-bp_y, (end_y-start_y)*bsz)
  427. #else
  428.       VerticalLine(bpl1, xbsz-bp_x, ybsz-bp_y, (end_y-start_y)*bsz, onoff);
  429. #endif
  430.     }
  431.     if (end_x == World.Width) {
  432.       xbsz = map_points[start_y][end_x-1].edge_x;
  433.       ybsz = map_points[start_y][end_x-1].edge_y;
  434. #ifdef PURE_OS
  435.       VLINE(wRp, xbsz+bsz-bp_x, ybsz-bp_y, (end_y-start_y)*bsz)
  436. #else
  437.       VerticalLine(bpl1, xbsz+bsz-bp_x, ybsz-bp_y, (end_y-start_y)*bsz, onoff);
  438. #endif
  439.     }
  440.  
  441.     for ( y = start_y; y < end_y; y++ ) {
  442.       for ( x = start_x; x < end_x; x++ ) {
  443.         switch (map_points[y][x].blocktype) {                
  444.           case BLOCK_EMPTY:
  445.           case BLOCK_FILLED_ND:
  446.             break;
  447.           case BLOCK_FILLED:
  448.             xbsz = map_points[y][x].edge_x;
  449.             ybsz = map_points[y][x].edge_y;
  450.             d_flags = map_points[y][x].draw_flags;
  451. #ifdef PURE_OS
  452.             if (d_flags & DRAW_UP)    { HLINE(wRp, xbsz-bp_x, ybsz-bp_y, bsz1) }
  453.             if (d_flags & DRAW_DOWN)  { HLINE(wRp, xbsz-bp_x, ybsz+bsz-bp_y, bsz1) }
  454.             if (d_flags & DRAW_LEFT)  { VLINE(wRp, xbsz-bp_x, ybsz-bp_y, bsz1) }
  455.             if (d_flags & DRAW_RIGHT) { VLINE(wRp, xbsz+bsz-bp_x, ybsz-bp_y, bsz1) }
  456. #else
  457.             if (d_flags & DRAW_UP)    { HorizontalLine(bpl1, xbsz-bp_x, ybsz-bp_y, bsz1, onoff); }
  458.             if (d_flags & DRAW_DOWN)  { HorizontalLine(bpl1, xbsz-bp_x, ybsz+bsz-bp_y, bsz1, onoff); }
  459.             if (d_flags & DRAW_LEFT)  { VerticalLine(bpl1, xbsz-bp_x, ybsz-bp_y, bsz1, onoff); }
  460.             if (d_flags & DRAW_RIGHT) { VerticalLine(bpl1, xbsz+bsz-bp_x, ybsz-bp_y, bsz1, onoff); }
  461. #endif
  462.             break;
  463.           case BLOCK_RU:
  464.             xbsz = map_points[y][x].edge_x;
  465.             ybsz = map_points[y][x].edge_y;
  466.             Move(wRp, xbsz-bp_x, ybsz-bp_y);
  467.             Draw(wRp, xbsz+bsz-bp_x, ybsz+bsz-bp_y);
  468.             d_flags = map_points[y][x].draw_flags;
  469.             WaitBlit();
  470. #ifdef PURE_OS
  471.             if (d_flags & DRAW_UP)    { HLINE(wRp, xbsz-bp_x, ybsz-bp_y, bsz1) }
  472.             if (d_flags & DRAW_RIGHT) { VLINE(wRp, xbsz+bsz-bp_x, ybsz-bp_y, bsz1) }
  473. #else
  474.             if (d_flags & DRAW_UP)    { HorizontalLine(bpl1, xbsz-bp_x, ybsz-bp_y, bsz1, onoff); }
  475.             if (d_flags & DRAW_RIGHT) { VerticalLine(bpl1, xbsz+bsz-bp_x, ybsz-bp_y, bsz1, onoff); }
  476. #endif
  477.             break;
  478.           case BLOCK_LU:
  479.             xbsz = map_points[y][x].edge_x;
  480.             ybsz = map_points[y][x].edge_y;
  481.             Move(wRp, xbsz-bp_x, ybsz+bsz-bp_y);
  482.             Draw(wRp, xbsz+bsz-bp_x, ybsz-bp_y);
  483.             d_flags = map_points[y][x].draw_flags;
  484.             WaitBlit();
  485. #ifdef PURE_OS
  486.             if (d_flags & DRAW_UP)   { HLINE(wRp, xbsz-bp_x, ybsz-bp_y, bsz1) }
  487.             if (d_flags & DRAW_LEFT) { VLINE(wRp, xbsz-bp_x, ybsz-bp_y, bsz1) }
  488. #else
  489.             if (d_flags & DRAW_UP)   { HorizontalLine(bpl1, xbsz-bp_x, ybsz-bp_y, bsz1, onoff); }
  490.             if (d_flags & DRAW_LEFT) { VerticalLine(bpl1, xbsz-bp_x, ybsz-bp_y, bsz1, onoff); }
  491. #endif
  492.             break;
  493.           case BLOCK_RD:
  494.             xbsz = map_points[y][x].edge_x;
  495.             ybsz = map_points[y][x].edge_y;
  496.             Move(wRp, xbsz-bp_x, ybsz+bsz-bp_y);
  497.             Draw(wRp, xbsz+bsz-bp_x, ybsz-bp_y);
  498.             d_flags = map_points[y][x].draw_flags;
  499.             WaitBlit();
  500. #ifdef PURE_OS
  501.             if (d_flags & DRAW_DOWN)  { HLINE(wRp, xbsz-bp_x, ybsz+bsz-bp_y, bsz1) }
  502.             if (d_flags & DRAW_RIGHT) { VLINE(wRp, xbsz+bsz-bp_x, ybsz-bp_y, bsz1) }
  503. #else
  504.             if (d_flags & DRAW_DOWN)  { HorizontalLine(bpl1, xbsz-bp_x, ybsz+bsz-bp_y, bsz1, onoff); }
  505.             if (d_flags & DRAW_RIGHT) { VerticalLine(bpl1, xbsz+bsz-bp_x, ybsz-bp_y, bsz1, onoff); }
  506. #endif
  507.             break;
  508.           case BLOCK_LD:
  509.             xbsz = map_points[y][x].edge_x;
  510.             ybsz = map_points[y][x].edge_y;
  511.             Move(wRp, xbsz-bp_x, ybsz-bp_y);
  512.             Draw(wRp, xbsz+bsz-bp_x, ybsz+bsz-bp_y);
  513.             d_flags = map_points[y][x].draw_flags;
  514.             WaitBlit();
  515. #ifdef PURE_OS
  516.             if (d_flags & DRAW_DOWN) { HLINE(wRp, xbsz-bp_x, ybsz+bsz-bp_y, bsz1) }
  517.             if (d_flags & DRAW_LEFT) { VLINE(wRp, xbsz-bp_x, ybsz-bp_y, bsz1) }
  518. #else
  519.             if (d_flags & DRAW_DOWN) { HorizontalLine(bpl1, xbsz-bp_x, ybsz+bsz-bp_y, bsz1, onoff); }
  520.             if (d_flags & DRAW_LEFT) { VerticalLine(bpl1, xbsz-bp_x, ybsz-bp_y, bsz1, onoff); }
  521. #endif
  522.             break;
  523.           case BLOCK_FUEL:
  524.             xbsz = map_points[y][x].edge_x;
  525.             ybsz = map_points[y][x].edge_y;
  526. #ifdef PURE_OS
  527.             HLINE(wRp, xbsz-bp_x, ybsz-bp_y, bsz1)
  528.             HLINE(wRp, xbsz-bp_x, ybsz+bsz-bp_y, bsz1)
  529.             VLINE(wRp, xbsz-bp_x, ybsz-bp_y, bsz1)
  530.             VLINE(wRp, xbsz+bsz-bp_x, ybsz-bp_y, bsz1)
  531. #else
  532.             HorizontalLine(bpl1, xbsz-bp_x, ybsz-bp_y, bsz1, onoff);
  533.             HorizontalLine(bpl1, xbsz-bp_x, ybsz+bsz-bp_y, bsz1, onoff);
  534.             VerticalLine(bpl1, xbsz-bp_x, ybsz-bp_y, bsz1, onoff);
  535.             VerticalLine(bpl1, xbsz+bsz-bp_x, ybsz-bp_y, bsz1, onoff);
  536. #endif
  537.             if (onoff == 1) {
  538.               fuelamount = ( (((((AFuelPod *)map_points[y][x].objectptr)->fuel
  539.                            << SHFTPR) / MAX_PODFUEL) * (MAP_BLOCKSIZE-3))
  540.                            >> SHFTPR );
  541.             } else {
  542.               fuelamount = ((AFuelPod *)
  543.                              map_points[y][x].objectptr)->p_fuel[buf];
  544.             }
  545. #ifdef PURE_OS
  546.             SetWriteMask(wRp,1l); 
  547.         if (onoff == 1) SetAPen(wRp,3); 
  548.             HLINE(wRp, xbsz-bp_x+1, ybsz+bsz-bp_y-1-fuelamount, bsz-2)
  549.         HLINE(wRp, xbsz-bp_x+1, ybsz+bsz-bp_y-2-fuelamount, bsz-2)
  550.             SetWriteMask(wRp,2l); 
  551.         if (onoff == 1) SetAPen(wRp,map_pen); 
  552. #else
  553.             HorizontalLine(bpl0, xbsz-bp_x+1, 
  554.                            ybsz+bsz-bp_y-1-fuelamount, bsz-2, onoff);
  555.             HorizontalLine(bpl0, xbsz-bp_x+1, 
  556.                            ybsz+bsz-bp_y-2-fuelamount, bsz-2, onoff);
  557. #endif
  558.             ((AFuelPod *)map_points[y][x].objectptr)->p_fuel[buf] = fuelamount;
  559.             break;
  560.           case BLOCK_CU:
  561.             /* Check if we should draw the cannon */
  562.             if ( ((ACannon *)map_points[y][x].objectptr)->cstate == DEAD
  563.                  && onoff == 1 )
  564.               break;
  565.             xbsz = map_points[y][x].edge_x;
  566.             ybsz = map_points[y][x].edge_y;
  567.             SetWriteMask(wRp, 3l);
  568.             SetAPen(wRp,cannon_pen); 
  569.             Move(wRp, xbsz-bp_x, ybsz+bsz-bp_y-1);
  570.             Draw(wRp, xbsz+bsz2-bp_x , ybsz+bsz-CAN_HEIGHT-bp_y);
  571.             Draw(wRp, xbsz+bsz-bp_x, ybsz+bsz-bp_y-1);
  572.             WaitBlit();
  573. #ifdef PURE_OS
  574.             HLINE(wRp, xbsz-bp_x, ybsz+bsz-bp_y, bsz1)
  575.             HLINE(wRp, xbsz-bp_x, ybsz+bsz-bp_y, bsz1)
  576. #else
  577.             HorizontalLine(bpl0, xbsz-bp_x, ybsz+bsz-bp_y, bsz1, onoff);
  578.             HorizontalLine(bpl1, xbsz-bp_x, ybsz+bsz-bp_y, bsz1, onoff);
  579. #endif
  580.             SetWriteMask(wRp, 2l);
  581.             SetAPen(wRp,map_pen); 
  582.             break;
  583.           case BLOCK_CD:
  584.             /* Check if we should draw the cannon */
  585.             if ( ((ACannon *)map_points[y][x].objectptr)->cstate == DEAD
  586.                  && onoff == 1 )
  587.               break;
  588.             xbsz = map_points[y][x].edge_x;
  589.             ybsz = map_points[y][x].edge_y;
  590.             SetWriteMask(wRp, 3l);
  591.             SetAPen(wRp,cannon_pen); 
  592.             Move(wRp, xbsz-bp_x, ybsz-bp_y);
  593.             Draw(wRp, xbsz+bsz2-bp_x , ybsz+CAN_HEIGHT-bp_y);
  594.             Draw(wRp, xbsz+bsz-bp_x, ybsz-bp_y);
  595.             WaitBlit();
  596. #ifdef PURE_OS
  597.             HLINE(wRp, xbsz-bp_x, ybsz-bp_y, bsz1)
  598.             HLINE(wRp, xbsz-bp_x, ybsz-bp_y, bsz1)
  599. #else
  600.             HorizontalLine(bpl0, xbsz-bp_x, ybsz-bp_y, bsz1, onoff);
  601.             HorizontalLine(bpl1, xbsz-bp_x, ybsz-bp_y, bsz1, onoff);
  602. #endif
  603.             SetWriteMask(wRp, 2l);
  604.             SetAPen(wRp,map_pen); 
  605.             break;
  606.           case BLOCK_CR:
  607.             /* Check if we should draw the cannon */
  608.             if ( ((ACannon *)map_points[y][x].objectptr)->cstate == DEAD
  609.                  && onoff == 1 )
  610.               break;
  611.             xbsz = map_points[y][x].edge_x;
  612.             ybsz = map_points[y][x].edge_y;
  613.             SetWriteMask(wRp, 3l);
  614.             SetAPen(wRp,cannon_pen); 
  615.             Move(wRp, xbsz-bp_x, ybsz-bp_y);
  616.             Draw(wRp, xbsz+CAN_HEIGHT-bp_x , ybsz+bsz2-bp_y);
  617.             Draw(wRp, xbsz-bp_x, ybsz+bsz-bp_y);
  618.             WaitBlit();
  619. #ifdef PURE_OS
  620.             VLINE(wRp, xbsz-bp_x, ybsz-bp_y, bsz1)
  621.             VLINE(wRp, xbsz-bp_x, ybsz-bp_y, bsz1)
  622. #else
  623.             VerticalLine(bpl0, xbsz-bp_x, ybsz-bp_y, bsz1, onoff);
  624.             VerticalLine(bpl1, xbsz-bp_x, ybsz-bp_y, bsz1, onoff);
  625. #endif
  626.             SetWriteMask(wRp, 2l);
  627.             SetAPen(wRp,map_pen); 
  628.             break;
  629.           case BLOCK_CL:
  630.             /* Check if we should draw the cannon */
  631.             if ( ((ACannon *)map_points[y][x].objectptr)->cstate == DEAD
  632.                  && onoff == 1 )
  633.               break;
  634.             xbsz = map_points[y][x].edge_x;
  635.             ybsz = map_points[y][x].edge_y;
  636.             SetWriteMask(wRp, 3l);
  637.             SetAPen(wRp,cannon_pen); 
  638.             Move(wRp, xbsz+bsz-bp_x, ybsz-bp_y);
  639.             Draw(wRp, xbsz+bsz-CAN_HEIGHT-bp_x , ybsz+bsz2-bp_y);
  640.             Draw(wRp, xbsz+bsz-bp_x, ybsz+bsz-bp_y);
  641.             WaitBlit();
  642. #ifdef PURE_OS
  643.             VLINE(wRp, xbsz+bsz-bp_x, ybsz-bp_y, bsz1)
  644.             VLINE(wRp, xbsz+bsz-bp_x, ybsz-bp_y, bsz1)
  645. #else
  646.             VerticalLine(bpl0, xbsz+bsz-bp_x, ybsz-bp_y, bsz1, onoff);
  647.             VerticalLine(bpl1, xbsz+bsz-bp_x, ybsz-bp_y, bsz1, onoff);
  648. #endif
  649.             SetWriteMask(wRp, 2l);
  650.             SetAPen(wRp,map_pen); 
  651.             break;
  652.           case BLOCK_BASE:
  653.             xbsz = map_points[y][x].edge_x;
  654.             ybsz = map_points[y][x].edge_y;
  655. #ifdef PURE_OS
  656.             SetWriteMask(wRp, 3l); 
  657.         if (onoff == 1) SetAPen(wRp, 3);
  658.             HLINE(wRp, xbsz-bp_x, ybsz+bsz-bp_y, bsz1)
  659.             HLINE(wRp, xbsz-bp_x, ybsz+bsz-bp_y, bsz1)
  660.             if (onoff == 1) SetAPen(wRp, 2);
  661.         SetWriteMask(wRp, 2l);
  662. #else
  663.             HorizontalLine(bpl0, xbsz-bp_x, ybsz+bsz-bp_y, bsz1, onoff);
  664.             HorizontalLine(bpl1, xbsz-bp_x, ybsz+bsz-bp_y, bsz1, onoff);
  665. #endif
  666.             break;
  667.           default:
  668.             break;
  669.         }
  670.       }
  671.     }
  672.   }
  673.   p_mapx[buf] = local_ship->pos.x;
  674.   p_mapy[buf] = local_ship->pos.y;
  675. }
  676.