Exemple #1
0
Fichier : map.c Projet : pegue/naev
/**
 * @brief Map custom widget mouse handling.
 *
 *    @param wid Window sending events.
 *    @param event Event window is sending.
 *    @param mx Mouse X position.
 *    @param my Mouse Y position.
 *    @param w Width of the widget.
 *    @param h Height of the widget.
 */
static void map_mouse( unsigned int wid, SDL_Event* event, double mx, double my,
      double w, double h )
{
   (void) wid;
   int i;
   double x,y, t;
   StarSystem *sys;

   t = 15.*15.; /* threshold */

   mx -= w/2 - map_xpos;
   my -= h/2 - map_ypos;

   switch (event->type) {
      
      case SDL_MOUSEBUTTONDOWN:
         /* zooming */
         if (event->button.button == SDL_BUTTON_WHEELUP)
            map_buttonZoom( 0, "btnZoomIn" );
         else if (event->button.button == SDL_BUTTON_WHEELDOWN)
            map_buttonZoom( 0, "btnZoomOut" );

         /* selecting star system */
         else {
            for (i=0; i<systems_nstack; i++) {
               sys = system_getIndex( i );

               /* must be reachable */
               if (!space_sysReachable(sys))
                  continue;

               /* get position */
               x = sys->pos.x * map_zoom;
               y = sys->pos.y * map_zoom;

               if ((pow2(mx-x)+pow2(my-y)) < t) {

                  map_select( sys );
                  break;
               }
            }
            map_drag = 1;
         }
         break;

      case SDL_MOUSEBUTTONUP:
         if (map_drag) map_drag = 0;
         break;

      case SDL_MOUSEMOTION:
         if (map_drag) {
            /* axis is inverted */
            map_xpos -= event->motion.xrel;
            map_ypos += event->motion.yrel;
         }
         break;
   }
}
Exemple #2
0
Fichier : map.c Projet : isfos/naev
/**
 * @brief Selects the system in the map.
 *
 *    @param sys System to select.
 */
void map_select( StarSystem *sys, char shifted )
{
    unsigned int wid;
    int i;

    wid = window_get(MAP_WDWNAME);

    if (sys == NULL) {
        map_selectCur();
    }
    else {
        map_selected = sys - systems_stack;

        /* select the current system and make a path to it */
        if (!shifted) {
            if (map_path)
                free(map_path);
            map_path  = NULL;
            map_npath = 0;
        }

        /* Try to make path if is reachable. */
        if (space_sysReachable(sys)) {
            if (!shifted) {
                map_path = map_getJumpPath( &map_npath,
                                            cur_system->name, sys->name, 0 , NULL );
            }
            else {
                map_path = map_getJumpPath( &map_npath,
                                            cur_system->name, sys->name, 0 , map_path );
            }

            if (map_npath==0)
                hyperspace_target = -1;
            else  {
                /* see if it is a valid hyperspace target */
                for (i=0; i<cur_system->njumps; i++) {
                    if (map_path[0] == system_getIndex(cur_system->jumps[i])) {
                        planet_target     = -1; /* override planet_target */
                        hyperspace_target = i;
                        break;
                    }
                }
            }
        }
        else { /* unreachable. */
            hyperspace_target = -1;
        }
    }

    map_update(wid);
}
Exemple #3
0
Fichier : map.c Projet : isfos/naev
/**
 * @brief Shows a map at x, y (relative to wid) with size w,h.
 *
 *    @param wid Window to show map on.
 *    @param x X position to put map at.
 *    @param y Y position to put map at.
 *    @param w Width of map to open.
 *    @param h Height of map to open.
 *    @param zoom Default zoom to use.
 */
