本文整理汇总了C++中Ship::Place方法的典型用法代码示例。如果您正苦于以下问题:C++ Ship::Place方法的具体用法?C++ Ship::Place怎么用?C++ Ship::Place使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ship
的用法示例。
在下文中一共展示了Ship::Place方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Place
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: Place
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);
}
示例3: Enter
// Do the randomization to make a ship enter or be in the given system.
void Fleet::Enter(const System &system, Ship &ship)
{
if(!system.Links().size())
{
Place(system, ship);
return;
}
const System *source = system.Links()[Random::Int(system.Links().size())];
Angle angle = Angle::Random();
Point pos = angle.Unit() * Random::Real() * 1000.;
ship.Place(pos, angle.Unit(), angle);
ship.SetSystem(source);
ship.SetTargetSystem(&system);
}