From 39c99a064fe92880581c05dc5ac96d7d6955655a Mon Sep 17 00:00:00 2001 From: Allanis Date: Wed, 27 Feb 2013 17:32:25 +0000 Subject: [PATCH] [Change] Moved credit funcions to economy.* and applied some moniez to NPC for you to loot. --- src/board.c | 22 +++++++++++++++++++++- src/economy.c | 16 ++++++++++++++++ src/economy.h | 4 ++++ src/player.c | 10 ++++------ 4 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 src/economy.c create mode 100644 src/economy.h diff --git a/src/board.c b/src/board.c index e2eeb1c..2d78cb6 100644 --- a/src/board.c +++ b/src/board.c @@ -3,6 +3,8 @@ #include "player.h" #include "toolkit.h" #include "space.h" +#include "rng.h" +#include "economy.h" #include "board.h" #define BOARDING_WIDTH 300 @@ -10,12 +12,16 @@ extern unsigned int player_target; +static unsigned int board_credits = 0; // Penniez on the ship. + static void player_unboard(char* str); // Attempt to board the players target. void player_board(void) { Pilot* p; unsigned int wid; + char str[128]; + char cred[10]; if(player_target == PLAYER_ID) { player_message("You need a target to board first!"); @@ -40,12 +46,26 @@ void player_board(void) { return; } - // TODO: Actual boarding. player_message("Boarding ship %s", p->name); + // Calculate credits based on ship price. + board_credits = RNG(20*p->ship->price, 50*p->ship->price)/1000; + // Create the boarding window. wid = window_create("Boarding", -1, -1, BOARDING_WIDTH, BOARDING_HEIGHT); + window_addText(wid, 20, -30, 120, 60, + 0, "txtCargo", &gl_smallFont, &cDConsole, + "Credits:\n" + "Cargo:\n"); + credits2str(cred, board_credits); + snprintf(str, 128, + "%s\n" + "%s\n", + cred, "none"); + + window_addText(wid, 80, -30, 120, 60, 0, "txtData", &gl_smallFont, &cBlack, str); + window_addButton(wid, 20, 20, 50, 30, "btnStealScred", "SCred", player_unboard); window_addButton(wid, -20, 20, 60, 30, "btnBoardingClose", "Close", player_unboard); } diff --git a/src/economy.c b/src/economy.c new file mode 100644 index 0000000..0798d18 --- /dev/null +++ b/src/economy.c @@ -0,0 +1,16 @@ +#include +#include "lephisto.h" +#include "economy.h" + +// Convert credits to a usable string for displaying. +// str must have 10 characters allocated. +void credits2str(char* str, unsigned int credits) { + if(credits >= 1000000000) + snprintf(str, 10, "%.2fB", (double)credits / 1000000000.); + else if(credits >= 1000000) + snprintf(str, 10, "%2fM", (double)credits / 1000000.); + else if(credits >= 1000) + snprintf(str, 10, "%.2fK", (double)credits / 1000.); + else snprintf(str, 10, "%d", credits); +} + diff --git a/src/economy.h b/src/economy.h new file mode 100644 index 0000000..2473c23 --- /dev/null +++ b/src/economy.h @@ -0,0 +1,4 @@ +#pragma once + +void credits2str(char* str, unsigned int credits); + diff --git a/src/player.c b/src/player.c index f55a110..ba35b39 100644 --- a/src/player.c +++ b/src/player.c @@ -11,6 +11,7 @@ #include "rng.h" #include "land.h" #include "sound.h" +#include "economy.h" #include "player.h" #define XML_GUI_ID "GUIs" // XML section identifier. @@ -446,12 +447,9 @@ void player_render(void) { // Misc. gl_print(NULL, gui.misc.x + 10, gui.misc.y - 10 - gl_defFont.h, &cConsole, "SCred:"); - if(credits >= 1000000) - snprintf(str, 10, "%.2fM", (double)credits / 1000000.); - else if(credits >= 1000) - snprintf(str, 10, "%.2fK", (double) credits / 1000.); - else - snprintf(str, 10, "%d", credits); + + credits2str(str, credits); + i = gl_printWidth(&gl_smallFont, "%s", str); gl_print(&gl_smallFont, gui.misc.x + gui.misc.w - 10 - i, gui.misc.y - 10 - gl_defFont.h, NULL, "%s", str);