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