4 int autocvar_cl_eventchase_nexball = 1;
6 REGISTER_MUTATOR(cl_nb, true);
8 MUTATOR_HOOKFUNCTION(cl_nb, WantEventchase)
10 if(autocvar_cl_eventchase_nexball && gametype == MAPINFO_TYPE_NEXBALL && !(WepSet_GetFromStat() & WEPSET(NEXBALL)))
16 .float metertime = _STAT(NB_METERSTART);
18 int autocvar_g_nexball_goalleadlimit;
19 #define autocvar_g_nexball_goallimit cvar("g_nexball_goallimit")
21 bool autocvar_g_nexball_basketball_jumppad = true;
22 float autocvar_g_nexball_basketball_bouncefactor;
23 float autocvar_g_nexball_basketball_bouncestop;
24 float autocvar_g_nexball_basketball_carrier_highspeed;
25 bool autocvar_g_nexball_basketball_meter;
26 float autocvar_g_nexball_basketball_meter_maxpower;
27 float autocvar_g_nexball_basketball_meter_minpower;
28 float autocvar_g_nexball_delay_collect;
29 float autocvar_g_nexball_delay_goal;
30 float autocvar_g_nexball_delay_start;
31 bool autocvar_g_nexball_football_jumppad = true;
32 float autocvar_g_nexball_football_bouncefactor;
33 float autocvar_g_nexball_football_bouncestop;
34 bool autocvar_g_nexball_radar_showallplayers;
35 bool autocvar_g_nexball_sound_bounce;
36 int autocvar_g_nexball_trail_color;
37 bool autocvar_g_nexball_playerclip_collisions = true;
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, entity toucher);
56 void football_touch(entity this, entity toucher);
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(int 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 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_NEXBALL_RETURN_HELD));
108 entity e = this.ballcarried;
109 DropBall(this.ballcarried, this.ballcarried.owner.origin, '0 0 0');
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.weaponentity_fld = weaponentity;
172 ball.team = plyr.team;
173 plyr.ballcarried = ball;
174 ball.nb_dropper = plyr;
176 plyr.effects |= autocvar_g_nexball_basketball_effects_default;
177 ball.effects &= ~autocvar_g_nexball_basketball_effects_default;
179 ball.velocity = '0 0 0';
180 set_movetype(ball, MOVETYPE_NONE);
181 settouch(ball, func_null);
182 ball.effects |= EF_NOSHADOW;
183 ball.scale = 1; // scale down.
185 WaypointSprite_AttachCarrier(WP_NbBall, plyr, RADARICON_FLAGCARRIER);
186 WaypointSprite_UpdateRule(plyr.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
188 if(autocvar_g_nexball_basketball_delay_hold)
190 setthink(ball, DropOwner);
191 ball.nextthink = time + autocvar_g_nexball_basketball_delay_hold;
194 plyr.(weaponentity).weapons = plyr.weapons;
195 plyr.m_switchweapon = plyr.(weaponentity).m_weapon;
196 plyr.weapons = WEPSET(NEXBALL);
197 Weapon w = WEP_NEXBALL;
198 w.wr_resetplayer(w, plyr);
199 plyr.(weaponentity).m_switchweapon = WEP_NEXBALL;
200 W_SwitchWeapon(plyr, WEP_NEXBALL, weaponentity);
203 void DropBall(entity ball, vector org, vector vel)
205 ball.effects |= autocvar_g_nexball_basketball_effects_default;
206 ball.effects &= ~EF_NOSHADOW;
207 ball.owner.effects &= ~autocvar_g_nexball_basketball_effects_default;
209 setattachment(ball, NULL, "");
210 setorigin(ball, org);
211 set_movetype(ball, MOVETYPE_BOUNCE);
212 UNSET_ONGROUND(ball);
213 ball.scale = ball_scale;
215 ball.nb_droptime = time;
216 settouch(ball, basketball_touch);
217 setthink(ball, ResetBall);
218 ball.nextthink = min(time + autocvar_g_nexball_delay_idle, ball.teamtime);
220 if(ball.owner.metertime)
222 ball.owner.metertime = 0;
223 .entity weaponentity = ball.weaponentity_fld;
224 ball.owner.(weaponentity).state = WS_READY;
227 WaypointSprite_Kill(ball.owner.waypointsprite_attachedforcarrier);
228 WaypointSprite_Spawn(WP_NbBall, 0, 0, ball, '0 0 64', NULL, ball.team, ball, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER); // no health bar please
229 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
231 ball.owner.ballcarried = NULL;
235 void InitBall(entity this)
237 if(game_stopped) return;
238 UNSET_ONGROUND(this);
239 set_movetype(this, MOVETYPE_BOUNCE);
240 if(this.classname == "nexball_basketball")
241 settouch(this, basketball_touch);
242 else if(this.classname == "nexball_football")
243 settouch(this, football_touch);
245 setthink(this, ResetBall);
246 this.nextthink = time + autocvar_g_nexball_delay_idle + 3;
250 _sound(this, CH_TRIGGER, this.noise1, VOL_BASE, ATTEN_NORM);
251 WaypointSprite_Ping(this.waypointsprite_attachedforcarrier);
255 void ResetBall(entity this)
257 if(this.cnt < 2) // step 1
259 if(time == this.teamtime)
260 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_NEXBALL_RETURN_HELD));
262 settouch(this, func_null);
263 set_movetype(this, MOVETYPE_NOCLIP);
264 this.velocity = '0 0 0'; // just in case?
266 LogNB("resetidle", NULL);
268 this.nextthink = time;
270 else if(this.cnt < 4) // step 2 and 3
272 // dprint("Step ", ftos(this.cnt), ": Calculated velocity: ", vtos(this.spawnorigin - this.origin), ", time: ", ftos(time), "\n");
273 this.velocity = (this.spawnorigin - this.origin) * (this.cnt - 1); // 1 or 0.5 second movement
274 this.nextthink = time + 0.5;
279 // dprint("Step 4: time: ", ftos(time), "\n");
280 if(vdist(this.origin - this.spawnorigin, >, 10)) // should not happen anymore
281 LOG_TRACE("The ball moved too far away from its spawn origin.\nOffset: ",
282 vtos(this.origin - this.spawnorigin), " Velocity: ", vtos(this.velocity), "\n");
283 this.velocity = '0 0 0';
284 setorigin(this, this.spawnorigin); // make sure it's positioned correctly anyway
285 set_movetype(this, MOVETYPE_NONE);
286 setthink(this, InitBall);
287 this.nextthink = max(time, game_starttime) + autocvar_g_nexball_delay_start;
291 void football_touch(entity this, entity toucher)
293 if(toucher.solid == SOLID_BSP)
295 if(time > this.lastground + 0.1)
297 _sound(this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
298 this.lastground = time;
300 if(this.velocity && !this.cnt)
301 this.nextthink = time + autocvar_g_nexball_delay_idle;
304 if (!IS_PLAYER(toucher))
306 if(toucher.health < 1)
309 this.nextthink = time + autocvar_g_nexball_delay_idle;
311 this.pusher = toucher;
312 this.team = toucher.team;
314 if(autocvar_g_nexball_football_physics == -1) // MrBougo try 1, before decompiling Rev's original
317 this.velocity = toucher.velocity * 1.5 + '0 0 1' * autocvar_g_nexball_football_boost_up;
319 else if(autocvar_g_nexball_football_physics == 1) // MrBougo's modded Rev style: partially independant of the height of the aiming point
321 makevectors(toucher.v_angle);
322 this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + '0 0 1' * autocvar_g_nexball_football_boost_up;
324 else if(autocvar_g_nexball_football_physics == 2) // 2nd mod try: totally independant. Really playable!
326 makevectors(toucher.v_angle.y * '0 1 0');
327 this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
329 else // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
331 makevectors(toucher.v_angle);
332 this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
334 this.avelocity = -250 * v_forward; // maybe there is a way to make it look better?
337 void basketball_touch(entity this, entity toucher)
339 if(toucher.ballcarried)
341 football_touch(this, toucher);
344 if(!this.cnt && IS_PLAYER(toucher) && !STAT(FROZEN, toucher) && !IS_DEAD(toucher) && (toucher != this.nb_dropper || time > this.nb_droptime + autocvar_g_nexball_delay_collect))
346 if(toucher.health <= 0)
348 LogNB("caught", toucher);
349 GiveBall(toucher, this);
351 else if(toucher.solid == SOLID_BSP)
353 _sound(this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
354 if(this.velocity && !this.cnt)
355 this.nextthink = min(time + autocvar_g_nexball_delay_idle, this.teamtime);
359 void GoalTouch(entity this, entity toucher)
362 float isclient, pscore, otherteam;
365 if(game_stopped) return;
366 if((this.spawnflags & GOAL_TOUCHPLAYER) && toucher.ballcarried)
367 ball = toucher.ballcarried;
370 if(ball.classname != "nexball_basketball")
371 if(ball.classname != "nexball_football")
373 if((!ball.pusher && this.team != GOAL_OUT) || ball.cnt)
375 EXACTTRIGGER_TOUCH(this, toucher);
378 if(NumTeams(nb_teams) == 2)
379 otherteam = OtherTeam(ball.team);
383 if((isclient = IS_CLIENT(ball.pusher)))
384 pname = ball.pusher.netname;
386 pname = "Someone (?)";
388 if(ball.team == this.team) //owngoal (regular goals)
390 LogNB("owngoal", ball.pusher);
391 bprint("Boo! ", pname, "^7 scored a goal against their own team!\n");
394 else if(this.team == GOAL_FAULT)
396 LogNB("fault", ball.pusher);
397 if(NumTeams(nb_teams) == 2)
398 bprint(Team_ColoredFullName(otherteam), " gets a point due to ", pname, "^7's silliness.\n");
400 bprint(Team_ColoredFullName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
403 else if(this.team == GOAL_OUT)
405 LogNB("out", ball.pusher);
406 if((this.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
407 bprint(pname, "^7 went out of bounds.\n");
409 bprint("The ball was returned.\n");
414 LogNB(strcat("goal:", ftos(this.team)), ball.pusher);
415 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", Team_ColoredFullName(ball.team), ".\n");
419 _sound(ball, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NONE);
421 if(ball.team && pscore)
423 if(NumTeams(nb_teams) == 2 && pscore < 0)
424 TeamScore_AddToTeam(otherteam, ST_NEXBALL_GOALS, -pscore);
426 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
431 PlayerScore_Add(ball.pusher, SP_NEXBALL_GOALS, pscore);
433 PlayerScore_Add(ball.pusher, SP_NEXBALL_FAULTS, -pscore);
436 if(ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
437 DropBall(ball, ball.owner.origin, ball.owner.velocity);
439 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
442 setthink(ball, ResetBall);
443 if(ball.classname == "nexball_basketball")
444 settouch(ball, football_touch); // better than func_null: football control until the ball gets reset
445 ball.nextthink = time + autocvar_g_nexball_delay_goal * (this.team != GOAL_OUT);
448 //=======================//
450 //=======================//
451 spawnfunc(nexball_team)
458 this.team = this.cnt + 1;
461 void nb_spawnteam(string teamname, float teamcolor)
463 LOG_TRACE("^2spawned team ", teamname);
464 entity e = new(nexball_team);
465 e.netname = teamname;
473 bool t_red = false, t_blue = false, t_yellow = false, t_pink = false;
475 for(e = NULL; (e = find(e, classname, "nexball_goal"));)
482 nb_spawnteam("Red", e.team-1) ;
490 nb_spawnteam("Blue", e.team-1) ;
498 nb_spawnteam("Yellow", e.team-1);
506 nb_spawnteam("Pink", e.team-1) ;
515 void nb_delayedinit(entity this)
517 if(find(NULL, classname, "nexball_team") == NULL)
519 nb_ScoreRules(nb_teams);
523 //=======================//
525 //=======================//
527 void SpawnBall(entity this)
529 if(!g_nexball) { delete(this); return; }
531 // balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
535 this.model = "models/nexball/ball.md3";
539 precache_model(this.model);
540 _setmodel(this, this.model);
541 setsize(this, BALL_MINS, BALL_MAXS);
542 ball_scale = this.scale;
544 relocate_nexball(this);
545 this.spawnorigin = this.origin;
547 this.effects = this.effects | EF_LOWPRECISION;
549 if(cvar(strcat("g_", this.classname, "_trail"))) //nexball_basketball :p
551 this.glow_color = autocvar_g_nexball_trail_color;
552 this.glow_trail = true;
555 set_movetype(this, MOVETYPE_FLY);
557 if(autocvar_g_nexball_playerclip_collisions)
558 this.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP;
560 if(!autocvar_g_nexball_sound_bounce)
562 else if(this.noise == "")
563 this.noise = strzone(SND(NB_BOUNCE));
564 //bounce sound placeholder (FIXME)
565 if(this.noise1 == "")
566 this.noise1 = strzone(SND(NB_DROP));
567 //ball drop sound placeholder (FIXME)
568 if(this.noise2 == "")
569 this.noise2 = strzone(SND(NB_STEAL));
570 //stealing sound placeholder (FIXME)
571 if(this.noise) precache_sound(this.noise);
572 precache_sound(this.noise1);
573 precache_sound(this.noise2);
575 WaypointSprite_AttachCarrier(WP_NbBall, this, RADARICON_FLAGCARRIER); // the ball's team is not set yet, no rule update needed
577 this.reset = ball_restart;
578 setthink(this, InitBall);
579 this.nextthink = game_starttime + autocvar_g_nexball_delay_start;
582 spawnfunc(nexball_basketball)
584 nexball_mode |= NBM_BASKETBALL;
585 this.classname = "nexball_basketball";
586 if (!(balls & BALL_BASKET))
589 CVTOV(g_nexball_basketball_effects_default);
590 CVTOV(g_nexball_basketball_delay_hold);
591 CVTOV(g_nexball_basketball_delay_hold_forteam);
592 CVTOV(g_nexball_basketball_teamsteal);
594 autocvar_g_nexball_basketball_effects_default = autocvar_g_nexball_basketball_effects_default & BALL_EFFECTMASK;
597 this.effects = autocvar_g_nexball_basketball_effects_default;
598 this.solid = SOLID_TRIGGER;
599 this.pushable = autocvar_g_nexball_basketball_jumppad;
600 balls |= BALL_BASKET;
601 this.bouncefactor = autocvar_g_nexball_basketball_bouncefactor;
602 this.bouncestop = autocvar_g_nexball_basketball_bouncestop;
606 spawnfunc(nexball_football)
608 nexball_mode |= NBM_FOOTBALL;
609 this.classname = "nexball_football";
610 this.solid = SOLID_TRIGGER;
612 this.pushable = autocvar_g_nexball_football_jumppad;
613 this.bouncefactor = autocvar_g_nexball_football_bouncefactor;
614 this.bouncestop = autocvar_g_nexball_football_bouncestop;
618 bool nb_Goal_Customize(entity this, entity client)
620 entity e = WaypointSprite_getviewentity(client);
621 entity wp_owner = this.owner;
622 if(SAME_TEAM(e, wp_owner)) { return false; }
627 void SpawnGoal(entity this)
629 if(!g_nexball) { delete(this); return; }
633 if(this.team != GOAL_OUT && Team_TeamToNumber(this.team) != -1)
635 entity wp = WaypointSprite_SpawnFixed(WP_NbGoal, (this.absmin + this.absmax) * 0.5, this, sprite, RADARICON_NONE);
636 wp.colormod = ((this.team) ? Team_ColorRGB(this.team) : '1 0.5 0');
637 setcefc(this.sprite, nb_Goal_Customize);
640 this.classname = "nexball_goal";
642 this.noise = "ctf/respawn.wav";
643 precache_sound(this.noise);
644 settouch(this, GoalTouch);
647 spawnfunc(nexball_redgoal)
649 this.team = NUM_TEAM_1;
652 spawnfunc(nexball_bluegoal)
654 this.team = NUM_TEAM_2;
657 spawnfunc(nexball_yellowgoal)
659 this.team = NUM_TEAM_3;
662 spawnfunc(nexball_pinkgoal)
664 this.team = NUM_TEAM_4;
668 spawnfunc(nexball_fault)
670 this.team = GOAL_FAULT;
672 this.noise = strzone(SND(TYPEHIT));
676 spawnfunc(nexball_out)
678 this.team = GOAL_OUT;
680 this.noise = strzone(SND(TYPEHIT));
685 //Spawnfuncs preserved for compatibility
690 spawnfunc_nexball_football(this);
692 spawnfunc(ball_football)
694 spawnfunc_nexball_football(this);
696 spawnfunc(ball_basketball)
698 spawnfunc_nexball_basketball(this);
700 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
701 spawnfunc(ball_redgoal)
703 spawnfunc_nexball_bluegoal(this); // I blame Revenant
705 spawnfunc(ball_bluegoal)
707 spawnfunc_nexball_redgoal(this); // but he didn't mean to cause trouble :p
709 spawnfunc(ball_fault)
711 spawnfunc_nexball_fault(this);
713 spawnfunc(ball_bound)
715 spawnfunc_nexball_out(this);
718 //=======================//
720 //=======================//
723 void W_Nexball_Think(entity this)
725 //dprint("W_Nexball_Think\n");
726 //vector new_dir = steerlib_arrive(this.enemy.origin, 2500);
727 vector new_dir = normalize(this.enemy.origin + '0 0 50' - this.origin);
728 vector old_dir = normalize(this.velocity);
729 float _speed = vlen(this.velocity);
730 vector new_vel = normalize(old_dir + (new_dir * autocvar_g_nexball_safepass_turnrate)) * _speed;
731 //vector new_vel = (new_dir * autocvar_g_nexball_safepass_turnrate
733 this.velocity = new_vel;
735 this.nextthink = time;
738 void W_Nexball_Touch(entity this, entity toucher)
740 entity ball, attacker;
741 attacker = this.owner;
742 //this.think = func_null;
745 PROJECTILE_TOUCH(this, toucher);
746 if(attacker.team != toucher.team || autocvar_g_nexball_basketball_teamsteal)
747 if((ball = toucher.ballcarried) && !STAT(FROZEN, toucher) && !IS_DEAD(toucher) && (IS_PLAYER(attacker)))
749 toucher.velocity = toucher.velocity + normalize(this.velocity) * toucher.damageforcescale * autocvar_g_balance_nexball_secondary_force;
750 UNSET_ONGROUND(toucher);
751 if(!attacker.ballcarried)
753 LogNB("stole", attacker);
754 _sound(toucher, CH_TRIGGER, ball.noise2, VOL_BASE, ATTEN_NORM);
756 if(SAME_TEAM(attacker, toucher) && time > attacker.teamkill_complain)
758 attacker.teamkill_complain = time + 5;
759 attacker.teamkill_soundtime = time + 0.4;
760 attacker.teamkill_soundsource = toucher;
763 GiveBall(attacker, toucher.ballcarried);
769 void W_Nexball_Attack(entity actor, .entity weaponentity, float t)
773 if(!(ball = actor.ballcarried))
776 W_SetupShot(actor, weaponentity, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
777 tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, NULL);
781 actor.metertime = 0; // Shot failed, hide the power meter
785 //Calculate multiplier
790 mi = autocvar_g_nexball_basketball_meter_minpower;
791 ma = max(mi, autocvar_g_nexball_basketball_meter_maxpower); // avoid confusion
792 //One triangle wave period with 1 as max
793 mul = 2 * (t % g_nexball_meter_period) / g_nexball_meter_period;
796 mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
799 DropBall(ball, w_shotorg, W_CalculateProjectileVelocity(actor, actor.velocity, w_shotdir * autocvar_g_balance_nexball_primary_speed * mul, false));
802 //TODO: use the speed_up cvar too ??
805 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht);
807 void W_Nexball_Attack2(entity actor, .entity weaponentity)
809 if(actor.ballcarried.enemy)
811 entity _ball = actor.ballcarried;
812 W_SetupShot(actor, weaponentity, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
813 DropBall(_ball, w_shotorg, trigger_push_calculatevelocity(_ball.origin, _ball.enemy, 32));
814 setthink(_ball, W_Nexball_Think);
815 _ball.nextthink = time;
819 if(!autocvar_g_nexball_tackling)
822 W_SetupShot(actor, weaponentity, false, 2, SND_NB_SHOOT2, CH_WEAPON_A, 0);
823 entity missile = new(ballstealer);
825 missile.owner = actor;
827 set_movetype(missile, MOVETYPE_FLY);
828 PROJECTILE_MAKETRIGGER(missile);
830 //setmodel(missile, "models/elaser.mdl"); // precision set below
831 setsize(missile, '0 0 0', '0 0 0');
832 setorigin(missile, w_shotorg);
834 W_SetupProjVelocity_Basic(missile, autocvar_g_balance_nexball_secondary_speed, 0);
835 missile.angles = vectoangles(missile.velocity);
836 settouch(missile, W_Nexball_Touch);
837 setthink(missile, SUB_Remove);
838 missile.nextthink = time + autocvar_g_balance_nexball_secondary_lifetime; //FIXME: use a distance instead?
840 missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
841 missile.flags = FL_PROJECTILE;
842 IL_PUSH(g_projectiles, missile);
843 IL_PUSH(g_bot_dodge, missile);
845 CSQCProjectile(missile, true, PROJECTILE_ELECTRO, true);
848 bool ball_customize(entity this, entity client)
852 this.effects &= ~EF_FLAME;
854 setcefc(this, func_null);
858 if(client == this.owner)
860 this.scale = autocvar_g_nexball_viewmodel_scale;
862 this.effects |= EF_FLAME;
864 this.effects &= ~EF_FLAME;
868 this.effects &= ~EF_FLAME;
875 METHOD(BallStealer, wr_think, void(BallStealer thiswep, entity actor, .entity weaponentity, int fire))
877 TC(BallStealer, thiswep);
879 if(weapon_prepareattack(thiswep, actor, weaponentity, false, autocvar_g_balance_nexball_primary_refire))
880 if(autocvar_g_nexball_basketball_meter)
882 if(actor.ballcarried && !actor.metertime)
883 actor.metertime = time;
885 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
889 W_Nexball_Attack(actor, weaponentity, -1);
890 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
893 if(weapon_prepareattack(thiswep, actor, weaponentity, true, autocvar_g_balance_nexball_secondary_refire))
895 W_Nexball_Attack2(actor, weaponentity);
896 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, autocvar_g_balance_nexball_secondary_animtime, w_ready);
899 if(!(fire & 1) && actor.metertime && actor.ballcarried)
901 W_Nexball_Attack(actor, weaponentity, time - actor.metertime);
902 // DropBall or stealing will set metertime back to 0
903 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
907 METHOD(BallStealer, wr_setup, void(BallStealer this, entity actor, .entity weaponentity))
909 TC(BallStealer, this);
910 //weapon_setup(WEP_PORTO.m_id);
913 METHOD(BallStealer, wr_checkammo1, bool(BallStealer this, entity actor, .entity weaponentity))
915 TC(BallStealer, this);
919 METHOD(BallStealer, wr_checkammo2, bool(BallStealer this, entity actor, .entity weaponentity))
921 TC(BallStealer, this);
925 void nb_DropBall(entity player)
927 if(player.ballcarried && g_nexball)
928 DropBall(player.ballcarried, player.origin, player.velocity);
931 MUTATOR_HOOKFUNCTION(nb, ClientDisconnect)
933 entity player = M_ARGV(0, entity);
938 MUTATOR_HOOKFUNCTION(nb, PlayerDies)
940 entity frag_target = M_ARGV(2, entity);
942 nb_DropBall(frag_target);
945 MUTATOR_HOOKFUNCTION(nb, MakePlayerObserver)
947 entity player = M_ARGV(0, entity);
953 MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
955 entity player = M_ARGV(0, entity);
957 makevectors(player.v_angle);
958 if(nexball_mode & NBM_BASKETBALL)
960 if(player.ballcarried)
963 player.ballcarried.velocity = player.velocity;
964 setcefc(player.ballcarried, ball_customize);
966 vector org = player.origin + player.view_ofs +
967 v_forward * autocvar_g_nexball_viewmodel_offset.x +
968 v_right * autocvar_g_nexball_viewmodel_offset.y +
969 v_up * autocvar_g_nexball_viewmodel_offset.z;
970 setorigin(player.ballcarried, org);
973 if(autocvar_g_nexball_safepass_maxdist)
975 if(player.ballcarried.wait < time && player.ballcarried.enemy)
977 //centerprint(player, sprintf("Lost lock on %s", player.ballcarried.enemy.netname));
978 player.ballcarried.enemy = NULL;
982 //tracebox(player.origin + player.view_ofs, '-2 -2 -2', '2 2 2', player.origin + player.view_ofs + v_forward * autocvar_g_nexball_safepass_maxdist);
983 crosshair_trace(player);
985 IS_CLIENT(trace_ent) &&
986 !IS_DEAD(trace_ent) &&
987 trace_ent.team == player.team &&
988 vdist(trace_ent.origin - player.origin, <=, autocvar_g_nexball_safepass_maxdist) )
991 //if(player.ballcarried.enemy != trace_ent)
992 // centerprint(player, sprintf("Locked to %s", trace_ent.netname));
993 player.ballcarried.enemy = trace_ent;
994 player.ballcarried.wait = time + autocvar_g_nexball_safepass_holdtime;
1002 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1004 .entity weaponentity = weaponentities[slot];
1006 if(player.(weaponentity).weapons)
1008 player.weapons = player.(weaponentity).weapons;
1009 Weapon w = WEP_NEXBALL;
1010 w.wr_resetplayer(w, player);
1011 player.(weaponentity).m_switchweapon = player.m_switchweapon;
1012 W_SwitchWeapon(player, player.(weaponentity).m_switchweapon, weaponentity);
1014 player.(weaponentity).weapons = '0 0 0';
1021 nexball_setstatus(player);
1024 MUTATOR_HOOKFUNCTION(nb, SpectateCopy)
1026 entity spectatee = M_ARGV(0, entity);
1027 entity client = M_ARGV(1, entity);
1029 client.metertime = spectatee.metertime;
1032 MUTATOR_HOOKFUNCTION(nb, PlayerSpawn)
1034 entity player = M_ARGV(0, entity);
1036 player.metertime = 0;
1037 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1039 .entity weaponentity = weaponentities[slot];
1040 player.(weaponentity).weapons = '0 0 0';
1043 if (nexball_mode & NBM_BASKETBALL)
1044 player.weapons |= WEPSET(NEXBALL);
1046 player.weapons = '0 0 0';
1051 .float stat_sv_airspeedlimit_nonqw;
1052 .float stat_sv_maxspeed;
1054 MUTATOR_HOOKFUNCTION(nb, PlayerPhysics)
1056 entity player = M_ARGV(0, entity);
1058 if(player.ballcarried)
1060 player.stat_sv_airspeedlimit_nonqw *= autocvar_g_nexball_basketball_carrier_highspeed;
1061 player.stat_sv_maxspeed *= autocvar_g_nexball_basketball_carrier_highspeed;
1065 MUTATOR_HOOKFUNCTION(nb, ForbidThrowCurrentWeapon)
1067 //entity player = M_ARGV(0, entity);
1068 entity wepent = M_ARGV(1, entity);
1070 return wepent.m_weapon == WEP_NEXBALL;
1073 MUTATOR_HOOKFUNCTION(nb, ForbidDropCurrentWeapon)
1075 //entity player = M_ARGV(0, entity);
1076 int wep = M_ARGV(1, int);
1078 return wep == WEP_MORTAR.m_id; // TODO: what is this for?
1081 MUTATOR_HOOKFUNCTION(nb, FilterItem)
1083 entity item = M_ARGV(0, entity);
1085 if(item.classname == "droppedweapon")
1086 if(item.weapon == WEP_NEXBALL.m_id)
1092 MUTATOR_HOOKFUNCTION(nb, ItemTouch)
1094 entity item = M_ARGV(0, entity);
1095 entity toucher = M_ARGV(1, entity);
1097 if(item.weapon && toucher.ballcarried)
1098 return MUT_ITEMTOUCH_RETURN; // no new weapons for you, mister!
1100 return MUT_ITEMTOUCH_CONTINUE;
1103 MUTATOR_HOOKFUNCTION(nb, CheckAllowedTeams)
1105 M_ARGV(1, string) = "nexball_team";
1109 MUTATOR_HOOKFUNCTION(nb, WantWeapon)
1111 M_ARGV(1, float) = 0; // weapon is set a few lines later, apparently
1115 MUTATOR_HOOKFUNCTION(nb, DropSpecialItems)
1117 entity frag_target = M_ARGV(0, entity);
1119 if(frag_target.ballcarried)
1120 DropBall(frag_target.ballcarried, frag_target.origin, frag_target.velocity);
1125 MUTATOR_HOOKFUNCTION(nb, SendWaypoint)
1127 M_ARGV(2, int) &= ~0x80;
1130 REGISTER_MUTATOR(nb, g_nexball)
1134 g_nexball_meter_period = autocvar_g_nexball_meter_period;
1135 if(g_nexball_meter_period <= 0)
1136 g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
1137 g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
1141 CVTOV(g_nexball_football_boost_forward); //100
1142 CVTOV(g_nexball_football_boost_up); //200
1143 CVTOV(g_nexball_delay_idle); //10
1144 CVTOV(g_nexball_football_physics); //0
1146 radar_showennemies = autocvar_g_nexball_radar_showallplayers;
1148 InitializeEntity(NULL, nb_delayedinit, INITPRIO_GAMETYPE);
1149 WEP_NEXBALL.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
1152 SetLimits(autocvar_g_nexball_goallimit, autocvar_g_nexball_goalleadlimit, autocvar_timelimit_override, -1);
1153 have_team_spawns = -1; // request team spawns
1156 MUTATOR_ONROLLBACK_OR_REMOVE
1158 WEP_NEXBALL.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
1159 // we actually cannot roll back nb_delayedinit here
1160 // BUT: we don't need to! If this gets called, adding always
1166 LOG_INFO("This is a game type and it cannot be removed at runtime.");