SetPlayerInput() and SetPlayerInputAll() may fail.

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3204 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
Meep-Eep
2009-10-08 19:59:53 +00:00
parent 7237f0bab3
commit c1d112191d
5 changed files with 28 additions and 11 deletions
+5 -1
View File
@@ -36,6 +36,7 @@
#include "setup.h" #include "setup.h"
#include "sounds.h" #include "sounds.h"
#include "libs/graphics/gfx_common.h" #include "libs/graphics/gfx_common.h"
#include "libs/log.h"
#include "libs/mathlib.h" #include "libs/mathlib.h"
#include "libs/inplib.h" #include "libs/inplib.h"
@@ -756,7 +757,10 @@ EncounterBattle (void)
PlayerControl[0] = CYBORG_CONTROL | AWESOME_RATING; PlayerControl[0] = CYBORG_CONTROL | AWESOME_RATING;
savedPlayerInput = PlayerInput[0]; savedPlayerInput = PlayerInput[0];
PlayerInput[0] = NULL; 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)); GameSounds = CaptureSound (LoadSound (GAME_SOUNDS));
+2 -1
View File
@@ -1738,7 +1738,8 @@ StartMelee (MELEE_STATE *pMS)
WaitForSoundEnd (TFBSOUND_WAIT_ALL); WaitForSoundEnd (TFBSOUND_WAIT_ALL);
SetPlayerInputAll (); if (!SetPlayerInputAll ())
break;
load_gravity_well ((BYTE)((COUNT)TFB_Random () % load_gravity_well ((BYTE)((COUNT)TFB_Random () %
NUMBER_OF_PLANET_TYPES)); NUMBER_OF_PLANET_TYPES));
Battle (); Battle ();
+15 -6
View File
@@ -231,7 +231,7 @@ InitGameKernel (void)
return TRUE; return TRUE;
} }
void bool
SetPlayerInput (COUNT playerI) SetPlayerInput (COUNT playerI)
{ {
assert (PlayerInput[playerI] == NULL); assert (PlayerInput[playerI] == NULL);
@@ -243,7 +243,7 @@ SetPlayerInput (COUNT playerI)
break; break;
case COMPUTER_CONTROL: case COMPUTER_CONTROL:
case CYBORG_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. // the ships and fights the battles.
// CYBORG_CONTROL is used in the full game; the computer only // CYBORG_CONTROL is used in the full game; the computer only
// fights the battles. XXX: This will need to be handled // fights the battles. XXX: This will need to be handled
@@ -260,23 +260,32 @@ SetPlayerInput (COUNT playerI)
break; break;
#endif #endif
default: default:
fprintf (stderr, "Invalid control method in SetPlayerInput().\n"); log_add (log_Fatal,
"Invalid control method in SetPlayerInput().");
explode (); /* Does not return */ explode (); /* Does not return */
} }
return PlayerInput[playerI] != NULL;
} }
void bool
SetPlayerInputAll (void) SetPlayerInputAll (void)
{ {
COUNT playerI; COUNT playerI;
for (playerI = 0; playerI < NUM_PLAYERS; playerI++) for (playerI = 0; playerI < NUM_PLAYERS; playerI++)
SetPlayerInput (playerI); if (!SetPlayerInput (playerI))
return false;
return true;
} }
void void
ClearPlayerInput (COUNT playerI) 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]->handlers->deleteContext (PlayerInput[playerI]);
PlayerInput[playerI] = NULL; PlayerInput[playerI] = NULL;
+2 -2
View File
@@ -67,8 +67,8 @@ extern void FreeKernel (void);
int initIO (void); int initIO (void);
void uninitIO (void); void uninitIO (void);
void SetPlayerInput (COUNT playerI); bool SetPlayerInput (COUNT playerI);
void SetPlayerInputAll (void); bool SetPlayerInputAll (void);
void ClearPlayerInput (COUNT playerI); void ClearPlayerInput (COUNT playerI);
void ClearPlayerInputAll (void); void ClearPlayerInputAll (void);
+4 -1
View File
@@ -162,7 +162,10 @@ while (--ac > 0)
while (StartGame ()) while (StartGame ())
{ {
// Initialise a new game // Initialise a new game
SetPlayerInputAll (); if (!SetPlayerInputAll ()) {
log_add (log_Fatal, "Could not set player input.");
explode (); // Does not return;
}
InitSIS (); InitSIS ();
InitGameClock (); InitGameClock ();
AddInitialGameEvents(); AddInitialGameEvents();