当前位置: 首页>>代码示例>>C++>>正文


C++ rn2函数代码示例

本文整理汇总了C++中rn2函数的典型用法代码示例。如果您正苦于以下问题:C++ rn2函数的具体用法?C++ rn2怎么用?C++ rn2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了rn2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init_objects

void
init_objects()
{
	int i, j, first, last, sum, end;
	char let, *tmp;

	/* init base; if probs given check that they add up to 100, 
	   otherwise compute probs; shuffle descriptions */
	end = nitems(objects);
	first = 0;
	while( first < end ) {
		let = objects[first].oc_olet;
		last = first+1;
		while(last < end && objects[last].oc_olet == let
				&& objects[last].oc_name != NULL)
			last++;
		i = letindex(let);
		if((!i && let != ILLOBJ_SYM) || bases[i] != 0)
			error("initialization error");
		bases[i] = first;

		if(let == GEM_SYM)
			setgemprobs();
	check:
		sum = 0;
		for(j = first; j < last; j++) sum += objects[j].oc_prob;
		if(sum == 0) {
			for(j = first; j < last; j++)
			    objects[j].oc_prob = (100+j-first)/(last-first);
			goto check;
		}
		if(sum != 100)
			error("init-prob error for %c", let);

		if(objects[first].oc_descr != NULL && let != TOOL_SYM){
			/* shuffle, also some additional descriptions */
			while(last < end && objects[last].oc_olet == let)
				last++;
			j = last;
			while(--j > first) {
				i = first + rn2(j+1-first);
				tmp = objects[j].oc_descr;
				objects[j].oc_descr = objects[i].oc_descr;
				objects[i].oc_descr = tmp;
			}
		}
		first = last;
	}
}
开发者ID:SylvestreG,项目名称:bitrig,代码行数:49,代码来源:hack.o_init.c

示例2: create_drawbridge

boolean
create_drawbridge(int x, int y, int dir, int flag)
{
    int x2,y2;
    boolean horiz;
    boolean lava = levl[x][y].typ == LAVAPOOL; /* assume initialized map */

    if (flag < 0 || flag > 1) flag = rn2(2);
    x2 = x;
    y2 = y;
    switch(dir) {
    case DB_NORTH:
        horiz = TRUE;
        y2--;
        break;
    case DB_SOUTH:
        horiz = TRUE;
        y2++;
        break;
    case DB_EAST:
        horiz = FALSE;
        x2++;
        break;
    default:
        impossible("bad direction in create_drawbridge");
        /* fall through */
    case DB_WEST:
        horiz = FALSE;
        x2--;
        break;
    }
    if (!IS_WALL(levl[x2][y2].typ))
        return(FALSE);
    if (flag) {             /* We want the bridge open */
        levl[x][y].typ = DRAWBRIDGE_DOWN;
        levl[x2][y2].typ = DOOR;
        levl[x2][y2].doormask = D_NODOOR;
    } else {
        levl[x][y].typ = DRAWBRIDGE_UP;
        levl[x2][y2].typ = DBWALL;
        /* Drawbridges are non-diggable. */
        levl[x2][y2].wall_info = W_NONDIGGABLE;
    }
    levl[x][y].horizontal = !horiz;
    levl[x2][y2].horizontal = horiz;
    levl[x][y].drawbridgemask = dir;
    if(lava) levl[x][y].drawbridgemask |= DB_LAVA;
    return(TRUE);
}
开发者ID:chasonr,项目名称:unnethack-i18n,代码行数:49,代码来源:dbridge.c

示例3: PlayerSelectProc

