/** * @brief Attempts to sell a commodity. * @param wid Window selling commodity from. * @param str Unused. */ static void commodity_sell( unsigned int wid, char* str ) { (void)str; char *comname; Commodity *com; unsigned int q; credits_t price; HookParam hparam[3]; /* Get parameters. */ q = commodity_getMod(); comname = toolkit_getList( wid, "lstGoods" ); com = commodity_get( comname ); price = planet_commodityPrice( land_planet, com ); /* Remove commodity. */ q = pilot_cargoRm( player.p, com, q ); price = price * (credits_t)q; player_modCredits( price ); land_checkAddRefuel(); commodity_update(wid, NULL); /* Run hooks. */ hparam[0].type = HOOK_PARAM_STRING; hparam[0].u.str = comname; hparam[1].type = HOOK_PARAM_NUMBER; hparam[1].u.num = q; hparam[2].type = HOOK_PARAM_SENTINEL; hooks_runParam( "comm_sell", hparam ); if (land_takeoff) takeoff(1); }
/** * @brief Renders the commodity buying modifier. * @param bx Base X position to render at. * @param by Base Y position to render at. * @param w Width to render at. * @param h Height to render at. */ static void commodity_renderMod( double bx, double by, double w, double h, void *data ) { (void) data; (void) h; int q; char buf[8]; q = commodity_getMod(); snprintf( buf, 8, "%dx", q ); gl_printMid( &gl_smallFont, w, bx, by, &cBlack, buf ); }
/** * @brief Renders the commodity buying modifier. * @param bx Base X position to render at. * @param by Base Y position to render at. * @param w Width to render at. * @param h Height to render at. */ static void commodity_renderMod( double bx, double by, double w, double h, void *data ) { (void) data; (void) h; int q; char buf[8]; q = commodity_getMod(); if (q != commodity_mod) { commodity_update( land_getWid(LAND_WINDOW_COMMODITY), NULL ); commodity_mod = q; } nsnprintf( buf, 8, "%dx", q ); gl_printMid( &gl_smallFont, w, bx, by, &cBlack, buf ); }
/** * @brief Buys the selected commodity. * @param wid Window buying from. * @param str Unused. */ static void commodity_buy( unsigned int wid, char* str ) { (void)str; char *comname; Commodity *com; unsigned int q; credits_t price; HookParam hparam[3]; /* Get selected. */ q = commodity_getMod(); comname = toolkit_getList( wid, "lstGoods" ); com = commodity_get( comname ); price = planet_commodityPrice( land_planet, com ); price *= q; /* Check stuff. */ if (!player_hasCredits( price )) { dialogue_alert( "Insufficient credits!" ); return; } else if (pilot_cargoFree(player.p) <= 0) { dialogue_alert( "Insufficient free space!" ); return; } /* Make the buy. */ q = pilot_cargoAdd( player.p, com, q ); player_modCredits( -price ); land_checkAddRefuel(); commodity_update(wid, NULL); /* Run hooks. */ hparam[0].type = HOOK_PARAM_STRING; hparam[0].u.str = comname; hparam[1].type = HOOK_PARAM_NUMBER; hparam[1].u.num = q; hparam[2].type = HOOK_PARAM_SENTINEL; hooks_runParam( "comm_buy", hparam ); if (land_takeoff) takeoff(1); }
static int commodity_canBuy( char *name ) { int failure; unsigned int q, price; Commodity *com; char buf[ECON_CRED_STRLEN]; failure = 0; q = commodity_getMod(); com = commodity_get( name ); price = planet_commodityPrice( land_planet, com ) * q; if (!player_hasCredits( price )) { credits2str( buf, price - player.p->credits, 2 ); land_errDialogueBuild("You need %s more credits.", buf ); failure = 1; } if (pilot_cargoFree(player.p) <= 0) { land_errDialogueBuild("No cargo space available!"); failure = 1; } return !failure; }