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