/** * @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); }
/** * @brief Adds special mission cargo, can't sell it and such. * * @param pilot Pilot to add it to. * @param cargo Commodity to add. * @param quantity Quantity to add. * @return The Mission Cargo ID of created cargo. */ unsigned int pilot_addMissionCargo( Pilot* pilot, Commodity* cargo, int quantity ) { int i; unsigned int id, max_id; /* Get ID. */ id = ++mission_cargo_id; /* Check for collisions with pilot and set ID generator to the max. */ max_id = 0; for (i=0; i<pilot->ncommodities; i++) if (pilot->commodities[i].id > max_id) max_id = pilot->commodities[i].id; if (max_id >= id) { mission_cargo_id = max_id; id = ++mission_cargo_id; } /* Add the cargo. */ pilot_cargoAdd( pilot, cargo, quantity, id ); return id; }