コード例 #1
0
ファイル: markup.c プロジェクト: nrnrnr/noweb
void getmodname(char *dest, int size, char *source) {
    /* excess characters in the module name are ignored */
    char *p = strsave(source);
    char *q = mod_start(p,1);

    if (q==NULL) 
#line 184 "markup.nw"
{
    free(p);
    impossible
        ("I couldn't manage to extract a module name, but I'm sure I saw one");
}
#line 178 "markup.nw"
    if (mod_end(q,1)==NULL) 
#line 184 "markup.nw"
{
    free(p);
    impossible
        ("I couldn't manage to extract a module name, but I'm sure I saw one");
}
#line 179 "markup.nw"
    strncpy(dest,q,size-1);
    dest[size-1] = '\0';
    free(p);
}
コード例 #2
0
ファイル: light.c プロジェクト: DanielT/NitroHack
/* Relink all lights that are so marked. */
void relink_light_sources(boolean ghostly, struct level *lev)
{
    char which;
    unsigned nid;
    light_source *ls;

    for (ls = lev->lev_lights; ls; ls = ls->next) {
	if (ls->flags & LSF_NEEDS_FIXUP) {
	    if (ls->type == LS_OBJECT || ls->type == LS_MONSTER) {
		if (ghostly) {
		    if (!lookup_id_mapping((long)ls->id, &nid))
			impossible("relink_light_sources: no id mapping");
		} else
		    nid = (long) ls->id;
		if (ls->type == LS_OBJECT) {
		    which = 'o';
		    ls->id = find_oid(nid);
		} else {
		    which = 'm';
		    ls->id = find_mid(lev, nid, FM_EVERYWHERE);
		}
		if (!ls->id)
		    impossible("relink_light_sources: cant find %c_id %d",
			       which, nid);
	    } else
		impossible("relink_light_sources: bad type (%d)", ls->type);

	    ls->flags &= ~LSF_NEEDS_FIXUP;
	}
    }
}
コード例 #3
0
ファイル: light.c プロジェクト: DanielT/NitroHack
/*
 * 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;
}
コード例 #4
0
ファイル: hack.shk.c プロジェクト: AhmadTux/DragonFlyBSD
void
splitbill(struct obj *obj, struct obj *otmp)
{
	/* otmp has been split off from obj */
	struct bill_x *bp;
	int tmp;

	bp = onbill(obj);
	if (!bp) {
		impossible("splitbill: not on bill?");
		return;
	}
	if (bp->bquan < otmp->quan)
		impossible("Negative quantity on bill??");
	if (bp->bquan == otmp->quan)
		impossible("Zero quantity on bill??");
	bp->bquan -= otmp->quan;

	if (ESHK(shopkeeper)->billct == BILLSZ)
		otmp->unpaid = 0;
	else {
		tmp = bp->price;
		bp = &bill[ESHK(shopkeeper)->billct];
		bp->bo_id = otmp->o_id;
		bp->bquan = otmp->quan;
		bp->useup = 0;
		bp->price = tmp;
		ESHK(shopkeeper)->billct++;
	}
}
コード例 #5
0
ファイル: hack.shk.c プロジェクト: AhmadTux/DragonFlyBSD
/*       -1 if object could not be found (but was paid) */
static int
dopayobj(struct bill_x *bp)
{
	struct obj *obj;
	long ltmp;

	/* find the object on one of the lists */
	obj = bp_to_obj(bp);

	if (!obj) {
		impossible("Shopkeeper administration out of order.");
		setpaid();	/* be nice to the player */
		return (0);
	}

	if (!obj->unpaid && !bp->useup) {
		impossible("Paid object on bill??");
		return (1);
	}
	obj->unpaid = 0;
	ltmp = bp->price * bp->bquan;
	if (ANGRY(shopkeeper))
		ltmp += ltmp / 3;
	if (u.ugold < ltmp) {
		pline("You don't have gold enough to pay %s.",
		      doname(obj));
		obj->unpaid = 1;
		return (0);
	}
	pay(ltmp, shopkeeper);
	pline("You bought %s for %ld gold piece%s.",
	      doname(obj), ltmp, plur(ltmp));
	if (bp->useup) {
		struct obj *otmp = billobjs;
		if (obj == billobjs)
			billobjs = obj->nobj;
		else {
			while (otmp && otmp->nobj != obj)
				otmp = otmp->nobj;
			if (otmp)
				otmp->nobj = obj->nobj;
			else
				pline("Error in shopkeeper administration.");
		}
		free(obj);
	}
	return (1);
}
コード例 #6
0
static void
x_img_tmp_draw_tile_transp(int tile, int ofsx, int ofsy)
{
    int i, j, n;
    guint32 pixel;
    int width, height;
    int srcx, srcy;
    struct tile_transp *t = &tile_transp[tile];
    unsigned char *rle = t->data;

    width = tmp_img->width;
    height = tmp_img->height;
    srcx = (tile % tiles_per_row) * Tile->unit_width;
    srcy = (tile / tiles_per_row) * Tile->unit_height;

    for(j = t->oy; j < t->oy + t->ny; j++) {
	for(i = t->ox + *rle++; i < t->ox + t->nx; ) {
	    for(n = *rle++; n; i++, n--) {
		if (ofsx + i >= 0 && ofsx + i < width &&
		  ofsy + j >= 0 && ofsy + j < height) {
		    pixel = gdk_image_get_pixel(tile_image, srcx + i, srcy + j);
		    gdk_image_put_pixel(tmp_img, ofsx + i, ofsy + j, pixel);
		}
	    }
	    if (i < t->ox + t->nx)
		i += *rle++;
	}
#ifdef DEBUG
	if (i != t->ox + t->nx) impossible("Transparency data misalign");
#endif
    }
}
コード例 #7
0
ファイル: hack.shk.c プロジェクト: AhmadTux/DragonFlyBSD
/* called with two args on merge */
void
obfree(struct obj *obj, struct obj *merge)
{
	struct bill_x *bp = onbill(obj);
	struct bill_x *bpm;

	if (bp) {
		if (!merge) {
			bp->useup = 1;
			obj->unpaid = 0;	/* only for doinvbill */
			obj->nobj = billobjs;
			billobjs = obj;
			return;
		}
		bpm = onbill(merge);
		if (!bpm) {
			/* this used to be a rename */
			impossible("obfree: not on bill??");
			return;
		} else {
			/* this was a merger */
			bpm->bquan += bp->bquan;
			ESHK(shopkeeper)->billct--;
			*bp = bill[ESHK(shopkeeper)->billct];
		}
	}
	free(obj);
}
コード例 #8
0
ファイル: hack.save.c プロジェクト: ajinkya93/netbsd-src
struct obj     *
restobjchn(int fd)
{
	struct obj     *otmp, *otmp2 = NULL;
	struct obj     *first = 0;
	int             xl;
	while (1) {
		mread(fd, &xl, sizeof(xl));
		if (xl == -1)
			break;
		otmp = newobj(xl);
		if (!first)
			first = otmp;
		else
			otmp2->nobj = otmp;
		mread(fd, otmp, (unsigned) xl + sizeof(struct obj));
		if (!otmp->o_id)
			otmp->o_id = flags.ident++;
		otmp2 = otmp;
	}
	if (first && otmp2->nobj) {
		impossible("Restobjchn: error reading objchn.");
		otmp2->nobj = 0;
	}
	return (first);
}
コード例 #9
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);
}
コード例 #10
0
struct obj *
restobjchn(int fd)
{
	struct obj *otmp, *otmp2;
	struct obj *first = NULL;
	int xl;

	/* suppress "used before set" warning from lint */
	otmp2 = NULL;
	for (;;) {
		mread(fd, (char *)&xl, sizeof(xl));
		if (xl == -1)
			break;
		otmp = newobj(xl);
		if (!first)
			first = otmp;
		else
			otmp2->nobj = otmp;
		mread(fd, (char *)otmp, (unsigned)xl + sizeof(struct obj));
		if (!otmp->o_id) otmp->o_id = flags.ident++;
		otmp2 = otmp;
	}
	if (first && otmp2->nobj) {
		impossible("Restobjchn: error reading objchn.");
		otmp2->nobj = 0;
	}
	return (first);
}
コード例 #11
0
ファイル: gnmain.c プロジェクト: chasonr/unnethack-i18n
static void ghack_sig_handler(int signum)
{
    int i;
    uid_t uid, euid;
    gid_t gid, egid;
    uid = getuid();
    euid = geteuid();
    gid = getgid();
    egid = getegid();
    if (gid != egid)
        setgid(gid);
    if (uid != euid)
        setuid(uid);
    for(i = SIZE(ghack_chain) - 1; i >= 0; i--)
        if (ghack_chain[i].signum == signum) {
            ghack_chain[i].handler(signum);
            break;
        }
    if (i < 0)
        impossible("Unhandled ghack signal");
    if (uid != euid)
        setuid(euid);
    if (gid != egid)
        setgid(egid);
}
コード例 #12
0
ファイル: steal.c プロジェクト: chasetopher/NetHack-4
static int
stealarm(void)
{
    struct monst *mtmp;
    struct obj *otmp;

    for (otmp = invent; otmp; otmp = otmp->nobj) {
        if (otmp->o_id == stealoid) {
            for (mtmp = level->monlist; mtmp; mtmp = mtmp->nmon) {
                if (mtmp->m_id == stealmid) {
                    if (DEADMONSTER(mtmp))
                        impossible("stealarm(): dead monster stealing");
                    if (!dmgtype(mtmp->data, AD_SITM))  /* polymorphed */
                        goto botm;
                    if (otmp->unpaid)
                        subfrombill(otmp, shop_keeper(level, *u.ushops));
                    freeinv(otmp);
                    pline("%s steals %s!", Monnam(mtmp), doname(otmp));
                    mpickobj(mtmp, otmp);       /* may free otmp */
                    /* Implies seduction, "you gladly hand over ..." so we
                       don't set mavenge bit here. */
                    monflee(mtmp, 0, FALSE, FALSE);
                    if (!tele_restrict(mtmp))
                        rloc(mtmp, FALSE);
                    break;
                }
            }
            break;
        }
    }
botm:stealoid = 0;
    return 0;
}
コード例 #13
0
ファイル: hack.save.c プロジェクト: Bluerise/openbsd-src
struct monst *
restmonchn(int fd)
{
	struct monst *mtmp, *mtmp2;
	struct monst *first = 0;
	int xl;

	struct permonst *monbegin;
	long differ;

	mread(fd, (char *)&monbegin, sizeof(monbegin));
	differ = (char *)(&mons[0]) - (char *)(monbegin);

	while(1) {
		mread(fd, (char *) &xl, sizeof(xl));
		if(xl == -1) break;
		mtmp = newmonst(xl);
		if(!first) first = mtmp;
		else mtmp2->nmon = mtmp;
		mread(fd, (char *) mtmp, (unsigned) xl + sizeof(struct monst));
		if(!mtmp->m_id)
			mtmp->m_id = flags.ident++;
		mtmp->data = (struct permonst *)
			((char *) mtmp->data + differ);
		if(mtmp->minvent)
			mtmp->minvent = restobjchn(fd);
		mtmp2 = mtmp;
	}
	if(first && mtmp2->nmon){
		impossible("Restmonchn: error reading monchn.");
		mtmp2->nmon = 0;
	}
	return(first);
}
コード例 #14
0
ファイル: qt4glyph.cpp プロジェクト: gurrhack/NetHack-Android
NetHackQtGlyphs::NetHackQtGlyphs()
{
    const char* tile_file = PIXMAPDIR "/nhtiles.bmp";
    if ( iflags.wc_tile_file )
	tile_file = iflags.wc_tile_file;

    if (!img.load(tile_file)) {
	tile_file = PIXMAPDIR "/x11tiles";
	if (!img.load(tile_file)) {
	    QString msg;
	    msg.sprintf("Cannot load x11tiles or nhtiles.bmp");
	    QMessageBox::warning(0, "IO Error", msg);
	} else {
	    tiles_per_row = TILES_PER_ROW;
	    if (img.width()%tiles_per_row) {
		impossible("Tile file \"%s\" has %d columns, not multiple of row count (%d)",
			tile_file, img.width(), tiles_per_row);
	    }
	}
    } else {
	tiles_per_row = 40;
    }

    if ( iflags.wc_tile_width )
	tilefile_tile_W = iflags.wc_tile_width;
    else
	tilefile_tile_W = img.width() / tiles_per_row;
    if ( iflags.wc_tile_height )
	tilefile_tile_H = iflags.wc_tile_height;
    else
	tilefile_tile_H = tilefile_tile_W;

    setSize(tilefile_tile_W, tilefile_tile_H);
}
コード例 #15
0
ファイル: steal.c プロジェクト: thejoshwolfe/nethack
static int stealarm (void) {
    struct monst *mtmp;
    struct obj *otmp;

    for(otmp = invent; otmp; otmp = otmp->nobj) {
        if(otmp->o_id == stealoid) {
            for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
                if(mtmp->m_id == stealmid) {
                    if(DEADMONSTER(mtmp)) impossible("stealarm(): dead monster stealing");
                    if(!dmgtype(mtmp->data, AD_SITM)) /* polymorphed */
                        goto botm;
                    if(otmp->unpaid)
                        subfrombill(otmp, shop_keeper(*u.ushops));
                    freeinv(otmp);
                    message_monster_object(MSG_M_STEALS_O, mtmp, otmp);
                    mpickobj(mtmp,otmp);     /* may free otmp */
                    /* Implies seduction, "you gladly hand over ..."
                       so we don't set mavenge bit here. */
                    monflee(mtmp, 0, false, false);
                    if (!tele_restrict(mtmp)) (void) rloc(mtmp, false);
                    break;
                }
            }
            break;
        }
    }
