1 //----------------------------------------------------------------------------- 2 // Client 3 //----------------------------------------------------------------------------- 4 5 #ifndef __CLIENT_H__ 6 #define __CLIENT_H__ 7 8 #include "types.h" 9 #include "camera.h" 10 #include "definitions.h" 11 12 /** 13 * Indexes for different player sounds. 14 */ 15 typedef struct 16 { 17 // specific sounds 18 int death1; 19 int death2; 20 int death3; 21 int drown; 22 int fall1; 23 int falling1; 24 int gasp; 25 int jump1; 26 int pain25_1; 27 int pain50_1; 28 int pain75_1; 29 int pain100_1; 30 int taunt; 31 32 // common sounds 33 int fry; 34 int gibimp1; 35 int gibimp2; 36 int gibimp3; 37 int gibsplt1; 38 int gurp1; 39 int gurp2; 40 int land1; 41 int talk; 42 int watr_in; 43 int watr_out; 44 int watr_un; 45 } PlayerSounds; 46 47 /** 48 * User command. 49 * This structure contains all possible commands for user. 50 */ 51 typedef struct 52 { 53 float forwardmove; 54 float sidemove; 55 float upmove; 56 float move_mouse_x; 57 float move_mouse_y; 58 } usercmd_t; 59 60 /** 61 * Client class. 62 * The client class represents an entity that can move in the world. It is 63 * generally used to represent players or bots. A camera is attached to the 64 * client, and for each clients, the world is represented following this 65 * own camera. 66 * @todo Make friction and acceleration dependent on ground slope, so it is 67 * easier to accelerate on a descending slope, and harder to stop (less 68 * friction). 69 */ 70 class Client 71 { 72 public: 73 Client(void); 74 ~Client(void); 75 76 /** 77 * Client initialization. 78 */ 79 void Init(int left = 0, int top = 0, int width = -1, int height = -1); 80 81 /** 82 * Loads a player. 83 * This function loads the player skin and sounds. For example, the 84 * playername parameter only contains "sarge" or "anarki" to load 85 * corresponding player settings. 86 * @param playername The name of player to be loaded. 87 */ 88 void LoadPlayer(const char *playername); 89 90 void Shut(void); /**< Client shuting out */ 91 92 /** 93 * Update client. 94 * Calculates client future position and updates camera orientation 95 * using current rotation matrix and tranlsation values. The function 96 * also simulates the acceleration and friction effects. 97 * @param bsp The binary space tree the client is eveolving in 98 * @param wld The client's world 99 */ 100 void Update(Q3BSP *bsp, World *wld); 101 102 /** 103 * Update client camera. 104 * Update the camera associated with current client. 105 * @todo Use viewport instead of camera. 106 */ 107 void UpdateCam(void); 108 109 /** 110 * Reset client movement. 111 */ 112 void ResetMovement(void); 113 114 /** 115 * Set new client angle. 116 * @param p the pitch value 117 * @param y the yaw value 118 * @param r the roll value 119 */ 120 void SetAngle(float p, float y, float r); 121 void SetAngle(vec3_t rot); 122 123 /** 124 * Set new client position. 125 * @param x the x client position 126 * @param y the y client position 127 * @param z the z client position 128 */ 129 void SetPos(float x, float y, float z); 130 void SetPos(vec3_t pos); 131 132 /** 133 * Increment the client angle. 134 * @param p the pitch increment 135 * @param y the yaw increment 136 * @param r the roll increment 137 */ 138 void AddAngle(float p, float y, float r); 139 140 /** 141 * Increment the client position. 142 * @param x the x client offset 143 * @param y the y client offset 144 * @param z the z client offset 145 */ 146 void AddPos(float x, float y, float z); 147 148 /** 149 * Move the client in forward direction. 150 */ 151 void MoveForward(float val = 1.f); 152 153 /** 154 * Move the client backward. 155 * The function will interpret the command and make the client moving 156 * using current speed, acceleration, friction, position and angle. 157 */ 158 void MoveBackward(float val = 1.f); 159 160 /** 161 * Move the client on the left. 162 * The function will interpret the command and make the client moving 163 * using current speed, acceleration, friction, position and angle. 164 */ 165 void MoveLeft(float val = 1.f); 166 167 /** 168 * Move the client on the right. 169 * The function will interpret the command and make the client moving 170 * using current speed, acceleration, friction, position and angle. 171 */ 172 void MoveRight(float val = 1.f); 173 174 /** 175 * Move the client up. 176 * The function will interpret the command and make the client moving 177 * using current speed, acceleration, friction, position and angle. 178 */ 179 void MoveUp(float val = 1.f); 180 181 /** 182 * Move the client down. 183 * The function will interpret the command and make the client moving 184 * using current speed, acceleration, friction, position and angle. 185 */ 186 void MoveDown(float val = 1.f); 187 188 /** 189 * Rotate the client using mouse. 190 * The function will interpret the rotation using mouse. 191 * @param val the yaw rotation value 192 */ 193 void MoveMouseX(float val); 194 195 /** 196 * Rotate the client using mouse. 197 * The function will interpret the rotation using mouse. 198 * @param val the pitch rotation value. 199 */ 200 void MoveMouseY(float val); 201 202 /** 203 * Rotates the client using mouse. 204 * The function is similar to moveMouseX and moveMouseY and permits to 205 * specify the mouse movement for x and y using a single function call. 206 * @param xval the yaw rotation value 207 * @param yval the pitch rotation value 208 */ 209 void MoveMouseXY(float xval, float yval); 210 211 /** 212 * Zoom or unzoom the camera. 213 * The function change the camera fov for zooming. If argument is 214 * positive fov is increased, if argument is negative, fov is 215 * decreased. The function check if current camera zoom is in 216 * boundaries. In this case, fov is upadted and function returns 1, 217 * if camera zoom is out of boundaries, fov is not updated and 218 * funcion returns 0. The result value can be used to avoid calling 219 * the function in the main program. 220 * @todo Make zoom depend of timer (because zoom is slower on low fps rate) 221 * @param val the zoom value to add (in degrees) 222 */ 223 void Zoom(float val); 224 225 int TouchBounds(bboxf_t bbox); 226 227 // Movements 228 229 /** 230 * Make the client jump. 231 * This has no effect if client camera is in flying mode. 232 */ 233 void Jump(void); 234 void Land(void); 235 void Fall(void); 236 void Falling(void); 237 void Die(int depthnum = 3); 238 void Gasp(void); 239 void Drown(void); 240 void Pain(int amount); 241 void Taunt(void); 242 void Fry(void); 243 void Gibimp(int type); 244 void Gurp(int type); 245 void Talk(void); 246 void Water(int type); /**< type -> 0 = in, 1 = out, 2 = un */ 247 248 // Triggered actions 249 bool JumpTo(vec3_t dest); 250 bool TeleportTo(vec3_t dest, float angle, float startwalk = 0.f); 251 252 /** 253 * Check the collisions for a client. 254 * @param targetpos the position that client want to get (but may not because of collision) 255 */ 256 void CheckCollision(vec3_t targetpos); 257 trace_t StepSlideMove(vec3_t vel); 258 void StepSlideMove_(vec3_t pos, vec3_t vel, vec3_t mins, vec3_t maxs); 259 void ClipVelocity(vec3_t in, vec3_t normal, vec3_t out, float overbounce); 260 261 /** 262 * Client camera. 263 * The camera is the client eye. 264 * @todo Support multiple cameras (for multiple (stereographic) eyes, rearview mirror, etc.) 265 */ 266 Camera cam; 267 268 /** 269 * Define if the client is an active client, if it can move by itself (active) or not (passive). 270 * By default, all client are active, but they can be changed to passive mode 271 * if required. In passive mode, no collision detection is done. 272 */ 273 bool active_client; 274 275 /** 276 * Define if the client is the current client. In the case there are more than one client 277 * only one can be the current selected client. This clients receives input commands and 278 * have sounds enabled. 279 * This value shouldn't be modified manually. The App class is responsible for this 280 * variable. 281 */ 282 bool isCurrent; 283 284 bool pitchLimit; /**< pitch limitation */ 285 286 float fov; /**< camera fov */ 287 float zoomlimit; /**< fov value when zooming */ 288 float jump_height; /**< height that client can jump */ 289 float max_speed; /**< maximum client translation speed */ 290 float acceleration; /**< client acceleration */ 291 float friction; /**< client friction */ 292 vec3_t forward, right, up; 293 294 vec3_t velocity; /**< velocity vector */ 295 bool flying; /**< client is flying (can't jump) */ 296 bool swimming; 297 bool falling; 298 299 float viewheight; /**< height of camera in the client bounding box */ 300 vec3_t mins, maxs; /**< client min and max sizes */ 301 float step_size; /**< step height that client can climb */ 302 vec3_t extSpeed; /**< external speed used for jumping */ 303 304 // Interpolation stuff 305 float interpolation; /**< Height we are interpolating on */ 306 float startheight; /**< Start height for interpolation */ 307 float progress; /**< Current progress (between 0 and 1) */ 308 309 colour_t color; /**< Used for debug */ 310 311 bool noclip; /**< enable collision */ 312 313 private: 314 315 int armor; /**< amount of resting armor */ 316 int life; /**< amount of resting life */ 317 318 usercmd_t cmd; /**< user command */ 319 320 int nzoom, pzoom; /**< variables used to avoid unnecessary 321 * function calls */ 322 323 char name[MAX_PLAYERNAME_LENGTH]; 324 PlayerSounds sounds; 325 int gender; /**< client gender (1 = male, 2 = female, 3 = other) */ 326 327 double diveStart; /**< time where client dived */ 328 double lastgurptime; /**< time of last grub */ 329 330 Q3BSP *curr_bsp; 331 World *curr_world; 332 }; 333 334 #endif /* __CLIENT_H__ */ 335