void map_show( int wid, int x, int y, int w, int h, double zoom )
{
    StarSystem *sys;

    /* mark systems as needed */
    mission_sysMark();

    /* Set position to focus on current system. */
    map_xpos = cur_system->pos.x * zoom;
    map_ypos = cur_system->pos.y * zoom;

    /* Set zoom. */
    map_setZoom(zoom);

    /* Make sure selected is sane. */
    sys = system_getIndex( map_selected );
    if (!(sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)) &&
            !sys_isKnown(sys) && !space_sysReachable(sys))
        map_selectCur();

    window_addCust( wid, x, y, w, h,
                    "cstMap", 1, map_render, map_mouse, NULL );
}
Exemple #4
0
/**
 * @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
Exemple #5
0
Fichier : map.c Projet : isfos/naev
/**
 * @brief Map custom widget mouse handling.
 *
 *    @param wid Window sending events.
 *    @param event Event window is sending.
 *    @param mx Mouse X position.
 *    @param my Mouse Y position.
 *    @param w Width of the widget.
 *    @param h Height of the widget.
 */
static void map_mouse( unsigned int wid, SDL_Event* event, double mx, double my,
                       double w, double h, void *data )
{
    (void) wid;
    (void) data;
    int i;
    double x,y, t;
    StarSystem *sys;

    t = 15.*15.; /* threshold */

    switch (event->type) {

    case SDL_MOUSEBUTTONDOWN:
        /* Must be in bounds. */
        if ((mx < 0.) || (mx > w) || (my < 0.) || (my > h))
            return;

        /* Zooming */
        if (event->button.button == SDL_BUTTON_WHEELUP)
            map_buttonZoom( 0, "btnZoomIn" );
        else if (event->button.button == SDL_BUTTON_WHEELDOWN)
            map_buttonZoom( 0, "btnZoomOut" );

        /* selecting star system */
        else {
            mx -= w/2 - map_xpos;
            my -= h/2 - map_ypos;

            for (i=0; i<systems_nstack; i++) {
                sys = system_getIndex( i );

                /* must be reachable */
                if (!sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)
                        && !space_sysReachable(sys))
                    continue;

                /* get position */
                x = sys->pos.x * map_zoom;
                y = sys->pos.y * map_zoom;

                if ((pow2(mx-x)+pow2(my-y)) < t) {

                    map_select( sys, (SDL_GetModState() & KMOD_SHIFT) );
                    break;
                }
            }
            map_drag = 1;
        }
        break;

    case SDL_MOUSEBUTTONUP:
        if (map_drag)
            map_drag = 0;
        break;

    case SDL_MOUSEMOTION:
        if (map_drag) {
            /* axis is inverted */
            map_xpos -= event->motion.xrel;
            map_ypos += event->motion.yrel;
        }
        break;
    }
}
Exemple #6
0
Fichier : map.c Projet : isfos/naev
/**
 * @brief Renders the custom map widget.
 *
 *    @param bx Base X position to render at.
 *    @param by Base Y position to render at.
 *    @param w Width of the widget.
 *    @param h Height of the widget.
 */