botm:   stealoid = 0;
        return 0;
}
コード例 #16
0
ファイル: gl_image.c プロジェクト: Arc0re/acehack
void sdlgl_generate_gamma_table(void)
{
  int i, result = 0;

  for (i=0; i < 256; i++)
  {
    switch (sdlgl_gamma)
    {
      case -5: result = i - gamma_table_bottom[i] / 2; break;
      case -4: result = i - gamma_table_bottom[i] / 3; break;
      case -3: result = i - gamma_table_bottom[i] / 4; break;
      case -2: result = i - gamma_table_bottom[i] / 6; break;
      case -1: result = i - gamma_table_bottom[i] / 8; break;
      case  0: result = i; break;
      case +1: result = i + gamma_table_top[i] / 8; break;
      case +2: result = i + gamma_table_top[i] / 6; break;
      case +3: result = i + gamma_table_top[i] / 4; break;
      case +4: result = i + gamma_table_top[i] / 3; break;
      case +5: result = i + gamma_table_top[i] / 2; break;

      default:
        impossible("Bad sdlgl_gamma value %d", sdlgl_gamma);
        break;
    }

    sdlgl_gamma_table[i] = min(255, max(0, result));
  }
}
コード例 #17
0
ファイル: quest.c プロジェクト: FredrIQ/nhfourk
/*
 * Expell the player to the stairs on the parent of the quest dungeon.
 *
 * This assumes that the hero is currently _in_ the quest dungeon and that
 * there is a single branch to and from it.
 */
