3 #include <common/replicate.qh>
4 #include <common/util.qh>
7 #include <common/physics/movetypes/movetypes.qh>
11 REGISTER_NET_TEMP(casings)
14 REPLICATE_FIELD(bool, cvar_cl_casings);
15 REPLICATE_FIELD(int, cvar_r_drawviewmodel);
16 REPLICATE(cvar_cl_casings, bool, "cl_casings");
17 REPLICATE(cvar_r_drawviewmodel, int, "r_drawviewmodel");
20 void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner, .entity weaponentity)
22 vector org = casingowner.(weaponentity).spawnorigin;
23 org = casingowner.origin + casingowner.view_ofs + org.x * v_forward - org.y * v_right + org.z * v_up;
25 FOREACH_CLIENT(true, {
26 if (!(CS_CVAR(it).cvar_cl_casings))
28 if (it == casingowner && !(CS_CVAR(it).cvar_r_drawviewmodel))
32 if (!sound_allowed(MSG_ONE, it))
33 casingtype |= 0x80; // silent
35 WriteHeader(MSG_ONE, casings);
36 WriteByte(MSG_ONE, casingtype);
37 WriteVector(MSG_ONE, org);
38 WriteShort(MSG_ONE, compressShortVector(vel)); // actually compressed velocity
39 WriteByte(MSG_ONE, ang.x * 256 / 360);
40 WriteByte(MSG_ONE, ang.y * 256 / 360);
41 WriteByte(MSG_ONE, ang.z * 256 / 360);
48 classfield(Casing) .float alpha;
49 classfield(Casing) .bool silent;
50 classfield(Casing) .int state;
51 classfield(Casing) .float cnt;
53 void Casing_Delete(entity this)
58 void Casing_Draw(entity this)
60 if (IS_ONGROUND(this))
64 //UNSET_ONGROUND(this);
68 this.alpha = bound(0, this.cnt - time, 1);
70 if (this.alpha < ALPHA_MIN_VISIBLE)
77 Movetype_Physics_MatchTicrate(this, autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy);
79 // return; // deleted by touch function
82 SOUND(BRASS1, W_Sound("brass1"));
83 SOUND(BRASS2, W_Sound("brass2"));
84 SOUND(BRASS3, W_Sound("brass3"));
85 Sound SND_BRASS_RANDOM() {
86 return REGISTRY_GET(Sounds, SND_BRASS1.m_id + floor(prandom() * 3));
88 SOUND(CASINGS1, W_Sound("casings1"));
89 SOUND(CASINGS2, W_Sound("casings2"));
90 SOUND(CASINGS3, W_Sound("casings3"));
91 Sound SND_CASINGS_RANDOM() {
92 return REGISTRY_GET(Sounds, SND_CASINGS1.m_id + floor(prandom() * 3));
95 void Casing_Touch(entity this, entity toucher)
97 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
104 if (!trace_ent || trace_ent.solid == SOLID_BSP)
106 if(vdist(this.velocity, >, 50))
108 if (time >= this.nextthink)
114 s = SND_CASINGS_RANDOM();
117 s = SND_BRASS_RANDOM();
121 sound (this, CH_SHOTS, s, VOL_BASE, ATTEN_LARGE);
126 this.nextthink = time + 0.2;
129 void Casing_Damage(entity this, float thisdmg, int hittype, vector org, vector thisforce)
133 this.velocity = this.velocity + thisforce + '0 0 100';
134 UNSET_ONGROUND(this);
137 NET_HANDLE(casings, bool isNew)
139 int _state = ReadByte();
140 vector org = ReadVector();
141 vector vel = decompressShortVector(ReadShort());
143 ang_x = ReadByte() * 360 / 256;
144 ang_y = ReadByte() * 360 / 256;
145 ang_z = ReadByte() * 360 / 256;
148 Casing casing = ListNewChildRubble(CasingsNGibs, new(casing));
149 casing.silent = (_state & 0x80);
150 casing.state = (_state & 0x7F);
152 setorigin(casing, casing.origin);
153 casing.velocity = vel;
155 casing.drawmask = MASK_NORMAL;
157 casing.draw = Casing_Draw;
158 if (isNew) IL_PUSH(g_drawables, casing);
159 casing.velocity = casing.velocity + 2 * prandomvec();
160 casing.avelocity = '0 250 0' + 100 * prandomvec();
161 set_movetype(casing, MOVETYPE_BOUNCE);
162 casing.bouncefactor = 0.25;
163 settouch(casing, Casing_Touch);
164 casing.move_time = time;
165 casing.event_damage = Casing_Damage;
166 casing.solid = SOLID_TRIGGER;
168 switch (casing.state)
171 setmodel(casing, MDL_CASING_SHELL);
172 casing.cnt = time + autocvar_cl_casings_shell_time;
175 setmodel(casing, MDL_CASING_BULLET);
176 casing.cnt = time + autocvar_cl_casings_bronze_time;
180 setsize(casing, '0 0 -1', '0 0 -1');
182 LimitedChildrenRubble(CasingsNGibs, "casing", autocvar_cl_casings_maxcount, Casing_Delete, NULL);