24#include "difficulty.h"
37#include "land_outfits.h"
41#include "map_overlay.h"
49#include "nlua_outfit.h"
58#include "player_gui.h"
59#include "player_fleet.h"
60#include "player_inventory.h"
88#define RADAR_RES_DEFAULT 50.
173static int preemption = 0;
248 _(
"Please write your name:") );
259 _(
"You already have a pilot named %s. Their autosave and backup save will be overwritten. Do you wish to continue?"),
player.
name);
281 WARN(_(
"Failed to run start mission '%s'."),
start_mission());
287 WARN(_(
"Failed to run start event '%s'."),
start_event());
305 const char *shipname, *acquired;
326 WARN(_(
"Ship not properly set by module."));
331 ps =
player_newShip( ship, shipname, 0, acquired, (shipname==NULL) ? 0 : 1 );
383 int trade,
const char *acquired,
int noname )
385 char *ship_name, *old_name;
393 _(
"Please name your new ship:") );
398 if (ship_name == NULL) {
402 if (def_name == NULL)
407 len = strlen(def_name)+10;
408 ship_name = malloc( len );
409 strcpy( ship_name, def_name );
411 snprintf( ship_name, len,
"%s %d", def_name, i );
419 _(
"Please do not give the ship the same name as another of your ships."));
424 ERR(_(
"Player ship isn't valid… This shouldn't happen!"));
430 ps->
acquired = (acquired!=NULL) ? strdup( acquired ) : NULL;
461 pilot_clearFlagsRaw( flags );
462 pilot_setFlagRaw( flags, PILOT_PLAYER );
463 pilot_setFlagRaw( flags, PILOT_NO_OUTFITS );
466 player_rmFlag( PLAYER_CREATING );
471 pilot_setFlagRaw( flags, PILOT_PLAYER_FLEET );
482 ERR(_(
"Something seriously wonky went on, newly created player does not exist, bailing!"));
519 WARN( _(
"Unable to swap player.p with ship '%s': ship does not exist!"), shipname );
537 if (e->
id == ps->
p->
id )
619 hparam[0].
type = HOOK_PARAM_STRING;
621 hparam[1].
type = HOOK_PARAM_STRING;
623 hparam[2].
type = HOOK_PARAM_STRING;
625 hparam[3].
type = HOOK_PARAM_STRING;
627 hparam[4].
type = HOOK_PARAM_SENTINEL;
657 WARN( _(
"Unable to find price for player's ship '%s': ship does not exist!"), shipname );
675 if (strcmp(shipname,ps->
p->
name)!=0)
679 pilot_rmFlag( ps->
p, PILOT_NOFREE );
773 pilot_rmFlag( ps->
p, PILOT_NOFREE );
799 difficulty_setLocal( NULL );
810 player_setFlag(PLAYER_CREATING);
927 player_rmFlag( PLAYER_NOLAND );
960 if (player_isFlag(PLAYER_DESTROYED)) {
968 if ((
player.
p == NULL) || (
player.
p->
id == 0) || player_isFlag(PLAYER_CREATING) ||
969 pilot_isFlag(
player.
p, PILOT_HIDE))
973 if (pilot_isFlag(
player.
p, PILOT_STEALTH ))
978 && !pilot_isFlag(
player.
p, PILOT_HYPERSPACE ) && !pilot_isFlag(
player.
p, PILOT_DISABLED )
979 && !pilot_isFlag(
player.
p, PILOT_LANDING ) && !pilot_isFlag(
player.
p, PILOT_TAKEOFF )
980 && !player_isFlag( PLAYER_CINEMATICS_GUI ))
996 if ((
player.
p == NULL) || player_isFlag(PLAYER_CREATING) ||
997 pilot_isFlag(
player.
p, PILOT_HIDE))
1000 if (pilot_isFlag(
player.
p, PILOT_STEALTH ))
1028 if (pilot_isDisabled(t))
1037 glUseProgram( shaders.stealthaura.program );
1049 double x, y, r,
st, z;
1066 glUseProgram( shaders.stealthmarker.program );
1067 glUniform1f( shaders.stealthmarker.paramf,
st );
1068 gl_renderShader( x, y, r*z, r*z, 0., &shaders.stealthmarker, &col, 1 );
1077 double a,
b,
d, x1, y1, x2, y2, r, theta;
1091 theta = 22.*M_PI/180.;
1094 d =
ABS( angle_diff(a,b) / (2*theta) );
1107 c.g =
d*0.2 + (1.-
d)*0.8;
1110 col_gammaToLinear( &
c );
1118 glUseProgram(shaders.crosshairs.program);
1119 glUniform1f(shaders.crosshairs.paramf, 1.);
1129 glColour c3 = cBlack;
1149 if (pilot_isFlag(pplayer,PILOT_DEAD)) {
1161 if (pilot_isFlag( pplayer, PILOT_MANUAL_CONTROL ) || pilot_isFlag( pplayer, PILOT_HIDE )) {
1169 if (player_isFlag(PLAYER_AUTONAV)) {
1177 if (!facing && player_isFlag(PLAYER_MFLY))
1181 if (!facing && player_isFlag(PLAYER_FACE)) {
1185 if (target != NULL) {
1220 if (player_isFlag(PLAYER_REVERSE)) {
1234 if (player_isFlag(PLAYER_TURN_LEFT))
1236 if (player_isFlag(PLAYER_TURN_RIGHT))
1238 turn =
CLAMP( -1., 1., turn );
1248 if (player_isFlag(PLAYER_PRIMARY)) {
1250 player_setFlag(PLAYER_PRIMARY_L);
1252 else if (player_isFlag(PLAYER_PRIMARY_L)) {
1254 player_rmFlag(PLAYER_PRIMARY_L);
1257 if (player_isFlag(PLAYER_SECONDARY)) {
1259 player_setFlag(PLAYER_SECONDARY_L);
1261 else if (player_isFlag(PLAYER_SECONDARY_L)) {
1263 player_rmFlag(PLAYER_SECONDARY_L);
1275 && !pilot_isFlag(
player.
p, PILOT_HYP_PREP)
1276 && !pilot_isFlag(
player.
p, PILOT_HYPERSPACE) )
1277 acc = -PILOT_REVERSE_THRUST;
1294 if (!player_isFlag(PLAYER_DESTROYED))
1310 if (pilot_isFlag(pplayer, PILOT_AFTERBURNER))
1312 else if (pilot_isFlag(pplayer, PILOT_HYPERSPACE))
1325 if (engsound >= 0) {
1363 for (
int j=0; j<ast->
nb; j++) {
1376 hparam[0].
type = HOOK_PARAM_ASTEROID;
1377 hparam[0].
u.
ast.parent = ast->
id;
1378 hparam[0].
u.
ast.id = a->id;
1379 hparam[1].
type = HOOK_PARAM_SENTINEL;
1396 if (repeat || (
player.
p == NULL))
1399 type = (value>=0) ? +1 : -1;
1404 if ((type>0) && (pilot_isFlag(
player.
p, PILOT_HYP_PREP) ||
1405 pilot_isFlag(
player.
p, PILOT_HYPERSPACE) ||
1406 pilot_isFlag(
player.
p, PILOT_LANDING) ||
1407 pilot_isFlag(
player.
p, PILOT_TAKEOFF)))
1434 if (reason != PINPUT_AUTONAV) {
1436 if ((!
paused || reason != PINPUT_MOVEMENT))
1440 if (reason != PINPUT_BRAKING) {
1441 pilot_rmFlag(
player.
p, PILOT_BRAKING);
1442 pilot_rmFlag(
player.
p, PILOT_COOLDOWN_BRAKE);
1443 if (pilot_isFlag(
player.
p, PILOT_COOLDOWN))
1462 WARN(_(
"Trying to set player's spob target to invalid ID '%d'"),
id);
1466 if ((
player.
p == NULL) || pilot_isFlag(
player.
p, PILOT_LANDING ))
1473 player_rmFlag(PLAYER_LANDACK);
1496 if ((
player.
p == NULL) || pilot_isFlag(
player.
p, PILOT_LANDING ))
1521 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ))
1556 return PLAYER_LAND_DENIED;
1560 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ) ||
1562 return PLAYER_LAND_DENIED;
1565 if ((pilot_isFlag(
player.
p, PILOT_LANDING) ||
1566 pilot_isFlag(
player.
p, PILOT_TAKEOFF)))
1567 return PLAYER_LAND_DENIED;
1572 return PLAYER_LAND_DENIED;
1583 spob_hasService(spob,SPOB_SERVICE_LAND) &&
1584 ((tp==-1) || ((td == -1) || (td >
d)))) {
1594 return PLAYER_LAND_DENIED;
1601 return PLAYER_LAND_AGAIN;
1604 if (player_isFlag(PLAYER_NOLAND)) {
1606 return PLAYER_LAND_DENIED;
1608 else if (pilot_isFlag(
player.
p, PILOT_NOLAND)) {
1609 player_message(
"#r%s", _(
"Docking stabilizers malfunctioning, cannot land.") );
1610 return PLAYER_LAND_DENIED;
1616 if ((spob->
lua_can_land==LUA_NOREF) && !spob_hasService(spob, SPOB_SERVICE_LAND)) {
1618 return PLAYER_LAND_DENIED;
1626 return PLAYER_LAND_DENIED;
1628 else if (!player_isFlag(PLAYER_LANDACK)) {
1629 if (spob_hasService(spob,SPOB_SERVICE_INHABITED)) {
1635 spob_name(spob), _(
"Landing authorized.") );
1639 return PLAYER_LAND_DENIED;
1645 player_setFlag(PLAYER_LANDACK);
1654 return PLAYER_LAND_AGAIN;
1659 return PLAYER_LAND_AGAIN;
1678 lua_rawgeti(naevL, LUA_REGISTRYINDEX, spob->
lua_land);
1681 if (nlua_pcall( spob->
lua_env, 2, 0 )) {
1682 WARN(_(
"Spob '%s' failed to run '%s':\n%s"), spob->
name,
"land", lua_tostring(naevL,-1));
1686 return PLAYER_LAND_OK;
1693 pilot_setFlag(
player.
p, PILOT_LANDING );
1697 return PLAYER_LAND_OK;
1708 if ((
player.
p == NULL) || !player_isFlag(PLAYER_LANDACK))
1713 WARN(_(
"Player has landing permission, but no valid spob targeted."));
1720 if (p->can_land || (p->land_override > 0))
1723 player_rmFlag(PLAYER_LANDACK);
1746void player_board (
void)
1749 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ) ||
1761 if ((!pilot_isDisabled(p) && !pilot_isFlag(p,PILOT_BOARDABLE)) ||
1762 pilot_isFlag(p,PILOT_NOBOARD)) {
1764 player_message(
"#r%s", _(
"You need a target to board first!") );
1787 WARN(_(
"Trying to set player's hyperspace target to invalid ID '%d'"),
id);
1791 if (pilot_isFlag(
player.
p, PILOT_HYP_PREP) ||
1792 pilot_isFlag(
player.
p, PILOT_HYP_BEGIN) ||
1793 pilot_isFlag(
player.
p, PILOT_HYPERSPACE))
1799 if ((old !=
id) && (
id >= 0))
1803 if (!nomsg && (old !=
id) && ((
player.
autonav == AUTONAV_JUMP_APPROACH) ||
1818 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ))
1841 map_select( NULL , 0);
1843 map_select(
cur_system->jumps[
id ].target, 0 );
1853 preemption = preempt;
1888 player_message( _(
"#rReceiving hail! Press #b%s#0 to respond."), buf );
1906 if (pilot_isFlag(
player.
p, PILOT_HYPERSPACE))
1910 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ) ||
1920 if (dist < mindist && jp_isUsable(&
cur_system->jumps[i])) {
1939 if (pilot_isFlag(
player.
p, PILOT_HYP_PREP)) {
1955 player_message(
"#r%s", _(
"You do not have enough fuel to hyperspace jump."));
1979 StarSystem *sys, *destsys;
2021 pilot_rmFlag(
player.
p, PILOT_HYPERSPACE );
2022 pilot_rmFlag(
player.
p, PILOT_HYP_BEGIN );
2023 pilot_rmFlag(
player.
p, PILOT_HYP_BRAKE );
2024 pilot_rmFlag(
player.
p, PILOT_HYP_PREP );
2032 if (pilot_isFlag(p, PILOT_PERSIST) || pilot_isFlag(p, PILOT_PLAYER)) {
2041 p->itimer = PILOT_PLAYER_NONTARGETABLE_JUMPIN_DELAY;
2042 pilot_setFlag( p, PILOT_NONTARGETABLE );
2045 pilot_rmFlag( p, PILOT_HYPERSPACE );
2046 pilot_rmFlag( p, PILOT_HYP_BEGIN );
2047 pilot_rmFlag( p, PILOT_HYP_BRAKE );
2048 pilot_rmFlag( p, PILOT_HYP_PREP );
2053 if (player_isFlag(PLAYER_AUTONAV)) {
2059 destsys = map_getDestination( &map_npath );
2061 "#oAutonav continuing until %s (%d jump left).",
2062 "#oAutonav continuing until %s (%d jumps left).",
2064 (sys_isKnown(destsys) ? _(destsys->name) : _(
"Unknown")),
2090 if ((
player.
p == NULL) || pilot_isFlag(
player.
p, PILOT_HYP_PREP) ||
2091 pilot_isFlag(
player.
p, PILOT_HYPERSPACE))
2128 if ((old !=
id) && player_isFlag(PLAYER_AUTONAV) &&
2166 if (tp == PLAYER_ID || ((td <
d))) {
2208 !pilot_isFlag(
player.
p, PILOT_HYP_PREP)) {
2303 if (PHYSFS_mkdir(
"screenshots") == 0) {
2304 WARN(_(
"Aborting screenshot"));
2310 snprintf( filename,
sizeof(filename),
"screenshots/screenshot%03d.png",
screenshot_cur );
2311 if (!PHYSFS_exists( filename ))
2316 WARN(_(
"You have reached the maximum amount of screenshots [999]"));
2336 if (pilot_isFlag(p, PILOT_HAILING))
2352 player_message( _(
"#r%s is out of comm range, unable to contact."), name );
2361 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ) ||
2369 if (spob_isFlag(spob, SPOB_UNINHABITED))
2389 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ))
2410 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ) ||
2420 if (pilot_isFlag(p, PILOT_HAILING)) {
2432 player_message(
"#r%s", _(
"You haven't been hailed by any pilots.") );
2443 if (!player_isFlag(PLAYER_MFLY)) {
2446 player_setFlag(PLAYER_MFLY);
2450 player_rmFlag(PLAYER_MFLY);
2465 if (pilot_isFlag(
player.
p, PILOT_TAKEOFF))
2469 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ) ||
2473 stopped = pilot_isStopped(
player.
p);
2474 if (stopped && !pilot_isFlag(
player.
p, PILOT_COOLDOWN))
2477 pilot_setFlag(
player.
p, PILOT_BRAKING);
2478 pilot_setFlag(
player.
p, PILOT_COOLDOWN_BRAKE);
2489 double px, py, r, x, y;
2498 double acc =
CLAMP(0., 1., (r - 100.) / 200.);
2499 acc = 3. *
pow2(acc) - 2. * pow(acc, 3.);
2530 if (player_isFlag(PLAYER_DESTROYED))
2534 player_setFlag(PLAYER_DESTROYED);
2672 WARN(_(
"Player ship '%s' not found in stack"), shipname);
2691 WARN(_(
"Player ship '%s' not found in stack"), shipname);
2771 int(*filter)(
const Outfit *o ),
const char *name )
2884static int cmp_int(
const void *p1,
const void *p2 )
2886 const int *i1 = (
const int*) p1;
2887 const int *i2 = (
const int*) p2;
2888 return (*i1) - (*i2);
2914 mission_toLuaTable( naevL, m );
2915 h[0].
type = HOOK_PARAM_REF;
2916 h[0].
u.
ref = luaL_ref( naevL, LUA_REGISTRYINDEX );
2917 h[1].
type = HOOK_PARAM_SENTINEL;
2998 if (license == NULL)
3036 if (player_isFlag( PLAYER_HOOK_HYPER )) {
3038 player_rmFlag( PLAYER_HOOK_HYPER );
3040 if (player_isFlag( PLAYER_HOOK_JUMPIN)) {
3046 player_rmFlag( PLAYER_HOOK_JUMPIN );
3048 if (player_isFlag( PLAYER_HOOK_LAND )) {
3051 player_rmFlag( PLAYER_HOOK_LAND );
3094 pe->
solid->
dir = RNGF() * 2. * M_PI;
3097 vec2_cset( &pe->
solid->
vel, 0., 0. );
3100 if (e->
type != ESCORT_TYPE_BAY)
3106 pilot_setFlag( pe, PILOT_DELETE );
3107 WARN(_(
"Escort is undeployed, removing."));
3117 pilot_setFlag( pe, PILOT_DELETE );
3118 WARN(_(
"Escort is deployed past outfit limits, removing."));
3158 case ESCORT_TYPE_BAY:
3159 xmlw_startElem(writer,
"escort");
3160 xmlw_attr(writer,
"type",
"bay");
3161 xmlw_attr(writer,
"name",
"%s", e->
ship);
3162 xmlw_endElem(writer);
3165 case ESCORT_TYPE_FLEET:
3168 xmlw_startElem(writer,
"escort");
3169 xmlw_attr(writer,
"type",
"fleet");
3170 xmlw_attr(writer,
"name",
"%s", pe->
name);
3171 xmlw_endElem(writer);
3192 int cycles, periods, seconds;
3196 xmlw_startElem(writer,
"player");
3205 xmlw_elem(writer,
"gui",
"%s",
player.
gui);
3206 xmlw_elem(writer,
"mapOverlay",
"%d",ovr_isOpen());
3214 xmlw_startElem(writer,
"time");
3215 ntime_getR( &cycles, &periods, &seconds, &rem );
3216 xmlw_elem(writer,
"SCU",
"%d", cycles);
3217 xmlw_elem(writer,
"STP",
"%d", periods);
3218 xmlw_elem(writer,
"STU",
"%d", seconds);
3219 xmlw_elem(writer,
"Remainder",
"%lf", rem);
3220 xmlw_endElem(writer);
3227 xmlw_startElem(writer,
"ships");
3230 xmlw_endElem(writer);
3233 xmlw_startElem(writer,
"guis");
3236 xmlw_elem(writer,
"gui",
"%s",guis[i]);
3237 xmlw_endElem(writer);
3240 xmlw_startElem(writer,
"outfits");
3242 xmlw_startElem(writer,
"outfit");
3245 xmlw_endElem(writer);
3247 xmlw_endElem(writer);
3250 xmlw_startElem(writer,
"licenses");
3253 xmlw_endElem(writer);
3256 xmlw_startElem(writer,
"inventory");
3260 xmlw_startElem(writer,
"item");
3261 xmlw_attr(writer,
"quantity",
"%d", pi->
quantity);
3262 xmlw_str(writer,
"%s", pi->
name);
3263 xmlw_endElem(writer);
3265 xmlw_endElem(writer);
3267 xmlw_endElem(writer);
3270 xmlw_startElem(writer,
"missions_done");
3274 xmlw_elem(writer,
"done",
"%s", m->
name);
3276 xmlw_endElem(writer);
3279 xmlw_startElem(writer,
"events_done");
3283 xmlw_elem(writer,
"done",
"%s", ev);
3285 xmlw_endElem(writer);
3288 xmlw_startElem(writer,
"escorts");
3290 xmlw_endElem(writer);
3293 xmlw_startElem(writer,
"metadata");
3295 xmlw_endElem(writer);
3306 xmlw_startElem(writer,
"outfit");
3307 xmlw_attr(writer,
"slot",
"%d",i);
3309 xmlw_attr(writer,
"quantity",
"%d", slot->u.
ammo.
quantity);
3310 xmlw_str(writer,
"%s",o->
name);
3311 xmlw_endElem(writer);
3326 xmlw_startElem(writer,
"ship");
3327 xmlw_attr(writer,
"name",
"%s",ship->
name);
3328 xmlw_attr(writer,
"model",
"%s",ship->
ship->
name);
3329 xmlw_attr(writer,
"favourite",
"%d",pship->
favourite);
3330 xmlw_attr(writer,
"deployed",
"%d",pship->
deployed);
3334 xmlw_elem(writer,
"acquired",
"%s", pship->
acquired);
3335 xmlw_saveTime(writer,
"acquired_date", pship->
acquired_date);
3336 xmlw_elem(writer,
"time_played",
"%f", pship->
time_played);
3341 xmlw_elem(writer,
"jumped_times",
"%u", pship->
jumped_times);
3342 xmlw_elem(writer,
"landed_times",
"%u", pship->
landed_times);
3343 xmlw_elem(writer,
"death_counter",
"%u", pship->
death_counter);
3346 xmlw_startElem(writer,
"ships_destroyed");
3347 for (
int i=SHIP_CLASS_NULL+1; i<SHIP_CLASS_TOTAL; i++) {
3348 char buf[STRMAX_SHORT];
3350 for (
size_t j=0; j<strlen(buf); j++)
3355 xmlw_endElem(writer);
3358 xmlw_elem(writer,
"fuel",
"%f",ship->
fuel);
3361 xmlw_startElem(writer,
"outfits_intrinsic");
3364 xmlw_endElem(writer);
3365 xmlw_startElem(writer,
"outfits_structure");
3371 xmlw_endElem(writer);
3372 xmlw_startElem(writer,
"outfits_utility");
3378 xmlw_endElem(writer);
3379 xmlw_startElem(writer,
"outfits_weapon");
3385 xmlw_endElem(writer);
3388 xmlw_startElem(writer,
"commodities");
3411 WARN(_(
"Found mission cargo '%s' without associated mission."),pc->
commodity->
name);
3412 WARN(_(
"Please reload save game to remove the dead cargo."));
3417 WARN(_(
"Found cargo '%s' with 0 quantity."),pc->
commodity->
name);
3418 WARN(_(
"Please reload save game to remove the dead cargo."));
3422 xmlw_startElem(writer,
"commodity");
3424 xmlw_attr(writer,
"quantity",
"%d",pc->
quantity);
3426 xmlw_attr(writer,
"id",
"%d",pc->
id);
3429 xmlw_endElem(writer);
3431 xmlw_endElem(writer);
3433 xmlw_startElem(writer,
"weaponsets");
3434 xmlw_attr(writer,
"autoweap",
"%d", ship->
autoweap);
3435 xmlw_attr(writer,
"active_set",
"%d", ship->
active_set);
3436 xmlw_attr(writer,
"aim_lines",
"%d", ship->
aimLines);
3437 for (
int i=0; i<PILOT_WEAPON_SETS; i++) {
3440 xmlw_startElem(writer,
"weaponset");
3442 xmlw_attr(writer,
"inrange",
"%d",ws->
inrange);
3443 xmlw_attr(writer,
"manual",
"%d",ws->
manual);
3444 xmlw_attr(writer,
"id",
"%d",i);
3446 xmlw_attr(writer,
"type",
"%d",ws->
type);
3448 xmlw_startElem(writer,
"weapon");
3449 xmlw_attr(writer,
"level",
"%d",weaps[j].level);
3450 xmlw_str(writer,
"%d",weaps[j].slotid);
3451 xmlw_endElem(writer);
3454 xmlw_endElem(writer);
3456 xmlw_endElem(writer);
3459 xmlw_startElem(writer,
"vars");
3461 xmlw_endElem(writer);
3463 xmlw_endElem(writer);
3476 time_t t = time(NULL);
3485 xmlw_saveTime(writer,
"last_played", time(NULL));
3499 xmlw_startElem(writer,
"ships_destroyed");
3500 for (
int i=SHIP_CLASS_NULL+1; i<SHIP_CLASS_TOTAL; i++) {
3501 char buf[STRMAX_SHORT];
3503 for (
size_t j=0; j<strlen(buf); j++)
3508 xmlw_endElem(writer);
3540 node = parent->xmlChildrenNode;
3542 if (xml_isNode(node,
"metadata"))
3544 else if (xml_isNode(node,
"player"))
3546 else if (xml_isNode(node,
"missions_done"))
3548 else if (xml_isNode(node,
"events_done"))
3550 else if (xml_isNode(node,
"escorts"))
3552 }
while (xml_nextNode(node));
3563 difficulty_setLocal( NULL );
3584 static nlua_env player_updater_env = LUA_NOREF;
3589 if (player_updater_env == LUA_NOREF) {
3590 player_updater_env = nlua_newEnv();
3592 char *buf =
ndata_read( SAVE_UPDATER_PATH, &bufsize );
3593 if (nlua_dobufenv(player_updater_env, buf, bufsize, SAVE_UPDATER_PATH) != 0) {
3594 WARN( _(
"Error loading file: %s\n"
3596 "Most likely Lua file has improper syntax, please check"),
3597 SAVE_UPDATER_PATH, lua_tostring(naevL,-1));
3605 nlua_getenv( naevL, player_updater_env, type );
3606 lua_pushstring( naevL, name );
3607 if (nlua_pcall(player_updater_env, 1, 1)) {
3608 WARN( _(
"Board: '%s'"), lua_tostring(naevL,-1));
3612 if (lua_type(naevL,-1) == LUA_TNUMBER) {
3636 else if (lua_type(naevL,-1) == LUA_TSTRING)
3641 WARN(_(
"Outfit '%s' in player save not found!"), name );
3663 else if (lua_type(naevL,-1) == LUA_TSTRING)
3664 s =
ship_get( lua_tostring(naevL,-1) );
3668 WARN(_(
"Ship '%s' in player save not found!"), name );
3690 else if (lua_type(naevL,-1) == LUA_TSTRING)
3693 WARN(_(
"Saved license does not exist and could not be found or updated: '%s'!"), name);
3705 const char *spob = NULL;
3706 unsigned int services;
3708 xmlNodePtr node, cur;
3709 int map_overlay_enabled = 0;
3723 node = parent->xmlChildrenNode;
3725 xmlr_str(node,
"location",spob);
3726 }
while (xml_nextNode(node));
3729 node = parent->xmlChildrenNode;
3735 xmlr_int(node,
"mapOverlay", map_overlay_enabled);
3742 if (xml_isNode(node,
"time")) {
3744 int cycles=-1, periods=-1, seconds=-1;
3745 cur = node->xmlChildrenNode;
3747 xmlr_int(cur,
"SCU", cycles);
3748 xmlr_int(cur,
"STP", periods);
3749 xmlr_int(cur,
"STU", seconds);
3750 xmlr_float(cur,
"Remainder", rem);
3751 }
while (xml_nextNode(cur));
3752 if ((cycles < 0) || (periods < 0) || (seconds < 0) || (rem<0.))
3753 WARN(_(
"Malformed time in save game!"));
3755 if ((cycles >= 0) || (periods >= 0) || (seconds >= 0))
3759 if (xml_isNode(node,
"ship"))
3763 else if (xml_isNode(node,
"ships")) {
3764 cur = node->xmlChildrenNode;
3766 if (xml_isNode(cur,
"ship"))
3768 }
while (xml_nextNode(cur));
3772 else if (xml_isNode(node,
"guis")) {
3773 cur = node->xmlChildrenNode;
3775 if (xml_isNode(cur,
"gui"))
3777 }
while (xml_nextNode(cur));
3781 else if (xml_isNode(node,
"outfits")) {
3782 cur = node->xmlChildrenNode;
3784 if (xml_isNode(cur,
"outfit")) {
3787 const char *oname = xml_get(cur);
3788 xmlr_attr_float( cur,
"quantity", q );
3790 WARN(_(
"Outfit '%s' was saved without quantity!"), (oname!=NULL) ? oname :
"NULL" );
3800 }
while (xml_nextNode(cur));
3804 else if (xml_isNode(node,
"licenses"))
3807 else if (xml_isNode(node,
"inventory"))
3810 }
while (xml_nextNode(node));
3814 pilot_clearFlagsRaw( flags );
3815 pilot_setFlagRaw( flags, PILOT_PLAYER );
3816 pilot_setFlagRaw( flags, PILOT_NO_OUTFITS );
3817 WARN(_(
"Player ship does not exist!"));
3820 WARN(_(
"Player has no other ships, giving starting ship."));
3822 faction_get(
"Player"),
"player", 0., NULL, NULL, flags, 0, 0 );
3829 faction_get(
"Player"),
"player", 0., NULL, NULL, flags, 0, 0 );
3831 WARN(_(
"Giving player ship '%s'."),
player.
p->
name );
3837 ERR(_(
"Something went horribly wrong, player does not exist after load..."));
3847 WARN(_(
"Save has no time information, setting to start information."));
3853 DEBUG(_(
"Player save was updated!"));
3854 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."));
3861 !spob_hasService(pnt, SPOB_SERVICE_LAND)) {
3862 WARN(_(
"Player starts out in non-existent or invalid spob '%s',"
3863 "trying to find a suitable one instead."),
3876 const char *found = NULL;
3877 for (
int i=0; i<3; i++) {
3878 services = SPOB_SERVICE_LAND | SPOB_SERVICE_INHABITED | SPOB_SERVICE_REFUEL;
3881 services |= SPOB_SERVICE_SHIPYARD;
3884 services |= SPOB_SERVICE_OUTFITS;
3891 WARN(_(
"Could not find a spob satisfying criteria %d."), i);
3894 if (found == NULL) {
3895 WARN(_(
"Could not find a suitable spob. Choosing a random spob."));
3904 a = RNGF() * 2.*M_PI;
3905 r = RNGF() * pnt->
radius * 0.8;
3915 ovr_setOpen(map_overlay_enabled);
3931 return !
areEnemies(p->presence.faction, FACTION_PLAYER);
3942 xmlNodePtr node = parent->xmlChildrenNode;
3944 xml_onlyNodes(node);
3946 if (!xml_isNode(node,
"done"))
3951 DEBUG(_(
"Mission '%s' doesn't seem to exist anymore, removing from save."),
3955 }
while (xml_nextNode(node));
3967 xmlNodePtr node = parent->xmlChildrenNode;
3969 xml_onlyNodes(node);
3971 if (!xml_isNode(node,
"done"))
3976 DEBUG(_(
"Event '%s' doesn't seem to exist anymore, removing from save."),
3980 }
while (xml_nextNode(node));
3992 xmlNodePtr node = parent->xmlChildrenNode;
3994 xml_onlyNodes(node);
3996 if (!xml_isNode( node,
"license" ))
3999 char *name = xml_get( node );
4001 WARN( _(
"License node is missing name." ) );
4005 }
while (xml_nextNode(node));
4017 xmlNodePtr node = parent->xmlChildrenNode;
4020 xml_onlyNodes(node);
4022 if (!xml_isNode( node,
"item" ))
4025 xmlr_attr_int_def( node,
"quantity", q, 1 );
4026 char *name = xml_get( node );
4028 WARN( _(
"Inventory item node is missing name." ) );
4032 }
while (xml_nextNode(node));
4044 xmlNodePtr node = parent->xmlChildrenNode;
4049 if (!xml_isNode(node,
"escort"))
4052 xmlr_attr_strd( node,
"type", buf );
4053 xmlr_attr_strd( node,
"name", name );
4055 name = xml_getStrd( node );
4056 if (strcmp(buf,
"bay")==0)
4059 else if (strcmp(buf,
"fleet")==0) {
4064 WARN(_(
"Fleet ship '%s' is deployed despite not being marked for deployal!"), ps->
p->
name);
4068 WARN(_(
"Fleet ship '%s' is deployed despite not being space worthy!"), ps->
p->
name);
4073 WARN(_(
"Escort has invalid type '%s'."), buf);
4076 }
while (xml_nextNode(node));
4088 xmlNodePtr node = parent->xmlChildrenNode;
4090 xml_onlyNodes(node);
4101 if (xml_isNode(node,
"last_played")) {
4105 else if (xml_isNode(node,
"date_created")) {
4109 else if (xml_isNode(node,
"ships_destroyed")) {
4110 xmlNodePtr cur = node->xmlChildrenNode;
4112 char buf[STRMAX_SHORT];
4117 strncpy( buf, (
const char*)cur->name,
sizeof(buf)-1 );
4118 for (
size_t i=0; i<strlen(buf); i++)
4123 if (
class==SHIP_CLASS_NULL) {
4124 WARN(_(
"Unknown ship class '%s' when parsing 'ships_destroyed' node!"), (
const char*)cur->name );
4129 }
while (xml_nextNode(cur));
4131 }
while (xml_nextNode(node));
4143 DEBUG( _(
"Outfit '%s' does not fit designated slot on player's pilot '%s', adding to stock."),
4151 DEBUG(_(
"Outfit '%s' does not fit on player's pilot '%s', adding to stock."),
4169 char *name = xml_get(node);
4171 WARN(_(
"Empty ship slot node found, skipping."));
4186 xmlr_attr_int(node,
"quantity",q);
4202 const Ship *ship_parsed;
4207 int autoweap, level, weapid, active_set, aim_lines, in_range, manual, weap_type;
4213 xmlr_attr_strd( parent,
"name", name );
4214 xmlr_attr_strd( parent,
"model", model );
4215 xmlr_attr_int_def( parent,
"favourite", ps.
favourite, 0 );
4216 xmlr_attr_int_def( parent,
"deployed", ps.
deployed, 0 );
4219 pilot_clearFlagsRaw( flags );
4221 pilot_setFlagRaw( flags, PILOT_PLAYER );
4222 pilot_setFlagRaw( flags, PILOT_NO_OUTFITS );
4225 if (!is_player && strcmp( name,
player.
p->
name ) == 0) {
4226 DEBUG( _(
"Ignoring player-owned ship '%s': duplicate of player's current ship."), name );
4234 if (ship_parsed == NULL) {
4235 WARN(_(
"Player ship '%s' not found!"), model);
4272 node = parent->xmlChildrenNode;
4274 xml_onlyNodes(node);
4277 xmlr_strd(node,
"acquired",ps.
acquired);
4278 if (xml_isNode(node,
"acquired_date")) {
4290 if (xml_isNode(node,
"ships_destroyed")) {
4291 xmlNodePtr cur = node->xmlChildrenNode;
4293 char buf[STRMAX_SHORT];
4298 strncpy( buf, (
const char*)cur->name,
sizeof(buf)-1 );
4299 for (
size_t i=0; i<strlen(buf); i++)
4304 if (
class==SHIP_CLASS_NULL) {
4305 WARN(_(
"Unknown ship class '%s' when parsing 'ships_destroyed' node!"), (
const char*)cur->name );
4310 }
while (xml_nextNode(cur));
4314 xmlr_int(node,
"fuel",fuel);
4317 if (xml_isNode(node,
"outfits_structure")) {
4318 xmlNodePtr cur = node->xmlChildrenNode;
4322 if (!xml_isNode(cur,
"outfit")) {
4323 WARN(_(
"Save has unknown '%s' tag!"),xml_get(cur));
4326 xmlr_attr_int_def( cur,
"slot", n, -1 );
4328 WARN(_(
"Outfit slot out of range, not adding to ship."));
4332 }
while (xml_nextNode(cur));
4335 else if (xml_isNode(node,
"outfits_utility")) {
4336 xmlNodePtr cur = node->xmlChildrenNode;
4340 if (!xml_isNode(cur,
"outfit")) {
4341 WARN(_(
"Save has unknown '%s' tag!"),xml_get(cur));
4344 xmlr_attr_int_def( cur,
"slot", n, -1 );
4346 WARN(_(
"Outfit slot out of range, not adding."));
4350 }
while (xml_nextNode(cur));
4353 else if (xml_isNode(node,
"outfits_weapon")) {
4354 xmlNodePtr cur = node->xmlChildrenNode;
4358 if (!xml_isNode(cur,
"outfit")) {
4359 WARN(_(
"Save has unknown '%s' tag!"),xml_get(cur));
4362 xmlr_attr_int_def( cur,
"slot", n, -1 );
4364 WARN(_(
"Outfit slot out of range, not adding."));
4368 }
while (xml_nextNode(cur));
4371 else if (xml_isNode(node,
"outfits_intrinsic")) {
4372 xmlNodePtr cur = node->xmlChildrenNode;
4375 if (!xml_isNode(cur,
"outfit")) {
4376 WARN(_(
"Save has unknown '%s' tag!"),xml_get(cur));
4382 }
while (xml_nextNode(cur));
4385 else if (xml_isNode(node,
"commodities")) {
4386 xmlNodePtr cur = node->xmlChildrenNode;
4388 if (xml_isNode(cur,
"commodity")) {
4391 xmlr_attr_int( cur,
"quantity", quantity );
4392 xmlr_attr_int_def( cur,
"id", cid, 0 );
4395 com = commodity_get(xml_get(cur));
4397 WARN(_(
"Unknown commodity '%s' detected, removing."), xml_get(cur));
4403 if ((quantity==0) && (cid==0))
4404 WARN(_(
"Adding cargo '%s' to ship '%s' that is not a mission cargo with quantity=0!"), com->
name, ship->
name );
4407 }
while (xml_nextNode(cur));
4411 }
while (xml_nextNode(node));
4422 DEBUG(_(
"Player ship '%s' failed slot validity check , removing all outfits and adding to stock."),
4435 for (
int i=0; i<PILOT_WEAPON_SETS; i++)
4440 node = parent->xmlChildrenNode;
4444 if (xml_isNode(node,
"vars")) {
4448 else if (!xml_isNode(node,
"weaponsets"))
4452 xmlr_attr_int( node,
"autoweap", autoweap );
4455 xmlr_attr_int_def( node,
"active_set", active_set, -1 );
4458 xmlr_attr_int( node,
"aim_lines", aim_lines );
4461 cur = node->xmlChildrenNode;
4466 if (!xml_isNode(cur,
"weaponset")) {
4467 WARN(_(
"Player ship '%s' has unknown node '%s' in 'weaponsets' (expected 'weaponset')."),
4468 ship->
name, cur->name);
4473 xmlr_attr_int_def(cur,
"id",
id, -1);
4475 WARN(_(
"Player ship '%s' missing 'id' tag for weapon set."),ship->
name);
4478 if ((
id < 0) || (
id >= PILOT_WEAPON_SETS)) {
4479 WARN(_(
"Player ship '%s' has invalid weapon set id '%d' [max %d]."),
4480 ship->
name,
id, PILOT_WEAPON_SETS-1 );
4485 xmlr_attr_int( cur,
"inrange", in_range );
4490 xmlr_attr_int( cur,
"manual", manual );
4498 xmlr_attr_int_def( cur,
"type", weap_type, -1 );
4499 if (weap_type == -1) {
4500 WARN(_(
"Player ship '%s' missing 'type' tag for weapon set."),ship->
name);
4506 ccur = cur->xmlChildrenNode;
4509 xml_onlyNodes(ccur);
4512 if (!xml_isNode(ccur,
"weapon")) {
4513 WARN(_(
"Player ship '%s' has unknown 'weaponset' child node '%s' (expected 'weapon')."),
4514 ship->
name, ccur->name );
4519 xmlr_attr_int_def( ccur,
"level", level, -1 );
4521 WARN(_(
"Player ship '%s' missing 'level' tag for weapon set weapon."), ship->
name);
4524 weapid = xml_getInt(ccur);
4526 WARN(_(
"Player ship '%s' has invalid weapon id %d [max %d]."),
4534 }
while (xml_nextNode(ccur));
4535 }
while (xml_nextNode(cur));
4536 }
while (xml_nextNode(node));
4543 if (active_set >= 0 && active_set < PILOT_WEAPON_SETS)
4571 if (pilot_isFlag(
player.
p, PILOT_STEALTH)) {
4584 player_message(
"#r%s", _(
"Unable to stealth: missiles locked on!") );
4586 player_message(
"#r%s", _(
"Unable to stealth: other pilots nearby!") );
void ai_think(Pilot *pilot, const double dt)
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’.
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.
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 escorts_jump(Pilot *parent, JumpPoint *jp)
Have a pilot order its escorts to jump.
void escort_rmListIndex(Pilot *p, int i)
Remove from escorts list.
int escort_addList(Pilot *p, const char *ship, EscortType_t type, unsigned int id, int persist)
Adds an escort to the escort list of a pilot.
int escort_clearDeployed(Pilot *p)
Clears deployed escorts of a pilot.
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)
int gui_load(const char *name)
Attempts to load the actual GUI.
char * gui_pick(void)
Determines which GUI should be used.
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.
void info_buttonClear(void)
Clears all the registered buttons.
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 *o), 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.
static char buf[NEWS_MAX_LENGTH]
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.
credits_t pilot_worth(const Pilot *p)
Gets the price or worth of a pilot in credits.
void pilot_setThrust(Pilot *p, double thrust)
Sets the pilot's thrust.
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_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_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_getNearestPos(const Pilot *p, unsigned int *tp, double x, double y, int disabled)
Get the nearest pilot to a pilot from a certain position.
ntime_t pilot_hyperspaceDelay(Pilot *p)
Calculates the hyperspace delay for a pilot.
double pilot_face(Pilot *p, const double dir)
Tries to turn the pilot to face dir.
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_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.
int pilot_hasCredits(Pilot *p, credits_t amount)
Checks to see if the pilot has at least a certain amount of credits.
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.
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.
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.
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_slotsCheckSafety(const Pilot *p)
Pilot slot safety check - makes sure stats are safe.
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_rmOutfitRaw(Pilot *pilot, PilotOutfitSlot *s)
Removes an outfit from the pilot without doing any checks.
int pilot_outfitLRemove(Pilot *pilot, PilotOutfitSlot *po)
Outfit is removed froma ship.
int pilot_outfitLAdd(Pilot *pilot, PilotOutfitSlot *po)
Outfit is added to a ship.
int pilot_addOutfitRaw(Pilot *pilot, const Outfit *outfit, PilotOutfitSlot *s)
Adds an outfit to the pilot, ignoring CPU or other limits.
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_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.
void pilot_weapSetAdd(Pilot *p, int id, PilotOutfitSlot *o, int level)
Adds an outfit to a weapon set.
void pilot_weapSetType(Pilot *p, int id, int type)
Changes the weapon sets mode.
PilotWeaponSet * pilot_weapSet(Pilot *p, int id)
Gets a weapon set from id.
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_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 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_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_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.
credits_t player_shipPrice(const char *shipname)
Calculates the price of one of the player's ships.
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.
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.
int player_getOutfitsFiltered(const Outfit **outfits, int(*filter)(const Outfit *o), const char *name)
Prepares two arrays for displaying in an image array.
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_thinkMouseFly(void)
Handles mouse flying based on cursor position.
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_brake(void)
Starts braking or active cooldown.
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_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.
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_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.
int player_guiAdd(char *name)
Adds a gui to the player.
char ** player_guiList(void)
Gets the list of GUIs.
int player_guiCheck(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.
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().)