Exemplo n.º 1
0
// returns 1 if save successful
bool dosave0 (bool failok)
{
    // Create the saved game directory first, if absent
    const char* homedir = getenv ("HOME");
    if (!homedir)
	return false;
    char savefile [PATH_MAX];
    snprintf (ArrayBlock(savefile), _PATH_SAVED_GAMES, homedir);
    if (0 != access (savefile, R_OK))
	mkpath (savefile, S_IRWXU);
    snprintf (ArrayBlock(savefile), HACK_SAVEFILE, homedir);

    int fd = creat (savefile, S_IRUSR| S_IWUSR);
    if (fd < 0) {
	if (failok)
	    pline("Cannot save game: %s (Continue or Quit)", strerror(errno));
	return false;
    }
    bwrite (fd, &_u, sizeof(struct you));
    saveobjchn (fd, invent);
    saveobjchn (fd, fcobj);
    savemonchn (fd, fallen_down);
    bwrite (fd, &_wflags, sizeof(struct worldflag));
    bwrite (fd, pl_character, sizeof pl_character);
    savenames (fd);
    savegenocided (fd);
    for (unsigned i = 0; i < _u.maxdlevel; ++i)
	savelev (fd, &_levels[i]);
    close (fd);
    return true;
}
Exemplo n.º 2
0
Arquivo: util.c Projeto: ifzz/casycom
void casycom_backtrace (void)
{
#if HAVE_EXECINFO_H
    void* frames [64];
    int nFrames = backtrace (ArrayBlock(frames));
    if (nFrames <= 1)
	return;	// Can happen if there is no debugging information
    char** syms = backtrace_symbols (frames, nFrames);
    if (!syms)
	return;
    for (int i = 1; i < nFrames; ++i)
	casycom_log (LOG_ERR, "\t%s\n", syms[i]);
    free (syms);
#endif
}
Exemplo n.º 3
0
static void initialize_windows (void)
{
    if (_wmsg)
	delwin (_wmsg);
    else {
	static const struct color_pair c_Pairs[] = {
	    { COLOR_WHITE,	COLOR_BLUE	},	// color_Panel
	    { COLOR_BLACK,	COLOR_WHITE	},	// color_CardBlack
	    { COLOR_RED,	COLOR_WHITE	}	// color_CardRed
	};
	init_pairs (ArrayBlock (c_Pairs));
    }
    _wmsg = newwin (LINES-PANEL_LINES, PANEL_COLS, 0, 0);
    scrollok (_wmsg, true);
    idlok (_wmsg, true);
    keypad (_wmsg, true);
    wmove (_wmsg, getmaxy(_wmsg)-1, 0);
    if (_wpanel)
	delwin (_wpanel);
    _wpanel = newwin (PANEL_LINES, PANEL_COLS, LINES-PANEL_LINES, 0);
    wbkgdset (_wpanel, COLOR_PAIR(color_Panel));
}
Exemplo n.º 4
0
bool dorecover (void)
{
    char savefile [PATH_MAX];
    snprintf (ArrayBlock(savefile), HACK_SAVEFILE, getenv("HOME"));
    int fd = open (savefile, O_RDONLY);
    if (fd < 0)
	return false;
    mread (fd, &_u, sizeof(struct you));
    if (_u.maxdlevel < 1 || _u.maxdlevel > MAXLEVEL) {
	close (fd);
	you_dtor();
	return false;
    }
    invent = restobjchn (fd);
    for (struct obj* o = invent; o; o = o->nobj)
	if (o->owornmask)
	    setworn (o, o->owornmask);
    fcobj = restobjchn (fd);
    fallen_down = restmonchn (fd);
    mread (fd, &_wflags, sizeof(struct worldflag));
    mread (fd, pl_character, sizeof pl_character);
    restnames (fd);
    restgenocided (fd);
    for (unsigned i = 0; i < _u.maxdlevel; ++i) {
	level_dtor (&_levels[i]);
	getlev (fd, &_levels[i]);
    }
    if (_u.dlevel < 1 || _u.dlevel > _u.maxdlevel)
	_u.dlevel = _u.maxdlevel;
    _level = &_levels[_u.dlevel-1];
    setsee();	// only to recompute seelx etc. - these weren't saved
    docrt();
    close (fd);
    unlink (savefile);
    return true;
}