1 /* $Id: kmine.c,v 1.3 2004-12-19 15:21:11 btb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Functions to change entire mines.
22 static char rcsid[] = "$Id: kmine.c,v 1.3 2004-12-19 15:21:11 btb Exp $";
38 #include "texpage.h" // For texpage_goto_first
50 #define MINESAVE_CRIPPLED 0
52 char mine_filename[128] = "*.MIN";
53 char sit_filename[128] = "*.SIT";
55 #define MAX_NAME_LENGTH 128
57 // See if filename f contains an extent. If not, add extent ext.
58 void checkforext( char * f, char *ext )
62 for (i=1; i<MAX_NAME_LENGTH; i++ ) {
66 if ((f[i] == ' ') || (f[i]==0) ) {
86 // See if filename f contains an extent. If not, add extent ext.
87 void set_extension( char * f, char *ext )
91 for (i=1; i<MAX_NAME_LENGTH-4; i++ ) {
92 if ((f[i]=='.') || (f[i] == ' ') || (f[i]==0) ) {
103 #if MINESAVE_CRIPPLED
106 char ErrorMessage[200];
108 sprintf( ErrorMessage, "Save Mine not available in demo version.\n");
109 MessageBox( -2, -2, 1, ErrorMessage, "Ok" );
114 #if !MINESAVE_CRIPPLED
118 // med_save_mine("TEMP.MIN");
119 if (ui_get_filename( mine_filename, "*.MIN", "SAVE MINE" ))
121 checkforext(mine_filename, "MIN");
122 if (med_save_mine(mine_filename))
134 texpage_goto_first();
136 LargeView.ev_matrix = vmd_identity_matrix; //FrontView.ev_matrix;
137 set_view_target_from_segment(Cursegp);
138 vm_vec_make(&Seg_scale,DEFAULT_X_SIZE,DEFAULT_Y_SIZE,DEFAULT_Z_SIZE);
139 Update_flags = UF_WORLD_CHANGED;
140 SetPlayerFromCurseg();
141 SetPlayerPosition(); //say default is permanant position
146 gamestate_not_restored = 0;
149 Game_mode = GM_UNKNOWN;
150 Current_level_num = 0; //0 means not a real game
158 char * MenuItems[] = { "New mine",
164 x = MenuX( -1, -1, 5, MenuItems );
180 Update_flags = UF_ALL;
186 // -----------------------------------------------------------------------------
187 // returns 1 if error, else 0
188 int med_load_situation(char * filename)
190 if (filename[0] == 97)
195 //@@ CFILE * LoadFile;
196 //@@ char mine_name[MAX_NAME_LENGTH];
197 //@@ char dir_name[_MAX_DIR];
198 //@@ char mine_path[MAX_NAME_LENGTH];
202 //@@ LoadFile = cfopen( filename, "rt" );
203 //@@ if (!LoadFile) {
204 //@@ char ErrorMessage[200];
206 //@@ sprintf( ErrorMessage, "ERROR: Unable to open %s\n", filename );
207 //@@ MessageBox( -2, -2, 1, ErrorMessage, "Ok" );
211 //@@ fscanf(LoadFile, "%s", &mine_name);
212 //@@ mprintf((0, "Mine name = [%s]\n", mine_name));
214 //@@ _splitpath(filename,mine_path,dir_name,NULL,NULL);
215 //@@ strcat(mine_path,dir_name);
216 //@@ strcat(mine_path,mine_name);
218 //@@ mprintf((0, "Mine path = [%s]\n", mine_path));
220 //@@ med_load_mine(mine_path);
222 //@@ fscanf(LoadFile, "%x %x %x", &pos.x, &pos.y, &pos.z);
223 //@@ mprintf((0, "Load Position = %8x %8x %8x\n", pos.x, pos.y, pos.z));
224 //@@ mprintf((0, "\n"));
226 //@@ fscanf(LoadFile, "%x %x %x", &mat[0], &mat[1], &mat[2]);
227 //@@ mprintf((0, "%8x %8x %8x\n", mat[0], mat[1], mat[2]));
229 //@@ fscanf(LoadFile, "%x %x %x", &mat[3], &mat[4], &mat[5]);
230 //@@ mprintf((0, "%8x %8x %8x\n", mat[3], mat[4], mat[5]));
232 //@@ fscanf(LoadFile, "%x %x %x", &mat[6], &mat[7], &mat[8]);
233 //@@ mprintf((0, "%8x %8x %8x\n", mat[6], mat[7], mat[8]));
234 //@@ mprintf((0, "\n"));
236 //@@ fscanf(LoadFile, "%i\n", &ConsoleObject->segnum);
238 //@@ cfclose( LoadFile );
240 //@@ ConsoleObject->pos = pos;
241 //@@ ConsoleObject->orient.m1 = mat[0]; ConsoleObject->orient.m2 = mat[1]; ConsoleObject->orient.m3 = mat[2];
242 //@@ ConsoleObject->orient.m4 = mat[3]; ConsoleObject->orient.m5 = mat[4]; ConsoleObject->orient.m6 = mat[5];
243 //@@ ConsoleObject->orient.m7 = mat[6]; ConsoleObject->orient.m8 = mat[7]; ConsoleObject->orient.m9 = mat[8];
248 // -----------------------------------------------------------------------------
249 int med_save_situation(char * filename)
252 char mine_name[MAX_NAME_LENGTH];
254 SaveFile = cfopen( filename, "wt" );
256 char ErrorMessage[200];
258 sprintf( ErrorMessage, "ERROR: Unable to open %s\n", filename );
259 MessageBox( -2, -2, 1, ErrorMessage, "Ok" );
264 // strcpy(mine_name, filename);
266 _splitpath(filename,NULL,NULL,mine_name,NULL);
268 set_extension(mine_name, "min");
269 fprintf(SaveFile, "%s\n", mine_name);
271 // Write player position.
272 fprintf(SaveFile, "%x %x %x\n",(unsigned int) ConsoleObject->pos.x,(unsigned int) ConsoleObject->pos.y,(unsigned int) ConsoleObject->pos.z);
274 // Write player orientation.
275 fprintf(SaveFile, "%8x %8x %8x\n",(unsigned int) ConsoleObject->orient.rvec.x,(unsigned int) ConsoleObject->orient.rvec.y,(unsigned int) ConsoleObject->orient.rvec.z);
276 fprintf(SaveFile, "%8x %8x %8x\n",(unsigned int) ConsoleObject->orient.uvec.x,(unsigned int) ConsoleObject->orient.uvec.y,(unsigned int) ConsoleObject->orient.uvec.z);
277 fprintf(SaveFile, "%8x %8x %8x\n",(unsigned int) ConsoleObject->orient.fvec.x,(unsigned int) ConsoleObject->orient.fvec.y,(unsigned int) ConsoleObject->orient.fvec.z);
278 fprintf(SaveFile, "%i\n", ConsoleObject->segnum);
280 mprintf((0, "Save Position = %8x %8x %8x\n", ConsoleObject->pos.x, ConsoleObject->pos.y, ConsoleObject->pos.z));
283 mprintf((0, "%8x %8x %8x\n", ConsoleObject->orient.rvec.x, ConsoleObject->orient.rvec.y, ConsoleObject->orient.rvec.z));
284 mprintf((0, "%8x %8x %8x\n", ConsoleObject->orient.uvec.x, ConsoleObject->orient.uvec.y, ConsoleObject->orient.uvec.z));
285 mprintf((0, "%8x %8x %8x\n", ConsoleObject->orient.fvec.x, ConsoleObject->orient.fvec.y, ConsoleObject->orient.fvec.z));
293 // -----------------------------------------------------------------------------
294 int SaveSituation(void)
296 if (ui_get_filename( sit_filename, "*.SIT", "Save Situation" )) {
297 set_extension(sit_filename, "MIN");
298 if (med_save_mine(sit_filename)) {
299 mprintf((0, "Unable to save mine in SaveSituation.\n"));
303 set_extension(sit_filename, "SIT");
304 if (med_save_situation(sit_filename))
311 // -----------------------------------------------------------------------------
312 // Load a situation file which consists of x,y,z, orientation matrix, mine name.
313 int LoadSituation(void)
316 if (ui_get_filename( sit_filename, "*.sit", "Load Situation" )) {
317 checkforext(sit_filename, "SIT");
318 if (med_load_situation(sit_filename))
320 // set_view_target_from_segment(Cursegp);
321 Update_flags = UF_WORLD_CHANGED;
322 // SetPlayerFromCurseg();