]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Begin adding a new sounds system for monsters (based on player sounds)
authorMario <mario.mario@y7mail.com>
Sun, 1 Sep 2013 23:38:31 +0000 (09:38 +1000)
committerMario <mario.mario@y7mail.com>
Sun, 1 Sep 2013 23:38:31 +0000 (09:38 +1000)
models/monsters/zombie.dpm_0.sounds [new file with mode: 0644]
qcsrc/common/monsters/sv_monsters.qc
qcsrc/common/monsters/sv_monsters.qh
sound/monsters/zombie/death.ogg [new file with mode: 0644]
sound/monsters/zombie/idle.ogg [new file with mode: 0644]
sound/monsters/zombie/sight.ogg [new file with mode: 0644]
sound/monsters/zombie_death.ogg [deleted file]
sound/monsters/zombie_idle.ogg [deleted file]
sound/monsters/zombie_sight.ogg [deleted file]

diff --git a/models/monsters/zombie.dpm_0.sounds b/models/monsters/zombie.dpm_0.sounds
new file mode 100644 (file)
index 0000000..7a7cff6
--- /dev/null
@@ -0,0 +1,8 @@
+//TAG: zombie
+death sound/monsters/zombie/death 0
+sight sound/monsters/zombie/sight 0
+//ranged sound/monsters/zombie/ranged 0
+//melee sound/monsters/zombie/melee 0
+//pain sound/monsters/zombie/pain 0
+spawn sound/monsters/zombie/spawn 0
+idle sound/monsters/zombie/idle 0
index 95b351997832015d2515e8dcf2e07ed31ca635c8..dd080160e33c91a1f47964f77640eb1879123ca2 100644 (file)
@@ -173,37 +173,125 @@ void MonsterTouch ()
                self.enemy = other;
 }
 
-void monster_sound(string msound, float sound_delay, float delaytoo)
+string get_monster_model_datafilename(string m, float sk, string fil)
 {
-       if(delaytoo && time < self.msound_delay)
-               return; // too early
-               
-       if(msound == "")
-               return; // sound doesn't exist
+       if(m)
+               m = strcat(m, "_");
+       else
+               m = "models/monsters/*_";
+       if(sk >= 0)
+               m = strcat(m, ftos(sk));
+       else
+               m = strcat(m, "*");
+       return strcat(m, ".", fil);
+}
 
-       sound(self, CHAN_AUTO, msound, VOL_BASE, ATTEN_NORM);
+void PrecacheMonsterSounds(string f)
+{
+       float fh;
+       string s;
+       fh = fopen(f, FILE_READ);
+       if(fh < 0)
+               return;
+       while((s = fgets(fh)))
+       {
+               if(tokenize_console(s) != 3)
+               {
+                       dprint("Invalid sound info line: ", s, "\n");
+                       continue;
+               }
+               PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
+       }
+       fclose(fh);
+}
 
-       self.msound_delay = time + sound_delay;
+void precache_monstersounds()
+{
+       string m = (get_monsterinfo(self.monsterid)).model;
+       float globhandle, n, i;
+       string f;
+       
+       globhandle = search_begin(strcat(m, "_*.sounds"), TRUE, FALSE);
+       if (globhandle < 0)
+               return;
+       n = search_getsize(globhandle);
+       for (i = 0; i < n; ++i)
+       {
+               //print(search_getfilename(globhandle, i), "\n");
+               f = search_getfilename(globhandle, i);
+               PrecacheMonsterSounds(f);
+       }
+       search_end(globhandle);
 }
 
-void monster_precachesounds(entity e)
+void ClearMonsterSounds()
 {
-       precache_sound(e.msound_idle);
-       precache_sound(e.msound_death);
-       precache_sound(e.msound_attack_melee);
-       precache_sound(e.msound_attack_ranged);
-       precache_sound(e.msound_sight);
-       precache_sound(e.msound_pain);
+#define _MSOUND(m) if(self.monstersound_##m) { strunzone(self.monstersound_##m); self.monstersound_##m = string_null; }
+       ALLMONSTERSOUNDS
+#undef _MSOUND
 }
 
