Example #1
0
void startup_common(const char *name, int playmode)
{
    /* (re)init all global data */
    init_data();
    init_tutorial();
    init_timeout();
    init_shop_selection();
    reset_food(); /* zero out victual and tin */
    reset_steal();
    reset_dig_status();
    reset_encumber_msg();
    reset_occupations();

    /* create mutable copies of object and artifact liss */
    init_objlist();
    init_artilist();
    reset_rndmonst(NON_PM);
    free_dungeon(); /* clean up stray dungeon data */

    program_state.game_running = 0;
    initoptions();

    dlb_init();	/* must be before newgame() */

    /*
     * Initialization of the boundaries of the mazes
     * Both boundaries have to be even.
     */
    x_maze_max = COLNO-1;
    if (x_maze_max % 2)
	x_maze_max--;
    y_maze_max = ROWNO-1;
    if (y_maze_max % 2)
	y_maze_max--;

    /*
	*  Initialize the vision system.  This must be before mklev() on a
	*  new game or before a level restore on a saved game.
	*/
    vision_init();
    
    if (playmode == MODE_TUTORIAL)
	flags.tutorial = TRUE;
    if (playmode == MODE_EXPLORE)
	discover = TRUE;
    else if (playmode == MODE_WIZARD)
	wizard = TRUE;
    
    if (name && name[0]) {
	strncpy(plname, name, PL_NSIZ);
	plname[PL_NSIZ-1] = '\0';
    }

    if (wizard)
	strcpy(plname, "巫师");

    cls();

    initrack();
}
Example #2
0
struct nh_topten_entry *
nh_get_topten(int *out_len, char *statusbuf,
              const char * volatile player, int top,
              int around, boolean own)
{
    struct toptenentry *ttlist, newtt;
    struct nh_topten_entry *score_list;
    boolean game_inited = (wiz1_level.dlevel != 0);
    boolean game_complete = game_inited && moves && program_state.gameover;
    int rank = -1;      /* index of the completed game in the topten list */
    int fd, i, j, sel_count;
    boolean *selected, off_list = FALSE;

    statusbuf[0] = '\0';
    *out_len = 0;

    if (!api_entry_checkpoint())
        return NULL;

    if (!game_inited) {
        /* If nh_get_topten() isn't called after a game, we never went through
           initialization. */
        dlb_init();
        init_dungeons();
    }

    if (!player) {
        if (game_complete)
            player = plname;
        else
            player = "";
    }

    fd = open_datafile(RECORD, O_RDONLY, SCOREPREFIX);
    ttlist = read_topten(fd, TTLISTLEN);
    close(fd);
    if (!ttlist) {
        strcpy(statusbuf, "Cannot open record file!");
        api_exit();
        return NULL;
    }

    /* find the rank of a completed game in the score list */
    if (game_complete && !strcmp(player, plname)) {
        fill_topten_entry(&newtt, end_how);

        /* find this entry in the list */
        for (i = 0; i < TTLISTLEN && validentry(ttlist[i]); i++)
            if (!memcmp(&ttlist[i], &newtt, sizeof (struct toptenentry)))
                rank = i;

        if (wizard || discover)
            sprintf(statusbuf,
                    "Since you were in %s mode, your game was not "
                    "added to the score list.", wizard ? "wizard" : "discover");
        else if (rank >= 0 && rank < 10)
            sprintf(statusbuf, "You made the top ten list!");
        else if (rank)
            sprintf(statusbuf, "You reached the %d%s place on the score list.",
                    rank + 1, ordin(rank + 1));
    }

    /* select scores for display */
    sel_count = 0;
    selected = calloc(TTLISTLEN, sizeof (boolean));

    for (i = 0; i < TTLISTLEN && validentry(ttlist[i]); i++) {
        if (top == -1 || i < top)
            selected[i] = TRUE;

        if (own && !strcmp(player, ttlist[i].name))
            selected[i] = TRUE;

        if (rank != -1 && rank - around <= i && i <= rank + around)
            selected[i] = TRUE;

        if (selected[i])
            sel_count++;
    }

    if (game_complete && sel_count == 0) {
        /* didn't make it onto the list and nothing else is selected */
        ttlist[0] = newtt;
        selected[0] = TRUE;
        sel_count++;
        off_list = TRUE;
    }


    score_list = xmalloc(sel_count * sizeof (struct nh_topten_entry));
    memset(score_list, 0, sel_count * sizeof (struct nh_topten_entry));
    *out_len = sel_count;
    j = 0;
    for (i = 0; i < TTLISTLEN && validentry(ttlist[i]); i++) {
        if (selected[i])
            fill_nh_score_entry(&ttlist[i], &score_list[j++], i + 1, i == rank);
    }

    if (off_list) {
        score_list[0].rank = -1;
        score_list[0].highlight = TRUE;
    }

    if (!game_inited) {
        free_dungeon();
        dlb_cleanup();
    }

    free(selected);
    free(ttlist);

    api_exit();
    return score_list;
}
Example #3
0
File: save.c Project: mbi/NitroHack
void freedynamicdata(void)
{
	int i;
	struct level *lev;
	
	if (!objects)
	    return; /* no cleanup necessary */
	
	unload_qtlist();
	free_invbuf();	/* let_to_name (invent.c) */
	free_youbuf();	/* You_buf,&c (pline.c) */
	tmp_at(DISP_FREEMEM, 0);	/* temporary display effects */
# define free_animals()	 mon_animal_list(FALSE)

	for (i = 0; i < MAXLINFO; i++) {
	    lev = levels[i];
	    levels[i] = NULL;
	    if (!lev) continue;
	    
	    /* level-specific data */
	    dmonsfree(lev);	/* release dead monsters */
	    free_timers(lev);
	    free_light_sources(lev);
	    free_monchn(lev->monlist);
	    free_worm(lev);		/* release worm segment information */
	    freetrapchn(lev->lev_traps);
	    free_objchn(lev->objlist);
	    free_objchn(lev->buriedobjlist);
	    free_objchn(lev->billobjs);
	    free_engravings(lev);
	    freedamage(lev);
	    
	    free(lev);
	}

	/* game-state data */
	free_objchn(invent);
	free_objchn(migrating_objs);
	free_monchn(migrating_mons);
	free_monchn(mydogs);		/* ascension or dungeon escape */
	free_animals();
	free_oracles();
	freefruitchn();
	freenames();
	free_waterlevel();
	free_dungeon();
	free_history();

	if (iflags.ap_rules) {
	    free(iflags.ap_rules->rules);
	    iflags.ap_rules->rules = NULL;
	    free(iflags.ap_rules);
	}
	iflags.ap_rules = NULL;
	free(artilist);
	free(objects);
	objects = NULL;
	artilist = NULL;
	
	if (active_birth_options)
	    free_optlist(active_birth_options);
	active_birth_options = NULL;
	
	return;
}