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