]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/projectile.qc
csqcprojectiles: make them more readable; make turrets use them too when they fire...
[divverent/nexuiz.git] / data / qcsrc / client / projectile.qc
1 .float itime;
2 .float count; // set if clientside projectile
3 .float cnt; // sound index
4 .float gravity;
5
6 void Projectile_Draw()
7 {
8         float dt;
9         vector oldorg, org;
10
11         oldorg = self.origin;
12
13         if(self.count & 0x80)
14         {
15                 dt = time - self.itime;
16                 self.velocity_z -= dt * self.gravity * getstatf(242); // STAT_MOVEVARS_GRAVITY
17                 org = self.origin + dt * self.velocity;
18                 self.itime = time;
19                 tracebox(self.origin, self.mins, self.maxs, org, MOVE_NORMAL, self);
20                 self.origin = trace_endpos;
21                 self.angles = vectoangles(self.velocity);
22         }
23         else
24         {
25                 InterpolateOrigin_Do();
26         }
27
28         switch(self.cnt)
29         {
30                 case PROJECTILE_ELECTRO:
31                         break; // electro uses no trail
32                 case PROJECTILE_ROCKET:
33                         trailparticles(self, particleeffectnum("TR_ROCKET"), oldorg, self.origin); // rocket
34                         break;
35                 case PROJECTILE_TAG:
36                         trailparticles(self, particleeffectnum("TR_VORESPIKE"), oldorg, self.origin); // seeker
37                         break;
38                 default:
39                         break;
40         }
41
42         self.renderflags = 0;
43
44         if(self.count & 0x80 || self.iflags & IFLAG_VALID)
45                 R_AddEntity(self);
46 }
47
48 void Ent_RemoveProjectile()
49 {
50         if(csqc_flags & CSQC_FLAG_COLORCODES)
51                 if(self.cnt)
52                         sound(self, CHAN_PAIN, "misc/null.wav", VOL_BASE, ATTN_NORM);
53 }
54
55 void Ent_Projectile()
56 {
57         float f;
58         float sz;
59
60         InterpolateOrigin_Undo();
61
62         // projectile properties:
63         //   kind (interpolated, or clientside)
64         //
65         //   modelindex
66         //   origin
67         //   scale
68         //   if clientside:
69         //     velocity
70         //     gravity
71         //   soundindex (hardcoded list)
72         //   effects
73         //
74         // projectiles don't send angles, because they always follow the velocity
75         
76         f = ReadByte();
77         self.count = (f & 0xC0);
78         self.iflags = IFLAG_AUTOANGLES | IFLAG_ANGLES;
79
80         if(self.count & 0x80)
81                 InterpolateOrigin_Undo();
82
83         if(f & 1)
84         {
85                 self.origin_x = ReadCoord();
86                 self.origin_y = ReadCoord();
87                 self.origin_z = ReadCoord();
88                 if(self.count & 0x80)
89                 {
90                         self.itime = time;
91                         self.velocity_x = ReadCoord();
92                         self.velocity_y = ReadCoord();
93                         self.velocity_z = ReadCoord();
94                         self.gravity = ReadCoord();
95                 }
96         }
97
98         if(f & 2)
99         {
100                 self.modelindex = ReadShort();
101                 if(f & 0x40)
102                 {
103                         self.scale = ReadByte() / 16.0;
104                         self.effects = ReadShort();
105                         self.effects |= 65536 * ReadByte();
106                 }
107                 else
108                 {
109                         self.scale = 1;
110                         self.effects = 0;
111                 }
112
113                 self.cnt = ReadShort();
114
115                 if(csqc_flags & CSQC_FLAG_COLORCODES)
116                         switch(self.cnt)
117                         {
118                                 case PROJECTILE_ELECTRO:
119                                         // only new engines support sound moving with object
120                                         sound(self, CHAN_PAIN, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
121                                         break;
122                                 case PROJECTILE_ROCKET:
123                                         sound(self, CHAN_PAIN, "weapons/rocket_fly.wav", VOL_BASE, ATTN_NORM);
124                                         break;
125                                 case PROJECTILE_TAG:
126                                         sound(self, CHAN_PAIN, "weapons/tag_rocket_fly.wav", VOL_BASE, ATTN_NORM);
127                                         break;
128                                 default:
129                                         break;
130                         }
131
132                 sz = ReadByte();
133                 switch(sz)
134                 {
135                         case 0:
136                         default:
137                                 self.mins = self.maxs = '0 0 0';
138                                 break;
139                 }
140         }
141
142         if(self.count)
143                 InterpolateOrigin_Note();
144         
145         self.draw = Projectile_Draw;
146 }