BOOL WINAPI PlayerSelectProc(HWND hDlg, UINT messg, UINT wParam, LONG lParam)
{
	int i;

	switch (messg) {
		case WM_INITDIALOG:
			CheckRadioButton(hDlg,IDD_ARCH,IDD_RAND,IDD_RAND);
			nCurrentChar = IDD_RAND;
			return TRUE;
		case WM_COMMAND:
			switch (wParam) {
			   case IDOK:
				if (nCurrentChar == IDD_RAND) {
					i = rn2((int)strlen(pl_classes));
					pl_character[0] = pl_classes[i];
				} else	{
					pl_character[0] = 
					   pl_classes[nCurrentChar-IDD_ARCH];
				}
				EndDialog(hDlg,TRUE);
				return TRUE;
				break;
			   case IDCANCEL:
				pl_character[0] = 0;
				EndDialog(hDlg,FALSE);
				return TRUE;
				break;
			   case IDD_ARCH:
			   case IDD_BARB:
			   case IDD_CAVEMAN:
			   case IDD_ELF:
			   case IDD_HEAL:
			   case IDD_KNIGHT:
			   case IDD_PRIEST:
			   case IDD_ROGUE:
			   case IDD_SAM:
			   case IDD_TOUR:
			   case IDD_VAL:
			   case IDD_WIZ:
			   case IDD_RAND:
				nCurrentChar = wParam;
				CheckRadioButton(hDlg,IDD_ARCH,
						 IDD_RAND,wParam);
				return TRUE;
				break;
		}
	}
	return FALSE;
}
开发者ID:BarclayII,项目名称:slashem-up,代码行数:49,代码来源:win32msg.c

示例4: boomhit

struct monst *
boomhit(int dx, int dy)
{
	int i, ct;
	struct monst *mtmp;
	char sym = ')';

	bhitpos.x = u.ux;
	bhitpos.y = u.uy;

	for (i = 0; i < 8; i++)
		if (xdir[i] == dx && ydir[i] == dy)
			break;
	tmp_at(-1, sym);	/* open call */
	for (ct = 0; ct < 10; ct++) {
		if (i == 8)
			i = 0;
		sym = ')' + '(' - sym;
		tmp_at(-2, sym);	/* change let call */
		dx = xdir[i];
		dy = ydir[i];
		bhitpos.x += dx;
		bhitpos.y += dy;
		if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != NULL) {
			tmp_at(-1, -1);
			return (mtmp);
		}
		if (!ZAP_POS(levl[bhitpos.x][bhitpos.y].typ)) {
			bhitpos.x -= dx;
			bhitpos.y -= dy;
			break;
		}
		if (bhitpos.x == u.ux && bhitpos.y == u.uy) {	/* ct == 9 */
			if (rn2(20) >= 10 + u.ulevel) {	/* we hit ourselves */
				thitu(10, rnd(10), "boomerang");
				break;
			} else {	/* we catch it */
				tmp_at(-1, -1);
				pline("Skillfully, you catch the boomerang.");
				return (&youmonst);
			}
		}
		tmp_at(bhitpos.x, bhitpos.y);
		if (ct % 5 != 0)
			i++;
	}
	tmp_at(-1, -1);		/* do not leave last symbol */
	return (0);
}
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:49,代码来源:hack.zap.c

示例5: mondied

/* drop (perhaps) a cadaver and remove monster */
void
mondied(struct monst *mdef)
{
	struct permonst *pd = mdef->data;

	if (letter(pd->mlet) && rn2(3)) {
		mkobj_at(pd->mlet, mdef->mx, mdef->my);
		if (cansee(mdef->mx, mdef->my)) {
			unpmon(mdef);
			atl(mdef->mx, mdef->my, fobj->olet);
		}
		stackobj(fobj);
	}
	mondead(mdef);
}
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:16,代码来源:hack.fight.c

示例6: courtmon

