3 #include <common/util.qh>
6 #include <common/physics/movetypes/movetypes.qh>
10 REGISTER_NET_TEMP(casings)
13 void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner)
15 .entity weaponentity = weaponentities[0]; // TODO: parameter
16 entity wep = self.(weaponentity);
17 vector org = self.origin + self.view_ofs + wep.spawnorigin.x * v_forward - wep.spawnorigin.y * v_right + wep.spawnorigin.z * v_up;
19 if (!sound_allowed(MSG_BROADCAST, casingowner))
22 WriteHeader(MSG_ALL, casings);
23 WriteByte(MSG_ALL, casingtype);
24 WriteCoord(MSG_ALL, org.x);
25 WriteCoord(MSG_ALL, org.y);
26 WriteCoord(MSG_ALL, org.z);
27 WriteShort(MSG_ALL, compressShortVector(vel)); // actually compressed velocity
28 WriteByte(MSG_ALL, ang.x * 256 / 360);
29 WriteByte(MSG_ALL, ang.y * 256 / 360);
30 WriteByte(MSG_ALL, ang.z * 256 / 360);
36 class(Casing) .float alpha;
37 class(Casing) .bool silent;
38 class(Casing) .int state;
39 class(Casing) .float cnt;
41 void Casing_Delete(entity this)
46 void Casing_Draw(entity this)
48 if (this.move_flags & FL_ONGROUND)
50 this.move_angles_x = 0;
51 this.move_angles_z = 0;
55 Movetype_Physics_MatchTicrate(this, autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy);
57 return; // deleted by touch function
60 this.alpha = bound(0, this.cnt - time, 1);
62 if (this.alpha < ALPHA_MIN_VISIBLE)
69 SOUND(BRASS1, W_Sound("brass1"));
70 SOUND(BRASS2, W_Sound("brass2"));
71 SOUND(BRASS3, W_Sound("brass3"));
72 Sound SND_BRASS_RANDOM() {
73 return Sounds_from(SND_BRASS1.m_id + floor(prandom() * 3));
75 SOUND(CASINGS1, W_Sound("casings1"));
76 SOUND(CASINGS2, W_Sound("casings2"));
77 SOUND(CASINGS3, W_Sound("casings3"));
78 Sound SND_CASINGS_RANDOM() {
79 return Sounds_from(SND_CASINGS1.m_id + floor(prandom() * 3));
84 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
91 if (!trace_ent || trace_ent.solid == SOLID_BSP)
93 if(vdist(self.velocity, >, 50))
95 if (time >= self.nextthink)
101 s = SND_CASINGS_RANDOM();
104 s = SND_BRASS_RANDOM();
108 sound (self, CH_SHOTS, s, VOL_BASE, ATTEN_LARGE);
113 self.nextthink = time + 0.2;
116 void Casing_Damage(entity this, float thisdmg, int hittype, vector org, vector thisforce)
120 this.move_velocity = this.move_velocity + thisforce + '0 0 100';
121 this.move_flags &= ~FL_ONGROUND;
124 NET_HANDLE(casings, bool isNew)
126 int _state = ReadByte();
131 vector vel = decompressShortVector(ReadShort());
133 ang_x = ReadByte() * 360 / 256;
134 ang_y = ReadByte() * 360 / 256;
135 ang_z = ReadByte() * 360 / 256;
138 if (!autocvar_cl_casings) return;
140 Casing casing = RubbleNew("casing");
141 casing.silent = (_state & 0x80);
142 casing.state = (_state & 0x7F);
144 setorigin(casing, casing.origin);
145 casing.velocity = vel;
147 casing.drawmask = MASK_NORMAL;
149 casing.draw = Casing_Draw;
150 casing.move_origin = casing.origin;
151 casing.move_velocity = casing.velocity + 2 * prandomvec();
152 casing.move_angles = casing.angles;
153 casing.move_avelocity = '0 250 0' + 100 * prandomvec();
154 casing.move_movetype = MOVETYPE_BOUNCE;
155 casing.move_touch = Casing_Touch;
156 casing.move_time = time;
157 casing.event_damage = Casing_Damage;
158 casing.solid = SOLID_TRIGGER;
160 switch (casing.state)
163 setmodel(casing, MDL_CASING_SHELL);
164 casing.cnt = time + autocvar_cl_casings_shell_time;
167 setmodel(casing, MDL_CASING_BULLET);
168 casing.cnt = time + autocvar_cl_casings_bronze_time;
172 setsize(casing, '0 0 -1', '0 0 -1');
174 RubbleLimit("casing", autocvar_cl_casings_maxcount, Casing_Delete);