Merge remote-tracking branch 'origin/divVerent/allow-override-item-model'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / casings.qc
1 .float silent;
2
3 void Casing_Delete()
4 {
5     remove(self);
6 }
7
8 void Casing_Draw()
9 {
10         if(self.move_flags & FL_ONGROUND)
11         {
12                 self.move_angles_x = 0;
13                 self.move_angles_z = 0;
14                 self.flags &~= FL_ONGROUND;
15         }
16
17         Movetype_Physics_MatchTicrate(autocvar_cl_casings_ticrate, autocvar_cl_casings_sloppy);
18
19         self.renderflags = 0;
20         self.alpha = bound(0, self.cnt - time, 1);
21
22         if(self.alpha < ALPHA_MIN_VISIBLE)
23         {
24                 Casing_Delete();
25                 self.drawmask = 0;
26         }
27 }
28
29 void Casing_Touch()
30 {
31         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
32         {
33                 Casing_Delete();
34                 return;
35         }
36
37         if(!self.silent)
38         if(!trace_ent || trace_ent.solid == SOLID_BSP)
39         {
40                 if(vlen(self.velocity) > 50)
41                 {
42                         if(time >= self.nextthink)
43                         {
44                                 string s;
45                                 float f;
46
47                                 f = floor(prandom() * 3) + 1;
48                                 switch(self.state)
49                                 {
50                                         case 1:
51                                                 s = strcat("weapons/casings", ftos(f), ".wav");
52                                                 break;
53                                         default:
54                                                 s = strcat("weapons/brass", ftos(f), ".wav");
55                                                 break;
56                                 }
57
58                                 sound (self, CH_SHOTS, s, VOL_BASE, ATTN_LARGE);
59                         }
60                 }
61         }
62
63         self.nextthink = time + 0.2;
64 }
65
66 void Casing_Damage(float thisdmg, float hittype, vector org, vector thisforce)
67 {
68         if(thisforce_z < 0)
69                 thisforce_z = 0;
70         self.move_velocity = self.move_velocity + thisforce + '0 0 100';
71         self.move_flags &~= FL_ONGROUND;
72 }
73
74 void Ent_Casing(float isNew)
75 {
76         entity casing;
77
78     casing = RubbleNew("casing");
79         casing.state = ReadByte();
80         casing.silent = (casing.state & 0x80);
81         casing.state = (casing.state & 0x7F);
82         casing.origin_x = ReadCoord();
83         casing.origin_y = ReadCoord();
84         casing.origin_z = ReadCoord();
85         casing.velocity = decompressShortVector(ReadShort());
86         casing.angles_x = ReadByte() * 360 / 256;
87         casing.angles_y = ReadByte() * 360 / 256;
88         casing.angles_z = ReadByte() * 360 / 256;
89         casing.drawmask = MASK_NORMAL;
90
91         if(autocvar_cl_casings && isNew) {
92                 casing.draw = Casing_Draw;
93                 casing.move_origin = casing.origin;
94                 casing.move_velocity = casing.velocity + 2 * prandomvec();
95                 casing.move_angles = casing.angles;
96                 casing.move_avelocity = '0 250 0' + 100 * prandomvec();
97                 casing.move_movetype = MOVETYPE_BOUNCE;
98                 casing.move_touch = Casing_Touch;
99                 casing.move_time = time;
100                 casing.event_damage = Casing_Damage;
101                 casing.solid = SOLID_TRIGGER;
102
103                 switch(casing.state)
104                 {
105                         case 1:
106                                 setmodel(casing, "models/casing_shell.mdl");
107                                 casing.cnt = time + autocvar_cl_casings_shell_time;
108                                 break;
109                         default:
110                                 setmodel(casing, "models/casing_bronze.iqm");
111                                 casing.cnt = time + autocvar_cl_casings_bronze_time;
112                                 break;
113                 }
114
115                 setsize(casing, '0 0 -1', '0 0 -1');
116         }
117     else
118         Casing_Delete();
119
120         RubbleLimit("casing", autocvar_cl_casings_maxcount, Casing_Delete);
121 }
122
123 void Casings_Precache()
124 {
125         precache_model("models/casing_shell.mdl");
126         precache_model("models/casing_bronze.iqm");
127         precache_sound("weapons/brass1.wav");
128         precache_sound("weapons/brass2.wav");
129         precache_sound("weapons/brass3.wav");
130         precache_sound("weapons/casings1.wav");
131         precache_sound("weapons/casings2.wav");
132         precache_sound("weapons/casings3.wav");
133 }