/** * @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 Makes the player jettison the currently selected cargo. * @param str Unused. */ static void cargo_jettison( unsigned int wid, char* str ) { (void)str; int i, j, f, pos, ret; Mission *misn; if (player.p->ncommodities==0) return; /* No cargo, redundant check */ pos = toolkit_getListPos( wid, "lstCargo" ); /* Special case mission cargo. */ if (player.p->commodities[pos].id != 0) { if (!dialogue_YesNo( "Abort Mission", "Are you sure you want to abort this mission?" )) return; /* Get the mission. */ f = 0; for (i=0; i<MISSION_MAX; i++) { for (j=0; j<player_missions[i].ncargo; j++) { if (player_missions[i].cargo[j] == player.p->commodities[pos].id) { f = 1; break; } } if (f==1) break; } if (!f) { WARN("Cargo '%d' does not belong to any active mission.", player.p->commodities[pos].id); return; } misn = &player_missions[i]; /* We run the "abort" function if it's found. */ ret = misn_tryRun( misn, "abort" ); /* Now clean up mission. */ if (ret != 2) { mission_cleanup( misn ); memmove( misn, &player_missions[i+1], sizeof(Mission) * (MISSION_MAX-i-1) ); memset( &player_missions[MISSION_MAX-1], 0, sizeof(Mission) ); } /* Reset markers. */ mission_sysMark(); /* Reset claims. */ claim_activateAll(); /* Regenerate list. */ mission_menu_genList( info_windows[ INFO_WIN_MISN ] ,0); } else { /* Remove the cargo */ commodity_Jettison( player.p->id, player.p->commodities[pos].commodity, player.p->commodities[pos].quantity ); pilot_cargoRm( player.p, player.p->commodities[pos].commodity, player.p->commodities[pos].quantity ); } /* We reopen the menu to recreate the list now. */ ship_update( info_windows[ INFO_WIN_SHIP ] ); cargo_genList( wid ); }