slight csqc physics speedup, should not help much with gibs though
[divverent/nexuiz.git] / data / qcsrc / client / casings.qc
1 float  casecount;
2 entity caselist;
3 .float silent;
4
5 void Casing_Delete()
6 {
7     --casecount;
8     remove(self);
9 }
10
11 void Casing_Draw()
12 {
13         if(self.move_flags & FL_ONGROUND)
14         {
15                 self.move_angles_x = 0;
16                 self.move_angles_z = 0;
17                 self.flags &~= FL_ONGROUND;
18         }
19
20         Movetype_Physics_NoMatchServer();
21
22         self.renderflags = 0;
23         self.alpha = bound(0, self.cnt - time, 1);
24
25         if(self.alpha < ALPHA_MIN_VISIBLE)
26                 Casing_Delete();
27         else
28                 R_AddEntity(self);
29 }
30
31 void Casing_Touch()
32 {
33         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
34         {
35                 Casing_Delete();
36                 return;
37         }
38
39         if(!self.silent)
40         if(!trace_ent || trace_ent.solid == SOLID_BSP)
41         {
42                 if(vlen(self.velocity) > 50)
43                 {
44                         if(time >= self.nextthink)
45                         {
46                                 string s;
47                                 float f;
48
49                                 f = floor(prandom() * 3) + 1;
50                                 switch(self.state)
51                                 {
52                                         case 1:
53                                                 s = strcat("weapons/casings", ftos(f), ".wav");
54                                                 break;
55                                         default:
56                                                 s = strcat("weapons/brass", ftos(f), ".wav");
57                                                 break;
58                                 }
59
60                                 sound (self, CHAN_PROJECTILE, s, VOL_BASE, ATTN_NORM);
61                         }
62                 }
63         }
64
65         self.nextthink = time + 0.2;
66 }
67
68 void Casing_Damage(float thisdmg, float hittype, vector org, vector thisforce)
69 {
70         if(thisforce_z < 0)
71                 thisforce_z = 0;
72         self.move_velocity = self.move_velocity + thisforce + '0 0 100';
73         self.move_flags &~= FL_ONGROUND;
74 }
75
76 void Ent_Casing()
77 {
78         entity casing;
79
80         if not(caselist)
81         caselist = spawn();
82
83         casing = RubbleNew(caselist);
84         ++casecount;
85         if(casecount >= cvar_or("cl_casings_maxcount",100))
86         RubbleDrop(caselist,Casing_Delete);
87
88         casing.state = ReadByte();
89         casing.silent = (casing.state & 0x80);
90         casing.state = (casing.state & 0x7F);
91         casing.origin_x = ReadCoord();
92         casing.origin_y = ReadCoord();
93         casing.origin_z = ReadCoord();
94         casing.velocity = decompressShortVector(ReadShort());
95         casing.angles_x = ReadByte() * 360 / 256;
96         casing.angles_y = ReadByte() * 360 / 256;
97         casing.angles_z = ReadByte() * 360 / 256;
98
99         if(cvar("cl_casings")) {
100                 casing.draw = Casing_Draw;
101                 casing.move_origin = casing.origin;
102                 casing.move_velocity = casing.velocity + 2 * prandomvec();
103                 casing.move_angles = casing.angles;
104                 casing.move_avelocity = '0 250 0' + 100 * prandomvec();
105                 casing.move_movetype = MOVETYPE_BOUNCE;
106                 casing.move_touch = Casing_Touch;
107                 casing.move_time = time;
108                 casing.event_damage = Casing_Damage;
109                 casing.solid = SOLID_TRIGGER;
110
111                 switch(casing.state)
112                 {
113                         case 1:
114                                 setmodel(casing, "models/casing_shell.mdl");
115                                 casing.cnt = time + cvar("cl_casings_shell_time");
116                                 break;
117                         default:
118                                 setmodel(casing, "models/casing_bronze.mdl");
119                                 casing.cnt = time + cvar("cl_casings_bronze_time");
120                                 break;
121                 }
122
123                 setsize(casing, '0 0 -1', '0 0 -1');
124         }
125     else
126         Casing_Delete();
127 }
128
129 void Casings_Precache()
130 {
131         precache_model("models/casing_shell.mdl");
132         precache_model("models/casing_bronze.mdl");
133         precache_sound("weapons/brass1.wav");
134         precache_sound("weapons/brass2.wav");
135         precache_sound("weapons/brass3.wav");
136         precache_sound("weapons/casings1.wav");
137         precache_sound("weapons/casings2.wav");
138         precache_sound("weapons/casings3.wav");
139 }