From 79411d240ec586b5471e9047c98994f950332876 Mon Sep 17 00:00:00 2001 From: Allanis Date: Fri, 9 Aug 2013 20:45:17 +0100 Subject: [PATCH] [Change] Unified colouring schemes. --- src/faction.c | 8 ++++++++ src/faction.h | 2 ++ src/map.c | 9 ++++----- src/pilot.c | 3 ++- src/pilot.h | 2 +- src/player.c | 20 +++++++++++--------- src/space.c | 14 +++++++------- 7 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/faction.c b/src/faction.c index f3b0412..f59acf2 100644 --- a/src/faction.c +++ b/src/faction.c @@ -120,6 +120,14 @@ int faction_getPlayer(int f) { } } +/* Get the colour of the faction based on its standing with the player. */ +glColour* faction_getColour(int f) { + if(f == -1) return &cInert; + else if(areAllies(FACTION_PLAYER, f)) return &cFriend; + else if(areEnemies(FACTION_PLAYER, f)) return &cHostile; + else return &cNeutral; +} + /* Return the players standing. */ static char* player_standings[] = { "Hero", /* 0 */ diff --git a/src/faction.h b/src/faction.h index cebee13..1d4002e 100644 --- a/src/faction.h +++ b/src/faction.h @@ -1,4 +1,5 @@ #pragma once +#include "colour.h" #define FACTION_PLAYER 0 @@ -11,6 +12,7 @@ char* faction_longname(int f); void faction_modPlayer(int f, int mod); int faction_getPlayer(int f); char* faction_getStanding(int mod); +glColour* faction_getColour(int f); /* Works with only factions. */ int areEnemies(int a, int b); diff --git a/src/map.c b/src/map.c index 8d64586..7aaa779 100644 --- a/src/map.c +++ b/src/map.c @@ -322,11 +322,10 @@ static void map_render(double bx, double by, double w, double h) { if(!sys_isMarked(sys) && !space_sysReachable(sys)) continue; /* System Colours. */ - if(sys == cur_system) COLOUR(cRadar_targ); - else if(!sys_isKnown(sys) || (sys->nplanets==0) || (sys->faction==-1)) - COLOUR(cInert); - else if(areEnemies(player->faction, sys->faction)) COLOUR(cRed); - else COLOUR(cYellow); + if(sys == cur_system) col = &cRadar_targ; + 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; diff --git a/src/pilot.c b/src/pilot.c index 6cab2a7..25d4e55 100644 --- a/src/pilot.c +++ b/src/pilot.c @@ -104,7 +104,8 @@ unsigned pilot_getNearestHostile(void) { tp = PLAYER_ID; d = 0; for(i = 0; i < pilot_nstack; i++) - if(pilot_isFlag(pilot_stack[i], PILOT_HOSTILE)) { + if(pilot_isFlag(pilot_stack[i], PILOT_HOSTILE) || + areEnemies(FACTION_PLAYER, pilot_stack[i]->faction)) { td = vect_dist(&pilot_stack[i]->solid->pos, &player->solid->pos); if(!pilot_isDisabled(pilot_stack[i]) && ((tp == PLAYER_ID) || (td < d))) { d = td; diff --git a/src/pilot.h b/src/pilot.h index dc26866..5afc6a6 100644 --- a/src/pilot.h +++ b/src/pilot.h @@ -71,7 +71,7 @@ typedef struct Pilot_ { char* name; /* Pilot's name (if unique). */ char* title; /* Title - Usuall indicating special properties - TODO. */ - int faction; + int faction; /* Pilot faction. */ /* Object characteristics. */ Ship* ship; /* Pilots ship. */ diff --git a/src/player.c b/src/player.c index c7c53e2..6197e0b 100644 --- a/src/player.c +++ b/src/player.c @@ -547,8 +547,7 @@ void player_renderBG(void) { if(planet_target >= 0) { planet = &cur_system->planets[planet_target]; - if(areEnemies(player->faction, planet->faction)) c = &cHostile; - else c = &cNeutral; + c = faction_getColour(planet->faction); x = planet->pos.x - planet->gfx_space->sw/2.; y = planet->pos.y + planet->gfx_space->sh/2.; @@ -581,7 +580,7 @@ void player_render(void) { /* There is still a pilot target. */ if(pilot_isDisabled(p)) c = &cInert; else if(pilot_isFlag(p, PILOT_HOSTILE)) c = &cHostile; - else c = &cNeutral; + else c = faction_getColour(p->faction); x = p->solid->pos.x - p->ship->gfx_space->sw * PILOT_SIZE_APROX/2.; y = p->solid->pos.y + p->ship->gfx_space->sh * PILOT_SIZE_APROX/2.; @@ -869,6 +868,7 @@ void player_renderGUI(void) { static void gui_renderPilot(const Pilot* p) { int x, y, sx, sy; double w, h; + glColour* col; x = (p->solid->pos.x - player->solid->pos.x) / gui.radar.res; y = (p->solid->pos.y - player->solid->pos.y) / gui.radar.res; @@ -878,8 +878,9 @@ static void gui_renderPilot(const Pilot* p) { if(sy < 1.) sy = 1.; if(((gui.radar.shape == RADAR_RECT) && ((ABS(x) > gui.radar.w/2.+sx) - || (ABS(y) > gui.radar.h/2.+sy))) || ((gui.radar.shape == RADAR_CIRCLE) && - ((x*x + y*y) > (int)(gui.radar.w*gui.radar.w)))) + || (ABS(y) > gui.radar.h/2.+sy))) || + ((gui.radar.shape == RADAR_CIRCLE) && + ((x*x + y*y) > (int)(gui.radar.w*gui.radar.w)))) return; /* Pilot isn't in range. */ if(gui.radar.shape == RADAR_RECT) { @@ -893,10 +894,11 @@ static void gui_renderPilot(const Pilot* p) { glBegin(GL_QUADS); /* Colours. */ - if(p->id == player_target) COLOUR(cRadar_targ); - else if(pilot_isDisabled(p)) COLOUR(cInert); - else if(pilot_isFlag(p, PILOT_HOSTILE)) COLOUR(cHostile); - else COLOUR(cNeutral); + if(p->id == player_target) col = &cRadar_targ; + else if(pilot_isDisabled(p)) col = &cInert; + else if(pilot_isFlag(p, PILOT_HOSTILE)) col = &cHostile; + else col = faction_getColour(p->faction); + COLOUR(*col); /* Image. */ glVertex2d(MAX(x-sx, -w), MIN(y+sy, h)); /* Top left. */ diff --git a/src/space.c b/src/space.c index f39be09..e5020df 100644 --- a/src/space.c +++ b/src/space.c @@ -93,6 +93,7 @@ void planets_minimap(const double res, const double w, int cx, cy, x, y, r, rc; double p; Planet* planet; + glColour* col; if(shape == RADAR_CIRCLE) rc = (int)(w*w); @@ -100,13 +101,12 @@ void planets_minimap(const double res, const double w, for(i = 0; i < cur_system->nplanets; i++) { planet = &cur_system->planets[i]; - if((planet->faction == -1) && !planet_hasService(planet, PLANET_SERVICE_BASIC)) - COLOUR(cInert); - else if(areEnemies(player->faction, planet->faction)) - COLOUR(cHostile); - else if(areAllies(player->faction, planet->faction)) - COLOUR(cFriend); - else COLOUR(cNeutral); + if(!planet_hasService(planet, PLANET_SERVICE_BASIC)) + col = &cInert; + else + col = faction_getColour(planet->faction); + COLOUR(*col); + 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);