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