From 70d4987a00ace5238226e1cc78989f1f78b68077 Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Sun, 29 Sep 2013 21:25:59 +0100
Subject: [PATCH] [Add] starting to add sound for beam weapons. Sound system
 could do with an overhaul tbh.

---
 src/music.c  |  2 +-
 src/outfit.c | 24 ++++++++++++++++++++++++
 src/outfit.h |  5 ++++-
 src/pilot.c  |  2 +-
 src/sound.c  |  2 +-
 src/weapon.c |  6 ++++++
 6 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/src/music.c b/src/music.c
index f874dc1..5711d38 100644
--- a/src/music.c
+++ b/src/music.c
@@ -3,7 +3,7 @@
  * @brief Control all the music playing.
  */
 
-#include <SDL_mixer.h>
+#include <SDL/SDL_mixer.h>
 #include <SDL.h>
 
 #include "llua.h"
diff --git a/src/outfit.c b/src/outfit.c
index 9efc09f..8f7aeef 100644
--- a/src/outfit.c
+++ b/src/outfit.c
@@ -564,6 +564,11 @@ static void outfit_parseSBeam(Outfit* tmp, const xmlNodePtr parent) {
   xmlNodePtr node;
   char str[PATH_MAX] = "\0";
 
+  /* Defaults. */
+  tmp->u.bem.sound_warmup = -1;
+  tmp->u.bem.sound        = -1;
+  tmp->u.bem.sound_off    = -1;
+
   node = parent->xmlChildrenNode;
   do {  /* Load all the data. */
     xmlr_float(node, "range",     tmp->u.bem.range);
@@ -584,10 +589,29 @@ static void outfit_parseSBeam(Outfit* tmp, const xmlNodePtr parent) {
       tmp->u.bem.gfx = gl_newSprite(str, 1, 1);
       continue;
     }
+
+    if(xml_isNode(node, "sound_warmup")) {
+      tmp->u.bem.sound_warmup = sound_get(xml_get(node));
+      continue;
+    }
+
+    if(xml_isNode(node, "sound")) {
+      tmp->u.bem.sound = sound_get(xml_get(node));
+      continue;
+    }
+
+    if(xml_isNode(node, "sound_off")) {
+      tmp->u.bem.sound_off = sound_get(xml_get(node));
+      continue;
+    }
+
   } while(xml_nextNode(node));
   
 #define MELEMENT(o,s) if(0) WARN("Outfit '%s' missing/invalid '"s"' element", tmp->name)
   MELEMENT(tmp->u.bem.gfx==NULL,    "gfx");
+  MELEMENT((sound_disabled!=0) && (tmp->u.bem.warmup > 0.) && (tmp->u.bem.sound<0), "sound_warmup");
+  MELEMENT((sound_disabled!=0) && (tmp->u.bem.sound < 0), "sound");
+  MELEMENT((sound_disabled!=0) && (tmp->u.bem.sound_off < 0), "sound_off");
   MELEMENT(tmp->u.bem.delay==0,     "range");
   MELEMENT(tmp->u.bem.duration==0,  "duration");
   MELEMENT(tmp->u.bem.range==0,     "range");
diff --git a/src/outfit.h b/src/outfit.h
index e4ba241..f28bbdf 100644
--- a/src/outfit.h
+++ b/src/outfit.h
@@ -77,8 +77,11 @@ typedef struct OutfitBeamData_ {
   DamageType dtype;       /**< Damage type. */
   double damage;          /**< Damage amount. */
 
-  /* Graphics */
+  /* Graphics and sound */
   glTexture* gfx;         /**< Base texture. */
+  int sound_warmup;       /**< Sound to play when warming up. @todo use. */
+  int sound;              /**< Sound to play. */
+  int sound_off;          /**< Sound to play when turning off. */
 } OutfitBeamData;
 
 /**
diff --git a/src/pilot.c b/src/pilot.c
index f838c76..069658e 100644
--- a/src/pilot.c
+++ b/src/pilot.c
@@ -255,7 +255,7 @@ static void pilot_shootWeapon(Pilot* p, PilotOutfit* w, const unsigned int t) {
     /** @todo Handle warmup stage. */
     w->state = PILOT_OUTFIT_ON;
     weapon_add(w->outfit, p->solid->dir,
-        &p->solid->pos, NULL, p->id, t);
+        &p->solid->pos, &p->solid->vel, p->id, t);
   }
 
   /*
diff --git a/src/sound.c b/src/sound.c
index 171c487..9830e68 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -7,7 +7,7 @@
 #include <sys/stat.h>
 
 #include <SDL.h>
-#include <SDL_mixer.h>
+#include <SDL/SDL_mixer.h>
 
 #include "lephisto.h"
 #include "log.h"
diff --git a/src/weapon.c b/src/weapon.c
index 5d9a5b3..e6b1981 100644
--- a/src/weapon.c
+++ b/src/weapon.c
@@ -308,6 +308,9 @@ static void weapons_updateLayer(const double dt, const WeaponLayer layer) {
     case OUTFIT_TYPE_TURRET_BEAM:
       wlayer[i]->timer -= dt;
       if(wlayer[i]->timer < 0.) {
+        sound_playPos(w->outfit->u.bem.sound_off,
+            w->solid->pos.x,
+            w->solid->pos.y);
         weapon_destroy(wlayer[i],layer);
         continue;
       }
@@ -639,6 +642,9 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2*
       w->solid = solid_create(mass, rdir, pos, NULL);
       w->think = think_beam;
       w->timer = outfit->u.bem.duration;
+      sound_playPos(w->outfit->u.bem.sound,
+          w->solid->pos.x + vel->x,
+          w->solid->pos.y + vel->y);
       break;
   
   /* Treat seekers togther. */