/** * @brief Gets the standing of the player with a certain faction. * * @luaparam faction Faction to get the standing of. * @luareturn The faction standing. * @luafunc getFaction( faction ) */ static int playerL_getFaction( lua_State *L ) { NLUA_MIN_ARGS(1); int f; if (lua_isstring(L,1)) f = faction_get( lua_tostring(L,1) ); else NLUA_INVALID_PARAMETER(); lua_pushnumber(L, faction_getPlayer(f)); return 1; }
/** * @brief Gets the player's standing with the faction. * * @usage if f:playerStanding() > 70 then -- Player is an ally * * @luaparam f Faction to get player's standing with. * @luareturn The value of the standing and the human readable string. * @luafunc playerStanding( f ) */ static int factionL_playerstanding( lua_State *L ) { int f; double n; f = luaL_validfaction(L,1); n = faction_getPlayer(f); lua_pushnumber(L, n); lua_pushstring(L, faction_getStanding(n)); return 2; }
/** * @brief Opens the communication dialogue with a pilot. * * @param pilot Pilot to communicate with. * @return 0 on success. */ int comm_openPilot( unsigned int pilot ) { const char *msg; unsigned int wid; /* Get the pilot. */ comm_pilot = pilot_get( pilot ); if (comm_pilot == NULL) return -1; /* Must not be disabled. */ if (pilot_isFlag(comm_pilot, PILOT_DISABLED)) { player_message("%s does not respond.", comm_pilot->name); return 0; } /* Check to see if pilot wants to communicate. */ msg = comm_getString( "comm_no" ); if (msg != NULL) { player_message( msg ); return 0; } /* Set up for the comm_get* functions. */ ai_setPilot( comm_pilot ); /* Create the generic comm window. */ wid = comm_open( ship_loadCommGFX( comm_pilot->ship ), comm_pilot->faction, pilot_isHostile(comm_pilot) ? -1 : pilot_isFriendly(comm_pilot) ? 1 : 0, pilot_isFlag(comm_pilot, PILOT_BRIBED), comm_pilot->name ); /* Add special buttons. */ window_addButton( wid, -20, 20 + BUTTON_HEIGHT + 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnGreet", "Greet", NULL ); if (!pilot_isFlag(comm_pilot, PILOT_BRIBED) && /* Not already bribed. */ ((faction_getPlayer( comm_pilot->faction ) < 0) || /* Hostile. */ pilot_isHostile(comm_pilot))) window_addButton( wid, -20, 20 + 2*BUTTON_HEIGHT + 40, BUTTON_WIDTH, BUTTON_HEIGHT, "btnBribe", "Bribe", comm_bribePilot ); else window_addButton( wid, -20, 20 + 2*BUTTON_HEIGHT + 40, BUTTON_WIDTH, BUTTON_HEIGHT, "btnRequest", "Refuel", comm_requestFuel ); /* Run hooks if needed. */ pilot_runHook( comm_pilot, PILOT_HOOK_HAIL ); return 0; }
/** * @brief Displays the player's standings. */ static void info_openStandings( unsigned int wid ) { int i; int n, m; char **str; int w, h, lw; /* Get dimensions. */ info_getDim( wid, &w, &h, &lw ); /* On close. */ window_onClose( wid, standings_close ); /* Buttons */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "closeMissions", "Close", info_close ); /* Graphics. */ window_addImage( wid, 0, 0, 0, 0, "imgLogo", NULL, 0 ); /* Text. */ window_addText( wid, lw+40, 0, (w-(lw+60)), 20, 1, "txtName", &gl_defFont, &cDConsole, NULL ); window_addText( wid, lw+40, 0, (w-(lw+60)), 20, 1, "txtStanding", &gl_smallFont, &cBlack, NULL ); /* Gets the faction standings. */ info_factions = faction_getAll( &n ); str = malloc( sizeof(char*) * n ); /* Create list. */ for (i=0; i<n; i++) { str[i] = malloc( 256 ); m = round( faction_getPlayer( info_factions[i] ) ); snprintf( str[i], 256, "%s [ %+d%% ]", faction_name( info_factions[i] ), m ); } /* Display list. */ window_addList( wid, 20, -40, lw, h-60, "lstStandings", str, n, 0, standings_update ); standings_update( wid , NULL ); }
/** * @brief Updates the standings menu. */ static void standings_update( unsigned int wid, char* str ) { (void) str; int p, y; glTexture *t; int w, h, lw; char buf[128]; int m; /* Get dimensions. */ info_getDim( wid, &w, &h, &lw ); /* Get faction. */ p = toolkit_getListPos( wid, "lstStandings" ); y = 0; /* Render logo. */ t = faction_logoSmall( info_factions[p] ); if (t != NULL) { window_modifyImage( wid, "imgLogo", t, 0, 0 ); y = -40; window_moveWidget( wid, "imgLogo", lw+40 + (w-(lw+60)-t->w)/2, y ); y -= t->h; } else { window_modifyImage( wid, "imgLogo", NULL, 0, 0 ); y = -20; } /* Modify text. */ y -= 20; window_modifyText( wid, "txtName", faction_longname( info_factions[p] ) ); window_moveWidget( wid, "txtName", lw+40, y ); y -= 40; m = round( faction_getPlayer( info_factions[p] ) ); snprintf( buf, sizeof(buf), "%+d%% [ %s ]", m, faction_getStanding( m ) ); window_modifyText( wid, "txtStanding", buf ); window_moveWidget( wid, "txtStanding", lw+40, y ); }
/** * @brief Updates the map window. * * @param wid Window id. */ static void map_update( unsigned int wid ) { int i; StarSystem* sys; int f, h, x, y; double standing, nstanding; unsigned int services; int l; int hasPresence, hasPlanets; char t; char buf[PATH_MAX]; int p; glTexture *logo; double w; double unknownPresence; /* Needs map to update. */ if (!map_isOpen()) return; /* Get selected system. */ sys = system_getIndex( map_selected ); /* Not known and no markers. */ if (!(sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)) && !sys_isKnown(sys) && !space_sysReachable(sys)) { map_selectCur(); sys = system_getIndex( map_selected ); } /* * Right Text */ x = -70; /* Side bar X offset. */ w = ABS(x) + 60; /* Width of the side bar. */ y = -20 - 20 - 64 - gl_defFont.h; /* Initialized to position for txtSFaction. */ if (!sys_isKnown(sys)) { /* System isn't known, erase all */ /* * Right Text */ if (sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)) window_modifyText( wid, "txtSysname", sys->name ); else window_modifyText( wid, "txtSysname", "Unknown" );; /* Faction */ window_modifyImage( wid, "imgFaction", NULL, 0, 0 ); window_moveWidget( wid, "txtSFaction", x, y); window_moveWidget( wid, "txtFaction", x + 50, y - gl_smallFont.h - 5 ); window_modifyText( wid, "txtFaction", "Unknown" ); y -= 2 * gl_smallFont.h + 5 + 15; /* Standing */ window_moveWidget( wid, "txtSStanding", x, y ); window_moveWidget( wid, "txtStanding", x + 50, y - gl_smallFont.h - 5 ); window_modifyText( wid, "txtStanding", "Unknown" ); y -= 2 * gl_smallFont.h + 5 + 15; /* Presence. */ window_moveWidget( wid, "txtSPresence", x, y ); window_moveWidget( wid, "txtPresence", x + 50, y - gl_smallFont.h - 5 ); window_modifyText( wid, "txtPresence", "Unknown" ); y -= 2 * gl_smallFont.h + 5 + 15; /* Planets */ window_moveWidget( wid, "txtSPlanets", x, y ); window_moveWidget( wid, "txtPlanets", x + 50, y - gl_smallFont.h - 5 ); window_modifyText( wid, "txtPlanets", "Unknown" ); y -= 2 * gl_smallFont.h + 5 + 15; /* Services */ window_moveWidget( wid, "txtSServices", x, y ); window_moveWidget( wid, "txtServices", x + 50, y -gl_smallFont.h - 5 ); window_modifyText( wid, "txtServices", "Unknown" ); /* * Bottom Text */ window_modifyText( wid, "txtSystemStatus", NULL ); return; } /* System is known */ window_modifyText( wid, "txtSysname", sys->name ); standing = 0.; nstanding = 0.; f = -1; for (i=0; i<sys->nplanets; i++) { if (sys->planets[i]->real != ASSET_REAL) continue; if (!planet_isKnown(sys->planets[i])) continue; 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 && /** @todo more verbosity */ (sys->planets[i]->faction>0)) { nsnprintf( buf, PATH_MAX, "Multiple" ); break; } } if (f == -1) { window_modifyImage( wid, "imgFaction", NULL, 0, 0 ); window_modifyText( wid, "txtFaction", "N/A" ); window_modifyText( wid, "txtStanding", "N/A" ); h = gl_smallFont.h; } else { if (i==sys->nplanets) /* saw them all and all the same */ nsnprintf( buf, PATH_MAX, "%s", faction_longname(f) ); /* Modify the image. */ logo = faction_logoSmall(f); window_modifyImage( wid, "imgFaction", logo, 0, 0 ); if (logo != NULL) window_moveWidget( wid, "imgFaction", -90 + logo->w/2, -20 - 32 - 10 - gl_defFont.h + logo->h/2); /* Modify the text */ window_modifyText( wid, "txtFaction", buf ); window_modifyText( wid, "txtStanding", faction_getStanding( standing / nstanding ) ); h = gl_printHeightRaw( &gl_smallFont, w, buf ); } /* Faction */ window_moveWidget( wid, "txtSFaction", x, y); window_moveWidget( wid, "txtFaction", x + 50, y - gl_smallFont.h - 5 ); y -= gl_smallFont.h + h + 5 + 15; /* Standing */ window_moveWidget( wid, "txtSStanding", x, y ); window_moveWidget( wid, "txtStanding", x + 50, y - gl_smallFont.h - 5 ); y -= 2 * gl_smallFont.h + 5 + 15; /* Get presence. */ hasPresence = 0; buf[0] = '\0'; l = 0; unknownPresence = 0; for (i=0; i < sys->npresence; i++) { if (sys->presence[i].value <= 0) continue; hasPresence = 1; if (faction_isKnown( sys->presence[i].faction )) { t = faction_getColourChar(sys->presence[i].faction); /* Use map grey instead of default neutral colour */ l += nsnprintf( &buf[l], PATH_MAX-l, "%s\e0%s: \e%c%.0f", (l==0)?"":"\n", faction_shortname(sys->presence[i].faction), (t=='N')?'M':t, sys->presence[i].value); } else
/** * @brief Updates the map window. * * @param wid Window id. */ static void map_update( unsigned int wid ) { int i; StarSystem* sys; int f, y, h, multiple_faction; double standing, nstanding; unsigned int services; char buf[PATH_MAX]; int p; glTexture *logo; /* Needs map to update. */ if (!map_isOpen()) return; sys = system_getIndex( map_selected ); /* Not known and no markers. */ if (!(sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)) && !sys_isKnown(sys) && !space_sysReachable(sys)) { map_selectCur(); sys = system_getIndex( map_selected ); } /* * Right Text */ if (!sys_isKnown(sys)) { /* System isn't known, erase all */ /* * Right Text */ if (sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)) window_modifyText( wid, "txtSysname", sys->name ); else window_modifyText( wid, "txtSysname", "Unknown" ); window_modifyImage( wid, "imgFaction", NULL ); window_moveWidget( wid, "txtSFaction", -20, -60 ); window_moveWidget( wid, "txtFaction", -20, -60-gl_smallFont.h-5 ); window_modifyText( wid, "txtFaction", "Unknown" ); /* Standing */ window_moveWidget( wid, "txtSStanding", -20, -100 ); window_moveWidget( wid, "txtStanding", -20, -100-gl_smallFont.h-5 ); window_modifyText( wid, "txtStanding", "Unknown" ); /* Security. */ window_moveWidget( wid, "txtSSecurity", -20, -140 ); window_moveWidget( wid, "txtSecurity", -20, -140-gl_smallFont.h-5 ); window_modifyText( wid, "txtSecurity", "Unknown" ); /* Planets */ window_moveWidget( wid, "txtSPlanets", -20, -180 ); window_moveWidget( wid, "txtPlanets", -20, -180-gl_smallFont.h-5 ); window_modifyText( wid, "txtPlanets", "Unknown" ); /* Services */ window_moveWidget( wid, "txtSServices", -20, -220 ); window_moveWidget( wid, "txtServices", -20, -220-gl_smallFont.h-5 ); window_modifyText( wid, "txtServices", "Unknown" ); /* * Bottom Text */ window_modifyText( wid, "txtSystemStatus", NULL ); return; } /* System is known */ window_modifyText( wid, "txtSysname", sys->name ); standing = 0.; nstanding = 0.; f = -1; multiple_faction = 0; for (i=0; i<sys->nplanets; i++) { 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 && /** @todo more verbosity */ (sys->planets[i]->faction>0)) { snprintf( buf, PATH_MAX, "Multiple" ); multiple_faction = 1; break; } } if (f == -1) { window_modifyImage( wid, "imgFaction", NULL ); window_moveWidget( wid, "txtSFaction", -20, -60 ); window_moveWidget( wid, "txtFaction", -20, -60-gl_smallFont.h-5 ); window_modifyText( wid, "txtFaction", "NA" ); window_moveWidget( wid, "txtSStanding", -20, -100 ); window_moveWidget( wid, "txtStanding", -20, -100-gl_smallFont.h-5 ); window_modifyText( wid, "txtStanding", "NA" ); y = -100; } else { if (i==sys->nplanets) /* saw them all and all the same */ snprintf( buf, PATH_MAX, "%s", faction_longname(f) ); y = -60; /* Modify the image. */ logo = faction_logoSmall(f); window_modifyImage( wid, "imgFaction", logo ); if (logo != NULL) { window_moveWidget( wid, "imgFaction", -(90-logo->w)/2-20-logo->w, y-(64-logo->h)/2-logo->h ); y -= 64 + 10; } /* Modify the text */ window_modifyText( wid, "txtFaction", buf ); window_modifyText( wid, "txtStanding", faction_getStanding( standing / nstanding ) ); /* Lower text if needed */ window_moveWidget( wid, "txtSFaction", -20, y ); window_moveWidget( wid, "txtFaction", -20, y-gl_smallFont.h-5 ); h = gl_printHeightRaw( &gl_smallFont, 80, buf ); window_moveWidget( wid, "txtSStanding", -20, y ); window_moveWidget( wid, "txtStanding", -20, y-gl_smallFont.h-5 ); y -= 40 + (h - gl_smallFont.h); window_moveWidget( wid, "txtSStanding", -20, y ); window_moveWidget( wid, "txtStanding", -20, y-gl_smallFont.h-5 ); } /* Get security. */ y -= 40; if (sys->nfleets == 0) snprintf(buf, PATH_MAX, "NA" ); else snprintf(buf, PATH_MAX, "%.0f %%", sys->security * 100.); window_moveWidget( wid, "txtSSecurity", -20, y ); window_moveWidget( wid, "txtSecurity", -20, y-gl_smallFont.h-5 ); window_modifyText( wid, "txtSecurity", buf ); /* Get planets */ if (sys->nplanets == 0) { strncpy( buf, "None", PATH_MAX ); window_modifyText( wid, "txtPlanets", buf ); } else { p = 0; buf[0] = '\0'; if (sys->nplanets > 0) p += snprintf( &buf[p], PATH_MAX-p, "%s", sys->planets[0]->name ); for (i=1; i<sys->nplanets; i++) { p += snprintf( &buf[p], PATH_MAX-p, ",\n%s", sys->planets[i]->name ); } window_modifyText( wid, "txtPlanets", buf ); } y -= 40; window_moveWidget( wid, "txtSPlanets", -20, y ); window_moveWidget( wid, "txtPlanets", -20, y-gl_smallFont.h-5 ); /* Get the services */ h = gl_printHeightRaw( &gl_smallFont, 80, buf ); y -= 40 + (h - gl_smallFont.h); window_moveWidget( wid, "txtSServices", -20, y ); window_moveWidget( wid, "txtServices", -20, y-gl_smallFont.h-5 ); services = 0; for (i=0; i<sys->nplanets; i++) services |= sys->planets[i]->services; buf[0] = '\0'; p = 0; /*snprintf(buf, sizeof(buf), "%f\n", sys->prices[0]);*/ /*Hack to control prices. */ if (services & PLANET_SERVICE_COMMODITY) p += snprintf( &buf[p], PATH_MAX-p, "Commodity\n"); if (services & PLANET_SERVICE_OUTFITS) p += snprintf( &buf[p], PATH_MAX-p, "Outfits\n"); if (services & PLANET_SERVICE_SHIPYARD) p += snprintf( &buf[p], PATH_MAX-p, "Shipyard\n"); if (buf[0] == '\0') p += snprintf( &buf[p], PATH_MAX-p, "None"); window_modifyText( wid, "txtServices", buf ); /* * System Status */ buf[0] = '\0'; p = 0; /* Nebula. */ if (sys->nebu_density > 0.) { /* Volatility */ if (sys->nebu_volatility > 700.) p += snprintf(&buf[p], PATH_MAX-p, " Volatile"); else if (sys->nebu_volatility > 300.) p += snprintf(&buf[p], PATH_MAX-p, " Dangerous"); else if (sys->nebu_volatility > 0.) p += snprintf(&buf[p], PATH_MAX-p, " Unstable"); /* Density */ if (sys->nebu_density > 700.) p += snprintf(&buf[p], PATH_MAX-p, " Dense"); else if (sys->nebu_density < 300.) p += snprintf(&buf[p], PATH_MAX-p, " Light"); p += snprintf(&buf[p], PATH_MAX-p, " Nebula"); } /* Interference. */ if (sys->interference > 0.) { if (buf[0] != '\0') p += snprintf(&buf[p], PATH_MAX-p, ","); /* Density. */ if (sys->interference > 700.) p += snprintf(&buf[p], PATH_MAX-p, " Dense"); else if (sys->interference < 300.) p += snprintf(&buf[p], PATH_MAX-p, " Light"); p += snprintf(&buf[p], PATH_MAX-p, " Interference"); } window_modifyText( wid, "txtSystemStatus", buf ); }