3 #include <common/replicate.qh>
4 #include <common/util.qh>
7 #include <common/physics/movetypes/movetypes.qh>
11 REGISTER_NET_TEMP(casings)
14 .bool cvar_cl_casings;
15 .int cvar_r_drawviewmodel;
18 int cvar_r_drawviewmodel;
20 REPLICATE(cvar_cl_casings, bool, "cl_casings");
21 REPLICATE(cvar_r_drawviewmodel, int, "r_drawviewmodel");
24 void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner, .entity weaponentity)
26 vector org = casingowner.(weaponentity).spawnorigin;
27 org = casingowner.origin + casingowner.view_ofs + org.x * v_forward - org.y * v_right + org.z * v_up;
29 FOREACH_CLIENT(true, {
30 if (!(CS(it).cvar_cl_casings))
32 if (it == casingowner && !(CS(it).cvar_r_drawviewmodel))
36 if (!sound_allowed(MSG_ONE, it))
37 casingtype |= 0x80; // silent
39 WriteHeader(MSG_ONE, casings);
40 WriteByte(MSG_ONE, casingtype);
41 WriteVector(MSG_ONE, org);
42 WriteShort(MSG_ONE, compressShortVector(vel)); // actually compressed velocity
43 WriteByte(MSG_ONE, ang.x * 256 / 360);
44 WriteByte(MSG_ONE, ang.y * 256 / 360);
45 WriteByte(MSG_ONE, ang.z * 256 / 360);
52 classfield(Casing) .float alpha;
53 classfield(Casing) .bool silent;
54 classfield(Casing) .int state;
55 classfield(Casing) .float cnt;
57 void Casing_Delete(entity this)
62 void Casing_Draw(entity this)
64 if (IS_ONGROUND(this))
68 //UNSET_ONGROUND(this);
72 this.alpha = bound(0, this.cnt - time, 1);
74 if (this.alpha < ALPHA_MIN_VISIBLE)
81 Movetype_Physics_MatchTicrate(this, autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy);
83 // return; // deleted by touch function
86 SOUND(BRASS1, W_Sound("brass1"));
87 SOUND(BRASS2, W_Sound("brass2"));
88 SOUND(BRASS3, W_Sound("brass3"));
89 Sound SND_BRASS_RANDOM() {
90 return REGISTRY_GET(Sounds, SND_BRASS1.m_id + floor(prandom() * 3));
92 SOUND(CASINGS1, W_Sound("casings1"));
93 SOUND(CASINGS2, W_Sound("casings2"));
94 SOUND(CASINGS3, W_Sound("casings3"));
95 Sound SND_CASINGS_RANDOM() {
96 return REGISTRY_GET(Sounds, SND_CASINGS1.m_id + floor(prandom() * 3));
99 void Casing_Touch(entity this, entity toucher)
101 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
108 if (!trace_ent || trace_ent.solid == SOLID_BSP)
110 if(vdist(this.velocity, >, 50))
112 if (time >= this.nextthink)
118 s = SND_CASINGS_RANDOM();
121 s = SND_BRASS_RANDOM();
125 sound (this, CH_SHOTS, s, VOL_BASE, ATTEN_LARGE);
130 this.nextthink = time + 0.2;
133 void Casing_Damage(entity this, float thisdmg, int hittype, vector org, vector thisforce)
137 this.velocity = this.velocity + thisforce + '0 0 100';
138 UNSET_ONGROUND(this);
141 NET_HANDLE(casings, bool isNew)
143 int _state = ReadByte();
144 vector org = ReadVector();
145 vector vel = decompressShortVector(ReadShort());
147 ang_x = ReadByte() * 360 / 256;
148 ang_y = ReadByte() * 360 / 256;
149 ang_z = ReadByte() * 360 / 256;
152 Casing casing = RubbleNew(new(casing));
153 casing.silent = (_state & 0x80);
154 casing.state = (_state & 0x7F);
156 setorigin(casing, casing.origin);
157 casing.velocity = vel;
159 casing.drawmask = MASK_NORMAL;
161 casing.draw = Casing_Draw;
162 if (isNew) IL_PUSH(g_drawables, casing);
163 casing.velocity = casing.velocity + 2 * prandomvec();
164 casing.avelocity = '0 250 0' + 100 * prandomvec();
165 set_movetype(casing, MOVETYPE_BOUNCE);
166 casing.bouncefactor = 0.25;
167 settouch(casing, Casing_Touch);
168 casing.move_time = time;
169 casing.event_damage = Casing_Damage;
170 casing.solid = SOLID_TRIGGER;
172 switch (casing.state)
175 setmodel(casing, MDL_CASING_SHELL);
176 casing.cnt = time + autocvar_cl_casings_shell_time;
179 setmodel(casing, MDL_CASING_BULLET);
180 casing.cnt = time + autocvar_cl_casings_bronze_time;
184 setsize(casing, '0 0 -1', '0 0 -1');
186 RubbleLimit("casing", autocvar_cl_casings_maxcount, Casing_Delete);