Translations update
[openttd/fttd.git] / src / music.cpp
blob4cd48a427b5352eb1e8152347300d78c4515bf30
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file music.cpp The songs that OpenTTD knows. */
12 #include "stdafx.h"
13 #include "string.h"
14 #include "base_media_func.h"
16 /** The type of set we're replacing */
17 const char MusicSet::set_type[] = "music";
19 const char MusicSet::extension[] = ".obm"; // OpenTTD Base Music
21 INSTANTIATE_BASE_MEDIA_METHODS(BaseMedia<MusicSet>, MusicSet)
23 /** Names corresponding to the music set's files */
24 const char * const MusicSet::file_names [NUM_SONGS_AVAILABLE] = {
25 "theme",
26 "old_0", "old_1", "old_2", "old_3", "old_4", "old_5", "old_6", "old_7", "old_8", "old_9",
27 "new_0", "new_1", "new_2", "new_3", "new_4", "new_5", "new_6", "new_7", "new_8", "new_9",
28 "ezy_0", "ezy_1", "ezy_2", "ezy_3", "ezy_4", "ezy_5", "ezy_6", "ezy_7", "ezy_8", "ezy_9",
31 bool MusicSet::FillSetDetails(IniFile *ini, const char *path, const char *full_filename)
33 bool ret = this->BaseSet<MusicSet, NUM_SONGS_AVAILABLE>::FillSetDetails (ini, path, full_filename);
34 if (ret) {
35 this->num_available = 0;
36 const IniGroup *names = ini->get_group ("names");
37 for (uint i = 0, j = 1; i < lengthof(this->song_name); i++) {
38 const char *filename = this->files[i].filename;
39 if (names == NULL || StrEmpty(filename)) {
40 this->song_name[i][0] = '\0';
41 continue;
44 const IniItem *item = NULL;
45 /* As we possibly add a path to the filename and we compare
46 * on the filename with the path as in the .obm, we need to
47 * keep stripping path elements until we find a match. */
48 for (const char *p = filename; p != NULL; p = strchr(p, PATHSEPCHAR)) {
49 /* Remove possible double path separator characters from
50 * the beginning, so we don't start reading e.g. root. */
51 while (*p == PATHSEPCHAR) p++;
53 item = names->find (p);
54 if (item != NULL && !StrEmpty(item->value)) break;
57 if (item == NULL || StrEmpty(item->value)) {
58 DEBUG(grf, 0, "Base music set song name missing: %s", filename);
59 return false;
62 bstrcpy (this->song_name[i], item->value);
63 this->track_nr[i] = j++;
64 this->num_available++;
67 return ret;