Example #1
0
static int ray_ok(board_t *board, move_t *move)
{
    int step, i;
    if (VERT != 0)
        step = (move->destination - move->source) / VERT;
    else
        step = (move->destination > move->source ? 1 : -1);

    i = move->source + step;

    while (i != move->destination)
    {
        if (board->square[i] != NONE)
            return 0;
        i += step;
    }

    if (board->square[i] == NONE)
        return 1;

    if (COLOUR(board->square[i]) != COLOUR(board->square[move->source]))
        return 1;

    return 0;
}
Example #2
0
static bitboard getPieceBitboard(const position * const pos, const int piece)
{
    bitboard b = 0;
    int colour = COLOUR(piece);
    if(IS_KING(piece)) {
        b = pos->king[colour];
    }
    else if(IS_PAWN(piece)) {
        b = pos->pawns[colour];
    }
    else if(IS_KNIGHT(piece)) {
        b = pos->knights[colour];
    }
    else if(IS_BISHOP(piece)) {
        b = pos->bishops[colour];
    }
    else if(IS_ROOK(piece)) {
        b = pos->rooks[colour];
    }
    else if(IS_QUEEN(piece)) {
        b = pos->queens[colour];
    }
    else {
        /* Something is wrong, I don't know which piece this is.
         * This must NEVER happen; move generation is screwed.
         */
        assert(0);
    }
    return b;
}
Example #3
0
static int square_attacked(board_t *b, int square, int side)
{
    board_t board = *b;
    move_t move;
    int i;

    board.turn = side;

    /* We add a piece because we only want to take capture moves into consideration. */
    board.square[square] = KING + OPPONENT(side);

    move.destination = square;

    for (i = 0; i < 64; i++)
    {
        if (COLOUR(board.square[i]) == side)
        {
            move.source = i;
            if ((PIECE(board.square[i]) == PAWN) && ((square < 8) || (square >= 56)))
                move.promotion_piece = QUEEN + side;
            else
                move.promotion_piece = NONE;
            if (move_is_semi_valid(&board, &move))
                return 1;
        }
    }
    return 0;
}
Example #4
0
File: font.c Project: nenau/naev
/**
 * @brief Starts the rendering engine.
 */
static void gl_fontRenderStart( const glFontStash* font, double x, double y, const glColour *c )
{
   double a;

   /* Enable textures. */
   glEnable(GL_TEXTURE_2D);

   /* Set up matrix. */
   gl_matrixMode(GL_MODELVIEW);
   gl_matrixPush();
      gl_matrixTranslate( round(x), round(y) );

   /* Handle colour. */
   if (font_restoreLast) {
      a   = (c==NULL) ? 1. : c->a;
      ACOLOUR(*font_lastCol,a);
   }
   else {
      if (c==NULL)
         glColor4d( 1., 1., 1., 1. );
      else
         COLOUR(*c);
   }
   font_restoreLast = 0;

   /* Activate the appropriate VBOs. */
   gl_vboActivateOffset( font->vbo_tex,  GL_TEXTURE_COORD_ARRAY, 0, 2, GL_FLOAT, 0 );
   gl_vboActivateOffset( font->vbo_vert, GL_VERTEX_ARRAY, 0, 2, GL_SHORT, 0 );
}
Example #5
0
File: font.c Project: nenau/naev
/**
 * @brief Renders a character.
 */
static int gl_fontRenderGlyph( glFontStash* stsh, uint32_t ch, const glColour *c, int state )
{
   GLushort ind[6];
   double a;
   const glColour *col;
   int vbo_id;

   /* Handle escape sequences. */
   if (ch == '\a') {/* Start sequence. */
      return 1;
   }
   if (state == 1) {
      col = gl_fontGetColour( ch );
      a   = (c==NULL) ? 1. : c->a;
      if (col == NULL) {
         if (c==NULL)
            glColor4d( 1., 1., 1., 1. );
         else
            COLOUR(*c);
      }
      else
         ACOLOUR(*col,a);
      font_lastCol = col;
      return 0;
   }

   /* Unicode goes here.
    * First try to find the glyph. */
   glFontGlyph *glyph;
   glyph = gl_fontGetGlyph( stsh, ch );
   if (glyph == NULL) {
      WARN(_("Unable to find glyph '%d'!"), ch );
      return -1;
   }

   /* Activate texture. */
   glBindTexture(GL_TEXTURE_2D, glyph->tex->id);

   /* VBO indices. */
   vbo_id = glyph->vbo_id;
   ind[0] = vbo_id + 0;
   ind[1] = vbo_id + 1;
   ind[2] = vbo_id + 3;
   ind[3] = vbo_id + 1;
   ind[4] = vbo_id + 3;
   ind[5] = vbo_id + 2;

   /* Draw the element. */
   glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, ind );

   /* Translate matrix. */
   gl_matrixTranslate( glyph->adv_x, glyph->adv_y );

   return 0;
}
Example #6
0
File: map.c Project: pegue/naev
/**
 * @brief Draws a mission marker on the map.
 *
 * @param x X position to draw at.
 * @param y Y position to draw at.
 * @param r Radius of system.
 * @param num Total number of markers.
 * @param cur Current marker to draw.
 * @param type Type to draw.
 */
