[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_ {
|
||||
char* name;
|
||||
|
||||
/* Enemies. */
|
||||
int* enemies;
|
||||
int nenemies;
|
||||
|
||||
/* Allies. */
|
||||
int* allies;
|
||||
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. */
|
||||
int areEnemies(int a, int b) {
|
||||
Faction* fa, *fb;
|
||||
|
@ -10,6 +10,7 @@ char* faction_name(int f);
|
||||
/* Player stuff. */
|
||||
void faction_modPlayer(int f, int mod);
|
||||
int faction_getPlayer(int f);
|
||||
char* faction_getStanding(int mod);
|
||||
|
||||
/* Works with only factions. */
|
||||
int areEnemies(int a, int b);
|
||||
|
62
src/map.c
62
src/map.c
@ -65,19 +65,44 @@ void map_open(void) {
|
||||
|
||||
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",
|
||||
&gl_defFont, &cDConsole, systems_stack[map_selected].name);
|
||||
|
||||
/* Faction. */
|
||||
window_addText(map_wid, -20, -60, 90, 20, 0, "txtSFaction",
|
||||
&gl_smallFont, &cDConsole, "Faction:");
|
||||
|
||||
window_addText(map_wid, -20, -60-gl_smallFont.h-5, 80, 100, 0, "txtFaction",
|
||||
&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:");
|
||||
|
||||
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);
|
||||
|
||||
window_addCust(map_wid, 20, -40, MAP_WIDTH, MAP_HEIGHT,
|
||||
@ -103,7 +128,7 @@ static void map_close(char* str) {
|
||||
static void map_update(void) {
|
||||
int i;
|
||||
StarSystem* sys;
|
||||
int f;
|
||||
int f, standing, nstanding;
|
||||
char buf[100];
|
||||
|
||||
sys = &systems_stack[map_selected];
|
||||
@ -111,6 +136,7 @@ static void map_update(void) {
|
||||
if(!sys_isKnown(sys)) { /* System isn't known. Erase all. */
|
||||
window_modifyText(map_wid, "txtSysname", "Unknown");
|
||||
window_modifyText(map_wid, "txtFaction", "Unknown");
|
||||
window_modifyText(map_wid, "txtStanding", "Unknown");
|
||||
window_modifyText(map_wid, "txtPlanets", "Unknown");
|
||||
return;
|
||||
}
|
||||
@ -118,40 +144,48 @@ static void map_update(void) {
|
||||
/* System is known. */
|
||||
window_modifyText(map_wid, "txtSysname", sys->name);
|
||||
|
||||
if(sys->nplanets == 0)
|
||||
/* No planets -> no factions. */
|
||||
snprintf(buf, 100, "NA");
|
||||
else {
|
||||
if(sys->nplanets == 0) { /* No planets -> no factions. */
|
||||
window_modifyText(map_wid, "txtFaction", "NA");
|
||||
window_modifyText(map_wid, "txtStanding", "NA");
|
||||
} else {
|
||||
standing = 0;
|
||||
nstanding = 0;
|
||||
f = -1;
|
||||
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;
|
||||
standing += faction_getPlayer(f);
|
||||
nstanding++;
|
||||
}
|
||||
else if(f != sys->planets[i].faction &&
|
||||
(sys->planets[i].faction!=0)) {
|
||||
/* TODO: more verbosity. */
|
||||
snprintf(buf, 100, "Multiple");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(i == sys->nplanets)
|
||||
/* Saw them all, and all the same. */
|
||||
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);
|
||||
|
||||
buf[0] = '\0';
|
||||
/* Get planets. */
|
||||
if(sys->nplanets == 0)
|
||||
snprintf(buf, 100, "None");
|
||||
window_modifyText(map_wid, "txtPlanets", "None");
|
||||
else {
|
||||
buf[0] = '\0';
|
||||
if(sys->nplanets > 0)
|
||||
strcat(buf, sys->planets[0].name);
|
||||
for(i = 1; i < sys->nplanets; i++) {
|
||||
strcat(buf, ",\n");
|
||||
strcat(buf, sys->planets[i].name);
|
||||
}
|
||||
}
|
||||
window_modifyText(map_wid, "txtPlanets", buf);
|
||||
}
|
||||
}
|
||||
|
||||
/* Return 1 if sys is part of the map_path. */
|
||||
|
Loading…
Reference in New Issue
Block a user