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


C++ rand_norm函数代码示例

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


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

示例1: _InitSpecific

void ConfusedMovementGenerator<T>::Initialize(T &unit) {
	const float wander_distance = 11;
	float x, y, z;
	x = unit.GetPositionX();
	y = unit.GetPositionY();
	z = unit.GetPositionZ();

	Map const* map = unit.GetBaseMap();

	i_nextMove = 1;

	bool is_water_ok, is_land_ok;
	_InitSpecific(unit, is_water_ok, is_land_ok);

	for (uint8 idx = 0; idx <= MAX_CONF_WAYPOINTS; ++idx) {
		float wanderX = x + wander_distance * (float) rand_norm()
				- wander_distance / 2;
		float wanderY = y + wander_distance * (float) rand_norm()
				- wander_distance / 2;
		Trinity::NormalizeMapCoord(wanderX);
		Trinity::NormalizeMapCoord(wanderY);

		float new_z = map->GetHeight(wanderX, wanderY, z, true);
		if (new_z > INVALID_HEIGHT
				&& unit.IsWithinLOS(wanderX, wanderY, new_z)) {
			// Don't move in water if we're not already in
			// Don't move on land if we're not already on it either
			bool is_water_now = map->IsInWater(x, y, z);
			bool is_water_next = map->IsInWater(wanderX, wanderY, new_z);
			if ((is_water_now && !is_water_next && !is_land_ok)
					|| (!is_water_now && is_water_next && !is_water_ok)) {
				i_waypoints[idx][0] = idx > 0 ? i_waypoints[idx - 1][0] : x; // Back to previous location
				i_waypoints[idx][1] = idx > 0 ? i_waypoints[idx - 1][1] : y;
				i_waypoints[idx][2] = idx > 0 ? i_waypoints[idx - 1][2] : z;
				continue;
			}

			// Taken from FleeingMovementGenerator
			if (!(new_z - z) || wander_distance / fabs(new_z - z) > 1.0f) {
				i_waypoints[idx][0] = wanderX;
				i_waypoints[idx][1] = wanderY;
				i_waypoints[idx][2] = new_z;
				continue;
			}
		} else // Back to previous location
		{
			i_waypoints[idx][0] = idx > 0 ? i_waypoints[idx - 1][0] : x;
			i_waypoints[idx][1] = idx > 0 ? i_waypoints[idx - 1][1] : y;
			i_waypoints[idx][2] = idx > 0 ? i_waypoints[idx - 1][2] : z;
			continue;
		}
	}

	unit.SetUInt64Value(UNIT_FIELD_TARGET, 0);
	unit.SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
	unit.CastStop();
	unit.StopMoving();
	unit.RemoveUnitMovementFlag(MOVEMENTFLAG_WALKING);
	unit.AddUnitState(UNIT_STAT_CONFUSED);
}
开发者ID:ProjectStarGate,项目名称:StarGate-Plus-EMU,代码行数:60,代码来源:ConfusedMovementGenerator.cpp

示例2: GetRandomPointInCircle

 void GetRandomPointInCircle(float max_rad, float &x, float &y)
 {
     float ang = 2*M_PI * rand_norm();
     float rad = max_rad * sqrt(rand_norm());
     x = rad * cos(ang);
     y = rad * sin(ang);
 }
开发者ID:Archives,项目名称:pwow_scriptdev2,代码行数:7,代码来源:boss_algalon.cpp

示例3: GetRandomPositionOnCircle

// uniformly distribute on the circle
static Position GetRandomPositionOnCircle(Position const& center, float radius)
{
    double angle = rand_norm() * 2.0 * M_PI;
    double relDistance = rand_norm() + rand_norm();
    if (relDistance > 1)
        relDistance = 1 - relDistance;
    return Position(center.GetPositionX() + std::sin(angle)*relDistance*radius, center.GetPositionY() + std::cos(angle)*relDistance*radius, center.GetPositionZ());
}
开发者ID:090809,项目名称:TrinityCore,代码行数:9,代码来源:boss_kelthuzad.cpp

