[Add] Pilots now keep track of how many weapons are locked onto them.

This commit is contained in:
Allanis 2013-07-09 18:53:55 +01:00
parent 1f8e6a22fe
commit f7c10bf329
4 changed files with 26 additions and 1 deletions

View File

@ -235,6 +235,15 @@ double outfit_range(const Outfit* o) {
return -1.; return -1.;
} }
int outfit_isSeeker(const Outfit* o) {
if((o->type == OUTFIT_TYPE_MISSILE_SEEK_AMMO) ||
(o->type == OUTFIT_TYPE_MISSILE_SEEK_SMART_AMMO) ||
(o->type == OUTFIT_TYPE_MISSILE_SWARM_AMMO) ||
(o->type == OUTFIT_TYPE_MISSILE_SWARM_SMART_AMMO))
return 1;
return 0;
}
const char* outfit_typename[] = { const char* outfit_typename[] = {
"NULL", "NULL",
"Bolt Cannon", "Bolt Cannon",

View File

@ -146,6 +146,7 @@ DamageType outfit_damageType(const Outfit* o);
int outfit_delay(const Outfit* o); int outfit_delay(const Outfit* o);
double outfit_energy(const Outfit* o); double outfit_energy(const Outfit* o);
double outfit_range(const Outfit* o); double outfit_range(const Outfit* o);
int outfit_isSeeker(const Outfit* o);
/* Load/free outfit stack. */ /* Load/free outfit stack. */
int outfit_load(void); int outfit_load(void);

View File

@ -105,6 +105,7 @@ typedef struct Pilot_ {
/* Misc. */ /* Misc. */
uint32_t flags; /* Used for AI etc. */ uint32_t flags; /* Used for AI etc. */
unsigned int ptimer; /* Generic timer for internal pilot use. */ unsigned int ptimer; /* Generic timer for internal pilot use. */
int lockons; /* Stores how many seeking weapons are targetting pilot. */
/* Hook attached to the pilot. */ /* Hook attached to the pilot. */
int hook_type; int hook_type;

View File

@ -379,6 +379,11 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2*
w->solid->pos.x, w->solid->pos.y, w->solid->pos.x, w->solid->pos.y,
w->solid->vel.x, w->solid->vel.y, w->outfit->u.amm.sound, 0); w->solid->vel.x, w->solid->vel.y, w->outfit->u.amm.sound, 0);
/* If they are seeking a pilot, increment lockon counter. */
pilot_target = pilot_get(target);
if(pilot_target != NULL)
pilot_target->lockons++;
/* Only diff is AI. */ /* Only diff is AI. */
if(outfit->type == OUTFIT_TYPE_MISSILE_SEEK_AMMO) if(outfit->type == OUTFIT_TYPE_MISSILE_SEEK_AMMO)
w->think = think_seeker; w->think = think_seeker;
@ -449,6 +454,15 @@ static void weapon_destroy(Weapon* w, WeaponLayer layer) {
int i; int i;
Weapon** wlayer; Weapon** wlayer;
int* nlayer; int* nlayer;
Pilot* pilot_target;
/* Decrement target lockons if needed. */
if(outfit_isSeeker(w->outfit)) {
pilot_target = pilot_get(w->target);
if(pilot_target != NULL)
pilot_target->lockons--;
}
switch(layer) { switch(layer) {
case WEAPON_LAYER_BG: case WEAPON_LAYER_BG:
wlayer = wbackLayer; wlayer = wbackLayer;