1 /* 2 * See Licensing and Copyright notice in naev.h 3 */ 4 5 6 #ifndef PLAYER_H 7 # define PLAYER_H 8 9 10 #include "pilot.h" 11 12 /** Player flag enum. */ 13 enum { 14 PLAYER_TURN_LEFT, /**< player is turning left */ 15 PLAYER_TURN_RIGHT, /**< player is turning right */ 16 PLAYER_REVERSE, /**< player is facing opposite of vel */ 17 PLAYER_ACCEL, /**< player is accelerating */ 18 PLAYER_DESTROYED, /**< player is destroyed */ 19 PLAYER_FACE, /**< player is facing target */ 20 PLAYER_PRIMARY, /**< player is shooting primary weapon */ 21 PLAYER_PRIMARY_L, /**< player shot primary weapon last frame. */ 22 PLAYER_SECONDARY, /**< player is shooting secondary weapon */ 23 PLAYER_SECONDARY_L, /**< player shot secondary last frame. */ 24 PLAYER_LANDACK, /**< player has permission to land */ 25 PLAYER_CREATING, /**< player is being created */ 26 PLAYER_AUTONAV, /**< player has autonavigation on. */ 27 PLAYER_NOLAND, /**< player is not allowed to land (cleared on enter). */ 28 PLAYER_DOUBLESPEED, /**< player is running at double speed. */ 29 PLAYER_CINEMATICS_GUI, /**< Disable rendering the GUI when in cinematics mode. */ 30 PLAYER_CINEMATICS_2X, /**< Disables usage of the 2x button when in cinematics mode. */ 31 PLAYER_HOOK_LAND, /**< Hook hack to avoid running hooks in the middle of the pilot stack. */ 32 PLAYER_HOOK_JUMPIN, /**< Hook hack to avoid running hooks in the middle of the pilot stack. */ 33 PLAYER_HOOK_HYPER, /**< Hook hack to avoid runving hooks in the middle of the pilot stack. */ 34 PLAYER_TUTORIAL, /**< Player is doing the tutorial. */ 35 PLAYER_MFLY, /**< Player has enabled mouse flying. */ 36 PLAYER_NOSAVE, /**< Player is not allowed to save. */ 37 PLAYER_FLAGS_MAX /* Maximum number of flags. */ 38 }; 39 40 typedef char PlayerFlags[ PLAYER_FLAGS_MAX ]; 41 42 /* flag functions */ 43 #define player_isFlag(f) (player.flags[f]) 44 #define player_setFlag(f) (player.flags[f] = 1) 45 #define player_rmFlag(f) (player.flags[f] = 0) 46 47 /* comfort flags. */ 48 #define player_isTut() player_isFlag(PLAYER_TUTORIAL) 49 50 51 /* Control restoration reasons. */ 52 enum { 53 PINPUT_NULL, /* No specific reason. */ 54 PINPUT_MOVEMENT, /* Player pressed a movement key. */ 55 PINPUT_AUTONAV, /* Player engaged autonav. */ 56 PINPUT_BRAKING /* Player engaged auto-braking. */ 57 }; 58 59 60 #include "player_autonav.h" 61 62 63 /** 64 * The player struct. 65 */ 66 typedef struct Player_s { 67 /* Player intrinsics. */ 68 Pilot *p; /**< Player's pilot. */ 69 char *name; /**< Player's name. */ 70 char *gui; /**< Player's GUI. */ 71 int guiOverride; /**< GUI is overridden (not default). */ 72 73 /* Player data. */ 74 PlayerFlags flags; /**< Player's flags. */ 75 int enemies; /**< Amount of enemies the player has. */ 76 double crating; /**< Combat rating. */ 77 int autonav; /**< Current autonav state. */ 78 Vector2d autonav_pos; /**< Target autonav position. */ 79 char *autonavmsg; /**< String to print on arrival. */ 80 double tc_max; /**< Maximum time compression value (bounded by ship speed or conf setting). */ 81 double autonav_timer; /**< Timer that prevents time accel after a reset. */ 82 double mousex; /**< Mouse X position (for mouse flying). */ 83 double mousey; /**< Mouse Y position (for mouse flying). */ 84 } Player_t; 85 86 87 /** 88 * @brief Wrapper for outfits. 89 */ 90 typedef struct PlayerOutfit_s { 91 const Outfit *o; /**< Actual associated outfit. */ 92 int q; /**< Amount of outfit owned. */ 93 } PlayerOutfit_t; 94 95 96 /** 97 * @brief Player ship. 98 */ 99 typedef struct PlayerShip_s { 100 Pilot* p; /**< Pilot. */ 101 char *loc; /**< Location. */ 102 int autoweap; /**< Automatically update weapon sets. */ 103 } PlayerShip_t; 104 105 106 /* 107 * Local player. 108 */ 109 extern Player_t player; /**< Local player. */ 110 111 112 /* 113 * Common player sounds. 114 */ 115 extern int snd_target; /**< Sound when targeting. */ 116 extern int snd_jump; /**< Sound when can jump. */ 117 extern int snd_nav; /**< Sound when changing nav computer. */ 118 extern int snd_hail; /**< Hail sound. */ 119 extern int snd_hypPowUp; /**< Hyperspace power up sound. */ 120 extern int snd_hypEng; /**< Hyperspace engine sound. */ 121 extern int snd_hypPowDown; /**< Hyperspace power down sound. */ 122 extern int snd_hypPowUpJump; /**< Hyperspace Power up to jump sound. */ 123 extern int snd_hypJump; /**< Hyperspace jump sound. */ 124 125 126 /* 127 * creation/cleanup 128 */ 129 int player_init (void); 130 void player_new (void); 131 void player_newTutorial (void); 132 Pilot* player_newShip( Ship* ship, const char *def_name, 133 int trade, int noname ); 134 void player_cleanup (void); 135 136 /* 137 * Hook voodoo. 138 */ 139 void player_runHooks (void); 140 141 142 /* 143 * render 144 */ 145 void player_render( double dt ); 146 147 148 /* 149 * Message stuff, in gui.c 150 */ 151 void player_messageToggle( int enable ); 152 void player_message( const char *fmt, ... ); 153 void player_messageRaw ( const char *str ); 154 155 /* 156 * misc 157 */ 158 void player_restoreControl( int reason, char *str ); 159 void player_checkLandAck (void); 160 void player_nolandMsg( const char *str ); 161 void player_clear (void); 162 void player_warp( const double x, const double y ); 163 const char* player_rating (void); 164 int player_hasCredits( credits_t amount ); 165 credits_t player_modCredits( credits_t amount ); 166 void player_hailStart (void); 167 int player_canTakeoff (void); 168 /* Sounds. */ 169 void player_soundPlay( int sound, int once ); 170 void player_soundPlayGUI( int sound, int once ); 171 void player_soundStop (void); 172 void player_soundPause (void); 173 void player_soundResume (void); 174 175 176 /* 177 * player ships 178 */ 179 int player_ships( char** sships, glTexture** tships ); 180 const PlayerShip_t* player_getShipStack( int *n ); 181 int player_nships (void); 182 int player_hasShip( char* shipname ); 183 Pilot* player_getShip( char* shipname ); 184 char* player_getLoc( char* shipname ); 185 void player_setLoc( char* shipname, char* loc ); 186 void player_swapShip( char* shipname ); 187 credits_t player_shipPrice( char* shipname ); 188 void player_rmShip( char* shipname ); 189 190 191 /* 192 * player outfits. 193 */ 194 int player_outfitOwned( const Outfit *o ); 195 const PlayerOutfit_t* player_getOutfits( int *n ); 196 int player_getOutfitsFiltered( Outfit **outfits, glTexture **toutfits, 197 int(*filter)( const Outfit *o ), char *name ); 198 int player_numOutfits (void); 199 int player_addOutfit( const Outfit *o, int quantity ); 200 int player_rmOutfit( const Outfit *o, int quantity ); 201 202 203 /* 204 * player missions 205 */ 206 void player_missionFinished( int id ); 207 int player_missionAlreadyDone( int id ); 208 209 210 /* 211 * player events 212 */ 213 void player_eventFinished( int id ); 214 int player_eventAlreadyDone( int id ); 215 216 217 /* 218 * licenses 219 */ 220 void player_addLicense( char *license ); 221 int player_hasLicense( char *license ); 222 char **player_getLicenses( int *nlicenses ); 223 224 225 /* 226 * escorts 227 */ 228 void player_clearEscorts (void); 229 int player_addEscorts (void); 230 231 232 /* 233 * pilot related stuff 234 */ 235 void player_dead (void); 236 void player_destroyed (void); 237 void player_think( Pilot* pplayer, const double dt ); 238 void player_update( Pilot *pplayer, const double dt ); 239 void player_updateSpecific( Pilot *pplayer, const double dt ); 240 void player_brokeHyperspace (void); 241 void player_hyperspacePreempt( int ); 242 int player_getHypPreempt(void); 243 244 /* 245 * Targeting. 246 */ 247 /* Clearing. */ 248 void player_targetClear (void); 249 /* Planets. */ 250 void player_targetPlanetSet( int id ); 251 void player_targetPlanet (void); 252 /* Hyperspace. */ 253 void player_targetHyperspaceSet( int id ); 254 void player_targetHyperspace (void); 255 /* Pilots. */ 256 void player_targetSet( unsigned int id ); 257 void player_targetHostile (void); 258 void player_targetNext( int mode ); 259 void player_targetPrev( int mode ); 260 void player_targetNearest (void); 261 void player_targetEscort( int prev ); 262 263 /* 264 * keybind actions 265 */ 266 void player_weapSetPress( int id, int type, int repeat ); 267 void player_land (void); 268 int player_jump (void); 269 void player_screenshot (void); 270 void player_accel( double acc ); 271 void player_accelOver (void); 272 void player_hail (void); 273 void player_hailPlanet (void); 274 void player_autohail (void); 275 void player_toggleMouseFly(void); 276 void player_brake(void); 277 278 279 #endif /* PLAYER_H */ 280