]> icculus.org git repositories - divverent/darkplaces.git/blob - cl_main.c
e0db84a6e38ab4866776ef8590bfd34f5775dd29
[divverent/darkplaces.git] / cl_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 // cl_main.c  -- client main loop
21
22 #include "quakedef.h"
23
24 // we need to declare some mouse variables here, because the menu system
25 // references them even when on a unix system.
26
27 // these two are not intended to be set directly
28 cvar_t  cl_name = {"_cl_name", "player", true};
29 cvar_t  cl_color = {"_cl_color", "0", true};
30 cvar_t  cl_pmodel = {"_cl_pmodel", "0", true};
31
32 cvar_t  cl_shownet = {"cl_shownet","0"};        // can be 0, 1, or 2
33 cvar_t  cl_nolerp = {"cl_nolerp","0"};
34
35 cvar_t  lookspring = {"lookspring","0", true};
36 cvar_t  lookstrafe = {"lookstrafe","0", true};
37 cvar_t  sensitivity = {"sensitivity","3", true};
38
39 cvar_t  m_pitch = {"m_pitch","0.022", true};
40 cvar_t  m_yaw = {"m_yaw","0.022", true};
41 cvar_t  m_forward = {"m_forward","1", true};
42 cvar_t  m_side = {"m_side","0.8", true};
43
44
45 client_static_t cls;
46 client_state_t  cl;
47 // FIXME: put these on hunk?
48 efrag_t                 cl_efrags[MAX_EFRAGS];
49 entity_t                cl_entities[MAX_EDICTS];
50 entity_t                cl_static_entities[MAX_STATIC_ENTITIES];
51 lightstyle_t    cl_lightstyle[MAX_LIGHTSTYLES];
52 dlight_t                cl_dlights[MAX_DLIGHTS];
53
54 int                             cl_numvisedicts;
55 entity_t                *cl_visedicts[MAX_VISEDICTS];
56
57 /*
58 =====================
59 CL_ClearState
60
61 =====================
62 */
63 void CL_ClearState (void)
64 {
65         int                     i;
66
67         if (!sv.active)
68                 Host_ClearMemory ();
69
70 // wipe the entire cl structure
71         memset (&cl, 0, sizeof(cl));
72
73         SZ_Clear (&cls.message);
74
75 // clear other arrays   
76         memset (cl_efrags, 0, sizeof(cl_efrags));
77         memset (cl_entities, 0, sizeof(cl_entities));
78         memset (cl_dlights, 0, sizeof(cl_dlights));
79         memset (cl_lightstyle, 0, sizeof(cl_lightstyle));
80         memset (cl_temp_entities, 0, sizeof(cl_temp_entities));
81         memset (cl_beams, 0, sizeof(cl_beams));
82         // LordHavoc: have to set up the baseline info for alpha and other stuff
83         for (i = 0;i < MAX_EDICTS;i++)
84         {
85                 cl_entities[i].state_baseline.alpha = 255;
86                 cl_entities[i].state_baseline.scale = 16;
87                 cl_entities[i].state_baseline.glowsize = 0;
88                 cl_entities[i].state_baseline.glowcolor = 254;
89                 cl_entities[i].state_baseline.colormod = 255;
90         }
91
92 //
93 // allocate the efrags and chain together into a free list
94 //
95         cl.free_efrags = cl_efrags;
96         for (i=0 ; i<MAX_EFRAGS-1 ; i++)
97                 cl.free_efrags[i].entnext = &cl.free_efrags[i+1];
98         cl.free_efrags[i].entnext = NULL;
99 }
100
101 /*
102 =====================
103 CL_Disconnect
104
105 Sends a disconnect message to the server
106 This is also called on Host_Error, so it shouldn't cause any errors
107 =====================
108 */
109 void CL_Disconnect (void)
110 {
111 // stop sounds (especially looping!)
112         S_StopAllSounds (true);
113         
114 // bring the console down and fade the colors back to normal
115 //      SCR_BringDownConsole ();
116
117 // if running a local server, shut it down
118         if (cls.demoplayback)
119                 CL_StopPlayback ();
120         else if (cls.state == ca_connected)
121         {
122                 if (cls.demorecording)
123                         CL_Stop_f ();
124
125                 Con_DPrintf ("Sending clc_disconnect\n");
126                 SZ_Clear (&cls.message);
127                 MSG_WriteByte (&cls.message, clc_disconnect);
128                 NET_SendUnreliableMessage (cls.netcon, &cls.message);
129                 SZ_Clear (&cls.message);
130                 NET_Close (cls.netcon);
131
132                 cls.state = ca_disconnected;
133                 if (sv.active)
134                         Host_ShutdownServer(false);
135         }
136
137         cls.demoplayback = cls.timedemo = false;
138         cls.signon = 0;
139 }
140
141 void CL_Disconnect_f (void)
142 {
143         CL_Disconnect ();
144         if (sv.active)
145                 Host_ShutdownServer (false);
146 }
147
148
149
150
151 /*
152 =====================
153 CL_EstablishConnection
154
155 Host should be either "local" or a net address to be passed on
156 =====================
157 */
158 void CL_EstablishConnection (char *host)
159 {
160         if (cls.state == ca_dedicated)
161                 return;
162
163         if (cls.demoplayback)
164                 return;
165
166         CL_Disconnect ();
167
168         cls.netcon = NET_Connect (host);
169         if (!cls.netcon)
170                 Host_Error ("CL_Connect: connect failed\n");
171         Con_DPrintf ("CL_EstablishConnection: connected to %s\n", host);
172         
173         cls.demonum = -1;                       // not in the demo loop now
174         cls.state = ca_connected;
175         cls.signon = 0;                         // need all the signon messages before playing
176 }
177
178 /*
179 =====================
180 CL_SignonReply
181
182 An svc_signonnum has been received, perform a client side setup
183 =====================
184 */
185 void CL_SignonReply (void)
186 {
187         char    str[8192];
188
189 Con_DPrintf ("CL_SignonReply: %i\n", cls.signon);
190
191         switch (cls.signon)
192         {
193         case 1:
194                 MSG_WriteByte (&cls.message, clc_stringcmd);
195                 MSG_WriteString (&cls.message, "prespawn");
196                 break;
197                 
198         case 2:
199                 MSG_WriteByte (&cls.message, clc_stringcmd);
200                 MSG_WriteString (&cls.message, va("name \"%s\"\n", cl_name.string));
201
202                 MSG_WriteByte (&cls.message, clc_stringcmd);
203                 MSG_WriteString (&cls.message, va("color %i %i\n", ((int)cl_color.value)>>4, ((int)cl_color.value)&15));
204         
205                 if (cl_pmodel.value)
206                 {
207                         MSG_WriteByte (&cls.message, clc_stringcmd);
208                         MSG_WriteString (&cls.message, va("pmodel %f\n", cl_pmodel.value));
209                 }
210
211                 MSG_WriteByte (&cls.message, clc_stringcmd);
212                 sprintf (str, "spawn %s", cls.spawnparms);
213                 MSG_WriteString (&cls.message, str);
214                 break;
215                 
216         case 3: 
217                 MSG_WriteByte (&cls.message, clc_stringcmd);
218                 MSG_WriteString (&cls.message, "begin");
219                 Cache_Report ();                // print remaining memory
220                 break;
221                 
222         case 4:
223                 SCR_EndLoadingPlaque ();                // allow normal screen updates
224                 break;
225         }
226 }
227
228 /*
229 =====================
230 CL_NextDemo
231
232 Called to play the next demo in the demo loop
233 =====================
234 */
235 void CL_NextDemo (void)
236 {
237         char    str[1024];
238
239         if (cls.demonum == -1)
240                 return;         // don't play demos
241
242         SCR_BeginLoadingPlaque ();
243
244         if (!cls.demos[cls.demonum][0] || cls.demonum == MAX_DEMOS)
245         {
246                 cls.demonum = 0;
247                 if (!cls.demos[cls.demonum][0])
248                 {
249                         Con_Printf ("No demos listed with startdemos\n");
250                         cls.demonum = -1;
251                         return;
252                 }
253         }
254
255         sprintf (str,"playdemo %s\n", cls.demos[cls.demonum]);
256         Cbuf_InsertText (str);
257         cls.demonum++;
258 }
259
260 /*
261 ==============
262 CL_PrintEntities_f
263 ==============
264 */
265 void CL_PrintEntities_f (void)
266 {
267         entity_t        *ent;
268         int                     i;
269         
270         for (i = 0, ent = cl_entities;i < MAX_EDICTS /*cl.num_entities*/;i++, ent++)
271         {
272                 Con_Printf ("%3i:", i);
273                 if (!ent->render.model)
274                 {
275                         Con_Printf ("EMPTY\n");
276                         continue;
277                 }
278                 Con_Printf ("%s:%2i  (%5.1f,%5.1f,%5.1f) [%5.1f %5.1f %5.1f]\n", ent->render.model->name, ent->render.frame, ent->render.origin[0], ent->render.origin[1], ent->render.origin[2], ent->render.angles[0], ent->render.angles[1], ent->render.angles[2]);
279         }
280 }
281
282
283 /*
284 ===============
285 CL_AllocDlight
286
287 ===============
288 */
289 void CL_AllocDlight (entity_t *ent, vec3_t org, float radius, float red, float green, float blue, float decay, float lifetime)
290 {
291         int             i;
292         dlight_t        *dl;
293
294 // first look for an exact key match
295         if (ent)
296         {
297                 dl = cl_dlights;
298                 for (i = 0;i < MAX_DLIGHTS;i++, dl++)
299                         if (dl->ent == ent)
300                                 goto dlightsetup;
301         }
302
303 // then look for anything else
304         dl = cl_dlights;
305         for (i = 0;i < MAX_DLIGHTS;i++, dl++)
306                 if (!dl->radius)
307                         goto dlightsetup;
308
309         // unable to find one
310         return;
311
312 dlightsetup:
313         memset (dl, 0, sizeof(*dl));
314         dl->ent = ent;
315         VectorCopy(org, dl->origin);
316         dl->radius = radius;
317         dl->color[0] = red;
318         dl->color[1] = green;
319         dl->color[2] = blue;
320         dl->decay = decay;
321         dl->die = cl.time + lifetime;
322 }
323
324
325 /*
326 ===============
327 CL_DecayLights
328
329 ===============
330 */
331 void CL_DecayLights (void)
332 {
333         int                     i;
334         dlight_t        *dl;
335         float           time;
336         
337         time = cl.time - cl.oldtime;
338
339         c_dlights = 0;
340         dl = cl_dlights;
341         for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
342         {
343                 if (!dl->radius)
344                         continue;
345                 if (dl->die < cl.time)
346                 {
347                         dl->radius = 0;
348                         continue;
349                 }
350
351                 c_dlights++; // count every dlight in use
352
353                 dl->radius -= time*dl->decay;
354                 if (dl->radius < 0)
355                         dl->radius = 0;
356         }
357 }
358
359
360 /*
361 ===============
362 CL_LerpPoint
363
364 Determines the fraction between the last two messages that the objects
365 should be put at.
366 ===============
367 */
368 float   CL_LerpPoint (void)
369 {
370         float   f, frac;
371
372         f = cl.mtime[0] - cl.mtime[1];
373
374         // LordHavoc: lerp in listen games as the server is being capped below the client (usually)
375         if (!f || cl_nolerp.value || cls.timedemo || (sv.active && svs.maxclients == 1))
376         {
377                 cl.time = cl.mtime[0];
378                 return 1;
379         }
380                 
381         if (f > 0.1)
382         {       // dropped packet, or start of demo
383                 cl.mtime[1] = cl.mtime[0] - 0.1;
384                 f = 0.1;
385         }
386         frac = (cl.time - cl.mtime[1]) / f;
387 //Con_Printf ("frac: %f\n",frac);
388         if (frac < 0)
389         {
390                 if (frac < -0.01)
391                 {
392                         cl.time = cl.mtime[1];
393 //                              Con_Printf ("low frac\n");
394                 }
395                 frac = 0;
396         }
397         else if (frac > 1)
398         {
399                 if (frac > 1.01)
400                 {
401                         cl.time = cl.mtime[0];
402 //                              Con_Printf ("high frac\n");
403                 }
404                 frac = 1;
405         }
406                 
407         return frac;
408 }
409
410 float CL_EntityLerpPoint (entity_t *ent)
411 {
412         float   f;
413
414         if (cl_nolerp.value || cls.timedemo || (sv.active && svs.maxclients == 1))
415                 return 1;
416
417         f = ent->state_current.time - ent->state_previous.time;
418 //      Con_Printf(" %g-%g=%g", ent->state_current.time, ent->state_previous.time, f);
419
420         if (f <= 0)
421                 return 1;
422         if (f >= 0.1)
423                 f = 0.1;
424
425 //      Con_Printf(" %g-%g/%g=%f", cl.time, ent->state_previous.time, f, (cl.time - ent->state_previous.time) / f);
426         f = (cl.time - ent->state_previous.time) / f;
427         return bound(0, f, 1);
428 }
429
430
431 /*
432 ===============
433 CL_RelinkEntities
434 ===============
435 */
436 void R_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent);
437 void CL_RelinkEntities (void)
438 {
439         entity_t        *ent;
440         int                     i, j;
441         float           frac, f, d;
442         vec3_t          delta;
443         float           bobjrotate;
444 //      float           bobjoffset;
445         vec3_t          oldorg;
446
447 // determine partial update time        
448         frac = CL_LerpPoint ();
449
450         cl_numvisedicts = 0;
451
452 //
453 // interpolate player info
454 //
455         for (i = 0;i < 3;i++)
456                 cl.velocity[i] = cl.mvelocity[1][i] + frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]);
457
458         if (cls.demoplayback)
459         {
460         // interpolate the angles       
461                 for (j = 0;j < 3;j++)
462                 {
463                         d = cl.mviewangles[0][j] - cl.mviewangles[1][j];
464                         if (d > 180)
465                                 d -= 360;
466                         else if (d < -180)
467                                 d += 360;
468                         cl.viewangles[j] = cl.mviewangles[1][j] + frac*d;
469                 }
470         }
471         
472         bobjrotate = ANGLEMOD(100*cl.time);
473 //      bobjoffset = cos(180 * cl.time * M_PI / 180) * 4.0f + 4.0f;
474         
475 // start on the entity after the world
476         for (i = 1, ent = cl_entities + 1;i < MAX_EDICTS /*cl.num_entities*/;i++, ent++)
477         {
478                 // if the object wasn't included in the latest packet, remove it
479                 if (!ent->state_current.modelindex)
480                         continue;
481
482                 VectorCopy (ent->render.origin, oldorg);
483
484                 if (!ent->state_previous.modelindex)
485                 {
486                         // only one state available
487                         VectorCopy (ent->state_current.origin, ent->render.origin);
488                         VectorCopy (ent->state_current.angles, ent->render.angles);
489 //                      Con_Printf(" %i", i);
490                 }
491                 else
492                 {
493                         // if the delta is large, assume a teleport and don't lerp
494                         f = CL_EntityLerpPoint(ent);
495                         if (f < 1)
496                         {
497                                 for (j = 0;j < 3;j++)
498                                 {
499                                         delta[j] = ent->state_current.origin[j] - ent->state_previous.origin[j];
500                                         // LordHavoc: increased lerp tolerance from 100 to 200
501                                         if (delta[j] > 200 || delta[j] < -200)
502                                                 f = 1;
503                                 }
504                         }
505                         if (f >= 1)
506                         {
507                                 // no interpolation
508                                 VectorCopy (ent->state_current.origin, ent->render.origin);
509                                 VectorCopy (ent->state_current.angles, ent->render.angles);
510                         }
511                         else
512                         {
513                                 // interpolate the origin and angles
514                                 for (j = 0;j < 3;j++)
515                                 {
516                                         ent->render.origin[j] = ent->state_previous.origin[j] + f*delta[j];
517
518                                         d = ent->state_current.angles[j] - ent->state_previous.angles[j];
519                                         if (d > 180)
520                                                 d -= 360;
521                                         else if (d < -180)
522                                                 d += 360;
523                                         ent->render.angles[j] = ent->state_previous.angles[j] + f*d;
524                                 }
525                         }
526                 }
527
528                 ent->render.flags = ent->state_current.flags;
529                 ent->render.effects = ent->state_current.effects;
530                 ent->render.model = cl.model_precache[ent->state_current.modelindex];
531                 ent->render.frame = ent->state_current.frame;
532                 if (cl.scores == NULL || !ent->state_current.colormap)
533                         ent->render.colormap = -1; // no special coloring
534                 else
535                         ent->render.colormap = cl.scores[ent->state_current.colormap - 1].colors; // color it
536                 ent->render.skinnum = ent->state_current.skin;
537                 ent->render.alpha = ent->state_current.alpha * (1.0f / 255.0f); // FIXME: interpolate?
538                 ent->render.scale = ent->state_current.scale * (1.0f / 16.0f); // FIXME: interpolate?
539                 ent->render.glowsize = ent->state_current.glowsize * 4.0f; // FIXME: interpolate?
540                 ent->render.glowcolor = ent->state_current.glowcolor;
541                 ent->render.colormod[0] = (float) ((ent->state_current.colormod >> 5) & 7) * (1.0f / 7.0f);
542                 ent->render.colormod[1] = (float) ((ent->state_current.colormod >> 2) & 7) * (1.0f / 7.0f);
543                 ent->render.colormod[2] = (float) (ent->state_current.colormod & 3) * (1.0f / 3.0f);
544
545                 // LordHavoc: if the entity has no effects, don't check each
546                 if (ent->render.effects)
547                 {
548                         if (ent->render.effects & EF_BRIGHTFIELD)
549                                 R_EntityParticles (ent);
550                         if (ent->render.effects & EF_MUZZLEFLASH)
551                         {
552                                 vec3_t v;
553
554                                 AngleVectors (ent->render.angles, v, NULL, NULL);
555
556                                 v[0] = v[0] * 18 + ent->render.origin[0];
557                                 v[1] = v[1] * 18 + ent->render.origin[1];
558                                 v[2] = v[2] * 18 + ent->render.origin[2] + 16;
559
560                                 CL_AllocDlight (ent, v, 100, 1, 1, 1, 0, 0.1);
561                         }
562                         if (ent->render.effects & EF_BRIGHTLIGHT)
563                                 CL_AllocDlight (ent, ent->render.origin, 400, 1, 1, 1, 0, 0);
564                         if (ent->render.effects & EF_DIMLIGHT)
565                                 CL_AllocDlight (ent, ent->render.origin, 200, 1, 1, 1, 0, 0);
566                         // LordHavoc: added EF_RED and EF_BLUE
567                         if (ent->render.effects & EF_RED) // red
568                         {                       
569                                 if (ent->render.effects & EF_BLUE) // magenta
570                                         CL_AllocDlight (ent, ent->render.origin, 200, 1.0f, 0.2f, 1.0f, 0, 0);
571                                 else // red
572                                         CL_AllocDlight (ent, ent->render.origin, 200, 1.0f, 0.1f, 0.1f, 0, 0);
573                         }
574                         else if (ent->render.effects & EF_BLUE) // blue
575                                 CL_AllocDlight (ent, ent->render.origin, 200, 0.1f, 0.1f, 1.0f, 0, 0);
576                         else if (ent->render.effects & EF_FLAME)
577                         {
578                                 if (ent->render.model)
579                                 {
580                                         vec3_t mins, maxs;
581                                         int temp;
582                                         VectorAdd(ent->render.origin, ent->render.model->mins, mins);
583                                         VectorAdd(ent->render.origin, ent->render.model->maxs, maxs);
584                                         // how many flames to make
585                                         temp = (int) (cl.time * 300) - (int) (cl.oldtime * 300);
586                                         R_FlameCube(mins, maxs, temp);
587                                 }
588                                 CL_AllocDlight (ent, ent->render.origin, lhrandom(200, 250), 1.0f, 0.7f, 0.3f, 0, 0);
589                         }
590                 }
591
592                 // LordHavoc: if the model has no flags, don't check each
593                 if (ent->render.model && ent->render.model->flags)
594                 {
595                         if (ent->render.model->flags & EF_ROTATE)
596                         {
597                                 ent->render.angles[1] = bobjrotate;
598 //                              ent->render.origin[2] += bobjoffset;
599                         }
600                         // only do trails if present in the previous frame as well
601                         if (ent->state_previous.modelindex)
602                         {
603                                 if (ent->render.model->flags & EF_GIB)
604                                         R_RocketTrail (oldorg, ent->render.origin, 2, ent);
605                                 else if (ent->render.model->flags & EF_ZOMGIB)
606                                         R_RocketTrail (oldorg, ent->render.origin, 4, ent);
607                                 else if (ent->render.model->flags & EF_TRACER)
608                                         R_RocketTrail (oldorg, ent->render.origin, 3, ent);
609                                 else if (ent->render.model->flags & EF_TRACER2)
610                                         R_RocketTrail (oldorg, ent->render.origin, 5, ent);
611                                 else if (ent->render.model->flags & EF_ROCKET)
612                                 {
613                                         R_RocketTrail (oldorg, ent->render.origin, 0, ent);
614                                         CL_AllocDlight (ent, ent->render.origin, 200, 1.0f, 0.8f, 0.4f, 0, 0);
615                                 }
616                                 else if (ent->render.model->flags & EF_GRENADE)
617                                 {
618                                         if (ent->render.alpha == -1) // LordHavoc: Nehahra dem compatibility
619                                                 R_RocketTrail (oldorg, ent->render.origin, 7, ent);
620                                         else
621                                                 R_RocketTrail (oldorg, ent->render.origin, 1, ent);
622                                 }
623                                 else if (ent->render.model->flags & EF_TRACER3)
624                                         R_RocketTrail (oldorg, ent->render.origin, 6, ent);
625                         }
626                 }
627                 if (ent->render.glowsize) // LordHavoc: customizable glow
628                 {
629                         byte *tempcolor = (byte *)&d_8to24table[ent->render.glowcolor];
630                         CL_AllocDlight (ent, ent->render.origin, ent->render.glowsize, tempcolor[0]*(1.0/255.0), tempcolor[1]*(1.0/255.0), tempcolor[2]*(1.0/255.0), 0, 0);
631                 }
632                 if (ent->render.flags & RENDER_GLOWTRAIL) // LordHavoc: customizable glow and trail
633                         R_RocketTrail2 (oldorg, ent->render.origin, ent->render.glowcolor, ent);
634
635                 if (i == cl.viewentity && !chase_active.value)
636                         continue;
637
638                 if (ent->render.model == NULL)
639                         continue;
640                 if (ent->render.effects & EF_NODRAW)
641                         continue;
642                 if (cl_numvisedicts < MAX_VISEDICTS)
643                         cl_visedicts[cl_numvisedicts++] = ent;
644         }
645 //      Con_Printf("\n");
646 }
647
648
649 // used by cl_shownet
650 int netshown;
651
652 /*
653 ===============
654 CL_ReadFromServer
655
656 Read all incoming data from the server
657 ===============
658 */
659 int CL_ReadFromServer (void)
660 {
661         int             ret;
662
663         cl.oldtime = cl.time;
664         cl.time += cl.frametime;
665         
666         netshown = false;
667         do
668         {
669                 ret = CL_GetMessage ();
670                 if (ret == -1)
671                         Host_Error ("CL_ReadFromServer: lost server connection");
672                 if (!ret)
673                         break;
674                 
675                 cl.last_received_message = realtime;
676                 CL_ParseServerMessage ();
677         } while (ret && cls.state == ca_connected);
678         
679         if (netshown)
680                 Con_Printf ("\n");
681
682         CL_RelinkEntities ();
683         CL_UpdateTEnts ();
684         CL_DoEffects ();
685
686 //
687 // bring the links up to date
688 //
689         return 0;
690 }
691
692 /*
693 =================
694 CL_SendCmd
695 =================
696 */
697 void CL_SendCmd (void)
698 {
699         usercmd_t               cmd;
700
701         if (cls.state != ca_connected)
702                 return;
703
704         if (cls.signon == SIGNONS)
705         {
706         // get basic movement from keyboard
707                 CL_BaseMove (&cmd);
708         
709         // allow mice or other external controllers to add to the move
710                 IN_Move (&cmd);
711         
712         // send the unreliable message
713                 CL_SendMove (&cmd);
714         }
715
716         if (cls.demoplayback)
717         {
718                 SZ_Clear (&cls.message);
719                 return;
720         }
721         
722 // send the reliable message
723         if (!cls.message.cursize)
724                 return;         // no message at all
725         
726         if (!NET_CanSendMessage (cls.netcon))
727         {
728                 Con_DPrintf ("CL_WriteToServer: can't send\n");
729                 return;
730         }
731
732         if (NET_SendMessage (cls.netcon, &cls.message) == -1)
733                 Host_Error ("CL_WriteToServer: lost server connection");
734
735         SZ_Clear (&cls.message);
736 }
737
738 // LordHavoc: pausedemo command
739 void CL_PauseDemo_f (void)
740 {
741         cls.demopaused = !cls.demopaused;
742         if (cls.demopaused)
743                 Con_Printf("Demo paused\n");
744         else
745                 Con_Printf("Demo unpaused\n");
746 }
747
748 /*
749 ======================
750 CL_PModel_f
751 LordHavoc: Intended for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
752 ======================
753 */
754 void CL_PModel_f (void)
755 {
756         int i;
757         eval_t *val;
758
759         if (Cmd_Argc () == 1)
760         {
761                 Con_Printf ("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
762                 return;
763         }
764         i = atoi(Cmd_Argv(1));
765
766         if (cmd_source == src_command)
767         {
768                 if (cl_pmodel.value == i)
769                         return;
770                 Cvar_SetValue ("_cl_pmodel", i);
771                 if (cls.state == ca_connected)
772                         Cmd_ForwardToServer ();
773                 return;
774         }
775
776         host_client->pmodel = i;
777         if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_pmodel)))
778                 val->_float = i;
779 }
780
781 /*
782 ======================
783 CL_Fog_f
784 ======================
785 */
786 void CL_Fog_f (void)
787 {
788         if (Cmd_Argc () == 1)
789         {
790                 Con_Printf ("\"fog\" is \"%f %f %f %f\"\n", fog_density, fog_red, fog_green, fog_blue);
791                 return;
792         }
793         fog_density = atof(Cmd_Argv(1));
794         fog_red = atof(Cmd_Argv(2));
795         fog_green = atof(Cmd_Argv(3));
796         fog_blue = atof(Cmd_Argv(4));
797 }
798
799 cvar_t demo_nehahra = {"demo_nehahra", "0"};
800
801 /*
802 =================
803 CL_Init
804 =================
805 */
806 void CL_Init (void)
807 {       
808         SZ_Alloc (&cls.message, 1024);
809
810         CL_InitInput ();
811         CL_InitTEnts ();
812         
813 //
814 // register our commands
815 //
816         Cvar_RegisterVariable (&cl_name);
817         Cvar_RegisterVariable (&cl_color);
818         Cvar_RegisterVariable (&cl_pmodel);
819         Cvar_RegisterVariable (&cl_upspeed);
820         Cvar_RegisterVariable (&cl_forwardspeed);
821         Cvar_RegisterVariable (&cl_backspeed);
822         Cvar_RegisterVariable (&cl_sidespeed);
823         Cvar_RegisterVariable (&cl_movespeedkey);
824         Cvar_RegisterVariable (&cl_yawspeed);
825         Cvar_RegisterVariable (&cl_pitchspeed);
826         Cvar_RegisterVariable (&cl_anglespeedkey);
827         Cvar_RegisterVariable (&cl_shownet);
828         Cvar_RegisterVariable (&cl_nolerp);
829         Cvar_RegisterVariable (&lookspring);
830         Cvar_RegisterVariable (&lookstrafe);
831         Cvar_RegisterVariable (&sensitivity);
832
833         Cvar_RegisterVariable (&m_pitch);
834         Cvar_RegisterVariable (&m_yaw);
835         Cvar_RegisterVariable (&m_forward);
836         Cvar_RegisterVariable (&m_side);
837
838 //      Cvar_RegisterVariable (&cl_autofire);
839         
840         Cmd_AddCommand ("entities", CL_PrintEntities_f);
841         Cmd_AddCommand ("disconnect", CL_Disconnect_f);
842         Cmd_AddCommand ("record", CL_Record_f);
843         Cmd_AddCommand ("stop", CL_Stop_f);
844         Cmd_AddCommand ("playdemo", CL_PlayDemo_f);
845         Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
846
847         Cmd_AddCommand ("fog", CL_Fog_f);
848
849         // LordHavoc: added pausedemo
850         Cmd_AddCommand ("pausedemo", CL_PauseDemo_f);
851         // LordHavoc: added pmodel command (like name, etc, only intended for Nehahra)
852         Cmd_AddCommand ("pmodel", CL_PModel_f);
853         // LordHavoc: added demo_nehahra cvar
854         Cvar_RegisterVariable (&demo_nehahra);
855         if (nehahra)
856                 Cvar_SetValue("demo_nehahra", 1);
857 }
858