From 5a84266a4fa609146a5049e529be5fbefa8b35b6 Mon Sep 17 00:00:00 2001 From: Allanis Date: Thu, 22 May 2014 20:35:23 +0100 Subject: [PATCH] [Add] Added keybinding to cycle through secondary weapons backwards. --- README | 3 ++- src/input.c | 8 +++++++- src/player.c | 38 ++++++++++++++++++++++++++++++++------ src/player.h | 1 + 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/README b/README index 1173354..d4fc205 100644 --- a/README +++ b/README @@ -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 diff --git a/src/input.c b/src/input.c index 50a9af5..b9ba214 100644 --- a/src/input.c +++ b/src/input.c @@ -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(); diff --git a/src/player.c b/src/player.c index 35ada6b..98dfc74 100644 --- a/src/player.c +++ b/src/player.c @@ -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. */ diff --git a/src/player.h b/src/player.h index f9ce8da..7e5999d 100644 --- a/src/player.h +++ b/src/player.h @@ -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);