コード例 #1
0
ファイル: Fleet.cpp プロジェクト: rlane/endless-sky
void Fleet::Place(const System &system, Ship &ship)
{
	// Count the inhabited planets in this system.
	int planets = 0;
	for(const StellarObject &object : system.Objects())
		if(object.GetPlanet() && object.GetPlanet()->HasSpaceport())
			++planets;
	
	// Determine where the fleet is going to or coming from.
	Point center;
	if(planets)
	{
		int index = Random::Int(planets);
		for(const StellarObject &object : system.Objects())
			if(object.GetPlanet() && object.GetPlanet()->HasSpaceport())
				if(!index--)
					center = object.Position();
	}
	
	// Move out a random distance from that object, facing toward it or away.
	center += Angle::Random().Unit() * (Random::Real() * 2. - 1.);
	Point pos = center + Angle::Random().Unit() * Random::Real() * 400.;
	
	double velocity = Random::Real() * ship.MaxVelocity();
	
	ship.SetSystem(&system);
	Angle angle = Angle::Random();
	ship.Place(pos, velocity * angle.Unit(), angle);
}
コード例 #2
0
ファイル: Fleet.cpp プロジェクト: kikotheexile/endless-sky
void Fleet::Place(const System &system, Ship &ship)
{
	// Move out a random distance from that object, facing toward it or away.
	Point pos = ChooseCenter(system) + Angle::Random().Unit() * Random::Real() * 400.;
	
	double velocity = Random::Real() * ship.MaxVelocity();
	
	ship.SetSystem(&system);
	Angle angle = Angle::Random();
	ship.Place(pos, velocity * angle.Unit(), angle);
}