Пример #1
0
	Vector3D Vector3D::GenerateRandomVector(Vector3D & i_Min, Vector3D & i_Max)
	{
		return Vector3D(
			RandInRange(i_Min.getX(), i_Max.getX()),
			RandInRange(i_Min.getY(), i_Max.getY()),
			RandInRange(i_Min.getZ(), i_Max.getZ()));
	}
Пример #2
0
Vector3Df AABoundingBox::GetRandomPosInside() const
{
    return Vector3Df(
               (float)RandInRange(m_min.x, m_max.x),
               (float)RandInRange(m_min.y, m_max.y),
               (float)RandInRange(m_min.z, m_max.z));
}
inline void ShotGun::ShootAt(Vector2D pos)
{ 
  if (NumRoundsRemaining() > 0 && isReadyForNextShot())
  {
    //a shotgun cartridge contains lots of tiny metal balls called pellets. 
    //Therefore, every time the shotgun is discharged we have to calculate
    //the spread of the pellets and add one for each trajectory
    for (int b=0; b<m_iNumBallsInShell; ++b)
    {
      //determine deviation from target using a bell curve type distribution
      double deviation = RandInRange(0, m_dSpread) + RandInRange(0, m_dSpread) - m_dSpread;

      Vector2D AdjustedTarget = pos - m_pOwner->Pos();
 
      //rotate the target vector by the deviation
      Vec2DRotateAroundOrigin(AdjustedTarget, deviation);
 
      //add a pellet to the game world
      m_pOwner->GetWorld()->AddShotGunPellet(m_pOwner, AdjustedTarget + m_pOwner->Pos());

    }

    m_iNumRoundsLeft--;

    UpdateTimeWeaponIsNextAvailable();

    //add a trigger to the game so that the other bots can hear this shot
    //(provided they are within range)
    m_pOwner->GetWorld()->GetMap()->AddSoundTrigger(m_pOwner, script->GetDouble("ShotGun_SoundRange"));
  }
}
Пример #4
0
void PrepareForKickOff::Enter(BallTeam* team)
{
    //reset key player pointers
    team->SetControllingPlayer(NULL);
    team->SetSupportingPlayer(NULL);
    team->SetReceiver(NULL);
    team->SetPlayerClosestToBall(NULL);

    int color = team->GetGame()->GetScored();
    if(color == BallTeam::blue)
        printf("blue get scored\n");
    else
        printf("red get scored\n");
    if(team->Color() == BallTeam::blue){
        if(team->GetGame()->GetScored() == BallTeam::blue){
            const int BlueRegions[TeamSize] = {1,6,8,3,5};
            ChangePlayerHomeRegions(team, BlueRegions);
        }
        else {//red team get score
            const int BlueRegions[TeamSize] = {16,20,23,21,13};
            ChangePlayerHomeRegions(team, BlueRegions);
        }
    }
    else //red team
    {
        if(team->GetGame()->GetScored() == BallTeam::red){
            const int RedRegions[TeamSize] = {16,20,23,21,13};
            ChangePlayerHomeRegions(team, RedRegions);
        }
        else{
            const int RedRegions[TeamSize] = {1,6,8,3,5};
            ChangePlayerHomeRegions(team, RedRegions);
        }
    }
    team->UpdateTargetsOfWaitingPlayers();
    if(team->GetGame()->GetScored() == BallTeam::blue) {
        double x = team->GetGame()->PlayingArea()->Left();
        double top = team->GetGame()->PlayingArea()->Top();
        double y = RandInRange(-top, top);
        team->GetGame()->GetBall()->PlaceAtPosition(Vector2D(x,y));
    }
    else if(team->GetGame()->GetScored() == BallTeam::red) 
    {
        double x = team->GetGame()->PlayingArea()->Right();
        double top = team->GetGame()->PlayingArea()->Top();
        double y = RandInRange(-top, top);
        team->GetGame()->GetBall()->PlaceAtPosition(Vector2D(x,y));
    }

    if(team->GetGame()->GetScored() != team->Color()){
        PlayerBase* it = team->GetPreparePlayer();
        FieldPlayer* plyr = static_cast<FieldPlayer*>(it);
        plyr->GetFSM()->ChangeState(ChaseBall::Instance());
        printf("I let player:%d to get ball\n",plyr->ID());
        //getchar();
    }

}
Пример #5
0
std::list<cocos2d::Point> Path::CreateRandomPath(int   NumWaypoints,
										   double MinX,
										   double MinY,
										   double MaxX,
										   double MaxY)
{
	m_WayPoints.clear();

	double midX = (MaxX+MinX)/2.0;
	double midY = (MaxY+MinY)/2.0;

	double smaller = MIN(midX, midY);

	double spacing = TwoPi/(double)NumWaypoints;

	for (int i=0; i<NumWaypoints; ++i)
	{
		double RadialDist = RandInRange(smaller*0.2f, smaller);

		cocos2d::Point temp(RadialDist, 0.0f);

		Vec2DRotateAroundOrigin(temp, i*spacing);

		temp.x += midX; temp.y += midY;

		m_WayPoints.push_back(temp);

	}

	curWaypoint = m_WayPoints.begin();

	return m_WayPoints;
}
Пример #6
0
//---------------------------- AddNoiseToAim ----------------------------------
//
//  adds a random deviation to the firing angle not greater than m_dAimAccuracy 
//  rads
//-----------------------------------------------------------------------------
void Raven_WeaponSystem::AddNoiseToAim(Vector2D& AimingPos)const
{
	Vector2D toPos = AimingPos - m_pOwner->Pos();

	Vec2DRotateAroundOrigin(toPos, RandInRange(-m_dAimAccuracy, m_dAimAccuracy));

	AimingPos = toPos + m_pOwner->Pos();
}
Пример #7
0
void MeshInstance::UpdateObjects()
{
	float gravityFactor = 1.0f;
	float gravityForce = 0.001f;
	Vector gravity = -m_position;
	gravity = gravity.scalar(gravityForce, gravity);

	// We have a basic factor of 1.0, so if the object gets beyond a certain distance
	// we then apply the gravity as a factor of its distance so the force to
	// move in is even greater.  This is already happening given how the gravity is
	// calculated, but with this extra factor, it reduces the chance of an object hitting
	// the equilibrium boundary where it just sits on the edge that is an even match of
	// its velocity vs the gravity pulling it in.
	if( m_position.Length() > 8.0f ){
		gravityFactor *= m_position.Length();
	}

	gravity = gravity.scalar(gravityFactor, gravity);
	
	// To smooth out movement, allow the dirVector to move the object in
	// one direction at least for more than 1 tick, reduces the jitter look of
	// the movement
	if(RandInRange(-1.0f,1.0f) >=0.0f){
		m_dirVector.x = RandInRange(-.1f,.1f);

		m_dirVector.y = RandInRange(-.1f,.1f);

		m_dirVector.z = RandInRange(-.1f,.1f);
	}


	m_position.x += m_dirVector.x;

	m_position.y += m_dirVector.y;

	m_position.z += m_dirVector.z;

	// Apply gravity
	m_position += gravity;
	
}
Пример #8
0
void 
BaseAI::SetRandDestforRoam(const vector2df curPos, vector3df &dst, 
						   const f32 range_roam)const
{
	irr::core::vector3df dest;
	dest.Z = 0.0f;
	dest.X = (f32)RandInRange(-1,1);
	dest.Y = (f32)RandInRange(-1,1);
	//·£´ýÀ¸·Î ¹æÇâ unitº¤Å͸¦ ±¸ÇÏ°í
	dest.normalize();

	//¹üÀ§ ¸¸Å­ °öÇÑ´Ù.
	dest = dest*range_roam;

	//ÇöÀç Á»ºñ À§Ä¡¸¦ ¹Ý¿µÇÑ´Ù.
	dest.X += curPos.X;
	dest.Y += curPos.Y;

	//°öÇØÁø ¹üÀ§ °ªÀ» m_VecRoamDest ¿¡ ÀúÀåÇÑ´Ù.
	dst.X = dest.X;
	dst.Y = dest.Y;
}
Пример #9
0
void MeshInstance::Allocate()
{
	m_position.x = RandInRange(-.1f,.1f);
	m_position.y = RandInRange(-.1f,.1f);
	m_position.z = RandInRange(-.1f,.1f);

	m_dirVector.x = RandInRange(-.1f,.1f);
	m_dirVector.y = RandInRange(-.1f,.1f);
	m_dirVector.z = RandInRange(-.1f,.1f);

}
Пример #10
0
bool TimeCount::isReadyOK()
{
	if (isEqual(0.0, m_dUpdatePeriod)) return true;

	if (m_dUpdatePeriod < 0)		   return false;

	DWORD CurrentTime = timeGetTime();

	static const double UpdatePeriodVariator = 10.0;

	if (CurrentTime >= m_dwNextUpdateTime)
	{
		m_dwNextUpdateTime = (DWORD)(CurrentTime + m_dUpdatePeriod + RandInRange(-UpdatePeriodVariator, UpdatePeriodVariator));

		return true;
	}

	return false;
}
Пример #11
0
FindWorkGoal::FindWorkGoal(SHumanComponent* pOwner)
	: Goal<SHumanComponent>(pOwner, GT_FindWork)
{
	m_fInterestingJobCoef = RandInRange(0.3f, 1.0f);
  m_fLookForPaymentCoef = RandInRange(0.3f, 1.0f);
}