From d366fec5b86eaed2a844a00f1ef421c6a378e769 Mon Sep 17 00:00:00 2001 From: Allanis Date: Mon, 4 Aug 2014 23:31:59 +0100 Subject: [PATCH] [Add] Added keybindings for targetting escorts. --- src/input.c | 12 +++++++++++- src/pilot.c | 19 +++++++++++++++++++ src/player.c | 38 ++++++++++++++++++++++++++++++++++++++ src/player.h | 1 + 4 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/input.c b/src/input.c index a41c806..974efd7 100644 --- a/src/input.c +++ b/src/input.c @@ -47,7 +47,7 @@ const char* keybindNames[] = { /* Secondary weapons. */ "secondary", "secondary_next", "secondary_prev", /* Escorts. */ - "e_attack", "e_hold", "e_return", "e_clear", + "e_targetNext", "e_targetPrev", "e_attack", "e_hold", "e_return", "e_clear", /* Space Navigation. */ "autonav", "target_planet", "land", "thyperspace","starmap", "jump", /* Communication. */ @@ -81,6 +81,8 @@ const char* keybindDescription[] = { "Cycles through secondary weapons.", "Cycles backwards through secondary weapons.", /* Escorts. */ + "Cycles through your esorts.", + "Cycles backwards through your escorts.", "Tells your escorts to attack your target.", "Tells your escorts to hold their posistion.", "Tells your escorts to return to your ships hanger.", @@ -143,6 +145,8 @@ void input_setDefault(void) { input_setKeybind("face", KEYBIND_KEYBOARD, SDLK_f, KMOD_NONE); input_setKeybind("board", KEYBIND_KEYBOARD, SDLK_b, KMOD_NONE); /* Escorts. */ + input_setKeybind("e_targetNext", KEYBIND_KEYBOARD, SDLK_g, KMOD_NONE); /* Tmp keybind. */ + input_setKeybind("e_targetPrev", KEYBIND_KEYBOARD, SDLK_g, KMOD_LCTRL); /* Tmp keybind. */ input_setKeybind("e_attack", KEYBIND_KEYBOARD, SDLK_1, KMOD_NONE); input_setKeybind("e_hold", KEYBIND_KEYBOARD, SDLK_2, KMOD_NONE); input_setKeybind("e_return", KEYBIND_KEYBOARD, SDLK_3, KMOD_NONE); @@ -486,6 +490,12 @@ static void input_key(int keynum, double value, double kabs) { } } /* Escorts. */ + else if(INGAME() && NODEAD() && KEY("e_targetNext")) { + if(value == KEY_PRESS) player_targetEscort(0); + } + else if(INGAME() && NODEAD() && KEY("e_targetPrev")) { + if(value == KEY_PRESS) player_targetEscort(1); + } else if(INGAME() && NODEAD() && KEY("e_attack")) { if(value == KEY_PRESS) escorts_attack(player); } diff --git a/src/pilot.c b/src/pilot.c index ad53088..3ba3d5c 100644 --- a/src/pilot.c +++ b/src/pilot.c @@ -689,6 +689,25 @@ int pilot_dock(Pilot* p, Pilot* target) { if(vect_dist(&p->solid->vel, &target->solid->vel) > 2*MIN_VEL_ERR) return -1; + /* Remove from pilots escort list. */ + for(i = 0; i < target->nescorts; i++) { + if(target->escorts[i] == p->id) + break; + } + /* Not found as pilots escorts. */ + if(i >= target->nescorts) + return -1; + /* Free if last pilot. */ + if(target->nescorts == 1) { + free(target->escorts); + target->escorts = NULL; + target->nescorts = 0; + } else { + memmove(&target->escorts[i], &target->escorts[i+1], + sizeof(unsigned int) * p->nescorts-i-1); + target->nescorts--; + } + /* Check to see if target has an available bay. */ for(i = 0; i < target->noutfits; i++) { if(outfit_isFighterBay(target->outfits[i].outfit)) { diff --git a/src/player.c b/src/player.c index 5ae2eb8..fb8f0a2 100644 --- a/src/player.c +++ b/src/player.c @@ -1238,6 +1238,44 @@ void player_targetPrev(void) { player_playSound(snd_target, 1); } +/** + * @brief Target the pilot. + * @param prev 1 if is cycling backwords. + */ +void player_targetEscort(int prev) { + int i; + + /* Check if current target is an escort. */ + for(i = 0; i < player->nescorts; i++) { + if(player->target == player->escorts[i]) { + /* Cycle targets. */ + if(prev) + player->target = (i > 0) ? + player->escorts[i-1] : PLAYER_ID; + else + player->target = (i < player->nescorts-1) ? + player->escorts[i+1] : PLAYER_ID; + break; + } + } + + /* Not found in loop. */ + if(i > player->nescorts) { + /* check see if she actually has escorts. */ + if(player->nescorts > 0) { + /* Cycle forward or backwords. */ + if(prev) + player->target = player->escorts[player->nescorts-1]; + else + player->target = player->escorts[0]; + } else + player->target = PLAYER_ID; + } + + if(player->target != PLAYER_ID) + player_playSound(snd_target, 1); +} + /** * @brief Player targets nearest pilot. */ diff --git a/src/player.h b/src/player.h index 257955a..3a06250 100644 --- a/src/player.h +++ b/src/player.h @@ -85,6 +85,7 @@ void player_targetHostile(void); void player_targetNext(void); void player_targetPrev(void); void player_targetNearest(void); +void player_targetEscort(int prev); void player_secondaryNext(void); void player_secondaryPrev(void); void player_targetPlanet(void);