const struct permonst *
courtmon(const d_level * dlev)
{
    int i = rn2(60) + rn2(3 * level_difficulty(dlev));

    if (i > 100)
        return mkclass(dlev, S_DRAGON, 0);
    else if (i > 95)
        return mkclass(dlev, S_GIANT, 0);
    else if (i > 85)
        return mkclass(dlev, S_TROLL, 0);
    else if (i > 75)
        return mkclass(dlev, S_CENTAUR, 0);
    else if (i > 60)
        return mkclass(dlev, S_ORC, 0);
    else if (i > 45)
        return &mons[PM_BUGBEAR];
    else if (i > 30)
        return &mons[PM_HOBGOBLIN];
    else if (i > 15)
        return mkclass(dlev, S_GNOME, 0);
    else
        return mkclass(dlev, S_KOBOLD, 0);
}
开发者ID:clockfort,项目名称:bingehack4,代码行数:24,代码来源:mkroom.c

示例7: tt_oname

/*
 * Get a random player name and class from the high score list,
 * and attach them to an object (for statues or morgue corpses).
 */
struct obj *
tt_oname(struct obj *otmp)
{
    int rank, fd;
    struct toptenentry *toptenlist, *tt;

    if (!otmp)
        return NULL;

    fd = open_datafile(RECORD, O_RDONLY, SCOREPREFIX);
    toptenlist = read_topten(fd, 100);  /* load the top 100 scores */
    close(fd);

    /* try to find a valid entry, reducing the value range for rank each time */
    rank = rn2(100);
    while (!validentry(toptenlist[rank]) && rank)
        rank = rn2(rank);

    tt = &toptenlist[rank];

    if (!validentry(toptenlist[rank]))
        otmp = NULL;    /* the topten list is empty */
    else {
        /* reset timer in case corpse started out as lizard or troll */
        if (otmp->otyp == CORPSE)
            obj_stop_timers(otmp);
        otmp->corpsenm = classmon(tt->plrole, (tt->plgend[0] == 'F'));
        otmp->owt = weight(otmp);
        otmp = oname(otmp, tt->name);
        if (otmp->otyp == CORPSE)
            start_corpse_timeout(otmp);
    }

    free(toptenlist);
    return otmp;
}
开发者ID:clockfort,项目名称:bingehack4,代码行数:40,代码来源:topten.c

示例8: mkobj

struct obj *
mkobj(int let)
{
	if (!let)
		let = mkobjstr[rn2(sizeof(mkobjstr) - 1)];
	return (
		mksobj(
		       letter(let) ?
		       CORPSE +
		       ((let > 'Z') ? (let - 'a' + 'Z' - '@' +
				       1) : (let - '@'))
		       :   probtype(let)
		       )
		);
}
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:15,代码来源:hack.mkobj.c

示例9: domindblast

int domindblast(void)
{
	struct monst *mtmp, *nmon;

	if (u.uen < 10) {
	    pline("You concentrate but lack the energy to maintain doing so.");
	    return 0;
	}
	u.uen -= 10;
	iflags.botl = 1;

	pline("You concentrate.");
	pline("A wave of psychic energy pours out.");
	for (mtmp=level->monlist; mtmp; mtmp = nmon) {
		int u_sen;

		nmon = mtmp->nmon;
		if (DEADMONSTER(mtmp))
			continue;
		if (distu(mtmp->mx, mtmp->my) > BOLT_LIM * BOLT_LIM)
			continue;
		if (mtmp->mpeaceful)
			continue;
		u_sen = telepathic(mtmp->data) && !mtmp->mcansee;
		if (u_sen || (telepathic(mtmp->data) && rn2(2)) || !rn2(10)) {
			pline("You lock in on %s %s.", s_suffix(mon_nam(mtmp)),
				u_sen ? "telepathy" :
				telepathic(mtmp->data) ? "latent telepathy" :
				"mind");
			mtmp->mhp -= rnd(15);
			if (mtmp->mhp <= 0)
				killed(mtmp);
		}
	}
	return 1;
}
开发者ID:DanielT,项目名称:NitroHack,代码行数:36,代码来源:polyself.c

示例10: mkswamp

