Skip to content

Commit 3699fa9

Browse files
authored
Merge pull request odamex#959 from odamex/lexi/issue-949
[BUGFIX] Fix crash when switching wads with differing HORDEDEFs
2 parents b5ed907 + c9d7920 commit 3699fa9

File tree

4 files changed

+52
-6
lines changed

4 files changed

+52
-6
lines changed

common/g_horde.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
extern std::vector<hordeDefine_t> WAVE_DEFINES;
3737

38+
static hordeDefine_t EMPTY_WAVE_DEFINE;
39+
3840
typedef OHashTable<std::string, mobjtype_t> AliasMap;
3941
AliasMap g_aliasMap;
4042

@@ -506,11 +508,20 @@ void G_ParseHordeDefs()
506508
}
507509

508510
/**
509-
* @brief Resolve a horde define ID to an actual define. Should be identical on client and server.
511+
* @brief Resolve a horde define ID to an actual define. Should be identical on client
512+
* and server.
510513
*
511514
* @param id ID of define.
512515
*/
513516
const hordeDefine_t& G_HordeDefine(size_t id)
514517
{
515-
return ::WAVE_DEFINES.at(id);
518+
if (id >= ::WAVE_DEFINES.size())
519+
{
520+
Printf(PRINT_WARNING,
521+
"Tried to access horde wave %llu but only have %llu hode defines!\n", id,
522+
::WAVE_DEFINES.size());
523+
return EMPTY_WAVE_DEFINE;
524+
}
525+
526+
return ::WAVE_DEFINES[id];
516527
}

common/p_horde.cpp

+37-4
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class HordeState
232232
/**
233233
* @brief Reset director state.
234234
*/
235-
void reset()
235+
void reset(bool printWave)
236236
{
237237
setState(HS_STARTING);
238238
m_wave = 1;
@@ -250,8 +250,12 @@ class HordeState
250250
m_nextPowerup = ::level.time + (30 * TICRATE);
251251
m_corpses.clear();
252252

253-
SV_BroadcastPrintf("Wave %d: \"%s\"\n", m_wave,
254-
G_HordeDefine(m_defineID).name.c_str());
253+
// Avoid printing wave name on boot and map switch.
254+
if (printWave)
255+
{
256+
SV_BroadcastPrintf("Wave %d: \"%s\"\n", m_wave,
257+
G_HordeDefine(m_defineID).name.c_str());
258+
}
255259
}
256260

257261
/**
@@ -718,6 +722,11 @@ void HordeState::tick()
718722
}
719723
}
720724

725+
void P_InitHorde()
726+
{
727+
::g_HordeDirector.reset(false);
728+
}
729+
721730
void P_NextSpawnTime(int& min, int& max)
722731
{
723732
::g_HordeDirector.getNextSpawnTime(min, max);
@@ -800,7 +809,7 @@ void P_RunHordeTics()
800809

801810
if (::level.time == 0)
802811
{
803-
::g_HordeDirector.reset();
812+
::g_HordeDirector.reset(true);
804813
}
805814

806815
// Add our spawns if a level reload or reset erased our previous spawns.
@@ -941,6 +950,12 @@ BEGIN_COMMAND(hordewave)
941950
return;
942951
}
943952

953+
if (!G_IsHordeMode())
954+
{
955+
Printf("Can't change the wave define outside of horde mode.\n");
956+
return;
957+
}
958+
944959
if (!::g_HordeDirector.forceWave(argv[1]))
945960
{
946961
Printf("Could not find wave define starting with \"%s\"\n", argv[1]);
@@ -950,12 +965,24 @@ END_COMMAND(hordewave)
950965

951966
BEGIN_COMMAND(hordenextwave)
952967
{
968+
if (!G_IsHordeMode())
969+
{
970+
Printf("Can't advance the wave outside of horde mode.\n");
971+
return;
972+
}
973+
953974
::g_HordeDirector.nextWave();
954975
}
955976
END_COMMAND(hordenextwave)
956977

957978
BEGIN_COMMAND(hordeboss)
958979
{
980+
if (!G_IsHordeMode())
981+
{
982+
Printf("Can't spawn a horde boss outside of horde mode.\n");
983+
return;
984+
}
985+
959986
if (::g_HordeDirector.forceBoss())
960987
{
961988
Printf("Spawned the boss.\n");
@@ -973,6 +1000,12 @@ EXTERN_CVAR(g_horde_goalhp)
9731000

9741001
BEGIN_COMMAND(hordeinfo)
9751002
{
1003+
if (!G_IsHordeMode())
1004+
{
1005+
Printf("Can't obtain horde info outside of horde mode.\n");
1006+
return;
1007+
}
1008+
9761009
float skillScaler = 1.0f;
9771010
if (sv_skill == sk_medium)
9781011
skillScaler = 0.75f;

common/p_horde.h

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct hordeInfo_t
9292
}
9393
};
9494

95+
void P_InitHorde();
9596
void P_NextSpawnTime(int& min, int& max);
9697
hordeInfo_t P_HordeInfo();
9798
void P_SetHordeInfo(const hordeInfo_t& info);

common/p_setup.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,7 @@ void P_Init (void)
19611961
P_InitPicAnims ();
19621962
R_InitSprites (sprnames);
19631963
InitTeamInfo();
1964+
P_InitHorde();
19641965
}
19651966

19661967
CVAR_FUNC_IMPL(sv_intermissionlimit)

0 commit comments

Comments
 (0)