diff --git a/src/weapon.c b/src/weapon.c index 6461dea..1f05c3c 100644 --- a/src/weapon.c +++ b/src/weapon.c @@ -330,9 +330,12 @@ static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer) { static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2* pos, const Vec2* vel, unsigned int parent, const unsigned int target) { Vec2 v; - double mass = 1; /* Presumer lasers have a mass of 1. */ - double rdir = dir; /* Real direction (accuracy). */ - Weapon* w = MALLOC_L(Weapon); + double mass, rdir; + Pilot* pilot_target; + Weapon* w; + + /* Create basic features. */ + w = MALLOC_L(Weapon); w->faction = pilot_get(parent)->faction; /*Non-Changeable. */ w->parent = parent; /* Non-Changeable. */ w->target = target; /* Non-Changeable. */ @@ -341,10 +344,21 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2* w->think = NULL; switch(outfit->type) { - case OUTFIT_TYPE_BOLT: - /* Need accuracy and speed based on player. -- Another contribution from VLack. */ - rdir += RNG(-outfit->u.blt.accuracy/2., outfit->u.blt.accuracy/2.)/180.*M_PI; + /* Bolts treated together. */ + case OUTFIT_TYPE_BOLT: + case OUTFIT_TYPE_TURRET_BOLT: + /* Only difference is the direction of fire. */ + if((outfit->type == OUTFIT_TYPE_TURRET_BOLT) && (w->parent != w->target)) { + rdir = vect_angle(pos, &pilot_get(w->target)->solid->pos); + rdir += RNG(-outfit->u.blt.accuracy/2., + outfit->u.blt.accuracy/2.)/180.*M_PI; + } else /* Fire straight. */ + rdir = dir + RNG(-outfit->u.blt.accuracy/2., + outfit->u.blt.accuracy/2.)/180.*M_PI; + if((rdir > 2.*M_PI) || (rdir < 0.)) rdir = fmod(rdir, 2.*M_PI); + + mass = 1; /* Lasers are presumed to have unitory mass. */ vectcpy(&v, vel); vect_cadd(&v, outfit->u.blt.speed*cos(rdir), outfit->u.blt.speed*sin(rdir)); w->timer += outfit->u.blt.range/outfit->u.blt.speed; @@ -353,42 +367,27 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2* w->solid->pos.x, w->solid->pos.y, w->solid->vel.x, w->solid->vel.y, w->outfit->u.blt.sound, 0); break; + + /* Treat seekers togther. */ case OUTFIT_TYPE_MISSILE_SEEK_AMMO: - mass = w->outfit->mass; - w->lockon = outfit->u.amm.lockon; - w->timer = outfit->u.amm.duration; - w->solid = solid_create(mass, dir, pos, vel); - w->think = think_seeker; /* Eeek!!! */ - w->voice = sound_addVoice(VOICE_PRIORITY_AMMO, - w->solid->pos.x, w->solid->pos.y, - w->solid->vel.x, w->solid->vel.y, w->outfit->u.amm.sound, 0); - break; case OUTFIT_TYPE_MISSILE_SEEK_SMART_AMMO: mass = w->outfit->mass; w->lockon = outfit->u.amm.lockon; w->timer = outfit->u.amm.duration; w->solid = solid_create(mass, dir, pos, vel); - w->think = think_smart; /* Smartass. */ w->voice = sound_addVoice(VOICE_PRIORITY_AMMO, w->solid->pos.x, w->solid->pos.y, w->solid->vel.x, w->solid->vel.y, w->outfit->u.amm.sound, 0); + + /* Only diff is AI. */ + if(outfit->type == OUTFIT_TYPE_MISSILE_SEEK_AMMO) + w->think = think_seeker; + else if(outfit->type == OUTFIT_TYPE_MISSILE_SEEK_SMART_AMMO) + w->think = think_smart; break; - case OUTFIT_TYPE_TURRET_BOLT: - if(w->parent != w->target) - rdir = vect_angle(pos, &pilot_get(w->target)->solid->pos); - rdir += RNG(-outfit->u.blt.accuracy/2., - outfit->u.blt.accuracy/2.)/180.*M_PI; - if((rdir > 2.*M_PI) || (rdir < 0.)) rdir = fmod(rdir, 2.*M_PI); - vectcpy(&v, vel); - vect_cadd(&v, outfit->u.blt.speed*cos(rdir), outfit->u.blt.speed*sin(rdir)); - w->timer = outfit->u.blt.range / outfit->u.blt.speed; - w->solid = solid_create(mass, rdir, pos, &v); - w->voice = sound_addVoice(VOICE_PRIORITY_BOLT, - w->solid->pos.x, w->solid->pos.y, - w->solid->vel.x, w->solid->vel.y, w->outfit->u.blt.sound, 0); - break; + + /* Just dump it where the player is. */ default: - /* Just dump it where the player is. */ w->voice = NULL; w->solid = solid_create(mass, dir, pos, vel); break;