Beispiel #1
0
/**
 * @brief Adds the "Buy Local Map" button if needed.
 */
void land_checkAddMap (void)
{
   char buf[ECON_CRED_STRLEN], cred[ECON_CRED_STRLEN];
   Outfit *o;

   /* Maps are only offered if the planet provides fuel. */
   if (!planet_hasService(land_planet, PLANET_SERVICE_REFUEL))
      return;

   o = outfit_get( LOCAL_MAP_NAME );
   if (o == NULL) {
      WARN("Outfit '%s' does not exist!", LOCAL_MAP_NAME);
      return;
   }

   /* Just enable button if it exists. */
   if (widget_exists( land_windows[0], "btnMap" ))
      window_enableButton( land_windows[0], "btnMap");
   /* Else create it. */
   else {
      /* Refuel button. */
      credits2str( cred, o->price, 2 );
      nsnprintf( buf, sizeof(buf), "Buy Local Map (%s)", cred );
      window_addButtonKey( land_windows[0], -20, 20 + (LAND_BUTTON_HEIGHT + 20),
            LAND_BUTTON_WIDTH,LAND_BUTTON_HEIGHT, "btnMap",
            buf, spaceport_buyMap, SDLK_b );
   }

   /* Make sure player can click it. */
   if (!outfit_canBuy(LOCAL_MAP_NAME, land_planet))
      window_disableButtonSoft( land_windows[0], "btnMap" );
}
Beispiel #2
0
/**
 * @brief Buys a local system map.
 */
static void spaceport_buyMap( unsigned int wid, char *str )
{
   (void) wid;
   (void) str;
   Outfit *o;
   unsigned int w;

   /* Make sure the map isn't already known, etc. */
   if (land_errDialogue( LOCAL_MAP_NAME, "buyOutfit" ))
      return;

   o = outfit_get( LOCAL_MAP_NAME );
   if (o == NULL) {
      WARN("Outfit '%s' does not exist!", LOCAL_MAP_NAME);
      return;
   }

   player_modCredits( -o->price );
   player_addOutfit(o, 1);

   /* Disable the button. */
   window_disableButtonSoft( land_windows[0], "btnMap" );

   /* Update map quantity in outfitter. */
   w = land_getWid( LAND_WINDOW_OUTFITS );
   if (w > 0)
      outfits_regenList( w, NULL );
}
Beispiel #3
0
/**
 * @brief Updates the commodity window.
 *    @param wid Window to update.
 *    @param str Unused.
 */
static void commodity_update( unsigned int wid, char* str )
{
   (void)str;
   char buf[PATH_MAX];
   char *comname;
   Commodity *com;

   comname = toolkit_getList( wid, "lstGoods" );
   if ((comname==NULL) || (strcmp( comname, "None" )==0)) {
      nsnprintf( buf, PATH_MAX,
         "NA Tons\n"
         "NA Credits/Ton\n"
         "\n"
         "NA Tons\n" );
      window_modifyText( wid, "txtDInfo", buf );
      window_modifyText( wid, "txtDesc", "No outfits available." );
      window_disableButton( wid, "btnCommodityBuy" );
      window_disableButton( wid, "btnCommoditySell" );
      return;
   }
   com = commodity_get( comname );

   /* modify text */
   nsnprintf( buf, PATH_MAX,
         "%d Tons\n"
         "%"CREDITS_PRI" Credits/Ton\n"
         "\n"
         "%d Tons\n",
         pilot_cargoOwned( player.p, comname ),
         planet_commodityPrice( land_planet, com ),
         pilot_cargoFree(player.p));
   window_modifyText( wid, "txtDInfo", buf );
   window_modifyText( wid, "txtDesc", com->description );

   /* Button enabling/disabling */
   if (commodity_canBuy( comname ))
      window_enableButton( wid, "btnCommodityBuy" );
   else
      window_disableButtonSoft( wid, "btnCommodityBuy" );

   if (commodity_canSell( comname ))
      window_enableButton( wid, "btnCommoditySell" );
   else
      window_disableButtonSoft( wid, "btnCommoditySell" );
}
Beispiel #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, *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");
}
Beispiel #5
0
/**
 * @brief Updates the outfits in the outfit window.
 *    @param wid Window to update the outfits in.
 *    @param str Unused.
 */