static void
expulsion(boolean seal)
{
    branch *br;
    d_level *dest;
    struct trap *t;
    int portal_flag;

    br = dungeon_branch("The Quest");
    dest = (br->end1.dnum == u.uz.dnum) ? &br->end2 : &br->end1;
    portal_flag = u.uevent.qexpelled ? 0 :      /* returned via artifact? */
        !seal ? 1 : -1;
    schedule_goto(dest, FALSE, FALSE, portal_flag, NULL, NULL);
    if (seal) { /* remove the portal to the quest - sealing it off */
        int reexpelled = u.uevent.qexpelled;

        u.uevent.qexpelled = 1;
        historic_event(FALSE, FALSE, "were expelled from the quest.");
        /* Delete the near portal now; the far (main dungeon side) portal will
           be deleted as part of arrival on that level. If monster movement is
           in progress, any who haven't moved yet will now miss out on a chance 
           to wander through it... */
        for (t = level->lev_traps; t; t = t->ntrap)
            if (t->ttyp == MAGIC_PORTAL)
                break;
        if (t)
            deltrap(level, t);  /* (display might be briefly out of sync) */
        else if (!reexpelled)
            impossible("quest portal already gone?");
    }
}
コード例 #18
0
ファイル: dbridge.c プロジェクト: FredrIQ/nhfourk
int
drawbridge_wall_direction(int x, int y)
{
    struct rm *loc;

    if (!isok(x,y)) {
        impossible("drawbridge_wall_direction(%d,%d) not ok.", x, y);
        return -1;
    }
    loc = &level->locations[x][y];
    if (loc->typ != DOOR && loc->typ != DBWALL)
        return -1;

    if (IS_DRAWBRIDGE(level->locations[x + 1][y].typ) &&
        (level->locations[x + 1][y].drawbridgemask & DB_DIR) == DB_WEST)
        return DB_WEST;
    if (IS_DRAWBRIDGE(level->locations[x - 1][y].typ) &&
        (level->locations[x - 1][y].drawbridgemask & DB_DIR) == DB_EAST)
        return DB_EAST;
    if (IS_DRAWBRIDGE(level->locations[x][y - 1].typ) &&
        (level->locations[x][y - 1].drawbridgemask & DB_DIR) == DB_SOUTH)
        return DB_SOUTH;
    if (IS_DRAWBRIDGE(level->locations[x][y + 1].typ) &&
        (level->locations[x][y + 1].drawbridgemask & DB_DIR) == DB_NORTH)
        return DB_NORTH;

    return -1;
}
コード例 #19
0
ファイル: ball.c プロジェクト: Arc0re/acehack
/*
 *  Place the ball & chain under the hero.  Make sure that the ball & chain
 *  variables are set (actually only needed when blind, but what the heck).
 *  It is assumed that when this is called, the ball and chain are NOT
 *  attached to the object list.
 *
 *  Should not be called while swallowed.
 */
