本文整理汇总了C++中d_rand函数的典型用法代码示例。如果您正苦于以下问题:C++ d_rand函数的具体用法?C++ d_rand怎么用?C++ d_rand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了d_rand函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FixDiv
void CShrapnel::Move (void)
{
fix xSpeed = FixDiv (m_info.xSpeed, I2X (25) / 1000);
CFixVector vOffs;
time_t nTicks;
if ((nTicks = gameStates.app.nSDLTicks - m_info.tUpdate) < 25)
return;
xSpeed = (fix) (xSpeed / gameStates.gameplay.slowmo [0].fSpeed);
for (; nTicks >= 25; nTicks -= 25) {
if (--(m_info.nTurn))
vOffs = m_info.vOffs;
else {
m_info.nTurn = ((m_info.xTTL > I2X (1) / 2) ? 2 : 4) + d_rand () % 4;
vOffs = m_info.vDir;
vOffs [X] = FixMul (vOffs [X], 2 * d_rand ());
vOffs [Y] = FixMul (vOffs [Y], 2 * d_rand ());
vOffs [Z] = FixMul (vOffs [Z], 2 * d_rand ());
CFixVector::Normalize (vOffs);
m_info.vOffs = vOffs;
}
vOffs *= xSpeed;
m_info.vPos += vOffs;
}
if (m_info.nSmoke >= 0)
particleManager.SetPos (m_info.nSmoke, &m_info.vPos, NULL, -1);
m_info.tUpdate = gameStates.app.nSDLTicks - nTicks;
}
示例2: DoAIRobotHit
// --------------------------------------------------------------------------------------------------------------------
// If a hiding robot gets bumped or hit, he decides to find another hiding place.
void DoAIRobotHit (CObject *objP, int nType)
{
int r;
if (objP->info.controlType != CT_AI)
return;
if ((nType != PA_WEAPON_ROBOT_COLLISION) && (nType != PA_PLAYER_COLLISION))
return;
if (objP->cType.aiInfo.behavior != AIB_STILL)
return;
r = d_rand ();
// Attack robots (eg, green guy) shouldn't have behavior = still.
//Assert (ROBOTINFO (objP->info.nId).attackType == 0);
// 1/8 time, charge CPlayerData, 1/4 time create path, rest of time, do nothing
if (r < 4096) {
CreatePathToPlayer (objP, 10, 1);
objP->cType.aiInfo.behavior = AIB_STATION;
objP->cType.aiInfo.nHideSegment = objP->info.nSegment;
gameData.ai.localInfo [objP->Index ()].mode = AIM_CHASE_OBJECT;
}
else if (r < 4096 + 8192) {
CreateNSegmentPath (objP, d_rand () / 8192 + 2, -1);
gameData.ai.localInfo [objP->Index ()].mode = AIM_FOLLOW_PATH;
}
}
示例3: SeismicDisturbanceFrame
void SeismicDisturbanceFrame (void)
{
if (gameStates.gameplay.seismic.nShakeFrequency) {
if (((gameStates.gameplay.seismic.nStartTime < gameData.time.xGame) &&
(gameStates.gameplay.seismic.nEndTime > gameData.time.xGame)) || StartSeismicDisturbance()) {
fix deltaTime = gameData.time.xGame - gameStates.gameplay.seismic.nStartTime;
int fc, rx, rz;
fix h;
fc = abs(deltaTime - (gameStates.gameplay.seismic.nEndTime - gameStates.gameplay.seismic.nStartTime) / 2);
fc /= F1_0 / 16;
if (fc > 16)
fc = 16;
else if (fc == 0)
fc = 1;
gameStates.gameplay.seismic.nVolume += fc;
h = 3 * F1_0 / 16 + (F1_0 * (16 - fc)) / 32;
rx = FixMul(d_rand() - 16384, h);
rz = FixMul(d_rand() - 16384, h);
gameData.objs.console->mType.physInfo.rotVel.p.x += rx;
gameData.objs.console->mType.physInfo.rotVel.p.z += rz;
// Shake the buddy!
if (gameData.escort.nObjNum != -1) {
gameData.objs.objects[gameData.escort.nObjNum].mType.physInfo.rotVel.p.x += rx*4;
gameData.objs.objects[gameData.escort.nObjNum].mType.physInfo.rotVel.p.z += rz*4;
}
// Shake a guided missile!
gameStates.gameplay.seismic.nMagnitude += rx;
}
}
}
示例4: DrawDebrisCorona
void DrawDebrisCorona (CObject *objP)
{
static tRgbaColorf debrisGlow = {0.66f, 0, 0, 1};
static tRgbaColorf markerGlow = {0, 0.66f, 0, 1};
static time_t t0 = 0;
if (objP->info.nType == OBJ_MARKER)
RenderWeaponCorona (objP, &markerGlow, 0.75f, 0, 4, 1, 1, 0);
#if DBG
else if (objP->info.nType == OBJ_DEBRIS) {
#else
else if ((objP->info.nType == OBJ_DEBRIS) && gameOpts->render.nDebrisLife) {
#endif
float h = (float) nDebrisLife [gameOpts->render.nDebrisLife] - X2F (objP->info.xLifeLeft);
if (h < 0)
h = 0;
if (h < 10) {
h = (10 - h) / 20.0f;
if (gameStates.app.nSDLTicks - t0 > 50) {
t0 = gameStates.app.nSDLTicks;
debrisGlow.red = 0.5f + X2F (d_rand () % (I2X (1) / 4));
debrisGlow.green = X2F (d_rand () % (I2X (1) / 4));
}
RenderWeaponCorona (objP, &debrisGlow, h, 5 * objP->info.xSize, 1.5f, 1, LIGHTTRAIL_BLENDMODE, 0);
}
}
}
示例5: start_seismic_disturbance
// Return true if time to start a seismic disturbance.
static int start_seismic_disturbance(void)
{
int rval;
if (Level_shake_duration < 1)
return 0;
rval = (2 * fixmul(d_rand(), Level_shake_frequency)) < FrameTime;
if (rval) {
Seismic_disturbance_start_time = GameTime64;
Seismic_disturbance_end_time = GameTime64 + Level_shake_duration;
if (!Seismic_sound_playing) {
digi_play_sample_looping(Seismic_sound, F1_0, -1, -1);
Seismic_sound_playing = 1;
Next_seismic_sound_time = GameTime64 + d_rand()/2;
}
#ifdef NETWORK
if (Game_mode & GM_MULTI)
multi_send_seismic (Seismic_disturbance_start_time,Seismic_disturbance_end_time);
#endif
}
return rval;
}
示例6: CreateSmallFireballOnObject
void CreateSmallFireballOnObject (CObject *objP, fix size_scale, int bSound)
{
fix size;
CFixVector vPos, vRand;
short nSegment;
vPos = objP->info.position.vPos;
vRand = CFixVector::Random();
vRand *= (objP->info.xSize / 2);
vPos += vRand;
size = FixMul (size_scale, I2X (1) / 2 + d_rand () * 4 / 2);
nSegment = FindSegByPos (vPos, objP->info.nSegment, 1, 0);
if (nSegment != -1) {
CObject *explObjP = /*Object*/CreateExplosion (nSegment, vPos, size, VCLIP_SMALL_EXPLOSION);
if (!explObjP)
return;
AttachObject (objP, explObjP);
if (bSound || (d_rand () < 8192)) {
fix vol = I2X (1) / 2;
if (objP->info.nType == OBJ_ROBOT)
vol *= 2;
audio.CreateObjectSound (SOUND_EXPLODING_WALL, SOUNDCLASS_EXPLOSION, objP->Index (), 0, vol);
}
}
}
示例7: RandomPoint
// --------------------------------------------------------------------------------
// Picks a Random point in a CSegment like so:
// From center, go up to 50% of way towards any of the 8 vertices.
CFixVector CSegment::RandomPoint (void)
{
int nVertex = (d_rand () * MAX_VERTICES_PER_SEGMENT) >> 15;
CFixVector v = gameData.segs.vertices [m_verts [nVertex]] - m_vCenter;
v *= (d_rand ());
return v;
}
示例8: SpitPowerup
//this function is for when the CPlayerData intentionally drops a powerup
//this function is based on DropPowerup()
int SpitPowerup (CObject *spitterP, ubyte id, int seed)
{
short nObject;
CObject *objP;
CFixVector newVelocity, newPos;
tObjTransformation *posP = OBJPOS (spitterP);
#if 0
if ((gameData.app.nGameMode & GM_NETWORK) &&
(gameData.multiplayer.powerupsInMine [(int)id] + PowerupsOnShips (id) >=
gameData.multiplayer.maxPowerupsAllowed [id]))
return -1;
#endif
newVelocity = spitterP->mType.physInfo.velocity + spitterP->info.position.mOrient.FVec() * I2X (SPIT_SPEED);
newVelocity[X] += (d_rand() - 16384) * SPIT_SPEED * 2;
newVelocity[Y] += (d_rand() - 16384) * SPIT_SPEED * 2;
newVelocity[Z] += (d_rand() - 16384) * SPIT_SPEED * 2;
// Give keys zero velocity so they can be tracked better in multi
if (IsMultiGame && (id >= POW_KEY_BLUE) && (id <= POW_KEY_GOLD))
newVelocity.SetZero ();
//there's a piece of code which lets the CPlayerData pick up a powerup if
//the distance between him and the powerup is less than 2 time their
//combined radii. So we need to create powerups pretty far out from
//the player.
newPos = posP->vPos + posP->mOrient.FVec () * spitterP->info.xSize;
if (IsMultiGame && (gameData.multigame.create.nLoc >= MAX_NET_CREATE_OBJECTS))
return (-1);
nObject = CreatePowerup (id, (short) (GetTeam (gameData.multiplayer.nLocalPlayer) + 1), (short) OBJSEG (spitterP), newPos, 1);
if (nObject < 0) {
Int3();
return nObject;
}
objP = OBJECTS + nObject;
objP->mType.physInfo.velocity = newVelocity;
objP->mType.physInfo.drag = 512; //1024;
objP->mType.physInfo.mass = I2X (1);
objP->mType.physInfo.flags = PF_BOUNCE;
objP->rType.vClipInfo.nClipIndex = gameData.objs.pwrUp.info [objP->info.nId].nClipIndex;
objP->rType.vClipInfo.xFrameTime = gameData.eff.vClipP [objP->rType.vClipInfo.nClipIndex].xFrameTime;
objP->rType.vClipInfo.nCurFrame = 0;
if (spitterP == gameData.objs.consoleP)
objP->cType.powerupInfo.nFlags |= PF_SPAT_BY_PLAYER;
switch (objP->info.nId) {
case POW_CONCUSSION_1:
case POW_CONCUSSION_4:
case POW_SHIELD_BOOST:
case POW_ENERGY:
objP->info.xLifeLeft = (d_rand() + I2X (3)) * 64; // Lives for 3 to 3.5 binary minutes (a binary minute is 64 seconds)
if (gameData.app.nGameMode & GM_MULTI)
objP->info.xLifeLeft /= 2;
break;
default:
//if (gameData.app.nGameMode & GM_MULTI)
// objP->info.xLifeLeft = (d_rand() + I2X (3)) * 64; // Lives for 5 to 5.5 binary minutes (a binary minute is 64 seconds)
break;
}
MultiSendWeapons (1);
return nObject;
}
示例9: rock_the_mine_frame
// If a smega missile been detonated, rock the mine!
// This should be called every frame.
// Maybe this should affect all robots, being called when they get their physics done.
void rock_the_mine_frame(void)
{
int i;
for (i=0; i<MAX_SMEGA_DETONATES; i++) {
if (Smega_detonate_times[i] != 0) {
fix delta_time = GameTime64 - Smega_detonate_times[i];
if (!Seismic_sound_playing) {
digi_play_sample_looping(Seismic_sound, F1_0, -1, -1);
Seismic_sound_playing = 1;
Next_seismic_sound_time = GameTime64 + d_rand()/2;
}
if (delta_time < SMEGA_SHAKE_TIME) {
// Control center destroyed, rock the player's ship.
int fc, rx, rz;
// -- fc = abs(delta_time - SMEGA_SHAKE_TIME/2);
// Changed 10/23/95 to make decreasing for super mega missile.
fc = (SMEGA_SHAKE_TIME - delta_time)/2;
fc /= SMEGA_SHAKE_TIME/32;
if (fc > 16)
fc = 16;
if (fc == 0)
fc = 1;
Seismic_tremor_volume += fc;
rx = fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32);
rz = fixmul(d_rand() - 16384, 3*F1_0/16 + (F1_0*(16-fc))/32);
if (FixedStep & EPS20)
{
ConsoleObject->mtype.phys_info.rotvel.x += rx;
ConsoleObject->mtype.phys_info.rotvel.z += rz;
// Shake the buddy!
if (Buddy_objnum != object_none) {
Objects[Buddy_objnum].mtype.phys_info.rotvel.x += rx*4;
Objects[Buddy_objnum].mtype.phys_info.rotvel.z += rz*4;
}
}
// Shake a guided missile!
Seismic_tremor_magnitude += rx;
} else
Smega_detonate_times[i] = 0;
}
}
// Hook in the rumble sound effect here.
}
示例10: setup_func
/* Setup a random function in the given dimensions */
static void setup_func(funcp *p, int di) {
double mn,mx;
double ax[MXDI][2];
int i, j;
p->di = di;
/* Setup random input curve parameters */
/* (This is the one that effects smoothness of function the most) */
for (j = 0; j < di; j++) {
for (mx = 4.0, i = 0; i < MXCHPARAMS; i++, mx *= 0.6) {
p->ip[j][i] = d_rand(-mx, mx);
}
}
/* Setup random shape parameters */
for (j = 0; j < di; j++) {
for (i = 0; i < (1 << di); i++) { /* Initially random */
p->shape[j][i] = d_rand(-0.1, 0.1);
}
}
/* Setup the random output value parameters */
/* First some axis dominant values */
for (i = 0; i < di; i++) {
ax[i][0] = d_rand(0.0, 1.0);
ax[i][1] = ax[i][0] + d_rand(-1.0, 1.0);
}
/* Sum them orthogonally and add indepent terms */
mn = 5.0;
mx = -5.0;
for (i = 0; i < (1 << di); i++) { /* Initially random */
p->op[i] = 0.0;
for (j = 0; j < di; j++) {
if ((1 << j) & i)
p->op[i] += ax[j][1];
else
p->op[i] += ax[j][0];
}
p->op[i] += d_rand(-0.3, 0.3);
if (p->op[i] < mn)
mn = p->op[i];
if (p->op[i] > mx)
mx = p->op[i];
}
for (i = 0; i < (1 << di); i++) { /* Then scale to between 0.0 and 1.0 */
p->op[i] = (p->op[i] - mn)/(mx - mn);
}
}
示例11: I2X
void CObject::RandomBump (fix xScale, fix xForce, bool bSound)
{
fix angle;
angle = (d_rand () - I2X (1) / 4);
mType.physInfo.rotVel [X] += FixMul (angle, xScale);
angle = (d_rand () - I2X (1) / 4);
mType.physInfo.rotVel [Z] += FixMul (angle, xScale);
CFixVector vRand = CFixVector::Random ();
Bump (vRand, xForce);
if (bSound)
audio.CreateObjectSound (SOUND_PLAYER_HIT_WALL, SOUNDCLASS_GENERIC, Index ());
}
示例12: DoSnipeFire
void DoSnipeFire (CObject *objP, tAILocalInfo *ailP)
{
if (ailP->nextActionTime < 0) {
tAIStaticInfo *aiP = &objP->cType.aiInfo;
CreateNSegmentPath (objP, 10 + d_rand () / 2048, OBJSEG (TARGETOBJ));
aiP->nPathLength = (aiP->nHideIndex < 0) ? 0 : SmoothPath (objP, &gameData.ai.routeSegs [aiP->nHideIndex], aiP->nPathLength);
if (d_rand () < 8192)
ailP->mode = AIM_SNIPE_RETREAT_BACKWARDS;
else
ailP->mode = AIM_SNIPE_RETREAT;
ailP->nextActionTime = SNIPE_RETREAT_TIME;
}
}
示例13: do_seismic_stuff
// ---------------------------------------------------------------------------------------
// Do seismic disturbance stuff including the looping sounds with changing volume.
void do_seismic_stuff(void)
{
int stv_save;
stv_save = Seismic_tremor_volume;
Seismic_tremor_magnitude = 0;
Seismic_tremor_volume = 0;
rock_the_mine_frame();
seismic_disturbance_frame();
if (stv_save != 0) {
if (Seismic_tremor_volume == 0) {
digi_stop_looping_sound();
Seismic_sound_playing = 0;
}
if ((GameTime64 > Next_seismic_sound_time) && Seismic_tremor_volume) {
int volume;
volume = Seismic_tremor_volume * 2048;
if (volume > F1_0)
volume = F1_0;
digi_change_looping_volume(volume);
Next_seismic_sound_time = GameTime64 + d_rand()/4 + 8192;
}
}
}
示例14: d_rand
int CShrapnelCloud::Create (CObject* parentObjP, CObject* objP)
{
int i, h = (int) (X2F (parentObjP->info.xSize) * fShrapnelScale [gameOpts->render.effects.nShrapnels] + 0.5);
objP->info.xLifeLeft = 0;
objP->cType.explInfo.nSpawnTime = -1;
objP->cType.explInfo.nDeleteObj = -1;
objP->cType.explInfo.nDeleteTime = -1;
h += d_rand () % h;
if (!CStack<CShrapnel>::Create (h))
return 0;
if (!Grow (h))
return 0;
#pragma omp parallel
{
#pragma omp for
for (i = 0; i < h; i++) {
m_data.buffer [i].Create (parentObjP, objP);
}
}
objP->info.xLifeLeft *= 2;
objP->cType.explInfo.nSpawnTime = -1;
objP->cType.explInfo.nDeleteObj = -1;
objP->cType.explInfo.nDeleteTime = -1;
return 1;
}
示例15: I2X
void CShrapnel::Draw (void)
{
if ((m_info.xTTL > 0) && LoadExplBlast ()) {
fix xSize = I2X (1) / 2 + d_rand () % (I2X (1) / 4);
G3DrawSprite (m_info.vPos, xSize, xSize, bmpExplBlast, NULL, X2F (m_info.xTTL) / X2F (m_info.xLife) / 2, 0, 0);
}
}