[Change] Moved credit funcions to economy.* and applied some moniez to NPC for you to loot.
This commit is contained in:
parent
2d664e3393
commit
39c99a064f
22
src/board.c
22
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);
|
||||
}
|
||||
|
16
src/economy.c
Normal file
16
src/economy.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#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);
|
||||
}
|
||||
|
4
src/economy.h
Normal file
4
src/economy.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void credits2str(char* str, unsigned int credits);
|
||||
|
10
src/player.c
10
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);
|
||||
|
Loading…
Reference in New Issue
Block a user