예제 #1
0
파일: Ship.cpp 프로젝트: GAlexx/pioneer
bool Ship::CanHyperspaceTo(const SystemPath *dest, int &outFuelRequired, double &outDurationSecs, enum HyperjumpStatus *outStatus) 
{
	Equip::Type t = m_equipment.Get(Equip::SLOT_ENGINE);
	Equip::Type fuelType = GetHyperdriveFuelType();
	int hyperclass = EquipType::types[t].pval;
	int fuel = m_equipment.Count(Equip::SLOT_CARGO, fuelType);
	outFuelRequired = 0;
	if (hyperclass == 0) {
		if (outStatus) *outStatus = HYPERJUMP_NO_DRIVE;
		return false;
	}

	if (Pi::currentSystem && Pi::currentSystem->GetPath().IsSameSystem(*dest)) {
		if (outStatus) *outStatus = HYPERJUMP_CURRENT_SYSTEM;
		return false;
	}

	float dist = distance_to_system(dest);

	this->CalcStats();
	outFuelRequired = int(ceil(hyperclass*hyperclass*dist / m_stats.hyperspace_range_max));
	double m_totalmass = m_stats.total_mass;
	if (outFuelRequired > hyperclass*hyperclass) outFuelRequired = hyperclass*hyperclass;
	if (outFuelRequired < 1) outFuelRequired = 1;
	if (dist > m_stats.hyperspace_range_max) {
		outFuelRequired = 0;
		if (outStatus) *outStatus = HYPERJUMP_OUT_OF_RANGE;
		return false;
	} else if (fuel < outFuelRequired) {
		if (outStatus) *outStatus = HYPERJUMP_INSUFFICIENT_FUEL;
		return false;
	} else {
		// Old comments:
		// take at most a week. why a week? because a week is a
		// fundamental physical unit in the same sense that the planck length
		// is, and so it is very probable that future hyperspace
		// technologies will involve travelling a week through time.

		// Now mass has more of an effect on the time taken, this is mainly
		// for gameplay considerations for courier missions and the like.
		outDurationSecs = ((dist * dist * 0.5) / (m_stats.hyperspace_range_max *
			hyperclass)) * 
			(60.0 * 60.0 * 24.0 * sqrt(m_totalmass));
		//float hours = outDurationSecs * 0.0002778;
		//printf("%f LY in %f hours OR %d seconds \n", dist, hours, outDurationSecs);
		//printf("%d seconds\n", outDurationSecs);
		if (outFuelRequired <= fuel) {
			if (outStatus) *outStatus = HYPERJUMP_OK;
			return true;
		} else {
			if (outStatus) *outStatus = HYPERJUMP_INSUFFICIENT_FUEL;
			return false;
		}
	}
}
예제 #2
0
Ship::HyperjumpStatus Ship::GetHyperspaceDetails(const SystemPath &dest, int &outFuelRequired, double &outDurationSecs)
{
	assert(dest.HasValidSystem());

	outFuelRequired = 0;
	outDurationSecs = 0.0;

	UpdateStats();

	if (GetFlightState() == HYPERSPACE)
		return HYPERJUMP_DRIVE_ACTIVE;

	Equip::Type t = m_equipment.Get(Equip::SLOT_ENGINE);
	Equip::Type fuelType = GetHyperdriveFuelType();
	int hyperclass = Equip::types[t].pval;
	int fuel = m_equipment.Count(Equip::SLOT_CARGO, fuelType);
	if (hyperclass == 0)
		return HYPERJUMP_NO_DRIVE;

	StarSystem *s = Pi::game->GetSpace()->GetStarSystem().Get();
	if (s && s->GetPath().IsSameSystem(dest))
		return HYPERJUMP_CURRENT_SYSTEM;

	float dist = distance_to_system(dest);

	outFuelRequired = Pi::CalcHyperspaceFuelOut(hyperclass, dist, m_stats.hyperspace_range_max);
	double m_totalmass = GetMass()/1000;
	if (dist > m_stats.hyperspace_range_max) {
		outFuelRequired = 0;
		return HYPERJUMP_OUT_OF_RANGE;
	} else if (fuel < outFuelRequired) {
		return HYPERJUMP_INSUFFICIENT_FUEL;
	} else {
		outDurationSecs = Pi::CalcHyperspaceDuration(hyperclass, m_totalmass, dist);

		if (outFuelRequired <= fuel) {
			return HYPERJUMP_OK;
		} else {
			return HYPERJUMP_INSUFFICIENT_FUEL;
		}
	}
}