Sorry guys, my bad, I realised that I had made a fair few changes to the sound patch since the last time it was posted. Here it is:
Index: code/gamesnd/gamesnd.cpp
===================================================================
--- code/gamesnd/gamesnd.cpp (revision 8067)
+++ code/gamesnd/gamesnd.cpp (working copy)
@@ -52,6 +52,30 @@
return -1;
}
+int gamesnd_get_by_iface_name(char* name)
+{
+ Assert( Snds_iface.size() <= INT_MAX );
+ Assert( Snds_iface.size() == Snds_iface_handle.size() );
+ int i = 0;
+ for(SCP_vector<game_snd>::iterator snd = Snds_iface.begin(); snd != Snds_iface.end(); ++snd)
+ {
+ char *p = strrchr( snd->filename, '.' );
+ if(p == NULL)
+ {
+ if(!stricmp(snd->filename, name))
+ {
+ return i;
+ }
+ }
+ else if(!strnicmp(snd->filename, name, p-snd->filename))
+ {
+ return i;
+ }
+ i++;
+ }
+ return -1;
+}
+
int gamesnd_get_by_tbl_index(int index)
{
//if we get passed -1, don't bother trying to look it up.
@@ -85,40 +109,111 @@
}
/**
- * Parse a sound
- *
+ * Helper function for parse_sound and parse_sound_list. Do not use directly.
+ *
* @param tag Tag
* @param idx_dest Sound index destination
* @param object_name Object name being parsed
+ * @param is_interface_sound Whether the sound is an interface sound or not (defaults to false)
+ * @param buf Buffer holding string to be parsed
*
- * This also means you shouldn't use optional_string or required_string,
- * just make sure the destination sound index can handle -1 if things
- * don't work out.
*/
-void parse_sound(char* tag, int *idx_dest, char* object_name)
+void parse_sound_core(char* tag, int *idx_dest, char* object_name, bool is_interface_sound, char* buf)
{
- char buf[MAX_FILENAME_LEN];
int idx;
- if(optional_string(tag))
+ if(is_interface_sound)
+ idx = gamesnd_get_by_iface_name(buf);
+ else
+ idx = gamesnd_get_by_name(buf);
+
+ if(idx != -1)
{
- stuff_string(buf, F_NAME, MAX_FILENAME_LEN);
- idx = gamesnd_get_by_name(buf);
- if(idx != -1)
- (*idx_dest) = idx;
+ (*idx_dest) = idx;
+ }
+ else
+ {
+ if(is_interface_sound)
+ idx = gamesnd_get_by_iface_tbl_index(atoi(buf));
else
- {
idx = gamesnd_get_by_tbl_index(atoi(buf));
- if (idx != -1)
- (*idx_dest) = idx;
- }
- Assert( Snds.size() <= INT_MAX );
- //Ensure sound is in range
- if((*idx_dest) < -1 || (*idx_dest) >= (int)Snds.size())
+ if (idx != -1)
+ (*idx_dest) = idx;
+ }
+
+ int size_to_check = 0;
+
+ if(is_interface_sound)
+ {
+ size_to_check = Snds_iface.size();
+ Assert( Snds_iface.size() == Snds_iface_handle.size() );
+ }
+ else
+ {
+ size_to_check = Snds.size();
+ }
+
+ Assert( size_to_check <= INT_MAX );
+
+ //Ensure sound is in range
+ if((*idx_dest) < -1 || (*idx_dest) >= (int)size_to_check)
+ {
+ (*idx_dest) = -1;
+ Warning(LOCATION, "%s sound index out of range on '%s'. Must be between 0 and %d. Forcing to -1 (Nonexistant sound).\n", tag, object_name, size_to_check);
+ }
+}
+
+/**
+ * Parse a sound. When using this function for a table entry,
+ * required_string and optional_string aren't needed, as this function deals with
+ * that as its tag parameter, just make sure that the destination sound index can
+ * handle -1 if things don't work out.
+ *
+ * @param tag Tag
+ * @param idx_dest Sound index destination
+ * @param object_name Object name being parsed
+ * @param is_interface_sound Whether the sound is an interface sound or not (defaults to false)
+ *
+ */
+void parse_sound(char* tag, int *idx_dest, char* object_name, bool is_interface_sound)
+{
+ if(optional_string(tag))
+ {
+ char buf[MAX_FILENAME_LEN];
+ stuff_string(buf, F_NAME, MAX_FILENAME_LEN);
+
+ parse_sound_core(tag, idx_dest, object_name, is_interface_sound, buf);
+ }
+}
+
+/**
+ * CommanderDJ - Parse a list of sounds. When using this function for a table entry,
+ * required_string and optional_string aren't needed, as this function deals with
+ * that as its tag parameter, just make sure that the destination sound index(es) can
+ * handle -1 if things don't work out.
+ *
+ * @param tag Tag
+ * @param idx_dest Destination of first sound index in list
+ * @param object_name Object name being parsed
+ * @param num Number of sounds to parse (defaults to 1)
+ * @param offset Element to start filling at (defaults to 0)
+ * @param is_interface_sound Whether the sound is an interface sound or not (defaults to false)
+ *
+ */
+void parse_sound_list(char* tag, int* idx_dest, char* object_name, int num, int offset, bool is_interface_sound)
+{
+ if(optional_string(tag))
+ {
+ //sanity checks
+ Assert(num>0);
+ Assert(offset>=0);
+
+ for(int i=0; i<num; i++)
{
- (*idx_dest) = -1;
- Warning(LOCATION, "%s sound index out of range on '%s'. Must be between 0 and %d. Forcing to -1 (Nonexistant sound).\n", tag, object_name, Snds.size());
+ char buf[MAX_FILENAME_LEN];
+ stuff_string_white(buf, MAX_FILENAME_LEN);
+ parse_sound_core(tag, &idx_dest[i+offset], object_name, is_interface_sound, buf);
}
}
}
Index: code/gamesnd/gamesnd.h
===================================================================
--- code/gamesnd/gamesnd.h (revision 8067)
+++ code/gamesnd/gamesnd.h (working copy)
@@ -28,13 +28,16 @@
void gamesnd_play_iface(int n);
void gamesnd_play_error_beep();
int gamesnd_get_by_name(char* name);
+int gamesnd_get_by_iface_name(char* name);
int gamesnd_get_by_tbl_index(int index);
int gamesnd_get_by_iface_tbl_index(int index);
//This should handle NO_SOUND just fine since it doesn't directly access lowlevel code
//Does all parsing for a sound
-void parse_sound(char* tag, int *idx_dest, char* object_name);
+void parse_sound(char* tag, int* idx_dest, char* object_name, bool is_interface_sound = false);
+void parse_sound_list(char* tag, int* idx_dest, char* object_name, int num = 1, int offset = 0, bool is_interface_sound = false);
+
// this is a callback, so it needs to be a real function
void common_play_highlight_sound();