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