]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/casings.qc
Merge branch 'master' into terencehill/quickmenu
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / casings.qc
1 #include "casings.qh"
2 #include "_all.qh"
3
4 #include "movetypes.qh"
5 #include "prandom.qh"
6 #include "rubble.qh"
7
8 #include "../common/util.qh"
9
10 .float cnt;
11 .float alpha;
12 .int state;
13
14 entityclass(Casing);
15 class(Casing) .bool silent;
16
17 void Casing_Delete()
18 {
19     remove(self);
20 }
21
22 void Casing_Draw()
23 {
24         if(self.move_flags & FL_ONGROUND)
25         {
26                 self.move_angles_x = 0;
27                 self.move_angles_z = 0;
28                 self.flags &= ~FL_ONGROUND;
29         }
30
31         Movetype_Physics_MatchTicrate(autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy);
32         if(wasfreed(self))
33                 return; // deleted by touch function
34
35         self.renderflags = 0;
36         self.alpha = bound(0, self.cnt - time, 1);
37
38         if(self.alpha < ALPHA_MIN_VISIBLE)
39         {
40                 Casing_Delete();
41                 self.drawmask = 0;
42         }
43 }
44
45 void Casing_Touch()
46 {
47         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
48         {
49                 Casing_Delete();
50                 return;
51         }
52
53         if(!self.silent)
54         if(!trace_ent || trace_ent.solid == SOLID_BSP)
55         {
56                 if(vlen(self.velocity) > 50)
57                 {
58                         if(time >= self.nextthink)
59                         {
60                                 string s;
61                                 int f = floor(prandom() * 3) + 1;
62
63                                 switch(self.state)
64                                 {
65                                         case 1:
66                                                 s = strcat("weapons/casings", itos(f), ".wav");
67                                                 break;
68                                         default:
69                                                 s = strcat("weapons/brass", itos(f), ".wav");
70                                                 break;
71                                 }
72
73                                 sound (self, CH_SHOTS, s, VOL_BASE, ATTEN_LARGE);
74                         }
75                 }
76         }
77
78         self.nextthink = time + 0.2;
79 }
80
81 void Casing_Damage(float thisdmg, int hittype, vector org, vector thisforce)
82 {
83         if(thisforce.z < 0)
84                 thisforce.z = 0;
85         self.move_velocity = self.move_velocity + thisforce + '0 0 100';
86         self.move_flags &= ~FL_ONGROUND;
87 }
88
89 void Ent_Casing(float isNew)
90 {
91         entity casing;
92
93         casing = RubbleNew("casing");
94         casing.state = ReadByte();
95         casing.silent = (casing.state & 0x80);
96         casing.state = (casing.state & 0x7F);
97         casing.origin_x = ReadCoord();
98         casing.origin_y = ReadCoord();
99         casing.origin_z = ReadCoord();
100         setorigin(casing, casing.origin);
101         casing.velocity = decompressShortVector(ReadShort());
102         casing.angles_x = ReadByte() * 360 / 256;
103         casing.angles_y = ReadByte() * 360 / 256;
104         casing.angles_z = ReadByte() * 360 / 256;
105         casing.drawmask = MASK_NORMAL;
106
107         if(autocvar_cl_casings && isNew) {
108                 casing.draw = Casing_Draw;
109                 casing.move_origin = casing.origin;
110                 casing.move_velocity = casing.velocity + 2 * prandomvec();
111                 casing.move_angles = casing.angles;
112                 casing.move_avelocity = '0 250 0' + 100 * prandomvec();
113                 casing.move_movetype = MOVETYPE_BOUNCE;
114                 casing.move_touch = Casing_Touch;
115                 casing.move_time = time;
116                 casing.event_damage = Casing_Damage;
117                 casing.solid = SOLID_TRIGGER;
118
119                 switch(casing.state)
120                 {
121                         case 1:
122                                 setmodel(casing, "models/casing_shell.mdl");
123                                 casing.cnt = time + autocvar_cl_casings_shell_time;
124                                 break;
125                         default:
126                                 setmodel(casing, "models/casing_bronze.iqm");
127                                 casing.cnt = time + autocvar_cl_casings_bronze_time;
128                                 break;
129                 }
130
131                 setsize(casing, '0 0 -1', '0 0 -1');
132
133                 RubbleLimit("casing", autocvar_cl_casings_maxcount, Casing_Delete);
134         }
135         else
136         {
137                 entity oldself = self;
138                 self = casing;
139                 Casing_Delete(); // yes, this IS stupid, but I don't need to duplicate all the read* stuff then
140                 self = oldself;
141         }
142 }
143
144 void Casings_Precache()
145 {
146         precache_model("models/casing_shell.mdl");
147         precache_model("models/casing_bronze.iqm");
148         precache_sound("weapons/brass1.wav");
149         precache_sound("weapons/brass2.wav");
150         precache_sound("weapons/brass3.wav");
151         precache_sound("weapons/casings1.wav");
152         precache_sound("weapons/casings2.wav");
153         precache_sound("weapons/casings3.wav");
154 }