static void map_drawMarker( double x, double y, double r,
      int num, int cur, int type )
{
   double a, c,s, d;

   /* Get colour marking. */
   switch (type) {
      case 0:
         COLOUR(cGreen);
         break;
      case 1:
         COLOUR(cLightBlue);
         break;
      case 2:
         COLOUR(cRed);
         break;
      case 3:
         COLOUR(cOrange);
         break;
   }

   /* Calculate the angle. */
   if ((num == 1) || (num == 2) || (num == 4))
      a = M_PI/4.;
   else if (num == 3)
      a = M_PI/6.;
   else if (num == 5)
      a = M_PI/10.;
   else
      a = M_PI/2.;
   a += M_PI*2. * (double)cur/(double)num;
   d = MAX(r, 8. * 1.5 * map_zoom);
   c  = cos(a);
   s  = sin(a);

   /* Draw the marking triangle. */
   glBegin(GL_TRIANGLES);
      glVertex2d( x + (d)*c,              y + (d)*s );
      glVertex2d( x + (d+8.)*c - (4.)*s,  y + (d+8.)*s + (4.)*c );
      glVertex2d( x + (d+8.)*c - (-4.)*s, y + (d+8.)*s + (-4.)*c );
   glEnd(); /* GL_TRIANGLES */
}
Example #7
0
static void getCastlingMoves(const position * const pos, const int player, move store[], int *numMoves)
{
    int colour;
    int sq;
    move m;
    sq = pos->kingSquare[player];
    colour = COLOUR(pos->board[sq]);
    m.from = sq;
    m.flags = CASTLE;
    m.thisPiece = pos->board[sq];
    m.promoteTo = 0;
    m.capturedPiece = 0;
    m.eval = 0;
    if(WHITE == player && !inCheck(pos, WHITE, pos->kingSquare[WHITE])) {
        if((pos->castleFlags & CASTLE_WK) && (0 == pos->board[1]) && (0 == pos->board[2])) {
              if(!inCheck(pos, WHITE, 1) && !inCheck(pos, WHITE, 2)) {

                    assert(WHITE_ROOK == pos->board[0]);

                    m.to = 1;
                    storeMoveIfLegal(pos, &m, WHITE, store, numMoves);
              }
        }
        if((pos->castleFlags & CASTLE_WQ) && (0 == pos->board[4]) && (0 == pos->board[5]) && (0 == pos->board[6])) {
              if(!inCheck(pos, WHITE, 4) && !inCheck(pos, WHITE, 5)) {

                    assert(WHITE_ROOK == pos->board[7]);

                    m.to = 5;
                    storeMoveIfLegal(pos, &m, WHITE, store, numMoves);
              }
        }
    }
    else if(!inCheck(pos, BLACK, pos->kingSquare[BLACK])) {
        if((pos->castleFlags & CASTLE_BK) && (0 == pos->board[57]) && (0 == pos->board[58])) {
              if(!inCheck(pos, BLACK, 57) && !inCheck(pos, BLACK, 58)) {

                    assert(BLACK_ROOK == pos->board[56]);

                    m.to = 57;
                    storeMoveIfLegal(pos, &m, BLACK, store, numMoves);
              }
        }
        if((pos->castleFlags & CASTLE_BQ) && (0 == pos->board[62]) && (0 == pos->board[61]) && (0 == pos->board[60])) {
              if(!inCheck(pos, BLACK, 61) && !inCheck(pos, BLACK, 60)) {

                    assert(BLACK_ROOK == pos->board[63]);

                    m.to = 61;
                    storeMoveIfLegal(pos, &m, BLACK, store, numMoves);
              }
        }
    }
}
Example #8
0
sEnvironmentSettings GetSettings()
{
	sEnvironmentSettings s;

	CmpPtr<ICmpWaterManager> cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
	ENSURE(cmpWaterManager);

	s.waterheight = cmpWaterManager->GetExactWaterLevel(0, 0) / (65536.f * HEIGHT_SCALE);

	WaterManager* wm = g_Renderer.GetWaterManager();
	s.waterwaviness = wm->m_Waviness;
	s.watermurkiness = wm->m_Murkiness;
	s.waterreflectiontintstrength = wm->m_ReflectionTintStrength;

	// CColor colours
#define COLOUR(A, B) A = Colour((int)(B.r*255), (int)(B.g*255), (int)(B.b*255))
	COLOUR(s.watercolour, wm->m_WaterColor);
	COLOUR(s.watertint, wm->m_WaterTint);
	COLOUR(s.waterreflectiontint, wm->m_ReflectionTint);
#undef COLOUR

	float sunrotation = g_LightEnv.GetRotation();
	if (sunrotation > (float)M_PI)
		sunrotation -= (float)M_PI*2;
	s.sunrotation = sunrotation;
	s.sunelevation = g_LightEnv.GetElevation();
	
	s.posteffect = g_Renderer.GetPostprocManager().GetPostEffect();

	s.skyset = g_Renderer.GetSkyManager()->GetSkySet();
	
	s.fogfactor = g_LightEnv.m_FogFactor;
	s.fogmax = g_LightEnv.m_FogMax;
	
	s.brightness = g_LightEnv.m_Brightness;
	s.contrast = g_LightEnv.m_Contrast;
	s.saturation = g_LightEnv.m_Saturation;
	s.bloom = g_LightEnv.m_Bloom;

	// RGBColor (CVector3D) colours
#define COLOUR(A, B) A = Colour((int)(B.X*255), (int)(B.Y*255), (int)(B.Z*255))
	s.sunoverbrightness = MaxComponent(g_LightEnv.m_SunColor);
	// clamp color to [0..1] before packing into u8 triplet
	if(s.sunoverbrightness > 1.0f)
		g_LightEnv.m_SunColor *= 1.0/s.sunoverbrightness;	// (there's no operator/=)
	// no component was above 1.0, so reset scale factor (don't want to darken)
	else
		s.sunoverbrightness = 1.0f;
	COLOUR(s.suncolour, g_LightEnv.m_SunColor);
	COLOUR(s.terraincolour, g_LightEnv.m_TerrainAmbientColor);
	COLOUR(s.unitcolour, g_LightEnv.m_UnitsAmbientColor);
	COLOUR(s.fogcolour, g_LightEnv.m_FogColor);
#undef COLOUR

	return s;
}
Example #9
0
static void 
colourview_refresh( vObject *vobject )
{
	Colourview *colourview = COLOURVIEW( vobject );
	Colour *colour = COLOUR( vobject->iobject );

#ifdef DEBUG
	printf( "colourview_refresh\n" );
#endif /*DEBUG*/

	conversion_set_image( colourview->conv, colour_ii_new( colour ) );
	set_gcaption( colourview->label, "%s", vips_buf_all( &colour->caption ) );

	VOBJECT_CLASS( parent_class )->refresh( vobject );
}
Example #10
0
		// Load a set of splotch colour palettes
		int LoadColourPalette(Parameter param, std::vector<COLOURMAP>& colourMaps)
		{
			paramfile* splotchParams = param.GetParamFileReference();

			// Get number of particle types
			int ptypes = splotchParams->find<int>("ptypes",1);

			// Resize colourmap vec appropriately 
			colourMaps.resize(ptypes);

			// For each type
			for (int i=0; i<ptypes; i++)
			{
				// Check if colour is vector, if so there will be no colourmap to load
				if (splotchParams->find<bool>("color_is_vector"+dataToString(i),false))
					std::cout << " color of ptype " << i << " is vector, so no colormap to load ..." << std::endl;
				else
				{
					// Read palette file
					std::ifstream infile (splotchParams->find<std::string>("palette"+dataToString(i)).c_str());
					if(!infile)
					{
						std::cout << "Could not open palette file "<< splotchParams->find<std::string>("palette"+dataToString(i)).c_str() << " for " << "palette"+dataToString(i) << std::endl;
						return 0;
					}

					// Get number of colours in palette
					std::string dummy;
					int nColours;
					infile >> dummy >> dummy >> nColours;
					std::cout << " loading " << nColours << " entries of color table of ptype " << i << std::endl;

					// Load
					double step = 1./(nColours-1);
					for (int j=0; j<nColours; j++)
					{
						float rrr,ggg,bbb;
						infile >> rrr >> ggg >> bbb;
						colourMaps[i].addVal(j*step,COLOUR(rrr/255,ggg/255,bbb/255));
					}
				}

				// Sort
				colourMaps[i].sortMap();
			}

			return 1;
		}
