本文整理汇总了C++中P_Random函数的典型用法代码示例。如果您正苦于以下问题:C++ P_Random函数的具体用法?C++ P_Random怎么用?C++ P_Random使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了P_Random函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: P_SpawnStrobeFlash
//==================================================================
//
// P_SpawnLightFlash
//
// After the map has been loaded, scan each sector for specials that spawn thinkers
//
//==================================================================
void P_SpawnStrobeFlash(sector_t * sector, int fastOrSlow, int inSync)
{
strobe_t *flash;
flash = Z_Malloc(sizeof(*flash), PU_LEVSPEC, 0);
P_AddThinker(&flash->thinker);
flash->sector = sector;
flash->darktime = fastOrSlow;
flash->brighttime = STROBEBRIGHT;
flash->thinker.function = T_StrobeFlash;
flash->maxlight = sector->lightlevel;
flash->minlight = P_FindMinSurroundingLight(sector, sector->lightlevel);
if (flash->minlight == flash->maxlight)
flash->minlight = 0;
sector->special = 0; // nothing special about it during gameplay
if (!inSync)
flash->count = (P_Random() & 7) + 1;
else
flash->count = 1;
}
示例2: A_SPosAttack
//
// A_SPosAttack
//
// Sergeant attack.
//
void A_SPosAttack(actionargs_t *actionargs)
{
Mobj *actor = actionargs->actor;
int i, bangle, slope;
if (!actor->target)
return;
S_StartSound(actor, sfx_shotgn);
A_FaceTarget(actionargs);
bangle = actor->angle;
slope = P_AimLineAttack(actor, bangle, MISSILERANGE, 0); // killough 8/2/98
for(i = 0; i < 3; ++i)
{
// haleyjd 08/05/04: use new function
int angle = bangle + (P_SubRandom(pr_sposattack) << 20);
int damage = ((P_Random(pr_sposattack) % 5) + 1) * 3;
P_LineAttack(actor, angle, MISSILERANGE, slope, damage);
}
}
示例3: A_Punch
//
// A_Punch
//
void A_Punch (AActor *mo)
{
angle_t angle;
int damage;
int slope;
player_t *player = mo->player;
damage = (P_Random (player->mo)%10+1)<<1;
if (player->powers[pw_strength])
damage *= 10;
angle = player->mo->angle;
angle += P_RandomDiff(player->mo) << 18;
// [SL] 2011-07-12 - Move players and sectors back to their positions when
// this player hit the fire button clientside.
Unlag::getInstance().reconcile(player->id);
slope = P_AimLineAttack (player->mo, angle, MELEERANGE);
P_LineAttack (player->mo, angle, MELEERANGE, slope, damage);
// [SL] 2011-07-12 - Restore players and sectors to their current position
// according to the server.
Unlag::getInstance().restore(player->id);
// turn to face target
if (linetarget)
{
A_FireSound (player, "player/male/fist");
//S_Sound (player->mo, CHAN_VOICE, "*fist", 1, ATTN_NORM);
player->mo->angle = P_PointToAngle (player->mo->x,
player->mo->y,
linetarget->x,
linetarget->y);
}
}
示例4: G_DeathMatchSpawnPlayer
void G_DeathMatchSpawnPlayer (int playernum)
{
int i,j;
int selections;
selections = deathmatch_p - deathmatchstarts;
if (selections < 4)
I_Error ("Only %i deathmatch spots, 4 required", selections);
for (j=0 ; j<20 ; j++)
{
i = P_Random()%selections;
if (G_CheckSpot (playernum, &deathmatchstarts[i]) )
{
deathmatchstarts[i].type = playernum+1;
P_SpawnPlayer (&deathmatchstarts[i]);
return;
}
}
/* no good spot, so the player will probably get stuck */
P_SpawnPlayer (&playerstarts[playernum]);
}
示例5: A_TroopAttack
//
// A_TroopAttack
//
// Imp attack.
//
void A_TroopAttack(actionargs_t *actionargs)
{
Mobj *actor = actionargs->actor;
if(!actor->target)
return;
A_FaceTarget(actionargs);
if(P_CheckMeleeRange(actor))
{
int damage;
S_StartSound(actor, sfx_claw);
damage = (P_Random(pr_troopattack)%8+1)*3;
P_DamageMobj(actor->target, actor, actor, damage, MOD_HIT);
}
else
{
// launch a missile
P_SpawnMissile(actor, actor->target, E_SafeThingType(MT_TROOPSHOT),
actor->z + DEFAULTMISSILEZ);
}
}
示例6: A_BFGSpray
void A_BFGSpray(mobj_t* mo)
{
int i;
int j;
int damage;
angle_t an;
// offset angles from its attack angle
for(i = 0; i < 40; i++)
{
an = mo->angle - ANG90/2 + ANG90/40*i;
// mo->target is the originator (player) of the missile
//
// [kex] add 1 to distance so autoaim can be forced
//
P_AimLineAttack(mo->target, an, 0, ATTACKRANGE + 1);
if(!linetarget)
continue;
//
// [d64] shift linetarget height by 1 instead of 2
//
P_SpawnMobj(linetarget->x, linetarget->y,
linetarget->z + (linetarget->height >> 1), MT_BFGSPREAD);
damage = 0;
for(j = 0; j < 15; j++)
damage += (P_Random() & 7) + 1;
P_DamageMobj(linetarget, mo->target, mo->target, damage);
}
A_FadeAlpha(mo);
}
示例7: EV_FlickerLight
//
// EV_FlickerLight
//
// haleyjd 01/16/07:
// Parameterized flickering light effect. Changes between maxval and minval
// at a randomized time period between 0.2 and 1.8 seconds (7 to 64 tics).
// Uses the normal lightflash thinker.
//
int EV_FlickerLight(line_t *line, int tag, int maxval, int minval)
{
LightFlashThinker *flash;
int i, rtn = 0;
bool backside = false;
if(line && tag == 0)
{
if(!line->backsector)
return rtn;
i = line->backsector - sectors;
backside = true;
goto dobackside;
}
for(i = -1; (i = P_FindSectorFromTag(tag, i)) >= 0;)
{
dobackside:
rtn = 1;
flash = new LightFlashThinker;
flash->addThinker();
flash->sector = §ors[i];
flash->maxlight = maxval;
flash->minlight = minval;
flash->maxtime = 64;
flash->mintime = 7;
flash->count = (P_Random(pr_lights) & flash->maxtime) + 1;
flash->sector->lightlevel = flash->maxlight;
if(backside)
return rtn;
}
return rtn;
}
示例8: P_SpawnStrobeFlash
//
// P_SpawnStrobeFlash
//
// Spawns a blinking light thinker
//
// Passed the sector that spawned the thinker, speed of blinking
// and whether blinking is to by syncrhonous with other sectors
//
// Returns nothing
//
void P_SpawnStrobeFlash(sector_t *sector, int fastOrSlow, int inSync)
{
StrobeThinker *flash;
flash = new StrobeThinker;
flash->addThinker();
flash->sector = sector;
flash->darktime = fastOrSlow;
flash->brighttime = STROBEBRIGHT;
flash->maxlight = sector->lightlevel;
flash->minlight = P_FindMinSurroundingLight(sector, sector->lightlevel);
if(flash->minlight == flash->maxlight)
flash->minlight = 0;
// nothing special about it during gameplay
sector->special &= ~31; //jff 3/14/98 clear non-generalized sector type
if(!inSync)
flash->count = (P_Random(pr_lights)&7)+1;
else
flash->count = 1;
}
示例9: switch
//.........这里部分代码省略.........
plat->type = type;
plat->sector = sec;
plat->sector->floordata = plat; //jff 2/23/98 multiple thinkers
plat->thinker.function = T_PlatRaise;
plat->crush = false;
plat->tag = line->tag;
//jff 1/26/98 Avoid raise plat bouncing a head off a ceiling and then
//going down forever -- default low to plat height when triggered
plat->low = sec->floorheight;
// set up plat according to type
switch(type)
{
case raiseToNearestAndChange:
plat->speed = PLATSPEED/2;
sec->floorpic = sides[line->sidenum[0]].sector->floorpic;
plat->high = P_FindNextHighestFloor(sec,sec->floorheight);
plat->wait = 0;
plat->status = up;
sec->special = 0;
//jff 3/14/98 clear old field as well
sec->oldspecial = 0;
S_StartSound((mobj_t *)&sec->soundorg,sfx_stnmov);
break;
case raiseAndChange:
plat->speed = PLATSPEED/2;
sec->floorpic = sides[line->sidenum[0]].sector->floorpic;
plat->high = sec->floorheight + amount*FRACUNIT;
plat->wait = 0;
plat->status = up;
S_StartSound((mobj_t *)&sec->soundorg,sfx_stnmov);
break;
case downWaitUpStay:
plat->speed = PLATSPEED * 4;
plat->low = P_FindLowestFloorSurrounding(sec);
if (plat->low > sec->floorheight)
plat->low = sec->floorheight;
plat->high = sec->floorheight;
plat->wait = 35*PLATWAIT;
plat->status = down;
S_StartSound((mobj_t *)&sec->soundorg,sfx_pstart);
break;
case blazeDWUS:
plat->speed = PLATSPEED * 8;
plat->low = P_FindLowestFloorSurrounding(sec);
if (plat->low > sec->floorheight)
plat->low = sec->floorheight;
plat->high = sec->floorheight;
plat->wait = 35*PLATWAIT;
plat->status = down;
S_StartSound((mobj_t *)&sec->soundorg,sfx_pstart);
break;
case perpetualRaise:
plat->speed = PLATSPEED;
plat->low = P_FindLowestFloorSurrounding(sec);
if (plat->low > sec->floorheight)
plat->low = sec->floorheight;
plat->high = P_FindHighestFloorSurrounding(sec);
if (plat->high < sec->floorheight)
plat->high = sec->floorheight;
plat->wait = 35*PLATWAIT;
plat->status = P_Random(pr_plats)&1;
S_StartSound((mobj_t *)&sec->soundorg,sfx_pstart);
break;
case toggleUpDn: //jff 3/14/98 add new type to support instant toggle
plat->speed = PLATSPEED; //not used
plat->wait = 35*PLATWAIT; //not used
plat->crush = true; //jff 3/14/98 crush anything in the way
// set up toggling between ceiling, floor inclusive
plat->low = sec->ceilingheight;
plat->high = sec->floorheight;
plat->status = down;
break;
default:
break;
}
P_AddActivePlat(plat); // add plat to list of active plats
}
return rtn;
}
示例10: A_WeaponSetCtr
//
// A_WeaponSetCtr
//
// Sets the value of the indicated counter variable for the thing.
// Can perform numerous operations -- this is more like a virtual
// machine than a codepointer ;)
//
// args[0] : counter # to set
// args[1] : value to utilize
// args[2] : operation to perform
//
void A_WeaponSetCtr(Mobj *mo)
{
int cnum;
int value;
int specialop;
int *counter;
player_t *player;
pspdef_t *pspr;
if(!(player = mo->player))
return;
pspr = &(player->psprites[player->curpsprite]);
cnum = E_ArgAsInt(pspr->state->args, 0, 0);
value = E_ArgAsInt(pspr->state->args, 1, 0);
specialop = E_ArgAsKwd(pspr->state->args, 2, &weapsetkwds, 0);
switch(cnum)
{
case 0:
case 1:
case 2:
counter = &(player->weaponctrs[player->readyweapon][cnum]); break;
default:
return;
}
switch(specialop)
{
case CPOP_ASSIGN:
*counter = value; break;
case CPOP_ADD:
*counter += value; break;
case CPOP_SUB:
*counter -= value; break;
case CPOP_MUL:
*counter *= value; break;
case CPOP_DIV:
if(value) // don't divide by zero
*counter /= value;
break;
case CPOP_MOD:
if(value > 0) // only allow modulus by positive values
*counter %= value;
break;
case CPOP_AND:
*counter &= value; break;
case CPOP_ANDNOT:
*counter &= ~value; break; // compound and-not operation
case CPOP_OR:
*counter |= value; break;
case CPOP_XOR:
*counter ^= value; break;
case CPOP_RND:
*counter = P_Random(pr_weapsetctr); break;
case CPOP_RNDMOD:
if(value > 0)
*counter = P_Random(pr_weapsetctr) % value; break;
case CPOP_SHIFTLEFT:
*counter <<= value; break;
case CPOP_SHIFTRIGHT:
*counter >>= value; break;
default:
break;
}
}
示例11: A_WeaponCtrOp
//
// A_WeaponCtrOp
//
// Sets the value of the indicated counter variable for the weapon
// using two (possibly the same) counters as operands.
//
// args[0] : counter operand #1
// args[1] : counter operand #2
// args[2] : counter destination
// args[3] : operation to perform
//
void A_WeaponCtrOp(Mobj *mo)
{
player_t *player;
pspdef_t *pspr;
int c_oper1_num;
int c_oper2_num;
int c_dest_num;
int specialop;
int *c_oper1, *c_oper2, *c_dest;
if(!(player = mo->player))
return;
pspr = &(player->psprites[player->curpsprite]);
c_oper1_num = E_ArgAsInt(pspr->state->args, 0, 0);
c_oper2_num = E_ArgAsInt(pspr->state->args, 1, 0);
c_dest_num = E_ArgAsInt(pspr->state->args, 2, 0);
specialop = E_ArgAsKwd(pspr->state->args, 3, &weapctropkwds, 0);
switch(c_oper1_num)
{
case 0:
case 1:
case 2:
c_oper1 = &(player->weaponctrs[player->readyweapon][c_oper1_num]);
break;
default:
return;
}
switch(c_oper2_num)
{
case 0:
case 1:
case 2:
c_oper2 = &(player->weaponctrs[player->readyweapon][c_oper2_num]);
break;
default:
return;
}
switch(c_dest_num)
{
case 0:
case 1:
case 2:
c_dest = &(player->weaponctrs[player->readyweapon][c_dest_num]); break;
default:
return;
}
switch(specialop)
{
case CPOP_ADD:
*c_dest = *c_oper1 + *c_oper2; break;
case CPOP_SUB:
*c_dest = *c_oper1 - *c_oper2; break;
case CPOP_MUL:
*c_dest = *c_oper1 * *c_oper2; break;
case CPOP_DIV:
if(c_oper2) // don't divide by zero
*c_dest = *c_oper1 / *c_oper2;
break;
case CPOP_MOD:
if(*c_oper2 > 0) // only allow modulus by positive values
*c_dest = *c_oper1 % *c_oper2;
break;
case CPOP_AND:
*c_dest = *c_oper1 & *c_oper2; break;
case CPOP_OR:
*c_dest = *c_oper1 | *c_oper2; break;
case CPOP_XOR:
*c_dest = *c_oper1 ^ *c_oper2; break;
case CPOP_DAMAGE:
// do a HITDICE-style calculation
if(*c_oper2 > 0) // the modulus must be positive
*c_dest = *c_oper1 * ((P_Random(pr_weapsetctr) % *c_oper2) + 1);
break;
case CPOP_SHIFTLEFT:
*c_dest = *c_oper1 << *c_oper2; break;
case CPOP_SHIFTRIGHT:
*c_dest = *c_oper1 >> *c_oper2; break;
// unary operations (c_oper2 is unused for these)
case CPOP_ABS:
*c_dest = abs(*c_oper1); break;
case CPOP_NEGATE:
//.........这里部分代码省略.........
示例12: A_CounterOp
//
// A_CounterOp
//
// Sets the value of the indicated counter variable for the thing
// using two (possibly the same) counters as operands.
//
// args[0] : counter operand #1
// args[1] : counter operand #2
// args[2] : counter destination
// args[3] : operation to perform
//
void A_CounterOp(Mobj *mo)
{
int c_oper1_num, c_oper2_num, c_dest_num, specialop;
int *c_oper1, *c_oper2, *c_dest;
c_oper1_num = E_ArgAsInt(mo->state->args, 0, 0);
c_oper2_num = E_ArgAsInt(mo->state->args, 1, 0);
c_dest_num = E_ArgAsInt(mo->state->args, 2, 0);
specialop = E_ArgAsKwd(mo->state->args, 3, &cpopkwds, 0);
if(c_oper1_num < 0 || c_oper1_num >= NUMMOBJCOUNTERS)
return; // invalid
c_oper1 = &(mo->counters[c_oper1_num]);
if(c_oper2_num < 0 || c_oper2_num >= NUMMOBJCOUNTERS)
return; // invalid
c_oper2 = &(mo->counters[c_oper2_num]);
if(c_dest_num < 0 || c_dest_num >= NUMMOBJCOUNTERS)
return; // invalid
c_dest = &(mo->counters[c_dest_num]);
switch(specialop)
{
case CPOP_ADD:
*c_dest = *c_oper1 + *c_oper2; break;
case CPOP_SUB:
*c_dest = *c_oper1 - *c_oper2; break;
case CPOP_MUL:
*c_dest = *c_oper1 * *c_oper2; break;
case CPOP_DIV:
if(c_oper2) // don't divide by zero
*c_dest = *c_oper1 / *c_oper2;
break;
case CPOP_MOD:
if(*c_oper2 > 0) // only allow modulus by positive values
*c_dest = *c_oper1 % *c_oper2;
break;
case CPOP_AND:
*c_dest = *c_oper1 & *c_oper2; break;
case CPOP_OR:
*c_dest = *c_oper1 | *c_oper2; break;
case CPOP_XOR:
*c_dest = *c_oper1 ^ *c_oper2; break;
case CPOP_DAMAGE:
// do a HITDICE-style calculation
if(*c_oper2 > 0) // the modulus must be positive
*c_dest = *c_oper1 * ((P_Random(pr_setcounter) % *c_oper2) + 1);
break;
case CPOP_SHIFTLEFT:
*c_dest = *c_oper1 << *c_oper2; break;
case CPOP_SHIFTRIGHT:
*c_dest = *c_oper1 >> *c_oper2; break;
// unary operations (c_oper2 is unused for these)
case CPOP_ABS:
*c_dest = abs(*c_oper1); break;
case CPOP_NEGATE:
*c_dest = -(*c_oper1); break;
case CPOP_NOT:
*c_dest = !(*c_oper1); break;
case CPOP_INVERT:
*c_dest = ~(*c_oper1); break;
default:
break;
}
}
示例13: EV_DoPlat
//.........这里部分代码省略.........
if (line)
sec->floorpic = sides[line->sidenum[0]].sector->floorpic;
if (change == 1)
sec->special = 0; // Stop damage and other stuff, if any
}
switch (type)
{
case DPlat::platRaiseAndStay:
plat->m_High = P_FindNextHighestFloor (sec, sec->floorheight);
plat->m_Status = DPlat::midup;
plat->PlayPlatSound();
break;
case DPlat::platUpByValue:
case DPlat::platUpByValueStay:
plat->m_High = sec->floorheight + height;
plat->m_Status = DPlat::midup;
plat->PlayPlatSound();
break;
case DPlat::platDownByValue:
plat->m_Low = sec->floorheight - height;
plat->m_Status = DPlat::middown;
plat->PlayPlatSound();
break;
case DPlat::platDownWaitUpStay:
plat->m_Low = P_FindLowestFloorSurrounding (sec) + lip*FRACUNIT;
if (plat->m_Low > sec->floorheight)
plat->m_Low = sec->floorheight;
plat->m_High = sec->floorheight;
plat->m_Status = DPlat::down;
plat->PlayPlatSound();
break;
case DPlat::platUpWaitDownStay:
plat->m_High = P_FindHighestFloorSurrounding (sec);
if (plat->m_High < sec->floorheight)
plat->m_High = sec->floorheight;
plat->m_Status = DPlat::up;
plat->PlayPlatSound();
break;
case DPlat::platPerpetualRaise:
plat->m_Low = P_FindLowestFloorSurrounding (sec) + lip*FRACUNIT;
if (plat->m_Low > sec->floorheight)
plat->m_Low = sec->floorheight;
plat->m_High = P_FindHighestFloorSurrounding (sec);
if (plat->m_High < sec->floorheight)
plat->m_High = sec->floorheight;
plat->m_Status = P_Random () & 1 ? DPlat::down : DPlat::up;
plat->PlayPlatSound();
break;
case DPlat::platToggle: //jff 3/14/98 add new type to support instant toggle
plat->m_Crush = false; //jff 3/14/98 crush anything in the way
// set up toggling between ceiling, floor inclusive
plat->m_Low = sec->ceilingheight;
plat->m_High = sec->floorheight;
plat->m_Status = DPlat::down;
// SN_StartSequence (sec, "Silence");
break;
case DPlat::platDownToNearestFloor:
plat->m_Low = P_FindNextLowestFloor (sec, sec->floorheight) + lip*FRACUNIT;
plat->m_Status = DPlat::down;
plat->m_High = sec->floorheight;
plat->PlayPlatSound();
break;
case DPlat::platDownToLowestCeiling:
plat->m_Low = P_FindLowestCeilingSurrounding (sec);
plat->m_High = sec->floorheight;
if (plat->m_Low > sec->floorheight)
plat->m_Low = sec->floorheight;
plat->m_Status = DPlat::down;
plat->PlayPlatSound();
break;
default:
break;
}
if (manual)
return rtn;
}
return rtn;
}
示例14: P_SubRandom
//
// P_SubRandom
//
// haleyjd 08/05/04: This function eliminates the need to use
// temporary variables everywhere in order to subtract two random
// values without incurring order of evaluation problems.
//
int P_SubRandom(pr_class_t pr_class)
{
int temp = P_Random(pr_class);
return (temp - P_Random(pr_class));
}
示例15: A_CorpseExplode
void C_DECL A_CorpseExplode(mobj_t* actor)
{
int i, n;
mobj_t* mo;
for(i = (P_Random() & 3) + 3; i; i--)
{
if((mo = P_SpawnMobj(MT_CORPSEBIT, actor->origin, P_Random() << 24, 0)))
{
P_MobjChangeState(mo, P_GetState(mo->type, SN_SPAWN) + (P_Random() % 3));
mo->mom[MZ] = FIX2FLT((P_Random() & 7) + 5) * .75f;
mo->mom[MX] = FIX2FLT((P_Random() - P_Random()) << 10);
mo->mom[MY] = FIX2FLT((P_Random() - P_Random()) << 10);
}
}
// Spawn a skull.
if((mo = P_SpawnMobj(MT_CORPSEBIT, actor->origin, P_Random() << 24, 0)))
{
P_MobjChangeState(mo, S_CORPSEBIT_4);
n = (P_Random() & 7) + 5;
mo->mom[MZ] = FIX2FLT(n) * .75f;
mo->mom[MX] = FIX2FLT((P_Random() - P_Random()) << 10);
mo->mom[MY] = FIX2FLT((P_Random() - P_Random()) << 10);
S_StartSound(SFX_FIRED_DEATH, mo);
}
P_MobjRemove(actor, false);
}