static void
mkswamp (void)  /* Michiel Huisjes & Fred de Wilde */
{
        struct mkroom *sroom;
        int sx,sy,i,eelct = 0;

        for(i=0; i<5; i++) {            /* turn up to 5 rooms swampy */
                sroom = &rooms[rn2(nroom)];
                if(sroom->hx < 0 || sroom->rtype != OROOM ||
                   has_upstairs(sroom) || has_dnstairs(sroom))
                        continue;

                /* satisfied; make a swamp */
                sroom->rtype = SWAMP;
                for(sx = sroom->lx; sx <= sroom->hx; sx++)
                for(sy = sroom->ly; sy <= sroom->hy; sy++)
                if(!OBJ_AT(sx, sy) &&
                   !MON_AT(sx, sy) && !t_at(sx,sy) && !nexttodoor(sx,sy)) {
                    if((sx+sy)%2) {
                        levl[sx][sy].typ = POOL;
                        if(!eelct || !rn2(4)) {
                            /* mkclass() won't do, as we might get kraken */
                            (void) makemon(rn2(5) ? &mons[PM_GIANT_EEL]
                                                  : rn2(2) ? &mons[PM_PIRANHA]
                                                  : &mons[PM_ELECTRIC_EEL],
                                                sx, sy, NO_MM_FLAGS);
                            eelct++;
                        }
                    } else
                        if(!rn2(4))     /* swamps tend to be moldy */
                            (void) makemon(mkclass(S_FUNGUS,0),
                                                sx, sy, NO_MM_FLAGS);
                }
                level.flags.has_swamp = 1;
        }
}
开发者ID:thejoshwolfe,项目名称:nethack,代码行数:36,代码来源:mkroom.c

示例11: safe_teleds

boolean safe_teleds(boolean allow_drag)
{
	int nux, nuy, tcnt = 0;

	do {
		nux = rnd(COLNO-1);
		nuy = rn2(ROWNO);
	} while (!teleok(nux, nuy, (boolean)(tcnt > 200)) && ++tcnt <= 400);

	if (tcnt <= 400) {
		teleds(nux, nuy, allow_drag);
		return TRUE;
	} else
		return FALSE;
}
开发者ID:DanielT,项目名称:NitroHack,代码行数:15,代码来源:teleport.c

示例12: pick_room

/* pick an unused room, preferably with only one door */
static struct mkroom *
pick_room(struct level *lev, boolean strict)
{
    struct mkroom *sroom;
    int i = lev->nroom;

    for (sroom = &lev->rooms[rn2(lev->nroom)]; i--; sroom++) {
        if (sroom == &lev->rooms[lev->nroom])
            sroom = &lev->rooms[0];
        if (sroom->hx < 0)
            return NULL;
        if (sroom->rtype != OROOM)
            continue;
        if (!strict) {
            if (has_upstairs(lev, sroom) ||
                (has_dnstairs(lev, sroom) && rn2(3)))
                continue;
        } else if (has_upstairs(lev, sroom) || has_dnstairs(lev, sroom))
            continue;
        if (sroom->doorct == 1 || !rn2(5) || wizard)
            return sroom;
    }
    return NULL;
}
开发者ID:clockfort,项目名称:bingehack4,代码行数:25,代码来源:mkroom.c

示例13: kick_steed

