pmodel fixes (now works properly in listen/singleplayer)
[xonotic/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].baseline.alpha = 255;
86                 cl_entities[i].baseline.scale = 16;
87                 cl_entities[i].baseline.glowsize = 0;
88                 cl_entities[i].baseline.glowcolor = 254;
89                 cl_entities[i].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 extern int numgltextures;
179 extern int texels;
180
181 /*
182 =====================
183 CL_SignonReply
184
185 An svc_signonnum has been received, perform a client side setup
186 =====================
187 */
188 void CL_SignonReply (void)
189 {
190         char    str[8192];
191
192 Con_DPrintf ("CL_SignonReply: %i\n", cls.signon);
193
194         switch (cls.signon)
195         {
196         case 1:
197                 MSG_WriteByte (&cls.message, clc_stringcmd);
198                 MSG_WriteString (&cls.message, "prespawn");
199                 break;
200                 
201         case 2:
202                 MSG_WriteByte (&cls.message, clc_stringcmd);
203                 MSG_WriteString (&cls.message, va("name \"%s\"\n", cl_name.string));
204
205                 MSG_WriteByte (&cls.message, clc_stringcmd);
206                 MSG_WriteString (&cls.message, va("color %i %i\n", ((int)cl_color.value)>>4, ((int)cl_color.value)&15));
207         
208                 if (cl_pmodel.value)
209                 {
210                         MSG_WriteByte (&cls.message, clc_stringcmd);
211                         MSG_WriteString (&cls.message, va("pmodel %f\n", cl_pmodel.value));
212                 }
213
214                 MSG_WriteByte (&cls.message, clc_stringcmd);
215                 sprintf (str, "spawn %s", cls.spawnparms);
216                 MSG_WriteString (&cls.message, str);
217                 break;
218                 
219         case 3: 
220                 MSG_WriteByte (&cls.message, clc_stringcmd);
221                 MSG_WriteString (&cls.message, "begin");
222                 Cache_Report ();                // print remaining memory
223                 break;
224                 
225         case 4:
226                 SCR_EndLoadingPlaque ();                // allow normal screen updates
227                 // LordHavoc: debugging purposes
228                 Con_DPrintf("GLQuake texture slots in use: %i : %i : %i texels\n", texture_extension_number, numgltextures, texels);
229                 break;
230         }
231 }
232
233 /*
234 =====================
235 CL_NextDemo
236
237 Called to play the next demo in the demo loop
238 =====================
239 */
240 void CL_NextDemo (void)
241 {
242         char    str[1024];
243
244         if (cls.demonum == -1)
245                 return;         // don't play demos
246
247         SCR_BeginLoadingPlaque ();
248
249         if (!cls.demos[cls.demonum][0] || cls.demonum == MAX_DEMOS)
250         {
251                 cls.demonum = 0;
252                 if (!cls.demos[cls.demonum][0])
253                 {
254                         Con_Printf ("No demos listed with startdemos\n");
255                         cls.demonum = -1;
256                         return;
257                 }
258         }
259
260         sprintf (str,"playdemo %s\n", cls.demos[cls.demonum]);
261         Cbuf_InsertText (str);
262         cls.demonum++;
263 }
264
265 /*
266 ==============
267 CL_PrintEntities_f
268 ==============
269 */
270 void CL_PrintEntities_f (void)
271 {
272         entity_t        *ent;
273         int                     i;
274         
275         for (i=0,ent=cl_entities ; i<cl.num_entities ; i++,ent++)
276         {
277                 Con_Printf ("%3i:",i);
278                 if (!ent->model)
279                 {
280                         Con_Printf ("EMPTY\n");
281                         continue;
282                 }
283                 Con_Printf ("%s:%2i  (%5.1f,%5.1f,%5.1f) [%5.1f %5.1f %5.1f]\n"
284                 ,ent->model->name,ent->frame, ent->origin[0], ent->origin[1], ent->origin[2], ent->angles[0], ent->angles[1], ent->angles[2]);
285         }
286 }
287
288
289 /*
290 ===============
291 SetPal
292
293 Debugging tool, just flashes the screen
294 ===============
295 */
296 void SetPal (int i)
297 {
298 #if 0
299         static int old;
300         byte    pal[768];
301         int             c;
302         
303         if (i == old)
304                 return;
305         old = i;
306
307         if (i==0)
308                 VID_SetPalette (host_basepal);
309         else if (i==1)
310         {
311                 for (c=0 ; c<768 ; c+=3)
312                 {
313                         pal[c] = 0;
314                         pal[c+1] = 255;
315                         pal[c+2] = 0;
316                 }
317                 VID_SetPalette (pal);
318         }
319         else
320         {
321                 for (c=0 ; c<768 ; c+=3)
322                 {
323                         pal[c] = 0;
324                         pal[c+1] = 0;
325                         pal[c+2] = 255;
326                 }
327                 VID_SetPalette (pal);
328         }
329 #endif
330 }
331
332 /*
333 ===============
334 CL_AllocDlight
335
336 ===============
337 */
338 dlight_t *CL_AllocDlight (int key)
339 {
340         int             i;
341         dlight_t        *dl;
342
343 // first look for an exact key match
344         if (key)
345         {
346                 dl = cl_dlights;
347                 for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
348                 {
349                         if (dl->key == key)
350                         {
351                                 memset (dl, 0, sizeof(*dl));
352                                 dl->key = key;
353                                 return dl;
354                         }
355                 }
356         }
357
358 // then look for anything else
359         dl = cl_dlights;
360         for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
361         {
362                 if (dl->die < cl.time)
363                 {
364                         memset (dl, 0, sizeof(*dl));
365                         dl->key = key;
366                         return dl;
367                 }
368         }
369
370         dl = &cl_dlights[0];
371         memset (dl, 0, sizeof(*dl));
372         dl->key = key;
373         return dl;
374 }
375
376
377 /*
378 ===============
379 CL_DecayLights
380
381 ===============
382 */
383 void CL_DecayLights (void)
384 {
385         int                     i;
386         dlight_t        *dl;
387         float           time;
388         
389         time = cl.time - cl.oldtime;
390
391         dl = cl_dlights;
392         for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
393         {
394                 if (dl->die < cl.time || !dl->radius)
395                         continue;
396                 
397                 dl->radius -= time*dl->decay;
398                 if (dl->radius < 0)
399                         dl->radius = 0;
400         }
401 }
402
403
404 /*
405 ===============
406 CL_LerpPoint
407
408 Determines the fraction between the last two messages that the objects
409 should be put at.
410 ===============
411 */
412 float   CL_LerpPoint (void)
413 {
414         float   f, frac;
415
416         f = cl.mtime[0] - cl.mtime[1];
417         
418         if (!f || cl_nolerp.value || cls.timedemo || sv.active)
419         {
420                 cl.time = cl.mtime[0];
421                 return 1;
422         }
423                 
424         if (f > 0.1)
425         {       // dropped packet, or start of demo
426                 cl.mtime[1] = cl.mtime[0] - 0.1;
427                 f = 0.1;
428         }
429         frac = (cl.time - cl.mtime[1]) / f;
430 //Con_Printf ("frac: %f\n",frac);
431         if (frac < 0)
432         {
433                 if (frac < -0.01)
434                 {
435 SetPal(1);
436                         cl.time = cl.mtime[1];
437 //                              Con_Printf ("low frac\n");
438                 }
439                 frac = 0;
440         }
441         else if (frac > 1)
442         {
443                 if (frac > 1.01)
444                 {
445 SetPal(2);
446                         cl.time = cl.mtime[0];
447 //                              Con_Printf ("high frac\n");
448                 }
449                 frac = 1;
450         }
451         else
452                 SetPal(0);
453                 
454         return frac;
455 }
456
457
458 /*
459 ===============
460 CL_RelinkEntities
461 ===============
462 */
463 void R_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent);
464 void CL_RelinkEntities (void)
465 {
466         entity_t        *ent;
467         int                     i, j;
468         float           frac, f, d;
469         vec3_t          delta;
470         float           bobjrotate;
471         vec3_t          oldorg;
472         dlight_t        *dl;
473         byte            *tempcolor;
474
475 // determine partial update time        
476         frac = CL_LerpPoint ();
477
478         cl_numvisedicts = 0;
479
480 //
481 // interpolate player info
482 //
483         for (i=0 ; i<3 ; i++)
484                 cl.velocity[i] = cl.mvelocity[1][i] + frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]);
485
486         if (cls.demoplayback)
487         {
488         // interpolate the angles       
489                 for (j=0 ; j<3 ; j++)
490                 {
491                         d = cl.mviewangles[0][j] - cl.mviewangles[1][j];
492                         if (d > 180)
493                                 d -= 360;
494                         else if (d < -180)
495                                 d += 360;
496                         cl.viewangles[j] = cl.mviewangles[1][j] + frac*d;
497                 }
498         }
499         
500         bobjrotate = anglemod(100*cl.time);
501         
502 // start on the entity after the world
503         for (i=1,ent=cl_entities+1 ; i<cl.num_entities ; i++,ent++)
504         {
505                 if (!ent->model)
506                 {       // empty slot
507                         if (ent->forcelink)
508                                 R_RemoveEfrags (ent);   // just became empty
509                         continue;
510                 }
511
512 // if the object wasn't included in the last packet, remove it
513                 if (ent->msgtime != cl.mtime[0])
514                 {
515                         ent->model = NULL;
516                         continue;
517                 }
518
519                 VectorCopy (ent->origin, oldorg);
520
521                 if (ent->forcelink)
522                 {       // the entity was not updated in the last message
523                         // so move to the final spot
524                         VectorCopy (ent->msg_origins[0], ent->origin);
525                         VectorCopy (ent->msg_angles[0], ent->angles);
526                 }
527                 else
528                 {       // if the delta is large, assume a teleport and don't lerp
529                         f = frac;
530                         for (j=0 ; j<3 ; j++)
531                         {
532                                 delta[j] = ent->msg_origins[0][j] - ent->msg_origins[1][j];
533                                 // LordHavoc: increased lerp tolerance from 100 to 200
534                                 if (delta[j] > 200 || delta[j] < -200)
535                                         f = 1;          // assume a teleportation, not a motion
536                         }
537
538                 // interpolate the origin and angles
539                         for (j=0 ; j<3 ; j++)
540                         {
541                                 ent->origin[j] = ent->msg_origins[1][j] + f*delta[j];
542
543                                 d = ent->msg_angles[0][j] - ent->msg_angles[1][j];
544                                 if (d > 180)
545                                         d -= 360;
546                                 else if (d < -180)
547                                         d += 360;
548                                 ent->angles[j] = ent->msg_angles[1][j] + f*d;
549                         }
550                         
551                 }
552
553                 if (ent->effects & EF_BRIGHTFIELD)
554                         R_EntityParticles (ent);
555                 if (ent->effects & EF_MUZZLEFLASH)
556                 {
557                         vec3_t          fv, rv, uv;
558
559                         dl = CL_AllocDlight (i);
560                         VectorCopy (ent->origin,  dl->origin);
561                         dl->origin[2] += 16;
562                         AngleVectors (ent->angles, fv, rv, uv);
563                          
564                         VectorMA (dl->origin, 18, fv, dl->origin);
565                         dl->radius = 200 + (rand()&31);
566                         dl->minlight = 32;
567                         dl->die = cl.time + 0.1;
568                         dl->color[0] = 1.0;dl->color[1] = 1.0;dl->color[2] = 1.0;
569                 }
570                 if (ent->effects & EF_BRIGHTLIGHT)
571                 {                       
572                         dl = CL_AllocDlight (i);
573                         VectorCopy (ent->origin,  dl->origin);
574                         dl->origin[2] += 16;
575                         dl->radius = 400 + (rand()&31);
576                         dl->die = cl.time + 0.001;
577                         dl->color[0] = 1.0;dl->color[1] = 1.0;dl->color[2] = 1.0;
578                 }
579                 if (ent->effects & EF_DIMLIGHT)
580                 {                       
581                         dl = CL_AllocDlight (i);
582                         VectorCopy (ent->origin,  dl->origin);
583                         dl->radius = 200 + (rand()&31);
584                         dl->die = cl.time + 0.001;
585                         dl->color[0] = 1.0;dl->color[1] = 1.0;dl->color[2] = 1.0;
586                 }
587                 // LordHavoc: added EF_RED and EF_BLUE
588                 if (ent->effects & EF_RED) // red
589                 {                       
590                         if (ent->effects & EF_BLUE) // magenta
591                         {
592                                 dl = CL_AllocDlight (i);
593                                 VectorCopy (ent->origin,  dl->origin);
594                                 dl->radius = 200 + (rand()&31);
595                                 dl->die = cl.time + 0.001;
596                                 dl->color[0] = 0.7;dl->color[1] = 0.07;dl->color[2] = 0.7;
597                         }
598                         else // red
599                         {
600                                 dl = CL_AllocDlight (i);
601                                 VectorCopy (ent->origin,  dl->origin);
602                                 dl->radius = 200 + (rand()&31);
603                                 dl->die = cl.time + 0.001;
604                                 dl->color[0] = 0.8;dl->color[1] = 0.05;dl->color[2] = 0.05;
605                         }
606                 }
607                 else if (ent->effects & EF_BLUE) // blue
608                 {
609                         dl = CL_AllocDlight (i);
610                         VectorCopy (ent->origin,  dl->origin);
611                         dl->radius = 200 + (rand()&31);
612                         dl->die = cl.time + 0.001;
613                         dl->color[0] = 0.05;dl->color[1] = 0.05;dl->color[2] = 0.8;
614                 }
615
616                 if (ent->model->flags) // LordHavoc: if the model has no flags, don't check each
617                 {
618                 // rotate binary objects locally
619                         if (ent->model->flags & EF_ROTATE)
620                                 ent->angles[1] = bobjrotate;
621                         if (ent->model->flags & EF_GIB)
622                                 R_RocketTrail (oldorg, ent->origin, 2, ent);
623                         else if (ent->model->flags & EF_ZOMGIB)
624                                 R_RocketTrail (oldorg, ent->origin, 4, ent);
625                         else if (ent->model->flags & EF_TRACER)
626                                 R_RocketTrail (oldorg, ent->origin, 3, ent);
627                         else if (ent->model->flags & EF_TRACER2)
628                                 R_RocketTrail (oldorg, ent->origin, 5, ent);
629                         else if (ent->model->flags & EF_ROCKET)
630                         {
631                                 R_RocketTrail (oldorg, ent->origin, 0, ent);
632                                 dl = CL_AllocDlight (i);
633                                 VectorCopy (ent->origin, dl->origin);
634                                 dl->radius = 200;
635                                 dl->die = cl.time + 0.001;
636                                 dl->color[0] = 1.0;dl->color[1] = 0.8;dl->color[2] = 0.4;
637                         }
638                         else if (ent->model->flags & EF_GRENADE)
639                         {
640                                 if (ent->alpha == -1) // LordHavoc: Nehahra dem compatibility
641                                         R_RocketTrail (oldorg, ent->origin, 7, ent);
642                                 else
643                                         R_RocketTrail (oldorg, ent->origin, 1, ent);
644                         }
645                         else if (ent->model->flags & EF_TRACER3)
646                                 R_RocketTrail (oldorg, ent->origin, 6, ent);
647                 }
648                 if (ent->glowsize) // LordHavoc: customizable glow
649                 {
650                         dl = CL_AllocDlight (i);
651                         VectorCopy (ent->origin, dl->origin);
652                         dl->dark = ent->glowsize < 0; // darklight
653                         dl->radius = ent->glowsize;
654                         if (dl->dark)
655                         {
656                                 if (ent->glowtrail) // LordHavoc: all darklights leave black trails
657                                         R_RocketTrail2 (oldorg, ent->origin, 0, ent);
658                                 dl->radius = -ent->glowsize;
659                         }
660                         else if (ent->glowtrail) // LordHavoc: customizable glow and trail
661                                 R_RocketTrail2 (oldorg, ent->origin, ent->glowcolor, ent);
662                         dl->die = cl.time + 0.001;
663                         tempcolor = (byte *)&d_8to24table[ent->glowcolor];
664                         dl->color[0] = tempcolor[0]*(1.0/255.0);dl->color[1] = tempcolor[1]*(1.0/255.0);dl->color[2] = tempcolor[2]*(1.0/255.0);
665                 }
666                 else if (ent->glowtrail) // LordHavoc: customizable glow and trail
667                         R_RocketTrail2 (oldorg, ent->origin, ent->glowcolor, ent);
668
669                 ent->forcelink = false;
670
671                 if (i == cl.viewentity && !chase_active.value)
672                         continue;
673
674 // LordHavoc: enabled EF_NODRAW
675                 if (!ent->model || ent->effects & EF_NODRAW)
676                         continue;
677                 if (cl_numvisedicts < MAX_VISEDICTS)
678                 {
679                         cl_visedicts[cl_numvisedicts] = ent;
680                         cl_numvisedicts++;
681                 }
682         }
683
684 }
685
686
687 /*
688 ===============
689 CL_ReadFromServer
690
691 Read all incoming data from the server
692 ===============
693 */
694 int CL_ReadFromServer (void)
695 {
696         int             ret;
697
698         cl.oldtime = cl.time;
699         cl.time += host_frametime;
700         
701         do
702         {
703                 ret = CL_GetMessage ();
704                 if (ret == -1)
705                         Host_Error ("CL_ReadFromServer: lost server connection");
706                 if (!ret)
707                         break;
708                 
709                 cl.last_received_message = realtime;
710                 CL_ParseServerMessage ();
711         } while (ret && cls.state == ca_connected);
712         
713         if (cl_shownet.value)
714                 Con_Printf ("\n");
715
716         CL_RelinkEntities ();
717         CL_UpdateTEnts ();
718
719 //
720 // bring the links up to date
721 //
722         return 0;
723 }
724
725 /*
726 =================
727 CL_SendCmd
728 =================
729 */
730 void CL_SendCmd (void)
731 {
732         usercmd_t               cmd;
733
734         if (cls.state != ca_connected)
735                 return;
736
737         if (cls.signon == SIGNONS)
738         {
739         // get basic movement from keyboard
740                 CL_BaseMove (&cmd);
741         
742         // allow mice or other external controllers to add to the move
743                 IN_Move (&cmd);
744         
745         // send the unreliable message
746                 CL_SendMove (&cmd);
747         
748         }
749
750         if (cls.demoplayback)
751         {
752                 SZ_Clear (&cls.message);
753                 return;
754         }
755         
756 // send the reliable message
757         if (!cls.message.cursize)
758                 return;         // no message at all
759         
760         if (!NET_CanSendMessage (cls.netcon))
761         {
762                 Con_DPrintf ("CL_WriteToServer: can't send\n");
763                 return;
764         }
765
766         if (NET_SendMessage (cls.netcon, &cls.message) == -1)
767                 Host_Error ("CL_WriteToServer: lost server connection");
768
769         SZ_Clear (&cls.message);
770 }
771
772 // LordHavoc: pausedemo command
773 void CL_PauseDemo_f (void)
774 {
775         cls.demopaused = !cls.demopaused;
776         if (cls.demopaused)
777                 Con_Printf("Demo paused\n");
778         else
779                 Con_Printf("Demo unpaused\n");
780 }
781
782 /*
783 ======================
784 CL_PModel_f
785 LordHavoc: Intended for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
786 ======================
787 */
788 void CL_PModel_f (void)
789 {
790         int i;
791         eval_t *val;
792
793         if (Cmd_Argc () == 1)
794         {
795                 Con_Printf ("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
796                 return;
797         }
798         i = atoi(Cmd_Argv(1));
799
800         if (cmd_source == src_command)
801         {
802                 if (cl_pmodel.value == i)
803                         return;
804                 Cvar_SetValue ("_cl_pmodel", i);
805                 if (cls.state == ca_connected)
806                         Cmd_ForwardToServer ();
807                 return;
808         }
809
810         host_client->pmodel = i;
811         if (val = GETEDICTFIELDVALUE(host_client->edict, eval_pmodel))
812                 val->_float = i;
813 }
814
815 cvar_t demo_nehahra = {"demo_nehahra", "0"};
816
817 /*
818 =================
819 CL_Init
820 =================
821 */
822 void CL_Init (void)
823 {       
824         SZ_Alloc (&cls.message, 1024);
825
826         CL_InitInput ();
827         CL_InitTEnts ();
828         
829 //
830 // register our commands
831 //
832         Cvar_RegisterVariable (&cl_name);
833         Cvar_RegisterVariable (&cl_color);
834         Cvar_RegisterVariable (&cl_pmodel);
835         Cvar_RegisterVariable (&cl_upspeed);
836         Cvar_RegisterVariable (&cl_forwardspeed);
837         Cvar_RegisterVariable (&cl_backspeed);
838         Cvar_RegisterVariable (&cl_sidespeed);
839         Cvar_RegisterVariable (&cl_movespeedkey);
840         Cvar_RegisterVariable (&cl_yawspeed);
841         Cvar_RegisterVariable (&cl_pitchspeed);
842         Cvar_RegisterVariable (&cl_anglespeedkey);
843         Cvar_RegisterVariable (&cl_shownet);
844         Cvar_RegisterVariable (&cl_nolerp);
845         Cvar_RegisterVariable (&lookspring);
846         Cvar_RegisterVariable (&lookstrafe);
847         Cvar_RegisterVariable (&sensitivity);
848
849         Cvar_RegisterVariable (&m_pitch);
850         Cvar_RegisterVariable (&m_yaw);
851         Cvar_RegisterVariable (&m_forward);
852         Cvar_RegisterVariable (&m_side);
853
854 //      Cvar_RegisterVariable (&cl_autofire);
855         
856         Cmd_AddCommand ("entities", CL_PrintEntities_f);
857         Cmd_AddCommand ("disconnect", CL_Disconnect_f);
858         Cmd_AddCommand ("record", CL_Record_f);
859         Cmd_AddCommand ("stop", CL_Stop_f);
860         Cmd_AddCommand ("playdemo", CL_PlayDemo_f);
861         Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
862
863         // LordHavoc: added pausedemo
864         Cmd_AddCommand ("pausedemo", CL_PauseDemo_f);
865         // LordHavoc: added pmodel command (like name, etc, only intended for Nehahra)
866         Cmd_AddCommand ("pmodel", CL_PModel_f);
867         // LordHavoc: added demo_nehahra cvar
868         Cvar_RegisterVariable (&demo_nehahra);
869         if (nehahra)
870                 Cvar_SetValue("demo_nehahra", 1);
871 }
872