Example #11
0
void SetSettings(const sEnvironmentSettings& s)
{
	CmpPtr<ICmpWaterManager> cmpWaterManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
	ENSURE(cmpWaterManager);

	cmpWaterManager->SetWaterLevel(entity_pos_t::FromFloat(s.waterheight * (65536.f * HEIGHT_SCALE)));

	WaterManager* wm = g_Renderer.GetWaterManager();
	wm->m_Waviness = s.waterwaviness;
	wm->m_Murkiness = s.watermurkiness;
	wm->m_ReflectionTintStrength = s.waterreflectiontintstrength;

#define COLOUR(A, B) B = CColor(A->r/255.f, A->g/255.f, A->b/255.f, 1.f)
	COLOUR(s.watercolour, wm->m_WaterColor);
	COLOUR(s.watertint, wm->m_WaterTint);
	COLOUR(s.waterreflectiontint, wm->m_ReflectionTint);
#undef COLOUR

	g_LightEnv.SetRotation(s.sunrotation);
	g_LightEnv.SetElevation(s.sunelevation);
	
	CStrW posteffect = *s.posteffect;
	if (posteffect.length() == 0)
		posteffect = L"default";
	g_Renderer.GetPostprocManager().SetPostEffect(posteffect);

	CStrW skySet = *s.skyset;
	if (skySet.length() == 0)
		skySet = L"default";
	g_Renderer.GetSkyManager()->SetSkySet(skySet);
	
	g_LightEnv.m_FogFactor = s.fogfactor;
	g_LightEnv.m_FogMax = s.fogmax;
	
	g_LightEnv.m_Brightness = s.brightness;
	g_LightEnv.m_Contrast = s.contrast;
	g_LightEnv.m_Saturation = s.saturation;
	g_LightEnv.m_Bloom = s.bloom;

#define COLOUR(A, B) B = RGBColor(A->r/255.f, A->g/255.f, A->b/255.f)
	COLOUR(s.suncolour, g_LightEnv.m_SunColor);
	g_LightEnv.m_SunColor *= s.sunoverbrightness;
	COLOUR(s.terraincolour, g_LightEnv.m_TerrainAmbientColor);
	COLOUR(s.unitcolour, g_LightEnv.m_UnitsAmbientColor);
	COLOUR(s.fogcolour, g_LightEnv.m_FogColor);
#undef COLOUR
}
Example #12
0
File: spfx.c Project: pegue/naev
/**
 * @brief Sets the cinematic mode.
 *
 * Should be run at the end of the render loop if needed.
 */
void spfx_cinematic (void)
{
   glMatrixMode(GL_MODELVIEW);
   glPushMatrix(); /* translation matrix */
      glTranslated( -(double)SCREEN_W/2., -(double)SCREEN_H/2., 0);

   COLOUR(cBlack);
   glBegin(GL_QUADS);
      glVertex2d( 0.,       0.           );
      glVertex2d( 0.,       SCREEN_H*0.2 );
      glVertex2d( SCREEN_W, SCREEN_H*0.2 );
      glVertex2d( SCREEN_W, 0.           );
      glVertex2d( 0.,       SCREEN_H     );
      glVertex2d( SCREEN_W, SCREEN_H     );
      glVertex2d( SCREEN_W, SCREEN_H*0.8 );
      glVertex2d( 0.,       SCREEN_H*0.8 );
   glEnd(); /* GL_QUADS */

   glPopMatrix(); /* translation matrx */
}
Example #13
0
static int is_mated(board_t *board, int side)
{
    int src, dest;
    move_t move;

    for (src = 0; src < 64; src++)
        if (COLOUR(board->square[src]) == side)
            for (dest = 0; dest < 64; dest++)
            {
                move.source = src;
                move.destination = dest;
                if ((PIECE(board->square[src]) == PAWN) && ((dest < 8) || (dest >= 56)))
                    move.promotion_piece = QUEEN + side;
                else
                    move.promotion_piece = NONE;
                if (move_is_valid(board, &move))
                    return 0;
            }
    return 1;
}
Example #14
0
File: weapon.c Project: zid/naev
/**
 * @brief Renders an individual weapon.
 *
 *    @param w Weapon to render.
 *    @param dt Current delta tick.
 */
