Announcement

Collapse
No announcement yet.

Adding Sound Effects to the game

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding Sound Effects to the game

    In the background I am heavily working on MoT-Mod 2.0. I revised almost each and every file, did a lot of cleanup etc. and my latest playtests are promising. I even got rid of all SLIC-errors with DebugSlic on (except for one that apparently has to do with players not yet having founded a city and hence not yet being alive [at least for some part of the exe], which all IsPlayerAlive-checks don't eliminate).

    However ... I have achieved a nice success regarding SOUNDS: I thought it would add to the atmosphere of the game to replace the odd "building complete"-audio message by sounds/sound effects that match the character of the building (e.g. flowing water for the aqueduct, some religious atmosphere for the shrine, etc.). Now there is only one explicit sound-function in SLIC, and that's PlaySound.

    The disadvantage of PlaySound is, that the sound gets played unconditionally for all players and regardless if the city is visible. I wanted the "building complete"-sound to be played only for the city owner (who naturally can see it), but not for other players (even if they *can* see the city). After quite a while of pondering I came to this solution:

    Code:
    HandleEvent(CreateBuilding) 'BuildingSound' post {
    location_t sfxLoc;
    int_t sfxBldg;
    int_t sfxPlayer;
    int_t sfxCurrPlayer;
    
    sfxLoc = city[0].location;
    sfxBldg = value[0].value;
    sfxPlayer = city[0].owner;
    sfxCurrPlayer = g.player;
    
    if(sfxPlayer == sfxCurrPlayer) {
    if(sfxBldg == BuildingDB(IMPROVE_SHRINE)) {
    AddEffect(sfxLoc, "SPECEFFECT_BLANC", "SOUND_SHRINE");
    }
    ... and so on for all buildings ...
    One tricky part of adding an effect just to play a sound is the effect sprite. In the first place I used "SPECEFFECT_NONE" which already exists in speceffectid.txt with sprite number -1. This does not work, obviously because the invalid sprite number causes the exe to omit the entire effect. So I had to create an effect sprite which consists of nothing else but transparency, gave it the number 98 and named it SPECEFFECT_BLANC. And hooray: this works just fine.

    I attach "GX98.SPR" (the blanc effect sprite) for those who want to experiment with this method themselves.
    Attached Files
    The modding knowledgebase: CTP2 Bureau (with CTP2 AE Modding Wiki). Modern Times Mod (work in progress): MoT-Mod for CTP2.
Working...
X