-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcl_main.c
938 lines (787 loc) · 23.4 KB
/
cl_main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
/*
Copyright (C) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// cl_main.c -- client main loop
#include "quakedef.h"
// we need to declare some mouse variables here, because the menu system
// references them even when on a unix system.
// these two are not intended to be set directly
cvar_t cl_name = {"cl_name", "player", CVAR_ARCHIVE};
cvar_t cl_color = {"cl_color", "0", CVAR_ARCHIVE};
cvar_t cl_shownet = {"cl_shownet","0", CVAR_NONE}; // can be 0, 1, or 2
cvar_t cl_nolerp = {"cl_nolerp","0", CVAR_NONE};
cvar_t cl_lerpmuzzleflash = {"cl_lerpmuzzleflash","0", CVAR_NONE};
cvar_t cl_coloredlight = {"cl_coloredlight","0", CVAR_ARCHIVE};
cvar_t cl_extradlight = {"cl_extradlight","0", CVAR_ARCHIVE};
cvar_t lookspring = {"lookspring","0", CVAR_ARCHIVE};
cvar_t lookstrafe = {"lookstrafe","0", CVAR_ARCHIVE};
cvar_t sensitivity = {"sensitivity","3", CVAR_ARCHIVE};
cvar_t m_pitch = {"m_pitch","0.022", CVAR_ARCHIVE};
cvar_t m_yaw = {"m_yaw","0.022", CVAR_ARCHIVE};
cvar_t m_forward = {"m_forward","1", CVAR_ARCHIVE};
cvar_t m_side = {"m_side","0.8", CVAR_ARCHIVE};
client_static_t cls;
client_state_t cl;
// FIXME: put these on hunk?
efrag_t cl_efrags[MAX_EFRAGS];
entity_t cl_entities[MAX_EDICTS];
entity_t cl_static_entities[MAX_STATIC_ENTITIES];
lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
dlight_t cl_dlights[MAX_DLIGHTS];
int cl_numvisedicts;
entity_t *cl_visedicts[MAX_VISEDICTS];
/*
=====================
CL_ClearState
=====================
*/
void CL_ClearState (void)
{
int i;
if (!sv.active)
Host_ClearMemory ();
// wipe the entire cl structure
memset (&cl, 0, sizeof(cl));
// If disconnect was missing, stop sounds here
if (cls.state == ca_connected)
S_StopAllSounds (true);
SZ_Clear (&cls.message);
// clear other arrays
memset (cl_efrags, 0, sizeof(cl_efrags));
memset (cl_entities, 0, sizeof(cl_entities));
memset (cl_dlights, 0, sizeof(cl_dlights));
memset (cl_lightstyle, 0, sizeof(cl_lightstyle));
memset (cl_temp_entities, 0, sizeof(cl_temp_entities));
memset (cl_beams, 0, sizeof(cl_beams));
//
// allocate the efrags and chain together into a free list
//
cl.free_efrags = cl_efrags;
for (i=0 ; i<MAX_EFRAGS-1 ; i++)
cl.free_efrags[i].entnext = &cl.free_efrags[i+1];
cl.free_efrags[i].entnext = NULL;
}
/*
=====================
CL_Reconnect
Wait for the signon messages again.
=====================
*/
void CL_Reconnect (void)
{
SCR_BeginLoadingPlaque ();
cls.signon = 0; // need new connection messages
}
/*
=====================
CL_Disconnect
Sends a disconnect message to the server
This is also called on Host_Error, so it shouldn't cause any errors
=====================
*/
void CL_Disconnect (void)
{
// stop sounds (especially looping!)
S_StopAllSounds (true);
CDAudio_Stop(); // Stop the CD music
// if running a local server, shut it down
cl.worldmodel = NULL; // This makes sure ambient sounds remain silent
// stop all intermissions
// (the intermission screen prints the map name so this is important for preventing a crash)
cl.intermission = 0; // Baker: So critical. SCR_UpdateScreen uses this.
// remove all center prints
con_lastcenterstring[0] = 0;
scr_centerstring[0] = 0;
scr_centertime_off = 0;
if (cls.demoplayback)
CL_StopPlayback ();
else if (cls.state == ca_connected)
{
if (cls.demorecording)
CL_Stop_f ();
Con_DPrintf ("Sending clc_disconnect\n");
SZ_Clear (&cls.message);
MSG_WriteByte (&cls.message, clc_disconnect);
NET_SendUnreliableMessage (cls.netcon, &cls.message);
SZ_Clear (&cls.message);
NET_Close (cls.netcon);
cls.state = ca_disconnected;
if (sv.active)
Host_ShutdownServer(false);
}
cls.demoplayback = cls.timedemo = false;
cls.signon = 0;
// If we failed to load the requested level, we don't stuck with loading plaque...
SCR_EndLoadingPlaque ();
}
/*
=====================
CL_EstablishConnection
Host should be either "local" or a net address to be passed on
=====================
*/
void CL_EstablishConnection (char *host)
{
if (cls.state == ca_dedicated)
return;
if (cls.demoplayback)
return;
CL_Disconnect ();
cls.netcon = NET_Connect (host);
if (!cls.netcon)
Host_Error ("CL_EstablishConnection: connect failed");
// JPG - ProQuake dprint
if (cls.netcon->mod == MOD_PROQUAKE && cl.protocol == PROTOCOL_NETQUAKE)
Con_DPrintf ("Connected to ProQuake server %s\n", host);
else
Con_DPrintf ("Connected to server %s\n", host);
cls.demonum = -1; // not in the demo loop now
cls.state = ca_connected;
cls.signon = 0; // need all the signon messages before playing
MSG_WriteByte (&cls.message, clc_nop); // ProQuake NAT fix
}
/*
=====================
CL_SignonReply
An svc_signonnum has been received, perform a client side setup
=====================
*/
void CL_SignonReply (void)
{
char str[100 + MAX_MAPSTRING];
Con_DPrintf ("CL_SignonReply: %i\n", cls.signon);
switch (cls.signon)
{
case 1:
MSG_WriteByte (&cls.message, clc_stringcmd);
MSG_WriteString (&cls.message, "prespawn");
break;
case 2:
MSG_WriteByte (&cls.message, clc_stringcmd);
MSG_WriteString (&cls.message, va("name \"%s\"\n", cl_name.string));
MSG_WriteByte (&cls.message, clc_stringcmd);
MSG_WriteString (&cls.message, va("color %i %i\n", ((int)cl_color.value)>>4, ((int)cl_color.value)&15));
MSG_WriteByte (&cls.message, clc_stringcmd);
sprintf (str, "spawn %s", cls.spawnparms);
MSG_WriteString (&cls.message, str);
break;
case 3:
MSG_WriteByte (&cls.message, clc_stringcmd);
MSG_WriteString (&cls.message, "begin");
Cache_Report (); // print remaining memory
break;
case 4:
SCR_EndLoadingPlaque (); // allow normal screen updates
break;
}
}
/*
==============
CL_PrintEntities_f
==============
*/
void CL_PrintEntities_f (void)
{
entity_t *ent;
int i;
for (i=0,ent=cl_entities ; i<cl.num_entities ; i++,ent++)
{
Con_Printf ("%3i:",i);
if (!ent->model)
{
Con_Printf ("EMPTY\n");
continue;
}
Con_Printf ("%s:%2i (%5.1f,%5.1f,%5.1f) [%5.1f %5.1f %5.1f]\n"
,ent->model->name,ent->frame, ent->origin[0], ent->origin[1], ent->origin[2], ent->angles[0], ent->angles[1], ent->angles[2]);
}
}
/*
===============
CL_AllocDlight
===============
*/
dlight_t *CL_AllocDlight (int key)
{
int i;
dlight_t *dl;
// first look for an exact key match
if (key)
{
dl = cl_dlights;
for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
{
if (dl->key == key)
{
memset (dl, 0, sizeof(*dl));
dl->key = key;
dl->color[0] = dl->color[1] = dl->color[2] = 1.0; // lit support via lordhavoc
dl->colored = false;
return dl;
}
}
}
// then look for anything else
dl = cl_dlights;
for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
{
if (dl->die < cl.time)
{
memset (dl, 0, sizeof(*dl));
dl->key = key;
dl->color[0] = dl->color[1] = dl->color[2] = 1.0; // lit support via lordhavoc
dl->colored = false;
return dl;
}
}
dl = &cl_dlights[0];
memset (dl, 0, sizeof(*dl));
dl->key = key;
dl->color[0] = dl->color[1] = dl->color[2] = 1.0; // lit support via lordhavoc
dl->colored = false;
return dl;
}
void CL_ColorDlight (dlight_t *dl, float r, float g, float b)
{
// leave dlight with white value it had at allocation
if (!cl_coloredlight.value)
return;
dl->color[0] = r;
dl->color[1] = g;
dl->color[2] = b;
dl->colored = true;
}
/*
===============
CL_DecayLights
===============
*/
void CL_DecayLights (void)
{
int i;
dlight_t *dl;
float time;
time = cl.time - cl.oldtime;
dl = cl_dlights;
for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
{
if (dl->die < cl.time || !dl->radius)
continue;
dl->radius -= time*dl->decay;
if (dl->radius < 0)
dl->radius = 0;
}
}
/*
===============
CL_LerpPoint
Determines the fraction between the last two messages that the objects
should be put at.
===============
*/
float CL_LerpPoint (void)
{
float f, frac;
f = cl.mtime[0] - cl.mtime[1];
if (!f || cls.timedemo || sv.active)
{
cl.time = cl.mtime[0];
return 1;
}
if (f > 0.1)
{ // dropped packet, or start of demo
cl.mtime[1] = cl.mtime[0] - 0.1;
f = 0.1;
}
frac = (cl.time - cl.mtime[1]) / f;
//Con_Printf ("frac: %f\n",frac);
if (frac < 0)
{
if (frac < -0.01)
{
cl.time = cl.mtime[1];
//Con_Printf ("low frac\n");
}
frac = 0;
}
else if (frac > 1)
{
if (frac > 1.01)
{
cl.time = cl.mtime[0];
//Con_Printf ("high frac\n");
}
frac = 1;
}
//johnfitz -- better nolerp behavior
if (cl_nolerp.value)
return 1;
//johnfitz
return frac;
}
/*
===============
CL_RelinkEntities
===============
*/
void CL_RelinkEntities (void)
{
entity_t *ent;
int i, j;
float frac, f, d;
vec3_t delta;
float objrotate;
vec3_t oldorg;
dlight_t *dl;
static float lastmsg = 0;
// determine partial update time
frac = CL_LerpPoint ();
cl_numvisedicts = 0;
//
// interpolate player info
//
for (i=0 ; i<3 ; i++)
cl.velocity[i] = cl.mvelocity[1][i] + frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]);
if (cls.demoplayback || cl.last_angle_time > host_time)
{
// interpolate the angles
for (j=0 ; j<3 ; j++)
{
d = cl.mviewangles[0][j] - cl.mviewangles[1][j];
if (d > 180)
d -= 360;
else if (d < -180)
d += 360;
cl.lerpangles[j] = cl.mviewangles[1][j] + frac*d;
if (cls.demoplayback)
cl.viewangles[j] = cl.mviewangles[1][j] + frac*d;
}
}
else
VectorCopy(cl.viewangles, cl.lerpangles);
objrotate = anglemod(100*cl.time);
// start on the entity after the world
for (i=1,ent=cl_entities+1 ; i<cl.num_entities ; i++,ent++)
{
if (!ent->model)
{ // empty slot
// ericw -- efrags are only used for static entities in GLQuake
// ent can't be static, so this is a no-op.
// if (ent->forcelink)
// R_RemoveEfrags (ent); // just became empty
continue;
}
// if the object wasn't included in the last packet, remove it
if (ent->msgtime != cl.mtime[0])
{
ent->model = NULL;
ent->lerpflags |= LERP_RESETMOVE|LERP_RESETANIM; //johnfitz -- next time this entity slot is reused, the lerp will need to be reset
continue;
}
VectorCopy (ent->origin, oldorg);
if (ent->forcelink)
{ // the entity was not updated in the last message
// so move to the final spot
VectorCopy (ent->msg_origins[0], ent->origin);
VectorCopy (ent->msg_angles[0], ent->angles);
}
else
{ // if the delta is large, assume a teleport and don't lerp
f = frac;
for (j=0 ; j<3 ; j++)
{
delta[j] = ent->msg_origins[0][j] - ent->msg_origins[1][j];
if (delta[j] > 100 || delta[j] < -100)
{
f = 1; // assume a teleportation, not a motion
ent->lerpflags |= LERP_RESETMOVE; //johnfitz -- don't lerp teleports
}
}
//johnfitz -- don't cl_lerp entities that will be r_lerped
if (ent->lerpflags & LERP_MOVESTEP)
f = 1;
// interpolate the origin and angles
for (j=0 ; j<3 ; j++)
{
ent->origin[j] = ent->msg_origins[1][j] + f*delta[j];
d = ent->msg_angles[0][j] - ent->msg_angles[1][j];
if (d > 180)
d -= 360;
else if (d < -180)
d += 360;
ent->angles[j] = ent->msg_angles[1][j] + f*d;
}
}
// rotate binary objects locally
if (ent->model->flags & EF_ROTATE)
ent->angles[1] = objrotate;
if (ent->effects & EF_BRIGHTFIELD)
R_EntityParticles (ent);
if (ent->effects & EF_MUZZLEFLASH)
{
vec3_t fv, rv, uv;
dl = CL_AllocDlight (i);
VectorCopy (ent->origin, dl->origin);
dl->origin[2] += 16;
AngleVectors (ent->angles, fv, rv, uv);
VectorMA (dl->origin, 18, fv, dl->origin);
dl->radius = 200 + (rand()&31);
dl->minlight = 32;
dl->die = cl.time + 0.1;
//johnfitz -- assume muzzle flash accompanied by muzzle flare, which looks bad when lerped
if (!cl_lerpmuzzleflash.value)
{
if (i == cl.viewentity)
cl.viewent.lerpflags |= LERP_RESETANIM|LERP_RESETANIM2; // no lerping for two frames
}
if (i == cl.viewentity)
{
// switch the flash colour for the current weapon
if (cl.stats[STAT_ACTIVEWEAPON] == IT_LIGHTNING)
CL_ColorDlight (dl, DL_COLOR_LIGHTBLUE);
else if (rogue && cl.stats[STAT_ACTIVEWEAPON] == RIT_PLASMA_GUN)
CL_ColorDlight (dl, DL_COLOR_LIGHTBLUE);
else if (quoth && cl.stats[STAT_ACTIVEWEAPON] == HIT_LASER_CANNON) // quoth plasma gun uses the same bit as hipnotic laser cannon, so check it first
CL_ColorDlight (dl, DL_COLOR_LIGHTBLUE);
else if (hipnotic && cl.stats[STAT_ACTIVEWEAPON] == HIT_LASER_CANNON)
CL_ColorDlight (dl, DL_COLOR_RED);
else
CL_ColorDlight (dl, DL_COLOR_ORANGE);
}
else
{
// some entities have different attacks resulting in a different flash colour
if (!strcmp (ent->model->name, "progs/wizard.mdl"))
CL_ColorDlight (dl, DL_COLOR_GREEN);
else if (!strcmp (ent->model->name, "progs/shalrath.mdl"))
CL_ColorDlight (dl, DL_COLOR_PURPLE);
else if (!strcmp (ent->model->name, "progs/shambler.mdl"))
CL_ColorDlight (dl, DL_COLOR_LIGHTBLUE);
else if (!strcmp (ent->model->name, "progs/enforcer.mdl"))
CL_ColorDlight (dl, DL_COLOR_ORANGE);
else if (!strcmp (ent->model->name, "progs/wrath.mdl") ||
!strcmp (ent->model->name, "progs/s_wrath.mdl")) // rogue wrath
CL_ColorDlight (dl, DL_COLOR_RED);
else if (!strcmp (ent->model->name, "progs/dragon.mdl"))
CL_ColorDlight (dl, DL_COLOR_GOLD);
else
CL_ColorDlight (dl, DL_COLOR_ORANGE);
}
}
if (ent->effects & EF_BRIGHTLIGHT) // rogue plasma and eel
{
dl = CL_AllocDlight (i);
VectorCopy (ent->origin, dl->origin);
dl->origin[2] += 16;
dl->radius = 400 + (rand()&31);
dl->die = cl.time + 0.001;
if (!strcmp (ent->model->name, "progs/plasma.mdl")) // rogue plasma
CL_ColorDlight (dl, DL_COLOR_LIGHTBLUE);
else if (!strcmp (ent->model->name, "progs/eel2.mdl")) // rogue eel
CL_ColorDlight (dl, DL_COLOR_LIGHTBLUE);
else if (!strcmp (ent->model->name, "progs/lasrspik.mdl")) // EER1 (laser for extended hipnotic prog)
CL_ColorDlight (dl, DL_COLOR_RED);
else
CL_ColorDlight (dl, DL_COLOR_WHITE); // uncoloured
}
if (ent->effects & EF_DIMLIGHT) // powerup(s) glows and laser
{
dl = CL_AllocDlight (i);
VectorCopy (ent->origin, dl->origin);
dl->radius = 200 + (rand()&31);
dl->die = cl.time + 0.001;
// powerup dynamic lights
if (i == cl.viewentity)
{
// set the appropriate colour depending on the current powerup(s)
if ((cl.items & IT_QUAD) && (cl.items & IT_INVULNERABILITY))
CL_ColorDlight (dl, DL_COLOR_PURPLE);
else if (cl.items & IT_QUAD)
CL_ColorDlight (dl, DL_COLOR_BLUE);
else if (cl.items & IT_INVULNERABILITY)
CL_ColorDlight (dl, DL_COLOR_RED);
else if (hipnotic && (cl.items & HIT_EMPATHY_SHIELDS)) // hipnotic empathy shield
CL_ColorDlight (dl, DL_COLOR_GOLD);
else
CL_ColorDlight (dl, DL_COLOR_WHITE); // uncoloured
}
else
{
if (!strcmp (ent->model->name, "progs/laser.mdl")) // id enforcer and rogue morph sometime
{
if (rogue)
CL_ColorDlight (dl, DL_COLOR_YELLOW); // morph laser
else
CL_ColorDlight (dl, DL_COLOR_ORANGE);
}
else if (!strcmp (ent->model->name, "progs/morph_az.mdl") ||
!strcmp (ent->model->name, "progs/morph_eg.mdl") ||
!strcmp (ent->model->name, "progs/morph_gr.mdl")) // rogue morph
CL_ColorDlight (dl, DL_COLOR_YELLOW);
else if (!strcmp (ent->model->name, "progs/eel2.mdl")) // rogue eel
CL_ColorDlight (dl, DL_COLOR_LIGHTBLUE);
else if (!strcmp (ent->model->name, "progs/sword.mdl")) // rogue invisible swordsman
CL_ColorDlight (dl, DL_COLOR_YELLOW);
else if (!strcmp (ent->model->name, "progs/lasrspik.mdl")) // hipnotic laser
CL_ColorDlight (dl, DL_COLOR_RED);
else
CL_ColorDlight (dl, DL_COLOR_WHITE); // uncoloured
}
}
// Nehahra
if ((ent->effects & EF_RED) || (ent->effects & EF_BLUE))
{
dl = CL_AllocDlight (i);
VectorCopy (ent->origin, dl->origin);
dl->radius = 200 + (rand()&31);
dl->die = cl.time + 0.001;
// set the appropriate colour
if ((ent->effects & EF_RED) && (ent->effects & EF_BLUE))
CL_ColorDlight (dl, DL_COLOR_PURPLE);
else if (ent->effects & EF_RED)
CL_ColorDlight (dl, DL_COLOR_RED);
else if (ent->effects & EF_BLUE)
CL_ColorDlight (dl, DL_COLOR_BLUE);
}
if (ent->model->flags & EF_GIB)
R_RocketTrail (oldorg, ent->origin, RT_GIB);
else if (ent->model->flags & EF_ZOMGIB)
R_RocketTrail (oldorg, ent->origin, RT_ZOMGIB);
else if (ent->model->flags & EF_TRACER)
{
R_RocketTrail (oldorg, ent->origin, RT_WIZARD);
// wizard trail
if (cl_extradlight.value)
{
dl = CL_AllocDlight (i);
VectorCopy (ent->origin, dl->origin);
dl->radius = 200;
dl->die = cl.time + 0.01;
CL_ColorDlight (dl, DL_COLOR_GREEN);
}
}
else if (ent->model->flags & EF_TRACER2)
{
R_RocketTrail (oldorg, ent->origin, RT_KNIGHT);
// knight trail
if (cl_extradlight.value)
{
dl = CL_AllocDlight (i);
VectorCopy (ent->origin, dl->origin);
dl->radius = 200;
dl->die = cl.time + 0.01;
CL_ColorDlight (dl, DL_COLOR_ORANGE);
}
}
else if (ent->model->flags & EF_TRACER3)
{
R_RocketTrail (oldorg, ent->origin, RT_VORE);
// vore trail
if (cl_extradlight.value)
{
dl = CL_AllocDlight (i);
VectorCopy (ent->origin, dl->origin);
dl->radius = 200;
dl->die = cl.time + 0.01;
CL_ColorDlight (dl, DL_COLOR_PURPLE);
}
}
else if (ent->model->flags & EF_ROCKET)
{
R_RocketTrail (oldorg, ent->origin, RT_ROCKET);
dl = CL_AllocDlight (i);
VectorCopy (ent->origin, dl->origin);
dl->radius = 200;
dl->die = cl.time + 0.01;
CL_ColorDlight (dl, DL_COLOR_ORANGE);
}
else if (ent->model->flags & EF_GRENADE)
R_RocketTrail (oldorg, ent->origin, RT_GRENADE);
ent->forcelink = false;
if (i == cl.viewentity && !chase_active.value)
continue;
// Nehahra
// LordHavoc: enabled EF_NODRAW
if (ent->effects & EF_NODRAW)
continue;
if (cl_numvisedicts < MAX_VISEDICTS)
{
cl_visedicts[cl_numvisedicts] = ent;
cl_numvisedicts++;
}
else if (IsTimeout (&lastmsg, 2))
Con_DWarning ("CL_RelinkEntities: too many visedicts (max = %d)\n", MAX_VISEDICTS);
}
}
/*
===============
CL_ReadFromServer
Read all incoming data from the server
===============
*/
int CL_ReadFromServer (void)
{
int ret;
cl.oldtime = cl.time;
cl.time += host_frametime;
do
{
ret = CL_GetMessage ();
if (ret == -1)
Host_Error ("CL_ReadFromServer: lost server connection");
if (!ret)
break;
cl.last_received_message = realtime;
CL_ParseServerMessage ();
} while (ret && cls.state == ca_connected);
if (cl_shownet.value)
Con_Printf ("\n");
CL_RelinkEntities ();
CL_UpdateTEnts ();
//
// bring the links up to date
//
return 0;
}
/*
=================
CL_SendCmd
=================
*/
void CL_SendCmd (void)
{
usercmd_t cmd;
if (cls.state != ca_connected)
return;
if (cls.signon == SIGNONS)
{
// get basic movement from keyboard
CL_BaseMove (&cmd);
// allow mice or other external controllers to add to the move
IN_Move (&cmd);
// send the unreliable message
CL_SendMove (&cmd);
}
if (cls.demoplayback)
{
SZ_Clear (&cls.message);
return;
}
// send the reliable message
if (!cls.message.cursize)
return; // no message at all
if (!NET_CanSendMessage (cls.netcon))
{
Con_DPrintf ("CL_SendCmd: can't send\n");
return;
}
if (NET_SendMessage (cls.netcon, &cls.message) == -1)
Host_Error ("CL_SendCmd: lost server connection");
SZ_Clear (&cls.message);
}
/*
=============
CL_Tracepos_f
display impact point of trace along VPN
=============
*/
void CL_Tracepos_f (void)
{
vec3_t v, w;
VectorScale(vpn, 8192.0, v);
TraceLine(r_refdef.vieworg, v, w);
if (VectorLength(w) == 0)
Con_Printf ("Tracepos: trace didn't hit anything\n");
else
Con_Printf ("Tracepos: (%i %i %i)\n", (int)w[0], (int)w[1], (int)w[2]);
}
/*
=============
CL_Viewpos_f
Display client's position and mangle
=============
*/
void CL_Viewpos_f (void)
{
// Player position
Con_Printf ("Viewpos: (%i %i %i) %i %i %i\n",
(int)cl_entities[cl.viewentity].origin[0],
(int)cl_entities[cl.viewentity].origin[1],
(int)cl_entities[cl.viewentity].origin[2],
(int)cl.viewangles[PITCH],
(int)cl.viewangles[YAW],
(int)cl.viewangles[ROLL]);
if (sv_player && sv_player->v.movetype == MOVETYPE_NOCLIP && Cmd_Argc() == 4)
{
// Major hack ...
sv_player->v.origin[0] = atoi (Cmd_Argv(1));
sv_player->v.origin[1] = atoi (Cmd_Argv(2));
sv_player->v.origin[2] = atoi (Cmd_Argv(3));
}
}
/*
=============
CL_StaticEnts_f
=============
*/
void CL_StaticEnts_f (void)
{
Con_Printf ("%d static entities\n", cl.num_statics);
}
/*
=================
CL_Init
=================
*/
void CL_Init (void)
{
SZ_Alloc (&cls.message, 8192); //1024, possibly dependant on CMDTEXTSIZE
CL_InitInput ();
CL_InitTEnts ();
//
// register our commands
//
Cvar_RegisterVariable (&cl_name);
Cvar_RegisterVariable (&cl_color);
Cvar_RegisterVariable (&cl_upspeed);
Cvar_RegisterVariable (&cl_forwardspeed);
Cvar_RegisterVariable (&cl_backspeed);
Cvar_RegisterVariable (&cl_sidespeed);
Cvar_RegisterVariable (&cl_movespeedkey);
Cvar_RegisterVariable (&cl_yawspeed);
Cvar_RegisterVariable (&cl_pitchspeed);
Cvar_RegisterVariable (&cl_maxpitch); // variable pitch clamping
Cvar_RegisterVariable (&cl_minpitch); // variable pitch clamping
Cvar_RegisterVariable (&cl_anglespeedkey);
Cvar_RegisterVariable (&cl_shownet);
Cvar_RegisterVariable (&cl_nolerp);
Cvar_RegisterVariable (&cl_lerpmuzzleflash);
Cvar_RegisterVariable (&cl_coloredlight);
Cvar_RegisterVariable (&cl_extradlight);
Cvar_RegisterVariable (&lookspring);
Cvar_RegisterVariable (&lookstrafe);
Cvar_RegisterVariable (&sensitivity);
Cvar_RegisterVariable (&m_pitch);
Cvar_RegisterVariable (&m_yaw);
Cvar_RegisterVariable (&m_forward);
Cvar_RegisterVariable (&m_side);
Cmd_AddCommand ("entities", CL_PrintEntities_f);
Cmd_AddCommand ("record", CL_Record_f);
Cmd_AddCommand ("stop", CL_Stop_f);
Cmd_AddCommand ("playdemo", CL_PlayDemo_f);
Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
Cmd_AddCommand ("tracepos", CL_Tracepos_f); // fitz
Cmd_AddCommand ("viewpos", CL_Viewpos_f);
Cmd_AddCommand ("staticents", CL_StaticEnts_f);
}