Esempio n. 1
0
Ship::ECMResult Ship::UseECM()
{
	int ecm_power_cap = 0;
	Properties().Get("ecm_power_cap", ecm_power_cap);
	if (m_ecmRecharge > 0.0f) return ECM_RECHARGING;

	if (ecm_power_cap > 0) {
		Sound::BodyMakeNoise(this, "ECM", 1.0f);
		m_ecmRecharge = GetECMRechargeTime();

		// damage neaby missiles
		const float ECM_RADIUS = 4000.0f;

		Space::BodyNearList nearby;
		Pi::game->GetSpace()->GetBodiesMaybeNear(this, ECM_RADIUS, nearby);
		for (Space::BodyNearIterator i = nearby.begin(); i != nearby.end(); ++i) {
			if ((*i)->GetFrame() != GetFrame()) continue;
			if (!(*i)->IsType(Object::MISSILE)) continue;

			double dist = ((*i)->GetPosition() - GetPosition()).Length();
			if (dist < ECM_RADIUS) {
				// increasing chance of destroying it with proximity
				if (Pi::rng.Double() > (dist / ECM_RADIUS)) {
					static_cast<Missile*>(*i)->ECMAttack(ecm_power_cap);
				}
			}
		}
		return ECM_ACTIVATED;
	}
	else return ECM_NOT_INSTALLED;
}
Esempio n. 2
0
void Ship::UseECM()
{
	const Equip::Type t = m_equipment.Get(Equip::SLOT_ECM);
	if (m_ecmRecharge > 0.0f) return;

	if (t != Equip::NONE) {
		Sound::BodyMakeNoise(this, "ECM", 1.0f);
		m_ecmRecharge = GetECMRechargeTime();

		// damage neaby missiles
		const float ECM_RADIUS = 4000.0f;

		Space::BodyNearList nearby;
		Pi::game->GetSpace()->GetBodiesMaybeNear(this, ECM_RADIUS, nearby);
		for (Space::BodyNearIterator i = nearby.begin(); i != nearby.end(); ++i) {
			if ((*i)->GetFrame() != GetFrame()) continue;
			if (!(*i)->IsType(Object::MISSILE)) continue;

			double dist = ((*i)->GetPosition() - GetPosition()).Length();
			if (dist < ECM_RADIUS) {
				// increasing chance of destroying it with proximity
				if (Pi::rng.Double() > (dist / ECM_RADIUS)) {
					static_cast<Missile*>(*i)->ECMAttack(Equip::types[t].pval);
				}
			}
		}
	}
}
Esempio n. 3
0
void Ship::Render(Graphics::Renderer *renderer, const Camera *camera, const vector3d &viewCoords, const matrix4x4d &viewTransform)
{
	if (IsDead()) return;

	m_shipFlavour.ApplyTo(GetModel());

	//angthrust negated, for some reason
	GetModel()->SetThrust(vector3f(m_thrusters), -vector3f(m_angThrusters));

	if (m_landingGearAnimation)
		m_landingGearAnimation->SetProgress(m_wheelState);

	//strncpy(params.pText[0], GetLabel().c_str(), sizeof(params.pText));
	RenderModel(renderer, viewCoords, viewTransform);

	// draw shield recharge bubble
	if (m_stats.shield_mass_left < m_stats.shield_mass) {
		const float shield = 0.01f*GetPercentShields();
		renderer->SetBlendMode(Graphics::BLEND_ADDITIVE);
		glPushMatrix();
		matrix4x4f trans = matrix4x4f::Identity();
		trans.Translate(viewCoords.x, viewCoords.y, viewCoords.z);
		trans.Scale(GetPhysRadius());
		renderer->SetTransform(trans);

		//fade based on strength
		Sfx::shieldEffect->GetMaterial()->diffuse =
			Color((1.0f-shield),shield,0.0,0.33f*(1.0f-shield));
		Sfx::shieldEffect->Draw(renderer);
		glPopMatrix();
		renderer->SetBlendMode(Graphics::BLEND_SOLID);
	}

	if (m_ecmRecharge > 0.0f) {
		// ECM effect: a cloud of particles for a sparkly effect
		vector3f v[100];
		for (int i=0; i<100; i++) {
			const double r1 = Pi::rng.Double()-0.5;
			const double r2 = Pi::rng.Double()-0.5;
			const double r3 = Pi::rng.Double()-0.5;
			v[i] = vector3f(viewTransform * (
				GetPosition() + GetPhysRadius() *
				vector3d(r1, r2, r3).Normalized()
			));
		}
		Color c(0.5,0.5,1.0,1.0);
		float totalRechargeTime = GetECMRechargeTime();
		if (totalRechargeTime >= 0.0f) {
			c.a = m_ecmRecharge / totalRechargeTime;
		}

		Sfx::ecmParticle->diffuse = c;
		renderer->SetBlendMode(Graphics::BLEND_ALPHA_ONE);
		renderer->DrawPointSprites(100, v, Sfx::ecmParticle, 50.f);
	}
}
Esempio n. 4
0
void Ship::UseECM()
{
	const Equip::Type t = m_equipment.Get(Equip::SLOT_ECM);
	if (m_ecmRecharge > 0.0f) return;
	if (t != Equip::NONE) {
		Sound::BodyMakeNoise(this, "ECM", 1.0f);
		m_ecmRecharge = GetECMRechargeTime();
		Space::DoECM(GetFrame(), GetPosition(), EquipType::types[t].pval);
	}
}
Esempio n. 5
0
void Ship::Render(Graphics::Renderer *renderer, const Camera *camera, const vector3d &viewCoords, const matrix4x4d &viewTransform)
{
	if (IsDead()) return;

	//angthrust negated, for some reason
	GetModel()->SetThrust(vector3f(m_thrusters), -vector3f(m_angThrusters));

	matrix3x3f mt;
	matrix3x3dtof(viewTransform.Inverse().GetOrient(), mt);
	s_heatGradientParams.heatingMatrix = mt;
	s_heatGradientParams.heatingNormal = vector3f(GetVelocity().Normalized());
	s_heatGradientParams.heatingAmount = Clamp(GetHullTemperature(),0.0,1.0);

	// This has to be done per-model with a shield and just before it's rendered
	const bool shieldsVisible = m_shieldCooldown > 0.01f && m_stats.shield_mass_left > (m_stats.shield_mass / 100.0f);
	GetShields()->SetEnabled(shieldsVisible);
	GetShields()->Update(m_shieldCooldown, 0.01f*GetPercentShields());

	//strncpy(params.pText[0], GetLabel().c_str(), sizeof(params.pText));
	RenderModel(renderer, camera, viewCoords, viewTransform);
	m_navLights->Render(renderer);
	renderer->GetStats().AddToStatCount(Graphics::Stats::STAT_SHIPS, 1);

	if (m_ecmRecharge > 0.0f) {
		// ECM effect: a cloud of particles for a sparkly effect
		vector3f v[100];
		for (int i=0; i<100; i++) {
			const double r1 = Pi::rng.Double()-0.5;
			const double r2 = Pi::rng.Double()-0.5;
			const double r3 = Pi::rng.Double()-0.5;
			v[i] = vector3f(GetPhysRadius()*vector3d(r1, r2, r3).NormalizedSafe());
		}
		Color c(128,128,255,255);
		float totalRechargeTime = GetECMRechargeTime();
		if (totalRechargeTime >= 0.0f) {
			c.a = (m_ecmRecharge / totalRechargeTime) * 255;
		}

		SfxManager::ecmParticle->diffuse = c;

		matrix4x4f t;
		for (int i=0; i<12; i++) t[i] = float(viewTransform[i]);
		t[12] = viewCoords.x;
		t[13] = viewCoords.y;
		t[14] = viewCoords.z;
		t[15] = 1.0f;

		renderer->SetTransform(t);
		renderer->DrawPointSprites(100, v, SfxManager::additiveAlphaState, SfxManager::ecmParticle.get(), 50.f);
	}
}
Esempio n. 6
0
void Ship::Render(const vector3d &viewCoords, const matrix4x4d &viewTransform)
{
	if ((!IsEnabled()) && !m_flightState) return;
	LmrObjParams &params = GetLmrObjParams();
	
	if ( (this != reinterpret_cast<Ship*>(Pi::player)) ||
	     (Pi::worldView->GetCamType() == WorldView::CAM_EXTERNAL) ) {
		m_shipFlavour.ApplyTo(&params);
		SetLmrTimeParams();
		params.angthrust[0] = float(-m_angThrusters.x);
		params.angthrust[1] = float(-m_angThrusters.y);
		params.angthrust[2] = float(-m_angThrusters.z);
		params.linthrust[0] = float(m_thrusters.x);
		params.linthrust[1] = float(m_thrusters.y);
		params.linthrust[2] = float(m_thrusters.z);
		params.argDoubles[0] = m_wheelState;
		params.argDoubles[5] = double(m_equipment.Get(Equip::SLOT_FUELSCOOP));
		params.argDoubles[6] = double(m_equipment.Get(Equip::SLOT_ENGINE));
		params.argDoubles[7] = double(m_equipment.Get(Equip::SLOT_ECM));
		params.argDoubles[8] = double(m_equipment.Get(Equip::SLOT_SCANNER));
		params.argDoubles[9] = double(m_equipment.Get(Equip::SLOT_ATMOSHIELD));
		params.argDoubles[10] = double(m_equipment.Get(Equip::SLOT_LASER, 0));
		params.argDoubles[11] = double(m_equipment.Get(Equip::SLOT_LASER, 1));
		for (int i=0; i<8; i++) {
			params.argDoubles[12+i] = double(m_equipment.Get(Equip::SLOT_MISSILE, i));
		}
		params.argDoubles[20] = m_flightState;

		//strncpy(params.pText[0], GetLabel().c_str(), sizeof(params.pText));
		RenderLmrModel(viewCoords, viewTransform);

		// draw shield recharge bubble
		if (m_stats.shield_mass_left < m_stats.shield_mass) {
			float shield = 0.01f*GetPercentShields();
			glDisable(GL_LIGHTING);
			glEnable(GL_BLEND);
			glColor4f((1.0f-shield),shield,0.0,0.33f*(1.0f-shield));
			glPushMatrix();
			glTranslatef(GLfloat(viewCoords.x), GLfloat(viewCoords.y), GLfloat(viewCoords.z));
			Render::State::UseProgram(Render::simpleShader);
			gluSphere(Pi::gluQuadric, GetLmrCollMesh()->GetBoundingRadius(), 20, 20);
			Render::State::UseProgram(0);
			glPopMatrix();
			glEnable(GL_LIGHTING);
			glDisable(GL_BLEND);
		}
	}
	if (m_ecmRecharge > 0.0f) {
		// pish effect
		vector3f v[100];
		for (int i=0; i<100; i++) {
			const double r1 = Pi::rng.Double()-0.5;
			const double r2 = Pi::rng.Double()-0.5;
			const double r3 = Pi::rng.Double()-0.5;
			v[i] = viewTransform * (
				GetPosition() +
				GetLmrCollMesh()->GetBoundingRadius() *
				vector3d(r1, r2, r3).Normalized()
			);
		}
		Color c(0.5,0.5,1.0,1.0);
		float totalRechargeTime = GetECMRechargeTime();
		if (totalRechargeTime >= 0.0f) {
			c.a = m_ecmRecharge / totalRechargeTime;
		}
		GLuint tex = util_load_tex_rgba(PIONEER_DATA_DIR"/textures/ecm.png");

		glBindTexture(GL_TEXTURE_2D, tex);
		Render::PutPointSprites(100, v, 50.0f, c);
	}

#if 0
	if (IsFiringLasers()) {
		glPushMatrix();
		TransformToModelCoords(camFrame);
		RenderLaserfire();
		glPopMatrix();
	}
#endif /* 0 */
}