static void weapon_render( Weapon* w, const double dt )
{
   double x,y, cx,cy, gx,gy;
   glTexture *gfx;
   double z;
   glColour c = { .r=1., .g=1., .b=1. };

   switch (w->outfit->type) {
      /* Weapons that use sprites. */
      case OUTFIT_TYPE_AMMO:
      case OUTFIT_TYPE_TURRET_AMMO:
      case OUTFIT_TYPE_BOLT:
      case OUTFIT_TYPE_TURRET_BOLT:
         gfx = outfit_gfx(w->outfit);

         /* Alpha based on strength. */
         c.a = w->strength;

         /* Outfit spins around. */
         if (outfit_isProp(w->outfit, OUTFIT_PROP_WEAP_SPIN)) {
            /* Check timer. */
            w->anim -= dt;
            if (w->anim < 0.) {
               w->anim = outfit_spin(w->outfit);

               /* Increment sprite. */
               w->sprite++;
               if (w->sprite >= gfx->sx*gfx->sy)
                  w->sprite = 0;
            }

            /* Render. */
            if (outfit_isBolt(w->outfit) && w->outfit->u.blt.gfx_end)
               gl_blitSpriteInterpolate( gfx, w->outfit->u.blt.gfx_end,
                     w->timer / w->life,
                     w->solid->pos.x, w->solid->pos.y,
                     w->sprite % (int)gfx->sx, w->sprite / (int)gfx->sx, &c );
            else
               gl_blitSprite( gfx, w->solid->pos.x, w->solid->pos.y,
                     w->sprite % (int)gfx->sx, w->sprite / (int)gfx->sx, &c );
         }
         /* Outfit faces direction. */
         else {
            if (outfit_isBolt(w->outfit) && w->outfit->u.blt.gfx_end)
               gl_blitSpriteInterpolate( gfx, w->outfit->u.blt.gfx_end,
                     w->timer / w->life,
                     w->solid->pos.x, w->solid->pos.y, w->sx, w->sy, &c );
            else
               gl_blitSprite( gfx, w->solid->pos.x, w->solid->pos.y, w->sx, w->sy, &c );
         }
         break;

      /* Beam weapons. */
      case OUTFIT_TYPE_BEAM:
      case OUTFIT_TYPE_TURRET_BEAM:
         gfx = outfit_gfx(w->outfit);

         /* Zoom. */
         gl_cameraZoomGet( &z );

         /* Position. */
         gl_cameraGet( &cx, &cy );
         gui_getOffset( &gx, &gy );
         x = (w->solid->pos.x - cx)*z + gx;
         y = (w->solid->pos.y - cy)*z + gy;

         /* Set up the matrix. */
         glMatrixMode(GL_PROJECTION);
         glPushMatrix();
            glTranslated( x, y, 0. );
            glRotated( 270. + w->solid->dir / M_PI * 180., 0., 0., 1. );

         /* Preparatives. */
         glEnable(GL_TEXTURE_2D);
         glBindTexture( GL_TEXTURE_2D, gfx->texture);
         glShadeModel(GL_SMOOTH);

         /* Actual rendering. */
         glBegin(GL_QUAD_STRIP);

            /* Start faded. */
            ACOLOUR(cWhite, 0.);

            glTexCoord2d( w->anim, 0. );
            glVertex2d( -gfx->sh/2.*z, 0. );

            glTexCoord2d( w->anim, 1. );
            glVertex2d( +gfx->sh/2.*z, 0. );

            /* Full strength. */
            COLOUR(cWhite);

            glTexCoord2d( w->anim + 10. / gfx->sw, 0. );
            glVertex2d( -gfx->sh/2.*z, 10.*z );

            glTexCoord2d( w->anim + 10. / gfx->sw, 1. );
            glVertex2d( +gfx->sh/2.*z, 10.*z );

            glTexCoord2d( w->anim + 0.8*w->outfit->u.bem.range / gfx->sw, 0. );
            glVertex2d( -gfx->sh/2.*z, 0.8*w->outfit->u.bem.range*z );

            glTexCoord2d( w->anim + 0.8*w->outfit->u.bem.range / gfx->sw, 1. );
            glVertex2d( +gfx->sh/2.*z, 0.8*w->outfit->u.bem.range*z );

            /* Fades out. */
            ACOLOUR(cWhite, 0.);

            glTexCoord2d( w->anim + w->outfit->u.bem.range / gfx->sw, 0. );
            glVertex2d( -gfx->sh/2.*z, w->outfit->u.bem.range*z );

            glTexCoord2d( w->anim + w->outfit->u.bem.range / gfx->sw, 1. );
            glVertex2d( +gfx->sh/2.*z, w->outfit->u.bem.range*z );
         glEnd(); /* GL_QUAD_STRIP */

         /* Do the beam movement. */
         w->anim -= 5. * dt;
         if (w->anim <= -gfx->sw)
            w->anim += gfx->sw;

         /* Clean up. */
         glDisable(GL_TEXTURE_2D);
         glShadeModel(GL_FLAT);
         glPopMatrix(); /* GL_PROJECTION */
         gl_checkErr();
         break;

      default:
         WARN("Weapon of type '%s' has no render implemented yet!",
               w->outfit->name);
         break;
   }
}


/**
 * @brief Checks to see if the weapon can hit the pilot.
 *
 *    @param w Weapon to check if hits pilot.
 *    @param p Pilot to check if is hit by weapon.
 *    @return 1 if can be hit, 0 if can't.
 */
static int weapon_checkCanHit( Weapon* w, Pilot *p )
{
   Pilot *parent;

   /* Can't hit invincible stuff. */
   if (pilot_isFlag(p, PILOT_INVINCIBLE))
      return 0;

   /* Can never hit same faction. */
   if (p->faction == w->faction)
      return 0;

   /* Go "through" dead pilots. */
   if (pilot_isFlag(p, PILOT_DEAD))
      return 0;

   /* Player behaves differently. */
   if (w->faction == FACTION_PLAYER) {

      /* Always hit without safety. */
      if (!weapon_safety)
         return 1;

      /* Always hit target. */
      else if (w->target == p->id)
         return 1;

      /* Always hit hostiles. */
      else if (pilot_isFlag(p, PILOT_HOSTILE))
         return 1;

      /* Always hit unbribed enemies. */
      else if (!pilot_isFlag(p, PILOT_BRIBED) &&
            areEnemies(w->faction, p->faction))
        return 1;

      /* Miss rest - can be neutral/ally. */
      else
         return 0;
   }

   /* Let hostiles hit player. */
   if (p->faction == FACTION_PLAYER) {
      parent = pilot_get(w->parent);
      if (parent != NULL) {
         if (pilot_isFlag(parent, PILOT_BRIBED))
            return 0;
         if (pilot_isFlag(parent, PILOT_HOSTILE))
            return 1;
      }
   }

   /* Hit non-allies. */
   if (areEnemies(w->faction, p->faction))
      return 1;

   return 0;
}
Example #15
0
/* Checks whether a move is valid, except for whether this puts own king in check. */
static int move_is_semi_valid(board_t *board, move_t *move)
{
    /* Bounds check. */
    if ((move->source > 63) || (move->source < 0))
        return 0;

    if ((move->destination > 63) || (move->destination < 0))
        return 0;

    /* Test for moving to same square. */
    if (move->source == move->destination)
        return 0;

    /* Test for empty source square. */
    if (board->square[move->source] == NONE)
        return 0;

    /* Test for moving opponent's piece. */
    if (COLOUR(board->square[move->source]) != board->turn)
        return 0;

    /* Check that a promotion piece is specified for promotion moves. */
    if ((PIECE(board->square[move->source]) == PAWN) && ((move->destination < 8) || (move->destination >= 56)))
    {
        switch (PIECE(move->promotion_piece))
        {
        case KNIGHT:
        case ROOK:
        case BISHOP:
        case QUEEN:
            break;
        default:
            return 0;
        }

        if (COLOUR(move->promotion_piece) != board->turn)
            return 0;
    }
    else if (move->promotion_piece != NONE)
        /* Promotion piece specified for non-promotion move. */
        return 0;

    switch (PIECE(board->square[move->source]))
    {
    case KNIGHT:
        if ((HOR != 1) && (HOR != 2))
            return 0;
        if ((HOR == 1) && (VERT != 2))
            return 0;
        if ((HOR == 2) && (VERT != 1))
            return 0;
        if (board->square[move->destination] == NONE)
            break;
        if (COLOUR(board->square[move->destination]) == COLOUR(board->square[move->source]))
            return 0;
        break;
    case BISHOP:
        if (HOR != VERT)
            return 0;
        if (!ray_ok(board, move))
            return 0;
        break;
    case ROOK:
        if ((HOR != 0) && (VERT != 0))
            return 0;
        if (!ray_ok(board, move))
            return 0;
        break;
    case QUEEN:
        if ((HOR != 0) && (VERT != 0) && (HOR != VERT))
            return 0;
        if (!ray_ok(board, move))
            return 0;
        break;
    case PAWN:
        /* Catch moves in wrong direction. */
        if ((move->destination > move->source) && (COLOUR(board->square[move->source]) == BLACK))
            return 0;
        if ((move->destination < move->source) && (COLOUR(board->square[move->source]) == WHITE))
            return 0;

        if (HOR > 1)
            return 0;

        if (HOR == 0)
        {
            /* Regular or double push. */

            if (VERT > 2)
                return 0;
            if (VERT == 2)
                if (!(((move->source >= 8) && (move->source <= 15)) || ((move->source >= 48) && (move->source <= 55))))
                    return 0;
            /* Use ray checking code with added requirement that destination square is empty. */
            if (!ray_ok(board, move) || (board->square[move->destination] != NONE))
                return 0;
        }
        else
        {
            if (VERT != 1)
                return 0;
            if (!ray_ok(board, move))
                return 0;
            /* En-passant move. */
            if (board->square[move->destination] == NONE)
            {
                if ((COLOUR(board->square[move->source]) == WHITE) && !((move->source >= 32) && (move->source < 40)))
                    return 0;
                if ((COLOUR(board->square[move->source]) == BLACK) && !((move->source >= 24) && (move->source < 32)))
                    return 0;

                if (board->square[move->destination + (COLOUR(board->square[move->source]) == WHITE ? -8 : 8)] !=
                        PAWN + OPPONENT(COLOUR(board->square[move->source])))
                    return 0;
            }

        }
        break;
    case KING:
        if (HOR > 2)
            return 0;
        else if (HOR == 2)
        {
            int white = COLOUR(board->square[move->source]) == WHITE;

            int i, step = (move->destination > move->source ? 1 : -1);
            int rook = (step == 1 ? (white ? 7 : 63) : (white ? 0 : 56));

            /* Castling. */
            if (VERT != 0)
                return 0;

            if (move->source != (white ? 4 : 60))
                return 0;

            if (board->square[rook] != ROOK + COLOUR(board->square[move->source]))
                return 0;

            i = move->source + step;

            while (i != rook)
            {
                if (board->square[i] != NONE)
                    return 0;
                i += step;
            }

            /* Check whether any of the squares the king moves over is under
            ** attack. Note that destination square is checked later.
            */
            if (square_attacked(board, move->source, (white ? BLACK : WHITE)))
                return 0;
            if (square_attacked(board, move->source + step, (white ? BLACK : WHITE)))
                return 0;
        }
        else
        {
            if (VERT > 1)
                return 0;
            if (!ray_ok(board, move))
                return 0;
        }
    }
    return 1;
}
Example #16
0
static bitboard getAttackRange(const int piece, const int type, const int sq, const bitboard allPieces, const int epSquare)
{
    bitboard attackRange = 0;
    int state = 0;
    int rank;
    int file;
    bitboard rotAllPieces = 0;
    bitboard rot_a1h8_allPieces = 0;
    bitboard rot_h1a8_allPieces = 0;
    const bitboard *table1 = 0;
    const bitboard *table2 = 0;
    const bitboard *table_attack = 0;
    /* supports only normal and capture */
    assert(NORMAL == type || CAPTURE == type);
    if(IS_KING(piece)) {
        attackRange = _king[sq];
    }
    else if(IS_PAWN(piece)) {
        if(WHITE == COLOUR(piece)) {
            table1 = _wpawn_advance1;
            table2 = _wpawn_advance2;
            table_attack = _wpawn_attack;
        }
        else {
            table1 = _bpawn_advance1;
            table2 = _bpawn_advance2;
            table_attack = _bpawn_attack;
        }
        if(NORMAL == type) {
            attackRange = table1[sq] & ~allPieces;
            if(attackRange) {
                attackRange |= table2[sq] & ~allPieces;
            }
        }
        else { /* capture */
            attackRange = table_attack[sq];
            /* check for ep */
            if(epSquare != -1) {
                if(table_attack[sq] & _mask[epSquare]) {
                    attackRange |= _mask[epSquare];
                }
            }
        }
    }
    else if(IS_KNIGHT(piece)) {
        attackRange = _knight[sq];
    }
    else if(IS_BISHOP(piece)) {
        rot_a1h8_allPieces = rotate_a1h8(allPieces);
        state = A1H8_STATE(rot_a1h8_allPieces, sq);
        attackRange = _a1h8[sq][state];
        rot_h1a8_allPieces = rotate_h1a8(allPieces);
        state = H1A8_STATE(rot_h1a8_allPieces, sq);
        attackRange |= _h1a8[sq][state];
    }
    else if(IS_ROOK(piece)) {
        rank = sq / 8;
        file = sq % 8;
        state = RANK_STATE(allPieces, rank);
        attackRange = _horz[sq][state];
        rotAllPieces = rotate(allPieces);
        state = FILE_STATE(rotAllPieces, file);
        attackRange |= _vert[sq][state];
    }
    else if(IS_QUEEN(piece)) {
        /* rook like moves */
        rank = sq / 8;
        file = sq % 8;
        state = RANK_STATE(allPieces, rank);
        attackRange = _horz[sq][state];
        rotAllPieces = rotate(allPieces);
        state = FILE_STATE(rotAllPieces, file);
        attackRange |= _vert[sq][state];
        /* bishop like moves */
        rot_a1h8_allPieces = rotate_a1h8(allPieces);
        state = A1H8_STATE(rot_a1h8_allPieces, sq);
        attackRange |= _a1h8[sq][state];
        rot_h1a8_allPieces = rotate_h1a8(allPieces);
        state = H1A8_STATE(rot_h1a8_allPieces, sq);
        attackRange |= _h1a8[sq][state];
    }
    else {
        /* Something is wrong, I don't know which piece this is.
         * This must NEVER happen; move generation is screwed.
         */
        assert(0);
    }
    return attackRange;
}
Example #17
0
static void clearCapturedPiece(position *pos, const move * const m)
{
    int piece;
    int colour;
    int castleBits;

    /*
        ep is handled in movePiece(...) method and not here
        this only handles the "simple" capture
        TODO: change later?
     */
    piece = m->capturedPiece;
    colour = COLOUR(piece);
    assert(!IS_KING(piece));
    /* clear all pieces bitboard */
    CLR_BIT(pos->pieces[colour], m->to);
    /*
        Do NOT set m->to to 0, as board[m->to] contains the moved piece!
        Just update the bitboards.
     */
    if(IS_PAWN(piece)) {
        CLR_BIT(pos->pawns[colour], m->to);
    }
    else if(IS_KNIGHT(piece)) {
        CLR_BIT(pos->knights[colour], m->to);
    }
    else if(IS_BISHOP(piece)) {
        CLR_BIT(pos->bishops[colour], m->to);
    }
    else if(IS_ROOK(piece)) {
        CLR_BIT(pos->rooks[colour], m->to);
    }
    else if(IS_QUEEN(piece)) {
        CLR_BIT(pos->queens[colour], m->to);
    }
    else {
        /* Something is wrong, I don't know which piece this is.
         * This must NEVER happen; move generation is screwed.
         */
        assert(0);
    }

    /* check if rook square has been captured and disable castling */
    if(m->to == 0) {
        castleBits = CASTLE_WK;
        pos->castleFlags &= ~castleBits;
    }
    else if(m->to == 7) {
        castleBits = CASTLE_WQ;
        pos->castleFlags &= ~castleBits;

    }
    else if(m->to == 56) {
        castleBits = CASTLE_BK;
        pos->castleFlags &= ~castleBits;

    }
    else if(m->to == 63) {
        castleBits = CASTLE_BQ;
        pos->castleFlags &= ~castleBits;

    }

}
Example #18
0
const char *Console::ColourToString(char IRCColour)
{
	switch (IRCColour)
	{
		case '0':
			return COLOUR(COMBINE(LIGHT, WHITE));
		case '1':
			return COLOUR(COMBINE(DARK, BLACK));
		case '2':
			return COLOUR(COMBINE(LIGHT, RED));
		case '3':
			return COLOUR(BROWN);
		case '4':
			return COLOUR(COMBINE(LIGHT, BROWN));
		case '5':
			return COLOUR(COMBINE(LIGHT, GREEN));
		case '6':
		case '7':
			return COLOUR(GREEN);
		case '8':
			return COLOUR(COMBINE(LIGHT, CYAN));
		case '9':
			return COLOUR(COMBINE(LIGHT, BLUE));
		case ':':
			return COLOUR(BLUE);
		case ';':
			return COLOUR(MAGENTA);
		case '<':
		case '=':
			return COLOUR(COMBINE(LIGHT, MAGENTA));
		case '>':
			return COLOUR(WHITE);
		case '?':
			return COLOUR(COMBINE(DARK, WHITE));
		case '@':
			return COLOUR(COMBINE(DARK, RED));
		case 'A':
			return COLOUR(COMBINE(DARK, BROWN));
		case 'B':
			return COLOUR(BROWN);
		case 'C':
		case 'D':
		case 'E':
			return COLOUR(COMBINE(DARK, GREEN));
		case 'F':
			return COLOUR(COMBINE(DARK, CYAN));
		case 'G':
		case 'H':
			return COLOUR(COMBINE(DARK, BLUE));
		case 'I':
		case 'J':
		case 'K':
			return COLOUR(COMBINE(DARK, MAGENTA));
	}
	return "\x1B[0m";
}
Example #19
0
// prints each series in the hash, also stores a pointer 
// for each series indexed by the order printed in eps_ptr
static void print_menu(Eps** eps_ptr, Eps *hash ) {
	
	sqlite3 *db;
	int result;
	
	result = sqlite3_open(DATABASE, &db);
	if( result ) {
		efprintf("show_menu failed: %s\n", sqlite3_errmsg(db));
		sqlite3_close(db);
		exit(23);
	}
	
	sqlite3_stmt *statement_h;
	const char *query_h = "select current from SeriesData where Title = ?";
	sqlite3_prepare_v2(db, query_h, (int) strlen(query_h), &statement_h, NULL);
	
	int index =0;
	// Prints each series of a separate row
	for(Eps *e=hash; e != NULL; e=e->hh.next, ++index) {
		
		// uses a array indexing index to series then use that to select the right series
		eps_ptr[index] =  e;
		bool ordered = true;
		
		qsort_b(e->eps->arr, e->eps->index, sizeof(size_t),
				^(const void *a, const void *b){
					const Ep *ea = *((Ep**)a), *eb = *((Ep**)b);
					mmprintf("%ld %ld res: %d\n", ea->num, eb->num, longcmp( ea->num, eb->num ) );
					return longcmp( ea->num , eb->num );
				}
				);
		
		
		if (e->eps->index > 1){
			for(int i = 0; i<e->eps->index-1;i++){
				if (EPS_ARR(e,i+1)->num != 1 + EPS_ARR(e,i)->num){
					ordered = false;
					break;
				}
			}
			
		}
		
		sqlite3_bind_text(statement_h, 1, e->series, -1, SQLITE_TRANSIENT);
		result = sqlite3_step(statement_h);
		mmprintf("r:%i Row:%i Ok:%i done:%i \n", result, SQLITE_ROW, SQLITE_OK, SQLITE_DONE );
		
		int current =-1;
		if (result == SQLITE_ROW||  result == SQLITE_OK  || result == SQLITE_DONE){
			
			current = sqlite3_column_int(statement_h, 0);
			mmprintf("current:%d\n",current );			
			
		}else{
			efprintf(  "SQL error %s : %s\n", e->series, sqlite3_errmsg(db));
			exit(12);
		}
		
			
		// Printing
		
		printf( SSS("%-2d") " :", COLOUR(index,GREEN));
		printf(" P: " SSS("%-2d"), COLOUR(current,WHITE));
		printf(" N: ");
		
		if (ordered && e->eps->index > 1 ){ // Range of eps
			printf(SSS("%4ld") SSS("-%-4ld"), 
				   COLOUR(EPS_ARR(e,0)->num, BLUE), COLOUR(EPS_ARR(e,e->eps->index-1)->num,BLUE)
				   );
			
		}else if (e->eps->index == 1){ // single ep
			const int extra = (3-1)*3;
			printf(SSS("%2ld") " %*s", COLOUR(EPS_ARR(e,0)->num, YELLOW), extra,"" );
			
		}else{ // range with eps missing (only shows the fist three)	
			const int min =  e->eps->index < 3 ? e->eps->index :3;
			const int extra = (3-min)*3;
			for(int i = 0; i<min;i++){
				printf(SSS("%2ld") " %*s", COLOUR(EPS_ARR(e,i)->num, RED), extra,"" );
			}
		}
		
		printf(" %s\n", e->series);
		result = sqlite3_reset(statement_h);
    }
Example #20
0
gg_dialog_t *dialog_saveload_create(gg_dialog_t *parent, int saving)
{
    gg_widget_t *dialog;
    gg_widget_t *rootvbox = gg_vbox_create(0);
    gg_widget_t *vbox = gg_vbox_create(0);
    gg_widget_t *hbox = gg_vbox_create(0);
    gg_widget_t *hboxtemp;
    gg_widget_t *widget;
    char temp[80];
    char whiteis[80], blackis[80];
    int i=0,j=0;
    int padding=0;

    change_saving=saving;

    if ( !changing_slot )
        saveload_selected=0;

    /*DBG_LOG( "dialog opened with saveselected of %i", saveload_selected );*/

    /* Right side.. */
    if (!changing_slot)
    {
#ifdef _arch_dreamcast
        dc_restore_savegames();
#endif
        for ( i=0; i<SAVEGAME_SLOTS; i++ )
            load_save_xml( i );
    }

    if ( get_slots() & (1 << saveload_selected) )
    {
        gg_widget_t *board_box = gg_vbox_create(0);

        sprintf( temp, "Saved: %s", get_time_save(saveload_selected) );
        widget = gg_label_create(temp);
        gg_container_append(GG_CONTAINER(vbox), widget);

        switch ( get_config_save(saveload_selected)->player[WHITE] )
        {
        case PLAYER_ENGINE:
            sprintf( whiteis, "CPU" );
            break;
        case PLAYER_UI:
            sprintf( whiteis, "Human" );
            break;
        default:
            /* Whoops */
            sprintf( whiteis, "Oh no.." );
            break;
        }

        switch ( get_config_save(saveload_selected)->player[BLACK] )
        {
        case PLAYER_ENGINE:
            sprintf( blackis, "CPU" );
            break;
        case PLAYER_UI:
            sprintf( blackis, "Human" );
            break;
        default:
            /* Whoops */
            sprintf( blackis, "Oh no.." );
            break;
        }

        sprintf( temp, "%s vs %s", whiteis, blackis );
        widget = gg_label_create(temp);
        gg_container_append(GG_CONTAINER(vbox), widget);

        sprintf( temp, "Difficulty: %s",
            get_config_save(saveload_selected)->difficulty ? "Normal" : "Easy" );
        widget = gg_label_create(temp);
        gg_container_append(GG_CONTAINER(vbox), widget);

        sprintf( temp, "Level: %i",
            get_config_save(saveload_selected)->cpu_level );
        widget = gg_label_create(temp);
        gg_container_append(GG_CONTAINER(vbox), widget);

        widget = gg_label_create(" ");
        gg_container_append(GG_CONTAINER(vbox), widget);

        /* create board.. */

        for ( i=7; i>=0; i-- )
        {
            gg_widget_t *hboxtemp2;
            gg_colour_t col_white =
                {
                    1.0f, 1.0f, 1.0f, 1.0f
                };
            /*gg_colour_t col_grey =
                {
                    0.3f, 0.3f, 0.3f, 1.0f
                };*/
            hboxtemp = gg_hbox_create(0);
            hboxtemp2 = gg_hbox_create(0);
            gg_set_requested_size(hboxtemp2, 20, 20);
            gg_container_append(GG_CONTAINER(hboxtemp), hboxtemp2);

            for ( j=0; j<8; j++ )
            {
                gg_colour_t col_green = {0.5, 0.6, 0.5, 1.0};
                gg_colour_t col_yellow = {0.8, 0.7, 0.4, 1.0};
                gg_colour_t front, *back;
                int square = get_saved_board(saveload_selected)->square[i * 8 + j];

                sprintf(temp, "%c", xmlsquaretofont(square));
                widget = gg_label_create( temp );
                gg_set_requested_size(widget, 20, 20);
                gg_align_set_alignment(GG_ALIGN(widget), 0.5, 0.5);

                if (COLOUR(square) == WHITE)
                    front = col_white;
                else
                    front = *get_col(COL_BLACK);

                if ((i + j) % 2 == 0)
                    back = &col_green;
                else
                    back = &col_yellow;

                /* FIXME Hack to turn off shadow */
                front.a = 2.0f;

                gg_label_set_colour(GG_LABEL(widget), &front, back);
                gg_container_append(GG_CONTAINER(hboxtemp), widget);
            }
            gg_container_append(GG_CONTAINER(board_box), hboxtemp);
        }
        gg_container_append(GG_CONTAINER(vbox), board_box);
    }
    else
    {
        sprintf( temp, "Empty slot" );
        widget = gg_label_create(temp);
        gg_container_append(GG_CONTAINER(vbox), widget);

        for ( i=0; i<12; i++ )
        {
            widget = gg_label_create(" ");
            gg_container_append(GG_CONTAINER(vbox), widget);
        }
    }
    gg_set_requested_size(vbox, 201, 0);
    gg_container_append(GG_CONTAINER(hbox), gg_frame_create(vbox));

    /* left side */
    vbox = gg_vbox_create(0);
    /* padding.. */
    for ( i=0; i<padding; i++ )
    {
        widget = gg_label_create(" ");
        gg_container_append(GG_CONTAINER(vbox), widget);
    }

    widget = gg_option_create();
    for ( i=0; i<SAVEGAME_SLOTS; i++ )
    {
        sprintf( temp, "Save slot: %i", i+1 );
        gg_option_append_label(GG_OPTION(widget), temp, 0.5f, 0.0f);
    }
    gg_widget_subscribe_signal_name(widget, widget->id, "option_changed", 
        dialog_saveload_change, widget);
    gg_container_append(GG_CONTAINER(vbox), widget);

    if ( changing_slot )
        gg_option_set_selected(GG_OPTION(widget), saveload_selected);

    if ( saving )
    {
        widget = gg_action_create_with_label("Save Game", 0.5f, 0.0f);
        gg_widget_subscribe_signal_name(widget, widget->id, "action_pressed", 
            dialog_savegame_save, vbox);
    }
    else
    {
        widget = gg_action_create_with_label("Load Game", 0.5f, 0.0f);
        gg_widget_subscribe_signal_name(widget, widget->id, "action_pressed", 
            dialog_loadgame_load, vbox);
    }
    gg_container_append(GG_CONTAINER(vbox), widget);

    widget = gg_action_create_with_label("Cancel", 0.5f, 0.0f);
    gg_widget_subscribe_signal_name(widget, widget->id, "action_pressed", 
        dialog_close_cb, NULL);
    gg_container_append(GG_CONTAINER(vbox), widget);

    /*for ( i=0; i<SAVEGAME_SLOTS; i++ )
    {
        sprintf( temp, "%i:  ", i );
        widget = gg_action_create_with_label(temp, 0.0f, 0.0f);

        gg_action_set_callback(GG_ACTION(widget), dialog_saveload_change, vbox);

        gg_container_append(GG_CONTAINER(vbox), widget);
    }*/

    gg_container_append(GG_CONTAINER(hbox), vbox );

    if ( changing_slot )
        gg_vbox_set_selected(vbox, padding );

    /* Dialog stuff */
    gg_container_append(GG_CONTAINER(rootvbox), hbox);
    dialog = gg_dialog_create(rootvbox, NULL, parent, GG_DIALOG_AUTOHIDE_PARENT);

    if ( saving )
        gg_dialog_set_style(GG_DIALOG(dialog), get_ingame_style());
    else
        gg_dialog_set_style(GG_DIALOG(dialog), get_menu_style());

    return GG_DIALOG(dialog);
}
Example #21
0
File: map.c Project: 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 );
   }
}