]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/nexball.qc
make the radar change potentially usable for other gamemodes, and less expensive too
[divverent/nexuiz.git] / data / qcsrc / server / nexball.qc
1 //EF_BRIGHTFIELD|EF_BRIGHTLIGHT|EF_DIMLIGHT|EF_BLUE|EF_RED|EF_FLAME
2 #define BALL_EFFECTMASK 1229
3 #define BALL_MINS '-16 -16 -16'  // The model is 24*24*24
4 #define BALL_MAXS '16 16 16'
5 #define BALL_ATTACHORG '3 0 16'
6 #define BALL_SPRITECOLOR '.91 .85 .62'
7 #define BALL_FOOT   1
8 #define BALL_BASKET 2
9 //spawnflags
10 #define GOAL_TOUCHPLAYER 1
11 //goal types
12 #define GOAL_FAULT -1
13 #define GOAL_OUT -2
14
15 #define CVTOV(s) s = cvar( #s )
16
17 float g_nexball_football_boost_forward;
18 float g_nexball_football_boost_up;
19 float g_nexball_football_physics;
20 float g_nexball_delay_idle;
21 float g_nexball_basketball_delay_hold;
22 float g_nexball_basketball_delay_hold_forteam;
23 float g_nexball_basketball_effects_default;
24 float g_nexball_basketball_teamsteal;
25 float balls;
26 float ball_scale;
27
28 .float teamtime;
29
30 void nb_delayedinit();
31 void nb_init() // Called early (worldspawn stage)
32 {
33         CVTOV(g_nexball_meter_period); //sent with the client init entity
34         if (g_nexball_meter_period <= 0)
35                 g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
36         g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
37         addstat(STAT_NB_METERSTART, AS_FLOAT, metertime);
38
39         // General settings
40         CVTOV(g_nexball_football_boost_forward);   //100
41         CVTOV(g_nexball_football_boost_up);        //200
42         CVTOV(g_nexball_delay_idle);               //10
43         CVTOV(g_nexball_football_physics);         //0
44
45         radar_showennemies = cvar("g_nexball_radar_showallplayers");
46
47         InitializeEntity(world, nb_delayedinit, INITPRIO_GAMETYPE);
48 }
49
50 void ResetBall();
51
52 void LogNB(string mode, entity actor)
53 {
54         string s;
55         if(!cvar("sv_eventlog"))
56                 return;
57         s = strcat(":nexball:", mode);
58         if(actor != world)
59                 s = strcat(s, ":", ftos(actor.playerid));
60         GameLogEcho(s);
61 }
62
63 void ball_restart (void)
64 {
65         if(self.owner)
66                 DropBall(self, self.owner.origin, '0 0 0');
67         ResetBall();
68 }
69
70 void nexball_setstatus (void)
71 {
72         local entity oldself;
73         if (!g_nexball)
74                 return;
75         if (self.ballcarried)
76         {
77                 if (self.ballcarried.teamtime && (self.ballcarried.teamtime < time))
78                 {
79                         bprint("The ", ColoredTeamName(self.team), " held the ball for too long.\n");
80                         oldself = self;
81                         self = self.ballcarried;
82                         DropBall(self, self.owner.origin, '0 0 0');
83                         ResetBall();
84                         self = oldself;
85                 } else
86                         self.items |= IT_KEY1;
87         }
88 }
89
90 void relocate_nexball (void)
91 {
92         tracebox(self.origin, BALL_MINS, BALL_MAXS, self.origin, TRUE, self);
93         if (trace_startsolid)
94         {
95                 vector o;
96                 o = self.origin;
97                 if(!move_out_of_solid(self))
98                         objerror("could not get out of solid at all!");
99                 print("^1NOTE: this map needs FIXING. ", self.classname, " at ", vtos(o - '0 0 1'));
100                 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
101                 print(" ", ftos(self.origin_y - o_y));
102                 print(" ", ftos(self.origin_z - o_z), "'\n");
103                 self.origin = o;
104         }
105 }
106
107 void basketball_touch();
108 void football_touch();
109
110 void DropOwner (void)
111 {
112         local entity ownr;
113         ownr = self.owner;
114         DropBall(self, ownr.origin, ownr.velocity);
115         makevectors(ownr.v_angle_y * '0 1 0');
116         ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
117         ownr.flags &~= FL_ONGROUND;
118 }
119
120 void GiveBall (entity plyr, entity ball)
121 {
122         local entity ownr;
123
124         if ((ownr = ball.owner))
125         {
126                 ownr.effects &~= g_nexball_basketball_effects_default;
127                 ownr.ballcarried = world;
128                 if (ownr.metertime)
129                 {
130                         ownr.metertime = 0;
131                         ownr.weaponentity.state = WS_READY;
132                 }
133         }
134
135         setattachment(ball, plyr, "");
136         setorigin(ball, BALL_ATTACHORG);
137
138         if (ball.team != plyr.team)
139                 ball.teamtime = time + g_nexball_basketball_delay_hold_forteam;
140
141         ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
142         ball.team = plyr.team;
143         plyr.ballcarried = ball;
144         ball.dropperid = plyr.playerid;
145
146         plyr.effects |= g_nexball_basketball_effects_default;
147         ball.effects &~= g_nexball_basketball_effects_default;
148
149         ball.velocity = '0 0 0';
150         ball.movetype = MOVETYPE_NONE;
151         ball.touch = SUB_Null;
152         ball.effects |= EF_NOSHADOW;
153         ball.scale = 1; // scale down.
154
155         ball.waypointsprite_attachedforcarrier.exteriormodeltoclient = plyr;
156
157         if (g_nexball_basketball_delay_hold)
158         {
159                 ball.think = DropOwner;
160                 ball.nextthink = time + g_nexball_basketball_delay_hold;
161         }
162 }
163
164 void DropBall (entity ball, vector org, vector vel)
165 {
166         ball.effects |= g_nexball_basketball_effects_default;
167         ball.effects &~= EF_NOSHADOW;
168         ball.owner.effects &~= g_nexball_basketball_effects_default;
169
170         setattachment(ball, world, "");
171         setorigin (ball, org);
172         ball.movetype = MOVETYPE_BOUNCE;
173         ball.flags &~= FL_ONGROUND;
174         ball.scale = ball_scale;
175         ball.velocity = vel;
176         ball.ctf_droptime = time;
177         ball.touch = basketball_touch;
178         ball.think = ResetBall;
179         ball.nextthink = min(time + g_nexball_delay_idle, ball.teamtime);
180
181         if (ball.owner.metertime)
182         {
183                 ball.owner.metertime = 0;
184                 ball.owner.weaponentity.state = WS_READY;
185         }
186
187         ball.waypointsprite_attachedforcarrier.exteriormodeltoclient = world;
188
189         ball.owner.ballcarried = world;
190         ball.owner = world;
191 }
192
193 void InitBall (void)
194 {
195         if (gameover) return;
196         self.flags &~= FL_ONGROUND;
197         self.movetype = MOVETYPE_BOUNCE;
198         if (self.classname == "nexball_basketball")
199                 self.touch = basketball_touch;
200         else if (self.classname == "nexball_football")
201                 self.touch = football_touch;
202         self.cnt = 0;
203         self.think = ResetBall;
204         self.nextthink = time + g_nexball_delay_idle + 3;
205         self.teamtime = 0;
206         self.pusher = world;
207         self.team = FALSE;
208         sound (self, CHAN_PROJECTILE, self.noise1, VOL_BASE, ATTN_NORM);
209         WaypointSprite_Ping(self.waypointsprite_attachedforcarrier);
210         LogNB("init", world);
211 }
212
213 void ResetBall (void)
214 {
215         if (self.cnt < 2) { // step 1
216                 if (time == self.teamtime)
217                         bprint("The ", ColoredTeamName(self.team), " held the ball for too long.\n");
218                 self.touch = SUB_Null;
219                 self.movetype = MOVETYPE_NOCLIP;
220                 self.velocity = '0 0 0'; // just in case?
221                 if(!self.cnt)
222                         LogNB("resetidle", world);
223                 self.cnt = 2;
224                 self.nextthink = time;
225         } else if (self.cnt < 4) { // step 2 and 3
226 //              dprint("Step ", ftos(self.cnt), ": Calculated velocity: ", vtos(self.spawnorigin - self.origin), ", time: ", ftos(time), "\n");
227                 self.velocity = (self.spawnorigin - self.origin) * (self.cnt - 1); // 1 or 0.5 second movement
228                 self.nextthink = time + 0.5;
229                 self.cnt += 1;
230         } else { // step 4
231 //              dprint("Step 4: time: ", ftos(time), "\n");
232                 if (vlen(self.origin - self.spawnorigin) > 10) // should not happen anymore
233                         dprint("The ball moved too far away from its spawn origin.\nOffset: ",
234                                vtos(self.origin - self.spawnorigin), " Velocity: ", vtos(self.velocity), "\n");
235                 self.velocity = '0 0 0';
236                 setorigin(self, self.spawnorigin); // make sure it's positioned correctly anyway
237                 self.movetype = MOVETYPE_NONE;
238                 self.think = InitBall;
239                 self.nextthink = max(time, game_starttime) + cvar("g_nexball_delay_start");
240         }
241 }
242
243 void football_touch (void)
244 {
245         if (other.solid == SOLID_BSP) {
246                 if (time > self.lastground + 0.1)
247                 {
248                         sound (self, CHAN_PROJECTILE, self.noise, VOL_BASE, ATTN_NORM);
249                         self.lastground = time;
250                 }
251                 if (vlen(self.velocity) && !self.cnt)
252                         self.nextthink = time + g_nexball_delay_idle;
253                 return;
254         }
255         if (other.classname != "player")
256                 return;
257         if (other.health < 1)
258                 return;
259         if (!self.cnt)
260                 self.nextthink = time + g_nexball_delay_idle;
261
262         self.pusher = other;
263         self.team = other.team;
264
265         if (g_nexball_football_physics == -1) { // MrBougo try 1, before decompiling Rev's original
266                 if (vlen(other.velocity))
267                         self.velocity = other.velocity * 1.5 + '0 0 1' * g_nexball_football_boost_up;
268         } else if (g_nexball_football_physics == 1) { // MrBougo's modded Rev style: partially independant of the height of the aiming point
269                 makevectors(other.v_angle);
270                 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + '0 0 1' * g_nexball_football_boost_up;
271         } else if (g_nexball_football_physics == 2) { // 2nd mod try: totally independant. Really playable!
272                 makevectors(other.v_angle_y * '0 1 0');
273                 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + v_up * g_nexball_football_boost_up;
274         } else { // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
275                 makevectors(other.v_angle);
276                 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + v_up * g_nexball_football_boost_up;
277         }
278         self.avelocity = -250 * v_forward;  // maybe there is a way to make it look better?
279 }
280
281 void basketball_touch (void)
282 {
283         if (other.ballcarried)
284         {
285                 football_touch();
286                 return;
287         }
288         if (!self.cnt && other.classname == "player" && (other.playerid != self.dropperid || time > self.ctf_droptime + cvar("g_nexball_delay_collect"))) {
289                 if (other.health <= 0)
290                         return;
291                 LogNB("caught", other);
292                 GiveBall(other, self);
293         } else if (other.solid == SOLID_BSP) {
294                 sound (self, CHAN_PROJECTILE, self.noise, VOL_BASE, ATTN_NORM);
295                 if (vlen(self.velocity) && !self.cnt)
296                         self.nextthink = min(time + g_nexball_delay_idle, self.teamtime);
297         }
298 }
299
300 void GoalTouch (void)
301 {
302         entity ball;
303         float isclient, pscore;
304         string pname;
305
306         if (gameover) return;
307         if ((self.spawnflags & GOAL_TOUCHPLAYER) && other.ballcarried)
308                 ball = other.ballcarried;
309         else
310                 ball = other;
311         if (ball.classname != "nexball_basketball")
312         if (ball.classname != "nexball_football")
313                 return;
314         if ((!ball.pusher && self.team != GOAL_OUT) || ball.cnt)
315                 return;
316         EXACTTRIGGER_TOUCH;
317
318
319         if((isclient = ball.pusher.flags & FL_CLIENT))
320                 pname = ball.pusher.netname;
321         else
322                 pname = "Someone (?)";
323
324         if        (ball.team == self.team) //owngoal (regular goals)
325         {
326                 LogNB("owngoal", ball.pusher);
327                 bprint("Boo! ", pname, "^7 scored a goal against his own team!\n");
328                 pscore = -1;
329         } else if (self.team == GOAL_FAULT) {
330                 LogNB("fault", ball.pusher);
331                 bprint(ColoredTeamName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
332                 pscore = -1;
333         } else if (self.team == GOAL_OUT) {
334                 LogNB("out", ball.pusher);
335                 if ((self.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
336                         bprint(pname, "^7 went out of bounds.\n");
337                 else
338                         bprint("The ball was returned.\n");
339                 pscore = 0;
340         } else {                           //score
341                 LogNB(strcat("goal:", ftos(self.team)), ball.pusher);
342                 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", ColoredTeamName(ball.team), ".\n");
343                 pscore = 1;
344         }
345
346         sound (ball, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
347
348         if(ball.team && pscore)
349                 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
350         if (isclient && pscore > 0)
351                 PlayerScore_Add(ball.pusher, SP_NEXBALL_GOALS, pscore);
352         else if (isclient && pscore < 0)
353                 PlayerScore_Add(ball.pusher, SP_NEXBALL_FAULTS, pscore);
354
355         if (ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
356                 DropBall(ball, ball.owner.origin, ball.owner.velocity);
357
358         WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
359
360         ball.cnt = 1;
361         ball.think = ResetBall;
362         if (ball.classname == "nexball_basketball")
363                 ball.touch = football_touch; // better than SUB_Null: football control until the ball gets reset
364         ball.nextthink = time + cvar("g_nexball_delay_goal") * (self.team != GOAL_OUT);
365 }
366
367 //=======================//
368 //       team ents       //
369 //=======================//
370 void spawnfunc_nexball_team (void)
371 {
372         if(!g_nexball) { remove(self); return; }
373         self.team = self.cnt + 1;
374 }
375
376 void nb_spawnteam (string teamname, float teamcolor)
377 {
378         dprint("^2spawned team ", teamname, "\n");
379         local entity e;
380         e = spawn();
381         e.classname = "nexball_team";
382         e.netname = teamname;
383         e.cnt = teamcolor;
384         e.team = e.cnt + 1;
385 };
386
387 void nb_spawnteams (void)
388 {
389         float t_r, t_b, t_y, t_p;
390         entity e;
391         for(e = world; (e = find(e, classname, "nexball_goal")); )
392         {
393                 switch(e.team)
394                 {
395                         case COLOR_TEAM1: if(!t_r) { nb_spawnteam ("Red", e.team-1)   ; t_r = 1; } break;
396                         case COLOR_TEAM2: if(!t_b) { nb_spawnteam ("Blue", e.team-1)  ; t_b = 1; } break;
397                         case COLOR_TEAM3: if(!t_y) { nb_spawnteam ("Yellow", e.team-1); t_y = 1; } break;
398                         case COLOR_TEAM4: if(!t_p) { nb_spawnteam ("Pink", e.team-1)  ; t_p = 1; } break;
399                 }
400         }
401 }
402
403 void nb_delayedinit (void)
404 {
405         if (find(world, classname, "nexball_team") == world)
406                 nb_spawnteams();
407         ScoreRules_nexball();
408 }
409
410
411 //=======================//
412 //      spawnfuncs       //
413 //=======================//
414
415 void SpawnBall (void)
416 {
417         if(!g_nexball) { remove(self); return; }
418
419 //      balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
420
421         if (!self.model) {
422                 self.model = "models/nexball/ball.md3";
423                 self.scale = 1.3;
424         }
425
426         precache_model (self.model);
427         setmodel (self, self.model);
428         setsize (self, BALL_MINS, BALL_MAXS);
429         ball_scale = self.scale;
430
431         relocate_nexball();
432         self.spawnorigin = self.origin;
433
434         self.effects = self.effects | EF_LOWPRECISION;
435
436         if (cvar(strcat("g_", self.classname, "_trail"))) //nexball_basketball :p
437         {
438                 self.glow_color = cvar("g_nexball_trail_color");
439                 self.glow_trail = TRUE;
440         }
441
442         self.movetype = MOVETYPE_FLY;
443
444         if (!cvar("g_nexball_sound_bounce"))
445                 self.noise = "";
446         else if (!self.noise)
447                 self.noise = "sound/nexball/bounce.wav";
448                 //bounce sound placeholder (FIXME)
449         if (!self.noise1)
450                 self.noise1 = "sound/nexball/drop.wav";
451                 //ball drop sound placeholder (FIXME)
452         if (!self.noise2)
453                 self.noise2 = "sound/nexball/steal.wav";
454                 //stealing sound placeholder (FIXME)
455         if (self.noise) precache_sound (self.noise);
456         precache_sound (self.noise1);
457         precache_sound (self.noise2);
458
459         WaypointSprite_AttachCarrier("nb-ball", self); // the ball's team is not set yet, no rule update needed
460         WaypointSprite_UpdateTeamRadar(self.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, BALL_SPRITECOLOR);
461
462         self.reset = ball_restart;
463         self.think = InitBall;
464         self.nextthink = game_starttime + cvar("g_nexball_delay_start");
465 }
466
467 void spawnfunc_nexball_basketball (void)
468 {
469         self.classname = "nexball_basketball";
470         if(!balls & BALL_BASKET)
471         {
472                 CVTOV(g_nexball_basketball_effects_default);
473                 CVTOV(g_nexball_basketball_delay_hold);
474                 CVTOV(g_nexball_basketball_delay_hold_forteam);
475                 CVTOV(g_nexball_basketball_teamsteal);
476                 g_nexball_basketball_effects_default = g_nexball_basketball_effects_default & BALL_EFFECTMASK;
477         }
478         if (!self.effects)
479                 self.effects = g_nexball_basketball_effects_default;
480         self.solid = SOLID_TRIGGER;
481         balls |= BALL_BASKET;
482         self.bouncefactor = cvar("g_nexball_basketball_bouncefactor");
483         self.bouncestop = cvar("g_nexball_basketball_bouncestop");
484         SpawnBall();
485 }
486
487 void spawnfunc_nexball_football (void)
488 {
489         self.classname = "nexball_football";
490         self.solid = SOLID_TRIGGER;
491         balls |= BALL_FOOT;
492         self.bouncefactor = cvar("g_nexball_football_bouncefactor");
493         self.bouncestop = cvar("g_nexball_football_bouncestop");
494         SpawnBall();
495 }
496
497 void SpawnGoal (void)
498 {
499         if(!g_nexball) { remove(self); return; }
500         EXACTTRIGGER_INIT;
501         self.classname = "nexball_goal";
502         if (!self.noise)
503                 self.noise = "ctf/respawn.wav";
504         precache_sound(self.noise);
505         self.touch = GoalTouch;
506 }
507
508 void spawnfunc_nexball_redgoal (void)
509 {
510         self.team = COLOR_TEAM1;
511         SpawnGoal();
512 }
513 void spawnfunc_nexball_bluegoal (void)
514 {
515         self.team = COLOR_TEAM2;
516         SpawnGoal();
517 }
518 void spawnfunc_nexball_yellowgoal (void)
519 {
520         self.team = COLOR_TEAM3;
521         SpawnGoal();
522 }
523 void spawnfunc_nexball_pinkgoal (void)
524 {
525         self.team = COLOR_TEAM4;
526         SpawnGoal();
527 }
528
529 void spawnfunc_nexball_fault (void)
530 {
531         self.team = GOAL_FAULT;
532         if (!self.noise)
533                 self.noise = "misc/typehit.wav";
534         SpawnGoal();
535 }
536
537 void spawnfunc_nexball_out (void)
538 {
539         self.team = GOAL_OUT;
540         if (!self.noise)
541                 self.noise = "misc/typehit.wav";
542         SpawnGoal();
543 }
544
545 //
546 //Spawnfuncs preserved for compatibility
547 //
548
549 void spawnfunc_ball            (void) { spawnfunc_nexball_football(); }
550 void spawnfunc_ball_football   (void) { spawnfunc_nexball_football(); }
551 void spawnfunc_ball_basketball (void) { spawnfunc_nexball_basketball(); }
552 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
553 void spawnfunc_ball_redgoal    (void) { spawnfunc_nexball_bluegoal(); } // I blame Revenant
554 void spawnfunc_ball_bluegoal   (void) { spawnfunc_nexball_redgoal(); }  // but he didn't mean to cause trouble :p
555 void spawnfunc_ball_fault      (void) { spawnfunc_nexball_fault(); }
556 void spawnfunc_ball_bound      (void) { spawnfunc_nexball_out(); }
557
558 //=======================//
559 //      Weapon code      //
560 //=======================//
561
562 void W_Nexball_Touch (void)
563 {
564         local entity ball, attacker;
565         attacker = self.owner;
566
567         PROJECTILE_TOUCH;
568         if(attacker.team != other.team || g_nexball_basketball_teamsteal)
569         if((ball = other.ballcarried) && (attacker.classname == "player" || attacker.classname == "gib"))
570         {
571                 other.velocity = other.velocity + normalize(self.velocity) * other.damageforcescale * cvar("g_balance_nexball_secondary_force");
572                 other.flags &~= FL_ONGROUND;
573                 if(!attacker.ballcarried)
574                 {
575                         LogNB("stole", attacker);
576                         sound (other, CHAN_AUTO, ball.noise2, VOL_BASE, ATTN_NORM);
577
578                         if(attacker.team == other.team && time > attacker.teamkill_complain)
579                         {
580                                 attacker.teamkill_complain = time + 5;
581                                 attacker.teamkill_soundtime = time + 0.4;
582                                 attacker.teamkill_soundsource = other;
583                         }
584
585                         GiveBall(attacker, other.ballcarried);
586                 }
587         }
588         remove(self);
589 }
590
591 void W_Nexball_Attack (float t)
592 {
593         local entity ball;
594         local float mul, mi, ma;
595         if (!(ball = self.ballcarried))
596                 return;
597
598         W_SetupShot (self, FALSE, 4, "nexball/shoot1.wav",0);
599         tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, world);
600         if(trace_startsolid)
601         {
602                 if(self.metertime)
603                         self.metertime = 0; // Shot failed, hide the power meter
604                 return;
605         }
606
607         //Calculate multiplier
608         if (t < 0)
609                 mul = 1;
610         else
611         {
612                 mi = cvar("g_nexball_basketball_meter_minpower");
613                 ma = max(mi, cvar("g_nexball_basketball_meter_maxpower")); // avoid confusion
614                 //One triangle wave period with 1 as max
615                 mul = 2 * mod(t, g_nexball_meter_period) / g_nexball_meter_period;
616                 if (mul > 1)
617                         mul = 2 - mul;
618                 mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
619         }
620         DropBall (ball, w_shotorg, W_CalculateProjectileVelocity(self.velocity, w_shotdir * cvar("g_balance_nexball_primary_speed") * mul));
621         //TODO: use the speed_up cvar too ??
622 }
623
624 void W_Nexball_Attack2 (void)
625 {
626         local entity missile;
627         if (!(balls & BALL_BASKET))
628                 return;
629         W_SetupShot (self, FALSE, 2, "nexball/shoot2.wav",0);
630 //      pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
631         missile = spawn ();
632
633         missile.owner = self;
634         missile.classname = "ballstealer";
635
636         missile.movetype = MOVETYPE_FLY;
637         missile.solid = SOLID_BBOX;
638
639         setmodel (missile, "models/elaser.mdl"); // precision set below
640         setsize (missile, '0 0 0', '0 0 0');
641         setorigin (missile, w_shotorg);
642
643         missile.velocity = w_shotdir * cvar("g_balance_nexball_secondary_speed");
644         W_SetupProjectileVelocity(missile);
645         missile.angles = vectoangles (missile.velocity);
646         missile.touch = W_Nexball_Touch;
647         missile.think = SUB_Remove;
648         missile.nextthink = time + cvar("g_balance_nexball_secondary_lifetime"); //FIXME: use a distance instead?
649
650         missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
651         missile.flags = FL_PROJECTILE;
652 }
653
654 float w_nexball_weapon(float req)
655 {
656         if (req == WR_THINK)
657         {
658                 if (self.BUTTON_ATCK)
659                 if (weapon_prepareattack(0, cvar("g_balance_nexball_primary_refire")))
660                 if (cvar("g_nexball_basketball_meter"))
661                 {
662                         if (self.ballcarried && !self.metertime)
663                                 self.metertime = time;
664                         else
665                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nexball_primary_animtime"), w_ready);
666                 }
667                 else
668                 {
669                         W_Nexball_Attack(-1);
670                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nexball_primary_animtime"), w_ready);
671                 }
672                 if (self.BUTTON_ATCK2)
673                 if (weapon_prepareattack(1, cvar("g_balance_nexball_secondary_refire")))
674                 {
675                         W_Nexball_Attack2();
676                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_nexball_secondary_animtime"), w_ready);
677                 }
678
679                 if (!self.BUTTON_ATCK && self.metertime && self.ballcarried)
680                 {
681                         W_Nexball_Attack(time - self.metertime);
682                         // DropBall or stealing will set metertime back to 0
683                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nexball_primary_animtime"), w_ready);
684                 }
685         }
686         else if (req == WR_PRECACHE)
687         {
688                 precache_model ("models/weapons/g_porto.md3");
689                 precache_model ("models/weapons/v_porto.md3");
690                 precache_model ("models/weapons/h_porto.dpm");
691                 precache_model ("models/elaser.mdl");
692                 precache_sound ("nexball/shoot1.wav");
693                 precache_sound ("nexball/shoot2.wav");
694         }
695         else if (req == WR_SETUP)
696                 weapon_setup(WEP_PORTO);
697         else if (req == WR_SUICIDEMESSAGE)
698         {
699                 w_deathtypestring = "is a weirdo";
700         }
701         else if (req == WR_KILLMESSAGE)
702         {
703                 w_deathtypestring = "got killed by #'s black magic";
704         }
705         // No need to check WR_CHECKAMMO* or WR_AIM, it should always return TRUE
706         return TRUE;
707 }