[Add] pilot_copy function.
This commit is contained in:
parent
2b8d4ecd82
commit
829d24eb79
29
src/pilot.c
29
src/pilot.c
@ -748,6 +748,35 @@ unsigned int pilot_create(Ship* ship, char* name, Faction* faction,
|
||||
return dyn->id;
|
||||
}
|
||||
|
||||
// Copy src pilot to dest.
|
||||
void pilot_copy(Pilot* dest, Pilot* src) {
|
||||
memcpy(dest, src, sizeof(Pilot));
|
||||
if(src->name) dest->name = strdup(src->name);
|
||||
|
||||
// Solid.
|
||||
dest->solid = malloc(sizeof(Solid));
|
||||
memcpy(dest->solid, src->solid, sizeof(Solid));
|
||||
|
||||
// Copy outfits.
|
||||
dest->outfits = malloc(sizeof(PilotOutfit)*src->noutfits);
|
||||
memcpy(dest->outfits, src->outfits,
|
||||
sizeof(PilotOutfit)*src->noutfits);
|
||||
dest->secondary = NULL;
|
||||
dest->ammo = NULL;
|
||||
dest->afterburner = NULL;
|
||||
|
||||
// Copy commodities.
|
||||
dest->commodities = malloc(sizeof(PilotCommodity)*src->ncommodities);
|
||||
memcpy(dest->commodities, src->commodities,
|
||||
sizeof(PilotCommodity)*src->ncommodities);
|
||||
|
||||
// Ai is not copied.
|
||||
dest->task = NULL;
|
||||
|
||||
// Will set afterburner and correct stats.
|
||||
pilot_calcStats(dest);
|
||||
}
|
||||
|
||||
// Frees and cleans up a pilot.
|
||||
static void pilot_free(Pilot* p) {
|
||||
if(player == p) player = NULL;
|
||||
|
@ -149,6 +149,8 @@ unsigned int pilot_create(Ship* ship, char* name, Faction* faction,
|
||||
AI_Profile* ai, const double dir, const Vec2* pos,
|
||||
const Vec2* vel, const int flags);
|
||||
|
||||
void pilot_copy(Pilot* dest, Pilot* src);
|
||||
|
||||
// Init/Cleanup.
|
||||
void pilot_destroy(Pilot* p);
|
||||
void pilots_free(void);
|
||||
|
@ -25,7 +25,9 @@ extern int player_credits;
|
||||
extern int combat_crating;
|
||||
|
||||
// Enums.
|
||||
typedef enum RadarShape_ { RADAR_RECT, RADAR_CIRCLE } RadarShape; // For render functions.
|
||||
|
||||
// For render functions.
|
||||
typedef enum RadarShape_ { RADAR_RECT, RADAR_CIRCLE } RadarShape;
|
||||
|
||||
// Creation.
|
||||
void player_new(void);
|
||||
|
Loading…
Reference in New Issue
Block a user