/** * @brief Makes sure it's sane to change ships in the equipment view. * @param shipname Ship being changed to. */ int can_swapEquipment( char* shipname ) { int failure = 0; char *loc = player_getLoc(shipname); Pilot *newship; newship = player_getShip(shipname); if (strcmp(shipname,player.p->name)==0) /* Already onboard. */ land_errDialogueBuild( "You're already onboard the %s.", shipname ); failure = 1; if (strcmp(loc,land_planet->name)) { /* Ship isn't here. */ dialogue_alert( "You must transport the ship to %s to be able to get in.", land_planet->name ); failure = 1; } if (pilot_cargoUsed(player.p) > (pilot_cargoFree(newship) + pilot_cargoUsed(newship))) { /* Current ship has too much cargo. */ land_errDialogueBuild( "You have %d tons more cargo than the new ship can hold.", pilot_cargoUsed(player.p) - pilot_cargoFree(newship), shipname ); failure = 1; } if (pilot_hasDeployed(player.p)) { /* Escorts are in space. */ land_errDialogueBuild( "You can't strand your fighters in space."); failure = 1; } return !failure; }
/** * @brief Updates the ship stuff. */ static void ship_update( unsigned int wid ) { char buf[1024], *hyp_delay; int cargo, len; cargo = pilot_cargoUsed( player.p ) + pilot_cargoFree( player.p ); hyp_delay = ntime_pretty( pilot_hyperspaceDelay( player.p ), 2 ); len = nsnprintf( buf, sizeof(buf), _("%s\n" "%s\n" "%s\n" "%d\n" "\n" "%d teraflops\n" "%.0f tonnes\n" "%s average\n" "%.0f kN/tonne\n" "%.0f m/s (max %.0f m/s)\n" "%.0f deg/s\n" "\n" "%.0f%%\n" /* Absorbption */ "%.0f / %.0f MJ (%.1f MW)\n" /* Shield */ "%.0f / %.0f MJ (%.1f MW)\n" /* Armour */ "%.0f / %.0f MJ (%.1f MW)\n" /* Energy */ "%d / %d tonnes\n" "%.0f / %.0f units (%d jumps)\n" "\n"), /* Generic */ player.p->name, player.p->ship->name, ship_class(player.p->ship), (int)floor(player.p->crew), player.p->cpu_max, /* Movement. */ player.p->solid->mass, hyp_delay, player.p->thrust / player.p->solid->mass, player.p->speed, solid_maxspeed( player.p->solid, player.p->speed, player.p->thrust ), player.p->turn*180./M_PI, /* Health. */ player.p->dmg_absorb * 100., player.p->shield, player.p->shield_max, player.p->shield_regen, player.p->armour, player.p->armour_max, player.p->armour_regen, player.p->energy, player.p->energy_max, player.p->energy_regen, pilot_cargoUsed( player.p ), cargo, player.p->fuel, player.p->fuel_max, pilot_getJumps(player.p)); equipment_shipStats( &buf[len], sizeof(buf)-len, player.p, 1 ); window_modifyText( wid, "txtDDesc", buf ); free( hyp_delay ); }
/** * @brief Moves cargo from one pilot to another. * * At the end has dest have exactly the same cargo as src and leaves src with none. * * @param dest Destination pilot. * @param src Source pilot. * @return 0 on success. */ int pilot_cargoMove( Pilot* dest, Pilot* src ) { /* Nothing to copy, success! */ if (src->ncommodities == 0) return 0; /* Check if it fits. */ if (pilot_cargoUsed(src) > pilot_cargoFree(dest)) { WARN("Unable to copy cargo over from pilot '%s' to '%s'", src->name, dest->name ); return -1; } /* Allocate new space. */ dest->ncommodities += src->ncommodities; dest->commodities = realloc( dest->commodities, sizeof(PilotCommodity)*dest->ncommodities); /* Copy over. */ memmove( &dest->commodities[0], &src->commodities[0], sizeof(PilotCommodity) * src->ncommodities); /* Clean src. */ if (src->commodities != NULL) free(src->commodities); src->ncommodities = 0; src->commodities = NULL; return 0; }
/** * @brief Calculates how much cargo ship has left and such. * * @param pilot Pilot to calculate free cargo space of. */ void pilot_cargoCalc( Pilot* pilot ) { pilot->mass_cargo = pilot_cargoUsed( pilot ); pilot->cargo_free = pilot->cap_cargo - pilot->mass_cargo; pilot->solid->mass = pilot->ship->mass + pilot->stats.cargo_inertia * pilot->mass_cargo + pilot->mass_outfit; pilot_updateMass( pilot ); }
/** * @brief Makes sure it's sane to change ships. * @param shipname Ship being changed to. */ int can_swap( char* shipname ) { int failure = 0; Ship* ship; ship = ship_get( shipname ); if (pilot_cargoUsed(player.p) > ship->cap_cargo) { /* Current ship has too much cargo. */ land_errDialogueBuild( "You have %g tons more cargo than the new ship can hold.", pilot_cargoUsed(player.p) - ship->cap_cargo, ship->name ); failure = 1; } if (pilot_hasDeployed(player.p)) { /* Escorts are in space. */ land_errDialogueBuild( "You can't strand your fighters in space."); failure = 1; } return !failure; }
/** * @brief Updates the ship stuff. */ static void ship_update( unsigned int wid ) { char buf[1024]; int cargo; cargo = pilot_cargoUsed( player.p ) + pilot_cargoFree( player.p ); snprintf( buf, sizeof(buf), "%s\n" "%s\n" "%s\n" "%d\n" "\n" "%.0f teraflops\n" "%.0f tonnes\n" "%s average\n" "%.0f kN/tonne\n" "%.0f m/s (max %.0f m/s)\n" "%.0f deg/s\n" "\n" "%.0f / %.0f MJ (%.1f MW)\n" /* Shield */ "%.0f / %.0f MJ (%.1f MW)\n" /* Armour */ "%.0f / %.0f MJ (%.1f MW)\n" /* Energy */ "%d / %d tonnes\n" "%.0f / %.0f units (%d jumps)", /* Generic */ player.p->name, player.p->ship->name, ship_class(player.p->ship), (int)floor(player.p->crew), player.p->cpu_max, /* Movement. */ player.p->solid->mass, ntime_pretty( pilot_hyperspaceDelay( player.p ), 2 ), player.p->thrust / player.p->solid->mass, player.p->speed, solid_maxspeed( player.p->solid, player.p->speed, player.p->thrust ), player.p->turn*180./M_PI, /* Health. */ player.p->shield, player.p->shield_max, player.p->shield_regen, player.p->armour, player.p->armour_max, player.p->armour_regen, player.p->energy, player.p->energy_max, player.p->energy_regen, pilot_cargoUsed( player.p ), cargo, player.p->fuel, player.p->fuel_max, pilot_getJumps(player.p)); window_modifyText( wid, "txtDDesc", buf ); }