本文整理汇总了C++中Ship::JumpFuel方法的典型用法代码示例。如果您正苦于以下问题:C++ Ship::JumpFuel方法的具体用法?C++ Ship::JumpFuel怎么用?C++ Ship::JumpFuel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ship
的用法示例。
在下文中一共展示了Ship::JumpFuel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DoCloak
void AI::DoCloak(Ship &ship, Command &command, const list<shared_ptr<Ship>> &ships)
{
if(ship.Attributes().Get("cloak"))
{
// Never cloak if it will cause you to be stranded.
if(ship.Attributes().Get("cloaking fuel") && !ship.Attributes().Get("ramscoop"))
{
double fuel = ship.Fuel() * ship.Attributes().Get("fuel capacity");
fuel -= ship.Attributes().Get("cloaking fuel");
if(fuel < ship.JumpFuel())
return;
}
// Otherwise, always cloak if you are in imminent danger.
static const double MAX_RANGE = 10000.;
double nearestEnemy = MAX_RANGE;
for(const auto &other : ships)
if(other->GetSystem() == ship.GetSystem() && other->IsTargetable() &&
other->GetGovernment()->IsEnemy(ship.GetGovernment()))
nearestEnemy = min(nearestEnemy,
ship.Position().Distance(other->Position()));
if(ship.Hull() + ship.Shields() < 1. && nearestEnemy < 2000.)
command |= Command::CLOAK;
// Also cloak if there are no enemies nearby and cloaking does
// not cost you fuel.
if(nearestEnemy == MAX_RANGE && !ship.Attributes().Get("cloaking fuel"))
command |= Command::CLOAK;
}
}
示例2: AutoFire
// Fire whichever of the given ship's weapons can hit a hostile target.
Command AI::AutoFire(const Ship &ship, const list<shared_ptr<Ship>> &ships, bool secondary) const
{
Command command;
int index = -1;
// Special case: your target is not your enemy. Do not fire, because you do
// not want to risk damaging that target. The only time a ship other than
// the player will target a friendly ship is if the player has asked a ship
// for assistance.
shared_ptr<Ship> currentTarget = ship.GetTargetShip();
const Government *gov = ship.GetGovernment();
bool isSharingTarget = ship.IsYours() && currentTarget == sharedTarget.lock();
bool currentIsEnemy = currentTarget
&& currentTarget->GetGovernment()->IsEnemy(gov)
&& currentTarget->GetSystem() == ship.GetSystem();
if(currentTarget && !(currentIsEnemy || isSharingTarget))
currentTarget.reset();
// Only fire on disabled targets if you don't want to plunder them.
bool spareDisabled = (ship.GetPersonality().Disables() || ship.GetPersonality().Plunders());
// Find the longest range of any of your non-homing weapons.
double maxRange = 0.;
for(const Armament::Weapon &weapon : ship.Weapons())
if(weapon.IsReady() && !weapon.IsHoming() && (secondary || !weapon.GetOutfit()->Icon()))
maxRange = max(maxRange, weapon.GetOutfit()->Range());
// Extend the weapon range slightly to account for velocity differences.
maxRange *= 1.5;
// Find all enemy ships within range of at least one weapon.
vector<shared_ptr<const Ship>> enemies;
if(currentTarget)
enemies.push_back(currentTarget);
for(auto target : ships)
if(target->IsTargetable() && gov->IsEnemy(target->GetGovernment())
&& target->Velocity().Length() < 20.
&& target->GetSystem() == ship.GetSystem()
&& target->Position().Distance(ship.Position()) < maxRange
&& target != currentTarget)
enemies.push_back(target);
for(const Armament::Weapon &weapon : ship.Weapons())
{
++index;
// Skip weapons that are not ready to fire. Also skip homing weapons if
// no target is selected, and secondary weapons if only firing primaries.
if(!weapon.IsReady() || (!currentTarget && weapon.IsHoming()))
continue;
if(!secondary && weapon.GetOutfit()->Icon())
continue;
// Special case: if the weapon uses fuel, be careful not to spend so much
// fuel that you cannot leave the system if necessary.
if(weapon.GetOutfit()->FiringFuel())
{
double fuel = ship.Fuel() * ship.Attributes().Get("fuel capacity");
fuel -= weapon.GetOutfit()->FiringFuel();
// If the ship is not ever leaving this system, it does not need to
// reserve any fuel.
bool isStaying = ship.GetPersonality().IsStaying();
if(!secondary || fuel < (isStaying ? 0. : ship.JumpFuel()))
continue;
}
// Figure out where this weapon will fire from, but add some randomness
// depending on how accurate this ship's pilot is.
Point start = ship.Position() + ship.Facing().Rotate(weapon.GetPoint());
start += ship.GetPersonality().Confusion();
const Outfit *outfit = weapon.GetOutfit();
double vp = outfit->Velocity();
double lifetime = outfit->TotalLifetime();
if(currentTarget && (weapon.IsHoming() || weapon.IsTurret()))
{
bool hasBoarded = Has(ship, currentTarget, ShipEvent::BOARD);
if(currentTarget->IsDisabled() && spareDisabled && !hasBoarded)
continue;
Point p = currentTarget->Position() - start;
Point v = currentTarget->Velocity() - ship.Velocity();
// By the time this action is performed, the ships will have moved
// forward one time step.
p += v;
if(p.Length() < outfit->BlastRadius())
continue;
double steps = Armament::RendevousTime(p, v, vp);
if(steps == steps && steps <= lifetime)
{
command.SetFire(index);
continue;
}
}
// Don't fire homing weapons with no target.
if(weapon.IsHoming())
continue;
for(const shared_ptr<const Ship> &target : enemies)
//.........这里部分代码省略.........
示例3: CanRefuel
bool Ship::CanRefuel(const Ship &other) const
{
return (fuel - other.JumpFuel() >= JumpFuel());
}