/** * @brief Makes sure it's sane to buy a ship, trading the old one in simultaneously. * @param shipname Ship being bought. */ int shipyard_canTrade( char* shipname ) { int failure = 0; Ship* ship; ship = ship_get( shipname ); credits_t price; price = ship_buyPrice( ship ); /* Must have the necessary license, enough credits, and be able to swap ships. */ if (!player_hasLicense(ship->license)) { land_errDialogueBuild( "You lack the %s.", ship->license ); failure = 1; } if (!player_hasCredits( price - player_shipPrice(player.p->name))) { credits_t creditdifference = price - (player_shipPrice(player.p->name) + player.p->credits); char buf[ECON_CRED_STRLEN]; credits2str( buf, creditdifference, 2 ); land_errDialogueBuild( "You need %s more credits.", buf); failure = 1; } if (!can_swap( shipname )) failure = 1; return !failure; }
/** * @brief Generates error dialogues used by several landing tabs. * @param name Name of the ship, outfit or commodity being acted upon. * @param type Type of action. */ int land_errDialogue( char* name, char* type ) { errorlist_ptr = NULL; if (strcmp(type,"tradeShip")==0) shipyard_canTrade( name ); else if (strcmp(type,"buyShip")==0) shipyard_canBuy( name, land_planet ); else if (strcmp(type,"swapEquipment")==0) can_swapEquipment( name ); else if (strcmp(type,"swap")==0) can_swap( name ); else if (strcmp(type,"sellShip")==0) can_sell( name ); else if (strcmp(type,"buyOutfit")==0) outfit_canBuy( name, land_planet ); else if (strcmp(type,"sellOutfit")==0) outfit_canSell( name ); else if (strcmp(type,"buyCommodity")==0) commodity_canBuy( name ); else if (strcmp(type,"sellCommodity")==0) commodity_canSell( name ); if (errorlist_ptr != NULL) { dialogue_alert( "%s", errorlist ); return 1; } return 0; }
/** * @brief Generates error dialogues used by several landing tabs. * @param shipname Ship being acted upon. * @param type Type of action. */ int land_errDialogue( char* shipname, char* type ) { errorlist_ptr = NULL; if (strcmp(type,"trade")==0) shipyard_canTrade( shipname ); else if (strcmp(type,"buy")==0) shipyard_canBuy( shipname ); else if (strcmp(type,"swapEquipment")==0) can_swapEquipment( shipname ); else if (strcmp(type,"swap")==0) can_swap( shipname ); else if (strcmp(type,"sell")==0) can_sell( shipname ); if (errorlist_ptr != NULL) { dialogue_alert( "%s", errorlist ); return 1; } return 0; }