示例4: SummonConservator

 void SummonConservator()
 {
     float x = (rand_norm() * 30.0f) - 15.0f;
     float y = (rand_norm() * 30.0f) - 15.0f;
     Creature *add = DoSpawnCreature(CR_ANCIENT_CONSERVATOR, x, y, 0, 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 2000);
     Unit *target = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 0);
     if(add && target)
         add->AddThreat(target, 1.0f);
 }
开发者ID:leecher228,项目名称:scriptdev2,代码行数:9,代码来源:boss_freya.cpp

示例5: _InitSpecific

void
ConfusedMovementGenerator<T>::Initialize(T &unit)
{
    const float wander_distance = 11;
    float x,y,z;
    x = unit.GetPositionX();
    y = unit.GetPositionY();
    z = unit.GetPositionZ();

    Map const* map = unit.GetBaseMap();

    i_nextMove = 1;

    bool is_water_ok, is_land_ok;
    _InitSpecific(unit, is_water_ok, is_land_ok);

    VMAP::IVMapManager *vMaps = VMAP::VMapFactory::createOrGetVMapManager();

    for (uint8 idx = 0; idx <= MAX_CONF_WAYPOINTS; ++idx)
    {
        const bool isInLoS = vMaps->isInLineOfSight(unit.GetMapId(), x, y, z + 2.0f, i_waypoints[idx][0], i_waypoints[idx][1], z + 2.0f);
        if (isInLoS)
        {
            const float wanderX = wander_distance*rand_norm() - wander_distance/2;
            const float wanderY = wander_distance*rand_norm() - wander_distance/2;
            i_waypoints[idx][0] = x + wanderX;
            i_waypoints[idx][1] = y + wanderY;
        }
        else
        {
            i_waypoints[idx][0] = x;
            i_waypoints[idx][1] = y;
        }

        // prevent invalid coordinates generation
        Quad::NormalizeMapCoord(i_waypoints[idx][0]);
        Quad::NormalizeMapCoord(i_waypoints[idx][1]);

        bool is_water = map->IsInWater(i_waypoints[idx][0],i_waypoints[idx][1],z);
        // if generated wrong path just ignore
        if ((is_water && !is_water_ok) || (!is_water && !is_land_ok))
        {
            i_waypoints[idx][0] = idx > 0 ? i_waypoints[idx-1][0] : x;
            i_waypoints[idx][1] = idx > 0 ? i_waypoints[idx-1][1] : y;
        }

        unit.UpdateGroundPositionZ(i_waypoints[idx][0],i_waypoints[idx][1],z);
        i_waypoints[idx][2] = z;
    }

    unit.SetUInt64Value(UNIT_FIELD_TARGET, 0);
    unit.SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
    unit.CastStop();
    unit.StopMoving();
    unit.RemoveUnitMovementFlag(MOVEMENTFLAG_WALK_MODE);
    unit.addUnitState(UNIT_STAT_CONFUSED);
}
开发者ID:artas,项目名称:quademu,代码行数:57,代码来源:ConfusedMovementGenerator.cpp

示例6: _InitSpecific

