本文整理汇总了C++中PlayerInfo::HasTravelPlan方法的典型用法代码示例。如果您正苦于以下问题:C++ PlayerInfo::HasTravelPlan方法的具体用法?C++ PlayerInfo::HasTravelPlan怎么用?C++ PlayerInfo::HasTravelPlan使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PlayerInfo
的用法示例。
在下文中一共展示了PlayerInfo::HasTravelPlan方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
MissionPanel::MissionPanel(PlayerInfo &player)
: MapPanel(player),
available(player.AvailableJobs()),
accepted(player.Missions()),
availableIt(player.AvailableJobs().begin()),
acceptedIt(player.AvailableJobs().empty() ? accepted.begin() : accepted.end())
{
while(acceptedIt != accepted.end() && !acceptedIt->IsVisible())
++acceptedIt;
wrap.SetWrapWidth(380);
wrap.SetFont(FontSet::Get(14));
wrap.SetAlignment(WrappedText::JUSTIFIED);
// Select the first available or accepted mission in the currently selected
// system, or along the travel plan.
if(!FindMissionForSystem(selectedSystem) && player.HasTravelPlan())
{
const auto &tp = player.TravelPlan();
for(auto it = tp.crbegin(); it != tp.crend(); ++it)
if(FindMissionForSystem(*it))
break;
}
// Auto select the destination system for the current mission.
if(availableIt != available.end())
selectedSystem = availableIt->Destination()->GetSystem();
else if(acceptedIt != accepted.end())
selectedSystem = acceptedIt->Destination()->GetSystem();
// Center the system slightly above the center of the screen because the
// lower panel is taking up more space than the upper one.
center = Point(0., -80.) - selectedSystem->Position();
}
示例2: UpdateKeys
void AI::UpdateKeys(PlayerInfo &player, bool isActive)
{
shift = (SDL_GetModState() & KMOD_SHIFT);
Command oldHeld = keyHeld;
keyHeld.ReadKeyboard();
keyDown = keyHeld.AndNot(oldHeld);
if(keyHeld.Has(AutopilotCancelKeys()))
keyStuck.Clear();
if(keyStuck.Has(Command::JUMP) && !player.HasTravelPlan())
keyStuck.Clear(Command::JUMP);
const Ship *flagship = player.Flagship();
if(!isActive || !flagship || flagship->IsDestroyed())
return;
// Only toggle the "cloak" command if one of your ships has a cloaking device.
if(keyDown.Has(Command::CLOAK))
for(const auto &it : player.Ships())
if(it->Attributes().Get("cloak"))
{
isCloaking = !isCloaking;
Messages::Add(isCloaking ? "Engaging cloaking device." : "Disengaging cloaking device.");
break;
}
// Toggle your secondary weapon.
if(keyDown.Has(Command::SELECT))
player.SelectNext();
// The commands below here only apply if you have escorts or fighters.
if(player.Ships().size() < 2)
return;
// Only toggle the "deploy" command if one of your ships has fighter bays.
if(keyDown.Has(Command::DEPLOY))
for(const auto &it : player.Ships())
if(it->HasBays())
{
isLaunching = !isLaunching;
Messages::Add(isLaunching ? "Deploying fighters" : "Recalling fighters.");
break;
}
shared_ptr<Ship> target = flagship->GetTargetShip();
if(keyDown.Has(Command::FIGHT) && target)
{
sharedTarget = target;
holdPosition = false;
moveToMe = false;
Messages::Add("All your ships are focusing their fire on \"" + target->Name() + "\".");
}
if(keyDown.Has(Command::HOLD))
{
sharedTarget.reset();
holdPosition = !holdPosition;
moveToMe = false;
Messages::Add(holdPosition ? "Your fleet is holding position."
: "Your fleet is no longer holding position.");
}
if(keyDown.Has(Command::GATHER))
{
sharedTarget.reset();
holdPosition = false;
moveToMe = !moveToMe;
Messages::Add(moveToMe ? "Your fleet is gathering around your flagship."
: "Your fleet is no longer gathering around your flagship.");
}
if(sharedTarget.lock() && sharedTarget.lock()->IsDisabled())
sharedTarget.reset();
}
示例3: MovePlayer
void AI::MovePlayer(Ship &ship, const PlayerInfo &player, const list<shared_ptr<Ship>> &ships)
{
Command command;
if(player.HasTravelPlan())
{
const System *system = player.TravelPlan().back();
ship.SetTargetSystem(system);
// Check if there's a particular planet there we want to visit.
for(const Mission &mission : player.Missions())
if(mission.Destination() && mission.Destination()->GetSystem() == system)
{
ship.SetDestination(mission.Destination());
break;
}
}
if(keyDown.Has(Command::NEAREST))
{
double closest = numeric_limits<double>::infinity();
int closeState = 0;
for(const shared_ptr<Ship> &other : ships)
if(other.get() != &ship && other->IsTargetable())
{
// Sort ships into one of three priority states:
// 0 = friendly, 1 = disabled enemy, 2 = active enemy.
int state = other->GetGovernment()->IsEnemy(ship.GetGovernment());
// Do not let "target nearest" select a friendly ship, so that
// if the player is repeatedly targeting nearest to, say, target
// a bunch of fighters, they won't start firing on friendly
// ships as soon as the last one is gone.
if((!state && !shift) || other->GetGovernment()->IsPlayer())
continue;
state += state * !other->IsDisabled();
double d = other->Position().Distance(ship.Position());
if(state > closeState || (state == closeState && d < closest))
{
ship.SetTargetShip(other);
closest = d;
closeState = state;
}
}
}
else if(keyDown.Has(Command::TARGET))
{
shared_ptr<const Ship> target = ship.GetTargetShip();
bool selectNext = !target || !target->IsTargetable();
for(const shared_ptr<Ship> &other : ships)
{
bool isPlayer = other->GetGovernment()->IsPlayer() || other->GetPersonality().IsEscort();
if(other == target)
selectNext = true;
else if(other.get() != &ship && selectNext && other->IsTargetable() && isPlayer == shift)
{
ship.SetTargetShip(other);
selectNext = false;
break;
}
}
if(selectNext)
ship.SetTargetShip(shared_ptr<Ship>());
}
else if(keyDown.Has(Command::BOARD))
{
shared_ptr<const Ship> target = ship.GetTargetShip();
if(!target || !target->IsDisabled() || target->IsDestroyed() || target->GetSystem() != ship.GetSystem())
{
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())
//.........这里部分代码省略.........