Exemplo n.º 1
0
/**
 * @brief Updates the quantity counter for the outfits.
 *
 *    @param wid Window to update counters of.
 */
void outfits_updateQuantities( unsigned int wid )
{
   Outfit **outfits, *o;
   int noutfits;
   char **quantity;
   int len, owned;
   int i;

   /* Get outfits. */
   outfits = tech_getOutfit( land_planet->tech, &noutfits );
   if (noutfits <= 0)
      return;

   quantity = malloc(sizeof(char*)*noutfits);
   for (i=0; i<noutfits; i++) {
      o = outfits[i];
      owned = player_outfitOwned(o);
      len = owned / 10 + 4;
      if (owned >= 1) {
         quantity[i] = malloc( len );
         snprintf( quantity[i], len, "%d", owned );
      }
      else
         quantity[i] = NULL;
   }
   free(outfits);
   toolkit_setImageArrayQuantity( wid, "iarOutfits", quantity );
}
Exemplo n.º 2
0
/**
 * @brief Removes an outfit from the player's outfit list.
 *
 * "all" will remove all outfits.
 *
 * @usage player.rmOutfit( "Plasma Blaster", 2 ) -- Removes two plasma blasters from the player
 *
 *    @luaparam name Name of the outfit to give.
 *    @luaparam q Optional parameter that sets the quantity to give (default 1).
 * @luafunc rmOutfit( name, q )
 */
static int playerL_rmOutfit( lua_State *L )
{
   const char *str;
   char **outfits;
   Outfit *o;
   int i, q, noutfits;

   /* Defaults. */
   q = 1;

   /* Handle parameters. */
   str = luaL_checkstring(L, 1);
   if (lua_gettop(L) > 1)
      q = luaL_checkint(L, 2);

   if (strcmp(str,"all")==0) {
      noutfits = player_numOutfits();
      /* Removing nothing is a bad idea. */
      if (noutfits == 0)
         return 0;

      outfits = malloc( sizeof(char*) * noutfits );
      player_getOutfits(outfits, NULL);
      for (i=0; i<noutfits; i++) {
         o = outfit_get(outfits[i]);
         q = player_outfitOwned(o);
         player_rmOutfit(o, q);
         /* Free memory. */
         free( outfits[i] );
      }
      /* Clean up. */
      free(outfits);
   }
   else {
      /* Get outfit. */
      o = outfit_get( str );
      if (o==NULL) {
         NLUA_ERROR(L, "Outfit '%s' not found.", str);
         return 0;
      }

      /* Remove the outfits. */
      player_rmOutfit( o, q );
   }

   /* Update equipment list. */
   outfits_updateEquipmentOutfits();

   return 0;
}
Exemplo n.º 3
0
/**
 * @brief Gets the number of outfits the player owns in their list (excludes equipped on ships).
 *
 * @usage q = player.numOutfit( "Laser Cannon" ) -- Number of 'Laser Cannons' the player owns (unequipped)
 *
 *    @luaparam name Name of the outfit to give.
 *    @luareturn The quantity the player owns.
 * @luafunc numOutfit( name )
 */
static int playerL_numOutfit( lua_State *L )
{
   const char *str;
   Outfit *o;
   int q;

   /* Handle parameters. */
   str = luaL_checkstring(L, 1);

   /* Get outfit. */
   o = outfit_get( str );
   if (o==NULL) {
      NLUA_ERROR(L, "Outfit '%s' not found.", str);
      return 0;
   }

   /* Count the outfit. */
   q = player_outfitOwned( o );
   lua_pushnumber( L, q );

   return 1;
}
Exemplo n.º 4
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 );
}