18#include "land_trade.h"
25#include "land_shipyard.h"
31#include "player_fleet.h"
33#include "tk/toolkit_priv.h"
48 ImageArrayCell *cgoods;
49 int w, h, iw, ih, dw, bw, titleHeight, infoHeight;
50 char buf[STRMAX_SHORT];
55 land_tabGenerate(LAND_WINDOW_COMMODITY);
62 iw = 565 + (w - LAND_WIDTH);
68 window_addButtonKey( wid, 40 + iw, 20, bw, LAND_BUTTON_HEIGHT,
70 window_addButtonKey( wid, 60 + iw + bw, 20, bw, LAND_BUTTON_HEIGHT,
72 window_addButtonKey( wid, 80 + iw + 2*bw, 20, bw, LAND_BUTTON_HEIGHT,
76 window_addCust( wid, 40 + iw, 40 + LAND_BUTTON_HEIGHT, 2*bw + 20,
81 window_addRect( wid, -20, -40, 192, 192,
"rctStore", &cBlack, 0 );
82 window_addImage( wid, -20, -40, 192, 192,
"imgStore", NULL, 1 );
86 window_addText( wid, 40 + iw, -40, dw, titleHeight, 0,
91 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Money:") );
92 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Market Price:") );
93 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Average price here:") );
94 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Average galactic price:") );
95 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"Purchased for:") );
97 window_addText( wid, 40 + iw, -60 - titleHeight, 200, infoHeight, 0,
99 window_addText( wid, 40 + iw + 224, -60 - titleHeight,
100 dw - (200 + 20+192), infoHeight, 0,
103 window_addText( wid, 40 + iw, -80-titleHeight-infoHeight,
105 window_addText( wid, 40 + iw,
MIN(-80-titleHeight-infoHeight, -192-60),
106 dw, h - (80+titleHeight+infoHeight) - (40+LAND_BUTTON_HEIGHT), 0,
117 if (!commodity_isFlag(pc->
commodity, COMMODITY_FLAG_ALWAYS_CAN_SELL))
122 cgoods = calloc( ngoods,
sizeof(ImageArrayCell) );
123 if (commodity_list != NULL)
124 free(commodity_list);
125 commodity_list = malloc( ngoods*
sizeof(
Commodity*) );
133 if (!commodity_isFlag(pc->
commodity, COMMODITY_FLAG_ALWAYS_CAN_SELL))
151 cgoods = calloc( ngoods,
sizeof(ImageArrayCell) );
152 cgoods[0].image = NULL;
153 cgoods[0].caption = strdup(_(
"None"));
159 if (toolkit_simImageArrayVisibleElements(iw,ih,iconsize,iconsize) < ngoods)
161 if (toolkit_simImageArrayVisibleElements(iw,ih,iconsize,iconsize) < ngoods)
164 window_addImageArray( wid, 20, 20,
165 iw, ih,
"iarTrade", iconsize, iconsize,
172void commodity_exchange_cleanup (
void)
174 free(commodity_list);
175 commodity_list = NULL;
187 char buf_purchase_price[ECON_CRED_STRLEN], buf_credits[ECON_CRED_STRLEN];
190 credits_t mean,globalmean;
191 double std, globalstd;
192 char buf_mean[ECON_CRED_STRLEN], buf_globalmean[ECON_CRED_STRLEN];
193 char buf_std[ECON_CRED_STRLEN], buf_globalstd[ECON_CRED_STRLEN];
194 char buf_local_price[ECON_CRED_STRLEN];
195 char buf_tonnes_owned[ECON_MASS_STRLEN], buf_tonnes_free[ECON_MASS_STRLEN];
196 int owned, cargo_free;
197 int i = toolkit_getImageArrayPos( wid,
"iarTrade" );
200 tonnes2str( buf_tonnes_free, cargo_free );
203 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s", _(
"N/A") );
204 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", buf_tonnes_free );
205 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", buf_credits );
206 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s",
"" );
207 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"N/A") );
208 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"N/A") );
209 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", _(
"N/A") );
210 window_modifyText( wid,
"txtDInfo", buf );
211 window_modifyText( wid,
"txtDesc", _(
"No commodities available.") );
212 window_disableButton( wid,
"btnCommodityBuy" );
213 window_disableButton( wid,
"btnCommoditySell" );
216 com = commodity_list[i];
219 window_modifyImage( wid,
"imgStore", com->
gfx_store, 192, 192 );
222 credits2str( buf_mean, mean, -1 );
223 snprintf( buf_std,
sizeof(buf_std), _(
"%.1f ¤"), std );
225 credits2str( buf_globalmean, globalmean, -1 );
226 snprintf( buf_globalstd,
sizeof(buf_globalstd), _(
"%.1f ¤"), globalstd );
228 buf_purchase_price[0]=
'\0';
233 tonnes2str( buf_tonnes_owned, owned );
234 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s", buf_tonnes_owned );
235 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", buf_tonnes_free );
236 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", buf_credits );
237 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
238 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%s/t"), buf_local_price );
239 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
240 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%s/t ± %s/t"), buf_mean, buf_std );
241 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n" );
242 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%s/t ± %s/t"), buf_globalmean, buf_globalstd );
243 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n%s", buf_purchase_price );
245 window_modifyText( wid,
"txtDInfo", buf );
246 window_modifyText( wid,
"txtName", _(com->
name) );
247 window_modifyText( wid,
"txtDesc", _(com->
description) );
251 if (commodity_isFlag(com, COMMODITY_FLAG_PRICE_CONSTANT)) {
252 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"Price is constant.") );
253 window_modifyText( wid,
"txtDRef", buf );
261 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"Price is based on #%c%.0f%%#0 of the price of #o%s#0."),
c, com->
price_mod*100., _(com->
price_ref) );
262 window_modifyText( wid,
"txtDRef", buf );
265 window_modifyText( wid,
"txtDRef", NULL );
269 window_enableButton( wid,
"btnCommodityBuy" );
271 window_disableButtonSoft( wid,
"btnCommodityBuy" );
274 window_enableButton( wid,
"btnCommoditySell" );
276 window_disableButtonSoft( wid,
"btnCommoditySell" );
284 int failure, incommodities;
285 unsigned int q, price;
286 char buf[ECON_CRED_STRLEN];
309 if (!incommodities) {
346 i = toolkit_getImageArrayPos( wid,
"iarTrade" );
347 com = commodity_list[i];
362 hparam[0].
type = HOOK_PARAM_STRING;
364 hparam[1].
type = HOOK_PARAM_NUMBER;
366 hparam[2].
type = HOOK_PARAM_SENTINEL;
368 land_needsTakeoff( 1 );
387 i = toolkit_getImageArrayPos( wid,
"iarTrade" );
388 com = commodity_list[i];
397 price = price * (credits_t)q;
404 hparam[0].
type = HOOK_PARAM_STRING;
406 hparam[1].
type = HOOK_PARAM_NUMBER;
408 hparam[2].
type = HOOK_PARAM_SENTINEL;
410 land_needsTakeoff( 1 );
419 SDL_Keymod mods = SDL_GetModState();
421 if (mods & (KMOD_LCTRL | KMOD_RCTRL))
423 if (mods & (KMOD_LSHIFT | KMOD_RSHIFT))
449 snprintf( buf,
sizeof(buf),
"%dx", q );
Provides macros to work with dynamic arrays.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
int economy_getAveragePrice(const Commodity *com, credits_t *mean, double *std)
Gets the average price of a good as seen by the player (anywhere).
int gl_printHeightRaw(const glFont *ft_font, const int width, const char *text)
Gets the height of a non-formatted string.
int gl_printMidRaw(const glFont *ft_font, int width, double x, double y, const glColour *c, double outlineR, const char *text)
Displays text centered in position and width.
int hooks_runParam(const char *stack, const HookParam *param)
Runs all the hooks of stack.
void land_errDialogueBuild(const char *fmt,...)
Generates error dialogues used by several landing tabs.
int land_errDialogue(const char *name, const char *type)
Generates error dialogues used by several landing tabs.
void land_buttonTakeoff(unsigned int wid, const char *unused)
Wrapper for takeoff mission button.
int commodity_canBuy(const Commodity *com)
Checks to see if the player can buy a commodity.
int commodity_getMod(void)
Gets the current modifier status.
void commodity_exchange_open(unsigned int wid)
Opens the local market window.
void commodity_sell(unsigned int wid, const char *str)
Attempts to sell a commodity.
void commodity_renderMod(double bx, double by, double w, double h, void *data)
Renders the commodity buying modifier.
void commodity_buy(unsigned int wid, const char *str)
Buys the selected commodity.
int commodity_canSell(const Commodity *com)
Checks to see if a player can sell a commodity.
void commodity_update(unsigned int wid, const char *str)
Updates the commodity window.
Header file with generic functions and naev-specifics.
int scnprintf(char *text, size_t maxlen, const char *fmt,...)
Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer....
glTexture * gl_dupTexture(const glTexture *texture)
Duplicates a texture.
credits_t player_modCredits(credits_t amount)
Modifies the amount of credits the player has.
int player_hasCredits(credits_t amount)
Checks to see if the player has enough credits.
int pfleet_cargoFree(void)
Gets the total amount of free cargo space in the player's fleet.
int pfleet_cargoOwned(const Commodity *com)
Gets the total amount of a commodity type owned by the player's fleet.
int pfleet_cargoAdd(const Commodity *com, int q)
Adds some cargo to the player's fleet.
int pfleet_cargoRm(const Commodity *com, int q, int jet)
Removes some cargo from the player's fleet.
int spob_averageSpobPrice(const Spob *p, const Commodity *c, credits_t *mean, double *std)
Gets the average price of a commodity at a spob that has been seen so far.
credits_t spob_commodityPrice(const Spob *p, const Commodity *c)
Gets the price of a commodity at a spob.
credits_t lastPurchasePrice
The actual hook parameter.
Stores a pilot commodity.
const Commodity * commodity
PilotCommodity * commodities