void ConfusedMovementGenerator<T>::Initialize(T &unit)
{
    unit.StopMoving();
    float const wander_distance = 2;
    float x = unit.GetPositionX();
    float y = unit.GetPositionY();
    float z = unit.GetPositionZ();

    Map const* map = unit.GetBaseMap();

    i_nextMove = 1;

    bool is_water_ok, is_land_ok;
    _InitSpecific(unit, is_water_ok, is_land_ok);

    for (uint8 idx = 0; idx < MAX_CONF_WAYPOINTS + 1; ++idx)
    {
        float wanderX = x + (wander_distance * (float)rand_norm() - wander_distance/2);
        float wanderY = y + (wander_distance * (float)rand_norm() - wander_distance/2);

        // prevent invalid coordinates generation
        WoWSource::NormalizeMapCoord(wanderX);
        WoWSource::NormalizeMapCoord(wanderY);

        if (unit.IsWithinLOS(wanderX, wanderY, z))
        {
            bool is_water = map->IsInWater(wanderX, wanderY, z);

            if ((is_water && !is_water_ok) || (!is_water && !is_land_ok))
            {
                //! Cannot use coordinates outside our InhabitType. Use the current or previous position.
                wanderX = idx > 0 ? i_waypoints[idx-1][0] : x;
                wanderY = idx > 0 ? i_waypoints[idx-1][1] : y;
            }
        }
        else
        {
            //! Trying to access path outside line of sight. Skip this by using the current or previous position.
            wanderX = idx > 0 ? i_waypoints[idx-1][0] : x;
            wanderY = idx > 0 ? i_waypoints[idx-1][1] : y;
        }

        unit.UpdateAllowedPositionZ(wanderX, wanderY, z);

        //! Positions are fine - apply them to this waypoint
        i_waypoints[idx][0] = wanderX;
        i_waypoints[idx][1] = wanderY;
        i_waypoints[idx][2] = z;
    }

    unit.StopMoving();
    unit.SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
    unit.AddUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_CONFUSED_MOVE);
}
开发者ID:Cailiaock,项目名称:5.4.7-Wow-source,代码行数:54,代码来源:ConfusedMovementGenerator.cpp

示例7: urand

bool ConfusedMovementGenerator<T>::Update(T &unit, const uint32 &diff)
{
    if (unit.HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED | UNIT_STATE_DISTRACTED))
        return true;

    if (i_nextMoveTime.Passed())
    {
        // currently moving, update location
        unit.AddUnitState(UNIT_STATE_CONFUSED_MOVE);

        if (unit.movespline->Finalized())
            i_nextMoveTime.Reset(urand(800, 1500));
 /*    {
            i_nextMove = urand(1, MAX_CONF_WAYPOINTS);
            i_nextMoveTime.Reset(urand(0, 1500-1));     // TODO: check the minimum reset time, should be probably higher
        }*/
    }
    else
    {
        // waiting for next move
        i_nextMoveTime.Update(diff);
        if (i_nextMoveTime.Passed())
        {
            // start moving
            unit.AddUnitState(UNIT_STATE_CONFUSED_MOVE);

         //   ASSERT( i_nextMove <= MAX_CONF_WAYPOINTS );
         //   float x = i_waypoints[i_nextMove][0];
         //   float y = i_waypoints[i_nextMove][1];
         //   float z = i_waypoints[i_nextMove][2];
            float x = i_x + 10.0f * ((float)rand_norm() - 0.5f);
            float y = i_y + 10.0f * ((float)rand_norm() - 0.5f);
            float z = i_z;

            unit.UpdateAllowedPositionZ(x, y, z);

            PathFinderMovementGenerator path(&unit);
            path.setPathLengthLimit(30.0f);
            path.calculate(x, y, z);
            if (path.getPathType() & PATHFIND_NOPATH)
            {
                i_nextMoveTime.Reset(urand(800, 1000));
               return true;
            }
            Movement::MoveSplineInit init(unit);
            // init.MoveTo(x, y, z);
            init.MovebyPath(path.getPath());
            init.SetWalk(true);
            init.Launch();
        }
    }

    return true;
}
开发者ID:Altair69,项目名称:SkyFireEMU,代码行数:54,代码来源:ConfusedMovementGenerator.cpp