void outfits_update( unsigned int wid, char* str )
{
   (void)str;
   char *outfitname;
   Outfit* outfit;
   char buf[PATH_MAX], buf2[ECON_CRED_STRLEN], buf3[ECON_CRED_STRLEN];
   double th;
   int iw, ih;
   int w, h;
   credits_t price;
   char colour;

   /* Get dimensions. */
   outfits_getSize( wid, &w, &h, &iw, &ih, NULL, NULL );

   /* Get and set parameters. */
   outfitname = toolkit_getImageArray( wid, "iarOutfits" );
   if (strcmp(outfitname,"None")==0) { /* No outfits */
      window_modifyImage( wid, "imgOutfit", NULL, 0, 0 );
      window_disableButton( wid, "btnBuyOutfit" );
      window_disableButton( wid, "btnSellOutfit" );
      nsnprintf( buf, PATH_MAX,
            "NA\n"
            "\n"
            "NA\n"
            "NA\n"
            "NA\n"
            "\n"
            "NA\n"
            "NA\n"
            "NA\n" );
      window_modifyText( wid, "txtDDesc", buf );
      window_modifyText( wid, "txtOutfitName", "None" );
      window_modifyText( wid, "txtDescShort", NULL );
      /* Reposition. */
      window_moveWidget( wid, "txtSDesc", 20+iw+20, -60 );
      window_moveWidget( wid, "txtDDesc", 20+iw+20+60, -60 );
      window_moveWidget( wid, "txtDescription", 20+iw+40, -240 );
      return;
   }

   outfit = outfit_get( outfitname );

   /* new image */
   window_modifyImage( wid, "imgOutfit", outfit->gfx_store, 0, 0 );

   if (outfit_canBuy(outfitname) > 0)
      window_enableButton( wid, "btnBuyOutfit" );
   else
      window_disableButtonSoft( wid, "btnBuyOutfit" );

   /* gray out sell button */
   if (outfit_canSell(outfitname) > 0)
      window_enableButton( wid, "btnSellOutfit" );
   else
      window_disableButtonSoft( wid, "btnSellOutfit" );

   /* Multiply and colourize outfit price as needed */
   price = outfit_getPrice(outfit);
   colour = (price > player.p->credits) ? 'r' : '0';

   /* new text */
   window_modifyText( wid, "txtDescription", outfit->description );
   credits2str( buf2, price, 2 );
   credits2str( buf3, player.p->credits, 2 );
   nsnprintf( buf, PATH_MAX,
         "%d\n"
         "\n"
         "%s\n"
         "%s\n"
         "%.0f tons\n"
         "\n"
         "\e%c%s\e0 credits\n"
         "%s credits\n"
         "%s\n",
         player_outfitOwned(outfit),
         outfit_slotName(outfit),
         outfit_slotSize(outfit),
         outfit->mass,
         colour, buf2,
         buf3,
         (outfit->license != NULL) ? outfit->license : "None" );
   window_modifyText( wid, "txtDDesc", buf );
   window_modifyText( wid, "txtOutfitName", outfit->name );
   window_modifyText( wid, "txtDescShort", outfit->desc_short );
   th = MAX( 128, gl_printHeightRaw( &gl_smallFont, 280, outfit->desc_short ) );
   window_moveWidget( wid, "txtSDesc", 40+iw+20, -60-th-20 );
   window_moveWidget( wid, "txtDDesc", 40+iw+20+60, -60-th-20 );
   th += gl_printHeightRaw( &gl_smallFont, 250, buf );
   window_moveWidget( wid, "txtDescription", 20+iw+40, -60-th-20 );
}
Beispiel #6
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_disableButtonSoft( wid, "btnBuyShip");
    else
        window_enableButton( wid, "btnBuyShip");

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