3 #include "../../util.qh"
6 #include "../../movetypes/movetypes.qh"
7 #include "../../../client/rubble.qh"
10 REGISTER_MUTATOR(casings, true);
13 void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner)
15 vector org = self.origin + self.view_ofs + self.weaponentity.spawnorigin.x * v_forward - self.weaponentity.spawnorigin.y * v_right + self.weaponentity.spawnorigin.z * v_up;
17 if (!sound_allowed(MSG_BROADCAST, casingowner))
20 WriteByte(MSG_ALL, SVC_TEMPENTITY);
21 WriteMutator(MSG_ALL, casings);
22 WriteByte(MSG_ALL, casingtype);
23 WriteCoord(MSG_ALL, org.x);
24 WriteCoord(MSG_ALL, org.y);
25 WriteCoord(MSG_ALL, org.z);
26 WriteShort(MSG_ALL, compressShortVector(vel)); // actually compressed velocity
27 WriteByte(MSG_ALL, ang.x * 256 / 360);
28 WriteByte(MSG_ALL, ang.y * 256 / 360);
29 WriteByte(MSG_ALL, ang.z * 256 / 360);
35 class(Casing) .float alpha;
36 class(Casing) .bool silent;
37 class(Casing) .int state;
38 class(Casing) .float cnt;
45 void Casing_Draw(entity this)
47 if (self.move_flags & FL_ONGROUND)
49 self.move_angles_x = 0;
50 self.move_angles_z = 0;
51 self.flags &= ~FL_ONGROUND;
54 Movetype_Physics_MatchTicrate(autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy);
56 return; // deleted by touch function
59 self.alpha = bound(0, self.cnt - time, 1);
61 if (self.alpha < ALPHA_MIN_VISIBLE)
68 SOUND(BRASS1, W_Sound("brass1"));
69 SOUND(BRASS2, W_Sound("brass2"));
70 SOUND(BRASS3, W_Sound("brass3"));
71 Sound SND_BRASS_RANDOM() {
72 return Sounds[SND_BRASS1.m_id + floor(prandom() * 3)];
74 SOUND(CASINGS1, W_Sound("casings1"));
75 SOUND(CASINGS2, W_Sound("casings2"));
76 SOUND(CASINGS3, W_Sound("casings3"));
77 Sound SND_CASINGS_RANDOM() {
78 return Sounds[SND_CASINGS1.m_id + floor(prandom() * 3)];
83 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
90 if (!trace_ent || trace_ent.solid == SOLID_BSP)
92 if (vlen(self.velocity) > 50)
94 if (time >= self.nextthink)
100 s = SND_CASINGS_RANDOM();
103 s = SND_BRASS_RANDOM();
107 sound (self, CH_SHOTS, s, VOL_BASE, ATTEN_LARGE);
112 self.nextthink = time + 0.2;
115 void Casing_Damage(float thisdmg, int hittype, vector org, vector thisforce)
119 self.move_velocity = self.move_velocity + thisforce + '0 0 100';
120 self.move_flags &= ~FL_ONGROUND;
123 MUTATOR_HOOKFUNCTION(casings, CSQC_Parse_TempEntity)
125 if (MUTATOR_RETURNVALUE) return;
126 if (!ReadMutatorEquals(mutator_argv_int_0, casings)) return;
129 int _state = ReadByte();
134 vector vel = decompressShortVector(ReadShort());
136 ang_x = ReadByte() * 360 / 256;
137 ang_y = ReadByte() * 360 / 256;
138 ang_z = ReadByte() * 360 / 256;
140 if (!autocvar_cl_casings) return;
142 Casing casing = RubbleNew("casing");
143 casing.silent = (_state & 0x80);
144 casing.state = (_state & 0x7F);
146 setorigin(casing, casing.origin);
147 casing.velocity = vel;
149 casing.drawmask = MASK_NORMAL;
151 casing.draw = Casing_Draw;
152 casing.move_origin = casing.origin;
153 casing.move_velocity = casing.velocity + 2 * prandomvec();
154 casing.move_angles = casing.angles;
155 casing.move_avelocity = '0 250 0' + 100 * prandomvec();
156 casing.move_movetype = MOVETYPE_BOUNCE;
157 casing.move_touch = Casing_Touch;
158 casing.move_time = time;
159 casing.event_damage = Casing_Damage;
160 casing.solid = SOLID_TRIGGER;
162 switch (casing.state)
165 setmodel(casing, MDL_CASING_SHELL);
166 casing.cnt = time + autocvar_cl_casings_shell_time;
169 setmodel(casing, MDL_CASING_BULLET);
170 casing.cnt = time + autocvar_cl_casings_bronze_time;
174 setsize(casing, '0 0 -1', '0 0 -1');
176 RubbleLimit("casing", autocvar_cl_casings_maxcount, Casing_Delete);