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