#pragma once
#include "pilot.h"

/* Flag definitions. */
#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 facing opposite of vel. */
#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_PRIMARY_L    (1<<12)   /**< Player shot primary weapon last frame. */
#define PLAYER_SECONDARY    (1<<13)   /**< Player is shooting secondary weapon. */
#define PLAYER_SECONDARY_L  (1<<14)   /**< Player shot secondary last frame. */
#define PLAYER_LANDACK      (1<<15)   /**< Player has permission to land. */
#define PLAYER_CREATING     (1<<16)   /**< Player is being created. */

/* Flag functions. */
#define player_isFlag(f)  (player_flags  & f)   /**< Check for a player flag. */
#define player_setFlag(f) if(!player_isFlag(f)) (player_flags |= f) /**< Set a player flag. */
#define player_rmFlag(f)  if(player_isFlag(f)) (player_flags ^= f)  /**< Remove a player flag. */

/* The player. */
extern Pilot* pilot;                /**< The player. */
extern char* player_name;           /**< Player's name. */
extern unsigned int player_flags;   /**< Player's flags. */
extern int player_crating;          /**< Player's combat rating. */

/* Enums. */

/* For render functions. */
typedef enum RadarShape_ { RADAR_RECT, RADAR_CIRCLE } RadarShape; /**< Player's radar shape. */

/* Creation/Cleanup. */
void player_new(void);
int player_newShip(Ship* ship, double px, double py,
                    double vx, double vy, double dir);
void player_cleanup(void);
int gui_load(const char* name);

/* Render. */
int gui_init(void);
void gui_free(void);
void player_render(void);
void player_renderBG(void);   /* Render BG layer. */
void player_renderGUI(void);  /* Render the GUI stuff. */

/* Misc. */
void player_message(const char* fmt, ...);
void player_clear(void);
void player_warp(const double x, const double y);
const char* player_rating(void);
void player_playSound(int sound, int once);
/* Cargo. */
int player_outfitOwned(const char* outfitname);
int player_cargoOwned(const char* commodityname);
void player_rmMissionCargo(unsigned int cargo_id);

/* Pilot ships. */
void    player_ships(char** sships, glTexture** tships);
int     player_nships(void);
Pilot*  player_getShip(char* shipname);
char*   player_getLoc(char* shipname);
void    player_setLoc(char* shipname, char* loc);
void    player_swapShip(char* shipname);
int     player_shipPrice(char* shipname);
void    player_rmShip(char* shipname);

/* Player missions. */
void player_missionFinished(int id);
int player_missionAlreadyDone(int id);

/* Keybind actions. */
void player_targetHostile(void);
void player_targetNext(void);
void player_targetNearest(void);
void player_setRadarRel(int mod);
void player_secondaryNext(void);
void player_targetPlanet(void);
void player_land(void);
void player_targetHyperspace(void);
void player_jump(void);
void player_screenshot(void);
void player_afterburn(void);
void player_afterburnOver(void);
void player_accel(double acc);
void player_accelOver(void);

