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