mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2025-01-12 21:01:00 +00:00
Backwards compatibility.
A test WAD for all possible use cases I can think of can be found here: https://dl.dropboxusercontent.com/u/3518218/21/secret/bc_test.wad
This commit is contained in:
parent
f5ba192f0b
commit
7349cbdbc0
5 changed files with 171 additions and 13 deletions
110
src/dehacked.c
110
src/dehacked.c
|
@ -65,6 +65,9 @@ static mobjtype_t get_mobjtype(const char *word);
|
|||
static statenum_t get_state(const char *word);
|
||||
static spritenum_t get_sprite(const char *word);
|
||||
static sfxenum_t get_sfx(const char *word);
|
||||
#ifdef MUSICSLOT_COMPATIBILITY
|
||||
static UINT16 get_mus(const char *word, UINT8 dehacked_mode);
|
||||
#endif
|
||||
static hudnum_t get_huditem(const char *word);
|
||||
#ifndef HAVE_BLUA
|
||||
static powertype_t get_power(const char *word);
|
||||
|
@ -1173,22 +1176,19 @@ static void readlevelheader(MYFILE *f, INT32 num)
|
|||
sizeof(mapheaderinfo[num-1]->musname), va("Level header %d: music", num));
|
||||
}
|
||||
}
|
||||
#ifdef MUSICSLOT_COMPATIBILITY
|
||||
else if (fastcmp(word, "MUSICSLOT"))
|
||||
{ // Backwards compatibility?
|
||||
// Convert to map number
|
||||
if (word2[0] >= 'A' && word2[0] <= 'Z' && word2[2] == '\0')
|
||||
i = M_MapNumber(word2[0], word2[1]);
|
||||
|
||||
if (!i)
|
||||
mapheaderinfo[num-1]->musname[0] = 0; // becomes empty string
|
||||
else if (i > 1035)
|
||||
deh_warning("Level header %d: musicslot out of range (0 - 1035)\n", num);
|
||||
else // it's just a number
|
||||
{
|
||||
{
|
||||
i = get_mus(word2, true);
|
||||
if (i && i <= 1035)
|
||||
snprintf(mapheaderinfo[num-1]->musname, 7, "%sM", G_BuildMapName(i));
|
||||
mapheaderinfo[num-1]->musname[6] = 0;
|
||||
}
|
||||
else if (i && i <= 1050)
|
||||
strncpy(mapheaderinfo[num-1]->musname, compat_special_music_slots[i - 1036], 7);
|
||||
else
|
||||
mapheaderinfo[num-1]->musname[0] = 0; // becomes empty string
|
||||
mapheaderinfo[num-1]->musname[6] = 0;
|
||||
}
|
||||
#endif
|
||||
else if (fastcmp(word, "MUSICTRACK"))
|
||||
mapheaderinfo[num-1]->mustrack = ((UINT16)i - 1);
|
||||
else if (fastcmp(word, "FORCECHARACTER"))
|
||||
|
@ -1463,6 +1463,20 @@ static void readcutscenescene(MYFILE *f, INT32 num, INT32 scenenum)
|
|||
strncpy(cutscenes[num]->scene[scenenum].musswitch, word2, 7);
|
||||
cutscenes[num]->scene[scenenum].musswitch[6] = 0;
|
||||
}
|
||||
#ifdef MUSICSLOT_COMPATIBILITY
|
||||
else if (fastcmp(word, "MUSICSLOT"))
|
||||
{
|
||||
DEH_WriteUndoline(word, cutscenes[num]->scene[scenenum].musswitch, UNDO_NONE);
|
||||
i = get_mus(word2, true);
|
||||
if (i && i <= 1035)
|
||||
snprintf(cutscenes[num]->scene[scenenum].musswitch, 7, "%sM", G_BuildMapName(i));
|
||||
else if (i && i <= 1050)
|
||||
strncpy(cutscenes[num]->scene[scenenum].musswitch, compat_special_music_slots[i - 1036], 7);
|
||||
else
|
||||
cutscenes[num]->scene[scenenum].musswitch[0] = 0; // becomes empty string
|
||||
cutscenes[num]->scene[scenenum].musswitch[6] = 0;
|
||||
}
|
||||
#endif
|
||||
else if (fastcmp(word, "MUSICTRACK"))
|
||||
{
|
||||
DEH_WriteUndoline(word, va("%u", cutscenes[num]->scene[scenenum].musswitchflags), UNDO_NONE);
|
||||
|
@ -7978,6 +7992,46 @@ static sfxenum_t get_sfx(const char *word)
|
|||
return sfx_None;
|
||||
}
|
||||
|
||||
#ifdef MUSICSLOT_COMPATIBILITY
|
||||
static UINT16 get_mus(const char *word, UINT8 dehacked_mode)
|
||||
{ // Returns the value of MUS_ enumerations
|
||||
UINT16 i;
|
||||
char lumptmp[4];
|
||||
|
||||
if (*word >= '0' && *word <= '9')
|
||||
return atoi(word);
|
||||
if (!word[2] && toupper(word[0]) >= 'A' && toupper(word[0]) <= 'Z')
|
||||
return (UINT16)M_MapNumber(word[0], word[1]);
|
||||
|
||||
if (fastncmp("MUS_",word,4))
|
||||
word += 4; // take off the MUS_
|
||||
else if (fastncmp("O_",word,2) || fastncmp("D_",word,2))
|
||||
word += 2; // take off the O_ or D_
|
||||
|
||||
strncpy(lumptmp, word, 4);
|
||||
lumptmp[3] = 0;
|
||||
if (fasticmp("MAP",lumptmp))
|
||||
{
|
||||
word += 3;
|
||||
if (toupper(word[0]) >= 'A' && toupper(word[0]) <= 'Z')
|
||||
return (UINT16)M_MapNumber(word[0], word[1]);
|
||||
else if ((i = atoi(word)))
|
||||
return i;
|
||||
|
||||
word -= 3;
|
||||
if (dehacked_mode)
|
||||
deh_warning("Couldn't find music named 'MUS_%s'",word);
|
||||
return 0;
|
||||
}
|
||||
for (i = 0; compat_special_music_slots[i][0]; ++i)
|
||||
if (fasticmp(word, compat_special_music_slots[i]))
|
||||
return i + 1036;
|
||||
if (dehacked_mode)
|
||||
deh_warning("Couldn't find music named 'MUS_%s'",word);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static hudnum_t get_huditem(const char *word)
|
||||
{ // Returns the value of HUD_ enumerations
|
||||
hudnum_t i;
|
||||
|
@ -8176,6 +8230,13 @@ static fixed_t find_const(const char **rword)
|
|||
free(word);
|
||||
return r;
|
||||
}
|
||||
#ifdef MUSICSLOT_COMPATIBILITY
|
||||
else if (fastncmp("MUS_",word,4) || fastncmp("O_",word,2)) {
|
||||
r = get_mus(word, true);
|
||||
free(word);
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
else if (fastncmp("PW_",word,3)) {
|
||||
r = get_power(word);
|
||||
free(word);
|
||||
|
@ -8545,6 +8606,29 @@ static inline int lib_getenum(lua_State *L)
|
|||
if (mathlib) return luaL_error(L, "sfx '%s' could not be found.\n", word);
|
||||
return 0;
|
||||
}
|
||||
#ifdef MUSICSLOT_COMPATIBILITY
|
||||
else if (!mathlib && fastncmp("mus_",word,4)) {
|
||||
p = word+4;
|
||||
if ((i = get_mus(p, false)) == 0)
|
||||
return 0;
|
||||
lua_pushinteger(L, i);
|
||||
return 1;
|
||||
}
|
||||
else if (mathlib && fastncmp("MUS_",word,4)) { // SOCs are ALL CAPS!
|
||||
p = word+4;
|
||||
if ((i = get_mus(p, false)) == 0)
|
||||
return luaL_error(L, "music '%s' could not be found.\n", word);
|
||||
lua_pushinteger(L, i);
|
||||
return 1;
|
||||
}
|
||||
else if (mathlib && (fastncmp("O_",word,2) || fastncmp("D_",word,2))) {
|
||||
p = word+2;
|
||||
if ((i = get_mus(p, false)) == 0)
|
||||
return luaL_error(L, "music '%s' could not be found.\n", word);
|
||||
lua_pushinteger(L, i);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
else if (!mathlib && fastncmp("pw_",word,3)) {
|
||||
p = word+3;
|
||||
for (i = 0; i < NUMPOWERS; i++)
|
||||
|
|
|
@ -490,4 +490,8 @@ extern const char *compdate, *comptime, *comprevision, *compbranch;
|
|||
/// Experimental tweaks to analog mode. (Needs a lot of work before it's ready for primetime.)
|
||||
//#define REDSANALOG
|
||||
|
||||
/// Backwards compatibility with musicslots.
|
||||
/// \note You should leave this enabled unless you're working with a future SRB2 version.
|
||||
#define MUSICSLOT_COMPATIBILITY
|
||||
|
||||
#endif // __DOOMDEF__
|
||||
|
|
|
@ -1636,17 +1636,59 @@ static int lib_sStopSound(lua_State *L)
|
|||
|
||||
static int lib_sChangeMusic(lua_State *L)
|
||||
{
|
||||
#ifdef MUSICSLOT_COMPATIBILITY
|
||||
const char *music_name;
|
||||
UINT32 music_num;
|
||||
char music_compat_name[7];
|
||||
|
||||
boolean looping;
|
||||
player_t *player = NULL;
|
||||
UINT16 music_flags = 0;
|
||||
NOHUD
|
||||
|
||||
if (lua_isnumber(L, 1))
|
||||
{
|
||||
music_num = (UINT32)luaL_checkinteger(L, 1);
|
||||
music_flags = (UINT16)(music_num & 0x0000FFFF);
|
||||
if (music_flags && music_flags <= 1035)
|
||||
snprintf(music_compat_name, 7, "%sM", G_BuildMapName((INT32)music_flags));
|
||||
else if (music_flags && music_flags <= 1050)
|
||||
strncpy(music_compat_name, compat_special_music_slots[music_flags - 1036], 7);
|
||||
else
|
||||
music_compat_name[0] = 0; // becomes empty string
|
||||
music_compat_name[6] = 0;
|
||||
music_name = (const char *)&music_compat_name;
|
||||
music_flags = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
music_num = 0;
|
||||
music_name = luaL_checkstring(L, 1);
|
||||
}
|
||||
|
||||
|
||||
looping = (boolean)lua_opttrueboolean(L, 2);
|
||||
|
||||
#else
|
||||
const char *music_name = luaL_checkstring(L, 1);
|
||||
boolean looping = (boolean)lua_opttrueboolean(L, 2);
|
||||
player_t *player = NULL;
|
||||
UINT16 music_flags = 0;
|
||||
NOHUD
|
||||
|
||||
#endif
|
||||
if (!lua_isnone(L, 3) && lua_isuserdata(L, 3))
|
||||
{
|
||||
player = *((player_t **)luaL_checkudata(L, 3, META_PLAYER));
|
||||
if (!player)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
}
|
||||
|
||||
#ifdef MUSICSLOT_COMPATIBILITY
|
||||
if (music_num)
|
||||
music_flags = (UINT16)((music_num & 0x7FFF0000) >> 16);
|
||||
else
|
||||
#endif
|
||||
music_flags = (UINT16)luaL_optinteger(L, 4, 0);
|
||||
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
|
|
|
@ -1155,6 +1155,28 @@ void S_StartSoundName(void *mo, const char *soundname)
|
|||
/// Music
|
||||
/// ------------------------
|
||||
|
||||
#ifdef MUSICSLOT_COMPATIBILITY
|
||||
const char *compat_special_music_slots[16] =
|
||||
{
|
||||
"titles", // 1036 title screen
|
||||
"read_m", // 1037 intro
|
||||
"lclear", // 1038 level clear
|
||||
"invinc", // 1039 invincibility
|
||||
"shoes", // 1040 super sneakers
|
||||
"minvnc", // 1041 Mario invincibility
|
||||
"drown", // 1042 drowning
|
||||
"gmover", // 1043 game over
|
||||
"xtlife", // 1044 extra life
|
||||
"contsc", // 1045 continue screen
|
||||
"supers", // 1046 Super Sonic
|
||||
"chrsel", // 1047 character select
|
||||
"credit", // 1048 credits
|
||||
"racent", // 1049 Race Results
|
||||
"stjr", // 1050 Sonic Team Jr. Presents
|
||||
""
|
||||
};
|
||||
#endif
|
||||
|
||||
#define music_playing (music_name[0]) // String is empty if no music is playing
|
||||
|
||||
static char music_name[7]; // up to 6-character name
|
||||
|
|
|
@ -139,4 +139,10 @@ void S_StopSoundByNum(sfxenum_t sfxnum);
|
|||
#define S_StartScreamSound S_StartSound
|
||||
#endif
|
||||
|
||||
#ifdef MUSICSLOT_COMPATIBILITY
|
||||
// For compatibility with code/scripts relying on older versions
|
||||
// This is a list of all the "special" slot names and their associated numbers
|
||||
const char *compat_special_music_slots[16];
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue