From 77afa506e470938b819dfaf203cd6706ac483298 Mon Sep 17 00:00:00 2001 From: Allanis Date: Sat, 15 Mar 2014 17:42:10 +0000 Subject: [PATCH] [Add] Added an indication on minimap as to where targeted planets reside. --- src/colour.c | 8 +++++--- src/colour.h | 3 ++- src/map.c | 5 +++-- src/physics.h | 2 +- src/player.c | 4 ++-- src/space.c | 40 +++++++++++++++++++++++++++++++++++++--- 6 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/colour.c b/src/colour.c index 7e53257..74d3a0c 100644 --- a/src/colour.c +++ b/src/colour.c @@ -38,9 +38,11 @@ glColour cNeutral = { .r = 0.9, .g = 1.0, .b = 0.3, .a = 1. }; /**< Neutra glColour cFriend = { .r = 0.0, .g = 1.0, .b = 0.0, .a = 1. }; /**< Friend object colour. */ glColour cHostile = { .r = 0.9, .g = 0.2, .b = 0.2, .a = 1. }; /**< Hostile object colour. */ /* Radar */ -glColour cRadar_player = { .r = 0.4, .g = 0.8, .b = 0.4, .a = 1. }; /**< Player colour on radar. */ -glColour cRadar_targ = { .r = 0.0, .g = 0.7, .b = 1.0, .a = 1. }; /**< Targetted object colour.*/ -glColour cRadar_weap = { .r = 0.8, .g = 0.2, .b = 0.2, .a = 1. }; /**< Weapon colour on radar. */ +glColour cRadar_player = { .r = 0.4, .g = 0.8, .b = 0.4, .a = 1. }; /**nplanets == 0)) col = &cInert; else col = faction_getColour(sys->faction); COLOUR(*col); diff --git a/src/physics.h b/src/physics.h index 5d557b5..403b244 100644 --- a/src/physics.h +++ b/src/physics.h @@ -8,7 +8,7 @@ #define VANGLE(v) ((v).angle) #define MOD(x,y) (sqrt((x)*(x) + (y)*(y))) -#define ANGLE(x,y) (((x)==0.) ? 0. : atan2(y,x)) +#define ANGLE(x,y) (atan2(y,x)) #define vect_dist(v,u) MOD((v)->x-(u)->x, (v)->y-(u)->y) #define vect_odist(v) MOD((v)->x, (v)->y) diff --git a/src/player.c b/src/player.c index 8c79925..deb2bba 100644 --- a/src/player.c +++ b/src/player.c @@ -1186,7 +1186,7 @@ static void gui_renderPilot(const Pilot* p) { sx = 0.85 * x; sy = 0.85 * y; - COLOUR(cRadar_targ); + COLOUR(cRadar_tPilot); glBegin(GL_LINES); glVertex2d(x, y); glVertex2d(sx, sy); @@ -1207,7 +1207,7 @@ static void gui_renderPilot(const Pilot* p) { glBegin(GL_QUADS); /* Colours. */ - if(p->id == player->target) col = &cRadar_targ; + if(p->id == player->target) col = &cRadar_tPilot; else if(pilot_isDisabled(p)) col = &cInert; else if(pilot_isFlag(p, PILOT_BRIBED)) col = &cNeutral; else if(pilot_isFlag(p, PILOT_HOSTILE)) col = &cHostile; diff --git a/src/space.c b/src/space.c index 921e208..186ae91 100644 --- a/src/space.c +++ b/src/space.c @@ -78,6 +78,8 @@ static Star* stars = NULL; /* Star array. */ static int nstars = 0; /* Total stars. */ static int mstars = 0; /* Memory stars are taking. */ +extern int planet_target; /* player.c */ + /* Intern. */ /* Planet load. */ static int planet_parse(Planet* planet, const xmlNodePtr parent); @@ -107,28 +109,60 @@ void planets_minimap(const double res, const double w, int i; int cx, cy, x, y, r, rc; double p; + double a, tx, ty; Planet* planet; glColour* col; if(shape == RADAR_CIRCLE) rc = (int)(w*w); - glBegin(GL_POINTS); for(i = 0; i < cur_system->nplanets; i++) { planet = cur_system->planets[i]; + /* Get the colour. */ col = faction_getColour(planet->faction); - if((col != &cHostile) && !planet_hasService(planet, PLANET_SERVICE_BASIC)) + if(i == planet_target) + col = &cRadar_tPlanet; + else if((col != &cHostile) && !planet_hasService(planet, PLANET_SERVICE_BASIC)) col = &cInert; /* Override non-hostile planets without services. */ COLOUR(*col); + /* Some parameters. */ r = (int)(cur_system->planets[i]->gfx_space->sw / res); cx = (int)((cur_system->planets[i]->pos.x - player->solid->pos.x) / res); cy = (int)((cur_system->planets[i]->pos.y - player->solid->pos.y) / res); + /* Check if in range. */ + if(shape == RADAR_RECT) { + /* Out of range. */ + if((ABS(cx) - r> 2/2.) || (ABS(cy) - r > h/2.)) + continue; + } + else if(shape == RADAR_CIRCLE) { + x = cx-r; + y = cy-r; + /* Out of range. */ + if(x*x + y*y > rc) { + if(planet_target == i) { + /* Draw a line like the one for pilots. */ + a = ANGLE(cx, cy); + tx = w*cos(a); + ty = w*sin(a); + + COLOUR(cRadar_tPlanet); + glBegin(GL_LINES); + glVertex2d( tx, ty ); + glVertex2d( 0.85*tx, 0.85*ty); + glEnd(); + } + continue; + } + } x = 0; y = r; p = (5. - (double)(r*3)) / 4.; + glBegin(GL_POINTS); + PIXEL(cx, cy+y); PIXEL(cx, cy-y); PIXEL(cx+y, cy); @@ -162,8 +196,8 @@ void planets_minimap(const double res, const double w, PIXEL(cx-y, cy-x); } } + glEnd(); } - glEnd(); } #undef PIXEL