コード例 #1
0
/* Write a light source structure to disk. */
static void
write_ls(struct memfile *mf, light_source * ls)
{
    struct obj *otmp;
    struct monst *mtmp;
    long id;

    if ((ls->flags & LSF_NEEDS_FIXUP)) {
        id = *(int32_t *) ls->id;
    } else if (ls->type == LS_OBJECT) {
        otmp = (struct obj *)ls->id;
        id = otmp->o_id;
    } else if (ls->type == LS_MONSTER) {
        mtmp = (struct monst *)ls->id;
        id = mtmp->m_id;
    } else {
        impossible("write_ls: bad type (%d)", ls->type);
        id = 0;
    }


    mtag(mf, id * 2 + ls->type, MTAG_LIGHT);
    mwrite32(mf, ls->type);
    mwrite16(mf, ls->range);

    mwrite16(mf, ls->flags | LSF_NEEDS_FIXUP);
    mwrite32(mf, id);
    mwrite8(mf, ls->x);
    mwrite8(mf, ls->y);
}
コード例 #2
0
ファイル: light.c プロジェクト: DanielT/NitroHack
/* Write a light source structure to disk. */
static void write_ls(struct memfile *mf, light_source *ls)
{
    struct obj *otmp;
    struct monst *mtmp;

    mwrite32(mf, ls->type);
    mwrite16(mf, ls->range);
    
    if ((ls->flags & LSF_NEEDS_FIXUP)) {
	mwrite16(mf, ls->flags);
	mwrite32(mf, (*(int32_t*)ls->id));
    } else if (ls->type == LS_OBJECT) {
	mwrite16(mf, ls->flags | LSF_NEEDS_FIXUP);
	otmp = (struct obj *)ls->id;
	mwrite32(mf, otmp->o_id);
    } else if (ls->type == LS_MONSTER) {
	mwrite16(mf, ls->flags | LSF_NEEDS_FIXUP);
	mtmp = (struct monst *)ls->id;
	mwrite32(mf, mtmp->m_id);
    } else
	impossible("write_ls: bad type (%d)", ls->type);
    
    mwrite8(mf, ls->x);
    mwrite8(mf, ls->y);
}
コード例 #3
0
ファイル: save.c プロジェクト: chasetopher/NetHack-4
static void
savetrapchn(struct memfile *mf, struct trap *trap, struct level *lev)
{
    struct trap *trap2;
    unsigned short tflags;
    int count = 0;

    mfmagic_set(mf, TRAPCHAIN_MAGIC);
    for (trap2 = trap; trap2; trap2 = trap2->ntrap)
        count++;
    mwrite32(mf, count);

    for (; trap; trap = trap->ntrap) {
        /* To distinguish traps from each other in tags, we use x/y/z coords */
        mtag(mf,
             ledger_no(&lev->z) + ((int)trap->tx << 8) + ((int)trap->ty << 16),
             MTAG_TRAP);
        mwrite8(mf, trap->tx);
        mwrite8(mf, trap->ty);
        mwrite8(mf, trap->dst.dnum);
        mwrite8(mf, trap->dst.dlevel);
        mwrite8(mf, trap->launch.x);
        mwrite8(mf, trap->launch.y);
        tflags = (trap->ttyp << 11) | (trap->tseen << 10) |
            (trap->once << 9) | (trap->madeby_u << 8);
        mwrite16(mf, tflags);
        mwrite16(mf, trap->vl.v_launch_otyp);
    }
}
コード例 #4
0
ファイル: save.c プロジェクト: mbi/NitroHack
static void save_spellbook(struct memfile *mf)
{
	int i;
	for (i = 0; i < MAXSPELL + 1; i++) {
	    mwrite32(mf, spl_book[i].sp_know);
	    mwrite16(mf, spl_book[i].sp_id);
	    mwrite8(mf, spl_book[i].sp_lev);
	}
}
コード例 #5
0
ファイル: save.c プロジェクト: chasetopher/NetHack-4
static void
save_location(struct memfile *mf, struct rm *loc)
{
    unsigned int memflags;
    unsigned short rflags;

    unsigned char bg = loc->mem_bg;

    /* pack mem_door_l, mem_door_t into mem_bg */
    switch (bg) {
    case S_vodoor:
        if (loc->mem_door_l && loc->mem_door_t)
            bg = S_vodoor_memlt;
        else if (loc->mem_door_l)
            bg = S_vodoor_meml;
        else if (loc->mem_door_t)
            bg = S_vodoor_memt;
        break;
    case S_hodoor:
        if (loc->mem_door_l && loc->mem_door_t)
            bg = S_hodoor_memlt;
        else if (loc->mem_door_l)
            bg = S_hodoor_meml;
        else if (loc->mem_door_t)
            bg = S_hodoor_memt;
        break;
    case S_vcdoor:
        if (loc->mem_door_l && loc->mem_door_t)
            bg = S_vcdoor_memlt;
        else if (loc->mem_door_l)
            bg = S_vcdoor_meml;
        else if (loc->mem_door_t)
            bg = S_vcdoor_memt;
        break;
    case S_hcdoor:
        if (loc->mem_door_l && loc->mem_door_t)
            bg = S_hcdoor_memlt;
        else if (loc->mem_door_l)
            bg = S_hcdoor_meml;
        else if (loc->mem_door_t)
            bg = S_hcdoor_memt;
        break;
    }

    memflags = (bg << 26) | (loc->mem_trap << 21) | (loc->mem_obj << 11) |
        (loc->mem_obj_mn << 2) | (loc->mem_invis << 1) |
        (loc->mem_stepped << 0);
    rflags = (loc->flags << 11) | (loc->horizontal << 10) | (loc->lit << 9) |
        (loc->waslit << 8) | (loc->roomno << 2) | (loc->edge << 1);
    mwrite32(mf, memflags);
    mwrite8(mf, loc->typ);
    mwrite8(mf, loc->seenv);
    mwrite16(mf, rflags);
}
コード例 #6
0
ファイル: save.c プロジェクト: mbi/NitroHack
static void savetrapchn(struct memfile *mf, struct trap *trap)
{
	struct trap *trap2;
	unsigned short tflags;
	int count = 0;
	
	mfmagic_set(mf, TRAPCHAIN_MAGIC);
	for (trap2 = trap; trap2; trap2 = trap2->ntrap)
	    count++;
	mwrite32(mf, count);

	for (; trap; trap = trap->ntrap) {
	    mwrite8(mf, trap->tx);
	    mwrite8(mf, trap->ty);
	    mwrite8(mf, trap->dst.dnum);
	    mwrite8(mf, trap->dst.dlevel);
	    mwrite8(mf, trap->launch.x);
	    mwrite8(mf, trap->launch.y);
	    tflags = (trap->ttyp << 11) | (trap->tseen << 10) |
			(trap->once << 9) | (trap->madeby_u << 8);
	    mwrite16(mf, tflags);
	    mwrite16(mf, trap->vl.v_launch_otyp);
	}
}
コード例 #7
0
ファイル: mkobj.c プロジェクト: DanielT/NitroHack
void save_obj(struct memfile *mf, struct obj *obj)
{
    unsigned int oflags;
    
    oflags = (obj->cursed << 31) | (obj->blessed << 30) | (obj->unpaid << 29) |
	     (obj->no_charge << 28) | (obj->known << 27) | (obj->dknown << 26) |
	     (obj->bknown << 25) | (obj->rknown << 24) | (obj->oeroded << 22) |
	     (obj->oeroded2 << 20) | (obj->oerodeproof << 19) | (obj->olocked << 18) |
	     (obj->obroken << 17) | (obj->otrapped << 16) | (obj->recharged << 13) |
	     (obj->lamplit << 12) | (obj->greased << 11) | (obj->oattached << 9) |
	     (obj->in_use << 8) | (obj->was_thrown << 7) | (obj->bypass << 6);
    
    mfmagic_set(mf, OBJ_MAGIC);
    
    mwrite32(mf, obj->onamelth);    
    mwrite32(mf, obj->o_id);
    mwrite32(mf, obj->owt);
    mwrite32(mf, obj->quan);
    mwrite32(mf, obj->corpsenm);
    mwrite32(mf, obj->oeaten);
    mwrite32(mf, obj->age);
    mwrite32(mf, obj->owornmask);
    mwrite32(mf, oflags);
    
    mwrite16(mf, obj->otyp);
    
    mwrite8(mf, obj->ox);
    mwrite8(mf, obj->oy);
    mwrite8(mf, obj->spe);
    mwrite8(mf, obj->oclass);
    mwrite8(mf, obj->invlet);
    mwrite8(mf, obj->oartifact);
    mwrite8(mf, obj->where);
    mwrite8(mf, obj->timed);
    /* no need to save the value of the cobj pointer, but we will need to know
     * if there is something in here that needs to be restored */
    mwrite8(mf, obj->cobj ? 1 : 0);
    
    if (obj->onamelth)
	mwrite(mf, ONAME(obj), obj->onamelth);
    
    if (obj->oattached == OATTACHED_MONST)
	save_mon(mf, (struct monst*)obj->oextra);
    else if (obj->oattached == OATTACHED_M_ID)
	mwrite32(mf, *(unsigned int*)obj->oextra);
}
コード例 #8
0
ファイル: save.c プロジェクト: mbi/NitroHack
static void save_location(struct memfile *mf, struct rm *loc)
{
	unsigned int lflags1;
	unsigned short lflags2;
	
	lflags1 = (loc->mem_bg << 26) |
	          (loc->mem_trap << 21) |
	          (loc->mem_obj << 11) |
	          (loc->mem_obj_mn << 2) |
	          (loc->mem_invis << 1);
	lflags2 = (loc->flags << 11) |
	          (loc->horizontal << 10) |
	          (loc->lit << 9) |
	          (loc->waslit << 8) |
	          (loc->roomno << 2) |
	          (loc->edge << 1);
	mwrite32(mf, lflags1);
	mwrite8(mf, loc->typ);
	mwrite8(mf, loc->seenv);
	mwrite16(mf, lflags2);
}
コード例 #9
0
/**
 * save_regions :
 */
