]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/effects/qc/casings.qc
Merge branch 'terencehill/cl_forceplayercolors_3' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / effects / qc / casings.qc
1 #include "casings.qh"
2
3 #include <common/replicate.qh>
4 #include <common/util.qh>
5
6 #ifdef CSQC
7 #include <common/physics/movetypes/movetypes.qh>
8 #include "rubble.qh"
9 #endif
10
11 REGISTER_NET_TEMP(casings)
12
13 #if defined(SVQC)
14 .bool cvar_cl_casings;
15 #elif defined(CSQC)
16 bool cvar_cl_casings;
17 #endif
18 REPLICATE(cvar_cl_casings, bool, "cl_casings");
19
20 #ifdef SVQC
21 void SpawnCasing(vector vel, float randomvel, vector ang, vector avel, float randomavel, int casingtype, entity casingowner, .entity weaponentity)
22 {
23         entity wep = casingowner.(weaponentity);
24         vector org = casingowner.origin + casingowner.view_ofs + wep.spawnorigin.x * v_forward - wep.spawnorigin.y * v_right + wep.spawnorigin.z * v_up;
25
26         FOREACH_CLIENT(true, {
27                 if (!(CS(it).cvar_cl_casings))
28                         continue;
29
30                 msg_entity = it;
31                 if (!sound_allowed(MSG_ONE, it))
32                         casingtype |= 0x80; // silent
33
34                 WriteHeader(MSG_ONE, casings);
35                 WriteByte(MSG_ONE, casingtype);
36                 WriteVector(MSG_ONE, org);
37                 WriteShort(MSG_ONE, compressShortVector(vel)); // actually compressed velocity
38                 WriteByte(MSG_ONE, ang.x * 256 / 360);
39                 WriteByte(MSG_ONE, ang.y * 256 / 360);
40                 WriteByte(MSG_ONE, ang.z * 256 / 360);
41         });
42 }
43 #endif
44
45 #ifdef CSQC
46 entityclass(Casing);
47 classfield(Casing) .float alpha;
48 classfield(Casing) .bool silent;
49 classfield(Casing) .int state;
50 classfield(Casing) .float cnt;
51
52 void Casing_Delete(entity this)
53 {
54     delete(this);
55 }
56
57 void Casing_Draw(entity this)
58 {
59     if (IS_ONGROUND(this))
60     {
61         this.angles_x = 0;
62         this.angles_z = 0;
63         //UNSET_ONGROUND(this);
64     }
65
66     this.renderflags = 0;
67     this.alpha = bound(0, this.cnt - time, 1);
68
69     if (this.alpha < ALPHA_MIN_VISIBLE)
70     {
71         Casing_Delete(this);
72         this.drawmask = 0;
73         return;
74     }
75
76     Movetype_Physics_MatchTicrate(this, autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy);
77     //if (wasfreed(this))
78     //    return; // deleted by touch function
79 }
80
81 SOUND(BRASS1, W_Sound("brass1"));
82 SOUND(BRASS2, W_Sound("brass2"));
83 SOUND(BRASS3, W_Sound("brass3"));
84 Sound SND_BRASS_RANDOM() {
85     return REGISTRY_GET(Sounds, SND_BRASS1.m_id + floor(prandom() * 3));
86 }
87 SOUND(CASINGS1, W_Sound("casings1"));
88 SOUND(CASINGS2, W_Sound("casings2"));
89 SOUND(CASINGS3, W_Sound("casings3"));
90 Sound SND_CASINGS_RANDOM() {
91     return REGISTRY_GET(Sounds, SND_CASINGS1.m_id + floor(prandom() * 3));
92 }
93
94 void Casing_Touch(entity this, entity toucher)
95 {
96     if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
97     {
98         Casing_Delete(this);
99         return;
100     }
101
102     if (!this.silent)
103     if (!trace_ent || trace_ent.solid == SOLID_BSP)
104     {
105         if(vdist(this.velocity, >, 50))
106         {
107             if (time >= this.nextthink)
108             {
109                 Sound s;
110                 switch (this.state)
111                 {
112                     case 1:
113                         s = SND_CASINGS_RANDOM();
114                         break;
115                     default:
116                         s = SND_BRASS_RANDOM();
117                         break;
118                 }
119
120                 sound (this, CH_SHOTS, s, VOL_BASE, ATTEN_LARGE);
121             }
122         }
123     }
124
125     this.nextthink = time + 0.2;
126 }
127
128 void Casing_Damage(entity this, float thisdmg, int hittype, vector org, vector thisforce)
129 {
130     if (thisforce.z < 0)
131         thisforce.z = 0;
132     this.velocity = this.velocity + thisforce + '0 0 100';
133     UNSET_ONGROUND(this);
134 }
135
136 NET_HANDLE(casings, bool isNew)
137 {
138     int _state = ReadByte();
139     vector org = ReadVector();
140     vector vel = decompressShortVector(ReadShort());
141     vector ang;
142     ang_x = ReadByte() * 360 / 256;
143     ang_y = ReadByte() * 360 / 256;
144     ang_z = ReadByte() * 360 / 256;
145     return = true;
146
147     Casing casing = RubbleNew("casing");
148     casing.silent = (_state & 0x80);
149     casing.state = (_state & 0x7F);
150     casing.origin = org;
151     setorigin(casing, casing.origin);
152     casing.velocity = vel;
153     casing.angles = ang;
154     casing.drawmask = MASK_NORMAL;
155
156     casing.draw = Casing_Draw;
157     if (isNew) IL_PUSH(g_drawables, casing);
158     casing.velocity = casing.velocity + 2 * prandomvec();
159     casing.avelocity = '0 250 0' + 100 * prandomvec();
160     set_movetype(casing, MOVETYPE_BOUNCE);
161     casing.bouncefactor = 0.25;
162     settouch(casing, Casing_Touch);
163     casing.move_time = time;
164     casing.event_damage = Casing_Damage;
165     casing.solid = SOLID_TRIGGER;
166
167     switch (casing.state)
168     {
169         case 1:
170             setmodel(casing, MDL_CASING_SHELL);
171             casing.cnt = time + autocvar_cl_casings_shell_time;
172             break;
173         default:
174             setmodel(casing, MDL_CASING_BULLET);
175             casing.cnt = time + autocvar_cl_casings_bronze_time;
176             break;
177     }
178
179     setsize(casing, '0 0 -1', '0 0 -1');
180
181     RubbleLimit("casing", autocvar_cl_casings_maxcount, Casing_Delete);
182 }
183
184 #endif