Ejemplo n.º 1
0
Archivo: land.c Proyecto: Dinth/naev
/**
 * @brief Checks if should add the refuel button and does if needed.
 */
void land_checkAddRefuel (void)
{
   char buf[ECON_CRED_STRLEN], cred[ECON_CRED_STRLEN];
   unsigned int w;

   /* Check to see if fuel conditions are met. */
   if (!planet_hasService(land_planet, PLANET_SERVICE_REFUEL)) {
      if (!widget_exists( land_windows[0], "txtRefuel" ))
         window_addText( land_windows[0], -20, 20 + (LAND_BUTTON_HEIGHT + 20) + 20,
                  200, gl_defFont.h, 1, "txtRefuel",
                  &gl_defFont, &cBlack, "No refueling services." );
      return;
   }

   /* Full fuel. */
   if (player.p->fuel >= player.p->fuel_max) {
      if (widget_exists( land_windows[0], "btnRefuel" ))
         window_destroyWidget( land_windows[0], "btnRefuel" );
      if (widget_exists( land_windows[0], "txtRefuel" ))
         window_destroyWidget( land_windows[0], "txtRefuel" );
      return;
   }

   /* Autorefuel. */
   if (conf.autorefuel) {
      spaceport_refuel( land_windows[0], "btnRefuel" );
      w = land_getWid( LAND_WINDOW_EQUIPMENT );
      if (w > 0)
         equipment_updateShips( w, NULL ); /* Must update counter. */
      if (player.p->fuel >= player.p->fuel_max)
         return;
   }

   /* Just enable button if it exists. */
   if (widget_exists( land_windows[0], "btnRefuel" )) {
      window_enableButton( land_windows[0], "btnRefuel");
      credits2str( cred, player.p->credits, 2 );
      snprintf( buf, sizeof(buf), "Credits: %s", cred );
      window_modifyText( land_windows[0], "txtRefuel", buf );
   }
   /* Else create it. */
   else {
      /* Refuel button. */
      credits2str( cred, refuel_price(), 2 );
      snprintf( buf, sizeof(buf), "Refuel %s", cred );
      window_addButton( land_windows[0], -20, 20 + (LAND_BUTTON_HEIGHT + 20),
            LAND_BUTTON_WIDTH,LAND_BUTTON_HEIGHT, "btnRefuel",
            buf, spaceport_refuel );
      /* Player credits. */
      credits2str( cred, player.p->credits, 2 );
      snprintf( buf, sizeof(buf), "Credits: %s", cred );
      window_addText( land_windows[0], -20, 20 + 2*(LAND_BUTTON_HEIGHT + 20),
            LAND_BUTTON_WIDTH, gl_smallFont.h, 1, "txtRefuel",
            &gl_smallFont, &cBlack, buf );
   }

   /* Make sure player can click it. */
   if (!player_hasCredits( refuel_price() ))
      window_disableButton( land_windows[0], "btnRefuel" );
}
Ejemplo n.º 2
0
Archivo: land.c Proyecto: Kinniken/naev
/**
 * @brief Refuels the player's current ship, if possible.
 */
void land_refuel (void)
{
   unsigned int w;

   /* Full fuel. */
   if (player.p->fuel >= player.p->fuel_max)
      return;

   /* No refuel service. */
   if (!planet_hasService(land_planet, PLANET_SERVICE_REFUEL))
      return;

   player.p->fuel = player.p->fuel_max;

   w = land_getWid( LAND_WINDOW_EQUIPMENT );
   if (w > 0)
      equipment_updateShips( w, NULL ); /* Must update counter. */
}
Ejemplo n.º 3
0
Archivo: land.c Proyecto: Dinth/naev
/**
 * @brief Saves the last place the player was.
 *
 *    @param wid Unused.
 *    @param wgt Unused.
 *    @param tab Tab changed to.
 */
static void land_changeTab( unsigned int wid, char *wgt, int tab )
{
   int i;
   (void) wid;
   (void) wgt;
   unsigned int w;
   const char *torun_hook;
   unsigned int to_visit;

   /* Sane defaults. */
   torun_hook = NULL;
   to_visit   = 0;

   /* Find what switched. */
   for (i=0; i<LAND_NUMWINDOWS; i++) {
      if (land_windowsMap[i] == tab) {
         last_window = i;
         w = land_getWid( i );

         /* Must regenerate outfits. */
         switch (i) {
            case LAND_WINDOW_MAIN:
               land_checkAddRefuel();
               break;
            case LAND_WINDOW_OUTFITS:
               outfits_update( w, NULL );
               outfits_updateQuantities( w );
               to_visit   = VISITED_OUTFITS;
               torun_hook = "outfits";
               break;
            case LAND_WINDOW_SHIPYARD:
               shipyard_update( w, NULL );
               to_visit   = VISITED_SHIPYARD;
               torun_hook = "shipyard";
               break;
            case LAND_WINDOW_BAR:
               bar_update( w, NULL );
               to_visit   = VISITED_BAR;
               torun_hook = "bar";
               break;
            case LAND_WINDOW_MISSION:
               misn_update( w, NULL );
               to_visit   = VISITED_MISSION;
               torun_hook = "mission";
               break;
            case LAND_WINDOW_COMMODITY:
               commodity_update( w, NULL );
               to_visit   = VISITED_COMMODITY;
               torun_hook = "commodity";
               break;
            case LAND_WINDOW_EQUIPMENT:
               equipment_updateShips( w, NULL );
               equipment_updateOutfits( w, NULL );
               to_visit   = VISITED_EQUIPMENT;
               torun_hook = "equipment";
               break;

            default:
               break;
         }

         /* Clear markers if closing Mission Computer. */
         if (i != LAND_WINDOW_MISSION) {
            space_clearComputerMarkers();
         }

         break;
      }
   }

   /* Check land missions - always run hooks. */
   /*if ((to_visit != 0) && !has_visited(to_visit)) {*/
   {
      /* Run hooks, run after music in case hook wants to change music. */
      if (torun_hook != NULL)
         if (hooks_run( torun_hook ) > 0)
            bar_genList( land_getWid(LAND_WINDOW_BAR) );

      visited(to_visit);

      if (land_takeoff)
         takeoff(1);
   }
}