示例8: UpdateAI

		void UpdateAI(uint32 diff)
		{
			if( !UpdateVictim() )
				return;

			events.Update(diff);

			if( me->HasUnitState(UNIT_STATE_CASTING) )
				return;

			DoMeleeAttackIfReady();

			switch( events.GetEvent() )
			{
				case 0:
					break;
				case EVENT_MAGIC_PULL:
					{
						Talk(SAY_PULL);
						//me->MonsterTextEmote(TEXT_MAGIC_PULL, 0, true);

						me->CastSpell(me, SPELL_MAGIC_PULL, false);
						events.RepeatEvent(urand(15000,25000));
						events.ScheduleEvent(EVENT_SUMMON_x4, 1500);
					}
					break;
				case EVENT_THUNDERING_STOMP:
					{
						Talk(SAY_STOMP);

						me->CastSpell(me, SPELL_THUNDERING_STOMP, false);
						events.RepeatEvent(urand(10000,20000));
					}
					break;
				case EVENT_SUMMON:
					{
						for( uint8 i=0; i<2; ++i )
						{
							float angle = rand_norm()*2*M_PI;
							me->SummonCreature(NPC_UNSTABLE_SPHERE, me->GetPositionX() + 5.0f*cos(angle), me->GetPositionY() + 5.0f*sin(angle), me->GetPositionZ(), 0.0f, TEMPSUMMON_TIMED_DESPAWN, 18000);
						}
						events.RepeatEvent(2000);
					}
					break;
				case EVENT_SUMMON_x4:
					for( uint8 i=0; i<4; ++i )
					{
						float angle = rand_norm()*2*M_PI;
						me->SummonCreature(NPC_UNSTABLE_SPHERE, me->GetPositionX() + 5.0f*cos(angle), me->GetPositionY() + 5.0f*sin(angle), me->GetPositionZ(), 0.0f, TEMPSUMMON_TIMED_DESPAWN, 18000);
					}
					events.PopEvent();
					break;
			}
		}
开发者ID:GlassFace,项目名称:sunwell,代码行数:54,代码来源:boss_drakos.cpp

示例9: cos

void
RandomMovementGenerator<Creature>::Initialize(Creature &creature)
{
    float x,y,z,z2, wander_distance;
    creature.GetRespawnCoord(x, y, z);
    creature.GetRespawnDist(wander_distance);
    uint32 mapid=creature.GetMapId();

    Map* map = MapManager::Instance().GetMap(mapid, &creature);
    // Initialization is done in bulk. Don’t use vamps for that (4. parameter = false). It is too costly when entering a new map grid
    z2 = map->GetHeight(x,y,z, false);
    if( fabs( z2 - z ) < 5 )
        z = z2;

    i_nextMove = 1;
    i_waypoints[0][0] = x;
    i_waypoints[0][1] = y;
    i_waypoints[0][2] = z;

    bool is_water_ok = creature.isCanSwimOrFly();
    bool is_land_ok  = creature.isCanWalkOrFly();

    for(unsigned int idx=1; idx < MAX_RAND_WAYPOINTS+1; ++idx)
    {
        const float angle = 2*M_PI*rand_norm();
        const float range = wander_distance*rand_norm();

        i_waypoints[idx][0] = x+ range * cos(angle);
        i_waypoints[idx][1] = y+ range * sin(angle);

        // prevent invalid coordinates generation
        MaNGOS::NormalizeMapCoord(i_waypoints[idx][0]);
        MaNGOS::NormalizeMapCoord(i_waypoints[idx][1]);

        bool is_water = map->IsInWater(i_waypoints[idx][0],i_waypoints[idx][1],z);
        // if generated wrong path just ignore
        if( is_water && !is_water_ok || !is_water && !is_land_ok )
        {
            i_waypoints[idx][0] = i_waypoints[idx-1][0];
            i_waypoints[idx][1] = i_waypoints[idx-1][1];
            i_waypoints[idx][2] = i_waypoints[idx-1][2];
            continue;
        }

        // Initialization is done in bulk. Don’t use vamps for that (4. parameter = false). It is too costly when entering a new map grid
        z2 = map->GetHeight(i_waypoints[idx][0],i_waypoints[idx][1],z, false);
        if( fabs( z2 - z ) < 5 )
            z = z2;
        i_waypoints[idx][2] =  z;
    }
    i_nextMoveTime.Reset(urand(0, 10000-1));                // TODO: check the lower bound (it is probably too small)
    creature.StopMoving();
}
开发者ID:Artea,项目名称:mangos-svn,代码行数:53,代码来源:RandomMovementGenerator.cpp

