[Add] You can somewhat steal credits now.
[Fix] Only board the ship once.
This commit is contained in:
parent
9aa025e812
commit
ddc831b353
82
src/board.c
82
src/board.c
@ -13,13 +13,16 @@
|
|||||||
extern unsigned int player_target;
|
extern unsigned int player_target;
|
||||||
|
|
||||||
static unsigned int board_credits = 0; // Penniez on the ship.
|
static unsigned int board_credits = 0; // Penniez on the ship.
|
||||||
|
static unsigned int board_wid = 0;
|
||||||
|
|
||||||
static void player_unboard(char* str);
|
static void board_exit(char* str);
|
||||||
|
static void board_stealCreds(char* str);
|
||||||
|
static void board_fail(void);
|
||||||
|
static void board_update(void);
|
||||||
|
|
||||||
// Attempt to board the players target.
|
// Attempt to board the players target.
|
||||||
void player_board(void) {
|
void player_board(void) {
|
||||||
Pilot* p;
|
Pilot* p;
|
||||||
unsigned int wid;
|
|
||||||
char str[128];
|
char str[128];
|
||||||
char cred[10];
|
char cred[10];
|
||||||
|
|
||||||
@ -34,29 +37,35 @@ void player_board(void) {
|
|||||||
player_message("You cannot board a ship that is not disabled!");
|
player_message("You cannot board a ship that is not disabled!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(vect_dist(&player->solid->pos, &p->solid->pos) >
|
else if(vect_dist(&player->solid->pos, &p->solid->pos) >
|
||||||
p->ship->gfx_space->sw * PILOT_SIZE_APROX) {
|
p->ship->gfx_space->sw * PILOT_SIZE_APROX) {
|
||||||
player_message("You are too far away to board your target");
|
player_message("You are too far away to board your target");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if((pow2(VX(player->solid->vel)-VX(p->solid->vel)) +
|
else if((pow2(VX(player->solid->vel)-VX(p->solid->vel)) +
|
||||||
pow2(VY(player->solid->vel)-VY(p->solid->vel))) >
|
pow2(VY(player->solid->vel)-VY(p->solid->vel))) >
|
||||||
(double)pow2(MAX_HYPERSPACE_VEL)) {
|
(double)pow2(MAX_HYPERSPACE_VEL)) {
|
||||||
player_message("You are going too fast to board the ship");
|
player_message("You are going too fast to board the ship");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if(pilot_isFlag(p, PILOT_BOARDED)) {
|
||||||
|
player_message("Your target cannot be boarded again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pilot will be boarded.
|
||||||
|
pilot_setFlag(p, PILOT_BOARDED);
|
||||||
player_message("Boarding ship %s", p->name);
|
player_message("Boarding ship %s", p->name);
|
||||||
|
|
||||||
// Calculate credits based on ship price.
|
// Calculate credits based on ship price.
|
||||||
board_credits = RNG(20*p->ship->price, 50*p->ship->price)/1000;
|
board_credits = RNG(20*p->ship->price, 50*p->ship->price)/1000;
|
||||||
|
|
||||||
// Create the boarding window.
|
// Create the boarding window.
|
||||||
wid = window_create("Boarding", -1, -1, BOARDING_WIDTH, BOARDING_HEIGHT);
|
board_wid = window_create("Boarding", -1, -1, BOARDING_WIDTH, BOARDING_HEIGHT);
|
||||||
|
|
||||||
window_addText(wid, 20, -30, 120, 60,
|
window_addText(board_wid, 20, -30, 120, 60,
|
||||||
0, "txtCargo", &gl_smallFont, &cDConsole,
|
0, "txtCargo", &gl_smallFont, &cDConsole,
|
||||||
"Credits:\n"
|
"SCreds:\n"
|
||||||
"Cargo:\n");
|
"Cargo:\n");
|
||||||
credits2str(cred, board_credits);
|
credits2str(cred, board_credits);
|
||||||
snprintf(str, 128,
|
snprintf(str, 128,
|
||||||
@ -64,14 +73,63 @@ void player_board(void) {
|
|||||||
"%s\n",
|
"%s\n",
|
||||||
cred, "none");
|
cred, "none");
|
||||||
|
|
||||||
window_addText(wid, 80, -30, 120, 60, 0, "txtData", &gl_smallFont, &cBlack, str);
|
window_addText(board_wid, 80, -30, 120, 60, 0, "txtData", &gl_smallFont, &cBlack, str);
|
||||||
|
|
||||||
window_addButton(wid, 20, 20, 50, 30, "btnStealScred", "SCred", player_unboard);
|
window_addButton(board_wid, 20, 20, 50, 30, "btnStealScred", "SCred", board_exit);
|
||||||
window_addButton(wid, -20, 20, 60, 30, "btnBoardingClose", "Close", player_unboard);
|
window_addButton(board_wid, -20, 20, 50, 30, "btnBoardingClose", "Close", board_exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void player_unboard(char* str) {
|
static void board_exit(char* str) {
|
||||||
if(strcmp(str, "btnBoardingClose")==0)
|
(void)str;
|
||||||
window_destroy(window_get("Boarding"));
|
window_destroy(window_get("Boarding"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void board_stealCreds(char* str) {
|
||||||
|
(void)str;
|
||||||
|
|
||||||
|
if(board_credits == 0) {
|
||||||
|
player_message("The ship has no SCreds left");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate success - TODO: make this based on crew.
|
||||||
|
if(RNG(0, 100) < 50) {
|
||||||
|
board_fail();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
credits += board_credits;
|
||||||
|
board_credits = 0;
|
||||||
|
board_update(); // Update the lack of credits.
|
||||||
|
player_message("You manage to steal the ship's credits");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Failed to board.
|
||||||
|
static void board_fail(void) {
|
||||||
|
Pilot* p;
|
||||||
|
|
||||||
|
if(RNG(0, 2)==0) {
|
||||||
|
p = pilot_get(player_target);
|
||||||
|
p->armour = -1;
|
||||||
|
player_message("You have tripped the ship's self destruct mechanism!");
|
||||||
|
} else
|
||||||
|
player_message("The ship's security system locks you out!");
|
||||||
|
|
||||||
|
board_exit(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the cargo and credit fields.
|
||||||
|
static void board_update(void) {
|
||||||
|
char str[128];
|
||||||
|
char cred[10];
|
||||||
|
|
||||||
|
credits2str(cred, board_credits);
|
||||||
|
|
||||||
|
snprintf(str, 128,
|
||||||
|
"%s\n"
|
||||||
|
"%s\n",
|
||||||
|
cred, "none");
|
||||||
|
|
||||||
|
window_modifyText(board_wid, "txtData", str);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#define PILOT_HYP_PREP (1<<5) // Pilot is getting ready for hyperspace.
|
#define PILOT_HYP_PREP (1<<5) // Pilot is getting ready for hyperspace.
|
||||||
#define PILOT_HYP_BEGIN (1<<6) // Pilot is starting engines.
|
#define PILOT_HYP_BEGIN (1<<6) // Pilot is starting engines.
|
||||||
#define PILOT_HYPERSPACE (1<<7) // Pilot is in hyperspace.
|
#define PILOT_HYPERSPACE (1<<7) // Pilot is in hyperspace.
|
||||||
|
#define PILOT_BOARDED (1<<8) // Pilot has been boarded already!
|
||||||
#define PILOT_DISABLED (1<<9) // Pilot is disabled.
|
#define PILOT_DISABLED (1<<9) // Pilot is disabled.
|
||||||
#define PILOT_DEAD (1<<10) // Pilot is on it's death bed.
|
#define PILOT_DEAD (1<<10) // Pilot is on it's death bed.
|
||||||
#define PILOT_DELETE (1<<15) // Pilot will get delete asap.
|
#define PILOT_DELETE (1<<15) // Pilot will get delete asap.
|
||||||
|
@ -15,6 +15,7 @@ typedef enum WidgetStatus_ {
|
|||||||
WIDGET_STATUS_NORMAL,
|
WIDGET_STATUS_NORMAL,
|
||||||
WIDGET_STATUS_MOUSEOVER,
|
WIDGET_STATUS_MOUSEOVER,
|
||||||
WIDGET_STATUS_MOUSEDOWN,
|
WIDGET_STATUS_MOUSEDOWN,
|
||||||
|
WIDGET_STATUS_FOCUS
|
||||||
} WidgetStatus;
|
} WidgetStatus;
|
||||||
|
|
||||||
typedef struct Widget_ {
|
typedef struct Widget_ {
|
||||||
@ -75,6 +76,7 @@ static int mwindows = 0;
|
|||||||
static Widget* window_newWidget(Window* w);
|
static Widget* window_newWidget(Window* w);
|
||||||
static void widget_cleanup(Widget* widget);
|
static void widget_cleanup(Widget* widget);
|
||||||
static Window* window_wget(const unsigned int wid);
|
static Window* window_wget(const unsigned int wid);
|
||||||
|
static Widget* window_getwgt(const unsigned int wid, char* name);
|
||||||
// Input.
|
// Input.
|
||||||
static void toolkit_mouseEvent(SDL_Event* event);
|
static void toolkit_mouseEvent(SDL_Event* event);
|
||||||
// Render.
|
// Render.
|
||||||
@ -192,6 +194,22 @@ static Window* window_wget(const unsigned int wid) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Widget* window_getwgt(const unsigned int wid, char* name) {
|
||||||
|
int i;
|
||||||
|
Window* wdw = window_wget(wid);
|
||||||
|
for(i = 0; i < wdw->nwidgets; i++)
|
||||||
|
if(strcmp(wdw->widgets[i].name, name)==0)
|
||||||
|
return &wdw->widgets[i];
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void window_modifyText(const unsigned int wid, char* name, char* newstring) {
|
||||||
|
Widget* wgt = window_getwgt(wid, name);
|
||||||
|
|
||||||
|
if(wgt->dat.txt.text) free(wgt->dat.txt.text);
|
||||||
|
wgt->dat.txt.text = strdup(newstring);
|
||||||
|
}
|
||||||
|
|
||||||
// Check if a window exists.
|
// Check if a window exists.
|
||||||
int window_exists(const char* wdwname) {
|
int window_exists(const char* wdwname) {
|
||||||
int i;
|
int i;
|
||||||
@ -532,6 +550,8 @@ static void toolkit_renderButton(Widget* btn, double bx, double by) {
|
|||||||
dc = &cGrey40;
|
dc = &cGrey40;
|
||||||
oc = &cGrey20;
|
oc = &cGrey20;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shaded base.
|
// Shaded base.
|
||||||
|
@ -19,6 +19,9 @@ void window_addText(const unsigned int wid, const int x, const int y,
|
|||||||
void window_addImage(const unsigned int wid, const int x, const int y,
|
void window_addImage(const unsigned int wid, const int x, const int y,
|
||||||
char* name, glTexture* image);
|
char* name, glTexture* image);
|
||||||
|
|
||||||
|
// Modification
|
||||||
|
void window_modifyText(const unsigned int wid, char* name, char* newstring);
|
||||||
|
|
||||||
// Get the window by name.
|
// Get the window by name.
|
||||||
int window_exists(const char* wdwname);
|
int window_exists(const char* wdwname);
|
||||||
unsigned int window_get(const char* wdwname);
|
unsigned int window_get(const char* wdwname);
|
||||||
|
Loading…
Reference in New Issue
Block a user