[Add] Added communication framework allowing you to interact with other pilots/planets.

This commit is contained in:
Allanis 2014-01-01 21:44:00 +00:00
parent e40a9ecbf7
commit 73b034d1ec
6 changed files with 84 additions and 10 deletions

View File

@ -10,22 +10,22 @@
<tech>7</tech> <tech>7</tech>
<description>!Used for testing!</description> <description>!Used for testing!</description>
<movement> <movement>
<thrust>220</thrust> <thrust>320</thrust>
<turn>135</turn> <turn>135</turn>
<speed>260</speed> <speed>260</speed>
</movement> </movement>
<health> <health>
<shield>340</shield> <shield>11340</shield>
<armour>300</armour> <armour>11300</armour>
<energy>380</energy> <energy>11380</energy>
<shield_regen>380</shield_regen> <shield_regen>11380</shield_regen>
<armour_regen>360</armour_regen> <armour_regen>11360</armour_regen>
<energy_regen>1000</energy_regen> <energy_regen>11000</energy_regen>
</health> </health>
<characteristics> <characteristics>
<crew>4</crew> <crew>10</crew>
<mass>95</mass> <mass>95</mass>
<fuel>1000</fuel> <fuel>1000000</fuel>
<cap_weapon>800</cap_weapon> <cap_weapon>800</cap_weapon>
<cap_cargo>6000</cap_cargo> <cap_cargo>6000</cap_cargo>
</characteristics> </characteristics>

54
src/comm.c Normal file
View File

@ -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;
}
}

4
src/comm.h Normal file
View File

@ -0,0 +1,4 @@
#pragma once
int comm_open(unsigned int pilot);

View File

@ -45,6 +45,8 @@ const char* keybindNames[] = {
"secondary", "secondary_next", "secondary", "secondary_next",
/* Space Navigation. */ /* Space Navigation. */
"autonav", "target_planet", "land", "thyperspace","starmap", "jump", "autonav", "target_planet", "land", "thyperspace","starmap", "jump",
/* Communication. */
"hail",
/* Misc. */ /* Misc. */
"mapzoomin", "mapzoomout", "screenshot", "pause", "menu", "info", "mapzoomin", "mapzoomout", "screenshot", "pause", "menu", "info",
"end" /* Must terminate at the end. */ "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("thyperspace", KEYBIND_KEYBOARD, SDLK_h, KMOD_NONE, 0);
input_setKeybind("starmap", KEYBIND_KEYBOARD, SDLK_m, KMOD_NONE, 0); input_setKeybind("starmap", KEYBIND_KEYBOARD, SDLK_m, KMOD_NONE, 0);
input_setKeybind("jump", KEYBIND_KEYBOARD, SDLK_j, 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. */ /* Misc. */
input_setKeybind("mapzoomin", KEYBIND_KEYBOARD, SDLK_KP_PLUS, KMOD_NONE, 0); input_setKeybind("mapzoomin", KEYBIND_KEYBOARD, SDLK_KP_PLUS, KMOD_NONE, 0);
input_setKeybind("mapzoomout", KEYBIND_KEYBOARD, SDLK_KP_MINUS, 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(); player_jump();
} }
} }
/* Communication. */
else if(KEY("hail") && INGAME() && NOHYP()) {
if(value == KEY_PRESS) {
player_hail();
}
}
/* Zoom in. */ /* Zoom in. */
else if(KEY("mapzoomin") && INGAME()) { else if(KEY("mapzoomin") && INGAME()) {
if(value == KEY_PRESS) player_setRadarRel(1); if(value == KEY_PRESS) player_setRadarRel(1);

View File

@ -30,6 +30,7 @@
#include "lfile.h" #include "lfile.h"
#include "spfx.h" #include "spfx.h"
#include "unidiff.h" #include "unidiff.h"
#include "comm.h"
#include "player.h" #include "player.h"
#define XML_GUI_ID "GUIs" /**< XML section identifier for GUI document. */ #define XML_GUI_ID "GUIs" /**< XML section identifier for GUI document. */
@ -2030,6 +2031,11 @@ void player_screenshot(void) {
gl_screenshot(filename); gl_screenshot(filename);
} }
void player_hail(void) {
if(player->target != player->id)
comm_open(player->target);
}
/** /**
* @fn void player_dead(void) * @fn void player_dead(void)
* *

View File

@ -88,4 +88,5 @@ void player_accel(double acc);
void player_accelOver(void); void player_accelOver(void);
void player_startAutonav(void); void player_startAutonav(void);
void player_abortAutonav(void); void player_abortAutonav(void);
void player_hail(void);