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 const float SP_NEXBALL_GOALS = 4;
74 const float SP_NEXBALL_FAULTS = 5;
75 void nb_ScoreRules(int teams)
77 ScoreRules_basics(teams, 0, 0, true);
78 ScoreInfo_SetLabel_TeamScore( ST_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
79 ScoreInfo_SetLabel_PlayerScore( SP_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
80 ScoreInfo_SetLabel_PlayerScore(SP_NEXBALL_FAULTS, "faults", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER);
81 ScoreRules_basics_end();
84 void LogNB(string mode, entity actor)
87 if(!autocvar_sv_eventlog)
89 s = strcat(":nexball:", mode);
91 s = strcat(s, ":", ftos(actor.playerid));
95 void ball_restart(entity this)
98 DropBall(this, this.owner.origin, '0 0 0');
102 void nexball_setstatus(entity this)
104 this.items &= ~IT_KEY1;
107 if(this.ballcarried.teamtime && (this.ballcarried.teamtime < time))
109 bprint("The ", Team_ColoredFullName(this.team), " held the ball for too long.\n");
110 DropBall(this.ballcarried, this.ballcarried.owner.origin, '0 0 0');
111 entity e = this.ballcarried;
115 this.items |= IT_KEY1;
119 void relocate_nexball(entity this)
121 tracebox(this.origin, BALL_MINS, BALL_MAXS, this.origin, true, this);
126 if(!move_out_of_solid(this))
127 objerror(this, "could not get out of solid at all!");
128 LOG_INFO("^1NOTE: this map needs FIXING. ", this.classname, " at ", vtos(o - '0 0 1'));
129 LOG_INFO(" needs to be moved out of solid, e.g. by '", ftos(this.origin.x - o.x));
130 LOG_INFO(" ", ftos(this.origin.y - o.y));
131 LOG_INFO(" ", ftos(this.origin.z - o.z), "'\n");
136 void DropOwner(entity this)
140 DropBall(this, ownr.origin, ownr.velocity);
141 makevectors(ownr.v_angle.y * '0 1 0');
142 ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
143 UNSET_ONGROUND(ownr);
146 void GiveBall(entity plyr, entity ball)
148 .entity weaponentity = weaponentities[0]; // TODO: find ballstealer
149 entity ownr = ball.owner;
152 ownr.effects &= ~autocvar_g_nexball_basketball_effects_default;
153 ownr.ballcarried = NULL;
157 ownr.(weaponentity).state = WS_READY;
159 WaypointSprite_Kill(ownr.waypointsprite_attachedforcarrier);
163 WaypointSprite_Kill(ball.waypointsprite_attachedforcarrier);
166 //setattachment(ball, plyr, "");
167 setorigin(ball, plyr.origin + plyr.view_ofs);
169 if(ball.team != plyr.team)
170 ball.teamtime = time + autocvar_g_nexball_basketball_delay_hold_forteam;
172 ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
173 ball.team = plyr.team;
174 plyr.ballcarried = ball;
175 ball.nb_dropper = plyr;
177 plyr.effects |= autocvar_g_nexball_basketball_effects_default;
178 ball.effects &= ~autocvar_g_nexball_basketball_effects_default;
180 ball.velocity = '0 0 0';
181 ball.movetype = MOVETYPE_NONE;
182 settouch(ball, func_null);
183 ball.effects |= EF_NOSHADOW;
184 ball.scale = 1; // scale down.
186 WaypointSprite_AttachCarrier(WP_NbBall, plyr, RADARICON_FLAGCARRIER);
187 WaypointSprite_UpdateRule(plyr.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
189 if(autocvar_g_nexball_basketball_delay_hold)
191 setthink(ball, DropOwner);
192 ball.nextthink = time + autocvar_g_nexball_basketball_delay_hold;
195 plyr.(weaponentity).weapons = plyr.weapons;
196 plyr.(weaponentity).m_switchweapon = PS(plyr).m_weapon;
197 plyr.weapons = WEPSET(NEXBALL);
198 Weapon w = WEP_NEXBALL;
199 w.wr_resetplayer(w, plyr);
200 PS(plyr).m_switchweapon = WEP_NEXBALL;
201 W_SwitchWeapon(plyr, WEP_NEXBALL);
204 void DropBall(entity ball, vector org, vector vel)
206 ball.effects |= autocvar_g_nexball_basketball_effects_default;
207 ball.effects &= ~EF_NOSHADOW;
208 ball.owner.effects &= ~autocvar_g_nexball_basketball_effects_default;
210 setattachment(ball, NULL, "");
211 setorigin(ball, org);
212 ball.movetype = MOVETYPE_BOUNCE;
213 UNSET_ONGROUND(ball);
214 ball.scale = ball_scale;
216 ball.nb_droptime = time;
217 settouch(ball, basketball_touch);
218 setthink(ball, ResetBall);
219 ball.nextthink = min(time + autocvar_g_nexball_delay_idle, ball.teamtime);
221 if(ball.owner.metertime)
223 ball.owner.metertime = 0;
224 .entity weaponentity = weaponentities[0]; // TODO: find ballstealer
225 ball.owner.(weaponentity).state = WS_READY;
228 WaypointSprite_Kill(ball.owner.waypointsprite_attachedforcarrier);
229 WaypointSprite_Spawn(WP_NbBall, 0, 0, ball, '0 0 64', NULL, ball.team, ball, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER); // no health bar please
230 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
232 ball.owner.ballcarried = NULL;
236 void InitBall(entity this)
239 UNSET_ONGROUND(this);
240 this.movetype = MOVETYPE_BOUNCE;
241 if(this.classname == "nexball_basketball")
242 settouch(this, basketball_touch);
243 else if(this.classname == "nexball_football")
244 settouch(this, football_touch);
246 setthink(this, ResetBall);
247 this.nextthink = time + autocvar_g_nexball_delay_idle + 3;
251 _sound(this, CH_TRIGGER, this.noise1, VOL_BASE, ATTEN_NORM);
252 WaypointSprite_Ping(this.waypointsprite_attachedforcarrier);
256 void ResetBall(entity this)
258 if(this.cnt < 2) // step 1
260 if(time == this.teamtime)
261 bprint("The ", Team_ColoredFullName(this.team), " held the ball for too long.\n");
263 settouch(this, func_null);
264 this.movetype = MOVETYPE_NOCLIP;
265 this.velocity = '0 0 0'; // just in case?
267 LogNB("resetidle", NULL);
269 this.nextthink = time;
271 else if(this.cnt < 4) // step 2 and 3
273 // dprint("Step ", ftos(this.cnt), ": Calculated velocity: ", vtos(this.spawnorigin - this.origin), ", time: ", ftos(time), "\n");
274 this.velocity = (this.spawnorigin - this.origin) * (this.cnt - 1); // 1 or 0.5 second movement
275 this.nextthink = time + 0.5;
280 // dprint("Step 4: time: ", ftos(time), "\n");
281 if(vdist(this.origin - this.spawnorigin, >, 10)) // should not happen anymore
282 LOG_TRACE("The ball moved too far away from its spawn origin.\nOffset: ",
283 vtos(this.origin - this.spawnorigin), " Velocity: ", vtos(this.velocity), "\n");
284 this.velocity = '0 0 0';
285 setorigin(this, this.spawnorigin); // make sure it's positioned correctly anyway
286 this.movetype = MOVETYPE_NONE;
287 setthink(this, InitBall);
288 this.nextthink = max(time, game_starttime) + autocvar_g_nexball_delay_start;
292 void football_touch(entity this)
294 if(other.solid == SOLID_BSP)
296 if(time > this.lastground + 0.1)
298 _sound(this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
299 this.lastground = time;
301 if(this.velocity && !this.cnt)
302 this.nextthink = time + autocvar_g_nexball_delay_idle;
305 if (!IS_PLAYER(other))
310 this.nextthink = time + autocvar_g_nexball_delay_idle;
313 this.team = other.team;
315 if(autocvar_g_nexball_football_physics == -1) // MrBougo try 1, before decompiling Rev's original
318 this.velocity = other.velocity * 1.5 + '0 0 1' * autocvar_g_nexball_football_boost_up;
320 else if(autocvar_g_nexball_football_physics == 1) // MrBougo's modded Rev style: partially independant of the height of the aiming point
322 makevectors(other.v_angle);
323 this.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + '0 0 1' * autocvar_g_nexball_football_boost_up;
325 else if(autocvar_g_nexball_football_physics == 2) // 2nd mod try: totally independant. Really playable!
327 makevectors(other.v_angle.y * '0 1 0');
328 this.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
330 else // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
332 makevectors(other.v_angle);
333 this.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
335 this.avelocity = -250 * v_forward; // maybe there is a way to make it look better?
338 void basketball_touch(entity this)
340 if(other.ballcarried)
342 football_touch(this);
345 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))
347 if(other.health <= 0)
349 LogNB("caught", other);
350 GiveBall(other, this);
352 else if(other.solid == SOLID_BSP)
354 _sound(this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
355 if(this.velocity && !this.cnt)
356 this.nextthink = min(time + autocvar_g_nexball_delay_idle, this.teamtime);
360 void GoalTouch(entity this)
363 float isclient, pscore, otherteam;
367 if((this.spawnflags & GOAL_TOUCHPLAYER) && other.ballcarried)
368 ball = other.ballcarried;
371 if(ball.classname != "nexball_basketball")
372 if(ball.classname != "nexball_football")
374 if((!ball.pusher && this.team != GOAL_OUT) || ball.cnt)
379 if(NumTeams(nb_teams) == 2)
380 otherteam = OtherTeam(ball.team);
384 if((isclient = IS_CLIENT(ball.pusher)))
385 pname = ball.pusher.netname;
387 pname = "Someone (?)";
389 if(ball.team == this.team) //owngoal (regular goals)
391 LogNB("owngoal", ball.pusher);
392 bprint("Boo! ", pname, "^7 scored a goal against their own team!\n");
395 else if(this.team == GOAL_FAULT)
397 LogNB("fault", ball.pusher);
398 if(NumTeams(nb_teams) == 2)
399 bprint(Team_ColoredFullName(otherteam), " gets a point due to ", pname, "^7's silliness.\n");
401 bprint(Team_ColoredFullName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
404 else if(this.team == GOAL_OUT)
406 LogNB("out", ball.pusher);
407 if((this.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
408 bprint(pname, "^7 went out of bounds.\n");
410 bprint("The ball was returned.\n");
415 LogNB(strcat("goal:", ftos(this.team)), ball.pusher);
416 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", Team_ColoredFullName(ball.team), ".\n");
420 _sound(ball, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NONE);
422 if(ball.team && pscore)
424 if(NumTeams(nb_teams) == 2 && pscore < 0)
425 TeamScore_AddToTeam(otherteam, ST_NEXBALL_GOALS, -pscore);
427 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
432 PlayerScore_Add(ball.pusher, SP_NEXBALL_GOALS, pscore);
434 PlayerScore_Add(ball.pusher, SP_NEXBALL_FAULTS, -pscore);
437 if(ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
438 DropBall(ball, ball.owner.origin, ball.owner.velocity);
440 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
443 setthink(ball, ResetBall);
444 if(ball.classname == "nexball_basketball")
445 settouch(ball, football_touch); // better than func_null: football control until the ball gets reset
446 ball.nextthink = time + autocvar_g_nexball_delay_goal * (this.team != GOAL_OUT);
449 //=======================//
451 //=======================//
452 spawnfunc(nexball_team)
459 this.team = this.cnt + 1;
462 void nb_spawnteam(string teamname, float teamcolor)
464 LOG_TRACE("^2spawned team ", teamname, "\n");
465 entity e = new(nexball_team);
466 e.netname = teamname;
474 bool t_red = false, t_blue = false, t_yellow = false, t_pink = false;
476 for(e = NULL; (e = find(e, classname, "nexball_goal"));)
483 nb_spawnteam("Red", e.team-1) ;
491 nb_spawnteam("Blue", e.team-1) ;
499 nb_spawnteam("Yellow", e.team-1);
507 nb_spawnteam("Pink", e.team-1) ;
516 void nb_delayedinit(entity this)
518 if(find(NULL, classname, "nexball_team") == NULL)
520 nb_ScoreRules(nb_teams);
524 //=======================//
526 //=======================//
528 void SpawnBall(entity this)
530 if(!g_nexball) { remove(this); return; }
532 // balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
536 this.model = "models/nexball/ball.md3";
540 precache_model(this.model);
541 _setmodel(this, this.model);
542 setsize(this, BALL_MINS, BALL_MAXS);
543 ball_scale = this.scale;
545 relocate_nexball(this);
546 this.spawnorigin = this.origin;
548 this.effects = this.effects | EF_LOWPRECISION;
550 if(cvar(strcat("g_", this.classname, "_trail"))) //nexball_basketball :p
552 this.glow_color = autocvar_g_nexball_trail_color;
553 this.glow_trail = true;
556 this.movetype = MOVETYPE_FLY;
558 if(!autocvar_g_nexball_sound_bounce)
560 else if(this.noise == "")
561 this.noise = strzone(SND(NB_BOUNCE));
562 //bounce sound placeholder (FIXME)
563 if(this.noise1 == "")
564 this.noise1 = strzone(SND(NB_DROP));
565 //ball drop sound placeholder (FIXME)
566 if(this.noise2 == "")
567 this.noise2 = strzone(SND(NB_STEAL));
568 //stealing sound placeholder (FIXME)
569 if(this.noise) precache_sound(this.noise);
570 precache_sound(this.noise1);
571 precache_sound(this.noise2);
573 WaypointSprite_AttachCarrier(WP_NbBall, this, RADARICON_FLAGCARRIER); // the ball's team is not set yet, no rule update needed
575 this.reset = ball_restart;
576 setthink(this, InitBall);
577 this.nextthink = game_starttime + autocvar_g_nexball_delay_start;
580 spawnfunc(nexball_basketball)
582 nexball_mode |= NBM_BASKETBALL;
583 this.classname = "nexball_basketball";
584 if (!(balls & BALL_BASKET))
587 CVTOV(g_nexball_basketball_effects_default);
588 CVTOV(g_nexball_basketball_delay_hold);
589 CVTOV(g_nexball_basketball_delay_hold_forteam);
590 CVTOV(g_nexball_basketball_teamsteal);
592 autocvar_g_nexball_basketball_effects_default = autocvar_g_nexball_basketball_effects_default & BALL_EFFECTMASK;
595 this.effects = autocvar_g_nexball_basketball_effects_default;
596 this.solid = SOLID_TRIGGER;
597 this.pushable = autocvar_g_nexball_basketball_jumppad;
598 balls |= BALL_BASKET;
599 this.bouncefactor = autocvar_g_nexball_basketball_bouncefactor;
600 this.bouncestop = autocvar_g_nexball_basketball_bouncestop;
604 spawnfunc(nexball_football)
606 nexball_mode |= NBM_FOOTBALL;
607 this.classname = "nexball_football";
608 this.solid = SOLID_TRIGGER;
610 this.pushable = autocvar_g_nexball_football_jumppad;
611 this.bouncefactor = autocvar_g_nexball_football_bouncefactor;
612 this.bouncestop = autocvar_g_nexball_football_bouncestop;
616 float nb_Goal_Customize(entity this)
619 e = WaypointSprite_getviewentity(other);
620 wp_owner = this.owner;
621 if(SAME_TEAM(e, wp_owner)) { return false; }
626 void SpawnGoal(entity this)
628 if(!g_nexball) { remove(this); return; }
632 if(this.team != GOAL_OUT && Team_TeamToNumber(this.team) != -1)
634 entity wp = WaypointSprite_SpawnFixed(WP_NbGoal, (this.absmin + this.absmax) * 0.5, this, sprite, RADARICON_NONE);
635 wp.colormod = ((this.team) ? Team_ColorRGB(this.team) : '1 0.5 0');
636 setcefc(this.sprite, nb_Goal_Customize);
639 this.classname = "nexball_goal";
641 this.noise = "ctf/respawn.wav";
642 precache_sound(this.noise);
643 settouch(this, GoalTouch);
646 spawnfunc(nexball_redgoal)
648 this.team = NUM_TEAM_1;
651 spawnfunc(nexball_bluegoal)
653 this.team = NUM_TEAM_2;
656 spawnfunc(nexball_yellowgoal)
658 this.team = NUM_TEAM_3;
661 spawnfunc(nexball_pinkgoal)
663 this.team = NUM_TEAM_4;
667 spawnfunc(nexball_fault)
669 this.team = GOAL_FAULT;
671 this.noise = strzone(SND(TYPEHIT));
675 spawnfunc(nexball_out)
677 this.team = GOAL_OUT;
679 this.noise = strzone(SND(TYPEHIT));
684 //Spawnfuncs preserved for compatibility
689 spawnfunc_nexball_football(this);
691 spawnfunc(ball_football)
693 spawnfunc_nexball_football(this);
695 spawnfunc(ball_basketball)
697 spawnfunc_nexball_basketball(this);
699 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
700 spawnfunc(ball_redgoal)
702 spawnfunc_nexball_bluegoal(this); // I blame Revenant
704 spawnfunc(ball_bluegoal)
706 spawnfunc_nexball_redgoal(this); // but he didn't mean to cause trouble :p
708 spawnfunc(ball_fault)
710 spawnfunc_nexball_fault(this);
712 spawnfunc(ball_bound)
714 spawnfunc_nexball_out(this);
717 //=======================//
719 //=======================//
722 void W_Nexball_Think(entity this)
724 //dprint("W_Nexball_Think\n");
725 //vector new_dir = steerlib_arrive(this.enemy.origin, 2500);
726 vector new_dir = normalize(this.enemy.origin + '0 0 50' - this.origin);
727 vector old_dir = normalize(this.velocity);
728 float _speed = vlen(this.velocity);
729 vector new_vel = normalize(old_dir + (new_dir * autocvar_g_nexball_safepass_turnrate)) * _speed;
730 //vector new_vel = (new_dir * autocvar_g_nexball_safepass_turnrate
732 this.velocity = new_vel;
734 this.nextthink = time;
737 void W_Nexball_Touch(entity this)
739 entity ball, attacker;
740 attacker = this.owner;
741 //this.think = func_null;
744 PROJECTILE_TOUCH(this);
745 if(attacker.team != other.team || autocvar_g_nexball_basketball_teamsteal)
746 if((ball = other.ballcarried) && !STAT(FROZEN, other) && !IS_DEAD(other) && (IS_PLAYER(attacker)))
748 other.velocity = other.velocity + normalize(this.velocity) * other.damageforcescale * autocvar_g_balance_nexball_secondary_force;
749 UNSET_ONGROUND(other);
750 if(!attacker.ballcarried)
752 LogNB("stole", attacker);
753 _sound(other, CH_TRIGGER, ball.noise2, VOL_BASE, ATTEN_NORM);
755 if(SAME_TEAM(attacker, other) && time > attacker.teamkill_complain)
757 attacker.teamkill_complain = time + 5;
758 attacker.teamkill_soundtime = time + 0.4;
759 attacker.teamkill_soundsource = other;
762 GiveBall(attacker, other.ballcarried);
768 void W_Nexball_Attack(entity actor, float t)
772 if(!(ball = actor.ballcarried))
775 W_SetupShot(actor, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
776 tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, NULL);
780 actor.metertime = 0; // Shot failed, hide the power meter
784 //Calculate multiplier
789 mi = autocvar_g_nexball_basketball_meter_minpower;
790 ma = max(mi, autocvar_g_nexball_basketball_meter_maxpower); // avoid confusion
791 //One triangle wave period with 1 as max
792 mul = 2 * (t % g_nexball_meter_period) / g_nexball_meter_period;
795 mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
798 DropBall(ball, w_shotorg, W_CalculateProjectileVelocity(actor, actor.velocity, w_shotdir * autocvar_g_balance_nexball_primary_speed * mul, false));
801 //TODO: use the speed_up cvar too ??
804 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht);
806 void W_Nexball_Attack2(entity actor)
808 if(actor.ballcarried.enemy)
810 entity _ball = actor.ballcarried;
811 W_SetupShot(actor, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
812 DropBall(_ball, w_shotorg, trigger_push_calculatevelocity(_ball.origin, _ball.enemy, 32));
813 setthink(_ball, W_Nexball_Think);
814 _ball.nextthink = time;
818 if(!autocvar_g_nexball_tackling)
821 W_SetupShot(actor, false, 2, SND_NB_SHOOT2, CH_WEAPON_A, 0);
822 entity missile = new(ballstealer);
824 missile.owner = actor;
826 missile.movetype = MOVETYPE_FLY;
827 PROJECTILE_MAKETRIGGER(missile);
829 //setmodel(missile, "models/elaser.mdl"); // precision set below
830 setsize(missile, '0 0 0', '0 0 0');
831 setorigin(missile, w_shotorg);
833 W_SetupProjVelocity_Basic(missile, autocvar_g_balance_nexball_secondary_speed, 0);
834 missile.angles = vectoangles(missile.velocity);
835 settouch(missile, W_Nexball_Touch);
836 setthink(missile, SUB_Remove);
837 missile.nextthink = time + autocvar_g_balance_nexball_secondary_lifetime; //FIXME: use a distance instead?
839 missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
840 missile.flags = FL_PROJECTILE;
842 CSQCProjectile(missile, true, PROJECTILE_ELECTRO, true);
845 float ball_customize(entity this)
849 this.effects &= ~EF_FLAME;
851 setcefc(this, func_null);
855 if(other == this.owner)
857 this.scale = autocvar_g_nexball_viewmodel_scale;
859 this.effects |= EF_FLAME;
861 this.effects &= ~EF_FLAME;
865 this.effects &= ~EF_FLAME;
872 METHOD(BallStealer, wr_think, void(BallStealer thiswep, entity actor, .entity weaponentity, int fire))
874 TC(BallStealer, thiswep);
876 if(weapon_prepareattack(thiswep, actor, weaponentity, false, autocvar_g_balance_nexball_primary_refire))
877 if(autocvar_g_nexball_basketball_meter)
879 if(actor.ballcarried && !actor.metertime)
880 actor.metertime = time;
882 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
886 W_Nexball_Attack(actor, -1);
887 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
890 if(weapon_prepareattack(thiswep, actor, weaponentity, true, autocvar_g_balance_nexball_secondary_refire))
892 W_Nexball_Attack2(actor);
893 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, autocvar_g_balance_nexball_secondary_animtime, w_ready);
896 if(!(fire & 1) && actor.metertime && actor.ballcarried)
898 W_Nexball_Attack(actor, time - actor.metertime);
899 // DropBall or stealing will set metertime back to 0
900 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
904 METHOD(BallStealer, wr_setup, void(BallStealer this, entity actor))
906 TC(BallStealer, this);
907 //weapon_setup(WEP_PORTO.m_id);
910 METHOD(BallStealer, wr_checkammo1, bool(BallStealer this, entity actor))
912 TC(BallStealer, this);
916 METHOD(BallStealer, wr_checkammo2, bool(BallStealer this, entity actor))
918 TC(BallStealer, this);
922 void nb_DropBall(entity player)
924 if(player.ballcarried && g_nexball)
925 DropBall(player.ballcarried, player.origin, player.velocity);
928 MUTATOR_HOOKFUNCTION(nb, ClientDisconnect)
930 entity player = M_ARGV(0, entity);
935 MUTATOR_HOOKFUNCTION(nb, PlayerDies)
937 entity frag_target = M_ARGV(2, entity);
939 nb_DropBall(frag_target);
942 MUTATOR_HOOKFUNCTION(nb, MakePlayerObserver)
944 entity player = M_ARGV(0, entity);
950 MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
952 entity player = M_ARGV(0, entity);
954 makevectors(player.v_angle);
955 if(nexball_mode & NBM_BASKETBALL)
957 if(player.ballcarried)
960 player.ballcarried.velocity = player.velocity;
961 setcefc(player.ballcarried, ball_customize);
963 vector org = player.origin + player.view_ofs +
964 v_forward * autocvar_g_nexball_viewmodel_offset.x +
965 v_right * autocvar_g_nexball_viewmodel_offset.y +
966 v_up * autocvar_g_nexball_viewmodel_offset.z;
967 setorigin(player.ballcarried, org);
970 if(autocvar_g_nexball_safepass_maxdist)
972 if(player.ballcarried.wait < time && player.ballcarried.enemy)
974 //centerprint(player, sprintf("Lost lock on %s", player.ballcarried.enemy.netname));
975 player.ballcarried.enemy = NULL;
979 //tracebox(player.origin + player.view_ofs, '-2 -2 -2', '2 2 2', player.origin + player.view_ofs + v_forward * autocvar_g_nexball_safepass_maxdist);
980 crosshair_trace(player);
982 IS_CLIENT(trace_ent) &&
983 !IS_DEAD(trace_ent) &&
984 trace_ent.team == player.team &&
985 vdist(trace_ent.origin - player.origin, <=, autocvar_g_nexball_safepass_maxdist) )
988 //if(player.ballcarried.enemy != trace_ent)
989 // centerprint(player, sprintf("Locked to %s", trace_ent.netname));
990 player.ballcarried.enemy = trace_ent;
991 player.ballcarried.wait = time + autocvar_g_nexball_safepass_holdtime;
999 .entity weaponentity = weaponentities[0]; // TODO
1000 if(player.(weaponentity).weapons)
1002 player.weapons = player.(weaponentity).weapons;
1003 Weapon w = WEP_NEXBALL;
1004 w.wr_resetplayer(w, player);
1005 PS(player).m_switchweapon = player.(weaponentity).m_switchweapon;
1006 W_SwitchWeapon(player, PS(player).m_switchweapon);
1008 player.(weaponentity).weapons = '0 0 0';
1014 nexball_setstatus(player);
1017 MUTATOR_HOOKFUNCTION(nb, SpectateCopy)
1019 entity spectatee = M_ARGV(0, entity);
1020 entity client = M_ARGV(1, entity);
1022 client.metertime = spectatee.metertime;
1025 MUTATOR_HOOKFUNCTION(nb, PlayerSpawn)
1027 entity player = M_ARGV(0, entity);
1029 player.metertime = 0;
1030 .entity weaponentity = weaponentities[0];
1031 player.(weaponentity).weapons = '0 0 0';
1033 if (nexball_mode & NBM_BASKETBALL)
1034 player.weapons |= WEPSET(NEXBALL);
1036 player.weapons = '0 0 0';
1041 .float stat_sv_airspeedlimit_nonqw;
1042 .float stat_sv_maxspeed;
1044 MUTATOR_HOOKFUNCTION(nb, PlayerPhysics)
1046 entity player = M_ARGV(0, entity);
1048 if(player.ballcarried)
1050 player.stat_sv_airspeedlimit_nonqw *= autocvar_g_nexball_basketball_carrier_highspeed;
1051 player.stat_sv_maxspeed *= autocvar_g_nexball_basketball_carrier_highspeed;
1055 MUTATOR_HOOKFUNCTION(nb, ForbidThrowCurrentWeapon)
1057 entity player = M_ARGV(0, entity);
1059 return PS(player).m_weapon == WEP_NEXBALL;
1062 MUTATOR_HOOKFUNCTION(nb, ForbidDropCurrentWeapon)
1064 entity player = M_ARGV(0, entity);
1066 return PS(player).m_weapon == WEP_MORTAR; // TODO: what is this for?
1069 MUTATOR_HOOKFUNCTION(nb, FilterItem)
1071 entity item = M_ARGV(0, entity);
1073 if(item.classname == "droppedweapon")
1074 if(item.weapon == WEP_NEXBALL.m_id)
1080 MUTATOR_HOOKFUNCTION(nb, GetTeamCount)
1082 M_ARGV(1, string) = "nexball_team";
1086 MUTATOR_HOOKFUNCTION(nb, WantWeapon)
1088 M_ARGV(1, float) = 0; // weapon is set a few lines later, apparently
1092 MUTATOR_HOOKFUNCTION(nb, DropSpecialItems)
1094 entity frag_target = M_ARGV(0, entity);
1096 if(frag_target.ballcarried)
1097 DropBall(frag_target.ballcarried, frag_target.origin, frag_target.velocity);
1102 MUTATOR_HOOKFUNCTION(nb, SendWaypoint)
1104 M_ARGV(2, int) &= ~0x80;
1107 REGISTER_MUTATOR(nb, g_nexball)
1111 g_nexball_meter_period = autocvar_g_nexball_meter_period;
1112 if(g_nexball_meter_period <= 0)
1113 g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
1114 g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
1118 CVTOV(g_nexball_football_boost_forward); //100
1119 CVTOV(g_nexball_football_boost_up); //200
1120 CVTOV(g_nexball_delay_idle); //10
1121 CVTOV(g_nexball_football_physics); //0
1123 radar_showennemies = autocvar_g_nexball_radar_showallplayers;
1125 InitializeEntity(NULL, nb_delayedinit, INITPRIO_GAMETYPE);
1126 WEP_NEXBALL.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
1129 SetLimits(autocvar_g_nexball_goallimit, autocvar_g_nexball_goalleadlimit, autocvar_timelimit_override, -1);
1130 have_team_spawns = -1; // request team spawns
1133 MUTATOR_ONROLLBACK_OR_REMOVE
1135 WEP_NEXBALL.spawnflags |= WEP_FLAG_MUTATORBLOCKED;
1136 // we actually cannot roll back nb_delayedinit here
1137 // BUT: we don't need to! If this gets called, adding always
1143 LOG_INFO("This is a game type and it cannot be removed at runtime.");