diff --git a/src/board.c b/src/board.c index 38172b6..3888827 100644 --- a/src/board.c +++ b/src/board.c @@ -12,13 +12,11 @@ #define BOARDING_WIDTH 300 /** Boarding window width. */ #define BOARDING_HEIGHT 200 /** boarding window height. */ -static unsigned int board_wid = 0; /** Boarding window identifier. */ - -static void board_exit(char* str); -static void board_stealCreds(char* str); -static void board_stealCargo(char* str); -static int board_fail(void); -static void board_update(void); +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 int board_fail(unsigned int wdw); +static void board_update(unsigned int wdw); /** * @fn void player_board(void) @@ -29,6 +27,7 @@ static void board_update(void); */ void player_board(void) { Pilot* p; + unsigned int wdw; if(player->target == PLAYER_ID) { player_message("You need a target to board first!"); @@ -62,49 +61,47 @@ void player_board(void) { player_message("Boarding ship %s.", p->name); /* Create the boarding window. */ - board_wid = window_create("Boarding", -1, -1, BOARDING_WIDTH, BOARDING_HEIGHT); + wdw = window_create("Boarding", -1, -1, BOARDING_WIDTH, BOARDING_HEIGHT); - window_addText(board_wid, 20, -30, 120, 60, + window_addText(wdw, 20, -30, 120, 60, 0, "txtCargo", &gl_smallFont, &cDConsole, "SCreds:\n" "Cargo:\n"); - window_addText(board_wid, 80, -30, 120, 60, 0, "txtData", + window_addText(wdw, 80, -30, 120, 60, 0, "txtData", &gl_smallFont, &cBlack, NULL); - window_addButton(board_wid, 20, 20, 50, 30, "btnStealCredits", + window_addButton(wdw, 20, 20, 50, 30, "btnStealCredits", "Credits", board_stealCreds); - window_addButton(board_wid, 90, 20, 50, 30, "btnStealCargo", + window_addButton(wdw, 90, 20, 50, 30, "btnStealCargo", "Cargo", board_stealCargo); - window_addButton(board_wid, -20, 20, 50, 30, "btnBoardingClose", + window_addButton(wdw, -20, 20, 50, 30, "btnBoardingClose", "Leave", board_exit); - board_update(); + board_update(wdw); /* Run hook if needed. */ pilot_runHook(p, PILOT_HOOK_BOARD); } /** - * @fn void board_exit(char* str) - * * @brief Closes the boarding window. + * @param wdw Window triggered the function. * @param str Unused. */ -static void board_exit(char* str) { - (void)str; - window_destroy(window_get("Boarding")); +static void board_exit(unsigned int wdw, char* str) { + (void) str; + window_destroy(wdw); } /** - * @fn static void board_stealCreds(char* str) - * * @brief Attempt to steal the boarding ships credits. + * @param wdw Window triggered the function. * @param str Unused. */ -static void board_stealCreds(char* str) { +static void board_stealCreds(unsigned int wdw, char* str) { (void)str; Pilot* p; @@ -116,21 +113,20 @@ static void board_stealCreds(char* str) { return; } - if(board_fail()) return; + if(board_fail(wdw)) return; player->credits += p->credits; p->credits = 0; - board_update(); /* Update the lack of credits. */ + board_update(wdw); /* Update the lack of credits. */ player_message("You manage to steal the ship's Scred."); } /** - * @fn static void board_stealCargo(char* str) - * - * @breif Attempt to steal the boarded ships cargo. + * @brief Attempt to steal the boarded ships cargo. + * @param wdw Window triggering the function. * @param str Unused. */ -static void board_stealCargo(char* str) { +static void board_stealCargo(unsigned int wdw, char* str) { (void)str; int q; Pilot* p; @@ -147,7 +143,7 @@ static void board_stealCargo(char* str) { return; } - if(board_fail()) return; + if(board_fail(wdw)) return; /** Steal as much as possible until full - @todo: Allow the player to choose. */ q = 1; @@ -158,17 +154,15 @@ static void board_stealCargo(char* str) { pilot_rmCargo(p, p->commodities[0].commodity, q); } - board_update(); + board_update(wdw); player_message("You manage to steal the ship's cargo."); } /** - * @fn static int board_fail(void) - * * @brief Check to see if the hijack attempt failed. * @return 1 on failure to board. Otherwise 0. */ -static int board_fail(void) { +static int board_fail(unsigned int wdw) { Pilot* p; p = pilot_get(player->target); @@ -186,16 +180,14 @@ static int board_fail(void) { /* You just got locked out!! */ player_message("The ship's security system locks you out!"); - board_exit(NULL); + board_exit(wdw, NULL); return 1; } /** - * @fn static void board_update(void) - * * @brief Updates the boarding window. */ -static void board_update(void) { +static void board_update(unsigned int wdw) { int i; char str[128], buf[32]; char cred[10]; @@ -218,6 +210,6 @@ static void board_update(void) { } } - window_modifyText(board_wid, "txtData", str); + window_modifyText(wdw, "txtData", str); }