[Add] Added keybinding to cycle through secondary weapons backwards.

This commit is contained in:
Allanis 2014-05-22 20:35:23 +01:00
parent 23ec93cad4
commit 5a84266a4f
4 changed files with 42 additions and 8 deletions

3
README
View File

@ -104,7 +104,8 @@ Keys:
-- 'f' : Faces the target.
-- 'b' : Board the target.
-- 'LALT' : Fires secondary weapon.
-- 'e' : Switches to the next secondary weapon.
-- 'e' : Cycle through secondary weapons.
-- 'LCTRL+e' : Cycle backwards through secondary weapons.
Escorts:
-- Cycle through secondary weapons until you find fighter bay, then fire

View File

@ -44,7 +44,7 @@ const char* keybindNames[] = {
/* Fighting. */
"primary", "face", "board",
/* Secondary weapons. */
"secondary", "secondary_next",
"secondary", "secondary_next", "secondary_prev",
/* Escorts. */
"e_attack", "e_hold", "e_return", "e_clear",
/* Space Navigation. */
@ -78,6 +78,7 @@ const char* keybindDescription[] = {
/* Secondary weapons. */
"Fires your secondary weapon.",
"Cycles through secondary weapons.",
"Cycles backwards through secondary weapons.",
/* Escorts. */
"Tells your escorts to attack your target.",
"Tells your escorts to hold their posistion.",
@ -145,6 +146,7 @@ void input_setDefault(void) {
/* Secondary weapon. */
input_setKeybind("secondary", KEYBIND_KEYBOARD, SDLK_LALT, KMOD_ALL, 0);
input_setKeybind("secondary_next", KEYBIND_KEYBOARD, SDLK_e, KMOD_NONE, 0);
input_setKeybind("secondary_prev", KEYBIND_KEYBOARD, SDLK_e, KMOD_LCTRL, 0);
/* Space */
input_setKeybind("autonav", KEYBIND_KEYBOARD, SDLK_j, KMOD_LCTRL, 0);
input_setKeybind("target_planet", KEYBIND_KEYBOARD, SDLK_p, KMOD_NONE, 0);
@ -449,6 +451,7 @@ static void input_key(int keynum, double value, int kabs) {
else if(INGAME() && NODEAD() && KEY("e_clear")) {
if(value == KEY_PRESS) escorts_clear(player);
}
/* Secondary weapons. */
/* Shooting secondary weapon. */
else if(KEY("secondary") && NOHYP()) {
if(value == KEY_PRESS) {
@ -462,6 +465,9 @@ static void input_key(int keynum, double value, int kabs) {
else if(KEY("secondary_next") && INGAME()) {
if(value == KEY_PRESS) player_secondaryNext();
}
else if(KEY("secondary_prev") && INGAME()) {
if(value == KEY_PRESS) player_secondaryPrev();
}
/* Space. */
else if(KEY("autonav") && INGAME() && NOHYP()) {
if(value == KEY_PRESS) player_startAutonav();

View File

@ -1911,15 +1911,14 @@ void player_setRadarRel(int mod) {
* @brief Get the next secondary weapon.
*/
void player_secondaryNext(void) {
int i = 0;
int i;
/* Get the current secondary weapon pos. */
if(player->secondary != NULL)
for(i = 0; i < player->noutfits; i++)
if(&player->outfits[i] == player->secondary) {
i++;
break;
}
i = player->secondary - player->outfits + 1;
else
i = 0;
/* Get the next secondary weapon. */
for(; i < player->noutfits; i++)
if(outfit_isProp(player->outfits[i].outfit, OUTFIT_PROP_WEAP_SECONDARY)) {
@ -1933,6 +1932,33 @@ void player_secondaryNext(void) {
pilot_setAmmo(player);
}
/**
* @brief Get the previous secondary weapon.
*/
void player_secondaryPrev(void) {
int i;
/* Get current secondary weapon pos. */
if(player->secondary != NULL)
i = player->secondary - player->outfits - 1;
else
i = player->noutfits - 1;
/* Get next secondary weapon. */
for(; i >= 0; i--)
if(outfit_isProp(player->outfits[i].outfit, OUTFIT_PROP_WEAP_SECONDARY)) {
pilot_switchSecondary(player, i);
break;
}
/* Found no bigger outfit. */
if(i < 0)
pilot_switchSecondary(player, -1);
/* Set ammo. */
pilot_setAmmo(player);
}
/**
* @brief Cycle through planet targets.
*/

View File

@ -86,6 +86,7 @@ void player_targetPrev(void);
void player_targetNearest(void);
void player_setRadarRel(int mod);
void player_secondaryNext(void);
void player_secondaryPrev(void);
void player_targetPlanet(void);
void player_land(void);
void player_targetHyperspace(void);