[Add] Map now displays faction standing of star system.
This commit is contained in:
parent
b65385a1bd
commit
8ef0ada807
@ -23,8 +23,11 @@
|
|||||||
typedef struct Faction_ {
|
typedef struct Faction_ {
|
||||||
char* name;
|
char* name;
|
||||||
|
|
||||||
|
/* Enemies. */
|
||||||
int* enemies;
|
int* enemies;
|
||||||
int nenemies;
|
int nenemies;
|
||||||
|
|
||||||
|
/* Allies. */
|
||||||
int* allies;
|
int* allies;
|
||||||
int nallies;
|
int nallies;
|
||||||
|
|
||||||
@ -116,6 +119,34 @@ int faction_getPlayer(int f) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return the players standing. */
|
||||||
|
static char* player_standings[] = {
|
||||||
|
"Hero", /* 0 */
|
||||||
|
"Admired",
|
||||||
|
"Great",
|
||||||
|
"Good",
|
||||||
|
"Decent",
|
||||||
|
"Wanted", /* 5 */
|
||||||
|
"Outlaw",
|
||||||
|
"Criminal",
|
||||||
|
"Enemy"
|
||||||
|
};
|
||||||
|
|
||||||
|
#define STANDING(m, i) if(mod >= m) return player_standings[i];
|
||||||
|
char* faction_getStanding(int mod) {
|
||||||
|
STANDING( 90, 0);
|
||||||
|
STANDING( 70, 1);
|
||||||
|
STANDING( 50, 2);
|
||||||
|
STANDING( 30, 3);
|
||||||
|
STANDING( 0, 4);
|
||||||
|
STANDING(-15, 5);
|
||||||
|
STANDING(-30, 6);
|
||||||
|
STANDING(-50, 7);
|
||||||
|
return player_standings[8];
|
||||||
|
|
||||||
|
}
|
||||||
|
#undef STANDING
|
||||||
|
|
||||||
/* Return 1 if Faction a and b are enemies. */
|
/* Return 1 if Faction a and b are enemies. */
|
||||||
int areEnemies(int a, int b) {
|
int areEnemies(int a, int b) {
|
||||||
Faction* fa, *fb;
|
Faction* fa, *fb;
|
||||||
|
@ -10,6 +10,7 @@ char* faction_name(int f);
|
|||||||
/* Player stuff. */
|
/* Player stuff. */
|
||||||
void faction_modPlayer(int f, int mod);
|
void faction_modPlayer(int f, int mod);
|
||||||
int faction_getPlayer(int f);
|
int faction_getPlayer(int f);
|
||||||
|
char* faction_getStanding(int mod);
|
||||||
|
|
||||||
/* Works with only factions. */
|
/* Works with only factions. */
|
||||||
int areEnemies(int a, int b);
|
int areEnemies(int a, int b);
|
||||||
|
68
src/map.c
68
src/map.c
@ -65,19 +65,44 @@ void map_open(void) {
|
|||||||
|
|
||||||
map_wid = window_create("Star Map", -1, -1, WINDOW_WIDTH, WINDOW_HEIGHT);
|
map_wid = window_create("Star Map", -1, -1, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SIDE TEXT
|
||||||
|
*
|
||||||
|
* $System
|
||||||
|
*
|
||||||
|
* Faction:
|
||||||
|
* $Faction (or Multiple)
|
||||||
|
*
|
||||||
|
* Status:
|
||||||
|
* $Status
|
||||||
|
*
|
||||||
|
* Planets:
|
||||||
|
* $Planet1, $Planet2, ...
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* System name. */
|
||||||
window_addText(map_wid, -20, -20, 100, 20, 1, "txtSysname",
|
window_addText(map_wid, -20, -20, 100, 20, 1, "txtSysname",
|
||||||
&gl_defFont, &cDConsole, systems_stack[map_selected].name);
|
&gl_defFont, &cDConsole, systems_stack[map_selected].name);
|
||||||
|
|
||||||
|
/* Faction. */
|
||||||
window_addText(map_wid, -20, -60, 90, 20, 0, "txtSFaction",
|
window_addText(map_wid, -20, -60, 90, 20, 0, "txtSFaction",
|
||||||
&gl_smallFont, &cDConsole, "Faction:");
|
&gl_smallFont, &cDConsole, "Faction:");
|
||||||
|
|
||||||
window_addText(map_wid, -20, -60-gl_smallFont.h-5, 80, 100, 0, "txtFaction",
|
window_addText(map_wid, -20, -60-gl_smallFont.h-5, 80, 100, 0, "txtFaction",
|
||||||
&gl_smallFont, &cBlack, NULL);
|
&gl_smallFont, &cBlack, NULL);
|
||||||
|
|
||||||
window_addText(map_wid, -20, -110, 90, 20, 0, "txtSPlanets",
|
/* Standing. */
|
||||||
|
window_addText(map_wid, -20, -110, 90, 20, 0, "txtSStanding",
|
||||||
|
&gl_smallFont, &cDConsole, "Standing:");
|
||||||
|
|
||||||
|
window_addText(map_wid, -20, -110-gl_smallFont.h-5, 80, 100, 0, "txtStanding",
|
||||||
|
&gl_smallFont, &cBlack, NULL);
|
||||||
|
|
||||||
|
/* Planets. */
|
||||||
|
window_addText(map_wid, -20, -150, 90, 20, 0, "txtSPlanets",
|
||||||
&gl_smallFont, &cDConsole, "Planets:");
|
&gl_smallFont, &cDConsole, "Planets:");
|
||||||
|
|
||||||
window_addText(map_wid, -20, -110-gl_smallFont.h-5, 80, 100, 0, "txtPlanets",
|
window_addText(map_wid, -20, -150-gl_smallFont.h-5, 80, 100, 0, "txtPlanets",
|
||||||
&gl_smallFont, &cBlack, NULL);
|
&gl_smallFont, &cBlack, NULL);
|
||||||
|
|
||||||
window_addCust(map_wid, 20, -40, MAP_WIDTH, MAP_HEIGHT,
|
window_addCust(map_wid, 20, -40, MAP_WIDTH, MAP_HEIGHT,
|
||||||
@ -103,55 +128,64 @@ static void map_close(char* str) {
|
|||||||
static void map_update(void) {
|
static void map_update(void) {
|
||||||
int i;
|
int i;
|
||||||
StarSystem* sys;
|
StarSystem* sys;
|
||||||
int f;
|
int f, standing, nstanding;
|
||||||
char buf[100];
|
char buf[100];
|
||||||
|
|
||||||
sys = &systems_stack[map_selected];
|
sys = &systems_stack[map_selected];
|
||||||
|
|
||||||
if(!sys_isKnown(sys)) { /* System isn't known. Erase all. */
|
if(!sys_isKnown(sys)) { /* System isn't known. Erase all. */
|
||||||
window_modifyText(map_wid, "txtSysname", "Unknown");
|
window_modifyText(map_wid, "txtSysname", "Unknown");
|
||||||
window_modifyText(map_wid, "txtFaction", "Unknown");
|
window_modifyText(map_wid, "txtFaction", "Unknown");
|
||||||
window_modifyText(map_wid, "txtPlanets", "Unknown");
|
window_modifyText(map_wid, "txtStanding", "Unknown");
|
||||||
|
window_modifyText(map_wid, "txtPlanets", "Unknown");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* System is known. */
|
/* System is known. */
|
||||||
window_modifyText(map_wid, "txtSysname", sys->name);
|
window_modifyText(map_wid, "txtSysname", sys->name);
|
||||||
|
|
||||||
if(sys->nplanets == 0)
|
if(sys->nplanets == 0) { /* No planets -> no factions. */
|
||||||
/* No planets -> no factions. */
|
window_modifyText(map_wid, "txtFaction", "NA");
|
||||||
snprintf(buf, 100, "NA");
|
window_modifyText(map_wid, "txtStanding", "NA");
|
||||||
else {
|
} else {
|
||||||
|
standing = 0;
|
||||||
|
nstanding = 0;
|
||||||
f = -1;
|
f = -1;
|
||||||
for(i = 0; i < sys->nplanets; i++) {
|
for(i = 0; i < sys->nplanets; i++) {
|
||||||
if((f == -1) && (sys->planets[i].faction != 0))
|
if((f == -1) && (sys->planets[i].faction != 0)) {
|
||||||
f = sys->planets[i].faction;
|
f = sys->planets[i].faction;
|
||||||
|
standing += faction_getPlayer(f);
|
||||||
|
nstanding++;
|
||||||
|
}
|
||||||
else if(f != sys->planets[i].faction &&
|
else if(f != sys->planets[i].faction &&
|
||||||
(sys->planets[i].faction!=0)) {
|
(sys->planets[i].faction!=0)) {
|
||||||
/* TODO: more verbosity. */
|
/* TODO: more verbosity. */
|
||||||
snprintf(buf, 100, "Multiple");
|
snprintf(buf, 100, "Multiple");
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(i == sys->nplanets)
|
if(i == sys->nplanets)
|
||||||
/* Saw them all, and all the same. */
|
/* Saw them all, and all the same. */
|
||||||
snprintf(buf, 100, "%s", faction_name(f));
|
snprintf(buf, 100, "%s", faction_name(f));
|
||||||
|
|
||||||
|
/* Modify the text. */
|
||||||
|
window_modifyText(map_wid, "txtFaction", buf);
|
||||||
|
window_modifyText(map_wid, "txtStanding",
|
||||||
|
faction_getStanding(standing / nstanding));
|
||||||
}
|
}
|
||||||
|
|
||||||
window_modifyText(map_wid, "txtFaction", buf);
|
/* Get planets. */
|
||||||
|
|
||||||
buf[0] = '\0';
|
|
||||||
if(sys->nplanets == 0)
|
if(sys->nplanets == 0)
|
||||||
snprintf(buf, 100, "None");
|
window_modifyText(map_wid, "txtPlanets", "None");
|
||||||
else {
|
else {
|
||||||
|
buf[0] = '\0';
|
||||||
if(sys->nplanets > 0)
|
if(sys->nplanets > 0)
|
||||||
strcat(buf, sys->planets[0].name);
|
strcat(buf, sys->planets[0].name);
|
||||||
for(i = 1; i < sys->nplanets; i++) {
|
for(i = 1; i < sys->nplanets; i++) {
|
||||||
strcat(buf, ",\n");
|
strcat(buf, ",\n");
|
||||||
strcat(buf, sys->planets[i].name);
|
strcat(buf, sys->planets[i].name);
|
||||||
}
|
}
|
||||||
|
window_modifyText(map_wid, "txtPlanets", buf);
|
||||||
}
|
}
|
||||||
window_modifyText(map_wid, "txtPlanets", buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return 1 if sys is part of the map_path. */
|
/* Return 1 if sys is part of the map_path. */
|
||||||
|
Loading…
Reference in New Issue
Block a user