sloppy (faster) gibs
[divverent/nexuiz.git] / data / 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                 Casing_Delete();
24         else
25                 R_AddEntity(self);
26 }
27
28 void Casing_Touch()
29 {
30         if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
31         {
32                 Casing_Delete();
33                 return;
34         }
35
36         if(!self.silent)
37         if(!trace_ent || trace_ent.solid == SOLID_BSP)
38         {
39                 if(vlen(self.velocity) > 50)
40                 {
41                         if(time >= self.nextthink)
42                         {
43                                 string s;
44                                 float f;
45
46                                 f = floor(prandom() * 3) + 1;
47                                 switch(self.state)
48                                 {
49                                         case 1:
50                                                 s = strcat("weapons/casings", ftos(f), ".wav");
51                                                 break;
52                                         default:
53                                                 s = strcat("weapons/brass", ftos(f), ".wav");
54                                                 break;
55                                 }
56
57                                 sound (self, CHAN_PROJECTILE, s, VOL_BASE, ATTN_NORM);
58                         }
59                 }
60         }
61
62         self.nextthink = time + 0.2;
63 }
64
65 void Casing_Damage(float thisdmg, float hittype, vector org, vector thisforce)
66 {
67         if(thisforce_z < 0)
68                 thisforce_z = 0;
69         self.move_velocity = self.move_velocity + thisforce + '0 0 100';
70         self.move_flags &~= FL_ONGROUND;
71 }
72
73 void Ent_Casing(float isNew)
74 {
75         entity casing;
76
77         casing = RubbleNew("casing");
78         casing.state = ReadByte();
79         casing.silent = (casing.state & 0x80);
80         casing.state = (casing.state & 0x7F);
81         casing.origin_x = ReadCoord();
82         casing.origin_y = ReadCoord();
83         casing.origin_z = ReadCoord();
84         casing.velocity = decompressShortVector(ReadShort());
85         casing.angles_x = ReadByte() * 360 / 256;
86         casing.angles_y = ReadByte() * 360 / 256;
87         casing.angles_z = ReadByte() * 360 / 256;
88
89         if(cvar("cl_casings") && isNew) {
90                 casing.draw = Casing_Draw;
91                 casing.move_origin = casing.origin;
92                 casing.move_velocity = casing.velocity + 2 * prandomvec();
93                 casing.move_angles = casing.angles;
94                 casing.move_avelocity = '0 250 0' + 100 * prandomvec();
95                 casing.move_movetype = MOVETYPE_BOUNCE;
96                 casing.move_touch = Casing_Touch;
97                 casing.move_time = time;
98                 casing.event_damage = Casing_Damage;
99                 casing.solid = SOLID_TRIGGER;
100
101                 switch(casing.state)
102                 {
103                         case 1:
104                                 setmodel(casing, "models/casing_shell.mdl");
105                                 casing.cnt = time + cvar("cl_casings_shell_time");
106                                 break;
107                         default:
108                                 setmodel(casing, "models/casing_bronze.mdl");
109                                 casing.cnt = time + cvar("cl_casings_bronze_time");
110                                 break;
111                 }
112
113                 setsize(casing, '0 0 -1', '0 0 -1');
114         }
115     else
116         Casing_Delete();
117
118         RubbleLimit("casing", cvar_or("cl_casings_maxcount",100), Casing_Delete);
119 }
120
121 void Casings_Precache()
122 {
123         precache_model("models/casing_shell.mdl");
124         precache_model("models/casing_bronze.mdl");
125         precache_sound("weapons/brass1.wav");
126         precache_sound("weapons/brass2.wav");
127         precache_sound("weapons/brass3.wav");
128         precache_sound("weapons/casings1.wav");
129         precache_sound("weapons/casings2.wav");
130         precache_sound("weapons/casings3.wav");
131 }