-void monster_setupsounds(string mon)
+.string GetMonsterSoundSampleField(string type)
 {
-       if(self.msound_idle == "") self.msound_idle = strzone(strcat("monsters/", mon, "_idle.wav"));
-       if(self.msound_death == "") self.msound_death = strzone(strcat("monsters/", mon, "_death.wav"));
-       if(self.msound_pain == "") self.msound_pain = strzone(strcat("monsters/", mon, "_pain.wav"));
-       if(self.msound_attack_melee == "") self.msound_attack_melee = strzone(strcat("monsters/", mon, "_melee.wav"));
-       if(self.msound_attack_ranged == "") self.msound_attack_ranged = strzone(strcat("monsters/", mon, "_attack.wav"));
-       if(self.msound_sight == "") self.msound_sight = strzone(strcat("monsters/", mon, "_sight.wav"));
+       GetMonsterSoundSampleField_notFound = 0;
+       switch(type)
+       {
+#define _MSOUND(m) case #m: return monstersound_##m;
+               ALLMONSTERSOUNDS
+#undef _MSOUND
+       }
+       GetMonsterSoundSampleField_notFound = 1;
+       return string_null;
+}
+
+float LoadMonsterSounds(string f, float first)
+{
+       float fh;
+       string s;
+       var .string field;
+       fh = fopen(f, FILE_READ);
+       if(fh < 0)
+       {
+               dprint("Monster sound file not found: ", f, "\n");
+               return 0;
+       }
+       while((s = fgets(fh)))
+       {
+               if(tokenize_console(s) != 3)
+                       continue;
+               field = GetMonsterSoundSampleField(argv(0));
+               if(GetMonsterSoundSampleField_notFound)
+                       continue;
+               if(self.field)
+                       strunzone(self.field);
+               self.field = strzone(strcat(argv(1), " ", argv(2)));
+       }
+       fclose(fh);
+       return 1;
+}
+
+.float skin_for_monstersound;
+void UpdateMonsterSounds()
+{
+       entity mon = get_monsterinfo(self.monsterid);
+       
+       if(self.skin == self.skin_for_monstersound)
+               return;
+       self.skin_for_monstersound = self.skin;
+       ClearMonsterSounds();
+       //LoadMonsterSounds("sound/monsters/default.sounds", 1);
+       if(!autocvar_g_debug_defaultsounds)
+       if(!LoadMonsterSounds(get_monster_model_datafilename(mon.model, self.skin, "sounds"), 0))
+               LoadMonsterSounds(get_monster_model_datafilename(mon.model, 0, "sounds"), 0);
+}
+
+void MonsterSound(.string samplefield, float sound_delay, float delaytoo, float chan)
+{
+       if(delaytoo && time < self.msound_delay)
+               return; // too early
+       GlobalSound(self.samplefield, chan, VOICETYPE_PLAYERSOUND);
+       
+       self.msound_delay = time + sound_delay;
 }
 
 void monster_makevectors(entity e)
@@ -359,14 +447,16 @@ void monster_checkattack(entity e, entity targ)
        if(vlen(targ.origin - e.origin) <= e.attack_range)
        if(e.monster_attackfunc(MONSTER_ATTACK_MELEE))
        {
-               monster_sound(e.msound_attack_melee, 0, FALSE);
+               //monster_sound(e.msound_attack_melee, 0, FALSE);
+               MonsterSound(monstersound_melee, 0, FALSE, CH_VOICE);
                return;
        }
        
        if(vlen(targ.origin - e.origin) > e.attack_range)
        if(e.monster_attackfunc(MONSTER_ATTACK_RANGED))
        {
-               monster_sound(e.msound_attack_ranged, 0, FALSE);
+               //monster_sound(e.msound_attack_ranged, 0, FALSE);
+               MonsterSound(monstersound_ranged, 0, FALSE, CH_VOICE);
                return;
        }
 }
