5 .float metertime = _STAT(NB_METERSTART);
7 int autocvar_g_nexball_goalleadlimit;
8 #define autocvar_g_nexball_goallimit cvar("g_nexball_goallimit")
10 bool autocvar_g_nexball_basketball_jumppad = true;
11 float autocvar_g_nexball_basketball_bouncefactor;
12 float autocvar_g_nexball_basketball_bouncestop;
13 float autocvar_g_nexball_basketball_carrier_highspeed;
14 bool autocvar_g_nexball_basketball_meter;
15 float autocvar_g_nexball_basketball_meter_maxpower;
16 float autocvar_g_nexball_basketball_meter_minpower;
17 float autocvar_g_nexball_delay_collect;
18 float autocvar_g_nexball_delay_goal;
19 float autocvar_g_nexball_delay_start;
20 bool autocvar_g_nexball_football_jumppad = true;
21 float autocvar_g_nexball_football_bouncefactor;
22 float autocvar_g_nexball_football_bouncestop;
23 bool autocvar_g_nexball_radar_showallplayers;
24 bool autocvar_g_nexball_sound_bounce;
25 int autocvar_g_nexball_trail_color;
27 float autocvar_g_nexball_safepass_turnrate;
28 float autocvar_g_nexball_safepass_maxdist;
29 float autocvar_g_nexball_safepass_holdtime;
30 float autocvar_g_nexball_viewmodel_scale;
31 float autocvar_g_nexball_tackling;
32 vector autocvar_g_nexball_viewmodel_offset;
34 float autocvar_g_balance_nexball_primary_animtime;
35 float autocvar_g_balance_nexball_primary_refire;
36 float autocvar_g_balance_nexball_primary_speed;
37 float autocvar_g_balance_nexball_secondary_animtime;
38 float autocvar_g_balance_nexball_secondary_force;
39 float autocvar_g_balance_nexball_secondary_lifetime;
40 float autocvar_g_balance_nexball_secondary_refire;
41 float autocvar_g_balance_nexball_secondary_speed;
43 void basketball_touch(entity this);
44 void football_touch(entity this);
45 void ResetBall(entity this);
46 const int NBM_NONE = 0;
47 const int NBM_FOOTBALL = 2;
48 const int NBM_BASKETBALL = 4;
51 float OtherTeam(float t) //works only if there are two teams on the map!
54 e = find(world, classname, "nexball_team");
56 e = find(e, classname, "nexball_team");
60 const float ST_NEXBALL_GOALS = 1;
61 const float SP_NEXBALL_GOALS = 4;
62 const float SP_NEXBALL_FAULTS = 5;
63 void nb_ScoreRules(float teams)
65 ScoreRules_basics(teams, 0, 0, true);
66 ScoreInfo_SetLabel_TeamScore( ST_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
67 ScoreInfo_SetLabel_PlayerScore( SP_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
68 ScoreInfo_SetLabel_PlayerScore(SP_NEXBALL_FAULTS, "faults", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER);
69 ScoreRules_basics_end();
72 void LogNB(string mode, entity actor)
75 if(!autocvar_sv_eventlog)
77 s = strcat(":nexball:", mode);
79 s = strcat(s, ":", ftos(actor.playerid));
83 void ball_restart(entity this)
86 DropBall(this, this.owner.origin, '0 0 0');
90 void nexball_setstatus(entity this)
92 this.items &= ~IT_KEY1;
95 if(this.ballcarried.teamtime && (this.ballcarried.teamtime < time))
97 bprint("The ", Team_ColoredFullName(this.team), " held the ball for too long.\n");
98 DropBall(this.ballcarried, this.ballcarried.owner.origin, '0 0 0');
99 entity e = this.ballcarried;
100 WITHSELF(e, ResetBall(e));
103 this.items |= IT_KEY1;
107 void relocate_nexball(entity this)
109 tracebox(this.origin, BALL_MINS, BALL_MAXS, this.origin, true, this);
114 if(!move_out_of_solid(this))
115 objerror("could not get out of solid at all!");
116 LOG_INFO("^1NOTE: this map needs FIXING. ", this.classname, " at ", vtos(o - '0 0 1'));
117 LOG_INFO(" needs to be moved out of solid, e.g. by '", ftos(this.origin.x - o.x));
118 LOG_INFO(" ", ftos(this.origin.y - o.y));
119 LOG_INFO(" ", ftos(this.origin.z - o.z), "'\n");
124 void DropOwner(entity this)
128 DropBall(this, ownr.origin, ownr.velocity);
129 makevectors(ownr.v_angle.y * '0 1 0');
130 ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
131 UNSET_ONGROUND(ownr);
134 void GiveBall(entity plyr, entity ball)
136 .entity weaponentity = weaponentities[0]; // TODO: find ballstealer
137 entity ownr = ball.owner;
140 ownr.effects &= ~autocvar_g_nexball_basketball_effects_default;
141 ownr.ballcarried = world;
145 ownr.(weaponentity).state = WS_READY;
147 WaypointSprite_Kill(ownr.waypointsprite_attachedforcarrier);
151 WaypointSprite_Kill(ball.waypointsprite_attachedforcarrier);
154 //setattachment(ball, plyr, "");
155 setorigin(ball, plyr.origin + plyr.view_ofs);
157 if(ball.team != plyr.team)
158 ball.teamtime = time + autocvar_g_nexball_basketball_delay_hold_forteam;
160 ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
161 ball.team = plyr.team;
162 plyr.ballcarried = ball;
163 ball.nb_dropper = plyr;
165 plyr.effects |= autocvar_g_nexball_basketball_effects_default;
166 ball.effects &= ~autocvar_g_nexball_basketball_effects_default;
168 ball.velocity = '0 0 0';
169 ball.movetype = MOVETYPE_NONE;
170 settouch(ball, func_null);
171 ball.effects |= EF_NOSHADOW;
172 ball.scale = 1; // scale down.
174 WaypointSprite_AttachCarrier(WP_NbBall, plyr, RADARICON_FLAGCARRIER);
175 WaypointSprite_UpdateRule(plyr.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
177 if(autocvar_g_nexball_basketball_delay_hold)
179 setthink(ball, DropOwner);
180 ball.nextthink = time + autocvar_g_nexball_basketball_delay_hold;
183 plyr.(weaponentity).weapons = plyr.weapons;
184 plyr.(weaponentity).m_switchweapon = PS(plyr).m_weapon;
185 plyr.weapons = WEPSET(NEXBALL);
186 Weapon w = WEP_NEXBALL;
187 WITHSELF(plyr, w.wr_resetplayer(w, plyr));
188 PS(plyr).m_switchweapon = WEP_NEXBALL;
189 WITHSELF(plyr, W_SwitchWeapon(plyr, WEP_NEXBALL));
192 void DropBall(entity ball, vector org, vector vel)
194 ball.effects |= autocvar_g_nexball_basketball_effects_default;
195 ball.effects &= ~EF_NOSHADOW;
196 ball.owner.effects &= ~autocvar_g_nexball_basketball_effects_default;
198 setattachment(ball, world, "");
199 setorigin(ball, org);
200 ball.movetype = MOVETYPE_BOUNCE;
201 UNSET_ONGROUND(ball);
202 ball.scale = ball_scale;
204 ball.nb_droptime = time;
205 settouch(ball, basketball_touch);
206 setthink(ball, ResetBall);
207 ball.nextthink = min(time + autocvar_g_nexball_delay_idle, ball.teamtime);
209 if(ball.owner.metertime)
211 ball.owner.metertime = 0;
212 .entity weaponentity = weaponentities[0]; // TODO: find ballstealer
213 ball.owner.(weaponentity).state = WS_READY;
216 WaypointSprite_Kill(ball.owner.waypointsprite_attachedforcarrier);
217 WaypointSprite_Spawn(WP_NbBall, 0, 0, ball, '0 0 64', world, ball.team, ball, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER); // no health bar please
218 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
220 ball.owner.ballcarried = world;
224 void InitBall(entity this)
227 UNSET_ONGROUND(this);
228 this.movetype = MOVETYPE_BOUNCE;
229 if(this.classname == "nexball_basketball")
230 settouch(this, basketball_touch);
231 else if(this.classname == "nexball_football")
232 settouch(this, football_touch);
234 setthink(this, ResetBall);
235 this.nextthink = time + autocvar_g_nexball_delay_idle + 3;
239 _sound(this, CH_TRIGGER, this.noise1, VOL_BASE, ATTEN_NORM);
240 WaypointSprite_Ping(this.waypointsprite_attachedforcarrier);
241 LogNB("init", world);
244 void ResetBall(entity this)
246 if(this.cnt < 2) // step 1
248 if(time == this.teamtime)
249 bprint("The ", Team_ColoredFullName(this.team), " held the ball for too long.\n");
251 settouch(this, func_null);
252 this.movetype = MOVETYPE_NOCLIP;
253 this.velocity = '0 0 0'; // just in case?
255 LogNB("resetidle", world);
257 this.nextthink = time;
259 else if(this.cnt < 4) // step 2 and 3
261 // dprint("Step ", ftos(this.cnt), ": Calculated velocity: ", vtos(this.spawnorigin - this.origin), ", time: ", ftos(time), "\n");
262 this.velocity = (this.spawnorigin - this.origin) * (this.cnt - 1); // 1 or 0.5 second movement
263 this.nextthink = time + 0.5;
268 // dprint("Step 4: time: ", ftos(time), "\n");
269 if(vlen(this.origin - this.spawnorigin) > 10) // should not happen anymore
270 LOG_TRACE("The ball moved too far away from its spawn origin.\nOffset: ",
271 vtos(this.origin - this.spawnorigin), " Velocity: ", vtos(this.velocity), "\n");
272 this.velocity = '0 0 0';
273 setorigin(this, this.spawnorigin); // make sure it's positioned correctly anyway
274 this.movetype = MOVETYPE_NONE;
275 setthink(this, InitBall);
276 this.nextthink = max(time, game_starttime) + autocvar_g_nexball_delay_start;
280 void football_touch(entity this)
282 if(other.solid == SOLID_BSP)
284 if(time > self.lastground + 0.1)
286 _sound(self, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NORM);
287 self.lastground = time;
289 if(vlen(self.velocity) && !self.cnt)
290 self.nextthink = time + autocvar_g_nexball_delay_idle;
293 if (!IS_PLAYER(other))
298 self.nextthink = time + autocvar_g_nexball_delay_idle;
301 self.team = other.team;
303 if(autocvar_g_nexball_football_physics == -1) // MrBougo try 1, before decompiling Rev's original
305 if(vlen(other.velocity))
306 self.velocity = other.velocity * 1.5 + '0 0 1' * autocvar_g_nexball_football_boost_up;
308 else if(autocvar_g_nexball_football_physics == 1) // MrBougo's modded Rev style: partially independant of the height of the aiming point
310 makevectors(other.v_angle);
311 self.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + '0 0 1' * autocvar_g_nexball_football_boost_up;
313 else if(autocvar_g_nexball_football_physics == 2) // 2nd mod try: totally independant. Really playable!
315 makevectors(other.v_angle.y * '0 1 0');
316 self.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
318 else // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
320 makevectors(other.v_angle);
321 self.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
323 self.avelocity = -250 * v_forward; // maybe there is a way to make it look better?
326 void basketball_touch(entity this)
328 if(other.ballcarried)
330 football_touch(this);
333 if(!self.cnt && IS_PLAYER(other) && !STAT(FROZEN, other) && !IS_DEAD(other) && (other != self.nb_dropper || time > self.nb_droptime + autocvar_g_nexball_delay_collect))
335 if(other.health <= 0)
337 LogNB("caught", other);
338 GiveBall(other, self);
340 else if(other.solid == SOLID_BSP)
342 _sound(self, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NORM);
343 if(vlen(self.velocity) && !self.cnt)
344 self.nextthink = min(time + autocvar_g_nexball_delay_idle, self.teamtime);
348 void GoalTouch(entity this)
351 float isclient, pscore, otherteam;
355 if((self.spawnflags & GOAL_TOUCHPLAYER) && other.ballcarried)
356 ball = other.ballcarried;
359 if(ball.classname != "nexball_basketball")
360 if(ball.classname != "nexball_football")
362 if((!ball.pusher && self.team != GOAL_OUT) || ball.cnt)
368 otherteam = OtherTeam(ball.team);
372 if((isclient = IS_CLIENT(ball.pusher)))
373 pname = ball.pusher.netname;
375 pname = "Someone (?)";
377 if(ball.team == self.team) //owngoal (regular goals)
379 LogNB("owngoal", ball.pusher);
380 bprint("Boo! ", pname, "^7 scored a goal against their own team!\n");
383 else if(self.team == GOAL_FAULT)
385 LogNB("fault", ball.pusher);
387 bprint(Team_ColoredFullName(otherteam), " gets a point due to ", pname, "^7's silliness.\n");
389 bprint(Team_ColoredFullName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
392 else if(self.team == GOAL_OUT)
394 LogNB("out", ball.pusher);
395 if((self.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
396 bprint(pname, "^7 went out of bounds.\n");
398 bprint("The ball was returned.\n");
403 LogNB(strcat("goal:", ftos(self.team)), ball.pusher);
404 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", Team_ColoredFullName(ball.team), ".\n");
408 _sound(ball, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NONE);
410 if(ball.team && pscore)
412 if(nb_teams == 2 && pscore < 0)
413 TeamScore_AddToTeam(otherteam, ST_NEXBALL_GOALS, -pscore);
415 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
420 PlayerScore_Add(ball.pusher, SP_NEXBALL_GOALS, pscore);
422 PlayerScore_Add(ball.pusher, SP_NEXBALL_FAULTS, -pscore);
425 if(ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
426 DropBall(ball, ball.owner.origin, ball.owner.velocity);
428 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
431 setthink(ball, ResetBall);
432 if(ball.classname == "nexball_basketball")
433 settouch(ball, football_touch); // better than func_null: football control until the ball gets reset
434 ball.nextthink = time + autocvar_g_nexball_delay_goal * (self.team != GOAL_OUT);
437 //=======================//
439 //=======================//
440 spawnfunc(nexball_team)
447 this.team = this.cnt + 1;
450 void nb_spawnteam(string teamname, float teamcolor)
452 LOG_TRACE("^2spawned team ", teamname, "\n");
453 entity e = new(nexball_team);
454 e.netname = teamname;
462 bool t_red = false, t_blue = false, t_yellow = false, t_pink = false;
464 for(e = world; (e = find(e, classname, "nexball_goal"));)
471 nb_spawnteam("Red", e.team-1) ;
478 nb_spawnteam("Blue", e.team-1) ;
485 nb_spawnteam("Yellow", e.team-1);
492 nb_spawnteam("Pink", e.team-1) ;
500 void nb_delayedinit(entity this)
502 if(find(world, classname, "nexball_team") == world)
504 nb_ScoreRules(nb_teams);
508 //=======================//
510 //=======================//
512 void SpawnBall(entity this)
514 if(!g_nexball) { remove(this); return; }
516 // balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
520 this.model = "models/nexball/ball.md3";
524 precache_model(this.model);
525 _setmodel(this, this.model);
526 setsize(this, BALL_MINS, BALL_MAXS);
527 ball_scale = this.scale;
529 relocate_nexball(this);
530 this.spawnorigin = this.origin;
532 this.effects = this.effects | EF_LOWPRECISION;
534 if(cvar(strcat("g_", this.classname, "_trail"))) //nexball_basketball :p
536 this.glow_color = autocvar_g_nexball_trail_color;
537 this.glow_trail = true;
540 this.movetype = MOVETYPE_FLY;
542 if(!autocvar_g_nexball_sound_bounce)
544 else if(this.noise == "")
545 this.noise = strzone(SND(NB_BOUNCE));
546 //bounce sound placeholder (FIXME)
547 if(this.noise1 == "")
548 this.noise1 = strzone(SND(NB_DROP));
549 //ball drop sound placeholder (FIXME)
550 if(this.noise2 == "")
551 this.noise2 = strzone(SND(NB_STEAL));
552 //stealing sound placeholder (FIXME)
553 if(this.noise) precache_sound(this.noise);
554 precache_sound(this.noise1);
555 precache_sound(this.noise2);
557 WaypointSprite_AttachCarrier(WP_NbBall, this, RADARICON_FLAGCARRIER); // the ball's team is not set yet, no rule update needed
559 this.reset = ball_restart;
560 setthink(this, InitBall);
561 this.nextthink = game_starttime + autocvar_g_nexball_delay_start;
564 spawnfunc(nexball_basketball)
566 nexball_mode |= NBM_BASKETBALL;
567 this.classname = "nexball_basketball";
568 if (!(balls & BALL_BASKET))
571 CVTOV(g_nexball_basketball_effects_default);
572 CVTOV(g_nexball_basketball_delay_hold);
573 CVTOV(g_nexball_basketball_delay_hold_forteam);
574 CVTOV(g_nexball_basketball_teamsteal);
576 autocvar_g_nexball_basketball_effects_default = autocvar_g_nexball_basketball_effects_default & BALL_EFFECTMASK;
579 this.effects = autocvar_g_nexball_basketball_effects_default;
580 this.solid = SOLID_TRIGGER;
581 this.pushable = autocvar_g_nexball_basketball_jumppad;
582 balls |= BALL_BASKET;
583 this.bouncefactor = autocvar_g_nexball_basketball_bouncefactor;
584 this.bouncestop = autocvar_g_nexball_basketball_bouncestop;
588 spawnfunc(nexball_football)
590 nexball_mode |= NBM_FOOTBALL;
591 this.classname = "nexball_football";
592 this.solid = SOLID_TRIGGER;
594 this.pushable = autocvar_g_nexball_football_jumppad;
595 this.bouncefactor = autocvar_g_nexball_football_bouncefactor;
596 this.bouncestop = autocvar_g_nexball_football_bouncestop;
600 float nb_Goal_Customize()
603 e = WaypointSprite_getviewentity(other);
604 wp_owner = self.owner;
605 if(SAME_TEAM(e, wp_owner)) { return false; }
610 void SpawnGoal(entity this)
612 if(!g_nexball) { remove(this); return; }
616 if(this.team != GOAL_OUT && Team_TeamToNumber(this.team) != -1)
618 entity wp = WaypointSprite_SpawnFixed(WP_NbGoal, (this.absmin + this.absmax) * 0.5, this, sprite, RADARICON_NONE);
619 wp.colormod = ((this.team) ? Team_ColorRGB(this.team) : '1 0.5 0');
620 this.sprite.customizeentityforclient = nb_Goal_Customize;
623 this.classname = "nexball_goal";
625 this.noise = "ctf/respawn.wav";
626 precache_sound(this.noise);
627 settouch(this, GoalTouch);
630 spawnfunc(nexball_redgoal)
632 this.team = NUM_TEAM_1;
635 spawnfunc(nexball_bluegoal)
637 this.team = NUM_TEAM_2;
640 spawnfunc(nexball_yellowgoal)
642 this.team = NUM_TEAM_3;
645 spawnfunc(nexball_pinkgoal)
647 this.team = NUM_TEAM_4;
651 spawnfunc(nexball_fault)
653 this.team = GOAL_FAULT;
655 this.noise = strzone(SND(TYPEHIT));
659 spawnfunc(nexball_out)
661 this.team = GOAL_OUT;
663 this.noise = strzone(SND(TYPEHIT));
668 //Spawnfuncs preserved for compatibility
673 spawnfunc_nexball_football(this);
675 spawnfunc(ball_football)
677 spawnfunc_nexball_football(this);
679 spawnfunc(ball_basketball)
681 spawnfunc_nexball_basketball(this);
683 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
684 spawnfunc(ball_redgoal)
686 spawnfunc_nexball_bluegoal(this); // I blame Revenant
688 spawnfunc(ball_bluegoal)
690 spawnfunc_nexball_redgoal(this); // but he didn't mean to cause trouble :p
692 spawnfunc(ball_fault)
694 spawnfunc_nexball_fault(this);
696 spawnfunc(ball_bound)
698 spawnfunc_nexball_out(this);
701 //=======================//
703 //=======================//
706 void W_Nexball_Think(entity this)
708 //dprint("W_Nexball_Think\n");
709 //vector new_dir = steerlib_arrive(this.enemy.origin, 2500);
710 vector new_dir = normalize(this.enemy.origin + '0 0 50' - this.origin);
711 vector old_dir = normalize(this.velocity);
712 float _speed = vlen(this.velocity);
713 vector new_vel = normalize(old_dir + (new_dir * autocvar_g_nexball_safepass_turnrate)) * _speed;
714 //vector new_vel = (new_dir * autocvar_g_nexball_safepass_turnrate
716 this.velocity = new_vel;
718 this.nextthink = time;
721 void W_Nexball_Touch(entity this)
723 entity ball, attacker;
724 attacker = this.owner;
725 //this.think = func_null;
726 //this.enemy = world;
728 PROJECTILE_TOUCH(this);
729 if(attacker.team != other.team || autocvar_g_nexball_basketball_teamsteal)
730 if((ball = other.ballcarried) && !STAT(FROZEN, other) && !IS_DEAD(other) && (IS_PLAYER(attacker)))
732 other.velocity = other.velocity + normalize(this.velocity) * other.damageforcescale * autocvar_g_balance_nexball_secondary_force;
733 UNSET_ONGROUND(other);
734 if(!attacker.ballcarried)
736 LogNB("stole", attacker);
737 _sound(other, CH_TRIGGER, ball.noise2, VOL_BASE, ATTEN_NORM);
739 if(SAME_TEAM(attacker, other) && time > attacker.teamkill_complain)
741 attacker.teamkill_complain = time + 5;
742 attacker.teamkill_soundtime = time + 0.4;
743 attacker.teamkill_soundsource = other;
746 GiveBall(attacker, other.ballcarried);
752 void W_Nexball_Attack(entity actor, float t)
756 if(!(ball = actor.ballcarried))
759 W_SetupShot(actor, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
760 tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, world);
764 actor.metertime = 0; // Shot failed, hide the power meter
768 //Calculate multiplier
773 mi = autocvar_g_nexball_basketball_meter_minpower;
774 ma = max(mi, autocvar_g_nexball_basketball_meter_maxpower); // avoid confusion
775 //One triangle wave period with 1 as max
776 mul = 2 * (t % g_nexball_meter_period) / g_nexball_meter_period;
779 mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
782 DropBall(ball, w_shotorg, W_CalculateProjectileVelocity(actor.velocity, w_shotdir * autocvar_g_balance_nexball_primary_speed * mul, false));
785 //TODO: use the speed_up cvar too ??
788 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht);
790 void W_Nexball_Attack2(entity actor)
792 if(actor.ballcarried.enemy)
794 entity _ball = actor.ballcarried;
795 W_SetupShot(actor, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
796 DropBall(_ball, w_shotorg, trigger_push_calculatevelocity(_ball.origin, _ball.enemy, 32));
797 setthink(_ball, W_Nexball_Think);
798 _ball.nextthink = time;
802 if(!autocvar_g_nexball_tackling)
805 W_SetupShot(actor, false, 2, SND_NB_SHOOT2, CH_WEAPON_A, 0);
806 entity missile = new(ballstealer);
808 missile.owner = actor;
810 missile.movetype = MOVETYPE_FLY;
811 PROJECTILE_MAKETRIGGER(missile);
813 //setmodel(missile, "models/elaser.mdl"); // precision set below
814 setsize(missile, '0 0 0', '0 0 0');
815 setorigin(missile, w_shotorg);
817 W_SetupProjVelocity_Basic(missile, autocvar_g_balance_nexball_secondary_speed, 0);
818 missile.angles = vectoangles(missile.velocity);
819 settouch(missile, W_Nexball_Touch);
820 setthink(missile, SUB_Remove);
821 missile.nextthink = time + autocvar_g_balance_nexball_secondary_lifetime; //FIXME: use a distance instead?
823 missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
824 missile.flags = FL_PROJECTILE;
826 CSQCProjectile(missile, true, PROJECTILE_ELECTRO, true);
829 float ball_customize()
833 self.effects &= ~EF_FLAME;
835 self.customizeentityforclient = func_null;
839 if(other == self.owner)
841 self.scale = autocvar_g_nexball_viewmodel_scale;
843 self.effects |= EF_FLAME;
845 self.effects &= ~EF_FLAME;
849 self.effects &= ~EF_FLAME;
856 METHOD(BallStealer, wr_think, void(BallStealer thiswep, entity actor, .entity weaponentity, int fire))
858 TC(BallStealer, thiswep);
860 if(weapon_prepareattack(thiswep, actor, weaponentity, false, autocvar_g_balance_nexball_primary_refire))
861 if(autocvar_g_nexball_basketball_meter)
863 if(actor.ballcarried && !actor.metertime)
864 actor.metertime = time;
866 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
870 W_Nexball_Attack(actor, -1);
871 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
874 if(weapon_prepareattack(thiswep, actor, weaponentity, true, autocvar_g_balance_nexball_secondary_refire))
876 W_Nexball_Attack2(actor);
877 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, autocvar_g_balance_nexball_secondary_animtime, w_ready);
880 if(!(fire & 1) && actor.metertime && actor.ballcarried)
882 W_Nexball_Attack(actor, time - actor.metertime);
883 // DropBall or stealing will set metertime back to 0
884 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
888 METHOD(BallStealer, wr_setup, void(BallStealer this, entity actor))
890 TC(BallStealer, this);
891 //weapon_setup(WEP_PORTO.m_id);
894 METHOD(BallStealer, wr_checkammo1, bool(BallStealer this, entity actor))
896 TC(BallStealer, this);
900 METHOD(BallStealer, wr_checkammo2, bool(BallStealer this, entity actor))
902 TC(BallStealer, this);
906 void nb_DropBall(entity player)
908 if(player.ballcarried && g_nexball)
909 DropBall(player.ballcarried, player.origin, player.velocity);
912 MUTATOR_HOOKFUNCTION(nb, ClientDisconnect)
918 MUTATOR_HOOKFUNCTION(nb, PlayerDies)
920 nb_DropBall(frag_target);
924 MUTATOR_HOOKFUNCTION(nb, MakePlayerObserver)
930 MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
932 makevectors(self.v_angle);
933 if(nexball_mode & NBM_BASKETBALL)
938 self.ballcarried.velocity = self.velocity;
939 self.ballcarried.customizeentityforclient = ball_customize;
941 vector org = self.origin + self.view_ofs +
942 v_forward * autocvar_g_nexball_viewmodel_offset.x +
943 v_right * autocvar_g_nexball_viewmodel_offset.y +
944 v_up * autocvar_g_nexball_viewmodel_offset.z;
945 setorigin(self.ballcarried, org);
948 if(autocvar_g_nexball_safepass_maxdist)
950 if(self.ballcarried.wait < time && self.ballcarried.enemy)
952 //centerprint(self, sprintf("Lost lock on %s", self.ballcarried.enemy.netname));
953 self.ballcarried.enemy = world;
957 //tracebox(self.origin + self.view_ofs, '-2 -2 -2', '2 2 2', self.origin + self.view_ofs + v_forward * autocvar_g_nexball_safepass_maxdist);
958 crosshair_trace(self);
960 IS_CLIENT(trace_ent) &&
961 !IS_DEAD(trace_ent) &&
962 trace_ent.team == self.team &&
963 vlen(trace_ent.origin - self.origin) <= autocvar_g_nexball_safepass_maxdist )
966 //if(self.ballcarried.enemy != trace_ent)
967 // centerprint(self, sprintf("Locked to %s", trace_ent.netname));
968 self.ballcarried.enemy = trace_ent;
969 self.ballcarried.wait = time + autocvar_g_nexball_safepass_holdtime;
977 .entity weaponentity = weaponentities[0]; // TODO
978 if(self.(weaponentity).weapons)
980 self.weapons = self.(weaponentity).weapons;
981 Weapon w = WEP_NEXBALL;
982 w.wr_resetplayer(w, self);
983 PS(self).m_switchweapon = self.(weaponentity).m_switchweapon;
984 W_SwitchWeapon(self, PS(self).m_switchweapon);
986 self.(weaponentity).weapons = '0 0 0';
992 nexball_setstatus(self);
997 MUTATOR_HOOKFUNCTION(nb, SpectateCopy)
1000 this.metertime = other.metertime;
1003 MUTATOR_HOOKFUNCTION(nb, PlayerSpawn)
1007 .entity weaponentity = weaponentities[0];
1008 this.(weaponentity).weapons = '0 0 0';
1010 if (nexball_mode & NBM_BASKETBALL)
1011 this.weapons |= WEPSET(NEXBALL);
1013 this.weapons = '0 0 0';
1018 .float stat_sv_airspeedlimit_nonqw;
1019 .float stat_sv_maxspeed;
1021 MUTATOR_HOOKFUNCTION(nb, PlayerPhysics)
1023 if(self.ballcarried)
1025 self.stat_sv_airspeedlimit_nonqw *= autocvar_g_nexball_basketball_carrier_highspeed;
1026 self.stat_sv_maxspeed *= autocvar_g_nexball_basketball_carrier_highspeed;
1031 MUTATOR_HOOKFUNCTION(nb, ForbidThrowCurrentWeapon)
1033 return PS(self).m_weapon == WEP_NEXBALL;
1036 MUTATOR_HOOKFUNCTION(nb, ForbidDropCurrentWeapon)
1038 return PS(self).m_weapon == WEP_MORTAR; // TODO: what is this for?
1041 MUTATOR_HOOKFUNCTION(nb, FilterItem)
1043 if(self.classname == "droppedweapon")
1044 if(self.weapon == WEP_NEXBALL.m_id)
1050 MUTATOR_HOOKFUNCTION(nb, GetTeamCount)
1052 ret_string = "nexball_team";
1056 MUTATOR_HOOKFUNCTION(nb, WantWeapon)
1058 ret_float = 0; // weapon is set a few lines later, apparently
1062 MUTATOR_HOOKFUNCTION(nb, DropSpecialItems)
1064 if(frag_target.ballcarried)
1065 DropBall(frag_target.ballcarried, frag_target.origin, frag_target.velocity);
1070 MUTATOR_HOOKFUNCTION(nb, SendWaypoint)
1072 wp_sendflags &= ~0x80;
1076 REGISTER_MUTATOR(nb, g_nexball)
1080 g_nexball_meter_period = autocvar_g_nexball_meter_period;
1081 if(g_nexball_meter_period <= 0)
1082 g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
1083 g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
1087 CVTOV(g_nexball_football_boost_forward); //100
1088 CVTOV(g_nexball_football_boost_up); //200
1089 CVTOV(g_nexball_delay_idle); //10
1090 CVTOV(g_nexball_football_physics); //0
1092 radar_showennemies = autocvar_g_nexball_radar_showallplayers;
1094 InitializeEntity(world, nb_delayedinit, INITPRIO_GAMETYPE);
1095 WEP_NEXBALL.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
1098 SetLimits(autocvar_g_nexball_goallimit, autocvar_g_nexball_goalleadlimit, autocvar_timelimit_override, -1);
1099 have_team_spawns = -1; // request team spawns
1102 MUTATOR_ONROLLBACK_OR_REMOVE
1104 WEP_NEXBALL.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
1105 // we actually cannot roll back nb_delayedinit here
1106 // BUT: we don't need to! If this gets called, adding always
1112 LOG_INFO("This is a game type and it cannot be removed at runtime.");