Debian Codegraph @

prboom2/src/s_advsound.c

raw
1 /* Emacs style mode select -*- C -*-
2 *-----------------------------------------------------------------------------
3 *
4 *
5 * PrBoom: a Doom port merged with LxDoom and LSDLDoom
6 * based on BOOM, a modified and improved DOOM engine
7 * Copyright (C) 1999 by
8 * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
9 * Copyright (C) 1999-2000 by
10 * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
11 * Copyright 2005, 2006 by
12 * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 * 02111-1307, USA.
28 *
29 * DESCRIPTION: Support MUSINFO lump (dynamic music changing)
30 *
31 *-----------------------------------------------------------------------------*/
32
33 #ifdef HAVE_CONFIG_H
34 #include "config.h"
35 #endif
36
37 #include "doomstat.h"
38 #include "doomtype.h"
39 #include "d_main.h"
40 #include "p_mobj.h"
41 #include "m_misc.h"
42 #include "sounds.h"
43 #include "s_sound.h"
44 #include "i_sound.h"
45 #include "r_defs.h"
46 #include "sc_man.h"
47 #include "w_wad.h"
48 #include "lprintf.h"
49
50 #include "s_advsound.h"
51
52 #define TIDNUM(x) ((int)(x->iden_nums & 0xFFFF)) // thing identifier
53
54 musinfo_t musinfo;
55
56 //
57 // S_ParseMusInfo
58 // Parses MUSINFO lump.
59 //
60 void S_ParseMusInfo(const char *mapid)
61 {
62 if (gamemode != shareware && W_LumpNameExists("MUSINFO"))
63 {
64 int num, lumpnum;
65 int inMap = false;
66 int load_muslump = -1;
67
68 /* don't restart music that is already playing */
69 if (mus_playing &&
70 mus_playing->lumpnum == S_music[mus_musinfo].lumpnum) {
71 load_muslump = S_music[mus_musinfo].lumpnum;
72 }
73
74 memset(&musinfo, 0, sizeof(musinfo));
75 musinfo.items[0] = -1;
76 musinfo.current_item = load_muslump;
77 S_music[mus_musinfo].lumpnum = load_muslump;
78
79 SC_OpenLump("MUSINFO");
80
81 while (SC_GetString())
82 {
83 if (inMap || SC_Compare(mapid))
84 {
85 if (!inMap)
86 {
87 SC_GetString();
88 inMap = true;
89 }
90
91 if (sc_String[0] == 'E' || sc_String[0] == 'e' ||
92 sc_String[0] == 'M' || sc_String[0] == 'm')
93 {
94 break;
95 }
96
97 // Check number in range
98 if (M_StrToInt(sc_String, &num) && num >= 0 && num < MAX_MUS_ENTRIES)
99 {
100 if (SC_GetString())
101 {
102 lumpnum = W_CheckNumForName(sc_String);
103
104 if (lumpnum != LUMP_NOT_FOUND)
105 {
106 musinfo.items[num] = lumpnum;
107 }
108 else
109 {
110 lprintf(LO_ERROR, "S_ParseMusInfo: Unknown MUS lump %s", sc_String);
111 }
112 }
113 }
114 else
115 {
116 lprintf(LO_ERROR, "S_ParseMusInfo: Number not in range 0 to %d", MAX_MUS_ENTRIES - 1);
117 }
118 }
119 }
120
121 SC_Close();
122 }
123 else
124 {
125 musinfo.items[0] = -1;
126 }
127 }
128
129 void MusInfoThinker(mobj_t *thing)
130 {
131 if (musinfo.mapthing != thing &&
132 thing->subsector->sector == players[displayplayer].mo->subsector->sector)
133 {
134 musinfo.lastmapthing = musinfo.mapthing;
135 musinfo.mapthing = thing;
136 musinfo.tics = 30;
137 }
138 }
139
140 void T_MAPMusic(void)
141 {
142 if (musinfo.tics < 0 || !musinfo.mapthing)
143 {
144 return;
145 }
146
147 if (musinfo.tics > 0)
148 {
149 musinfo.tics--;
150 }
151 else
152 {
153 if (!musinfo.tics && musinfo.lastmapthing != musinfo.mapthing)
154 {
155 int arraypt = TIDNUM(musinfo.mapthing);
156
157 if (arraypt >= 0 && arraypt < MAX_MUS_ENTRIES)
158 {
159 int lumpnum = musinfo.items[arraypt];
160
161 if (lumpnum >= 0 && lumpnum < numlumps)
162 {
163 S_ChangeMusInfoMusic(lumpnum, true);
164 }
165 }
166
167 musinfo.tics = -1;
168 }
169 }
170 }