/** * @brief Puts the game in cinematics mode or back to regular mode. * * Possible options are:<br/> * <ul> * <li>abort : (string) autonav abort message * <li>no2x : (boolean) whether to prevent the player from engaging double-speed, default false * <li>gui : (boolean) enables the player's gui, default disabled * </ul> * * @usage player.cinematics( true, { gui = true } ) -- Enables cinematics without hiding gui. * * @luaparam enable If true sets cinematics mode, if false disables. Defaults to disable. * @luaparam options Table of options. * @luafunc cinematics( enable, options ) */ static int playerL_cinematics( lua_State *L ) { int b; const char *abort_msg; int f_gui, f_2x; /* Defaults. */ abort_msg = NULL; f_gui = 0; f_2x = 0; /* Parse parameters. */ b = lua_toboolean( L, 1 ); if (lua_gettop(L) > 1) { if (!lua_istable(L,2)) { NLUA_ERROR( L, "Second parameter to cinematics should be a table of options or omitted!" ); return 0; } lua_getfield( L, 2, "abort" ); if (!lua_isnil( L, -1 )) abort_msg = luaL_checkstring( L, -1 ); lua_pop( L, 1 ); lua_getfield( L, 2, "gui" ); f_gui = lua_toboolean(L, -1); lua_pop( L, 1 ); lua_getfield( L, 2, "no2x" ); f_2x = lua_toboolean(L, -1); lua_pop( L, 1 ); } /* Remove doublespeed. */ if (player_isFlag( PLAYER_DOUBLESPEED )) { player_rmFlag( PLAYER_DOUBLESPEED ); pause_setSpeed(1.); } if (b) { /* Do stuff. */ player_autonavAbort( abort_msg ); player_rmFlag( PLAYER_DOUBLESPEED ); ovr_setOpen(0); pause_setSpeed(1.); if (!f_gui) player_setFlag( PLAYER_CINEMATICS_GUI ); if (f_2x) player_setFlag( PLAYER_CINEMATICS_2X ); } else { player_rmFlag( PLAYER_CINEMATICS_GUI ); player_rmFlag( PLAYER_CINEMATICS_2X ); } return 0; }
/** * @brief Aborts autonav. * * @param reason Human-readable string describing abort condition. */ void player_autonavAbort( const char *reason ) { /* No point if player is beyond aborting. */ if ((player.p==NULL) || pilot_isFlag(player.p, PILOT_HYPERSPACE)) return; /* Cooldown (handled later) may be script-initiated and we don't * want to make it player-abortable while under manual control. */ if (pilot_isFlag( player.p, PILOT_MANUAL_CONTROL )) return; if (player_isFlag(PLAYER_AUTONAV)) { if (reason != NULL) player_message(_("\arAutonav aborted: %s!"), reason); else player_message(_("\arAutonav aborted!")); player_rmFlag(PLAYER_AUTONAV); /* Get rid of acceleration. */ player_accelOver(); /* Break possible hyperspacing. */ if (pilot_isFlag(player.p, PILOT_HYP_PREP)) { pilot_hyperspaceAbort(player.p); player_message(_("\apAborting hyperspace sequence.")); } /* Reset time compression. */ player_autonavEnd(); } }
/** * @brief Sets player save ability. * * @usage player.allowSave( b ) * @luaparam b true if the player is allowed to save, false otherwise. Defaults to true. * @luafunc allowSave( b ) */ static int playerL_allowSave( lua_State *L ) { unsigned int b; if (lua_gettop(L)==0) b = 1; else b = lua_toboolean(L, 1); if (b) player_rmFlag(PLAYER_NOSAVE); else player_setFlag(PLAYER_NOSAVE); return 0; }
/** * @brief Allows or disallows the player to land. * * This will allow or disallow landing on a system level and is reset when the * player enters another system. * * @usage player.allowLand() -- Allows the player to land * @usage player.allowLand( false ) -- Doesn't allow the player to land. * @usage player.allowLand( false, "No landing." ) -- Doesn't allow the player to land with the message "No landing." * * @luaparam b Whether or not to allow the player to land (defaults to true if omitted). * @luaparam msg Message displayed when player tries to land (only if disallowed to land). Can be omitted to use default. * @luafunc allowLand( b, msg ) */ static int playerL_allowLand( lua_State *L ) { int b; const char *str; str = NULL; if (lua_gettop(L) > 0) { b = lua_toboolean(L,1); if (lua_isstring(L,2)) str = lua_tostring(L,2); } else b = 1; if (b) player_rmFlag( PLAYER_NOLAND ); else { player_setFlag( PLAYER_NOLAND ); player_nolandMsg( str ); } return 0; }
/** * @brief Runs the input command. * * @param keynum The index of the keybind. * @param value The value of the keypress (defined above). * @param kabs The absolute value. */ static void input_key( int keynum, double value, double kabs, int repeat ) { unsigned int t; HookParam hparam[3]; /* Repetition stuff. */ if (conf.repeat_delay != 0) { if ((value == KEY_PRESS) && !repeat) { repeat_key = keynum; repeat_keyTimer = SDL_GetTicks(); repeat_keyCounter = 0; } else if (value == KEY_RELEASE) { repeat_key = -1; repeat_keyTimer = 0; repeat_keyCounter = 0; } } /* * movement */ /* accelerating */ if (KEY("accel") && !repeat) { if (kabs >= 0.) { player_restoreControl( PINPUT_MOVEMENT, NULL ); player_accel(kabs); input_accelButton = 1; } else { /* prevent it from getting stuck */ if (value==KEY_PRESS) { player_restoreControl( PINPUT_MOVEMENT, NULL ); player_setFlag(PLAYER_ACCEL); player_accel(1.); input_accelButton = 1; } else if (value==KEY_RELEASE) { player_accelOver(); player_rmFlag(PLAYER_ACCEL); input_accelButton = 0; } /* double tap accel = afterburn! */ t = SDL_GetTicks(); if ((conf.afterburn_sens != 0) && (value==KEY_PRESS) && INGAME() && NOHYP() && NODEAD() && (t-input_accelLast <= conf.afterburn_sens)) pilot_afterburn( player.p ); else if (value==KEY_RELEASE) pilot_afterburnOver( player.p ); if (value==KEY_PRESS) input_accelLast = t; } /* turning left */ } else if (KEY("left") && !repeat) { if (kabs >= 0.) { player_restoreControl( PINPUT_MOVEMENT, NULL ); player_setFlag(PLAYER_TURN_LEFT); player_left = kabs; } else { /* set flags for facing correction */ if (value==KEY_PRESS) { player_restoreControl( PINPUT_MOVEMENT, NULL ); player_setFlag(PLAYER_TURN_LEFT); player_left = 1.; } else if (value==KEY_RELEASE) { player_rmFlag(PLAYER_TURN_LEFT); player_left = 0.; } } /* turning right */ } else if (KEY("right") && !repeat) { if (kabs >= 0.) { player_restoreControl( PINPUT_MOVEMENT, NULL ); player_setFlag(PLAYER_TURN_RIGHT); player_right = kabs; } else { /* set flags for facing correction */ if (value==KEY_PRESS) { player_restoreControl( PINPUT_MOVEMENT, NULL ); player_setFlag(PLAYER_TURN_RIGHT); player_right = 1.; } else if (value==KEY_RELEASE) { player_rmFlag(PLAYER_TURN_RIGHT); player_right = 0.; } } /* turn around to face vel */ } else if (KEY("reverse") && !repeat) { if (value==KEY_PRESS) { player_restoreControl( PINPUT_MOVEMENT, NULL ); player_setFlag(PLAYER_REVERSE); } else if ((value==KEY_RELEASE) && player_isFlag(PLAYER_REVERSE)) { player_rmFlag(PLAYER_REVERSE); if (!player_isFlag(PLAYER_ACCEL)) player_accelOver(); } /* * combat */ /* shooting primary weapon */ } else if (KEY("primary") && NODEAD() && !repeat) { if (value==KEY_PRESS) { player_setFlag(PLAYER_PRIMARY); } else if (value==KEY_RELEASE) player_rmFlag(PLAYER_PRIMARY); /* targeting */ } else if (INGAME() && NODEAD() && KEY("target_next")) { if (value==KEY_PRESS) player_targetNext(0); } else if (INGAME() && NODEAD() && KEY("target_prev")) { if (value==KEY_PRESS) player_targetPrev(0); } else if (INGAME() && NODEAD() && KEY("target_nearest")) { if (value==KEY_PRESS) player_targetNearest(); } else if (INGAME() && NODEAD() && KEY("target_nextHostile")) { if (value==KEY_PRESS) player_targetNext(1); } else if (INGAME() && NODEAD() && KEY("target_prevHostile")) { if (value==KEY_PRESS) player_targetPrev(1); } else if (INGAME() && NODEAD() && KEY("target_hostile")) { if (value==KEY_PRESS) player_targetHostile(); } else if (INGAME() && NODEAD() && KEY("target_clear")) { if (value==KEY_PRESS) player_targetClear(); /* face the target */ } else if (INGAME() && NODEAD() && KEY("face") && !repeat) { if (value==KEY_PRESS) { player_restoreControl( PINPUT_MOVEMENT, NULL ); player_setFlag(PLAYER_FACE); } else if ((value==KEY_RELEASE) && player_isFlag(PLAYER_FACE)) player_rmFlag(PLAYER_FACE); /* board them ships */ } else if (KEY("board") && INGAME() && NOHYP() && NODEAD() && !repeat) { if (value==KEY_PRESS) { player_restoreControl( 0, NULL ); player_board(); } /* * Escorts. */ } else if (INGAME() && NODEAD() && KEY("e_targetNext") && !repeat) { if (value==KEY_PRESS) player_targetEscort(0); } else if (INGAME() && NODEAD() && KEY("e_targetPrev") && !repeat) { if (value==KEY_PRESS) player_targetEscort(1); } else if (INGAME() && NODEAD() && KEY("e_attack") && !repeat) { if (value==KEY_PRESS) escorts_attack(player.p); } else if (INGAME() && NODEAD() && KEY("e_hold") && !repeat) { if (value==KEY_PRESS) escorts_hold(player.p); } else if (INGAME() && NODEAD() && KEY("e_return") && !repeat) { if (value==KEY_PRESS) escorts_return(player.p); } else if (INGAME() && NODEAD() && KEY("e_clear") && !repeat) { if (value==KEY_PRESS) escorts_clear(player.p); /* * secondary weapons */ /* shooting secondary weapon */ } else if (KEY("secondary") && NOHYP() && NODEAD() && !repeat) { if (value==KEY_PRESS) { player_setFlag(PLAYER_SECONDARY); } else if (value==KEY_RELEASE) player_rmFlag(PLAYER_SECONDARY); /* Weapon sets. */ } else if (KEY("weapset1")) { player_weapSetPress( 0, value, repeat ); } else if (KEY("weapset2")) { player_weapSetPress( 1, value, repeat ); } else if (KEY("weapset3")) { player_weapSetPress( 2, value, repeat ); } else if (KEY("weapset4")) { player_weapSetPress( 3, value, repeat ); } else if (KEY("weapset5")) { player_weapSetPress( 4, value, repeat ); } else if (KEY("weapset6")) { player_weapSetPress( 5, value, repeat ); } else if (KEY("weapset7")) { player_weapSetPress( 6, value, repeat ); } else if (KEY("weapset8")) { player_weapSetPress( 7, value, repeat ); } else if (KEY("weapset9")) { player_weapSetPress( 8, value, repeat ); } else if (KEY("weapset0")) { player_weapSetPress( 9, value, repeat ); /* * space */ } else if (KEY("autonav") && INGAME() && NOHYP() && NODEAD()) { if (value==KEY_PRESS) player_autonavStart(); /* target planet (cycles like target) */ } else if (KEY("target_planet") && INGAME() && NOHYP() && NOLAND() && NODEAD()) { if (value==KEY_PRESS) player_targetPlanet(); /* target nearest planet or attempt to land */ } else if (KEY("land") && INGAME() && NOHYP() && NOLAND() && NODEAD()) { if (value==KEY_PRESS) player_land(); } else if (KEY("thyperspace") && NOHYP() && NOLAND() && NODEAD()) { if (value==KEY_PRESS) player_targetHyperspace(); } else if (KEY("starmap") && NOHYP() && NODEAD() && !repeat) { if (value==KEY_PRESS) map_open(); } else if (KEY("jump") && INGAME() && !repeat) { if (value==KEY_PRESS) { player_restoreControl( 0, NULL ); player_jump(); } } else if (KEY("overlay") && NODEAD() && INGAME() && !repeat) { ovr_key( value ); } else if (KEY("mousefly") && NODEAD() && !repeat) { if (value==KEY_PRESS) player_toggleMouseFly(); } else if (KEY("autobrake") && NOHYP() && NOLAND() && NODEAD() && !repeat) { if (value==KEY_PRESS) { player_restoreControl( PINPUT_BRAKING, NULL ); player_brake(); } /* * Communication. */ } else if (KEY("log_up") && INGAME() && NODEAD()) { if (value==KEY_PRESS) { gui_messageScrollUp(5); } } else if (KEY("log_down") && INGAME() && NODEAD()) { if (value==KEY_PRESS) { gui_messageScrollDown(5); } } else if (KEY("hail") && INGAME() && NOHYP() && NODEAD() && !repeat) { if (value==KEY_PRESS) { player_hail(); } } else if (KEY("autohail") && INGAME() && NOHYP() && NODEAD() && !repeat) { if (value==KEY_PRESS) { player_autohail(); } /* * misc */ /* zooming in */ } else if (KEY("mapzoomin") && INGAME() && NODEAD()) { if (value==KEY_PRESS) gui_setRadarRel(-1); /* zooming out */ } else if (KEY("mapzoomout") && INGAME() && NODEAD()) { if (value==KEY_PRESS) gui_setRadarRel(1); /* take a screenshot */ } else if (KEY("screenshot")) { if (value==KEY_PRESS) player_screenshot(); #if SDL_VERSION_ATLEAST(2,0,0) /* toggle fullscreen */ } else if (KEY("togglefullscreen") && !repeat) { if (value==KEY_PRESS) naev_toggleFullscreen(); #endif /* SDL_VERSION_ATLEAST(2,0,0) */ /* pause the games */ } else if (KEY("pause") && !repeat) { if (value==KEY_PRESS) { if (!toolkit_isOpen()) { if (paused) unpause_game(); else pause_player(); } } /* toggle speed mode */ } else if (KEY("speed") && !repeat) { if ((value==KEY_PRESS) && (!player_isFlag( PLAYER_CINEMATICS_2X ))) { if (player_isFlag(PLAYER_DOUBLESPEED)) { if (!player_isFlag(PLAYER_AUTONAV)) pause_setSpeed(1.); player_rmFlag(PLAYER_DOUBLESPEED); } else { if (!player_isFlag(PLAYER_AUTONAV)) pause_setSpeed(2.); player_setFlag(PLAYER_DOUBLESPEED); } } /* opens a small menu */ } else if (KEY("menu") && NODEAD() && !repeat) { if (value==KEY_PRESS) menu_small(); /* shows pilot information */ } else if (KEY("info") && NOHYP() && NODEAD() && !repeat) { if (value==KEY_PRESS) menu_info( INFO_MAIN ); /* Opens the Lua console. */ } else if (KEY("console") && NODEAD() && !repeat) { if (value==KEY_PRESS) cli_open(); } /* Key press not used. */ else { return; } /* Run the hook. */ hparam[0].type = HOOK_PARAM_STRING; hparam[0].u.str = input_keybinds[keynum].name; hparam[1].type = HOOK_PARAM_BOOL; hparam[1].u.b = (value > 0.); hparam[2].type = HOOK_PARAM_SENTINEL; hooks_runParam( "input", hparam ); }
/** * @brief Makes the player take off if landed. * * @param delay Whether or not to have time pass as if the player landed normally. */ void takeoff( int delay ) { int h; char *nt; double a, r; if (!landed) return; /* Clear queued takeoff. */ land_takeoff = 0; /* Refuel if needed. */ land_checkAddRefuel(); /* In case we had paused messy sounds. */ sound_stopAll(); /* ze music */ music_choose("takeoff"); /* to randomize the takeoff a bit */ a = RNGF() * 2. * M_PI; r = RNGF() * land_planet->radius; /* no longer authorized to land */ player_rmFlag(PLAYER_LANDACK); pilot_rmFlag(player.p,PILOT_LANDING); /* No longer landing. */ /* set player to another position with random facing direction and no vel */ player_warp( land_planet->pos.x + r * cos(a), land_planet->pos.y + r * sin(a) ); vect_pset( &player.p->solid->vel, 0., 0. ); player.p->solid->dir = RNGF() * 2. * M_PI; cam_setTargetPilot( player.p->id, 0 ); /* heal the player */ player.p->armour = player.p->armour_max; player.p->shield = player.p->shield_max; player.p->energy = player.p->energy_max; player.p->stimer = 0.; /* initialize the new space */ h = player.p->nav_hyperspace; space_init(NULL); player.p->nav_hyperspace = h; /* cleanup */ if (save_all() < 0) { /* must be before cleaning up planet */ dialogue_alert( "Failed to save game! You should exit and check the log to see what happened and then file a bug report!" ); } /* time goes by, triggers hook before takeoff */ if (delay) ntime_inc( ntime_create( 0, 1, 0 ) ); /* 1 STP */ nt = ntime_pretty( 0, 2 ); player_message("\epTaking off from %s on %s.", land_planet->name, nt); free(nt); /* Hooks and stuff. */ land_cleanup(); /* Cleanup stuff */ hooks_run("takeoff"); /* Must be run after cleanup since we don't want the missions to think we are landed. */ if (menu_isOpen(MENU_MAIN)) return; player_addEscorts(); hooks_run("enter"); if (menu_isOpen(MENU_MAIN)) return; events_trigger( EVENT_TRIGGER_ENTER ); if (menu_isOpen(MENU_MAIN)) return; player.p->ptimer = PILOT_TAKEOFF_DELAY; pilot_setFlag( player.p, PILOT_TAKEOFF ); pilot_setThrust( player.p, 0. ); pilot_setTurn( player.p, 0. ); }
/** * @brief Ends the autonav. */ void player_autonavEnd (void) { player_rmFlag(PLAYER_AUTONAV); player_autonavResetSpeed(); }
/** * @brief Makes the player take off if landed. * * @param delay Whether or not to have time pass as if the player landed normally. */ void takeoff( int delay ) { int h; char *nt; double a, r; if (!landed) return; /* Player's ship is not able to fly. */ if (!player_canTakeoff()) { char message[512]; pilot_reportSpaceworthy( player.p, message, sizeof(message) ); dialogue_msg( "Ship not fit for flight", message ); /* Check whether the player needs rescuing. */ land_stranded(); return; } /* Clear queued takeoff. */ land_takeoff = 0; /* Refuel if needed. */ land_refuel(); /* In case we had paused messy sounds. */ sound_stopAll(); /* ze music */ music_choose("takeoff"); /* to randomize the takeoff a bit */ a = RNGF() * 2. * M_PI; r = RNGF() * land_planet->radius; /* no longer authorized to land */ player_rmFlag(PLAYER_LANDACK); pilot_rmFlag(player.p,PILOT_LANDING); /* No longer landing. */ /* set player to another position with random facing direction and no vel */ player_warp( land_planet->pos.x + r * cos(a), land_planet->pos.y + r * sin(a) ); vect_pset( &player.p->solid->vel, 0., 0. ); player.p->solid->dir = RNGF() * 2. * M_PI; cam_setTargetPilot( player.p->id, 0 ); /* heal the player */ pilot_healLanded( player.p ); /* Clear planet target. Allows for easier autonav out of the system. */ player_targetPlanetSet( -1 ); /* initialize the new space */ h = player.p->nav_hyperspace; space_init(NULL); player.p->nav_hyperspace = h; /* cleanup */ if (save_all() < 0) /* must be before cleaning up planet */ dialogue_alert( "Failed to save game! You should exit and check the log to see what happened and then file a bug report!" ); /* time goes by, triggers hook before takeoff */ if (delay) ntime_inc( ntime_create( 0, 1, 0 ) ); /* 1 STP */ nt = ntime_pretty( 0, 2 ); player_message("\epTaking off from %s on %s.", land_planet->name, nt); free(nt); /* Hooks and stuff. */ land_cleanup(); /* Cleanup stuff */ hooks_run("takeoff"); /* Must be run after cleanup since we don't want the missions to think we are landed. */ if (menu_isOpen(MENU_MAIN)) return; player_addEscorts(); hooks_run("enter"); if (menu_isOpen(MENU_MAIN)) return; events_trigger( EVENT_TRIGGER_ENTER ); missions_run( MIS_AVAIL_SPACE, -1, NULL, NULL ); if (menu_isOpen(MENU_MAIN)) return; player.p->ptimer = PILOT_TAKEOFF_DELAY; pilot_setFlag( player.p, PILOT_TAKEOFF ); pilot_setThrust( player.p, 0. ); pilot_setTurn( player.p, 0. ); }