本文整理汇总了C++中System::Links方法的典型用法代码示例。如果您正苦于以下问题:C++ System::Links方法的具体用法?C++ System::Links怎么用?C++ System::Links使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System::Links方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: Enter
void Fleet::Enter(const System &system, list<shared_ptr<Ship>> &ships, const Planet *planet) const
{
if(!total || !government || variants.empty())
return;
// Pick a fleet variant to instantiate.
const Variant &variant = ChooseVariant();
if(variant.ships.empty())
return;
// Where this fleet can come from depends on whether it is friendly to any
// planets in this system and whether it has jump drives.
vector<const System *> linkVector;
// Find out what the "best" jump method the fleet has is. Assume that if the
// others don't have that jump method, they are being carried as fighters.
// That is, content creators should avoid creating fleets with a mix of jump
// drives and hyperdrives.
int jumpType = 0;
for(const Ship *ship : variant.ships)
jumpType = max(jumpType,
ship->Attributes().Get("jump drive") ? 200 :
ship->Attributes().Get("hyperdrive") ? 100 : 0);
if(jumpType)
{
// Don't try to make a fleet "enter" from another system if none of the
// ships have jump drives.
bool isWelcomeHere = !system.GetGovernment()->IsEnemy(government);
for(const System *neighbor : (jumpType == 200 ? system.Neighbors() : system.Links()))
{
// If this ship is not "welcome" in the current system, prefer to have
// it enter from a system that is friendly to it. (This is for realism,
// so attack fleets don't come from what ought to be a safe direction.)
if(isWelcomeHere || neighbor->GetGovernment()->IsEnemy(government))
linkVector.push_back(neighbor);
else
linkVector.insert(linkVector.end(), 4, neighbor);
}
}
// Find all the inhabited planets this fleet could take off from.
vector<const Planet *> planetVector;
if(!personality.IsSurveillance())
for(const StellarObject &object : system.Objects())
if(object.GetPlanet() && object.GetPlanet()->HasSpaceport()
&& !object.GetPlanet()->GetGovernment()->IsEnemy(government))
planetVector.push_back(object.GetPlanet());
// If there is nowhere for this fleet to come from, don't create it.
size_t options = linkVector.size() + planetVector.size();
if(!options)
return;
// Choose a random planet or star system to come from.
size_t choice = Random::Int(options);
// Figure out what system the ship is starting in, where it is going, and
// what position it should start from in the system.
const System *source = &system;
const System *target = &system;
Point position;
double radius = 0.;
// If a planet is chosen, also pick a system to travel to after taking off.
if(choice >= linkVector.size())
{
planet = planetVector[choice - linkVector.size()];
if(!linkVector.empty())
target = linkVector[Random::Int(linkVector.size())];
}
// Find the stellar object for the given planet, and place the ships there.
if(planet)
{
for(const StellarObject &object : system.Objects())
if(object.GetPlanet() == planet)
{
position = object.Position();
radius = object.Radius();
break;
}
}
else if(choice < linkVector.size())
{
// We are entering this system via hyperspace, not taking off from a planet.
radius = 1000.;
source = linkVector[choice];
}
// Place all the ships in the chosen fleet variant.
shared_ptr<Ship> flagship;
vector<shared_ptr<Ship>> placed = Instantiate(variant);
for(shared_ptr<Ship> &ship : placed)
{
// If this is a fighter and someone can carry it, no need to position it.
if(PlaceFighter(ship, placed))
continue;
Angle angle = Angle::Random(360.);
Point pos = position + angle.Unit() * (Random::Real() * radius);
//.........这里部分代码省略.........