3 #include <common/util.qh>
6 #include <common/physics/movetypes/movetypes.qh>
10 REGISTER_NET_TEMP(casings)
13 .bool cvar_cl_casings;
17 REPLICATE(cvar_cl_casings, bool, "cl_casings");
20 void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner, .entity weaponentity)
22 entity wep = casingowner.(weaponentity);
23 vector org = casingowner.origin + casingowner.view_ofs + wep.spawnorigin.x * v_forward - wep.spawnorigin.y * v_right + wep.spawnorigin.z * v_up;
25 FOREACH_CLIENT(true, {
26 if (!(CS(it).cvar_cl_casings))
30 if (!sound_allowed(MSG_ONE, it))
31 casingtype |= 0x80; // silent
33 WriteHeader(MSG_ONE, casings);
34 WriteByte(MSG_ONE, casingtype);
35 WriteVector(MSG_ONE, org);
36 WriteShort(MSG_ONE, compressShortVector(vel)); // actually compressed velocity
37 WriteByte(MSG_ONE, ang.x * 256 / 360);
38 WriteByte(MSG_ONE, ang.y * 256 / 360);
39 WriteByte(MSG_ONE, ang.z * 256 / 360);
46 classfield(Casing) .float alpha;
47 classfield(Casing) .bool silent;
48 classfield(Casing) .int state;
49 classfield(Casing) .float cnt;
51 void Casing_Delete(entity this)
56 void Casing_Draw(entity this)
58 if (IS_ONGROUND(this))
62 //UNSET_ONGROUND(this);
65 Movetype_Physics_MatchTicrate(this, autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy);
67 return; // deleted by touch function
70 this.alpha = bound(0, this.cnt - time, 1);
72 if (this.alpha < ALPHA_MIN_VISIBLE)
79 SOUND(BRASS1, W_Sound("brass1"));
80 SOUND(BRASS2, W_Sound("brass2"));
81 SOUND(BRASS3, W_Sound("brass3"));
82 Sound SND_BRASS_RANDOM() {
83 return Sounds_from(SND_BRASS1.m_id + floor(prandom() * 3));
85 SOUND(CASINGS1, W_Sound("casings1"));
86 SOUND(CASINGS2, W_Sound("casings2"));
87 SOUND(CASINGS3, W_Sound("casings3"));
88 Sound SND_CASINGS_RANDOM() {
89 return Sounds_from(SND_CASINGS1.m_id + floor(prandom() * 3));
92 void Casing_Touch(entity this, entity toucher)
94 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
101 if (!trace_ent || trace_ent.solid == SOLID_BSP)
103 if(vdist(this.velocity, >, 50))
105 if (time >= this.nextthink)
111 s = SND_CASINGS_RANDOM();
114 s = SND_BRASS_RANDOM();
118 sound (this, CH_SHOTS, s, VOL_BASE, ATTEN_LARGE);
123 this.nextthink = time + 0.2;
126 void Casing_Damage(entity this, float thisdmg, int hittype, vector org, vector thisforce)
130 this.velocity = this.velocity + thisforce + '0 0 100';
131 UNSET_ONGROUND(this);
134 NET_HANDLE(casings, bool isNew)
136 int _state = ReadByte();
137 vector org = ReadVector();
138 vector vel = decompressShortVector(ReadShort());
140 ang_x = ReadByte() * 360 / 256;
141 ang_y = ReadByte() * 360 / 256;
142 ang_z = ReadByte() * 360 / 256;
145 Casing casing = RubbleNew("casing");
146 casing.silent = (_state & 0x80);
147 casing.state = (_state & 0x7F);
149 setorigin(casing, casing.origin);
150 casing.velocity = vel;
152 casing.drawmask = MASK_NORMAL;
154 casing.draw = Casing_Draw;
155 if (isNew) IL_PUSH(g_drawables, casing);
156 casing.velocity = casing.velocity + 2 * prandomvec();
157 casing.avelocity = '0 250 0' + 100 * prandomvec();
158 set_movetype(casing, MOVETYPE_BOUNCE);
159 settouch(casing, Casing_Touch);
160 casing.move_time = time;
161 casing.event_damage = Casing_Damage;
162 casing.solid = SOLID_TRIGGER;
164 switch (casing.state)
167 setmodel(casing, MDL_CASING_SHELL);
168 casing.cnt = time + autocvar_cl_casings_shell_time;
171 setmodel(casing, MDL_CASING_BULLET);
172 casing.cnt = time + autocvar_cl_casings_bronze_time;
176 setsize(casing, '0 0 -1', '0 0 -1');
178 RubbleLimit("casing", autocvar_cl_casings_maxcount, Casing_Delete);