本文整理汇总了C++中Ship::GetTargetPlanet方法的典型用法代码示例。如果您正苦于以下问题:C++ Ship::GetTargetPlanet方法的具体用法?C++ Ship::GetTargetPlanet怎么用?C++ Ship::GetTargetPlanet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ship
的用法示例。
在下文中一共展示了Ship::GetTargetPlanet方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MoveToPlanet
bool AI::MoveToPlanet(Ship &ship, Command &command)
{
if(!ship.GetTargetPlanet())
return false;
const Point &target = ship.GetTargetPlanet()->Position();
return MoveTo(ship, command, target, ship.GetTargetPlanet()->Radius(), 1.);
}
示例2: Refuel
void AI::Refuel(Ship &ship, Command &command)
{
if(ship.GetParent() && ship.GetParent()->GetTargetPlanet())
ship.SetTargetPlanet(ship.GetParent()->GetTargetPlanet());
else if(!ship.GetTargetPlanet())
{
double closest = numeric_limits<double>::infinity();
for(const StellarObject &object : ship.GetSystem()->Objects())
if(object.GetPlanet() && object.GetPlanet()->HasSpaceport())
{
double distance = ship.Position().Distance(object.Position());
if(distance < closest)
{
ship.SetTargetPlanet(&object);
closest = distance;
}
}
}
if(ship.GetTargetPlanet())
{
MoveToPlanet(ship, command);
command |= Command::LAND;
}
}
示例3: DoSurveillance
void AI::DoSurveillance(Ship &ship, Command &command, const list<shared_ptr<Ship>> &ships) const
{
const shared_ptr<Ship> &target = ship.GetTargetShip();
if(target && (!target->IsTargetable() || target->GetSystem() != ship.GetSystem()))
ship.SetTargetShip(shared_ptr<Ship>());
if(target && ship.GetGovernment()->IsEnemy(target->GetGovernment()))
{
MoveIndependent(ship, command);
command |= AutoFire(ship, ships);
return;
}
bool cargoScan = ship.Attributes().Get("cargo scan");
bool outfitScan = ship.Attributes().Get("outfit scan");
double atmosphereScan = ship.Attributes().Get("atmosphere scan");
bool jumpDrive = ship.Attributes().Get("jump drive");
bool hyperdrive = ship.Attributes().Get("hyperdrive");
// This function is only called for ships that are in the player's system.
if(ship.GetTargetSystem())
{
PrepareForHyperspace(ship, command);
command |= Command::JUMP;
command |= Command::DEPLOY;
}
else if(ship.GetTargetPlanet())
{
MoveToPlanet(ship, command);
double distance = ship.Position().Distance(ship.GetTargetPlanet()->Position());
if(distance < atmosphereScan && !Random::Int(100))
ship.SetTargetPlanet(nullptr);
else
command |= Command::LAND;
}
else if(ship.GetTargetShip() && ship.GetTargetShip()->IsTargetable()
&& ship.GetTargetShip()->GetSystem() == ship.GetSystem())
{
bool mustScanCargo = cargoScan && !Has(ship, target, ShipEvent::SCAN_CARGO);
bool mustScanOutfits = outfitScan && !Has(ship, target, ShipEvent::SCAN_OUTFITS);
bool isInSystem = (ship.GetSystem() == target->GetSystem() && !target->IsEnteringHyperspace());
if(!isInSystem || (!mustScanCargo && !mustScanOutfits))
ship.SetTargetShip(shared_ptr<Ship>());
else
{
CircleAround(ship, command, *target);
command |= Command::SCAN;
}
}
else
{
shared_ptr<Ship> newTarget = FindTarget(ship, ships);
if(newTarget && ship.GetGovernment()->IsEnemy(newTarget->GetGovernment()))
{
ship.SetTargetShip(newTarget);
return;
}
vector<shared_ptr<Ship>> targetShips;
vector<const StellarObject *> targetPlanets;
vector<const System *> targetSystems;
if(cargoScan || outfitScan)
for(const auto &it : ships)
if(it->GetGovernment() != ship.GetGovernment() && it->IsTargetable()
&& it->GetSystem() == ship.GetSystem())
{
if(Has(ship, it, ShipEvent::SCAN_CARGO) && Has(ship, it, ShipEvent::SCAN_OUTFITS))
continue;
targetShips.push_back(it);
}
if(atmosphereScan)
for(const StellarObject &object : ship.GetSystem()->Objects())
if(!object.IsStar() && object.Radius() < 130.)
targetPlanets.push_back(&object);
if(jumpDrive)
for(const System *link : ship.GetSystem()->Neighbors())
targetSystems.push_back(link);
else if(hyperdrive)
for(const System *link : ship.GetSystem()->Links())
targetSystems.push_back(link);
unsigned total = targetShips.size() + targetPlanets.size() + targetSystems.size();
if(!total)
return;
unsigned index = Random::Int(total);
if(index < targetShips.size())
ship.SetTargetShip(targetShips[index]);
else
{
index -= targetShips.size();
if(index < targetPlanets.size())
ship.SetTargetPlanet(targetPlanets[index]);
else
ship.SetTargetSystem(targetSystems[index - targetPlanets.size()]);
}
}
//.........这里部分代码省略.........
示例4: MoveIndependent
void AI::MoveIndependent(Ship &ship, Command &command) const
{
if(ship.Position().Length() >= 10000.)
{
MoveTo(ship, command, Point(), 40., .8);
return;
}
shared_ptr<const Ship> target = ship.GetTargetShip();
if(target && (ship.GetGovernment()->IsEnemy(target->GetGovernment())
|| (ship.IsYours() && target == sharedTarget.lock())))
{
bool shouldBoard = ship.Cargo().Free() && ship.GetPersonality().Plunders();
bool hasBoarded = Has(ship, target, ShipEvent::BOARD);
if(shouldBoard && target->IsDisabled() && !hasBoarded)
{
if(ship.IsBoarding())
return;
MoveTo(ship, command, target->Position(), 40., .8);
command |= Command::BOARD;
}
else
Attack(ship, command, *target);
return;
}
else if(target)
{
bool cargoScan = ship.Attributes().Get("cargo scan");
bool outfitScan = ship.Attributes().Get("outfit scan");
if((!cargoScan || Has(ship, target, ShipEvent::SCAN_CARGO))
&& (!outfitScan || Has(ship, target, ShipEvent::SCAN_OUTFITS)))
target.reset();
else
{
CircleAround(ship, command, *target);
if(!ship.GetGovernment()->IsPlayer())
command |= Command::SCAN;
}
return;
}
// If this ship is moving independently because it has a target, not because
// it has no parent, don't let it make travel plans.
if(ship.GetParent() && !ship.GetPersonality().IsStaying())
return;
if(!ship.GetTargetSystem() && !ship.GetTargetPlanet() && !ship.GetPersonality().IsStaying())
{
int jumps = ship.JumpsRemaining();
// Each destination system has an average priority of 10.
// If you only have one jump left, landing should be high priority.
int planetWeight = jumps ? (1 + 40 / jumps) : 1;
vector<int> systemWeights;
int totalWeight = 0;
const vector<const System *> &links = ship.Attributes().Get("jump drive")
? ship.GetSystem()->Neighbors() : ship.GetSystem()->Links();
if(jumps)
{
for(const System *link : links)
{
// Prefer systems in the direction we're facing.
Point direction = link->Position() - ship.GetSystem()->Position();
int weight = static_cast<int>(
11. + 10. * ship.Facing().Unit().Dot(direction.Unit()));
systemWeights.push_back(weight);
totalWeight += weight;
}
}
int systemTotalWeight = totalWeight;
// Anywhere you can land that has a port has the same weight. Ships will
// not land anywhere without a port.
vector<const StellarObject *> planets;
for(const StellarObject &object : ship.GetSystem()->Objects())
if(object.GetPlanet() && object.GetPlanet()->HasSpaceport()
&& object.GetPlanet()->CanLand(ship))
{
planets.push_back(&object);
totalWeight += planetWeight;
}
if(!totalWeight)
return;
int choice = Random::Int(totalWeight);
if(choice < systemTotalWeight)
{
for(unsigned i = 0; i < systemWeights.size(); ++i)
{
choice -= systemWeights[i];
if(choice < 0)
{
ship.SetTargetSystem(links[i]);
break;
}
}
}
else
{
choice = (choice - systemTotalWeight) / planetWeight;
//.........这里部分代码省略.........
示例5: MovePlayer
//.........这里部分代码省略.........
{
double closest = numeric_limits<double>::infinity();
bool foundEnemy = false;
bool foundAnything = false;
for(const shared_ptr<Ship> &other : ships)
if(other->IsTargetable() && other->IsDisabled() && !other->IsDestroyed())
{
bool isEnemy = other->GetGovernment()->IsEnemy(ship.GetGovernment());
double d = other->Position().Distance(ship.Position());
if((isEnemy && !foundEnemy) || d < closest)
{
closest = d;
foundEnemy = isEnemy;
foundAnything = true;
ship.SetTargetShip(other);
}
}
if(!foundAnything)
keyDown.Clear(Command::BOARD);
}
}
else if(keyDown.Has(Command::LAND))
{
// If the player is right over an uninhabited planet, display a message
// explaining why they cannot land there.
string message;
for(const StellarObject &object : ship.GetSystem()->Objects())
if(!object.GetPlanet() && !object.GetSprite().IsEmpty())
{
double distance = ship.Position().Distance(object.Position());
if(distance < object.Radius())
message = object.LandingMessage();
}
const StellarObject *target = ship.GetTargetPlanet();
if(target && ship.Position().Distance(target->Position()) < target->Radius())
{
// Special case: if there are two planets in system and you have one
// selected, then press "land" again, do not toggle to the other if
// you are within landing range of the one you have selected.
}
else if(message.empty() && target)
{
bool found = false;
const StellarObject *next = nullptr;
for(const StellarObject &object : ship.GetSystem()->Objects())
if(object.GetPlanet())
{
if(found)
{
next = &object;
break;
}
else if(&object == ship.GetTargetPlanet())
found = true;
}
if(!next)
{
for(const StellarObject &object : ship.GetSystem()->Objects())
if(object.GetPlanet())
{
next = &object;
break;
}
}
ship.SetTargetPlanet(next);
if(next->GetPlanet() && !next->GetPlanet()->CanLand())