static void ProcessInput (void) { BOOLEAN CanRunAway; size_t sideI; #ifdef NETPLAY netInput (); #endif CanRunAway = RunAwayAllowed (); for (sideI = 0; sideI < NUM_SIDES; sideI++) { HSTARSHIP hBattleShip, hNextShip; size_t cur_player = battleInputOrder[sideI]; for (hBattleShip = GetHeadLink (&race_q[cur_player]); hBattleShip != 0; hBattleShip = hNextShip) { BATTLE_INPUT_STATE InputState; STARSHIP *StarShipPtr; StarShipPtr = LockStarShip (&race_q[cur_player], hBattleShip); hNextShip = _GetSuccLink (StarShipPtr); if (StarShipPtr->hShip) { // TODO: review and see if we have to do this every frame, or // if we can do this once somewhere StarShipPtr->control = PlayerControl[cur_player]; InputState = PlayerInput[cur_player]->handlers->frameInput ( PlayerInput[cur_player], StarShipPtr); #if CREATE_JOURNAL JournalInput (InputState); #endif /* CREATE_JOURNAL */ #ifdef NETPLAY if (!(PlayerControl[cur_player] & NETWORK_CONTROL)) { BattleInputBuffer *bib = getBattleInputBuffer(cur_player); Netplay_NotifyAll_battleInput (InputState); flushPacketQueues (); BattleInputBuffer_push (bib, InputState); // Add this input to the end of the buffer. BattleInputBuffer_pop (bib, &InputState); // Get the input from the front of the buffer. } #endif StarShipPtr->ship_input_state = 0; if (StarShipPtr->RaceDescPtr->ship_info.crew_level) { if (InputState & BATTLE_LEFT) StarShipPtr->ship_input_state |= LEFT; else if (InputState & BATTLE_RIGHT) StarShipPtr->ship_input_state |= RIGHT; if (InputState & BATTLE_THRUST) StarShipPtr->ship_input_state |= THRUST; if (InputState & BATTLE_WEAPON) StarShipPtr->ship_input_state |= WEAPON; if (InputState & BATTLE_SPECIAL) StarShipPtr->ship_input_state |= SPECIAL; if (InputState & BATTLE_DOWN) StarShipPtr->ship_input_state |= DOWN; // JMS_KEYS: Down key is now in use! if (CanRunAway && cur_player == 0 && (InputState & BATTLE_ESCAPE)) DoRunAway (StarShipPtr); } } UnlockStarShip (&race_q[cur_player], hBattleShip); } } #ifdef NETPLAY flushPacketQueues (); #endif if (GLOBAL (CurrentActivity) & (CHECK_LOAD | CHECK_ABORT)) GLOBAL (CurrentActivity) &= ~IN_BATTLE; }
/* TODO: Include player timeouts */ static BOOLEAN DoGetMelee (GETMELEE_STATE *gms) { BOOLEAN done; COUNT playerI; SetMenuSounds (MENU_SOUND_NONE, MENU_SOUND_NONE); if (!gms->Initialized) { gms->Initialized = TRUE; return TRUE; } for (playerI = 0; playerI < NUM_PLAYERS; playerI++) { if (!gms->player[playerI].selecting) continue; if (!gms->player[playerI].done) Flash_process (gms->player[playerI].flashContext); } SleepThread (ONE_SECOND / 120); #ifdef NETPLAY netInput (); if (!allConnected ()) goto aborted; #endif if (GLOBAL (CurrentActivity) & CHECK_ABORT) goto aborted; done = TRUE; for (playerI = 0; playerI < NUM_PLAYERS; playerI++) { if (!gms->player[playerI].selecting) continue; if (!gms->player[playerI].done) { if (!PlayerInput[playerI]->handlers->selectShip ( PlayerInput[playerI], gms)) goto aborted; if (gms->player[playerI].done) { Flash_terminate (gms->player[playerI].flashContext); gms->player[playerI].flashContext = NULL; } else done = FALSE; } } #ifdef NETPLAY flushPacketQueues (); #endif return !done; aborted: #ifdef NETPLAY flushPacketQueues (); #endif for (playerI = 0; playerI < NUM_PLAYERS; playerI++) { if (!gms->player[playerI].selecting) continue; gms->player[playerI].choice = 0; gms->player[playerI].hBattleShip = 0; } GLOBAL (CurrentActivity) &= ~CHECK_ABORT; return FALSE; }