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