[Add] player.c is now partially documented.

This commit is contained in:
Allanis 2013-09-02 17:08:51 +01:00
parent 28f6e07768
commit d3173f2949

View File

@ -1,3 +1,9 @@
/**
* @file player.c
*
* @brief Contains all the player related stuff.
*/
#include <malloc.h> #include <malloc.h>
#include "lephisto.h" #include "lephisto.h"
@ -24,54 +30,54 @@
#include "spfx.h" #include "spfx.h"
#include "player.h" #include "player.h"
#define XML_GUI_ID "GUIs" /* XML section identifier. */ #define XML_GUI_ID "GUIs" /**< XML section identifier for GUI document. */
#define XML_GUI_TAG "gui" #define XML_GUI_TAG "gui" /**< XML section identifier for GUI tags. */
#define XML_START_ID "Start" #define XML_START_ID "Start" /**< Module start xml document identifier. */
#define GUI_DATA "../dat/gui.xml" #define GUI_DATA "../dat/gui.xml" /**< Global GUI configuration file. */
#define GUI_GFX "../gfx/gui/" #define GUI_GFX "../gfx/gui/" /**< Location of the GUI graphics. */
#define START_DATA "../dat/start.xml" #define START_DATA "../dat/start.xml" /**< Module start information file. */
#define TARGET_WIDTH 128 #define TARGET_WIDTH 128 /**< Width of target graphics. */
#define TARGET_HEIGHT 96 #define TARGET_HEIGHT 96 /**< Height of target graphics. */
#define PLAYER_RESERVED_CHANNELS 4 #define PLAYER_RESERVED_CHANNELS 4 /**< Number of channels to reserve for player sounds. */
#define PLAYER_CHANNEL 0 #define PLAYER_CHANNEL 0 /**< Player channel. */
/* Player stuff. */ /* Player stuff. */
Pilot* player = NULL; /* extern in pilot.h */ Pilot* player = NULL; /**< The player. */
static Ship* player_ship = NULL; /* Temp ship to hold when naming it. */ static Ship* player_ship = NULL; /**< Temp ship to hold when naming it. */
static double player_px, player_py, player_vx, player_vy, player_dir; static double player_px, player_py, player_vx, player_vy, player_dir; /**< More hack. */
static int player_credits = 0; /* Temp hack. */ static int player_credits = 0; /**< Temp hack on create. */
/* Player pilot stack - Ships she owns. */ /* Player pilot stack - Ships she owns. */
static Pilot** player_stack = NULL; static Pilot** player_stack = NULL; /**< Stack of ships player has. */
static char** player_lstack = NULL; /* Names of the planet the ships are at. */ static char** player_lstack = NULL; /**< Names of the planet the ships are at. */
static int player_nstack = 0; static int player_nstack = 0; /**< Number of ships player has. */
/* Player global properties. */ /* Player global properties. */
char* player_name = NULL; /* Player name. */ char* player_name = NULL; /**< Player name. */
int player_crating = 0; /* Ze rating. */ int player_crating = 0; /**< Player combar rating. */
unsigned int player_flags = 0; /* Player flags. */ unsigned int player_flags = 0; /**< Player flags. */
/* Input.c */ /* Input.c */
double player_turn = 0.; /* Turn velocity from input. */ double player_turn = 0.; /**< Turn velocity from input. */
static double player_acc = 0.; /* Accel velocity from input. */ static double player_acc = 0.; /**< Accel velocity from input. */
unsigned int player_target = PLAYER_ID; /* Targetted pilot. */ unsigned int player_target = PLAYER_ID; /**< Targetted pilot. */
/* Internal */ /* Internal */
int planet_target = -1; /* Targetted planet. */ int planet_target = -1; /**< Targetted planet. */
int hyperspace_target = -1; /* Target hyperspace route. */ int hyperspace_target = -1; /**< Target hyperspace route. */
/* For death etc. */ /* For death etc. */
static unsigned int player_timer = 0; static unsigned int player_timer = 0; /**< For death and such. */
static Vec2 player_cam; static Vec2 player_cam; /**< Again, for death etc. */
static int* missions_done = NULL; /* Saves position. */ static int* missions_done = NULL; /**< Saves position of completed missions. */
static int missions_mdone = 0; static int missions_mdone = 0; /**< Memory size of completed missions. */
static int missions_ndone = 0; static int missions_ndone = 0; /**< Number of completed missions. */
/* Pilot stuff for GUI. */ /* Pilot stuff for GUI. */
extern Pilot** pilot_stack; extern Pilot** pilot_stack;
@ -82,17 +88,17 @@ extern StarSystem* systems_stack;
/* GUI crap. */ /* GUI crap. */
typedef struct Radar_ { typedef struct Radar_ {
double x,y; /* Position. */ double x,y; /**< Position. */
double w,h; /* Dimensions. */ double w,h; /**< Dimensions. */
RadarShape shape; RadarShape shape; /**< Shape. */
double res; /* Resolution. */ double res; /**< Resolution. */
} Radar; } Radar;
/* Radar res. */ /* Radar res. */
#define RADAR_RES_MAX 100. #define RADAR_RES_MAX 100. /**< Max radar resolution. */
#define RADAR_RES_MIN 10. #define RADAR_RES_MIN 10. /**< Min radar resolution. */
#define RADAR_RES_INTERVAL 10. #define RADAR_RES_INTERVAL 10. /**< Steps used to increase/decrease resolution. */
#define RADAR_RES_DEFAULT 40. #define RADAR_RES_DEFAULT 40. /**< Default resolution. */
typedef struct Rect_ { typedef struct Rect_ {
double x,y; double x,y;
@ -101,40 +107,41 @@ typedef struct Rect_ {
typedef struct GUI_ { typedef struct GUI_ {
/* Graphics. */ /* Graphics. */
glTexture* gfx_frame; glTexture* gfx_frame; /**< Frame of the GUI. */
glTexture* gfx_targetPilot, *gfx_targetPlanet; glTexture* gfx_targetPilot, *gfx_targetPlanet; /**< Graphics used to target planets. */
Radar radar; Radar radar; /**< The radar. */
Rect nav; Rect nav; /**< Navigation computer. */
Rect shield, armour, energy; Rect shield, armour, energy; /**< Health bars. */
Rect weapon; Rect weapon; /**< Weapon targeting system. */
Rect target_health, target_name, target_faction; Rect target_health, target_name, target_faction; /**< Target stuff. */
Rect misc; Rect misc; /**< Misc stuff: credits, cargo.. */
Rect msg; Rect msg; /**< Where messages go. */
/* Positions. */ /* Positions. */
Vec2 frame; Vec2 frame; /**< Global frame position. */
Vec2 target; Vec2 target; /**< Global target position. */
} GUI; } GUI;
GUI gui = { static GUI gui = {
.gfx_frame = NULL, .gfx_frame = NULL,
.gfx_targetPilot = NULL, .gfx_targetPilot = NULL,
.gfx_targetPlanet = NULL .gfx_targetPlanet = NULL
}; }; /**< The GUI. */
/* Needed to render properly. */
double gui_xoff = 0.; double gui_xoff = 0.;
double gui_yoff = 0.; double gui_yoff = 0.;
/* Messages. */ /* Messages. */
#define MSG_SIZE_MAX 80 #define MSG_SIZE_MAX 80
int msg_timeout = 5000; int msg_timeout = 5000; /**< How long it takes for a message to timeout. */
int msg_max = 5; /* Max messages on screen. */ int msg_max = 5; /**< Max messages on screen. */
typedef struct Msg_ { typedef struct Msg_ {
char str[MSG_SIZE_MAX]; char str[MSG_SIZE_MAX];
unsigned int t; unsigned int t;
} Msg; } Msg;
static Msg* msg_stack; static Msg* msg_stack; /**< Stack of messages. */
/* External. */ /* External. */
extern void pilot_render(const Pilot* pilot); /* Extern is in Pilot.* */ extern void pilot_render(const Pilot* pilot); /* Extern is in Pilot.* */
@ -172,7 +179,16 @@ void player_think(Pilot* player);
void player_brokeHyperspace(void); void player_brokeHyperspace(void);
double player_faceHyperspace(void); double player_faceHyperspace(void);
/* Prompt player name. */ /**
* @fn void player_new(void)
*
* @brief Create a new player.
*
* - Cleans up after old player.
* - Prompts for name.
*
* @sa player_newMake
*/
void player_new(void) { void player_new(void) {
int r; int r;
/* Let's not seg fault due to a lack of environment. */ /* Let's not seg fault due to a lack of environment. */
@ -207,7 +223,11 @@ void player_new(void) {
player_newMake(); player_newMake();
} }
/* Create a new player. */ /**
* @fn static void player_newMake(void)
*
* @brief Actually create a new player.
*/
static void player_newMake(void) { static void player_newMake(void) {
Ship* ship; Ship* ship;
char* sysname; char* sysname;
@ -294,7 +314,14 @@ static void player_newMake(void) {
map_clear(); map_clear();
} }
/* Create a dialogue to name the new ship. */ /**
* @fn void player_newShip(Ship* ship, double px, double py,
* double vx, double vy, double dir)
*
* @brief Create a new ship for player.
*
* @sa player_newShipMake
*/
void player_newShip(Ship* ship, double px, double py, void player_newShip(Ship* ship, double px, double py,
double vx, double vy, double dir) { double vx, double vy, double dir) {
@ -315,7 +342,11 @@ void player_newShip(Ship* ship, double px, double py,
free(ship_name); free(ship_name);
} }
/* Change the players ship. */ /**
* @fn static void player_newShipMake(char* name)
*
* @brief Actually create the new ship.
*/
static void player_newShipMake(char* name) { static void player_newShipMake(char* name) {
Vec2 vp, vv; Vec2 vp, vv;
@ -348,7 +379,12 @@ static void player_newShipMake(char* name) {
player_credits = 0; player_credits = 0;
} }
/* Swaps the current ship with shipname. */ /**
* @fn void player_swapShip(char* shipname)
*
* @brief Swap players current ship with her ship named 'shipname'.
* @param shipname Ship to change to.
*/
void player_swapShip(char* shipname) { void player_swapShip(char* shipname) {
int i, j; int i, j;
Pilot* ship; Pilot* ship;
@ -387,7 +423,11 @@ void player_swapShip(char* shipname) {
WARN("Unable to swap player with ship '%s': Ship does not exist!", shipname); WARN("Unable to swap player with ship '%s': Ship does not exist!", shipname);
} }
/* Clean up player stuff like player_stack. */ /**
* @brief void player_cleanup(void
*
* @brief Clean up player stuff like player_stack.
*/
void player_cleanup(void) { void player_cleanup(void) {
int i; int i;
@ -429,8 +469,12 @@ void player_cleanup(void) {
} }
} }
/* Initializes the player sound. */ /**
static int player_soundReserved = 0; * @fn static void player_initSound(void)
*
* @brief Initialize the player sounds.
*/
static int player_soundReserved = 0; /**< Has the player already reserved sound? */
static void player_initSound(void) { static void player_initSound(void) {
if(player_soundReserved) return; if(player_soundReserved) return;
@ -439,15 +483,32 @@ static void player_initSound(void) {
player_soundReserved = 1; player_soundReserved = 1;
} }
/* Play a sound. */ /**
* @fn static void player_playSound(int sound, int once)
*
* @brief Play a sound at the player.
* @param sound ID of the sound to play.
* @param once Play only once?
*/
static void player_playSound(int sound, int once) { static void player_playSound(int sound, int once) {
sound_playGroup(PLAYER_CHANNEL, sound, once); sound_playGroup(PLAYER_CHANNEL, sound, once);
} }
/**
* @fn static void player_stopSound(void)
*
* @brief Stop playing player sounds.
*/
static void player_stopSound(void) { static void player_stopSound(void) {
sound_stopGroup(PLAYER_CHANNEL); sound_stopGroup(PLAYER_CHANNEL);
} }
/**
* @fn void player_message(const char* fmt, ...)
*
* @brief Add a msg to the queue to be displayed on screen.
* @param fmt String with formatting like prinf.
*/
void player_message(const char* fmt, ...) { void player_message(const char* fmt, ...) {
va_list ap; va_list ap;
int i; int i;
@ -469,17 +530,35 @@ void player_message(const char* fmt, ...) {
msg_stack[0].t = SDL_GetTicks() + msg_timeout; msg_stack[0].t = SDL_GetTicks() + msg_timeout;
} }
/**
* @fn void player_warp(const double x, const double y)
*
* @brief Warp the player to the new position.
* @param x X value of the position to warp to.
* @param y Y value of the position to warp to.
*/
void player_warp(const double x, const double y) { void player_warp(const double x, const double y) {
vect_cset(&player->solid->pos, x, y); vect_cset(&player->solid->pos, x, y);
} }
/* Clear the targets. */ /**
* @fn player_clear(void)
*
* @brief Clear the targets.
*/
void player_clear(void) { void player_clear(void) {
player_target = PLAYER_ID; player_target = PLAYER_ID;
planet_target = -1; planet_target = -1;
hyperspace_target = -1; hyperspace_target = -1;
} }
/**
* @fn const char* player_rating(void)
*
* @brief Get the players combat rating in a human readable string.
*
* @return The players combat rating in a human readable string.
*/
static char* player_ratings[] = { static char* player_ratings[] = {
"None", "None",
"Smallfry", "Smallfry",
@ -501,7 +580,13 @@ const char* player_rating(void) {
else return player_ratings[7]; else return player_ratings[7];
} }
/* Return amount of outfits the player owns. */ /**
* @fn int player_outfitOwned(const char* outfitname)
*
* @brief Get how many of the outfits the player owns.
* @param outfitname Outfit to check how many the player owns of.
* @return The number of outfits matching outfitname owned.
*/
int player_outfitOwned(const char* outfitname) { int player_outfitOwned(const char* outfitname) {
int i; int i;