3 #include <common/util.qh>
6 #include <common/physics/movetypes/movetypes.qh>
10 REGISTER_NET_TEMP(casings)
13 void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner, .entity weaponentity)
15 entity wep = casingowner.(weaponentity);
16 vector org = casingowner.origin + casingowner.view_ofs + wep.spawnorigin.x * v_forward - wep.spawnorigin.y * v_right + wep.spawnorigin.z * v_up;
18 if (!sound_allowed(MSG_BROADCAST, casingowner))
21 WriteHeader(MSG_ALL, casings);
22 WriteByte(MSG_ALL, casingtype);
23 WriteVector(MSG_ALL, org);
24 WriteShort(MSG_ALL, compressShortVector(vel)); // actually compressed velocity
25 WriteByte(MSG_ALL, ang.x * 256 / 360);
26 WriteByte(MSG_ALL, ang.y * 256 / 360);
27 WriteByte(MSG_ALL, ang.z * 256 / 360);
33 classfield(Casing) .float alpha;
34 classfield(Casing) .bool silent;
35 classfield(Casing) .int state;
36 classfield(Casing) .float cnt;
38 void Casing_Delete(entity this)
43 void Casing_Draw(entity this)
45 if (IS_ONGROUND(this))
49 //UNSET_ONGROUND(this);
52 Movetype_Physics_MatchTicrate(this, autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy);
54 return; // deleted by touch function
57 this.alpha = bound(0, this.cnt - time, 1);
59 if (this.alpha < ALPHA_MIN_VISIBLE)
66 SOUND(BRASS1, W_Sound("brass1"));
67 SOUND(BRASS2, W_Sound("brass2"));
68 SOUND(BRASS3, W_Sound("brass3"));
69 Sound SND_BRASS_RANDOM() {
70 return Sounds_from(SND_BRASS1.m_id + floor(prandom() * 3));
72 SOUND(CASINGS1, W_Sound("casings1"));
73 SOUND(CASINGS2, W_Sound("casings2"));
74 SOUND(CASINGS3, W_Sound("casings3"));
75 Sound SND_CASINGS_RANDOM() {
76 return Sounds_from(SND_CASINGS1.m_id + floor(prandom() * 3));
79 void Casing_Touch(entity this, entity toucher)
81 if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
88 if (!trace_ent || trace_ent.solid == SOLID_BSP)
90 if(vdist(this.velocity, >, 50))
92 if (time >= this.nextthink)
98 s = SND_CASINGS_RANDOM();
101 s = SND_BRASS_RANDOM();
105 sound (this, CH_SHOTS, s, VOL_BASE, ATTEN_LARGE);
110 this.nextthink = time + 0.2;
113 void Casing_Damage(entity this, float thisdmg, int hittype, vector org, vector thisforce)
117 this.velocity = this.velocity + thisforce + '0 0 100';
118 UNSET_ONGROUND(this);
121 NET_HANDLE(casings, bool isNew)
123 int _state = ReadByte();
124 vector org = ReadVector();
125 vector vel = decompressShortVector(ReadShort());
127 ang_x = ReadByte() * 360 / 256;
128 ang_y = ReadByte() * 360 / 256;
129 ang_z = ReadByte() * 360 / 256;
132 if (!autocvar_cl_casings) return;
134 Casing casing = RubbleNew("casing");
135 casing.silent = (_state & 0x80);
136 casing.state = (_state & 0x7F);
138 setorigin(casing, casing.origin);
139 casing.velocity = vel;
141 casing.drawmask = MASK_NORMAL;
143 casing.draw = Casing_Draw;
144 if (isNew) IL_PUSH(g_drawables, casing);
145 casing.velocity = casing.velocity + 2 * prandomvec();
146 casing.avelocity = '0 250 0' + 100 * prandomvec();
147 set_movetype(casing, MOVETYPE_BOUNCE);
148 settouch(casing, Casing_Touch);
149 casing.move_time = time;
150 casing.event_damage = Casing_Damage;
151 casing.solid = SOLID_TRIGGER;
153 switch (casing.state)
156 setmodel(casing, MDL_CASING_SHELL);
157 casing.cnt = time + autocvar_cl_casings_shell_time;
160 setmodel(casing, MDL_CASING_BULLET);
161 casing.cnt = time + autocvar_cl_casings_bronze_time;
165 setsize(casing, '0 0 -1', '0 0 -1');
167 RubbleLimit("casing", autocvar_cl_casings_maxcount, Casing_Delete);