static void map_render( double bx, double by, double w, double h, void *data )
{
    (void) data;
    int i,j, n,m;
    double x,y,r, tx,ty, fuel;
    StarSystem *sys, *jsys, *hsys, *lsys;
    glColour *col, c;
    GLfloat vertex[8*(2+4)];
    int sw, sh;

    /* Parameters. */
    r = round(CLAMP(5., 15., 6.*map_zoom));
    x = round((bx - map_xpos + w/2) * 1.);
    y = round((by - map_ypos + h/2) * 1.);

    /* background */
    gl_renderRect( bx, by, w, h, &cBlack );

    /*
     * First pass renders everything almost (except names and markers).
     */
    for (i=0; i<systems_nstack; i++) {
        sys = system_getIndex( i );

        /* check to make sure system is known or adjacent to known (or marked) */
        if (!sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)
                && !space_sysReachable(sys))
            continue;

        tx = x + sys->pos.x*map_zoom;
        ty = y + sys->pos.y*map_zoom;

        /* draws the disk representing the faction */
        if (sys_isKnown(sys) && (sys->faction != -1)) {
            sw = gl_faction_disk->sw;
            sh = gl_faction_disk->sw;

            col = faction_colour(sys->faction);
            c.r = col->r;
            c.g = col->g;
            c.b = col->b;
            c.a = 0.7;

            gl_blitTexture(
                gl_faction_disk,
                tx - sw/2, ty - sh/2, sw, sh,
                0., 0., gl_faction_disk->srw, gl_faction_disk->srw, &c );
        }

        /* Draw the system. */
        if (!sys_isKnown(sys) || (sys->nfleets==0)) col = &cInert;
        else if (sys->security >= 1.) col = &cGreen;
        else if (sys->security >= 0.6) col = &cOrange;
        else if (sys->security >= 0.3) col = &cRed;
        else col = &cDarkRed;

        gl_drawCircleInRect( tx, ty, r, bx, by, w, h, col, 0 );

        /* If system is known fill it. */
        if (sys_isKnown(sys) && (sys->nplanets > 0)) {
            /* Planet colours */
            if (!sys_isKnown(sys)) col = &cInert;
            else if (sys->nplanets==0) col = &cInert;
            else col = faction_getColour( sys->faction);

            /* Radius slightly shorter. */
            gl_drawCircleInRect( tx, ty, 0.5*r, bx, by, w, h, col, 1 );
        }

        if (!sys_isKnown(sys))
            continue; /* we don't draw hyperspace lines */

        /* draw the hyperspace paths */
        glShadeModel(GL_SMOOTH);
        col = &cDarkBlue;
        /* first we draw all of the paths. */
        for (j=0; j<sys->njumps; j++) {

            jsys = system_getIndex( sys->jumps[j] );
            if (hyperspace_target != -1)
                hsys = system_getIndex( cur_system->jumps[hyperspace_target] );

            /* Draw the lines. */
            vertex[0]  = x + sys->pos.x * map_zoom;
            vertex[1]  = y + sys->pos.y * map_zoom;
            vertex[2]  = vertex[0] + (jsys->pos.x - sys->pos.x)/2. * map_zoom;
            vertex[3]  = vertex[1] + (jsys->pos.y - sys->pos.y)/2. * map_zoom;
            vertex[4]  = x + jsys->pos.x * map_zoom;
            vertex[5]  = y + jsys->pos.y * map_zoom;
            vertex[6]  = col->r;
            vertex[7]  = col->g;
            vertex[8]  = col->b;
            vertex[9]  = 0.;
            vertex[10] = col->r;
            vertex[11] = col->g;
            vertex[12] = col->b;
            vertex[13] = col->a;
            vertex[14] = col->r;
            vertex[15] = col->g;
            vertex[16] = col->b;
            vertex[17] = 0.;
            gl_vboSubData( map_vbo, 0, sizeof(GLfloat) * 3*(2+4), vertex );
            gl_vboActivateOffset( map_vbo, GL_VERTEX_ARRAY, 0, 2, GL_FLOAT, 0 );
            gl_vboActivateOffset( map_vbo, GL_COLOR_ARRAY,
                                  sizeof(GLfloat) * 2*3, 4, GL_FLOAT, 0 );
            glDrawArrays( GL_LINE_STRIP, 0, 3 );
            gl_vboDeactivate();
        }
        glShadeModel( GL_FLAT );
    }

    /* Now we'll draw over the lines with the new pathways. */
    if (map_path != NULL) {
        lsys = cur_system;
        glShadeModel(GL_SMOOTH);
        col = &cGreen;
        fuel = player->fuel;

        for (j=0; j<map_npath; j++) {
            jsys = map_path[j];
            if (fuel == player->fuel)
                col = &cGreen;
            else if (fuel < 100.)
                col = &cRed;
            else
                col = &cYellow;
            fuel -= 100;

            /* Draw the lines. */
            vertex[0]  = x + lsys->pos.x * map_zoom;
            vertex[1]  = y + lsys->pos.y * map_zoom;
            vertex[2]  = vertex[0] + (jsys->pos.x - lsys->pos.x)/2. * map_zoom;
            vertex[3]  = vertex[1] + (jsys->pos.y - lsys->pos.y)/2. * map_zoom;
            vertex[4]  = x + jsys->pos.x * map_zoom;
            vertex[5]  = y + jsys->pos.y * map_zoom;
            vertex[6]  = col->r;
            vertex[7]  = col->g;
            vertex[8]  = col->b;
            vertex[9]  = 0.;
            vertex[10] = col->r;
            vertex[11] = col->g;
            vertex[12] = col->b;
            vertex[13] = col->a;
            vertex[14] = col->r;
            vertex[15] = col->g;
            vertex[16] = col->b;
            vertex[17] = 0.;
            gl_vboSubData( map_vbo, 0, sizeof(GLfloat) * 3*(2+4), vertex );
            gl_vboActivateOffset( map_vbo, GL_VERTEX_ARRAY, 0, 2, GL_FLOAT, 0 );
            gl_vboActivateOffset( map_vbo, GL_COLOR_ARRAY,
                                  sizeof(GLfloat) * 2*3, 4, GL_FLOAT, 0 );
            glDrawArrays( GL_LINE_STRIP, 0, 3 );
            gl_vboDeactivate();

            lsys = jsys;
        }

        glShadeModel( GL_FLAT );
    }

    /*
     * Second pass - System names
     */
    for (i=0; i<systems_nstack; i++) {
        sys = system_getIndex( i );

        /* Skip system. */
        if (!sys_isKnown(sys) || (map_zoom <= 0.5 ))
            continue;

        tx = x + (sys->pos.x+11.) * map_zoom;
        ty = y + (sys->pos.y-5.) * map_zoom;
        gl_print( &gl_smallFont,
                  tx + SCREEN_W/2., ty + SCREEN_H/2.,
                  &cWhite, sys->name );
    }


    /*
     * Third pass - system markers
     */
    for (i=0; i<systems_nstack; i++) {
        sys = system_getIndex( i );

        /* We only care about marked now. */
        if (!sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED))
            continue;

        /* Get the position. */
        tx = x + sys->pos.x*map_zoom;
        ty = y + sys->pos.y*map_zoom;

        /* Count markers. */
        n  = (sys_isFlag(sys, SYSTEM_CMARKED)) ? 1 : 0;
        n += sys->markers_misc;
        n += sys->markers_cargo;
        n += sys->markers_rush;

        /* Draw the markers. */
        j = 0;
        if (sys_isFlag(sys, SYSTEM_CMARKED)) {
            map_drawMarker( tx, ty, r, n, j, 0 );
            j++;
        }
        for (m=0; m<sys->markers_misc; m++) {
            map_drawMarker( tx, ty, r, n, j, 1 );
            j++;
        }
        for (m=0; m<sys->markers_rush; m++) {
            map_drawMarker( tx, ty, r, n, j, 2 );
            j++;
        }
        for (m=0; m<sys->markers_cargo; m++) {
            map_drawMarker( tx, ty, r, n, j, 3 );
            j++;
        }
    }

    /* Selected planet. */
    if (map_selected != -1) {
        sys = system_getIndex( map_selected );
        gl_drawCircleInRect( x + sys->pos.x * map_zoom, y + sys->pos.y * map_zoom,
                             1.5*r, bx, by, w, h, &cRed, 0 );
    }

    /* Current planet. */
    gl_drawCircleInRect( x + cur_system->pos.x * map_zoom,
                         y + cur_system->pos.y * map_zoom,
                         1.5*r, bx, by, w, h, &cRadar_tPlanet, 0 );
}
Exemple #7
0
Fichier : map.c Projet : 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 );
}
Exemple #8
0
Fichier : map.c Projet : pegue/naev
/**
 * @brief Renders the custom map widget.
 *
 *    @param bx Base X position to render at.
 *    @param by Base Y position to render at.
 *    @param w Width of the widget.
 *    @param h Height of the widget.
 */
