home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / kmine.c < prev    next >
Text File  |  1998-06-08  |  12KB  |  447 lines

  1. /*
  2.  * $Source: f:/miner/source/main/editor/rcs/kmine.c $
  3.  * $Revision: 2.0 $
  4.  * $Author: john $
  5.  * $Date: 1995/02/27 11:34:22 $
  6.  *
  7.  * Functions to change entire mines.
  8.  *
  9.  * $Log: kmine.c $
  10.  * Revision 2.0  1995/02/27  11:34:22  john
  11.  * Version 2.0! No anonymous unions, Watcom 10.0, with no need
  12.  * for bitmaps.tbl.
  13.  * 
  14.  * Revision 1.53  1995/02/22  15:04:52  allender
  15.  * remove anonymous unions from vecmat stuff
  16.  * 
  17.  * Revision 1.52  1994/11/27  23:17:13  matt
  18.  * Made changes for new mprintf calling convention
  19.  * 
  20.  * Revision 1.51  1994/11/17  14:48:05  mike
  21.  * validation functions moved from editor to game.
  22.  * 
  23.  * Revision 1.50  1994/11/17  11:38:49  matt
  24.  * Ripped out code to load old mines
  25.  * 
  26.  * Revision 1.49  1994/10/08  17:10:22  matt
  27.  * Correctly set current_level_num when loading/creating mine in editor
  28.  * 
  29.  * Revision 1.48  1994/10/03  11:30:45  matt
  30.  * Fixed problem with permanant player position when creating a new mine
  31.  * 
  32.  * Revision 1.47  1994/09/29  17:42:19  matt
  33.  * Cleaned up game_mode a little
  34.  * 
  35.  * Revision 1.46  1994/08/18  10:48:21  john
  36.  * Cleaned up game sequencing.
  37.  * 
  38.  * Revision 1.45  1994/08/09  16:05:36  john
  39.  * Added the ability to place players.  Made old
  40.  * Player variable be ConsoleObject.
  41.  * 
  42.  * Revision 1.44  1994/07/22  12:37:06  matt
  43.  * Cleaned up editor/game interactions some more.
  44.  * 
  45.  * Revision 1.43  1994/07/21  17:26:50  matt
  46.  * When new mine created, the default save filename is now reset
  47.  * 
  48.  * Revision 1.42  1994/06/08  14:29:25  matt
  49.  * Took out support for old mine versions
  50.  * 
  51.  * Revision 1.41  1994/06/03  12:28:04  yuan
  52.  * Fixed game restore state.
  53.  * 
  54.  * Revision 1.40  1994/05/19  12:10:29  matt
  55.  * Use new vecmat macros and globals
  56.  * 
  57.  * Revision 1.39  1994/05/14  17:17:56  matt
  58.  * Got rid of externs in source (non-header) files
  59.  * 
  60.  * Revision 1.38  1994/05/12  14:47:47  mike
  61.  * New previous mine structure and object structure.
  62.  * 
  63.  * Revision 1.37  1994/05/06  12:52:12  yuan
  64.  * Adding some gamesave checks...
  65.  * 
  66.  * Revision 1.36  1994/05/05  20:37:02  yuan
  67.  * Added gamesave checks when entering and leaving the game.
  68.  * 
  69.  * Removed Load Game Save Game functions...
  70.  * Now there is only Load/Save Mine... (equivalent to old Load/Save Game)
  71.  * 
  72.  * Revision 1.35  1994/04/27  22:57:54  matt
  73.  * Made sit mine load from path of sit file
  74.  * 
  75.  * Revision 1.34  1994/04/21  18:29:55  matt
  76.  * Don't use same variable for mine filename & sit filename
  77.  * 
  78.  * Revision 1.33  1994/04/21  18:21:43  matt
  79.  * Strip path from mine filename in sit file
  80.  * 
  81.  * Revision 1.32  1994/04/18  10:54:35  mike
  82.  * Add situation save/load
  83.  * 
  84.  * Revision 1.31  1994/02/16  16:47:54  yuan
  85.  * Removed temp.min.
  86.  * 
  87.  * Revision 1.30  1994/02/16  15:22:51  yuan
  88.  * Checking in for editor make.
  89.  * 
  90.  * Revision 1.29  1994/02/09  15:04:23  yuan
  91.  * brought back save ability
  92.  * 
  93.  * Revision 1.28  1994/02/08  12:42:45  yuan
  94.  * fixed log.
  95.  * 
  96.  * Revision 1.27  1994/02/08  12:41:47  yuan
  97.  *    Crippled save mine function from demo version.
  98.  * 
  99.  * Revision 1.26  1994/01/13  13:26:05  yuan
  100.  * Added med_compress_mine when creating new mine or
  101.  * when loading mine
  102.  * 
  103.  * Revision 1.25  1994/01/11  12:03:23  yuan
  104.  * Fixed so that when old mine implementation not in,
  105.  * message is displayed when you try to load an old mine
  106.  * 
  107.  * Revision 1.24  1994/01/11  11:47:57  yuan
  108.  * *** empty log message ***
  109.  * 
  110.  * Revision 1.23  1994/01/05  09:59:56  yuan
  111.  * Added load old mine funciton
  112.  * 
  113.  * Revision 1.22  1993/12/16  15:58:08  john
  114.  * moved texture selection page to texpage.c
  115.  * ,
  116.  * 
  117.  * Revision 1.21  1993/12/10  14:48:55  mike
  118.  * Kill orthogonal views.
  119.  * 
  120.  * Revision 1.20  1993/12/03  16:44:06  yuan
  121.  * Changed some 0.0 return values to 0
  122.  * 
  123.  * 
  124.  * Revision 1.19  1993/12/02  12:39:34  matt
  125.  * Removed extra includes
  126.  * 
  127.  * Revision 1.18  1993/11/17  13:14:48  yuan
  128.  * Moved Save Group to group.c
  129.  * 
  130.  * Revision 1.17  1993/11/16  17:25:48  yuan
  131.  * Unworking group function added... 
  132.  * 
  133.  * Revision 1.16  1993/11/15  14:46:25  john
  134.  * Changed Menu to MenuX
  135.  * 
  136.  * Revision 1.15  1993/11/08  19:13:45  yuan
  137.  * Added Undo command (not working yet)
  138.  * 
  139.  */
  140.  
  141. #pragma off (unreferenced)
  142. static char rcsid[] = "$Id: kmine.c 2.0 1995/02/27 11:34:22 john Exp $";
  143. #pragma on (unreferenced)
  144.  
  145. #include <string.h>
  146. #include <stdio.h>
  147. #include <stdlib.h>
  148.  
  149. #include "error.h"
  150.  
  151. #include "inferno.h"
  152. #include "editor.h"
  153. #include "ui.h"
  154. #include "texpage.h"        // For texpage_goto_first
  155. #include "segment.h"
  156. #include "mono.h"
  157. #include "kdefs.h"
  158. #include "info.h"
  159. #include "game.h"
  160. #include "gameseq.h"
  161.  
  162. #include "dcflib.h"
  163. #include "nocfile.h"
  164.  
  165. #include "object.h"
  166.  
  167. #define MINESAVE_CRIPPLED    0
  168.  
  169. char mine_filename[128] = "*.MIN";
  170. char sit_filename[128] = "*.SIT";
  171.  
  172. #define MAX_NAME_LENGTH 128
  173.  
  174. //    See if filename f contains an extent.  If not, add extent ext.
  175. void checkforext( char * f, char *ext )
  176. {
  177.     int i;
  178.  
  179.     for (i=1; i<MAX_NAME_LENGTH; i++ ) {
  180.         if (f[i]=='.')
  181.             return;
  182.  
  183.         if ((f[i] == ' ') || (f[i]==0) ) {
  184.             f[i] = '.';
  185.             f[i+1] = ext[0];
  186.             f[i+2] = ext[1];
  187.             f[i+3] = ext[2];
  188.             f[i+4] = 0;
  189.             return;
  190.         }
  191.     }
  192.  
  193.     if (i < 123) {
  194.         f[i] = '.';
  195.         f[i+1] = ext[0];
  196.         f[i+2] = ext[1];
  197.         f[i+3] = ext[2];
  198.         f[i+4] = 0;
  199.         return;
  200.     }
  201. }
  202.  
  203. //    See if filename f contains an extent.  If not, add extent ext.
  204. void set_extension( char * f, char *ext )
  205. {
  206.     int i;
  207.  
  208.     for (i=1; i<MAX_NAME_LENGTH-4; i++ ) {
  209.         if ((f[i]=='.') || (f[i] == ' ') || (f[i]==0) ) {
  210.             f[i] = '.';
  211.             f[i+1] = ext[0];
  212.             f[i+2] = ext[1];
  213.             f[i+3] = ext[2];
  214.             f[i+4] = 0;
  215.             return;
  216.         }
  217.     }
  218. }
  219.  
  220. #if MINESAVE_CRIPPLED
  221. int SaveMine()
  222. {
  223.     char  ErrorMessage[200];
  224.  
  225.     sprintf( ErrorMessage, "Save Mine not available in demo version.\n");
  226.     MessageBox( -2, -2, 1, ErrorMessage, "Ok" );
  227.     return 1;
  228. }
  229. #endif
  230.  
  231. #if !MINESAVE_CRIPPLED
  232. int SaveMine()
  233. {
  234.     // Save mine
  235. //    med_save_mine("TEMP.MIN");
  236.     if (ui_get_filename( mine_filename, "*.MIN", "SAVE MINE" ))
  237.     {
  238.         checkforext(mine_filename, "MIN");
  239.         if (med_save_mine(mine_filename))
  240.             return 0;
  241.         mine_changed = 0;
  242.     }
  243.     
  244.     return 1;
  245. }
  246. #endif
  247.  
  248. int CreateNewMine()
  249. {
  250.     if (SafetyCheck())  {
  251.         texpage_goto_first();
  252.         create_new_mine();
  253.         LargeView.ev_matrix = vmd_identity_matrix;    //FrontView.ev_matrix;
  254.         set_view_target_from_segment(Cursegp);
  255.         vm_vec_make(&Seg_scale,DEFAULT_X_SIZE,DEFAULT_Y_SIZE,DEFAULT_Z_SIZE);
  256.         Update_flags = UF_WORLD_CHANGED;
  257.         SetPlayerFromCurseg();
  258.         SetPlayerPosition();        //say default is permanant position
  259.         mine_changed = 0;
  260.         N_found_segs = 0;
  261.         N_selected_segs = 0;
  262.         med_compress_mine();
  263.         gamestate_not_restored = 0;
  264.         init_info = 1;
  265.         ResetFilename();
  266.         Game_mode = GM_UNKNOWN;
  267.         Current_level_num = 0;        //0 means not a real game
  268.     }
  269.     return 1;
  270. }
  271.  
  272. int MineMenu()
  273. {
  274.     int x;
  275.     char * MenuItems[] = { "New mine",
  276.                        "Load mine",
  277.                        "Save mine",
  278.                        "Print mine",
  279.                        "Redraw mine" };
  280.  
  281.     x = MenuX( -1, -1, 5, MenuItems );
  282.  
  283.     switch( x )
  284.     {
  285.     case 1:     // New
  286.         CreateNewMine();
  287.         break;
  288.     case 2:     // Load
  289.         //@@LoadMine();
  290.         break;
  291.     case 3:     // Save
  292.         SaveMine();
  293.         break;
  294.     case 4:     // Print
  295.         break;
  296.     case 5:     // Redraw
  297.         Update_flags = UF_ALL;
  298.         break;
  299.     }
  300.     return 1;
  301. }
  302.  
  303. // -----------------------------------------------------------------------------
  304. // returns 1 if error, else 0
  305. int med_load_situation(char * filename)
  306. {
  307.     if (filename[0] == 97)
  308.         Int3();
  309.     Int3();
  310.  
  311.     return 1;
  312. //@@    CFILE * LoadFile;
  313. //@@    char    mine_name[MAX_NAME_LENGTH];
  314. //@@    char    dir_name[_MAX_DIR];
  315. //@@    char    mine_path[MAX_NAME_LENGTH];
  316. //@@    vms_vector    pos;
  317. //@@    fix    mat[9];
  318. //@@
  319. //@@    LoadFile = cfopen( filename, "rt" );
  320. //@@    if (!LoadFile)    {
  321. //@@        char  ErrorMessage[200];
  322. //@@
  323. //@@        sprintf( ErrorMessage, "ERROR: Unable to open %s\n", filename );
  324. //@@        MessageBox( -2, -2, 1, ErrorMessage, "Ok" );
  325. //@@        return 1;
  326. //@@    }
  327. //@@
  328. //@@    fscanf(LoadFile, "%s", &mine_name);
  329. //@@    mprintf((0, "Mine name = [%s]\n", mine_name));
  330. //@@
  331. //@@    _splitpath(filename,mine_path,dir_name,NULL,NULL);
  332. //@@    strcat(mine_path,dir_name);
  333. //@@    strcat(mine_path,mine_name);
  334. //@@
  335. //@@    mprintf((0, "Mine path = [%s]\n", mine_path));
  336. //@@
  337. //@@    med_load_mine(mine_path);
  338. //@@
  339. //@@    fscanf(LoadFile, "%x %x %x", &pos.x, &pos.y, &pos.z);
  340. //@@    mprintf((0, "Load Position = %8x %8x %8x\n", pos.x, pos.y, pos.z));
  341. //@@    mprintf((0, "\n"));
  342. //@@
  343. //@@    fscanf(LoadFile, "%x %x %x", &mat[0], &mat[1], &mat[2]);
  344. //@@    mprintf((0, "%8x %8x %8x\n", mat[0], mat[1], mat[2]));
  345. //@@
  346. //@@    fscanf(LoadFile, "%x %x %x", &mat[3], &mat[4], &mat[5]);
  347. //@@    mprintf((0, "%8x %8x %8x\n", mat[3], mat[4], mat[5]));
  348. //@@
  349. //@@    fscanf(LoadFile, "%x %x %x", &mat[6], &mat[7], &mat[8]);
  350. //@@    mprintf((0, "%8x %8x %8x\n", mat[6], mat[7], mat[8]));
  351. //@@    mprintf((0, "\n"));
  352. //@@
  353. //@@    fscanf(LoadFile, "%i\n", &ConsoleObject->segnum);
  354. //@@
  355. //@@    cfclose( LoadFile );
  356. //@@
  357. //@@    ConsoleObject->pos = pos;
  358. //@@    ConsoleObject->orient.m1 = mat[0];    ConsoleObject->orient.m2 = mat[1];    ConsoleObject->orient.m3 = mat[2];
  359. //@@    ConsoleObject->orient.m4 = mat[3];    ConsoleObject->orient.m5 = mat[4];    ConsoleObject->orient.m6 = mat[5];
  360. //@@    ConsoleObject->orient.m7 = mat[6];    ConsoleObject->orient.m8 = mat[7];    ConsoleObject->orient.m9 = mat[8];
  361. //@@
  362. //@@    return 0;
  363. }
  364.  
  365. //    -----------------------------------------------------------------------------
  366. int med_save_situation(char * filename)
  367. {
  368.     CFILE * SaveFile;
  369.     char    mine_name[MAX_NAME_LENGTH];
  370.  
  371.     SaveFile = cfopen( filename, "wt" );
  372.     if (!SaveFile)    {
  373.         char  ErrorMessage[200];
  374.  
  375.         sprintf( ErrorMessage, "ERROR: Unable to open %s\n", filename );
  376.         MessageBox( -2, -2, 1, ErrorMessage, "Ok" );
  377.         return 1;
  378.     }
  379.  
  380.     //    Write mine name.
  381. //    strcpy(mine_name, filename);
  382. _splitpath(filename,NULL,NULL,mine_name,NULL);
  383.     set_extension(mine_name, "min");
  384.     fprintf(SaveFile, "%s\n", mine_name);
  385.  
  386.     //    Write player position.
  387.     fprintf(SaveFile, "%x %x %x\n", ConsoleObject->pos.x, ConsoleObject->pos.y, ConsoleObject->pos.z);
  388.  
  389.     //    Write player orientation.
  390.     fprintf(SaveFile, "%x %x %x\n", ConsoleObject->orient.rvec.x, ConsoleObject->orient.rvec.y, ConsoleObject->orient.rvec.z);
  391.     fprintf(SaveFile, "%x %x %x\n", ConsoleObject->orient.uvec.x, ConsoleObject->orient.uvec.y, ConsoleObject->orient.uvec.z);             
  392.     fprintf(SaveFile, "%x %x %x\n", ConsoleObject->orient.fvec.x, ConsoleObject->orient.fvec.y, ConsoleObject->orient.fvec.z);
  393.     fprintf(SaveFile, "%i\n", ConsoleObject->segnum);
  394.  
  395.     mprintf((0, "Save Position = %8x %8x %8x\n", ConsoleObject->pos.x, ConsoleObject->pos.y, ConsoleObject->pos.z));
  396.     mprintf((0, "\n"));
  397.  
  398.     mprintf((0, "%8x %8x %8x\n", ConsoleObject->orient.rvec.x, ConsoleObject->orient.rvec.y, ConsoleObject->orient.rvec.z));
  399.     mprintf((0, "%8x %8x %8x\n", ConsoleObject->orient.uvec.x, ConsoleObject->orient.uvec.y, ConsoleObject->orient.uvec.z));
  400.     mprintf((0, "%8x %8x %8x\n", ConsoleObject->orient.fvec.x, ConsoleObject->orient.fvec.y, ConsoleObject->orient.fvec.z));
  401.     mprintf((0, "\n"));
  402.  
  403.     cfclose( SaveFile);
  404.  
  405.     return 1;
  406. }
  407.  
  408. //    -----------------------------------------------------------------------------
  409. int SaveSituation(void)
  410. {
  411.     if (ui_get_filename( sit_filename, "*.SIT", "Save Situation" )) {
  412.         set_extension(sit_filename, "MIN");
  413.         if (med_save_mine(sit_filename)) {
  414.             mprintf((0, "Unable to save mine in SaveSituation.\n"));
  415.             return 0;
  416.         }
  417.  
  418.         set_extension(sit_filename, "SIT");
  419.         if (med_save_situation(sit_filename))
  420.             return 0;
  421.     }
  422.     
  423.     return 1;
  424. }
  425.  
  426. //    -----------------------------------------------------------------------------
  427. //    Load a situation file which consists of x,y,z, orientation matrix, mine name.
  428. int LoadSituation(void)
  429. {
  430.     if (SafetyCheck())  {
  431.         if (ui_get_filename( sit_filename, "*.sit", "Load Situation" ))    {
  432.          checkforext(sit_filename, "SIT");
  433.          if (med_load_situation(sit_filename))
  434.                  return 0;
  435.             // set_view_target_from_segment(Cursegp);
  436.             Update_flags = UF_WORLD_CHANGED;
  437.             // SetPlayerFromCurseg();
  438.             med_compress_mine();
  439.             init_info = 1;
  440.             mine_changed = 0;
  441.         }
  442.     }
  443.  
  444.     return 1;
  445. }
  446.  
  447.