Example #1
0
/**
 * @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;
}
Example #2
0
File: land.c Project: Dinth/naev
/**
 * @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;
}
Example #3
0
/**
 * @brief Updates the ships in the shipyard window.
 *    @param wid Window to update the ships in.
 *    @param str Unused.
 */
void shipyard_update( unsigned int wid, char* str )
{
   (void)str;
   char *shipname, *license_text;
   Ship* ship;
   char buf[PATH_MAX], buf2[ECON_CRED_STRLEN], buf3[ECON_CRED_STRLEN];
   size_t len;

   shipname = toolkit_getImageArray( wid, "iarShipyard" );

   /* No ships */
   if (strcmp(shipname,"None")==0) {
      window_modifyImage( wid, "imgTarget", NULL, 0, 0 );
      window_disableButton( wid, "btnBuyShip");
      window_disableButton( wid, "btnTradeShip");
      nsnprintf( buf, PATH_MAX,
            "None\n"
            "NA\n"
            "NA\n"
            "NA\n"
            "\n"
            "NA\n"
            "NA\n"
            "NA\n"
            "NA\n"
            "NA\n"
            "\n"
            "NA\n"
            "NA\n"
            "NA\n"
            "NA\n"
            "NA\n"
            "NA\n"
            "NA\n"
            "NA\n"
            "NA\n"
            "NA\n" );
      window_modifyImage( wid, "imgTarget", NULL, 0, 0 );
      window_modifyText( wid, "txtStats", NULL );
      window_modifyText( wid, "txtDescription", NULL );
      window_modifyText( wid, "txtDDesc", buf );
      return;
   }

   ship = ship_get( shipname );
   shipyard_selected = ship;

   /* update image */
   window_modifyImage( wid, "imgTarget", ship->gfx_store, 0, 0 );

   /* update text */
   window_modifyText( wid, "txtStats", ship->desc_stats );
   window_modifyText( wid, "txtDescription", ship->description );
   price2str( buf2, ship_buyPrice(ship), player.p->credits, 2 );
   credits2str( buf3, player.p->credits, 2 );

   /* Remove the word " License".  It's redundant and makes the text overflow
      into another text box */
   license_text = ship->license;
   if (license_text) {
      len = strlen(ship->license);
      if (strcmp(" License", ship->license + len - 8) == 0) {
         license_text = malloc(len - 7);
         assert(license_text);
         memcpy(license_text, ship->license, len - 8);
         license_text[len - 8] = '\0';
      }
   }
   nsnprintf( buf, PATH_MAX,
         "%s\n"
         "%s\n"
         "%s\n"
         "%d\n"
         "\n"
         "%.0f teraflops\n"
         "%.0f tons\n"
         "%.0f kN/ton\n"
         "%.0f m/s\n"
         "%.0f deg/s\n"
         "\n"
         "%.0f%% damage\n"
         "%.0f MJ (%.1f MW)\n"
         "%.0f MJ (%.1f MW)\n"
         "%.0f MJ (%.1f MW)\n"
         "%.0f tons\n"
         "%d units\n"
         "%.0f units\n"
         "%s credits\n"
         "%s credits\n"
         "%s\n",
         ship->name,
         ship_class(ship),
         ship->fabricator,
         ship->crew,
         /* Weapons & Manoeuvrability */
         ship->cpu,
         ship->mass,
         ship->thrust,
         ship->speed,
         ship->turn*180/M_PI,
         /* Misc */
         ship->dmg_absorb*100.,
         ship->shield, ship->shield_regen,
         ship->armour, ship->armour_regen,
         ship->energy, ship->energy_regen,
         ship->cap_cargo,
         ship->fuel,
         ship->fuel_consumption,
         buf2,
         buf3,
         (license_text != NULL) ? license_text : "None" );
   window_modifyText( wid,  "txtDDesc", buf );

   if (license_text != ship->license)
      free(license_text);

   if (!shipyard_canBuy( shipname, land_planet ))
      window_disableButtonSoft( wid, "btnBuyShip");
   else
      window_enableButton( wid, "btnBuyShip");

   if (!shipyard_canTrade( shipname ))
      window_disableButtonSoft( wid, "btnTradeShip");
   else
      window_enableButton( wid, "btnTradeShip");
}
Example #4
0
/**
 * @brief Updates the ships in the shipyard window.
 *    @param wid Window to update the ships in.
 *    @param str Unused.
 */
