From b55259321e4526263830821c9f3370e161f808f9 Mon Sep 17 00:00:00 2001 From: Allanis Date: Sun, 24 Feb 2013 16:06:19 +0000 Subject: [PATCH] [Add] Pushback effect for weapons. --- dat/outfit.xml | 2 +- dat/ship.xml | 12 ++++++------ dat/start.xml | 2 +- src/pilot.c | 23 +++++++++++++++++++---- src/pilot.h | 3 ++- src/weapon.c | 2 +- 6 files changed, 30 insertions(+), 14 deletions(-) diff --git a/dat/outfit.xml b/dat/outfit.xml index 3dc6234..83da37a 100644 --- a/dat/outfit.xml +++ b/dat/outfit.xml @@ -4,7 +4,7 @@ 5 2 - 5 + 0 lasergreen diff --git a/dat/ship.xml b/dat/ship.xml index 3fc2722..0675c5e 100644 --- a/dat/ship.xml +++ b/dat/ship.xml @@ -20,12 +20,12 @@ 2 - 7 + 32 20 25 - Laser + Laser @@ -48,7 +48,7 @@ 2 - 5 + 25 25 10 @@ -62,9 +62,9 @@ engine 2 - 180 - 130 - 260 + 320 + 150 + 360 160 diff --git a/dat/start.xml b/dat/start.xml index f034a85..e3dd9c2 100644 --- a/dat/start.xml +++ b/dat/start.xml @@ -1,7 +1,7 @@ Dark Tides - Merchant Ship + Lancer 500 1500 diff --git a/src/pilot.c b/src/pilot.c index 833aebb..7fa595a 100644 --- a/src/pilot.c +++ b/src/pilot.c @@ -177,18 +177,33 @@ static void pilot_shootWeapon(Pilot* p, PilotOutfit* w, const unsigned int t) { } // Damage the pilot. -void pilot_hit(Pilot* p, const double damage_shield, const double damage_armour) { - if(p->shield - damage_shield > 0.) +void pilot_hit(Pilot* p, const Solid* w,const double damage_shield, + const double damage_armour) { + + double dam_mod; + + if(p->shield - damage_shield > 0.) { p->shield -= damage_shield; + dam_mod = damage_shield/p->shield_max; + } else if(p->shield > 0.) { // Shields can take part of the blow. p->armour -= p->shield/damage_shield*damage_armour; p->shield = 0.; + dam_mod = (damage_shield+damage_armour) / (p->shield_max + p->armour_max); } - else if(p->armour-damage_armour > 0.) + else if(p->armour-damage_armour > 0.) { p->armour -= damage_armour; - else + dam_mod = damage_armour/p->armour_max; + } + else { p->armour = 0.; + dam_mod = 0.; + } + + vect_cadd(&p->solid->vel, + w->vel.x * (dam_mod/4. + w->mass/p->solid->mass/4.), + w->vel.y * (dam_mod/4. + w->mass/p->solid->mass/4.)); } // Set the pilot's ammo based on their secondary weapon. diff --git a/src/pilot.h b/src/pilot.h index dd59584..d93b2c3 100644 --- a/src/pilot.h +++ b/src/pilot.h @@ -105,7 +105,8 @@ Fleet* fleet_get(const char* name); // MISC. void pilot_shoot(Pilot* p, const unsigned int target, const int secondary); -void pilot_hit(Pilot* p, const double damage_shield, const double damage_armour); +void pilot_hit(Pilot* p, const Solid* w, + const double damage_shield, const double damage_armour); void pilot_setAmmo(Pilot* p); double pilot_face(Pilot* p, const float dir); diff --git a/src/weapon.c b/src/weapon.c index 7b21897..39d592d 100644 --- a/src/weapon.c +++ b/src/weapon.c @@ -243,7 +243,7 @@ static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer) { pilot_setFlag(p, PILOT_HOSTILE); // Let the ship know that is should take some kind of damage. - pilot_hit(p, w->outfit->damage_shield, w->outfit->damage_armour); + pilot_hit(p, w->solid, w->outfit->damage_shield, w->outfit->damage_armour); // We don't need the weapon particle any longer. weapon_destroy(w, layer); }