From 829d24eb79e1fa5df2d5e260fcb2ad42391f65f0 Mon Sep 17 00:00:00 2001 From: Allanis Date: Fri, 22 Mar 2013 12:48:16 +0000 Subject: [PATCH] [Add] pilot_copy function. --- src/menu.c | 2 +- src/pilot.c | 29 +++++++++++++++++++++++++++++ src/pilot.h | 2 ++ src/player.h | 10 ++++++---- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/menu.c b/src/menu.c index 1acf9c1..c2365f4 100644 --- a/src/menu.c +++ b/src/menu.c @@ -142,7 +142,7 @@ void menu_info(void) { 0, "txtDPilot", &gl_smallFont, &cDConsole, "Pilot:\n" "Combat\n" - " Rating:" + " Rating:" "\n" "Ship:\n"); diff --git a/src/pilot.c b/src/pilot.c index 6da05e9..d0f8024 100644 --- a/src/pilot.c +++ b/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; diff --git a/src/pilot.h b/src/pilot.h index 7d69d27..1187af7 100644 --- a/src/pilot.h +++ b/src/pilot.h @@ -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); diff --git a/src/player.h b/src/player.h index 0755826..49b8f4d 100644 --- a/src/player.h +++ b/src/player.h @@ -5,12 +5,12 @@ #define PLAYER_TURN_LEFT (1<<0) // Player is turning left. #define PLAYER_TURN_RIGHT (1<<1) // Player is turning right. #define PLAYER_REVERSE (1<<2) // Player is facint opposite vel. -#define PLAYER_AFTERBURNER (1<<3) // Player is burning it up. -#define PLAYER_DESTROYED (1<<9) // Player goes BOOM! +#define PLAYER_AFTERBURNER (1<<3) // Player is burning it up. +#define PLAYER_DESTROYED (1<<9) // Player goes BOOM! #define PLAYER_FACE (1<<10) // Player is facing target. #define PLAYER_PRIMARY (1<<11) // Player is shooting primary 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. #define player_isFlag(f) (player_flags & f) @@ -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);