示例#1
0
文件: land.c 项目: Dinth/naev
/**
 * @brief Updates the missions in the spaceport bar.
 *    @param wid Window to update the outfits in.
 *    @param str Unused.
 */
static void bar_update( unsigned int wid, char* str )
{
   (void) str;
   int pos;
   int w, h, iw, ih, bw, bh, dh;

   /* Get dimensions. */
   bar_getDim( wid, &w, &h, &iw, &ih, &bw, &bh );
   dh = gl_printHeightRaw( &gl_smallFont, w - iw - 60, land_planet->bar_description );

   /* Get array. */
   pos = toolkit_getImageArrayPos( wid, "iarMissions" );

   /* See if is news. */
   if (pos==0) { /* News selected. */
      if (!widget_exists(wid, "cstNews")) {
         /* Destroy portrait. */
         if (widget_exists(wid, "imgPortrait")) {
            window_destroyWidget(wid, "imgPortrait");
         }

         /* Disable button. */
         window_disableButton( wid, "btnApproach" );

         /* Clear text. */
         window_modifyText(  wid, "txtPortrait", NULL );
         window_modifyText(  wid, "txtMission",  NULL );

         /* Create news. */
         news_widget( wid, iw + 60, -40 - (40 + dh),
               w - iw - 100, h - 40 - (dh+20) - 40 - bh - 20 );
      }
      return;
   }

   /* Shift to ignore news now. */
   pos--;

   /* Destroy news widget if needed. */
   if (widget_exists(wid, "cstNews")) {
      window_destroyWidget( wid, "cstNews" );
   }

   /* Create widgets if needed. */
   if (!widget_exists(wid, "imgPortrait")) {
      window_addImage( wid, iw + 40 + (w-iw-60-PORTRAIT_WIDTH)/2,
            -(40 + dh + 40 + gl_defFont.h + 20 + PORTRAIT_HEIGHT),
            0, 0, "imgPortrait", NULL, 1 );
   }

   /* Enable button. */
   window_enableButton( wid, "btnApproach" );

   /* Set portrait. */
   window_modifyText(  wid, "txtPortrait", npc_getName( pos ) );
   window_modifyImage( wid, "imgPortrait", npc_getTexture( pos ), 0, 0 );

   /* Set mission description. */
   window_modifyText(  wid, "txtMission", npc_getDesc( pos ));
}
示例#2
0
文件: info.c 项目: AvanWolf/naev
/**
 * @brief Updates the standings menu.
 */
static void standings_update( unsigned int wid, char* str )
{
   (void) str;
   int p, y;
   glTexture *t;
   int w, h, lw;
   char buf[128];
   int m;

   /* Get dimensions. */
   info_getDim( wid, &w, &h, &lw );

   /* Get faction. */
   p = toolkit_getListPos( wid, "lstStandings" );
   y = 0;

   /* Render logo. */
   t = faction_logoSmall( info_factions[p] );
   if (t != NULL) {
      window_modifyImage( wid, "imgLogo", t, 0, 0 );
      y  = -40;
      window_moveWidget( wid, "imgLogo", lw+40 + (w-(lw+60)-t->w)/2, y );
      y -= t->h;
   }
   else {
      window_modifyImage( wid, "imgLogo", NULL, 0, 0 );
      y = -20;
   }

   /* Modify text. */
   y -= 20;
   window_modifyText( wid, "txtName", faction_longname( info_factions[p] ) );
   window_moveWidget( wid, "txtName", lw+40, y );
   y -= 40;
   m = round( faction_getPlayer( info_factions[p] ) );
   snprintf( buf, sizeof(buf), "%+d%%   [ %s ]", m, faction_getStanding( m ) );
   window_modifyText( wid, "txtStanding", buf );
   window_moveWidget( wid, "txtStanding", lw+40, y );
}
示例#3
0
文件: menu.c 项目: pegue/naev
/**
 * @brief Function to clean up the background window.
 *    @param wid Window to clean.
 *    @param str Unused.
 */
