]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/effects/qc/casings.qc
Purge most of the weaponentities[0] cases
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / effects / qc / casings.qc
1 #ifdef SVQC
2 void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner, .entity weaponentity);
3 #endif
4
5 #ifdef IMPLEMENTATION
6
7 #include <common/util.qh>
8
9 #ifdef CSQC
10 #include <common/physics/movetypes/movetypes.qh>
11 #include "rubble.qh"
12 #endif
13
14 REGISTER_NET_TEMP(casings)
15
16 #ifdef SVQC
17 void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner, .entity weaponentity)
18 {
19     entity wep = casingowner.(weaponentity);
20     vector org = casingowner.origin + casingowner.view_ofs + wep.spawnorigin.x * v_forward - wep.spawnorigin.y * v_right + wep.spawnorigin.z * v_up;
21
22     if (!sound_allowed(MSG_BROADCAST, casingowner))
23         casingtype |= 0x80;
24
25     WriteHeader(MSG_ALL, casings);
26     WriteByte(MSG_ALL, casingtype);
27     WriteCoord(MSG_ALL, org.x);
28     WriteCoord(MSG_ALL, org.y);
29     WriteCoord(MSG_ALL, org.z);
30     WriteShort(MSG_ALL, compressShortVector(vel)); // actually compressed velocity
31     WriteByte(MSG_ALL, ang.x * 256 / 360);
32     WriteByte(MSG_ALL, ang.y * 256 / 360);
33     WriteByte(MSG_ALL, ang.z * 256 / 360);
34 }
35 #endif
36
37 #ifdef CSQC
38 entityclass(Casing);
39 class(Casing) .float alpha;
40 class(Casing) .bool silent;
41 class(Casing) .int state;
42 class(Casing) .float cnt;
43
44 void Casing_Delete(entity this)
45 {
46     delete(this);
47 }
48
49 void Casing_Draw(entity this)
50 {
51     if (IS_ONGROUND(this))
52     {
53         this.angles_x = 0;
54         this.angles_z = 0;
55         //UNSET_ONGROUND(this);
56     }
57
58     Movetype_Physics_MatchTicrate(this, autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy);
59     if (wasfreed(this))
60         return; // deleted by touch function
61
62     this.renderflags = 0;
63     this.alpha = bound(0, this.cnt - time, 1);
64
65     if (this.alpha < ALPHA_MIN_VISIBLE)
66     {
67         Casing_Delete(this);
68         this.drawmask = 0;
69     }
70 }
71
72 SOUND(BRASS1, W_Sound("brass1"));
73 SOUND(BRASS2, W_Sound("brass2"));
74 SOUND(BRASS3, W_Sound("brass3"));
75 Sound SND_BRASS_RANDOM() {
76     return Sounds_from(SND_BRASS1.m_id + floor(prandom() * 3));
77 }
78 SOUND(CASINGS1, W_Sound("casings1"));
79 SOUND(CASINGS2, W_Sound("casings2"));
80 SOUND(CASINGS3, W_Sound("casings3"));
81 Sound SND_CASINGS_RANDOM() {
82     return Sounds_from(SND_CASINGS1.m_id + floor(prandom() * 3));
83 }
84
85 void Casing_Touch(entity this, entity toucher)
86 {
87     if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
88     {
89         Casing_Delete(this);
90         return;
91     }
92
93     if (!this.silent)
94     if (!trace_ent || trace_ent.solid == SOLID_BSP)
95     {
96         if(vdist(this.velocity, >, 50))
97         {
98             if (time >= this.nextthink)
99             {
100                 Sound s;
101                 switch (this.state)
102                 {
103                     case 1:
104                         s = SND_CASINGS_RANDOM();
105                         break;
106                     default:
107                         s = SND_BRASS_RANDOM();
108                         break;
109                 }
110
111                 sound (this, CH_SHOTS, s, VOL_BASE, ATTEN_LARGE);
112             }
113         }
114     }
115
116     this.nextthink = time + 0.2;
117 }
118
119 void Casing_Damage(entity this, float thisdmg, int hittype, vector org, vector thisforce)
120 {
121     if (thisforce.z < 0)
122         thisforce.z = 0;
123     this.velocity = this.velocity + thisforce + '0 0 100';
124     UNSET_ONGROUND(this);
125 }
126
127 NET_HANDLE(casings, bool isNew)
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     return = true;
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     if (isNew) IL_PUSH(g_drawables, casing);
154     casing.velocity = casing.velocity + 2 * prandomvec();
155     casing.avelocity = '0 250 0' + 100 * prandomvec();
156     set_movetype(casing, MOVETYPE_BOUNCE);
157     settouch(casing, 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