2006-03-20 16:43:15 +00:00
|
|
|
/*
|
2014-06-01 17:55:23 +00:00
|
|
|
* Portions of this file are copyright Rebirth contributors and licensed as
|
|
|
|
* described in COPYING.txt.
|
|
|
|
* Portions of this file are copyright Parallax Software and licensed
|
|
|
|
* according to the Parallax license below.
|
|
|
|
* See COPYING.txt for license details.
|
|
|
|
|
2006-03-20 16:43:15 +00:00
|
|
|
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
|
|
|
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
|
|
|
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
|
|
|
|
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
|
|
|
|
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|
|
|
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
|
|
|
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
|
|
|
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
2010-12-24 04:26:24 +00:00
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
2006-03-20 16:43:15 +00:00
|
|
|
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
2008-04-06 20:23:28 +00:00
|
|
|
|
2006-03-20 16:43:15 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Functions to change entire mines.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2012-07-07 18:35:06 +00:00
|
|
|
#include "dxxerror.h"
|
2010-12-24 04:26:24 +00:00
|
|
|
#include "strutil.h"
|
2006-03-20 16:43:15 +00:00
|
|
|
#include "inferno.h"
|
|
|
|
#include "editor.h"
|
2013-03-16 03:10:55 +00:00
|
|
|
#include "editor/esegment.h"
|
2013-09-24 01:59:09 +00:00
|
|
|
#include "editor/medmisc.h"
|
2006-03-20 16:43:15 +00:00
|
|
|
#include "ui.h"
|
|
|
|
#include "texpage.h" // For texpage_goto_first
|
|
|
|
#include "segment.h"
|
|
|
|
#include "kdefs.h"
|
|
|
|
#include "info.h"
|
|
|
|
#include "game.h"
|
2014-07-20 01:09:55 +00:00
|
|
|
#include "physfsx.h"
|
2006-03-20 16:43:15 +00:00
|
|
|
#include "gameseq.h"
|
|
|
|
#include "object.h"
|
|
|
|
|
2010-12-24 04:26:24 +00:00
|
|
|
char mine_filename[PATH_MAX] = "*.MIN";
|
2013-11-28 00:24:06 +00:00
|
|
|
static char sit_filename[PATH_MAX] = "*.SIT";
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2010-12-24 04:26:24 +00:00
|
|
|
#define MAX_NAME_LENGTH PATH_MAX
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
// See if filename f contains an extent. If not, add extent ext.
|
2013-10-27 22:00:14 +00:00
|
|
|
static void checkforext( char * f, const char *ext )
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=1; i<MAX_NAME_LENGTH; i++ ) {
|
|
|
|
if (f[i]=='.')
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((f[i] == ' ') || (f[i]==0) ) {
|
|
|
|
f[i] = '.';
|
|
|
|
f[i+1] = ext[0];
|
|
|
|
f[i+2] = ext[1];
|
|
|
|
f[i+3] = ext[2];
|
|
|
|
f[i+4] = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < 123) {
|
|
|
|
f[i] = '.';
|
|
|
|
f[i+1] = ext[0];
|
|
|
|
f[i+2] = ext[1];
|
|
|
|
f[i+3] = ext[2];
|
|
|
|
f[i+4] = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if filename f contains an extent. If not, add extent ext.
|
2013-10-27 22:00:14 +00:00
|
|
|
static void set_extension( char * f, const char *ext )
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=1; i<MAX_NAME_LENGTH-4; i++ ) {
|
|
|
|
if ((f[i]=='.') || (f[i] == ' ') || (f[i]==0) ) {
|
|
|
|
f[i] = '.';
|
|
|
|
f[i+1] = ext[0];
|
|
|
|
f[i+2] = ext[1];
|
|
|
|
f[i+3] = ext[2];
|
|
|
|
f[i+4] = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int SaveMine()
|
|
|
|
{
|
|
|
|
// Save mine
|
|
|
|
// med_save_mine("TEMP.MIN");
|
|
|
|
if (ui_get_filename( mine_filename, "*.MIN", "SAVE MINE" ))
|
|
|
|
{
|
|
|
|
checkforext(mine_filename, "MIN");
|
|
|
|
if (med_save_mine(mine_filename))
|
|
|
|
return 0;
|
|
|
|
mine_changed = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CreateNewMine()
|
|
|
|
{
|
|
|
|
if (SafetyCheck()) {
|
|
|
|
texpage_goto_first();
|
|
|
|
create_new_mine();
|
|
|
|
LargeView.ev_matrix = vmd_identity_matrix; //FrontView.ev_matrix;
|
|
|
|
set_view_target_from_segment(Cursegp);
|
2015-01-12 00:26:02 +00:00
|
|
|
Seg_scale = {DEFAULT_X_SIZE, DEFAULT_Y_SIZE, DEFAULT_Z_SIZE};
|
2006-03-20 16:43:15 +00:00
|
|
|
Update_flags = UF_WORLD_CHANGED;
|
|
|
|
SetPlayerFromCurseg();
|
|
|
|
SetPlayerPosition(); //say default is permanant position
|
|
|
|
mine_changed = 0;
|
2013-12-11 23:59:36 +00:00
|
|
|
Found_segs.clear();
|
2013-12-11 23:59:36 +00:00
|
|
|
Selected_segs.clear();
|
2006-03-20 16:43:15 +00:00
|
|
|
med_compress_mine();
|
|
|
|
gamestate_not_restored = 0;
|
|
|
|
init_info = 1;
|
|
|
|
ResetFilename();
|
|
|
|
Game_mode = GM_UNKNOWN;
|
|
|
|
Current_level_num = 0; //0 means not a real game
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MineMenu()
|
|
|
|
{
|
|
|
|
int x;
|
2013-09-02 23:21:13 +00:00
|
|
|
static const char *const MenuItems[] = { "New mine",
|
2006-03-20 16:43:15 +00:00
|
|
|
"Load mine",
|
|
|
|
"Save mine",
|
|
|
|
"Print mine",
|
|
|
|
"Redraw mine" };
|
|
|
|
|
|
|
|
x = MenuX( -1, -1, 5, MenuItems );
|
|
|
|
|
|
|
|
switch( x )
|
|
|
|
{
|
|
|
|
case 1: // New
|
|
|
|
CreateNewMine();
|
|
|
|
break;
|
|
|
|
case 2: // Load
|
|
|
|
//@@LoadMine();
|
|
|
|
break;
|
|
|
|
case 3: // Save
|
|
|
|
SaveMine();
|
|
|
|
break;
|
|
|
|
case 4: // Print
|
|
|
|
break;
|
|
|
|
case 5: // Redraw
|
|
|
|
Update_flags = UF_ALL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// returns 1 if error, else 0
|
2013-10-27 22:00:14 +00:00
|
|
|
static int med_load_situation(char * filename)
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
|
|
|
if (filename[0] == 97)
|
|
|
|
Int3();
|
|
|
|
Int3();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2013-10-27 22:00:14 +00:00
|
|
|
static int med_save_situation(char * filename)
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
2015-01-17 18:31:42 +00:00
|
|
|
auto SaveFile = PHYSFSX_openWriteBuffered(filename);
|
2006-03-20 16:43:15 +00:00
|
|
|
if (!SaveFile) {
|
|
|
|
char ErrorMessage[200];
|
|
|
|
|
2016-01-09 16:38:16 +00:00
|
|
|
snprintf(ErrorMessage, sizeof(ErrorMessage), "ERROR: Unable to open %s\n", filename);
|
2012-04-17 08:02:32 +00:00
|
|
|
ui_messagebox( -2, -2, 1, ErrorMessage, "Ok" );
|
2006-03-20 16:43:15 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write mine name.
|
2013-06-09 18:10:09 +00:00
|
|
|
struct splitpath_t path;
|
|
|
|
d_splitpath(filename, &path);
|
2016-06-05 01:04:26 +00:00
|
|
|
PHYSFSX_printf(SaveFile, "%.*s.min\n", static_cast<int>(path.base_end - path.base_start), path.base_start);
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
// Write player position.
|
2010-08-19 13:32:33 +00:00
|
|
|
PHYSFSX_printf(SaveFile, "%x %x %x\n",(unsigned int) ConsoleObject->pos.x,(unsigned int) ConsoleObject->pos.y,(unsigned int) ConsoleObject->pos.z);
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
// Write player orientation.
|
2010-08-19 13:32:33 +00:00
|
|
|
PHYSFSX_printf(SaveFile, "%8x %8x %8x\n",(unsigned int) ConsoleObject->orient.rvec.x,(unsigned int) ConsoleObject->orient.rvec.y,(unsigned int) ConsoleObject->orient.rvec.z);
|
|
|
|
PHYSFSX_printf(SaveFile, "%8x %8x %8x\n",(unsigned int) ConsoleObject->orient.uvec.x,(unsigned int) ConsoleObject->orient.uvec.y,(unsigned int) ConsoleObject->orient.uvec.z);
|
|
|
|
PHYSFSX_printf(SaveFile, "%8x %8x %8x\n",(unsigned int) ConsoleObject->orient.fvec.x,(unsigned int) ConsoleObject->orient.fvec.y,(unsigned int) ConsoleObject->orient.fvec.z);
|
|
|
|
PHYSFSX_printf(SaveFile, "%i\n", ConsoleObject->segnum);
|
2006-03-20 16:43:15 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
int SaveSituation(void)
|
|
|
|
{
|
|
|
|
if (ui_get_filename( sit_filename, "*.SIT", "Save Situation" )) {
|
|
|
|
set_extension(sit_filename, "MIN");
|
|
|
|
if (med_save_mine(sit_filename)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_extension(sit_filename, "SIT");
|
|
|
|
if (med_save_situation(sit_filename))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Load a situation file which consists of x,y,z, orientation matrix, mine name.
|
|
|
|
int LoadSituation(void)
|
|
|
|
{
|
|
|
|
if (SafetyCheck()) {
|
|
|
|
if (ui_get_filename( sit_filename, "*.sit", "Load Situation" )) {
|
|
|
|
checkforext(sit_filename, "SIT");
|
|
|
|
if (med_load_situation(sit_filename))
|
|
|
|
return 0;
|
|
|
|
// set_view_target_from_segment(Cursegp);
|
|
|
|
Update_flags = UF_WORLD_CHANGED;
|
|
|
|
// SetPlayerFromCurseg();
|
|
|
|
med_compress_mine();
|
|
|
|
init_info = 1;
|
|
|
|
mine_changed = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|