diff --git a/sc2/src/sc2code/encount.c b/sc2/src/sc2code/encount.c index f9231d116..0c94af5c3 100644 --- a/sc2/src/sc2code/encount.c +++ b/sc2/src/sc2code/encount.c @@ -36,6 +36,7 @@ #include "setup.h" #include "sounds.h" #include "libs/graphics/gfx_common.h" +#include "libs/log.h" #include "libs/mathlib.h" #include "libs/inplib.h" @@ -756,7 +757,10 @@ EncounterBattle (void) PlayerControl[0] = CYBORG_CONTROL | AWESOME_RATING; savedPlayerInput = PlayerInput[0]; PlayerInput[0] = NULL; - SetPlayerInput (0); + if (!SetPlayerInput (0)) { + log_add (log_Fatal, "Could not set cyborg player input."); + explode (); // Does not return; + } } GameSounds = CaptureSound (LoadSound (GAME_SOUNDS)); diff --git a/sc2/src/sc2code/melee.c b/sc2/src/sc2code/melee.c index 6c780929e..d6b3a9b5c 100644 --- a/sc2/src/sc2code/melee.c +++ b/sc2/src/sc2code/melee.c @@ -1738,7 +1738,8 @@ StartMelee (MELEE_STATE *pMS) WaitForSoundEnd (TFBSOUND_WAIT_ALL); - SetPlayerInputAll (); + if (!SetPlayerInputAll ()) + break; load_gravity_well ((BYTE)((COUNT)TFB_Random () % NUMBER_OF_PLANET_TYPES)); Battle (); diff --git a/sc2/src/sc2code/setup.c b/sc2/src/sc2code/setup.c index 2cd43426d..fa30e429e 100644 --- a/sc2/src/sc2code/setup.c +++ b/sc2/src/sc2code/setup.c @@ -231,7 +231,7 @@ InitGameKernel (void) return TRUE; } -void +bool SetPlayerInput (COUNT playerI) { assert (PlayerInput[playerI] == NULL); @@ -243,7 +243,7 @@ SetPlayerInput (COUNT playerI) break; case COMPUTER_CONTROL: case CYBORG_CONTROL: - // COMPUTER_CONTROL is used in SuperMelee; the computer choses + // COMPUTER_CONTROL is used in SuperMelee; the computer chooses // the ships and fights the battles. // CYBORG_CONTROL is used in the full game; the computer only // fights the battles. XXX: This will need to be handled @@ -260,23 +260,32 @@ SetPlayerInput (COUNT playerI) break; #endif default: - fprintf (stderr, "Invalid control method in SetPlayerInput().\n"); + log_add (log_Fatal, + "Invalid control method in SetPlayerInput()."); explode (); /* Does not return */ } + + return PlayerInput[playerI] != NULL; } -void +bool SetPlayerInputAll (void) { COUNT playerI; for (playerI = 0; playerI < NUM_PLAYERS; playerI++) - SetPlayerInput (playerI); + if (!SetPlayerInput (playerI)) + return false; + return true; } void ClearPlayerInput (COUNT playerI) { - assert (PlayerInput[playerI] != NULL); + if (PlayerInput[playerI] == NULL) { + log_add (log_Debug, "ClearPlayerInput(): PlayerInput[%d] was NULL.", + playerI); + return; + } PlayerInput[playerI]->handlers->deleteContext (PlayerInput[playerI]); PlayerInput[playerI] = NULL; diff --git a/sc2/src/sc2code/setup.h b/sc2/src/sc2code/setup.h index 6c2ee6cc2..fa5152d59 100644 --- a/sc2/src/sc2code/setup.h +++ b/sc2/src/sc2code/setup.h @@ -67,8 +67,8 @@ extern void FreeKernel (void); int initIO (void); void uninitIO (void); -void SetPlayerInput (COUNT playerI); -void SetPlayerInputAll (void); +bool SetPlayerInput (COUNT playerI); +bool SetPlayerInputAll (void); void ClearPlayerInput (COUNT playerI); void ClearPlayerInputAll (void); diff --git a/sc2/src/sc2code/starcon.c b/sc2/src/sc2code/starcon.c index f74da4050..a68347f7d 100644 --- a/sc2/src/sc2code/starcon.c +++ b/sc2/src/sc2code/starcon.c @@ -162,7 +162,10 @@ while (--ac > 0) while (StartGame ()) { // Initialise a new game - SetPlayerInputAll (); + if (!SetPlayerInputAll ()) { + log_add (log_Fatal, "Could not set player input."); + explode (); // Does not return; + } InitSIS (); InitGameClock (); AddInitialGameEvents();