[Change] Better handling of secondary weapons.
This commit is contained in:
parent
acc4ce6547
commit
230329f868
18
src/ai.c
18
src/ai.c
@ -1298,6 +1298,7 @@ static int ai_aim(lua_State* L) {
|
|||||||
Vec2 tv;
|
Vec2 tv;
|
||||||
double dist, diff;
|
double dist, diff;
|
||||||
double mod;
|
double mod;
|
||||||
|
double speed;
|
||||||
LLUA_MIN_ARGS(1);
|
LLUA_MIN_ARGS(1);
|
||||||
|
|
||||||
/* Only acceptable parameter is pilot id. */
|
/* Only acceptable parameter is pilot id. */
|
||||||
@ -1316,8 +1317,16 @@ static int ai_aim(lua_State* L) {
|
|||||||
/* Get the distance. */
|
/* Get the distance. */
|
||||||
dist = vect_dist(&cur_pilot->solid->pos, &p->solid->pos);
|
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. */
|
/* Time for shots to reach distance. */
|
||||||
t = dist / cur_pilot->weap_speed;
|
t = dist / speed;
|
||||||
|
|
||||||
/* Position is calculated on where it should be. */
|
/* Position is calculated on where it should be. */
|
||||||
x = p->solid->pos.x + p->solid->vel.x*t
|
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) {
|
static int outfit_isMelee(Pilot* p, PilotOutfit* o) {
|
||||||
(void)p;
|
(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 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1380,7 +1390,9 @@ static int outfit_isMelee(Pilot* p, PilotOutfit* o) {
|
|||||||
* @param o Outfit to check.
|
* @param o Outfit to check.
|
||||||
*/
|
*/
|
||||||
static int outfit_isRanged(Pilot* p, PilotOutfit* o) {
|
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. */
|
/* Must have ammo. */
|
||||||
if(pilot_getAmmo(p, o->outfit) <= 0)
|
if(pilot_getAmmo(p, o->outfit) <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user