diff --git a/dat/ship.xml b/dat/ship.xml index 8ac79b8..35d509e 100644 --- a/dat/ship.xml +++ b/dat/ship.xml @@ -10,22 +10,22 @@ 7 !Used for testing! - 220 + 320 135 260 - 340 - 300 - 380 - 380 - 360 - 1000 + 11340 + 11300 + 11380 + 11380 + 11360 + 11000 - 4 + 10 95 - 1000 + 1000000 800 6000 diff --git a/src/comm.c b/src/comm.c new file mode 100644 index 0000000..9a6ba11 --- /dev/null +++ b/src/comm.c @@ -0,0 +1,54 @@ +/** + * @file comm.c + * + * @brief For communicating with planets/pilots. + */ + +#include "lephisto.h" +#include "log.h" +#include "toolkit.h" +#include "pilot.h" +#include "comm.h" + +#define COMM_WIDTH 320 /**< Communication window width. */ +#define COMM_HEIGHT 240 /**< Communication window height. */ + +#define BUTTON_WIDTH 90 /**< Button width. */ +#define BUTTON_HEIGHT 30 /*<< Button height. */ + +static Pilot* comm_pilot = NULL; /**< Pilot currently talking to. */ +static int comm_wid = 0; /**< Communication window ID. */ + +static void comm_close(char* str); + +/** + * @brief Open the communication dialogue with a pilot. + * @param pilot Pilot to communicate with. + * @return 0 on success. + */ +int comm_open(unsigned int pilot) { + char buf[128]; + + /* Get the pilot. */ + comm_pilot = pilot_get(pilot); + if(comm_pilot == NULL) + return -1; + + /* Create the window. */ + snprintf(buf, 128, "Comm - %s", comm_pilot->name); + comm_wid = window_create(buf, -1, -1, COMM_WIDTH, COMM_HEIGHT); + + window_addButton(comm_wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, + "btnClose", "Close Channel", comm_close); + + return 0; +} + +static void comm_close(char* str) { + (void)str; + if(comm_wid > 0) { + window_destroy(comm_wid); + comm_wid = 0; + } +} + diff --git a/src/comm.h b/src/comm.h new file mode 100644 index 0000000..474b11c --- /dev/null +++ b/src/comm.h @@ -0,0 +1,4 @@ +#pragma once + +int comm_open(unsigned int pilot); + diff --git a/src/input.c b/src/input.c index 0de096c..4e8d436 100644 --- a/src/input.c +++ b/src/input.c @@ -45,6 +45,8 @@ const char* keybindNames[] = { "secondary", "secondary_next", /* Space Navigation. */ "autonav", "target_planet", "land", "thyperspace","starmap", "jump", + /* Communication. */ + "hail", /* Misc. */ "mapzoomin", "mapzoomout", "screenshot", "pause", "menu", "info", "end" /* Must terminate at the end. */ @@ -94,7 +96,8 @@ void input_setDefault(void) { input_setKeybind("thyperspace", KEYBIND_KEYBOARD, SDLK_h, KMOD_NONE, 0); input_setKeybind("starmap", KEYBIND_KEYBOARD, SDLK_m, KMOD_NONE, 0); input_setKeybind("jump", KEYBIND_KEYBOARD, SDLK_j, KMOD_NONE, 0); - + /* Communication. */ + input_setKeybind("hail", KEYBIND_KEYBOARD, SDLK_y, KMOD_NONE, 0); /* Misc. */ input_setKeybind("mapzoomin", KEYBIND_KEYBOARD, SDLK_KP_PLUS, KMOD_NONE, 0); input_setKeybind("mapzoomout", KEYBIND_KEYBOARD, SDLK_KP_MINUS, KMOD_NONE, 0); @@ -362,6 +365,12 @@ static void input_key(int keynum, double value, int kabs) { player_jump(); } } + /* Communication. */ + else if(KEY("hail") && INGAME() && NOHYP()) { + if(value == KEY_PRESS) { + player_hail(); + } + } /* Zoom in. */ else if(KEY("mapzoomin") && INGAME()) { if(value == KEY_PRESS) player_setRadarRel(1); diff --git a/src/player.c b/src/player.c index 135e5aa..2e1f7e0 100644 --- a/src/player.c +++ b/src/player.c @@ -30,6 +30,7 @@ #include "lfile.h" #include "spfx.h" #include "unidiff.h" +#include "comm.h" #include "player.h" #define XML_GUI_ID "GUIs" /**< XML section identifier for GUI document. */ @@ -2030,6 +2031,11 @@ void player_screenshot(void) { gl_screenshot(filename); } +void player_hail(void) { + if(player->target != player->id) + comm_open(player->target); +} + /** * @fn void player_dead(void) * diff --git a/src/player.h b/src/player.h index b0c5b99..8d1d636 100644 --- a/src/player.h +++ b/src/player.h @@ -88,4 +88,5 @@ void player_accel(double acc); void player_accelOver(void); void player_startAutonav(void); void player_abortAutonav(void); +void player_hail(void);