[Add] pilot_copy function.

This commit is contained in:
Allanis 2013-03-22 12:48:16 +00:00
parent 2b8d4ecd82
commit 829d24eb79
4 changed files with 38 additions and 5 deletions

View File

@ -142,7 +142,7 @@ void menu_info(void) {
0, "txtDPilot", &gl_smallFont, &cDConsole, 0, "txtDPilot", &gl_smallFont, &cDConsole,
"Pilot:\n" "Pilot:\n"
"Combat\n" "Combat\n"
" Rating:" " Rating:"
"\n" "\n"
"Ship:\n"); "Ship:\n");

View File

@ -748,6 +748,35 @@ unsigned int pilot_create(Ship* ship, char* name, Faction* faction,
return dyn->id; 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. // Frees and cleans up a pilot.
static void pilot_free(Pilot* p) { static void pilot_free(Pilot* p) {
if(player == p) player = NULL; if(player == p) player = NULL;

View File

@ -149,6 +149,8 @@ unsigned int pilot_create(Ship* ship, char* name, Faction* faction,
AI_Profile* ai, const double dir, const Vec2* pos, AI_Profile* ai, const double dir, const Vec2* pos,
const Vec2* vel, const int flags); const Vec2* vel, const int flags);
void pilot_copy(Pilot* dest, Pilot* src);
// Init/Cleanup. // Init/Cleanup.
void pilot_destroy(Pilot* p); void pilot_destroy(Pilot* p);
void pilots_free(void); void pilots_free(void);

View File

@ -5,12 +5,12 @@
#define PLAYER_TURN_LEFT (1<<0) // Player is turning left. #define PLAYER_TURN_LEFT (1<<0) // Player is turning left.
#define PLAYER_TURN_RIGHT (1<<1) // Player is turning right. #define PLAYER_TURN_RIGHT (1<<1) // Player is turning right.
#define PLAYER_REVERSE (1<<2) // Player is facint opposite vel. #define PLAYER_REVERSE (1<<2) // Player is facint opposite vel.
#define PLAYER_AFTERBURNER (1<<3) // Player is burning it up. #define PLAYER_AFTERBURNER (1<<3) // Player is burning it up.
#define PLAYER_DESTROYED (1<<9) // Player goes BOOM! #define PLAYER_DESTROYED (1<<9) // Player goes BOOM!
#define PLAYER_FACE (1<<10) // Player is facing target. #define PLAYER_FACE (1<<10) // Player is facing target.
#define PLAYER_PRIMARY (1<<11) // Player is shooting primary weapon. #define PLAYER_PRIMARY (1<<11) // Player is shooting primary weapon.
#define PLAYER_SECONDARY (1<<12) // Player is shooting secondary weapon. #define PLAYER_SECONDARY (1<<12) // Player is shooting secondary weapon.
#define PLAYER_LANDACK (1<<13) // Player has permission to land. #define PLAYER_LANDACK (1<<13) // Player has permission to land.
// Flag functions. // Flag functions.
#define player_isFlag(f) (player_flags & f) #define player_isFlag(f) (player_flags & f)
@ -25,7 +25,9 @@ extern int player_credits;
extern int combat_crating; extern int combat_crating;
// Enums. // Enums.
typedef enum RadarShape_ { RADAR_RECT, RADAR_CIRCLE } RadarShape; // For render functions.
// For render functions.
typedef enum RadarShape_ { RADAR_RECT, RADAR_CIRCLE } RadarShape;
// Creation. // Creation.
void player_new(void); void player_new(void);