Made invalid-attempt-to-get-player errors less subtle. Word-wrapping in assert2 dialog box.

This was SVN commit r1857.
This commit is contained in:
Ykkrosh 2005-01-29 00:11:50 +00:00
parent bafdbe7f98
commit 60ee5acd2b
3 changed files with 36 additions and 2 deletions

View file

@ -44,8 +44,8 @@ CAPTION "Program Error"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "&Continue",IDC_CONTINUE,7,239,50,14
EDITTEXT IDC_EDIT1,7,7,314,204,ES_MULTILINE | ES_AUTOHSCROLL |
ES_READONLY | ES_WANTRETURN | WS_VSCROLL
EDITTEXT IDC_EDIT1,7,7,314,204,ES_MULTILINE | ES_READONLY |
ES_WANTRETURN | WS_VSCROLL
PUSHBUTTON "Copy",IDC_COPY,271,212,50,14
PUSHBUTTON "&Suppress",IDC_SUPPRESS,59,239,50,14
PUSHBUTTON "&Break",IDC_BREAK,111,239,50,14

View file

@ -260,3 +260,31 @@ void CGame::Update(double deltaTime)
// TODO Detect game over and bring up the summary screen or something
}
CPlayer *CGame::GetPlayer(uint idx)
{
if (idx > m_NumPlayers)
{
debug_warn("Invalid player ID");
LOG(ERROR, "", "Invalid player ID %d (outside 0..%d)", idx, m_NumPlayers);
return m_Players[0];
}
// Be a bit more paranoid - maybe m_Players hasn't been set large enough
else if (idx >= m_Players.size())
{
debug_warn("Invalid player ID");
LOG(ERROR, "", "Invalid player ID %d (not <=%d - internal error?)", idx, m_Players.size());
if (m_Players.size() == 0)
{
// Hmm. This is a bit of a problem.
assert2(! "### ### ### ### ERROR: Tried to access the players list when there aren't any players. That really isn't going to work, so I'll give up. ### ###");
abort();
}
else
return m_Players[0];
}
else
return m_Players[idx];
}

View file

@ -99,6 +99,7 @@ public:
inline void SetLocalPlayer(CPlayer *pLocalPlayer)
{ m_pLocalPlayer=pLocalPlayer; }
/*
inline CPlayer *GetPlayer(uint idx)
{
if (idx >= 0 && idx <= m_NumPlayers)
@ -109,6 +110,11 @@ public:
return m_Players[0];
}
}
*/
// PT: No longer inline, because it does too much error checking. When
// everything stops trying to access players before they're loaded, feel
// free to put the inline version back.
CPlayer *GetPlayer(uint idx);
inline std::vector<CPlayer*>* GetPlayers()
{ return( &m_Players ); }