示例10: path

bool ConfusedMovementGenerator<T>::Update(T &unit, const uint32 &diff)
{
    if (unit.HasUnitState(UNIT_STATE_ROOT | UNIT_STATE_STUNNED | UNIT_STATE_DISTRACTED))
        return true;

    if (i_nextMoveTime.Passed())
    {
        // currently moving, update location
        unit.AddUnitState(UNIT_STATE_CONFUSED_MOVE);

        if (unit.movespline->Finalized())
            i_nextMoveTime.Reset(100); // short reset
    }
    else
    {
        // waiting for next move
        i_nextMoveTime.Update(diff);
        if (i_nextMoveTime.Passed())
        {
            // start moving
            unit.AddUnitState(UNIT_STATE_CONFUSED_MOVE);

            float x = i_x + 4.0f*((float)rand_norm() - 0.5f); 
            float y = i_y + 4.0f*((float)rand_norm() - 0.5f);
			float z = i_z;

			Trinity::NormalizeMapCoord(x);	
            Trinity::NormalizeMapCoord(y);

            unit.UpdateAllowedPositionZ(x, y, z);

            if (z <= INVALID_HEIGHT)	
                i_z = unit.GetBaseMap()->GetHeight(unit.GetPhaseMask(), x, y, MAX_HEIGHT) + 2.0f;

            PathFinderMovementGenerator path(&unit);
            path.setPathLengthLimit(20.0f);
            path.setUseStrightPath(false);

            if (!unit.IsWithinLOS(x, y, z) || !path.calculate(x, y, z) || (path.getPathType() & PATHFIND_NOPATH))
            {
                i_nextMoveTime.Reset(100);
                return true;
            }

            Movement::MoveSplineInit init(unit);
            init.MovebyPath(path.getPath());
            init.SetWalk(true); 
            init.Launch();
        }
    }

    return true;
}
开发者ID:Laintime,项目名称:BattleArenas,代码行数:53,代码来源:ConfusedMovementGenerator.cpp

示例11: SummonLashers

 void SummonLashers()
 {
     int i;
     float x,y;
     for(i=0; i<10; ++i)
     {
         x = (rand_norm() * 30.0f) - 15.0f;
         y = (rand_norm() * 30.0f) - 15.0f;
         Creature *lasher = DoSpawnCreature(CR_DETONATING_LASHER, x, y, 0, 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 2000);
         Unit *target = m_creature->SelectAttackingTarget(ATTACKING_TARGET_RANDOM, 0);
         if(lasher && target)
             lasher->AddThreat(target, 1.0f);
     }
 }
开发者ID:leecher228,项目名称:scriptdev2,代码行数:14,代码来源:boss_freya.cpp

