From 8329afc6dfaddbd740724dd23de6c5845a19c343 Mon Sep 17 00:00:00 2001 From: Misa Date: Tue, 11 May 2021 19:59:02 -0700 Subject: [PATCH] Replace main game music with music area map The main game used a set of copy-pasted code to set the music of each area. There WAS some redundancy built-in, but only three rooms in each direction from the entrance of a zone. Given this, it's completely possible for players to mismatch the music of the area and level. In fact, it's easy to do it even on accident, especially since 2.3 now lets you quicksave and quit during cutscenes. Just play a cutscene that has Pause music, then quicksave, quit, and reload. Also some other accidental ways that I've forgotten about. To fix this, I've done what mapclass has and made an areamap. Except for music. This map is the map of the track number of every single room, except for three special cases: -1 for do nothing and don't change music (usually because multiple different tracks can be played in this room), -2 for Tower music (needs to be track 2 or 9 depending on Flip Mode), and -3 for the start of Space Station 2 (track 1 in time trials, track 4 otherwise). I've thoroughly tested this areamap by playing through the game and entering every single room. Additionally I've also thoroughly tested all special cases (entering the Ship through the teleporter or main entrance, using the Ship's jukebox, the Tower in Flip Mode and regular mode, and the start of Space Station 2 in time trial and in regular mode). Closes #449. --- desktop_version/src/Map.cpp | 60 +--------------------- desktop_version/src/Music.cpp | 93 +++++++++++++++++++++++++--------- desktop_version/src/Script.cpp | 10 ++-- 3 files changed, 73 insertions(+), 90 deletions(-) diff --git a/desktop_version/src/Map.cpp b/desktop_version/src/Map.cpp index 565eecb2..23357046 100644 --- a/desktop_version/src/Map.cpp +++ b/desktop_version/src/Map.cpp @@ -1012,65 +1012,7 @@ void mapclass::gotoroom(int rx, int ry) game.currentroomdeaths = roomdeaths[game.roomx - 100 + (20 * (game.roomy - 100))]; //Alright, change music depending on where we are: - //Tower - if (game.roomx == 107 && game.roomy == 106) music.niceplay(4); - if (game.roomx == 107 && game.roomy == 107) music.niceplay(4); - if (game.roomx == 107 && game.roomy == 108) music.niceplay(4); - if (game.roomx == 107 && game.roomy == 109) music.niceplay(4); - if (game.roomx == 108 && game.roomy == 109) - { - if (graphics.setflipmode) - { - music.niceplay(9); - } - else - { - music.niceplay(2); - } - } - if (game.roomx == 109) - { - if (graphics.setflipmode) - { - music.niceplay(9); - } - else - { - music.niceplay(2); - } - } - //Warp Zone - if (game.roomx == 112 && game.roomy == 101) music.niceplay(4); - if (game.roomx == 113 && game.roomy == 101) music.niceplay(4); - if (game.roomx == 113 && game.roomy == 102) music.niceplay(4); - if (game.roomx == 114 && game.roomy == 101) music.niceplay(12); - if (game.roomx == 115 && game.roomy == 101) music.niceplay(12); - if (game.roomx == 115 && game.roomy == 102) music.niceplay(12); - //Lab - if (game.roomx == 101 && game.roomy == 115) music.niceplay(4); - if (game.roomx == 100 && game.roomy == 115) music.niceplay(4); - if (game.roomx == 101 && game.roomy == 116) music.niceplay(4); - if (game.roomx == 100 && game.roomy == 116) music.niceplay(4); - if (game.roomx == 102 && game.roomy == 116) music.niceplay(3); - if (game.roomx == 102 && game.roomy == 117) music.niceplay(3); - if (game.roomx == 101 && game.roomy == 117) music.niceplay(3); - //Space Station - if (game.intimetrial) - { - if (game.roomx == 111 && game.roomy == 112) music.niceplay(1); - if (game.roomx == 111 && game.roomy == 113) music.niceplay(1); - if (game.roomx == 112 && game.roomy == 114) music.niceplay(1); - if (game.roomx == 112 && game.roomy == 115) music.niceplay(1); - } - else - { - if (game.roomx == 111 && game.roomy == 112) music.niceplay(1); - if (game.roomx == 111 && game.roomy == 113) music.niceplay(1); - if (game.roomx == 112 && game.roomy == 114) music.niceplay(4); - if (game.roomx == 112 && game.roomy == 115) music.niceplay(4); - } - //Leaving the Ship - if (game.roomx == 104 && game.roomy == 112) music.niceplay(4); + music.changemusicarea(game.roomx - 100, game.roomy - 100); } int temp = rx + (ry * 100); loadlevel(game.roomx, game.roomy); diff --git a/desktop_version/src/Music.cpp b/desktop_version/src/Music.cpp index a6af5c1e..7fdcbadd 100644 --- a/desktop_version/src/Music.cpp +++ b/desktop_version/src/Music.cpp @@ -6,7 +6,9 @@ #include "BinaryBlob.h" #include "Game.h" +#include "Graphics.h" #include "Map.h" +#include "Script.h" #include "UtilityClass.h" musicclass::musicclass(void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,-2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 3, 3, 3, 3, 3, 3, 3, 4,-2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 3, 3, 3, 3, 3, 4, 4, 3, 4,-2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 3, 3, 3, 3, 3, 4, 4, 3, 4,-2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 +}; + +SDL_COMPILE_TIME_ASSERT(areamap, SDL_arraysize(areamap) == 20 * 20); + void musicclass::changemusicarea(int x, int y) { - switch(musicroom(x, y)) + int room; + int track; + + if (script.running) { - case musicroom(11, 4): - niceplay(2); - break; + return; + } - case musicroom(2, 4): - case musicroom(7, 15): - niceplay(3); - break; + room = musicroom(x, y); - case musicroom(18, 1): - case musicroom(15, 0): - niceplay(12); - break; + if (!INBOUNDS_ARR(room, areamap)) + { + SDL_assert(0 && "Music map index out-of-bounds!"); + return; + } - case musicroom(0, 0): - case musicroom(0, 16): - case musicroom(2, 11): - case musicroom(7, 9): - case musicroom(8, 11): - case musicroom(13, 2): - case musicroom(17, 12): - case musicroom(14, 19): - case musicroom(17, 17): - niceplay(4); - break; + track = areamap[room]; - default: - niceplay(1); + switch (track) + { + case -1: + /* Don't change music. */ + return; + case -2: + /* Special case: Tower music, changes with Flip Mode. */ + if (graphics.setflipmode) + { + track = 9; /* ecroF evitisoP */ + } + else + { + track = 2; /* Positive Force */ + } + break; + case -3: + /* Special case: start of Space Station 2. */ + if (game.intimetrial) + { + track = 1; /* Pushing Onwards */ + } + else + { + track = 4; /* Passion for Exploring */ + } break; } + + niceplay(track); } void musicclass::playef(int t) diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index 01175b23..310a3be7 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -3361,13 +3361,11 @@ void scriptclass::teleport(void) else { //change music based on location - if (graphics.setflipmode && game.teleport_to_x == 11 && game.teleport_to_y == 4) + if (game.teleport_to_x == 2 && game.teleport_to_y == 11) { - music.niceplay(9); - } - else - { - music.changemusicarea(game.teleport_to_x, game.teleport_to_y); + /* Special case: Ship music needs to be set here; + * ship teleporter on music map is -1 for jukebox. */ + music.niceplay(4); } game.savetele_textbox(); }