1 /* $Id: kmine.c,v 1.2 2004-12-19 14:52:48 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.2 2004-12-19 14:52:48 btb Exp $";
34 #include "texpage.h" // For texpage_goto_first
46 #define MINESAVE_CRIPPLED 0
48 char mine_filename[128] = "*.MIN";
49 char sit_filename[128] = "*.SIT";
51 #define MAX_NAME_LENGTH 128
53 // See if filename f contains an extent. If not, add extent ext.
54 void checkforext( char * f, char *ext )
58 for (i=1; i<MAX_NAME_LENGTH; i++ ) {
62 if ((f[i] == ' ') || (f[i]==0) ) {
82 // See if filename f contains an extent. If not, add extent ext.
83 void set_extension( char * f, char *ext )
87 for (i=1; i<MAX_NAME_LENGTH-4; i++ ) {
88 if ((f[i]=='.') || (f[i] == ' ') || (f[i]==0) ) {
102 char ErrorMessage[200];
104 sprintf( ErrorMessage, "Save Mine not available in demo version.\n");
105 MessageBox( -2, -2, 1, ErrorMessage, "Ok" );
110 #if !MINESAVE_CRIPPLED
114 // med_save_mine("TEMP.MIN");
115 if (ui_get_filename( mine_filename, "*.MIN", "SAVE MINE" ))
117 checkforext(mine_filename, "MIN");
118 if (med_save_mine(mine_filename))
130 texpage_goto_first();
132 LargeView.ev_matrix = vmd_identity_matrix; //FrontView.ev_matrix;
133 set_view_target_from_segment(Cursegp);
134 vm_vec_make(&Seg_scale,DEFAULT_X_SIZE,DEFAULT_Y_SIZE,DEFAULT_Z_SIZE);
135 Update_flags = UF_WORLD_CHANGED;
136 SetPlayerFromCurseg();
137 SetPlayerPosition(); //say default is permanant position
142 gamestate_not_restored = 0;
145 Game_mode = GM_UNKNOWN;
146 Current_level_num = 0; //0 means not a real game
154 char * MenuItems[] = { "New mine",
160 x = MenuX( -1, -1, 5, MenuItems );
176 Update_flags = UF_ALL;
182 // -----------------------------------------------------------------------------
183 // returns 1 if error, else 0
184 int med_load_situation(char * filename)
186 if (filename[0] == 97)
191 //@@ CFILE * LoadFile;
192 //@@ char mine_name[MAX_NAME_LENGTH];
193 //@@ char dir_name[_MAX_DIR];
194 //@@ char mine_path[MAX_NAME_LENGTH];
198 //@@ LoadFile = cfopen( filename, "rt" );
199 //@@ if (!LoadFile) {
200 //@@ char ErrorMessage[200];
202 //@@ sprintf( ErrorMessage, "ERROR: Unable to open %s\n", filename );
203 //@@ MessageBox( -2, -2, 1, ErrorMessage, "Ok" );
207 //@@ fscanf(LoadFile, "%s", &mine_name);
208 //@@ mprintf((0, "Mine name = [%s]\n", mine_name));
210 //@@ _splitpath(filename,mine_path,dir_name,NULL,NULL);
211 //@@ strcat(mine_path,dir_name);
212 //@@ strcat(mine_path,mine_name);
214 //@@ mprintf((0, "Mine path = [%s]\n", mine_path));
216 //@@ med_load_mine(mine_path);
218 //@@ fscanf(LoadFile, "%x %x %x", &pos.x, &pos.y, &pos.z);
219 //@@ mprintf((0, "Load Position = %8x %8x %8x\n", pos.x, pos.y, pos.z));
220 //@@ mprintf((0, "\n"));
222 //@@ fscanf(LoadFile, "%x %x %x", &mat[0], &mat[1], &mat[2]);
223 //@@ mprintf((0, "%8x %8x %8x\n", mat[0], mat[1], mat[2]));
225 //@@ fscanf(LoadFile, "%x %x %x", &mat[3], &mat[4], &mat[5]);
226 //@@ mprintf((0, "%8x %8x %8x\n", mat[3], mat[4], mat[5]));
228 //@@ fscanf(LoadFile, "%x %x %x", &mat[6], &mat[7], &mat[8]);
229 //@@ mprintf((0, "%8x %8x %8x\n", mat[6], mat[7], mat[8]));
230 //@@ mprintf((0, "\n"));
232 //@@ fscanf(LoadFile, "%i\n", &ConsoleObject->segnum);
234 //@@ cfclose( LoadFile );
236 //@@ ConsoleObject->pos = pos;
237 //@@ ConsoleObject->orient.m1 = mat[0]; ConsoleObject->orient.m2 = mat[1]; ConsoleObject->orient.m3 = mat[2];
238 //@@ ConsoleObject->orient.m4 = mat[3]; ConsoleObject->orient.m5 = mat[4]; ConsoleObject->orient.m6 = mat[5];
239 //@@ ConsoleObject->orient.m7 = mat[6]; ConsoleObject->orient.m8 = mat[7]; ConsoleObject->orient.m9 = mat[8];
244 // -----------------------------------------------------------------------------
245 int med_save_situation(char * filename)
248 char mine_name[MAX_NAME_LENGTH];
250 SaveFile = cfopen( filename, "wt" );
252 char ErrorMessage[200];
254 sprintf( ErrorMessage, "ERROR: Unable to open %s\n", filename );
255 MessageBox( -2, -2, 1, ErrorMessage, "Ok" );
260 // strcpy(mine_name, filename);
262 _splitpath(filename,NULL,NULL,mine_name,NULL);
264 set_extension(mine_name, "min");
265 fprintf(SaveFile, "%s\n", mine_name);
267 // Write player position.
268 fprintf(SaveFile, "%x %x %x\n",(unsigned int) ConsoleObject->pos.x,(unsigned int) ConsoleObject->pos.y,(unsigned int) ConsoleObject->pos.z);
270 // Write player orientation.
271 fprintf(SaveFile, "%8x %8x %8x\n",(unsigned int) ConsoleObject->orient.rvec.x,(unsigned int) ConsoleObject->orient.rvec.y,(unsigned int) ConsoleObject->orient.rvec.z);
272 fprintf(SaveFile, "%8x %8x %8x\n",(unsigned int) ConsoleObject->orient.uvec.x,(unsigned int) ConsoleObject->orient.uvec.y,(unsigned int) ConsoleObject->orient.uvec.z);
273 fprintf(SaveFile, "%8x %8x %8x\n",(unsigned int) ConsoleObject->orient.fvec.x,(unsigned int) ConsoleObject->orient.fvec.y,(unsigned int) ConsoleObject->orient.fvec.z);
274 fprintf(SaveFile, "%i\n", ConsoleObject->segnum);
276 mprintf((0, "Save Position = %8x %8x %8x\n", ConsoleObject->pos.x, ConsoleObject->pos.y, ConsoleObject->pos.z));
279 mprintf((0, "%8x %8x %8x\n", ConsoleObject->orient.rvec.x, ConsoleObject->orient.rvec.y, ConsoleObject->orient.rvec.z));
280 mprintf((0, "%8x %8x %8x\n", ConsoleObject->orient.uvec.x, ConsoleObject->orient.uvec.y, ConsoleObject->orient.uvec.z));
281 mprintf((0, "%8x %8x %8x\n", ConsoleObject->orient.fvec.x, ConsoleObject->orient.fvec.y, ConsoleObject->orient.fvec.z));
289 // -----------------------------------------------------------------------------
290 int SaveSituation(void)
292 if (ui_get_filename( sit_filename, "*.SIT", "Save Situation" )) {
293 set_extension(sit_filename, "MIN");
294 if (med_save_mine(sit_filename)) {
295 mprintf((0, "Unable to save mine in SaveSituation.\n"));
299 set_extension(sit_filename, "SIT");
300 if (med_save_situation(sit_filename))
307 // -----------------------------------------------------------------------------
308 // Load a situation file which consists of x,y,z, orientation matrix, mine name.
309 int LoadSituation(void)
312 if (ui_get_filename( sit_filename, "*.sit", "Load Situation" )) {
313 checkforext(sit_filename, "SIT");
314 if (med_load_situation(sit_filename))
316 // set_view_target_from_segment(Cursegp);
317 Update_flags = UF_WORLD_CHANGED;
318 // SetPlayerFromCurseg();