コード例 #1
0
ファイル: land.c プロジェクト: Dinth/naev
/**
 * @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;
}
コード例 #2
0
ファイル: land.c プロジェクト: Dinth/naev
/**
 * @brief Updates the commodity window.
 *    @param wid Window to update.
 *    @param str Unused.
 */
static void commodity_update( unsigned int wid, char* str )
{
   (void)str;
   char buf[PATH_MAX];
   char *comname;
   Commodity *com;

   comname = toolkit_getList( wid, "lstGoods" );
   if ((comname==NULL) || (strcmp( comname, "None" )==0)) {
      snprintf( buf, PATH_MAX,
         "NA Tons\n"
         "NA Credits/Ton\n"
         "\n"
         "NA Tons\n" );
      window_modifyText( wid, "txtDInfo", buf );
      window_modifyText( wid, "txtDesc", "No outfits available." );
   }
   com = commodity_get( comname );

   /* modify text */
   snprintf( buf, PATH_MAX,
         "%d Tons\n"
         "%"CREDITS_PRI" Credits/Ton\n"
         "\n"
         "%d Tons\n",
         pilot_cargoOwned( player.p, comname ),
         planet_commodityPrice( land_planet, com ),
         pilot_cargoFree(player.p));
   window_modifyText( wid, "txtDInfo", buf );
   window_modifyText( wid, "txtDesc", com->description );
}
コード例 #3
0
/**
 * @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;
}
コード例 #4
0
ファイル: board.c プロジェクト: pegue/naev
/**
 * @brief Attempt to steal the boarded ship's cargo.
 *
 *    @param wdw Window triggering the function.
 *    @param str Unused.
 */
static void board_stealCargo( unsigned int wdw, char* str )
{
   (void)str;
   int q;
   Pilot* p;

   p = pilot_get(player->target);

   if (p->ncommodities==0) { /* no cargo */
      player_message("The ship has no cargo.");
      return;
   }
   else if (pilot_cargoFree(player) <= 0) {
      player_message("You have no room for cargo.");
      return;
   }

   if (board_fail(wdw)) return;

   /** steal as much as possible until full - @todo let player choose */
   q = 1;
   while ((p->ncommodities > 0) && (q!=0)) {
      q = pilot_addCargo( player, p->commodities[0].commodity,
            p->commodities[0].quantity );
      pilot_rmCargo( p, p->commodities[0].commodity, q );
   }

   board_update( wdw );
   player_message("You manage to steal the ship's cargo.");
}
コード例 #5
0
/**
 * @brief Tries to add quantity of cargo to pilot.
 *
 *    @param pilot Pilot to add cargo to.
 *    @param cargo Cargo to add.
 *    @param quantity Quantity to add.
 *    @param id Mission ID to add (0 is none).
 *    @return Quantity actually added.
 */
int pilot_cargoAdd( Pilot* pilot, Commodity* cargo,
      int quantity, unsigned int id )
{
   int free;

   /* Check to see how much to add. */
   free = pilot_cargoFree(pilot);
   if (free < quantity)
      quantity = free;

   return pilot_cargoAddRaw( pilot, cargo, quantity, id );
}
コード例 #6
0
ファイル: info.c プロジェクト: nenau/naev
/**
 * @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 );
}
コード例 #7
0
ファイル: info.c プロジェクト: AvanWolf/naev
/**
 * @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 );
}
コード例 #8
0
ファイル: land.c プロジェクト: Dinth/naev
/**
 * @brief Buys the selected commodity.
 *    @param wid Window buying from.
 *    @param str Unused.
 */
static void commodity_buy( unsigned int wid, char* str )
{
   (void)str;
   char *comname;
   Commodity *com;
   unsigned int q;
   credits_t price;
   HookParam hparam[3];

   /* Get selected. */
   q     = commodity_getMod();
   comname = toolkit_getList( wid, "lstGoods" );
   com   = commodity_get( comname );
   price = planet_commodityPrice( land_planet, com );
   price *= q;

   /* Check stuff. */
   if (!player_hasCredits( price )) {
      dialogue_alert( "Insufficient credits!" );
      return;
   }
   else if (pilot_cargoFree(player.p) <= 0) {
      dialogue_alert( "Insufficient free space!" );
      return;
   }

   /* Make the buy. */
   q = pilot_cargoAdd( player.p, com, q );
   player_modCredits( -price );
   land_checkAddRefuel();
   commodity_update(wid, NULL);

   /* Run hooks. */
   hparam[0].type    = HOOK_PARAM_STRING;
   hparam[0].u.str   = comname;
   hparam[1].type    = HOOK_PARAM_NUMBER;
   hparam[1].u.num   = q;
   hparam[2].type    = HOOK_PARAM_SENTINEL;
   hooks_runParam( "comm_buy", hparam );
   if (land_takeoff)
      takeoff(1);
}
コード例 #9
0
ファイル: land.c プロジェクト: KennethWilke/naev
static int commodity_canBuy( char *name )
{
   int failure;
   unsigned int q, price;
   Commodity *com;
   char buf[ECON_CRED_STRLEN];

   failure = 0;
   q = commodity_getMod();
   com = commodity_get( name );
   price = planet_commodityPrice( land_planet, com ) * q;

   if (!player_hasCredits( price )) {
      credits2str( buf, price - player.p->credits, 2 );
      land_errDialogueBuild("You need %s more credits.", buf );
      failure = 1;
   }
   if (pilot_cargoFree(player.p) <= 0) {
      land_errDialogueBuild("No cargo space available!");
      failure = 1;
   }

   return !failure;
}
コード例 #10
0
ファイル: nlua_player.c プロジェクト: Delll/naev
/**
 * @brief Gets the free cargo space the player has.
 *
 *    @luareturn The free cargo space in tons of the player.
 * @brief freeCargo()
 */
static int playerL_freeSpace( lua_State *L )
{
   lua_pushnumber(L, pilot_cargoFree(player) );
   return 1;
}