[Change] Seperated boarding from player.c to board.c. Fixed ship information panel.
This commit is contained in:
parent
ae84dcf911
commit
5694a0b598
57
src/board.c
Normal file
57
src/board.c
Normal file
@ -0,0 +1,57 @@
|
||||
#include "lephisto.h"
|
||||
#include "pilot.h"
|
||||
#include "player.h"
|
||||
#include "toolkit.h"
|
||||
#include "space.h"
|
||||
#include "board.h"
|
||||
|
||||
#define BOARDING_WIDTH 300
|
||||
#define BOARDING_HEIGHT 200
|
||||
|
||||
extern unsigned int player_target;
|
||||
|
||||
static void player_unboard(char* str);
|
||||
|
||||
// Attempt to board the players target.
|
||||
void player_board(void) {
|
||||
Pilot* p;
|
||||
unsigned int wid;
|
||||
|
||||
if(player_target == PLAYER_ID) {
|
||||
player_message("You need a target to board first!");
|
||||
return;
|
||||
}
|
||||
|
||||
p = pilot_get(player_target);
|
||||
|
||||
if(!pilot_isDisabled(p)) {
|
||||
player_message("You cannot board a ship that is not disabled!");
|
||||
return;
|
||||
}
|
||||
if(vect_dist(&player->solid->pos, &p->solid->pos) >
|
||||
p->ship->gfx_space->sw * PILOT_SIZE_APROX) {
|
||||
player_message("You are too far away to board your target");
|
||||
return;
|
||||
}
|
||||
if((pow2(VX(player->solid->vel)-VX(p->solid->vel)) +
|
||||
pow2(VY(player->solid->vel)-VY(p->solid->vel))) >
|
||||
(double)pow2(MAX_HYPERSPACE_VEL)) {
|
||||
player_message("You are going too fast to board the ship");
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Actual boarding.
|
||||
player_message("Boarding ship %s", p->name);
|
||||
|
||||
// Create the boarding window.
|
||||
wid = window_create("Boarding", -1, -1, BOARDING_WIDTH, BOARDING_HEIGHT);
|
||||
|
||||
window_addButton(wid, 20, 20, 50, 30, "btnStealScred", "SCred", player_unboard);
|
||||
window_addButton(wid, -20, 20, 60, 30, "tbnBoardingClose", "Close", player_unboard);
|
||||
}
|
||||
|
||||
static void player_unboard(char* str) {
|
||||
if(strcmp(str, "btnBoardingClose")==0)
|
||||
window_destroy(window_get("Boarding"));
|
||||
}
|
||||
|
4
src/board.h
Normal file
4
src/board.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void player_board(void);
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "pause.h"
|
||||
#include "toolkit.h"
|
||||
#include "menu.h"
|
||||
#include "board.h"
|
||||
#include "input.h"
|
||||
|
||||
#define KEY_PRESS ( 1.)
|
||||
|
@ -10,6 +10,8 @@
|
||||
#define MAX(x,y) (((x)>(y))?(x):(y))
|
||||
#define MIN(x,y) (((x)>(y))?(y):(x))
|
||||
|
||||
#define pow2(x) ((x)*(x))
|
||||
|
||||
#define DATA_DEF "data" // Default data packfile.
|
||||
extern char* data; // Modifiable datafile.
|
||||
#define DATA data // Data file.
|
||||
|
44
src/player.c
44
src/player.c
@ -10,7 +10,6 @@
|
||||
#include "space.h"
|
||||
#include "rng.h"
|
||||
#include "land.h"
|
||||
#include "toolkit.h"
|
||||
#include "sound.h"
|
||||
#include "player.h"
|
||||
|
||||
@ -24,11 +23,6 @@
|
||||
|
||||
#define START_DATA "../dat/start.xml"
|
||||
|
||||
#define pow2(x) ((x)*(x))
|
||||
|
||||
#define BOARDING_WIDTH 300
|
||||
#define BOARDING_HEIGHT 200
|
||||
|
||||
// Player stuff.
|
||||
Pilot* player = NULL; // extern in pilot.h
|
||||
// Player global properties.
|
||||
@ -112,7 +106,6 @@ static void rect_parse(const xmlNodePtr parent, double* x, double* y, double* w,
|
||||
static int gui_parse(const xmlNodePtr parent, const char* name);
|
||||
static void gui_renderPilot(const Pilot* p);
|
||||
static void gui_renderBar(const glColour* c, const Rect* r, const double w);
|
||||
static void player_unboard(char* str);
|
||||
|
||||
// Create a new player.
|
||||
void player_new(void) {
|
||||
@ -844,43 +837,6 @@ void player_setRadarRel(int mod) {
|
||||
else if(gui.radar.res < RADAR_RES_MIN) gui.radar.res = RADAR_RES_MIN;
|
||||
}
|
||||
|
||||
void player_board(void) {
|
||||
Pilot* p;
|
||||
unsigned int wid;
|
||||
|
||||
if(player_target == PLAYER_ID) {
|
||||
player_message("You need a target to board first!");
|
||||
return;
|
||||
}
|
||||
p = pilot_get(player_target);
|
||||
|
||||
if(!pilot_isDisabled(p)) {
|
||||
player_message("You cannot board a ship that isn't disabled!");
|
||||
return;
|
||||
}
|
||||
if(vect_dist(&player->solid->pos, &p->solid->pos) > p->ship->gfx_space->sw * PILOT_SIZE_APROX) {
|
||||
player_message("You are too far away to board your target");
|
||||
return;
|
||||
}
|
||||
if((pow2(VX(player->solid->vel)-VX(p->solid->vel)) +
|
||||
pow2(VY(player->solid->vel)-VY(p->solid->vel))) > (double)pow2(MAX_HYPERSPACE_VEL)) {
|
||||
|
||||
player_message("You are going too fast to board the ship");
|
||||
return;
|
||||
}
|
||||
player_message("Boarding ship %s", p->name);
|
||||
|
||||
// Create boarding window.
|
||||
wid = window_create("Boarding", -1, -1, BOARDING_WIDTH, BOARDING_HEIGHT);
|
||||
|
||||
window_addButton(wid, -20, 20, 50, 30, "btnBoardingClose", "Close", player_unboard);
|
||||
}
|
||||
|
||||
static void player_unboard(char* str) {
|
||||
if(strcmp(str, "btnBoardingClose")==0)
|
||||
window_destroy(window_get("Boarding"));
|
||||
}
|
||||
|
||||
// Get the next secondary weapon.
|
||||
void player_secondaryNext(void) {
|
||||
int i = 0;
|
||||
|
@ -234,10 +234,11 @@ void ships_free(void) {
|
||||
|
||||
// Used to visualize the ships status.
|
||||
void ship_view(char* shipname) {
|
||||
Ship* s = NULL;
|
||||
Ship* s;
|
||||
char buf[1024];
|
||||
unsigned int wid;
|
||||
wid = window_create(shipname, -1, -1, VIEW_WIDTH, VIEW_HEIGHT);
|
||||
s = ship_get(shipname);
|
||||
|
||||
window_addText(wid, 20, 0, 100, VIEW_HEIGHT-30,
|
||||
0, "txtLabel", &gl_smallFont, &cDConsole,
|
||||
|
Loading…
Reference in New Issue
Block a user