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

  1. /*
  2.  * $Source: f:/miner/source/main/editor/rcs/kgame.c $
  3.  * $Revision: 2.0 $
  4.  * $Author: john $
  5.  * $Date: 1995/02/27 11:34:55 $
  6.  * 
  7.  * Game Loading editor functions
  8.  * 
  9.  * $Log: kgame.c $
  10.  * Revision 2.0  1995/02/27  11:34:55  john
  11.  * Version 2.0! No anonymous unions, Watcom 10.0, with no need
  12.  * for bitmaps.tbl.
  13.  * 
  14.  * Revision 1.25  1995/02/23  10:18:05  allender
  15.  * fixed parameter mismatch with compute_segment_center
  16.  * 
  17.  * Revision 1.24  1994/11/17  11:38:59  matt
  18.  * Ripped out code to load old mines
  19.  * 
  20.  * Revision 1.23  1994/11/09  11:58:56  matt
  21.  * Fixed small bug
  22.  * 
  23.  * Revision 1.22  1994/10/20  12:48:02  matt
  24.  * Replaced old save files (MIN/SAV/HOT) with new LVL files
  25.  * 
  26.  * Revision 1.21  1994/10/15  19:08:47  mike
  27.  * Fix bug if player object out of mine at save.
  28.  * 
  29.  * Revision 1.20  1994/10/13  13:15:43  matt
  30.  * Properly relink player object when bashed for "permanant" position save
  31.  * 
  32.  * Revision 1.19  1994/10/11  17:07:23  matt
  33.  * Fixed problem that sometimes caused bad player segnum after compress
  34.  * 
  35.  * Revision 1.18  1994/10/08  17:10:40  matt
  36.  * Correctly set current_level_num when loading/creating mine in editor
  37.  * 
  38.  * Revision 1.17  1994/09/26  23:46:13  matt
  39.  * Improved player position save code
  40.  * 
  41.  * Revision 1.16  1994/09/26  23:22:50  matt
  42.  * Added functions to keep player's starting position from getting messed up
  43.  * 
  44.  * Revision 1.15  1994/09/14  16:50:51  yuan
  45.  * Added load mine only function
  46.  * 
  47.  * Revision 1.14  1994/07/22  12:36:50  matt
  48.  * Cleaned up editor/game interactions some more.
  49.  * 
  50.  * Revision 1.13  1994/07/21  17:26:26  matt
  51.  * When new mine created, the default save filename is now reset
  52.  * 
  53.  * Revision 1.12  1994/06/03  12:27:05  yuan
  54.  * Fixed restore game state.
  55.  * 
  56.  * 
  57.  * Revision 1.11  1994/05/30  11:36:09  yuan
  58.  * Do gamesave if new mine is loaded and game is entered...
  59.  * 
  60.  * Revision 1.10  1994/05/14  18:00:33  matt
  61.  * Got rid of externs in source (non-header) files
  62.  * 
  63.  * Revision 1.9  1994/05/10  12:15:44  yuan
  64.  * Fixed load_game functions to match prototype.
  65.  * 
  66.  * Revision 1.8  1994/05/06  12:52:15  yuan
  67.  * Adding some gamesave checks...
  68.  * 
  69.  * Revision 1.7  1994/05/04  17:32:05  yuan
  70.  * med_load_game changed to load_game
  71.  * med_save_game changed to save_game
  72.  * 
  73.  */
  74.  
  75. #pragma off (unreferenced)
  76. static char rcsid[] = "$Id: kgame.c 2.0 1995/02/27 11:34:55 john Exp $";
  77. #pragma on (unreferenced)
  78.  
  79. #include <string.h>
  80. #include <stdio.h>
  81.  
  82. #include "inferno.h"
  83. #include "editor.h"
  84. #include "ui.h"
  85. #include "game.h"
  86. #include "gamesave.h"
  87. #include "gameseq.h"
  88.  
  89. char game_filename[128] = "*.LVL";
  90.  
  91. extern void checkforext( char * f, char *ext );
  92.  
  93. void checkforgamext( char * f )
  94. {
  95.     int i;
  96.  
  97.     for (i=1; i<strlen(f); i++ )
  98.     {
  99.         if (f[i]=='.') return;
  100.  
  101.         if ((f[i]==' '||f[i]==0) )
  102.         {
  103.             f[i]='.';
  104.             f[i+1]='L';
  105.             f[i+2]= 'V';
  106.             f[i+3]= 'L';
  107.             f[i+4]=0;
  108.             return;
  109.         }
  110.     }
  111.  
  112.     if (i < 123)
  113.     {
  114.         f[i]='.';
  115.         f[i+1]='L';
  116.         f[i+2]= 'V';
  117.         f[i+3]= 'L';
  118.         f[i+4]=0;
  119.         return;
  120.     }
  121. }
  122.  
  123. //these variables store the "permanant" player position, which overrides
  124. //whatever the player's position happens to be when the game is saved
  125. int Perm_player_segnum=-1;        //-1 means position not set
  126. vms_vector Perm_player_position;
  127. vms_matrix Perm_player_orient;
  128.  
  129. //set the player's "permanant" position from the current position
  130. SetPlayerPosition()
  131. {
  132.     Perm_player_position = ConsoleObject->pos;
  133.     Perm_player_orient = ConsoleObject->orient;
  134.     Perm_player_segnum = ConsoleObject->segnum;
  135.  
  136.     editor_status("Player initial position set");
  137. }
  138.  
  139. // Save game
  140. // returns 1 if successful
  141. //    returns 0 if unsuccessful
  142. int SaveGameData()
  143. {
  144.     char Message[200];
  145.  
  146.     if (gamestate_not_restored) {
  147.         sprintf( Message, "Game State has not been restored...\nContinue?\n");
  148.         if (MessageBox( -2, -2, 2, Message, "NO", "Yes" )==1) 
  149.             return 0;
  150.         }
  151.         
  152.    if (ui_get_filename( game_filename, "*.LVL", "SAVE GAME" )) {
  153.         int saved_flag;
  154.         vms_vector save_pos = ConsoleObject->pos;
  155.         vms_matrix save_orient = ConsoleObject->orient;
  156.         int save_segnum = ConsoleObject->segnum;
  157.  
  158.       checkforgamext(game_filename);
  159.  
  160.         if (Perm_player_segnum > Highest_segment_index)
  161.             Perm_player_segnum = -1;
  162.  
  163.         if (Perm_player_segnum!=-1) {
  164.             if (get_seg_masks(&Perm_player_position,Perm_player_segnum,0).centermask==0) {
  165.                 ConsoleObject->pos = Perm_player_position;
  166.                 obj_relink(ConsoleObject-Objects,Perm_player_segnum);
  167.                 ConsoleObject->orient = Perm_player_orient;
  168.             }
  169.             else
  170.                 Perm_player_segnum=-1;        //position was bogus
  171.         }
  172.       saved_flag=save_level(game_filename);
  173.         if (Perm_player_segnum!=-1) {
  174.             int    found_save_segnum;
  175.  
  176.             if (save_segnum > Highest_segment_index)
  177.                 save_segnum = 0;
  178.  
  179.             ConsoleObject->pos = save_pos;
  180.             found_save_segnum = find_point_seg(&save_pos,save_segnum);
  181.             if (found_save_segnum == -1) {
  182.                 compute_segment_center(&save_pos, &(Segments[save_segnum]));
  183.                 found_save_segnum = save_segnum;
  184.             }
  185.  
  186.             obj_relink(ConsoleObject-Objects,found_save_segnum);
  187.             ConsoleObject->orient = save_orient;
  188.         }
  189.         if (saved_flag)
  190.             return 0;
  191.         mine_changed = 0;
  192.     }
  193.     return 1;
  194. }
  195.  
  196. // returns 1 if successful
  197. //    returns 0 if unsuccessful
  198. int LoadGameData()
  199. {
  200. if (SafetyCheck())  {
  201.     if (ui_get_filename( game_filename, "*.LVL", "LOAD GAME" ))
  202.         {
  203.         checkforgamext(game_filename);
  204.         if (load_level(game_filename))
  205.             return 0;
  206.         Current_level_num = 0;            //not a real level
  207.         gamestate_not_restored = 0;
  208.         Update_flags = UF_WORLD_CHANGED;
  209.         Perm_player_position = ConsoleObject->pos;
  210.         Perm_player_orient = ConsoleObject->orient;
  211.         Perm_player_segnum = ConsoleObject->segnum;
  212.         }
  213.     }
  214.     return 1;
  215. }
  216.  
  217. //called whenever a new mine is created, so new mine doesn't get name
  218. //of last saved mine as default
  219. void ResetFilename()
  220. {
  221.     strcpy(game_filename,"*.LVL");
  222. }
  223.  
  224.