[Add] Making room for some beam weapons.

This commit is contained in:
Allanis 2013-09-19 22:15:18 +01:00
parent c8ef8c62fc
commit c969041367
3 changed files with 125 additions and 30 deletions

View File

@ -142,12 +142,39 @@ void outfit_calcDamage(double* dshield, double* darmour, double* knockback,
} }
} }
/* Return 1 if outfit is a weapon (beam/bolt). */ /**
* @fn int outfit_isWeapon(const Outfit* o)
*
* @brief Check if outfit is a fixed mounted weapon.
* @param o Outfit to check.
* @return 1 if o is weapon (beam/bolt).
*/
int outfit_isWeapon(const Outfit* o) { int outfit_isWeapon(const Outfit* o) {
return ((o->type == OUTFIT_TYPE_BOLT) || (o->type == OUTFIT_TYPE_BEAM)); return ((o->type == OUTFIT_TYPE_BOLT) || (o->type == OUTFIT_TYPE_BEAM));
} }
/* Return 1 if outfit is a launcher. */ /**
* @fn int outfit_isBolt(const outfit* o)
*
* @brief Check if outfit is bolt type weapon.
* @param o Outfit to check.
* @return 1 if o is a bolt type weapon.
*/
int outfit_isBolt(const Outfit* o) {
return((o->type == OUTFIT_TYPE_BOLT) || (o->type == OUTFIT_TYPE_TURRET_BOLT));
}
/**
* @fn int outfit_isBeam(const Outfit* o)
*
* @brief Check if outfit is a weapon launcher.
* @param o Outfit to check.
* @return 1 if o is a weapon launcher.
*/
int outfit_isBeam(const Outfit* o) {
return((o->type == OUTFIT_TYPE_BEAM) || (o->type == OUTFIT_TYPE_TURRET_BEAM));
}
int outfit_isLauncher(const Outfit* o) { int outfit_isLauncher(const Outfit* o) {
return((o->type == OUTFIT_TYPE_MISSILE_DUMB) || return((o->type == OUTFIT_TYPE_MISSILE_DUMB) ||
(o->type == OUTFIT_TYPE_MISSILE_SEEK) || (o->type == OUTFIT_TYPE_MISSILE_SEEK) ||
@ -156,7 +183,13 @@ int outfit_isLauncher(const Outfit* o) {
(o->type == OUTFIT_TYPE_MISSILE_SWARM_SMART)); (o->type == OUTFIT_TYPE_MISSILE_SWARM_SMART));
} }
/* Return 1 if outfit is weapon ammunition. */ /**
* @fn int outfit_isAmmo(const Outfit* o)
*
* @brief Check if outfit is ammo for a launcher.
* @param o outfit to check.
* @return 1 if o is ammo.
*/
int outfit_isAmmo(const Outfit* o) { int outfit_isAmmo(const Outfit* o) {
return((o->type == OUTFIT_TYPE_MISSILE_DUMB_AMMO) || return((o->type == OUTFIT_TYPE_MISSILE_DUMB_AMMO) ||
(o->type == OUTFIT_TYPE_MISSILE_SEEK_AMMO) || (o->type == OUTFIT_TYPE_MISSILE_SEEK_AMMO) ||
@ -166,29 +199,61 @@ int outfit_isAmmo(const Outfit* o) {
} }
/**
* @fn int outfit_isTurret(const Outfit* o)
*
* @brief Check if outfit is a turret class weapon.
* @param o Outfit to check.
* @return 1 if o is a turret class weapon.
*/
int outfit_isTurret(const Outfit* o) { int outfit_isTurret(const Outfit* o) {
return ((o->type == OUTFIT_TYPE_TURRET_BOLT) || return ((o->type == OUTFIT_TYPE_TURRET_BOLT) ||
(o->type == OUTFIT_TYPE_TURRET_BEAM)); (o->type == OUTFIT_TYPE_TURRET_BEAM));
} }
/* Return 1 if o is a modification. */ /**
* @fn int outfit_isMod(const Outfit* o)
*
* @breif Check if outfit is a ship modification.
* @param o Outfit to check.
* @return 1 if o is a ship modification.
*/
int outfit_isMod(const Outfit* o) { int outfit_isMod(const Outfit* o) {
return (o->type == OUTFIT_TYPE_MODIFICATION); return (o->type == OUTFIT_TYPE_MODIFICATION);
} }
/* Return 1 if o is an afterburner. */ /**
* @fn int outfit_isAfterburner(const Outfit* o)
* @brief Check if outfit is an afterburner.
* @param o Outfit to check.
* @return 1 if o is an afterburner.
*/
int outfit_isAfterburner(const Outfit* o) { int outfit_isAfterburner(const Outfit* o) {
return (o->type == OUTFIT_TYPE_AFTERBURNER); return (o->type == OUTFIT_TYPE_AFTERBURNER);
} }
/**
* @fn int outfit_isJammer(const Outfit* o)
*
* @brief Check if outfit is a missile jammer.
* @param o Outfit to check.
* @return 1 if o is a jammer.
*/
int outfit_isJammer(const Outfit* o) {
return(o->type == OUTFIT_TYPE_JAMMER);
}
/**
* @fn int outfit_isMap(const Outfit* o)
*
* @brief Check if outfit is a space map.
* @param o Outfit to check.
* @return 1 if o is a map.
*/
int outfit_isMap(const Outfit* o) { int outfit_isMap(const Outfit* o) {
return(o->type == OUTFIT_TYPE_MAP); return(o->type == OUTFIT_TYPE_MAP);
} }
/* Return 1 if o is a jammer. */
int outfit_isJammer(const Outfit* o) {
return(o->type == OUTFIT_TYPE_JAMMER);
}
/* Get the outfit graphics. */ /* Get the outfit graphics. */
glTexture* outfit_gfx(const Outfit* o) { glTexture* outfit_gfx(const Outfit* o) {

View File

@ -73,7 +73,7 @@ typedef struct Outfit_ {
} blt; } blt;
struct { /* Beam. */ struct { /* Beam. */
double range; /* Distance it travels. */ double range; /* Distance it travels. */
glColour colour; /* Beam colour. */ glColour* colour; /* Beam colour. */
double energy; /* Energy drained. */ double energy; /* Energy drained. */
double damage_armour, damage_shield; /* Damage. */ double damage_armour, damage_shield; /* Damage. */
} bem; } bem;
@ -137,6 +137,8 @@ Outfit* outfit_get(const char* name);
char** outfit_getTech(int* n, const int* tech, const int techmax); char** outfit_getTech(int* n, const int* tech, const int techmax);
/* Outfit types. */ /* Outfit types. */
int outfit_isWeapon(const Outfit* o); int outfit_isWeapon(const Outfit* o);
int outfit_isBolt(const Outfit* o);
int outfit_isBeam(const Outfit* o);
int outfit_isLauncher(const Outfit* o); int outfit_isLauncher(const Outfit* o);
int outfit_isAmmo(const Outfit* o); int outfit_isAmmo(const Outfit* o);
int outfit_isTurret(const Outfit* o); int outfit_isTurret(const Outfit* o);

View File

@ -260,6 +260,8 @@ static void weapons_updateLayer(const double dt, const WeaponLayer layer) {
case OUTFIT_TYPE_BOLT: case OUTFIT_TYPE_BOLT:
case OUTFIT_TYPE_TURRET_BOLT: case OUTFIT_TYPE_TURRET_BOLT:
case OUTFIT_TYPE_MISSILE_DUMB_AMMO: /* Dumb missiles are like bolts. */ case OUTFIT_TYPE_MISSILE_DUMB_AMMO: /* Dumb missiles are like bolts. */
case OUTFIT_TYPE_BEAM: /* Timer usage is actually more complicated for beams.. */
case OUTFIT_TYPE_TURRET_BEAM:
wlayer[i]->timer -= dt; wlayer[i]->timer -= dt;
if(wlayer[i]->timer < 0.) { if(wlayer[i]->timer < 0.) {
weapon_destroy(wlayer[i],layer); weapon_destroy(wlayer[i],layer);
@ -302,12 +304,35 @@ static void weapon_render(const Weapon* w) {
int sx, sy; int sx, sy;
glTexture* gfx; glTexture* gfx;
gfx = outfit_gfx(w->outfit); switch(w->outfit->type) {
case OUTFIT_TYPE_MISSILE_SEEK_AMMO:
case OUTFIT_TYPE_MISSILE_SEEK_SMART_AMMO:
case OUTFIT_TYPE_MISSILE_SWARM_AMMO:
case OUTFIT_TYPE_MISSILE_SWARM_SMART_AMMO:
case OUTFIT_TYPE_BOLT:
case OUTFIT_TYPE_TURRET_BOLT:
case OUTFIT_TYPE_MISSILE_DUMB_AMMO:
gfx = outfit_gfx(w->outfit);
/* Get the sprite corresponding to the direction facing. */
gl_getSpriteFromDir(&sx, &sy, gfx, w->solid->dir);
gl_blitSprite(gfx, w->solid->pos.x, w->solid->pos.y, sx, sy, NULL);
break;
/* Get the sprite corresponding to the direction facing. */ /* Beam weapons. */
gl_getSpriteFromDir(&sx, &sy, gfx, w->solid->dir); case OUTFIT_TYPE_BEAM:
case OUTFIT_TYPE_TURRET_BEAM:
glBegin(GL_LINES);
glVertex2d(w->solid->pos.x, w->solid->pos.y);
glVertex2d(w->solid->pos.x + w->outfit->u.bem.range*cos(w->solid->dir),
w->solid->pos.y + w->outfit->u.bem.range*sin(w->solid->dir));
glEnd();
break;
gl_blitSprite(gfx, w->solid->pos.x, w->solid->pos.y, sx, sy, NULL); default:
WARN("Weapon of type '%s' has no render implmented yet!!!",
w->outfit->name);
break;
}
} }
/* Update the weapon. */ /* Update the weapon. */
@ -329,22 +354,25 @@ 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. */
/* Smart weapons only collide with their target. */ /* Smart weapons only collide with their target. */
if((weapon_isSmart(w)) && (pilot_stack[i]->id == w->target) && if(weapon_isSmart(w)) {
CollideSprite(gfx, wsx, wsy, &w->solid->pos, if((pilot_stack[i]->id == w->target) &&
pilot_stack[i]->ship->gfx_space, psx, psy, &pilot_stack[i]->solid->pos, CollideSprite(gfx, wsx, wsy, &w->solid->pos,
&crash)) { pilot_stack[i]->ship->gfx_space, psx, psy, &pilot_stack[i]->solid->pos,
&crash)) {
weapon_hit(w, pilot_stack[i], layer, &crash); weapon_hit(w, pilot_stack[i], layer, &crash);
return; return;
} }
/* Dumb weapons hit anything not of the same faction. */ /* Dumb weapons hit anything not of the same faction. */
if(!weapon_isSmart(w) && else if(!weapon_isSmart(w) &&
!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)) {
weapon_hit(w, pilot_stack[i], layer, &crash);
return; weapon_hit(w, pilot_stack[i], layer, &crash);
return;
}
} }
} }