void
placebc()
{
    if (!uchain || !uball) {
	impossible("Where are your ball and chain?");
	return;
    }

    (void) flooreffects(uchain, u.ux, u.uy, "");	/* chain might rust */

    if (carried(uball))		/* the ball is carried */
	u.bc_order = BCPOS_DIFFER;
    else {
	/* ball might rust -- already checked when carried */
	(void) flooreffects(uball, u.ux, u.uy, "");
	place_object(uball, u.ux, u.uy);
	u.bc_order = BCPOS_CHAIN;
    }

    place_object(uchain, u.ux, u.uy);

    u.bglyph = u.cglyph = levl[u.ux][u.uy].glyph;   /* pick up glyph */

    newsym(u.ux,u.uy);
}
コード例 #20
0
boolean
teleport_pet(struct monst * mtmp, boolean force_it)
{
    struct obj *otmp;

    if (mtmp == u.usteed)
        return FALSE;

    if (mtmp->mleashed) {
        otmp = get_mleash(mtmp);
        if (!otmp) {
            impossible("%s is leashed, without a leash.", Monnam(mtmp));
            goto release_it;
        }
        if (otmp->cursed && !force_it) {
            yelp(mtmp);
            return FALSE;
        } else {
            pline("Your leash goes slack.");
        release_it:
            m_unleash(mtmp, FALSE);
            return TRUE;
        }
    }
    return TRUE;
}
コード例 #21
0
ファイル: hack.do_wear.c プロジェクト: blakeney/slack
void
ringoff(struct obj *obj)
{
long mask;
	mask = obj->owornmask & W_RING;
	setworn(NULL, obj->owornmask);
	if(!(u.uprops[PROP(obj->otyp)].p_flgs & mask))
		impossible("Strange... I didn't know you had that ring.");
	u.uprops[PROP(obj->otyp)].p_flgs &= ~mask;
	switch(obj->otyp) {
	case RIN_FIRE_RESISTANCE:
		/* Bad luck if the player is in hell... --jgm */
		if (!Fire_resistance && dlevel >= 30) {
			pline("The flames of Hell burn you to a crisp.");
			killer = "stupidity in hell";
			done("burned");
		}
		break;
	case RIN_LEVITATION:
		if(!Levitation) {	/* no longer floating */
			float_down();
		}
		break;
	case RIN_GAIN_STRENGTH:
		u.ustr -= obj->spe;
		u.ustrmax -= obj->spe;
		if(u.ustr > 118) u.ustr = 118;
		if(u.ustrmax > 118) u.ustrmax = 118;
		flags.botl = 1;
		break;
	case RIN_INCREASE_DAMAGE:
		u.udaminc -= obj->spe;
		break;
	}
}
コード例 #22
0
ファイル: polyself.c プロジェクト: DanielT/NitroHack
int dobreathe(void)
{
	const struct attack *mattk;
	schar dx, dy, dz;

	if (Strangled) {
	    pline("You can't breathe.  Sorry.");
	    return 0;
	}
	if (u.uen < 15) {
	    pline("You don't have enough energy to breathe!");
	    return 0;
	}
	u.uen -= 15;
	iflags.botl = 1;

	if (!getdir(NULL, &dx, &dy, &dz))
	    return 0;

	mattk = attacktype_fordmg(youmonst.data, AT_BREA, AD_ANY);
	if (!mattk)
	    impossible("bad breath attack?");	/* mouthwash needed... */
	else
	    buzz((int) (20 + mattk->adtyp-1), (int)mattk->damn,
		u.ux, u.uy, dx, dy);
	return 1;
}
コード例 #23
0
ファイル: were.c プロジェクト: DanielT/NitroHack
void new_were(struct monst *mon)
{
	int pm;

	pm = counter_were(monsndx(mon->data));
	if (!pm) {
	    impossible("unknown lycanthrope %s.", mon->data->mname);
	    return;
	}

	if (canseemon(mon) && !Hallucination)
	    pline("%s changes into a %s.", Monnam(mon),
			is_human(&mons[pm]) ? "human" :
			mons[pm].mname+4);

	set_mon_data(mon, &mons[pm], 0);
	if (mon->msleeping || !mon->mcanmove) {
	    /* transformation wakens and/or revitalizes */
	    mon->msleeping = 0;
	    mon->mfrozen = 0;	/* not asleep or paralyzed */
	    mon->mcanmove = 1;
	}
	/* regenerate by 1/4 of the lost hit points */
	mon->mhp += (mon->mhpmax - mon->mhp) / 4;
	newsym(mon->mx,mon->my);
	mon_break_armor(mon, FALSE);
	possibly_unwield(mon, FALSE);
}
コード例 #24
0
static coa_t gzip1_alloc(tfm_action act)
{
    coa_t coa = NULL;
    int ret = 0;
    switch (act) {
    case TFMA_WRITE:	/* compress */
        coa = reiser4_vmalloc(zlib_deflate_workspacesize());
        if (!coa) {
            ret = -ENOMEM;
            break;
        }
        break;
    case TFMA_READ:	/* decompress */
        coa = reiser4_vmalloc(zlib_inflate_workspacesize());
        if (!coa) {
            ret = -ENOMEM;
            break;
        }
        break;
    default:
        impossible("edward-767",
                   "trying to alloc workspace for unknown tfm action");
    }
    if (ret) {
        warning("edward-768",
                "alloc workspace for gzip1 (tfm action = %d) failed\n",
                act);
        return ERR_PTR(ret);
    }
    return coa;
}
コード例 #25
0
ファイル: end.c プロジェクト: FredrIQ/fiqhack
static boolean
should_query_disclose_options(char *defquery)
{
    if (!defquery) {
        impossible("should_query_disclose_option: null defquery");
        return TRUE;
    }

    if (program_state.followmode == FM_RECOVERQUIT) {
        *defquery = 'n';
        return FALSE;
    }

    switch (flags.end_disclose) {
    default:   /* fall through */
    case DISCLOSE_PROMPT_DEFAULT_YES:
        *defquery = 'y';
        return TRUE;
    case DISCLOSE_YES_WITHOUT_PROMPT:
        *defquery = 'y';
        return FALSE;
    case DISCLOSE_PROMPT_DEFAULT_NO:
        *defquery = 'n';
        return TRUE;
    case DISCLOSE_NO_WITHOUT_PROMPT:
        *defquery = 'n';
        return FALSE;
    }
}
コード例 #26
0
static void lzo1_free(coa_t coa, tfm_action act)
{
    assert("edward-879", coa != NULL);

    switch (act) {
    case TFMA_WRITE:	/* compress */
        vfree(coa);
        break;
    case TFMA_READ:		/* decompress */
        impossible("edward-1304",
                   "trying to free non-allocated workspace");
    default:
        impossible("edward-880", "unknown tfm action");
    }
    return;
}
コード例 #27
0
static coa_t lzo1_alloc(tfm_action act)
{
    int ret = 0;
    coa_t coa = NULL;

    switch (act) {
    case TFMA_WRITE:	/* compress */
        coa = reiser4_vmalloc(LZO1X_1_MEM_COMPRESS);
        if (!coa) {
            ret = -ENOMEM;
            break;
        }
    case TFMA_READ:		/* decompress */
        break;
    default:
        impossible("edward-877",
                   "trying to alloc workspace for unknown tfm action");
    }
    if (ret) {
        warning("edward-878",
                "alloc workspace for lzo1 (tfm action = %d) failed\n",
                act);
        return ERR_PTR(ret);
    }
    return coa;
}
コード例 #28
0
ファイル: light.c プロジェクト: DanielT/NitroHack
/*
 * Delete a light source. This assumes only one light source is attached
 * to an object at a time.
 */
