1 #include "../../util.qh"
4 #include "../../movetypes/movetypes.qh"
5 #include "../../../client/rubble.qh"
8 REGISTER_MUTATOR(casings, true);
11 void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner)
13 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;
15 if (!sound_allowed(MSG_BROADCAST, casingowner))
18 WriteByte(MSG_ALL, SVC_TEMPENTITY);
19 WriteMutator(MSG_ALL, casings);
20 WriteByte(MSG_ALL, casingtype);
21 WriteCoord(MSG_ALL, org.x);
22 WriteCoord(MSG_ALL, org.y);
23 WriteCoord(MSG_ALL, org.z);
24 WriteShort(MSG_ALL, compressShortVector(vel)); // actually compressed velocity
25 WriteByte(MSG_ALL, ang.x * 256 / 360);
26 WriteByte(MSG_ALL, ang.y * 256 / 360);
27 WriteByte(MSG_ALL, ang.z * 256 / 360);
33 class(Casing) .float alpha;
34 class(Casing) .bool silent;
35 class(Casing) .int state;
36 class(Casing) .float cnt;
45 if (self.move_flags & FL_ONGROUND)
47 self.move_angles_x = 0;
48 self.move_angles_z = 0;
49 self.flags &= ~FL_ONGROUND;
52 Movetype_Physics_MatchTicrate(autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy);
54 return; // deleted by touch function
57 self.alpha = bound(0, self.cnt - time, 1);
59 if (self.alpha < ALPHA_MIN_VISIBLE)
68 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
75 if (!trace_ent || trace_ent.solid == SOLID_BSP)
77 if (vlen(self.velocity) > 50)
79 if (time >= self.nextthink)
82 int f = floor(prandom() * 3) + 1;
87 s = W_Sound(strcat("casings", itos(f)));
90 s = W_Sound(strcat("brass", itos(f)));
94 sound (self, CH_SHOTS, s, VOL_BASE, ATTEN_LARGE);
99 self.nextthink = time + 0.2;
102 void Casing_Damage(float thisdmg, int hittype, vector org, vector thisforce)
106 self.move_velocity = self.move_velocity + thisforce + '0 0 100';
107 self.move_flags &= ~FL_ONGROUND;
110 MUTATOR_HOOKFUNCTION(casings, CSQC_Parse_TempEntity)
112 if (MUTATOR_RETURNVALUE) return;
113 if (!ReadMutatorEquals(mutator_argv_int_0, casings)) return;
116 int _state = ReadByte();
121 vector vel = decompressShortVector(ReadShort());
123 ang_x = ReadByte() * 360 / 256;
124 ang_y = ReadByte() * 360 / 256;
125 ang_z = ReadByte() * 360 / 256;
127 if (!autocvar_cl_casings) return;
129 Casing casing = RubbleNew("casing");
130 casing.silent = (_state & 0x80);
131 casing.state = (_state & 0x7F);
133 setorigin(casing, casing.origin);
134 casing.velocity = vel;
136 casing.drawmask = MASK_NORMAL;
138 casing.draw = Casing_Draw;
139 casing.move_origin = casing.origin;
140 casing.move_velocity = casing.velocity + 2 * prandomvec();
141 casing.move_angles = casing.angles;
142 casing.move_avelocity = '0 250 0' + 100 * prandomvec();
143 casing.move_movetype = MOVETYPE_BOUNCE;
144 casing.move_touch = Casing_Touch;
145 casing.move_time = time;
146 casing.event_damage = Casing_Damage;
147 casing.solid = SOLID_TRIGGER;
149 switch (casing.state)
152 setmodel(casing, MDL_CASING_SHELL);
153 casing.cnt = time + autocvar_cl_casings_shell_time;
156 setmodel(casing, MDL_CASING_BULLET);
157 casing.cnt = time + autocvar_cl_casings_bronze_time;
161 setsize(casing, '0 0 -1', '0 0 -1');
163 RubbleLimit("casing", autocvar_cl_casings_maxcount, Casing_Delete);
168 precache_sound(W_Sound("brass1"));
169 precache_sound(W_Sound("brass2"));
170 precache_sound(W_Sound("brass3"));
171 precache_sound(W_Sound("casings1"));
172 precache_sound(W_Sound("casings2"));
173 precache_sound(W_Sound("casings3"));