/** * @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 Resets the game speed. */ void player_autonavResetSpeed (void) { if (player_isFlag(PLAYER_DOUBLESPEED)) { tc_mod = 2.; pause_setSpeed( 2. ); } else { tc_mod = 1.; pause_setSpeed( 1. ); } tc_rampdown = 0; }
static int menu_main_bkg_system (void) { nsave_t *ns; int n; const char *sys; Planet *pnt; double cx, cy; /* Clean pilots. */ pilots_cleanAll(); sys = NULL; /* Refresh saves. */ load_refresh(); /* Get start position. */ ns = load_getList( &n ); if ((n > 0) && (planet_exists( ns[0].planet ))) { pnt = planet_get( ns[0].planet ); if (pnt != NULL) { sys = planet_getSystem( ns[0].planet ); if (sys != NULL) { cx = pnt->pos.x; cy = pnt->pos.y; cx += 300; cy += 200; } } } /* Fallback if necessary. */ if (sys == NULL) { sys = start_system(); start_position( &cx, &cy ); } /* Initialize. */ space_init( sys ); cam_setTargetPos( cx, cy, 0 ); cam_setZoom( conf.zoom_far ); pause_setSpeed( 1. ); sound_setSpeed( 1. ); return 0; }
/** * @brief Prepares the player to enter autonav. * * @return 1 on success, 0 on failure (disabled, etc.) */ static int player_autonavSetup (void) { /* Not under manual control or disabled. */ if (pilot_isFlag( player.p, PILOT_MANUAL_CONTROL ) || pilot_isDisabled(player.p)) return 0; /* Autonav is mutually-exclusive with other autopilot methods. */ player_restoreControl( PINPUT_AUTONAV, NULL ); player_message(_("\apAutonav initialized.")); if (!player_isFlag(PLAYER_AUTONAV)) { tc_base = player_isFlag(PLAYER_DOUBLESPEED) ? 2. : 1.; tc_mod = tc_base; if (conf.compression_mult >= 1.) player.tc_max = MIN( conf.compression_velocity / solid_maxspeed(player.p->solid, player.p->speed, player.p->thrust), conf.compression_mult ); else player.tc_max = conf.compression_velocity / solid_maxspeed(player.p->solid, player.p->speed, player.p->thrust); /* Safe cap. */ player.tc_max = MAX( 1., player.tc_max ); } /* Sane values. */ tc_rampdown = 0; tc_down = 0.; lasts = player.p->shield / player.p->shield_max; lasta = player.p->armour / player.p->armour_max; /* Set flag and tc_mod just in case. */ player_setFlag(PLAYER_AUTONAV); pause_setSpeed( tc_mod ); /* Make sure time acceleration starts immediately. */ player.autonav_timer = 0.; return 1; }
/** * @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 Updates the player's autonav. * * @param dt Current delta tick (should be real delta tick, not game delta tick). */ void player_updateAutonav( double dt ) { const double dis_dead = 5.0; const double dis_mod = 0.5; const double dis_max = 4.0; const double dis_ramp = 6.0; if (paused || (player.p==NULL) || pilot_isFlag(player.p, PILOT_DEAD)) return; /* We handle disabling here. */ if (pilot_isFlag(player.p, PILOT_DISABLED)) { /* It is somewhat like: * /------------\ 4x * / \ * -----/ \----- 1x * * <---><-><----------><-><---> * 5 6 X 6 5 Real time * 5 15 X 15 5 Game time * * For triangles we have to add the rectangle and triangle areas. */ /* 5 second deadtime. */ if (player.p->dtimer_accum < dis_dead) tc_mod = tc_base; else { /* Ramp down. */ if (player.p->dtimer - player.p->dtimer_accum < dis_dead + (dis_max-tc_base)*dis_ramp/2 + tc_base*dis_ramp) tc_mod = MAX( tc_base, tc_mod - dis_mod*dt ); /* Normal. */ else tc_mod = MIN( dis_max, tc_mod + dis_mod*dt ); } pause_setSpeed( tc_mod ); return; } /* Must be autonaving. */ if (!player_isFlag(PLAYER_AUTONAV)) return; /* Ramping down. */ if (tc_rampdown) { if (tc_mod != tc_base) { tc_mod = MAX( tc_base, tc_mod-tc_down*dt ); pause_setSpeed( tc_mod ); } return; } /* We'll update the time compression here. */ if (tc_mod == player.tc_max) return; else tc_mod += 0.2 * dt * (player.tc_max-tc_base); /* Avoid going over. */ if (tc_mod > player.tc_max) tc_mod = player.tc_max; pause_setSpeed( tc_mod ); }