Ejemplo n.º 1
0
void overview_swap_levels(Overview * self, int level1, int level2) {
    if (! level1 || ! level2) {
#line 167
        return ;
    }
    if (level1 == level2) {
#line 169
        return ;
    }
    // 2 -> 0
#line 173
    game->level = level2;
    load_level(1);
    game->level = 0;
    save_level(1);
    self->screenshot [0] = self->screenshot [level2];
    // 1 -> 2
#line 180
    game->level = level1;
    load_level(1);
    game->level = level2;
    save_level(1);
    self->screenshot [level2] = self->screenshot [level1];
    // 0 -> 1
#line 187
    game->level = 0;
    load_level(1);
    game->level = level1;
    save_level(1);
    self->screenshot [level1] = self->screenshot [0];
}
Ejemplo n.º 2
0
bool save_game(char *filename)
{
        char cmd[260];
        int i;
        FILE *f;
        struct savefile_header header;
        //int i;
        monster_t *m;
        obj_t *o;

        gtprintf("Saving game to file %s", filename);
        f = fopen(filename, "w");

        header.magic = GT_SAVEFILE_MAGIC;
        header.version.major = GT_VERSION_MAJ;
        header.version.minor = GT_VERSION_MIN;
        header.version.revision = GT_VERSION_REV;

        fwrite(&header, sizeof(struct savefile_header), 1, f);
        fwrite(&gtconfig, sizeof(gt_config_t), 1, f);
        fwrite(game, sizeof(game_t), 1, f);

        /* then, let's save the player */
        save_player(player, f);

        m = monsterdefs->head;
        for(i=0; i <= game->monsterdefs; i++) {
                if(m)
                        save_monsterdef(m, f);
                m = m->next;
        }

        o = objdefs->head;
        for(i=0; i <= game->objdefs; i++) {
                if(o)
                        save_objdef(o, f);
                o = o->next;
        }

        /* then, let's save world and levels */
        save_level(world->dng, f);

        for(i=1; i<=game->createddungeons; i++)
                save_level(&world->dng[i], f);

        /* finally, the eventlist */
        save_eventlist(f);

        fclose(f);

        if(gtconfig.compress_savefile) {
                sprintf(cmd, "xz %s", filename);
                system(cmd);
        }

        gtprintf("Saving successful!");
        return true;
}
Ejemplo n.º 3
0
int	GotoGameScreen()
{
	stop_time();

//@@	init_player_stats();
//@@
//@@	Player_init.pos = Player->pos;
//@@	Player_init.orient = Player->orient;
//@@	Player_init.segnum = Player->segnum;	
	
// -- must always save gamesave.sav because the restore-objects code relies on it
// -- that code could be made smarter and use the original file, if appropriate.
//	if (mine_changed) 
	if (gamestate_not_restored == 0) {
		gamestate_not_restored = 1;
		save_level("GAMESAVE.LVL");
		editor_status("Gamestate saved.\n");
	}

	ai_reset_all_paths();

	start_time();

	ModeFlag = 3;
	return 1;
}
Ejemplo n.º 4
0
Archivo: med.c Proyecto: paud/d2x-xl
int	GotoGameCommon(int mode) {
	StopTime();

//@@	init_player_stats();
//@@
//@@	gameData.multi.playerInit.pos = Player->pos;
//@@	gameData.multi.playerInit.orient = Player->orient;
//@@	gameData.multi.playerInit.segnum = Player->segnum;	
	
// -- must always save gamesave.sav because the restore-gameData.objs.objects code relies on it
// -- that code could be made smarter and use the original file, if appropriate.
//	if (mine_changed) 
	if (gamestate_not_restored == 0) {
		gamestate_not_restored = 1;
		save_level("GAMESAVE.LVL");
		editor_status("Gamestate saved.\n");
	}

	ai_reset_all_paths();

	StartTime();

	ModeFlag = mode;
	return 1;
}
Ejemplo n.º 5
0
//  ---------- Create a bridge segment between current segment:side adjacent segment:side ----------
int CreateSloppyAdjacentJoint()
{
    int		adj_side;
    segment	*adj_sp;

    save_level("SLOPPY.LVL");

    if (med_find_closest_threshold_segment_side(Cursegp, Curside, &adj_sp, &adj_side, 20*F1_0)) {
        if (Cursegp->children[Curside] != adj_sp-Segments) {
            if (!med_form_joint(Cursegp,Curside,adj_sp,adj_side))
            {
                Update_flags |= UF_WORLD_CHANGED;
                mine_changed = 1;
                autosave_mine(mine_filename);
                diagnostic_message("Sloppy Joint segment formed.");
                strcpy(undo_status[Autosave_count], "Sloppy Joint segment undone.");
                warn_if_concave_segments();
            }
            else editor_status("Couldn't form sloppy joint.\n");
        } else
            editor_status("Attempted to form sloppy joint through connected side -- joint segment not formed (you bozo).");
    } else
        editor_status("Could not find close threshold segment -- joint segment not formed.");

    return 1;
}
Ejemplo n.º 6
0
// Save game
// returns 1 if successful
//	returns 0 if unsuccessful
int SaveGameData()
{
	char Message[200];

	if (gamestate_not_restored) {
		sprintf( Message, "Game State has not been restored...\nContinue?\n");
		if (MessageBox( -2, -2, 2, Message, "NO", "Yes" )==1) 
			return 0;
		}
		
   if (ui_get_filename( game_filename, "*.LVL", "SAVE GAME" )) {
		int saved_flag;
		vms_vector save_pos = ConsoleObject->pos;
		vms_matrix save_orient = ConsoleObject->orient;
		int save_segnum = ConsoleObject->segnum;

      checkforgamext(game_filename);

		if (Perm_player_segnum > Highest_segment_index)
			Perm_player_segnum = -1;

		if (Perm_player_segnum!=-1) {
			if (get_seg_masks(&Perm_player_position,Perm_player_segnum,0).centermask==0) {
				ConsoleObject->pos = Perm_player_position;
				obj_relink(ConsoleObject-Objects,Perm_player_segnum);
				ConsoleObject->orient = Perm_player_orient;
			}
			else
				Perm_player_segnum=-1;		//position was bogus
		}
      saved_flag=save_level(game_filename);
		if (Perm_player_segnum!=-1) {
			int	found_save_segnum;

			if (save_segnum > Highest_segment_index)
				save_segnum = 0;

			ConsoleObject->pos = save_pos;
			found_save_segnum = find_point_seg(&save_pos,save_segnum);
			if (found_save_segnum == -1) {
				compute_segment_center(&save_pos, &(Segments[save_segnum]));
				found_save_segnum = save_segnum;
			}

			obj_relink(ConsoleObject-Objects,found_save_segnum);
			ConsoleObject->orient = save_orient;
		}
		if (saved_flag)
			return 0;
		mine_changed = 0;
	}
	return 1;
}
Ejemplo n.º 7
0
void
EditorLevel::save_level(const std::string& filename)
{
  // Create new file (overwrite existing file)
  std::ostringstream out_file;

  Writer fw(out_file);
  save_level(fw);

  // Write the file
  System::write_file(filename, out_file.str());
}
Ejemplo n.º 8
0
Archivo: sat.c Proyecto: Meijuh/ltsmin
void
reach_sat_fix(reach_proc_t reach_proc, vset_t visited,
              bitvector_t *reach_groups, long *eg_count, long *next_count, long *guard_count)
{
    (void) reach_proc;
    (void) guard_count;

    if (PINS_USE_GUARDS)
        Abort("guard-splitting not supported with saturation=sat-fix");

    int level = 0;
    vset_t old_vis = vset_create(domain, -1, NULL);
    vset_t deadlocks = dlk_detect?vset_create(domain, -1, NULL):NULL;
    vset_t dlk_temp = dlk_detect?vset_create(domain, -1, NULL):NULL;

    LACE_ME;
    while (!vset_equal(visited, old_vis)) {
        if (trc_output != NULL) save_level(visited);
        vset_copy(old_vis, visited);
        stats_and_progress_report(NULL, visited, level);
        level++;
        for(int i = 0; i < nGrps; i++){
            if (!bitvector_is_set(reach_groups, i)) continue;
            expand_group_next(i, visited);
            reach_chain_stop();
            (*eg_count)++;
        }
        if (dlk_detect) vset_copy(deadlocks, visited);
        if (USE_PARALLELISM) vset_least_fixpoint_par(visited, visited, group_next, nGrps);
        else vset_least_fixpoint(visited, visited, group_next, nGrps);
        (*next_count)++;
        check_invariants(visited, level);
        if (dlk_detect) {
            for (int i = 0; i < nGrps; i++) {
                vset_prev(dlk_temp, visited, group_next[i],deadlocks);
                reduce(i, dlk_temp);
                vset_minus(deadlocks, dlk_temp);
                vset_clear(dlk_temp);
            }
            deadlock_check(deadlocks, reach_groups);
        }
        vset_reorder(domain);
    }

    vset_destroy(old_vis);
    if (dlk_detect) {
        vset_destroy(deadlocks);
        vset_destroy(dlk_temp);
    }
}
Ejemplo n.º 9
0
Archivo: sat.c Proyecto: Meijuh/ltsmin
void
reach_sat(reach_proc_t reach_proc, vset_t visited,
          bitvector_t *reach_groups, long *eg_count, long *next_count, long *guard_count)
{
    (void) reach_proc;
    (void) next_count;
    (void) guard_count;

    if (PINS_USE_GUARDS)
        Abort("guard-splitting not supported with saturation=sat");

    if (act_detect != NULL && trc_output != NULL)
        Abort("Action detection with trace generation not supported");

    for (int i = 0; i < nGrps; i++) {
        if (bitvector_is_set(reach_groups, i)) {
            struct expand_info *ctx = RTmalloc(sizeof(struct expand_info));
            ctx->group = i;
            ctx->group_explored = group_explored[i];
            ctx->eg_count = eg_count;

            vrel_set_expand(group_next[i], expand_group_next_projected, ctx);
        }
    }

    if (trc_output != NULL) save_level(visited);
    stats_and_progress_report(NULL, visited, 0);
    if (USE_PARALLELISM) vset_least_fixpoint_par(visited, visited, group_next, nGrps);
    else vset_least_fixpoint(visited, visited, group_next, nGrps);
    stats_and_progress_report(NULL, visited, 1);

    check_invariants(visited, -1);

    if (dlk_detect) {
        vset_t deadlocks = vset_create(domain, -1, NULL);
        vset_t dlk_temp = vset_create(domain, -1, NULL);
        vset_copy(deadlocks, visited);
        for (int i = 0; i < nGrps; i++) {
            vset_prev(dlk_temp, visited, group_next[i],deadlocks);
            reduce(i, dlk_temp);
            vset_minus(deadlocks, dlk_temp);
            vset_clear(dlk_temp);
        }
        deadlock_check(deadlocks, reach_groups);
        vset_destroy(deadlocks);
        vset_destroy(dlk_temp);
    }
}
Ejemplo n.º 10
0
void file_warning(void)
{
halfword p= save_ptr;
int l= cur_level;
int c= cur_group;
int i;
save_ptr= cur_boundary;
while(grp_stack[in_open]!=save_ptr){
decr(cur_level);
tprint_nl("Warning: end of file when ");
print_group(true);
tprint(" is incomplete");
cur_group= save_level(save_ptr);
save_ptr= save_value(save_ptr);
}
save_ptr= p;
cur_level= (quarterword)l;
cur_group= (group_code)c;
p= cond_ptr;
l= if_limit;
c= cur_if;
i= if_line;
while(if_stack[in_open]!=cond_ptr){
tprint_nl("Warning: end of file when ");
print_cmd_chr(if_test_cmd,cur_if);
if(if_limit==fi_code)
tprint_esc("else");
print_if_line(if_line);
tprint(" is incomplete");
if_line= if_line_field(cond_ptr);
cur_if= if_limit_subtype(cond_ptr);
if_limit= if_limit_type(cond_ptr);
cond_ptr= vlink(cond_ptr);
}
cond_ptr= p;
if_limit= l;
cur_if= c;
if_line= i;
print_ln();
if(tracing_nesting_par> 1)
show_context();
if(history==spotless)
history= warning_issued;
}
Ejemplo n.º 11
0
//loads a level (.LVL) file from disk
//returns 0 if success, else error code
int load_level(const char * filename_passed)
{
#ifdef EDITOR
	int use_compiled_level=1;
#endif
	PHYSFS_file * LoadFile;
	char filename[PATH_MAX];
	int sig, minedata_offset, gamedata_offset, hostagetext_offset;
	int mine_err, game_err;
#ifdef NETWORK
	int i;
#endif

#ifdef NETWORK
   if (Game_mode & GM_NETWORK)
	 {
	  for (i=0;i<MAX_POWERUP_TYPES;i++)
		{
			MaxPowerupsAllowed[i]=0;
			PowerupsInMine[i]=0;
		}
	 }
#endif

	#ifdef COMPACT_SEGS
	ncache_flush();
	#endif

	#ifndef RELEASE
	Level_being_loaded = filename_passed;
	#endif

	strcpy(filename,filename_passed);

#ifdef EDITOR
	//if we have the editor, try the LVL first, no matter what was passed.
	//if we don't have an LVL, try what was passed or SDL/RDL  
	//if we don't have the editor, we just use what was passed

	change_filename_extension(filename,filename_passed,".lvl");
	use_compiled_level = 0;

	if (!PHYSFSX_exists(filename,1))
	{
		char *p = strrchr(filename_passed, '.');

		if (d_stricmp(p, ".lvl"))
			strcpy(filename, filename_passed);	// set to what was passed
		else
			change_filename_extension(filename, filename, ".rdl");
		use_compiled_level = 1;
	}		
#endif

	if (!PHYSFSX_exists(filename,1))
		sprintf(filename,"%s%s",MISSION_DIR,filename_passed);

	LoadFile = PHYSFSX_openReadBuffered( filename );

	if (!LoadFile)	{
		#ifdef EDITOR
			return 1;
		#else
			Error("Can't open file <%s>\n",filename);
		#endif
	}

	strcpy( Gamesave_current_filename, filename );

	sig                      = PHYSFSX_readInt(LoadFile);
	Gamesave_current_version = PHYSFSX_readInt(LoadFile);
	minedata_offset          = PHYSFSX_readInt(LoadFile);
	gamedata_offset          = PHYSFSX_readInt(LoadFile);

	Assert(sig == MAKE_SIG('P','L','V','L'));
	(void)sig;

	if (Gamesave_current_version < 5)
		hostagetext_offset = PHYSFSX_readInt(LoadFile);

	PHYSFSX_fseek(LoadFile,minedata_offset,SEEK_SET);
	#ifdef EDITOR
	if (!use_compiled_level)
		mine_err = load_mine_data(LoadFile);
	else
	#endif
		//NOTE LINK TO ABOVE!!
		mine_err = load_mine_data_compiled(LoadFile);

	/* !!!HACK!!!
	 * Descent 1 - Level 19: OBERON MINE has some ugly overlapping rooms (segment 484).
	 * HACK to make this issue less visible by moving one vertex a little.
	 */
	if (Current_mission && !d_stricmp("Descent: First Strike",Current_mission_longname) && !d_stricmp("level19.rdl",filename) && PHYSFS_fileLength(LoadFile) == 136706)
		Vertices[1905].z =-385*F1_0;

	if (mine_err == -1) {   //error!!
		PHYSFS_close(LoadFile);
		return 2;
	}

	PHYSFSX_fseek(LoadFile,gamedata_offset,SEEK_SET);
	game_err = load_game_data(LoadFile);

	if (game_err == -1) {   //error!!
		PHYSFS_close(LoadFile);
		return 3;
	}

	(void)hostagetext_offset;

	//======================== CLOSE FILE =============================

	PHYSFS_close( LoadFile );

	#if 0	//def EDITOR
	#ifndef RELEASE
	write_game_text_file(filename);
	if (Errors_in_mine) {
		if (is_real_level(filename)) {
			char  ErrorMessage[200];

			sprintf( ErrorMessage, "Warning: %i errors in %s!\n", Errors_in_mine, Level_being_loaded );
			stop_time();
			gr_palette_load(gr_palette);
			nm_messagebox( NULL, 1, "Continue", ErrorMessage );
			start_time();
		}
	}
	#endif
	#endif

	#ifdef EDITOR
	//If an old version, ask the use if he wants to save as new version
	if (((LEVEL_FILE_VERSION>1) && Gamesave_current_version<LEVEL_FILE_VERSION) || mine_err==1 || game_err==1) {
		char  ErrorMessage[200];

		sprintf( ErrorMessage, "You just loaded a old version level.  Would\n"
						"you like to save it as a current version level?");

		gr_palette_load(gr_palette);
		if (nm_messagebox( NULL, 2, "Don't Save", "Save", ErrorMessage )==1)
			save_level(filename);
	}
	#endif

	#ifdef EDITOR
	if (EditorWindow)
		editor_status_fmt("Loaded NEW mine %s, \"%s\"",filename,Current_level_name);
	#endif

	#if !defined(NDEBUG) && !defined(COMPACT_SEGS)
	if (check_segment_connections())
		nm_messagebox( "ERROR", 1, "Ok", 
				"Connectivity errors detected in\n"
				"mine.  See monochrome screen for\n"
				"details, and contact Matt or Mike." );
	#endif

	return 0;
}
Ejemplo n.º 12
0
void runner_update(LandRunner * self) {
    All * a = global_a;
#line 234
    update();
#line 236
    if (land_closebutton()) {
        save_level(0);
        land_quit();
    }
    if (land_switched_out()) {
        save_level(0);
    }
    if (land_was_halted()) {
#line 243
        ;
    }
#line 246
    if (! land_keybuffer_empty()) {
        int k, u;
        land_keybuffer_next(& k, & u);
        cheat(u);
#line 251
        if (k == LandKeyEscape) {
            save_level(0);
            land_quit();
        }
#line 254
        else if (k == LandKeyFunction + 1) {
            a->show_fps = ! a->show_fps;
        }
#line 255
        else {
#line 257
            if (a->text_input) {
                if (u == '|') {
                    u = '\n';
                }
#line 260
                if (u == 13) {
                    u = 0;
                }
#line 262
                if (a->text_input == 1) {
                    game->title [a->cursor++] = u;
                }
#line 264
                else if (a->text_input == 2) {
                    game->hint [a->cursor++] = u;
                }
#line 266
                if (u == 0) {
                    a->text_input = 0;
                }
            }
#line 268
            else if (! a->title) {
                if (a->editor_enabled) {
                    game_key(game, k);
                }
            }
        }
    }
}
Ejemplo n.º 13
0
void main_switch_to_title(int com) {
    All * a = global_a;
    a->title = 1;
    save_level(0);
    title_com(com);
}
Ejemplo n.º 14
0
Archivo: save.cpp Proyecto: kekimmo/tuk
void save (FILE* file, const SaveState& state) {
  fprintf(file, "Version: %d\n", STATE_VERSION);
  save_level(file, state.level);
  save_actors(file, state.actors);
  save_tasks(file, state.tasks);
}