[Add] Some more beam support stuff.
This commit is contained in:
parent
c969041367
commit
8bf7a67af7
96
src/weapon.c
96
src/weapon.c
@ -73,6 +73,7 @@ static void weapon_destroy(Weapon* w, WeaponLayer layer);
|
|||||||
static void weapon_free(Weapon* w);
|
static void weapon_free(Weapon* w);
|
||||||
/* Think. */
|
/* Think. */
|
||||||
static void think_seeker(Weapon* w, const double dt);
|
static void think_seeker(Weapon* w, const double dt);
|
||||||
|
static void think_beam(Weapon* w, const double dt);
|
||||||
/*static void think_smart(Weapon* w, const double dt);*/
|
/*static void think_smart(Weapon* w, const double dt);*/
|
||||||
/* Extern. */
|
/* Extern. */
|
||||||
void weapon_minimap(const double res, const double w,
|
void weapon_minimap(const double res, const double w,
|
||||||
@ -177,48 +178,41 @@ static void think_seeker(Weapon* w, const double dt) {
|
|||||||
/*limit_speed(&w->solid->vel, w->outfit->u.amm.speed, dt);*/
|
/*limit_speed(&w->solid->vel, w->outfit->u.amm.speed, dt);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================================================
|
/**
|
||||||
* Smart seeker brain. Much better at homing.
|
* @fn static void think_beam(Weapon* w, const double dt)
|
||||||
* ========================================================
|
*
|
||||||
|
* @brief The Pseudo-ai of the beam weapons.
|
||||||
|
* @param w Weapon to do the thinking.
|
||||||
|
* @return dt Current delta tick.
|
||||||
*/
|
*/
|
||||||
#if 0
|
static void think_beam(Weapon* w, const double dt) {
|
||||||
static void think_smart(Weapon* w, const double dt) {
|
(void) dt;
|
||||||
Vec2 sv, tv;
|
Pilot* p;
|
||||||
double t;
|
|
||||||
|
|
||||||
if(w->target == w->parent) return; /* No self shooting here. */
|
|
||||||
|
|
||||||
Pilot* p = pilot_get(w->target); /* No null pilots.. */
|
|
||||||
|
|
||||||
|
/* Get pilot, if pilot is dead beam is destroyed too. */
|
||||||
|
p = pilot_get(w->parent);
|
||||||
if(p == NULL) {
|
if(p == NULL) {
|
||||||
limit_speed(&w->solid->vel, w->outfit->u.amm.speed, dt);
|
w->timer = -1; /* Hack to make it get destroyed next update. */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ammo isn't locked on yet. */
|
/* Update beam position to match pilot. */
|
||||||
if(w->lockon < 0.) {
|
w->solid->pos.x = p->solid->pos.x;
|
||||||
vect_cset(&tv, VX(p->solid->pos) + dt*VX(p->solid->vel),
|
w->solid->pos.y = p->solid->pos.y;
|
||||||
VY(p->solid->pos) + dt*VY(p->solid->vel));
|
|
||||||
|
|
||||||
vect_cset(&sv, VX(w->solid->pos) + dt*VX(w->solid->vel),
|
/* Handle aiming. */
|
||||||
VY(w->solid->pos) + dt*VY(w->solid->vel));
|
switch(w->outfit->type) {
|
||||||
|
case OUTFIT_TYPE_BEAM:
|
||||||
t = -angle_diff(w->solid->dir, vect_angle(&tv, &sv));
|
w->solid->dir = p->solid->dir;
|
||||||
|
break;
|
||||||
w->solid->dir_vel = t * w->outfit->u.amm.turn; /* Face the target. */
|
case OUTFIT_TYPE_TURRET_BEAM:
|
||||||
|
/** @todo Have beam turret aim independently. */
|
||||||
if(w->solid->dir_vel > w->outfit->u.amm.turn)
|
w->solid->dir = p->solid->dir;
|
||||||
w->solid->dir_vel = w->outfit->u.amm.turn;
|
break;
|
||||||
else if(w->solid->dir_vel < -w->outfit->u.amm.turn)
|
default:
|
||||||
w->solid->dir_vel = -w->outfit->u.amm.turn;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
vect_pset(&w->solid->vel, w->outfit->u.amm.speed, w->solid->dir);
|
|
||||||
|
|
||||||
limit_speed(&w->solid->vel, w->outfit->u.amm.speed, dt);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Update all the weapon layers. */
|
/* Update all the weapon layers. */
|
||||||
void weapons_update(const double dt) {
|
void weapons_update(const double dt) {
|
||||||
@ -339,7 +333,7 @@ static void weapon_render(const Weapon* w) {
|
|||||||
static void weapon_update(Weapon* w, const double dt, WeaponLayer layer) {
|
static void weapon_update(Weapon* w, const double dt, WeaponLayer layer) {
|
||||||
int i, wsx, wsy, psx, psy;
|
int i, wsx, wsy, psx, psy;
|
||||||
glTexture* gfx;
|
glTexture* gfx;
|
||||||
Vec2 crash;
|
Vec2 crash[2];
|
||||||
|
|
||||||
gfx = outfit_gfx(w->outfit);
|
gfx = outfit_gfx(w->outfit);
|
||||||
|
|
||||||
@ -353,14 +347,30 @@ static void weapon_update(Weapon* w, const double dt, WeaponLayer layer) {
|
|||||||
|
|
||||||
if(w->parent == pilot_stack[i]->id) continue; /* Hey! That's you. */
|
if(w->parent == pilot_stack[i]->id) continue; /* Hey! That's you. */
|
||||||
|
|
||||||
|
/* Beam weapons have special collisions. */
|
||||||
|
if(outfit_isBeam(w->outfit)) {
|
||||||
|
if(!areAllies(w->faction, pilot_stack[i]->faction) &&
|
||||||
|
CollideLineSprite(&w->solid->pos, w->solid->dir,
|
||||||
|
w->outfit->u.bem.range,
|
||||||
|
pilot_stack[i]->ship->gfx_space, psx, psy,
|
||||||
|
&pilot_stack[i]->solid->pos,
|
||||||
|
crash)) {
|
||||||
|
|
||||||
|
/** @todo beam_hit Needs it's own function. */
|
||||||
|
|
||||||
|
/* No return because beam can still think, it's not
|
||||||
|
* destroyed like the other weapons. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Smart weapons only collide with their target. */
|
/* Smart weapons only collide with their target. */
|
||||||
if(weapon_isSmart(w)) {
|
else if(weapon_isSmart(w)) {
|
||||||
if((pilot_stack[i]->id == w->target) &&
|
if((pilot_stack[i]->id == w->target) &&
|
||||||
CollideSprite(gfx, wsx, wsy, &w->solid->pos,
|
CollideSprite(gfx, wsx, wsy, &w->solid->pos,
|
||||||
pilot_stack[i]->ship->gfx_space, psx, psy, &pilot_stack[i]->solid->pos,
|
pilot_stack[i]->ship->gfx_space, psx, psy, &pilot_stack[i]->solid->pos,
|
||||||
&crash)) {
|
&crash[0])) {
|
||||||
|
|
||||||
weapon_hit(w, pilot_stack[i], layer, &crash);
|
weapon_hit(w, pilot_stack[i], layer, &crash[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* Dumb weapons hit anything not of the same faction. */
|
/* Dumb weapons hit anything not of the same faction. */
|
||||||
@ -368,9 +378,9 @@ static void weapon_update(Weapon* w, const double dt, WeaponLayer layer) {
|
|||||||
!areAllies(w->faction, pilot_stack[i]->faction) &&
|
!areAllies(w->faction, pilot_stack[i]->faction) &&
|
||||||
CollideSprite(gfx, wsx, wsy, &w->solid->pos,
|
CollideSprite(gfx, wsx, wsy, &w->solid->pos,
|
||||||
pilot_stack[i]->ship->gfx_space, psx, psy, &pilot_stack[i]->solid->pos,
|
pilot_stack[i]->ship->gfx_space, psx, psy, &pilot_stack[i]->solid->pos,
|
||||||
&crash)) {
|
&crash[0])) {
|
||||||
|
|
||||||
weapon_hit(w, pilot_stack[i], layer, &crash);
|
weapon_hit(w, pilot_stack[i], layer, &crash[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -475,6 +485,14 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2*
|
|||||||
w->solid->pos.y + w->solid->vel.y);
|
w->solid->pos.y + w->solid->vel.y);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* Beam weapons are treated together. */
|
||||||
|
case OUTFIT_TYPE_BEAM:
|
||||||
|
case OUTFIT_TYPE_TURRET_BEAM:
|
||||||
|
mass = 1.;
|
||||||
|
w->solid = solid_create(mass, dir, pos, NULL);
|
||||||
|
w->think = think_beam;
|
||||||
|
break;
|
||||||
|
|
||||||
/* Treat seekers togther. */
|
/* Treat seekers togther. */
|
||||||
case OUTFIT_TYPE_MISSILE_SEEK_AMMO:
|
case OUTFIT_TYPE_MISSILE_SEEK_AMMO:
|
||||||
case OUTFIT_TYPE_MISSILE_SEEK_SMART_AMMO:
|
case OUTFIT_TYPE_MISSILE_SEEK_SMART_AMMO:
|
||||||
|
Loading…
Reference in New Issue
Block a user