home *** CD-ROM | disk | FTP | other *** search
/ Launch & Play / spustahrej2.iso / Egoboo / code / remove.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-12-03  |  36.7 KB  |  1,104 lines

  1. // remove.c
  2.  
  3. // Egoboo, Copyright (C) 2000 Aaron Bishop
  4.  
  5. #include "egoboo.h"
  6.  
  7. // Egoboo, Copyright (C) 2000 Aaron Bishop
  8. /* The following is a description of how we are going to split this file into
  9. ** several files.  The first step is to mark which functions go into which
  10. ** files.  To do this, a simple one line comment will be used.  The first three
  11. ** characters on the line will be '//!'.  This is then followed by the name of
  12. ** the file to put the following lines into.  The indicated file will be used
  13. ** until the next marker is found.  The utility that will do the split will
  14. ** simply append the given file until a new marker is found.  If a file is
  15. ** given that has not been seen before, the utility will create a new file.
  16. **
  17. ** Note that note every function will have a tag.  For example, the directory
  18. ** functions are grouped together, so only one tag is used.
  19. **
  20. ** A special file name of ! will indicate the section should not be put into
  21. ** any file.  Functions that are commented out will use this feature.  Also,
  22. ** the first line of this file has this special marker to skip this comment.
  23. **
  24. ** The following is a list of currently used file names with a short
  25. ** description to indicate what goes in that file.
  26. **
  27. ** (The sections marked with * will be for ports)
  28. **
  29. ** script.c     - Scripting functions (mostly for AI)
  30. ** camera.c     - Camera movement
  31. ** char.c       - Character logic
  32. ** config.c     - Configuration files
  33. ** win-files.c  - Directory / File management (*)
  34. ** game.c       - Game logic
  35. ** input.c      - Input (* mouse, keyboard, joystick)
  36. ** menu.c       - Menuing
  37. ** network.c    - Network (*)
  38. ** sound.c      - Sound and music (*)
  39. ** passage.c    - All passage functions
  40. ** particle.c   - Particle engine
  41. ** enchant.c    - Enchantments
  42. ** graphic.c    - Platform independent graphics functions
  43. ** module.c     - Work with modules
  44. **
  45. ** (Hyphenated names belong to ports)
  46. */
  47. #include "full.h"
  48.  
  49. // SDL specific declarations
  50. SDL_Joystick *sdljoya = NULL;
  51. SDL_Joystick *sdljoyb = NULL;
  52. Uint8 *sdlkeybuffer = NULL;
  53. #define SDLKEYDOWN(k) (sdlkeybuffer[k])
  54.  
  55. // OPENGL specific declarations
  56. GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};  /* White diffuse light. */
  57. GLfloat light_position[] = {10.0, 10.0, 30.0, 1.0};  /* nonInfinite light location. */
  58. int win_id;
  59. static GLuint texName;
  60.  
  61. //------------------------------------------------------------------------------
  62. //Functions I Bothered to List--------------------------------------------------
  63. //------------------------------------------------------------------------------
  64. //
  65. void find_all_players();
  66. void let_character_think(int character);
  67. void change_character(unsigned short cnt, unsigned short profile, unsigned char skin,
  68.      unsigned char leavewhich);
  69. /* PORT
  70. extern "C" { int WaveLoadFile(char *, UINT *, DWORD *, WAVEFORMATEX **, BYTE **); }
  71. */
  72. void spawn_poof(unsigned short character, unsigned short profile);
  73. void debug_message(char *text);
  74. void kill_character(unsigned short character, unsigned short killer);
  75. unsigned short change_armor(unsigned short character, unsigned short skin);
  76. void draw_trim_box(int left, int top, int right, int bottom);
  77. void reset_character_alpha(unsigned short character);
  78. void export_one_character_profile(char *szSaveName, unsigned short character);
  79. void export_one_character_skin(char *szSaveName, unsigned short character);
  80. void export_one_character_name(char *szSaveName, unsigned short character);
  81. void drop_all_items(unsigned short character);
  82. void drop_keys(unsigned short character);
  83. void copy_file_to_all_players(char *source, char *dest);
  84. void copy_file_to_host(char *source, char *dest);
  85. void copy_directory_to_host(char *source, char *dest);
  86. void disenchant_character(unsigned short cnt);
  87. void give_experience(int character, int amount, unsigned char xptype);
  88. int spawn_one_character(float x, float y, float z, int profile, unsigned char team,
  89. unsigned char skin, unsigned short facing, char *name, int override);
  90.  
  91. #ifdef _MACOS
  92. #define FILENAME(x) os_cvrt_filename(x,':')
  93. #endif
  94. #ifdef _LINUX
  95. #define FILENAME(x) x
  96. #endif
  97. #ifdef _WIN32
  98. #define FILENAME(x) os_cvrt_filename(x,'\\')
  99. #endif
  100.  
  101. //---------------------------------------------------------------------------------------------
  102. //__inline int __get_level(unsigned char x, unsigned char y, unsigned int fan)
  103. //{
  104.     // ZZ> This function returns the height of a point within a mesh fan, fast
  105. //    int z0, z1, z2, z3;         // Height of each fan corner
  106. //    int zleft, zright,zdone;    // Weighted height of each side
  107.  
  108.  
  109. //    x = (x&127)>>4;             // 8 divisions
  110. //    y = (y&127)>>4;             // 8 divisions
  111. //    z0 = meshvrtz[meshvrtstart[fan]+0];
  112. //    z1 = meshvrtz[meshvrtstart[fan]+1];
  113. //    z2 = meshvrtz[meshvrtstart[fan]+2];
  114. //    z3 = meshvrtz[meshvrtstart[fan]+3];
  115. //    switch(y)
  116. //    {
  117. //        // Fully top
  118. //        case 0:
  119. //            zleft = z0<<3;
  120. //            zright = z1<<3;
  121. //            break;
  122. //        case 1:
  123. //            zleft = (z0<<3)-z0+z3;
  124. //            zright = (z1<<3)-z1+z2;
  125. //            break;
  126. //        case 2:
  127. //            z0 = z0<<1;
  128. //            z3 = z3<<1;
  129. //            zleft = z0+z0+z0+z3;
  130. //            z1 = z1<<1;
  131. //            z2 = z2<<1;
  132. //            zright = z1+z1+z1+z2;
  133. //            break;
  134. //        case 3:
  135. //            zleft = (z0<<2)+z0+z3+z3+z3;
  136. //            zright = (z1<<2)+z1+z2+z2+z2;
  137. //            break;
  138. //        case 4:
  139. //            zleft = (z0<<2)+(z3<<2);
  140. //            zright = (z1<<2)+(z2<<2);
  141. //            break;
  142. //        case 5:
  143. //            zleft = z0+z0+z0+(z3<<2)+z3;
  144. //            zright = z1+z1+z1+(z2<<2)+z2;
  145. //            break;
  146. //        case 6:
  147. //            z0 = z0<<1;
  148. //            z3 = z3<<1;
  149. //            zleft = z0+z3+z3+z3;
  150. //            z1 = z1<<1;
  151. //            z2 = z2<<1;
  152. //            zright = z1+z2+z2+z2;
  153. //            break;
  154. //        case 7:
  155. //            zleft = z0+(z3<<3)-z3;
  156. //            zright = z1+(z2<<3)-z2;
  157. //            break;
  158. //        // Fully bottom done in next fan as fully top
  159. //    }
  160.  
  161.  
  162. //    switch(y)
  163. //    {
  164. //        // Fully left
  165. //        case 0:
  166. //            zdone = zleft<<3;
  167. //            break;
  168. //        case 1:
  169. //            zdone = (zleft<<3)-zleft+zright;
  170. //            break;
  171. //        case 2:
  172. //            zleft = zleft<<1;
  173. //            zright = zright<<1;
  174. //            zdone = zleft+zleft+zleft+zright;
  175. //            break;
  176. //        case 3:
  177. //            zdone = (zleft<<2)+zleft+zright+zright+zright;
  178. //            break;
  179. //        case 4:
  180. //            zdone = (zleft<<2)+(zright<<2);
  181. //            break;
  182. //        case 5:
  183. //            zdone = zleft+zleft+zleft+(zright<<2)+zright;
  184. //            break;
  185. //        case 6:
  186. //            zleft = zleft<<1;
  187. //            zright = zright<<1;
  188. //            zdone = zleft+zright+zright+zright;
  189. //            break;
  190. //        case 7:
  191. //            zdone = zleft+(zright<<3)-zright;
  192. //            break;
  193. //        // Fully right done in next fan as fully left
  194. //    }
  195.  
  196. //    return ((zdone>>6)+RAISE);
  197. //}
  198.  
  199. //--------------------------------------------------------------------------------------------
  200. /*PORT
  201. void directx_setup_error(HWND hWnd, HRESULT ddrval, char *szerrortext)
  202. {
  203.     // ZZ> This function displays an error message
  204.     // Steinbach's Guideline for Systems Programming:
  205.     //   Never test for an error condition you don't know how to handle.
  206.     char                buf[256];
  207.     sprintf(buf, "%d... %s\n", (ddrval&65535), szerrortext);
  208.     MessageBox(hWnd, buf, "ERROR", MB_OK);
  209.     release_grfx();
  210.     DestroyWindow(hWnd);
  211. }
  212. */
  213.  
  214. //--------------------------------------------------------------------------------------------
  215. /*PORT
  216. void clear_surface(LPDIRECTDRAWSURFACE lpDDS)
  217. {
  218.     // ZZ> This function clears a surface to black
  219.     DDBLTFX bltfx;
  220.     ZeroMemory(&bltfx, sizeof(bltfx)); // Sets dwFillColor to 0 as well
  221.     bltfx.dwSize = sizeof(bltfx);
  222.     lpDDS->Blt(NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &bltfx);
  223. }
  224. */
  225.  
  226. //--------------------------------------------------------------------------------------------
  227. /*PORT
  228. DWORD transform_vertices(DWORD number, D3DLVERTEX v[], D3DTLVERTEX vt[])
  229. {
  230.     // ZZ> This function projects a bunch of vertices onto the screen
  231.     //     and returns FALSE if any made it
  232.     D3DTRANSFORMDATA Data;
  233.     DWORD Offscreen;
  234.  
  235.  
  236.     Data.dwSize = sizeof(Data);
  237.     Data.lpIn = v;
  238.     Data.dwInSize = sizeof(v[0]);
  239.     Data.lpOut = vt;
  240.     Data.dwOutSize = sizeof(vt[0]);
  241.     Data.lpHOut = NULL;
  242.     Data.dwClip = 0;
  243.     Data.dwClipIntersection = 0;
  244.     Data.dwClipUnion = 0;
  245.     lpD3DVViewport->TransformVertices(number, &Data, D3DTRANSFORM_UNCLIPPED, &Offscreen);
  246.     return Offscreen;
  247. }
  248. */
  249.  
  250. //--------------------------------------------------------------------------------------------
  251. /*PORT
  252. void render_background(unsigned short texture)
  253. {
  254.     // ZZ> This function draws the large background
  255.     D3DTLVERTEX vtlist[4];
  256.     DWORD light;
  257.     float size;
  258.     unsigned short rotate;
  259.     float sinsize, cossize;
  260.     D3DVALUE x, y, z, rhw, u, v;
  261.  
  262.  
  263.     // Flat shade this
  264.     if(shading != D3DSHADE_FLAT)
  265.         lpD3DDDevice->SetRenderState(D3DRENDERSTATE_SHADEMODE, D3DSHADE_FLAT);
  266.  
  267.  
  268.     // Choose texture and matrix
  269.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_TEXTUREHANDLE, txTexture[texture].GetHandle());
  270.  
  271.  
  272.  
  273.     // Figure out the screen coordinates of its corners
  274.     x = scrx/2.0;
  275.     y = scry/2.0;
  276.     z = .99999;
  277.     rhw = 1.0;
  278.     u = waterlayeru[1];
  279.     v = waterlayerv[1];
  280.     rotate=16384+8192-camturnleftrightshort;
  281.     rotate = rotate>>2;
  282.     size = x + y + 1;
  283.     sinsize = turntosin[rotate]*size;
  284.     cossize = turntosin[(rotate+4096)&16383]*size;
  285.  
  286.     light = (0xffffffff);
  287.  
  288.     vtlist[0].dvSX = x + cossize;
  289.     vtlist[0].dvSY = y - sinsize;
  290.     vtlist[0].dvSZ = z;
  291.     vtlist[0].dvRHW = rhw;
  292.     vtlist[0].dcColor = light;
  293.     vtlist[0].dcSpecular = 0;
  294.     vtlist[0].dvTU = 0+u;
  295.     vtlist[0].dvTV = 0+v;
  296.  
  297.     vtlist[1].dvSX = x + sinsize;
  298.     vtlist[1].dvSY = y + cossize;
  299.     vtlist[1].dvSZ = z;
  300.     vtlist[1].dvRHW = rhw;
  301.     vtlist[1].dcColor = light;
  302.     vtlist[1].dcSpecular = 0;
  303.     vtlist[1].dvTU = backgroundrepeat+u;
  304.     vtlist[1].dvTV = 0+v;
  305.  
  306.     vtlist[2].dvSX = x - cossize;
  307.     vtlist[2].dvSY = y + sinsize;
  308.     vtlist[2].dvSZ = z;
  309.     vtlist[2].dvRHW = rhw;
  310.     vtlist[2].dcColor = light;
  311.     vtlist[2].dcSpecular = 0;
  312.     vtlist[2].dvTU = backgroundrepeat+u;
  313.     vtlist[2].dvTV = backgroundrepeat+v;
  314.  
  315.     vtlist[3].dvSX = x - sinsize;
  316.     vtlist[3].dvSY = y - cossize;
  317.     vtlist[3].dvSZ = z;
  318.     vtlist[3].dvRHW = rhw;
  319.     vtlist[3].dcColor = light;
  320.     vtlist[3].dcSpecular = 0;
  321.     vtlist[3].dvTU = 0+u;
  322.     vtlist[3].dvTV = backgroundrepeat+v;
  323.  
  324.     // Go on and draw it
  325.     lpD3DDDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, D3DVT_TLVERTEX, (LPVOID)vtlist, 4, NULL);
  326.  
  327.     // Return to normal shading
  328.     if(shading != D3DSHADE_FLAT)
  329.         lpD3DDDevice->SetRenderState(D3DRENDERSTATE_SHADEMODE, shading);
  330. }
  331. */
  332.  
  333. //--------------------------------------------------------------------------------------------
  334. /*PORT
  335. void render_foreground_overlay(unsigned short texture)
  336. {
  337.     // ZZ> This function draws the large transparent overlay
  338.     D3DTLVERTEX vtlist[4];
  339.     DWORD light;
  340.     float size;
  341.     unsigned short rotate;
  342.     float sinsize, cossize;
  343.     D3DVALUE x, y, z, rhw, u, v;
  344.  
  345.  
  346.     // Flat shade this
  347.     if(shading != D3DSHADE_FLAT)
  348.         lpD3DDDevice->SetRenderState(D3DRENDERSTATE_SHADEMODE, D3DSHADE_FLAT);
  349.  
  350.  
  351.     // Choose texture and matrix
  352.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_TEXTUREHANDLE, txTexture[texture].GetHandle());
  353.  
  354.  
  355.  
  356.     // Figure out the screen coordinates of its corners
  357.     x = scrx/2.0;
  358.     y = scry/2.0;
  359.     z = 0;
  360.     rhw = 1.0;
  361.     u = waterlayeru[0];
  362.     v = waterlayerv[0];
  363.     rotate=16384+8192-camturnleftrightshort;
  364.     rotate = rotate>>2;
  365.     size = x + y + 1;
  366.     sinsize = turntosin[rotate]*size;
  367.     cossize = turntosin[(rotate+4096)&16383]*size;
  368.  
  369.     light = (0x00ffffff);
  370.     light |= (waterlayeralpha[0]<<24);
  371.  
  372.     vtlist[0].dvSX = x + cossize;
  373.     vtlist[0].dvSY = y - sinsize;
  374.     vtlist[0].dvSZ = z;
  375.     vtlist[0].dvRHW = rhw;
  376.     vtlist[0].dcColor = light;
  377.     vtlist[0].dcSpecular = 0;
  378.     vtlist[0].dvTU = 0+u;
  379.     vtlist[0].dvTV = 0+v;
  380.  
  381.     vtlist[1].dvSX = x + sinsize;
  382.     vtlist[1].dvSY = y + cossize;
  383.     vtlist[1].dvSZ = z;
  384.     vtlist[1].dvRHW = rhw;
  385.     vtlist[1].dcColor = light;
  386.     vtlist[1].dcSpecular = 0;
  387.     vtlist[1].dvTU = foregroundrepeat+u;
  388.     vtlist[1].dvTV = 0+v;
  389.  
  390.     vtlist[2].dvSX = x - cossize;
  391.     vtlist[2].dvSY = y + sinsize;
  392.     vtlist[2].dvSZ = z;
  393.     vtlist[2].dvRHW = rhw;
  394.     vtlist[2].dcColor = light;
  395.     vtlist[2].dcSpecular = 0;
  396.     vtlist[2].dvTU = foregroundrepeat+u;
  397.     vtlist[2].dvTV = foregroundrepeat+v;
  398.  
  399.     vtlist[3].dvSX = x - sinsize;
  400.     vtlist[3].dvSY = y - cossize;
  401.     vtlist[3].dvSZ = z;
  402.     vtlist[3].dvRHW = rhw;
  403.     vtlist[3].dcColor = light;
  404.     vtlist[3].dcSpecular = 0;
  405.     vtlist[3].dvTU = 0+u;
  406.     vtlist[3].dvTV = foregroundrepeat+v;
  407.  
  408.  
  409.     // Go on and draw it
  410.     lpD3DDDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, D3DVT_TLVERTEX, (LPVOID)vtlist, 4, NULL);
  411.  
  412.  
  413.     // Return to normal shading
  414.     if(shading != D3DSHADE_FLAT)
  415.         lpD3DDDevice->SetRenderState(D3DRENDERSTATE_SHADEMODE, shading);
  416. }
  417. */
  418.  
  419. //--------------------------------------------------------------------------------------------
  420. /*PORT
  421. long FAR PASCAL window_refresh( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  422. {
  423.     // ZZ> This function gets called whenever we get a Windows message
  424.     switch(message)
  425.     {
  426.         case WM_ACTIVATEAPP:
  427.             // Start up
  428.             appactive = wParam;
  429.             break;
  430.         case WM_SETCURSOR:
  431.             // Make sure the hardware cursor stays off
  432.             SetCursor(NULL);
  433.             return TRUE;
  434.         case WM_DESTROY:
  435.             // Shut down
  436.             quit_game();
  437. //            CoUninitialize();
  438.             break;
  439.    }
  440.    return DefWindowProc(hWnd, message, wParam, lParam);
  441. }
  442. */
  443.  
  444. //--------------------------------------------------------------------------------------------
  445. /*PORT
  446. BOOL PASCAL enumcallback(GUID FAR* lpGUID, LPSTR lpDriverDesc, LPSTR lpDriverName, LPVOID lpContext)
  447. {
  448.     // BB> This is the callback routine for enumerating the 3D cards
  449.     //     so we can see if the user has a Voodoo or not
  450.     LPDIRECTDRAW lpDD;
  451.  
  452.     if(DirectDrawCreate(lpGUID, &lpDD, NULL) != DD_OK)
  453.         return(1);                  // SKIP BAD ONES
  454.     if(lpGUID!=NULL)                // Pick this guy first
  455.     {
  456.         enum_id=lpGUID;
  457.         enum_nonnull=1;
  458.         sprintf(enum_desc,"%s",lpDriverDesc);
  459.         particletrans = 0x40000000;  //  Improve smoke for Voodoo
  460.         antialiastrans = 0x60000000;  // Improve antialiasing for Voodoo
  461.         lpDD->Release();
  462.     }
  463.     else
  464.     {
  465.         if(!enum_nonnull)           // If we don't have anything else
  466.         {
  467.             enum_id=lpGUID;
  468.             sprintf(enum_desc,"%s",lpDriverDesc);
  469.             lpDD->Release();
  470.         }
  471.     }
  472.     return(1);                      // Go onto next one
  473. }
  474. */
  475.  
  476. //--------------------------------------------------------------------------------------------
  477. /*PORT
  478. BOOL FAR PASCAL InitJoystickInput(LPCDIDEVICEINSTANCE pdinst,
  479.                                   LPVOID pvRef)
  480. {
  481.     // ZZ> This function turns on up to two joysticks
  482.     LPDIRECTINPUT pdi = lpDI;
  483.     LPDIRECTINPUTDEVICE pdev;
  484.  
  485.  
  486.     // Create the DirectInput joystick device
  487.     if(pdi->CreateDevice(pdinst->guidInstance, &pdev, NULL) != DI_OK)
  488.     {
  489.         return DIENUM_CONTINUE;
  490.     }
  491.  
  492.     // Do important stuff
  493.     if(pdev->SetDataFormat(&c_dfDIJoystick) != DI_OK)
  494.     {
  495.         pdev->Release();
  496.         return DIENUM_CONTINUE;
  497.     }
  498.  
  499.     // Do more important stuff
  500.     if(pdev->SetCooperativeLevel(hGlobalWindow, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND) != DI_OK)
  501.     {
  502.         pdev->Release();
  503.         return DIENUM_CONTINUE;
  504.     }
  505.  
  506.  
  507.  
  508.  
  509.     // Set joystick range on X axis
  510.     DIPROPRANGE diprg;
  511.     diprg.diph.dwSize       = sizeof(diprg);
  512.     diprg.diph.dwHeaderSize = sizeof(diprg.diph);
  513.     diprg.diph.dwObj        = DIJOFS_X;
  514.     diprg.diph.dwHow        = DIPH_BYOFFSET;
  515.     diprg.lMin              = -1000;
  516.     diprg.lMax              = +1000;
  517.     if(pdev->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK)
  518.     {
  519.         pdev->Release();
  520.         return FALSE;
  521.     }
  522.     // Set dead zone to 10%
  523.     DIPROPDWORD dipdw;
  524.     dipdw.diph.dwSize       = sizeof(dipdw);
  525.     dipdw.diph.dwHeaderSize = sizeof(dipdw.diph);
  526.     dipdw.diph.dwObj        = DIJOFS_X;
  527.     dipdw.diph.dwHow        = DIPH_BYOFFSET;
  528.     dipdw.dwData            = 1000;
  529.     if(pdev->SetProperty(DIPROP_DEADZONE, &dipdw.diph) != DI_OK)
  530.     {
  531.         pdev->Release();
  532.         return FALSE;
  533.     }
  534.  
  535.  
  536.     // Set joystick range on Y axis
  537.     diprg.diph.dwSize       = sizeof(diprg);
  538.     diprg.diph.dwHeaderSize = sizeof(diprg.diph);
  539.     diprg.diph.dwObj        = DIJOFS_Y;
  540.     diprg.diph.dwHow        = DIPH_BYOFFSET;
  541.     diprg.lMin              = -1000;
  542.     diprg.lMax              = +1000;
  543.     if(pdev->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK)
  544.     {
  545.         pdev->Release();
  546.         return FALSE;
  547.     }
  548.     // Set dead zone to 10%
  549.     dipdw.diph.dwSize       = sizeof(dipdw);
  550.     dipdw.diph.dwHeaderSize = sizeof(dipdw.diph);
  551.     dipdw.diph.dwObj        = DIJOFS_Y;
  552.     dipdw.diph.dwHow        = DIPH_BYOFFSET;
  553.     dipdw.dwData            = 1000;
  554.     if(pdev->SetProperty(DIPROP_DEADZONE, &dipdw.diph) != DI_OK)
  555.     {
  556.         pdev->Release();
  557.         return FALSE;
  558.     }
  559.  
  560.  
  561.     // Make it simple to access
  562.     numjoy++;
  563.     if(numjoy==1)
  564.     {
  565.         lpDIDJoyA = pdev;
  566.         joyaon = TRUE;
  567.     }
  568.     if(numjoy==2)
  569.     {
  570.         lpDIDJoyB = pdev;
  571.         joybon = TRUE;
  572.     }
  573.  
  574.  
  575.     return TRUE;
  576. }
  577. */
  578.  
  579. //--------------------------------------------------------------------------------------------
  580. /*PORT
  581. BOOL FAR PASCAL ConnectionsCallback(
  582.      LPCGUID lpguidSP, LPVOID lpConnection, DWORD dwConnectionSize,
  583.      LPCDPNAME lpName, DWORD dwFlags, LPVOID lpContext)
  584. {
  585.     // ZZ> This is a callback
  586.     HWND     hWnd = (HWND) lpContext;
  587.     LPVOID   lpConnectionBuffer;
  588.     char cTmp;
  589.     int cnt;
  590.  
  591.  
  592.     if(numservice < MAXSERVICE)
  593.     {
  594.         // make space for connection 
  595.         lpConnectionBuffer = GlobalAllocPtr(GHND, dwConnectionSize);
  596.         if (lpConnectionBuffer != NULL)
  597.         {
  598.             // Store connection data for later
  599.             memcpy(lpConnectionBuffer, lpConnection, dwConnectionSize);
  600.  
  601.  
  602.             // Save that pointer
  603.             netlpconnectionbuffer[numservice] = lpConnectionBuffer;
  604.  
  605.  
  606.             // Copy the name
  607.             cnt = 0;
  608.             cTmp = lpName->lpszShortNameA[cnt];
  609.             while(cnt < NETNAMESIZE-1 && cTmp != 0 && cTmp != ' ')
  610.             {
  611.                 netservicename[numservice][cnt] = cTmp;
  612.                 cnt++;
  613.                 cTmp = lpName->lpszShortNameA[cnt];
  614.             }
  615.             netservicename[numservice][cnt] = 0;
  616.             if(globalnetworkerr)  fprintf(globalnetworkerr, "    %2d. %s\n", numservice, netservicename[numservice]);
  617.  
  618.  
  619.             // Make it official
  620.             numservice++;
  621.         }
  622.     }
  623.     else
  624.     {
  625.         // Say we didn't have room
  626.         if(globalnetworkerr)  fprintf(globalnetworkerr, "    ERROR:  Too many...\n");
  627.     }
  628.     return TRUE;
  629. }
  630.  
  631. */
  632.  
  633. //--------------------------------------------------------------------------------------------
  634. /*PORT
  635. static BOOL setup_directx(HINSTANCE hInstance, int nCmdShow)
  636. {
  637.     // ZZ> This function creates a window and sets up DirectX
  638.     DSBUFFERDESC        dsbd;
  639.     D3DFINDDEVICERESULT result;
  640.     D3DVIEWPORT         viewport;
  641.     HWND                hWnd;
  642.     WNDCLASS            wc;
  643.     DDSURFACEDESC       ddsd;
  644.     HRESULT             ddrval;
  645.     HRESULT             dsrval;
  646.     int                 goodsound = FALSE;
  647.  
  648.  
  649.     // Set up and register window class
  650.     wc.style = CS_HREDRAW | CS_VREDRAW;
  651.     wc.lpfnWndProc = window_refresh;
  652.     wc.cbClsExtra = 0;
  653.     wc.cbWndExtra = 0;
  654.     wc.hInstance = hInstance;
  655.     wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
  656.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  657.     wc.hbrBackground = NULL;
  658.     wc.lpszMenuName = NAME;
  659.     wc.lpszClassName = NAME;
  660.     RegisterClass(&wc);
  661.  
  662.     
  663.     // Create a window
  664.     hWnd = CreateWindowEx(
  665.         WS_EX_TOPMOST,
  666.         NAME,
  667.         TITLE,
  668.         WS_POPUP,
  669.         0, 0,
  670.         GetSystemMetrics(SM_CXSCREEN),
  671.         GetSystemMetrics(SM_CYSCREEN),
  672.         NULL,
  673.         NULL,
  674.         hInstance,
  675.         NULL);
  676.     if(!hWnd)
  677.     {
  678.         return FALSE;
  679.     }
  680.     ShowWindow(hWnd, nCmdShow);
  681.     UpdateWindow(hWnd);
  682.  
  683.  
  684.     // Save the pointer for later
  685.     hGlobalWindow = hWnd;
  686.  
  687.  
  688.     // Get memory for the mesh
  689.     if(!get_mesh_memory())
  690.     {
  691.         directx_setup_error(hWnd, 0, "Reduce the maximum number of vertices!!!  See SETUP.TXT");
  692.         return FALSE;
  693.     }
  694.  
  695.  
  696.     // BB> Find if the user has a Voodoo
  697.     DirectDrawEnumerate(enumcallback,NULL);
  698.     // Create the main DirectDraw object
  699.     ddrval = DirectDrawCreate(enum_id, &lpDD, NULL);
  700.     if(ddrval != DD_OK) { directx_setup_error(hWnd, ddrval, "DirectDraw failed BIG.  See SETUP.TXT");  return FALSE; }
  701.  
  702.  
  703.     // Get exclusive mode
  704.     ddrval = lpDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
  705.     if(ddrval != DD_OK) { directx_setup_error(hWnd, ddrval, "DirectDraw isn't cooperating.  See SETUP.TXT");  return FALSE; }
  706.  
  707.  
  708.     // Set the display mode
  709.     ddrval = lpDD->SetDisplayMode(scrx, scry, scrd);
  710.     if(ddrval != DD_OK) { directx_setup_error(hWnd, ddrval, "Display not set correctly.  See SETUP.TXT");  return FALSE; }
  711.  
  712.  
  713.     // Create a primary surface
  714.     ZeroMemory(&ddsd, sizeof(ddsd));  ddsd.dwSize = sizeof(ddsd);
  715.     ddsd.dwFlags = DDSD_CAPS;
  716.     ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
  717.     ddrval = lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL);
  718.     if(ddrval != DD_OK) { directx_setup_error(hWnd, ddrval, "Primary surface not created.  See SETUP.TXT");  return FALSE; }
  719.  
  720.  
  721.  
  722.     // Attach a back buffer to it...
  723.     ZeroMemory(&ddsd, sizeof(ddsd));  ddsd.dwSize = sizeof(ddsd);
  724.     ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
  725.     ddsd.dwWidth = scrx;
  726.     ddsd.dwHeight = scry;
  727.     if(videoacceleratoron)
  728.         ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY;
  729.     else
  730.         ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER | DDSCAPS_3DDEVICE | DDSCAPS_SYSTEMMEMORY;
  731.     ddrval = lpDD->CreateSurface(&ddsd, &lpDDSBack, NULL);
  732.     if(ddrval != DD_OK) { directx_setup_error(hWnd, ddrval, "Backbuffer not created.  See SETUP.TXT");  return FALSE; }
  733.     if(videoacceleratoron)
  734.     {
  735.         ddrval = lpDDSPrimary->AddAttachedSurface(lpDDSBack);
  736.         if(ddrval != DD_OK) { directx_setup_error(hWnd, ddrval, "Backbuffer not attached.  See SETUP.TXT");  return FALSE; }
  737.     }
  738.  
  739.  
  740.     // Set the palette if in an indexed color mode
  741.     if(scrd == 8)
  742.     {
  743.         lpDDPPalette = DDLoadPalette(lpDD, NULL); //basicdat\\bestpal.pal
  744.         ddrval = lpDDSPrimary->SetPalette(lpDDPPalette);
  745.         if(ddrval != DD_OK) { directx_setup_error(hWnd, ddrval, "Primary palette error.  See SETUP.TXT");  return FALSE; }
  746.         ddrval = lpDDSBack->SetPalette(lpDDPPalette);
  747.         if(ddrval != DD_OK) { directx_setup_error(hWnd, ddrval, "Back palette error");  return FALSE; }
  748.     }
  749.  
  750.  
  751.     // ZB> ...And attach a z-buffer to that
  752.     ZeroMemory(&ddsd, sizeof(ddsd));  ddsd.dwSize = sizeof(ddsd);
  753.     ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_ZBUFFERBITDEPTH;
  754.     ddsd.dwWidth = scrx;
  755.     ddsd.dwHeight = scry;
  756.     ddsd.dwZBufferBitDepth = scrz;
  757.     if(videoacceleratoron)
  758.       ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
  759.     else
  760.       ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_SYSTEMMEMORY;
  761.     ddrval = lpDD->CreateSurface(&ddsd, &lpDDSZbuffer, NULL);
  762.     if(ddrval != DD_OK) { directx_setup_error(hWnd, ddrval, "Zbuffer not created.  See SETUP.TXT");  return FALSE; }
  763.     ddrval = lpDDSBack->AddAttachedSurface(lpDDSZbuffer);
  764.     if(ddrval != DD_OK) { directx_setup_error(hWnd, ddrval, "Zbuffer not attached.  See SETUP.TXT");  return FALSE; }
  765.  
  766.  
  767.     // Get a Direct3D object
  768.     ddrval = lpDD->QueryInterface(IID_IDirect3D2, (LPVOID *)&lpD3D);
  769.     if(ddrval != S_OK) { directx_setup_error(hWnd, ddrval, "Direct3D failed BIG.  See SETUP.TXT");  return FALSE; }
  770.  
  771.  
  772.     // Determine what rendering device to use
  773.     switch(deviceguid)
  774.     {
  775.         case GID_HAL:
  776.             result.guid = IID_IDirect3DHALDevice;
  777.             break;
  778.         case GID_RAMP:
  779.             result.guid = IID_IDirect3DRampDevice;
  780.             break;
  781.         case GID_MMX:
  782.             result.guid = IID_IDirect3DMMXDevice;
  783.             break;
  784.         case GID_RGB:
  785.             result.guid = IID_IDirect3DRGBDevice;
  786.             break;
  787.     }
  788.  
  789.     // Create the D3D device
  790.     ddrval = lpD3D->CreateDevice(result.guid, lpDDSBack, &lpD3DDDevice);
  791.     if(ddrval != DD_OK) { directx_setup_error(hWnd, ddrval, "Direct3D device not created.  See SETUP.TXT");  return FALSE; }
  792.  
  793.  
  794.     // Create a viewport
  795.     ZeroMemory(&viewport, sizeof(viewport));
  796.     viewport.dwSize   = sizeof(viewport);
  797.     viewport.dwWidth  = scrx;
  798.     viewport.dwHeight = scry;
  799.     viewport.dvScaleX = (float) scry;
  800.     viewport.dvScaleY = (float) scry;
  801.     viewport.dvMaxX   = D3DVAL(1.0);
  802.     viewport.dvMaxY   = D3DVAL(1.0);
  803.     ddrval = lpD3D->CreateViewport(&lpD3DVViewport, NULL);
  804.     if(ddrval != D3D_OK) { directx_setup_error(hWnd, ddrval, "Viewport not created.  See SETUP.TXT");  return FALSE; }
  805.     ddrval = lpD3DDDevice->AddViewport(lpD3DVViewport);
  806.     if(ddrval != D3D_OK) { directx_setup_error(hWnd, ddrval, "Viewport not added.  See SETUP.TXT");  return FALSE; }
  807.     ddrval = lpD3DVViewport->SetViewport(&viewport);
  808.     if(ddrval != D3D_OK) { directx_setup_error(hWnd, ddrval, "Viewport not set.  See SETUP.TXT");  return FALSE; }
  809.     ddrval = lpD3DDDevice->SetCurrentViewport(lpD3DVViewport);
  810.     if(ddrval != D3D_OK) { directx_setup_error(hWnd, ddrval, "Viewport not current.  See SETUP.TXT");  return FALSE; }
  811.  
  812.  
  813.     // Make a material if we're in RAMP
  814.     if(deviceguid == GID_RAMP)
  815.     {
  816.         D3DMATERIALHANDLE hMat;
  817.         ddrval = lpD3D->CreateMaterial(&lpD3DMMaterial, NULL);
  818.         if(ddrval != DD_OK) { directx_setup_error(hWnd, ddrval, "Material interface error.  See SETUP.TXT");  return FALSE; }
  819.         memset(&D3DMBackMaterial, 0, sizeof(D3DMATERIAL));
  820.         D3DMBackMaterial.dwSize = sizeof(D3DMATERIAL);
  821.         D3DMBackMaterial.dcvDiffuse.r = 1;
  822.         D3DMBackMaterial.dcvDiffuse.g = 1;
  823.         D3DMBackMaterial.dcvDiffuse.b = 1;
  824.         D3DMBackMaterial.dcvAmbient.r = 0;
  825.         D3DMBackMaterial.dcvAmbient.g = 0;
  826.         D3DMBackMaterial.dcvAmbient.b = 0;
  827.         D3DMBackMaterial.dcvSpecular.r = 0;
  828.         D3DMBackMaterial.dcvSpecular.g = 0;
  829.         D3DMBackMaterial.dcvSpecular.b = 0;
  830.         D3DMBackMaterial.dvPower = 0;
  831.         D3DMBackMaterial.dwRampSize = 16;
  832.         ddrval = lpD3DMMaterial->SetMaterial(&D3DMBackMaterial);
  833.         if(ddrval != D3D_OK) { directx_setup_error(hWnd, ddrval, "Material not set.  See SETUP.TXT");  return FALSE; }
  834.         ddrval = lpD3DMMaterial->GetHandle(lpD3DDDevice, &hMat);
  835.         if(ddrval != D3D_OK) { directx_setup_error(hWnd, ddrval, "Material handle unavailable.  See SETUP.TXT");  return FALSE; }
  836.         ddrval = lpD3DDDevice->SetLightState(D3DLIGHTSTATE_MATERIAL, hMat);
  837.         if(ddrval != D3D_OK) { directx_setup_error(hWnd, ddrval, "Material light not set.  See SETUP.TXT");  return FALSE; }
  838.     }
  839.  
  840.  
  841.  
  842.  
  843.     // Initialize and set the matrices
  844.     mWorld = IdentityMatrix();
  845.     mViewSave = ViewMatrix(D3DVECTOR(0,0,0), D3DVECTOR(0,0,-1), D3DVECTOR(0,1,0), 0);
  846. //    make_camera_matrix();
  847.     mProjection = ProjectionMatrix(.001f, 2000.0f, (float)(FOV*PI/180)); // 60 degree FOV
  848. //old    mProjection = MatrixMult(Translate(0, 0, -.99999f), mProjection); // Fix Z value...
  849. //    mProjection = MatrixMult(ScaleXYZ(1, -1, 10000), mProjection);  // ...'cause it needs it
  850. //better    mProjection = MatrixMult(Translate(0, 0, -.999999f), mProjection); // Fix Z value...
  851. //    mProjection = MatrixMult(ScaleXYZ(1, -1, 100000), mProjection);  // ...'cause it needs it
  852. //works    mProjection = MatrixMult(Translate(0, 0, -.99999859), mProjection); // Fix Z value...
  853. //    mProjection = MatrixMult(ScaleXYZ(1, -1, 500000), mProjection);  // ...'cause it needs it
  854. //    mProjection = MatrixMult(ScaleXYZ(1, -1, 100000), mProjection);  // ...'cause it needs it
  855.  
  856.  
  857.     mProjection = MatrixMult(Translate(0, 0, -.999996), mProjection); // Fix Z value...
  858.     mProjection = MatrixMult(ScaleXYZ(-1, -1, 100000), mProjection);  // HUK // ...'cause it needs it
  859.     lpD3DDDevice->SetTransform(D3DTRANSFORMSTATE_VIEW, &mView);
  860.     lpD3DDDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &mProjection);
  861.  
  862.  
  863.     // ZB> Set the render states
  864.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_ZENABLE,TRUE);
  865.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE,TRUE);
  866.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_ZFUNC,D3DCMP_LESSEQUAL);
  867.  
  868.  
  869.     // Set the render states
  870.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_ANTIALIAS,antialias);
  871.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_TEXTUREADDRESS,D3DTADDRESS_WRAP);
  872.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_FILLMODE,fillmode);
  873.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_CULLMODE,D3DCULL_CCW);
  874.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_SPECULARENABLE,TRUE);
  875.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_ZVISIBLE,FALSE);
  876.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_SUBPIXEL,TRUE);
  877.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_MONOENABLE,FALSE);
  878.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_SHADEMODE,shading);
  879.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
  880.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, TRUE);
  881.  
  882.  
  883.     // Set the player render options
  884.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE,perspective);
  885.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_TEXTUREMAG,filter);
  886.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_TEXTUREMIN,filter);
  887.     lpD3DDDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE,dither);
  888.     if(deviceguid == GID_RAMP || deviceguid == GID_RGB)
  889.     {
  890.         lpD3DDDevice->SetRenderState(D3DRENDERSTATE_MONOENABLE, TRUE);
  891.     }
  892.  
  893.  
  894.     // Turn that sound on...
  895.     if(soundon)
  896.     {
  897.         // Turn it on
  898.         dsrval = DirectSoundCreate(NULL, &lpDirectSound, NULL);
  899.         if(dsrval != DS_OK) { soundon = 0; }
  900.     }
  901.     if(soundon)
  902.     {
  903.         // Set the cooperativity level...  Need 22kHz, 8 bit, stereo sounds
  904.         dsrval = lpDirectSound->SetCooperativeLevel(hWnd, DSSCL_PRIORITY);
  905.         if(dsrval != DS_OK)
  906.         {
  907.             dsrval = lpDirectSound->SetCooperativeLevel(hWnd, DSSCL_NORMAL);
  908.             if(dsrval != DS_OK)
  909.             {
  910.                 soundon = 0;
  911.             }
  912.         }
  913.         else
  914.         {
  915.             goodsound = TRUE;
  916.         }
  917.     }
  918.     if(soundon)
  919.     {
  920.         // Create a primary sound buffer
  921.         memset(&dsbd, 0, sizeof(DSBUFFERDESC));
  922.         dsbd.dwSize = sizeof(DSBUFFERDESC);
  923.         dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER;// | DSBCAPS_GETCURRENTPOSITION2;
  924.         dsbd.dwBufferBytes = 0;
  925.         dsbd.lpwfxFormat = NULL;
  926.         dsrval = lpDirectSound->CreateSoundBuffer(&dsbd, &lpDSPrimaryBuffer, NULL);
  927.         if(dsrval != DS_OK) { soundon = -5; }
  928.     }
  929.     if(soundon)
  930.     {
  931.         if(goodsound)
  932.         {
  933.             // Make it do good sounds
  934.             WAVEFORMATEX wf;
  935.             memset(&wf, 0, sizeof(WAVEFORMATEX)); 
  936.             wf.wFormatTag = WAVE_FORMAT_PCM; 
  937.             wf.nChannels = 2; 
  938.             wf.nSamplesPerSec = 22050; 
  939.             wf.nBlockAlign = 4; 
  940.             wf.nAvgBytesPerSec = wf.nSamplesPerSec * wf.nBlockAlign; 
  941.             wf.wBitsPerSample = 16; 
  942.             lpDSPrimaryBuffer->SetFormat(&wf);
  943.         }
  944.         // Start playing silence
  945.         lpDSPrimaryBuffer->Play(0, 0, 0);
  946.     }
  947.  
  948.  
  949.     // Create the DirectInput object
  950.     ddrval = DirectInputCreate(hInstance, DIRECTINPUT_VERSION, &lpDI, NULL);
  951.     if(ddrval != DI_OK) { directx_setup_error(hWnd, ddrval, "DirectInput failed BIG.  See SETUP.TXT");  return FALSE; }
  952.  
  953.  
  954.     // Create a mouse interface
  955.     if(mouseon)
  956.     {
  957.         // Turn it on
  958.         ddrval = lpDI->CreateDevice(GUID_SysMouse, &lpDIDMouse, NULL);
  959.         if(ddrval != DI_OK) { mouseon = 0;  directx_setup_error(hWnd, 0, "Mouse not turned on!!!");}
  960.     }
  961.     if(mouseon)
  962.     {
  963.         // Data format
  964.         ddrval = lpDIDMouse->SetDataFormat(&c_dfDIMouse);
  965.         if(ddrval != DI_OK) { mouseon = 0;  directx_setup_error(hWnd, 0, "Mouse not formatted!!!");}
  966.     }
  967.     if(mouseon)
  968.     {
  969.         // Cooperativity levels
  970.         ddrval = lpDIDMouse->SetCooperativeLevel(hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
  971.         if(ddrval != DI_OK) { mouseon = 0;  directx_setup_error(hWnd, 0, "Mouse not cooperating!!!");}
  972.     }
  973.  
  974.  
  975.     // Create a keyboard interface
  976.     if(keyon)
  977.     {
  978.         // Turn it on
  979.         ddrval = lpDI->CreateDevice(GUID_SysKeyboard, &lpDIDKey, NULL);
  980.         if(ddrval != DI_OK) { keyon = 0;  directx_setup_error(hWnd, 0, "Keyboard not turned on!!!");}
  981.     }
  982.     if(keyon)
  983.     {
  984.         // Data format
  985.         ddrval = lpDIDKey->SetDataFormat(&c_dfDIKeyboard);
  986.         if(ddrval != DI_OK) { keyon = 0;  directx_setup_error(hWnd, 0, "Keyboard not formatted!!!");}
  987.     }
  988.     if(keyon)
  989.     {
  990.         // Cooperativity levels
  991.         ddrval = lpDIDKey->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
  992.         if(ddrval != DI_OK) { keyon = 0;  directx_setup_error(hWnd, 0, "Keyboard not cooperating!!!");}
  993.     }
  994.  
  995.  
  996.     // Enumerate joysticks ( yeah )
  997.     lpDI->EnumDevices(DIDEVTYPE_JOYSTICK, InitJoystickInput, lpDI, DIEDFL_ATTACHEDONLY);
  998.  
  999.  
  1000.     // Silly stuff for trapezoidal projection
  1001.     rotmeshtopside = ((float)scrx/scry)*ROTMESHTOPSIDE/(1.33333);
  1002.     rotmeshbottomside = ((float)scrx/scry)*ROTMESHBOTTOMSIDE/(1.33333);
  1003.     rotmeshup = ((float)scrx/scry)*ROTMESHUP/(1.33333);
  1004.     rotmeshdown = ((float)scrx/scry)*ROTMESHDOWN/(1.33333);
  1005.  
  1006.  
  1007.     // Turn on networking ( or simulate it )
  1008.     setup_network();
  1009.  
  1010.  
  1011.     // Clear the surfaces to black
  1012.     SetCursor(NULL);
  1013.     clear_surface(lpDDSPrimary);
  1014.     clear_surface(lpDDSBack);
  1015.     return TRUE;
  1016. }
  1017. */
  1018.  
  1019. //--------------------------------------------------------------------------------------------
  1020. /*PORT
  1021. BOOL FAR PASCAL SessionsCallback(
  1022.     LPCDPSESSIONDESC2 lpSessionDesc, LPDWORD lpdwTimeOut,
  1023.     DWORD dwFlags, LPVOID lpContext)
  1024. {
  1025.     // ZZ> This is a callback
  1026.     LPGUID lpGuid;
  1027.     char cTmp;
  1028.     int cnt;
  1029.  
  1030.  
  1031.     // Determine if the enumeration has timed out.
  1032.     if (dwFlags & DPESC_TIMEDOUT)  return FALSE;
  1033.  
  1034.  
  1035.  
  1036.     if(numsession < MAXSESSION)
  1037.     {
  1038.         // Make space for the session instance GUID.
  1039.         lpGuid = (LPGUID) GlobalAllocPtr(GHND, sizeof(GUID));
  1040.         if(lpGuid != NULL)
  1041.         {
  1042.             // Copy the name
  1043.             cnt = 0;
  1044.             cTmp = lpSessionDesc->lpszSessionNameA[cnt];
  1045.             while(cnt < NETNAMESIZE-1 && cTmp != 0)
  1046.             {
  1047.                 if(cTmp == '_')  cTmp = ' ';
  1048.                 netsessionname[numsession][cnt] = cTmp;
  1049.                 cnt++;
  1050.                 cTmp = lpSessionDesc->lpszSessionNameA[cnt];
  1051.             }
  1052.             netsessionname[numsession][cnt] = 0;
  1053.             if(globalnetworkerr)  fprintf(globalnetworkerr, "    %s\n", netsessionname[numsession]);
  1054.  
  1055.  
  1056.             // Store the pointer to the GUID in the list.
  1057.             *lpGuid = lpSessionDesc->guidInstance;
  1058.             netlpsessionguid[numsession] = lpGuid;
  1059.  
  1060.  
  1061.             // Make it official
  1062.             numsession++;
  1063.         }
  1064.     }
  1065.     return TRUE;
  1066. }
  1067. */
  1068. //--------------------------------------------------------------------------------------------
  1069. /*PORT
  1070. BOOL FAR PASCAL PlayersCallback(
  1071.     DPID dpId, DWORD dwPlayerType, LPCDPNAME lpName, DWORD dwFlags, LPVOID lpContext)
  1072. {
  1073.     // ZZ> This is a callback
  1074.     char cTmp;
  1075.     int cnt;
  1076.  
  1077.  
  1078.     if(numplayer < MAXNETPLAYER)
  1079.     {
  1080.         // Copy the ID
  1081.         netplayerid[numplayer] = dpId;
  1082.  
  1083.  
  1084.         // Copy the name
  1085.         cnt = 0;
  1086.         cTmp = lpName->lpszShortNameA[cnt];
  1087.         while(cnt < NETNAMESIZE-1 && cTmp != 0 && cTmp != '\'')
  1088.         {
  1089.             netplayername[numplayer][cnt] = cTmp;
  1090.             cnt++;
  1091.             cTmp = lpName->lpszShortNameA[cnt];
  1092.         }
  1093.         netplayername[numplayer][cnt] = 0;
  1094. //        if(globalnetworkerr)  fprintf(globalnetworkerr, "    %s\n", netplayername[numplayer]);
  1095.  
  1096.  
  1097.         // Make it official
  1098.         numplayer++;
  1099.         return TRUE;
  1100.     }
  1101.     return FALSE;
  1102. }
  1103. */
  1104.