2 void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner);
7 #include <common/util.qh>
10 #include <common/physics/movetypes/movetypes.qh>
14 REGISTER_NET_TEMP(casings)
17 void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner)
19 .entity weaponentity = weaponentities[0]; // TODO: parameter
20 entity wep = casingowner.(weaponentity);
21 vector org = casingowner.origin + casingowner.view_ofs + wep.spawnorigin.x * v_forward - wep.spawnorigin.y * v_right + wep.spawnorigin.z * v_up;
23 if (!sound_allowed(MSG_BROADCAST, casingowner))
26 WriteHeader(MSG_ALL, casings);
27 WriteByte(MSG_ALL, casingtype);
28 WriteCoord(MSG_ALL, org.x);
29 WriteCoord(MSG_ALL, org.y);
30 WriteCoord(MSG_ALL, org.z);
31 WriteShort(MSG_ALL, compressShortVector(vel)); // actually compressed velocity
32 WriteByte(MSG_ALL, ang.x * 256 / 360);
33 WriteByte(MSG_ALL, ang.y * 256 / 360);
34 WriteByte(MSG_ALL, ang.z * 256 / 360);
40 class(Casing) .float alpha;
41 class(Casing) .bool silent;
42 class(Casing) .int state;
43 class(Casing) .float cnt;
45 void Casing_Delete(entity this)
50 void Casing_Draw(entity this)
52 if (IS_ONGROUND(this))
56 //UNSET_ONGROUND(this);
59 Movetype_Physics_MatchTicrate(this, autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy);
61 return; // deleted by touch function
64 this.alpha = bound(0, this.cnt - time, 1);
66 if (this.alpha < ALPHA_MIN_VISIBLE)
73 SOUND(BRASS1, W_Sound("brass1"));
74 SOUND(BRASS2, W_Sound("brass2"));
75 SOUND(BRASS3, W_Sound("brass3"));
76 Sound SND_BRASS_RANDOM() {
77 return Sounds_from(SND_BRASS1.m_id + floor(prandom() * 3));
79 SOUND(CASINGS1, W_Sound("casings1"));
80 SOUND(CASINGS2, W_Sound("casings2"));
81 SOUND(CASINGS3, W_Sound("casings3"));
82 Sound SND_CASINGS_RANDOM() {
83 return Sounds_from(SND_CASINGS1.m_id + floor(prandom() * 3));
86 void Casing_Touch(entity this, entity toucher)
88 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
95 if (!trace_ent || trace_ent.solid == SOLID_BSP)
97 if(vdist(this.velocity, >, 50))
99 if (time >= this.nextthink)
105 s = SND_CASINGS_RANDOM();
108 s = SND_BRASS_RANDOM();
112 sound (this, CH_SHOTS, s, VOL_BASE, ATTEN_LARGE);
117 this.nextthink = time + 0.2;
120 void Casing_Damage(entity this, float thisdmg, int hittype, vector org, vector thisforce)
124 this.velocity = this.velocity + thisforce + '0 0 100';
125 UNSET_ONGROUND(this);
128 NET_HANDLE(casings, bool isNew)
130 int _state = ReadByte();
135 vector vel = decompressShortVector(ReadShort());
137 ang_x = ReadByte() * 360 / 256;
138 ang_y = ReadByte() * 360 / 256;
139 ang_z = ReadByte() * 360 / 256;
142 if (!autocvar_cl_casings) return;
144 Casing casing = RubbleNew("casing");
145 casing.silent = (_state & 0x80);
146 casing.state = (_state & 0x7F);
148 setorigin(casing, casing.origin);
149 casing.velocity = vel;
151 casing.drawmask = MASK_NORMAL;
153 casing.draw = Casing_Draw;
154 if (isNew) IL_PUSH(g_drawables, casing);
155 casing.velocity = casing.velocity + 2 * prandomvec();
156 casing.avelocity = '0 250 0' + 100 * prandomvec();
157 casing.move_movetype = MOVETYPE_BOUNCE;
158 settouch(casing, Casing_Touch);
159 casing.move_time = time;
160 casing.event_damage = Casing_Damage;
161 casing.solid = SOLID_TRIGGER;
163 switch (casing.state)
166 setmodel(casing, MDL_CASING_SHELL);
167 casing.cnt = time + autocvar_cl_casings_shell_time;
170 setmodel(casing, MDL_CASING_BULLET);
171 casing.cnt = time + autocvar_cl_casings_bronze_time;
175 setsize(casing, '0 0 -1', '0 0 -1');
177 RubbleLimit("casing", autocvar_cl_casings_maxcount, Casing_Delete);