/** * @brief Applies a hunk and adds it to the diff. * * @param diff Diff to which the hunk belongs. * @param hunk Hunk to apply. * @return 0 on success. */ static int diff_patchHunk( UniHunk_t *hunk ) { Planet *p; switch (hunk->type) { /* Adding an asset. */ case HUNK_TYPE_ASSET_ADD: planet_updateLand( planet_get(hunk->u.name) ); return system_addPlanet( system_get(hunk->target.u.name), hunk->u.name ); /* Removing an asset. */ case HUNK_TYPE_ASSET_REMOVE: return system_rmPlanet( system_get(hunk->target.u.name), hunk->u.name ); /* Making an asset a black market. */ case HUNK_TYPE_ASSET_BLACKMARKET: planet_setBlackMarket( planet_get(hunk->u.name) ); return 0; /* Making an asset a legal market. */ case HUNK_TYPE_ASSET_LEGALMARKET: planet_rmFlag( planet_get(hunk->u.name), PLANET_BLACKMARKET ); return 0; /* Adding a Jump. */ case HUNK_TYPE_JUMP_ADD: return system_addJumpDiff( system_get(hunk->target.u.name), hunk->node ); /* Removing a jump. */ case HUNK_TYPE_JUMP_REMOVE: return system_rmJump( system_get(hunk->target.u.name), hunk->u.name ); /* Adding a tech. */ case HUNK_TYPE_TECH_ADD: return tech_addItem( hunk->target.u.name, hunk->u.name ); /* Removing a tech. */ case HUNK_TYPE_TECH_REMOVE: return tech_rmItem( hunk->target.u.name, hunk->u.name ); /* Changing asset faction. */ case HUNK_TYPE_ASSET_FACTION: p = planet_get( hunk->target.u.name ); if (p==NULL) return -1; hunk->o.name = faction_name( p->faction ); return planet_setFaction( p, faction_get(hunk->u.name) ); case HUNK_TYPE_ASSET_FACTION_REMOVE: return planet_setFaction( planet_get(hunk->target.u.name), faction_get(hunk->o.name) ); default: WARN("Unknown hunk type '%d'.", hunk->type); break; } return -1; }
/** * @brief Changes the ownership of the planet, and adds uni state change to list * * @param planet name of planet * @param faction name of faction * @return 0 on success */ int unistate_setFaction(char *planet, char *faction) { if(!planet || !faction) return -3; assetStatePtr node = NULL; Planet *p = NULL; int f_id; //Get planet struct and faction ID. If either return errors, bail. if((p = planet_get(planet)) == NULL || (f_id = faction_get(faction)) == -1) return -2; //Change the faction of the planet planet_setFaction(p, f_id); //update the universe space_reconstructPresences(); //does the planet already have mods? if((node = unistate_getNode(planet)) != NULL) { //if a faction mod hasn't been added yet if(node->faction == NULL) node->faction = strdup(faction); //else wipe old entry and make new one else { free(node->faction); node->faction = strdup(faction); } return 0; } //else we need to make a new node else return unistate_addNode(planet, faction, -1, -1); }
/** * @brief Starts autonav with a planet destination. */ void player_autonavPnt( char *name ) { Planet *p; p = planet_get( name ); if (!player_autonavSetup()) return; player.autonav = AUTONAV_PNT_APPROACH; player.autonavmsg = p->name; vect_cset( &player.autonav_pos, p->pos.x, p->pos.y ); }
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 Loads the state of the universe into an xml file (Used in load.c) * * @param rootNode pointer to the root node of the game save file we are loading off of * @return 0 on success */ int unistate_load(xmlNodePtr rootNode) { if(!rootNode) return -1; assetStatePtr cur = NULL; xmlNodePtr elementNode = NULL; Planet *p; int f_id; elementNode = rootNode->children; do { if(xml_isNode(elementNode, "uni_state")) { //populate list if(!(unistateList = unistate_populateList(elementNode))) return -1; cur = unistateList; while(cur != NULL) { //Get planet struct and faction ID. If either return errors, bail. if((p = planet_get(cur->name)) == NULL) { WARN("Invalid planet or faction passed"); cur = cur->next; continue; } //Change the faction of the planet if(cur->faction != NULL && (f_id = faction_get(cur->faction)) != -1) planet_setFaction(p, f_id); //Change presence of planet if(cur->presence != -1) p->presenceAmount = (double)cur->presence; //Change range of presence if(cur->range != -1) p->presenceRange = (double)cur->range; //update the universe space_reconstructPresences(); //move along cur = cur->next; } return 0; } } while(xml_nextNode(elementNode)); //if it fell through to here then it didn't find what we were looking for return -2; }
/** * @brief Gets a planet directly. * * @param L Lua state to get planet from. * @param ind Index position to find the planet. * @return Planet found at the index in the state. */ Planet* luaL_validplanet( lua_State *L, int ind ) { LuaPlanet *lp; Planet *p; if (lua_isplanet(L, ind)) { lp = luaL_checkplanet(L, ind); p = planet_getIndex(*lp); } else if (lua_isstring(L, ind)) p = planet_get( lua_tostring(L, ind) ); else { luaL_typerror(L, ind, PLANET_METATABLE); return NULL; } if (p == NULL) NLUA_ERROR(L, _("Planet is invalid")); return p; }
/** * @brief Changes the range of a planet's presence. * * @param planet name of planet to be modified * @param presence presence rangevalue to be changed to * @return 0 on success */ int unistate_setRange(char *planet, int range) { if(!planet) return -3; assetStatePtr node = NULL; Planet *p = NULL; //Get planet struct. If it return errors, bail. if((p = planet_get(planet)) == NULL) return -2; //Change the presence of the planet p->presenceRange = (double)range; //update the universe space_reconstructPresences(); //does the planet already have mods? if((node = unistate_getNode(planet)) != NULL) { //if a faction mod hasn't been added yet node->range = range; return 0; } //else we need to make a new node else return unistate_addNode(planet, NULL, -1, range); }
/** * @brief Helper function for playerL_addShip. */ static Pilot* playerL_newShip( lua_State *L ) { const char *str, *name, *pntname; Ship *s; Pilot *new_ship; Planet *pnt, *t; int noname; /* Defaults. */ t = NULL; /* Handle parameters. */ str = luaL_checkstring(L, 1); if (lua_gettop(L) > 1) name = luaL_checkstring(L,2); else name = str; if (lua_gettop(L) > 2) pntname = luaL_checkstring (L,3); else pntname = NULL; noname = lua_toboolean(L,4); /* Get planet. */ if (pntname != NULL) { pnt = planet_get( pntname ); if (pnt == NULL) { NLUA_ERROR(L, "Planet '%s' not found!", pntname); return 0; } /* Horrible hack to swap variables. */ t = land_planet; land_planet = pnt; } else pnt = NULL; /* Must be landed if pnt is NULL. */ if ((pnt == NULL) && (land_planet==NULL)) { NLUA_ERROR(L, "Player must be landed to add a ship without location parameter."); return 0; } /* Get ship. */ s = ship_get(str); if (s==NULL) { NLUA_ERROR(L, "Ship '%s' not found.", str); return 0; } /* Add the ship, look in case it's cancelled. */ do { new_ship = player_newShip( s, name, 0, noname ); } while (new_ship == NULL); /* Undo the horrible hack. */ if (t != NULL) land_planet = t; return new_ship; }
/** * @brief Teleports the player to a new planet or system (only if not landed). * * If the destination is a system, the coordinates of the player will not change. * If the destination is a planet, the player will be placed over that planet. * * @usage player.teleport( system.get("Arcanis") ) -- Teleports the player to Arcanis. * @usage player.teleport( "Arcanis" ) -- Teleports the player to Arcanis. * @usage player.teleport( "Dvaer Prime" ) -- Teleports the player to Dvaer, and relocates him to Dvaer Prime. * * @luaparam dest System or name of a system or planet or name of a planet to teleport the player to. * @luafunc teleport( dest ) */ static int playerL_teleport( lua_State *L ) { Planet *pnt; StarSystem *sys; const char *name, *pntname; /* Must not be landed. */ if (landed) NLUA_ERROR(L,"Can not teleport the player while landed!"); if (comm_isOpen()) NLUA_ERROR(L,"Can not teleport the player while the comm is open!"); if (player_isBoarded()) NLUA_ERROR(L,"Can not teleport the player while he is boarded!"); pnt = NULL; /* Get a system. */ if (lua_issystem(L,1)) { sys = luaL_validsystem(L,1); name = system_getIndex(sys->id)->name; } /* Get a planet. */ else if (lua_isplanet(L,1)) { pnt = luaL_validplanet(L,1); name = planet_getSystem( pnt->name ); if (name == NULL) { NLUA_ERROR( L, "Planet '%s' does not belong to a system..", pnt->name ); return 0; } } /* Get destination from string. */ else if (lua_isstring(L,1)) { name = lua_tostring(L,1); if (!system_exists( name )) { if (!planet_exists( name )) { NLUA_ERROR( L, "'%s' is not a valid teleportation target.", name ); return 0; } /* No system found, assume destination string is the name of a planet. */ pntname = name; name = planet_getSystem( name ); pnt = planet_get( pntname ); if (name == NULL) { NLUA_ERROR( L, "Planet '%s' does not belong to a system..", pntname ); return 0; } } } else NLUA_INVALID_PARAMETER(L); /* Check if system exists. */ if (!system_exists( name )) { NLUA_ERROR( L, "System '%s' does not exist.", name ); return 0; } /* Jump out hook is run first. */ hooks_run( "jumpout" ); /* Just in case remove hyperspace flags. */ pilot_rmFlag( player.p, PILOT_HYPERSPACE ); pilot_rmFlag( player.p, PILOT_HYP_BEGIN ); pilot_rmFlag( player.p, PILOT_HYP_BRAKE ); pilot_rmFlag( player.p, PILOT_HYP_PREP ); /* Free graphics. */ space_gfxUnload( cur_system ); /* Go to the new system. */ space_init( name ); /* Map gets deformed when jumping this way. */ map_clear(); /* Add the escorts. */ player_addEscorts(); /* Run hooks - order is important. */ hooks_run( "jumpin" ); hooks_run( "enter" ); events_trigger( EVENT_TRIGGER_ENTER ); missions_run( MIS_AVAIL_SPACE, -1, NULL, NULL ); /* Reset targets when teleporting */ player_targetPlanetSet( -1 ); player_targetHyperspaceSet( -1 ); gui_setNav(); /* Move to planet. */ if (pnt != NULL) vectcpy( &player.p->solid->pos, &pnt->pos ); return 0; }
/** * @brief Gets a planet. * * Possible values of param: * - nil : Gets the current landed planet or nil if there is none. * - bool : Gets a random planet. * - faction : Gets random planet belonging to faction matching the number. * - string : Gets the planet by name. * - table : Gets random planet belonging to any of the factions in the * table. * * @usage p,s = planet.get( "Anecu" ) -- Gets planet by name * @usage p,s = planet.get( faction.get( "Empire" ) ) -- Gets random Empire planet * @usage p,s = planet.get(true) -- Gets completely random planet * @usage p,s = planet.get( { faction.get("Empire"), faction.get("Dvaered") } ) -- Random planet belonging to Empire or Dvaered * @luaparam param See description. * @luareturn Returns the planet and the system it belongs to. * @luafunc get( param ) */ static int planetL_get( lua_State *L ) { int i; int *factions; int nfactions; char **planets; int nplanets; const char *rndplanet; LuaPlanet planet; LuaSystem sys; LuaFaction *f; rndplanet = NULL; nplanets = 0; /* Get the landed planet */ if (lua_gettop(L) == 0) { if (land_planet != NULL) { planet.p = land_planet; lua_pushplanet(L,planet); sys.s = system_get( planet_getSystem(land_planet->name) ); lua_pushsystem(L,sys); return 2; } NLUA_ERROR(L,"Attempting to get landed planet when player not landed."); return 0; /* Not landed. */ } /* If boolean return random. */ else if (lua_isboolean(L,1)) { planet.p = planet_get( space_getRndPlanet() ); lua_pushplanet(L,planet); sys.s = system_get( planet_getSystem(land_planet->name) ); lua_pushsystem(L,sys); return 2; } /* Get a planet by faction */ else if (lua_isfaction(L,1)) { f = lua_tofaction(L,1); planets = space_getFactionPlanet( &nplanets, &f->f, 1 ); } /* Get a planet by name */ else if (lua_isstring(L,1)) { rndplanet = lua_tostring(L,1); } /* Get a planet from faction list */ else if (lua_istable(L,1)) { /* Get table length and preallocate. */ nfactions = (int) lua_objlen(L,1); factions = malloc( sizeof(int) * nfactions ); /* Load up the table. */ lua_pushnil(L); i = 0; while (lua_next(L, -2) != 0) { f = lua_tofaction(L, -1); factions[i++] = f->f; lua_pop(L,1); } /* get the planets */ planets = space_getFactionPlanet( &nplanets, factions, nfactions ); free(factions); } else NLUA_INVALID_PARAMETER(); /* Bad Parameter */ /* No suitable planet found */ if ((rndplanet == NULL) && (nplanets == 0)) { free(planets); return 0; } /* Pick random planet */ else if (rndplanet == NULL) { rndplanet = planets[RNG(0,nplanets-1)]; free(planets); } /* Push the planet */ planet.p = planet_get(rndplanet); /* The real planet */ lua_pushplanet(L,planet); sys.s = system_get( planet_getSystem(rndplanet) ); lua_pushsystem(L,sys); return 2; }
/** * @brief Applies a hunk and adds it to the diff. * * @param diff Diff to which the hunk belongs. * @param hunk Hunk to apply. * @return 0 on success. */ static int diff_patchHunk( UniHunk_t *hunk ) { Planet *p; int a, b; switch (hunk->type) { /* Adding an asset. */ case HUNK_TYPE_ASSET_ADD: planet_updateLand( planet_get(hunk->u.name) ); return system_addPlanet( system_get(hunk->target.u.name), hunk->u.name ); /* Removing an asset. */ case HUNK_TYPE_ASSET_REMOVE: return system_rmPlanet( system_get(hunk->target.u.name), hunk->u.name ); /* Making an asset a black market. */ case HUNK_TYPE_ASSET_BLACKMARKET: planet_addService( planet_get(hunk->u.name), PLANET_SERVICE_BLACKMARKET ); return 0; /* Making an asset a legal market. */ case HUNK_TYPE_ASSET_LEGALMARKET: planet_rmService( planet_get(hunk->u.name), PLANET_SERVICE_BLACKMARKET ); return 0; /* Adding a Jump. */ case HUNK_TYPE_JUMP_ADD: return system_addJumpDiff( system_get(hunk->target.u.name), hunk->node ); /* Removing a jump. */ case HUNK_TYPE_JUMP_REMOVE: return system_rmJump( system_get(hunk->target.u.name), hunk->u.name ); /* Adding a tech. */ case HUNK_TYPE_TECH_ADD: return tech_addItem( hunk->target.u.name, hunk->u.name ); /* Removing a tech. */ case HUNK_TYPE_TECH_REMOVE: return tech_rmItem( hunk->target.u.name, hunk->u.name ); /* Changing asset faction. */ case HUNK_TYPE_ASSET_FACTION: p = planet_get( hunk->target.u.name ); if (p==NULL) return -1; hunk->o.name = faction_name( p->faction ); return planet_setFaction( p, faction_get(hunk->u.name) ); case HUNK_TYPE_ASSET_FACTION_REMOVE: return planet_setFaction( planet_get(hunk->target.u.name), faction_get(hunk->o.name) ); /* Making a faction visible. */ case HUNK_TYPE_FACTION_VISIBLE: return faction_setInvisible( faction_get(hunk->target.u.name), 0 ); /* Making a faction invisible. */ case HUNK_TYPE_FACTION_INVISIBLE: return faction_setInvisible( faction_get(hunk->target.u.name), 1 ); /* Making two factions allies. */ case HUNK_TYPE_FACTION_ALLY: a = faction_get( hunk->target.u.name ); b = faction_get( hunk->u.name ); if (areAllies(a, b)) hunk->o.data = 'A'; else if (areEnemies(a, b)) hunk->o.data = 'E'; else hunk->o.data = 0; faction_addAlly( a, b ); faction_addAlly( b, a ); return 0; /* Making two factions enemies. */ case HUNK_TYPE_FACTION_ENEMY: a = faction_get( hunk->target.u.name ); b = faction_get( hunk->u.name ); if (areAllies(a, b)) hunk->o.data = 'A'; else if (areEnemies(a, b)) hunk->o.data = 'E'; else hunk->o.data = 0; faction_addEnemy( a, b ); faction_addEnemy( b, a ); return 0; /* Making two factions neutral (removing enemy/ally statuses). */ case HUNK_TYPE_FACTION_NEUTRAL: a = faction_get( hunk->target.u.name ); b = faction_get( hunk->u.name ); if (areAllies(a, b)) hunk->o.data = 'A'; else if (areEnemies(a, b)) hunk->o.data = 'E'; else hunk->o.data = 0; faction_rmAlly( a, b ); faction_rmAlly( b, a ); faction_rmEnemy( a, b ); faction_rmEnemy( b, a ); return 0; /* Resetting the alignment state of two factions. */ case HUNK_TYPE_FACTION_REALIGN: a = faction_get( hunk->target.u.name ); b = faction_get( hunk->u.name ); if (hunk->o.data == 'A') { faction_rmEnemy(a, b); faction_rmEnemy(b, a); faction_addAlly(a, b); faction_addAlly(b, a); } else if (hunk->o.data == 'E') { faction_rmAlly(a, b); faction_rmAlly(b, a); faction_addEnemy(a, b); faction_addAlly(b, a); } else { faction_rmAlly( a, b ); faction_rmAlly( b, a ); faction_rmEnemy( a, b ); faction_rmEnemy( b, a ); } return 0; default: WARN(_("Unknown hunk type '%d'."), hunk->type); break; } return -1; }
static int planetL_getBackend( lua_State *L, int landable ) { int i; int *factions; int nfactions; char **planets; int nplanets; const char *rndplanet; LuaSystem luasys; LuaFaction f; Planet *pnt; StarSystem *sys; char *sysname; rndplanet = NULL; planets = NULL; nplanets = 0; /* If boolean return random. */ if (lua_isboolean(L,1)) { pnt = planet_get( space_getRndPlanet(landable, 0, NULL) ); lua_pushplanet(L,planet_index( pnt )); luasys = system_index( system_get( planet_getSystem(pnt->name) ) ); lua_pushsystem(L,luasys); return 2; } /* Get a planet by faction */ else if (lua_isfaction(L,1)) { f = lua_tofaction(L,1); planets = space_getFactionPlanet( &nplanets, &f, 1, landable ); } /* Get a planet by name */ else if (lua_isstring(L,1)) { rndplanet = lua_tostring(L,1); if (landable) { pnt = planet_get( rndplanet ); if (pnt == NULL) { NLUA_ERROR(L, _("Planet '%s' not found in stack"), rndplanet); return 0; } /* Check if can land. */ planet_updateLand( pnt ); if (!pnt->can_land) return 0; } } /* Get a planet from faction list */ else if (lua_istable(L,1)) { /* Get table length and preallocate. */ nfactions = (int) lua_objlen(L,1); factions = malloc( sizeof(int) * nfactions ); /* Load up the table. */ lua_pushnil(L); i = 0; while (lua_next(L, -2) != 0) { if (lua_isfaction(L, -1)) factions[i++] = lua_tofaction(L, -1); lua_pop(L,1); } /* get the planets */ planets = space_getFactionPlanet( &nplanets, factions, nfactions, landable ); free(factions); } else NLUA_INVALID_PARAMETER(L); /* Bad Parameter */ /* No suitable planet found */ if ((rndplanet == NULL) && ((planets == NULL) || nplanets == 0)) return 0; /* Pick random planet */ else if (rndplanet == NULL) { planets = (char**) arrayShuffle( (void**)planets, nplanets ); for (i=0; i<nplanets; i++) { if (landable) { /* Check landing. */ pnt = planet_get( planets[i] ); if (pnt == NULL) continue; planet_updateLand( pnt ); if (!pnt->can_land) continue; } rndplanet = planets[i]; break; } free(planets); } /* Push the planet */ pnt = planet_get(rndplanet); /* The real planet */ if (pnt == NULL) { NLUA_ERROR(L, _("Planet '%s' not found in stack"), rndplanet); return 0; } sysname = planet_getSystem(rndplanet); if (sysname == NULL) { NLUA_ERROR(L, _("Planet '%s' is not placed in a system"), rndplanet); return 0; } sys = system_get( sysname ); if (sys == NULL) { NLUA_ERROR(L, _("Planet '%s' can't find system '%s'"), rndplanet, sysname); return 0; } lua_pushplanet(L,planet_index( pnt )); luasys = system_index( sys ); lua_pushsystem(L,luasys); return 2; }
/** * @brief Unpersists Lua data. * * @param L State to unperisist data into. * @param parent Node containing all the Lua persisted data. * @return 0 on success. */ static int nxml_unpersistDataNode( lua_State *L, xmlNodePtr parent ) { LuaPlanet p; LuaSystem s; LuaFaction f; LuaShip sh; LuaTime lt; Planet *pnt; StarSystem *ss; xmlNodePtr node; char *name, *type, *buf, *num; int keynum; node = parent->xmlChildrenNode; do { if (xml_isNode(node,"data")) { /* Get general info. */ xmlr_attr(node,"name",name); xmlr_attr(node,"type",type); /* Check to see if key is a number. */ xmlr_attr(node,"keynum",num); if (num != NULL) { keynum = 1; lua_pushnumber(L, atof(name)); free(num); } else lua_pushstring(L, name); /* handle data types */ /* Recursive tables. */ if (strcmp(type,"table")==0) { xmlr_attr(node,"name",buf); /* Create new table. */ lua_newtable(L); /* Save data. */ nxml_unpersistDataNode(L,node); /* Set table. */ free(buf); } else if (strcmp(type,"number")==0) lua_pushnumber(L,xml_getFloat(node)); else if (strcmp(type,"bool")==0) lua_pushboolean(L,xml_getInt(node)); else if (strcmp(type,"string")==0) lua_pushstring(L,xml_get(node)); else if (strcmp(type,"planet")==0) { pnt = planet_get(xml_get(node)); if (pnt != NULL) { p.id = planet_index(pnt); lua_pushplanet(L,p); } else WARN("Failed to load unexistent planet '%s'", xml_get(node)); } else if (strcmp(type,"system")==0) { ss = system_get(xml_get(node)); if (ss != NULL) { s.id = system_index( ss ); lua_pushsystem(L,s); } else WARN("Failed to load unexistent system '%s'", xml_get(node)); } else if (strcmp(type,"faction")==0) { f.f = faction_get(xml_get(node)); lua_pushfaction(L,f); } else if (strcmp(type,"ship")==0) { sh.ship = ship_get(xml_get(node)); lua_pushship(L,sh); } else if (strcmp(type,"time")==0) { lt.t = xml_getLong(node); lua_pushtime(L,lt); } else { WARN("Unknown lua data type!"); lua_pop(L,1); return -1; } /* Set field. */ lua_settable(L, -3); /* cleanup */ free(type); free(name); } } while (xml_nextNode(node)); return 0; }
/** * @brief Handles the autonavigation process for the player. */ static void player_autonav (void) { JumpPoint *jp; int ret; double d, t, tint; double vel; switch (player.autonav) { case AUTONAV_JUMP_APPROACH: /* Target jump. */ jp = &cur_system->jumps[ player.p->nav_hyperspace ]; ret = player_autonavApproach( &jp->pos, &d, 0 ); if (ret) player.autonav = AUTONAV_JUMP_BRAKE; else if (!tc_rampdown && (map_npath<=1)) { vel = MIN( 1.5*player.p->speed, VMOD(player.p->solid->vel) ); t = d / vel * (1.2 - .1 * tc_base); /* tint is the integral of the time in per time units. * * tc_mod * ^ * | * |\ * | \ * | \___ * | * +------> time * 0 3 * * We decompose integral in a rectangle (3*1) and a triangle (3*(tc_mod-1.))/2. * This is the "elapsed time" when linearly decreasing the tc_mod. Which we can * use to calculate the actual "game time" that'll pass when decreasing the * tc_mod to 1 during 3 seconds. This can be used then to compare when we want to * start decrementing. */ tint = 3. + 0.5*(3.*(tc_mod-tc_base)); if (t < tint) { tc_rampdown = 1; tc_down = (tc_mod-tc_base) / 3.; } } break; case AUTONAV_JUMP_BRAKE: /* Target jump. */ jp = &cur_system->jumps[ player.p->nav_hyperspace ]; if (player.p->stats.misc_instant_jump) { ret = pilot_interceptPos( player.p, jp->pos.x, jp->pos.y ); if (!ret && space_canHyperspace(player.p)) ret = 1; player_acc = player.p->solid->thrust / player.p->thrust; } else ret = player_autonavBrake(); /* Try to jump or see if braked. */ if (ret) { if (space_canHyperspace(player.p)) player_jump(); player.autonav = AUTONAV_JUMP_APPROACH; } /* See if should ramp down. */ if (!tc_rampdown && (map_npath<=1)) { tc_rampdown = 1; tc_down = (tc_mod-tc_base) / 3.; } break; case AUTONAV_POS_APPROACH: ret = player_autonavApproach( &player.autonav_pos, &d, 1 ); if (ret) { player_message( _("\apAutonav arrived at position.") ); player_autonavEnd(); } else if (!tc_rampdown) player_autonavRampdown(d); break; case AUTONAV_PNT_APPROACH: ret = player_autonavApproach( &player.autonav_pos, &d, 1 ); if (ret) { player_message( _("\apAutonav arrived at \a%c%s\a\0."), planet_getColourChar( planet_get(player.autonavmsg) ), player.autonavmsg ); player_autonavEnd(); } else if (!tc_rampdown) player_autonavRampdown(d); break; } }