@@ -559,7 +649,8 @@ void monster_move(float runspeed, float walkspeed, float stopspeed, float manim_
                {
                        self.enemy = FindTarget(self);
                        if(self.enemy)
-                               monster_sound(self.msound_sight, 0, FALSE);
+                               MonsterSound(monstersound_sight, 0, FALSE, CH_VOICE);
+                               //monster_sound(self.msound_sight, 0, FALSE);
                }
                        
                self.last_enemycheck = time + 2;
@@ -573,7 +664,8 @@ void monster_move(float runspeed, float walkspeed, float stopspeed, float manim_
                self.moveto = monster_pickmovetarget(targ);
 
        if not(self.enemy)
-               monster_sound(self.msound_idle, 5, TRUE);
+               MonsterSound(monstersound_idle, 5, TRUE, CH_VOICE);
+               //monster_sound(self.msound_idle, 5, TRUE);
        
        if(self.state != MONSTER_STATE_ATTACK_LEAP && self.state != MONSTER_STATE_ATTACK_MELEE)
                self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
@@ -808,8 +900,9 @@ void monster_die()
        self.ltime = time + 5;
        
        monster_dropitem();
-               
-       monster_sound(self.msound_death, 0, FALSE);
+       
+       MonsterSound(monstersound_death, 0, FALSE, CH_VOICE);
+       //monster_sound(self.msound_death, 0, FALSE);
                
        if(!(self.spawnflags & MONSTERFLAG_SPAWNED) && !self.monster_respawned)
                monsters_killed += 1;
@@ -939,14 +1032,16 @@ void monster_spawn()
        
        self.pos1 = self.origin;
        
-       monster_setupsounds(self.netname);
-
-       monster_precachesounds(self);
+       //monster_setupsounds(self.netname);
+       precache_monstersounds();
+       UpdateMonsterSounds();
+       //monster_precachesounds(self);
        
        if(teamplay)
                self.monster_attack = TRUE; // we can have monster enemies in team games
        
-       monster_sound(self.msound_spawn, 0, FALSE);
+       //monster_sound(self.msound_spawn, 0, FALSE);
+       MonsterSound(monstersound_spawn, 0, FALSE, CH_VOICE);
        
        self.think = monster_think;
        self.nextthink = time + self.ticrate;
index bd3c7779236e770c2caf414f550b9615999b4fea..1f210235f5f7be8a0070dcb78e465926019fcfe3 100644 (file)
@@ -32,6 +32,23 @@ const float MONSTER_ATTACK_RANGED    = 2;
 
 .float m_armor_blockpercent;
 
+// monster sounds
+// copied from player sounds
+#define ALLMONSTERSOUNDS \
+               _MSOUND(death) \
+               _MSOUND(sight) \
+               _MSOUND(ranged) \
+               _MSOUND(melee) \
+               _MSOUND(pain) \
+               _MSOUND(spawn) \
+               _MSOUND(idle) 
+
+#define _MSOUND(m) .string monstersound_##m;
+ALLMONSTERSOUNDS
+#undef _MSOUND
+
+float GetMonsterSoundSampleField_notFound;
+
 .float monster_respawned; // used to make sure we're not recounting respawned monster stats
 
 const float MONSTERSKILL_NOTEASY = 256; // monster will not spawn on skill <= 1
diff --git a/sound/monsters/zombie/death.ogg b/sound/monsters/zombie/death.ogg
new file mode 100644 (file)
index 0000000..7af422e
Binary files /dev/null and b/sound/monsters/zombie/death.ogg differ
diff --git a/sound/monsters/zombie/idle.ogg b/sound/monsters/zombie/idle.ogg
new file mode 100644 (file)
index 0000000..3dac288
Binary files /dev/null and b/sound/monsters/zombie/idle.ogg differ
diff --git a/sound/monsters/zombie/sight.ogg b/sound/monsters/zombie/sight.ogg
new file mode 100644 (file)
index 0000000..c033a9e
Binary files /dev/null and b/sound/monsters/zombie/sight.ogg differ
diff --git a/sound/monsters/zombie_death.ogg b/sound/monsters/zombie_death.ogg
deleted file mode 100644 (file)
index 7af422e..0000000
Binary files a/sound/monsters/zombie_death.ogg and /dev/null differ
diff --git a/sound/monsters/zombie_idle.ogg b/sound/monsters/zombie_idle.ogg
deleted file mode 100644 (file)
index 3dac288..0000000
Binary files a/sound/monsters/zombie_idle.ogg and /dev/null differ
diff --git a/sound/monsters/zombie_sight.ogg b/sound/monsters/zombie_sight.ogg
deleted file mode 100644 (file)
index c033a9e..0000000
Binary files a/sound/monsters/zombie_sight.ogg and /dev/null differ