5 int autocvar_cl_eventchase_nexball = 1;
7 REGISTER_MUTATOR(cl_nb, true);
9 MUTATOR_HOOKFUNCTION(cl_nb, WantEventchase)
11 if(autocvar_cl_eventchase_nexball && gametype == MAPINFO_TYPE_NEXBALL && !(WepSet_GetFromStat() & WEPSET(NEXBALL)))
17 .float metertime = _STAT(NB_METERSTART);
19 int autocvar_g_nexball_goalleadlimit;
20 #define autocvar_g_nexball_goallimit cvar("g_nexball_goallimit")
22 bool autocvar_g_nexball_basketball_jumppad = true;
23 float autocvar_g_nexball_basketball_bouncefactor;
24 float autocvar_g_nexball_basketball_bouncestop;
25 float autocvar_g_nexball_basketball_carrier_highspeed;
26 bool autocvar_g_nexball_basketball_meter;
27 float autocvar_g_nexball_basketball_meter_maxpower;
28 float autocvar_g_nexball_basketball_meter_minpower;
29 float autocvar_g_nexball_delay_collect;
30 float autocvar_g_nexball_delay_goal;
31 float autocvar_g_nexball_delay_start;
32 bool autocvar_g_nexball_football_jumppad = true;
33 float autocvar_g_nexball_football_bouncefactor;
34 float autocvar_g_nexball_football_bouncestop;
35 bool autocvar_g_nexball_radar_showallplayers;
36 bool autocvar_g_nexball_sound_bounce;
37 int autocvar_g_nexball_trail_color;
39 float autocvar_g_nexball_safepass_turnrate;
40 float autocvar_g_nexball_safepass_maxdist;
41 float autocvar_g_nexball_safepass_holdtime;
42 float autocvar_g_nexball_viewmodel_scale;
43 float autocvar_g_nexball_tackling;
44 vector autocvar_g_nexball_viewmodel_offset;
46 float autocvar_g_balance_nexball_primary_animtime;
47 float autocvar_g_balance_nexball_primary_refire;
48 float autocvar_g_balance_nexball_primary_speed;
49 float autocvar_g_balance_nexball_secondary_animtime;
50 float autocvar_g_balance_nexball_secondary_force;
51 float autocvar_g_balance_nexball_secondary_lifetime;
52 float autocvar_g_balance_nexball_secondary_refire;
53 float autocvar_g_balance_nexball_secondary_speed;
55 void basketball_touch(entity this);
56 void football_touch(entity this);
57 void ResetBall(entity this);
58 const int NBM_NONE = 0;
59 const int NBM_FOOTBALL = 2;
60 const int NBM_BASKETBALL = 4;
63 float OtherTeam(float t) //works only if there are two teams on the map!
66 e = find(NULL, classname, "nexball_team");
68 e = find(e, classname, "nexball_team");
72 const float ST_NEXBALL_GOALS = 1;
73 void nb_ScoreRules(float teams)
75 ScoreRules_basics(teams, 0, 0, true);
76 ScoreInfo_SetLabel_TeamScore( ST_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
77 ScoreInfo_SetLabel_PlayerScore(SP_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
78 ScoreInfo_SetLabel_PlayerScore(SP_NEXBALL_FAULTS, "faults", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER);
79 ScoreRules_basics_end();
82 void LogNB(string mode, entity actor)
85 if(!autocvar_sv_eventlog)
87 s = strcat(":nexball:", mode);
89 s = strcat(s, ":", ftos(actor.playerid));
93 void ball_restart(entity this)
96 DropBall(this, this.owner.origin, '0 0 0');
100 void nexball_setstatus(entity this)
102 this.items &= ~IT_KEY1;
105 if(this.ballcarried.teamtime && (this.ballcarried.teamtime < time))
107 bprint("The ", Team_ColoredFullName(this.team), " held the ball for too long.\n");
108 DropBall(this.ballcarried, this.ballcarried.owner.origin, '0 0 0');
109 entity e = this.ballcarried;
113 this.items |= IT_KEY1;
117 void relocate_nexball(entity this)
119 tracebox(this.origin, BALL_MINS, BALL_MAXS, this.origin, true, this);
124 if(!move_out_of_solid(this))
125 objerror(this, "could not get out of solid at all!");
126 LOG_INFO("^1NOTE: this map needs FIXING. ", this.classname, " at ", vtos(o - '0 0 1'));
127 LOG_INFO(" needs to be moved out of solid, e.g. by '", ftos(this.origin.x - o.x));
128 LOG_INFO(" ", ftos(this.origin.y - o.y));
129 LOG_INFO(" ", ftos(this.origin.z - o.z), "'\n");
134 void DropOwner(entity this)
138 DropBall(this, ownr.origin, ownr.velocity);
139 makevectors(ownr.v_angle.y * '0 1 0');
140 ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
141 UNSET_ONGROUND(ownr);
144 void GiveBall(entity plyr, entity ball)
146 .entity weaponentity = weaponentities[0]; // TODO: find ballstealer
147 entity ownr = ball.owner;
150 ownr.effects &= ~autocvar_g_nexball_basketball_effects_default;
151 ownr.ballcarried = NULL;
155 ownr.(weaponentity).state = WS_READY;
157 WaypointSprite_Kill(ownr.waypointsprite_attachedforcarrier);
161 WaypointSprite_Kill(ball.waypointsprite_attachedforcarrier);
164 //setattachment(ball, plyr, "");
165 setorigin(ball, plyr.origin + plyr.view_ofs);
167 if(ball.team != plyr.team)
168 ball.teamtime = time + autocvar_g_nexball_basketball_delay_hold_forteam;
170 ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
171 ball.team = plyr.team;
172 plyr.ballcarried = ball;
173 ball.nb_dropper = plyr;
175 plyr.effects |= autocvar_g_nexball_basketball_effects_default;
176 ball.effects &= ~autocvar_g_nexball_basketball_effects_default;
178 ball.velocity = '0 0 0';
179 ball.movetype = MOVETYPE_NONE;
180 settouch(ball, func_null);
181 ball.effects |= EF_NOSHADOW;
182 ball.scale = 1; // scale down.
184 WaypointSprite_AttachCarrier(WP_NbBall, plyr, RADARICON_FLAGCARRIER);
185 WaypointSprite_UpdateRule(plyr.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
187 if(autocvar_g_nexball_basketball_delay_hold)
189 setthink(ball, DropOwner);
190 ball.nextthink = time + autocvar_g_nexball_basketball_delay_hold;
193 plyr.(weaponentity).weapons = plyr.weapons;
194 plyr.(weaponentity).m_switchweapon = PS(plyr).m_weapon;
195 plyr.weapons = WEPSET(NEXBALL);
196 Weapon w = WEP_NEXBALL;
197 w.wr_resetplayer(w, plyr);
198 PS(plyr).m_switchweapon = WEP_NEXBALL;
199 W_SwitchWeapon(plyr, WEP_NEXBALL);
202 void DropBall(entity ball, vector org, vector vel)
204 ball.effects |= autocvar_g_nexball_basketball_effects_default;
205 ball.effects &= ~EF_NOSHADOW;
206 ball.owner.effects &= ~autocvar_g_nexball_basketball_effects_default;
208 setattachment(ball, NULL, "");
209 setorigin(ball, org);
210 ball.movetype = MOVETYPE_BOUNCE;
211 UNSET_ONGROUND(ball);
212 ball.scale = ball_scale;
214 ball.nb_droptime = time;
215 settouch(ball, basketball_touch);
216 setthink(ball, ResetBall);
217 ball.nextthink = min(time + autocvar_g_nexball_delay_idle, ball.teamtime);
219 if(ball.owner.metertime)
221 ball.owner.metertime = 0;
222 .entity weaponentity = weaponentities[0]; // TODO: find ballstealer
223 ball.owner.(weaponentity).state = WS_READY;
226 WaypointSprite_Kill(ball.owner.waypointsprite_attachedforcarrier);
227 WaypointSprite_Spawn(WP_NbBall, 0, 0, ball, '0 0 64', NULL, ball.team, ball, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER); // no health bar please
228 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
230 ball.owner.ballcarried = NULL;
234 void InitBall(entity this)
237 UNSET_ONGROUND(this);
238 this.movetype = MOVETYPE_BOUNCE;
239 if(this.classname == "nexball_basketball")
240 settouch(this, basketball_touch);
241 else if(this.classname == "nexball_football")
242 settouch(this, football_touch);
244 setthink(this, ResetBall);
245 this.nextthink = time + autocvar_g_nexball_delay_idle + 3;
249 _sound(this, CH_TRIGGER, this.noise1, VOL_BASE, ATTEN_NORM);
250 WaypointSprite_Ping(this.waypointsprite_attachedforcarrier);
254 void ResetBall(entity this)
256 if(this.cnt < 2) // step 1
258 if(time == this.teamtime)
259 bprint("The ", Team_ColoredFullName(this.team), " held the ball for too long.\n");
261 settouch(this, func_null);
262 this.movetype = MOVETYPE_NOCLIP;
263 this.velocity = '0 0 0'; // just in case?
265 LogNB("resetidle", NULL);
267 this.nextthink = time;
269 else if(this.cnt < 4) // step 2 and 3
271 // dprint("Step ", ftos(this.cnt), ": Calculated velocity: ", vtos(this.spawnorigin - this.origin), ", time: ", ftos(time), "\n");
272 this.velocity = (this.spawnorigin - this.origin) * (this.cnt - 1); // 1 or 0.5 second movement
273 this.nextthink = time + 0.5;
278 // dprint("Step 4: time: ", ftos(time), "\n");
279 if(vdist(this.origin - this.spawnorigin, >, 10)) // should not happen anymore
280 LOG_TRACE("The ball moved too far away from its spawn origin.\nOffset: ",
281 vtos(this.origin - this.spawnorigin), " Velocity: ", vtos(this.velocity), "\n");
282 this.velocity = '0 0 0';
283 setorigin(this, this.spawnorigin); // make sure it's positioned correctly anyway
284 this.movetype = MOVETYPE_NONE;
285 setthink(this, InitBall);
286 this.nextthink = max(time, game_starttime) + autocvar_g_nexball_delay_start;
290 void football_touch(entity this)
292 if(other.solid == SOLID_BSP)
294 if(time > this.lastground + 0.1)
296 _sound(this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
297 this.lastground = time;
299 if(this.velocity && !this.cnt)
300 this.nextthink = time + autocvar_g_nexball_delay_idle;
303 if (!IS_PLAYER(other))
308 this.nextthink = time + autocvar_g_nexball_delay_idle;
311 this.team = other.team;
313 if(autocvar_g_nexball_football_physics == -1) // MrBougo try 1, before decompiling Rev's original
316 this.velocity = other.velocity * 1.5 + '0 0 1' * autocvar_g_nexball_football_boost_up;
318 else if(autocvar_g_nexball_football_physics == 1) // MrBougo's modded Rev style: partially independant of the height of the aiming point
320 makevectors(other.v_angle);
321 this.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + '0 0 1' * autocvar_g_nexball_football_boost_up;
323 else if(autocvar_g_nexball_football_physics == 2) // 2nd mod try: totally independant. Really playable!
325 makevectors(other.v_angle.y * '0 1 0');
326 this.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
328 else // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
330 makevectors(other.v_angle);
331 this.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
333 this.avelocity = -250 * v_forward; // maybe there is a way to make it look better?
336 void basketball_touch(entity this)
338 if(other.ballcarried)
340 football_touch(this);
343 if(!this.cnt && IS_PLAYER(other) && !STAT(FROZEN, other) && !IS_DEAD(other) && (other != this.nb_dropper || time > this.nb_droptime + autocvar_g_nexball_delay_collect))
345 if(other.health <= 0)
347 LogNB("caught", other);
348 GiveBall(other, this);
350 else if(other.solid == SOLID_BSP)
352 _sound(this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
353 if(this.velocity && !this.cnt)
354 this.nextthink = min(time + autocvar_g_nexball_delay_idle, this.teamtime);
358 void GoalTouch(entity this)
361 float isclient, pscore, otherteam;
365 if((this.spawnflags & GOAL_TOUCHPLAYER) && other.ballcarried)
366 ball = other.ballcarried;
369 if(ball.classname != "nexball_basketball")
370 if(ball.classname != "nexball_football")
372 if((!ball.pusher && this.team != GOAL_OUT) || ball.cnt)
378 otherteam = OtherTeam(ball.team);
382 if((isclient = IS_CLIENT(ball.pusher)))
383 pname = ball.pusher.netname;
385 pname = "Someone (?)";
387 if(ball.team == this.team) //owngoal (regular goals)
389 LogNB("owngoal", ball.pusher);
390 bprint("Boo! ", pname, "^7 scored a goal against their own team!\n");
393 else if(this.team == GOAL_FAULT)
395 LogNB("fault", ball.pusher);
397 bprint(Team_ColoredFullName(otherteam), " gets a point due to ", pname, "^7's silliness.\n");
399 bprint(Team_ColoredFullName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
402 else if(this.team == GOAL_OUT)
404 LogNB("out", ball.pusher);
405 if((this.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
406 bprint(pname, "^7 went out of bounds.\n");
408 bprint("The ball was returned.\n");
413 LogNB(strcat("goal:", ftos(this.team)), ball.pusher);
414 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", Team_ColoredFullName(ball.team), ".\n");
418 _sound(ball, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NONE);
420 if(ball.team && pscore)
422 if(nb_teams == 2 && pscore < 0)
423 TeamScore_AddToTeam(otherteam, ST_NEXBALL_GOALS, -pscore);
425 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
430 PlayerScore_Add(ball.pusher, SP_NEXBALL_GOALS, pscore);
432 PlayerScore_Add(ball.pusher, SP_NEXBALL_FAULTS, -pscore);
435 if(ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
436 DropBall(ball, ball.owner.origin, ball.owner.velocity);
438 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
441 setthink(ball, ResetBall);
442 if(ball.classname == "nexball_basketball")
443 settouch(ball, football_touch); // better than func_null: football control until the ball gets reset
444 ball.nextthink = time + autocvar_g_nexball_delay_goal * (this.team != GOAL_OUT);
447 //=======================//
449 //=======================//
450 spawnfunc(nexball_team)
457 this.team = this.cnt + 1;
460 void nb_spawnteam(string teamname, float teamcolor)
462 LOG_TRACE("^2spawned team ", teamname, "\n");
463 entity e = new(nexball_team);
464 e.netname = teamname;
472 bool t_red = false, t_blue = false, t_yellow = false, t_pink = false;
474 for(e = NULL; (e = find(e, classname, "nexball_goal"));)
481 nb_spawnteam("Red", e.team-1) ;
488 nb_spawnteam("Blue", e.team-1) ;
495 nb_spawnteam("Yellow", e.team-1);
502 nb_spawnteam("Pink", e.team-1) ;
510 void nb_delayedinit(entity this)
512 if(find(NULL, classname, "nexball_team") == NULL)
514 nb_ScoreRules(nb_teams);
518 //=======================//
520 //=======================//
522 void SpawnBall(entity this)
524 if(!g_nexball) { remove(this); return; }
526 // balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
530 this.model = "models/nexball/ball.md3";
534 precache_model(this.model);
535 _setmodel(this, this.model);
536 setsize(this, BALL_MINS, BALL_MAXS);
537 ball_scale = this.scale;
539 relocate_nexball(this);
540 this.spawnorigin = this.origin;
542 this.effects = this.effects | EF_LOWPRECISION;
544 if(cvar(strcat("g_", this.classname, "_trail"))) //nexball_basketball :p
546 this.glow_color = autocvar_g_nexball_trail_color;
547 this.glow_trail = true;
550 this.movetype = MOVETYPE_FLY;
552 if(!autocvar_g_nexball_sound_bounce)
554 else if(this.noise == "")
555 this.noise = strzone(SND(NB_BOUNCE));
556 //bounce sound placeholder (FIXME)
557 if(this.noise1 == "")
558 this.noise1 = strzone(SND(NB_DROP));
559 //ball drop sound placeholder (FIXME)
560 if(this.noise2 == "")
561 this.noise2 = strzone(SND(NB_STEAL));
562 //stealing sound placeholder (FIXME)
563 if(this.noise) precache_sound(this.noise);
564 precache_sound(this.noise1);
565 precache_sound(this.noise2);
567 WaypointSprite_AttachCarrier(WP_NbBall, this, RADARICON_FLAGCARRIER); // the ball's team is not set yet, no rule update needed
569 this.reset = ball_restart;
570 setthink(this, InitBall);
571 this.nextthink = game_starttime + autocvar_g_nexball_delay_start;
574 spawnfunc(nexball_basketball)
576 nexball_mode |= NBM_BASKETBALL;
577 this.classname = "nexball_basketball";
578 if (!(balls & BALL_BASKET))
581 CVTOV(g_nexball_basketball_effects_default);
582 CVTOV(g_nexball_basketball_delay_hold);
583 CVTOV(g_nexball_basketball_delay_hold_forteam);
584 CVTOV(g_nexball_basketball_teamsteal);
586 autocvar_g_nexball_basketball_effects_default = autocvar_g_nexball_basketball_effects_default & BALL_EFFECTMASK;
589 this.effects = autocvar_g_nexball_basketball_effects_default;
590 this.solid = SOLID_TRIGGER;
591 this.pushable = autocvar_g_nexball_basketball_jumppad;
592 balls |= BALL_BASKET;
593 this.bouncefactor = autocvar_g_nexball_basketball_bouncefactor;
594 this.bouncestop = autocvar_g_nexball_basketball_bouncestop;
598 spawnfunc(nexball_football)
600 nexball_mode |= NBM_FOOTBALL;
601 this.classname = "nexball_football";
602 this.solid = SOLID_TRIGGER;
604 this.pushable = autocvar_g_nexball_football_jumppad;
605 this.bouncefactor = autocvar_g_nexball_football_bouncefactor;
606 this.bouncestop = autocvar_g_nexball_football_bouncestop;
610 float nb_Goal_Customize(entity this)
613 e = WaypointSprite_getviewentity(other);
614 wp_owner = this.owner;
615 if(SAME_TEAM(e, wp_owner)) { return false; }
620 void SpawnGoal(entity this)
622 if(!g_nexball) { remove(this); return; }
626 if(this.team != GOAL_OUT && Team_TeamToNumber(this.team) != -1)
628 entity wp = WaypointSprite_SpawnFixed(WP_NbGoal, (this.absmin + this.absmax) * 0.5, this, sprite, RADARICON_NONE);
629 wp.colormod = ((this.team) ? Team_ColorRGB(this.team) : '1 0.5 0');
630 setcefc(this.sprite, nb_Goal_Customize);
633 this.classname = "nexball_goal";
635 this.noise = "ctf/respawn.wav";
636 precache_sound(this.noise);
637 settouch(this, GoalTouch);
640 spawnfunc(nexball_redgoal)
642 this.team = NUM_TEAM_1;
645 spawnfunc(nexball_bluegoal)
647 this.team = NUM_TEAM_2;
650 spawnfunc(nexball_yellowgoal)
652 this.team = NUM_TEAM_3;
655 spawnfunc(nexball_pinkgoal)
657 this.team = NUM_TEAM_4;
661 spawnfunc(nexball_fault)
663 this.team = GOAL_FAULT;
665 this.noise = strzone(SND(TYPEHIT));
669 spawnfunc(nexball_out)
671 this.team = GOAL_OUT;
673 this.noise = strzone(SND(TYPEHIT));
678 //Spawnfuncs preserved for compatibility
683 spawnfunc_nexball_football(this);
685 spawnfunc(ball_football)
687 spawnfunc_nexball_football(this);
689 spawnfunc(ball_basketball)
691 spawnfunc_nexball_basketball(this);
693 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
694 spawnfunc(ball_redgoal)
696 spawnfunc_nexball_bluegoal(this); // I blame Revenant
698 spawnfunc(ball_bluegoal)
700 spawnfunc_nexball_redgoal(this); // but he didn't mean to cause trouble :p
702 spawnfunc(ball_fault)
704 spawnfunc_nexball_fault(this);
706 spawnfunc(ball_bound)
708 spawnfunc_nexball_out(this);
711 //=======================//
713 //=======================//
716 void W_Nexball_Think(entity this)
718 //dprint("W_Nexball_Think\n");
719 //vector new_dir = steerlib_arrive(this.enemy.origin, 2500);
720 vector new_dir = normalize(this.enemy.origin + '0 0 50' - this.origin);
721 vector old_dir = normalize(this.velocity);
722 float _speed = vlen(this.velocity);
723 vector new_vel = normalize(old_dir + (new_dir * autocvar_g_nexball_safepass_turnrate)) * _speed;
724 //vector new_vel = (new_dir * autocvar_g_nexball_safepass_turnrate
726 this.velocity = new_vel;
728 this.nextthink = time;
731 void W_Nexball_Touch(entity this)
733 entity ball, attacker;
734 attacker = this.owner;
735 //this.think = func_null;
738 PROJECTILE_TOUCH(this);
739 if(attacker.team != other.team || autocvar_g_nexball_basketball_teamsteal)
740 if((ball = other.ballcarried) && !STAT(FROZEN, other) && !IS_DEAD(other) && (IS_PLAYER(attacker)))
742 other.velocity = other.velocity + normalize(this.velocity) * other.damageforcescale * autocvar_g_balance_nexball_secondary_force;
743 UNSET_ONGROUND(other);
744 if(!attacker.ballcarried)
746 LogNB("stole", attacker);
747 _sound(other, CH_TRIGGER, ball.noise2, VOL_BASE, ATTEN_NORM);
749 if(SAME_TEAM(attacker, other) && time > attacker.teamkill_complain)
751 attacker.teamkill_complain = time + 5;
752 attacker.teamkill_soundtime = time + 0.4;
753 attacker.teamkill_soundsource = other;
756 GiveBall(attacker, other.ballcarried);
762 void W_Nexball_Attack(entity actor, float t)
766 if(!(ball = actor.ballcarried))
769 W_SetupShot(actor, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
770 tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, NULL);
774 actor.metertime = 0; // Shot failed, hide the power meter
778 //Calculate multiplier
783 mi = autocvar_g_nexball_basketball_meter_minpower;
784 ma = max(mi, autocvar_g_nexball_basketball_meter_maxpower); // avoid confusion
785 //One triangle wave period with 1 as max
786 mul = 2 * (t % g_nexball_meter_period) / g_nexball_meter_period;
789 mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
792 DropBall(ball, w_shotorg, W_CalculateProjectileVelocity(actor, actor.velocity, w_shotdir * autocvar_g_balance_nexball_primary_speed * mul, false));
795 //TODO: use the speed_up cvar too ??
798 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht);
800 void W_Nexball_Attack2(entity actor)
802 if(actor.ballcarried.enemy)
804 entity _ball = actor.ballcarried;
805 W_SetupShot(actor, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
806 DropBall(_ball, w_shotorg, trigger_push_calculatevelocity(_ball.origin, _ball.enemy, 32));
807 setthink(_ball, W_Nexball_Think);
808 _ball.nextthink = time;
812 if(!autocvar_g_nexball_tackling)
815 W_SetupShot(actor, false, 2, SND_NB_SHOOT2, CH_WEAPON_A, 0);
816 entity missile = new(ballstealer);
818 missile.owner = actor;
820 missile.movetype = MOVETYPE_FLY;
821 PROJECTILE_MAKETRIGGER(missile);
823 //setmodel(missile, "models/elaser.mdl"); // precision set below
824 setsize(missile, '0 0 0', '0 0 0');
825 setorigin(missile, w_shotorg);
827 W_SetupProjVelocity_Basic(missile, autocvar_g_balance_nexball_secondary_speed, 0);
828 missile.angles = vectoangles(missile.velocity);
829 settouch(missile, W_Nexball_Touch);
830 setthink(missile, SUB_Remove);
831 missile.nextthink = time + autocvar_g_balance_nexball_secondary_lifetime; //FIXME: use a distance instead?
833 missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
834 missile.flags = FL_PROJECTILE;
836 CSQCProjectile(missile, true, PROJECTILE_ELECTRO, true);
839 float ball_customize(entity this)
843 this.effects &= ~EF_FLAME;
845 setcefc(this, func_null);
849 if(other == this.owner)
851 this.scale = autocvar_g_nexball_viewmodel_scale;
853 this.effects |= EF_FLAME;
855 this.effects &= ~EF_FLAME;
859 this.effects &= ~EF_FLAME;
866 METHOD(BallStealer, wr_think, void(BallStealer thiswep, entity actor, .entity weaponentity, int fire))
868 TC(BallStealer, thiswep);
870 if(weapon_prepareattack(thiswep, actor, weaponentity, false, autocvar_g_balance_nexball_primary_refire))
871 if(autocvar_g_nexball_basketball_meter)
873 if(actor.ballcarried && !actor.metertime)
874 actor.metertime = time;
876 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
880 W_Nexball_Attack(actor, -1);
881 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
884 if(weapon_prepareattack(thiswep, actor, weaponentity, true, autocvar_g_balance_nexball_secondary_refire))
886 W_Nexball_Attack2(actor);
887 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, autocvar_g_balance_nexball_secondary_animtime, w_ready);
890 if(!(fire & 1) && actor.metertime && actor.ballcarried)
892 W_Nexball_Attack(actor, time - actor.metertime);
893 // DropBall or stealing will set metertime back to 0
894 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
898 METHOD(BallStealer, wr_setup, void(BallStealer this, entity actor))
900 TC(BallStealer, this);
901 //weapon_setup(WEP_PORTO.m_id);
904 METHOD(BallStealer, wr_checkammo1, bool(BallStealer this, entity actor))
906 TC(BallStealer, this);
910 METHOD(BallStealer, wr_checkammo2, bool(BallStealer this, entity actor))
912 TC(BallStealer, this);
916 void nb_DropBall(entity player)
918 if(player.ballcarried && g_nexball)
919 DropBall(player.ballcarried, player.origin, player.velocity);
922 MUTATOR_HOOKFUNCTION(nb, ClientDisconnect)
924 entity player = M_ARGV(0, entity);
929 MUTATOR_HOOKFUNCTION(nb, PlayerDies)
931 entity frag_target = M_ARGV(2, entity);
933 nb_DropBall(frag_target);
936 MUTATOR_HOOKFUNCTION(nb, MakePlayerObserver)
938 entity player = M_ARGV(0, entity);
944 MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
946 entity player = M_ARGV(0, entity);
948 makevectors(player.v_angle);
949 if(nexball_mode & NBM_BASKETBALL)
951 if(player.ballcarried)
954 player.ballcarried.velocity = player.velocity;
955 setcefc(player.ballcarried, ball_customize);
957 vector org = player.origin + player.view_ofs +
958 v_forward * autocvar_g_nexball_viewmodel_offset.x +
959 v_right * autocvar_g_nexball_viewmodel_offset.y +
960 v_up * autocvar_g_nexball_viewmodel_offset.z;
961 setorigin(player.ballcarried, org);
964 if(autocvar_g_nexball_safepass_maxdist)
966 if(player.ballcarried.wait < time && player.ballcarried.enemy)
968 //centerprint(player, sprintf("Lost lock on %s", player.ballcarried.enemy.netname));
969 player.ballcarried.enemy = NULL;
973 //tracebox(player.origin + player.view_ofs, '-2 -2 -2', '2 2 2', player.origin + player.view_ofs + v_forward * autocvar_g_nexball_safepass_maxdist);
974 crosshair_trace(player);
976 IS_CLIENT(trace_ent) &&
977 !IS_DEAD(trace_ent) &&
978 trace_ent.team == player.team &&
979 vdist(trace_ent.origin - player.origin, <=, autocvar_g_nexball_safepass_maxdist) )
982 //if(player.ballcarried.enemy != trace_ent)
983 // centerprint(player, sprintf("Locked to %s", trace_ent.netname));
984 player.ballcarried.enemy = trace_ent;
985 player.ballcarried.wait = time + autocvar_g_nexball_safepass_holdtime;
993 .entity weaponentity = weaponentities[0]; // TODO
994 if(player.(weaponentity).weapons)
996 player.weapons = player.(weaponentity).weapons;
997 Weapon w = WEP_NEXBALL;
998 w.wr_resetplayer(w, player);
999 PS(player).m_switchweapon = player.(weaponentity).m_switchweapon;
1000 W_SwitchWeapon(player, PS(player).m_switchweapon);
1002 player.(weaponentity).weapons = '0 0 0';
1008 nexball_setstatus(player);
1011 MUTATOR_HOOKFUNCTION(nb, SpectateCopy)
1013 entity spectatee = M_ARGV(0, entity);
1014 entity client = M_ARGV(1, entity);
1016 client.metertime = spectatee.metertime;
1019 MUTATOR_HOOKFUNCTION(nb, PlayerSpawn)
1021 entity player = M_ARGV(0, entity);
1023 player.metertime = 0;
1024 .entity weaponentity = weaponentities[0];
1025 player.(weaponentity).weapons = '0 0 0';
1027 if (nexball_mode & NBM_BASKETBALL)
1028 player.weapons |= WEPSET(NEXBALL);
1030 player.weapons = '0 0 0';
1035 .float stat_sv_airspeedlimit_nonqw;
1036 .float stat_sv_maxspeed;
1038 MUTATOR_HOOKFUNCTION(nb, PlayerPhysics)
1040 entity player = M_ARGV(0, entity);
1042 if(player.ballcarried)
1044 player.stat_sv_airspeedlimit_nonqw *= autocvar_g_nexball_basketball_carrier_highspeed;
1045 player.stat_sv_maxspeed *= autocvar_g_nexball_basketball_carrier_highspeed;
1049 MUTATOR_HOOKFUNCTION(nb, ForbidThrowCurrentWeapon)
1051 entity player = M_ARGV(0, entity);
1053 return PS(player).m_weapon == WEP_NEXBALL;
1056 MUTATOR_HOOKFUNCTION(nb, ForbidDropCurrentWeapon)
1058 entity player = M_ARGV(0, entity);
1060 return PS(player).m_weapon == WEP_MORTAR; // TODO: what is this for?
1063 MUTATOR_HOOKFUNCTION(nb, FilterItem)
1065 entity item = M_ARGV(0, entity);
1067 if(item.classname == "droppedweapon")
1068 if(item.weapon == WEP_NEXBALL.m_id)
1074 MUTATOR_HOOKFUNCTION(nb, GetTeamCount)
1076 M_ARGV(1, string) = "nexball_team";
1080 MUTATOR_HOOKFUNCTION(nb, WantWeapon)
1082 M_ARGV(1, float) = 0; // weapon is set a few lines later, apparently
1086 MUTATOR_HOOKFUNCTION(nb, DropSpecialItems)
1088 entity frag_target = M_ARGV(0, entity);
1090 if(frag_target.ballcarried)
1091 DropBall(frag_target.ballcarried, frag_target.origin, frag_target.velocity);
1096 MUTATOR_HOOKFUNCTION(nb, SendWaypoint)
1098 M_ARGV(2, int) &= ~0x80;
1101 REGISTER_MUTATOR(nb, g_nexball)
1105 g_nexball_meter_period = autocvar_g_nexball_meter_period;
1106 if(g_nexball_meter_period <= 0)
1107 g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
1108 g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
1112 CVTOV(g_nexball_football_boost_forward); //100
1113 CVTOV(g_nexball_football_boost_up); //200
1114 CVTOV(g_nexball_delay_idle); //10
1115 CVTOV(g_nexball_football_physics); //0
1117 radar_showennemies = autocvar_g_nexball_radar_showallplayers;
1119 InitializeEntity(NULL, nb_delayedinit, INITPRIO_GAMETYPE);
1120 WEP_NEXBALL.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
1123 SetLimits(autocvar_g_nexball_goallimit, autocvar_g_nexball_goalleadlimit, autocvar_timelimit_override, -1);
1124 have_team_spawns = -1; // request team spawns
1127 MUTATOR_ONROLLBACK_OR_REMOVE
1129 WEP_NEXBALL.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
1130 // we actually cannot roll back nb_delayedinit here
1131 // BUT: we don't need to! If this gets called, adding always
1137 LOG_INFO("This is a game type and it cannot be removed at runtime.");