void shipyard_update( unsigned int wid, char* str )
{
    (void)str;
    char *shipname;
    Ship* ship;
    char buf[PATH_MAX], buf2[ECON_CRED_STRLEN], buf3[ECON_CRED_STRLEN];

    shipname = toolkit_getImageArray( wid, "iarShipyard" );

    /* No ships */
    if (strcmp(shipname,"None")==0) {
        window_modifyImage( wid, "imgTarget", NULL, 0, 0 );
        window_disableButton( wid, "btnBuyShip");
        window_disableButton( wid, "btnTradeShip");
        snprintf( buf, PATH_MAX,
                  "None\n"
                  "NA\n"
                  "NA\n"
                  "NA\n"
                  "\n"
                  "NA\n"
                  "NA\n"
                  "NA\n"
                  "NA\n"
                  "NA\n"
                  "NA\n"
                  "\n"
                  "NA\n"
                  "NA\n"
                  "NA\n"
                  "NA\n"
                  "NA\n"
                  "NA\n"
                  "NA\n"
                  "NA\n"
                  "NA\n" );
        window_modifyImage( wid, "imgTarget", NULL, 0, 0 );
        window_modifyText( wid, "txtStats", NULL );
        window_modifyText( wid, "txtDescription", NULL );
        window_modifyText( wid, "txtDDesc", buf );
        return;
    }

    ship = ship_get( shipname );
    shipyard_selected = ship;

    /* update image */
    window_modifyImage( wid, "imgTarget", ship->gfx_store, 0, 0 );

    /* update text */
    window_modifyText( wid, "txtStats", ship->desc_stats );
    window_modifyText( wid, "txtDescription", ship->description );
    credits2str( buf2, ship->price, 2 );
    credits2str( buf3, player.p->credits, 2 );
    snprintf( buf, PATH_MAX,
              "%s\n"
              "%s\n"
              "%s\n"
              "%d\n"
              "\n"
              "%.0f teraflops\n"
              "%.0f tons\n"
              "%.1f STU average\n"
              "%.0f kN/ton\n"
              "%.0f m/s\n"
              "%.0f deg/s\n"
              "\n"
              "%.0f%% damage\n"
              "%.0f MJ (%.1f MW)\n"
              "%.0f MJ (%.1f MW)\n"
              "%.0f MJ (%.1f MW)\n"
              "%.0f tons\n"
              "%d units\n"
              "%s credits\n"
              "%s credits\n"
              "%s\n",
              ship->name,
              ship_class(ship),
              ship->fabricator,
              ship->crew,
              /* Weapons & Manoeuvrability */
              ship->cpu,
              ship->mass,
              pow( ship->mass, 1./2.5 ) / 5. * (ship->stats_array.jump_delay/100.+1.), /**< @todo make this more portable. */
              ship->thrust / ship->mass,
              ship->speed,
              ship->turn*180/M_PI,
              /* Misc */
              ship->dmg_absorb*100.,
              ship->shield, ship->shield_regen,
              ship->armour, ship->armour_regen,
              ship->energy, ship->energy_regen,
              ship->cap_cargo,
              ship->fuel,
              buf2,
              buf3,
              (ship->license != NULL) ? ship->license : "None" );
    window_modifyText( wid,  "txtDDesc", buf );

    if (!shipyard_canBuy( shipname ))
        window_disableButton( wid, "btnBuyShip");
    else
        window_enableButton( wid, "btnBuyShip");

    if (!shipyard_canTrade( shipname ))
        window_disableButton( wid, "btnTradeShip");
    else
        window_enableButton( wid, "btnTradeShip");
}