[Add] Added target_prev keybind.

This commit is contained in:
Allanis 2014-01-04 15:33:18 +00:00
parent 45dd236662
commit 014b71e8d6
5 changed files with 65 additions and 20 deletions

View File

@ -36,7 +36,7 @@ const char* keybindNames[] = {
/* Movement. */
"accel", "left", "right", "reverse", "afterburn",
/* Targetting. */
"target", "target_nearest", "target_hostile",
"target", "target_prev", "target_nearest", "target_hostile",
/* Fighting. */
"primary", "face", "board",
/* Escorts. */
@ -73,6 +73,7 @@ void input_setDefault(void) {
input_setKeybind("reverse", KEYBIND_KEYBOARD, SDLK_s, KMOD_ALL, 0);
/* Targetting. */
input_setKeybind("target", KEYBIND_KEYBOARD, SDLK_TAB, KMOD_NONE, 0);
input_setKeybind("target_prev", KEYBIND_KEYBOARD, SDLK_TAB, KMOD_RCTRL, 0);
input_setKeybind("target_nearest", KEYBIND_KEYBOARD, SDLK_t, KMOD_NONE, 0);
input_setKeybind("target_hostile", KEYBIND_KEYBOARD, SDLK_r, KMOD_NONE, 0);
/* Combat. */
@ -285,6 +286,9 @@ static void input_key(int keynum, double value, int kabs) {
else if(INGAME() && NODEAD() && KEY("target")) {
if(value == KEY_PRESS) player_targetNext();
}
else if(INGAME() && NODEAD() && KEY("target_prev")) {
if(value == KEY_PRESS) player_targetPrev();
}
else if(INGAME() && NODEAD() && KEY("target_nearest")) {
if(value == KEY_PRESS) player_targetNearest();
}

View File

@ -58,6 +58,7 @@ extern void player_dead(void);
extern void player_destroyed(void);
extern int gui_load(const char* name);
/* Internal. */
static int pilot_getStackPos(const unsigned int id);
static void pilot_shootWeapon(Pilot* p, PilotOutfit* w);
static void pilot_update(Pilot* pilot, const double dt);
static void pilot_hyperspace(Pilot* pilot);
@ -68,13 +69,13 @@ static Fleet* fleet_parse(const xmlNodePtr parent);
static void pilot_dead(Pilot* p);
/**
* @fn unsinged int pilot_getNextID(const unsigned int id)
* @fn static int pilot_getStackPos(const unsigned int id)
*
* @brief Get the next pilot on id.
* @param id ID of current pilot.
* @return ID of next pilot of PLAYER_ID if no next pilot.
* @brief Get the pilots position in the stack.
* @param id ID of the pilot to get.
* @return Position of pilot in stack or -1 if not found.
*/
unsigned int pilot_getNextID(const unsigned int id) {
static int pilot_getStackPos(const unsigned int id) {
/* Binary search. */
int l, m, h;
l = 0;
@ -83,13 +84,44 @@ unsigned int pilot_getNextID(const unsigned int id) {
m = (l+h) >> 1; /* For impossible overflow returning negative value. */
if(pilot_stack[m]->id > id) h = m-1;
else if(pilot_stack[m]->id < id) l = m+1;
else break;
else return m;
}
if(m == (pilot_nstack-1)) return PLAYER_ID;
/* Not found. */
return -1;
}
/**
* @fn unsinged int pilot_getNextID(const unsigned int id)
*
* @brief Get the next pilot on id.
* @param id ID of current pilot.
* @return ID of next pilot of PLAYER_ID if no next pilot.
*/
unsigned int pilot_getNextID(const unsigned int id) {
int m;
m = pilot_getStackPos(id);
if((m == (pilot_nstack-1)) || (m == -1)) return PLAYER_ID;
else return pilot_stack[m+1]->id;
}
/**
* @fn unsigned int pilot_getPrevID(const unsigned int id)
*
* @brief Get the previous pilot based on ID.
* @param id ID of the current pilot.
* @return ID of previous pilot or PLAYER_ID if no previous pilot.
*/
unsigned int pilot_getPrevID(const unsigned int id) {
int m;
m = pilot_getStackPos(id);
if(m == -1) return PLAYER_ID;
else if(m == 0) return pilot_stack[pilot_nstack-1]->id;
else return pilot_stack[m-1]->id;
}
/**
* @brief Get the nearest enemy to the pilot.
* @param p Pilot to get his nearest enemy.
@ -139,19 +171,16 @@ unsigned int pilot_getNearestPilot(const Pilot* p) {
/* Pull a pilot out of the pilot_stack based on id. */
Pilot* pilot_get(const unsigned int id) {
int m;
if(id == PLAYER_ID) return player; /* Special case player. */
/* Binary search. */
int l, m, h;
l = 0;
h = pilot_nstack-1;
while(l <= h) {
m = (l+h)>>1;
if(pilot_stack[m]->id > id) h = m-1;
else if(pilot_stack[m]->id < id) l = m+1;
else return pilot_stack[m];
}
m = pilot_getStackPos(id);
if(m == -1)
return NULL;
else
return pilot_stack[m];
}
/* Grab a fleet out of the stack. */

View File

@ -222,6 +222,7 @@ typedef struct Fleet_ {
extern Pilot* player; /* The player. */
Pilot* pilot_get(unsigned int id);
unsigned int pilot_getNextID(const unsigned int id);
unsigned int pilot_getPrevID(const unsigned int id);
unsigned int pilot_getNearestEnemy(const Pilot* p);
unsigned int pilot_getNearestHostile(void); /* Only for the player. */
unsigned int pilot_getNearestPilot(const Pilot* p);

View File

@ -1975,6 +1975,16 @@ void player_targetNext(void) {
player_playSound(snd_target, 1);
}
/**
* @fn
*/
void player_targetPrev(void) {
player->target = pilot_getPrevID(player->target);
if(player->target != PLAYER_ID)
player_playSound(snd_target, 1);
}
/**
* @fn player_targetNearest(void)
*

View File

@ -74,6 +74,7 @@ int player_missionAlreadyDone(int id);
/* Keybind actions. */
void player_targetHostile(void);
void player_targetNext(void);
void player_targetPrev(void);
void player_targetNearest(void);
void player_setRadarRel(int mod);
void player_secondaryNext(void);