Make state.c more similar between D1X and D2X
This commit is contained in:
parent
d7e33667bf
commit
90c02b1ea3
|
@ -1,5 +1,9 @@
|
||||||
D1X-Rebirth Changelog
|
D1X-Rebirth Changelog
|
||||||
|
|
||||||
|
20090822
|
||||||
|
--------
|
||||||
|
main/ai.h, main/state.c: Make state.c more similar between D1X and D2X
|
||||||
|
|
||||||
20090810
|
20090810
|
||||||
--------
|
--------
|
||||||
arch/sdl/window.c, main/automap.c, main/game.c, main/inferno.c, main/multi.c: Make the game screen into a 'window', handling events through event_process
|
arch/sdl/window.c, main/automap.c, main/game.c, main/inferno.c, main/multi.c: Make the game screen into a 'window', handling events through event_process
|
||||||
|
|
|
@ -96,4 +96,7 @@ extern void ai_init_boss_for_ship(void);
|
||||||
extern int Boss_been_hit;
|
extern int Boss_been_hit;
|
||||||
extern fix AI_proc_time;
|
extern fix AI_proc_time;
|
||||||
|
|
||||||
|
extern int ai_save_state(PHYSFS_file * fp);
|
||||||
|
extern int ai_restore_state(PHYSFS_file *fp, int version);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
79
main/state.c
79
main/state.c
|
@ -17,12 +17,12 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "pstypes.h"
|
||||||
#include "inferno.h"
|
#include "inferno.h"
|
||||||
#include "segment.h"
|
#include "segment.h"
|
||||||
#include "textures.h"
|
#include "textures.h"
|
||||||
|
@ -30,6 +30,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
#include "gamemine.h"
|
#include "gamemine.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
#include "gamefont.h"
|
||||||
#include "gameseg.h"
|
#include "gameseg.h"
|
||||||
#include "switch.h"
|
#include "switch.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
@ -56,13 +57,11 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
||||||
#include "pcx.h"
|
#include "pcx.h"
|
||||||
#include "u_mem.h"
|
#include "u_mem.h"
|
||||||
#include "args.h"
|
#include "args.h"
|
||||||
//added 6/15/99 - Owen Evans
|
#include "ai.h"
|
||||||
#include "strutil.h"
|
#include "state.h"
|
||||||
//end added
|
|
||||||
#include "gamefont.h"
|
|
||||||
#include "multi.h"
|
#include "multi.h"
|
||||||
#ifdef OGL
|
#ifdef OGL
|
||||||
#include "ogl_init.h"
|
#include "gr.h"
|
||||||
#endif
|
#endif
|
||||||
#include "physfsx.h"
|
#include "physfsx.h"
|
||||||
|
|
||||||
|
@ -83,9 +82,6 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
||||||
#define THUMBNAIL_H 50
|
#define THUMBNAIL_H 50
|
||||||
#define DESC_LENGTH 20
|
#define DESC_LENGTH 20
|
||||||
|
|
||||||
extern int ai_save_state( PHYSFS_file * fp );
|
|
||||||
extern int ai_restore_state( PHYSFS_file * fp );
|
|
||||||
|
|
||||||
extern int Do_appearance_effect;
|
extern int Do_appearance_effect;
|
||||||
extern fix Fusion_next_sound_time;
|
extern fix Fusion_next_sound_time;
|
||||||
|
|
||||||
|
@ -105,6 +101,7 @@ char dgss_id[4] = "DGSS";
|
||||||
|
|
||||||
uint state_game_id;
|
uint state_game_id;
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
void state_callback(int nitems,newmenu_item * items, int * last_key, int citem)
|
void state_callback(int nitems,newmenu_item * items, int * last_key, int citem)
|
||||||
{
|
{
|
||||||
nitems = nitems;
|
nitems = nitems;
|
||||||
|
@ -216,7 +213,7 @@ int state_get_savegame_filename(char * fname, char * dsc, char * caption )
|
||||||
}
|
}
|
||||||
|
|
||||||
if (choice > 0) {
|
if (choice > 0) {
|
||||||
sprintf( fname, filename[choice-1] );
|
strcpy( fname, filename[choice-1] );
|
||||||
if ( dsc != NULL ) strcpy( dsc, desc[choice-1] );
|
if ( dsc != NULL ) strcpy( dsc, desc[choice-1] );
|
||||||
state_default_item = choice - 1;
|
state_default_item = choice - 1;
|
||||||
return choice;
|
return choice;
|
||||||
|
@ -362,12 +359,13 @@ int state_save_old_game(int slotnum, char * sg_name, player * sg_player,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------
|
||||||
int state_save_all(int between_levels)
|
int state_save_all(int between_levels)
|
||||||
{
|
{
|
||||||
int rval;
|
int rval;
|
||||||
char filename[128], desc[DESC_LENGTH+1];
|
char filename[128], desc[DESC_LENGTH+1];
|
||||||
|
|
||||||
#ifndef SHAREWARE
|
#ifdef NETWORK
|
||||||
if ( Game_mode & GM_MULTI ) {
|
if ( Game_mode & GM_MULTI ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -398,8 +396,14 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
|
||||||
GLint gl_draw_buffer;
|
GLint gl_draw_buffer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
if (GameArg.SysUsePlayersDir && strncmp(filename, "Players/", 8))
|
||||||
|
Int3();
|
||||||
|
#endif
|
||||||
|
|
||||||
fp = PHYSFSX_openWriteBuffered(filename);
|
fp = PHYSFSX_openWriteBuffered(filename);
|
||||||
if ( !fp ) {
|
if ( !fp ) {
|
||||||
|
nm_messagebox(NULL, 1, TXT_OK, "Error writing savegame.\nPossibly out of disk\nspace.");
|
||||||
start_time();
|
start_time();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -415,6 +419,7 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
|
||||||
PHYSFS_write(fp, desc, sizeof(char) * DESC_LENGTH, 1);
|
PHYSFS_write(fp, desc, sizeof(char) * DESC_LENGTH, 1);
|
||||||
|
|
||||||
// Save the current screen shot...
|
// Save the current screen shot...
|
||||||
|
|
||||||
cnv = gr_create_canvas( THUMBNAIL_W, THUMBNAIL_H );
|
cnv = gr_create_canvas( THUMBNAIL_W, THUMBNAIL_H );
|
||||||
if ( cnv )
|
if ( cnv )
|
||||||
{
|
{
|
||||||
|
@ -429,7 +434,7 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
|
||||||
|
|
||||||
render_frame(0);
|
render_frame(0);
|
||||||
|
|
||||||
#ifdef OGL
|
#if defined(OGL)
|
||||||
buf = d_malloc(THUMBNAIL_W * THUMBNAIL_H * 3);
|
buf = d_malloc(THUMBNAIL_W * THUMBNAIL_H * 3);
|
||||||
glGetIntegerv(GL_DRAW_BUFFER, &gl_draw_buffer);
|
glGetIntegerv(GL_DRAW_BUFFER, &gl_draw_buffer);
|
||||||
glReadBuffer(gl_draw_buffer);
|
glReadBuffer(gl_draw_buffer);
|
||||||
|
@ -443,6 +448,7 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
|
||||||
}
|
}
|
||||||
d_free(buf);
|
d_free(buf);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pal = gr_palette;
|
pal = gr_palette;
|
||||||
|
|
||||||
PHYSFS_write(fp, cnv->cv_bitmap.bm_data, THUMBNAIL_W * THUMBNAIL_H, 1);
|
PHYSFS_write(fp, cnv->cv_bitmap.bm_data, THUMBNAIL_W * THUMBNAIL_H, 1);
|
||||||
|
@ -461,11 +467,7 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
|
||||||
PHYSFS_write(fp, &between_levels, sizeof(int), 1);
|
PHYSFS_write(fp, &between_levels, sizeof(int), 1);
|
||||||
|
|
||||||
// Save the mission info...
|
// Save the mission info...
|
||||||
#ifndef SHAREWARE
|
PHYSFS_write(fp, Current_mission_filename, 9 * sizeof(char), 1);
|
||||||
PHYSFS_write( fp, Current_mission_filename, sizeof(char)*9, 1 );
|
|
||||||
#else
|
|
||||||
PHYSFS_write( fp, "\0\0\0\0\0\0\0\0", sizeof(char)*9, 1 );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//Save level info
|
//Save level info
|
||||||
PHYSFS_write(fp, &Current_level_num, sizeof(int), 1);
|
PHYSFS_write(fp, &Current_level_num, sizeof(int), 1);
|
||||||
|
@ -484,11 +486,10 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
|
||||||
// Save the difficulty level
|
// Save the difficulty level
|
||||||
PHYSFS_write(fp, &Difficulty_level, sizeof(int), 1);
|
PHYSFS_write(fp, &Difficulty_level, sizeof(int), 1);
|
||||||
|
|
||||||
// Save the Cheats_enabled
|
// Save cheats enabled
|
||||||
PHYSFS_write(fp, &Cheats_enabled, sizeof(int), 1);
|
PHYSFS_write(fp, &Cheats_enabled, sizeof(int), 1);
|
||||||
PHYSFS_write(fp, &Game_turbo_mode, sizeof(int), 1);
|
PHYSFS_write(fp, &Game_turbo_mode, sizeof(int), 1);
|
||||||
|
|
||||||
|
|
||||||
if ( !between_levels ) {
|
if ( !between_levels ) {
|
||||||
|
|
||||||
//Finish all morph objects
|
//Finish all morph objects
|
||||||
|
@ -514,7 +515,7 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
|
||||||
//Save object info
|
//Save object info
|
||||||
i = Highest_object_index+1;
|
i = Highest_object_index+1;
|
||||||
PHYSFS_write(fp, &i, sizeof(int), 1);
|
PHYSFS_write(fp, &i, sizeof(int), 1);
|
||||||
PHYSFS_write( fp, Objects, sizeof(object)*i, 1 );
|
PHYSFS_write(fp, Objects, sizeof(object), i);
|
||||||
|
|
||||||
//Save wall info
|
//Save wall info
|
||||||
i = Num_walls;
|
i = Num_walls;
|
||||||
|
@ -531,8 +532,10 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
|
||||||
PHYSFS_write(fp, Triggers, sizeof(trigger), Num_triggers);
|
PHYSFS_write(fp, Triggers, sizeof(trigger), Num_triggers);
|
||||||
|
|
||||||
//Save tmap info
|
//Save tmap info
|
||||||
for (i=0; i<=Highest_segment_index; i++ ) {
|
for (i = 0; i <= Highest_segment_index; i++)
|
||||||
for (j=0; j<6; j++ ) {
|
{
|
||||||
|
for (j = 0; j < 6; j++)
|
||||||
|
{
|
||||||
PHYSFS_write(fp, &Segments[i].sides[j].wall_num, sizeof(short), 1);
|
PHYSFS_write(fp, &Segments[i].sides[j].wall_num, sizeof(short), 1);
|
||||||
PHYSFS_write(fp, &Segments[i].sides[j].tmap_num, sizeof(short), 1);
|
PHYSFS_write(fp, &Segments[i].sides[j].tmap_num, sizeof(short), 1);
|
||||||
PHYSFS_write(fp, &Segments[i].sides[j].tmap_num2, sizeof(short), 1);
|
PHYSFS_write(fp, &Segments[i].sides[j].tmap_num2, sizeof(short), 1);
|
||||||
|
@ -559,7 +562,8 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
|
||||||
ai_save_state( fp );
|
ai_save_state( fp );
|
||||||
|
|
||||||
// Save the automap visited info
|
// Save the automap visited info
|
||||||
PHYSFS_write( fp, Automap_visited, sizeof(ubyte)*MAX_SEGMENTS, 1 );
|
PHYSFS_write(fp, Automap_visited, sizeof(ubyte), MAX_SEGMENTS);
|
||||||
|
|
||||||
}
|
}
|
||||||
PHYSFS_write(fp, &state_game_id, sizeof(uint), 1);
|
PHYSFS_write(fp, &state_game_id, sizeof(uint), 1);
|
||||||
PHYSFS_write(fp, &Laser_rapid_fire, sizeof(int), 1);
|
PHYSFS_write(fp, &Laser_rapid_fire, sizeof(int), 1);
|
||||||
|
@ -575,11 +579,12 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------
|
||||||
int state_restore_all(int in_game)
|
int state_restore_all(int in_game)
|
||||||
{
|
{
|
||||||
char filename[128];
|
char filename[128];
|
||||||
|
|
||||||
#ifndef SHAREWARE
|
#ifdef NETWORK
|
||||||
if ( Game_mode & GM_MULTI ) {
|
if ( Game_mode & GM_MULTI ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -625,10 +630,16 @@ int state_restore_all_sub(char *filename)
|
||||||
char id[5];
|
char id[5];
|
||||||
char org_callsign[CALLSIGN_LEN+16];
|
char org_callsign[CALLSIGN_LEN+16];
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
if (GameArg.SysUsePlayersDir && strncmp(filename, "Players/", 8))
|
||||||
|
Int3();
|
||||||
|
#endif
|
||||||
|
|
||||||
fp = PHYSFSX_openReadBuffered(filename);
|
fp = PHYSFSX_openReadBuffered(filename);
|
||||||
if ( !fp ) return 0;
|
if ( !fp ) return 0;
|
||||||
|
|
||||||
//Read id
|
//Read id
|
||||||
|
//FIXME: check for swapped file, react accordingly...
|
||||||
PHYSFS_read(fp, id, sizeof(char) * 4, 1);
|
PHYSFS_read(fp, id, sizeof(char) * 4, 1);
|
||||||
if ( memcmp( id, dgss_id, 4 )) {
|
if ( memcmp( id, dgss_id, 4 )) {
|
||||||
PHYSFS_close(fp);
|
PHYSFS_close(fp);
|
||||||
|
@ -654,32 +665,15 @@ int state_restore_all_sub(char *filename)
|
||||||
// Read the mission info...
|
// Read the mission info...
|
||||||
PHYSFS_read(fp, mission, sizeof(char) * 9, 1);
|
PHYSFS_read(fp, mission, sizeof(char) * 9, 1);
|
||||||
|
|
||||||
#ifndef SHAREWARE
|
|
||||||
if (!load_mission_by_name( mission )) {
|
if (!load_mission_by_name( mission )) {
|
||||||
nm_messagebox( NULL, 1, "Ok", "Error!\nUnable to load mission\n'%s'\n", mission );
|
nm_messagebox( NULL, 1, "Ok", "Error!\nUnable to load mission\n'%s'\n", mission );
|
||||||
PHYSFS_close(fp);
|
PHYSFS_close(fp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
if (mission[0]) {
|
|
||||||
nm_messagebox( NULL, 1, "Ok", "Error!\nCannot load mission '%s'\nThe shareware version only supports savegames of the shareware mission!", mission );
|
|
||||||
PHYSFS_close(fp);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//Read level info
|
//Read level info
|
||||||
PHYSFS_read(fp, ¤t_level, sizeof(int), 1);
|
PHYSFS_read(fp, ¤t_level, sizeof(int), 1);
|
||||||
PHYSFS_read(fp, &next_level, sizeof(int), 1);
|
PHYSFS_read(fp, &next_level, sizeof(int), 1);
|
||||||
#ifdef SHAREWARE
|
|
||||||
if (current_level < 1 || current_level > Last_level ||
|
|
||||||
next_level < 0 || next_level > Last_level) {
|
|
||||||
nm_messagebox( NULL, 1, "Ok", "Error!\nCannot load level %d\nThe shareware version only supports savegames of shareware levels!",
|
|
||||||
between_levels? next_level:current_level);
|
|
||||||
PHYSFS_close(fp);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//Restore GameTime
|
//Restore GameTime
|
||||||
PHYSFS_read(fp, &GameTime, sizeof(fix), 1);
|
PHYSFS_read(fp, &GameTime, sizeof(fix), 1);
|
||||||
|
@ -727,6 +721,7 @@ int state_restore_all_sub(char *filename)
|
||||||
PHYSFS_read(fp, &Difficulty_level, sizeof(int), 1);
|
PHYSFS_read(fp, &Difficulty_level, sizeof(int), 1);
|
||||||
|
|
||||||
// Restore the cheats enabled flag
|
// Restore the cheats enabled flag
|
||||||
|
|
||||||
PHYSFS_read(fp, &Cheats_enabled, sizeof(int), 1);
|
PHYSFS_read(fp, &Cheats_enabled, sizeof(int), 1);
|
||||||
PHYSFS_read(fp, &Game_turbo_mode, sizeof(int), 1);
|
PHYSFS_read(fp, &Game_turbo_mode, sizeof(int), 1);
|
||||||
|
|
||||||
|
@ -867,7 +862,7 @@ RetryObjectLoading:
|
||||||
PHYSFS_close(fp);
|
PHYSFS_close(fp);
|
||||||
|
|
||||||
// Load in bitmaps, etc..
|
// Load in bitmaps, etc..
|
||||||
// piggy_load_level_data();//already used page_in_textures in StartNewLevelSub, so no need for this here. -MPM
|
//!! piggy_load_level_data(); //already done by StartNewLevelSub()
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue