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

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