[Add] Implemented the ability to steal fuel from ships.
This commit is contained in:
parent
9a4b745939
commit
4e3c85f369
91
src/board.c
91
src/board.c
@ -9,12 +9,16 @@
|
|||||||
#include "hook.h"
|
#include "hook.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
|
||||||
#define BOARDING_WIDTH 300 /** Boarding window width. */
|
#define BOARDING_WIDTH 300 /**< Boarding window width. */
|
||||||
#define BOARDING_HEIGHT 200 /** boarding window height. */
|
#define BOARDING_HEIGHT 200 /**< Boarding window height. */
|
||||||
|
|
||||||
|
#define BUTTON_WIDTH 50 /**< Boarding button width. */
|
||||||
|
#define BUTTON_HEIGHT 30 /**< Boarding button height. */
|
||||||
|
|
||||||
static void board_exit(unsigned int wdw, char* str);
|
static void board_exit(unsigned int wdw, char* str);
|
||||||
static void board_stealCreds(unsigned int wdw, char* str);
|
static void board_stealCreds(unsigned int wdw, char* str);
|
||||||
static void board_stealCargo(unsigned int wdw, char* str);
|
static void board_stealCargo(unsigned int wdw, char* str);
|
||||||
|
static void board_stealFuel(unsigned int wdw, char* str);
|
||||||
static int board_fail(unsigned int wdw);
|
static int board_fail(unsigned int wdw);
|
||||||
static void board_update(unsigned int wdw);
|
static void board_update(unsigned int wdw);
|
||||||
|
|
||||||
@ -66,19 +70,18 @@ void player_board(void) {
|
|||||||
window_addText(wdw, 20, -30, 120, 60,
|
window_addText(wdw, 20, -30, 120, 60,
|
||||||
0, "txtCargo", &gl_smallFont, &cDConsole,
|
0, "txtCargo", &gl_smallFont, &cDConsole,
|
||||||
"SCreds:\n"
|
"SCreds:\n"
|
||||||
"Cargo:\n");
|
"Cargo:\n"
|
||||||
|
"Fuel:");
|
||||||
|
|
||||||
window_addText(wdw, 80, -30, 120, 60, 0, "txtData",
|
window_addButton(wdw, 20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
|
||||||
&gl_smallFont, &cBlack, NULL);
|
"btnStealCredits", "Credits", board_stealCreds);
|
||||||
|
window_addButton(wdw, 20+BUTTON_WIDTH+20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
|
||||||
|
"btnStealCargo", "Cargo", board_stealCargo);
|
||||||
|
window_addButton(wdw, 20+2*(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT,
|
||||||
|
"btnStealFuel", "Fuel", board_stealFuel);
|
||||||
|
|
||||||
window_addButton(wdw, 20, 20, 50, 30, "btnStealCredits",
|
window_addButton(wdw, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
|
||||||
"Credits", board_stealCreds);
|
"btnBoardingClose", "Leave", board_exit);
|
||||||
|
|
||||||
window_addButton(wdw, 90, 20, 50, 30, "btnStealCargo",
|
|
||||||
"Cargo", board_stealCargo);
|
|
||||||
|
|
||||||
window_addButton(wdw, -20, 20, 50, 30, "btnBoardingClose",
|
|
||||||
"Leave", board_exit);
|
|
||||||
|
|
||||||
board_update(wdw);
|
board_update(wdw);
|
||||||
|
|
||||||
@ -158,6 +161,41 @@ static void board_stealCargo(unsigned int wdw, char* str) {
|
|||||||
player_message("You manage to steal the ship's cargo.");
|
player_message("You manage to steal the ship's cargo.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*/
|
||||||
|
static void board_stealFuel(unsigned int wdw, char* str) {
|
||||||
|
(void)str;
|
||||||
|
double f;
|
||||||
|
Pilot* p;
|
||||||
|
|
||||||
|
p = pilot_get(player->target);
|
||||||
|
|
||||||
|
if(p->fuel <= 0.) { /* Urgh.. They don't have any fuel. */
|
||||||
|
player_message("The ship has no fuel.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if(p->fuel == p->fuel_max) {
|
||||||
|
player_message("Your ship is at maximum fuel capacity.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(board_fail(wdw)) return;
|
||||||
|
|
||||||
|
/* Steal fuel. */
|
||||||
|
f = player->fuel;
|
||||||
|
player->fuel += p->fuel;
|
||||||
|
|
||||||
|
/* Make sure doesn't overflow. */
|
||||||
|
if(player->fuel > player->fuel_max) {
|
||||||
|
p->fuel = player->fuel_max - player->fuel;
|
||||||
|
player->fuel = player->fuel_max;
|
||||||
|
}
|
||||||
|
|
||||||
|
board_update(wdw);
|
||||||
|
player_message("You manage to steal the ships fuel.");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check to see if the hijack attempt failed.
|
* @brief Check to see if the hijack attempt failed.
|
||||||
* @return 1 on failure to board. Otherwise 0.
|
* @return 1 on failure to board. Otherwise 0.
|
||||||
@ -189,28 +227,41 @@ static int board_fail(unsigned int wdw) {
|
|||||||
* @brief Updates the boarding window.
|
* @brief Updates the boarding window.
|
||||||
*/
|
*/
|
||||||
static void board_update(unsigned int wdw) {
|
static void board_update(unsigned int wdw) {
|
||||||
int i;
|
int i, len;
|
||||||
char str[128], buf[32];
|
char str[128], buf[32];
|
||||||
char cred[10];
|
char cred[10];
|
||||||
Pilot* p;
|
Pilot* p;
|
||||||
|
|
||||||
p = pilot_get(player->target);
|
p = pilot_get(player->target);
|
||||||
|
|
||||||
|
/* Credits. */
|
||||||
credits2str(cred, p->credits, 2);
|
credits2str(cred, p->credits, 2);
|
||||||
|
|
||||||
snprintf(str, 11,
|
snprintf(str, 128, "%s\n", cred);
|
||||||
"%s\n", cred);
|
len = strlen(str);
|
||||||
if(p->ncommodities == 0)
|
|
||||||
strncat(str, "none", 10);
|
/* Commodities. */
|
||||||
else {
|
if(p->ncommodities == 0) {
|
||||||
|
strncat(str, "none", 128-len);
|
||||||
|
len = strlen(str);
|
||||||
|
} else {
|
||||||
for(i = 0; i < p->ncommodities; i++) {
|
for(i = 0; i < p->ncommodities; i++) {
|
||||||
snprintf(buf, 32,
|
snprintf(buf, 32,
|
||||||
"%d %s\n",
|
"%d %s\n",
|
||||||
p->commodities[i].quantity, p->commodities[i].commodity->name);
|
p->commodities[i].quantity, p->commodities[i].commodity->name);
|
||||||
strncat(str, buf, 32);
|
strncat(str, buf, 128-len);
|
||||||
|
len = strlen(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(p->fuel <= 0.)
|
||||||
|
strncat(str, "none", 128-len);
|
||||||
|
else {
|
||||||
|
snprintf(buf, 32, "%.0f Units", p->fuel);
|
||||||
|
strncat(str, buf, 128-len);
|
||||||
|
}
|
||||||
|
len = strlen(str);
|
||||||
|
|
||||||
window_modifyText(wdw, "txtData", str);
|
window_modifyText(wdw, "txtData", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user