]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/projectile.qc
fix some projectile issues, and send less bytes per csqc projectile
[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 & 0x80);
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.cnt = ReadByte();
120
121                 switch(self.cnt)
122                 {
123                         case PROJECTILE_ELECTRO: setmodel(self, "models/ebomb.mdl"); break;
124                         case PROJECTILE_ROCKET: setmodel(self, "models/rocket.md3"); break;
125                         case PROJECTILE_TAG: setmodel(self, "models/laser.mdl"); break;
126                         case PROJECTILE_BULLET: setmodel(self, "models/tracer.mdl"); break;
127                         case PROJECTILE_CRYLINK: setmodel(self, "models/plasmatrail.mdl"); break;
128                         case PROJECTILE_ELECTRO_BEAM: setmodel(self, "models/elaser.mdl"); break;
129                         case PROJECTILE_GRENADE: setmodel(self, "models/grenademodel.md3"); break;
130                         case PROJECTILE_GRENADE_BOUNCING: setmodel(self, "models/grenademodel.md3"); break;
131                         case PROJECTILE_LASER: setmodel(self, "models/laser.mdl"); break;
132                         case PROJECTILE_HLAC: setmodel(self, "models/hlac_bullet.md3"); break;
133                         default:
134                                 error("Received invalid CSQC projectile, can't work with this!");
135                                 break;
136                 }
137
138                 self.scale = 1;
139                 self.mins = '0 0 0';
140                 self.maxs = '0 0 0';
141                 self.move_movetype = MOVETYPE_TOSS;
142                 self.move_moveflags = MOVEFLAG_STOPONIMPACT;
143
144                 switch(self.cnt)
145                 {
146                         case PROJECTILE_ELECTRO:
147                                 // only new engines support sound moving with object
148                                 loopsound(self, CHAN_PAIN, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
149                                 self.mins = '0 0 -3';
150                                 self.maxs = '0 0 -3';
151                                 self.move_movetype = MOVETYPE_BOUNCE;
152                                 self.move_moveflags = 0;
153                                 break;
154                         case PROJECTILE_ROCKET:
155                                 loopsound(self, CHAN_PAIN, "weapons/rocket_fly.wav", VOL_BASE, ATTN_NORM);
156                                 self.mins = '-3 -3 -3';
157                                 self.maxs = '3 3 3';
158                                 break;
159                         case PROJECTILE_TAG:
160                                 loopsound(self, CHAN_PAIN, "weapons/tag_rocket_fly.wav", VOL_BASE, ATTN_NORM);
161                                 self.mins = '-2 -2 -2';
162                                 self.maxs = '2 2 2';
163                                 break;
164                         case PROJECTILE_GRENADE:
165                                 self.mins = '0 0 0';
166                                 self.maxs = '0 0 0';
167                                 break;
168                         case PROJECTILE_GRENADE_BOUNCING:
169                                 self.mins = '0 0 -3';
170                                 self.maxs = '0 0 -3';
171                                 self.move_movetype = MOVETYPE_BOUNCE;
172                                 self.move_moveflags = 0;
173                                 break;
174                         default:
175                                 break;
176                 }
177         }
178
179         if(self.count)
180                 InterpolateOrigin_Note();
181         
182         self.draw = Projectile_Draw;
183 }
184
185 void Projectile_Precache()
186 {
187         precache_model("models/ebomb.mdl");
188         precache_model("models/rocket.md3");
189         precache_model("models/laser.mdl");
190         precache_model("models/tracer.mdl");
191         precache_model("models/plasmatrail.mdl");
192         precache_model("models/elaser.mdl");
193         precache_model("models/grenademodel.md3");
194         precache_model("models/grenademodel.md3");
195         precache_model("models/laser.mdl");
196         precache_model("models/hlac_bullet.md3");
197 }