diff --git a/src/outfit.c b/src/outfit.c index 3db25e4..e745df2 100644 --- a/src/outfit.c +++ b/src/outfit.c @@ -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) { 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) { return((o->type == OUTFIT_TYPE_MISSILE_DUMB) || (o->type == OUTFIT_TYPE_MISSILE_SEEK) || @@ -156,7 +183,13 @@ int outfit_isLauncher(const Outfit* o) { (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) { return((o->type == OUTFIT_TYPE_MISSILE_DUMB_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) { return ((o->type == OUTFIT_TYPE_TURRET_BOLT) || (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) { 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) { 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) { 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. */ glTexture* outfit_gfx(const Outfit* o) { diff --git a/src/outfit.h b/src/outfit.h index f6e090f..63c89cc 100644 --- a/src/outfit.h +++ b/src/outfit.h @@ -73,7 +73,7 @@ typedef struct Outfit_ { } blt; struct { /* Beam. */ double range; /* Distance it travels. */ - glColour colour; /* Beam colour. */ + glColour* colour; /* Beam colour. */ double energy; /* Energy drained. */ double damage_armour, damage_shield; /* Damage. */ } bem; @@ -137,6 +137,8 @@ Outfit* outfit_get(const char* name); char** outfit_getTech(int* n, const int* tech, const int techmax); /* Outfit types. */ 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_isAmmo(const Outfit* o); int outfit_isTurret(const Outfit* o); diff --git a/src/weapon.c b/src/weapon.c index 0b7f2ac..650b348 100644 --- a/src/weapon.c +++ b/src/weapon.c @@ -260,6 +260,8 @@ static void weapons_updateLayer(const double dt, const WeaponLayer layer) { case OUTFIT_TYPE_BOLT: case OUTFIT_TYPE_TURRET_BOLT: 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; if(wlayer[i]->timer < 0.) { weapon_destroy(wlayer[i],layer); @@ -302,12 +304,35 @@ static void weapon_render(const Weapon* w) { int sx, sy; 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. */ - gl_getSpriteFromDir(&sx, &sy, gfx, w->solid->dir); + /* Beam weapons. */ + 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. */ @@ -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. */ /* Smart weapons only collide with their target. */ - if((weapon_isSmart(w)) && (pilot_stack[i]->id == w->target) && - CollideSprite(gfx, wsx, wsy, &w->solid->pos, - pilot_stack[i]->ship->gfx_space, psx, psy, &pilot_stack[i]->solid->pos, - &crash)) { - - weapon_hit(w, pilot_stack[i], layer, &crash); - return; - } - /* Dumb weapons hit anything not of the same faction. */ - if(!weapon_isSmart(w) && - !areAllies(w->faction, pilot_stack[i]->faction) && - CollideSprite(gfx, wsx, wsy, &w->solid->pos, - pilot_stack[i]->ship->gfx_space, psx, psy, &pilot_stack[i]->solid->pos, - &crash)) { - weapon_hit(w, pilot_stack[i], layer, &crash); - return; + if(weapon_isSmart(w)) { + if((pilot_stack[i]->id == w->target) && + CollideSprite(gfx, wsx, wsy, &w->solid->pos, + pilot_stack[i]->ship->gfx_space, psx, psy, &pilot_stack[i]->solid->pos, + &crash)) { + + weapon_hit(w, pilot_stack[i], layer, &crash); + return; + } + /* Dumb weapons hit anything not of the same faction. */ + else if(!weapon_isSmart(w) && + !areAllies(w->faction, pilot_stack[i]->faction) && + CollideSprite(gfx, wsx, wsy, &w->solid->pos, + pilot_stack[i]->ship->gfx_space, psx, psy, &pilot_stack[i]->solid->pos, + &crash)) { + + weapon_hit(w, pilot_stack[i], layer, &crash); + return; + } } }