void
save_regions(struct memfile *mf, struct level *lev)
{
    int i, j;
    unsigned len1, len2;
    struct region *r;

    mfmagic_set(mf, REGION_MAGIC);
    mtag(mf, ledger_no(&lev->z), MTAG_REGION);
    mwrite32(mf, save_encode_32(moves, moves, moves));    /* timestamp */
    mwrite32(mf, lev->n_regions);

    /* Note: level regions don't have ID numbers, so we can't tag individual
       regions; instead, diff efficiency depends on the fact that regions tend
       to stay in the order and are typically inserted or deleted near the end
       of the list */
    for (i = 0; i < lev->n_regions; i++) {
        r = lev->regions[i];

        save_rect(mf, r->bounding_box);
        mwrite32(mf, r->attach_2_m);
        mwrite32(mf, r->effect_id);
        mwrite32(mf, r->arg);
        mwrite16(mf, r->nrects);
        for (j = 0; j < r->nrects; j++)
            save_rect(mf, r->rects[j]);
        mwrite16(mf, r->ttl);
        mwrite16(mf, r->expire_f);
        mwrite16(mf, r->can_enter_f);
        mwrite16(mf, r->enter_f);
        mwrite16(mf, r->can_leave_f);
        mwrite16(mf, r->leave_f);
        mwrite16(mf, r->inside_f);
        mwrite16(mf, r->n_monst);
        mwrite8(mf, r->player_flags);
        mwrite8(mf, r->attach_2_u);
        mwrite8(mf, r->visible);

        for (j = 0; j < r->n_monst; j++)
            mwrite32(mf, r->monsters[j]);

        len1 = r->enter_msg ? strlen(r->enter_msg) + 1 : 0;
        mwrite16(mf, len1);
        len2 = r->leave_msg ? strlen(r->leave_msg) + 1 : 0;
        mwrite16(mf, len2);

        if (len1 > 0)
            mwrite(mf, r->enter_msg, len1);

        if (len2 > 0)
            mwrite(mf, r->leave_msg, len2);
    }
}