]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/projectile.qc
the next batch of weapons using the new projectile code: grenade launcher, electro...
[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_ROCKET:
25                         trailparticles(self, particleeffectnum("TR_ROCKET"), oldorg, self.origin);
26                         break;
27                 case PROJECTILE_TAG:
28                         trailparticles(self, particleeffectnum("TR_VORESPIKE"), oldorg, self.origin);
29                         break;
30                 case PROJECTILE_ELECTRO_BEAM:
31                         trailparticles(self, particleeffectnum("TR_NEXUIZPLASMA"), oldorg, self.origin);
32                         break;
33                 case PROJECTILE_GRENADE:
34                         trailparticles(self, particleeffectnum("TR_KNIGHTSPIKE"), oldorg, self.origin);
35                         if(!(self.move_flags & FL_ONGROUND))
36                                 self.angles -= '750 0 0' * time;
37                         break;
38                 case PROJECTILE_GRENADE_BOUNCING:
39                         trailparticles(self, particleeffectnum("TR_KNIGHTSPIKE"), oldorg, self.origin);
40                         if(!(self.move_flags & FL_ONGROUND))
41                                 self.angles += '100 150 100' * time;
42                         break;
43                 default:
44                         break;
45         }
46
47         self.renderflags = 0;
48
49         if(self.count & 0x80 || self.iflags & IFLAG_VALID)
50                 R_AddEntity(self);
51 }
52
53 void loopsound(entity e, float ch, string samp, float vol, float attn)
54 {
55         if(csqc_flags & CSQC_FLAG_COLORCODES)
56                 sound(e, ch, samp, vol, attn);
57 }
58
59 void Ent_RemoveProjectile()
60 {
61         if(self.cnt)
62                 loopsound(self, CHAN_PAIN, "misc/null.wav", VOL_BASE, ATTN_NORM);
63 }
64
65 void Ent_Projectile()
66 {
67         float f;
68
69         InterpolateOrigin_Undo();
70
71         // projectile properties:
72         //   kind (interpolated, or clientside)
73         //
74         //   modelindex
75         //   origin
76         //   scale
77         //   if clientside:
78         //     velocity
79         //     gravity
80         //   soundindex (hardcoded list)
81         //   effects
82         //
83         // projectiles don't send angles, because they always follow the velocity
84         
85         f = ReadByte();
86         self.count = (f & 0xC0);
87         self.iflags = IFLAG_AUTOANGLES | IFLAG_ANGLES;
88         self.move_flags &~= FL_ONGROUND;
89         self.solid = SOLID_TRIGGER;
90
91         // sv_gameplayfix_delayprojectiles
92         if(!self.move_time)
93                 self.move_time = time + ticrate;
94         else
95                 self.move_time = max(self.move_time, time);
96
97         if(self.count & 0x80)
98                 InterpolateOrigin_Undo();
99
100         if(f & 1)
101         {
102                 self.origin_x = ReadCoord();
103                 self.origin_y = ReadCoord();
104                 self.origin_z = ReadCoord();
105                 if(self.count & 0x80)
106                 {
107                         self.velocity_x = ReadCoord();
108                         self.velocity_y = ReadCoord();
109                         self.velocity_z = ReadCoord();
110                         self.gravity = ReadCoord();
111
112                         self.move_origin = self.origin;
113                         self.move_velocity = self.velocity;
114                 }
115         }
116
117         if(f & 2)
118         {
119                 self.modelindex = ReadShort();
120
121                 if(f & 0x40)
122                         self.scale = ReadByte() / 16.0;
123                 else
124                         self.scale = 1;
125
126                 self.cnt = ReadByte();
127
128                 self.mins = '0 0 0';
129                 self.maxs = '0 0 0';
130                 self.move_movetype = MOVETYPE_TOSS;
131                 self.move_moveflags = MOVEFLAG_STOPONIMPACT;
132
133                 switch(self.cnt)
134                 {
135                         case PROJECTILE_ELECTRO:
136                                 // only new engines support sound moving with object
137                                 loopsound(self, CHAN_PAIN, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
138                                 self.mins = '0 0 -3';
139                                 self.maxs = '0 0 -3';
140                                 self.move_movetype = MOVETYPE_BOUNCE;
141                                 self.move_moveflags = 0;
142                                 break;
143                         case PROJECTILE_ROCKET:
144                                 loopsound(self, CHAN_PAIN, "weapons/rocket_fly.wav", VOL_BASE, ATTN_NORM);
145                                 self.mins = '-3 -3 -3';
146                                 self.maxs = '3 3 3';
147                                 break;
148                         case PROJECTILE_TAG:
149                                 loopsound(self, CHAN_PAIN, "weapons/tag_rocket_fly.wav", VOL_BASE, ATTN_NORM);
150                                 self.mins = '-2 -2 -2';
151                                 self.maxs = '2 2 2';
152                                 break;
153                         case PROJECTILE_GRENADE:
154                                 self.mins = '0 0 0';
155                                 self.maxs = '0 0 0';
156                                 break;
157                         case PROJECTILE_GRENADE_BOUNCING:
158                                 self.mins = '0 0 -3';
159                                 self.maxs = '0 0 -3';
160                                 self.move_movetype = MOVETYPE_BOUNCE;
161                                 self.move_moveflags = 0;
162                                 break;
163                         default:
164                                 break;
165                 }
166         }
167
168         if(self.count)
169                 InterpolateOrigin_Note();
170         
171         self.draw = Projectile_Draw;
172 }