static void map_render( double bx, double by, double w, double h )
{
   int i,j, n,m;
   double x,y,r, tx,ty;
   StarSystem *sys, *jsys, *hsys;
   glColour* col;

   r = 5.;
   x = (bx - map_xpos + w/2) * 1.;
   y = (by - map_ypos + h/2) * 1.;

   /* background */
   COLOUR(cBlack);
   glBegin(GL_QUADS);
      glVertex2d( bx, by );
      glVertex2d( bx, by+h );
      glVertex2d( bx+w, by+h );
      glVertex2d( bx+w, by );
   glEnd(); /* GL_QUADS */


   /* render the star systems */
   for (i=0; i<systems_nstack; i++) {
      
      sys = system_getIndex( i );

      /* check to make sure system is known or adjacent to known (or marked) */
      if (!sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED) && !space_sysReachable(sys))
         continue;

      /* system colours */
      if (sys==cur_system) col = &cRadar_tPlanet;
      else if (!sys_isKnown(sys) || (sys->nplanets==0)) col = &cInert;
      else col = faction_getColour( sys->faction);
      COLOUR(*col);

      /* draw the system */
      tx = x + sys->pos.x*map_zoom;
      ty = y + sys->pos.y*map_zoom;
      gl_drawCircleInRect( tx, ty, r, bx, by, w, h );

      /* draw the system name */
      if (sys_isKnown(sys) && (map_zoom > 0.5 )) {
         tx = x + 7. + sys->pos.x * map_zoom;
         ty = y - 5. + sys->pos.y * map_zoom;
         gl_print( &gl_smallFont,
               tx + SCREEN_W/2., ty + SCREEN_H/2.,
               &cWhite, sys->name );
      }


      if (!sys_isKnown(sys)) continue; /* we don't draw hyperspace lines */

      /* draw the hyperspace paths */
      glShadeModel(GL_SMOOTH);
      /* cheaply use transparency instead of actually calculating
       * from where to where the line must go :) */  
      for (j=0; j<sys->njumps; j++) {

         jsys = system_getIndex( sys->jumps[j] );
         if (hyperspace_target != -1)
            hsys = system_getIndex( cur_system->jumps[hyperspace_target] );

         n = map_inPath(jsys);
         m = map_inPath(sys);
         /* set the colours */
         /* is the route the current one? */
         if ((hyperspace_target != -1) && 
               ( ((cur_system==sys) && (j==hyperspace_target)) ||
                  ((cur_system==jsys) &&
                     (sys==hsys )))) {
            if (player->fuel < HYPERSPACE_FUEL)
               col = &cRed;
            else
               col = &cGreen;
         }
         /* is the route part of the path? */
         else if ((n > 0) && (m > 0)) {
            if ((n == 2) || (m == 2)) /* out of fuel */
               col = &cRed;
            else
               col = &cYellow;
         }
         else
            col = &cDarkBlue;

         glBegin(GL_LINE_STRIP);
            ACOLOUR(*col,0.);
            tx = x + sys->pos.x * map_zoom;
            ty = y + sys->pos.y * map_zoom;
            glVertex2d( tx, ty );
            COLOUR(*col);
            tx += (jsys->pos.x - sys->pos.x)/2. * map_zoom;
            ty += (jsys->pos.y - sys->pos.y)/2. * map_zoom;
            glVertex2d( tx, ty );
            ACOLOUR(*col,0.);
            tx = x + jsys->pos.x * map_zoom;
            ty = y + jsys->pos.y * map_zoom;
            glVertex2d( tx, ty );
         glEnd(); /* GL_LINE_STRIP */
      }
      glShadeModel(GL_FLAT);
   }

   /* Second pass to put markers. */
   for (i=0; i<systems_nstack; i++) {
      sys = system_getIndex( i );

      /* We only care about marked now. */
      if (!sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED))
         continue;

      /* Get the position. */
      tx = x + sys->pos.x*map_zoom;
      ty = y + sys->pos.y*map_zoom;

      /* Count markers. */
      n  = (sys_isFlag(sys, SYSTEM_CMARKED)) ? 1 : 0;
      n += sys->markers_misc;
      n += sys->markers_cargo;
      n += sys->markers_rush;

      /* Draw the markers. */
      j = 0;
      if (sys_isFlag(sys, SYSTEM_CMARKED)) {
         map_drawMarker( tx, ty, r, n, j, 0 );
         j++;
      }
      for (m=0; m<sys->markers_misc; m++) {
         map_drawMarker( tx, ty, r, n, j, 1 );
         j++;
      }
      for (m=0; m<sys->markers_rush; m++) {
         map_drawMarker( tx, ty, r, n, j, 2 );
         j++;
      }
      for (m=0; m<sys->markers_cargo; m++) {
         map_drawMarker( tx, ty, r, n, j, 3 );
         j++;
      }
   }

   /* selected planet */
   if (map_selected != -1) {
      sys = system_getIndex( map_selected );
      COLOUR(cRed);
      gl_drawCircleInRect( x + sys->pos.x * map_zoom, y + sys->pos.y * map_zoom,
            r+3., bx, by, w, h );
   }
}