/** * @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; } }
/** * @brief Updates the map window. * * @param wid Window id. */ static void map_update( unsigned int wid ) { int i; StarSystem* sys; int f, h, x, y; double standing, nstanding; unsigned int services; int l; int hasPresence, hasPlanets; char t; char buf[PATH_MAX]; int p; glTexture *logo; double w; /* Needs map to update. */ if (!map_isOpen()) return; /* Get selected system. */ sys = system_getIndex( map_selected ); /* Not known and no markers. */ if (!(sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)) && !sys_isKnown(sys) && !space_sysReachable(sys)) { map_selectCur(); sys = system_getIndex( map_selected ); } /* * Right Text */ x = -70; /* Side bar X offset. */ w = ABS(x) + 60; /* Width of the side bar. */ y = -20 - 20 - 64 - gl_defFont.h; /* Initialized to position for txtSFaction. */ if (!sys_isKnown(sys)) { /* System isn't known, erase all */ /* * Right Text */ if (sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)) window_modifyText( wid, "txtSysname", sys->name ); else window_modifyText( wid, "txtSysname", "Unknown" );; /* Faction */ window_modifyImage( wid, "imgFaction", NULL, 0, 0 ); window_moveWidget( wid, "txtSFaction", x, y); window_moveWidget( wid, "txtFaction", x + 50, y - gl_smallFont.h - 5 ); window_modifyText( wid, "txtFaction", "Unknown" ); y -= 2 * gl_smallFont.h + 5 + 15; /* Standing */ window_moveWidget( wid, "txtSStanding", x, y ); window_moveWidget( wid, "txtStanding", x + 50, y - gl_smallFont.h - 5 ); window_modifyText( wid, "txtStanding", "Unknown" ); y -= 2 * gl_smallFont.h + 5 + 15; /* Presence. */ window_moveWidget( wid, "txtSPresence", x, y ); window_moveWidget( wid, "txtPresence", x + 50, y - gl_smallFont.h - 5 ); window_modifyText( wid, "txtPresence", "Unknown" ); y -= 2 * gl_smallFont.h + 5 + 15; /* Planets */ window_moveWidget( wid, "txtSPlanets", x, y ); window_moveWidget( wid, "txtPlanets", x + 50, y - gl_smallFont.h - 5 ); window_modifyText( wid, "txtPlanets", "Unknown" ); y -= 2 * gl_smallFont.h + 5 + 15; /* Services */ window_moveWidget( wid, "txtSServices", x, y ); window_moveWidget( wid, "txtServices", x + 50, y -gl_smallFont.h - 5 ); window_modifyText( wid, "txtServices", "Unknown" ); /* * Bottom Text */ window_modifyText( wid, "txtSystemStatus", NULL ); return; } /* System is known */ window_modifyText( wid, "txtSysname", sys->name ); standing = 0.; nstanding = 0.; f = -1; for (i=0; i<sys->nplanets; i++) { if(sys->planets[i]->real == ASSET_REAL) { if ((f==-1) && (sys->planets[i]->faction>0)) { f = sys->planets[i]->faction; standing += faction_getPlayer( f ); nstanding++; } else if (f != sys->planets[i]->faction && /** @todo more verbosity */ (sys->planets[i]->faction>0)) { snprintf( buf, PATH_MAX, "Multiple" ); break; } } } if (f == -1) { window_modifyImage( wid, "imgFaction", NULL, 0, 0 ); window_modifyText( wid, "txtFaction", "N/A" ); window_modifyText( wid, "txtStanding", "N/A" ); h = gl_smallFont.h; } else { if (i==sys->nplanets) /* saw them all and all the same */ snprintf( buf, PATH_MAX, "%s", faction_longname(f) ); /* Modify the image. */ logo = faction_logoSmall(f); window_modifyImage( wid, "imgFaction", logo, 0, 0 ); if (logo != NULL) window_moveWidget( wid, "imgFaction", -90 + logo->w/2, -20 - 32 - 10 - gl_defFont.h + logo->h/2); /* Modify the text */ window_modifyText( wid, "txtFaction", buf ); window_modifyText( wid, "txtStanding", faction_getStanding( standing / nstanding ) ); h = gl_printHeightRaw( &gl_smallFont, w, buf ); } /* Faction */ window_moveWidget( wid, "txtSFaction", x, y); window_moveWidget( wid, "txtFaction", x + 50, y - gl_smallFont.h - 5 ); y -= gl_smallFont.h + h + 5 + 15; /* Standing */ window_moveWidget( wid, "txtSStanding", x, y ); window_moveWidget( wid, "txtStanding", x + 50, y - gl_smallFont.h - 5 ); y -= 2 * gl_smallFont.h + 5 + 15; /* Get presence. */ hasPresence = 0; buf[0] = '\0'; l = 0; for (i=0; i < sys->npresence; i++) { if (sys->presence[i].value <= 0) continue; hasPresence = 1; t = faction_getColourChar(sys->presence[i].faction); /* Use map grey instead of default neutral colour */ l += snprintf( &buf[l], PATH_MAX-l, "%s\e0%s: \e%c%.0f", (l==0)?"":"\n", faction_shortname(sys->presence[i].faction), (t=='N')?'M':t, sys->presence[i].value); } if (hasPresence == 0) snprintf(buf, PATH_MAX, "N/A"); window_moveWidget( wid, "txtSPresence", x, y ); window_moveWidget( wid, "txtPresence", x + 50, y-gl_smallFont.h-5 ); window_modifyText( wid, "txtPresence", buf ); /* Scroll down. */ h = gl_printHeightRaw( &gl_smallFont, w, buf ); y -= 40 + (h - gl_smallFont.h); /* Get planets */ hasPlanets = 0; p = 0; buf[0] = '\0'; for (i=0; i<sys->nplanets; i++) { if(sys->planets[i]->real != ASSET_REAL) continue; /* Colourize output. */ planet_updateLand(sys->planets[i]); t = planet_getColourChar(sys->planets[i]); if (t == 'N') t = 'M'; else if (t == 'R') t = 'S'; if (!hasPlanets) p += snprintf( &buf[p], PATH_MAX-p, "\e%c%s\en", t, sys->planets[i]->name ); else p += snprintf( &buf[p], PATH_MAX-p, ",\n\e%c%s\en", t, sys->planets[i]->name ); hasPlanets = 1; }