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