home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / graphics / acksrc.zip / ACKINIT.C < prev    next >
Text File  |  1993-06-20  |  4KB  |  197 lines

  1. /*           ACK-3D ( Animation Construction Kit 3D )              */
  2. /* Initialization     */
  3. /* Author: Lary Myers */
  4.  
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <dos.h>
  8. #include <mem.h>
  9. #include <alloc.h>
  10. #include <io.h>
  11. #include <fcntl.h>
  12. #include <time.h>
  13. #include <string.h>
  14. #include <sys\stat.h>
  15. #include "ack3d.h"
  16. #include "ackext.h"
  17.  
  18.  
  19. unsigned char far *ScreenBuffer;
  20.  
  21.     int    VidRow[200];
  22.  
  23. /****************************************************************************
  24. **                                       **
  25. ****************************************************************************/
  26. int BuildTables(void)
  27. {
  28.     int        i;
  29.     int        result;
  30.     long    height;
  31.  
  32. if (GetTables() == -1)
  33.     return(-1);
  34.  
  35. ScreenBuffer = malloc(64000);
  36. if (ScreenBuffer == NULL)
  37.     return(-1);
  38.  
  39. memset(ScreenBuffer,0,64000);
  40.  
  41. for (i = 0; i < 200; i++)
  42.     VidRow[i] = i * 320;
  43.  
  44.  
  45. height = 18000;
  46. height = 14000;
  47.  
  48. DistanceTable[0] = MAX_HEIGHT;
  49.  
  50. /************** 64 * 65536 ************/
  51. AdjustTable[0] = 4194304L / height;
  52.  
  53. for (i = 1; i < MAX_DISTANCE; i++)
  54.     {
  55.     DistanceTable[i] = height / i;
  56.     if (height - (DistanceTable[i] * i) > (i / 2))
  57.     DistanceTable[i]++;
  58.  
  59.     if (DistanceTable[i] < MIN_HEIGHT)
  60.     DistanceTable[i] = MIN_HEIGHT;
  61.  
  62.     if (DistanceTable[i] > MAX_HEIGHT)
  63.     DistanceTable[i] = MAX_HEIGHT;
  64.  
  65.     AdjustTable[i] = 4194304L / DistanceTable[i];
  66.     }
  67.  
  68.  
  69. return(0);
  70. }
  71.  
  72. /****************************************************************************
  73. **                                       **
  74. ****************************************************************************/
  75. void InitializeMouse(void)
  76. {
  77.  
  78. memset(&mouse,0,sizeof(MOUSE));
  79. HaveMouse = 0;
  80. if (mouse_installed() == -1)
  81.     {
  82.     HaveMouse = 1;
  83.     CheckMouse(&mouse);
  84.     }
  85.  
  86. }
  87.  
  88.  
  89. /****************************************************************************
  90. **                                       **
  91. ****************************************************************************/
  92. void BuildXYgrid(void)
  93. {
  94.         int        i,j,CurIndex,pos,x1,y1;
  95. unsigned    char    MapCode;
  96.  
  97. for (i = 0; i < MAX_DOORS; i++)
  98.     {
  99.     Door[i].ColOffset = 0;
  100.     Door[i].mPos = Door[i].mPos1 = -1;
  101.     }
  102.  
  103. i = (GRID_WIDTH+1) * (GRID_HEIGHT+1);
  104. memset(xGrid,0,i);
  105. memset(yGrid,0,i);
  106. memset(xObjGrid,0,i);
  107. memset(yObjGrid,0,i);
  108.  
  109. CurIndex     = 1;
  110. TotalSpecial = 0;
  111. TotalSecret  = 0;
  112.  
  113. for (i = 0; i < GRID_HEIGHT; i++)
  114.     {
  115.     for (j = 0; j < GRID_WIDTH; j++)
  116.     {
  117.     pos    = (i * GRID_WIDTH) + j;
  118.     MapCode = Grid[pos];
  119.  
  120.     if (MapCode == MAP_STARTCODE)
  121.         {
  122.         StartY = pos & 0xFFC0;
  123.         StartX = (pos - StartY) << 6;
  124.         StartY += 32;
  125.         StartX += 32;
  126.         continue;
  127.         }
  128.  
  129.     if (MapCode == MAP_UPCODE ||
  130.         MapCode == MAP_DOWNCODE ||
  131.         MapCode == MAP_GOALCODE)
  132.         {
  133.         SpecialCodes[TotalSpecial].mPos = pos;
  134.         SpecialCodes[TotalSpecial++].mCode = MapCode;
  135.         continue;
  136.         }
  137.  
  138.     if (MapCode)            /* Something is in map */
  139.         {
  140.         if (MapCode < 0x80)        /* Wall codes range from 1-7F */
  141.         {
  142.         if (MapCode != DOOR_YCODE)
  143.             {
  144.             if (xGrid[pos] != DOOR_SIDECODE)
  145.             xGrid[pos] = MapCode;
  146.  
  147.             xGrid[pos+1] = MapCode;
  148.             }
  149.         else
  150.             {
  151.             xGrid[pos]     = DOOR_SIDECODE;
  152.             xGrid[pos+1] = DOOR_SIDECODE;
  153.             }
  154.  
  155.         if (MapCode != DOOR_XCODE)
  156.             {
  157.             if (yGrid[pos] != DOOR_SIDECODE)
  158.             yGrid[pos] = MapCode;
  159.             yGrid[pos+GRID_WIDTH] = MapCode;
  160.             }
  161.         else
  162.             {
  163.             yGrid[pos]          = DOOR_SIDECODE;
  164.             yGrid[pos+GRID_WIDTH] = DOOR_SIDECODE;
  165.             }
  166.         }
  167.         else            /* > 0x80 means an object code */
  168.         {
  169.         CurIndex = MapCode & 0x3F;
  170.         if (CurIndex < MAX_OBJECTS)
  171.             {
  172.             Grid[pos] = 0x80;
  173.             if (MapCode & 0x40)
  174.             Grid[pos] |= 0x40;
  175.  
  176.             xObjGrid[pos]         = CurIndex;
  177.             xObjGrid[pos+1]         = CurIndex;
  178.             yObjGrid[pos]         = CurIndex;
  179.             yObjGrid[pos+GRID_WIDTH] = CurIndex;
  180.  
  181.             x1 = (j << 6) + 32;        /* Place object in center of */
  182.             y1 = (i << 6) + 32;        /* the current map square     */
  183.             ObjList[CurIndex].x         = x1;
  184.             ObjList[CurIndex].y         = y1;
  185.  
  186.             ObjList[CurIndex].mPos   = pos;
  187.             ObjList[CurIndex].VidRow = CenterRow;
  188.             ObjList[CurIndex].Active = 1;
  189.             }
  190.         }
  191.         }
  192.     }
  193.     }
  194.  
  195. }
  196.  
  197.