9#include "player_fleet.h"
20static int pfleet_cargoAddRaw(
const Commodity *com,
int q );
29 for (
int i = 0; i <
array_size( pships ); i++ ) {
55 char buf_amount[ECON_MASS_STRLEN], buf_free[ECON_MASS_STRLEN],
56 buf_needed[ECON_MASS_STRLEN];
61 _(
"Not Enough Cargo Space" ),
62 _(
"Your ship '%s' has %s of cargo but there is only %s of "
63 "free space in the rest of the fleet. Get rid of %s of "
64 "cargo to shrink your fleet?" ),
65 p->name, buf_amount, buf_free, buf_needed ) ) {
76 if ( e->
type != ESCORT_TYPE_FLEET )
78 if ( strcmp( pe->
name, p->name ) == 0 ) {
84 WARN( _(
"Player deployed ship '%s' not found in escort list!" ),
92 for (
int i = 0; i <
array_size( p->commodities ); i++ ) {
129 WARN( _(
"Trying to deploy fleet ship '%s' despite not being space "
138 a = RNGF() * 2. * M_PI;
139 vec2_cset( &v,
player.p->solid.pos.x + 50. * cos( a ),
140 player.p->solid.pos.y + 50. * sin( a ) );
148 pilot_setFlag( ps->
p, PILOT_INVINC_PLAYER );
149 pilot_rmFlag( ps->
p, PILOT_PLAYER );
159 for (
int i =
array_size( p->commodities ) - 1; i >= 0; i-- ) {
169 for (
int j = 0; j <
array_size( *pclist ); j++ ) {
198static int pc_cmp(
const void *pa,
const void *pb )
204 if ( ( pca->
id > 0 ) && ( pcb->
id == 0 ) )
206 else if ( ( pca->
id == 0 ) && ( pcb->
id > 0 ) )
220 if ( pc_add != NULL )
224 shipCargo( &pclist,
player.p, 1 );
230 if ( e->
type != ESCORT_TYPE_FLEET )
232 shipCargo( &pclist, pe, 1 );
239 for (
int i = 0; i <
array_size( pclist ); i++ ) {
249 if (
landed && ( q < pc->quantity ) )
255 WARN( _(
"Failure to add cargo '%s' to player fleet. Only %d of %d "
283 if (
player.fleet_capacity <= 0 )
290 if ( e->
type != ESCORT_TYPE_FLEET )
307 if (
player.fleet_capacity <= 0 )
314 if ( e->
type != ESCORT_TYPE_FLEET )
348 if (
player.fleet_capacity <= 0 )
355 if ( e->
type != ESCORT_TYPE_FLEET )
362static int pfleet_cargoAddRaw(
const Commodity *com,
int q )
365 if ( (
player.fleet_capacity <= 0 ) || ( q - added <= 0 ) )
372 if ( e->
type != ESCORT_TYPE_FLEET )
375 if ( q - added <= 0 )
394 memset( &pc, 0,
sizeof( pc ) );
413 unsigned int id = pilot_genMissionCargoID(
player.p );
414 memset( &pc, 0,
sizeof( pc ) );
435 if (
player.fleet_capacity <= 0 )
443 if ( e->
type != ESCORT_TYPE_FLEET )
451 if ( q - removed <= 0 )
454 if ( q - removed > 0 ) {
473 shipCargo( &pclist,
player.p, 0 );
479 if ( e->
type != ESCORT_TYPE_FLEET )
481 shipCargo( &pclist, pe, 0 );
507 if ( e->
type != ESCORT_TYPE_FLEET )
int ai_pinit(Pilot *p, const char *ai)
Initializes the pilot in the ai.
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
#define array_erase(ptr_array, first, last)
Erases elements in interval [first, last).
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
void tonnes2str(char *str, int tonnes)
Converts tonnes to a usable string for displaying.
int dialogue_YesNo(const char *caption, const char *fmt,...)
Runs a dialogue with both yes and no options.
void equipment_updateShips(unsigned int wid, const char *str)
Updates the player's ship window.
int escort_clearDeployed(Pilot *p, int slot)
Clears deployed escorts of a pilot.
unsigned int escort_createRef(Pilot *p, Pilot *pe, const vec2 *pos, const vec2 *vel, double dir, EscortType_t type, int add, int dockslot)
Creates an escort from a reference.
void escort_rmListIndex(Pilot *p, int i)
Remove from escorts list.
unsigned int land_getWid(int window)
Gets the WID of a window by type.
Header file with generic functions and naev-specifics.
void pilot_free(Pilot *p)
Frees and cleans up a pilot.
void pilot_stackRemove(Pilot *p)
Tries to remove a pilot from the stack.
void pilot_reset(Pilot *pilot)
Resets a pilot.
Pilot * pilot_get(unsigned int id)
Pulls a pilot out of the pilot_stack based on ID.
int pilot_cargoFree(const Pilot *p)
Gets the pilot's free cargo space.
int pilot_cargoRm(Pilot *pilot, const Commodity *cargo, int quantity)
Tries to get rid of quantity cargo from pilot.
int pilot_cargoOwned(const Pilot *pilot, const Commodity *cargo)
Gets how many of the commodity a pilot has.
int pilot_cargoJet(Pilot *p, const Commodity *cargo, int quantity, int simulate)
Tries to get rid of quantity cargo from pilot, jetting it into space.
int pilot_cargoAdd(Pilot *pilot, const Commodity *cargo, int quantity, unsigned int id)
Tries to add quantity of cargo to pilot.
int pilot_cargoUsed(const Pilot *p)
Gets how much cargo ship has on board.
int pilot_cargoAddRaw(Pilot *pilot, const Commodity *cargo, int quantity, unsigned int id)
Adds cargo without checking the pilot's free space.
void pilot_cargoCalc(Pilot *pilot)
Calculates how much cargo ship has left and such.
int pilot_isSpaceworthy(const Pilot *p)
Pilot safety check - makes sure stats are safe.
void pilot_weaponAuto(Pilot *p)
Tries to automatically set and create the pilot's weapon set.
const PlayerShip_t * player_getShipStack(void)
Gets the array (array.h) of the player's ships.
int pfleet_toggleDeploy(PlayerShip_t *ps, int deploy)
Toggles a player ship as deployed.
int pfleet_deploy(PlayerShip_t *ps)
Deploys a player's pilot.
PilotCommodity * pfleet_cargoList(void)
Gets a list of all the cargo in the fleet.
PFleetCargo * pfleet_cargoListShips(const Commodity *com)
Gets the list of ships that are carry a certain commodity in the player fleet and the amount they are...
unsigned int pfleet_cargoMissionAdd(const Commodity *com, int q)
Adds some mission cargo to the player's fleet.
int pfleet_cargoFree(void)
Gets the total amount of free cargo space in the player's fleet.
void pfleet_cargoRedistribute(void)
Redistributes the cargo in the player's fleet.
int pfleet_cargoOwned(const Commodity *com)
Gets the total amount of a commodity type owned by the player's fleet.
int pfleet_cargoAdd(const Commodity *com, int q)
Adds some cargo to the player's fleet.
int pfleet_cargoRm(const Commodity *com, int q, int jet)
Removes some cargo from the player's fleet.
int pfleet_cargoMissionFree(void)
Gets the free mission cargo space in the player's fleet.
int pfleet_cargoUsed(void)
Gets the total cargo space used by the player's fleet.
static void pfleet_cargoRedistributeInternal(PilotCommodity *pc_add)
Redistributes the cargo in the player's fleet.
void pfleet_update(void)
Updates the used fleet capacity of the player.
Stores a pilot commodity.
const Commodity * commodity
The representation of an in-game pilot.