/* The player kicks or whips the steed */
void
kick_steed(void)
{
    char He[4];

    if (!u.usteed)
        return;

    /* [ALI] Various effects of kicking sleeping/paralyzed steeds */
    if (u.usteed->msleeping || !u.usteed->mcanmove) {
        /* We assume a message has just been output of the form "You kick
           <steed>." */
        strcpy(He, mhe(u.usteed));
        *He = highc(*He);
        if ((u.usteed->mcanmove || u.usteed->mfrozen) && !rn2(2)) {
            if (u.usteed->mcanmove)
                u.usteed->msleeping = 0;
            else if (u.usteed->mfrozen > 2)
                u.usteed->mfrozen -= 2;
            else {
                u.usteed->mfrozen = 0;
                u.usteed->mcanmove = 1;
            }
            if (u.usteed->msleeping || !u.usteed->mcanmove)
                pline("%s stirs.", He);
            else
                pline("%s rouses %sself!", He, mhim(u.usteed));
        } else
            pline("%s does not respond.", He);
        return;
    }

    /* Make the steed less tame and check if it resists */
    if (u.usteed->mtame)
        u.usteed->mtame--;
    if (!u.usteed->mtame && u.usteed->mleashed)
        m_unleash(u.usteed, TRUE);
    if (!u.usteed->mtame ||
            (u.ulevel + u.usteed->mtame < rnd(MAXULEV / 2 + 5))) {
        newsym(u.usteed->mx, u.usteed->my);
        dismount_steed(DISMOUNT_THROWN);
        return;
    }

    pline("%s gallops!", Monnam(u.usteed));
    u.ugallop += rn1(20, 30);
    return;
}
开发者ID:FredrIQ,项目名称:nhfourk,代码行数:49,代码来源:steed.c

示例14: rloc

/* return TRUE if successful, FALSE if not */
boolean rloc(struct monst *mtmp, /* mx==0 implies migrating monster arrival */
	     boolean suppress_impossible)
{
	int x, y, trycount;

	if (mtmp == u.usteed) {
	    tele();
	    return TRUE;
	}

	if (mtmp->iswiz && mtmp->mx) {	/* Wizard, not just arriving */
	    if (!In_W_tower(u.ux, u.uy, &u.uz))
		x = level->upstair.sx,  y = level->upstair.sy;
	    else if (!level->dnladder.sx)	/* bottom level of tower */
		x = level->upladder.sx,  y = level->upladder.sy;
	    else
		x = level->dnladder.sx,  y = level->dnladder.sy;
	    /* if the wiz teleports away to heal, try the up staircase,
	       to block the player's escaping before he's healed
	       (deliberately use `goodpos' rather than `rloc_pos_ok' here) */
	    if (goodpos(level, x, y, mtmp, 0))
		goto found_xy;
	}

	trycount = 0;
	do {
	    x = rn1(COLNO-3,2);
	    y = rn2(ROWNO);
	    if ((trycount < 500) ? rloc_pos_ok(x, y, mtmp)
				 : goodpos(level, x, y, mtmp, 0))
		goto found_xy;
	} while (++trycount < 1000);

	/* last ditch attempt to find a good place */
	for (x = 2; x < COLNO - 1; x++)
	    for (y = 0; y < ROWNO; y++)
		if (goodpos(level, x, y, mtmp, 0))
		    goto found_xy;

	/* level either full of monsters or somehow faulty */
	if (!suppress_impossible)
		impossible("rloc(): couldn't relocate monster");
	return FALSE;

 found_xy:
	rloc_to(mtmp, x, y);
	return TRUE;
}
开发者ID:DanielT,项目名称:NitroHack,代码行数:49,代码来源:teleport.c

示例15: redist_attr

void redist_attr (void) {
    int i, tmp;

    for(i = 0; i < A_MAX; i++) {
        if (i==A_INT || i==A_WIS) continue;
        /* Polymorphing doesn't change your mind */
        tmp = AMAX(i);
        AMAX(i) += (rn2(5)-2);
        if (AMAX(i) > ATTRMAX(i)) AMAX(i) = ATTRMAX(i);
        if (AMAX(i) < ATTRMIN(i)) AMAX(i) = ATTRMIN(i);
        ABASE(i) = ABASE(i) * AMAX(i) / tmp;
        /* ABASE(i) > ATTRMAX(i) is impossible */
        if (ABASE(i) < ATTRMIN(i)) ABASE(i) = ATTRMIN(i);
    }
    (void)encumber_msg();
}
开发者ID:thejoshwolfe,项目名称:nethack,代码行数:16,代码来源:attrib.c


注:本文中的rn2函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。