[Change] Improve key handling to avoid situations where pilot gets
"blocked".
This commit is contained in:
		
							parent
							
								
									ae91853484
								
							
						
					
					
						commit
						cc33574b5e
					
				
							
								
								
									
										61
									
								
								src/input.c
									
									
									
									
									
								
							
							
						
						
									
										61
									
								
								src/input.c
									
									
									
									
									
								
							| @ -209,7 +209,7 @@ void input_exit(void) { | ||||
| static void input_keyConvGen(void) { | ||||
|   SDLKey k; | ||||
| 
 | ||||
|   for(k == SDLK_FIRST; k < SDLK_LAST; k++) | ||||
|   for(k = SDLK_FIRST; k < SDLK_LAST; k++) | ||||
|     keyconv[k] = SDL_GetKeyName(k); | ||||
| } | ||||
| 
 | ||||
| @ -339,36 +339,46 @@ static void input_key(int keynum, double value, int kabs) { | ||||
| 
 | ||||
|     if(value == KEY_PRESS) input_accelLast = t; | ||||
|   } | ||||
|   /* Afterburning. */ | ||||
|   else if(KEY("afterburn") && INGAME() && NOHYP()) { | ||||
|     if(value == KEY_PRESS) player_afterburn(); | ||||
|     else if(value == KEY_RELEASE) player_afterburnOver(); | ||||
|     if(value == KEY_PRESS) | ||||
|       player_afterburn(); | ||||
|     else if((value == KEY_RELEASE) && player_isFlag(PLAYER_AFTERBURNER)) | ||||
|       player_afterburnOver(); | ||||
|   } | ||||
|   /* Turning left. */ | ||||
|   else if(KEY("left")) { | ||||
|     if(kabs) | ||||
|       player_turn = -value; | ||||
|     else { | ||||
|       /* Set flags for facing correction. */ | ||||
|       if(value == KEY_PRESS) { | ||||
|         player_abortAutonav(NULL); | ||||
|         player_setFlag(PLAYER_TURN_LEFT); | ||||
|       } | ||||
|     else if(value == KEY_RELEASE) { player_rmFlag(PLAYER_TURN_LEFT); } | ||||
| 
 | ||||
|     if(kabs) { player_turn = -value; } | ||||
|     else { player_turn -= value; } | ||||
|     if(player_turn < -1.) player_turn = -1.; /* Make sure value is sane. */ | ||||
|       else if(value == KEY_RELEASE) | ||||
|         player_rmFlag(PLAYER_TURN_LEFT); | ||||
|       player_turn -= value; | ||||
|     } | ||||
|     /* Make sure the value is sane. */ | ||||
|     if(player_turn < -1.) player_turn = -1.; | ||||
|   } | ||||
|   /* Turning right. */ | ||||
|   else if(KEY("right")) { | ||||
|     if(kabs) | ||||
|       player_turn = value; | ||||
|     else { | ||||
|       /* Set flags for facing correction. */ | ||||
|       if(value == KEY_PRESS) { | ||||
|         player_abortAutonav(NULL); | ||||
|         player_setFlag(PLAYER_TURN_RIGHT); | ||||
|       } | ||||
|     else if(value == KEY_RELEASE) { player_rmFlag(PLAYER_TURN_RIGHT); } | ||||
| 
 | ||||
|     if(kabs) { player_turn = value; } | ||||
|     else { player_turn += value; } | ||||
| 
 | ||||
|     if(player_turn < -1.) { player_turn = -1.; } /* Make sure value is sane. */ | ||||
|       else if(value == KEY_RELEASE) | ||||
|         player_rmFlag(PLAYER_TURN_RIGHT); | ||||
|       player_turn += value; | ||||
|     } | ||||
|     /* Make sure the value is sane. */ | ||||
|     if(player_turn > 1.) player_turn = 1.; | ||||
|   } | ||||
|   /* Turn around to face vel. */ | ||||
|   else if(KEY("reverse")) { | ||||
| @ -376,7 +386,7 @@ static void input_key(int keynum, double value, int kabs) { | ||||
|       player_abortAutonav(NULL); | ||||
|       player_setFlag(PLAYER_REVERSE); | ||||
|     } | ||||
|     else if(value == KEY_RELEASE) { | ||||
|     else if((value == KEY_RELEASE) && player_isFlag(PLAYER_REVERSE)) { | ||||
|       player_rmFlag(PLAYER_REVERSE); | ||||
|       player_turn = 0; /* Turning corrections. */ | ||||
|       if(player_isFlag(PLAYER_TURN_LEFT))  { player_turn -= 1; } | ||||
| @ -410,7 +420,7 @@ static void input_key(int keynum, double value, int kabs) { | ||||
|       player_abortAutonav(NULL); | ||||
|       player_setFlag(PLAYER_FACE); | ||||
|     } | ||||
|     else if(value == KEY_RELEASE) { | ||||
|     else if((value == KEY_RELEASE) && player_isFlag(PLAYER_FACE)) { | ||||
|       player_rmFlag(PLAYER_FACE); | ||||
| 
 | ||||
|       /* Turning corrections. */ | ||||
| @ -441,8 +451,12 @@ static void input_key(int keynum, double value, int kabs) { | ||||
|   } | ||||
|   /* Shooting secondary weapon. */ | ||||
|   else if(KEY("secondary") && NOHYP()) { | ||||
|     if(value == KEY_PRESS) { player_setFlag(PLAYER_SECONDARY); } | ||||
|     else if(value == KEY_RELEASE) { player_rmFlag(PLAYER_SECONDARY); } | ||||
|     if(value == KEY_PRESS) { | ||||
|       player_abortAutonav(NULL); | ||||
|       player_setFlag(PLAYER_SECONDARY); | ||||
|     } | ||||
|     else if(value == KEY_RELEASE) | ||||
|       player_rmFlag(PLAYER_SECONDARY); | ||||
|   } | ||||
|   /* Selecting secondary weapon. */ | ||||
|   else if(KEY("secondary_next") && INGAME()) { | ||||
| @ -569,11 +583,16 @@ static void input_keyevent(int event, SDLKey key, SDLMod mod) { | ||||
| 
 | ||||
|   mod &= ~(KMOD_CAPS | KMOD_NUM | KMOD_MODE); /* We want to ignore "global" modifiers. */ | ||||
| 
 | ||||
|   for(i = 0; strcmp(keybindNames[i], "end"); i++) | ||||
|   for(i = 0; strcmp(keybindNames[i], "end"); i++) { | ||||
|     if((input_keybinds[i]->type == KEYBIND_KEYBOARD) && | ||||
|         (input_keybinds[i]->key == key) && | ||||
|         ((input_keybinds[i]->mod == mod) || (input_keybinds[i]->mod == KMOD_ALL))) | ||||
|         (input_keybinds[i]->key == key)) { | ||||
|       if((input_keybinds[i]->mod == mod) || | ||||
|           (input_keybinds[i]->mod == KMOD_ALL) || | ||||
|           (event == KEY_RELEASE)) /**< Release always gets through. */ | ||||
|         input_key(i, event, 0); | ||||
|       /* No break so all keys get pressed if needed. */ | ||||
|     } | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Allanis
						Allanis