示例12: UpdateAI

        void UpdateAI(uint32 diff)
        {
            if (!UpdateVictim())
                return;

            events.Update(diff);
            
            if( me->HasUnitState(UNIT_STATE_CASTING) )
                return;

            switch( events.GetEvent() )
            {
                case 0:
                    break;
                case EVENT_SPELL_SHADOWBOLT:
                    me->CastSpell(me->GetVictim(), SPELL_SHADOWBOLT, false);
                    events.RepeatEvent(urand(4000,5000));
                    break;
                case EVENT_FROST_TOMB:
                    if( Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 0.0f, true) )
                        if( !target->HasAura(SPELL_FROST_TOMB_AURA) )
                        {
                            Talk(SAY_FROST_TOMB_EMOTE, target);
                            Talk(SAY_FROST_TOMB);
                            me->CastSpell(target, SPELL_FROST_TOMB, false);
                            events.RepeatEvent(15000);
                            break;
                        }
                    events.RepeatEvent(1000);
                    break;
                case EVENT_SUMMON_SKELETONS:
                    Talk(SAY_SUMMON_SKELETONS);
                    for (uint8 i = 0; i < 5; ++i)
                    {
                        float dist = rand_norm()*4+3.0f;
                        float angle = rand_norm()*2*M_PI;
                        if( Creature* c = me->SummonCreature(NPC_SKELETON, 156.2f+cos(angle)*dist, 259.1f+sin(angle)*dist, 42.9f, 0, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 20000) )
                            if( Unit* target = c->SelectNearestTarget(250.0f) )
                            {
                                c->AddThreat(target, 5.0f);
                                DoZoneInCombat(c);
                            }
                    }
                    events.PopEvent();
                    break;
            }

            DoMeleeAttackIfReady();
        }
开发者ID:boom8866,项目名称:azerothcore-wotlk,代码行数:49,代码来源:boss_keleseth.cpp

示例13: molten_flameAI

 molten_flameAI(Creature *c) : NullCreatureAI(c)
 {
     float x, y, z;
     me->CastSpell(me,SPELL_MOLTEN_FLAME,true);
     me->GetNearPoint(me, x, y, z, 1.0f, 50.0f, float(M_PI*2*rand_norm()));
     me->GetMotionMaster()->MovePoint(0, x, y, z);
 }
开发者ID:B3NNY,项目名称:TrinityCore,代码行数:7,代码来源:boss_supremus.cpp

示例14: ReceiveEmote

        void ReceiveEmote(Player* player, uint32 emote)
        {
            if (emote == TEXTEMOTE_KISS)
            {
                alreadykissed = true;

                if(urand(0,3) == 0)
                {
                    DoCast(me,SPELL_TRANSFORM,true);
                    me->MonsterSay(SAY_FREED,LANG_UNIVERSAL,player->GetGUID());
                    me->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP);
                }else
                {
                    if (!player->HasAura(SPELL_WARTS_B_GONE))
                    {
                    //FIXME    me->CastSpell(player,SPELL_WARTS);
                    }else
                        player->RemoveAurasDueToSpell(SPELL_WARTS_B_GONE);

                        me->CastSpell(me,SPELL_FROG_LOVE,true);
                        me->GetMotionMaster()->MoveFollow(player,1,float(rand_norm()*2*M_PI));
                }

                me->DespawnOrUnsummon(15000);
            }
        }
开发者ID:dsstest,项目名称:ArkCORE,代码行数:26,代码来源:grizzly_hills.cpp

示例15: UpdateAI

       void UpdateAI(const uint32 uiDiff)
       {
           if (!UpdateVictim())
               return;

           if (uiChargeTimer <= uiDiff)
           {
               chargeing = true;
               float x,y,z;
               me->GetNearPoint(me, x, y, z, 1.0f, 15.0f, float(2 * M_PI * rand_norm()));
               me->GetMotionMaster()->MovePoint(1,x,y,z);

               uiChargeTimer = 15*IN_MILLISECONDS;
           } else uiChargeTimer -= uiDiff;

           if (uiShieldBreakerTimer <= uiDiff)
           {
               DoCastVictim(SPELL_SHIELD_BREAKER);
               uiShieldBreakerTimer = 10*IN_MILLISECONDS;
           } else uiShieldBreakerTimer -= uiDiff;

           if (me->isAttackReady())
           {
               DoCast(me->getVictim(), SPELL_PLAYER_THRUST, true);
               me->resetAttackTimer();
           }

           if (Player* player = Player::GetPlayer(*me,guidAttacker))
                if (!player->HasAura(SPELL_AURA_TOURNAMENT_MOUNT))
                    EnterEvadeMode();
       }
开发者ID:Xavy34,项目名称:GaryMoveOut,代码行数:31,代码来源:icecrown.cpp


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