[Change] Better handling of secondary weapons.

This commit is contained in:
Allanis 2014-05-21 00:09:43 +01:00
parent acc4ce6547
commit 230329f868

View File

@ -1298,6 +1298,7 @@ static int ai_aim(lua_State* L) {
Vec2 tv;
double dist, diff;
double mod;
double speed;
LLUA_MIN_ARGS(1);
/* Only acceptable parameter is pilot id. */
@ -1316,8 +1317,16 @@ static int ai_aim(lua_State* L) {
/* Get the distance. */
dist = vect_dist(&cur_pilot->solid->pos, &p->solid->pos);
/* Check if we should recalculate weapon speed with secondary weapon. */
if((cur_pilot->secondary != NULL) &&
outfit_isBolt(cur_pilot->secondary->outfit) &&
(cur_pilot->secondary->outfit->type == OUTFIT_TYPE_MISSILE_DUMB)) {
speed = cur_pilot->weap_speed + outfit_speed(cur_pilot->secondary->outfit);
speed /= 2.;
}
/* Time for shots to reach distance. */
t = dist / cur_pilot->weap_speed;
t = dist / speed;
/* Position is calculated on where it should be. */
x = p->solid->pos.x + p->solid->vel.x*t
@ -1369,7 +1378,8 @@ static int ai_settarget(lua_State* L) {
*/
static int outfit_isMelee(Pilot* p, PilotOutfit* o) {
(void)p;
if(outfit_isBolt(o->outfit) || outfit_isBeam(o->outfit))
if(outfit_isBolt(o->outfit) || outfit_isBeam(o->outfit) ||
(o->outfit->type == OUTFIT_TYPE_MISSILE_DUMB))
return 1;
return 0;
}
@ -1380,7 +1390,9 @@ static int outfit_isMelee(Pilot* p, PilotOutfit* o) {
* @param o Outfit to check.
*/
static int outfit_isRanged(Pilot* p, PilotOutfit* o) {
if(outfit_isFighterBay(o->outfit) || outfit_isLauncher(o->outfit)) {
if(outfit_isFighterBay(o->outfit) ||
(outfit_isLauncher(o->outfit) &&
(o->outfit->type != OUTFIT_TYPE_MISSILE_DUMB))) {
/* Must have ammo. */
if(pilot_getAmmo(p, o->outfit) <= 0)
return 0;