25#include "difficulty.h"
38#include "land_outfits.h"
42#include "map_overlay.h"
50#include "nlua_outfit.h"
59#include "player_gui.h"
60#include "player_fleet.h"
61#include "player_inventory.h"
89#define RADAR_RES_DEFAULT 50.
174static int preemption = 0;
194 player_autonavInit();
253 const char *SAVEPATH =
"_tmp";
258 _(
"Please write your name:") );
267 snprintf( buf,
sizeof(buf),
"%s/%s", SAVEPATH,
player.
name );
268 if (PHYSFS_mkdir(buf)==0)
269 dialogue_alert(_(
"'%s' is an invalid player name as it can not be saved to your filesystem! Please choose another."),
player.
name);
271 int ret = PHYSFS_delete( buf );
273 WARN(_(
"Unable to delete temporary file '%s': %s"), buf, PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ));
275 ret = PHYSFS_delete( SAVEPATH );
277 WARN(_(
"Unable to delete temporary file '%s': %s"), SAVEPATH, PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ));
281 PHYSFS_getLastErrorCode();
287 _(
"You already have a pilot named %s. Their autosave and backup save will be overwritten. Do you wish to continue?"),
player.
name);
309 WARN(_(
"Failed to run start mission '%s'."),
start_mission());
315 WARN(_(
"Failed to run start event '%s'."),
start_event());
333 const char *shipname, *acquired;
354 WARN(_(
"Ship not properly set by module."));
359 ps =
player_newShip( ship, shipname, 0, acquired, (shipname==NULL) ? 0 : 1 );
411 int trade,
const char *acquired,
int noname )
421 _(
"Please name your new ship:") );
426 if (ship_name == NULL) {
430 if (def_name == NULL)
435 len = strlen(def_name)+10;
436 ship_name = malloc( len );
437 strcpy( ship_name, def_name );
439 snprintf( ship_name, len,
"%s %d", def_name, i );
447 _(
"Please do not give the ship the same name as another of your ships."));
452 ERR(_(
"Player ship isn't valid… This shouldn't happen!"));
458 ps->
acquired = (acquired!=NULL) ? strdup( acquired ) : NULL;
489 pilot_clearFlagsRaw( flags );
490 pilot_setFlagRaw( flags, PILOT_PLAYER );
491 pilot_setFlagRaw( flags, PILOT_NO_EQUIP );
494 player_rmFlag( PLAYER_CREATING );
499 pilot_setFlagRaw( flags, PILOT_PLAYER_FLEET );
510 ERR(_(
"Something seriously wonky went on, newly created player does not exist, bailing!"));
532 int removed, hyptarget;
544 WARN( _(
"Unable to swap player.p with ship '%s': ship does not exist!"), shipname );
565 if (e->
id == ps->
p->
id )
648 hparam[0].
type = HOOK_PARAM_STRING;
650 hparam[1].
type = HOOK_PARAM_SHIP;
652 hparam[2].
type = HOOK_PARAM_STRING;
654 hparam[3].
type = HOOK_PARAM_SHIP;
656 hparam[4].
type = HOOK_PARAM_SENTINEL;
685 WARN( _(
"Unable to find price for player's ship '%s': ship does not exist!"), shipname );
694 pilot_rmFlag( ps->
p, PILOT_NOFREE );
711 if (strcmp(shipname,ps->
p->
name)!=0)
715 player_rmPlayerShip( ps );
827 difficulty_setLocal( NULL );
838 player_setFlag(PLAYER_CREATING);
955 player_rmFlag( PLAYER_NOLAND );
988 if (player_isFlag(PLAYER_DESTROYED)) {
996 if ((
player.
p == NULL) || (
player.
p->
id == 0) || player_isFlag(PLAYER_CREATING) ||
997 pilot_isFlag(
player.
p, PILOT_HIDE))
1001 if (pilot_isFlag(
player.
p, PILOT_STEALTH ))
1006 && !pilot_isFlag(
player.
p, PILOT_HYPERSPACE ) && !pilot_isFlag(
player.
p, PILOT_DISABLED )
1007 && !pilot_isFlag(
player.
p, PILOT_LANDING ) && !pilot_isFlag(
player.
p, PILOT_TAKEOFF )
1008 && !player_isFlag( PLAYER_CINEMATICS_GUI ))
1024 if ((
player.
p == NULL) || player_isFlag(PLAYER_CREATING) ||
1025 pilot_isFlag(
player.
p, PILOT_HIDE))
1028 if (pilot_isFlag(
player.
p, PILOT_STEALTH ))
1056 if (pilot_isDisabled(t))
1065 glUseProgram( shaders.stealthaura.program );
1077 double x, y, r,
st, z;
1094 glUseProgram( shaders.stealthmarker.program );
1095 glUniform1f( shaders.stealthmarker.paramf,
st );
1096 gl_renderShader( x, y, r*z, r*z, 0., &shaders.stealthmarker, &col, 1 );
1105 double a, b,
d, x1, y1, x2, y2, r, theta;
1119 theta = 22.*M_PI/180.;
1122 d =
ABS( angle_diff(a,b) / (2*theta) );
1135 c.g =
d*0.2 + (1.-
d)*0.8;
1138 col_gammaToLinear( &
c );
1146 glUseProgram(shaders.crosshairs.program);
1147 glUniform1f(shaders.crosshairs.paramf, 1.);
1157 glColour c3 = cBlack;
1176 if (pilot_isFlag(pplayer,PILOT_DEAD)) {
1185 ai_think( pplayer, dt, pilot_isFlag(pplayer, PILOT_MANUAL_CONTROL) );
1188 if (pilot_isFlag( pplayer, PILOT_MANUAL_CONTROL ) || pilot_isFlag( pplayer, PILOT_HIDE ))
1195 if (player_isFlag(PLAYER_AUTONAV)) {
1203 if (!facing && player_isFlag(PLAYER_MFLY))
1207 if (!facing && player_isFlag(PLAYER_FACE)) {
1211 if (target != NULL) {
1250 if (player_isFlag(PLAYER_REVERSE)) {
1264 if (player_isFlag(PLAYER_TURN_LEFT))
1266 if (player_isFlag(PLAYER_TURN_RIGHT))
1268 turn =
CLAMP( -1., 1., turn );
1278 if (player_isFlag(PLAYER_PRIMARY)) {
1280 player_setFlag(PLAYER_PRIMARY_L);
1282 else if (player_isFlag(PLAYER_PRIMARY_L)) {
1284 player_rmFlag(PLAYER_PRIMARY_L);
1287 if (player_isFlag(PLAYER_SECONDARY)) {
1289 player_setFlag(PLAYER_SECONDARY_L);
1291 else if (player_isFlag(PLAYER_SECONDARY_L)) {
1293 player_rmFlag(PLAYER_SECONDARY_L);
1297 player_autonavReset( 1. );
1299 if (!player_isFlag(PLAYER_AUTONAV)) {
1304 && !pilot_isFlag(
player.
p, PILOT_HYP_PREP)
1305 && !pilot_isFlag(
player.
p, PILOT_HYPERSPACE) )
1306 acc = -PILOT_REVERSE_THRUST;
1324 if (!player_isFlag(PLAYER_DESTROYED))
1340 if (pilot_isFlag(pplayer, PILOT_AFTERBURNER))
1342 else if (pilot_isFlag(pplayer, PILOT_HYPERSPACE))
1355 if (engsound >= 0) {
1393 for (
int j=0; j<ast->
nb; j++) {
1406 hparam[0].
type = HOOK_PARAM_ASTEROID;
1407 hparam[0].
u.
ast.parent = ast->
id;
1408 hparam[0].
u.
ast.id = a->id;
1409 hparam[1].
type = HOOK_PARAM_SENTINEL;
1426 if (repeat || (
player.
p == NULL))
1429 type = (value>=0) ? +1 : -1;
1435 if ((pilot_isFlag(
player.
p, PILOT_HYP_PREP) ||
1436 pilot_isFlag(
player.
p, PILOT_HYPERSPACE) ||
1437 pilot_isFlag(
player.
p, PILOT_LANDING) ||
1438 pilot_isFlag(
player.
p, PILOT_TAKEOFF)))
1466 if (reason != PINPUT_AUTONAV) {
1468 if ((!
paused || reason != PINPUT_MOVEMENT))
1472 if (reason != PINPUT_BRAKING) {
1473 pilot_rmFlag(
player.
p, PILOT_BRAKING);
1474 pilot_rmFlag(
player.
p, PILOT_COOLDOWN_BRAKE);
1475 if (pilot_isFlag(
player.
p, PILOT_COOLDOWN))
1494 WARN(_(
"Trying to set player's spob target to invalid ID '%d'"),
id);
1498 if ((
player.
p == NULL) || pilot_isFlag(
player.
p, PILOT_LANDING ))
1505 player_rmFlag(PLAYER_LANDACK);
1526 if ((
player.
p == NULL) || pilot_isFlag(
player.
p, PILOT_LANDING ))
1551 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ))
1586 return PLAYER_LAND_DENIED;
1590 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ) ||
1592 return PLAYER_LAND_DENIED;
1595 if ((pilot_isFlag(
player.
p, PILOT_LANDING) ||
1596 pilot_isFlag(
player.
p, PILOT_TAKEOFF)))
1597 return PLAYER_LAND_DENIED;
1602 return PLAYER_LAND_DENIED;
1605 if (player_isFlag(PLAYER_NOLAND)) {
1607 return PLAYER_LAND_DENIED;
1609 else if (pilot_isFlag(
player.
p, PILOT_NOLAND)) {
1610 player_message(
"#r%s", _(
"Docking stabilizers malfunctioning, cannot land.") );
1611 return PLAYER_LAND_DENIED;
1616 return PLAYER_LAND_DENIED;
1620 return PLAYER_LAND_AGAIN;
1626 if ((spob->
lua_can_land==LUA_NOREF) && !spob_hasService(spob, SPOB_SERVICE_LAND)) {
1628 return PLAYER_LAND_DENIED;
1636 return PLAYER_LAND_DENIED;
1638 else if (!player_isFlag(PLAYER_LANDACK)) {
1639 if (spob_hasService(spob,SPOB_SERVICE_INHABITED)) {
1645 spob_name(spob), _(
"Landing authorized.") );
1649 return PLAYER_LAND_DENIED;
1655 player_setFlag(PLAYER_LANDACK);
1664 return PLAYER_LAND_AGAIN;
1669 return PLAYER_LAND_AGAIN;
1688 lua_rawgeti(naevL, LUA_REGISTRYINDEX, spob->
lua_land);
1691 if (nlua_pcall( spob->
lua_env, 2, 0 )) {
1692 WARN(_(
"Spob '%s' failed to run '%s':\n%s"), spob->
name,
"land", lua_tostring(naevL,-1));
1696 return PLAYER_LAND_OK;
1703 pilot_setFlag(
player.
p, PILOT_LANDING );
1707 return PLAYER_LAND_OK;
1718 if ((
player.
p == NULL) || !player_isFlag(PLAYER_LANDACK))
1723 WARN(_(
"Player has landing permission, but no valid spob targeted."));
1730 if (p->can_land || (p->land_override > 0))
1733 player_rmFlag(PLAYER_LANDACK);
1769 if (canland == PLAYER_LAND_AGAIN)
1771 else if (canland == PLAYER_LAND_DENIED)
1781 if ((nearp!=NULL) && !pilot_isFlag(nearp,PILOT_NOBOARD) && (
d<
pow2(5e3)) &&
1782 (pilot_isDisabled(nearp) || pilot_isFlag(nearp,PILOT_BOARDABLE))) {
1798 if (!spob_hasService(spob,SPOB_SERVICE_LAND))
1800 if ((tp==-1) || ((td==-1) || (td >
d))) {
1830 WARN(_(
"Trying to set player's hyperspace target to invalid ID '%d'"),
id);
1834 if (pilot_isFlag(
player.
p, PILOT_HYP_PREP) ||
1835 pilot_isFlag(
player.
p, PILOT_HYP_BEGIN) ||
1836 pilot_isFlag(
player.
p, PILOT_HYPERSPACE))
1842 if ((old !=
id) && (
id >= 0))
1846 if (!nomsg && (old !=
id) && (
player.
autonav==AUTONAV_JUMP))
1860 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ))
1883 map_select( NULL , 0);
1885 map_select(
cur_system->jumps[
id ].target, 0 );
1895 preemption = preempt;
1930 player_message( _(
"#rReceiving hail! Press #b%s#r to respond.#0"), buf );
1933 player_autonavReset( 10. );
1946 if (pilot_isFlag(
player.
p, PILOT_HYPERSPACE))
1950 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ) ||
1957 double mindist = INFINITY;
1960 if (dist < mindist && jp_isUsable(&
cur_system->jumps[i])) {
1979 if (pilot_isFlag(
player.
p, PILOT_HYP_PREP)) {
1995 player_message(
"#r%s", _(
"You do not have enough fuel to hyperspace jump."));
2060 pilot_rmFlag(
player.
p, PILOT_HYPERSPACE );
2061 pilot_rmFlag(
player.
p, PILOT_HYP_BEGIN );
2062 pilot_rmFlag(
player.
p, PILOT_HYP_BRAKE );
2063 pilot_rmFlag(
player.
p, PILOT_HYP_PREP );
2071 if (pilot_isFlag(p, PILOT_PERSIST) || pilot_isFlag(p, PILOT_PLAYER)) {
2080 p->itimer = PILOT_PLAYER_NONTARGETABLE_JUMPIN_DELAY;
2081 pilot_setFlag( p, PILOT_NONTARGETABLE );
2084 pilot_rmFlag( p, PILOT_HYPERSPACE );
2085 pilot_rmFlag( p, PILOT_HYP_BEGIN );
2086 pilot_rmFlag( p, PILOT_HYP_BRAKE );
2087 pilot_rmFlag( p, PILOT_HYP_PREP );
2092 player_autonavEnter();
2115 if ((
player.
p == NULL) || pilot_isFlag(
player.
p, PILOT_HYP_PREP) ||
2116 pilot_isFlag(
player.
p, PILOT_HYPERSPACE))
2153 if ((old !=
id) && player_isFlag(PLAYER_AUTONAV) && (
player.
autonav==AUTONAV_PILOT))
2188 if (tp == PLAYER_ID || ((td <
d))) {
2230 !pilot_isFlag(
player.
p, PILOT_HYP_PREP)) {
2323 if (PHYSFS_mkdir(
"screenshots") == 0) {
2324 WARN(_(
"Aborting screenshot"));
2330 snprintf( filename,
sizeof(filename),
"screenshots/screenshot%03d.png",
screenshot_cur );
2331 if (!PHYSFS_exists( filename ))
2336 WARN(_(
"You have reached the maximum amount of screenshots [999]"));
2356 if (pilot_isFlag(p, PILOT_HAILING))
2372 player_message( _(
"#r%s is out of comm range, unable to contact."), name );
2381 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ) ||
2389 if (spob_isFlag(spob, SPOB_UNINHABITED))
2409 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ))
2430 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ) ||
2440 if (pilot_isFlag(p, PILOT_HAILING)) {
2452 player_message(
"#r%s", _(
"You haven't been hailed by any pilots.") );
2463 if (!player_isFlag(PLAYER_MFLY)) {
2466 player_setFlag(PLAYER_MFLY);
2470 player_rmFlag(PLAYER_MFLY);
2485 if (pilot_isFlag(
player.
p, PILOT_TAKEOFF))
2489 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ) ||
2493 stopped = pilot_isStopped(
player.
p);
2494 if (stopped && !pilot_isFlag(
player.
p, PILOT_COOLDOWN))
2497 pilot_setFlag(
player.
p, PILOT_BRAKING);
2498 pilot_setFlag(
player.
p, PILOT_COOLDOWN_BRAKE);
2510 double px, py, r, x, y;
2519 double acc =
CLAMP(0., 1., (r - 100.) / 200.);
2520 acc = 3. *
pow2(acc) - 2. * pow(acc, 3.);
2551 if (player_isFlag(PLAYER_DESTROYED))
2555 player_setFlag(PLAYER_DESTROYED);
2693 WARN(_(
"Player ship '%s' not found in stack"), shipname);
2712 WARN(_(
"Player ship '%s' not found in stack"), shipname);
2740 if (o->
slot.
type==OUTFIT_SLOT_INTRINSIC)
2796 int(*filter)(
const Outfit *o ),
const char *name )
2860 else if (o->
slot.
type==OUTFIT_SLOT_INTRINSIC) {
2892 if (o->
slot.
type==OUTFIT_SLOT_INTRINSIC)
2918static int cmp_int(
const void *p1,
const void *p2 )
2920 const int *i1 = (
const int*) p1;
2921 const int *i2 = (
const int*) p2;
2922 return (*i1) - (*i2);
2948 mission_toLuaTable( naevL, m );
2949 h[0].
type = HOOK_PARAM_REF;
2950 h[0].
u.
ref = luaL_ref( naevL, LUA_REGISTRYINDEX );
2951 h[1].
type = HOOK_PARAM_SENTINEL;
3001 event_toLuaTable( naevL,
id );
3002 h[0].
type = HOOK_PARAM_REF;
3003 h[0].
u.
ref = luaL_ref( naevL, LUA_REGISTRYINDEX );
3004 h[1].
type = HOOK_PARAM_SENTINEL;
3041 if (license == NULL)
3079 if (player_isFlag( PLAYER_HOOK_HYPER )) {
3080 player_rmFlag( PLAYER_HOOK_HYPER );
3083 if (player_isFlag( PLAYER_HOOK_JUMPIN)) {
3084 player_rmFlag( PLAYER_HOOK_JUMPIN );
3091 if (player_isFlag( PLAYER_HOOK_LAND )) {
3092 player_rmFlag( PLAYER_HOOK_LAND );
3137 pe->
solid.
dir = RNGF() * 2. * M_PI;
3140 vec2_cset( &pe->
solid.
vel, 0., 0. );
3143 if (e->
type != ESCORT_TYPE_BAY)
3149 pilot_setFlag( pe, PILOT_DELETE );
3150 WARN(_(
"Escort is undeployed, removing."));
3160 pilot_setFlag( pe, PILOT_DELETE );
3161 WARN(_(
"Escort is deployed past outfit limits, removing."));
3201 case ESCORT_TYPE_BAY:
3202 xmlw_startElem(writer,
"escort");
3203 xmlw_attr(writer,
"type",
"bay");
3204 xmlw_attr(writer,
"name",
"%s", e->
ship->
name);
3205 xmlw_endElem(writer);
3208 case ESCORT_TYPE_FLEET:
3211 xmlw_startElem(writer,
"escort");
3212 xmlw_attr(writer,
"type",
"fleet");
3213 xmlw_attr(writer,
"name",
"%s", pe->
name);
3214 xmlw_endElem(writer);
3235 int cycles, periods, seconds;
3239 xmlw_startElem(writer,
"player");
3248 xmlw_elem(writer,
"gui",
"%s",
player.
gui);
3249 xmlw_elem(writer,
"mapOverlay",
"%d",ovr_isOpen());
3257 xmlw_startElem(writer,
"time");
3258 ntime_getR( &cycles, &periods, &seconds, &rem );
3259 xmlw_elem(writer,
"SCU",
"%d", cycles);
3260 xmlw_elem(writer,
"STP",
"%d", periods);
3261 xmlw_elem(writer,
"STU",
"%d", seconds);
3262 xmlw_elem(writer,
"Remainder",
"%lf", rem);
3263 xmlw_endElem(writer);
3270 xmlw_startElem(writer,
"ships");
3273 xmlw_endElem(writer);
3276 xmlw_startElem(writer,
"guis");
3279 xmlw_elem(writer,
"gui",
"%s",guis[i]);
3280 xmlw_endElem(writer);
3283 xmlw_startElem(writer,
"outfits");
3285 xmlw_startElem(writer,
"outfit");
3288 xmlw_endElem(writer);
3290 xmlw_endElem(writer);
3293 xmlw_startElem(writer,
"licenses");
3296 xmlw_endElem(writer);
3299 xmlw_startElem(writer,
"inventory");
3303 xmlw_startElem(writer,
"item");
3304 xmlw_attr(writer,
"quantity",
"%d", pi->
quantity);
3305 xmlw_str(writer,
"%s", pi->
name);
3306 xmlw_endElem(writer);
3308 xmlw_endElem(writer);
3310 xmlw_endElem(writer);
3313 xmlw_startElem(writer,
"missions_done");
3317 xmlw_elem(writer,
"done",
"%s", m->
name);
3319 xmlw_endElem(writer);
3322 xmlw_startElem(writer,
"events_done");
3326 xmlw_elem(writer,
"done",
"%s", ev);
3328 xmlw_endElem(writer);
3331 xmlw_startElem(writer,
"escorts");
3333 xmlw_endElem(writer);
3336 xmlw_startElem(writer,
"metadata");
3338 xmlw_endElem(writer);
3349 xmlw_startElem(writer,
"outfit");
3350 xmlw_attr(writer,
"slot",
"%d",i);
3352 xmlw_attr(writer,
"quantity",
"%d", slot->u.
ammo.
quantity);
3353 xmlw_str(writer,
"%s",o->
name);
3354 xmlw_endElem(writer);
3369 xmlw_startElem(writer,
"ship");
3370 xmlw_attr(writer,
"name",
"%s",ship->
name);
3371 xmlw_attr(writer,
"model",
"%s",ship->
ship->
name);
3372 xmlw_attr(writer,
"favourite",
"%d",pship->
favourite);
3373 xmlw_attr(writer,
"deployed",
"%d",pship->
deployed);
3377 xmlw_elem(writer,
"acquired",
"%s", pship->
acquired);
3378 xmlw_saveTime(writer,
"acquired_date", pship->
acquired_date);
3379 xmlw_elem(writer,
"time_played",
"%f", pship->
time_played);
3384 xmlw_elem(writer,
"jumped_times",
"%u", pship->
jumped_times);
3385 xmlw_elem(writer,
"landed_times",
"%u", pship->
landed_times);
3386 xmlw_elem(writer,
"death_counter",
"%u", pship->
death_counter);
3389 xmlw_startElem(writer,
"ships_destroyed");
3390 for (
int i=SHIP_CLASS_NULL+1; i<SHIP_CLASS_TOTAL; i++) {
3391 char buf[STRMAX_SHORT];
3393 for (
size_t j=0; j<strlen(buf); j++)
3398 xmlw_endElem(writer);
3401 xmlw_elem(writer,
"fuel",
"%f",ship->
fuel);
3404 xmlw_startElem(writer,
"outfits_intrinsic");
3407 xmlw_endElem(writer);
3408 xmlw_startElem(writer,
"outfits_structure");
3414 xmlw_endElem(writer);
3415 xmlw_startElem(writer,
"outfits_utility");
3421 xmlw_endElem(writer);
3422 xmlw_startElem(writer,
"outfits_weapon");
3428 xmlw_endElem(writer);
3431 xmlw_startElem(writer,
"commodities");
3454 WARN(_(
"Found mission cargo '%s' without associated mission."),pc->
commodity->
name);
3455 WARN(_(
"Please reload save game to remove the dead cargo."));
3460 WARN(_(
"Found cargo '%s' with 0 quantity."),pc->
commodity->
name);
3461 WARN(_(
"Please reload save game to remove the dead cargo."));
3465 xmlw_startElem(writer,
"commodity");
3467 xmlw_attr(writer,
"quantity",
"%d",pc->
quantity);
3469 xmlw_attr(writer,
"id",
"%d",pc->
id);
3472 xmlw_endElem(writer);
3474 xmlw_endElem(writer);
3476 xmlw_startElem(writer,
"weaponsets");
3477 xmlw_attr(writer,
"autoweap",
"%d", ship->
autoweap);
3478 xmlw_attr(writer,
"active_set",
"%d", ship->
active_set);
3479 xmlw_attr(writer,
"aim_lines",
"%d", ship->
aimLines);
3480 for (
int i=0; i<PILOT_WEAPON_SETS; i++) {
3483 xmlw_startElem(writer,
"weaponset");
3485 xmlw_attr(writer,
"inrange",
"%d",ws->
inrange);
3486 xmlw_attr(writer,
"manual",
"%d",ws->
manual);
3487 xmlw_attr(writer,
"volley",
"%d",ws->
volley);
3488 xmlw_attr(writer,
"id",
"%d",i);
3490 xmlw_attr(writer,
"type",
"%d",ws->
type);
3492 xmlw_startElem(writer,
"weapon");
3493 xmlw_attr(writer,
"level",
"%d",weaps[j].level);
3494 xmlw_str(writer,
"%d",weaps[j].slotid);
3495 xmlw_endElem(writer);
3498 xmlw_endElem(writer);
3500 xmlw_endElem(writer);
3503 xmlw_startElem(writer,
"vars");
3505 xmlw_endElem(writer);
3507 xmlw_endElem(writer);
3520 time_t t = time(NULL);
3529 xmlw_saveTime(writer,
"last_played", time(NULL));
3543 xmlw_startElem(writer,
"ships_destroyed");
3544 for (
int i=SHIP_CLASS_NULL+1; i<SHIP_CLASS_TOTAL; i++) {
3545 char buf[STRMAX_SHORT];
3547 for (
size_t j=0; j<strlen(buf); j++)
3552 xmlw_endElem(writer);
3584 node = parent->xmlChildrenNode;
3586 if (xml_isNode(node,
"metadata"))
3588 else if (xml_isNode(node,
"player"))
3590 else if (xml_isNode(node,
"missions_done"))
3592 else if (xml_isNode(node,
"events_done"))
3594 else if (xml_isNode(node,
"escorts"))
3596 }
while (xml_nextNode(node));
3607 difficulty_setLocal( NULL );
3628 static nlua_env player_updater_env = LUA_NOREF;
3633 if (player_updater_env == LUA_NOREF) {
3634 player_updater_env = nlua_newEnv();
3636 char *buf =
ndata_read( SAVE_UPDATER_PATH, &bufsize );
3637 if (nlua_dobufenv(player_updater_env, buf, bufsize, SAVE_UPDATER_PATH) != 0) {
3638 WARN( _(
"Error loading file: %s\n"
3640 "Most likely Lua file has improper syntax, please check"),
3641 SAVE_UPDATER_PATH, lua_tostring(naevL,-1));
3649 nlua_getenv( naevL, player_updater_env, type );
3650 lua_pushstring( naevL, name );
3651 if (nlua_pcall(player_updater_env, 1, 1)) {
3652 WARN( _(
"Board: '%s'"), lua_tostring(naevL,-1));
3656 if (lua_type(naevL,-1) == LUA_TNUMBER) {
3680 else if (lua_type(naevL,-1) == LUA_TSTRING)
3685 WARN(_(
"Outfit '%s' in player save not found!"), name );
3707 else if (lua_type(naevL,-1) == LUA_TSTRING)
3708 s =
ship_get( lua_tostring(naevL,-1) );
3712 WARN(_(
"Ship '%s' in player save not found!"), name );
3734 else if (lua_type(naevL,-1) == LUA_TSTRING)
3737 WARN(_(
"Saved license does not exist and could not be found or updated: '%s'!"), name);
3749 const char *spob = NULL;
3751 xmlNodePtr node, cur;
3752 int map_overlay_enabled = 0;
3764 node = parent->xmlChildrenNode;
3766 xmlr_str(node,
"location",spob);
3767 }
while (xml_nextNode(node));
3770 node = parent->xmlChildrenNode;
3776 xmlr_int(node,
"mapOverlay", map_overlay_enabled);
3783 if (xml_isNode(node,
"time")) {
3785 int cycles=-1, periods=-1, seconds=-1;
3786 cur = node->xmlChildrenNode;
3788 xmlr_int(cur,
"SCU", cycles);
3789 xmlr_int(cur,
"STP", periods);
3790 xmlr_int(cur,
"STU", seconds);
3791 xmlr_float(cur,
"Remainder", rem);
3792 }
while (xml_nextNode(cur));
3793 if ((cycles < 0) || (periods < 0) || (seconds < 0) || (rem<0.))
3794 WARN(_(
"Malformed time in save game!"));
3796 if ((cycles >= 0) || (periods >= 0) || (seconds >= 0))
3800 if (xml_isNode(node,
"ship"))
3804 else if (xml_isNode(node,
"ships")) {
3805 cur = node->xmlChildrenNode;
3807 if (xml_isNode(cur,
"ship"))
3809 }
while (xml_nextNode(cur));
3813 else if (xml_isNode(node,
"guis")) {
3814 cur = node->xmlChildrenNode;
3816 if (xml_isNode(cur,
"gui"))
3818 }
while (xml_nextNode(cur));
3822 else if (xml_isNode(node,
"outfits")) {
3823 cur = node->xmlChildrenNode;
3825 if (xml_isNode(cur,
"outfit")) {
3828 const char *oname = xml_get(cur);
3829 xmlr_attr_float( cur,
"quantity", q );
3831 WARN(_(
"Outfit '%s' was saved without quantity!"), (oname!=NULL) ? oname :
"NULL" );
3841 }
while (xml_nextNode(cur));
3845 else if (xml_isNode(node,
"licenses"))
3848 else if (xml_isNode(node,
"inventory"))
3851 }
while (xml_nextNode(node));
3856 pilot_clearFlagsRaw( flags );
3857 pilot_setFlagRaw( flags, PILOT_PLAYER );
3858 pilot_setFlagRaw( flags, PILOT_NO_OUTFITS );
3859 WARN(_(
"Player ship does not exist!"));
3862 WARN(_(
"Player has no other ships, giving starting ship."));
3864 faction_get(
"Player"),
"player", 0., NULL, NULL, flags, 0, 0 );
3870 faction_get(
"Player"),
"player", 0., NULL, NULL, flags, 0, 0 );
3872 WARN(_(
"Giving player ship '%s'."),
player.
p->
name );
3878 ERR(_(
"Something went horribly wrong, player does not exist after load..."));
3888 WARN(_(
"Save has no time information, setting to start information."));
3894 DEBUG(_(
"Player save was updated!"));
3895 dialogue_msg(_(
"Save Game Updated"),_(
"The loaded save games has had outfits and ships updated to the current Naev version. You will find that some outfits and ships you have had have been changed. In the case no equivalent outfit or ship was found, you have been refunded the cost in credits."));
3902 !spob_hasService(pnt, SPOB_SERVICE_LAND)) {
3903 WARN(_(
"Player starts out in non-existent or invalid spob '%s',"
3904 "trying to find a suitable one instead."),
3917 const char *found = NULL;
3918 for (
int i=0; i<3; i++) {
3919 unsigned int services = SPOB_SERVICE_LAND | SPOB_SERVICE_INHABITED | SPOB_SERVICE_REFUEL;
3922 services |= SPOB_SERVICE_SHIPYARD;
3925 services |= SPOB_SERVICE_OUTFITS;
3932 WARN(_(
"Could not find a spob satisfying criteria %d."), i);
3935 if (found == NULL) {
3936 WARN(_(
"Could not find a suitable spob. Choosing a random spob."));
3945 a = RNGF() * 2.*M_PI;
3946 r = RNGF() * pnt->
radius * 0.8;
3956 ovr_setOpen(map_overlay_enabled);
3972 return !
areEnemies(p->presence.faction, FACTION_PLAYER);
3983 xmlNodePtr node = parent->xmlChildrenNode;
3985 xml_onlyNodes(node);
3987 if (!xml_isNode(node,
"done"))
3992 DEBUG(_(
"Mission '%s' doesn't seem to exist anymore, removing from save."),
3996 }
while (xml_nextNode(node));
4008 xmlNodePtr node = parent->xmlChildrenNode;
4010 xml_onlyNodes(node);
4012 if (!xml_isNode(node,
"done"))
4017 DEBUG(_(
"Event '%s' doesn't seem to exist anymore, removing from save."),
4021 }
while (xml_nextNode(node));
4033 xmlNodePtr node = parent->xmlChildrenNode;
4035 xml_onlyNodes(node);
4037 if (!xml_isNode( node,
"license" ))
4040 const char *name = xml_get( node );
4042 WARN( _(
"License node is missing name." ) );
4046 }
while (xml_nextNode(node));
4058 xmlNodePtr node = parent->xmlChildrenNode;
4061 xml_onlyNodes(node);
4063 if (!xml_isNode( node,
"item" ))
4066 xmlr_attr_int_def( node,
"quantity", q, 1 );
4067 const char *name = xml_get( node );
4069 WARN( _(
"Inventory item node is missing name." ) );
4073 }
while (xml_nextNode(node));
4085 xmlNodePtr node = parent->xmlChildrenNode;
4090 if (!xml_isNode(node,
"escort"))
4093 xmlr_attr_strd( node,
"type", buf );
4094 xmlr_attr_strd( node,
"name", name );
4096 name = xml_getStrd( node );
4097 if (strcmp(buf,
"bay")==0)
4100 else if (strcmp(buf,
"fleet")==0) {
4105 WARN(_(
"Fleet ship '%s' is deployed despite not being marked for deployal!"), ps->
p->
name);
4109 WARN(_(
"Fleet ship '%s' is deployed despite not being space worthy!"), ps->
p->
name);
4114 WARN(_(
"Escort has invalid type '%s'."), buf);
4117 }
while (xml_nextNode(node));
4129 xmlNodePtr node = parent->xmlChildrenNode;
4131 xml_onlyNodes(node);
4142 if (xml_isNode(node,
"last_played")) {
4146 else if (xml_isNode(node,
"date_created")) {
4150 else if (xml_isNode(node,
"ships_destroyed")) {
4151 xmlNodePtr cur = node->xmlChildrenNode;
4153 char buf[STRMAX_SHORT];
4158 strncpy( buf, (
const char*)cur->name,
sizeof(buf)-1 );
4159 for (
size_t i=0; i<strlen(buf); i++)
4164 if (
class==SHIP_CLASS_NULL) {
4165 WARN(_(
"Unknown ship class '%s' when parsing 'ships_destroyed' node!"), (
const char*)cur->name );
4170 }
while (xml_nextNode(cur));
4172 }
while (xml_nextNode(node));
4184 DEBUG( _(
"Outfit '%s' does not fit designated slot on player's pilot '%s', adding to stock."),
4192 DEBUG(_(
"Outfit '%s' does not fit on player's pilot '%s', adding to stock."),
4209 const char *name = xml_get(node);
4211 WARN(_(
"Empty ship slot node found, skipping."));
4226 xmlr_attr_int(node,
"quantity",q);
4241 int id, autoweap, fuel, aim_lines, active_set;
4242 const Ship *ship_parsed;
4252 xmlr_attr_strd( parent,
"name", name );
4253 xmlr_attr_strd( parent,
"model", model );
4254 xmlr_attr_int_def( parent,
"favourite", ps.
favourite, 0 );
4255 xmlr_attr_int_def( parent,
"deployed", ps.
deployed, 0 );
4258 pilot_clearFlagsRaw( flags );
4260 pilot_setFlagRaw( flags, PILOT_PLAYER );
4261 pilot_setFlagRaw( flags, PILOT_NO_OUTFITS );
4264 if (!is_player && strcmp( name,
player.
p->
name ) == 0) {
4265 DEBUG( _(
"Ignoring player-owned ship '%s': duplicate of player's current ship."), name );
4273 if (ship_parsed == NULL) {
4274 WARN(_(
"Player ship '%s' not found!"), model);
4306 node = parent->xmlChildrenNode;
4308 xml_onlyNodes(node);
4311 xmlr_strd(node,
"acquired",ps.
acquired);
4312 if (xml_isNode(node,
"acquired_date")) {
4324 if (xml_isNode(node,
"ships_destroyed")) {
4325 xmlNodePtr cur = node->xmlChildrenNode;
4327 char buf[STRMAX_SHORT];
4332 strncpy( buf, (
const char*)cur->name,
sizeof(buf)-1 );
4333 for (
size_t i=0; i<strlen(buf); i++)
4338 if (
class==SHIP_CLASS_NULL) {
4339 WARN(_(
"Unknown ship class '%s' when parsing 'ships_destroyed' node!"), (
const char*)cur->name );
4344 }
while (xml_nextNode(cur));
4348 xmlr_int(node,
"fuel",fuel);
4351 if (xml_isNode(node,
"outfits_structure")) {
4352 xmlNodePtr cur = node->xmlChildrenNode;
4356 if (!xml_isNode(cur,
"outfit")) {
4357 WARN(_(
"Save has unknown '%s' tag!"),xml_get(cur));
4360 xmlr_attr_int_def( cur,
"slot", n, -1 );
4362 WARN(_(
"Outfit slot out of range, not adding to ship."));
4366 }
while (xml_nextNode(cur));
4369 else if (xml_isNode(node,
"outfits_utility")) {
4370 xmlNodePtr cur = node->xmlChildrenNode;
4374 if (!xml_isNode(cur,
"outfit")) {
4375 WARN(_(
"Save has unknown '%s' tag!"),xml_get(cur));
4378 xmlr_attr_int_def( cur,
"slot", n, -1 );
4380 WARN(_(
"Outfit slot out of range, not adding."));
4384 }
while (xml_nextNode(cur));
4387 else if (xml_isNode(node,
"outfits_weapon")) {
4388 xmlNodePtr cur = node->xmlChildrenNode;
4392 if (!xml_isNode(cur,
"outfit")) {
4393 WARN(_(
"Save has unknown '%s' tag!"),xml_get(cur));
4396 xmlr_attr_int_def( cur,
"slot", n, -1 );
4398 WARN(_(
"Outfit slot out of range, not adding."));
4402 }
while (xml_nextNode(cur));
4405 else if (xml_isNode(node,
"outfits_intrinsic")) {
4406 xmlNodePtr cur = node->xmlChildrenNode;
4409 if (!xml_isNode(cur,
"outfit")) {
4410 WARN(_(
"Save has unknown '%s' tag!"),xml_get(cur));
4416 WARN(_(
"Player ship '%s' has intrinsic outfit '%s' exceeding limits! Removing."),ship->
name,o->
name);
4420 }
while (xml_nextNode(cur));
4423 else if (xml_isNode(node,
"commodities")) {
4424 xmlNodePtr cur = node->xmlChildrenNode;
4426 if (xml_isNode(cur,
"commodity")) {
4429 xmlr_attr_int( cur,
"quantity", quantity );
4430 xmlr_attr_int_def( cur,
"id", cid, 0 );
4435 WARN(_(
"Unknown commodity '%s' detected, removing."), xml_get(cur));
4441 if ((quantity==0) && (cid==0))
4442 WARN(_(
"Adding cargo '%s' to ship '%s' that is not a mission cargo with quantity=0!"), com->
name, ship->
name );
4445 }
while (xml_nextNode(cur));
4449 }
while (xml_nextNode(node));
4460 DEBUG(_(
"Player ship '%s' failed slot validity check , removing all outfits and adding to stock."),
4473 for (
int i=0; i<PILOT_WEAPON_SETS; i++)
4478 node = parent->xmlChildrenNode;
4482 if (xml_isNode(node,
"vars")) {
4486 else if (!xml_isNode(node,
"weaponsets"))
4490 xmlr_attr_int( node,
"autoweap", autoweap );
4493 xmlr_attr_int_def( node,
"active_set", active_set, -1 );
4496 xmlr_attr_int( node,
"aim_lines", aim_lines );
4499 cur = node->xmlChildrenNode;
4501 int in_range, manual, weap_type, volley;
4505 if (!xml_isNode(cur,
"weaponset")) {
4506 WARN(_(
"Player ship '%s' has unknown node '%s' in 'weaponsets' (expected 'weaponset')."),
4507 ship->
name, cur->name);
4512 xmlr_attr_int_def(cur,
"id",
id, -1);
4514 WARN(_(
"Player ship '%s' missing 'id' tag for weapon set."),ship->
name);
4517 if ((
id < 0) || (
id >= PILOT_WEAPON_SETS)) {
4518 WARN(_(
"Player ship '%s' has invalid weapon set id '%d' [max %d]."),
4519 ship->
name,
id, PILOT_WEAPON_SETS-1 );
4527 xmlr_attr_int( cur,
"inrange", in_range );
4532 xmlr_attr_int( cur,
"manual", manual );
4537 xmlr_attr_int( cur,
"volley", volley );
4545 xmlr_attr_int_def( cur,
"type", weap_type, -1 );
4546 if (weap_type == -1) {
4547 WARN(_(
"Player ship '%s' missing 'type' tag for weapon set."),ship->
name);
4553 ccur = cur->xmlChildrenNode;
4557 xml_onlyNodes(ccur);
4560 if (!xml_isNode(ccur,
"weapon")) {
4561 WARN(_(
"Player ship '%s' has unknown 'weaponset' child node '%s' (expected 'weapon')."),
4562 ship->
name, ccur->name );
4567 xmlr_attr_int_def( ccur,
"level", level, -1 );
4569 WARN(_(
"Player ship '%s' missing 'level' tag for weapon set weapon."), ship->
name);
4572 weapid = xml_getInt(ccur);
4574 WARN(_(
"Player ship '%s' has invalid weapon id %d [max %d]."),
4582 }
while (xml_nextNode(ccur));
4583 }
while (xml_nextNode(cur));
4584 }
while (xml_nextNode(node));
4591 if (active_set >= 0 && active_set < PILOT_WEAPON_SETS)
4621 if (pilot_isFlag(
player.
p, PILOT_STEALTH)) {
4634 player_message(
"#r%s", _(
"Unable to stealth: missiles locked on!") );
4636 player_message(
"#r%s", _(
"Unable to stealth: other pilots nearby!") );
void ai_think(Pilot *pilot, double dt, int dotask)
Heart of the AI, brains of the pilot.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
#define array_front(ptr_array)
Returns the first element in the array.
#define array_erase(ptr_array, first, last)
Erases elements in interval [first, last).
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
#define array_back(ptr_array)
Returns the last element in the array.
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
int player_canBoard(int noisy)
Sees if the pilot can board a pilot.
int player_tryBoard(int noisy)
Attempt to board the player's target.
void cam_setZoom(double zoom)
Sets the camera zoom.
void cam_setTargetPilot(unsigned int follow, int soft_over)
Sets the target to follow.
void cam_setTargetPos(double x, double y, int soft_over)
Sets the camera target to a position.
double cam_getZoom(void)
Gets the camera zoom.
int cam_getTarget(void)
Returns the camera's current target.
void claim_clear(void)
Clears the claims on all systems.
void col_blend(glColour *blend, const glColour *fg, const glColour *bg, float alpha)
Blends two colours.
int comm_openPilot(unsigned int pilot)
Opens the communication dialogue with a pilot.
int comm_openSpob(Spob *spob)
Opens a communication dialogue with a spob.
Commodity * commodity_get(const char *name)
Gets a commodity by name.
void dialogue_alert(const char *fmt,...)
Displays an alert popup with only an ok button and a message.
char * dialogue_input(const char *title, int min, int max, const char *fmt,...)
Creates a dialogue that allows the player to write a message.
void dialogue_msg(const char *caption, const char *fmt,...)
Opens a dialogue window with an ok button and a message.
int dialogue_YesNo(const char *caption, const char *fmt,...)
Runs a dialogue with both yes and no options.
int economy_init(void)
Initializes the economy.
void economy_clearKnown(void)
Clears all system knowledge.
void equipment_regenLists(unsigned int wid, int outfits, int ships)
Regenerates the equipment window lists.
void escort_freeList(Pilot *p)
Remove all escorts from a pilot.
int escort_addList(Pilot *p, const Ship *ship, EscortType_t type, unsigned int id, int persist)
Adds an escort to the escort list of a pilot.
void escort_rmListIndex(Pilot *p, int i)
Remove from escorts list.
int escort_clearDeployed(Pilot *p)
Clears deployed escorts of a pilot.
int escorts_jump(const Pilot *parent, const JumpPoint *jp)
Have a pilot order its escorts to jump.
int event_start(const char *name, unsigned int *id)
Starts an event.
const char * event_dataName(int dataid)
Gets the event data name from id.
void events_cleanup(void)
Cleans up and removes active events.
int event_dataID(const char *evdata)
Gets the event data id from name.
void events_trigger(EventTrigger_t trigger)
Runs all the events matching a trigger.
void factions_reset(void)
Resets player standing and flags of factions to default.
int areEnemies(int a, int b)
Checks whether two factions are enemies.
void factions_clearDynamic(void)
Clears dynamic factions.
int faction_get(const char *name)
Gets a faction ID by name.
int areAllies(int a, int b)
Checks whether two factions are allies or not.
void gui_clearMessages(void)
Clears the GUI messages.
void gui_setTarget(void)
Player just changed their pilot target.
void gui_setDefaults(void)
const char * gui_pick(void)
Determines which GUI should be used.
int gui_load(const char *name)
Attempts to load the actual GUI.
void gui_radarGetRes(double *res)
Outputs the radar's resolution.
void gui_forceBlink(void)
Force sets the spob and pilot radar blink.
void gui_cleanup(void)
Cleans up the GUI.
void gui_setNav(void)
Player just changed their nav computer target.
void player_message(const char *fmt,...)
Adds a mesg to the queue to be displayed on screen.
int hooks_runParam(const char *stack, const HookParam *param)
Runs all the hooks of stack.
int hooks_runParamDeferred(const char *stack, const HookParam *param)
Runs all the hooks of stack in the next frame. Does not trigger right away.
int hooks_run(const char *stack)
Runs all the hooks of stack.
int intro_display(const char *text, const char *mus)
Displays the introduction sequence.
void takeoff(int delay, int nosave)
Makes the player take off if landed.
unsigned int land_getWid(int window)
Gets the WID of a window by type.
void land_cleanup(void)
Cleans up some land-related variables.
void land(Spob *p, int load)
Opens up all the land dialogue stuff.
void land_refuel(void)
Refuels the player's current ship, if possible.
int outfits_filter(const Outfit **outfits, int n, int(*filter)(const Outfit *), const char *name)
Applies a filter function and string to a list of outfits.
int load_refresh(void)
Loads or refreshes saved games for the player.
const nsave_t * load_getList(const char *name)
Gets the array (array.h) of loaded saves.
int lvar_save(const lvar *arr, xmlTextWriterPtr writer)
Saves the mission variables.
lvar * lvar_load(xmlNodePtr parent)
Loads the vars from XML file.
Mission ** player_missions
void missions_run(MissionAvailability loc, int faction, const Spob *pnt, const StarSystem *sys)
Runs missions matching location, all Lua side and one-shot.
int mission_start(const char *name, unsigned int *id)
Starts a mission.
int mission_getID(const char *name)
Gets id from mission name.
void missions_cleanup(void)
Cleans up all the player's active missions.
const MissionData * mission_get(int id)
Gets a MissionData based on ID.
int music_choose(const char *situation)
Actually runs the music stuff, based on situation.
Header file with generic functions and naev-specifics.
const char * naev_version(int long_version)
Returns the version in a human readable string.
void * ndata_read(const char *path, size_t *filesize)
Reads a file from the ndata (will be NUL terminated).
int news_init(void)
Initiate news linked list with a stack.
int lua_isoutfit(lua_State *L, int ind)
Checks to see if ind is a outfit.
const Outfit * lua_tooutfit(lua_State *L, int ind)
Lua bindings to interact with outfits.
LuaPilot * lua_pushpilot(lua_State *L, LuaPilot pilot)
Pushes a pilot on the stack.
int lua_isship(lua_State *L, int ind)
Checks to see if ind is a ship.
const Ship * lua_toship(lua_State *L, int ind)
Lua bindings to interact with ships.
LuaSpob * lua_pushspob(lua_State *L, LuaSpob spob)
Pushes a spob on the stack.
void var_cleanup(void)
Cleans up all the mission variables.
int strsort(const void *p1, const void *p2)
Sort function for sorting strings with qsort().
void ntime_set(ntime_t t)
Sets the time absolutely, does NOT generate an event, used at init.
ntime_t ntime_get(void)
Gets the current time.
void ntime_inc(ntime_t t)
Sets the time relatively.
void ntime_getR(int *cycles, int *periods, int *seconds, double *rem)
Gets the current time broken into individual components.
void ntime_setR(int cycles, int periods, int seconds, double rem)
Loads time including remainder.
void gl_screenshot(const char *filename)
Takes a screenshot.
void gl_renderShader(double x, double y, double w, double h, double r, const SimpleShader *shd, const glColour *c, int center)
Renders a simple shader.
void gl_renderLine(double x1, double y1, double x2, double y2, const glColour *c)
Draws a line.
void gl_gameToScreenCoords(double *nx, double *ny, double bx, double by)
Converts in-game coordinates to screen coordinates.
void gl_screenToGameCoords(double *nx, double *ny, int bx, int by)
Converts screen coordinates to in-game coordinates.
void gl_renderCircle(double cx, double cy, double r, const glColour *c, int filled)
Draws a circle.
const Outfit * outfit_get(const char *name)
Gets an outfit by name.
int outfit_isLauncher(const Outfit *o)
Checks if outfit is a weapon launcher.
int outfit_isLocalMap(const Outfit *o)
Checks if outfit is a local space map.
int outfit_compareTech(const void *outfit1, const void *outfit2)
Function meant for use with C89, C99 algorithm qsort().
const Outfit * outfit_getW(const char *name)
Gets an outfit by name without warning on no-find.
int outfit_fitsSlot(const Outfit *o, const OutfitSlot *s)
Checks to see if an outfit fits a slot.
int outfit_isFighterBay(const Outfit *o)
Checks if outfit is a fighter bay.
int outfit_isMap(const Outfit *o)
Checks if outfit is a space map.
int outfit_isLicense(const Outfit *o)
Checks if outfit is a license.
int outfit_isGUI(const Outfit *o)
Checks if outfit is a GUI.
int outfit_licenseExists(const char *name)
Checks to see if a license exists.
void pause_setSpeed(double mod)
Adjusts the game's dt modifier.
void pilot_free(Pilot *p)
Frees and cleans up a pilot.
void pilot_stackRemove(Pilot *p)
Tries to remove a pilot from the stack.
int pilot_isHostile(const Pilot *p)
Checks to see if pilot is hostile to the player.
void pilot_cooldown(Pilot *p, int dochecks)
Begins active cooldown, reducing hull and outfit temperatures.
unsigned int pilot_getNearestPilot(const Pilot *p)
Get the nearest pilot to a pilot.
Pilot * pilot_getTarget(Pilot *p)
Gets the target of a pilot using a fancy caching system.
Pilot * pilot_createEmpty(const Ship *ship, const char *name, int faction, PilotFlags flags)
Creates a pilot without adding it to the stack.
double pilot_face(Pilot *p, double dir, double dt)
Tries to turn the pilot to face dir.
double pilot_getNearestPos(const Pilot *p, unsigned int *tp, double x, double y, int disabled)
Get the nearest pilot to a pilot from a certain position.
Pilot * pilot_setPlayer(Pilot *after)
Replaces the player's pilot with an alternate ship with the same ID.
void pilot_renderOverlay(Pilot *p)
Renders the pilot overlay.
void pilot_setAccel(Pilot *p, double accel)
Sets the pilot's accel.
void pilot_cooldownEnd(Pilot *p, const char *reason)
Terminates active cooldown.
credits_t pilot_modCredits(Pilot *p, credits_t amount)
Modifies the amount of credits the pilot has.
void pilot_hyperspaceAbort(Pilot *p)
Stops the pilot from hyperspacing.
void pilot_setTurn(Pilot *p, double turn)
Sets the pilot's turn.
int pilot_validTarget(const Pilot *p, const Pilot *target)
Checks to see if a pilot is a valid target for another pilot.
void pilot_reset(Pilot *pilot)
Resets a pilot.
int pilot_isFriendly(const Pilot *p)
Checks to see if pilot is friendly to the player.
PilotOutfitSlot * pilot_getDockSlot(Pilot *p)
Gets the dock slot of the pilot.
Pilot * pilot_get(unsigned int id)
Pulls a pilot out of the pilot_stack based on ID.
ntime_t pilot_hyperspaceDelay(const Pilot *p)
Calculates the hyperspace delay for a pilot.
double pilot_getNearestPosPilot(const Pilot *p, Pilot **tp, double x, double y, int disabled)
Get the nearest pilot to a pilot from a certain position.
static Pilot ** pilot_stack
void pilot_render(Pilot *p)
Renders the pilot.
Pilot *const * pilot_getAll(void)
Gets the pilot stack.
int pilot_canTarget(const Pilot *p)
Same as pilot_validTarget but without the range check.
credits_t pilot_worth(const Pilot *p, int count_unique)
Gets the price or worth of a pilot in credits.
double pilot_aimAngle(Pilot *p, const vec2 *pos, const vec2 *vel)
Returns the angle for a pilot to aim at another pilot.
unsigned int pilot_getNextID(unsigned int id, int mode)
Gets the next pilot based on id.
void pilots_cleanAll(void)
Even cleans up the player.
void pilot_update(Pilot *pilot, double dt)
Updates the pilot.
Pilot * pilot_create(const Ship *ship, const char *name, int faction, const char *ai, const double dir, const vec2 *pos, const vec2 *vel, const PilotFlags flags, unsigned int dockpilot, int dockslot)
Creates a new pilot.
unsigned int pilot_getPrevID(unsigned int id, int mode)
Gets the previous pilot based on ID.
int pilot_numOutfit(const Pilot *p, const Outfit *o)
Checks to see how many of an outfit a pilot has.
int pilot_hasCredits(const Pilot *p, credits_t amount)
Checks to see if the pilot has at least a certain amount of credits.
void pilot_setTarget(Pilot *p, unsigned int id)
Sets the target of the pilot.
int pilot_cargoMoveRaw(Pilot *dest, Pilot *src)
Moves cargo from one pilot to another without any checks.
int pilot_cargoAddRaw(Pilot *pilot, const Commodity *cargo, int quantity, unsigned int id)
Adds cargo without checking the pilot's free space.
int pilot_inRangePilot(const Pilot *p, const Pilot *target, double *dist2)
Check to see if a pilot is in sensor range of another.
int pilot_inRangeSpob(const Pilot *p, int target)
Check to see if a spob is in sensor range of the pilot.
void pilot_destealth(Pilot *p)
Destealths a pilot.
int pilot_stealth(Pilot *p)
Stealths a pilot.
int pilot_hasOutfitLimit(const Pilot *p, const char *limit)
Checks to see if a pilot has an outfit with a specific outfit type.
int pilot_slotsCheckSafety(const Pilot *p)
Pilot slot safety check - makes sure stats are safe.
int pilot_outfitLAdd(const Pilot *pilot, PilotOutfitSlot *po)
Outfit is added to a ship.
int pilot_maxAmmoO(const Pilot *p, const Outfit *o)
Gets the maximum available ammo for a pilot for a specific outfit.
void pilot_outfitLOnjumpin(Pilot *pilot)
Runs Lua outfits when pilot jumps into a system.
void pilot_calcStats(Pilot *pilot)
Recalculates the pilot's stats based on his outfits.
int pilot_addAmmo(Pilot *pilot, PilotOutfitSlot *s, int quantity)
Adds some ammo to the pilot stock.
int pilot_hasIntrinsic(const Pilot *pilot, const Outfit *outfit)
Gets how many copies of an intrinsic a pilot has.
int pilot_rmOutfitRaw(Pilot *pilot, PilotOutfitSlot *s)
Removes an outfit from the pilot without doing any checks.
int pilot_outfitLRemove(const Pilot *pilot, PilotOutfitSlot *po)
Outfit is removed froma ship.
int pilot_addOutfitRaw(Pilot *pilot, const Outfit *outfit, PilotOutfitSlot *s)
Adds an outfit to the pilot, ignoring CPU or other limits.
int pilot_rmOutfitIntrinsic(Pilot *pilot, const Outfit *outfit)
Removes an outfit from an intrinsic slot.
int pilot_isSpaceworthy(const Pilot *p)
Pilot safety check - makes sure stats are safe.
int pilot_addOutfitIntrinsic(Pilot *pilot, const Outfit *outfit)
Adds an outfit as an intrinsic slot.
void pilot_outfitLInitAll(Pilot *pilot)
Runs the pilot's Lua outfits init script.
void pilot_weapSetInrange(Pilot *p, int id, int inrange)
Changes the weapon set inrange property.
void pilot_weaponSafe(Pilot *p)
Sets the weapon set as safe.
int pilot_shoot(Pilot *p, int level)
Makes the pilot shoot.
void pilot_weapSetManual(Pilot *p, int id, int manual)
Changes the weapon set manual property.
void pilot_afterburnOver(Pilot *p)
Deactivates the afterburner.
void pilot_weapSetVolley(Pilot *p, int id, int volley)
Changes the weapon set volley property.
void pilot_shootStop(Pilot *p, int level)
Have pilot stop shooting their weapon.
void ws_copy(PilotWeaponSet dest[PILOT_WEAPON_SETS], const PilotWeaponSet src[PILOT_WEAPON_SETS])
Copies a weapon set over.
void ws_free(PilotWeaponSet ws[PILOT_WEAPON_SETS])
Frees a weapon set.
int pilot_outfitOffAll(Pilot *p)
Disables all active outfits for a pilot.
void pilot_weaponSetDefault(Pilot *p)
Gives the pilot a default weapon set.
void pilot_weapSetClear(Pilot *p, int id)
Clears a weapon set.
void pilot_weaponAuto(Pilot *p)
Tries to automatically set and create the pilot's weapon set.
void pilot_weapSetPress(Pilot *p, int id, int type)
Handles a weapon set press.
void pilot_weapSetType(Pilot *p, int id, WeaponSetType type)
Changes the weapon sets mode.
void pilot_weapSetAdd(Pilot *p, int id, const PilotOutfitSlot *o, int level)
Adds an outfit to a weapon set.
void player_hailStart(void)
Starts the hail sounds and aborts autoNav.
void player_stealth(void)
Input binding for toggling stealth for the player.
void player_weapSetPress(int id, double value, int repeat)
Handles keyboard events involving the player's weapon-set keys. It's valid to call this while gamepla...
int player_eventAlreadyDone(int id)
Checks to see if player has already completed a event.
int player_nships(void)
Gets the amount of ships player has in storage.
int player_save(xmlTextWriterPtr writer)
Save the freaking player in a freaking xmlfile.
void player_soundResume(void)
Resumes the ship's sounds.
static int player_saveShipSlot(xmlTextWriterPtr writer, const PilotOutfitSlot *slot, int i)
Saves an outfit slot.
int player_rmOutfit(const Outfit *o, int quantity)
Remove an outfit from the player's outfit stack.
void player_runHooks(void)
Runs hooks for the player.
static int player_shipsCompare(const void *arg1, const void *arg2)
PlayerShip_t compare function for qsort().
void player_updateSpecific(Pilot *pplayer, const double dt)
Does a player specific update.
static void player_clearEscorts(void)
Clears escorts to make sure deployment is safe.
int player_getOutfitsFiltered(const Outfit ***outfits, int(*filter)(const Outfit *o), const char *name)
Prepares two arrays for displaying in an image array.
int player_hasLicense(const char *license)
Checks to see if player has license.
void player_autohail(void)
Automatically tries to hail a pilot that hailed the player.
void player_dead(void)
Player got pwned.
void player_swapShip(const char *shipname, int move_cargo)
Swaps player's current ship with their ship named shipname.
static void player_renderAimHelper(double dt)
Renders the aim helper.
void player_cooldownBrake(void)
Starts braking or active cooldown.
void player_accel(double acc)
Start accelerating.
static double player_hailTimer
int player_ships(char **sships, glTexture **tships)
Returns a buffer with all the player's ships names.
void player_targetEscort(int prev)
Targets the pilot.
void player_targetAsteroidSet(int field, int id)
Sets the player's target asteroid.
static void player_parseShipSlot(xmlNodePtr node, Pilot *ship, PilotOutfitSlot *slot)
Parses a ship outfit slot.
static void player_renderStealthUnderlay(double dt)
Renders the stealth overlay for the player.
int player_addOutfit(const Outfit *o, int quantity)
Adds an outfit to the player outfit stack.
void player_soundPlay(int sound, int once)
Plays a sound at the player.
static int player_soundReserved
void player_new(void)
Creates a new player.
static PlayerShip_t * player_stack
void player_warp(double x, double y)
Warps the player to the new position.
static int player_parseDoneMissions(xmlNodePtr parent)
Parses player's done missions.
static PlayerShip_t * player_newShipMake(const char *name)
Actually creates the new ship.
static int player_parseEscorts(xmlNodePtr parent)
Parses the escorts from the escort node.
void player_checkLandAck(void)
Revokes landing authorization if the player's reputation is too low.
int player_numOutfits(void)
Gets the amount of different outfits in the player outfit stack.
static int player_parseShip(xmlNodePtr parent, int is_player)
Parses a player's ship.
void player_targetSet(unsigned int id)
Sets the player's target.
static int screenshot_cur
static void player_tryAddLicense(const char *name)
Tries to get an outfit for the player or looks for equivalents.
void player_render(double dt)
Renders the player.
void player_hailSpob(void)
Opens communication with the player's spob target.
credits_t player_shipPrice(const char *shipname, int count_unique)
Calculates the price of one of the player's ships.
void player_resetSpeed(void)
Resets the player speed stuff.
static int player_lastEngineSound
const PlayerShip_t * player_getShipStack(void)
Gets the array (array.h) of the player's ships.
static int player_outfitCompare(const void *arg1, const void *arg2)
qsort() compare function for PlayerOutfit_t sorting.
void player_targetHyperspaceSet(int id, int nomsg)
Sets the player's hyperspace target.
static char * player_message_noland
static int player_parseMetadata(xmlNodePtr parent)
Parses the player metadata.
void player_cleanup(void)
Cleans up player stuff like player_stack.
static int player_parseLicenses(xmlNodePtr parent)
Parses player's licenses.
void player_targetHyperspace(void)
Gets a hyperspace target.
static double player_timer
PlayerShip_t * player_newShip(const Ship *ship, const char *def_name, int trade, const char *acquired, int noname)
Creates a new ship for player.
void player_rmShip(const char *shipname)
Removes one of the player's ships.
int player_outfitOwnedTotal(const Outfit *o)
void player_hyperspacePreempt(int preempt)
Enables or disables jump points preempting spobs in autoface and target clearing.
PlayerShip_t * player_getPlayerShip(const char *shipname)
Gets a specific ship.
void player_toggleMouseFly(void)
Toggles mouse flying.
void player_targetNearest(void)
Player targets nearest pilot.
static PlayerOutfit_t * player_outfits
static credits_t player_payback
double player_dt_default(void)
Returns the player's total default time delta based on time dilation stuff.
void player_update(Pilot *pplayer, const double dt)
Player update function.
static const Ship * player_tryGetShip(const char *name)
Tries to get an ship for the player or looks for equivalents.
const char ** player_getLicenses()
Gets the array (array.h) of license names in the player's inventory.
void player_brokeHyperspace(void)
Player actually broke hyperspace (entering new system).
static credits_t player_creds
int player_getHypPreempt(void)
Returns whether the jump point target should preempt the spob target.
int player_missionAlreadyDone(int id)
Checks to see if player has already completed a mission.
void player_renderUnderlay(double dt)
Renders the player underlay.
static int player_hailCounter
int player_addEscorts(void)
Adds the player's escorts.
static int player_parseDoneEvents(xmlNodePtr parent)
Parses player's done missions.
#define RADAR_RES_DEFAULT
void player_soundStop(void)
Stops playing player sounds.
void player_restoreControl(int reason, const char *str)
Aborts autonav and other states that take control of the ship.
void player_addLicense(const char *license)
Gives the player a license.
credits_t player_modCredits(credits_t amount)
Modifies the amount of credits the player has.
int * player_eventsDoneList(void)
Gets a list of all the events the player has done.
int player_jump(void)
Actually attempts to jump in hyperspace.
void player_targetSpobSet(int id)
Sets the player's target spob.
static int player_filterSuitableSpob(Spob *p)
Filter function for space_getRndSpob.
void player_clear(void)
Clears the targets.
static const Outfit * player_tryGetOutfit(const char *name, int q)
Tries to get an outfit for the player or looks for equivalents.
static void player_addOutfitToPilot(Pilot *pilot, const Outfit *outfit, PilotOutfitSlot *s)
Adds outfit to pilot if it can.
static void player_spobOutOfRangeMsg(void)
Displays an out of range message for the player's currently selected spob.
static int player_runUpdaterScript(const char *type, const char *name, int q)
Runs the save updater script, leaving any result on the stack of naevL.
static Spob * player_parse(xmlNodePtr parent)
Parses the player node.
int player_hasShip(const char *shipname)
Sees if player has a ship of a name.
void player_accelOver(void)
Done accelerating.
static int player_gui_group
void player_think(Pilot *pplayer, const double dt)
Basically uses keyboard input instead of AI input. Used in pilot.c.
int player_land(int loud)
Try to land or target closest spob if no land target.
static int player_newMake(void)
Actually creates a new player.
static int player_saveShip(xmlTextWriterPtr writer, PlayerShip_t *pship)
Saves a ship.
static int player_hyper_group
void player_soundPause(void)
Pauses the ship's sounds.
static int player_saveEscorts(xmlTextWriterPtr writer)
Saves the player's escorts.
int player_hasCredits(credits_t amount)
Checks to see if the player has enough credits.
static int player_engine_group
void player_shipsSort(void)
Sorts the players ships.
void player_missionFinished(int id)
Marks a mission as completed.
int player_outfitOwned(const Outfit *o)
Gets how many of the outfit the player owns.
void player_targetClearAll(void)
Clears all player targets: hyperspace, spob, asteroid, etc...
static int * missions_done
static char ** player_licenses
void player_nolandMsg(const char *str)
Sets the no land message.
void player_targetPrev(int mode)
Cycles to previous target.
const PlayerOutfit_t * player_getOutfits(void)
Gets an array (array.h) of the player's outfits.
Spob * player_load(xmlNodePtr parent)
Loads the player stuff.
static void player_newSetup()
Sets up a new player.
static int player_ran_updater
static const Ship * player_ship
void player_soundPlayGUI(int sound, int once)
Plays a GUI sound (unaffected by time accel).
static void player_renderStealthOverlay(double dt)
Renders the stealth overlay for the player.
void player_targetClear(void)
Clears the player's ship, spob or hyperspace target, in that order.
void player_targetHostile(void)
Targets the nearest hostile enemy to the player.
static void player_initSound(void)
Initializes the player sounds.
static int player_parseInventory(xmlNodePtr parent)
Parses player's inventory.
void player_eventFinished(int id)
Marks a event as completed.
void player_screenshot(void)
Takes a screenshot.
void player_approach(void)
Logic to make the player approach a target pilot to board or spob to land on.
void player_destroyed(void)
Player blew up in a fireball.
void player_targetSpob(void)
Cycle through spob targets.
int player_init(void)
Initializes player stuff.
int * player_missionsDoneList(void)
Gets a list of all the missions the player has done.
static void player_checkHail(void)
Checks to see if player is still being hailed and clears hail counters if he isn't.
Pilot * player_getShip(const char *shipname)
Gets a specific ship.
static int player_thinkMouseFly(double dt)
Handles mouse flying based on cursor position.
void player_targetNext(int mode)
Cycles to next target.
static int player_saveMetadata(xmlTextWriterPtr writer)
Saves the player meta-data.
void player_hail(void)
Opens communication with the player's target.
void player_autonavEnd(void)
Ends the autonav.
void player_autonavResetSpeed(void)
Resets the game speed.
void player_autonavStart(void)
Starts autonav.
void player_autonavBoard(unsigned int p)
Starts autonav with a pilot to board.
void player_autonavSpob(const char *name, int tryland)
Starts autonav with a spob destination.
void player_autonavAbort(const char *reason)
Aborts autonav.
void player_thinkAutonav(Pilot *pplayer, double dt)
Handles autonav thinking.
int pfleet_deploy(PlayerShip_t *ps)
Deploys a player's pilot.
void pfleet_update(void)
Updates the used fleet capacity of the player.
const char ** player_guiList(void)
Gets the list of GUIs.
int player_guiAdd(const char *name)
Adds a gui to the player.
int player_guiCheck(const char *name)
Check if player has a GUI.
void player_guiCleanup(void)
Cleans up the player's GUI list.
int player_inventoryAdd(const char *name, int amount)
Adds an item to the player inventory.
static PlayerItem * inventory
void player_inventoryClear(void)
Clears the inventory and frees memory.
const PlayerItem * player_inventory(void)
Gets the whole player inventory.
ShipClass ship_classFromString(const char *str)
Gets the machine ship class identifier from a human readable string.
const Ship * ship_getW(const char *name)
Gets a ship based on its name without warning.
const char * ship_classToString(ShipClass class)
Gets the ship class name in human readable form.
const Ship * ship_get(const char *name)
Gets a ship based on its name.
void shiplog_clear(void)
Clear the shiplog.
int sound_createGroup(int size)
Creates a sound group.
void sound_pitchGroup(int group, double pitch)
Sets the pitch of a group.
void sound_resumeGroup(int group)
Resumes all the sounds in a group.
void sound_speedGroup(int group, int enable)
Sets whether or not the speed affects a group.
int sound_playGroup(int group, int sound, int once)
Plays a sound in a group.
void sound_stopGroup(int group)
Stops all the sounds in a group.
void sound_stopAll(void)
Stops all the playing voices.
int sound_get(const char *name)
Gets the buffer to sound of name.
void sound_pauseGroup(int group)
Pauses all the sounds in a group.
void sound_volumeGroup(int group, double volume)
Sets the volume of a group.
void sound_setSpeed(double s)
Sets the speed to play the sound at.
void space_init(const char *sysname, int do_simulate)
Initializes the system.
void space_gfxUnload(StarSystem *sys)
Unloads all the graphics for a star system.
Spob * spob_get(const char *spobname)
Gets a spob based on its name.
const char * space_getRndSpob(int landable, unsigned int services, int(*filter)(Spob *p))
Gets the name of a random spob.
int spob_index(const Spob *p)
Gets the ID of a spob.
char spob_getColourChar(const Spob *p)
Gets the spob colour char.
StarSystem * system_get(const char *sysname)
Get the system from its name.
const char * spob_getSystem(const char *spobname)
Get the name of a system from a spobname.
int space_calcJumpInPos(const StarSystem *in, const StarSystem *out, vec2 *pos, vec2 *vel, double *dir, const Pilot *p)
Calculates the jump in pos for a pilot.
void spob_updateLand(Spob *p)
Updates the land possibilities of a spob.
void space_clearKnown(void)
Clears all system knowledge.
const char * spob_name(const Spob *p)
Gets the translated name of a spob.
void space_gfxLoad(StarSystem *sys)
Loads all the graphics for a star system.
int space_hyperspace(Pilot *p)
Tries to get the pilot into hyperspace.
const char * start_acquired(void)
Gets the module's starting ship was acquired.
const char * start_event(void)
Gets the starting event of the player.
const char * start_mission(void)
Gets the starting mission of the player.
void start_position(double *x, double *y)
Gets the starting position of the player.
const char * start_chapter(void)
Gets the player's starting chapter.
const char * start_ship(void)
Gets the module player starting ship.
ntime_t start_date(void)
Gets the starting date.
const char * start_shipname(void)
Gets the module's starting ship's name.
const char * start_system(void)
Gets the starting system name.
unsigned int start_credits(void)
Gets the player's starting credits.
Represents an asteroid field anchor.
Represents a single asteroid.
The actual hook parameter.
A ship outfit, depends radically on the type.
OutfitAfterburnerData afb
Stores a pilot commodity.
const Commodity * commodity
Stores an outfit the pilot has.
A pilot Weapon Set Outfit.
A weapon set represents a set of weapons that have an action.
PilotWeaponSetOutfit * slots
The representation of an in-game pilot.
PilotWeaponSet weapon_sets[PILOT_WEAPON_SETS]
PilotCommodity * commodities
PilotOutfitSlot * outfit_structure
PilotOutfitSlot ** outfits
PilotOutfitSlot * outfit_utility
PilotOutfitSlot * outfit_intrinsic
PilotOutfitSlot * afterburner
PilotOutfitSlot * outfit_weapon
Represents an item in the player inventory.
unsigned int death_counter
unsigned int landed_times
unsigned int ships_destroyed[SHIP_CLASS_TOTAL]
unsigned int jumped_times
PilotWeaponSet weapon_sets[PILOT_WEAPON_SETS]
unsigned int jumped_times
unsigned int ships_destroyed[SHIP_CLASS_TOTAL]
unsigned int death_counter
unsigned int landed_times
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
Abstraction for rendering sprite sheets.
Contains a mission variable.
void diff_clear(void)
Removes all active diffs. (Call before economy_destroy().)