예제 #1
0
/**
 * @brief Player attempts to buy a ship.
 *    @param wid Window player is buying ship from.
 *    @param str Unused.
 */
static void shipyard_buy( unsigned int wid, char* str )
{
   (void)str;
   char *shipname, buf[ECON_CRED_STRLEN];
   Ship* ship;

   shipname = toolkit_getImageArray( wid, "iarShipyard" );
   if (strcmp(shipname, "None") == 0)
      return;

   ship = ship_get( shipname );

   credits_t targetprice = ship_buyPrice(ship);

   if (land_errDialogue( shipname, "buyShip" ))
      return;

   credits2str( buf, targetprice, 2 );
   if (dialogue_YesNo("Are you sure?", /* confirm */
         "Do you really want to spend %s on a new ship?", buf )==0)
      return;

   /* player just got a new ship */
   if (player_newShip( ship, NULL, 0, 0 ) == NULL) {
      /* Player actually aborted naming process. */
      return;
   }
   player_modCredits( -targetprice ); /* ouch, paying is hard */

   /* Update shipyard. */
   shipyard_update(wid, NULL);
}
예제 #2
0
/**
 * @brief Player attempts to buy a ship, trading the current ship in.
 *    @param wid Window player is buying ship from.
 *    @param str Unused.
 */
static void shipyard_trade( unsigned int wid, char* str )
{
   (void)str;
   char *shipname, buf[ECON_CRED_STRLEN], buf2[ECON_CRED_STRLEN],
         buf3[ECON_CRED_STRLEN], buf4[ECON_CRED_STRLEN];
   Ship* ship;

   shipname = toolkit_getImageArray( wid, "iarShipyard" );
   if (strcmp(shipname, "None") == 0)
      return;

   ship = ship_get( shipname );

   credits_t targetprice = ship_buyPrice(ship);
   credits_t playerprice = player_shipPrice(player.p->name);

   if (land_errDialogue( shipname, "tradeShip" ))
      return;

   credits2str( buf, targetprice, 2 );
   credits2str( buf2, playerprice, 2 );
   credits2str( buf3, targetprice - playerprice, 2 );
   credits2str( buf4, playerprice - targetprice, 2 );

   /* Display the correct dialogue depending on the new ship's price versus the player's. */
   if ( targetprice == playerprice ) {
      if (dialogue_YesNo("Are you sure?", /* confirm */
         "Your %s is worth %s, exactly as much as the new ship, so no credits need be exchanged. Are you sure you want to trade your ship in?",
               player.p->ship->name, buf2)==0)
         return;
   }
   else if ( targetprice < playerprice ) {
      if (dialogue_YesNo("Are you sure?", /* confirm */
         "Your %s is worth %s credits, more than the new ship. For your ship, you will get the new %s and %s credits. Are you sure you want to trade your ship in?",
               player.p->ship->name, buf2, ship->name, buf4)==0)
         return;
   }
   else if ( targetprice > playerprice ) {
      if (dialogue_YesNo("Are you sure?", /* confirm */
         "Your %s is worth %s, so the new ship will cost %s credits. Are you sure you want to trade your ship in?",
               player.p->ship->name, buf2, buf3)==0)
         return;
   }

   /* player just got a new ship */
   if (player_newShip( ship, NULL, 1, 0 ) == NULL)
      return; /* Player aborted the naming process. */

   player_modCredits( playerprice - targetprice ); /* Modify credits by the difference between ship values. */

   land_refuel();

   /* The newShip call will trigger a loadGUI that will recreate the land windows. Therefore the land ID will
    * be void. We must reload in in order to properly update it again.*/
   wid = land_getWid(LAND_WINDOW_SHIPYARD);

   /* Update shipyard. */
   shipyard_update(wid, NULL);
}
예제 #3
0
/**
 * @brief Player attempts to buy a ship, trading the current ship in.
 *    @param wid Window player is buying ship from.
 *    @param str Unused.
 */
static void shipyard_trade( unsigned int wid, char* str )
{
    (void)str;
    char *shipname, buf[ECON_CRED_STRLEN], buf2[ECON_CRED_STRLEN],
         buf3[ECON_CRED_STRLEN], buf4[ECON_CRED_STRLEN];
    Ship* ship;

    shipname = toolkit_getImageArray( wid, "iarShipyard" );
    ship = ship_get( shipname );

    credits_t targetprice = ship->price;
    credits_t playerprice = player_shipPrice(player.p->name);

    if (land_errDialogue( shipname, "trade" ))
        return;

    credits2str( buf, targetprice, 2 );
    credits2str( buf2, playerprice, 2 );
    credits2str( buf3, targetprice - playerprice, 2 );
    credits2str( buf4, playerprice - targetprice, 2 );

    /* Display the correct dialogue depending on the new ship's price versus the player's. */
    if ( targetprice == playerprice ) {
        if (dialogue_YesNo("Are you sure?", /* confirm */
                           "Your %s is worth %s, exactly as much as the new ship, so no credits need be exchanged. Are you sure you want to trade your ship in?",
                           player.p->ship->name, buf2)==0)
            return;
    }
    else if ( targetprice < playerprice ) {
        if (dialogue_YesNo("Are you sure?", /* confirm */
                           "Your %s is worth %s credits, more than the new ship. For your ship, you will get the new %s and %s credits. Are you sure you want to trade your ship in?",
                           player.p->ship->name, buf2, ship->name, buf4)==0)
            return;
    }
    else if ( targetprice > playerprice ) {
        if (dialogue_YesNo("Are you sure?", /* confirm */
                           "Your %s is worth %s, so the new ship will cost %s credits. Are you sure you want to trade your ship in?",
                           player.p->ship->name, buf2, buf3)==0)
            return;
    }

    /* player just got a new ship */
    if (player_newShip( ship, NULL, 1, 0 ) == NULL)
        return; /* Player aborted the naming process. */

    player_modCredits( playerprice - targetprice ); /* Modify credits by the difference between ship values. */

    land_checkAddRefuel();

    /* Update shipyard. */
    shipyard_update(wid, NULL);
}
예제 #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");
}
예제 #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;

   /* 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" );
      snprintf( 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(outfit,1,0) > 0)
      window_enableButton( wid, "btnBuyOutfit" );
   else
      window_disableButton( wid, "btnBuyOutfit" );

   /* gray out sell button */
   if (outfit_canSell(outfit,1,0) > 0)
      window_enableButton( wid, "btnSellOutfit" );
   else
      window_disableButton( wid, "btnSellOutfit" );

   /* new text */
   window_modifyText( wid, "txtDescription", outfit->description );
   credits2str( buf2, outfit->price, 2 );
   credits2str( buf3, player.p->credits, 2 );
   snprintf( buf, PATH_MAX,
         "%d\n"
         "\n"
         "%s\n"
         "%s\n"
         "%.0f tons\n"
         "\n"
         "%s credits\n"
         "%s credits\n"
         "%s\n",
         player_outfitOwned(outfit),
         outfit_slotName(outfit),
         outfit_slotSize(outfit),
         outfit->mass,
         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, 320, 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 );
}
예제 #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_disableButton( wid, "btnBuyShip");
    else
        window_enableButton( wid, "btnBuyShip");

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