Development > Newbie Coding
Multiple Sound Files for Messages
Neonin:
Based on Crystan's idea to have voiceovers for the Geoscape messages and an observation I made that it might be better to have multiple options for each message so you don't get bombarded with the same phrase over and over again, I was wondering if something as simple as this would do the trick in cp_messages.cpp:
--- Code: --- if (playSound) {
const char *sound = NULL;
int msgClipNum;
msgClipNum = rand()%4+1;
switch (type) {
case MSG_DEBUG:
break;
case MSG_STANDARD:
switch (msgClipNum) {
case 1:
sound = "geoscape/standard1";
break;
case 2:
sound = "geoscape/standard2";
break;
case 3:
sound = "geoscape/standard3";
break;
case 4:
sound = "geoscape/standard4";
break;
}
break;
case MSG_INFO:
case MSG_TRANSFERFINISHED:
case MSG_DEATH:
case MSG_CONSTRUCTION:
case MSG_PRODUCTION:
switch (msgClipNum) {
case 1:
sound = "geoscape/info1";
break;
case 2:
sound = "geoscape/info2";
break;
case 3:
sound = "geoscape/info3";
break;
case 4:
sound = "geoscape/info4";
break;
}
break;
case MSG_RESEARCH_PROPOSAL:
case MSG_RESEARCH_FINISHED:
assert(pedia);
case MSG_RESEARCH_HALTED:
case MSG_EVENT:
case MSG_NEWS:
/* reread the new mails in UP_GetUnreadMails */
ccs.numUnreadMails = -1;
switch (msgClipNum) {
case 1:
sound = "geoscape/mail1";
break;
case 2:
sound = "geoscape/mail2";
break;
case 3:
sound = "geoscape/mail3";
break;
case 4:
sound = "geoscape/mail4";
break;
}
break;
case MSG_UFOLOST:
switch (msgClipNum) {
case 1:
sound = "geoscape/ufolost1";
break;
case 2:
sound = "geoscape/ufolost2";
break;
case 3:
sound = "geoscape/ufolost3";
break;
case 4:
sound = "geoscape/ufolost4";
break;
}
break;
case MSG_UFOSPOTTED:
switch (msgClipNum) {
case 1:
sound = "geoscape/ufospotted1";
break;
case 2:
sound = "geoscape/ufospotted2";
break;
case 3:
sound = "geoscape/ufospotted3";
break;
case 4:
sound = "geoscape/ufospotted4";
break;
}
break;
case MSG_BASEATTACK:
switch (msgClipNum) {
case 1:
sound = "geoscape/basealert1";
break;
case 2:
sound = "geoscape/basealert2";
break;
case 3:
sound = "geoscape/basealert3";
break;
case 4:
sound = "geoscape/basealert4";
break;
}
break;
case MSG_TERRORSITE:
switch (msgClipNum) {
case 1:
sound = "geoscape/alien-activity1";
break;
case 2:
sound = "geoscape/alien-activity2";
break;
case 3:
sound = "geoscape/alien-activity3";
break;
case 4:
sound = "geoscape/alien-activity4";
break;
}
break;
case MSG_CRASHSITE:
switch (msgClipNum) {
case 1:
sound = "geoscape/newmission1";
break;
case 2:
sound = "geoscape/newmission2";
break;
case 3:
sound = "geoscape/newmission3";
break;
case 4:
sound = "geoscape/newmission4";
break;
}
break;
case MSG_PROMOTION:
switch (msgClipNum) {
case 1:
sound = "geoscape/promotion1";
break;
case 2:
sound = "geoscape/promotion2";
break;
case 3:
sound = "geoscape/promotion3";
break;
case 4:
sound = "geoscape/promotion4";
break;
}
break;
case MSG_MAX:
break;
}
cgi->S_StartLocalSample(sound, 1.0f);
}
--- End code ---
The rand() function requires stdlib.h is defined in the includes but I'm assuming that's already in the code somewhere. My C++ coding is very rusty but I think that's all it would take to generate a number between 1-4 and then use that to select a sound file. To start with a quick copy/paste and rename of the original files would allow the code to work until the actual sound files were created.
Then again, this game is far more complex than anything I've ever fiddled with before code-wise so I don't know if this would do something horrible, and getting this stuff to compile on Windows looks like a pain in the arse just to test something as simple as this. Perhaps one of you experienced coders could look at it and see if it seems viable?
Neonin:
I answered my own question, got the source to compile and tested it with copy/pasted sound effects with clicks in them to signify which one was being played :P
It does work :D
geever:
May I note that your approach with hardcoded number of sounds is not too flexible?
If we ever add that support for multiple geoscape sounds we need a way to either automatically detect number of available sounds per category or make them scripted.
-geever
Neonin:
It's as flexible as the current system :P
But yes, a way of counting how many of a specific type of sound is in the folder (best to separate each type into its own folder if going down that route) would be much preferable. I've also encountered a problem while playing where, for example, when you research something that throws up more than one possible avenue of research it will try and play a file, often different ones, for each topic all at once. It's... noisy... to say the least. Obviously a way of detecting that a message of that type is already going to play or getting the message code to only play one sound per type of message queued would be needed.
No idea if my coding knowledge is up to either task but I shall give it a shot, it gives me a little project to do when I'm not playing :P
Neonin:
Quick update:
Reading then number of files in a directory uses different commands in C++ dependant on the OS (unless you've installed certain libraries that bring it all under one set of commands) so I am looking to make this scriptable.
I've also modified the code some more so that you can have different sounds based on the type of tech in use in the message, so you could have one file for "Weapon research completed" and another for "Armour research finished", same for production, etc. This would enable a more varied and accurate Geoscape voiceover hopefully!
Anyway, big thing is making it scriptable so I shall be looking at current examples and trying to learn from those :P
Navigation
[0] Message Index
[#] Next page
Go to full version