/** * @brief Opens the communication dialogue with a pilot. * * @param pilot Pilot to communicate with. * @return 0 on success. */ int comm_openPilot( unsigned int pilot ) { const char *msg; unsigned int wid; /* Get the pilot. */ comm_pilot = pilot_get( pilot ); if (comm_pilot == NULL) return -1; /* Must not be disabled. */ if (pilot_isFlag(comm_pilot, PILOT_DISABLED)) { player_message("%s does not respond.", comm_pilot->name); return 0; } /* Check to see if pilot wants to communicate. */ msg = comm_getString( "comm_no" ); if (msg != NULL) { player_message( msg ); return 0; } /* Set up for the comm_get* functions. */ ai_setPilot( comm_pilot ); /* Create the generic comm window. */ wid = comm_open( ship_loadCommGFX( comm_pilot->ship ), comm_pilot->faction, pilot_isHostile(comm_pilot) ? -1 : pilot_isFriendly(comm_pilot) ? 1 : 0, pilot_isFlag(comm_pilot, PILOT_BRIBED), comm_pilot->name ); /* Add special buttons. */ window_addButton( wid, -20, 20 + BUTTON_HEIGHT + 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnGreet", "Greet", NULL ); if (!pilot_isFlag(comm_pilot, PILOT_BRIBED) && /* Not already bribed. */ ((faction_getPlayer( comm_pilot->faction ) < 0) || /* Hostile. */ pilot_isHostile(comm_pilot))) window_addButton( wid, -20, 20 + 2*BUTTON_HEIGHT + 40, BUTTON_WIDTH, BUTTON_HEIGHT, "btnBribe", "Bribe", comm_bribePilot ); else window_addButton( wid, -20, 20 + 2*BUTTON_HEIGHT + 40, BUTTON_WIDTH, BUTTON_HEIGHT, "btnRequest", "Refuel", comm_requestFuel ); /* Run hooks if needed. */ pilot_runHook( comm_pilot, PILOT_HOOK_HAIL ); return 0; }
/** * @brief Checks whether the speed should be reset due to damage or missile locks. * * @return 1 if the speed should be reset. */ int player_autonavShouldResetSpeed (void) { double failpc, shield, armour; int i, n; Pilot **pstk; int hostiles, will_reset; if (!player_isFlag(PLAYER_AUTONAV)) return 0; hostiles = 0; will_reset = 0; failpc = conf.autonav_reset_speed; shield = player.p->shield / player.p->shield_max; armour = player.p->armour / player.p->armour_max; pstk = pilot_getAll( &n ); for (i=0; i<n; i++) { if ((pstk[i]->id != PLAYER_ID) && pilot_isHostile( pstk[i] ) && pilot_inRangePilot( player.p, pstk[i] ) && !pilot_isDisabled( pstk[i] ) && !pilot_isFlag( pstk[i], PILOT_BRIBED )) { hostiles = 1; break; } } if (hostiles) { if (failpc > .995) { will_reset = 1; player.autonav_timer = MAX( player.autonav_timer, 0. ); } else if ((shield < lasts && shield < failpc) || armour < lasta) { will_reset = 1; player.autonav_timer = MAX( player.autonav_timer, 2. ); } } lasts = shield; lasta = armour; if (will_reset || (player.autonav_timer > 0)) { player_autonavResetSpeed(); return 1; } return 0; }