Exemplo n.º 1
0
/*
 * Part of the light source save routine.  Count up the number of light
 * sources that would be written.  If write_it is true, actually write
 * the light source out.
 */
static int maybe_write_ls(struct memfile *mf, struct level *lev, int range, boolean write_it)
{
    int count = 0, is_global;
    light_source *ls;

    for (ls = lev->lev_lights; ls; ls = ls->next) {
	if (!ls->id) {
	    impossible("maybe_write_ls: no id! [range=%d]", range);
	    continue;
	}
	switch (ls->type) {
	case LS_OBJECT:
	    is_global = !obj_is_local((struct obj *)ls->id);
	    break;
	case LS_MONSTER:
	    is_global = !mon_is_local((struct monst *)ls->id);
	    break;
	default:
	    is_global = 0;
	    impossible("maybe_write_ls: bad type (%d) [range=%d]",
		       ls->type, range);
	    break;
	}
	/* if global and not doing local, or vice versa, count it */
	if (is_global ^ (range == RANGE_LEVEL)) {
	    count++;
	    if (write_it) write_ls(mf, ls);
	}
    }

    return count;
}
Exemplo n.º 2
0
void transfer_lights(struct level *oldlev, struct level *newlev)
{
    light_source **prev, *curr;
    boolean is_global;
    
    for (prev = &oldlev->lev_lights; (curr = *prev) != 0; ) {
	switch (curr->type) {
	    case LS_OBJECT:
		is_global = !obj_is_local((struct obj *)curr->id);
		break;
	    case LS_MONSTER:
		is_global = !mon_is_local((struct monst *)curr->id);
		break;
	    default:
		is_global = FALSE;
		break;
	}
	/* associate all global light sources with the new level */
	if (is_global) {
	    *prev = curr->next;
	    curr->next = newlev->lev_lights;
	    newlev->lev_lights = curr;
	} else {
	    prev = &(*prev)->next;
	}
    }
}
Exemplo n.º 3
0
int
wiz_light_sources(const struct nh_cmd_arg *arg)
{
    struct nh_menulist menu;
    const char *buf;
    light_source *ls;

    (void) arg;

    init_menulist(&menu);

    buf = msgprintf("Mobile light sources: hero @ (%2d,%2d)", u.ux, u.uy);
    add_menutext(&menu, buf);
    add_menutext(&menu, "");

    if (level->lev_lights) {
        add_menutext(&menu, "location range flags  type    id");
        add_menutext(&menu, "-------- ----- ------ ----  -------");
        for (ls = level->lev_lights; ls; ls = ls->next) {
            buf = msgprintf("  %2d,%2d   %2d   0x%04x  %s  %p",
                    ls->x, ls->y, ls->range, ls->flags,
                    (ls->type == LS_OBJECT ? "obj" :
                     ls->type == LS_MONSTER ? (
                       mon_is_local((struct monst *)ls->id) ? "mon" :
                       ((struct monst *)ls->id == &youmonst) ? "you" :
                       "<m>") : /* migrating monster */ "???"),
                    ls->id);
            add_menutext(&menu, buf);
        }
    } else
        add_menutext(&menu, "<none>");


    display_menu(&menu, NULL, PICK_NONE, PLHINT_ANYWHERE,
                 NULL);

    return 0;
}
Exemplo n.º 4
0
void
transfer_lights(struct level *oldlev, struct level *newlev, unsigned int obj_id)
{
    light_source **prev, *curr;
    boolean transfer;

    if (newlev == oldlev)
        return;

    for (prev = &oldlev->lev_lights; (curr = *prev) != 0;) {
        switch (curr->type) {
        case LS_OBJECT:
            if (obj_id)
                transfer = (((struct obj *)curr->id)->o_id == obj_id);
            else
                transfer = !obj_is_local((struct obj *)curr->id);
            break;
        case LS_MONSTER:
            if (obj_id)
                transfer = FALSE;
            else
                transfer = !mon_is_local((struct monst *)curr->id);
            break;
        default:
            transfer = FALSE;
            break;
        }
        /* associate light sources with the new level */
        if (transfer) {
            *prev = curr->next;
            curr->next = newlev->lev_lights;
            newlev->lev_lights = curr;
        } else {
            prev = &(*prev)->next;
        }
    }
}
Exemplo n.º 5
0
int wiz_light_sources(void)
{
    struct menulist menu;
    char buf[BUFSZ];
    light_source *ls;

    init_menulist(&menu);

    sprintf(buf, "Mobile light sources: hero @ (%2d,%2d)", u.ux, u.uy);
    add_menutext(&menu, buf);
    add_menutext(&menu, "");

    if (level->lev_lights) {
	add_menutext(&menu, "location range flags  type    id");
	add_menutext(&menu, "-------- ----- ------ ----  -------");
	for (ls = level->lev_lights; ls; ls = ls->next) {
	    sprintf(buf, "  %2d,%2d   %2d   0x%04x  %s  %p",
		ls->x, ls->y, ls->range, ls->flags,
		(ls->type == LS_OBJECT ? "obj" :
		 ls->type == LS_MONSTER ?
		    (mon_is_local((struct monst *)ls->id) ? "mon" :
		     ((struct monst *)ls->id == &youmonst) ? "you" :
		     "<m>") :		/* migrating monster */
		 "???"),
		ls->id);
	    add_menutext(&menu, buf);
	}
    } else
	add_menutext(&menu, "<none>");


    display_menu(menu.items, menu.icount, NULL, PICK_NONE, NULL);
    free(menu.items);

    return 0;
}