]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/casings.qc
Use the sound list
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / casings.qc
1 #include "../../util.qh"
2
3 #ifdef CSQC
4 #include "../../movetypes/movetypes.qh"
5 #include "../../../client/rubble.qh"
6 #endif
7
8 REGISTER_MUTATOR(casings, true);
9
10 #ifdef SVQC
11 void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner)
12 {SELFPARAM();
13     vector org = self.origin + self.view_ofs + self.weaponentity.spawnorigin.x * v_forward - self.weaponentity.spawnorigin.y * v_right + self.weaponentity.spawnorigin.z * v_up;
14
15     if (!sound_allowed(MSG_BROADCAST, casingowner))
16         casingtype |= 0x80;
17
18     WriteByte(MSG_ALL, SVC_TEMPENTITY);
19     WriteMutator(MSG_ALL, casings);
20     WriteByte(MSG_ALL, casingtype);
21     WriteCoord(MSG_ALL, org.x);
22     WriteCoord(MSG_ALL, org.y);
23     WriteCoord(MSG_ALL, org.z);
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);
28 }
29 #endif
30
31 #ifdef CSQC
32 entityclass(Casing);
33 class(Casing) .float alpha;
34 class(Casing) .bool silent;
35 class(Casing) .int state;
36 class(Casing) .float cnt;
37
38 void Casing_Delete()
39 {SELFPARAM();
40     remove(self);
41 }
42
43 void Casing_Draw()
44 {SELFPARAM();
45     if (self.move_flags & FL_ONGROUND)
46     {
47         self.move_angles_x = 0;
48         self.move_angles_z = 0;
49         self.flags &= ~FL_ONGROUND;
50     }
51
52     Movetype_Physics_MatchTicrate(autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy);
53     if (wasfreed(self))
54         return; // deleted by touch function
55
56     self.renderflags = 0;
57     self.alpha = bound(0, self.cnt - time, 1);
58
59     if (self.alpha < ALPHA_MIN_VISIBLE)
60     {
61         Casing_Delete();
62         self.drawmask = 0;
63     }
64 }
65
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[SND_BRASS1.m_id + floor(prandom() * 3)];
71 }
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[SND_CASINGS1.m_id + floor(prandom() * 3)];
77 }
78
79 void Casing_Touch()
80 {SELFPARAM();
81     if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
82     {
83         Casing_Delete();
84         return;
85     }
86
87     if (!self.silent)
88     if (!trace_ent || trace_ent.solid == SOLID_BSP)
89     {
90         if (vlen(self.velocity) > 50)
91         {
92             if (time >= self.nextthink)
93             {
94                 Sound s;
95                 switch (self.state)
96                 {
97                     case 1:
98                         s = SND_CASINGS_RANDOM();
99                         break;
100                     default:
101                         s = SND_BRASS_RANDOM();
102                         break;
103                 }
104
105                 sound (self, CH_SHOTS, s, VOL_BASE, ATTEN_LARGE);
106             }
107         }
108     }
109
110     self.nextthink = time + 0.2;
111 }
112
113 void Casing_Damage(float thisdmg, int hittype, vector org, vector thisforce)
114 {SELFPARAM();
115     if (thisforce.z < 0)
116         thisforce.z = 0;
117     self.move_velocity = self.move_velocity + thisforce + '0 0 100';
118     self.move_flags &= ~FL_ONGROUND;
119 }
120
121 MUTATOR_HOOKFUNCTION(casings, CSQC_Parse_TempEntity)
122 {
123     if (MUTATOR_RETURNVALUE) return;
124     if (!ReadMutatorEquals(mutator_argv_int_0, casings)) return;
125     return = true;
126
127     int _state = ReadByte();
128     vector org;
129     org_x = ReadCoord();
130     org_y = ReadCoord();
131     org_z = ReadCoord();
132     vector vel = decompressShortVector(ReadShort());
133     vector ang;
134     ang_x = ReadByte() * 360 / 256;
135     ang_y = ReadByte() * 360 / 256;
136     ang_z = ReadByte() * 360 / 256;
137
138     if (!autocvar_cl_casings) return;
139
140     Casing casing = RubbleNew("casing");
141     casing.silent = (_state & 0x80);
142     casing.state = (_state & 0x7F);
143     casing.origin = org;
144     setorigin(casing, casing.origin);
145     casing.velocity = vel;
146     casing.angles = ang;
147     casing.drawmask = MASK_NORMAL;
148
149     casing.draw = Casing_Draw;
150     casing.move_origin = casing.origin;
151     casing.move_velocity = casing.velocity + 2 * prandomvec();
152     casing.move_angles = casing.angles;
153     casing.move_avelocity = '0 250 0' + 100 * prandomvec();
154     casing.move_movetype = MOVETYPE_BOUNCE;
155     casing.move_touch = Casing_Touch;
156     casing.move_time = time;
157     casing.event_damage = Casing_Damage;
158     casing.solid = SOLID_TRIGGER;
159
160     switch (casing.state)
161     {
162         case 1:
163             setmodel(casing, MDL_CASING_SHELL);
164             casing.cnt = time + autocvar_cl_casings_shell_time;
165             break;
166         default:
167             setmodel(casing, MDL_CASING_BULLET);
168             casing.cnt = time + autocvar_cl_casings_bronze_time;
169             break;
170     }
171
172     setsize(casing, '0 0 -1', '0 0 -1');
173
174     RubbleLimit("casing", autocvar_cl_casings_maxcount, Casing_Delete);
175 }
176
177 #endif