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