new entity protocol, GREATLY improved over quake, massive net traffic reduction
[divverent/darkplaces.git] / server.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20 // server.h
21
22 typedef struct
23 {
24         int                     maxclients;
25         int                     maxclientslimit;
26         struct client_s *clients;               // [maxclients]
27         int                     serverflags;            // episode completion information
28         qboolean        changelevel_issued;     // cleared when at SV_SpawnServer
29 } server_static_t;
30
31 //=============================================================================
32
33 typedef enum {ss_loading, ss_active} server_state_t;
34
35 typedef struct
36 {
37         qboolean        active;                         // false if only a net client
38
39         qboolean        paused;
40         qboolean        loadgame;                       // handle connections specially
41
42         double          time;
43
44         double          frametime;
45         
46         int                     lastcheck;                      // used by PF_checkclient
47         double          lastchecktime;
48         
49         char            name[64];                       // map name
50         char            modelname[64];          // maps/<name>.bsp, for model_precache[0]
51         struct model_s  *worldmodel;
52         char            *model_precache[MAX_MODELS];    // NULL terminated
53         struct model_s  *models[MAX_MODELS];
54         char            *sound_precache[MAX_SOUNDS];    // NULL terminated
55         char            *lightstyles[MAX_LIGHTSTYLES];
56         int                     num_edicts;
57         int                     max_edicts;
58         edict_t         *edicts;                        // can NOT be array indexed, because
59                                                                         // edict_t is variable sized, but can
60                                                                         // be used to reference the world ent
61         server_state_t  state;                  // some actions are only valid during load
62
63         sizebuf_t       datagram;
64         byte            datagram_buf[MAX_DATAGRAM];
65
66         sizebuf_t       reliable_datagram;      // copied to all clients at end of frame
67         byte            reliable_datagram_buf[MAX_DATAGRAM];
68
69         sizebuf_t       signon;
70         byte            signon_buf[32768]; // LordHavoc: increased signon message buffer from 8192 to 32768
71 } server_t;
72
73
74 #define NUM_PING_TIMES          16
75 #define NUM_SPAWN_PARMS         16
76
77 typedef struct client_s
78 {
79         qboolean                active;                         // false = client is free
80         qboolean                spawned;                        // false = don't send datagrams
81         qboolean                dropasap;                       // has been told to go to another level
82         qboolean                sendsignon;                     // only valid before spawned
83
84         double                  last_message;           // reliable messages must be sent
85                                                                                 // periodically
86
87         struct qsocket_s *netconnection;        // communications handle
88
89         usercmd_t               cmd;                            // movement
90         vec3_t                  wishdir;                        // intended motion calced from cmd
91
92         sizebuf_t               message;                        // can be added to at any time,
93                                                                                 // copied and clear once per frame
94         byte                    msgbuf[MAX_MSGLEN];
95         edict_t                 *edict;                         // EDICT_NUM(clientnum+1)
96         char                    name[32];                       // for printing to other people
97         int                             colors;
98
99         float                   ping_times[NUM_PING_TIMES];
100         int                             num_pings;                      // ping_times[num_pings%NUM_PING_TIMES]
101         float                   ping;                           // LordHavoc: can be used for prediction or whatever...
102         float                   latency;                        // LordHavoc: specifically used for prediction, accounts for sys_ticrate too
103
104 // spawn parms are carried from level to level
105         float                   spawn_parms[NUM_SPAWN_PARMS];
106
107 // client known data for deltas
108         int                             old_frags;
109         int                             pmodel;
110
111 #ifdef QUAKEENTITIES
112         // delta compression state
113         float                   nextfullupdate[MAX_EDICTS];
114 #endif
115         // visibility state
116         float                   visibletime[MAX_EDICTS];
117
118 #ifndef QUAKEENTITIES
119         entity_database_t entitydatabase;
120         int                             entityframenumber; // incremented each time an entity frame is sent
121 #endif
122 } client_t;
123
124
125 //=============================================================================
126
127 // edict->movetype values
128 #define MOVETYPE_NONE                   0               // never moves
129 #define MOVETYPE_ANGLENOCLIP    1
130 #define MOVETYPE_ANGLECLIP              2
131 #define MOVETYPE_WALK                   3               // gravity
132 #define MOVETYPE_STEP                   4               // gravity, special edge handling
133 #define MOVETYPE_FLY                    5
134 #define MOVETYPE_TOSS                   6               // gravity
135 #define MOVETYPE_PUSH                   7               // no clip to world, push and crush
136 #define MOVETYPE_NOCLIP                 8
137 #define MOVETYPE_FLYMISSILE             9               // extra size to monsters
138 #define MOVETYPE_BOUNCE                 10
139 #define MOVETYPE_BOUNCEMISSILE  11              // bounce w/o gravity
140 #define MOVETYPE_FOLLOW                 12              // track movement of aiment
141
142 // edict->solid values
143 #define SOLID_NOT                               0               // no interaction with other objects
144 #define SOLID_TRIGGER                   1               // touch on edge, but not blocking
145 #define SOLID_BBOX                              2               // touch on edge, block
146 #define SOLID_SLIDEBOX                  3               // touch on edge, but not an onground
147 #define SOLID_BSP                               4               // bsp clip, touch on edge, block
148 // LordHavoc: corpse code
149 #define SOLID_CORPSE                    5               // same as SOLID_BBOX, except it behaves as SOLID_NOT against SOLID_SLIDEBOX objects (players/monsters)
150
151 // edict->deadflag values
152 #define DEAD_NO                                 0
153 #define DEAD_DYING                              1
154 #define DEAD_DEAD                               2
155
156 #define DAMAGE_NO                               0
157 #define DAMAGE_YES                              1
158 #define DAMAGE_AIM                              2
159
160 // edict->flags
161 #define FL_FLY                                  1
162 #define FL_SWIM                                 2
163 //#define       FL_GLIMPSE                              4
164 #define FL_CONVEYOR                             4
165 #define FL_CLIENT                               8
166 #define FL_INWATER                              16
167 #define FL_MONSTER                              32
168 #define FL_GODMODE                              64
169 #define FL_NOTARGET                             128
170 #define FL_ITEM                                 256
171 #define FL_ONGROUND                             512
172 #define FL_PARTIALGROUND                1024    // not all corners are valid
173 #define FL_WATERJUMP                    2048    // player jumping out of water
174 #define FL_JUMPRELEASED                 4096    // for jump debouncing
175
176 // entity effects
177
178 #define EF_BRIGHTFIELD                  1
179 #define EF_MUZZLEFLASH                  2
180 #define EF_BRIGHTLIGHT                  4
181 #define EF_DIMLIGHT                     8
182 // added EF_ effects:
183 #define EF_NODRAW                               16
184 #define EF_ADDITIVE                             32  // LordHavoc: Additive Rendering
185 #define EF_BLUE                                 64
186 #define EF_RED                                  128
187
188 #define SPAWNFLAG_NOT_EASY                      256
189 #define SPAWNFLAG_NOT_MEDIUM            512
190 #define SPAWNFLAG_NOT_HARD                      1024
191 #define SPAWNFLAG_NOT_DEATHMATCH        2048
192
193 //============================================================================
194
195 extern cvar_t teamplay;
196 extern cvar_t skill;
197 extern cvar_t deathmatch;
198 extern cvar_t coop;
199 extern cvar_t fraglimit;
200 extern cvar_t timelimit;
201 extern cvar_t pausable;
202 extern cvar_t sv_deltacompress;
203 extern cvar_t sv_maxvelocity;
204 extern cvar_t sv_gravity;
205 extern cvar_t sv_nostep;
206 extern cvar_t sv_friction;
207 extern cvar_t sv_edgefriction;
208 extern cvar_t sv_stopspeed;
209 extern cvar_t sv_maxspeed;
210 extern cvar_t sv_accelerate;
211 extern cvar_t sv_idealpitchscale;
212 extern cvar_t sv_aim;
213 extern cvar_t sv_predict;
214
215 extern server_static_t svs;                             // persistant server info
216 extern server_t sv;                                     // local server
217
218 extern client_t *host_client;
219
220 extern jmp_buf host_abortserver;
221
222 extern edict_t *sv_player;
223
224 //===========================================================
225
226 void SV_Init (void);
227
228 void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count);
229 void SV_StartEffect (vec3_t org, int modelindex, int startframe, int framecount, int framerate);
230 void SV_StartSound (edict_t *entity, int channel, char *sample, int volume, float attenuation);
231
232 void SV_DropClient (qboolean crash);
233
234 void SV_SendClientMessages (void);
235 void SV_ClearDatagram (void);
236
237 int SV_ModelIndex (char *name);
238
239 void SV_SetIdealPitch (void);
240
241 void SV_AddUpdates (void);
242
243 void SV_ClientThink (void);
244 void SV_AddClientToServer (struct qsocket_s     *ret);
245
246 void SV_ClientPrintf (char *fmt, ...);
247 void SV_BroadcastPrintf (char *fmt, ...);
248
249 void SV_Physics (void);
250
251 qboolean SV_CheckBottom (edict_t *ent);
252 qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink);
253
254 void SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg);
255
256 void SV_MoveToGoal (void);
257
258 void SV_CheckForNewClients (void);
259 void SV_RunClients (void);
260 void SV_SaveSpawnparms (void);
261 void SV_SpawnServer (char *server);