当前位置: 首页>>代码示例>>C++>>正文


C++ Ship::IsBoarding方法代码示例

本文整理汇总了C++中Ship::IsBoarding方法的典型用法代码示例。如果您正苦于以下问题:C++ Ship::IsBoarding方法的具体用法?C++ Ship::IsBoarding怎么用?C++ Ship::IsBoarding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ship的用法示例。


在下文中一共展示了Ship::IsBoarding方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: RendezvousTime

// Fire this weapon. If it is a turret, it automatically points toward
// the given ship's target. If the weapon requires ammunition, it will
// be subtracted from the given ship.
void Armament::Weapon::Fire(Ship &ship, list<Projectile> &projectiles, list<Effect> &effects)
{
	// Since this is only called internally by Armament (no one else has non-
	// const access), assume Armament checked that this is a valid call.
	Angle aim = ship.Facing();
	
	// Get projectiles to start at the right position. They are drawn at an
	// offset of (.5 * velocity) and that velocity includes the velocity of the
	// ship that fired them.
	Point start = ship.Position() + aim.Rotate(point) - .5 * ship.Velocity();
	
	shared_ptr<const Ship> target = ship.GetTargetShip();
	// If you are boarding your target, do not fire on it.
	if(ship.IsBoarding() || ship.Commands().Has(Command::BOARD))
		target.reset();
	
	if(!isTurret || !target || target->GetSystem() != ship.GetSystem())
		aim += angle;
	else
	{
		Point p = target->Position() - start + ship.GetPersonality().Confusion();
		Point v = target->Velocity() - ship.Velocity();
		double steps = RendezvousTime(p, v, outfit->Velocity());
		
		// Special case: RendezvousTime() may return NaN. But in that case, this
		// comparison will return false.
		if(!(steps < outfit->TotalLifetime()))
			steps = outfit->TotalLifetime();
		
		p += steps * v;
		
		aim = Angle(TO_DEG * atan2(p.X(), -p.Y()));
	}
	
	projectiles.emplace_back(ship, start, aim, outfit);
	if(outfit->WeaponSound())
		Audio::Play(outfit->WeaponSound(), start);
	double force = outfit->FiringForce();
	if(force)
		ship.ApplyForce(aim.Unit() * -force);
	
	for(const auto &eit : outfit->FireEffects())
		for(int i = 0; i < eit.second; ++i)
		{
			effects.push_back(*eit.first);
			effects.back().Place(start, ship.Velocity(), aim);
		}
	
	Fire(ship);
}
开发者ID:Arnogax,项目名称:endless-sky,代码行数:53,代码来源:Armament.cpp

示例2: weapon

Projectile::Projectile(const Ship &parent, Point position, Angle angle, const Outfit *weapon)
	: weapon(weapon), animation(weapon->WeaponSprite()),
	position(position), velocity(parent.Velocity()), angle(angle),
	targetShip(parent.GetTargetShip()), government(parent.GetGovernment()),
	lifetime(weapon->Lifetime())
{
	// If you are boarding your target, do not fire on it.
	if(parent.IsBoarding() || parent.Commands().Has(Command::BOARD))
		targetShip.reset();
	
	cachedTarget = targetShip.lock().get();
	double inaccuracy = weapon->Inaccuracy();
	if(inaccuracy)
		this->angle += Angle::Random(inaccuracy) - Angle::Random(inaccuracy);
	
	velocity += this->angle.Unit() * weapon->Velocity();
}
开发者ID:Phezzan,项目名称:endless-sky,代码行数:17,代码来源:Projectile.cpp

示例3: Body

Projectile::Projectile(const Ship &parent, Point position, Angle angle, const Outfit *weapon)
	: Body(weapon->WeaponSprite(), position, parent.Velocity(), angle),
	weapon(weapon), targetShip(parent.GetTargetShip()), lifetime(weapon->Lifetime())
{
	government = parent.GetGovernment();
	
	// If you are boarding your target, do not fire on it.
	if(parent.IsBoarding() || parent.Commands().Has(Command::BOARD))
		targetShip.reset();
	
	cachedTarget = targetShip.lock().get();
	if(cachedTarget)
		targetGovernment = cachedTarget->GetGovernment();
	double inaccuracy = weapon->Inaccuracy();
	if(inaccuracy)
		this->angle += Angle::Random(inaccuracy) - Angle::Random(inaccuracy);
	
	velocity += this->angle.Unit() * (weapon->Velocity() + Random::Real() * weapon->RandomVelocity());
	
	// If a random lifetime is specified, add a random amount up to that amount.
	if(weapon->RandomLifetime())
		lifetime += Random::Int(weapon->RandomLifetime() + 1);
}
开发者ID:BorkBorkGoesTheCode,项目名称:endless-sky,代码行数:23,代码来源:Projectile.cpp

示例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;
//.........这里部分代码省略.........
开发者ID:balachia,项目名称:endless-sky,代码行数:101,代码来源:AI.cpp

示例5: MovePlayer


//.........这里部分代码省略.........
			{
				message = "You can land on more than one planet in this system. Landing on ";
				if(ship.GetTargetPlanet()->Name().empty())
					message += "???.";
				else
					message += ship.GetTargetPlanet()->Name() + ".";
			}
		}
		if(!message.empty())
			Messages::Add(message);
	}
	else if(keyDown.Has(Command::JUMP))
	{
		if(!ship.GetTargetSystem())
		{
			double bestMatch = -2.;
			const auto &links = (ship.Attributes().Get("jump drive") ?
				ship.GetSystem()->Neighbors() : ship.GetSystem()->Links());
			for(const System *link : links)
			{
				Point direction = link->Position() - ship.GetSystem()->Position();
				double match = ship.Facing().Unit().Dot(direction.Unit());
				if(match > bestMatch)
				{
					bestMatch = match;
					ship.SetTargetSystem(link);
				}
			}
		}
	}
	else if(keyDown.Has(Command::SCAN))
		command |= Command::SCAN;
	
	bool hasGuns = Preferences::Has("Automatic firing") && !ship.IsBoarding()
		&& !(keyStuck | keyHeld).Has(Command::LAND | Command::JUMP | Command::BOARD);
	if(hasGuns)
		command |= AutoFire(ship, ships, false);
	hasGuns |= keyHeld.Has(Command::PRIMARY);
	if(keyHeld)
	{
		if(keyHeld.Has(Command::RIGHT | Command::LEFT))
			command.SetTurn(keyHeld.Has(Command::RIGHT) - keyHeld.Has(Command::LEFT));
		else if(keyHeld.Has(Command::BACK))
		{
			if(ship.Attributes().Get("reverse thrust"))
				command |= Command::BACK;
			else
				command.SetTurn(TurnBackward(ship));
		}
		
		if(keyHeld.Has(Command::FORWARD))
			command |= Command::FORWARD;
		if(keyHeld.Has(Command::PRIMARY))
		{
			int index = 0;
			for(const Armament::Weapon &weapon : ship.Weapons())
			{
				const Outfit *outfit = weapon.GetOutfit();
				if(outfit && !outfit->Icon())
				{
					command.SetFire(index);
					hasGuns |= !weapon.IsTurret();
				}
				++index;
			}
		}
开发者ID:balachia,项目名称:endless-sky,代码行数:67,代码来源:AI.cpp


注:本文中的Ship::IsBoarding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。