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;
18 REPLICATE(cvar_cl_casings, bool, "cl_casings");
21 void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner, .entity weaponentity)
23 entity wep = casingowner.(weaponentity);
24 vector org = casingowner.origin + casingowner.view_ofs + wep.spawnorigin.x * v_forward - wep.spawnorigin.y * v_right + wep.spawnorigin.z * v_up;
26 FOREACH_CLIENT(true, {
27 if (!(CS(it).cvar_cl_casings))
31 if (!sound_allowed(MSG_ONE, it))
32 casingtype |= 0x80; // silent
34 WriteHeader(MSG_ONE, casings);
35 WriteByte(MSG_ONE, casingtype);
36 WriteVector(MSG_ONE, org);
37 WriteShort(MSG_ONE, compressShortVector(vel)); // actually compressed velocity
38 WriteByte(MSG_ONE, ang.x * 256 / 360);
39 WriteByte(MSG_ONE, ang.y * 256 / 360);
40 WriteByte(MSG_ONE, ang.z * 256 / 360);
47 classfield(Casing) .float alpha;
48 classfield(Casing) .bool silent;
49 classfield(Casing) .int state;
50 classfield(Casing) .float cnt;
52 void Casing_Delete(entity this)
57 void Casing_Draw(entity this)
59 if (IS_ONGROUND(this))
63 //UNSET_ONGROUND(this);
67 this.alpha = bound(0, this.cnt - time, 1);
69 if (this.alpha < ALPHA_MIN_VISIBLE)
76 Movetype_Physics_MatchTicrate(this, autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy);
78 // return; // deleted by touch function
81 SOUND(BRASS1, W_Sound("brass1"));
82 SOUND(BRASS2, W_Sound("brass2"));
83 SOUND(BRASS3, W_Sound("brass3"));
84 Sound SND_BRASS_RANDOM() {
85 return REGISTRY_GET(Sounds, SND_BRASS1.m_id + floor(prandom() * 3));
87 SOUND(CASINGS1, W_Sound("casings1"));
88 SOUND(CASINGS2, W_Sound("casings2"));
89 SOUND(CASINGS3, W_Sound("casings3"));
90 Sound SND_CASINGS_RANDOM() {
91 return REGISTRY_GET(Sounds, SND_CASINGS1.m_id + floor(prandom() * 3));
94 void Casing_Touch(entity this, entity toucher)
96 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
103 if (!trace_ent || trace_ent.solid == SOLID_BSP)
105 if(vdist(this.velocity, >, 50))
107 if (time >= this.nextthink)
113 s = SND_CASINGS_RANDOM();
116 s = SND_BRASS_RANDOM();
120 sound (this, CH_SHOTS, s, VOL_BASE, ATTEN_LARGE);
125 this.nextthink = time + 0.2;
128 void Casing_Damage(entity this, float thisdmg, int hittype, vector org, vector thisforce)
132 this.velocity = this.velocity + thisforce + '0 0 100';
133 UNSET_ONGROUND(this);
136 NET_HANDLE(casings, bool isNew)
138 int _state = ReadByte();
139 vector org = ReadVector();
140 vector vel = decompressShortVector(ReadShort());
142 ang_x = ReadByte() * 360 / 256;
143 ang_y = ReadByte() * 360 / 256;
144 ang_z = ReadByte() * 360 / 256;
147 Casing casing = RubbleNew("casing");
148 casing.silent = (_state & 0x80);
149 casing.state = (_state & 0x7F);
151 setorigin(casing, casing.origin);
152 casing.velocity = vel;
154 casing.drawmask = MASK_NORMAL;
156 casing.draw = Casing_Draw;
157 if (isNew) IL_PUSH(g_drawables, casing);
158 casing.velocity = casing.velocity + 2 * prandomvec();
159 casing.avelocity = '0 250 0' + 100 * prandomvec();
160 set_movetype(casing, MOVETYPE_BOUNCE);
161 casing.bouncefactor = 0.25;
162 settouch(casing, Casing_Touch);
163 casing.move_time = time;
164 casing.event_damage = Casing_Damage;
165 casing.solid = SOLID_TRIGGER;
167 switch (casing.state)
170 setmodel(casing, MDL_CASING_SHELL);
171 casing.cnt = time + autocvar_cl_casings_shell_time;
174 setmodel(casing, MDL_CASING_BULLET);
175 casing.cnt = time + autocvar_cl_casings_bronze_time;
179 setsize(casing, '0 0 -1', '0 0 -1');
181 RubbleLimit("casing", autocvar_cl_casings_maxcount, Casing_Delete);