static void menu_main_cleanBG( unsigned int wid, char* str )
{
   (void) str;

   /* 
    * Ugly hack to prevent player.c from segfaulting due to the fact
    * that game will attempt to render while waiting for the quit event
    * pushed by exit_game() to be handled without actually having a player
    * nor anything of the likes (nor toolkit to stop rendering) while
    * not leaking any texture.
    */
   gl_freeTexture( window_getImage(wid, "imgLogo") );
   window_modifyImage( wid, "imgLogo", 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
文件: map.c 项目: Elderman/naev
/**
 * @brief Updates the map window.
 *
 *    @param wid Window id.
 */
static void map_update( unsigned int wid )
{
   int i;
   StarSystem* sys;
   int f, h, x, y;
   double standing, nstanding;
   unsigned int services;
   int l;
   int hasPresence, hasPlanets;
   char t;
   char buf[PATH_MAX];
   int p;
   glTexture *logo;
   double w;
   double unknownPresence;

   /* Needs map to update. */
   if (!map_isOpen())
      return;

   /* Get selected system. */
   sys = system_getIndex( map_selected );

   /* Not known and no markers. */
   if (!(sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)) &&
         !sys_isKnown(sys) && !space_sysReachable(sys)) {
      map_selectCur();
      sys = system_getIndex( map_selected );
   }

   /*
    * Right Text
    */

   x = -70; /* Side bar X offset. */
   w = ABS(x) + 60; /* Width of the side bar. */
   y = -20 - 20 - 64 - gl_defFont.h; /* Initialized to position for txtSFaction. */

   if (!sys_isKnown(sys)) { /* System isn't known, erase all */
      /*
       * Right Text
       */
      if (sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED))
         window_modifyText( wid, "txtSysname", sys->name );
      else
         window_modifyText( wid, "txtSysname", "Unknown" );;

      /* Faction */
      window_modifyImage( wid, "imgFaction", NULL, 0, 0 );
      window_moveWidget( wid, "txtSFaction", x, y);
      window_moveWidget( wid, "txtFaction", x + 50, y - gl_smallFont.h - 5 );
      window_modifyText( wid, "txtFaction", "Unknown" );
      y -= 2 * gl_smallFont.h + 5 + 15;

      /* Standing */
      window_moveWidget( wid, "txtSStanding", x, y );
      window_moveWidget( wid, "txtStanding", x + 50, y - gl_smallFont.h - 5 );
      window_modifyText( wid, "txtStanding", "Unknown" );
      y -= 2 * gl_smallFont.h + 5 + 15;

      /* Presence. */
      window_moveWidget( wid, "txtSPresence", x, y );
      window_moveWidget( wid, "txtPresence",  x + 50, y - gl_smallFont.h - 5 );
      window_modifyText( wid, "txtPresence", "Unknown" );
      y -= 2 * gl_smallFont.h + 5 + 15;

      /* Planets */
      window_moveWidget( wid, "txtSPlanets", x, y );
      window_moveWidget( wid, "txtPlanets", x + 50, y - gl_smallFont.h - 5 );
      window_modifyText( wid, "txtPlanets", "Unknown" );
      y -= 2 * gl_smallFont.h + 5 + 15;

      /* Services */
      window_moveWidget( wid, "txtSServices", x, y );
      window_moveWidget( wid, "txtServices", x + 50, y -gl_smallFont.h - 5 );
      window_modifyText( wid, "txtServices", "Unknown" );

      /*
       * Bottom Text
       */
      window_modifyText( wid, "txtSystemStatus", NULL );
      return;
   }

   /* System is known */
   window_modifyText( wid, "txtSysname", sys->name );

   standing  = 0.;
   nstanding = 0.;
   f         = -1;
   for (i=0; i<sys->nplanets; i++) {
      if (sys->planets[i]->real != ASSET_REAL)
         continue;
      if (!planet_isKnown(sys->planets[i]))
         continue;

      if ((f==-1) && (sys->planets[i]->faction>0)) {
         f = sys->planets[i]->faction;
         standing += faction_getPlayer( f );
         nstanding++;
      }
      else if (f != sys->planets[i]->faction && /** @todo more verbosity */
               (sys->planets[i]->faction>0)) {
         nsnprintf( buf, PATH_MAX, "Multiple" );
         break;
      }
   }
   if (f == -1) {
      window_modifyImage( wid, "imgFaction", NULL, 0, 0 );
      window_modifyText( wid, "txtFaction", "N/A" );
      window_modifyText( wid, "txtStanding", "N/A" );
      h = gl_smallFont.h;
   }
   else {
      if (i==sys->nplanets) /* saw them all and all the same */
         nsnprintf( buf, PATH_MAX, "%s", faction_longname(f) );

      /* Modify the image. */
      logo = faction_logoSmall(f);
      window_modifyImage( wid, "imgFaction", logo, 0, 0 );
      if (logo != NULL)
         window_moveWidget( wid, "imgFaction",
               -90 + logo->w/2, -20 - 32 - 10 - gl_defFont.h + logo->h/2);

      /* Modify the text */
      window_modifyText( wid, "txtFaction", buf );
      window_modifyText( wid, "txtStanding",
            faction_getStanding( standing / nstanding ) );

      h = gl_printHeightRaw( &gl_smallFont, w, buf );
   }

   /* Faction */
   window_moveWidget( wid, "txtSFaction", x, y);
   window_moveWidget( wid, "txtFaction", x + 50, y - gl_smallFont.h - 5 );
   y -= gl_smallFont.h + h + 5 + 15;

   /* Standing */
   window_moveWidget( wid, "txtSStanding", x, y );
   window_moveWidget( wid, "txtStanding", x + 50, y - gl_smallFont.h - 5 );
   y -= 2 * gl_smallFont.h + 5 + 15;

   /* Get presence. */
   hasPresence = 0;
   buf[0]      = '\0';
   l           = 0;
   unknownPresence = 0;
   for (i=0; i < sys->npresence; i++) {
      if (sys->presence[i].value <= 0)
         continue;
      hasPresence = 1;
      if (faction_isKnown( sys->presence[i].faction )) {
         t           = faction_getColourChar(sys->presence[i].faction);
         /* Use map grey instead of default neutral colour */
         l += nsnprintf( &buf[l], PATH_MAX-l, "%s\e0%s: \e%c%.0f",
                        (l==0)?"":"\n", faction_shortname(sys->presence[i].faction),
                        (t=='N')?'M':t, sys->presence[i].value);
      }
      else
示例#7
0
文件: map.c 项目: isfos/naev
/**
 * @brief Updates the map window.
 *
 *    @param wid Window id.
 */
static void map_update( unsigned int wid )
{
    int i;
    StarSystem* sys;
    int f, y, h, multiple_faction;
    double standing, nstanding;
    unsigned int services;
    char buf[PATH_MAX];
    int p;
    glTexture *logo;

    /* Needs map to update. */
    if (!map_isOpen())
        return;

    sys = system_getIndex( map_selected );

    /* Not known and no markers. */
    if (!(sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)) &&
            !sys_isKnown(sys) && !space_sysReachable(sys)) {
        map_selectCur();
        sys = system_getIndex( map_selected );
    }

    /*
     * Right Text
     */
    if (!sys_isKnown(sys)) { /* System isn't known, erase all */
        /*
         * Right Text
         */
        if (sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED))
            window_modifyText( wid, "txtSysname", sys->name );
        else
            window_modifyText( wid, "txtSysname", "Unknown" );
        window_modifyImage( wid, "imgFaction", NULL );
        window_moveWidget( wid, "txtSFaction", -20, -60 );
        window_moveWidget( wid, "txtFaction", -20, -60-gl_smallFont.h-5 );
        window_modifyText( wid, "txtFaction", "Unknown" );
        /* Standing */
        window_moveWidget( wid, "txtSStanding", -20, -100 );
        window_moveWidget( wid, "txtStanding", -20, -100-gl_smallFont.h-5 );
        window_modifyText( wid, "txtStanding", "Unknown" );
        /* Security. */
        window_moveWidget( wid, "txtSSecurity", -20, -140 );
        window_moveWidget( wid, "txtSecurity",  -20, -140-gl_smallFont.h-5 );
        window_modifyText( wid, "txtSecurity", "Unknown" );
        /* Planets */
        window_moveWidget( wid, "txtSPlanets", -20, -180 );
        window_moveWidget( wid, "txtPlanets", -20, -180-gl_smallFont.h-5 );
        window_modifyText( wid, "txtPlanets", "Unknown" );
        /* Services */
        window_moveWidget( wid, "txtSServices", -20, -220 );
        window_moveWidget( wid, "txtServices", -20, -220-gl_smallFont.h-5 );
        window_modifyText( wid, "txtServices", "Unknown" );

        /*
         * Bottom Text
         */
        window_modifyText( wid, "txtSystemStatus", NULL );
        return;
    }

    /* System is known */
    window_modifyText( wid, "txtSysname", sys->name );

    standing  = 0.;
    nstanding = 0.;
    f         = -1;
    multiple_faction = 0;
    for (i=0; i<sys->nplanets; i++) {
        if ((f==-1) && (sys->planets[i]->faction>0)) {
            f = sys->planets[i]->faction;
            standing += faction_getPlayer( f );
            nstanding++;
        }
        else if (f != sys->planets[i]->faction && /** @todo more verbosity */
                 (sys->planets[i]->faction>0)) {
            snprintf( buf, PATH_MAX, "Multiple" );
            multiple_faction = 1;
            break;
        }
    }
    if (f == -1) {
        window_modifyImage( wid, "imgFaction", NULL );
        window_moveWidget( wid, "txtSFaction", -20, -60 );
        window_moveWidget( wid, "txtFaction", -20, -60-gl_smallFont.h-5 );
        window_modifyText( wid, "txtFaction", "NA" );
        window_moveWidget( wid, "txtSStanding", -20, -100 );
        window_moveWidget( wid, "txtStanding", -20, -100-gl_smallFont.h-5 );
        window_modifyText( wid, "txtStanding", "NA" );
        y = -100;

    }
    else {
        if (i==sys->nplanets) /* saw them all and all the same */
            snprintf( buf, PATH_MAX, "%s", faction_longname(f) );

        y = -60;

        /* Modify the image. */
        logo = faction_logoSmall(f);
        window_modifyImage( wid, "imgFaction", logo );
        if (logo != NULL) {
            window_moveWidget( wid, "imgFaction",
                               -(90-logo->w)/2-20-logo->w, y-(64-logo->h)/2-logo->h );
            y -= 64 + 10;
        }

        /* Modify the text */
        window_modifyText( wid, "txtFaction", buf );
        window_modifyText( wid, "txtStanding",
                           faction_getStanding( standing / nstanding ) );

        /* Lower text if needed */
        window_moveWidget( wid, "txtSFaction", -20, y );
        window_moveWidget( wid, "txtFaction", -20, y-gl_smallFont.h-5 );
        h = gl_printHeightRaw( &gl_smallFont, 80, buf );
        window_moveWidget( wid, "txtSStanding", -20, y );
        window_moveWidget( wid, "txtStanding", -20, y-gl_smallFont.h-5 );
        y -= 40 + (h - gl_smallFont.h);
        window_moveWidget( wid, "txtSStanding", -20, y );
        window_moveWidget( wid, "txtStanding", -20, y-gl_smallFont.h-5 );
    }

    /* Get security. */
    y -= 40;
    if (sys->nfleets == 0)
        snprintf(buf, PATH_MAX, "NA" );
    else
        snprintf(buf, PATH_MAX, "%.0f %%", sys->security * 100.);
    window_moveWidget( wid, "txtSSecurity", -20, y );
    window_moveWidget( wid, "txtSecurity", -20, y-gl_smallFont.h-5 );
    window_modifyText( wid, "txtSecurity", buf );

    /* Get planets */
    if (sys->nplanets == 0) {
        strncpy( buf, "None", PATH_MAX );
        window_modifyText( wid, "txtPlanets", buf );
    }
    else {
        p = 0;
        buf[0] = '\0';
        if (sys->nplanets > 0)
            p += snprintf( &buf[p], PATH_MAX-p, "%s", sys->planets[0]->name );
        for (i=1; i<sys->nplanets; i++) {
            p += snprintf( &buf[p], PATH_MAX-p, ",\n%s", sys->planets[i]->name );
        }

        window_modifyText( wid, "txtPlanets", buf );
    }
    y -= 40;
    window_moveWidget( wid, "txtSPlanets", -20, y );
    window_moveWidget( wid, "txtPlanets", -20, y-gl_smallFont.h-5 );

    /* Get the services */
    h = gl_printHeightRaw( &gl_smallFont, 80, buf );
    y -= 40 + (h - gl_smallFont.h);
    window_moveWidget( wid, "txtSServices", -20, y );
    window_moveWidget( wid, "txtServices", -20, y-gl_smallFont.h-5 );
    services = 0;
    for (i=0; i<sys->nplanets; i++)
        services |= sys->planets[i]->services;
    buf[0] = '\0';
    p = 0;
    /*snprintf(buf, sizeof(buf), "%f\n", sys->prices[0]);*/ /*Hack to control prices. */
    if (services & PLANET_SERVICE_COMMODITY)
        p += snprintf( &buf[p], PATH_MAX-p, "Commodity\n");
    if (services & PLANET_SERVICE_OUTFITS)
        p += snprintf( &buf[p], PATH_MAX-p, "Outfits\n");
    if (services & PLANET_SERVICE_SHIPYARD)
        p += snprintf( &buf[p], PATH_MAX-p, "Shipyard\n");
    if (buf[0] == '\0')
        p += snprintf( &buf[p], PATH_MAX-p, "None");
    window_modifyText( wid, "txtServices", buf );


    /*
     * System Status
     */
    buf[0] = '\0';
    p = 0;
    /* Nebula. */
    if (sys->nebu_density > 0.) {

        /* Volatility */
        if (sys->nebu_volatility > 700.)
            p += snprintf(&buf[p], PATH_MAX-p, " Volatile");
        else if (sys->nebu_volatility > 300.)
            p += snprintf(&buf[p], PATH_MAX-p, " Dangerous");
        else if (sys->nebu_volatility > 0.)
            p += snprintf(&buf[p], PATH_MAX-p, " Unstable");

        /* Density */
        if (sys->nebu_density > 700.)
            p += snprintf(&buf[p], PATH_MAX-p, " Dense");
        else if (sys->nebu_density < 300.)
            p += snprintf(&buf[p], PATH_MAX-p, " Light");
        p += snprintf(&buf[p], PATH_MAX-p, " Nebula");
    }
    /* Interference. */
    if (sys->interference > 0.) {

        if (buf[0] != '\0')
            p += snprintf(&buf[p], PATH_MAX-p, ",");

        /* Density. */
        if (sys->interference > 700.)
            p += snprintf(&buf[p], PATH_MAX-p, " Dense");
        else if (sys->interference < 300.)
            p += snprintf(&buf[p], PATH_MAX-p, " Light");

        p += snprintf(&buf[p], PATH_MAX-p, " Interference");
    }
    window_modifyText( wid, "txtSystemStatus", buf );
}
示例#8
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");
}