[Add] Implemented the ability to steal fuel from ships.

This commit is contained in:
Allanis 2014-03-10 01:40:46 +00:00
parent 9a4b745939
commit 4e3c85f369

View File

@ -9,12 +9,16 @@
#include "hook.h"
#include "board.h"
#define BOARDING_WIDTH 300 /** Boarding window width. */
#define BOARDING_HEIGHT 200 /** boarding window height. */
#define BOARDING_WIDTH 300 /**< Boarding window width. */
#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_stealCreds(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 void board_update(unsigned int wdw);
@ -66,19 +70,18 @@ void player_board(void) {
window_addText(wdw, 20, -30, 120, 60,
0, "txtCargo", &gl_smallFont, &cDConsole,
"SCreds:\n"
"Cargo:\n");
"Cargo:\n"
"Fuel:");
window_addText(wdw, 80, -30, 120, 60, 0, "txtData",
&gl_smallFont, &cBlack, NULL);
window_addButton(wdw, 20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
"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",
"Credits", board_stealCreds);
window_addButton(wdw, 90, 20, 50, 30, "btnStealCargo",
"Cargo", board_stealCargo);
window_addButton(wdw, -20, 20, 50, 30, "btnBoardingClose",
"Leave", board_exit);
window_addButton(wdw, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
"btnBoardingClose", "Leave", board_exit);
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.");
}
/**
* @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.
* @return 1 on failure to board. Otherwise 0.
@ -189,28 +227,41 @@ static int board_fail(unsigned int wdw) {
* @brief Updates the boarding window.
*/
static void board_update(unsigned int wdw) {
int i;
int i, len;
char str[128], buf[32];
char cred[10];
Pilot* p;
p = pilot_get(player->target);
/* Credits. */
credits2str(cred, p->credits, 2);
snprintf(str, 11,
"%s\n", cred);
if(p->ncommodities == 0)
strncat(str, "none", 10);
else {
snprintf(str, 128, "%s\n", cred);
len = strlen(str);
/* Commodities. */
if(p->ncommodities == 0) {
strncat(str, "none", 128-len);
len = strlen(str);
} else {
for(i = 0; i < p->ncommodities; i++) {
snprintf(buf, 32,
"%d %s\n",
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);
}