]> icculus.org git repositories - divverent/darkplaces.git/blob - sv_main.c
added buildnumber.c to makefile
[divverent/darkplaces.git] / sv_main.c
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 // sv_main.c -- server main program
21
22 #include "quakedef.h"
23
24 server_t                sv;
25 server_static_t svs;
26
27 char    localmodels[MAX_MODELS][5];                     // inline model names for precache
28
29 //============================================================================
30
31 /*
32 ===============
33 SV_Init
34 ===============
35 */
36 void SV_Init (void)
37 {
38         int             i;
39         extern  cvar_t  sv_maxvelocity;
40         extern  cvar_t  sv_gravity;
41         extern  cvar_t  sv_nostep;
42         extern  cvar_t  sv_friction;
43         extern  cvar_t  sv_edgefriction;
44         extern  cvar_t  sv_stopspeed;
45         extern  cvar_t  sv_maxspeed;
46         extern  cvar_t  sv_accelerate;
47         extern  cvar_t  sv_idealpitchscale;
48         extern  cvar_t  sv_aim;
49
50         Cvar_RegisterVariable (&sv_maxvelocity);
51         Cvar_RegisterVariable (&sv_gravity);
52         Cvar_RegisterVariable (&sv_friction);
53         Cvar_RegisterVariable (&sv_edgefriction);
54         Cvar_RegisterVariable (&sv_stopspeed);
55         Cvar_RegisterVariable (&sv_maxspeed);
56         Cvar_RegisterVariable (&sv_accelerate);
57         Cvar_RegisterVariable (&sv_idealpitchscale);
58         Cvar_RegisterVariable (&sv_aim);
59         Cvar_RegisterVariable (&sv_nostep);
60
61         for (i=0 ; i<MAX_MODELS ; i++)
62                 sprintf (localmodels[i], "*%i", i);
63 }
64
65 /*
66 =============================================================================
67
68 EVENT MESSAGES
69
70 =============================================================================
71 */
72
73 /*  
74 ==================
75 SV_StartParticle
76
77 Make sure the event gets sent to all clients
78 ==================
79 */
80 void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count)
81 {
82         int             i, v;
83
84         if (sv.datagram.cursize > MAX_DATAGRAM-16)
85                 return; 
86         MSG_WriteByte (&sv.datagram, svc_particle);
87         MSG_WriteCoord (&sv.datagram, org[0]);
88         MSG_WriteCoord (&sv.datagram, org[1]);
89         MSG_WriteCoord (&sv.datagram, org[2]);
90         for (i=0 ; i<3 ; i++)
91         {
92                 v = dir[i]*16;
93                 if (v > 127)
94                         v = 127;
95                 else if (v < -128)
96                         v = -128;
97                 MSG_WriteChar (&sv.datagram, v);
98         }
99         MSG_WriteByte (&sv.datagram, count);
100         MSG_WriteByte (&sv.datagram, color);
101 }           
102
103 /*  
104 ==================
105 SV_StartSound
106
107 Each entity can have eight independant sound sources, like voice,
108 weapon, feet, etc.
109
110 Channel 0 is an auto-allocate channel, the others override anything
111 allready running on that entity/channel pair.
112
113 An attenuation of 0 will play full volume everywhere in the level.
114 Larger attenuations will drop off.  (max 4 attenuation)
115
116 ==================
117 */  
118 void SV_StartSound (edict_t *entity, int channel, char *sample, int volume,
119     float attenuation)
120 {       
121     int         sound_num;
122     int field_mask;
123     int                 i;
124         int                     ent;
125         
126         if (volume < 0 || volume > 255)
127                 Host_Error ("SV_StartSound: volume = %i", volume);
128
129         if (attenuation < 0 || attenuation > 4)
130                 Host_Error ("SV_StartSound: attenuation = %f", attenuation);
131
132         if (channel < 0 || channel > 7)
133                 Host_Error ("SV_StartSound: channel = %i", channel);
134
135         if (sv.datagram.cursize > MAX_DATAGRAM-16)
136                 return; 
137
138 // find precache number for sound
139     for (sound_num=1 ; sound_num<MAX_SOUNDS
140         && sv.sound_precache[sound_num] ; sound_num++)
141         if (!strcmp(sample, sv.sound_precache[sound_num]))
142             break;
143     
144     if ( sound_num == MAX_SOUNDS || !sv.sound_precache[sound_num] )
145     {
146         Con_Printf ("SV_StartSound: %s not precached\n", sample);
147         return;
148     }
149     
150         ent = NUM_FOR_EDICT(entity);
151
152         channel = (ent<<3) | channel;
153
154         field_mask = 0;
155         if (volume != DEFAULT_SOUND_PACKET_VOLUME)
156                 field_mask |= SND_VOLUME;
157         if (attenuation != DEFAULT_SOUND_PACKET_ATTENUATION)
158                 field_mask |= SND_ATTENUATION;
159
160 // directed messages go only to the entity the are targeted on
161         MSG_WriteByte (&sv.datagram, svc_sound);
162         MSG_WriteByte (&sv.datagram, field_mask);
163         if (field_mask & SND_VOLUME)
164                 MSG_WriteByte (&sv.datagram, volume);
165         if (field_mask & SND_ATTENUATION)
166                 MSG_WriteByte (&sv.datagram, attenuation*64);
167         MSG_WriteShort (&sv.datagram, channel);
168         MSG_WriteByte (&sv.datagram, sound_num);
169         for (i=0 ; i<3 ; i++)
170                 MSG_WriteCoord (&sv.datagram, entity->v.origin[i]+0.5*(entity->v.mins[i]+entity->v.maxs[i]));
171 }           
172
173 /*
174 ==============================================================================
175
176 CLIENT SPAWNING
177
178 ==============================================================================
179 */
180
181 /*
182 ================
183 SV_SendServerinfo
184
185 Sends the first message from the server to a connected client.
186 This will be sent on the initial connection and upon each server load.
187 ================
188 */
189 void SV_SendServerinfo (client_t *client)
190 {
191         char                    **s;
192         char                    message[2048];
193
194         MSG_WriteByte (&client->message, svc_print);
195 #ifdef NEHAHRA
196         sprintf (message, "%c\nDPNEHAHRA VERSION %4.2f SERVER (%i CRC)", 2, VERSION, pr_crc);
197 #else
198         sprintf (message, "%c\nDARKPLACES VERSION %4.2f SERVER (%i CRC)", 2, VERSION, pr_crc);
199 #endif
200         MSG_WriteString (&client->message,message);
201
202         MSG_WriteByte (&client->message, svc_serverinfo);
203         MSG_WriteLong (&client->message, PROTOCOL_VERSION);
204         MSG_WriteByte (&client->message, svs.maxclients);
205
206         if (!coop.value && deathmatch.value)
207                 MSG_WriteByte (&client->message, GAME_DEATHMATCH);
208         else
209                 MSG_WriteByte (&client->message, GAME_COOP);
210
211         sprintf (message, pr_strings+sv.edicts->v.message);
212
213         MSG_WriteString (&client->message,message);
214
215         for (s = sv.model_precache+1 ; *s ; s++)
216                 MSG_WriteString (&client->message, *s);
217         MSG_WriteByte (&client->message, 0);
218
219         for (s = sv.sound_precache+1 ; *s ; s++)
220                 MSG_WriteString (&client->message, *s);
221         MSG_WriteByte (&client->message, 0);
222
223 // send music
224         MSG_WriteByte (&client->message, svc_cdtrack);
225         MSG_WriteByte (&client->message, sv.edicts->v.sounds);
226         MSG_WriteByte (&client->message, sv.edicts->v.sounds);
227
228 // set view     
229         MSG_WriteByte (&client->message, svc_setview);
230         MSG_WriteShort (&client->message, NUM_FOR_EDICT(client->edict));
231
232         MSG_WriteByte (&client->message, svc_signonnum);
233         MSG_WriteByte (&client->message, 1);
234
235         client->sendsignon = true;
236         client->spawned = false;                // need prespawn, spawn, etc
237 }
238
239 /*
240 ================
241 SV_ConnectClient
242
243 Initializes a client_t for a new net connection.  This will only be called
244 once for a player each game, not once for each level change.
245 ================
246 */
247 void SV_ConnectClient (int clientnum)
248 {
249         edict_t                 *ent;
250         client_t                *client;
251         int                             edictnum;
252         struct qsocket_s *netconnection;
253         int                             i;
254         float                   spawn_parms[NUM_SPAWN_PARMS];
255
256         client = svs.clients + clientnum;
257
258         Con_DPrintf ("Client %s connected\n", client->netconnection->address);
259
260         edictnum = clientnum+1;
261
262         ent = EDICT_NUM(edictnum);
263         
264 // set up the client_t
265         netconnection = client->netconnection;
266         
267         if (sv.loadgame)
268                 memcpy (spawn_parms, client->spawn_parms, sizeof(spawn_parms));
269         memset (client, 0, sizeof(*client));
270         client->netconnection = netconnection;
271
272         strcpy (client->name, "unconnected");
273         client->active = true;
274         client->spawned = false;
275         client->edict = ent;
276         client->message.data = client->msgbuf;
277         client->message.maxsize = sizeof(client->msgbuf);
278         client->message.allowoverflow = true;           // we can catch it
279
280         if (sv.loadgame)
281                 memcpy (client->spawn_parms, spawn_parms, sizeof(spawn_parms));
282         else
283         {
284         // call the progs to get default spawn parms for the new client
285                 PR_ExecuteProgram (pr_global_struct->SetNewParms);
286                 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
287                         client->spawn_parms[i] = (&pr_global_struct->parm1)[i];
288         }
289
290         SV_SendServerinfo (client);
291 }
292
293
294 /*
295 ===================
296 SV_CheckForNewClients
297
298 ===================
299 */
300 void SV_CheckForNewClients (void)
301 {
302         struct qsocket_s        *ret;
303         int                             i;
304                 
305 //
306 // check for new connections
307 //
308         while (1)
309         {
310                 ret = NET_CheckNewConnections ();
311                 if (!ret)
312                         break;
313
314         // 
315         // init a new client structure
316         //      
317                 for (i=0 ; i<svs.maxclients ; i++)
318                         if (!svs.clients[i].active)
319                                 break;
320                 if (i == svs.maxclients)
321                         Sys_Error ("Host_CheckForNewClients: no free clients");
322                 
323                 svs.clients[i].netconnection = ret;
324                 SV_ConnectClient (i);   
325         
326                 net_activeconnections++;
327         }
328 }
329
330
331
332 /*
333 ===============================================================================
334
335 FRAME UPDATES
336
337 ===============================================================================
338 */
339
340 /*
341 ==================
342 SV_ClearDatagram
343
344 ==================
345 */
346 void SV_ClearDatagram (void)
347 {
348         SZ_Clear (&sv.datagram);
349 }
350
351 /*
352 =============================================================================
353
354 The PVS must include a small area around the client to allow head bobbing
355 or other small motion on the client side.  Otherwise, a bob might cause an
356 entity that should be visible to not show up, especially when the bob
357 crosses a waterline.
358
359 =============================================================================
360 */
361
362 int             fatbytes;
363 byte    fatpvs[MAX_MAP_LEAFS/8];
364
365 void SV_AddToFatPVS (vec3_t org, mnode_t *node)
366 {
367         int             i;
368         byte    *pvs;
369         mplane_t        *plane;
370         float   d;
371
372         while (1)
373         {
374         // if this is a leaf, accumulate the pvs bits
375                 if (node->contents < 0)
376                 {
377                         if (node->contents != CONTENTS_SOLID)
378                         {
379                                 pvs = Mod_LeafPVS ( (mleaf_t *)node, sv.worldmodel);
380                                 for (i=0 ; i<fatbytes ; i++)
381                                         fatpvs[i] |= pvs[i];
382                         }
383                         return;
384                 }
385         
386                 plane = node->plane;
387                 d = DotProduct (org, plane->normal) - plane->dist;
388                 if (d > 8)
389                         node = node->children[0];
390                 else if (d < -8)
391                         node = node->children[1];
392                 else
393                 {       // go down both
394                         SV_AddToFatPVS (org, node->children[0]);
395                         node = node->children[1];
396                 }
397         }
398 }
399
400 /*
401 =============
402 SV_FatPVS
403
404 Calculates a PVS that is the inclusive or of all leafs within 8 pixels of the
405 given point.
406 =============
407 */
408 byte *SV_FatPVS (vec3_t org)
409 {
410         fatbytes = (sv.worldmodel->numleafs+31)>>3;
411         memset (fatpvs, 0, fatbytes);
412         SV_AddToFatPVS (org, sv.worldmodel->nodes);
413         return fatpvs;
414 }
415
416 //=============================================================================
417
418
419 /*
420 =============
421 SV_WriteEntitiesToClient
422
423 =============
424 */
425 void SV_WriteEntitiesToClient (edict_t  *clent, sizebuf_t *msg)
426 {
427         int             e, i, clentnum, bits, alpha, glowcolor, glowsize, scale, colormod, modred, modgreen, modblue, dodelta, effects;
428         byte    *pvs;
429         vec3_t  org, origin, angles;
430         float   movelerp, moveilerp;
431         edict_t *ent;
432         eval_t  *val;
433         entity_state_t *baseline; // LordHavoc: delta or startup baseline
434
435 // find the client's PVS
436         VectorAdd (clent->v.origin, clent->v.view_ofs, org);
437         pvs = SV_FatPVS (org);
438         /*
439         if (dpprotocol)
440         {
441                 MSG_WriteByte(msg, svc_playerposition);
442                 MSG_WriteFloat(msg, org[0]);
443                 MSG_WriteFloat(msg, org[1]);
444                 MSG_WriteFloat(msg, org[2]);
445         }
446         */
447
448         clentnum = EDICT_TO_PROG(clent); // LordHavoc: for comparison purposes
449 // send over all entities (except the client) that touch the pvs
450         ent = NEXT_EDICT(sv.edicts);
451         for (e=1 ; e<sv.num_edicts ; e++, ent = NEXT_EDICT(ent))
452         {
453                 bits = 0;
454                 if (ent != clent) // LordHavoc: always send player
455                 {
456                         if ((val = GETEDICTFIELDVALUE(ent, eval_viewmodelforclient)) && val->edict)
457                         {
458                                 if (val->edict != clentnum)
459                                         continue; // don't show to anyone else
460                                 else
461                                         bits |= U_VIEWMODEL; // show relative to the view
462                         }
463                         else
464                         {
465                                 // LordHavoc: never draw something told not to display to this client
466                                 if ((val = GETEDICTFIELDVALUE(ent, eval_nodrawtoclient)) && val->edict == clentnum)
467                                         continue;
468                                 if ((val = GETEDICTFIELDVALUE(ent, eval_drawonlytoclient)) && val->edict && val->edict != clentnum)
469                                         continue;
470                                 // ignore if not touching a PV leaf
471                                 for (i=0 ; i < ent->num_leafs ; i++)
472                                         if (pvs[ent->leafnums[i] >> 3] & (1 << (ent->leafnums[i]&7) ))
473                                                 break;
474                                         
475                                 if (i == ent->num_leafs)
476                                         continue;               // not visible
477                         }
478                 }
479
480                 // don't send if flagged for NODRAW and there are no effects
481                 alpha = 255;
482                 scale = 16;
483                 glowsize = 0;
484                 glowcolor = 254;
485                 colormod = 255;
486                 effects = ent->v.effects;
487
488                 if ((val = GETEDICTFIELDVALUE(ent, eval_alpha)))
489                 if ((alpha = (int) (val->_float * 255.0)) == 0)
490                         alpha = 255;
491                 if ((val = GETEDICTFIELDVALUE(ent, eval_renderamt)) && val->_float != 0) // HalfLife support
492                         alpha = (int) val->_float;
493                 if (alpha < 0) alpha = 0;
494                 if (alpha > 255) alpha = 255;
495
496                 if ((val = GETEDICTFIELDVALUE(ent, eval_glow_size)))
497                         glowsize = (int) val->_float >> 2;
498                 if (glowsize > 255) glowsize = 255;
499                 if (glowsize < 0) glowsize = 0;
500
501                 if ((val = GETEDICTFIELDVALUE(ent, eval_scale)))
502                 if ((scale = (int) (val->_float * 16.0)) == 0) scale = 16;
503                 if (scale < 0) scale = 0;
504                 if (scale > 255) scale = 255;
505
506                 if ((val = GETEDICTFIELDVALUE(ent, eval_glow_trail)))
507                 if (val->_float != 0)
508                         bits |= U_GLOWTRAIL;
509
510                 if ((val = GETEDICTFIELDVALUE(ent, eval_glow_color)))
511                 if (val->_float != 0)
512                         glowcolor = (int) val->_float;
513
514                 if ((val = GETEDICTFIELDVALUE(ent, eval_fullbright)))
515                 if (val->_float != 0)
516                         effects |= EF_FULLBRIGHT;
517
518                 if ((val = GETEDICTFIELDVALUE(ent, eval_colormod)))
519                 if (val->vector[0] != 0 || val->vector[1] != 0 || val->vector[2] != 0)
520                 {
521                         modred = val->vector[0] * 8.0;if (modred < 0) modred = 0;if (modred > 7) modred = 7;
522                         modgreen = val->vector[1] * 8.0;if (modgreen < 0) modgreen = 0;if (modgreen > 7) modgreen = 7;
523                         modblue = val->vector[2] * 4.0;if (modblue < 0) modblue = 0;if (modblue > 3) modblue = 3;
524                         colormod = (modred << 5) | (modgreen << 2) | modblue;
525                 }
526
527                 if (ent != clent)
528                 {
529                         if (glowsize == 0 && bits == 0) // no effects
530                         {
531                                 if (ent->v.modelindex && pr_strings[ent->v.model]) // model
532                                 {
533                                         if (sv.models[ (int)ent->v.modelindex ]->flags == 0 && (ent->v.effects == EF_NODRAW || scale <= 0 || alpha <= 0))
534                                                 continue;
535                                 }
536                                 else // no model and no effects
537                                         continue;
538                         }
539                 }
540
541                 if (msg->maxsize - msg->cursize < 32) // LordHavoc: increased check from 16 to 32
542                 {
543                         Con_Printf ("packet overflow\n");
544                         return;
545                 }
546
547 // send an update
548                 bits = 0;
549
550                 dodelta = FALSE;
551                 if ((int)ent->v.effects & EF_DELTA)
552                         dodelta = cl.time < ent->nextfullupdate; // every half second a full update is forced
553
554                 if (dodelta)
555                 {
556                         bits |= U_DELTA;
557                         baseline = &ent->deltabaseline;
558                 }
559                 else
560                 {
561                         ent->nextfullupdate = cl.time + 0.5;
562                         baseline = &ent->baseline;
563                 }
564
565                 if (e >= 256)
566                         bits |= U_LONGENTITY;
567                 if (ent->v.movetype == MOVETYPE_STEP)
568                         bits |= U_STEP;
569                 
570                 if (ent->v.movetype == MOVETYPE_STEP && ((int) ent->v.flags & (FL_ONGROUND | FL_FLY | FL_SWIM))) // monsters have smoothed walking/flying/swimming movement
571                 {
572                         if (!ent->steplerptime || ent->steplerptime > sv.time) // when the level just started...
573                         {
574                                 ent->steplerptime = sv.time;
575                                 VectorCopy(ent->v.origin, ent->stepoldorigin);
576                                 VectorCopy(ent->v.angles, ent->stepoldangles);
577                                 VectorCopy(ent->v.origin, ent->steporigin);
578                                 VectorCopy(ent->v.angles, ent->stepangles);
579                         }
580                         VectorSubtract(ent->v.origin, ent->steporigin, origin);
581                         VectorSubtract(ent->v.angles, ent->stepangles, angles);
582                         if (DotProduct(origin, origin) >= 0.125 || DotProduct(angles, angles) >= 1.4)
583                         {
584                                 // update lerp positions
585                                 ent->steplerptime = sv.time;
586                                 VectorCopy(ent->steporigin, ent->stepoldorigin);
587                                 VectorCopy(ent->stepangles, ent->stepoldangles);
588                                 VectorCopy(ent->v.origin, ent->steporigin);
589                                 VectorCopy(ent->v.angles, ent->stepangles);
590                         }
591                         movelerp = (sv.time - ent->steplerptime) * 10.0;
592                         if (movelerp > 1) movelerp = 1;
593                         moveilerp = 1 - movelerp;
594                         origin[0] = ent->stepoldorigin[0] * moveilerp + ent->steporigin[0] * movelerp;
595                         origin[1] = ent->stepoldorigin[1] * moveilerp + ent->steporigin[1] * movelerp;
596                         origin[2] = ent->stepoldorigin[2] * moveilerp + ent->steporigin[2] * movelerp;
597                         // choose shortest rotate (to avoid 'spin around' situations)
598                         VectorSubtract(ent->stepangles, ent->stepoldangles, angles);
599                         if (angles[0] < -180) angles[0] += 360;if (angles[0] >= 180) angles[0] -= 360;
600                         if (angles[1] < -180) angles[1] += 360;if (angles[1] >= 180) angles[1] -= 360;
601                         if (angles[2] < -180) angles[2] += 360;if (angles[2] >= 180) angles[2] -= 360;
602                         angles[0] = angles[0] * movelerp + ent->stepoldangles[0];
603                         angles[1] = angles[1] * movelerp + ent->stepoldangles[1];
604                         angles[2] = angles[2] * movelerp + ent->stepoldangles[2];
605                         VectorMA(origin, host_client->ping, ent->v.velocity, origin);
606                 }
607                 else // copy as they are
608                 {
609 //                      VectorCopy(ent->v.origin, origin);
610                         VectorCopy(ent->v.angles, angles);
611                         VectorMA(ent->v.origin, host_client->latency, ent->v.velocity, origin);
612                         if (ent->v.movetype == MOVETYPE_STEP) // monster, but airborn, update lerp info
613                         {
614                                 // update lerp positions
615                                 ent->steplerptime = sv.time;
616                                 VectorCopy(ent->v.origin, ent->stepoldorigin);
617                                 VectorCopy(ent->v.angles, ent->stepoldangles);
618                                 VectorCopy(ent->v.origin, ent->steporigin);
619                                 VectorCopy(ent->v.angles, ent->stepangles);
620                         }
621                 }
622
623                 // LordHavoc: old stuff, but rewritten to have more exact tolerances
624                 if ((int)(origin[0]*8.0) != (int)(baseline->origin[0]*8.0))                                             bits |= U_ORIGIN1;
625                 if ((int)(origin[1]*8.0) != (int)(baseline->origin[1]*8.0))                                             bits |= U_ORIGIN2;
626                 if ((int)(origin[2]*8.0) != (int)(baseline->origin[2]*8.0))                                             bits |= U_ORIGIN3;
627                 if ((int)(angles[0]*(256.0/360.0)) != (int)(baseline->angles[0]*(256.0/360.0))) bits |= U_ANGLE1;
628                 if ((int)(angles[1]*(256.0/360.0)) != (int)(baseline->angles[1]*(256.0/360.0))) bits |= U_ANGLE2;
629                 if ((int)(angles[2]*(256.0/360.0)) != (int)(baseline->angles[2]*(256.0/360.0))) bits |= U_ANGLE3;
630                 if (baseline->colormap != (int) ent->v.colormap)                                                                bits |= U_COLORMAP;
631                 if (baseline->skin != (int) ent->v.skin)                                                                                bits |= U_SKIN;
632                 if ((baseline->frame & 0x00FF) != ((int) ent->v.frame & 0x00FF))                                bits |= U_FRAME;
633                 if ((baseline->effects & 0x00FF) != ((int) ent->v.effects & 0x00FF))                    bits |= U_EFFECTS;
634                 if (baseline->modelindex != (int) ent->v.modelindex)                                                    bits |= U_MODEL;
635
636                 // LordHavoc: new stuff
637                 if (baseline->alpha != alpha)                                                                                                   bits |= U_ALPHA;
638                 if (baseline->scale != scale)                                                                                                   bits |= U_SCALE;
639                 if (((int) baseline->effects & 0xFF00) != ((int) ent->v.effects & 0xFF00))              bits |= U_EFFECTS2;
640                 if (baseline->glowsize != glowsize)                                                                                             bits |= U_GLOWSIZE;
641                 if (baseline->glowcolor != glowcolor)                                                                                   bits |= U_GLOWCOLOR;
642                 if (baseline->colormod != colormod)                                                                                             bits |= U_COLORMOD;
643                 if (((int) baseline->frame & 0xFF00) != ((int) ent->v.frame & 0xFF00))                  bits |= U_FRAME2;
644
645                 // update delta baseline
646                 VectorCopy(ent->v.origin, ent->deltabaseline.origin);
647                 VectorCopy(ent->v.angles, ent->deltabaseline.angles);
648                 ent->deltabaseline.colormap = ent->v.colormap;
649                 ent->deltabaseline.skin = ent->v.skin;
650                 ent->deltabaseline.frame = ent->v.frame;
651                 ent->deltabaseline.effects = ent->v.effects;
652                 ent->deltabaseline.modelindex = ent->v.modelindex;
653                 ent->deltabaseline.alpha = alpha;
654                 ent->deltabaseline.scale = scale;
655                 ent->deltabaseline.glowsize = glowsize;
656                 ent->deltabaseline.glowcolor = glowcolor;
657                 ent->deltabaseline.colormod = colormod;
658
659                 // write the message
660                 if (bits >= 16777216)
661                         bits |= U_EXTEND2;
662                 if (bits >= 65536)
663                         bits |= U_EXTEND1;
664                 if (bits >= 256)
665                         bits |= U_MOREBITS;
666                 bits |= U_SIGNAL;
667
668                 MSG_WriteByte (msg, bits);
669                 if (bits & U_MOREBITS)
670                         MSG_WriteByte (msg, bits>>8);
671                 // LordHavoc: extend bytes have to be written here due to delta compression
672                 if (bits & U_EXTEND1)
673                         MSG_WriteByte (msg, bits>>16);
674                 if (bits & U_EXTEND2)
675                         MSG_WriteByte (msg, bits>>24);
676
677                 // LordHavoc: old stuff
678                 if (bits & U_LONGENTITY)
679                         MSG_WriteShort (msg,e);
680                 else
681                         MSG_WriteByte (msg,e);
682                 if (bits & U_MODEL)             MSG_WriteByte (msg,     ent->v.modelindex);
683                 if (bits & U_FRAME)             MSG_WriteByte (msg, ent->v.frame);
684                 if (bits & U_COLORMAP)  MSG_WriteByte (msg, ent->v.colormap);
685                 if (bits & U_SKIN)              MSG_WriteByte (msg, ent->v.skin);
686                 if (bits & U_EFFECTS)   MSG_WriteByte (msg, ent->v.effects);
687                 if (bits & U_ORIGIN1)   MSG_WriteCoord (msg, origin[0]);
688                 if (bits & U_ANGLE1)    MSG_WriteAngle(msg, angles[0]);
689                 if (bits & U_ORIGIN2)   MSG_WriteCoord (msg, origin[1]);
690                 if (bits & U_ANGLE2)    MSG_WriteAngle(msg, angles[1]);
691                 if (bits & U_ORIGIN3)   MSG_WriteCoord (msg, origin[2]);
692                 if (bits & U_ANGLE3)    MSG_WriteAngle(msg, angles[2]);
693
694                 // LordHavoc: new stuff
695                 if (bits & U_ALPHA)             MSG_WriteByte(msg, alpha);
696                 if (bits & U_SCALE)             MSG_WriteByte(msg, scale);
697                 if (bits & U_EFFECTS2)  MSG_WriteByte(msg, (int)ent->v.effects >> 8);
698                 if (bits & U_GLOWSIZE)  MSG_WriteByte(msg, glowsize);
699                 if (bits & U_GLOWCOLOR) MSG_WriteByte(msg, glowcolor);
700                 if (bits & U_COLORMOD)  MSG_WriteByte(msg, colormod);
701                 if (bits & U_FRAME2)    MSG_WriteByte(msg, (int)ent->v.frame >> 8);
702         }
703 }
704
705 /*
706 =============
707 SV_CleanupEnts
708
709 =============
710 */
711 void SV_CleanupEnts (void)
712 {
713         int             e;
714         edict_t *ent;
715         
716         ent = NEXT_EDICT(sv.edicts);
717         for (e=1 ; e<sv.num_edicts ; e++, ent = NEXT_EDICT(ent))
718         {
719                 ent->v.effects = (int)ent->v.effects & ~EF_MUZZLEFLASH;
720         }
721
722 }
723
724 /*
725 ==================
726 SV_WriteClientdataToMessage
727
728 ==================
729 */
730 void SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg)
731 {
732         int             bits;
733         int             i;
734         edict_t *other;
735         int             items;
736         eval_t  *val;
737
738 //
739 // send a damage message
740 //
741         if (ent->v.dmg_take || ent->v.dmg_save)
742         {
743                 other = PROG_TO_EDICT(ent->v.dmg_inflictor);
744                 MSG_WriteByte (msg, svc_damage);
745                 MSG_WriteByte (msg, ent->v.dmg_save);
746                 MSG_WriteByte (msg, ent->v.dmg_take);
747                 for (i=0 ; i<3 ; i++)
748                         MSG_WriteCoord (msg, other->v.origin[i] + 0.5*(other->v.mins[i] + other->v.maxs[i]));
749         
750                 ent->v.dmg_take = 0;
751                 ent->v.dmg_save = 0;
752         }
753
754 //
755 // send the current viewpos offset from the view entity
756 //
757         SV_SetIdealPitch ();            // how much to look up / down ideally
758
759 // a fixangle might get lost in a dropped packet.  Oh well.
760         if ( ent->v.fixangle )
761         {
762                 MSG_WriteByte (msg, svc_setangle);
763                 for (i=0 ; i < 3 ; i++)
764                         MSG_WriteAngle (msg, ent->v.angles[i] );
765                 ent->v.fixangle = 0;
766         }
767
768         bits = 0;
769         
770         if (ent->v.view_ofs[2] != DEFAULT_VIEWHEIGHT)
771                 bits |= SU_VIEWHEIGHT;
772                 
773         if (ent->v.idealpitch)
774                 bits |= SU_IDEALPITCH;
775
776 // stuff the sigil bits into the high bits of items for sbar, or else
777 // mix in items2
778         val = GETEDICTFIELDVALUE(ent, eval_items2);
779
780         if (val)
781                 items = (int)ent->v.items | ((int)val->_float << 23);
782         else
783                 items = (int)ent->v.items | ((int)pr_global_struct->serverflags << 28);
784
785         bits |= SU_ITEMS;
786         
787         if ( (int)ent->v.flags & FL_ONGROUND)
788                 bits |= SU_ONGROUND;
789         
790         if ( ent->v.waterlevel >= 2)
791                 bits |= SU_INWATER;
792         
793         for (i=0 ; i<3 ; i++)
794         {
795                 if (ent->v.punchangle[i])
796                         bits |= (SU_PUNCH1<<i);
797                 if (ent->v.velocity[i])
798                         bits |= (SU_VELOCITY1<<i);
799         }
800         
801         if (ent->v.weaponframe)
802                 bits |= SU_WEAPONFRAME;
803
804         if (ent->v.armorvalue)
805                 bits |= SU_ARMOR;
806
807 //      if (ent->v.weapon)
808                 bits |= SU_WEAPON;
809
810 // send the data
811
812         MSG_WriteByte (msg, svc_clientdata);
813         MSG_WriteShort (msg, bits);
814
815         if (bits & SU_VIEWHEIGHT)
816                 MSG_WriteChar (msg, ent->v.view_ofs[2]);
817
818         if (bits & SU_IDEALPITCH)
819                 MSG_WriteChar (msg, ent->v.idealpitch);
820
821         for (i=0 ; i<3 ; i++)
822         {
823                 if (bits & (SU_PUNCH1<<i))
824                         MSG_WriteChar (msg, ent->v.punchangle[i]);
825                 if (bits & (SU_VELOCITY1<<i))
826                         MSG_WriteChar (msg, ent->v.velocity[i]/16);
827         }
828
829 // [always sent]        if (bits & SU_ITEMS)
830         MSG_WriteLong (msg, items);
831
832         if (bits & SU_WEAPONFRAME)
833                 MSG_WriteByte (msg, ent->v.weaponframe);
834         if (bits & SU_ARMOR)
835                 MSG_WriteByte (msg, ent->v.armorvalue);
836         if (bits & SU_WEAPON)
837                 MSG_WriteByte (msg, SV_ModelIndex(pr_strings+ent->v.weaponmodel));
838         
839         MSG_WriteShort (msg, ent->v.health);
840         MSG_WriteByte (msg, ent->v.currentammo);
841         MSG_WriteByte (msg, ent->v.ammo_shells);
842         MSG_WriteByte (msg, ent->v.ammo_nails);
843         MSG_WriteByte (msg, ent->v.ammo_rockets);
844         MSG_WriteByte (msg, ent->v.ammo_cells);
845
846         if (standard_quake)
847         {
848                 MSG_WriteByte (msg, ent->v.weapon);
849         }
850         else
851         {
852                 for(i=0;i<32;i++)
853                 {
854                         if ( ((int)ent->v.weapon) & (1<<i) )
855                         {
856                                 MSG_WriteByte (msg, i);
857                                 break;
858                         }
859                 }
860         }
861 }
862
863 /*
864 =======================
865 SV_SendClientDatagram
866 =======================
867 */
868 qboolean SV_SendClientDatagram (client_t *client)
869 {
870         byte            buf[MAX_DATAGRAM];
871         sizebuf_t       msg;
872         
873         msg.data = buf;
874         msg.maxsize = sizeof(buf);
875         msg.cursize = 0;
876
877         MSG_WriteByte (&msg, svc_time);
878         MSG_WriteFloat (&msg, sv.time);
879
880 // add the client specific data to the datagram
881         SV_WriteClientdataToMessage (client->edict, &msg);
882
883         SV_WriteEntitiesToClient (client->edict, &msg);
884
885 // copy the server datagram if there is space
886         if (msg.cursize + sv.datagram.cursize < msg.maxsize)
887                 SZ_Write (&msg, sv.datagram.data, sv.datagram.cursize);
888
889 // send the datagram
890         if (NET_SendUnreliableMessage (client->netconnection, &msg) == -1)
891         {
892                 SV_DropClient (true);// if the message couldn't send, kick off
893                 return false;
894         }
895         
896         return true;
897 }
898
899 /*
900 =======================
901 SV_UpdateToReliableMessages
902 =======================
903 */
904 void SV_UpdateToReliableMessages (void)
905 {
906         int                     i, j;
907         client_t *client;
908
909 // check for changes to be sent over the reliable streams
910         for (i=0, host_client = svs.clients ; i<svs.maxclients ; i++, host_client++)
911         {
912                 if (host_client->old_frags != host_client->edict->v.frags)
913                 {
914                         for (j=0, client = svs.clients ; j<svs.maxclients ; j++, client++)
915                         {
916                                 if (!client->active)
917                                         continue;
918                                 MSG_WriteByte (&client->message, svc_updatefrags);
919                                 MSG_WriteByte (&client->message, i);
920                                 MSG_WriteShort (&client->message, host_client->edict->v.frags);
921                         }
922
923                         host_client->old_frags = host_client->edict->v.frags;
924                 }
925         }
926         
927         for (j=0, client = svs.clients ; j<svs.maxclients ; j++, client++)
928         {
929                 if (!client->active)
930                         continue;
931                 SZ_Write (&client->message, sv.reliable_datagram.data, sv.reliable_datagram.cursize);
932         }
933
934         SZ_Clear (&sv.reliable_datagram);
935 }
936
937
938 /*
939 =======================
940 SV_SendNop
941
942 Send a nop message without trashing or sending the accumulated client
943 message buffer
944 =======================
945 */
946 void SV_SendNop (client_t *client)
947 {
948         sizebuf_t       msg;
949         byte            buf[4];
950         
951         msg.data = buf;
952         msg.maxsize = sizeof(buf);
953         msg.cursize = 0;
954
955         MSG_WriteChar (&msg, svc_nop);
956
957         if (NET_SendUnreliableMessage (client->netconnection, &msg) == -1)
958                 SV_DropClient (true);   // if the message couldn't send, kick off
959         client->last_message = realtime;
960 }
961
962 /*
963 =======================
964 SV_SendClientMessages
965 =======================
966 */
967 void SV_SendClientMessages (void)
968 {
969         int                     i;
970         
971 // update frags, names, etc
972         SV_UpdateToReliableMessages ();
973
974 // build individual updates
975         for (i=0, host_client = svs.clients ; i<svs.maxclients ; i++, host_client++)
976         {
977                 if (!host_client->active)
978                         continue;
979
980                 if (host_client->spawned)
981                 {
982                         if (!SV_SendClientDatagram (host_client))
983                                 continue;
984                 }
985                 else
986                 {
987                 // the player isn't totally in the game yet
988                 // send small keepalive messages if too much time has passed
989                 // send a full message when the next signon stage has been requested
990                 // some other message data (name changes, etc) may accumulate 
991                 // between signon stages
992                         if (!host_client->sendsignon)
993                         {
994                                 if (realtime - host_client->last_message > 5)
995                                         SV_SendNop (host_client);
996                                 continue;       // don't send out non-signon messages
997                         }
998                 }
999
1000                 // check for an overflowed message.  Should only happen
1001                 // on a very fucked up connection that backs up a lot, then
1002                 // changes level
1003                 if (host_client->message.overflowed)
1004                 {
1005                         SV_DropClient (true);
1006                         host_client->message.overflowed = false;
1007                         continue;
1008                 }
1009                         
1010                 if (host_client->message.cursize || host_client->dropasap)
1011                 {
1012                         if (!NET_CanSendMessage (host_client->netconnection))
1013                         {
1014 //                              I_Printf ("can't write\n");
1015                                 continue;
1016                         }
1017
1018                         if (host_client->dropasap)
1019                                 SV_DropClient (false);  // went to another level
1020                         else
1021                         {
1022                                 if (NET_SendMessage (host_client->netconnection
1023                                 , &host_client->message) == -1)
1024                                         SV_DropClient (true);   // if the message couldn't send, kick off
1025                                 SZ_Clear (&host_client->message);
1026                                 host_client->last_message = realtime;
1027                                 host_client->sendsignon = false;
1028                         }
1029                 }
1030         }
1031         
1032         
1033 // clear muzzle flashes
1034         SV_CleanupEnts ();
1035 }
1036
1037
1038 /*
1039 ==============================================================================
1040
1041 SERVER SPAWNING
1042
1043 ==============================================================================
1044 */
1045
1046 /*
1047 ================
1048 SV_ModelIndex
1049
1050 ================
1051 */
1052 int SV_ModelIndex (char *name)
1053 {
1054         int             i;
1055         
1056         if (!name || !name[0])
1057                 return 0;
1058
1059         for (i=0 ; i<MAX_MODELS && sv.model_precache[i] ; i++)
1060                 if (!strcmp(sv.model_precache[i], name))
1061                         return i;
1062         if (i==MAX_MODELS || !sv.model_precache[i])
1063                 Host_Error ("SV_ModelIndex: model %s not precached", name);
1064         return i;
1065 }
1066
1067 /*
1068 ================
1069 SV_CreateBaseline
1070
1071 ================
1072 */
1073 void SV_CreateBaseline (void)
1074 {
1075         int                     i;
1076         edict_t                 *svent;
1077         int                             entnum; 
1078                 
1079         for (entnum = 0; entnum < sv.num_edicts ; entnum++)
1080         {
1081         // get the current server version
1082                 svent = EDICT_NUM(entnum);
1083                 if (svent->free)
1084                         continue;
1085                 if (entnum > svs.maxclients && !svent->v.modelindex)
1086                         continue;
1087
1088         //
1089         // create entity baseline
1090         //
1091                 VectorCopy (svent->v.origin, svent->baseline.origin);
1092                 VectorCopy (svent->v.angles, svent->baseline.angles);
1093                 svent->baseline.frame = svent->v.frame;
1094                 svent->baseline.skin = svent->v.skin;
1095                 if (entnum > 0 && entnum <= svs.maxclients)
1096                 {
1097                         svent->baseline.colormap = entnum;
1098                         svent->baseline.modelindex = SV_ModelIndex("progs/player.mdl");
1099                 }
1100                 else
1101                 {
1102                         svent->baseline.colormap = 0;
1103                         svent->baseline.modelindex =
1104                                 SV_ModelIndex(pr_strings + svent->v.model);
1105                 }
1106                 svent->baseline.alpha = 255;
1107                 svent->baseline.scale = 16;
1108                 svent->baseline.glowsize = 0;
1109                 svent->baseline.glowcolor = 254;
1110                 svent->baseline.colormod = 255;
1111                 
1112         //
1113         // add to the message
1114         //
1115                 MSG_WriteByte (&sv.signon,svc_spawnbaseline);           
1116                 MSG_WriteShort (&sv.signon,entnum);
1117
1118                 MSG_WriteByte (&sv.signon, svent->baseline.modelindex);
1119                 MSG_WriteByte (&sv.signon, svent->baseline.frame);
1120                 MSG_WriteByte (&sv.signon, svent->baseline.colormap);
1121                 MSG_WriteByte (&sv.signon, svent->baseline.skin);
1122                 for (i=0 ; i<3 ; i++)
1123                 {
1124                         MSG_WriteCoord(&sv.signon, svent->baseline.origin[i]);
1125                         MSG_WriteAngle(&sv.signon, svent->baseline.angles[i]);
1126                 }
1127         }
1128 }
1129
1130
1131 /*
1132 ================
1133 SV_SendReconnect
1134
1135 Tell all the clients that the server is changing levels
1136 ================
1137 */
1138 void SV_SendReconnect (void)
1139 {
1140         char    data[128];
1141         sizebuf_t       msg;
1142
1143         msg.data = data;
1144         msg.cursize = 0;
1145         msg.maxsize = sizeof(data);
1146
1147         MSG_WriteChar (&msg, svc_stufftext);
1148         MSG_WriteString (&msg, "reconnect\n");
1149         NET_SendToAll (&msg, 5);
1150         
1151         if (cls.state != ca_dedicated)
1152                 Cmd_ExecuteString ("reconnect\n", src_command);
1153 }
1154
1155
1156 /*
1157 ================
1158 SV_SaveSpawnparms
1159
1160 Grabs the current state of each client for saving across the
1161 transition to another level
1162 ================
1163 */
1164 void SV_SaveSpawnparms (void)
1165 {
1166         int             i, j;
1167
1168         svs.serverflags = pr_global_struct->serverflags;
1169
1170         for (i=0, host_client = svs.clients ; i<svs.maxclients ; i++, host_client++)
1171         {
1172                 if (!host_client->active)
1173                         continue;
1174
1175         // call the progs to get default spawn parms for the new client
1176                 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1177                 PR_ExecuteProgram (pr_global_struct->SetChangeParms);
1178                 for (j=0 ; j<NUM_SPAWN_PARMS ; j++)
1179                         host_client->spawn_parms[j] = (&pr_global_struct->parm1)[j];
1180         }
1181 }
1182
1183 qboolean isworldmodel;
1184
1185 /*
1186 ================
1187 SV_SpawnServer
1188
1189 This is called at the start of each level
1190 ================
1191 */
1192 extern float            scr_centertime_off;
1193
1194 void SV_SpawnServer (char *server)
1195 {
1196         edict_t         *ent;
1197         int                     i;
1198
1199         // let's not have any servers with no name
1200         if (hostname.string[0] == 0)
1201                 Cvar_Set ("hostname", "UNNAMED");
1202         scr_centertime_off = 0;
1203
1204         Con_DPrintf ("SpawnServer: %s\n",server);
1205         svs.changelevel_issued = false;         // now safe to issue another
1206
1207 //
1208 // tell all connected clients that we are going to a new level
1209 //
1210         if (sv.active)
1211         {
1212                 SV_SendReconnect ();
1213         }
1214
1215 //
1216 // make cvars consistant
1217 //
1218         if (coop.value)
1219                 Cvar_SetValue ("deathmatch", 0);
1220         current_skill = (int)(skill.value + 0.5);
1221         if (current_skill < 0)
1222                 current_skill = 0;
1223         if (current_skill > 3)
1224                 current_skill = 3;
1225
1226         Cvar_SetValue ("skill", (float)current_skill);
1227         
1228 //
1229 // set up the new server
1230 //
1231         Host_ClearMemory ();
1232
1233         memset (&sv, 0, sizeof(sv));
1234
1235         strcpy (sv.name, server);
1236
1237 // load progs to get entity field count
1238         PR_LoadProgs ();
1239
1240 // allocate server memory
1241         sv.max_edicts = MAX_EDICTS;
1242         
1243         sv.edicts = Hunk_AllocName (sv.max_edicts*pr_edict_size, "edicts");
1244
1245         sv.datagram.maxsize = sizeof(sv.datagram_buf);
1246         sv.datagram.cursize = 0;
1247         sv.datagram.data = sv.datagram_buf;
1248         
1249         sv.reliable_datagram.maxsize = sizeof(sv.reliable_datagram_buf);
1250         sv.reliable_datagram.cursize = 0;
1251         sv.reliable_datagram.data = sv.reliable_datagram_buf;
1252         
1253         sv.signon.maxsize = sizeof(sv.signon_buf);
1254         sv.signon.cursize = 0;
1255         sv.signon.data = sv.signon_buf;
1256         
1257 // leave slots at start for clients only
1258         sv.num_edicts = svs.maxclients+1;
1259         for (i=0 ; i<svs.maxclients ; i++)
1260         {
1261                 ent = EDICT_NUM(i+1);
1262                 svs.clients[i].edict = ent;
1263         }
1264         
1265         sv.state = ss_loading;
1266         sv.paused = false;
1267
1268         sv.time = 1.0;
1269         
1270         strcpy (sv.name, server);
1271         sprintf (sv.modelname,"maps/%s.bsp", server);
1272         isworldmodel = true; // LordHavoc: only load submodels on the world model
1273         sv.worldmodel = Mod_ForName (sv.modelname, false);
1274         isworldmodel = false;
1275         if (!sv.worldmodel)
1276         {
1277                 Con_Printf ("Couldn't spawn server %s\n", sv.modelname);
1278                 sv.active = false;
1279                 return;
1280         }
1281         sv.models[1] = sv.worldmodel;
1282         
1283 //
1284 // clear world interaction links
1285 //
1286         SV_ClearWorld ();
1287         
1288         sv.sound_precache[0] = pr_strings;
1289
1290         sv.model_precache[0] = pr_strings;
1291         sv.model_precache[1] = sv.modelname;
1292         for (i=1 ; i<sv.worldmodel->numsubmodels ; i++)
1293         {
1294                 sv.model_precache[1+i] = localmodels[i];
1295                 sv.models[i+1] = Mod_ForName (localmodels[i], false);
1296         }
1297
1298 //
1299 // load the rest of the entities
1300 //      
1301         ent = EDICT_NUM(0);
1302         memset (&ent->v, 0, progs->entityfields * 4);
1303         ent->free = false;
1304         ent->v.model = sv.worldmodel->name - pr_strings;
1305         ent->v.modelindex = 1;          // world model
1306         ent->v.solid = SOLID_BSP;
1307         ent->v.movetype = MOVETYPE_PUSH;
1308         ent->v.angles[0] = ent->v.angles[1] = ent->v.angles[2] = 0;
1309
1310         if (coop.value)
1311                 pr_global_struct->coop = coop.value;
1312         else
1313                 pr_global_struct->deathmatch = deathmatch.value;
1314
1315         pr_global_struct->mapname = sv.name - pr_strings;
1316
1317 // serverflags are for cross level information (sigils)
1318         pr_global_struct->serverflags = svs.serverflags;
1319         
1320         ED_LoadFromFile (sv.worldmodel->entities);
1321         // LordHavoc: clear world angles (to fix e3m3.bsp)
1322         sv.edicts->v.angles[0] = sv.edicts->v.angles[1] = sv.edicts->v.angles[2] = 0;
1323
1324         sv.active = true;
1325
1326 // all setup is completed, any further precache statements are errors
1327         sv.state = ss_active;
1328         
1329 // run two frames to allow everything to settle
1330         host_frametime = 0.1;
1331         SV_Physics ();
1332         SV_Physics ();
1333
1334 // create a baseline for more efficient communications
1335         SV_CreateBaseline ();
1336
1337 // send serverinfo to all connected clients
1338         for (i=0,host_client = svs.clients ; i<svs.maxclients ; i++, host_client++)
1339                 if (host_client->active)
1340                         SV_SendServerinfo (host_client);
1341         
1342         Con_DPrintf ("Server spawned.\n");
1343 }
1344
1345 // LordHavoc: added light checking to the server
1346 int RecursiveLightPoint (vec3_t color, mnode_t *node, vec3_t start, vec3_t end);
1347 void SV_LightPoint (vec3_t color, vec3_t p)
1348 {
1349         vec3_t          end;
1350         
1351         if (!sv.worldmodel->lightdata)
1352         {
1353                 color[0] = color[1] = color[2] = 255;
1354                 return;
1355         }
1356         
1357         end[0] = p[0];
1358         end[1] = p[1];
1359         end[2] = p[2] - 2048;
1360
1361         color[0] = color[1] = color[2] = 0;
1362         RecursiveLightPoint (color, sv.worldmodel->nodes, p, end);
1363 }