void del_light_source(struct level *lev, int type, void *id)
{
    light_source *curr, *prev;
    long tmp_id;

    /* need to be prepared for dealing a with light source which
       has only been partially restored during a level change
       (in particular: chameleon vs prot. from shape changers) */
    switch (type) {
    case LS_OBJECT:	tmp_id = (((struct obj *)id)->o_id);
			break;
    case LS_MONSTER:	tmp_id = (((struct monst *)id)->m_id);
			break;
    default:		tmp_id = 0;
			break;
    }

    for (prev = 0, curr = lev->lev_lights; curr; prev = curr, curr = curr->next) {
	if (curr->type != type) continue;
	if (curr->id == ((curr->flags & LSF_NEEDS_FIXUP) ? (void*)tmp_id : id)) {
	    if (prev)
		prev->next = curr->next;
	    else
		lev->lev_lights = curr->next;

	    free(curr);
	    vision_full_recalc = 1;
	    return;
	}
    }
    impossible("del_light_source: not found type=%d, id=0x%lx", type, (long)id);
}
コード例 #29
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);
}
コード例 #30
0
ファイル: dbridge.c プロジェクト: FredrIQ/nhfourk
/*
 * Use is_db_wall where you want to verify that a drawbridge "wall" (i.e.,
 * portcullis) is in the UP position in the location x, y.
 *
 * (If you want to find find out the direction or to verify the existence of a
 * portcullis without regard to whether it's UP or DOWN, then in that case use
 * drawbridge_wall_direction instead.)
 */
boolean
is_db_wall(int x, int y)
{
    if (!isok(x,y)) {
        impossible("is_db_wall(%d,%d) not ok.", x, y);
        return FALSE; /* arbitrary choice */
    }
    return (boolean) (level->locations[x][y].typ == DBWALL);
}